@livx.cc/agentx 0.99.155 → 0.99.157

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
@@ -6493,14 +6493,14 @@ function summarize(messages, focus) {
6493
6493
  if (lastAssistant) lines.push(`last assistant: ${lastAssistant}`);
6494
6494
  if (carried.length) lines.push("earlier recap:", ...carried.map((l) => ` ${l}`));
6495
6495
  if (focus?.trim()) {
6496
- const words4 = focus.toLowerCase().split(/\s+/).filter((w) => w.length > 2);
6496
+ const words5 = focus.toLowerCase().split(/\s+/).filter((w) => w.length > 2);
6497
6497
  const kept = [];
6498
6498
  const ordered = [...messages.filter((m) => !isSyntheticSummary(m)), ...messages.filter(isSyntheticSummary)];
6499
6499
  outer: for (const msg of ordered) {
6500
6500
  if (msg.role === "tool") continue;
6501
6501
  for (const line of contentText(msg.content).split("\n")) {
6502
6502
  const l = line.toLowerCase();
6503
- if (line.trim() && words4.some((w) => l.includes(w))) {
6503
+ if (line.trim() && words5.some((w) => l.includes(w))) {
6504
6504
  kept.push(line.trim().slice(0, 200));
6505
6505
  if (kept.length >= 12) break outer;
6506
6506
  }
@@ -7667,13 +7667,13 @@ function isTranscriptComplete(text) {
7667
7667
  const trimmed = text.trim();
7668
7668
  if (!trimmed) return false;
7669
7669
  if (/[.?!]$/.test(trimmed)) return true;
7670
- const words4 = trimmed.toLowerCase().split(/\s+/);
7671
- const lastWord = words4[words4.length - 1];
7670
+ const words5 = trimmed.toLowerCase().split(/\s+/);
7671
+ const lastWord = words5[words5.length - 1];
7672
7672
  if (COMPLETE_ENDINGS.has(lastWord)) return true;
7673
7673
  if (INCOMPLETE_ENDINGS.has(lastWord)) return false;
7674
7674
  const lower2 = trimmed.toLowerCase();
7675
7675
  for (const marker of CONTINUATION_MARKERS) if (lower2.endsWith(marker)) return false;
7676
- if (words4.length <= 2) return false;
7676
+ if (words5.length <= 2) return false;
7677
7677
  return true;
7678
7678
  }
7679
7679
  var MAX_HOLD_MS = 2e3;
@@ -7723,12 +7723,12 @@ var SpeakerRunsOptions = class {
7723
7723
  /** A run shorter than this (a diarization flap) joins its neighbour — the previous run, or the next for a leading one. */
7724
7724
  minRunWords = 2;
7725
7725
  };
7726
- function speakerRuns(words4, options) {
7726
+ function speakerRuns(words5, options) {
7727
7727
  const { minRunWords } = { ...new SpeakerRunsOptions(), ...options };
7728
7728
  let runs = [];
7729
- for (const w of words4) {
7729
+ for (const w of words5) {
7730
7730
  const last = runs[runs.length - 1];
7731
- const spk = w.spk ?? last?.spk ?? words4.find((x) => x.spk != null)?.spk ?? "";
7731
+ const spk = w.spk ?? last?.spk ?? words5.find((x) => x.spk != null)?.spk ?? "";
7732
7732
  if (last?.spk === spk) last.words.push(w);
7733
7733
  else runs.push({ spk, words: [w] });
7734
7734
  }
@@ -8194,13 +8194,13 @@ var VoiceEngine = class _VoiceEngine {
8194
8194
  };
8195
8195
  if (this.options.revealMode === "word" || this.options.heardTimestamps) {
8196
8196
  this.tts.wantTimestamps = true;
8197
- this.tts.onTimestamps = (words4, start) => {
8197
+ this.tts.onTimestamps = (words5, start) => {
8198
8198
  if (this.interrupted) return;
8199
8199
  start.forEach((s, i) => {
8200
- if (this.wordAnchorPending) this.wordPending.push([words4[i] ?? "", s]);
8200
+ if (this.wordAnchorPending) this.wordPending.push([words5[i] ?? "", s]);
8201
8201
  else {
8202
8202
  this.wordStarts.push(this.wordOrigin + s);
8203
- this.wordTexts.push(words4[i] ?? "");
8203
+ this.wordTexts.push(words5[i] ?? "");
8204
8204
  }
8205
8205
  });
8206
8206
  };
@@ -8475,8 +8475,8 @@ var VoiceEngine = class _VoiceEngine {
8475
8475
  while (n < this.wordStarts.length && this.wordStarts[n] <= playedSec) n++;
8476
8476
  if (n !== this.revealedN) {
8477
8477
  this.revealedN = n;
8478
- const words4 = this.revealText.trim().split(/\s+/).filter(Boolean);
8479
- this.options.onReveal(words4.slice(0, n).join(" "));
8478
+ const words5 = this.revealText.trim().split(/\s+/).filter(Boolean);
8479
+ this.options.onReveal(words5.slice(0, n).join(" "));
8480
8480
  }
8481
8481
  this.revealPoll = this.clock.setTimeout(tick, 60);
8482
8482
  };
@@ -9322,7 +9322,8 @@ var VoiceEngine = class _VoiceEngine {
9322
9322
  const names = lines.map((t) => this.options.speakerResolver.name(t.speaker, t));
9323
9323
  return { out: formatTurns(lines, (t) => names[lines.indexOf(t)]), speakers: [...new Set(names)] };
9324
9324
  }
9325
- handleUtterance(text, langs, rawTurns) {
9325
+ /** `judged`: the host yielded to these very words (decideOverlap) — the user's, never our echo. */
9326
+ handleUtterance(text, langs, rawTurns, judged = false) {
9326
9327
  let turns;
9327
9328
  const cap = this.uttEcho;
9328
9329
  this.uttEcho = void 0;
@@ -9356,12 +9357,23 @@ var VoiceEngine = class _VoiceEngine {
9356
9357
  }
9357
9358
  }
9358
9359
  const ownTail = !this.pausedAt && (this.clock.now() < this.bargeGraceUntil || this.refinalizes(text));
9360
+ if (this.speaking && this.ctxOpen && !this.pausedAt && this.overlapCapable && !ownTail && this.options.overlapDecideMs > 0 && this.shortOverlap(text) && this.novelWords(text).length > 0 && this.novelWords(text).length * 2 >= this.words(text).length) {
9361
+ this.pausedAt = this.clock.now();
9362
+ this.player.pause();
9363
+ this.lastOverlapPartial = text;
9364
+ this.decideHeldFinal = text;
9365
+ addLangs(this.decideHeldLangs, langs);
9366
+ this.decideHeldTurns.push(...turns);
9367
+ this.diag("overlap_pause", { text: text.slice(0, 60), final: true });
9368
+ this.awaitOverlapDecision(text);
9369
+ return;
9370
+ }
9359
9371
  if (this.speaking && (this.ctxOpen || this.pausedAt) && this.overlapCapable && !ownTail) {
9360
9372
  this.diag("utterance_drop", { reason: "overlap_noise", text: text.slice(0, 60) });
9361
9373
  this.stt.reset();
9362
9374
  return;
9363
9375
  }
9364
- if (this.echoActive() && (!this.options.bargeIn || (this.usingAec ? this.echoFinal(text, audible) : this.novelWords(text).length < 2))) {
9376
+ if (!judged && this.echoActive() && (!this.options.bargeIn || (this.usingAec ? this.echoFinal(text, audible) : this.novelWords(text).length < 2))) {
9365
9377
  this.diag("echo_swallow", { guard: "echo_gate", text: text.slice(0, 60) });
9366
9378
  this.stt.reset();
9367
9379
  return;
@@ -9518,7 +9530,7 @@ var VoiceEngine = class _VoiceEngine {
9518
9530
  this.diag("barge_in", { phase, trigger, novel: this.novelWords(txt).length, total: this.words(txt).length });
9519
9531
  this.interrupt();
9520
9532
  this.options.onBargeIn(phase);
9521
- if (held2) this.handleUtterance(held2, heldLangs, heldTurns);
9533
+ if (held2) this.handleUtterance(held2, heldLangs, heldTurns, trigger === "host_yield");
9522
9534
  }
9523
9535
  /** Wait (bounded) for the host's verdict. `fresh` = a re-decision on grown text: it gets its own window — the host
9524
9536
  * was only just asked about it (live: "Oh," → "Oh, that" → "Oh, that— that's new" outgrew every verdict, and the
@@ -10104,8 +10116,8 @@ var SonioxSTT = class {
10104
10116
  /** Per-speaker turns of the current utterance (diarization only; undefined otherwise or when Soniox tagged no speaker). */
10105
10117
  turns(withPartials) {
10106
10118
  if (!this.options.diarization) return void 0;
10107
- const words4 = sonioxWords(withPartials ? [...this.finalToks, ...this.partialToks] : this.finalToks);
10108
- return words4.some((w) => w.spk != null) ? speakerRuns(words4) : void 0;
10119
+ const words5 = sonioxWords(withPartials ? [...this.finalToks, ...this.partialToks] : this.finalToks);
10120
+ return words5.some((w) => w.spk != null) ? speakerRuns(words5) : void 0;
10109
10121
  }
10110
10122
  reset() {
10111
10123
  this.finalToks = [];
@@ -10459,6 +10471,14 @@ import { AIClient, DecideClient, JevAdapter, LlmDecideAdapter } from "ai.libx.js
10459
10471
 
10460
10472
  // src/voice/overlap.ts
10461
10473
  init_logging();
10474
+
10475
+ // src/voice/closing.ts
10476
+ var words = (s) => s.trim() ? s.trim().split(/\s+/) : [];
10477
+ function isClosing(text) {
10478
+ return words(text).length <= 8 && /(?:^|[^\p{L}])(?:good ?bye|bye|see you|good ?night|talk (?:to you )?later|hang up|end (?:the )?call|ביי|להתראות|נתראה|לילה טוב|יאללה ביי)(?:$|[^\p{L}])/iu.test(text);
10479
+ }
10480
+
10481
+ // src/voice/overlap.ts
10462
10482
  var log20 = forComponent("Overlap");
10463
10483
  var norm2 = (s) => s.toLowerCase().replace(/[’']/g, "'").replace(/[^\p{L}\p{N}' -]+/gu, " ").replace(/\s+/g, " ").trim();
10464
10484
  var HARD = /^(?:(?:stop|wait|no|nope|hold on|hang on|hold up|pause|cancel|quiet|enough|shut up|never ?mind)(?: |$))+$/;
@@ -10502,19 +10522,20 @@ function overlapRule(text) {
10502
10522
  if (CONTINUE.test(norm2(text))) return "keep";
10503
10523
  let t = norm2(text);
10504
10524
  if (!t) return void 0;
10525
+ if (isClosing(text)) return "cut";
10505
10526
  if (HARD.test(t + " ")) return t.includes(" ") ? "cut" : "hold";
10506
10527
  for (const p of PHRASES) t = t.split(p).join(" ");
10507
- const words4 = t.split(/[\s-]+/).filter(Boolean);
10528
+ const words5 = t.split(/[\s-]+/).filter(Boolean);
10508
10529
  const ack = (w) => ACK.has(w) || HE_ACK.has(w) || /^(?:ha)+h?$|^(?:he)+h?$|^m+(?:hm+)?$|^h?m+$/.test(w);
10509
- if (words4.every(ack)) return "keep";
10510
- const lead2 = words4.findIndex((w) => !LEAD.has(w));
10511
- if (lead2 >= 0 && LEADER.has(words4[lead2]) && !words4.some((w) => HARD.test(w + " ")) && words4.slice(lead2).filter((w) => !ack(w) && !LEAD.has(w)).length <= 1) return "keep";
10530
+ if (words5.every(ack)) return "keep";
10531
+ const lead2 = words5.findIndex((w) => !LEAD.has(w));
10532
+ if (lead2 >= 0 && LEADER.has(words5[lead2]) && !words5.some((w) => HARD.test(w + " ")) && words5.slice(lead2).filter((w) => !ack(w) && !LEAD.has(w)).length <= 1) return "keep";
10512
10533
  return void 0;
10513
10534
  }
10514
10535
  function fastOverlapModel(ai, model = "groq/qwen/qwen3.8-27b") {
10515
10536
  return async (heard, signal) => {
10516
10537
  const prompt = 'Live voice call. The assistant is mid-sentence and the user just said this over it: "' + heard + `"
10517
- Are they STEERING \u2014 asking for something new, asking a real question about it, correcting it, or telling it to stop? A reaction is not steering: surprise, disbelief, "what?", "really?", "you're serious?", "that's serious", agreement, a laugh \u2014 the assistant just carries on.
10538
+ 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.
10518
10539
  Answer yes (steering) or no (a reaction).`;
10519
10540
  const reasoning = /qwen/.test(model) ? { providerOptions: { reasoning_effort: "none" } } : /gpt-oss/.test(model) ? { providerOptions: { reasoning_effort: "low" } } : {};
10520
10541
  const r = await ai.chat({ model, messages: [{ role: "user", content: prompt }], stream: false, signal, temperature: 0, maxTokens: /gpt-oss/.test(model) ? 200 : 3, ...reasoning });
@@ -10719,7 +10740,7 @@ function interruptionNote(cut, intent, hold = true) {
10719
10740
  }
10720
10741
  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. ";
10721
10742
  var acted = (what, r) => r === false ? `${what}_skipped` : what;
10722
- var words = (s) => s.trim() ? s.trim().split(/\s+/).length : 0;
10743
+ var words2 = (s) => s.trim() ? s.trim().split(/\s+/).length : 0;
10723
10744
  var Instinct = class {
10724
10745
  constructor(options) {
10725
10746
  this.options = options;
@@ -10764,7 +10785,7 @@ var Instinct = class {
10764
10785
  this.turnStart = 0;
10765
10786
  }
10766
10787
  async consult(heard) {
10767
- if (this.inflight || words(heard) < this.o.minWords) return;
10788
+ if (this.inflight || words2(heard) < this.o.minWords) return;
10768
10789
  this.inflight = true;
10769
10790
  try {
10770
10791
  const now4 = this.o.now();
@@ -10778,7 +10799,7 @@ var Instinct = class {
10778
10799
  interject: "cut in now with a short correction, the word they are reaching for, or an answer"
10779
10800
  });
10780
10801
  if (!d) return;
10781
- if (!this.partial || words(this.partial) - words(heard) >= this.o.staleWords) return this.o.onDecision({ ...d, acted: "stale" });
10802
+ if (!this.partial || words2(this.partial) - words2(heard) >= this.o.staleWords) return this.o.onDecision({ ...d, acted: "stale" });
10782
10803
  const p = d.probabilities, t = this.o.now();
10783
10804
  if (d.choice === "interject" && p.interject >= this.o.interjectMin && t - this.lastInterjectAt > this.o.interjectGapMs) {
10784
10805
  this.lastInterjectAt = t;
@@ -11272,8 +11293,8 @@ function cleanLine(s, lang, maxWords = 6) {
11272
11293
  const tags = [...first.matchAll(LINE_TAG)].map((m) => `[${m[1].toLowerCase()}]`).filter((t, i, a) => a.indexOf(t) === i).join(" ");
11273
11294
  const raw = first.replace(LINE_TAG, " ").trim();
11274
11295
  if (tags && !/[\p{L}\p{N}]/u.test(raw)) return /laughter|gasp/.test(tags) ? tags : "";
11275
- const words4 = cleanWords(raw, lang, maxWords);
11276
- return words4 && tags ? `${tags} ${words4}` : words4;
11296
+ const words5 = cleanWords(raw, lang, maxWords);
11297
+ return words5 && tags ? `${tags} ${words5}` : words5;
11277
11298
  }
11278
11299
  var LINE_TAG = /\[(laughter|gasp|quiet)\]/gi;
11279
11300
  var lineWords = (line) => line.replace(LINE_TAG, " ").trim();
@@ -11482,10 +11503,7 @@ function endsMidPhrase(text) {
11482
11503
  if (TRAILING_PREPS.has(last)) return !QUESTION_START.test(t) && !PHRASAL_HOST.has(prev);
11483
11504
  return MID_PHRASE_WORDS.has(last);
11484
11505
  }
11485
- var words2 = (s) => s.trim() ? s.trim().split(/\s+/) : [];
11486
- function isClosing(text) {
11487
- return words2(text).length <= 8 && /(?:^|[^\p{L}])(?:good ?bye|bye|see you|good ?night|talk (?:to you )?later|hang up|end (?:the )?call|ביי|להתראות|נתראה|לילה טוב|יאללה ביי)(?:$|[^\p{L}])/iu.test(text);
11488
- }
11506
+ var words3 = (s) => s.trim() ? s.trim().split(/\s+/) : [];
11489
11507
  var TurnGateOptions = class {
11490
11508
  holdMs = 1200;
11491
11509
  /** A finished statement (not a question) waits this long for more speech before it is a turn. 0 = sent at once. */
@@ -11617,7 +11635,7 @@ var TurnGate = class {
11617
11635
  }
11618
11636
  refinal(last, t, key, sttId) {
11619
11637
  if (!last.started) return this.send(t, key, sttId ?? last.sttId, "replace", last.id);
11620
- const a = words2(last.text), b = words2(t);
11638
+ const a = words3(last.text), b = words3(t);
11621
11639
  let i = 0;
11622
11640
  while (i < a.length && i < b.length && norm3(a[i]) === norm3(b[i])) i++;
11623
11641
  const extra = b.slice(i).join(" ");
@@ -11664,8 +11682,8 @@ function isFalseStart(sentence) {
11664
11682
  return !!m && !/^(?:h+m+|u+m+|u+h+|o+h+|a+h+|well|so|er+m*)$/i.test(m[1]);
11665
11683
  }
11666
11684
  function wordOverlap(sentence, prior) {
11667
- const words4 = (x) => x.replace(/\[[^\]]*\]/g, " ").toLowerCase().replace(/['’]/g, "").match(new RegExp("\\p{L}{4,}", "gu")) ?? [];
11668
- const have = new Set(words4(prior)), ws = words4(sentence);
11685
+ const words5 = (x) => x.replace(/\[[^\]]*\]/g, " ").toLowerCase().replace(/['’]/g, "").match(new RegExp("\\p{L}{4,}", "gu")) ?? [];
11686
+ const have = new Set(words5(prior)), ws = words5(sentence);
11669
11687
  return ws.length ? ws.filter((w) => have.has(w)).length / ws.length : 0;
11670
11688
  }
11671
11689
  var DuplexAgentOptions = class {
@@ -14236,8 +14254,8 @@ var ConvoTree = class {
14236
14254
  this.from = heardWords;
14237
14255
  }
14238
14256
  /** Posterior of a node after seeing its cue. */
14239
- confidence(p, words4) {
14240
- const l = p * (words4 > 1 ? this.o.phraseEvidence : this.o.cueEvidence);
14257
+ confidence(p, words5) {
14258
+ const l = p * (words5 > 1 ? this.o.phraseEvidence : this.o.cueEvidence);
14241
14259
  return l / (l + 1 - p);
14242
14260
  }
14243
14261
  /** The partial's newest evidence: the strongest new cue hit (its children open, its siblings fade), or null. A turn_end
@@ -14431,9 +14449,17 @@ var ProgressOptions = class {
14431
14449
  now = () => performance.now();
14432
14450
  };
14433
14451
  function argsHint(args) {
14434
- if (!args || typeof args !== "object") return typeof args === "string" ? args.slice(0, 40) : "";
14435
- const s = Object.values(args).find((v) => typeof v === "string" && v.trim());
14436
- return typeof s === "string" ? s.trim().replace(/\s+/g, " ").slice(0, 40) : "";
14452
+ const s = !args || typeof args !== "object" ? args : Object.values(args).find((v) => typeof v === "string" && v.trim());
14453
+ return typeof s === "string" ? urlWords(s.trim()).replace(/\s+/g, " ").slice(0, 40).trim() : "";
14454
+ }
14455
+ function urlWords(s) {
14456
+ if (!/^https?:\/\/\S+$/i.test(s)) return s;
14457
+ try {
14458
+ const u = new URL(s), host = u.hostname.replace(/^www\./, "").split(".").slice(0, -1).filter((p) => p.length > 2);
14459
+ return [...host, ...decodeURIComponent(u.pathname).split(/[/._-]+/)].filter((w) => new RegExp("\\p{L}{2}", "u").test(w) && !/^(?:html?|php|aspx?|index)$/i.test(w)).join(" ");
14460
+ } catch {
14461
+ return s;
14462
+ }
14437
14463
  }
14438
14464
  var Progress = class {
14439
14465
  constructor(options) {
@@ -14516,13 +14542,17 @@ var Progress = class {
14516
14542
  return null;
14517
14543
  }), late]).finally(() => clearTimeout(t));
14518
14544
  const l = cleanLine(raw ?? "", lang, 5);
14519
- if (!l || about && !echoesHeard(l, hint) || RESULT_CLAIM_RE.test(l) || HE_RESULT_CLAIM.test(l) || this.said.has(norm3(l)) || this.streamed) return "";
14545
+ const why = raw === null ? "late or failed" : !l ? `unusable "${raw}"` : about && !echoesHeard(l, `${hint} ${about}`) ? `names nothing of "${hint}": "${l}"` : RESULT_CLAIM_RE.test(l) || HE_RESULT_CLAIM.test(l) ? `claims a result: "${l}"` : this.said.has(norm3(l)) ? `repeat: "${l}"` : this.streamed ? "reply streamed" : "";
14546
+ if (why) {
14547
+ log29.debug(`no line for ${tool || "(no tool)"}: ${why}`);
14548
+ return "";
14549
+ }
14520
14550
  return l;
14521
14551
  }
14522
14552
  };
14523
14553
  function fastProgressGenerator(ai, model, gender) {
14524
14554
  return async (tool, hint, lang, signal, avoid = []) => {
14525
- 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.`;
14555
+ const prompt = `An assistant on a live voice call is ${tool ? `running the tool "${tool}"` : "working on a request"}${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.`;
14526
14556
  return fastText(ai, { model, prompt, signal });
14527
14557
  };
14528
14558
  }
@@ -14710,10 +14740,10 @@ var SecondChannelOptions = class {
14710
14740
  now = () => performance.now();
14711
14741
  random = Math.random;
14712
14742
  };
14713
- var words3 = (s) => s.trim() ? s.trim().split(/\s+/) : [];
14743
+ var words4 = (s) => s.trim() ? s.trim().split(/\s+/) : [];
14714
14744
  var HESITATION = /^(?:a+y*|a+i|e+[hr]*|erm+|u+[hm]*|h?m+|o+h+|ooh|like|so|well|אה+|אמ+|אה?ם+|ממ+)$/u;
14715
14745
  var onlyHesitation = (s) => {
14716
- const w = words3(s).slice(-3).map((x) => x.toLowerCase().replace(/[^\p{L}]/gu, "")).filter(Boolean);
14746
+ const w = words4(s).slice(-3).map((x) => x.toLowerCase().replace(/[^\p{L}]/gu, "")).filter(Boolean);
14717
14747
  return !!w.length && w.every((x) => HESITATION.test(x));
14718
14748
  };
14719
14749
  function withBudget(p, ms, what, ac) {
@@ -14879,7 +14909,7 @@ var SecondChannel = class {
14879
14909
  if (this.tree.empty && !this.growing && this.growTries < 2) this.requestTree();
14880
14910
  if (!this.tree.empty) {
14881
14911
  this.treeStep(t);
14882
- if (!this.regrown && words3(t).length >= this.o.regrowAtWords) {
14912
+ if (!this.regrown && words4(t).length >= this.o.regrowAtWords) {
14883
14913
  this.regrown = true;
14884
14914
  this.requestTree(t);
14885
14915
  }
@@ -14892,7 +14922,7 @@ var SecondChannel = class {
14892
14922
  }
14893
14923
  }
14894
14924
  if (this.o.anticipate && !this.tree) {
14895
- const n = words3(t).length;
14925
+ const n = words4(t).length;
14896
14926
  if (!this.plan && !this.planning && this.planTries < 2) this.requestPlan();
14897
14927
  else if (this.plan && !this.revised && n >= this.o.reviseAtWords) {
14898
14928
  this.revised = true;
@@ -14905,7 +14935,7 @@ var SecondChannel = class {
14905
14935
  this.bcTimer = null;
14906
14936
  if (this.userSpeaking && this.heard === t) void this.consider("interim", 0, true, cue);
14907
14937
  }, cue ? this.o.cuePauseMs : this.o.backchannelPauseMs) : null;
14908
- if (words3(t).length - this.decidedAt >= this.o.decideEveryWords) void this.consider("interim");
14938
+ if (words4(t).length - this.decidedAt >= this.o.decideEveryWords) void this.consider("interim");
14909
14939
  }
14910
14940
  /** The user went quiet for `ms` (host VAD/STT pause, or the internal interim timer). */
14911
14941
  onPause(ms) {
@@ -15000,7 +15030,7 @@ var SecondChannel = class {
15000
15030
  this.heard = text.trim();
15001
15031
  this.said = (heardCut ?? this.reply).trim();
15002
15032
  this.lastWordAgo = Math.max(0, lastWordAgoMs);
15003
- this.floorWords = this.carried + words3(this.heard).length;
15033
+ this.floorWords = this.carried + words4(this.heard).length;
15004
15034
  this.lastUser = this.heard;
15005
15035
  this.detect(this.heard);
15006
15036
  this.main = "idle";
@@ -15059,7 +15089,7 @@ var SecondChannel = class {
15059
15089
  return this.main === "first_audio" || this.main === "speaking";
15060
15090
  }
15061
15091
  tail() {
15062
- return words3(this.heard).slice(-this.o.microWords).join(" ");
15092
+ return words4(this.heard).slice(-this.o.microWords).join(" ");
15063
15093
  }
15064
15094
  /** Hard gates every line passes, whoever proposed it. */
15065
15095
  allowed(k) {
@@ -15078,7 +15108,7 @@ var SecondChannel = class {
15078
15108
  }
15079
15109
  /** Why this turn gets no bridge by rule ('' = it may) — language, a quick/phatic turn, or blocked(). */
15080
15110
  bridgeBlock() {
15081
- const w = words3(this.heard), intent = turnIntent(this.heard);
15111
+ const w = words4(this.heard), intent = turnIntent(this.heard);
15082
15112
  if (!this.lang) return "language unknown";
15083
15113
  if (this.ownWords) return this.blocked("bridge");
15084
15114
  if (intent === "closer") return "no answer due";
@@ -15101,7 +15131,7 @@ var SecondChannel = class {
15101
15131
  }
15102
15132
  /** 0ms rule: the candidate line for this trigger, or silence. */
15103
15133
  rule(trigger, pauseMs = 0, breath = false, cue = null) {
15104
- const w = words3(this.heard);
15134
+ const w = words4(this.heard);
15105
15135
  if (!this.lang) return "silence";
15106
15136
  if (trigger === "working") return this.bridgeBlock() ? "silence" : "bridge";
15107
15137
  if (w.length <= this.o.shortTurnWords || w.length <= 6 && isPhatic(this.heard, this.bank)) return "silence";
@@ -15116,7 +15146,7 @@ var SecondChannel = class {
15116
15146
  this.planning = true;
15117
15147
  this.planTries++;
15118
15148
  }
15119
- const ctx = { agent: this.reply.trim(), user: words3(this.lastUser).slice(-30).join(" "), recent: [...this.recent], lang: this.lang, heard };
15149
+ const ctx = { agent: this.reply.trim(), user: words4(this.lastUser).slice(-30).join(" "), recent: [...this.recent], lang: this.lang, heard };
15120
15150
  void withBudget(this.o.plan(ctx, ac.signal), this.o.planBudgetMs, heard ? "plan revision" : "plan").then((p) => {
15121
15151
  if (p === null) ac.abort();
15122
15152
  if (turn !== this.turnNo) return;
@@ -15138,7 +15168,7 @@ var SecondChannel = class {
15138
15168
  const ctx = { talk: heard ? [...this.talk, `them (still talking): ${heard.slice(-240)}`] : [...this.talk], lang: detectLanguage(this.talk.join(" ").replace(/\b(them|you):/g, "")) ?? this.lang, recent: this.leaves.slice(-this.o.leafMemory), ...this.o.persona ? { persona: this.o.persona } : {} };
15139
15169
  const late = setTimeout(() => ac.abort(), this.o.growBudgetMs);
15140
15170
  void this.o.grow(ctx, ac.signal).then((r) => {
15141
- if (r.nodes.length) tree.grow(r.nodes, this.userSpeaking ? words3(this.heard).length : 0);
15171
+ if (r.nodes.length) tree.grow(r.nodes, this.userSpeaking ? words4(this.heard).length : 0);
15142
15172
  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 } : {} });
15143
15173
  }, (e) => {
15144
15174
  log30.warn(`tree failed: ${e?.message ?? e}`);
@@ -15154,10 +15184,10 @@ var SecondChannel = class {
15154
15184
  if (!hit) return;
15155
15185
  if (hit.node.moment === "barge_in") return this.playLeaf(hit, "interim", "backchannel");
15156
15186
  if (this.leafTimer) clearTimeout(this.leafTimer);
15157
- const at = words3(t).length;
15187
+ const at = words4(t).length;
15158
15188
  this.leafTimer = setTimeout(() => {
15159
15189
  this.leafTimer = null;
15160
- if (this.userSpeaking && words3(this.heard).length - at < this.o.leafStaleWords) this.playLeaf(hit, "interim", "backchannel");
15190
+ if (this.userSpeaking && words4(this.heard).length - at < this.o.leafStaleWords) this.playLeaf(hit, "interim", "backchannel");
15161
15191
  }, this.o.cuePauseMs);
15162
15192
  }
15163
15193
  /** A breath with no cue hit: the quick model may name the leaf that fits the words just said. Its answer plays only if
@@ -15167,14 +15197,14 @@ var SecondChannel = class {
15167
15197
  if (!this.o.pickLeaf || !this.o.aec) return;
15168
15198
  this.breathTimer = setTimeout(() => {
15169
15199
  this.breathTimer = null;
15170
- const n = words3(t).length, tree = this.tree;
15200
+ const n = words4(t).length, tree = this.tree;
15171
15201
  if (!this.backchannelMoment(n, true) || this.heard !== t || this.leafTimer || this.picking || tree.empty || this.leafGated()) return;
15172
15202
  this.picking = true;
15173
15203
  const ac = new AbortController(), nodes = tree.nodes.filter((x) => x.moment !== "ask"), lines = nodes.map((x, i) => ({ i, line: x.line, when: x.when }));
15174
15204
  void withBudget(this.o.pickLeaf(t, lines, ac.signal), this.o.pickBudgetMs, "breath pick", ac).then((i) => {
15175
15205
  this.picking = false;
15176
15206
  const node = typeof i === "number" ? nodes[i] : void 0, hit = node && tree.nodes.includes(node) ? tree.picked(tree.nodes.indexOf(node), this.heard) : null;
15177
- if (!hit || !this.userSpeaking || words3(this.heard).length - n >= this.o.leafStaleWords) return;
15207
+ if (!hit || !this.userSpeaking || words4(this.heard).length - n >= this.o.leafStaleWords) return;
15178
15208
  tree.take(hit.node, hit.conf);
15179
15209
  this.playLeaf(hit, "interim", "backchannel");
15180
15210
  });
@@ -15244,7 +15274,7 @@ var SecondChannel = class {
15244
15274
  if (trigger === "working") this.o.onEvent({ trigger, rule: "silence", ms: 0, acted: "silence", reason: "deciding another line" });
15245
15275
  return;
15246
15276
  }
15247
- const n0 = words3(this.heard).length;
15277
+ const n0 = words4(this.heard).length;
15248
15278
  this.decidedAt = n0;
15249
15279
  if (!(this.o.anticipate && this.plan && trigger === "interim")) cue = null;
15250
15280
  const opts = this.options;
@@ -15260,7 +15290,7 @@ var SecondChannel = class {
15260
15290
  this.busy = true;
15261
15291
  const gen = this.gen, t0 = this.o.now();
15262
15292
  const ev = (e) => this.o.onEvent({ trigger, rule, ms: Math.round(this.o.now() - t0), ...cue ? { cue: cue.line } : {}, ...e });
15263
- const stale = () => gen !== this.gen || words3(this.heard).length - n0 >= this.o.staleWords;
15293
+ const stale = () => gen !== this.gen || words4(this.heard).length - n0 >= this.o.staleWords;
15264
15294
  try {
15265
15295
  let kind = rule;
15266
15296
  let choice;
@@ -15280,7 +15310,7 @@ var SecondChannel = class {
15280
15310
  if (stale()) return ev({ choice, kind, text, acted: "stale" });
15281
15311
  if (!this.allowed(kind)) return ev({ choice, kind, text, acted: "gated" });
15282
15312
  const said = this.say(kind, text);
15283
- if (said && cue) this.cueFrom = words3(this.heard).length;
15313
+ if (said && cue) this.cueFrom = words4(this.heard).length;
15284
15314
  if (said && kind === "backchannel" && this.o.reactionGapMs && !this.bank?.backchannel.some((b) => norm3(b) === norm3(text))) this.lastReactAt = this.o.now();
15285
15315
  ev({ choice, kind, text, acted: said ? "spoken" : "skipped" });
15286
15316
  } finally {
@@ -15306,7 +15336,7 @@ var SecondChannel = class {
15306
15336
  this.noLine = "";
15307
15337
  if (!this.o.generate || !(this.ownWords || this.o.generateFor.includes("bridge")) || !this.lang || !this.heard) return;
15308
15338
  const gen = this.gen, ac = new AbortController(), own = this.ownWords;
15309
- const said = own ? words3(this.said.replace(/\[[^\]]*\]/g, " ")).slice(-this.o.microWords).join(" ") : "", heard = `${this.heard} ${said}`;
15339
+ const said = own ? words4(this.said.replace(/\[[^\]]*\]/g, " ")).slice(-this.o.microWords).join(" ") : "", heard = `${this.heard} ${said}`;
15310
15340
  const ctx = { kind: "bridge", heard: this.tail(), state: this.main, avoid: [...this.recent], lang: this.lang, ...own ? { ask: true } : {}, ...said ? { said, cut: this.barged } : {} };
15311
15341
  log30.debug(`bridge ctx: said=${JSON.stringify(ctx.said ?? "")} cut=${!!ctx.cut}`);
15312
15342
  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) => {
@@ -15374,8 +15404,8 @@ var SecondChannel = class {
15374
15404
  if (kind === "bridge") this.bridged = true;
15375
15405
  this.recent = [...this.recent, text].slice(-this.o.avoidLines);
15376
15406
  this.live = lineWords(text);
15377
- const words4 = this.live;
15378
- if (words4) this.o.show(words4, kind);
15407
+ const words5 = this.live;
15408
+ if (words5) this.o.show(words5, kind);
15379
15409
  const p = Promise.resolve(r).then(() => {
15380
15410
  }, (e) => {
15381
15411
  log30.warn(`channel line playback failed: ${e?.message ?? e}`);
@@ -15478,6 +15508,9 @@ var VoiceCallOptions = class {
15478
15508
  /** Live: the quick lane (fastQuickLane) owns the conversation — each turn it answers, acks + hands to MAIN, resumes a
15479
15509
  * cut answer, or stays quiet. Absent (or another mode): every turn goes to MAIN as before. */
15480
15510
  quick;
15511
+ /** The quick lane said a farewell to someone ending the call (QuickMove `end`): the host hangs up once that line has
15512
+ * played (as Para's [[hangup]] marker does for MAIN). The call takes no more turns after it. */
15513
+ hangUp;
15481
15514
  /** Past this the turn goes to MAIN as before (the bridge covers it). */
15482
15515
  quickBudgetMs = 1800;
15483
15516
  /** The unsaid rest of MAIN's reply a barge just cut (a peek, like heardCut), else null — what a resume says. */
@@ -15489,6 +15522,9 @@ var VoiceCallOptions = class {
15489
15522
  /** Stop the in-flight fill line now (barge-in only). */
15490
15523
  cancel = () => {
15491
15524
  };
15525
+ /** Cut whatever the host is playing now (MAIN's reply draining): a farewell is said over nothing, then the call hangs up. */
15526
+ cutAudio = () => {
15527
+ };
15492
15528
  /** Host caption — never history. */
15493
15529
  show = () => {
15494
15530
  };
@@ -15563,7 +15599,9 @@ var VoiceCall = class {
15563
15599
  cancel: () => o.cancel(),
15564
15600
  now: o.now
15565
15601
  });
15566
- this.progress = new Progress({ ...o.mode === "live" ? { templates: {}, generateBudgetMs: 1500, gapMs: 5e3 } : {}, ...ai ? { generate: fastProgressGenerator(ai, o.fastModel, o.gender) } : {}, gender: o.gender, now: o.now, ...o.progress });
15602
+ const po = { ...o.mode === "live" ? { templates: {}, generateBudgetMs: 1500, gapMs: 5e3 } : {}, ...ai ? { generate: fastProgressGenerator(ai, o.fastModel, o.gender) } : {}, gender: o.gender, now: o.now, ...o.progress };
15603
+ if (o.mode === "live") po.stageRepeatMs ??= po.gapMs;
15604
+ this.progress = new Progress(po);
15567
15605
  this.judge = new OverlapJudge({ ...ai ? { model: overlapModelFor(ai) } : {}, now: o.now });
15568
15606
  this.gate = new TurnGate({
15569
15607
  now: o.now,
@@ -15954,8 +15992,15 @@ var VoiceCall = class {
15954
15992
  }
15955
15993
  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;
15956
15994
  this.gate.replyStarted(c.id);
15957
- if (!await this.sayRetry(said, "reply", c.id)) return this.close(c, "silent");
15958
- this.o.show(said, "reply");
15995
+ const end = mv.kind === "say" && !!mv.end;
15996
+ if (end) try {
15997
+ this.o.cutAudio();
15998
+ } catch (e) {
15999
+ log31.warn(`cutAudio threw: ${e.message}`);
16000
+ }
16001
+ const played = await this.sayRetry(said, "reply", c.id, end ? 240 : 8);
16002
+ if (!played && !end) return this.close(c, "silent");
16003
+ if (played) this.o.show(said, "reply");
15959
16004
  if (mv.kind === "resume") {
15960
16005
  this.cutRest = "";
15961
16006
  this.o.dropCut?.();
@@ -15965,6 +16010,17 @@ var VoiceCall = class {
15965
16010
  this.history.push({ who: "you", text: said });
15966
16011
  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.`);
15967
16012
  }
16013
+ if (end) {
16014
+ this.o.onMetric({ name: "hangup", id: c.id, text: said });
16015
+ if (played && (!this.o.hostAudio || c.worded)) this.quickWorded(c, this.lastAudibleAt);
16016
+ this.end();
16017
+ try {
16018
+ this.o.hangUp?.();
16019
+ } catch (e) {
16020
+ log31.warn(`hangUp threw: ${e.message}`);
16021
+ }
16022
+ return;
16023
+ }
15968
16024
  if (this.o.hostAudio && !c.worded) {
15969
16025
  c.quickWord = true;
15970
16026
  return;
@@ -15981,9 +16037,9 @@ var VoiceCall = class {
15981
16037
  }
15982
16038
  this.close(c, "answered");
15983
16039
  }
15984
- /** say(), retried while the host's player is busy (up to 2s). */
15985
- async sayRetry(line, kind, id) {
15986
- for (let i = 0; i < 8; i++) {
16040
+ /** say(), retried while the host's player is busy (`tries` × 250ms: 2s). */
16041
+ async sayRetry(line, kind, id, tries = 8) {
16042
+ for (let i = 0; i < tries; i++) {
15987
16043
  if (this.ended) return false;
15988
16044
  if (this.say(line, kind) !== false) return true;
15989
16045
  await new Promise((r) => setTimeout(r, 250));
@@ -17550,8 +17606,8 @@ var CutInAbsorber = class {
17550
17606
  const cut = this.cut || (meta?.supersedes !== void 0 && meta.supersedes === this.absorbed?.text ? this.absorbed.cut : "");
17551
17607
  this.cut = "";
17552
17608
  this.absorbed = void 0;
17553
- const words4 = (s) => s.trim().split(/\s+/).filter(Boolean).length;
17554
- if (!cut || words4(text) - words4(cut) >= 3) return false;
17609
+ const words5 = (s) => s.trim().split(/\s+/).filter(Boolean).length;
17610
+ if (!cut || words5(text) - words5(cut) >= 3) return false;
17555
17611
  this.absorbed = { text, cut };
17556
17612
  return true;
17557
17613
  }
@@ -17735,6 +17791,9 @@ function bindVoiceCall(v, call, live, decideMs = 900) {
17735
17791
  };
17736
17792
  call.options.cancel = () => {
17737
17793
  };
17794
+ call.options.cutAudio = () => {
17795
+ if (v.audible) v.interrupt();
17796
+ };
17738
17797
  }
17739
17798
  function keepHeard(transcript, cut) {
17740
17799
  const full = cut.full.trim(), heard = cut.heard.trim();
@@ -17905,10 +17964,12 @@ function fakeVoiceParts(uttFile) {
17905
17964
  function fakeTape(heardFile, saidFile) {
17906
17965
  const CHAR = TTS_SAMPLE_RATE * 2 / 15;
17907
17966
  const makeTts = () => {
17967
+ let at = 0;
17908
17968
  const t = {
17909
17969
  connect() {
17910
17970
  },
17911
17971
  newContext() {
17972
+ at = 0;
17912
17973
  },
17913
17974
  cancel() {
17914
17975
  },
@@ -17920,6 +17981,13 @@ function fakeTape(heardFile, saidFile) {
17920
17981
  },
17921
17982
  speak(text, more = true) {
17922
17983
  if (saidFile) appendFileSync(saidFile, JSON.stringify({ t: Date.now(), speak: text }) + "\n");
17984
+ const words5 = [], start = [];
17985
+ for (const m of text.matchAll(/\S+/g)) {
17986
+ words5.push(m[0]);
17987
+ start.push((at + m.index) / 15);
17988
+ }
17989
+ at += text.length;
17990
+ if (t.wantTimestamps && words5.length) setTimeout(() => t.onTimestamps?.(words5, start), 5);
17923
17991
  const pcm = new Uint8Array(text.length * CHAR), v = new DataView(pcm.buffer);
17924
17992
  for (let i = 0; i < text.length; i++) for (let b = 0; b < CHAR; b += 2) v.setUint16(i * CHAR + b, text.charCodeAt(i), true);
17925
17993
  setTimeout(() => {
@@ -18042,6 +18110,35 @@ var JsonlDiagSink = class {
18042
18110
 
18043
18111
  // src/voice/spokenFilter.ts
18044
18112
  var SPOKEN_TURN = `Your reply is spoken aloud: answer in one to three short plain sentences \u2014 no markdown, headings, lists, links or code, and no sources line even when a tool asks you to cite them (offer to send them if asked) \u2014 and offer more detail only if asked. Say only facts from this turn's tool results or this call, and keep a list in its source's order: "top" or "first" is its rank 1.`;
18113
+ var HANGUP = "[[hangup]]";
18114
+ var CALL_HANGUP = `When the user means to end the call \u2014 in any words or language: a goodbye ("okay, bye", "talk later"), or that they're done ("that's all, thanks") \u2014 say one short farewell and finish that reply with ${HANGUP}: the call hangs up once it has played. Judge the intent, not the word: "say bye to Dan" or "before I go, one more thing" keep the call. Never write ${HANGUP} otherwise.`;
18115
+ function markerStrip(marker) {
18116
+ let held2 = "", hit = false;
18117
+ return {
18118
+ get hit() {
18119
+ return hit;
18120
+ },
18121
+ push(t) {
18122
+ let s = held2 + t;
18123
+ held2 = "";
18124
+ for (let i; (i = s.indexOf(marker)) >= 0; ) {
18125
+ hit = true;
18126
+ s = s.slice(0, i) + s.slice(i + marker.length);
18127
+ }
18128
+ for (let k = Math.min(marker.length - 1, s.length); k > 0; k--) if (marker.startsWith(s.slice(-k))) {
18129
+ held2 = s.slice(-k);
18130
+ s = s.slice(0, -k);
18131
+ break;
18132
+ }
18133
+ return s;
18134
+ },
18135
+ flush() {
18136
+ const s = held2;
18137
+ held2 = "";
18138
+ return s;
18139
+ }
18140
+ };
18141
+ }
18045
18142
  var HEADS = ["sources", "source", "references", "citations", "links"];
18046
18143
  var MARKS = String.raw`[#*_>\s-]*`;
18047
18144
  var SOURCES = new RegExp(String.raw`(^|\n|[.!?…]\s)${MARKS}(?:${HEADS.join("|")})${MARKS}[::]`, "i");
@@ -18130,16 +18227,16 @@ init_logging();
18130
18227
  var log39 = forComponent("QuickLane");
18131
18228
  var SAY_WORDS = 30;
18132
18229
  var ACK_WORDS = 10;
18133
- var ACKS = { en: ["On it.", "Sure, one sec.", "Okay, looking.", "Got it, checking."], he: ["\u05E8\u05D2\u05E2 \u05D0\u05D7\u05D3.", "\u05D0\u05D5\u05E7\u05D9\u05D9, \u05E9\u05E0\u05D9\u05D9\u05D4.", "\u05E9\u05E0\u05D9\u05D9\u05D4."] };
18230
+ 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."] };
18134
18231
  function quickMove(raw, c) {
18135
18232
  const mv = rawMove(raw, c), owns = quickOwns(c.heard);
18136
18233
  if (owns === "reaction" && (!mv || mv.kind === "deep")) {
18137
18234
  const l = ownLine(ASIDES[c.lang]?.react, c);
18138
18235
  return l ? { kind: "say", line: l } : { kind: "quiet" };
18139
18236
  }
18140
- if (isClosing(c.heard) && (!mv || mv.kind !== "say")) {
18237
+ if (isClosing(c.heard) && (!mv || mv.kind === "quiet")) {
18141
18238
  const l = ownLine(BYES[c.lang], c);
18142
- return l ? { kind: "say", line: l } : mv;
18239
+ return l ? { kind: "say", line: l, end: true } : mv;
18143
18240
  }
18144
18241
  return mv;
18145
18242
  }
@@ -18149,9 +18246,9 @@ var ownLine = (pool, c) => {
18149
18246
  return (pool ?? []).find((x) => !said.has(norm3(x))) ?? "";
18150
18247
  };
18151
18248
  function rawMove(raw, c) {
18152
- const m = /^\s*(SAY|DEEP|RESUME|QUIET)\b\s*:?\s*(.*)$/im.exec(raw.trim());
18249
+ const m = /^\s*(SAY|BYE|DEEP|RESUME|QUIET)\b\s*:?\s*(.*)$/im.exec(raw.trim());
18153
18250
  if (!m) return null;
18154
- const kind = m[1].toUpperCase(), body = m[2].trim();
18251
+ const bye = m[1].toUpperCase() === "BYE", kind = bye ? "SAY" : m[1].toUpperCase(), body = m[2].trim();
18155
18252
  const owns = quickOwns(c.heard);
18156
18253
  if (!owns && kind !== "DEEP") return { kind: "deep", ack: stockAck(c), brief: "" };
18157
18254
  if (kind === "QUIET") return { kind: "quiet" };
@@ -18161,22 +18258,22 @@ function rawMove(raw, c) {
18161
18258
  }
18162
18259
  if (kind === "DEEP") {
18163
18260
  const [ack = "", brief = ""] = body.split(body.includes("|") ? "|" : /\s+[—–-]\s+/).map((s) => s.trim());
18164
- const a = cleanLine(ack, c.lang, ACK_WORDS);
18261
+ const a = cleanLine(ack, c.lang, ACK_WORDS).replace(/[\s,;:—–-]+$/u, "");
18165
18262
  const said = new Set(c.history.filter((h) => h.who === "you").map((h) => norm3(h.text)));
18166
18263
  const ok = a && !said.has(norm3(a)) && !RESULT_CLAIM_RE.test(a) && !new RegExp("\\p{N}", "u").test(a);
18167
18264
  return { kind: "deep", ack: ok ? a : stockAck(c), brief };
18168
18265
  }
18169
18266
  const line = sayLine(body, c.lang);
18170
18267
  if (!line) return null;
18171
- if (parrots(line, c.heard)) return { kind: "quiet" };
18172
- if (c.history.some((h) => h.who === "you" && norm3(h.text) === norm3(line))) return { kind: "quiet" };
18268
+ if (!bye && parrots(line, c.heard)) return { kind: "quiet" };
18269
+ if (!bye && c.history.some((h) => h.who === "you" && norm3(h.text) === norm3(line))) return { kind: "quiet" };
18173
18270
  const facts = unknownFacts(line, c), novel = novelWords(line, c);
18174
18271
  const unknown = facts.length || novel.length >= 2 ? [...facts, ...novel] : [];
18175
18272
  if (unknown.length) {
18176
18273
  log39.debug(`quick line "${line}" names ${unknown.join(", ")} \u2014 not in the call: deep lane`);
18177
18274
  return { kind: "deep", ack: "", brief: "" };
18178
18275
  }
18179
- return { kind: "say", line };
18276
+ return bye && isClosing(c.heard) ? { kind: "say", line, end: true } : { kind: "say", line };
18180
18277
  }
18181
18278
  var stockAck = (c) => ownLine(ACKS[c.lang], c);
18182
18279
  function quickOwns(heard) {
@@ -18271,8 +18368,9 @@ They just said: "${c.heard}"
18271
18368
  ` + (c.rest ? `Your last answer was cut. Its unsaid rest: "${c.rest.slice(0, 300)}"
18272
18369
  ` : "") + `
18273
18370
  Reply with exactly ONE line, one of:
18274
- SAY: <your words> \u2014 ONLY a greeting or how-are-you, a short reaction ("wow", "really?"), a goodbye, 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.
18275
- 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 says you're on it ("Sure, checking Hacker News.") and never a result. The speech-to-text misspells names: fix them from context ("Haka News" \u2192 Hacker News).
18371
+ 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.
18372
+ 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.
18373
+ 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: a lookup says you're on it and names what you'll look at ("Sure, let me pull up the kitty changelog."); 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).
18276
18374
  QUIET \u2014 nothing is owed: a bare "okay", "mm-hm", or a reaction you already answered.
18277
18375
  "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.
18278
18376
  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.`;
@@ -23299,12 +23397,25 @@ async function repl(args, ai, cfg, cwd) {
23299
23397
  let callFastModel = "";
23300
23398
  let callReplyOpen = false;
23301
23399
  let spoken = new SpokenFilter();
23400
+ let hang = markerStrip(HANGUP);
23401
+ const hangUpCall = () => {
23402
+ voiceDiag?.push({ t: performance.now(), kind: "call_hangup" });
23403
+ call?.end();
23404
+ void (async () => {
23405
+ for (let i = 0; i < 60 && voiceIO; i++) {
23406
+ await voiceIO.awaitIdle();
23407
+ await new Promise((r) => setTimeout(r, 500));
23408
+ if (!voiceIO?.audible && !(voiceIO?.player?.drainMs() ?? 0)) break;
23409
+ }
23410
+ editorRef?.abort();
23411
+ })();
23412
+ };
23302
23413
  let greetNote = "";
23303
23414
  const callTurns = /* @__PURE__ */ new Map();
23304
23415
  const callTools = /* @__PURE__ */ new Set();
23305
23416
  if (args.call) {
23306
23417
  if (args.voice || args.voicePersona) agent.options.systemPrompt += "\n\n" + (args.voicePersona ?? CALL_PROMPT);
23307
- agent.options.systemPrompt += "\n\n" + CALL_WEB_PROMPT;
23418
+ agent.options.systemPrompt += "\n\n" + CALL_WEB_PROMPT + "\n\n" + CALL_HANGUP;
23308
23419
  if (args.voiceSystemPrompt) agent.options.systemPrompt += "\n\n" + args.voiceSystemPrompt;
23309
23420
  const fast = callFast(args, ai, cfg);
23310
23421
  for (const n of fast.notes) err(yellow(` \u26A0 ${n}
@@ -23316,6 +23427,8 @@ async function repl(args, ai, cfg, cwd) {
23316
23427
  // live: the quick lane owns the conversation, MAIN is its deep lane (#1331). Only here: its lines reach MAIN through
23317
23428
  // noteTurn, which a --channel-only host (Para) does not take yet.
23318
23429
  ...args.channelMode === "live" && process.env.AGENTX_QUICK_LANE !== "0" ? { quick: fastQuickLane(ai, fast.options.fastModel, args.voiceGender, args.voicePersona) } : {},
23430
+ // the quick lane's farewell to a goodbye ends the call, as an ExitSession 'quit' does: the line plays out, then exit
23431
+ hangUp: hangUpCall,
23319
23432
  show: (t, kind) => {
23320
23433
  err("\r\x1B[0J" + dim(` \u21B3 ${kind === "progress" ? "\u22EF " : ""}${t}
23321
23434
  `));
@@ -23362,6 +23475,7 @@ ${note}`;
23362
23475
  greetNote = "";
23363
23476
  callReplyOpen = false;
23364
23477
  spoken = new SpokenFilter();
23478
+ hang = markerStrip(HANGUP);
23365
23479
  try {
23366
23480
  const r = await dispatchLine(`${text}${note}
23367
23481
 
@@ -23376,14 +23490,18 @@ ${SPOKEN_TURN}`, { id });
23376
23490
  rec.running = false;
23377
23491
  call?.main({ type: "done", id });
23378
23492
  editorRef?.redrawNow();
23493
+ if (hang.hit) hangUpCall();
23379
23494
  }
23380
23495
  });
23381
23496
  }
23382
23497
  });
23383
23498
  const host = agent.options.host, notify = host.notify.bind(host);
23384
23499
  host.notify = (e) => {
23385
- if (e.kind === "text_delta" && typeof e.message === "string") call.main({ type: "text", text: e.message });
23386
- else if (e.kind === "tool_use") call.main({ type: "tool", name: String(e.name ?? ""), args: e.input });
23500
+ if (e.kind === "text_delta" && typeof e.message === "string") {
23501
+ e = { ...e, message: hang.push(e.message) };
23502
+ if (!e.message) return;
23503
+ call.main({ type: "text", text: e.message });
23504
+ } else if (e.kind === "tool_use") call.main({ type: "tool", name: String(e.name ?? ""), args: e.input });
23387
23505
  else if (e.kind === "tool_result") call.main({ type: "tool_done" });
23388
23506
  else if (e.kind === "tool_activity") {
23389
23507
  if (!callTools.has(e.id)) {
@@ -25676,7 +25794,9 @@ async function channelServe(args, ai, cfg) {
25676
25794
  out({ type: "resumed" });
25677
25795
  },
25678
25796
  // the rest was said: the host's cut note no longer holds
25679
- userLine: (text, how) => out({ type: "user_line", text, how })
25797
+ userLine: (text, how) => out({ type: "user_line", text, how }),
25798
+ hangUp: () => out({ type: "hangup" })
25799
+ // the farewell went out as a {type:'channel', kind:'reply'}: end the call once it played
25680
25800
  } : {},
25681
25801
  channel: { ...fast.channel, onTree: (e) => out({ type: "metric", name: "tree", ms: e.ms, kind: `${e.tokens ? `${e.tokens.input}/${e.tokens.output} tok ` : ""}${e.error ?? (e.lines ?? []).join(" | ")}` }), onLeaf: (e) => out({ type: "metric", name: "leaf", ms: e.ms, kind: `${e.moment} ${e.conf} ${e.acted}`, text: e.text }) },
25682
25802
  speak: (line, kind) => {