@livx.cc/agentx 0.99.57 → 0.99.58
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.d.ts +7 -0
- package/dist/cli.js +2074 -302
- package/dist/cli.js.map +1 -1
- package/dist/index.d.ts +167 -29
- package/dist/index.js +1472 -186
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/cli.js
CHANGED
|
@@ -2561,7 +2561,7 @@ async function psGroupCpuSeconds(pgid) {
|
|
|
2561
2561
|
const out = await new Promise((res, rej) => execFile4("ps", ["-A", "-o", "pid=,ppid=,pgid=,time="], { timeout: 5e3, env: { ...process.env, LC_ALL: "C" } }, (e, so) => e ? rej(e) : res(String(so))));
|
|
2562
2562
|
return sumTreeCpu(out, pgid);
|
|
2563
2563
|
} catch (e) {
|
|
2564
|
-
|
|
2564
|
+
log22.debug(`ps cpu probe failed for group ${pgid}: ${e}`);
|
|
2565
2565
|
return void 0;
|
|
2566
2566
|
}
|
|
2567
2567
|
}
|
|
@@ -2693,7 +2693,7 @@ function makeRealShellTool(options) {
|
|
|
2693
2693
|
proc.stdout?.off?.("data", collect);
|
|
2694
2694
|
proc.stderr?.off?.("data", collect);
|
|
2695
2695
|
const id = registry.adopt(cmd, proc, out);
|
|
2696
|
-
finish(handoffFor(timeoutMs, id,
|
|
2696
|
+
finish(handoffFor(timeoutMs, id, clean2(out), !!registry.notifiesOnExit));
|
|
2697
2697
|
};
|
|
2698
2698
|
}
|
|
2699
2699
|
const collect = (chunk) => {
|
|
@@ -2708,14 +2708,14 @@ function makeRealShellTool(options) {
|
|
|
2708
2708
|
proc.stdout?.on("data", collect);
|
|
2709
2709
|
proc.stderr?.on("data", collect);
|
|
2710
2710
|
proc.on("error", (err2) => {
|
|
2711
|
-
if (err2?.name === "AbortError" || ctl.signal.aborted) return finish(reasonFor(timedOut, timeoutMs,
|
|
2712
|
-
|
|
2713
|
-
finish(`[exit 1] ${err2?.message ?? err2}${out ? "\n" +
|
|
2711
|
+
if (err2?.name === "AbortError" || ctl.signal.aborted) return finish(reasonFor(timedOut, timeoutMs, clean2(out)));
|
|
2712
|
+
log22.debug("shell spawn error", err2);
|
|
2713
|
+
finish(`[exit 1] ${err2?.message ?? err2}${out ? "\n" + clean2(out) : ""}`);
|
|
2714
2714
|
});
|
|
2715
2715
|
proc.on("close", (code) => {
|
|
2716
2716
|
flushEmit(ctx);
|
|
2717
|
-
if (ctl.signal.aborted) return finish(reasonFor(timedOut, timeoutMs,
|
|
2718
|
-
const body =
|
|
2717
|
+
if (ctl.signal.aborted) return finish(reasonFor(timedOut, timeoutMs, clean2(out)));
|
|
2718
|
+
const body = clean2(out);
|
|
2719
2719
|
if (code && code !== 0) return finish(`[exit ${code}]${body ? "\n" + body : ""}`);
|
|
2720
2720
|
finish(body || "(command succeeded, no output)");
|
|
2721
2721
|
});
|
|
@@ -2754,7 +2754,7 @@ function makeShellJobTools(registry) {
|
|
|
2754
2754
|
if (out == null) return NO_JOB2(String(id));
|
|
2755
2755
|
const st = registry.status(String(id));
|
|
2756
2756
|
return `[${st.status}${st.exitCode != null ? ` exit ${st.exitCode}` : ""}${st.reason ? `: ${st.reason}` : ""}]
|
|
2757
|
-
${
|
|
2757
|
+
${clean2(out) || "(no output yet)"}`;
|
|
2758
2758
|
}
|
|
2759
2759
|
},
|
|
2760
2760
|
{
|
|
@@ -2782,7 +2782,7 @@ ${clean(out) || "(no output yet)"}`;
|
|
|
2782
2782
|
}
|
|
2783
2783
|
];
|
|
2784
2784
|
}
|
|
2785
|
-
var
|
|
2785
|
+
var log22, clean2, DETACHED, SECRET_ENV_RE, _spawn, ShellJobRegistry, shellStatus, NO_JOB2;
|
|
2786
2786
|
var init_tools_shell = __esm({
|
|
2787
2787
|
"src/tools.shell.ts"() {
|
|
2788
2788
|
"use strict";
|
|
@@ -2791,8 +2791,8 @@ var init_tools_shell = __esm({
|
|
|
2791
2791
|
init_logging();
|
|
2792
2792
|
init_shell_sandbox();
|
|
2793
2793
|
init_tools_jobs();
|
|
2794
|
-
|
|
2795
|
-
|
|
2794
|
+
log22 = forComponent("shell");
|
|
2795
|
+
clean2 = (s) => truncateOutput(redactSecrets(s.replace(/\n+$/, "")));
|
|
2796
2796
|
DETACHED = { stdio: ["ignore", "pipe", "pipe"], detached: true };
|
|
2797
2797
|
SECRET_ENV_RE = /(_API_KEY|_TOKEN|_SECRET|_PASSWORD|_PRIVATE_KEY|^AWS_|^GITHUB_TOKEN$|^OPENAI_|^ANTHROPIC_|^GOOGLE_|^GEMINI_|^GROQ_|^NPM_TOKEN$)/i;
|
|
2798
2798
|
ShellJobRegistry = class {
|
|
@@ -2877,7 +2877,7 @@ var init_tools_shell = __esm({
|
|
|
2877
2877
|
notifyExit(id, meta, status, reason) {
|
|
2878
2878
|
if (!this.cfg.onExit || status === "killed" && !reason?.startsWith("stuck")) return;
|
|
2879
2879
|
try {
|
|
2880
|
-
this.cfg.onExit({ id, command: meta.command, status: shellStatus(status), exitCode: meta.exitCode, tail:
|
|
2880
|
+
this.cfg.onExit({ id, command: meta.command, status: shellStatus(status), exitCode: meta.exitCode, tail: clean2(this.jobs.output(id) ?? "").slice(-4e3), ...reason && status !== "done" ? { reason } : {} });
|
|
2881
2881
|
} catch {
|
|
2882
2882
|
}
|
|
2883
2883
|
}
|
|
@@ -2939,7 +2939,7 @@ var init_tools_shell = __esm({
|
|
|
2939
2939
|
|
|
2940
2940
|
// cli/cli.ts
|
|
2941
2941
|
import { createInterface } from "readline/promises";
|
|
2942
|
-
import { existsSync as existsSync9, readFileSync as readFileSync9, appendFileSync, mkdirSync as mkdirSync12, writeFileSync as writeFileSync9, readdirSync as readdirSync4, statSync as
|
|
2942
|
+
import { existsSync as existsSync9, readFileSync as readFileSync9, appendFileSync, mkdirSync as mkdirSync12, writeFileSync as writeFileSync9, readdirSync as readdirSync4, statSync as statSync6, unlinkSync as unlinkSync5 } from "fs";
|
|
2943
2943
|
import { homedir as homedir10 } from "os";
|
|
2944
2944
|
import { spawnSync as spawnSync6 } from "child_process";
|
|
2945
2945
|
|
|
@@ -3009,7 +3009,7 @@ function copyTextToClipboard(text, platform2 = process.platform) {
|
|
|
3009
3009
|
|
|
3010
3010
|
// cli/cli.ts
|
|
3011
3011
|
import { join as join14, resolve as resolve4, basename as basename2, extname, dirname as dirname5 } from "path";
|
|
3012
|
-
import { AIClient, listModels, listProviders, getProviderFromModel, getModelInfo, resolveModel, isModelSupported, disposeCursorSessions, disposeClaudeCodeSessions } from "ai.libx.js";
|
|
3012
|
+
import { AIClient, DecideClient, listModels, listProviders, getProviderFromModel, getModelInfo, resolveModel, isModelSupported, disposeCursorSessions, disposeClaudeCodeSessions } from "ai.libx.js";
|
|
3013
3013
|
|
|
3014
3014
|
// src/Agent.ts
|
|
3015
3015
|
init_llm();
|
|
@@ -5524,14 +5524,14 @@ function summarize(messages, focus) {
|
|
|
5524
5524
|
if (lastAssistant) lines.push(`last assistant: ${lastAssistant}`);
|
|
5525
5525
|
if (carried.length) lines.push("earlier recap:", ...carried.map((l) => ` ${l}`));
|
|
5526
5526
|
if (focus?.trim()) {
|
|
5527
|
-
const
|
|
5527
|
+
const words2 = focus.toLowerCase().split(/\s+/).filter((w) => w.length > 2);
|
|
5528
5528
|
const kept = [];
|
|
5529
5529
|
const ordered = [...messages.filter((m) => !isSyntheticSummary(m)), ...messages.filter(isSyntheticSummary)];
|
|
5530
5530
|
outer: for (const msg of ordered) {
|
|
5531
5531
|
if (msg.role === "tool") continue;
|
|
5532
5532
|
for (const line of contentText(msg.content).split("\n")) {
|
|
5533
5533
|
const l = line.toLowerCase();
|
|
5534
|
-
if (line.trim() &&
|
|
5534
|
+
if (line.trim() && words2.some((w) => l.includes(w))) {
|
|
5535
5535
|
kept.push(line.trim().slice(0, 200));
|
|
5536
5536
|
if (kept.length >= 12) break outer;
|
|
5537
5537
|
}
|
|
@@ -6489,6 +6489,130 @@ var EmotionStream = class {
|
|
|
6489
6489
|
}
|
|
6490
6490
|
};
|
|
6491
6491
|
|
|
6492
|
+
// node_modules/@bod.ee/voice/src/core/endpointing.ts
|
|
6493
|
+
var INCOMPLETE_ENDINGS = /* @__PURE__ */ new Set([
|
|
6494
|
+
// Conjunctions
|
|
6495
|
+
"and",
|
|
6496
|
+
"but",
|
|
6497
|
+
"or",
|
|
6498
|
+
"so",
|
|
6499
|
+
"because",
|
|
6500
|
+
"although",
|
|
6501
|
+
"though",
|
|
6502
|
+
"while",
|
|
6503
|
+
"since",
|
|
6504
|
+
"unless",
|
|
6505
|
+
"if",
|
|
6506
|
+
"when",
|
|
6507
|
+
"where",
|
|
6508
|
+
// Prepositions
|
|
6509
|
+
"to",
|
|
6510
|
+
"for",
|
|
6511
|
+
"with",
|
|
6512
|
+
"about",
|
|
6513
|
+
"of",
|
|
6514
|
+
"at",
|
|
6515
|
+
"in",
|
|
6516
|
+
"on",
|
|
6517
|
+
"from",
|
|
6518
|
+
"by",
|
|
6519
|
+
"into",
|
|
6520
|
+
"through",
|
|
6521
|
+
// Articles / determiners
|
|
6522
|
+
"the",
|
|
6523
|
+
"a",
|
|
6524
|
+
"an",
|
|
6525
|
+
"this",
|
|
6526
|
+
"that",
|
|
6527
|
+
"these",
|
|
6528
|
+
"those",
|
|
6529
|
+
"my",
|
|
6530
|
+
"your",
|
|
6531
|
+
"his",
|
|
6532
|
+
"her",
|
|
6533
|
+
"our",
|
|
6534
|
+
"their",
|
|
6535
|
+
// Bare pronouns ("…as I asked it" — the live case above)
|
|
6536
|
+
"i",
|
|
6537
|
+
"you",
|
|
6538
|
+
"we",
|
|
6539
|
+
"they",
|
|
6540
|
+
"he",
|
|
6541
|
+
"she",
|
|
6542
|
+
"it",
|
|
6543
|
+
// Fillers (thinking)
|
|
6544
|
+
"um",
|
|
6545
|
+
"uh",
|
|
6546
|
+
"like",
|
|
6547
|
+
"well"
|
|
6548
|
+
]);
|
|
6549
|
+
var CONTINUATION_MARKERS = [
|
|
6550
|
+
"you know",
|
|
6551
|
+
"i mean",
|
|
6552
|
+
"the thing is",
|
|
6553
|
+
"let me think",
|
|
6554
|
+
"first of all",
|
|
6555
|
+
"on one hand",
|
|
6556
|
+
"for example"
|
|
6557
|
+
];
|
|
6558
|
+
var COMPLETE_ENDINGS = /* @__PURE__ */ new Set([
|
|
6559
|
+
"yeah",
|
|
6560
|
+
"yes",
|
|
6561
|
+
"no",
|
|
6562
|
+
"nah",
|
|
6563
|
+
"okay",
|
|
6564
|
+
"ok",
|
|
6565
|
+
"sure",
|
|
6566
|
+
"right",
|
|
6567
|
+
"thanks",
|
|
6568
|
+
"bye",
|
|
6569
|
+
"absolutely",
|
|
6570
|
+
"definitely",
|
|
6571
|
+
"exactly",
|
|
6572
|
+
"correct",
|
|
6573
|
+
"true",
|
|
6574
|
+
"false"
|
|
6575
|
+
]);
|
|
6576
|
+
function isTranscriptComplete(text) {
|
|
6577
|
+
const trimmed = text.trim();
|
|
6578
|
+
if (!trimmed) return false;
|
|
6579
|
+
if (/[.?!]$/.test(trimmed)) return true;
|
|
6580
|
+
const words2 = trimmed.toLowerCase().split(/\s+/);
|
|
6581
|
+
const lastWord = words2[words2.length - 1];
|
|
6582
|
+
if (COMPLETE_ENDINGS.has(lastWord)) return true;
|
|
6583
|
+
if (INCOMPLETE_ENDINGS.has(lastWord)) return false;
|
|
6584
|
+
const lower = trimmed.toLowerCase();
|
|
6585
|
+
for (const marker of CONTINUATION_MARKERS) if (lower.endsWith(marker)) return false;
|
|
6586
|
+
if (words2.length <= 2) return false;
|
|
6587
|
+
return true;
|
|
6588
|
+
}
|
|
6589
|
+
var MAX_HOLD_MS = 2e3;
|
|
6590
|
+
var MIN_MERGE_HOLD_MS = 800;
|
|
6591
|
+
function endpointTier(transcript) {
|
|
6592
|
+
const t = transcript.trim();
|
|
6593
|
+
if (!isTranscriptComplete(t)) return 1;
|
|
6594
|
+
return /[.?!]$/.test(t) ? 3 : 2;
|
|
6595
|
+
}
|
|
6596
|
+
function tierHoldMs(tier, ctx) {
|
|
6597
|
+
if (tier === 1) return ctx.incompleteMs;
|
|
6598
|
+
if (tier === 2) return Math.round((ctx.baseMs + ctx.incompleteMs) / 2);
|
|
6599
|
+
return ctx.baseMs;
|
|
6600
|
+
}
|
|
6601
|
+
function computeHoldMs(ctx) {
|
|
6602
|
+
const t = ctx.transcript.trim();
|
|
6603
|
+
const tier = endpointTier(t);
|
|
6604
|
+
let ms = tierHoldMs(tier, ctx);
|
|
6605
|
+
const ai = ctx.lastAiMessage?.trim();
|
|
6606
|
+
if (ai) {
|
|
6607
|
+
if (/\?$/.test(ai)) ms -= 300;
|
|
6608
|
+
if (ai.split(/\s+/).length > 60) ms += 400;
|
|
6609
|
+
}
|
|
6610
|
+
const lastWord = t.toLowerCase().split(/\s+/).pop();
|
|
6611
|
+
if (lastWord === "um" || lastWord === "uh" || lastWord === "hmm") ms += 500;
|
|
6612
|
+
const floor = tier === 3 ? ctx.baseMs : Math.max(ctx.baseMs, Math.min(tierHoldMs(tier, ctx), MIN_MERGE_HOLD_MS));
|
|
6613
|
+
return Math.max(floor, Math.min(MAX_HOLD_MS, ms));
|
|
6614
|
+
}
|
|
6615
|
+
|
|
6492
6616
|
// node_modules/@bod.ee/voice/src/core/engine.ts
|
|
6493
6617
|
var log12 = forComponent2("VoiceEngine");
|
|
6494
6618
|
var realClock = {
|
|
@@ -6497,7 +6621,7 @@ var realClock = {
|
|
|
6497
6621
|
clearTimeout: (h) => clearTimeout(h)
|
|
6498
6622
|
};
|
|
6499
6623
|
var forSpeech = (t) => t.replace(/[*`#]+/g, "").replace(/(?<![\p{L}\p{N}])_([^_\n]+)_(?![\p{L}\p{N}])/gu, "$1").replace(/^[ \t]*[-•]\s+/gm, "").replace(/\s*[\u2013\u2014]\s*/g, ", ").replace(/[\u2010\u2011]/g, "-").replace(/\s*\|\s*/g, ", ").replace(/(\d)\s+%/g, "$1%").replace(/\.{3,}/g, ".");
|
|
6500
|
-
var normWord = (w) => w.toLowerCase().replace(/[
|
|
6624
|
+
var normWord = (w) => w.toLowerCase().replace(/[^\p{L}\p{M}\p{N}]/gu, "");
|
|
6501
6625
|
var SPEC_TRAILING_OK = /* @__PURE__ */ new Set(["please", "thanks", "thank", "you", "now", "okay", "ok", "kindly", "alright", "then", "though", "right", "yeah"]);
|
|
6502
6626
|
function speculationConfirms(spec, final) {
|
|
6503
6627
|
const sw = spec.trim().split(/\s+/).map(normWord).filter(Boolean);
|
|
@@ -6508,11 +6632,27 @@ function speculationConfirms(spec, final) {
|
|
|
6508
6632
|
for (let i = sw.length; i < fw.length; i++) if (!SPEC_TRAILING_OK.has(fw[i])) return false;
|
|
6509
6633
|
return true;
|
|
6510
6634
|
}
|
|
6635
|
+
function heardPrefix(text, spoken, lookahead = 4) {
|
|
6636
|
+
const toks = [...text.matchAll(/\S+/g)];
|
|
6637
|
+
let i = 0, at = 0;
|
|
6638
|
+
for (const w of spoken) {
|
|
6639
|
+
const nw = normWord(w);
|
|
6640
|
+
if (!nw) continue;
|
|
6641
|
+
for (let k = i; k < Math.min(toks.length, i + lookahead); k++)
|
|
6642
|
+
if (normWord(toks[k][0]) === nw) {
|
|
6643
|
+
at = toks[k].index;
|
|
6644
|
+
i = k + 1;
|
|
6645
|
+
break;
|
|
6646
|
+
}
|
|
6647
|
+
}
|
|
6648
|
+
return at;
|
|
6649
|
+
}
|
|
6511
6650
|
var VoiceEngineOptions = class {
|
|
6512
6651
|
stt;
|
|
6513
6652
|
tts;
|
|
6514
6653
|
player;
|
|
6515
|
-
/** a final utterance arrived (endpoint) — host dispatches it as a turn
|
|
6654
|
+
/** a final utterance arrived (endpoint) — host dispatches it as a turn. `meta.supersedes` marks a fuller
|
|
6655
|
+
* re-finalization of the utterance dispatched just before it: replace that turn, don't add one. */
|
|
6516
6656
|
onUtterance = () => {
|
|
6517
6657
|
};
|
|
6518
6658
|
/** live partial transcript while listening (host renders the 🎤 line) */
|
|
@@ -6520,6 +6660,14 @@ var VoiceEngineOptions = class {
|
|
|
6520
6660
|
};
|
|
6521
6661
|
onState = () => {
|
|
6522
6662
|
};
|
|
6663
|
+
/** The assistant's spoken turn finished AUDIBLY — every TTS chunk arrived AND playback drained.
|
|
6664
|
+
* Fires from the same `settle()` that returns the engine to 'listening', just before that state
|
|
6665
|
+
* change. Distinct from the host's `endSpeech()`, which only closes the TEXT stream (audio is
|
|
6666
|
+
* still playing at that point). NOT fired for a turn cut by barge-in — the host gets `onBargeIn`
|
|
6667
|
+
* instead. Also fires for engine-internal speech (adaptive ack, filler, queued utterances), so a
|
|
6668
|
+
* host that only cares about ITS turns should gate on its own open-turn flag. Default no-op. */
|
|
6669
|
+
onSpeechEnd = () => {
|
|
6670
|
+
};
|
|
6523
6671
|
/** user spoke/acted over playback — host aborts the in-flight turn (called AFTER audio is killed).
|
|
6524
6672
|
* phase: 'speaking' = cut mid-speech (real interruption); 'drain' = in the final audio tail
|
|
6525
6673
|
* (normal turn-taking — hosts shouldn't alarm). */
|
|
@@ -6534,6 +6682,14 @@ var VoiceEngineOptions = class {
|
|
|
6534
6682
|
/** the adaptive ack actually fired (host can mark the turn as spoken — e.g. suppress dead-air repair) */
|
|
6535
6683
|
onAdaptiveAck = () => {
|
|
6536
6684
|
};
|
|
6685
|
+
/** HOST-CHOSEN adaptive ack: asked once per armed ack (at beginSpeech(true), i.e. at dispatch) so a slow pick
|
|
6686
|
+
* runs in parallel with the reflex. Return the phrase to speak, or `null` = stay silent this turn. A Promise
|
|
6687
|
+
* still pending when the ack is due gets up to another `adaptiveAckMs` (then the turn stays silent — a wrong
|
|
6688
|
+
* ack is worse than none); a rejection falls back to the default pools. Unset (null) = the engine's own
|
|
6689
|
+
* shape-picked pools (ACKS_NEUTRAL / ACKS_QUESTION). Phrases enter the echo set like the defaults — keep them
|
|
6690
|
+
* short and not a lone word users say on their own ("okay", "yeah"): the ack-squash guard drops a user
|
|
6691
|
+
* utterance that equals the last ack. */
|
|
6692
|
+
pickAck = null;
|
|
6537
6693
|
/** Endpoint merge window (ms): hold an endpointed utterance briefly — if speech resumes (spelled
|
|
6538
6694
|
* letters, mid-thought pauses), the next utterance MERGES instead of dispatching a truncated one
|
|
6539
6695
|
* ("E-L-Y." / "A."). Costs this much latency per turn; 0 disables. */
|
|
@@ -6541,6 +6697,21 @@ var VoiceEngineOptions = class {
|
|
|
6541
6697
|
/** Extended merge window (ms) for utterances that look incomplete (trailing conjunction/filler).
|
|
6542
6698
|
* Gives the user time to finish their thought without triggering a model call. */
|
|
6543
6699
|
incompleteMergeMs = 1500;
|
|
6700
|
+
/** ADAPTIVE endpoint hold (opt-in; default OFF = today's byte-identical two-tier behavior).
|
|
6701
|
+
* The fixed merge tiers (`utteranceMergeMs` vs `incompleteMergeMs`, chosen by a trailing-word
|
|
6702
|
+
* regex, and skipped entirely at ≥4 words) dispatch mid-thought FRAGMENTS as their own turn: live,
|
|
6703
|
+
* "…give me the best" dispatched, got an empty reply, and "…give me the best of it." arrived 766ms
|
|
6704
|
+
* later as a second turn. When true, every endpointed utterance is held for
|
|
6705
|
+
* `computeHoldMs(...)` — sized by linguistic completeness, whether the STT emitted a sentence-final
|
|
6706
|
+
* mark, and what the assistant last said — so the continuation MERGES instead of burning a turn.
|
|
6707
|
+
* COST — this is strictly slower than the default path, never faster: today every ≥4-word utterance
|
|
6708
|
+
* dispatches at 0ms (the fast path below), so adaptive ADDS the whole hold — ~350ms to every
|
|
6709
|
+
* sentence-final utterance, ~925ms to every complete-looking unpunctuated one (the common case),
|
|
6710
|
+
* and up to 2s on a mid-thought fragment. Paid on turns that didn't need it, to stop burning a turn
|
|
6711
|
+
* (empty reply + blank bubble) on the ones that did — hence opt-in. Also changes `onHold` timing:
|
|
6712
|
+
* it now fires on every tier-2/3 hold, not only on `looksIncomplete` (`holdFiller` stays tier-1
|
|
6713
|
+
* only). See core/endpointing.ts. */
|
|
6714
|
+
adaptiveEndpointing = false;
|
|
6544
6715
|
/** Grace window (ms) after an utterance dispatches, during which the user's own trailing audio cannot
|
|
6545
6716
|
* barge the reply it requested. Soniox keeps finalizing partials past <end>; without this they read
|
|
6546
6717
|
* as a barge and abort the fresh turn (live: mid-sentence self-interruption + steps=1→steps=0 double
|
|
@@ -6551,6 +6722,15 @@ var VoiceEngineOptions = class {
|
|
|
6551
6722
|
* while audible (speaking + drain tail), so echo can never become a phantom turn — the right mode
|
|
6552
6723
|
* when there's no AEC (e.g. the non-VPIO mic fallback) and no headphones. Cost: can't interrupt. */
|
|
6553
6724
|
bargeIn = true;
|
|
6725
|
+
/** Which barge-in TIER to run — the host's override of the mic's self-report.
|
|
6726
|
+
* - `'auto'` (default) — trust `stt.usingAec`: AEC tier when the mic reports echo cancellation
|
|
6727
|
+
* applied, heuristic/energy tier otherwise. Unchanged legacy behavior.
|
|
6728
|
+
* - `'aec'` — force the AEC tier (STT stays live through TTS; barge decided by the dominant-novel
|
|
6729
|
+
* gate + overlap pause) even if the mic reports no echo cancellation.
|
|
6730
|
+
* - `'energy'` — force the heuristic tier (echo-baseline EMA spike arms `suspectUntil`, novel-word
|
|
6731
|
+
* count decides; STT buffer reset after our own audio) even if the mic REPORTS echoCancellation.
|
|
6732
|
+
* Mobile Safari reports `true` while cancelling poorly — that report is what this overrides. */
|
|
6733
|
+
bargeInMode = "auto";
|
|
6554
6734
|
/** Filler phrase spoken when holding for an incomplete utterance ('' disables). */
|
|
6555
6735
|
holdFiller = "";
|
|
6556
6736
|
/** Called when the engine holds an incomplete utterance (host can render a visual cue). */
|
|
@@ -6574,6 +6754,15 @@ var VoiceEngineOptions = class {
|
|
|
6574
6754
|
* Mechanism-based discriminator: a re-PAUSE this soon after a resume = a persistent human, not an
|
|
6575
6755
|
* echo blip (which pauses once and stalls). Cede on the re-pause regardless of the novel gate. */
|
|
6576
6756
|
overlapRepauseCedeMs = 1500;
|
|
6757
|
+
/** HOST-DECIDED short overlaps (opt-in; 0 = off = cede on ≥2 genuine words, as always). The fast "≥2 novel words →
|
|
6758
|
+
* cede" rule cannot tell a reaction ("Oh, that's new") from a barge, and it fires ~300ms before a host-side judge
|
|
6759
|
+
* (e.g. an AI instinct) can answer — so a judge could never keep a delivery going (live 20260923-125143: ceded on
|
|
6760
|
+
* "Oh, that", the judge said keep_talking 300ms later). When > 0, a SHORT genuine overlap (≤ overlapDecideMaxWords,
|
|
6761
|
+
* no '?', no stop/question word) keeps the pause and waits for `decideOverlap()`; with no decision after this many
|
|
6762
|
+
* ms it cedes. Long or obvious barges still cede instantly. Audio is already paused, so waiting costs no talk-over. */
|
|
6763
|
+
overlapDecideMs = 0;
|
|
6764
|
+
/** Longest overlap (words) the host decides; also how far an overlap the host kept may grow before it cedes. */
|
|
6765
|
+
overlapDecideMaxWords = 4;
|
|
6577
6766
|
/** Speculative ENERGY pre-pause while speaking (AEC tier): two residue gate-passes within 350ms →
|
|
6578
6767
|
* pause ~300ms before the STT tokens land. But energy CANNOT separate residue bursts from speech
|
|
6579
6768
|
* (the documented whack-a-mole) — so a residue spike during loud playback false-pauses with NO user
|
|
@@ -6626,6 +6815,10 @@ var VoiceEngineOptions = class {
|
|
|
6626
6815
|
* timestamp-emitting TTS (CartesiaTTS.wantTimestamps) driven over `AudioSink.playedMs`.
|
|
6627
6816
|
*/
|
|
6628
6817
|
revealMode = "off";
|
|
6818
|
+
/** Locate EXACTLY what the user heard when a barge cuts speech: request word timestamps from the TTS (when it
|
|
6819
|
+
* supports them) and match them against the playback clock (InterruptedReply `heard`/`exact`). Independent of
|
|
6820
|
+
* `revealMode` — no reveal events. Without timestamps the cut falls back to the ~15 chars/s estimate. */
|
|
6821
|
+
heardTimestamps = true;
|
|
6629
6822
|
/** Called with the cumulative revealed text for the current assistant turn (see `revealMode`).
|
|
6630
6823
|
* Reset to '' at the start of each spoken turn. */
|
|
6631
6824
|
onReveal = () => {
|
|
@@ -6656,8 +6849,27 @@ var VoiceEngine = class _VoiceEngine {
|
|
|
6656
6849
|
// cumulative revealed (on-screen) text for the current turn — see revealMode
|
|
6657
6850
|
// 'word' karaoke reveal: spoken-word start times (sec, absolute from turn-audio start) + poll state.
|
|
6658
6851
|
wordStarts = [];
|
|
6852
|
+
wordTexts = [];
|
|
6853
|
+
// the timestamped words, parallel to wordStarts (heard-cut matching)
|
|
6854
|
+
ackWords = 0;
|
|
6855
|
+
// leading timestamped words that are the ack spoken on this turn's context, not the reply
|
|
6659
6856
|
revealedN = 0;
|
|
6660
6857
|
revealPoll = null;
|
|
6858
|
+
// Sub-turn timestamp anchoring. A TTS context emits word starts relative to ITS OWN audio start, so
|
|
6859
|
+
// `wordStarts` (one flat turn timeline) is only valid while the turn stays on one context. It does
|
|
6860
|
+
// not: `subturnBoundary()` rotates the context, and Cartesia ALSO rotates it on its own (~5s idle
|
|
6861
|
+
// timeout mid tool-call) — after which starts restart at 0 and every remaining word instantly
|
|
6862
|
+
// satisfies the reveal predicate, dumping the whole segment on screen.
|
|
6863
|
+
// Fix is deterministic, not detective: at a boundary we FORCE the rotation ourselves, so the new
|
|
6864
|
+
// context's origin is always known — it is the turn-audio position where its first byte lands,
|
|
6865
|
+
// captured from the sink at that byte (`playedMs + drainMs` = content seconds written so far).
|
|
6866
|
+
// Starts arriving before that byte are held in `wordPending` and rebased when it does.
|
|
6867
|
+
wordOrigin = 0;
|
|
6868
|
+
// sec offset added to incoming starts (0 = first sub-turn)
|
|
6869
|
+
wordAnchorPending = false;
|
|
6870
|
+
// awaiting the new sub-turn's first audio byte
|
|
6871
|
+
wordPending = [];
|
|
6872
|
+
// [word, start] received while pending, rebased on capture
|
|
6661
6873
|
clock;
|
|
6662
6874
|
drainTimer = null;
|
|
6663
6875
|
// heuristic tier state (inert under AEC) — frozen as validated in the experiment
|
|
@@ -6688,6 +6900,8 @@ var VoiceEngine = class _VoiceEngine {
|
|
|
6688
6900
|
// endpointed text held for the merge window
|
|
6689
6901
|
mergePath = "direct";
|
|
6690
6902
|
// how the pending utterance was assembled (diag)
|
|
6903
|
+
holdTier = 0;
|
|
6904
|
+
// adaptive tier of the hold this dispatch came out of (diag; 0 = none)
|
|
6691
6905
|
lastGraceDiag = 0;
|
|
6692
6906
|
// grace_suppress emitted once per grace window
|
|
6693
6907
|
pendingTimer = null;
|
|
@@ -6698,10 +6912,24 @@ var VoiceEngine = class _VoiceEngine {
|
|
|
6698
6912
|
// the agent replied (or after 3s) still dispatches.
|
|
6699
6913
|
lastDispatchFlat = "";
|
|
6700
6914
|
lastDispatchWords = [];
|
|
6915
|
+
lastDispatchText = "";
|
|
6701
6916
|
lastDispatchAt = 0;
|
|
6702
6917
|
repliedSinceDispatch = false;
|
|
6918
|
+
dispatchReply = "";
|
|
6919
|
+
// the agent's prose since the last dispatch (answeredSinceDispatch)
|
|
6703
6920
|
static DUP_FINAL_MS = 3e3;
|
|
6704
6921
|
lastInterrupted = null;
|
|
6922
|
+
queuedTurn = false;
|
|
6923
|
+
// the current spoken turn is a queued worker utterance (pumpQueue), not a host turn
|
|
6924
|
+
// host-decided overlap (options.overlapDecideMs): pending decision timer, a final that landed while waiting, and
|
|
6925
|
+
// the window in which the overlap the host chose to talk over is absorbed (its growth + its final)
|
|
6926
|
+
decideTimer = null;
|
|
6927
|
+
decideSince = 0;
|
|
6928
|
+
// when this hold began waiting for the host — caps re-decisions (3× overlapDecideMs)
|
|
6929
|
+
decideHeldFinal = "";
|
|
6930
|
+
overlapKeptUntil = 0;
|
|
6931
|
+
overlapKept = "";
|
|
6932
|
+
// what the host judged keep_talking on — only THOSE words are absorbed
|
|
6705
6933
|
// overlap (pause) tier state — AEC + pause-capable sinks only
|
|
6706
6934
|
pausedAt = 0;
|
|
6707
6935
|
lastResumeAt = 0;
|
|
@@ -6750,13 +6978,21 @@ var VoiceEngine = class _VoiceEngine {
|
|
|
6750
6978
|
}
|
|
6751
6979
|
async start() {
|
|
6752
6980
|
this.tts.onAudio = (c) => {
|
|
6753
|
-
if (this.speaking
|
|
6981
|
+
if (!this.speaking && !this.bcActive) return;
|
|
6982
|
+
if (this.wordAnchorPending && this.speaking) this.anchorSubturn();
|
|
6983
|
+
this.player.write(c);
|
|
6754
6984
|
};
|
|
6755
|
-
if (this.options.revealMode === "word") {
|
|
6985
|
+
if (this.options.revealMode === "word" || this.options.heardTimestamps) {
|
|
6756
6986
|
this.tts.wantTimestamps = true;
|
|
6757
|
-
this.tts.onTimestamps = (
|
|
6987
|
+
this.tts.onTimestamps = (words2, start) => {
|
|
6758
6988
|
if (this.interrupted) return;
|
|
6759
|
-
|
|
6989
|
+
start.forEach((s, i) => {
|
|
6990
|
+
if (this.wordAnchorPending) this.wordPending.push([words2[i] ?? "", s]);
|
|
6991
|
+
else {
|
|
6992
|
+
this.wordStarts.push(this.wordOrigin + s);
|
|
6993
|
+
this.wordTexts.push(words2[i] ?? "");
|
|
6994
|
+
}
|
|
6995
|
+
});
|
|
6760
6996
|
};
|
|
6761
6997
|
}
|
|
6762
6998
|
this.stt.onPartial = (text) => this.handlePartial(text);
|
|
@@ -6765,10 +7001,15 @@ var VoiceEngine = class _VoiceEngine {
|
|
|
6765
7001
|
await Promise.all([this.tts.connect(), this.stt.start()]);
|
|
6766
7002
|
this.tts.warmup?.();
|
|
6767
7003
|
this.setState("listening");
|
|
6768
|
-
|
|
7004
|
+
if (this.options.bargeInMode === "aec" && !this.stt.usingAec)
|
|
7005
|
+
log12.warn("bargeInMode=aec but mic does not report echoCancellation applied \u2014 STT may transcribe the assistant");
|
|
7006
|
+
log12.debug(`voice I/O up (${this.usingAec ? "AEC" : "heuristic echo"} capture, mode=${this.options.bargeInMode}, mic reports aec=${this.stt.usingAec})`);
|
|
6769
7007
|
}
|
|
7008
|
+
/** The RESOLVED barge-in tier (the single seam every tier branch reads). `bargeInMode` overrides
|
|
7009
|
+
* the mic's self-report — see the option doc for why the report is not trustworthy on mobile. */
|
|
6770
7010
|
get usingAec() {
|
|
6771
|
-
|
|
7011
|
+
const m = this.options.bargeInMode;
|
|
7012
|
+
return m === "aec" ? true : m === "energy" ? false : this.stt.usingAec;
|
|
6772
7013
|
}
|
|
6773
7014
|
/** Flip barge-in at runtime (e.g. the mic fell back to non-VPIO → go half-duplex so echo can't leak). */
|
|
6774
7015
|
setBargeIn(on) {
|
|
@@ -6800,6 +7041,12 @@ var VoiceEngine = class _VoiceEngine {
|
|
|
6800
7041
|
for (const r of this.idleWaiters.splice(0)) r();
|
|
6801
7042
|
}
|
|
6802
7043
|
}
|
|
7044
|
+
/** True while the assistant is AUDIBLE — deltas flowing or queued audio still draining. Goes false
|
|
7045
|
+
* exactly when `onSpeechEnd` fires (or immediately on barge-in). Lets a host tell "the turn closed
|
|
7046
|
+
* but audio is still playing" from "there was nothing to play", without waiting for a callback. */
|
|
7047
|
+
get audible() {
|
|
7048
|
+
return this.speaking;
|
|
7049
|
+
}
|
|
6803
7050
|
/** Resolve when the engine is no longer speaking (immediate if already idle). */
|
|
6804
7051
|
awaitIdle() {
|
|
6805
7052
|
if (this.state !== "speaking" && this.state !== "thinking") return Promise.resolve();
|
|
@@ -6816,19 +7063,31 @@ var VoiceEngine = class _VoiceEngine {
|
|
|
6816
7063
|
this.drainTimer = null;
|
|
6817
7064
|
}
|
|
6818
7065
|
this.interrupted = false;
|
|
7066
|
+
this.queuedTurn = false;
|
|
6819
7067
|
this.bcSupersede();
|
|
6820
7068
|
this.resetOverlap(true);
|
|
7069
|
+
const acked = ack && this.dispatchRefinal && this.ackSpent;
|
|
7070
|
+
if (acked) {
|
|
7071
|
+
ack = false;
|
|
7072
|
+
this.diag("ack_skipped", { reason: "refinal" });
|
|
7073
|
+
}
|
|
6821
7074
|
this.diag("tts_turn_begin", { ack, gapless: this.speaking });
|
|
7075
|
+
const gapless = this.speaking;
|
|
6822
7076
|
if (!this.speaking) this.player.markTurn();
|
|
6823
7077
|
this.speaking = true;
|
|
6824
7078
|
this.ctxOpen = true;
|
|
6825
7079
|
this.spokeDeltas = false;
|
|
6826
|
-
this.adaptiveAckFired =
|
|
6827
|
-
this.ackProbe = null;
|
|
7080
|
+
this.adaptiveAckFired = acked;
|
|
7081
|
+
this.ackProbe = acked ? "" : null;
|
|
7082
|
+
this.ackPickedFired = false;
|
|
6828
7083
|
this.reply = "";
|
|
6829
7084
|
this.revealText = "";
|
|
6830
7085
|
this.wordStarts = [];
|
|
7086
|
+
this.wordTexts = [];
|
|
7087
|
+
this.ackWords = 0;
|
|
6831
7088
|
this.revealedN = 0;
|
|
7089
|
+
this.resetSubturnAnchor();
|
|
7090
|
+
if (gapless) this.wordAnchorPending = true;
|
|
6832
7091
|
if (this.options.revealMode === "word") this.startWordReveal();
|
|
6833
7092
|
this.emo = this.options.emotions ? new EmotionStream(this.options.showEmotions) : null;
|
|
6834
7093
|
this.echoWords = new Set(this.words(this.prevReply));
|
|
@@ -6840,23 +7099,27 @@ var VoiceEngine = class _VoiceEngine {
|
|
|
6840
7099
|
this.spokeDeltas = true;
|
|
6841
7100
|
this.ackAt = this.clock.now();
|
|
6842
7101
|
this.lastAck = this.options.ackPhrase;
|
|
7102
|
+
this.ackSpent = true;
|
|
7103
|
+
this.ackWords = this.options.ackPhrase.trim().split(/\s+/).length;
|
|
6843
7104
|
for (const w of this.words(this.options.ackPhrase)) this.echoWords.add(w);
|
|
6844
7105
|
} else if (ack && this.options.adaptiveAckMs > 0) {
|
|
7106
|
+
const pick = this.startAckPick();
|
|
7107
|
+
const ms = this.options.adaptiveAckMs;
|
|
6845
7108
|
this.ackTimer = this.clock.setTimeout(() => {
|
|
6846
7109
|
this.ackTimer = null;
|
|
6847
|
-
if (!
|
|
6848
|
-
|
|
6849
|
-
|
|
6850
|
-
|
|
6851
|
-
|
|
6852
|
-
|
|
6853
|
-
|
|
6854
|
-
|
|
6855
|
-
|
|
6856
|
-
|
|
6857
|
-
|
|
6858
|
-
|
|
6859
|
-
|
|
7110
|
+
if (!pick.pending) return this.fireAck(pick.phrase, pick.picked);
|
|
7111
|
+
this.ackTimer = this.clock.setTimeout(() => {
|
|
7112
|
+
this.ackTimer = null;
|
|
7113
|
+
pick.onDone = null;
|
|
7114
|
+
this.ackPick = null;
|
|
7115
|
+
this.diag("ack_cancelled", { reason: "pick_late" });
|
|
7116
|
+
}, ms);
|
|
7117
|
+
pick.onDone = () => {
|
|
7118
|
+
this.clearAckTimer();
|
|
7119
|
+
this.fireAck(pick.phrase, pick.picked);
|
|
7120
|
+
};
|
|
7121
|
+
}, ms);
|
|
7122
|
+
this.ackPick = pick;
|
|
6860
7123
|
}
|
|
6861
7124
|
if (!this.turnStartAt) this.turnStartAt = this.clock.now();
|
|
6862
7125
|
this.setState("thinking");
|
|
@@ -6876,11 +7139,16 @@ var VoiceEngine = class _VoiceEngine {
|
|
|
6876
7139
|
this.adaptiveAckFired = false;
|
|
6877
7140
|
const lead = m ? m[1] : bare;
|
|
6878
7141
|
const norm2 = lead.replace(/[^a-z ]/gi, " ").replace(/\s+/g, " ").trim().toLowerCase();
|
|
7142
|
+
const same = this.ackPickedFired ? bare.match(_VoiceEngine.leadingPhrase(this.lastAck)) : null;
|
|
6879
7143
|
if (_VoiceEngine.ACK_LEADING.test(norm2)) {
|
|
6880
7144
|
const rest = m ? m[2] : "";
|
|
6881
7145
|
this.diag("reflex_ack_suppressed", { lead: lead.trim() });
|
|
6882
7146
|
if (!rest.trim()) return "";
|
|
6883
7147
|
text = rest;
|
|
7148
|
+
} else if (same) {
|
|
7149
|
+
this.diag("reflex_ack_suppressed", { lead: same[0].trim() });
|
|
7150
|
+
text = bare.slice(same[0].length);
|
|
7151
|
+
if (!text.trim()) return "";
|
|
6884
7152
|
} else {
|
|
6885
7153
|
text = probe;
|
|
6886
7154
|
}
|
|
@@ -6893,7 +7161,10 @@ var VoiceEngine = class _VoiceEngine {
|
|
|
6893
7161
|
prose = " " + prose;
|
|
6894
7162
|
}
|
|
6895
7163
|
this.reply += prose;
|
|
6896
|
-
if (prose.trim())
|
|
7164
|
+
if (prose.trim()) {
|
|
7165
|
+
this.repliedSinceDispatch = true;
|
|
7166
|
+
this.dispatchReply += prose;
|
|
7167
|
+
}
|
|
6897
7168
|
for (const w of this.words(this.reply)) this.echoWords.add(w);
|
|
6898
7169
|
this.tts.speak(forSpeech(speech), true);
|
|
6899
7170
|
if (!this.spokeDeltas && this.turnStartAt) log12.debug(`ttft: ${Math.round(this.clock.now() - this.turnStartAt)}ms`);
|
|
@@ -6905,6 +7176,42 @@ var VoiceEngine = class _VoiceEngine {
|
|
|
6905
7176
|
}
|
|
6906
7177
|
return display;
|
|
6907
7178
|
}
|
|
7179
|
+
/** Sub-turn seam: the host's agent stream interrupted the reply with a tool call, so the spoken
|
|
7180
|
+
* turn continues on a FRESH TTS context. Flushes the current context and opens the next, then
|
|
7181
|
+
* re-anchors the karaoke timeline at the position the next context's first audio byte lands on.
|
|
7182
|
+
*
|
|
7183
|
+
* Rotating unconditionally is the point: Cartesia restarts word timestamps at 0 for each context
|
|
7184
|
+
* and ALSO rotates on its own after ~5s idle — so leaving the context alone makes reveal timing
|
|
7185
|
+
* depend on an invisible server-side timer (short gap = one timeline, long gap = a restart we
|
|
7186
|
+
* never saw). By always rotating, the origin is always known and never inferred.
|
|
7187
|
+
*
|
|
7188
|
+
* No-op outside an open turn. Reveal text/word ordering is unchanged — only the time origin. */
|
|
7189
|
+
subturnBoundary() {
|
|
7190
|
+
if (!this.speaking || !this.ctxOpen) return;
|
|
7191
|
+
this.diag("tts_subturn_boundary", { playedMs: Math.round(Math.max(0, this.player.playedMs())) });
|
|
7192
|
+
this.tts.end();
|
|
7193
|
+
this.tts.newContext();
|
|
7194
|
+
this.wordAnchorPending = true;
|
|
7195
|
+
this.wordPending = [];
|
|
7196
|
+
}
|
|
7197
|
+
/** Capture the current sub-turn's time origin = content seconds already written to the sink.
|
|
7198
|
+
* `playedMs + drainMs` is that sum in both regimes (mid-playback it telescopes to the scheduled
|
|
7199
|
+
* content; fully drained, drainMs is 0 and playedMs has reached the scheduled total). */
|
|
7200
|
+
anchorSubturn() {
|
|
7201
|
+
this.wordAnchorPending = false;
|
|
7202
|
+
this.wordOrigin = Math.max(0, this.player.playedMs() + this.player.drainMs()) / 1e3;
|
|
7203
|
+
this.diag("reveal_anchor", { originSec: Number(this.wordOrigin.toFixed(3)), held: this.wordPending.length });
|
|
7204
|
+
for (const [w, s] of this.wordPending) {
|
|
7205
|
+
this.wordStarts.push(this.wordOrigin + s);
|
|
7206
|
+
this.wordTexts.push(w);
|
|
7207
|
+
}
|
|
7208
|
+
this.wordPending = [];
|
|
7209
|
+
}
|
|
7210
|
+
resetSubturnAnchor() {
|
|
7211
|
+
this.wordOrigin = 0;
|
|
7212
|
+
this.wordAnchorPending = false;
|
|
7213
|
+
this.wordPending = [];
|
|
7214
|
+
}
|
|
6908
7215
|
/** Karaoke reveal poll: reveal the display-word prefix up to the count of spoken words whose
|
|
6909
7216
|
* Cartesia start time has been reached on the playback clock (`AudioSink.playedMs`, which excludes
|
|
6910
7217
|
* paused time). Poll-driven (not AudioContext timers) so it's portable across CLI/browser sinks and
|
|
@@ -6919,8 +7226,8 @@ var VoiceEngine = class _VoiceEngine {
|
|
|
6919
7226
|
while (n < this.wordStarts.length && this.wordStarts[n] <= playedSec) n++;
|
|
6920
7227
|
if (n !== this.revealedN) {
|
|
6921
7228
|
this.revealedN = n;
|
|
6922
|
-
const
|
|
6923
|
-
this.options.onReveal(
|
|
7229
|
+
const words2 = this.revealText.trim().split(/\s+/).filter(Boolean);
|
|
7230
|
+
this.options.onReveal(words2.slice(0, n).join(" "));
|
|
6924
7231
|
}
|
|
6925
7232
|
this.revealPoll = this.clock.setTimeout(tick, 60);
|
|
6926
7233
|
};
|
|
@@ -6976,6 +7283,11 @@ var VoiceEngine = class _VoiceEngine {
|
|
|
6976
7283
|
if (this.turnStartAt) log12.debug(`turn: ${Math.round(this.clock.now() - this.turnStartAt)}ms (incl. playback)`);
|
|
6977
7284
|
this.echoUntil = this.clock.now() + 2500;
|
|
6978
7285
|
if (!this.usingAec) this.stt.reset();
|
|
7286
|
+
try {
|
|
7287
|
+
this.options.onSpeechEnd();
|
|
7288
|
+
} catch (e) {
|
|
7289
|
+
log12.warn(`onSpeechEnd threw: ${e instanceof Error ? e.message : e}`);
|
|
7290
|
+
}
|
|
6979
7291
|
this.setState("listening");
|
|
6980
7292
|
if (this.uttQueue.length) this.pumpQueue();
|
|
6981
7293
|
};
|
|
@@ -6990,8 +7302,9 @@ var VoiceEngine = class _VoiceEngine {
|
|
|
6990
7302
|
this.drainTimer = this.clock.setTimeout(drainThenSettle, 15e3);
|
|
6991
7303
|
} else drainThenSettle();
|
|
6992
7304
|
}
|
|
6993
|
-
/**
|
|
6994
|
-
* the user did NOT hear
|
|
7305
|
+
/** What the last barge-in cut — the reply that was playing (and its estimated heard part) plus every queued worker
|
|
7306
|
+
* utterance it dropped — consumed by the host to tell the model what the user did NOT hear, or to park the rest of
|
|
7307
|
+
* a delivery for resuming. Cleared on read. */
|
|
6995
7308
|
takeInterruptedReply() {
|
|
6996
7309
|
const r = this.lastInterrupted;
|
|
6997
7310
|
this.lastInterrupted = null;
|
|
@@ -7000,11 +7313,12 @@ var VoiceEngine = class _VoiceEngine {
|
|
|
7000
7313
|
/** Speak a short filler phrase without starting a model turn (stays in listening mode after). */
|
|
7001
7314
|
speakFiller(text) {
|
|
7002
7315
|
if (!text || this.speaking) return;
|
|
7003
|
-
const replied = this.repliedSinceDispatch;
|
|
7316
|
+
const replied = this.repliedSinceDispatch, reply = this.dispatchReply;
|
|
7004
7317
|
this.beginSpeech();
|
|
7005
7318
|
this.speakDelta(text);
|
|
7006
7319
|
this.endSpeech();
|
|
7007
7320
|
this.repliedSinceDispatch = replied;
|
|
7321
|
+
this.dispatchReply = reply;
|
|
7008
7322
|
}
|
|
7009
7323
|
/** Enqueue a COMPLETE worker utterance (already-split spoken text) onto the central speech queue.
|
|
7010
7324
|
* If nothing is currently speaking it plays immediately; otherwise it queues and plays after the
|
|
@@ -7022,6 +7336,7 @@ var VoiceEngine = class _VoiceEngine {
|
|
|
7022
7336
|
const text = this.uttQueue.shift();
|
|
7023
7337
|
if (text == null) return;
|
|
7024
7338
|
this.beginSpeech();
|
|
7339
|
+
this.queuedTurn = true;
|
|
7025
7340
|
this.speakDelta(text);
|
|
7026
7341
|
this.endSpeech();
|
|
7027
7342
|
}
|
|
@@ -7036,6 +7351,69 @@ var VoiceEngine = class _VoiceEngine {
|
|
|
7036
7351
|
* micro-ack already spoke one. Anchored end-to-end so only a whole ack-only clause matches. */
|
|
7037
7352
|
static ACK_LEADING = /^(?:(?:okay|ok|alright|sure|yeah|yep|right|got it|on it|still|still on it|still working on it|working on it|checking|one sec|one moment|mm hm|mmhm|hmm|let me (?:see|check|think))[ ,]*)+$/;
|
|
7038
7353
|
recentAcks = [];
|
|
7354
|
+
/** The armed turn's ack choice: the host's `pickAck` (sync or async); `phrase` undefined = the default pools, drawn
|
|
7355
|
+
* only when the ack actually fires. `onDone` is set only while the ack is due and the pick is still pending. */
|
|
7356
|
+
ackPick = null;
|
|
7357
|
+
startAckPick() {
|
|
7358
|
+
const host = this.options.pickAck;
|
|
7359
|
+
const pick = { pending: false, phrase: void 0, picked: !!host, onDone: null };
|
|
7360
|
+
if (!host) return pick;
|
|
7361
|
+
const ctx = { text: this.lastDispatchText, question: this.lastDispatchWasQuestion, barged: this.bargedBeforeDispatch };
|
|
7362
|
+
const fallback = (e) => {
|
|
7363
|
+
log12.warn(`pickAck failed \u2014 using the default pools: ${e instanceof Error ? e.message : e}`);
|
|
7364
|
+
pick.picked = false;
|
|
7365
|
+
return void 0;
|
|
7366
|
+
};
|
|
7367
|
+
let r;
|
|
7368
|
+
try {
|
|
7369
|
+
r = host(ctx);
|
|
7370
|
+
} catch (e) {
|
|
7371
|
+
pick.phrase = fallback(e);
|
|
7372
|
+
return pick;
|
|
7373
|
+
}
|
|
7374
|
+
if (typeof r?.then !== "function") {
|
|
7375
|
+
pick.phrase = r;
|
|
7376
|
+
return pick;
|
|
7377
|
+
}
|
|
7378
|
+
pick.pending = true;
|
|
7379
|
+
Promise.resolve(r).catch(fallback).then((phrase) => {
|
|
7380
|
+
pick.pending = false;
|
|
7381
|
+
pick.phrase = phrase;
|
|
7382
|
+
if (this.ackPick === pick) pick.onDone?.();
|
|
7383
|
+
});
|
|
7384
|
+
return pick;
|
|
7385
|
+
}
|
|
7386
|
+
/** Speak the adaptive ack (null = the host chose silence, undefined = draw from the default pools) — only if the
|
|
7387
|
+
* turn is still waiting on its reflex. */
|
|
7388
|
+
fireAck(phrase, picked) {
|
|
7389
|
+
this.ackPick = null;
|
|
7390
|
+
if (!this.speaking || !this.ctxOpen || this.spokeDeltas || this.interrupted) return;
|
|
7391
|
+
if (phrase === void 0) phrase = this.pickAck();
|
|
7392
|
+
if (phrase === null || !phrase.trim()) {
|
|
7393
|
+
this.diag("ack_skipped", { reason: "silent" });
|
|
7394
|
+
return;
|
|
7395
|
+
}
|
|
7396
|
+
this.diag("ack_fired", { phrase, adaptive: true, waitedMs: this.options.adaptiveAckMs, ...picked ? { picked } : {} });
|
|
7397
|
+
this.tts.speak(phrase + " ", true);
|
|
7398
|
+
this.spokeDeltas = true;
|
|
7399
|
+
this.ackAt = this.clock.now();
|
|
7400
|
+
this.lastAck = phrase;
|
|
7401
|
+
this.ackSpent = true;
|
|
7402
|
+
this.ackWords = phrase.trim().split(/\s+/).length;
|
|
7403
|
+
for (const w of this.words(phrase)) this.echoWords.add(w);
|
|
7404
|
+
this.setState("speaking");
|
|
7405
|
+
this.adaptiveAckFired = true;
|
|
7406
|
+
this.ackProbe = "";
|
|
7407
|
+
this.ackPickedFired = picked;
|
|
7408
|
+
this.options.onAdaptiveAck();
|
|
7409
|
+
}
|
|
7410
|
+
/** `phrase`'s words at the very start of a text, any punctuation between them ("Oh no." ~ "oh, no —"). */
|
|
7411
|
+
static leadingPhrase(phrase) {
|
|
7412
|
+
const w = phrase.toLowerCase().match(/[a-z0-9]+/g) ?? [];
|
|
7413
|
+
return w.length ? new RegExp(`^[^a-z0-9]*${w.join("[^a-z0-9]+")}(?![a-z0-9])[^a-z0-9]*`, "i") : /$^/;
|
|
7414
|
+
}
|
|
7415
|
+
ackPickedFired = false;
|
|
7416
|
+
// the fired ack was the host's pick → the probe also strips the reflex repeating it
|
|
7039
7417
|
pickAck() {
|
|
7040
7418
|
const pool = this.lastDispatchWasQuestion ? _VoiceEngine.ACKS_QUESTION : _VoiceEngine.ACKS_NEUTRAL;
|
|
7041
7419
|
const fresh = pool.filter((p) => !this.recentAcks.includes(p));
|
|
@@ -7045,7 +7423,16 @@ var VoiceEngine = class _VoiceEngine {
|
|
|
7045
7423
|
return phrase;
|
|
7046
7424
|
}
|
|
7047
7425
|
lastDispatchWasQuestion = false;
|
|
7426
|
+
dispatchRefinal = false;
|
|
7427
|
+
// the last dispatch re-finalized (superseded) the one before it — same logical turn
|
|
7428
|
+
ackSpent = false;
|
|
7429
|
+
// an ack already played for the current logical turn (reset by a non-refinal dispatch)
|
|
7430
|
+
bargedSinceDispatch = false;
|
|
7431
|
+
// an effective interrupt landed since the last dispatch
|
|
7432
|
+
bargedBeforeDispatch = false;
|
|
7433
|
+
// …as of the last dispatch (AckContext.barged)
|
|
7048
7434
|
clearAckTimer(reason) {
|
|
7435
|
+
if (reason) this.ackPick = null;
|
|
7049
7436
|
if (!this.ackTimer) return;
|
|
7050
7437
|
this.clock.clearTimeout(this.ackTimer);
|
|
7051
7438
|
this.ackTimer = null;
|
|
@@ -7061,11 +7448,16 @@ var VoiceEngine = class _VoiceEngine {
|
|
|
7061
7448
|
this.clearAckTimer("interrupt");
|
|
7062
7449
|
this.adaptiveAckFired = false;
|
|
7063
7450
|
this.ackProbe = null;
|
|
7064
|
-
|
|
7065
|
-
const droppedQueued =
|
|
7066
|
-
|
|
7067
|
-
|
|
7451
|
+
const queued = this.uttQueue.splice(0);
|
|
7452
|
+
const droppedQueued = queued.length;
|
|
7453
|
+
if (droppedQueued) log12.info(`barge-in cut ${droppedQueued} queued worker utterance(s) \u2014 handed to the host`);
|
|
7454
|
+
this.overlapKeptUntil = 0;
|
|
7455
|
+
if (!this.speaking && !this.drainTimer) {
|
|
7456
|
+
if (droppedQueued) this.lastInterrupted = { full: "", heard: "", queued, queuedTurn: false };
|
|
7457
|
+
return;
|
|
7458
|
+
}
|
|
7068
7459
|
this.stopWordReveal(false);
|
|
7460
|
+
this.resetSubturnAnchor();
|
|
7069
7461
|
this.diag("interrupt", { droppedQueued, ctxOpen: this.ctxOpen, playedMs: Math.round(Math.max(0, this.player.playedMs())) });
|
|
7070
7462
|
if (this.drainTimer) {
|
|
7071
7463
|
this.clock.clearTimeout(this.drainTimer);
|
|
@@ -7073,8 +7465,9 @@ var VoiceEngine = class _VoiceEngine {
|
|
|
7073
7465
|
}
|
|
7074
7466
|
this.resetOverlap(false);
|
|
7075
7467
|
this.lastResumeAt = 0;
|
|
7076
|
-
const
|
|
7077
|
-
if (this.reply) this.lastInterrupted = { full: this.reply, heard: this.
|
|
7468
|
+
const { heard, exact } = this.heardCut();
|
|
7469
|
+
if (this.reply || droppedQueued) this.lastInterrupted = { full: this.reply, heard, exact, queued, queuedTurn: this.queuedTurn };
|
|
7470
|
+
if (heard.length < this.reply.length || droppedQueued) this.bargedSinceDispatch = true;
|
|
7078
7471
|
this.speaking = false;
|
|
7079
7472
|
this.ctxOpen = false;
|
|
7080
7473
|
this.interrupted = true;
|
|
@@ -7086,8 +7479,23 @@ var VoiceEngine = class _VoiceEngine {
|
|
|
7086
7479
|
if (this.reply) this.prevReply = this.reply;
|
|
7087
7480
|
this.setState("listening");
|
|
7088
7481
|
}
|
|
7482
|
+
/** How much of the reply the user heard at a cut (paused time is excluded by the sink's playedMs). Exact from the
|
|
7483
|
+
* TTS word timestamps the playback clock has reached (the ack's leading words skipped); without timestamps, an
|
|
7484
|
+
* estimate — played seconds × ~15 chars/s of TTS speech, coarse and often mid-word. */
|
|
7485
|
+
heardCut() {
|
|
7486
|
+
const played = Math.max(0, this.player.playedMs());
|
|
7487
|
+
if (!this.wordTexts.length) return { heard: this.reply.slice(0, Math.round(played / 1e3 * 15)), exact: false };
|
|
7488
|
+
let n = 0;
|
|
7489
|
+
while (n < this.wordStarts.length && this.wordStarts[n] <= played / 1e3) n++;
|
|
7490
|
+
if (!this.ctxOpen && n === this.wordStarts.length && played / 1e3 - this.wordStarts[n - 1] >= 0.4) return { heard: this.reply, exact: true };
|
|
7491
|
+
return { heard: this.reply.slice(0, heardPrefix(this.reply, this.wordTexts.slice(this.ackWords, n))), exact: true };
|
|
7492
|
+
}
|
|
7089
7493
|
stop() {
|
|
7090
7494
|
this.uttQueue = [];
|
|
7495
|
+
if (this.decideTimer) {
|
|
7496
|
+
this.clock.clearTimeout(this.decideTimer);
|
|
7497
|
+
this.decideTimer = null;
|
|
7498
|
+
}
|
|
7091
7499
|
this.clearAckTimer();
|
|
7092
7500
|
if (this.resumeTimer) this.clock.clearTimeout(this.resumeTimer);
|
|
7093
7501
|
if (this.pendingTimer) this.clock.clearTimeout(this.pendingTimer);
|
|
@@ -7100,9 +7508,41 @@ var VoiceEngine = class _VoiceEngine {
|
|
|
7100
7508
|
this.setState("idle");
|
|
7101
7509
|
}
|
|
7102
7510
|
// --- listening side (STT-driven) ---
|
|
7511
|
+
/** Echo-comparable tokens. Our text and the STT's rendering of it must tokenize alike: every non-alphanumeric
|
|
7512
|
+
* (em-dash, non-breaking hyphen, nbsp, …) SEPARATES words — deleting it glued "releases—GPT‑6" into
|
|
7513
|
+
* "releasesgpt6" and the echo gate missed our own words. Numbers take the spoken form STT may hear: letter/digit
|
|
7514
|
+
* runs split ("K2.8" → k 2 point 8), a decimal point is "point", number words are digits ("five" → 5).
|
|
7515
|
+
* Apostrophes are dropped (it's → its). Words under 2 letters are noise; digits are kept. Any script counts (Unicode
|
|
7516
|
+
* letters/marks/digits): an ASCII-only split gave Hebrew speech ZERO words, which the echo gate read as pure echo
|
|
7517
|
+
* (live 20260923-125143: "סבתא מחוץ לדלת?" and "תודה." swallowed). */
|
|
7103
7518
|
words(s) {
|
|
7104
|
-
return s.toLowerCase().replace(/[
|
|
7105
|
-
}
|
|
7519
|
+
return s.toLowerCase().replace(/['’]/g, "").replace(/(\d)\.(?=\d)/g, "$1 point ").replace(new RegExp("(\\p{L})(?=\\d)|(\\d)(?=\\p{L})", "gu"), "$1$2 ").split(/[^\p{L}\p{M}\p{N}]+/u).map((w) => _VoiceEngine.NUMBER_WORDS[w] ?? w).filter((w) => w.length >= 2 || /\d/.test(w));
|
|
7520
|
+
}
|
|
7521
|
+
static NUMBER_WORDS = Object.fromEntries(
|
|
7522
|
+
[
|
|
7523
|
+
"zero",
|
|
7524
|
+
"one",
|
|
7525
|
+
"two",
|
|
7526
|
+
"three",
|
|
7527
|
+
"four",
|
|
7528
|
+
"five",
|
|
7529
|
+
"six",
|
|
7530
|
+
"seven",
|
|
7531
|
+
"eight",
|
|
7532
|
+
"nine",
|
|
7533
|
+
"ten",
|
|
7534
|
+
"eleven",
|
|
7535
|
+
"twelve",
|
|
7536
|
+
"thirteen",
|
|
7537
|
+
"fourteen",
|
|
7538
|
+
"fifteen",
|
|
7539
|
+
"sixteen",
|
|
7540
|
+
"seventeen",
|
|
7541
|
+
"eighteen",
|
|
7542
|
+
"nineteen",
|
|
7543
|
+
"twenty"
|
|
7544
|
+
].map((w, i) => [w, String(i)])
|
|
7545
|
+
);
|
|
7106
7546
|
novelWords(text) {
|
|
7107
7547
|
return this.words(text).filter((w) => !this.echoWords.has(w));
|
|
7108
7548
|
}
|
|
@@ -7119,6 +7559,22 @@ var VoiceEngine = class _VoiceEngine {
|
|
|
7119
7559
|
const novel = this.novelWords(text).length;
|
|
7120
7560
|
return novel > 0 && novel / Math.max(1, total) > 0.5;
|
|
7121
7561
|
}
|
|
7562
|
+
/** Echo verdict for a FINAL in the echo window (AEC tier). Bag-of-words genuine() alone swallowed real replies
|
|
7563
|
+
* that reuse a few of our words — live 20260923-102258, right after a barge over "…Gemini 3.8 Flash…":
|
|
7564
|
+
* "Wait, there is a new Gemini model?" (3 novel / 6) was dropped twice and the user had to repeat it. Echo
|
|
7565
|
+
* of our own audio reproduces RUNS of what we said, in order (mis-hearings break a word, not the run); a
|
|
7566
|
+
* reply that shares vocabulary scatters it. So a ≥4-word final that fails the bag test is echo only if at
|
|
7567
|
+
* least half its words sit in a word pair we actually said. Shorter finals can't show order → bag rule. */
|
|
7568
|
+
echoFinal(text) {
|
|
7569
|
+
if (this.genuine(text)) return false;
|
|
7570
|
+
const w = this.words(text);
|
|
7571
|
+
if (w.length < 4) return true;
|
|
7572
|
+
const said = this.words(`${this.prevReply} ${this.reply} ${this.lastAck}`);
|
|
7573
|
+
const pairs = new Set(said.slice(1).map((x, i) => `${said[i]} ${x}`));
|
|
7574
|
+
const inRun = w.map(() => false);
|
|
7575
|
+
for (let i = 1; i < w.length; i++) if (pairs.has(`${w[i - 1]} ${w[i]}`)) inRun[i - 1] = inRun[i] = true;
|
|
7576
|
+
return inRun.filter(Boolean).length * 2 >= w.length;
|
|
7577
|
+
}
|
|
7122
7578
|
handlePartial(text) {
|
|
7123
7579
|
if (this.speaking) {
|
|
7124
7580
|
if (!this.options.bargeIn) return;
|
|
@@ -7130,14 +7586,29 @@ var VoiceEngine = class _VoiceEngine {
|
|
|
7130
7586
|
if (!this.echoActive() || (this.usingAec ? this.genuine(text) : this.novelWords(text).length >= 1)) this.options.onPartial(text);
|
|
7131
7587
|
return;
|
|
7132
7588
|
}
|
|
7589
|
+
if (this.echoesDispatch(text, true)) {
|
|
7590
|
+
if (this.lastDupPartial !== text.trim()) {
|
|
7591
|
+
this.lastDupPartial = text.trim();
|
|
7592
|
+
this.diag("dup_partial", { reason: "dup_final", text: text.slice(0, 60) });
|
|
7593
|
+
}
|
|
7594
|
+
if (this.pausedAt) {
|
|
7595
|
+
this.diag("overlap_resume", { heldMs: Math.round(this.clock.now() - this.pausedAt), reason: "dup_final" });
|
|
7596
|
+
this.resetOverlap(true);
|
|
7597
|
+
}
|
|
7598
|
+
return;
|
|
7599
|
+
}
|
|
7133
7600
|
if (this.overlapCapable) {
|
|
7134
7601
|
const txt = text.trim();
|
|
7135
7602
|
if (!txt || txt === this.lastOverlapPartial) return;
|
|
7136
7603
|
this.lastOverlapPartial = txt;
|
|
7137
7604
|
if (!this.genuine(txt)) {
|
|
7138
|
-
if (this.pausedAt) this.armResume();
|
|
7605
|
+
if (this.pausedAt && !this.decideTimer) this.armResume();
|
|
7139
7606
|
return;
|
|
7140
7607
|
}
|
|
7608
|
+
if (this.overlapKeptUntil && this.clock.now() < this.overlapKeptUntil) {
|
|
7609
|
+
if (!this.unjudged(txt)) return;
|
|
7610
|
+
this.overlapKeptUntil = 0;
|
|
7611
|
+
}
|
|
7141
7612
|
if (!this.pausedAt) {
|
|
7142
7613
|
this.pausedAt = this.clock.now();
|
|
7143
7614
|
const sinceResumeMs = this.lastResumeAt ? Math.round(this.clock.now() - this.lastResumeAt) : void 0;
|
|
@@ -7152,13 +7623,14 @@ var VoiceEngine = class _VoiceEngine {
|
|
|
7152
7623
|
}
|
|
7153
7624
|
}
|
|
7154
7625
|
if (this.words(txt).length >= 2) {
|
|
7155
|
-
|
|
7156
|
-
|
|
7157
|
-
|
|
7158
|
-
|
|
7626
|
+
if (this.options.overlapDecideMs > 0 && this.shortOverlap(txt)) {
|
|
7627
|
+
this.awaitOverlapDecision(txt);
|
|
7628
|
+
return;
|
|
7629
|
+
}
|
|
7630
|
+
this.cedeOverlap("overlap_cede", txt);
|
|
7159
7631
|
return;
|
|
7160
7632
|
}
|
|
7161
|
-
this.armResume();
|
|
7633
|
+
if (!this.decideTimer) this.armResume();
|
|
7162
7634
|
return;
|
|
7163
7635
|
}
|
|
7164
7636
|
const barge = this.usingAec ? this.genuine(text) : this.novelWords(text).length >= (this.suspectUntil ? 1 : 2);
|
|
@@ -7203,7 +7675,7 @@ var VoiceEngine = class _VoiceEngine {
|
|
|
7203
7675
|
this.specTimer = null;
|
|
7204
7676
|
if (this.speaking || this.specSpent || this.pendingUtt) return;
|
|
7205
7677
|
if (this.words(this.specPartial).length < this.options.speculativeMinWords) return;
|
|
7206
|
-
const flat = this.specPartial
|
|
7678
|
+
const flat = normWord(this.specPartial);
|
|
7207
7679
|
if (flat && this.lastDispatchFlat && this.clock.now() - this.lastDispatchAt < _VoiceEngine.DUP_FINAL_MS && (this.lastDispatchFlat.startsWith(flat) || flat.startsWith(this.lastDispatchFlat))) return;
|
|
7208
7680
|
this.specSpent = true;
|
|
7209
7681
|
this.specText = this.specPartial;
|
|
@@ -7242,7 +7714,7 @@ var VoiceEngine = class _VoiceEngine {
|
|
|
7242
7714
|
const letters = p.replace(/[^\p{L}]/gu, "");
|
|
7243
7715
|
const latin = p.replace(/[^A-Za-z]/g, "");
|
|
7244
7716
|
if (!letters || latin.length / letters.length < 0.7) return veto("non_latin");
|
|
7245
|
-
const flat = p
|
|
7717
|
+
const flat = normWord(p);
|
|
7246
7718
|
if (flat && this.lastDispatchFlat && this.clock.now() - this.lastDispatchAt < _VoiceEngine.DUP_FINAL_MS && (this.lastDispatchFlat.startsWith(flat) || flat.startsWith(this.lastDispatchFlat))) return;
|
|
7247
7719
|
this.fireBackchannel();
|
|
7248
7720
|
}, this.options.backchannelMs);
|
|
@@ -7330,6 +7802,10 @@ var VoiceEngine = class _VoiceEngine {
|
|
|
7330
7802
|
}
|
|
7331
7803
|
if (pfx && norm2(nw[pw.length - 1]).startsWith(norm2(pw[pw.length - 1]))) return next;
|
|
7332
7804
|
}
|
|
7805
|
+
if (_VoiceEngine.restates(prev, next)) {
|
|
7806
|
+
this.diag("merge_restated", { dropped: prev.slice(0, 60) });
|
|
7807
|
+
return next;
|
|
7808
|
+
}
|
|
7333
7809
|
const max = Math.min(pw.length, nw.length);
|
|
7334
7810
|
for (let k = max; k > 0; k--) {
|
|
7335
7811
|
let match = true;
|
|
@@ -7344,6 +7820,25 @@ var VoiceEngine = class _VoiceEngine {
|
|
|
7344
7820
|
static normWord(w) {
|
|
7345
7821
|
return normWord(w);
|
|
7346
7822
|
}
|
|
7823
|
+
/** `next` RESTATES the held, unfinished `prev` — the user restarted ("Wo- wait, can you explain more about" →
|
|
7824
|
+
* "What— wait, can you explain more about that? …", live 20260924-093945, where both landed in the dispatch).
|
|
7825
|
+
* Keep only the later version. Conservative: prev's words from index i ≤ 2 through its END reappear contiguously
|
|
7826
|
+
* in next starting at j ≤ 2, that run is ≥4 words and ≥75% of prev. i > 0 with j = 0 is NOT a restart — that is
|
|
7827
|
+
* an overlapping re-final continuing prev ("Tell me about the" + "about the weather"), deduped by the caller
|
|
7828
|
+
* keeping prev's head. prev's last word may be a char-prefix (a mid-word endpoint). */
|
|
7829
|
+
static restates(prev, next) {
|
|
7830
|
+
const p = prev.split(/\s+/).map(normWord).filter(Boolean), n = next.split(/\s+/).map(normWord).filter(Boolean);
|
|
7831
|
+
for (let i = 0; i <= 2; i++) {
|
|
7832
|
+
const k = p.length - i;
|
|
7833
|
+
if (k < 4 || k < 0.75 * p.length) return false;
|
|
7834
|
+
for (let j = i === 0 ? 0 : 1; j <= 2 && j + k <= n.length; j++) {
|
|
7835
|
+
let ok = true;
|
|
7836
|
+
for (let x = 0; x < k && ok; x++) ok = x === k - 1 ? n[j + x].startsWith(p[i + x]) : n[j + x] === p[i + x];
|
|
7837
|
+
if (ok) return true;
|
|
7838
|
+
}
|
|
7839
|
+
}
|
|
7840
|
+
return false;
|
|
7841
|
+
}
|
|
7347
7842
|
/** Soniox re-finalization of an ALREADY-DISPATCHED utterance, arriving PAST the merge window:
|
|
7348
7843
|
* the new final is a strict word-prefix superset of the last dispatch (the last dispatched word
|
|
7349
7844
|
* may be a char-prefix of the corresponding new word — a mid-word endpoint), and it lands within
|
|
@@ -7374,18 +7869,71 @@ var VoiceEngine = class _VoiceEngine {
|
|
|
7374
7869
|
if (!nSame.startsWith(pLast)) return false;
|
|
7375
7870
|
return nw.length > pw.length || nSame.length > pLast.length;
|
|
7376
7871
|
}
|
|
7872
|
+
/** The STT re-emitting (part of) the utterance just dispatched: ≥2 words that form a contiguous run of the dispatched
|
|
7873
|
+
* words, within DUP_FINAL_MS. A merged dispatch ("Okay." + "Um, check for the recent news in AI.") has its later
|
|
7874
|
+
* segment come back as a partial/final a beat later — the identical/superset guards miss a PIECE. A human cannot
|
|
7875
|
+
* re-speak a ≥2-word stretch of what they said within ~1s; one word ("stop") is never treated as a duplicate.
|
|
7876
|
+
* `partial`: the last word may be cut mid-word ("…news in A"). */
|
|
7877
|
+
echoesDispatch(text, partial = false) {
|
|
7878
|
+
if (!this.lastDispatchWords.length || this.clock.now() - this.lastDispatchAt >= _VoiceEngine.DUP_FINAL_MS) return false;
|
|
7879
|
+
const d = this.lastDispatchWords.map(normWord).filter(Boolean), w = text.trim().split(/\s+/).map(normWord).filter(Boolean);
|
|
7880
|
+
if (w.length < 2 || w.length > d.length) return false;
|
|
7881
|
+
const last = w.length - 1;
|
|
7882
|
+
outer: for (let i = 0; i + w.length <= d.length; i++) {
|
|
7883
|
+
for (let k = 0; k < w.length; k++) if (partial && k === last ? !d[i + k].startsWith(w[k]) : d[i + k] !== w[k]) continue outer;
|
|
7884
|
+
return true;
|
|
7885
|
+
}
|
|
7886
|
+
return false;
|
|
7887
|
+
}
|
|
7888
|
+
/** The agent replied since the dispatch with more than an acknowledgement (ACK_LEADING: "On it.", "Sure, one sec."). */
|
|
7889
|
+
answeredSinceDispatch() {
|
|
7890
|
+
return this.repliedSinceDispatch && !_VoiceEngine.ACK_LEADING.test(this.dispatchReply.replace(/[^a-z ]/gi, " ").replace(/\s+/g, " ").trim().toLowerCase());
|
|
7891
|
+
}
|
|
7892
|
+
lastDupPartial = "";
|
|
7893
|
+
// dup_partial diag once per distinct partial
|
|
7377
7894
|
static TRAIL_RE = /(?:^|\s)(?:and|but|or|so|to|the|a|an|of|in|for|with|that|if|uh|um|like|about|from|into|on|is|are|was|were|,)$/i;
|
|
7895
|
+
/** The user's line right after a barge cut our speech (or a re-final growing it), with no terminal punctuation:
|
|
7896
|
+
* they took the floor mid-thought — Soniox closes on the pause, not the thought (live 20260923-192543: "But isn't it"
|
|
7897
|
+
* → "…can be done" → "…with boxing" → "…or semantic?" dispatched 4 times). Held like an incomplete utterance. */
|
|
7898
|
+
unfinishedBargeLine(text) {
|
|
7899
|
+
const line = this.bargedSinceDispatch || this.bargedBeforeDispatch && this.refinalizes(text);
|
|
7900
|
+
return line && !/[.?!…]["'”’)\]]*$/.test(text.trim()) && !_VoiceEngine.CONTROL_RE.test(text.trim());
|
|
7901
|
+
}
|
|
7902
|
+
/** A short line that is complete on its own ("Stop", "Yes", "Okay, stop", "go on") — never held as unfinished. */
|
|
7903
|
+
static CONTROL_RE = ((w) => new RegExp(`^${w}(?:[\\s,]+${w})*[.!?\u2026]*$`, "i"))("(?:stop|wait|yes|yeah|yep|no|nope|okay|ok|go on|continue|never ?mind)");
|
|
7378
7904
|
/** The utterance sounds like the user paused mid-thought (trailing conjunction/filler/comma). */
|
|
7379
7905
|
looksIncomplete(text) {
|
|
7380
|
-
return _VoiceEngine.TRAIL_RE.test(text.trim());
|
|
7906
|
+
return _VoiceEngine.TRAIL_RE.test(text.trim()) && !_VoiceEngine.CONTROL_RE.test(text.trim());
|
|
7381
7907
|
}
|
|
7382
7908
|
handleUtterance(text) {
|
|
7383
|
-
if (this.speaking &&
|
|
7909
|
+
if (this.speaking && this.echoesDispatch(text)) {
|
|
7910
|
+
this.diag("utterance_drop", { reason: "dup_final", text: text.slice(0, 60) });
|
|
7911
|
+
if (this.pausedAt) {
|
|
7912
|
+
this.diag("overlap_resume", { heldMs: Math.round(this.clock.now() - this.pausedAt), reason: "dup_final" });
|
|
7913
|
+
this.resetOverlap(true);
|
|
7914
|
+
}
|
|
7915
|
+
return;
|
|
7916
|
+
}
|
|
7917
|
+
if (this.decideTimer) {
|
|
7918
|
+
this.decideHeldFinal = this.mergeUtterance(this.decideHeldFinal, text);
|
|
7919
|
+
this.diag("utterance_held", { reason: "overlap_decide", text: text.slice(0, 60) });
|
|
7920
|
+
return;
|
|
7921
|
+
}
|
|
7922
|
+
if (this.overlapKeptUntil) {
|
|
7923
|
+
const kept = this.clock.now() < this.overlapKeptUntil && !this.unjudged(text);
|
|
7924
|
+
this.overlapKeptUntil = 0;
|
|
7925
|
+
if (kept) {
|
|
7926
|
+
this.diag("utterance_drop", { reason: "overlap_kept", text: text.slice(0, 60) });
|
|
7927
|
+
return;
|
|
7928
|
+
}
|
|
7929
|
+
}
|
|
7930
|
+
const ownTail = !this.pausedAt && (this.clock.now() < this.bargeGraceUntil || this.refinalizes(text));
|
|
7931
|
+
if (this.speaking && (this.ctxOpen || this.pausedAt) && this.overlapCapable && !ownTail) {
|
|
7384
7932
|
this.diag("utterance_drop", { reason: "overlap_noise", text: text.slice(0, 60) });
|
|
7385
7933
|
this.stt.reset();
|
|
7386
7934
|
return;
|
|
7387
7935
|
}
|
|
7388
|
-
if (this.echoActive() && (!this.options.bargeIn || (this.usingAec ?
|
|
7936
|
+
if (this.echoActive() && (!this.options.bargeIn || (this.usingAec ? this.echoFinal(text) : this.novelWords(text).length < 2))) {
|
|
7389
7937
|
this.diag("echo_swallow", { guard: "echo_gate", text: text.slice(0, 60) });
|
|
7390
7938
|
this.stt.reset();
|
|
7391
7939
|
return;
|
|
@@ -7399,9 +7947,28 @@ var VoiceEngine = class _VoiceEngine {
|
|
|
7399
7947
|
if (this.pendingUtt) this.mergePath = "merged";
|
|
7400
7948
|
this.pendingUtt = this.mergeUtterance(this.pendingUtt, text);
|
|
7401
7949
|
if (this.pendingTimer) this.clock.clearTimeout(this.pendingTimer);
|
|
7402
|
-
if (this.options.
|
|
7950
|
+
if (this.options.adaptiveEndpointing) {
|
|
7951
|
+
const holdMs = computeHoldMs({
|
|
7952
|
+
transcript: this.pendingUtt,
|
|
7953
|
+
lastAiMessage: this.prevReply,
|
|
7954
|
+
baseMs: this.options.utteranceMergeMs,
|
|
7955
|
+
incompleteMs: this.options.incompleteMergeMs
|
|
7956
|
+
});
|
|
7957
|
+
const tier = endpointTier(this.pendingUtt);
|
|
7958
|
+
this.holdTier = tier;
|
|
7959
|
+
this.diag("hold", { reason: "adaptive", tier, punctuated: tier === 3, holdMs, tail: this.pendingUtt.slice(-40) });
|
|
7960
|
+
if (holdMs > this.options.utteranceMergeMs) {
|
|
7961
|
+
this.options.onHold();
|
|
7962
|
+
if (tier === 1 && this.options.holdFiller && !this.speaking) this.speakFiller(this.options.holdFiller);
|
|
7963
|
+
}
|
|
7964
|
+
if (holdMs <= 0) return this.flushUtterance();
|
|
7965
|
+
this.pendingTimer = this.clock.setTimeout(() => this.flushUtterance(), holdMs);
|
|
7966
|
+
return;
|
|
7967
|
+
}
|
|
7968
|
+
const bargeHold = !this.looksIncomplete(this.pendingUtt) && this.unfinishedBargeLine(this.pendingUtt);
|
|
7969
|
+
if (this.options.incompleteMergeMs && (bargeHold || this.looksIncomplete(this.pendingUtt))) {
|
|
7403
7970
|
log12.verbose(`hold: incomplete utterance "${this.pendingUtt.slice(-40)}"`);
|
|
7404
|
-
this.diag("hold", { reason: "incomplete", tail: this.pendingUtt.slice(-40) });
|
|
7971
|
+
this.diag("hold", { reason: bargeHold ? "barge_unfinished" : "incomplete", tail: this.pendingUtt.slice(-40) });
|
|
7405
7972
|
this.options.onHold();
|
|
7406
7973
|
if (this.options.holdFiller && !this.speaking) this.speakFiller(this.options.holdFiller);
|
|
7407
7974
|
this.pendingTimer = this.clock.setTimeout(() => this.flushUtterance(), this.options.incompleteMergeMs);
|
|
@@ -7432,9 +7999,13 @@ var VoiceEngine = class _VoiceEngine {
|
|
|
7432
7999
|
this.pendingUtt = "";
|
|
7433
8000
|
const path = this.mergePath;
|
|
7434
8001
|
this.mergePath = "direct";
|
|
8002
|
+
const heldTier = this.holdTier;
|
|
8003
|
+
this.holdTier = 0;
|
|
7435
8004
|
if (text) {
|
|
7436
|
-
const flat = text
|
|
7437
|
-
|
|
8005
|
+
const flat = normWord(text);
|
|
8006
|
+
const answered = this.answeredSinceDispatch();
|
|
8007
|
+
const part = flat !== this.lastDispatchFlat && !answered && this.echoesDispatch(text);
|
|
8008
|
+
if (part || flat && flat === this.lastDispatchFlat && !answered && this.clock.now() - this.lastDispatchAt < _VoiceEngine.DUP_FINAL_MS) {
|
|
7438
8009
|
log12.verbose(`dropped duplicate final "${text.slice(0, 40)}" (identical to the just-dispatched utterance, no reply between)`);
|
|
7439
8010
|
this.diag("utterance_drop", { reason: "dup_final", text: text.slice(0, 60) });
|
|
7440
8011
|
return;
|
|
@@ -7445,22 +8016,121 @@ var VoiceEngine = class _VoiceEngine {
|
|
|
7445
8016
|
this.diag("utterance_drop", { reason: "refinalized", text: text.slice(0, 60) });
|
|
7446
8017
|
this.lastDispatchFlat = flat;
|
|
7447
8018
|
this.lastDispatchWords = text.trim().split(/\s+/);
|
|
8019
|
+
this.lastDispatchText = text;
|
|
7448
8020
|
return;
|
|
7449
8021
|
}
|
|
8022
|
+
const meta = refinal ? { supersedes: this.lastDispatchText } : void 0;
|
|
7450
8023
|
this.lastDispatchFlat = flat;
|
|
7451
8024
|
this.lastDispatchWords = text.trim().split(/\s+/);
|
|
8025
|
+
this.lastDispatchText = text;
|
|
7452
8026
|
this.lastDispatchAt = this.clock.now();
|
|
7453
8027
|
this.repliedSinceDispatch = false;
|
|
8028
|
+
this.dispatchReply = "";
|
|
7454
8029
|
this.lastDispatchWasQuestion = /\?\s*$/.test(text);
|
|
8030
|
+
this.bargedBeforeDispatch = refinal ? this.bargedBeforeDispatch || this.bargedSinceDispatch : this.bargedSinceDispatch;
|
|
8031
|
+
this.bargedSinceDispatch = false;
|
|
8032
|
+
this.dispatchRefinal = refinal;
|
|
8033
|
+
if (!refinal) this.ackSpent = false;
|
|
7455
8034
|
this.turnStartAt = this.clock.now();
|
|
7456
8035
|
this.bargeGraceUntil = this.clock.now() + this.options.bargeGraceMs;
|
|
7457
|
-
this.diag("dispatch", { text, path: refinal ? "refinalized" : path, question: this.lastDispatchWasQuestion });
|
|
7458
|
-
this.options.onUtterance(text);
|
|
8036
|
+
this.diag("dispatch", { text, path: refinal ? "refinalized" : path, heldTier, question: this.lastDispatchWasQuestion, ...this.bargedBeforeDispatch ? { barged: true } : {} });
|
|
8037
|
+
this.options.onUtterance(text, meta);
|
|
7459
8038
|
}
|
|
7460
8039
|
}
|
|
7461
8040
|
get overlapCapable() {
|
|
7462
8041
|
return this.usingAec && this.options.overlapPause && !!this.player.pause && !!this.player.resume;
|
|
7463
8042
|
}
|
|
8043
|
+
/** Stop/question words that make an overlap an obvious barge — never held for a host decision. */
|
|
8044
|
+
static OVERLAP_CEDE_WORDS = /* @__PURE__ */ new Set([
|
|
8045
|
+
"stop",
|
|
8046
|
+
"wait",
|
|
8047
|
+
"no",
|
|
8048
|
+
"hold",
|
|
8049
|
+
"hang",
|
|
8050
|
+
"pause",
|
|
8051
|
+
"quiet",
|
|
8052
|
+
"enough",
|
|
8053
|
+
"shut",
|
|
8054
|
+
"cancel",
|
|
8055
|
+
"what",
|
|
8056
|
+
"why",
|
|
8057
|
+
"how",
|
|
8058
|
+
"who",
|
|
8059
|
+
"when",
|
|
8060
|
+
"where",
|
|
8061
|
+
"which"
|
|
8062
|
+
]);
|
|
8063
|
+
/** A short, non-urgent overlap: the kind a listener cue or reaction takes (see overlapDecideMs). */
|
|
8064
|
+
shortOverlap(text) {
|
|
8065
|
+
const w = this.words(text);
|
|
8066
|
+
return w.length <= this.options.overlapDecideMaxWords && !/\?/.test(text) && !w.some((x) => _VoiceEngine.OVERLAP_CEDE_WORDS.has(x));
|
|
8067
|
+
}
|
|
8068
|
+
/** Cede the floor to an overlap: interrupt, tell the host, then dispatch a final that was held while deciding. */
|
|
8069
|
+
cedeOverlap(trigger, txt) {
|
|
8070
|
+
const phase = this.ctxOpen ? "speaking" : "drain";
|
|
8071
|
+
const held2 = this.decideHeldFinal;
|
|
8072
|
+
this.decideHeldFinal = "";
|
|
8073
|
+
this.diag("barge_in", { phase, trigger, novel: this.novelWords(txt).length, total: this.words(txt).length });
|
|
8074
|
+
this.interrupt();
|
|
8075
|
+
this.options.onBargeIn(phase);
|
|
8076
|
+
if (held2) this.handleUtterance(held2);
|
|
8077
|
+
}
|
|
8078
|
+
/** Wait (bounded) for the host's verdict. `fresh` = a re-decision on grown text: it gets its own window — the host
|
|
8079
|
+
* was only just asked about it (live: "Oh," → "Oh, that" → "Oh, that— that's new" outgrew every verdict, and the
|
|
8080
|
+
* first window ran out mid-chase, ceding a reaction Jev kept) — but the whole hold is capped at 3× the window. */
|
|
8081
|
+
awaitOverlapDecision(txt, fresh = false) {
|
|
8082
|
+
if (this.decideTimer && !fresh) return;
|
|
8083
|
+
if (this.resumeTimer) {
|
|
8084
|
+
this.clock.clearTimeout(this.resumeTimer);
|
|
8085
|
+
this.resumeTimer = null;
|
|
8086
|
+
}
|
|
8087
|
+
if (this.decideTimer) this.clock.clearTimeout(this.decideTimer);
|
|
8088
|
+
const now4 = this.clock.now(), ms = this.options.overlapDecideMs;
|
|
8089
|
+
if (!this.decideSince) this.decideSince = now4;
|
|
8090
|
+
const wait = Math.min(ms, this.decideSince + 3 * ms - now4);
|
|
8091
|
+
this.diag("overlap_await", { text: txt.slice(0, 60), ms: wait });
|
|
8092
|
+
this.decideTimer = this.clock.setTimeout(() => {
|
|
8093
|
+
this.decideTimer = null;
|
|
8094
|
+
if (this.pausedAt) this.cedeOverlap("overlap_decide_timeout", this.lastOverlapPartial || txt);
|
|
8095
|
+
}, Math.max(0, wait));
|
|
8096
|
+
}
|
|
8097
|
+
/** Words in `text` the host's keep_talking verdict never covered (the overlap grew after it judged). */
|
|
8098
|
+
unjudged(text) {
|
|
8099
|
+
const seen = new Set(this.words(this.overlapKept));
|
|
8100
|
+
return this.words(text).some((w) => !seen.has(w));
|
|
8101
|
+
}
|
|
8102
|
+
/** The host's verdict on the overlap the engine is holding (overlapDecideMs, or any live overlap pause):
|
|
8103
|
+
* 'yield' cedes the floor (a final that landed meanwhile is dispatched); 'keep_talking' resumes playback and
|
|
8104
|
+
* absorbs the rest of THAT reaction — `heard`, the text the verdict judged (default: the live partial); its final
|
|
8105
|
+
* is dropped. Words beyond `heard` are a new overlap, decided afresh: if the partial/final has already grown past
|
|
8106
|
+
* it, the hold stays and `overlap_pause` is re-emitted for a new verdict (bounded by overlapDecideMs, else it
|
|
8107
|
+
* cedes; a re-decision gets its own window, the whole hold capped at 3× it) and this returns false. Also false when no overlap hold is live (the engine already decided). */
|
|
8108
|
+
decideOverlap(choice, heard) {
|
|
8109
|
+
if (!this.pausedAt || !this.speaking) return false;
|
|
8110
|
+
if (choice === "yield") {
|
|
8111
|
+
this.cedeOverlap("host_yield", this.lastOverlapPartial);
|
|
8112
|
+
return true;
|
|
8113
|
+
}
|
|
8114
|
+
this.overlapKept = heard?.trim() || this.lastOverlapPartial;
|
|
8115
|
+
const grown = this.decideHeldFinal || this.lastOverlapPartial;
|
|
8116
|
+
if (this.unjudged(grown)) {
|
|
8117
|
+
if (!(this.options.overlapDecideMs > 0 && this.shortOverlap(grown))) {
|
|
8118
|
+
this.cedeOverlap("overlap_cede", grown);
|
|
8119
|
+
return false;
|
|
8120
|
+
}
|
|
8121
|
+
this.diag("overlap_pause", { text: grown.slice(0, 60), redecide: true });
|
|
8122
|
+
this.awaitOverlapDecision(grown, true);
|
|
8123
|
+
return false;
|
|
8124
|
+
}
|
|
8125
|
+
const held2 = this.decideHeldFinal;
|
|
8126
|
+
this.decideHeldFinal = "";
|
|
8127
|
+
this.diag("overlap_resume", { heldMs: Math.round(this.clock.now() - this.pausedAt), reason: "host_keep" });
|
|
8128
|
+
if (held2) this.diag("utterance_drop", { reason: "overlap_kept", text: held2.slice(0, 60) });
|
|
8129
|
+
this.overlapKeptUntil = held2 ? 0 : this.clock.now() + 4e3;
|
|
8130
|
+
this.resetOverlap(true);
|
|
8131
|
+
this.lastResumeAt = 0;
|
|
8132
|
+
return true;
|
|
8133
|
+
}
|
|
7464
8134
|
armResume() {
|
|
7465
8135
|
if (this.resumeTimer) this.clock.clearTimeout(this.resumeTimer);
|
|
7466
8136
|
this.resumeTimer = this.clock.setTimeout(() => {
|
|
@@ -7476,6 +8146,20 @@ var VoiceEngine = class _VoiceEngine {
|
|
|
7476
8146
|
this.clock.clearTimeout(this.resumeTimer);
|
|
7477
8147
|
this.resumeTimer = null;
|
|
7478
8148
|
}
|
|
8149
|
+
if (this.decideTimer) {
|
|
8150
|
+
this.clock.clearTimeout(this.decideTimer);
|
|
8151
|
+
this.decideTimer = null;
|
|
8152
|
+
}
|
|
8153
|
+
this.decideSince = 0;
|
|
8154
|
+
const held2 = this.decideHeldFinal;
|
|
8155
|
+
this.decideHeldFinal = "";
|
|
8156
|
+
if (held2) {
|
|
8157
|
+
this.diag("utterance_release", { reason: "overlap_hold_exit", text: held2.slice(0, 60) });
|
|
8158
|
+
this.pendingUtt = this.mergeUtterance(this.pendingUtt, held2);
|
|
8159
|
+
if (this.pendingTimer) this.clock.clearTimeout(this.pendingTimer);
|
|
8160
|
+
this.pendingTimer = this.clock.setTimeout(() => this.flushUtterance(), 0);
|
|
8161
|
+
}
|
|
8162
|
+
if (this.pausedAt) this.diag("overlap_end", { resumed: resume, heldMs: Math.round(this.clock.now() - this.pausedAt) });
|
|
7479
8163
|
if (this.pausedAt && resume) {
|
|
7480
8164
|
this.player.resume?.();
|
|
7481
8165
|
this.lastResumeAt = this.clock.now();
|
|
@@ -7541,7 +8225,8 @@ var SentenceCoalescer = class _SentenceCoalescer {
|
|
|
7541
8225
|
feed(delta) {
|
|
7542
8226
|
if (delta) this.buf += delta;
|
|
7543
8227
|
let cut = -1;
|
|
7544
|
-
|
|
8228
|
+
const decimal = (i) => this.buf[i] === "." && /\d/.test(this.buf[i - 1] ?? "") && (i + 1 === this.buf.length || /\d/.test(this.buf[i + 1]));
|
|
8229
|
+
for (let i = 0; i < this.buf.length; i++) if (_SentenceCoalescer.isEnd(this.buf[i]) && !decimal(i)) cut = i;
|
|
7545
8230
|
if (cut < 0) return "";
|
|
7546
8231
|
if (this.buf[cut] !== "\n") while (cut + 1 < this.buf.length && CLOSERS.includes(this.buf[cut + 1])) cut++;
|
|
7547
8232
|
const ready = this.buf.slice(0, cut + 1).trim();
|
|
@@ -7556,9 +8241,14 @@ var SentenceCoalescer = class _SentenceCoalescer {
|
|
|
7556
8241
|
};
|
|
7557
8242
|
var SpokenSplitter = class {
|
|
7558
8243
|
buf = "";
|
|
7559
|
-
|
|
8244
|
+
open = false;
|
|
7560
8245
|
/** True once any spoken char has ever been emitted (drives the no-spoken fallback). */
|
|
7561
8246
|
spokeAny = false;
|
|
8247
|
+
/** Inside a `<spoken>` block after the last feed. Once it is false, a caller coalescing sentences can flush: nothing
|
|
8248
|
+
* more of that block is coming (a held "…in 2026." would otherwise wait for the next spoken text or the stream end). */
|
|
8249
|
+
get inSpoken() {
|
|
8250
|
+
return this.open;
|
|
8251
|
+
}
|
|
7562
8252
|
/** Feed a delta; returns the spoken/detail spans completed by this chunk (either may be ''). */
|
|
7563
8253
|
feed(delta) {
|
|
7564
8254
|
this.buf += delta;
|
|
@@ -7572,26 +8262,26 @@ var SpokenSplitter = class {
|
|
|
7572
8262
|
let spoken = "";
|
|
7573
8263
|
let detail = "";
|
|
7574
8264
|
while (this.buf.length) {
|
|
7575
|
-
const tag = this.
|
|
8265
|
+
const tag = this.open ? CLOSE : OPEN;
|
|
7576
8266
|
const idx = this.buf.indexOf(tag);
|
|
7577
8267
|
if (idx >= 0) {
|
|
7578
8268
|
const text2 = this.buf.slice(0, idx);
|
|
7579
|
-
if (this.
|
|
8269
|
+
if (this.open) spoken += text2;
|
|
7580
8270
|
else detail += text2;
|
|
7581
8271
|
this.buf = this.buf.slice(idx + tag.length);
|
|
7582
|
-
this.
|
|
8272
|
+
this.open = !this.open;
|
|
7583
8273
|
continue;
|
|
7584
8274
|
}
|
|
7585
8275
|
const lt = this.buf.lastIndexOf("<");
|
|
7586
8276
|
const holdStart = lt >= 0 && tag.startsWith(this.buf.slice(lt)) ? lt : this.buf.length;
|
|
7587
8277
|
const text = this.buf.slice(0, holdStart);
|
|
7588
|
-
if (this.
|
|
8278
|
+
if (this.open) spoken += text;
|
|
7589
8279
|
else detail += text;
|
|
7590
8280
|
this.buf = this.buf.slice(holdStart);
|
|
7591
8281
|
break;
|
|
7592
8282
|
}
|
|
7593
8283
|
if (final && this.buf) {
|
|
7594
|
-
if (this.
|
|
8284
|
+
if (this.open) spoken += this.buf;
|
|
7595
8285
|
else detail += this.buf;
|
|
7596
8286
|
this.buf = "";
|
|
7597
8287
|
}
|
|
@@ -7606,7 +8296,11 @@ var now = () => performance.now();
|
|
|
7606
8296
|
var SonioxSTTOptions = class {
|
|
7607
8297
|
auth = "";
|
|
7608
8298
|
source;
|
|
7609
|
-
|
|
8299
|
+
/** `stt-rt-preview` was RETIRED (aliased to the two-generations-old v3 on 2025-10-31), so every
|
|
8300
|
+
* caller that never set this was silently running an old model while the alias kept it working —
|
|
8301
|
+
* the failure mode of a default that is a moving vendor pointer. Pin a real version instead;
|
|
8302
|
+
* `stt-rt-v5` is live today (verified against GET https://api.soniox.com/v1/models). */
|
|
8303
|
+
model = "stt-rt-v5";
|
|
7610
8304
|
languageHints = ["en"];
|
|
7611
8305
|
/** Client-side endpoint: finalized text + no new tokens for this long = utterance (don't wait for
|
|
7612
8306
|
* Soniox's semantic <end>, which adds 0.5-1.5s — the difference between ping-pong and lag). */
|
|
@@ -7979,6 +8673,15 @@ function base64ToBytes(b64) {
|
|
|
7979
8673
|
return out;
|
|
7980
8674
|
}
|
|
7981
8675
|
|
|
8676
|
+
// node_modules/@bod.ee/voice/src/adapters/fish.ts
|
|
8677
|
+
var log15 = forComponent2("FishTTS");
|
|
8678
|
+
|
|
8679
|
+
// node_modules/@bod.ee/voice/src/adapters/grok.ts
|
|
8680
|
+
var log16 = forComponent2("GrokTTS");
|
|
8681
|
+
|
|
8682
|
+
// node_modules/@bod.ee/voice/src/adapters/grok-stt.ts
|
|
8683
|
+
var log17 = forComponent2("GrokSTT");
|
|
8684
|
+
|
|
7982
8685
|
// src/voice/engine.ts
|
|
7983
8686
|
init_logging();
|
|
7984
8687
|
configureLogging((name) => {
|
|
@@ -7987,8 +8690,431 @@ configureLogging((name) => {
|
|
|
7987
8690
|
return { debug: at("debug"), verbose: at("verbose"), info: at("info"), warn: at("warn"), error: at("error") };
|
|
7988
8691
|
});
|
|
7989
8692
|
|
|
8693
|
+
// src/voice/instinct.ts
|
|
8694
|
+
init_logging();
|
|
8695
|
+
var log18 = forComponent("Instinct");
|
|
8696
|
+
var InstinctOptions = class {
|
|
8697
|
+
decider;
|
|
8698
|
+
/** Partial unchanged this long (a micro-pause) → consult. */
|
|
8699
|
+
stableMs = 250;
|
|
8700
|
+
/** Don't consult on fragments shorter than this. */
|
|
8701
|
+
minWords = 4;
|
|
8702
|
+
/** Act only on the TOP choice, and only above its floor (live eval 2026-09-23: a correct cut-in often
|
|
8703
|
+
* tops at 0.6-0.8; a mid-thought "we could maybe" drew a 0.58 backchannel that must not fire). */
|
|
8704
|
+
backchannelMin = 0.65;
|
|
8705
|
+
interjectMin = 0.6;
|
|
8706
|
+
yieldMin = 0.7;
|
|
8707
|
+
backchannelGapMs = 5e3;
|
|
8708
|
+
interjectGapMs = 2e4;
|
|
8709
|
+
/** A decision whose partial grew by this many words while in flight is stale → dropped. */
|
|
8710
|
+
staleWords = 3;
|
|
8711
|
+
/** Overlap: consult only once the engine has HELD the pause this long without ceding. The engine cedes on
|
|
8712
|
+
* the 2nd novel word (~200ms after the pause, live 2026-09-23) — a call fired at the pause lands after that
|
|
8713
|
+
* (~300-400ms) and can never act. A hold that survives this window is the undecided case (a 1-word overlap
|
|
8714
|
+
* the engine would RESUME over at overlapResumeMs=700) — the one where a yield actually changes the outcome. */
|
|
8715
|
+
overlapSettleMs = 250;
|
|
8716
|
+
/** ackFor waits this long for the host's ackOutcome before treating the ack as unspoken. Hosts set it to the engine's
|
|
8717
|
+
* last chance to fire (bod-voice: 2×adaptiveAckMs — past that a pending pick is dropped as pick_late). */
|
|
8718
|
+
ackSettleMs = 1500;
|
|
8719
|
+
context = () => ({});
|
|
8720
|
+
/** Actions return `false` when the host could not act (engine state moved on) → logged as `<act>_skipped`. */
|
|
8721
|
+
onBackchannel = () => {
|
|
8722
|
+
};
|
|
8723
|
+
onInterject = () => {
|
|
8724
|
+
};
|
|
8725
|
+
onYield = () => {
|
|
8726
|
+
};
|
|
8727
|
+
/** The overlap was judged a listener cue — carry on. Hosts whose engine HOLDS short overlaps for a verdict
|
|
8728
|
+
* (bod-voice overlapDecideMs) resume it here; otherwise leave the default no-op (the engine decides). */
|
|
8729
|
+
onKeepTalking = () => {
|
|
8730
|
+
};
|
|
8731
|
+
onDecision = () => {
|
|
8732
|
+
};
|
|
8733
|
+
now = () => performance.now();
|
|
8734
|
+
};
|
|
8735
|
+
var ACK_SITUATIONS = {
|
|
8736
|
+
hard_question: `a question that takes real thought, judgment or looking something up ("what's the biggest takeaway?", "how should I structure this?")`,
|
|
8737
|
+
simple_question: 'a quick question with an instant, obvious answer ("how are you?", "what time is it?", "can you hear me?")',
|
|
8738
|
+
emotional_bad: "they share something bad, sad, painful, worrying or frustrating",
|
|
8739
|
+
emotional_good: "they share good news, excitement, relief or pride",
|
|
8740
|
+
challenge: `they doubt, question or push back on what you just said ("are you sure?", "why do you say that?", "that doesn't sound right")`,
|
|
8741
|
+
surprise: `they react with surprise or disbelief to what you said ("oh, that's new", "really?", "no way", "oh.")`,
|
|
8742
|
+
agreement: `they agree with you, confirm, or tell you to go on ("exactly", "yes, that's it", "okay, so continue")`,
|
|
8743
|
+
goodbye: "they are wrapping up the conversation or saying goodbye",
|
|
8744
|
+
command: 'a request or instruction for you to do, find, check or tell them something ("tell me the news", "check my calendar")',
|
|
8745
|
+
silent: 'ONLY when nothing was really said yet: an unfinished fragment or false start, a mic check or count ("one, two"), a bare greeting or filler ("hey", "um")'
|
|
8746
|
+
};
|
|
8747
|
+
var ACK_BANK = {
|
|
8748
|
+
hard_question: ["Hmm, let me think on that.", "Ooh, interesting one.", "Hm, that's a big one.", "Let's see here."],
|
|
8749
|
+
simple_question: ["Oh, well, so\u2014", "Well, let's see\u2014", "Oh, easy one\u2014"],
|
|
8750
|
+
challenge: ["Fair question.", "Mm, fair to ask.", "Hm, okay, so\u2014", "Ah, I get why\u2014"],
|
|
8751
|
+
emotional_bad: ["Oh, I'm sorry.", "Ugh, that's rough.", "Aw, that's hard.", "Oh man, I'm sorry."],
|
|
8752
|
+
emotional_good: ["Oh, that's great!", "Oh, that's awesome!", "Oh, nice one!", "Love to hear it!"],
|
|
8753
|
+
surprise: ["Right? Pretty wild.", "Yeah, wild, huh?", "Huh, I know.", "Wild, isn't it?"],
|
|
8754
|
+
agreement: ["Mm, good, so\u2014", "Yeah, so\u2014", "Alright, so\u2014", "Yep, with you."],
|
|
8755
|
+
goodbye: ["Alright, catch you later.", "Great chatting.", "Okay, all set then."],
|
|
8756
|
+
command: ["On it.", "Sure, one sec.", "Got it, one moment.", "Sure thing, one sec."],
|
|
8757
|
+
silent: [],
|
|
8758
|
+
// interruption acks, keyed on the barge intent
|
|
8759
|
+
stop: ["Sure, stopping.", "Okay, stopping here.", "Got it, I'll stop."],
|
|
8760
|
+
aside: ["Oh, quick one\u2014", "Ah, sure, so\u2014", "Oh, right, so\u2014"],
|
|
8761
|
+
steer: ["Ah, okay, switching\u2014", "Ah, got it, so\u2014", "Oh, gotcha, sure\u2014"],
|
|
8762
|
+
resume: ["Right, so\u2014", "Anyway, so\u2014", "So, as I was saying\u2014"]
|
|
8763
|
+
};
|
|
8764
|
+
var INTENT_ACK_OVER = {
|
|
8765
|
+
stop: Object.keys(ACK_SITUATIONS).filter((s) => s !== "silent"),
|
|
8766
|
+
steer: ["command"],
|
|
8767
|
+
resume: ["agreement", "silent"],
|
|
8768
|
+
aside: []
|
|
8769
|
+
};
|
|
8770
|
+
function interruptionNote(cut, intent) {
|
|
8771
|
+
const full = cut.full.trim();
|
|
8772
|
+
let at = Math.min(cut.heard.length, cut.full.length);
|
|
8773
|
+
if (/\S/.test(cut.full[at] ?? "") && /\S/.test(cut.full[at - 1] ?? "")) at = cut.full.lastIndexOf(" ", at) + 1;
|
|
8774
|
+
const heardWords = cut.full.slice(0, at).trim().split(/\s+/).filter(Boolean).length;
|
|
8775
|
+
const unheard = cut.full.slice(at).trim();
|
|
8776
|
+
const landed = heardWords < 4 ? "They cut in almost at once \u2014 treat all of it as unsaid." : `They heard everything before this part. They missed the rest of it: "${unheard}".`;
|
|
8777
|
+
const how = {
|
|
8778
|
+
resume: "They did not ask anything new. Carry on with the part they missed \u2014 no restart, no apology.",
|
|
8779
|
+
aside: "It was an aside. Answer it briefly FIRST, then finish the part they missed, adjusted to anything they just said. Say each point once: skip whatever they already heard and whatever your answer just covered.",
|
|
8780
|
+
steer: "They steered away. Follow their new direction; carry over only what still matters from your unfinished point, or drop it.",
|
|
8781
|
+
stop: "They want you to stop. Do not resume; at most a few words of acknowledgement.",
|
|
8782
|
+
unknown: "Decide like a person would: if it was an aside, answer it and then finish your point; if they steered away, follow them and drop or adapt the rest."
|
|
8783
|
+
};
|
|
8784
|
+
return `
|
|
8785
|
+
[the user interrupted you mid-speech. You were saying: "${full}" ${landed} ${how[intent ?? "unknown"]} Just talk, like a person picking the thread back up: never tell them what they heard or missed, never say where you were cut off, and never quote your earlier words back. If their words are still an unfinished fragment, call Hold instead of answering.]`;
|
|
8786
|
+
}
|
|
8787
|
+
var FRAME = "You are the instinct of a warm, attentive human in a live spoken conversation. Decide what a natural human would do THIS instant \u2014 the way people do without thinking. ";
|
|
8788
|
+
var acted = (what, r) => r === false ? `${what}_skipped` : what;
|
|
8789
|
+
var words = (s) => s.trim() ? s.trim().split(/\s+/).length : 0;
|
|
8790
|
+
var Instinct = class {
|
|
8791
|
+
constructor(options) {
|
|
8792
|
+
this.options = options;
|
|
8793
|
+
this.options = { ...new InstinctOptions(), ...options };
|
|
8794
|
+
}
|
|
8795
|
+
options;
|
|
8796
|
+
partial = "";
|
|
8797
|
+
turnStart = 0;
|
|
8798
|
+
timer = null;
|
|
8799
|
+
inflight = false;
|
|
8800
|
+
lastBcAt = -Infinity;
|
|
8801
|
+
lastInterjectAt = -Infinity;
|
|
8802
|
+
lastIntent;
|
|
8803
|
+
overlapGen = 0;
|
|
8804
|
+
// bumped by overlapEnded / a newer overlap → cancels a pending or in-flight overlap consult
|
|
8805
|
+
lastAckPick;
|
|
8806
|
+
interjecting = false;
|
|
8807
|
+
// inside onInterject — see pickAck
|
|
8808
|
+
lastAckSaid = "";
|
|
8809
|
+
get o() {
|
|
8810
|
+
return this.options;
|
|
8811
|
+
}
|
|
8812
|
+
/** A live user partial while the agent is LISTENING. Consults once the partial goes stable. */
|
|
8813
|
+
hear(text) {
|
|
8814
|
+
const t = text.trim();
|
|
8815
|
+
if (!t || t === this.partial) return;
|
|
8816
|
+
this.partial = t;
|
|
8817
|
+
if (!this.turnStart) this.turnStart = this.o.now();
|
|
8818
|
+
if (this.timer) clearTimeout(this.timer);
|
|
8819
|
+
this.timer = setTimeout(() => {
|
|
8820
|
+
this.timer = null;
|
|
8821
|
+
void this.consult(t);
|
|
8822
|
+
}, this.o.stableMs);
|
|
8823
|
+
}
|
|
8824
|
+
/** The user's turn ended (final dispatched, or the agent took the floor) — forget the partial, and drop any
|
|
8825
|
+
* pending overlap consult: whatever hold it was about is over. */
|
|
8826
|
+
reset() {
|
|
8827
|
+
this.overlapGen++;
|
|
8828
|
+
if (this.timer) clearTimeout(this.timer);
|
|
8829
|
+
this.timer = null;
|
|
8830
|
+
this.partial = "";
|
|
8831
|
+
this.turnStart = 0;
|
|
8832
|
+
}
|
|
8833
|
+
async consult(heard) {
|
|
8834
|
+
if (this.inflight || words(heard) < this.o.minWords) return;
|
|
8835
|
+
this.inflight = true;
|
|
8836
|
+
try {
|
|
8837
|
+
const now4 = this.o.now();
|
|
8838
|
+
const d = await this.ask("listen", heard, {
|
|
8839
|
+
heard_so_far: heard,
|
|
8840
|
+
user_speaking_for_ms: Math.round(now4 - this.turnStart),
|
|
8841
|
+
ms_since_our_last_backchannel: Number.isFinite(this.lastBcAt) ? Math.round(now4 - this.lastBcAt) : null
|
|
8842
|
+
}, FRAME + "The user is mid-turn and just paused for a split second. Do you keep quiet, give a tiny listener cue, or cut in? Cut in only when a human really would: they are clearly wrong about something that matters, they are struggling for a word you know, or they asked something and are trailing off.", {
|
|
8843
|
+
stay_silent: "keep listening \u2014 they are mid-thought, nothing to add",
|
|
8844
|
+
backchannel: 'a tiny "mm-hm"/"right" to show you are following, without taking the turn (fits after a clause in a longer story or explanation)',
|
|
8845
|
+
interject: "cut in now with a short correction, the word they are reaching for, or an answer"
|
|
8846
|
+
});
|
|
8847
|
+
if (!d) return;
|
|
8848
|
+
if (!this.partial || words(this.partial) - words(heard) >= this.o.staleWords) return this.o.onDecision({ ...d, acted: "stale" });
|
|
8849
|
+
const p = d.probabilities, t = this.o.now();
|
|
8850
|
+
if (d.choice === "interject" && p.interject >= this.o.interjectMin && t - this.lastInterjectAt > this.o.interjectGapMs) {
|
|
8851
|
+
this.lastInterjectAt = t;
|
|
8852
|
+
const at = this.partial;
|
|
8853
|
+
this.reset();
|
|
8854
|
+
this.interjecting = true;
|
|
8855
|
+
let r;
|
|
8856
|
+
try {
|
|
8857
|
+
r = this.o.onInterject(at);
|
|
8858
|
+
} finally {
|
|
8859
|
+
this.interjecting = false;
|
|
8860
|
+
}
|
|
8861
|
+
this.o.onDecision({ ...d, acted: acted("interject", r) });
|
|
8862
|
+
} else if (d.choice === "backchannel" && p.backchannel >= this.o.backchannelMin && t - this.lastBcAt > this.o.backchannelGapMs) {
|
|
8863
|
+
this.lastBcAt = t;
|
|
8864
|
+
this.o.onDecision({ ...d, acted: acted("backchannel", this.o.onBackchannel()) });
|
|
8865
|
+
} else this.o.onDecision(d);
|
|
8866
|
+
} finally {
|
|
8867
|
+
this.inflight = false;
|
|
8868
|
+
}
|
|
8869
|
+
}
|
|
8870
|
+
/** The user started talking OVER the agent (engine paused on a genuine overlap). Yield or keep going?
|
|
8871
|
+
* Consulted only if the engine is STILL holding after overlapSettleMs — see overlapEnded(). */
|
|
8872
|
+
async overlap(heard) {
|
|
8873
|
+
if (!heard.trim()) return;
|
|
8874
|
+
const gen = ++this.overlapGen;
|
|
8875
|
+
if (this.o.overlapSettleMs > 0) await new Promise((r) => setTimeout(r, this.o.overlapSettleMs));
|
|
8876
|
+
if (gen !== this.overlapGen) return;
|
|
8877
|
+
const d = await this.ask(
|
|
8878
|
+
"overlap",
|
|
8879
|
+
heard,
|
|
8880
|
+
{ user_said_over_us: heard },
|
|
8881
|
+
FRAME + "You are mid-sentence and the user just said something over you. Would a human stop and give them the floor, or treat it as a listener cue and carry on?",
|
|
8882
|
+
{
|
|
8883
|
+
yield: 'they want the floor \u2014 an objection, question, correction, "stop"/"wait", or new information',
|
|
8884
|
+
keep_talking: 'just a listener cue or agreement ("yeah", "mm-hm", "right", "okay") \u2014 carry on'
|
|
8885
|
+
}
|
|
8886
|
+
);
|
|
8887
|
+
if (d && gen !== this.overlapGen) this.o.onDecision({ ...d, acted: "stale" });
|
|
8888
|
+
else if (d && (d.probabilities.yield ?? 0) >= this.o.yieldMin) {
|
|
8889
|
+
this.o.onDecision({ ...d, acted: acted("yield", this.o.onYield(heard)) });
|
|
8890
|
+
} else if (d?.choice === "keep_talking") {
|
|
8891
|
+
this.o.onDecision({ ...d, acted: acted("keep_talking", this.o.onKeepTalking(heard)) });
|
|
8892
|
+
} else if (d) this.o.onDecision(d);
|
|
8893
|
+
}
|
|
8894
|
+
/** The engine's hold ended (it ceded the floor, resumed over a stalled overlap, began a new turn, or was
|
|
8895
|
+
* interrupted) — drop any pending/in-flight overlap consult. Hosts call this on every hold exit. */
|
|
8896
|
+
overlapEnded() {
|
|
8897
|
+
this.overlapGen++;
|
|
8898
|
+
}
|
|
8899
|
+
/** What the user meant by cutting us off mid-speech. Memoized per text (the duplex judge and the host's
|
|
8900
|
+
* note builder ask about the same line). Rejects on decider failure — callers pick their fallback. */
|
|
8901
|
+
bargeIntent(heard) {
|
|
8902
|
+
if (this.lastIntent?.heard === heard) return this.lastIntent.p;
|
|
8903
|
+
const p = this.ask(
|
|
8904
|
+
"barge_intent",
|
|
8905
|
+
heard,
|
|
8906
|
+
{ user_said_after_cutting_us_off: heard },
|
|
8907
|
+
FRAME + "You were in the middle of saying something (what_we_said_last) and the user cut you off with this. What would a human take from it?",
|
|
8908
|
+
{
|
|
8909
|
+
resume: 'nothing new \u2014 a filler, apology, or "go on": just pick up where you left off',
|
|
8910
|
+
aside: "a quick question, comment, or clarification about what you were saying \u2014 answer it, then carry on with your point",
|
|
8911
|
+
steer: "they are redirecting \u2014 a different topic, a correction of your plan, or a new request that replaces what you were saying",
|
|
8912
|
+
stop: "they want you to stop talking or drop it"
|
|
8913
|
+
},
|
|
8914
|
+
true
|
|
8915
|
+
).then((d) => {
|
|
8916
|
+
if (d) this.o.onDecision({ ...d, acted: d.choice });
|
|
8917
|
+
return d?.choice ?? "steer";
|
|
8918
|
+
});
|
|
8919
|
+
this.lastIntent = { heard, p };
|
|
8920
|
+
return p;
|
|
8921
|
+
}
|
|
8922
|
+
/** The ack for a finished user turn (engine `pickAck`, asked at dispatch): one Choice over ACK_SITUATIONS, run in
|
|
8923
|
+
* parallel with the reflex. After a barge the interruption's intent (bargeIntent, memoized — the same call the note
|
|
8924
|
+
* builder makes) replaces the situations in INTENT_ACK_OVER with its own ack; the rest keep the situational ack.
|
|
8925
|
+
* `null` = say nothing. Never rejects: a failed Choice → silence (logged in ask) — a wrong ack is worse than none,
|
|
8926
|
+
* and a slow reflex still gets the dead-air repair.
|
|
8927
|
+
* A cut-in (asked from inside onInterject) is always silent: it has no dispatch, so the engine's context carries the
|
|
8928
|
+
* user's PREVIOUS final (live: "My dog died yesterday." re-acked "Oh no." before a cut-in correction), and the
|
|
8929
|
+
* unfinished partial is no turn to react to — the interjection itself is the reply. */
|
|
8930
|
+
pickAck(ctx) {
|
|
8931
|
+
if (this.interjecting) {
|
|
8932
|
+
log18.debug(`ack: cut-in turn \u2192 silent (engine context "${ctx.text.slice(0, 40)}" is the previous final)`);
|
|
8933
|
+
return Promise.resolve(null);
|
|
8934
|
+
}
|
|
8935
|
+
const text = ctx.text.trim();
|
|
8936
|
+
const p = (async () => {
|
|
8937
|
+
const intentP = ctx.barged ? this.bargeIntent(text).catch((e) => {
|
|
8938
|
+
log18.warn(`barge intent for the ack failed \u2014 situational ack: ${e.message}`);
|
|
8939
|
+
return null;
|
|
8940
|
+
}) : null;
|
|
8941
|
+
const d = await this.ask(
|
|
8942
|
+
"ack",
|
|
8943
|
+
text,
|
|
8944
|
+
{ user_just_said: text },
|
|
8945
|
+
FRAME + "The user just finished speaking (user_just_said) and your real reply is a moment away. Classify what they said, so the fitting quick acknowledgement can be voiced first. Pick the category that matches their words; most requests and questions are NOT silent.",
|
|
8946
|
+
ACK_SITUATIONS
|
|
8947
|
+
);
|
|
8948
|
+
const sit = d?.choice ?? "silent";
|
|
8949
|
+
const intent = intentP ? await intentP : null;
|
|
8950
|
+
const key = intent && INTENT_ACK_OVER[intent].includes(sit) ? intent : sit;
|
|
8951
|
+
const phrase = this.rotate(ACK_BANK[key] ?? []);
|
|
8952
|
+
if (d) this.o.onDecision({ ...d, acted: phrase ? `${key}: ${phrase}` : `${key}: silent` });
|
|
8953
|
+
return phrase;
|
|
8954
|
+
})();
|
|
8955
|
+
let settle;
|
|
8956
|
+
const spoken = new Promise((r) => {
|
|
8957
|
+
settle = r;
|
|
8958
|
+
});
|
|
8959
|
+
const timer = setTimeout(() => {
|
|
8960
|
+
log18.debug(`ack: no engine outcome in ${this.o.ackSettleMs}ms \u2014 not claimed`);
|
|
8961
|
+
settle(null);
|
|
8962
|
+
}, this.o.ackSettleMs);
|
|
8963
|
+
void spoken.then(() => clearTimeout(timer));
|
|
8964
|
+
this.lastAckPick = { text, p, spoken, settle };
|
|
8965
|
+
return p;
|
|
8966
|
+
}
|
|
8967
|
+
/** The host reports what the engine did with the armed ack: the phrase it actually spoke, or null (silent, late,
|
|
8968
|
+
* cancelled). First report per pick wins — a later turn's cancel of an already-spoken ack changes nothing. */
|
|
8969
|
+
ackOutcome(said) {
|
|
8970
|
+
this.lastAckPick?.settle(said);
|
|
8971
|
+
}
|
|
8972
|
+
/** What was said out loud to open the reply to this exact text — lets a host tell the reply turn, without a second
|
|
8973
|
+
* call. Only an ack the engine actually SPOKE (ackOutcome): a pick that lands after the engine's deadline is never
|
|
8974
|
+
* claimed. null: nothing picked, not spoken, not asked, or no outcome within ackSettleMs of the pick's start.
|
|
8975
|
+
* Never waits past that cap (a hung pick included), and returns as soon as the outcome settles. */
|
|
8976
|
+
async ackFor(text) {
|
|
8977
|
+
const pick = this.lastAckPick;
|
|
8978
|
+
if (pick?.text !== text.trim()) return null;
|
|
8979
|
+
return Promise.race([pick.p.then((p) => p ? pick.spoken : null), pick.spoken]);
|
|
8980
|
+
}
|
|
8981
|
+
/** A random phrase from `pool`, never the one said last (no back-to-back repeat across keys). */
|
|
8982
|
+
rotate(pool) {
|
|
8983
|
+
const fresh = pool.filter((x) => x !== this.lastAckSaid);
|
|
8984
|
+
const from = fresh.length ? fresh : pool;
|
|
8985
|
+
if (!from.length) return null;
|
|
8986
|
+
return this.lastAckSaid = from[Math.floor(Math.random() * from.length)];
|
|
8987
|
+
}
|
|
8988
|
+
async ask(kind, heard, state, instructions, criteria, rethrow = false) {
|
|
8989
|
+
const t0 = this.o.now();
|
|
8990
|
+
try {
|
|
8991
|
+
const ctx = this.o.context();
|
|
8992
|
+
const { answers } = await this.o.decider.decide({
|
|
8993
|
+
state: { ...state, what_we_said_last: ctx.agentSaid || null, recent_conversation: ctx.recent || null },
|
|
8994
|
+
questions: { act: { type: "choice", instructions, criteria } }
|
|
8995
|
+
});
|
|
8996
|
+
return { kind, heard, choice: answers.act.choice, probabilities: answers.act.probabilities, ms: Math.round(this.o.now() - t0) };
|
|
8997
|
+
} catch (e) {
|
|
8998
|
+
log18.warn(`${kind} decision failed \u2014 falling back to engine defaults: ${e.message}`);
|
|
8999
|
+
if (rethrow) throw e;
|
|
9000
|
+
return null;
|
|
9001
|
+
}
|
|
9002
|
+
}
|
|
9003
|
+
};
|
|
9004
|
+
|
|
9005
|
+
// src/voice/unsaid.ts
|
|
9006
|
+
init_logging();
|
|
9007
|
+
var log19 = forComponent("Unsaid");
|
|
9008
|
+
var STOP2 = new Set("that this with have from they them their there then than what when were will would your about into just also been some only over more most very which while after before because these those does here".split(" "));
|
|
9009
|
+
var contentStems = (s) => (s.toLowerCase().match(/[a-z0-9']+/g) ?? []).filter((w) => w.length >= 4 && !STOP2.has(w)).map((w) => w.slice(0, 4));
|
|
9010
|
+
var SAID_OVERLAP = 0.6;
|
|
9011
|
+
var UNSAID_OVERLAP = 0.25;
|
|
9012
|
+
var CONVEYED_MIN = 0.3;
|
|
9013
|
+
function splitClauses(text) {
|
|
9014
|
+
return text.split(/(?<=[.!?…])\s+|(?<=;)\s+|(?<=,)\s+(?=(?:and|but)\b)/i).map((s) => s.trim()).filter((s) => contentStems(s).length > 0);
|
|
9015
|
+
}
|
|
9016
|
+
var overlap = (clause, said) => {
|
|
9017
|
+
const w = contentStems(clause);
|
|
9018
|
+
return w.filter((x) => said.has(x)).length / w.length;
|
|
9019
|
+
};
|
|
9020
|
+
var INSTRUCTIONS = "A voice assistant was interrupted mid-delivery; ASSISTANT_SAID is what it then said aloud. Did the MAIN POINT of this clause of the unheard delivery reach the listener through ASSISTANT_SAID \u2014 would hearing the clause too add nothing important? Different words, casual phrasing, rounder numbers, or a missing minor detail (a name, an exact figure) still count as conveyed. Not conveyed only when the clause's main point is absent from ASSISTANT_SAID, even if a neighbouring point is there.";
|
|
9021
|
+
async function unsaidClauses(pieces, spoken, decider, timeoutMs = 5e3) {
|
|
9022
|
+
const said = new Set(contentStems(spoken));
|
|
9023
|
+
const open = splitClauses(pieces.join(" ")).map((c) => ({ c, r: overlap(c, said) })).filter((x) => x.r < SAID_OVERLAP);
|
|
9024
|
+
if (!open.length) return [];
|
|
9025
|
+
const fallback = () => open.filter((x) => x.r < UNSAID_OVERLAP).map((x) => x.c);
|
|
9026
|
+
if (!decider) return fallback();
|
|
9027
|
+
const state = { assistant_said: spoken };
|
|
9028
|
+
const questions = {};
|
|
9029
|
+
open.forEach((x, i) => {
|
|
9030
|
+
state[`c${i}`] = x.c;
|
|
9031
|
+
questions[`c${i}`] = { type: "noul", instructions: `${INSTRUCTIONS} The clause is c${i}.`, criteria: { true: `the main point of c${i} reached the listener`, false: `the main point of c${i} is missing` } };
|
|
9032
|
+
});
|
|
9033
|
+
let timer;
|
|
9034
|
+
try {
|
|
9035
|
+
const { answers } = await Promise.race([
|
|
9036
|
+
decider.decide({ state, questions }),
|
|
9037
|
+
new Promise((_, rej) => {
|
|
9038
|
+
timer = setTimeout(() => rej(new Error(`no verdict in ${timeoutMs}ms`)), timeoutMs);
|
|
9039
|
+
})
|
|
9040
|
+
]);
|
|
9041
|
+
return open.filter((_, i) => {
|
|
9042
|
+
const p = Number(answers[`c${i}`]?.noul);
|
|
9043
|
+
if (!Number.isFinite(p)) throw new Error(`no noul for c${i}`);
|
|
9044
|
+
return p < CONVEYED_MIN;
|
|
9045
|
+
}).map((x) => x.c);
|
|
9046
|
+
} catch (e) {
|
|
9047
|
+
log19.warn(`unsaid judge failed \u2014 only near-zero-overlap clauses count as unsaid: ${e.message}`);
|
|
9048
|
+
return fallback();
|
|
9049
|
+
} finally {
|
|
9050
|
+
clearTimeout(timer);
|
|
9051
|
+
}
|
|
9052
|
+
}
|
|
9053
|
+
|
|
9054
|
+
// src/voice/leak.ts
|
|
9055
|
+
var TOOL = String.raw`(?:QuickLook|TaskStatus|CancelTask|AnswerTask|ExitSession|Act|Think|Hold(?! on\b))`;
|
|
9056
|
+
var SUSPECT = [
|
|
9057
|
+
/\b(?:user|assistant)\b/i,
|
|
9058
|
+
/\b(?:instructions?|guidelines?|polic(?:y|ies)|system prompt|developer (?:message|instructions?|prompt))\b/i,
|
|
9059
|
+
new RegExp(String.raw`\b${TOOL}\b`),
|
|
9060
|
+
/\bwe (?:need to|have to|should|must|ought to)\b|(?:^|[.!?]\s*)(?:need to|should|must|let's)\b/i,
|
|
9061
|
+
/\bi (?:need to|have to|should|must) (?:respond|reply|answer|output|produce|comply|acknowledge|say|ask|greet|call|use|dispatch|wait|keep|avoid|not)\b/i,
|
|
9062
|
+
/\b(?:respond|reply|output|produce|comply|acknowledge?)\w*\b/i,
|
|
9063
|
+
/\bwe(?: have|'ve)\b|\bwe (?:already )?(?:responded|replied|dispatched|used|called|did|gave|said|asked)\b/i,
|
|
9064
|
+
/\bno (?:further|more|other)\b/i,
|
|
9065
|
+
/\[\s*task\b|\bt\d+\b|\bwait(?:ing)? for (?:the )?(?:events?|results?|task)\b/i,
|
|
9066
|
+
/\w\s*\{\s*"|\bwhat:\s*"/,
|
|
9067
|
+
/\b(?:last|previous) (?:response|reply|message|turn)\b|\bthe (?:conversation|transcript|context)\b/i
|
|
9068
|
+
];
|
|
9069
|
+
var STRICT = [
|
|
9070
|
+
// the listener as a third-person subject opening the sentence ("The user wants…", telegraphic "User wants…")
|
|
9071
|
+
/^(?:the )?user(?:'s)? (?:asks|asked|wants|wanted|said|says|is (?:asking|saying|speaking|referring|requesting)|just (?:said|asked)|requests|requested|mentioned|seems|keeps|repeated|typed|provided|expects|explicitly)\b/i,
|
|
9072
|
+
/\b(?:if|when|since|because) user (?:is|keeps|wants|says|said|asks|asked|seems)\b/i,
|
|
9073
|
+
/\bwe have (?:an? )?(?:user (?:who|request|message|asking|saying)|conversation (?:where|with)|new user message)\b|^we have task\b/i,
|
|
9074
|
+
/\bthe assistant(?:'s (?:context|last|previous) (?:response|reply|turn|message)| (?:responded|replied) with)\b/i,
|
|
9075
|
+
// planning its own reply
|
|
9076
|
+
/\b(?:we|i) (?:need to|have to|should|must) (?:respond|reply|answer)(?:\s*:|\s+(?:briefly|concisely|accordingly|according to|appropriately|to the user|with (?:a |the )?(?:brief|short|result|acknowledg)))/i,
|
|
9077
|
+
/\b(?:we|i) (?:need to|should|must) output\b|^(?:we|i) must comply[.!]?$/i,
|
|
9078
|
+
/\bno (?:further|more|other) (?:response|reply|output)s? (?:is )?(?:needed|required|necessary)\b/i,
|
|
9079
|
+
/\bwe(?: have|'ve)? (?:already )?(?:responded|replied)[.!]?$/i,
|
|
9080
|
+
// its own protocol: using its tools, tool-call syntax, task events
|
|
9081
|
+
new RegExp(String.raw`(?:\b[Ww]e(?: need to| should| must| have to| will|'ll)|\b[Ll]et'?s|^[Ss]hould|^[Nn]ow we should) (?:call|use|do|dispatch(?: to)?|invoke) (?:the )?${TOOL}\b`),
|
|
9082
|
+
new RegExp(String.raw`\b(?:[Ww]e (?:called|dispatched)|responded with) ${TOOL}\b|\b${TOOL}\s*\{|\bwhat:\s*"|\b${TOOL} (?:tool )?(?:brief|call|args?|arguments)\b`),
|
|
9083
|
+
/\bwait(?:ing)? for (?:the )?(?:events?|t\d+)\b|\bt\d+ (?:completed|failed)\b|\[\s*task\b/i
|
|
9084
|
+
];
|
|
9085
|
+
var SENTENCE_END = new RegExp(`[.!?\u2026]+["')\\]]*(?:\\s|(?=\\p{Lu}|\\[))`, "gu");
|
|
9086
|
+
var SENTENCE_SPLIT = new RegExp(`(?<=[.!?\u2026]+["')\\]]*)(?:\\s+|(?=\\p{Lu}|\\[))`, "u");
|
|
9087
|
+
var clean = (s) => s.replace(/\[[a-z_ ]+\]\s*/gi, "").trim();
|
|
9088
|
+
function isLeakSuspect(sentence) {
|
|
9089
|
+
const s = clean(sentence);
|
|
9090
|
+
return SUSPECT.some((re) => re.test(s));
|
|
9091
|
+
}
|
|
9092
|
+
function isStrictLeak(sentence) {
|
|
9093
|
+
return sentence.split(SENTENCE_SPLIT).some((x) => {
|
|
9094
|
+
const s = clean(x);
|
|
9095
|
+
return STRICT.some((re) => re.test(s));
|
|
9096
|
+
});
|
|
9097
|
+
}
|
|
9098
|
+
var JUDGE_INSTRUCTIONS = `This sentence was produced by a voice assistant's reply stream and is about to be read aloud to the user. Is it the assistant's private scratchpad reasoning that leaked out \u2014 talking ABOUT the conversation instead of TO the listener? Leaked reasoning: refers to the listener in the third person ("the user wants\u2026", "user said\u2026"), plans its own reply ("we need to respond\u2026", "we should output\u2026", "I should answer briefly"), cites its own guidelines/instructions, or narrates its internal tool calls and task events (QuickLook, Act, Think, Hold, TaskStatus, "t2 completed") as steps it is taking. Speech: anything said TO the listener \u2014 answers, questions, offers, news, advice, explaining what it can do when asked, even if it mentions a user, an assistant, a policy, instructions, replying, or a tool.`;
|
|
9099
|
+
var LEAK_JUDGE_THRESHOLD = 0.6;
|
|
9100
|
+
async function judgeLeak(decider, sentence, userSaid) {
|
|
9101
|
+
const { answers } = await decider.decide({
|
|
9102
|
+
state: { what_the_user_just_said: userSaid.slice(-600) || null, sentence_about_to_be_spoken: clean(sentence) },
|
|
9103
|
+
questions: {
|
|
9104
|
+
q: {
|
|
9105
|
+
type: "noul",
|
|
9106
|
+
instructions: JUDGE_INSTRUCTIONS,
|
|
9107
|
+
criteria: { true: "leaked private reasoning \u2014 must not be spoken", false: "said to the listener \u2014 fine to speak" }
|
|
9108
|
+
}
|
|
9109
|
+
}
|
|
9110
|
+
});
|
|
9111
|
+
const p = Number(answers.q.noul);
|
|
9112
|
+
if (!Number.isFinite(p)) throw new Error("leak judge: no noul in the answer");
|
|
9113
|
+
return p;
|
|
9114
|
+
}
|
|
9115
|
+
|
|
7990
9116
|
// src/duplex.ts
|
|
7991
|
-
var
|
|
9117
|
+
var log20 = forComponent("DuplexAgent");
|
|
7992
9118
|
function describeCall(call) {
|
|
7993
9119
|
const v = call.args && Object.values(call.args).find((x) => typeof x === "string" && x.trim());
|
|
7994
9120
|
const hint = v ? ` (${String(v).replace(/\s+/g, " ").trim().slice(0, 48)})` : "";
|
|
@@ -8030,6 +9156,13 @@ var DuplexAgentOptions = class {
|
|
|
8030
9156
|
/** Teach the model to emit inline `[emotion]` tags for Cartesia emotion control. Only set when the
|
|
8031
9157
|
* TTS actually speaks them — text-duplex (no TTS) would otherwise print literal tags. */
|
|
8032
9158
|
emotionTags = false;
|
|
9159
|
+
/** Judge a post-barge line while a delivery is parked: resume it now, answer an aside and carry it on (the reflex,
|
|
9160
|
+
* told what was heard — see asideNote), or drop it (steer/stop). Unset → the conservative `isTrivialBarge` allowlist (resume | steer); a throwing judge
|
|
9161
|
+
* falls back to it too. */
|
|
9162
|
+
bargeIntent;
|
|
9163
|
+
/** Typed-decision model (e.g. ai.libx.js DecideClient → Jev). Judges reflex sentences the leak screen flags as
|
|
9164
|
+
* SUSPECT (src/voice/leak.ts) — only suspects pay the ~300ms call. Unset → only the strict leak shapes are cut. */
|
|
9165
|
+
decider;
|
|
8033
9166
|
/** Awaited BEFORE a worker spawns — open a per-task checkpoint frame, audit, etc.
|
|
8034
9167
|
* (post-spawn would race the worker's first edits). */
|
|
8035
9168
|
onTaskStart;
|
|
@@ -8038,6 +9171,13 @@ var DuplexAgentOptions = class {
|
|
|
8038
9171
|
progressUpdates = false;
|
|
8039
9172
|
/** Min ms between progress re-voices per task. */
|
|
8040
9173
|
progressIntervalMs = 25e3;
|
|
9174
|
+
/** Spoken budget of ONE task delivery (chars, ~3 short sentences). Past it the rest is parked — cut at a sentence
|
|
9175
|
+
* boundary, `spokenOffer` spoken instead — so "go on" continues it once (the parked/resume path) and an aside or
|
|
9176
|
+
* steer handles it like any parked delivery. The worker is also asked for a short spoken summary + one offer (the
|
|
9177
|
+
* source); this is the backstop. Live 20260924-093945: ~20s and ~70s monologues whose closing choice went unspoken.
|
|
9178
|
+
* The full result always folds into the transcript. 0 = unbudgeted. */
|
|
9179
|
+
spokenBudgetChars = 0;
|
|
9180
|
+
spokenOffer = "There's more. Want me to go on?";
|
|
8041
9181
|
/** Relay worker questions (AskUserQuestion + permission asks via parkQuestion) through the VOICE:
|
|
8042
9182
|
* the question re-voices as '[task <id> asks] …', the user answers conversationally, and the
|
|
8043
9183
|
* voice model resolves it with the AnswerTask tool. Off → host.ask passthrough (text menus). */
|
|
@@ -8056,20 +9196,30 @@ var DuplexAgentOptions = class {
|
|
|
8056
9196
|
/** User-scope memory dir for global facts (type=user/feedback). Forwarded to Remember's routing. */
|
|
8057
9197
|
memoryUserDir;
|
|
8058
9198
|
};
|
|
9199
|
+
var SESSION_ID_RE = /^\d{8}-\d{6}(?:-[\w-]+)?$/;
|
|
8059
9200
|
var RESERVED_EVENT_MARKER = /\[task\b[^\]\n]*\b(?:completed|failed|progress|asks)\b/i;
|
|
8060
9201
|
var RESERVED_EVENT_OPENER = /\[\s*task\b/i;
|
|
8061
9202
|
var STAGE_DIRECTION_RE = /^\(\s*(?:(?:waiting|checking|searching|thinking|processing|loading|working|fetching|looking)\b[^)]*|[^)]*(?:\.\.\.|…)\s*)\)$/i;
|
|
8062
9203
|
function nowLine() {
|
|
8063
9204
|
return `Current date and time: ${(/* @__PURE__ */ new Date()).toLocaleString("en-US", { weekday: "long", year: "numeric", month: "long", day: "numeric", hour: "numeric", minute: "2-digit", timeZoneName: "short" })}`;
|
|
8064
9205
|
}
|
|
9206
|
+
var STOP_INTENT = /\b(stop|cancel|no|nope|nah|never\s?mind|nvm|forget it|drop it|don'?t|quiet|shut up|enough|hold on|wait|pause|hang on|actually)\b/;
|
|
8065
9207
|
function isTrivialBarge(text) {
|
|
8066
9208
|
const t = text.trim().toLowerCase().replace(/[.,!?…\s]+$/g, "").replace(/^[.,!?…\s]+/, "");
|
|
8067
9209
|
if (!t) return false;
|
|
8068
|
-
if (
|
|
9210
|
+
if (STOP_INTENT.test(t)) return false;
|
|
8069
9211
|
const core = t.replace(/^(?:oh|um+|uh+|er+|hmm+|ah+|well|so|okay|ok|yeah|yep)[\s,]+/, "").trim();
|
|
8070
9212
|
return /^(?:oh|um+|uh+|er+|hmm+|ah+|sorry|oops|whoops|my bad|pardon|excuse me|apologies|go on|go ahead|continue|keep going|carry on|as you were|please continue|you were saying|sorry go on|sorry continue|go on then|go on please)$/.test(core || t);
|
|
8071
9213
|
}
|
|
8072
|
-
|
|
9214
|
+
function isOfferAcceptance(text) {
|
|
9215
|
+
const t = text.trim().toLowerCase().replace(/[.,!?…]+/g, " ").replace(/\s+/g, " ").trim();
|
|
9216
|
+
if (!t || STOP_INTENT.test(t)) return false;
|
|
9217
|
+
const core = t.replace(/^(?:oh|um+|uh+|well|so|okay|ok|alright)\s+/, "");
|
|
9218
|
+
return /^(?:(?:yes|yeah|yep|yup|sure|ok|okay|alright)(?: please| sure| go on| go ahead| tell me more| do it| why not)?|please|please do|sure thing|go for it|do it|more|tell me more|what else|and then|sounds good|absolutely|definitely|of course|why not|i'?d like that|let'?s hear it|let'?s do it)$/.test(core || t);
|
|
9219
|
+
}
|
|
9220
|
+
var isQuestion = (s) => /\?["'”’)\]]*$/.test(s.trim());
|
|
9221
|
+
var OFFER_OVERRUN = 150;
|
|
9222
|
+
var VOICE_SYSTEM_PROMPT = 'You are a spoken voice assistant \u2014 the user HEARS everything you say. Use short sentences. One idea per sentence. No markdown, no bullet lists, no code blocks, no headings, no emoji. Never emit stage directions or parenthetical asides about your own process \u2014 nothing like "(waiting for the result...)" or "(checking)"; while work runs, either say it as plain speech or end your turn.\nThis holds even when asked to "print", "list", "show", or "make a table" \u2014 there is no screen for the spoken channel. Speak it as flowing prose ("Tuesday is half a meter, Wednesday a bit less\u2026"), or if they truly need it on screen, route it to Act to render. Never emit dashes or pipes into speech.\nKeep turns SHORT \u2014 one to three sentences, then stop. Never lecture, enumerate cases, or add caveats unprompted. Conversation is a fast exchange: give the one thing asked, and let the user pull more if they want it.\nYou have three cognitive tiers \u2014 like a human brain:\n\u2022 YOU (reflex) \u2014 instant, lightweight. Handle greetings, simple questions, status checks, QuickLook.\n\u2022 `Act` \u2014 your hands. A background worker with its own configured tools and access to the user\'s environment (files and shell{{WORKER_WEB}}). Use for reading, editing, searching, running tasks, building \u2014 any real work.\n{{THINK_SLOT}}\nWhen you are unsure whether you can do or access something, do NOT assume and do NOT claim a capability you have not confirmed. To check what you can do, QuickLook `capabilities` (instant \u2014 it lists your worker\'s real tools) and answer from that. Never promise an ability that is not in your capabilities; if it is not there, tell the user plainly you can\'t. To actually DO real work, call `Act`. When the user mentions their project, folder, files, or environment ("this project", "the current folder", "my code"), call `Act` IMMEDIATELY \u2014 do not ask for paths or details the worker can discover itself. Never pretend to have done the work or invent results \u2014 the worker\'s report is your only source.\nYou cannot mute the microphone or stop voice capture yourself \u2014 no tool does it. If the user asks you to stop listening or turn the voice off, never claim you did: tell them to say exactly "voice off" (handled by the app directly), or type /voice.\nYou are NOT a knowledge base. For any question whose answer needs SPECIFIC verifiable facts you do not already have in hand \u2014 how to build/configure/implement something, exact API, library, entitlement, command or option names, current events, or particular numbers, dates, or names \u2014 do NOT answer from your own memory: you will confidently make things up (a fake API, a wrong entitlement, an event that did not happen). Route it to `Act`, which can search and verify, and speak only what its report says. DELEGATION RULE \u2014 decide for yourself, the user never has to push: if you cannot answer confidently from the conversation plus trivial well-known knowledge, do NOT refuse and do NOT guess \u2014 dispatch `Act` immediately with a clear brief and say you are checking. Anything needing CURRENT data (weather, news, prices, dates, sky/astronomy, "right now"), real computation, or verification is an automatic dispatch \u2014 never a refusal. The user should never need to say "search the web" or "think harder" to make you act; needing fresh or verified information IS the trigger. Refuse only what your worker genuinely cannot do (check `capabilities`), and say why. Answer inline ONLY for general conversation, chit-chat, and trivia you are sure of, or facts you can see via QuickLook. When elaborating on a completed task ("tell me more", "the gist"), stay strictly within what that result actually said \u2014 if the user asks for something the result did not cover, that is NEW information: dispatch `Act`, do not improvise.\nALWAYS react before you work: the FIRST thing in your turn is a brief spoken acknowledgement of what you heard and what you are about to do ("got it \u2014 opening that now", "sure, let me pull it up", "okay, checking"). NEVER call a tool (Act, Think, QuickLook) silently \u2014 the user must hear you react before you go quiet to work. After dispatching Act or Think, that same one short sentence IS your turn \u2014 end it and do not wait for the result. Exactly ONE short line: never stack a second acknowledgement, and never narrate your own presence or status while waiting ("I\'m here", "let me see", "still checking" right after you already acked). One clean ack then silence reads as competent; repeated check-ins read as nervous.\nA completed task speaks its OWN result to the user (the worker voices what matters as it finishes) \u2014 you do NOT re-voice clean task results. A FAILED or INCOMPLETE task still arrives as a "[task t1 failed] \u2026" event for you to handle. The completed result stays in YOUR context \u2014 it is yours to draw on. When the user follows up ("tell me more", "what else", "and?"), answer FROM that result first: you already have the detail, so elaborate on what you have. Do NOT spawn a fresh worker to re-search or re-gather what you were just handed. Re-dispatch ONLY when genuinely new information is needed \u2014 e.g. the user wants the full contents of a SPECIFIC source, which is one WebFetch of that URL, not a brand-new search. "[task t1 progress] \u2026" events are interim status, NOT results \u2014 on a genuinely LONG wait you MAY give one brief half-sentence aside, but only occasionally; silence while working is normal and fine (the user knows you are on it). Do NOT narrate every step or re-announce yourself. Never present progress as a finished result.\nCRITICAL: while a task is still running you have NO answer yet \u2014 never state a specific result of any kind (a number, size, count, name, path, or value). The real answer exists ONLY once the task finishes (the worker speaks it, and `TaskStatus` then returns it); inventing one meanwhile (a made-up disk size, commit count, etc.) is a serious error. Until then, only acknowledge and wait.\nNever read raw file paths, diffs, or code aloud verbatim.\nDo NOT end every turn with the same canned offer ("want a rundown?", "want the steps?"). Offer once at most; if the user pushes back, repeats themselves, or sounds unsatisfied ("you know what I mean?", "think deeper", "are you sure?"), do NOT re-offer the same thing \u2014 change approach: dispatch `Act`/`Think` to actually dig in, or ask one concrete clarifying question. Repeating a non-answer is worse than silence.\n"[task t1 asks] \u2026" events are QUESTIONS from a background task \u2014 relay to the user in your own words, short, then end your turn. When the user answers, call `AnswerTask` with that id and their answer. NEVER answer on the user\'s behalf for permissions or risky operations; if their reply is ambiguous, confirm first.\nIf the user\'s message sounds INCOMPLETE \u2014 trailing off mid-sentence, a fragment that needs more context ("and then we", "but the problem is"), hesitation fillers ("uh", "um") \u2014 call `Hold` instead of answering. This keeps listening for the rest of their thought. Only respond with substance when you have a complete question or request.\nDispatch discipline: send ONE self-contained task per request \u2014 a single worker with the full brief beats several workers with fragments (each worker starts fresh and re-discovers context). NEVER dispatch a worker just to read files or gather information \u2014 workers explore and discover context themselves; pass on what you already know and let one worker do the whole job. Split into parallel tasks only when the user asks for genuinely independent things. When a task completes, report its result and stop \u2014 do NOT dispatch follow-up work (verification, polish, extras) the user did not ask for, unless the report itself signals failure or doubt.\nDo not fire a second Act/Think for work already in flight, and NEVER spawn a second task to re-count, cross-check, or verify a result a worker already gave you \u2014 trust its answer; a single question gets ONE task. Call `TaskStatus` at most ONCE per turn; if a task is still running, give one brief status aside and end the turn \u2014 never poll it again and again in a loop. "Still on it" is ONLY for a repeat check on a task you already acknowledged earlier \u2014 NEVER as the ack when you first dispatch work ("still" is wrong when nothing was running yet; use a fresh "on it"/"got it, checking" instead). Use `CancelTask` when the user asks to stop something.\nPRIORITY: when the user says goodbye or wants to end/finish/wrap up the session ("ok bye", "that\'s all", "let\'s finish", "let\'s end", "goodnight", "exit", "wrap up"), call `ExitSession` IMMEDIATELY \u2014 do not act, do not check status, just exit.\nFor TRIVIAL instant lookups only \u2014 current time, git branch, listing a folder, peeking at a small file, or checking your own `capabilities`/tools \u2014 use `QuickLook` (instant, no task). Whenever the user asks what you can do or whether you have some ability, QuickLook `capabilities` and answer from that \u2014 never guess. Anything requiring searching, reasoning, running commands, or editing goes through `Act`.\n{{MEMORY_SLOT}}\nUser messages may arrive via speech-to-text and can carry transcription artifacts \u2014 odd words, cut-offs, homophones ("for you" vs "folder"). Read for INTENT, not surface text. If a message seems garbled, surprising, or only half-parses, do NOT guess an action or improvise content from it \u2014 briefly confirm what they meant ("did you mean\u2026?") and wait. A one-line confirm beats a confident wrong answer or an invented response to a request you did not actually understand.';
|
|
8073
9223
|
var THINK_GUIDANCE = "\u2022 `Think` \u2014 your brain. A premium reasoning model, FAR more expensive than Act. Reserve it for open-ended architecture/design questions, or a problem Act already FAILED at. ALL implementation work \u2014 coding, refactoring, debugging, edge cases, tests \u2014 goes to Act; Act is highly capable. Never send the same work to both.";
|
|
8074
9224
|
var THINK_DISABLED_GUIDANCE = "(Think tier is not available \u2014 use Act for all escalations.)";
|
|
8075
9225
|
var VOICE_STYLE_CONVERSATIONAL = `Speak like a person in a live conversation, not an assistant reading a script. React first, then deliver: a quick impulsive beat ("oh nice", "hmm, hold on", "ah, got it") before the substance. Use contractions always. Vary sentence length \u2014 some very short. Light fillers and backchannels are fine ("mm-hm", "right", "let's see") but at most one per reply \u2014 never stack them. When you escalate to Act or Think, say it like a human would ("hang on, let me actually dig into that \u2014 gimme a minute") instead of announcing a task. When a result comes back, react to it like you just found out ("okay so \u2014 turns out\u2026"). Match the user's energy: a quick question gets a quick answer \u2014 a few words is a perfectly good turn. Prefer a short answer plus an offer ("want the details?") over covering everything. Never narrate your own mechanics (no "I will now act", no task ids out loud).`;
|
|
@@ -8084,14 +9234,22 @@ var DuplexAgent = class _DuplexAgent {
|
|
|
8084
9234
|
* (TaskRecord.createdTurn) so parking can tell a prior-topic task from the current turn's fresh one. */
|
|
8085
9235
|
turn = 0;
|
|
8086
9236
|
pendingEvents = [];
|
|
8087
|
-
/**
|
|
8088
|
-
*
|
|
9237
|
+
/** THE parked delivery: every piece the user has NOT heard, in speaking order — the unheard rest a barge cut out of
|
|
9238
|
+
* the voice queue (parkCutDelivery) followed by each segment a barge-parked task produced since (deliverSegment).
|
|
9239
|
+
* Nothing already voiced is ever added, so a resume never repeats what was heard. The next line's barge intent
|
|
9240
|
+
* decides: resume → spoken verbatim, aside → handed to the reflex to carry on after its answer (asideNote) — both
|
|
9241
|
+
* send the barge-parked tasks live again; steer/stop → cleared, and those tasks
|
|
9242
|
+
* are moved on from (the full result stays in the transcript, recoverable by asking). `task` = the owner, so a
|
|
9243
|
+
* task whose outcome goes to an integration turn takes its pieces back (dropParked). */
|
|
8089
9244
|
parkedRedeliver = [];
|
|
8090
|
-
/**
|
|
8091
|
-
|
|
8092
|
-
|
|
8093
|
-
|
|
8094
|
-
|
|
9245
|
+
/** parkedRedeliver length when the last barge parked (parkInFlightDeliveries): the cut it hands over later
|
|
9246
|
+
* (parkCutDelivery) was voiced BEFORE anything parked since, so it is inserted here. */
|
|
9247
|
+
bargeMark = 0;
|
|
9248
|
+
/** The last barge cut a REFLEX reply (parkCutDelivery): a "go on" is then the reflex's to answer — it runs a normal
|
|
9249
|
+
* turn (the host's interruption note continues the reply), and only then does the parked delivery resume. */
|
|
9250
|
+
reflexCut = false;
|
|
9251
|
+
/** Recent live task segments → their task id: attributes a cut delivery (parkCutDelivery) to the task that spoke it. */
|
|
9252
|
+
voicedBy = /* @__PURE__ */ new Map();
|
|
8095
9253
|
/** Out-of-band follow-up attribution for the events coalescing into the next flush turn: TRUE iff ≥1 of
|
|
8096
9254
|
* the tasks being integrated was NON-CLEAN (early-stop/failure). Carried out-of-band on the enqueue call
|
|
8097
9255
|
* by the caller that KNOWS the outcome — a plain boolean the MODEL CANNOT PERTURB. It is NOT scanned from
|
|
@@ -8124,6 +9282,24 @@ var DuplexAgent = class _DuplexAgent {
|
|
|
8124
9282
|
// chars of reflexBuf already forwarded to the host/TTS
|
|
8125
9283
|
fabricationCut = false;
|
|
8126
9284
|
// reflex emitted a reserved [task …] marker → suppress its tail
|
|
9285
|
+
leakCuts = [];
|
|
9286
|
+
// heads of analysis-register leaks cut this turn — scrubbed from the transcript at turn end
|
|
9287
|
+
leakStep = false;
|
|
9288
|
+
// the CURRENT step's tail is muted by a leak cut (the next step speaks again, unlike a fabricated marker)
|
|
9289
|
+
leakHit = false;
|
|
9290
|
+
// this turn (or its repair) had a leak cut — the dead-air fallback must not blame the user
|
|
9291
|
+
stepMarks = [];
|
|
9292
|
+
// reflexBuf offsets where a step ended (its text is complete there)
|
|
9293
|
+
leakVerdicts = /* @__PURE__ */ new Map();
|
|
9294
|
+
// judged suspect sentences this turn (true = leak)
|
|
9295
|
+
judging;
|
|
9296
|
+
// the in-flight leak judge (one at a time — the gate is sequential)
|
|
9297
|
+
turnGen = 0;
|
|
9298
|
+
// bumped whenever the gated stream is replaced — a late verdict for an old one is dropped
|
|
9299
|
+
turnSpoken = "";
|
|
9300
|
+
// reflex text actually forwarded to the host this turn
|
|
9301
|
+
turnBase = 0;
|
|
9302
|
+
// transcript length at turn start (scope for the leak scrub)
|
|
8127
9303
|
/** TRUE for the duration of a re-voice turn that is integrating ≥1 NON-CLEAN task (turn-eligibility,
|
|
8128
9304
|
* carried out-of-band — NOT derived from any worker/brief string). ANY Act/Think dispatched in such a
|
|
8129
9305
|
* turn is stamped followUp:true. This GUARANTEES the dangerous direction is impossible: a genuine
|
|
@@ -8172,7 +9348,8 @@ var DuplexAgent = class _DuplexAgent {
|
|
|
8172
9348
|
...new Set(workerToolNames.filter((n) => n.startsWith("mcp__")).map((n) => n.slice(5).split("__")[0]))
|
|
8173
9349
|
];
|
|
8174
9350
|
const workerMcp = mcpNames.length ? `, and it can use these MCP servers: ${[...new Set(mcpNames)].join(", ")}` + (mcpNames.some((n) => /browser/i.test(n)) ? ' \u2014 including driving a REAL browser (open tabs, navigate, click, screenshot), so answer "yes" if asked whether you can control/drive a browser and route an actual browse to Act' : "") : "";
|
|
8175
|
-
const prompt = VOICE_SYSTEM_PROMPT.replace("{{MEMORY_SLOT}}", memSlot).replace("{{THINK_SLOT}}", thinkSlot).replace("{{WORKER_WEB}}", workerWeb + workerMcp) + (o.
|
|
9351
|
+
const prompt = VOICE_SYSTEM_PROMPT.replace("{{MEMORY_SLOT}}", memSlot).replace("{{THINK_SLOT}}", thinkSlot).replace("{{WORKER_WEB}}", workerWeb + workerMcp) + (o.quickLook?.sessions ? `
|
|
9352
|
+
Past conversations with this user are saved. When they refer to an EARLIER conversation or session ("last time", "the previous session", "you already did it before", "earlier today"), call QuickLook what:"sessions" (then what:"sessions" with path:"<id>" to read one) BEFORE answering \u2014 never say it does not exist without checking. Report only what the recap says: if it does not say why something happened, say you don't know \u2014 never guess a motive.` : "") + (o.voiceStyle === "conversational" ? "\n" + VOICE_STYLE_CONVERSATIONAL : "") + (o.emotionTags ? "\n" + EMOTION_TAGS_GUIDANCE : "") + `
|
|
8176
9353
|
${nowLine()}. Anchor every relative or time-sensitive reference \u2014 "today", "now", "current", "recent", "latest", "this year" \u2014 to THIS moment. When the user asks about something recent (news, sports, events), they mean near this date, not a well-known past instance; brief your worker with the current year so it searches for what is happening NOW, not a famous older event.`;
|
|
8177
9354
|
const tools = [
|
|
8178
9355
|
...o.reflexOptions?.tools ?? [],
|
|
@@ -8193,32 +9370,26 @@ ${nowLine()}. Anchor every relative or time-sensitive reference \u2014 "today",
|
|
|
8193
9370
|
if (this.heldThisTurn) return;
|
|
8194
9371
|
if (this.fabricationCut) return;
|
|
8195
9372
|
if (this.turnDispatched && this.spokeBeforeDispatch) return;
|
|
8196
|
-
|
|
8197
|
-
this.reflexBuf += msg;
|
|
8198
|
-
this.scrubStageDirections();
|
|
9373
|
+
this.reflexBuf += ev.message;
|
|
8199
9374
|
const m = this.reflexBuf.match(RESERVED_EVENT_MARKER) ?? this.reflexBuf.match(RESERVED_EVENT_OPENER);
|
|
8200
9375
|
if (m) {
|
|
8201
9376
|
this.fabricationCut = true;
|
|
8202
|
-
|
|
8203
|
-
|
|
8204
|
-
|
|
8205
|
-
if (safe.trim()) this.spokeThisTurn = true;
|
|
8206
|
-
this.emitHost({ ...ev, message: safe });
|
|
9377
|
+
log20.warn(`reflex fabricated a [task \u2026] event in its spoken stream \u2014 cutting it (kept ${m.index} chars)`);
|
|
9378
|
+
this.reflexBuf = this.reflexBuf.slice(0, Math.max(m.index, this.reflexForwarded));
|
|
9379
|
+
this.pumpReflex(true);
|
|
8207
9380
|
return;
|
|
8208
9381
|
}
|
|
8209
|
-
|
|
8210
|
-
const partial = held2 > 0 && /\[\s*t?a?s?k?$/i.test(this.reflexBuf.slice(-Math.min(held2, 6)));
|
|
8211
|
-
let upto = partial ? this.reflexBuf.length - this.reflexBuf.slice(-6).match(/\[\s*t?a?s?k?$/i)[0].length : this.reflexBuf.length;
|
|
8212
|
-
const paren = this.reflexBuf.lastIndexOf("(");
|
|
8213
|
-
if (paren >= this.reflexForwarded && !this.reflexBuf.includes(")", paren) && this.reflexBuf.length - paren <= 80)
|
|
8214
|
-
upto = Math.min(upto, paren);
|
|
8215
|
-
const out = this.reflexBuf.slice(this.reflexForwarded, upto);
|
|
8216
|
-
this.reflexForwarded = upto;
|
|
8217
|
-
if (!out) return;
|
|
8218
|
-
if (out.trim()) this.spokeThisTurn = true;
|
|
8219
|
-
this.emitHost({ ...ev, message: out });
|
|
9382
|
+
this.pumpReflex(false);
|
|
8220
9383
|
return;
|
|
8221
9384
|
}
|
|
9385
|
+
if (ev?.kind === "turn_start" || ev?.kind === "tool_use") {
|
|
9386
|
+
this.stepMarks.push(this.reflexBuf.length);
|
|
9387
|
+
if (this.leakStep) {
|
|
9388
|
+
this.leakStep = false;
|
|
9389
|
+
this.reflexForwarded = this.reflexBuf.length;
|
|
9390
|
+
}
|
|
9391
|
+
this.pumpReflex(false);
|
|
9392
|
+
}
|
|
8222
9393
|
host.notify?.(ev);
|
|
8223
9394
|
}
|
|
8224
9395
|
};
|
|
@@ -8252,16 +9423,163 @@ ${nowLine()}. Anchor every relative or time-sensitive reference \u2014 "today",
|
|
|
8252
9423
|
this.voice.options.tools.push(...mem.tools);
|
|
8253
9424
|
if (mem.index) this.voice.options.systemPrompt += "\n\n" + mem.index;
|
|
8254
9425
|
}
|
|
8255
|
-
/**
|
|
8256
|
-
*
|
|
8257
|
-
|
|
8258
|
-
|
|
8259
|
-
|
|
8260
|
-
|
|
8261
|
-
|
|
8262
|
-
|
|
8263
|
-
|
|
8264
|
-
|
|
9426
|
+
/** Forward what the reflex's spoken-stream gates allow (text_delta → host/TTS; forwarded audio can't be unsent):
|
|
9427
|
+
* - hold a trailing fragment that could be a `[task` opener split across deltas ("[ta" + "sk"), and an UNCLOSED
|
|
9428
|
+
* "(" (a stage direction is judged — and dropped — only once its ")" arrives; bounded at 80 chars);
|
|
9429
|
+
* - the leak gate: whole sentences only, each screened by isLeakSuspect the moment it completes — a strict match
|
|
9430
|
+
* is cut, any other suspect waits for the decider's verdict (judgeLeak) while the rest queues behind it.
|
|
9431
|
+
* `final` = the stream is done: release the holds and judge whatever is left as a sentence. Text before a step
|
|
9432
|
+
* boundary (stepMarks) is complete — no holds, its tail is a sentence. Idempotent; re-run as verdicts land. */
|
|
9433
|
+
pumpReflex(final) {
|
|
9434
|
+
for (; ; ) {
|
|
9435
|
+
if (this.leakStep) return;
|
|
9436
|
+
this.scrubStageDirections();
|
|
9437
|
+
const from = this.reflexForwarded;
|
|
9438
|
+
const buf = this.reflexBuf;
|
|
9439
|
+
const lastMark = Math.max(from, ...this.stepMarks);
|
|
9440
|
+
let upto = buf.length;
|
|
9441
|
+
if (!final && upto > lastMark) {
|
|
9442
|
+
const tail = buf.slice(Math.max(lastMark, upto - 6)).match(/\[\s*t?a?s?k?$/i);
|
|
9443
|
+
if (tail) upto -= tail[0].length;
|
|
9444
|
+
const paren = buf.lastIndexOf("(");
|
|
9445
|
+
if (paren >= lastMark && !buf.includes(")", paren) && buf.length - paren <= 80) upto = Math.min(upto, paren);
|
|
9446
|
+
}
|
|
9447
|
+
if (upto <= from) return;
|
|
9448
|
+
const region = buf.slice(from, upto);
|
|
9449
|
+
const ends = [...region.matchAll(SENTENCE_END)].map((m) => m.index + m[0].length);
|
|
9450
|
+
for (const k of this.stepMarks) if (k > from && k <= upto) ends.push(k - from);
|
|
9451
|
+
if (final || !ends.length && region.length >= 160) ends.push(region.length);
|
|
9452
|
+
ends.sort((a, b) => a - b);
|
|
9453
|
+
let ok = 0, leak;
|
|
9454
|
+
for (const e of ends) {
|
|
9455
|
+
if (e <= ok) continue;
|
|
9456
|
+
const v = this.leakVerdict(region.slice(ok, e));
|
|
9457
|
+
if (v === void 0) break;
|
|
9458
|
+
if (v) {
|
|
9459
|
+
leak = region.slice(ok, e);
|
|
9460
|
+
break;
|
|
9461
|
+
}
|
|
9462
|
+
ok = e;
|
|
9463
|
+
}
|
|
9464
|
+
this.forwardReflex(from + ok);
|
|
9465
|
+
if (leak === void 0) return;
|
|
9466
|
+
const at = from + ok;
|
|
9467
|
+
this.leakHit = true;
|
|
9468
|
+
this.leakCuts.push(leak.trim().slice(0, 40));
|
|
9469
|
+
log20.warn(`reflex spoke its own analysis ("${leak.trim().slice(0, 40)}\u2026") \u2014 cut before TTS`);
|
|
9470
|
+
this.notify("diag", "analysis_leak", { text: leak.trim().slice(0, 80), at: this.turnSpoken.trim() ? "mid_reply" : "before_speech" });
|
|
9471
|
+
const next = this.stepMarks.find((k) => k > at);
|
|
9472
|
+
if (next === void 0) {
|
|
9473
|
+
this.reflexForwarded = buf.length;
|
|
9474
|
+
this.leakStep = true;
|
|
9475
|
+
return;
|
|
9476
|
+
}
|
|
9477
|
+
this.reflexForwarded = next;
|
|
9478
|
+
}
|
|
9479
|
+
}
|
|
9480
|
+
forwardReflex(to) {
|
|
9481
|
+
const out = this.reflexBuf.slice(this.reflexForwarded, to);
|
|
9482
|
+
this.reflexForwarded = Math.max(this.reflexForwarded, to);
|
|
9483
|
+
if (!out) return;
|
|
9484
|
+
if (out.trim()) this.spokeThisTurn = true;
|
|
9485
|
+
this.turnSpoken += out;
|
|
9486
|
+
this.emitHost({ kind: "text_delta", message: out });
|
|
9487
|
+
}
|
|
9488
|
+
/** Leak verdict for one complete sentence: false = speak, true = cut, undefined = the judge is still out.
|
|
9489
|
+
* Non-suspects pass free; strict shapes are cut without a call; other suspects go to the decider (if any) —
|
|
9490
|
+
* one call at a time, cached per turn. A failed/slow judge fails OPEN (speech is never muted on a guess). */
|
|
9491
|
+
leakVerdict(sentence) {
|
|
9492
|
+
const s = sentence.trim();
|
|
9493
|
+
if (!s || !isLeakSuspect(s)) return false;
|
|
9494
|
+
if (isStrictLeak(s)) return true;
|
|
9495
|
+
const decider = this.options.decider;
|
|
9496
|
+
if (!decider) return false;
|
|
9497
|
+
const known = this.leakVerdicts.get(s);
|
|
9498
|
+
if (known !== void 0 || this.judging) return known;
|
|
9499
|
+
const gen = this.turnGen, t0 = performance.now();
|
|
9500
|
+
const userSaid = [...this.voice.transcript].reverse().map((m) => m.role === "user" ? contentText(m.content) : "").find((t) => t && !t.startsWith("[reminder]")) ?? "";
|
|
9501
|
+
let timer;
|
|
9502
|
+
const timeout = new Promise((_, rej) => {
|
|
9503
|
+
timer = setTimeout(() => rej(new Error(`no verdict in ${_DuplexAgent.LEAK_JUDGE_TIMEOUT_MS}ms`)), _DuplexAgent.LEAK_JUDGE_TIMEOUT_MS);
|
|
9504
|
+
});
|
|
9505
|
+
this.judging = Promise.race([judgeLeak(decider, s, userSaid), timeout]).then((p) => {
|
|
9506
|
+
this.notify("diag", "leak_judge", { text: s.slice(0, 80), p: Math.round(p * 100) / 100, ms: Math.round(performance.now() - t0) });
|
|
9507
|
+
return p >= LEAK_JUDGE_THRESHOLD;
|
|
9508
|
+
}, (e) => {
|
|
9509
|
+
log20.warn(`leak judge failed \u2014 speaking the sentence: ${e.message}`);
|
|
9510
|
+
return false;
|
|
9511
|
+
}).then((leak) => {
|
|
9512
|
+
clearTimeout(timer);
|
|
9513
|
+
if (gen !== this.turnGen) return;
|
|
9514
|
+
this.judging = void 0;
|
|
9515
|
+
this.leakVerdicts.set(s, leak);
|
|
9516
|
+
this.pumpReflex(false);
|
|
9517
|
+
});
|
|
9518
|
+
return void 0;
|
|
9519
|
+
}
|
|
9520
|
+
static LEAK_JUDGE_TIMEOUT_MS = 1500;
|
|
9521
|
+
/** The stream is done: settle every pending verdict and release everything the gates still hold. */
|
|
9522
|
+
async drainReflex() {
|
|
9523
|
+
for (; ; ) {
|
|
9524
|
+
this.pumpReflex(true);
|
|
9525
|
+
if (!this.judging) return;
|
|
9526
|
+
await this.judging;
|
|
9527
|
+
}
|
|
9528
|
+
}
|
|
9529
|
+
/** Drop any in-flight judge of the current stream (its verdict must not pump a stream that moved on). */
|
|
9530
|
+
dropJudge() {
|
|
9531
|
+
this.turnGen++;
|
|
9532
|
+
this.judging = void 0;
|
|
9533
|
+
}
|
|
9534
|
+
/** Remove a cut analysis leak from this turn's assistant message(s) — left in, it primes the next turn to
|
|
9535
|
+
* leak again and reads as something we said. Keeps any legit prefix; drops a message left empty. */
|
|
9536
|
+
scrubLeakFromTranscript() {
|
|
9537
|
+
const keys = this.leakCuts.splice(0);
|
|
9538
|
+
const t = this.voice.transcript;
|
|
9539
|
+
for (const key of keys) {
|
|
9540
|
+
let i = t.length - 1;
|
|
9541
|
+
while (i >= this.turnBase && !(t[i].role === "assistant" && typeof t[i].content === "string" && t[i].content.includes(key))) i--;
|
|
9542
|
+
if (i < this.turnBase) {
|
|
9543
|
+
log20.warn("analysis leak cut, but its text was not found in the transcript to scrub");
|
|
9544
|
+
continue;
|
|
9545
|
+
}
|
|
9546
|
+
const m = t[i];
|
|
9547
|
+
m.content = m.content.slice(0, m.content.indexOf(key)).trimEnd();
|
|
9548
|
+
if (!m.content && !m.tool_calls?.length) t.splice(i, 1);
|
|
9549
|
+
}
|
|
9550
|
+
}
|
|
9551
|
+
/** A Hold turn is silent BY DESIGN: every reflex text after the Hold is muted (voiceHost drops it), so none of it may
|
|
9552
|
+
* persist either — the transcript is what the agent SAID. Live 20260923-125143 msg 10: the model's reasoning ("We
|
|
9553
|
+
* need to respond according to guidelines… So we should hold") was saved as an assistant reply and fed every later
|
|
9554
|
+
* turn. Strips the text of assistant messages after the Hold call (tool calls stay — they happened); a message left
|
|
9555
|
+
* empty is removed. */
|
|
9556
|
+
scrubHeldText() {
|
|
9557
|
+
if (!this.heldThisTurn) return;
|
|
9558
|
+
const t = this.voice.transcript;
|
|
9559
|
+
let i = this.turnBase;
|
|
9560
|
+
while (i < t.length && !t[i].tool_calls?.some((c) => c.function.name === "Hold")) i++;
|
|
9561
|
+
for (let j = t.length - 1; j > i; j--) {
|
|
9562
|
+
const m = t[j];
|
|
9563
|
+
if (m.role !== "assistant" || !contentText(m.content).trim()) continue;
|
|
9564
|
+
if (m.tool_calls?.length) m.content = "";
|
|
9565
|
+
else t.splice(j, 1);
|
|
9566
|
+
}
|
|
9567
|
+
}
|
|
9568
|
+
/** Shared turn epilogue (user turn, confirmed speculation, re-voice): release held text, scrub a cut leak,
|
|
9569
|
+
* then repair dead air — unless the turn was ABORTED: the user took the floor (barge-in / Esc), which is
|
|
9570
|
+
* not dead air, and a nudge would run on the same aborted signal (live: the "[reminder]" landed in the
|
|
9571
|
+
* transcript as a user turn with no reply, session 20260923-101910 msg 27). */
|
|
9572
|
+
async endTurn(res, fallback) {
|
|
9573
|
+
if (res?.finishReason === "aborted") {
|
|
9574
|
+
this.dropJudge();
|
|
9575
|
+
this.scrubLeakFromTranscript();
|
|
9576
|
+
this.scrubHeldText();
|
|
9577
|
+
return;
|
|
9578
|
+
}
|
|
9579
|
+
await this.drainReflex();
|
|
9580
|
+
this.scrubLeakFromTranscript();
|
|
9581
|
+
this.scrubHeldText();
|
|
9582
|
+
if (this.silentTurn) await this.ackIfSilent(fallback);
|
|
8265
9583
|
}
|
|
8266
9584
|
/** Remove complete stage-direction parentheticals from the UNFORWARDED reflex text (STAGE_DIRECTION_RE).
|
|
8267
9585
|
* Only the unforwarded region is touched — already-spoken audio can't be unsent, and splicing before
|
|
@@ -8283,6 +9601,14 @@ ${nowLine()}. Anchor every relative or time-sensitive reference \u2014 "today",
|
|
|
8283
9601
|
this.reflexBuf = "";
|
|
8284
9602
|
this.reflexForwarded = 0;
|
|
8285
9603
|
this.fabricationCut = false;
|
|
9604
|
+
this.leakCuts = [];
|
|
9605
|
+
this.leakStep = this.leakHit = false;
|
|
9606
|
+
this.stepMarks = [];
|
|
9607
|
+
this.leakVerdicts.clear();
|
|
9608
|
+
this.turnSpoken = "";
|
|
9609
|
+
this.offerOpen = false;
|
|
9610
|
+
this.dropJudge();
|
|
9611
|
+
this.turnBase = this.voice.transcript.length;
|
|
8286
9612
|
this.turnFollowUp = false;
|
|
8287
9613
|
this.voice.options.toolChoice = void 0;
|
|
8288
9614
|
}
|
|
@@ -8294,7 +9620,7 @@ ${nowLine()}. Anchor every relative or time-sensitive reference \u2014 "today",
|
|
|
8294
9620
|
return {
|
|
8295
9621
|
preToolUse: (call) => {
|
|
8296
9622
|
if (this.spec?.state === "pending" && !_DuplexAgent.SPEC_SAFE_TOOLS.has(call.name)) {
|
|
8297
|
-
|
|
9623
|
+
log20.verbose(`speculation aborted: reflex called ${call.name} on unconfirmed input`);
|
|
8298
9624
|
this.abortSpeculation();
|
|
8299
9625
|
return { block: true, reason: "Speculative turn aborted." };
|
|
8300
9626
|
}
|
|
@@ -8328,16 +9654,27 @@ ${nowLine()}. Anchor every relative or time-sensitive reference \u2014 "today",
|
|
|
8328
9654
|
* Wording adapts to whether work was dispatched (an ack) or the inline reply was simply lost. */
|
|
8329
9655
|
async ackIfSilent(fallback) {
|
|
8330
9656
|
const dispatched = this.turnDispatched;
|
|
9657
|
+
const reminder = fallback ? "[reminder] You said nothing to the user this turn. Tell them, in ONE short spoken sentence, what just happened \u2014 no tools." : dispatched ? "[reminder] You dispatched a task but said nothing to the user. Say ONE short spoken acknowledgement now \u2014 no tools." : "[reminder] You said nothing to the user this turn. Give your ONE short spoken reply now \u2014 no tools.";
|
|
9658
|
+
const base = this.voice.transcript.length;
|
|
9659
|
+
this.fabricationCut = this.leakStep = false;
|
|
9660
|
+
this.reflexBuf = "";
|
|
9661
|
+
this.reflexForwarded = 0;
|
|
9662
|
+
this.stepMarks = [];
|
|
9663
|
+
this.dropJudge();
|
|
8331
9664
|
this.nudging = true;
|
|
8332
9665
|
try {
|
|
8333
|
-
await this.voice.send(
|
|
9666
|
+
await this.voice.send(reminder);
|
|
8334
9667
|
} catch (e) {
|
|
8335
|
-
|
|
9668
|
+
log20.warn(`ack nudge failed: ${e instanceof Error ? e.message : e}`);
|
|
8336
9669
|
} finally {
|
|
8337
9670
|
this.nudging = false;
|
|
9671
|
+
const i = this.voice.transcript.findIndex((m, k) => k >= base && m.role === "user" && m.content === reminder);
|
|
9672
|
+
if (i >= 0) this.voice.transcript.splice(i, 1);
|
|
9673
|
+
await this.drainReflex();
|
|
9674
|
+
this.scrubLeakFromTranscript();
|
|
8338
9675
|
}
|
|
8339
9676
|
if (!this.spokeThisTurn) {
|
|
8340
|
-
const pool = fallback ? [fallback] : dispatched ? _DuplexAgent.FALLBACK_ACKS : _DuplexAgent.FALLBACK_RETRY;
|
|
9677
|
+
const pool = fallback ? [fallback] : dispatched ? _DuplexAgent.FALLBACK_ACKS : this.leakHit ? _DuplexAgent.FALLBACK_OWN : _DuplexAgent.FALLBACK_RETRY;
|
|
8341
9678
|
const fresh = pool.filter((p) => p !== this.lastFallback);
|
|
8342
9679
|
const line = (fresh.length ? fresh : pool)[Math.floor(Math.random() * (fresh.length || pool.length))];
|
|
8343
9680
|
this.lastFallback = line;
|
|
@@ -8348,26 +9685,134 @@ ${nowLine()}. Anchor every relative or time-sensitive reference \u2014 "today",
|
|
|
8348
9685
|
* hosts/tests key on it. */
|
|
8349
9686
|
static FALLBACK_ACKS = ["Okay, on it.", "On it.", "Alright, working on it."];
|
|
8350
9687
|
static FALLBACK_RETRY = ["Sorry, could you say that again?", "Hm, I missed that \u2014 could you say that again?"];
|
|
9688
|
+
static FALLBACK_OWN = ["Sorry, I lost my train of thought there \u2014 give me that one more time?", "Hm, I got tangled up \u2014 ask me that once more?"];
|
|
8351
9689
|
lastFallback = "";
|
|
8352
9690
|
/** One user turn: the voice agent streams the reply (and may Act/Think). Serialized with re-voice turns.
|
|
8353
9691
|
* If a speculative reflex call is pending and this content CONFIRMS it (the final matches the
|
|
8354
9692
|
* speculated partial), the in-flight call is adopted as THE turn: its buffered output flushes to the
|
|
8355
9693
|
* host NOW (this is the latency win) and streaming continues live. Any other content aborts the
|
|
8356
|
-
* speculation first (rolled back silently) and runs a normal turn behind it.
|
|
8357
|
-
|
|
8358
|
-
|
|
8359
|
-
|
|
8360
|
-
|
|
8361
|
-
|
|
8362
|
-
|
|
8363
|
-
|
|
9694
|
+
* speculation first (rolled back silently) and runs a normal turn behind it.
|
|
9695
|
+
* `opts.id` names the turn; `opts.replaces` names an earlier one this content REPLACES — the voice engine's
|
|
9696
|
+
* fuller re-finalization of an utterance whose reply had not started ("…previous" → "…previous
|
|
9697
|
+
* conversation."). The replaced turn is skipped if it has not run yet, else aborted and rolled back out of
|
|
9698
|
+
* the transcript (kept only if it already dispatched work) — one reply, to the full text. */
|
|
9699
|
+
send(content, opts) {
|
|
9700
|
+
if (opts?.replaces) this.replaceTurn(opts.replaces);
|
|
9701
|
+
const cur = this.voice.options.signal;
|
|
9702
|
+
const ext = cur && cur === this.turnSignal?.own ? this.turnSignal.ext : cur;
|
|
9703
|
+
const rec = opts?.id ? this.trackTurn(opts.id) : void 0;
|
|
9704
|
+
if (rec?.superseded) {
|
|
9705
|
+
this.notify("diag", "turn_replaced", { id: opts.id, ran: false });
|
|
9706
|
+
return Promise.resolve(_DuplexAgent.replacedResult(this.voice.transcript));
|
|
9707
|
+
}
|
|
9708
|
+
const reflexCut = this.reflexCut;
|
|
9709
|
+
this.reflexCut = false;
|
|
9710
|
+
if (typeof content === "string" && this.hasParkedDelivery()) {
|
|
9711
|
+
const fallback = () => isTrivialBarge(content) ? "resume" : "steer";
|
|
9712
|
+
const accepted = this.offerOpen && this.parkedRedeliver.length > 0 && this.parkedRedeliver.every((p) => p.task === this.offer.task) && (isOfferAcceptance(content) || isTrivialBarge(content));
|
|
9713
|
+
const judge = accepted ? void 0 : this.options.bargeIntent;
|
|
9714
|
+
return (accepted ? Promise.resolve("resume") : judge ? judge(content).catch((e) => {
|
|
9715
|
+
log20.warn(`bargeIntent judge failed \u2014 using the allowlist: ${e.message}`);
|
|
9716
|
+
return fallback();
|
|
9717
|
+
}) : Promise.resolve(fallback())).then((intent) => {
|
|
9718
|
+
this.notify("diag", "barge_intent", { intent, text: content.slice(0, 80) });
|
|
9719
|
+
if (intent === "resume" && !reflexCut) return this.resumeParked();
|
|
9720
|
+
if (intent === "aside" || intent === "resume") {
|
|
9721
|
+
const told = intent === "aside" ? [...this.parkedRedeliver] : [];
|
|
9722
|
+
return this.sendTurn(intent === "aside" ? content + this.asideNote(told) : content, true, rec, ext).then(async (r) => {
|
|
9723
|
+
if (r.finishReason === "aborted" || this.heldThisTurn) return r;
|
|
9724
|
+
const missed = unsaidClauses(told.map((p) => p.text), this.turnSpoken, this.options.decider);
|
|
9725
|
+
const turn = this.turn;
|
|
9726
|
+
this.parkedRedeliver = this.parkedRedeliver.filter((p) => !told.includes(p));
|
|
9727
|
+
await this.resumeParked();
|
|
9728
|
+
void missed.then((m) => {
|
|
9729
|
+
const dropped = m.filter((c) => !isQuestion(c)).join(" ").replace(/[,;]$/, ".");
|
|
9730
|
+
if (!dropped || this.turn !== turn) return;
|
|
9731
|
+
this.parkedRedeliver.unshift({ text: dropped, task: told.at(-1)?.task });
|
|
9732
|
+
this.notify("diag", "aside_dropped", { text: dropped.slice(0, 80) });
|
|
9733
|
+
});
|
|
9734
|
+
return r;
|
|
9735
|
+
});
|
|
9736
|
+
}
|
|
9737
|
+
return this.sendTurn(content, false, rec, ext);
|
|
9738
|
+
});
|
|
9739
|
+
}
|
|
9740
|
+
return this.sendTurn(content, false, rec, ext);
|
|
9741
|
+
}
|
|
9742
|
+
/** Host-named user turns (send opts.id), so a later send can replace one. Bounded; a replace that arrives
|
|
9743
|
+
* BEFORE its target (the host's dispatch hops can reorder) leaves a pre-superseded record behind. */
|
|
9744
|
+
userTurns = /* @__PURE__ */ new Map();
|
|
9745
|
+
turnSignal;
|
|
9746
|
+
// the combined signal a named turn installed while it runs
|
|
9747
|
+
trackTurn(id) {
|
|
9748
|
+
let rec = this.userTurns.get(id);
|
|
9749
|
+
if (!rec) {
|
|
9750
|
+
rec = { ctl: new AbortController(), done: false, superseded: false };
|
|
9751
|
+
this.userTurns.set(id, rec);
|
|
9752
|
+
if (this.userTurns.size > 32) this.userTurns.delete(this.userTurns.keys().next().value);
|
|
9753
|
+
}
|
|
9754
|
+
return rec;
|
|
9755
|
+
}
|
|
9756
|
+
replaceTurn(id) {
|
|
9757
|
+
const rec = this.trackTurn(id);
|
|
9758
|
+
if (rec.done) {
|
|
9759
|
+
const drop = rec.dropped;
|
|
9760
|
+
rec.dropped = void 0;
|
|
9761
|
+
if (drop?.length) void this.enqueue(async () => {
|
|
9762
|
+
const t = this.voice.transcript;
|
|
9763
|
+
for (const m of drop) {
|
|
9764
|
+
const i = t.indexOf(m);
|
|
9765
|
+
if (i >= 0) t.splice(i, 1);
|
|
9766
|
+
}
|
|
9767
|
+
this.notify("diag", "turn_replaced", { ran: true, rolledBack: true, late: true });
|
|
8364
9768
|
});
|
|
9769
|
+
return;
|
|
8365
9770
|
}
|
|
9771
|
+
if (rec.superseded) return;
|
|
9772
|
+
rec.superseded = true;
|
|
9773
|
+
rec.ctl.abort();
|
|
9774
|
+
}
|
|
9775
|
+
static replacedResult(messages) {
|
|
9776
|
+
return { text: "", steps: 0, finishReason: "aborted", messages };
|
|
9777
|
+
}
|
|
9778
|
+
/** A turn replaced mid-run: mute whatever it still holds, and erase it from the transcript (the replacing turn
|
|
9779
|
+
* carries the user's full words) — unless it already dispatched work or SPOKE: the task is real, and the user
|
|
9780
|
+
* heard those words, so both stay visible to the replacing turn. An aborted stream never reaches the transcript,
|
|
9781
|
+
* so what was spoken is recorded as the replaced turn's reply. */
|
|
9782
|
+
dropReplacedTurn() {
|
|
9783
|
+
this.fabricationCut = true;
|
|
9784
|
+
this.reflexBuf = this.reflexBuf.slice(0, this.reflexForwarded);
|
|
9785
|
+
this.dropJudge();
|
|
9786
|
+
const spoke = this.turnSpoken.trim();
|
|
9787
|
+
const rolledBack = !this.turnDispatched && !spoke;
|
|
9788
|
+
if (rolledBack) this.voice.transcript.length = this.turnBase;
|
|
9789
|
+
else if (spoke) {
|
|
9790
|
+
const t = this.voice.transcript;
|
|
9791
|
+
const have = t.slice(this.turnBase).filter((m) => m.role === "assistant").map((m) => contentText(m.content)).join(" ");
|
|
9792
|
+
if (!have.includes(spoke)) t.push({ role: "assistant", content: spoke });
|
|
9793
|
+
}
|
|
9794
|
+
this.notify("diag", "turn_replaced", { ran: true, rolledBack, spoke: !!spoke });
|
|
9795
|
+
return _DuplexAgent.replacedResult(this.voice.transcript);
|
|
9796
|
+
}
|
|
9797
|
+
resumeParked() {
|
|
9798
|
+
if (this.spec) this.abortSpeculation();
|
|
9799
|
+
return this.enqueue(async () => {
|
|
9800
|
+
this.resetTurn();
|
|
9801
|
+
this.redeliverParked();
|
|
9802
|
+
for (const t of this.tasks.values()) if (t.status === "running" && t.deliveryParked === "barge") t.deliveryParked = void 0;
|
|
9803
|
+
return { text: "", steps: 0, finishReason: "stop", messages: [] };
|
|
9804
|
+
});
|
|
9805
|
+
}
|
|
9806
|
+
sendTurn(content, keepParked = false, rec, ext) {
|
|
8366
9807
|
const spec = this.spec;
|
|
8367
9808
|
if (spec?.state === "pending") {
|
|
8368
9809
|
if (typeof content === "string" && speculationConfirms(spec.text, content)) {
|
|
8369
9810
|
spec.state = "confirmed";
|
|
8370
9811
|
spec.finalText = content;
|
|
9812
|
+
if (rec) {
|
|
9813
|
+
spec.rec = rec;
|
|
9814
|
+
rec.ctl.signal.addEventListener("abort", () => spec.ctl.abort(), { once: true });
|
|
9815
|
+
}
|
|
8371
9816
|
for (const ev of spec.buf.splice(0)) this.options.host?.notify?.(ev);
|
|
8372
9817
|
spec.decide("confirm");
|
|
8373
9818
|
this.notify("diag", "speculation_confirmed", { text: spec.text.slice(0, 80) });
|
|
@@ -8379,12 +9824,32 @@ ${nowLine()}. Anchor every relative or time-sensitive reference \u2014 "today",
|
|
|
8379
9824
|
await this.initMemory();
|
|
8380
9825
|
this.resetTurn();
|
|
8381
9826
|
this.turn++;
|
|
8382
|
-
|
|
8383
|
-
|
|
8384
|
-
|
|
8385
|
-
|
|
8386
|
-
|
|
8387
|
-
|
|
9827
|
+
if (!keepParked) {
|
|
9828
|
+
this.parkedRedeliver = [];
|
|
9829
|
+
for (const t of this.tasks.values()) if (t.deliveryParked === "barge") t.deliveryParked = "moved_on";
|
|
9830
|
+
}
|
|
9831
|
+
if (rec?.superseded) {
|
|
9832
|
+
this.notify("diag", "turn_replaced", { ran: false });
|
|
9833
|
+
return _DuplexAgent.replacedResult(this.voice.transcript);
|
|
9834
|
+
}
|
|
9835
|
+
const signal = rec && (ext ? AbortSignal.any([ext, rec.ctl.signal]) : rec.ctl.signal);
|
|
9836
|
+
if (signal) {
|
|
9837
|
+
this.voice.options.signal = signal;
|
|
9838
|
+
this.turnSignal = { own: signal, ext };
|
|
9839
|
+
}
|
|
9840
|
+
let res;
|
|
9841
|
+
try {
|
|
9842
|
+
res = await this.voice.send(content);
|
|
9843
|
+
} finally {
|
|
9844
|
+
if (signal) {
|
|
9845
|
+
this.voice.options.signal = ext;
|
|
9846
|
+
this.turnSignal = void 0;
|
|
9847
|
+
}
|
|
9848
|
+
if (rec) rec.done = true;
|
|
9849
|
+
}
|
|
9850
|
+
if (rec?.superseded) return this.dropReplacedTurn();
|
|
9851
|
+
if (rec && res.finishReason === "aborted" && !this.turnDispatched && !this.turnSpoken.trim()) rec.dropped = this.voice.transcript.slice(this.turnBase);
|
|
9852
|
+
await this.endTurn(res);
|
|
8388
9853
|
return res;
|
|
8389
9854
|
});
|
|
8390
9855
|
}
|
|
@@ -8425,7 +9890,7 @@ ${nowLine()}. Anchor every relative or time-sensitive reference \u2014 "today",
|
|
|
8425
9890
|
try {
|
|
8426
9891
|
res = await this.voice.send(spec.text);
|
|
8427
9892
|
} catch (e) {
|
|
8428
|
-
|
|
9893
|
+
log20.warn(`speculative turn failed: ${e instanceof Error ? e.message : e}`);
|
|
8429
9894
|
} finally {
|
|
8430
9895
|
this.voice.options.signal = prevSignal;
|
|
8431
9896
|
}
|
|
@@ -8439,7 +9904,7 @@ ${nowLine()}. Anchor every relative or time-sensitive reference \u2014 "today",
|
|
|
8439
9904
|
if (d === "abort") {
|
|
8440
9905
|
if (this.voice.transcript.length > base) this.voice.transcript.length = base;
|
|
8441
9906
|
this.speculativeAbortedCalls++;
|
|
8442
|
-
|
|
9907
|
+
log20.verbose(`speculation aborted (${this.speculativeAbortedCalls} total): "${spec.text.slice(0, 50)}"`);
|
|
8443
9908
|
if (this.spec === spec) this.spec = void 0;
|
|
8444
9909
|
return res ?? empty;
|
|
8445
9910
|
}
|
|
@@ -8451,8 +9916,9 @@ ${nowLine()}. Anchor every relative or time-sensitive reference \u2014 "today",
|
|
|
8451
9916
|
}
|
|
8452
9917
|
}
|
|
8453
9918
|
this.spec = void 0;
|
|
8454
|
-
|
|
8455
|
-
if (
|
|
9919
|
+
if (spec.rec) spec.rec.done = true;
|
|
9920
|
+
if (spec.rec?.superseded) return this.dropReplacedTurn();
|
|
9921
|
+
await this.endTurn(res);
|
|
8456
9922
|
return res ?? empty;
|
|
8457
9923
|
});
|
|
8458
9924
|
}
|
|
@@ -8481,37 +9947,125 @@ ${nowLine()}. Anchor every relative or time-sensitive reference \u2014 "today",
|
|
|
8481
9947
|
* superseded topic never talks over the new one (the debt-after-jokes regression). Tasks keep running and
|
|
8482
9948
|
* still fold their result into the transcript — recoverable, just not spoken. Returns parked ids (logging).
|
|
8483
9949
|
* Does NOT cancel. Two callers, two shapes:
|
|
8484
|
-
* - BARGE (default): the user interrupted AUDIO. Park EVERY running task (including this turn's) — the
|
|
8485
|
-
* worker they cut off must stop, whatever turn launched it —
|
|
8486
|
-
*
|
|
8487
|
-
* - SUPERSEDE (`priorTurnsOnly`, `
|
|
8488
|
-
*
|
|
8489
|
-
*
|
|
8490
|
-
parkInFlightDeliveries(
|
|
8491
|
-
if (
|
|
9950
|
+
* - BARGE (default): the user interrupted AUDIO. Park EVERY live running task (including this turn's) — the
|
|
9951
|
+
* worker they cut off must stop, whatever turn launched it — as 'barge', so a following "go on" can bring
|
|
9952
|
+
* it back. A task the user already moved on from stays moved on: a barge never revives it.
|
|
9953
|
+
* - SUPERSEDE (`priorTurnsOnly`, `barge:false`, from dispatch()): a new dispatch redirected to fresh work.
|
|
9954
|
+
* Park only PRIOR-turn live tasks so parallel siblings dispatched in the SAME turn don't silence each other,
|
|
9955
|
+
* as 'moved_on' (don't resurface on a stray "go on"). */
|
|
9956
|
+
parkInFlightDeliveries(barge = true, priorTurnsOnly = false) {
|
|
9957
|
+
if (barge) {
|
|
9958
|
+
this.bargeMark = this.parkedRedeliver.length;
|
|
9959
|
+
this.reflexCut = false;
|
|
9960
|
+
this.offerOpen = false;
|
|
9961
|
+
}
|
|
8492
9962
|
const parked = [];
|
|
8493
9963
|
for (const rec of this.tasks.values())
|
|
8494
9964
|
if (rec.status === "running" && !rec.deliveryParked && (!priorTurnsOnly || rec.createdTurn < this.turn)) {
|
|
8495
|
-
rec.deliveryParked =
|
|
9965
|
+
rec.deliveryParked = barge ? "barge" : "moved_on";
|
|
8496
9966
|
parked.push(rec.id);
|
|
8497
9967
|
}
|
|
8498
9968
|
return parked;
|
|
8499
9969
|
}
|
|
8500
|
-
/**
|
|
8501
|
-
* one
|
|
9970
|
+
/** A barge-in cut a worker delivery the VOICE ENGINE was still speaking — the queued utterances it dropped plus the
|
|
9971
|
+
* unheard rest of the one playing (cli splitCut). It joins the parked delivery AHEAD of whatever parked tasks
|
|
9972
|
+
* produced since the barge (it was voiced first); the user's next line runs the barge-intent judge — resume it,
|
|
9973
|
+
* answer an aside and carry it on, or drop it on a steer/stop. `heard` = the cut utterance's part the user DID hear
|
|
9974
|
+
* (the aside note tells the reflex what was heard vs missed).
|
|
9975
|
+
* Live 20260923-125143: "Oh, that— that's new." cut an iOS-news delivery and its 6 remaining utterances vanished.
|
|
9976
|
+
* `reflexCut` = the barge cut a REFLEX reply (the host's cut had a reply): a "go on" then runs the reflex (see send).
|
|
9977
|
+
* A cut spoken by a task the user moved on from (or whose outcome went to an integration turn) is not parked. */
|
|
9978
|
+
parkCutDelivery(text, reflexCut = false, heard = "") {
|
|
9979
|
+
this.reflexCut = reflexCut;
|
|
9980
|
+
const t = text.trim();
|
|
9981
|
+
if (!t) return;
|
|
9982
|
+
if (this.offer.text && this.offer.text.endsWith(t)) {
|
|
9983
|
+
this.offerOpen = !reflexCut;
|
|
9984
|
+
return;
|
|
9985
|
+
}
|
|
9986
|
+
if (t.split(SENTENCE_SPLIT).every(isQuestion)) return;
|
|
9987
|
+
const first = t.split(/(?<=[.!?])\s/)[0];
|
|
9988
|
+
const task = [...this.voicedBy].reverse().find(([seg]) => t.includes(seg) || first.length >= 16 && seg.includes(first))?.[1];
|
|
9989
|
+
if (task && this.tasks.get(task)?.deliveryParked === "moved_on") return;
|
|
9990
|
+
this.parkedRedeliver.splice(Math.min(this.bargeMark, this.parkedRedeliver.length), 0, { text: t, task, ...heard ? { heard } : {} });
|
|
9991
|
+
this.notify("diag", "delivery_parked", { chars: t.length });
|
|
9992
|
+
}
|
|
9993
|
+
/** One spoken segment of a task's delivery — the ONLY path a worker's speech takes (streamed segments, the settle
|
|
9994
|
+
* tail, the no-spoken fallback). Live → the voice queue; barge-parked → the parked delivery, in order; superseded
|
|
9995
|
+
* (the user moved on) → nowhere (the result still folds into the transcript at settle). */
|
|
9996
|
+
deliverSegment(rec, seg) {
|
|
9997
|
+
if (!seg.trim()) return;
|
|
9998
|
+
if (rec) rec.spokenText = (rec.spokenText ? rec.spokenText + " " : "") + seg;
|
|
9999
|
+
if (!rec?.deliveryParked) {
|
|
10000
|
+
const [say, rest] = rec ? this.budgetSplit(rec, seg) : [seg, ""];
|
|
10001
|
+
if (say) {
|
|
10002
|
+
this.offerOpen = false;
|
|
10003
|
+
this.options.host?.notify?.({ kind: "speak_utterance", message: say });
|
|
10004
|
+
if (rec) {
|
|
10005
|
+
this.voicedBy.set(say.trim(), rec.id);
|
|
10006
|
+
if (this.voicedBy.size > 64) this.voicedBy.delete(this.voicedBy.keys().next().value);
|
|
10007
|
+
}
|
|
10008
|
+
}
|
|
10009
|
+
if (!rest || !rec) return;
|
|
10010
|
+
rec.deliveryParked = "barge";
|
|
10011
|
+
this.parkedRedeliver.push({ text: rest, task: rec.id });
|
|
10012
|
+
if (this.options.spokenOffer) {
|
|
10013
|
+
this.offer = { text: rec.capOffer = this.options.spokenOffer, task: rec.id };
|
|
10014
|
+
this.offerOpen = true;
|
|
10015
|
+
this.options.host?.notify?.({ kind: "speak_utterance", message: this.offer.text });
|
|
10016
|
+
}
|
|
10017
|
+
this.notify("diag", "delivery_budget", { task: rec.id, spoke: rec.voicedChars, parked: rest.length });
|
|
10018
|
+
} else if (rec.deliveryParked === "barge") this.parkedRedeliver.push({ text: seg, task: rec.id });
|
|
10019
|
+
}
|
|
10020
|
+
/** Split a delivery segment at the spoken budget (whole sentences; the first sentence always speaks): what to voice
|
|
10021
|
+
* now, and the rest to park. Marks the budget spent on a cut, so a resumed delivery runs on unbudgeted. */
|
|
10022
|
+
budgetSplit(rec, seg) {
|
|
10023
|
+
const cap = this.options.spokenBudgetChars;
|
|
10024
|
+
if (!cap || rec.budgetSpent) return [seg, ""];
|
|
10025
|
+
const sents = seg.trim().split(SENTENCE_SPLIT);
|
|
10026
|
+
let used = rec.voicedChars ?? 0, n = 0;
|
|
10027
|
+
while (n < sents.length && (!used || used + sents[n].length <= cap)) used += sents[n++].length + 1;
|
|
10028
|
+
const over = sents.slice(n);
|
|
10029
|
+
if (!over.length || over.length === 1 && isQuestion(over[0]) && over[0].length <= OFFER_OVERRUN && used <= cap) {
|
|
10030
|
+
rec.voicedChars = used + (over[0] ? over[0].length + 1 : 0);
|
|
10031
|
+
return [seg, ""];
|
|
10032
|
+
}
|
|
10033
|
+
rec.voicedChars = used;
|
|
10034
|
+
rec.budgetSpent = true;
|
|
10035
|
+
return [sents.slice(0, n).join(" "), sents.slice(n).join(" ")];
|
|
10036
|
+
}
|
|
10037
|
+
/** The cap offer last spoken and the task whose rest it offers — a barge over it is not a delivery to park
|
|
10038
|
+
* (parkCutDelivery). */
|
|
10039
|
+
offer = { text: "", task: "" };
|
|
10040
|
+
/** The cap offer was the last thing voiced (no delivery or turn has spoken since) — a plain yes accepts it (send). */
|
|
10041
|
+
offerOpen = false;
|
|
10042
|
+
/** The task's outcome now belongs to its integration turn (failed / stopped early): take back its parked pieces and
|
|
10043
|
+
* keep it from being revived — a "go on" must not replay raw segments of a result the reflex is about to explain. */
|
|
10044
|
+
dropParked(rec) {
|
|
10045
|
+
this.parkedRedeliver = this.parkedRedeliver.filter((p) => p.task !== rec.id);
|
|
10046
|
+
if (rec.deliveryParked) rec.deliveryParked = "moved_on";
|
|
10047
|
+
}
|
|
10048
|
+
/** True while there is a parked delivery the next line may resume: unheard text already parked, or a barge-parked
|
|
10049
|
+
* task still running (one the user moved on from does not count). */
|
|
8502
10050
|
hasParkedDelivery() {
|
|
8503
|
-
return this.parkedRedeliver.length > 0 || [...this.tasks.values()].some((t) => t.status === "running" && t.deliveryParked);
|
|
8504
|
-
}
|
|
8505
|
-
/**
|
|
8506
|
-
*
|
|
10051
|
+
return this.parkedRedeliver.length > 0 || [...this.tasks.values()].some((t) => t.status === "running" && t.deliveryParked === "barge");
|
|
10052
|
+
}
|
|
10053
|
+
/** The note for an aside over a parked delivery: the same reply-interruption note a cut reflex reply gets
|
|
10054
|
+
* (interruptionNote), over the delivery as it was being said — the cut utterance's heard part, then every unheard
|
|
10055
|
+
* piece. Nothing parked yet (the task is still working) → its result simply follows the answer. */
|
|
10056
|
+
asideNote(told) {
|
|
10057
|
+
const rest = told.map((p) => p.text).join(" ").trim();
|
|
10058
|
+
if (!rest) return "\n[you were in the middle of delivering a task result \u2014 answer this briefly; the rest of the result follows right after your answer. If their words are an unfinished fragment, call Hold instead.]";
|
|
10059
|
+
const heard = told[0]?.heard ?? "";
|
|
10060
|
+
return interruptionNote({ full: heard + rest, heard }, "aside");
|
|
10061
|
+
}
|
|
10062
|
+
/** Speak the parked delivery now (resume), in order, and clear it. */
|
|
8507
10063
|
redeliverParked() {
|
|
8508
|
-
|
|
8509
|
-
|
|
8510
|
-
|
|
8511
|
-
|
|
8512
|
-
|
|
8513
|
-
}
|
|
8514
|
-
return true;
|
|
10064
|
+
const text = this.parkedRedeliver.splice(0).map((p) => p.text).join(" ").trim();
|
|
10065
|
+
if (!text) return;
|
|
10066
|
+
this.offerOpen = false;
|
|
10067
|
+
this.options.host?.notify?.({ kind: "speak_utterance", message: text });
|
|
10068
|
+
this.notify("diag", "parked_redelivered", { chars: text.length });
|
|
8515
10069
|
}
|
|
8516
10070
|
/** Resolve when all queued voice turns AND all in-flight worker tasks have settled (tests, graceful shutdown). */
|
|
8517
10071
|
async idle() {
|
|
@@ -8567,9 +10121,8 @@ ${nowLine()}. Anchor every relative or time-sensitive reference \u2014 "today",
|
|
|
8567
10121
|
const failed = events.find((e) => /^\[task\b[^\]\n]*\bfailed\b/i.test(e));
|
|
8568
10122
|
this.resetTurn();
|
|
8569
10123
|
this.turnFollowUp = nonCleanTurn;
|
|
8570
|
-
await this.voice.send(events.join("\n"));
|
|
8571
|
-
this.
|
|
8572
|
-
if (this.silentTurn) await this.ackIfSilent(failed ? "Sorry, that didn't work \u2014 the task failed." : void 0);
|
|
10124
|
+
const res = await this.voice.send(events.join("\n"));
|
|
10125
|
+
await this.endTurn(res, failed ? "Sorry, that didn't work \u2014 the task failed." : void 0);
|
|
8573
10126
|
this.notify("revoice_done", "");
|
|
8574
10127
|
});
|
|
8575
10128
|
}
|
|
@@ -8577,13 +10130,14 @@ ${nowLine()}. Anchor every relative or time-sensitive reference \u2014 "today",
|
|
|
8577
10130
|
* Act briefs get a self-verify footer — the worker's report is trusted without review, so it
|
|
8578
10131
|
* must check its own work before reporting (nearly free under prompt caching; measured honest:
|
|
8579
10132
|
* it does NOT fix one-shot logic bugs — see mind/10). Think tasks are pure reasoning — no footer. */
|
|
10133
|
+
/** Static text snapshot of the last `turns` user/assistant messages (`role: text` lines). */
|
|
10134
|
+
recentExcerpt(turns = this.options.excerptTurns) {
|
|
10135
|
+
return this.voice.transcript.filter((m) => (m.role === "user" || m.role === "assistant") && contentText(m.content).trim()).slice(-turns).map((m) => `${m.role}: ${contentText(m.content)}`).join("\n");
|
|
10136
|
+
}
|
|
8580
10137
|
buildBrief(brief, tier = "act", deliver = true) {
|
|
8581
|
-
const recent = this.
|
|
10138
|
+
const recent = this.recentExcerpt();
|
|
8582
10139
|
const verify = tier === "act" ? "\n\nBefore reporting done: re-read what you changed and check it against EVERY requirement above \u2014 fix any gap first. Your report is trusted without review." : "";
|
|
8583
|
-
const deliverContract = deliver ? `
|
|
8584
|
-
|
|
8585
|
-
## DELIVER (spoken delivery)
|
|
8586
|
-
You are reporting back to a user who is LISTENING. Stream your work normally \u2014 your prose is the written work record and detail, and is NOT spoken. Wrap anything the user should HEAR in <spoken>\u2026</spoken> tags. LEAD WITH the actual content they asked for: if they asked for a specific piece of content \u2014 a value, a name, the actual lines, the writing itself \u2014 that content goes INSIDE the <spoken> tags, not a remark about it. Your FIRST <spoken> segment is substantive \u2014 never a greeting or an acknowledgement (the front-end has already acked; do not double-ack). Keep spoken text concise and natural for the ear: short sentences, no markdown. NEVER enumerate in speech \u2014 no numbered or bulleted lists ("One. \u2026 Two. \u2026" is robotic). Deliver multiple items as flowing conversation with brief connective phrasing ("here's one\u2026", "and another\u2026", "oh, and\u2026"), pausing between items with sentence breaks, not numbers.` + (this.options.emotionTags ? " Inside <spoken>, you may prefix a sentence with an inline [emotion] tag (e.g. [excited], [curious]) to color how it is voiced \u2014 only when it genuinely fits, and vary it; [laughter] gives a natural laugh." : "") : "";
|
|
10140
|
+
const deliverContract = deliver ? "\n\n## DELIVER (spoken delivery)\nYou are reporting back to a user who is LISTENING. Stream your work normally \u2014 your prose is the written work record and detail, and is NOT spoken. Wrap anything the user should HEAR in <spoken>\u2026</spoken> tags. LEAD WITH the actual content they asked for: if they asked for a specific piece of content \u2014 a value, a name, the actual lines, the writing itself \u2014 that content goes INSIDE the <spoken> tags, not a remark about it. Your FIRST <spoken> segment is substantive \u2014 never a greeting or an acknowledgement (the front-end has already acked; do not double-ack). Keep spoken text concise and natural for the ear: short sentences, no markdown. " + (this.options.spokenBudgetChars ? `Speak a SHORT summary only: at most three short sentences with the one thing that matters most, then ONE short offer that names what else you have, as a question they can answer in a word \u2014 under ${this.options.spokenBudgetChars} characters in all, the offer included. Everything else stays in your written prose (it is kept and they can ask for it); spoken text past that budget is cut and held until they ask. ` : "") + `NEVER enumerate in speech \u2014 no numbered or bulleted lists ("One. \u2026 Two. \u2026" is robotic). Deliver multiple items as flowing conversation with brief connective phrasing ("here's one\u2026", "and another\u2026", "oh, and\u2026"), pausing between items with sentence breaks, not numbers.` + (this.options.emotionTags ? " Inside <spoken>, you may prefix a sentence with an inline [emotion] tag (e.g. [excited], [curious]) to color how it is voiced \u2014 only when it genuinely fits, and vary it; [laughter] gives a natural laugh." : "") : "";
|
|
8587
10141
|
return `${nowLine()}.
|
|
8588
10142
|
|
|
8589
10143
|
` + (recent ? `${brief}
|
|
@@ -8629,12 +10183,7 @@ ${recent}` : brief) + verify + deliverContract;
|
|
|
8629
10183
|
return a || "(no answer from the user \u2014 use your best judgment and note the assumption)";
|
|
8630
10184
|
};
|
|
8631
10185
|
const splitter = new SpokenSplitter();
|
|
8632
|
-
const speak = (seg) =>
|
|
8633
|
-
if (!seg) return;
|
|
8634
|
-
const r = this.tasks.get(id);
|
|
8635
|
-
if (r) r.spokenText = (r.spokenText ? r.spokenText + " " : "") + seg;
|
|
8636
|
-
if (!r?.deliveryParked) o.host?.notify?.({ kind: "speak_utterance", message: seg });
|
|
8637
|
-
};
|
|
10186
|
+
const speak = (seg) => this.deliverSegment(this.tasks.get(id), seg);
|
|
8638
10187
|
const coalescer = new SentenceCoalescer();
|
|
8639
10188
|
const feedSpoken = (s) => {
|
|
8640
10189
|
const ready = coalescer.feed(s);
|
|
@@ -8648,6 +10197,7 @@ ${recent}` : brief) + verify + deliverContract;
|
|
|
8648
10197
|
if (ev?.kind === "text_delta" && typeof ev.message === "string") {
|
|
8649
10198
|
const { spoken, detail } = splitter.feed(ev.message);
|
|
8650
10199
|
feedSpoken(spoken);
|
|
10200
|
+
if (!splitter.inSpoken) flushSpoken();
|
|
8651
10201
|
if (detail.trim()) pushTail(detail.trim());
|
|
8652
10202
|
return;
|
|
8653
10203
|
}
|
|
@@ -8704,7 +10254,7 @@ Another agent just implemented the above. Independently check the CURRENT state
|
|
|
8704
10254
|
this.notify("task_verify", `task ${id}: verifying`, { id });
|
|
8705
10255
|
const cres = await new Agent(checkerOpts).run(checkBrief);
|
|
8706
10256
|
if (cres.finishReason !== "stop") {
|
|
8707
|
-
|
|
10257
|
+
log20.warn(`task ${id}: verify inconclusive (${cres.finishReason})`);
|
|
8708
10258
|
this.notify("task_verify", `task ${id}: verify inconclusive (${cres.finishReason})`, { id, finishReason: cres.finishReason });
|
|
8709
10259
|
}
|
|
8710
10260
|
const sum = (a = 0, b = 0) => a + b;
|
|
@@ -8735,7 +10285,7 @@ Another agent just implemented the above. Independently check the CURRENT state
|
|
|
8735
10285
|
const due = () => {
|
|
8736
10286
|
if (this.pendingAsks.size) return void 0;
|
|
8737
10287
|
const rec = this.tasks.get(id);
|
|
8738
|
-
return rec && rec.status === "running" && Date.now() - lastAt >= this.options.progressIntervalMs ? rec : void 0;
|
|
10288
|
+
return rec && rec.status === "running" && !rec.deliveryParked && Date.now() - lastAt >= this.options.progressIntervalMs ? rec : void 0;
|
|
8739
10289
|
};
|
|
8740
10290
|
const emit = (rec, line, call) => {
|
|
8741
10291
|
lastAt = Date.now();
|
|
@@ -8840,7 +10390,7 @@ Another agent just implemented the above. Independently check the CURRENT state
|
|
|
8840
10390
|
rec.status = "done";
|
|
8841
10391
|
rec.result = res.text;
|
|
8842
10392
|
const incomplete = res.finishReason !== "stop" && res.finishReason !== "empty";
|
|
8843
|
-
|
|
10393
|
+
log20.verbose(`task ${id} done (${res.steps} steps${incomplete ? `, INCOMPLETE: ${res.finishReason}` : ""})`);
|
|
8844
10394
|
this.notify("task_done", `task ${id} (${rec.label}) completed`, {
|
|
8845
10395
|
id,
|
|
8846
10396
|
text: res.text,
|
|
@@ -8852,46 +10402,39 @@ Another agent just implemented the above. Independently check the CURRENT state
|
|
|
8852
10402
|
});
|
|
8853
10403
|
if (incomplete) {
|
|
8854
10404
|
if (this.foldIfSuperseded(rec, res.text)) return;
|
|
10405
|
+
this.dropParked(rec);
|
|
8855
10406
|
return this.queueRevoice(this.integrationPrompt(rec, "incomplete", res.text, res.finishReason), true);
|
|
8856
10407
|
}
|
|
8857
10408
|
const tail = rec.splitter?.flush();
|
|
8858
|
-
if (tail?.spoken
|
|
8859
|
-
if (res.text.trim()) this.
|
|
8860
|
-
if (
|
|
8861
|
-
|
|
8862
|
-
|
|
8863
|
-
if (this.awaitTrivialRedeliver) {
|
|
8864
|
-
this.awaitTrivialRedeliver = false;
|
|
8865
|
-
this.options.host?.notify?.({ kind: "speak_utterance", message: gist });
|
|
8866
|
-
this.notify("diag", "parked_redelivered", { chars: gist.length });
|
|
8867
|
-
} else this.parkedRedeliver.push(gist);
|
|
8868
|
-
}
|
|
8869
|
-
}
|
|
8870
|
-
if (!rec.splitter?.spokeAny && res.text.trim() && !rec.deliveryParked)
|
|
8871
|
-
this.options.host?.notify?.({ kind: "speak_utterance", message: res.text });
|
|
10409
|
+
if (tail?.spoken) this.deliverSegment(rec, tail.spoken);
|
|
10410
|
+
if (!rec.splitter?.spokeAny && res.text.trim()) this.deliverSegment(rec, res.text);
|
|
10411
|
+
if (res.text.trim()) this.voice.transcript.push({ role: "assistant", content: res.text + (rec.capOffer ? `
|
|
10412
|
+
|
|
10413
|
+
(Said aloud in place of the rest of the spoken summary: "${rec.capOffer}")` : "") });
|
|
8872
10414
|
}
|
|
8873
10415
|
onWorkerFailed(id, err2) {
|
|
8874
10416
|
this.failTask(this.tasks.get(id), err2 instanceof Error ? err2.message : String(err2));
|
|
8875
10417
|
}
|
|
8876
|
-
/** A delivery the user has SUPERSEDED —
|
|
10418
|
+
/** A delivery the user has SUPERSEDED — moved on from (deliveryParked 'moved_on', set by a redirect) —
|
|
8877
10419
|
* must not hijack the voice when it settles late (partial or failed): that would talk over the new topic
|
|
8878
10420
|
* and, worse, auto-escalate work the user already abandoned. Fold a recoverable note into the transcript
|
|
8879
10421
|
* instead (the reflex can surface it if asked) and report true so the caller skips queueRevoice. A merely
|
|
8880
|
-
* barge-parked task (
|
|
10422
|
+
* barge-parked task ('barge' — a "go on" may still resume it) is NOT superseded: it
|
|
8881
10423
|
* keeps the normal surfacing path so a failure the user still cares about is not swallowed. */
|
|
8882
10424
|
foldIfSuperseded(rec, note) {
|
|
8883
|
-
if (
|
|
10425
|
+
if (rec.deliveryParked !== "moved_on") return false;
|
|
8884
10426
|
if (note.trim()) this.voice.transcript.push({ role: "assistant", content: note });
|
|
8885
|
-
|
|
10427
|
+
log20.verbose(`task ${rec.id} settled but superseded (${rec.status}) \u2014 folded into transcript, not voiced`);
|
|
8886
10428
|
return true;
|
|
8887
10429
|
}
|
|
8888
10430
|
failTask(rec, msg) {
|
|
8889
10431
|
this.dropAsk(rec.id);
|
|
8890
10432
|
rec.status = "error";
|
|
8891
10433
|
rec.result = msg;
|
|
8892
|
-
|
|
10434
|
+
log20.warn(`task ${rec.id} failed: ${msg}`);
|
|
8893
10435
|
this.notify("task_error", `task ${rec.id} (${rec.label}) failed: ${msg}`);
|
|
8894
10436
|
if (this.foldIfSuperseded(rec, `The "${rec.label}" task failed: ${msg}`)) return;
|
|
10437
|
+
this.dropParked(rec);
|
|
8895
10438
|
this.queueRevoice(this.integrationPrompt(rec, "error", msg, "error"), true);
|
|
8896
10439
|
}
|
|
8897
10440
|
// --- voice tools (closures over this instance) ---
|
|
@@ -8920,10 +10463,18 @@ Another agent just implemented the above. Independently check the CURRENT state
|
|
|
8920
10463
|
this.notify("task_started", `task ${id} (${lbl}) started`, { id, brief, tier });
|
|
8921
10464
|
return id;
|
|
8922
10465
|
}
|
|
10466
|
+
/** Tool result for a dispatch. The task is ALREADY RUNNING — live, the terse "Acknowledge briefly" drew
|
|
10467
|
+
* "Did you want me to look up today's news?" right after dispatching exactly that (session 20260923-101910
|
|
10468
|
+
* msg 18). Also truthful about delivery: a clean result is spoken by the worker itself and lands in
|
|
10469
|
+
* context (TaskStatus returns it); only failures come back as a [task … failed] event. */
|
|
10470
|
+
dispatchResult(id, verb) {
|
|
10471
|
+
const after = `The worker speaks its result to the user itself when done (TaskStatus ${id} returns it).`;
|
|
10472
|
+
return this.spokeBeforeDispatch ? `${verb} task ${id} \u2014 it is already running. You already acknowledged \u2014 end your turn now with NO further text. ${after}` : `${verb} task ${id} \u2014 it is already running. Now tell the user in ONE short sentence that you are on it (what you are doing) \u2014 do NOT ask whether they want it; it is already happening. ${after}`;
|
|
10473
|
+
}
|
|
8923
10474
|
actTool() {
|
|
8924
10475
|
return {
|
|
8925
10476
|
name: "Act",
|
|
8926
|
-
description: 'Escalate real work (reading/editing files, searching, running tasks, building) to a standard background worker. Returns immediately with a task id; the result
|
|
10477
|
+
description: 'Escalate real work (reading/editing files, searching, running tasks, building) to a standard background worker. Returns immediately with a task id; when it finishes the worker speaks its result to the user itself (failures arrive as a "[task <id> failed]" event). Provide a clear, self-contained `brief` (the worker does not hear the live conversation).',
|
|
8927
10478
|
parameters: {
|
|
8928
10479
|
type: "object",
|
|
8929
10480
|
required: ["brief"],
|
|
@@ -8938,7 +10489,7 @@ Another agent just implemented the above. Independently check the CURRENT state
|
|
|
8938
10489
|
this.turnBriefs.add(String(brief ?? ""));
|
|
8939
10490
|
this.voice.options.toolChoice = "none";
|
|
8940
10491
|
const id = await this.dispatch(String(brief ?? ""), "act", label ? String(label) : void 0, this.turnFollowUp);
|
|
8941
|
-
return this.
|
|
10492
|
+
return this.dispatchResult(id, "Acting on");
|
|
8942
10493
|
}
|
|
8943
10494
|
};
|
|
8944
10495
|
}
|
|
@@ -8960,7 +10511,7 @@ Another agent just implemented the above. Independently check the CURRENT state
|
|
|
8960
10511
|
this.turnBriefs.add(String(brief ?? ""));
|
|
8961
10512
|
this.voice.options.toolChoice = "none";
|
|
8962
10513
|
const id = await this.dispatch(String(brief ?? ""), "think", label ? String(label) : void 0, this.turnFollowUp);
|
|
8963
|
-
return this.
|
|
10514
|
+
return this.dispatchResult(id, "Thinking on");
|
|
8964
10515
|
}
|
|
8965
10516
|
};
|
|
8966
10517
|
}
|
|
@@ -8972,7 +10523,13 @@ Another agent just implemented the above. Independently check the CURRENT state
|
|
|
8972
10523
|
run: async ({ id }) => {
|
|
8973
10524
|
const list = id ? [this.tasks.get(String(id))].filter(Boolean) : [...this.tasks.values()];
|
|
8974
10525
|
if (!list.length) return id ? `No task '${id}'.` : "No background tasks.";
|
|
8975
|
-
|
|
10526
|
+
const cap = id ? 1500 : 300;
|
|
10527
|
+
const clip = (x) => x.length > cap ? `${x.slice(0, cap)}\u2026 (truncated)` : x;
|
|
10528
|
+
return list.map((t) => {
|
|
10529
|
+
const head = `${t.id} (${t.label}): ${t.status}`;
|
|
10530
|
+
const body = (t.status === "done" ? t.spokenText?.trim() || t.result?.trim() : t.status === "error" ? t.result?.trim() : "") ?? "";
|
|
10531
|
+
return body ? `${head}. ${t.status === "error" ? "Error" : "Result"}: ${clip(body)}` : head;
|
|
10532
|
+
}).join("\n");
|
|
8976
10533
|
}
|
|
8977
10534
|
};
|
|
8978
10535
|
}
|
|
@@ -8984,18 +10541,20 @@ Another agent just implemented the above. Independently check the CURRENT state
|
|
|
8984
10541
|
const kinds = [.../* @__PURE__ */ new Set(["time", "branch", "ls", "file", "capabilities", ...Object.keys(this.options.quickLook ?? {})])];
|
|
8985
10542
|
return {
|
|
8986
10543
|
name: "QuickLook",
|
|
8987
|
-
description: `Instant read-only lookup \u2014 one of: ${kinds.join(", ")}. For trivial facts only; anything needing search, commands, or reasoning goes through Act
|
|
10544
|
+
description: `Instant read-only lookup \u2014 one of: ${kinds.join(", ")}. ` + (kinds.includes("sessions") ? '`sessions` = EARLIER conversations with this user: what:"sessions" lists them; what:"sessions" with path:"<session id>" reads one (not what:"file"). ' : "") + "For trivial facts only; anything needing search, commands, or reasoning goes through Act.",
|
|
8988
10545
|
parameters: {
|
|
8989
10546
|
type: "object",
|
|
8990
10547
|
required: ["what"],
|
|
8991
10548
|
properties: {
|
|
8992
10549
|
what: { type: "string", enum: kinds, description: "what to look up" },
|
|
8993
|
-
path: { type: "string", description:
|
|
10550
|
+
path: { type: "string", description: 'for ls/file: the path to look at; for sessions: a session id (or "previous")' }
|
|
8994
10551
|
}
|
|
8995
10552
|
},
|
|
8996
10553
|
run: async ({ what, path }) => {
|
|
8997
10554
|
const fs = this.options.fs;
|
|
8998
10555
|
try {
|
|
10556
|
+
const sessions = this.options.quickLook?.sessions;
|
|
10557
|
+
if (sessions && (what === "file" || what === "ls") && SESSION_ID_RE.test(String(path ?? "").trim())) return await sessions(String(path).trim());
|
|
8999
10558
|
const over = this.options.quickLook?.[String(what)];
|
|
9000
10559
|
if (over) return await over(path ? String(path) : void 0);
|
|
9001
10560
|
switch (String(what)) {
|
|
@@ -9290,7 +10849,7 @@ import { MemFilesystem as MemFilesystem3, IndexedDbFilesystem, CommandExecutor a
|
|
|
9290
10849
|
init_logging();
|
|
9291
10850
|
import { spawn } from "child_process";
|
|
9292
10851
|
import { createHash } from "crypto";
|
|
9293
|
-
var
|
|
10852
|
+
var log21 = forComponent("mcp");
|
|
9294
10853
|
var PROTOCOL_VERSION = "2025-06-18";
|
|
9295
10854
|
var DEFAULT_TIMEOUT_MS = 3e4;
|
|
9296
10855
|
var DEFAULT_CALL_TIMEOUT_MS = 30 * 6e4;
|
|
@@ -9320,7 +10879,7 @@ var StdioTransport = class {
|
|
|
9320
10879
|
proc.stdout.setEncoding("utf8");
|
|
9321
10880
|
proc.stdout.on("data", (chunk) => this.onData(chunk));
|
|
9322
10881
|
proc.stderr.setEncoding("utf8");
|
|
9323
|
-
proc.stderr.on("data", (chunk) =>
|
|
10882
|
+
proc.stderr.on("data", (chunk) => log21.debug(`[${command}] stderr:`, chunk.trimEnd()));
|
|
9324
10883
|
proc.on("exit", (code) => this.failAll(new Error(`MCP server "${command}" exited (code ${code})`)));
|
|
9325
10884
|
proc.on("error", (e) => this.failAll(e instanceof Error ? e : new Error(String(e))));
|
|
9326
10885
|
}
|
|
@@ -9334,7 +10893,7 @@ var StdioTransport = class {
|
|
|
9334
10893
|
try {
|
|
9335
10894
|
this.dispatch(JSON.parse(line));
|
|
9336
10895
|
} catch (e) {
|
|
9337
|
-
|
|
10896
|
+
log21.debug("dropping non-JSON line from MCP server:", line, e);
|
|
9338
10897
|
}
|
|
9339
10898
|
}
|
|
9340
10899
|
}
|
|
@@ -9344,7 +10903,7 @@ var StdioTransport = class {
|
|
|
9344
10903
|
try {
|
|
9345
10904
|
p2?.onProgress?.(msg.params ?? {});
|
|
9346
10905
|
} catch (e) {
|
|
9347
|
-
|
|
10906
|
+
log21.debug("onProgress handler threw", e);
|
|
9348
10907
|
}
|
|
9349
10908
|
return;
|
|
9350
10909
|
}
|
|
@@ -9382,7 +10941,7 @@ var StdioTransport = class {
|
|
|
9382
10941
|
const onAbort = () => {
|
|
9383
10942
|
if (!this.pending.delete(id)) return;
|
|
9384
10943
|
clearTimeout(timer);
|
|
9385
|
-
this.notify("notifications/cancelled", { requestId: id, reason: String(signal?.reason?.message ?? "cancelled") }).catch((e) =>
|
|
10944
|
+
this.notify("notifications/cancelled", { requestId: id, reason: String(signal?.reason?.message ?? "cancelled") }).catch((e) => log21.debug("cancel notify failed", e));
|
|
9386
10945
|
reject(abortError(signal));
|
|
9387
10946
|
};
|
|
9388
10947
|
const done = () => signal?.removeEventListener("abort", onAbort);
|
|
@@ -9406,7 +10965,7 @@ var StdioTransport = class {
|
|
|
9406
10965
|
try {
|
|
9407
10966
|
this.proc?.stdin?.end();
|
|
9408
10967
|
} catch (e) {
|
|
9409
|
-
|
|
10968
|
+
log21.debug("stdin end failed", e);
|
|
9410
10969
|
}
|
|
9411
10970
|
this.proc?.kill();
|
|
9412
10971
|
}
|
|
@@ -9441,7 +11000,7 @@ var HttpTransport = class {
|
|
|
9441
11000
|
return await this.post({ jsonrpc: "2.0", id, method, params: opts.onProgress ? withProgressToken(params, id) : params }, false, signal, opts.onProgress);
|
|
9442
11001
|
} catch (e) {
|
|
9443
11002
|
if (opts.signal?.aborted) {
|
|
9444
|
-
void this.notify("notifications/cancelled", { requestId: id, reason: String(opts.signal.reason?.message ?? "cancelled") }).catch((err2) =>
|
|
11003
|
+
void this.notify("notifications/cancelled", { requestId: id, reason: String(opts.signal.reason?.message ?? "cancelled") }).catch((err2) => log21.debug("cancel notify failed", err2));
|
|
9445
11004
|
throw abortError(opts.signal);
|
|
9446
11005
|
}
|
|
9447
11006
|
throw e;
|
|
@@ -9484,7 +11043,7 @@ function sseMessage(line) {
|
|
|
9484
11043
|
try {
|
|
9485
11044
|
return JSON.parse(trimmed.slice(5).trim());
|
|
9486
11045
|
} catch (e) {
|
|
9487
|
-
|
|
11046
|
+
log21.debug("skipping unparseable SSE data line", e);
|
|
9488
11047
|
return void 0;
|
|
9489
11048
|
}
|
|
9490
11049
|
}
|
|
@@ -9494,7 +11053,7 @@ async function readSseResponse(resp, id, onProgress) {
|
|
|
9494
11053
|
try {
|
|
9495
11054
|
onProgress?.(obj.params ?? {});
|
|
9496
11055
|
} catch (e) {
|
|
9497
|
-
|
|
11056
|
+
log21.debug("onProgress handler threw", e);
|
|
9498
11057
|
}
|
|
9499
11058
|
return void 0;
|
|
9500
11059
|
}
|
|
@@ -9593,7 +11152,7 @@ async function mountWithDeadline(name, cfg, mountTimeoutMs) {
|
|
|
9593
11152
|
return { name, client, tools, specs, serverInfo: init?.serverInfo, config: cfg };
|
|
9594
11153
|
})(), mountTimeoutMs, name);
|
|
9595
11154
|
} catch (e) {
|
|
9596
|
-
await client.close().catch((err2) =>
|
|
11155
|
+
await client.close().catch((err2) => log21.debug(`close after failed mount of "${name}": ${err2}`));
|
|
9597
11156
|
throw e;
|
|
9598
11157
|
}
|
|
9599
11158
|
}
|
|
@@ -9604,15 +11163,15 @@ function validEntries(servers) {
|
|
|
9604
11163
|
return Object.entries(servers).filter(([name, cfg]) => {
|
|
9605
11164
|
if (!cfg || cfg.disabled) return false;
|
|
9606
11165
|
if (!cfg.command && !cfg.url) {
|
|
9607
|
-
|
|
11166
|
+
log21.warn(`MCP server "${name}" needs a command (stdio) or url (http) \u2014 skipping`);
|
|
9608
11167
|
return false;
|
|
9609
11168
|
}
|
|
9610
11169
|
return true;
|
|
9611
11170
|
});
|
|
9612
11171
|
}
|
|
9613
11172
|
function logMountFailure(name, e) {
|
|
9614
|
-
if (e instanceof McpAuthError)
|
|
9615
|
-
else
|
|
11173
|
+
if (e instanceof McpAuthError) log21.warn(`MCP "${name}" needs-auth: HTTP ${e.status} \u2014 set bearerToken or headers in its config; skipping`);
|
|
11174
|
+
else log21.error(`MCP server "${name}" failed to mount: ${e?.message ?? e}`);
|
|
9616
11175
|
}
|
|
9617
11176
|
async function mountMcpServers(servers = {}, opts = {}) {
|
|
9618
11177
|
const entries = validEntries(servers);
|
|
@@ -9622,7 +11181,7 @@ async function mountMcpServers(servers = {}, opts = {}) {
|
|
|
9622
11181
|
const name = entries[i][0];
|
|
9623
11182
|
if (r.status === "fulfilled") {
|
|
9624
11183
|
out.push(r.value);
|
|
9625
|
-
|
|
11184
|
+
log21.debug(`MCP "${name}" mounted \u2014 ${r.value.tools.length} tool(s)${r.value.serverInfo?.name ? ` from ${r.value.serverInfo.name}` : ""}`);
|
|
9626
11185
|
} else logMountFailure(name, r.reason);
|
|
9627
11186
|
});
|
|
9628
11187
|
return out;
|
|
@@ -9662,7 +11221,7 @@ var McpPool = class {
|
|
|
9662
11221
|
const prev = this.warm.get(key);
|
|
9663
11222
|
if (prev) {
|
|
9664
11223
|
clearTimeout(prev.timer);
|
|
9665
|
-
if (prev.client !== client) void prev.client.close().catch((err2) =>
|
|
11224
|
+
if (prev.client !== client) void prev.client.close().catch((err2) => log21.debug(`warm-pool replace close failed: ${err2}`));
|
|
9666
11225
|
}
|
|
9667
11226
|
const e = { client, timer: void 0 };
|
|
9668
11227
|
this.warm.set(key, e);
|
|
@@ -9679,7 +11238,7 @@ var McpPool = class {
|
|
|
9679
11238
|
const e = this.warm.get(key);
|
|
9680
11239
|
if (!e) return;
|
|
9681
11240
|
this.warm.delete(key);
|
|
9682
|
-
await e.client.close().catch((err2) =>
|
|
11241
|
+
await e.client.close().catch((err2) => log21.debug(`warm-pool evict close failed: ${err2}`));
|
|
9683
11242
|
}
|
|
9684
11243
|
async closeAll() {
|
|
9685
11244
|
for (const e of this.warm.values()) {
|
|
@@ -9897,7 +11456,7 @@ init_tools_shell();
|
|
|
9897
11456
|
// src/tools.notify.ts
|
|
9898
11457
|
init_logging();
|
|
9899
11458
|
import { execFile } from "child_process";
|
|
9900
|
-
var
|
|
11459
|
+
var log23 = forComponent("notify");
|
|
9901
11460
|
function makeNotifyTool(opts = {}) {
|
|
9902
11461
|
const platform2 = opts.platform ?? process.platform;
|
|
9903
11462
|
const run = opts.exec ?? execFile;
|
|
@@ -9921,7 +11480,7 @@ function makeNotifyTool(opts = {}) {
|
|
|
9921
11480
|
return new Promise((resolve5) => {
|
|
9922
11481
|
run(argv[0], argv[1], { timeout: 5e3 }, (e) => {
|
|
9923
11482
|
if (e) {
|
|
9924
|
-
|
|
11483
|
+
log23.debug("notification failed", e);
|
|
9925
11484
|
resolve5(`Notification failed: ${e.message}`);
|
|
9926
11485
|
} else resolve5("Notification shown.");
|
|
9927
11486
|
});
|
|
@@ -9937,7 +11496,7 @@ import { BodDB as BodDB2 } from "@bod.ee/db";
|
|
|
9937
11496
|
init_logging();
|
|
9938
11497
|
import { existsSync as existsSync2, readFileSync as readFileSync4 } from "fs";
|
|
9939
11498
|
import { homedir } from "os";
|
|
9940
|
-
var
|
|
11499
|
+
var log24 = forComponent("cli-util");
|
|
9941
11500
|
function dotDirs(base, sub, opts = {}) {
|
|
9942
11501
|
const home = opts.home ?? homedir();
|
|
9943
11502
|
const dirs = [`${base}/.agent/${sub}`, `${base}/.claude/${sub}`, `${home}/.agent/${sub}`, `${home}/.claude/${sub}`];
|
|
@@ -9954,7 +11513,7 @@ function parseJson(text, fallback, what = "json") {
|
|
|
9954
11513
|
try {
|
|
9955
11514
|
return JSON.parse(text);
|
|
9956
11515
|
} catch (e) {
|
|
9957
|
-
|
|
11516
|
+
log24.debug(`parseJson(${what}) failed: ${e.message}`);
|
|
9958
11517
|
return fallback;
|
|
9959
11518
|
}
|
|
9960
11519
|
}
|
|
@@ -9964,7 +11523,7 @@ function readJsonFile(path, fallback) {
|
|
|
9964
11523
|
try {
|
|
9965
11524
|
text = readFileSync4(path, "utf8");
|
|
9966
11525
|
} catch (e) {
|
|
9967
|
-
|
|
11526
|
+
log24.debug(`readJsonFile(${path}) unreadable: ${e.message}`);
|
|
9968
11527
|
return fallback;
|
|
9969
11528
|
}
|
|
9970
11529
|
return parseJson(text, fallback, path);
|
|
@@ -10263,7 +11822,7 @@ import { existsSync as existsSync4, mkdirSync as mkdirSync5, readFileSync as rea
|
|
|
10263
11822
|
import { homedir as homedir3 } from "os";
|
|
10264
11823
|
import { dirname as dirname3, join as join6 } from "path";
|
|
10265
11824
|
import { fileURLToPath } from "url";
|
|
10266
|
-
var
|
|
11825
|
+
var log25 = forComponent("VoiceIO");
|
|
10267
11826
|
var now3 = () => performance.now();
|
|
10268
11827
|
var Player = class {
|
|
10269
11828
|
proc = null;
|
|
@@ -10277,7 +11836,7 @@ var Player = class {
|
|
|
10277
11836
|
["-loglevel", "quiet", "-nodisp", "-fflags", "nobuffer", "-flags", "low_delay", "-probesize", "32", "-f", "s16le", "-ar", String(TTS_SAMPLE_RATE), "-ch_layout", "mono", "-i", "-"],
|
|
10278
11837
|
{ stdio: ["pipe", "ignore", "ignore"] }
|
|
10279
11838
|
);
|
|
10280
|
-
this.proc.on("error", (e) =>
|
|
11839
|
+
this.proc.on("error", (e) => log25.warn(`ffplay error: ${e.message}`));
|
|
10281
11840
|
this.proc.stdin.on("error", () => {
|
|
10282
11841
|
});
|
|
10283
11842
|
this.bytesWritten = 0;
|
|
@@ -10315,7 +11874,7 @@ function detectFfmpegMic() {
|
|
|
10315
11874
|
const devices = [...audio.matchAll(/\[(\d+)\] (.+)/g)].map(([, idx, name]) => ({ idx, name: name.trim() }));
|
|
10316
11875
|
const mic = devices.find((d) => /microphone|built-in/i.test(d.name) && !/teams|blackhole|loopback/i.test(d.name)) ?? devices[0];
|
|
10317
11876
|
if (!mic) throw new Error("no audio input device found");
|
|
10318
|
-
|
|
11877
|
+
log25.debug(`ffmpeg mic: [${mic.idx}] ${mic.name}`);
|
|
10319
11878
|
return `:${mic.idx}`;
|
|
10320
11879
|
}
|
|
10321
11880
|
function detectedInputDevice() {
|
|
@@ -10351,15 +11910,15 @@ function resolveAecBinary() {
|
|
|
10351
11910
|
if (existsSync4(bin) && statSync4(bin).mtimeMs >= statSync4(src).mtimeMs) return bin;
|
|
10352
11911
|
if (spawnSync2("which", ["swiftc"]).status !== 0) return null;
|
|
10353
11912
|
mkdirSync5(cacheDir, { recursive: true });
|
|
10354
|
-
|
|
11913
|
+
log25.info("compiling AEC mic helper (first run)\u2026");
|
|
10355
11914
|
const build = spawnSync2("swiftc", ["-O", "-o", bin, src, "-Xlinker", "-sectcreate", "-Xlinker", "__TEXT", "-Xlinker", "__info_plist", "-Xlinker", plist], { encoding: "utf8" });
|
|
10356
11915
|
if (build.status !== 0) {
|
|
10357
|
-
|
|
11916
|
+
log25.warn(`AEC build failed: ${build.stderr?.slice(0, 400)}`);
|
|
10358
11917
|
return null;
|
|
10359
11918
|
}
|
|
10360
11919
|
const sign = spawnSync2("codesign", ["-fs", "-", bin], { encoding: "utf8" });
|
|
10361
11920
|
if (sign.status !== 0) {
|
|
10362
|
-
|
|
11921
|
+
log25.warn(`codesign failed: ${sign.stderr?.slice(0, 200)}`);
|
|
10363
11922
|
return null;
|
|
10364
11923
|
}
|
|
10365
11924
|
return bin;
|
|
@@ -10401,16 +11960,16 @@ var NodeMicSource = class {
|
|
|
10401
11960
|
this.proc = spawn2(this.bin, [], { stdio: ["ignore", "pipe", "ignore"] });
|
|
10402
11961
|
} else {
|
|
10403
11962
|
if (spawnSync2("which", ["ffmpeg"]).status !== 0) throw new Error("voice I/O unavailable: no AEC helper and no ffmpeg on PATH");
|
|
10404
|
-
|
|
11963
|
+
log25.info("mic: raw capture (no AEC) \u2014 echo handled heuristically; headphones recommended");
|
|
10405
11964
|
this.proc = spawn2(
|
|
10406
11965
|
"ffmpeg",
|
|
10407
11966
|
["-loglevel", "error", "-f", "avfoundation", "-i", detectFfmpegMic(), "-ar", String(STT_SAMPLE_RATE), "-ac", "1", "-f", "s16le", "-"],
|
|
10408
11967
|
{ stdio: ["ignore", "pipe", "pipe"] }
|
|
10409
11968
|
);
|
|
10410
|
-
this.proc.stderr.on("data", (d) =>
|
|
11969
|
+
this.proc.stderr.on("data", (d) => log25.warn(`ffmpeg: ${String(d).trim()}`));
|
|
10411
11970
|
}
|
|
10412
11971
|
this.proc.on("exit", (c) => {
|
|
10413
|
-
if (c && !this.stopped)
|
|
11972
|
+
if (c && !this.stopped) log25.error(`mic capture exited (${c}) \u2014 check mic permission / MIC_DEVICE / MIC_AEC=0`);
|
|
10414
11973
|
});
|
|
10415
11974
|
this.proc.stdout.on("data", (chunk) => onChunk(chunk));
|
|
10416
11975
|
}
|
|
@@ -10476,7 +12035,7 @@ var AecDuplexAudio = class {
|
|
|
10476
12035
|
this.proc.stdin.on("error", () => {
|
|
10477
12036
|
});
|
|
10478
12037
|
this.proc.on("exit", (c) => {
|
|
10479
|
-
if (c && !this.stopped)
|
|
12038
|
+
if (c && !this.stopped) log25.error(`aec duplex audio exited (${c}) \u2014 check mic permission / MIC_AEC=0`);
|
|
10480
12039
|
});
|
|
10481
12040
|
this.proc.stdout.on("data", (chunk) => {
|
|
10482
12041
|
this.gotChunk = true;
|
|
@@ -10492,7 +12051,7 @@ var AecDuplexAudio = class {
|
|
|
10492
12051
|
openMicSettings();
|
|
10493
12052
|
this.onFatal?.("microphone permission denied \u2014 enable it in System Settings \u2192 Privacy & Security \u2192 Microphone for your terminal, then restart it");
|
|
10494
12053
|
}
|
|
10495
|
-
} else
|
|
12054
|
+
} else log25.debug(`mic-aec: ${s}`);
|
|
10496
12055
|
}
|
|
10497
12056
|
});
|
|
10498
12057
|
if (!this.noVpio && !this.triedFallback) {
|
|
@@ -10501,7 +12060,7 @@ var AecDuplexAudio = class {
|
|
|
10501
12060
|
this.triedFallback = true;
|
|
10502
12061
|
this.noVpio = true;
|
|
10503
12062
|
this._aec = false;
|
|
10504
|
-
|
|
12063
|
+
log25.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)");
|
|
10505
12064
|
this.onDegrade?.();
|
|
10506
12065
|
this.killProc();
|
|
10507
12066
|
this.spawnHelper();
|
|
@@ -10605,6 +12164,78 @@ var matchVoiceCommand = (text) => {
|
|
|
10605
12164
|
const t = text.toLowerCase().replace(/[^a-z ]/g, " ").replace(/\s+/g, " ").trim().replace(/^(?:hey|ok|okay|please) /, "").replace(/ (?:please|now)$/, "");
|
|
10606
12165
|
return /^(voice off|mute|stop listening)( \1)*$/.test(t) ? "off" : null;
|
|
10607
12166
|
};
|
|
12167
|
+
var replacedVoiceTurn = (last, meta) => meta?.supersedes !== void 0 && last?.text === meta.supersedes ? last : void 0;
|
|
12168
|
+
var CutInAbsorber = class {
|
|
12169
|
+
cut = "";
|
|
12170
|
+
absorbed;
|
|
12171
|
+
interjected(heard) {
|
|
12172
|
+
this.cut = heard;
|
|
12173
|
+
this.absorbed = void 0;
|
|
12174
|
+
}
|
|
12175
|
+
absorbs(text, meta) {
|
|
12176
|
+
const cut = this.cut || (meta?.supersedes !== void 0 && meta.supersedes === this.absorbed?.text ? this.absorbed.cut : "");
|
|
12177
|
+
this.cut = "";
|
|
12178
|
+
this.absorbed = void 0;
|
|
12179
|
+
const words2 = (s) => s.trim().split(/\s+/).filter(Boolean).length;
|
|
12180
|
+
if (!cut || words2(text) - words2(cut) >= 3) return false;
|
|
12181
|
+
this.absorbed = { text, cut };
|
|
12182
|
+
return true;
|
|
12183
|
+
}
|
|
12184
|
+
};
|
|
12185
|
+
function splitCut(cut) {
|
|
12186
|
+
if (!cut) return { reply: null, delivery: "", heard: "" };
|
|
12187
|
+
const queued = cut.queued ?? [];
|
|
12188
|
+
if (!cut.queuedTurn) return { reply: cut.full ? cut : null, delivery: queued.join(" ").trim(), heard: "" };
|
|
12189
|
+
let at = cut.full.length;
|
|
12190
|
+
if (cut.full.length - cut.heard.length > 12) {
|
|
12191
|
+
const sentence = Math.max(...[". ", "! ", "? "].map((b) => cut.heard.lastIndexOf(b)));
|
|
12192
|
+
at = cut.exact ? cut.heard.length : sentence < 0 ? 0 : sentence + 2;
|
|
12193
|
+
}
|
|
12194
|
+
const heard = cut.full.slice(0, at).trim();
|
|
12195
|
+
return { reply: null, delivery: [cut.full.slice(at), ...queued].map((x) => x.trim()).filter(Boolean).join(" "), heard: heard && heard + " " };
|
|
12196
|
+
}
|
|
12197
|
+
function takeCut(v, forVoiceLine) {
|
|
12198
|
+
const cut = v?.takeInterruptedReply() ?? null;
|
|
12199
|
+
return splitCut(forVoiceLine ? cut : null);
|
|
12200
|
+
}
|
|
12201
|
+
function bindOverlapInstinct(v, instinct, live, decideMs = 900) {
|
|
12202
|
+
const o = v.options;
|
|
12203
|
+
const { onDiag } = o;
|
|
12204
|
+
o.overlapDecideMs = decideMs;
|
|
12205
|
+
instinct.options.overlapSettleMs = 0;
|
|
12206
|
+
o.onDiag = (ev) => {
|
|
12207
|
+
onDiag(ev);
|
|
12208
|
+
if (!live()) return;
|
|
12209
|
+
if (ev.kind === "overlap_pause") void instinct.overlap(String(ev.text ?? ""));
|
|
12210
|
+
else if (/^(?:barge_in|overlap_resume|overlap_end|interrupt|tts_turn_begin)$/.test(ev.kind)) instinct.overlapEnded();
|
|
12211
|
+
};
|
|
12212
|
+
Object.assign(instinct.options, {
|
|
12213
|
+
onYield: () => {
|
|
12214
|
+
if (!live()) return false;
|
|
12215
|
+
if (v.decideOverlap("yield")) return;
|
|
12216
|
+
if (!v.audible) return false;
|
|
12217
|
+
v.interrupt();
|
|
12218
|
+
o.onBargeIn("speaking");
|
|
12219
|
+
},
|
|
12220
|
+
// `heard` = what Jev judged: the engine absorbs only those words — a reaction that grows past them is re-decided.
|
|
12221
|
+
onKeepTalking: (heard) => live() ? v.decideOverlap("keep_talking", heard) : false
|
|
12222
|
+
});
|
|
12223
|
+
}
|
|
12224
|
+
function bindAckInstinct(v, instinct) {
|
|
12225
|
+
const o = v.options;
|
|
12226
|
+
const { onDiag } = o;
|
|
12227
|
+
o.pickAck = (c) => instinct.pickAck(c);
|
|
12228
|
+
instinct.options.ackSettleMs = 2 * o.adaptiveAckMs + 200;
|
|
12229
|
+
o.onDiag = (ev) => {
|
|
12230
|
+
try {
|
|
12231
|
+
if (ev.kind === "ack_fired") instinct.ackOutcome(String(ev.phrase));
|
|
12232
|
+
else if (ev.kind === "ack_skipped" || ev.kind === "ack_cancelled") instinct.ackOutcome(null);
|
|
12233
|
+
} catch (e) {
|
|
12234
|
+
log25.warn(`ack outcome tap failed: ${e instanceof Error ? e.message : e}`);
|
|
12235
|
+
}
|
|
12236
|
+
onDiag(ev);
|
|
12237
|
+
};
|
|
12238
|
+
}
|
|
10608
12239
|
var VoiceIOOptions = class extends VoiceEngineOptions {
|
|
10609
12240
|
sonioxApiKey = process.env.SONIOX_API_KEY ?? "";
|
|
10610
12241
|
cartesiaApiKey = process.env.CARTESIA_API_KEY ?? "";
|
|
@@ -10721,7 +12352,7 @@ function fakeVoiceParts(uttFile) {
|
|
|
10721
12352
|
init_logging();
|
|
10722
12353
|
import { appendFile, mkdirSync as mkdirSync6 } from "fs";
|
|
10723
12354
|
import { dirname as dirname4 } from "path";
|
|
10724
|
-
var
|
|
12355
|
+
var log26 = forComponent("VoiceDiag");
|
|
10725
12356
|
var JsonlDiagSink = class {
|
|
10726
12357
|
constructor(path) {
|
|
10727
12358
|
this.path = path;
|
|
@@ -10762,7 +12393,7 @@ var JsonlDiagSink = class {
|
|
|
10762
12393
|
disable(e) {
|
|
10763
12394
|
this.disabled = true;
|
|
10764
12395
|
this.queue.length = 0;
|
|
10765
|
-
|
|
12396
|
+
log26.debug(`voice diag sink disabled (${this.path}): ${e instanceof Error ? e.message : e}`);
|
|
10766
12397
|
}
|
|
10767
12398
|
/** True once a failure permanently disabled the sink (tests/inspection). */
|
|
10768
12399
|
get isDisabled() {
|
|
@@ -10832,7 +12463,7 @@ async function loadConfig(cwd) {
|
|
|
10832
12463
|
|
|
10833
12464
|
// cli/hooks-config.ts
|
|
10834
12465
|
import { spawnSync as spawnSync3 } from "child_process";
|
|
10835
|
-
var
|
|
12466
|
+
var log27 = forComponent("hooks");
|
|
10836
12467
|
var escapeRegex = (s) => s.replace(/[.+^${}()|[\]\\]/g, "\\$&");
|
|
10837
12468
|
function ruleMatches(rule, toolName) {
|
|
10838
12469
|
if (!rule.tool || rule.tool === "*") return true;
|
|
@@ -10849,7 +12480,7 @@ function runCmd(rule, env) {
|
|
|
10849
12480
|
});
|
|
10850
12481
|
return { code: r.status ?? 1, out: ((r.stdout ?? "") + (r.stderr ?? "")).trim() };
|
|
10851
12482
|
} catch (e) {
|
|
10852
|
-
|
|
12483
|
+
log27.debug(`hook command failed: ${rule.command}`, e);
|
|
10853
12484
|
return { code: 1, out: String(e?.message ?? e) };
|
|
10854
12485
|
}
|
|
10855
12486
|
}
|
|
@@ -10953,10 +12584,10 @@ function formatDiff(ops, opts = {}) {
|
|
|
10953
12584
|
}
|
|
10954
12585
|
|
|
10955
12586
|
// cli/session.ts
|
|
10956
|
-
import { existsSync as existsSync6, mkdirSync as mkdirSync7, readFileSync as readFileSync7, writeFileSync as writeFileSync4, readdirSync, renameSync, symlinkSync as symlinkSync2, unlinkSync, readlinkSync } from "fs";
|
|
12587
|
+
import { existsSync as existsSync6, mkdirSync as mkdirSync7, readFileSync as readFileSync7, writeFileSync as writeFileSync4, readdirSync, renameSync, symlinkSync as symlinkSync2, unlinkSync, readlinkSync, statSync as statSync5 } from "fs";
|
|
10957
12588
|
import { homedir as homedir5 } from "os";
|
|
10958
12589
|
import { join as join8 } from "path";
|
|
10959
|
-
var
|
|
12590
|
+
var log28 = forComponent("session");
|
|
10960
12591
|
var globalDir = () => join8(homedir5(), ".agent", "sessions");
|
|
10961
12592
|
var SessionStore = class {
|
|
10962
12593
|
dir;
|
|
@@ -11001,7 +12632,7 @@ var SessionStore = class {
|
|
|
11001
12632
|
}
|
|
11002
12633
|
load(id) {
|
|
11003
12634
|
if (!this.safeId(id)) {
|
|
11004
|
-
|
|
12635
|
+
log28.debug(`rejecting unsafe session id: ${id}`);
|
|
11005
12636
|
return void 0;
|
|
11006
12637
|
}
|
|
11007
12638
|
const path = join8(this.dir, `${id}.json`);
|
|
@@ -11009,7 +12640,7 @@ var SessionStore = class {
|
|
|
11009
12640
|
try {
|
|
11010
12641
|
return JSON.parse(readFileSync7(path, "utf8"));
|
|
11011
12642
|
} catch (e) {
|
|
11012
|
-
|
|
12643
|
+
log28.debug(`unreadable session ${id} \u2014 ignoring`, e);
|
|
11013
12644
|
return void 0;
|
|
11014
12645
|
}
|
|
11015
12646
|
}
|
|
@@ -11022,11 +12653,26 @@ var SessionStore = class {
|
|
|
11022
12653
|
try {
|
|
11023
12654
|
metas.push(JSON.parse(readFileSync7(join8(this.dir, f), "utf8")).meta);
|
|
11024
12655
|
} catch (e) {
|
|
11025
|
-
|
|
12656
|
+
log28.debug(`skipping unreadable session file ${f}`, e);
|
|
11026
12657
|
}
|
|
11027
12658
|
}
|
|
11028
12659
|
return metas.sort((a, b) => b.updated - a.updated);
|
|
11029
12660
|
}
|
|
12661
|
+
/** Cheap listing — ids from filenames + mtime/size from stat, NO parsing (list() parses every file: 870
|
|
12662
|
+
* sessions / 157MB took ~150ms+ synchronously). Most-recently-written first. */
|
|
12663
|
+
files() {
|
|
12664
|
+
if (!existsSync6(this.dir)) return [];
|
|
12665
|
+
const out = [];
|
|
12666
|
+
for (const f of readdirSync(this.dir)) {
|
|
12667
|
+
if (!f.endsWith(".json")) continue;
|
|
12668
|
+
try {
|
|
12669
|
+
const st = statSync5(join8(this.dir, f));
|
|
12670
|
+
out.push({ id: f.slice(0, -5), mtime: st.mtimeMs, size: st.size });
|
|
12671
|
+
} catch {
|
|
12672
|
+
}
|
|
12673
|
+
}
|
|
12674
|
+
return out.sort((a, b) => b.mtime - a.mtime);
|
|
12675
|
+
}
|
|
11030
12676
|
latest() {
|
|
11031
12677
|
return this.list()[0];
|
|
11032
12678
|
}
|
|
@@ -11087,6 +12733,61 @@ function titleOf(messages) {
|
|
|
11087
12733
|
const t = contentText(u?.content).replace(/\s+/g, " ").trim();
|
|
11088
12734
|
return t.length > 60 ? t.slice(0, 57) + "\u2026" : t || "(empty)";
|
|
11089
12735
|
}
|
|
12736
|
+
function recapLine(m) {
|
|
12737
|
+
if (m.role !== "user" && m.role !== "assistant") return "";
|
|
12738
|
+
let t = contentText(m.content);
|
|
12739
|
+
if (m.role === "user" && /^\[(?:session started|reminder)\]/.test(t)) return "";
|
|
12740
|
+
const spoken = [...t.matchAll(/<spoken>([\s\S]*?)<\/spoken>/g)].map((x) => x[1]).join(" ");
|
|
12741
|
+
if (spoken) t = spoken;
|
|
12742
|
+
t = t.replace(/\s*\[the user interrupted you[\s\S]*$/, "").replace(/\[[a-z_ ]+\]\s*/gi, "").replace(/\s+/g, " ").trim();
|
|
12743
|
+
return t ? `${m.role}: ${t}` : "";
|
|
12744
|
+
}
|
|
12745
|
+
function sessionRecap(store, currentId, which, cap = 2500, maxParseBytes = 4e6) {
|
|
12746
|
+
const others = store.files().filter((f) => f.id !== currentId);
|
|
12747
|
+
if (!others.length) return "No earlier sessions in this project.";
|
|
12748
|
+
const created = (id) => {
|
|
12749
|
+
const m = id.match(/^(\d{4})(\d{2})(\d{2})-(\d{2})(\d{2})(\d{2})/);
|
|
12750
|
+
return m ? new Date(+m[1], +m[2] - 1, +m[3], +m[4], +m[5], +m[6]).getTime() : NaN;
|
|
12751
|
+
};
|
|
12752
|
+
const when = (ts) => {
|
|
12753
|
+
if (!Number.isFinite(ts)) return "unknown time";
|
|
12754
|
+
const d = new Date(ts), today = (/* @__PURE__ */ new Date()).toDateString() === d.toDateString();
|
|
12755
|
+
return `${today ? "today" : d.toLocaleDateString("en-US", { month: "short", day: "numeric" })} ${d.toLocaleTimeString("en-US", { hour: "numeric", minute: "2-digit" })}`;
|
|
12756
|
+
};
|
|
12757
|
+
const load = (f) => f.size <= maxParseBytes ? store.load(f.id) : void 0;
|
|
12758
|
+
const w = which?.trim();
|
|
12759
|
+
if (!w) {
|
|
12760
|
+
const rows = others.slice(0, 5).map((f) => {
|
|
12761
|
+
const data2 = load(f);
|
|
12762
|
+
const asks = (data2?.messages ?? []).filter((m) => m.role === "user").map(recapLine).filter(Boolean).slice(0, 3).map((l) => `"${l.slice(6, 86)}"`);
|
|
12763
|
+
return `- ${f.id} (${when(created(f.id))}${data2 ? `, ${data2.meta.turns} turns` : ""})${asks.length ? `: ${asks.join("; ")}` : ""}`;
|
|
12764
|
+
});
|
|
12765
|
+
return `Earlier sessions (newest first) \u2014 to read one, call QuickLook with what:"sessions" and path:"<id>":
|
|
12766
|
+
${rows.join("\n")}`;
|
|
12767
|
+
}
|
|
12768
|
+
const recent = others.slice(0, 5).map((f) => f.id).join(", ");
|
|
12769
|
+
let hit;
|
|
12770
|
+
if (/^(latest|last|previous|prev)$/i.test(w)) {
|
|
12771
|
+
const cur = created(currentId);
|
|
12772
|
+
hit = others.filter((f) => created(f.id) < cur).sort((a, b) => created(b.id) - created(a.id))[0] ?? others[0];
|
|
12773
|
+
} else {
|
|
12774
|
+
hit = others.find((f) => f.id === w);
|
|
12775
|
+
if (!hit) {
|
|
12776
|
+
const pre = others.filter((f) => f.id.startsWith(w));
|
|
12777
|
+
if (pre.length > 1) return `'${w}' matches ${pre.length} sessions \u2014 use the full id: ${pre.slice(0, 5).map((f) => f.id).join(", ")}`;
|
|
12778
|
+
hit = pre[0];
|
|
12779
|
+
}
|
|
12780
|
+
}
|
|
12781
|
+
if (!hit) return `No session '${w}'. Recent: ${recent}`;
|
|
12782
|
+
const data = load(hit);
|
|
12783
|
+
if (!data) return `Session ${hit.id} is too large (or unreadable) to recap here \u2014 ask a worker (Act) to read it.`;
|
|
12784
|
+
let body = data.messages.map(recapLine).filter(Boolean).map((l) => l.length > 600 ? `${l.slice(0, 600)}\u2026` : l).join("\n");
|
|
12785
|
+
if (body.length > cap) body = `\u2026(earlier lines omitted)
|
|
12786
|
+
${body.slice(-cap)}`;
|
|
12787
|
+
return `Session ${data.meta.id} (${when(data.meta.created)}):
|
|
12788
|
+
${body || "(no conversation)"}
|
|
12789
|
+
(That is everything recorded. Where it does not say why something was done or what was meant, say you do not know \u2014 never supply a reason.)`;
|
|
12790
|
+
}
|
|
11090
12791
|
|
|
11091
12792
|
// cli/checkpoints.ts
|
|
11092
12793
|
var MUTATORS = /* @__PURE__ */ new Set(["Write", "Edit", "MultiEdit", "ApplyEdits"]);
|
|
@@ -11191,7 +12892,7 @@ import { promisify } from "util";
|
|
|
11191
12892
|
import { writeFileSync as writeFileSync5, mkdirSync as mkdirSync8 } from "fs";
|
|
11192
12893
|
import { homedir as homedir6 } from "os";
|
|
11193
12894
|
import { join as join9, resolve as resolve3, sep as sep3, parse as parsePath } from "path";
|
|
11194
|
-
var
|
|
12895
|
+
var log29 = forComponent("checkpoints");
|
|
11195
12896
|
var exec = promisify(execFile3);
|
|
11196
12897
|
var DEFAULT_EXCLUDE = [".agent/", ".git/", "node_modules/", "dist/", "build/", ".next/", "target/", ".venv/", "__pycache__/", "*.log"];
|
|
11197
12898
|
function isBroadRoot(p) {
|
|
@@ -11237,7 +12938,7 @@ var ShadowRepo = class {
|
|
|
11237
12938
|
writeFileSync5(join9(this.gitDir, "info", "exclude"), this.exclude.join("\n") + "\n");
|
|
11238
12939
|
this.ready = true;
|
|
11239
12940
|
} catch (e) {
|
|
11240
|
-
|
|
12941
|
+
log29.debug(`git checkpoints unavailable for ${this.workTree}`, e);
|
|
11241
12942
|
this.ready = false;
|
|
11242
12943
|
}
|
|
11243
12944
|
return this.ready;
|
|
@@ -11248,7 +12949,7 @@ var ShadowRepo = class {
|
|
|
11248
12949
|
}
|
|
11249
12950
|
async commit(label, forced = []) {
|
|
11250
12951
|
await this.run("add", "-A");
|
|
11251
|
-
for (const p of forced) await this.run("add", "-f", "--", p).catch((e) =>
|
|
12952
|
+
for (const p of forced) await this.run("add", "-f", "--", p).catch((e) => log29.debug(`force-add failed: ${p}`, e));
|
|
11252
12953
|
await this.run("commit", "--allow-empty", "-q", "-m", label);
|
|
11253
12954
|
}
|
|
11254
12955
|
/** Inject the CURRENT (pre-edit) content of `paths` into the turn-open restore point by amending it.
|
|
@@ -11256,8 +12957,8 @@ var ShadowRepo = class {
|
|
|
11256
12957
|
* turn-boundary `add -A` would never have captured it. Amend (vs a new commit) keeps one restore
|
|
11257
12958
|
* point per turn, so the REPL's turn↔frame mapping stays intact. */
|
|
11258
12959
|
async amendForced(paths) {
|
|
11259
|
-
for (const p of paths) await this.run("add", "-f", "--", p).catch((e) =>
|
|
11260
|
-
await this.run("commit", "--amend", "--no-edit", "-q", "--allow-empty").catch((e) =>
|
|
12960
|
+
for (const p of paths) await this.run("add", "-f", "--", p).catch((e) => log29.debug(`force-capture failed: ${p}`, e));
|
|
12961
|
+
await this.run("commit", "--amend", "--no-edit", "-q", "--allow-empty").catch((e) => log29.debug("amend failed", e));
|
|
11261
12962
|
}
|
|
11262
12963
|
/** Commits on `ref`, oldest-first (canonical index space). */
|
|
11263
12964
|
async log(ref) {
|
|
@@ -11317,7 +13018,7 @@ var ShadowRepo = class {
|
|
|
11317
13018
|
await this.run("gc", "--auto", "-q").catch(() => {
|
|
11318
13019
|
});
|
|
11319
13020
|
} catch (e) {
|
|
11320
|
-
|
|
13021
|
+
log29.debug("checkpoint prune failed", e);
|
|
11321
13022
|
}
|
|
11322
13023
|
}
|
|
11323
13024
|
};
|
|
@@ -11385,7 +13086,7 @@ var GitCheckpoints = class {
|
|
|
11385
13086
|
use(sessionId) {
|
|
11386
13087
|
if (sessionId === this.session) return;
|
|
11387
13088
|
this.session = sessionId;
|
|
11388
|
-
if (this.started) for (const r of this.repos) void r.point(this.ref()).catch((e) =>
|
|
13089
|
+
if (this.started) for (const r of this.repos) void r.point(this.ref()).catch((e) => log29.debug("re-point failed", e));
|
|
11389
13090
|
}
|
|
11390
13091
|
async begin(label) {
|
|
11391
13092
|
if (!await this.start()) return;
|
|
@@ -11405,7 +13106,7 @@ var GitCheckpoints = class {
|
|
|
11405
13106
|
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
|
|
11406
13107
|
`);
|
|
11407
13108
|
} else {
|
|
11408
|
-
|
|
13109
|
+
log29.debug("checkpoint commit failed", e);
|
|
11409
13110
|
survivors.push(this.repos[i]);
|
|
11410
13111
|
survivorCaches.push(this.caches[i] ?? []);
|
|
11411
13112
|
}
|
|
@@ -11440,7 +13141,7 @@ var GitCheckpoints = class {
|
|
|
11440
13141
|
if (this.forced.has(abs)) continue;
|
|
11441
13142
|
this.forced.add(abs);
|
|
11442
13143
|
const i = this.repoIndexFor(abs);
|
|
11443
|
-
if (i >= 0) await this.repos[i].amendForced([abs]).catch((e) =>
|
|
13144
|
+
if (i >= 0) await this.repos[i].amendForced([abs]).catch((e) => log29.debug("amendForced failed", e));
|
|
11444
13145
|
}
|
|
11445
13146
|
}
|
|
11446
13147
|
};
|
|
@@ -12519,8 +14220,8 @@ var REWIND = "\0REWIND";
|
|
|
12519
14220
|
var PASTE_PREVIEW_MAX = 40;
|
|
12520
14221
|
function pastePreview(text) {
|
|
12521
14222
|
const line = text.split("\n").find((l) => l.trim()) ?? "";
|
|
12522
|
-
const
|
|
12523
|
-
return
|
|
14223
|
+
const clean3 = line.replace(/[[\]]/g, "").replace(/\s+/g, " ").trim();
|
|
14224
|
+
return clean3.length > PASTE_PREVIEW_MAX ? clean3.slice(0, PASTE_PREVIEW_MAX) + "\u2026" : clean3;
|
|
12524
14225
|
}
|
|
12525
14226
|
function applyVimNormal(s, key, str) {
|
|
12526
14227
|
const k = key?.name;
|
|
@@ -13293,7 +14994,7 @@ import { spawnSync as spawnSync5 } from "child_process";
|
|
|
13293
14994
|
import { writeFileSync as writeFileSync8, mkdirSync as mkdirSync10, readdirSync as readdirSync2, unlinkSync as unlinkSync3, chmodSync, existsSync as existsSync7 } from "fs";
|
|
13294
14995
|
import { homedir as homedir8 } from "os";
|
|
13295
14996
|
import { join as join12 } from "path";
|
|
13296
|
-
var
|
|
14997
|
+
var log30 = forComponent("os-sched");
|
|
13297
14998
|
var OsScheduler = class {
|
|
13298
14999
|
options;
|
|
13299
15000
|
constructor(options) {
|
|
@@ -13355,7 +15056,7 @@ var OsScheduler = class {
|
|
|
13355
15056
|
}
|
|
13356
15057
|
}
|
|
13357
15058
|
} catch (e) {
|
|
13358
|
-
|
|
15059
|
+
log30.debug(`cancel ${id}`, e);
|
|
13359
15060
|
}
|
|
13360
15061
|
for (const f of [`${id}.json`, `${id}.sh`]) {
|
|
13361
15062
|
try {
|
|
@@ -13472,7 +15173,7 @@ import { spawn as spawn3 } from "child_process";
|
|
|
13472
15173
|
import { existsSync as existsSync8, mkdirSync as mkdirSync11, unlinkSync as unlinkSync4, readdirSync as readdirSync3 } from "fs";
|
|
13473
15174
|
import { homedir as homedir9 } from "os";
|
|
13474
15175
|
import { join as join13 } from "path";
|
|
13475
|
-
var
|
|
15176
|
+
var log31 = forComponent("remote-trigger");
|
|
13476
15177
|
var TRIGGER_DIR = () => join13(homedir9(), ".agent", "triggers");
|
|
13477
15178
|
var sockPath = (sessionId, dir = TRIGGER_DIR()) => join13(dir, `${sessionId}.sock`);
|
|
13478
15179
|
var TriggerServer = class {
|
|
@@ -13510,13 +15211,13 @@ var TriggerServer = class {
|
|
|
13510
15211
|
conn.end(JSON.stringify({ ok: false, error: String(e) }) + "\n");
|
|
13511
15212
|
}
|
|
13512
15213
|
});
|
|
13513
|
-
conn.on("error", (e) =>
|
|
15214
|
+
conn.on("error", (e) => log31.debug("trigger conn error", e));
|
|
13514
15215
|
});
|
|
13515
|
-
this.server.on("error", (e) =>
|
|
15216
|
+
this.server.on("error", (e) => log31.debug("trigger server error", e));
|
|
13516
15217
|
this.server.listen(p);
|
|
13517
15218
|
this.path = p;
|
|
13518
15219
|
} catch (e) {
|
|
13519
|
-
|
|
15220
|
+
log31.debug("trigger server unavailable", e);
|
|
13520
15221
|
}
|
|
13521
15222
|
}
|
|
13522
15223
|
/** Re-bind on /resume (the session id changed). */
|
|
@@ -13638,7 +15339,7 @@ var strike = C("9");
|
|
|
13638
15339
|
var link = (text, url) => useColor ? `\x1B]8;;${url}\x1B\\${cyan(text)}\x1B]8;;\x1B\\` : `${text} (${url})`;
|
|
13639
15340
|
var mdPalette = { bold, dim, cyan, italic, strike, green, link };
|
|
13640
15341
|
var err = (s) => process.stderr.write(s);
|
|
13641
|
-
var
|
|
15342
|
+
var log32 = forComponent("cli");
|
|
13642
15343
|
var VERSION = (() => {
|
|
13643
15344
|
try {
|
|
13644
15345
|
return JSON.parse(readFileSync9(new URL("../package.json", import.meta.url), "utf8")).version ?? "?";
|
|
@@ -14394,7 +16095,7 @@ function costOf(pricing, promptTokens = 0, completionTokens = 0, cacheCreationTo
|
|
|
14394
16095
|
function turnCost(model, usage) {
|
|
14395
16096
|
return costOf(getModelInfo(model)?.pricing, usage?.promptTokens ?? 0, usage?.completionTokens ?? 0, usage?.cacheCreationTokens ?? 0, usage?.cacheReadTokens ?? 0, model);
|
|
14396
16097
|
}
|
|
14397
|
-
async function evaluateGoal(ai, condition, transcript,
|
|
16098
|
+
async function evaluateGoal(ai, condition, transcript, log33) {
|
|
14398
16099
|
const recent = transcript.filter((m) => m.role === "assistant").slice(-8).map((m) => {
|
|
14399
16100
|
const text = typeof m.content === "string" ? m.content : m.content.filter((p) => p.type === "text").map((p) => p.text).join(" ");
|
|
14400
16101
|
return text.slice(0, 600);
|
|
@@ -14414,7 +16115,7 @@ ${recent}` }
|
|
|
14414
16115
|
const match = r.content.match(/\{[\s\S]*\}/);
|
|
14415
16116
|
if (match) return JSON.parse(match[0]);
|
|
14416
16117
|
} catch (e) {
|
|
14417
|
-
|
|
16118
|
+
log33(dim(` (goal evaluator error: ${e?.message ?? e})
|
|
14418
16119
|
`));
|
|
14419
16120
|
}
|
|
14420
16121
|
return { met: false, reason: "evaluation unclear" };
|
|
@@ -14635,7 +16336,7 @@ function mcpAgentTools(mounted, opts) {
|
|
|
14635
16336
|
return tools;
|
|
14636
16337
|
}
|
|
14637
16338
|
async function closeMcp(mounted) {
|
|
14638
|
-
await Promise.all(mounted.map((m) => m.client.close().catch((e) =>
|
|
16339
|
+
await Promise.all(mounted.map((m) => m.client.close().catch((e) => log32.debug("mcp close failed", e))));
|
|
14639
16340
|
}
|
|
14640
16341
|
var IMG_EXT = { ".png": "image/png", ".jpg": "image/jpeg", ".jpeg": "image/jpeg", ".gif": "image/gif", ".webp": "image/webp" };
|
|
14641
16342
|
function mentionRefs(line) {
|
|
@@ -14650,7 +16351,7 @@ function readImageParts(cwd, line) {
|
|
|
14650
16351
|
if (!mime) continue;
|
|
14651
16352
|
const abs = ref.startsWith("~/") ? untilde(ref) : resolve4(cwd, ref);
|
|
14652
16353
|
try {
|
|
14653
|
-
|
|
16354
|
+
statSync6(abs);
|
|
14654
16355
|
} catch {
|
|
14655
16356
|
continue;
|
|
14656
16357
|
}
|
|
@@ -14666,7 +16367,7 @@ function pastePathClassifier(cwd) {
|
|
|
14666
16367
|
if (!/^(\/|~\/|\.\/|\.\.\/)/.test(t)) return null;
|
|
14667
16368
|
const abs = t.startsWith("~/") ? untilde(t) : resolve4(cwd, t);
|
|
14668
16369
|
try {
|
|
14669
|
-
if (!
|
|
16370
|
+
if (!statSync6(abs).isFile()) return null;
|
|
14670
16371
|
} catch {
|
|
14671
16372
|
return null;
|
|
14672
16373
|
}
|
|
@@ -14687,7 +16388,7 @@ async function expandMentions(fs, line) {
|
|
|
14687
16388
|
if (loaded.includes(ref) || missing.includes(ref)) continue;
|
|
14688
16389
|
if (ref.includes(":") && mcpMentionResolver) {
|
|
14689
16390
|
const body = await mcpMentionResolver(ref).catch((e) => {
|
|
14690
|
-
|
|
16391
|
+
log32.debug("mcp mention resolve failed", e);
|
|
14691
16392
|
return null;
|
|
14692
16393
|
});
|
|
14693
16394
|
if (body != null) {
|
|
@@ -14774,7 +16475,7 @@ async function runTurn(agent, store, session, task, cp, cwd = process.cwd(), sen
|
|
|
14774
16475
|
try {
|
|
14775
16476
|
store.save(session);
|
|
14776
16477
|
} catch (ex) {
|
|
14777
|
-
|
|
16478
|
+
log32.debug("mid-turn session flush failed", ex);
|
|
14778
16479
|
}
|
|
14779
16480
|
}
|
|
14780
16481
|
return origNotify(e);
|
|
@@ -14795,8 +16496,8 @@ async function runTurn(agent, store, session, task, cp, cwd = process.cwd(), sen
|
|
|
14795
16496
|
} finally {
|
|
14796
16497
|
spinner.stop();
|
|
14797
16498
|
spinner.turnStart = 0;
|
|
14798
|
-
activeTurn = null;
|
|
14799
|
-
agent.options.signal = void 0;
|
|
16499
|
+
if (activeTurn === ctrl) activeTurn = null;
|
|
16500
|
+
if (agent.options.signal === ctrl.signal) agent.options.signal = void 0;
|
|
14800
16501
|
if (host && origNotify) host.notify = origNotify;
|
|
14801
16502
|
}
|
|
14802
16503
|
agent.options.host?.flushText?.();
|
|
@@ -14923,14 +16624,14 @@ var isCancelTeardown = (e) => {
|
|
|
14923
16624
|
function installCancelGuards(mounted) {
|
|
14924
16625
|
process.on("unhandledRejection", (e) => {
|
|
14925
16626
|
if (isCancelTeardown(e)) {
|
|
14926
|
-
|
|
16627
|
+
log32.debug("suppressed unhandledRejection (cursor stream cancel)", e);
|
|
14927
16628
|
return;
|
|
14928
16629
|
}
|
|
14929
|
-
|
|
16630
|
+
log32.error("unhandledRejection", e);
|
|
14930
16631
|
});
|
|
14931
16632
|
process.on("uncaughtException", (e) => {
|
|
14932
16633
|
if (isCancelTeardown(e)) {
|
|
14933
|
-
|
|
16634
|
+
log32.debug("suppressed uncaughtException (cursor stream cancel)", e);
|
|
14934
16635
|
return;
|
|
14935
16636
|
}
|
|
14936
16637
|
console.error(e);
|
|
@@ -14990,6 +16691,18 @@ async function repl(args, ai, cfg, cwd) {
|
|
|
14990
16691
|
let dx;
|
|
14991
16692
|
let voiceIO;
|
|
14992
16693
|
let voiceDiag;
|
|
16694
|
+
const decider = duplex && process.env.TYPESAFE_AI_KEY ? new DecideClient({ apiKey: process.env.TYPESAFE_AI_KEY }) : void 0;
|
|
16695
|
+
const instinct = decider && process.env.VOICE_INSTINCT === "1" ? new Instinct({
|
|
16696
|
+
decider,
|
|
16697
|
+
context: () => ({ agentSaid: dx?.recentExcerpt(1).replace(/^\w+: /, ""), recent: dx?.recentExcerpt(4) }),
|
|
16698
|
+
onDecision: ({ kind, ...d }) => {
|
|
16699
|
+
voiceDiag?.push({ t: performance.now(), kind: `instinct_${kind}`, ...d });
|
|
16700
|
+
const probs = Object.entries(d.probabilities).sort((a, b) => b[1] - a[1]).map(([k, p]) => `${k} ${Math.round(p * 100)}%`).join(" \xB7 ");
|
|
16701
|
+
const act = d.acted && !/stale|skipped/.test(d.acted) ? yellow(`\u26A1 ${d.acted}`) : dim(d.acted ?? "no-op");
|
|
16702
|
+
err("\r\x1B[0J" + dim(` \u{1F9E0} jev ${kind.padEnd(12)} ${probs} ${d.ms}ms "${d.heard.slice(-40)}" `) + act + "\n");
|
|
16703
|
+
editorRef?.redrawNow();
|
|
16704
|
+
}
|
|
16705
|
+
}) : void 0;
|
|
14993
16706
|
let voiceLineOpen = false;
|
|
14994
16707
|
const emotionsOn = process.env.VOICE_EMOTIONS !== "0";
|
|
14995
16708
|
let showEmotions = process.env.VOICE_SHOW_EMOTIONS === "1";
|
|
@@ -15180,6 +16893,8 @@ async function repl(args, ai, cfg, cwd) {
|
|
|
15180
16893
|
};
|
|
15181
16894
|
dx = new DuplexAgent({
|
|
15182
16895
|
ai,
|
|
16896
|
+
...instinct ? { bargeIntent: (t) => instinct.bargeIntent(t) } : {},
|
|
16897
|
+
decider,
|
|
15183
16898
|
fs: agent.options.fs,
|
|
15184
16899
|
memoryDir: agent.options.memoryDir,
|
|
15185
16900
|
memoryUserDir: agent.options.memoryUserDir,
|
|
@@ -15189,7 +16904,7 @@ async function repl(args, ai, cfg, cwd) {
|
|
|
15189
16904
|
providerOptionsFor: (m) => providerOptionsFor(m, cwd, cfg.mcpServers, mounted.map((x) => x.name)),
|
|
15190
16905
|
...(args.thinkModel ?? cfg.thinkModel) !== void 0 ? { thinkModel: (args.thinkModel ?? cfg.thinkModel) === false ? false : resolveModelOrNewest(String(args.thinkModel ?? cfg.thinkModel)) } : {},
|
|
15191
16906
|
host,
|
|
15192
|
-
...args.voice ? { voiceStyle: "conversational", progressUpdates: true, askRelay: true, emotionTags: emotionsOn } : {},
|
|
16907
|
+
...args.voice ? { voiceStyle: "conversational", progressUpdates: true, askRelay: true, emotionTags: emotionsOn, spokenBudgetChars: 350 } : {},
|
|
15193
16908
|
// voice: progress asides + worker questions relayed through the conversation; emotion tags taught only with a TTS that speaks them
|
|
15194
16909
|
// Per-TASK checkpoint frames (the natural undo unit in duplex = one delegation): opened BEFORE
|
|
15195
16910
|
// the worker spawns (post-spawn would race its first edits). `checkpoints` is bound below.
|
|
@@ -15219,7 +16934,9 @@ async function repl(args, ai, cfg, cwd) {
|
|
|
15219
16934
|
}
|
|
15220
16935
|
}
|
|
15221
16936
|
return parts.length ? parts.join("\n").slice(0, 2e3) : "(no memory yet)";
|
|
15222
|
-
}
|
|
16937
|
+
},
|
|
16938
|
+
// Cross-session recall: earlier conversations in this project (path = a session id / "previous").
|
|
16939
|
+
sessions: (which) => sessionRecap(store, session.meta.id, which)
|
|
15223
16940
|
},
|
|
15224
16941
|
// The voice runs on the REAL fs (it has no fs tools — harmless) so @mentions, !cmd and #note
|
|
15225
16942
|
// resolve against the project; + CC-parity chrome for its own tool calls (⚙ Act …).
|
|
@@ -15230,7 +16947,7 @@ async function repl(args, ai, cfg, cwd) {
|
|
|
15230
16947
|
}
|
|
15231
16948
|
const face = dx ? dx.voice : agent;
|
|
15232
16949
|
const work = workerOptions ?? agent.options;
|
|
15233
|
-
const sendVia = dx ? (c) => dx.send(c) : void 0;
|
|
16950
|
+
const sendVia = dx ? (c, o) => dx.send(c, o) : void 0;
|
|
15234
16951
|
const baseRules = () => [
|
|
15235
16952
|
...parsePermRules({ deny: args.disallowedTools }),
|
|
15236
16953
|
...parsePermRules({ allow: args.allowedTools }),
|
|
@@ -15335,7 +17052,7 @@ async function repl(args, ai, cfg, cwd) {
|
|
|
15335
17052
|
try {
|
|
15336
17053
|
mkdirSync12(dir, { recursive: true });
|
|
15337
17054
|
} catch (e) {
|
|
15338
|
-
|
|
17055
|
+
log32.debug("paste image dir create failed", e);
|
|
15339
17056
|
}
|
|
15340
17057
|
const img = grabClipboardImage(dir, String(Date.now()));
|
|
15341
17058
|
return img ? { display: "Image", ref: "@" + img.path, path: img.path } : null;
|
|
@@ -15448,7 +17165,7 @@ Added entries are loadable now via the Skill/SlashCommand tools; removed ones ar
|
|
|
15448
17165
|
mkdirSync12(join14(cwd, ".agent"), { recursive: true });
|
|
15449
17166
|
appendFileSync(histPath, line + "\n");
|
|
15450
17167
|
} catch (e) {
|
|
15451
|
-
|
|
17168
|
+
log32.debug("history write failed", e);
|
|
15452
17169
|
}
|
|
15453
17170
|
};
|
|
15454
17171
|
const ago = (t) => {
|
|
@@ -15520,7 +17237,7 @@ Added entries are loadable now via the Skill/SlashCommand tools; removed ones ar
|
|
|
15520
17237
|
try {
|
|
15521
17238
|
store.save(session);
|
|
15522
17239
|
} catch (e) {
|
|
15523
|
-
|
|
17240
|
+
log32.debug("session save after rewind failed", e);
|
|
15524
17241
|
}
|
|
15525
17242
|
err(green(" \u27F2 jumped back") + dim(` \u2014 ${face.transcript.length} message(s) kept; edit + resend
|
|
15526
17243
|
`));
|
|
@@ -15546,7 +17263,8 @@ Added entries are loadable now via the Skill/SlashCommand tools; removed ones ar
|
|
|
15546
17263
|
else err(red(" no such session\n"));
|
|
15547
17264
|
};
|
|
15548
17265
|
const announcedTasks = /* @__PURE__ */ new Set();
|
|
15549
|
-
const
|
|
17266
|
+
const replacedVoiceTurns = /* @__PURE__ */ new Set();
|
|
17267
|
+
const turn = async (task, opts) => {
|
|
15550
17268
|
if (bangContext.length) {
|
|
15551
17269
|
task = `${bangContext.join("\n\n")}
|
|
15552
17270
|
|
|
@@ -15554,20 +17272,20 @@ ${task}`;
|
|
|
15554
17272
|
bangContext.length = 0;
|
|
15555
17273
|
}
|
|
15556
17274
|
const delta = await refreshCatalogs().catch((e) => {
|
|
15557
|
-
|
|
17275
|
+
log32.debug("catalog refresh failed", e);
|
|
15558
17276
|
return "";
|
|
15559
17277
|
});
|
|
15560
17278
|
if (delta) {
|
|
15561
17279
|
err(dim(" \u27F3 skill/command catalog changed \u2014 delta attached to this turn\n"));
|
|
15562
17280
|
task += "\n\n" + delta;
|
|
15563
17281
|
}
|
|
15564
|
-
const r = await runTurn(face, store, session, task, duplex ? void 0 : checkpoints, cwd, sendVia);
|
|
17282
|
+
const r = await runTurn(face, store, session, task, duplex ? void 0 : checkpoints, cwd, sendVia && ((c) => sendVia(c, opts)));
|
|
15565
17283
|
if (voiceIO) {
|
|
15566
17284
|
voiceReasonEnd();
|
|
15567
17285
|
voiceEchoEnd();
|
|
15568
17286
|
editorRef?.resume();
|
|
15569
17287
|
}
|
|
15570
|
-
voiceIO?.endSpeech();
|
|
17288
|
+
if (!(opts?.id && replacedVoiceTurns.delete(opts.id))) voiceIO?.endSpeech();
|
|
15571
17289
|
if (dx) {
|
|
15572
17290
|
const fresh = [...dx.tasks.values()].filter((t) => t.status === "running" && !announcedTasks.has(t.id));
|
|
15573
17291
|
fresh.forEach((t) => announcedTasks.add(t.id));
|
|
@@ -15818,7 +17536,7 @@ ${task}`;
|
|
|
15818
17536
|
desc: "rescan skills/commands dirs and rebuild the system prompt (one cache miss) \u2014 picks up entries created mid-session",
|
|
15819
17537
|
run: async () => {
|
|
15820
17538
|
await refreshCatalogs().catch((e) => {
|
|
15821
|
-
|
|
17539
|
+
log32.debug("catalog refresh failed", e);
|
|
15822
17540
|
});
|
|
15823
17541
|
face.reprepare();
|
|
15824
17542
|
err(green(` \u2713 reloaded \u2014 ${skills.length} skill(s), ${cmds.length} command(s); system prompt rebuilds on next message
|
|
@@ -16320,7 +18038,7 @@ ${task}`;
|
|
|
16320
18038
|
try {
|
|
16321
18039
|
for (const def of (await loadAgents(fs2, d)).agents) if (!seen.has(def.name)) seen.set(def.name, { def, from: d });
|
|
16322
18040
|
} catch (e) {
|
|
16323
|
-
|
|
18041
|
+
log32.debug(`loadAgents(${d}) failed`, e);
|
|
16324
18042
|
}
|
|
16325
18043
|
}
|
|
16326
18044
|
if (!seen.size) {
|
|
@@ -16408,7 +18126,7 @@ ${task}`;
|
|
|
16408
18126
|
}
|
|
16409
18127
|
if (idx >= 0) {
|
|
16410
18128
|
const old = mounted.splice(idx, 1)[0];
|
|
16411
|
-
await old.client.close().catch((e) =>
|
|
18129
|
+
await old.client.close().catch((e) => log32.debug("mcp close failed", e));
|
|
16412
18130
|
}
|
|
16413
18131
|
try {
|
|
16414
18132
|
const m = await mountMcpServer(name, conf);
|
|
@@ -16436,7 +18154,7 @@ ${task}`;
|
|
|
16436
18154
|
}
|
|
16437
18155
|
const m = mounted.splice(idx, 1)[0];
|
|
16438
18156
|
remountMcpTools();
|
|
16439
|
-
await m.client.close().catch((e) =>
|
|
18157
|
+
await m.client.close().catch((e) => log32.debug("mcp close failed", e));
|
|
16440
18158
|
err(dim(` removed "${name}"
|
|
16441
18159
|
`));
|
|
16442
18160
|
return;
|
|
@@ -16639,7 +18357,7 @@ ${task}`;
|
|
|
16639
18357
|
try {
|
|
16640
18358
|
return readdirSync4(join14(cwd, absDir.replace(/^\/+/, "")), { withFileTypes: true }).map((d) => ({ name: d.name, dir: d.isDirectory() }));
|
|
16641
18359
|
} catch (e) {
|
|
16642
|
-
|
|
18360
|
+
log32.debug("completion readdir failed", absDir, e);
|
|
16643
18361
|
return null;
|
|
16644
18362
|
}
|
|
16645
18363
|
};
|
|
@@ -16738,7 +18456,8 @@ ${task}`;
|
|
|
16738
18456
|
};
|
|
16739
18457
|
let prefill;
|
|
16740
18458
|
let tick = 0;
|
|
16741
|
-
const dispatchLine = async (line) => {
|
|
18459
|
+
const dispatchLine = async (line, opts) => {
|
|
18460
|
+
if (!opts?.id) takeCut(voiceIO, false);
|
|
16742
18461
|
if (/^[!#/]/.test(line)) dispatchPending = false;
|
|
16743
18462
|
history.unshift(line.replace(/\n+/g, " \u23CE "));
|
|
16744
18463
|
remember(line.replace(/\n+/g, " \u23CE "));
|
|
@@ -16775,7 +18494,7 @@ ${out}
|
|
|
16775
18494
|
return;
|
|
16776
18495
|
}
|
|
16777
18496
|
await refreshCatalogs().catch((e) => {
|
|
16778
|
-
|
|
18497
|
+
log32.debug("catalog refresh failed", e);
|
|
16779
18498
|
});
|
|
16780
18499
|
const sk = skills.find((x) => x.name === name);
|
|
16781
18500
|
if (sk) {
|
|
@@ -16795,7 +18514,7 @@ ${out}
|
|
|
16795
18514
|
}
|
|
16796
18515
|
const task = pendingImages.length ? `${line} ${pendingImages.map((p) => "@" + p).join(" ")}` : line;
|
|
16797
18516
|
pendingImages.length = 0;
|
|
16798
|
-
await turn(task);
|
|
18517
|
+
await turn(task, opts);
|
|
16799
18518
|
if (goalCondition && !aborting && !exitRequested) {
|
|
16800
18519
|
goalTurns++;
|
|
16801
18520
|
persistGoal();
|
|
@@ -16804,6 +18523,11 @@ ${out}
|
|
|
16804
18523
|
if (exitRequested) return "quit";
|
|
16805
18524
|
};
|
|
16806
18525
|
let voicePartial = "";
|
|
18526
|
+
let interjectNote = "";
|
|
18527
|
+
const ackedNote = (said) => said ? `
|
|
18528
|
+
[you already said "${said}" out loud to open this reply \u2014 do not acknowledge again; go straight on.]` : "";
|
|
18529
|
+
let voiceSeq = 0;
|
|
18530
|
+
let lastVoiceTurn;
|
|
16807
18531
|
let partialRedraw = null;
|
|
16808
18532
|
const startVoice = async (greet) => {
|
|
16809
18533
|
if (voiceIO) return true;
|
|
@@ -16861,7 +18585,7 @@ ${out}
|
|
|
16861
18585
|
voiceEchoEnd();
|
|
16862
18586
|
if (phase === "speaking") err("\r\x1B[0J" + yellow(" \u270B interrupted\n"));
|
|
16863
18587
|
},
|
|
16864
|
-
onUtterance: (text) => {
|
|
18588
|
+
onUtterance: (text, meta) => {
|
|
16865
18589
|
voicePartial = "";
|
|
16866
18590
|
if (!text.trim()) return;
|
|
16867
18591
|
if (matchVoiceCommand(text) === "off") {
|
|
@@ -16876,15 +18600,24 @@ ${out}
|
|
|
16876
18600
|
})();
|
|
16877
18601
|
return;
|
|
16878
18602
|
}
|
|
16879
|
-
const
|
|
16880
|
-
const
|
|
16881
|
-
|
|
16882
|
-
|
|
16883
|
-
|
|
18603
|
+
const replaces = replacedVoiceTurn(lastVoiceTurn, meta);
|
|
18604
|
+
const { reply: cut, delivery, heard } = takeCut(voiceIO, !replaces);
|
|
18605
|
+
if (delivery || cut) dx?.parkCutDelivery(delivery, !!cut, heard);
|
|
18606
|
+
const cutReply = cut && cut.full.length - cut.heard.length > 40 ? cut : null;
|
|
18607
|
+
const noteP = replaces ? replaces.note : !cutReply ? Promise.resolve("") : (instinct ? instinct.bargeIntent(text).catch((e) => {
|
|
18608
|
+
log32.warn(`barge intent failed \u2014 model decides: ${e.message}`);
|
|
18609
|
+
return void 0;
|
|
18610
|
+
}) : Promise.resolve(void 0)).then(async (intent) => interruptionNote(cutReply, intent) + ackedNote(await instinct?.ackFor(text)));
|
|
18611
|
+
const cutIn = replaces ? replaces.cutIn : interjectNote;
|
|
18612
|
+
interjectNote = "";
|
|
18613
|
+
const id = `v${++voiceSeq}`;
|
|
18614
|
+
lastVoiceTurn = { id, text, note: noteP, cutIn };
|
|
18615
|
+
if (replaces) replacedVoiceTurns.add(replaces.id);
|
|
18616
|
+
if (/^[!#/]/.test(text.trim()) || cutReply || cutIn || replaces || pendingImages.length) dx?.abortSpeculation();
|
|
16884
18617
|
if (!/^[!#/]/.test(text.trim())) voiceIO.beginSpeech(true);
|
|
16885
18618
|
err(`\r\x1B[K ${bold(cyan("\u{1F3A4} \u203A"))} ${text}
|
|
16886
18619
|
`);
|
|
16887
|
-
void dispatchLine(text + note).then(async (r) => {
|
|
18620
|
+
void noteP.then((note) => dispatchLine(text + note + cutIn, { id, replaces: replaces?.id })).then(async (r) => {
|
|
16888
18621
|
if (r === "quit") {
|
|
16889
18622
|
await voiceIO?.awaitIdle();
|
|
16890
18623
|
editorRef?.abort();
|
|
@@ -16892,6 +18625,43 @@ ${out}
|
|
|
16892
18625
|
}).finally(() => editorRef?.redrawNow());
|
|
16893
18626
|
}
|
|
16894
18627
|
});
|
|
18628
|
+
if (instinct) {
|
|
18629
|
+
const v = voiceIO, o = v.options;
|
|
18630
|
+
const { onPartial } = o;
|
|
18631
|
+
const onUtterance = o.onUtterance;
|
|
18632
|
+
const listening = () => voiceIO === v && v.state === "listening" && !v.audible;
|
|
18633
|
+
const cutIns = new CutInAbsorber();
|
|
18634
|
+
o.onPartial = (text) => {
|
|
18635
|
+
if (listening()) instinct.hear(text);
|
|
18636
|
+
onPartial(text);
|
|
18637
|
+
};
|
|
18638
|
+
bindOverlapInstinct(v, instinct, () => voiceIO === v);
|
|
18639
|
+
bindAckInstinct(v, instinct);
|
|
18640
|
+
o.onUtterance = (text, meta) => {
|
|
18641
|
+
instinct.reset();
|
|
18642
|
+
if (cutIns.absorbs(text, meta)) {
|
|
18643
|
+
voicePartial = "";
|
|
18644
|
+
voiceDiag?.push({ t: performance.now(), kind: "instinct_final_absorbed", text });
|
|
18645
|
+
return;
|
|
18646
|
+
}
|
|
18647
|
+
onUtterance(text, meta);
|
|
18648
|
+
};
|
|
18649
|
+
Object.assign(instinct.options, {
|
|
18650
|
+
// Engine blip path: throwaway TTS context, no floor claim. Private in bod-voice — upstream a public
|
|
18651
|
+
// `backchannel()` if this graduates from the spike. AEC only (the blip would deafen half-duplex).
|
|
18652
|
+
onBackchannel: () => {
|
|
18653
|
+
if (!listening() || !v.usingAec) return false;
|
|
18654
|
+
v.fireBackchannel();
|
|
18655
|
+
},
|
|
18656
|
+
onInterject: (heard) => {
|
|
18657
|
+
if (!listening()) return false;
|
|
18658
|
+
cutIns.interjected(heard);
|
|
18659
|
+
interjectNote = `
|
|
18660
|
+
[you are CUTTING IN \u2014 the user is still mid-sentence and has said only this so far. Do it the way a person would: one short natural interjection (a correction, the word they're reaching for, or the answer), then stop and let them continue.]`;
|
|
18661
|
+
onUtterance(heard);
|
|
18662
|
+
}
|
|
18663
|
+
});
|
|
18664
|
+
}
|
|
16895
18665
|
{
|
|
16896
18666
|
const vo = voiceIO.options;
|
|
16897
18667
|
voiceDiag.push({
|
|
@@ -16909,9 +18679,11 @@ ${out}
|
|
|
16909
18679
|
bargeIn: vo.bargeIn,
|
|
16910
18680
|
overlapPause: vo.overlapPause,
|
|
16911
18681
|
overlapResumeMs: vo.overlapResumeMs,
|
|
18682
|
+
overlapDecideMs: vo.overlapDecideMs,
|
|
16912
18683
|
speculativeMs: vo.speculativeMs,
|
|
16913
18684
|
backchannelMs: vo.backchannelMs,
|
|
16914
|
-
emotions: vo.emotions
|
|
18685
|
+
emotions: vo.emotions,
|
|
18686
|
+
ackPick: !!vo.pickAck
|
|
16915
18687
|
}
|
|
16916
18688
|
});
|
|
16917
18689
|
}
|