Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
afe731b
feat: add 9 new improvement items to Qwen Code report (26→35 total)
wenshao Apr 3, 2026
8e15375
feat: add 2 deep-dive articles + link to 9 new improvement items
wenshao Apr 3, 2026
51015b2
feat: add 8 more improvement items (35→43 total)
wenshao Apr 3, 2026
2b94334
feat: add final 4 items from last sweep (43→47 total)
wenshao Apr 3, 2026
0ab6185
feat: expand Top 5 → Top 20 detailed improvement descriptions
wenshao Apr 3, 2026
a94b5c5
fix: remove cost tracking item (multi-model, not applicable to Qwen)
wenshao Apr 3, 2026
34966dc
fix: restore Top 20 — add Denial Tracking as item 20
wenshao Apr 3, 2026
c1e5533
fix: remove /btw misreport — Qwen Code already has btwCommand.ts
wenshao Apr 3, 2026
c9de808
fix: remove LSP Tool misreport — Qwen Code has lsp.ts with full imple…
wenshao Apr 3, 2026
d4db40a
feat: add 3 deep-dive articles + complete P0/P1 link coverage
wenshao Apr 3, 2026
3330cf5
feat: add Team Memory Sync deep-dive (180 lines)
wenshao Apr 3, 2026
0ac2338
fix: replace History Snip (scaffolding) with Team Memory Sync in Top 20
wenshao Apr 3, 2026
36593e9
feat: rewrite all 45 matrix items with clear one-line descriptions
wenshao Apr 3, 2026
5b68598
feat: add dynamic status line as P3 item (45→46 total)
wenshao Apr 3, 2026
e9fa3af
feat: expand Top 20 → all 47 items with detailed descriptions
wenshao Apr 3, 2026
8bac2ac
feat: add anchor links + compact status bar + all 48 detailed sections
wenshao Apr 3, 2026
5ea9dd4
fix: correct all 43 mismatched anchor links + shorten progress column
wenshao Apr 3, 2026
dd4e9c0
feat: add 9 items from official docs/changelog (48→57 total)
wenshao Apr 3, 2026
f35984d
feat: add 15 items from official docs (57→72 total, 1298 lines)
wenshao Apr 3, 2026
ca4801a
fix: remove /loop misreport — Qwen Code has loop skill + CronCreate/C…
wenshao Apr 3, 2026
e20b79c
fix: remove /context misreport + update Agent SDK (Qwen has TS SDK)
wenshao Apr 3, 2026
849f9b9
feat: split improvement report into 4 files by priority
wenshao Apr 3, 2026
7bd8c03
feat: rewrite P0/P1 file with source-indexed format for developers
wenshao Apr 3, 2026
57e1cba
feat: rewrite all 70 items in developer-friendly format + fix anchor …
wenshao Apr 3, 2026
c6b1172
feat: add 意义/缺失后果/改进收益 to all 70 items + fix cross-file anchors
wenshao Apr 3, 2026
e464dc4
fix: remove Channels misreport — Qwen Code has full channel system
wenshao Apr 3, 2026
11d1ddc
fix: re-number all 69 items sequentially (1-69) + fix cross-file anchors
wenshao Apr 4, 2026
f09bc08
fix: rebuild all 69 anchors + add 3 missing impacts
wenshao Apr 4, 2026
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
131 changes: 131 additions & 0 deletions docs/comparison/computer-use-deep-dive.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
# Computer Use 桌面自动化 Deep-Dive

> AI Agent 能否操作桌面应用——截图、点击、打字、读剪贴板?本文基于 Claude Code(v2.1.89 源码分析)的源码分析,介绍其 Computer Use 桌面自动化架构。Qwen Code 目前无此功能。

---

## 1. 架构总览

```
Claude Code CLI
↓ MCP 协议
Computer Use MCP Server(进程内 stdio 传输)
↓ NAPI
┌─────────────────────────────────┐
│ @ant/computer-use-swift │ ← 截图(SCContentFilter)
│ @ant/computer-use-input (Rust) │ ← 鼠标/键盘(enigo)
└─────────────────────────────────┘
↓ macOS API
NSWorkspace / TCC / IOKit
```

| 维度 | 详情 |
|------|------|
| **集成方式** | MCP Server(进程内,stdio 传输) |
| **截图** | `SCContentFilter`(macOS ScreenCaptureKit) |
| **输入控制** | Rust `enigo` NAPI 绑定 |
| **权限** | TCC Accessibility + Screen Recording |
| **门控** | GrowthBook `tengu_malort_pedway` + Max/Pro 订阅 |
| **工具名** | `mcp__computer-use__*` |

---

## 2. 截图捕获

```typescript
// 源码: utils/computerUse/swiftLoader.ts
// 通过 NAPI 加载 @ant/computer-use-swift
// 方法: captureExcluding(), captureRegion(), screenshot
// JPEG 质量: 0.75
// 坐标缩放: 逻辑坐标 → 物理像素 → API 目标尺寸
```

**终端豁免**:截图时自动隐藏终端窗口(避免截到 Agent 自身 UI)。通过 `getTerminalBundleId()` 检测当前终端:iTerm、Terminal.app、Ghostty、Kitty、Warp、VS Code。

---

## 3. 鼠标/键盘控制

| 操作 | 实现 | 参数 |
|------|------|------|
| `moveMouse()` | 瞬移 + 50ms 稳定延迟 | x, y |
| `click()` | 支持修饰键(press/release 括号化) | button, modifiers |
| `drag()` | ease-out-cubic 动画,60fps,2000px/s,最大 0.5s | start, end |
| `scroll()` | 垂直优先 | dx, dy |
| `key()` / `keys()` | 通过 DispatchQueue.main 分发 | key name, modifiers |
| `holdKey()` | press/release 追踪防止修饰键卡住 | key, action |
| `type()` | 剪贴板粘贴(含回读验证)或直接 typeText() | text |

**Run Loop 排空**:`drainRunLoop()` 确保 main-queue dispatch 事件到达——30s 超时上限,orphan 标志防护。

> 源码: `utils/computerUse/executor.ts`

---

## 4. TCC 权限

```typescript
// 源码: utils/computerUse/hostAdapter.ts#L47-L54
// 启动时检查:
checkAccessibility() // 辅助功能权限(鼠标/键盘控制)
checkScreenRecording() // 屏幕录制权限(截图捕获)
// 两项均需批准才能使用 Computer Use
```

---

## 5. MCP 集成

```typescript
// 源码: utils/computerUse/setup.ts#L23-L53
// Server 配置:
{
type: 'stdio', // 进程内传输
command: process.execPath, // 自身二进制
args: ['--computer-use-mcp'], // MCP 入口
scope: 'dynamic', // 按需启动
}
// 工具名: mcp__computer-use__screenshot, mcp__computer-use__click, ...
// 权限: buildComputerUseTools() 自动添加 allowed tools(绕过权限提示)
```

**CallTool 覆盖**(源码: `utils/computerUse/wrapper.tsx`):拦截 MCP callTool,注入权限对话框、状态管理、锁获取和截图持久化。

---

## 6. 门控与限制

| 门控 | 条件 |
|------|------|
| GrowthBook | `tengu_malort_pedway` 特性开关 |
| 订阅 | Max / Pro 订阅(Ant 用户绕过) |
| 平台 | 仅 macOS(SCContentFilter 依赖) |
| 并发 | 文件锁(`computerUseLock.ts`)防止并发 CU 会话 |
| 中止 | Cmd+Escape 热键(`escHotkey.ts` 通过 event-tap 注册) |

**子门控**(GrowthBook 动态配置):
- `pixelValidation` — 像素级操作验证
- `clipboardPasteMultiline` — 多行剪贴板粘贴
- `mouseAnimation` — 鼠标拖拽动画
- `hideBeforeAction` — 操作前隐藏终端
- `autoTargetDisplay` — 自动选择目标显示器
- `clipboardGuard` — 剪贴板保护

---

## 7. 关键源码文件

| 文件 | 职责 |
|------|------|
| `utils/computerUse/mcpServer.ts` | MCP Server 入口 |
| `utils/computerUse/executor.ts` | 鼠标/键盘/截图执行 |
| `utils/computerUse/hostAdapter.ts` | TCC 权限检查 |
| `utils/computerUse/swiftLoader.ts` | SCContentFilter NAPI |
| `utils/computerUse/inputLoader.ts` | enigo/keyboard NAPI |
| `utils/computerUse/gates.ts` | GrowthBook 门控 |
| `utils/computerUse/setup.ts` | MCP 配置 |
| `utils/computerUse/wrapper.tsx` | CallTool 覆盖 |
| `utils/computerUse/computerUseLock.ts` | 并发文件锁 |
| `utils/computerUse/escHotkey.ts` | Cmd+Escape 中止热键 |

> **免责声明**: 以上分析基于 2026 年 Q1 源码,后续版本可能已变更。Computer Use 仅限 macOS,需 Max/Pro 订阅。
166 changes: 166 additions & 0 deletions docs/comparison/cost-fastmode-deep-dive.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
# 成本追踪与 Fast Mode Deep-Dive

> 用户如何了解 AI Agent 的实际花费?能否在速度和成本之间灵活切换?本文基于 Claude Code(v2.1.89 源码分析)和 Qwen Code(v0.15.0 开源)的源码分析,对比两者在成本追踪、Fast Mode 速度分级和并发会话管理方面的差异。

---

## 1. 架构总览

| 维度 | Claude Code | Qwen Code |
|------|------------|-----------|
| **成本显示** | USD 金额 + 按模型分项 + cache 效率 | Token 计数 + 请求数 + cache 效率百分比 |
| **成本持久化** | 按 session ID 存储在项目配置中 | 无持久化 |
| **Fast Mode** | ✅ Opus 4.6 标准/快速切换($5→$30/Mtok) | ❌(仅 `--fast` 指定备用模型) |

Copilot AI Apr 3, 2026

Copy link

Choose a reason for hiding this comment

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

In the overview table, Fast Mode pricing is summarized as “$5→$30/Mtok”, but later in the same document you describe separate input/output pricing (“$5/$25 → $30/$150 per Mtok”). Please make the overview row consistent (e.g., include both rates or use a neutral wording like “显著更贵”).

Suggested change
| **Fast Mode** | ✅ Opus 4.6 标准/快速切换($5$30/Mtok) | ❌(仅 `--fast` 指定备用模型) |
| **Fast Mode** | ✅ Opus 4.6 标准/快速切换($5/$25 → $30/$150 per Mtok) | ❌(仅 `--fast` 指定备用模型) |

Copilot uses AI. Check for mistakes.

Copilot AI Apr 3, 2026

Copy link

Choose a reason for hiding this comment

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

同一文档内 Fast Mode 的定价表述不一致:这里写“$5→$30/Mtok”,但后文示例又写成“Standard $5/$25 → Fast $30/$150 per Mtok”。建议在总览表里明确是 input/output 两档价格,或用与后文一致的格式,避免读者误解。

Suggested change
| **Fast Mode** | ✅ Opus 4.6 标准/快速切换($5→$30/Mtok) | ❌(仅 `--fast` 指定备用模型) |
| **Fast Mode** | ✅ Opus 4.6 标准/快速切换(Standard $5/$25 → Fast $30/$150 per Mtok) | ❌(仅 `--fast` 指定备用模型) |

Copilot uses AI. Check for mistakes.
| **并发 Session** | ✅ PID 文件追踪 + 后台 Agent 脱附 | 无跨终端追踪 |

---

## 2. Claude Code:USD 成本追踪

### 2.1 成本累计

```typescript
// 源码: cost-tracker.ts
// 每次 API 响应后调用:
addToTotalSessionCost(model, usage)
→ calculateUSDCost(model, usage) // 按定价表计算 USD
→ addToTotalModelUsage(model, usage) // 按模型分项累计
→ getCostCounter().add(cost) // OpenTelemetry 指标
```

### 2.2 /cost 命令输出

```
Total cost: $1.25
Total duration (API): 2m 45s
Total duration (wall): 5m 30s
Total code changes: 25 lines added, 8 lines removed

Usage by model:
Opus 4.6: 100,000 input, 45,000 output, 5,000 cache read, 2,500 cache write ($0.95)
Sonnet 4.6: 50,000 input, 12,000 output ($0.30)
```

**关键信息**:
- USD 金额精确到分
- Cache read / write tokens 分开显示——用户可判断 prompt cache 效率
- 按模型分项——用户可识别哪个模型消耗最多
- API 时间 vs 总时间——区分网络延迟和工具执行时间

### 2.3 会话成本持久化

```typescript
// 源码: cost-tracker.ts
// 保存到项目配置:
saveCurrentSessionCosts() → config.projects[projectPath] = {
lastSessionId, lastCost, lastAPIDuration, lastModelUsage, lastLinesChanged
}
// --resume 恢复时:
restoreCostStateForSession() → 检查 sessionId 匹配后恢复累积成本
```

### 2.4 Fast Mode

```typescript
// 源码: utils/fastMode.ts
// 切换: /fast 命令 或 设置 fastMode: true
// 定价: Opus 4.6 Standard $5/$25 → Fast $30/$150 per Mtok

// 冷却机制:
type FastModeState =
| { status: 'active' }
| { status: 'cooldown'; resetAt: number; reason: 'rate_limit' | 'overloaded' }

// 429 错误 → triggerFastModeCooldown(resetTimestamp, reason)
// 冷却结束 → 自动恢复 active
```

**与重试集成**(源码: `services/api/withRetry.ts`):
- 短 `retry-after`(<20s):保持 Fast Mode 重试(保留 cache)
- 长 `retry-after`:进入冷却,回退到 Standard
- Overage rejection:永久禁用 Fast Mode

### 2.5 并发 Session 管理

```typescript
// 源码: utils/concurrentSessions.ts
// PID 文件: ~/.claude/sessions/{pid}.json
{
pid: 12345,
sessionId: "abc-123",
cwd: "/path/to/project",
kind: "interactive" | "bg" | "daemon" | "daemon-worker",
name: "background-session-name",
startedAt: 1704067200000
}
// countConcurrentSessions() — 扫描 PID 文件,过滤已退出进程
// 自动清理: registerCleanup() 在退出时删除 PID 文件
```

---

## 3. Qwen Code:Token 统计

### 3.1 /stats 命令

```typescript
// 源码: qwen-code/packages/cli/src/ui/components/StatsDisplay.tsx
// 显示内容:
// - Session ID、工具调用(成功/失败)、成功率
// - Wall time、Agent 活跃时间、API 时间占比
// - 按模型分项: 模型名、请求数、输入/输出 tokens
// - Cache 效率: "{cacheEfficiency.toFixed(1)}% of input from cache"
```

### 3.2 无 USD 成本计算

Qwen Code 的 `/stats` 显示 token 数量和 cache 效率百分比,但**不计算 USD 金额**——因为支持多 Provider(Google/Qwen/Anthropic/OpenAI),定价差异大,难以统一计算。

### 3.3 /model --fast

```typescript
// 源码: qwen-code/packages/cli/src/ui/commands/modelCommand.ts
// /model --fast <modelName> → 设置后台任务的备用快速模型
// 与 Claude Code 的 Fast Mode 不同:
// - Claude: 同一模型的不同推理速度(相同 Opus 4.6,不同 QPS/价格)
// - Qwen: 指定另一个更快的模型(如用 Haiku 替代 Opus)
```

---

## 4. 对比

| 维度 | Claude Code | Qwen Code |
|------|------------|-----------|
| 成本单位 | **USD 金额** | Token 数量 |
| 按模型分项 | ✅ 含 cache read/write 分项 | ✅ 含 cache 效率百分比 |
| 成本持久化 | ✅ 跨 `--resume` 累加 | ❌ |
| Fast Mode | ✅ 同模型速度切换 + 冷却 + 重试集成 | ⚠️ `--fast` 指定备用模型(非速度分级) |
| 并发追踪 | ✅ PID 文件 + 后台脱附 | ❌ |
| 代码变更统计 | ✅ lines added/removed | ❌ |

---

## 5. 关键源码文件

### Claude Code

| 文件 | 职责 |
|------|------|
| `cost-tracker.ts` | 成本累计、持久化、/cost 格式化 |
| `utils/modelCost.ts` | 定价表(7 个价格档) |
| `utils/fastMode.ts` | Fast Mode 状态机 + 冷却 |
| `commands/fast/fast.tsx` | /fast 命令 UI |
| `commands/cost/cost.ts` | /cost 命令 |
| `utils/concurrentSessions.ts` | PID 追踪 + 并发计数 |

### Qwen Code

| 文件 | 职责 |
|------|------|
| `packages/cli/src/ui/components/StatsDisplay.tsx` | 统计 UI |
| `packages/cli/src/ui/commands/statsCommand.ts` | /stats 命令 |
| `packages/cli/src/ui/commands/modelCommand.ts` | /model --fast |
| `packages/core/src/telemetry/metrics.ts` | OpenTelemetry 指标 |

> **免责声明**: 以上分析基于 2026 年 Q1 源码,后续版本可能已变更。
Loading