@livx.cc/agentx 0.99.152 → 0.99.154

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/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { c as AgentOptions, H as Hooks, x as RunResult, k as Decider, b as Agent, q as PermissionPolicy, G as Gender, L as LineKind, d as ChannelMode, y as SecondChannelOptions, S as SecondChannel } from './secondChannel-BVmp2lze.js';
2
- export { A as ADVISE_LIMIT, a as AdvisorSetup, C as CC_WRITE_TOOLS, e as ChatFragment, f as ChatUsage, g as Classification, h as Classifier, i as CompactResult, j as ContextFileSpec, D as DEFAULT_MUTATING, l as Decision, M as ModelRouter, m as ModelRouterOptions, P as PLANNER_BLOCKED, n as PLANNER_REFUSAL, o as PLAN_FIRST, p as PermissionOptions, r as PermissionRule, s as PreToolUseDecision, R as ReasoningEffort, t as RecordingHooks, u as RecordingLifecycle, v as RouteDecision, w as RouterState, T as Tier, z as ToolUse, B as ToolUseMeta, W as WRITE_TOOLS, E as advisorFor, F as advisorPrompt, I as ccModeOptions, J as claudeCodeDisallowedTools, K as composeHooks, N as delegatePrompt, O as delegateTools, Q as delegateWorkerFor, U as estimateTokens, V as jevAvailable, X as jevClassifier, Y as loadContextFiles, Z as loadInstructions, _ as makeAdvisor, $ as meterWorkers, a0 as pickTier, a1 as planMode, a2 as plannerBlocks, a3 as reasoningToChatFragment } from './secondChannel-BVmp2lze.js';
1
+ import { c as AgentOptions, H as Hooks, x as RunResult, k as Decider, b as Agent, q as PermissionPolicy, G as Gender, L as LineKind, d as ChannelMode, y as SecondChannelOptions, S as SecondChannel } from './secondChannel-CR3xWWB_.js';
2
+ export { A as ADVISE_LIMIT, a as AdvisorSetup, C as CC_WRITE_TOOLS, e as ChatFragment, f as ChatUsage, g as Classification, h as Classifier, i as CompactResult, j as ContextFileSpec, D as DEFAULT_MUTATING, l as Decision, M as ModelRouter, m as ModelRouterOptions, P as PLANNER_BLOCKED, n as PLANNER_REFUSAL, o as PLAN_FIRST, p as PermissionOptions, r as PermissionRule, s as PreToolUseDecision, R as ReasoningEffort, t as RecordingHooks, u as RecordingLifecycle, v as RouteDecision, w as RouterState, T as Tier, z as ToolUse, B as ToolUseMeta, W as WRITE_TOOLS, E as advisorFor, F as advisorPrompt, I as ccModeOptions, J as claudeCodeDisallowedTools, K as composeHooks, N as delegatePrompt, O as delegateTools, Q as delegateWorkerFor, U as estimateTokens, V as jevAvailable, X as jevClassifier, Y as loadContextFiles, Z as loadInstructions, _ as makeAdvisor, $ as meterWorkers, a0 as pickTier, a1 as planMode, a2 as plannerBlocks, a3 as reasoningToChatFragment } from './secondChannel-CR3xWWB_.js';
3
3
  export { MODEL_ALIASES, ModelSwitch, ResolveModelSwitchOpts, latestClaude, modelShortLabel, resolveModelAlias, resolveModelSwitch } from './models.js';
4
4
  import { IFilesystem, FileMetadata } from '@livx.cc/wcli/core';
5
5
  export { CommandExecutor, FileMetadata, IFilesystem, IndexedDbFilesystem, MemFilesystem, registerHeadlessCommands } from '@livx.cc/wcli/core';
@@ -1676,6 +1676,44 @@ declare function makeTaskBatchTool(opts: TaskToolOptions): AgentTool;
1676
1676
  /** Component-scoped logger (libx.js). debug/verbose gated via DEBUG env/localStorage. */
1677
1677
  declare const forComponent: (name: string) => libx_js_src_modules_log.ComponentLogger;
1678
1678
 
1679
+ /**
1680
+ * The quick lane of a live call (#1331): a fast model that OWNS the conversation. Each user turn it either answers
1681
+ * itself (chit-chat, a reaction, a clarification, restating something already said), acknowledges and hands the turn
1682
+ * to the deep lane (MAIN: tools, facts it can't know, real thinking), resumes an answer the user cut, or stays quiet.
1683
+ * It knows only the call's shared history — what the user said and what was said aloud by either lane — so a fact
1684
+ * comes only from the deep lane or from what was already said; `quickMove` enforces it (a line that names a number or
1685
+ * a name the call never held goes to the deep lane instead).
1686
+ */
1687
+
1688
+ interface LaneLine {
1689
+ who: 'user' | 'you';
1690
+ text: string;
1691
+ cut?: boolean;
1692
+ }
1693
+ interface QuickContext {
1694
+ /** The call so far, oldest first (the turn being decided is `heard`, not in here). */
1695
+ history: LaneLine[];
1696
+ /** The user's turn, verbatim from the STT. */
1697
+ heard: string;
1698
+ lang: string;
1699
+ /** The unsaid rest of an answer the user just cut ('' = none). */
1700
+ rest?: string;
1701
+ }
1702
+ type QuickMove = {
1703
+ kind: 'say';
1704
+ line: string;
1705
+ } | {
1706
+ kind: 'deep';
1707
+ ack: string;
1708
+ brief: string;
1709
+ } | {
1710
+ kind: 'resume';
1711
+ line: string;
1712
+ } | {
1713
+ kind: 'quiet';
1714
+ };
1715
+ type QuickDecider = (c: QuickContext, signal: AbortSignal) => Promise<QuickMove | null>;
1716
+
1679
1717
  type Topic = 'board' | 'websearch' | 'page' | 'browser' | 'search' | 'mail' | 'calendar' | 'memory' | 'write' | 'run' | 'read' | 'delegate';
1680
1718
  /** Two phrasings per topic and language (never the same line twice in a call). Hebrew is gendered on the speaker:
1681
1719
  * 'he-f' / 'he-m' follow the voice (ProgressOptions.gender); 'he' (plural present) when the gender is unknown. */
@@ -1736,7 +1774,8 @@ interface WorkContext {
1736
1774
  /** The spoken answer. `stop:` opens it when they called the work off, `work:` when they change or add to it. '' = silence. */
1737
1775
  type WorkReply = (c: WorkContext, signal: AbortSignal) => Promise<string>;
1738
1776
 
1739
- type FillKind = LineKind | 'progress' | 'aside';
1777
+ /** 'ack'/'reply': the quick lane's own words (live with `quick`) — an acknowledgement before the deep lane, or its answer. */
1778
+ type FillKind = LineKind | 'progress' | 'aside' | 'ack' | 'reply';
1740
1779
  /** MAIN's stream as the host forwards it. `id` = the turn (sendTurn's id); absent → the current turn. */
1741
1780
  interface MainEvent {
1742
1781
  type: 'start' | 'text' | 'tool' | 'tool_done' | 'audio' | 'done' | 'error';
@@ -1771,11 +1810,11 @@ interface TurnTimeline {
1771
1810
  end?: 'answered' | 'cut' | 'replaced' | 'silent';
1772
1811
  }
1773
1812
  interface CallMetric {
1774
- name: 'first_sound' | 'first_word' | 'turn' | 'drop' | 'hold' | 'fill' | 'lang' | 'timeline';
1813
+ name: 'first_sound' | 'first_word' | 'turn' | 'drop' | 'hold' | 'fill' | 'lang' | 'timeline' | 'lane';
1775
1814
  id?: string;
1776
1815
  /** ms from the user's last word (see TurnTimeline) */
1777
1816
  ms?: number;
1778
- by?: 'fill' | 'progress' | 'main';
1817
+ by?: 'fill' | 'progress' | 'main' | 'quick';
1779
1818
  kind?: string;
1780
1819
  text?: string;
1781
1820
  lang?: string | null;
@@ -1795,9 +1834,21 @@ declare class VoiceCallOptions {
1795
1834
  * runs as MAIN's next turn. Not injected mid-run: that makes MAIN run again just to hear a remark. Absent: such a line
1796
1835
  * barges in as before. */
1797
1836
  noteTurn?: (note: string) => void;
1837
+ /** What the user HEARD of MAIN's reply a barge just cut (a peek — the host still takes the cut for MAIN), else null:
1838
+ * a live bridge echoes what their "that" points at. */
1839
+ heardCut?: () => string | null;
1798
1840
  /** Writes that immediate answer (fastWorkReply). */
1799
1841
  workReply?: WorkReply;
1800
1842
  workReplyBudgetMs: number;
1843
+ /** Live: the quick lane (fastQuickLane) owns the conversation — each turn it answers, acks + hands to MAIN, resumes a
1844
+ * cut answer, or stays quiet. Absent (or another mode): every turn goes to MAIN as before. */
1845
+ quick?: QuickDecider;
1846
+ /** Past this the turn goes to MAIN as before (the bridge covers it). */
1847
+ quickBudgetMs: number;
1848
+ /** The unsaid rest of MAIN's reply a barge just cut (a peek, like heardCut), else null — what a resume says. */
1849
+ cutRest?: () => string | null;
1850
+ /** A resume said that rest: the host drops the cut (MAIN's history keeps the whole reply). */
1851
+ dropCut?: () => void;
1801
1852
  /** Host TTS (fill lane): resolves when played; `false` = could not play. */
1802
1853
  speak: (text: string, kind: FillKind) => Promise<unknown> | boolean;
1803
1854
  /** Stop the in-flight fill line now (barge-in only). */
@@ -1851,6 +1902,10 @@ declare class VoiceCall {
1851
1902
  private progressTimer;
1852
1903
  private lastUserAt;
1853
1904
  private ended;
1905
+ /** The call as both lanes know it: the user's turns and what was said aloud (quick lines, MAIN's heard replies). */
1906
+ readonly history: LaneLine[];
1907
+ private cutRest;
1908
+ private cutTurn?;
1854
1909
  constructor(options?: Partial<VoiceCallOptions> | undefined);
1855
1910
  private get o();
1856
1911
  /** The language the fill channel speaks right now (null = unknown → silent). */
@@ -1905,7 +1960,16 @@ declare class VoiceCall {
1905
1960
  /** Follow the user's language from their own words: a confident detection, else the current language if the words
1906
1961
  * fit it, else unknown (silent). Pinned into the channel so its own detection never diverges. */
1907
1962
  private follow;
1963
+ private get quickOn();
1908
1964
  private onTurn;
1965
+ /** A MAIN reply cut while it played: the history keeps the part heard; a resume may say the rest. */
1966
+ private logCut;
1967
+ private logReply;
1968
+ /** The quick lane owns this turn: it answers, acks and hands it to MAIN, resumes a cut answer, or stays quiet. A late
1969
+ * or unusable decision hands the turn to MAIN as before (the fill channel's bridge covers it). */
1970
+ private quickTurn;
1971
+ /** say(), retried while the host's player is busy (up to 2s). */
1972
+ private sayRetry;
1909
1973
  private onDrop;
1910
1974
  /** Every fill/progress line passes here: only in the turn's known language, never after the call ended. */
1911
1975
  private say;
package/dist/index.js CHANGED
@@ -10456,11 +10456,13 @@ function cueKind(text) {
10456
10456
  return r.split(" ").some((w) => AGREE.has(w)) ? "agree" : null;
10457
10457
  }
10458
10458
  var ASIDES = {
10459
- en: { agree: ["Oh yeah, definitely.", "Yeah, exactly.", "Right, yeah."], continue: [] },
10460
- he: { agree: ["\u05DB\u05DF, \u05D1\u05D3\u05D9\u05D5\u05E7.", "\u05DB\u05DF, \u05DE\u05DE\u05E9.", "\u05E0\u05DB\u05D5\u05DF, \u05DB\u05DF."], continue: [] }
10459
+ en: { agree: ["Oh yeah, definitely.", "Yeah, exactly.", "Right, yeah."], continue: [], react: ["I know, right?", "Right? Wild.", "Yeah, crazy, right?"] },
10460
+ 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?"] }
10461
10461
  };
10462
- function overlapAside(text, lang, avoid = "", pick = (n) => Math.floor(Math.random() * n)) {
10463
- const kind = cueKind(text);
10462
+ 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;
10463
+ var isReaction = (text) => REACT.test(norm2(text));
10464
+ function overlapAside(text, lang, avoid = "", pick = (n) => Math.floor(Math.random() * n), react = false) {
10465
+ const kind = react && REACT.test(norm2(text)) ? "react" : cueKind(text);
10464
10466
  const l = new RegExp("\\p{Script=Hebrew}", "u").test(text) ? "he" : /[a-z]/i.test(text) ? "en" : lang;
10465
10467
  const pool = kind && l ? ASIDES[l]?.[kind] : void 0;
10466
10468
  if (!pool?.length) return null;
@@ -10589,13 +10591,17 @@ var INTENT_ACK_OVER = {
10589
10591
  resume: ["agreement", "silent"],
10590
10592
  aside: []
10591
10593
  };
10592
- function interruptionNote(cut, intent) {
10594
+ function heardAt(cut) {
10595
+ const at = Math.min(cut.heard.length, cut.full.length);
10596
+ return /\S/.test(cut.full[at] ?? "") && /\S/.test(cut.full[at - 1] ?? "") ? cut.full.lastIndexOf(" ", at) + 1 : at;
10597
+ }
10598
+ function interruptionNote(cut, intent, hold = true) {
10593
10599
  const full = cut.full.trim();
10594
- let at = Math.min(cut.heard.length, cut.full.length);
10595
- if (/\S/.test(cut.full[at] ?? "") && /\S/.test(cut.full[at - 1] ?? "")) at = cut.full.lastIndexOf(" ", at) + 1;
10600
+ const at = heardAt(cut);
10596
10601
  const heardWords = cut.full.slice(0, at).trim().split(/\s+/).filter(Boolean).length;
10597
10602
  const unheard = cut.full.slice(at).trim();
10598
- const landed = heardWords < 4 ? "They cut in almost at once \u2014 treat all of it as unsaid." : `They heard everything before this part. They missed the rest of it: "${unheard}".`;
10603
+ const lastWords = cut.full.slice(0, at).trim().split(/\s+/).slice(-8).join(" ");
10604
+ const landed = heardWords < 4 ? "They cut in almost at once \u2014 treat all of it as unsaid." : `They heard everything before this part. They missed the rest of it: "${unheard}". The last words they heard were "\u2026${lastWords}" \u2014 a "that"/"it"/"this" in their words means the thing those words were naming, never anything in the missed part.`;
10599
10605
  const how = {
10600
10606
  resume: "They did not ask anything new. Carry on with the part they missed \u2014 no restart, no apology.",
10601
10607
  aside: "It was an aside. Answer it briefly FIRST, then finish the part they missed, adjusted to anything they just said. Say each point once: skip whatever they already heard and whatever your answer just covered.",
@@ -10604,7 +10610,7 @@ function interruptionNote(cut, intent) {
10604
10610
  unknown: "Decide like a person would: if it was an aside, answer it and then finish your point; if they steered away, follow them and drop or adapt the rest."
10605
10611
  };
10606
10612
  return `
10607
- [the user interrupted you mid-speech. You were saying: "${full}" ${landed} ${how[intent ?? "unknown"]} Just talk, like a person picking the thread back up: never tell them what they heard or missed, never say where you were cut off, and never quote your earlier words back. If their words are still an unfinished fragment, call Hold instead of answering.]`;
10613
+ [the user interrupted you mid-speech. You were saying: "${full}" ${landed} ${how[intent ?? "unknown"]} Just talk, like a person picking the thread back up: never tell them what they heard or missed, never say where you were cut off, and never quote your earlier words back.` + (hold ? " If their words are still an unfinished fragment, call Hold instead of answering." : "") + "]";
10608
10614
  }
10609
10615
 
10610
10616
  // src/voice/unsaid.ts
@@ -13816,9 +13822,12 @@ var SOFT_CUE = "~";
13816
13822
  var STOP4 = new Set("about after again also always been before being could does doing down even every from going have here into just know like look make many more most much must never only other over really right same should some still such sure take than that their them then there these they thing think this those through very want well were what when where which while will with would your yeah okay".split(" "));
13817
13823
  var isContent = (w) => w.length >= 4 && !STOP4.has(w);
13818
13824
  function echoesHeard(line, heard) {
13819
- const said = new Set(cueWords(heard));
13820
- return cueWords(lineWords(line)).some((w) => isContent(w) && said.has(w));
13825
+ const said = cueWords(heard).filter(echoable).map(stem);
13826
+ return cueWords(lineWords(line)).filter(echoable).map(stem).some((w) => said.some((h) => h === w || Math.min(h.length, w.length) >= 4 && (h.startsWith(w) || w.startsWith(h))));
13821
13827
  }
13828
+ var stem = (w) => w.replace(/['’]s$/, "").replace(new RegExp("(?<=\\p{L}{3})s$", "u"), "");
13829
+ var SHORT_STOP = new Set("the and you are was for not but has had his her its our who why how can did get got let may one out see she two use way yes all any new now off old own say too him hey huh ooh wow yep".split(" "));
13830
+ var echoable = (w) => isContent(w) || w.length === 3 && !SHORT_STOP.has(w) && !new RegExp("^\\p{N}+$", "u").test(w);
13822
13831
  var leafKey = (line) => cueWords(lineWords(line)).join(" ");
13823
13832
  var ConvoTreeOptions = class {
13824
13833
  /** A leaf plays at this confidence or above. */
@@ -14344,6 +14353,8 @@ var SecondChannel = class {
14344
14353
  // live: this turn's ask leaf
14345
14354
  barged = false;
14346
14355
  // the user cut in since their last turn: that turn is a steer, not a story to react to
14356
+ said = "";
14357
+ // live: what the user heard the assistant say last (the cut's heard part, else the last reply)
14347
14358
  leafReady = Promise.resolve();
14348
14359
  // live: the turn-end leaf pick settled
14349
14360
  recent = [];
@@ -14560,8 +14571,9 @@ var SecondChannel = class {
14560
14571
  }
14561
14572
  }
14562
14573
  /** The user's final line was dispatched to the main agent (its words are the bridge's micro-context). */
14563
- onUserTurn(text, lastWordAgoMs = 0) {
14574
+ onUserTurn(text, lastWordAgoMs = 0, heardCut) {
14564
14575
  this.heard = text.trim();
14576
+ this.said = (heardCut ?? this.reply).trim();
14565
14577
  this.lastWordAgo = Math.max(0, lastWordAgoMs);
14566
14578
  this.floorWords = this.carried + words2(this.heard).length;
14567
14579
  this.lastUser = this.heard;
@@ -14868,12 +14880,14 @@ var SecondChannel = class {
14868
14880
  this.bridgeReady = Promise.resolve();
14869
14881
  this.noLine = "";
14870
14882
  if (!this.o.generate || !(this.ownWords || this.o.generateFor.includes("bridge")) || !this.lang || !this.heard) return;
14871
- const gen = this.gen, ac = new AbortController(), own = this.ownWords, heard = this.heard;
14872
- const ctx = { kind: "bridge", heard: this.tail(), state: this.main, avoid: [...this.recent], lang: this.lang, ...own ? { ask: true } : {} };
14883
+ const gen = this.gen, ac = new AbortController(), own = this.ownWords;
14884
+ const said = own ? words2(this.said.replace(/\[[^\]]*\]/g, " ")).slice(-this.o.microWords).join(" ") : "", heard = `${this.heard} ${said}`;
14885
+ const ctx = { kind: "bridge", heard: this.tail(), state: this.main, avoid: [...this.recent], lang: this.lang, ...own ? { ask: true } : {}, ...said ? { said, cut: this.barged } : {} };
14886
+ log31.debug(`bridge ctx: said=${JSON.stringify(ctx.said ?? "")} cut=${!!ctx.cut}`);
14873
14887
  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) => {
14874
14888
  const none = own && /^\s*none\b/i.test(raw ?? ""), text = none ? "" : cleanLine(raw ?? "", ctx.lang), echoes = !own || echoesHeard(text, heard);
14875
14889
  if (text && gen === this.gen && echoes) this.bridgeDraft = { gen, text };
14876
- else if (gen === this.gen) this.noLine = raw === null ? "fast model late or failed" : none ? "fast model: none" : !text ? "fast model line unusable" : "line names nothing heard";
14890
+ else if (gen === this.gen) this.noLine = raw === null ? "fast model late or failed" : none ? "fast model: none" : !text ? "fast model line unusable" : `line names nothing heard: "${text}"`;
14877
14891
  }).catch((e) => log31.debug(`bridge prefetch failed: ${e?.message ?? e}`));
14878
14892
  }
14879
14893
  async line(kind, react = true) {
@@ -14977,11 +14991,21 @@ var KIND_HINT2 = {
14977
14991
  };
14978
14992
  var REACT_HINT = 'a short reaction to their LAST words instead: feeling ("oh no", "ha, nice", "ugh"), surprise ("wait, really?", "huh"), a light laugh if they joke or laugh ("ha!"), or an echo of their key word ("the deploy?") \u2014 still never asks for an answer or takes the turn; if nothing there deserves a reaction, a plain "mm-hm"';
14979
14993
  var TAG_HINT = 'Real listeners often react without words: the line may be, or begin with, [laughter] or [gasp], and [quiet] before words breathes them under the voice ("[gasp]", "[laughter]", "[gasp] [quiet] no way"). Use a sound when it fits what they said.';
14994
+ function askPrompt(c, gender) {
14995
+ const last = c.said ? c.said.split(/(?<=[.!?])\s+/).filter((x) => /\w/.test(x)).pop() : "";
14996
+ const said = !c.said ? "" : c.cut ? `You (the assistant) were saying: "\u2026${c.said}" \u2014 they cut you off there, so the last thing they heard was "${last}". Their "that"/"it" means THAT last thing.
14997
+ ` : `You (the assistant) last said: "\u2026${c.said}"
14998
+ `;
14999
+ return `A live voice call. ${said}The user just said: "${c.heard}"
15000
+ Your full answer takes a few seconds. Write ONE spoken line of 2-5 words in ${languageName(c.lang)} to say at once, in their or your own words:
15001
+ - they ask you to look up, check, find or do something \u2192 name the thing and say you are on it ("Hacker News, one sec.")
15002
+ - they ask about something you said ("that", "it", "who", "why") \u2192 echo the thing they mean as a short question ("the OpenAI one?", "the Postman thing?") or a quick reaction to it
15003
+ Never state a fact, a name or an answer that was not already said. If it is a closer, thanks, an ok/yes, small talk or a remark that needs no answer, write: none
15004
+ ${personaHint(gender)} Output only the line.`;
15005
+ }
14980
15006
  function fastLineGenerator(ai, model, gender) {
14981
15007
  return async (c, signal) => {
14982
- const prompt = c.ask ? `A live voice call. The user just said: "${c.heard}"
14983
- If this asks you to look up, check, find or do something that takes a while, write ONE spoken line of 2-5 words in ${languageName(c.lang)} that names the thing in their own words and says you are on it ("Hacker News, one sec."). If it is small talk, a statement, or something you can answer at once, write: none
14984
- ${personaHint(gender)} Output only the line.` : `You voice the tiny side-sounds of a live spoken conversation. Write ONE line of 1-5 words: ${KIND_HINT2[c.kind]}.
15008
+ const prompt = c.ask ? askPrompt(c, gender) : `You voice the tiny side-sounds of a live spoken conversation. Write ONE line of 1-5 words: ${KIND_HINT2[c.kind]}.
14985
15009
  ` + (c.react ? `Here the line may be ${REACT_HINT}.
14986
15010
  ` : "") + (c.tags ? `${TAG_HINT}
14987
15011
  ` : "") + `The user just said: "${c.heard}"
@@ -15016,9 +15040,21 @@ var VoiceCallOptions = class {
15016
15040
  * runs as MAIN's next turn. Not injected mid-run: that makes MAIN run again just to hear a remark. Absent: such a line
15017
15041
  * barges in as before. */
15018
15042
  noteTurn;
15043
+ /** What the user HEARD of MAIN's reply a barge just cut (a peek — the host still takes the cut for MAIN), else null:
15044
+ * a live bridge echoes what their "that" points at. */
15045
+ heardCut;
15019
15046
  /** Writes that immediate answer (fastWorkReply). */
15020
15047
  workReply;
15021
15048
  workReplyBudgetMs = 1500;
15049
+ /** Live: the quick lane (fastQuickLane) owns the conversation — each turn it answers, acks + hands to MAIN, resumes a
15050
+ * cut answer, or stays quiet. Absent (or another mode): every turn goes to MAIN as before. */
15051
+ quick;
15052
+ /** Past this the turn goes to MAIN as before (the bridge covers it). */
15053
+ quickBudgetMs = 1800;
15054
+ /** The unsaid rest of MAIN's reply a barge just cut (a peek, like heardCut), else null — what a resume says. */
15055
+ cutRest;
15056
+ /** A resume said that rest: the host drops the cut (MAIN's history keeps the whole reply). */
15057
+ dropCut;
15022
15058
  /** Host TTS (fill lane): resolves when played; `false` = could not play. */
15023
15059
  speak = () => false;
15024
15060
  /** Stop the in-flight fill line now (barge-in only). */
@@ -15060,6 +15096,7 @@ var VoiceCallOptions = class {
15060
15096
  progressLeadMs = 1e3;
15061
15097
  };
15062
15098
  var VoiceCall = class {
15099
+ // a MAIN reply cut while audible: its heard part goes to the history at the next turn
15063
15100
  constructor(options) {
15064
15101
  this.options = options;
15065
15102
  this.options = { ...new VoiceCallOptions(), ...options };
@@ -15122,6 +15159,11 @@ var VoiceCall = class {
15122
15159
  progressTimer = null;
15123
15160
  lastUserAt = -Infinity;
15124
15161
  ended = false;
15162
+ /** The call as both lanes know it: the user's turns and what was said aloud (quick lines, MAIN's heard replies). */
15163
+ history = [];
15164
+ cutRest = "";
15165
+ // the unsaid rest of the last cut MAIN reply, until the next turn decides it
15166
+ cutTurn;
15125
15167
  get o() {
15126
15168
  return this.options;
15127
15169
  }
@@ -15217,6 +15259,7 @@ var VoiceCall = class {
15217
15259
  return;
15218
15260
  case "text":
15219
15261
  if (!ev.text) return;
15262
+ c.reply += ev.text;
15220
15263
  c.marks.mainFirst ??= this.o.now();
15221
15264
  c.marks.mainText ??= this.o.now();
15222
15265
  if (!c.streamed) {
@@ -15293,6 +15336,7 @@ var VoiceCall = class {
15293
15336
  } catch (e) {
15294
15337
  log32.warn(`cancel threw: ${e.message}`);
15295
15338
  }
15339
+ if (c?.worded && c.lane === "deep" && !c.cutRead) this.cutTurn = c;
15296
15340
  if (c?.running) {
15297
15341
  c.running = false;
15298
15342
  this.o.abortTurn(c.id);
@@ -15301,6 +15345,7 @@ var VoiceCall = class {
15301
15345
  }
15302
15346
  /** Soft barge-in: keep (a listener cue — no turn) or cut (→ barge()). */
15303
15347
  async overlap(text) {
15348
+ if (this.o.mode === "live" && isReaction(text)) return "keep";
15304
15349
  const d = await this.judge.judge(text);
15305
15350
  if (d.verdict === "cut") this.barge();
15306
15351
  return d.verdict;
@@ -15312,9 +15357,10 @@ var VoiceCall = class {
15312
15357
  aside(text) {
15313
15358
  const now3 = this.o.now();
15314
15359
  if (now3 - this.lastAside.at < this.o.asideGapMs) return null;
15315
- const line = overlapAside(text, this.lang, this.lastAside.text);
15360
+ const line = overlapAside(text, this.lang, this.lastAside.text, void 0, this.o.mode === "live");
15316
15361
  if (!line) return null;
15317
15362
  this.lastAside = { text: line, at: now3 };
15363
+ if (this.quickOn) this.history.push({ who: "user", text }, { who: "you", text: line });
15318
15364
  this.o.onMetric({ name: "fill", kind: "aside", text: line, lang: this.lang });
15319
15365
  return line;
15320
15366
  }
@@ -15342,18 +15388,23 @@ var VoiceCall = class {
15342
15388
  this.lang = l;
15343
15389
  if (l) this.fill.setLanguage(l, true);
15344
15390
  }
15391
+ get quickOn() {
15392
+ return this.o.mode === "live" && !!this.o.quick;
15393
+ }
15345
15394
  onTurn(t) {
15346
15395
  this.floor = "";
15347
15396
  if (this.o.noteTurn && this.o.workReply && t.kind !== "replace" && this.working && !isClosing(t.text)) return void this.overWork(this.cur, t);
15397
+ const prev = this.cur, quick = this.quickOn && !this.working && (t.kind === "new" || prev?.lane !== "deep");
15348
15398
  const now3 = this.o.now(), lastWord = this.lastWordAt !== null;
15349
15399
  const at = this.lastWordAt ?? this.firstFinalAt ?? now3;
15350
15400
  const finalAt = this.finalAt || now3;
15351
15401
  this.firstFinalAt = null;
15352
15402
  this.lastWordAt = null;
15353
- if (this.cur) this.close(this.cur, t.replaces === this.cur.id ? "replaced" : void 0);
15403
+ if (this.quickOn) this.logCut();
15404
+ if (prev) this.close(prev, t.replaces === prev.id ? "replaced" : void 0);
15354
15405
  this.follow(t.text);
15355
15406
  this.clearProgress();
15356
- this.cur = { id: t.id, text: t.text, at, finalAt, lastWord, running: true, streamed: false, sounded: false, worded: false, done: false, marks: { sent: now3 }, closed: false, due: turnIntent(t.text) !== "closer", open: 0, tool: "", draft: "", drafting: false, draftAt: -Infinity };
15407
+ this.cur = { id: t.id, text: t.text, at, finalAt, lastWord, running: !quick, streamed: false, sounded: false, worded: false, done: false, marks: { sent: now3 }, closed: false, due: turnIntent(t.text) !== "closer", open: 0, tool: "", draft: "", drafting: false, draftAt: -Infinity, reply: "", ...this.quickOn ? { lane: quick ? "pending" : "deep" } : {} };
15357
15408
  const early = this.earlyHeard;
15358
15409
  this.earlyHeard = null;
15359
15410
  if (early && early.at >= at) {
@@ -15362,8 +15413,98 @@ var VoiceCall = class {
15362
15413
  }
15363
15414
  this.progress.turn();
15364
15415
  this.o.onMetric({ name: "turn", id: t.id, kind: t.kind, text: t.text });
15365
- this.o.sendTurn(t.text, { id: t.id, ...t.replaces ? { replaces: t.replaces } : {} });
15366
- if (t.kind === "new") this.fill.onUserTurn(t.text, now3 - at);
15416
+ if (this.quickOn) {
15417
+ const last = this.history.at(-1);
15418
+ if (t.kind !== "new" && last?.who === "user") last.text = t.text;
15419
+ else this.history.push({ who: "user", text: t.text });
15420
+ }
15421
+ if (quick) return void this.quickTurn(this.cur, t);
15422
+ this.o.sendTurn(t.text, { id: t.id, ...t.replaces && (!this.quickOn || prev?.lane === "deep") ? { replaces: t.replaces } : {} });
15423
+ if (t.kind === "new") this.fill.onUserTurn(t.text, now3 - at, this.o.heardCut?.() ?? void 0);
15424
+ }
15425
+ /** A MAIN reply cut while it played: the history keeps the part heard; a resume may say the rest. */
15426
+ logCut() {
15427
+ const c = this.cutTurn;
15428
+ this.cutTurn = void 0;
15429
+ if (!c || c.cutRead) return;
15430
+ c.cutRead = true;
15431
+ this.cutRest = "";
15432
+ const heard = this.o.heardCut?.() ?? null;
15433
+ if (heard === null) return void this.logReply(c);
15434
+ if (c.logged) Object.assign(c.logged, { text: heard, cut: true });
15435
+ else this.history.push(c.logged = { who: "you", text: heard, cut: true });
15436
+ this.cutRest = this.o.cutRest?.() ?? "";
15437
+ }
15438
+ logReply(c) {
15439
+ if (c.lane !== "deep" || c.logged || !c.reply.trim()) return;
15440
+ this.history.push(c.logged = { who: "you", text: c.reply.replace(/\[[a-z ]+\]\s*/gi, "").trim() });
15441
+ }
15442
+ /** The quick lane owns this turn: it answers, acks and hands it to MAIN, resumes a cut answer, or stays quiet. A late
15443
+ * or unusable decision hands the turn to MAIN as before (the fill channel's bridge covers it). */
15444
+ async quickTurn(c, t) {
15445
+ const ac = new AbortController(), t0 = this.o.now(), lang = this.lang, rest = this.cutRest;
15446
+ c.ask = ac;
15447
+ const late = setTimeout(() => ac.abort(), this.o.quickBudgetMs);
15448
+ const mv = lang ? await this.o.quick({ history: this.history.slice(0, -1), heard: t.text, lang, rest }, ac.signal).catch((e) => {
15449
+ if (this.cur === c) log32.warn(`quick lane ${ac.signal.aborted ? `late (${this.o.quickBudgetMs}ms)` : `failed: ${e?.message ?? e}`} \u2014 deep lane`);
15450
+ return null;
15451
+ }).finally(() => clearTimeout(late)) : null;
15452
+ if (this.ended || this.cur !== c || c.closed) return;
15453
+ c.ask = void 0;
15454
+ this.o.onMetric({ name: "lane", id: c.id, kind: mv?.kind ?? "fallback", ms: Math.round(this.o.now() - t0), ...mv && "line" in mv && mv.line ? { text: mv.line } : mv?.kind === "deep" && mv.ack ? { text: mv.ack } : {} });
15455
+ const note = (n) => this.o.noteTurn?.(`[${n}]`);
15456
+ if (!mv || mv.kind === "deep") {
15457
+ c.lane = "deep";
15458
+ c.running = true;
15459
+ this.cutRest = "";
15460
+ const ack = mv?.kind === "deep" ? mv.ack : "", brief = mv?.kind === "deep" ? mv.brief : "";
15461
+ if (ack) {
15462
+ note(`You (the call's quick voice) already told them aloud: "${ack}". Do not acknowledge again \u2014 start with the answer itself.${brief && brief !== t.text ? ` It took their words to mean: ${brief}.` : ""}`);
15463
+ this.history.push({ who: "you", text: ack });
15464
+ }
15465
+ this.o.sendTurn(t.text, { id: t.id });
15466
+ if (!ack) return void this.fill.onUserTurn(t.text, this.o.now() - c.at, this.o.heardCut?.() ?? void 0);
15467
+ this.gate.replyStarted(c.id);
15468
+ if (await this.sayRetry(ack, "ack", c.id)) {
15469
+ this.o.show(ack, "ack");
15470
+ if (this.cur === c && c.running) this.beat(c);
15471
+ }
15472
+ return;
15473
+ }
15474
+ c.lane = "quick";
15475
+ if (mv.kind === "quiet") {
15476
+ c.due = false;
15477
+ return this.close(c, "silent");
15478
+ }
15479
+ const said = mv.kind === "resume" ? `${mv.line} ${rest}`.trim() : mv.line;
15480
+ this.gate.replyStarted(c.id);
15481
+ if (!await this.sayRetry(said, "reply", c.id)) return this.close(c, "silent");
15482
+ this.o.show(said, "reply");
15483
+ if (!c.worded) {
15484
+ c.worded = true;
15485
+ c.marks.mainAudio = this.lastAudibleAt;
15486
+ this.o.onMetric({ name: "first_word", id: c.id, ms: Math.round(this.lastAudibleAt - c.at), by: "quick" });
15487
+ }
15488
+ if (mv.kind === "resume") {
15489
+ this.cutRest = "";
15490
+ this.o.dropCut?.();
15491
+ this.history.push({ who: "you", text: rest });
15492
+ note(`They asked you to go on, and you continued your cut answer aloud: "${rest}". All of it has now been said.`);
15493
+ } else {
15494
+ this.history.push({ who: "you", text: said });
15495
+ 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.`);
15496
+ }
15497
+ this.close(c, "answered");
15498
+ }
15499
+ /** say(), retried while the host's player is busy (up to 2s). */
15500
+ async sayRetry(line, kind, id) {
15501
+ for (let i = 0; i < 8; i++) {
15502
+ if (this.ended) return false;
15503
+ if (this.say(line, kind) !== false) return true;
15504
+ await new Promise((r) => setTimeout(r, 250));
15505
+ }
15506
+ this.o.onMetric({ name: "drop", id, kind: `${kind} unplayed`, text: line });
15507
+ return false;
15367
15508
  }
15368
15509
  onDrop(text, why) {
15369
15510
  if (!this.gate.holding) {
@@ -15388,7 +15529,7 @@ var VoiceCall = class {
15388
15529
  this.o.onMetric({ name: "fill", kind, text, lang: this.lang });
15389
15530
  if (kind !== "backchannel") this.progress.heard();
15390
15531
  const c = this.cur && !this.cur.closed ? this.cur : void 0;
15391
- const forTurn = !!c && (kind === "bridge" || kind === "progress" || kind === "filler" && c.running && !c.sounded);
15532
+ const forTurn = !!c && (kind === "bridge" || kind === "progress" || kind === "ack" || kind === "reply" || kind === "filler" && c.running && !c.sounded);
15392
15533
  if (c && forTurn && c.marks.fill === void 0) {
15393
15534
  c.marks.fill = this.o.now();
15394
15535
  c.fillKind = kind;
@@ -15398,7 +15539,7 @@ var VoiceCall = class {
15398
15539
  this.lastAudibleAt = this.o.now();
15399
15540
  if (c && forTurn) {
15400
15541
  c.marks.fillAudio ??= this.o.now();
15401
- this.sounded(c, kind === "progress" ? "progress" : "fill");
15542
+ this.sounded(c, kind === "progress" ? "progress" : kind === "ack" || kind === "reply" ? "quick" : "fill");
15402
15543
  }
15403
15544
  return r;
15404
15545
  }
@@ -15412,6 +15553,8 @@ var VoiceCall = class {
15412
15553
  close(c, end) {
15413
15554
  if (c.closed) return;
15414
15555
  c.closed = true;
15556
+ c.ask?.abort();
15557
+ this.logReply(c);
15415
15558
  c.end = c.worded ? "answered" : end ?? c.end ?? "silent";
15416
15559
  if (!c.worded) this.o.onMetric({ name: "first_word", id: c.id, by: "main", kind: c.end });
15417
15560
  const rel = (t) => t === void 0 ? void 0 : Math.round(t - c.at);
@@ -15448,17 +15591,13 @@ var VoiceCall = class {
15448
15591
  const line = own || (this.o.mode === "live" ? "" : answer);
15449
15592
  const stop = /^\s*stop\s*:/i.test(raw), change = !answer || /^\s*work\s*:/i.test(raw);
15450
15593
  const noted = `[The user said this on the call while you worked: "${t.text}".${line ? ` You answered aloud: "${line}".` : ""}${stop ? " That stopped the work." : ""} Take it into account; do not answer it again.]`;
15594
+ this.history.push({ who: "user", text: t.text });
15451
15595
  if (line && !this.ended) {
15452
- for (let i = 0; i < 8 && this.say(line, "aside") === false; i++) {
15453
- if (i === 7) {
15454
- this.o.onMetric({ name: "drop", id: t.id, kind: "aside unplayed", text: line });
15455
- break;
15456
- }
15457
- await new Promise((r) => setTimeout(r, 250));
15458
- }
15596
+ await this.sayRetry(line, "aside", t.id);
15459
15597
  if (this.lastAudibleAt >= at) {
15460
15598
  this.progress.note(line);
15461
15599
  this.o.show(line, "aside");
15600
+ this.history.push({ who: "you", text: line });
15462
15601
  }
15463
15602
  } else if (!line) this.o.onMetric({ name: "drop", id: t.id, kind: "no aside line" });
15464
15603
  if (stop) {