agent.libx.js 0.93.11 → 0.93.12
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 +74 -9
- package/dist/cli.js.map +1 -1
- package/dist/index.d.ts +13 -2
- package/dist/index.js +53 -5
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { a as AgentOptions, H as Hooks, h as RunResult, A as Agent } from './Agent-
|
|
2
|
-
export { C as ChatFragment, D as DEFAULT_MUTATING, b as Decision, P as PermissionOptions, c as PermissionPolicy, d as PermissionRule, e as PreToolUseDecision, R as ReasoningEffort, f as RecordingHooks, g as RecordingLifecycle, T as ToolUse, i as ToolUseMeta, j as composeHooks, p as planMode, r as reasoningToChatFragment } from './Agent-
|
|
1
|
+
import { a as AgentOptions, H as Hooks, h as RunResult, A as Agent } from './Agent-kWrJvtZM.js';
|
|
2
|
+
export { C as ChatFragment, D as DEFAULT_MUTATING, b as Decision, P as PermissionOptions, c as PermissionPolicy, d as PermissionRule, e as PreToolUseDecision, R as ReasoningEffort, f as RecordingHooks, g as RecordingLifecycle, T as ToolUse, i as ToolUseMeta, j as composeHooks, p as planMode, r as reasoningToChatFragment } from './Agent-kWrJvtZM.js';
|
|
3
3
|
import { IFilesystem, FileMetadata } from '@livx.cc/wcli/core';
|
|
4
4
|
export { CommandExecutor, FileMetadata, IFilesystem, IndexedDbFilesystem, MemFilesystem, registerHeadlessCommands } from '@livx.cc/wcli/core';
|
|
5
5
|
import { BodDB } from '@bod.ee/db';
|
|
@@ -610,6 +610,11 @@ declare class DuplexAgentOptions {
|
|
|
610
610
|
reflexOptions?: Partial<AgentOptions>;
|
|
611
611
|
actOptions?: Partial<AgentOptions>;
|
|
612
612
|
thinkOptions?: Partial<AgentOptions>;
|
|
613
|
+
/** Fresh-context check on each successful Act task: a NEW agent (no self-confirmation bias) re-reads
|
|
614
|
+
* the file state against the brief and fixes any gap before the result is re-voiced. Bounded to one
|
|
615
|
+
* pass; ~2x Act cost so default OFF. The self-verify FOOTER (same context) was measured ineffective —
|
|
616
|
+
* this is the structural fix (see mind/10). Think tasks are pure reasoning, never checked. */
|
|
617
|
+
verifyActTasks: boolean;
|
|
613
618
|
/** Receives the voice text_delta stream + task lifecycle events. */
|
|
614
619
|
host?: HostBridge;
|
|
615
620
|
/** How many recent transcript messages are rendered into a worker's brief. */
|
|
@@ -681,6 +686,12 @@ declare class DuplexAgent {
|
|
|
681
686
|
private buildBrief;
|
|
682
687
|
/** Spawn a detached worker for task `id`; its settlement notifies + enqueues the re-voice turn. */
|
|
683
688
|
private spawnWorker;
|
|
689
|
+
/** Fresh-context check of a successful Act task: a NEW agent (same model/fs/tools, but NO shared
|
|
690
|
+
* conversation context) re-reads the file state against the brief and fixes any gap. The fix lands
|
|
691
|
+
* on the shared fs automatically (workers write fs directly, no overlay), so grading sees the
|
|
692
|
+
* corrected state. Bounded to ONE pass. Off unless `verifyActTasks`; never runs for think/failed/
|
|
693
|
+
* cancelled tasks. Usage is merged so /cost reflects the real (worker + checker) spend. */
|
|
694
|
+
private maybeVerify;
|
|
684
695
|
/** Throttled per-task progress: worker tool calls → at most one progress re-voice per interval.
|
|
685
696
|
* Two sources, one throttle: completed steps (post) and a heartbeat for a SINGLE long tool call
|
|
686
697
|
* (pre records the in-flight call; a self-cleaning timer narrates "still inside Bash — 70s").
|
package/dist/index.js
CHANGED
|
@@ -2657,6 +2657,9 @@ var AgentOptions = class {
|
|
|
2657
2657
|
instructionFiles = true;
|
|
2658
2658
|
/** Host interaction channel (human-in-the-loop). If set: adds the `AskUserQuestion` tool. */
|
|
2659
2659
|
host;
|
|
2660
|
+
/** Add the `AskUserQuestion` tool when a host is present (default true). Set false for an agent that
|
|
2661
|
+
* must never block a turn on a structured question — e.g. a voice reflex that confirms inline. */
|
|
2662
|
+
askUserQuestion = true;
|
|
2660
2663
|
/** Deterministic interception points around tool execution (pre/post/stop). */
|
|
2661
2664
|
hooks;
|
|
2662
2665
|
/** If true: add the `Task` tool so the agent can spawn depth-limited child agents over the VFS. */
|
|
@@ -2793,7 +2796,7 @@ var Agent = class _Agent {
|
|
|
2793
2796
|
if (catalog) systemPrompt += "\n\n" + catalog;
|
|
2794
2797
|
if (tool) tools = [...tools, tool];
|
|
2795
2798
|
}
|
|
2796
|
-
if (o.host) tools = [...tools, askUserQuestionTool];
|
|
2799
|
+
if (o.host && o.askUserQuestion) tools = [...tools, askUserQuestionTool];
|
|
2797
2800
|
if (o.subagents) {
|
|
2798
2801
|
let agents;
|
|
2799
2802
|
if (o.agentsDir) {
|
|
@@ -3625,6 +3628,11 @@ var DuplexAgentOptions = class {
|
|
|
3625
3628
|
reflexOptions;
|
|
3626
3629
|
actOptions;
|
|
3627
3630
|
thinkOptions;
|
|
3631
|
+
/** Fresh-context check on each successful Act task: a NEW agent (no self-confirmation bias) re-reads
|
|
3632
|
+
* the file state against the brief and fixes any gap before the result is re-voiced. Bounded to one
|
|
3633
|
+
* pass; ~2x Act cost so default OFF. The self-verify FOOTER (same context) was measured ineffective —
|
|
3634
|
+
* this is the structural fix (see mind/10). Think tasks are pure reasoning, never checked. */
|
|
3635
|
+
verifyActTasks = false;
|
|
3628
3636
|
/** Receives the voice text_delta stream + task lifecycle events. */
|
|
3629
3637
|
host;
|
|
3630
3638
|
/** How many recent transcript messages are rendered into a worker's brief. */
|
|
@@ -3655,7 +3663,7 @@ var DuplexAgentOptions = class {
|
|
|
3655
3663
|
/** User-scope memory dir for global facts (type=user/feedback). Forwarded to Remember's routing. */
|
|
3656
3664
|
memoryUserDir;
|
|
3657
3665
|
};
|
|
3658
|
-
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
|
|
3666
|
+
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.';
|
|
3659
3667
|
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.";
|
|
3660
3668
|
var THINK_DISABLED_GUIDANCE = "(Think tier is not available \u2014 use Act for all escalations.)";
|
|
3661
3669
|
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).`;
|
|
@@ -3697,6 +3705,10 @@ Today's date: ${(/* @__PURE__ */ new Date()).toDateString()}.`;
|
|
|
3697
3705
|
model: o.reflexModel,
|
|
3698
3706
|
stream: true,
|
|
3699
3707
|
host: o.host,
|
|
3708
|
+
// The reflex IS the conversational channel — it confirms ambiguity inline ("did you mean…?"),
|
|
3709
|
+
// never via the blocking AskUserQuestion tool (Agent auto-adds it whenever a host is set). Left in,
|
|
3710
|
+
// it stalls a voice turn until the kill-switch. Worker questions still reach the user via parkQuestion.
|
|
3711
|
+
askUserQuestion: false,
|
|
3700
3712
|
systemPrompt: prompt,
|
|
3701
3713
|
instructionFiles: false,
|
|
3702
3714
|
maxSteps: 8,
|
|
@@ -3796,7 +3808,7 @@ ${recent}` : brief) + verify;
|
|
|
3796
3808
|
return a || "(no answer from the user \u2014 use your best judgment and note the assumption)";
|
|
3797
3809
|
};
|
|
3798
3810
|
const workerHost = o.askRelay ? { ask: relayAsk } : o.host?.ask ? { ask: (q) => o.host.ask(q) } : void 0;
|
|
3799
|
-
const
|
|
3811
|
+
const agentOpts = {
|
|
3800
3812
|
ai: o.ai,
|
|
3801
3813
|
fs: o.fs,
|
|
3802
3814
|
model: tierModel,
|
|
@@ -3805,10 +3817,46 @@ ${recent}` : brief) + verify;
|
|
|
3805
3817
|
...workerHost ? { host: workerHost } : {},
|
|
3806
3818
|
...hooks ? { hooks } : {},
|
|
3807
3819
|
signal: controller.signal
|
|
3808
|
-
|
|
3809
|
-
|
|
3820
|
+
// shared with the checker so a cancel tears down both
|
|
3821
|
+
};
|
|
3822
|
+
const promise = new Agent(agentOpts).run(briefText).then((res) => this.maybeVerify(id, briefText, res, tier, agentOpts)).then((res) => this.onWorkerSettled(id, res)).catch((err) => this.onWorkerFailed(id, err));
|
|
3810
3823
|
this.tasks.set(id, { id, label, status: "running", controller, promise });
|
|
3811
3824
|
}
|
|
3825
|
+
/** Fresh-context check of a successful Act task: a NEW agent (same model/fs/tools, but NO shared
|
|
3826
|
+
* conversation context) re-reads the file state against the brief and fixes any gap. The fix lands
|
|
3827
|
+
* on the shared fs automatically (workers write fs directly, no overlay), so grading sees the
|
|
3828
|
+
* corrected state. Bounded to ONE pass. Off unless `verifyActTasks`; never runs for think/failed/
|
|
3829
|
+
* cancelled tasks. Usage is merged so /cost reflects the real (worker + checker) spend. */
|
|
3830
|
+
async maybeVerify(id, briefText, res, tier, agentOpts) {
|
|
3831
|
+
if (!this.options.verifyActTasks || tier !== "act" || res.finishReason !== "stop") return res;
|
|
3832
|
+
if (this.tasks.get(id)?.status === "cancelled") return res;
|
|
3833
|
+
const checkBrief = `${briefText}
|
|
3834
|
+
|
|
3835
|
+
## VERIFY MODE
|
|
3836
|
+
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".`;
|
|
3837
|
+
this.notify("task_verify", `task ${id}: verifying`, { id });
|
|
3838
|
+
const cres = await new Agent(agentOpts).run(checkBrief);
|
|
3839
|
+
if (cres.finishReason !== "stop") {
|
|
3840
|
+
log7.warn(`task ${id}: verify inconclusive (${cres.finishReason})`);
|
|
3841
|
+
this.notify("task_verify", `task ${id}: verify inconclusive (${cres.finishReason})`, { id, finishReason: cres.finishReason });
|
|
3842
|
+
}
|
|
3843
|
+
const sum = (a = 0, b = 0) => a + b;
|
|
3844
|
+
return {
|
|
3845
|
+
...res,
|
|
3846
|
+
steps: res.steps + cres.steps,
|
|
3847
|
+
// Merge the checker's messages so downstream tool-call/step accounting includes BOTH agents
|
|
3848
|
+
// (else a verified task's toolCalls would undercount vs its steps/usage).
|
|
3849
|
+
messages: [...res.messages, ...cres.messages],
|
|
3850
|
+
usageEstimated: res.usageEstimated || cres.usageEstimated,
|
|
3851
|
+
usage: res.usage && cres.usage ? {
|
|
3852
|
+
promptTokens: sum(res.usage.promptTokens, cres.usage.promptTokens),
|
|
3853
|
+
completionTokens: sum(res.usage.completionTokens, cres.usage.completionTokens),
|
|
3854
|
+
totalTokens: sum(res.usage.totalTokens, cres.usage.totalTokens),
|
|
3855
|
+
cacheCreationTokens: sum(res.usage.cacheCreationTokens, cres.usage.cacheCreationTokens),
|
|
3856
|
+
cacheReadTokens: sum(res.usage.cacheReadTokens, cres.usage.cacheReadTokens)
|
|
3857
|
+
} : res.usage ?? cres.usage
|
|
3858
|
+
};
|
|
3859
|
+
}
|
|
3812
3860
|
/** Throttled per-task progress: worker tool calls → at most one progress re-voice per interval.
|
|
3813
3861
|
* Two sources, one throttle: completed steps (post) and a heartbeat for a SINGLE long tool call
|
|
3814
3862
|
* (pre records the in-flight call; a self-cleaning timer narrates "still inside Bash — 70s").
|