Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 78 additions & 0 deletions .impeccable.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# Impeccable Design Context

## Users

**Primary**: Technical teams and enterprises using AI-assisted coding in production workflows.
- DevOps engineers managing remote agents via RCS dashboard
- Development teams collaborating through shared sessions
- Individual developers using terminal CLI daily

**Context**: Used during focused work sessions — debugging, code review, agent orchestration. Users are in "get things done" mode, not browsing. They value efficiency but also appreciate warmth and personality.

**Job to be done**: Make advanced AI coding tools accessible and controllable, especially features that normally require enterprise accounts or Anthropic OAuth.

## Brand Personality

**3 words**: Warm, Considered, Human

**Voice**: Like a knowledgeable colleague who's genuinely enthusiastic about the craft — not a corporate product manager. Community-first, open, slightly playful. Chinese developer community culture (贴吧/discord 温暖氛围).

**Emotional goals**: Confidence (this tool is solid), Warmth (this community is welcoming), Delight (small moments of personality make the difference).

**References**:
- **Anthropic's own design language** — their clean, considered aesthetic with warm undertones. The terra cotta/burnt orange as a human accent. Lots of breathing room. Typography-forward.
- **NOT**: Generic AI product (no ChatGPT blue, no gradient text, no "AI slop"). NOT corporate SaaS (no Salesforce-blue dashboards, no enterprise sterility).

**Anti-references**: Corporate enterprise dashboards, generic AI product pages, anything that looks like it was "designed by committee."

## Aesthetic Direction

**Theme**: Light + Dark dual mode (user/system preference switch)

**Tone**: Anthropomorphic warmth meets terminal precision. The brand orange (Claude's terra cotta) is the thread that ties everything together — it's the human element in a technical world.

**Typography**: Clean, considered, with good hierarchy. Terminal-native for CLI; modern web fonts for Web UI (RCS dashboard, docs). Favor readability and personality.

**Color**:
- Primary: Claude orange family (`#D77757` / terra cotta)
- Accent: Warm neutrals tinted toward orange
- Semantic: Success/Error/Warning following Anthropic's established palette
- Dark mode: Warm dark surfaces (not cold blue-black)

**Differentiation**: The CCB brand sits at the intersection of "serious tool" and "community project." It should feel like Anthropic's design principles applied to an open-source context — less corporate polish, more human craft. The mascot "Clawd" and the playful "踩踩背" naming hint at personality that the design should honor.

**Scope**: All Web UI — RCS control panel, documentation site, landing pages.

## Design Principles

1. **Considered over clever** — Every design choice should feel intentional, not trendy. If it doesn't serve the user, it doesn't ship.
2. **Warmth through subtlety** — Orange tints on neutrals, breathing room in layouts, personality in copy. Not giant emoji or aggressive color.
3. **Density with clarity** — Technical users need information density, but not chaos. Every pixel earns its place.
4. **Community voice** — The design should feel like it was made by people who use it, not by a distant design team. Slightly rough edges are fine if they're honest.
5. **Anthropic's shadow** — When in doubt, follow Anthropic's design instincts — the clean layouts, the generous spacing, the warm color temperature. Then add the community touch.

## Existing Design Assets

### Brand Colors (from theme system)
- Claude Orange: `rgb(215,119,87)` / `#D77757`
- Claude Blue: `rgb(87,105,247)` / `#5769F7`
- Permission Blue: `rgb(87,105,247)`
- Auto Accept Violet: `rgb(135,0,255)`
- Plan Mode Teal: `rgb(0,102,102)`
- Success: `rgb(78,186,101)`
- Error: `rgb(255,107,128)`
- Warning: `rgb(255,193,7)`

### Logo
- CCB text + orange play button icon
- Dark/Light SVG variants in `docs/logo/`
- Favicon: Orange circle `#D97706` with white play triangle

### Mascot
- "Clawd" — terminal-art character with multiple poses
- Theme-aware coloring

### Theme System
- 7 variants: dark, light, dark-ansi, light-ansi, dark-daltonized, light-daltonized, auto
- 89+ semantic color tokens
- Full documentation in `packages/@ant/ink/docs/04-theme-system.md`
48 changes: 44 additions & 4 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ bun run build
bun run build:vite

# Test
bun test # run all tests (3066 tests / 205 files / 0 fail)
bun test # run all tests (3175 tests / 207 files / 0 fail)
bun test src/utils/__tests__/hash.test.ts # run single file
bun test --coverage # with coverage report

Expand Down Expand Up @@ -157,11 +157,12 @@ bun run docs:dev
| `packages/@ant/model-provider/` | Model provider 抽象层 |
| `packages/builtin-tools/` | 内置工具集(60 个 tool 实现,通过 `@claude-code-best/builtin-tools` 导出) |
| `packages/agent-tools/` | Agent 工具集 |
| `packages/acp-link/` | ACP 代理服务器(WebSocket → ACP agent 桥接) |
| `packages/cc-knowledge/` | Claude Code 知识库(非 workspace 包) |
| `packages/langfuse-dashboard/` | Langfuse 可观测性面板(非 workspace 包) |
| `packages/mcp-client/` | MCP 客户端库 |
| `packages/mcp-server/` | MCP 服务端库(非 workspace 包) |
| `packages/remote-control-server/` | 自托管 Remote Control Server(Docker 部署,含 Web UI) |
| `packages/remote-control-server/` | 自托管 Remote Control Server(Docker 部署,含 Web UI)— Web UI 已重构为 React + Vite + Radix UI,支持 ACP agent 接入 |
| `packages/swarm/` | Swarm 解耦模块(非 workspace 包) |
| `packages/shell/` | Shell 抽象(非 workspace 包) |
| `packages/audio-capture-napi/` | 原生音频捕获(已恢复) |
Expand All @@ -173,10 +174,17 @@ bun run docs:dev
### Bridge / Remote Control

- **`src/bridge/`** (~38 files) — Remote Control / Bridge 模式。feature-gated by `BRIDGE_MODE`。包含 bridge API、会话管理、JWT 认证、消息传输、权限回调等。Entry: `bridgeMain.ts`。
- **`packages/remote-control-server/`** — 自托管 RCS,支持 Docker 部署,含 Web UI 控制面板。通过 `bun run rcs` 启动。
- **`packages/remote-control-server/`** — 自托管 RCS,支持 Docker 部署,含 Web UI 控制面板(React 19 + Vite + Radix UI)。支持 ACP agent 通过 acp-link 接入(ACP WebSocket handler、relay handler、SSE event stream)。通过 `bun run rcs` 启动。
- CLI 快速路径: `claude remote-control` / `claude rc` / `claude bridge`。
- 详见 `docs/features/remote-control-self-hosting.md`。

### ACP Protocol (Agent Client Protocol)

- **`src/services/acp/`** — ACP agent 实现,包含 `agent.ts`(AcpAgent 类)、`bridge.ts`(Claude Code ↔ ACP 桥接)、`permissions.ts`(权限处理)、`entry.ts`(入口)。
- **`packages/acp-link/`** — ACP 代理服务器,将 WebSocket 客户端桥接到 ACP agent。提供 `acp-link` CLI 命令,支持自定义端口/HTTPS/认证/会话管理、RCS 集成(REST 注册 + WS identify 两步流程)、权限模式透传(fallback: 客户端传值 > config > `ACP_PERMISSION_MODE` 环境变量)。
- ACP 权限管道改进:`createAcpCanUseTool` 统一权限流水线,`applySessionMode` 模式同步,`bypassPermissions` 可用性检测(非 root/sandbox 环境)。
- ACP Plan 可视化已支持 `session/update plan` 类型的消息展示(PlanView 组件,含进度条/状态图标/优先级标签)。

### Daemon Mode

- **`src/daemon/`** — Daemon 模式(长驻 supervisor)。feature-gated by `DAEMON`。包含 `main.ts`(entry)和 `workerRegistry.ts`(worker 管理)。
Expand Down Expand Up @@ -209,6 +217,12 @@ Feature flags control which functionality is enabled at runtime. 代码中统一

支持 OpenAI、Gemini、Grok 三种第三方 API,通过 `/login` 命令配置,均采用流适配器模式转为 Anthropic 内部格式。详见各兼容层的 docs 文档。

### 穷鬼模式(Budget Mode)

- 通过 `/poor` 命令切换,持久化到 `settings.json`。
- 启用后跳过 `extract_memories`、`prompt_suggestion` 和 `verification_agent`,显著减少 token 消耗。
- 实现在 `src/commands/poor/poorMode.ts`。

### Stubbed/Deleted Modules

| Module | Status |
Expand All @@ -233,7 +247,7 @@ Feature flags control which functionality is enabled at runtime. 代码中统一
## Testing

- **框架**: `bun:test`(内置断言 + mock)
- **当前状态**: 3066 tests / 205 files / 0 fail
- **当前状态**: 3175 tests / 207 files / 0 fail
- **单元测试**: 就近放置于 `src/**/__tests__/`,文件名 `<module>.test.ts`
- **集成测试**: `tests/integration/` — 4 个文件(cli-arguments, context-build, message-pipeline, tool-chain)
- **共享 mock/fixture**: `tests/mocks/`(api-responses, file-system, fixtures/)
Expand Down Expand Up @@ -278,3 +292,29 @@ bun run typecheck # equivalent to bun run typecheck
- **Biome 配置** — 大量 lint 规则被关闭(decompiled 代码不适合严格 lint)。`.tsx` 文件用 120 行宽 + 强制分号;其他文件 80 行宽 + 按需分号。
- **Ink 框架在 `packages/@ant/ink/`** — 不是 `src/ink/`(该目录不存在)。Ink 相关的组件、hooks、keybindings 都在 packages 中。
- **Provider 优先级** — `modelType` 参数 > 环境变量 > 默认 `firstParty`。新增 provider 需在 `src/utils/model/providers.ts` 注册。

## Design Context

Impeccable 设计上下文保存在 `.impeccable.md` 中。设计 Web UI(RCS 控制面板、文档站、着陆页)时必须参考该文件。

### 核心设计原则

1. **Considered over clever** — 每个设计选择都应感觉有意为之,而非追逐潮流
2. **Warmth through subtlety** — 通过橙色色调的中性色、留白布局、有温度的文案来传达温暖
3. **Density with clarity** — 技术用户需要信息密度,但不能混乱
4. **Community voice** — 设计应感觉是由使用者创造的,而非遥远的设计团队
5. **Anthropic's shadow** — 遵循 Anthropic 的设计直觉:干净的布局、充足的间距、温暖的色温

### 品牌色

- 主色:Claude Orange `#D77757`(terra cotta)
- 辅色:Claude Blue `#5769F7`
- 暗色模式使用温暖的深色表面(非冷蓝黑色)

### 目标用户

技术团队/企业,在专业工作流中使用 AI 辅助编程。友好的开源社区氛围,非企业 SaaS 风格。

### 视觉参考

Anthropic 公司的设计风格 — 干净、考究、温暖的底色。大量留白,以排版为核心。避免 AI 产品常见的设计套路(渐变文字、玻璃态、霓虹色)。
205 changes: 205 additions & 0 deletions docs/features/acp-link.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,205 @@
# acp-link — ACP 代理服务器

> 源码目录:`packages/acp-link/`
> PR: #292
> 新增时间:2026-04-18
Comment on lines +4 to +5
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

PR 引用号与当前 PR 不一致

Line 4 写的是 PR: #292``,但当前变更来自 PR #293。建议修正,避免后续追溯混淆。

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@docs/features/acp-link.md` around lines 4 - 5, The PR reference in
docs/features/acp-link.md is incorrect—change the literal text "PR: `#292`" to
"PR: `#293`" so the document matches the current PR; locate the string "PR: `#292`"
in the file and update it (leave the rest of the header like "新增时间:2026-04-18"
unchanged).


## 一、功能概述

`acp-link` 是一个 ACP (Agent Client Protocol) 代理服务器,将 WebSocket 客户端桥接到 ACP agent 的 stdio 接口。它让 ACP agent(如 Claude Code)可以通过 WebSocket 远程访问,而不仅限于本地 stdio。

### 核心特性

- **WebSocket → stdio 桥接**:将浏览器/远程客户端的 WebSocket 连接转换为 ACP agent 的 stdin/stdout NDJSON 流
- **会话管理**:创建、加载、恢复、列出、关闭会话
- **权限审批流程**:客户端可远程审批 agent 的工具权限请求
- **RCS 集成**:可与 Remote Control Server (RCS) 连接,将 ACP agent 注册到 RCS 并通过 Web UI 交互
- **HTTPS 支持**:内置自签名证书生成,支持安全连接
- **Token 认证**:自动生成或通过环境变量配置认证 token

## 二、架构

### 独立模式

```
┌──────────────────┐ WebSocket ┌──────────────────┐ stdio/NDJSON ┌──────────────┐
│ 浏览器/客户端 │ ◄──────────────►│ acp-link │ ◄────────────────►│ ACP Agent │
│ (WS Client) │ ws://host:port │ (Proxy Server) │ spawn subprocess │ (Claude等) │
└──────────────────┘ └──────────────────┘ └──────────────┘
```

### RCS 集成模式

```
┌──────────────┐ WebSocket ┌──────────────────┐ stdio/NDJSON ┌──────────────┐
│ RCS Web UI │ ◄──────────────►│ Remote Control │ ◄─────────────────►│ acp-link │
│ (/code/*) │ ACP Relay WS │ Server (RCS) │ ACP events │ + Agent │
└──────────────┘ └──────────────────┘ └──────────────┘
```

### 文件结构

```
packages/acp-link/
├── src/
│ ├── server.ts # 主服务器:WS 连接管理、会话管理、权限处理、消息桥接
│ ├── rcs-upstream.ts # RCS 上游客户端:REST 注册 + WS identify 两步流程
│ ├── cert.ts # TLS 证书生成(自签名)
│ ├── logger.ts # 日志模块
│ ├── types.ts # JSON-RPC 和 ACP 协议类型定义
│ ├── cli/
│ │ ├── bin.ts # CLI 入口
│ │ ├── command.ts # 命令行参数解析
│ │ ├── app.ts # 应用启动
│ │ └── context.ts # 上下文配置
│ └── __tests__/ # 测试(cert, server, types)
├── package.json
└── tsconfig.json
```

## 三、安装与使用

### 基本用法

```bash
# 直接运行(在 monorepo 中)
# 注意:claude 本身不支持 ACP,需要用 ccb-bun --acp 启动 ACP agent
bun packages/acp-link/src/cli/bin.ts ccb-bun -- --acp

# 指定端口和主机
acp-link --port 9000 --host 0.0.0.0 ccb-bun -- --acp

# 启用 HTTPS(自签名证书)
acp-link --https ccb-bun -- --acp

# 调试模式
acp-link --debug ccb-bun -- --acp
```

### CLI 参考

```
USAGE
acp-link [--port value] [--host value] [--debug] [--no-auth] [--https] <command>...
acp-link --help
acp-link --version

FLAGS
[--port] Port to listen on [default = 9315]
[--host] Host to bind to [default = localhost]
[--debug] Enable debug logging to file
[--no-auth] Disable authentication (dangerous)
[--https] Enable HTTPS with self-signed cert
-h --help Print help information and exit
-v --version Print version information and exit

ARGUMENTS
command... Agent command followed by its arguments (e.g. "ccb-bun -- --acp")
```

## 四、认证

默认启动时自动生成随机 token。客户端连接时需通过 query 参数传递:

```
ws://localhost:9315/ws?token=<your-token>
```

配置固定 token:

```bash
ACP_AUTH_TOKEN=my-fixed-token acp-link ccb-bun -- --acp
```

禁用认证(不推荐,仅用于开发):

```bash
acp-link --no-auth ccb-bun -- --acp
```

## 五、RCS 集成

acp-link 支持将 ACP agent 注册到 Remote Control Server,通过 Web UI 远程操控。

### 连接方式

```bash
# 通过环境变量配置 RCS 连接
ACP_RCS_URL=http://localhost:3000 \
ACP_RCS_TOKEN=sk-rcs-your-key \
ACP_RCS_NAME=my-agent \
acp-link ccb-bun -- --acp
```

### 注册流程(两步)

1. **REST 注册**:通过 `POST /v1/environments/bridge` 向 RCS 注册环境
2. **WS identify**:建立 WebSocket 连接后发送 `identify` 消息(携带 agentId),替代完整 `register`

```
acp-link RCS
│ │
│── POST /v1/environments/bridge ──►│ (REST 注册)
│◄── { agentId, sessionId } ───────│
│ │
│── WS connect ─────────────────►│ (WebSocket)
│── identify { agentId } ────────►│ (WS 标识)
│◄── registered ─────────────────│
│ │
│── ACP events ─────────────────►│ (双向消息转发)
│◄── user prompts/permissions ───│
```

## 六、权限模式

### permissionMode 传递链

权限模式通过整条链路传递:Web UI → RCS → acp-link → ACP agent。

支持的权限模式:
- `default` — 每次请求权限确认
- `auto` — 自动判断
- `acceptEdits` — 自动接受编辑
- `plan` — 规划模式
- `dontAsk` — 不询问
- `bypassPermissions` — 绕过权限(需 sandbox 环境)

### fallback 链

当客户端未显式传递 permissionMode 时,使用以下 fallback 链:

```
客户端传值 > config.permissionMode > ACP_PERMISSION_MODE 环境变量
```

示例:

```bash
ACP_PERMISSION_MODE=auto acp-link ccb-bun -- --acp
```

## 七、权限管道(2026-04-18 改进)

### 模式同步

`applySessionMode` 在 agent 切换权限模式时同步 `appState.toolPermissionContext.mode`,确保内部权限上下文与 ACP 客户端状态一致。

### 统一权限流水线

`createAcpCanUseTool` 接入 `hasPermissionsToUseTool` 统一权限流水线,替代原来分散的处理逻辑。支持 `onModeChange` 回调,模式变更时实时同步。

### bypass 检测

`bypassPermissions` 模式增加可用性检测 — 仅在非 root 或 sandbox 环境中允许启用,防止权限绕过的安全风险。

## 八、环境变量

| 变量 | 说明 |
|------|------|
| `ACP_AUTH_TOKEN` | 固定认证 token(默认自动生成) |
| `ACP_PERMISSION_MODE` | 默认权限模式 fallback |
| `ACP_RCS_URL` | RCS 服务器地址(启用 RCS 集成) |
| `ACP_RCS_TOKEN` | RCS API token |
| `ACP_RCS_NAME` | Agent 名称(在 RCS 中显示) |
| `ACP_RCS_CHANNEL_GROUP` | Channel group ID |
| `ACP_MAX_SESSIONS` | 最大会话数 |
Comment on lines +24 to +205
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

为 fenced code block 补充语言标识

文档里多处代码块未声明语言(如 Line 24、Line 33、Line 42、Line 81、Line 104、Line 139、Line 171),会持续触发 MD040。建议统一补上(bash/text/plaintext)。

📝 示例修复(节选)
-```
+```text
 ┌──────────────────┐    WebSocket     ┌──────────────────┐    stdio/NDJSON    ┌──────────────┐
 │  浏览器/客户端     │ ◄──────────────►│  acp-link        │ ◄────────────────►│  ACP Agent   │
 │  (WS Client)     │  ws://host:port  │  (Proxy Server)  │  spawn subprocess │  (Claude等)   │
 └──────────────────┘                  └──────────────────┘                    └──────────────┘

- +text
USAGE
acp-link [--port value] [--host value] [--debug] [--no-auth] [--https] ...

</details>

<details>
<summary>🤖 Prompt for AI Agents</summary>

Verify each finding against the current code and only fix it if needed.

In @docs/features/acp-link.md around lines 24 - 205, The Markdown in
docs/features/acp-link.md contains multiple fenced code blocks without a
language tag (e.g., the ASCII diagrams, CLI usage block, shell examples and the
boxed flows), which triggers MD040; add appropriate language identifiers to each
fence (use text/plain for ASCII diagrams and protocol diagrams, bash for
shell/CLI examples, and text or plaintext for generic blocks) so linters
recognize them; update the top diagram fences, the RCS/integration diagrams, the
"文件结构" tree, the CLI usage block ("USAGE...FLAGS...ARGUMENTS"), the
installation/usage bash snippets, and any other unlabeled triple-backtick blocks
accordingly.


</details>

<!-- fingerprinting:phantom:triton:hawk:69c8fff2-2695-4c70-a91a-afa315f45df6 -->

<!-- This is an auto-generated comment by CodeRabbit -->

Loading
Loading