Files
claude-code/packages/remote-control-server/README.md
claude-code-best 34154ee3f5 feat: 支持 acp-link 包进行 acp 通用的 remote-control (#292)
* fix: 修复超时问题

* feat: 添加 acp-link 代码

* refactor: 样式重构完成

* feat: RCS 添加 ACP 后端支持

- 新增 ACP WebSocket handler (agent 注册、EventBus 订阅)
- 新增 relay handler (前端 WS → acp-link 透传 + EventBus inbound 转发)
- 新增 SSE event stream 供外部消费者订阅 channel group 事件
- ACP REST 接口无鉴权 (agents、channel-groups)
- WebSocket 端点保留 token 鉴权
- SPA 路由 /acp/ 指向 acp.html

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* feat: 添加 ACP 专属前端界面

- 新增 /acp/ SPA 页面 (agent 列表 + 实时交互)
- Agent 列表按 channel group 分组,显示在线状态
- 通过 RCS WebSocket relay 与 agent 通信
- Vite multi-page 构建 (index.html + acp.html)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* feat: acp-link 支持 RCS relay 双向通信

- rcs-upstream 新增 messageHandler 转发非控制消息
- server.ts 新增虚拟 WS + relay client state 处理 relay ACP 消息
- newSession/loadSession 补充 mcpServers 参数
- 连接成功后显示 ACP Dashboard URL

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* refactor: 移除 FileExplorer 及文件操作相关代码

- 删除 FileExplorer 组件
- ACPMain 移除 Files tab,仅保留 Chat 和 History
- client.ts 移除 listDir/readFile/onFileChanges 等方法
- types.ts 移除 FileItem/FileContent/FileChange 等类型

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* fix: 修复类型问题

* feat: RCS 后端统一 ACP/Bridge 注册逻辑

- store: EnvironmentRecord 增加 capabilities 字段、storeFindEnvironmentByMachineName 复用逻辑
- store: 新增 storeGetSessionOwners,支持未绑定 session 自动 claim
- environment: registerEnvironment 支持 ACP 复用已有记录,返回 session_id
- session: resolveOwnedWebSessionId 支持无 owner session 自动绑定
- acp-ws-handler: 新增 handleIdentify 支持 REST+WS 两步注册
- acp routes: /acp/relay 和 /acp/agents 支持 UUID 认证
- event-bus: 增加 error 类型 payload 日志

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* feat: acp-link 改 REST 注册 + WS identify 两步流程

- rcs-upstream: 新增 registerViaRest() 通过 POST /v1/environments/bridge 注册
- rcs-upstream: WS 连接后发送 identify 替代 register,携带 agentId
- rcs-upstream: 入口链接改为 /code/?sid=${sessionId} 实现用户绑定
- server: 修复心跳跳过 relay 虚拟连接的 bug
- server: maxSessions 配置传入 RCS upstream

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* feat: 前端统一 Chat 组件 + ACP 聊天界面重构

- 新增 chat/ 组件: ChatView, ChatInput, MessageBubble, ToolCallGroup, PermissionPanel, SessionSidebar, CommandMenu
- ACPMain: 重构支持完整 ACP 协议交互(session/prompt/permission)
- rcs-chat-adapter: 统一 bridge session SSE 适配器
- ACPClient: 增强 session 管理、permission 流程、streaming 支持
- index.css: 新增 chat 相关样式、动画、布局
- useCommands: 新增快捷命令 hook

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* refactor: 删除 /acp/ 独立页面,ACP 聊天统一到 /code/:sessionId

- 删除 acp.html、acp-main.tsx 入口文件和 pages/acp/ 目录
- SessionDetail: ACP session 在同一页面渲染 ACPSessionDetail 组件
- App.tsx: ?sid= 参数自动调用 apiBind 绑定用户 UUID
- Dashboard: 统一 session 列表导航,ACP 显示紫色标签
- relay-client: 改用 UUID 认证替代 API token
- EnvironmentList: 显示 workerType 标签(ACP Agent / Claude Code)
- index.ts: 移除 /acp/ SPA 路由,vite.config 移除 acp 入口

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* build: 更新构建及测试修复

---------

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-18 17:59:29 +08:00

175 lines
5.1 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Remote Control Server (RCS)
Remote Control Server 是 Claude Code 的远程控制后端,允许你通过浏览器 Web UI 远程监控和操作 Claude Code 会话。
## 功能
- **会话管理** — 创建、监控、归档 Claude Code 会话
- **实时消息流** — WebSocket / SSE 双向传输,实时查看对话和工具调用
- **权限审批** — 在 Web UI 中审批 Claude Code 的工具权限请求
- **多环境管理** — 注册多个运行环境,支持心跳和断线重连
- **认证安全** — API Key + JWT 双层认证
## 快速开始
### Docker 部署(推荐)
```bash
docker run -d \
--name rcs \
-p 3000:3000 \
-e RCS_API_KEYS=your-api-key-here \
-v rcs-data:/app/data \
ghcr.io/claude-code-best/remote-control-server:latest
```
## 环境变量
### 服务器配置
| 变量 | 默认值 | 说明 |
|------|--------|------|
| `RCS_PORT` | `3000` | 监听端口 |
| `RCS_HOST` | `0.0.0.0` | 监听地址 |
| `RCS_API_KEYS` | _(空)_ | API 密钥列表,逗号分隔。客户端和 Worker 连接时需要提供 |
| `RCS_BASE_URL` | _(自动)_ | 外部访问地址,例如 `https://rcs.example.com`。用于生成 WebSocket 连接 URL |
| `RCS_VERSION` | `0.1.0` | 服务版本号,显示在 `/health` 响应中 |
### 超时与心跳
| 变量 | 默认值 | 说明 |
|------|--------|------|
| `RCS_POLL_TIMEOUT` | `8` | V1 轮询超时(秒) |
| `RCS_HEARTBEAT_INTERVAL` | `20` | 心跳间隔(秒) |
| `RCS_JWT_EXPIRES_IN` | `3600` | JWT 令牌有效期(秒) |
| `RCS_DISCONNECT_TIMEOUT` | `300` | 断线判定超时(秒) |
## Claude Code 客户端配置
### 连接到自托管服务器
在 Claude Code 所在环境设置以下变量:
```bash
# 指向你的 RCS 服务器地址
export CLAUDE_BRIDGE_BASE_URL="https://rcs.example.com"
# 认证令牌(与 RCS_API_KEYS 中的值对应)
export CLAUDE_BRIDGE_OAUTH_TOKEN="your-api-key-here"
```
然后启动远程控制模式:
```bash
ccb --remote-control
```
> **注意**:远程控制功能需要启用 `BRIDGE_MODE` feature flag。开发模式下默认启用。
### 环境变量参考
| 变量 | 说明 |
|------|------|
| `CLAUDE_BRIDGE_BASE_URL` | RCS 服务器地址,覆盖默认的 Anthropic 云端地址 |
| `CLAUDE_BRIDGE_OAUTH_TOKEN` | 认证令牌,用于连接 RCS 服务器 |
| `CLAUDE_BRIDGE_SESSION_INGRESS_URL` | WebSocket 入口地址(默认与 BASE_URL 相同) |
| `CLAUDE_CODE_REMOTE` | 设为 `1` 时标记为远程执行模式 |
## Docker Compose 示例
```yaml
version: "3.8"
services:
rcs:
build:
context: .
dockerfile: packages/remote-control-server/Dockerfile
args:
VERSION: "0.1.0"
ports:
- "3000:3000"
environment:
- RCS_API_KEYS=sk-rcs-change-me
- RCS_BASE_URL=https://rcs.example.com
volumes:
- rcs-data:/app/data
restart: unless-stopped
volumes:
rcs-data:
```
## ACP 兼容的 remote-control
```sh
ACP_RCS_URL=http://localhost:3000 ACP_RCS_TOKEN=test-my-key acp-link ccb-bun -- --acp
```
## 反向代理配置
使用 Nginx 或 Caddy 反向代理时,需要支持 WebSocket 升级:
```nginx
server {
listen 443 ssl;
server_name rcs.example.com;
location / {
proxy_pass http://127.0.0.1:3000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_read_timeout 86400s;
}
}
```
Caddy 配置更简单,自动处理 WebSocket
```
rcs.example.com {
reverse_proxy localhost:3000
}
```
## 架构概览
```
┌─────────────┐ WebSocket/SSE ┌──────────────────┐
│ Claude Code │ ◄──────────────────► │ Remote Control │
│ (Bridge CLI)│ HTTP API │ Server │
└─────────────┘ │ │
│ ┌────────────┐ │
┌─────────────┐ HTTP/SSE │ │ Event Bus │ │
│ Web UI │ ◄────────────────── │ └────────────┘ │
│ (/code/*) │ │ ┌────────────┐ │
└─────────────┘ │ │ In-Memory │ │
│ │ Store │ │
│ └────────────┘ │
└──────────────────┘
```
- **传输层**WebSocketV1和 SSE + HTTP POSTV2
- **存储**纯内存存储Map重启后数据清除
- **认证**API Key客户端+ JWTWorker
- **前端**:原生 JS SPA通过 `/code/*` 路径访问
## 开发
```bash
# 安装依赖
bun install
# 开发模式(热重载)
bun run dev
# 类型检查
bun run typecheck
# 运行测试
bun test packages/remote-control-server/
```