agent.libx.js 0.93.26 → 0.93.28
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 +89 -80
- package/dist/cli.js.map +1 -1
- package/dist/index.d.ts +64 -1
- package/dist/index.js +159 -57
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -374,6 +374,69 @@ declare function makeWebSearchTool(options?: WebSearchOptions): AgentTool;
|
|
|
374
374
|
declare const webFetchTool: AgentTool;
|
|
375
375
|
declare const webSearchTool: AgentTool;
|
|
376
376
|
|
|
377
|
+
/**
|
|
378
|
+
* Scratch — keep large tool/subagent outputs OUT of the main context, but queryable AS FILES.
|
|
379
|
+
*
|
|
380
|
+
* Pattern: many-tool / many-subagent engines bloat context with raw outputs (search results, big
|
|
381
|
+
* file reads, subagent reports) that are mostly noise once a gist is taken. Here, a tool wrapped with
|
|
382
|
+
* `Scratch.capture` writes any oversized result to an ephemeral scratch filesystem (a real VFS) and
|
|
383
|
+
* returns a compact stub (path + preview) to context. To recover a buried detail later you do NOT
|
|
384
|
+
* re-bloat context — you peek with the FILE tools already on hand:
|
|
385
|
+
* • Grep/Glob/Read over the scratch dir — returns matching lines, not the blob (a free, light peek).
|
|
386
|
+
* • Ask({question, over?}) — a CHEAP child agent over the scratch FS that greps/reads and returns
|
|
387
|
+
* just the answer; its reasoning tokens never touch the caller's context.
|
|
388
|
+
* Two-tier division of labour: cheap RETRIEVE/EXTRACT, strong caller SYNTHESIZE.
|
|
389
|
+
*
|
|
390
|
+
* The scratch FS is injected (IoC): pass a MemFilesystem for ephemeral, or a disk-backed one under the
|
|
391
|
+
* session dir to persist across resume (CC's lesson: the filesystem is the durable store). Segregated
|
|
392
|
+
* module — zero Agent-core changes.
|
|
393
|
+
*/
|
|
394
|
+
|
|
395
|
+
/** Default scratch dir (a path in the injected scratch FS). */
|
|
396
|
+
declare const SCRATCH_DIR = "/scratch";
|
|
397
|
+
interface ScratchOptions {
|
|
398
|
+
/** Min result length (chars) to capture; smaller results pass through untouched. Default 1500. */
|
|
399
|
+
threshold?: number;
|
|
400
|
+
/** Dir within the scratch FS to write captures. Default SCRATCH_DIR. */
|
|
401
|
+
dir?: string;
|
|
402
|
+
/** Chars of the captured output to preview in the stub. Default 320. */
|
|
403
|
+
previewChars?: number;
|
|
404
|
+
}
|
|
405
|
+
/**
|
|
406
|
+
* Owns an (injected) scratch filesystem + a capture counter. `capture(tool)` wraps a tool so its
|
|
407
|
+
* oversized string results spill to a scratch file and are replaced in context with a stub.
|
|
408
|
+
*/
|
|
409
|
+
declare class Scratch {
|
|
410
|
+
fs: IFilesystem;
|
|
411
|
+
options: Required<ScratchOptions>;
|
|
412
|
+
private seq;
|
|
413
|
+
private dirReady?;
|
|
414
|
+
constructor(fs: IFilesystem, options?: ScratchOptions);
|
|
415
|
+
/** Number of captures so far. */
|
|
416
|
+
get count(): number;
|
|
417
|
+
/** Wrap a tool: oversized STRING results spill to a scratch file; everything else passes through. */
|
|
418
|
+
capture(tool: AgentTool): AgentTool;
|
|
419
|
+
/** Wrap many tools at once. */
|
|
420
|
+
captureAll(tools: AgentTool[]): AgentTool[];
|
|
421
|
+
}
|
|
422
|
+
interface AskOptions {
|
|
423
|
+
/** The scratch filesystem to peek into (dedicated VFS holding only scratch files). */
|
|
424
|
+
fs: IFilesystem;
|
|
425
|
+
ai: ChatLike;
|
|
426
|
+
/** Model for the peek — intentionally a CHEAP model; the caller synthesizes. */
|
|
427
|
+
model: string;
|
|
428
|
+
/** Step budget for the peek child (default 6). */
|
|
429
|
+
maxSteps?: number;
|
|
430
|
+
/** Scratch dir to search when `over` is omitted. Default SCRATCH_DIR. */
|
|
431
|
+
dir?: string;
|
|
432
|
+
}
|
|
433
|
+
/**
|
|
434
|
+
* `Ask` — peek into the scratch FS to answer a question WITHOUT loading raw data into the caller's
|
|
435
|
+
* context. Spawns a cheap child agent (Read/Grep/Glob over scratch) that greps/reads and returns just
|
|
436
|
+
* the answer. Pass `over` (a path) for a targeted peek, or omit to grep-discover.
|
|
437
|
+
*/
|
|
438
|
+
declare function makeAskTool(o: AskOptions): AgentTool;
|
|
439
|
+
|
|
377
440
|
/**
|
|
378
441
|
* `AskUserQuestion` tool — lets the model pose a structured choice to a human.
|
|
379
442
|
* Delegates to `ctx.host.ask`. Registered only when a HostBridge is provided
|
|
@@ -1075,4 +1138,4 @@ declare class CartesiaTTS {
|
|
|
1075
1138
|
close(): void;
|
|
1076
1139
|
}
|
|
1077
1140
|
|
|
1078
|
-
export { Agent, type AgentDef, AgentOptions, AgentTool, type Attempt, type AudioSink, type AudioSource, type AuthProvider, BodDbFilesystem, CartesiaTTS, CartesiaTTSOptions, ChatLike, ChatOptions, ChatResponse, type CommandInfo, ConsoleHostBridge, DEFAULT_DENY, DuplexAgent, DuplexAgentOptions, type DuplexTaskStatus, FakeAIClient, Hooks, HostBridge, JailOptions, JailedFilesystem, type LessonOptions, LessonOptionsDefaults, type LoadMemoryOpts, MEMORY_PROMPT, MessageContent, type Mount, MountFilesystem, NodeDiskFilesystem, OverlayFilesystem, type ReflectOptions, RunResult, STT_SAMPLE_RATE, ScriptedHostBridge, type SkillInfo, SonioxSTT, SonioxSTTOptions, type SttLike, TTS_SAMPLE_RATE, type TaskRecord, type TaskToolOptions, ToolCall, type ToolSpec, type TtsLike, UserQuestion, VOICE_MEMORY_PROMPT, VOICE_SYSTEM_PROMPT, VoiceEngine, VoiceEngineOptions, type VoiceState, type WebFetchOptions, type WebSearchOptions, type WorkerTier, applyEditsTool, askUserQuestionTool, checkpointTool, checkpointTools, compileSynthesizedTool, decodeDdgUrl, diskAgentOptions, expandCommand, expandTemplate, forComponent, fullAgentOptions, globTool, grepTool, htmlToText, idfWeights, lessonCapture, loadAgents, loadCommands, loadInstructions, loadMemory, loadSkills, makeTaskBatchTool, makeTaskTool, makeWebFetchTool, makeWebSearchTool, mkdirp, multiEditTool, parseDdgHtml, raceAttempts, reflectOnRun, relevanceScore, repoIndex, repoMapTool, resolveAuth, rollbackTool, sandboxAgentOptions, slugify, tokenize, toolCall, topByRelevance, validateToolCode, webFetchTool, webSearchTool, writeFact, writeTool };
|
|
1141
|
+
export { Agent, type AgentDef, AgentOptions, AgentTool, type AskOptions, type Attempt, type AudioSink, type AudioSource, type AuthProvider, BodDbFilesystem, CartesiaTTS, CartesiaTTSOptions, ChatLike, ChatOptions, ChatResponse, type CommandInfo, ConsoleHostBridge, DEFAULT_DENY, DuplexAgent, DuplexAgentOptions, type DuplexTaskStatus, FakeAIClient, Hooks, HostBridge, JailOptions, JailedFilesystem, type LessonOptions, LessonOptionsDefaults, type LoadMemoryOpts, MEMORY_PROMPT, MessageContent, type Mount, MountFilesystem, NodeDiskFilesystem, OverlayFilesystem, type ReflectOptions, RunResult, SCRATCH_DIR, STT_SAMPLE_RATE, Scratch, type ScratchOptions, ScriptedHostBridge, type SkillInfo, SonioxSTT, SonioxSTTOptions, type SttLike, TTS_SAMPLE_RATE, type TaskRecord, type TaskToolOptions, ToolCall, type ToolSpec, type TtsLike, UserQuestion, VOICE_MEMORY_PROMPT, VOICE_SYSTEM_PROMPT, VoiceEngine, VoiceEngineOptions, type VoiceState, type WebFetchOptions, type WebSearchOptions, type WorkerTier, applyEditsTool, askUserQuestionTool, checkpointTool, checkpointTools, compileSynthesizedTool, decodeDdgUrl, diskAgentOptions, expandCommand, expandTemplate, forComponent, fullAgentOptions, globTool, grepTool, htmlToText, idfWeights, lessonCapture, loadAgents, loadCommands, loadInstructions, loadMemory, loadSkills, makeAskTool, makeTaskBatchTool, makeTaskTool, makeWebFetchTool, makeWebSearchTool, mkdirp, multiEditTool, parseDdgHtml, raceAttempts, reflectOnRun, relevanceScore, repoIndex, repoMapTool, resolveAuth, rollbackTool, sandboxAgentOptions, slugify, tokenize, toolCall, topByRelevance, validateToolCode, webFetchTool, webSearchTool, writeFact, writeTool };
|
package/dist/index.js
CHANGED
|
@@ -1998,9 +1998,9 @@ async function loadCommands(fs, dir, opts = {}) {
|
|
|
1998
1998
|
properties: { name: { type: "string" }, args: { type: "string", description: "arguments to fill the template" } }
|
|
1999
1999
|
},
|
|
2000
2000
|
async run({ name, args }, ctx) {
|
|
2001
|
-
const
|
|
2002
|
-
const c = commands.find((x) => x.name ===
|
|
2003
|
-
if (!c) return `Error: no command named '${
|
|
2001
|
+
const slug2 = String(name ?? "").replace(/^\//, "");
|
|
2002
|
+
const c = commands.find((x) => x.name === slug2);
|
|
2003
|
+
if (!c) return `Error: no command named '${slug2}'. Available: ${commands.map((x) => x.name).join(", ")}`;
|
|
2004
2004
|
return expandCommand(ctx.fs, c, String(args ?? ""));
|
|
2005
2005
|
}
|
|
2006
2006
|
};
|
|
@@ -2035,9 +2035,9 @@ async function loadMemory(fs, dir, opts = {}) {
|
|
|
2035
2035
|
const lines = md.split("\n");
|
|
2036
2036
|
if (!header) header = lines.filter((l) => !/^\s*-\s*\[.+\]\(.+\.md\)/.test(l)).join("\n").trim();
|
|
2037
2037
|
for (const l of lines.filter((l2) => /^\s*-\s*\[.+\]\(.+\.md\)/.test(l2))) {
|
|
2038
|
-
const
|
|
2039
|
-
if (
|
|
2040
|
-
seenSlugs.add(
|
|
2038
|
+
const slug2 = l.match(/\]\(([^)]+)\.md\)/)?.[1];
|
|
2039
|
+
if (slug2 && !seenSlugs.has(slug2)) {
|
|
2040
|
+
seenSlugs.add(slug2);
|
|
2041
2041
|
allPointers.push(l);
|
|
2042
2042
|
}
|
|
2043
2043
|
}
|
|
@@ -2053,20 +2053,20 @@ function slugify(s, fallback = "note") {
|
|
|
2053
2053
|
const base = String(s ?? "").trim().toLowerCase().replace(/\.md$/i, "").replace(/[^\w\s-]/g, "").replace(/[\s_]+/g, "-").replace(/-+/g, "-").replace(/^-|-$/g, "").slice(0, 48);
|
|
2054
2054
|
return base || fallback;
|
|
2055
2055
|
}
|
|
2056
|
-
async function writeFact(fs, dir,
|
|
2056
|
+
async function writeFact(fs, dir, slug2, body, opts) {
|
|
2057
2057
|
await mkdirp(fs, dir);
|
|
2058
2058
|
const content = opts?.type ? `---
|
|
2059
2059
|
type: ${opts.type}
|
|
2060
2060
|
---
|
|
2061
2061
|
|
|
2062
2062
|
${body}` : body;
|
|
2063
|
-
await fs.writeFile(`${dir}/${
|
|
2063
|
+
await fs.writeFile(`${dir}/${slug2}.md`, content.endsWith("\n") ? content : content + "\n");
|
|
2064
2064
|
const indexPath = `${dir}/MEMORY.md`;
|
|
2065
2065
|
const idx = await fs.exists(indexPath) ? await fs.readFile(indexPath) : "# Memory Index\n";
|
|
2066
2066
|
const summary = opts?.description || body.split("\n")[0].slice(0, 80);
|
|
2067
|
-
const line = `- [${
|
|
2067
|
+
const line = `- [${slug2}](${slug2}.md) \u2014 ${summary}`;
|
|
2068
2068
|
const lines = idx.split("\n");
|
|
2069
|
-
const at = lines.findIndex((l) => l.includes(`(${
|
|
2069
|
+
const at = lines.findIndex((l) => l.includes(`(${slug2}.md)`));
|
|
2070
2070
|
if (at >= 0) {
|
|
2071
2071
|
if (lines[at] !== line) {
|
|
2072
2072
|
lines[at] = line;
|
|
@@ -2117,8 +2117,8 @@ async function listSlugs(fs, dir, prefix = "") {
|
|
|
2117
2117
|
}
|
|
2118
2118
|
return out;
|
|
2119
2119
|
}
|
|
2120
|
-
async function loadFact(fs, dir,
|
|
2121
|
-
const path = `${dir}/${
|
|
2120
|
+
async function loadFact(fs, dir, slug2) {
|
|
2121
|
+
const path = `${dir}/${slug2}.md`;
|
|
2122
2122
|
try {
|
|
2123
2123
|
const raw = await fs.readFile(path);
|
|
2124
2124
|
const { body } = splitFrontmatter(raw);
|
|
@@ -2127,9 +2127,9 @@ async function loadFact(fs, dir, slug) {
|
|
|
2127
2127
|
return null;
|
|
2128
2128
|
}
|
|
2129
2129
|
}
|
|
2130
|
-
async function loadFactMulti(fs, dirs,
|
|
2130
|
+
async function loadFactMulti(fs, dirs, slug2) {
|
|
2131
2131
|
for (const d of dirs) {
|
|
2132
|
-
const r = await loadFact(fs, d,
|
|
2132
|
+
const r = await loadFact(fs, d, slug2);
|
|
2133
2133
|
if (r != null) return r;
|
|
2134
2134
|
}
|
|
2135
2135
|
return null;
|
|
@@ -2155,9 +2155,9 @@ function recallTool(fs, dirs) {
|
|
|
2155
2155
|
pattern: { type: "string", description: 'glob pattern to match against slugs (e.g. "auth*", "*database*")' }
|
|
2156
2156
|
}
|
|
2157
2157
|
},
|
|
2158
|
-
async run({ slug, slugs, pattern }, ctx) {
|
|
2158
|
+
async run({ slug: slug2, slugs, pattern }, ctx) {
|
|
2159
2159
|
let targets = [];
|
|
2160
|
-
if (
|
|
2160
|
+
if (slug2) targets = [cleanSlug(slug2)];
|
|
2161
2161
|
else if (Array.isArray(slugs)) targets = slugs.map(cleanSlug).filter(Boolean);
|
|
2162
2162
|
else if (pattern) {
|
|
2163
2163
|
const escaped = String(pattern).replace(/[.+^${}()|[\]\\]/g, "\\$&");
|
|
@@ -2208,19 +2208,19 @@ function memorySearchTool(fs, dirs) {
|
|
|
2208
2208
|
matcher = (l) => l.toLowerCase().includes(lower);
|
|
2209
2209
|
}
|
|
2210
2210
|
const loaded = [];
|
|
2211
|
-
for (const
|
|
2212
|
-
const body = await loadFactMulti(fs, dirs,
|
|
2213
|
-
if (body) loaded.push({ slug, body });
|
|
2211
|
+
for (const slug2 of slugs) {
|
|
2212
|
+
const body = await loadFactMulti(fs, dirs, slug2);
|
|
2213
|
+
if (body) loaded.push({ slug: slug2, body });
|
|
2214
2214
|
}
|
|
2215
2215
|
const idf = idfWeights(loaded.map((l) => l.body));
|
|
2216
2216
|
const qTokens = tokenize(q);
|
|
2217
2217
|
const hits = [];
|
|
2218
|
-
for (const { slug, body } of loaded) {
|
|
2218
|
+
for (const { slug: slug2, body } of loaded) {
|
|
2219
2219
|
const lines = body.split("\n");
|
|
2220
2220
|
const matchLine = lines.find(matcher);
|
|
2221
2221
|
if (!matchLine && !relevanceScore(body, qTokens, idf)) continue;
|
|
2222
2222
|
const snippet = matchLine?.trim().slice(0, 120) || lines.find((l) => l.trim())?.trim().slice(0, 120) || "";
|
|
2223
|
-
hits.push({ slug, snippet, score: relevanceScore(body, qTokens, idf) });
|
|
2223
|
+
hits.push({ slug: slug2, snippet, score: relevanceScore(body, qTokens, idf) });
|
|
2224
2224
|
}
|
|
2225
2225
|
if (!hits.length) return "(no matches)";
|
|
2226
2226
|
hits.sort((a, b) => b.score - a.score);
|
|
@@ -2244,11 +2244,11 @@ function rememberTool(fs, dir, memOpts = {}) {
|
|
|
2244
2244
|
description: { type: "string", description: "one-line summary for the memory index (\u226480 chars)" }
|
|
2245
2245
|
}
|
|
2246
2246
|
},
|
|
2247
|
-
async run({ fact, slug, type, description }, ctx) {
|
|
2247
|
+
async run({ fact, slug: slug2, type, description }, ctx) {
|
|
2248
2248
|
const body = String(fact ?? "").trim();
|
|
2249
2249
|
if (!body) return `Error: nothing to remember (empty fact).`;
|
|
2250
2250
|
if (++writes > maxWrites) return `Rate limit: too many memories this session (${maxWrites}). Only persist genuinely durable facts.`;
|
|
2251
|
-
const name = slugify(
|
|
2251
|
+
const name = slugify(slug2 || body.split("\n")[0]);
|
|
2252
2252
|
const isGlobal = (type === "user" || type === "feedback") && memOpts.userDir;
|
|
2253
2253
|
const targetDir = isGlobal ? memOpts.userDir : dir;
|
|
2254
2254
|
await writeFact(fs, targetDir, name, body, { type, description });
|
|
@@ -3568,9 +3568,108 @@ init_tools_structured();
|
|
|
3568
3568
|
init_todo();
|
|
3569
3569
|
init_tools_web();
|
|
3570
3570
|
|
|
3571
|
+
// src/scratch.ts
|
|
3572
|
+
init_tools();
|
|
3573
|
+
init_tools_structured();
|
|
3574
|
+
init_logging();
|
|
3575
|
+
var log5 = forComponent("scratch");
|
|
3576
|
+
var SCRATCH_DIR = "/scratch";
|
|
3577
|
+
function shortArgs(args) {
|
|
3578
|
+
try {
|
|
3579
|
+
const s = JSON.stringify(args ?? {});
|
|
3580
|
+
return s.length > 50 ? s.slice(0, 47) + "\u2026" : s;
|
|
3581
|
+
} catch {
|
|
3582
|
+
return "";
|
|
3583
|
+
}
|
|
3584
|
+
}
|
|
3585
|
+
var slug = (s) => s.replace(/[^a-z0-9]+/gi, "-").replace(/^-+|-+$/g, "").toLowerCase().slice(0, 32) || "out";
|
|
3586
|
+
var Scratch = class {
|
|
3587
|
+
constructor(fs, options = {}) {
|
|
3588
|
+
this.fs = fs;
|
|
3589
|
+
this.options = { threshold: 1500, dir: SCRATCH_DIR, previewChars: 320, ...options };
|
|
3590
|
+
}
|
|
3591
|
+
fs;
|
|
3592
|
+
options;
|
|
3593
|
+
seq = 0;
|
|
3594
|
+
dirReady;
|
|
3595
|
+
/** Number of captures so far. */
|
|
3596
|
+
get count() {
|
|
3597
|
+
return this.seq;
|
|
3598
|
+
}
|
|
3599
|
+
/** Wrap a tool: oversized STRING results spill to a scratch file; everything else passes through. */
|
|
3600
|
+
capture(tool) {
|
|
3601
|
+
const { threshold, dir, previewChars } = this.options;
|
|
3602
|
+
return {
|
|
3603
|
+
...tool,
|
|
3604
|
+
run: async (args, ctx) => {
|
|
3605
|
+
const raw = await tool.run(args, ctx);
|
|
3606
|
+
if (typeof raw !== "string" || raw.length <= threshold) return raw;
|
|
3607
|
+
const id = "a" + ++this.seq;
|
|
3608
|
+
const path = `${dir}/${id}-${slug(tool.name)}.txt`;
|
|
3609
|
+
const header = `# ${tool.name}(${shortArgs(args)}) \u2014 ${raw.length} bytes
|
|
3610
|
+
`;
|
|
3611
|
+
try {
|
|
3612
|
+
await (this.dirReady ??= mkdirp(this.fs, dir));
|
|
3613
|
+
await this.fs.writeFile(path, header + raw);
|
|
3614
|
+
} catch (e) {
|
|
3615
|
+
log5.debug("scratch write failed; returning raw", e);
|
|
3616
|
+
return raw;
|
|
3617
|
+
}
|
|
3618
|
+
const preview = raw.slice(0, previewChars).replace(/\s+/g, " ").trim();
|
|
3619
|
+
return `[scratch ${path} \xB7 ${tool.name} \xB7 ${raw.length} bytes \u2014 full output saved out of context to keep it clean]
|
|
3620
|
+
preview: ${preview}\u2026
|
|
3621
|
+
To pull a specific detail, Grep/Read ${path}, or call Ask({ question: "\u2026", over: "${path}" }). Do NOT guess at what the preview cuts off.`;
|
|
3622
|
+
}
|
|
3623
|
+
};
|
|
3624
|
+
}
|
|
3625
|
+
/** Wrap many tools at once. */
|
|
3626
|
+
captureAll(tools) {
|
|
3627
|
+
return tools.map((t) => this.capture(t));
|
|
3628
|
+
}
|
|
3629
|
+
};
|
|
3630
|
+
var ASK_PROMPT = "You are a retrieval-extraction step with Read, Grep and Glob over a scratch filesystem holding raw outputs from earlier tools. Find the information that answers the question and return it concisely, quoting values/facts verbatim. Do NOT add analysis or anything not grounded in the files. If the answer is not present, say so plainly.";
|
|
3631
|
+
function makeAskTool(o) {
|
|
3632
|
+
const dir = o.dir ?? SCRATCH_DIR;
|
|
3633
|
+
return {
|
|
3634
|
+
name: "Ask",
|
|
3635
|
+
description: "Answer a question by peeking into the scratch files \u2014 large earlier outputs (web search, big reads, subagent reports) kept out of your context. Pass `over` with a scratch path for a targeted lookup, or omit it to search the scratch dir. Returns only the extracted answer; the full data never enters your context.",
|
|
3636
|
+
parameters: {
|
|
3637
|
+
type: "object",
|
|
3638
|
+
required: ["question"],
|
|
3639
|
+
properties: {
|
|
3640
|
+
question: { type: "string", description: "what you need from the scratch files" },
|
|
3641
|
+
over: { type: "string", description: 'scratch path to read, e.g. "/scratch/a3-websearch.txt"; omit to search' }
|
|
3642
|
+
}
|
|
3643
|
+
},
|
|
3644
|
+
async run({ question, over }) {
|
|
3645
|
+
const q = String(question ?? "").trim();
|
|
3646
|
+
if (!q) return "Error: empty question";
|
|
3647
|
+
const child = new Agent({
|
|
3648
|
+
ai: o.ai,
|
|
3649
|
+
model: o.model,
|
|
3650
|
+
fs: o.fs,
|
|
3651
|
+
tools: toolsByName(["Read", "Grep", "Glob"]),
|
|
3652
|
+
maxSteps: o.maxSteps ?? 6,
|
|
3653
|
+
systemPrompt: ASK_PROMPT
|
|
3654
|
+
});
|
|
3655
|
+
const hint = over ? `Start by reading: ${over}.` : `Grep/Glob ${dir} to find the relevant file(s) first.`;
|
|
3656
|
+
try {
|
|
3657
|
+
const res = await child.run(`${hint}
|
|
3658
|
+
|
|
3659
|
+
Question: ${q}`);
|
|
3660
|
+
const answer = (res.text ?? "").trim();
|
|
3661
|
+
return answer || "(no answer found in scratch)";
|
|
3662
|
+
} catch (e) {
|
|
3663
|
+
log5.debug("Ask peek failed", e);
|
|
3664
|
+
return `Error querying scratch: ${e?.message ?? e}`;
|
|
3665
|
+
}
|
|
3666
|
+
}
|
|
3667
|
+
};
|
|
3668
|
+
}
|
|
3669
|
+
|
|
3571
3670
|
// src/lessons.ts
|
|
3572
3671
|
init_logging();
|
|
3573
|
-
var
|
|
3672
|
+
var log6 = forComponent("Lessons");
|
|
3574
3673
|
var LessonOptionsDefaults = class {
|
|
3575
3674
|
minRepeats = 2;
|
|
3576
3675
|
};
|
|
@@ -3595,15 +3694,15 @@ function lessonCapture(options) {
|
|
|
3595
3694
|
counts.set(lesson.slug, n);
|
|
3596
3695
|
if (n < o.minRepeats) return;
|
|
3597
3696
|
written.add(lesson.slug);
|
|
3598
|
-
await writeFact(o.fs, o.dir, lesson.slug, lesson.body).catch((e) =>
|
|
3599
|
-
|
|
3697
|
+
await writeFact(o.fs, o.dir, lesson.slug, lesson.body).catch((e) => log6.warn(`could not persist ${lesson.slug}: ${e?.message ?? e}`));
|
|
3698
|
+
log6.debug(`captured lesson ${lesson.slug} (recurred ${n}\xD7)`);
|
|
3600
3699
|
}
|
|
3601
3700
|
};
|
|
3602
3701
|
}
|
|
3603
3702
|
|
|
3604
3703
|
// src/reflect.ts
|
|
3605
3704
|
init_logging();
|
|
3606
|
-
var
|
|
3705
|
+
var log7 = forComponent("Reflect");
|
|
3607
3706
|
async function reflectOnRun(o) {
|
|
3608
3707
|
const digest = digestRun(o.result.messages, o.maxDigestChars ?? 6e3);
|
|
3609
3708
|
if (!digest.trim()) return null;
|
|
@@ -3619,21 +3718,21 @@ If the run was fine or the issue was purely task-specific (not generalizable), r
|
|
|
3619
3718
|
const r = await o.ai.chat({ model: o.model, messages: [{ role: "user", content: prompt }], stream: false });
|
|
3620
3719
|
text = r?.content ?? "";
|
|
3621
3720
|
} catch (e) {
|
|
3622
|
-
|
|
3721
|
+
log7.warn(`reflection call failed: ${e?.message ?? e}`);
|
|
3623
3722
|
return null;
|
|
3624
3723
|
}
|
|
3625
3724
|
const m = text.match(/LESSON:\s*(.+)/i);
|
|
3626
3725
|
const lesson = m?.[1]?.trim().slice(0, 200) ?? "";
|
|
3627
3726
|
if (!lesson || /^none\b/i.test(lesson)) return null;
|
|
3628
|
-
const
|
|
3727
|
+
const slug2 = ("lesson-" + slugify(lesson)).slice(0, 56);
|
|
3629
3728
|
try {
|
|
3630
|
-
await writeFact(o.fs, o.dir,
|
|
3729
|
+
await writeFact(o.fs, o.dir, slug2, lesson);
|
|
3631
3730
|
} catch (e) {
|
|
3632
|
-
|
|
3731
|
+
log7.warn(`could not persist lesson: ${e?.message ?? e}`);
|
|
3633
3732
|
return null;
|
|
3634
3733
|
}
|
|
3635
|
-
|
|
3636
|
-
return
|
|
3734
|
+
log7.debug(`reflection persisted ${slug2}`);
|
|
3735
|
+
return slug2;
|
|
3637
3736
|
}
|
|
3638
3737
|
function digestRun(messages, maxChars) {
|
|
3639
3738
|
const lines = [];
|
|
@@ -3649,7 +3748,7 @@ function digestRun(messages, maxChars) {
|
|
|
3649
3748
|
// src/duplex.ts
|
|
3650
3749
|
import { MemFilesystem as MemFilesystem2 } from "@livx.cc/wcli/core";
|
|
3651
3750
|
init_logging();
|
|
3652
|
-
var
|
|
3751
|
+
var log8 = forComponent("DuplexAgent");
|
|
3653
3752
|
function describeCall(call) {
|
|
3654
3753
|
const v = call.args && Object.values(call.args).find((x) => typeof x === "string" && x.trim());
|
|
3655
3754
|
const hint = v ? ` (${String(v).replace(/\s+/g, " ").trim().slice(0, 48)})` : "";
|
|
@@ -3703,7 +3802,7 @@ var DuplexAgentOptions = class {
|
|
|
3703
3802
|
/** User-scope memory dir for global facts (type=user/feedback). Forwarded to Remember's routing. */
|
|
3704
3803
|
memoryUserDir;
|
|
3705
3804
|
};
|
|
3706
|
-
var VOICE_SYSTEM_PROMPT = 'You are a spoken voice assistant \u2014 the user HEARS everything you say. Use short sentences. One idea per sentence. No markdown, no bullet lists, no code blocks, no headings, no emoji.\nKeep turns SHORT \u2014 one to three sentences, then stop. Never lecture, enumerate cases, or add caveats unprompted. Conversation is a fast exchange: give the one thing asked, and let the user pull more if they want it.\nYou have three cognitive tiers \u2014 like a human brain:\n\u2022 YOU (reflex) \u2014 instant, lightweight. Handle greetings, simple questions, status checks, QuickLook.\n\u2022 `Act` \u2014 your hands. A 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,
|
|
3805
|
+
var VOICE_SYSTEM_PROMPT = 'You are a spoken voice assistant \u2014 the user HEARS everything you say. Use short sentences. One idea per sentence. No markdown, no bullet lists, no code blocks, no headings, no emoji.\nKeep turns SHORT \u2014 one to three sentences, then stop. Never lecture, enumerate cases, or add caveats unprompted. Conversation is a fast exchange: give the one thing asked, and let the user pull more if they want it.\nYou have three cognitive tiers \u2014 like a human brain:\n\u2022 YOU (reflex) \u2014 instant, lightweight. Handle greetings, simple questions, status checks, QuickLook.\n\u2022 `Act` \u2014 your hands. A 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.';
|
|
3707
3806
|
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.";
|
|
3708
3807
|
var THINK_DISABLED_GUIDANCE = "(Think tier is not available \u2014 use Act for all escalations.)";
|
|
3709
3808
|
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).`;
|
|
@@ -3826,7 +3925,7 @@ Today's date: ${(/* @__PURE__ */ new Date()).toDateString()}.`;
|
|
|
3826
3925
|
try {
|
|
3827
3926
|
await this.voice.send("[reminder] You dispatched a task but said nothing to the user. Say ONE short spoken acknowledgement now \u2014 no tools.");
|
|
3828
3927
|
} catch (e) {
|
|
3829
|
-
|
|
3928
|
+
log8.warn(`ack nudge failed: ${e instanceof Error ? e.message : e}`);
|
|
3830
3929
|
} finally {
|
|
3831
3930
|
this.nudging = false;
|
|
3832
3931
|
}
|
|
@@ -3949,7 +4048,7 @@ Another agent just implemented the above. Independently check the CURRENT state
|
|
|
3949
4048
|
this.notify("task_verify", `task ${id}: verifying`, { id });
|
|
3950
4049
|
const cres = await new Agent(agentOpts).run(checkBrief);
|
|
3951
4050
|
if (cres.finishReason !== "stop") {
|
|
3952
|
-
|
|
4051
|
+
log8.warn(`task ${id}: verify inconclusive (${cres.finishReason})`);
|
|
3953
4052
|
this.notify("task_verify", `task ${id}: verify inconclusive (${cres.finishReason})`, { id, finishReason: cres.finishReason });
|
|
3954
4053
|
}
|
|
3955
4054
|
const sum = (a = 0, b = 0) => a + b;
|
|
@@ -4051,7 +4150,7 @@ Another agent just implemented the above. Independently check the CURRENT state
|
|
|
4051
4150
|
return this.failTask(rec, msg);
|
|
4052
4151
|
}
|
|
4053
4152
|
rec.status = "done";
|
|
4054
|
-
|
|
4153
|
+
log8.verbose(`task ${id} done (${res.steps} steps)`);
|
|
4055
4154
|
this.notify("task_done", `task ${id} (${rec.label}) completed`, {
|
|
4056
4155
|
id,
|
|
4057
4156
|
text: res.text,
|
|
@@ -4068,7 +4167,7 @@ Another agent just implemented the above. Independently check the CURRENT state
|
|
|
4068
4167
|
failTask(rec, msg) {
|
|
4069
4168
|
this.dropAsk(rec.id);
|
|
4070
4169
|
rec.status = "error";
|
|
4071
|
-
|
|
4170
|
+
log8.warn(`task ${rec.id} failed: ${msg}`);
|
|
4072
4171
|
this.notify("task_error", `task ${rec.id} (${rec.label}) failed: ${msg}`);
|
|
4073
4172
|
this.queueRevoice(`[task ${rec.id} failed] ${msg}`);
|
|
4074
4173
|
}
|
|
@@ -4433,7 +4532,7 @@ init_logging();
|
|
|
4433
4532
|
|
|
4434
4533
|
// src/voice/engine.ts
|
|
4435
4534
|
init_logging();
|
|
4436
|
-
var
|
|
4535
|
+
var log9 = forComponent("VoiceEngine");
|
|
4437
4536
|
var now = () => performance.now();
|
|
4438
4537
|
var VoiceEngineOptions = class {
|
|
4439
4538
|
stt;
|
|
@@ -4540,7 +4639,7 @@ var VoiceEngine = class _VoiceEngine {
|
|
|
4540
4639
|
this.stt.onLevel = (rms) => this.handleLevel(rms);
|
|
4541
4640
|
await Promise.all([this.tts.connect(), this.stt.start()]);
|
|
4542
4641
|
this.setState("listening");
|
|
4543
|
-
|
|
4642
|
+
log9.debug(`voice I/O up (${this.stt.usingAec ? "AEC" : "heuristic echo"} capture)`);
|
|
4544
4643
|
}
|
|
4545
4644
|
get usingAec() {
|
|
4546
4645
|
return this.stt.usingAec;
|
|
@@ -4592,7 +4691,7 @@ var VoiceEngine = class _VoiceEngine {
|
|
|
4592
4691
|
this.reply += text;
|
|
4593
4692
|
for (const w of this.words(this.reply)) this.echoWords.add(w);
|
|
4594
4693
|
this.tts.speak(text, true);
|
|
4595
|
-
if (!this.spokeDeltas && this.turnStartAt)
|
|
4694
|
+
if (!this.spokeDeltas && this.turnStartAt) log9.debug(`ttft: ${Math.round(now() - this.turnStartAt)}ms`);
|
|
4596
4695
|
this.spokeDeltas = true;
|
|
4597
4696
|
this.setState("speaking");
|
|
4598
4697
|
}
|
|
@@ -4613,7 +4712,7 @@ var VoiceEngine = class _VoiceEngine {
|
|
|
4613
4712
|
}
|
|
4614
4713
|
this.drainTimer = null;
|
|
4615
4714
|
this.speaking = false;
|
|
4616
|
-
if (this.turnStartAt)
|
|
4715
|
+
if (this.turnStartAt) log9.debug(`turn: ${Math.round(now() - this.turnStartAt)}ms (incl. playback)`);
|
|
4617
4716
|
this.echoUntil = now() + 2500;
|
|
4618
4717
|
if (!this.usingAec) this.stt.reset();
|
|
4619
4718
|
this.setState("listening");
|
|
@@ -4754,7 +4853,7 @@ var VoiceEngine = class _VoiceEngine {
|
|
|
4754
4853
|
this.pendingUtt = this.pendingUtt ? `${this.pendingUtt} ${text}` : text;
|
|
4755
4854
|
if (this.pendingTimer) clearTimeout(this.pendingTimer);
|
|
4756
4855
|
if (this.options.incompleteMergeMs && this.looksIncomplete(this.pendingUtt)) {
|
|
4757
|
-
|
|
4856
|
+
log9.verbose(`hold: incomplete utterance "${this.pendingUtt.slice(-40)}"`);
|
|
4758
4857
|
this.options.onHold();
|
|
4759
4858
|
if (this.options.holdFiller && !this.speaking) {
|
|
4760
4859
|
this.beginSpeech();
|
|
@@ -4852,7 +4951,7 @@ async function resolveAuth(auth) {
|
|
|
4852
4951
|
}
|
|
4853
4952
|
|
|
4854
4953
|
// src/voice/soniox.ts
|
|
4855
|
-
var
|
|
4954
|
+
var log10 = forComponent("SonioxSTT");
|
|
4856
4955
|
var now2 = () => performance.now();
|
|
4857
4956
|
var SonioxSTTOptions = class {
|
|
4858
4957
|
auth = "";
|
|
@@ -4909,9 +5008,9 @@ var SonioxSTT = class {
|
|
|
4909
5008
|
this.ws.onmessage = (ev) => this.handle(JSON.parse(String(ev.data)));
|
|
4910
5009
|
this.ws.onclose = (ev) => {
|
|
4911
5010
|
if (this.stopped) return;
|
|
4912
|
-
|
|
5011
|
+
log10.warn(`soniox ws closed (${ev.code} ${ev.reason || ""}) \u2014 reconnecting`);
|
|
4913
5012
|
this.reset();
|
|
4914
|
-
this.connectWs().catch((e) =>
|
|
5013
|
+
this.connectWs().catch((e) => log10.error(`soniox reconnect failed: ${e.message}`));
|
|
4915
5014
|
};
|
|
4916
5015
|
}
|
|
4917
5016
|
async start() {
|
|
@@ -4921,7 +5020,7 @@ var SonioxSTT = class {
|
|
|
4921
5020
|
this.endpointTimer = setInterval(() => {
|
|
4922
5021
|
const combined = (this.finalText + this.partialText).trim();
|
|
4923
5022
|
if (!combined || now2() - this.lastChangeAt < this.options.silenceEndpointMs) return;
|
|
4924
|
-
if (this.firstTokenAt)
|
|
5023
|
+
if (this.firstTokenAt) log10.debug(`stt: ${Math.round(now2() - this.firstTokenAt)}ms first-token\u2192silence-endpoint, "${combined.slice(0, 60)}"`);
|
|
4925
5024
|
this.reset();
|
|
4926
5025
|
this.onUtterance(combined, now2());
|
|
4927
5026
|
}, 120);
|
|
@@ -4938,7 +5037,7 @@ var SonioxSTT = class {
|
|
|
4938
5037
|
});
|
|
4939
5038
|
}
|
|
4940
5039
|
handle(m) {
|
|
4941
|
-
if (m.error_message) return
|
|
5040
|
+
if (m.error_message) return log10.error(`soniox: ${m.error_message}`);
|
|
4942
5041
|
let endpoint = false;
|
|
4943
5042
|
for (const t of m.tokens ?? []) {
|
|
4944
5043
|
if (t.text === "<end>") endpoint = true;
|
|
@@ -4954,7 +5053,7 @@ var SonioxSTT = class {
|
|
|
4954
5053
|
this.onPartial(combined);
|
|
4955
5054
|
if (endpoint && this.finalText.trim()) {
|
|
4956
5055
|
const utterance = this.finalText.trim();
|
|
4957
|
-
if (this.firstTokenAt)
|
|
5056
|
+
if (this.firstTokenAt) log10.debug(`stt: ${Math.round(now2() - this.firstTokenAt)}ms first-token\u2192endpoint, "${utterance.slice(0, 60)}"`);
|
|
4958
5057
|
this.reset();
|
|
4959
5058
|
this.onUtterance(utterance, now2());
|
|
4960
5059
|
}
|
|
@@ -4976,7 +5075,7 @@ var SonioxSTT = class {
|
|
|
4976
5075
|
|
|
4977
5076
|
// src/voice/cartesia.ts
|
|
4978
5077
|
init_logging();
|
|
4979
|
-
var
|
|
5078
|
+
var log11 = forComponent("CartesiaTTS");
|
|
4980
5079
|
var now3 = () => performance.now();
|
|
4981
5080
|
var CartesiaTTSOptions = class {
|
|
4982
5081
|
auth = "";
|
|
@@ -5021,9 +5120,9 @@ var CartesiaTTS = class _CartesiaTTS {
|
|
|
5021
5120
|
this.ws.onerror = (e) => rej(new Error(`cartesia ws: ${e.message || "connect failed"}`));
|
|
5022
5121
|
});
|
|
5023
5122
|
this.ws.onclose = (ev) => {
|
|
5024
|
-
|
|
5123
|
+
log11.warn(`cartesia ws closed (${ev.code} ${ev.reason || ""})`);
|
|
5025
5124
|
if (!this.closed) {
|
|
5026
|
-
this.connecting = this.doConnect().catch((e) =>
|
|
5125
|
+
this.connecting = this.doConnect().catch((e) => log11.error(`cartesia reconnect failed: ${e.message}`));
|
|
5027
5126
|
}
|
|
5028
5127
|
};
|
|
5029
5128
|
this.ws.onmessage = (ev) => {
|
|
@@ -5033,7 +5132,7 @@ var CartesiaTTS = class _CartesiaTTS {
|
|
|
5033
5132
|
this.consecutiveErrors = 0;
|
|
5034
5133
|
if (this.down) {
|
|
5035
5134
|
this.down = false;
|
|
5036
|
-
|
|
5135
|
+
log11.info("TTS recovered");
|
|
5037
5136
|
this.stopProbe();
|
|
5038
5137
|
}
|
|
5039
5138
|
if (!this.firstAudioAt) this.firstAudioAt = now3();
|
|
@@ -5042,7 +5141,7 @@ var CartesiaTTS = class _CartesiaTTS {
|
|
|
5042
5141
|
this.consecutiveErrors = 0;
|
|
5043
5142
|
if (this.down) {
|
|
5044
5143
|
this.down = false;
|
|
5045
|
-
|
|
5144
|
+
log11.info("TTS recovered");
|
|
5046
5145
|
this.stopProbe();
|
|
5047
5146
|
}
|
|
5048
5147
|
this.onDone();
|
|
@@ -5051,11 +5150,11 @@ var CartesiaTTS = class _CartesiaTTS {
|
|
|
5051
5150
|
this.consecutiveErrors++;
|
|
5052
5151
|
if (!this.down && this.consecutiveErrors >= _CartesiaTTS.CB_THRESHOLD) {
|
|
5053
5152
|
this.down = true;
|
|
5054
|
-
|
|
5153
|
+
log11.warn(`TTS circuit breaker open \u2014 ${this.consecutiveErrors} consecutive errors, switching to text-only`);
|
|
5055
5154
|
this.onDone();
|
|
5056
5155
|
this.startProbe();
|
|
5057
5156
|
} else if (!this.down) {
|
|
5058
|
-
|
|
5157
|
+
log11.warn(`cartesia: ${JSON.stringify(m)}`);
|
|
5059
5158
|
}
|
|
5060
5159
|
}
|
|
5061
5160
|
};
|
|
@@ -5157,8 +5256,10 @@ export {
|
|
|
5157
5256
|
PermissionPolicy,
|
|
5158
5257
|
RecordingHooks,
|
|
5159
5258
|
RecordingLifecycle,
|
|
5259
|
+
SCRATCH_DIR,
|
|
5160
5260
|
STT_SAMPLE_RATE,
|
|
5161
5261
|
SandboxJobRegistry,
|
|
5262
|
+
Scratch,
|
|
5162
5263
|
ScriptedHostBridge,
|
|
5163
5264
|
SonioxSTT,
|
|
5164
5265
|
SonioxSTTOptions,
|
|
@@ -5197,6 +5298,7 @@ export {
|
|
|
5197
5298
|
loadMemory,
|
|
5198
5299
|
loadSkills,
|
|
5199
5300
|
log,
|
|
5301
|
+
makeAskTool,
|
|
5200
5302
|
makeContext,
|
|
5201
5303
|
makeJobTools,
|
|
5202
5304
|
makeLazyMcpToolSearch,
|