@sjawhar/claude-envoy 2.25.1 → 2.26.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.25.1"
5
+ "version": "2.26.0"
6
6
  }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "claude-envoy",
3
- "version": "2.25.1",
3
+ "version": "2.26.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
@@ -269,6 +269,12 @@ above says how to run it).
269
269
  temporary file, not the rename onto `session-id`. The heartbeat is the fallback. On shutdown
270
270
  (stdin end, SIGTERM, SIGINT, SIGHUP) drain NATS, deregister the session, close the transport, and
271
271
  let the stdio process exit.
272
+ The relay subscription also answers the listener's connection probe, through the shared
273
+ `receive` in `@legion/envoy-client/consumer-delivery` (the probe's format is in
274
+ `packages/envoy/AGENTS.md`, "Session consumers"), and the server holds no subscription for it
275
+ beyond the relay subject: while that subject is open a send reads `connected`, and once the
276
+ connection closes, or a `/clear` handoff moves the relay to the new id and drops the old
277
+ subject, nothing answers and a send to the id left behind reads `stopped`.
272
278
  - The listener merges each registration's topics into the entry and never removes one. So every
273
279
  registry write (register, unsubscribe, deregister, the handoff) goes through the session's one
274
280
  `serialized` chain, a registration reads the id and topics when it runs, and a topic leaves the
package/dist/dispatch.js CHANGED
@@ -14880,6 +14880,12 @@ var DEFAULT_ISSUE_PAGE_LIMIT = 50;
14880
14880
  var DEFAULT_ISSUE_READ_EVENTS = 10;
14881
14881
  var ASK_TURNS = ["human", "agent"];
14882
14882
  var DELIVERY_CAPABILITIES = ["aside", "btw", "steer"];
14883
+ var DELIVERY_ATTEMPT_STATES = ["pending", "sent", "queued", "failed"];
14884
+ var SETTLED_DELIVERY_STATES = [
14885
+ "sent",
14886
+ "queued",
14887
+ "failed"
14888
+ ];
14883
14889
  var IDEMPOTENCY_KEY_HEADER = "Idempotency-Key";
14884
14890
  var IDEMPOTENCY_REPLAYED_HEADER = "Idempotency-Replayed";
14885
14891
  var IDEMPOTENCY_KEY_MAX = 128;
@@ -14896,6 +14902,7 @@ function answerNotKept(status, replayed, body) {
14896
14902
  var IDEMPOTENCY_KEY_TTL_MS = 24 * 60 * 60 * 1000;
14897
14903
  var IDEMPOTENCY_LEASE_MS = 60 * 1000;
14898
14904
  var DELIVERY_DUPLICATE_WINDOW_MS = 72 * 60 * 60 * 1000;
14905
+ var DELIVERY_DUPLICATE_WINDOW_HOURS = DELIVERY_DUPLICATE_WINDOW_MS / 3600000;
14899
14906
  var SEARCH_DEGRADED_EMBEDDER_UNAVAILABLE = "embedder_unavailable";
14900
14907
 
14901
14908
  // ../contracts/src/dispatch-api-refs.ts
@@ -16200,7 +16207,7 @@ var commentDeliveryFields = {
16200
16207
  session_id: string2().nullable(),
16201
16208
  envelope_id: string2().nullable(),
16202
16209
  duplicate: boolean2().optional(),
16203
- state: _enum2(["pending", "sent", "failed"]),
16210
+ state: _enum2(DELIVERY_ATTEMPT_STATES),
16204
16211
  error: string2().nullable(),
16205
16212
  resolve_error: string2().nullable(),
16206
16213
  reply_id: string2().nullable(),
@@ -16288,7 +16295,7 @@ var CommentDeliveryEventPayloadSchema = strictObject({
16288
16295
  attempt: number2().int().positive(),
16289
16296
  delivery: _enum2(DELIVERY_CAPABILITIES),
16290
16297
  session_id: string2().nullable(),
16291
- state: _enum2(["sent", "failed"]),
16298
+ state: _enum2(SETTLED_DELIVERY_STATES),
16292
16299
  duplicate: boolean2().optional(),
16293
16300
  error: string2().optional(),
16294
16301
  reply_id: string2().nullable()
@@ -16323,7 +16330,7 @@ var messageDeliveryFields = {
16323
16330
  session_id: string2(),
16324
16331
  envelope_id: string2().nullable(),
16325
16332
  duplicate: boolean2().optional(),
16326
- state: _enum2(["pending", "sent", "failed"]),
16333
+ state: _enum2(DELIVERY_ATTEMPT_STATES),
16327
16334
  error: string2().nullable(),
16328
16335
  reply_id: string2().nullable(),
16329
16336
  created_at: string2(),
@@ -16374,7 +16381,7 @@ var messageDeliveryEventPayloadFields = {
16374
16381
  session_id: string2(),
16375
16382
  target: string2().optional(),
16376
16383
  title: string2(),
16377
- state: _enum2(["sent", "failed"]),
16384
+ state: _enum2(SETTLED_DELIVERY_STATES),
16378
16385
  duplicate: boolean2().optional(),
16379
16386
  error: string2().optional()
16380
16387
  };
@@ -21699,6 +21706,7 @@ var issueFreeTools = {
21699
21706
  dispatch_whoami: true,
21700
21707
  dispatch_limits: true,
21701
21708
  dispatch_inbox: true,
21709
+ dispatch_send_to_agent: true,
21702
21710
  dispatch_architecture_sync: true
21703
21711
  };
21704
21712
  function canonicalExternalIssueRef(value) {
@@ -23592,6 +23600,19 @@ async function messageCommand(context) {
23592
23600
  }
23593
23601
  };
23594
23602
  }
23603
+ function arrivalText(attempt) {
23604
+ if (attempt === undefined)
23605
+ return "Dispatch recorded no delivery attempt for it";
23606
+ if (attempt.state === "failed") {
23607
+ return `its delivery failed: ${attempt.error ?? "the listener gave no reason"}`;
23608
+ }
23609
+ if (attempt.state === "pending")
23610
+ return "its delivery is still on its way";
23611
+ if (attempt.state === "queued") {
23612
+ return `that session is stopped, so its delivery is queued: it gets the message if it runs again within ${DELIVERY_DUPLICATE_WINDOW_HOURS} hours`;
23613
+ }
23614
+ return `it reached that session as ${attempt.delivery}`;
23615
+ }
23595
23616
  async function sendToAgentCommand(context) {
23596
23617
  const { args, client } = context;
23597
23618
  const session = stringArg(args, "session");
@@ -23603,7 +23624,7 @@ async function sendToAgentCommand(context) {
23603
23624
  });
23604
23625
  const attempt = message.deliveries?.at(-1);
23605
23626
  const readBack = conversationReadBack(message.id);
23606
- const arrival = attempt === undefined ? "Dispatch recorded no delivery attempt for it" : attempt.state === "failed" ? `its delivery failed: ${attempt.error ?? "the listener gave no reason"}` : attempt.state === "pending" ? "its delivery is still on its way" : `it reached that session as ${attempt.delivery}`;
23627
+ const arrival = arrivalText(attempt);
23607
23628
  return {
23608
23629
  text: `Sent message ${message.id} to session ${session}; ${arrival}. ${readBack}`,
23609
23630
  details: {
@@ -29519,8 +29540,11 @@ var EnvelopeResponseSchema = EnvelopeSchema.extend({
29519
29540
  holder: string2().optional(),
29520
29541
  holder_state: SessionStateSchema.optional(),
29521
29542
  recipient_state: SessionStateSchema.optional(),
29543
+ state: string2().optional(),
29522
29544
  last_seen: number2().int().optional(),
29523
- duplicate: boolean2().optional()
29545
+ duplicate: boolean2().optional(),
29546
+ recipients: number2().int().nonnegative().optional(),
29547
+ recipients_connected: number2().int().nonnegative().optional()
29524
29548
  });
29525
29549
  var PublishResponseSchema = EnvelopeResponseSchema.extend({
29526
29550
  kept: boolean2().optional(),
@@ -29648,7 +29672,7 @@ class EnvoySendUnconfirmedError extends Error {
29648
29672
  const got = last instanceof EnvoyApiError ? `the listener answered ${last.details.status} (${last.message})` : `the listener did not answer (${last instanceof Error ? last.message : String(last)})`;
29649
29673
  const tried = attempts === 1 ? "on its only attempt" : `on the last of ${attempts} attempts`;
29650
29674
  const resendSafe = mintedDedupeKey2.test(`agent.${targetSessionID.trim()}.${idempotencyKey}`);
29651
- const resend = resendSafe ? `Sending it again with idempotency_key ${idempotencyKey} within ` + `${DELIVERY_DUPLICATE_WINDOW_MS / 3600000} hours is the safe resend: Envoy drops it as ` + "a repeat if the first copy arrived (a recipient that restarted in between can rarely " + "see it twice)." : `Envoy cannot recognise a resend under idempotency_key ${idempotencyKey} as a repeat ` + "(the key is not a lower-case UUID, or the session id holds a dot): ask the recipient " + "whether it arrived before sending it again.";
29675
+ const resend = resendSafe ? `Sending it again with idempotency_key ${idempotencyKey} within ` + `${DELIVERY_DUPLICATE_WINDOW_HOURS} hours is the safe resend: Envoy drops it as ` + "a repeat if the first copy arrived (a recipient that restarted in between can rarely " + "see it twice)." : `Envoy cannot recognise a resend under idempotency_key ${idempotencyKey} as a repeat ` + "(the key is not a lower-case UUID, or the session id holds a dot): ask the recipient " + "whether it arrived before sending it again.";
29652
29676
  super(`The send to ${targetSessionID} is not confirmed delivered: ${got} ${tried}. It may or may ` + `not have arrived. ${resend}`, { cause: last });
29653
29677
  this.targetSessionID = targetSessionID;
29654
29678
  this.idempotencyKey = idempotencyKey;
@@ -29798,6 +29822,7 @@ function createEnvoyClient(config) {
29798
29822
  recipient: response.recipient ?? input.targetSessionID,
29799
29823
  confirmed: response.recipient !== undefined,
29800
29824
  recipientState: response.recipient_state ?? "live",
29825
+ state: response.state === "stopped" ? "stopped" : "connected",
29801
29826
  ...response.last_seen === undefined || response.last_seen <= 0 ? {} : { lastSeen: response.last_seen },
29802
29827
  duplicate: response.duplicate === true
29803
29828
  };
@@ -29818,6 +29843,8 @@ function createEnvoyClient(config) {
29818
29843
  envelope: response,
29819
29844
  ...response.holder === undefined ? {} : { holder: response.holder },
29820
29845
  ...response.holder_state === undefined ? {} : { holderState: response.holder_state },
29846
+ ...response.recipients === undefined ? {} : { recipients: response.recipients },
29847
+ ...response.recipients_connected === undefined ? {} : { recipientsConnected: response.recipients_connected },
29821
29848
  ...response.kept === undefined ? {} : { kept: response.kept },
29822
29849
  ...response.kept_reason === undefined ? {} : { keptReason: response.kept_reason }
29823
29850
  };
@@ -36484,6 +36484,12 @@ var DEFAULT_ISSUE_PAGE_LIMIT = 50;
36484
36484
  var DEFAULT_ISSUE_READ_EVENTS = 10;
36485
36485
  var ASK_TURNS = ["human", "agent"];
36486
36486
  var DELIVERY_CAPABILITIES = ["aside", "btw", "steer"];
36487
+ var DELIVERY_ATTEMPT_STATES = ["pending", "sent", "queued", "failed"];
36488
+ var SETTLED_DELIVERY_STATES = [
36489
+ "sent",
36490
+ "queued",
36491
+ "failed"
36492
+ ];
36487
36493
  var IDEMPOTENCY_KEY_HEADER = "Idempotency-Key";
36488
36494
  var IDEMPOTENCY_REPLAYED_HEADER = "Idempotency-Replayed";
36489
36495
  var IDEMPOTENCY_KEY_MAX = 128;
@@ -36500,6 +36506,7 @@ function answerNotKept(status, replayed, body) {
36500
36506
  var IDEMPOTENCY_KEY_TTL_MS = 24 * 60 * 60 * 1000;
36501
36507
  var IDEMPOTENCY_LEASE_MS = 60 * 1000;
36502
36508
  var DELIVERY_DUPLICATE_WINDOW_MS = 72 * 60 * 60 * 1000;
36509
+ var DELIVERY_DUPLICATE_WINDOW_HOURS = DELIVERY_DUPLICATE_WINDOW_MS / 3600000;
36503
36510
  var SEARCH_DEGRADED_EMBEDDER_UNAVAILABLE = "embedder_unavailable";
36504
36511
 
36505
36512
  // ../contracts/src/dispatch-api-refs.ts
@@ -37804,7 +37811,7 @@ var commentDeliveryFields = {
37804
37811
  session_id: string2().nullable(),
37805
37812
  envelope_id: string2().nullable(),
37806
37813
  duplicate: boolean2().optional(),
37807
- state: _enum2(["pending", "sent", "failed"]),
37814
+ state: _enum2(DELIVERY_ATTEMPT_STATES),
37808
37815
  error: string2().nullable(),
37809
37816
  resolve_error: string2().nullable(),
37810
37817
  reply_id: string2().nullable(),
@@ -37892,7 +37899,7 @@ var CommentDeliveryEventPayloadSchema = strictObject({
37892
37899
  attempt: number2().int().positive(),
37893
37900
  delivery: _enum2(DELIVERY_CAPABILITIES),
37894
37901
  session_id: string2().nullable(),
37895
- state: _enum2(["sent", "failed"]),
37902
+ state: _enum2(SETTLED_DELIVERY_STATES),
37896
37903
  duplicate: boolean2().optional(),
37897
37904
  error: string2().optional(),
37898
37905
  reply_id: string2().nullable()
@@ -37927,7 +37934,7 @@ var messageDeliveryFields = {
37927
37934
  session_id: string2(),
37928
37935
  envelope_id: string2().nullable(),
37929
37936
  duplicate: boolean2().optional(),
37930
- state: _enum2(["pending", "sent", "failed"]),
37937
+ state: _enum2(DELIVERY_ATTEMPT_STATES),
37931
37938
  error: string2().nullable(),
37932
37939
  reply_id: string2().nullable(),
37933
37940
  created_at: string2(),
@@ -37978,7 +37985,7 @@ var messageDeliveryEventPayloadFields = {
37978
37985
  session_id: string2(),
37979
37986
  target: string2().optional(),
37980
37987
  title: string2(),
37981
- state: _enum2(["sent", "failed"]),
37988
+ state: _enum2(SETTLED_DELIVERY_STATES),
37982
37989
  duplicate: boolean2().optional(),
37983
37990
  error: string2().optional()
37984
37991
  };
@@ -45383,8 +45390,11 @@ var EnvelopeResponseSchema = EnvelopeSchema.extend({
45383
45390
  holder: string2().optional(),
45384
45391
  holder_state: SessionStateSchema.optional(),
45385
45392
  recipient_state: SessionStateSchema.optional(),
45393
+ state: string2().optional(),
45386
45394
  last_seen: number2().int().optional(),
45387
- duplicate: boolean2().optional()
45395
+ duplicate: boolean2().optional(),
45396
+ recipients: number2().int().nonnegative().optional(),
45397
+ recipients_connected: number2().int().nonnegative().optional()
45388
45398
  });
45389
45399
  var PublishResponseSchema = EnvelopeResponseSchema.extend({
45390
45400
  kept: boolean2().optional(),
@@ -45512,7 +45522,7 @@ class EnvoySendUnconfirmedError extends Error {
45512
45522
  const got = last instanceof EnvoyApiError ? `the listener answered ${last.details.status} (${last.message})` : `the listener did not answer (${last instanceof Error ? last.message : String(last)})`;
45513
45523
  const tried = attempts === 1 ? "on its only attempt" : `on the last of ${attempts} attempts`;
45514
45524
  const resendSafe = mintedDedupeKey2.test(`agent.${targetSessionID.trim()}.${idempotencyKey}`);
45515
- const resend = resendSafe ? `Sending it again with idempotency_key ${idempotencyKey} within ` + `${DELIVERY_DUPLICATE_WINDOW_MS / 3600000} hours is the safe resend: Envoy drops it as ` + "a repeat if the first copy arrived (a recipient that restarted in between can rarely " + "see it twice)." : `Envoy cannot recognise a resend under idempotency_key ${idempotencyKey} as a repeat ` + "(the key is not a lower-case UUID, or the session id holds a dot): ask the recipient " + "whether it arrived before sending it again.";
45525
+ const resend = resendSafe ? `Sending it again with idempotency_key ${idempotencyKey} within ` + `${DELIVERY_DUPLICATE_WINDOW_HOURS} hours is the safe resend: Envoy drops it as ` + "a repeat if the first copy arrived (a recipient that restarted in between can rarely " + "see it twice)." : `Envoy cannot recognise a resend under idempotency_key ${idempotencyKey} as a repeat ` + "(the key is not a lower-case UUID, or the session id holds a dot): ask the recipient " + "whether it arrived before sending it again.";
45516
45526
  super(`The send to ${targetSessionID} is not confirmed delivered: ${got} ${tried}. It may or may ` + `not have arrived. ${resend}`, { cause: last });
45517
45527
  this.targetSessionID = targetSessionID;
45518
45528
  this.idempotencyKey = idempotencyKey;
@@ -45662,6 +45672,7 @@ function createEnvoyClient(config) {
45662
45672
  recipient: response.recipient ?? input.targetSessionID,
45663
45673
  confirmed: response.recipient !== undefined,
45664
45674
  recipientState: response.recipient_state ?? "live",
45675
+ state: response.state === "stopped" ? "stopped" : "connected",
45665
45676
  ...response.last_seen === undefined || response.last_seen <= 0 ? {} : { lastSeen: response.last_seen },
45666
45677
  duplicate: response.duplicate === true
45667
45678
  };
@@ -45682,6 +45693,8 @@ function createEnvoyClient(config) {
45682
45693
  envelope: response,
45683
45694
  ...response.holder === undefined ? {} : { holder: response.holder },
45684
45695
  ...response.holder_state === undefined ? {} : { holderState: response.holder_state },
45696
+ ...response.recipients === undefined ? {} : { recipients: response.recipients },
45697
+ ...response.recipients_connected === undefined ? {} : { recipientsConnected: response.recipients_connected },
45685
45698
  ...response.kept === undefined ? {} : { kept: response.kept },
45686
45699
  ...response.kept_reason === undefined ? {} : { keptReason: response.kept_reason }
45687
45700
  };
@@ -45762,7 +45775,8 @@ var RelayHeader = {
45762
45775
  streamID: "Envoy-Stream-Id",
45763
45776
  delivered: "Envoy-Delivered",
45764
45777
  storedAt: "Envoy-Stored-At",
45765
- gap: "Envoy-Gap"
45778
+ gap: "Envoy-Gap",
45779
+ probe: "Envoy-Probe"
45766
45780
  };
45767
45781
  var RELAY_PROGRESS_INTERVAL_MS = 20000;
45768
45782
  var FOLLOW_CLOCK_ALLOWANCE_MS = 2000;
@@ -46032,6 +46046,11 @@ function createConsumerDelivery(options) {
46032
46046
  }
46033
46047
  }
46034
46048
  const receive = (message) => {
46049
+ if (message.headers?.get(RelayHeader.probe) === "1") {
46050
+ if (message.reply !== undefined && message.reply !== "")
46051
+ send(message.reply, "done");
46052
+ return;
46053
+ }
46035
46054
  const decoded = decodeRelayFrame(message);
46036
46055
  if ("error" in decoded) {
46037
46056
  log(`dropping an undecodable relay frame: ${decoded.error}`);
@@ -48065,6 +48084,7 @@ var issueFreeTools = {
48065
48084
  dispatch_whoami: true,
48066
48085
  dispatch_limits: true,
48067
48086
  dispatch_inbox: true,
48087
+ dispatch_send_to_agent: true,
48068
48088
  dispatch_architecture_sync: true
48069
48089
  };
48070
48090
  function canonicalExternalIssueRef(value) {
@@ -49893,6 +49913,19 @@ async function messageCommand(context) {
49893
49913
  }
49894
49914
  };
49895
49915
  }
49916
+ function arrivalText(attempt) {
49917
+ if (attempt === undefined)
49918
+ return "Dispatch recorded no delivery attempt for it";
49919
+ if (attempt.state === "failed") {
49920
+ return `its delivery failed: ${attempt.error ?? "the listener gave no reason"}`;
49921
+ }
49922
+ if (attempt.state === "pending")
49923
+ return "its delivery is still on its way";
49924
+ if (attempt.state === "queued") {
49925
+ return `that session is stopped, so its delivery is queued: it gets the message if it runs again within ${DELIVERY_DUPLICATE_WINDOW_HOURS} hours`;
49926
+ }
49927
+ return `it reached that session as ${attempt.delivery}`;
49928
+ }
49896
49929
  async function sendToAgentCommand(context) {
49897
49930
  const { args, client } = context;
49898
49931
  const session = stringArg(args, "session");
@@ -49904,7 +49937,7 @@ async function sendToAgentCommand(context) {
49904
49937
  });
49905
49938
  const attempt = message.deliveries?.at(-1);
49906
49939
  const readBack = conversationReadBack(message.id);
49907
- const arrival = attempt === undefined ? "Dispatch recorded no delivery attempt for it" : attempt.state === "failed" ? `its delivery failed: ${attempt.error ?? "the listener gave no reason"}` : attempt.state === "pending" ? "its delivery is still on its way" : `it reached that session as ${attempt.delivery}`;
49940
+ const arrival = arrivalText(attempt);
49908
49941
  return {
49909
49942
  text: `Sent message ${message.id} to session ${session}; ${arrival}. ${readBack}`,
49910
49943
  details: {
@@ -52908,8 +52941,9 @@ function allowedAPIURL(value) {
52908
52941
  }
52909
52942
 
52910
52943
  // ../envoy-client/src/tool-contract.ts
52911
- var SESSION_STATE_GUIDE = "A session is live, unresponsive or gone, by how long ago it last registered: live within 5 " + "minutes, unresponsive after that and within an hour, gone past the hour or with no record at " + `all. ${UNRESPONSIVE_RULE} A session named with no state is live.`;
52944
+ var SESSION_STATE_GUIDE = "A session is live, unresponsive or gone, by how long ago it last registered: live within 5 " + "minutes, unresponsive after that and within an hour, gone past the hour or with no record at " + `all. ${UNRESPONSIVE_RULE} A session named with no state is live. A send answered with state ` + "stopped means that session is not running: the message is stored for it and reaches it if " + `it runs again within ${DELIVERY_DUPLICATE_WINDOW_HOURS} hours, and nothing of its claims changes.`;
52912
52945
  var DELIVERY_CONTRACT = "Delivery is at-least-once, possibly out of order across topics; use id for dedupe and at for freshness.";
52946
+ var PUBLISH_COUNTS = "The answer counts who gets it: recipients is every session other than you that the message " + `goes to, one that is stopped and gets it when it runs again within ${DELIVERY_DUPLICATE_WINDOW_HOURS} hours included, and ` + "recipients_connected is how many of those are running now. A listener that counts neither " + "sends neither, and a role topic names its holder instead.";
52913
52947
  var STORED_DELIVERY = "Every notification topic is stored (agent, dispatch, github, slack, legion, ghostwispr, " + "whatsapp, team; a role message reaches its holder as a stored copy on the holder's agent " + "topic), and reaches each subscribed session once from the durable consumer its listener " + "relays to it, also one that was away or restarted. A 200 means the stream stored the message " + "for each subscribed session's consumer, not that any recipient has read it.";
52914
52948
  var TOPIC_GUIDE = "Topic guide (all are under notifications.): agent.<session_id> (subscribe: own inbox); role.<role> " + "(publish-to; holders claim via envoy_role_set). > matches one or more trailing tokens and does not " + "match the base subject. Envoy registers the concrete base when you subscribe to <subject>.>, so " + "the recommended default remains github.<owner>.<repo>.pr.<n>.>. <owner> and <repo> are one token " + "each, with every dot in the name written _ (sjawhar/.github is github.sjawhar._github; " + "acme/site.io is github.acme.site_io), and a topic spelled with the dot receives nothing. " + "Default PR subscription: " + "github.<owner>.<repo>.pr.<n>.> (it receives the quiet PR family): pr.<n> (lifecycle: " + "opened/synchronize/closed; closed carries merged, merge_commit_sha, merged_by, head_sha), " + "pr.<n>.comment, pr.<n>.review, pr.<n>.mention, pr.<n>.checks (one settlement event per commit whose checks settle, the head or not, naming its sha: " + 'passed/failed/cancelled/skipped with failing names and URLs; re-fires with superseded_settlement: "true" ' + "when new runs appear for the same commit). Other GitHub: issue.<n>, issue.<n>.comment, " + "issue.<n>.mention, mention, push.branch.<name>, push.tag.<name>, workflow.<file>.<action> (only " + "runs without an associated PR); slack.<team>.<channel>.message|mention and " + "slack.<team>.<channel>.thread.<ts>.message|mention; ghostwispr.<session>.<kind>; " + "whatsapp.<phone>.<jid>.<kind>; envoy.exceptions.<original-topic>.";
52915
52949
  var URGENCY_VALUES = EnvelopeSchema.shape.urgency.unwrap().options;
@@ -52977,7 +53011,7 @@ var envoyToolSpecs = [
52977
53011
  },
52978
53012
  {
52979
53013
  name: "envoy_send",
52980
- description: `Send an Envoy agent-to-agent message directly to another session by session ID. The confirmation names the recipient's state. A message to an unresponsive session is stored and reaches it when it answers again, so an unresponsive recipient is not a failed send and no reason to send to someone else instead. ${SESSION_STATE_GUIDE} ${DELIVERY_CONTRACT} A send that is not confirmed delivered errs naming its idempotency_key; send the same message again with that idempotency_key within 72 hours, and Envoy drops it as a repeat if the first copy arrived.`,
53014
+ description: `Send an Envoy agent-to-agent message directly to another session by session ID. The confirmation names the recipient's state. A message to an unresponsive session is stored and reaches it when it answers again, so an unresponsive recipient is not a failed send and no reason to send to someone else instead. ${SESSION_STATE_GUIDE} ${DELIVERY_CONTRACT} A send that is not confirmed delivered errs naming its idempotency_key; send the same message again with that idempotency_key within ${DELIVERY_DUPLICATE_WINDOW_HOURS} hours, and Envoy drops it as a repeat if the first copy arrived.`,
52981
53015
  arguments: (schema) => ({
52982
53016
  session_id: schema.string().describe("Target session ID; find it with envoy_sessions or envoy_whoami."),
52983
53017
  ...messageArguments(schema),
@@ -52987,7 +53021,7 @@ var envoyToolSpecs = [
52987
53021
  },
52988
53022
  {
52989
53023
  name: "envoy_publish",
52990
- description: `Publish an Envoy message to a notifications. topic. ${STORED_DELIVERY} A role or built-in topic is delivered as its guide says. A role message has three possible answers. First, a session holds the role, and the stream stores the forward for that holder's consumer. Its 200 says the stream stored it, and it does not say that the holder read it; it names the holder and the state the listener resolved the holder in. Second, no session holds the role. The listener then keeps the message, and gives it to the next session that claims that role in the hour that follows. This is a success, and the result says that the listener kept the message. Third, the listener keeps nothing and errs, which tells you to reach the agent some other way: the holder refuses the message, or the forward is not stored within four seconds. A holder that stopped answering keeps its role but was not sent the message, and nothing waits for it, so publish the message again once that holder's holder_state reads live, and start no replacement for that session. A team topic (such as notifications.team.deploy-squad.all) is stored like every other, so a session subscribed to it that was away still receives it when it returns, and one that subscribes after you publish does not. A notifications. topic no stream subject captures is refused by name: nothing would store it. ${SESSION_STATE_GUIDE} ${DELIVERY_CONTRACT}`,
53024
+ description: `Publish an Envoy message to a notifications. topic. ${STORED_DELIVERY} A role or built-in topic is delivered as its guide says. A role message has three possible answers. First, a session holds the role, and the stream stores the forward for that holder's consumer. Its 200 says the stream stored it, and it does not say that the holder read it; it names the holder and the state the listener resolved the holder in. Second, no session holds the role. The listener then keeps the message, and gives it to the next session that claims that role in the hour that follows. This is a success, and the result says that the listener kept the message. Third, the listener keeps nothing and errs, which tells you to reach the agent some other way: the holder refuses the message, or the forward is not stored within four seconds. A holder that stopped answering keeps its role but was not sent the message, and nothing waits for it, so publish the message again once that holder's holder_state reads live, and start no replacement for that session. A team topic (such as notifications.team.deploy-squad.all) is stored like every other, so a session subscribed to it that was away still receives it when it returns, and one that subscribes after you publish does not. A notifications. topic no stream subject captures is refused by name: nothing would store it. ${PUBLISH_COUNTS} ${SESSION_STATE_GUIDE} ${DELIVERY_CONTRACT}`,
52991
53025
  arguments: (schema) => ({ topic: schema.string(), ...messageArguments(schema) }),
52992
53026
  operation: EnvoyToolOperation.publish
52993
53027
  },
@@ -53030,16 +53064,37 @@ var envoyToolSpecs = [
53030
53064
  operation: EnvoyToolOperation.slackPost
53031
53065
  }
53032
53066
  ];
53067
+ function lastSeenText(lastSeen) {
53068
+ return `${new Date(lastSeen).toISOString().slice(0, 19)}Z`;
53069
+ }
53070
+ var STORED_ONCE = "an earlier attempt under the same idempotency_key was already stored, so this one stored no " + "second copy";
53033
53071
  function sendConfirmationText(result) {
53072
+ if (result.state === "stopped") {
53073
+ const seen = result.lastSeen === undefined ? "" : ` (last seen ${lastSeenText(result.lastSeen)})`;
53074
+ const waits = `the session is stopped${seen}; if it runs again within ${DELIVERY_DUPLICATE_WINDOW_HOURS} hours, it gets the message`;
53075
+ if (result.duplicate) {
53076
+ return `queued once for ${result.recipient}: ${STORED_ONCE}; ${waits}`;
53077
+ }
53078
+ return `queued ${result.envelope.event_id} for ${result.recipient}: ${waits}`;
53079
+ }
53034
53080
  if (result.duplicate) {
53035
- return `sent to ${result.recipient} once: an earlier attempt under the same idempotency_key was already stored, so this one stored no second copy`;
53081
+ return `sent to ${result.recipient} once: ${STORED_ONCE}`;
53036
53082
  }
53037
53083
  const since = result.lastSeen === undefined ? "" : ` since ${new Date(result.lastSeen).toISOString()}`;
53038
53084
  const state = result.recipientState === "unresponsive" ? `unresponsive${since}, so it is stored until that session answers; ${UNRESPONSIVE_RULE}` : result.recipientState;
53039
53085
  return `sent ${result.envelope.event_id} to ${result.recipient} (${state})${result.confirmed ? "" : " (recipient unconfirmed by listener)"}`;
53040
53086
  }
53041
53087
  function publishConfirmationText(result) {
53042
- const sentences = [`published ${result.envelope.event_id}.`];
53088
+ const published = `published ${result.envelope.event_id}`;
53089
+ if (result.recipients === 0) {
53090
+ return `${published}; no other session subscribes to ${result.envelope.topic}, so no other session gets it`;
53091
+ }
53092
+ if (result.recipients !== undefined) {
53093
+ const sessions = result.recipients === 1 ? "1 other session" : `${result.recipients} other sessions`;
53094
+ const running = result.recipientsConnected === undefined ? "" : ` (${result.recipientsConnected} running now)`;
53095
+ return `${published} to ${sessions}${running}`;
53096
+ }
53097
+ const sentences = [`${published}.`];
53043
53098
  if (result.kept === true) {
53044
53099
  sentences.push("Envoy kept it for the role: no session holds it yet, and the message waits for the session that claims it next.");
53045
53100
  } else if (result.holder !== undefined) {
@@ -56499,7 +56554,7 @@ var import_nats2 = __toESM(require_mod4(), 1);
56499
56554
 
56500
56555
  // package.json
56501
56556
  var name = "@sjawhar/claude-envoy";
56502
- var version2 = "2.25.1";
56557
+ var version2 = "2.26.0";
56503
56558
  var legion = {
56504
56559
  daemonApiVersion: 137
56505
56560
  };
@@ -61077,7 +61132,9 @@ async function executeEnvoyTool(runtime, name, input) {
61077
61132
  event_id: result.envelope.event_id,
61078
61133
  recipient: result.recipient,
61079
61134
  recipient_state: result.recipientState,
61080
- confirmed: result.confirmed
61135
+ confirmed: result.confirmed,
61136
+ state: result.state,
61137
+ ...result.lastSeen === undefined ? {} : { last_seen: result.lastSeen }
61081
61138
  };
61082
61139
  }
61083
61140
  case EnvoyToolOperation.publish: {
@@ -61095,6 +61152,8 @@ async function executeEnvoyTool(runtime, name, input) {
61095
61152
  topic: result.envelope.topic,
61096
61153
  ...result.holder === undefined ? {} : { holder: result.holder },
61097
61154
  ...result.holderState === undefined ? {} : { holder_state: result.holderState },
61155
+ ...result.recipients === undefined ? {} : { recipients: result.recipients },
61156
+ ...result.recipientsConnected === undefined ? {} : { recipients_connected: result.recipientsConnected },
61098
61157
  ...result.kept === undefined ? {} : { kept: result.kept },
61099
61158
  ...result.keptReason === undefined ? {} : { kept_reason: result.keptReason }
61100
61159
  };
@@ -13831,6 +13831,12 @@ var DEFAULT_ISSUE_PAGE_LIMIT = 50;
13831
13831
  var DEFAULT_ISSUE_READ_EVENTS = 10;
13832
13832
  var ASK_TURNS = ["human", "agent"];
13833
13833
  var DELIVERY_CAPABILITIES = ["aside", "btw", "steer"];
13834
+ var DELIVERY_ATTEMPT_STATES = ["pending", "sent", "queued", "failed"];
13835
+ var SETTLED_DELIVERY_STATES = [
13836
+ "sent",
13837
+ "queued",
13838
+ "failed"
13839
+ ];
13834
13840
  var IDEMPOTENCY_KEY_HEADER = "Idempotency-Key";
13835
13841
  var IDEMPOTENCY_REPLAYED_HEADER = "Idempotency-Replayed";
13836
13842
  var IDEMPOTENCY_KEY_MAX = 128;
@@ -13847,6 +13853,7 @@ function answerNotKept(status, replayed, body) {
13847
13853
  var IDEMPOTENCY_KEY_TTL_MS = 24 * 60 * 60 * 1000;
13848
13854
  var IDEMPOTENCY_LEASE_MS = 60 * 1000;
13849
13855
  var DELIVERY_DUPLICATE_WINDOW_MS = 72 * 60 * 60 * 1000;
13856
+ var DELIVERY_DUPLICATE_WINDOW_HOURS = DELIVERY_DUPLICATE_WINDOW_MS / 3600000;
13850
13857
  var SEARCH_DEGRADED_EMBEDDER_UNAVAILABLE = "embedder_unavailable";
13851
13858
 
13852
13859
  // ../contracts/src/dispatch-api-refs.ts
@@ -15151,7 +15158,7 @@ var commentDeliveryFields = {
15151
15158
  session_id: string2().nullable(),
15152
15159
  envelope_id: string2().nullable(),
15153
15160
  duplicate: boolean2().optional(),
15154
- state: _enum2(["pending", "sent", "failed"]),
15161
+ state: _enum2(DELIVERY_ATTEMPT_STATES),
15155
15162
  error: string2().nullable(),
15156
15163
  resolve_error: string2().nullable(),
15157
15164
  reply_id: string2().nullable(),
@@ -15239,7 +15246,7 @@ var CommentDeliveryEventPayloadSchema = strictObject({
15239
15246
  attempt: number2().int().positive(),
15240
15247
  delivery: _enum2(DELIVERY_CAPABILITIES),
15241
15248
  session_id: string2().nullable(),
15242
- state: _enum2(["sent", "failed"]),
15249
+ state: _enum2(SETTLED_DELIVERY_STATES),
15243
15250
  duplicate: boolean2().optional(),
15244
15251
  error: string2().optional(),
15245
15252
  reply_id: string2().nullable()
@@ -15274,7 +15281,7 @@ var messageDeliveryFields = {
15274
15281
  session_id: string2(),
15275
15282
  envelope_id: string2().nullable(),
15276
15283
  duplicate: boolean2().optional(),
15277
- state: _enum2(["pending", "sent", "failed"]),
15284
+ state: _enum2(DELIVERY_ATTEMPT_STATES),
15278
15285
  error: string2().nullable(),
15279
15286
  reply_id: string2().nullable(),
15280
15287
  created_at: string2(),
@@ -15325,7 +15332,7 @@ var messageDeliveryEventPayloadFields = {
15325
15332
  session_id: string2(),
15326
15333
  target: string2().optional(),
15327
15334
  title: string2(),
15328
- state: _enum2(["sent", "failed"]),
15335
+ state: _enum2(SETTLED_DELIVERY_STATES),
15329
15336
  duplicate: boolean2().optional(),
15330
15337
  error: string2().optional()
15331
15338
  };
@@ -20667,6 +20674,7 @@ var issueFreeTools = {
20667
20674
  dispatch_whoami: true,
20668
20675
  dispatch_limits: true,
20669
20676
  dispatch_inbox: true,
20677
+ dispatch_send_to_agent: true,
20670
20678
  dispatch_architecture_sync: true
20671
20679
  };
20672
20680
  function canonicalExternalIssueRef(value) {
@@ -22560,6 +22568,19 @@ async function messageCommand(context) {
22560
22568
  }
22561
22569
  };
22562
22570
  }
22571
+ function arrivalText(attempt) {
22572
+ if (attempt === undefined)
22573
+ return "Dispatch recorded no delivery attempt for it";
22574
+ if (attempt.state === "failed") {
22575
+ return `its delivery failed: ${attempt.error ?? "the listener gave no reason"}`;
22576
+ }
22577
+ if (attempt.state === "pending")
22578
+ return "its delivery is still on its way";
22579
+ if (attempt.state === "queued") {
22580
+ return `that session is stopped, so its delivery is queued: it gets the message if it runs again within ${DELIVERY_DUPLICATE_WINDOW_HOURS} hours`;
22581
+ }
22582
+ return `it reached that session as ${attempt.delivery}`;
22583
+ }
22563
22584
  async function sendToAgentCommand(context) {
22564
22585
  const { args, client } = context;
22565
22586
  const session = stringArg(args, "session");
@@ -22571,7 +22592,7 @@ async function sendToAgentCommand(context) {
22571
22592
  });
22572
22593
  const attempt = message.deliveries?.at(-1);
22573
22594
  const readBack = conversationReadBack(message.id);
22574
- const arrival = attempt === undefined ? "Dispatch recorded no delivery attempt for it" : attempt.state === "failed" ? `its delivery failed: ${attempt.error ?? "the listener gave no reason"}` : attempt.state === "pending" ? "its delivery is still on its way" : `it reached that session as ${attempt.delivery}`;
22595
+ const arrival = arrivalText(attempt);
22575
22596
  return {
22576
22597
  text: `Sent message ${message.id} to session ${session}; ${arrival}. ${readBack}`,
22577
22598
  details: {
@@ -76,7 +76,8 @@ next look of its own.
76
76
 
77
77
  The controller topic is a live wake: a message published while no controller runs reaches nobody
78
78
  at the time. `envoy_publish`'s own answer tells you whether one took it. A publish to a role
79
- answers with its live `holder`. With no claim on `legion-<project>-controller` at all, the answer
79
+ answers with its live `holder`, and with no count of recipients: the listener forwards a role
80
+ message to its holder alone. With no claim on `legion-<project>-controller` at all, the answer
80
81
  says Envoy kept the message instead (`packages/envoy/cmd/listener`, the test "unheld role is kept
81
82
  and answered 202 without publishing on the role topic"): the next session that claims the role is
82
83
  handed each kept message once, within one hour of the keep. A keep is not a delivery: a
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sjawhar/claude-envoy",
3
- "version": "2.25.1",
3
+ "version": "2.26.0",
4
4
  "license": "Apache-2.0",
5
5
  "description": "Claude Code plugin for Legion's Envoy bus",
6
6
  "type": "module",
@@ -19,8 +19,12 @@ Delivery is at-least-once and can come out of order across topics: drop a repeat
19
19
 
20
20
  - Read the `recipient` in the send result, the session Envoy targeted: if it is not the one you meant, resend to the right id.
21
21
 
22
+ - A send answered `queued <id> for <recipient>: the session is stopped …` (`state: stopped`) went to a session that is not running, and nothing of its claims changes.
23
+ Do not send that message again, because a second send stores a second copy for that session to read.
24
+ What each send answer means: `skill://envoy/references/deliveries.md`, "What a publish and a send answer".
25
+
22
26
  - When `envoy_send` says the send is not confirmed delivered, send the same message again with the `idempotency_key` the error names, within 72 hours:
23
- Envoy drops it as a repeat if the first copy arrived, and the result says when an earlier attempt was already stored.
27
+ Envoy drops it as a repeat if the first copy arrived, and the result then says the earlier attempt was already stored (its text begins `sent to <recipient> once` for a running session, `queued once for <recipient>` for a stopped one).
24
28
  A resend without that key can deliver the message twice.
25
29
  When the error says Envoy cannot recognise the repeat, ask the recipient whether it arrived instead.
26
30
 
@@ -152,6 +156,9 @@ Every topic starts with `notifications.`.
152
156
  Every other `notifications.` topic no source in the table uses is refused by name, at publish and at subscribe, because no session would ever receive it.
153
157
  A topic outside `notifications.` is refused at publish alone: you may subscribe to one, and nothing is stored under it, so you receive nothing on it.
154
158
 
159
+ - A publish answered `published <id>; no other session subscribes to <topic>, so no other session gets it` reached nobody: reach whoever you meant another way.
160
+ What the counts in a publish answer mean: `skill://envoy/references/deliveries.md`, "What a publish and a send answer".
161
+
155
162
  - How a role claim survives a resume, a fork or a dead process: `skill://envoy/references/roles.md`.
156
163
 
157
164
  - In a Legion pane, the plugin claims your role for you, at your session's first turn;
@@ -118,6 +118,28 @@ It depends on where a session takes its deliveries, not on whether the topic is
118
118
  Your session is never left unregistered by one:
119
119
  a registration that carries such a topic from an older subscription of yours keeps its other topics and names that one in a warning.
120
120
 
121
+ ## What a publish and a send answer
122
+
123
+ - A publish to any topic but a role answers how many sessions get the message, counted when it was published: `published <id> to N other sessions (M running now)`.
124
+ `N` is every session other than you whose topics match the topic, a stopped session Envoy knows from the last 30 days included, and `M` is how many of those are live now.
125
+ A stopped session among them reads the message from its own consumer if it runs again within 72 hours.
126
+
127
+ - `published <id>; no other session subscribes to <topic>, so no other session gets it` is that count at zero: nobody follows the topic, so the message reached nobody.
128
+ Reach whoever you meant another way, because a session that subscribes later does not get it.
129
+
130
+ - A role topic's answer names its live `holder` instead of a count.
131
+ A listener that cannot read its records of known sessions counts nothing and answers `published <id>.` alone.
132
+
133
+ - A send answers what its target was when Envoy stored the message: `sent <id> to <recipient> (live)` for a live session, the same line with `unresponsive` and the time it went silent for an unresponsive one, and `queued <id> for <recipient>: the session is stopped (last seen <time>); if it runs again within 72 hours, it gets the message` for one that is not running.
134
+ The listener tells a running session from a stopped one with one request on the session's relay subject, the subject the session's own plugin receives its messages on:
135
+ anything that answers it or stays silent for a second reads as running, a predecessor process of the same session id included, and nothing there at all reads as stopped.
136
+ None of the three lines says that the session read the message.
137
+
138
+ - A queued message waits for a session Envoy knows and that is not running.
139
+ Never send a queued message again: a second send stores a second copy for that session to read.
140
+
141
+ - A send fails with `no live session <id>` only when Envoy knows no session under that id, running now or in the last 30 days, or when the session is stopped and the listener cannot read its records of known sessions.
142
+
121
143
  ## Listener API errors
122
144
 
123
145
  When you call the listener's `/v1` API directly, every error response is JSON, and when a field is at fault, `expected` names it: fix that field and retry.
@@ -1844,6 +1844,8 @@ export async function executeEnvoyTool(
1844
1844
  recipient: result.recipient,
1845
1845
  recipient_state: result.recipientState,
1846
1846
  confirmed: result.confirmed,
1847
+ state: result.state,
1848
+ ...(result.lastSeen === undefined ? {} : { last_seen: result.lastSeen }),
1847
1849
  }
1848
1850
  }
1849
1851
  case EnvoyToolOperation.publish: {
@@ -1855,15 +1857,19 @@ export async function executeEnvoyTool(
1855
1857
  message: args.message,
1856
1858
  ...toMessageMetadata(args),
1857
1859
  })
1858
- // The answer the model reads, its line first. A publish to a topic the stream captures is
1859
- // answered with the envelope alone; a kept answer is a success of its own, which the line
1860
- // says in the words the Oh My Pi plugin uses (`publishConfirmationText`).
1860
+ // The answer the model reads, its line first: the counts of a stored topic's answer, a role
1861
+ // holder, or a kept answer, which is a success of its own, all in the words the Oh My Pi
1862
+ // plugin uses (`publishConfirmationText`).
1861
1863
  return {
1862
1864
  message: publishConfirmationText(result),
1863
1865
  event_id: result.envelope.event_id,
1864
1866
  topic: result.envelope.topic,
1865
1867
  ...(result.holder === undefined ? {} : { holder: result.holder }),
1866
1868
  ...(result.holderState === undefined ? {} : { holder_state: result.holderState }),
1869
+ ...(result.recipients === undefined ? {} : { recipients: result.recipients }),
1870
+ ...(result.recipientsConnected === undefined
1871
+ ? {}
1872
+ : { recipients_connected: result.recipientsConnected }),
1867
1873
  ...(result.kept === undefined ? {} : { kept: result.kept }),
1868
1874
  ...(result.keptReason === undefined ? {} : { kept_reason: result.keptReason }),
1869
1875
  }