Computer use(计算机操作)
通过 accessibility 树、截图和安全的 UI 操作,让 agent 驱动本地桌面应用。
devcore computer CLI 让 agent 能够检查并控制原生桌面应用——列出正在运行的应用、读取 accessibility 树、点击控件、设置值、输入文本、滚动以及截屏。当某个任务需要操作操作系统或第三方应用(而非终端或内置浏览器)时,就用它。
Beta
Computer use 为每个平台提供了原生辅助程序,并且需要 Accessibility 权限(在 macOS 上还需要 Screen Recording 权限)。命令接口已足够稳定,可供 skill 基于其构建,但 flag 名称仍可能变动。
首次设置
检查运行时和权限:
devcore status --json
devcore computer permissions --json
devcore computer capabilities --json如果 permissions 报告有任何缺失,请在系统设置中为 DevAgent Computer Use 授予 Accessibility 权限(在 macOS 上还需 Screen Recording 权限),然后重新运行 permissions --json 以确认。
Snapshot → act → snapshot
每次交互都遵循同样的循环:读取应用当前状态,对某个特定元素执行操作,然后重新读取状态以验证结果。
devcore computer list-apps --json
devcore computer get-app-state --app com.spotify.client --json
devcore computer click --app com.spotify.client --element-index 42 --json元素索引的作用范围仅限于最近一次 get-app-state 的结果,并且可能是稀疏的。在 --json 输出中,从 result.snapshot.treeText 读取该树。不要根据 elementCount 臆造索引。在导航、焦点变化、滚动或任何应用重新渲染之后,复用某个索引前请刷新状态。
多窗口应用
devcore computer list-windows --app com.microsoft.edgemac --json
devcore computer get-app-state --app com.microsoft.edgemac --window-id <id> --json
devcore computer click --app com.microsoft.edgemac --window-id <id> --element-index 12 --json当列出的 id 不是 none 时,优先使用稳定的 --window-id;否则使用 --window-index。
选择一个应用
优先使用 list-apps 返回的 bundle ID:
devcore computer get-app-state --app com.microsoft.edgemac --json在没有歧义时,应用名称也可以使用(--app Spotify)。仅当 bundle ID 和名称都发生冲突时,才使用 --app pid:<number>。
可用操作
devcore computer click --app <app> --element-index <i> --json
devcore computer set-value --app <app> --element-index <i> --value "text" --json
devcore computer type-text --app <app> --text "text" --json
devcore computer press-key --app <app> --key Return --json
devcore computer hotkey --app <app> --key CmdOrCtrl+A --json
devcore computer paste-text --app <app> --text "text" --json
devcore computer scroll --app <app> --element-index <i> --direction down --json
devcore computer drag --app <app> --from-x 100 --from-y 100 --to-x 300 --to-y 300 --json
devcore computer perform-secondary-action --app <app> --element-index <i> --action <name> --json优先使用语义化操作(click、set-value、perform-secondary-action),而非原始的 type-text 或 press-key——它们直接定位 accessibility 元素,并且在焦点变化时依然有效,而键盘输入则做不到。
当 accessibility 定位失败时,谨慎地回退到坐标方式:
devcore computer click --app com.apple.Safari --x 120 --y 340 --json
devcore computer drag --app <app> --from-element-index 3 --to-element-index 9 --json敏感输入
通过 stdin 传入密钥,避免它们出现在 shell 历史记录中:
printf '%s' "$TEXT" | devcore computer set-value \
--app com.apple.Safari --element-index 7 --value-stdin --json--text-stdin 对 type-text 和 paste-text 的用法相同。
截图
get-app-state 返回一棵 accessibility 树,并默认返回一张截图。使用 --json 时,图像字节会被写入磁盘,路径通过 screenshot.path 返回,而不是嵌入在响应中。当不需要像素时,传入 --no-screenshot(更快、载荷更小)。传入 --restore-window 可在截图前将隐藏或最小化的窗口显示到前台。
在 agent 中使用
随附的 computer-use skill 将同样的命令接口连同安全指引打包在一起。将它安装到 agent 的 skill 目录:
npx skills add https://github.com/Clouditera/devagent-skills --skill computer-use关于 skill 如何被识别加载,参见 Skills registry & MCP。
后续步骤
- DevCore CLI overview — CLI 的其余接口(worktree、终端、浏览器)。
- Skills registry & MCP — 将此 CLI 分发给 agent。