@sjawhar/claude-envoy 2.7.1 → 2.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,5 +2,5 @@
2
2
  "name": "claude-envoy",
3
3
  "description": "Put Envoy events into the Claude Code session's own conversation and expose Envoy MCP tools.",
4
4
  "mcpServers": "./.mcp.json",
5
- "version": "2.7.1"
5
+ "version": "2.9.0"
6
6
  }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "claude-envoy",
3
- "version": "2.7.1",
3
+ "version": "2.9.0",
4
4
  "description": "Put Envoy events into the Claude Code session's own conversation and expose Envoy MCP tools.",
5
5
  "mcpServers": {}
6
6
  }
package/AGENTS.md CHANGED
@@ -5,15 +5,16 @@ Claude Code plugin package for Legion's Envoy subsystem.
5
5
  ## Overview
6
6
 
7
7
  One MCP stdio process is the Envoy ingress.
8
- It subscribes NATS directly to the session's
9
- `notifications.agent.<session_id>` subject and every topic the session follows — the lane receipts,
10
- the live team topics and the core fallback ride those subscriptions, not the session's messages,
11
- which come from the relay below. It renders each
8
+ It subscribes NATS to two subjects.
9
+ Every Envoy message reaches it on the session's relay subject, where the listener serves the
10
+ session's own durable consumer, and it answers no receipt.
11
+ The other is the Agents page live view's control subject
12
+ (`agentstream.<session_id>.control`, `src/agent-stream-runner.ts`), which carries a viewer's
13
+ replay request and its watch pings and no Envoy traffic.
14
+ It renders each
12
15
  envelope through `@legion/envoy-client/delivery`, then writes it into the session's own
13
16
  conversation through the mod (`src/mod-session.ts`), or, in a Legion pane, through the bridge's
14
17
  inbox.
15
- A core-NATS direct delivery gets its empty receipt
16
- when the server enqueues the write; that means the server took it, not that the model read it.
17
18
  There is no Monitor and no native Claude messaging socket path. The server's tools are the
18
19
  `envoyToolSpecs` alone, the ten `envoy_*` tools and `slack_post`: agents reach Dispatch through the
19
20
  `dispatch` command, which `bin/dispatch` puts on the Bash tool's `PATH`.
@@ -25,9 +26,10 @@ come from ("Session consumers" in
25
26
  `@legion/envoy-client/consumer-delivery`. The server subscribes the current id's relay subject
26
27
  before it registers, and every registration asks for consumer delivery with the relay's epoch
27
28
  (one per NATS connection; a nats.js `reconnect` begins another and registers at once,
28
- `renewRelayEpoch`) and its resume point. Answered `consumer`, the relay carries the agent subject
29
- and every followed topic the stream stores, in stream order: each frame is answered `received`
30
- as it decodes, goes to the same write queue a live frame takes, and is answered `done` once the
29
+ `renewRelayEpoch`) and its resume point. The answer's one mode is `consumer`, and the relay
30
+ carries the agent subject and every followed topic, each of which the stream stores, in stream
31
+ order: each frame is answered `received`
32
+ as it decodes, goes to the server's write queue, and is answered `done` once the
31
33
  notifier resolved its write and the ledger recorded it (`deliverRelayed`), at once for a frame
32
34
  skipped, already shown or a late BTW, which is passed over. In a Legion pane the notifier
33
35
  resolves when `legion claude-bridge` answers its inbox, which it does once Claude Code re-emits
@@ -36,59 +38,56 @@ resolves once the mod has stored the row, and while the session is idle the card
36
38
  instead and the write resolves once the mod reports that the engine took it (`show`). A write
37
39
  that fails
38
40
  answers `nak`, and from the frame's third delivery `done` with a notice naming it; a frame that
39
- arrives after a `/clear` moved the session to another id is answered `nak`. The core copies of
40
- those subjects answer only a lane's receipt (`relaysCoreTopic`), and the replay engine makes no
41
- `/v1/replay` call. The relay's snapshot (the resume point and each topic's follow time) is the
41
+ arrives after a `/clear` moved the session to another id is answered `nak`. The relay's snapshot
42
+ (the resume point and each topic's follow time) is the
42
43
  `consumer` part of the id's state file, written whenever it changes. An id with no snapshot of
43
- its own that has replay cursors — one coming from a release before this relay, or a session whose
44
- listener gains the grant later — registers the lowest cursor the engine holds over its agent
45
- subject and its followed stored topics, so the listener creates the consumer there instead of at
46
- the stream's end and what was stored while the session was away is still relayed, and shown: such
47
- an id has no follow times either, and a frame stored before a topic's follow time is kept when
48
- the engine's cursor for it says the core path followed the topic from below that frame's sequence.
49
- Answered `core`, or not at all, the core path below runs:
50
- the rollout fallback for a plugin or listener of an earlier release and for a listener whose NATS
51
- user lacks the session-consumer grant, which dispatch://INFRA-771 removes.
44
+ its own starts its consumer at the stream's end, so it is shown nothing published before it
45
+ first registered. A registration the listener can give no consumer is refused by name, with the
46
+ reason the one canonical list holds (`ErrorWireSchema.reason`,
47
+ `packages/envoy-client/src/transport.ts`), and nothing is
48
+ registered: the server says so on stderr and asks again at each heartbeat. There is no second
49
+ path to fall back to.
52
50
 
53
- On that fallback, what those subscriptions missed while they were down, the server reads back
54
- from Envoy's notification stream through its listener (`POST /v1/replay`) with the shared engine
55
- `@legion/envoy-client/replay`, which pi-envoy uses too (its rules are "Missed messages" in
56
- `packages/pi-envoy/AGENTS.md`). A sweep runs at channel start (a resume included), on each nats.js
57
- `reconnect` status, on every heartbeat and after a new follow, and shows each stored frame the
58
- session was not shown, once, through the same path a live frame takes (the mod's write into the
59
- conversation, or the Legion bridge's inbox), with a last line saying when it was published while the
60
- connection was down (`replayedText`, worded by the engine, as are the notices, which its
61
- `envoyNoticeText` renders in TOON as every live card is); a frame there runs nothing. On this
62
- path, role messages and team or other ad-hoc topics are not recovered. The live path records
63
- each frame Claude Code was handed in the engine's ledger before its claim settles, and drops a
64
- frame the ledger holds (a repeat after a restart). The state is one file per session id,
51
+ A message published while the session was not running or its connection was down waits in that
52
+ consumer and is relayed when the session returns, inside the stream's 72 hours, through the same
53
+ path a frame taken live takes (the mod's write into the conversation, or the Legion bridge's
54
+ inbox), with a last line saying when it was published while the
55
+ connection was down (`storedText`, worded by `@legion/envoy-client/delivery-ledger`, as are the
56
+ notices, which its `envoyNoticeText` renders in TOON as every card is); such a frame runs
57
+ nothing. The server records
58
+ each frame Claude Code was handed in the delivery ledger before its claim settles, and drops a
59
+ frame the ledger holds (a repeat the relay's restart at the ack floor sent again). The state is one file per session id,
65
60
  `replay-<url-encoded session id>.json` in the
66
- plugin's state directory (`src/replay-state.ts`, mode 0600, written by rename): the cursors, the
67
- followed subjects, which the server follows again at start even after the listener reaped its
68
- interests, and at most 72 hours of ledger, at most 20,000 entries; no sweep prunes these files,
61
+ plugin's state directory (`src/replay-state.ts`, mode 0600, written by rename): the resume point,
62
+ the followed subjects, which the server follows again at start even after the listener reaped its
63
+ interests, and at most 72 hours of ledger, at most 20,000 entries; nothing prunes these files,
69
64
  since Claude Code can resume a session at any later time. A `/clear` handoff to a new id starts a
70
65
  fresh file, as a new session does, so nothing from before it comes back. A frame that fails three
71
- times, or a live frame that fails and no sweep will show (one that arrived before its subject's
72
- cursor started included, stamped when its subscription yielded it, `readArrivals`, not when the
73
- frames queued before it finished delivering), is replaced by a notice naming it on
74
- the same path; a notice that cannot be shown, and a listener that does not replay (404,
75
- `REPLAY_UNAVAILABLE`, 401 or 403), go to stderr. A crash between the hand-off and the ledger
76
- write can show a frame twice, never lose it. The host policy pi-envoy shares is the engine's too:
77
- which subjects are followed for replay (`replayFollowedSubjects`: the agent subject and every
78
- topic but a role's or one reaching a private stream subject, which registration leaves out too:
79
- `reachesPrivateStreamSubject`, the listener's rule, another session's agent subject, a
80
- failed-delivery lane, the Legion controller lane, or a wildcard reaching one), which remembered
81
- topics come back at start
82
- (`rememberedTopics`), when a replayed `subscription.removed` closes a topic and takes it out of
83
- the registry (`closeReplayedRemoval`), and which one-time notices are a card rather than a warning
84
- (`routeReplayNotice`); this server keeps only how it shows a card, where it warns, and its file.
66
+ times is replaced by a notice naming it on
67
+ the same path; a notice that cannot be shown goes to stderr. A crash between the hand-off and the ledger
68
+ write can show a frame twice, never lose it. The host policy pi-envoy shares is the ledger's too:
69
+ which subjects the session follows (`replayFollowedSubjects`: the agent subject and every
70
+ topic but a role's or one reaching a private stream subject), which remembered topics come back
71
+ at start (`rememberedTopics`), when a `subscription.removed` frame closes a topic and takes it
72
+ out of the registry, and which topics a registration carries (`registrationTopics`: the
73
+ session's own agent subject and every followed topic the listener will store for it, leaving out
74
+ one reaching a private stream subject that is not this session's — `reachesPrivateStreamSubject`,
75
+ the listener's rule: another session's agent subject, a failed-delivery lane, a controller notice
76
+ lane of a project whose controller role this session does not hold, or a wildcard reaching one —
77
+ and one nothing would ever be delivered on, `streamDeliversNothing`, which the listener stores
78
+ for no session: it leaves such a topic out of the row and warns about it, so a topic the session
79
+ follows from its row or its remembered state wedges nothing); those rules are
80
+ `@legion/envoy-client/stream-topics`'s, and this server keeps only how it shows a card, where it
81
+ warns, and its file. A caller that names such a topic itself is refused by name: `follow`, which
82
+ is the `envoy_subscribe` tool's call and nothing else, throws `uncapturedTopicRefusal`, the
83
+ listener's own warning for that topic, and follows nothing of that call.
85
84
 
86
85
  `runEnvoyChannelServer` dials NATS with the shared options of
87
86
  `@legion/envoy-client/nats-connection` (`natsConnectionOptions`): a ping every 10 s and the
88
87
  connection dropped on the tick that finds two pings unanswered, so a path that freezes without
89
88
  closing (packets stop, neither side closes) is left within 30 s and redialed at once, 52 s when
90
89
  that redial also hangs on nats.js's 20 s dial timeout and the 2 s reconnect wait; it reconnects
91
- forever, 2 s apart, and each `reconnect` status starts the sweep above. nats.js's default 120 s
90
+ forever, 2 s apart, and each `reconnect` status renews the relay's epoch. nats.js's default 120 s
92
91
  ping interval left a frozen path for up to 6 minutes. Every registration names the plugin:
93
92
  `plugin` `@sjawhar/claude-envoy` and `plugin_version` the version segment of the plugin-cache
94
93
  directory the bundle runs from (`…/plugins/cache/<marketplace>/<plugin>/<version>/`, the npm
@@ -127,8 +126,8 @@ Dispatch asks stay on Dispatch.
127
126
  | A person's message | `src/user-turn-router.ts`, `src/mod-session.ts`, `src/user-turn-state.ts`, `src/claude-rows.ts` | What a frame from Dispatch's Agents page becomes (INFRA-1026). The accept step is `acceptUserTurn` (`@legion/pi-shared/accept-user-turn`), the one step both Envoy plugins take — this router and `acceptedUserTurn` in `packages/pi-envoy/extensions/envoy.ts` — so a fix to the rule lands in both: a candidate frame (`isUserTurnCandidate`), an attempt this session has not handled, the attempt recorded **before** Dispatch is asked (a 404 included), the accept, and the stored body it answers — never the frame's own text. This host supplies the record, the Dispatch client, the session id and the wording of each refusal. The record lives in `turns/<url-encoded session id>.json` and outlives the process, so no restart spends an attempt twice; it also maps each delivered row to the Dispatch message it is, which tags that row on the live view. A row is matched to a message by the shared line rule (`comparableLines`, `@legion/contracts`), which the Agents page reads a stored body by too, so the two cannot drift and show a person's message twice. A terminal session takes the body through the mod (`$.session.append` during a turn, `$.prompt.submit({asUser:true})` while idle, one submit in flight at a time, and one plain submit at a row the turn never read); a pane's goes to the bridge's inbox, with its pictures as `blocks`. That plain submit carries each unread message's own words and its Dispatch id and never points at the row (`unreadRowPrompt`): driven live, a prompt saying "Read the message above" was answered `I don't see an actual Dispatch message content above` and `it looks like an injection and I'm not going to act on it`. A `/` message runs through `$.command.run` and its output is the reply — the result's `text`, else its `context` entries, which is where a terminal `/context` puts its table and the only place it puts it, else the `<local-command-stdout>` row Claude Code wrote for that run (`src/claude-rows.ts`, which the live view parses the same rows with), waited for two seconds since the row and the result reach this process on separate posts and cross — with a waiting reply after ten seconds, and a reply saying so when the command printed nothing, since `typedInputReply` has nothing to say for an empty output; `/model` and `/effort` are picks (`$.config.set`, `set-effort`), answered with `typedInputReply`'s text once the settings frame is refreshed; a BTW is `$.model.fork`. A row of the `command` door is a run's by when it arrives and by nothing else: a run claims the first echo row to arrive inside one second of its own answer (`runsCommandRow`), and the `<local-command-stdout>` row directly behind that claimed echo is that run's output, while an echo no run claimed — and the output row behind it — is a command the person typed at their own terminal and belongs to no run. Never by the command the row names: Claude Code runs `/cost` as `/usage` and `/model anthropic/haiku` as `/model haiku`. `origin` separates nothing, measured on live Claude Code 2.1.310 (INFRA-1026): a `/model haiku` this session ran answered at 08:14:06.839 and wrote its caveat (`{"kind":"plugin"}`, `isMeta`) at .844, its echo (`{"kind":"plugin"}`) at .858 and its stdout (`{"kind":"engine"}`) at .888, a `/config` a person typed at a terminal wrote its echo and its stdout with `{"kind":"engine"}` too, and a Dispatch `/cost` whose dialog waited for the person had written no row of its own when that `/config` arrived 36 seconds later. The live view draws nothing of a claimed echo row — the person's own line reaches the page as the message Dispatch stored beside the stream — and nothing of any row Claude Code marks `isMeta`, such as the `<system-reminder>` naming the session that a terminal `/rename` leaves behind its own two rows. |
128
127
  | Session identity | `src/session-identity.ts`, `src/session-state.ts`, `src/claude-session.ts` | `SessionIdentity` is the one mutable id holder; handoff file `sessions/<claude-pid>/session-id`; role file `roles/<url-encoded session id>.json` (`readPersistedRole`, `writePersistedRole`; the suffix is what keeps a session id of `.` or `..` inside `roles/`, since `encodeURIComponent` leaves a dot alone), whose record carries the writing process's `client_instance_id` beside the session id and the role, optional so a record written before the field loads unchanged. `CLAUDE_CODE_SESSION_ID`, or explicit `ENVOY_SESSION_ID` for QA. `src/session-state.ts` holds what the state files share and nothing that imports zod: `writeAtomicStateFile`, and `pruneStateDirectory(directory, isStale)`, the one ENOENT-tolerant sweep behind all three of them — handoffs by liveness (a `sessions/<pid>` whose Claude process is gone, anything else there left alone), titles and roles by age (`writtenLongAgo`, `STATE_FILE_MAX_AGE_MS`, thirty days). The role sweep exists because exactly one path removes a role file by hand — a soft `setRole` the listener refuses naming a session that is **not** the one the record is for, which says that session no longer holds the role. A refusal naming the record's own session keeps the file: the role is then held under that id by another process sharing this state directory, and the refused process goes on pressing its claim, refreshing the record's mtime on each heartbeat as a confirmed holder does, so the age sweep never reaches a record a process is still claiming for. The handoff sweep cannot reach either, keyed as it is by session id with no process left to ask about. All three run at startup in `startChannelSession`, each under its own `.catch` that logs and swallows: the heartbeat timer is not armed yet, so housekeeping must never cost a session its channel. |
129
128
  | Session title | `src/session-title.ts`, `src/session-state.ts` | The title every registration sends, which Dispatch's Agents page shows in place of the id: `ENVOY_SESSION_TITLE` on one line when it holds a character that shows; else the name the person running the session gave it (`claude -n`, `--name`, `/rename`), alone, with no short id after it, since a name a person chose needs nothing to tell it apart; else a name and the current id's first eight characters (a function of the id, so it follows a `/clear` handoff, and keeps two sessions in one tmux window apart). The chosen name is read, through `readChosenTitleSync`, from the `titles/<url-encoded session id>.txt` file the hooks write under `CLAUDE_PLUGIN_DATA` (keyed by id, like the role file, so `claude --resume <id>` finds it and a `/clear`'s new id starts without one; the suffix keeps a session id of `.` or `..` inside `titles/`, since `encodeURIComponent` leaves a dot alone), and every writer and reader goes through `sessionTitleFile` so the file the hook writes is the file the server reads; that read is synchronous and swallows every error, because a cosmetic title must leave the session on its fallback rather than fail the registration carrying it, and the name goes through the same `oneLine`/`visible` pair the other sources do, so a blank or invisible one falls through to the fallback while a multi-line one is put on one line and kept. The fallback's name is the pane's tmux name (`TMUX` and `TMUX_PANE`, one bounded `tmux -u -S <socket> display-message` at startup, used only when the answering server's pid is the one in `TMUX` and the pane's process is one of this process's ancestors (`isAncestor`); `session:window` when the window's `automatic-rename` is off, else the session, never a window index; for grouped sessions the group's name), else the project directory's name (outside tmux, a refused or missing answer, or a session named only by digits in a window nobody named). That name is worked out once as the server starts; the chosen name is asked for on every call instead, so a rename reaches the page on the session's next prompt plus a heartbeat, with no watcher anywhere. `pruneStaleSessionTitles` drops title files untouched for thirty days at startup, through the sweep the handoff and role prunes share and under the same best-effort guard, since nothing else deletes a file keyed by a session id. The listener replaces the stored title on every registration, and `register` also stamps it (`stampTitle`: `writeSessionTitle` in the session's Dispatch state directory) once per id, where the `dispatch` command reads it for the `session_title` on its writes; with inbound messages or Envoy off, nothing registers, so `runEnvoyChannelServer` stamps it once for the starting id (a `/clear` there leaves the new id unstamped); nothing is stamped when the session starts with Dispatch off or under `ENVOY_SESSION_ID`. |
130
- | NATS topic consumer | `src/channel-forwarder.ts` | Dedupe through the shared `createDeliveryDedupe`: a re-send by its `dedupe_key` (never by `event_id` alone, which the listener mints fresh for every send, so a Dispatch Retry would pass as new), and a second copy of one publish arriving on overlapping subscriptions by its `event_id`; surface the envelope's topic, and drain safely at shutdown. The promise the dedupe keeps is stated on `DELIVERY_DUPLICATE_WINDOW_MS` in `packages/contracts`. |
131
- | Consumer delivery | `src/envoy-channel-server.ts` (`openRelay`, `deliverRelayed`, `renewRelayEpoch`, `relaysCoreTopic`), `src/replay-state.ts` (the `consumer` part of `replay-<session id>.json`), `../envoy-client/src/consumer-delivery.ts`, `../../scripts/e2e/envoy-session-delivery.sh` | The listener's relay of the session's durable consumer ("Overview"): the relay subscription and epoch, each frame's `received`, `done` and `nak`, and the persisted resume point. The repository's `scripts/e2e/envoy-session-delivery.sh` is the live proof under `legion claude-bridge` (`scripts/e2e/README.md`). |
129
+ | NATS topic consumer | `src/channel-topics.ts` | Dedupe through the shared `createDeliveryDedupe`: a re-send by its `dedupe_key` (never by `event_id` alone, which the listener mints fresh for every send, so a Dispatch Retry would pass as new), and a second copy of one publish arriving on overlapping subscriptions by its `event_id`; surface the envelope's topic, and drain safely at shutdown. The promise the dedupe keeps is stated on `DELIVERY_DUPLICATE_WINDOW_MS` in `packages/contracts`. |
130
+ | Consumer delivery | `src/envoy-channel-server.ts` (`openRelay`, `deliverRelayed`, `renewRelayEpoch`), `src/replay-state.ts` (the `consumer` part of `replay-<session id>.json`), `../envoy-client/src/consumer-delivery.ts`, `../../scripts/e2e/envoy-session-delivery.sh` | The listener's relay of the session's durable consumer ("Overview"): the relay subscription and epoch, each frame's `received`, `done` and `nak`, and the persisted resume point. The repository's `scripts/e2e/envoy-session-delivery.sh` is the live proof under `legion claude-bridge` (`scripts/e2e/README.md`). |
132
131
  | Outbound transport | `src/envoy-client.ts`, `bin/envoy-send.ts` | Envoy listener HTTP client for `envoy-send`, which sends to the listener and with the bearer `envoySettings` resolves over the envoy.json `envoyConfigPath("command")` chooses. |
133
132
  | Send CLI parsing | `src/send-arguments.ts` | Validates destination and message arguments. |
134
133
  | Manual `/clear` smoke | `scripts/smoke-clear-rebind.sh` | Real `/clear` against the live listener with the build in `CLAUDE_PLUGIN_DIR` (default: a `--out` build of this tree in the smoke's scratch directory); checks the registry entry moves to the new id without the old direct subject. Sends no prompt to the model; excluded from CI. |
@@ -248,7 +247,7 @@ above says how to run it).
248
247
  - `renderInbound` from `@legion/envoy-client/delivery` is the sole inbound renderer. Never add an
249
248
  adapter-specific renderer or emit raw envelope bytes.
250
249
  - A frame's identity fields are `event_id`, `dedupe_key`, `source`, `source_event_id` and
251
- `topic` (`deliveryIdentity` in `src/channel-forwarder.ts`), each parsed on its own and kept
250
+ `topic` (`deliveryIdentity` in `src/channel-topics.ts`), each parsed on its own and kept
252
251
  only when valid, so one field the rule refuses still leaves its sibling able to recognise a
253
252
  repeat.
254
253
  Nothing else of an envelope leaves the renderer: what reaches the session is the rendered
@@ -272,35 +271,32 @@ above says how to run it).
272
271
  - The listener merges each registration's topics into the entry and never removes one. So every
273
272
  registry write (register, unsubscribe, deregister, the handoff) goes through the session's one
274
273
  `serialized` chain, a registration reads the id and topics when it runs, and a topic leaves the
275
- forwarder's topic list (`unfollow` removes it before its first await) before the listener is
274
+ followed topic list (`unfollow` removes it before its first await) before the listener is
276
275
  told or the next registration is sent. A human Dispatch subscription removal is repeated to the
277
276
  listener through the same chain. Nothing inside the chain may wait without a bound (the
278
277
  handoff's NATS flush has a timeout), because shutdown's deregistration queues behind it.
279
- - Publish the empty receipt only for a forwarded lane (envelope topic differs from the direct
280
- subject: the listener's role lane, which waits for it). A plain direct send is a JetStream publish
281
- whose reply inbox expects the server's acknowledgement; an empty receipt there makes the listener
282
- report `invalid jetstream publish response` for an event that was delivered. The rule is
283
- `expectsLaneReceipt` from `@legion/envoy-client/delivery`, shared with the OMP extension. The
284
- core subscription answers that receipt in both delivery modes: on consumer delivery the core copy
285
- of a relayed subject answers its receipt and is shown nothing, and the stored copy arrives on the
286
- relay.
278
+ - Publish no receipt. No session answers one any more: the listener forwards a role message to the
279
+ holder's agent subject and waits only for the stream's acknowledgement that it stored it, and
280
+ the holder's own consumer relays that stored copy, which the relay frame's `done` answers. A
281
+ reply inbox on a frame belongs to the server's JetStream acknowledgement; an empty receipt there
282
+ makes a publisher report `invalid jetstream publish response` for an event that was delivered.
287
283
  - Every capture of the session id goes through the shared `SessionIdentity` (`identity.id` at the
288
284
  moment of use), never a copied string: after a `/clear` handoff the model posts to Dispatch,
289
285
  registers, unfollows, remembers roles, and deregisters under the current id.
290
- - Pass a `ChannelInboundMessage` built field by field; a nats.js `Msg` exposes `subject`, `data`, and
291
- `reply` through prototype getters that an object spread silently drops. The forwarder decodes
292
- `data` once into `raw`; downstream code reads `raw`, never re-decodes.
286
+ - Hand the relay the nats.js `Msg` itself (`decodeRelayFrame` in
287
+ `@legion/envoy-client/consumer-delivery` reads its `data`, `headers` and `reply`): a `Msg` exposes
288
+ them through prototype getters that an object spread silently drops. The relay decodes `data`
289
+ once into the frame's text; downstream code reads that, never re-decodes.
293
290
  - Register what the session can take now, never a constant: `sessionCapabilities`
294
291
  (`src/envoy-channel-server.ts`) reads whether this is a pane and whether the mod is connected,
295
292
  and `ChannelSession.capabilitiesChanged()` registers again when that changes. Dispatch refuses
296
293
  a targeted delivery in a mode the session does
297
294
  not advertise, and a message with no command goes in the mode the addressed sessions take
298
295
  (`plainDelivery`), as a broadcast does (`broadcastDelivery`).
299
- The direct NATS receipt occurs immediately after the write is enqueued; it cannot imply model
300
- processing, because nothing in the mod protocol says the model read a row.
301
- A relayed frame's `done` waits for the write instead: the mod's write into the conversation in
302
- a terminal session, and the bridge's inbox answer in a Legion pane, which comes once Claude
303
- Code re-emits the delivery (`--replay-user-messages`).
296
+ A relayed frame's `done` waits for the write: the mod's write into the conversation in a
297
+ terminal session, and the bridge's inbox answer in a Legion pane, which comes once Claude Code
298
+ re-emits the delivery (`--replay-user-messages`). Neither says the model read the message —
299
+ nothing in the mod protocol does — only that the session holds it.
304
300
  - Write every message into a terminal session through the one call `hooks/mod.ts` serves,
305
301
  whether a person sent it or Envoy delivered it: `session.message` hands the mod the message,
306
302
  and the mod decides what it becomes (`hooks/mod-writer.ts`, which holds these rules while
package/README.md CHANGED
@@ -68,14 +68,13 @@ message from Dispatch's Agents page as that person's own turn.
68
68
  answered. On every `UserPromptSubmit`, `dist/session-title-hook.js` records the name a person
69
69
  gave the session (below, "Session title"); its `timeout` is 5 s, and it is a bundle of its own
70
70
  because Claude Code holds the prompt until it returns.
71
- - The channel server subscribes directly to `notifications.agent.<session_id>` and to every topic
72
- followed by `envoy_subscribe`; those subscriptions carry the lane receipts, the live team topics
73
- and the core fallback, never the session's own messages. It renders every envelope with the
71
+ - The channel server subscribes one NATS subject, the session's relay subject; it receives from no
72
+ other subscription. It renders every envelope with the
74
73
  shared `@legion/envoy-client/delivery` renderer and never exposes raw envelope bytes.
75
74
  - The session's messages come from a durable consumer the listener keeps for it on
76
75
  Envoy's notification stream and relays on `notifications.envoy.deliver.<session_id>`, which
77
76
  the server subscribes before it registers: the session's own subject, the stored copies of role
78
- messages to a role it holds, and every followed topic the stream stores, in stream order. The
77
+ messages to a role it holds, and every followed topic, in stream order. The
79
78
  server answers each frame `received` as it decodes and `done` once the session has it: in a
80
79
  Legion pane once the bridge reports that Claude Code took the delivery, and in a terminal
81
80
  session once the mod reports the write: a row stored in the turn running
@@ -84,37 +83,31 @@ message from Dispatch's Agents page as that person's own turn.
84
83
  writes each Envoy event once, by its event id (`writeOnce` in `hooks/mod-writer.ts`), so the
85
84
  repeat is answered from the first write's record.
86
85
  A frame not taken yet when Claude Code stops, or published while the session was not running
87
- or disconnected, comes again and is delivered once, for up to 72 hours.
88
- Team and other ad-hoc topics, which the
89
- stream does not store, stay live only. The resume point is kept in `replay-<session id>.json`
90
- with the replay state below. `packages/envoy/AGENTS.md`, "Session consumers", states the rule.
91
- - The core path is the rollout fallback dispatch://INFRA-771 removes (a listener that answers
92
- `core`, or one of an earlier release). There a message
93
- published while those subscriptions were down (NATS restarting, the connection dropped, the
94
- session not running) is recovered from Envoy's notification stream, which keeps
95
- messages for 72 hours: the server asks its listener (`POST /v1/replay`) for what the stream
96
- stored on the session's own subject and on each topic it follows, at start (a resume included),
97
- after a reconnect, on every heartbeat and after a new follow, and delivers each missed message
98
- once, the same way as a live one, with a line saying when it was published while the connection
99
- was down. It runs nothing: a Dispatch delivery recovered this way is that event and no more.
86
+ or disconnected, comes again and is delivered once, for up to 72 hours. A
87
+ `notifications.team.<name>` topic is stored and delivered like any other followed topic. The
88
+ resume point is kept in `replay-<session id>.json` with the ledger below.
89
+ `packages/envoy/AGENTS.md`, "Session consumers", states the rule.
90
+ - Nothing is fetched back: a message published while the session was not running, restarting or
91
+ disconnected (NATS restarting, the connection dropped) waits in that consumer and is delivered
92
+ when the session returns, the same way as any other, with a line saying when it was published
93
+ while the connection was down. It runs nothing: a Dispatch delivery delivered this way is that
94
+ event and no more.
100
95
  The server pings NATS every 10 seconds and drops a connection that leaves two pings unanswered,
101
- so a connection that stops answering without closing is left within 30 seconds and redialed.
102
- On this path, role messages and team or other ad-hoc topics are not recovered, and neither
103
- is anything older than 72 hours, from before the session followed the topic, or from before it
104
- first ran this version of the plugin; a `/clear` starts afresh, as a new session does. What the
105
- session was shown and where it read to are kept in `replay-<session id>.json` in the plugin's
106
- data directory, so a resume skips nothing the stream still holds and delivers nothing again (up
107
- to 20,000 messages shown in 72 hours); a crash between handing a message over and recording it
96
+ so a connection that stops answering without closing is left within 30 seconds and redialed,
97
+ and the listener restarts the relay at the consumer's ack floor.
98
+ What the consumer does not hold: anything older than 72 hours, anything from before the session
99
+ followed the topic, and anything from before it first registered; a `/clear` starts afresh, as a
100
+ new session does. What the session was delivered, and where it read to, are kept in
101
+ `replay-<session id>.json` in the plugin's
102
+ data directory, so a resume delivers nothing again (up
103
+ to 20,000 messages in 72 hours); a crash between handing a message over and recording it
108
104
  can deliver it twice, never lose it. A message that fails three times is replaced by one notice
109
- naming it. Against a listener without the route, the server says once on stderr that missed
110
- messages are not recovered, and live delivery goes on as before.
111
- - A forwarded role-lane envelope (one that still names its `notifications.role.<role>` topic while
112
- arriving on the direct subject) receives its empty receipt immediately after the server accepts
113
- the event into its ordered notification queue.
114
- That confirms the server took the event, not that the model read it: nothing in the mod
115
- protocol says the model read a row.
116
- A plain direct send (`/v1/messages/send`) is a JetStream publish and gets no receipt: its reply
117
- subject is the publisher's acknowledgement inbox, and an empty receipt there fails the publish.
105
+ naming it. A registration the listener can give no consumer is refused by name, and the server
106
+ says once on stderr that Envoy inbound is unavailable and asks again at every heartbeat.
107
+ - No receipt is published. A role message reaches this session as a forward the listener stored on
108
+ the session's own subject, which its consumer relays and whose `done` answers for it; the
109
+ listener waits only for the stream's acknowledgement that it stored the forward. A frame's reply
110
+ subject is a publisher's acknowledgement inbox, and an empty receipt there fails the publish.
118
111
  - The server registers the session as self-subscribed with what it can take now
119
112
  (`sessionCapabilities` in `src/envoy-channel-server.ts`), read again at every registration. A
120
113
  terminal session reaches the model only through its mod (`hooks/mod.ts`, `src/mod-session.ts`),