agent.libx.js 0.92.1 → 0.92.2
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 +1 -1
- package/dist/cli.js +64 -2
- package/dist/cli.js.map +1 -1
- package/dist/index.d.ts +11 -1
- package/dist/index.js +62 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/cli/cli.ts
CHANGED
|
@@ -1039,7 +1039,7 @@ async function repl(args: Args, ai: ChatLike, cfg: Partial<AgentConfig>, cwd: st
|
|
|
1039
1039
|
workerModel: agent.options.model,
|
|
1040
1040
|
workerOptions,
|
|
1041
1041
|
host,
|
|
1042
|
-
...(args.voice ? { voiceStyle: 'conversational' as const } : {}),
|
|
1042
|
+
...(args.voice ? { voiceStyle: 'conversational' as const, progressUpdates: true } : {}), // voice: narrate throttled worker progress (dead air is worse than a short aside)
|
|
1043
1043
|
// Per-TASK checkpoint frames (the natural undo unit in duplex = one delegation): opened BEFORE
|
|
1044
1044
|
// the worker spawns (post-spawn would race its first edits). `checkpoints` is bound below.
|
|
1045
1045
|
onTaskStart: async (_id, label) => { await checkpoints.begin(label); },
|
package/dist/cli.js
CHANGED
|
@@ -3383,6 +3383,11 @@ function digestRun(messages, maxChars) {
|
|
|
3383
3383
|
import { MemFilesystem as MemFilesystem2 } from "@livx.cc/wcli/core";
|
|
3384
3384
|
init_logging();
|
|
3385
3385
|
var log6 = forComponent("DuplexAgent");
|
|
3386
|
+
function describeCall(call) {
|
|
3387
|
+
const v = call.args && Object.values(call.args).find((x) => typeof x === "string" && x.trim());
|
|
3388
|
+
const hint = v ? ` (${String(v).replace(/\s+/g, " ").trim().slice(0, 48)})` : "";
|
|
3389
|
+
return `${call.name}${hint}`;
|
|
3390
|
+
}
|
|
3386
3391
|
var DuplexAgentOptions = class {
|
|
3387
3392
|
/** Any ai.libx.js AIClient — shared by the voice and worker agents (routed by model). */
|
|
3388
3393
|
ai;
|
|
@@ -3403,11 +3408,16 @@ var DuplexAgentOptions = class {
|
|
|
3403
3408
|
/** Awaited BEFORE a delegated worker spawns — open a per-task checkpoint frame, audit, etc.
|
|
3404
3409
|
* (post-spawn would race the worker's first edits). */
|
|
3405
3410
|
onTaskStart;
|
|
3411
|
+
/** Re-voice throttled worker progress asides ('[task t1 progress] …') so long tasks aren't dead
|
|
3412
|
+
* air. Off by default — each update costs a voice turn (LLM call + speech). */
|
|
3413
|
+
progressUpdates = false;
|
|
3414
|
+
/** Min ms between progress re-voices per task. */
|
|
3415
|
+
progressIntervalMs = 25e3;
|
|
3406
3416
|
/** Host overrides for QuickLook lookups (keyed by `what`). The engine's defaults go through the
|
|
3407
3417
|
* (possibly jailed) fs — e.g. `.git/**` is deny-listed, so the CLI supplies 'branch' itself. */
|
|
3408
3418
|
quickLook;
|
|
3409
3419
|
};
|
|
3410
|
-
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. Never read raw file paths, diffs, or code aloud verbatim.\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`.\nNEVER 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.\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.';
|
|
3420
|
+
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.\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`.\nNEVER 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.\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.';
|
|
3411
3421
|
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).`;
|
|
3412
3422
|
var DuplexAgent = class {
|
|
3413
3423
|
options;
|
|
@@ -3492,18 +3502,69 @@ ${recent}` : brief;
|
|
|
3492
3502
|
spawnWorker(id, label, briefText) {
|
|
3493
3503
|
const o = this.options;
|
|
3494
3504
|
const controller = new AbortController();
|
|
3505
|
+
const base = o.workerOptions?.hooks;
|
|
3506
|
+
const report = o.progressUpdates ? this.progressReporter(id) : void 0;
|
|
3507
|
+
const hooks = report ? {
|
|
3508
|
+
...base,
|
|
3509
|
+
preToolUse: async (call, meta) => {
|
|
3510
|
+
const d = await base?.preToolUse?.(call, meta);
|
|
3511
|
+
report.pre(call);
|
|
3512
|
+
return d;
|
|
3513
|
+
},
|
|
3514
|
+
postToolUse: async (call, result, meta) => {
|
|
3515
|
+
await base?.postToolUse?.(call, result, meta);
|
|
3516
|
+
report.post(call);
|
|
3517
|
+
}
|
|
3518
|
+
} : base;
|
|
3495
3519
|
const worker = new Agent({
|
|
3496
3520
|
ai: o.ai,
|
|
3497
3521
|
fs: o.fs,
|
|
3498
3522
|
model: o.workerModel,
|
|
3499
3523
|
...o.workerOptions,
|
|
3500
3524
|
// may override ai/fs/model/tools/… —
|
|
3525
|
+
...hooks ? { hooks } : {},
|
|
3501
3526
|
signal: controller.signal
|
|
3502
3527
|
// …but never the per-task cancellation signal
|
|
3503
3528
|
});
|
|
3504
3529
|
const promise = worker.run(briefText).then((res) => this.onWorkerSettled(id, res)).catch((err2) => this.onWorkerFailed(id, err2));
|
|
3505
3530
|
this.tasks.set(id, { id, label, status: "running", controller, promise });
|
|
3506
3531
|
}
|
|
3532
|
+
/** Throttled per-task progress: worker tool calls → at most one progress re-voice per interval.
|
|
3533
|
+
* Two sources, one throttle: completed steps (post) and a heartbeat for a SINGLE long tool call
|
|
3534
|
+
* (pre records the in-flight call; a self-cleaning timer narrates "still inside Bash — 70s").
|
|
3535
|
+
* Completion supersedes: nothing is emitted once the task has settled. */
|
|
3536
|
+
progressReporter(id) {
|
|
3537
|
+
let lastAt = Date.now();
|
|
3538
|
+
let steps = 0;
|
|
3539
|
+
let inflight = null;
|
|
3540
|
+
const due = () => {
|
|
3541
|
+
const rec = this.tasks.get(id);
|
|
3542
|
+
return rec && rec.status === "running" && Date.now() - lastAt >= this.options.progressIntervalMs ? rec : void 0;
|
|
3543
|
+
};
|
|
3544
|
+
const emit = (rec, line, call) => {
|
|
3545
|
+
lastAt = Date.now();
|
|
3546
|
+
this.notify("task_progress", `task ${id} (${rec.label}): ${line}`, { id, steps, call: call.name });
|
|
3547
|
+
this.queueRevoice(`[task ${id} progress] ${line}`);
|
|
3548
|
+
};
|
|
3549
|
+
const timer = setInterval(() => {
|
|
3550
|
+
const rec = this.tasks.get(id);
|
|
3551
|
+
if (!rec || rec.status !== "running") return clearInterval(timer);
|
|
3552
|
+
if (!inflight || !due()) return;
|
|
3553
|
+
emit(rec, `still inside ${describeCall(inflight.call)} \u2014 ${Math.round((Date.now() - inflight.at) / 1e3)}s on this step`, inflight.call);
|
|
3554
|
+
}, Math.max(this.options.progressIntervalMs, 250));
|
|
3555
|
+
timer.unref?.();
|
|
3556
|
+
return {
|
|
3557
|
+
pre: (call) => {
|
|
3558
|
+
inflight = { call, at: Date.now() };
|
|
3559
|
+
},
|
|
3560
|
+
post: (call) => {
|
|
3561
|
+
steps++;
|
|
3562
|
+
inflight = null;
|
|
3563
|
+
const rec = due();
|
|
3564
|
+
if (rec) emit(rec, `still running \u2014 ${steps} steps so far, now: ${describeCall(call)}`, call);
|
|
3565
|
+
}
|
|
3566
|
+
};
|
|
3567
|
+
}
|
|
3507
3568
|
onWorkerSettled(id, res) {
|
|
3508
3569
|
const rec = this.tasks.get(id);
|
|
3509
3570
|
if (res.finishReason === "aborted" || rec.status === "cancelled") {
|
|
@@ -7654,7 +7715,8 @@ async function repl(args, ai, cfg, cwd) {
|
|
|
7654
7715
|
workerModel: agent.options.model,
|
|
7655
7716
|
workerOptions,
|
|
7656
7717
|
host,
|
|
7657
|
-
...args.voice ? { voiceStyle: "conversational" } : {},
|
|
7718
|
+
...args.voice ? { voiceStyle: "conversational", progressUpdates: true } : {},
|
|
7719
|
+
// voice: narrate throttled worker progress (dead air is worse than a short aside)
|
|
7658
7720
|
// Per-TASK checkpoint frames (the natural undo unit in duplex = one delegation): opened BEFORE
|
|
7659
7721
|
// the worker spawns (post-spawn would race its first edits). `checkpoints` is bound below.
|
|
7660
7722
|
onTaskStart: async (_id, label) => {
|