@agentvault/claude-bridge 0.8.29 → 0.8.30

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.
Files changed (2) hide show
  1. package/dist/index.js +79 -12
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -11718,11 +11718,11 @@ async function joinWithFirstMatchingKp(welcomeBytes, candidates) {
11718
11718
  return null;
11719
11719
  }
11720
11720
  function ownIdentity() {
11721
- const v22 = true ? "0.23.60" : FALLBACK;
11721
+ const v22 = true ? "0.23.61" : FALLBACK;
11722
11722
  return `${PACKAGE}@${v22}`;
11723
11723
  }
11724
11724
  function buildSha() {
11725
- const raw = true ? "628e3ba" : "";
11725
+ const raw = true ? "129e537" : "";
11726
11726
  const cleaned = (raw ?? "").trim();
11727
11727
  return !cleaned || cleaned === "unknown" ? null : cleaned;
11728
11728
  }
@@ -71000,6 +71000,17 @@ var init_dist = __esm({
71000
71000
  * self-heal rather than be logged and dropped. */
71001
71001
  _mlsCommitFailCounts = /* @__PURE__ */ new Map();
71002
71002
  static MAX_MLS_DECRYPT_FAILS = 3;
71003
+ /**
71004
+ * #1518: ids of MLS application frames this process has already decrypted
71005
+ * (server-assigned `mls_messages.id`, the same on the live delivery pull and
71006
+ * on a `/sync` / reconnect replay). A replayed frame cannot be decrypted a
71007
+ * second time — forward secrecy deleted its key — so without this every
71008
+ * reconnect after a backend deploy fed already-read messages into the
71009
+ * decrypt-failure counter and re-admitted the agent (+2 epochs). Insertion
71010
+ * ordered; the oldest ids fall out past DECRYPTED_ID_CAP.
71011
+ */
71012
+ _decryptedMessageIds = /* @__PURE__ */ new Map();
71013
+ static DECRYPTED_ID_CAP = 5e3;
71003
71014
  /**
71004
71015
  * #1084: consecutive resyncs that found NOTHING to apply, per group.
71005
71016
  *
@@ -73205,7 +73216,7 @@ ${text}`,
73205
73216
  */
73206
73217
  sendActivitySpan(spanData) {
73207
73218
  if (!this._ws || this._ws.readyState !== WebSocket2.OPEN) return;
73208
- const pluginVersion = true ? "0.23.60" : "0.0.0-dev";
73219
+ const pluginVersion = true ? "0.23.61" : "0.0.0-dev";
73209
73220
  const agentName = this.config.agentName ?? "Agent";
73210
73221
  const resource = {
73211
73222
  "service.name": "agentvault-agent",
@@ -75415,7 +75426,7 @@ ${text}`,
75415
75426
  agentVersion: this.config.agentVersion ?? "0.0.0",
75416
75427
  // __AV_VERSION__ is injected by esbuild from package.json at build time.
75417
75428
  // Falls back to "0.0.0-dev" in non-bundled contexts (tests).
75418
- pluginVersion: true ? "0.23.60" : "0.0.0-dev"
75429
+ pluginVersion: true ? "0.23.61" : "0.0.0-dev"
75419
75430
  });
75420
75431
  this._telemetryReporter.startAutoFlush(3e4);
75421
75432
  }
@@ -75747,7 +75758,7 @@ ${text}`,
75747
75758
  agentVersion: this.config.agentVersion ?? "0.0.0",
75748
75759
  // __AV_VERSION__ is injected by esbuild from package.json at build time.
75749
75760
  // Falls back to "0.0.0-dev" in non-bundled contexts (tests).
75750
- pluginVersion: true ? "0.23.60" : "0.0.0-dev"
75761
+ pluginVersion: true ? "0.23.61" : "0.0.0-dev"
75751
75762
  });
75752
75763
  this._telemetryReporter.startAutoFlush(3e4);
75753
75764
  }
@@ -76183,9 +76194,14 @@ ${text}`,
76183
76194
  if (groupId) void this._requestWelcomeSelfHeal(groupId);
76184
76195
  return;
76185
76196
  }
76197
+ if (this._alreadyDecrypted(data.message_id)) {
76198
+ console.debug(`[SecureChannel] MLS 1:1 frame ${String(data.message_id).slice(0, 8)} already read \u2014 replay skipped`);
76199
+ return;
76200
+ }
76186
76201
  try {
76187
76202
  const cipherBytes = new Uint8Array(Buffer.from(data.payload, "hex"));
76188
76203
  const result = await mgr.decrypt(cipherBytes);
76204
+ this._rememberDecrypted(data.message_id);
76189
76205
  if (mgrKey) this._mlsDecryptFailCounts.delete(mgrKey);
76190
76206
  const mlsGroupId = (convGroupId ? this._persisted?.mlsGroups?.[convGroupId]?.mlsGroupId : null) ?? this._persisted?.mlsConversations?.[convId]?.mlsGroupId ?? groupId;
76191
76207
  if (mlsGroupId) {
@@ -77208,9 +77224,14 @@ ${baseText}`;
77208
77224
  }
77209
77225
  return;
77210
77226
  }
77227
+ if (this._alreadyDecrypted(data.message_id)) {
77228
+ console.debug(`[SecureChannel] MLS room frame ${String(data.message_id).slice(0, 8)} already read \u2014 replay skipped`);
77229
+ return;
77230
+ }
77211
77231
  try {
77212
77232
  const ciphertext = Buffer.from(data.payload, "hex");
77213
77233
  const result = await mlsGroup.decrypt(new Uint8Array(ciphertext));
77234
+ this._rememberDecrypted(data.message_id);
77214
77235
  this._mlsDecryptFailCounts.delete(resolvedRoomId);
77215
77236
  await saveMlsState(this.config.dataDir, groupId, JSON.stringify(mlsGroup.exportState()));
77216
77237
  if (result.isHandshake || !result.plaintext) {
@@ -78388,16 +78409,57 @@ ${baseText}`;
78388
78409
  }
78389
78410
  return await mlsGroup.encrypt(plaintextBytes);
78390
78411
  }
78412
+ /** #1518: is the server answering at all? Bounded; any failure is "no". */
78413
+ async _serverReachable() {
78414
+ try {
78415
+ const res = await fetch(`${this.config.apiUrl}/health`, { signal: AbortSignal.timeout(5e3) });
78416
+ return res.ok;
78417
+ } catch {
78418
+ return false;
78419
+ }
78420
+ }
78421
+ /** #1518: the server is down — don't re-key (that needs the same server).
78422
+ * Clear the run so the next failures ask again. Reported as handled. */
78423
+ _deferResync(groupKey, groupId, why) {
78424
+ this._mlsDecryptFailCounts.delete(groupKey);
78425
+ console.warn(
78426
+ `[SecureChannel] Resync for ${groupId.slice(0, 8)}: server unreachable (${why}) \u2014 NOT re-keying; will retry (#1518)`
78427
+ );
78428
+ return true;
78429
+ }
78430
+ /** #1518: has this process already decrypted the frame with this id? */
78431
+ _alreadyDecrypted(messageId) {
78432
+ return typeof messageId === "string" && messageId !== "" && this._decryptedMessageIds.has(messageId);
78433
+ }
78434
+ /** #1518: remember a decrypted frame's id (bounded; oldest dropped). */
78435
+ _rememberDecrypted(messageId) {
78436
+ if (typeof messageId !== "string" || messageId === "") return;
78437
+ this._decryptedMessageIds.set(messageId, true);
78438
+ if (this._decryptedMessageIds.size > _SecureChannel.DECRYPTED_ID_CAP) {
78439
+ const oldest = this._decryptedMessageIds.keys().next().value;
78440
+ if (oldest !== void 0) this._decryptedMessageIds.delete(oldest);
78441
+ }
78442
+ }
78391
78443
  async _resyncOnDivergence(groupKey, groupId) {
78392
78444
  const mgr = this._mlsGroups.get(groupKey);
78393
78445
  if (!mgr?.isInitialized) return false;
78394
78446
  const fromEpoch = Number(mgr.epoch);
78395
78447
  try {
78396
- const res = await fetch(
78397
- `${this.config.apiUrl}/api/v1/mls/groups/${groupId}/sync?last_epoch=${fromEpoch}`,
78398
- { headers: { Authorization: `Bearer ${this._deviceJwt}` } }
78399
- );
78448
+ let res;
78449
+ try {
78450
+ res = await fetch(
78451
+ `${this.config.apiUrl}/api/v1/mls/groups/${groupId}/sync?last_epoch=${fromEpoch}`,
78452
+ { headers: { Authorization: `Bearer ${this._deviceJwt}` } }
78453
+ );
78454
+ } catch (netErr) {
78455
+ if (!await this._serverReachable()) return this._deferResync(groupKey, groupId, String(netErr));
78456
+ console.warn(`[SecureChannel] Resync-on-divergence failed for ${groupId.slice(0, 8)}:`, netErr);
78457
+ return false;
78458
+ }
78400
78459
  if (!res.ok) {
78460
+ if ((res.status >= 500 || res.status === 429) && !await this._serverReachable()) {
78461
+ return this._deferResync(groupKey, groupId, `HTTP ${res.status}`);
78462
+ }
78401
78463
  console.warn(`[SecureChannel] Resync /sync failed for ${groupId.slice(0, 8)}: ${res.status}`);
78402
78464
  return false;
78403
78465
  }
@@ -79512,9 +79574,14 @@ ${baseText}`;
79512
79574
  console.warn(`[SecureChannel] MLS group not loaded for A2A ${a2aChannelId.slice(0, 8)}`);
79513
79575
  return;
79514
79576
  }
79577
+ if (this._alreadyDecrypted(data.message_id)) {
79578
+ console.debug(`[SecureChannel] MLS A2A frame ${String(data.message_id).slice(0, 8)} already read \u2014 replay skipped`);
79579
+ return;
79580
+ }
79515
79581
  try {
79516
79582
  const ciphertext = new Uint8Array(Buffer.from(data.payload, "hex"));
79517
79583
  const result = await mlsGroup.decrypt(ciphertext);
79584
+ this._rememberDecrypted(data.message_id);
79518
79585
  this._mlsDecryptFailCounts.delete(`a2a:${a2aChannelId}`);
79519
79586
  await saveMlsState(this.config.dataDir, groupId, JSON.stringify(mlsGroup.exportState()));
79520
79587
  if (result.isHandshake || !result.plaintext) {
@@ -102165,7 +102232,7 @@ data:
102165
102232
  await init_policy_enforcer();
102166
102233
  init_room_protocol();
102167
102234
  init_tool_telemetry();
102168
- VERSION = true ? "0.23.60" : "0.0.0-dev";
102235
+ VERSION = true ? "0.23.61" : "0.0.0-dev";
102169
102236
  }
102170
102237
  });
102171
102238
  await init_index();
@@ -145949,7 +146016,7 @@ async function main() {
145949
146016
  "[bridge] warning: passing the invite token on the command line is visible to other local users via 'ps'. Prefer: AV_INVITE_TOKEN=\u2026 npx @agentvault/claude-bridge"
145950
146017
  );
145951
146018
  }
145952
- logLine(`[bridge] version: ${true ? "0.8.29" : "dev"}`);
146019
+ logLine(`[bridge] version: ${true ? "0.8.30" : "dev"}`);
145953
146020
  logLine(`[bridge] data dir: ${cfg.dataDir} (${cfg.dataDirSource})`);
145954
146021
  logLine(`[bridge] workspace: ${cfg.workspaceDir} \xB7 permissions: ${cfg.permissionMode} \xB7 enclave dir fenced`);
145955
146022
  if (cfg.armRoom) {
@@ -145981,7 +146048,7 @@ async function main() {
145981
146048
  // its default would render "@agentvault/agentvault@0.7.x" — the wrong
145982
146049
  // package name attached to the bridge's version number, which is worse
145983
146050
  // than either alone.
145984
- clientVersion: `@agentvault/claude-bridge@${true ? "0.8.29" : "dev"}`
146051
+ clientVersion: `@agentvault/claude-bridge@${true ? "0.8.30" : "dev"}`
145985
146052
  });
145986
146053
  const agentSystemPrompt = cfg.systemPrompt ?? identityPrompt(cfg.agentName);
145987
146054
  const deviceJwt = () => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agentvault/claude-bridge",
3
- "version": "0.8.29",
3
+ "version": "0.8.30",
4
4
  "type": "module",
5
5
  "description": "AgentVault Claude Bridge — daemon for bridging a Claude agent into secure E2E-encrypted AgentVault 1:1 direct messages and rooms.",
6
6
  "main": "dist/index.js",