agent.libx.js 0.93.8 → 0.93.11

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
@@ -1982,7 +1982,7 @@ IMPLICIT CAPTURE: when the user shares their name, role, a preference, a correct
1982
1982
  For explicit "remember X" requests, also call Remember directly and confirm briefly ("got it").
1983
1983
  Do NOT remember: transient task details, conversation filler, things you'd forget in a real conversation.
1984
1984
  Keep it invisible: never announce "saving to memory" or list what you remembered unless asked.
1985
- For anything requiring files, shell, or web \u2014 still Delegate.`;
1985
+ For anything requiring files, shell, or web \u2014 still Act.`;
1986
1986
  async function loadMemory(fs, dir, opts = {}) {
1987
1987
  const dirs = (Array.isArray(dir) ? dir : [dir]).filter(Boolean);
1988
1988
  const writeDir = dirs[0];
@@ -2691,6 +2691,10 @@ var AgentOptions = class {
2691
2691
  autoTest;
2692
2692
  /** Provider-specific options forwarded to ai.chat() (e.g. cursor mcpServers, cwd). */
2693
2693
  providerOptions;
2694
+ /** Prompt caching (providers that support it, e.g. Anthropic): cache tools/system/conversation
2695
+ * prefix across the loop's steps — reads cost 0.1x, writes 1.25x. A multi-step agent loop
2696
+ * re-sends its whole prefix every step, so this is a large net cost cut. Default on. */
2697
+ promptCache = true;
2694
2698
  /** Tool selection mode: 'auto' = model decides (needed for Groq); undefined = provider default. */
2695
2699
  toolChoice;
2696
2700
  /** Extended-thinking / reasoning effort, normalized across providers (anthropic, openai).
@@ -2880,7 +2884,7 @@ var Agent = class _Agent {
2880
2884
  const wireTools = toWireTools(this.activeTools);
2881
2885
  const useStream = o.stream === true && typeof o.host?.notify === "function";
2882
2886
  let steps = 0;
2883
- const usage = { promptTokens: 0, completionTokens: 0, totalTokens: 0 };
2887
+ const usage = { promptTokens: 0, completionTokens: 0, totalTokens: 0, cacheCreationTokens: 0, cacheReadTokens: 0 };
2884
2888
  let usageEstimated = false;
2885
2889
  const start = Date.now();
2886
2890
  let toolCallsTotal = 0;
@@ -2911,6 +2915,7 @@ var Agent = class _Agent {
2911
2915
  } : void 0;
2912
2916
  const reasonOpts = {
2913
2917
  ...frag,
2918
+ ...o.promptCache ? { promptCache: true } : {},
2914
2919
  ...o.providerOptions || cursorPo ? { providerOptions: { ...frag.providerOptions, ...o.providerOptions, ...cursorPo } } : {}
2915
2920
  };
2916
2921
  try {
@@ -2938,6 +2943,8 @@ var Agent = class _Agent {
2938
2943
  usage.promptTokens += res.usage.promptTokens ?? 0;
2939
2944
  usage.completionTokens += res.usage.completionTokens ?? 0;
2940
2945
  usage.totalTokens += res.usage.totalTokens ?? 0;
2946
+ usage.cacheCreationTokens += res.usage.cacheCreationTokens ?? 0;
2947
+ usage.cacheReadTokens += res.usage.cacheReadTokens ?? 0;
2941
2948
  }
2942
2949
  const toolCalls = res.toolCalls ?? [];
2943
2950
  this.transcript.push({
@@ -3506,15 +3513,18 @@ function describeCall(call) {
3506
3513
  return `${call.name}${hint}`;
3507
3514
  }
3508
3515
  var DuplexAgentOptions = class {
3509
- /** Any ai.libx.js AIClient — shared by the voice and worker agents (routed by model). */
3516
+ /** Any ai.libx.js AIClient — shared by all tiers (routed by model). */
3510
3517
  ai;
3511
- /** The WORKER's filesystem. If omitted the worker keeps Agent's jailed-disk-at-cwd default. */
3518
+ /** The WORKER's filesystem (act + think). If omitted the worker keeps Agent's jailed-disk-at-cwd default. */
3512
3519
  fs;
3513
- voiceModel = "groq/openai/gpt-oss-20b";
3514
- workerModel = "anthropic/claude-sonnet-4-6";
3520
+ reflexModel = "groq/openai/gpt-oss-20b";
3521
+ actModel = "anthropic/claude-sonnet-4-6";
3522
+ /** Premium reasoning model. Set to `false` to disable the Think tier entirely. */
3523
+ thinkModel = "anthropic/claude-opus-4-8";
3515
3524
  /** Escape hatches merged over the derived per-agent options. */
3516
- voiceOptions;
3517
- workerOptions;
3525
+ reflexOptions;
3526
+ actOptions;
3527
+ thinkOptions;
3518
3528
  /** Receives the voice text_delta stream + task lifecycle events. */
3519
3529
  host;
3520
3530
  /** How many recent transcript messages are rendered into a worker's brief. */
@@ -3522,7 +3532,7 @@ var DuplexAgentOptions = class {
3522
3532
  /** Voice register: 'neutral' = clean spoken style; 'conversational' = human-like — fillers,
3523
3533
  * backchannels, impulsive first reactions before content (mimics real duplex conversation). */
3524
3534
  voiceStyle = "neutral";
3525
- /** Awaited BEFORE a delegated worker spawns — open a per-task checkpoint frame, audit, etc.
3535
+ /** Awaited BEFORE a worker spawns — open a per-task checkpoint frame, audit, etc.
3526
3536
  * (post-spawn would race the worker's first edits). */
3527
3537
  onTaskStart;
3528
3538
  /** Re-voice throttled worker progress asides ('[task t1 progress] …') so long tasks aren't dead
@@ -3545,8 +3555,10 @@ var DuplexAgentOptions = class {
3545
3555
  /** User-scope memory dir for global facts (type=user/feedback). Forwarded to Remember's routing. */
3546
3556
  memoryUserDir;
3547
3557
  };
3548
- var VOICE_SYSTEM_PROMPT = 'You are a spoken voice assistant \u2014 the user HEARS everything you say. Use short sentences. One idea per sentence. No markdown, no bullet lists, no code blocks, no headings, no emoji.\nKeep turns SHORT \u2014 one to three sentences, then stop. Never lecture, enumerate cases, or add caveats unprompted. Conversation is a fast exchange: give the one thing asked, and let the user pull more if they want it.\nYou work in a pair: you talk, and a background worker with FULL access to the user\'s environment (files, shell, web) does the hands-on work. You can find out or do ANYTHING by calling `Delegate` with a clear, self-contained brief \u2014 so NEVER tell the user you can\'t see, access, or do something. Delegate and find out. When the user mentions their project, folder, files, or environment ("this project", "the current folder", "my code"), delegate IMMEDIATELY \u2014 do not ask for paths or details the worker can discover itself. Never pretend to have done the work or invent results \u2014 the worker\'s report is your only source.\nAfter calling Delegate, tell the user you are on it in one short sentence, then end your turn. Do not wait for the result.\nResults arrive later as events like "[task t1 completed] \u2026" or "[task t1 failed] \u2026". When one arrives, summarize it for the ear in one or two short sentences. "[task t1 progress] \u2026" events are interim status, NOT results \u2014 give at most a half-sentence aside ("still on it \u2014 running tests now") and end your turn. Never present progress as a finished result.\nNever read raw file paths, diffs, or code aloud verbatim.\n"[task t1 asks] \u2026" events are QUESTIONS from a background task \u2014 relay to the user in your own words, short, then end your turn. When the user answers, call `AnswerTask` with that id and their answer. NEVER answer on the user\'s behalf for permissions or risky operations; if their reply is ambiguous, confirm first.\nDo not fire a second Delegate for work already in flight \u2014 check `TaskStatus` first. Use `CancelTask` when the user asks to stop something.\nPRIORITY: when the user says goodbye or wants to end/finish/wrap up the session ("ok bye", "that\'s all", "let\'s finish", "let\'s end", "goodnight", "exit", "wrap up"), call `ExitSession` IMMEDIATELY \u2014 do not delegate, do not check status, just exit.\nFor TRIVIAL instant lookups only \u2014 current time, git branch, listing a folder, peeking at a small file \u2014 use `QuickLook` (instant, no task). Anything requiring searching, reasoning, running commands, or editing still goes through `Delegate`.\n{{MEMORY_SLOT}}\nUser messages may arrive via speech-to-text and can carry transcription artifacts \u2014 odd words, cut-offs, homophones ("for you" vs "folder"). Read for INTENT, not surface text. If a message seems garbled or surprising, briefly confirm what they meant ("did you mean\u2026?") instead of answering the literal words.';
3549
- var VOICE_STYLE_CONVERSATIONAL = `Speak like a person in a live conversation, not an assistant reading a script. React first, then deliver: a quick impulsive beat ("oh nice", "hmm, hold on", "ah, got it") before the substance. Use contractions always. Vary sentence length \u2014 some very short. Light fillers and backchannels are fine ("mm-hm", "right", "let's see") but at most one per reply \u2014 never stack them. When you delegate, say it like a human would ("hang on, let me actually dig into that \u2014 gimme a minute") instead of announcing a task. When a result comes back, react to it like you just found out ("okay so \u2014 turns out\u2026"). Match the user's energy: a quick question gets a quick answer \u2014 a few words is a perfectly good turn. Prefer a short answer plus an offer ("want the details?") over covering everything. Never narrate your own mechanics (no "I will now delegate", no task ids out loud).`;
3558
+ var VOICE_SYSTEM_PROMPT = 'You are a spoken voice assistant \u2014 the user HEARS everything you say. Use short sentences. One idea per sentence. No markdown, no bullet lists, no code blocks, no headings, no emoji.\nKeep turns SHORT \u2014 one to three sentences, then stop. Never lecture, enumerate cases, or add caveats unprompted. Conversation is a fast exchange: give the one thing asked, and let the user pull more if they want it.\nYou have three cognitive tiers \u2014 like a human brain:\n\u2022 YOU (reflex) \u2014 instant, lightweight. Handle greetings, simple questions, status checks, QuickLook.\n\u2022 `Act` \u2014 your hands. A standard background worker with FULL access to the user\'s environment (files, shell, web). Use for reading, editing, searching, running tasks, building \u2014 any real work.\n{{THINK_SLOT}}\nYou can find out or do ANYTHING by calling `Act` with a clear, self-contained brief \u2014 so NEVER tell the user you can\'t see, access, or do something. Act and find out. When the user mentions their project, folder, files, or environment ("this project", "the current folder", "my code"), call `Act` IMMEDIATELY \u2014 do not ask for paths or details the worker can discover itself. Never pretend to have done the work or invent results \u2014 the worker\'s report is your only source.\nAfter calling Act or Think, tell the user you are on it in one short sentence, then end your turn. Do not wait for the result.\nResults arrive later as events like "[task t1 completed] \u2026" or "[task t1 failed] \u2026". When one arrives, summarize it for the ear in one or two short sentences. "[task t1 progress] \u2026" events are interim status, NOT results \u2014 give at most a half-sentence aside ("still on it \u2014 running tests now") and end your turn. Never present progress as a finished result.\nNever read raw file paths, diffs, or code aloud verbatim.\n"[task t1 asks] \u2026" events are QUESTIONS from a background task \u2014 relay to the user in your own words, short, then end your turn. When the user answers, call `AnswerTask` with that id and their answer. NEVER answer on the user\'s behalf for permissions or risky operations; if their reply is ambiguous, confirm first.\nIf the user\'s message sounds INCOMPLETE \u2014 trailing off mid-sentence, a fragment that needs more context ("and then we", "but the problem is"), hesitation fillers ("uh", "um") \u2014 call `Hold` instead of answering. This keeps listening for the rest of their thought. Only respond with substance when you have a complete question or request.\nDispatch discipline: send ONE self-contained task per request \u2014 a single worker with the full brief beats several workers with fragments (each worker starts fresh and re-discovers context). NEVER dispatch a worker just to read files or gather information \u2014 workers explore and discover context themselves; pass on what you already know and let one worker do the whole job. Split into parallel tasks only when the user asks for genuinely independent things. When a task completes, report its result and stop \u2014 do NOT dispatch follow-up work (verification, polish, extras) the user did not ask for, unless the report itself signals failure or doubt.\nDo not fire a second Act/Think for work already in flight \u2014 check `TaskStatus` first. Use `CancelTask` when the user asks to stop something.\nPRIORITY: when the user says goodbye or wants to end/finish/wrap up the session ("ok bye", "that\'s all", "let\'s finish", "let\'s end", "goodnight", "exit", "wrap up"), call `ExitSession` IMMEDIATELY \u2014 do not act, do not check status, just exit.\nFor TRIVIAL instant lookups only \u2014 current time, git branch, listing a folder, peeking at a small file \u2014 use `QuickLook` (instant, no task). Anything requiring searching, reasoning, running commands, or editing goes through `Act`.\n{{MEMORY_SLOT}}\nUser messages may arrive via speech-to-text and can carry transcription artifacts \u2014 odd words, cut-offs, homophones ("for you" vs "folder"). Read for INTENT, not surface text. If a message seems garbled or surprising, briefly confirm what they meant ("did you mean\u2026?") instead of answering the literal words.';
3559
+ var THINK_GUIDANCE = "\u2022 `Think` \u2014 your brain. A premium reasoning model, FAR more expensive than Act. Reserve it for open-ended architecture/design questions, or a problem Act already FAILED at. ALL implementation work \u2014 coding, refactoring, debugging, edge cases, tests \u2014 goes to Act; Act is highly capable. Never send the same work to both.";
3560
+ var THINK_DISABLED_GUIDANCE = "(Think tier is not available \u2014 use Act for all escalations.)";
3561
+ var VOICE_STYLE_CONVERSATIONAL = `Speak like a person in a live conversation, not an assistant reading a script. React first, then deliver: a quick impulsive beat ("oh nice", "hmm, hold on", "ah, got it") before the substance. Use contractions always. Vary sentence length \u2014 some very short. Light fillers and backchannels are fine ("mm-hm", "right", "let's see") but at most one per reply \u2014 never stack them. When you escalate to Act or Think, say it like a human would ("hang on, let me actually dig into that \u2014 gimme a minute") instead of announcing a task. When a result comes back, react to it like you just found out ("okay so \u2014 turns out\u2026"). Match the user's energy: a quick question gets a quick answer \u2014 a few words is a perfectly good turn. Prefer a short answer plus an offer ("want the details?") over covering everything. Never narrate your own mechanics (no "I will now act", no task ids out loud).`;
3550
3562
  var DuplexAgent = class {
3551
3563
  options;
3552
3564
  voice;
@@ -3565,21 +3577,32 @@ var DuplexAgent = class {
3565
3577
  if (o.memoryDir && o.fs) {
3566
3578
  this.memoryReady = loadMemory(o.fs, o.memoryDir, { maxWritesPerSession: 10, userDir: o.memoryUserDir });
3567
3579
  }
3568
- const memSlot = o.memoryDir && o.fs ? VOICE_MEMORY_PROMPT : "NEVER claim to have stored, saved, or remembered something durably \u2014 you cannot. Anything the user wants persisted (their name, preferences, notes) must be Delegated so a worker writes it to memory.";
3569
- const prompt = VOICE_SYSTEM_PROMPT.replace("{{MEMORY_SLOT}}", memSlot) + (o.voiceStyle === "conversational" ? "\n" + VOICE_STYLE_CONVERSATIONAL : "") + `
3580
+ const memSlot = o.memoryDir && o.fs ? VOICE_MEMORY_PROMPT : "NEVER claim to have stored, saved, or remembered something durably \u2014 you cannot. Anything the user wants persisted (their name, preferences, notes) must go through Act so a worker writes it to memory.";
3581
+ const thinkSlot = o.thinkModel !== false ? THINK_GUIDANCE : THINK_DISABLED_GUIDANCE;
3582
+ const prompt = VOICE_SYSTEM_PROMPT.replace("{{MEMORY_SLOT}}", memSlot).replace("{{THINK_SLOT}}", thinkSlot) + (o.voiceStyle === "conversational" ? "\n" + VOICE_STYLE_CONVERSATIONAL : "") + `
3570
3583
  Today's date: ${(/* @__PURE__ */ new Date()).toDateString()}.`;
3584
+ const tools = [
3585
+ ...o.reflexOptions?.tools ?? [],
3586
+ this.actTool(),
3587
+ ...o.thinkModel !== false ? [this.thinkTool()] : [],
3588
+ this.taskStatusTool(),
3589
+ this.cancelTaskTool(),
3590
+ this.quickLookTool(),
3591
+ this.answerTaskTool(),
3592
+ this.holdTool()
3593
+ ];
3571
3594
  this.voice = new Agent({
3572
3595
  ai: o.ai,
3573
3596
  fs: new MemFilesystem2(),
3574
- model: o.voiceModel,
3597
+ model: o.reflexModel,
3575
3598
  stream: true,
3576
3599
  host: o.host,
3577
3600
  systemPrompt: prompt,
3578
3601
  instructionFiles: false,
3579
3602
  maxSteps: 8,
3580
3603
  timeoutMs: 3e4,
3581
- ...o.voiceOptions,
3582
- tools: [...o.voiceOptions?.tools ?? [], this.delegateTool(), this.taskStatusTool(), this.cancelTaskTool(), this.quickLookTool(), this.answerTaskTool()]
3604
+ ...o.reflexOptions,
3605
+ tools
3583
3606
  });
3584
3607
  }
3585
3608
  /** Resolve memory tools + inject index into voice system prompt (once). */
@@ -3590,7 +3613,7 @@ Today's date: ${(/* @__PURE__ */ new Date()).toDateString()}.`;
3590
3613
  this.voice.options.tools.push(...mem.tools);
3591
3614
  if (mem.index) this.voice.options.systemPrompt += "\n\n" + mem.index;
3592
3615
  }
3593
- /** One user turn: the voice agent streams the reply (and may Delegate). Serialized with re-voice turns. */
3616
+ /** One user turn: the voice agent streams the reply (and may Act/Think). Serialized with re-voice turns. */
3594
3617
  send(content) {
3595
3618
  return this.enqueue(async () => {
3596
3619
  await this.initMemory();
@@ -3631,19 +3654,25 @@ Today's date: ${(/* @__PURE__ */ new Date()).toDateString()}.`;
3631
3654
  this.notify("revoice_done", "");
3632
3655
  });
3633
3656
  }
3634
- /** The worker's brief: the Delegate args + a STATIC text snapshot of the recent conversation. */
3635
- buildBrief(brief) {
3657
+ /** The worker's brief: the Act/Think args + a STATIC text snapshot of the recent conversation.
3658
+ * Act briefs get a self-verify footer — the worker's report is trusted without review, so it
3659
+ * must check its own work before reporting (nearly free under prompt caching; measured honest:
3660
+ * it does NOT fix one-shot logic bugs — see mind/10). Think tasks are pure reasoning — no footer. */
3661
+ buildBrief(brief, tier = "act") {
3636
3662
  const recent = this.voice.transcript.filter((m) => (m.role === "user" || m.role === "assistant") && contentText(m.content).trim()).slice(-this.options.excerptTurns).map((m) => `${m.role}: ${contentText(m.content)}`).join("\n");
3637
- return recent ? `${brief}
3663
+ const verify = tier === "act" ? "\n\nBefore reporting done: re-read what you changed and check it against EVERY requirement above \u2014 fix any gap first. Your report is trusted without review." : "";
3664
+ return (recent ? `${brief}
3638
3665
 
3639
3666
  ## Recent conversation (for context)
3640
- ${recent}` : brief;
3667
+ ${recent}` : brief) + verify;
3641
3668
  }
3642
3669
  /** Spawn a detached worker for task `id`; its settlement notifies + enqueues the re-voice turn. */
3643
- spawnWorker(id, label, briefText) {
3670
+ spawnWorker(id, label, briefText, tier = "act") {
3644
3671
  const o = this.options;
3672
+ const tierOpts = tier === "think" ? o.thinkOptions : o.actOptions;
3673
+ const tierModel = tier === "think" ? o.thinkModel : o.actModel;
3645
3674
  const controller = new AbortController();
3646
- const base = o.workerOptions?.hooks;
3675
+ const base = tierOpts?.hooks ?? o.actOptions?.hooks;
3647
3676
  const report = o.progressUpdates ? this.progressReporter(id) : void 0;
3648
3677
  const hooks = report ? {
3649
3678
  ...base,
@@ -3670,13 +3699,12 @@ ${recent}` : brief;
3670
3699
  const worker = new Agent({
3671
3700
  ai: o.ai,
3672
3701
  fs: o.fs,
3673
- model: o.workerModel,
3674
- ...o.workerOptions,
3675
- // may override ai/fs/model/tools/… —
3702
+ model: tierModel,
3703
+ ...tier === "think" ? { reasoning: tierOpts?.reasoning ?? "high" } : {},
3704
+ ...tierOpts,
3676
3705
  ...workerHost ? { host: workerHost } : {},
3677
3706
  ...hooks ? { hooks } : {},
3678
3707
  signal: controller.signal
3679
- // …but never the per-task cancellation signal
3680
3708
  });
3681
3709
  const promise = worker.run(briefText).then((res) => this.onWorkerSettled(id, res)).catch((err2) => this.onWorkerFailed(id, err2));
3682
3710
  this.tasks.set(id, { id, label, status: "running", controller, promise });
@@ -3764,7 +3792,14 @@ ${recent}` : brief;
3764
3792
  }
3765
3793
  rec.status = "done";
3766
3794
  log6.verbose(`task ${id} done (${res.steps} steps)`);
3767
- this.notify("task_done", `task ${id} (${rec.label}) completed`, { id, text: res.text, usage: res.usage, usageEstimated: res.usageEstimated });
3795
+ this.notify("task_done", `task ${id} (${rec.label}) completed`, {
3796
+ id,
3797
+ text: res.text,
3798
+ usage: res.usage,
3799
+ usageEstimated: res.usageEstimated,
3800
+ steps: res.steps,
3801
+ toolCalls: res.messages.filter((m) => m.role === "tool").length
3802
+ });
3768
3803
  this.queueRevoice(`[task ${id} completed] ${res.text}`);
3769
3804
  }
3770
3805
  onWorkerFailed(id, err2) {
@@ -3777,11 +3812,32 @@ ${recent}` : brief;
3777
3812
  this.notify("task_error", `task ${rec.id} (${rec.label}) failed: ${msg}`);
3778
3813
  this.queueRevoice(`[task ${rec.id} failed] ${msg}`);
3779
3814
  }
3780
- // --- the three voice tools (closures over this instance) ---
3781
- delegateTool() {
3815
+ // --- voice tools (closures over this instance) ---
3816
+ /** Live-switch the think tier: `false` disables (removes the Think tool from the voice agent),
3817
+ * a model id enables (adds the tool if missing). The system-prompt THINK_SLOT text is frozen at
3818
+ * construction — the tool's own description carries the routing guidance, so a live enable works;
3819
+ * dispatch()'s think→act fallback covers any straggler calls after a live disable. */
3820
+ setThinkModel(model) {
3821
+ this.options.thinkModel = model;
3822
+ const tools = this.voice.options.tools;
3823
+ const i = tools.findIndex((t) => t.name === "Think");
3824
+ if (model === false && i >= 0) tools.splice(i, 1);
3825
+ else if (model !== false && i < 0) tools.push(this.thinkTool());
3826
+ }
3827
+ /** User/programmatic spawn: the CLI's /act and /think commands. Returns the task id. */
3828
+ async dispatch(brief, tier = "act", label) {
3829
+ if (tier === "think" && this.options.thinkModel === false) tier = "act";
3830
+ const id = `t${++this.seq}`;
3831
+ const lbl = label ?? tier;
3832
+ await this.options.onTaskStart?.(id, lbl);
3833
+ this.spawnWorker(id, lbl, this.buildBrief(brief, tier), tier);
3834
+ this.notify("task_started", `task ${id} (${lbl}) started`, { id, brief, tier });
3835
+ return id;
3836
+ }
3837
+ actTool() {
3782
3838
  return {
3783
- name: "Delegate",
3784
- description: 'Escalate real work (reading/editing files, searching, running tasks, deep analysis) to a background worker agent. Returns immediately with a task id; the result arrives later as a "[task <id> completed]" event. Provide a clear, self-contained `brief` (the worker does not hear the live conversation).',
3839
+ name: "Act",
3840
+ description: 'Escalate real work (reading/editing files, searching, running tasks, building) to a standard background worker. Returns immediately with a task id; the result arrives later as a "[task <id> completed]" event. Provide a clear, self-contained `brief` (the worker does not hear the live conversation).',
3785
3841
  parameters: {
3786
3842
  type: "object",
3787
3843
  required: ["brief"],
@@ -3791,12 +3847,26 @@ ${recent}` : brief;
3791
3847
  }
3792
3848
  },
3793
3849
  run: async ({ brief, label }) => {
3794
- const id = `t${++this.seq}`;
3795
- const lbl = String(label ?? "task");
3796
- await this.options.onTaskStart?.(id, lbl);
3797
- this.spawnWorker(id, lbl, this.buildBrief(String(brief ?? "")));
3798
- this.notify("task_started", `task ${id} (${lbl}) started`, { id, brief });
3799
- return `Delegated as task ${id}. Acknowledge briefly; the result will arrive as a [task ${id} completed] event.`;
3850
+ const id = await this.dispatch(String(brief ?? ""), "act", label ? String(label) : void 0);
3851
+ return `Acting on task ${id}. Acknowledge briefly; the result will arrive as a [task ${id} completed] event.`;
3852
+ }
3853
+ };
3854
+ }
3855
+ thinkTool() {
3856
+ return {
3857
+ name: "Think",
3858
+ description: "Escalate to a premium deep-reasoning agent for complex analysis, architecture decisions, hard debugging, or planning. Same async pattern as Act \u2014 returns a task id. Use when the problem needs careful thought before (or instead of) action. Do not use Think for simple tasks \u2014 Act is cheaper and faster.",
3859
+ parameters: {
3860
+ type: "object",
3861
+ required: ["brief"],
3862
+ properties: {
3863
+ brief: { type: "string", description: "the question or problem to reason about deeply" },
3864
+ label: { type: "string", description: "a short (2-4 word) label for the task" }
3865
+ }
3866
+ },
3867
+ run: async ({ brief, label }) => {
3868
+ const id = await this.dispatch(String(brief ?? ""), "think", label ? String(label) : void 0);
3869
+ return `Thinking on task ${id}. Acknowledge briefly; the result will arrive as a [task ${id} completed] event.`;
3800
3870
  }
3801
3871
  };
3802
3872
  }
@@ -3812,7 +3882,7 @@ ${recent}` : brief;
3812
3882
  }
3813
3883
  };
3814
3884
  }
3815
- /** Sub-100ms read-only lookups the voice may do itself — everything else stays Delegate-only.
3885
+ /** Sub-100ms read-only lookups the voice may do itself — everything else stays Act-only.
3816
3886
  * fs-only (no shell; the engine is VFS-abstracted): time, git branch (.git/HEAD read), ls, file
3817
3887
  * head. Output is hard-capped so a lookup can never bloat the skinny voice context. */
3818
3888
  quickLookTool() {
@@ -3820,7 +3890,7 @@ ${recent}` : brief;
3820
3890
  const kinds = [.../* @__PURE__ */ new Set(["time", "branch", "ls", "file", ...Object.keys(this.options.quickLook ?? {})])];
3821
3891
  return {
3822
3892
  name: "QuickLook",
3823
- description: `Instant read-only lookup \u2014 one of: ${kinds.join(", ")}. For trivial facts only; anything needing search, commands, or reasoning goes through Delegate.`,
3893
+ description: `Instant read-only lookup \u2014 one of: ${kinds.join(", ")}. For trivial facts only; anything needing search, commands, or reasoning goes through Act.`,
3824
3894
  parameters: {
3825
3895
  type: "object",
3826
3896
  required: ["what"],
@@ -3853,7 +3923,7 @@ ${recent}` : brief;
3853
3923
  if (!path) return "file lookup needs a path";
3854
3924
  const text = await fs.readFile(String(path));
3855
3925
  return text.length > CAP2 ? text.slice(0, CAP2) + `
3856
- \u2026 (truncated \u2014 ${text.length} chars total; Delegate for the full file)` : text;
3926
+ \u2026 (truncated \u2014 ${text.length} chars total; Act for the full file)` : text;
3857
3927
  }
3858
3928
  default:
3859
3929
  return `unknown lookup '${what}'`;
@@ -3881,6 +3951,22 @@ ${recent}` : brief;
3881
3951
  }
3882
3952
  };
3883
3953
  }
3954
+ holdTool() {
3955
+ return {
3956
+ name: "Hold",
3957
+ description: 'The user seems mid-thought \u2014 hold the turn (stay listening) instead of answering. Optionally pass a short filler ("mhm", "go on") to speak while waiting. Use when the message sounds incomplete, trailing off, or like they paused to think.',
3958
+ parameters: {
3959
+ type: "object",
3960
+ properties: {
3961
+ filler: { type: "string", description: 'optional short filler to speak ("mhm", "go on", "mm-hm")' }
3962
+ }
3963
+ },
3964
+ run: async ({ filler }) => {
3965
+ if (filler) this.notify("hold_filler", String(filler));
3966
+ return "Holding \u2014 listening for the rest of the user's thought. Do not respond further this turn.";
3967
+ }
3968
+ };
3969
+ }
3884
3970
  cancelTaskTool() {
3885
3971
  return {
3886
3972
  name: "CancelTask",
@@ -3965,6 +4051,14 @@ var VoiceEngineOptions = class {
3965
4051
  * letters, mid-thought pauses), the next utterance MERGES instead of dispatching a truncated one
3966
4052
  * ("E-L-Y." / "A."). Costs this much latency per turn; 0 disables. */
3967
4053
  utteranceMergeMs = 350;
4054
+ /** Extended merge window (ms) for utterances that look incomplete (trailing conjunction/filler).
4055
+ * Gives the user time to finish their thought without triggering a model call. */
4056
+ incompleteMergeMs = 1500;
4057
+ /** Filler phrase spoken when holding for an incomplete utterance ('' disables). */
4058
+ holdFiller = "";
4059
+ /** Called when the engine holds an incomplete utterance (host can render a visual cue). */
4060
+ onHold = () => {
4061
+ };
3968
4062
  /** heuristic (non-AEC) energy barge-in tuning */
3969
4063
  bargeRmsMult = 2;
3970
4064
  bargeRmsFloor = 500;
@@ -3978,7 +4072,7 @@ var VoiceEngineOptions = class {
3978
4072
  /** no new partial activity for this long while paused → resume, drop the interjection */
3979
4073
  overlapResumeMs = 700;
3980
4074
  };
3981
- var VoiceEngine = class {
4075
+ var VoiceEngine = class _VoiceEngine {
3982
4076
  options;
3983
4077
  state = "idle";
3984
4078
  stt;
@@ -4031,7 +4125,7 @@ var VoiceEngine = class {
4031
4125
  this.stt.onLevel = (rms) => this.handleLevel(rms);
4032
4126
  await Promise.all([this.tts.connect(), this.stt.start()]);
4033
4127
  this.setState("listening");
4034
- log7.info(`voice I/O up (${this.stt.usingAec ? "AEC" : "heuristic echo"} capture)`);
4128
+ log7.debug(`voice I/O up (${this.stt.usingAec ? "AEC" : "heuristic echo"} capture)`);
4035
4129
  }
4036
4130
  get usingAec() {
4037
4131
  return this.stt.usingAec;
@@ -4074,7 +4168,7 @@ var VoiceEngine = class {
4074
4168
  this.spokeDeltas = true;
4075
4169
  this.ackAt = now();
4076
4170
  }
4077
- this.turnStartAt = now();
4171
+ if (!this.turnStartAt) this.turnStartAt = now();
4078
4172
  this.setState("thinking");
4079
4173
  }
4080
4174
  speakDelta(text) {
@@ -4083,7 +4177,7 @@ var VoiceEngine = class {
4083
4177
  this.reply += text;
4084
4178
  for (const w of this.words(this.reply)) this.echoWords.add(w);
4085
4179
  this.tts.speak(text, true);
4086
- if (!this.spokeDeltas && this.turnStartAt) log7.info(`ttft: ${Math.round(now() - this.turnStartAt)}ms`);
4180
+ if (!this.spokeDeltas && this.turnStartAt) log7.debug(`ttft: ${Math.round(now() - this.turnStartAt)}ms`);
4087
4181
  this.spokeDeltas = true;
4088
4182
  this.setState("speaking");
4089
4183
  }
@@ -4104,7 +4198,7 @@ var VoiceEngine = class {
4104
4198
  }
4105
4199
  this.drainTimer = null;
4106
4200
  this.speaking = false;
4107
- if (this.turnStartAt) log7.info(`turn: ${Math.round(now() - this.turnStartAt)}ms (incl. playback)`);
4201
+ if (this.turnStartAt) log7.debug(`turn: ${Math.round(now() - this.turnStartAt)}ms (incl. playback)`);
4108
4202
  this.echoUntil = now() + 2500;
4109
4203
  if (!this.usingAec) this.stt.reset();
4110
4204
  this.setState("listening");
@@ -4127,6 +4221,13 @@ var VoiceEngine = class {
4127
4221
  this.lastInterrupted = null;
4128
4222
  return r;
4129
4223
  }
4224
+ /** Speak a short filler phrase without starting a model turn (stays in listening mode after). */
4225
+ speakFiller(text) {
4226
+ if (!text || this.speaking) return;
4227
+ this.beginSpeech();
4228
+ this.speakDelta(text);
4229
+ this.endSpeech();
4230
+ }
4130
4231
  /** barge-in: stop audio NOW, cancel generation, reset for the user's utterance */
4131
4232
  interrupt() {
4132
4233
  if (!this.speaking && !this.drainTimer) return;
@@ -4210,6 +4311,11 @@ var VoiceEngine = class {
4210
4311
  }
4211
4312
  if (!this.echoActive() || (this.usingAec ? this.genuine(text) : this.novelWords(text).length >= 1)) this.options.onPartial(text);
4212
4313
  }
4314
+ static TRAIL_RE = /(?:^|\s)(?:and|but|or|so|to|the|a|an|of|in|for|with|that|if|uh|um|like|about|from|into|on|is|are|was|were|,)$/i;
4315
+ /** The utterance sounds like the user paused mid-thought (trailing conjunction/filler/comma). */
4316
+ looksIncomplete(text) {
4317
+ return _VoiceEngine.TRAIL_RE.test(text.trim());
4318
+ }
4213
4319
  handleUtterance(text) {
4214
4320
  if (this.speaking && (this.ctxOpen || this.pausedAt) && this.overlapCapable) {
4215
4321
  this.stt.reset();
@@ -4226,6 +4332,17 @@ var VoiceEngine = class {
4226
4332
  }
4227
4333
  this.pendingUtt = this.pendingUtt ? `${this.pendingUtt} ${text}` : text;
4228
4334
  if (this.pendingTimer) clearTimeout(this.pendingTimer);
4335
+ if (this.options.incompleteMergeMs && this.looksIncomplete(this.pendingUtt)) {
4336
+ log7.verbose(`hold: incomplete utterance "${this.pendingUtt.slice(-40)}"`);
4337
+ this.options.onHold();
4338
+ if (this.options.holdFiller && !this.speaking) {
4339
+ this.beginSpeech();
4340
+ this.speakDelta(this.options.holdFiller);
4341
+ this.endSpeech();
4342
+ }
4343
+ this.pendingTimer = setTimeout(() => this.flushUtterance(), this.options.incompleteMergeMs);
4344
+ return;
4345
+ }
4229
4346
  if (!this.options.utteranceMergeMs || this.words(this.pendingUtt).length >= 4) return this.flushUtterance();
4230
4347
  this.pendingTimer = setTimeout(() => this.flushUtterance(), this.options.utteranceMergeMs);
4231
4348
  }
@@ -4236,7 +4353,10 @@ var VoiceEngine = class {
4236
4353
  }
4237
4354
  const text = this.pendingUtt;
4238
4355
  this.pendingUtt = "";
4239
- if (text) this.options.onUtterance(text);
4356
+ if (text) {
4357
+ this.turnStartAt = now();
4358
+ this.options.onUtterance(text);
4359
+ }
4240
4360
  }
4241
4361
  get overlapCapable() {
4242
4362
  return this.usingAec && this.options.overlapPause && !!this.player.pause && !!this.player.resume;
@@ -4377,7 +4497,7 @@ var SonioxSTT = class {
4377
4497
  this.endpointTimer = setInterval(() => {
4378
4498
  const combined = (this.finalText + this.partialText).trim();
4379
4499
  if (!combined || now2() - this.lastChangeAt < this.options.silenceEndpointMs) return;
4380
- if (this.firstTokenAt) log8.info(`stt: ${Math.round(now2() - this.firstTokenAt)}ms first-token\u2192silence-endpoint, "${combined.slice(0, 60)}"`);
4500
+ if (this.firstTokenAt) log8.debug(`stt: ${Math.round(now2() - this.firstTokenAt)}ms first-token\u2192silence-endpoint, "${combined.slice(0, 60)}"`);
4381
4501
  this.reset();
4382
4502
  this.onUtterance(combined, now2());
4383
4503
  }, 120);
@@ -4410,7 +4530,7 @@ var SonioxSTT = class {
4410
4530
  this.onPartial(combined);
4411
4531
  if (endpoint && this.finalText.trim()) {
4412
4532
  const utterance = this.finalText.trim();
4413
- if (this.firstTokenAt) log8.info(`stt: ${Math.round(now2() - this.firstTokenAt)}ms first-token\u2192endpoint, "${utterance.slice(0, 60)}"`);
4533
+ if (this.firstTokenAt) log8.debug(`stt: ${Math.round(now2() - this.firstTokenAt)}ms first-token\u2192endpoint, "${utterance.slice(0, 60)}"`);
4414
4534
  this.reset();
4415
4535
  this.onUtterance(utterance, now2());
4416
4536
  }
@@ -4441,7 +4561,7 @@ var CartesiaTTSOptions = class {
4441
4561
  /** 'apiKey' (server/CLI) → `api_key=` URL param; 'token' (browser, BE-minted) → `access_token=`. */
4442
4562
  authMode = "apiKey";
4443
4563
  };
4444
- var CartesiaTTS = class {
4564
+ var CartesiaTTS = class _CartesiaTTS {
4445
4565
  options;
4446
4566
  ws;
4447
4567
  ctxSeq = 0;
@@ -4451,6 +4571,12 @@ var CartesiaTTS = class {
4451
4571
  onDone = () => {
4452
4572
  };
4453
4573
  firstAudioAt = 0;
4574
+ /** Circuit breaker: consecutive error count + down flag. */
4575
+ consecutiveErrors = 0;
4576
+ down = false;
4577
+ probeTimer = null;
4578
+ static CB_THRESHOLD = 3;
4579
+ static CB_PROBE_MS = 3e4;
4454
4580
  constructor(options) {
4455
4581
  this.options = { ...new CartesiaTTSOptions(), ...options };
4456
4582
  }
@@ -4480,10 +4606,34 @@ var CartesiaTTS = class {
4480
4606
  const m = JSON.parse(String(ev.data));
4481
4607
  if (m.context_id && m.context_id !== this.ctxId) return;
4482
4608
  if (m.type === "chunk" && m.data) {
4609
+ this.consecutiveErrors = 0;
4610
+ if (this.down) {
4611
+ this.down = false;
4612
+ log9.info("TTS recovered");
4613
+ this.stopProbe();
4614
+ }
4483
4615
  if (!this.firstAudioAt) this.firstAudioAt = now3();
4484
4616
  this.onAudio(base64ToBytes(m.data));
4485
- } else if (m.type === "done") this.onDone();
4486
- else if (m.type === "error" && !/already been cancelled|does not exist/.test(m.message || "")) log9.warn(`cartesia: ${JSON.stringify(m)}`);
4617
+ } else if (m.type === "done") {
4618
+ this.consecutiveErrors = 0;
4619
+ if (this.down) {
4620
+ this.down = false;
4621
+ log9.info("TTS recovered");
4622
+ this.stopProbe();
4623
+ }
4624
+ this.onDone();
4625
+ } else if (m.type === "error") {
4626
+ if (/already been cancelled|does not exist/.test(m.message || "")) return;
4627
+ this.consecutiveErrors++;
4628
+ if (!this.down && this.consecutiveErrors >= _CartesiaTTS.CB_THRESHOLD) {
4629
+ this.down = true;
4630
+ log9.warn(`TTS circuit breaker open \u2014 ${this.consecutiveErrors} consecutive errors, switching to text-only`);
4631
+ this.onDone();
4632
+ this.startProbe();
4633
+ } else if (!this.down) {
4634
+ log9.warn(`cartesia: ${JSON.stringify(m)}`);
4635
+ }
4636
+ }
4487
4637
  };
4488
4638
  }
4489
4639
  /** Ensure the WS is open before sending — reconnects if idle-closed. */
@@ -4507,17 +4657,42 @@ var CartesiaTTS = class {
4507
4657
  });
4508
4658
  }
4509
4659
  speak(text, cont) {
4660
+ if (this.down) return;
4510
4661
  if (this.ws?.readyState === WebSocket.OPEN) this.ws.send(this.frame(text, cont));
4511
4662
  else void this.ensureConnected().then(() => this.ws?.readyState === WebSocket.OPEN && this.ws.send(this.frame(text, cont)));
4512
4663
  }
4513
4664
  end() {
4665
+ if (this.down) {
4666
+ this.onDone();
4667
+ return;
4668
+ }
4514
4669
  if (this.ws?.readyState === WebSocket.OPEN) this.ws.send(this.frame("", false));
4515
4670
  }
4516
4671
  cancel() {
4517
4672
  if (this.ws?.readyState === WebSocket.OPEN) this.ws.send(JSON.stringify({ context_id: this.ctxId, cancel: true }));
4518
4673
  }
4674
+ startProbe() {
4675
+ if (this.probeTimer) return;
4676
+ this.probeTimer = setInterval(() => {
4677
+ if (!this.down) {
4678
+ this.stopProbe();
4679
+ return;
4680
+ }
4681
+ this.consecutiveErrors = 0;
4682
+ this.newContext();
4683
+ if (this.ws?.readyState === WebSocket.OPEN) this.ws.send(this.frame(".", false));
4684
+ }, _CartesiaTTS.CB_PROBE_MS);
4685
+ this.probeTimer.unref?.();
4686
+ }
4687
+ stopProbe() {
4688
+ if (this.probeTimer) {
4689
+ clearInterval(this.probeTimer);
4690
+ this.probeTimer = null;
4691
+ }
4692
+ }
4519
4693
  close() {
4520
4694
  this.closed = true;
4695
+ this.stopProbe();
4521
4696
  if (this.ws) this.ws.onclose = null;
4522
4697
  this.ws?.close();
4523
4698
  }
@@ -7368,6 +7543,8 @@ function parseArgs(argv) {
7368
7543
  a.voice = true;
7369
7544
  a.duplex = true;
7370
7545
  } else if (x === "--voice-model") a.voiceModel = val(++i, x);
7546
+ else if (x === "--think-model") a.thinkModel = val(++i, x);
7547
+ else if (x === "--no-think") a.thinkModel = false;
7371
7548
  else if (x === "--allowedTools" || x === "--allowed-tools") a.allowedTools = val(++i, x).split(",").map((s) => s.trim()).filter(Boolean);
7372
7549
  else if (x === "--disallowedTools" || x === "--disallowed-tools") a.disallowedTools = val(++i, x).split(",").map((s) => s.trim()).filter(Boolean);
7373
7550
  else if (x === "--append-system-prompt") a.appendSystemPrompt = val(++i, x);
@@ -7390,6 +7567,7 @@ function parseArgs(argv) {
7390
7567
  if (a.duplex && (a.task || a.print)) throw new Error("--duplex is interactive-only (a conversational mode) \u2014 drop the task/-p");
7391
7568
  if (a.duplex && a.plan) throw new Error("--plan is not supported in --duplex (workers are non-interactive; a plan could never be approved)");
7392
7569
  if (a.voiceModel && !a.duplex) throw new Error("--voice-model only applies with --duplex");
7570
+ if (a.thinkModel !== void 0 && !a.duplex) throw new Error("--think-model/--no-think only apply with --duplex");
7393
7571
  return a;
7394
7572
  }
7395
7573
  var HELP = `agentx \u2014 agent.libx.js CLI
@@ -7426,6 +7604,8 @@ Flags:
7426
7604
  with SONIOX_API_KEY + CARTESIA_API_KEY(+VOICE_ID) set: real voice I/O \u2014 mic in,
7427
7605
  spoken replies out (echo-cancelled; speak over it to interrupt)
7428
7606
  --voice-model <id> with --duplex: the fast voice model (default groq/openai/gpt-oss-20b)
7607
+ --think-model <id> with --duplex: the premium deep-reasoning model (default anthropic/claude-opus-4-6)
7608
+ --no-think with --duplex: disable the Think tier (Act handles everything)
7429
7609
  --add-dir <path> mount another directory into the workspace (repeatable; disk mode only)
7430
7610
  --subagents allow the Task tool (spawn child agents)
7431
7611
  --reasoning <e> extended thinking: off|low|medium|high or a token budget (anthropic/openai)
@@ -7455,7 +7635,7 @@ Project instructions: ./AGENTS.md or ./CLAUDE.md are auto-loaded (scaffold with
7455
7635
  Auto-loaded from ./.agent/: commands/, skills/, memory/, agents/.
7456
7636
 
7457
7637
  REPL shortcuts: !<cmd> runs a shell command inline \xB7 #<note> saves a memory \xB7 @path inlines a file
7458
- REPL slash commands: /help /version /tools /permissions /status /cost /context /cwd /model /reasoning /config /rename /compact /rewind /undo /clear /sessions /resume /commands /skills /mcp /init /export /paste /goal /exit
7638
+ REPL slash commands: /help /version /tools /permissions /status /cost /context /cwd /model /reasoning /config /rename /compact /rewind /undo /clear /sessions /resume /commands /skills /mcp /init /export /paste /goal /exit (duplex: /act /think /voice-model /think-model)
7459
7639
  REPL completion: type / (commands+skills) or @ (files) for a LIVE menu \u2014 \u2191/\u2193 select, \u23CE/Tab accept, Esc dismiss.
7460
7640
  REPL multi-line: Option/Alt+Enter inserts a newline, or end a line with \\ to continue. Esc cancels a running turn / clears the input line; double-Esc jumps back to edit a previous message.
7461
7641
  REPL shortcuts: Shift+Tab cycles permission posture (ask \u2192 accept-edits \u2192 plan) \xB7 Alt+T toggles reasoning \xB7 Alt+P switches model \xB7 Ctrl+O toggles verbose tool output \xB7 \u2192 or Tab accepts the dim history ghost-suggestion \xB7 Alt+S/Ctrl+S stash/unstash.
@@ -7694,12 +7874,13 @@ function printHistory(messages) {
7694
7874
  const s = formatHistory(messages);
7695
7875
  if (s) err(s);
7696
7876
  }
7697
- function costOf(pricing, promptTokens = 0, completionTokens = 0) {
7877
+ function costOf(pricing, promptTokens = 0, completionTokens = 0, cacheCreationTokens = 0, cacheReadTokens = 0) {
7698
7878
  if (!pricing) return 0;
7699
- return promptTokens / 1e3 * pricing.inputCostPer1K + completionTokens / 1e3 * pricing.outputCostPer1K;
7879
+ const fresh = Math.max(0, promptTokens - cacheCreationTokens - cacheReadTokens);
7880
+ return fresh / 1e3 * pricing.inputCostPer1K + cacheCreationTokens / 1e3 * pricing.inputCostPer1K * 1.25 + cacheReadTokens / 1e3 * pricing.inputCostPer1K * 0.1 + completionTokens / 1e3 * pricing.outputCostPer1K;
7700
7881
  }
7701
7882
  function turnCost(model, usage) {
7702
- return costOf(getModelInfo(model)?.pricing, usage?.promptTokens ?? 0, usage?.completionTokens ?? 0);
7883
+ return costOf(getModelInfo(model)?.pricing, usage?.promptTokens ?? 0, usage?.completionTokens ?? 0, usage?.cacheCreationTokens ?? 0, usage?.cacheReadTokens ?? 0);
7703
7884
  }
7704
7885
  async function evaluateGoal(ai, condition, transcript, log17) {
7705
7886
  const recent = transcript.filter((m) => m.role === "assistant").slice(-8).map((m) => {
@@ -8172,12 +8353,21 @@ async function repl(args, ai, cfg, cwd) {
8172
8353
  const duplexAsk = async (call) => {
8173
8354
  if (args.voice && dx) {
8174
8355
  const hint = summarizeCall(call.name, call.args).slice(0, 80);
8175
- if (cfg.voiceAskUi === "menu") {
8356
+ if (cfg.voiceAskUi !== "relay") {
8176
8357
  editorRef?.suspend();
8177
- const v = await selectMenu(process.stderr, { title: `? background worker asks to run ${call.name} ${hint}`, items: [{ label: "Allow", value: "y" }, { label: "Deny", value: "n" }], current: "n" });
8358
+ const v = await selectMenu(process.stderr, {
8359
+ title: `? background worker asks to run ${call.name} ${hint}`,
8360
+ items: [{ label: "Allow once", value: "y" }, { label: "Allow always", value: "a" }, { label: "Deny", value: "n" }],
8361
+ current: "y"
8362
+ });
8178
8363
  editorRef?.resume();
8179
8364
  editorRef?.redrawNow();
8180
- return { decision: v === "y" ? "allow" : "deny" };
8365
+ if (v === "a") {
8366
+ const cmd = typeof call.args?.command === "string" ? call.args.command : null;
8367
+ work.permissions?.options.rules.unshift(cmd ? { tool: call.name, pathGlob: cmd, decision: "allow" } : { tool: call.name, decision: "allow" });
8368
+ persistRule(cwd, "allow", cmd ? `${call.name}(${cmd})` : call.name);
8369
+ }
8370
+ return { decision: v === "y" || v === "a" ? "allow" : "deny" };
8181
8371
  }
8182
8372
  const id = `perm-${++permSeq}`;
8183
8373
  const a = await dx.parkQuestion(id, `Permission: may the background worker run ${call.name}${hint ? ` (${hint})` : ""}? Answer yes or no (you can also type it).`);
@@ -8209,6 +8399,10 @@ async function repl(args, ai, cfg, cwd) {
8209
8399
  voiceIO.speakDelta(e.message);
8210
8400
  editorRef?.suspend();
8211
8401
  }
8402
+ if (e.kind === "hold_filler" && voiceIO) {
8403
+ voiceIO.speakFiller(e.message);
8404
+ return;
8405
+ }
8212
8406
  if (e.kind === "revoice_done") {
8213
8407
  base.flushText();
8214
8408
  process.stdout.write("\n");
@@ -8243,7 +8437,7 @@ async function repl(args, ai, cfg, cwd) {
8243
8437
  };
8244
8438
  const rewindFilesTool = {
8245
8439
  name: "RewindFiles",
8246
- description: "Undo file changes made by delegated tasks: roll back the last N task checkpoints (default 1). Use when the user asks to undo/revert what a task changed.",
8440
+ description: "Undo file changes made by Act/Think tasks: roll back the last N task checkpoints (default 1). Use when the user asks to undo/revert what a task changed.",
8247
8441
  parameters: { type: "object", properties: { steps: { type: "number", description: "how many task checkpoints to undo (default 1)" } } },
8248
8442
  run: async ({ steps }) => {
8249
8443
  if (!checkpoints.size) return "No file checkpoints to rewind yet.";
@@ -8259,9 +8453,10 @@ async function repl(args, ai, cfg, cwd) {
8259
8453
  fs: agent.options.fs,
8260
8454
  memoryDir: agent.options.memoryDir,
8261
8455
  memoryUserDir: agent.options.memoryUserDir,
8262
- ...args.voiceModel ?? cfg.voiceModel ? { voiceModel: resolveModelOrNewest(args.voiceModel ?? cfg.voiceModel) } : {},
8263
- workerModel: agent.options.model,
8264
- workerOptions,
8456
+ ...args.voiceModel ?? cfg.reflexModel ? { reflexModel: resolveModelOrNewest(args.voiceModel ?? cfg.reflexModel) } : {},
8457
+ actModel: agent.options.model,
8458
+ actOptions: workerOptions,
8459
+ ...(args.thinkModel ?? cfg.thinkModel) !== void 0 ? { thinkModel: (args.thinkModel ?? cfg.thinkModel) === false ? false : resolveModelOrNewest(String(args.thinkModel ?? cfg.thinkModel)) } : {},
8265
8460
  host,
8266
8461
  ...args.voice ? { voiceStyle: "conversational", progressUpdates: true, askRelay: true } : {},
8267
8462
  // voice: progress asides + worker questions relayed through the conversation
@@ -8296,8 +8491,8 @@ async function repl(args, ai, cfg, cwd) {
8296
8491
  }
8297
8492
  },
8298
8493
  // The voice runs on the REAL fs (it has no fs tools — harmless) so @mentions, !cmd and #note
8299
- // resolve against the project; + CC-parity chrome for its own tool calls (⚙ Delegate …).
8300
- voiceOptions: { fs: agent.options.fs, hooks: displayHooks(agent.options.fs), tools: [rewindFilesTool, exitSessionTool(() => {
8494
+ // resolve against the project; + CC-parity chrome for its own tool calls (⚙ Act …).
8495
+ reflexOptions: { fs: agent.options.fs, hooks: displayHooks(agent.options.fs), tools: [rewindFilesTool, exitSessionTool(() => {
8301
8496
  exitRequested = true;
8302
8497
  })] }
8303
8498
  });
@@ -8341,7 +8536,7 @@ async function repl(args, ai, cfg, cwd) {
8341
8536
  };
8342
8537
  const setModel = (m) => {
8343
8538
  work.model = m;
8344
- if (dx) dx.options.workerModel = m;
8539
+ if (dx) dx.options.actModel = m;
8345
8540
  persistModel(cwd, m);
8346
8541
  err(dim(" model \u2192 " + m + "\n"));
8347
8542
  };
@@ -8622,7 +8817,7 @@ ${extra}` : body);
8622
8817
  desc: "show CLI version + runtime",
8623
8818
  run: () => {
8624
8819
  const rt = process.versions.bun ? `bun ${process.versions.bun}` : `node ${process.versions.node}`;
8625
- err(` ${bold("agent.libx.js")} ${cyan("v" + VERSION)}${dim(` \xB7 ${duplex ? `voice ${dx.options.voiceModel} \xB7 worker ${work.model}` : work.model} \xB7 ${rt}`)}
8820
+ err(` ${bold("agent.libx.js")} ${cyan("v" + VERSION)}${dim(` \xB7 ${duplex ? `reflex ${dx.options.reflexModel} \xB7 act ${work.model}${dx.options.thinkModel !== false ? ` \xB7 think ${dx.options.thinkModel}` : ""}` : work.model} \xB7 ${rt}`)}
8626
8821
  `);
8627
8822
  }
8628
8823
  },
@@ -8652,7 +8847,7 @@ ${extra}` : body);
8652
8847
  const mode = args.vfs ? "sandbox (VFS \u2014 disk untouched)" : args.boddb ? `boddb (database workspace at ${args.boddb} \u2014 disk untouched)` : args.shell ? "disk + real /bin/sh" : "disk (full real FS, like Claude Code)";
8653
8848
  const pol = work.permissions;
8654
8849
  const perm = !pol ? "allow all (unattended)" : `${pol.options.rules.length} rule(s), default ${pol.options.default}`;
8655
- const model = duplex ? `voice ${dx.options.voiceModel} \xB7 worker ${work.model}` : work.model;
8850
+ const model = duplex ? `reflex ${dx.options.reflexModel} \xB7 act ${work.model}${dx.options.thinkModel !== false ? ` \xB7 think ${dx.options.thinkModel}` : ""}` : work.model;
8656
8851
  err(formatStatus({ model, cwd, mode, tools: (duplex ? work.tools ?? [] : agent.options.tools).map((t) => t.name), permissions: perm, turns: session.meta.turns, tokens: session.meta.tokens ?? 0, sessionId: session.meta.id, estimated: session.meta.costEstimated ?? false }));
8657
8852
  if (duplex && dx.tasks.size) err(dim(` tasks: ${[...dx.tasks.values()].map((t) => `${t.id}:${t.status}`).join(" ")}
8658
8853
  `));
@@ -8714,7 +8909,7 @@ ${extra}` : body);
8714
8909
  }
8715
8910
  const picked = await pickModel(work.model);
8716
8911
  if (picked) setModel(picked);
8717
- else err(dim(" " + (duplex ? `voice ${dx.options.voiceModel} \xB7 worker ${work.model}` : work.model) + "\n"));
8912
+ else err(dim(" " + (duplex ? `reflex ${dx.options.reflexModel} \xB7 act ${work.model}${dx.options.thinkModel !== false ? ` \xB7 think ${dx.options.thinkModel}` : ""}` : work.model) + "\n"));
8718
8913
  }
8719
8914
  },
8720
8915
  ...duplex ? { workers: {
@@ -8730,22 +8925,70 @@ ${extra}` : body);
8730
8925
  `));
8731
8926
  }
8732
8927
  }, "voice-model": {
8733
- desc: "switch the duplex voice (fast) model \u2014 /voice-model <id>, or alone for a picker",
8928
+ desc: "switch the reflex (voice) model \u2014 /voice-model <id>, or alone for a picker",
8734
8929
  run: async (a) => {
8735
8930
  const apply = (id) => {
8736
8931
  const m = resolveModelOrNewest(id);
8737
- dx.options.voiceModel = m;
8932
+ dx.options.reflexModel = m;
8738
8933
  dx.voice.options.model = m;
8739
- err(green(` \u2713 voice model \u2192 ${m}
8934
+ err(green(` \u2713 reflex model \u2192 ${m}
8740
8935
  `));
8741
8936
  };
8742
8937
  if (a[0]) {
8743
8938
  apply(a[0]);
8744
8939
  return;
8745
8940
  }
8746
- const picked = await pickModel(dx.options.voiceModel);
8941
+ const picked = await pickModel(dx.options.reflexModel);
8747
8942
  if (picked) apply(picked);
8748
- else err(dim(` voice ${dx.options.voiceModel}
8943
+ else err(dim(` reflex ${dx.options.reflexModel}
8944
+ `));
8945
+ }
8946
+ }, "think-model": {
8947
+ desc: "switch the think (premium) model, or /think-model off to disable",
8948
+ run: async (a) => {
8949
+ if (a[0] === "off" || a[0] === "false") {
8950
+ dx.setThinkModel(false);
8951
+ err(green(` \u2713 think tier disabled
8952
+ `));
8953
+ return;
8954
+ }
8955
+ const apply = (id) => {
8956
+ const m = resolveModelOrNewest(id);
8957
+ dx.setThinkModel(m);
8958
+ err(green(` \u2713 think model \u2192 ${m}
8959
+ `));
8960
+ };
8961
+ if (a[0]) {
8962
+ apply(a[0]);
8963
+ return;
8964
+ }
8965
+ const current = dx.options.thinkModel === false ? void 0 : dx.options.thinkModel;
8966
+ const picked = await pickModel(current ?? "anthropic/claude-opus-4-6");
8967
+ if (picked) apply(picked);
8968
+ else err(dim(` think ${dx.options.thinkModel === false ? "off" : dx.options.thinkModel}
8969
+ `));
8970
+ }
8971
+ }, act: {
8972
+ desc: "spawn a standard worker \u2014 /act <brief>",
8973
+ run: async (a) => {
8974
+ if (!a.length) {
8975
+ err(dim(" usage: /act <what to do>\n"));
8976
+ return;
8977
+ }
8978
+ const id = await dx.dispatch(a.join(" "), "act");
8979
+ err(dim(` \u2192 task ${id} started
8980
+ `));
8981
+ }
8982
+ }, think: {
8983
+ desc: "spawn a deep-reasoning worker \u2014 /think <question>",
8984
+ run: async (a) => {
8985
+ if (!a.length) {
8986
+ err(dim(" usage: /think <what to reason about>\n"));
8987
+ return;
8988
+ }
8989
+ const off = dx.options.thinkModel === false;
8990
+ const id = await dx.dispatch(a.join(" "), "think");
8991
+ err(dim(` \u2192 task ${id} ${off ? "(think tier off \u2014 running as act)" : "(think)"} started
8749
8992
  `));
8750
8993
  }
8751
8994
  } } : {},
@@ -9155,7 +9398,7 @@ ${extra}` : body);
9155
9398
  err(bold("agent.libx.js") + cyan(" v" + VERSION) + dim(` \u2014 ${work.model} \xB7 ${cwd}
9156
9399
  `));
9157
9400
  err(dim("Type a task, or /help. Type / or @ for live suggestions (\u2191/\u2193 \u23CE). Esc cancels/clears; double-Esc jumps back; Ctrl-D exits.\n"));
9158
- if (dx) err(dim(`\u25D1 duplex \u2014 voice: ${dx.options.voiceModel} \xB7 worker: ${work.model} (real work runs in background tasks, re-voiced when done)
9401
+ if (dx) err(dim(`\u25D1 duplex \u2014 reflex: ${dx.options.reflexModel} \xB7 act: ${work.model}${dx.options.thinkModel !== false ? ` \xB7 think: ${dx.options.thinkModel}` : ""} (real work runs in background tasks, re-voiced when done)
9159
9402
  `));
9160
9403
  const listDir = (absDir) => {
9161
9404
  try {
@@ -9473,7 +9716,32 @@ ${extra}` : body);
9473
9716
  } else if (running.length) {
9474
9717
  err(dim(` \u2026 waiting for ${running.length} background task(s) (Ctrl-C to force quit)
9475
9718
  `));
9476
- await dx.idle();
9719
+ let forced = false;
9720
+ let onCtrlC = () => {
9721
+ };
9722
+ const onByte = (b) => {
9723
+ if (!b.includes(3)) return;
9724
+ forced = true;
9725
+ for (const t of running) {
9726
+ t.status = "cancelled";
9727
+ t.controller.abort();
9728
+ }
9729
+ err(dim(`
9730
+ \u2026 force-quit \u2014 cancelled ${running.length} background task(s)
9731
+ `));
9732
+ onCtrlC();
9733
+ };
9734
+ process.stdin.on("data", onByte);
9735
+ await Promise.race([dx.idle(), new Promise((res) => {
9736
+ onCtrlC = res;
9737
+ })]);
9738
+ process.stdin.off("data", onByte);
9739
+ if (forced) {
9740
+ voiceIO?.stop();
9741
+ releaseStdin();
9742
+ await closeMcp(mounted);
9743
+ process.exit(130);
9744
+ }
9477
9745
  face.options.host?.flushText?.();
9478
9746
  duplexPersist();
9479
9747
  }