Repository navigation
feat(dev): pnpm dev runs a per-worktree local instance an agent can keep alive - #81
Conversation
There was no local instance an agent could start, keep alive across turns and tear down cleanly; `pnpm dev` was `turbo run dev`, tied to the shell. `pnpm dev` is now an Effect 4 CLI in `scripts/dev` (the `@patchy/dev` workspace package). It computes a per-worktree plan (ports from a hash of the worktree path, state in `.local/dev/`), spawns a detached supervisor under `node --import tsx`, and returns when `/healthz` answers. The supervisor owns one scope: embedded Postgres via `acquireRelease`, the server via `ChildProcessSpawner` with SIGTERM-then-SIGKILL, so either exiting tears down the other. `status`, `stop`, `logs` and `reset` act only on the pids `plan.json` records; `--dry-run --json` prints the plan with no side effects. The seed (one dev company, one admin token) is a SQL fixture shared with the vitest Postgres template. Closes #70 Co-Authored-By: Claude Fable 5 <[email protected]>
Code review — PR 81 vs #70Two-axis review of StandardsNo Hard (documented)Functions return
const healthy = (plan: Plan) =>
HttpClient.get(`${plan.apiUrl}/healthz`).pipe(
Effect.map((response) => response.status === 200),
Effect.orElseSucceed(() => false),
Effect.provide(FetchHttpClient.layer)
);Provide Tests re-provide Judgement (smells; not violations)
SpecAgainst issue #70, quoted per finding. (a) Missing or partial“Env goes straight to each child.” Server spawn in “each service via “ (b) Scope creep“ Env also writes (c) Implemented but wrong“compute plan → … → start the server → write That early write also weakens “Start is idempotent”: Comment “Its env is exactly the plan, nothing inherited wins” ( Met (called out)Language-service warnings are errors in Intent (#70)#70's product problem: an agent needs a local Patchy Cloud it can start, keep using across turns, and tear down cleanly — also the port's first Effect 4 code, so later port PRs have something to smoke on. That problem is solved. The last mile is still “point the CLI at No watch is honest, not a gap: #70 did not ask for it. MethodThe spec demanded this method, and the method is the right one. One foreground process cannot outlive an agent turn. Docker Compose / turbo+wait-on fail the ticket (embedded Postgres, “Turbo is not on the dev path,” Effect-first harness). Daemonizing is the supervisor.
Effect is used as the tool, not as architecture-for-show: CLI, Schema, Seed shared with vitest is spec-demanded coupling. Sharing the rows is good.
YAGNIThe tight parts should stay: one Plan schema, Do not flag the plan hash/scan, detached supervisor + What is extra or ugly:
Standards: 3 documented findings, 4 smell judgement calls. Worst: Spec: 3 partial, 2 scope, 2 wrong. Worst: start is not actually idempotent for the whole window it waits on |
Review fixes on #81. `start` records the supervisor pid the moment it is spawned, so a second `pnpm dev` during initdb refuses instead of starting a second supervisor on the same data dir; `--dry-run` reports the recorded plan in that window rather than failing. The server's env is closed (plan + PATH and HOME) instead of extending the shell's, which the old comment claimed and the code did not do. `/healthz` probes are bounded so a server that accepts the socket but never answers does not hang the runner. Failures are mapped to `CliError.UserError` inside the handlers so `Command.run` prints one line instead of `runMain` printing a stack. `HttpClient` is provided at `runMain`; pid probes and the Postgres fixture constants live in one place each; handlers use `Effect.fn`; the plan tests share one `it.layer`. README points at `pnpm dev`. Co-Authored-By: Claude Fable 5 <[email protected]>
|
Thanks for the review — went through every item against the source. What changed in 2nd commit, and what I left alone and why. Fixed
Not changed
Lint, typecheck (language-service rules as errors for Written by Claude Fable 5 via Claude Code. |
What changed
There was no local instance an agent could start, keep using across turns and tear down cleanly:
pnpm devwasturbo run dev, tied to the shell that ran it, with no Postgres, no seed and no way to run two worktrees at once.pnpm devis now an Effect 4 runner (scripts/dev/, the port's first Effect code). It computes a plan for the current worktree — ports hashed from the worktree path, state in.local/dev/— starts embedded Postgres, migrates, seeds one dev company with a working token, starts the server, writes.local/dev/envand returns once/healthzanswers. The processes live in a detached supervisor that owns one Effect scope, so either service exiting (orstop) tears the other down.status,stop,logs,resetand--dry-run --jsonround it out;docs/DEVELOPMENT.mddocuments all of it.One behaviour change outside the runner: the vitest Postgres template now carries the same seed (
acct_dev/patchy-dev-token) instead of a bootstrapdev-token. Every Postgres test bootstrapsdev-tokenitself, so nothing depended on the template row.Closes #70
How it was verified
Plan tests (
scripts/dev/src/plan.test.ts): hash → ports, upward scan,plan.jsonround-trip, worktree detection — no processes.Manually:
pnpm devhealthy in ~3s; secondpnpm devis a no-op; CLIwhoamianduploadagainst.local/dev/envsucceed; two worktrees side by side,stopin one leaves the other healthy;stopleaves no stray processes;resetre-initdbs and re-seeds;kill -9of the postmaster closes the whole instance.pnpm lint,pnpm typecheck(language-service warnings promoted to errors forscripts/dev),pnpm format:check, fullpnpm test(57 files, 1820 tests).pnpm testpasses locallyAdded or updated tests covering this change
Release impact
Tick exactly one.
Local development tooling only; no change to the CLI's public behaviour, the API, the schema or configuration.
Written by Claude Fable 5 via Claude Code.