Commit Graph
39 Commits
Author SHA1 Message Date
Gabriel Brown 78cb3d90c2 feat(worker): box-user script builders + username sanitizer 2026-07-13 09:49:59 -04:00
Gabriel Brown a640b5cb94 fix(terminal): bun-safe exec attach, box self-heal, surfaced errors
The workspace terminal died everywhere: bun's node:http client never
emits the client 'upgrade' event (it surfaces the 101 as a plain
response), so docker-modem's exec.start({hijack:true}) waited forever —
a connected WebSocket with no bytes flowing (prod), or an instant close
when the socket was unreachable (dev). The pre-Phase-1 bridge avoided
dockerode attach for exactly this reason; the real-TTY-resize rewrite
reintroduced it.

- runtime/exec-stream.ts: speak the exec-start HTTP upgrade over a raw
  net socket (docker and podman both answer 101 UPGRADED). Works under
  bun and node; honors the modem's socketPath/host:port. The stream is
  returned paused so the first screen paint can't race the caller's
  data handler. Exec create/resize stay on dockerode (plain POSTs).
- user-container.ts: acquireUserBox re-ensures the container on every
  acquire instead of trusting a cached "initialized" flag, so a box
  removed behind the worker's back (manual rm, another instance's
  reaper) is recreated instead of bricking terminals and agent turns
  until restart.
- terminal.ts: bridge failures are logged and close the WebSocket with
  a clamped human-readable reason instead of a silent catch;
  xterm-session.tsx displays that reason instead of a mute
  "Session ended". Also roomier terminal line spacing (1.2 -> 1.35).
2026-07-12 22:14:37 -04:00
Gabriel Brown 1fbb2dd0a1 chore: remove dead routes/components + fix redact/env cleanup 2026-07-11 18:11:22 -04:00
Gabriel Brown a5bc0434f3 chore: fix eslint errors introduced across phases 1-3 2026-07-11 13:27:23 -04:00
Gabriel Brown 2c6a605646 feat(worker): user-scoped /box/terminal websocket bridge
Add a USER-scoped `/box/terminal` WebSocket that acquires the user's box
and opens a login shell rooted at `~`. Extract the shared real-TTY PTY
bridging (buffered input, dockerode exec/start, resize, forward, cleanup)
out of the job `bridge()` into `runShellBridge`, parameterized by how the
box is acquired, the working directory, and the env; `bridge()` and the
new `bridgeBox()` both call it so the job path is unchanged.

The `/box/terminal` upgrade reads the username FROM the token
(`parseBoxTokenUsername`, part[2] of the 4-part token), then verifies the
whole token with `verifyBoxTerminalToken`; on success `bridgeBox` derives
`boxHomePaths(username)`, seeds a minimal `.bash_profile` via a shared
`ensureBashProfile` (extracted from `materializeUserHome`), acquires the
box, and opens the shell at `containerHome` with `TERM`+`HOME` only (no
per-job secrets). Cleanup releases the box handle.

Manual verification (dockerode PTY I/O is daemon-dependent):
- `bun run test:unit` 105 passed (incl. new `parseBoxTokenUsername` tests),
  `bun run typecheck` clean.
- Raw upgrade against a live server: valid box token -> `101 Switching
  Protocols`; bad token -> refused (no upgrade). Job `/jobs/:id/terminal`
  branch unchanged.
- `bridgeBox` path exercised: `acquireUserBox` created `spoon-box-<user>`
  and `ensureBashProfile` seeded `~/.bash_profile`. Interactive typing/
  resize could not be observed on this host because dockerode cannot reach
  the podman API socket (same mechanism the job terminal uses, so no
  regression) — full browser flow is covered by later tasks.

Claude-Session: https://claude.ai/code/session_01ScyZ1NhfN84LAnHpwhfEQk
2026-07-11 12:25:32 -04:00
Gabriel Brown 192f547be5 feat(worker): /box status, lifecycle, tree, and file HTTP routes
Wire the box helpers into the worker HTTP server as /box/* routes,
authed by the internal bearer token like every other worker route.
Adds a boxRoute matcher (/^\/box\/(status|lifecycle|tree|file)$/) and
dispatches before jobRoute; missing user -> 400, unknown lifecycle
action -> 400, containment throws -> 400 (server keeps serving).

Manual verification (harness on :3922, internal token, user gabriel):
  GET  /box/status?user=gabriel        -> 200 {"status":{...running:false...}}
  GET  /box/status  (no user)          -> 400 {"error":"Missing user"}
  (no Authorization header)            -> 401
  POST /box/lifecycle {"action":"bogus"} -> 400 {"error":"Unknown action"}
  GET  /box/tree?user=gabriel          -> 200 {"tree":{"name":"~",...}}
  PUT  /box/file {"path":"spoon-test.txt","content":"hi from task4"} -> 200 {"success":true}
  GET  /box/file?path=spoon-test.txt   -> 200 {"path":...,"content":"hi from task4"}
  GET  /box/file?path=../../../../../etc/passwd -> 400 {"error":"Refusing to access path outside home: ..."}
  GET  /box/status after escape        -> 200 (no crash)
  GET  /box/other?user=gabriel         -> 404 {"error":"Not found"}
2026-07-11 12:13:50 -04:00
Gabriel Brown bf0276b1f3 feat(worker): home-scoped box file tree/read/write with realpath containment 2026-07-11 12:05:04 -04:00
Gabriel Brown 6439e5200b feat(worker): per-user box status and lifecycle helpers
Centralize per-user box home-path derivation, status inspection, and
lifecycle (start/stop/restart) in a new box.ts so the HTTP routes and the
terminal WS bridge share one source of truth. Add inspectUserBoxStatus to
docker.ts (single `inspect --format` call, all-null/false on non-zero exit)
and resetBox to user-container.ts (clears the idle timer and drops the
registry entry so a stopped box isn't treated as held).

Manual verification (docker required, after Task 4 wires the routes): with
the worker running and a box up,
`curl -H "Authorization: Bearer $TOKEN" localhost:3921/box/status?user=<you>`
shows running:true + image + startedAt; `POST /box/lifecycle {"action":"stop"}`
flips status to running:false; `start` brings it back.
2026-07-11 11:57:57 -04:00
Gabriel Brown d4303e652e feat(worker): user-scoped box terminal token verification 2026-07-11 11:52:26 -04:00
Gabriel Brown 432e3b501e fix(worker): don't double-append streamed answer when completed event carries content 2026-07-11 11:47:11 -04:00
Gabriel Brown 2311679802 fix(worker): chmod materialized env file to 0600 even when it pre-exists 2026-07-11 11:36:03 -04:00
Gabriel Brown 58c815a7a7 fix(worker): materialize env files 0600, re-materialize per run, delete on stop 2026-07-11 11:36:03 -04:00
Gabriel Brown 0716a224ef fix(worker): codex prepareAuth skips auth.json for api_key profiles 2026-07-11 11:00:08 -04:00
Gabriel Brown c0f107c4cf feat(backend): queue-time runtime/profile validation; job.runtime authoritative in worker 2026-07-11 10:58:05 -04:00
Gabriel Brown 76886621b5 feat(worker): ClaudeCodeAdapter runs claude -p stream-json in the per-user box 2026-07-11 10:35:56 -04:00
Gabriel Brown c9ee2e6cde refactor(worker): delete per-job OpenCode container path, host_port split, and dead docker helpers
Claude-Session: https://claude.ai/code/session_01ScyZ1NhfN84LAnHpwhfEQk
2026-07-11 10:26:58 -04:00
Gabriel Brown ff0425cf4b feat(worker): OpenCodeAdapter runs opencode in the per-user box (no side container) 2026-07-11 10:07:58 -04:00
Gabriel Brown 949a036d13 fix(worker): surface nonzero-exit agent turns as failed even when text streamed 2026-07-11 10:07:14 -04:00
Gabriel Brown e5bba720b4 refactor(worker): move Codex turn logic into CodexAdapter behind AgentRuntime 2026-07-11 02:53:26 -04:00
Gabriel Brown c1e816741d fix(worker): marked-command survives tail-exec; kill script excludes itself 2026-07-10 18:53:00 -04:00
Gabriel Brown bab87cc2d0 feat(worker): in-box process-group marker + kill helpers for agent turns 2026-07-10 18:53:00 -04:00
Gabriel Brown 38431155b2 refactor(worker): extract AgentRuntime interface, shared provider helpers, and adapter registry 2026-07-10 18:28:41 -04:00
Gabriel Brown ac68484059 fix(worker): make cancellation teardown failure-safe 2026-07-10 18:04:40 -04:00
Gabriel Brown 8af33fc9e0 fix(worker): always release stopped workspaces 2026-07-10 17:35:33 -04:00
Gabriel Brown c4d0f5219a fix(terminal): use real TTY exec and resize 2026-07-10 17:21:52 -04:00
Gabriel Brown 57c175aecd fix(worker): contain workspace paths against symlinks 2026-07-10 17:11:00 -04:00
Gabriel Brown 0b5a2c0411 fix(worker): ensure reconciled boxes before acquire 2026-07-10 17:04:41 -04:00
Gabriel Brown 284f7ea52b fix(worker): serialize box failure and idle reaping 2026-07-10 17:00:22 -04:00
Gabriel Brown 9e7a8722f3 fix(worker): make user-box lifecycle concurrency-safe 2026-07-10 16:54:55 -04:00
Gabriel Brown daec4d6dfa fix(worker): make workspace cleanup layout-aware 2026-07-10 15:55:11 -04:00
Gabriel Brown 65aae85369 Update formatting on worker
Build and Push Spoon Images / quality (push) Successful in 1m27s
Build and Push Spoon Images / build-images (push) Successful in 7m13s
2026-06-24 08:40:52 -04:00
Gabriel Brown c1263b2e69 Worker: interactive terminal WebSocket bridge (PTY in workspace container)
- attachTerminalServer() upgrades /jobs/:id/terminal WS connections, verifying a
  short-lived job-scoped HMAC token (verifyTerminalToken) so the browser never
  holds the worker secret
- Bridges the socket to a bash PTY via dockerode exec (Tty) in a persistent
  per-job shell container (spoon-agent-term-<id>) mounting the workspace; binary
  frames = stdin, JSON text frames = resize; idle containers reaped after 30m
- New env: SPOON_AGENT_TERMINAL_IMAGE/SECRET/IDLE_MS (secret falls back to the
  shared worker internal token)
2026-06-24 08:16:39 -04:00
Gabriel Brown 40a6dd78e4 Fix worker image missing docker CLI; harden spawn-failure handling
Build and Push Spoon Images / quality (push) Successful in 1m47s
Build and Push Spoon Images / build-images (push) Successful in 6m33s
Root cause of the prod empty-response: the spoon-agent-worker image shipped
without a docker CLI binary, so it could never launch the codex job container.
On Debian trixie (the bun base) 'docker.io' + --no-install-recommends installs
the daemon package but omits the client (split into 'docker-cli'), leaving no
'docker' on PATH. execa('docker', ...) hit ENOENT, and with reject:false that
resolves with exitCode undefined -> coerced to 0 -> looked like a successful
empty run -> 'Codex completed without producing an assistant response'.

- agent-worker.Dockerfile: drop docker.io, install the official static docker
  CLI client pinned to 29.5.3 (matches the host daemon) to /usr/local/bin/docker
- runtime/docker.ts: normalizeRunResult() so a spawn failure (exitCode null) is
  always a non-zero exit carrying the real reason, never a silent empty success
- tests: cover the spawn-failure and normal-result paths
2026-06-24 06:31:17 -04:00
Gabriel Brown 9643cb197b Fix agent empty-response in prod: workdir mount, image freshness, error surfacing
- Pin codex@0.142.0 + opencode-ai@1.17.9 in the job image (was @latest,
  causing dev/prod drift)
- Worker now s the job image once per process so prod stops
  running a stale Codex
- Surface Codex error/turn.failed events instead of swallowing them, so the
  real failure reason is reported rather than 'no assistant response'
- Harden the Codex JSON parser to also handle the legacy msg-wrapped shape
- Fix the docker-in-docker workdir: bind-mount identical host:container path
  and set SPOON_AGENT_HOST_WORKDIR (named volume can't be mounted by sibling
  job containers)
- Add docs/compose.prod.yml as a documented reference deployment
2026-06-24 05:38:35 -04:00
Gabriel Brown 30a17196f5 fix worker forreal
Build and Push Spoon Images / quality (push) Successful in 1m45s
Build and Push Spoon Images / build-images (push) Successful in 7m35s
2026-06-23 21:38:41 -04:00
Gabriel Brown c3d265d428 Fix worker 2026-06-23 20:35:01 -04:00
Gabriel Brown a6f7ea7f78 Clean up old stuff & fix ui errors
Build and Push Spoon Images / quality (push) Successful in 2m22s
Build and Push Spoon Images / build-images (push) Successful in 23m10s
2026-06-23 14:57:05 -04:00
Gabriel Brown fe72fc2957 Add features & update project 2026-06-23 01:46:08 -04:00
Gabriel Brown 7e7bec56d5 Add way for infisical to switch accounts when signed into wrong account
Build and Push Next App / quality (push) Successful in 1m34s
Build and Push Next App / build-next (push) Successful in 4m11s
2026-06-22 13:14:25 -04:00