4 Commits
Author SHA1 Message Date
w3cjandClaude Opus 5.5 aeea3135b2 feat(proxy): the proxy's broker and its child
A VM's proxy runs as two processes, as design.md's "The proxy's broker"
says: devvm _proxy, the broker, which keeps what only the host should
do, and devvm _proxy-child, which reads the VM's network and can be
confined by the follow-ups.

- wire.go: the protocol over one socketpair (close-on-exec from the
  start: SOCK_CLOEXEC on Linux, ForkLock elsewhere), length-prefixed JSON
  frames of at most 2 MiB, unknown fields refused, bytes as base64, one
  descriptor on a frame's first bytes (SCM_RIGHTS, MSG_CTRUNC breaks the
  rules), wire types for every secret (redact.Secret at once).
- broker.go: newBroker, the start (handshake: version 1 and each side's
  executable's SHA-256, within 4 s), the answers (value through lookups,
  kept 30 s or 5 min, a failure 5 s, dropped when the bindings change;
  file by number; link connected by the broker and passed as a
  descriptor; token exchanged by the broker), each by something in its
  own config, with caps 1/8/4/256; live: the lifeline closes the socket
  and kills the child 6 s later, SIGTERM stops it within a second, a
  child that ends ends the broker, a rule broken stops the child.
- child.go: the start (startOf), the child's server (newChildServer),
  the broker as hostSide over the socket (brokerClient), runChildOn;
  ready only after it reads the host's addresses (kept: the last good
  read), roots and time zone loaded first.
- process.go: Main(ctx, ...) and ChildMain; the child spawned with
  /proc/self/exe on Linux, PR_SET_PDEATHSIG from a locked thread
  (daemon.Cmd.DieWithThread), descriptors 3 and 4, and TZ, SSL_CERT_*
  and GODEBUG with updatemaxprocs=0 alone; run/proxy-child.pid and
  run/proxy.confined ("none" until the follow-ups); KeepLogs in the
  broker. ChildMain refuses to start unless descriptors 3 and 4 are a
  unix socket and an IP one (checkInherited): run by hand, without
  them, those numbers can be the Go runtime's own, which closing
  crashed it (signal_recv: inconsistent state).
- capture.go: a captured token request goes to the broker
  (captureToken, exchanger), so a login's real tokens never enter the
  child; an error reply passes up to 1 MiB, longer gets 502.
- watched.go: the child stats each changing file and asks the broker
  for it once it changed, keeping the stamp of what the broker read.
- rotate.go: proxy.log rotated by both through its descriptor, under a
  lock of a description of its own; OpenLog opens a log never through a
  link, one link, yours, replacing what a child left in its place.
- nixcache.go: the trim and its count through a safefile.Root, nar/
  only as a folder, links deleted as themselves; reads never through a
  link; the lock tried for 5 s (ErrNixLocked, nix_cache_locked).
- daemon: Cmd.Err, Files, Env, DieWithThread; Handle.Kill, Exit;
  WritePID.
- netpolicy: Proxy.Stop also stops a child that outlived its broker
  (run/proxy-child.pid, _proxy-child -for); proxy.log opened with
  OpenLog; a refused launch keeps a running VM only while both run.
  devvm network log and lock read the event log through safefile.
- vm, vmssh, vmlog: links.log and ports.log opened with OpenLog, read
  through safefile, trimmed only as a regular file with one link.
- backend: the build proxy's logs in a logs/ folder of their own.
- cli: _proxy-child; _proxy waits for its child on a signal
  (StopsItsOwn); the child reads none of devvm's folders (no
  makePrivate); ui.Files.
- Tests: FuzzBrokerFrames, the frames' rules, the handshake and the
  pair's end in synctest bubbles, the caps, the broker naming its own
  alone, the client over a real socketpair with a passed descriptor,
  ChildMain, TestInheritedSocket and proxy.txtar's child run by hand,
  the frozen 0.1.0 configs starting a broker and child,
  two writers rotating once, planted links, FIFOs and hard links; the
  testscript runner stops _proxy-child too; e2e: broker and child, their
  arguments, descriptors and environment, stop, SIGKILL either, planted
  files in the logs folder and the Nix cache, build proxies gone.
- Review fixes: the lifeline closes the socket and starts the kill's
  timer before logging; every log lock (proxy.log's, the event log's
  rotation) is tried without blocking for 200 ms (flockWithin, which the
  Nix lock shares), then written without or the rotation skipped; a
  copied log's rotation streams at most twice its limit from a line's
  start (copyFrom, copyAtomic); a reply too long to send goes as
  too_long; kept token headers capped at 1 KiB; the child gives up on a
  request whose context ended, dropping its late reply and holding its
  slot until then; a write deadline on the start frame; errors reach the
  child as codes (not_found, refused, busy, too_long, failed), their
  text in the broker's log; FuzzFrameStreams, and FuzzBrokerFrames
  writes from a goroutine; nix_cache_locked links to How it works.
- Docs: processes, network, overview, design (with threat rows for the
  logs' locks and a log made huge), troubleshooting, the proxy's
  README, structure, testing; CHANGELOG.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-15 22:04:32 -07:00
d349868c31 feat(agents): one definition per coding agent, and Cursor's CLI
Every list of the coding agents now derives from internal/agents'
registry, one Def each, and Cursor's CLI (cursor-agent) is a fifth
agent.

The registry:
- each agent's login command, login formats and capture on its Def;
  one message for every agent where each had its own
- the agents' table, the README's list and the docs' history lists are
  generated from the registry (cli.DocBlocks, TestDocBlocks); scripts
  and Go tests take their lists from it too
- each agent's own code lives in a file named for it; the structure
  test lets only an agent's own files choose by its name, following
  constants named after an agent
- a VM remade by clone on/off keeps no agent's login files
  (agents.LoginFiles from every Def.Logins; Claude Code's .claude.json
  stays, as it is also history)

Cursor's CLI:
- `devvm --agents cursor`, `devvm agent login cursor`, history import
  and export of ~/.cursor/chats
- the proxy captures its login at a GET endpoint, guards a shared host
  by path, and puts the login in only where the CLI sends it, bound to
  the CLI's 57 methods
- account changes and the agent store are refused in a VM; Cursor's
  headers and trailers are scanned for tokens
- e2e: Cursor's CLI in the network section, its poll behind the fake
  company proxy

Docs: the agents' pages lead with commands, with a How it works page
for the agents.

Co-authored-by: JB <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-12 11:49:48 -07:00
w3cjandClaude Opus 5.5 db90ab1b5b fix(tools): opencode 2 in VMs, with its Codex logins and its database
devvm's pinned mise (2026.10.7) resolves aqua's "latest" to GitHub's latest
release, which opencode keeps on its 1.x line (v1.19.5) while it publishes
2.x beside it, so ls-remote lists 2.2.5 but lock picks 1.19.5. The shared
tools' mise.toml holds opencode at "2", which locks the newest 2.x on every
platform (linux-arm64/x64 and their musl entries, the same assets as 1.x).

opencode 2 keeps its logins in its SQLite database and imports auth.json
once, as it makes its credential table. devvm agent login opencode runs
its Codex logins (opencode auth login openai --method chatgpt-browser or
chatgpt-headless), which still post to auth.openai.com/oauth/token with
Codex's client ID, so the capture and the host's refresh are unchanged;
its Sign in with ChatGPT (/api/accounts/oauth/token, a client of its own
and an id_token checked against OpenAI's keys) stays refused by the
proxy's guard. An API key saved into a VM whose opencode has made its
database is imported with opencode auth import (OpencodeKeyImport).

Tests: TestOpencodeKeyImport, the login argv, agent_login.txtar's import
and its failure, the guard on opencode 2's token-sharing path; e2e's
network VM gets opencode and a device-code login against the fake
endpoint. tests/e2e-mise.lock bumped (opencode 2.2.5, claude 2.1.318,
pnpm 12.18.0).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-05 23:17:00 -07:00
w3cjandClaude Opus 5.5 2151d1b959 feat(proxy): capture agents' logins at their token endpoints
A login that Codex or opencode makes inside a VM goes to devvm's agent
store, and the VM gets only placeholders. Every VM's proxy intercepts
OpenAI's token endpoint (auth.openai.com/oauth/token, listed in its
config's captures for Codex and opencode on every tier), and its host
joins the allowlist of a VM whose image has either agent. This is the
proxy's first response rewriting (ModifyResponse, stdlib only).

- proxy: Config.Captures, IO.Capture (Capturer: Request, Response),
  Exchange; a POST to the endpoint's path (cleaned, without ;params, any
  case) is read (64 KiB) and its 2xx reply (1 MiB) goes to IO.Capture,
  never to the VM; the VM gets IO.Capture's reply with only Content-Type,
  Cache-Control, Pragma and Date; a "login" event names the agent; what
  can't be read gets 502, logged as a refused block, values never logged.
- agentlogin: Endpoints, Pick (the User-Agent tells opencode, Bun's, from
  Codex), File.CaptureRequest and File.Capture under lockLogin: Codex's
  auth.json (tokens, account_id, last_refresh; the id_token->API-key
  exchange's key in OPENAI_API_KEY, the VM's id_token placeholder swapped
  for the store's on the way out), opencode's auth.json openai entry,
  Claude Code's .credentials.json (capturer only: no VM captures Claude
  yet). A code replaces the login, a refresh adds to it (newest refresh
  token kept). The VM's reply: the bindings' placeholders, refresh token
  devvm-proxy-managed, expiry 2099.
- secrets: Store.CaptureRequest, Store.Capture (folder private, out of
  backups), the token endpoints' hosts in secrets.policy.
- netpolicy: Capturer (devvm _proxy's IO.Capture: the VM's salt, its
  agent, the bindings written again at once); devvm network log shows
  login lines.
- e2e (network): a fake token endpoint behind a company proxy of the
  run's own, with the run's CA; the store gets the real tokens and key,
  the VM placeholders and no refresh token, no log holds a value, the
  next launch gets the login as placeholders.
- Docs: Logins made in a VM (internals/network.md), coding-agents.md,
  safety/network.md (the account swap), the proxy's README.

Security review (security-audit skill, plus an independent read):
- Fixed: a VM could spell the path another way (/oauth/token;x) and get
  real tokens uncaptured: path parameters dropped before matching.
- Fixed: another path on the host could hand the VM tokens: any 2xx from
  a token endpoint's host naming access_token, refresh_token or id_token
  is refused, whatever its type (web pages pass unread); 101 refused.
- Fixed: 1xx replies (103 with Set-Cookie) reached the VM before
  ModifyResponse: dropped on token endpoints' hosts.
- Fixed: Set-Cookie and other headers on a captured reply reached the
  VM: only four headers kept.
- Fixed: an error reply to the exchange could quote the real id_token:
  it reaches the VM as its OAuth error code alone.
- Fixed: a captured request went upstream under the VM's raw path and
  query: it goes to the endpoint's own path, no query.
- Fixed: repeated form or JSON fields, which devvm and the endpoint
  could read apart, are refused.
- Fixed: captures depended on the image's agents, so a self-installed
  Codex logged in uncaptured: every VM's proxy captures at the endpoint.
- Fixed: at most 8 bodies read whole at once.
- Fixed: the VM's refresh with its managed refresh token is answered
  from the store, so a VM's Codex isn't logged out after 8 days.
- Fixed: a login saved whose bindings write failed reached the VM as a
  502: it reaches the VM, the error is logged.
- Accepted, documented: any VM with the agent can replace the store's
  login (an account of its choosing); on the open tier a program can go
  around the proxy; Claude Code's own /login in a VM isn't captured.
- Unconfirmed: domain fronting through a sibling OpenAI host whose
  tunnel isn't intercepted (depends on the CDN routing on Host).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-05 17:22:55 -07:00