Skip to content

Standalone cua: native runtime, Keychain secret substitution, existing Chrome profiles - #1

Merged
SSFSKIM merged 123 commits into
mainfrom
feat/chrome-existing-profile
Oct 4, 2026
Merged

SSFSKIM merged 123 commits into
mainfrom
feat/chrome-existing-profile

Conversation

@SSFSKIM

@SSFSKIM SSFSKIM commented Oct 4, 2026

Copy link
Copy Markdown
Owner

Summary

Standalone cua: an MCP server that lets Claude Code drive OpenAI's cua_repl without the Codex/ChatGPT desktop app running, with Keychain-backed secret substitution and the user's existing Chrome profiles through the original OpenAI extension route.

Spec and record: docs/doperpowers/specs/2026-10-02-standalone-cua-design.md (Progress, Decision Log, Surprises, Outcomes & Retrospective). Execution reports: 2026-10-02-standalone-cua-execution-report.md (A+B) and 2026-10-03-phase-c-execution-report.md (C). Evidence per milestone under docs/evidence/.

Phase A — standalone native runtime (M1–M3, M6)

  • cua install extracts the pinned official release archive (sha256-verified) into ~/Library/Application Support/cua/runtimes/<release>/, keeping signatures and sandbox intact; cua doctor re-verifies.
  • cua serve is a per-connection MCP server over the vendor node_repl with a server-owned task id, end_task, and fail-closed teardown.
  • Observed: the release's own copy of the native helper cold-starts with the desktop app closed (desktop still installed; fresh-TCC and desktop-absent operation remain open release gates).

Phase B — secret substitution (M4–M5)

  • Swift cua-keychain helper (SecItem) behind a secure TTY prompt; cua secrets add|list|remove.
  • Trusted-side wrappers replace whole {{secret:<label>}} references in paste/type_text/set_value (native) and playwright_locator_fill/tab_ax_action (browser). The REPL never sees the value. Live round trips into TextEdit and into a Chrome page pass with no value in the transport, stderr, screenshots or state.

Phase C — existing Chrome profiles (M7–M13)

  • Browser surface over the original OpenAI extension + native host, in the user's own profiles (cookies, logins, password manager untouched). Requires the server's own cua login in its private CODEX_HOME.
  • Profile registry (cua profiles add|bind|remove, profiles_list tool): personal/work/school → Chrome profile directories; bind by the user's explicit pick (vendor enrichment never labels a backend on this Mac).
  • cua chrome register [--replace] | unregister: place the release's own Chrome plugin host, replace native-messaging manifests only on explicit --replace with per-browser backups, and restore byte-for-byte (hash-verified). Live: Chrome launched cua's host; round trip 17/17 through it; all manifests restored to the pre-gate hash.
  • scripts/accept-chrome.mjs --all: C1–C7 PASS on this Mac.

Verification

  • npm test 341/341; helper suites Swift 55 + Node 7; probe suites 42/42, 11/11, 15/15; clean clone passes npm pack --dry-run.
  • Independent reviews per milestone (astra-high) and a whole-branch reviewer-high review, all fix waves landed.

Known limits / residue

  • All live evidence was gathered with the desktop app installed. Clean-machine, fresh-TCC, Developer ID signing and desktop-absent runs are open release gates.
  • Extension disable/enable or reinstall mints a new instance id; the binding goes stale and profiles list still reports it ready until rebound (tracked residue).
  • User-tab operations, downloads, dialogs, frames and tab-group side effects untested on this route.
  • wip/m8-playwright-transport holds the parked login-free alternative.
  • One mislabelled commit (c5e0e27) carries part of a concurrent spec edit; noted in the Decision Log.

SSFSKIM added 30 commits October 2, 2026 08:50
…er (M1)

Adds scripts/probe-runtime.mjs, a read-only probe that launches the pinned
runtime from a scratch CUA_HOME with an allowlisted environment, completes the
MCP handshake, runs cua.getState() through a no-op trusted sky wrapper, calls
turn_ended, and records signatures, process ancestry, the native helper that
served, and whether a probe-owned unix socket is reachable from the trusted
worker and from untrusted cells with and without a sandbox socket allowance.
Pure helpers are unit-tested under the new Node test runner. Sanitized findings
are in docs/evidence/m1-runtime-portability.md.
Adds the checked-in 26.928.40906 darwin-arm64 pin and src/runtime: strict pin
parsing and installed-runtime resolution, verified archive or official-URL
acquisition with staging, ditto extraction of only the pinned components,
layout/vendor-manifest/IPC/codesign team checks, atomic activation and
`runtime use`, a passive doctor that separates installed-runtime health from
live-helper and permission evidence, and the allowlisted launch record with
CUA_REPL_ENABLED_SURFACES=computer. bin/cua.mjs routes install, doctor and
runtime use. Node-only tests cover mechanics on ditto-built fixture archives;
real-archive and download installs are recorded in docs/evidence/m2-installer.md.
… and use (M2 review)

An existing release tree is never replaced or deleted: a verified one is a
no-op, a damaged one fails installed_release_invalid with offline recovery
guidance, and a target that is not a real directory with a valid install
record (file, symlink, empty dir, bad install.json) fails target_occupied
untouched. Placement claims the target with an exclusive mkdir before the
rename. resolveRuntime, runtime use and doctor validate the pin against the
host. A JSON-null vendor manifest is a failed check, and doctor's human
verdict says live capability is unverified while checks are blocked.
`cua serve` resolves the installed runtime, launches it through buildLaunch in its own
process group and an owned 0700 run directory, and serves one connection with a random
session ID. The model sees js, js_reset, end_task and secrets_list (unavailable until M4);
turn_ended and js_add_node_module_dir stay private.

src/mcp/task.mjs is the Idle/Active/Ending/Failed/Closing state machine: serialized work
stamped with the task as turn ID, completion only after quiescence plus an acknowledged
turn_ended within one 5 s deadline, terminal rejection and exactly-once settlement on any
uncertainty, and no revival from late replies. src/mcp/server.mjs routes JSON-RPC with
proxy-owned upstream IDs, forwards cancellations and elicitation answers unqueued, keeps
MIME correction and approval persistence. src/mcp/upstream.mjs tears down the owned
process group (EOF, SIGTERM, SIGKILL within a 5 s budget) and never signals the helper.

cua-shim.mjs becomes a thin entry for `cua serve`; the CLI moves to src/cli.mjs. The
plugin drops its Stop/SubagentStop turn_ended hooks and the CODEX_HOME override;
verify.mjs checks the four-tool surface, task IDs and relocated executables live.
Evidence: docs/evidence/m3-mcp-lifecycle.md.
…nd close (M3 review)

The runtime's process group is now led by a server-owned anchor (src/mcp/anchor.mjs)
that starts the vendor launcher inside the group and stays alive until the last
signal. Group signals are sent only while the anchor's exit is unobserved; if its
identity is lost, teardown signals nothing and reports cleanup unconfirmed. Teardown
waits for the launch before judging membership, confirms SIGKILL against the members
listed while the anchor held the group, and leaves no timer behind.

Work is dispatched synchronously with its in-flight transition, so a cancel in the
same input chunk is forwarded. Losing the client output enters the Closing path like
EOF. After the 1 s flush budget the transport is destroyed, and `cua serve` exits
after its owned cleanup even if something else holds the loop.

Host notes, end_task and the README say that cancellation does not stop a running
cell, js_reset waits for it, timeout_ms bounds runaway work, and native cleanup after
forced teardown is unconfirmed. The package now ships the helper verify.mjs imports.
…ting (M3 re-review)

The anchor now takes `launch` and `stop` messages and acknowledges `stop` only after
any launch has been handed to the kernel. Teardown judges group emptiness only after
that acknowledgement, so no runtime can be launched after the group was accepted as
empty.

Confirmation is read-only and covers the whole group. The anchor's exit must be
observed, then `pgrep -g` must list the group empty. Failed group signals, a surviving
anchor or member, and a failed or timed-out listing all report unconfirmed, with a
reason. Nothing is signalled after the final signal or once the anchor's exit has
been observed.

Every enumeration is bounded by the remaining budget, and its process is killed on
timeout. The escalation collapses to one path: release the anchor when only it is
left, otherwise SIGTERM then SIGKILL.
…er connection over a private broker (M4)

native/keychain: production cua-keychain (hidden terminal set, list, confirmed
remove, broker over a 0600 unix socket with a stdin-delivered capability token,
framed and bounded wire) and test-owned in-memory test host and pty driver.
cua secrets set|list|remove route to it; serve starts one broker per connection
before the runtime and stops it with the runtime; secrets_list lists labels
through it; doctor reports helper build and signing. npm run build:helper and
npm run test:helper exercise the actual helper; npm test stays Node-only; an
opt-in live roundtrip touches one disposable Keychain item.
…p secrets usage errors value-free and harden reply decoding (M4 review)

- Restoring the terminal flushes unread input, and an early stop (overlong
  paste, cancel) first drains what is still arriving, so no hidden byte reaches
  the next reader or is echoed.
- The server records the broker socket's device and inode once the helper is
  ready and removes only that socket; a broker that never became ready, or a
  replaced path, is left alone.
- cua secrets argument errors are fixed messages, never parser text.
- The broker client settles any connect/attach/write failure once as
  disconnected and closes the stream; replies must be valid UTF-8 and exactly
  one frame.
…nside the trusted sky service (M5)

The production trusted sky service (src/services/sky.mjs) is registered for every connection and delegates to the
vendor sky service; only the whole text of paste/type_text or value of set_value in their pinned shapes expands,
read from the connection's broker over nodeRepl.nativePipe. Invalid or unknown labels, denied or locked Keychain,
secrets off or unavailable and unsupported shapes fail before input; a failure after substitution returns a fixed
value-free diagnostic. The broker client no longer subscribes to an event the real nativePipe stream rejects. Trusted
code is now the vendor modules plus src/services and src/secrets; state/codex is no longer trusted. Adds the opt-in
live sentinel probe (scripts/probe-secrets.mjs) and its evidence.
…ole (M5 review)

A reference in a request whose method only coerces to paste/type_text/set_value (the vendor looks methods up by
property key) or whose fields are not the pinned primitive types now fails closed as unsupported_secret_shape before
any read. The live probe's file scan streams every file whole with chunk overlap and fails on unread files instead
of skipping files of 4 MiB or more.
…ilure, record unreachable scan roots, and pin test hosts and stop-ack ordering

- doctor: missing files or invalid vendor signatures point at the shared offline recovery (stop servers, remove the
  release, reinstall) since install refuses to repair in place
- broker close: an endpoint unlink failure (EACCES) returns {confirmed:false, reason} instead of rejecting
- leak scan: a root behind an inaccessible ancestor is unread; only ENOENT means absent
- runtime-install tests pass the fixture host to resolve/use as well as install
- upstream: a controlled-ordering test that enumeration never judges the group empty before the anchor's stop ack
node_repl records an accepted session approval under the connection's random session id, which no later connection
can use; the file now goes with its connection. Other sessions' files are left alone.
…it scenarios, and package the helper sources

- scripts/accept-native.mjs: per-item PASS/FAIL/BLOCKED report for acceptance 1-10 (suites, install/reinstall,
  doctor, verify, lifecycle probe, release-gate inventory, packaging, clean clone of HEAD); metadata only
- --live-keychain runs scripts/probe-secrets.mjs, which now also proves fail-closed references (secrets off, no
  broker) at the controlled target before any input
- --live-textedit drives one disposable TextEdit document through cua serve, accepting only the exact TextEdit
  app approval for the session; combined with --live-keychain it types a disposable secret into it
- package files carry the Keychain helper sources and build script; README documents standalone install, plain MCP
  registration, helper signing and acceptance
SSFSKIM added 12 commits October 3, 2026 16:58
…r's pinned shapes

The vendor client's FunctionAgentTransport adds client_timeout_ms to every
command it sends (the locator's timeoutMs when positive, else undefined). The
pinned fill and tab-action shapes omitted it, so the live C2 fill of a secret
reference was refused as unsupported_secret_shape (failing closed, nothing
entered). It is now an optional positive integer in both shapes; any other
value still fails closed before a read.
…closed at the fill on the transport's client_timeout_ms
…Chrome, round trip blocked by the stale binding, restore verified byte-for-byte
…el mapping proven, 17/17 PASS, restore intact
…onnection, the register undo and the hash-verified restore
…orts, and C3's remove/re-add on the real registry
@SSFSKIM

SSFSKIM commented Oct 4, 2026

Copy link
Copy Markdown
Owner Author

Independent panel review (review-code, max) over 54cf811..a4dbe5c — 8 lanes (sweep + 5 derived lenses + verifier), 11 candidates, 10 confirmed after de-duplication: 1 P1, 9 P2. The secret-substitution lens (broker auth, malformed commands, both vendor failure channels) confirmed nothing.

All ten are fixed in 4cf2ceb..f54334b + 3d390cd..5b2defa (rebased), record folded in f914a77; npm test 341 → 366.

# Finding Fix
P1 Binding ignored the backend's browser family; an Edge extension with a same-named profile could be auto-bound for Chrome Inventory keeps family; only chrome backends are candidates, others reported as an excluded count
P2 runtime use activated a release whose placed Chrome component no longer verified Shared component verification before activation (chrome_component_invalid, target_occupied)
P2 Placed component accepted without extension-host-config.json verifyPlacedChromeComponent requires a valid config (host_config_invalid); install/register/doctor share it
P2 Doctor ran the login probe on a binary whose signature check had failed codex.login gated on runtime.files + runtime.signatures passing
P2 Plugin-installed copy could not find the locally built Keychain helper Helper resolved from $CUA_HOME/bin first; build:helper installs there; doctor names the location
P2 Unconfirmed teardown left transport handles open (hang in profiles bind/probes) terminate() disposes stdio/IPC/process handles when teardown ends; nothing signalled
P2 Readline error unhandled → EIO threw past teardown Interface errors share the input-error close
P2 Two concurrent chrome register runs could lose the original manifest's recovery record Per-home chrome/registration.lock; second run waits 5 s then registration_contended
P2 External in-place manifest write during --replace could poison the backup Backup accepted only as a whole parseable manifest; truncated = contention; verified backups never overwritten
P2 Bind committed a discovered id after the registration changed underneath Compare-and-set in bindProfile (profile_changed)

Behaviour changes worth noting: --replace no longer replaces a manifest that stays unparseable (hint tells the user to move it aside); the helper location supersedes the earlier "checkout build only" decision. Remaining millisecond-scale races are logged in tech-debt-tracker.md. A reviewer-high re-review of the fix range is running; results will be posted here.

@SSFSKIM

SSFSKIM commented Oct 4, 2026

Copy link
Copy Markdown
Owner Author

Re-review of the fix range a4dbe5c..f914a77 (reviewer-high): correct, no material findings; the ten defects are closed without regression on the reviewed paths, the documented millisecond races stay within scope. Suite 366/366. Live Chrome/Keychain acceptance flows were not rerun in the review.

@SSFSKIM
SSFSKIM merged commit b480cba into main Oct 4, 2026
@SSFSKIM
SSFSKIM deleted the feat/chrome-existing-profile branch October 4, 2026 04:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant