Plan: the hub on the phone, part by part (#688)

Closes: #688. Relates to: #255 (the pending record, whose paths these follow), #545 (the hub), #485 (full), #689 (the picker, the other half pivot waits on), pi-pivot#204 (the wire), pi-pivot#205 (the phone’s page). Branch: feat/hub-parts. Status: Done (2026-11-02) — U1-U4 on feat/hub-parts; the phone’s page is pi-pivot#205

Erratum (2026-11-02): the change signals reuse seams that already fire, rather than new hooks on HelperRuns and DecisionRing: a decision is registerJudge’s `onTrace (appendTrace pushes the ring, then calls it), and a helper’s start and end are wireSubagents’ `setRunningAgents and helperFinished. Monitors and jobs gain the planned callback (registerMonitorTools’ `onChanged, JobToolOptions.changed). index.ts hands each a late-bound hubChanged.poke, pointed at the publisher once registerHub exists.

Erratum (2026-11-02): registerHub builds the publisher and returns it, not index.ts: the facts part asks through the hub’s own facts state (askFacts), which registerHub holds. The facts part is read only on a whole publish (a hello, a session start), since asking emits gadhs-hub:ask on the bus.

Erratum (2026-11-02): a decision’s by is the record’s queuedBy (who sent a queued step to the human); TraceRecord has no agent. Its reason falls back to queuedFor as the tab’s row does.

Erratum (2026-11-02): the part parser, the record and the fit are a module of their own, pi-remote/hub-parts.ts (hubPartOf, hubRecord, fitPart), beside mirror.ts rather than in it, with their unit and vector tests in test/hub-parts.test.ts; the end-to-end cases are in hub-e2e.test.ts as planned. wire.ts re-exports 0.10.0’s hub types. pi-remote’s facts line for held-back items comes from hubPartNotes, which also says when the texts are withheld for want of a redactor. The link’s hello reaches pi-modes through LinkDeps.onHello, emitted on state.events, pi’s bus kept on the state.

Design

What was agreed (pi-dev’s review on #688, 2026-11-02; pivot-wire 0.10.0 published from it)

One record per part, not one snapshot: { t: "hub", session, at } & HubPart, with HubPart one of helpers | monitors | jobs | decisions | facts and its whole list, which replaces what the phone held for that part. pi’s own enum values travel verbatim (TraceDecision, TraceSource, HelperState, JobState, MonitorStatus). The published types (@gadhs/pivot-wire@0.10.0 on the project registry, 2026-11-02 16:24 UTC: types/HubPart.ts, HelperRun.ts, MonitorRun.ts, JobRun.ts, Decision.ts, HubFacts.ts, PendingStep.ts, and ToDevice.ts’s `{ "t": "hub", session, at } & HubPart arm) are the contract. The tree pins 0.9.0 today (pi-remote/package.json); U1 moves it to 0.10.0, so from U1 on the types are in node_modules/@gadhs/pivot-wire/types/ and pi-remote builds each record to its type, as it builds pending.

Where the facts are, and how a change is known

registerHub’s `HubDeps (pi-modes/hub-wiring.ts) already holds every source: helpers(), monitors().list(), jobs.list(), judge.decisions(), judge.pendingSteps(), and the asked facts (askFacts). The hub reads them fresh on each opening; nothing signals a change of a monitor’s last line, a helper’s live spend or a job’s latest line.

So pi-modes publishes by reading and comparing, not by hooking each source: a HubPublisher (new, pi-modes/hub-publish.ts) builds each part from HubDeps, serialises it, and emits gadhs:hub for a part whose serialisation differs from the last one emitted. It runs:

  • on a tick every 1 000 ms while anything is live (a running helper, monitor or job, or a step waiting), stopped otherwise: the tick is a few map reads and a JSON compare, and the interval is the cost of a moving last_line, which the hub’s own tab shows at that rate;

  • at once on a change signal, so an end is not a second late: each of HelperRuns, DecisionRing and the job watch gains a changed hook as MonitorRegistry has (monitor-registry.ts, changed?: () ⇒ void, called on start and end); the four hooks and the pending event are wired to the publisher in index.ts, where the registries are constructed (registerHub gets a HubPublisher it did not build, through HubDeps);

  • all five parts, compared or not, on a new bus event gadhs:hub-wanted from pi-remote when a phone says hello (below), and once at session_start. Not on gadhs-hub:ask: that is the event askFacts emits to collect the facts part, so answering it with a publish that calls askFacts would re-enter itself.

Only a session with the hub registered publishes (headless hosts register it too: registerHub runs for every mode). A helper’s child session publishes its own; the phone follows the sessions it is shown.

Each part, from pi’s records

Every field is the published type’s; nothing the phone cannot use goes out (no paths, no commands, no shell).

  • helpers: each HelperRun → { id, agent, task, model, state, started_at, ended_at, usd, exact, tokens, result }. usd/tokens/exact from priced when ended (exact its own), from live while running (exact: true: the ledger’s own), absent otherwise. result cut to 4 KiB with a marker, as the hub pane cuts it.

  • monitors: each MonitorSummary → { id, description, status, started_at, ended_at, exit_code, events: counts.events, actions: counts.actionsRun, actions_failed, restarts, last_line: lastLine?.text }. Not command, shell, files.

  • jobs: each JobEntry → { id, description, state: ended?.cause ?? "running", started_at: startedAtMs, ended_at: ended?.at, exit_code: ended?.exitCode, stuck, host, latest }. stuck as the hub reads it (STUCK_TEXT’s condition: running, no script start within `jobStartGraceMs); host a remote job’s host; latest the watch’s last line when the watch follows it, else absent.

  • decisions: groupDecisions(judge.decisions(), waitingIds) (hub-views.ts), newest first, at most 200 (the ring’s size): each → { at, decision: record.decision, source: record.source, step_id, step_state, summary, reason, by }; step_state from StepState as waiting on you → waiting, withdrawn → withdrawn, no longer waiting → settled; summary the item’s one line as decisionItemRow renders it (hub-views.ts); reason the judge’s reason or the pattern, cut to 2 KiB; by the record’s agent when it names one.

  • facts: the asked sources' lines, each { source, lines }, pi-remote’s own included when it answered.

full on a pending step

PendingQueue.snapshot() adds full when the entry has one (PendingEntry.full is set only when fullAction differs from shown, #485), and pendingStepsOf (pi-remote/mirror.ts) accepts and forwards it as PendingStep.full. PendingStepView gains full?: string. Absent otherwise, on both sides.

pi-remote: the record along the pending record’s four paths

The pending record travels: (1) the hub’s own session, forwardPending → link.broadcastControl; (2) a member, broadcastControl → the hub’s onPending → uplink.sendControl with the member’s id; (3) replay after every hello, peer.greet() from deps.pendings(), the hub’s own and each member’s; (4) the link’s attach, lifecycle.ts, for what the phones already show. A hub part follows each:

  1. forwardHub(state, data) reads gadhs:hub’s payload into a `HubPart by its allowed fields (hubPartOf, mirror.ts, as strict as pendingStepsOf: a malformed part is dropped whole and logged), keeps it in state.hubParts: Map<part, HubPart> (state.hub is the hub’s socket server already), and broadcasts { t: "hub", session, at, …​part } unless identical to what it kept.

  2. The hub’s onHub(member, json) rebuilds it the same way, keeps it on member.hubParts, and sends it up with the member’s id.

  3. greet() (peer.ts) sends, after the pendings, every kept part of every session through a new hubParts() on the view the link gives the peer (link.ts, beside pendings(): the hub’s own and each member’s).

  4. The attach (lifecycle.ts) sends the session’s kept parts after its pending.

On hello pi-remote also emits gadhs:hub-wanted, so a phone that joins gets fresh parts, not the last tick’s; pi-modes answers by publishing all five.

The record is sized as the pending record is (mirror.ts’s record cut, #199’s frame budget): a part over the cap drops its oldest items (decisions: oldest first; the others are small) and says so as a `facts line under source: "pi-remote".

Risks

Risk Mode Mitigation

A tick publishes a part that did not change

Silent: noise on the relay, battery on the phone

Compare the serialisation; the tick stops when nothing is live. Test: two reads of the same state emit once.

A part is published while a phone’s hello is in flight

Fail-open: a stale part shown after a fresh one

Every record carries at; the phone keeps the newer (pivot’s side, pi-pivot#205). Here, greet sends what is kept, and gadhs:hub-wanted after hello refreshes it. Concurrency test: a tick’s part and a hello’s replay interleaved leave the phone with the later at last.

A malformed payload from a member (an older pi-modes)

Fail-closed: dropped

hubPartOf as strict as pendingStepsOf, logged as control hub malformed.

A secret in a helper’s result, a monitor’s last_line or a job’s latest

Fail-open: disclosure to the phone

The same text already reaches the desk’s hub, and the transcript pi-remote mirrors was redacted by pi-workflow at tool_result before it entered the session; these three texts never pass that seam. pi-workflow’s redactSecrets (redact.ts) is reachable from neither pi-modes nor pi-remote (ADR-004: no package dependency either way; the existing bridge runs from pi-modes to pi-workflow). So pi-workflow publishes a redactor on a global symbol of its own, gadhs:pi-workflow-redact, at init, the mirror of the existing bridge, and pi-remote consumes it lazily in hubPartOf. Absent (pi-workflow not loaded), the three fields are not sent at all: fail-closed, and the facts part says redaction unavailable: results and lines withheld. Test: a token-shaped result is masked with the redactor present, and withheld without it.

The record over the frame budget

Fail-closed: a dropped frame, the part missing on the phone

The pending record’s cut, generalised; decisions trimmed oldest first and said in facts.

gadhs:hub-wanted on every hello

Silent: five emits per hello

Cheap reads; the hub does the same on open.

A field the phone should never get (a path, a command, a shell)

Fail-open: disclosure

Each builder constructs the wire object field by field from the published type; no spread of a pi record. Test: the serialised parts of a seeded hub contain none of the seeded monitor’s command, shell or files, the job’s cwd, log or script, or the helper’s transcript path.

Out of scope

Acting on the hub from the phone (stop a monitor, approve from a decision row): read-only first, as pi-pivot#158 decided. Messages (#566). The phone’s page itself (pi-pivot#205).

Scope

Each unit one commit on feat/hub-parts; pi-modes' and pi-remote’s suites green; new tests mutation-checked. U4 closes #688.

U1: full on the pending step

pi-modes/pending-event.ts: full?: string. pending-queue.ts snapshot(): full when the entry has one. pi-remote/package.json: @gadhs/pivot-wire 0.10.0 (lockfile updated). pi-remote/mirror.ts pendingStepsOf: accepts a string full, refuses any other type. Tests: pi-modes/test/pending-queue.test.ts, unit: a long or multi-line action snapshots with full, a short one without; pi-remote/test/units.test.ts (where pendingStepsOf is tested), contract: a step with full is forwarded with it, a non-string full drops the snapshot.

U2: pi-modes publishes the parts

pi-modes/hub-publish.ts: HUB_EVENT = "gadhs:hub", HUB_WANTED_EVENT = "gadhs:hub-wanted", the five builders (pure, each from the record types above), HubPublisher (compare-and-emit, the tick, publishAll). decision-ring.ts, helper-runs.ts, job-tools.ts’s watch: a `changed hook each, as monitor-registry.ts has. hub-wiring.ts: HubDeps gains publisher; registerHub wires gadhs:hub-wanted and session_start to publishAll. index.ts: builds the publisher, hands it to registerHub, and wires the four changed hooks and the pending event to it. Tests, pi-modes/test/hub-publish.test.ts: unit — each builder on a seeded record, every field, the enum values verbatim, the cuts at 4 KiB and 2 KiB, the step_state mapping, stuck, host; integration through registerHub on a fake pi — a changed monitor line emits monitors once and nothing else, an unchanged tick emits nothing, a helper’s end emits helpers at once, the ask emits all five, the tick stops when nothing is live. Mutation: the compare removed makes the unchanged-tick test fail.

U3: pi-remote forwards the parts

pi-workflow/redact-bridge.ts (new): publishes { redact: (text) ⇒ string } on Symbol.for("gadhs:pi-workflow-redact") at init, from redactSecrets. pi-remote/redact.ts (new): reads it lazily; undefined when absent. pi-remote/mirror.ts: hubPartOf (strict shape, then the redactor over result, last_line and latest, or those three withheld and said when it is absent), the record cut for a part. pi-remote/state.ts: hubParts. pi-remote/index.ts: forwardHub on gadhs:hub; gadhs:hub-wanted emitted on hello. pi-remote/hub.ts: onHub, member.hubParts. pi-remote/link.ts: hubParts() on the peer’s view, beside pendings(). pi-remote/peer.ts: greet sends the parts after the pendings. pi-remote/lifecycle.ts: the attach sends them. Tests, pi-remote/test/hub-e2e.test.ts beside the pending cases: contract — the hub session’s part reaches the phone as 0.10.0’s record (checked against the published type by a vector from node_modules/@gadhs/pivot-wire/vectors), a member’s with the member’s id, an identical part again sends nothing, a malformed one is dropped and logged, hello replays every kept part and asks for fresh ones, the attach sends them, a part over the cap is trimmed oldest-first and says so; concurrency — a tick’s part and a hello’s replay interleaved leave the later at last; security — a token-shaped result from the bus is masked in the record the phone gets with the redactor published, and withheld and said without it. pi-workflow/test/redact.test.ts: the bridge publishes `redactSecrets’ behaviour.

U4: docs and release note

docs/modules/ROOT/pages/remote.adoc: "What the phone is told about the hub" beside the pending section: the five parts, when they go, what never goes (paths, commands), the cut. docs/modules/ROOT/pages/modes.adoc, the hub section: one paragraph that the hub is published to a paired phone. CHANGELOG.adoc Unreleased, Added; pivot-wire 0.10.0 named. Closes #688.

Edit this page · latest