agent.libx.js 0.93.44 → 0.94.1
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 +325 -8
- package/dist/cli.js.map +1 -1
- package/dist/index.d.ts +94 -1
- package/dist/index.js +261 -3
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -2659,6 +2659,11 @@ function reasoningToChatFragment(model, effort) {
|
|
|
2659
2659
|
|
|
2660
2660
|
// src/Agent.ts
|
|
2661
2661
|
var log3 = forComponent("Agent");
|
|
2662
|
+
function isAbortError(err2) {
|
|
2663
|
+
const e = err2;
|
|
2664
|
+
const blob = `${e?.message ?? ""} ${e?.name ?? ""} ${e?.code ?? ""} ${e?.cause?.name ?? ""}`;
|
|
2665
|
+
return /operation was aborted|\bAbortError\b|ABORT_ERR|\[canceled\]/i.test(blob);
|
|
2666
|
+
}
|
|
2662
2667
|
var AgentOptions = class {
|
|
2663
2668
|
/** Any ai.libx.js AIClient (or a FakeAIClient). */
|
|
2664
2669
|
ai;
|
|
@@ -2985,7 +2990,7 @@ var Agent = class _Agent {
|
|
|
2985
2990
|
}
|
|
2986
2991
|
} catch (err2) {
|
|
2987
2992
|
if (err2?.code === "budget") return kill("budget");
|
|
2988
|
-
if (o.signal?.aborted) return kill("aborted");
|
|
2993
|
+
if (o.signal?.aborted || isAbortError(err2)) return kill("aborted");
|
|
2989
2994
|
log3.error(`chat() failed: ${err2?.message ?? err2}`, err2);
|
|
2990
2995
|
return { text: "", steps, finishReason: "error", messages: this.transcript, usage, usageEstimated, error: err2 };
|
|
2991
2996
|
}
|
|
@@ -3491,6 +3496,253 @@ init_OverlayFilesystem();
|
|
|
3491
3496
|
// src/index.ts
|
|
3492
3497
|
init_tools();
|
|
3493
3498
|
|
|
3499
|
+
// src/scheduler.ts
|
|
3500
|
+
function parseCronField(field, min, max) {
|
|
3501
|
+
const vals = /* @__PURE__ */ new Set();
|
|
3502
|
+
for (const part of field.split(",")) {
|
|
3503
|
+
const [rangeStr, stepStr] = part.split("/");
|
|
3504
|
+
const step = stepStr ? parseInt(stepStr, 10) : 1;
|
|
3505
|
+
if (isNaN(step) || step < 1) throw new Error(`invalid cron step: ${part}`);
|
|
3506
|
+
let lo, hi;
|
|
3507
|
+
if (rangeStr === "*") {
|
|
3508
|
+
lo = min;
|
|
3509
|
+
hi = max;
|
|
3510
|
+
} else if (rangeStr.includes("-")) {
|
|
3511
|
+
const [a, b] = rangeStr.split("-").map(Number);
|
|
3512
|
+
if (isNaN(a) || isNaN(b)) throw new Error(`invalid cron range: ${part}`);
|
|
3513
|
+
lo = a;
|
|
3514
|
+
hi = b;
|
|
3515
|
+
} else {
|
|
3516
|
+
const n = parseInt(rangeStr, 10);
|
|
3517
|
+
if (isNaN(n)) throw new Error(`invalid cron value: ${part}`);
|
|
3518
|
+
lo = n;
|
|
3519
|
+
hi = stepStr ? max : n;
|
|
3520
|
+
}
|
|
3521
|
+
for (let i = lo; i <= hi; i += step) vals.add(i);
|
|
3522
|
+
}
|
|
3523
|
+
return [...vals].sort((a, b) => a - b);
|
|
3524
|
+
}
|
|
3525
|
+
function parseCron(expr) {
|
|
3526
|
+
const parts = expr.trim().split(/\s+/);
|
|
3527
|
+
if (parts.length !== 5) throw new Error(`cron expression must have 5 fields (minute hour dom month dow), got ${parts.length}: "${expr}"`);
|
|
3528
|
+
return {
|
|
3529
|
+
minute: parseCronField(parts[0], 0, 59),
|
|
3530
|
+
hour: parseCronField(parts[1], 0, 23),
|
|
3531
|
+
dom: parseCronField(parts[2], 1, 31),
|
|
3532
|
+
month: parseCronField(parts[3], 1, 12),
|
|
3533
|
+
dow: parseCronField(parts[4], 0, 6)
|
|
3534
|
+
};
|
|
3535
|
+
}
|
|
3536
|
+
function cronMatches(fields, date) {
|
|
3537
|
+
return fields.minute.includes(date.getMinutes()) && fields.hour.includes(date.getHours()) && fields.dom.includes(date.getDate()) && fields.month.includes(date.getMonth() + 1) && fields.dow.includes(date.getDay());
|
|
3538
|
+
}
|
|
3539
|
+
function nextCronAfter(cron, after) {
|
|
3540
|
+
const fields = parseCron(cron);
|
|
3541
|
+
const d = new Date(after);
|
|
3542
|
+
d.setSeconds(0, 0);
|
|
3543
|
+
d.setMinutes(d.getMinutes() + 1);
|
|
3544
|
+
const limit = after + 366 * 864e5;
|
|
3545
|
+
while (d.getTime() <= limit) {
|
|
3546
|
+
if (cronMatches(fields, d)) return d.getTime();
|
|
3547
|
+
d.setMinutes(d.getMinutes() + 1);
|
|
3548
|
+
}
|
|
3549
|
+
return null;
|
|
3550
|
+
}
|
|
3551
|
+
var Scheduler = class {
|
|
3552
|
+
jobs = /* @__PURE__ */ new Map();
|
|
3553
|
+
seq = 0;
|
|
3554
|
+
timer = null;
|
|
3555
|
+
firing = false;
|
|
3556
|
+
fire;
|
|
3557
|
+
now;
|
|
3558
|
+
tickMs;
|
|
3559
|
+
constructor(opts) {
|
|
3560
|
+
this.fire = opts.fire;
|
|
3561
|
+
this.now = opts.now ?? Date.now;
|
|
3562
|
+
this.tickMs = opts.tickMs ?? 15e3;
|
|
3563
|
+
if (!opts.manual) this.start();
|
|
3564
|
+
}
|
|
3565
|
+
/** Start the tick timer. Idempotent. */
|
|
3566
|
+
start() {
|
|
3567
|
+
if (this.timer) return;
|
|
3568
|
+
this.timer = setInterval(() => this.tick(), this.tickMs);
|
|
3569
|
+
if (typeof this.timer === "object" && "unref" in this.timer) this.timer.unref();
|
|
3570
|
+
}
|
|
3571
|
+
/** Stop the tick timer. Does not clear jobs. */
|
|
3572
|
+
stop() {
|
|
3573
|
+
if (this.timer) {
|
|
3574
|
+
clearInterval(this.timer);
|
|
3575
|
+
this.timer = null;
|
|
3576
|
+
}
|
|
3577
|
+
}
|
|
3578
|
+
/** Add a scheduled job. Returns the job id. */
|
|
3579
|
+
add(opts) {
|
|
3580
|
+
if ("cron" in opts.trigger) parseCron(opts.trigger.cron);
|
|
3581
|
+
if ("at" in opts.trigger && opts.trigger.at < this.now()) {
|
|
3582
|
+
}
|
|
3583
|
+
if ("everyMs" in opts.trigger && opts.trigger.everyMs < 1e3) {
|
|
3584
|
+
throw new Error("interval must be >= 1000ms");
|
|
3585
|
+
}
|
|
3586
|
+
const id = `sched-${++this.seq}`;
|
|
3587
|
+
this.jobs.set(id, {
|
|
3588
|
+
id,
|
|
3589
|
+
prompt: opts.prompt,
|
|
3590
|
+
trigger: opts.trigger,
|
|
3591
|
+
status: "active",
|
|
3592
|
+
created: this.now(),
|
|
3593
|
+
runs: 0,
|
|
3594
|
+
label: opts.label
|
|
3595
|
+
});
|
|
3596
|
+
return id;
|
|
3597
|
+
}
|
|
3598
|
+
/** Cancel a job. Returns false if not found. */
|
|
3599
|
+
cancel(id) {
|
|
3600
|
+
const j = this.jobs.get(id);
|
|
3601
|
+
if (!j) return false;
|
|
3602
|
+
j.status = "done";
|
|
3603
|
+
return true;
|
|
3604
|
+
}
|
|
3605
|
+
get(id) {
|
|
3606
|
+
return this.jobs.get(id);
|
|
3607
|
+
}
|
|
3608
|
+
list() {
|
|
3609
|
+
return [...this.jobs.values()];
|
|
3610
|
+
}
|
|
3611
|
+
active() {
|
|
3612
|
+
return this.list().filter((j) => j.status === "active");
|
|
3613
|
+
}
|
|
3614
|
+
/** Compute when a job next fires (epoch ms), or null if done/unknown. */
|
|
3615
|
+
nextFire(job) {
|
|
3616
|
+
if (job.status !== "active") return null;
|
|
3617
|
+
const t = job.trigger;
|
|
3618
|
+
if ("at" in t) return t.at;
|
|
3619
|
+
if ("everyMs" in t) return (job.lastRun ?? job.created) + t.everyMs;
|
|
3620
|
+
if ("cron" in t) return nextCronAfter(t.cron, job.lastRun ?? job.created);
|
|
3621
|
+
return null;
|
|
3622
|
+
}
|
|
3623
|
+
/** Check all active jobs and fire any that are due. Reentrant-safe. */
|
|
3624
|
+
async tick() {
|
|
3625
|
+
if (this.firing) return;
|
|
3626
|
+
this.firing = true;
|
|
3627
|
+
try {
|
|
3628
|
+
const now5 = this.now();
|
|
3629
|
+
for (const job of this.jobs.values()) {
|
|
3630
|
+
if (job.status !== "active") continue;
|
|
3631
|
+
const due = this.nextFire(job);
|
|
3632
|
+
if (due == null || due > now5) continue;
|
|
3633
|
+
job.lastRun = now5;
|
|
3634
|
+
job.runs++;
|
|
3635
|
+
if ("at" in job.trigger) job.status = "done";
|
|
3636
|
+
try {
|
|
3637
|
+
await this.fire(job);
|
|
3638
|
+
} catch {
|
|
3639
|
+
}
|
|
3640
|
+
}
|
|
3641
|
+
} finally {
|
|
3642
|
+
this.firing = false;
|
|
3643
|
+
}
|
|
3644
|
+
}
|
|
3645
|
+
/** Export all jobs for session persistence. */
|
|
3646
|
+
snapshot() {
|
|
3647
|
+
return this.list().filter((j) => j.status === "active").map((j) => ({ ...j }));
|
|
3648
|
+
}
|
|
3649
|
+
/** Restore jobs from a snapshot (e.g. on --resume). Clears existing jobs first. */
|
|
3650
|
+
restore(snapshots) {
|
|
3651
|
+
this.jobs.clear();
|
|
3652
|
+
for (const s of snapshots) {
|
|
3653
|
+
this.seq = Math.max(this.seq, parseInt(s.id.replace("sched-", ""), 10) || 0);
|
|
3654
|
+
this.jobs.set(s.id, { ...s });
|
|
3655
|
+
}
|
|
3656
|
+
}
|
|
3657
|
+
/** Number of active jobs. */
|
|
3658
|
+
get size() {
|
|
3659
|
+
return this.active().length;
|
|
3660
|
+
}
|
|
3661
|
+
destroy() {
|
|
3662
|
+
this.stop();
|
|
3663
|
+
this.jobs.clear();
|
|
3664
|
+
}
|
|
3665
|
+
};
|
|
3666
|
+
function makeScheduleTools(scheduler) {
|
|
3667
|
+
return [
|
|
3668
|
+
{
|
|
3669
|
+
name: "ScheduleTask",
|
|
3670
|
+
description: 'Schedule a prompt to fire automatically while this session is alive.\nModes:\n \u2022 One-off: {at: <epoch_ms>} \u2014 fires once at that time, then done.\n \u2022 Interval: {everyMs: <ms>} \u2014 fires repeatedly (\u22651s).\n \u2022 Cron: {cron: "min hr dom mon dow"} \u2014 standard 5-field cron.\nReturns the job id. Jobs only fire while the CLI session is running \u2014 they do NOT survive quitting.',
|
|
3671
|
+
parameters: {
|
|
3672
|
+
type: "object",
|
|
3673
|
+
required: ["prompt", "trigger"],
|
|
3674
|
+
properties: {
|
|
3675
|
+
prompt: { type: "string", description: "The prompt to inject when the job fires." },
|
|
3676
|
+
trigger: {
|
|
3677
|
+
type: "object",
|
|
3678
|
+
description: 'One of: {at: epoch_ms}, {everyMs: ms}, {cron: "5-field expr"}.',
|
|
3679
|
+
properties: {
|
|
3680
|
+
at: { type: "number" },
|
|
3681
|
+
everyMs: { type: "number" },
|
|
3682
|
+
cron: { type: "string" }
|
|
3683
|
+
}
|
|
3684
|
+
},
|
|
3685
|
+
label: { type: "string", description: "Short label for display (optional)." }
|
|
3686
|
+
}
|
|
3687
|
+
},
|
|
3688
|
+
async run({ prompt, trigger, label }) {
|
|
3689
|
+
try {
|
|
3690
|
+
const id = scheduler.add({ prompt, trigger, label });
|
|
3691
|
+
const job = scheduler.get(id);
|
|
3692
|
+
const next = scheduler.nextFire(job);
|
|
3693
|
+
return `Scheduled ${id}${label ? ` (${label})` : ""}. Next fire: ${next ? new Date(next).toLocaleString() : "now"}.`;
|
|
3694
|
+
} catch (e) {
|
|
3695
|
+
return `Error: ${e?.message ?? e}`;
|
|
3696
|
+
}
|
|
3697
|
+
}
|
|
3698
|
+
},
|
|
3699
|
+
{
|
|
3700
|
+
name: "ScheduleList",
|
|
3701
|
+
description: "List all scheduled jobs and their next fire time.",
|
|
3702
|
+
parameters: { type: "object", properties: {} },
|
|
3703
|
+
async run() {
|
|
3704
|
+
const jobs = scheduler.list();
|
|
3705
|
+
if (!jobs.length) return "(no scheduled jobs)";
|
|
3706
|
+
return jobs.map((j) => {
|
|
3707
|
+
const next = scheduler.nextFire(j);
|
|
3708
|
+
const trig = "at" in j.trigger ? `once @ ${new Date(j.trigger.at).toLocaleString()}` : "everyMs" in j.trigger ? `every ${(j.trigger.everyMs / 1e3).toFixed(0)}s` : `cron: ${j.trigger.cron}`;
|
|
3709
|
+
return `${j.id} ${j.status} ${trig} runs:${j.runs} next:${next ? new Date(next).toLocaleTimeString() : "\u2014"}${j.label ? " " + j.label : ""}`;
|
|
3710
|
+
}).join("\n");
|
|
3711
|
+
}
|
|
3712
|
+
},
|
|
3713
|
+
{
|
|
3714
|
+
name: "ScheduleCancel",
|
|
3715
|
+
description: "Cancel a scheduled job by id.",
|
|
3716
|
+
parameters: { type: "object", required: ["id"], properties: { id: { type: "string" } } },
|
|
3717
|
+
async run({ id }) {
|
|
3718
|
+
return scheduler.cancel(String(id)) ? `Cancelled ${id}.` : `Error: no scheduled job '${id}'. Use ScheduleList to see jobs.`;
|
|
3719
|
+
}
|
|
3720
|
+
},
|
|
3721
|
+
{
|
|
3722
|
+
name: "Wakeup",
|
|
3723
|
+
description: 'Self-pacing: schedule a one-off re-invocation of the agent after a delay.\nUse this to resume work later in the session (e.g. "check back in 5 minutes").\nThe prompt fires once, while the session is alive. Equivalent to ScheduleTask with {at: now + delayMs}.',
|
|
3724
|
+
parameters: {
|
|
3725
|
+
type: "object",
|
|
3726
|
+
required: ["delayMs", "prompt"],
|
|
3727
|
+
properties: {
|
|
3728
|
+
delayMs: { type: "number", description: "Delay in milliseconds (minimum 5000)." },
|
|
3729
|
+
prompt: { type: "string", description: "The prompt to inject when waking up." },
|
|
3730
|
+
label: { type: "string" }
|
|
3731
|
+
}
|
|
3732
|
+
},
|
|
3733
|
+
async run({ delayMs, prompt, label }) {
|
|
3734
|
+
const delay = Math.max(5e3, Number(delayMs) || 5e3);
|
|
3735
|
+
try {
|
|
3736
|
+
const id = scheduler.add({ prompt, trigger: { at: Date.now() + delay }, label: label ?? "wakeup" });
|
|
3737
|
+
return `Wakeup ${id} in ${(delay / 1e3).toFixed(0)}s.`;
|
|
3738
|
+
} catch (e) {
|
|
3739
|
+
return `Error: ${e?.message ?? e}`;
|
|
3740
|
+
}
|
|
3741
|
+
}
|
|
3742
|
+
}
|
|
3743
|
+
];
|
|
3744
|
+
}
|
|
3745
|
+
|
|
3494
3746
|
// src/presets.ts
|
|
3495
3747
|
init_tools();
|
|
3496
3748
|
import { MemFilesystem } from "@livx.cc/wcli/core";
|
|
@@ -3771,7 +4023,7 @@ var DuplexAgentOptions = class {
|
|
|
3771
4023
|
memoryUserDir;
|
|
3772
4024
|
};
|
|
3773
4025
|
var RESERVED_EVENT_MARKER = /\[task\b[^\]\n]*\b(?:completed|failed|progress|asks)\b/i;
|
|
3774
|
-
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.\nThis holds even when asked to "print", "list", "show", or "make a table" \u2014 there is no screen for the spoken channel. Speak it as flowing prose ("Tuesday is half a meter, Wednesday a bit less\u2026"), or if they truly need it on screen, route it to Act to render. Never emit dashes or pipes into speech.\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 background worker with its own configured tools and access to the user\'s environment (files and shell{{WORKER_WEB}}). Use for reading, editing, searching, running tasks, building \u2014 any real work.\n{{THINK_SLOT}}\nWhen you are unsure whether you can do or access something, do NOT assume and do NOT claim a capability you have not confirmed. To check what you can do, QuickLook `capabilities` (instant \u2014 it lists your worker\'s real tools) and answer from that. Never promise an ability that is not in your capabilities; if it is not there, tell the user plainly you can\'t. To actually DO real work, call `Act`. 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.\nALWAYS react before you work: the FIRST thing in your turn is a brief spoken acknowledgement of what you heard and what you are about to do ("got it \u2014 opening that now", "sure, let me pull it up", "okay, checking"). NEVER call a tool (Act, Think, QuickLook) silently \u2014 the user must hear you react before you go quiet to work. After dispatching Act or Think, that same one short sentence IS your turn \u2014 end it and do not wait for the result.\nResults arrive later as events like "[task t1 completed] \u2026" or "[task t1 failed] \u2026". When one arrives, speak the USEFUL gist in one or two short sentences \u2014 the actual answer the user wanted (the headline finding, the key numbers), not the thinnest possible "it\'s done". A forecast \u2192 say it\'s calm AND that it\'s good for swimming but not surf; a count \u2192 say the number. Be brief, but do not drop the substance. If the result is a LIST (search results, multiple files/matches), the user CANNOT see it \u2014 there is no screen and no numbered menu to point at. Speak the gist: say what you found and name the top one or two by NAME (the source, not "the first one" or a number), then ask plainly if they want more. Never ask them to "pick which one" or reference items by position. The completed result stays in YOUR context \u2014 it is yours to draw on. When the user follows up ("tell me more", "what else", "and?"), answer FROM that result first: you already have the detail, so elaborate on what you have. Do NOT spawn a fresh worker to re-search or re-gather what you were just handed. Re-dispatch ONLY when genuinely new information is needed \u2014 e.g. the user wants the full contents of a SPECIFIC source, which is one WebFetch of that URL, not a brand-new search. "[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, or checking your own `capabilities`/tools \u2014 use `QuickLook` (instant, no task). Whenever the user asks what you can do or whether you have some ability, QuickLook `capabilities` and answer from that \u2014 never guess. 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.';
|
|
4026
|
+
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.\nThis holds even when asked to "print", "list", "show", or "make a table" \u2014 there is no screen for the spoken channel. Speak it as flowing prose ("Tuesday is half a meter, Wednesday a bit less\u2026"), or if they truly need it on screen, route it to Act to render. Never emit dashes or pipes into speech.\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 background worker with its own configured tools and access to the user\'s environment (files and shell{{WORKER_WEB}}). Use for reading, editing, searching, running tasks, building \u2014 any real work.\n{{THINK_SLOT}}\nWhen you are unsure whether you can do or access something, do NOT assume and do NOT claim a capability you have not confirmed. To check what you can do, QuickLook `capabilities` (instant \u2014 it lists your worker\'s real tools) and answer from that. Never promise an ability that is not in your capabilities; if it is not there, tell the user plainly you can\'t. To actually DO real work, call `Act`. 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.\nYou are NOT a knowledge base. For any question whose answer needs SPECIFIC verifiable facts you do not already have in hand \u2014 how to build/configure/implement something, exact API, library, entitlement, command or option names, current events, or particular numbers, dates, or names \u2014 do NOT answer from your own memory: you will confidently make things up (a fake API, a wrong entitlement, an event that did not happen). Route it to `Act`, which can search and verify, and speak only what its report says. Answer inline ONLY for general conversation, chit-chat, and trivia you are sure of, or facts you can see via QuickLook. When elaborating on a completed task ("tell me more", "the gist"), stay strictly within what that result actually said \u2014 if the user asks for something the result did not cover, that is NEW information: dispatch `Act`, do not improvise.\nALWAYS react before you work: the FIRST thing in your turn is a brief spoken acknowledgement of what you heard and what you are about to do ("got it \u2014 opening that now", "sure, let me pull it up", "okay, checking"). NEVER call a tool (Act, Think, QuickLook) silently \u2014 the user must hear you react before you go quiet to work. After dispatching Act or Think, that same one short sentence IS your turn \u2014 end it and do not wait for the result.\nResults arrive later as events like "[task t1 completed] \u2026" or "[task t1 failed] \u2026". When one arrives, speak the USEFUL gist in one or two short sentences \u2014 the actual answer the user wanted (the headline finding, the key numbers), not the thinnest possible "it\'s done". A forecast \u2192 say it\'s calm AND that it\'s good for swimming but not surf; a count \u2192 say the number. Be brief, but do not drop the substance. If the result is a LIST (search results, multiple files/matches), the user CANNOT see it \u2014 there is no screen and no numbered menu to point at. Speak the gist: say what you found and name the top one or two by NAME (the source, not "the first one" or a number), then ask plainly if they want more. Never ask them to "pick which one" or reference items by position. The completed result stays in YOUR context \u2014 it is yours to draw on. When the user follows up ("tell me more", "what else", "and?"), answer FROM that result first: you already have the detail, so elaborate on what you have. Do NOT spawn a fresh worker to re-search or re-gather what you were just handed. Re-dispatch ONLY when genuinely new information is needed \u2014 e.g. the user wants the full contents of a SPECIFIC source, which is one WebFetch of that URL, not a brand-new search. "[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.\nDo NOT end every turn with the same canned offer ("want a rundown?", "want the steps?"). Offer once at most; if the user pushes back, repeats themselves, or sounds unsatisfied ("you know what I mean?", "think deeper", "are you sure?"), do NOT re-offer the same thing \u2014 change approach: dispatch `Act`/`Think` to actually dig in, or ask one concrete clarifying question. Repeating a non-answer is worse than silence.\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, or checking your own `capabilities`/tools \u2014 use `QuickLook` (instant, no task). Whenever the user asks what you can do or whether you have some ability, QuickLook `capabilities` and answer from that \u2014 never guess. 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.';
|
|
3775
4027
|
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.";
|
|
3776
4028
|
var THINK_DISABLED_GUIDANCE = "(Think tier is not available \u2014 use Act for all escalations.)";
|
|
3777
4029
|
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).`;
|
|
@@ -4412,7 +4664,7 @@ init_logging();
|
|
|
4412
4664
|
init_logging();
|
|
4413
4665
|
var log8 = forComponent("VoiceEngine");
|
|
4414
4666
|
var now = () => performance.now();
|
|
4415
|
-
var forSpeech = (t) => t.replace(/[*_`#]+/g, "").replace(/^[ \t]*[-•]\s+/gm, "");
|
|
4667
|
+
var forSpeech = (t) => t.replace(/[*_`#]+/g, "").replace(/^[ \t]*[-•]\s+/gm, "").replace(/\s*[\u2013\u2014]\s*/g, ", ").replace(/[\u2010\u2011]/g, "-").replace(/\s*\|\s*/g, ", ").replace(/(\d)\s+%/g, "$1%").replace(/\.{3,}/g, ".");
|
|
4416
4668
|
var VoiceEngineOptions = class {
|
|
4417
4669
|
stt;
|
|
4418
4670
|
tts;
|
|
@@ -5070,6 +5322,7 @@ var CartesiaTTS = class _CartesiaTTS {
|
|
|
5070
5322
|
}
|
|
5071
5323
|
speak(text, cont) {
|
|
5072
5324
|
if (this.down) return;
|
|
5325
|
+
if (cont && !text) return;
|
|
5073
5326
|
if (this.ws?.readyState === WebSocket.OPEN) this.ws.send(this.frame(text, cont));
|
|
5074
5327
|
else void this.ensureConnected().then(() => this.ws?.readyState === WebSocket.OPEN && this.ws.send(this.frame(text, cont)));
|
|
5075
5328
|
}
|
|
@@ -7925,6 +8178,9 @@ var vis = (s) => needsBidi(s) ? bidiLine(s).visual : s;
|
|
|
7925
8178
|
function displayText(s) {
|
|
7926
8179
|
return s.replace(/`([^`]+)`/g, "$1").replace(/\[([^\]]+)\]\([^)]+\)/g, "$1").replace(/\*\*([^*]+)\*\*/g, "$1").replace(/~~([^~]+)~~/g, "$1").replace(/(?<![\w*])[*_]([^*_\s][^*_]*?)[*_](?![\w*])/g, "$1");
|
|
7927
8180
|
}
|
|
8181
|
+
function plainLine(s) {
|
|
8182
|
+
return displayText(s).replace(/^\s{0,3}#{1,6}\s+/, "").replace(/^(\s*)[-*+]\s+/, "$1");
|
|
8183
|
+
}
|
|
7928
8184
|
function mdInline(line, p) {
|
|
7929
8185
|
const re = /(`[^`]+`)|(\[[^\]]+\]\([^)]+\))|(\*\*[^*]+\*\*)|(~~[^~]+~~)|((?<![\w*])[*_][^*_\s][^*_]*?[*_](?![\w*]))/g;
|
|
7930
8186
|
return line.replace(re, (_m, code, link2, bold2, strike2, italic2) => {
|
|
@@ -8976,9 +9232,37 @@ async function repl(args, ai, cfg, cwd) {
|
|
|
8976
9232
|
if (args.voice && !args.duplex) agent.options.tools = [...agent.options.tools ?? [], exitSessionTool(() => {
|
|
8977
9233
|
exitRequested = true;
|
|
8978
9234
|
})];
|
|
9235
|
+
const scheduleQueue = [];
|
|
9236
|
+
let scheduleTurn;
|
|
9237
|
+
const scheduler = new Scheduler({
|
|
9238
|
+
fire: (job) => {
|
|
9239
|
+
if (!activeTurn && scheduleTurn) {
|
|
9240
|
+
err(dim(` \u23F0 scheduled \u203A ${job.prompt.slice(0, 60)}${job.prompt.length > 60 ? "\u2026" : ""}
|
|
9241
|
+
`));
|
|
9242
|
+
void scheduleTurn(job.prompt).then(() => editorRef?.redrawNow());
|
|
9243
|
+
} else {
|
|
9244
|
+
scheduleQueue.push(job.prompt);
|
|
9245
|
+
}
|
|
9246
|
+
},
|
|
9247
|
+
tickMs: 15e3
|
|
9248
|
+
});
|
|
9249
|
+
agent.options.tools = [...agent.options.tools ?? [], ...makeScheduleTools(scheduler)];
|
|
8979
9250
|
const duplex = args.duplex;
|
|
8980
9251
|
let dx;
|
|
8981
9252
|
let voiceIO;
|
|
9253
|
+
let voiceLineOpen = false;
|
|
9254
|
+
const voiceEcho = (text) => {
|
|
9255
|
+
const s = forSpeech(text);
|
|
9256
|
+
if (!s) return;
|
|
9257
|
+
process.stdout.write(s);
|
|
9258
|
+
voiceLineOpen = true;
|
|
9259
|
+
};
|
|
9260
|
+
const voiceEchoEnd = () => {
|
|
9261
|
+
if (voiceLineOpen) {
|
|
9262
|
+
process.stdout.write("\n");
|
|
9263
|
+
voiceLineOpen = false;
|
|
9264
|
+
}
|
|
9265
|
+
};
|
|
8982
9266
|
let toggleVoice;
|
|
8983
9267
|
let editorRef;
|
|
8984
9268
|
let repaintStash = () => {
|
|
@@ -9039,6 +9323,8 @@ async function repl(args, ai, cfg, cwd) {
|
|
|
9039
9323
|
if (e.kind === "text_delta" && voiceIO) {
|
|
9040
9324
|
voiceIO.speakDelta(e.message);
|
|
9041
9325
|
editorRef?.suspend();
|
|
9326
|
+
voiceEcho(e.message);
|
|
9327
|
+
return;
|
|
9042
9328
|
} else if (e.kind === "text_delta" && stashBuf) {
|
|
9043
9329
|
process.stdout.write("\r\x1B[K");
|
|
9044
9330
|
base.notify(e);
|
|
@@ -9050,8 +9336,11 @@ async function repl(args, ai, cfg, cwd) {
|
|
|
9050
9336
|
return;
|
|
9051
9337
|
}
|
|
9052
9338
|
if (e.kind === "revoice_done") {
|
|
9053
|
-
|
|
9054
|
-
|
|
9339
|
+
if (voiceIO) voiceEchoEnd();
|
|
9340
|
+
else {
|
|
9341
|
+
base.flushText();
|
|
9342
|
+
process.stdout.write("\n");
|
|
9343
|
+
}
|
|
9055
9344
|
voiceIO?.endSpeech();
|
|
9056
9345
|
duplexPersist();
|
|
9057
9346
|
editorRef?.resume();
|
|
@@ -9062,7 +9351,7 @@ async function repl(args, ai, cfg, cwd) {
|
|
|
9062
9351
|
const lines = String(e.data.text).split("\n");
|
|
9063
9352
|
const shown = lines.slice(0, previewLines());
|
|
9064
9353
|
err("\r\x1B[0J\n" + dim(` \u29BF ${e.message}
|
|
9065
|
-
`) + shown.map((l) => dim(` ${l}
|
|
9354
|
+
`) + shown.map((l) => dim(` ${plainLine(l)}
|
|
9066
9355
|
`)).join(""));
|
|
9067
9356
|
if (lines.length > shown.length) err(dim(` \u2026 (+${lines.length - shown.length} more lines)
|
|
9068
9357
|
`));
|
|
@@ -9276,6 +9565,11 @@ async function repl(args, ai, cfg, cwd) {
|
|
|
9276
9565
|
installCancelGuards(mounted);
|
|
9277
9566
|
const store = new SessionStore(cwd);
|
|
9278
9567
|
let session = startSession(args, store, face, cwd);
|
|
9568
|
+
if (session.meta.scheduledJobs?.length) {
|
|
9569
|
+
scheduler.restore(session.meta.scheduledJobs);
|
|
9570
|
+
err(dim(` \u23F0 ${scheduler.size} scheduled job(s) re-armed
|
|
9571
|
+
`));
|
|
9572
|
+
}
|
|
9279
9573
|
const checkpoints = args.vfs || args.boddb ? new CheckpointStack(agent.options.fs) : new GitCheckpoints({ workTree: cwd, gitDir: join9(cwd, ".agent", "checkpoints.git"), addDirs: args.addDirs, sessionId: session.meta.id });
|
|
9280
9574
|
const cpHooks = checkpoints.hooks?.();
|
|
9281
9575
|
if (cpHooks) work.hooks = composeHooks(work.hooks, cpHooks);
|
|
@@ -9329,6 +9623,11 @@ async function repl(args, ai, cfg, cwd) {
|
|
|
9329
9623
|
goalTurns = m.goalTurns ?? 0;
|
|
9330
9624
|
goalTokens = m.goalTokens ?? 0;
|
|
9331
9625
|
goalLastReason = m.goalLastReason;
|
|
9626
|
+
if (m.scheduledJobs?.length) {
|
|
9627
|
+
scheduler.restore(m.scheduledJobs);
|
|
9628
|
+
err(dim(` \u23F0 ${scheduler.size} scheduled job(s) re-armed
|
|
9629
|
+
`));
|
|
9630
|
+
}
|
|
9332
9631
|
err(dim(` resumed ${data.meta.id} (${data.meta.turns} turns)${data.meta.title ? " \u2014 " + data.meta.title : ""}
|
|
9333
9632
|
`));
|
|
9334
9633
|
if (goalCondition) err(dim(` \u25CE goal active: ${goalCondition} (${goalTurns} turns)
|
|
@@ -9403,7 +9702,7 @@ async function repl(args, ai, cfg, cwd) {
|
|
|
9403
9702
|
const turn = async (task) => {
|
|
9404
9703
|
const r = await runTurn(face, store, session, task, duplex ? void 0 : checkpoints, cwd, sendVia);
|
|
9405
9704
|
if (voiceIO) {
|
|
9406
|
-
|
|
9705
|
+
voiceEchoEnd();
|
|
9407
9706
|
editorRef?.resume();
|
|
9408
9707
|
}
|
|
9409
9708
|
voiceIO?.endSpeech();
|
|
@@ -9414,6 +9713,7 @@ async function repl(args, ai, cfg, cwd) {
|
|
|
9414
9713
|
}
|
|
9415
9714
|
return r;
|
|
9416
9715
|
};
|
|
9716
|
+
scheduleTurn = turn;
|
|
9417
9717
|
const runSkill = async (sk, extra = "") => {
|
|
9418
9718
|
try {
|
|
9419
9719
|
const body = await fs.readFile(sk.path);
|
|
@@ -10298,9 +10598,13 @@ ${extra}` : body);
|
|
|
10298
10598
|
editorRef?.redrawNow();
|
|
10299
10599
|
}, 250);
|
|
10300
10600
|
},
|
|
10601
|
+
// voiceEchoEnd closes the open echo line; '\r\x1b[0J' wipes the stale prompt/footer before the
|
|
10602
|
+
// notice — every other async-chrome writer does this, and without it "✋ interrupted" overprints
|
|
10603
|
+
// the footer's leading chars (the "interrupted% ctx" glue).
|
|
10301
10604
|
onBargeIn: (phase) => {
|
|
10302
10605
|
activeTurn?.abort();
|
|
10303
|
-
|
|
10606
|
+
voiceEchoEnd();
|
|
10607
|
+
if (phase === "speaking") err("\r\x1B[0J" + yellow(" \u270B interrupted\n"));
|
|
10304
10608
|
},
|
|
10305
10609
|
onUtterance: (text) => {
|
|
10306
10610
|
voicePartial = "";
|
|
@@ -10386,6 +10690,7 @@ ${extra}` : body);
|
|
|
10386
10690
|
if (r && r !== "off") parts.push(`reasoning:${r}`);
|
|
10387
10691
|
if (verboseOutput) parts.push("verbose");
|
|
10388
10692
|
if (goalCondition) parts.push(`\u25CE goal (${goalTurns} turns)`);
|
|
10693
|
+
if (scheduler.size) parts.push(`\u23F0 ${scheduler.size} scheduled`);
|
|
10389
10694
|
if (inputStash.length) parts.push(`${inputStash.length} stashed (\u2303S to pop)`);
|
|
10390
10695
|
const taskLines = [];
|
|
10391
10696
|
if (dx) {
|
|
@@ -10454,8 +10759,20 @@ ${extra}` : body);
|
|
|
10454
10759
|
`));
|
|
10455
10760
|
quit = await dispatchLine(next) === "quit";
|
|
10456
10761
|
}
|
|
10762
|
+
while (!quit && scheduleQueue.length) {
|
|
10763
|
+
const prompt = scheduleQueue.shift();
|
|
10764
|
+
err(dim(` \u23F0 scheduled \u203A ${prompt.slice(0, 60)}${prompt.length > 60 ? "\u2026" : ""}
|
|
10765
|
+
`));
|
|
10766
|
+
await turn(prompt);
|
|
10767
|
+
}
|
|
10768
|
+
session.meta.scheduledJobs = scheduler.snapshot();
|
|
10769
|
+
try {
|
|
10770
|
+
store.save(session);
|
|
10771
|
+
} catch {
|
|
10772
|
+
}
|
|
10457
10773
|
if (quit) break;
|
|
10458
10774
|
}
|
|
10775
|
+
scheduler.destroy();
|
|
10459
10776
|
voiceIO?.stop();
|
|
10460
10777
|
if (dx) {
|
|
10461
10778
|
const running = [...dx.tasks.values()].filter((t) => t.status === "running");
|