@livx.cc/agentx 0.99.151 → 0.99.153

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/cli.js CHANGED
@@ -2962,7 +2962,7 @@ async function psGroupCpuSeconds(pgid) {
2962
2962
  try {
2963
2963
  return await winTreeCpuSeconds(pgid);
2964
2964
  } catch (e) {
2965
- log32.debug(`cpu probe failed for ${pgid}: ${e}`);
2965
+ log33.debug(`cpu probe failed for ${pgid}: ${e}`);
2966
2966
  return void 0;
2967
2967
  }
2968
2968
  }
@@ -2971,7 +2971,7 @@ async function psGroupCpuSeconds(pgid) {
2971
2971
  const out = await new Promise((res, rej) => execFile5("ps", ["-A", "-o", "pid=,ppid=,pgid=,time="], { timeout: 5e3, env: { ...process.env, LC_ALL: "C" } }, (e, so) => e ? rej(e) : res(String(so))));
2972
2972
  return sumTreeCpu(out, pgid);
2973
2973
  } catch (e) {
2974
- log32.debug(`ps cpu probe failed for group ${pgid}: ${e}`);
2974
+ log33.debug(`ps cpu probe failed for group ${pgid}: ${e}`);
2975
2975
  return void 0;
2976
2976
  }
2977
2977
  }
@@ -3121,7 +3121,7 @@ function makeRealShellTool(options) {
3121
3121
  proc.stderr?.on("data", collect);
3122
3122
  proc.on("error", (err2) => {
3123
3123
  if (err2?.name === "AbortError" || ctl.signal.aborted) return finish(reasonFor(timedOut, timeoutMs, clean2(out)));
3124
- log32.debug("shell spawn error", err2);
3124
+ log33.debug("shell spawn error", err2);
3125
3125
  finish(`[exit 1] ${err2?.message ?? err2}${out ? "\n" + clean2(out) : ""}`);
3126
3126
  });
3127
3127
  proc.on("close", (code) => {
@@ -3200,7 +3200,7 @@ ${clean2(out) || "(no output yet)"}`;
3200
3200
  }
3201
3201
  ];
3202
3202
  }
3203
- var log32, clean2, DETACHED, shellArgv, SECRET_ENV_RE, _spawn, ShellJobRegistry, shellStatus, NO_JOB2;
3203
+ var log33, clean2, DETACHED, shellArgv, SECRET_ENV_RE, _spawn, ShellJobRegistry, shellStatus, NO_JOB2;
3204
3204
  var init_tools_shell = __esm({
3205
3205
  "src/tools.shell.ts"() {
3206
3206
  "use strict";
@@ -3210,7 +3210,7 @@ var init_tools_shell = __esm({
3210
3210
  init_shell_sandbox();
3211
3211
  init_tools_jobs();
3212
3212
  init_platform();
3213
- log32 = forComponent("shell");
3213
+ log33 = forComponent("shell");
3214
3214
  clean2 = (s) => truncateOutput(redactSecrets(s.replace(/\n+$/, "")));
3215
3215
  DETACHED = { stdio: ["ignore", "pipe", "pipe"], ...DETACH_OPTIONS };
3216
3216
  shellArgv = (sh, command) => ({ bin: sh.bin, args: sh.args(command), ...sh.spawnOptions ? { spawnOptions: sh.spawnOptions } : {} });
@@ -10446,12 +10446,14 @@ var LEADER = /* @__PURE__ */ new Set(["yeah", "yea", "yes", "yep", "yup", "ok",
10446
10446
  var PHRASES = ["got it", "i see", "makes sense", "of course", "for sure", "all right", "that's right", "that's true", "thats right", "thats true", "love it", "i know", "me too", "uh huh"];
10447
10447
  var CONTINUE = /^(?:(?:and|so|oh) )?(?:and|so|really|seriously|then what|and then|go on|keep going|ואז|באמת|נו)$/;
10448
10448
  var AGREE = new Set("yeah yea yes yep yup right sure true totally exactly definitely absolutely agreed correct indeed \u05DB\u05DF \u05E0\u05DB\u05D5\u05DF \u05D1\u05D3\u05D9\u05D5\u05E7 \u05D1\u05E8\u05D5\u05E8 \u05D1\u05D8\u05D7 \u05D0\u05DB\u05DF \u05DC\u05D2\u05DE\u05E8\u05D9 \u05DE\u05E1\u05DB\u05D9\u05DD \u05DE\u05E1\u05DB\u05D9\u05DE\u05D4 \u05DE\u05DE\u05E9".split(" "));
10449
+ var DOUBT = /^(?:(?:and|so|oh|wait|but) )*(?:really|seriously|are|is|was|were|do|does|did|you|no way|באמת|בטוח|בטוחה|רצינית?)(?=\s|$)/u;
10449
10450
  var AGREE_PHRASES = ["of course", "for sure", "that's right", "that's true", "thats right", "thats true", "makes sense", "i agree"];
10450
10451
  var HE_ACK = new Set("\u05DB\u05DF \u05E0\u05DB\u05D5\u05DF \u05D1\u05D3\u05D9\u05D5\u05E7 \u05D1\u05E8\u05D5\u05E8 \u05D1\u05D8\u05D7 \u05D0\u05DB\u05DF \u05DC\u05D2\u05DE\u05E8\u05D9 \u05DE\u05DE\u05E9 \u05D0\u05D5\u05E7\u05D9\u05D9 \u05D0\u05D5\u05E7\u05D9 \u05E1\u05D1\u05D1\u05D4 \u05D9\u05E4\u05D4 \u05DE\u05E2\u05D5\u05DC\u05D4 \u05D5\u05D5\u05D0\u05D5 \u05D0\u05D4\u05D4 \u05D0\u05D4 \u05D4\u05DE\u05DE \u05DE\u05DE\u05DE".split(" "));
10451
10452
  function cueKind(text) {
10452
10453
  const t = norm2(text);
10453
10454
  if (!t) return null;
10454
10455
  if (CONTINUE.test(t)) return "continue";
10456
+ if (/\?/.test(text) || DOUBT.test(t)) return null;
10455
10457
  let r = t;
10456
10458
  for (const p of AGREE_PHRASES) if (r.includes(p)) return "agree";
10457
10459
  r = r.split(/[\s-]+/).filter((w) => !LEAD.has(w)).join(" ");
@@ -10664,13 +10666,20 @@ var INTENT_ACK_OVER = {
10664
10666
  resume: ["agreement", "silent"],
10665
10667
  aside: []
10666
10668
  };
10667
- function interruptionNote(cut, intent) {
10669
+ function heardAt(cut) {
10670
+ const at = Math.min(cut.heard.length, cut.full.length);
10671
+ return /\S/.test(cut.full[at] ?? "") && /\S/.test(cut.full[at - 1] ?? "") ? cut.full.lastIndexOf(" ", at) + 1 : at;
10672
+ }
10673
+ function cutHeard(cut) {
10674
+ return cut.full.slice(0, heardAt(cut)).trim();
10675
+ }
10676
+ function interruptionNote(cut, intent, hold = true) {
10668
10677
  const full = cut.full.trim();
10669
- let at = Math.min(cut.heard.length, cut.full.length);
10670
- if (/\S/.test(cut.full[at] ?? "") && /\S/.test(cut.full[at - 1] ?? "")) at = cut.full.lastIndexOf(" ", at) + 1;
10678
+ const at = heardAt(cut);
10671
10679
  const heardWords = cut.full.slice(0, at).trim().split(/\s+/).filter(Boolean).length;
10672
10680
  const unheard = cut.full.slice(at).trim();
10673
- const landed = heardWords < 4 ? "They cut in almost at once \u2014 treat all of it as unsaid." : `They heard everything before this part. They missed the rest of it: "${unheard}".`;
10681
+ const lastWords = cut.full.slice(0, at).trim().split(/\s+/).slice(-8).join(" ");
10682
+ const landed = heardWords < 4 ? "They cut in almost at once \u2014 treat all of it as unsaid." : `They heard everything before this part. They missed the rest of it: "${unheard}". The last words they heard were "\u2026${lastWords}" \u2014 a "that"/"it"/"this" in their words means the thing those words were naming, never anything in the missed part.`;
10674
10683
  const how = {
10675
10684
  resume: "They did not ask anything new. Carry on with the part they missed \u2014 no restart, no apology.",
10676
10685
  aside: "It was an aside. Answer it briefly FIRST, then finish the part they missed, adjusted to anything they just said. Say each point once: skip whatever they already heard and whatever your answer just covered.",
@@ -10679,7 +10688,7 @@ function interruptionNote(cut, intent) {
10679
10688
  unknown: "Decide like a person would: if it was an aside, answer it and then finish your point; if they steered away, follow them and drop or adapt the rest."
10680
10689
  };
10681
10690
  return `
10682
- [the user interrupted you mid-speech. You were saying: "${full}" ${landed} ${how[intent ?? "unknown"]} Just talk, like a person picking the thread back up: never tell them what they heard or missed, never say where you were cut off, and never quote your earlier words back. If their words are still an unfinished fragment, call Hold instead of answering.]`;
10691
+ [the user interrupted you mid-speech. You were saying: "${full}" ${landed} ${how[intent ?? "unknown"]} Just talk, like a person picking the thread back up: never tell them what they heard or missed, never say where you were cut off, and never quote your earlier words back.` + (hold ? " If their words are still an unfinished fragment, call Hold instead of answering." : "") + "]";
10683
10692
  }
10684
10693
  var FRAME = "You are the instinct of a warm, attentive human in a live spoken conversation. Decide what a natural human would do THIS instant \u2014 the way people do without thinking. ";
10685
10694
  var acted = (what, r) => r === false ? `${what}_skipped` : what;
@@ -11462,6 +11471,10 @@ var TurnGateOptions = class {
11462
11471
  * 20261103-114604, "Okay." settled 700ms into "What will the…" and MAIN started, was aborted twice and merged. The
11463
11472
  * rest's final merges in; capped at this long from the hold (an STT that never finalizes a partial). */
11464
11473
  talkingMaxMs = 6e3;
11474
+ /** With settleMs: a final of acknowledgement words only ("Ok Okay.") waits this long. No answer is due, and it is
11475
+ * mostly the start of the turn: live 20261103-210433, "Ok Okay." settled at 700ms, the rest began 1s after it, and
11476
+ * MAIN was started and aborted. Quiet past this sends it as it was. */
11477
+ openerMs = 2e3;
11465
11478
  onTurn = () => {
11466
11479
  };
11467
11480
  onDrop = () => {
@@ -11519,7 +11532,7 @@ var TurnGate = class {
11519
11532
  if (this.closed && isClosing(t)) return this.o.onDrop(t, "goodbye");
11520
11533
  const mid = endsMidPhrase(t);
11521
11534
  if (mid || this.o.settleMs && !/\?["')\]]*$/.test(t)) {
11522
- const ms = mid ? this.o.holdMs : this.o.settleMs;
11535
+ const ms = mid ? this.o.holdMs : this.o.settleMs && this.opener(t) ? Math.max(this.o.settleMs, this.o.openerMs) : this.o.settleMs;
11523
11536
  this.held = { text: t, sttId, ms, replaces, since: now4, timer: setTimeout(() => this.settle(), ms) };
11524
11537
  return this.o.onHold(t);
11525
11538
  }
@@ -11564,6 +11577,11 @@ var TurnGate = class {
11564
11577
  if (this.closed && isClosing(h.text)) return this.o.onDrop(h.text, "goodbye");
11565
11578
  this.send(h.text, norm3(h.text), h.sttId, "new", h.replaces);
11566
11579
  }
11580
+ /** Only acknowledgement words ("Ok Okay.", "Alright.") and no goodbye: no answer is due, and it usually opens what
11581
+ * comes next. */
11582
+ opener(t) {
11583
+ return turnIntent(t) === "closer" && !isClosing(t);
11584
+ }
11567
11585
  end() {
11568
11586
  if (this.held) {
11569
11587
  clearTimeout(this.held.timer);
@@ -14084,17 +14102,42 @@ Reply JSON only: {"turn":"...","density":"...","cues":[{"when":["phrase",...],"l
14084
14102
  }
14085
14103
  };
14086
14104
 
14105
+ // src/voice/fastText.ts
14106
+ init_logging();
14107
+ var log27 = forComponent("FastText");
14108
+ var isReasoningFast = (model) => /gpt-oss/.test(model);
14109
+ async function fastText(ai, o) {
14110
+ const reasons = isReasoningFast(o.model);
14111
+ const r = await ai.chat({
14112
+ model: o.model,
14113
+ messages: [{ role: "user", content: o.prompt }],
14114
+ stream: false,
14115
+ ...o.signal ? { signal: o.signal } : {},
14116
+ maxTokens: reasons ? Math.max(o.maxTokens ?? 0, 400) : o.maxTokens ?? 150,
14117
+ ...o.temperature !== void 0 ? { temperature: o.temperature } : {},
14118
+ ...reasons ? { providerOptions: { reasoning_effort: "low" } } : {}
14119
+ });
14120
+ if (reasons && r.finishReason === "length") {
14121
+ log27.debug(`${o.model} hit its token cap \u2014 no answer: ${(r.content ?? "").slice(0, 80)}`);
14122
+ return "";
14123
+ }
14124
+ return r.content ?? "";
14125
+ }
14126
+
14087
14127
  // src/voice/convoTree.ts
14088
- var log27 = forComponent("ConvoTree");
14128
+ var log28 = forComponent("ConvoTree");
14089
14129
  var MOMENTS = ["turn_end", "barge_in", "in_between", "ask"];
14090
14130
  var MAX_LINE_WORDS = 5;
14091
14131
  var SOFT_CUE = "~";
14092
14132
  var STOP4 = new Set("about after again also always been before being could does doing down even every from going have here into just know like look make many more most much must never only other over really right same should some still such sure take than that their them then there these they thing think this those through very want well were what when where which while will with would your yeah okay".split(" "));
14093
14133
  var isContent = (w) => w.length >= 4 && !STOP4.has(w);
14094
14134
  function echoesHeard(line, heard) {
14095
- const said = new Set(cueWords(heard));
14096
- return cueWords(lineWords(line)).some((w) => isContent(w) && said.has(w));
14135
+ const said = cueWords(heard).map(stem).filter(echoable);
14136
+ return cueWords(lineWords(line)).map(stem).filter(echoable).some((w) => said.some((h) => h === w || Math.min(h.length, w.length) >= 4 && (h.startsWith(w) || w.startsWith(h))));
14097
14137
  }
14138
+ var stem = (w) => w.replace(/['’]s$/, "").replace(new RegExp("(?<=\\p{L}{3})s$", "u"), "");
14139
+ var SHORT_STOP = new Set("the and you are was for not but has had his her its our who why how can did get got let may one out see she two use way yes all any new now off old own say too him hey huh ooh wow yep".split(" "));
14140
+ var echoable = (w) => isContent(w) || w.length === 3 && !SHORT_STOP.has(w) && !new RegExp("^\\p{N}+$", "u").test(w);
14098
14141
  var leafKey = (line) => cueWords(lineWords(line)).join(" ");
14099
14142
  function parseNodes(list, lang, depth, maxBranches) {
14100
14143
  const out = [];
@@ -14250,7 +14293,7 @@ Reply JSON only: {"soft":["...","..."],"branches":[{"when":["..."],"p":0.5,"mome
14250
14293
  const seen = new Set(c.recent.map(leafKey));
14251
14294
  const fresh = (l) => l.filter((n) => !seen.has(leafKey(n.line))).map((n) => ({ ...n, next: fresh(n.next) }));
14252
14295
  const nodes = fresh(parseTree(r.content ?? "", c.lang, o.levels));
14253
- if (!nodes.length) log27.debug(`unusable tree: ${(r.content ?? "").slice(0, 160)}`);
14296
+ if (!nodes.length) log28.debug(`unusable tree: ${(r.content ?? "").slice(0, 160)}`);
14254
14297
  return { nodes, ...r.usage ? { tokens: { input: r.usage.promptTokens, output: r.usage.completionTokens } } : {} };
14255
14298
  }
14256
14299
  };
@@ -14260,16 +14303,14 @@ function fastLeafPicker(ai, model = "groq/openai/gpt-oss-120b") {
14260
14303
  They may still be talking. A warm listener reacts often: does one of these fit the words they just said? It must fit those words.
14261
14304
  ` + lines.map((l) => `${l.i}: ${l.line} (fits: ${l.when.join(", ").replace("~", "any moment, when no topic line fits")})`).join("\n") + `
14262
14305
  Answer only the number, or "none".`;
14263
- const reasoning = /gpt-oss/.test(model) ? { providerOptions: { reasoning_effort: "low" } } : {};
14264
- const r = await ai.chat({ model, messages: [{ role: "user", content: prompt }], stream: false, signal, temperature: 0, maxTokens: /gpt-oss/.test(model) ? 200 : 4, ...reasoning });
14265
- const m = (r.content ?? "").trim().match(/^\d+/);
14306
+ const m = (await fastText(ai, { model, prompt, signal, temperature: 0, maxTokens: 4 })).trim().match(/^\d+/);
14266
14307
  return m ? Number(m[0]) : -1;
14267
14308
  };
14268
14309
  }
14269
14310
 
14270
14311
  // src/voice/progress.ts
14271
14312
  init_logging();
14272
- var log28 = forComponent("Progress");
14313
+ var log29 = forComponent("Progress");
14273
14314
  var HE_RESULT_CLAIM = /(?:^|\s)(?:מצאתי|סיימתי|בוצע|הנה|אין)(?=\s|$|[.,!…])/u;
14274
14315
  var PLUMBING = /toolsearch|^mcp__.*__(list_commands|call_info)$/;
14275
14316
  var isPlumbing = (tool) => PLUMBING.test(tool.toLowerCase());
@@ -14444,7 +14485,7 @@ var Progress = class {
14444
14485
  });
14445
14486
  const hint = argsHint(args) || about.slice(-80);
14446
14487
  const raw = await Promise.race([this.o.generate(tool, hint, lang, ac.signal, this.lines).catch((e) => {
14447
- log28.warn(`progress line failed: ${e?.message ?? e}`);
14488
+ log29.warn(`progress line failed: ${e?.message ?? e}`);
14448
14489
  return null;
14449
14490
  }), late]).finally(() => clearTimeout(t));
14450
14491
  const l = cleanLine(raw ?? "", lang, 5);
@@ -14455,9 +14496,7 @@ var Progress = class {
14455
14496
  function fastProgressGenerator(ai, model, gender) {
14456
14497
  return async (tool, hint, lang, signal, avoid = []) => {
14457
14498
  const prompt = `An assistant on a live voice call is running the tool "${tool}"${hint ? ` (about: "${hint}")` : ""}. Write ONE spoken line of 2-5 words, in ${languageName(lang)}, saying what it is doing right now (like "checking the board\u2026"). ${hint ? 'Name what it works on the way a person would say it ("looking up that Astra post\u2026"), never a string of its keywords ("scanning Astra weights\u2026"). ' : ""}${avoid.length ? `It already said ${avoid.map((a) => `"${a}"`).join(", ")}: say something new, a different angle on the same work. ` : ""}Never state a result or a finding. ${personaHint(gender)} Output only the line.`;
14458
- const reasoning = /gpt-oss/.test(model) ? { providerOptions: { reasoning_effort: "low" } } : {};
14459
- const r = await ai.chat({ model, messages: [{ role: "user", content: prompt }], stream: false, signal, maxTokens: 150, ...reasoning });
14460
- return r.content ?? "";
14499
+ return fastText(ai, { model, prompt, signal });
14461
14500
  };
14462
14501
  }
14463
14502
  var WORK_CLAIM = /\b(?:none|nothing|nobody|zero|\d+|one|two|three|four|five|many|several|some|looks like|seems|turns out|apparently|it'?s|they'?re|there'?s)\b|(?:^|\s)(?:כלום|אף|נראה)(?=\s|$|[.,!…])/iu;
@@ -14478,15 +14517,13 @@ ${persona.slice(0, 500)}
14478
14517
 
14479
14518
  ` : ""}You are on a live voice call, in the middle of doing this for them: "${c.request.slice(-160)}"${c.tool ? ` (right now: ${c.tool}${c.hint ? ` on ${c.hint}` : ""})` : ""}. They just said, while you work: "${c.heard.slice(-200)}"
14480
14519
  Answer them at once with ONE short spoken line of 2-7 words in ${languageName(c.lang)}, the way a person busy on it would ("yeah, looking now"). You have NO results yet and cannot know any: only acknowledge the work, never say what was or was not found, not even "nothing yet" or "none so far". ` + (c.avoid.length ? `Do not reuse: ${c.avoid.map((a) => `"${a}"`).join(", ")}. ` : "") + `If they tell you to stop or drop the work, start the line with "stop:". If they change the request or add to it, start it with "work:". ${personaHint(gender)} Output only the line, no tone tag.`;
14481
- const reasoning = /gpt-oss/.test(model) ? { providerOptions: { reasoning_effort: "low" } } : {};
14482
- const r = await ai.chat({ model, messages: [{ role: "user", content: prompt }], stream: false, signal, maxTokens: 150, ...reasoning });
14483
- return r.content ?? "";
14520
+ return fastText(ai, { model, prompt, signal });
14484
14521
  };
14485
14522
  }
14486
14523
 
14487
14524
  // src/voice/secondChannel.ts
14488
14525
  init_logging();
14489
- var log29 = forComponent("SecondChannel");
14526
+ var log30 = forComponent("SecondChannel");
14490
14527
  var CHANNEL_MODES = {
14491
14528
  turn: { kinds: ["bridge"], bridgeDelayMs: 1500 },
14492
14529
  normal: {},
@@ -14656,15 +14693,15 @@ function withBudget(p, ms, what, ac) {
14656
14693
  let t;
14657
14694
  const late = new Promise((r) => {
14658
14695
  t = setTimeout(() => {
14659
- log29.debug(`${what}: over the ${ms}ms budget \u2014 dropped`);
14696
+ log30.debug(`${what}: over the ${ms}ms budget \u2014 dropped`);
14660
14697
  ac?.abort();
14661
14698
  r(null);
14662
14699
  }, ms);
14663
14700
  });
14664
14701
  return Promise.race([p.catch((e) => {
14665
14702
  const msg = String(e?.message ?? e);
14666
- if (e?.name === "AbortError" || /aborted/i.test(msg)) log29.debug(`${what}: aborted after its budget`);
14667
- else log29.warn(`${what} failed \u2014 falling back: ${msg}`);
14703
+ if (e?.name === "AbortError" || /aborted/i.test(msg)) log30.debug(`${what}: aborted after its budget`);
14704
+ else log30.warn(`${what} failed \u2014 falling back: ${msg}`);
14668
14705
  return null;
14669
14706
  }), late]).finally(() => clearTimeout(t));
14670
14707
  }
@@ -14708,10 +14745,14 @@ var SecondChannel = class {
14708
14745
  // a bridge generated ahead, used only if ready in time
14709
14746
  bridgeReady = Promise.resolve();
14710
14747
  // live: that draft settled
14748
+ noLine = "";
14749
+ // live: why that draft gave no line
14711
14750
  askLeaf = null;
14712
14751
  // live: this turn's ask leaf
14713
14752
  barged = false;
14714
14753
  // the user cut in since their last turn: that turn is a steer, not a story to react to
14754
+ said = "";
14755
+ // live: what the user heard the assistant say last (the cut's heard part, else the last reply)
14715
14756
  leafReady = Promise.resolve();
14716
14757
  // live: the turn-end leaf pick settled
14717
14758
  recent = [];
@@ -14767,7 +14808,7 @@ var SecondChannel = class {
14767
14808
  if (host) this.pinned = true;
14768
14809
  const lang = primaryLang(tag);
14769
14810
  if (!lang || lang === this.lang) return;
14770
- log29.debug(`language ${this.lang} \u2192 ${lang}`);
14811
+ log30.debug(`language ${this.lang} \u2192 ${lang}`);
14771
14812
  this.lang = lang;
14772
14813
  this.recent = [];
14773
14814
  this.picks.clear();
@@ -14917,9 +14958,20 @@ var SecondChannel = class {
14917
14958
  }, Math.max(late, wait + 1));
14918
14959
  }
14919
14960
  }
14961
+ /** The STT closed the user's line (a final that ends a sentence), before it is a turn (the host may still hold it): a
14962
+ * listener cue armed on its last words is late now. Replay of 20261103-210433: "oh wow" played 330ms after "…and
14963
+ * hacker news." while the gate held the turn, and spaced the request's own line to 1.5s. */
14964
+ onLineEnd() {
14965
+ this.userSpeaking = false;
14966
+ for (const k of ["bcTimer", "leafTimer", "breathTimer"]) {
14967
+ if (this[k]) clearTimeout(this[k]);
14968
+ this[k] = null;
14969
+ }
14970
+ }
14920
14971
  /** The user's final line was dispatched to the main agent (its words are the bridge's micro-context). */
14921
- onUserTurn(text, lastWordAgoMs = 0) {
14972
+ onUserTurn(text, lastWordAgoMs = 0, heardCut) {
14922
14973
  this.heard = text.trim();
14974
+ this.said = (heardCut ?? this.reply).trim();
14923
14975
  this.lastWordAgo = Math.max(0, lastWordAgoMs);
14924
14976
  this.floorWords = this.carried + words3(this.heard).length;
14925
14977
  this.lastUser = this.heard;
@@ -14952,7 +15004,7 @@ var SecondChannel = class {
14952
15004
  try {
14953
15005
  this.o.cancel();
14954
15006
  } catch (e) {
14955
- log29.warn(`cancel threw: ${e.message}`);
15007
+ log30.warn(`cancel threw: ${e.message}`);
14956
15008
  }
14957
15009
  }
14958
15010
  }
@@ -15062,7 +15114,7 @@ var SecondChannel = class {
15062
15114
  if (r.nodes.length) tree.grow(r.nodes, this.userSpeaking ? words3(this.heard).length : 0);
15063
15115
  this.o.onTree({ ms: Math.round(this.o.now() - t0), branches: r.nodes.length, lines: r.nodes.flatMap((n) => [n.line, ...n.next.map((k) => k.line)]), ...r.tokens ? { tokens: r.tokens } : {} });
15064
15116
  }, (e) => {
15065
- log29.warn(`tree failed: ${e?.message ?? e}`);
15117
+ log30.warn(`tree failed: ${e?.message ?? e}`);
15066
15118
  this.o.onTree({ ms: Math.round(this.o.now() - t0), branches: 0, error: String(e?.message ?? e) });
15067
15119
  }).finally(() => {
15068
15120
  clearTimeout(late);
@@ -15116,7 +15168,7 @@ var SecondChannel = class {
15116
15168
  if (gen === this.gen && echoesHeard(hit.node.line, heard)) this.askLeaf = { gen, text: hit.node.line };
15117
15169
  return;
15118
15170
  }
15119
- if (hit && steer) return;
15171
+ if (hit && (steer || turnIntent(heard) === "ask")) return;
15120
15172
  if (hit && gen === this.gen && (this.main === "queued" || this.main === "thinking")) {
15121
15173
  this.playLeaf(hit, "working", "bridge");
15122
15174
  if (this.lastKind === "bridge" && this.bridged) {
@@ -15171,7 +15223,7 @@ var SecondChannel = class {
15171
15223
  const opts = this.options;
15172
15224
  if (opts.mode === "chatty" && !opts.aec && !this.degradedLogged) {
15173
15225
  this.degradedLogged = true;
15174
- log29.info("chatty mode without echo cancellation \u2014 normal timing (our lines would re-trigger the mic)");
15226
+ log30.info("chatty mode without echo cancellation \u2014 normal timing (our lines would re-trigger the mic)");
15175
15227
  }
15176
15228
  const rule = this.rule(trigger, pauseMs, breath, cue);
15177
15229
  if (rule === "silence") {
@@ -15190,14 +15242,14 @@ var SecondChannel = class {
15190
15242
  const d = await withBudget(this.o.decide(this.tail(), { ...this.state(pauseMs), rule }, ac.signal), this.o.decisionBudgetMs, "channel decision", ac);
15191
15243
  choice = d?.choice;
15192
15244
  if (choice && choice in CHANNEL_ACTIONS && (choice === "silence" || this.allowed(choice))) kind = choice;
15193
- else if (choice && choice in CHANNEL_ACTIONS) log29.debug(`decider chose ${choice} for a ${rule} moment \u2014 the rule stands`);
15245
+ else if (choice && choice in CHANNEL_ACTIONS) log30.debug(`decider chose ${choice} for a ${rule} moment \u2014 the rule stands`);
15194
15246
  }
15195
15247
  if (kind === "silence") return ev({ choice, acted: "silence" });
15196
15248
  if (stale()) return ev({ choice, kind, acted: "stale" });
15197
15249
  if (!this.allowed(kind)) return ev({ choice, kind, acted: "gated" });
15198
15250
  const react = kind === "backchannel" && !this.answeringUs && this.o.now() - this.lastReactAt >= this.o.reactionGapMs;
15199
15251
  const text = cue && react && !this.recent.some((r) => norm3(r) === norm3(cue.line)) ? cue.line : await this.line(kind, react);
15200
- if (!text) return ev({ choice, kind, acted: "no_bank" });
15252
+ if (!text) return ev({ choice, kind, acted: "no_bank", ...kind === "bridge" && this.ownWords ? { reason: this.noLine || (gen !== this.gen ? "turn moved on" : "no line") } : {} });
15201
15253
  if (stale()) return ev({ choice, kind, text, acted: "stale" });
15202
15254
  if (!this.allowed(kind)) return ev({ choice, kind, text, acted: "gated" });
15203
15255
  const said = this.say(kind, text);
@@ -15224,13 +15276,17 @@ var SecondChannel = class {
15224
15276
  this.bridgeDraft = null;
15225
15277
  this.askLeaf = null;
15226
15278
  this.bridgeReady = Promise.resolve();
15279
+ this.noLine = "";
15227
15280
  if (!this.o.generate || !(this.ownWords || this.o.generateFor.includes("bridge")) || !this.lang || !this.heard) return;
15228
- const gen = this.gen, ac = new AbortController(), own = this.ownWords, heard = this.heard;
15229
- const ctx = { kind: "bridge", heard: this.tail(), state: this.main, avoid: [...this.recent], lang: this.lang, ...own ? { ask: true } : {} };
15281
+ const gen = this.gen, ac = new AbortController(), own = this.ownWords;
15282
+ const said = own ? words3(this.said.replace(/\[[^\]]*\]/g, " ")).slice(-this.o.microWords).join(" ") : "", heard = `${this.heard} ${said}`;
15283
+ const ctx = { kind: "bridge", heard: this.tail(), state: this.main, avoid: [...this.recent], lang: this.lang, ...own ? { ask: true } : {}, ...said ? { said, cut: this.barged } : {} };
15284
+ log30.debug(`bridge ctx: said=${JSON.stringify(ctx.said ?? "")} cut=${!!ctx.cut}`);
15230
15285
  this.bridgeReady = withBudget(this.o.generate(ctx, ac.signal), own ? this.o.bridgeBudgetMs : Math.max(this.o.generateBudgetMs, this.o.bridgeDelayMs), "bridge generate", ac).then((raw) => {
15231
- const text = own && /^\s*none\b/i.test(raw ?? "") ? "" : cleanLine(raw ?? "", ctx.lang);
15232
- if (text && gen === this.gen && (!own || echoesHeard(text, heard))) this.bridgeDraft = { gen, text };
15233
- }).catch((e) => log29.debug(`bridge prefetch failed: ${e?.message ?? e}`));
15286
+ const none = own && /^\s*none\b/i.test(raw ?? ""), text = none ? "" : cleanLine(raw ?? "", ctx.lang), echoes = !own || echoesHeard(text, heard);
15287
+ if (text && gen === this.gen && echoes) this.bridgeDraft = { gen, text };
15288
+ else if (gen === this.gen) this.noLine = raw === null ? "fast model late or failed" : none ? "fast model: none" : !text ? "fast model line unusable" : `line names nothing heard: "${text}"`;
15289
+ }).catch((e) => log30.debug(`bridge prefetch failed: ${e?.message ?? e}`));
15234
15290
  }
15235
15291
  async line(kind, react = true) {
15236
15292
  if (kind === "bridge" && this.ownWords) {
@@ -15257,7 +15313,7 @@ var SecondChannel = class {
15257
15313
  if (raw === null) ac.abort();
15258
15314
  const text = cleanLine(raw ?? "", this.lang);
15259
15315
  if (text && !this.recent.some((r) => norm3(r) === norm3(text))) return text;
15260
- if (text) log29.debug(`generated "${text}" repeats a recent line \u2014 canned`);
15316
+ if (text) log30.debug(`generated "${text}" repeats a recent line \u2014 canned`);
15261
15317
  }
15262
15318
  return this.pick(kind);
15263
15319
  }
@@ -15281,7 +15337,7 @@ var SecondChannel = class {
15281
15337
  try {
15282
15338
  r = this.o.speak(text, kind);
15283
15339
  } catch (e) {
15284
- log29.warn(`speak threw \u2014 line dropped: ${e.message}`);
15340
+ log30.warn(`speak threw \u2014 line dropped: ${e.message}`);
15285
15341
  return false;
15286
15342
  }
15287
15343
  if (r === false) return false;
@@ -15295,7 +15351,7 @@ var SecondChannel = class {
15295
15351
  if (words4) this.o.show(words4, kind);
15296
15352
  const p = Promise.resolve(r).then(() => {
15297
15353
  }, (e) => {
15298
- log29.warn(`channel line playback failed: ${e?.message ?? e}`);
15354
+ log30.warn(`channel line playback failed: ${e?.message ?? e}`);
15299
15355
  }).finally(() => {
15300
15356
  if (this.inflight === p) this.inflight = null;
15301
15357
  });
@@ -15337,20 +15393,28 @@ function channelLine(line, kind) {
15337
15393
  const text = lineWords(line);
15338
15394
  return { type: "channel", kind, text, ...text === line ? {} : { speech: line } };
15339
15395
  }
15396
+ function askPrompt(c, gender) {
15397
+ const last = c.said ? c.said.split(/(?<=[.!?])\s+/).filter((x) => /\w/.test(x)).pop() : "";
15398
+ const said = !c.said ? "" : c.cut ? `You (the assistant) were saying: "\u2026${c.said}" \u2014 they cut you off there, so the last thing they heard was "${last}". Their "that"/"it" means THAT last thing.
15399
+ ` : `You (the assistant) last said: "\u2026${c.said}"
15400
+ `;
15401
+ return `A live voice call. ${said}The user just said: "${c.heard}"
15402
+ Your full answer takes a few seconds. Write ONE spoken line of 2-5 words in ${languageName(c.lang)} to say at once, in their or your own words:
15403
+ - they ask you to look up, check, find or do something \u2192 name the thing and say you are on it ("Hacker News, one sec.")
15404
+ - they ask about something you said ("that", "it", "who", "why") \u2192 echo the thing they mean as a short question ("the OpenAI one?", "the Postman thing?") or a quick reaction to it
15405
+ Never state a fact, a name or an answer that was not already said. If it is a closer, thanks, an ok/yes, small talk or a remark that needs no answer, write: none
15406
+ ${personaHint(gender)} Output only the line.`;
15407
+ }
15340
15408
  function fastLineGenerator(ai, model, gender) {
15341
15409
  return async (c, signal) => {
15342
- const prompt = c.ask ? `A live voice call. The user just said: "${c.heard}"
15343
- If this asks you to look up, check, find or do something that takes a while, write ONE spoken line of 2-5 words in ${languageName(c.lang)} that names the thing in their own words and says you are on it ("Hacker News, one sec."). If it is small talk, a statement, or something you can answer at once, write: none
15344
- ${personaHint(gender)} Output only the line.` : `You voice the tiny side-sounds of a live spoken conversation. Write ONE line of 1-5 words: ${KIND_HINT2[c.kind]}.
15410
+ const prompt = c.ask ? askPrompt(c, gender) : `You voice the tiny side-sounds of a live spoken conversation. Write ONE line of 1-5 words: ${KIND_HINT2[c.kind]}.
15345
15411
  ` + (c.react ? `Here the line may be ${REACT_HINT}.
15346
15412
  ` : "") + (c.tags ? `${TAG_HINT}
15347
15413
  ` : "") + `The user just said: "${c.heard}"
15348
15414
  The assistant is: ${c.state}.
15349
15415
  ` + (c.avoid.length ? `Do not reuse any of: ${c.avoid.map((a) => `"${a}"`).join(", ")}.
15350
15416
  ` : "") + `React to their actual words, casually, in ${languageName(c.lang)}. ${personaHint(gender)} Output only the line.`;
15351
- const reasoning = /gpt-oss/.test(model) ? { providerOptions: { reasoning_effort: "low" } } : {};
15352
- const r = await ai.chat({ model, messages: [{ role: "user", content: prompt }], stream: false, signal, maxTokens: 150, ...reasoning });
15353
- return r.content ?? "";
15417
+ return fastText(ai, { model, prompt, signal });
15354
15418
  };
15355
15419
  }
15356
15420
  function closedQuestion(reply) {
@@ -15361,7 +15425,7 @@ function closedQuestion(reply) {
15361
15425
  }
15362
15426
 
15363
15427
  // src/voice/call.ts
15364
- var log30 = forComponent("VoiceCall");
15428
+ var log31 = forComponent("VoiceCall");
15365
15429
  function newWords(text, turn) {
15366
15430
  const said = new Set(norm3(turn).split(" "));
15367
15431
  return norm3(text).split(" ").filter((w) => w && !said.has(w)).length;
@@ -15378,6 +15442,9 @@ var VoiceCallOptions = class {
15378
15442
  * runs as MAIN's next turn. Not injected mid-run: that makes MAIN run again just to hear a remark. Absent: such a line
15379
15443
  * barges in as before. */
15380
15444
  noteTurn;
15445
+ /** What the user HEARD of MAIN's reply a barge just cut (a peek — the host still takes the cut for MAIN), else null:
15446
+ * a live bridge echoes what their "that" points at. */
15447
+ heardCut;
15381
15448
  /** Writes that immediate answer (fastWorkReply). */
15382
15449
  workReply;
15383
15450
  workReplyBudgetMs = 1500;
@@ -15516,7 +15583,7 @@ var VoiceCall = class {
15516
15583
  const c = this.cur, steers = !!this.o.noteTurn && this.working;
15517
15584
  const resumed = !steers || c.marks.mainFirst === void 0 && this.o.now() - c.at < this.o.resumeMs;
15518
15585
  if (this.o.mode === "live" && c?.running && !c.worded && resumed && newWords(text, c.text) >= 2) {
15519
- log30.debug("user resumed before the reply \u2014 yielded");
15586
+ log31.debug("user resumed before the reply \u2014 yielded");
15520
15587
  this.giveWay(c);
15521
15588
  this.gate.reopen(c.id);
15522
15589
  }
@@ -15535,9 +15602,13 @@ var VoiceCall = class {
15535
15602
  this.sttLang = o.lang ? primaryLang(o.lang) : null;
15536
15603
  this.lastWordAt = typeof lastWordAgoMs === "number" && lastWordAgoMs >= 0 ? now4 - lastWordAgoMs : null;
15537
15604
  this.finalAt = now4;
15605
+ this.floor = `${this.floor} ${text}`.trim();
15606
+ if (!endsMidPhrase(text) && turnIntent(this.floor) !== "say") this.fill.onLineEnd();
15538
15607
  this.gate.final(text, sttId);
15539
15608
  }
15540
15609
  finalAt = 0;
15610
+ floor = "";
15611
+ // the finals said since the last turn went out
15541
15612
  sttLang = null;
15542
15613
  // the STT's language for the final being followed
15543
15614
  /** The host's player started a line's audio now (or in `inMs`): `fill`/`progress` = the fill channel's, `main` = MAIN's
@@ -15637,7 +15708,7 @@ var VoiceCall = class {
15637
15708
  try {
15638
15709
  this.o.cancel();
15639
15710
  } catch (e) {
15640
- log30.warn(`cancel threw: ${e.message}`);
15711
+ log31.warn(`cancel threw: ${e.message}`);
15641
15712
  }
15642
15713
  return;
15643
15714
  }
@@ -15649,7 +15720,7 @@ var VoiceCall = class {
15649
15720
  try {
15650
15721
  this.o.cancel();
15651
15722
  } catch (e) {
15652
- log30.warn(`cancel threw: ${e.message}`);
15723
+ log31.warn(`cancel threw: ${e.message}`);
15653
15724
  }
15654
15725
  if (c?.running) {
15655
15726
  c.running = false;
@@ -15701,6 +15772,7 @@ var VoiceCall = class {
15701
15772
  if (l) this.fill.setLanguage(l, true);
15702
15773
  }
15703
15774
  onTurn(t) {
15775
+ this.floor = "";
15704
15776
  if (this.o.noteTurn && this.o.workReply && t.kind !== "replace" && this.working && !isClosing(t.text)) return void this.overWork(this.cur, t);
15705
15777
  const now4 = this.o.now(), lastWord = this.lastWordAt !== null;
15706
15778
  const at = this.lastWordAt ?? this.firstFinalAt ?? now4;
@@ -15720,13 +15792,14 @@ var VoiceCall = class {
15720
15792
  this.progress.turn();
15721
15793
  this.o.onMetric({ name: "turn", id: t.id, kind: t.kind, text: t.text });
15722
15794
  this.o.sendTurn(t.text, { id: t.id, ...t.replaces ? { replaces: t.replaces } : {} });
15723
- if (t.kind === "new") this.fill.onUserTurn(t.text, now4 - at);
15795
+ if (t.kind === "new") this.fill.onUserTurn(t.text, now4 - at, this.o.heardCut?.() ?? void 0);
15724
15796
  }
15725
15797
  onDrop(text, why) {
15726
15798
  if (!this.gate.holding) {
15727
15799
  this.firstFinalAt = null;
15728
15800
  this.lastWordAt = null;
15729
15801
  this.earlyHeard = null;
15802
+ this.floor = "";
15730
15803
  }
15731
15804
  this.o.onMetric({ name: "drop", kind: why, text });
15732
15805
  }
@@ -15737,7 +15810,7 @@ var VoiceCall = class {
15737
15810
  try {
15738
15811
  r = this.o.speak(text, kind);
15739
15812
  } catch (e) {
15740
- log30.warn(`speak threw: ${e.message}`);
15813
+ log31.warn(`speak threw: ${e.message}`);
15741
15814
  return false;
15742
15815
  }
15743
15816
  if (r === false) return false;
@@ -15797,7 +15870,7 @@ var VoiceCall = class {
15797
15870
  this.o.onMetric({ name: "turn", id: t.id, kind: "aside", text: t.text });
15798
15871
  const ac = new AbortController(), late = setTimeout(() => ac.abort(), this.o.workReplyBudgetMs), lang = this.lang;
15799
15872
  const raw = lang ? await this.o.workReply({ request: c.text, heard: t.text, tool: c.tool, hint: argsHint(c.args), lang, avoid: this.progress.recent }, ac.signal).catch((e) => {
15800
- log30.warn(`work reply failed \u2014 MAIN only: ${e?.message ?? e}`);
15873
+ log31.warn(`work reply failed \u2014 MAIN only: ${e?.message ?? e}`);
15801
15874
  return "";
15802
15875
  }).finally(() => clearTimeout(late)) : "";
15803
15876
  const own = cleanWorkReply(raw, lang ?? ""), answer = own || workAck(raw, lang ?? "", this.o.gender);
@@ -15880,7 +15953,7 @@ init_logging();
15880
15953
  init_platform();
15881
15954
  import { spawn } from "child_process";
15882
15955
  import { createHash } from "crypto";
15883
- var log31 = forComponent("mcp");
15956
+ var log32 = forComponent("mcp");
15884
15957
  var PROTOCOL_VERSION = "2025-06-18";
15885
15958
  var DEFAULT_TIMEOUT_MS = 3e4;
15886
15959
  var DEFAULT_CALL_TIMEOUT_MS = 30 * 6e4;
@@ -15912,7 +15985,7 @@ var StdioTransport = class {
15912
15985
  proc.stdout.setEncoding("utf8");
15913
15986
  proc.stdout.on("data", (chunk) => this.onData(chunk));
15914
15987
  proc.stderr.setEncoding("utf8");
15915
- proc.stderr.on("data", (chunk) => log31.debug(`[${command}] stderr:`, chunk.trimEnd()));
15988
+ proc.stderr.on("data", (chunk) => log32.debug(`[${command}] stderr:`, chunk.trimEnd()));
15916
15989
  proc.on("exit", (code) => this.failAll(new Error(`MCP server "${command}" exited (code ${code})`)));
15917
15990
  proc.on("error", (e) => this.failAll(e instanceof Error ? e : new Error(String(e))));
15918
15991
  }
@@ -15926,7 +15999,7 @@ var StdioTransport = class {
15926
15999
  try {
15927
16000
  this.dispatch(JSON.parse(line));
15928
16001
  } catch (e) {
15929
- log31.debug("dropping non-JSON line from MCP server:", line, e);
16002
+ log32.debug("dropping non-JSON line from MCP server:", line, e);
15930
16003
  }
15931
16004
  }
15932
16005
  }
@@ -15936,7 +16009,7 @@ var StdioTransport = class {
15936
16009
  try {
15937
16010
  p2?.onProgress?.(msg.params ?? {});
15938
16011
  } catch (e) {
15939
- log31.debug("onProgress handler threw", e);
16012
+ log32.debug("onProgress handler threw", e);
15940
16013
  }
15941
16014
  return;
15942
16015
  }
@@ -15974,7 +16047,7 @@ var StdioTransport = class {
15974
16047
  const onAbort = () => {
15975
16048
  if (!this.pending.delete(id)) return;
15976
16049
  clearTimeout(timer);
15977
- this.notify("notifications/cancelled", { requestId: id, reason: String(signal?.reason?.message ?? "cancelled") }).catch((e) => log31.debug("cancel notify failed", e));
16050
+ this.notify("notifications/cancelled", { requestId: id, reason: String(signal?.reason?.message ?? "cancelled") }).catch((e) => log32.debug("cancel notify failed", e));
15978
16051
  reject(abortError(signal));
15979
16052
  };
15980
16053
  const done = () => signal?.removeEventListener("abort", onAbort);
@@ -15998,7 +16071,7 @@ var StdioTransport = class {
15998
16071
  try {
15999
16072
  this.proc?.stdin?.end();
16000
16073
  } catch (e) {
16001
- log31.debug("stdin end failed", e);
16074
+ log32.debug("stdin end failed", e);
16002
16075
  }
16003
16076
  if (!(IS_WIN && killTree(this.proc?.pid, "SIGTERM"))) this.proc?.kill();
16004
16077
  }
@@ -16033,7 +16106,7 @@ var HttpTransport = class {
16033
16106
  return await this.post({ jsonrpc: "2.0", id, method, params: opts.onProgress ? withProgressToken(params, id) : params }, false, signal, opts.onProgress);
16034
16107
  } catch (e) {
16035
16108
  if (opts.signal?.aborted) {
16036
- void this.notify("notifications/cancelled", { requestId: id, reason: String(opts.signal.reason?.message ?? "cancelled") }).catch((err2) => log31.debug("cancel notify failed", err2));
16109
+ void this.notify("notifications/cancelled", { requestId: id, reason: String(opts.signal.reason?.message ?? "cancelled") }).catch((err2) => log32.debug("cancel notify failed", err2));
16037
16110
  throw abortError(opts.signal);
16038
16111
  }
16039
16112
  throw e;
@@ -16076,7 +16149,7 @@ function sseMessage(line) {
16076
16149
  try {
16077
16150
  return JSON.parse(trimmed.slice(5).trim());
16078
16151
  } catch (e) {
16079
- log31.debug("skipping unparseable SSE data line", e);
16152
+ log32.debug("skipping unparseable SSE data line", e);
16080
16153
  return void 0;
16081
16154
  }
16082
16155
  }
@@ -16086,7 +16159,7 @@ async function readSseResponse(resp, id, onProgress) {
16086
16159
  try {
16087
16160
  onProgress?.(obj.params ?? {});
16088
16161
  } catch (e) {
16089
- log31.debug("onProgress handler threw", e);
16162
+ log32.debug("onProgress handler threw", e);
16090
16163
  }
16091
16164
  return void 0;
16092
16165
  }
@@ -16185,7 +16258,7 @@ async function mountWithDeadline(name, cfg, mountTimeoutMs) {
16185
16258
  return { name, client, tools, specs, serverInfo: init?.serverInfo, config: cfg };
16186
16259
  })(), mountTimeoutMs, name);
16187
16260
  } catch (e) {
16188
- await client.close().catch((err2) => log31.debug(`close after failed mount of "${name}": ${err2}`));
16261
+ await client.close().catch((err2) => log32.debug(`close after failed mount of "${name}": ${err2}`));
16189
16262
  throw e;
16190
16263
  }
16191
16264
  }
@@ -16196,15 +16269,15 @@ function validEntries(servers) {
16196
16269
  return Object.entries(servers).filter(([name, cfg]) => {
16197
16270
  if (!cfg || cfg.disabled) return false;
16198
16271
  if (!cfg.command && !cfg.url) {
16199
- log31.warn(`MCP server "${name}" needs a command (stdio) or url (http) \u2014 skipping`);
16272
+ log32.warn(`MCP server "${name}" needs a command (stdio) or url (http) \u2014 skipping`);
16200
16273
  return false;
16201
16274
  }
16202
16275
  return true;
16203
16276
  });
16204
16277
  }
16205
16278
  function logMountFailure(name, e) {
16206
- if (e instanceof McpAuthError) log31.warn(`MCP "${name}" needs-auth: HTTP ${e.status} \u2014 set bearerToken or headers in its config; skipping`);
16207
- else log31.error(`MCP server "${name}" failed to mount: ${e?.message ?? e}`);
16279
+ if (e instanceof McpAuthError) log32.warn(`MCP "${name}" needs-auth: HTTP ${e.status} \u2014 set bearerToken or headers in its config; skipping`);
16280
+ else log32.error(`MCP server "${name}" failed to mount: ${e?.message ?? e}`);
16208
16281
  }
16209
16282
  async function mountMcpServers(servers = {}, opts = {}) {
16210
16283
  const entries = validEntries(servers);
@@ -16214,7 +16287,7 @@ async function mountMcpServers(servers = {}, opts = {}) {
16214
16287
  const name = entries[i][0];
16215
16288
  if (r.status === "fulfilled") {
16216
16289
  out.push(r.value);
16217
- log31.debug(`MCP "${name}" mounted \u2014 ${r.value.tools.length} tool(s)${r.value.serverInfo?.name ? ` from ${r.value.serverInfo.name}` : ""}`);
16290
+ log32.debug(`MCP "${name}" mounted \u2014 ${r.value.tools.length} tool(s)${r.value.serverInfo?.name ? ` from ${r.value.serverInfo.name}` : ""}`);
16218
16291
  } else logMountFailure(name, r.reason);
16219
16292
  });
16220
16293
  return out;
@@ -16254,7 +16327,7 @@ var McpPool = class {
16254
16327
  const prev = this.warm.get(key);
16255
16328
  if (prev) {
16256
16329
  clearTimeout(prev.timer);
16257
- if (prev.client !== client) void prev.client.close().catch((err2) => log31.debug(`warm-pool replace close failed: ${err2}`));
16330
+ if (prev.client !== client) void prev.client.close().catch((err2) => log32.debug(`warm-pool replace close failed: ${err2}`));
16258
16331
  }
16259
16332
  const e = { client, timer: void 0 };
16260
16333
  this.warm.set(key, e);
@@ -16271,7 +16344,7 @@ var McpPool = class {
16271
16344
  const e = this.warm.get(key);
16272
16345
  if (!e) return;
16273
16346
  this.warm.delete(key);
16274
- await e.client.close().catch((err2) => log31.debug(`warm-pool evict close failed: ${err2}`));
16347
+ await e.client.close().catch((err2) => log32.debug(`warm-pool evict close failed: ${err2}`));
16275
16348
  }
16276
16349
  async closeAll() {
16277
16350
  for (const e of this.warm.values()) {
@@ -16517,7 +16590,7 @@ init_tools_shell();
16517
16590
  // src/tools.notify.ts
16518
16591
  init_logging();
16519
16592
  import { execFile as execFile2 } from "child_process";
16520
- var log33 = forComponent("notify");
16593
+ var log34 = forComponent("notify");
16521
16594
  var WIN_TOAST = [
16522
16595
  "[Windows.UI.Notifications.ToastNotificationManager, Windows.UI.Notifications, ContentType = WindowsRuntime] | Out-Null",
16523
16596
  "$t = [Windows.UI.Notifications.ToastNotificationManager]::GetTemplateContent([Windows.UI.Notifications.ToastTemplateType]::ToastText02)",
@@ -16548,7 +16621,7 @@ function makeNotifyTool(opts = {}) {
16548
16621
  return new Promise((resolve6) => {
16549
16622
  run(argv[0], argv[1], { timeout: 5e3, ...extra }, (e) => {
16550
16623
  if (e) {
16551
- log33.debug("notification failed", e);
16624
+ log34.debug("notification failed", e);
16552
16625
  resolve6(`Notification failed: ${e.message}`);
16553
16626
  } else resolve6("Notification shown.");
16554
16627
  });
@@ -16565,7 +16638,7 @@ init_logging();
16565
16638
  import { existsSync as existsSync2, readFileSync as readFileSync5 } from "fs";
16566
16639
  import { homedir } from "os";
16567
16640
  import { delimiter as delimiter2 } from "path";
16568
- var log34 = forComponent("cli-util");
16641
+ var log35 = forComponent("cli-util");
16569
16642
  function extraDirs(env = process.env) {
16570
16643
  return (env.AGENTX_EXTRA_DIRS || "").split(delimiter2).map((d) => d.trim()).filter(Boolean);
16571
16644
  }
@@ -16585,7 +16658,7 @@ function parseJson(text, fallback, what = "json") {
16585
16658
  try {
16586
16659
  return JSON.parse(text);
16587
16660
  } catch (e) {
16588
- log34.debug(`parseJson(${what}) failed: ${e.message}`);
16661
+ log35.debug(`parseJson(${what}) failed: ${e.message}`);
16589
16662
  return fallback;
16590
16663
  }
16591
16664
  }
@@ -16595,7 +16668,7 @@ function readJsonFile(path, fallback) {
16595
16668
  try {
16596
16669
  text = readFileSync5(path, "utf8");
16597
16670
  } catch (e) {
16598
- log34.debug(`readJsonFile(${path}) unreadable: ${e.message}`);
16671
+ log35.debug(`readJsonFile(${path}) unreadable: ${e.message}`);
16599
16672
  return fallback;
16600
16673
  }
16601
16674
  return parseJson(text, fallback, path);
@@ -16909,7 +16982,7 @@ import { appendFileSync, existsSync as existsSync4, mkdirSync as mkdirSync5, rea
16909
16982
  import { homedir as homedir3 } from "os";
16910
16983
  import { dirname as dirname4, join as join8 } from "path";
16911
16984
  import { fileURLToPath } from "url";
16912
- var log35 = forComponent("VoiceIO");
16985
+ var log36 = forComponent("VoiceIO");
16913
16986
  var now3 = () => performance.now();
16914
16987
  var Player = class {
16915
16988
  proc = null;
@@ -16923,7 +16996,7 @@ var Player = class {
16923
16996
  ["-loglevel", "quiet", "-nodisp", "-fflags", "nobuffer", "-flags", "low_delay", "-probesize", "32", "-f", "s16le", "-ar", String(TTS_SAMPLE_RATE), "-ch_layout", "mono", "-i", "-"],
16924
16997
  { stdio: ["pipe", "ignore", "ignore"] }
16925
16998
  );
16926
- this.proc.on("error", (e) => log35.warn(`ffplay error: ${e.message}`));
16999
+ this.proc.on("error", (e) => log36.warn(`ffplay error: ${e.message}`));
16927
17000
  this.proc.stdin.on("error", () => {
16928
17001
  });
16929
17002
  this.bytesWritten = 0;
@@ -16961,7 +17034,7 @@ function detectFfmpegMic() {
16961
17034
  const devices = [...audio.matchAll(/\[(\d+)\] (.+)/g)].map(([, idx, name]) => ({ idx, name: name.trim() }));
16962
17035
  const mic = devices.find((d) => /microphone|built-in/i.test(d.name) && !/teams|blackhole|loopback/i.test(d.name)) ?? devices[0];
16963
17036
  if (!mic) throw new Error("no audio input device found");
16964
- log35.debug(`ffmpeg mic: [${mic.idx}] ${mic.name}`);
17037
+ log36.debug(`ffmpeg mic: [${mic.idx}] ${mic.name}`);
16965
17038
  return `:${mic.idx}`;
16966
17039
  }
16967
17040
  function detectDshowMic() {
@@ -16972,7 +17045,7 @@ function detectDshowMic() {
16972
17045
  const devices = [...(r.stderr ?? "").matchAll(/"([^"]+)"\s*\(audio\)/g)].map((m) => m[1]);
16973
17046
  const mic = devices.find((d) => !/stereo mix|loopback|virtual|cable|teams/i.test(d)) ?? devices[0];
16974
17047
  if (!mic) throw new Error("no audio input device found (set MIC_DEVICE to the DirectShow device name)");
16975
- log35.debug(`ffmpeg dshow mic: ${mic}`);
17048
+ log36.debug(`ffmpeg dshow mic: ${mic}`);
16976
17049
  return `audio=${mic}`;
16977
17050
  }
16978
17051
  function detectedInputDevice() {
@@ -17008,15 +17081,15 @@ function resolveAecBinary() {
17008
17081
  if (existsSync4(bin) && statSync6(bin).mtimeMs >= statSync6(src).mtimeMs) return bin;
17009
17082
  if (spawnSync3("which", ["swiftc"]).status !== 0) return null;
17010
17083
  mkdirSync5(cacheDir, { recursive: true });
17011
- log35.info("compiling AEC mic helper (first run)\u2026");
17084
+ log36.info("compiling AEC mic helper (first run)\u2026");
17012
17085
  const build = spawnSync3("swiftc", ["-O", "-o", bin, src, "-Xlinker", "-sectcreate", "-Xlinker", "__TEXT", "-Xlinker", "__info_plist", "-Xlinker", plist], { encoding: "utf8" });
17013
17086
  if (build.status !== 0) {
17014
- log35.warn(`AEC build failed: ${build.stderr?.slice(0, 400)}`);
17087
+ log36.warn(`AEC build failed: ${build.stderr?.slice(0, 400)}`);
17015
17088
  return null;
17016
17089
  }
17017
17090
  const sign = spawnSync3("codesign", ["-fs", "-", bin], { encoding: "utf8" });
17018
17091
  if (sign.status !== 0) {
17019
- log35.warn(`codesign failed: ${sign.stderr?.slice(0, 200)}`);
17092
+ log36.warn(`codesign failed: ${sign.stderr?.slice(0, 200)}`);
17020
17093
  return null;
17021
17094
  }
17022
17095
  return bin;
@@ -17058,17 +17131,17 @@ var NodeMicSource = class {
17058
17131
  this.proc = spawn2(this.bin, [], { stdio: ["ignore", "pipe", "ignore"] });
17059
17132
  } else {
17060
17133
  if (!hasCommand("ffmpeg")) throw new Error("voice I/O unavailable: no AEC helper and no ffmpeg on PATH");
17061
- log35.info("mic: raw capture (no AEC) \u2014 echo handled heuristically; headphones recommended");
17134
+ log36.info("mic: raw capture (no AEC) \u2014 echo handled heuristically; headphones recommended");
17062
17135
  const input = process.platform === "win32" ? ["-f", "dshow", "-i", detectDshowMic()] : ["-f", "avfoundation", "-i", detectFfmpegMic()];
17063
17136
  this.proc = spawn2(
17064
17137
  "ffmpeg",
17065
17138
  ["-loglevel", "error", ...input, "-ar", String(STT_SAMPLE_RATE), "-ac", "1", "-f", "s16le", "-"],
17066
17139
  { stdio: ["ignore", "pipe", "pipe"], ...process.platform === "win32" ? { windowsHide: true } : {} }
17067
17140
  );
17068
- this.proc.stderr.on("data", (d) => log35.warn(`ffmpeg: ${String(d).trim()}`));
17141
+ this.proc.stderr.on("data", (d) => log36.warn(`ffmpeg: ${String(d).trim()}`));
17069
17142
  }
17070
17143
  this.proc.on("exit", (c) => {
17071
- if (c && !this.stopped) log35.error(`mic capture exited (${c}) \u2014 check mic permission / MIC_DEVICE / MIC_AEC=0`);
17144
+ if (c && !this.stopped) log36.error(`mic capture exited (${c}) \u2014 check mic permission / MIC_DEVICE / MIC_AEC=0`);
17072
17145
  });
17073
17146
  this.proc.stdout.on("data", (chunk) => onChunk(chunk));
17074
17147
  }
@@ -17134,7 +17207,7 @@ var AecDuplexAudio = class {
17134
17207
  this.proc.stdin.on("error", () => {
17135
17208
  });
17136
17209
  this.proc.on("exit", (c) => {
17137
- if (c && !this.stopped) log35.error(`aec duplex audio exited (${c}) \u2014 check mic permission / MIC_AEC=0`);
17210
+ if (c && !this.stopped) log36.error(`aec duplex audio exited (${c}) \u2014 check mic permission / MIC_AEC=0`);
17138
17211
  });
17139
17212
  this.proc.stdout.on("data", (chunk) => {
17140
17213
  this.gotChunk = true;
@@ -17150,7 +17223,7 @@ var AecDuplexAudio = class {
17150
17223
  openMicSettings();
17151
17224
  this.onFatal?.("microphone permission denied \u2014 enable it in System Settings \u2192 Privacy & Security \u2192 Microphone for your terminal, then restart it");
17152
17225
  }
17153
- } else log35.debug(`mic-aec: ${s}`);
17226
+ } else log36.debug(`mic-aec: ${s}`);
17154
17227
  }
17155
17228
  });
17156
17229
  if (!this.noVpio && !this.triedFallback) {
@@ -17159,7 +17232,7 @@ var AecDuplexAudio = class {
17159
17232
  this.triedFallback = true;
17160
17233
  this.noVpio = true;
17161
17234
  this._aec = false;
17162
- log35.warn("mic-aec: VPIO delivered no audio in 2.5s \u2014 falling back to non-VPIO capture (no AEC \u2192 half-duplex, no barge-in)");
17235
+ log36.warn("mic-aec: VPIO delivered no audio in 2.5s \u2014 falling back to non-VPIO capture (no AEC \u2192 half-duplex, no barge-in)");
17163
17236
  this.onDegrade?.();
17164
17237
  this.killProc();
17165
17238
  this.spawnHelper();
@@ -17330,7 +17403,7 @@ function bindAckInstinct(v, instinct) {
17330
17403
  if (ev.kind === "ack_fired") instinct.ackOutcome(String(ev.phrase));
17331
17404
  else if (ev.kind === "ack_skipped" || ev.kind === "ack_cancelled") instinct.ackOutcome(null);
17332
17405
  } catch (e) {
17333
- log35.warn(`ack outcome tap failed: ${e instanceof Error ? e.message : e}`);
17406
+ log36.warn(`ack outcome tap failed: ${e instanceof Error ? e.message : e}`);
17334
17407
  }
17335
17408
  onDiag(ev);
17336
17409
  };
@@ -17388,10 +17461,19 @@ function bindVoiceCall(v, call, live, decideMs = 900) {
17388
17461
  const { onPartial, onState, onBargeIn, onDiag } = o;
17389
17462
  let own = false;
17390
17463
  const take = v.takeInterruptedReply.bind(v);
17391
- v.takeInterruptedReply = () => {
17464
+ let held2;
17465
+ const ownCut = () => {
17392
17466
  const r = take();
17393
- if (!r || !call.spoke(r.full)) return r;
17394
- return r.queued.length ? { ...r, full: "", heard: "" } : null;
17467
+ return !r || !call.spoke(r.full) ? r : r.queued.length ? { ...r, full: "", heard: "" } : null;
17468
+ };
17469
+ v.takeInterruptedReply = () => {
17470
+ const r = held2 !== void 0 ? held2 : ownCut();
17471
+ held2 = void 0;
17472
+ return r;
17473
+ };
17474
+ call.options.heardCut = () => {
17475
+ held2 ??= ownCut();
17476
+ return held2?.full ? cutHeard(held2) : null;
17395
17477
  };
17396
17478
  o.onPartial = (t) => {
17397
17479
  if (live() && (own || !v.audible)) call.interim(t, performance.now(), v.usingAec);
@@ -17401,7 +17483,17 @@ function bindVoiceCall(v, call, live, decideMs = 900) {
17401
17483
  if (live() && !own && s === "speaking") call.main({ type: "audio" });
17402
17484
  onState(s);
17403
17485
  };
17486
+ let filling = false;
17487
+ const beginSpeech = v.beginSpeech.bind(v);
17488
+ v.beginSpeech = ((...a) => {
17489
+ if (own && !filling && live()) {
17490
+ own = false;
17491
+ call.main({ type: "audio" }, v.player?.drainMs() ?? 0);
17492
+ }
17493
+ return beginSpeech(...a);
17494
+ });
17404
17495
  o.onBargeIn = (phase) => {
17496
+ held2 = void 0;
17405
17497
  if (live()) call.barge();
17406
17498
  onBargeIn(phase);
17407
17499
  };
@@ -17422,7 +17514,12 @@ function bindVoiceCall(v, call, live, decideMs = 900) {
17422
17514
  if (!live() || v.audible) return false;
17423
17515
  if (kind === "backchannel") return speakBlip(v, text);
17424
17516
  own = true;
17425
- v.speakFiller(text);
17517
+ filling = true;
17518
+ try {
17519
+ v.speakFiller(text);
17520
+ } finally {
17521
+ filling = false;
17522
+ }
17426
17523
  return v.awaitIdle().finally(() => {
17427
17524
  own = false;
17428
17525
  });
@@ -17452,7 +17549,7 @@ function speakBlip(v, text) {
17452
17549
  v.fireBackchannel();
17453
17550
  return true;
17454
17551
  } catch (e) {
17455
- log35.warn(`backchannel blip failed \u2014 line dropped: ${e.message}`);
17552
+ log36.warn(`backchannel blip failed \u2014 line dropped: ${e.message}`);
17456
17553
  return false;
17457
17554
  } finally {
17458
17555
  E.BACKCHANNELS = pool;
@@ -17471,7 +17568,7 @@ function channelInput(sc, m) {
17471
17568
  }
17472
17569
  if (m.type === "agent_state") {
17473
17570
  if (typeof m.state === "string" && MAIN_STATES.has(m.state)) sc.onAgentState(m.state);
17474
- else log35.warn(`agent_state: unknown state ${JSON.stringify(m.state)} \u2014 ignored`);
17571
+ else log36.warn(`agent_state: unknown state ${JSON.stringify(m.state)} \u2014 ignored`);
17475
17572
  return true;
17476
17573
  }
17477
17574
  return false;
@@ -17597,7 +17694,7 @@ function fakeVoiceParts(uttFile) {
17597
17694
  return { stt, tts, player };
17598
17695
  }
17599
17696
  function fakeTape(heardFile, saidFile) {
17600
- const CHAR = TTS_SAMPLE_RATE * 2 * 60 / 1e3;
17697
+ const CHAR = TTS_SAMPLE_RATE * 2 / 15;
17601
17698
  const makeTts = () => {
17602
17699
  const t = {
17603
17700
  connect() {
@@ -17681,7 +17778,7 @@ function fakeTape(heardFile, saidFile) {
17681
17778
  init_logging();
17682
17779
  import { appendFile, mkdirSync as mkdirSync6 } from "fs";
17683
17780
  import { dirname as dirname5 } from "path";
17684
- var log36 = forComponent("VoiceDiag");
17781
+ var log37 = forComponent("VoiceDiag");
17685
17782
  var JsonlDiagSink = class {
17686
17783
  constructor(path) {
17687
17784
  this.path = path;
@@ -17722,7 +17819,7 @@ var JsonlDiagSink = class {
17722
17819
  disable(e) {
17723
17820
  this.disabled = true;
17724
17821
  this.queue.length = 0;
17725
- log36.debug(`voice diag sink disabled (${this.path}): ${e instanceof Error ? e.message : e}`);
17822
+ log37.debug(`voice diag sink disabled (${this.path}): ${e instanceof Error ? e.message : e}`);
17726
17823
  }
17727
17824
  /** True once a failure permanently disabled the sink (tests/inspection). */
17728
17825
  get isDisabled() {
@@ -17790,7 +17887,7 @@ var SpokenFilter = class {
17790
17887
 
17791
17888
  // src/voice/greeting.ts
17792
17889
  init_logging();
17793
- var log37 = forComponent("CallGreeting");
17890
+ var log38 = forComponent("CallGreeting");
17794
17891
  var CallGreetingOptions = class {
17795
17892
  model = "groq/openai/gpt-oss-120b";
17796
17893
  persona = "";
@@ -17803,7 +17900,6 @@ async function callGreeting(ai, options) {
17803
17900
  ${o.persona}
17804
17901
 
17805
17902
  ` : ""}You open a live voice call. Write ONE short spoken sentence that greets the caller and asks what they would like to do. Keep the persona's tone tags if it uses them. Output only the line.`;
17806
- const reasoning = /gpt-oss/.test(o.model) ? { providerOptions: { reasoning_effort: "low" } } : {};
17807
17903
  let timer;
17808
17904
  const late = new Promise((r) => {
17809
17905
  timer = setTimeout(() => {
@@ -17811,8 +17907,8 @@ ${o.persona}
17811
17907
  r("");
17812
17908
  }, o.budgetMs);
17813
17909
  });
17814
- const asked = Promise.resolve(ai.chat({ model: o.model, messages: [{ role: "user", content: prompt }], stream: false, signal: ac.signal, maxTokens: 200, ...reasoning })).then((r) => (r.content ?? "").trim().split("\n")[0].replace(/^["']|["']$/g, "")).catch((e) => {
17815
- log37.warn(`greeting failed \u2014 canned line: ${e?.message ?? e}`);
17910
+ const asked = fastText(ai, { model: o.model, prompt, signal: ac.signal, maxTokens: 200 }).then((r) => r.trim().split("\n")[0].replace(/^["']|["']$/g, "")).catch((e) => {
17911
+ log38.warn(`greeting failed \u2014 canned line: ${e?.message ?? e}`);
17816
17912
  return "";
17817
17913
  });
17818
17914
  const line = await Promise.race([asked, late]);
@@ -17967,7 +18063,7 @@ function applyOverlay(cfg, file) {
17967
18063
  // cli/hooks-config.ts
17968
18064
  import { spawnSync as spawnSync4 } from "child_process";
17969
18065
  init_platform();
17970
- var log38 = forComponent("hooks");
18066
+ var log39 = forComponent("hooks");
17971
18067
  var escapeRegex = (s) => s.replace(/[.+^${}()|[\]\\]/g, "\\$&");
17972
18068
  function ruleMatches(rule, toolName) {
17973
18069
  if (!rule.tool || rule.tool === "*") return true;
@@ -17986,7 +18082,7 @@ function runCmd(rule, env) {
17986
18082
  });
17987
18083
  return { code: r.status ?? 1, out: ((r.stdout ?? "") + (r.stderr ?? "")).trim() };
17988
18084
  } catch (e) {
17989
- log38.debug(`hook command failed: ${rule.command}`, e);
18085
+ log39.debug(`hook command failed: ${rule.command}`, e);
17990
18086
  return { code: 1, out: String(e?.message ?? e) };
17991
18087
  }
17992
18088
  }
@@ -18094,7 +18190,7 @@ import { existsSync as existsSync6, mkdirSync as mkdirSync8, readFileSync as rea
18094
18190
  import { homedir as homedir6 } from "os";
18095
18191
  import { join as join11 } from "path";
18096
18192
  init_platform();
18097
- var log39 = forComponent("session");
18193
+ var log40 = forComponent("session");
18098
18194
  var globalDir = () => join11(homedir6(), ".agent", "sessions");
18099
18195
  function indexLink(target, link2) {
18100
18196
  try {
@@ -18157,7 +18253,7 @@ var SessionStore = class {
18157
18253
  }
18158
18254
  load(id) {
18159
18255
  if (!this.safeId(id)) {
18160
- log39.debug(`rejecting unsafe session id: ${id}`);
18256
+ log40.debug(`rejecting unsafe session id: ${id}`);
18161
18257
  return void 0;
18162
18258
  }
18163
18259
  const path = join11(this.dir, `${id}.json`);
@@ -18165,7 +18261,7 @@ var SessionStore = class {
18165
18261
  try {
18166
18262
  return JSON.parse(readFileSync8(path, "utf8"));
18167
18263
  } catch (e) {
18168
- log39.debug(`unreadable session ${id} \u2014 ignoring`, e);
18264
+ log40.debug(`unreadable session ${id} \u2014 ignoring`, e);
18169
18265
  return void 0;
18170
18266
  }
18171
18267
  }
@@ -18178,7 +18274,7 @@ var SessionStore = class {
18178
18274
  try {
18179
18275
  metas.push(JSON.parse(readFileSync8(join11(this.dir, f), "utf8")).meta);
18180
18276
  } catch (e) {
18181
- log39.debug(`skipping unreadable session file ${f}`, e);
18277
+ log40.debug(`skipping unreadable session file ${f}`, e);
18182
18278
  }
18183
18279
  }
18184
18280
  return metas.sort((a, b) => b.updated - a.updated);
@@ -18610,7 +18706,7 @@ import { promisify } from "util";
18610
18706
  import { writeFileSync as writeFileSync6, mkdirSync as mkdirSync9 } from "fs";
18611
18707
  import { homedir as homedir7 } from "os";
18612
18708
  import { join as join12, resolve as resolve4, sep as sep3, parse as parsePath } from "path";
18613
- var log40 = forComponent("checkpoints");
18709
+ var log41 = forComponent("checkpoints");
18614
18710
  var exec = promisify(execFile4);
18615
18711
  var DEFAULT_EXCLUDE = [".agent/", ".git/", "node_modules/", "dist/", "build/", ".next/", "target/", ".venv/", "__pycache__/", "*.log"];
18616
18712
  function isBroadRoot(p) {
@@ -18658,7 +18754,7 @@ var ShadowRepo = class {
18658
18754
  writeFileSync6(join12(this.gitDir, "info", "exclude"), this.exclude.join("\n") + "\n");
18659
18755
  this.ready = true;
18660
18756
  } catch (e) {
18661
- log40.debug(`git checkpoints unavailable for ${this.workTree}`, e);
18757
+ log41.debug(`git checkpoints unavailable for ${this.workTree}`, e);
18662
18758
  this.ready = false;
18663
18759
  }
18664
18760
  return this.ready;
@@ -18669,7 +18765,7 @@ var ShadowRepo = class {
18669
18765
  }
18670
18766
  async commit(label, forced = []) {
18671
18767
  await this.run("add", "-A");
18672
- for (const p of forced) await this.run("add", "-f", "--", p).catch((e) => log40.debug(`force-add failed: ${p}`, e));
18768
+ for (const p of forced) await this.run("add", "-f", "--", p).catch((e) => log41.debug(`force-add failed: ${p}`, e));
18673
18769
  await this.run("commit", "--allow-empty", "-q", "-m", label);
18674
18770
  }
18675
18771
  /** Inject the CURRENT (pre-edit) content of `paths` into the turn-open restore point by amending it.
@@ -18677,8 +18773,8 @@ var ShadowRepo = class {
18677
18773
  * turn-boundary `add -A` would never have captured it. Amend (vs a new commit) keeps one restore
18678
18774
  * point per turn, so the REPL's turn↔frame mapping stays intact. */
18679
18775
  async amendForced(paths) {
18680
- for (const p of paths) await this.run("add", "-f", "--", p).catch((e) => log40.debug(`force-capture failed: ${p}`, e));
18681
- await this.run("commit", "--amend", "--no-edit", "-q", "--allow-empty").catch((e) => log40.debug("amend failed", e));
18776
+ for (const p of paths) await this.run("add", "-f", "--", p).catch((e) => log41.debug(`force-capture failed: ${p}`, e));
18777
+ await this.run("commit", "--amend", "--no-edit", "-q", "--allow-empty").catch((e) => log41.debug("amend failed", e));
18682
18778
  }
18683
18779
  /** Commits on `ref`, oldest-first (canonical index space). */
18684
18780
  async log(ref) {
@@ -18738,7 +18834,7 @@ var ShadowRepo = class {
18738
18834
  await this.run("gc", "--auto", "-q").catch(() => {
18739
18835
  });
18740
18836
  } catch (e) {
18741
- log40.debug("checkpoint prune failed", e);
18837
+ log41.debug("checkpoint prune failed", e);
18742
18838
  }
18743
18839
  }
18744
18840
  };
@@ -18806,7 +18902,7 @@ var GitCheckpoints = class {
18806
18902
  use(sessionId) {
18807
18903
  if (sessionId === this.session) return;
18808
18904
  this.session = sessionId;
18809
- if (this.started) for (const r of this.repos) void r.point(this.ref()).catch((e) => log40.debug("re-point failed", e));
18905
+ if (this.started) for (const r of this.repos) void r.point(this.ref()).catch((e) => log41.debug("re-point failed", e));
18810
18906
  }
18811
18907
  async begin(label) {
18812
18908
  if (!await this.start()) return;
@@ -18826,7 +18922,7 @@ var GitCheckpoints = class {
18826
18922
  process.stderr.write(`\x1B[2m checkpoints: '${this.repos[i].root}' too large to snapshot in ${Math.round(this.options.opTimeoutMs / 1e3)}s \u2014 file rewind disabled here\x1B[0m
18827
18923
  `);
18828
18924
  } else {
18829
- log40.debug("checkpoint commit failed", e);
18925
+ log41.debug("checkpoint commit failed", e);
18830
18926
  survivors.push(this.repos[i]);
18831
18927
  survivorCaches.push(this.caches[i] ?? []);
18832
18928
  }
@@ -18861,7 +18957,7 @@ var GitCheckpoints = class {
18861
18957
  if (this.forced.has(abs)) continue;
18862
18958
  this.forced.add(abs);
18863
18959
  const i = this.repoIndexFor(abs);
18864
- if (i >= 0) await this.repos[i].amendForced([abs]).catch((e) => log40.debug("amendForced failed", e));
18960
+ if (i >= 0) await this.repos[i].amendForced([abs]).catch((e) => log41.debug("amendForced failed", e));
18865
18961
  }
18866
18962
  }
18867
18963
  };
@@ -20651,7 +20747,7 @@ import { spawnSync as spawnSync6 } from "child_process";
20651
20747
  import { writeFileSync as writeFileSync8, mkdirSync as mkdirSync10, readdirSync as readdirSync2, unlinkSync as unlinkSync3, chmodSync, existsSync as existsSync7 } from "fs";
20652
20748
  import { homedir as homedir8 } from "os";
20653
20749
  import { join as join14 } from "path";
20654
- var log41 = forComponent("os-sched");
20750
+ var log42 = forComponent("os-sched");
20655
20751
  var OsScheduler = class {
20656
20752
  options;
20657
20753
  constructor(options) {
@@ -20713,7 +20809,7 @@ var OsScheduler = class {
20713
20809
  }
20714
20810
  }
20715
20811
  } catch (e) {
20716
- log41.debug(`cancel ${id}`, e);
20812
+ log42.debug(`cancel ${id}`, e);
20717
20813
  }
20718
20814
  for (const f of [`${id}.json`, `${id}.sh`]) {
20719
20815
  try {
@@ -20831,7 +20927,7 @@ import { existsSync as existsSync8, mkdirSync as mkdirSync11, unlinkSync as unli
20831
20927
  import { homedir as homedir9 } from "os";
20832
20928
  import { join as join15 } from "path";
20833
20929
  init_platform();
20834
- var log42 = forComponent("remote-trigger");
20930
+ var log43 = forComponent("remote-trigger");
20835
20931
  var TRIGGER_DIR = () => join15(homedir9(), ".agent", "triggers");
20836
20932
  var sockPath = (sessionId, dir = TRIGGER_DIR()) => join15(dir, `${sessionId}.sock`);
20837
20933
  var TriggerServer = class {
@@ -20869,13 +20965,13 @@ var TriggerServer = class {
20869
20965
  conn.end(JSON.stringify({ ok: false, error: String(e) }) + "\n");
20870
20966
  }
20871
20967
  });
20872
- conn.on("error", (e) => log42.debug("trigger conn error", e));
20968
+ conn.on("error", (e) => log43.debug("trigger conn error", e));
20873
20969
  });
20874
- this.server.on("error", (e) => log42.debug("trigger server error", e));
20970
+ this.server.on("error", (e) => log43.debug("trigger server error", e));
20875
20971
  this.server.listen(p);
20876
20972
  this.path = p;
20877
20973
  } catch (e) {
20878
- log42.debug("trigger server unavailable", e);
20974
+ log43.debug("trigger server unavailable", e);
20879
20975
  }
20880
20976
  }
20881
20977
  /** Re-bind on /resume (the session id changed). */
@@ -21007,7 +21103,7 @@ var strike = C("9");
21007
21103
  var link = (text, url) => useColor ? `\x1B]8;;${url}\x1B\\${cyan(text)}\x1B]8;;\x1B\\` : `${text} (${url})`;
21008
21104
  var mdPalette = { bold, dim, cyan, italic, strike, green, link };
21009
21105
  var err = (s) => process.stderr.write(s);
21010
- var log43 = forComponent("cli");
21106
+ var log44 = forComponent("cli");
21011
21107
  var VERSION = (() => {
21012
21108
  try {
21013
21109
  return JSON.parse(readFileSync10(new URL("../package.json", import.meta.url), "utf8")).version ?? "?";
@@ -21911,7 +22007,7 @@ function turnCost(model, usage) {
21911
22007
  const priced = model.startsWith("claude-code/") ? `anthropic/${resolveModelAlias(model.slice("claude-code/".length))}` : model;
21912
22008
  return costOf(getModelInfo(priced)?.pricing, usage?.promptTokens ?? 0, usage?.completionTokens ?? 0, usage?.cacheCreationTokens ?? 0, usage?.cacheReadTokens ?? 0, priced);
21913
22009
  }
21914
- async function evaluateGoal(ai, condition, transcript, log44) {
22010
+ async function evaluateGoal(ai, condition, transcript, log45) {
21915
22011
  const recent = transcript.filter((m) => m.role === "assistant").slice(-8).map((m) => {
21916
22012
  const text = typeof m.content === "string" ? m.content : m.content.filter((p) => p.type === "text").map((p) => p.text).join(" ");
21917
22013
  return text.slice(0, 600);
@@ -21931,7 +22027,7 @@ ${recent}` }
21931
22027
  const match = r.content.match(/\{[\s\S]*\}/);
21932
22028
  if (match) return JSON.parse(match[0]);
21933
22029
  } catch (e) {
21934
- log44(dim(` (goal evaluator error: ${e?.message ?? e})
22030
+ log45(dim(` (goal evaluator error: ${e?.message ?? e})
21935
22031
  `));
21936
22032
  }
21937
22033
  return { met: false, reason: "evaluation unclear" };
@@ -22159,7 +22255,7 @@ function mcpAgentTools(mounted, opts) {
22159
22255
  return tools;
22160
22256
  }
22161
22257
  async function closeMcp(mounted) {
22162
- await Promise.all(mounted.map((m) => m.client.close().catch((e) => log43.debug("mcp close failed", e))));
22258
+ await Promise.all(mounted.map((m) => m.client.close().catch((e) => log44.debug("mcp close failed", e))));
22163
22259
  }
22164
22260
  var IMG_EXT = { ".png": "image/png", ".jpg": "image/jpeg", ".jpeg": "image/jpeg", ".gif": "image/gif", ".webp": "image/webp" };
22165
22261
  function mentionRefs(line) {
@@ -22218,7 +22314,7 @@ async function expandMentions(fs, line) {
22218
22314
  if (loaded.includes(ref) || missing.includes(ref)) continue;
22219
22315
  if (ref.includes(":") && mcpMentionResolver) {
22220
22316
  const body = await mcpMentionResolver(ref).catch((e) => {
22221
- log43.debug("mcp mention resolve failed", e);
22317
+ log44.debug("mcp mention resolve failed", e);
22222
22318
  return null;
22223
22319
  });
22224
22320
  if (body != null) {
@@ -22244,7 +22340,7 @@ ${await fs.readFile(path)}`);
22244
22340
  ${blocks.join("\n\n")}` : line, loaded, missing };
22245
22341
  }
22246
22342
  function applyTurnMode(agent, session, task, flags = {}, onModel) {
22247
- const p = parseDirectives(task, { strict: true, keys: ["model", "turns", "delegate", "advisor", "mode"], warn: (m) => log43.debug(m) });
22343
+ const p = parseDirectives(task, { strict: true, keys: ["model", "turns", "delegate", "advisor", "mode"], warn: (m) => log44.debug(m) });
22248
22344
  const d = p.directives, isMode = !!(d.delegate || d.advisor || d.modeOff);
22249
22345
  if (p.unresolvedModel && /->|<-|delegate:|advisor:/.test(task.slice(0, task.length - p.prompt.length))) {
22250
22346
  err(red(` \u2717 unknown model "${p.unresolvedModel}"${p.ambiguous ? ` (could be: ${p.ambiguous.join(", ")})` : ""} \u2014 turn not sent
@@ -22337,7 +22433,7 @@ async function runTurn(agent, store, session, task, cp, cwd = process.cwd(), sen
22337
22433
  try {
22338
22434
  store.save(session);
22339
22435
  } catch (ex) {
22340
- log43.debug("mid-turn session flush failed", ex);
22436
+ log44.debug("mid-turn session flush failed", ex);
22341
22437
  }
22342
22438
  }
22343
22439
  return origNotify(e);
@@ -22501,14 +22597,14 @@ var isCancelTeardown = (e) => {
22501
22597
  function installCancelGuards(mounted) {
22502
22598
  process.on("unhandledRejection", (e) => {
22503
22599
  if (isCancelTeardown(e)) {
22504
- log43.debug("suppressed unhandledRejection (cursor stream cancel)", e);
22600
+ log44.debug("suppressed unhandledRejection (cursor stream cancel)", e);
22505
22601
  return;
22506
22602
  }
22507
- log43.error("unhandledRejection", e);
22603
+ log44.error("unhandledRejection", e);
22508
22604
  });
22509
22605
  process.on("uncaughtException", (e) => {
22510
22606
  if (isCancelTeardown(e)) {
22511
- log43.debug("suppressed uncaughtException (cursor stream cancel)", e);
22607
+ log44.debug("suppressed uncaughtException (cursor stream cancel)", e);
22512
22608
  return;
22513
22609
  }
22514
22610
  console.error(e);
@@ -22882,10 +22978,11 @@ ${note}`;
22882
22978
  if (old?.before !== void 0) face.transcript.splice(old.before);
22883
22979
  if (rec.skip) return;
22884
22980
  const { reply: cut } = takeCut(voiceIO, true);
22885
- if (cut && keepHeard(face.transcript, cut)) voiceDiag?.push({ t: performance.now(), kind: "call_kept_heard", heard: cut.heard.length, full: cut.full.length });
22981
+ const cutNote = cut && keepHeard(face.transcript, cut) ? interruptionNote(cut, void 0, false) : "";
22982
+ if (cutNote) voiceDiag?.push({ t: performance.now(), kind: "call_kept_heard", heard: cut.heard.length, full: cut.full.length });
22886
22983
  rec.running = true;
22887
22984
  rec.before = face.transcript.length;
22888
- const note = greetNote;
22985
+ const note = cutNote + greetNote;
22889
22986
  greetNote = "";
22890
22987
  callReplyOpen = false;
22891
22988
  spoken = new SpokenFilter();
@@ -22898,7 +22995,7 @@ ${SPOKEN_TURN}`, { id });
22898
22995
  editorRef?.abort();
22899
22996
  }
22900
22997
  } catch (e) {
22901
- log43.error("call turn failed", e);
22998
+ log44.error("call turn failed", e);
22902
22999
  } finally {
22903
23000
  rec.running = false;
22904
23001
  call?.main({ type: "done", id });
@@ -23048,7 +23145,7 @@ ${SPOKEN_TURN}`, { id });
23048
23145
  try {
23049
23146
  mkdirSync12(dir, { recursive: true });
23050
23147
  } catch (e) {
23051
- log43.debug("paste image dir create failed", e);
23148
+ log44.debug("paste image dir create failed", e);
23052
23149
  }
23053
23150
  const img = grabClipboardImage(dir, String(Date.now()));
23054
23151
  return img ? { display: "Image", ref: "@" + img.path, path: img.path } : null;
@@ -23161,7 +23258,7 @@ Added entries are loadable now via the Skill/SlashCommand tools; removed ones ar
23161
23258
  mkdirSync12(join16(cwd, ".agent"), { recursive: true });
23162
23259
  appendFileSync2(histPath, line + "\n");
23163
23260
  } catch (e) {
23164
- log43.debug("history write failed", e);
23261
+ log44.debug("history write failed", e);
23165
23262
  }
23166
23263
  };
23167
23264
  const ago = (t) => {
@@ -23233,7 +23330,7 @@ Added entries are loadable now via the Skill/SlashCommand tools; removed ones ar
23233
23330
  try {
23234
23331
  store.save(session);
23235
23332
  } catch (e) {
23236
- log43.debug("session save after rewind failed", e);
23333
+ log44.debug("session save after rewind failed", e);
23237
23334
  }
23238
23335
  err(green(" \u27F2 jumped back") + dim(` \u2014 ${face.transcript.length} message(s) kept; edit + resend
23239
23336
  `));
@@ -23268,7 +23365,7 @@ ${task}`;
23268
23365
  bangContext.length = 0;
23269
23366
  }
23270
23367
  const delta = await refreshCatalogs().catch((e) => {
23271
- log43.debug("catalog refresh failed", e);
23368
+ log44.debug("catalog refresh failed", e);
23272
23369
  return "";
23273
23370
  });
23274
23371
  if (delta) {
@@ -23542,7 +23639,7 @@ ${task}`;
23542
23639
  desc: "rescan skills/commands dirs and rebuild the system prompt (one cache miss) \u2014 picks up entries created mid-session",
23543
23640
  run: async () => {
23544
23641
  await refreshCatalogs().catch((e) => {
23545
- log43.debug("catalog refresh failed", e);
23642
+ log44.debug("catalog refresh failed", e);
23546
23643
  });
23547
23644
  face.reprepare();
23548
23645
  err(green(` \u2713 reloaded \u2014 ${skills.length} skill(s), ${cmds.length} command(s); system prompt rebuilds on next message
@@ -24045,7 +24142,7 @@ ${task}`;
24045
24142
  try {
24046
24143
  for (const def of (await loadAgents(fs2, d)).agents) if (!seen.has(def.name)) seen.set(def.name, { def, from: d });
24047
24144
  } catch (e) {
24048
- log43.debug(`loadAgents(${d}) failed`, e);
24145
+ log44.debug(`loadAgents(${d}) failed`, e);
24049
24146
  }
24050
24147
  }
24051
24148
  if (!seen.size) {
@@ -24133,7 +24230,7 @@ ${task}`;
24133
24230
  }
24134
24231
  if (idx >= 0) {
24135
24232
  const old = mounted.splice(idx, 1)[0];
24136
- await old.client.close().catch((e) => log43.debug("mcp close failed", e));
24233
+ await old.client.close().catch((e) => log44.debug("mcp close failed", e));
24137
24234
  }
24138
24235
  try {
24139
24236
  const m = await mountMcpServer(name, conf);
@@ -24161,7 +24258,7 @@ ${task}`;
24161
24258
  }
24162
24259
  const m = mounted.splice(idx, 1)[0];
24163
24260
  remountMcpTools();
24164
- await m.client.close().catch((e) => log43.debug("mcp close failed", e));
24261
+ await m.client.close().catch((e) => log44.debug("mcp close failed", e));
24165
24262
  err(dim(` removed "${name}"
24166
24263
  `));
24167
24264
  return;
@@ -24364,7 +24461,7 @@ ${task}`;
24364
24461
  try {
24365
24462
  return readdirSync4(join16(cwd, absDir.replace(/^\/+/, "")), { withFileTypes: true }).map((d) => ({ name: d.name, dir: d.isDirectory() }));
24366
24463
  } catch (e) {
24367
- log43.debug("completion readdir failed", absDir, e);
24464
+ log44.debug("completion readdir failed", absDir, e);
24368
24465
  return null;
24369
24466
  }
24370
24467
  };
@@ -24503,7 +24600,7 @@ ${out}
24503
24600
  return;
24504
24601
  }
24505
24602
  await refreshCatalogs().catch((e) => {
24506
- log43.debug("catalog refresh failed", e);
24603
+ log44.debug("catalog refresh failed", e);
24507
24604
  });
24508
24605
  const sk = skills.find((x) => x.name === name);
24509
24606
  if (sk) {
@@ -24633,7 +24730,7 @@ ${out}
24633
24730
  if (delivery || cut) dx?.parkCutDelivery(delivery, !!cut, heard);
24634
24731
  const cutReply = cut && cut.full.length - cut.heard.length > 40 ? cut : null;
24635
24732
  const noteP = replaces ? replaces.note : !cutReply ? Promise.resolve("") : (instinct ? instinct.bargeIntent(text).catch((e) => {
24636
- log43.warn(`barge intent failed \u2014 model decides: ${e.message}`);
24733
+ log44.warn(`barge intent failed \u2014 model decides: ${e.message}`);
24637
24734
  return void 0;
24638
24735
  }) : Promise.resolve(void 0)).then(async (intent) => interruptionNote(cutReply, intent) + ackedNote(await instinct?.ackFor(text)));
24639
24736
  const cutIn = replaces ? replaces.cutIn : interjectNote;
@@ -25034,10 +25131,10 @@ function channelOptions(ai, model, gender) {
25034
25131
  // 0: the reactive live path
25035
25132
  pickLeaf: fastLeafPicker(ai, process.env.AGENTX_LEAF_MODEL || "groq/openai/gpt-oss-120b"),
25036
25133
  persona: process.env.AGENTX_CALL_PERSONA ?? "",
25037
- onTree: (e) => log43.debug(`voice tree: ${e.branches} branches in ${e.ms}ms${e.tokens ? ` tokens ${e.tokens.input}/${e.tokens.output}` : ""}${e.error ? ` error ${e.error}` : ""}`),
25134
+ onTree: (e) => log44.debug(`voice tree: ${e.branches} branches in ${e.ms}ms${e.tokens ? ` tokens ${e.tokens.input}/${e.tokens.output}` : ""}${e.error ? ` error ${e.error}` : ""}`),
25038
25135
  onEvent: (e) => {
25039
- if (e.moment) log43.debug(`voice leaf: ${e.moment} ${e.conf} "${e.text}" ${e.acted}`);
25040
- else log43.debug(`channel ${e.trigger}: rule=${e.rule} choice=${e.choice ?? "-"} \u2192 ${e.acted}${e.text ? ` "${e.text}"` : ""}${e.cue ? " (planned cue)" : ""} ${e.ms}ms`);
25136
+ if (e.moment) log44.debug(`voice leaf: ${e.moment} ${e.conf} "${e.text}" ${e.acted}`);
25137
+ else log44.debug(`channel ${e.trigger}: rule=${e.rule} choice=${e.choice ?? "-"} \u2192 ${e.acted}${e.text ? ` "${e.text}"` : ""}${e.cue ? " (planned cue)" : ""} ${e.ms}ms`);
25041
25138
  },
25042
25139
  // Banks in the user's language: generated once per language, cached + topped up across sessions (~/.agent/cache).
25043
25140
  banks: new ChannelBanks({ generate: fastBankGenerator(ai, model), cacheDir: join16(homedir10(), ".agent", "cache", "channel-banks") }),
@@ -25131,7 +25228,7 @@ async function duplexServe(args, ai, cfg, cwd) {
25131
25228
  try {
25132
25229
  store.save(session);
25133
25230
  } catch (e) {
25134
- log43.warn("duplex session save failed", e);
25231
+ log44.warn("duplex session save failed", e);
25135
25232
  }
25136
25233
  };
25137
25234
  const overlap2 = overlapResponder(ai, args.duplexV2 ? args.channelMode : void 0, out);
@@ -25171,7 +25268,7 @@ async function duplexServe(args, ai, cfg, cwd) {
25171
25268
  done2();
25172
25269
  out({ type: "turn_done", id, finishReason: res?.finishReason ?? "error", ...why ? { error: why } : {} });
25173
25270
  }).catch((e) => {
25174
- log43.error("duplex turn failed", e);
25271
+ log44.error("duplex turn failed", e);
25175
25272
  done2();
25176
25273
  out({ type: "turn_done", id, finishReason: "error", error: String(e?.message ?? e) });
25177
25274
  });