@oxagen/cli 3.0.1-791 → 3.0.1-792

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/oxagen.mjs +597 -139
  2. package/package.json +1 -1
package/oxagen.mjs CHANGED
@@ -5369,7 +5369,13 @@ var init_envelope = __esm({
5369
5369
  // (`assistant-session.ts` in @oxagen/agent), never a host. The body is
5370
5370
  // opaque on the wire. Its strict schema is `loopDetectedBodySchema` in
5371
5371
  // `loop-detected.ts`.
5372
- "oxagen:loop_detected": external_exports.object({}).catchall(json)
5372
+ "oxagen:loop_detected": external_exports.object({}).catchall(json),
5373
+ // The hook daemon told a wrapped agent, once, that it kept making the same
5374
+ // call and getting the same result (#8572): the loop's kind, the frame of
5375
+ // the call that brought it to where it starts, and the hook whose answer
5376
+ // carried the notice. The body is opaque on the wire. Its strict schema is
5377
+ // `loopNoticeBodySchema` in `collector/loop-notice.ts`.
5378
+ "oxagen:loop_notice": external_exports.object({}).catchall(json)
5373
5379
  };
5374
5380
  TACHO_KINDS = Object.keys(KIND_BODIES);
5375
5381
  agentIdentitySchema = external_exports.object({
@@ -14700,11 +14706,11 @@ function normalizeHook(raw, env, options) {
14700
14706
  }
14701
14707
  case "PostToolUse":
14702
14708
  case "PostToolUseFailure": {
14703
- const failed4 = input.hook_event_name === "PostToolUseFailure";
14709
+ const failed5 = input.hook_event_name === "PostToolUseFailure";
14704
14710
  const facts = toolFacts2(input, options.sessionUuid);
14705
14711
  const body2 = {
14706
14712
  ...facts,
14707
- tool_status: failed4 ? "error" : "ok",
14713
+ tool_status: failed5 ? "error" : "ok",
14708
14714
  ...input.duration_ms !== void 0 ? { tool_duration_ms: count(input.duration_ms) } : {}
14709
14715
  };
14710
14716
  if (input.tool_response !== void 0) {
@@ -14717,7 +14723,7 @@ function normalizeHook(raw, env, options) {
14717
14723
  body2["tool_result_tokens_basis"] = "estimated";
14718
14724
  }
14719
14725
  let errorText4;
14720
- if (failed4) {
14726
+ if (failed5) {
14721
14727
  const error2 = input.error ?? input["error_type"];
14722
14728
  if (error2 !== void 0) {
14723
14729
  errorText4 = typeof error2 === "string" ? error2 : JSON.stringify(error2);
@@ -14730,7 +14736,7 @@ function normalizeHook(raw, env, options) {
14730
14736
  const drafts = [
14731
14737
  draft("tool_call", body2, toolCallContent(input, errorText4))
14732
14738
  ];
14733
- const effectFrame = failed4 || facts["effect_id"] === void 0 ? void 0 : effectFrameKind(
14739
+ const effectFrame = failed5 || facts["effect_id"] === void 0 ? void 0 : effectFrameKind(
14734
14740
  facts["effect_kind"],
14735
14741
  facts["tool_source"]
14736
14742
  );
@@ -17676,11 +17682,11 @@ function completeCall(state, call2, exitCode, status2, mcpName) {
17676
17682
  function toolCallDraft(frame2, record2, ts2) {
17677
17683
  const output = frame2.output;
17678
17684
  const outputText = output === void 0 ? void 0 : jcs(output);
17679
- const failed4 = frame2.status !== void 0 || frame2.exitCode !== void 0 && frame2.exitCode !== 0;
17685
+ const failed5 = frame2.status !== void 0 || frame2.exitCode !== void 0 && frame2.exitCode !== 0;
17680
17686
  const body2 = {};
17681
17687
  if (frame2.name !== void 0) body2["tool_name"] = frame2.name;
17682
17688
  if (frame2.call !== void 0) body2["tool_use_id"] = frame2.call;
17683
- body2["tool_status"] = frame2.status === "declined" ? "rejected" : failed4 ? "error" : "ok";
17689
+ body2["tool_status"] = frame2.status === "declined" ? "rejected" : failed5 ? "error" : "ok";
17684
17690
  if (frame2.inputDigest !== void 0) {
17685
17691
  body2["tool_input_digest"] = frame2.inputDigest;
17686
17692
  body2["tool_input_bytes"] = frame2.inputBytes;
@@ -19967,18 +19973,18 @@ function normalizeTranscriptLine(line, fallbackTs, toolInputs) {
19967
19973
  if (s(item?.["type"]) !== "tool_result") continue;
19968
19974
  const toolUseResult = record2["toolUseResult"];
19969
19975
  const toolUseId = s(item?.["tool_use_id"]);
19970
- const failed4 = b(item?.["is_error"]) === true;
19976
+ const failed5 = b(item?.["is_error"]) === true;
19971
19977
  const held = toolUseId !== void 0 ? toolInputs?.take(toolUseId) : void 0;
19972
19978
  const input = held?.input;
19973
- const error2 = failed4 ? resultText(item?.["content"]) : void 0;
19974
- const output = toolUseResult ?? (failed4 ? void 0 : item?.["content"]);
19979
+ const error2 = failed5 ? resultText(item?.["content"]) : void 0;
19980
+ const output = toolUseResult ?? (failed5 ? void 0 : item?.["content"]);
19975
19981
  const exitCode = error2 !== void 0 ? exitCodeOfErrorText(error2) : void 0;
19976
19982
  drafts.push({
19977
19983
  ...draft(
19978
19984
  "tool_call",
19979
19985
  {
19980
19986
  ...defined({ tool_name: held?.name, tool_use_id: toolUseId }),
19981
- tool_status: failed4 ? "error" : "ok",
19987
+ tool_status: failed5 ? "error" : "ok",
19982
19988
  // The input's hash and size by the formula the hook uses, so
19983
19989
  // a call only the transcript recorded can be compared with
19984
19990
  // an identical call for loops and retries.
@@ -23719,14 +23725,14 @@ var init_transcript_tailer = __esm({
23719
23725
  cursor.agents = { ...cursor.agents, [subagentId]: sub };
23720
23726
  this.dirty = true;
23721
23727
  }
23722
- const { fed, failed: failed4 } = await this.advance(
23728
+ const { fed, failed: failed5 } = await this.advance(
23723
23729
  session,
23724
23730
  sub,
23725
23731
  Number.POSITIVE_INFINITY,
23726
23732
  IN_QUEUE,
23727
23733
  subagentId
23728
23734
  );
23729
- if (failed4) {
23735
+ if (failed5) {
23730
23736
  this.options.log?.(
23731
23737
  `subagent transcript ${sub.path} stays open after its SubagentStop: the read failed at ${sub.offset}`
23732
23738
  );
@@ -24083,9 +24089,9 @@ var init_transcript_tailer = __esm({
24083
24089
  return true;
24084
24090
  };
24085
24091
  const standsAt = (from) => applyStat() && sealer.current() && cursor.offset === from;
24086
- const done = async (failed4) => {
24092
+ const done = async (failed5) => {
24087
24093
  if (!statApplied) await sealer.run(applyStat);
24088
- return { fed, failed: failed4, bytes };
24094
+ return { fed, failed: failed5, bytes };
24089
24095
  };
24090
24096
  let remaining = budget;
24091
24097
  let offset = replaced ? 0 : at2;
@@ -28850,13 +28856,13 @@ async function issueStatic(harness, deps) {
28850
28856
  }
28851
28857
  async function restoreCredentials(host, deps, mode = "unenroll", only) {
28852
28858
  const restored = [];
28853
- const failed4 = [];
28859
+ const failed5 = [];
28854
28860
  const warnings = [];
28855
28861
  let custodyUnreadable = false;
28856
28862
  const contract = deps.modelCredentials;
28857
28863
  const store = deps.credentialStore;
28858
28864
  if (contract === void 0)
28859
- return { restored, failed: failed4, warnings, custodyUnreadable };
28865
+ return { restored, failed: failed5, warnings, custodyUnreadable };
28860
28866
  const helperCommand = deps.runtime.credentialHelperCommand;
28861
28867
  const heldElsewhere = harnessesHeldElsewhere(deps.paths, deps.paths.dir);
28862
28868
  for (const harness of MODEL_CREDENTIAL_HARNESSES) {
@@ -28888,7 +28894,7 @@ async function restoreCredentials(host, deps, mode = "unenroll", only) {
28888
28894
  if (unreadable !== void 0) {
28889
28895
  custodyUnreadable = true;
28890
28896
  if (mode === "passthrough") {
28891
- failed4.push(
28897
+ failed5.push(
28892
28898
  `the ${provider} credential in custody cannot be read (${unreadable}); ${label} keeps its run token until the store is fixed`
28893
28899
  );
28894
28900
  continue;
@@ -28925,10 +28931,10 @@ async function restoreCredentials(host, deps, mode = "unenroll", only) {
28925
28931
  }
28926
28932
  }
28927
28933
  } catch (error2) {
28928
- failed4.push(error2 instanceof Error ? error2.message : String(error2));
28934
+ failed5.push(error2 instanceof Error ? error2.message : String(error2));
28929
28935
  }
28930
28936
  }
28931
- return { restored, failed: failed4, warnings, custodyUnreadable };
28937
+ return { restored, failed: failed5, warnings, custodyUnreadable };
28932
28938
  }
28933
28939
  async function acquireSubscriptionToken(options, deps) {
28934
28940
  const io = deps.subscriptionLogin;
@@ -29909,7 +29915,7 @@ import { readFileSync as readFileSync10 } from "node:fs";
29909
29915
  import { dirname as dirname9, resolve as resolve3 } from "node:path";
29910
29916
  import { fileURLToPath } from "node:url";
29911
29917
  function readVersion() {
29912
- if (true) return "3.0.1-791";
29918
+ if (true) return "3.0.1-792";
29913
29919
  try {
29914
29920
  const here = dirname9(fileURLToPath(import.meta.url));
29915
29921
  const pkg = JSON.parse(
@@ -30228,10 +30234,10 @@ function claudeFacts(exec4, platform = process.platform, env = process.env, home
30228
30234
  }
30229
30235
  function settleOrThrow(harnessFiles) {
30230
30236
  const outcomes = harnessFiles.settle();
30231
- const failed4 = outcomes.filter((outcome) => outcome.result === "failed");
30232
- if (failed4.length > 0)
30237
+ const failed5 = outcomes.filter((outcome) => outcome.result === "failed");
30238
+ if (failed5.length > 0)
30233
30239
  throw new Error(
30234
- failed4.map((outcome) => `${outcome.path} ${outcome.reason}`).join("; ")
30240
+ failed5.map((outcome) => `${outcome.path} ${outcome.reason}`).join("; ")
30235
30241
  );
30236
30242
  return outcomes;
30237
30243
  }
@@ -30921,9 +30927,9 @@ async function untrustCodexHooks(options) {
30921
30927
  let problem;
30922
30928
  ours.forEach((hook, index) => {
30923
30929
  const answer = wrote.answers[index] ?? {};
30924
- const failed4 = answerProblem(answer, CONFIG_WRITE);
30925
- if (failed4 === void 0) removed.push(hook.key);
30926
- else problem ??= failed4;
30930
+ const failed5 = answerProblem(answer, CONFIG_WRITE);
30931
+ if (failed5 === void 0) removed.push(hook.key);
30932
+ else problem ??= failed5;
30927
30933
  });
30928
30934
  return problem === void 0 ? { removed } : { removed, problem };
30929
30935
  }
@@ -36020,8 +36026,8 @@ async function revokeAndMark(host, options, deps, warnings) {
36020
36026
  }
36021
36027
  async function restoreModelBaseUrlsFor(host, deps) {
36022
36028
  const restored = [];
36023
- const failed4 = [];
36024
- if (deps.modelBaseUrls === void 0) return { restored, failed: failed4 };
36029
+ const failed5 = [];
36030
+ if (deps.modelBaseUrls === void 0) return { restored, failed: failed5 };
36025
36031
  const stellaHome = dirname14(deps.paths.stellaToml);
36026
36032
  const heldElsewhere = harnessesHeldElsewhere(deps.paths, deps.paths.dir);
36027
36033
  for (const harness of MODEL_BASE_URL_HARNESSES) {
@@ -36050,10 +36056,10 @@ async function restoreModelBaseUrlsFor(host, deps) {
36050
36056
  for (const entry2 of state.harnesses)
36051
36057
  if (entry2.changed) restored.push(entry2.file);
36052
36058
  } catch (error2) {
36053
- failed4.push(error2 instanceof Error ? error2.message : String(error2));
36059
+ failed5.push(error2 instanceof Error ? error2.message : String(error2));
36054
36060
  }
36055
36061
  }
36056
- return { restored, failed: failed4 };
36062
+ return { restored, failed: failed5 };
36057
36063
  }
36058
36064
  async function disarmGateway(host, deps, warnings) {
36059
36065
  const credentials2 = await restoreCredentials(host, deps, "passthrough");
@@ -36087,13 +36093,13 @@ async function stopGateway(host, deps, warnings) {
36087
36093
  return true;
36088
36094
  }
36089
36095
  async function stripEnrollmentHooks(host, deps, settle4 = false) {
36090
- const failed4 = [];
36096
+ const failed5 = [];
36091
36097
  const attempt = (path2, run3) => {
36092
36098
  try {
36093
36099
  run3();
36094
36100
  } catch (error2) {
36095
36101
  const reason3 = error2 instanceof Error ? error2.message : String(error2);
36096
- failed4.push(reason3.includes(path2) ? reason3 : `${path2}: ${reason3}`);
36102
+ failed5.push(reason3.includes(path2) ? reason3 : `${path2}: ${reason3}`);
36097
36103
  }
36098
36104
  };
36099
36105
  const heldElsewhere = harnessesHeldElsewhere(deps.paths, deps.paths.dir);
@@ -36218,11 +36224,11 @@ async function stripEnrollmentHooks(host, deps, settle4 = false) {
36218
36224
  });
36219
36225
  });
36220
36226
  }
36221
- if (settle4 && failed4.length === 0) {
36227
+ if (settle4 && failed5.length === 0) {
36222
36228
  try {
36223
36229
  deps.settleHarnessFiles?.();
36224
36230
  } catch (error2) {
36225
- failed4.push(
36231
+ failed5.push(
36226
36232
  `restoring the original files: ${error2 instanceof Error ? error2.message : String(error2)}`
36227
36233
  );
36228
36234
  }
@@ -36237,7 +36243,7 @@ async function stripEnrollmentHooks(host, deps, settle4 = false) {
36237
36243
  ...stellaMcpChanged !== void 0 ? { stellaMcpChanged } : {},
36238
36244
  claudeDesktopChanged,
36239
36245
  ...claudeCodeMcpChanged !== void 0 ? { claudeCodeMcpChanged } : {},
36240
- failed: failed4
36246
+ failed: failed5
36241
36247
  };
36242
36248
  }
36243
36249
  async function unenroll(options, deps) {
@@ -36582,15 +36588,15 @@ async function unenrollLocked(options, deps) {
36582
36588
  ["pending session ends", deps.paths.pendingEnds, false]
36583
36589
  ];
36584
36590
  const purged = parts.filter(([, path2, recursive]) => remove2(path2, recursive)).map(([name2]) => name2);
36585
- let failed4 = purged.length < parts.length;
36591
+ let failed5 = purged.length < parts.length;
36586
36592
  if (!existsSync16(join24(deps.paths.dir, HARNESS_RECEIPTS)) && !remove2(join24(deps.paths.dir, HARNESS_BACKUPS), true))
36587
- failed4 = true;
36593
+ failed5 = true;
36588
36594
  const logShared = otherLiveAgents(deps.paths, deps.paths.dir).length > 0;
36589
36595
  if (!logShared) {
36590
36596
  if (remove2(deps.paths.log)) purged.push("the collector log");
36591
- else failed4 = true;
36597
+ else failed5 = true;
36592
36598
  }
36593
- const kept = failed4 ? "; the rest could not be removed" : "";
36599
+ const kept = failed5 ? "; the rest could not be removed" : "";
36594
36600
  if (purged.length > 0) deps.out(` ${listOf2(purged)} purged${kept}`);
36595
36601
  else deps.out(" nothing could be purged");
36596
36602
  if (logShared)
@@ -44606,9 +44612,9 @@ function createWorkOrderAutostart(deps) {
44606
44612
  );
44607
44613
  }
44608
44614
  async function endSend(id2, reason3) {
44609
- const failed4 = await refuseWorkOrder(deps.client, id2, reason3);
44615
+ const failed5 = await refuseWorkOrder(deps.client, id2, reason3);
44610
44616
  log(
44611
- failed4 === void 0 ? `work order ${id2} cannot start here and is removed: ${reason3}` : `work order ${id2} cannot start here and is removed: ${reason3} Oxagen was not told (${failed4}); a person can end the send in the app.`
44617
+ failed5 === void 0 ? `work order ${id2} cannot start here and is removed: ${reason3}` : `work order ${id2} cannot start here and is removed: ${reason3} Oxagen was not told (${failed5}); a person can end the send in the app.`
44612
44618
  );
44613
44619
  await abandon(id2);
44614
44620
  }
@@ -44767,9 +44773,9 @@ function createWorkOrderAutostart(deps) {
44767
44773
  if (sessions.has(id2)) return;
44768
44774
  const said = lastLogLine(logPath);
44769
44775
  const reason3 = `${binary} ${exitPhrase(exit)} before it opened a run.${said !== void 0 ? ` Its last output: ${said}` : ""} The full output is in ${logPath} on this machine.`;
44770
- const failed4 = await refuseWorkOrder(deps.client, id2, reason3.slice(0, 512));
44776
+ const failed5 = await refuseWorkOrder(deps.client, id2, reason3.slice(0, 512));
44771
44777
  log(
44772
- failed4 === void 0 ? `work order ${id2}: ${reason3} Oxagen ended the send.` : `work order ${id2}: ${reason3} Oxagen kept the send (${failed4}).`
44778
+ failed5 === void 0 ? `work order ${id2}: ${reason3} Oxagen ended the send.` : `work order ${id2}: ${reason3} Oxagen kept the send (${failed5}).`
44773
44779
  );
44774
44780
  }
44775
44781
  function watch2(id2, binary, workspace, exited) {
@@ -45240,10 +45246,10 @@ async function readPreexistingPaths(exec4, root, startedAtMs, copies) {
45240
45246
  );
45241
45247
  let room = copies === void 0 ? 0 : copies.capBytes - await copiedBytes(copies.dir);
45242
45248
  const planned = present.sort(byPath).map((file) => {
45243
- const hashed = !(file.found.kind === "file" && file.found.size > MAX_HASHED_FILE_BYTES);
45244
- const copied = copies !== void 0 && hashed && file.found.kind === "file" && file.found.size <= room;
45249
+ const hashed2 = !(file.found.kind === "file" && file.found.size > MAX_HASHED_FILE_BYTES);
45250
+ const copied = copies !== void 0 && hashed2 && file.found.kind === "file" && file.found.size <= room;
45245
45251
  if (copied) room -= file.found.size;
45246
- return { ...file, hashed, copied };
45252
+ return { ...file, hashed: hashed2, copied };
45247
45253
  });
45248
45254
  await pooled(
45249
45255
  planned.map((file) => async () => {
@@ -47147,7 +47153,137 @@ var init_subagent_meta = __esm({
47147
47153
  });
47148
47154
 
47149
47155
  // ../../packages/tacho/src/loops.ts
47150
- var LOOP_START;
47156
+ function isMcpTool(tool) {
47157
+ return tool.startsWith(MCP_TOOL_PREFIX) || tool.startsWith(CURSOR_MCP_TOOL_PREFIX);
47158
+ }
47159
+ function slotsOf(steps) {
47160
+ return steps.map((step) => "fileChanged" in step ? null : step);
47161
+ }
47162
+ function sameResult(a, b3) {
47163
+ return a.tool === b3.tool && a.inputHash === b3.inputHash && a.outputHash === b3.outputHash;
47164
+ }
47165
+ function sameFailure(a, b3) {
47166
+ return a.tool === b3.tool && a.inputHash === b3.inputHash && a.errorClass === b3.errorClass;
47167
+ }
47168
+ function hashed(c) {
47169
+ return c.inputHash !== "" && c.outputHash !== "";
47170
+ }
47171
+ function failed(c) {
47172
+ return c.inputHash !== "" && c.errorClass !== null && c.errorClass !== "";
47173
+ }
47174
+ function reaches(loop, length) {
47175
+ const calls = loop.positions.length;
47176
+ return "calls" in length ? calls >= length.calls : Math.floor(calls / loop.period) >= length.cycles;
47177
+ }
47178
+ function streaks(slots, kind, joins, matches2) {
47179
+ const out = [];
47180
+ let run3 = [];
47181
+ let positions = [];
47182
+ const close = () => {
47183
+ const first = run3[0];
47184
+ if (first !== void 0 && run3.length >= 2)
47185
+ out.push({ kind, positions, period: 1, tool: first.tool });
47186
+ run3 = [];
47187
+ positions = [];
47188
+ };
47189
+ slots.forEach((c, i2) => {
47190
+ if (c === null || !joins(c)) {
47191
+ close();
47192
+ return;
47193
+ }
47194
+ const last = run3.at(-1);
47195
+ if (last !== void 0 && !matches2(last, c)) close();
47196
+ run3.push(c);
47197
+ positions.push(i2);
47198
+ });
47199
+ close();
47200
+ return out;
47201
+ }
47202
+ function shortCycles(slots) {
47203
+ const out = [];
47204
+ const segments = [[]];
47205
+ slots.forEach((c, i2) => {
47206
+ if (c === null || !hashed(c)) segments.push([]);
47207
+ else segments.at(-1)?.push({ call: c, at: i2 });
47208
+ });
47209
+ for (const segment of segments) {
47210
+ const same = (k, period) => {
47211
+ const a = segment[k];
47212
+ const b3 = segment[k - period];
47213
+ return a !== void 0 && b3 !== void 0 && sameResult(a.call, b3.call);
47214
+ };
47215
+ for (let period = 2; period <= MAX_PERIOD; period += 1) {
47216
+ let k = period;
47217
+ while (k < segment.length) {
47218
+ if (!same(k, period)) {
47219
+ k += 1;
47220
+ continue;
47221
+ }
47222
+ const start = k - period;
47223
+ let end = k;
47224
+ while (same(end, period)) end += 1;
47225
+ const cycle2 = segment.slice(start, start + period).map((s2) => s2.call);
47226
+ const distinct = cycle2.every(
47227
+ (c, j) => cycle2.slice(j + 1).every((d) => !sameResult(c, d))
47228
+ );
47229
+ const first = cycle2[0];
47230
+ if (first !== void 0 && distinct && end - start >= 2 * period)
47231
+ out.push({
47232
+ kind: "short_cycle",
47233
+ positions: segment.slice(start, end).map((s2) => s2.at),
47234
+ period,
47235
+ tool: first.tool
47236
+ });
47237
+ k = end;
47238
+ }
47239
+ }
47240
+ }
47241
+ return out;
47242
+ }
47243
+ function stagnations(slots) {
47244
+ const out = [];
47245
+ const seen = /* @__PURE__ */ new Map();
47246
+ let run3 = [];
47247
+ let positions = [];
47248
+ const close = () => {
47249
+ const first = run3[0];
47250
+ const inputs = new Set(run3.map((c) => c.inputHash));
47251
+ if (first !== void 0 && run3.length >= 2 && inputs.size >= 2)
47252
+ out.push({ kind: "stagnation", positions, period: 1, tool: first.tool });
47253
+ run3 = [];
47254
+ positions = [];
47255
+ };
47256
+ slots.forEach((c, i2) => {
47257
+ if (c === null || !hashed(c)) {
47258
+ close();
47259
+ return;
47260
+ }
47261
+ const outputs = seen.get(c.tool) ?? /* @__PURE__ */ new Set();
47262
+ const repeated = outputs.has(c.outputHash);
47263
+ outputs.add(c.outputHash);
47264
+ seen.set(c.tool, outputs);
47265
+ if (c.mayWrite || isMcpTool(c.tool)) {
47266
+ close();
47267
+ return;
47268
+ }
47269
+ const first = run3[0];
47270
+ if (first !== void 0 && (first.tool !== c.tool || !repeated)) close();
47271
+ run3.push(c);
47272
+ positions.push(i2);
47273
+ });
47274
+ close();
47275
+ return out;
47276
+ }
47277
+ function findLoops(steps, threshold) {
47278
+ const slots = slotsOf(steps);
47279
+ return [
47280
+ ...streaks(slots, "exact_repeat", hashed, sameResult),
47281
+ ...streaks(slots, "failing_retry", failed, sameFailure),
47282
+ ...shortCycles(slots),
47283
+ ...stagnations(slots)
47284
+ ].filter((loop) => reaches(loop, threshold[loop.kind])).sort((a, b3) => (a.positions[0] ?? 0) - (b3.positions[0] ?? 0));
47285
+ }
47286
+ var LOOP_START, MAX_PERIOD, MCP_TOOL_PREFIX, CURSOR_MCP_TOOL_PREFIX;
47151
47287
  var init_loops = __esm({
47152
47288
  "../../packages/tacho/src/loops.ts"() {
47153
47289
  "use strict";
@@ -47157,6 +47293,9 @@ var init_loops = __esm({
47157
47293
  short_cycle: { cycles: 3 },
47158
47294
  stagnation: { calls: 6 }
47159
47295
  };
47296
+ MAX_PERIOD = 3;
47297
+ MCP_TOOL_PREFIX = "mcp__";
47298
+ CURSOR_MCP_TOOL_PREFIX = "MCP:";
47160
47299
  }
47161
47300
  });
47162
47301
 
@@ -47407,6 +47546,203 @@ var init_reflection_ask = __esm({
47407
47546
  }
47408
47547
  });
47409
47548
 
47549
+ // ../../packages/tacho/src/collector/loop-notice.ts
47550
+ function chainOf(record2, chain) {
47551
+ let chains = states2.get(record2);
47552
+ if (chains === void 0) {
47553
+ chains = /* @__PURE__ */ new Map();
47554
+ states2.set(record2, chains);
47555
+ }
47556
+ const state = chains.get(chain) ?? {
47557
+ calls: [],
47558
+ noticed: /* @__PURE__ */ new Set(),
47559
+ held: void 0
47560
+ };
47561
+ chains.delete(chain);
47562
+ chains.set(chain, state);
47563
+ for (const oldest of chains.keys()) {
47564
+ if (chains.size <= LOOP_CHAINS_PER_SESSION) break;
47565
+ chains.delete(oldest);
47566
+ }
47567
+ return state;
47568
+ }
47569
+ function isNoticed(kind) {
47570
+ return NOTICED_LOOP_KINDS.some((noticed) => noticed === kind);
47571
+ }
47572
+ function callId(call2) {
47573
+ return `${call2.tool}\0${call2.inputHash}`;
47574
+ }
47575
+ function loopKey(loop, calls) {
47576
+ const at2 = (i2) => i2 === void 0 ? void 0 : calls[i2];
47577
+ const first = at2(loop.positions[0]);
47578
+ if (first === void 0) return loop.kind;
47579
+ if (loop.kind === "stagnation") return `stagnation${first.tool}`;
47580
+ if (loop.kind === "short_cycle") {
47581
+ const cycle2 = loop.positions.slice(0, loop.period).map((i2) => at2(i2)).filter((c) => c !== void 0).map(callId).sort();
47582
+ return `short_cycle${cycle2.join("")}`;
47583
+ }
47584
+ return `${loop.kind}${callId(first)}`;
47585
+ }
47586
+ function noticeOf(loop, calls, key, also) {
47587
+ const last = calls[calls.length - 1];
47588
+ const length = loop.positions.length;
47589
+ const next = calls[calls.length - loop.period];
47590
+ const labels = loop.positions.slice(0, loop.kind === "short_cycle" ? loop.period : 1).map((i2) => calls[i2]?.label).filter((label) => label !== void 0);
47591
+ return {
47592
+ kind: loop.kind,
47593
+ key,
47594
+ also,
47595
+ tool: loop.tool,
47596
+ labels: labels.length > 0 ? labels : [loop.tool],
47597
+ repeats: loop.kind === "short_cycle" ? Math.floor(length / loop.period) : length,
47598
+ callSeq: last?.seq,
47599
+ next: {
47600
+ tool: next?.tool ?? loop.tool,
47601
+ inputHash: loop.kind === "stagnation" ? null : next?.inputHash ?? null
47602
+ }
47603
+ };
47604
+ }
47605
+ function noteLoopCall(record2, chain, call2) {
47606
+ const state = chainOf(record2, chain);
47607
+ state.calls.push(call2);
47608
+ if (state.calls.length > LOOP_WINDOW_CALLS)
47609
+ state.calls.splice(0, state.calls.length - LOOP_WINDOW_CALLS);
47610
+ const newest = state.calls.length - 1;
47611
+ const live = findLoops(state.calls, LOOP_START).filter(
47612
+ (loop) => isNoticed(loop.kind) && loop.positions.at(-1) === newest
47613
+ ).sort(
47614
+ (a, b3) => NOTICED_LOOP_KINDS.indexOf(a.kind) - NOTICED_LOOP_KINDS.indexOf(b3.kind)
47615
+ );
47616
+ const keys = live.map((loop) => loopKey(loop, state.calls));
47617
+ for (const [i2, loop] of live.entries()) {
47618
+ const key = keys[i2];
47619
+ if (key === void 0 || state.noticed.has(key)) continue;
47620
+ return noticeOf(
47621
+ loop,
47622
+ state.calls,
47623
+ key,
47624
+ keys.filter((other) => other !== key)
47625
+ );
47626
+ }
47627
+ return void 0;
47628
+ }
47629
+ function markLoopNoticed(record2, chain, notice) {
47630
+ const { noticed } = chainOf(record2, chain);
47631
+ for (const key of [notice.key, ...notice.also]) noticed.add(key);
47632
+ for (const oldest of noticed) {
47633
+ if (noticed.size <= NOTICED_PER_CHAIN) break;
47634
+ noticed.delete(oldest);
47635
+ }
47636
+ }
47637
+ function holdLoopNotice(record2, chain, notice) {
47638
+ if (notice.next.inputHash === null) return;
47639
+ chainOf(record2, chain).held = notice;
47640
+ }
47641
+ function takeHeldLoopNotice(record2, chain) {
47642
+ const chains = states2.get(record2);
47643
+ const state = chains?.get(chain);
47644
+ if (state === void 0) return void 0;
47645
+ const held = state.held;
47646
+ state.held = void 0;
47647
+ return held;
47648
+ }
47649
+ function nextCallRepeats(notice, tool, inputHash) {
47650
+ return tool === notice.next.tool && notice.next.inputHash !== null && inputHash === notice.next.inputHash;
47651
+ }
47652
+ function endLoopWindow(record2, chain) {
47653
+ const state = states2.get(record2)?.get(chain);
47654
+ if (state === void 0) return;
47655
+ state.calls = [];
47656
+ state.held = void 0;
47657
+ }
47658
+ function forgetLoopNotices(record2) {
47659
+ states2.delete(record2);
47660
+ }
47661
+ function loopCallFrom(body2, seq2, label) {
47662
+ const text6 = (key) => {
47663
+ const value = body2[key];
47664
+ return typeof value === "string" ? value : "";
47665
+ };
47666
+ const status2 = text6("tool_status");
47667
+ const failed5 = status2 === "error" || status2 === "rejected";
47668
+ const errorClass2 = text6("tool_error_class");
47669
+ const tool = text6("tool_name");
47670
+ const output = text6("tool_output_digest");
47671
+ return {
47672
+ tool,
47673
+ inputHash: text6("tool_input_digest"),
47674
+ outputHash: output === "" && failed5 ? text6("tool_error_message_digest") : output,
47675
+ errorClass: failed5 && errorClass2 !== "" ? errorClass2 : null,
47676
+ mayWrite: body2["tool_is_mutating"] !== false,
47677
+ seq: seq2,
47678
+ label: label ?? tool
47679
+ };
47680
+ }
47681
+ function clipTool2(name2) {
47682
+ return name2.length > TOOL_NAME_MAX_CHARS2 ? `${name2.slice(0, TOOL_NAME_MAX_CHARS2 - 3)}...` : name2;
47683
+ }
47684
+ function inOrder(tools) {
47685
+ const last = tools.at(-1) ?? "";
47686
+ if (tools.length <= 1) return last;
47687
+ const rest = tools.slice(0, -1).join(", ");
47688
+ return tools.length === 2 ? `${rest} then ${last}` : `${rest}, then ${last}`;
47689
+ }
47690
+ function loopNoticeText(notice) {
47691
+ const tools = notice.labels.map(clipTool2);
47692
+ const tool = tools[0] ?? clipTool2(notice.tool);
47693
+ if (notice.kind === "stagnation")
47694
+ return `Oxagen: you ran ${tool} ${notice.repeats} times with different inputs and got only results it had already returned. Change the approach before you run it again.`;
47695
+ if (notice.kind === "short_cycle")
47696
+ return `Oxagen: you ran ${inOrder(tools)} with the same inputs ${notice.repeats} times and got the same results each time. Change the input or the approach before you run them again.`;
47697
+ return `Oxagen: you ran ${tool} with the same input ${notice.repeats} times and got the same result each time. Change the input or the approach before you run it again.`;
47698
+ }
47699
+ function loopNoticeBody(notice, boundary) {
47700
+ return {
47701
+ loop_kind: notice.kind,
47702
+ repeats: notice.repeats,
47703
+ tool_name: clipTool2(notice.tool),
47704
+ boundary,
47705
+ ...notice.callSeq !== void 0 ? { call_seq: notice.callSeq } : {}
47706
+ };
47707
+ }
47708
+ var NOTICED_LOOP_KINDS, LOOP_NOTICE_BOUNDARIES, LOOP_NOTICE_REASON_CODE, LOOP_REFUSAL_LEAD, LOOP_WINDOW_CALLS, LOOP_CHAINS_PER_SESSION, NOTICED_PER_CHAIN, TOOL_NAME_MAX_CHARS2, ROOT_CHAIN, states2, loopNoticeBodySchema;
47709
+ var init_loop_notice = __esm({
47710
+ "../../packages/tacho/src/collector/loop-notice.ts"() {
47711
+ "use strict";
47712
+ init_zod();
47713
+ init_loops();
47714
+ NOTICED_LOOP_KINDS = [
47715
+ "exact_repeat",
47716
+ "short_cycle",
47717
+ "stagnation"
47718
+ ];
47719
+ LOOP_NOTICE_BOUNDARIES = [
47720
+ "PostToolUse",
47721
+ "PostToolUseFailure",
47722
+ "PreToolUse"
47723
+ ];
47724
+ LOOP_NOTICE_REASON_CODE = "loop_notice";
47725
+ LOOP_REFUSAL_LEAD = "This call did not run. ";
47726
+ LOOP_WINDOW_CALLS = 32;
47727
+ LOOP_CHAINS_PER_SESSION = 16;
47728
+ NOTICED_PER_CHAIN = 64;
47729
+ TOOL_NAME_MAX_CHARS2 = 64;
47730
+ ROOT_CHAIN = "";
47731
+ states2 = /* @__PURE__ */ new WeakMap();
47732
+ loopNoticeBodySchema = external_exports.object({
47733
+ loop_kind: external_exports.enum(NOTICED_LOOP_KINDS),
47734
+ /** Calls for an exact repeat or a stagnation, full cycles for a short cycle. */
47735
+ repeats: external_exports.number().int().min(0).max(Number.MAX_SAFE_INTEGER),
47736
+ /** The tool of the loop's first call, clipped as the notice prints it. */
47737
+ tool_name: external_exports.string().max(TOOL_NAME_MAX_CHARS2),
47738
+ /** The hook whose answer carried the notice to the agent. */
47739
+ boundary: external_exports.enum(LOOP_NOTICE_BOUNDARIES),
47740
+ /** The frame of the call that brought the loop to where it starts. Absent when the hook recorded no frame for it. */
47741
+ call_seq: external_exports.number().int().min(0).max(Number.MAX_SAFE_INTEGER).optional()
47742
+ }).strict();
47743
+ }
47744
+ });
47745
+
47410
47746
  // ../../packages/tacho/src/interjection.ts
47411
47747
  var digest4, timestamp, count5, configVersion, workspaceSlug, interjectionKeySchema, INTERJECTION_RECEIPT_ID_PATTERN, INTERJECTION_QUESTION_MAX, INTERJECTION_PATHS, INTERJECTION_ANSWER_SOURCES, SKILLS_RESOLVED_REASONS, repoUnknownBodySchema, interjectLinkPathSchema, interjectCreatePathSchema, INTERJECT_PROVIDERS, interjectBodySchema, answerBodySchema, repoBoundBodySchema, workspaceCreatedBodySchema, skillsResolvedBodySchema, interjectionAnswerPayloadSchema;
47412
47748
  var init_interjection = __esm({
@@ -47784,7 +48120,7 @@ function recalledToolName(seen) {
47784
48120
  }
47785
48121
  function noteRecallHints(record2, toolName4, toolInput2) {
47786
48122
  const hints = hintsOf(record2);
47787
- if (toolName4 !== void 0 && toolName4.length > 0 && toolName4.length <= TOOL_NAME_MAX_CHARS2)
48123
+ if (toolName4 !== void 0 && toolName4.length > 0 && toolName4.length <= TOOL_NAME_MAX_CHARS3)
47788
48124
  hints.tools = inFront(
47789
48125
  hints.tools,
47790
48126
  recalledToolName(toolName4),
@@ -47862,13 +48198,13 @@ function recallScope(record2) {
47862
48198
  function forgetRecallHints(record2) {
47863
48199
  delete record2.recallHints;
47864
48200
  }
47865
- var RECALL_TOOLS_KEPT, RECALL_PATHS_KEPT, TOOL_NAME_MAX_CHARS2, PATH_MAX_CHARS, PATH_KEYS, MCP_PREFIX3, REPOSITORY_RETRY_FIRST_MS, REPOSITORY_RETRY_MAX_MS;
48201
+ var RECALL_TOOLS_KEPT, RECALL_PATHS_KEPT, TOOL_NAME_MAX_CHARS3, PATH_MAX_CHARS, PATH_KEYS, MCP_PREFIX3, REPOSITORY_RETRY_FIRST_MS, REPOSITORY_RETRY_MAX_MS;
47866
48202
  var init_recall_hints = __esm({
47867
48203
  "../../packages/tacho/src/collector/recall-hints.ts"() {
47868
48204
  "use strict";
47869
48205
  RECALL_TOOLS_KEPT = 32;
47870
48206
  RECALL_PATHS_KEPT = 64;
47871
- TOOL_NAME_MAX_CHARS2 = 200;
48207
+ TOOL_NAME_MAX_CHARS3 = 200;
47872
48208
  PATH_MAX_CHARS = 512;
47873
48209
  PATH_KEYS = ["file_path", "path", "notebook_path"];
47874
48210
  MCP_PREFIX3 = "mcp__";
@@ -48164,6 +48500,89 @@ function drainMidTurn(input, record2, deps, events, replay, used = 0) {
48164
48500
  if (continuation !== void 0) texts.push(continuation);
48165
48501
  return texts;
48166
48502
  }
48503
+ function loopChainOf(input) {
48504
+ return input.agent_id ?? ROOT_CHAIN;
48505
+ }
48506
+ function subagentOf(input) {
48507
+ if (input.agent_id === void 0) return void 0;
48508
+ return {
48509
+ subagent_id: input.agent_id,
48510
+ ...input.agent_type !== void 0 ? { subagent_type: input.agent_type } : {}
48511
+ };
48512
+ }
48513
+ function loopNoticeStep(deps, step, run3) {
48514
+ try {
48515
+ return run3();
48516
+ } catch (error2) {
48517
+ deps.log?.(
48518
+ `loop notice: could not ${step}, so the hook answers without it: ${error2 instanceof Error ? error2.message : String(error2)}`
48519
+ );
48520
+ return void 0;
48521
+ }
48522
+ }
48523
+ function noteFinishedCall(input, record2, payload, env, sealed) {
48524
+ if (record2.harness === "stella" || input.tool_name === void 0)
48525
+ return void 0;
48526
+ const frame2 = sealed.find((event) => event.kind === "tool_call");
48527
+ const body2 = frame2 !== void 0 && isRecord(frame2.body) ? frame2.body : normalizeHook(payload, env, {
48528
+ sessionUuid: record2.recorder.sessionUuid
48529
+ }).find((draft) => draft.kind === "tool_call")?.body;
48530
+ if (body2 === void 0) return void 0;
48531
+ return noteLoopCall(
48532
+ record2,
48533
+ loopChainOf(input),
48534
+ loopCallFrom(body2, frame2?.seq, harnessToolNameOf(input))
48535
+ );
48536
+ }
48537
+ function sealLoopNotice(record2, input, notice, boundary, at2) {
48538
+ return record2.recorder.sealCollectorEventOn(
48539
+ subagentOf(input),
48540
+ void 0,
48541
+ "oxagen:loop_notice",
48542
+ loopNoticeBody(notice, boundary),
48543
+ { ts: at2, hook_event_name: input.hook_event_name }
48544
+ );
48545
+ }
48546
+ function sendLoopNotice(input, record2, deps, events, replay, notice, at2) {
48547
+ if (notice === void 0 || replay !== void 0) return void 0;
48548
+ const boundary = input.hook_event_name;
48549
+ if (boundary !== "PostToolUse" && boundary !== "PostToolUseFailure")
48550
+ return void 0;
48551
+ if (!deliversMessages(record2.harness, boundary)) {
48552
+ if (record2.harness === "cursor")
48553
+ holdLoopNotice(record2, loopChainOf(input), notice);
48554
+ return void 0;
48555
+ }
48556
+ if (!answerInTime(deps, deps.now())) return void 0;
48557
+ events.push(...sealLoopNotice(record2, input, notice, boundary, at2));
48558
+ markLoopNoticed(record2, loopChainOf(input), notice);
48559
+ return loopNoticeText(notice);
48560
+ }
48561
+ function loopRefusal(input, record2, deps, events, replay, evaluation, call2, at2) {
48562
+ const chain = loopChainOf(input);
48563
+ const held = takeHeldLoopNotice(record2, chain);
48564
+ const tool = call2?.["tool_name"];
48565
+ const inputHash = call2?.["tool_input_digest"];
48566
+ if (held === void 0 || replay !== void 0 || evaluation.decision === "deny" || typeof tool !== "string" || !nextCallRepeats(
48567
+ held,
48568
+ tool,
48569
+ typeof inputHash === "string" ? inputHash : void 0
48570
+ ) || !answerInTime(deps, deps.now()))
48571
+ return void 0;
48572
+ events.push(...sealLoopNotice(record2, input, held, "PreToolUse", at2));
48573
+ markLoopNoticed(record2, chain, held);
48574
+ const refused2 = {
48575
+ ...evaluation,
48576
+ decision: "deny",
48577
+ evaluated: "deny",
48578
+ source: "bundle",
48579
+ reason_code: LOOP_NOTICE_REASON_CODE,
48580
+ reason: `${LOOP_REFUSAL_LEAD}${loopNoticeText(held)}`
48581
+ };
48582
+ delete refused2.rule;
48583
+ delete refused2.rules;
48584
+ return refused2;
48585
+ }
48167
48586
  function noteHandedContext(record2, input, replay, text6, at2) {
48168
48587
  if (replay !== void 0 || input.agent_id !== void 0) return;
48169
48588
  if (text6.length === 0) return;
@@ -48671,7 +49090,10 @@ async function routeHook(raw, env, deps, replay, harness, agent, hookId) {
48671
49090
  ) : void 0;
48672
49091
  if (block === void 0 && input.agent_id === void 0)
48673
49092
  record2.control.resumeOwed = void 0;
48674
- if (block === void 0) notePrompt(record2, promptText(input));
49093
+ if (block === void 0) {
49094
+ notePrompt(record2, promptText(input));
49095
+ endLoopWindow(record2, loopChainOf(input));
49096
+ }
48675
49097
  const handed = [
48676
49098
  ...delivered,
48677
49099
  ...recalled !== void 0 ? [recalled.text] : []
@@ -48767,10 +49189,6 @@ async function routeHook(raw, env, deps, replay, harness, agent, hookId) {
48767
49189
  };
48768
49190
  }
48769
49191
  }
48770
- if (evaluation.decision === "deny" && evaluation.source !== "human" && evaluation.reason_code !== INTERJECTION_OPEN)
48771
- notePolicyDenial(record2, toolName4);
48772
- const facts = policyFacts2(evaluation, currentView);
48773
- const attrs2 = policyAttrs(evaluation, replay);
48774
49192
  const toolDrafts = normalizeHook(payload, env, {
48775
49193
  sessionUuid: record2.recorder.sessionUuid
48776
49194
  });
@@ -48778,6 +49196,24 @@ async function routeHook(raw, env, deps, replay, harness, agent, hookId) {
48778
49196
  (draft) => draft.kind === "tool_requested"
48779
49197
  );
48780
49198
  const toolBody = toolDraft?.body ?? {};
49199
+ evaluation = loopNoticeStep(
49200
+ deps,
49201
+ "refuse the repeated call",
49202
+ () => loopRefusal(
49203
+ input,
49204
+ record2,
49205
+ deps,
49206
+ events,
49207
+ replay,
49208
+ evaluation,
49209
+ toolDraft?.body,
49210
+ at2
49211
+ )
49212
+ ) ?? evaluation;
49213
+ if (evaluation.decision === "deny" && evaluation.source !== "human" && evaluation.reason_code !== INTERJECTION_OPEN && evaluation.reason_code !== LOOP_NOTICE_REASON_CODE)
49214
+ notePolicyDenial(record2, toolName4);
49215
+ const facts = policyFacts2(evaluation, currentView);
49216
+ const attrs2 = policyAttrs(evaluation, replay);
48781
49217
  events.push(
48782
49218
  ...record2.recorder.sealCollectorEventOn(
48783
49219
  toolDraft?.subagent,
@@ -48903,7 +49339,13 @@ async function routeHook(raw, env, deps, replay, harness, agent, hookId) {
48903
49339
  }
48904
49340
  case "PostToolUse":
48905
49341
  case "PostToolUseFailure": {
48906
- events.push(...record2.recorder.ingestHook(payload, env, at2, withReplay));
49342
+ const sealed = record2.recorder.ingestHook(payload, env, at2, withReplay);
49343
+ events.push(...sealed);
49344
+ const loop = loopNoticeStep(
49345
+ deps,
49346
+ "note the call",
49347
+ () => noteFinishedCall(input, record2, payload, env, sealed)
49348
+ );
48907
49349
  if (view.bundle.cedar !== void 0 && input.tool_name !== void 0)
48908
49350
  notePolicyRunCall(record2, {
48909
49351
  cedar: view.bundle.cedar,
@@ -48929,7 +49371,15 @@ async function routeHook(raw, env, deps, replay, harness, agent, hookId) {
48929
49371
  }
48930
49372
  if (operatorBlock(view, record2) !== void 0)
48931
49373
  return { events, response: {}, record: record2 };
48932
- const texts = drainMidTurn(input, record2, deps, events, replay);
49374
+ const notice = loopNoticeStep(
49375
+ deps,
49376
+ "send the notice",
49377
+ () => sendLoopNotice(input, record2, deps, events, replay, loop, at2)
49378
+ );
49379
+ const texts = [
49380
+ ...drainMidTurn(input, record2, deps, events, replay, notice?.length),
49381
+ ...notice !== void 0 ? [notice] : []
49382
+ ];
48933
49383
  noteHandedContext(record2, input, replay, texts.join(CONTEXT_JOINER), at2);
48934
49384
  return {
48935
49385
  events,
@@ -48945,6 +49395,11 @@ async function routeHook(raw, env, deps, replay, harness, agent, hookId) {
48945
49395
  case "Stop":
48946
49396
  case "StopFailure": {
48947
49397
  events.push(...record2.recorder.ingestHook(payload, env, at2, withReplay));
49398
+ loopNoticeStep(
49399
+ deps,
49400
+ "drop the held notice",
49401
+ () => takeHeldLoopNotice(record2, loopChainOf(input))
49402
+ );
48948
49403
  const block = operatorBlock(view, record2);
48949
49404
  if (block !== void 0) {
48950
49405
  if (block.code === "session_paused" && replay === void 0)
@@ -48981,6 +49436,7 @@ async function routeHook(raw, env, deps, replay, harness, agent, hookId) {
48981
49436
  deps.registry.seal(record2);
48982
49437
  forgetRecallHints(record2);
48983
49438
  forgetPolicyRun(record2);
49439
+ forgetLoopNotices(record2);
48984
49440
  const harness2 = skillsHarness(record2);
48985
49441
  if (deps.skills !== void 0 && harness2 !== void 0)
48986
49442
  await deps.skills.remove(harness2, record2.harnessSessionId, env);
@@ -49085,6 +49541,7 @@ var init_hook_handler = __esm({
49085
49541
  init_inventory();
49086
49542
  init_subagent_meta();
49087
49543
  init_reflection_ask();
49544
+ init_loop_notice();
49088
49545
  init_interjection2();
49089
49546
  init_recall_hints();
49090
49547
  init_policy_run();
@@ -50614,7 +51071,7 @@ function fileStateStorage(path2, unparsed) {
50614
51071
  save: (json2) => writeSensitiveFileAtomic(path2, json2)
50615
51072
  };
50616
51073
  }
50617
- function stateSaver(storage, failed4) {
51074
+ function stateSaver(storage, failed5) {
50618
51075
  let lastFailure;
50619
51076
  return (json2) => {
50620
51077
  try {
@@ -50624,7 +51081,7 @@ function stateSaver(storage, failed4) {
50624
51081
  const detail = error2 instanceof Error ? error2.message : String(error2);
50625
51082
  if (detail === lastFailure) return;
50626
51083
  lastFailure = detail;
50627
- failed4(detail);
51084
+ failed5(detail);
50628
51085
  }
50629
51086
  };
50630
51087
  }
@@ -51604,7 +52061,7 @@ function createMemoryRecall(deps) {
51604
52061
  `memory recall: ${detail}; prompts go on without recalled memories`
51605
52062
  )
51606
52063
  );
51607
- function failed4(detail) {
52064
+ function failed5(detail) {
51608
52065
  failures.failed(detail);
51609
52066
  return [];
51610
52067
  }
@@ -51640,7 +52097,7 @@ function createMemoryRecall(deps) {
51640
52097
  );
51641
52098
  } catch (error2) {
51642
52099
  if (signal.aborted) return [];
51643
- return failed4(`the control plane is unreachable (${reason2(error2)})`);
52100
+ return failed5(`the control plane is unreachable (${reason2(error2)})`);
51644
52101
  }
51645
52102
  if (signal.aborted) return [];
51646
52103
  if (answer.status === 404) {
@@ -51654,16 +52111,16 @@ function createMemoryRecall(deps) {
51654
52111
  return [];
51655
52112
  }
51656
52113
  if (!answer.ok)
51657
- return failed4(`the control plane answered ${answer.status}`);
52114
+ return failed5(`the control plane answered ${answer.status}`);
51658
52115
  let json2;
51659
52116
  try {
51660
52117
  json2 = JSON.parse(answer.text);
51661
52118
  } catch {
51662
- return failed4("the control plane's answer is not JSON");
52119
+ return failed5("the control plane's answer is not JSON");
51663
52120
  }
51664
52121
  const parsed2 = recallAnswerSchema.safeParse(json2);
51665
52122
  if (!parsed2.success)
51666
- return failed4("the control plane's answer is not a list of memories");
52123
+ return failed5("the control plane's answer is not a list of memories");
51667
52124
  failures.clear();
51668
52125
  return parsed2.data.items.map(({ id: id2, statement }) => ({ id: id2, statement }));
51669
52126
  }
@@ -51675,7 +52132,7 @@ function createMemoryRecall(deps) {
51675
52132
  timer = setTimeout(() => {
51676
52133
  controller.abort();
51677
52134
  resolve29(
51678
- failed4(
52135
+ failed5(
51679
52136
  `the control plane took longer than ${timeoutMs} ms to answer`
51680
52137
  )
51681
52138
  );
@@ -51683,7 +52140,7 @@ function createMemoryRecall(deps) {
51683
52140
  });
51684
52141
  try {
51685
52142
  const answered = ask(request3, controller.signal).catch(
51686
- (error2) => failed4(`the ask failed (${reason2(error2)})`)
52143
+ (error2) => failed5(`the ask failed (${reason2(error2)})`)
51687
52144
  );
51688
52145
  return await Promise.race([answered, timedOut]);
51689
52146
  } finally {
@@ -51841,11 +52298,11 @@ var init_memory_write = __esm({
51841
52298
  import { watch as fsWatch } from "node:fs";
51842
52299
  import { stat as fsStat } from "node:fs/promises";
51843
52300
  import { basename as basename8, dirname as dirname25 } from "node:path";
51844
- function nodeFolderWatch(folder, changed, failed4) {
52301
+ function nodeFolderWatch(folder, changed, failed5) {
51845
52302
  const watcher = fsWatch(folder, { persistent: false }, (_event, name2) => {
51846
52303
  changed(typeof name2 === "string" ? name2 : void 0);
51847
52304
  });
51848
- watcher.on("error", failed4);
52305
+ watcher.on("error", failed5);
51849
52306
  return { close: () => watcher.close() };
51850
52307
  }
51851
52308
  async function nodeStoreFileStat(path2) {
@@ -53154,7 +53611,7 @@ function linkError(refusal, detail) {
53154
53611
  function unreachable(detail) {
53155
53612
  return linkError(cloudUnreachable(), detail);
53156
53613
  }
53157
- function failed(error2, limit, signal) {
53614
+ function failed2(error2, limit, signal) {
53158
53615
  return limit.aborted && signal?.aborted !== true ? new CloudLinkTimeout(errorText2(error2)) : unreachable(errorText2(error2));
53159
53616
  }
53160
53617
  function statusRefusal(status2) {
@@ -53184,7 +53641,7 @@ function createCloudLink(options) {
53184
53641
  signal: signal === void 0 ? limit : AbortSignal.any([signal, limit])
53185
53642
  });
53186
53643
  } catch (error2) {
53187
- throw failed(error2, limit, signal);
53644
+ throw failed2(error2, limit, signal);
53188
53645
  }
53189
53646
  if (!response.ok)
53190
53647
  throw linkError(
@@ -53194,7 +53651,7 @@ function createCloudLink(options) {
53194
53651
  try {
53195
53652
  return { status: response.status, text: await response.text() };
53196
53653
  } catch (error2) {
53197
- throw failed(error2, limit, signal);
53654
+ throw failed2(error2, limit, signal);
53198
53655
  }
53199
53656
  }
53200
53657
  return {
@@ -53850,8 +54307,8 @@ import { StringDecoder } from "node:string_decoder";
53850
54307
  async function withSession(options, work) {
53851
54308
  const { server } = options.launch;
53852
54309
  const maxLineChars = options.maxLineChars ?? DEFAULT_MAX_LINE_CHARS;
53853
- const failed4 = (reason3) => new LocalServerError(serverFailed(server, reason3));
53854
- if (options.signal?.aborted === true) throw failed4(STOPPED);
54310
+ const failed5 = (reason3) => new LocalServerError(serverFailed(server, reason3));
54311
+ if (options.signal?.aborted === true) throw failed5(STOPPED);
53855
54312
  let child;
53856
54313
  try {
53857
54314
  child = options.spawn(options.launch.command, [...options.launch.args], {
@@ -53860,7 +54317,7 @@ async function withSession(options, work) {
53860
54317
  windowsHide: true
53861
54318
  });
53862
54319
  } catch (error2) {
53863
- throw failed4(`it could not start (${errorText2(error2)})`);
54320
+ throw failed5(`it could not start (${errorText2(error2)})`);
53864
54321
  }
53865
54322
  const pending = /* @__PURE__ */ new Map();
53866
54323
  const decoder4 = new StringDecoder("utf8");
@@ -53914,7 +54371,7 @@ async function withSession(options, work) {
53914
54371
  ERROR_MESSAGE_CHARS
53915
54372
  );
53916
54373
  entry2.reject(
53917
- failed4(
54374
+ failed5(
53918
54375
  `it answered ${entry2.method} with error ${String(error2.code)}: ${text6}`
53919
54376
  )
53920
54377
  );
@@ -53942,7 +54399,7 @@ async function withSession(options, work) {
53942
54399
  }
53943
54400
  buffer += text6.slice(start);
53944
54401
  if (buffer.length > maxLineChars)
53945
- fail3(failed4(`it wrote a line longer than ${maxLineChars} characters`));
54402
+ fail3(failed5(`it wrote a line longer than ${maxLineChars} characters`));
53946
54403
  });
53947
54404
  child.stderr.on("data", (chunk) => {
53948
54405
  stderrTail = (stderrTail + String(chunk)).slice(-STDERR_TAIL_CHARS2);
@@ -53950,21 +54407,21 @@ async function withSession(options, work) {
53950
54407
  child.on("close", (code, signal) => {
53951
54408
  exited = true;
53952
54409
  const how = code === null ? `it stopped on signal ${String(signal)}` : `it exited with code ${code}`;
53953
- fail3(failed4(withStderr(`${how} before it answered`)));
54410
+ fail3(failed5(withStderr(`${how} before it answered`)));
53954
54411
  });
53955
54412
  child.on(
53956
54413
  "error",
53957
- (error2) => fail3(failed4(withStderr(`it could not start (${error2.message})`)))
54414
+ (error2) => fail3(failed5(withStderr(`it could not start (${error2.message})`)))
53958
54415
  );
53959
54416
  child.stdin.on(
53960
54417
  "error",
53961
- (error2) => fail3(failed4(withStderr(`its stdin closed (${error2.message})`)))
54418
+ (error2) => fail3(failed5(withStderr(`its stdin closed (${error2.message})`)))
53962
54419
  );
53963
54420
  const timer = setTimeout(
53964
54421
  () => fail3(new LocalServerError(deadlinePassed(server, options.deadlineMs))),
53965
54422
  options.deadlineMs
53966
54423
  );
53967
- const onAbort = () => fail3(failed4(STOPPED));
54424
+ const onAbort = () => fail3(failed5(STOPPED));
53968
54425
  options.signal?.addEventListener("abort", onAbort, { once: true });
53969
54426
  function request3(method, params) {
53970
54427
  if (failure4 !== void 0) return Promise.reject(failure4);
@@ -59414,7 +59871,7 @@ function createModelProxy(deps) {
59414
59871
  familyPriced,
59415
59872
  settledAt,
59416
59873
  durationMs,
59417
- failed: failed4
59874
+ failed: failed5
59418
59875
  }) => {
59419
59876
  const responseText = responseBody.text();
59420
59877
  const owner = record2 === void 0 ? void 0 : deps.registry.byUuid(record2.recorder.sessionUuid);
@@ -59442,7 +59899,7 @@ function createModelProxy(deps) {
59442
59899
  ttftMs: firstByteAt !== void 0 ? Math.max(0, firstByteAt - startedAt) : void 0,
59443
59900
  durationMs,
59444
59901
  status: status2,
59445
- failed: failed4,
59902
+ failed: failed5,
59446
59903
  requestId
59447
59904
  });
59448
59905
  const sessionSighting = closed2 && record2 !== void 0 ? (owner ?? record2).recorder.judgeModelCallSealedElsewhere(callBody2) : void 0;
@@ -59610,13 +60067,13 @@ function createModelProxy(deps) {
59610
60067
  });
59611
60068
  if (heldError === void 0) upstream.pipe(res);
59612
60069
  };
59613
- const onError = (failed4, error2) => {
59614
- if (settled2 || failed4 !== upstreamReq) return;
60070
+ const onError = (failed5, error2) => {
60071
+ if (settled2 || failed5 !== upstreamReq) return;
59615
60072
  if (abortReason !== void 0) {
59616
60073
  settle4("interrupted");
59617
60074
  return;
59618
60075
  }
59619
- if (!retried && status2 === void 0 && failed4.reusedSocket && error2.code === "ECONNRESET") {
60076
+ if (!retried && status2 === void 0 && failed5.reusedSocket && error2.code === "ECONNRESET") {
59620
60077
  retried = true;
59621
60078
  deps.log(
59622
60079
  `model proxy: ${target.host} reset a pooled connection, sending the call again on a new one session=${sessionKey}`
@@ -64010,6 +64467,7 @@ async function initializeDaemon(options, server, port, ready, clock2) {
64010
64467
  acks.push(ack);
64011
64468
  },
64012
64469
  now,
64470
+ log,
64013
64471
  // A hook that queued behind others, or behind a slow read, can be
64014
64472
  // answered after the harness stopped waiting. Past this instant
64015
64473
  // the handler leaves the session's messages queued, rather than
@@ -66449,15 +66907,15 @@ function messageOf4(error2) {
66449
66907
  return error2 instanceof Error ? error2.message : String(error2);
66450
66908
  }
66451
66909
  async function refuse2(client, id2, reason3, deps) {
66452
- const failed4 = await refuseWorkOrder(client, id2, reason3);
66453
- if (failed4 === void 0) {
66910
+ const failed5 = await refuseWorkOrder(client, id2, reason3);
66911
+ if (failed5 === void 0) {
66454
66912
  deps.err(
66455
66913
  `${reason3} Oxagen has ended this send, and the work item can be sent again.`
66456
66914
  );
66457
66915
  return;
66458
66916
  }
66459
66917
  deps.err(reason3);
66460
- deps.err(`Could not tell Oxagen that ${id2} cannot start: ${failed4}`);
66918
+ deps.err(`Could not tell Oxagen that ${id2} cannot start: ${failed5}`);
66461
66919
  }
66462
66920
  async function workStart(id2, deps) {
66463
66921
  if (!WORK_ORDER_ID_PATTERN.test(id2)) {
@@ -71387,16 +71845,16 @@ function checkTurnLoopPairing(journal) {
71387
71845
  for (const event of journal.events) {
71388
71846
  switch (event.event) {
71389
71847
  case "model_response": {
71390
- for (const callId of event.tool_calls) {
71391
- if (everRequested.has(callId)) {
71848
+ for (const callId2 of event.tool_calls) {
71849
+ if (everRequested.has(callId2)) {
71392
71850
  violations.push(
71393
- `call id \`${callId}\` requested again at seq ${event.seq}: call ids are unique per session`
71851
+ `call id \`${callId2}\` requested again at seq ${event.seq}: call ids are unique per session`
71394
71852
  );
71395
71853
  continue;
71396
71854
  }
71397
- everRequested.add(callId);
71855
+ everRequested.add(callId2);
71398
71856
  totalRequested += 1;
71399
- pending.set(callId, event.seq);
71857
+ pending.set(callId2, event.seq);
71400
71858
  }
71401
71859
  break;
71402
71860
  }
@@ -71434,7 +71892,7 @@ function checkTurnLoopPairing(journal) {
71434
71892
  }
71435
71893
  case "prompt_assembled": {
71436
71894
  if (pending.size > 0) {
71437
- const dangling = [...pending.entries()].sort(([a], [b3]) => a < b3 ? -1 : a > b3 ? 1 : 0).map(([callId, at2]) => `\`${callId}\` (requested at seq ${at2})`);
71895
+ const dangling = [...pending.entries()].sort(([a], [b3]) => a < b3 ? -1 : a > b3 ? 1 : 0).map(([callId2, at2]) => `\`${callId2}\` (requested at seq ${at2})`);
71438
71896
  violations.push(
71439
71897
  `prompt assembled at seq ${event.seq} with ${dangling.length} unresolved tool call(s): ${dangling.join(", ")}`
71440
71898
  );
@@ -72857,7 +73315,7 @@ var init_package = __esm({
72857
73315
  "package.json"() {
72858
73316
  package_default = {
72859
73317
  name: "@oxagen/cli",
72860
- version: "3.0.1-791",
73318
+ version: "3.0.1-792",
72861
73319
  description: "Oxagen governance CLI: spend, source tracking, grounding, credentials, and audit (agentic coding lives in the stella CLI)",
72862
73320
  type: "module",
72863
73321
  main: "./dist/index.js",
@@ -92827,12 +93285,12 @@ async function workspaceConnect(argument, opts, writer = stdoutWriter, deps = {}
92827
93285
  } else {
92828
93286
  printConnect(ref, machineName, results, madeActive, writer);
92829
93287
  }
92830
- const failed4 = results.filter(
93288
+ const failed5 = results.filter(
92831
93289
  (r) => r.status === "failed" || r.status === "refused"
92832
93290
  );
92833
- if (failed4.length > 0) {
93291
+ if (failed5.length > 0) {
92834
93292
  out.error(
92835
- `${failed4.length} of ${results.length} harnesses were not connected to ${ref}. The lines above say why.`,
93293
+ `${failed5.length} of ${results.length} harnesses were not connected to ${ref}. The lines above say why.`,
92836
93294
  "connect"
92837
93295
  );
92838
93296
  }
@@ -128614,13 +129072,13 @@ function oneOf2(value, allowed, flag2, writer) {
128614
129072
  return value;
128615
129073
  }
128616
129074
  async function handleMemoryList(opts, writer = stdoutWriter) {
128617
- const states2 = listOpt(opts.state);
128618
- for (const state of states2)
129075
+ const states3 = listOpt(opts.state);
129076
+ for (const state of states3)
128619
129077
  oneOf2(state, WORKSPACE_MEMORY_STATES, "--state", writer);
128620
129078
  const harness = oneOf2(opts.harness, HARNESSES2, "--harness", writer);
128621
129079
  try {
128622
129080
  const result2 = await listWorkspaceMemories({
128623
- states: states2.length === 0 ? void 0 : states2,
129081
+ states: states3.length === 0 ? void 0 : states3,
128624
129082
  harness,
128625
129083
  agent: opts.agent,
128626
129084
  repository: opts.repository,
@@ -129450,7 +129908,7 @@ GitHub connected. Fetching repositories...
129450
129908
  )
129451
129909
  );
129452
129910
  const repos = [];
129453
- let failed4 = 0;
129911
+ let failed5 = 0;
129454
129912
  listed.forEach((result2, i2) => {
129455
129913
  if (result2.status === "fulfilled") {
129456
129914
  for (const r of result2.value.repositories) {
@@ -129458,13 +129916,13 @@ GitHub connected. Fetching repositories...
129458
129916
  }
129459
129917
  return;
129460
129918
  }
129461
- failed4 += 1;
129919
+ failed5 += 1;
129462
129920
  process.stdout.write(
129463
129921
  ` Could not list the repositories of ${installations[i2]?.accountLogin ?? "an installation"}: ${errorMessage3(result2.reason)}
129464
129922
  `
129465
129923
  );
129466
129924
  });
129467
- if (failed4 > 0) {
129925
+ if (failed5 > 0) {
129468
129926
  process.stdout.write(
129469
129927
  ` The link was not updated. Re-run \`oxagen init\` to try again.
129470
129928
  `
@@ -152253,7 +152711,7 @@ async function read(response, call2, clock2, settings) {
152253
152711
  if (next.value.done === true) break;
152254
152712
  if (template.streaming === "unary" && items.length === 1) {
152255
152713
  response.cancel();
152256
- return failed2(
152714
+ return failed3(
152257
152715
  internal(
152258
152716
  `${template.method} is unary, but the upstream sent more than one response message.`
152259
152717
  )
@@ -152265,7 +152723,7 @@ async function read(response, call2, clock2, settings) {
152265
152723
  item = decodeResponse(call2.method, encoded);
152266
152724
  } catch (error2) {
152267
152725
  response.cancel();
152268
- return failed2(internal(messageOf5(error2)));
152726
+ return failed3(internal(messageOf5(error2)));
152269
152727
  }
152270
152728
  items.push(item);
152271
152729
  if (template.streaming === "server") {
@@ -152293,7 +152751,7 @@ function fromStatus(status2, call2, items) {
152293
152751
  return { ok: true, value: streamResult(items, false), ending };
152294
152752
  const [value] = items;
152295
152753
  if (value === void 0) {
152296
- return failed2(
152754
+ return failed3(
152297
152755
  internal(
152298
152756
  `${call2.template.method} ended with OK and sent no response message.`
152299
152757
  ),
@@ -152306,7 +152764,7 @@ function fromStatus(status2, call2, items) {
152306
152764
  const detail = status2.message === "" ? `The upstream returned ${name2} with no message.` : status2.message;
152307
152765
  if (status2.code === STATUS_DEADLINE_EXCEEDED)
152308
152766
  return deadlinePassed2(call2, items, detail, ending);
152309
- return failed2(
152767
+ return failed3(
152310
152768
  { title: name2, detail, status: status2.code },
152311
152769
  ending,
152312
152770
  status2.code === STATUS_UNAVAILABLE && items.length === 0
@@ -152314,7 +152772,7 @@ function fromStatus(status2, call2, items) {
152314
152772
  }
152315
152773
  function transportFailure2(error2, call2, items) {
152316
152774
  if (!(error2 instanceof TransportError)) {
152317
- return failed2({
152775
+ return failed3({
152318
152776
  title: "Transport error",
152319
152777
  detail: messageOf5(error2),
152320
152778
  status: void 0
@@ -152324,7 +152782,7 @@ function transportFailure2(error2, call2, items) {
152324
152782
  case "timeout":
152325
152783
  return deadlinePassed2(call2, items, error2.message);
152326
152784
  case "not_sent":
152327
- return failed2(
152785
+ return failed3(
152328
152786
  {
152329
152787
  title: statusName(STATUS_UNAVAILABLE),
152330
152788
  detail: error2.message,
@@ -152334,7 +152792,7 @@ function transportFailure2(error2, call2, items) {
152334
152792
  items.length === 0
152335
152793
  );
152336
152794
  default:
152337
- return failed2({
152795
+ return failed3({
152338
152796
  title: TRANSPORT_TITLES2[error2.code],
152339
152797
  detail: error2.message,
152340
152798
  status: void 0
@@ -152342,7 +152800,7 @@ function transportFailure2(error2, call2, items) {
152342
152800
  }
152343
152801
  }
152344
152802
  function stopped(stop, call2, items) {
152345
- if (stop === "cancelled") return failed2(CANCELLED2);
152803
+ if (stop === "cancelled") return failed3(CANCELLED2);
152346
152804
  return deadlinePassed2(
152347
152805
  call2,
152348
152806
  items,
@@ -152358,7 +152816,7 @@ function deadlinePassed2(call2, items, detail, upstream) {
152358
152816
  };
152359
152817
  return { ok: true, value: streamResult(items, true), ending };
152360
152818
  }
152361
- return failed2(
152819
+ return failed3(
152362
152820
  {
152363
152821
  title: statusName(STATUS_DEADLINE_EXCEEDED),
152364
152822
  detail,
@@ -152377,7 +152835,7 @@ function internal(detail) {
152377
152835
  status: STATUS_INTERNAL
152378
152836
  };
152379
152837
  }
152380
- function failed2(error2, ending, retryable = false) {
152838
+ function failed3(error2, ending, retryable = false) {
152381
152839
  return { ok: false, error: error2, retryable, ending };
152382
152840
  }
152383
152841
  function exchangesFor(call2, ending) {
@@ -153513,7 +153971,7 @@ var init_validate = __esm({
153513
153971
 
153514
153972
  // ../../packages/mcp-studio/src/execute/call.ts
153515
153973
  import { randomUUID as randomUUID5 } from "node:crypto";
153516
- function failed3(text6, exchanges = []) {
153974
+ function failed4(text6, exchanges = []) {
153517
153975
  return {
153518
153976
  result: { content: [{ type: "text", text: text6 }], isError: true },
153519
153977
  exchanges
@@ -153574,11 +154032,11 @@ function dispatch(senders, tool, args, context) {
153574
154032
  }
153575
154033
  async function executeCall(tool, args, environment, credentials2, transport, options = {}) {
153576
154034
  const badArguments = inputRefusal(tool.definition.inputSchema, args);
153577
- if (badArguments !== null) return failed3(badArguments);
154035
+ if (badArguments !== null) return failed4(badArguments);
153578
154036
  const { server, name: name2 } = environment;
153579
154037
  const env = Object.hasOwn(server.environments, name2) ? server.environments[name2] : void 0;
153580
154038
  if (env === void 0)
153581
- return failed3(
154039
+ return failed4(
153582
154040
  `The server ${server.name} has no environment named ${name2}.`
153583
154041
  );
153584
154042
  const shaping = tool.shaping;
@@ -153597,7 +154055,7 @@ async function executeCall(tool, args, environment, credentials2, transport, opt
153597
154055
  signal
153598
154056
  );
153599
154057
  if (resolved.type === "missing")
153600
- return failed3(`${resolved.message}
154058
+ return failed4(`${resolved.message}
153601
154059
  ${resolved.connect_url}`);
153602
154060
  credential = resolved;
153603
154061
  }
@@ -153647,7 +154105,7 @@ ${resolved.connect_url}`);
153647
154105
  },
153648
154106
  send5
153649
154107
  );
153650
- if (!paged.ok) return failed3(errorText3(paged.error), paged.exchanges);
154108
+ if (!paged.ok) return failed4(errorText3(paged.error), paged.exchanges);
153651
154109
  value = paged.value;
153652
154110
  exchanges = paged.exchanges;
153653
154111
  const note = paged.paged === void 0 ? void 0 : pagingNote(paged.paged, { shaping });
@@ -153655,7 +154113,7 @@ ${resolved.connect_url}`);
153655
154113
  } else {
153656
154114
  const sent = await send5(upstream, shaping.deadline_ms);
153657
154115
  exchanges = sent.exchanges ?? [];
153658
- if (!sent.ok) return failed3(errorText3(sent.error), exchanges);
154116
+ if (!sent.ok) return failed4(errorText3(sent.error), exchanges);
153659
154117
  value = sent.value;
153660
154118
  }
153661
154119
  if (local || kind === "mcp") {
@@ -162558,7 +163016,7 @@ var require_subchannel = __commonJS({
162558
163016
  }
162559
163017
  return false;
162560
163018
  }
162561
- createCall(metadata, host, method, listener, callId) {
163019
+ createCall(metadata, host, method, listener, callId2) {
162562
163020
  if (!this.transport) {
162563
163021
  throw new Error("Cannot create call, subchannel not READY");
162564
163022
  }
@@ -162578,7 +163036,7 @@ var require_subchannel = __commonJS({
162578
163036
  } else {
162579
163037
  statsTracker = {};
162580
163038
  }
162581
- return this.transport.createCall(metadata, host, method, listener, statsTracker, callId);
163039
+ return this.transport.createCall(metadata, host, method, listener, statsTracker, callId2);
162582
163040
  }
162583
163041
  /**
162584
163042
  * If the subchannel is currently IDLE, start connecting and switch to the
@@ -163339,13 +163797,13 @@ var require_subchannel_call = __commonJS({
163339
163797
  };
163340
163798
  }
163341
163799
  var Http2SubchannelCall = class {
163342
- constructor(http2Stream, callEventTracker, listener, transport, callId) {
163800
+ constructor(http2Stream, callEventTracker, listener, transport, callId2) {
163343
163801
  var _a2;
163344
163802
  this.http2Stream = http2Stream;
163345
163803
  this.callEventTracker = callEventTracker;
163346
163804
  this.listener = listener;
163347
163805
  this.transport = transport;
163348
- this.callId = callId;
163806
+ this.callId = callId2;
163349
163807
  this.isReadFilterPending = false;
163350
163808
  this.isPushPending = false;
163351
163809
  this.canPush = false;
@@ -164047,7 +164505,7 @@ var require_transport = __commonJS({
164047
164505
  }
164048
164506
  }
164049
164507
  }
164050
- createCall(metadata, host, method, listener, subchannelCallStatsTracker, callId) {
164508
+ createCall(metadata, host, method, listener, subchannelCallStatsTracker, callId2) {
164051
164509
  const headers = metadata.toHttp2Headers();
164052
164510
  headers[HTTP2_HEADER_AUTHORITY] = host;
164053
164511
  headers[HTTP2_HEADER_USER_AGENT] = this.userAgent;
@@ -164121,7 +164579,7 @@ var require_transport = __commonJS({
164121
164579
  }
164122
164580
  };
164123
164581
  }
164124
- call2 = new subchannel_call_1.Http2SubchannelCall(http2Stream, eventTracker, listener, this, callId !== null && callId !== void 0 ? callId : (0, call_number_1.getNextCallNumber)());
164582
+ call2 = new subchannel_call_1.Http2SubchannelCall(http2Stream, eventTracker, listener, this, callId2 !== null && callId2 !== void 0 ? callId2 : (0, call_number_1.getNextCallNumber)());
164125
164583
  this.addActiveCall(call2);
164126
164584
  return call2;
164127
164585
  }
@@ -165016,36 +165474,36 @@ var require_retrying_call = __commonJS({
165016
165474
  this.totalAllocated = 0;
165017
165475
  this.allocatedPerCall = /* @__PURE__ */ new Map();
165018
165476
  }
165019
- allocate(size, callId) {
165477
+ allocate(size, callId2) {
165020
165478
  var _a2;
165021
- const currentPerCall = (_a2 = this.allocatedPerCall.get(callId)) !== null && _a2 !== void 0 ? _a2 : 0;
165479
+ const currentPerCall = (_a2 = this.allocatedPerCall.get(callId2)) !== null && _a2 !== void 0 ? _a2 : 0;
165022
165480
  if (this.limitPerCall - currentPerCall < size || this.totalLimit - this.totalAllocated < size) {
165023
165481
  return false;
165024
165482
  }
165025
- this.allocatedPerCall.set(callId, currentPerCall + size);
165483
+ this.allocatedPerCall.set(callId2, currentPerCall + size);
165026
165484
  this.totalAllocated += size;
165027
165485
  return true;
165028
165486
  }
165029
- free(size, callId) {
165487
+ free(size, callId2) {
165030
165488
  var _a2;
165031
165489
  if (this.totalAllocated < size) {
165032
- throw new Error(`Invalid buffer allocation state: call ${callId} freed ${size} > total allocated ${this.totalAllocated}`);
165490
+ throw new Error(`Invalid buffer allocation state: call ${callId2} freed ${size} > total allocated ${this.totalAllocated}`);
165033
165491
  }
165034
165492
  this.totalAllocated -= size;
165035
- const currentPerCall = (_a2 = this.allocatedPerCall.get(callId)) !== null && _a2 !== void 0 ? _a2 : 0;
165493
+ const currentPerCall = (_a2 = this.allocatedPerCall.get(callId2)) !== null && _a2 !== void 0 ? _a2 : 0;
165036
165494
  if (currentPerCall < size) {
165037
- throw new Error(`Invalid buffer allocation state: call ${callId} freed ${size} > allocated for call ${currentPerCall}`);
165495
+ throw new Error(`Invalid buffer allocation state: call ${callId2} freed ${size} > allocated for call ${currentPerCall}`);
165038
165496
  }
165039
- this.allocatedPerCall.set(callId, currentPerCall - size);
165497
+ this.allocatedPerCall.set(callId2, currentPerCall - size);
165040
165498
  }
165041
- freeAll(callId) {
165499
+ freeAll(callId2) {
165042
165500
  var _a2;
165043
- const currentPerCall = (_a2 = this.allocatedPerCall.get(callId)) !== null && _a2 !== void 0 ? _a2 : 0;
165501
+ const currentPerCall = (_a2 = this.allocatedPerCall.get(callId2)) !== null && _a2 !== void 0 ? _a2 : 0;
165044
165502
  if (this.totalAllocated < currentPerCall) {
165045
- throw new Error(`Invalid buffer allocation state: call ${callId} allocated ${currentPerCall} > total allocated ${this.totalAllocated}`);
165503
+ throw new Error(`Invalid buffer allocation state: call ${callId2} allocated ${currentPerCall} > total allocated ${this.totalAllocated}`);
165046
165504
  }
165047
165505
  this.totalAllocated -= currentPerCall;
165048
- this.allocatedPerCall.delete(callId);
165506
+ this.allocatedPerCall.delete(callId2);
165049
165507
  }
165050
165508
  };
165051
165509
  exports.MessageBufferTracker = MessageBufferTracker;