@sjawhar/claude-envoy 6.12.5 → 6.12.7

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": "6.12.5"
5
+ "version": "6.12.7"
6
6
  }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "claude-envoy",
3
- "version": "6.12.5",
3
+ "version": "6.12.7",
4
4
  "description": "Put Envoy events into the Claude Code session's own conversation and expose Envoy MCP tools.",
5
5
  "mcpServers": {}
6
6
  }
@@ -66854,7 +66854,7 @@ var import_nats5 = __toESM(require_mod4(), 1);
66854
66854
 
66855
66855
  // package.json
66856
66856
  var name2 = "@sjawhar/claude-envoy";
66857
- var version2 = "6.12.5";
66857
+ var version2 = "6.12.7";
66858
66858
  var package_default = {
66859
66859
  name: name2,
66860
66860
  version: version2,
@@ -66865,9 +66865,12 @@ var package_default = {
66865
66865
  repository: { type: "git", url: "https://github.com/cybermonklabs/legion" },
66866
66866
  scripts: { channel: "bun bin/envoy-channel.ts", "verify-build": "bash scripts/verify-build.sh", prepack: "bash scripts/pack-skills.sh", postpack: "bash scripts/pack-skills.sh --restore", typecheck: "bun ../contracts/scripts/gen-api.ts && bunx tsc --noEmit", test: "bun test --timeout=60000", lint: "bunx biome check src/ hooks/ scripts/" },
66867
66867
  devDependencies: { "@biomejs/biome": "^2.3.14", "@legion/cipher-client": "workspace:*", "@legion/contracts": "workspace:*", "@legion/envoy-client": "workspace:*", "@legion/pi-shared": "workspace:*", "@legion/test-fixtures": "workspace:*", "@modelcontextprotocol/sdk": "^1.30.0", "bun-types": "latest", nats: "^2.29.2", typescript: "^5.3.0", zod: "4.3.6" },
66868
- legion: { daemonApiVersion: 284 }
66868
+ legion: { daemonApiVersion: 285 }
66869
66869
  };
66870
66870
 
66871
+ // ../pi-shared/src/agent-stream.ts
66872
+ import { createHash as createHash4 } from "crypto";
66873
+
66871
66874
  // ../envoy-client/src/inbound-card.ts
66872
66875
  var CARD_HEAD = "envoy:";
66873
66876
  var TOON_INDENT = " ";
@@ -66968,7 +66971,7 @@ function streamedCard(host) {
66968
66971
  const delivered = "dispatchMessageId";
66969
66972
  return stringField(host.details, delivered) === undefined;
66970
66973
  }
66971
- function keyFor(message, untagged) {
66974
+ function keyFor(message) {
66972
66975
  if (message.role === "toolResult") {
66973
66976
  return message.toolCallId === undefined ? null : `t:${message.toolCallId}`;
66974
66977
  }
@@ -66978,7 +66981,7 @@ function keyFor(message, untagged) {
66978
66981
  if (!streamedCard(message.host))
66979
66982
  return null;
66980
66983
  const { details } = message.host;
66981
- const card = stringField(details, "envoyCard") ?? stringField(details, "event_id") ?? untagged(message.host);
66984
+ const card = stringField(details, "envoyCard") ?? stringField(details, "event_id") ?? createHash4("sha256").update(contentText(message.host.content)).digest("hex").slice(0, 16);
66982
66985
  return `m:c${message.timestamp}:${card}`;
66983
66986
  }
66984
66987
  if (message.role !== "user")
@@ -67003,6 +67006,27 @@ function contentText(content) {
67003
67006
  return pieces.join(`
67004
67007
  `);
67005
67008
  }
67009
+ function detached(raw) {
67010
+ if (typeof raw !== "object" || raw === null)
67011
+ return raw;
67012
+ const copy = {};
67013
+ for (const field of Object.keys(raw)) {
67014
+ const value = Reflect.get(raw, field);
67015
+ try {
67016
+ copy[field] = structuredClone(value);
67017
+ continue;
67018
+ } catch {}
67019
+ try {
67020
+ const json = JSON.stringify(value);
67021
+ if (json !== undefined) {
67022
+ copy[field] = JSON.parse(json);
67023
+ continue;
67024
+ }
67025
+ } catch {}
67026
+ copy[field] = String(value);
67027
+ }
67028
+ return copy;
67029
+ }
67006
67030
  function boundedStrings(_key, value) {
67007
67031
  return typeof value === "string" ? capAgentStreamText(value, AGENT_STREAM_LIMITS.toolChars) : value;
67008
67032
  }
@@ -67139,8 +67163,6 @@ class AgentStreamPublisher {
67139
67163
  #history = new Map;
67140
67164
  #settled = new Set;
67141
67165
  #publishedAt = new Map;
67142
- #untaggedCards = new WeakMap;
67143
- #untaggedCount = 0;
67144
67166
  #seq;
67145
67167
  #watchedUntil = 0;
67146
67168
  #listedCommands;
@@ -67302,23 +67324,58 @@ class AgentStreamPublisher {
67302
67324
  return { ...context, kind: "context", seq: this.#contextSeq, v: AGENT_STREAM_PROTOCOL };
67303
67325
  }
67304
67326
  record(subject, raw, streaming, dispatchMessageId) {
67327
+ const entry = this.#keep(raw, streaming, dispatchMessageId);
67328
+ if (entry === undefined)
67329
+ return false;
67330
+ if (!this.watched)
67331
+ return true;
67332
+ const now = this.#deps.now();
67333
+ const published = this.#publishedAt.get(entry.key);
67334
+ const tooSoon = published !== undefined && now - published < AGENT_STREAM_LIMITS.snapshotIntervalMs;
67335
+ if (entry.streaming && tooSoon)
67336
+ return true;
67337
+ this.#publishedAt.set(entry.key, now);
67338
+ this.#deps.publish(subject, JSON.stringify(frameFor(entry)));
67339
+ return true;
67340
+ }
67341
+ restore(messages, dispatchMessageIdOf = () => {
67342
+ return;
67343
+ }) {
67344
+ const slots = new Map;
67345
+ for (const [index, raw] of messages.entries()) {
67346
+ const message = readMessage(raw);
67347
+ const key = message === null ? null : keyFor(message);
67348
+ if (key === null)
67349
+ continue;
67350
+ slots.set(key, index);
67351
+ if (slots.size <= AGENT_STREAM_LIMITS.historyMessages)
67352
+ continue;
67353
+ const oldest = slots.keys().next();
67354
+ if (oldest.done !== true)
67355
+ slots.delete(oldest.value);
67356
+ }
67357
+ const held = new Map(this.#history);
67358
+ this.#history.clear();
67359
+ for (const [key, index] of slots) {
67360
+ if (held.has(key))
67361
+ continue;
67362
+ const raw = messages[index];
67363
+ this.#keep(detached(raw), false, dispatchMessageIdOf(raw));
67364
+ }
67365
+ for (const [key, entry] of held)
67366
+ this.#history.set(key, entry);
67367
+ this.#evict();
67368
+ }
67369
+ #keep(raw, streaming, dispatchMessageId) {
67305
67370
  const message = readMessage(raw);
67306
67371
  if (message === null)
67307
- return false;
67308
- const key = keyFor(message, (host) => {
67309
- let number = this.#untaggedCards.get(host);
67310
- if (number === undefined) {
67311
- this.#untaggedCount += 1;
67312
- number = this.#untaggedCount;
67313
- this.#untaggedCards.set(host, number);
67314
- }
67315
- return number;
67316
- });
67372
+ return;
67373
+ const key = keyFor(message);
67317
67374
  if (key === null)
67318
- return false;
67375
+ return;
67319
67376
  const stillStreaming = message.role === "assistant" && streaming;
67320
67377
  if (stillStreaming && this.#settled.has(key))
67321
- return false;
67378
+ return;
67322
67379
  this.#seq += 1;
67323
67380
  const entry = {
67324
67381
  at: message.timestamp,
@@ -67331,6 +67388,10 @@ class AgentStreamPublisher {
67331
67388
  this.#history.set(key, entry);
67332
67389
  if (!stillStreaming)
67333
67390
  this.#settled.add(key);
67391
+ this.#evict();
67392
+ return entry;
67393
+ }
67394
+ #evict() {
67334
67395
  while (this.#history.size > AGENT_STREAM_LIMITS.historyMessages) {
67335
67396
  const oldest = this.#history.keys().next();
67336
67397
  if (oldest.done === true)
@@ -67339,16 +67400,6 @@ class AgentStreamPublisher {
67339
67400
  this.#settled.delete(oldest.value);
67340
67401
  this.#publishedAt.delete(oldest.value);
67341
67402
  }
67342
- if (!this.watched)
67343
- return true;
67344
- const now = this.#deps.now();
67345
- const published = this.#publishedAt.get(key);
67346
- const tooSoon = published !== undefined && now - published < AGENT_STREAM_LIMITS.snapshotIntervalMs;
67347
- if (stillStreaming && tooSoon)
67348
- return true;
67349
- this.#publishedAt.set(key, now);
67350
- this.#deps.publish(subject, JSON.stringify(frameFor(entry)));
67351
- return true;
67352
67403
  }
67353
67404
  replay(sessionID) {
67354
67405
  if (!this.watched)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sjawhar/claude-envoy",
3
- "version": "6.12.5",
3
+ "version": "6.12.7",
4
4
  "license": "Apache-2.0",
5
5
  "description": "Claude Code plugin for Legion's Envoy bus",
6
6
  "type": "module",
@@ -45,6 +45,6 @@
45
45
  "zod": "4.3.6"
46
46
  },
47
47
  "legion": {
48
- "daemonApiVersion": 284
48
+ "daemonApiVersion": 285
49
49
  }
50
50
  }