Plan: agent handles - a short name a project declares, addressed by to:<handle>
Closes: #596 (U1 and U2, each by its MR). Relates to: #594, #595, #599 (round two, shipped in 0.140.0), pi-pivot ADR-008 as amended (da422d0). Branches: chore/pivot-wire-0-7, feat/msg-handles, in that order. Status: Done (2026-10-31) — shipped in 0.141.0 (wake line, #610, in 0.142.0); handles stamped, woken and named in receipts, live across luchs and panther
Design
What the operator decided (2026-10-31)
#596 was approved as recommended after the consumers' poll: an optional handle per project, to:<handle> always wakes it, the record carries both the handle and the path, and a duplicate on a box is refused naming the other project. pi-win asked that it be keyed by the normalised path the agent name already uses, so one folder cannot get two identities by case. canopy rated it the most important of the five: its collaborator’s path changed with a drive move. claude-design wants handles to match the ntfy titles (claude-design, pi-win, pivot). The operator then chose how a handle is declared: by the agent, with a tool, refused if taken, kept in the box’s messaging state like the subscriptions.
pivot published pivot-wire 0.7.0: Message.handle? is 1-32 characters with no whitespace, optional both ways. An older reader ignores it, an older sender’s record decodes to none, and the vectors' fixture carries handle: "pivot".
What stays as it is
-
The agent name (
agent-name.ts) is still the project’s canonical path, or the configuredagent; the handle is beside it, never instead of it.to:<agent>still wakes. -
The relay is untouched: the handle is inside the sealed record.
-
Uniqueness is per box. Two boxes may each have a
pi-win; a message shows its box as well. Cross-box uniqueness is out of scope, an issue if it ever bites.
Files
pi-remote: package.json (the pin), messaging.ts (its msgPath/readJson/writeJson helpers serve the new file), msg-tools.ts, msg-store.ts, lifecycle.ts, hub.ts, test/messaging.test.ts, test/extension.test.ts, test/member.test.ts. pi-modes: msg-wake.ts, hub-facts.ts, modes.json, test/msg-wake.test.ts, test/hub-facts.test.ts. Docs: docs/modules/ROOT/pages/remote.adoc (the tools bullets, § Agent names, ==== Wakes), CHANGELOG.adoc (== Unreleased, over the review size limit, not supplied). Root: pnpm-lock.yaml (not supplied; regenerated by pnpm install).
U1: the pin and the record (#596, part one)
The pin. @gadhs/pivot-wire goes from 0.6.0 to 0.7.0 in packages/pi-remote/package.json, exact as before, with pnpm install and the lockfile committed in the same commit (the U4 lesson: a lockfile out of step fails validate with "no stamp").
The record. parseRecord() (messaging.ts) accepts an optional handle: string, rejecting a record whose handle is present and not a string. StoredMessage (msg-store.ts) carries handle?: string; PostRecord inherits it. MsgReceived.record (hub-facts.ts) carries handle?: string, and readMsgReceived() reads it. recordText() and listText() (msg-tools.ts) show from: <agent> (<handle>) (box …) when there is one.
Tests. Contract (test/messaging.test.ts, the vectors block): the 0.7.0 fixture opens with handle: "pivot" and is stored and delivered with it; a record without handle still parses; handle: 7 does not. Contract (test/hub-facts.test.ts): handle round-trips and stays optional. Unit (test/extension.test.ts): msg_read shows the handle in from:.
U2: declaring and addressing (#596, part two)
The file. msg/handles.json in the state directory, agent name to handle, written whole through a rename like subscriptions.json. loadHandles(agentDir): Record<string, string> and setHandle(agentDir, agent, handle | undefined): { ok: true } | { ok: false; heldBy: string } in messaging.ts. A handle is HANDLE_RE = /^\S{1,32}$/ (pivot-wire’s grammar). setHandle refuses one held by another agent name on the box, naming it; setting the same handle again is no change; undefined drops it.
The tool. msg_handle { handle?, off? } in msg-tools.ts, the fifth messaging tool: with handle, declares it for this session’s agent name and answers “now pi-win” or the refusal “"pi-win" is held by d:\code\other”; with off: true, drops it; with neither, says the current one or that there is none. modes.json: allowed in auto, manual and plan (naming oneself is not a post; plan already allows msg_subscribe). msg_channels shows it: “subscribed: you (pi-win), /work/other”. The hub-socket protocol gains nothing: a handle is read from the file where it is needed.
Posting. Where a record gets its agent it gets its handle: postMessage() in lifecycle.ts for the hub’s own session, and HubServer.onPost() in hub.ts for a member’s post, both from loadHandles(agentDir)[agent]. A receipt (agent: "box") carries none.
Waking. wakes(tags, agent, sub) (msg-wake.ts) gains an optional handle: to:<handle> wakes as to:<agent> does, before the broadcast and wake-tag rules. MsgReceived gains handle?: string for this session’s agent, set by receivedEvent() from the file; outcome() passes it. receiptBody() (messaging.ts) asks wakes with each agent’s handle and names a woken or collected agent by its handle when it has one, else its agent name. mine (#599) is unchanged: it compares agent names.
Docs. remote.adoc: the msg_handle bullet; § Agent names says a project may declare a handle, where it is kept, and that it is unique per box; ==== Wakes adds to:<handle>. CHANGELOG.adoc == Unreleased, Added.
Tests. Unit (test/messaging.test.ts): setHandle keeps, refuses a duplicate naming the holder, accepts the same again as no change, drops on undefined, and rejects whitespace and 33 characters by the grammar; receiptBody names by handle. Unit (test/msg-wake.test.ts): to:<handle> wakes; without a handle the tag is an ordinary one; to:<agent> still wakes a handled agent. Integration (test/extension.test.ts): msg_handle sets, refuses, shows and drops; a post after it carries handle in the sealed record (opened under the box’s id); a member’s post through the hub socket carries it too (test/member.test.ts, where HubClient.post is driven, asserting the record the hub’s onPost hands on); msg_channels shows it. Mutation checks on setHandle, wakes and the two posting sites.
Risks
-
A handle shadows another agent’s name (fail-open:
to:pi-winmeant for a project namedpi-winbyagentconfig).setHandlerefuses a handle equal to any agent name on the box with a subscription or a handle. Tested. -
Two projects race for a handle (silent: both believe they hold it). Writes go through one file, read then written whole; the second writer reads the first’s. Sessions on one box are few and a declaration is rare; accepted, noted in the doc comment.
-
A receipt names a handle the sender does not know (silent: unreadable receipt). The receipt gives
handleonly for an agent that has one and the sender can match it by tag; agent names are the fallback. Accepted. -
An older box reads a record with a handle (fail-closed: a record dropped as malformed). pivot-wire ignores unknown fields and
parseRecordon 0.6.0 boxes keeps the fields it knows and ignores the rest, so the record opens and is stored without its handle. U1’s contract test on the 0.7.0 vectors, whose fixture carries one, is the check. pivot-wire 0.7.0 is verified on the registry (npm view) withMessage.handle?as itstypes/Message.tsand README state; the tree still pins 0.6.0 until U1.
Erratum (2026-10-31): U2 as built. The handle is stamped in Messaging.publish(), which both the hub’s own posts and a member’s (through onPost) reach, rather than at postMessage() and HubServer.onPost() separately; a receipt (agent: "box") finds none. setHandle returns { ok: false; why } with the reason in words, and also refuses the reserved all (the broadcast) and box (which signs receipts).
Scope
In: the two units, their tests and mutation checks, the changelog entries and remote.adoc.
Out: cross-box uniqueness; a handle in the phone’s session list (pivot’s, if wanted); a handle set from gadhs-pi-remote.json (the operator chose the tool); renaming agent in the record.
Delivery, per unit: a branch from origin/main; the code, tests and a mutation check; the CHANGELOG.adoc entry and remote.adoc on the same branch; both packages' suites, tsc and biome check green; land by MR with Closes #596 on U2 and Relates to #596 on U1. One release after U2, pi-remote and pi-modes. Then the consumers declare their handles (pi-win, pivot, canopy, claude-design, gesso-controller, pi-dev) and a to:pi-win from luchs wakes panther in the live check.