feat(daemon): walking skeleton, the App talks to the Daemon #2

Merged babariviere.com
targeting main from feat/daemon-walking-skeleton-the-app-talks-to-the-daemon
Merged opened by babariviere.com
targeting main from feat/daemon-walking-skeleton-the-app-talks-to-the-daemon

Summary #

The App connects to the Daemon over a WebSocket on 127.0.0.1, sends the Daemon's token, gets a snapshot, then events.

read ~/Library/Application Support/com.babariviere.pilot/daemon.jsonWebSocket + Authorization: Bearer <token>401 without the right tokensnapshot (Repos, Missions, Inbox)missionChanged, inboxChanged …connection ends → every page shows "Pilot's Daemon did not answer." + Try again, and the App retries every 5 sAppDaemonAppDaemon
protocol/
├── index.ts          # snapshot, events, address file, token header
└── scripted.ts       # control channel of the scripted Daemon (App tests)
daemon/
├── src/
│   ├── main.ts           # node src/main.ts: address file, SQLite file, start
│   ├── daemon.ts         # startDaemon: harness host + server
│   ├── harness-host.ts   # the only module that imports Pi Durable 1.6.0
│   ├── server.ts         # WebSocket server, token check, snapshot then events
│   └── github.ts         # GitHub gateway (gh), not used yet
└── test/
    ├── harness.ts        # Daemon test harness: real Daemon, throwaway SQLite, scripted pi-ai model, fake GitHub
    ├── scripted-daemon.ts + app-tests.ts   # runs nsh test in app/ against a scripted Daemon
    └── *.test.ts
justfile              # just dev: Daemon + App; just test; just check
app/
├── Shell.tsx         # top bar: Home, Inbox, Missions, Repos, Settings; back, forward; keys
├── pages.tsx         # each place with its loading, empty and error states
└── daemon.ts         # the App's link to the Daemon

Also: the App's id is now com.babariviere.pilot, and app/nsh.json declares its capabilities.

Development never touches the Owner's data. PILOT_PROFILE=dev gives the App and the Daemon their own folder (com.babariviere.pilot.dev) and port (47111). Every just recipe sets it.

New guardrails:

  • .tangled/workflows/ci.yml runs on every pull request to main. daemon runs the lint, type check and Daemon tests. app runs just check and the App tests headless on Linux.
  • just lint (scripts/lint.sh, part of just check) finds window widths outside ui/look.ts, hand-styled page titles, and nsh/base controls in screens.
  • just live-check runs the real App in a macOS window against a real development Daemon.

Agent docs: the nsh and nsh-design-guides skills from longbridge/nsh (.agents/skills/, pinned in skills-lock.json), and docs/nsh.md for the NSH traps they do not cover. AGENTS.md points to both.

Evidence #

  • Before: the App showed one title and the gallery. There was no Daemon. After: npm --prefix daemon test: 5 passed.
    only the harness host module imports Pi Durable
    the Daemon refuses a connection without its token        (HTTP 401)
    on connect the App gets a snapshot, then events
    every App connected gets each event, and an App that connects later starts with a snapshot
    the Daemon runs on its SQLite file and starts again on it after a restart
    
    npm --prefix daemon run test:app: 24 passed. 8 are new shell tests: empty states, events, the Daemon's error on every page, Try again, the retry on its own, a stuck Daemon that never sends a snapshot, a wrong token, and the Inbox count.
  • A real App window (nsh test --target macos) connected to a real Daemon and showed "Nothing waits for you".
  • just live-check passed. CI pipeline 3n334za6uvb22 passed both workflows (24 App tests on Linux).

Merge Danger #

Door: two-way

The protocol and the address file are new. Nothing depends on them yet.

Blast Radius: tests

A plain cd app && nsh test now fails the shell tests, because no scripted Daemon runs. Use npm --prefix daemon run test:app. The gallery's pictures now need cd app && nsh test App.test.tsx --target web.

Commits 1

feat(daemon): walking skeleton, the App talks to the Daemon
Sign up or Sign in to add to the discussion.