Commit Graph
5 Commits
Author SHA1 Message Date
Georgy Butaev e30c842869 feat(desktop) + fix(design,lint): project selection + auto-sync + Sync to Web (ck_* token); canonical injectIntoTab + real appendEvent bridge.dispatch/worker.started in Fleet Runner runtime (replaces fake in-memory); hardened zellij.ts (session resolution + -- write-chars); ui-public-download-* + --public-accent (zero design violations); full cockpit->fleetcrown rebrand in desktop/scripts/docs/thoughts/marketing/home; update desktop README + docs/desktop-app.md with capabilities + gaps (in-memory vs real log)
- desktop build clean, tsc clean, lint 0, home/ 89/89
- advances desktop-2/3: dispatches now produce durable events in ~/.fleetcrown/events.jsonl with proper runId/sentinel so stop-hooks and web control plane treat them as first-class
- still no embedded watcher (idle via co-running home/watcher.ts for now)

Refs: desktop-app.md phases, Cockpit.roadmap T1/T2, prior landing 2d98638
2026-06-02 14:54:51 +02:00
g-but 16dfdc0c88 fix(home): lint clean — convert require() to top-level imports + extend pre-commit to home/
home/log.ts:selfTest used `require("node:os")` and `require("node:crypto")`
to avoid adding top-level imports for test-only deps. Eslint's
@typescript-eslint/no-require-imports flagged both as errors. The
pre-commit hook only ran `eslint src/` so it never caught them.

Two fixes in one commit:
  • Moved the imports to top-level alongside the existing fs + path
    imports. randomUUID is named-imported (matches the existing
    home/emit.ts style); os stays default-imported.
  • Extended .husky/pre-commit's eslint step from 'src/' to 'src/ home/'
    so future home/ lint regressions can't slip through.

Three remaining cryp.randomUUID() callsites and the import block all
updated together. tsc clean, eslint clean, home/log 6/6 still green.
2026-05-20 07:28:56 +02:00
g-but 95768076f5 test(home): add self-test suite for log.ts — the read-side counterpart of emit.ts
Symmetric with d0e120f: home/log.ts had zero tests despite being the
read path every consumer relies on. A regression in the replay loop or
the per-line parser would silently drop events for the brain (state
drift) or the worker (lost dispatches). Six inline tests covering the
synchronous replay path:

  • Initial replay classifies every existing line as phase='replay'.
  • Garbled line surfaces via onError AND subsequent valid lines on
    the same replay still arrive — single bad line never poisons the
    rest of the stream.
  • Missing log file (and missing parent dir) is auto-created.
  • Empty file produces zero events, zero errors.
  • position() reflects bytes consumed during replay.
  • Blank lines between events are skipped silently (no onError noise).

Each test uses a fresh os.tmpdir + randomUUID file so cases don't
leak state between each other; everything is cleaned up via fs.rmSync.
Live-append testing is intentionally skipped — fs.watch is async/
debounced/best-effort on Linux, so the same consume() code path is
already exercised by the synchronous replay tests.

home/state 15/15 · home/decide 11/11 · home/projects 7/7 · home/worker
12/12 · home/render 12/12 · home/emit 5/5 · home/log 6/6 (new).
tsc clean.
2026-05-20 06:15:24 +02:00
g-butandClaude Opus 4.7 338237608c feat(home): M8 — worker.ts consumes bridge.dispatch events and injects via zellij
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>
2026-05-20 02:18:31 +02:00
g-butandClaude Opus 4.7 aeeaa466f7 feat(home): M2 — local Brain skeleton (tail event log → project state → /api/state)
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>
2026-05-20 01:23:03 +02:00