@agentvault/claude-bridge 0.8.28 → 0.8.29

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.
package/dist/bridge.d.ts CHANGED
@@ -162,6 +162,13 @@ export interface ReplyChannel {
162
162
  groupId?: string;
163
163
  }): Promise<T>;
164
164
  }
165
+ /**
166
+ * #1467: the owner's Claude plan refused a turn. One `ai.agent.tool.invoke`
167
+ * error span (tool `model_turn`, code `plan_limit_reached`) with the reset time
168
+ * when known. No conversation: the limit is the plan's, not one chat's — and
169
+ * so the span never says who was being answered. Never throws.
170
+ */
171
+ export declare function reportPlanLimit(channel: Pick<ReplyChannel, "telemetry">, resetsAt: number | undefined): void;
165
172
  /**
166
173
  * Tracks the destination of the most recent inbound message and routes outbound
167
174
  * replies there. Replaces the bridge's old single `activeRoomId` string so the
package/dist/index.js CHANGED
@@ -11722,7 +11722,7 @@ function ownIdentity() {
11722
11722
  return `${PACKAGE}@${v22}`;
11723
11723
  }
11724
11724
  function buildSha() {
11725
- const raw = true ? "9599d8e" : "";
11725
+ const raw = true ? "628e3ba" : "";
11726
11726
  const cleaned = (raw ?? "").trim();
11727
11727
  return !cleaned || cleaned === "unknown" ? null : cleaned;
11728
11728
  }
@@ -12540,6 +12540,10 @@ function buildToolInvokeSpan(report) {
12540
12540
  "tool.duration_ms": durationMs
12541
12541
  };
12542
12542
  if (isError) attributes["tool.error_kind"] = safeErrorKind(report.errorKind);
12543
+ const resets = report.limitResetsAt;
12544
+ if (attributes["tool.error_kind"] === "plan_limit_reached" && typeof resets === "number" && Number.isInteger(resets) && resets > 0 && resets < 1e11) {
12545
+ attributes["av.limit_resets_at"] = resets;
12546
+ }
12543
12547
  if (kind !== "unknown" && typeof conv.id === "string" && conv.id) {
12544
12548
  attributes["av.conversation_id"] = conv.id.slice(0, 64);
12545
12549
  }
@@ -70780,6 +70784,11 @@ var init_dist = __esm({
70780
70784
  "ambiguous_target",
70781
70785
  "no_receipt",
70782
70786
  "invalid_request",
70787
+ // #1467: the owner's own AI plan refused the turn (a bridge on a subscription).
70788
+ "plan_limit_reached",
70789
+ // #1467: a Muse turn failed — Meta answered 429, or anything else.
70790
+ "model_rate_limited",
70791
+ "model_error",
70783
70792
  UNCLASSIFIED_ERROR
70784
70793
  ];
70785
70794
  KNOWN_CODES = new Set(KNOWN_TOOL_ERROR_CODES);
@@ -144600,6 +144609,27 @@ function makeRoomSayTool(onSay) {
144600
144609
  );
144601
144610
  }
144602
144611
  var ROOM_SAY_TOOL_NAME = "mcp__room__say";
144612
+ function newTurn(item) {
144613
+ return {
144614
+ reply: item?.reply,
144615
+ autoReply: item?.autoReplyOnText ?? false,
144616
+ toolEligibleSender: item?.toolEligibleSender === true,
144617
+ roomReplyExpected: item?.replyExpected === true,
144618
+ hasRoomContext: item?.armed !== void 0,
144619
+ // D5: THIS turn's armed getter; the gate calls it live per tool decision.
144620
+ armed: item?.armed ?? (() => false),
144621
+ // Fallback signal, decoupled from the tool gate. Defaults to autoReplyOnText
144622
+ // so an owner 1:1 DM keeps the #416 behavior; a room turn sets it explicitly
144623
+ // according to the shared @mention policy.
144624
+ replyExpected: item?.replyExpected ?? item?.autoReplyOnText ?? false,
144625
+ sayAllowed: item?.replyExpected ?? true,
144626
+ said: false,
144627
+ text: "",
144628
+ sawResult: false,
144629
+ refused: false,
144630
+ telemetry: {}
144631
+ };
144632
+ }
144603
144633
  var PersistentClaudeSession = class {
144604
144634
  constructor(opts) {
144605
144635
  this.opts = opts;
@@ -144607,54 +144637,26 @@ var PersistentClaudeSession = class {
144607
144637
  opts;
144608
144638
  waiting = null;
144609
144639
  pending = [];
144610
- /** Reply sink bound to the message currently being processed. Set as each
144611
- * message is handed to the model so the say tool routes to the right place. */
144612
- activeReply;
144613
- /** Owner-DM attestation also enables its plain-text fallback. Room turns
144614
- * carry separate sender authority and can never become DMs on disarm. */
144615
- currentAutoReply = false;
144616
- currentToolEligibleSender = false;
144617
- currentRoomReplyExpected = false;
144618
- currentHasRoomContext = false;
144619
- /** Called per tool decision so a mid-turn room disarm takes effect live. */
144620
- currentArmedGetter = () => false;
144621
- /** Effective prose fallback policy, including the separate owner-DM default. */
144622
- currentReplyExpected = false;
144623
- /** #1180: whether the say tool may deliver on this turn. Rooms pass an explicit
144624
- * `replyExpected` (#1107: no @ → nobody replies) and that decides it; a 1:1 DM
144625
- * passes none and say stays allowed there. Distinct from `currentReplyExpected`,
144626
- * which drives only the #416 prose fallback and is false for un-attested DMs. */
144627
- currentSayAllowed = true;
144628
- saidThisTurn = false;
144629
- turnText = "";
144630
- /** #630 drop-probe: did a `result` event arrive for the CURRENT turn? Reset per
144631
- * turn in input(), set in the result block. Distinguishes a turn that never
144632
- * reached a result boundary (the silent-drop prime suspect) from a healthy
144633
- * #416 fallback delivery (which delivers via `void reply(...)` WITHOUT setting
144634
- * saidThisTurn, so !saidThisTurn alone would false-flag it). */
144635
- sawResultThisTurn = false;
144636
144640
  /**
144637
- * Per-turn telemetry lifted off the SDK's `result` message.
144638
- *
144639
- * The message arrives on EVERY turn and we kept one boolean from it
144640
- * (`sawResultThisTurn`), discarding the rest. That is the #791 shape: data
144641
- * delivered on the healthy path that nothing reads.
144642
- *
144643
- * It costs us a real answer. A turn that produced nothing (`composed=0,
144644
- * said=false`) could be the model choosing silence, the turn cap being hit, or
144645
- * the provider returning 429 — three different bugs with one symptom, and
144646
- * `subtype`/`apiErrorStatus` are what separate them. 4 of 12 turns on
144647
- * 2026-08-07 were silent and could not be attributed.
144648
- *
144649
- * `durationApiMs` vs `durationMs` also gives the model-time / SDK-overhead
144650
- * split directly. That split previously had to be reconstructed by joining
144651
- * `WorkerIncident.ranMs` against SDK transcripts on disk by wall clock.
144652
- *
144653
- * Every field is OPTIONAL and left undefined when no result arrives (abort or
144654
- * crash mid-turn): absent must read as absent, never as a zero that looks like
144655
- * a real measurement.
144641
+ * #1508: one entry per message the SDK has pulled, oldest first. The SDK
144642
+ * reads queued prompts EAGERLY (measured: a second message is pulled 300 ms
144643
+ * after the first, long before turn 1's output), yet answers them one turn
144644
+ * and one `result` each, in order. So a turn's settings live with ITS
144645
+ * message: input() appends, a `result` retires the head. Everything the
144646
+ * running turn reads — reply target, owed/allowed rules, composed text —
144647
+ * comes from the head (`turn()`), never from the newest message.
144648
+ */
144649
+ turns = [];
144650
+ /** The turn most recently retired. `turn()` falls back to it between turns,
144651
+ * so a late say goes where it did before (the last message's reply). */
144652
+ settled = newTurn();
144653
+ /**
144654
+ * #1467: the plan's limit status as the SDK last reported it. SESSION-level
144655
+ * on purpose: the CLI emits `rate_limit_event` only when the status CHANGES
144656
+ * (`if(!j$(V0,K))YT8(K)` in SDK 0.2.141), so every refused turn after the
144657
+ * first arrives with no event of its own. Never reset per turn.
144656
144658
  */
144657
- resultTelemetry = {};
144659
+ planLimit = { rejected: false };
144658
144660
  /** In-process room MCP server — hoisted so buildSdkOptions can reference it. */
144659
144661
  roomServer;
144660
144662
  /** AbortController for the in-flight query(); abort() triggers it (queue timeout). */
@@ -144682,7 +144684,14 @@ ${text}` : text;
144682
144684
  type: "user",
144683
144685
  message: { role: "user", content },
144684
144686
  parent_tool_use_id: null,
144685
- session_id: ""
144687
+ session_id: "",
144688
+ // #1508 LOAD-BEARING: without this the CLI drains queued prompts
144689
+ // ("next", the default) into the RUNNING turn after each tool call —
144690
+ // and the listener speaks through a tool (room say). Measured live
144691
+ // (SDK 0.2.141): a message queued during `say` was answered inside turn 1
144692
+ // ("DONE-ONE DONE-TWO", one result); with "later" each got its own turn
144693
+ // and result. One merge would leave the turn FIFO one behind for good.
144694
+ priority: "later"
144686
144695
  };
144687
144696
  const item = {
144688
144697
  msg,
@@ -144704,16 +144713,22 @@ ${text}` : text;
144704
144713
  * back to opts.onSay. This is what closes the DM→room leak: the destination is
144705
144714
  * the one captured for the message being answered, not a live global target. */
144706
144715
  async deliver(text) {
144707
- if (!this.currentSayAllowed) {
144716
+ const turn = this.turn();
144717
+ if (!turn.sayAllowed) {
144708
144718
  logLine(
144709
144719
  `[session] say during a turn this agent does not owe (no @mention) \u2014 SUPPRESSED: ${JSON.stringify(text.slice(0, 80))}`
144710
144720
  );
144711
144721
  return;
144712
144722
  }
144713
- this.saidThisTurn = true;
144714
- if (this.activeReply) await this.activeReply(text);
144723
+ turn.said = true;
144724
+ if (turn.reply) await turn.reply(text);
144715
144725
  else if (this.opts.onSay) await this.opts.onSay(text);
144716
144726
  }
144727
+ /** #1508: the turn now producing output — the oldest pulled message not yet
144728
+ * answered — or, between turns, the one just answered. */
144729
+ turn() {
144730
+ return this.turns[0] ?? this.settled;
144731
+ }
144717
144732
  /** Abort the in-flight query() — used by the worker queue on a per-task timeout. */
144718
144733
  abort() {
144719
144734
  this._abort?.abort();
@@ -144729,11 +144744,12 @@ ${text}` : text;
144729
144744
  * Read-only; it must never mutate turn state.
144730
144745
  */
144731
144746
  snapshot() {
144747
+ const turn = this.turn();
144732
144748
  return {
144733
- composedChars: this.turnText.length,
144734
- sawResult: this.sawResultThisTurn,
144735
- said: this.saidThisTurn,
144736
- ...this.resultTelemetry
144749
+ composedChars: turn.text.length,
144750
+ sawResult: turn.sawResult,
144751
+ said: turn.said,
144752
+ ...turn.telemetry
144737
144753
  };
144738
144754
  }
144739
144755
  async *input() {
@@ -144748,18 +144764,7 @@ ${text}` : text;
144748
144764
  this.waiting = resolve5;
144749
144765
  });
144750
144766
  }
144751
- this.activeReply = item.reply;
144752
- this.currentAutoReply = item.autoReplyOnText ?? false;
144753
- this.currentToolEligibleSender = item.toolEligibleSender === true;
144754
- this.currentRoomReplyExpected = item.replyExpected === true;
144755
- this.currentHasRoomContext = item.armed !== void 0;
144756
- this.currentReplyExpected = item.replyExpected ?? item.autoReplyOnText ?? false;
144757
- this.currentSayAllowed = item.replyExpected ?? true;
144758
- this.currentArmedGetter = item.armed ?? (() => false);
144759
- this.saidThisTurn = false;
144760
- this.turnText = "";
144761
- this.sawResultThisTurn = false;
144762
- this.resultTelemetry = {};
144767
+ this.turns.push(newTurn(item));
144763
144768
  yield item.msg;
144764
144769
  }
144765
144770
  }
@@ -144790,7 +144795,7 @@ ${text}` : text;
144790
144795
  osIsolated: this.opts.osIsolated ?? false,
144791
144796
  // Tools require owner-DM attestation without room context, or a verified
144792
144797
  // human sender addressing this agent in an armed room. A reply alone grants no authority.
144793
- // D5: currentArmedGetter() is called HERE on every tool decision, so a
144798
+ // D5: the turn's armed() is called HERE on every tool decision, so a
144794
144799
  // mid-turn disarm denies the next call. See worker-permission.test.ts +
144795
144800
  // session.test.ts for the covering assertions.
144796
144801
  //
@@ -144799,12 +144804,12 @@ ${text}` : text;
144799
144804
  // off, even if the router ever mis-routed. `?? false` is the fail-closed
144800
144805
  // default (no getter ⇒ no tools). Read LIVE per tool decision so a Work-off
144801
144806
  // flip / fail-closed reconnect window denies the very next call.
144802
- isToolTurn: () => (this.opts.workAllowed?.() ?? false) && (this.currentAutoReply && !this.currentHasRoomContext || this.currentToolEligibleSender && this.currentRoomReplyExpected && this.currentArmedGetter()),
144807
+ isToolTurn: () => (this.opts.workAllowed?.() ?? false) && (this.turn().autoReply && !this.turn().hasRoomContext || this.turn().toolEligibleSender && this.turn().roomReplyExpected && this.turn().armed()),
144803
144808
  // Full-access lane: a 1:1 owner DM, whose ephemeral worker is seeded with
144804
144809
  // ONLY the owner's own message, so no third party can steer the turn.
144805
144810
  // The presence of room context is fixed for the turn. Disarming a room
144806
144811
  // must never promote a both-flags turn to the full-access owner-DM lane.
144807
- isOwnerDmTurn: () => this.currentAutoReply && !this.currentHasRoomContext,
144812
+ isOwnerDmTurn: () => this.turn().autoReply && !this.turn().hasRoomContext,
144808
144813
  // #627: the owner removed all gates for this device. Evaluated by
144809
144814
  // gateDecision AFTER isToolTurn, so an unarmed room turn stays chat-only
144810
144815
  // — this widens what a tool turn may do, never which turns get tools.
@@ -144813,7 +144818,7 @@ ${text}` : text;
144813
144818
  gatesRemoved: () => this.opts.gatesRemoved?.() ?? false,
144814
144819
  // Slice 2 Plan B: emit an audit self-report for each tool decision on an
144815
144820
  // armed-room turn (both allow and deny). room_say is excluded by the hook.
144816
- isArmedTurn: () => this.currentArmedGetter(),
144821
+ isArmedTurn: () => this.turn().armed(),
144817
144822
  onToolDecision: (d10) => {
144818
144823
  if (!this.opts.apiUrl || !this.opts.roomId) return;
144819
144824
  reportToolAudit({
@@ -144890,21 +144895,38 @@ ${text}` : text;
144890
144895
  });
144891
144896
  try {
144892
144897
  for await (const m6 of q10) {
144893
- if (m6.type === "assistant") {
144898
+ if (m6.type === "rate_limit_event") {
144899
+ const info = m6.rate_limit_info;
144900
+ if (info && typeof info === "object") {
144901
+ const at = info.resetsAt;
144902
+ const rejected = info.status === "rejected" && info.isUsingOverage !== true;
144903
+ this.planLimit = {
144904
+ rejected,
144905
+ resetsAt: rejected && typeof at === "number" && Number.isFinite(at) ? Math.floor(at) : void 0
144906
+ };
144907
+ }
144908
+ } else if (m6.type === "assistant") {
144909
+ if (m6.error === "rate_limit") this.turn().refused = true;
144894
144910
  const blocks = m6.message?.content ?? [];
144895
144911
  const text = blocks.filter((b5) => b5.type === "text").map((b5) => b5.text ?? "").join("");
144896
144912
  if (text.trim()) {
144897
- this.turnText += text;
144913
+ this.turn().text += text;
144898
144914
  this.opts.onObserve?.(text);
144899
144915
  }
144900
144916
  } else if (m6.type === "result") {
144901
- this.sawResultThisTurn = true;
144917
+ if (this.turns.length === 0) {
144918
+ logLine("[session] result with no message waiting for it \u2014 ignored");
144919
+ continue;
144920
+ }
144921
+ const turn = this.turns[0];
144922
+ turn.sawResult = true;
144902
144923
  const r7 = m6;
144903
144924
  const num2 = (k2) => typeof r7[k2] === "number" ? r7[k2] : void 0;
144904
144925
  const str = (k2) => typeof r7[k2] === "string" ? r7[k2] : void 0;
144905
144926
  const usage = r7.usage ?? {};
144906
144927
  const unum = (k2) => typeof usage[k2] === "number" ? usage[k2] : void 0;
144907
- this.resultTelemetry = {
144928
+ this.reportPlanLimitIfAny(turn);
144929
+ turn.telemetry = {
144908
144930
  durationMs: num2("duration_ms"),
144909
144931
  durationApiMs: num2("duration_api_ms"),
144910
144932
  numTurns: num2("num_turns"),
@@ -144919,26 +144941,41 @@ ${text}` : text;
144919
144941
  if (usageEntries.length > 0) this.opts.onUsage?.(usageEntries, num2("duration_api_ms"));
144920
144942
  } catch {
144921
144943
  }
144922
- const reply = this.activeReply;
144923
- if (this.currentReplyExpected && !this.saidThisTurn && this.turnText.trim()) {
144944
+ const reply = turn.reply;
144945
+ if (turn.replyExpected && !turn.said && turn.text.trim()) {
144924
144946
  if (reply) {
144925
- void reply(this.turnText);
144947
+ void reply(turn.text);
144926
144948
  } else {
144927
144949
  logLine(
144928
- `[drop-probe] BLOCKED at result: composed ${this.turnText.length} chars, reply expected but activeReply unset \u2014 reply DROPPED`
144950
+ `[drop-probe] BLOCKED at result: composed ${turn.text.length} chars, reply expected but no reply sink \u2014 reply DROPPED`
144929
144951
  );
144930
144952
  }
144931
144953
  }
144954
+ this.settled = this.turns.shift();
144932
144955
  }
144933
144956
  }
144934
144957
  } finally {
144935
- if (this.currentReplyExpected && !this.saidThisTurn && !this.sawResultThisTurn && this.turnText.trim()) {
144958
+ const turn = this.turn();
144959
+ if (turn.replyExpected && !turn.said && !turn.sawResult && turn.text.trim()) {
144936
144960
  logLine(
144937
- `[drop-probe] STREAM ENDED before result: composed ${this.turnText.length} chars, reply expected, said=false \u2014 reply DROPPED (no result event)`
144961
+ `[drop-probe] STREAM ENDED before result: composed ${turn.text.length} chars, reply expected, said=false \u2014 reply DROPPED (no result event)`
144938
144962
  );
144939
144963
  }
144940
144964
  }
144941
144965
  }
144966
+ /**
144967
+ * #1467: at a turn's result, report it when Claude refused it with a rate
144968
+ * limit WHILE the plan's status is rejected. A refusal with the plan allowed
144969
+ * is a short-term rate limit, not the plan's cap; a rejected status with no
144970
+ * refusal (extra usage, model fallback) was served. Never throws.
144971
+ */
144972
+ reportPlanLimitIfAny(turn) {
144973
+ if (!turn.refused || !this.planLimit.rejected) return;
144974
+ try {
144975
+ this.opts.onPlanLimit?.({ resetsAt: this.planLimit.resetsAt });
144976
+ } catch {
144977
+ }
144978
+ }
144942
144979
  };
144943
144980
 
144944
144981
  // src/worker-queue.ts
@@ -145495,6 +145532,19 @@ function reportSay(channel, t7, startedAt, failure3) {
145495
145532
  } catch {
145496
145533
  }
145497
145534
  }
145535
+ function reportPlanLimit(channel, resetsAt) {
145536
+ try {
145537
+ reportToolInvoke(channel.telemetry, {
145538
+ toolName: "model_turn",
145539
+ outcome: "error",
145540
+ errorKind: "plan_limit_reached",
145541
+ durationMs: 0,
145542
+ conversation: { kind: "unknown" },
145543
+ limitResetsAt: resetsAt
145544
+ });
145545
+ } catch {
145546
+ }
145547
+ }
145498
145548
  async function sendDm(channel, t7, text) {
145499
145549
  if ((t7.conversationId || t7.groupId) && typeof channel.runForConversation === "function") {
145500
145550
  await channel.runForConversation(
@@ -145899,7 +145949,7 @@ async function main() {
145899
145949
  "[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"
145900
145950
  );
145901
145951
  }
145902
- logLine(`[bridge] version: ${true ? "0.8.28" : "dev"}`);
145952
+ logLine(`[bridge] version: ${true ? "0.8.29" : "dev"}`);
145903
145953
  logLine(`[bridge] data dir: ${cfg.dataDir} (${cfg.dataDirSource})`);
145904
145954
  logLine(`[bridge] workspace: ${cfg.workspaceDir} \xB7 permissions: ${cfg.permissionMode} \xB7 enclave dir fenced`);
145905
145955
  if (cfg.armRoom) {
@@ -145931,7 +145981,7 @@ async function main() {
145931
145981
  // its default would render "@agentvault/agentvault@0.7.x" — the wrong
145932
145982
  // package name attached to the bridge's version number, which is worse
145933
145983
  // than either alone.
145934
- clientVersion: `@agentvault/claude-bridge@${true ? "0.8.28" : "dev"}`
145984
+ clientVersion: `@agentvault/claude-bridge@${true ? "0.8.29" : "dev"}`
145935
145985
  });
145936
145986
  const agentSystemPrompt = cfg.systemPrompt ?? identityPrompt(cfg.agentName);
145937
145987
  const deviceJwt = () => {
@@ -145956,9 +146006,14 @@ async function main() {
145956
146006
  });
145957
146007
  }
145958
146008
  };
146009
+ const onPlanLimit = ({ resetsAt }) => {
146010
+ reportPlanLimit(channel, resetsAt);
146011
+ logLine(`[bridge] Claude plan limit reached${resetsAt ? ` (resets at epoch ${resetsAt})` : ""}`);
146012
+ };
145959
146013
  const listener = new PersistentClaudeSession({
145960
146014
  model: cfg.model,
145961
146015
  onUsage: reportUsage,
146016
+ onPlanLimit,
145962
146017
  systemPrompt: agentSystemPrompt,
145963
146018
  // Claude speaks by calling the say tool → the session routes it to the reply
145964
146019
  // bound to the message being answered (wireBridge captures that per inbound via
@@ -145976,6 +146031,7 @@ async function main() {
145976
146031
  model: cfg.model,
145977
146032
  systemPrompt: agentSystemPrompt,
145978
146033
  onUsage: reportUsage,
146034
+ onPlanLimit,
145979
146035
  onObserve: (text) => logLine(`[worker] observed (${text.length} chars, not sent)`),
145980
146036
  worker: true,
145981
146037
  // Task 4: the hard backstop — no tool runs on any worker turn (owner DM or
package/dist/session.d.ts CHANGED
@@ -38,6 +38,8 @@ export type SDKUserMessage = {
38
38
  };
39
39
  parent_tool_use_id: string | null;
40
40
  session_id?: string;
41
+ /** SDK 0.2.141: when the CLI may take a queued prompt. #1508 sends "later". */
42
+ priority?: "now" | "next" | "later";
41
43
  };
42
44
  export type QueryFn = (args: {
43
45
  prompt: AsyncIterable<SDKUserMessage>;
@@ -105,59 +107,39 @@ export interface SessionOpts {
105
107
  * telemetry can never break a turn.
106
108
  */
107
109
  onUsage?: (usage: LlmUsage[], durationApiMs?: number) => void;
110
+ /**
111
+ * #1467: the owner's Claude plan refused this turn. Called at most once per
112
+ * turn, with the plan's reset time in whole epoch seconds when the SDK gave
113
+ * one. Fire-and-forget; a throw is swallowed.
114
+ */
115
+ onPlanLimit?: (info: {
116
+ resetsAt?: number;
117
+ }) => void;
108
118
  }
109
119
  export declare class PersistentClaudeSession {
110
120
  private opts;
111
121
  private waiting;
112
122
  private pending;
113
- /** Reply sink bound to the message currently being processed. Set as each
114
- * message is handed to the model so the say tool routes to the right place. */
115
- private activeReply?;
116
- /** Owner-DM attestation also enables its plain-text fallback. Room turns
117
- * carry separate sender authority and can never become DMs on disarm. */
118
- private currentAutoReply;
119
- private currentToolEligibleSender;
120
- private currentRoomReplyExpected;
121
- private currentHasRoomContext;
122
- /** Called per tool decision so a mid-turn room disarm takes effect live. */
123
- private currentArmedGetter;
124
- /** Effective prose fallback policy, including the separate owner-DM default. */
125
- private currentReplyExpected;
126
- /** #1180: whether the say tool may deliver on this turn. Rooms pass an explicit
127
- * `replyExpected` (#1107: no @ → nobody replies) and that decides it; a 1:1 DM
128
- * passes none and say stays allowed there. Distinct from `currentReplyExpected`,
129
- * which drives only the #416 prose fallback and is false for un-attested DMs. */
130
- private currentSayAllowed;
131
- private saidThisTurn;
132
- private turnText;
133
- /** #630 drop-probe: did a `result` event arrive for the CURRENT turn? Reset per
134
- * turn in input(), set in the result block. Distinguishes a turn that never
135
- * reached a result boundary (the silent-drop prime suspect) from a healthy
136
- * #416 fallback delivery (which delivers via `void reply(...)` WITHOUT setting
137
- * saidThisTurn, so !saidThisTurn alone would false-flag it). */
138
- private sawResultThisTurn;
139
123
  /**
140
- * Per-turn telemetry lifted off the SDK's `result` message.
141
- *
142
- * The message arrives on EVERY turn and we kept one boolean from it
143
- * (`sawResultThisTurn`), discarding the rest. That is the #791 shape: data
144
- * delivered on the healthy path that nothing reads.
145
- *
146
- * It costs us a real answer. A turn that produced nothing (`composed=0,
147
- * said=false`) could be the model choosing silence, the turn cap being hit, or
148
- * the provider returning 429 — three different bugs with one symptom, and
149
- * `subtype`/`apiErrorStatus` are what separate them. 4 of 12 turns on
150
- * 2026-08-07 were silent and could not be attributed.
151
- *
152
- * `durationApiMs` vs `durationMs` also gives the model-time / SDK-overhead
153
- * split directly. That split previously had to be reconstructed by joining
154
- * `WorkerIncident.ranMs` against SDK transcripts on disk by wall clock.
155
- *
156
- * Every field is OPTIONAL and left undefined when no result arrives (abort or
157
- * crash mid-turn): absent must read as absent, never as a zero that looks like
158
- * a real measurement.
124
+ * #1508: one entry per message the SDK has pulled, oldest first. The SDK
125
+ * reads queued prompts EAGERLY (measured: a second message is pulled 300 ms
126
+ * after the first, long before turn 1's output), yet answers them one turn
127
+ * and one `result` each, in order. So a turn's settings live with ITS
128
+ * message: input() appends, a `result` retires the head. Everything the
129
+ * running turn reads — reply target, owed/allowed rules, composed text —
130
+ * comes from the head (`turn()`), never from the newest message.
131
+ */
132
+ private turns;
133
+ /** The turn most recently retired. `turn()` falls back to it between turns,
134
+ * so a late say goes where it did before (the last message's reply). */
135
+ private settled;
136
+ /**
137
+ * #1467: the plan's limit status as the SDK last reported it. SESSION-level
138
+ * on purpose: the CLI emits `rate_limit_event` only when the status CHANGES
139
+ * (`if(!j$(V0,K))YT8(K)` in SDK 0.2.141), so every refused turn after the
140
+ * first arrives with no event of its own. Never reset per turn.
159
141
  */
160
- private resultTelemetry;
142
+ private planLimit;
161
143
  /** In-process room MCP server — hoisted so buildSdkOptions can reference it. */
162
144
  private roomServer;
163
145
  /** AbortController for the in-flight query(); abort() triggers it (queue timeout). */
@@ -189,6 +171,9 @@ export declare class PersistentClaudeSession {
189
171
  * back to opts.onSay. This is what closes the DM→room leak: the destination is
190
172
  * the one captured for the message being answered, not a live global target. */
191
173
  deliver(text: string): Promise<void>;
174
+ /** #1508: the turn now producing output — the oldest pulled message not yet
175
+ * answered — or, between turns, the one just answered. */
176
+ private turn;
192
177
  /** Abort the in-flight query() — used by the worker queue on a per-task timeout. */
193
178
  abort(): void;
194
179
  /**
@@ -223,5 +208,12 @@ export declare class PersistentClaudeSession {
223
208
  */
224
209
  private buildSdkOptions;
225
210
  start(): Promise<void>;
211
+ /**
212
+ * #1467: at a turn's result, report it when Claude refused it with a rate
213
+ * limit WHILE the plan's status is rejected. A refusal with the plan allowed
214
+ * is a short-term rate limit, not the plan's cap; a rejected status with no
215
+ * refusal (extra usage, model fallback) was served. Never throws.
216
+ */
217
+ private reportPlanLimitIfAny;
226
218
  }
227
219
  //# sourceMappingURL=session.d.ts.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agentvault/claude-bridge",
3
- "version": "0.8.28",
3
+ "version": "0.8.29",
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",