agent.libx.js 0.93.11 → 0.93.13
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/cli/cli.ts +21 -6
- package/dist/{Agent-Di1u5nH0.d.ts → Agent-kWrJvtZM.d.ts} +3 -0
- package/dist/cli.d.ts +12 -5
- package/dist/cli.js +92 -10
- package/dist/cli.js.map +1 -1
- package/dist/index.d.ts +20 -2
- package/dist/index.js +71 -6
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/cli/cli.ts
CHANGED
|
@@ -498,24 +498,39 @@ function printHistory(messages: Message[]): void {
|
|
|
498
498
|
if (s) err(s);
|
|
499
499
|
}
|
|
500
500
|
|
|
501
|
+
/** Cache-read/write price multipliers over the input rate, by provider (derived from the model
|
|
502
|
+
* prefix). Anthropic: write 1.25x / read 0.1x. OpenAI & Gemini auto-cache (no write surcharge),
|
|
503
|
+
* reads 0.5x / 0.25x. DeepSeek read 0.1x. Unknown → no discount (1x/1x, safe over-estimate). */
|
|
504
|
+
export function cacheMultipliers(model?: string): { read: number; write: number } {
|
|
505
|
+
const p = (model ?? '').split('/')[0];
|
|
506
|
+
switch (p) {
|
|
507
|
+
case 'anthropic': return { read: 0.1, write: 1.25 };
|
|
508
|
+
case 'openai': return { read: 0.5, write: 1 };
|
|
509
|
+
case 'google': return { read: 0.25, write: 1 };
|
|
510
|
+
case 'deepseek': return { read: 0.1, write: 1 };
|
|
511
|
+
default: return { read: 1, write: 1 };
|
|
512
|
+
}
|
|
513
|
+
}
|
|
514
|
+
|
|
501
515
|
/** USD cost from a model's per-1K pricing (ai.libx.js ModelPricing) + token usage. 0 if unpriced.
|
|
502
|
-
* Cache-aware: promptTokens includes cache reads/writes — priced at
|
|
503
|
-
* (
|
|
516
|
+
* Cache-aware: promptTokens includes cache reads/writes — priced at the provider's real multipliers
|
|
517
|
+
* (via `model`) so cached runs aren't overstated. Omitting `model` falls back to Anthropic's rates. */
|
|
504
518
|
export function costOf(
|
|
505
519
|
pricing: { inputCostPer1K: number; outputCostPer1K: number } | undefined,
|
|
506
|
-
promptTokens = 0, completionTokens = 0, cacheCreationTokens = 0, cacheReadTokens = 0,
|
|
520
|
+
promptTokens = 0, completionTokens = 0, cacheCreationTokens = 0, cacheReadTokens = 0, model?: string,
|
|
507
521
|
): number {
|
|
508
522
|
if (!pricing) return 0;
|
|
523
|
+
const mult = model ? cacheMultipliers(model) : { read: 0.1, write: 1.25 };
|
|
509
524
|
const fresh = Math.max(0, promptTokens - cacheCreationTokens - cacheReadTokens);
|
|
510
525
|
return (fresh / 1000) * pricing.inputCostPer1K
|
|
511
|
-
+ (cacheCreationTokens / 1000) * pricing.inputCostPer1K *
|
|
512
|
-
+ (cacheReadTokens / 1000) * pricing.inputCostPer1K *
|
|
526
|
+
+ (cacheCreationTokens / 1000) * pricing.inputCostPer1K * mult.write
|
|
527
|
+
+ (cacheReadTokens / 1000) * pricing.inputCostPer1K * mult.read
|
|
513
528
|
+ (completionTokens / 1000) * pricing.outputCostPer1K;
|
|
514
529
|
}
|
|
515
530
|
|
|
516
531
|
/** Cost of one turn at `model`'s rate (looks up ai.libx.js pricing). */
|
|
517
532
|
function turnCost(model: string, usage?: { promptTokens?: number; completionTokens?: number; cacheCreationTokens?: number; cacheReadTokens?: number }): number {
|
|
518
|
-
return costOf(getModelInfo(model)?.pricing, usage?.promptTokens ?? 0, usage?.completionTokens ?? 0, usage?.cacheCreationTokens ?? 0, usage?.cacheReadTokens ?? 0);
|
|
533
|
+
return costOf(getModelInfo(model)?.pricing, usage?.promptTokens ?? 0, usage?.completionTokens ?? 0, usage?.cacheCreationTokens ?? 0, usage?.cacheReadTokens ?? 0, model);
|
|
519
534
|
}
|
|
520
535
|
|
|
521
536
|
/** Evaluate whether a goal condition has been met, based on recent transcript. */
|
|
@@ -243,6 +243,9 @@ declare class AgentOptions {
|
|
|
243
243
|
instructionFiles: boolean | string[];
|
|
244
244
|
/** Host interaction channel (human-in-the-loop). If set: adds the `AskUserQuestion` tool. */
|
|
245
245
|
host?: HostBridge;
|
|
246
|
+
/** Add the `AskUserQuestion` tool when a host is present (default true). Set false for an agent that
|
|
247
|
+
* must never block a turn on a structured question — e.g. a voice reflex that confirms inline. */
|
|
248
|
+
askUserQuestion: boolean;
|
|
246
249
|
/** Deterministic interception points around tool execution (pre/post/stop). */
|
|
247
250
|
hooks?: Hooks;
|
|
248
251
|
/** If true: add the `Task` tool so the agent can spawn depth-limited child agents over the VFS. */
|
package/dist/cli.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env bun
|
|
2
|
-
import { h as RunResult, R as ReasoningEffort } from './Agent-
|
|
2
|
+
import { h as RunResult, R as ReasoningEffort } from './Agent-kWrJvtZM.js';
|
|
3
3
|
import { IFilesystem } from '@livx.cc/wcli/core';
|
|
4
4
|
import { M as Message, c as ContentPart } from './tools-GPWp7oXq.js';
|
|
5
5
|
|
|
@@ -107,13 +107,20 @@ declare function exportMarkdown(meta: {
|
|
|
107
107
|
costUsd?: number;
|
|
108
108
|
costEstimated?: boolean;
|
|
109
109
|
}, messages: Message[]): string;
|
|
110
|
+
/** Cache-read/write price multipliers over the input rate, by provider (derived from the model
|
|
111
|
+
* prefix). Anthropic: write 1.25x / read 0.1x. OpenAI & Gemini auto-cache (no write surcharge),
|
|
112
|
+
* reads 0.5x / 0.25x. DeepSeek read 0.1x. Unknown → no discount (1x/1x, safe over-estimate). */
|
|
113
|
+
declare function cacheMultipliers(model?: string): {
|
|
114
|
+
read: number;
|
|
115
|
+
write: number;
|
|
116
|
+
};
|
|
110
117
|
/** USD cost from a model's per-1K pricing (ai.libx.js ModelPricing) + token usage. 0 if unpriced.
|
|
111
|
-
* Cache-aware: promptTokens includes cache reads/writes — priced at
|
|
112
|
-
* (
|
|
118
|
+
* Cache-aware: promptTokens includes cache reads/writes — priced at the provider's real multipliers
|
|
119
|
+
* (via `model`) so cached runs aren't overstated. Omitting `model` falls back to Anthropic's rates. */
|
|
113
120
|
declare function costOf(pricing: {
|
|
114
121
|
inputCostPer1K: number;
|
|
115
122
|
outputCostPer1K: number;
|
|
116
|
-
} | undefined, promptTokens?: number, completionTokens?: number, cacheCreationTokens?: number, cacheReadTokens?: number): number;
|
|
123
|
+
} | undefined, promptTokens?: number, completionTokens?: number, cacheCreationTokens?: number, cacheReadTokens?: number, model?: string): number;
|
|
117
124
|
/** Format a USD amount: 2 decimals at $1+, 4 below (agent turns are sub-cent). */
|
|
118
125
|
declare function fmtUsd(n: number): string;
|
|
119
126
|
/** ~4 chars/token estimate over a transcript (matches the Agent's context-budget heuristic). */
|
|
@@ -192,4 +199,4 @@ declare function jsonResult(res: RunResult, session: SessionData): {
|
|
|
192
199
|
*/
|
|
193
200
|
declare function readMultiline(readLine: (continuing: boolean) => Promise<string | null>): Promise<string | null>;
|
|
194
201
|
|
|
195
|
-
export { type PermMode, appendMemoryNote, costOf, estimateTranscriptTokens, expandMentions, exportMarkdown, fmtUsd, formatHistory, formatStatus, jsonResult, parseArgs, pastePathClassifier, readImageParts, readMultiline, resolvePermMode, runShellLine };
|
|
202
|
+
export { type PermMode, appendMemoryNote, cacheMultipliers, costOf, estimateTranscriptTokens, expandMentions, exportMarkdown, fmtUsd, formatHistory, formatStatus, jsonResult, parseArgs, pastePathClassifier, readImageParts, readMultiline, resolvePermMode, runShellLine };
|
package/dist/cli.js
CHANGED
|
@@ -2661,6 +2661,9 @@ var AgentOptions = class {
|
|
|
2661
2661
|
instructionFiles = true;
|
|
2662
2662
|
/** Host interaction channel (human-in-the-loop). If set: adds the `AskUserQuestion` tool. */
|
|
2663
2663
|
host;
|
|
2664
|
+
/** Add the `AskUserQuestion` tool when a host is present (default true). Set false for an agent that
|
|
2665
|
+
* must never block a turn on a structured question — e.g. a voice reflex that confirms inline. */
|
|
2666
|
+
askUserQuestion = true;
|
|
2664
2667
|
/** Deterministic interception points around tool execution (pre/post/stop). */
|
|
2665
2668
|
hooks;
|
|
2666
2669
|
/** If true: add the `Task` tool so the agent can spawn depth-limited child agents over the VFS. */
|
|
@@ -2797,7 +2800,7 @@ var Agent = class _Agent {
|
|
|
2797
2800
|
if (catalog) systemPrompt += "\n\n" + catalog;
|
|
2798
2801
|
if (tool) tools = [...tools, tool];
|
|
2799
2802
|
}
|
|
2800
|
-
if (o.host) tools = [...tools, askUserQuestionTool];
|
|
2803
|
+
if (o.host && o.askUserQuestion) tools = [...tools, askUserQuestionTool];
|
|
2801
2804
|
if (o.subagents) {
|
|
2802
2805
|
let agents;
|
|
2803
2806
|
if (o.agentsDir) {
|
|
@@ -3525,6 +3528,11 @@ var DuplexAgentOptions = class {
|
|
|
3525
3528
|
reflexOptions;
|
|
3526
3529
|
actOptions;
|
|
3527
3530
|
thinkOptions;
|
|
3531
|
+
/** Fresh-context check on each successful Act task: a NEW agent (no self-confirmation bias) re-reads
|
|
3532
|
+
* the file state against the brief and fixes any gap before the result is re-voiced. Bounded to one
|
|
3533
|
+
* pass; ~2x Act cost so default OFF. The self-verify FOOTER (same context) was measured ineffective —
|
|
3534
|
+
* this is the structural fix (see mind/10). Think tasks are pure reasoning, never checked. */
|
|
3535
|
+
verifyActTasks = false;
|
|
3528
3536
|
/** Receives the voice text_delta stream + task lifecycle events. */
|
|
3529
3537
|
host;
|
|
3530
3538
|
/** How many recent transcript messages are rendered into a worker's brief. */
|
|
@@ -3555,7 +3563,7 @@ var DuplexAgentOptions = class {
|
|
|
3555
3563
|
/** User-scope memory dir for global facts (type=user/feedback). Forwarded to Remember's routing. */
|
|
3556
3564
|
memoryUserDir;
|
|
3557
3565
|
};
|
|
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
|
|
3566
|
+
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.\nCRITICAL: while a task is still running you have NO answer yet \u2014 never state a specific result of any kind (a number, size, count, name, path, or value). The real answer arrives ONLY in the "[task \u2026 completed]" event; inventing one meanwhile (a made-up disk size, commit count, etc.) is a serious error. Until then, only acknowledge and wait.\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, and NEVER spawn a second task to re-count, cross-check, or verify a result a worker already gave you \u2014 trust its answer; a single question gets ONE task. Call `TaskStatus` at most ONCE per turn; if a task is still running, just say "still on it" and end the turn \u2014 never poll it again and again in a loop. 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
3567
|
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
3568
|
var THINK_DISABLED_GUIDANCE = "(Think tier is not available \u2014 use Act for all escalations.)";
|
|
3561
3569
|
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).`;
|
|
@@ -3597,6 +3605,10 @@ Today's date: ${(/* @__PURE__ */ new Date()).toDateString()}.`;
|
|
|
3597
3605
|
model: o.reflexModel,
|
|
3598
3606
|
stream: true,
|
|
3599
3607
|
host: o.host,
|
|
3608
|
+
// The reflex IS the conversational channel — it confirms ambiguity inline ("did you mean…?"),
|
|
3609
|
+
// never via the blocking AskUserQuestion tool (Agent auto-adds it whenever a host is set). Left in,
|
|
3610
|
+
// it stalls a voice turn until the kill-switch. Worker questions still reach the user via parkQuestion.
|
|
3611
|
+
askUserQuestion: false,
|
|
3600
3612
|
systemPrompt: prompt,
|
|
3601
3613
|
instructionFiles: false,
|
|
3602
3614
|
maxSteps: 8,
|
|
@@ -3696,7 +3708,7 @@ ${recent}` : brief) + verify;
|
|
|
3696
3708
|
return a || "(no answer from the user \u2014 use your best judgment and note the assumption)";
|
|
3697
3709
|
};
|
|
3698
3710
|
const workerHost = o.askRelay ? { ask: relayAsk } : o.host?.ask ? { ask: (q2) => o.host.ask(q2) } : void 0;
|
|
3699
|
-
const
|
|
3711
|
+
const agentOpts = {
|
|
3700
3712
|
ai: o.ai,
|
|
3701
3713
|
fs: o.fs,
|
|
3702
3714
|
model: tierModel,
|
|
@@ -3705,10 +3717,46 @@ ${recent}` : brief) + verify;
|
|
|
3705
3717
|
...workerHost ? { host: workerHost } : {},
|
|
3706
3718
|
...hooks ? { hooks } : {},
|
|
3707
3719
|
signal: controller.signal
|
|
3708
|
-
|
|
3709
|
-
|
|
3720
|
+
// shared with the checker so a cancel tears down both
|
|
3721
|
+
};
|
|
3722
|
+
const promise = new Agent(agentOpts).run(briefText).then((res) => this.maybeVerify(id, briefText, res, tier, agentOpts)).then((res) => this.onWorkerSettled(id, res)).catch((err2) => this.onWorkerFailed(id, err2));
|
|
3710
3723
|
this.tasks.set(id, { id, label, status: "running", controller, promise });
|
|
3711
3724
|
}
|
|
3725
|
+
/** Fresh-context check of a successful Act task: a NEW agent (same model/fs/tools, but NO shared
|
|
3726
|
+
* conversation context) re-reads the file state against the brief and fixes any gap. The fix lands
|
|
3727
|
+
* on the shared fs automatically (workers write fs directly, no overlay), so grading sees the
|
|
3728
|
+
* corrected state. Bounded to ONE pass. Off unless `verifyActTasks`; never runs for think/failed/
|
|
3729
|
+
* cancelled tasks. Usage is merged so /cost reflects the real (worker + checker) spend. */
|
|
3730
|
+
async maybeVerify(id, briefText, res, tier, agentOpts) {
|
|
3731
|
+
if (!this.options.verifyActTasks || tier !== "act" || res.finishReason !== "stop") return res;
|
|
3732
|
+
if (this.tasks.get(id)?.status === "cancelled") return res;
|
|
3733
|
+
const checkBrief = `${briefText}
|
|
3734
|
+
|
|
3735
|
+
## VERIFY MODE
|
|
3736
|
+
Another agent just implemented the above. Independently check the CURRENT state of the files against EVERY requirement. Fix any gap you find. If everything is already correct, make NO changes \u2014 do not refactor or improve \u2014 and report "verified".`;
|
|
3737
|
+
this.notify("task_verify", `task ${id}: verifying`, { id });
|
|
3738
|
+
const cres = await new Agent(agentOpts).run(checkBrief);
|
|
3739
|
+
if (cres.finishReason !== "stop") {
|
|
3740
|
+
log6.warn(`task ${id}: verify inconclusive (${cres.finishReason})`);
|
|
3741
|
+
this.notify("task_verify", `task ${id}: verify inconclusive (${cres.finishReason})`, { id, finishReason: cres.finishReason });
|
|
3742
|
+
}
|
|
3743
|
+
const sum = (a = 0, b = 0) => a + b;
|
|
3744
|
+
return {
|
|
3745
|
+
...res,
|
|
3746
|
+
steps: res.steps + cres.steps,
|
|
3747
|
+
// Merge the checker's messages so downstream tool-call/step accounting includes BOTH agents
|
|
3748
|
+
// (else a verified task's toolCalls would undercount vs its steps/usage).
|
|
3749
|
+
messages: [...res.messages, ...cres.messages],
|
|
3750
|
+
usageEstimated: res.usageEstimated || cres.usageEstimated,
|
|
3751
|
+
usage: res.usage && cres.usage ? {
|
|
3752
|
+
promptTokens: sum(res.usage.promptTokens, cres.usage.promptTokens),
|
|
3753
|
+
completionTokens: sum(res.usage.completionTokens, cres.usage.completionTokens),
|
|
3754
|
+
totalTokens: sum(res.usage.totalTokens, cres.usage.totalTokens),
|
|
3755
|
+
cacheCreationTokens: sum(res.usage.cacheCreationTokens, cres.usage.cacheCreationTokens),
|
|
3756
|
+
cacheReadTokens: sum(res.usage.cacheReadTokens, cres.usage.cacheReadTokens)
|
|
3757
|
+
} : res.usage ?? cres.usage
|
|
3758
|
+
};
|
|
3759
|
+
}
|
|
3712
3760
|
/** Throttled per-task progress: worker tool calls → at most one progress re-voice per interval.
|
|
3713
3761
|
* Two sources, one throttle: completed steps (post) and a heartbeat for a SINGLE long tool call
|
|
3714
3762
|
* (pre records the in-flight call; a self-cleaning timer narrates "still inside Bash — 70s").
|
|
@@ -4071,6 +4119,12 @@ var VoiceEngineOptions = class {
|
|
|
4071
4119
|
overlapPause = true;
|
|
4072
4120
|
/** no new partial activity for this long while paused → resume, drop the interjection */
|
|
4073
4121
|
overlapResumeMs = 700;
|
|
4122
|
+
/** A genuine barge over a LONG reply is defeated by the dominant-novel gate: Meet echoes our own
|
|
4123
|
+
* speech back, so the partial is mostly our words + a few of hers → never "dominant novel" → it
|
|
4124
|
+
* resumes (replaying old audio — the audible "completes the buffer" blip) instead of ceding.
|
|
4125
|
+
* Mechanism-based discriminator: a re-PAUSE this soon after a resume = a persistent human, not an
|
|
4126
|
+
* echo blip (which pauses once and stalls). Cede on the re-pause regardless of the novel gate. */
|
|
4127
|
+
overlapRepauseCedeMs = 1500;
|
|
4074
4128
|
};
|
|
4075
4129
|
var VoiceEngine = class _VoiceEngine {
|
|
4076
4130
|
options;
|
|
@@ -4103,6 +4157,8 @@ var VoiceEngine = class _VoiceEngine {
|
|
|
4103
4157
|
lastInterrupted = null;
|
|
4104
4158
|
// overlap (pause) tier state — AEC + pause-capable sinks only
|
|
4105
4159
|
pausedAt = 0;
|
|
4160
|
+
lastResumeAt = 0;
|
|
4161
|
+
// when the overlap last resumed from a false alarm — a quick re-pause cedes
|
|
4106
4162
|
lastOverlapPartial = "";
|
|
4107
4163
|
// change-detection: only NEW partial text counts as activity
|
|
4108
4164
|
resumeTimer = null;
|
|
@@ -4236,6 +4292,7 @@ var VoiceEngine = class _VoiceEngine {
|
|
|
4236
4292
|
this.drainTimer = null;
|
|
4237
4293
|
}
|
|
4238
4294
|
this.resetOverlap(false);
|
|
4295
|
+
this.lastResumeAt = 0;
|
|
4239
4296
|
const heardChars = Math.round(Math.max(0, this.player.playedMs()) / 1e3 * 15);
|
|
4240
4297
|
if (this.reply) this.lastInterrupted = { full: this.reply, heard: this.reply.slice(0, heardChars) };
|
|
4241
4298
|
this.speaking = false;
|
|
@@ -4287,6 +4344,11 @@ var VoiceEngine = class _VoiceEngine {
|
|
|
4287
4344
|
if (!this.pausedAt) {
|
|
4288
4345
|
this.pausedAt = now();
|
|
4289
4346
|
this.player.pause();
|
|
4347
|
+
if (this.lastResumeAt && now() - this.lastResumeAt < this.options.overlapRepauseCedeMs) {
|
|
4348
|
+
this.interrupt();
|
|
4349
|
+
this.options.onBargeIn(this.ctxOpen ? "speaking" : "drain");
|
|
4350
|
+
return;
|
|
4351
|
+
}
|
|
4290
4352
|
}
|
|
4291
4353
|
if (this.genuine(txt) && this.words(txt).length >= 2) {
|
|
4292
4354
|
const phase = this.ctxOpen ? "speaking" : "drain";
|
|
@@ -4375,7 +4437,10 @@ var VoiceEngine = class _VoiceEngine {
|
|
|
4375
4437
|
clearTimeout(this.resumeTimer);
|
|
4376
4438
|
this.resumeTimer = null;
|
|
4377
4439
|
}
|
|
4378
|
-
if (this.pausedAt && resume)
|
|
4440
|
+
if (this.pausedAt && resume) {
|
|
4441
|
+
this.player.resume?.();
|
|
4442
|
+
this.lastResumeAt = now();
|
|
4443
|
+
}
|
|
4379
4444
|
this.pausedAt = 0;
|
|
4380
4445
|
this.lastOverlapPartial = "";
|
|
4381
4446
|
this.gatePassTimes = [];
|
|
@@ -5130,7 +5195,7 @@ import { existsSync as existsSync2, mkdirSync as mkdirSync2 } from "fs";
|
|
|
5130
5195
|
import { platform, arch, release, userInfo, homedir } from "os";
|
|
5131
5196
|
init_tools_shell();
|
|
5132
5197
|
import { BodDB as BodDB2 } from "@bod.ee/db";
|
|
5133
|
-
var DEFAULT_TOOLS = ["bash", "Read", "Edit", "Write", "Grep", "Glob", "MultiEdit", "TodoWrite"];
|
|
5198
|
+
var DEFAULT_TOOLS = ["bash", "Read", "Edit", "Write", "Grep", "Glob", "MultiEdit", "ApplyEdits", "RepoMap", "TodoWrite"];
|
|
5134
5199
|
function autoWebTools() {
|
|
5135
5200
|
const tools = [];
|
|
5136
5201
|
tools.push("WebFetch");
|
|
@@ -7874,13 +7939,29 @@ function printHistory(messages) {
|
|
|
7874
7939
|
const s = formatHistory(messages);
|
|
7875
7940
|
if (s) err(s);
|
|
7876
7941
|
}
|
|
7877
|
-
function
|
|
7942
|
+
function cacheMultipliers(model) {
|
|
7943
|
+
const p = (model ?? "").split("/")[0];
|
|
7944
|
+
switch (p) {
|
|
7945
|
+
case "anthropic":
|
|
7946
|
+
return { read: 0.1, write: 1.25 };
|
|
7947
|
+
case "openai":
|
|
7948
|
+
return { read: 0.5, write: 1 };
|
|
7949
|
+
case "google":
|
|
7950
|
+
return { read: 0.25, write: 1 };
|
|
7951
|
+
case "deepseek":
|
|
7952
|
+
return { read: 0.1, write: 1 };
|
|
7953
|
+
default:
|
|
7954
|
+
return { read: 1, write: 1 };
|
|
7955
|
+
}
|
|
7956
|
+
}
|
|
7957
|
+
function costOf(pricing, promptTokens = 0, completionTokens = 0, cacheCreationTokens = 0, cacheReadTokens = 0, model) {
|
|
7878
7958
|
if (!pricing) return 0;
|
|
7959
|
+
const mult = model ? cacheMultipliers(model) : { read: 0.1, write: 1.25 };
|
|
7879
7960
|
const fresh = Math.max(0, promptTokens - cacheCreationTokens - cacheReadTokens);
|
|
7880
|
-
return fresh / 1e3 * pricing.inputCostPer1K + cacheCreationTokens / 1e3 * pricing.inputCostPer1K *
|
|
7961
|
+
return fresh / 1e3 * pricing.inputCostPer1K + cacheCreationTokens / 1e3 * pricing.inputCostPer1K * mult.write + cacheReadTokens / 1e3 * pricing.inputCostPer1K * mult.read + completionTokens / 1e3 * pricing.outputCostPer1K;
|
|
7881
7962
|
}
|
|
7882
7963
|
function turnCost(model, usage) {
|
|
7883
|
-
return costOf(getModelInfo(model)?.pricing, usage?.promptTokens ?? 0, usage?.completionTokens ?? 0, usage?.cacheCreationTokens ?? 0, usage?.cacheReadTokens ?? 0);
|
|
7964
|
+
return costOf(getModelInfo(model)?.pricing, usage?.promptTokens ?? 0, usage?.completionTokens ?? 0, usage?.cacheCreationTokens ?? 0, usage?.cacheReadTokens ?? 0, model);
|
|
7884
7965
|
}
|
|
7885
7966
|
async function evaluateGoal(ai, condition, transcript, log17) {
|
|
7886
7967
|
const recent = transcript.filter((m) => m.role === "assistant").slice(-8).map((m) => {
|
|
@@ -9842,6 +9923,7 @@ if (import.meta.main) main().catch((e) => {
|
|
|
9842
9923
|
});
|
|
9843
9924
|
export {
|
|
9844
9925
|
appendMemoryNote,
|
|
9926
|
+
cacheMultipliers,
|
|
9845
9927
|
costOf,
|
|
9846
9928
|
estimateTranscriptTokens,
|
|
9847
9929
|
expandMentions,
|