@livx.cc/agentx 0.96.18 → 0.97.5
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/{Agent-DdhD1pGw.d.ts → Agent-B_JD31Zx.d.ts} +1 -1
- package/dist/cli.d.ts +2 -2
- package/dist/cli.js +175 -19
- package/dist/cli.js.map +1 -1
- package/dist/index.d.ts +43 -11
- package/dist/index.js +155 -17
- package/dist/index.js.map +1 -1
- package/dist/{mcp-CnzmQ8JE.d.ts → mcp-BZcizHav.d.ts} +1 -1
- package/dist/mcp.client.d.ts +2 -2
- package/dist/{tools-DtpN8Agv.d.ts → tools-DmrqMJcI.d.ts} +3 -0
- package/dist/tools.shell.d.ts +1 -1
- package/dist/tools.shell.js.map +1 -1
- package/package.json +2 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { IFilesystem } from '@livx.cc/wcli/core';
|
|
2
|
-
import { M as Message, H as HostBridge, A as AgentTool, C as ChatLike, e as MessageContent } from './tools-
|
|
2
|
+
import { M as Message, H as HostBridge, A as AgentTool, C as ChatLike, e as MessageContent } from './tools-DmrqMJcI.js';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Hooks — deterministic interception points around tool execution, run by the
|
package/dist/cli.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env bun
|
|
2
|
-
import { H as Hooks, h as RunResult, R as ReasoningEffort, A as Agent } from './Agent-
|
|
2
|
+
import { H as Hooks, h as RunResult, R as ReasoningEffort, A as Agent } from './Agent-B_JD31Zx.js';
|
|
3
3
|
import { IFilesystem } from '@livx.cc/wcli/core';
|
|
4
|
-
import { M as Message, c as ContentPart, e as MessageContent } from './tools-
|
|
4
|
+
import { M as Message, c as ContentPart, e as MessageContent } from './tools-DmrqMJcI.js';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* On-disk session store for the CLI: each conversation is one JSON file at
|
package/dist/cli.js
CHANGED
|
@@ -4581,6 +4581,77 @@ function digestRun(messages, maxChars) {
|
|
|
4581
4581
|
// src/duplex.ts
|
|
4582
4582
|
import { MemFilesystem as MemFilesystem2 } from "@livx.cc/wcli/core";
|
|
4583
4583
|
init_logging();
|
|
4584
|
+
|
|
4585
|
+
// src/voice/spokenSplitter.ts
|
|
4586
|
+
var OPEN = "<spoken>";
|
|
4587
|
+
var CLOSE = "</spoken>";
|
|
4588
|
+
var SentenceCoalescer = class _SentenceCoalescer {
|
|
4589
|
+
buf = "";
|
|
4590
|
+
static isEnd(c) {
|
|
4591
|
+
return c === "\n" || c === "." || c === "!" || c === "?" || c === "\u2026";
|
|
4592
|
+
}
|
|
4593
|
+
feed(delta) {
|
|
4594
|
+
if (delta) this.buf += delta;
|
|
4595
|
+
let cut = -1;
|
|
4596
|
+
for (let i = 0; i < this.buf.length; i++) if (_SentenceCoalescer.isEnd(this.buf[i])) cut = i;
|
|
4597
|
+
if (cut < 0) return "";
|
|
4598
|
+
const ready = this.buf.slice(0, cut + 1).trim();
|
|
4599
|
+
this.buf = this.buf.slice(cut + 1);
|
|
4600
|
+
return ready;
|
|
4601
|
+
}
|
|
4602
|
+
flush() {
|
|
4603
|
+
const s = this.buf.trim();
|
|
4604
|
+
this.buf = "";
|
|
4605
|
+
return s;
|
|
4606
|
+
}
|
|
4607
|
+
};
|
|
4608
|
+
var SpokenSplitter = class {
|
|
4609
|
+
buf = "";
|
|
4610
|
+
inSpoken = false;
|
|
4611
|
+
/** True once any spoken char has ever been emitted (drives the no-spoken fallback). */
|
|
4612
|
+
spokeAny = false;
|
|
4613
|
+
/** Feed a delta; returns the spoken/detail spans completed by this chunk (either may be ''). */
|
|
4614
|
+
feed(delta) {
|
|
4615
|
+
this.buf += delta;
|
|
4616
|
+
return this.drain(false);
|
|
4617
|
+
}
|
|
4618
|
+
/** Drain any buffered partial. A trailing `<…` that never completed a tag is emitted as detail. */
|
|
4619
|
+
flush() {
|
|
4620
|
+
return this.drain(true);
|
|
4621
|
+
}
|
|
4622
|
+
drain(final) {
|
|
4623
|
+
let spoken = "";
|
|
4624
|
+
let detail = "";
|
|
4625
|
+
while (this.buf.length) {
|
|
4626
|
+
const tag = this.inSpoken ? CLOSE : OPEN;
|
|
4627
|
+
const idx = this.buf.indexOf(tag);
|
|
4628
|
+
if (idx >= 0) {
|
|
4629
|
+
const text2 = this.buf.slice(0, idx);
|
|
4630
|
+
if (this.inSpoken) spoken += text2;
|
|
4631
|
+
else detail += text2;
|
|
4632
|
+
this.buf = this.buf.slice(idx + tag.length);
|
|
4633
|
+
this.inSpoken = !this.inSpoken;
|
|
4634
|
+
continue;
|
|
4635
|
+
}
|
|
4636
|
+
const lt = this.buf.lastIndexOf("<");
|
|
4637
|
+
const holdStart = lt >= 0 && tag.startsWith(this.buf.slice(lt)) ? lt : this.buf.length;
|
|
4638
|
+
const text = this.buf.slice(0, holdStart);
|
|
4639
|
+
if (this.inSpoken) spoken += text;
|
|
4640
|
+
else detail += text;
|
|
4641
|
+
this.buf = this.buf.slice(holdStart);
|
|
4642
|
+
break;
|
|
4643
|
+
}
|
|
4644
|
+
if (final && this.buf) {
|
|
4645
|
+
if (this.inSpoken) spoken += this.buf;
|
|
4646
|
+
else detail += this.buf;
|
|
4647
|
+
this.buf = "";
|
|
4648
|
+
}
|
|
4649
|
+
if (spoken.trim()) this.spokeAny = true;
|
|
4650
|
+
return { spoken, detail };
|
|
4651
|
+
}
|
|
4652
|
+
};
|
|
4653
|
+
|
|
4654
|
+
// src/duplex.ts
|
|
4584
4655
|
var log8 = forComponent("DuplexAgent");
|
|
4585
4656
|
function describeCall(call) {
|
|
4586
4657
|
const v = call.args && Object.values(call.args).find((x) => typeof x === "string" && x.trim());
|
|
@@ -4648,7 +4719,7 @@ var DuplexAgentOptions = class {
|
|
|
4648
4719
|
};
|
|
4649
4720
|
var RESERVED_EVENT_MARKER = /\[task\b[^\]\n]*\b(?:completed|failed|progress|asks)\b/i;
|
|
4650
4721
|
var RESERVED_EVENT_OPENER = /\[\s*task\b/i;
|
|
4651
|
-
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 cannot mute the microphone or stop voice capture yourself \u2014 no tool does it. If the user asks you to stop listening or turn the voice off, never claim you did: tell them to say exactly "voice off" (handled by the app directly), or type /voice.\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.\
|
|
4722
|
+
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 cannot mute the microphone or stop voice capture yourself \u2014 no tool does it. If the user asks you to stop listening or turn the voice off, never claim you did: tell them to say exactly "voice off" (handled by the app directly), or type /voice.\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.\nA completed task speaks its OWN result to the user (the worker voices what matters as it finishes) \u2014 you do NOT re-voice clean task results. A FAILED or INCOMPLETE task still arrives as a "[task t1 failed] \u2026" event for you to handle. 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, surprising, or only half-parses, do NOT guess an action or improvise content from it \u2014 briefly confirm what they meant ("did you mean\u2026?") and wait. A one-line confirm beats a confident wrong answer or an invented response to a request you did not actually understand.';
|
|
4652
4723
|
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.";
|
|
4653
4724
|
var THINK_DISABLED_GUIDANCE = "(Think tier is not available \u2014 use Act for all escalations.)";
|
|
4654
4725
|
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).`;
|
|
@@ -4923,13 +4994,14 @@ Today's date: ${(/* @__PURE__ */ new Date()).toDateString()}.`;
|
|
|
4923
4994
|
* Act briefs get a self-verify footer — the worker's report is trusted without review, so it
|
|
4924
4995
|
* must check its own work before reporting (nearly free under prompt caching; measured honest:
|
|
4925
4996
|
* it does NOT fix one-shot logic bugs — see mind/10). Think tasks are pure reasoning — no footer. */
|
|
4926
|
-
buildBrief(brief, tier = "act") {
|
|
4997
|
+
buildBrief(brief, tier = "act", deliver = true) {
|
|
4927
4998
|
const recent = this.voice.transcript.filter((m) => (m.role === "user" || m.role === "assistant") && contentText(m.content).trim()).slice(-this.options.excerptTurns).map((m) => `${m.role}: ${contentText(m.content)}`).join("\n");
|
|
4928
4999
|
const verify = tier === "act" ? "\n\nBefore reporting done: re-read what you changed and check it against EVERY requirement above \u2014 fix any gap first. Your report is trusted without review." : "";
|
|
5000
|
+
const deliverContract = deliver ? "\n\n## DELIVER (spoken delivery)\nYou are reporting back to a user who is LISTENING. Stream your work normally \u2014 your prose is the written work record and detail, and is NOT spoken. Wrap anything the user should HEAR in <spoken>\u2026</spoken> tags. LEAD WITH the actual content they asked for: if they asked for a specific piece of content \u2014 a value, a name, the actual lines, the writing itself \u2014 that content goes INSIDE the <spoken> tags, not a remark about it. Your FIRST <spoken> segment is substantive \u2014 never a greeting or an acknowledgement (the front-end has already acked; do not double-ack). Keep spoken text concise and natural for the ear: short sentences, no markdown." : "";
|
|
4929
5001
|
return (recent ? `${brief}
|
|
4930
5002
|
|
|
4931
5003
|
## Recent conversation (for context)
|
|
4932
|
-
${recent}` : brief) + verify;
|
|
5004
|
+
${recent}` : brief) + verify + deliverContract;
|
|
4933
5005
|
}
|
|
4934
5006
|
/** Spawn a detached worker for task `id`; its settlement notifies + enqueues the re-voice turn. */
|
|
4935
5007
|
spawnWorker(id, label, briefText, tier, brief, followUp) {
|
|
@@ -4968,7 +5040,28 @@ ${recent}` : brief) + verify;
|
|
|
4968
5040
|
const a = await this.parkQuestion(id, `${q2.question}${opts}`);
|
|
4969
5041
|
return a || "(no answer from the user \u2014 use your best judgment and note the assumption)";
|
|
4970
5042
|
};
|
|
4971
|
-
const
|
|
5043
|
+
const splitter = new SpokenSplitter();
|
|
5044
|
+
const speak = (seg) => {
|
|
5045
|
+
if (seg) o.host?.notify?.({ kind: "speak_utterance", message: seg });
|
|
5046
|
+
};
|
|
5047
|
+
const coalescer = new SentenceCoalescer();
|
|
5048
|
+
const feedSpoken = (s) => {
|
|
5049
|
+
const ready = coalescer.feed(s);
|
|
5050
|
+
if (ready) speak(ready);
|
|
5051
|
+
};
|
|
5052
|
+
const flushSpoken = () => speak(coalescer.flush());
|
|
5053
|
+
const askBridge = o.askRelay ? { ask: relayAsk } : o.host?.ask ? { ask: (q2) => o.host.ask(q2) } : {};
|
|
5054
|
+
const workerHost = {
|
|
5055
|
+
...askBridge,
|
|
5056
|
+
notify: (ev) => {
|
|
5057
|
+
if (ev?.kind === "text_delta" && typeof ev.message === "string") {
|
|
5058
|
+
const { spoken, detail } = splitter.feed(ev.message);
|
|
5059
|
+
feedSpoken(spoken);
|
|
5060
|
+
if (detail.trim()) pushTail(detail.trim());
|
|
5061
|
+
return;
|
|
5062
|
+
}
|
|
5063
|
+
}
|
|
5064
|
+
};
|
|
4972
5065
|
const agentOpts = {
|
|
4973
5066
|
ai: o.ai,
|
|
4974
5067
|
fs: o.fs,
|
|
@@ -4978,13 +5071,22 @@ ${recent}` : brief) + verify;
|
|
|
4978
5071
|
// Recompute providerOptions for THIS worker's model (after tierOpts so it wins over any inherited
|
|
4979
5072
|
// main-template value) — prevents cursor-only cwd/cursorSession leaking onto an anthropic worker.
|
|
4980
5073
|
providerOptions: o.providerOptionsFor?.(tierModel),
|
|
4981
|
-
|
|
5074
|
+
stream: true,
|
|
5075
|
+
// worker streams text_delta so the splitter can extract <spoken> live (after tierOpts: never overridden off)
|
|
5076
|
+
host: workerHost,
|
|
5077
|
+
// carries BOTH ask AND the <spoken>-splitting notify
|
|
4982
5078
|
...hooks ? { hooks } : {},
|
|
4983
5079
|
signal: controller.signal
|
|
4984
5080
|
// shared with the checker so a cancel tears down both
|
|
4985
5081
|
};
|
|
4986
|
-
const promise = new Agent(agentOpts).run(briefText).then((res) =>
|
|
4987
|
-
|
|
5082
|
+
const promise = new Agent(agentOpts).run(briefText).then((res) => {
|
|
5083
|
+
const { spoken, detail } = splitter.flush();
|
|
5084
|
+
feedSpoken(spoken);
|
|
5085
|
+
if (detail.trim()) pushTail(detail.trim());
|
|
5086
|
+
flushSpoken();
|
|
5087
|
+
return res;
|
|
5088
|
+
}).then((res) => this.maybeVerify(id, brief, res, tier, agentOpts, askBridge)).then((res) => this.onWorkerSettled(id, res)).catch((err2) => this.onWorkerFailed(id, err2));
|
|
5089
|
+
this.tasks.set(id, { id, label, status: "running", controller, promise, tail, brief, followUp, splitter });
|
|
4988
5090
|
if (this.tasks.size > this.options.maxTaskRecords)
|
|
4989
5091
|
for (const [tid, rec] of this.tasks) {
|
|
4990
5092
|
if (this.tasks.size <= this.options.maxTaskRecords) break;
|
|
@@ -4996,15 +5098,20 @@ ${recent}` : brief) + verify;
|
|
|
4996
5098
|
* on the shared fs automatically (workers write fs directly, no overlay), so grading sees the
|
|
4997
5099
|
* corrected state. Bounded to ONE pass. Off unless `verifyActTasks`; never runs for think/failed/
|
|
4998
5100
|
* cancelled tasks. Usage is merged so /cost reflects the real (worker + checker) spend. */
|
|
4999
|
-
async maybeVerify(id,
|
|
5101
|
+
async maybeVerify(id, brief, res, tier, agentOpts, askBridge) {
|
|
5000
5102
|
if (!this.options.verifyActTasks || tier !== "act" || res.finishReason !== "stop") return res;
|
|
5001
5103
|
if (this.tasks.get(id)?.status === "cancelled") return res;
|
|
5002
|
-
const
|
|
5104
|
+
const { stream: _stream, host: _host, ...restOpts } = agentOpts;
|
|
5105
|
+
const checkerOpts = {
|
|
5106
|
+
...restOpts,
|
|
5107
|
+
...askBridge.ask ? { host: { ask: askBridge.ask } } : {}
|
|
5108
|
+
};
|
|
5109
|
+
const checkBrief = `${this.buildBrief(brief, tier, false)}
|
|
5003
5110
|
|
|
5004
5111
|
## VERIFY MODE
|
|
5005
5112
|
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".`;
|
|
5006
5113
|
this.notify("task_verify", `task ${id}: verifying`, { id });
|
|
5007
|
-
const cres = await new Agent(
|
|
5114
|
+
const cres = await new Agent(checkerOpts).run(checkBrief);
|
|
5008
5115
|
if (cres.finishReason !== "stop") {
|
|
5009
5116
|
log8.warn(`task ${id}: verify inconclusive (${cres.finishReason})`);
|
|
5010
5117
|
this.notify("task_verify", `task ${id}: verify inconclusive (${cres.finishReason})`, { id, finishReason: cres.finishReason });
|
|
@@ -5095,12 +5202,14 @@ Another agent just implemented the above. Independently check the CURRENT state
|
|
|
5095
5202
|
dropAsk(id) {
|
|
5096
5203
|
this.pendingAsks.get(id)?.resolve("");
|
|
5097
5204
|
}
|
|
5098
|
-
/** Build the INTEGRATION TURN prompt for a settled worker
|
|
5099
|
-
*
|
|
5100
|
-
*
|
|
5205
|
+
/** Build the INTEGRATION TURN prompt for a NON-CLEAN settled worker (early stop / failure). A clean
|
|
5206
|
+
* success never reaches here — it streams its own `<spoken>` delivery during the run. For a partial
|
|
5207
|
+
* or failed result the outcome re-enters the reflex as a decision (like a tool_result flowing back
|
|
5208
|
+
* into a normal agent loop): the reflex evaluates the outcome against the original intent and chooses
|
|
5209
|
+
* what to do next.
|
|
5101
5210
|
*
|
|
5102
5211
|
* Decision branches (the reflex acts on them with EXISTING tools — no new surface):
|
|
5103
|
-
* • accept →
|
|
5212
|
+
* • accept → SPEAK the (partial) result plainly — don't dress a failure up as success.
|
|
5104
5213
|
* • escalate → call `Think` with the SAME brief — only when Act failed/stalled AND a Think tier
|
|
5105
5214
|
* exists AND this task wasn't already a follow-up (one hop max). Wires the dead
|
|
5106
5215
|
* "Reserve Think for a problem Act already FAILED at" promise.
|
|
@@ -5111,8 +5220,6 @@ Another agent just implemented the above. Independently check the CURRENT state
|
|
|
5111
5220
|
* failed-revoice fallback still fire, and the per-event transcript markers stay intact. */
|
|
5112
5221
|
integrationPrompt(rec, outcome, body, finishReason) {
|
|
5113
5222
|
const opener = outcome === "error" ? `[task ${rec.id} failed]` : `[task ${rec.id} completed]`;
|
|
5114
|
-
if (outcome === "ok")
|
|
5115
|
-
return `${opener} ${body}`;
|
|
5116
5223
|
const underCap = this.autoEscalations < _DuplexAgent.MAX_AUTO_ESCALATIONS;
|
|
5117
5224
|
const canEscalate = (outcome === "error" || outcome === "incomplete") && underCap;
|
|
5118
5225
|
const hasThink = this.options.thinkModel !== false;
|
|
@@ -5152,7 +5259,14 @@ Another agent just implemented the above. Independently check the CURRENT state
|
|
|
5152
5259
|
steps: res.steps,
|
|
5153
5260
|
toolCalls: res.messages.filter((m) => m.role === "tool").length
|
|
5154
5261
|
});
|
|
5155
|
-
|
|
5262
|
+
if (incomplete) {
|
|
5263
|
+
return this.queueRevoice(this.integrationPrompt(rec, "incomplete", res.text, res.finishReason), true);
|
|
5264
|
+
}
|
|
5265
|
+
const tail = rec.splitter?.flush();
|
|
5266
|
+
if (tail?.spoken) this.options.host?.notify?.({ kind: "speak_utterance", message: tail.spoken });
|
|
5267
|
+
if (res.text.trim()) this.voice.transcript.push({ role: "assistant", content: res.text });
|
|
5268
|
+
if (!rec.splitter?.spokeAny && res.text.trim())
|
|
5269
|
+
this.options.host?.notify?.({ kind: "speak_utterance", message: res.text });
|
|
5156
5270
|
}
|
|
5157
5271
|
onWorkerFailed(id, err2) {
|
|
5158
5272
|
this.failTask(this.tasks.get(id), err2 instanceof Error ? err2.message : String(err2));
|
|
@@ -5576,6 +5690,9 @@ var VoiceEngine = class _VoiceEngine {
|
|
|
5576
5690
|
resumeTimer = null;
|
|
5577
5691
|
turnStartAt = 0;
|
|
5578
5692
|
// timestamp when the current turn began (for TTFT logging)
|
|
5693
|
+
// Central speech queue (above the TTS context): complete worker utterances serialize into ONE
|
|
5694
|
+
// playback stream, one-at-a-time, never splicing into the live reflex's open utterance.
|
|
5695
|
+
uttQueue = [];
|
|
5579
5696
|
constructor(options) {
|
|
5580
5697
|
this.options = { ...new VoiceEngineOptions(), ...options };
|
|
5581
5698
|
const o = this.options;
|
|
@@ -5674,6 +5791,7 @@ var VoiceEngine = class _VoiceEngine {
|
|
|
5674
5791
|
this.echoUntil = now() + 2500;
|
|
5675
5792
|
if (!this.usingAec) this.stt.reset();
|
|
5676
5793
|
this.setState("listening");
|
|
5794
|
+
if (this.uttQueue.length) this.pumpQueue();
|
|
5677
5795
|
};
|
|
5678
5796
|
const drainThenSettle = () => {
|
|
5679
5797
|
if (this.drainTimer) clearTimeout(this.drainTimer);
|
|
@@ -5700,8 +5818,27 @@ var VoiceEngine = class _VoiceEngine {
|
|
|
5700
5818
|
this.speakDelta(text);
|
|
5701
5819
|
this.endSpeech();
|
|
5702
5820
|
}
|
|
5821
|
+
/** Enqueue a COMPLETE worker utterance (already-split spoken text) onto the central speech queue.
|
|
5822
|
+
* If nothing is currently speaking it plays immediately; otherwise it queues and plays after the
|
|
5823
|
+
* current utterance fully ends (settle → pumpQueue) — never spliced into an open reflex utterance. */
|
|
5824
|
+
enqueueUtterance(text) {
|
|
5825
|
+
if (!text || !text.trim()) return;
|
|
5826
|
+
this.uttQueue.push(text);
|
|
5827
|
+
if (!this.speaking) this.pumpQueue();
|
|
5828
|
+
}
|
|
5829
|
+
/** Play the next queued worker utterance as its own one-shot turn (begin → delta → end). Drives the
|
|
5830
|
+
* next one from the settle completion (endSpeech), so utterances serialize without overlap. */
|
|
5831
|
+
pumpQueue() {
|
|
5832
|
+
if (this.speaking) return;
|
|
5833
|
+
const text = this.uttQueue.shift();
|
|
5834
|
+
if (text == null) return;
|
|
5835
|
+
this.beginSpeech();
|
|
5836
|
+
this.speakDelta(text);
|
|
5837
|
+
this.endSpeech();
|
|
5838
|
+
}
|
|
5703
5839
|
/** barge-in: stop audio NOW, cancel generation, reset for the user's utterance */
|
|
5704
5840
|
interrupt() {
|
|
5841
|
+
this.uttQueue = [];
|
|
5705
5842
|
if (!this.speaking && !this.drainTimer) return;
|
|
5706
5843
|
if (this.drainTimer) {
|
|
5707
5844
|
clearTimeout(this.drainTimer);
|
|
@@ -5723,6 +5860,7 @@ var VoiceEngine = class _VoiceEngine {
|
|
|
5723
5860
|
this.setState("listening");
|
|
5724
5861
|
}
|
|
5725
5862
|
stop() {
|
|
5863
|
+
this.uttQueue = [];
|
|
5726
5864
|
if (this.resumeTimer) clearTimeout(this.resumeTimer);
|
|
5727
5865
|
if (this.pendingTimer) clearTimeout(this.pendingTimer);
|
|
5728
5866
|
if (this.drainTimer) clearTimeout(this.drainTimer);
|
|
@@ -11510,6 +11648,23 @@ async function repl(args, ai, cfg, cwd) {
|
|
|
11510
11648
|
...base,
|
|
11511
11649
|
notify(e) {
|
|
11512
11650
|
if (voiceIO && (e.kind === "thinking_delta" || e.kind === "turn_start")) return;
|
|
11651
|
+
if (e.kind === "speak_utterance") {
|
|
11652
|
+
if (voiceIO) {
|
|
11653
|
+
spinner.stop();
|
|
11654
|
+
voiceIO.enqueueUtterance(e.message);
|
|
11655
|
+
editorRef?.suspend();
|
|
11656
|
+
voiceEcho(e.message);
|
|
11657
|
+
voiceEchoEnd();
|
|
11658
|
+
editorRef?.resume();
|
|
11659
|
+
editorRef?.redrawNow();
|
|
11660
|
+
} else {
|
|
11661
|
+
err("\r\x1B[0J" + dim(` \u29BF ${plainLine(e.message)}
|
|
11662
|
+
`));
|
|
11663
|
+
editorRef?.redrawNow();
|
|
11664
|
+
repaintStash();
|
|
11665
|
+
}
|
|
11666
|
+
return;
|
|
11667
|
+
}
|
|
11513
11668
|
if (e.kind === "text_delta" && voiceIO) {
|
|
11514
11669
|
spinner.stop();
|
|
11515
11670
|
voiceIO.speakDelta(e.message);
|
|
@@ -13214,8 +13369,9 @@ ${out}
|
|
|
13214
13369
|
return;
|
|
13215
13370
|
}
|
|
13216
13371
|
const cut = voiceIO.takeInterruptedReply();
|
|
13217
|
-
const note = cut
|
|
13218
|
-
[the user interrupted you mid-speech \u2014 they only heard up to: "\u2026${cut.heard.slice(-80)}". Work any unheard essentials into your reply naturally, only if still relevant.]` :
|
|
13372
|
+
const note = !cut || cut.full.length - cut.heard.length <= 40 ? "" : cut.heard.trim() ? `
|
|
13373
|
+
[the user interrupted you mid-speech \u2014 they only heard up to: "\u2026${cut.heard.slice(-80)}". Work any unheard essentials into your reply naturally, only if still relevant.]` : `
|
|
13374
|
+
[the user interrupted you before hearing any of your previous reply \u2014 none of it landed; do not assume they got it.]`;
|
|
13219
13375
|
if (!/^[!#/]/.test(text.trim())) voiceIO.beginSpeech(true);
|
|
13220
13376
|
err(`\r\x1B[K ${bold(cyan("\u{1F3A4} \u203A"))} ${text}
|
|
13221
13377
|
`);
|