Node-based terminal manager for AI coding agents — tmux-backed terminals and parallel agent sessions as draggable nodes on an infinite pan/zoom canvas. macOS, Linux, and a browser Server Edition.
Plan: live (shared) dino game — spectator mode
Branch: feat/dino-live (worktree /root/nodeterm-dino, off main)
Spec: docs/superpowers/specs/2026-07-14-dino-live-design.md (approved)
Summary
The dino game state is local-only, so a shared canvas shows independent dinos. Make it a spectator
feature: one authority plays, others watch the same game live — by riding the presence layer (an
ephemeral PeerState.dino field, like chat). No new core channel; works over local/relay/browser
via the hub automatically.
Tasks (subagent-driven, TDD, review each) — sequential (one worktree)
Task 1 — Shared types + hub cast handler (foundation)
src/shared/presence.ts: addDinoSnapshot(y, ducking, crashed, started, score, speed, groundScroll, obstacles[{kind,x,y,sx,sw,sh,flap}]); adddino: { nodeId: string; snap: DinoSnapshot } | nulltoPeerState; add capsDINO_MAX_OBSTACLES(≈ 12) and asanitizeDinoPayload(payload): {nodeId,snap}|nullpure helper that clamps obstacle count, coerces numbers, caps the nodeId (REF_MAX_LEN), and returns null for anything malformed/oversized (mirror the chat/focus cap discipline).src/core/presence/hub.ts: handle a newpresence:dinocast — runsanitizeDinoPayload, set the sender'sPeerState.dino, broadcast aPeerDiffupdate. Mirror the existingpresence:chathandler exactly (same dumb-reflector path).leave/disconnect already drops the whole peer state, sodinoclears for free — confirm no extra work.- TDD (
hub.test.ts): adinocast sets the sender'sdino+ broadcasts anupdate; a payload withDINO_MAX_OBSTACLES is clamped; a malformed payload → null (dropped); a
leaveclears it. - Also add
IPC.presenceDino = 'presence:dino'tosrc/shared/ipc.ts(a cast, next to presenceChat) so Task 2 wires it — but the HANDLER registration in the shells is Task 2's job if it lives outside the hub; if the hub is where casts are dispatched, register here. Check howpresence:chatis dispatched (main index / server ws / the hub) and follow that seam.
Task 2 — Wire: preload + bridge + presence session
src/preload/index.ts:presence.dino: (payload) => ipcRenderer.send(IPC.presenceDino, payload)(mirrorchat). Update thePresenceApitype inshared/types.ts.src/renderer/bridge/*(ws-bridge / stubs): the browser bridge shim forpresence.dino(a cast over the WS-RPC, likepresence.cursor/chat). Thesatisfies NodeTerminalApigate forces the declaration — wire it as a real cast (presence works in the browser), not a stub.src/renderer/state/presence.tsPresenceSession: add adino(payload)write (casts on the session'sapi.presence.dino) and aselectDino(state, nodeId)selector returning the OTHER peer (not self, filtered bymyId) broadcasting adinowhosenodeIdmatches — mirrorselectVisible/ the chat selectors. Session-aware for free (it's on the PresenceSession).- TDD (
state/presence.test.ts):selectDino(nodeId)returns a peer broadcasting for that node, excludes self and other node ids;dino(payload)casts on the api.
Task 3 — dino-game engine: broadcast + spectate
src/renderer/nodes/dino/dino-game.ts: add tocreateDinoGame's opts anonSnapshot?: (snap: DinoSnapshot | null) => voidand to its returned interfacesetRemote(snap: DinoSnapshot | null): void+isAuthority(): boolean.- Broadcast: in
frame(), atDINO_BROADCAST_HZ = 20(throttle by wall-time since last emit), callonSnapshot(currentSnapshot())while the local sim is authoritative andstarted || crashed; callonSnapshot(null)when it returns to pre-start idle / onstop()/destroy(). - Spectate:
setRemote(snap)with a non-null snap puts the game in REMOTE mode — the rAF loop still runs (to draw) butupdate()is suspended and input (jump/duck) is ignored;draw()renders the remotesnap(dino y/frame, obstacles, score, GAME OVER).setRemote(null)returns to LOCAL mode (own sim resumes from idle). Local input while in REMOTE mode → immediately switch to LOCAL (take-over: seed the sim from the last remote snap for continuity), and the caller starts broadcasting.
- Broadcast: in
- Keep the file self-contained (no imports beyond the DinoSnapshot type). Extract
currentSnapshot()and the remote-draw as small internal functions. - TDD (
dino/dino-game.test.ts): drive the state machine without a real canvas where possible (mock the 2d context) —setRemote(snap)suspends update + renders the snap; a local key in remote mode switches to local + fires the take-over;onSnapshotthrottles to ~20 Hz and yields null on idle. If a full canvas mock is too heavy, extract the mode/throttle/snapshot logic into a tiny pure module and test THAT; state what you did.
Task 4 — DinoNode wiring (authority + spectate + label + tiebreak)
src/renderer/nodes/DinoNode.tsx: it's under the active-session provider.- Get the active presence:
const presence = useActiveSessionPresence()andconst { api } = useSession(). - Pass
onSnapshot: (snap) => api.presence.dino(snap ? { nodeId: id, snap } : null)tocreateDinoGame. - Subscribe
presence.store(useShallow((s) => selectDino(s, id)))→ the peer (if any) broadcasting for THIS node. When present AND that peer should win the authority tiebreak (lower clientId wins; if OUR clientId is lower we keep local play and ignore the remote), callgame.setRemote(peer.dino.snap)on each new snapshot; when absent,game.setRemote(null). - Render a small "▷ is playing" label (peer color) while spectating.
- On unmount,
api.presence.dino(null)if we were the authority (belt-and-suspenders; the engine'sdestroy()/stop()already emits null via onSnapshot).
- Get the active presence:
- TDD: extract any non-trivial decision (the tiebreak: given my clientId + the broadcasting peer, do I spectate or keep playing?) into a tiny pure helper + unit-test it. The JSX wiring relies on typecheck (no jsdom for DinoNode).
Task 5 — Gate + docs + acceptance
npm run typecheck+ fullnpx vitest rungreen (the pre-existing workspace-watcher fs-timing failure is not ours — confirm it's the only red).docs/team-presence.md(or remote-sessions.md): note the dino live/spectator feature rides presence.- Update the dino spec's status to landed.
- Two-instance acceptance (append to the checklist): A plays a shared dino → B watches it live with A's name; B presses Space → takeover; A closes/disconnects → B falls back to idle.
Merge gate
No crypto/handshake file touched. Full suite + typecheck green. Whole-branch review: the hub cap can't
be bypassed (a peer can't flood via presence:dino); the perf contract holds (the ~20 Hz snapshot
does not re-render Canvas — DinoNode already re-renders on its own state, and the broadcast is a cast,
not a Canvas subscription); local-only + solo behavior byte-identical (no peers → cast is a no-op,
own sim runs as today). Then merge to main.