@livx.cc/agentx 0.99.160 → 0.99.161

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
@@ -10668,6 +10668,9 @@ var ASIDES = {
10668
10668
  he: { agree: ["\u05DB\u05DF, \u05D1\u05D3\u05D9\u05D5\u05E7.", "\u05DB\u05DF, \u05DE\u05DE\u05E9.", "\u05E0\u05DB\u05D5\u05DF, \u05DB\u05DF."], continue: [], react: ["\u05E0\u05DB\u05D5\u05DF? \u05DE\u05D8\u05D5\u05E8\u05E3.", "\u05DB\u05DF, \u05DE\u05D8\u05D5\u05E8\u05E3.", "\u05DE\u05D8\u05D5\u05E8\u05E3, \u05E0\u05DB\u05D5\u05DF?"] }
10669
10669
  };
10670
10670
  var REACT = /^(?:(?:oh|and|so|wait|but|ok|okay|yeah)\s+)*(?:wow|whoa|woah|really|seriously|no way|oh my god|omg|crazy|insane|amazing|unbelievable|what|are you serious|you're kidding|וואו|באמת|מה|מטורף|רצינית?|לא נכון)(?:\s+(?:wow|really|seriously|that's crazy|that's wild|no way|באמת|וואו))*$/u;
10671
+ var WH_LEAD = "^(?:(?:oh|and|so|wait|but|ok|okay|um|uh|sorry)\\s+)*";
10672
+ var WH_QUESTION = new RegExp(WH_LEAD + "(?:who|whom|whose|where|which|why|how|when|what|\u05DE\u05D9|\u05D0\u05D9\u05E4\u05D4|\u05DC\u05DE\u05D4|\u05D0\u05D9\u05DA|\u05DE\u05EA\u05D9|\u05DE\u05D4)\\s+\\S", "u");
10673
+ var WH_EXCLAIM = new RegExp(WH_LEAD + "(?:what an? |how (?:cool|nice|fun|sweet|sad|funny|weird|crazy|strange|interesting|beautiful|lovely|cute|amazing|awesome)\\b)", "u");
10671
10674
  var isReaction = (text) => {
10672
10675
  const t = norm2(text);
10673
10676
  return REACT.test(t) || new RegExp("\\s\\p{L}{1,3}$", "u").test(t) && REACT.test(t.replace(new RegExp("\\s\\p{L}{1,3}$", "u"), ""));
@@ -10686,6 +10689,7 @@ function overlapRule(text) {
10686
10689
  if (!t) return void 0;
10687
10690
  if (isClosing(text)) return "cut";
10688
10691
  if (HARD.test(t + " ")) return t.includes(" ") ? "cut" : "hold";
10692
+ if (WH_QUESTION.test(t) && !REACT.test(t) && !WH_EXCLAIM.test(t)) return "cut";
10689
10693
  for (const p of PHRASES) t = t.split(p).join(" ");
10690
10694
  const words5 = t.split(/[\s-]+/).filter(Boolean);
10691
10695
  const ack = (w) => ACK.has(w) || HE_ACK.has(w) || /^(?:ha)+h?$|^(?:he)+h?$|^m+(?:hm+)?$|^h?m+$/.test(w);
@@ -10697,7 +10701,7 @@ function overlapRule(text) {
10697
10701
  function fastOverlapModel(ai, model = "groq/qwen/qwen3.8-27b") {
10698
10702
  return async (heard, signal) => {
10699
10703
  const prompt = 'Live voice call. The assistant is mid-sentence and the user just said this over it: "' + heard + `"
10700
- Are they STEERING \u2014 asking for something new, asking a real question about it, correcting it, telling it to stop, or saying goodbye? A reaction is not steering: surprise, disbelief, "what?", "really?", "you're serious?", "that's serious", agreement, a laugh \u2014 the assistant just carries on.
10704
+ Are they STEERING \u2014 asking for something new, asking a real question about it, correcting it, telling it to stop, or saying goodbye? A question about what it said ("who did that?", "where?", "which one?") IS steering. A reaction is not steering: surprise, disbelief, a lone "what?", "really?", "you're serious?", "that's serious", agreement, a laugh \u2014 the assistant just carries on.
10701
10705
  Answer yes (steering) or no (a reaction).`;
10702
10706
  const reasoning = /qwen/.test(model) ? { providerOptions: { reasoning_effort: "none" } } : /gpt-oss/.test(model) ? { providerOptions: { reasoning_effort: "low" } } : {};
10703
10707
  const r = await ai.chat({ model, messages: [{ role: "user", content: prompt }], stream: false, signal, temperature: 0, maxTokens: /gpt-oss/.test(model) ? 200 : 3, ...reasoning });
@@ -10787,6 +10791,19 @@ function voiceDecider(env = process.env, timeoutMs = 1500) {
10787
10791
  const llm = new LlmDecideAdapter({ client: { chat: (c) => ai.chat({ reasoningEffort: "low", ...c }) } });
10788
10792
  return new DecideClient({ ...o, timeoutMs, adapters: { typesafe: new JevAdapter(), llm } });
10789
10793
  }
10794
+ var TURN_ACTIONS = {
10795
+ answer: "Their line is complete and calls for your reply now (a question, a request, a greeting, an answer to what you asked).",
10796
+ ack_then_answer: "Complete, and a real answer needs a moment: a short acknowledgement now, then the answer.",
10797
+ backchannel: 'They are telling something longer and only paused: a tiny listener sound ("mm", "right") at most, keep listening.',
10798
+ wait: 'They are mid-thought (cut off, a list, "and...", a number being said): say nothing, they will go on.',
10799
+ silence: "Not for you to answer (a recording, a menu, talk to someone else, or an ending that needs nothing)."
10800
+ };
10801
+ function turnJudgeFor(env = process.env, timeoutMs = 900) {
10802
+ const decider = voiceDecider(env, timeoutMs);
10803
+ if (!decider) return void 0;
10804
+ const instinct = new Instinct({ decider });
10805
+ return (heard, state) => instinct.turnEnd(heard, state);
10806
+ }
10790
10807
  var InstinctOptions = class {
10791
10808
  decider;
10792
10809
  /** Partial unchanged this long (a micro-pause) → consult. */
@@ -11112,6 +11129,18 @@ var Instinct = class {
11112
11129
  CHANNEL_ACTIONS
11113
11130
  );
11114
11131
  }
11132
+ /** A held final (the STT ended a line; the gate waits to see if more comes): is it our turn, and how to react.
11133
+ * answer / ack_then_answer → the turn goes out now; wait / backchannel → it waits the long hold; silence → it goes
11134
+ * out and the quick lane may stay quiet. The choice also reaches the quick lane as a hint. */
11135
+ turnEnd(heard, state = {}) {
11136
+ return this.ask(
11137
+ "turn_end",
11138
+ heard,
11139
+ { their_line: heard, ...state },
11140
+ FRAME + "The other person just paused after this line. Decide, as a person on a phone call would, whether it is your turn now and how you would react.",
11141
+ TURN_ACTIONS
11142
+ );
11143
+ }
11115
11144
  /** A random phrase from `pool`, never the one said last (no back-to-back repeat across keys). */
11116
11145
  rotate(pool) {
11117
11146
  const fresh = pool.filter((x) => x !== this.lastAckSaid);
@@ -11449,18 +11478,18 @@ function fitsLanguage(line, lang) {
11449
11478
  return !ws.some((w) => !mine?.has(w) && Object.entries(STOP3).some(([l, s]) => l !== lang && s.has(w)));
11450
11479
  }
11451
11480
  var norm3 = (s) => s.toLowerCase().replace(/[^\p{L}\p{N}' ]/gu, "").replace(/\s+/g, " ").trim();
11452
- function cleanLine(s, lang, maxWords = 6) {
11481
+ function cleanLine(s, lang, maxWords = 6, maxChars = 60) {
11453
11482
  if (/^(?:gasp|quiet|laughter)[.!?…]*$/i.test(s.trim())) return "";
11454
11483
  const first = s.trim().split("\n")[0];
11455
11484
  const tags = [...first.matchAll(LINE_TAG)].map((m) => `[${m[1].toLowerCase()}]`).filter((t, i, a) => a.indexOf(t) === i).join(" ");
11456
11485
  const raw = first.replace(LINE_TAG, " ").trim();
11457
11486
  if (tags && !/[\p{L}\p{N}]/u.test(raw)) return /laughter|gasp/.test(tags) ? tags : "";
11458
- const words5 = cleanWords(raw, lang, maxWords);
11487
+ const words5 = cleanWords(raw, lang, maxWords, maxChars);
11459
11488
  return words5 && tags ? `${tags} ${words5}` : words5;
11460
11489
  }
11461
11490
  var LINE_TAG = /\[(laughter|gasp|quiet)\]/gi;
11462
11491
  var lineWords = (line) => line.replace(LINE_TAG, " ").trim();
11463
- function cleanWords(raw, lang, maxWords) {
11492
+ function cleanWords(raw, lang, maxWords, maxChars = 60) {
11464
11493
  const l = raw.replace(/^[-*•\d.)\s]+/, "").replace(/^["'“”«»]+|["'“”«»]+$/g, "").replace(new RegExp("^\\p{L}+:\\s*", "u"), "").trim();
11465
11494
  if (!l || isLeakSuspect(raw) || isLeakSuspect(l)) {
11466
11495
  if (l) log23.debug(`line "${raw}" reads as meta \u2014 rejected`);
@@ -11470,7 +11499,7 @@ function cleanWords(raw, lang, maxWords) {
11470
11499
  log23.debug(`line "${l}" is not ${lang} \u2014 rejected`);
11471
11500
  return "";
11472
11501
  }
11473
- return l.split(/\s+/).length > maxWords || l.length > 60 ? "" : l;
11502
+ return l.split(/\s+/).length > maxWords || l.length > maxChars ? "" : l;
11474
11503
  }
11475
11504
  var SPEAKER_FILLER = /^(?:so|well|actually|basically|anyway|anyways|like|you know|i mean|kind of|sort of|literally|honestly|and|but|because|then|the thing is)\b/i;
11476
11505
  function validateBank(raw, lang, minPerKind = 3) {
@@ -11762,6 +11791,21 @@ var TurnGate = class {
11762
11791
  clearTimeout(h.timer);
11763
11792
  h.timer = setTimeout(() => this.settle(), h.ms);
11764
11793
  }
11794
+ /** A turn judge says the held `text` is a whole turn: send it now (not while they are mid-line). */
11795
+ release(text) {
11796
+ const h = this.held;
11797
+ if (!h || h.talking || norm3(h.text) !== norm3(text)) return false;
11798
+ this.flush();
11799
+ return true;
11800
+ }
11801
+ /** A turn judge says they are not done: the held `text` waits the long hold (more speech still merges in). */
11802
+ extend(text) {
11803
+ const h = this.held;
11804
+ if (!h || norm3(h.text) !== norm3(text) || h.ms >= this.o.holdMs) return;
11805
+ h.ms = this.o.holdMs;
11806
+ clearTimeout(h.timer);
11807
+ h.timer = setTimeout(() => this.settle(), h.ms);
11808
+ }
11765
11809
  /** The hold's quiet ran out: send it — unless the user is mid-line (a partial with no final yet). */
11766
11810
  settle() {
11767
11811
  const h = this.held;
@@ -14930,6 +14974,7 @@ var SecondChannel = class {
14930
14974
  const preset = CHANNEL_MODES[options?.mode ?? "normal"] ?? {};
14931
14975
  const base = new SecondChannelOptions();
14932
14976
  this.options = { ...base, ...preset, ...options };
14977
+ if (process.env.AGENTX_CALL_ROLE === "caller") this.options.kinds = (this.options.kinds ?? []).filter((k) => k === "backchannel");
14933
14978
  for (const k of Object.keys(preset)) if (!options || !(k in options)) this.normalTiming[k] = base[k];
14934
14979
  this.startedAt = this.o.now();
14935
14980
  if (this.o.lang) this.setLanguage(this.o.lang, true);
@@ -15696,6 +15741,9 @@ var VoiceCallOptions = class {
15696
15741
  };
15697
15742
  /** The fast model (lines, banks, progress) — used only with `ai`. */
15698
15743
  fastModel = latestClaude("haiku");
15744
+ /** The turn-end judge (Instinct.turnEnd over Jev): a held final goes out at once or waits, and its read of how to
15745
+ * react reaches the quick lane. Absent → the gate's timers alone. */
15746
+ turnJudge;
15699
15747
  /** Model client for the fast model + the channel decider / overlap judge. Absent → canned lines and rules only. */
15700
15748
  ai;
15701
15749
  /** Cache dir for per-language banks (ChannelBanks). */
@@ -15771,7 +15819,10 @@ var VoiceCall = class {
15771
15819
  ...o.gate,
15772
15820
  onTurn: (t) => this.onTurn(t),
15773
15821
  onDrop: (text, why) => this.onDrop(text, why),
15774
- onHold: (text) => o.onMetric({ name: "hold", text })
15822
+ onHold: (text) => {
15823
+ o.onMetric({ name: "hold", text });
15824
+ this.judgeHold(text);
15825
+ }
15775
15826
  });
15776
15827
  }
15777
15828
  options;
@@ -15800,6 +15851,20 @@ var VoiceCall = class {
15800
15851
  get o() {
15801
15852
  return this.options;
15802
15853
  }
15854
+ /** The turn judge's last read (choice for `text`): the quick lane's hint for that turn. */
15855
+ hint;
15856
+ judgeHold(text) {
15857
+ const j = this.o.turnJudge;
15858
+ if (!j || this.ended) return;
15859
+ const said = [...this.history].reverse().find((h) => h.who === "you")?.text;
15860
+ j(text, { agent_last_said: said ?? null, agent_speaking: !!this.cur?.running }).then((d) => {
15861
+ if (!d) return;
15862
+ this.hint = { text, choice: d.choice };
15863
+ const go = d.choice === "answer" || d.choice === "ack_then_answer" || d.choice === "silence";
15864
+ const acted2 = go ? this.gate.release(text) ? "released" : "late" : (this.gate.extend(text), "extended");
15865
+ this.o.onMetric({ name: "judge", ms: d.ms, kind: `${d.choice} ${acted2}`, text });
15866
+ }).catch((e) => log31.warn(`turn judge failed \u2014 the gate's timers decide: ${e?.message ?? e}`));
15867
+ }
15803
15868
  /** The language the fill channel speaks right now (null = unknown → silent). */
15804
15869
  get language() {
15805
15870
  return this.lang;
@@ -16120,7 +16185,7 @@ var VoiceCall = class {
16120
16185
  const ac = new AbortController(), t0 = this.o.now(), lang = this.lang, rest = this.cutRest;
16121
16186
  c.ask = ac;
16122
16187
  const late = setTimeout(() => ac.abort(), this.o.quickBudgetMs);
16123
- const mv = lang ? await this.o.quick({ history: this.history.slice(0, -1), heard: t.text, lang, rest }, ac.signal).catch((e) => {
16188
+ const mv = lang ? await this.o.quick({ history: this.history.slice(0, -1), heard: t.text, lang, rest, ...this.hint && t.text.includes(this.hint.text) ? { hint: this.hint.choice } : {} }, ac.signal).catch((e) => {
16124
16189
  if (this.cur === c) log31.warn(`quick lane ${ac.signal.aborted ? `late (${this.o.quickBudgetMs}ms)` : `failed: ${e?.message ?? e}`} \u2014 deep lane`);
16125
16190
  return null;
16126
16191
  }).finally(() => clearTimeout(late)) : null;
@@ -16152,7 +16217,8 @@ var VoiceCall = class {
16152
16217
  c.due = false;
16153
16218
  return this.close(c, "silent");
16154
16219
  }
16155
- const said = mv.kind === "resume" ? `${mv.line} ${cutSentence([...this.history].reverse().find((h) => h.who === "you" && h.cut)?.text ?? "")} ${rest}`.replace(/\s+/g, " ").trim() : mv.line;
16220
+ const cutAt = () => cutSentence([...this.history].reverse().find((h) => h.who === "you" && h.cut)?.text ?? "");
16221
+ const said = mv.kind === "resume" ? `${mv.line} ${cutAt()} ${rest}`.replace(/\s+/g, " ").trim() : mv.kind === "clarify" ? `${mv.line} ${lang && BACK_TO[lang] || ""} ${cutAt()} ${rest}`.replace(/\s+/g, " ").trim() : mv.line;
16156
16222
  this.gate.replyStarted(c.id);
16157
16223
  const end = mv.kind === "say" && !!mv.end;
16158
16224
  if (end) try {
@@ -16168,6 +16234,11 @@ var VoiceCall = class {
16168
16234
  this.o.dropCut?.();
16169
16235
  this.history.push({ who: "you", text: rest });
16170
16236
  note(`They asked you to go on, and you continued your cut answer aloud: "${rest}". All of it has now been said.`);
16237
+ } else if (mv.kind === "clarify") {
16238
+ this.cutRest = "";
16239
+ this.o.dropCut?.();
16240
+ this.history.push({ who: "you", text: mv.line }, { who: "you", text: rest });
16241
+ note(`They cut your answer to ask "${t.text}". You (the call's quick voice) answered aloud "${mv.line}" and then continued your cut answer: "${rest}". All of it has now been said.`);
16171
16242
  } else {
16172
16243
  this.history.push({ who: "you", text: said });
16173
16244
  note(`On the call they said "${t.text}" and you (the call's quick voice) answered aloud: "${said}". Already said \u2014 do not repeat it.`);
@@ -16356,6 +16427,7 @@ var VoiceCall = class {
16356
16427
  }
16357
16428
  }
16358
16429
  };
16430
+ var BACK_TO = { en: "Anyway,", he: "\u05D1\u05DB\u05DC \u05DE\u05E7\u05E8\u05D4," };
16359
16431
  function cutSentence(heard) {
16360
16432
  const tail = heard.trim().split(/(?<=[.!?…])\s+/).at(-1) ?? "";
16361
16433
  if (!tail || /[.!?…]["'”’)]*$/.test(tail)) return "";
@@ -17601,6 +17673,7 @@ var NodeMicSource = class {
17601
17673
  }, 500).unref?.();
17602
17674
  }
17603
17675
  };
17676
+ var vpioProbeMs = () => Number(process.env.MIC_VPIO_PROBE_MS) || 5e3;
17604
17677
  var AecDuplexAudio = class {
17605
17678
  constructor(bin) {
17606
17679
  this.bin = bin;
@@ -17629,6 +17702,9 @@ var AecDuplexAudio = class {
17629
17702
  fallbackTimer = null;
17630
17703
  bytesWritten = 0;
17631
17704
  startedAt = 0;
17705
+ /** This turn's TTS while VPIO is unproven (no mic chunk yet). A dead VPIO engine plays nothing either, so the
17706
+ * fallback helper replays it — else the greeting, spoken inside the VPIO probe window, is never heard. */
17707
+ unproven = [];
17632
17708
  // --- AudioSource ---
17633
17709
  start(onChunk) {
17634
17710
  this.onChunk = onChunk;
@@ -17641,7 +17717,7 @@ var AecDuplexAudio = class {
17641
17717
  this.spawnHelper();
17642
17718
  }
17643
17719
  /** (Re)spawn the helper. On the first spawn, arm a fast watchdog: if VPIO delivers NO audio within
17644
- * ~2.5s, the VP input tap is dead on this machine (seen on macOS 26.5.x) — respawn once with
17720
+ * vpioProbeMs(), the VP input tap is dead on this machine (seen on macOS 26.5.x) — respawn once with
17645
17721
  * MIC_NO_VPIO=1 (plain capture, heuristic echo) so the mic actually works instead of starving STT. */
17646
17722
  spawnHelper() {
17647
17723
  const env = this.noVpio ? { ...process.env, MIC_NO_VPIO: "1" } : process.env;
@@ -17652,7 +17728,10 @@ var AecDuplexAudio = class {
17652
17728
  if (c && !this.stopped) log36.error(`aec duplex audio exited (${c}) \u2014 check mic permission / MIC_AEC=0`);
17653
17729
  });
17654
17730
  this.proc.stdout.on("data", (chunk) => {
17655
- this.gotChunk = true;
17731
+ if (!this.gotChunk) {
17732
+ this.gotChunk = true;
17733
+ this.unproven = [];
17734
+ }
17656
17735
  this.onChunk(chunk);
17657
17736
  });
17658
17737
  this.proc.stderr.on("data", (d) => {
@@ -17674,11 +17753,19 @@ var AecDuplexAudio = class {
17674
17753
  this.triedFallback = true;
17675
17754
  this.noVpio = true;
17676
17755
  this._aec = false;
17677
- 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)");
17756
+ log36.warn(`mic-aec: VPIO delivered no audio in ${vpioProbeMs() / 1e3}s \u2014 falling back to non-VPIO capture (no AEC \u2192 half-duplex, no barge-in)`);
17678
17757
  this.onDegrade?.();
17679
17758
  this.killProc();
17680
17759
  this.spawnHelper();
17681
- }, 2500);
17760
+ const replay = this.unproven;
17761
+ this.unproven = [];
17762
+ if (replay.length) {
17763
+ this.startedAt = now3();
17764
+ this.pausedSince = 0;
17765
+ this.pausedAccum = 0;
17766
+ for (const c of replay) this.frame(c);
17767
+ }
17768
+ }, vpioProbeMs());
17682
17769
  this.fallbackTimer.unref?.();
17683
17770
  }
17684
17771
  }
@@ -17713,12 +17800,14 @@ var AecDuplexAudio = class {
17713
17800
  this.frame(null);
17714
17801
  this.bytesWritten = 0;
17715
17802
  this.startedAt = 0;
17803
+ this.unproven = [];
17716
17804
  this.pausedSince = 0;
17717
17805
  this.pausedAccum = 0;
17718
17806
  }
17719
17807
  write(chunk) {
17720
17808
  if (!this.startedAt) this.startedAt = now3();
17721
17809
  this.bytesWritten += chunk.length;
17810
+ if (!this.gotChunk && !this.noVpio) this.unproven.push(chunk);
17722
17811
  this.frame(chunk);
17723
17812
  }
17724
17813
  playedMs() {
@@ -17734,6 +17823,7 @@ var AecDuplexAudio = class {
17734
17823
  this.frame(null);
17735
17824
  this.bytesWritten = 0;
17736
17825
  this.startedAt = 0;
17826
+ this.unproven = [];
17737
17827
  this.pausedSince = 0;
17738
17828
  this.pausedAccum = 0;
17739
17829
  }
@@ -18406,9 +18496,68 @@ ${o.persona}
18406
18496
  return line || o.fallback;
18407
18497
  }
18408
18498
 
18499
+ // src/voice/menuKeys.ts
18500
+ init_logging();
18501
+ var log39 = forComponent("MenuKeys");
18502
+ var MenuKeysOptions = class {
18503
+ ai;
18504
+ model = "groq/openai/gpt-oss-120b";
18505
+ /** Who we are and what the call is for (the call persona / task). */
18506
+ persona = "";
18507
+ timeoutMs = 4e3;
18508
+ };
18509
+ var MenuKeys = class _MenuKeys {
18510
+ options;
18511
+ /** The menu so far: each line heard, and what we pressed after it. */
18512
+ steps = [];
18513
+ constructor(options) {
18514
+ this.options = { ...new MenuKeysOptions(), ...options };
18515
+ }
18516
+ /** The prompt for the menu so far (exported for tests). */
18517
+ static prompt(persona, steps) {
18518
+ const menu = steps.map((s) => `MENU: ${s.line}${s.pressed ? `
18519
+ YOU PRESSED: ${s.pressed}` : ""}`).join("\n");
18520
+ return `${persona.slice(0, 800)}
18521
+
18522
+ You placed this call and an automated phone menu is playing. What it said so far, oldest first:
18523
+ ${menu}
18524
+
18525
+ Which key(s) do you press NOW for your task? Answer with only the keys (digits, * or #, e.g. "1" or "2#"), or WAIT when: the option for your task was not said yet, it is a greeting/recording/hold message, you already pressed for this same menu, or it asks for something the task does not give (an ID, a number). After "wrong key"/"invalid choice", press the right key for the menu again.`;
18526
+ }
18527
+ /** "1", "2#", "WAIT", "Press 1." … → the keys, or '' (wait). */
18528
+ static parse(raw) {
18529
+ const t = raw.trim().replace(/^["'`]+|["'`.]+$/g, "");
18530
+ if (/^wait\b/i.test(t)) return "";
18531
+ const m = t.match(/^(?:press\s*)?([0-9*#]{1,12})$/i);
18532
+ return m ? m[1] : "";
18533
+ }
18534
+ /** A menu line was heard: the keys to press now, or '' (wait). */
18535
+ async hear(line) {
18536
+ const t0 = performance.now();
18537
+ this.steps.push({ line });
18538
+ const ac = new AbortController(), timer = setTimeout(() => ac.abort(), this.options.timeoutMs);
18539
+ try {
18540
+ const raw = await fastText(this.options.ai, { model: this.options.model, prompt: _MenuKeys.prompt(this.options.persona, this.steps.slice(-8)), signal: ac.signal, maxTokens: 20, temperature: 0 });
18541
+ const digits = _MenuKeys.parse(raw);
18542
+ if (digits) this.steps[this.steps.length - 1].pressed = digits;
18543
+ return { digits, ms: Math.round(performance.now() - t0) };
18544
+ } catch (e) {
18545
+ log39.debug(`menu keys failed \u2014 the main agent decides: ${e?.message ?? e}`);
18546
+ return { digits: "", ms: Math.round(performance.now() - t0) };
18547
+ } finally {
18548
+ clearTimeout(timer);
18549
+ }
18550
+ }
18551
+ /** The host pressed keys itself (the main agent's press_keys): later reads know it. */
18552
+ pressed(digits) {
18553
+ const s = this.steps.at(-1);
18554
+ if (s) s.pressed = digits;
18555
+ }
18556
+ };
18557
+
18409
18558
  // src/voice/quickLane.ts
18410
18559
  init_logging();
18411
- var log39 = forComponent("QuickLane");
18560
+ var log40 = forComponent("QuickLane");
18412
18561
  var SAY_WORDS = 30;
18413
18562
  var ACK_WORDS = 10;
18414
18563
  var ACKS = { en: ["On it.", "Sure, one sec.", "Okay.", "Alright."], he: ["\u05E8\u05D2\u05E2 \u05D0\u05D7\u05D3.", "\u05D0\u05D5\u05E7\u05D9\u05D9, \u05E9\u05E0\u05D9\u05D9\u05D4.", "\u05E9\u05E0\u05D9\u05D9\u05D4."] };
@@ -18430,9 +18579,20 @@ var ownLine = (pool, c) => {
18430
18579
  return (pool ?? []).find((x) => !said.has(norm3(x))) ?? "";
18431
18580
  };
18432
18581
  function rawMove(raw, c) {
18433
- const m = /^\s*(SAY|BYE|DEEP|RESUME|QUIET)\b\s*:?\s*(.*)$/im.exec(raw.trim());
18582
+ const m = /^\s*(SAY|BYE|DEEP|RESUME|CLARIFY|QUIET)\b\s*:?\s*(.*)$/im.exec(raw.trim());
18434
18583
  if (!m) return null;
18435
18584
  const bye = m[1].toUpperCase() === "BYE", kind = bye ? "SAY" : m[1].toUpperCase(), body = m[2].trim();
18585
+ if (kind === "CLARIFY") {
18586
+ const deep = { kind: "deep", ack: stockAck(c), brief: "" };
18587
+ if (!c.rest) return deep;
18588
+ const [ans = "", quote = ""] = body.split("|").map((s) => s.trim());
18589
+ const line2 = sayLine(ans, c.lang);
18590
+ if (!line2) return null;
18591
+ if (unknownFacts(line2, c).length || novelWords(line2, c).length >= 2) return deep;
18592
+ const answer = norm3([...c.history.filter((h) => h.who === "you" && h.cut).slice(-1).map((h) => h.text), c.rest].join(" ")), q2 = norm3(quote);
18593
+ if (!q2 || !answer.includes(q2) || !asksAbout(c.heard, q2) || novelWords(line2, c, quote).length < novelWords(line2, c, answer).length) return deep;
18594
+ return { kind: "clarify", line: line2 };
18595
+ }
18436
18596
  const owns = quickOwns(c.heard);
18437
18597
  if (!owns && kind !== "DEEP") return { kind: "deep", ack: stockAck(c), brief: "" };
18438
18598
  if (kind === "QUIET") return { kind: "quiet" };
@@ -18442,7 +18602,7 @@ function rawMove(raw, c) {
18442
18602
  }
18443
18603
  if (kind === "DEEP") {
18444
18604
  const [ack = "", brief = ""] = body.split(body.includes("|") ? "|" : /\s+[—–-]\s+/).map((s) => s.trim());
18445
- const a = cleanLine(ack, c.lang, ACK_WORDS).replace(/[\s,;:—–-]+$/u, "");
18605
+ const a = cleanLine(ack, c.lang, c.plan ? 18 : ACK_WORDS, c.plan ? 140 : 60).replace(/[\s,;:—–-]+$/u, "");
18446
18606
  const said = new Set(c.history.filter((h) => h.who === "you").map((h) => norm3(h.text)));
18447
18607
  const ok = a && !said.has(norm3(a)) && !RESULT_CLAIM_RE.test(a) && !new RegExp("\\p{N}", "u").test(a);
18448
18608
  return { kind: "deep", ack: ok ? a : stockAck(c), brief };
@@ -18454,12 +18614,18 @@ function rawMove(raw, c) {
18454
18614
  const facts = unknownFacts(line, c), novel = novelWords(line, c);
18455
18615
  const unknown = facts.length || novel.length >= 2 ? [...facts, ...novel] : [];
18456
18616
  if (unknown.length) {
18457
- log39.debug(`quick line "${line}" names ${unknown.join(", ")} \u2014 not in the call: deep lane`);
18617
+ log40.debug(`quick line "${line}" names ${unknown.join(", ")} \u2014 not in the call: deep lane`);
18458
18618
  return { kind: "deep", ack: "", brief: "" };
18459
18619
  }
18460
18620
  return bye && isClosing(c.heard) ? { kind: "say", line, end: true } : { kind: "say", line };
18461
18621
  }
18462
- var stockAck = (c) => ownLine(ACKS[c.lang], c);
18622
+ var Q_STOP = new Set("who whom whose where which why how when what do does did is are was were the a an they she he it you your that this of in on at to and or one ones there their them about mean meant wait sorry so okay \u05DE\u05D9 \u05D0\u05D9\u05E4\u05D4 \u05DC\u05DE\u05D4 \u05D0\u05D9\u05DA \u05DE\u05EA\u05D9 \u05DE\u05D4 \u05D0\u05EA \u05D6\u05D4 \u05D6\u05D0\u05EA \u05D4\u05DD \u05D4\u05DF \u05D4\u05D5\u05D0 \u05D4\u05D9\u05D0".split(" "));
18623
+ function asksAbout(heard, normQuote) {
18624
+ const st = (w) => w.replace(/['’]s$/, "").replace(new RegExp("(?<=\\p{L}{3})(?:es|s)$", "u"), "");
18625
+ const qs = new Set(normQuote.split(" ").map(st));
18626
+ return norm3(heard).split(" ").some((w) => w && !Q_STOP.has(w) && qs.has(st(w)));
18627
+ }
18628
+ var stockAck = (c) => c.caller ? "" : ownLine(ACKS[c.lang], c);
18463
18629
  function quickOwns(heard) {
18464
18630
  const t = heard.replace(/\s*[—–]\s*/g, " ").trim(), n = norm3(t);
18465
18631
  if (!n) return null;
@@ -18515,15 +18681,17 @@ function holdLine(c) {
18515
18681
  const said = new Set(c.history.filter((h) => h.who === "you").map((h) => norm3(h.text)));
18516
18682
  return (HOLDS[c.lang] ?? []).find((x) => !said.has(norm3(x))) ?? "";
18517
18683
  }
18518
- function fastQuickLane(ai, model, gender, persona = "", hedgeMs = 900, tools = true) {
18519
- return async (c, signal) => {
18684
+ function fastQuickLane(ai, model, gender, persona = "", hedgeMs = 900, tools = true, caller = false, plan) {
18685
+ return async (c0, signal) => {
18686
+ const c = caller ? { ...c0, caller: true, ...plan?.text ? { plan: plan.text } : {} } : c0;
18687
+ if (caller && plan?.opener && !c.history.some((h) => h.who === "you")) return { kind: "deep", ack: plan.opener, brief: "" };
18520
18688
  if (c.rest && GO_ON.test(c.heard)) return { kind: "resume", line: "" };
18521
18689
  const hold = holdLine(c);
18522
18690
  if (hold) return { kind: "say", line: hold };
18523
18691
  const ask = async () => {
18524
18692
  const raw = await fastText(ai, { model, prompt: quickPrompt(c, gender, persona, tools), signal, temperature: 0.4 });
18525
18693
  const mv = quickMove(raw, c);
18526
- if (!mv) log39.debug(`quick lane: unusable "${raw.slice(0, 80)}"`);
18694
+ if (!mv) log40.debug(`quick lane: unusable "${raw.slice(0, 80)}"`);
18527
18695
  return mv;
18528
18696
  };
18529
18697
  let timer;
@@ -18553,13 +18721,83 @@ They just said: "${c.heard}"
18553
18721
  ` : "") + `
18554
18722
  Reply with exactly ONE line, one of:
18555
18723
  BYE: <a short farewell> \u2014 they mean to end the call ("no, thank you, bye", "okay, talk later"): the call hangs up after it. Judge the intent: "say bye to Dan" or "before I go, one more thing" is not an end.
18556
- SAY: <your words> \u2014 ONLY a greeting or how-are-you, a short reaction ("wow", "really?"), or when they ask exactly to repeat something ALREADY said ("say that again", "which one was that?"). Any request ("tell me a story\u2026"), any question about content ("what is\u2026?", "wait, what?", "how long is it?") is DEEP, even if you could guess. Max two short sentences. Use only facts from the call above; never invent a name, number, news item or result.
18724
+ SAY: <your words> \u2014 ONLY a greeting or how-are-you, a short reaction ("wow", "really?"), or when they ask exactly to repeat something ALREADY said ("say that again", "which one was that?"). Any request ("tell me a story\u2026"), any question about content ("what is\u2026?", "wait, what?", "how long is it?") is DEEP, even if you could guess${c.rest ? " (or CLARIFY, below)" : ""}. Max two short sentences. Use only facts from the call above; never invent a name, number, news item or result.
18557
18725
  DEEP: <a 2-8 word acknowledgement> | <what the colleague must do, names spelled right> \u2014 anything needing a lookup, current information, tools, files, or real thinking. The acknowledgement is your natural first reaction to THIS kind of ask, in your own voice: ${tools ? `a lookup says you're on it and names what you'll look at ("Sure, let me pull up the kitty changelog."); ` : `never say you will check, look up, pull up, find or fetch anything \u2014 nothing can be; a question gets a short thinking reaction ("Hmm, okay\u2026", "Right, so\u2026"); `}a story, joke or idea gets a reaction to the idea itself (a story about a dragon: "Ooh, a dragon story, okay\u2026"); a question about what was said gets a short "ah"-type reaction ("Ah, good question."). Say "checking" or "looking" only when something is actually looked up. Never a result. The speech-to-text misspells names: fix them from context ("Haka News" \u2192 Hacker News).
18558
- QUIET \u2014 nothing is owed: a bare "okay", "mm-hm", or a reaction you already answered.
18726
+ ` + (c.rest ? `CLARIFY: <one short answer> | <the exact words of your cut answer or its rest that answer it, copied verbatim> \u2014 they cut your answer to ask a quick question ABOUT it ("who?", "where do they sit?", "which one?") that your words above or the unsaid rest already answer. Find the exact span first, then answer from it only; your cut answer then goes on by itself. A new request, a change of topic, or a question those words do not answer is DEEP.
18727
+ ` : "") + `QUIET \u2014 nothing is owed: a bare "okay", "mm-hm", or a reaction you already answered.
18559
18728
  "Wait" / "hold on" with nothing new: a brief SAY ("Sure.") \u2014 no work for the colleague. Vary your words: never reuse an acknowledgement or reaction already said in this call.
18560
- A reaction ("wow", "really?") gets a short fitting reply in your own words ("I know, right?"), never their word back. Never repeat what was already said. Speak ${languageName(c.lang)}. ${personaHint(gender)} Output only the line.`;
18729
+ A reaction ("wow", "really?") gets a short fitting reply in your own words ("I know, right?"), never their word back. Never repeat what was already said. ` + (c.hint ? `
18730
+ A listener judge read this moment as: ${c.hint} (a hint; your own reading of their words wins).
18731
+ ` : "") + (c.plan ? `
18732
+ YOUR PLAN for this call (made before dialing; follow it, adapt to what they say):
18733
+ ${c.plan}
18734
+ When their words match a case in your plan, answer DEEP with that planned line as the acknowledgement (said at once; the colleague goes on from it).
18735
+ ` : "") + (c.caller ? `
18736
+ YOU PLACED THIS CALL: you ask, they answer; they are not your user. Never say you will check, wait or look anything up ("one moment", "checking", "\u05E8\u05D2\u05E2", "\u05D1\u05D5\u05D3\u05E7"). "Hello?" / "are you there?" from them = they lost you: SAY a short presence line in their language ("Yes, hi, I'm here" / "\u05DB\u05DF, \u05E9\u05DC\u05D5\u05DD, \u05D0\u05E0\u05D9 \u05E4\u05D4"). A DEEP acknowledgement may be empty ("DEEP: | \u2026"): prefer empty to a filler.
18737
+ ` : "") + `Speak ${languageName(c.lang)}. ${personaHint(gender)} Output only the line.`;
18561
18738
  }
18562
18739
 
18740
+ // src/voice/callPlan.ts
18741
+ init_logging();
18742
+ var log41 = forComponent("CallPlan");
18743
+ var CallPlanOptions = class {
18744
+ ai;
18745
+ model = "";
18746
+ /** Who calls whom and why (the call's task): the plan's only input. */
18747
+ persona = "";
18748
+ /** The call's language ('' = the persona's). */
18749
+ lang = "";
18750
+ gender;
18751
+ /** Give up after this long (the call goes on without a plan). */
18752
+ timeoutMs = 1e4;
18753
+ };
18754
+ var CallPlan = class _CallPlan {
18755
+ options;
18756
+ /** The whole plan as text ('' until ready / when it failed). */
18757
+ text = "";
18758
+ /** The first thing to say when a person answers: a hello + one short question. */
18759
+ opener = "";
18760
+ ready;
18761
+ /** How long the plan took (ms; 0 = not made). */
18762
+ ms = 0;
18763
+ /** The model's raw answer (diagnostics: a plan with no opener). */
18764
+ raw = "";
18765
+ constructor(options) {
18766
+ this.options = { ...new CallPlanOptions(), ...options };
18767
+ this.ready = this.options.persona ? this.make() : Promise.resolve();
18768
+ }
18769
+ /** The plan's prompt (exported for tests). */
18770
+ static prompt(persona, lang, gender) {
18771
+ return `${persona.slice(0, 800)}
18772
+
18773
+ You are about to dial this call. Plan it in your head first, like a person does: what you say first, what you ask and in what order, and how you answer what they will most likely say. One line each:
18774
+ OPENER: <only a casual greeting, the way people really open a call \u2014 may start with a small filler ("hmm", "uh") \u2014 1-3 words, no question yet>
18775
+ ASK: <your first short question, said after they answer the greeting; then the follow-ups in order> (2-4 lines)
18776
+ IF <a likely reply \u2014 yes, no, not in stock, don't know, hold on, transfer, who is this, a question back\u2026>: <what you say then> (4-7 lines)
18777
+ CLOSE: <a short thanks + bye>
18778
+ Every line is what you would say aloud: ${lang ? languageName(lang) : "the persona's language"}, casual and spoken like a real person (fillers, short turns, never formal), max 14 words, never a list in one breath, never "I am an AI", never a name for yourself or anyone that the task does not give, numbers as words ("five", not "5"). ${personaHint(gender)} Output only these lines.`;
18779
+ }
18780
+ /** "OPENER: …" → the opener (cleaned for speech). */
18781
+ static parse(raw, lang) {
18782
+ const lines = raw.split("\n").map((l) => l.replace(/^[\s>*_`#\-\d.)]+/, "").replace(/\*\*|__/g, "").trim()).filter((l) => /^(OPENER|ASK|IF|CLOSE)\b/i.test(l));
18783
+ const op = lines.find((l) => /^OPENER\b/i.test(l))?.replace(/^OPENER\s*:\s*/i, "").replace(/^["'\s]+|["'\s]+$/g, "") ?? "";
18784
+ return { text: lines.join("\n").slice(0, 1200), opener: op ? cleanLine(op, lang || "en", 18, 140) : "" };
18785
+ }
18786
+ async make() {
18787
+ const o = this.options, t0 = Date.now(), ac = new AbortController(), timer = setTimeout(() => ac.abort(), o.timeoutMs);
18788
+ try {
18789
+ const raw = this.raw = await fastText(o.ai, { model: o.model, prompt: _CallPlan.prompt(o.persona, o.lang, o.gender), signal: ac.signal, temperature: 0.4, maxTokens: 1500 });
18790
+ Object.assign(this, _CallPlan.parse(raw, o.lang));
18791
+ this.ms = Date.now() - t0;
18792
+ log41.debug(`plan ready in ${Date.now() - t0}ms: ${this.opener ? `opener "${this.opener}"` : "no opener"}`);
18793
+ } catch (e) {
18794
+ log41.debug(`no plan (${e?.message || e}) \u2014 the call goes on without one`);
18795
+ } finally {
18796
+ clearTimeout(timer);
18797
+ }
18798
+ }
18799
+ };
18800
+
18563
18801
  // cli/config.ts
18564
18802
  import { homedir as homedir5 } from "os";
18565
18803
  import { existsSync as existsSync5, readFileSync as readFileSync7 } from "fs";
@@ -18707,7 +18945,7 @@ function applyOverlay(cfg, file) {
18707
18945
  // cli/hooks-config.ts
18708
18946
  import { spawnSync as spawnSync4 } from "child_process";
18709
18947
  init_platform();
18710
- var log40 = forComponent("hooks");
18948
+ var log42 = forComponent("hooks");
18711
18949
  var escapeRegex = (s) => s.replace(/[.+^${}()|[\]\\]/g, "\\$&");
18712
18950
  function ruleMatches(rule, toolName) {
18713
18951
  if (!rule.tool || rule.tool === "*") return true;
@@ -18726,7 +18964,7 @@ function runCmd(rule, env) {
18726
18964
  });
18727
18965
  return { code: r.status ?? 1, out: ((r.stdout ?? "") + (r.stderr ?? "")).trim() };
18728
18966
  } catch (e) {
18729
- log40.debug(`hook command failed: ${rule.command}`, e);
18967
+ log42.debug(`hook command failed: ${rule.command}`, e);
18730
18968
  return { code: 1, out: String(e?.message ?? e) };
18731
18969
  }
18732
18970
  }
@@ -18834,7 +19072,7 @@ import { existsSync as existsSync6, mkdirSync as mkdirSync8, readFileSync as rea
18834
19072
  import { homedir as homedir6 } from "os";
18835
19073
  import { join as join11 } from "path";
18836
19074
  init_platform();
18837
- var log41 = forComponent("session");
19075
+ var log43 = forComponent("session");
18838
19076
  var globalDir = () => join11(homedir6(), ".agent", "sessions");
18839
19077
  function indexLink(target, link2) {
18840
19078
  try {
@@ -18897,7 +19135,7 @@ var SessionStore = class {
18897
19135
  }
18898
19136
  load(id) {
18899
19137
  if (!this.safeId(id)) {
18900
- log41.debug(`rejecting unsafe session id: ${id}`);
19138
+ log43.debug(`rejecting unsafe session id: ${id}`);
18901
19139
  return void 0;
18902
19140
  }
18903
19141
  const path = join11(this.dir, `${id}.json`);
@@ -18905,7 +19143,7 @@ var SessionStore = class {
18905
19143
  try {
18906
19144
  return JSON.parse(readFileSync8(path, "utf8"));
18907
19145
  } catch (e) {
18908
- log41.debug(`unreadable session ${id} \u2014 ignoring`, e);
19146
+ log43.debug(`unreadable session ${id} \u2014 ignoring`, e);
18909
19147
  return void 0;
18910
19148
  }
18911
19149
  }
@@ -18918,7 +19156,7 @@ var SessionStore = class {
18918
19156
  try {
18919
19157
  metas.push(JSON.parse(readFileSync8(join11(this.dir, f), "utf8")).meta);
18920
19158
  } catch (e) {
18921
- log41.debug(`skipping unreadable session file ${f}`, e);
19159
+ log43.debug(`skipping unreadable session file ${f}`, e);
18922
19160
  }
18923
19161
  }
18924
19162
  return metas.sort((a, b) => b.updated - a.updated);
@@ -19350,7 +19588,7 @@ import { promisify } from "util";
19350
19588
  import { writeFileSync as writeFileSync6, mkdirSync as mkdirSync9 } from "fs";
19351
19589
  import { homedir as homedir7 } from "os";
19352
19590
  import { join as join12, resolve as resolve4, sep as sep3, parse as parsePath } from "path";
19353
- var log42 = forComponent("checkpoints");
19591
+ var log44 = forComponent("checkpoints");
19354
19592
  var exec = promisify(execFile4);
19355
19593
  var DEFAULT_EXCLUDE = [".agent/", ".git/", "node_modules/", "dist/", "build/", ".next/", "target/", ".venv/", "__pycache__/", "*.log"];
19356
19594
  function isBroadRoot(p) {
@@ -19398,7 +19636,7 @@ var ShadowRepo = class {
19398
19636
  writeFileSync6(join12(this.gitDir, "info", "exclude"), this.exclude.join("\n") + "\n");
19399
19637
  this.ready = true;
19400
19638
  } catch (e) {
19401
- log42.debug(`git checkpoints unavailable for ${this.workTree}`, e);
19639
+ log44.debug(`git checkpoints unavailable for ${this.workTree}`, e);
19402
19640
  this.ready = false;
19403
19641
  }
19404
19642
  return this.ready;
@@ -19409,7 +19647,7 @@ var ShadowRepo = class {
19409
19647
  }
19410
19648
  async commit(label, forced = []) {
19411
19649
  await this.run("add", "-A");
19412
- for (const p of forced) await this.run("add", "-f", "--", p).catch((e) => log42.debug(`force-add failed: ${p}`, e));
19650
+ for (const p of forced) await this.run("add", "-f", "--", p).catch((e) => log44.debug(`force-add failed: ${p}`, e));
19413
19651
  await this.run("commit", "--allow-empty", "-q", "-m", label);
19414
19652
  }
19415
19653
  /** Inject the CURRENT (pre-edit) content of `paths` into the turn-open restore point by amending it.
@@ -19417,8 +19655,8 @@ var ShadowRepo = class {
19417
19655
  * turn-boundary `add -A` would never have captured it. Amend (vs a new commit) keeps one restore
19418
19656
  * point per turn, so the REPL's turn↔frame mapping stays intact. */
19419
19657
  async amendForced(paths) {
19420
- for (const p of paths) await this.run("add", "-f", "--", p).catch((e) => log42.debug(`force-capture failed: ${p}`, e));
19421
- await this.run("commit", "--amend", "--no-edit", "-q", "--allow-empty").catch((e) => log42.debug("amend failed", e));
19658
+ for (const p of paths) await this.run("add", "-f", "--", p).catch((e) => log44.debug(`force-capture failed: ${p}`, e));
19659
+ await this.run("commit", "--amend", "--no-edit", "-q", "--allow-empty").catch((e) => log44.debug("amend failed", e));
19422
19660
  }
19423
19661
  /** Commits on `ref`, oldest-first (canonical index space). */
19424
19662
  async log(ref) {
@@ -19478,7 +19716,7 @@ var ShadowRepo = class {
19478
19716
  await this.run("gc", "--auto", "-q").catch(() => {
19479
19717
  });
19480
19718
  } catch (e) {
19481
- log42.debug("checkpoint prune failed", e);
19719
+ log44.debug("checkpoint prune failed", e);
19482
19720
  }
19483
19721
  }
19484
19722
  };
@@ -19546,7 +19784,7 @@ var GitCheckpoints = class {
19546
19784
  use(sessionId) {
19547
19785
  if (sessionId === this.session) return;
19548
19786
  this.session = sessionId;
19549
- if (this.started) for (const r of this.repos) void r.point(this.ref()).catch((e) => log42.debug("re-point failed", e));
19787
+ if (this.started) for (const r of this.repos) void r.point(this.ref()).catch((e) => log44.debug("re-point failed", e));
19550
19788
  }
19551
19789
  async begin(label) {
19552
19790
  if (!await this.start()) return;
@@ -19566,7 +19804,7 @@ var GitCheckpoints = class {
19566
19804
  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
19567
19805
  `);
19568
19806
  } else {
19569
- log42.debug("checkpoint commit failed", e);
19807
+ log44.debug("checkpoint commit failed", e);
19570
19808
  survivors.push(this.repos[i]);
19571
19809
  survivorCaches.push(this.caches[i] ?? []);
19572
19810
  }
@@ -19601,7 +19839,7 @@ var GitCheckpoints = class {
19601
19839
  if (this.forced.has(abs)) continue;
19602
19840
  this.forced.add(abs);
19603
19841
  const i = this.repoIndexFor(abs);
19604
- if (i >= 0) await this.repos[i].amendForced([abs]).catch((e) => log42.debug("amendForced failed", e));
19842
+ if (i >= 0) await this.repos[i].amendForced([abs]).catch((e) => log44.debug("amendForced failed", e));
19605
19843
  }
19606
19844
  }
19607
19845
  };
@@ -21391,7 +21629,7 @@ import { spawnSync as spawnSync6 } from "child_process";
21391
21629
  import { writeFileSync as writeFileSync8, mkdirSync as mkdirSync10, readdirSync as readdirSync2, unlinkSync as unlinkSync3, chmodSync, existsSync as existsSync7 } from "fs";
21392
21630
  import { homedir as homedir8 } from "os";
21393
21631
  import { join as join14 } from "path";
21394
- var log43 = forComponent("os-sched");
21632
+ var log45 = forComponent("os-sched");
21395
21633
  var OsScheduler = class {
21396
21634
  options;
21397
21635
  constructor(options) {
@@ -21453,7 +21691,7 @@ var OsScheduler = class {
21453
21691
  }
21454
21692
  }
21455
21693
  } catch (e) {
21456
- log43.debug(`cancel ${id}`, e);
21694
+ log45.debug(`cancel ${id}`, e);
21457
21695
  }
21458
21696
  for (const f of [`${id}.json`, `${id}.sh`]) {
21459
21697
  try {
@@ -21571,7 +21809,7 @@ import { existsSync as existsSync8, mkdirSync as mkdirSync11, unlinkSync as unli
21571
21809
  import { homedir as homedir9 } from "os";
21572
21810
  import { join as join15 } from "path";
21573
21811
  init_platform();
21574
- var log44 = forComponent("remote-trigger");
21812
+ var log46 = forComponent("remote-trigger");
21575
21813
  var TRIGGER_DIR = () => join15(homedir9(), ".agent", "triggers");
21576
21814
  var sockPath = (sessionId, dir = TRIGGER_DIR()) => join15(dir, `${sessionId}.sock`);
21577
21815
  var TriggerServer = class {
@@ -21609,13 +21847,13 @@ var TriggerServer = class {
21609
21847
  conn.end(JSON.stringify({ ok: false, error: String(e) }) + "\n");
21610
21848
  }
21611
21849
  });
21612
- conn.on("error", (e) => log44.debug("trigger conn error", e));
21850
+ conn.on("error", (e) => log46.debug("trigger conn error", e));
21613
21851
  });
21614
- this.server.on("error", (e) => log44.debug("trigger server error", e));
21852
+ this.server.on("error", (e) => log46.debug("trigger server error", e));
21615
21853
  this.server.listen(p);
21616
21854
  this.path = p;
21617
21855
  } catch (e) {
21618
- log44.debug("trigger server unavailable", e);
21856
+ log46.debug("trigger server unavailable", e);
21619
21857
  }
21620
21858
  }
21621
21859
  /** Re-bind on /resume (the session id changed). */
@@ -21747,7 +21985,7 @@ var strike = C("9");
21747
21985
  var link = (text, url) => useColor ? `\x1B]8;;${url}\x1B\\${cyan(text)}\x1B]8;;\x1B\\` : `${text} (${url})`;
21748
21986
  var mdPalette = { bold, dim, cyan, italic, strike, green, link };
21749
21987
  var err = (s) => process.stderr.write(s);
21750
- var log45 = forComponent("cli");
21988
+ var log47 = forComponent("cli");
21751
21989
  var VERSION = (() => {
21752
21990
  try {
21753
21991
  return JSON.parse(readFileSync10(new URL("../package.json", import.meta.url), "utf8")).version ?? "?";
@@ -21909,6 +22147,12 @@ function parseArgs(argv) {
21909
22147
  else if (x === "--conversational" || x === "--convo" || x === "--voice") {
21910
22148
  a.voice = true;
21911
22149
  a.duplex = true;
22150
+ } else if (x === "--live") {
22151
+ a.voice = true;
22152
+ a.call = true;
22153
+ a.duplex = true;
22154
+ a.lean = true;
22155
+ a.channelMode ??= "live";
21912
22156
  } else if (x === "--voice-model") a.voiceModel = val(++i, x);
21913
22157
  else if (x === "--voice-gender") {
21914
22158
  const g = val(++i, x);
@@ -22016,6 +22260,8 @@ Flags:
22016
22260
  --call voice call (duplex v3): the main agent (-m, full tools) answers every turn; a fast model
22017
22261
  (--voice-model, default Claude Haiku) only fills the wait \u2014 backchannels, fillers, bridges,
22018
22262
  progress lines \u2014 and never enters the history. --duplex/--duplex-v2/--voice alias it
22263
+ --live live voice call: --call + mic on at start + --channel-mode live (Jev turn judge, quick lane,
22264
+ live prediction tree); TYPESAFE_AI_KEY enables Jev, else Groq decides
22019
22265
  interactively (AGENTX_DUPLEX_V1=1 keeps the v1 reflex below for one release)
22020
22266
  --duplex duplex mode: a fast voice model replies instantly and delegates real work
22021
22267
  to a background worker agent (-m model); results are re-voiced when ready
@@ -22659,7 +22905,7 @@ function turnCost(model, usage) {
22659
22905
  const priced = model.startsWith("claude-code/") ? `anthropic/${resolveModelAlias(model.slice("claude-code/".length))}` : model;
22660
22906
  return costOf(getModelInfo(priced)?.pricing, usage?.promptTokens ?? 0, usage?.completionTokens ?? 0, usage?.cacheCreationTokens ?? 0, usage?.cacheReadTokens ?? 0, priced);
22661
22907
  }
22662
- async function evaluateGoal(ai, condition, transcript, log46) {
22908
+ async function evaluateGoal(ai, condition, transcript, log48) {
22663
22909
  const recent = transcript.filter((m) => m.role === "assistant").slice(-8).map((m) => {
22664
22910
  const text = typeof m.content === "string" ? m.content : m.content.filter((p) => p.type === "text").map((p) => p.text).join(" ");
22665
22911
  return text.slice(0, 600);
@@ -22679,7 +22925,7 @@ ${recent}` }
22679
22925
  const match = r.content.match(/\{[\s\S]*\}/);
22680
22926
  if (match) return JSON.parse(match[0]);
22681
22927
  } catch (e) {
22682
- log46(dim(` (goal evaluator error: ${e?.message ?? e})
22928
+ log48(dim(` (goal evaluator error: ${e?.message ?? e})
22683
22929
  `));
22684
22930
  }
22685
22931
  return { met: false, reason: "evaluation unclear" };
@@ -22908,7 +23154,7 @@ function mcpAgentTools(mounted, opts) {
22908
23154
  return tools;
22909
23155
  }
22910
23156
  async function closeMcp(mounted) {
22911
- await Promise.all(mounted.map((m) => m.client.close().catch((e) => log45.debug("mcp close failed", e))));
23157
+ await Promise.all(mounted.map((m) => m.client.close().catch((e) => log47.debug("mcp close failed", e))));
22912
23158
  }
22913
23159
  var IMG_EXT = { ".png": "image/png", ".jpg": "image/jpeg", ".jpeg": "image/jpeg", ".gif": "image/gif", ".webp": "image/webp" };
22914
23160
  function mentionRefs(line) {
@@ -22967,7 +23213,7 @@ async function expandMentions(fs, line) {
22967
23213
  if (loaded.includes(ref) || missing.includes(ref)) continue;
22968
23214
  if (ref.includes(":") && mcpMentionResolver) {
22969
23215
  const body = await mcpMentionResolver(ref).catch((e) => {
22970
- log45.debug("mcp mention resolve failed", e);
23216
+ log47.debug("mcp mention resolve failed", e);
22971
23217
  return null;
22972
23218
  });
22973
23219
  if (body != null) {
@@ -22993,7 +23239,7 @@ ${await fs.readFile(path)}`);
22993
23239
  ${blocks.join("\n\n")}` : line, loaded, missing };
22994
23240
  }
22995
23241
  function applyTurnMode(agent, session, task, flags = {}, onModel) {
22996
- const p = parseDirectives(task, { strict: true, keys: ["model", "turns", "delegate", "advisor", "mode"], warn: (m) => log45.debug(m) });
23242
+ const p = parseDirectives(task, { strict: true, keys: ["model", "turns", "delegate", "advisor", "mode"], warn: (m) => log47.debug(m) });
22997
23243
  const d = p.directives, isMode = !!(d.delegate || d.advisor || d.modeOff);
22998
23244
  if (p.unresolvedModel && /->|<-|delegate:|advisor:/.test(task.slice(0, task.length - p.prompt.length))) {
22999
23245
  err(red(` \u2717 unknown model "${p.unresolvedModel}"${p.ambiguous ? ` (could be: ${p.ambiguous.join(", ")})` : ""} \u2014 turn not sent
@@ -23086,7 +23332,7 @@ async function runTurn(agent, store, session, task, cp, cwd = process.cwd(), sen
23086
23332
  try {
23087
23333
  store.save(session);
23088
23334
  } catch (ex) {
23089
- log45.debug("mid-turn session flush failed", ex);
23335
+ log47.debug("mid-turn session flush failed", ex);
23090
23336
  }
23091
23337
  }
23092
23338
  return origNotify(e);
@@ -23250,14 +23496,14 @@ var isCancelTeardown = (e) => {
23250
23496
  function installCancelGuards(mounted) {
23251
23497
  process.on("unhandledRejection", (e) => {
23252
23498
  if (isCancelTeardown(e)) {
23253
- log45.debug("suppressed unhandledRejection (cursor stream cancel)", e);
23499
+ log47.debug("suppressed unhandledRejection (cursor stream cancel)", e);
23254
23500
  return;
23255
23501
  }
23256
- log45.error("unhandledRejection", e);
23502
+ log47.error("unhandledRejection", e);
23257
23503
  });
23258
23504
  process.on("uncaughtException", (e) => {
23259
23505
  if (isCancelTeardown(e)) {
23260
- log45.debug("suppressed uncaughtException (cursor stream cancel)", e);
23506
+ log47.debug("suppressed uncaughtException (cursor stream cancel)", e);
23261
23507
  return;
23262
23508
  }
23263
23509
  console.error(e);
@@ -23612,6 +23858,10 @@ async function repl(args, ai, cfg, cwd) {
23612
23858
  call = new VoiceCall({
23613
23859
  ai,
23614
23860
  ...fast.options,
23861
+ ...args.channelMode === "live" ? (() => {
23862
+ const turnJudge = turnJudgeFor();
23863
+ return turnJudge ? { turnJudge } : {};
23864
+ })() : {},
23615
23865
  // live: the quick lane owns the conversation, MAIN is its deep lane (#1331). Only here: its lines reach MAIN through
23616
23866
  // noteTurn, which a --channel-only host (Para) does not take yet.
23617
23867
  ...args.channelMode === "live" && process.env.AGENTX_QUICK_LANE !== "0" ? { quick: fastQuickLane(ai, fast.options.fastModel, args.voiceGender, args.voicePersona) } : {},
@@ -23673,7 +23923,7 @@ ${SPOKEN_TURN}`, { id });
23673
23923
  editorRef?.abort();
23674
23924
  }
23675
23925
  } catch (e) {
23676
- log45.error("call turn failed", e);
23926
+ log47.error("call turn failed", e);
23677
23927
  } finally {
23678
23928
  rec.running = false;
23679
23929
  call?.main({ type: "done", id });
@@ -23827,7 +24077,7 @@ ${SPOKEN_TURN}`, { id });
23827
24077
  try {
23828
24078
  mkdirSync12(dir, { recursive: true });
23829
24079
  } catch (e) {
23830
- log45.debug("paste image dir create failed", e);
24080
+ log47.debug("paste image dir create failed", e);
23831
24081
  }
23832
24082
  const img = grabClipboardImage(dir, String(Date.now()));
23833
24083
  return img ? { display: "Image", ref: "@" + img.path, path: img.path } : null;
@@ -23940,7 +24190,7 @@ Added entries are loadable now via the Skill/SlashCommand tools; removed ones ar
23940
24190
  mkdirSync12(join16(cwd, ".agent"), { recursive: true });
23941
24191
  appendFileSync2(histPath, line + "\n");
23942
24192
  } catch (e) {
23943
- log45.debug("history write failed", e);
24193
+ log47.debug("history write failed", e);
23944
24194
  }
23945
24195
  };
23946
24196
  const ago = (t) => {
@@ -24012,7 +24262,7 @@ Added entries are loadable now via the Skill/SlashCommand tools; removed ones ar
24012
24262
  try {
24013
24263
  store.save(session);
24014
24264
  } catch (e) {
24015
- log45.debug("session save after rewind failed", e);
24265
+ log47.debug("session save after rewind failed", e);
24016
24266
  }
24017
24267
  err(green(" \u27F2 jumped back") + dim(` \u2014 ${face.transcript.length} message(s) kept; edit + resend
24018
24268
  `));
@@ -24047,7 +24297,7 @@ ${task}`;
24047
24297
  bangContext.length = 0;
24048
24298
  }
24049
24299
  const delta = await refreshCatalogs().catch((e) => {
24050
- log45.debug("catalog refresh failed", e);
24300
+ log47.debug("catalog refresh failed", e);
24051
24301
  return "";
24052
24302
  });
24053
24303
  if (delta) {
@@ -24321,7 +24571,7 @@ ${task}`;
24321
24571
  desc: "rescan skills/commands dirs and rebuild the system prompt (one cache miss) \u2014 picks up entries created mid-session",
24322
24572
  run: async () => {
24323
24573
  await refreshCatalogs().catch((e) => {
24324
- log45.debug("catalog refresh failed", e);
24574
+ log47.debug("catalog refresh failed", e);
24325
24575
  });
24326
24576
  face.reprepare();
24327
24577
  err(green(` \u2713 reloaded \u2014 ${skills.length} skill(s), ${cmds.length} command(s); system prompt rebuilds on next message
@@ -24824,7 +25074,7 @@ ${task}`;
24824
25074
  try {
24825
25075
  for (const def of (await loadAgents(fs2, d)).agents) if (!seen.has(def.name)) seen.set(def.name, { def, from: d });
24826
25076
  } catch (e) {
24827
- log45.debug(`loadAgents(${d}) failed`, e);
25077
+ log47.debug(`loadAgents(${d}) failed`, e);
24828
25078
  }
24829
25079
  }
24830
25080
  if (!seen.size) {
@@ -24912,7 +25162,7 @@ ${task}`;
24912
25162
  }
24913
25163
  if (idx >= 0) {
24914
25164
  const old = mounted.splice(idx, 1)[0];
24915
- await old.client.close().catch((e) => log45.debug("mcp close failed", e));
25165
+ await old.client.close().catch((e) => log47.debug("mcp close failed", e));
24916
25166
  }
24917
25167
  try {
24918
25168
  const m = await mountMcpServer(name, conf);
@@ -24940,7 +25190,7 @@ ${task}`;
24940
25190
  }
24941
25191
  const m = mounted.splice(idx, 1)[0];
24942
25192
  remountMcpTools();
24943
- await m.client.close().catch((e) => log45.debug("mcp close failed", e));
25193
+ await m.client.close().catch((e) => log47.debug("mcp close failed", e));
24944
25194
  err(dim(` removed "${name}"
24945
25195
  `));
24946
25196
  return;
@@ -25143,7 +25393,7 @@ ${task}`;
25143
25393
  try {
25144
25394
  return readdirSync4(join16(cwd, absDir.replace(/^\/+/, "")), { withFileTypes: true }).map((d) => ({ name: d.name, dir: d.isDirectory() }));
25145
25395
  } catch (e) {
25146
- log45.debug("completion readdir failed", absDir, e);
25396
+ log47.debug("completion readdir failed", absDir, e);
25147
25397
  return null;
25148
25398
  }
25149
25399
  };
@@ -25282,7 +25532,7 @@ ${out}
25282
25532
  return;
25283
25533
  }
25284
25534
  await refreshCatalogs().catch((e) => {
25285
- log45.debug("catalog refresh failed", e);
25535
+ log47.debug("catalog refresh failed", e);
25286
25536
  });
25287
25537
  const sk = skills.find((x) => x.name === name);
25288
25538
  if (sk) {
@@ -25412,7 +25662,7 @@ ${out}
25412
25662
  if (delivery || cut) dx?.parkCutDelivery(delivery, !!cut, heard);
25413
25663
  const cutReply = cut && cut.full.length - cut.heard.length > 40 ? cut : null;
25414
25664
  const noteP = replaces ? replaces.note : !cutReply ? Promise.resolve("") : (instinct ? instinct.bargeIntent(text).catch((e) => {
25415
- log45.warn(`barge intent failed \u2014 model decides: ${e.message}`);
25665
+ log47.warn(`barge intent failed \u2014 model decides: ${e.message}`);
25416
25666
  return void 0;
25417
25667
  }) : Promise.resolve(void 0)).then(async (intent) => interruptionNote(cutReply, intent) + ackedNote(await instinct?.ackFor(text)));
25418
25668
  const cutIn = replaces ? replaces.cutIn : interjectNote;
@@ -25813,10 +26063,10 @@ function channelOptions(ai, model, gender) {
25813
26063
  // 0: the reactive live path
25814
26064
  pickLeaf: fastLeafPicker(ai, process.env.AGENTX_LEAF_MODEL || "groq/openai/gpt-oss-120b"),
25815
26065
  persona: process.env.AGENTX_CALL_PERSONA ?? "",
25816
- onTree: (e) => log45.debug(`voice tree: ${e.branches} branches in ${e.ms}ms${e.tokens ? ` tokens ${e.tokens.input}/${e.tokens.output}` : ""}${e.error ? ` error ${e.error}` : ""}`),
26066
+ onTree: (e) => log47.debug(`voice tree: ${e.branches} branches in ${e.ms}ms${e.tokens ? ` tokens ${e.tokens.input}/${e.tokens.output}` : ""}${e.error ? ` error ${e.error}` : ""}`),
25817
26067
  onEvent: (e) => {
25818
- if (e.moment) log45.debug(`voice leaf: ${e.moment} ${e.conf} "${e.text}" ${e.acted}`);
25819
- else log45.debug(`channel ${e.trigger}: rule=${e.rule} choice=${e.choice ?? "-"} \u2192 ${e.acted}${e.text ? ` "${e.text}"` : ""}${e.cue ? " (planned cue)" : ""} ${e.ms}ms`);
26068
+ if (e.moment) log47.debug(`voice leaf: ${e.moment} ${e.conf} "${e.text}" ${e.acted}`);
26069
+ else log47.debug(`channel ${e.trigger}: rule=${e.rule} choice=${e.choice ?? "-"} \u2192 ${e.acted}${e.text ? ` "${e.text}"` : ""}${e.cue ? " (planned cue)" : ""} ${e.ms}ms`);
25820
26070
  },
25821
26071
  // Banks in the user's language: generated once per language, cached + topped up across sessions (~/.agent/cache).
25822
26072
  banks: new ChannelBanks({ generate: fastBankGenerator(ai, model), cacheDir: join16(homedir10(), ".agent", "cache", "channel-banks") }),
@@ -25910,7 +26160,7 @@ async function duplexServe(args, ai, cfg, cwd) {
25910
26160
  try {
25911
26161
  store.save(session);
25912
26162
  } catch (e) {
25913
- log45.warn("duplex session save failed", e);
26163
+ log47.warn("duplex session save failed", e);
25914
26164
  }
25915
26165
  };
25916
26166
  const overlap2 = overlapResponder(ai, args.duplexV2 ? args.channelMode : void 0, out);
@@ -25950,7 +26200,7 @@ async function duplexServe(args, ai, cfg, cwd) {
25950
26200
  done2();
25951
26201
  out({ type: "turn_done", id, finishReason: res?.finishReason ?? "error", ...why ? { error: why } : {} });
25952
26202
  }).catch((e) => {
25953
- log45.error("duplex turn failed", e);
26203
+ log47.error("duplex turn failed", e);
25954
26204
  done2();
25955
26205
  out({ type: "turn_done", id, finishReason: "error", error: String(e?.message ?? e) });
25956
26206
  });
@@ -25969,12 +26219,22 @@ async function channelServe(args, ai, cfg) {
25969
26219
  const { model, notes, options: fast } = callFast(args, ai, cfg);
25970
26220
  const quick = args.quickLane && args.channelMode === "live" && process.env.AGENTX_QUICK_LANE !== "0";
25971
26221
  let cut = null;
26222
+ const caller = process.env.AGENTX_CALL_ROLE === "caller", persona = process.env.AGENTX_CALL_PERSONA ?? "";
26223
+ const plan = quick && caller && persona ? new CallPlan({ ai, model: fast.fastModel, persona, lang: process.env.AGENTX_CALL_LANG ?? "", gender: args.voiceGender }) : void 0;
26224
+ void plan?.ready.then(() => {
26225
+ out({ type: "metric", name: "plan", ms: plan.ms, ...plan.opener ? { text: plan.opener } : {}, kind: plan.opener ? `opener "${plan.opener}"` : `no opener: ${JSON.stringify(plan.raw.slice(0, 300))}` });
26226
+ if (plan.text) out({ type: "note", text: `Your plan for this call (made before dialing \u2014 follow it, adapt to what they say; your quick voice may already have said its lines):
26227
+ ${plan.text}` });
26228
+ });
26229
+ const menu = caller ? new MenuKeys({ ai, model: process.env.AGENTX_MENU_MODEL || "groq/openai/gpt-oss-120b", persona }) : void 0;
26230
+ const turnJudge = args.channelMode === "live" ? turnJudgeFor() : void 0;
25972
26231
  const call = new VoiceCall({
25973
26232
  ...fast,
25974
26233
  // no `ai` here: the channel's model wiring is explicit
26234
+ ...turnJudge ? { turnJudge } : {},
25975
26235
  ...quick ? {
25976
- quick: fastQuickLane(ai, fast.fastModel, args.voiceGender, process.env.AGENTX_CALL_PERSONA ?? "", void 0, process.env.AGENTX_CALL_NO_TOOLS !== "1"),
25977
- // (1: MAIN has no tools — a sandboxed phone call)
26236
+ quick: fastQuickLane(ai, fast.fastModel, args.voiceGender, persona, void 0, process.env.AGENTX_CALL_NO_TOOLS !== "1", caller, plan),
26237
+ // (NO_TOOLS 1: MAIN has no tools — a sandboxed phone call; ROLE caller: we placed it)
25978
26238
  noteTurn: (text) => out({ type: "note", text }),
25979
26239
  heardCut: () => cut?.heard ?? null,
25980
26240
  cutRest: () => cut && cut.full.slice(cut.heard.length).trim() || null,
@@ -26010,6 +26270,7 @@ async function channelServe(args, ai, cfg) {
26010
26270
  return call.aside(t);
26011
26271
  });
26012
26272
  out({ type: "ready", model, channelMode: args.channelMode, softBarge: softBarge(args.channelMode), call: true, ...quick ? { quickLane: true } : {}, ...notes.length ? { notes } : {} });
26273
+ if (args.channelMode === "live") out({ type: "metric", name: "judge", kind: turnJudge ? `on (${process.env.TYPESAFE_AI_KEY ? "jev" : "groq"})` : "off (no decider key)" });
26013
26274
  const rl = createInterface({ input: process.stdin });
26014
26275
  rl.on("line", (line) => {
26015
26276
  let m;
@@ -26032,6 +26293,8 @@ async function channelServe(args, ai, cfg) {
26032
26293
  else if (m.type === "user" && typeof m.text === "string") call.hostTurn(m.text);
26033
26294
  else if (m.type === "text" && typeof m.text === "string") call.fill.onMainTokens(m.text);
26034
26295
  else if (m.type === "overlap") overlap2(m);
26296
+ else if (m.type === "menu" && menu && typeof m.text === "string") void menu.hear(m.text).then((r) => out({ type: "keys", digits: r.digits, ms: r.ms, text: m.text }));
26297
+ else if (m.type === "pressed" && menu && typeof m.digits === "string") menu.pressed(m.digits);
26035
26298
  else if (m.type === "exit") rl.close();
26036
26299
  });
26037
26300
  await new Promise((r) => rl.on("close", () => r()));