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/dist/index.d.ts CHANGED
@@ -565,7 +565,7 @@ declare function loadInstructions(fs: IFilesystem, names?: string[]): Promise<st
565
565
  * re-voiced by the fast persona — push, not poll (unlike subagent.ts's background `Task`).
566
566
  *
567
567
  * Host events (via the open HostEvent union): the voice agent's standard `text_delta` stream,
568
- * plus `task_started` / `task_done` / `task_error` / `task_cancelled`.
568
+ * plus `task_started` / `task_progress` / `task_done` / `task_error` / `task_cancelled`.
569
569
  */
570
570
 
571
571
  type DuplexTaskStatus = 'running' | 'done' | 'error' | 'cancelled';
@@ -597,6 +597,11 @@ declare class DuplexAgentOptions {
597
597
  /** Awaited BEFORE a delegated worker spawns — open a per-task checkpoint frame, audit, etc.
598
598
  * (post-spawn would race the worker's first edits). */
599
599
  onTaskStart?: (id: string, label: string) => void | Promise<void>;
600
+ /** Re-voice throttled worker progress asides ('[task t1 progress] …') so long tasks aren't dead
601
+ * air. Off by default — each update costs a voice turn (LLM call + speech). */
602
+ progressUpdates: boolean;
603
+ /** Min ms between progress re-voices per task. */
604
+ progressIntervalMs: number;
600
605
  /** Host overrides for QuickLook lookups (keyed by `what`). The engine's defaults go through the
601
606
  * (possibly jailed) fs — e.g. `.git/**` is deny-listed, so the CLI supplies 'branch' itself. */
602
607
  quickLook?: Record<string, (path?: string) => string | Promise<string>>;
@@ -630,6 +635,11 @@ declare class DuplexAgent {
630
635
  private buildBrief;
631
636
  /** Spawn a detached worker for task `id`; its settlement notifies + enqueues the re-voice turn. */
632
637
  private spawnWorker;
638
+ /** Throttled per-task progress: worker tool calls → at most one progress re-voice per interval.
639
+ * Two sources, one throttle: completed steps (post) and a heartbeat for a SINGLE long tool call
640
+ * (pre records the in-flight call; a self-cleaning timer narrates "still inside Bash — 70s").
641
+ * Completion supersedes: nothing is emitted once the task has settled. */
642
+ private progressReporter;
633
643
  private onWorkerSettled;
634
644
  private onWorkerFailed;
635
645
  private failTask;
package/dist/index.js CHANGED
@@ -3483,6 +3483,11 @@ function digestRun(messages, maxChars) {
3483
3483
  import { MemFilesystem as MemFilesystem2 } from "@livx.cc/wcli/core";
3484
3484
  init_logging();
3485
3485
  var log7 = forComponent("DuplexAgent");
3486
+ function describeCall(call) {
3487
+ const v = call.args && Object.values(call.args).find((x) => typeof x === "string" && x.trim());
3488
+ const hint = v ? ` (${String(v).replace(/\s+/g, " ").trim().slice(0, 48)})` : "";
3489
+ return `${call.name}${hint}`;
3490
+ }
3486
3491
  var DuplexAgentOptions = class {
3487
3492
  /** Any ai.libx.js AIClient — shared by the voice and worker agents (routed by model). */
3488
3493
  ai;
@@ -3503,11 +3508,16 @@ var DuplexAgentOptions = class {
3503
3508
  /** Awaited BEFORE a delegated worker spawns — open a per-task checkpoint frame, audit, etc.
3504
3509
  * (post-spawn would race the worker's first edits). */
3505
3510
  onTaskStart;
3511
+ /** Re-voice throttled worker progress asides ('[task t1 progress] …') so long tasks aren't dead
3512
+ * air. Off by default — each update costs a voice turn (LLM call + speech). */
3513
+ progressUpdates = false;
3514
+ /** Min ms between progress re-voices per task. */
3515
+ progressIntervalMs = 25e3;
3506
3516
  /** Host overrides for QuickLook lookups (keyed by `what`). The engine's defaults go through the
3507
3517
  * (possibly jailed) fs — e.g. `.git/**` is deny-listed, so the CLI supplies 'branch' itself. */
3508
3518
  quickLook;
3509
3519
  };
3510
- 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.';
3520
+ 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.';
3511
3521
  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).`;
3512
3522
  var DuplexAgent = class {
3513
3523
  options;
@@ -3592,18 +3602,69 @@ ${recent}` : brief;
3592
3602
  spawnWorker(id, label, briefText) {
3593
3603
  const o = this.options;
3594
3604
  const controller = new AbortController();
3605
+ const base = o.workerOptions?.hooks;
3606
+ const report = o.progressUpdates ? this.progressReporter(id) : void 0;
3607
+ const hooks = report ? {
3608
+ ...base,
3609
+ preToolUse: async (call, meta) => {
3610
+ const d = await base?.preToolUse?.(call, meta);
3611
+ report.pre(call);
3612
+ return d;
3613
+ },
3614
+ postToolUse: async (call, result, meta) => {
3615
+ await base?.postToolUse?.(call, result, meta);
3616
+ report.post(call);
3617
+ }
3618
+ } : base;
3595
3619
  const worker = new Agent({
3596
3620
  ai: o.ai,
3597
3621
  fs: o.fs,
3598
3622
  model: o.workerModel,
3599
3623
  ...o.workerOptions,
3600
3624
  // may override ai/fs/model/tools/… —
3625
+ ...hooks ? { hooks } : {},
3601
3626
  signal: controller.signal
3602
3627
  // …but never the per-task cancellation signal
3603
3628
  });
3604
3629
  const promise = worker.run(briefText).then((res) => this.onWorkerSettled(id, res)).catch((err) => this.onWorkerFailed(id, err));
3605
3630
  this.tasks.set(id, { id, label, status: "running", controller, promise });
3606
3631
  }
3632
+ /** Throttled per-task progress: worker tool calls → at most one progress re-voice per interval.
3633
+ * Two sources, one throttle: completed steps (post) and a heartbeat for a SINGLE long tool call
3634
+ * (pre records the in-flight call; a self-cleaning timer narrates "still inside Bash — 70s").
3635
+ * Completion supersedes: nothing is emitted once the task has settled. */
3636
+ progressReporter(id) {
3637
+ let lastAt = Date.now();
3638
+ let steps = 0;
3639
+ let inflight = null;
3640
+ const due = () => {
3641
+ const rec = this.tasks.get(id);
3642
+ return rec && rec.status === "running" && Date.now() - lastAt >= this.options.progressIntervalMs ? rec : void 0;
3643
+ };
3644
+ const emit = (rec, line, call) => {
3645
+ lastAt = Date.now();
3646
+ this.notify("task_progress", `task ${id} (${rec.label}): ${line}`, { id, steps, call: call.name });
3647
+ this.queueRevoice(`[task ${id} progress] ${line}`);
3648
+ };
3649
+ const timer = setInterval(() => {
3650
+ const rec = this.tasks.get(id);
3651
+ if (!rec || rec.status !== "running") return clearInterval(timer);
3652
+ if (!inflight || !due()) return;
3653
+ emit(rec, `still inside ${describeCall(inflight.call)} \u2014 ${Math.round((Date.now() - inflight.at) / 1e3)}s on this step`, inflight.call);
3654
+ }, Math.max(this.options.progressIntervalMs, 250));
3655
+ timer.unref?.();
3656
+ return {
3657
+ pre: (call) => {
3658
+ inflight = { call, at: Date.now() };
3659
+ },
3660
+ post: (call) => {
3661
+ steps++;
3662
+ inflight = null;
3663
+ const rec = due();
3664
+ if (rec) emit(rec, `still running \u2014 ${steps} steps so far, now: ${describeCall(call)}`, call);
3665
+ }
3666
+ };
3667
+ }
3607
3668
  onWorkerSettled(id, res) {
3608
3669
  const rec = this.tasks.get(id);
3609
3670
  if (res.finishReason === "aborted" || rec.status === "cancelled") {