@livx.cc/agentx 0.99.144 → 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 +2 -2
- package/dist/cli.d.ts +2 -1
- package/dist/cli.js +660 -213
- package/dist/cli.js.map +1 -1
- package/dist/index.d.ts +4 -4
- package/dist/index.js +392 -62
- package/dist/index.js.map +1 -1
- package/dist/{secondChannel--Iv3ZQ69.d.ts → secondChannel-CJ1eYZKA.d.ts} +119 -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,7 +10459,17 @@ 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
|
-
|
|
10462
|
+
if (/^(?:gasp|quiet|laughter)[.!?…]*$/i.test(s.trim())) return "";
|
|
10463
|
+
const first = s.trim().split("\n")[0];
|
|
10464
|
+
const tags = [...first.matchAll(LINE_TAG)].map((m) => `[${m[1].toLowerCase()}]`).filter((t, i, a) => a.indexOf(t) === i).join(" ");
|
|
10465
|
+
const raw = first.replace(LINE_TAG, " ").trim();
|
|
10466
|
+
if (tags && !/[\p{L}\p{N}]/u.test(raw)) return /laughter|gasp/.test(tags) ? tags : "";
|
|
10467
|
+
const words4 = cleanWords(raw, lang, maxWords);
|
|
10468
|
+
return words4 && tags ? `${tags} ${words4}` : words4;
|
|
10469
|
+
}
|
|
10470
|
+
var LINE_TAG = /\[(laughter|gasp|quiet)\]/gi;
|
|
10471
|
+
var lineWords = (line) => line.replace(LINE_TAG, " ").trim();
|
|
10472
|
+
function cleanWords(raw, lang, maxWords) {
|
|
10463
10473
|
const l = raw.replace(/^[-*•\d.)\s]+/, "").replace(/^["'“”«»]+|["'“”«»]+$/g, "").replace(new RegExp("^\\p{L}+:\\s*", "u"), "").trim();
|
|
10464
10474
|
if (!l || isLeakSuspect(raw) || isLeakSuspect(l)) {
|
|
10465
10475
|
if (l) log23.debug(`line "${raw}" reads as meta \u2014 rejected`);
|
|
@@ -13204,7 +13214,267 @@ init_models();
|
|
|
13204
13214
|
|
|
13205
13215
|
// src/voice/progress.ts
|
|
13206
13216
|
init_logging();
|
|
13207
|
-
|
|
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");
|
|
13208
13478
|
var HE_RESULT_CLAIM = /(?:^|\s)(?:מצאתי|סיימתי|בוצע|הנה|אין)(?=\s|$|[.,!…])/u;
|
|
13209
13479
|
var TOPICS = [
|
|
13210
13480
|
[/toolsearch|^mcp__.*__(list_commands|call_info)$/, null],
|
|
@@ -13328,8 +13598,8 @@ var Progress = class {
|
|
|
13328
13598
|
this.said.add(norm3(line));
|
|
13329
13599
|
this.lastAt = this.o.now();
|
|
13330
13600
|
}
|
|
13331
|
-
/** The line for this tool call in `lang`, or '' (no template and no/late/invalid generation, a repeat, a result claim). */
|
|
13332
|
-
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 = "") {
|
|
13333
13603
|
if (this.streamed) return "";
|
|
13334
13604
|
const name = tool.toLowerCase();
|
|
13335
13605
|
const hit = TOPICS.find(([re]) => re.test(name));
|
|
@@ -13348,18 +13618,18 @@ var Progress = class {
|
|
|
13348
13618
|
r(null);
|
|
13349
13619
|
}, this.o.generateBudgetMs);
|
|
13350
13620
|
});
|
|
13351
|
-
const raw = await Promise.race([this.o.generate(tool, argsHint(args), lang, ac.signal).catch((e) => {
|
|
13352
|
-
|
|
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}`);
|
|
13353
13623
|
return null;
|
|
13354
13624
|
}), late]).finally(() => clearTimeout(t));
|
|
13355
13625
|
const l = cleanLine(raw ?? "", lang, 5);
|
|
13356
|
-
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 "";
|
|
13357
13627
|
return l;
|
|
13358
13628
|
}
|
|
13359
13629
|
};
|
|
13360
13630
|
function fastProgressGenerator(ai, model, gender) {
|
|
13361
13631
|
return async (tool, hint, lang, signal) => {
|
|
13362
|
-
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.`;
|
|
13363
13633
|
const reasoning = /gpt-oss/.test(model) ? { providerOptions: { reasoning_effort: "low" } } : {};
|
|
13364
13634
|
const r = await ai.chat({ model, messages: [{ role: "user", content: prompt }], stream: false, signal, maxTokens: 150, ...reasoning });
|
|
13365
13635
|
return r.content ?? "";
|
|
@@ -13368,81 +13638,7 @@ function fastProgressGenerator(ai, model, gender) {
|
|
|
13368
13638
|
|
|
13369
13639
|
// src/voice/secondChannel.ts
|
|
13370
13640
|
init_logging();
|
|
13371
|
-
|
|
13372
|
-
// src/voice/backchannelPlan.ts
|
|
13373
|
-
init_logging();
|
|
13374
|
-
var log27 = forComponent("BackchannelPlan");
|
|
13375
|
-
var TURN_TYPES = ["story", "list", "complaint", "explanation", "short_command", "question", "other"];
|
|
13376
|
-
var DENSITIES = ["none", "low", "normal", "high"];
|
|
13377
|
-
var silentTurn = (p) => p.density === "none" || p.turn === "short_command" || p.turn === "question";
|
|
13378
|
-
var cueWords = (s) => s.toLowerCase().replace(/[^\p{L}\p{N}'\s]+/gu, " ").split(/\s+/).filter(Boolean);
|
|
13379
|
-
function parsePlan(raw, lang, maxCues = 8) {
|
|
13380
|
-
const m = raw.match(/\{[\s\S]*\}/);
|
|
13381
|
-
if (!m) return null;
|
|
13382
|
-
let o;
|
|
13383
|
-
try {
|
|
13384
|
-
o = JSON.parse(m[0]);
|
|
13385
|
-
} catch {
|
|
13386
|
-
return null;
|
|
13387
|
-
}
|
|
13388
|
-
const turn = String(o?.turn ?? "").toLowerCase().replace(/[\s-]+/g, "_");
|
|
13389
|
-
const density = String(o?.density ?? "").toLowerCase();
|
|
13390
|
-
if (!TURN_TYPES.includes(turn) || !DENSITIES.includes(density)) return null;
|
|
13391
|
-
const cues = [];
|
|
13392
|
-
for (const c of Array.isArray(o.cues) ? o.cues : []) {
|
|
13393
|
-
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);
|
|
13394
|
-
const line = typeof c?.line === "string" ? cleanLine(c.line, lang, 4) : "";
|
|
13395
|
-
if (when.length && line) cues.push({ when: [...new Set(when)], line });
|
|
13396
|
-
if (cues.length >= maxCues) break;
|
|
13397
|
-
}
|
|
13398
|
-
return { turn, density, cues };
|
|
13399
|
-
}
|
|
13400
|
-
function matchCue(plan, heard, from = 0) {
|
|
13401
|
-
if (!plan || silentTurn(plan)) return null;
|
|
13402
|
-
const w = cueWords(heard);
|
|
13403
|
-
for (let i = Math.max(0, from); i < w.length; i++) {
|
|
13404
|
-
for (const c of plan.cues) {
|
|
13405
|
-
for (const p of c.when) {
|
|
13406
|
-
const pw = p.split(" ");
|
|
13407
|
-
if (i + pw.length <= w.length && pw.every((x, j) => w[i + j] === x)) return c;
|
|
13408
|
-
}
|
|
13409
|
-
}
|
|
13410
|
-
}
|
|
13411
|
-
return null;
|
|
13412
|
-
}
|
|
13413
|
-
var BackchannelPlannerOptions = class {
|
|
13414
|
-
/** Fast model (Groq gpt-oss / the reflex). */
|
|
13415
|
-
model = "groq/openai/gpt-oss-120b";
|
|
13416
|
-
maxTokens = 900;
|
|
13417
|
-
};
|
|
13418
|
-
var BackchannelPlanner = class {
|
|
13419
|
-
constructor(ai, options) {
|
|
13420
|
-
this.ai = ai;
|
|
13421
|
-
this.options = options;
|
|
13422
|
-
this.options = { ...new BackchannelPlannerOptions(), ...options };
|
|
13423
|
-
}
|
|
13424
|
-
ai;
|
|
13425
|
-
options;
|
|
13426
|
-
async plan(c, signal) {
|
|
13427
|
-
const o = this.options;
|
|
13428
|
-
const name = languageName(c.lang);
|
|
13429
|
-
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.
|
|
13430
|
-
Assistant just said: "${c.agent.slice(-400)}"
|
|
13431
|
-
` + (c.user ? `User's previous turn ended: "${c.user.slice(-200)}"
|
|
13432
|
-
` : "") + (c.heard ? `User so far in this turn: "${c.heard.slice(-300)}"
|
|
13433
|
-
` : "") + `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).
|
|
13434
|
-
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.
|
|
13435
|
-
Reply JSON only: {"turn":"...","density":"...","cues":[{"when":["phrase",...],"line":"..."}]}. Phrases in the user's language.`;
|
|
13436
|
-
const reasoning = /gpt-oss/.test(o.model) ? { providerOptions: { reasoning_effort: "low" } } : {};
|
|
13437
|
-
const r = await this.ai.chat({ model: o.model, messages: [{ role: "user", content: prompt }], stream: false, signal, maxTokens: o.maxTokens, ...reasoning });
|
|
13438
|
-
const p = parsePlan(r.content ?? "", c.lang);
|
|
13439
|
-
if (!p) log27.debug(`unusable plan: ${(r.content ?? "").slice(0, 120)}`);
|
|
13440
|
-
return p;
|
|
13441
|
-
}
|
|
13442
|
-
};
|
|
13443
|
-
|
|
13444
|
-
// src/voice/secondChannel.ts
|
|
13445
|
-
var log28 = forComponent("SecondChannel");
|
|
13641
|
+
var log29 = forComponent("SecondChannel");
|
|
13446
13642
|
var CHANNEL_MODES = {
|
|
13447
13643
|
turn: { kinds: ["bridge"], bridgeDelayMs: 1500 },
|
|
13448
13644
|
normal: {},
|
|
@@ -13461,10 +13657,10 @@ var CHANNEL_MODES = {
|
|
|
13461
13657
|
maxPerWindow: 6
|
|
13462
13658
|
},
|
|
13463
13659
|
live: {
|
|
13464
|
-
kinds: ["backchannel"],
|
|
13660
|
+
kinds: ["backchannel", "bridge"],
|
|
13465
13661
|
anticipate: true,
|
|
13466
13662
|
cueOnly: false,
|
|
13467
|
-
generateFor: ["backchannel"],
|
|
13663
|
+
generateFor: ["backchannel", "bridge"],
|
|
13468
13664
|
reactionGapMs: 0,
|
|
13469
13665
|
generateBudgetMs: 400,
|
|
13470
13666
|
backchannelMinWords: 3,
|
|
@@ -13519,6 +13715,8 @@ var SecondChannelOptions = class {
|
|
|
13519
13715
|
decideEveryWords = 3;
|
|
13520
13716
|
decisionBudgetMs = 300;
|
|
13521
13717
|
generateBudgetMs = 500;
|
|
13718
|
+
/** `live`: how long the fast model may take on a bridge line; later = silence. */
|
|
13719
|
+
bridgeBudgetMs = 1200;
|
|
13522
13720
|
minGapMs = 2500;
|
|
13523
13721
|
/** Backchannel after backchannel needs this gap (~4-6 cues in a 30s monologue — Para phone call 2026-10-13: 5s left
|
|
13524
13722
|
* one cue in a long statement). */
|
|
@@ -13572,6 +13770,31 @@ var SecondChannelOptions = class {
|
|
|
13572
13770
|
cueOnly = true;
|
|
13573
13771
|
onPlan = () => {
|
|
13574
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
|
+
};
|
|
13575
13798
|
now = () => performance.now();
|
|
13576
13799
|
random = Math.random;
|
|
13577
13800
|
};
|
|
@@ -13580,15 +13803,15 @@ function withBudget(p, ms, what, ac) {
|
|
|
13580
13803
|
let t;
|
|
13581
13804
|
const late = new Promise((r) => {
|
|
13582
13805
|
t = setTimeout(() => {
|
|
13583
|
-
|
|
13806
|
+
log29.debug(`${what}: over the ${ms}ms budget \u2014 dropped`);
|
|
13584
13807
|
ac?.abort();
|
|
13585
13808
|
r(null);
|
|
13586
13809
|
}, ms);
|
|
13587
13810
|
});
|
|
13588
13811
|
return Promise.race([p.catch((e) => {
|
|
13589
13812
|
const msg = String(e?.message ?? e);
|
|
13590
|
-
if (e?.name === "AbortError" || /aborted/i.test(msg))
|
|
13591
|
-
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}`);
|
|
13592
13815
|
return null;
|
|
13593
13816
|
}), late]).finally(() => clearTimeout(t));
|
|
13594
13817
|
}
|
|
@@ -13601,6 +13824,7 @@ var SecondChannel = class {
|
|
|
13601
13824
|
for (const k of Object.keys(preset)) if (!options || !(k in options)) this.normalTiming[k] = base[k];
|
|
13602
13825
|
this.startedAt = this.o.now();
|
|
13603
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);
|
|
13604
13828
|
}
|
|
13605
13829
|
options;
|
|
13606
13830
|
heard = "";
|
|
@@ -13629,6 +13853,12 @@ var SecondChannel = class {
|
|
|
13629
13853
|
// one bridge per main turn
|
|
13630
13854
|
bridgeDraft = null;
|
|
13631
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
|
|
13632
13862
|
recent = [];
|
|
13633
13863
|
picks = /* @__PURE__ */ new Map();
|
|
13634
13864
|
inflight = null;
|
|
@@ -13656,6 +13886,21 @@ var SecondChannel = class {
|
|
|
13656
13886
|
normalTiming = {};
|
|
13657
13887
|
// chatty without aec: the preset's keys back at their defaults
|
|
13658
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;
|
|
13659
13904
|
/** The language lines are spoken in (detected from the user's words, or set by the host). */
|
|
13660
13905
|
get language() {
|
|
13661
13906
|
return this.lang;
|
|
@@ -13667,7 +13912,7 @@ var SecondChannel = class {
|
|
|
13667
13912
|
if (host) this.pinned = true;
|
|
13668
13913
|
const lang = primaryLang(tag);
|
|
13669
13914
|
if (!lang || lang === this.lang) return;
|
|
13670
|
-
|
|
13915
|
+
log29.debug(`language ${this.lang} \u2192 ${lang}`);
|
|
13671
13916
|
this.lang = lang;
|
|
13672
13917
|
this.recent = [];
|
|
13673
13918
|
this.picks.clear();
|
|
@@ -13680,6 +13925,10 @@ var SecondChannel = class {
|
|
|
13680
13925
|
const l = detectLanguage(text, !!this.lang);
|
|
13681
13926
|
if (l) this.setLanguage(l);
|
|
13682
13927
|
}
|
|
13928
|
+
/** `live` speaks no stock bridge/filler, with or without aec. */
|
|
13929
|
+
get ownWords() {
|
|
13930
|
+
return this.options.mode === "live";
|
|
13931
|
+
}
|
|
13683
13932
|
get bank() {
|
|
13684
13933
|
return this.lang ? this.o.banks ? this.o.banks.get(this.lang) : this.lang === "en" ? EN_BANK : null : null;
|
|
13685
13934
|
}
|
|
@@ -13703,7 +13952,23 @@ var SecondChannel = class {
|
|
|
13703
13952
|
this.onPause(this.o.fillerPauseMs);
|
|
13704
13953
|
}, this.o.fillerPauseMs);
|
|
13705
13954
|
let cue = null;
|
|
13706
|
-
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) {
|
|
13707
13972
|
const n = words3(t).length;
|
|
13708
13973
|
if (!this.plan && !this.planning && this.planTries < 2) this.requestPlan();
|
|
13709
13974
|
else if (this.plan && !this.revised && n >= this.o.reviseAtWords) {
|
|
@@ -13748,11 +14013,24 @@ var SecondChannel = class {
|
|
|
13748
14013
|
this.decidedAt = 0;
|
|
13749
14014
|
this.bridged = false;
|
|
13750
14015
|
this.cueFrom = 0;
|
|
13751
|
-
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();
|
|
13752
14023
|
return;
|
|
13753
14024
|
}
|
|
13754
14025
|
if (s === "queued") {
|
|
13755
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
|
+
}
|
|
13756
14034
|
this.plan = null;
|
|
13757
14035
|
this.planning = false;
|
|
13758
14036
|
this.planTries = 0;
|
|
@@ -13766,7 +14044,7 @@ var SecondChannel = class {
|
|
|
13766
14044
|
if (this[k]) clearTimeout(this[k]);
|
|
13767
14045
|
this[k] = null;
|
|
13768
14046
|
}
|
|
13769
|
-
if (this.o.instantBridge) this.prefetchBridge();
|
|
14047
|
+
if (this.o.instantBridge || this.ownWords) this.prefetchBridge();
|
|
13770
14048
|
const wait = Math.max(this.o.bridgeDelayMs, this.o.minGapMs - (this.o.now() - this.lastAt));
|
|
13771
14049
|
if (wait > 0) this.bridgeTimer = setTimeout(() => {
|
|
13772
14050
|
this.bridgeTimer = null;
|
|
@@ -13793,6 +14071,10 @@ var SecondChannel = class {
|
|
|
13793
14071
|
this.detect(this.heard);
|
|
13794
14072
|
this.main = "idle";
|
|
13795
14073
|
this.onAgentState("queued");
|
|
14074
|
+
if (this.tree) {
|
|
14075
|
+
this.noteTalk("them", this.heard);
|
|
14076
|
+
this.leafReady = this.turnEndLeaf();
|
|
14077
|
+
}
|
|
13796
14078
|
}
|
|
13797
14079
|
/** The main answer's streamed text (before its audio): channel-1 is responding — no bridge from here on. */
|
|
13798
14080
|
onMainTokens(text) {
|
|
@@ -13812,7 +14094,7 @@ var SecondChannel = class {
|
|
|
13812
14094
|
try {
|
|
13813
14095
|
this.o.cancel();
|
|
13814
14096
|
} catch (e) {
|
|
13815
|
-
|
|
14097
|
+
log29.warn(`cancel threw: ${e.message}`);
|
|
13816
14098
|
}
|
|
13817
14099
|
}
|
|
13818
14100
|
}
|
|
@@ -13823,6 +14105,10 @@ var SecondChannel = class {
|
|
|
13823
14105
|
this.cutLine = null;
|
|
13824
14106
|
return !!c && c === text.trim();
|
|
13825
14107
|
}
|
|
14108
|
+
/** Another fill line (progress) already covers this turn's wait: no bridge after it. */
|
|
14109
|
+
covered() {
|
|
14110
|
+
this.bridged = true;
|
|
14111
|
+
}
|
|
13826
14112
|
/** Resolves when the in-flight line finished playing (immediately when none) — hosts enqueue channel-1 audio behind it. */
|
|
13827
14113
|
drain() {
|
|
13828
14114
|
return this.inflight ?? Promise.resolve();
|
|
@@ -13902,6 +14188,106 @@ var SecondChannel = class {
|
|
|
13902
14188
|
this.o.onPlan(p, !!heard, Math.round(this.o.now() - t0));
|
|
13903
14189
|
});
|
|
13904
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
|
+
}
|
|
13905
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
|
|
13906
14292
|
* sentence end only deep into a story — a short request's end is the end of their turn (replay: "mm-hm" right after
|
|
13907
14293
|
* "Check hacker news for recent news.", just before the final). */
|
|
@@ -13924,7 +14310,7 @@ var SecondChannel = class {
|
|
|
13924
14310
|
const opts = this.options;
|
|
13925
14311
|
if (opts.mode === "chatty" && !opts.aec && !this.degradedLogged) {
|
|
13926
14312
|
this.degradedLogged = true;
|
|
13927
|
-
|
|
14313
|
+
log29.info("chatty mode without echo cancellation \u2014 normal timing (our lines would re-trigger the mic)");
|
|
13928
14314
|
}
|
|
13929
14315
|
const rule = this.rule(trigger, pauseMs, breath, cue);
|
|
13930
14316
|
if (rule === "silence") {
|
|
@@ -13943,7 +14329,7 @@ var SecondChannel = class {
|
|
|
13943
14329
|
const d = await withBudget(this.o.decide(this.tail(), { ...this.state(pauseMs), rule }, ac.signal), this.o.decisionBudgetMs, "channel decision", ac);
|
|
13944
14330
|
choice = d?.choice;
|
|
13945
14331
|
if (choice && choice in CHANNEL_ACTIONS && (choice === "silence" || this.allowed(choice))) kind = choice;
|
|
13946
|
-
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`);
|
|
13947
14333
|
}
|
|
13948
14334
|
if (kind === "silence") return ev({ choice, acted: "silence" });
|
|
13949
14335
|
if (stale()) return ev({ choice, kind, acted: "stale" });
|
|
@@ -13975,15 +14361,28 @@ var SecondChannel = class {
|
|
|
13975
14361
|
/** Start writing this turn's bridge now, so it may be ready by bridgeDelayMs. The bridge never waits for it. */
|
|
13976
14362
|
prefetchBridge() {
|
|
13977
14363
|
this.bridgeDraft = null;
|
|
13978
|
-
|
|
13979
|
-
|
|
13980
|
-
|
|
13981
|
-
|
|
13982
|
-
|
|
13983
|
-
|
|
13984
|
-
|
|
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}`));
|
|
13985
14373
|
}
|
|
13986
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
|
+
}
|
|
13987
14386
|
if (kind === "bridge" && this.o.instantBridge) {
|
|
13988
14387
|
const d = this.bridgeDraft?.gen === this.gen ? this.bridgeDraft.text : "";
|
|
13989
14388
|
this.bridgeDraft = null;
|
|
@@ -13992,18 +14391,19 @@ var SecondChannel = class {
|
|
|
13992
14391
|
}
|
|
13993
14392
|
if (this.o.generate && this.o.generateFor.includes(kind) && (kind !== "backchannel" || react)) {
|
|
13994
14393
|
const ac = new AbortController();
|
|
13995
|
-
const ctx = { kind, heard: this.tail(), state: this.main, avoid: [...this.recent], lang: this.lang, ...kind === "backchannel" && this.o.reactionGapMs ? { react: true } : {} };
|
|
14394
|
+
const ctx = { kind, heard: this.tail(), state: this.main, avoid: [...this.recent], lang: this.lang, ...kind === "backchannel" && this.o.reactionGapMs ? { react: true } : {}, ...kind === "backchannel" && this.o.mode === "live" ? { tags: true } : {} };
|
|
13996
14395
|
const raw = await withBudget(this.o.generate(ctx, ac.signal), this.o.generateBudgetMs, `${kind} generate`);
|
|
13997
14396
|
if (raw === null) ac.abort();
|
|
13998
14397
|
const text = cleanLine(raw ?? "", this.lang);
|
|
13999
14398
|
if (text && !this.recent.some((r) => norm3(r) === norm3(text))) return text;
|
|
14000
|
-
if (text)
|
|
14399
|
+
if (text) log29.debug(`generated "${text}" repeats a recent line \u2014 canned`);
|
|
14001
14400
|
}
|
|
14002
14401
|
return this.pick(kind);
|
|
14003
14402
|
}
|
|
14004
14403
|
/** Canned rotation in the user's language: never one of the last `bankExclude` picks of this kind, nor a recent
|
|
14005
14404
|
* line. '' = no bank for this language yet (silence). */
|
|
14006
14405
|
pick(kind) {
|
|
14406
|
+
if (this.ownWords && kind !== "backchannel") return "";
|
|
14007
14407
|
const pool = this.bank?.[kind] ?? [];
|
|
14008
14408
|
if (!pool.length) return "";
|
|
14009
14409
|
const hist = this.picks.get(kind) ?? [];
|
|
@@ -14019,7 +14419,7 @@ var SecondChannel = class {
|
|
|
14019
14419
|
try {
|
|
14020
14420
|
r = this.o.speak(text, kind);
|
|
14021
14421
|
} catch (e) {
|
|
14022
|
-
|
|
14422
|
+
log29.warn(`speak threw \u2014 line dropped: ${e.message}`);
|
|
14023
14423
|
return false;
|
|
14024
14424
|
}
|
|
14025
14425
|
if (r === false) return false;
|
|
@@ -14028,11 +14428,12 @@ var SecondChannel = class {
|
|
|
14028
14428
|
if (kind === "backchannel") this.bcTimes.push(this.lastAt);
|
|
14029
14429
|
if (kind === "bridge") this.bridged = true;
|
|
14030
14430
|
this.recent = [...this.recent, text].slice(-this.o.avoidLines);
|
|
14031
|
-
this.live = text
|
|
14032
|
-
this.
|
|
14431
|
+
this.live = lineWords(text);
|
|
14432
|
+
const words4 = this.live;
|
|
14433
|
+
if (words4) this.o.show(words4, kind);
|
|
14033
14434
|
const p = Promise.resolve(r).then(() => {
|
|
14034
14435
|
}, (e) => {
|
|
14035
|
-
|
|
14436
|
+
log29.warn(`channel line playback failed: ${e?.message ?? e}`);
|
|
14036
14437
|
}).finally(() => {
|
|
14037
14438
|
if (this.inflight === p) this.inflight = null;
|
|
14038
14439
|
});
|
|
@@ -14069,10 +14470,18 @@ var KIND_HINT2 = {
|
|
|
14069
14470
|
bridge: 'a neutral one-moment cue while the answer is prepared ("let me see\u2026", "one sec\u2026") \u2014 never the start of a statement or opinion ("the thing is", "well actually")'
|
|
14070
14471
|
};
|
|
14071
14472
|
var REACT_HINT = 'a short reaction to their LAST words instead: feeling ("oh no", "ha, nice", "ugh"), surprise ("wait, really?", "huh"), a light laugh if they joke or laugh ("ha!"), or an echo of their key word ("the deploy?") \u2014 still never asks for an answer or takes the turn; if nothing there deserves a reaction, a plain "mm-hm"';
|
|
14473
|
+
var TAG_HINT = 'Real listeners often react without words: the line may be, or begin with, [laughter] or [gasp], and [quiet] before words breathes them under the voice ("[gasp]", "[laughter]", "[gasp] [quiet] no way"). Use a sound when it fits what they said.';
|
|
14474
|
+
function channelLine(line, kind) {
|
|
14475
|
+
const text = lineWords(line);
|
|
14476
|
+
return { type: "channel", kind, text, ...text === line ? {} : { speech: line } };
|
|
14477
|
+
}
|
|
14072
14478
|
function fastLineGenerator(ai, model, gender) {
|
|
14073
14479
|
return async (c, signal) => {
|
|
14074
|
-
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]}.
|
|
14075
14483
|
` + (c.react ? `Here the line may be ${REACT_HINT}.
|
|
14484
|
+
` : "") + (c.tags ? `${TAG_HINT}
|
|
14076
14485
|
` : "") + `The user just said: "${c.heard}"
|
|
14077
14486
|
The assistant is: ${c.state}.
|
|
14078
14487
|
` + (c.avoid.length ? `Do not reuse any of: ${c.avoid.map((a) => `"${a}"`).join(", ")}.
|
|
@@ -14090,7 +14499,7 @@ function closedQuestion(reply) {
|
|
|
14090
14499
|
}
|
|
14091
14500
|
|
|
14092
14501
|
// src/voice/call.ts
|
|
14093
|
-
var
|
|
14502
|
+
var log30 = forComponent("VoiceCall");
|
|
14094
14503
|
var VoiceCallOptions = class {
|
|
14095
14504
|
/** Host runs MAIN with exactly `text` (a replace: roll the `replaces` turn back first). */
|
|
14096
14505
|
sendTurn = () => {
|
|
@@ -14165,7 +14574,7 @@ var VoiceCall = class {
|
|
|
14165
14574
|
cancel: () => o.cancel(),
|
|
14166
14575
|
now: o.now
|
|
14167
14576
|
});
|
|
14168
|
-
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 });
|
|
14169
14578
|
this.judge = new OverlapJudge({ ...ai ? { model: overlapModelFor(ai) } : {}, now: o.now });
|
|
14170
14579
|
this.gate = new TurnGate({
|
|
14171
14580
|
now: o.now,
|
|
@@ -14218,7 +14627,7 @@ var VoiceCall = class {
|
|
|
14218
14627
|
this.gate.speaking();
|
|
14219
14628
|
const c = this.cur;
|
|
14220
14629
|
if (this.o.mode === "live" && c?.running && !c.worded && text.trim().split(/\s+/).length >= 2) {
|
|
14221
|
-
|
|
14630
|
+
log30.debug("user resumed before the reply \u2014 yielded");
|
|
14222
14631
|
this.barge();
|
|
14223
14632
|
}
|
|
14224
14633
|
this.follow(text);
|
|
@@ -14322,7 +14731,7 @@ var VoiceCall = class {
|
|
|
14322
14731
|
try {
|
|
14323
14732
|
this.o.cancel();
|
|
14324
14733
|
} catch (e) {
|
|
14325
|
-
|
|
14734
|
+
log30.warn(`cancel threw: ${e.message}`);
|
|
14326
14735
|
}
|
|
14327
14736
|
if (this.cur?.running) {
|
|
14328
14737
|
this.cur.running = false;
|
|
@@ -14409,7 +14818,7 @@ var VoiceCall = class {
|
|
|
14409
14818
|
try {
|
|
14410
14819
|
r = this.o.speak(text, kind);
|
|
14411
14820
|
} catch (e) {
|
|
14412
|
-
|
|
14821
|
+
log30.warn(`speak threw: ${e.message}`);
|
|
14413
14822
|
return false;
|
|
14414
14823
|
}
|
|
14415
14824
|
if (r === false) return false;
|
|
@@ -14460,7 +14869,8 @@ var VoiceCall = class {
|
|
|
14460
14869
|
async onTool(c, name, args) {
|
|
14461
14870
|
const lang = this.lang;
|
|
14462
14871
|
if (!lang || c.streamed) return;
|
|
14463
|
-
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}` });
|
|
14464
14874
|
if (!line || this.cur !== c || c.streamed || !c.running || this.lang !== lang) return;
|
|
14465
14875
|
this.clearProgress();
|
|
14466
14876
|
const tryNow = () => {
|
|
@@ -14472,6 +14882,7 @@ var VoiceCall = class {
|
|
|
14472
14882
|
}
|
|
14473
14883
|
if (this.say(line, "progress") !== false) {
|
|
14474
14884
|
this.progress.spoke(line);
|
|
14885
|
+
this.fill.covered();
|
|
14475
14886
|
this.o.show(line, "progress");
|
|
14476
14887
|
}
|
|
14477
14888
|
};
|
|
@@ -14495,7 +14906,7 @@ init_logging();
|
|
|
14495
14906
|
init_platform();
|
|
14496
14907
|
import { spawn } from "child_process";
|
|
14497
14908
|
import { createHash } from "crypto";
|
|
14498
|
-
var
|
|
14909
|
+
var log31 = forComponent("mcp");
|
|
14499
14910
|
var PROTOCOL_VERSION = "2025-06-18";
|
|
14500
14911
|
var DEFAULT_TIMEOUT_MS = 3e4;
|
|
14501
14912
|
var DEFAULT_CALL_TIMEOUT_MS = 30 * 6e4;
|
|
@@ -14527,7 +14938,7 @@ var StdioTransport = class {
|
|
|
14527
14938
|
proc.stdout.setEncoding("utf8");
|
|
14528
14939
|
proc.stdout.on("data", (chunk) => this.onData(chunk));
|
|
14529
14940
|
proc.stderr.setEncoding("utf8");
|
|
14530
|
-
proc.stderr.on("data", (chunk) =>
|
|
14941
|
+
proc.stderr.on("data", (chunk) => log31.debug(`[${command}] stderr:`, chunk.trimEnd()));
|
|
14531
14942
|
proc.on("exit", (code) => this.failAll(new Error(`MCP server "${command}" exited (code ${code})`)));
|
|
14532
14943
|
proc.on("error", (e) => this.failAll(e instanceof Error ? e : new Error(String(e))));
|
|
14533
14944
|
}
|
|
@@ -14541,7 +14952,7 @@ var StdioTransport = class {
|
|
|
14541
14952
|
try {
|
|
14542
14953
|
this.dispatch(JSON.parse(line));
|
|
14543
14954
|
} catch (e) {
|
|
14544
|
-
|
|
14955
|
+
log31.debug("dropping non-JSON line from MCP server:", line, e);
|
|
14545
14956
|
}
|
|
14546
14957
|
}
|
|
14547
14958
|
}
|
|
@@ -14551,7 +14962,7 @@ var StdioTransport = class {
|
|
|
14551
14962
|
try {
|
|
14552
14963
|
p2?.onProgress?.(msg.params ?? {});
|
|
14553
14964
|
} catch (e) {
|
|
14554
|
-
|
|
14965
|
+
log31.debug("onProgress handler threw", e);
|
|
14555
14966
|
}
|
|
14556
14967
|
return;
|
|
14557
14968
|
}
|
|
@@ -14589,7 +15000,7 @@ var StdioTransport = class {
|
|
|
14589
15000
|
const onAbort = () => {
|
|
14590
15001
|
if (!this.pending.delete(id)) return;
|
|
14591
15002
|
clearTimeout(timer);
|
|
14592
|
-
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));
|
|
14593
15004
|
reject(abortError(signal));
|
|
14594
15005
|
};
|
|
14595
15006
|
const done = () => signal?.removeEventListener("abort", onAbort);
|
|
@@ -14613,7 +15024,7 @@ var StdioTransport = class {
|
|
|
14613
15024
|
try {
|
|
14614
15025
|
this.proc?.stdin?.end();
|
|
14615
15026
|
} catch (e) {
|
|
14616
|
-
|
|
15027
|
+
log31.debug("stdin end failed", e);
|
|
14617
15028
|
}
|
|
14618
15029
|
if (!(IS_WIN && killTree(this.proc?.pid, "SIGTERM"))) this.proc?.kill();
|
|
14619
15030
|
}
|
|
@@ -14648,7 +15059,7 @@ var HttpTransport = class {
|
|
|
14648
15059
|
return await this.post({ jsonrpc: "2.0", id, method, params: opts.onProgress ? withProgressToken(params, id) : params }, false, signal, opts.onProgress);
|
|
14649
15060
|
} catch (e) {
|
|
14650
15061
|
if (opts.signal?.aborted) {
|
|
14651
|
-
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));
|
|
14652
15063
|
throw abortError(opts.signal);
|
|
14653
15064
|
}
|
|
14654
15065
|
throw e;
|
|
@@ -14691,7 +15102,7 @@ function sseMessage(line) {
|
|
|
14691
15102
|
try {
|
|
14692
15103
|
return JSON.parse(trimmed.slice(5).trim());
|
|
14693
15104
|
} catch (e) {
|
|
14694
|
-
|
|
15105
|
+
log31.debug("skipping unparseable SSE data line", e);
|
|
14695
15106
|
return void 0;
|
|
14696
15107
|
}
|
|
14697
15108
|
}
|
|
@@ -14701,7 +15112,7 @@ async function readSseResponse(resp, id, onProgress) {
|
|
|
14701
15112
|
try {
|
|
14702
15113
|
onProgress?.(obj.params ?? {});
|
|
14703
15114
|
} catch (e) {
|
|
14704
|
-
|
|
15115
|
+
log31.debug("onProgress handler threw", e);
|
|
14705
15116
|
}
|
|
14706
15117
|
return void 0;
|
|
14707
15118
|
}
|
|
@@ -14800,7 +15211,7 @@ async function mountWithDeadline(name, cfg, mountTimeoutMs) {
|
|
|
14800
15211
|
return { name, client, tools, specs, serverInfo: init?.serverInfo, config: cfg };
|
|
14801
15212
|
})(), mountTimeoutMs, name);
|
|
14802
15213
|
} catch (e) {
|
|
14803
|
-
await client.close().catch((err2) =>
|
|
15214
|
+
await client.close().catch((err2) => log31.debug(`close after failed mount of "${name}": ${err2}`));
|
|
14804
15215
|
throw e;
|
|
14805
15216
|
}
|
|
14806
15217
|
}
|
|
@@ -14811,15 +15222,15 @@ function validEntries(servers) {
|
|
|
14811
15222
|
return Object.entries(servers).filter(([name, cfg]) => {
|
|
14812
15223
|
if (!cfg || cfg.disabled) return false;
|
|
14813
15224
|
if (!cfg.command && !cfg.url) {
|
|
14814
|
-
|
|
15225
|
+
log31.warn(`MCP server "${name}" needs a command (stdio) or url (http) \u2014 skipping`);
|
|
14815
15226
|
return false;
|
|
14816
15227
|
}
|
|
14817
15228
|
return true;
|
|
14818
15229
|
});
|
|
14819
15230
|
}
|
|
14820
15231
|
function logMountFailure(name, e) {
|
|
14821
|
-
if (e instanceof McpAuthError)
|
|
14822
|
-
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}`);
|
|
14823
15234
|
}
|
|
14824
15235
|
async function mountMcpServers(servers = {}, opts = {}) {
|
|
14825
15236
|
const entries = validEntries(servers);
|
|
@@ -14829,7 +15240,7 @@ async function mountMcpServers(servers = {}, opts = {}) {
|
|
|
14829
15240
|
const name = entries[i][0];
|
|
14830
15241
|
if (r.status === "fulfilled") {
|
|
14831
15242
|
out.push(r.value);
|
|
14832
|
-
|
|
15243
|
+
log31.debug(`MCP "${name}" mounted \u2014 ${r.value.tools.length} tool(s)${r.value.serverInfo?.name ? ` from ${r.value.serverInfo.name}` : ""}`);
|
|
14833
15244
|
} else logMountFailure(name, r.reason);
|
|
14834
15245
|
});
|
|
14835
15246
|
return out;
|
|
@@ -14869,7 +15280,7 @@ var McpPool = class {
|
|
|
14869
15280
|
const prev = this.warm.get(key);
|
|
14870
15281
|
if (prev) {
|
|
14871
15282
|
clearTimeout(prev.timer);
|
|
14872
|
-
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}`));
|
|
14873
15284
|
}
|
|
14874
15285
|
const e = { client, timer: void 0 };
|
|
14875
15286
|
this.warm.set(key, e);
|
|
@@ -14886,7 +15297,7 @@ var McpPool = class {
|
|
|
14886
15297
|
const e = this.warm.get(key);
|
|
14887
15298
|
if (!e) return;
|
|
14888
15299
|
this.warm.delete(key);
|
|
14889
|
-
await e.client.close().catch((err2) =>
|
|
15300
|
+
await e.client.close().catch((err2) => log31.debug(`warm-pool evict close failed: ${err2}`));
|
|
14890
15301
|
}
|
|
14891
15302
|
async closeAll() {
|
|
14892
15303
|
for (const e of this.warm.values()) {
|
|
@@ -15132,7 +15543,7 @@ init_tools_shell();
|
|
|
15132
15543
|
// src/tools.notify.ts
|
|
15133
15544
|
init_logging();
|
|
15134
15545
|
import { execFile as execFile2 } from "child_process";
|
|
15135
|
-
var
|
|
15546
|
+
var log33 = forComponent("notify");
|
|
15136
15547
|
var WIN_TOAST = [
|
|
15137
15548
|
"[Windows.UI.Notifications.ToastNotificationManager, Windows.UI.Notifications, ContentType = WindowsRuntime] | Out-Null",
|
|
15138
15549
|
"$t = [Windows.UI.Notifications.ToastNotificationManager]::GetTemplateContent([Windows.UI.Notifications.ToastTemplateType]::ToastText02)",
|
|
@@ -15163,7 +15574,7 @@ function makeNotifyTool(opts = {}) {
|
|
|
15163
15574
|
return new Promise((resolve6) => {
|
|
15164
15575
|
run(argv[0], argv[1], { timeout: 5e3, ...extra }, (e) => {
|
|
15165
15576
|
if (e) {
|
|
15166
|
-
|
|
15577
|
+
log33.debug("notification failed", e);
|
|
15167
15578
|
resolve6(`Notification failed: ${e.message}`);
|
|
15168
15579
|
} else resolve6("Notification shown.");
|
|
15169
15580
|
});
|
|
@@ -15180,7 +15591,7 @@ init_logging();
|
|
|
15180
15591
|
import { existsSync as existsSync2, readFileSync as readFileSync5 } from "fs";
|
|
15181
15592
|
import { homedir } from "os";
|
|
15182
15593
|
import { delimiter as delimiter2 } from "path";
|
|
15183
|
-
var
|
|
15594
|
+
var log34 = forComponent("cli-util");
|
|
15184
15595
|
function extraDirs(env = process.env) {
|
|
15185
15596
|
return (env.AGENTX_EXTRA_DIRS || "").split(delimiter2).map((d) => d.trim()).filter(Boolean);
|
|
15186
15597
|
}
|
|
@@ -15200,7 +15611,7 @@ function parseJson(text, fallback, what = "json") {
|
|
|
15200
15611
|
try {
|
|
15201
15612
|
return JSON.parse(text);
|
|
15202
15613
|
} catch (e) {
|
|
15203
|
-
|
|
15614
|
+
log34.debug(`parseJson(${what}) failed: ${e.message}`);
|
|
15204
15615
|
return fallback;
|
|
15205
15616
|
}
|
|
15206
15617
|
}
|
|
@@ -15210,7 +15621,7 @@ function readJsonFile(path, fallback) {
|
|
|
15210
15621
|
try {
|
|
15211
15622
|
text = readFileSync5(path, "utf8");
|
|
15212
15623
|
} catch (e) {
|
|
15213
|
-
|
|
15624
|
+
log34.debug(`readJsonFile(${path}) unreadable: ${e.message}`);
|
|
15214
15625
|
return fallback;
|
|
15215
15626
|
}
|
|
15216
15627
|
return parseJson(text, fallback, path);
|
|
@@ -15524,7 +15935,7 @@ import { existsSync as existsSync4, mkdirSync as mkdirSync5, readFileSync as rea
|
|
|
15524
15935
|
import { homedir as homedir3 } from "os";
|
|
15525
15936
|
import { dirname as dirname4, join as join8 } from "path";
|
|
15526
15937
|
import { fileURLToPath } from "url";
|
|
15527
|
-
var
|
|
15938
|
+
var log35 = forComponent("VoiceIO");
|
|
15528
15939
|
var now3 = () => performance.now();
|
|
15529
15940
|
var Player = class {
|
|
15530
15941
|
proc = null;
|
|
@@ -15538,7 +15949,7 @@ var Player = class {
|
|
|
15538
15949
|
["-loglevel", "quiet", "-nodisp", "-fflags", "nobuffer", "-flags", "low_delay", "-probesize", "32", "-f", "s16le", "-ar", String(TTS_SAMPLE_RATE), "-ch_layout", "mono", "-i", "-"],
|
|
15539
15950
|
{ stdio: ["pipe", "ignore", "ignore"] }
|
|
15540
15951
|
);
|
|
15541
|
-
this.proc.on("error", (e) =>
|
|
15952
|
+
this.proc.on("error", (e) => log35.warn(`ffplay error: ${e.message}`));
|
|
15542
15953
|
this.proc.stdin.on("error", () => {
|
|
15543
15954
|
});
|
|
15544
15955
|
this.bytesWritten = 0;
|
|
@@ -15576,7 +15987,7 @@ function detectFfmpegMic() {
|
|
|
15576
15987
|
const devices = [...audio.matchAll(/\[(\d+)\] (.+)/g)].map(([, idx, name]) => ({ idx, name: name.trim() }));
|
|
15577
15988
|
const mic = devices.find((d) => /microphone|built-in/i.test(d.name) && !/teams|blackhole|loopback/i.test(d.name)) ?? devices[0];
|
|
15578
15989
|
if (!mic) throw new Error("no audio input device found");
|
|
15579
|
-
|
|
15990
|
+
log35.debug(`ffmpeg mic: [${mic.idx}] ${mic.name}`);
|
|
15580
15991
|
return `:${mic.idx}`;
|
|
15581
15992
|
}
|
|
15582
15993
|
function detectDshowMic() {
|
|
@@ -15587,7 +15998,7 @@ function detectDshowMic() {
|
|
|
15587
15998
|
const devices = [...(r.stderr ?? "").matchAll(/"([^"]+)"\s*\(audio\)/g)].map((m) => m[1]);
|
|
15588
15999
|
const mic = devices.find((d) => !/stereo mix|loopback|virtual|cable|teams/i.test(d)) ?? devices[0];
|
|
15589
16000
|
if (!mic) throw new Error("no audio input device found (set MIC_DEVICE to the DirectShow device name)");
|
|
15590
|
-
|
|
16001
|
+
log35.debug(`ffmpeg dshow mic: ${mic}`);
|
|
15591
16002
|
return `audio=${mic}`;
|
|
15592
16003
|
}
|
|
15593
16004
|
function detectedInputDevice() {
|
|
@@ -15623,15 +16034,15 @@ function resolveAecBinary() {
|
|
|
15623
16034
|
if (existsSync4(bin) && statSync6(bin).mtimeMs >= statSync6(src).mtimeMs) return bin;
|
|
15624
16035
|
if (spawnSync3("which", ["swiftc"]).status !== 0) return null;
|
|
15625
16036
|
mkdirSync5(cacheDir, { recursive: true });
|
|
15626
|
-
|
|
16037
|
+
log35.info("compiling AEC mic helper (first run)\u2026");
|
|
15627
16038
|
const build = spawnSync3("swiftc", ["-O", "-o", bin, src, "-Xlinker", "-sectcreate", "-Xlinker", "__TEXT", "-Xlinker", "__info_plist", "-Xlinker", plist], { encoding: "utf8" });
|
|
15628
16039
|
if (build.status !== 0) {
|
|
15629
|
-
|
|
16040
|
+
log35.warn(`AEC build failed: ${build.stderr?.slice(0, 400)}`);
|
|
15630
16041
|
return null;
|
|
15631
16042
|
}
|
|
15632
16043
|
const sign = spawnSync3("codesign", ["-fs", "-", bin], { encoding: "utf8" });
|
|
15633
16044
|
if (sign.status !== 0) {
|
|
15634
|
-
|
|
16045
|
+
log35.warn(`codesign failed: ${sign.stderr?.slice(0, 200)}`);
|
|
15635
16046
|
return null;
|
|
15636
16047
|
}
|
|
15637
16048
|
return bin;
|
|
@@ -15673,17 +16084,17 @@ var NodeMicSource = class {
|
|
|
15673
16084
|
this.proc = spawn2(this.bin, [], { stdio: ["ignore", "pipe", "ignore"] });
|
|
15674
16085
|
} else {
|
|
15675
16086
|
if (!hasCommand("ffmpeg")) throw new Error("voice I/O unavailable: no AEC helper and no ffmpeg on PATH");
|
|
15676
|
-
|
|
16087
|
+
log35.info("mic: raw capture (no AEC) \u2014 echo handled heuristically; headphones recommended");
|
|
15677
16088
|
const input = process.platform === "win32" ? ["-f", "dshow", "-i", detectDshowMic()] : ["-f", "avfoundation", "-i", detectFfmpegMic()];
|
|
15678
16089
|
this.proc = spawn2(
|
|
15679
16090
|
"ffmpeg",
|
|
15680
16091
|
["-loglevel", "error", ...input, "-ar", String(STT_SAMPLE_RATE), "-ac", "1", "-f", "s16le", "-"],
|
|
15681
16092
|
{ stdio: ["ignore", "pipe", "pipe"], ...process.platform === "win32" ? { windowsHide: true } : {} }
|
|
15682
16093
|
);
|
|
15683
|
-
this.proc.stderr.on("data", (d) =>
|
|
16094
|
+
this.proc.stderr.on("data", (d) => log35.warn(`ffmpeg: ${String(d).trim()}`));
|
|
15684
16095
|
}
|
|
15685
16096
|
this.proc.on("exit", (c) => {
|
|
15686
|
-
if (c && !this.stopped)
|
|
16097
|
+
if (c && !this.stopped) log35.error(`mic capture exited (${c}) \u2014 check mic permission / MIC_DEVICE / MIC_AEC=0`);
|
|
15687
16098
|
});
|
|
15688
16099
|
this.proc.stdout.on("data", (chunk) => onChunk(chunk));
|
|
15689
16100
|
}
|
|
@@ -15749,7 +16160,7 @@ var AecDuplexAudio = class {
|
|
|
15749
16160
|
this.proc.stdin.on("error", () => {
|
|
15750
16161
|
});
|
|
15751
16162
|
this.proc.on("exit", (c) => {
|
|
15752
|
-
if (c && !this.stopped)
|
|
16163
|
+
if (c && !this.stopped) log35.error(`aec duplex audio exited (${c}) \u2014 check mic permission / MIC_AEC=0`);
|
|
15753
16164
|
});
|
|
15754
16165
|
this.proc.stdout.on("data", (chunk) => {
|
|
15755
16166
|
this.gotChunk = true;
|
|
@@ -15765,7 +16176,7 @@ var AecDuplexAudio = class {
|
|
|
15765
16176
|
openMicSettings();
|
|
15766
16177
|
this.onFatal?.("microphone permission denied \u2014 enable it in System Settings \u2192 Privacy & Security \u2192 Microphone for your terminal, then restart it");
|
|
15767
16178
|
}
|
|
15768
|
-
} else
|
|
16179
|
+
} else log35.debug(`mic-aec: ${s}`);
|
|
15769
16180
|
}
|
|
15770
16181
|
});
|
|
15771
16182
|
if (!this.noVpio && !this.triedFallback) {
|
|
@@ -15774,7 +16185,7 @@ var AecDuplexAudio = class {
|
|
|
15774
16185
|
this.triedFallback = true;
|
|
15775
16186
|
this.noVpio = true;
|
|
15776
16187
|
this._aec = false;
|
|
15777
|
-
|
|
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)");
|
|
15778
16189
|
this.onDegrade?.();
|
|
15779
16190
|
this.killProc();
|
|
15780
16191
|
this.spawnHelper();
|
|
@@ -15945,7 +16356,7 @@ function bindAckInstinct(v, instinct) {
|
|
|
15945
16356
|
if (ev.kind === "ack_fired") instinct.ackOutcome(String(ev.phrase));
|
|
15946
16357
|
else if (ev.kind === "ack_skipped" || ev.kind === "ack_cancelled") instinct.ackOutcome(null);
|
|
15947
16358
|
} catch (e) {
|
|
15948
|
-
|
|
16359
|
+
log35.warn(`ack outcome tap failed: ${e instanceof Error ? e.message : e}`);
|
|
15949
16360
|
}
|
|
15950
16361
|
onDiag(ev);
|
|
15951
16362
|
};
|
|
@@ -16067,7 +16478,7 @@ function speakBlip(v, text) {
|
|
|
16067
16478
|
v.fireBackchannel();
|
|
16068
16479
|
return true;
|
|
16069
16480
|
} catch (e) {
|
|
16070
|
-
|
|
16481
|
+
log35.warn(`backchannel blip failed \u2014 line dropped: ${e.message}`);
|
|
16071
16482
|
return false;
|
|
16072
16483
|
} finally {
|
|
16073
16484
|
E.BACKCHANNELS = pool;
|
|
@@ -16086,7 +16497,7 @@ function channelInput(sc, m) {
|
|
|
16086
16497
|
}
|
|
16087
16498
|
if (m.type === "agent_state") {
|
|
16088
16499
|
if (typeof m.state === "string" && MAIN_STATES.has(m.state)) sc.onAgentState(m.state);
|
|
16089
|
-
else
|
|
16500
|
+
else log35.warn(`agent_state: unknown state ${JSON.stringify(m.state)} \u2014 ignored`);
|
|
16090
16501
|
return true;
|
|
16091
16502
|
}
|
|
16092
16503
|
return false;
|
|
@@ -16212,7 +16623,7 @@ function fakeVoiceParts(uttFile) {
|
|
|
16212
16623
|
init_logging();
|
|
16213
16624
|
import { appendFile, mkdirSync as mkdirSync6 } from "fs";
|
|
16214
16625
|
import { dirname as dirname5 } from "path";
|
|
16215
|
-
var
|
|
16626
|
+
var log36 = forComponent("VoiceDiag");
|
|
16216
16627
|
var JsonlDiagSink = class {
|
|
16217
16628
|
constructor(path) {
|
|
16218
16629
|
this.path = path;
|
|
@@ -16253,7 +16664,7 @@ var JsonlDiagSink = class {
|
|
|
16253
16664
|
disable(e) {
|
|
16254
16665
|
this.disabled = true;
|
|
16255
16666
|
this.queue.length = 0;
|
|
16256
|
-
|
|
16667
|
+
log36.debug(`voice diag sink disabled (${this.path}): ${e instanceof Error ? e.message : e}`);
|
|
16257
16668
|
}
|
|
16258
16669
|
/** True once a failure permanently disabled the sink (tests/inspection). */
|
|
16259
16670
|
get isDisabled() {
|
|
@@ -16412,7 +16823,7 @@ function applyOverlay(cfg, file) {
|
|
|
16412
16823
|
// cli/hooks-config.ts
|
|
16413
16824
|
import { spawnSync as spawnSync4 } from "child_process";
|
|
16414
16825
|
init_platform();
|
|
16415
|
-
var
|
|
16826
|
+
var log37 = forComponent("hooks");
|
|
16416
16827
|
var escapeRegex = (s) => s.replace(/[.+^${}()|[\]\\]/g, "\\$&");
|
|
16417
16828
|
function ruleMatches(rule, toolName) {
|
|
16418
16829
|
if (!rule.tool || rule.tool === "*") return true;
|
|
@@ -16431,7 +16842,7 @@ function runCmd(rule, env) {
|
|
|
16431
16842
|
});
|
|
16432
16843
|
return { code: r.status ?? 1, out: ((r.stdout ?? "") + (r.stderr ?? "")).trim() };
|
|
16433
16844
|
} catch (e) {
|
|
16434
|
-
|
|
16845
|
+
log37.debug(`hook command failed: ${rule.command}`, e);
|
|
16435
16846
|
return { code: 1, out: String(e?.message ?? e) };
|
|
16436
16847
|
}
|
|
16437
16848
|
}
|
|
@@ -16539,7 +16950,7 @@ import { existsSync as existsSync6, mkdirSync as mkdirSync8, readFileSync as rea
|
|
|
16539
16950
|
import { homedir as homedir6 } from "os";
|
|
16540
16951
|
import { join as join11 } from "path";
|
|
16541
16952
|
init_platform();
|
|
16542
|
-
var
|
|
16953
|
+
var log38 = forComponent("session");
|
|
16543
16954
|
var globalDir = () => join11(homedir6(), ".agent", "sessions");
|
|
16544
16955
|
function indexLink(target, link2) {
|
|
16545
16956
|
try {
|
|
@@ -16602,7 +17013,7 @@ var SessionStore = class {
|
|
|
16602
17013
|
}
|
|
16603
17014
|
load(id) {
|
|
16604
17015
|
if (!this.safeId(id)) {
|
|
16605
|
-
|
|
17016
|
+
log38.debug(`rejecting unsafe session id: ${id}`);
|
|
16606
17017
|
return void 0;
|
|
16607
17018
|
}
|
|
16608
17019
|
const path = join11(this.dir, `${id}.json`);
|
|
@@ -16610,7 +17021,7 @@ var SessionStore = class {
|
|
|
16610
17021
|
try {
|
|
16611
17022
|
return JSON.parse(readFileSync8(path, "utf8"));
|
|
16612
17023
|
} catch (e) {
|
|
16613
|
-
|
|
17024
|
+
log38.debug(`unreadable session ${id} \u2014 ignoring`, e);
|
|
16614
17025
|
return void 0;
|
|
16615
17026
|
}
|
|
16616
17027
|
}
|
|
@@ -16623,7 +17034,7 @@ var SessionStore = class {
|
|
|
16623
17034
|
try {
|
|
16624
17035
|
metas.push(JSON.parse(readFileSync8(join11(this.dir, f), "utf8")).meta);
|
|
16625
17036
|
} catch (e) {
|
|
16626
|
-
|
|
17037
|
+
log38.debug(`skipping unreadable session file ${f}`, e);
|
|
16627
17038
|
}
|
|
16628
17039
|
}
|
|
16629
17040
|
return metas.sort((a, b) => b.updated - a.updated);
|
|
@@ -17055,7 +17466,7 @@ import { promisify } from "util";
|
|
|
17055
17466
|
import { writeFileSync as writeFileSync6, mkdirSync as mkdirSync9 } from "fs";
|
|
17056
17467
|
import { homedir as homedir7 } from "os";
|
|
17057
17468
|
import { join as join12, resolve as resolve4, sep as sep3, parse as parsePath } from "path";
|
|
17058
|
-
var
|
|
17469
|
+
var log39 = forComponent("checkpoints");
|
|
17059
17470
|
var exec = promisify(execFile4);
|
|
17060
17471
|
var DEFAULT_EXCLUDE = [".agent/", ".git/", "node_modules/", "dist/", "build/", ".next/", "target/", ".venv/", "__pycache__/", "*.log"];
|
|
17061
17472
|
function isBroadRoot(p) {
|
|
@@ -17103,7 +17514,7 @@ var ShadowRepo = class {
|
|
|
17103
17514
|
writeFileSync6(join12(this.gitDir, "info", "exclude"), this.exclude.join("\n") + "\n");
|
|
17104
17515
|
this.ready = true;
|
|
17105
17516
|
} catch (e) {
|
|
17106
|
-
|
|
17517
|
+
log39.debug(`git checkpoints unavailable for ${this.workTree}`, e);
|
|
17107
17518
|
this.ready = false;
|
|
17108
17519
|
}
|
|
17109
17520
|
return this.ready;
|
|
@@ -17114,7 +17525,7 @@ var ShadowRepo = class {
|
|
|
17114
17525
|
}
|
|
17115
17526
|
async commit(label, forced = []) {
|
|
17116
17527
|
await this.run("add", "-A");
|
|
17117
|
-
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));
|
|
17118
17529
|
await this.run("commit", "--allow-empty", "-q", "-m", label);
|
|
17119
17530
|
}
|
|
17120
17531
|
/** Inject the CURRENT (pre-edit) content of `paths` into the turn-open restore point by amending it.
|
|
@@ -17122,8 +17533,8 @@ var ShadowRepo = class {
|
|
|
17122
17533
|
* turn-boundary `add -A` would never have captured it. Amend (vs a new commit) keeps one restore
|
|
17123
17534
|
* point per turn, so the REPL's turn↔frame mapping stays intact. */
|
|
17124
17535
|
async amendForced(paths) {
|
|
17125
|
-
for (const p of paths) await this.run("add", "-f", "--", p).catch((e) =>
|
|
17126
|
-
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));
|
|
17127
17538
|
}
|
|
17128
17539
|
/** Commits on `ref`, oldest-first (canonical index space). */
|
|
17129
17540
|
async log(ref) {
|
|
@@ -17183,7 +17594,7 @@ var ShadowRepo = class {
|
|
|
17183
17594
|
await this.run("gc", "--auto", "-q").catch(() => {
|
|
17184
17595
|
});
|
|
17185
17596
|
} catch (e) {
|
|
17186
|
-
|
|
17597
|
+
log39.debug("checkpoint prune failed", e);
|
|
17187
17598
|
}
|
|
17188
17599
|
}
|
|
17189
17600
|
};
|
|
@@ -17251,7 +17662,7 @@ var GitCheckpoints = class {
|
|
|
17251
17662
|
use(sessionId) {
|
|
17252
17663
|
if (sessionId === this.session) return;
|
|
17253
17664
|
this.session = sessionId;
|
|
17254
|
-
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));
|
|
17255
17666
|
}
|
|
17256
17667
|
async begin(label) {
|
|
17257
17668
|
if (!await this.start()) return;
|
|
@@ -17271,7 +17682,7 @@ var GitCheckpoints = class {
|
|
|
17271
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
|
|
17272
17683
|
`);
|
|
17273
17684
|
} else {
|
|
17274
|
-
|
|
17685
|
+
log39.debug("checkpoint commit failed", e);
|
|
17275
17686
|
survivors.push(this.repos[i]);
|
|
17276
17687
|
survivorCaches.push(this.caches[i] ?? []);
|
|
17277
17688
|
}
|
|
@@ -17306,7 +17717,7 @@ var GitCheckpoints = class {
|
|
|
17306
17717
|
if (this.forced.has(abs)) continue;
|
|
17307
17718
|
this.forced.add(abs);
|
|
17308
17719
|
const i = this.repoIndexFor(abs);
|
|
17309
|
-
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));
|
|
17310
17721
|
}
|
|
17311
17722
|
}
|
|
17312
17723
|
};
|
|
@@ -19096,7 +19507,7 @@ import { spawnSync as spawnSync6 } from "child_process";
|
|
|
19096
19507
|
import { writeFileSync as writeFileSync8, mkdirSync as mkdirSync10, readdirSync as readdirSync2, unlinkSync as unlinkSync3, chmodSync, existsSync as existsSync7 } from "fs";
|
|
19097
19508
|
import { homedir as homedir8 } from "os";
|
|
19098
19509
|
import { join as join14 } from "path";
|
|
19099
|
-
var
|
|
19510
|
+
var log40 = forComponent("os-sched");
|
|
19100
19511
|
var OsScheduler = class {
|
|
19101
19512
|
options;
|
|
19102
19513
|
constructor(options) {
|
|
@@ -19158,7 +19569,7 @@ var OsScheduler = class {
|
|
|
19158
19569
|
}
|
|
19159
19570
|
}
|
|
19160
19571
|
} catch (e) {
|
|
19161
|
-
|
|
19572
|
+
log40.debug(`cancel ${id}`, e);
|
|
19162
19573
|
}
|
|
19163
19574
|
for (const f of [`${id}.json`, `${id}.sh`]) {
|
|
19164
19575
|
try {
|
|
@@ -19276,7 +19687,7 @@ import { existsSync as existsSync8, mkdirSync as mkdirSync11, unlinkSync as unli
|
|
|
19276
19687
|
import { homedir as homedir9 } from "os";
|
|
19277
19688
|
import { join as join15 } from "path";
|
|
19278
19689
|
init_platform();
|
|
19279
|
-
var
|
|
19690
|
+
var log41 = forComponent("remote-trigger");
|
|
19280
19691
|
var TRIGGER_DIR = () => join15(homedir9(), ".agent", "triggers");
|
|
19281
19692
|
var sockPath = (sessionId, dir = TRIGGER_DIR()) => join15(dir, `${sessionId}.sock`);
|
|
19282
19693
|
var TriggerServer = class {
|
|
@@ -19314,13 +19725,13 @@ var TriggerServer = class {
|
|
|
19314
19725
|
conn.end(JSON.stringify({ ok: false, error: String(e) }) + "\n");
|
|
19315
19726
|
}
|
|
19316
19727
|
});
|
|
19317
|
-
conn.on("error", (e) =>
|
|
19728
|
+
conn.on("error", (e) => log41.debug("trigger conn error", e));
|
|
19318
19729
|
});
|
|
19319
|
-
this.server.on("error", (e) =>
|
|
19730
|
+
this.server.on("error", (e) => log41.debug("trigger server error", e));
|
|
19320
19731
|
this.server.listen(p);
|
|
19321
19732
|
this.path = p;
|
|
19322
19733
|
} catch (e) {
|
|
19323
|
-
|
|
19734
|
+
log41.debug("trigger server unavailable", e);
|
|
19324
19735
|
}
|
|
19325
19736
|
}
|
|
19326
19737
|
/** Re-bind on /resume (the session id changed). */
|
|
@@ -19452,7 +19863,7 @@ var strike = C("9");
|
|
|
19452
19863
|
var link = (text, url) => useColor ? `\x1B]8;;${url}\x1B\\${cyan(text)}\x1B]8;;\x1B\\` : `${text} (${url})`;
|
|
19453
19864
|
var mdPalette = { bold, dim, cyan, italic, strike, green, link };
|
|
19454
19865
|
var err = (s) => process.stderr.write(s);
|
|
19455
|
-
var
|
|
19866
|
+
var log42 = forComponent("cli");
|
|
19456
19867
|
var VERSION = (() => {
|
|
19457
19868
|
try {
|
|
19458
19869
|
return JSON.parse(readFileSync10(new URL("../package.json", import.meta.url), "utf8")).version ?? "?";
|
|
@@ -19624,6 +20035,7 @@ function parseArgs(argv) {
|
|
|
19624
20035
|
else if (x === "--disallowedTools" || x === "--disallowed-tools") a.disallowedTools = val(++i, x).split(",").map((s) => s.trim()).filter(Boolean);
|
|
19625
20036
|
else if (x === "--append-system-prompt") a.appendSystemPrompt = val(++i, x);
|
|
19626
20037
|
else if (x === "--voice-system-prompt") a.voiceSystemPrompt = val(++i, x);
|
|
20038
|
+
else if (x === "--voice-persona") a.voicePersona = readPersona(val(++i, x));
|
|
19627
20039
|
else if (x === "--add-dir") (a.addDirs ??= []).push(val(++i, x));
|
|
19628
20040
|
else if (x === "--mcp-config") a.mcpConfig = val(++i, x);
|
|
19629
20041
|
else if (x === "--reasoning") a.reasoning = parseReasoning(val(++i, x));
|
|
@@ -19659,6 +20071,8 @@ function parseArgs(argv) {
|
|
|
19659
20071
|
if (a.channelOnly && !a.inputFormat) throw new Error("--channel-only needs --input-format stream-json --output-format stream-json");
|
|
19660
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)");
|
|
19661
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;
|
|
19662
20076
|
if (a.call && a.inputFormat) throw new Error("--call is interactive (mic/TTS here); a headless host runs --channel-only");
|
|
19663
20077
|
if (a.channelMode && !a.duplexV2 && !a.channelOnly && !a.call) throw new Error("--channel-mode only applies with --duplex-v2 or --channel-only");
|
|
19664
20078
|
a.channelMode ??= parseChannelMode(process.env.AGENTX_CHANNEL_MODE);
|
|
@@ -19720,6 +20134,8 @@ Flags:
|
|
|
19720
20134
|
enter the agent's history (headless: stdin interim/pause/agent_state, stdout channel)
|
|
19721
20135
|
--channel-only headless (--input-format stream-json): ONLY the second channel, for a host whose main
|
|
19722
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)
|
|
19723
20139
|
--channel-mode <m> second-channel talkativeness: turn (only a bridge when the answer is slow) | normal
|
|
19724
20140
|
(default) | chatty (frequent cues + content reactions; needs echo cancellation)
|
|
19725
20141
|
env fallback: AGENTX_CHANNEL_MODE
|
|
@@ -20349,7 +20765,7 @@ function turnCost(model, usage) {
|
|
|
20349
20765
|
const priced = model.startsWith("claude-code/") ? `anthropic/${resolveModelAlias(model.slice("claude-code/".length))}` : model;
|
|
20350
20766
|
return costOf(getModelInfo(priced)?.pricing, usage?.promptTokens ?? 0, usage?.completionTokens ?? 0, usage?.cacheCreationTokens ?? 0, usage?.cacheReadTokens ?? 0, priced);
|
|
20351
20767
|
}
|
|
20352
|
-
async function evaluateGoal(ai, condition, transcript,
|
|
20768
|
+
async function evaluateGoal(ai, condition, transcript, log43) {
|
|
20353
20769
|
const recent = transcript.filter((m) => m.role === "assistant").slice(-8).map((m) => {
|
|
20354
20770
|
const text = typeof m.content === "string" ? m.content : m.content.filter((p) => p.type === "text").map((p) => p.text).join(" ");
|
|
20355
20771
|
return text.slice(0, 600);
|
|
@@ -20369,7 +20785,7 @@ ${recent}` }
|
|
|
20369
20785
|
const match = r.content.match(/\{[\s\S]*\}/);
|
|
20370
20786
|
if (match) return JSON.parse(match[0]);
|
|
20371
20787
|
} catch (e) {
|
|
20372
|
-
|
|
20788
|
+
log43(dim(` (goal evaluator error: ${e?.message ?? e})
|
|
20373
20789
|
`));
|
|
20374
20790
|
}
|
|
20375
20791
|
return { met: false, reason: "evaluation unclear" };
|
|
@@ -20597,7 +21013,7 @@ function mcpAgentTools(mounted, opts) {
|
|
|
20597
21013
|
return tools;
|
|
20598
21014
|
}
|
|
20599
21015
|
async function closeMcp(mounted) {
|
|
20600
|
-
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))));
|
|
20601
21017
|
}
|
|
20602
21018
|
var IMG_EXT = { ".png": "image/png", ".jpg": "image/jpeg", ".jpeg": "image/jpeg", ".gif": "image/gif", ".webp": "image/webp" };
|
|
20603
21019
|
function mentionRefs(line) {
|
|
@@ -20656,7 +21072,7 @@ async function expandMentions(fs, line) {
|
|
|
20656
21072
|
if (loaded.includes(ref) || missing.includes(ref)) continue;
|
|
20657
21073
|
if (ref.includes(":") && mcpMentionResolver) {
|
|
20658
21074
|
const body = await mcpMentionResolver(ref).catch((e) => {
|
|
20659
|
-
|
|
21075
|
+
log42.debug("mcp mention resolve failed", e);
|
|
20660
21076
|
return null;
|
|
20661
21077
|
});
|
|
20662
21078
|
if (body != null) {
|
|
@@ -20682,7 +21098,7 @@ ${await fs.readFile(path)}`);
|
|
|
20682
21098
|
${blocks.join("\n\n")}` : line, loaded, missing };
|
|
20683
21099
|
}
|
|
20684
21100
|
function applyTurnMode(agent, session, task, flags = {}, onModel) {
|
|
20685
|
-
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) });
|
|
20686
21102
|
const d = p.directives, isMode = !!(d.delegate || d.advisor || d.modeOff);
|
|
20687
21103
|
if (p.unresolvedModel && /->|<-|delegate:|advisor:/.test(task.slice(0, task.length - p.prompt.length))) {
|
|
20688
21104
|
err(red(` \u2717 unknown model "${p.unresolvedModel}"${p.ambiguous ? ` (could be: ${p.ambiguous.join(", ")})` : ""} \u2014 turn not sent
|
|
@@ -20775,7 +21191,7 @@ async function runTurn(agent, store, session, task, cp, cwd = process.cwd(), sen
|
|
|
20775
21191
|
try {
|
|
20776
21192
|
store.save(session);
|
|
20777
21193
|
} catch (ex) {
|
|
20778
|
-
|
|
21194
|
+
log42.debug("mid-turn session flush failed", ex);
|
|
20779
21195
|
}
|
|
20780
21196
|
}
|
|
20781
21197
|
return origNotify(e);
|
|
@@ -20939,14 +21355,14 @@ var isCancelTeardown = (e) => {
|
|
|
20939
21355
|
function installCancelGuards(mounted) {
|
|
20940
21356
|
process.on("unhandledRejection", (e) => {
|
|
20941
21357
|
if (isCancelTeardown(e)) {
|
|
20942
|
-
|
|
21358
|
+
log42.debug("suppressed unhandledRejection (cursor stream cancel)", e);
|
|
20943
21359
|
return;
|
|
20944
21360
|
}
|
|
20945
|
-
|
|
21361
|
+
log42.error("unhandledRejection", e);
|
|
20946
21362
|
});
|
|
20947
21363
|
process.on("uncaughtException", (e) => {
|
|
20948
21364
|
if (isCancelTeardown(e)) {
|
|
20949
|
-
|
|
21365
|
+
log42.debug("suppressed uncaughtException (cursor stream cancel)", e);
|
|
20950
21366
|
return;
|
|
20951
21367
|
}
|
|
20952
21368
|
console.error(e);
|
|
@@ -21273,7 +21689,7 @@ async function repl(args, ai, cfg, cwd) {
|
|
|
21273
21689
|
let callChain = Promise.resolve();
|
|
21274
21690
|
const callTurns = /* @__PURE__ */ new Map();
|
|
21275
21691
|
if (args.call) {
|
|
21276
|
-
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);
|
|
21277
21693
|
if (args.voiceSystemPrompt) agent.options.systemPrompt += "\n\n" + args.voiceSystemPrompt;
|
|
21278
21694
|
call = new VoiceCall({
|
|
21279
21695
|
ai,
|
|
@@ -21315,7 +21731,7 @@ async function repl(args, ai, cfg, cwd) {
|
|
|
21315
21731
|
editorRef?.abort();
|
|
21316
21732
|
}
|
|
21317
21733
|
} catch (e) {
|
|
21318
|
-
|
|
21734
|
+
log42.error("call turn failed", e);
|
|
21319
21735
|
} finally {
|
|
21320
21736
|
rec.running = false;
|
|
21321
21737
|
call?.main({ type: "done", id });
|
|
@@ -21447,7 +21863,7 @@ async function repl(args, ai, cfg, cwd) {
|
|
|
21447
21863
|
try {
|
|
21448
21864
|
mkdirSync12(dir, { recursive: true });
|
|
21449
21865
|
} catch (e) {
|
|
21450
|
-
|
|
21866
|
+
log42.debug("paste image dir create failed", e);
|
|
21451
21867
|
}
|
|
21452
21868
|
const img = grabClipboardImage(dir, String(Date.now()));
|
|
21453
21869
|
return img ? { display: "Image", ref: "@" + img.path, path: img.path } : null;
|
|
@@ -21560,7 +21976,7 @@ Added entries are loadable now via the Skill/SlashCommand tools; removed ones ar
|
|
|
21560
21976
|
mkdirSync12(join16(cwd, ".agent"), { recursive: true });
|
|
21561
21977
|
appendFileSync(histPath, line + "\n");
|
|
21562
21978
|
} catch (e) {
|
|
21563
|
-
|
|
21979
|
+
log42.debug("history write failed", e);
|
|
21564
21980
|
}
|
|
21565
21981
|
};
|
|
21566
21982
|
const ago = (t) => {
|
|
@@ -21632,7 +22048,7 @@ Added entries are loadable now via the Skill/SlashCommand tools; removed ones ar
|
|
|
21632
22048
|
try {
|
|
21633
22049
|
store.save(session);
|
|
21634
22050
|
} catch (e) {
|
|
21635
|
-
|
|
22051
|
+
log42.debug("session save after rewind failed", e);
|
|
21636
22052
|
}
|
|
21637
22053
|
err(green(" \u27F2 jumped back") + dim(` \u2014 ${face.transcript.length} message(s) kept; edit + resend
|
|
21638
22054
|
`));
|
|
@@ -21667,7 +22083,7 @@ ${task}`;
|
|
|
21667
22083
|
bangContext.length = 0;
|
|
21668
22084
|
}
|
|
21669
22085
|
const delta = await refreshCatalogs().catch((e) => {
|
|
21670
|
-
|
|
22086
|
+
log42.debug("catalog refresh failed", e);
|
|
21671
22087
|
return "";
|
|
21672
22088
|
});
|
|
21673
22089
|
if (delta) {
|
|
@@ -21937,7 +22353,7 @@ ${task}`;
|
|
|
21937
22353
|
desc: "rescan skills/commands dirs and rebuild the system prompt (one cache miss) \u2014 picks up entries created mid-session",
|
|
21938
22354
|
run: async () => {
|
|
21939
22355
|
await refreshCatalogs().catch((e) => {
|
|
21940
|
-
|
|
22356
|
+
log42.debug("catalog refresh failed", e);
|
|
21941
22357
|
});
|
|
21942
22358
|
face.reprepare();
|
|
21943
22359
|
err(green(` \u2713 reloaded \u2014 ${skills.length} skill(s), ${cmds.length} command(s); system prompt rebuilds on next message
|
|
@@ -22440,7 +22856,7 @@ ${task}`;
|
|
|
22440
22856
|
try {
|
|
22441
22857
|
for (const def of (await loadAgents(fs2, d)).agents) if (!seen.has(def.name)) seen.set(def.name, { def, from: d });
|
|
22442
22858
|
} catch (e) {
|
|
22443
|
-
|
|
22859
|
+
log42.debug(`loadAgents(${d}) failed`, e);
|
|
22444
22860
|
}
|
|
22445
22861
|
}
|
|
22446
22862
|
if (!seen.size) {
|
|
@@ -22528,7 +22944,7 @@ ${task}`;
|
|
|
22528
22944
|
}
|
|
22529
22945
|
if (idx >= 0) {
|
|
22530
22946
|
const old = mounted.splice(idx, 1)[0];
|
|
22531
|
-
await old.client.close().catch((e) =>
|
|
22947
|
+
await old.client.close().catch((e) => log42.debug("mcp close failed", e));
|
|
22532
22948
|
}
|
|
22533
22949
|
try {
|
|
22534
22950
|
const m = await mountMcpServer(name, conf);
|
|
@@ -22556,7 +22972,7 @@ ${task}`;
|
|
|
22556
22972
|
}
|
|
22557
22973
|
const m = mounted.splice(idx, 1)[0];
|
|
22558
22974
|
remountMcpTools();
|
|
22559
|
-
await m.client.close().catch((e) =>
|
|
22975
|
+
await m.client.close().catch((e) => log42.debug("mcp close failed", e));
|
|
22560
22976
|
err(dim(` removed "${name}"
|
|
22561
22977
|
`));
|
|
22562
22978
|
return;
|
|
@@ -22759,7 +23175,7 @@ ${task}`;
|
|
|
22759
23175
|
try {
|
|
22760
23176
|
return readdirSync4(join16(cwd, absDir.replace(/^\/+/, "")), { withFileTypes: true }).map((d) => ({ name: d.name, dir: d.isDirectory() }));
|
|
22761
23177
|
} catch (e) {
|
|
22762
|
-
|
|
23178
|
+
log42.debug("completion readdir failed", absDir, e);
|
|
22763
23179
|
return null;
|
|
22764
23180
|
}
|
|
22765
23181
|
};
|
|
@@ -22898,7 +23314,7 @@ ${out}
|
|
|
22898
23314
|
return;
|
|
22899
23315
|
}
|
|
22900
23316
|
await refreshCatalogs().catch((e) => {
|
|
22901
|
-
|
|
23317
|
+
log42.debug("catalog refresh failed", e);
|
|
22902
23318
|
});
|
|
22903
23319
|
const sk = skills.find((x) => x.name === name);
|
|
22904
23320
|
if (sk) {
|
|
@@ -22935,6 +23351,11 @@ ${out}
|
|
|
22935
23351
|
let partialRedraw = null;
|
|
22936
23352
|
const startVoice = async (greet) => {
|
|
22937
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
|
+
}
|
|
22938
23359
|
if (!(duplex || call) || !process.stdin.isTTY) {
|
|
22939
23360
|
err(dim(" (voice needs --call on a TTY)\n"));
|
|
22940
23361
|
return false;
|
|
@@ -23023,7 +23444,7 @@ ${out}
|
|
|
23023
23444
|
if (delivery || cut) dx?.parkCutDelivery(delivery, !!cut, heard);
|
|
23024
23445
|
const cutReply = cut && cut.full.length - cut.heard.length > 40 ? cut : null;
|
|
23025
23446
|
const noteP = replaces ? replaces.note : !cutReply ? Promise.resolve("") : (instinct ? instinct.bargeIntent(text).catch((e) => {
|
|
23026
|
-
|
|
23447
|
+
log42.warn(`barge intent failed \u2014 model decides: ${e.message}`);
|
|
23027
23448
|
return void 0;
|
|
23028
23449
|
}) : Promise.resolve(void 0)).then(async (intent) => interruptionNote(cutReply, intent) + ackedNote(await instinct?.ackFor(text)));
|
|
23029
23450
|
const cutIn = replaces ? replaces.cutIn : interjectNote;
|
|
@@ -23149,7 +23570,7 @@ ${out}
|
|
|
23149
23570
|
if (greet) {
|
|
23150
23571
|
const where = cwd.split("/").pop();
|
|
23151
23572
|
const resumed = session.messages.length > 0;
|
|
23152
|
-
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.`;
|
|
23153
23574
|
void turn(prompt).finally(() => editorRef?.redrawNow());
|
|
23154
23575
|
}
|
|
23155
23576
|
return true;
|
|
@@ -23387,6 +23808,16 @@ function duplexError(e, reflexModel) {
|
|
|
23387
23808
|
const code = e?.statusCode;
|
|
23388
23809
|
return code && !msg.includes(String(code)) ? `${msg} (${code})` : msg;
|
|
23389
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
|
+
}
|
|
23390
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.`;
|
|
23391
23822
|
var HOLD_RESUME_MS = 4e3;
|
|
23392
23823
|
var leakDecider = () => voiceDecider();
|
|
@@ -23397,15 +23828,24 @@ function channelOptions(ai, model, gender) {
|
|
|
23397
23828
|
const decider = leakDecider();
|
|
23398
23829
|
const instinct = decider ? new Instinct({ decider }) : void 0;
|
|
23399
23830
|
const planner = new BackchannelPlanner(ai, { model });
|
|
23831
|
+
const grower = new ConvoTreeGrower(ai, { ...process.env.AGENTX_TREE_MODEL ? { model: process.env.AGENTX_TREE_MODEL } : {} });
|
|
23400
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
|
+
},
|
|
23401
23842
|
// Banks in the user's language: generated once per language, cached + topped up across sessions (~/.agent/cache).
|
|
23402
23843
|
banks: new ChannelBanks({ generate: fastBankGenerator(ai, model), cacheDir: join16(homedir10(), ".agent", "cache", "channel-banks") }),
|
|
23403
23844
|
decide: channelDecide(ai, instinct),
|
|
23404
23845
|
generate: fastLineGenerator(ai, model, gender),
|
|
23405
23846
|
// Anticipated backchannels: on in chatty mode (its preset), else off until the offline replay proves them (tests/voice-bc-anticipate-eval.ts)
|
|
23406
23847
|
plan: (c, s) => planner.plan(c, s),
|
|
23407
|
-
...process.env.AGENTX_CHANNEL_ANTICIPATE === "1" ? { anticipate: true } : {}
|
|
23408
|
-
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 } : {}
|
|
23409
23849
|
};
|
|
23410
23850
|
}
|
|
23411
23851
|
function overlapResponder(ai, mode, out, aside) {
|
|
@@ -23467,7 +23907,10 @@ async function duplexServe(args, ai, cfg, cwd) {
|
|
|
23467
23907
|
});
|
|
23468
23908
|
if (args.voiceSystemPrompt) dx.voice.options.systemPrompt += "\n\n" + args.voiceSystemPrompt;
|
|
23469
23909
|
let scTurn = 0;
|
|
23470
|
-
const sc = args.duplexV2 ? makeSecondChannel(ai, dx.options.reflexModel, args.channelMode, {
|
|
23910
|
+
const sc = args.duplexV2 ? makeSecondChannel(ai, dx.options.reflexModel, args.channelMode, { speak: (line, kind) => {
|
|
23911
|
+
out(channelLine(line, kind));
|
|
23912
|
+
return true;
|
|
23913
|
+
} }) : void 0;
|
|
23471
23914
|
const store = new SessionStore(cwd);
|
|
23472
23915
|
const session = startSession(args, store, dx.voice, cwd);
|
|
23473
23916
|
persist = () => {
|
|
@@ -23476,7 +23919,7 @@ async function duplexServe(args, ai, cfg, cwd) {
|
|
|
23476
23919
|
try {
|
|
23477
23920
|
store.save(session);
|
|
23478
23921
|
} catch (e) {
|
|
23479
|
-
|
|
23922
|
+
log42.warn("duplex session save failed", e);
|
|
23480
23923
|
}
|
|
23481
23924
|
};
|
|
23482
23925
|
const overlap2 = overlapResponder(ai, args.duplexV2 ? args.channelMode : void 0, out);
|
|
@@ -23516,7 +23959,7 @@ async function duplexServe(args, ai, cfg, cwd) {
|
|
|
23516
23959
|
done2();
|
|
23517
23960
|
out({ type: "turn_done", id, finishReason: res?.finishReason ?? "error", ...why ? { error: why } : {} });
|
|
23518
23961
|
}).catch((e) => {
|
|
23519
|
-
|
|
23962
|
+
log42.error("duplex turn failed", e);
|
|
23520
23963
|
done2();
|
|
23521
23964
|
out({ type: "turn_done", id, finishReason: "error", error: String(e?.message ?? e) });
|
|
23522
23965
|
});
|
|
@@ -23538,12 +23981,16 @@ async function channelServe(args, ai, cfg) {
|
|
|
23538
23981
|
fastModel: model,
|
|
23539
23982
|
mode: args.channelMode,
|
|
23540
23983
|
gender: args.voiceGender ?? "",
|
|
23541
|
-
|
|
23542
|
-
|
|
23543
|
-
|
|
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 }) },
|
|
23987
|
+
speak: (line, kind) => {
|
|
23988
|
+
out(channelLine(line, kind));
|
|
23989
|
+
return true;
|
|
23990
|
+
},
|
|
23991
|
+
// the host plays {type:'channel'} lines: `speech` keeps the tags, `text` shows
|
|
23544
23992
|
hostAudio: true,
|
|
23545
23993
|
// …and says when one really plays ({type:'heard'}) — a line its player drops never counts as sound
|
|
23546
|
-
show: (text, kind) => out({ type: "channel", kind, text }),
|
|
23547
23994
|
sendTurn: (text, o) => out({ type: "turn", id: o.id, text, ...o.replaces ? { replaces: o.replaces } : {} }),
|
|
23548
23995
|
abortTurn: (id) => out({ type: "abort", id }),
|
|
23549
23996
|
onMetric: (m) => {
|