Dogfooding the local dispatch loop (drive orangecat from FleetCrown) dead-ends
immediately: the documented way to boot the engine references files deleted in
a3f470d. That commit retired the standalone Brain (home/server.ts, :3001) and
its scripts/home-start.sh launcher — Fleet Runner desktop is now the sole local
executor — but explicitly deferred the doc cleanup to a "Session 4c" that never
happened. So a reader following the docs runs commands for files that don't
exist.
home/README.md:
- Title/intro/diagram no longer present the 3-process Brain stack as current;
they describe the 2 remaining pieces (watcher + worker) + Fleet Runner.
- "## Run": drop `bash scripts/home-start.sh` and `npx tsx home/server.ts`;
document the real per-piece `--start` iteration path.
- Smoke-test sections: replace dead `POST :3001/api/dispatch|/api/cancel` with
the verified current path — appending bridge.dispatch / bridge.cancel events
straight to ~/.<slug>/events.jsonl (the worker's actual contract).
- Files table: drop the deleted server.ts row; add the real state.ts / log.ts.
- Testing note: server.ts HTTP testing claim removed.
CLAUDE.md: home/ stack description + Dev Commands updated to match (Fleet
Runner is the executor; no home-start.sh).
Docs-only; every remaining server.ts/home-start mention is explicitly historical.
Every dispatch out of /api/dispatch was defaulting to 'claude' because
the caller (the UI Dispatch button) doesn't send an adapter, the
project state doesn't carry one, and the brain had no other source.
Projects that should run codex or gemini (e.g. anything cross-checking
a Claude session, or codex for OpenClaw) silently got the wrong agent.
Extended agent-projects.conf with an optional 3rd pipe-separated field:
Cockpit|/home/g/dev/cockpit
OrangeCat|/home/g/dev/orangecat|codex
Two-field entries keep their semantics (adapter stays undefined →
downstream defaults to claude, same as before). The 3rd field is
validated against @/lib/events ADAPTERS — unknown values silently
degrade to undefined so a typo doesn't poison dispatches.
Files touched:
• home/projects.ts: ProjectConfig grows an optional adapter field,
loader parses the 3rd column, new resolveProjectAdapter() helper.
• home/server.ts: /api/dispatch adapter resolution now does
caller-body ?? resolveProjectAdapter(project) ?? undefined; worker
keeps defaulting to claude when both are absent.
• home/README.md: files table updated to reflect the new format.
home/projects 11/11 (was 7) — four new cases cover the codex 3rd
field, resolveProjectAdapter, two-field entries staying undefined,
and the unknown-adapter typo-defence path. Full suite: 82/82
across the eight home/ modules. tsc clean, eslint clean.
home/README.md said 'state.ts # 15 tests' and CLAUDE.md said '76 inline
tests' — both stale already (3ff199f added 2 state regressions so the
true count is 17/78). Every test-add commit was implicitly creating
a doc-rot debt. Replaced the hardcoded numbers with semantic labels
('event projection', 'autonomy + confidence', etc.) and added one
short note that 'npm run test:home' aggregates the actual N/M total —
the real count lives in the test runner output, not in prose.
No code change. tsc clean.
.husky/pre-push already runs the dev-server smoke when the server is
detected; the eight inline home/ self-test suites had no automatic
gate, so a typo in state.ts or decide.ts could push to origin without
anyone noticing until the next /control session went sideways.
Added 'npm run test:home' at the top of .husky/pre-push (always runs,
no server dependency, ~14s). Smoke still follows when the server is
up. Net push time: tsc+eslint (pre-commit, <5s) + test:home (~14s) +
smoke (~3s when server up). Pre-commit stays fast — 14s on every
commit would be too much friction.
Pre-commit unchanged. Updated home/README.md's 'Inline self-tests'
section to lead with 'npm run test:home' and note it's wired to
pre-push.
Dry-ran the pre-push hook end-to-end: 76 home/ tests + 40 smoke
routes all pass. tsc clean.
The README's individual-process invocation section pointed at
worker.ts --self-test as a one-off, but emit/log/watcher all gained
their own --self-test branches in the last three commits (d0e120f,
9576807, e85e249). New 'Inline self-tests' section between
Idempotency and What's not here yet, with the exact invocation for
each of the eight suites and current test counts (76 total inline
tests across the stack).
Also documents why server.ts is the lone holdout — its route
handlers are bound to req/res streams, so unit-testing them in
isolation isn't worth the mocking cost; npm run smoke (which boots
the real dev server and curls every route) covers it instead.
No code change. tsc clean.
Everything that's shipped in the last five commits invalidated chunks
of home/README.md. Bringing it back in sync:
• Per-process invocations now need --start (commit 7ecbc0f). The
naked examples were footgun-bait — anyone copying them would hit
the new usage-banner and assume the docs were wrong.
• The dispatch smoke test used autonomy=auto, which after commit
4237260 doesn't fire on a fresh project (confidence 0.5 < 0.55).
Added the four-mode threshold table so the semantic difference
between manual/confirm/auto/sleep is clear, and the example uses
manual (the human-clicks-Dispatch path) for an immediate fire.
• Added a /api/cancel smoke (commit dd382eb) with a note that the
eventual worker.finished gets re-labelled user_abort (commit
e81d9ee) since the bash stop hook can't infer that on its own.
• Files table: added home/projects.ts (registry SSOT), listed
/api/cancel + /api/events on server.ts, mentioned watcher's
registry filter, and noted the worker also handles bridge.cancel
+ emits worker.crashed.
No code change. Tests untouched; tsc clean.
scripts/home-start.sh starts server + watcher + worker together, merges
their output (with [server] / [watcher] / [worker] prefixes per line)
into /tmp/${APP_SLUG}-home.log, and traps SIGINT to take the whole stack
down cleanly. Removes the previous three-terminal ceremony — one command,
one log, one Ctrl-C.
Pre-flight: refuses to start if anything is already serving
localhost:3001, so two stacks can't race on the same events.jsonl file.
Wait -n: if any child process exits unexpectedly, the launcher tears the
remaining two down. The user gets one obvious signal instead of a quiet
half-broken loop where (say) the worker crashed but the server kept
serving stale state.
home/README.md updated to point at the launcher first, with the
three-terminal recipe kept for iterative development.
Unblocks the M9 live exercise: previously each test required three
terminals + remembering each command + cleaning up three pids manually.
Now it's `bash scripts/home-start.sh` → curl /api/dispatch → Ctrl-C.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Eighth milestone of the greenfield rewrite. home/worker.ts is the consumer
half of the dispatch loop. Tails the same JSONL log home/server.ts reads,
filters for bridge.dispatch events, and injects each prompt into the
right zellij tab via @/lib/zellij.injectIntoTab. On success emits
worker.started with the same runId; on injection failure emits
worker.crashed.
With M8 the loop closes locally:
user/UI POST → /api/dispatch → bridge.dispatch event in the log
→ worker.ts (this commit) → injectIntoTab → claude runs
→ claude writes session.md → M3 watcher → worker.idle event
→ claude stop hook → M4 emit → worker.finished event
→ Brain projects all of it back into state
Idempotency: home/log.ts gained a phase flag ("replay" | "live") so the
worker can distinguish initial log replay (build the set of already-started
runIds) from live appends (act on new dispatches). Restarting the worker
never re-injects. Bridge dispatches that exist in the log with no matching
worker.started downstream are treated as crash-recovery and fired after
replay completes (setImmediate signals the event-loop rollover).
Three Node processes now run side by side:
home/server.ts Brain. /api/state, /api/dispatch, the UI.
home/watcher.ts Bridge. session.md → worker.idle.
home/worker.ts Consumer. bridge.dispatch → injectIntoTab → worker.started.
home/log.ts: tailLog signature gained `phase` as the second arg to onEvent.
home/server.ts ignores it (just updates state), home/worker.ts uses it.
Existing call site is forward-compatible (TS allows ignoring optional
trailing arg), no other home/ file needed an update.
home/README.md rewritten to document the three-process model + a curl-
based smoke test of the dispatch loop.
What this commit deliberately does NOT do:
- retire /api/control/dispatch on Vercel (M9 — parity verification first)
- persist startedRunIds across restarts in any way other than via log
replay (the log IS the durable state)
- per-project adapter selection — worker.started always claims adapter:
"claude" for now; M9 reads project config
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Second milestone of the greenfield rewrite. A standalone Node HTTP server
in home/ that boots, tails ~/.<APP_SLUG>/events.jsonl, projects each event
into per-project state, and serves a minimal status UI at localhost:3001.
No external deps beyond node:* and the existing zod via @/lib/events.
home/state.ts pure applyEvent(state, event) → state — testable in
isolation; project view stays minimal (currentRun,
lastHandoff, recentOutcomes ≤ 5) for M2
home/log.ts tail one JSONL file via fs.watch + position tracking;
replays existing content on boot, recovers from file
truncation, returns parse errors via onError instead of
throwing (so a garbled line doesn't kill the daemon)
home/server.ts HTTP server with /control HTML view + /api/state +
/api/health + /api/events (manual append for testing).
Vanilla JS in the HTML, no React yet — that lands when
the brain replaces the existing /control surface.
End-to-end verification (against ~/.cockpit/events.jsonl):
- worker.started → project appears with running pill
- worker.finished → pill clears, outcome glyph ✓ in streak,
handoff text shown
tsconfig.json includes home/**/*.ts so the existing tsc + eslint gates
cover the new code. Runs separately from the Next.js app — no port
collision, no Vercel involvement, no DB needed.
What this commit deliberately does NOT do:
- emit events (M4 — replace the agent stop-hook to append to the log)
- decide (M5 — pure decide() function over state)
- dispatch (M6 — wire bridge.dispatch back to a worker)
- persist beyond the log (state rebuilds from log replay on boot)
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>