@livx.cc/agentx 0.99.147 → 0.99.148

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/README.md CHANGED
@@ -120,7 +120,7 @@ agentx --resume <id> "…" # resume a specific session
120
120
  - **@-file mentions & headless JSON** — reference files inline in a prompt with `@path` (e.g. `explain @src/Agent.ts`; `~/` expands to the home directory; quote paths with spaces as `@"…"` — drag-dropped files, e.g. macOS screenshots, quote themselves automatically); script with `-p --output-format json` to get one machine-readable result object on stdout (activity stays on stderr).
121
121
  - **Raise, don't guess** (`AskUserQuestion` + `finishReason: 'needs_input'`) — when a decision is genuinely the user's, the agent asks. Interactively that's an arrow-select prompt. **Headless** (`-p`, piped, no TTY) there's nobody to prompt, so instead of blocking on a prompt no one can see — or, worse, "proceeding with best judgment" — the run **stops and hands the question to its caller**: exit code `2`, a yellow `? needs input` footer, and `{finishReason:'needs_input', question:{…}, sessionId}` in `--output-format json`. The transcript is preserved, so the caller answers and continues (`--resume <id> -p "<answer>"`) instead of re-running. A delegated agent silently deciding something that was never its to decide is the failure this closes.
122
122
  - **Tab-completion** — `Tab` completes `/<command>` names and `@<path>` file/dir references (descends subdirs, dotfiles hidden unless typed) straight from the working tree.
123
- - **Voice call (duplex v3)** — `agentx --call --voice` (also what interactive `--duplex`/`--duplex-v2`/`--voice` run now; `AGENTX_DUPLEX_V1=1` keeps the reflex engine below for one release): the main agent (`-m`, full tools, real history) hears the user's exact words and answers every turn; a fast model (`--voice-model`, default Claude Haiku) only covers the wait — backchannels, fillers, bridges and tool-progress lines — and has no path into the history. `VoiceCall` (`src/voice/call.ts`, exported) is the host-agnostic core: `TurnGate` holds mid-phrase finals, merges re-finals, drops duplicates and a second goodbye; `Progress` speaks "checking the board…" during long tool runs. `--voice-persona <file>` sets who the call is: it replaces the default call style in MAIN's prompt and feeds the live prediction tree. In `--channel-mode live`, bridges and progress carry the request's own words ("Hacker News, one sec.": a tree leaf, else the fast model, else silence), never a stock line. A call's greeting uses no tools and its prompt is warmed first.
123
+ - **Voice call (duplex v3)** — `agentx --call --voice` (also what interactive `--duplex`/`--duplex-v2`/`--voice` run now; `AGENTX_DUPLEX_V1=1` keeps the reflex engine below for one release): the main agent (`-m`, full tools, real history) hears the user's exact words and answers every turn; a fast model (`--voice-model`, default Claude Haiku) only covers the wait — backchannels, fillers, bridges and tool-progress lines — and has no path into the history. `VoiceCall` (`src/voice/call.ts`, exported) is the host-agnostic core: `TurnGate` holds mid-phrase finals, merges re-finals, drops duplicates and a second goodbye; `Progress` speaks "checking the board…" during long tool runs. `--voice-persona <file>` sets who the call is: it replaces the default call style in MAIN's prompt and feeds the live prediction tree. In `--channel-mode live`, bridges and progress carry the request's own words ("Hacker News, one sec.": a tree leaf, else the fast model, else silence), never a stock line. A call's greeting uses no tools and its prompt is warmed first. While MAIN works (`noteTurn` + `workReply`), a remark gets an immediate fast-model answer and reaches MAIN as a note on its next turn; a change runs as MAIN's next turn; a stop aborts it. Progress lines start about 3 s into a silence and repeat about every 5 s, never the same line. `--call` sets `ENABLE_TOOL_SEARCH=false` (claude-code/*: tools loaded up front, a larger prompt for no ToolSearch round trip). A persona should say to react first, then give the fact: `When they react or push back ("what?", "are you serious?"), react first, like a person, then give the fact.`
124
124
  - **Fill channel for host apps** — `agentx --channel-only --input-format stream-json --output-format stream-json` hosts a `VoiceCall` behind NDJSON for an app whose MAIN is its own agent: stdin `{type:'final', text, sttId?}`, `{type:'main', ev}` (MAIN's start/text/tool/tool_done/audio/done/error), `{type:'interim'|'pause'|'barge'|'overlap'}`; stdout `{type:'turn', id, text, replaces?}` (run MAIN on it), `{type:'abort', id}`, `{type:'channel', kind, text, speech?}` (`speech`: what to play when it differs: tagged; `text` is '' for a sound alone). The v2 inputs (`user`/`text`/`agent_state`) still work.
125
125
  - **Duplex mode** — `agentx --duplex` runs the full standard REPL (slash commands, sessions, postures, rewind, MCP) with the three-tier engine driving turns: a fast voice model (`--voice-model`, default `groq/openai/gpt-oss-120b`) answers every line instantly and delegates real work to background workers built with the same wiring as a normal run (fs mode, permissions, MCP); worker activity shows as dim chrome and results are re-voiced when ready. Switch any tier live with `/model` (opens a reflex/act/think picker), or the `/voice-model` · `/think-model` shortcuts. `/tasks` lists background tasks, inspects a task's live output tail, and cancels a running one from a picker (Esc mid-turn cancels the foreground turn; Esc again at the idle prompt cancels running workers).
126
126
  - **Headless duplex for host apps** — `agentx --voice --input-format stream-json --output-format stream-json` runs the same duplex engine behind an NDJSON pipe, for an app that owns its own mic/TTS (the Bare browser uses it). stdin: `{type:'user', text, id?, replaces?, cut?}` (`cut` = the host voice engine's `takeInterruptedReply()`, so "heard up to" / parked deliveries work exactly as in the CLI), `{type:'barge'}`, `{type:'cancel', task}`, `{type:'exit'}`. stdout: reflex `text`/`thinking` deltas, worker `speak` utterances, `filler`, `task` lifecycle events, `turn_done`, `revoice_done`, `exit`. `--append-system-prompt` goes to the workers, `--voice-system-prompt` to the voice model.
package/dist/cli.js CHANGED
@@ -13981,9 +13981,6 @@ init_logging();
13981
13981
  init_logging();
13982
13982
  init_models();
13983
13983
 
13984
- // src/voice/progress.ts
13985
- init_logging();
13986
-
13987
13984
  // src/voice/convoTree.ts
13988
13985
  init_logging();
13989
13986
 
@@ -14243,10 +14240,13 @@ Answer only the number, or "none".`;
14243
14240
  }
14244
14241
 
14245
14242
  // src/voice/progress.ts
14243
+ init_logging();
14246
14244
  var log28 = forComponent("Progress");
14247
14245
  var HE_RESULT_CLAIM = /(?:^|\s)(?:מצאתי|סיימתי|בוצע|הנה|אין)(?=\s|$|[.,!…])/u;
14246
+ var PLUMBING = /toolsearch|^mcp__.*__(list_commands|call_info)$/;
14247
+ var isPlumbing = (tool) => PLUMBING.test(tool.toLowerCase());
14248
14248
  var TOPICS = [
14249
- [/toolsearch|^mcp__.*__(list_commands|call_info)$/, null],
14249
+ [PLUMBING, null],
14250
14250
  // tool plumbing — no line (and no generated one)
14251
14251
  [/kanban|board|card|\bkb\b|list_cards/, "board"],
14252
14252
  [/mail|gmail|inbox/, "mail"],
@@ -14346,6 +14346,7 @@ var Progress = class {
14346
14346
  said = /* @__PURE__ */ new Set();
14347
14347
  lastAt = -Infinity;
14348
14348
  streamed = false;
14349
+ lines = [];
14349
14350
  get o() {
14350
14351
  return this.options;
14351
14352
  }
@@ -14353,20 +14354,33 @@ var Progress = class {
14353
14354
  turn() {
14354
14355
  this.streamed = false;
14355
14356
  }
14356
- /** MAIN's text streamed this turn: no more progress lines for it. */
14357
+ /** MAIN's text streamed this turn: no more progress lines, until a tool runs again. */
14357
14358
  text() {
14358
14359
  this.streamed = true;
14359
14360
  }
14360
- /** May a line play now? (the caller passes when the user last heard anything) */
14361
- due(lastAudibleAt) {
14361
+ /** A tool started: MAIN is working again. */
14362
+ tool() {
14363
+ this.streamed = false;
14364
+ }
14365
+ /** May a line play now, or `leadMs` from now? (the caller passes when the user last heard anything) */
14366
+ due(lastAudibleAt, leadMs = 0) {
14362
14367
  const now4 = this.o.now();
14363
- return !this.streamed && now4 - lastAudibleAt >= this.o.silenceMs && now4 - this.lastAt >= this.o.gapMs;
14368
+ return !this.streamed && now4 - lastAudibleAt >= this.o.silenceMs - leadMs && now4 - this.lastAt >= this.o.gapMs - leadMs;
14364
14369
  }
14365
14370
  /** Mark `line` spoken. */
14366
14371
  spoke(line) {
14367
- this.said.add(norm3(line));
14372
+ this.note(line);
14368
14373
  this.lastAt = this.o.now();
14369
14374
  }
14375
+ /** A line the user heard from elsewhere (an aside): progress never repeats it. */
14376
+ note(line) {
14377
+ this.said.add(norm3(line));
14378
+ this.lines = [...this.lines, line].slice(-6);
14379
+ }
14380
+ /** The last lines heard, for a writer to avoid. */
14381
+ get recent() {
14382
+ return [...this.lines];
14383
+ }
14370
14384
  /** `about`: the user's request, for a generated line. The line for this tool call in `lang`, or '' (no template and no/late/invalid generation, a repeat, a result claim). */
14371
14385
  async line(tool, args, lang, about = "") {
14372
14386
  if (this.streamed) return "";
@@ -14387,7 +14401,7 @@ var Progress = class {
14387
14401
  r(null);
14388
14402
  }, this.o.generateBudgetMs);
14389
14403
  });
14390
- const raw = await Promise.race([this.o.generate(tool, [about.slice(-80), argsHint(args)].filter(Boolean).join("; "), lang, ac.signal).catch((e) => {
14404
+ const raw = await Promise.race([this.o.generate(tool, [about.slice(-80), argsHint(args)].filter(Boolean).join("; "), lang, ac.signal, this.lines).catch((e) => {
14391
14405
  log28.warn(`progress line failed: ${e?.message ?? e}`);
14392
14406
  return null;
14393
14407
  }), late]).finally(() => clearTimeout(t));
@@ -14397,8 +14411,24 @@ var Progress = class {
14397
14411
  }
14398
14412
  };
14399
14413
  function fastProgressGenerator(ai, model, gender) {
14400
- return async (tool, hint, lang, signal) => {
14401
- 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 ? "Use the words of what it is about. " : ""}Never state a result or a finding. ${personaHint(gender)} Output only the line.`;
14414
+ return async (tool, hint, lang, signal, avoid = []) => {
14415
+ 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 ? "Use the words of what it is about. " : ""}${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.`;
14416
+ const reasoning = /gpt-oss/.test(model) ? { providerOptions: { reasoning_effort: "low" } } : {};
14417
+ const r = await ai.chat({ model, messages: [{ role: "user", content: prompt }], stream: false, signal, maxTokens: 150, ...reasoning });
14418
+ return r.content ?? "";
14419
+ };
14420
+ }
14421
+ function cleanWorkReply(raw, lang) {
14422
+ const l = cleanLine(raw.replace(/^\s*(?:stop|work)\s*:/i, ""), lang, 8);
14423
+ return RESULT_CLAIM_RE.test(l) || HE_RESULT_CLAIM.test(l) ? "" : l;
14424
+ }
14425
+ function fastWorkReply(ai, model, gender, persona = "") {
14426
+ return async (c, signal) => {
14427
+ const prompt = `${persona ? `Who you are on this call:
14428
+ ${persona.slice(0, 500)}
14429
+
14430
+ ` : ""}You are on a live voice call, in the middle of doing this for them: "${c.request.slice(-160)}"${c.tool ? ` (right now: ${c.tool}${c.hint ? ` on ${c.hint}` : ""})` : ""}. They just said, while you work: "${c.heard.slice(-200)}"
14431
+ Answer them at once with ONE short spoken line of 2-7 words in ${languageName(c.lang)}, the way a person busy on it would ("yeah, looking now"). You have no results yet: state none, promise none. ` + (c.avoid.length ? `Do not reuse: ${c.avoid.map((a) => `"${a}"`).join(", ")}. ` : "") + `If they tell you to stop or drop the work, start the line with "stop:". If they change the request or add to it, start it with "work:". ${personaHint(gender)} Output only the line, no tone tag.`;
14402
14432
  const reasoning = /gpt-oss/.test(model) ? { providerOptions: { reasoning_effort: "low" } } : {};
14403
14433
  const r = await ai.chat({ model, messages: [{ role: "user", content: prompt }], stream: false, signal, maxTokens: 150, ...reasoning });
14404
14434
  return r.content ?? "";
@@ -15000,7 +15030,7 @@ var SecondChannel = class {
15000
15030
  this.breathTimer = setTimeout(() => {
15001
15031
  this.breathTimer = null;
15002
15032
  const n = words3(t).length, tree = this.tree;
15003
- if (n < this.o.backchannelMinWords || this.heard !== t || this.leafTimer || this.picking || tree.empty || this.leafGated()) return;
15033
+ if (!this.backchannelMoment(n, true) || this.heard !== t || this.leafTimer || this.picking || tree.empty || this.leafGated()) return;
15004
15034
  this.picking = true;
15005
15035
  const ac = new AbortController(), nodes = tree.nodes.filter((x) => x.moment !== "ask"), lines = nodes.map((x, i) => ({ i, line: x.line, when: x.when }));
15006
15036
  void withBudget(this.o.pickLeaf(t, lines, ac.signal), this.o.pickBudgetMs, "breath pick", ac).then((i) => {
@@ -15062,6 +15092,7 @@ var SecondChannel = class {
15062
15092
  * sentence end only deep into a story — a short request's end is the end of their turn (replay: "mm-hm" right after
15063
15093
  * "Check hacker news for recent news.", just before the final). */
15064
15094
  backchannelMoment(n, breath) {
15095
+ if (!cueWords(this.heard).some(isContent)) return false;
15065
15096
  if (/\?$/.test(this.heard) || pendingQuestion(this.heard)) return false;
15066
15097
  if (this.carried) n += this.carried;
15067
15098
  else if (n < this.o.requestHoldWords && requestOpener(this.heard)) return false;
@@ -15281,6 +15312,14 @@ var VoiceCallOptions = class {
15281
15312
  /** Host aborts a running MAIN turn (barge-in). */
15282
15313
  abortTurn = () => {
15283
15314
  };
15315
+ /** Host keeps `note` for MAIN's next turn. With it (and `workReply`), what the user says while MAIN works is answered at
15316
+ * once by the fast model and MAIN is not aborted or restarted: a remark reaches MAIN as this note, a change or addition
15317
+ * runs as MAIN's next turn. Not injected mid-run: that makes MAIN run again just to hear a remark. Absent: such a line
15318
+ * barges in as before. */
15319
+ noteTurn;
15320
+ /** Writes that immediate answer (fastWorkReply). */
15321
+ workReply;
15322
+ workReplyBudgetMs = 1500;
15284
15323
  /** Host TTS (fill lane): resolves when played; `false` = could not play. */
15285
15324
  speak = () => false;
15286
15325
  /** Stop the in-flight fill line now (barge-in only). */
@@ -15313,6 +15352,13 @@ var VoiceCallOptions = class {
15313
15352
  now = () => performance.now();
15314
15353
  /** An aside (aside()) needs this long since the last one — a cue answered every time sounds scripted. */
15315
15354
  asideGapMs = 8e3;
15355
+ /** After a turn went out, new words this soon are the same turn going on (it gives way to the fuller one), if MAIN has
15356
+ * not started. Later ones are a new thing said over the work. */
15357
+ resumeMs = 3e3;
15358
+ /** Progress waits while the user spoke this recently. */
15359
+ userQuietMs = 800;
15360
+ /** A progress line starts being written this long before it is due. */
15361
+ progressLeadMs = 1e3;
15316
15362
  };
15317
15363
  var VoiceCall = class {
15318
15364
  constructor(options) {
@@ -15348,7 +15394,7 @@ var VoiceCall = class {
15348
15394
  cancel: () => o.cancel(),
15349
15395
  now: o.now
15350
15396
  });
15351
- this.progress = new Progress({ ...o.mode === "live" ? { templates: {}, generateBudgetMs: 1500 } : {}, ...ai ? { generate: fastProgressGenerator(ai, o.fastModel, o.gender) } : {}, gender: o.gender, now: o.now, ...o.progress });
15397
+ 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 });
15352
15398
  this.judge = new OverlapJudge({ ...ai ? { model: overlapModelFor(ai) } : {}, now: o.now });
15353
15399
  this.gate = new TurnGate({
15354
15400
  now: o.now,
@@ -15375,6 +15421,7 @@ var VoiceCall = class {
15375
15421
  earlyHeard = null;
15376
15422
  // a fill line heard while that turn was still held
15377
15423
  progressTimer = null;
15424
+ lastUserAt = -Infinity;
15378
15425
  ended = false;
15379
15426
  get o() {
15380
15427
  return this.options;
@@ -15387,6 +15434,11 @@ var VoiceCall = class {
15387
15434
  get turn() {
15388
15435
  return this.cur && { id: this.cur.id, text: this.cur.text, running: this.cur.running };
15389
15436
  }
15437
+ /** MAIN is on this turn and has the floor to itself: nothing the user says now stops it, unless they ask it to. */
15438
+ get working() {
15439
+ const c = this.cur;
15440
+ return !!c && c.running && !c.closed && (!c.worded || c.open > 0);
15441
+ }
15390
15442
  /** The host STT's language (BCP-47): the current language until the user's words say otherwise. */
15391
15443
  setLanguage(tag) {
15392
15444
  const l = primaryLang(tag);
@@ -15399,13 +15451,16 @@ var VoiceCall = class {
15399
15451
  if (this.ended || !text.trim()) return;
15400
15452
  if (typeof aec === "boolean") this.fill.options.aec = aec;
15401
15453
  this.gate.speaking();
15402
- const c = this.cur;
15403
- if (this.o.mode === "live" && c?.running && !c.worded && newWords(text, c.text) >= 2) {
15454
+ this.lastUserAt = this.o.now();
15455
+ const c = this.cur, steers = !!this.o.noteTurn && this.working;
15456
+ const resumed = !steers || c.marks.mainFirst === void 0 && this.o.now() - c.at < this.o.resumeMs;
15457
+ if (this.o.mode === "live" && c?.running && !c.worded && resumed && newWords(text, c.text) >= 2) {
15404
15458
  log30.debug("user resumed before the reply \u2014 yielded");
15405
- this.barge();
15459
+ this.giveWay(c);
15406
15460
  this.gate.reopen(c.id);
15407
15461
  }
15408
15462
  this.follow(text);
15463
+ if (this.o.noteTurn && this.working) return;
15409
15464
  this.fill.onInterim(text);
15410
15465
  }
15411
15466
  /** STT final → TurnGate. `lastWordAgoMs`: how long ago the user's last word of it ended (the STT's word clock,
@@ -15464,6 +15519,8 @@ var VoiceCall = class {
15464
15519
  if (!c.streamed) {
15465
15520
  c.streamed = true;
15466
15521
  this.gate.replyStarted(c.id);
15522
+ }
15523
+ if (c.open <= 0) {
15467
15524
  this.progress.text();
15468
15525
  this.clearProgress();
15469
15526
  }
@@ -15472,9 +15529,17 @@ var VoiceCall = class {
15472
15529
  case "tool":
15473
15530
  c.marks.mainFirst ??= this.o.now();
15474
15531
  this.gate.replyStarted(c.id);
15475
- void this.onTool(c, ev.name ?? "", ev.args);
15532
+ c.open++;
15533
+ c.streamed = false;
15534
+ if (ev.name && !isPlumbing(ev.name)) {
15535
+ c.tool = ev.name;
15536
+ c.args = ev.args;
15537
+ }
15538
+ this.progress.tool();
15539
+ this.beat(c);
15476
15540
  return;
15477
15541
  case "tool_done":
15542
+ c.open = Math.max(0, c.open - 1);
15478
15543
  return;
15479
15544
  case "audio": {
15480
15545
  const at = this.o.now() + Math.max(0, inMs);
@@ -15496,11 +15561,28 @@ var VoiceCall = class {
15496
15561
  this.clearProgress();
15497
15562
  this.fill.onAgentState("idle");
15498
15563
  if (c.worded) this.close(c, "answered");
15564
+ if (c.next) {
15565
+ const next = c.next;
15566
+ c.next = void 0;
15567
+ this.onTurn(next);
15568
+ }
15499
15569
  return;
15500
15570
  }
15501
15571
  }
15502
15572
  /** The user barged in (hard): cut fill + MAIN audio (the host cuts its own), abort a running MAIN turn. */
15503
15573
  barge() {
15574
+ if (this.o.noteTurn && this.working) {
15575
+ this.fill.onBargeIn();
15576
+ try {
15577
+ this.o.cancel();
15578
+ } catch (e) {
15579
+ log30.warn(`cancel threw: ${e.message}`);
15580
+ }
15581
+ return;
15582
+ }
15583
+ this.giveWay();
15584
+ }
15585
+ giveWay(c = this.cur) {
15504
15586
  this.fill.onBargeIn();
15505
15587
  this.clearProgress();
15506
15588
  try {
@@ -15508,11 +15590,11 @@ var VoiceCall = class {
15508
15590
  } catch (e) {
15509
15591
  log30.warn(`cancel threw: ${e.message}`);
15510
15592
  }
15511
- if (this.cur?.running) {
15512
- this.cur.running = false;
15513
- this.o.abortTurn(this.cur.id);
15593
+ if (c?.running) {
15594
+ c.running = false;
15595
+ this.o.abortTurn(c.id);
15514
15596
  }
15515
- if (this.cur && !this.cur.worded) this.cur.end ??= "cut";
15597
+ if (c && !c.worded) c.end ??= "cut";
15516
15598
  }
15517
15599
  /** Soft barge-in: keep (a listener cue — no turn) or cut (→ barge()). */
15518
15600
  async overlap(text) {
@@ -15558,6 +15640,7 @@ var VoiceCall = class {
15558
15640
  if (l) this.fill.setLanguage(l, true);
15559
15641
  }
15560
15642
  onTurn(t) {
15643
+ if (this.o.noteTurn && this.o.workReply && t.kind !== "replace" && this.working && !isClosing(t.text)) return void this.overWork(this.cur, t);
15561
15644
  const now4 = this.o.now(), lastWord = this.lastWordAt !== null;
15562
15645
  const at = this.lastWordAt ?? this.firstFinalAt ?? now4;
15563
15646
  const finalAt = this.finalAt || now4;
@@ -15566,7 +15649,7 @@ var VoiceCall = class {
15566
15649
  if (this.cur) this.close(this.cur, t.replaces === this.cur.id ? "replaced" : void 0);
15567
15650
  this.follow(t.text);
15568
15651
  this.clearProgress();
15569
- this.cur = { id: t.id, text: t.text, at, finalAt, lastWord, running: true, streamed: false, sounded: false, worded: false, done: false, marks: { sent: now4 }, closed: false, due: turnIntent(t.text) !== "closer" };
15652
+ this.cur = { id: t.id, text: t.text, at, finalAt, lastWord, running: true, streamed: false, sounded: false, worded: false, done: false, marks: { sent: now4 }, closed: false, due: turnIntent(t.text) !== "closer", open: 0, tool: "", draft: "", drafting: false, draftAt: -Infinity };
15570
15653
  const early = this.earlyHeard;
15571
15654
  this.earlyHeard = null;
15572
15655
  if (early && early.at >= at) {
@@ -15604,6 +15687,7 @@ var VoiceCall = class {
15604
15687
  c.marks.fill = this.o.now();
15605
15688
  c.fillKind = kind;
15606
15689
  }
15690
+ if (c && kind === "bridge" && this.o.mode === "live" && echoesHeard(text, c.text)) this.beat(c);
15607
15691
  if (this.o.hostAudio) return r;
15608
15692
  this.lastAudibleAt = this.o.now();
15609
15693
  if (c && forTurn) {
@@ -15641,27 +15725,78 @@ var VoiceCall = class {
15641
15725
  for (const k of Object.keys(tl)) if (tl[k] === void 0) delete tl[k];
15642
15726
  this.o.onMetric({ name: "timeline", id: c.id, text: c.text, timeline: tl });
15643
15727
  }
15644
- async onTool(c, name, args) {
15645
- const lang = this.lang;
15646
- if (!lang || c.streamed) return;
15647
- const line = await this.progress.line(name, args, lang, this.o.mode === "live" ? c.text : "");
15648
- if (!line && this.o.mode === "live") this.o.onMetric({ name: "drop", id: c.id, kind: `no progress line: ${name}` });
15649
- if (!line || this.cur !== c || c.streamed || !c.running || this.lang !== lang) return;
15728
+ /** The user spoke while MAIN works: the fast model answers now, the words reach MAIN as a note, MAIN keeps going. */
15729
+ async overWork(c, t) {
15730
+ const at = this.o.now();
15731
+ this.firstFinalAt = null;
15732
+ this.lastWordAt = null;
15733
+ this.follow(t.text);
15734
+ queueMicrotask(() => this.gate.replyStarted(t.id));
15735
+ this.o.onMetric({ name: "turn", id: t.id, kind: "aside", text: t.text });
15736
+ const ac = new AbortController(), late = setTimeout(() => ac.abort(), this.o.workReplyBudgetMs), lang = this.lang;
15737
+ const raw = lang ? await this.o.workReply({ request: c.text, heard: t.text, tool: c.tool, hint: argsHint(c.args), lang, avoid: this.progress.recent }, ac.signal).catch((e) => {
15738
+ log30.warn(`work reply failed \u2014 MAIN only: ${e?.message ?? e}`);
15739
+ return "";
15740
+ }).finally(() => clearTimeout(late)) : "";
15741
+ const line = cleanWorkReply(raw, lang ?? ""), stop = /^\s*stop\s*:/i.test(raw), change = !line || /^\s*work\s*:/i.test(raw);
15742
+ 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.]`;
15743
+ if (line && !this.ended) {
15744
+ for (let i = 0; i < 8 && this.say(line, "aside") === false; i++) {
15745
+ if (i === 7) {
15746
+ this.o.onMetric({ name: "drop", id: t.id, kind: "aside unplayed", text: line });
15747
+ break;
15748
+ }
15749
+ await new Promise((r) => setTimeout(r, 250));
15750
+ }
15751
+ if (this.lastAudibleAt >= at) {
15752
+ this.progress.note(line);
15753
+ this.o.show(line, "aside");
15754
+ }
15755
+ } else if (!line) this.o.onMetric({ name: "drop", id: t.id, kind: "no aside line" });
15756
+ if (stop) {
15757
+ this.o.noteTurn(noted);
15758
+ c.next = void 0;
15759
+ if (this.working && this.cur === c) this.giveWay(c);
15760
+ return;
15761
+ }
15762
+ if (change && this.cur === c && c.running) {
15763
+ c.next = c.next ? { ...c.next, text: `${c.next.text} ${t.text}` } : { ...t, kind: "new" };
15764
+ return;
15765
+ }
15766
+ if (change) return this.onTurn({ ...t, kind: "new" });
15767
+ this.o.noteTurn(noted);
15768
+ }
15769
+ /** While MAIN's tools run: a progress line once nothing was heard for `silenceMs`, then every `gapMs`, written just ahead
15770
+ * so it plays on time. Ticks are local (no network) and stop with the turn. */
15771
+ beat(c) {
15650
15772
  this.clearProgress();
15651
- const tryNow = () => {
15773
+ const tick = () => {
15652
15774
  this.progressTimer = null;
15653
- if (this.ended || this.cur !== c || c.streamed || !c.running) return;
15654
- if (!this.progress.due(this.lastAudibleAt)) {
15655
- this.progressTimer = setTimeout(tryNow, 250);
15656
- return;
15775
+ if (this.ended || this.cur !== c || !c.running || c.streamed && c.open <= 0) return;
15776
+ const lang = this.lang, now4 = this.o.now();
15777
+ if (lang && !c.draft && !c.drafting && now4 - c.draftAt >= 1e3 && this.progress.due(this.lastAudibleAt, this.o.progressLeadMs)) {
15778
+ c.drafting = true;
15779
+ void this.progress.line(c.tool, c.args, lang, this.o.mode === "live" ? c.text : "").then((l) => {
15780
+ c.drafting = false;
15781
+ c.draft = l;
15782
+ if (!l) c.draftAt = this.o.now();
15783
+ if (!l && this.o.mode === "live") this.o.onMetric({ name: "drop", id: c.id, kind: `no progress line: ${c.tool}` });
15784
+ else sayDraft();
15785
+ });
15657
15786
  }
15658
- if (this.say(line, "progress") !== false) {
15659
- this.progress.spoke(line);
15787
+ sayDraft();
15788
+ this.progressTimer = setTimeout(tick, 250);
15789
+ };
15790
+ const sayDraft = () => {
15791
+ if (!c.draft || this.ended || this.cur !== c || !c.running || c.streamed && c.open <= 0 || this.o.now() - this.lastUserAt < this.o.userQuietMs || !this.progress.due(this.lastAudibleAt)) return;
15792
+ if (this.say(c.draft, "progress") !== false) {
15793
+ this.progress.spoke(c.draft);
15660
15794
  this.fill.covered();
15661
- this.o.show(line, "progress");
15795
+ this.o.show(c.draft, "progress");
15796
+ c.draft = "";
15662
15797
  }
15663
15798
  };
15664
- tryNow();
15799
+ tick();
15665
15800
  }
15666
15801
  clearProgress() {
15667
15802
  if (this.progressTimer) {
@@ -20883,6 +21018,7 @@ function parseArgs(argv) {
20883
21018
  if (a.duplex && a.plan) throw new Error("--plan is not supported in --duplex (workers are non-interactive; a plan could never be approved)");
20884
21019
  if (a.voiceSystemPrompt && !a.duplex) throw new Error("--voice-system-prompt only applies with --duplex");
20885
21020
  if (a.voicePersona && !a.duplex && !a.channelOnly) throw new Error("--voice-persona only applies with --call or --channel-only");
21021
+ if (a.call) process.env.ENABLE_TOOL_SEARCH ??= "false";
20886
21022
  if (a.voicePersona) process.env.AGENTX_CALL_PERSONA = a.voicePersona;
20887
21023
  if (a.call && a.inputFormat) throw new Error("--call is interactive (mic/TTS here); a headless host runs --channel-only");
20888
21024
  if (a.channelMode && !a.duplexV2 && !a.channelOnly && !a.call) throw new Error("--channel-mode only applies with --duplex-v2 or --channel-only");
@@ -22502,8 +22638,10 @@ async function repl(args, ai, cfg, cwd) {
22502
22638
  let callReplyOpen = false;
22503
22639
  let greetNote = "";
22504
22640
  const callTurns = /* @__PURE__ */ new Map();
22641
+ const callTools = /* @__PURE__ */ new Set();
22505
22642
  if (args.call) {
22506
22643
  if (args.voice || args.voicePersona) agent.options.systemPrompt += "\n\n" + (args.voicePersona ?? CALL_PROMPT);
22644
+ agent.options.systemPrompt += "\n\n" + CALL_WEB_PROMPT;
22507
22645
  if (args.voiceSystemPrompt) agent.options.systemPrompt += "\n\n" + args.voiceSystemPrompt;
22508
22646
  const fast = callFast(args, ai, cfg);
22509
22647
  for (const n of fast.notes) err(yellow(` \u26A0 ${n}
@@ -22519,7 +22657,16 @@ async function repl(args, ai, cfg, cwd) {
22519
22657
  },
22520
22658
  onMetric: (m) => voiceDiag?.push({ t: performance.now(), ...m, kind: `call_${m.name}`, ...m.kind ? { what: m.kind } : {} }),
22521
22659
  abortTurn: (id) => {
22522
- if (callTurns.get(id)?.running) activeTurn?.abort();
22660
+ if (callTurns.get(id)?.running) {
22661
+ voiceDiag?.push({ t: performance.now(), kind: "call_abort", id });
22662
+ activeTurn?.abort();
22663
+ }
22664
+ },
22665
+ noteTurn: (note) => {
22666
+ greetNote += `
22667
+
22668
+ ${note}`;
22669
+ voiceDiag?.push({ t: performance.now(), kind: "call_note", note });
22523
22670
  },
22524
22671
  sendTurn: (text, { id, replaces }) => {
22525
22672
  const old = replaces ? callTurns.get(replaces) : void 0;
@@ -22562,6 +22709,13 @@ async function repl(args, ai, cfg, cwd) {
22562
22709
  if (e.kind === "text_delta" && typeof e.message === "string") call.main({ type: "text", text: e.message });
22563
22710
  else if (e.kind === "tool_use") call.main({ type: "tool", name: String(e.name ?? ""), args: e.input });
22564
22711
  else if (e.kind === "tool_result") call.main({ type: "tool_done" });
22712
+ else if (e.kind === "tool_activity") {
22713
+ if (!callTools.has(e.id)) {
22714
+ callTools.add(e.id);
22715
+ call.main({ type: "tool", name: String(e.name ?? ""), args: e.input });
22716
+ }
22717
+ if (e.status !== "running") call.main({ type: "tool_done" });
22718
+ }
22565
22719
  if (e.kind === "text_delta" && voiceIO) {
22566
22720
  voiceReasonEnd();
22567
22721
  spinner.stop();
@@ -24236,7 +24390,7 @@ ${out}
24236
24390
  // Barge-in also parks any in-flight task's spoken delivery so a superseded topic can't keep talking
24237
24391
  // over the user's new one (debt-after-jokes regression) — the result still lands in the transcript.
24238
24392
  onBargeIn: (phase) => {
24239
- activeTurn?.abort();
24393
+ if (!call?.working) activeTurn?.abort();
24240
24394
  dx?.parkInFlightDeliveries();
24241
24395
  voiceReasonEnd();
24242
24396
  voiceEchoEnd();
@@ -24650,7 +24804,8 @@ function readPersona(file) {
24650
24804
  if (!text) throw new Error(`--voice-persona: ${file} is empty`);
24651
24805
  return text;
24652
24806
  }
24653
- var CALL_PROMPT = `This is a live VOICE call: your text is spoken aloud. Reply in the language of the user's last message. Open with one short sentence (it is spoken while you continue), then keep it brief and conversational \u2014 no markdown, lists, code or URLs read aloud. Short listener sounds ("mm-hm", "let me check\u2026") are played for you while you work; do not repeat or mention them.`;
24807
+ var CALL_PROMPT = `This is a live VOICE call: your text is spoken aloud. Reply in the language of the user's last message. Open with one short sentence (it is spoken while you continue), then keep it brief and conversational \u2014 no markdown, lists, code or URLs read aloud. When they react or push back ("what?", "are you serious?"), react first, like a person, then give the fact. Short listener sounds ("mm-hm", "let me check\u2026") are played for you while you work; do not repeat or mention them.`;
24808
+ var CALL_WEB_PROMPT = "For public web pages use WebSearch and WebFetch; touch the user's browser only when they ask for it.";
24654
24809
  var HOLD_RESUME_MS = 4e3;
24655
24810
  var leakDecider = () => voiceDecider();
24656
24811
  function makeSecondChannel(ai, reflexModel, mode = "normal", opts) {
@@ -24688,6 +24843,7 @@ function callFast(args, ai, cfg) {
24688
24843
  mode: args.channelMode,
24689
24844
  gender: args.voiceGender ?? "",
24690
24845
  progress: { generate: fastProgressGenerator(ai, line, args.voiceGender) },
24846
+ workReply: fastWorkReply(ai, line, args.voiceGender, args.voicePersona),
24691
24847
  channel: channelOptions(ai, line, args.voiceGender)
24692
24848
  } };
24693
24849
  }