Files
claude-code/docs/features/computer-use.md
claude-code-best c5edee431f docs: 文档检查/check 20260419 (#296)
* docs: 修复文档巡检发现的 4 处错误

- daemon.md: 反映实际实现状态(supervisor/worker 已实现而非 stub)
- bridge-mode.md: API 操作数量从 7 修正为 9
- web-search-tool.md: 文件路径从 src/tools/ 修正为 packages/builtin-tools/src/tools/
- remote-control-self-hosting.md: 补充缺失的 RCS_WS_IDLE_TIMEOUT 和 RCS_WS_KEEPALIVE_INTERVAL 配置项

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

* docs: 修正 Safety 和 Context 文档中的代码引用和类型错误

- permission-model: 修正规则来源从"五层"到八层,优先级顺序对齐代码
- permission-model: PermissionUpdate 类型改为实际的 addRules/replaceRules 等
- permission-model: 补充 acceptEdits 和 dontAsk 两种权限模式
- permission-model: DENIAL_LIMITS 字段名对齐实际代码
- plan-mode: 工具路径从 src/tools/ 改为 packages/builtin-tools/src/tools/
- compaction: 修正 COMPACTABLE_TOOLS 和 POST_COMPACT_* 的行号
- project-memory: 修正 ENTRYPOINT_NAME 常量的行号
- system-prompt: 修正 SystemPrompt 类型定义文件路径和多个行号引用

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

* docs: 修复 introduction 文档中的错误路径和行号引用

- why-this-whitepaper.mdx: BashTool 路径从 src/tools/ 修正为 packages/builtin-tools/src/tools/
- what-is-claude-code.mdx: 移除不存在的 Azure provider,改为实际的 7 种 provider
- architecture-overview.mdx: State 类型行号从 204 修正为 207

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

* docs: 修复 conversation/features 文档中的错误

- streaming.mdx: queryStreamRaw → queryModelWithStreaming 函数名修正
- streaming.mdx: Azure 提供商不存在,替换为实际 7 个提供商
- debug-mode.mdx: --inspect-wait 描述错误,实际使用 BUN_INSPECT 环境变量
- buddy.mdx: 补充缺失的 companionReact.ts、CompanionCard.tsx、index.ts

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

* docs: 修复文档巡检中的源码引用错误

- feature-flags.mdx: 修正 feature() 兜底描述,实际从 bun:bundle 导入而非 cli.tsx:3 内联
- feature-flags.mdx: 修正工具 require 路径为 @claude-code-best/builtin-tools 包路径
- ant-only-world.mdx: 修正 tools.ts 中 require 路径为包路径
- ant-only-world.mdx: 修正 INTERNAL_ONLY_COMMANDS 行号 (267-295) 和数量 (24+)
- skills.mdx: 修正 COMMANDS memoize 行号 258 → 299
- mcp-protocol.mdx: 修正 fetchToolsForClient LRU 缓存上限 20 → 100
- streaming.mdx: 修正流式事件引用
- file-operations.mdx: 修正工具路径引用
- search-and-navigation.mdx: 修正搜索工具引用
- shell-execution.mdx: 修正 shell 工具引用
- buddy.mdx: 补充缺失的 frontmatter 字段
- debug-mode.mdx: 修正调试模式描述

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

* docs: 修正 tools/agent 文档中的文件路径和行号引用

- 修正 TodoWriteTool、AgentTool、ToolSearchTool 等工具路径
  src/tools/ → packages/builtin-tools/src/tools/
- 更新 Tool.ts、tools.ts、BashTool.tsx 中过时的行号引用
- 修正 WebSearchTool/WebFetchTool/EnterWorktreeTool/ExitWorktreeTool 路径
- 修正 AgentTool.tsx 中多行行号引用

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

* docs: 修正 feature 文档中的文件路径和行号引用

- ultraplan.md: 更新文件行数(525/349/127)
- fork-subagent.md: 路径迁移 src/tools/ → packages/builtin-tools/
- mcp-skills.md: 修正 getMcpSkillCommands 行号 547→604,client.ts 行号 117→129
- kairos.md: 修正 getBriefSection/getProactiveSection 行号
- proactive.md: 修正 getProactiveSection 行号 860→864

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

* docs: 修正顶层文档中的路径迁移和行号引用

- auto-updater.md: config.ts 行号 1735→1737,标注未接入启动流程的函数
- external-dependencies.md: WebSearchTool/WebFetchTool 路径迁移到 builtin-tools 包,Vertex 行号修正
- lsp-integration.md: LSPTool 路径从 src/tools/ 迁移到 packages/builtin-tools/
- stub-recovery-design-1-4.md: 修正 Windows 绝对路径链接为标准代码引用

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

* docs: 修正 task 文档中的文件扩展名和路径引用

- task-004: AssistantSessionChooser.ts → .tsx, assistant.ts → .tsx
- task-003: cli.tsx 行号 249→272, markdownConfigLoader.ts 行号 29→35
- lan-pipes: SendMessageTool 路径迁移到 packages/builtin-tools/

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

* docs: 补充 computer-use-tools-reference 缺失的 Windows 工具

添加遗漏的 open_terminal 和 activate_window 两个 Windows 专属工具,
修正工具总数 37→39,Windows 工具数 10→12。

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

* docs: 修正 audit/bash-classifier/token-budget/tree-sitter 文档

- feature-flags-audit: ScheduleCronTool 路径迁移、DAEMON 状态更新为 COMPLETE、assistant 文件标记已补全、UDS 标记已实现
- bash-classifier: BashPermissionRequest 文件路径修正、withRetry 行号移除
- token-budget: attachments.ts 行号范围修正
- tree-sitter-bash: bashPermissions.ts 路径迁移到 packages/builtin-tools

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

* docs: 修正 langfuse-monitoring AgentTool 路径迁移

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

* docs: 修正 bridgeApi 行号和 Tool.ts 行号引用

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

* docs: 修正 Safety/Extensibility 文档中的工具路径迁移和行号引用

- sandbox.mdx: shouldUseSandbox.ts 和 bashPermissions.ts 路径迁移至 packages/builtin-tools
- why-safety-matters.mdx: bashPermissions.ts 路径迁移(3 处)
- plan-mode.mdx: EnterPlanModeTool/prompt.ts 路径迁移
- auto-mode.mdx: Auto mode 指令行号 3464→3481
- hooks.mdx: AgentTool/runAgent.ts 路径迁移
- skills.mdx: SkillTool.ts 路径迁移
- custom-agents.mdx: Agent built-in 目录和 exploreAgent.ts 路径迁移

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

* docs: 修正 internals 文档引用计数和路径

- ant-only-world: USER_TYPE 引用计数 465→410+,工具路径迁移到 builtin-tools
- growthbook-ab-testing: growthbook.ts 行数 1156→1258
- hidden-features: 语音模式状态更新(audio-napi 已恢复)

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

* docs: 修正工具文档中的行号引用

- sub-agents: AgentTool.call 入口行号 340→387
- shell-execution: ShellCommand onTimeout 行号 129→144

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

* docs: 修正 feature 文档中的状态、路径和计数

- all-features-guide: 修正 feature flag 启用范围(dev only vs dev+build)
- tier3-stubs: 大量状态修正(stub→已实现),缩减过时条目
- workflow-scripts: 路径迁移到 builtin-tools,状态更新
- web-browser-tool: 工具状态缺失→已实现,路径迁移
- context-collapse: CtxInspectTool 状态缺失→已实现
- computer-use: 行号引用更新,平台分发描述修正
- computer-use-tools-reference: 工具数 39→38
- voice-mode: voiceModeEnabled 行数 55→54

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

* docs: 更新 the-loop 查询循环行号引用

query.ts 代码变更后终止原因行号整体偏移约 40 行

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

* docs: 补充 feature-flags-audit 完整 build 默认 feature 列表

添加 ULTRATHINK/LODESTONE/ACP/DAEMON 等 19 个缺失的 build 默认 feature,
修正 dev-only 特征标注(UDS_INBOX/LAN_PIPES/BG_SESSIONS/TEMPLATES)

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

* docs: 修正 feature-flags-audit ConfigTool 路径迁移

ConfigTool 路径从 src/tools/ 迁移到 packages/builtin-tools/src/tools/

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

* docs: 修正 feature-flags-audit BashTool 路径迁移

BashTool 路径从 src/tools/ 迁移到 packages/builtin-tools/src/tools/

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

* docs: 修正 feature-flags-audit SkillTool 路径迁移

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

* docs: 更新 feature-flags-audit WorkflowTool 状态为已实现

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

---------

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-19 09:30:00 +08:00

9.4 KiB
Raw Blame History

Computer Use — macOS / Windows / Linux 跨平台实施计划

更新时间2026-04-03 参考项目:E:\源码\claude-code-source-main\claude-code-source-main

1. 现状

参考项目的 Computer Use 仅支持 macOS——从入口到底层全部写死 darwin。我们的项目在 Phase 1-3 中已经完成了:

  • @ant/computer-use-mcp stub 替换为完整实现12 文件)
  • @ant/computer-use-input 拆为 dispatcher + backendsdarwin + win32
  • @ant/computer-use-swift 拆为 dispatcher + backendsdarwin + win32
  • CHICAGO_MCP 编译开关已开
  • src/ 层 macOS 硬编码已移除Phase 2 已完成)

2. 阻塞点全景

2.1 入口层

# 文件:行号 阻塞代码 影响
1 src/main.tsx:2366 feature("CHICAGO_MCP") 门控 CU 初始化入口

2.2 加载层

# 文件:行号 阻塞代码 影响
2 src/utils/computerUse/swiftLoader.ts macOS-only loader已改为仅 darwin 加载) 非 darwin 使用 platforms/ 替代
3 src/utils/computerUse/executor.ts:302 process.platform !== 'darwin' → cross-platform executor 非 darwin 走跨平台路径

2.3 macOS 特有依赖

# 文件:行号 依赖 macOS 实现 需要替代方案
4 executor.ts:72-96 剪贴板 pbcopy/pbpaste / PowerShell / xclip Win: PowerShell Get/Set-ClipboardLinux: xclip/wl-copy
5 drainRunLoop.ts CFRunLoop pump cu._drainMainRunLoop() 非 darwin直接执行 fn(),不需要 pump
6 escHotkey.ts ESC 热键 CGEventTap 非 darwin返回 false已有 Ctrl+C fallback
7 hostAdapter.ts 系统权限 TCC accessibility + screenRecording Win直接 grantedLinux检查 xdotool
8 common.ts:55-58 平台标识 动态获取 已改为 process.platform 分发
9 executor.ts:232 粘贴快捷键 command/ctrl 分发 已按平台分发粘贴快捷键

2.4 缺失的 Linux 后端

macOS Windows Linux
computer-use-input/backends/ darwin.ts win32.ts 需新建 linux.ts
computer-use-swift/backends/ darwin.ts win32.ts 需新建 linux.ts

3. 每个平台的能力依赖

3.1 computer-use-input键鼠

功能 macOS Windows Linux
鼠标移动 CGEvent JXA SetCursorPos P/Invoke xdotool mousemove
鼠标点击 CGEvent JXA SendInput P/Invoke xdotool click
鼠标滚轮 CGEvent JXA SendInput MOUSEEVENTF_WHEEL xdotool scroll
键盘按键 System Events osascript keybd_event P/Invoke xdotool key
组合键 System Events osascript keybd_event 组合 xdotool key combo
文本输入 System Events keystroke SendKeys.SendWait xdotool type
前台应用 System Events osascript GetForegroundWindow P/Invoke xdotool getactivewindow + /proc
工具依赖 osascript内置 powershell内置 xdotool需安装

3.2 computer-use-swift截图 + 应用管理)

功能 macOS Windows Linux
全屏截图 screencapture CopyFromScreen gnome-screenshot / scrot / grim
区域截图 screencapture -R CopyFromScreen(rect) gnome-screenshot -a / scrot -a / grim -g
显示器列表 CGGetActiveDisplayList JXA Screen.AllScreens xrandr --query
运行中应用 System Events JXA Get-Process wmctrl -l / ps
打开应用 osascript activate Start-Process xdg-open / gtk-launch
隐藏/显示 System Events visibility ShowWindow/SetForegroundWindow wmctrl -c / xdotool
工具依赖 screencapture + osascript powershell xdotool + scrot/grim + wmctrl

3.3 executor 层

功能 macOS Windows Linux
drainRunLoop CFRunLoop pump 不需要 不需要
ESC 热键 CGEventTap 跳过Ctrl+C fallback 跳过Ctrl+C fallback
剪贴板读 pbpaste powershell Get-Clipboard xclip -o / wl-paste
剪贴板写 pbcopy powershell Set-Clipboard xclip / wl-copy
粘贴快捷键 command+v ctrl+v ctrl+v
终端检测 __CFBundleIdentifier WT_SESSION / TERM_PROGRAM TERM_PROGRAM
系统权限 TCC check 直接 granted 检查 xdotool 安装

4. 执行步骤

Phase 1已完成

  • @ant/computer-use-mcp stub → 完整实现
  • @ant/computer-use-input dispatcher + darwin/win32 backends
  • @ant/computer-use-swift dispatcher + darwin/win32 backends
  • CHICAGO_MCP 编译开关

Phase 2移除 6 处 macOS 硬编码(解锁 macOS + Windows

改动原则macOS 代码路径不变,只在每处 darwin 守卫后加 win32/linux 分支。

步骤 文件 改动
2.1 src/main.tsx:2366 feature("CHICAGO_MCP") → 已为跨平台入口
2.2 src/utils/computerUse/swiftLoader.ts 已改为仅 darwin 加载,非 darwin 使用 platforms/
2.3 src/utils/computerUse/executor.ts:302-309 已改为 cross-platform dispatch非 darwin → createCrossPlatformExecutor
2.4 src/utils/computerUse/executor.ts:72-96 剪贴板已按平台分发darwin→pbcopy/pbpastewin32→PowerShelllinux→xclip
2.5 src/utils/computerUse/executor.ts:232 粘贴快捷键已按平台分发darwin→command其他→ctrl
2.6 src/utils/computerUse/executor.ts:302-309 非 darwin 已改为 createCrossPlatformExecutor()
2.7 src/utils/computerUse/drainRunLoop.ts 非 darwin 无需 pump直接执行 fn
2.8 src/utils/computerUse/escHotkey.ts 非 darwin 返回 false已有 Ctrl+C fallback
2.9 src/utils/computerUse/hostAdapter.ts 非 darwin 权限检查逻辑已实现
2.10 src/utils/computerUse/common.ts:58 已改为动态 process.platform 分发
2.11 src/utils/computerUse/common.ts:55 已改为 darwin→'native',其他→'none'
2.12 src/utils/computerUse/gates.ts:55 已更新(需验证 enabled 默认值)
2.13 src/utils/computerUse/gates.ts:39 hasRequiredSubscription() 已更新

Phase 3新增 Linux 后端

步骤 文件 内容
3.1 packages/@ant/computer-use-input/src/backends/linux.ts xdotool 键鼠mousemove/click/key/type/getactivewindow
3.2 packages/@ant/computer-use-swift/src/backends/linux.ts scrot/grim 截图 + xrandr 显示器 + wmctrl 窗口管理
3.3 packages/@ant/computer-use-input/src/index.ts dispatcher 加 case 'linux'
3.4 packages/@ant/computer-use-swift/src/index.ts dispatcher 加 case 'linux'

Phase 4验证

测试项 macOS Windows Linux
build 成功 验证 验证
MCP 工具列表非空 验证 验证 验证
鼠标移动 验证 已通过 验证
截图 验证 已通过 验证
键盘输入 验证 验证 验证
前台窗口 验证 已通过 验证
剪贴板 验证 验证 验证

5. 文件改动总览

不动的文件14 个)

cleanup.tscomputerUseLock.tswrapper.tsxtoolRendering.tsxmcpServer.tssetup.tsappNames.tsinputLoader.tssrc/services/mcp/client.ts@ant/computer-use-mcp/src/*Phase 1 已完成)、backends/darwin.ts(两个包都不动)

改 src/ 的文件8 个)

文件 改动量 风险
main.tsx 1 行
swiftLoader.ts 2 行
executor.ts ~40 行(剪贴板分发 + 平台守卫 + paste 快捷键)
drainRunLoop.ts 1 行
escHotkey.ts 3 行
hostAdapter.ts 5 行
common.ts 3 行
gates.ts 3 行

新增文件2 个)

文件 行数估算
packages/@ant/computer-use-input/src/backends/linux.ts ~150 行
packages/@ant/computer-use-swift/src/backends/linux.ts ~200 行

6. Linux 依赖工具

工具 用途 安装命令Ubuntu
xdotool 键鼠模拟 + 窗口管理 sudo apt install xdotool
scrotgnome-screenshot 截图 sudo apt install scrot
xrandr 显示器信息 通常已预装
xclip 剪贴板 sudo apt install xclip
wmctrl 窗口列表/切换 sudo apt install wmctrl

Wayland 环境需要替代工具:ydotool(替代 xdotoolgrim(替代 scrotwl-clipboard(替代 xclip。初期可先只支持 X11Wayland 标记为 todo。

7. 执行顺序建议

Phase 2解锁 macOS + Windows
  ├── 2.1-2.3  移除 3 处硬编码 throw/skip
  ├── 2.4-2.5  剪贴板 + 粘贴快捷键平台分发
  ├── 2.6      swiftLoader → 直接实例化
  ├── 2.7-2.9  drainRunLoop / escHotkey / permissions 平台分支
  ├── 2.10-2.11 common.ts 平台标识动态化
  ├── 2.12-2.13 gates.ts 默认值
  └── 验证 Windows

Phase 3Linux 后端)
  ├── 3.1  input/backends/linux.ts
  ├── 3.2  swift/backends/linux.ts
  ├── 3.3-3.4  dispatcher 加 linux case
  └── 验证 Linux

Phase 4集成验证 + PR

每个 Phase 可独立验证、独立提交。Phase 2 完成后 macOS + Windows 可用Phase 3 完成后三平台全部可用。