跳过主要内容
C

dsh-cua-desktop

cotton1candy/dsh-cua-desktop

把 ChatGPT 桌面端自带的电脑操控运行时接入 DSH profile:以 stdio MCP 服务器暴露其常驻 JavaScript 内核,agent 通过 mcp__cua__js 在 Chrome 与任意 macOS 应用中点击、输入、滚动、读取无障碍树并截图。需 ChatGPT.app、Codex/ChatGPT Chrome 扩展,以及 macOS 辅助功能与屏幕录制权限。

安装

dsh plugin --profile web add github:cotton1candy/dsh-cua-desktop

README

dsh-cua-desktop

A DSH bundle that gives every agent in the profile hands-on control of Chrome and any macOS app, using the computer-use runtime that already ships inside ChatGPT.app — the same runtime Codex desktop uses for its computer-use feature.

That runtime does not need the ChatGPT app process, and in its local browser mode it never calls OpenAI. cua_repl is a local MCP stdio server that runs a persistent JavaScript kernel with the cua API.

DSH agent → mcp__cua__js
              │
              ▼
        /bin/sh bootstrap (finds a Node runtime, materialises the launcher)
              │
              ▼
        cua-repl  (ChatGPT.app/Contents/Resources/cua_node/…/@oai/cua-repl)
              │
              ▼
        node_repl  (MCP stdio server, persistent JS kernel)
              ├── browser service ──► ChatGPT browser extension ──► Chrome (native messaging)
              └── sky service     ──► SkyComputerUseService     ──► macOS AX + screen

Installed with plugin_manager install_bundle; it lives at the profile level, so it applies to every workspace and every session in the profile, not to the folder it was built in.

Tools

ToolWhat it is
mcp__cua__jsRun JavaScript in a persistent kernel: cua.getApp(), cua.listApps(), cua.getBrowser(), cua.createBrowserTab(), cua.getTab(), plus per-target click, typeText, pressKey, scroll, getAXState, getScreenshot, Playwright locators, and nodeRepl.write() / nodeRepl.emitImage().
mcp__cua__js_resetDrop all JavaScript bindings and start a fresh kernel.
mcp__cua__js_add_node_module_dirAdd a node_modules directory for import inside the kernel.

The js description is the runtime's own documentation (API reference, accessibility workflow, computer-use confirmation policy). turn_ended is intentionally hidden: the launcher drives it itself when the MCP server shuts down.

Requirements

  1. ChatGPT.app in /Applications (override with DSH_CUA_CHATGPT_APP). The bundle reads the runtime out of ChatGPT.app/Contents/Resources; the app is never launched.
  2. Chrome + the Codex/ChatGPT browser extension (hehggadaopoacecdllhhajmbjkdcmajg) installed, enabled, and its native-messaging host (com.openai.codexextension) registered.
  3. macOS Accessibility (required) and Screen Recording (screenshots) for the computer-use helper, i.e. SkyComputerUseService / Codex Computer Use. If the ChatGPT app has used computer use before, these are already granted.

No configuration is required.

Configuration

The patch declares each knob explicitly because DSH strips DSH_* names from MCP child environments. Set them in the DSH process environment before starting DSH:

VariableDefaultMeaning
DSH_CUA_SURFACESbrowser,computerWhich surfaces to enable (browser, computer).
DSH_CUA_APPROVALSacceptHow to answer the runtime's approval elicitations: accept, deny, or forward (for clients that can render them).
DSH_CUA_WAKE_CHROME1Wake Chrome's extension host when nothing is listening. 0 disables.
DSH_CUA_DEFAULT_TIMEOUT_MS180000Default per-js-call timeout injected when the agent omits timeout_ms.
DSH_CUA_CHATGPT_APP/Applications/ChatGPT.appAlternate app bundle.
DSH_CUA_NODEdiscoveredNode executable for the launcher.
DSH_CUA_DEBUG01 logs discovery/approval decisions to the MCP server's stderr.

What the launcher does beyond starting the runtime

  • Discovery. Finds cua_node, cua-repl, the browser service (app bundle or the newest ~/.codex/plugins/cache/openai-bundled/browser/*), the local codex CLI, the Sky service bundle and the app version on every start.
  • CODEX_CLI_PATH. node_repl needs a sandbox supervisor. Without one it runs the kernel unsandboxed, the privileged native-pipe bridge never reaches the browser trusted worker, and the Chrome backend silently reports zero browsers. The supervisor is the codex binary inside ChatGPT.app — a local process that only listens on stdio.
  • Turn metadata. The browser backend refuses to work without x-codex-turn-metadata (session_id, turn_id). Codex sends it per tool call; DSH does not, so the launcher injects it into every tools/call.
  • Approvals. The first time an app is driven, the Sky backend asks Allow Computer Use to use "<app>"? as an MCP elicitation. DSH's MCP client cannot render form elicitations, so the request used to fail the call. The launcher advertises the capability to the runtime on DSH's behalf and answers the request (accept by default, logged with DSH_CUA_DEBUG=1). Set DSH_CUA_APPROVALS=deny to refuse instead.
  • Chrome wake-up. Chrome spawns the extension's native-messaging host lazily. With the ChatGPT app closed and Chrome idle there is no host, so no browser is discovered. The launcher activates Chrome once (and opens one blank tab only if that is not enough) and waits for the host socket to accept a connection.
  • Tab lifetime. Codex closes the tabs it created via a turn_ended hook at the end of a turn. DSH has no such boundary, so the launcher sends turn_ended when the MCP server shuts down; during a session the agent should close what it opened (await tab.close()) or mark what must survive (tab.markDeliverable()).

Sandbox: what the kernel can and cannot do

Every process the runtime spawns is supervised by the codex sandbox. Observed launch line:

codex sandbox -c default_permissions="node_repl" \
  -c permissions.node_repl={filesystem = {... = "read", ":root" = "read"},
                            network = {enabled = false}} \
  -- node --experimental-vm-modules kernel.js

Consequences worth knowing:

  • The JavaScript kernel has no network access. Navigating a page is done by Chrome, not by the kernel; the kernel cannot fetch anything itself.
  • The kernel's filesystem is read-only. Screenshots and other binary results must come back through nodeRepl.emitImage(...); fs.writeFileSync inside the kernel fails with EPERM by design.

A live session was measured to open no non-loopback sockets from any process in its tree (python → launcher → cua_repl → node_repl → codex sandbox / codex app-server).

Troubleshooting

SymptomCause and fix
browsers: [] with no errorNo listening extension host. Restart Chrome, or let the launcher wake it (DSH_CUA_DEBUG=1 shows the decision). A host that was killed mid-flight can stay wedged until Chrome restarts.
Missing required Codex turn metadataThe launcher did not inject metadata — check that the MCP server being used is this bundle's row.
nodeRepl.createElicitation is unavailableThe run bypassed the launcher; the raw cua_repl server cannot answer approvals for DSH.
EPERM writing a file from the kernelExpected: the kernel is read-only. Use nodeRepl.emitImage.
No apps, only browsersSky service missing or Accessibility permission revoked for the computer-use helper.

Verify

node src/cua-runtime.cjs --print-config   # what it discovered
node src/cua-runtime.cjs --selftest       # start the runtime, print app/browser counts

Development

node scripts/build-patch.mjs   # regenerate cordis.patch.yml from src/cua-runtime.cjs

cordis.patch.yml is generated: it embeds src/cua-runtime.cjs because a linked bundle cannot know its own installed path when the patch is composed. Edit the source, rebuild, then remove_bundle + install_bundle to pick up patch changes (locale/docs are read live).

Verified

  • Chrome through the extension: tab create/navigate/AX read/screenshot/close, on example.com and example.org, with the ChatGPT app both running and quit.
  • Native macOS AX: Calculator, TextEdit and Google Chrome accessibility trees plus screenshots.
  • Installed row: plugin_manager reports application: applied; list_bundles shows dsh-cua-desktop 1.0.0, enabled: true, row cua-runtime → @deepseek-ai/dsh-mcp-client, and the three tools appear in a live agent tool list.
  • Cold start with ChatGPT.app quit: native apps worked immediately; Chrome needed the extension host, which the launcher wakes.

相关插件