devbox mode plan (#474): six tasks, copy deck first
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
docs/superpowers/plans/2026-10-30-devbox-mode.md+265 −0
CI passed — run details
Intent
<task-notification> <task-id>bsqq64zas</task-id> <tool-use-id>toolu_01JkTNzzJsAuRTVN8ohw71dQ</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/9b370a04-693c-4bda-b2eb-9a4b08f7626d/tasks/bsqq64zas.output</output-file> <status>completed</status> <summary>Background command "Run Astra builder check on the design" completed (exit code 0)</summary> </task-notification>
Alright go ahead
Attributed to this commit: 45.2 g CO₂e (4,688,939 tokens). This is an attribution, not a measurement — usage counted from this commit's own marker forward to the next one on design-devbox-mode, never backward from it. A turn that produced more than one commit books all of its tokens to the last one, and a concurrent session on this branch can add to the same figure. Some of it was priced using the shared default rate, because no model-specific factor row exists yet for at least one model involved. The Carbon view has the repo total, which is never derived from this attribution.
diff --git a/docs/superpowers/plans/2026-10-30-devbox-mode.md b/docs/superpowers/plans/2026-10-30-devbox-mode.md| new file mode 100644 |
| index 000000000..f9f5d1e1e |
| --- /dev/null |
| +++ b/docs/superpowers/plans/2026-10-30-devbox-mode.md |
| @@ -0,0 +1,265 @@ |
| +# Devbox Mode Implementation Plan |
| + |
| +> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking. |
| + |
| +**Goal:** `carlos devbox` publishes owned, tailnet-only `https://<name>.<devbox domain>` links on a shared workstation, either to a user's loopback dev server or to a folder snapshot, served by the platform edge running unprivileged. |
| + |
| +**Architecture:** One process (`carlos devbox serve`, a systemd unit running as a dedicated service user with `CAP_NET_BIND_SERVICE`) holds two things. The first is an edge entrypoint, `edge.ServeDevbox`: wildcard-only TLS on one private address, with no `:80`, no per-host ACME, no response cache, no guard and no rate limit. The second is a registrar on a Unix socket. It identifies callers by `SO_PEERCRED` uid, keeps an owner record per name, writes ordinary registry routes (`service` with a loopback `Addr`, or `static`), and stores folder snapshots that the edge serves from local disk. |
| + |
| +**Tech Stack:** Go; existing `internal/edge` (wildcard DNS-01, static file serving), `internal/registry` (SQLite), `golang.org/x/sys/unix`. |
| + |
| +**Spec:** `docs/superpowers/specs/2026-10-30-devbox-mode-design.md` (approved by Paul 2026-10-30). Discussion: amadan #474. |
| + |
| +**Spec §5.5 choice: option (b), a local static tree.** `(*staticSite).serveTree` and `serveFile` read only `app` and `channel` (for log lines), so a local tree reuses all of the file serving, `_headers` and `_redirects` with no store, signing or extraction cache. Option (a) would have meant a release key on the devbox and holding off five store-armed subsystems. |
| + |
| +## Global Constraints |
| + |
| +- Nothing runs as root after the one-time install. No code path calls `sudo` or checks for euid 0. |
| +- The edge listens only on the configured address. `ServeDevbox` refuses an empty host, `0.0.0.0` or `::`. There is no `:80` listener. |
| +- No ACME order is ever placed for a name the wildcard does not cover, including before the wildcard first arrives. |
| +- No S3 or other object-store requests. Snapshots are on local disk only. |
| +- Names are one DNS label: `[a-z0-9-]`, 1-63 characters, no leading or trailing hyphen. |
| +- Live links target `127.0.0.1:<port>` only: the wire carries a port, never a host, so a non-loopback upstream cannot be expressed. Ports 1-65535. |
| +- Folder snapshot cap: 200 MiB per link (compressed upload). Spool cap: 5 GiB in total (my number; the spec asks for "a total cap"). |
| +- The peer-credential code is Linux-only: `//go:build linux`, with a `!linux` stub returning `errors.ErrUnsupported`. CI cross-builds darwin and windows. |
| +- User-facing strings come only from the approved copy deck (Task 1). No em dashes. Neutral examples only (`shop`, `devbox.example.com`), never tenant names. |
| +- Local test runs cover only the touched packages, with `-run`. CI runs the full suite. Socket tests need a short `TMPDIR` (for example `TMPDIR=/tmp/g`) because of the 108-byte socket path limit. |
| + |
| +## Review Focus |
| + |
| +1. **A live link shared before its dev server is up.** Expect `share` to succeed. `list` shows it as not answering, and a request gets the edge's existing 502, never a hang. Test: Task 5 `TestShareLiveBeforeServerUp`. |
| +2. **A name already owned by another user.** Expect `share` to be refused with the owner's username, and nothing about the existing link to change. Test: Task 5 `TestShareRefusesOtherOwnersName`. |
| +3. **Re-sharing your own name as the other kind (live to folder or back).** Expect the link to switch kind, the registry row to be replaced, and the old snapshot to be removed. Test: Task 5 `TestReshareSwitchesKind`. |
| +4. **A branch name that isn't a valid label** (`Feature/Widget_GTM`, 80 characters, all punctuation). Expect it folded to a valid label, or a clear refusal asking for an explicit name when nothing valid remains. Test: Task 4 `TestNameFromBranch`. |
| +5. **The registrar restarting.** Expect every link to survive, with owners, kinds and snapshots intact and the registry rows unchanged. Test: Task 5 `TestRegistrarRestartKeepsLinks`. |
| + |
| +--- |
| + |
| +### Task 1: Copy deck |
| + |
| +**Files:** |
| +- Create: `docs/superpowers/plans/2026-10-30-devbox-mode-copy.md` |
| +- Create: `approved_devbox_copy_test.go` |
| + |
| +**Interfaces:** |
| +- Produces: deck ids `DBX-C1`…`DBX-Cn`. Every later task cites the ids whose text it writes, and adds them to `devboxCopyBuilt` in the same commit. |
| + |
| +- [ ] **Step 1:** Write the deck in the moves record's table format (see `docs/superpowers/plans/2026-10-08-carlos-run-copy.md`), one row per string, covering: |
| + - `carlos devbox` usage and help for `share`, `unshare`, `list`; |
| + - the share success line, which is the full URL alone on its own line; |
| + - the `list` header and its states (answering, not answering, folder); |
| + - every refusal: name owned by someone else (names the owner), invalid name, branch name folds to nothing, non-loopback port, folder over 200 MiB, spool full, not your link, unknown link, registrar unreachable; |
| + - the unreachable hint that names the agent sandbox as the likely cause (spec §5.7); |
| + - the runbook's prose (Task 6) as a separate section. |
| +- [ ] **Step 2:** Run the copy-review skill on the deck. Apply Paul's edits verbatim. |
| +- [ ] **Step 3:** Write `approved_devbox_copy_test.go` on the pattern of `approved_run_copy_test.go`: `TestDevboxCopyRecordIsComplete`, `TestDevboxBuiltCopyIsApproved`, `TestDevboxBuiltCopyIsApplied`, `TestDevboxCopyHasNoEmDash`. `devboxCopyBuilt` starts empty. |
| +- [ ] **Step 4:** Run `go test -run 'TestDevboxCopy' .`. Expected: PASS. |
| +- [ ] **Step 5:** Commit. |
| + |
| +### Task 2: Edge serves a local static tree |
| + |
| +**Files:** |
| +- Create: `internal/edge/localstatic.go` |
| +- Modify: `internal/edge/edge.go` (the `Edge` struct: field `localStaticRoot string`; `staticHandlerFor` at ~:700) |
| +- Modify: `internal/edge/static.go` (export the extractor) |
| +- Test: `internal/edge/localstatic_test.go` |
| + |
| +**Interfaces:** |
| +- Produces: |
| + - `func WithLocalStatic(root string) RunOption` |
| + - `func ExtractSite(data []byte, dst string) error`, a thin export of `extractSiteTar` |
| + - the layout contract `<root>/<rt.App>/current`, a symlink to the served tree's directory, swapped by rename. |
| + |
| +- [ ] **Step 1: Write the failing tests** in `localstatic_test.go`: |
| + - `TestLocalStaticServesCurrentTree`: given a route `{Kind: "static", App: "shop"}` and `<root>/shop/current` → `t1/` holding `index.html`, `GET /` returns 200 with that body. |
| + - `TestLocalStaticAppliesHeaders`: `t1/_headers` sets `X-Mock: yes` for `/*`, and the response carries it. |
| + - `TestLocalStaticFollowsSwap`: after `current` is renamed onto `t2/`, which has a different body and different `_headers`, the next request serves `t2` and its headers, with no `Reload`. |
| + - `TestLocalStaticMissingIs404`: no `<root>/shop/current` gives 404. |
| + - `TestLocalStaticRefusesDotDot`: `GET /../x` gives 400, the same as `serveTree`. |
| + - `TestStoreStaticUnchangedWithoutLocalRoot`: with no `WithLocalStatic`, `staticHandlerFor` behaves exactly as before (the 404 stub when no store is configured). |
| +- [ ] **Step 2:** Run `go test ./internal/edge -run 'TestLocalStatic|TestStoreStaticUnchanged'`. Expected: FAIL (undefined). |
| +- [ ] **Step 3: Implement.** |
| + - `newLocalStaticHandler(rt registry.Route, root string) http.Handler` resolves `current` with `filepath.EvalSymlinks` per request. It parses `_headers` and `_redirects` once per resolved target, cached by target path, using the existing `parseHeaders` and `parseRedirects`. It serves through `(*staticSite).serveTree` on a `staticSite{app: rt.App, channel: "devbox"}` value (`serveTree` reads only `app` and `channel`). |
| + - `staticHandlerFor` checks `e.localStaticRoot != ""` first. |
| +- [ ] **Step 4:** Run the same command. Expected: PASS. |
| +- [ ] **Step 5:** Commit. |
| + |
| +### Task 3: `edge.ServeDevbox`, the wildcard-only front door |
| + |
| +**Files:** |
| +- Create: `internal/edge/devbox.go` |
| +- Test: `internal/edge/devbox_test.go` |
| + |
| +**Interfaces:** |
| +- Consumes: `WithLocalStatic` (Task 2). |
| +- Produces: |
| + ```go |
| + type DevboxConfig struct { |
| + Registry *registry.Registry |
| + ListenAddr string // host:port; host must be a specific IP |
| + CertDir string // autocert.DirCache for the wildcard + ACME account key |
| + SpoolRoot string // passed to WithLocalStatic |
| + } |
| + func ServeDevbox(ctx context.Context, cfg DevboxConfig) error // blocks until ctx is done, then drains |
| + ``` |
| + The wildcard parents and the DNS provider come from the existing env (`CARLOS_WILDCARD_DOMAINS`, `CARLOS_DNS_PROVIDER=route53`). |
| + |
| +- [ ] **Step 1: Write the failing tests:** |
| + - `TestDevboxRefusesUnspecifiedListenAddr`: `""`, `":443"`, `"0.0.0.0:443"` and `"[::]:443"` each return an error before anything listens. |
| + - `TestDevboxRefusesNoWildcard`: with `CARLOS_WILDCARD_DOMAINS` unset, it returns an error. |
| + - `TestDevboxCertForUncoveredNameFails`: the devbox `GetCertificate` returns an error for `other.example.net`, for the parent apex, and for a covered name before the wildcard is obtained. The inner function it wraps is a refusal, never autocert. Assert that no `autocert.Manager` is built: build the chain through an unexported `devboxGetCertificate(w *wildcardManager) func(*tls.ClientHelloInfo) (*tls.Certificate, error)`, and test it with a wildcard manager seeded by the existing `wildcard_test.go` helpers. |
| + - `TestDevboxEdgeSwitchesOff`: the edge `ServeDevbox` builds has a nil cache, `guard == guardOff` and `rateMode == RateOff`, whatever `CARLOS_EDGE_PROTECT` and `CARLOS_RATE_LIMIT` say. |
| +- [ ] **Step 2:** Run `go test ./internal/edge -run TestDevbox`. Expected: FAIL. |
| +- [ ] **Step 3: Implement.** |
| + - Build `New(reg, nil)`, apply `WithLocalStatic(cfg.SpoolRoot)`, then set `guard`, `rateMode` and the cache off. |
| + - Start `go e.Watch(...)`, `newCertCache(cfg.CertDir)` and `newWildcardFromEnv(e, cache)` (refresh, then `go w.run()`). |
| + - Serve TLS with `devboxGetCertificate(w)` on one listener from `listen("https", cfg.ListenAddr, ...)`. |
| + - Do not call `armCertIssuance`, `newCertMirror`, `newHomeMap`, `armDoor`, `EnableStatic` or cert warm. |
| +- [ ] **Step 4:** Run the same command. Expected: PASS. |
| +- [ ] **Step 5:** Commit. |
| + |
| +### Task 4: Names and the link store |
| + |
| +**Files:** |
| +- Create: `internal/devbox/names.go`, `internal/devbox/links.go` |
| +- Test: `internal/devbox/names_test.go`, `internal/devbox/links_test.go` |
| + |
| +**Interfaces:** |
| +- Produces: |
| + ```go |
| + func ValidName(name string) error |
| + func NameFromBranch(branch string) (string, error) // error when nothing valid remains |
| + type Kind string // "live" | "folder" |
| + type Link struct { |
| + Name, OwnerName string |
| + OwnerUID uint32 |
| + Kind Kind |
| + Port int // live only |
| + Snapshot string // folder only: current snapshot dir name |
| + Created, Updated time.Time |
| + } |
| + type Links struct{ /* path, mutex */ } |
| + func OpenLinks(path string) (*Links, error) // creates 0600 if missing |
| + func (l *Links) Get(name string) (Link, bool) |
| + func (l *Links) Put(link Link) error // write-temp + fsync + rename, 0600 |
| + func (l *Links) Delete(name string) error |
| + func (l *Links) All() []Link // sorted by Name |
| + ``` |
| + |
| +- [ ] **Step 1: Write the failing tests:** |
| + - `TestValidName`: accepts `shop`, `a`, `x-1` and a 63-character label. Refuses `""`, `-a`, `a-`, `A`, `a_b`, `a.b` and a 64-character label. |
| + - `TestNameFromBranch`: |
| + - `"Feature/Widget_GTM"` → `"feature-widget-gtm"`; |
| + - runs of punctuation collapse to one `-`; |
| + - an 80-character branch is cut to 63 characters with no trailing `-`; |
| + - `"///"` returns an error. |
| + - `TestLinksRoundTrip`: Put, reopen, Get gives an equal value. The file mode is 0600. |
| + - `TestLinksAllSorted`, and `TestLinksDeleteMissingIsNoError`. |
| +- [ ] **Step 2:** Run `go test ./internal/devbox -run 'TestValidName|TestNameFromBranch|TestLinks'`. Expected: FAIL. |
| +- [ ] **Step 3:** Implement. JSON file, one process writes it. |
| +- [ ] **Step 4:** Run the same command. Expected: PASS. |
| +- [ ] **Step 5:** Commit. |
| + |
| +### Task 5: The registrar |
| + |
| +**Files:** |
| +- Create: `internal/devbox/registrar.go`, `internal/devbox/peer_linux.go`, `internal/devbox/peer_other.go` |
| +- Test: `internal/devbox/registrar_test.go` |
| + |
| +**Interfaces:** |
| +- Consumes: Task 4; `edge.ExtractSite` (Task 2); `registry.(*Registry).Upsert` and `.Delete`. |
| +- Produces: |
| + ```go |
| + type Registrar struct { |
| + Reg *registry.Registry |
| + Links *Links |
| + Domain string // wildcard parent, e.g. "devbox.example.com" |
| + SpoolRoot string // same root as edge WithLocalStatic |
| + SpoolCap int64 // 5 << 30 |
| + LookupUser func(uid uint32) string // os/user; "" when unknown |
| + } |
| + func (r *Registrar) Handler() http.Handler // reads the caller uid from the request context |
| + func WithPeerUID(ctx context.Context, uid uint32) context.Context |
| + func PeerUID(c net.Conn) (uint32, error) // SO_PEERCRED; linux only |
| + func ConnContext(ctx context.Context, c net.Conn) context.Context // for http.Server.ConnContext; a conn with no uid gets no identity, and every request is then refused |
| + ``` |
| + Wire API, HTTP over the socket: |
| + - `POST /share/live {name, port}` |
| + - `POST /share/folder?name=` with a `site.tar.gz` body (the `edge.PackDir` format), capped at 200 MiB |
| + - `POST /unshare {name}` |
| + - `GET /list`, returning `[]{name, owner, kind, target, created, updated, answering}` |
| + - Errors return a JSON `{code, detail}`. Codes map one to one onto the deck's refusal ids. |
| + |
| + Registry rows. The host is `<name>.<Domain>`. |
| + - live: `{Host, Kind: "service", Addr: "127.0.0.1:<port>", App: name, Status: "ready"}` |
| + - folder: `{Host, Kind: "static", App: name, Status: "ready"}` |
| + |
| + Snapshot layout: extract into `<SpoolRoot>/<name>/<unix-nanos>/`, then swap `<SpoolRoot>/<name>/current` by symlink plus rename, then remove the previous tree. |
| + |
| +- [ ] **Step 1: Write the failing tests.** These drive `Handler()` with `WithPeerUID` (no real socket) except the last. |
| + - `TestShareLiveWritesServiceRoute`: the row has exactly the fields above. `Links` holds the owner uid and name. |
| + - `TestShareLiveRefusesBadPort`: port 0 and port 70000 are refused. Nothing is written. |
| + - `TestShareRefusesOtherOwnersName` (Review Focus 2): uid 1002 sharing a name uid 1001 owns is refused with the `owned` code and the owner's username. The row and `Links` are unchanged. |
| + - `TestUnshareRefusesNonOwner`, and `TestUnshareRemovesRowLinkAndSpool`. |
| + - `TestShareFolderSwapsCurrent`: the second upload replaces `current`, and the first tree is gone. |
| + - `TestShareFolderOverCapRefused`: a body over 200 MiB (use a reader that streams zeros, not a 200 MiB allocation) is refused, and nothing is extracted. `TestSpoolFullRefused`: with `SpoolCap` set small, the upload is refused. |
| + - `TestReshareSwitchesKind` (Review Focus 3): live to folder replaces the row's kind and fields, and folder to live removes the spool directory. |
| + - `TestShareLiveBeforeServerUp` (Review Focus 1): sharing a closed port succeeds, and `/list` reports `answering: false`. After a listener opens on that port, `answering: true`. The dial timeout is 300 ms. |
| + - `TestListShowsUnknownOwnerAsUID`: when `LookupUser` returns `""`, the owner shows as `uid 1003`. |
| + - `TestRegistrarRestartKeepsLinks` (Review Focus 5): a fresh `Registrar` on the same `Links` path, registry and spool lists the same links, and the folder still serves through Task 2's handler. |
| + - `TestSocketCallerIdentity` (linux, `TMPDIR` short): a real `http.Server` on a Unix socket with `ConnContext` stamps `os.Getuid()`, and a request from this process is attributed to that uid. |
| +- [ ] **Step 2:** Run `TMPDIR=/tmp/g go test ./internal/devbox -run 'TestShare|TestUnshare|TestReshare|TestList|TestRegistrar|TestSocket'`. Expected: FAIL. |
| +- [ ] **Step 3: Implement.** |
| + - `PeerUID` follows `internal/instancectl/peer_linux.go:23` (`peerCred`). |
| + - One mutex serialises every mutation, so the registry and `Links` move together. |
| + - On a failure partway through, roll back `Links` to the prior value. |
| +- [ ] **Step 4:** Run the same command. Expected: PASS. Also run `GOOS=darwin go vet ./internal/devbox` and `GOOS=windows go vet ./internal/devbox`, and expect both clean. |
| +- [ ] **Step 5:** Commit. |
| + |
| +### Task 6: `carlos devbox` and the unit |
| + |
| +**Files:** |
| +- Create: `devbox_cli.go`, `devbox_cli_test.go` |
| +- Modify: `main.go` (add `case "devbox": runDevbox(args)` to the dispatch, near `case "edge"`) |
| +- Create: `infra/devbox/carlos-devbox.service`, `infra/devbox/route53-acme-policy.json`, `infra/devbox/README.md` |
| + |
| +**Interfaces:** |
| +- Consumes: Tasks 3 and 5. |
| +- Produces: |
| + - `carlos devbox share [--port N | --dir PATH] [name]` |
| + - `carlos devbox unshare [name]` |
| + - `carlos devbox list` |
| + - `carlos devbox serve` |
| + |
| + The socket is `$CARLOS_DEVBOX_SOCKET`, defaulting to `/run/carlos-devbox/devbox.sock`. `serve` reads: |
| + - `CARLOS_DEVBOX_LISTEN` (the host:port of the tailnet address); |
| + - `CARLOS_DEVBOX_DOMAIN`; |
| + - `CARLOS_DATA_DIR` (the registry, `links.json`, `certs/` and `spool/` live under it); |
| + - and the existing wildcard and DNS env. |
| + |
| +- [ ] **Step 1: Write the failing tests.** These run against an in-process `serve` composition on a temp socket, using a registrar with a fake TLS-less edge (the CLI never talks to the edge). |
| + - `TestDevboxShareLivePrintsURL`: stdout is exactly `https://shop.devbox.example.com\n`. |
| + - `TestDevboxShareDefaultsToBranchName`: in a temp git repo on branch `Feature/Shop`, the link is named `feature-shop`. |
| + - `TestDevboxShareDirPacksFolder`, and `TestDevboxShareDirRefusesSymlink` (the `PackDir` refusal, worded by the deck). |
| + - `TestDevboxUnreachableNamesSandbox`: with no socket present, the error carries the deck's sandbox hint. |
| + - `TestDevboxListTable`: the columns and states match the deck. |
| +- [ ] **Step 2:** Run `TMPDIR=/tmp/g go test -run TestDevbox .`. Expected: FAIL. |
| +- [ ] **Step 3: Implement.** |
| + - `serve` creates the socket at mode 0666, with its directory created by systemd `RuntimeDirectory=carlos-devbox`, `RuntimeDirectoryMode=0755`. |
| + - It runs the registrar `http.Server` (with `ConnContext`) and `edge.ServeDevbox` under one context, and stops both on SIGTERM. |
| + - The unit runs as `User=carlos-devbox` with `AmbientCapabilities=CAP_NET_BIND_SERVICE`, `CapabilityBoundingSet=CAP_NET_BIND_SERVICE` and `NoNewPrivileges=yes`. Its environment comes from `EnvironmentFile=/etc/carlos-devbox/env` (mode 0600). Copy `internal/host/units/carlos-edge.service`'s hardening where it applies. |
| + - The IAM policy allows `route53:ChangeResourceRecordSets` on one hosted zone, with the conditions `route53:ChangeResourceRecordSetsNormalizedRecordNames` = `_acme-challenge.<devbox domain>` and `route53:ChangeResourceRecordSetsRecordTypes` = `TXT`. It also allows `route53:ListHostedZonesByName` and `route53:GetChange`. |
| + - The runbook (its prose comes from the deck) covers: |
| + - the one-time root steps: create the user, install the binary and unit, write the env file, enable the unit; |
| + - the DNS A record `*.<devbox domain>` pointing at the tailnet IPv4; |
| + - the spec §9 smoke checklist. |
| + - Add the ids written to `devboxCopyBuilt`. |
| +- [ ] **Step 4:** Run `TMPDIR=/tmp/g go test -run 'TestDevbox' .`. Expected: PASS. |
| +- [ ] **Step 5:** Commit, push, and let CI run the full suite and the cross-builds. |
| + |
| +## After merge (operator, not a task) |
| + |
| +The first devbox's names and address are in #474. Release, then a person with root follows `infra/devbox/README.md` on the devbox and works through its smoke checklist. Once that passes: |
| + |
| +- remove the stopgap serve block (`tailscale serve --https=2950N off`, N = 0–9); |
| +- file the app-repo follow-up that switches review-link docs to `carlos devbox share` (spec §7). |