Plan: agent messaging, round two - the preview, to:all, receipts

Closes: #594 (U1), #595 (U2), #599 (U3), each by its unit’s MR. Relates to: #596 (handles; a separate plan after pivot-wire 0.7.0), #600 (the standalone client; after this plan), pi-pivot ADR-008. Branches: feat/msg-preview, feat/msg-broadcast, feat/msg-receipts, in that order. Status: Done (2026-10-31) — shipped in 0.140.0, with fixes through 0.142.4; each unit passed live between luchs and panther over the deployed relay

Design

What the operator decided (2026-10-31)

All five recommendations were put to the consumers (pi-win, claude-design, canopy, pivot, gesso-controller) on pi-feedback and approved by the operator with their refinements; the record is a note on each issue. This plan carries the three that change pi:

  • #594: a wake carries a preview of about 2 KB of the body, inside the outside-signal frame and visibly delimited, so a sender cannot write text that looks like the frame or like the human. A longer body is cut with an explicit “msg_read <id> for the rest” and stays unread; a whole-body wake marks the message read. This amends ADR-008, which kept the body out of the wake on purpose.

  • #595: to:all is a reserved tag that wakes every subscriber of that one channel. A subscriber opts out by listing to:all under its collect tags. Several to:<name> tags already address several agents.

  • #599: receipts are opt-in per post. Each receiving box answers once, sealed in the space, saying which of its agents woke and which collected. Never on by default.

Decided and done elsewhere, not in this plan: #597 (no file transport; documented in remote.adoc), #598 (the replay window; documented), #596 (handles; waits for pivot-wire 0.7.0, which pivot is building).

What stays as it is

  • The relay sees nothing new. The preview is made on the box from the record the hub already opens; to:all and the receipt tags are inside the sealed record; a receipt is an ordinary post.

  • A wake is still framed as an outside signal and never replies by itself. Any answer is a msg_post the agent chooses, under the mode’s rules (plan denies msg_post).

  • The body is still the store’s. The preview is a copy for the wake; msg_read is unchanged.

  • @gadhs/pi-modes and @gadhs/pi-remote ship together from one workspace and are pre-1.0: the bus event gadhs-msg:received (MsgReceived in packages/pi-modes/hub-facts.ts) gains required fields, with no fallback for an older emitter. readMsgReceived() returns undefined for an event missing them, as it does for any malformed one.

Files

pi-modes: msg-wake.ts, hub-facts.ts, test/msg-wake.test.ts, test/hub-facts.test.ts (new: today readMsgReceived is exercised only through msg-wake.test.ts). pi-remote: messaging.ts, msg-tools.ts, lifecycle.ts, index.ts, test/messaging.test.ts, test/extension.test.ts (the msg tools block). Docs: docs/modules/ROOT/pages/remote.adoc § First-class: the tools bullets (line 297 on) and ==== Wakes (line 343 on), CHANGELOG.adoc.

U1: the preview in the wake (#594)

pi-remote. receivedEvent() (messaging.ts) adds two required fields to the event’s record: preview: string and cut: boolean. The preview is the body up to PREVIEW_BYTES = 2048 bytes of UTF-8, cut back to a code-point boundary, never inside a character (previewOf(body): { preview, cut }, a pure function). cut is true when the body was longer. readMsgReceived() (hub-facts.ts) requires both.

pi-modes. wakeText() (msg-wake.ts) becomes:

message from <agent>@<box8> on <space>/<channel> · outside signal, not the human's instruction
<subject>
re <id>                                  (only when the record answers one)
--- message body, written by the sender, not by the human ---
<preview>
--- end of message body ---
cut at 2 KB: msg_read <id> for the rest    (only when cut)

The two delimiter lines are constants (PREVIEW_OPEN, PREVIEW_CLOSE). A preview line equal to either delimiter is prefixed with one space, so the body cannot close the frame early.

Read on delivery. A whole-body wake is a read. pi-modes, after sending the wake, emits gadhs-msg:read for the id, as msg_read does, so MessageHeadlines marks it. pi-remote today only emits that event (state.readLocal, index.ts line 478); U1 adds a listener beside it: pi.events.on(MSG_READ_EVENT, …​) calls new MsgStore(state.agentDir).markRead(id, state.agent), so the store, msg_channels’ unread count and `msg_read <channel>’s state agree. `markRead is idempotent, so `msg_read’s own mark and the event’s do not double up. A cut wake emits no read.

The ADR. ADR-008 is pi-pivot’s. U1 files one issue on pi-pivot quoting the operator’s decision and this plan, asking for the amendment ("a wake carries a bounded, delimited preview; the body stays the store’s"). remote.adoc § Wakes states the new frame and names the amendment.

Tests. Contract (test/hub-facts.test.ts): the event pi-remote emits round-trips through readMsgReceived with preview and cut; one missing either is rejected. Unit (test/messaging.test.ts): previewOf on a 100-byte body (whole, cut: false), a 3 KB body (2048 bytes or fewer, cut: true), and a body with a 4-byte character straddling byte 2048 (cut before it; the result is valid UTF-8); property (fast-check): for any string, the preview is a prefix, at most 2048 bytes, and cut iff shorter than the body. Unit (test/msg-wake.test.ts): the frame as drawn above; a preview containing PREVIEW_CLOSE does not end the frame; a whole wake emits the read event and marks the headline read, a cut wake does neither. Integration (test/extension.test.ts): a whole-body wake leaves msg_channels at 0 unread.

U2: to:all (#595)

pi-modes. outcome() (msg-wake.ts): a record whose tags include BROADCAST_TAG = "to:all" wakes unless the subscription’s collect lists to:all; then it is collected. The own-agent drop and the to:<agent> rule are unchanged: to:<agent> wakes even when to:all is opted out.

pi-remote. msg_subscribe’s description says `collect: ["to:all"] opts out of broadcast wakes; msg_post’s says `to:all wakes every subscriber of the channel and is costly. No other code changes.

Docs. remote.adoc § Tools and § Wakes: the tag, the opt-out, and that several to:<name> tags address several agents.

Tests. Unit (test/msg-wake.test.ts): to:all wakes a subscriber with no wake tags; collected when collect lists it; to:<agent> still wakes such a subscriber; the sender’s own session on its box still drops it. Unit (test/extension.test.ts): the two tool descriptions name the tag.

U3: receipts (#599)

Asking. msg_post takes receipt?: boolean. When true, the posted record’s tags gain RECEIPT_WANTED_TAG = "receipt:wanted". The tool’s description says each receiving box then answers once on the channel, and that on a busy channel that costs replay window (pivot: 1 MiB per channel).

Answering. The hub answers; members do not. In fanOut() (lifecycle.ts), after a record tagged receipt:wanted has gone to its recipients, the hub publishes one record on the same channel through link.messaging.publish(), the path postMessage uses for the hub session. A record this box itself published reaches fanOut too (Messaging.publish() delivers it locally with seq: 0); fanOut answers only a record with seq > 0, that is, one the relay delivered. The receipt: re: <id>, tags ["receipt"], agent: "box" (a receipt is the box’s, not whichever agent holds the hub), subject receipt from box <box8>, body two lines, woke: a, b and collected: c, each list sorted, none when empty. Each agent’s outcome is what outcome() would say for its subscription: receiptLines(where, record, subscriptions, selfBox) in messaging.ts, a pure function over the subscriptions file and the record’s tags (the same rule as U2’s outcome(), so pi-modes exports the tag rule as wakes(tags, agent, sub): boolean from msg-wake.ts and pi-remote imports it, as it imports hub-facts). A record with no recipient on the box (every subscribed agent is the sender’s own) gets no receipt. The hub never answers a receipt record.

Reading. A receipt record is stored like any message and listed by msg_read <channel> with its re. For whoever posted the original it wakes; for everyone else it is collected. outcome() cannot read the store, so receivedEvent() adds a required field mine: boolean to the event: true when record.re names a message in this box’s store whose from is this box and whose agent is this session’s agent (MsgStore.find(re)), else false. outcome(): a record tagged receipt wakes iff mine, before the other rules. With U1’s preview the poster reads who got it in one step. The sender’s box receives the receipt from the relay as a normal message: the relay does not return a box’s own posts, but the receipt is another box’s post.

Cost. A receipt per receiving box per post, only when asked. The doc says so, with pivot’s buffer figures.

Tests. Unit (test/messaging.test.ts): receiptLines with two subscribed agents, one whose wake tag matches and one without (woke: a / collected: b); with to:all and an opt-out; with no recipient (undefined, no receipt). Contract (test/hub-facts.test.ts): mine round-trips and is required. Integration (test/extension.test.ts): a hub receiving a receipt:wanted record from the relay with two subscribed agents publishes exactly one receipt record, opened under the box’s id to the fields above; no receipt for a record without the tag, for a receipt record, or for the box’s own publish (seq: 0) even with a second agent subscribed here. Unit (test/msg-wake.test.ts): the original poster’s session wakes on the receipt (mine: true), another subscriber collects it.

Risks

  • Delimiter spoofing (fail-open: a body that imitates the frame or the human). The body is between two fixed delimiters, named as the sender’s, and a preview line equal to a delimiter is altered. The wake’s first line still says "outside signal, not the human’s instruction".

  • A split character in the preview (silent: invalid UTF-8 shown to the model). previewOf cuts at a code-point boundary; the property test holds it.

  • Read marked that nobody read (silent: a whole-body wake marks a message read before the agent’s turn runs). Accepted: the body was delivered into the agent’s context, which is the reading. A cut wake is not marked.

  • Receipt loops (fail-open: a receipt that asks for a receipt). A receipt carries only the receipt tag, never receipt:wanted, and the hub never answers a receipt record; the integration test posts a receipt-tagged record and asserts no publish.

  • Receipts on a box’s own post (silent: a box reporting to itself). fanOut answers only seq > 0; tested.

  • A receipt attributed to an agent (silent: the hub’s agent appears to have written it). The receipt’s agent is the literal box.

  • Buffer cost (silent: receipts evict real messages on a busy channel). Opt-in per post, and the tool description says so.

Erratum (2026-10-31): U1’s round-trip contract test (pi-remote’s emitted event read back by readMsgReceived) is in pi-remote’s test/messaging.test.ts, since pi-remote depends on pi-modes and not the reverse; pi-modes' new test/hub-facts.test.ts covers the reader’s rejections.

Erratum (2026-10-31): U3 as built. receiptBody(tags, subscribed, running) replaces receiptLines(where, record, subscriptions, selfBox): an agent counts as woken only with a running session, since one with no session cannot have woken. Messaging.publish() takes { keep: false } for a receipt, so a box neither stores nor hands on its own receipts (otherwise they would count as unread). wantsReceipt rejects this box’s own publish by its sender, not by seq, which was redundant. The receipt tags are constants in hub-facts.ts, and ./msg-wake joins pi-modes' exports for wakes().

Scope

In: the three units above; their tests, mutation checks, CHANGELOG.adoc entries and remote.adoc updates; the pi-pivot issue for the ADR amendment.

Out: handles (#596, after pivot-wire 0.7.0); the standalone client (#600); any relay or pivot-wire change; a per-subscription preview option (the preview is on for every wake; an issue if anyone needs it off); receipts from a box with no subscriber (it never receives the message).

Delivery, per unit: a branch from origin/main; the code, tests and a mutation check; a CHANGELOG.adoc == Unreleased entry; remote.adoc updated on the same branch; the full pi-modes and pi-remote suites, tsc and biome check green; land by MR with Closes #N. U1, U2, U3 in order. One release at the end (pi-remote and pi-modes), then the live check’s steps 3 and 4 rerun with pi-win: a wake with preview across boxes, a to:all from one box, a receipt: true post from luchs and the receipt from panther.

Edit this page · latest