English
RCoder 是一个基于 Rust 构建的现代化 AI 驱动开发平台,通过 SACP (Symposium ACP) 协议实现与多种 AI 代理的统一交互。项目采用微服务架构,支持 Docker 容器化部署和 gRPC 高性能通信。
- 反向代理:集成 Cloudflare Pingora,高性能端口路由
/proxy/{port}/{path}
- HTTP API:基于 Axum 的现代化 REST API 与统一 SSE 进度流
- 多代理支持:统一接入 Claude Code、Codex 等 AI 代理
- 容器化架构:每个项目对应独立的 Docker 容器,实现隔离和资源管理
- gRPC 通信:基于 Tonic 的高性能内部通信,支持 Server Streaming
- 配置系统:命令行 > 环境变量 > 配置文件,多层配置优先级
- API 文档:自动化 API 文档(utoipa + Swagger UI)
- 可观测性:Tracing + OpenTelemetry 完整链路追踪 + Pyroscope 性能分析
- Computer Agent:容器化 AI 代理环境,集成 VNC 远程桌面、音频流和 IME 输入
外部客户端 (HTTP/SSE)
↓
RCoder (HTTP API Server + Docker 管理 + gRPC 客户端)
↓ gRPC (Chat, CancelSession, SubscribeProgress)
Agent Runner (gRPC Server in Docker)
↓ Server Streaming (实时进度事件)
RCoder (转换为 SSE)
↓
外部客户端 (SSE)
- RCoder 主服务:Axum HTTP 服务 + 容器管理 + gRPC 客户端
- Agent Runner:独立的 AI 代理运行环境(Docker 容器内),提供 gRPC 服务
- Pingora 代理:高性能反向代理服务,支持端口路由
- Docker Manager:全局容器生命周期管理
| 组件类型 |
技术选型 |
说明 |
| 编程语言 |
Rust 2024 Edition |
现代化系统编程语言 |
| HTTP 框架 |
Axum + Tower |
高性能异步 Web 框架 |
| RPC 框架 |
Tonic (gRPC) |
高性能 RPC 通信 |
| AI 协议 |
SACP + MCP |
支持多种 AI 代理协议 |
| 容器化 |
Docker + Bollard |
容器管理和编排 |
| 数据库 |
DuckDB + SQLx |
嵌入式分析数据库 |
| 日志系统 |
Tracing + OpenTelemetry |
结构化日志和分布式追踪 |
| 性能分析 |
Pyroscope |
持续性能剖析 |
| 命令行 |
clap |
现代化命令行参数解析 |
- Rust: 1.75+(2024 Edition)
- Docker(用于容器化部署)
- 可选:Claude Code CLI(用于 Claude 代理)
git clone https://github.com/your-org/rcoder.git
cd rcoder
cargo build --workspace
cargo run --bin rcoder
cargo run --bin rcoder -- --port 8087 --projects-dir ./my-projects
make dev-build
make dev-up
make dev-restart
make dev-logs
make dev-down
cargo run --bin rcoder -- --enable-proxy --proxy-port 8080
cargo run --bin rcoder -- --enable-proxy --proxy-port 8080 --backend-port 3000
| 参数 |
短参数 |
说明 |
示例 |
--port |
-p |
设置主服务端口 |
--port 8087 |
--projects-dir |
-d |
设置项目工作目录 |
--projects-dir ./projects |
--enable-proxy |
无 |
启用 Pingora 反向代理 |
--enable-proxy |
--proxy-port |
无 |
设置 Pingora 监听端口 |
--proxy-port 8080 |
--backend-port |
无 |
默认后端端口 |
--backend-port 3000 |
cargo run --bin rcoder -- --help
Pingora 是项目内置的高性能反向代理。
cargo run --bin rcoder -- --enable-proxy --proxy-port 8080
curl "http://127.0.0.1:8080/proxy/5173/page/123/"
| 端点 |
方法 |
说明 |
/health |
GET |
健康检查 |
/chat |
POST |
发送聊天消息给 AI 代理 |
/agent/progress/{session_id} |
GET (SSE) |
获取实时进度流 |
/agent/session/cancel |
POST |
取消正在执行的任务 |
/agent/stop |
POST |
停止 Agent |
/agent/status/{project_id} |
GET |
查询 Agent 状态 |
/api/docs |
GET |
Swagger UI API 文档 |
| 方法 |
类型 |
说明 |
Chat |
Unary |
发送聊天请求 |
SubscribeProgress |
Server Streaming |
订阅进度事件流 |
CancelSession |
Unary |
取消会话任务 |
GetStatus |
Unary |
查询 Agent 状态 |
StopAgent |
Unary |
停止 Agent |
GetContainerStatus |
Unary |
查询容器状态 |
GetVncStatus |
Unary |
查询 VNC 服务状态 |
Computer Agent 提供容器化的 AI 代理环境,支持 VNC 远程桌面、音频流和 IME 输入。每个用户对应独立的 Docker 容器,多个项目可共享同一容器。
| 端点 |
方法 |
说明 |
/computer/chat |
POST |
发送聊天消息到 Computer Agent |
/computer/progress/{session_id} |
GET (SSE) |
获取实时进度流 |
/computer/agent/stop |
POST |
停止指定项目的 Agent(不销毁容器) |
/computer/agent/status |
POST |
查询 Agent 状态(alive/idle/busy) |
/computer/agent/session/cancel |
POST |
取消正在执行的会话 |
| 端点 |
方法 |
说明 |
/computer/desktop/{user_id}/{project_id} |
GET |
获取 VNC 桌面访问地址 |
/computer/vnc/{user_id}/{project_id}/{*path} |
GET |
VNC/noVNC 代理(端口 6080) |
/computer/audio/{user_id}/{project_id}/{*path} |
GET |
音频流代理(端口 6089/6090) |
/computer/ime/{user_id}/{project_id}/{*path} |
GET |
IME 输入法代理(端口 6091) |
| 端点 |
方法 |
说明 |
/computer/pod/count |
GET |
容器数量统计(按服务类型分组) |
/computer/pod/list |
GET |
列出所有容器详情(支持分页 ?limit=100) |
/computer/pod/ensure |
POST |
确保容器存在(幂等,不启动 Agent) |
/computer/pod/keepalive |
POST |
刷新容器活跃时间(防止自动清理) |
/computer/pod/restart |
POST |
重启容器(销毁并重建) |
/computer/pod/status |
GET |
查询容器状态(?user_id=xxx) |
/computer/pod/vnc-status |
GET |
查询 VNC 服务就绪状态 |
curl -X POST http://localhost:8087/computer/chat \
-H "Content-Type: application/json" \
-d '{
"user_id": "user-123",
"project_id": "my-project",
"prompt": "帮我创建一个 Python Web 应用"
}'
curl -X GET http://localhost:8087/health
响应:
{
"status": "ok",
"timestamp": "2024-01-01T00:00:00Z"
}
curl -X POST http://localhost:8087/chat \
-H "Content-Type: application/json" \
-d '{
"prompt": "你好,请帮我创建一个 Rust Web API 项目",
"project_id": "my-project",
"session_id": "optional-session-id"
}'
curl -X GET http://localhost:8087/agent/progress/your-session-id \
-H "Accept: text/event-stream"
crates/
├── agent_abstraction/ # Agent 抽象层
├── agent_config/ # Agent 配置管理
├── agent_runner/ # Agent 运行时(gRPC 服务端)
│ ├── src/
│ │ ├── grpc/ # gRPC 服务实现
│ │ ├── proxy_agent/ # ACP 代理实现
│ │ └── service/ # 核心服务
│ └── Cargo.toml
├── docker_manager/ # Docker 容器管理
├── duckdb_manager/ # DuckDB 数据库管理
├── rcoder/ # 主应用
│ ├── src/
│ │ ├── grpc/ # gRPC 客户端
│ │ ├── handler/ # HTTP 处理器
│ │ ├── service/ # 业务服务
│ │ └── cleanup_task/ # 清理任务
│ └── Cargo.toml
├── rcoder-proxy/ # Pingora 代理封装
├── rcoder-telemetry/ # 遥测和追踪
└── shared_types/ # 共享类型和 Proto 定义
└── proto/
└── agent.proto # gRPC 协议定义
- 命令行参数 - 最高优先级
- 环境变量 - 中等优先级
- 配置文件 - 较低优先级
- 默认配置 - 最低优先级
default_agent_id: "claude-code-acp-ts"
projects_dir: "./project_workspace"
port: 8087
docker_config:
network_mode: "bridge"
network_base_name: "agent-network"
work_dir: "/app"
auto_cleanup: true
container_ttl_seconds: 3600
api_timeout_seconds: 10
cache_status_ttl_seconds: 10
cleanup_config:
enabled: true
idle_timeout_seconds: 600
cleanup_interval_seconds: 300
container_protection_seconds: 300
api_key_auth:
enabled: false
api_key: "sk-xxx"
proxy_config:
listen_port: 8088
default_backend_port: 8086
backend_host: "127.0.0.1"
| 变量名 |
说明 |
默认值 |
RCODER_PORT |
服务端口 |
8087 |
RCODER_PROJECTS_DIR |
项目目录 |
./project_workspace |
RCODER_NETWORK_MODE |
Docker 网络模式 |
bridge |
RCODER_NETWORK_BASE_NAME |
网络基础名称 |
agent-network |
RCODER_API_TIMEOUT_SECONDS |
Docker API 超时 |
10 |
RCODER_API_KEY_ENABLED |
启用 API Key 鉴权 |
false |
RCODER_API_KEY |
API Key 密钥 |
- |
RUST_LOG |
日志级别 |
info |
RCODER_PORT=8080 RUST_LOG=debug cargo run --bin rcoder
RCODER_PORT=8080 cargo run --bin rcoder -- --port 9000
cargo test --workspace
make test-unit
make test-integration
cargo fmt
cargo clippy
cargo clippy -- -D warnings
RUST_LOG=debug cargo run --bin rcoder -- --port 8087
cargo install cargo-watch
cargo watch -x "run --bin rcoder"
make docker-build
make docker-build-master
make docker-build-agent-runner
make docker-build-agent-production
make dev-up
docker-compose -f docker/docker-compose.yml ps
make dev-down
make pyroscope-up
open http://localhost:4040
make pyroscope-down
- 端口被占用:使用
--port 参数指定其他端口
- 容器启动失败:检查 Docker 服务状态和网络配置
- gRPC 连接失败:确认容器网络和端口配置
- API Key 错误:检查
api_key_auth 配置
RUST_LOG=debug cargo run --bin rcoder
make dev-logs
docker exec -it <container_id> /bin/bash
- 基于 SACP 协议的 AI 代理统一管理
- gRPC 高性能通信架构
- Docker 容器化部署(项目级隔离)
- VNC/noVNC 远程桌面支持
- API Key 鉴权中间件
- 容器自动清理机制
- 多镜像配置支持
- Pyroscope 性能分析集成
- Rust 2024 Edition
- Tonic gRPC (v0.14.2)
- SACP 协议 (v10.1.0)
- MCP 协议支持 (rmcp v0.12.0)
- DuckDB 数据库
- OpenTelemetry 追踪
- eBPF 调试工具支持
本项目采用 Apache-2.0 许可证。详见 LICENSE 文件。
欢迎贡献!请阅读 CONTRIBUTING.md 了解如何参与开发。
- Fork 项目
- 创建特性分支 (
git checkout -b feature/amazing-feature)
- 提交更改 (
git commit -m 'Add amazing feature')
- 推送到分支 (
git push origin feature/amazing-feature)
- 开启 Pull Request
由 RCoder 团队精心打造,致力于推进 AI 驱动的现代化开发体验。