@livx.cc/agentx 0.99.145 → 0.99.146
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/README.md +1 -1
- package/dist/cli.d.ts +2 -1
- package/dist/cli.js +631 -205
- package/dist/cli.js.map +1 -1
- package/dist/index.d.ts +4 -4
- package/dist/index.js +376 -58
- package/dist/index.js.map +1 -1
- package/dist/{secondChannel-BFPgXN2z.d.ts → secondChannel-CJ1eYZKA.d.ts} +117 -0
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -2962,7 +2962,7 @@ async function psGroupCpuSeconds(pgid) {
|
|
|
2962
2962
|
try {
|
|
2963
2963
|
return await winTreeCpuSeconds(pgid);
|
|
2964
2964
|
} catch (e) {
|
|
2965
|
-
|
|
2965
|
+
log32.debug(`cpu probe failed for ${pgid}: ${e}`);
|
|
2966
2966
|
return void 0;
|
|
2967
2967
|
}
|
|
2968
2968
|
}
|
|
@@ -2971,7 +2971,7 @@ async function psGroupCpuSeconds(pgid) {
|
|
|
2971
2971
|
const out = await new Promise((res, rej) => execFile5("ps", ["-A", "-o", "pid=,ppid=,pgid=,time="], { timeout: 5e3, env: { ...process.env, LC_ALL: "C" } }, (e, so) => e ? rej(e) : res(String(so))));
|
|
2972
2972
|
return sumTreeCpu(out, pgid);
|
|
2973
2973
|
} catch (e) {
|
|
2974
|
-
|
|
2974
|
+
log32.debug(`ps cpu probe failed for group ${pgid}: ${e}`);
|
|
2975
2975
|
return void 0;
|
|
2976
2976
|
}
|
|
2977
2977
|
}
|
|
@@ -3121,7 +3121,7 @@ function makeRealShellTool(options) {
|
|
|
3121
3121
|
proc.stderr?.on("data", collect);
|
|
3122
3122
|
proc.on("error", (err2) => {
|
|
3123
3123
|
if (err2?.name === "AbortError" || ctl.signal.aborted) return finish(reasonFor(timedOut, timeoutMs, clean2(out)));
|
|
3124
|
-
|
|
3124
|
+
log32.debug("shell spawn error", err2);
|
|
3125
3125
|
finish(`[exit 1] ${err2?.message ?? err2}${out ? "\n" + clean2(out) : ""}`);
|
|
3126
3126
|
});
|
|
3127
3127
|
proc.on("close", (code) => {
|
|
@@ -3200,7 +3200,7 @@ ${clean2(out) || "(no output yet)"}`;
|
|
|
3200
3200
|
}
|
|
3201
3201
|
];
|
|
3202
3202
|
}
|
|
3203
|
-
var
|
|
3203
|
+
var log32, clean2, DETACHED, shellArgv, SECRET_ENV_RE, _spawn, ShellJobRegistry, shellStatus, NO_JOB2;
|
|
3204
3204
|
var init_tools_shell = __esm({
|
|
3205
3205
|
"src/tools.shell.ts"() {
|
|
3206
3206
|
"use strict";
|
|
@@ -3210,7 +3210,7 @@ var init_tools_shell = __esm({
|
|
|
3210
3210
|
init_shell_sandbox();
|
|
3211
3211
|
init_tools_jobs();
|
|
3212
3212
|
init_platform();
|
|
3213
|
-
|
|
3213
|
+
log32 = forComponent("shell");
|
|
3214
3214
|
clean2 = (s) => truncateOutput(redactSecrets(s.replace(/\n+$/, "")));
|
|
3215
3215
|
DETACHED = { stdio: ["ignore", "pipe", "pipe"], ...DETACH_OPTIONS };
|
|
3216
3216
|
shellArgv = (sh, command) => ({ bin: sh.bin, args: sh.args(command), ...sh.spawnOptions ? { spawnOptions: sh.spawnOptions } : {} });
|
|
@@ -10459,6 +10459,7 @@ function fitsLanguage(line, lang) {
|
|
|
10459
10459
|
}
|
|
10460
10460
|
var norm3 = (s) => s.toLowerCase().replace(/[^\p{L}\p{N}' ]/gu, "").replace(/\s+/g, " ").trim();
|
|
10461
10461
|
function cleanLine(s, lang, maxWords = 6) {
|
|
10462
|
+
if (/^(?:gasp|quiet|laughter)[.!?…]*$/i.test(s.trim())) return "";
|
|
10462
10463
|
const first = s.trim().split("\n")[0];
|
|
10463
10464
|
const tags = [...first.matchAll(LINE_TAG)].map((m) => `[${m[1].toLowerCase()}]`).filter((t, i, a) => a.indexOf(t) === i).join(" ");
|
|
10464
10465
|
const raw = first.replace(LINE_TAG, " ").trim();
|
|
@@ -13213,7 +13214,267 @@ init_models();
|
|
|
13213
13214
|
|
|
13214
13215
|
// src/voice/progress.ts
|
|
13215
13216
|
init_logging();
|
|
13216
|
-
|
|
13217
|
+
|
|
13218
|
+
// src/voice/convoTree.ts
|
|
13219
|
+
init_logging();
|
|
13220
|
+
|
|
13221
|
+
// src/voice/backchannelPlan.ts
|
|
13222
|
+
init_logging();
|
|
13223
|
+
var log26 = forComponent("BackchannelPlan");
|
|
13224
|
+
var TURN_TYPES = ["story", "list", "complaint", "explanation", "short_command", "question", "other"];
|
|
13225
|
+
var DENSITIES = ["none", "low", "normal", "high"];
|
|
13226
|
+
var silentTurn = (p) => p.density === "none" || p.turn === "short_command" || p.turn === "question";
|
|
13227
|
+
var cueWords = (s) => s.toLowerCase().replace(/[^\p{L}\p{N}'\s]+/gu, " ").split(/\s+/).filter(Boolean);
|
|
13228
|
+
function parsePlan(raw, lang, maxCues = 8) {
|
|
13229
|
+
const m = raw.match(/\{[\s\S]*\}/);
|
|
13230
|
+
if (!m) return null;
|
|
13231
|
+
let o;
|
|
13232
|
+
try {
|
|
13233
|
+
o = JSON.parse(m[0]);
|
|
13234
|
+
} catch {
|
|
13235
|
+
return null;
|
|
13236
|
+
}
|
|
13237
|
+
const turn = String(o?.turn ?? "").toLowerCase().replace(/[\s-]+/g, "_");
|
|
13238
|
+
const density = String(o?.density ?? "").toLowerCase();
|
|
13239
|
+
if (!TURN_TYPES.includes(turn) || !DENSITIES.includes(density)) return null;
|
|
13240
|
+
const cues = [];
|
|
13241
|
+
for (const c of Array.isArray(o.cues) ? o.cues : []) {
|
|
13242
|
+
const when = (Array.isArray(c?.when) ? c.when : [c?.when]).filter((w) => typeof w === "string").map((w) => cueWords(w).join(" ")).filter((w) => w && w.split(" ").length <= 4);
|
|
13243
|
+
const line = typeof c?.line === "string" ? cleanLine(c.line, lang, 4) : "";
|
|
13244
|
+
if (when.length && line) cues.push({ when: [...new Set(when)], line });
|
|
13245
|
+
if (cues.length >= maxCues) break;
|
|
13246
|
+
}
|
|
13247
|
+
return { turn, density, cues };
|
|
13248
|
+
}
|
|
13249
|
+
function matchCue(plan, heard, from = 0) {
|
|
13250
|
+
if (!plan || silentTurn(plan)) return null;
|
|
13251
|
+
const w = cueWords(heard);
|
|
13252
|
+
for (let i = Math.max(0, from); i < w.length; i++) {
|
|
13253
|
+
for (const c of plan.cues) {
|
|
13254
|
+
for (const p of c.when) {
|
|
13255
|
+
const pw = p.split(" ");
|
|
13256
|
+
if (i + pw.length <= w.length && pw.every((x, j) => w[i + j] === x)) return c;
|
|
13257
|
+
}
|
|
13258
|
+
}
|
|
13259
|
+
}
|
|
13260
|
+
return null;
|
|
13261
|
+
}
|
|
13262
|
+
var BackchannelPlannerOptions = class {
|
|
13263
|
+
/** Fast model (Groq gpt-oss / the reflex). */
|
|
13264
|
+
model = "groq/openai/gpt-oss-120b";
|
|
13265
|
+
maxTokens = 900;
|
|
13266
|
+
};
|
|
13267
|
+
var BackchannelPlanner = class {
|
|
13268
|
+
constructor(ai, options) {
|
|
13269
|
+
this.ai = ai;
|
|
13270
|
+
this.options = options;
|
|
13271
|
+
this.options = { ...new BackchannelPlannerOptions(), ...options };
|
|
13272
|
+
}
|
|
13273
|
+
ai;
|
|
13274
|
+
options;
|
|
13275
|
+
async plan(c, signal) {
|
|
13276
|
+
const o = this.options;
|
|
13277
|
+
const name = languageName(c.lang);
|
|
13278
|
+
const prompt = `You plan a live voice assistant's LISTENER sounds ("mm-hm", "right", "oh no") for the user's ${c.heard ? "CURRENT" : "NEXT"} spoken turn.
|
|
13279
|
+
Assistant just said: "${c.agent.slice(-400)}"
|
|
13280
|
+
` + (c.user ? `User's previous turn ended: "${c.user.slice(-200)}"
|
|
13281
|
+
` : "") + (c.heard ? `User so far in this turn: "${c.heard.slice(-300)}"
|
|
13282
|
+
` : "") + `Predict the turn: turn = story | list | complaint | explanation | short_command | question | other; density = none (short request or a question: never interrupt) | low | normal | high (a long story wants frequent cues).
|
|
13283
|
+
cues: 3-8 short words/phrases the user is likely to say at a clause boundary where a listener cue fits (list markers like "first", "and then", "also"; narrative markers; emotional words; names/topics from the context), each with ONE fitting listener line of 1-3 words in ${name} that reacts to it (sympathy for bad news, "okay" for a list step) \u2014 never a question, never an answer.
|
|
13284
|
+
Reply JSON only: {"turn":"...","density":"...","cues":[{"when":["phrase",...],"line":"..."}]}. Phrases in the user's language.`;
|
|
13285
|
+
const reasoning = /gpt-oss/.test(o.model) ? { providerOptions: { reasoning_effort: "low" } } : {};
|
|
13286
|
+
const r = await this.ai.chat({ model: o.model, messages: [{ role: "user", content: prompt }], stream: false, signal, maxTokens: o.maxTokens, ...reasoning });
|
|
13287
|
+
const p = parsePlan(r.content ?? "", c.lang);
|
|
13288
|
+
if (!p) log26.debug(`unusable plan: ${(r.content ?? "").slice(0, 120)}`);
|
|
13289
|
+
return p;
|
|
13290
|
+
}
|
|
13291
|
+
};
|
|
13292
|
+
|
|
13293
|
+
// src/voice/convoTree.ts
|
|
13294
|
+
var log27 = forComponent("ConvoTree");
|
|
13295
|
+
var MOMENTS = ["turn_end", "barge_in", "in_between", "ask"];
|
|
13296
|
+
var MAX_LINE_WORDS = 5;
|
|
13297
|
+
var SOFT_CUE = "~";
|
|
13298
|
+
var STOP4 = new Set("about after again also always been before being could does doing down even every from going have here into just know like look make many more most much must never only other over really right same should some still such sure take than that their them then there these they thing think this those through very want well were what when where which while will with would your yeah okay".split(" "));
|
|
13299
|
+
var isContent = (w) => w.length >= 4 && !STOP4.has(w);
|
|
13300
|
+
function echoesHeard(line, heard) {
|
|
13301
|
+
const said = new Set(cueWords(heard));
|
|
13302
|
+
return cueWords(lineWords(line)).some((w) => isContent(w) && said.has(w));
|
|
13303
|
+
}
|
|
13304
|
+
var leafKey = (line) => cueWords(lineWords(line)).join(" ");
|
|
13305
|
+
function parseNodes(list, lang, depth, maxBranches) {
|
|
13306
|
+
const out = [];
|
|
13307
|
+
for (const n of Array.isArray(list) ? list : []) {
|
|
13308
|
+
const moment = String(n?.moment ?? "").toLowerCase().replace(/[\s-]+/g, "_");
|
|
13309
|
+
const when = (Array.isArray(n?.when) ? n.when : [n?.when]).filter((w) => typeof w === "string").map((w) => cueWords(w).join(" ")).filter((w) => w && w.split(" ").length <= 4 && w.split(" ").some(isContent));
|
|
13310
|
+
const names = (Array.isArray(n?.names) ? n.names : []).filter((w) => typeof w === "string").flatMap((w) => cueWords(w));
|
|
13311
|
+
const p = Number(n?.p);
|
|
13312
|
+
const line = typeof n?.line === "string" ? cleanLine(n.line, lang, MAX_LINE_WORDS) : "";
|
|
13313
|
+
if (!MOMENTS.includes(moment) || !when.length || !line || !(p > 0)) continue;
|
|
13314
|
+
out.push({ when: [...new Set(when)], p: Math.min(p, 1), moment, line, ...names.length ? { names } : {}, next: depth > 1 ? parseNodes(n.next, lang, depth - 1, maxBranches) : [] });
|
|
13315
|
+
if (out.length >= maxBranches) break;
|
|
13316
|
+
}
|
|
13317
|
+
return out;
|
|
13318
|
+
}
|
|
13319
|
+
function parseTree(raw, lang, depth = 2, maxBranches = 4) {
|
|
13320
|
+
const m = raw.match(/\{[\s\S]*\}/);
|
|
13321
|
+
if (!m) return [];
|
|
13322
|
+
try {
|
|
13323
|
+
const o = JSON.parse(m[0]), nodes = parseNodes(o?.branches, lang, depth, maxBranches);
|
|
13324
|
+
if (!nodes.length) return [];
|
|
13325
|
+
const soft = (Array.isArray(o?.soft) ? o.soft : []).filter((l) => typeof l === "string").map((l) => cleanLine(l, lang, 3)).filter(Boolean).slice(0, 2);
|
|
13326
|
+
return [...nodes, ...soft.map((line) => ({ when: [SOFT_CUE], p: 0.25, moment: "in_between", line, next: [] }))];
|
|
13327
|
+
} catch {
|
|
13328
|
+
return [];
|
|
13329
|
+
}
|
|
13330
|
+
}
|
|
13331
|
+
var ConvoTreeOptions = class {
|
|
13332
|
+
/** A leaf plays at this confidence or above. */
|
|
13333
|
+
threshold = 0.5;
|
|
13334
|
+
/** How much more likely a cue of one word / of two or more is if its branch is the true one. */
|
|
13335
|
+
cueEvidence = 3;
|
|
13336
|
+
phraseEvidence = 8;
|
|
13337
|
+
/** A hit weakens each sibling by this factor. */
|
|
13338
|
+
siblingDecay = 0.5;
|
|
13339
|
+
/** A cue counts only within the newest N words: older ones have passed, a reaction to them would be late. */
|
|
13340
|
+
cueWindow = 4;
|
|
13341
|
+
};
|
|
13342
|
+
var namesHeard = (n, said) => (n.names ?? []).every((w) => said.has(w));
|
|
13343
|
+
function echoHeard(node, heard) {
|
|
13344
|
+
if (node.when[0] === SOFT_CUE) return true;
|
|
13345
|
+
const said = new Set(cueWords(heard));
|
|
13346
|
+
return node.when.flatMap((w) => w.split(" ")).some((w) => isContent(w) && said.has(w)) && namesHeard(node, said);
|
|
13347
|
+
}
|
|
13348
|
+
var ConvoTree = class {
|
|
13349
|
+
// a turn_end leaf waiting for the turn to end
|
|
13350
|
+
constructor(options) {
|
|
13351
|
+
this.options = options;
|
|
13352
|
+
this.options = { ...new ConvoTreeOptions(), ...options };
|
|
13353
|
+
}
|
|
13354
|
+
options;
|
|
13355
|
+
live = [];
|
|
13356
|
+
from = 0;
|
|
13357
|
+
// word index after the last hit
|
|
13358
|
+
armed = null;
|
|
13359
|
+
get o() {
|
|
13360
|
+
return this.options;
|
|
13361
|
+
}
|
|
13362
|
+
get nodes() {
|
|
13363
|
+
return this.live;
|
|
13364
|
+
}
|
|
13365
|
+
get empty() {
|
|
13366
|
+
return !this.live.length;
|
|
13367
|
+
}
|
|
13368
|
+
/** A fresh tree. `heardWords`: words already said this turn (a tree grown mid-turn matches only what comes next). */
|
|
13369
|
+
grow(nodes, heardWords = 0) {
|
|
13370
|
+
this.live = nodes.map((n) => ({ ...n }));
|
|
13371
|
+
this.armed = null;
|
|
13372
|
+
this.from = heardWords;
|
|
13373
|
+
}
|
|
13374
|
+
/** Posterior of a node after seeing its cue. */
|
|
13375
|
+
confidence(p, words4) {
|
|
13376
|
+
const l = p * (words4 > 1 ? this.o.phraseEvidence : this.o.cueEvidence);
|
|
13377
|
+
return l / (l + 1 - p);
|
|
13378
|
+
}
|
|
13379
|
+
/** The partial's newest evidence: the strongest new cue hit (its children open, its siblings fade), or null. A turn_end
|
|
13380
|
+
* hit is armed for endTurn; the caller plays the others. Hits under the threshold still sharpen the tree. */
|
|
13381
|
+
step(heard) {
|
|
13382
|
+
const w = cueWords(heard), said = new Set(w);
|
|
13383
|
+
let best = null;
|
|
13384
|
+
for (let i = Math.max(this.from, w.length - this.o.cueWindow); i < w.length; i++) {
|
|
13385
|
+
for (const node2 of this.live) for (const cue of node2.when) {
|
|
13386
|
+
const pw = cue.split(" ");
|
|
13387
|
+
if (!namesHeard(node2, said) || i + pw.length > w.length || !pw.every((x, j) => w[i + j] === x)) continue;
|
|
13388
|
+
const conf2 = this.confidence(node2.p, pw.length);
|
|
13389
|
+
if (!best || conf2 > best.conf) best = { node: node2, conf: conf2, end: i + pw.length };
|
|
13390
|
+
}
|
|
13391
|
+
}
|
|
13392
|
+
if (!best) return null;
|
|
13393
|
+
const { node, conf } = best;
|
|
13394
|
+
this.from = best.end;
|
|
13395
|
+
this.take(node, conf);
|
|
13396
|
+
const hit = { node, conf };
|
|
13397
|
+
if ((node.moment === "turn_end" || node.moment === "ask") && conf >= (this.armed?.conf ?? 0)) {
|
|
13398
|
+
this.armed = hit;
|
|
13399
|
+
return null;
|
|
13400
|
+
}
|
|
13401
|
+
return conf >= this.o.threshold ? hit : null;
|
|
13402
|
+
}
|
|
13403
|
+
/** A node happened: it leaves the live set, its siblings fade, its children open. */
|
|
13404
|
+
take(node, conf) {
|
|
13405
|
+
this.live = [...this.live.filter((n) => n !== node).map((n) => ({ ...n, p: n.p * this.o.siblingDecay })), ...node.next.map((n) => ({ ...n, p: Math.min(1, n.p * Math.max(conf, 0.5) * 1.5) }))];
|
|
13406
|
+
}
|
|
13407
|
+
/** The turn ended: the armed leaf if it clears the threshold. The live set stays for a picker; `advance` clears it. */
|
|
13408
|
+
turnLeaf() {
|
|
13409
|
+
const a = this.armed;
|
|
13410
|
+
return a && a.conf >= this.o.threshold ? a : null;
|
|
13411
|
+
}
|
|
13412
|
+
/** A quick model named a node at the turn's end: its evidence counts as a phrase. Null when under the threshold. */
|
|
13413
|
+
picked(i, heard = "") {
|
|
13414
|
+
const node = this.live[i];
|
|
13415
|
+
if (!node || !echoHeard(node, heard)) return null;
|
|
13416
|
+
const conf = this.confidence(node.p, 2);
|
|
13417
|
+
return conf >= this.o.threshold ? { node, conf } : null;
|
|
13418
|
+
}
|
|
13419
|
+
/** Next turn: what followed a played/armed branch stays live until a fresh tree lands; the rest is gone. */
|
|
13420
|
+
advance() {
|
|
13421
|
+
this.live = this.live.filter((n) => n.p >= 0.05);
|
|
13422
|
+
this.armed = null;
|
|
13423
|
+
this.from = 0;
|
|
13424
|
+
}
|
|
13425
|
+
};
|
|
13426
|
+
var ConvoTreeGrowerOptions = class {
|
|
13427
|
+
/** gpt-oss on Groq: ~1.2s a tree. cursor/composer-2.5-fast took 10-15s (the Dessa rig), slower than the talk's turns. */
|
|
13428
|
+
model = "groq/openai/gpt-oss-120b";
|
|
13429
|
+
maxTokens = 1400;
|
|
13430
|
+
/** Branches and levels the model is asked for. */
|
|
13431
|
+
branches = 3;
|
|
13432
|
+
levels = 2;
|
|
13433
|
+
};
|
|
13434
|
+
var ConvoTreeGrower = class {
|
|
13435
|
+
constructor(ai, options) {
|
|
13436
|
+
this.ai = ai;
|
|
13437
|
+
this.options = options;
|
|
13438
|
+
this.options = { ...new ConvoTreeGrowerOptions(), ...options };
|
|
13439
|
+
}
|
|
13440
|
+
ai;
|
|
13441
|
+
options;
|
|
13442
|
+
async grow(c, signal) {
|
|
13443
|
+
const o = this.options;
|
|
13444
|
+
const prompt = `You predict a live spoken talk between "them" (a human) and "you".
|
|
13445
|
+
` + (c.persona ? `You are: ${c.persona.slice(0, 500)}
|
|
13446
|
+
` : "") + `The talk so far:
|
|
13447
|
+
${c.talk.join("\n") || "(it is just starting)"}
|
|
13448
|
+
|
|
13449
|
+
If their last line is marked (still talking), predict how THAT sentence goes on. Otherwise predict what THEY say next: ${o.branches} different likely evolutions, each with ${o.branches - 1} follow-ups of what they say after it (${o.levels} levels). Think of what real people say, in this talk, right now.
|
|
13450
|
+
Each branch: "when" = 4-6 single words or short phrases THEY would actually say that reveal this branch (specific words of the topic and feeling words, not "so" or "and"); "p" = its probability (siblings sum to about 1); "moment" = when a real person would react: "barge_in" (cuts in the instant they hear it: big news, a shock, a joke), "in_between" (a sound in their breath, they keep talking: the usual one), "turn_end" (right when they finish: rare), "ask" (they ask you to look up, check or do something: at least one branch is this, its line names the thing and says you are on it: "Hacker News, one sec.", up to 5 words); "line" = what you say then, 1-3 plain words in ${languageName(c.lang)} that react to THOSE words (an echo of their word is great: "Paris?!", "the jumper", "mm, okay", "oh no"). Vary them; no stock line twice. A line that names a topic lists it in "names" ("Paris?!": ["paris"]). At most ONE line in the whole tree may carry a sound, only for a real shock or a real joke: it begins with [gasp] or [laughter], [quiet] for something tender. A reaction, never an answer or a question that needs one.
|
|
13451
|
+
` + (c.recent.length ? `Already said, never reuse these or close variants: ${c.recent.map((r2) => `"${r2}"`).join(", ")}.
|
|
13452
|
+
` : "") + `Do not use any tools. Also "soft": 2 plain listener sounds that fit the feeling of this moment and name no topic ("mm", "oh wow", "right", "oh no", "ha").
|
|
13453
|
+
Reply JSON only: {"soft":["...","..."],"branches":[{"when":["..."],"p":0.5,"moment":"...","line":"...","names":["each topic word the line itself says, none for a feeling"],"next":[{...same, no next}]}]}`;
|
|
13454
|
+
const reasoning = /gpt-oss/.test(o.model) ? { providerOptions: { reasoning_effort: "low" } } : {};
|
|
13455
|
+
const r = await this.ai.chat({ model: o.model, messages: [{ role: "user", content: prompt }], stream: false, signal, maxTokens: o.maxTokens, ...reasoning });
|
|
13456
|
+
const seen = new Set(c.recent.map(leafKey));
|
|
13457
|
+
const fresh = (l) => l.filter((n) => !seen.has(leafKey(n.line))).map((n) => ({ ...n, next: fresh(n.next) }));
|
|
13458
|
+
const nodes = fresh(parseTree(r.content ?? "", c.lang, o.levels));
|
|
13459
|
+
if (!nodes.length) log27.debug(`unusable tree: ${(r.content ?? "").slice(0, 160)}`);
|
|
13460
|
+
return { nodes, ...r.usage ? { tokens: { input: r.usage.promptTokens, output: r.usage.completionTokens } } : {} };
|
|
13461
|
+
}
|
|
13462
|
+
};
|
|
13463
|
+
function fastLeafPicker(ai, model = "groq/openai/gpt-oss-120b") {
|
|
13464
|
+
return async (heard, lines, signal) => {
|
|
13465
|
+
const prompt = `Live spoken talk. They just said: "${heard.slice(-240)}"
|
|
13466
|
+
They may still be talking. A warm listener reacts often: does one of these fit the words they just said? It must fit those words.
|
|
13467
|
+
` + lines.map((l) => `${l.i}: ${l.line} (fits: ${l.when.join(", ").replace("~", "any moment, when no topic line fits")})`).join("\n") + `
|
|
13468
|
+
Answer only the number, or "none".`;
|
|
13469
|
+
const reasoning = /gpt-oss/.test(model) ? { providerOptions: { reasoning_effort: "low" } } : {};
|
|
13470
|
+
const r = await ai.chat({ model, messages: [{ role: "user", content: prompt }], stream: false, signal, temperature: 0, maxTokens: /gpt-oss/.test(model) ? 200 : 4, ...reasoning });
|
|
13471
|
+
const m = (r.content ?? "").trim().match(/^\d+/);
|
|
13472
|
+
return m ? Number(m[0]) : -1;
|
|
13473
|
+
};
|
|
13474
|
+
}
|
|
13475
|
+
|
|
13476
|
+
// src/voice/progress.ts
|
|
13477
|
+
var log28 = forComponent("Progress");
|
|
13217
13478
|
var HE_RESULT_CLAIM = /(?:^|\s)(?:מצאתי|סיימתי|בוצע|הנה|אין)(?=\s|$|[.,!…])/u;
|
|
13218
13479
|
var TOPICS = [
|
|
13219
13480
|
[/toolsearch|^mcp__.*__(list_commands|call_info)$/, null],
|
|
@@ -13337,8 +13598,8 @@ var Progress = class {
|
|
|
13337
13598
|
this.said.add(norm3(line));
|
|
13338
13599
|
this.lastAt = this.o.now();
|
|
13339
13600
|
}
|
|
13340
|
-
/** The line for this tool call in `lang`, or '' (no template and no/late/invalid generation, a repeat, a result claim). */
|
|
13341
|
-
async line(tool, args, lang) {
|
|
13601
|
+
/** `about`: the user's request, for a generated line. The line for this tool call in `lang`, or '' (no template and no/late/invalid generation, a repeat, a result claim). */
|
|
13602
|
+
async line(tool, args, lang, about = "") {
|
|
13342
13603
|
if (this.streamed) return "";
|
|
13343
13604
|
const name = tool.toLowerCase();
|
|
13344
13605
|
const hit = TOPICS.find(([re]) => re.test(name));
|
|
@@ -13357,18 +13618,18 @@ var Progress = class {
|
|
|
13357
13618
|
r(null);
|
|
13358
13619
|
}, this.o.generateBudgetMs);
|
|
13359
13620
|
});
|
|
13360
|
-
const raw = await Promise.race([this.o.generate(tool, argsHint(args), lang, ac.signal).catch((e) => {
|
|
13361
|
-
|
|
13621
|
+
const raw = await Promise.race([this.o.generate(tool, [about.slice(-80), argsHint(args)].filter(Boolean).join("; "), lang, ac.signal).catch((e) => {
|
|
13622
|
+
log28.warn(`progress line failed: ${e?.message ?? e}`);
|
|
13362
13623
|
return null;
|
|
13363
13624
|
}), late]).finally(() => clearTimeout(t));
|
|
13364
13625
|
const l = cleanLine(raw ?? "", lang, 5);
|
|
13365
|
-
if (!l || RESULT_CLAIM_RE.test(l) || HE_RESULT_CLAIM.test(l) || this.said.has(norm3(l)) || this.streamed) return "";
|
|
13626
|
+
if (!l || about && !echoesHeard(l, `${about} ${argsHint(args)}`) || RESULT_CLAIM_RE.test(l) || HE_RESULT_CLAIM.test(l) || this.said.has(norm3(l)) || this.streamed) return "";
|
|
13366
13627
|
return l;
|
|
13367
13628
|
}
|
|
13368
13629
|
};
|
|
13369
13630
|
function fastProgressGenerator(ai, model, gender) {
|
|
13370
13631
|
return async (tool, hint, lang, signal) => {
|
|
13371
|
-
const prompt = `An assistant on a live voice call is running the tool "${tool}"${hint ? ` (about: "${hint}")` : ""}. Write ONE spoken line of 2-5 words, in ${languageName(lang)}, saying what it is doing right now (like "checking the board\u2026"). Never state a result or a finding. ${personaHint(gender)} Output only the line.`;
|
|
13632
|
+
const prompt = `An assistant on a live voice call is running the tool "${tool}"${hint ? ` (about: "${hint}")` : ""}. Write ONE spoken line of 2-5 words, in ${languageName(lang)}, saying what it is doing right now (like "checking the board\u2026"). ${hint ? "Use the words of what it is about. " : ""}Never state a result or a finding. ${personaHint(gender)} Output only the line.`;
|
|
13372
13633
|
const reasoning = /gpt-oss/.test(model) ? { providerOptions: { reasoning_effort: "low" } } : {};
|
|
13373
13634
|
const r = await ai.chat({ model, messages: [{ role: "user", content: prompt }], stream: false, signal, maxTokens: 150, ...reasoning });
|
|
13374
13635
|
return r.content ?? "";
|
|
@@ -13377,81 +13638,7 @@ function fastProgressGenerator(ai, model, gender) {
|
|
|
13377
13638
|
|
|
13378
13639
|
// src/voice/secondChannel.ts
|
|
13379
13640
|
init_logging();
|
|
13380
|
-
|
|
13381
|
-
// src/voice/backchannelPlan.ts
|
|
13382
|
-
init_logging();
|
|
13383
|
-
var log27 = forComponent("BackchannelPlan");
|
|
13384
|
-
var TURN_TYPES = ["story", "list", "complaint", "explanation", "short_command", "question", "other"];
|
|
13385
|
-
var DENSITIES = ["none", "low", "normal", "high"];
|
|
13386
|
-
var silentTurn = (p) => p.density === "none" || p.turn === "short_command" || p.turn === "question";
|
|
13387
|
-
var cueWords = (s) => s.toLowerCase().replace(/[^\p{L}\p{N}'\s]+/gu, " ").split(/\s+/).filter(Boolean);
|
|
13388
|
-
function parsePlan(raw, lang, maxCues = 8) {
|
|
13389
|
-
const m = raw.match(/\{[\s\S]*\}/);
|
|
13390
|
-
if (!m) return null;
|
|
13391
|
-
let o;
|
|
13392
|
-
try {
|
|
13393
|
-
o = JSON.parse(m[0]);
|
|
13394
|
-
} catch {
|
|
13395
|
-
return null;
|
|
13396
|
-
}
|
|
13397
|
-
const turn = String(o?.turn ?? "").toLowerCase().replace(/[\s-]+/g, "_");
|
|
13398
|
-
const density = String(o?.density ?? "").toLowerCase();
|
|
13399
|
-
if (!TURN_TYPES.includes(turn) || !DENSITIES.includes(density)) return null;
|
|
13400
|
-
const cues = [];
|
|
13401
|
-
for (const c of Array.isArray(o.cues) ? o.cues : []) {
|
|
13402
|
-
const when = (Array.isArray(c?.when) ? c.when : [c?.when]).filter((w) => typeof w === "string").map((w) => cueWords(w).join(" ")).filter((w) => w && w.split(" ").length <= 4);
|
|
13403
|
-
const line = typeof c?.line === "string" ? cleanLine(c.line, lang, 4) : "";
|
|
13404
|
-
if (when.length && line) cues.push({ when: [...new Set(when)], line });
|
|
13405
|
-
if (cues.length >= maxCues) break;
|
|
13406
|
-
}
|
|
13407
|
-
return { turn, density, cues };
|
|
13408
|
-
}
|
|
13409
|
-
function matchCue(plan, heard, from = 0) {
|
|
13410
|
-
if (!plan || silentTurn(plan)) return null;
|
|
13411
|
-
const w = cueWords(heard);
|
|
13412
|
-
for (let i = Math.max(0, from); i < w.length; i++) {
|
|
13413
|
-
for (const c of plan.cues) {
|
|
13414
|
-
for (const p of c.when) {
|
|
13415
|
-
const pw = p.split(" ");
|
|
13416
|
-
if (i + pw.length <= w.length && pw.every((x, j) => w[i + j] === x)) return c;
|
|
13417
|
-
}
|
|
13418
|
-
}
|
|
13419
|
-
}
|
|
13420
|
-
return null;
|
|
13421
|
-
}
|
|
13422
|
-
var BackchannelPlannerOptions = class {
|
|
13423
|
-
/** Fast model (Groq gpt-oss / the reflex). */
|
|
13424
|
-
model = "groq/openai/gpt-oss-120b";
|
|
13425
|
-
maxTokens = 900;
|
|
13426
|
-
};
|
|
13427
|
-
var BackchannelPlanner = class {
|
|
13428
|
-
constructor(ai, options) {
|
|
13429
|
-
this.ai = ai;
|
|
13430
|
-
this.options = options;
|
|
13431
|
-
this.options = { ...new BackchannelPlannerOptions(), ...options };
|
|
13432
|
-
}
|
|
13433
|
-
ai;
|
|
13434
|
-
options;
|
|
13435
|
-
async plan(c, signal) {
|
|
13436
|
-
const o = this.options;
|
|
13437
|
-
const name = languageName(c.lang);
|
|
13438
|
-
const prompt = `You plan a live voice assistant's LISTENER sounds ("mm-hm", "right", "oh no") for the user's ${c.heard ? "CURRENT" : "NEXT"} spoken turn.
|
|
13439
|
-
Assistant just said: "${c.agent.slice(-400)}"
|
|
13440
|
-
` + (c.user ? `User's previous turn ended: "${c.user.slice(-200)}"
|
|
13441
|
-
` : "") + (c.heard ? `User so far in this turn: "${c.heard.slice(-300)}"
|
|
13442
|
-
` : "") + `Predict the turn: turn = story | list | complaint | explanation | short_command | question | other; density = none (short request or a question: never interrupt) | low | normal | high (a long story wants frequent cues).
|
|
13443
|
-
cues: 3-8 short words/phrases the user is likely to say at a clause boundary where a listener cue fits (list markers like "first", "and then", "also"; narrative markers; emotional words; names/topics from the context), each with ONE fitting listener line of 1-3 words in ${name} that reacts to it (sympathy for bad news, "okay" for a list step) \u2014 never a question, never an answer.
|
|
13444
|
-
Reply JSON only: {"turn":"...","density":"...","cues":[{"when":["phrase",...],"line":"..."}]}. Phrases in the user's language.`;
|
|
13445
|
-
const reasoning = /gpt-oss/.test(o.model) ? { providerOptions: { reasoning_effort: "low" } } : {};
|
|
13446
|
-
const r = await this.ai.chat({ model: o.model, messages: [{ role: "user", content: prompt }], stream: false, signal, maxTokens: o.maxTokens, ...reasoning });
|
|
13447
|
-
const p = parsePlan(r.content ?? "", c.lang);
|
|
13448
|
-
if (!p) log27.debug(`unusable plan: ${(r.content ?? "").slice(0, 120)}`);
|
|
13449
|
-
return p;
|
|
13450
|
-
}
|
|
13451
|
-
};
|
|
13452
|
-
|
|
13453
|
-
// src/voice/secondChannel.ts
|
|
13454
|
-
var log28 = forComponent("SecondChannel");
|
|
13641
|
+
var log29 = forComponent("SecondChannel");
|
|
13455
13642
|
var CHANNEL_MODES = {
|
|
13456
13643
|
turn: { kinds: ["bridge"], bridgeDelayMs: 1500 },
|
|
13457
13644
|
normal: {},
|
|
@@ -13470,10 +13657,10 @@ var CHANNEL_MODES = {
|
|
|
13470
13657
|
maxPerWindow: 6
|
|
13471
13658
|
},
|
|
13472
13659
|
live: {
|
|
13473
|
-
kinds: ["backchannel"],
|
|
13660
|
+
kinds: ["backchannel", "bridge"],
|
|
13474
13661
|
anticipate: true,
|
|
13475
13662
|
cueOnly: false,
|
|
13476
|
-
generateFor: ["backchannel"],
|
|
13663
|
+
generateFor: ["backchannel", "bridge"],
|
|
13477
13664
|
reactionGapMs: 0,
|
|
13478
13665
|
generateBudgetMs: 400,
|
|
13479
13666
|
backchannelMinWords: 3,
|
|
@@ -13528,6 +13715,8 @@ var SecondChannelOptions = class {
|
|
|
13528
13715
|
decideEveryWords = 3;
|
|
13529
13716
|
decisionBudgetMs = 300;
|
|
13530
13717
|
generateBudgetMs = 500;
|
|
13718
|
+
/** `live`: how long the fast model may take on a bridge line; later = silence. */
|
|
13719
|
+
bridgeBudgetMs = 1200;
|
|
13531
13720
|
minGapMs = 2500;
|
|
13532
13721
|
/** Backchannel after backchannel needs this gap (~4-6 cues in a 30s monologue — Para phone call 2026-10-13: 5s left
|
|
13533
13722
|
* one cue in a long statement). */
|
|
@@ -13581,6 +13770,31 @@ var SecondChannelOptions = class {
|
|
|
13581
13770
|
cueOnly = true;
|
|
13582
13771
|
onPlan = () => {
|
|
13583
13772
|
};
|
|
13773
|
+
/** `live` only (convoTree.ts): grows the prediction tree after each reply. Once a tree is up it is the only source of
|
|
13774
|
+
* lines while the user talks: a leaf above its threshold, or silence. No tree yet / a failed one: the reactive path. */
|
|
13775
|
+
grow;
|
|
13776
|
+
/** The quick model at a turn's end with no cue hit: names a leaf or none, inside `pickBudgetMs`. */
|
|
13777
|
+
pickLeaf;
|
|
13778
|
+
pickBudgetMs = 700;
|
|
13779
|
+
growBudgetMs = 15e3;
|
|
13780
|
+
tree = {};
|
|
13781
|
+
/** The tree grower's persona (who is speaking). */
|
|
13782
|
+
persona = "";
|
|
13783
|
+
/** Lines of talk the grower sees. */
|
|
13784
|
+
talkLines = 8;
|
|
13785
|
+
/** Mid-turn: at this many words the tree regrows once from what they are saying now. */
|
|
13786
|
+
regrowAtWords = 6;
|
|
13787
|
+
/** A leaf is dropped once the talk moved this many words past its cue. */
|
|
13788
|
+
leafStaleWords = 3;
|
|
13789
|
+
/** Interims stop this long: the quick model may pick a leaf (shorter than the ~400ms word cadence, so most gaps count; leafGated spaces the calls). */
|
|
13790
|
+
leafBreathMs = 200;
|
|
13791
|
+
/** Played leaves the grower must avoid, and how many lines pass before a tag may play again. */
|
|
13792
|
+
leafMemory = 16;
|
|
13793
|
+
tagEvery = 4;
|
|
13794
|
+
onTree = () => {
|
|
13795
|
+
};
|
|
13796
|
+
onLeaf = () => {
|
|
13797
|
+
};
|
|
13584
13798
|
now = () => performance.now();
|
|
13585
13799
|
random = Math.random;
|
|
13586
13800
|
};
|
|
@@ -13589,15 +13803,15 @@ function withBudget(p, ms, what, ac) {
|
|
|
13589
13803
|
let t;
|
|
13590
13804
|
const late = new Promise((r) => {
|
|
13591
13805
|
t = setTimeout(() => {
|
|
13592
|
-
|
|
13806
|
+
log29.debug(`${what}: over the ${ms}ms budget \u2014 dropped`);
|
|
13593
13807
|
ac?.abort();
|
|
13594
13808
|
r(null);
|
|
13595
13809
|
}, ms);
|
|
13596
13810
|
});
|
|
13597
13811
|
return Promise.race([p.catch((e) => {
|
|
13598
13812
|
const msg = String(e?.message ?? e);
|
|
13599
|
-
if (e?.name === "AbortError" || /aborted/i.test(msg))
|
|
13600
|
-
else
|
|
13813
|
+
if (e?.name === "AbortError" || /aborted/i.test(msg)) log29.debug(`${what}: aborted after its budget`);
|
|
13814
|
+
else log29.warn(`${what} failed \u2014 falling back: ${msg}`);
|
|
13601
13815
|
return null;
|
|
13602
13816
|
}), late]).finally(() => clearTimeout(t));
|
|
13603
13817
|
}
|
|
@@ -13610,6 +13824,7 @@ var SecondChannel = class {
|
|
|
13610
13824
|
for (const k of Object.keys(preset)) if (!options || !(k in options)) this.normalTiming[k] = base[k];
|
|
13611
13825
|
this.startedAt = this.o.now();
|
|
13612
13826
|
if (this.o.lang) this.setLanguage(this.o.lang, true);
|
|
13827
|
+
if (this.o.mode === "live" && this.o.grow) this.tree = new ConvoTree(this.o.tree);
|
|
13613
13828
|
}
|
|
13614
13829
|
options;
|
|
13615
13830
|
heard = "";
|
|
@@ -13638,6 +13853,12 @@ var SecondChannel = class {
|
|
|
13638
13853
|
// one bridge per main turn
|
|
13639
13854
|
bridgeDraft = null;
|
|
13640
13855
|
// a bridge generated ahead, used only if ready in time
|
|
13856
|
+
bridgeReady = Promise.resolve();
|
|
13857
|
+
// live: that draft settled
|
|
13858
|
+
askLeaf = null;
|
|
13859
|
+
// live: this turn's ask leaf
|
|
13860
|
+
leafReady = Promise.resolve();
|
|
13861
|
+
// live: the turn-end leaf pick settled
|
|
13641
13862
|
recent = [];
|
|
13642
13863
|
picks = /* @__PURE__ */ new Map();
|
|
13643
13864
|
inflight = null;
|
|
@@ -13665,6 +13886,21 @@ var SecondChannel = class {
|
|
|
13665
13886
|
normalTiming = {};
|
|
13666
13887
|
// chatty without aec: the preset's keys back at their defaults
|
|
13667
13888
|
degradedLogged = false;
|
|
13889
|
+
tree = null;
|
|
13890
|
+
// live with a grower only
|
|
13891
|
+
growing = false;
|
|
13892
|
+
growTries = 0;
|
|
13893
|
+
// per turn
|
|
13894
|
+
replyGrown = false;
|
|
13895
|
+
// one tree per reply (idle comes more than once)
|
|
13896
|
+
talk = [];
|
|
13897
|
+
leaves = [];
|
|
13898
|
+
// leaves played this call
|
|
13899
|
+
sinceTag = Infinity;
|
|
13900
|
+
regrown = false;
|
|
13901
|
+
picking = false;
|
|
13902
|
+
breathTimer = null;
|
|
13903
|
+
leafTimer = null;
|
|
13668
13904
|
/** The language lines are spoken in (detected from the user's words, or set by the host). */
|
|
13669
13905
|
get language() {
|
|
13670
13906
|
return this.lang;
|
|
@@ -13676,7 +13912,7 @@ var SecondChannel = class {
|
|
|
13676
13912
|
if (host) this.pinned = true;
|
|
13677
13913
|
const lang = primaryLang(tag);
|
|
13678
13914
|
if (!lang || lang === this.lang) return;
|
|
13679
|
-
|
|
13915
|
+
log29.debug(`language ${this.lang} \u2192 ${lang}`);
|
|
13680
13916
|
this.lang = lang;
|
|
13681
13917
|
this.recent = [];
|
|
13682
13918
|
this.picks.clear();
|
|
@@ -13689,6 +13925,10 @@ var SecondChannel = class {
|
|
|
13689
13925
|
const l = detectLanguage(text, !!this.lang);
|
|
13690
13926
|
if (l) this.setLanguage(l);
|
|
13691
13927
|
}
|
|
13928
|
+
/** `live` speaks no stock bridge/filler, with or without aec. */
|
|
13929
|
+
get ownWords() {
|
|
13930
|
+
return this.options.mode === "live";
|
|
13931
|
+
}
|
|
13692
13932
|
get bank() {
|
|
13693
13933
|
return this.lang ? this.o.banks ? this.o.banks.get(this.lang) : this.lang === "en" ? EN_BANK : null : null;
|
|
13694
13934
|
}
|
|
@@ -13712,7 +13952,23 @@ var SecondChannel = class {
|
|
|
13712
13952
|
this.onPause(this.o.fillerPauseMs);
|
|
13713
13953
|
}, this.o.fillerPauseMs);
|
|
13714
13954
|
let cue = null;
|
|
13715
|
-
if (this.
|
|
13955
|
+
if (this.tree) {
|
|
13956
|
+
if (this.tree.empty && !this.growing && this.growTries < 2) this.requestTree();
|
|
13957
|
+
if (!this.tree.empty) {
|
|
13958
|
+
this.treeStep(t);
|
|
13959
|
+
if (!this.regrown && words3(t).length >= this.o.regrowAtWords) {
|
|
13960
|
+
this.regrown = true;
|
|
13961
|
+
this.requestTree(t);
|
|
13962
|
+
}
|
|
13963
|
+
this.armBreath(t);
|
|
13964
|
+
if (this.bcTimer) {
|
|
13965
|
+
clearTimeout(this.bcTimer);
|
|
13966
|
+
this.bcTimer = null;
|
|
13967
|
+
}
|
|
13968
|
+
return;
|
|
13969
|
+
}
|
|
13970
|
+
}
|
|
13971
|
+
if (this.o.anticipate && !this.tree) {
|
|
13716
13972
|
const n = words3(t).length;
|
|
13717
13973
|
if (!this.plan && !this.planning && this.planTries < 2) this.requestPlan();
|
|
13718
13974
|
else if (this.plan && !this.revised && n >= this.o.reviseAtWords) {
|
|
@@ -13757,11 +14013,24 @@ var SecondChannel = class {
|
|
|
13757
14013
|
this.decidedAt = 0;
|
|
13758
14014
|
this.bridged = false;
|
|
13759
14015
|
this.cueFrom = 0;
|
|
13760
|
-
if (this.
|
|
14016
|
+
if (this.tree) {
|
|
14017
|
+
if (this.reply.trim() && !this.replyGrown) {
|
|
14018
|
+
this.replyGrown = true;
|
|
14019
|
+
this.noteTalk("you", this.reply);
|
|
14020
|
+
this.requestTree();
|
|
14021
|
+
}
|
|
14022
|
+
} else if (this.o.anticipate && this.reply.trim() && !this.plan && !this.planning) this.requestPlan();
|
|
13761
14023
|
return;
|
|
13762
14024
|
}
|
|
13763
14025
|
if (s === "queued") {
|
|
13764
14026
|
this.turnNo++;
|
|
14027
|
+
this.growTries = 0;
|
|
14028
|
+
this.replyGrown = false;
|
|
14029
|
+
this.regrown = false;
|
|
14030
|
+
if (this.breathTimer) {
|
|
14031
|
+
clearTimeout(this.breathTimer);
|
|
14032
|
+
this.breathTimer = null;
|
|
14033
|
+
}
|
|
13765
14034
|
this.plan = null;
|
|
13766
14035
|
this.planning = false;
|
|
13767
14036
|
this.planTries = 0;
|
|
@@ -13775,7 +14044,7 @@ var SecondChannel = class {
|
|
|
13775
14044
|
if (this[k]) clearTimeout(this[k]);
|
|
13776
14045
|
this[k] = null;
|
|
13777
14046
|
}
|
|
13778
|
-
if (this.o.instantBridge) this.prefetchBridge();
|
|
14047
|
+
if (this.o.instantBridge || this.ownWords) this.prefetchBridge();
|
|
13779
14048
|
const wait = Math.max(this.o.bridgeDelayMs, this.o.minGapMs - (this.o.now() - this.lastAt));
|
|
13780
14049
|
if (wait > 0) this.bridgeTimer = setTimeout(() => {
|
|
13781
14050
|
this.bridgeTimer = null;
|
|
@@ -13802,6 +14071,10 @@ var SecondChannel = class {
|
|
|
13802
14071
|
this.detect(this.heard);
|
|
13803
14072
|
this.main = "idle";
|
|
13804
14073
|
this.onAgentState("queued");
|
|
14074
|
+
if (this.tree) {
|
|
14075
|
+
this.noteTalk("them", this.heard);
|
|
14076
|
+
this.leafReady = this.turnEndLeaf();
|
|
14077
|
+
}
|
|
13805
14078
|
}
|
|
13806
14079
|
/** The main answer's streamed text (before its audio): channel-1 is responding — no bridge from here on. */
|
|
13807
14080
|
onMainTokens(text) {
|
|
@@ -13821,7 +14094,7 @@ var SecondChannel = class {
|
|
|
13821
14094
|
try {
|
|
13822
14095
|
this.o.cancel();
|
|
13823
14096
|
} catch (e) {
|
|
13824
|
-
|
|
14097
|
+
log29.warn(`cancel threw: ${e.message}`);
|
|
13825
14098
|
}
|
|
13826
14099
|
}
|
|
13827
14100
|
}
|
|
@@ -13832,6 +14105,10 @@ var SecondChannel = class {
|
|
|
13832
14105
|
this.cutLine = null;
|
|
13833
14106
|
return !!c && c === text.trim();
|
|
13834
14107
|
}
|
|
14108
|
+
/** Another fill line (progress) already covers this turn's wait: no bridge after it. */
|
|
14109
|
+
covered() {
|
|
14110
|
+
this.bridged = true;
|
|
14111
|
+
}
|
|
13835
14112
|
/** Resolves when the in-flight line finished playing (immediately when none) — hosts enqueue channel-1 audio behind it. */
|
|
13836
14113
|
drain() {
|
|
13837
14114
|
return this.inflight ?? Promise.resolve();
|
|
@@ -13911,6 +14188,106 @@ var SecondChannel = class {
|
|
|
13911
14188
|
this.o.onPlan(p, !!heard, Math.round(this.o.now() - t0));
|
|
13912
14189
|
});
|
|
13913
14190
|
}
|
|
14191
|
+
noteTalk(who, text) {
|
|
14192
|
+
this.talk = [...this.talk, `${who}: ${text.trim().slice(-300)}`].slice(-this.o.talkLines);
|
|
14193
|
+
}
|
|
14194
|
+
/** Grow the tree off the hot path. A tree that lands after its turn is still the best guess: it replaces what is live. */
|
|
14195
|
+
requestTree(heard) {
|
|
14196
|
+
if (!this.tree || !this.o.grow || !this.lang || this.growing) return;
|
|
14197
|
+
this.growing = true;
|
|
14198
|
+
this.growTries++;
|
|
14199
|
+
const t0 = this.o.now(), ac = new AbortController(), tree = this.tree;
|
|
14200
|
+
const ctx = { talk: heard ? [...this.talk, `them (still talking): ${heard.slice(-240)}`] : [...this.talk], lang: detectLanguage(this.talk.join(" ").replace(/\b(them|you):/g, "")) ?? this.lang, recent: this.leaves.slice(-this.o.leafMemory), ...this.o.persona ? { persona: this.o.persona } : {} };
|
|
14201
|
+
const late = setTimeout(() => ac.abort(), this.o.growBudgetMs);
|
|
14202
|
+
void this.o.grow(ctx, ac.signal).then((r) => {
|
|
14203
|
+
if (r.nodes.length) tree.grow(r.nodes, this.userSpeaking ? words3(this.heard).length : 0);
|
|
14204
|
+
this.o.onTree({ ms: Math.round(this.o.now() - t0), branches: r.nodes.length, lines: r.nodes.flatMap((n) => [n.line, ...n.next.map((k) => k.line)]), ...r.tokens ? { tokens: r.tokens } : {} });
|
|
14205
|
+
}, (e) => {
|
|
14206
|
+
log29.warn(`tree failed: ${e?.message ?? e}`);
|
|
14207
|
+
this.o.onTree({ ms: Math.round(this.o.now() - t0), branches: 0, error: String(e?.message ?? e) });
|
|
14208
|
+
}).finally(() => {
|
|
14209
|
+
clearTimeout(late);
|
|
14210
|
+
this.growing = false;
|
|
14211
|
+
});
|
|
14212
|
+
}
|
|
14213
|
+
/** Text match on the partial (no model). barge_in plays now, in_between at the next breath; turn_end waits in the tree. */
|
|
14214
|
+
treeStep(t) {
|
|
14215
|
+
const hit = this.tree.step(t);
|
|
14216
|
+
if (!hit) return;
|
|
14217
|
+
if (hit.node.moment === "barge_in") return this.playLeaf(hit, "interim", "backchannel");
|
|
14218
|
+
if (this.leafTimer) clearTimeout(this.leafTimer);
|
|
14219
|
+
const at = words3(t).length;
|
|
14220
|
+
this.leafTimer = setTimeout(() => {
|
|
14221
|
+
this.leafTimer = null;
|
|
14222
|
+
if (this.userSpeaking && words3(this.heard).length - at < this.o.leafStaleWords) this.playLeaf(hit, "interim", "backchannel");
|
|
14223
|
+
}, this.o.cuePauseMs);
|
|
14224
|
+
}
|
|
14225
|
+
/** A breath with no cue hit: the quick model may name the leaf that fits the words just said. Its answer plays only if
|
|
14226
|
+
* they have not moved on. */
|
|
14227
|
+
armBreath(t) {
|
|
14228
|
+
if (this.breathTimer) clearTimeout(this.breathTimer);
|
|
14229
|
+
if (!this.o.pickLeaf || !this.o.aec) return;
|
|
14230
|
+
this.breathTimer = setTimeout(() => {
|
|
14231
|
+
this.breathTimer = null;
|
|
14232
|
+
const n = words3(t).length, tree = this.tree;
|
|
14233
|
+
if (n < this.o.backchannelMinWords || this.heard !== t || this.leafTimer || this.picking || tree.empty || this.leafGated()) return;
|
|
14234
|
+
this.picking = true;
|
|
14235
|
+
const ac = new AbortController(), nodes = tree.nodes.filter((x) => x.moment !== "ask"), lines = nodes.map((x, i) => ({ i, line: x.line, when: x.when }));
|
|
14236
|
+
void withBudget(this.o.pickLeaf(t, lines, ac.signal), this.o.pickBudgetMs, "breath pick", ac).then((i) => {
|
|
14237
|
+
this.picking = false;
|
|
14238
|
+
const node = typeof i === "number" ? nodes[i] : void 0, hit = node && tree.nodes.includes(node) ? tree.picked(tree.nodes.indexOf(node), this.heard) : null;
|
|
14239
|
+
if (!hit || !this.userSpeaking || words3(this.heard).length - n >= this.o.leafStaleWords) return;
|
|
14240
|
+
tree.take(hit.node, hit.conf);
|
|
14241
|
+
this.playLeaf(hit, "interim", "backchannel");
|
|
14242
|
+
});
|
|
14243
|
+
}, this.o.leafBreathMs);
|
|
14244
|
+
}
|
|
14245
|
+
/** The user's turn went to MAIN: the armed leaf at once, else the quick model may name one in time. It plays only while
|
|
14246
|
+
* MAIN is still silent, as the turn's first sound. */
|
|
14247
|
+
async turnEndLeaf() {
|
|
14248
|
+
const tree = this.tree, gen = this.gen, heard = this.heard;
|
|
14249
|
+
let hit = tree.turnLeaf();
|
|
14250
|
+
if (!hit && this.o.pickLeaf && !tree.empty) {
|
|
14251
|
+
const ac = new AbortController(), lines = tree.nodes.map((n, i2) => ({ i: i2, line: n.line, when: n.when }));
|
|
14252
|
+
const i = await withBudget(this.o.pickLeaf(heard, lines, ac.signal), this.o.pickBudgetMs, "leaf pick", ac);
|
|
14253
|
+
if (typeof i === "number" && i >= 0) hit = tree.picked(i, heard);
|
|
14254
|
+
}
|
|
14255
|
+
tree.advance();
|
|
14256
|
+
if (hit?.node.moment === "ask") {
|
|
14257
|
+
if (gen === this.gen && echoesHeard(hit.node.line, heard)) this.askLeaf = { gen, text: hit.node.line };
|
|
14258
|
+
return;
|
|
14259
|
+
}
|
|
14260
|
+
if (hit && gen === this.gen && (this.main === "queued" || this.main === "thinking")) {
|
|
14261
|
+
this.playLeaf(hit, "working", "bridge");
|
|
14262
|
+
if (this.lastKind === "bridge" && this.bridged) {
|
|
14263
|
+
this.bridged = false;
|
|
14264
|
+
this.lastKind = null;
|
|
14265
|
+
if (this.bridgeTimer) clearTimeout(this.bridgeTimer);
|
|
14266
|
+
this.bridgeTimer = setTimeout(() => {
|
|
14267
|
+
this.bridgeTimer = null;
|
|
14268
|
+
void this.consider("working");
|
|
14269
|
+
}, this.o.minGapMs);
|
|
14270
|
+
}
|
|
14271
|
+
}
|
|
14272
|
+
}
|
|
14273
|
+
leafGated() {
|
|
14274
|
+
return !this.lang || this.audioLocked || !!this.inflight || this.o.now() - this.lastAt < this.o.minGapMs || this.capped();
|
|
14275
|
+
}
|
|
14276
|
+
/** A leaf's gates: never over MAIN's audio or another line, spaced, capped; never a repeat. */
|
|
14277
|
+
playLeaf(hit, trigger, kind) {
|
|
14278
|
+
const { moment } = hit.node, conf = Math.round(hit.conf * 100) / 100;
|
|
14279
|
+
const tagged = hit.node.line !== lineWords(hit.node.line);
|
|
14280
|
+
const line = tagged && this.sinceTag < this.o.tagEvery ? lineWords(hit.node.line) : hit.node.line;
|
|
14281
|
+
const gated = !line || this.leafGated() || this.leaves.includes(leafKey(line));
|
|
14282
|
+
const said = !gated && this.say(kind, line);
|
|
14283
|
+
if (said) {
|
|
14284
|
+
this.leaves = [...this.leaves, leafKey(line)].slice(-this.o.leafMemory);
|
|
14285
|
+
this.sinceTag = line === hit.node.line && tagged ? 0 : this.sinceTag + 1;
|
|
14286
|
+
}
|
|
14287
|
+
const e = { trigger, rule: kind, kind, text: line, ms: 0, moment, conf, acted: gated ? "gated" : said ? "spoken" : "skipped" };
|
|
14288
|
+
this.o.onEvent(e);
|
|
14289
|
+
this.o.onLeaf(e);
|
|
14290
|
+
}
|
|
13914
14291
|
/** A clause boundary mid-floor: a breath or a comma-like close. Not a question (it wants the answer, not "mm-hm"), and a
|
|
13915
14292
|
* sentence end only deep into a story — a short request's end is the end of their turn (replay: "mm-hm" right after
|
|
13916
14293
|
* "Check hacker news for recent news.", just before the final). */
|
|
@@ -13933,7 +14310,7 @@ var SecondChannel = class {
|
|
|
13933
14310
|
const opts = this.options;
|
|
13934
14311
|
if (opts.mode === "chatty" && !opts.aec && !this.degradedLogged) {
|
|
13935
14312
|
this.degradedLogged = true;
|
|
13936
|
-
|
|
14313
|
+
log29.info("chatty mode without echo cancellation \u2014 normal timing (our lines would re-trigger the mic)");
|
|
13937
14314
|
}
|
|
13938
14315
|
const rule = this.rule(trigger, pauseMs, breath, cue);
|
|
13939
14316
|
if (rule === "silence") {
|
|
@@ -13952,7 +14329,7 @@ var SecondChannel = class {
|
|
|
13952
14329
|
const d = await withBudget(this.o.decide(this.tail(), { ...this.state(pauseMs), rule }, ac.signal), this.o.decisionBudgetMs, "channel decision", ac);
|
|
13953
14330
|
choice = d?.choice;
|
|
13954
14331
|
if (choice && choice in CHANNEL_ACTIONS && (choice === "silence" || this.allowed(choice))) kind = choice;
|
|
13955
|
-
else if (choice && choice in CHANNEL_ACTIONS)
|
|
14332
|
+
else if (choice && choice in CHANNEL_ACTIONS) log29.debug(`decider chose ${choice} for a ${rule} moment \u2014 the rule stands`);
|
|
13956
14333
|
}
|
|
13957
14334
|
if (kind === "silence") return ev({ choice, acted: "silence" });
|
|
13958
14335
|
if (stale()) return ev({ choice, kind, acted: "stale" });
|
|
@@ -13984,15 +14361,28 @@ var SecondChannel = class {
|
|
|
13984
14361
|
/** Start writing this turn's bridge now, so it may be ready by bridgeDelayMs. The bridge never waits for it. */
|
|
13985
14362
|
prefetchBridge() {
|
|
13986
14363
|
this.bridgeDraft = null;
|
|
13987
|
-
|
|
13988
|
-
|
|
13989
|
-
|
|
13990
|
-
|
|
13991
|
-
|
|
13992
|
-
|
|
13993
|
-
|
|
14364
|
+
this.askLeaf = null;
|
|
14365
|
+
this.bridgeReady = Promise.resolve();
|
|
14366
|
+
if (!this.o.generate || !(this.ownWords || this.o.generateFor.includes("bridge")) || !this.lang || !this.heard || this.ownWords && turnIntent(this.heard) !== "ask" && !requestOpener(this.heard)) return;
|
|
14367
|
+
const gen = this.gen, ac = new AbortController(), own = this.ownWords, heard = this.heard;
|
|
14368
|
+
const ctx = { kind: "bridge", heard: this.tail(), state: this.main, avoid: [...this.recent], lang: this.lang, ...own ? { ask: true } : {} };
|
|
14369
|
+
this.bridgeReady = withBudget(this.o.generate(ctx, ac.signal), own ? this.o.bridgeBudgetMs : Math.max(this.o.generateBudgetMs, this.o.bridgeDelayMs), "bridge generate", ac).then((raw) => {
|
|
14370
|
+
const text = own && /^\s*none\b/i.test(raw ?? "") ? "" : cleanLine(raw ?? "", ctx.lang);
|
|
14371
|
+
if (text && gen === this.gen && (!own || echoesHeard(text, heard))) this.bridgeDraft = { gen, text };
|
|
14372
|
+
}).catch((e) => log29.debug(`bridge prefetch failed: ${e?.message ?? e}`));
|
|
13994
14373
|
}
|
|
13995
14374
|
async line(kind, react = true) {
|
|
14375
|
+
if (kind === "bridge" && this.ownWords) {
|
|
14376
|
+
const gen = this.gen;
|
|
14377
|
+
await Promise.all([this.leafReady, this.bridgeReady]);
|
|
14378
|
+
if (gen !== this.gen) return "";
|
|
14379
|
+
const leaf = this.askLeaf?.gen === gen ? this.askLeaf.text : "", d = this.bridgeDraft?.gen === gen ? this.bridgeDraft.text : "";
|
|
14380
|
+
if (leaf && !this.leaves.includes(leafKey(leaf))) {
|
|
14381
|
+
this.leaves = [...this.leaves, leafKey(leaf)].slice(-this.o.leafMemory);
|
|
14382
|
+
return leaf;
|
|
14383
|
+
}
|
|
14384
|
+
return d && !this.recent.some((r) => norm3(r) === norm3(d)) ? d : "";
|
|
14385
|
+
}
|
|
13996
14386
|
if (kind === "bridge" && this.o.instantBridge) {
|
|
13997
14387
|
const d = this.bridgeDraft?.gen === this.gen ? this.bridgeDraft.text : "";
|
|
13998
14388
|
this.bridgeDraft = null;
|
|
@@ -14006,13 +14396,14 @@ var SecondChannel = class {
|
|
|
14006
14396
|
if (raw === null) ac.abort();
|
|
14007
14397
|
const text = cleanLine(raw ?? "", this.lang);
|
|
14008
14398
|
if (text && !this.recent.some((r) => norm3(r) === norm3(text))) return text;
|
|
14009
|
-
if (text)
|
|
14399
|
+
if (text) log29.debug(`generated "${text}" repeats a recent line \u2014 canned`);
|
|
14010
14400
|
}
|
|
14011
14401
|
return this.pick(kind);
|
|
14012
14402
|
}
|
|
14013
14403
|
/** Canned rotation in the user's language: never one of the last `bankExclude` picks of this kind, nor a recent
|
|
14014
14404
|
* line. '' = no bank for this language yet (silence). */
|
|
14015
14405
|
pick(kind) {
|
|
14406
|
+
if (this.ownWords && kind !== "backchannel") return "";
|
|
14016
14407
|
const pool = this.bank?.[kind] ?? [];
|
|
14017
14408
|
if (!pool.length) return "";
|
|
14018
14409
|
const hist = this.picks.get(kind) ?? [];
|
|
@@ -14028,7 +14419,7 @@ var SecondChannel = class {
|
|
|
14028
14419
|
try {
|
|
14029
14420
|
r = this.o.speak(text, kind);
|
|
14030
14421
|
} catch (e) {
|
|
14031
|
-
|
|
14422
|
+
log29.warn(`speak threw \u2014 line dropped: ${e.message}`);
|
|
14032
14423
|
return false;
|
|
14033
14424
|
}
|
|
14034
14425
|
if (r === false) return false;
|
|
@@ -14042,7 +14433,7 @@ var SecondChannel = class {
|
|
|
14042
14433
|
if (words4) this.o.show(words4, kind);
|
|
14043
14434
|
const p = Promise.resolve(r).then(() => {
|
|
14044
14435
|
}, (e) => {
|
|
14045
|
-
|
|
14436
|
+
log29.warn(`channel line playback failed: ${e?.message ?? e}`);
|
|
14046
14437
|
}).finally(() => {
|
|
14047
14438
|
if (this.inflight === p) this.inflight = null;
|
|
14048
14439
|
});
|
|
@@ -14086,7 +14477,9 @@ function channelLine(line, kind) {
|
|
|
14086
14477
|
}
|
|
14087
14478
|
function fastLineGenerator(ai, model, gender) {
|
|
14088
14479
|
return async (c, signal) => {
|
|
14089
|
-
const prompt =
|
|
14480
|
+
const prompt = c.ask ? `A live voice call. The user just said: "${c.heard}"
|
|
14481
|
+
If this asks you to look up, check, find or do something that takes a while, write ONE spoken line of 2-5 words in ${languageName(c.lang)} that names the thing in their own words and says you are on it ("Hacker News, one sec."). If it is small talk, a statement, or something you can answer at once, write: none
|
|
14482
|
+
${personaHint(gender)} Output only the line.` : `You voice the tiny side-sounds of a live spoken conversation. Write ONE line of 1-5 words: ${KIND_HINT2[c.kind]}.
|
|
14090
14483
|
` + (c.react ? `Here the line may be ${REACT_HINT}.
|
|
14091
14484
|
` : "") + (c.tags ? `${TAG_HINT}
|
|
14092
14485
|
` : "") + `The user just said: "${c.heard}"
|
|
@@ -14106,7 +14499,7 @@ function closedQuestion(reply) {
|
|
|
14106
14499
|
}
|
|
14107
14500
|
|
|
14108
14501
|
// src/voice/call.ts
|
|
14109
|
-
var
|
|
14502
|
+
var log30 = forComponent("VoiceCall");
|
|
14110
14503
|
var VoiceCallOptions = class {
|
|
14111
14504
|
/** Host runs MAIN with exactly `text` (a replace: roll the `replaces` turn back first). */
|
|
14112
14505
|
sendTurn = () => {
|
|
@@ -14181,7 +14574,7 @@ var VoiceCall = class {
|
|
|
14181
14574
|
cancel: () => o.cancel(),
|
|
14182
14575
|
now: o.now
|
|
14183
14576
|
});
|
|
14184
|
-
this.progress = new Progress({ ...ai ? { generate: fastProgressGenerator(ai, o.fastModel, o.gender) } : {}, gender: o.gender, now: o.now, ...o.progress });
|
|
14577
|
+
this.progress = new Progress({ ...o.mode === "live" ? { templates: {}, generateBudgetMs: 1500 } : {}, ...ai ? { generate: fastProgressGenerator(ai, o.fastModel, o.gender) } : {}, gender: o.gender, now: o.now, ...o.progress });
|
|
14185
14578
|
this.judge = new OverlapJudge({ ...ai ? { model: overlapModelFor(ai) } : {}, now: o.now });
|
|
14186
14579
|
this.gate = new TurnGate({
|
|
14187
14580
|
now: o.now,
|
|
@@ -14234,7 +14627,7 @@ var VoiceCall = class {
|
|
|
14234
14627
|
this.gate.speaking();
|
|
14235
14628
|
const c = this.cur;
|
|
14236
14629
|
if (this.o.mode === "live" && c?.running && !c.worded && text.trim().split(/\s+/).length >= 2) {
|
|
14237
|
-
|
|
14630
|
+
log30.debug("user resumed before the reply \u2014 yielded");
|
|
14238
14631
|
this.barge();
|
|
14239
14632
|
}
|
|
14240
14633
|
this.follow(text);
|
|
@@ -14338,7 +14731,7 @@ var VoiceCall = class {
|
|
|
14338
14731
|
try {
|
|
14339
14732
|
this.o.cancel();
|
|
14340
14733
|
} catch (e) {
|
|
14341
|
-
|
|
14734
|
+
log30.warn(`cancel threw: ${e.message}`);
|
|
14342
14735
|
}
|
|
14343
14736
|
if (this.cur?.running) {
|
|
14344
14737
|
this.cur.running = false;
|
|
@@ -14425,7 +14818,7 @@ var VoiceCall = class {
|
|
|
14425
14818
|
try {
|
|
14426
14819
|
r = this.o.speak(text, kind);
|
|
14427
14820
|
} catch (e) {
|
|
14428
|
-
|
|
14821
|
+
log30.warn(`speak threw: ${e.message}`);
|
|
14429
14822
|
return false;
|
|
14430
14823
|
}
|
|
14431
14824
|
if (r === false) return false;
|
|
@@ -14476,7 +14869,8 @@ var VoiceCall = class {
|
|
|
14476
14869
|
async onTool(c, name, args) {
|
|
14477
14870
|
const lang = this.lang;
|
|
14478
14871
|
if (!lang || c.streamed) return;
|
|
14479
|
-
const line = await this.progress.line(name, args, lang);
|
|
14872
|
+
const line = await this.progress.line(name, args, lang, this.o.mode === "live" ? c.text : "");
|
|
14873
|
+
if (!line && this.o.mode === "live") this.o.onMetric({ name: "drop", id: c.id, kind: `no progress line: ${name}` });
|
|
14480
14874
|
if (!line || this.cur !== c || c.streamed || !c.running || this.lang !== lang) return;
|
|
14481
14875
|
this.clearProgress();
|
|
14482
14876
|
const tryNow = () => {
|
|
@@ -14488,6 +14882,7 @@ var VoiceCall = class {
|
|
|
14488
14882
|
}
|
|
14489
14883
|
if (this.say(line, "progress") !== false) {
|
|
14490
14884
|
this.progress.spoke(line);
|
|
14885
|
+
this.fill.covered();
|
|
14491
14886
|
this.o.show(line, "progress");
|
|
14492
14887
|
}
|
|
14493
14888
|
};
|
|
@@ -14511,7 +14906,7 @@ init_logging();
|
|
|
14511
14906
|
init_platform();
|
|
14512
14907
|
import { spawn } from "child_process";
|
|
14513
14908
|
import { createHash } from "crypto";
|
|
14514
|
-
var
|
|
14909
|
+
var log31 = forComponent("mcp");
|
|
14515
14910
|
var PROTOCOL_VERSION = "2025-06-18";
|
|
14516
14911
|
var DEFAULT_TIMEOUT_MS = 3e4;
|
|
14517
14912
|
var DEFAULT_CALL_TIMEOUT_MS = 30 * 6e4;
|
|
@@ -14543,7 +14938,7 @@ var StdioTransport = class {
|
|
|
14543
14938
|
proc.stdout.setEncoding("utf8");
|
|
14544
14939
|
proc.stdout.on("data", (chunk) => this.onData(chunk));
|
|
14545
14940
|
proc.stderr.setEncoding("utf8");
|
|
14546
|
-
proc.stderr.on("data", (chunk) =>
|
|
14941
|
+
proc.stderr.on("data", (chunk) => log31.debug(`[${command}] stderr:`, chunk.trimEnd()));
|
|
14547
14942
|
proc.on("exit", (code) => this.failAll(new Error(`MCP server "${command}" exited (code ${code})`)));
|
|
14548
14943
|
proc.on("error", (e) => this.failAll(e instanceof Error ? e : new Error(String(e))));
|
|
14549
14944
|
}
|
|
@@ -14557,7 +14952,7 @@ var StdioTransport = class {
|
|
|
14557
14952
|
try {
|
|
14558
14953
|
this.dispatch(JSON.parse(line));
|
|
14559
14954
|
} catch (e) {
|
|
14560
|
-
|
|
14955
|
+
log31.debug("dropping non-JSON line from MCP server:", line, e);
|
|
14561
14956
|
}
|
|
14562
14957
|
}
|
|
14563
14958
|
}
|
|
@@ -14567,7 +14962,7 @@ var StdioTransport = class {
|
|
|
14567
14962
|
try {
|
|
14568
14963
|
p2?.onProgress?.(msg.params ?? {});
|
|
14569
14964
|
} catch (e) {
|
|
14570
|
-
|
|
14965
|
+
log31.debug("onProgress handler threw", e);
|
|
14571
14966
|
}
|
|
14572
14967
|
return;
|
|
14573
14968
|
}
|
|
@@ -14605,7 +15000,7 @@ var StdioTransport = class {
|
|
|
14605
15000
|
const onAbort = () => {
|
|
14606
15001
|
if (!this.pending.delete(id)) return;
|
|
14607
15002
|
clearTimeout(timer);
|
|
14608
|
-
this.notify("notifications/cancelled", { requestId: id, reason: String(signal?.reason?.message ?? "cancelled") }).catch((e) =>
|
|
15003
|
+
this.notify("notifications/cancelled", { requestId: id, reason: String(signal?.reason?.message ?? "cancelled") }).catch((e) => log31.debug("cancel notify failed", e));
|
|
14609
15004
|
reject(abortError(signal));
|
|
14610
15005
|
};
|
|
14611
15006
|
const done = () => signal?.removeEventListener("abort", onAbort);
|
|
@@ -14629,7 +15024,7 @@ var StdioTransport = class {
|
|
|
14629
15024
|
try {
|
|
14630
15025
|
this.proc?.stdin?.end();
|
|
14631
15026
|
} catch (e) {
|
|
14632
|
-
|
|
15027
|
+
log31.debug("stdin end failed", e);
|
|
14633
15028
|
}
|
|
14634
15029
|
if (!(IS_WIN && killTree(this.proc?.pid, "SIGTERM"))) this.proc?.kill();
|
|
14635
15030
|
}
|
|
@@ -14664,7 +15059,7 @@ var HttpTransport = class {
|
|
|
14664
15059
|
return await this.post({ jsonrpc: "2.0", id, method, params: opts.onProgress ? withProgressToken(params, id) : params }, false, signal, opts.onProgress);
|
|
14665
15060
|
} catch (e) {
|
|
14666
15061
|
if (opts.signal?.aborted) {
|
|
14667
|
-
void this.notify("notifications/cancelled", { requestId: id, reason: String(opts.signal.reason?.message ?? "cancelled") }).catch((err2) =>
|
|
15062
|
+
void this.notify("notifications/cancelled", { requestId: id, reason: String(opts.signal.reason?.message ?? "cancelled") }).catch((err2) => log31.debug("cancel notify failed", err2));
|
|
14668
15063
|
throw abortError(opts.signal);
|
|
14669
15064
|
}
|
|
14670
15065
|
throw e;
|
|
@@ -14707,7 +15102,7 @@ function sseMessage(line) {
|
|
|
14707
15102
|
try {
|
|
14708
15103
|
return JSON.parse(trimmed.slice(5).trim());
|
|
14709
15104
|
} catch (e) {
|
|
14710
|
-
|
|
15105
|
+
log31.debug("skipping unparseable SSE data line", e);
|
|
14711
15106
|
return void 0;
|
|
14712
15107
|
}
|
|
14713
15108
|
}
|
|
@@ -14717,7 +15112,7 @@ async function readSseResponse(resp, id, onProgress) {
|
|
|
14717
15112
|
try {
|
|
14718
15113
|
onProgress?.(obj.params ?? {});
|
|
14719
15114
|
} catch (e) {
|
|
14720
|
-
|
|
15115
|
+
log31.debug("onProgress handler threw", e);
|
|
14721
15116
|
}
|
|
14722
15117
|
return void 0;
|
|
14723
15118
|
}
|
|
@@ -14816,7 +15211,7 @@ async function mountWithDeadline(name, cfg, mountTimeoutMs) {
|
|
|
14816
15211
|
return { name, client, tools, specs, serverInfo: init?.serverInfo, config: cfg };
|
|
14817
15212
|
})(), mountTimeoutMs, name);
|
|
14818
15213
|
} catch (e) {
|
|
14819
|
-
await client.close().catch((err2) =>
|
|
15214
|
+
await client.close().catch((err2) => log31.debug(`close after failed mount of "${name}": ${err2}`));
|
|
14820
15215
|
throw e;
|
|
14821
15216
|
}
|
|
14822
15217
|
}
|
|
@@ -14827,15 +15222,15 @@ function validEntries(servers) {
|
|
|
14827
15222
|
return Object.entries(servers).filter(([name, cfg]) => {
|
|
14828
15223
|
if (!cfg || cfg.disabled) return false;
|
|
14829
15224
|
if (!cfg.command && !cfg.url) {
|
|
14830
|
-
|
|
15225
|
+
log31.warn(`MCP server "${name}" needs a command (stdio) or url (http) \u2014 skipping`);
|
|
14831
15226
|
return false;
|
|
14832
15227
|
}
|
|
14833
15228
|
return true;
|
|
14834
15229
|
});
|
|
14835
15230
|
}
|
|
14836
15231
|
function logMountFailure(name, e) {
|
|
14837
|
-
if (e instanceof McpAuthError)
|
|
14838
|
-
else
|
|
15232
|
+
if (e instanceof McpAuthError) log31.warn(`MCP "${name}" needs-auth: HTTP ${e.status} \u2014 set bearerToken or headers in its config; skipping`);
|
|
15233
|
+
else log31.error(`MCP server "${name}" failed to mount: ${e?.message ?? e}`);
|
|
14839
15234
|
}
|
|
14840
15235
|
async function mountMcpServers(servers = {}, opts = {}) {
|
|
14841
15236
|
const entries = validEntries(servers);
|
|
@@ -14845,7 +15240,7 @@ async function mountMcpServers(servers = {}, opts = {}) {
|
|
|
14845
15240
|
const name = entries[i][0];
|
|
14846
15241
|
if (r.status === "fulfilled") {
|
|
14847
15242
|
out.push(r.value);
|
|
14848
|
-
|
|
15243
|
+
log31.debug(`MCP "${name}" mounted \u2014 ${r.value.tools.length} tool(s)${r.value.serverInfo?.name ? ` from ${r.value.serverInfo.name}` : ""}`);
|
|
14849
15244
|
} else logMountFailure(name, r.reason);
|
|
14850
15245
|
});
|
|
14851
15246
|
return out;
|
|
@@ -14885,7 +15280,7 @@ var McpPool = class {
|
|
|
14885
15280
|
const prev = this.warm.get(key);
|
|
14886
15281
|
if (prev) {
|
|
14887
15282
|
clearTimeout(prev.timer);
|
|
14888
|
-
if (prev.client !== client) void prev.client.close().catch((err2) =>
|
|
15283
|
+
if (prev.client !== client) void prev.client.close().catch((err2) => log31.debug(`warm-pool replace close failed: ${err2}`));
|
|
14889
15284
|
}
|
|
14890
15285
|
const e = { client, timer: void 0 };
|
|
14891
15286
|
this.warm.set(key, e);
|
|
@@ -14902,7 +15297,7 @@ var McpPool = class {
|
|
|
14902
15297
|
const e = this.warm.get(key);
|
|
14903
15298
|
if (!e) return;
|
|
14904
15299
|
this.warm.delete(key);
|
|
14905
|
-
await e.client.close().catch((err2) =>
|
|
15300
|
+
await e.client.close().catch((err2) => log31.debug(`warm-pool evict close failed: ${err2}`));
|
|
14906
15301
|
}
|
|
14907
15302
|
async closeAll() {
|
|
14908
15303
|
for (const e of this.warm.values()) {
|
|
@@ -15148,7 +15543,7 @@ init_tools_shell();
|
|
|
15148
15543
|
// src/tools.notify.ts
|
|
15149
15544
|
init_logging();
|
|
15150
15545
|
import { execFile as execFile2 } from "child_process";
|
|
15151
|
-
var
|
|
15546
|
+
var log33 = forComponent("notify");
|
|
15152
15547
|
var WIN_TOAST = [
|
|
15153
15548
|
"[Windows.UI.Notifications.ToastNotificationManager, Windows.UI.Notifications, ContentType = WindowsRuntime] | Out-Null",
|
|
15154
15549
|
"$t = [Windows.UI.Notifications.ToastNotificationManager]::GetTemplateContent([Windows.UI.Notifications.ToastTemplateType]::ToastText02)",
|
|
@@ -15179,7 +15574,7 @@ function makeNotifyTool(opts = {}) {
|
|
|
15179
15574
|
return new Promise((resolve6) => {
|
|
15180
15575
|
run(argv[0], argv[1], { timeout: 5e3, ...extra }, (e) => {
|
|
15181
15576
|
if (e) {
|
|
15182
|
-
|
|
15577
|
+
log33.debug("notification failed", e);
|
|
15183
15578
|
resolve6(`Notification failed: ${e.message}`);
|
|
15184
15579
|
} else resolve6("Notification shown.");
|
|
15185
15580
|
});
|
|
@@ -15196,7 +15591,7 @@ init_logging();
|
|
|
15196
15591
|
import { existsSync as existsSync2, readFileSync as readFileSync5 } from "fs";
|
|
15197
15592
|
import { homedir } from "os";
|
|
15198
15593
|
import { delimiter as delimiter2 } from "path";
|
|
15199
|
-
var
|
|
15594
|
+
var log34 = forComponent("cli-util");
|
|
15200
15595
|
function extraDirs(env = process.env) {
|
|
15201
15596
|
return (env.AGENTX_EXTRA_DIRS || "").split(delimiter2).map((d) => d.trim()).filter(Boolean);
|
|
15202
15597
|
}
|
|
@@ -15216,7 +15611,7 @@ function parseJson(text, fallback, what = "json") {
|
|
|
15216
15611
|
try {
|
|
15217
15612
|
return JSON.parse(text);
|
|
15218
15613
|
} catch (e) {
|
|
15219
|
-
|
|
15614
|
+
log34.debug(`parseJson(${what}) failed: ${e.message}`);
|
|
15220
15615
|
return fallback;
|
|
15221
15616
|
}
|
|
15222
15617
|
}
|
|
@@ -15226,7 +15621,7 @@ function readJsonFile(path, fallback) {
|
|
|
15226
15621
|
try {
|
|
15227
15622
|
text = readFileSync5(path, "utf8");
|
|
15228
15623
|
} catch (e) {
|
|
15229
|
-
|
|
15624
|
+
log34.debug(`readJsonFile(${path}) unreadable: ${e.message}`);
|
|
15230
15625
|
return fallback;
|
|
15231
15626
|
}
|
|
15232
15627
|
return parseJson(text, fallback, path);
|
|
@@ -15540,7 +15935,7 @@ import { existsSync as existsSync4, mkdirSync as mkdirSync5, readFileSync as rea
|
|
|
15540
15935
|
import { homedir as homedir3 } from "os";
|
|
15541
15936
|
import { dirname as dirname4, join as join8 } from "path";
|
|
15542
15937
|
import { fileURLToPath } from "url";
|
|
15543
|
-
var
|
|
15938
|
+
var log35 = forComponent("VoiceIO");
|
|
15544
15939
|
var now3 = () => performance.now();
|
|
15545
15940
|
var Player = class {
|
|
15546
15941
|
proc = null;
|
|
@@ -15554,7 +15949,7 @@ var Player = class {
|
|
|
15554
15949
|
["-loglevel", "quiet", "-nodisp", "-fflags", "nobuffer", "-flags", "low_delay", "-probesize", "32", "-f", "s16le", "-ar", String(TTS_SAMPLE_RATE), "-ch_layout", "mono", "-i", "-"],
|
|
15555
15950
|
{ stdio: ["pipe", "ignore", "ignore"] }
|
|
15556
15951
|
);
|
|
15557
|
-
this.proc.on("error", (e) =>
|
|
15952
|
+
this.proc.on("error", (e) => log35.warn(`ffplay error: ${e.message}`));
|
|
15558
15953
|
this.proc.stdin.on("error", () => {
|
|
15559
15954
|
});
|
|
15560
15955
|
this.bytesWritten = 0;
|
|
@@ -15592,7 +15987,7 @@ function detectFfmpegMic() {
|
|
|
15592
15987
|
const devices = [...audio.matchAll(/\[(\d+)\] (.+)/g)].map(([, idx, name]) => ({ idx, name: name.trim() }));
|
|
15593
15988
|
const mic = devices.find((d) => /microphone|built-in/i.test(d.name) && !/teams|blackhole|loopback/i.test(d.name)) ?? devices[0];
|
|
15594
15989
|
if (!mic) throw new Error("no audio input device found");
|
|
15595
|
-
|
|
15990
|
+
log35.debug(`ffmpeg mic: [${mic.idx}] ${mic.name}`);
|
|
15596
15991
|
return `:${mic.idx}`;
|
|
15597
15992
|
}
|
|
15598
15993
|
function detectDshowMic() {
|
|
@@ -15603,7 +15998,7 @@ function detectDshowMic() {
|
|
|
15603
15998
|
const devices = [...(r.stderr ?? "").matchAll(/"([^"]+)"\s*\(audio\)/g)].map((m) => m[1]);
|
|
15604
15999
|
const mic = devices.find((d) => !/stereo mix|loopback|virtual|cable|teams/i.test(d)) ?? devices[0];
|
|
15605
16000
|
if (!mic) throw new Error("no audio input device found (set MIC_DEVICE to the DirectShow device name)");
|
|
15606
|
-
|
|
16001
|
+
log35.debug(`ffmpeg dshow mic: ${mic}`);
|
|
15607
16002
|
return `audio=${mic}`;
|
|
15608
16003
|
}
|
|
15609
16004
|
function detectedInputDevice() {
|
|
@@ -15639,15 +16034,15 @@ function resolveAecBinary() {
|
|
|
15639
16034
|
if (existsSync4(bin) && statSync6(bin).mtimeMs >= statSync6(src).mtimeMs) return bin;
|
|
15640
16035
|
if (spawnSync3("which", ["swiftc"]).status !== 0) return null;
|
|
15641
16036
|
mkdirSync5(cacheDir, { recursive: true });
|
|
15642
|
-
|
|
16037
|
+
log35.info("compiling AEC mic helper (first run)\u2026");
|
|
15643
16038
|
const build = spawnSync3("swiftc", ["-O", "-o", bin, src, "-Xlinker", "-sectcreate", "-Xlinker", "__TEXT", "-Xlinker", "__info_plist", "-Xlinker", plist], { encoding: "utf8" });
|
|
15644
16039
|
if (build.status !== 0) {
|
|
15645
|
-
|
|
16040
|
+
log35.warn(`AEC build failed: ${build.stderr?.slice(0, 400)}`);
|
|
15646
16041
|
return null;
|
|
15647
16042
|
}
|
|
15648
16043
|
const sign = spawnSync3("codesign", ["-fs", "-", bin], { encoding: "utf8" });
|
|
15649
16044
|
if (sign.status !== 0) {
|
|
15650
|
-
|
|
16045
|
+
log35.warn(`codesign failed: ${sign.stderr?.slice(0, 200)}`);
|
|
15651
16046
|
return null;
|
|
15652
16047
|
}
|
|
15653
16048
|
return bin;
|
|
@@ -15689,17 +16084,17 @@ var NodeMicSource = class {
|
|
|
15689
16084
|
this.proc = spawn2(this.bin, [], { stdio: ["ignore", "pipe", "ignore"] });
|
|
15690
16085
|
} else {
|
|
15691
16086
|
if (!hasCommand("ffmpeg")) throw new Error("voice I/O unavailable: no AEC helper and no ffmpeg on PATH");
|
|
15692
|
-
|
|
16087
|
+
log35.info("mic: raw capture (no AEC) \u2014 echo handled heuristically; headphones recommended");
|
|
15693
16088
|
const input = process.platform === "win32" ? ["-f", "dshow", "-i", detectDshowMic()] : ["-f", "avfoundation", "-i", detectFfmpegMic()];
|
|
15694
16089
|
this.proc = spawn2(
|
|
15695
16090
|
"ffmpeg",
|
|
15696
16091
|
["-loglevel", "error", ...input, "-ar", String(STT_SAMPLE_RATE), "-ac", "1", "-f", "s16le", "-"],
|
|
15697
16092
|
{ stdio: ["ignore", "pipe", "pipe"], ...process.platform === "win32" ? { windowsHide: true } : {} }
|
|
15698
16093
|
);
|
|
15699
|
-
this.proc.stderr.on("data", (d) =>
|
|
16094
|
+
this.proc.stderr.on("data", (d) => log35.warn(`ffmpeg: ${String(d).trim()}`));
|
|
15700
16095
|
}
|
|
15701
16096
|
this.proc.on("exit", (c) => {
|
|
15702
|
-
if (c && !this.stopped)
|
|
16097
|
+
if (c && !this.stopped) log35.error(`mic capture exited (${c}) \u2014 check mic permission / MIC_DEVICE / MIC_AEC=0`);
|
|
15703
16098
|
});
|
|
15704
16099
|
this.proc.stdout.on("data", (chunk) => onChunk(chunk));
|
|
15705
16100
|
}
|
|
@@ -15765,7 +16160,7 @@ var AecDuplexAudio = class {
|
|
|
15765
16160
|
this.proc.stdin.on("error", () => {
|
|
15766
16161
|
});
|
|
15767
16162
|
this.proc.on("exit", (c) => {
|
|
15768
|
-
if (c && !this.stopped)
|
|
16163
|
+
if (c && !this.stopped) log35.error(`aec duplex audio exited (${c}) \u2014 check mic permission / MIC_AEC=0`);
|
|
15769
16164
|
});
|
|
15770
16165
|
this.proc.stdout.on("data", (chunk) => {
|
|
15771
16166
|
this.gotChunk = true;
|
|
@@ -15781,7 +16176,7 @@ var AecDuplexAudio = class {
|
|
|
15781
16176
|
openMicSettings();
|
|
15782
16177
|
this.onFatal?.("microphone permission denied \u2014 enable it in System Settings \u2192 Privacy & Security \u2192 Microphone for your terminal, then restart it");
|
|
15783
16178
|
}
|
|
15784
|
-
} else
|
|
16179
|
+
} else log35.debug(`mic-aec: ${s}`);
|
|
15785
16180
|
}
|
|
15786
16181
|
});
|
|
15787
16182
|
if (!this.noVpio && !this.triedFallback) {
|
|
@@ -15790,7 +16185,7 @@ var AecDuplexAudio = class {
|
|
|
15790
16185
|
this.triedFallback = true;
|
|
15791
16186
|
this.noVpio = true;
|
|
15792
16187
|
this._aec = false;
|
|
15793
|
-
|
|
16188
|
+
log35.warn("mic-aec: VPIO delivered no audio in 2.5s \u2014 falling back to non-VPIO capture (no AEC \u2192 half-duplex, no barge-in)");
|
|
15794
16189
|
this.onDegrade?.();
|
|
15795
16190
|
this.killProc();
|
|
15796
16191
|
this.spawnHelper();
|
|
@@ -15961,7 +16356,7 @@ function bindAckInstinct(v, instinct) {
|
|
|
15961
16356
|
if (ev.kind === "ack_fired") instinct.ackOutcome(String(ev.phrase));
|
|
15962
16357
|
else if (ev.kind === "ack_skipped" || ev.kind === "ack_cancelled") instinct.ackOutcome(null);
|
|
15963
16358
|
} catch (e) {
|
|
15964
|
-
|
|
16359
|
+
log35.warn(`ack outcome tap failed: ${e instanceof Error ? e.message : e}`);
|
|
15965
16360
|
}
|
|
15966
16361
|
onDiag(ev);
|
|
15967
16362
|
};
|
|
@@ -16083,7 +16478,7 @@ function speakBlip(v, text) {
|
|
|
16083
16478
|
v.fireBackchannel();
|
|
16084
16479
|
return true;
|
|
16085
16480
|
} catch (e) {
|
|
16086
|
-
|
|
16481
|
+
log35.warn(`backchannel blip failed \u2014 line dropped: ${e.message}`);
|
|
16087
16482
|
return false;
|
|
16088
16483
|
} finally {
|
|
16089
16484
|
E.BACKCHANNELS = pool;
|
|
@@ -16102,7 +16497,7 @@ function channelInput(sc, m) {
|
|
|
16102
16497
|
}
|
|
16103
16498
|
if (m.type === "agent_state") {
|
|
16104
16499
|
if (typeof m.state === "string" && MAIN_STATES.has(m.state)) sc.onAgentState(m.state);
|
|
16105
|
-
else
|
|
16500
|
+
else log35.warn(`agent_state: unknown state ${JSON.stringify(m.state)} \u2014 ignored`);
|
|
16106
16501
|
return true;
|
|
16107
16502
|
}
|
|
16108
16503
|
return false;
|
|
@@ -16228,7 +16623,7 @@ function fakeVoiceParts(uttFile) {
|
|
|
16228
16623
|
init_logging();
|
|
16229
16624
|
import { appendFile, mkdirSync as mkdirSync6 } from "fs";
|
|
16230
16625
|
import { dirname as dirname5 } from "path";
|
|
16231
|
-
var
|
|
16626
|
+
var log36 = forComponent("VoiceDiag");
|
|
16232
16627
|
var JsonlDiagSink = class {
|
|
16233
16628
|
constructor(path) {
|
|
16234
16629
|
this.path = path;
|
|
@@ -16269,7 +16664,7 @@ var JsonlDiagSink = class {
|
|
|
16269
16664
|
disable(e) {
|
|
16270
16665
|
this.disabled = true;
|
|
16271
16666
|
this.queue.length = 0;
|
|
16272
|
-
|
|
16667
|
+
log36.debug(`voice diag sink disabled (${this.path}): ${e instanceof Error ? e.message : e}`);
|
|
16273
16668
|
}
|
|
16274
16669
|
/** True once a failure permanently disabled the sink (tests/inspection). */
|
|
16275
16670
|
get isDisabled() {
|
|
@@ -16428,7 +16823,7 @@ function applyOverlay(cfg, file) {
|
|
|
16428
16823
|
// cli/hooks-config.ts
|
|
16429
16824
|
import { spawnSync as spawnSync4 } from "child_process";
|
|
16430
16825
|
init_platform();
|
|
16431
|
-
var
|
|
16826
|
+
var log37 = forComponent("hooks");
|
|
16432
16827
|
var escapeRegex = (s) => s.replace(/[.+^${}()|[\]\\]/g, "\\$&");
|
|
16433
16828
|
function ruleMatches(rule, toolName) {
|
|
16434
16829
|
if (!rule.tool || rule.tool === "*") return true;
|
|
@@ -16447,7 +16842,7 @@ function runCmd(rule, env) {
|
|
|
16447
16842
|
});
|
|
16448
16843
|
return { code: r.status ?? 1, out: ((r.stdout ?? "") + (r.stderr ?? "")).trim() };
|
|
16449
16844
|
} catch (e) {
|
|
16450
|
-
|
|
16845
|
+
log37.debug(`hook command failed: ${rule.command}`, e);
|
|
16451
16846
|
return { code: 1, out: String(e?.message ?? e) };
|
|
16452
16847
|
}
|
|
16453
16848
|
}
|
|
@@ -16555,7 +16950,7 @@ import { existsSync as existsSync6, mkdirSync as mkdirSync8, readFileSync as rea
|
|
|
16555
16950
|
import { homedir as homedir6 } from "os";
|
|
16556
16951
|
import { join as join11 } from "path";
|
|
16557
16952
|
init_platform();
|
|
16558
|
-
var
|
|
16953
|
+
var log38 = forComponent("session");
|
|
16559
16954
|
var globalDir = () => join11(homedir6(), ".agent", "sessions");
|
|
16560
16955
|
function indexLink(target, link2) {
|
|
16561
16956
|
try {
|
|
@@ -16618,7 +17013,7 @@ var SessionStore = class {
|
|
|
16618
17013
|
}
|
|
16619
17014
|
load(id) {
|
|
16620
17015
|
if (!this.safeId(id)) {
|
|
16621
|
-
|
|
17016
|
+
log38.debug(`rejecting unsafe session id: ${id}`);
|
|
16622
17017
|
return void 0;
|
|
16623
17018
|
}
|
|
16624
17019
|
const path = join11(this.dir, `${id}.json`);
|
|
@@ -16626,7 +17021,7 @@ var SessionStore = class {
|
|
|
16626
17021
|
try {
|
|
16627
17022
|
return JSON.parse(readFileSync8(path, "utf8"));
|
|
16628
17023
|
} catch (e) {
|
|
16629
|
-
|
|
17024
|
+
log38.debug(`unreadable session ${id} \u2014 ignoring`, e);
|
|
16630
17025
|
return void 0;
|
|
16631
17026
|
}
|
|
16632
17027
|
}
|
|
@@ -16639,7 +17034,7 @@ var SessionStore = class {
|
|
|
16639
17034
|
try {
|
|
16640
17035
|
metas.push(JSON.parse(readFileSync8(join11(this.dir, f), "utf8")).meta);
|
|
16641
17036
|
} catch (e) {
|
|
16642
|
-
|
|
17037
|
+
log38.debug(`skipping unreadable session file ${f}`, e);
|
|
16643
17038
|
}
|
|
16644
17039
|
}
|
|
16645
17040
|
return metas.sort((a, b) => b.updated - a.updated);
|
|
@@ -17071,7 +17466,7 @@ import { promisify } from "util";
|
|
|
17071
17466
|
import { writeFileSync as writeFileSync6, mkdirSync as mkdirSync9 } from "fs";
|
|
17072
17467
|
import { homedir as homedir7 } from "os";
|
|
17073
17468
|
import { join as join12, resolve as resolve4, sep as sep3, parse as parsePath } from "path";
|
|
17074
|
-
var
|
|
17469
|
+
var log39 = forComponent("checkpoints");
|
|
17075
17470
|
var exec = promisify(execFile4);
|
|
17076
17471
|
var DEFAULT_EXCLUDE = [".agent/", ".git/", "node_modules/", "dist/", "build/", ".next/", "target/", ".venv/", "__pycache__/", "*.log"];
|
|
17077
17472
|
function isBroadRoot(p) {
|
|
@@ -17119,7 +17514,7 @@ var ShadowRepo = class {
|
|
|
17119
17514
|
writeFileSync6(join12(this.gitDir, "info", "exclude"), this.exclude.join("\n") + "\n");
|
|
17120
17515
|
this.ready = true;
|
|
17121
17516
|
} catch (e) {
|
|
17122
|
-
|
|
17517
|
+
log39.debug(`git checkpoints unavailable for ${this.workTree}`, e);
|
|
17123
17518
|
this.ready = false;
|
|
17124
17519
|
}
|
|
17125
17520
|
return this.ready;
|
|
@@ -17130,7 +17525,7 @@ var ShadowRepo = class {
|
|
|
17130
17525
|
}
|
|
17131
17526
|
async commit(label, forced = []) {
|
|
17132
17527
|
await this.run("add", "-A");
|
|
17133
|
-
for (const p of forced) await this.run("add", "-f", "--", p).catch((e) =>
|
|
17528
|
+
for (const p of forced) await this.run("add", "-f", "--", p).catch((e) => log39.debug(`force-add failed: ${p}`, e));
|
|
17134
17529
|
await this.run("commit", "--allow-empty", "-q", "-m", label);
|
|
17135
17530
|
}
|
|
17136
17531
|
/** Inject the CURRENT (pre-edit) content of `paths` into the turn-open restore point by amending it.
|
|
@@ -17138,8 +17533,8 @@ var ShadowRepo = class {
|
|
|
17138
17533
|
* turn-boundary `add -A` would never have captured it. Amend (vs a new commit) keeps one restore
|
|
17139
17534
|
* point per turn, so the REPL's turn↔frame mapping stays intact. */
|
|
17140
17535
|
async amendForced(paths) {
|
|
17141
|
-
for (const p of paths) await this.run("add", "-f", "--", p).catch((e) =>
|
|
17142
|
-
await this.run("commit", "--amend", "--no-edit", "-q", "--allow-empty").catch((e) =>
|
|
17536
|
+
for (const p of paths) await this.run("add", "-f", "--", p).catch((e) => log39.debug(`force-capture failed: ${p}`, e));
|
|
17537
|
+
await this.run("commit", "--amend", "--no-edit", "-q", "--allow-empty").catch((e) => log39.debug("amend failed", e));
|
|
17143
17538
|
}
|
|
17144
17539
|
/** Commits on `ref`, oldest-first (canonical index space). */
|
|
17145
17540
|
async log(ref) {
|
|
@@ -17199,7 +17594,7 @@ var ShadowRepo = class {
|
|
|
17199
17594
|
await this.run("gc", "--auto", "-q").catch(() => {
|
|
17200
17595
|
});
|
|
17201
17596
|
} catch (e) {
|
|
17202
|
-
|
|
17597
|
+
log39.debug("checkpoint prune failed", e);
|
|
17203
17598
|
}
|
|
17204
17599
|
}
|
|
17205
17600
|
};
|
|
@@ -17267,7 +17662,7 @@ var GitCheckpoints = class {
|
|
|
17267
17662
|
use(sessionId) {
|
|
17268
17663
|
if (sessionId === this.session) return;
|
|
17269
17664
|
this.session = sessionId;
|
|
17270
|
-
if (this.started) for (const r of this.repos) void r.point(this.ref()).catch((e) =>
|
|
17665
|
+
if (this.started) for (const r of this.repos) void r.point(this.ref()).catch((e) => log39.debug("re-point failed", e));
|
|
17271
17666
|
}
|
|
17272
17667
|
async begin(label) {
|
|
17273
17668
|
if (!await this.start()) return;
|
|
@@ -17287,7 +17682,7 @@ var GitCheckpoints = class {
|
|
|
17287
17682
|
process.stderr.write(`\x1B[2m checkpoints: '${this.repos[i].root}' too large to snapshot in ${Math.round(this.options.opTimeoutMs / 1e3)}s \u2014 file rewind disabled here\x1B[0m
|
|
17288
17683
|
`);
|
|
17289
17684
|
} else {
|
|
17290
|
-
|
|
17685
|
+
log39.debug("checkpoint commit failed", e);
|
|
17291
17686
|
survivors.push(this.repos[i]);
|
|
17292
17687
|
survivorCaches.push(this.caches[i] ?? []);
|
|
17293
17688
|
}
|
|
@@ -17322,7 +17717,7 @@ var GitCheckpoints = class {
|
|
|
17322
17717
|
if (this.forced.has(abs)) continue;
|
|
17323
17718
|
this.forced.add(abs);
|
|
17324
17719
|
const i = this.repoIndexFor(abs);
|
|
17325
|
-
if (i >= 0) await this.repos[i].amendForced([abs]).catch((e) =>
|
|
17720
|
+
if (i >= 0) await this.repos[i].amendForced([abs]).catch((e) => log39.debug("amendForced failed", e));
|
|
17326
17721
|
}
|
|
17327
17722
|
}
|
|
17328
17723
|
};
|
|
@@ -19112,7 +19507,7 @@ import { spawnSync as spawnSync6 } from "child_process";
|
|
|
19112
19507
|
import { writeFileSync as writeFileSync8, mkdirSync as mkdirSync10, readdirSync as readdirSync2, unlinkSync as unlinkSync3, chmodSync, existsSync as existsSync7 } from "fs";
|
|
19113
19508
|
import { homedir as homedir8 } from "os";
|
|
19114
19509
|
import { join as join14 } from "path";
|
|
19115
|
-
var
|
|
19510
|
+
var log40 = forComponent("os-sched");
|
|
19116
19511
|
var OsScheduler = class {
|
|
19117
19512
|
options;
|
|
19118
19513
|
constructor(options) {
|
|
@@ -19174,7 +19569,7 @@ var OsScheduler = class {
|
|
|
19174
19569
|
}
|
|
19175
19570
|
}
|
|
19176
19571
|
} catch (e) {
|
|
19177
|
-
|
|
19572
|
+
log40.debug(`cancel ${id}`, e);
|
|
19178
19573
|
}
|
|
19179
19574
|
for (const f of [`${id}.json`, `${id}.sh`]) {
|
|
19180
19575
|
try {
|
|
@@ -19292,7 +19687,7 @@ import { existsSync as existsSync8, mkdirSync as mkdirSync11, unlinkSync as unli
|
|
|
19292
19687
|
import { homedir as homedir9 } from "os";
|
|
19293
19688
|
import { join as join15 } from "path";
|
|
19294
19689
|
init_platform();
|
|
19295
|
-
var
|
|
19690
|
+
var log41 = forComponent("remote-trigger");
|
|
19296
19691
|
var TRIGGER_DIR = () => join15(homedir9(), ".agent", "triggers");
|
|
19297
19692
|
var sockPath = (sessionId, dir = TRIGGER_DIR()) => join15(dir, `${sessionId}.sock`);
|
|
19298
19693
|
var TriggerServer = class {
|
|
@@ -19330,13 +19725,13 @@ var TriggerServer = class {
|
|
|
19330
19725
|
conn.end(JSON.stringify({ ok: false, error: String(e) }) + "\n");
|
|
19331
19726
|
}
|
|
19332
19727
|
});
|
|
19333
|
-
conn.on("error", (e) =>
|
|
19728
|
+
conn.on("error", (e) => log41.debug("trigger conn error", e));
|
|
19334
19729
|
});
|
|
19335
|
-
this.server.on("error", (e) =>
|
|
19730
|
+
this.server.on("error", (e) => log41.debug("trigger server error", e));
|
|
19336
19731
|
this.server.listen(p);
|
|
19337
19732
|
this.path = p;
|
|
19338
19733
|
} catch (e) {
|
|
19339
|
-
|
|
19734
|
+
log41.debug("trigger server unavailable", e);
|
|
19340
19735
|
}
|
|
19341
19736
|
}
|
|
19342
19737
|
/** Re-bind on /resume (the session id changed). */
|
|
@@ -19468,7 +19863,7 @@ var strike = C("9");
|
|
|
19468
19863
|
var link = (text, url) => useColor ? `\x1B]8;;${url}\x1B\\${cyan(text)}\x1B]8;;\x1B\\` : `${text} (${url})`;
|
|
19469
19864
|
var mdPalette = { bold, dim, cyan, italic, strike, green, link };
|
|
19470
19865
|
var err = (s) => process.stderr.write(s);
|
|
19471
|
-
var
|
|
19866
|
+
var log42 = forComponent("cli");
|
|
19472
19867
|
var VERSION = (() => {
|
|
19473
19868
|
try {
|
|
19474
19869
|
return JSON.parse(readFileSync10(new URL("../package.json", import.meta.url), "utf8")).version ?? "?";
|
|
@@ -19640,6 +20035,7 @@ function parseArgs(argv) {
|
|
|
19640
20035
|
else if (x === "--disallowedTools" || x === "--disallowed-tools") a.disallowedTools = val(++i, x).split(",").map((s) => s.trim()).filter(Boolean);
|
|
19641
20036
|
else if (x === "--append-system-prompt") a.appendSystemPrompt = val(++i, x);
|
|
19642
20037
|
else if (x === "--voice-system-prompt") a.voiceSystemPrompt = val(++i, x);
|
|
20038
|
+
else if (x === "--voice-persona") a.voicePersona = readPersona(val(++i, x));
|
|
19643
20039
|
else if (x === "--add-dir") (a.addDirs ??= []).push(val(++i, x));
|
|
19644
20040
|
else if (x === "--mcp-config") a.mcpConfig = val(++i, x);
|
|
19645
20041
|
else if (x === "--reasoning") a.reasoning = parseReasoning(val(++i, x));
|
|
@@ -19675,6 +20071,8 @@ function parseArgs(argv) {
|
|
|
19675
20071
|
if (a.channelOnly && !a.inputFormat) throw new Error("--channel-only needs --input-format stream-json --output-format stream-json");
|
|
19676
20072
|
if (a.duplex && a.plan) throw new Error("--plan is not supported in --duplex (workers are non-interactive; a plan could never be approved)");
|
|
19677
20073
|
if (a.voiceSystemPrompt && !a.duplex) throw new Error("--voice-system-prompt only applies with --duplex");
|
|
20074
|
+
if (a.voicePersona && !a.duplex && !a.channelOnly) throw new Error("--voice-persona only applies with --call or --channel-only");
|
|
20075
|
+
if (a.voicePersona) process.env.AGENTX_CALL_PERSONA = a.voicePersona;
|
|
19678
20076
|
if (a.call && a.inputFormat) throw new Error("--call is interactive (mic/TTS here); a headless host runs --channel-only");
|
|
19679
20077
|
if (a.channelMode && !a.duplexV2 && !a.channelOnly && !a.call) throw new Error("--channel-mode only applies with --duplex-v2 or --channel-only");
|
|
19680
20078
|
a.channelMode ??= parseChannelMode(process.env.AGENTX_CHANNEL_MODE);
|
|
@@ -19736,6 +20134,8 @@ Flags:
|
|
|
19736
20134
|
enter the agent's history (headless: stdin interim/pause/agent_state, stdout channel)
|
|
19737
20135
|
--channel-only headless (--input-format stream-json): ONLY the second channel, for a host whose main
|
|
19738
20136
|
answer comes from elsewhere (stdin user/text/barge/interim/pause/agent_state, stdout channel)
|
|
20137
|
+
--voice-persona <f> call persona from a file: replaces the default call style in MAIN's prompt and tells the live
|
|
20138
|
+
prediction tree who is speaking (--call / --channel-only; as Para's Settings > Call persona)
|
|
19739
20139
|
--channel-mode <m> second-channel talkativeness: turn (only a bridge when the answer is slow) | normal
|
|
19740
20140
|
(default) | chatty (frequent cues + content reactions; needs echo cancellation)
|
|
19741
20141
|
env fallback: AGENTX_CHANNEL_MODE
|
|
@@ -20365,7 +20765,7 @@ function turnCost(model, usage) {
|
|
|
20365
20765
|
const priced = model.startsWith("claude-code/") ? `anthropic/${resolveModelAlias(model.slice("claude-code/".length))}` : model;
|
|
20366
20766
|
return costOf(getModelInfo(priced)?.pricing, usage?.promptTokens ?? 0, usage?.completionTokens ?? 0, usage?.cacheCreationTokens ?? 0, usage?.cacheReadTokens ?? 0, priced);
|
|
20367
20767
|
}
|
|
20368
|
-
async function evaluateGoal(ai, condition, transcript,
|
|
20768
|
+
async function evaluateGoal(ai, condition, transcript, log43) {
|
|
20369
20769
|
const recent = transcript.filter((m) => m.role === "assistant").slice(-8).map((m) => {
|
|
20370
20770
|
const text = typeof m.content === "string" ? m.content : m.content.filter((p) => p.type === "text").map((p) => p.text).join(" ");
|
|
20371
20771
|
return text.slice(0, 600);
|
|
@@ -20385,7 +20785,7 @@ ${recent}` }
|
|
|
20385
20785
|
const match = r.content.match(/\{[\s\S]*\}/);
|
|
20386
20786
|
if (match) return JSON.parse(match[0]);
|
|
20387
20787
|
} catch (e) {
|
|
20388
|
-
|
|
20788
|
+
log43(dim(` (goal evaluator error: ${e?.message ?? e})
|
|
20389
20789
|
`));
|
|
20390
20790
|
}
|
|
20391
20791
|
return { met: false, reason: "evaluation unclear" };
|
|
@@ -20613,7 +21013,7 @@ function mcpAgentTools(mounted, opts) {
|
|
|
20613
21013
|
return tools;
|
|
20614
21014
|
}
|
|
20615
21015
|
async function closeMcp(mounted) {
|
|
20616
|
-
await Promise.all(mounted.map((m) => m.client.close().catch((e) =>
|
|
21016
|
+
await Promise.all(mounted.map((m) => m.client.close().catch((e) => log42.debug("mcp close failed", e))));
|
|
20617
21017
|
}
|
|
20618
21018
|
var IMG_EXT = { ".png": "image/png", ".jpg": "image/jpeg", ".jpeg": "image/jpeg", ".gif": "image/gif", ".webp": "image/webp" };
|
|
20619
21019
|
function mentionRefs(line) {
|
|
@@ -20672,7 +21072,7 @@ async function expandMentions(fs, line) {
|
|
|
20672
21072
|
if (loaded.includes(ref) || missing.includes(ref)) continue;
|
|
20673
21073
|
if (ref.includes(":") && mcpMentionResolver) {
|
|
20674
21074
|
const body = await mcpMentionResolver(ref).catch((e) => {
|
|
20675
|
-
|
|
21075
|
+
log42.debug("mcp mention resolve failed", e);
|
|
20676
21076
|
return null;
|
|
20677
21077
|
});
|
|
20678
21078
|
if (body != null) {
|
|
@@ -20698,7 +21098,7 @@ ${await fs.readFile(path)}`);
|
|
|
20698
21098
|
${blocks.join("\n\n")}` : line, loaded, missing };
|
|
20699
21099
|
}
|
|
20700
21100
|
function applyTurnMode(agent, session, task, flags = {}, onModel) {
|
|
20701
|
-
const p = parseDirectives(task, { strict: true, keys: ["model", "turns", "delegate", "advisor", "mode"], warn: (m) =>
|
|
21101
|
+
const p = parseDirectives(task, { strict: true, keys: ["model", "turns", "delegate", "advisor", "mode"], warn: (m) => log42.debug(m) });
|
|
20702
21102
|
const d = p.directives, isMode = !!(d.delegate || d.advisor || d.modeOff);
|
|
20703
21103
|
if (p.unresolvedModel && /->|<-|delegate:|advisor:/.test(task.slice(0, task.length - p.prompt.length))) {
|
|
20704
21104
|
err(red(` \u2717 unknown model "${p.unresolvedModel}"${p.ambiguous ? ` (could be: ${p.ambiguous.join(", ")})` : ""} \u2014 turn not sent
|
|
@@ -20791,7 +21191,7 @@ async function runTurn(agent, store, session, task, cp, cwd = process.cwd(), sen
|
|
|
20791
21191
|
try {
|
|
20792
21192
|
store.save(session);
|
|
20793
21193
|
} catch (ex) {
|
|
20794
|
-
|
|
21194
|
+
log42.debug("mid-turn session flush failed", ex);
|
|
20795
21195
|
}
|
|
20796
21196
|
}
|
|
20797
21197
|
return origNotify(e);
|
|
@@ -20955,14 +21355,14 @@ var isCancelTeardown = (e) => {
|
|
|
20955
21355
|
function installCancelGuards(mounted) {
|
|
20956
21356
|
process.on("unhandledRejection", (e) => {
|
|
20957
21357
|
if (isCancelTeardown(e)) {
|
|
20958
|
-
|
|
21358
|
+
log42.debug("suppressed unhandledRejection (cursor stream cancel)", e);
|
|
20959
21359
|
return;
|
|
20960
21360
|
}
|
|
20961
|
-
|
|
21361
|
+
log42.error("unhandledRejection", e);
|
|
20962
21362
|
});
|
|
20963
21363
|
process.on("uncaughtException", (e) => {
|
|
20964
21364
|
if (isCancelTeardown(e)) {
|
|
20965
|
-
|
|
21365
|
+
log42.debug("suppressed uncaughtException (cursor stream cancel)", e);
|
|
20966
21366
|
return;
|
|
20967
21367
|
}
|
|
20968
21368
|
console.error(e);
|
|
@@ -21289,7 +21689,7 @@ async function repl(args, ai, cfg, cwd) {
|
|
|
21289
21689
|
let callChain = Promise.resolve();
|
|
21290
21690
|
const callTurns = /* @__PURE__ */ new Map();
|
|
21291
21691
|
if (args.call) {
|
|
21292
|
-
if (args.voice) agent.options.systemPrompt += "\n\n" + CALL_PROMPT;
|
|
21692
|
+
if (args.voice || args.voicePersona) agent.options.systemPrompt += "\n\n" + (args.voicePersona ?? CALL_PROMPT);
|
|
21293
21693
|
if (args.voiceSystemPrompt) agent.options.systemPrompt += "\n\n" + args.voiceSystemPrompt;
|
|
21294
21694
|
call = new VoiceCall({
|
|
21295
21695
|
ai,
|
|
@@ -21331,7 +21731,7 @@ async function repl(args, ai, cfg, cwd) {
|
|
|
21331
21731
|
editorRef?.abort();
|
|
21332
21732
|
}
|
|
21333
21733
|
} catch (e) {
|
|
21334
|
-
|
|
21734
|
+
log42.error("call turn failed", e);
|
|
21335
21735
|
} finally {
|
|
21336
21736
|
rec.running = false;
|
|
21337
21737
|
call?.main({ type: "done", id });
|
|
@@ -21463,7 +21863,7 @@ async function repl(args, ai, cfg, cwd) {
|
|
|
21463
21863
|
try {
|
|
21464
21864
|
mkdirSync12(dir, { recursive: true });
|
|
21465
21865
|
} catch (e) {
|
|
21466
|
-
|
|
21866
|
+
log42.debug("paste image dir create failed", e);
|
|
21467
21867
|
}
|
|
21468
21868
|
const img = grabClipboardImage(dir, String(Date.now()));
|
|
21469
21869
|
return img ? { display: "Image", ref: "@" + img.path, path: img.path } : null;
|
|
@@ -21576,7 +21976,7 @@ Added entries are loadable now via the Skill/SlashCommand tools; removed ones ar
|
|
|
21576
21976
|
mkdirSync12(join16(cwd, ".agent"), { recursive: true });
|
|
21577
21977
|
appendFileSync(histPath, line + "\n");
|
|
21578
21978
|
} catch (e) {
|
|
21579
|
-
|
|
21979
|
+
log42.debug("history write failed", e);
|
|
21580
21980
|
}
|
|
21581
21981
|
};
|
|
21582
21982
|
const ago = (t) => {
|
|
@@ -21648,7 +22048,7 @@ Added entries are loadable now via the Skill/SlashCommand tools; removed ones ar
|
|
|
21648
22048
|
try {
|
|
21649
22049
|
store.save(session);
|
|
21650
22050
|
} catch (e) {
|
|
21651
|
-
|
|
22051
|
+
log42.debug("session save after rewind failed", e);
|
|
21652
22052
|
}
|
|
21653
22053
|
err(green(" \u27F2 jumped back") + dim(` \u2014 ${face.transcript.length} message(s) kept; edit + resend
|
|
21654
22054
|
`));
|
|
@@ -21683,7 +22083,7 @@ ${task}`;
|
|
|
21683
22083
|
bangContext.length = 0;
|
|
21684
22084
|
}
|
|
21685
22085
|
const delta = await refreshCatalogs().catch((e) => {
|
|
21686
|
-
|
|
22086
|
+
log42.debug("catalog refresh failed", e);
|
|
21687
22087
|
return "";
|
|
21688
22088
|
});
|
|
21689
22089
|
if (delta) {
|
|
@@ -21953,7 +22353,7 @@ ${task}`;
|
|
|
21953
22353
|
desc: "rescan skills/commands dirs and rebuild the system prompt (one cache miss) \u2014 picks up entries created mid-session",
|
|
21954
22354
|
run: async () => {
|
|
21955
22355
|
await refreshCatalogs().catch((e) => {
|
|
21956
|
-
|
|
22356
|
+
log42.debug("catalog refresh failed", e);
|
|
21957
22357
|
});
|
|
21958
22358
|
face.reprepare();
|
|
21959
22359
|
err(green(` \u2713 reloaded \u2014 ${skills.length} skill(s), ${cmds.length} command(s); system prompt rebuilds on next message
|
|
@@ -22456,7 +22856,7 @@ ${task}`;
|
|
|
22456
22856
|
try {
|
|
22457
22857
|
for (const def of (await loadAgents(fs2, d)).agents) if (!seen.has(def.name)) seen.set(def.name, { def, from: d });
|
|
22458
22858
|
} catch (e) {
|
|
22459
|
-
|
|
22859
|
+
log42.debug(`loadAgents(${d}) failed`, e);
|
|
22460
22860
|
}
|
|
22461
22861
|
}
|
|
22462
22862
|
if (!seen.size) {
|
|
@@ -22544,7 +22944,7 @@ ${task}`;
|
|
|
22544
22944
|
}
|
|
22545
22945
|
if (idx >= 0) {
|
|
22546
22946
|
const old = mounted.splice(idx, 1)[0];
|
|
22547
|
-
await old.client.close().catch((e) =>
|
|
22947
|
+
await old.client.close().catch((e) => log42.debug("mcp close failed", e));
|
|
22548
22948
|
}
|
|
22549
22949
|
try {
|
|
22550
22950
|
const m = await mountMcpServer(name, conf);
|
|
@@ -22572,7 +22972,7 @@ ${task}`;
|
|
|
22572
22972
|
}
|
|
22573
22973
|
const m = mounted.splice(idx, 1)[0];
|
|
22574
22974
|
remountMcpTools();
|
|
22575
|
-
await m.client.close().catch((e) =>
|
|
22975
|
+
await m.client.close().catch((e) => log42.debug("mcp close failed", e));
|
|
22576
22976
|
err(dim(` removed "${name}"
|
|
22577
22977
|
`));
|
|
22578
22978
|
return;
|
|
@@ -22775,7 +23175,7 @@ ${task}`;
|
|
|
22775
23175
|
try {
|
|
22776
23176
|
return readdirSync4(join16(cwd, absDir.replace(/^\/+/, "")), { withFileTypes: true }).map((d) => ({ name: d.name, dir: d.isDirectory() }));
|
|
22777
23177
|
} catch (e) {
|
|
22778
|
-
|
|
23178
|
+
log42.debug("completion readdir failed", absDir, e);
|
|
22779
23179
|
return null;
|
|
22780
23180
|
}
|
|
22781
23181
|
};
|
|
@@ -22914,7 +23314,7 @@ ${out}
|
|
|
22914
23314
|
return;
|
|
22915
23315
|
}
|
|
22916
23316
|
await refreshCatalogs().catch((e) => {
|
|
22917
|
-
|
|
23317
|
+
log42.debug("catalog refresh failed", e);
|
|
22918
23318
|
});
|
|
22919
23319
|
const sk = skills.find((x) => x.name === name);
|
|
22920
23320
|
if (sk) {
|
|
@@ -22951,6 +23351,11 @@ ${out}
|
|
|
22951
23351
|
let partialRedraw = null;
|
|
22952
23352
|
const startVoice = async (greet) => {
|
|
22953
23353
|
if (voiceIO) return true;
|
|
23354
|
+
if (greet && call) {
|
|
23355
|
+
bindClaudeCodeSession(agent, session);
|
|
23356
|
+
await agent.prewarm().catch((e) => err(dim(` (prewarm failed: ${e?.message ?? e})
|
|
23357
|
+
`)));
|
|
23358
|
+
}
|
|
22954
23359
|
if (!(duplex || call) || !process.stdin.isTTY) {
|
|
22955
23360
|
err(dim(" (voice needs --call on a TTY)\n"));
|
|
22956
23361
|
return false;
|
|
@@ -23039,7 +23444,7 @@ ${out}
|
|
|
23039
23444
|
if (delivery || cut) dx?.parkCutDelivery(delivery, !!cut, heard);
|
|
23040
23445
|
const cutReply = cut && cut.full.length - cut.heard.length > 40 ? cut : null;
|
|
23041
23446
|
const noteP = replaces ? replaces.note : !cutReply ? Promise.resolve("") : (instinct ? instinct.bargeIntent(text).catch((e) => {
|
|
23042
|
-
|
|
23447
|
+
log42.warn(`barge intent failed \u2014 model decides: ${e.message}`);
|
|
23043
23448
|
return void 0;
|
|
23044
23449
|
}) : Promise.resolve(void 0)).then(async (intent) => interruptionNote(cutReply, intent) + ackedNote(await instinct?.ackFor(text)));
|
|
23045
23450
|
const cutIn = replaces ? replaces.cutIn : interjectNote;
|
|
@@ -23165,7 +23570,7 @@ ${out}
|
|
|
23165
23570
|
if (greet) {
|
|
23166
23571
|
const where = cwd.split("/").pop();
|
|
23167
23572
|
const resumed = session.messages.length > 0;
|
|
23168
|
-
const prompt = resumed ? `[session resumed] You're rejoining a live voice conversation already in progress \u2014 the full history, including the user's memory/preferences, is already in context, so do NOT call QuickLook again. In one short spoken line, welcome the user back and pick the thread up where it left off: if your last turn ended on an open question or offer, continue it naturally rather than asking what they'd like to do.` : `[session started] First call QuickLook with what:"memory" \u2014 if it knows the user's name or preferences, use them. Then greet the user warmly in one or two short sentences, as the opener of a live voice conversation. Context: working directory "${where}". Personalize from whatever you learned (memory). Then ask what they'd like to do.`;
|
|
23573
|
+
const prompt = resumed ? `[session resumed] You're rejoining a live voice conversation already in progress \u2014 the full history, including the user's memory/preferences, is already in context, so do NOT call QuickLook again. In one short spoken line, welcome the user back and pick the thread up where it left off: if your last turn ended on an open question or offer, continue it naturally rather than asking what they'd like to do.` : call ? `[session started] Do not call any tool: answer in this one reply, from what you already know. Greet the user warmly in one short spoken sentence, as the opener of a live voice call, and ask what they'd like to do.` : `[session started] First call QuickLook with what:"memory" \u2014 if it knows the user's name or preferences, use them. Then greet the user warmly in one or two short sentences, as the opener of a live voice conversation. Context: working directory "${where}". Personalize from whatever you learned (memory). Then ask what they'd like to do.`;
|
|
23169
23574
|
void turn(prompt).finally(() => editorRef?.redrawNow());
|
|
23170
23575
|
}
|
|
23171
23576
|
return true;
|
|
@@ -23403,6 +23808,16 @@ function duplexError(e, reflexModel) {
|
|
|
23403
23808
|
const code = e?.statusCode;
|
|
23404
23809
|
return code && !msg.includes(String(code)) ? `${msg} (${code})` : msg;
|
|
23405
23810
|
}
|
|
23811
|
+
function readPersona(file) {
|
|
23812
|
+
let text = "";
|
|
23813
|
+
try {
|
|
23814
|
+
text = readFileSync10(file, "utf8").trim();
|
|
23815
|
+
} catch (e) {
|
|
23816
|
+
throw new Error(`--voice-persona: can't read ${file}: ${e.message}`);
|
|
23817
|
+
}
|
|
23818
|
+
if (!text) throw new Error(`--voice-persona: ${file} is empty`);
|
|
23819
|
+
return text;
|
|
23820
|
+
}
|
|
23406
23821
|
var CALL_PROMPT = `This is a live VOICE call: your text is spoken aloud. Reply in the language of the user's last message. Open with one short sentence (it is spoken while you continue), then keep it brief and conversational \u2014 no markdown, lists, code or URLs read aloud. Short listener sounds ("mm-hm", "let me check\u2026") are played for you while you work; do not repeat or mention them.`;
|
|
23407
23822
|
var HOLD_RESUME_MS = 4e3;
|
|
23408
23823
|
var leakDecider = () => voiceDecider();
|
|
@@ -23413,15 +23828,24 @@ function channelOptions(ai, model, gender) {
|
|
|
23413
23828
|
const decider = leakDecider();
|
|
23414
23829
|
const instinct = decider ? new Instinct({ decider }) : void 0;
|
|
23415
23830
|
const planner = new BackchannelPlanner(ai, { model });
|
|
23831
|
+
const grower = new ConvoTreeGrower(ai, { ...process.env.AGENTX_TREE_MODEL ? { model: process.env.AGENTX_TREE_MODEL } : {} });
|
|
23416
23832
|
return {
|
|
23833
|
+
...process.env.AGENTX_TREE === "0" ? {} : { grow: (c, s) => grower.grow(c, s) },
|
|
23834
|
+
// 0: the reactive live path
|
|
23835
|
+
pickLeaf: fastLeafPicker(ai, process.env.AGENTX_LEAF_MODEL || "groq/openai/gpt-oss-120b"),
|
|
23836
|
+
persona: process.env.AGENTX_CALL_PERSONA ?? "",
|
|
23837
|
+
onTree: (e) => log42.debug(`voice tree: ${e.branches} branches in ${e.ms}ms${e.tokens ? ` tokens ${e.tokens.input}/${e.tokens.output}` : ""}${e.error ? ` error ${e.error}` : ""}`),
|
|
23838
|
+
onEvent: (e) => {
|
|
23839
|
+
if (e.moment) log42.debug(`voice leaf: ${e.moment} ${e.conf} "${e.text}" ${e.acted}`);
|
|
23840
|
+
else log42.debug(`channel ${e.trigger}: rule=${e.rule} choice=${e.choice ?? "-"} \u2192 ${e.acted}${e.text ? ` "${e.text}"` : ""}${e.cue ? " (planned cue)" : ""} ${e.ms}ms`);
|
|
23841
|
+
},
|
|
23417
23842
|
// Banks in the user's language: generated once per language, cached + topped up across sessions (~/.agent/cache).
|
|
23418
23843
|
banks: new ChannelBanks({ generate: fastBankGenerator(ai, model), cacheDir: join16(homedir10(), ".agent", "cache", "channel-banks") }),
|
|
23419
23844
|
decide: channelDecide(ai, instinct),
|
|
23420
23845
|
generate: fastLineGenerator(ai, model, gender),
|
|
23421
23846
|
// Anticipated backchannels: on in chatty mode (its preset), else off until the offline replay proves them (tests/voice-bc-anticipate-eval.ts)
|
|
23422
23847
|
plan: (c, s) => planner.plan(c, s),
|
|
23423
|
-
...process.env.AGENTX_CHANNEL_ANTICIPATE === "1" ? { anticipate: true } : {}
|
|
23424
|
-
onEvent: (e) => log41.debug(`channel ${e.trigger}: rule=${e.rule} choice=${e.choice ?? "-"} \u2192 ${e.acted}${e.text ? ` "${e.text}"` : ""}${e.cue ? " (planned cue)" : ""} ${e.ms}ms`)
|
|
23848
|
+
...process.env.AGENTX_CHANNEL_ANTICIPATE === "1" ? { anticipate: true } : {}
|
|
23425
23849
|
};
|
|
23426
23850
|
}
|
|
23427
23851
|
function overlapResponder(ai, mode, out, aside) {
|
|
@@ -23495,7 +23919,7 @@ async function duplexServe(args, ai, cfg, cwd) {
|
|
|
23495
23919
|
try {
|
|
23496
23920
|
store.save(session);
|
|
23497
23921
|
} catch (e) {
|
|
23498
|
-
|
|
23922
|
+
log42.warn("duplex session save failed", e);
|
|
23499
23923
|
}
|
|
23500
23924
|
};
|
|
23501
23925
|
const overlap2 = overlapResponder(ai, args.duplexV2 ? args.channelMode : void 0, out);
|
|
@@ -23535,7 +23959,7 @@ async function duplexServe(args, ai, cfg, cwd) {
|
|
|
23535
23959
|
done2();
|
|
23536
23960
|
out({ type: "turn_done", id, finishReason: res?.finishReason ?? "error", ...why ? { error: why } : {} });
|
|
23537
23961
|
}).catch((e) => {
|
|
23538
|
-
|
|
23962
|
+
log42.error("duplex turn failed", e);
|
|
23539
23963
|
done2();
|
|
23540
23964
|
out({ type: "turn_done", id, finishReason: "error", error: String(e?.message ?? e) });
|
|
23541
23965
|
});
|
|
@@ -23557,7 +23981,9 @@ async function channelServe(args, ai, cfg) {
|
|
|
23557
23981
|
fastModel: model,
|
|
23558
23982
|
mode: args.channelMode,
|
|
23559
23983
|
gender: args.voiceGender ?? "",
|
|
23560
|
-
|
|
23984
|
+
progress: { generate: fastProgressGenerator(ai, process.env.AGENTX_CHANNEL_MODEL || model, args.voiceGender) },
|
|
23985
|
+
// no `ai` here: the channel's model wiring is explicit
|
|
23986
|
+
channel: { ...channelOptions(ai, process.env.AGENTX_CHANNEL_MODEL || model, args.voiceGender), onTree: (e) => out({ type: "metric", name: "tree", ms: e.ms, kind: `${e.tokens ? `${e.tokens.input}/${e.tokens.output} tok ` : ""}${e.error ?? (e.lines ?? []).join(" | ")}` }), onLeaf: (e) => out({ type: "metric", name: "leaf", ms: e.ms, kind: `${e.moment} ${e.conf} ${e.acted}`, text: e.text }) },
|
|
23561
23987
|
speak: (line, kind) => {
|
|
23562
23988
|
out(channelLine(line, kind));
|
|
23563
23989
|
return true;
|