@livx.cc/agentx 0.99.165 → 0.99.167
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 +5 -1
- package/dist/cli.js +581 -188
- package/dist/cli.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +204 -32
- package/dist/index.js.map +1 -1
- package/dist/native/mic-aec.swift +44 -1
- package/dist/{secondChannel-BNDDJv6d.d.ts → secondChannel-DLB-hDny.d.ts} +5 -0
- package/package.json +2 -2
package/dist/cli.js
CHANGED
|
@@ -2077,8 +2077,8 @@ var init_tools_jobs = __esm({
|
|
|
2077
2077
|
arm() {
|
|
2078
2078
|
if (this.timer || !this.options.sweepMs) return;
|
|
2079
2079
|
this.timer = setInterval(() => {
|
|
2080
|
-
const
|
|
2081
|
-
if (!
|
|
2080
|
+
const live2 = [...this.jobs.values()].some((j) => j.status === "running" && (j.idleMs || j.hardCapMs));
|
|
2081
|
+
if (!live2) {
|
|
2082
2082
|
clearInterval(this.timer);
|
|
2083
2083
|
this.timer = void 0;
|
|
2084
2084
|
return;
|
|
@@ -3359,10 +3359,32 @@ var init_tools_shell = __esm({
|
|
|
3359
3359
|
|
|
3360
3360
|
// cli/cli.ts
|
|
3361
3361
|
import { createInterface } from "readline/promises";
|
|
3362
|
-
import { existsSync as existsSync9, readFileSync as readFileSync10, appendFileSync as appendFileSync2, mkdirSync as
|
|
3363
|
-
import { homedir as
|
|
3362
|
+
import { existsSync as existsSync9, readFileSync as readFileSync10, appendFileSync as appendFileSync2, mkdirSync as mkdirSync13, writeFileSync as writeFileSync10, readdirSync as readdirSync4, statSync as statSync7, unlinkSync as unlinkSync5 } from "fs";
|
|
3363
|
+
import { homedir as homedir11 } from "os";
|
|
3364
3364
|
import { spawnSync as spawnSync7 } from "child_process";
|
|
3365
3365
|
|
|
3366
|
+
// src/runtimes.ts
|
|
3367
|
+
var RUNTIMES = {
|
|
3368
|
+
"claude-code": { keyless: true, ownsTools: true },
|
|
3369
|
+
cursor: { keyless: false, ownsTools: false }
|
|
3370
|
+
// host tools are bridged in through its toolExecutor
|
|
3371
|
+
};
|
|
3372
|
+
function runtimeOf(model) {
|
|
3373
|
+
const p = (model ?? "").split("/")[0];
|
|
3374
|
+
return (model ?? "").includes("/") && p in RUNTIMES ? p : void 0;
|
|
3375
|
+
}
|
|
3376
|
+
var isDelegated = (model) => !!runtimeOf(model);
|
|
3377
|
+
var isClaudeCode = (model) => runtimeOf(model) === "claude-code";
|
|
3378
|
+
var isCursor = (model) => runtimeOf(model) === "cursor";
|
|
3379
|
+
var isKeyless = (modelOrProvider) => {
|
|
3380
|
+
const p = (modelOrProvider ?? "").split("/")[0];
|
|
3381
|
+
return !!RUNTIMES[p]?.keyless;
|
|
3382
|
+
};
|
|
3383
|
+
var ownsTools = (model) => {
|
|
3384
|
+
const r = runtimeOf(model);
|
|
3385
|
+
return !!r && RUNTIMES[r].ownsTools;
|
|
3386
|
+
};
|
|
3387
|
+
|
|
3366
3388
|
// cli/clipboard.ts
|
|
3367
3389
|
import { execFileSync } from "child_process";
|
|
3368
3390
|
import { statSync, writeFileSync } from "fs";
|
|
@@ -3440,7 +3462,7 @@ function copyTextToClipboard(text, platform2 = process.platform) {
|
|
|
3440
3462
|
}
|
|
3441
3463
|
|
|
3442
3464
|
// cli/cli.ts
|
|
3443
|
-
import { join as
|
|
3465
|
+
import { join as join17, resolve as resolve5, basename as basename4, extname, dirname as dirname6 } from "path";
|
|
3444
3466
|
import { AIClient as AIClient2, listModels, listProviders, getProviderFromModel, getModelInfo, resolveModel, isModelSupported, disposeCursorSessions, disposeClaudeCodeSessions, rewindClaudeCodeSession } from "ai.libx.js";
|
|
3445
3467
|
|
|
3446
3468
|
// src/ccBridge.ts
|
|
@@ -4239,7 +4261,11 @@ var PermissionPolicy = class {
|
|
|
4239
4261
|
preToolUse: async (call) => {
|
|
4240
4262
|
const d = this.decide(call);
|
|
4241
4263
|
if (d === "allow") return;
|
|
4242
|
-
if (d === "deny")
|
|
4264
|
+
if (d === "deny") {
|
|
4265
|
+
const reason = `denied by permission policy (${call.name})`;
|
|
4266
|
+
this.options.onDeny?.(call, reason);
|
|
4267
|
+
return { block: true, reason };
|
|
4268
|
+
}
|
|
4243
4269
|
if (this.options.ask) {
|
|
4244
4270
|
const r = await this.options.ask(call);
|
|
4245
4271
|
const decision = r?.decision ?? "deny";
|
|
@@ -4738,7 +4764,7 @@ function pairOk(kind, main2, other) {
|
|
|
4738
4764
|
log8.warn(`${kind} off: both sides are ${main2}`);
|
|
4739
4765
|
return false;
|
|
4740
4766
|
}
|
|
4741
|
-
if (main2
|
|
4767
|
+
if (isCursor(main2) || isCursor(other)) {
|
|
4742
4768
|
log8.warn(`${kind} off: cursor models are not supported (${main2} / ${other})`);
|
|
4743
4769
|
return false;
|
|
4744
4770
|
}
|
|
@@ -5141,6 +5167,9 @@ var AgentOptions = class {
|
|
|
5141
5167
|
* caps, MCP soft timeout) live on `JobRegistryOptions`. Completion notices reach the model via `inject` unless
|
|
5142
5168
|
* the host set its own `onExit`. */
|
|
5143
5169
|
jobs;
|
|
5170
|
+
/** Called after every `inject()` (a background job's completion notice, a host steer). A REPL uses it to wake an
|
|
5171
|
+
* IDLE session — between turns nothing drains the queue, so a finished job would otherwise wait for the next prompt. */
|
|
5172
|
+
onInject;
|
|
5144
5173
|
/** Plan mode: block mutating tools until the agent calls `ExitPlanMode` (host-approved). */
|
|
5145
5174
|
planMode = false;
|
|
5146
5175
|
/** Permission policy gating each tool call (allow / ask / deny). */
|
|
@@ -5298,6 +5327,7 @@ var Agent = class _Agent {
|
|
|
5298
5327
|
* Pushing onto `transcript` directly from outside would race the loop — this drains inside it. */
|
|
5299
5328
|
inject(content) {
|
|
5300
5329
|
this.pendingInjections.push(content);
|
|
5330
|
+
this.options.onInject?.();
|
|
5301
5331
|
}
|
|
5302
5332
|
/** Drop any queued-but-unconsumed injections. The REPL calls this after a LOCAL command (/cmd, !bash)
|
|
5303
5333
|
* — which runs no send() to drain them — so a mid-command steer can't leak into the next real turn. */
|
|
@@ -5311,7 +5341,7 @@ var Agent = class _Agent {
|
|
|
5311
5341
|
/** claude-code/*: the providerOptions every step adds (and prewarm, so the session it starts is the one step 1 reuses). */
|
|
5312
5342
|
claudeCodePo() {
|
|
5313
5343
|
const o = this.options;
|
|
5314
|
-
if (!o.model
|
|
5344
|
+
if (!isClaudeCode(o.model)) return void 0;
|
|
5315
5345
|
const po = { steer: () => this.drainPendingSteers() };
|
|
5316
5346
|
const mode = ccModeOptions(this.modeKind, o.providerOptions?.hooks, () => this.adv?.used() ?? 0);
|
|
5317
5347
|
const bridged = (t) => o.ccBridge === "all" || CC_BRIDGED.has(t.name) || mode.bridge.has(t.name);
|
|
@@ -5341,7 +5371,7 @@ var Agent = class _Agent {
|
|
|
5341
5371
|
async prewarm() {
|
|
5342
5372
|
const o = this.options;
|
|
5343
5373
|
const api = o.model.startsWith("anthropic/") && o.promptCache;
|
|
5344
|
-
if (!api && (!o.model
|
|
5374
|
+
if (!api && (!isClaudeCode(o.model) || !o.providerOptions?.claudeCodeSession)) return;
|
|
5345
5375
|
await this.ensureFs();
|
|
5346
5376
|
const systemPrompt = await this.prepare(), startCtx = await this.fireSessionStart();
|
|
5347
5377
|
const sys = { role: "system", content: systemPrompt + (startCtx ? "\n\n" + startCtx : "") };
|
|
@@ -5658,8 +5688,8 @@ var Agent = class _Agent {
|
|
|
5658
5688
|
let res;
|
|
5659
5689
|
let sent = this.trimContext();
|
|
5660
5690
|
const frag = reasoningToChatFragment(o.model, o.reasoning);
|
|
5661
|
-
const sentTools = o.model
|
|
5662
|
-
const isCursorWithTools = o.model
|
|
5691
|
+
const sentTools = ownsTools(o.model) ? [] : wireTools;
|
|
5692
|
+
const isCursorWithTools = isCursor(o.model) && wireTools.length > 0;
|
|
5663
5693
|
const hostToolTimeoutMs = o.providerOptions?.toolTimeoutMs;
|
|
5664
5694
|
const derivedToolTimeoutMs = Math.max(TRANSPORT_TOOL_TIMEOUT_FLOOR_MS, ...this.activeTools.map(transportHeadroomMs));
|
|
5665
5695
|
const effectiveToolTimeoutMs = typeof hostToolTimeoutMs === "number" ? Math.max(hostToolTimeoutMs, derivedToolTimeoutMs) : derivedToolTimeoutMs;
|
|
@@ -5689,8 +5719,8 @@ var Agent = class _Agent {
|
|
|
5689
5719
|
const cursorPo = isCursorWithTools ? { toolTimeoutMs: effectiveToolTimeoutMs, toolExecutor: hostExec } : void 0;
|
|
5690
5720
|
const claudeSteerPo = this.claudeCodePo();
|
|
5691
5721
|
if (this.ccServer) this.ccExec = hostExec;
|
|
5692
|
-
const cursorDeny = o.model
|
|
5693
|
-
if (o.model
|
|
5722
|
+
const cursorDeny = isCursor(o.model) ? o.permissions?.denyRules(true) ?? [] : [];
|
|
5723
|
+
if (isCursor(o.model) && o.permissions?.options.default === "deny")
|
|
5694
5724
|
throw new Error("cursor/* cannot enforce --onlyTools: its native tools bypass it. Refusing to run \u2014 use a claude-code/* or API model.");
|
|
5695
5725
|
if (cursorDeny.length)
|
|
5696
5726
|
throw new Error(`cursor/* cannot enforce --disallowedTools (${cursorDeny.join(", ")}): its native tools bypass them. Refusing to run \u2014 use a claude-code/* or API model, or drop --disallowedTools.`);
|
|
@@ -8153,6 +8183,9 @@ var VoiceEngine = class _VoiceEngine {
|
|
|
8153
8183
|
// bumps on every aside start/cancel — a late aside of a dead hold never plays
|
|
8154
8184
|
speaking = false;
|
|
8155
8185
|
// audible (deltas flowing OR audio draining)
|
|
8186
|
+
speechStartAt = 0;
|
|
8187
|
+
// clock time `speaking` last turned on / off
|
|
8188
|
+
speechEndAt = 0;
|
|
8156
8189
|
ctxOpen = false;
|
|
8157
8190
|
// the current TTS context still accepts deltas (false once end-frame sent)
|
|
8158
8191
|
interrupted = false;
|
|
@@ -8350,11 +8383,13 @@ var VoiceEngine = class _VoiceEngine {
|
|
|
8350
8383
|
this.handleUtterance(k.text, language ? { [language]: k.text.length } : void 0, k.turns);
|
|
8351
8384
|
};
|
|
8352
8385
|
this.stt.onLevel = (rms) => this.handleLevel(rms);
|
|
8386
|
+
this.stt.isAudible = (agoMs = 0) => this.speakingAt(this.clock.now() - agoMs);
|
|
8353
8387
|
const stt = this.stt;
|
|
8354
8388
|
this.agentText = stt.agentTextInput && stt.sendAgentText ? new AgentTextFeed({
|
|
8355
8389
|
clock: this.clock,
|
|
8356
8390
|
playedMs: () => Math.max(0, this.player.playedMs()),
|
|
8357
8391
|
send: (text, end) => {
|
|
8392
|
+
this.diag("agent_text", { text: text.slice(0, 80), ...end ? { end: true } : {} });
|
|
8358
8393
|
try {
|
|
8359
8394
|
stt.sendAgentText(text, end);
|
|
8360
8395
|
} catch (e) {
|
|
@@ -8446,7 +8481,10 @@ var VoiceEngine = class _VoiceEngine {
|
|
|
8446
8481
|
}
|
|
8447
8482
|
this.diag("tts_turn_begin", { ack, gapless: this.speaking });
|
|
8448
8483
|
const gapless = this.speaking;
|
|
8449
|
-
if (!this.speaking)
|
|
8484
|
+
if (!this.speaking) {
|
|
8485
|
+
this.player.markTurn();
|
|
8486
|
+
this.speechStartAt = this.clock.now();
|
|
8487
|
+
}
|
|
8450
8488
|
this.speaking = true;
|
|
8451
8489
|
this.ctxOpen = true;
|
|
8452
8490
|
this.spokeDeltas = false;
|
|
@@ -8671,6 +8709,7 @@ var VoiceEngine = class _VoiceEngine {
|
|
|
8671
8709
|
}
|
|
8672
8710
|
this.drainTimer = null;
|
|
8673
8711
|
this.speaking = false;
|
|
8712
|
+
this.speechEndAt = this.clock.now();
|
|
8674
8713
|
this.agentText?.end();
|
|
8675
8714
|
this.stopWordReveal(true);
|
|
8676
8715
|
if (this.turnStartAt) log14.debug(`turn: ${Math.round(this.clock.now() - this.turnStartAt)}ms (incl. playback)`);
|
|
@@ -8869,6 +8908,7 @@ var VoiceEngine = class _VoiceEngine {
|
|
|
8869
8908
|
if (this.reply || droppedQueued) this.lastInterrupted = { full: this.reply, heard, exact, queued, queuedTurn: this.queuedTurn };
|
|
8870
8909
|
if (heard.length < this.reply.length || droppedQueued) this.bargedSinceDispatch = true;
|
|
8871
8910
|
this.speaking = false;
|
|
8911
|
+
this.speechEndAt = this.clock.now();
|
|
8872
8912
|
this.ctxOpen = false;
|
|
8873
8913
|
this.interrupted = true;
|
|
8874
8914
|
this.suspectUntil = 0;
|
|
@@ -8978,6 +9018,14 @@ var VoiceEngine = class _VoiceEngine {
|
|
|
8978
9018
|
novelWords(text) {
|
|
8979
9019
|
return this.words(text).filter((w) => !this.echoWords.has(w));
|
|
8980
9020
|
}
|
|
9021
|
+
/** Was the assistant speaking at clock time `t` (+ PHANTOM_TAIL_MS)? Narrower than echoActive's multi-second echo
|
|
9022
|
+
* tail on purpose: the STT phantom guard drops low-confidence short finals here, and a real "Yes." said right after
|
|
9023
|
+
* a question must not land inside it. speechEndAt already trails the audio by the settle margin (~300ms). */
|
|
9024
|
+
speakingAt(t) {
|
|
9025
|
+
if (t < this.speechStartAt) return false;
|
|
9026
|
+
return this.speaking || t < this.speechEndAt + _VoiceEngine.PHANTOM_TAIL_MS;
|
|
9027
|
+
}
|
|
9028
|
+
static PHANTOM_TAIL_MS = 300;
|
|
8981
9029
|
echoActive() {
|
|
8982
9030
|
return this.speaking || this.clock.now() < this.echoUntil;
|
|
8983
9031
|
}
|
|
@@ -9750,9 +9798,9 @@ var VoiceEngine = class _VoiceEngine {
|
|
|
9750
9798
|
return false;
|
|
9751
9799
|
}
|
|
9752
9800
|
const epoch = ++this.asideEpoch, chunks = [], t0 = this.clock.now();
|
|
9753
|
-
const
|
|
9801
|
+
const live2 = () => epoch === this.asideEpoch;
|
|
9754
9802
|
const give = (reason) => {
|
|
9755
|
-
if (!
|
|
9803
|
+
if (!live2()) return;
|
|
9756
9804
|
this.asideEpoch++;
|
|
9757
9805
|
this.diag("aside_skipped", { reason, text: text.slice(0, 40) });
|
|
9758
9806
|
try {
|
|
@@ -9767,10 +9815,10 @@ var VoiceEngine = class _VoiceEngine {
|
|
|
9767
9815
|
this.lastAck = text;
|
|
9768
9816
|
this.echoUntil = Math.max(this.echoUntil, t0 + 2500 + this.options.asideMaxMs);
|
|
9769
9817
|
t.onAudio = (c) => {
|
|
9770
|
-
if (
|
|
9818
|
+
if (live2()) chunks.push(c);
|
|
9771
9819
|
};
|
|
9772
9820
|
t.onDone = () => {
|
|
9773
|
-
if (!
|
|
9821
|
+
if (!live2()) return;
|
|
9774
9822
|
this.clock.clearTimeout(timer);
|
|
9775
9823
|
const n = chunks.reduce((a, c) => a + c.length, 0);
|
|
9776
9824
|
if (!n || !this.speaking || this.pausedAt) return give(!n ? "no_audio" : this.pausedAt ? "held_again" : "turn_over");
|
|
@@ -10047,7 +10095,18 @@ var SonioxSTTOptions = class {
|
|
|
10047
10095
|
* same socket (`sendAgentText`, which VoiceEngine drives paced to playback), so Soniox filters the leftover echo
|
|
10048
10096
|
* of our own voice out of the transcript. Complements AEC — keep echo cancellation on. */
|
|
10049
10097
|
agentTextInput = false;
|
|
10098
|
+
/** Phantom guard: when its last word fell while the assistant was speaking (`isAudible`, wired by VoiceEngine), drop a
|
|
10099
|
+
* final of at most `phantomMaxWords` words, all listener tokens (`phantomTokens`), whose least-sure token is below
|
|
10100
|
+
* `phantomMinConfidence`. stt-rt-v6 makes up backchannels ("Okay.", "Yeah.", "Mm-hmm.") from echo residue under our
|
|
10101
|
+
* own voice: all at confMin 0.33-0.78 (agentx session 20261111-124649). Confidence alone can't separate them from a
|
|
10102
|
+
* real word said over our voice — `say` clips into live Soniox under a reply's residue: 12/19 soft interjections fell
|
|
10103
|
+
* below 0.8 — so words that act ("Stop.", "No.", "Yes.", "Wait.") always pass; a listener token over our own speech
|
|
10104
|
+
* is a no-op anyway. 0 = off. */
|
|
10105
|
+
phantomMinConfidence = 0.8;
|
|
10106
|
+
phantomMaxWords = 2;
|
|
10107
|
+
phantomTokens = /^(?:okay|ok|yeah|yep|yup|mm-?hmm|mhm|hmm+|mm+|uh-?huh|oh|ah|right)$/i;
|
|
10050
10108
|
};
|
|
10109
|
+
var STD_TOKEN_KEYS = /* @__PURE__ */ new Set(["text", "start_ms", "end_ms", "confidence", "is_final", "language", "speaker"]);
|
|
10051
10110
|
var SonioxSTT = class {
|
|
10052
10111
|
options;
|
|
10053
10112
|
ws;
|
|
@@ -10072,6 +10131,9 @@ var SonioxSTT = class {
|
|
|
10072
10131
|
* loop). The host tears voice down instead of spinning forever. */
|
|
10073
10132
|
onFatal = () => {
|
|
10074
10133
|
};
|
|
10134
|
+
/** Was the assistant speaking `agoMs` ago (+ a short tail)? Set by VoiceEngine; gates the phantom guard, asked for the
|
|
10135
|
+
* moment the utterance's last word was said (not when its final landed, ~1s later). */
|
|
10136
|
+
isAudible = () => false;
|
|
10075
10137
|
/** Diagnostic tap (provider errors, ws reconnects, no-audio watchdog). Fire-and-forget: a throwing
|
|
10076
10138
|
* handler disables itself — never affects transcription. Wired by VoiceIO / the lab bridge. */
|
|
10077
10139
|
onDiag = () => {
|
|
@@ -10106,6 +10168,12 @@ var SonioxSTT = class {
|
|
|
10106
10168
|
finalToks = [];
|
|
10107
10169
|
// diarization only: finalized tokens of the current utterance
|
|
10108
10170
|
partialToks = [];
|
|
10171
|
+
uttToks = [];
|
|
10172
|
+
// stt_final diag: finalized tokens of the current utterance
|
|
10173
|
+
uttPartials = [];
|
|
10174
|
+
// stt_final diag: its current partial tokens
|
|
10175
|
+
levels = [];
|
|
10176
|
+
// stt_final diag: recent mic RMS per chunk (~12s)
|
|
10109
10177
|
constructor(options) {
|
|
10110
10178
|
this.options = { ...new SonioxSTTOptions(), ...options };
|
|
10111
10179
|
}
|
|
@@ -10169,10 +10237,7 @@ var SonioxSTT = class {
|
|
|
10169
10237
|
const combined = (this.finalText + this.partialText).trim();
|
|
10170
10238
|
if (!combined || now() - this.lastChangeAt < this.options.silenceEndpointMs) return;
|
|
10171
10239
|
if (this.firstTokenAt) log15.debug(`stt: ${Math.round(now() - this.firstTokenAt)}ms first-token\u2192silence-endpoint, "${combined.slice(0, 60)}"`);
|
|
10172
|
-
|
|
10173
|
-
const turns = this.turns(true), ago = this.lastWordAgoMs();
|
|
10174
|
-
this.reset();
|
|
10175
|
-
this.onUtterance(this.stray(combined), now(), language, turns, ago);
|
|
10240
|
+
this.emit(combined, "silence");
|
|
10176
10241
|
}, 120);
|
|
10177
10242
|
this.endpointTimer.unref?.();
|
|
10178
10243
|
this.startedChunksAt = now();
|
|
@@ -10198,7 +10263,10 @@ var SonioxSTT = class {
|
|
|
10198
10263
|
const v = view.getInt16(i, true);
|
|
10199
10264
|
sum += v * v;
|
|
10200
10265
|
}
|
|
10201
|
-
|
|
10266
|
+
const rms = Math.sqrt(sum / (chunk.byteLength / 2));
|
|
10267
|
+
this.levels.push({ at: this.lastChunkAt, rms });
|
|
10268
|
+
if (this.levels.length > 120) this.levels.shift();
|
|
10269
|
+
this.onLevel(rms);
|
|
10202
10270
|
if (this.ws.readyState === WebSocket.OPEN) {
|
|
10203
10271
|
this.ws.send(chunk);
|
|
10204
10272
|
const at = this.sentBytes / 2 / STT_SAMPLE_RATE * 1e3;
|
|
@@ -10229,6 +10297,7 @@ var SonioxSTT = class {
|
|
|
10229
10297
|
if (t.text !== "<end>" && typeof t.end_ms === "number" && String(t.text).trim() && t.end_ms > this.lastWordEndMs) this.lastWordEndMs = t.end_ms;
|
|
10230
10298
|
if (t.text === "<end>") endpoint = true;
|
|
10231
10299
|
else if (t.is_final) {
|
|
10300
|
+
this.uttToks.push(t);
|
|
10232
10301
|
this.finalText += t.text;
|
|
10233
10302
|
this.countLang(this.finalLangChars, t);
|
|
10234
10303
|
if (this.options.diarization) this.finalToks.push(t);
|
|
@@ -10239,6 +10308,7 @@ var SonioxSTT = class {
|
|
|
10239
10308
|
this.partialLangChars = {};
|
|
10240
10309
|
for (const t of partials) this.countLang(this.partialLangChars, t);
|
|
10241
10310
|
if (this.options.diarization) this.partialToks = partials;
|
|
10311
|
+
this.uttPartials = partials;
|
|
10242
10312
|
const combined = this.finalText + this.partialText;
|
|
10243
10313
|
if (combined !== this.lastCombined) {
|
|
10244
10314
|
this.lastCombined = combined;
|
|
@@ -10249,10 +10319,32 @@ var SonioxSTT = class {
|
|
|
10249
10319
|
if (endpoint && this.finalText.trim()) {
|
|
10250
10320
|
const utterance = this.finalText.trim();
|
|
10251
10321
|
if (this.firstTokenAt) log15.debug(`stt: ${Math.round(now() - this.firstTokenAt)}ms first-token\u2192endpoint, "${utterance.slice(0, 60)}"`);
|
|
10252
|
-
|
|
10253
|
-
|
|
10254
|
-
|
|
10255
|
-
|
|
10322
|
+
this.emit(utterance, "end");
|
|
10323
|
+
}
|
|
10324
|
+
}
|
|
10325
|
+
/** Close the current utterance: diag, reset, then hand it to onUtterance — unless the phantom guard drops it. */
|
|
10326
|
+
emit(text, endpoint) {
|
|
10327
|
+
const withPartials = endpoint === "silence";
|
|
10328
|
+
const language = this.language(withPartials);
|
|
10329
|
+
const turns = this.turns(withPartials), ago = this.lastWordAgoMs();
|
|
10330
|
+
const confMin = this.finalDiag(text, endpoint, ago);
|
|
10331
|
+
this.reset();
|
|
10332
|
+
if (this.phantom(text, confMin, ago)) {
|
|
10333
|
+
this.diag("stt_phantom_dropped", { text: text.slice(0, 80), confMin, lastWordAgoMs: ago });
|
|
10334
|
+
return;
|
|
10335
|
+
}
|
|
10336
|
+
this.onUtterance(this.stray(text), now(), language, turns, ago);
|
|
10337
|
+
}
|
|
10338
|
+
phantom(text, confMin, agoMs) {
|
|
10339
|
+
const { phantomMinConfidence: min, phantomMaxWords: max, phantomTokens: listener } = this.options;
|
|
10340
|
+
if (!min || confMin === void 0 || confMin >= min) return false;
|
|
10341
|
+
const words5 = text.split(/[\s,.!?…]+/).filter(Boolean);
|
|
10342
|
+
if (!words5.length || words5.length > max || !words5.every((w) => listener.test(w))) return false;
|
|
10343
|
+
try {
|
|
10344
|
+
return this.isAudible(agoMs ?? 0);
|
|
10345
|
+
} catch (e) {
|
|
10346
|
+
log15.warn(`isAudible threw: ${e instanceof Error ? e.message : e}`);
|
|
10347
|
+
return false;
|
|
10256
10348
|
}
|
|
10257
10349
|
}
|
|
10258
10350
|
/** How long ago (ms, now) the utterance's last spoken word ended: the audio sent so far minus that token's end_ms on
|
|
@@ -10285,7 +10377,29 @@ var SonioxSTT = class {
|
|
|
10285
10377
|
const words5 = sonioxWords(withPartials ? [...this.finalToks, ...this.partialToks] : this.finalToks);
|
|
10286
10378
|
return words5.some((w) => w.spk != null) ? speakerRuns(words5) : void 0;
|
|
10287
10379
|
}
|
|
10380
|
+
/** One `stt_final` diag per utterance: how sure Soniox was, the mic level over it, and any token fields beyond the
|
|
10381
|
+
* usual ones — to tell words the user said from ones the STT made up (a phantom "Okay." heard 186× over our own
|
|
10382
|
+
* speech, agentx session 20261111-105859). */
|
|
10383
|
+
finalDiag(text, endpoint, lastWordAgoMs) {
|
|
10384
|
+
const toks = [...this.uttToks, ...endpoint === "silence" ? this.uttPartials : []].filter((t) => String(t.text).trim());
|
|
10385
|
+
const conf = toks.map((t) => t.confidence).filter((c) => typeof c === "number");
|
|
10386
|
+
const since = (this.firstTokenAt || now()) - 1500;
|
|
10387
|
+
const rms = this.levels.filter((l) => l.at >= since).map((l) => l.rms).sort((a, b) => a - b);
|
|
10388
|
+
const extra = [...new Set(toks.flatMap((t) => Object.keys(t).filter((k) => !STD_TOKEN_KEYS.has(k))))];
|
|
10389
|
+
this.diag("stt_final", {
|
|
10390
|
+
text: text.slice(0, 80),
|
|
10391
|
+
endpoint,
|
|
10392
|
+
lastWordAgoMs,
|
|
10393
|
+
...conf.length ? { confMin: +Math.min(...conf).toFixed(3), confAvg: +(conf.reduce((a, b) => a + b, 0) / conf.length).toFixed(3) } : {},
|
|
10394
|
+
...rms.length ? { rmsPeak: Math.round(rms[rms.length - 1]), rmsMed: Math.round(rms[rms.length >> 1]) } : {},
|
|
10395
|
+
...toks.length ? { startMs: toks[0].start_ms, endMs: toks[toks.length - 1].end_ms } : {},
|
|
10396
|
+
...extra.length ? { tokenKeys: extra } : {}
|
|
10397
|
+
});
|
|
10398
|
+
return conf.length ? Math.min(...conf) : void 0;
|
|
10399
|
+
}
|
|
10288
10400
|
reset() {
|
|
10401
|
+
this.uttToks = [];
|
|
10402
|
+
this.uttPartials = [];
|
|
10289
10403
|
this.finalToks = [];
|
|
10290
10404
|
this.partialToks = [];
|
|
10291
10405
|
this.finalLangChars = {};
|
|
@@ -10388,7 +10502,7 @@ var now2 = () => performance.now();
|
|
|
10388
10502
|
var CartesiaTTSOptions = class {
|
|
10389
10503
|
auth = "";
|
|
10390
10504
|
voiceId = "";
|
|
10391
|
-
model = "sonic-3.
|
|
10505
|
+
model = "sonic-3.6";
|
|
10392
10506
|
/** 'apiKey' (server/CLI) → `api_key=` URL param; 'token' (browser, BE-minted) → `access_token=`. */
|
|
10393
10507
|
authMode = "apiKey";
|
|
10394
10508
|
/** Cartesia `language` code ('en', 'he', …). Unset → field omitted (provider default). Mutable:
|
|
@@ -10490,6 +10604,16 @@ var CartesiaTTS = class _CartesiaTTS {
|
|
|
10490
10604
|
};
|
|
10491
10605
|
this.ws.onmessage = (ev) => {
|
|
10492
10606
|
const m = JSON.parse(String(ev.data));
|
|
10607
|
+
const pr = m.context_id && this.priming.get(m.context_id);
|
|
10608
|
+
if (pr) {
|
|
10609
|
+
if (m.type === "chunk" && m.data) pr.chunks.push(base64ToBytes(m.data));
|
|
10610
|
+
else if (m.type === "done" || m.type === "error") {
|
|
10611
|
+
this.priming.delete(m.context_id);
|
|
10612
|
+
if (m.type === "done") this.primed.set(pr.key, pr.chunks);
|
|
10613
|
+
else this.primed.delete(pr.key);
|
|
10614
|
+
}
|
|
10615
|
+
return;
|
|
10616
|
+
}
|
|
10493
10617
|
if (m.context_id && m.context_id !== this.ctxId) return;
|
|
10494
10618
|
if (m.type === "chunk" && m.data) {
|
|
10495
10619
|
this.consecutiveErrors = 0;
|
|
@@ -10547,7 +10671,40 @@ var CartesiaTTS = class _CartesiaTTS {
|
|
|
10547
10671
|
this.newContext();
|
|
10548
10672
|
if (this.ws?.readyState === WebSocket.OPEN) this.ws.send(this.frame("Ok.", false));
|
|
10549
10673
|
}
|
|
10674
|
+
/** Phrases synthesized ahead (prime): key → audio (null = still generating). */
|
|
10675
|
+
primed = /* @__PURE__ */ new Map();
|
|
10676
|
+
priming = /* @__PURE__ */ new Map();
|
|
10677
|
+
/** This context began with a primed phrase: its audio played from the cache; more text is synthesized after it. */
|
|
10678
|
+
ctxCached = false;
|
|
10679
|
+
ctxRest = "";
|
|
10680
|
+
ctxSent = false;
|
|
10681
|
+
static key(t) {
|
|
10682
|
+
return t.trim().replace(/[\s.,!?…]+$/u, "").replace(/\s+/g, " ");
|
|
10683
|
+
}
|
|
10684
|
+
/** Synthesize `text` now, in this voice and language, and keep its audio: a later utterance that is exactly this text
|
|
10685
|
+
* plays at once, with no TTS round trip (a call's planned opener — live: ~470ms to its first audio). */
|
|
10686
|
+
prime(text) {
|
|
10687
|
+
const key = _CartesiaTTS.key(text);
|
|
10688
|
+
if (!key || this.primed.has(key) || this.down) return;
|
|
10689
|
+
this.primed.set(key, null);
|
|
10690
|
+
const id = `prime-${++this.ctxSeq}`;
|
|
10691
|
+
const send = () => {
|
|
10692
|
+
const cur = this.ctxId, lang = this.ctxLanguage;
|
|
10693
|
+
this.ctxId = id;
|
|
10694
|
+
this.ctxLanguage = this.options.language;
|
|
10695
|
+
const f = this.frame(text, false);
|
|
10696
|
+
this.ctxId = cur;
|
|
10697
|
+
this.ctxLanguage = lang;
|
|
10698
|
+
this.priming.set(id, { key, chunks: [] });
|
|
10699
|
+
this.ws.send(f);
|
|
10700
|
+
};
|
|
10701
|
+
if (this.ws?.readyState === WebSocket.OPEN) send();
|
|
10702
|
+
else void this.ensureConnected().then(() => this.ws?.readyState === WebSocket.OPEN && send());
|
|
10703
|
+
}
|
|
10550
10704
|
newContext() {
|
|
10705
|
+
this.ctxCached = false;
|
|
10706
|
+
this.ctxRest = "";
|
|
10707
|
+
this.ctxSent = false;
|
|
10551
10708
|
this.ctxId = `ctx-${++this.ctxSeq}`;
|
|
10552
10709
|
this.firstAudioAt = 0;
|
|
10553
10710
|
this.ctxLanguage = this.options.language;
|
|
@@ -10573,6 +10730,19 @@ var CartesiaTTS = class _CartesiaTTS {
|
|
|
10573
10730
|
if (this.down) return;
|
|
10574
10731
|
text = cont ? this.say.feed(text) : this.say.feed(text) + this.say.flush();
|
|
10575
10732
|
if (cont && !text) return;
|
|
10733
|
+
const hit = !this.firstAudioAt && !this.ctxCached && this.primed.get(_CartesiaTTS.key(text));
|
|
10734
|
+
if (hit) {
|
|
10735
|
+
this.ctxCached = true;
|
|
10736
|
+
this.firstAudioAt = now2();
|
|
10737
|
+
this.diag("tts_primed", { chars: text.length });
|
|
10738
|
+
for (const c of hit) this.onAudio(c);
|
|
10739
|
+
return;
|
|
10740
|
+
}
|
|
10741
|
+
if (this.ctxCached) {
|
|
10742
|
+
this.ctxRest += text;
|
|
10743
|
+
return;
|
|
10744
|
+
}
|
|
10745
|
+
this.ctxSent = true;
|
|
10576
10746
|
if (this.ws?.readyState === WebSocket.OPEN) this.ws.send(this.frame(text, cont));
|
|
10577
10747
|
else void this.ensureConnected().then(() => this.ws?.readyState === WebSocket.OPEN && this.ws.send(this.frame(text, cont)));
|
|
10578
10748
|
}
|
|
@@ -10586,11 +10756,27 @@ var CartesiaTTS = class _CartesiaTTS {
|
|
|
10586
10756
|
this.ws.send(JSON.stringify({ ...JSON.parse(this.frame("", true)), flush: true }));
|
|
10587
10757
|
}
|
|
10588
10758
|
end() {
|
|
10589
|
-
|
|
10759
|
+
let held2 = this.say.flush();
|
|
10590
10760
|
if (this.down) {
|
|
10591
10761
|
this.onDone();
|
|
10592
10762
|
return;
|
|
10593
10763
|
}
|
|
10764
|
+
const hit = !this.ctxSent && !this.ctxCached && !this.firstAudioAt && this.primed.get(_CartesiaTTS.key(held2));
|
|
10765
|
+
if (hit) {
|
|
10766
|
+
this.diag("tts_primed", { chars: held2.length });
|
|
10767
|
+
this.firstAudioAt = now2();
|
|
10768
|
+
for (const c of hit) this.onAudio(c);
|
|
10769
|
+
queueMicrotask(() => this.onDone());
|
|
10770
|
+
return;
|
|
10771
|
+
}
|
|
10772
|
+
if (this.ctxCached) {
|
|
10773
|
+
held2 = (this.ctxRest + held2).trim();
|
|
10774
|
+
this.ctxRest = "";
|
|
10775
|
+
if (!held2) {
|
|
10776
|
+
queueMicrotask(() => this.onDone());
|
|
10777
|
+
return;
|
|
10778
|
+
}
|
|
10779
|
+
}
|
|
10594
10780
|
if (this.ws?.readyState === WebSocket.OPEN) this.ws.send(this.frame(held2, false));
|
|
10595
10781
|
}
|
|
10596
10782
|
cancel() {
|
|
@@ -10692,8 +10878,6 @@ var REACT = /^(?:(?:oh|and|so|wait|but|ok|okay|yeah)\s+)*(?:wow|whoa|woah|really
|
|
|
10692
10878
|
var WH_LEAD = "^(?:(?:oh|and|so|wait|but|ok|okay|um|uh|sorry)\\s+)*";
|
|
10693
10879
|
var WH_QUESTION = new RegExp(WH_LEAD + "(?:who|whom|whose|where|which|why|how|when|what|\u05DE\u05D9|\u05D0\u05D9\u05E4\u05D4|\u05DC\u05DE\u05D4|\u05D0\u05D9\u05DA|\u05DE\u05EA\u05D9|\u05DE\u05D4)\\s+\\S", "u");
|
|
10694
10880
|
var WH_EXCLAIM = new RegExp(WH_LEAD + "(?:what an? |how (?:cool|nice|fun|sweet|sad|funny|weird|crazy|strange|interesting|beautiful|lovely|cute|amazing|awesome)\\b)", "u");
|
|
10695
|
-
var BARE = /* @__PURE__ */ new Set(["yeah", "yea", "yes", "yep", "yup", "ok", "okay", "k", "right", "sure", "mm", "mmm", "hmm", "mhm", "mm-hm", "mm-hmm", "uh-huh", "um", "uh", "ah", "oh"]);
|
|
10696
|
-
var isBareCue = (text) => BARE.has(norm2(text).replace(/^-+|-+$/g, ""));
|
|
10697
10881
|
var isReaction = (text) => {
|
|
10698
10882
|
const t = norm2(text);
|
|
10699
10883
|
return REACT.test(t) || new RegExp("\\s\\p{L}{1,3}$", "u").test(t) && REACT.test(t.replace(new RegExp("\\s\\p{L}{1,3}$", "u"), ""));
|
|
@@ -12275,7 +12459,7 @@ ${nowLine()}. Anchor every relative or time-sensitive reference \u2014 "today",
|
|
|
12275
12459
|
* no other MCP server — the reflex only talks and routes; real work still goes through Act and its policy. */
|
|
12276
12460
|
claudeCodeReflex() {
|
|
12277
12461
|
const o = this.options;
|
|
12278
|
-
if (!o.reflexModel
|
|
12462
|
+
if (!isClaudeCode(o.reflexModel)) return {};
|
|
12279
12463
|
const po = o.providerOptionsFor?.(o.reflexModel) ?? {};
|
|
12280
12464
|
return {
|
|
12281
12465
|
ccBridge: "all",
|
|
@@ -16082,10 +16266,6 @@ var VoiceCall = class {
|
|
|
16082
16266
|
this.barge();
|
|
16083
16267
|
return "cut";
|
|
16084
16268
|
}
|
|
16085
|
-
if (isBareCue(text)) {
|
|
16086
|
-
this.o.onMetric({ name: "drop", kind: "bare cue", text });
|
|
16087
|
-
return "keep";
|
|
16088
|
-
}
|
|
16089
16269
|
if (this.o.mode === "live" && isReaction(text)) return this.kept(text), "keep";
|
|
16090
16270
|
const d = await this.judge.judge(text);
|
|
16091
16271
|
if (d.verdict === "cut") this.barge();
|
|
@@ -16130,7 +16310,7 @@ var VoiceCall = class {
|
|
|
16130
16310
|
* fill line: never MAIN history. */
|
|
16131
16311
|
aside(text) {
|
|
16132
16312
|
const now4 = this.o.now();
|
|
16133
|
-
if (
|
|
16313
|
+
if (now4 - this.lastAside.at < this.o.asideGapMs) return null;
|
|
16134
16314
|
const line = overlapAside(text, this.lang, this.lastAside.text, void 0, this.o.mode === "live");
|
|
16135
16315
|
if (!line) return null;
|
|
16136
16316
|
this.lastAside = { text: line, at: now4 };
|
|
@@ -16169,10 +16349,7 @@ var VoiceCall = class {
|
|
|
16169
16349
|
onTurn(t) {
|
|
16170
16350
|
this.floor = "";
|
|
16171
16351
|
this.flushKept(t.text);
|
|
16172
|
-
if (this.o.noteTurn && this.o.workReply && t.kind !== "replace" && this.working && !isClosing(t.text))
|
|
16173
|
-
if (isBareCue(t.text)) return void this.o.onMetric({ name: "drop", id: t.id, kind: "bare cue", text: t.text });
|
|
16174
|
-
return void this.overWork(this.cur, t);
|
|
16175
|
-
}
|
|
16352
|
+
if (this.o.noteTurn && this.o.workReply && t.kind !== "replace" && this.working && !isClosing(t.text)) return void this.overWork(this.cur, t);
|
|
16176
16353
|
const prev = this.cur, quick = this.quickOn && !this.working && (t.kind === "new" || prev?.lane !== "deep");
|
|
16177
16354
|
const now4 = this.o.now(), lastWord = this.lastWordAt !== null;
|
|
16178
16355
|
const at = this.lastWordAt ?? this.firstFinalAt ?? now4;
|
|
@@ -17179,6 +17356,16 @@ function dotDirs(base, sub, opts = {}) {
|
|
|
17179
17356
|
const dirs = [`${base}/.agent/${sub}`, `${base}/.claude/${sub}`, `${home}/.agent/${sub}`, `${home}/.claude/${sub}`, ...extraDirs().map((d) => `${d}/${sub}`)];
|
|
17180
17357
|
return opts.existing ? dirs.filter((d) => existsSync2(d)) : dirs;
|
|
17181
17358
|
}
|
|
17359
|
+
function userInstructionFiles(o = {}) {
|
|
17360
|
+
const home = o.home ?? homedir(), cwd = o.cwd ?? process.cwd();
|
|
17361
|
+
const project = new Set(["AGENT.md", "AGENTS.md", "CLAUDE.md"].flatMap((n) => [`${cwd}/${n}`, `${cwd}/.claude/${n}`]));
|
|
17362
|
+
const tiers = [[`${home}/.agent/AGENTS.md`], extraDirs(o.env).map((d) => `${d.replace(/\/+$/, "")}/CLAUDE.md`), [`${home}/.claude/CLAUDE.md`]];
|
|
17363
|
+
for (const tier of tiers) {
|
|
17364
|
+
const hit = tier.filter((p) => existsSync2(p));
|
|
17365
|
+
if (hit.length) return hit.filter((p) => !project.has(p));
|
|
17366
|
+
}
|
|
17367
|
+
return [];
|
|
17368
|
+
}
|
|
17182
17369
|
function truncate(s, n, suffix = "\u2026") {
|
|
17183
17370
|
const t = s ?? "";
|
|
17184
17371
|
return t.length > n ? t.slice(0, n) + suffix : t;
|
|
@@ -17259,7 +17446,7 @@ function toCursorMcp(servers) {
|
|
|
17259
17446
|
return Object.keys(out).length ? { mcpServers: out } : void 0;
|
|
17260
17447
|
}
|
|
17261
17448
|
function cursorProviderOptions(model, cwd, mcpServers, hostMcpServers) {
|
|
17262
|
-
if (!(model
|
|
17449
|
+
if (!isCursor(model)) return void 0;
|
|
17263
17450
|
return { cwd, ...toCursorMcp(mcpServers) ?? {}, ...hostMcpServers?.length ? { hostMcpServers } : {}, ...process.env.CURSOR_WARM === "0" ? {} : { cursorSession: randomUUID() } };
|
|
17264
17451
|
}
|
|
17265
17452
|
function toClaudeCodeMcp(servers) {
|
|
@@ -17278,7 +17465,7 @@ function toClaudeCodeMcp(servers) {
|
|
|
17278
17465
|
return Object.keys(out).length ? { mcpServers: out } : void 0;
|
|
17279
17466
|
}
|
|
17280
17467
|
function claudeCodeProviderOptions(model, cwd, mcpServers) {
|
|
17281
|
-
if (!(model
|
|
17468
|
+
if (!isClaudeCode(model)) return void 0;
|
|
17282
17469
|
const env = (() => {
|
|
17283
17470
|
const base = plainEnv(process.env, process.env.AGENTX_CC_USE_API_KEY ? [] : ["ANTHROPIC_API_KEY", "ANTHROPIC_AUTH_TOKEN"]);
|
|
17284
17471
|
return { ENABLE_CLAUDEAI_MCP_SERVERS: "false", ...base };
|
|
@@ -17301,12 +17488,12 @@ async function buildAgent(o) {
|
|
|
17301
17488
|
const jailedDisk = new JailedFilesystem(disk);
|
|
17302
17489
|
jailedDisk.setCwd(cwd);
|
|
17303
17490
|
const virtual = o.sandbox || !!o.boddb;
|
|
17304
|
-
const
|
|
17305
|
-
const
|
|
17306
|
-
const
|
|
17307
|
-
if (virtual &&
|
|
17491
|
+
const isCursor2 = isCursor(o.model);
|
|
17492
|
+
const isClaudeCode2 = isClaudeCode(o.model);
|
|
17493
|
+
const isDelegated2 = isDelegated(o.model);
|
|
17494
|
+
if (virtual && isDelegated2)
|
|
17308
17495
|
throw new Error(
|
|
17309
|
-
`${
|
|
17496
|
+
`${isCursor2 ? "cursor" : "claude-code"}/* models cannot run in --sandbox/--boddb: the delegated agent runs its own real-disk tools and bypasses the VFS jail. Use disk mode (default).`
|
|
17310
17497
|
);
|
|
17311
17498
|
let fs = jailedDisk;
|
|
17312
17499
|
const vcwd = toVfsPath(cwd);
|
|
@@ -17330,7 +17517,7 @@ async function buildAgent(o) {
|
|
|
17330
17517
|
let mountNote = "";
|
|
17331
17518
|
if (o.confine) {
|
|
17332
17519
|
if (virtual) throw new Error("--confine is a disk-mode jail; --sandbox/--boddb already contain the agent.");
|
|
17333
|
-
if (
|
|
17520
|
+
if (isClaudeCode2 && o.permissions?.options.default !== "deny") throw new Error("claude-code/* can be confined only with an allow-list (--onlyTools): its own tools bypass the jail.");
|
|
17334
17521
|
const roots = [...new Set([cwd, ...o.addDirs ?? []].map((d) => realpathSync3(resolve3(d))))];
|
|
17335
17522
|
const mem = new MemFilesystem3();
|
|
17336
17523
|
for (const r of roots) await mkdirp(mem, r);
|
|
@@ -17392,7 +17579,7 @@ Reference files in them by their mount path (the left side).`;
|
|
|
17392
17579
|
const agentRef = {};
|
|
17393
17580
|
const jobRegistry = new JobRegistry();
|
|
17394
17581
|
const useRealShell = o.realShell ?? !virtual;
|
|
17395
|
-
if (useRealShell && !virtual && !
|
|
17582
|
+
if (useRealShell && !virtual && !isClaudeCode2) {
|
|
17396
17583
|
const jobs = new ShellJobRegistry({
|
|
17397
17584
|
cwd,
|
|
17398
17585
|
killOnExit: true,
|
|
@@ -17419,8 +17606,8 @@ Reference files in them by their mount path (the left side).`;
|
|
|
17419
17606
|
// turns, amortising the ~2s Agent.create + h2 handshake. Keyed per agentx launch.
|
|
17420
17607
|
...(() => {
|
|
17421
17608
|
let po = providerOptionsFor(o.model, cwd, o.mcpServers, o.hostMcpServers);
|
|
17422
|
-
if (po && o.lean &&
|
|
17423
|
-
if (po && o.confine &&
|
|
17609
|
+
if (po && o.lean && isClaudeCode2) po = { ...po, settingSources: [] };
|
|
17610
|
+
if (po && o.confine && isClaudeCode2) {
|
|
17424
17611
|
if (!po.claudeCodeSession) throw new Error("claude-code/* cannot be confined without the warm session (AGENTX_CC_WARM=0): its own tools would bypass the jail.");
|
|
17425
17612
|
return { providerOptions: { ...po, tools: [] }, ccBridge: "all" };
|
|
17426
17613
|
}
|
|
@@ -17454,7 +17641,7 @@ Windows paths: file tools accept ${cwd} style paths and the same path written ${
|
|
|
17454
17641
|
const list = [...names];
|
|
17455
17642
|
return `You are agentx (an agent runtime) \u2014 NOT Claude Code or Claude Desktop, which are separate agents with their own config. Your MCP servers are configured in .agent/settings.json or .agent/config.* (this project's .agent/ or ~/.agent/), and their tools are already in your tool list as \`mcp__<server>__<tool>\`.${list.length ? ` Configured MCP servers: ${list.join(", ")}.` : " No MCP servers are currently configured."} When asked which MCPs/tools you have, answer from your own tool list \u2014 never read Claude Code/Desktop config (e.g. ~/.claude.json, claude_desktop_config.json) to answer; those belong to a different agent.`;
|
|
17456
17643
|
})();
|
|
17457
|
-
const closureNote =
|
|
17644
|
+
const closureNote = isDelegated2 ? "Never end your turn on an action you only announced. If you say you are about to search, read, check or run something, DO it in the same turn before you stop. Your last message must be the ANSWER \u2014 the result and what it means \u2014 or an explicit statement that you are blocked and why. Narration of what you are about to do is not an ending." : "";
|
|
17458
17645
|
const extra = [o.appendSystemPrompt, envNote, cwdNote, shellNote, toneNote, mountNote, mcpNote, closureNote].filter(Boolean).join("\n\n");
|
|
17459
17646
|
const basePrompt = (() => {
|
|
17460
17647
|
let p = new AgentOptions().systemPrompt;
|
|
@@ -17465,7 +17652,7 @@ Windows paths: file tools accept ${cwd} style paths and the same path written ${
|
|
|
17465
17652
|
return { systemPrompt: basePrompt + "\n\n" + extra };
|
|
17466
17653
|
})(),
|
|
17467
17654
|
tools: (() => {
|
|
17468
|
-
if (
|
|
17655
|
+
if (isClaudeCode2) return o.confine ? toolsByName(o.tools ?? DEFAULT_TOOLS).filter((t) => o.permissions?.decide({ name: t.name, args: {} }) !== "deny") : [];
|
|
17469
17656
|
const requested = o.tools ?? DEFAULT_TOOLS;
|
|
17470
17657
|
const base = toolsByName([...requested, ...autoWebTools()]);
|
|
17471
17658
|
const tail = [...o.extraTools ?? []];
|
|
@@ -17499,6 +17686,11 @@ Windows paths: file tools accept ${cwd} style paths and the same path written ${
|
|
|
17499
17686
|
memoryUserDir,
|
|
17500
17687
|
agentsDir: dot("agents"),
|
|
17501
17688
|
instructionFiles: o.lean ? false : o.instructionFiles ?? ["AGENTS.md", "CLAUDE.md"],
|
|
17689
|
+
// the user's global rules (~/.agent/AGENTS.md › AGENTX_EXTRA_DIRS/CLAUDE.md › ~/.claude/CLAUDE.md) — real disk only
|
|
17690
|
+
...o.lean || virtual ? {} : (() => {
|
|
17691
|
+
const f = userInstructionFiles({ cwd });
|
|
17692
|
+
return f.length ? { contextFiles: f.map((p) => ({ path: toVfsPath(p), label: "User instructions (global)" })) } : {};
|
|
17693
|
+
})(),
|
|
17502
17694
|
// Only override the Agent's safety defaults when explicitly configured.
|
|
17503
17695
|
...o.maxTokens != null ? { maxTokens: o.maxTokens } : {},
|
|
17504
17696
|
...o.timeoutMs != null ? { timeoutMs: o.timeoutMs } : {},
|
|
@@ -17532,7 +17724,8 @@ init_logging();
|
|
|
17532
17724
|
init_llm();
|
|
17533
17725
|
init_platform();
|
|
17534
17726
|
import { spawn as spawn2, spawnSync as spawnSync3 } from "child_process";
|
|
17535
|
-
import {
|
|
17727
|
+
import { createHash as createHash3 } from "crypto";
|
|
17728
|
+
import { appendFileSync, existsSync as existsSync4, mkdirSync as mkdirSync5, readFileSync as readFileSync6, renameSync, rmSync as rmSync2 } from "fs";
|
|
17536
17729
|
import { homedir as homedir3 } from "os";
|
|
17537
17730
|
import { dirname as dirname4, join as join8 } from "path";
|
|
17538
17731
|
import { fileURLToPath } from "url";
|
|
@@ -17631,20 +17824,26 @@ function resolveAecBinary() {
|
|
|
17631
17824
|
const plist = join8(nativeDir(), "Info.plist");
|
|
17632
17825
|
if (!existsSync4(src)) return null;
|
|
17633
17826
|
const cacheDir = join8(homedir3(), ".agent", "cache");
|
|
17634
|
-
const
|
|
17635
|
-
|
|
17827
|
+
const hash = createHash3("sha1").update(readFileSync6(src)).update(readFileSync6(plist)).digest("hex").slice(0, 10);
|
|
17828
|
+
const bin = join8(cacheDir, `mic-aec-${hash}`);
|
|
17829
|
+
if (existsSync4(bin)) return bin;
|
|
17636
17830
|
if (spawnSync3("which", ["swiftc"]).status !== 0) return null;
|
|
17637
17831
|
mkdirSync5(cacheDir, { recursive: true });
|
|
17638
17832
|
log36.info("compiling AEC mic helper (first run)\u2026");
|
|
17639
|
-
const
|
|
17640
|
-
|
|
17641
|
-
log36.warn(
|
|
17642
|
-
|
|
17643
|
-
}
|
|
17644
|
-
const sign = spawnSync3("codesign", ["-fs", "-", bin], { encoding: "utf8" });
|
|
17645
|
-
if (sign.status !== 0) {
|
|
17646
|
-
log36.warn(`codesign failed: ${sign.stderr?.slice(0, 200)}`);
|
|
17833
|
+
const tmp = `${bin}.${process.pid}.tmp`;
|
|
17834
|
+
const fail = (msg) => {
|
|
17835
|
+
log36.warn(msg);
|
|
17836
|
+
rmSync2(tmp, { force: true });
|
|
17647
17837
|
return null;
|
|
17838
|
+
};
|
|
17839
|
+
const build = spawnSync3("swiftc", ["-O", "-o", tmp, src, "-Xlinker", "-sectcreate", "-Xlinker", "__TEXT", "-Xlinker", "__info_plist", "-Xlinker", plist], { encoding: "utf8" });
|
|
17840
|
+
if (build.status !== 0) return fail(`AEC build failed: ${build.stderr?.slice(0, 400)}`);
|
|
17841
|
+
const sign = spawnSync3("codesign", ["-fs", "-", tmp], { encoding: "utf8" });
|
|
17842
|
+
if (sign.status !== 0) return fail(`codesign failed: ${sign.stderr?.slice(0, 200)}`);
|
|
17843
|
+
try {
|
|
17844
|
+
renameSync(tmp, bin);
|
|
17845
|
+
} catch (e) {
|
|
17846
|
+
return fail(`AEC helper install failed: ${e instanceof Error ? e.message : e}`);
|
|
17648
17847
|
}
|
|
17649
17848
|
return bin;
|
|
17650
17849
|
}
|
|
@@ -17942,27 +18141,27 @@ function takeCut(v, forVoiceLine) {
|
|
|
17942
18141
|
const cut = v?.takeInterruptedReply() ?? null;
|
|
17943
18142
|
return splitCut(forVoiceLine ? cut : null);
|
|
17944
18143
|
}
|
|
17945
|
-
function bindOverlapInstinct(v, instinct,
|
|
18144
|
+
function bindOverlapInstinct(v, instinct, live2, decideMs = 900) {
|
|
17946
18145
|
const o = v.options;
|
|
17947
18146
|
const { onDiag } = o;
|
|
17948
18147
|
o.overlapDecideMs = decideMs;
|
|
17949
18148
|
instinct.options.overlapSettleMs = 0;
|
|
17950
18149
|
o.onDiag = (ev) => {
|
|
17951
18150
|
onDiag(ev);
|
|
17952
|
-
if (!
|
|
18151
|
+
if (!live2()) return;
|
|
17953
18152
|
if (ev.kind === "overlap_pause") void instinct.overlap(String(ev.text ?? ""));
|
|
17954
18153
|
else if (/^(?:barge_in|overlap_resume|overlap_end|interrupt|tts_turn_begin)$/.test(ev.kind)) instinct.overlapEnded();
|
|
17955
18154
|
};
|
|
17956
18155
|
Object.assign(instinct.options, {
|
|
17957
18156
|
onYield: () => {
|
|
17958
|
-
if (!
|
|
18157
|
+
if (!live2()) return false;
|
|
17959
18158
|
if (v.decideOverlap("yield")) return;
|
|
17960
18159
|
if (!v.audible) return false;
|
|
17961
18160
|
v.interrupt();
|
|
17962
18161
|
o.onBargeIn("speaking");
|
|
17963
18162
|
},
|
|
17964
18163
|
// `heard` = what Jev judged: the engine absorbs only those words — a reaction that grows past them is re-decided.
|
|
17965
|
-
onKeepTalking: (heard) =>
|
|
18164
|
+
onKeepTalking: (heard) => live2() ? v.decideOverlap("keep_talking", heard) : false
|
|
17966
18165
|
});
|
|
17967
18166
|
}
|
|
17968
18167
|
function bindAckInstinct(v, instinct) {
|
|
@@ -17980,7 +18179,7 @@ function bindAckInstinct(v, instinct) {
|
|
|
17980
18179
|
onDiag(ev);
|
|
17981
18180
|
};
|
|
17982
18181
|
}
|
|
17983
|
-
function bindSecondChannel(v, sc,
|
|
18182
|
+
function bindSecondChannel(v, sc, live2) {
|
|
17984
18183
|
const o = v.options;
|
|
17985
18184
|
const { onPartial, onUtterance, onState, onBargeIn } = o;
|
|
17986
18185
|
let own = false;
|
|
@@ -17991,15 +18190,15 @@ function bindSecondChannel(v, sc, live) {
|
|
|
17991
18190
|
return r.queued.length ? { ...r, full: "", heard: "" } : null;
|
|
17992
18191
|
};
|
|
17993
18192
|
o.onPartial = (t) => {
|
|
17994
|
-
if (
|
|
18193
|
+
if (live2() && (own || !v.audible)) sc.onInterim(t);
|
|
17995
18194
|
onPartial(t);
|
|
17996
18195
|
};
|
|
17997
18196
|
o.onUtterance = ((t, meta) => {
|
|
17998
|
-
if (
|
|
18197
|
+
if (live2() && t.trim()) sc.onUserTurn(t);
|
|
17999
18198
|
onUtterance(t, meta);
|
|
18000
18199
|
});
|
|
18001
18200
|
o.onState = (s) => {
|
|
18002
|
-
if (
|
|
18201
|
+
if (live2() && !own) {
|
|
18003
18202
|
if (s === "speaking") sc.onAgentState("first_audio");
|
|
18004
18203
|
else if (s === "listening") sc.onAgentState("idle");
|
|
18005
18204
|
}
|
|
@@ -18011,14 +18210,14 @@ function bindSecondChannel(v, sc, live) {
|
|
|
18011
18210
|
};
|
|
18012
18211
|
const speakDelta = v.speakDelta.bind(v);
|
|
18013
18212
|
v.speakDelta = ((t, ...rest) => {
|
|
18014
|
-
if (
|
|
18213
|
+
if (live2()) sc.noteReply(t);
|
|
18015
18214
|
return speakDelta(t, ...rest);
|
|
18016
18215
|
});
|
|
18017
18216
|
Object.defineProperty(sc.options, "aec", { get: () => v.usingAec, set: () => {
|
|
18018
18217
|
}, enumerable: true, configurable: true });
|
|
18019
18218
|
Object.assign(sc.options, {
|
|
18020
18219
|
speak: (text, kind) => {
|
|
18021
|
-
if (!
|
|
18220
|
+
if (!live2() || v.audible) return false;
|
|
18022
18221
|
if (kind === "backchannel") return speakBlip(v, text);
|
|
18023
18222
|
own = true;
|
|
18024
18223
|
v.speakFiller(text);
|
|
@@ -18028,7 +18227,7 @@ function bindSecondChannel(v, sc, live) {
|
|
|
18028
18227
|
}
|
|
18029
18228
|
});
|
|
18030
18229
|
}
|
|
18031
|
-
function bindVoiceCall(v, call,
|
|
18230
|
+
function bindVoiceCall(v, call, live2, decideMs = 900) {
|
|
18032
18231
|
const o = v.options;
|
|
18033
18232
|
const { onPartial, onState, onBargeIn, onDiag } = o;
|
|
18034
18233
|
let own = false;
|
|
@@ -18055,17 +18254,17 @@ function bindVoiceCall(v, call, live, decideMs = 900) {
|
|
|
18055
18254
|
v.takeInterruptedReply();
|
|
18056
18255
|
};
|
|
18057
18256
|
o.onPartial = (t) => {
|
|
18058
|
-
if (
|
|
18257
|
+
if (live2() && (own || !v.audible)) call.interim(t, performance.now(), v.usingAec);
|
|
18059
18258
|
onPartial(t);
|
|
18060
18259
|
};
|
|
18061
18260
|
o.onState = (s) => {
|
|
18062
|
-
if (
|
|
18261
|
+
if (live2() && !own && s === "speaking") call.main({ type: "audio" });
|
|
18063
18262
|
onState(s);
|
|
18064
18263
|
};
|
|
18065
18264
|
let filling = false;
|
|
18066
18265
|
const beginSpeech = v.beginSpeech.bind(v);
|
|
18067
18266
|
v.beginSpeech = ((...a) => {
|
|
18068
|
-
if (own && !filling &&
|
|
18267
|
+
if (own && !filling && live2()) {
|
|
18069
18268
|
own = false;
|
|
18070
18269
|
call.main({ type: "audio" }, v.player?.drainMs() ?? 0);
|
|
18071
18270
|
}
|
|
@@ -18073,16 +18272,16 @@ function bindVoiceCall(v, call, live, decideMs = 900) {
|
|
|
18073
18272
|
});
|
|
18074
18273
|
o.onBargeIn = (phase) => {
|
|
18075
18274
|
held2 = void 0;
|
|
18076
|
-
if (
|
|
18275
|
+
if (live2()) call.barge();
|
|
18077
18276
|
onBargeIn(phase);
|
|
18078
18277
|
};
|
|
18079
18278
|
o.overlapDecideMs = decideMs;
|
|
18080
18279
|
o.onDiag = (ev) => {
|
|
18081
18280
|
onDiag(ev);
|
|
18082
|
-
if (!
|
|
18281
|
+
if (!live2() || ev.kind !== "overlap_pause") return;
|
|
18083
18282
|
const heard = String(ev.text ?? "");
|
|
18084
18283
|
void call.overlap(heard).then((verdict) => {
|
|
18085
|
-
if (!
|
|
18284
|
+
if (!live2()) return;
|
|
18086
18285
|
if (verdict === "keep") v.decideOverlap("keep_talking", heard, call.aside(heard) ?? void 0);
|
|
18087
18286
|
else if (verdict === "cut") v.decideOverlap("yield", heard);
|
|
18088
18287
|
});
|
|
@@ -18090,7 +18289,7 @@ function bindVoiceCall(v, call, live, decideMs = 900) {
|
|
|
18090
18289
|
Object.defineProperty(call.fill.options, "aec", { get: () => v.usingAec, set: () => {
|
|
18091
18290
|
}, enumerable: true, configurable: true });
|
|
18092
18291
|
call.options.speak = (text, kind) => {
|
|
18093
|
-
if (!
|
|
18292
|
+
if (!live2() || v.audible) return false;
|
|
18094
18293
|
if (kind === "backchannel") return speakBlip(v, text);
|
|
18095
18294
|
own = true;
|
|
18096
18295
|
filling = true;
|
|
@@ -18562,14 +18761,14 @@ YOU PRESSED: ${s.pressed}` : ""}`).join("\n");
|
|
|
18562
18761
|
You placed this call and an automated phone menu is playing. What it said so far, oldest first:
|
|
18563
18762
|
${menu}
|
|
18564
18763
|
|
|
18565
|
-
Which key(s) do you press NOW for your task? Answer with only the keys (digits, * or #, e.g. "1" or "2#"), or WAIT when: the option for your task was not said yet, it is a greeting/recording/hold message, you already pressed for this same menu, or it asks
|
|
18764
|
+
Which key(s) do you press NOW for your task? Answer with only the keys (digits, * or #, e.g. "1" or "2#"), or WAIT when: the option for your task was not said yet, it is a greeting/recording/hold message, you already pressed for this same menu, or it asks you to type something (an ID, a code, a number) that is not written in your task above. Never guess or make up digits: an ID given in the task may be typed (with # when asked); a code the menu says it texted (SMS) is read for you: answer SMS (SMS# when it asks to end with #). After "wrong key"/"invalid choice", press the right menu key again.`;
|
|
18566
18765
|
}
|
|
18567
18766
|
/** "1", "2#", "WAIT", "Press 1." … → the keys, or '' (wait). */
|
|
18568
18767
|
static parse(raw) {
|
|
18569
18768
|
const t = raw.trim().replace(/^["'`]+|["'`.]+$/g, "");
|
|
18570
18769
|
if (/^wait\b/i.test(t)) return "";
|
|
18571
|
-
const m = t.match(/^(?:press\s*)?([0-9*#]{
|
|
18572
|
-
return m ? m[1] : "";
|
|
18770
|
+
const m = t.match(/^(?:press\s*)?((?:SMS)?[0-9*#]{0,12})$/i);
|
|
18771
|
+
return m && m[1] ? m[1].replace(/sms/i, "SMS") : "";
|
|
18573
18772
|
}
|
|
18574
18773
|
/** A menu line was heard: the keys to press now, or '' (wait). */
|
|
18575
18774
|
async hear(line) {
|
|
@@ -19108,7 +19307,7 @@ function formatDiff(ops, opts = {}) {
|
|
|
19108
19307
|
}
|
|
19109
19308
|
|
|
19110
19309
|
// cli/session.ts
|
|
19111
|
-
import { existsSync as existsSync6, mkdirSync as mkdirSync8, readFileSync as readFileSync8, writeFileSync as writeFileSync5, readdirSync, renameSync, symlinkSync as symlinkSync2, unlinkSync, readlinkSync, statSync as
|
|
19310
|
+
import { existsSync as existsSync6, mkdirSync as mkdirSync8, readFileSync as readFileSync8, writeFileSync as writeFileSync5, readdirSync, renameSync as renameSync2, symlinkSync as symlinkSync2, unlinkSync, readlinkSync, statSync as statSync6 } from "fs";
|
|
19112
19311
|
import { homedir as homedir6 } from "os";
|
|
19113
19312
|
import { join as join11 } from "path";
|
|
19114
19313
|
init_platform();
|
|
@@ -19164,7 +19363,7 @@ var SessionStore = class {
|
|
|
19164
19363
|
const path = join11(this.dir, `${data.meta.id}.json`);
|
|
19165
19364
|
const tmp = `${path}.${process.pid}.tmp`;
|
|
19166
19365
|
writeFileSync5(tmp, JSON.stringify(data));
|
|
19167
|
-
|
|
19366
|
+
renameSync2(tmp, path);
|
|
19168
19367
|
try {
|
|
19169
19368
|
const gd = globalDir();
|
|
19170
19369
|
if (!existsSync6(gd)) mkdirSync8(gd, { recursive: true });
|
|
@@ -19209,7 +19408,7 @@ var SessionStore = class {
|
|
|
19209
19408
|
for (const f of readdirSync(this.dir)) {
|
|
19210
19409
|
if (!f.endsWith(".json")) continue;
|
|
19211
19410
|
try {
|
|
19212
|
-
const st =
|
|
19411
|
+
const st = statSync6(join11(this.dir, f));
|
|
19213
19412
|
out.push({ id: f.slice(0, -5), mtime: st.mtimeMs, size: st.size });
|
|
19214
19413
|
} catch {
|
|
19215
19414
|
}
|
|
@@ -21975,8 +22174,8 @@ function makeRemoteTriggerTool(opts) {
|
|
|
21975
22174
|
if (!target) return `Error: no session matching '${id}' in the global index (~/.agent/sessions).`;
|
|
21976
22175
|
const full = target.meta.id;
|
|
21977
22176
|
if (opts.selfId && full === opts.selfId()) return "Error: that is THIS session \u2014 use Task/TaskBatch for self-delegation.";
|
|
21978
|
-
const
|
|
21979
|
-
if (
|
|
22177
|
+
const live2 = await triggerLive(full, { prompt: text, from: opts.selfId?.() }, dir);
|
|
22178
|
+
if (live2?.ok) return `Delivered to live session ${full} \u2014 it runs there; the user sees it in that terminal.`;
|
|
21980
22179
|
if (!target.meta.cwd || !existsSync8(target.meta.cwd)) return `Error: session ${full} has no reachable cwd (${target.meta.cwd ?? "unknown"}).`;
|
|
21981
22180
|
return new Promise((res) => {
|
|
21982
22181
|
const child = doSpawn(...headlessArgv(opts, text, full), {
|
|
@@ -22009,6 +22208,142 @@ ${answer || "(no output)"}` : `Error: headless run of ${full} exited ${code}: ${
|
|
|
22009
22208
|
};
|
|
22010
22209
|
}
|
|
22011
22210
|
|
|
22211
|
+
// cli/liveStatus.ts
|
|
22212
|
+
import { mkdirSync as mkdirSync12, renameSync as renameSync3, writeFileSync as writeFileSync9 } from "fs";
|
|
22213
|
+
import { homedir as homedir10 } from "os";
|
|
22214
|
+
import { join as join16 } from "path";
|
|
22215
|
+
var log47 = forComponent("live-status");
|
|
22216
|
+
var LiveStatusOptions = class {
|
|
22217
|
+
dir = join16(homedir10(), ".agent", "live");
|
|
22218
|
+
pid = process.pid;
|
|
22219
|
+
cwd = process.cwd();
|
|
22220
|
+
model = () => void 0;
|
|
22221
|
+
jobs = () => void 0;
|
|
22222
|
+
now = () => Date.now();
|
|
22223
|
+
};
|
|
22224
|
+
var LiveStatus = class {
|
|
22225
|
+
options;
|
|
22226
|
+
state = "idle";
|
|
22227
|
+
detail;
|
|
22228
|
+
sessionId;
|
|
22229
|
+
prompts = 0;
|
|
22230
|
+
denied;
|
|
22231
|
+
turns = 0;
|
|
22232
|
+
// turns in flight
|
|
22233
|
+
holds = 0;
|
|
22234
|
+
// open dispatch regions
|
|
22235
|
+
waits = 0;
|
|
22236
|
+
constructor(options) {
|
|
22237
|
+
this.options = { ...new LiveStatusOptions(), ...options };
|
|
22238
|
+
}
|
|
22239
|
+
get file() {
|
|
22240
|
+
return join16(this.options.dir, `${this.options.pid}.json`);
|
|
22241
|
+
}
|
|
22242
|
+
/** A turn, a dispatch region or a human wait is open (the REPL is not at rest). */
|
|
22243
|
+
get busy() {
|
|
22244
|
+
return this.turns > 0 || this.holds > 0 || this.waits > 0;
|
|
22245
|
+
}
|
|
22246
|
+
/** Session started or its id changed (/resume, /clear). */
|
|
22247
|
+
session(id) {
|
|
22248
|
+
this.sessionId = id;
|
|
22249
|
+
this.write();
|
|
22250
|
+
}
|
|
22251
|
+
/** A dispatch region opens: no `idle` until it closes. */
|
|
22252
|
+
hold() {
|
|
22253
|
+
this.holds++;
|
|
22254
|
+
}
|
|
22255
|
+
release() {
|
|
22256
|
+
this.holds = Math.max(0, this.holds - 1);
|
|
22257
|
+
this.settle();
|
|
22258
|
+
}
|
|
22259
|
+
/** A model turn starts. `machine` = not a human prompt (trigger / job wake / schedule): not counted. */
|
|
22260
|
+
turnStart(o = {}) {
|
|
22261
|
+
this.turns++;
|
|
22262
|
+
if (!o.machine) this.prompts++;
|
|
22263
|
+
this.denied = void 0;
|
|
22264
|
+
this.set("running", o.detail);
|
|
22265
|
+
}
|
|
22266
|
+
turnEnd() {
|
|
22267
|
+
this.turns = Math.max(0, this.turns - 1);
|
|
22268
|
+
this.settle();
|
|
22269
|
+
}
|
|
22270
|
+
/** A human wait (question, permission, confirm). Returns the release: back to running (or idle when nothing runs). */
|
|
22271
|
+
waiting(detail) {
|
|
22272
|
+
const prev = this.state === "waiting" ? void 0 : this.state;
|
|
22273
|
+
this.waits++;
|
|
22274
|
+
this.set("waiting", detail);
|
|
22275
|
+
let done = false;
|
|
22276
|
+
return () => {
|
|
22277
|
+
if (done) return;
|
|
22278
|
+
done = true;
|
|
22279
|
+
this.waits--;
|
|
22280
|
+
if (this.state === "exited" || this.waits > 0) return;
|
|
22281
|
+
this.set(this.turns > 0 ? "running" : prev ?? "idle");
|
|
22282
|
+
this.settle();
|
|
22283
|
+
};
|
|
22284
|
+
}
|
|
22285
|
+
/** Wrap a human wait. */
|
|
22286
|
+
async wait(detail, fn) {
|
|
22287
|
+
const end = this.waiting(detail);
|
|
22288
|
+
try {
|
|
22289
|
+
return await fn();
|
|
22290
|
+
} finally {
|
|
22291
|
+
end();
|
|
22292
|
+
}
|
|
22293
|
+
}
|
|
22294
|
+
/** The permission policy refused a tool: recorded on the current state until the next turn starts. */
|
|
22295
|
+
deny(d) {
|
|
22296
|
+
this.denied = d;
|
|
22297
|
+
this.write();
|
|
22298
|
+
}
|
|
22299
|
+
exited(detail) {
|
|
22300
|
+
if (this.state === "exited") return;
|
|
22301
|
+
this.set("exited", detail);
|
|
22302
|
+
}
|
|
22303
|
+
snapshot() {
|
|
22304
|
+
const jobs = this.options.jobs();
|
|
22305
|
+
return {
|
|
22306
|
+
state: this.state,
|
|
22307
|
+
...this.detail ? { detail: this.detail } : {},
|
|
22308
|
+
pid: this.options.pid,
|
|
22309
|
+
...this.sessionId ? { sessionId: this.sessionId } : {},
|
|
22310
|
+
cwd: this.options.cwd,
|
|
22311
|
+
...this.options.model() ? { model: this.options.model() } : {},
|
|
22312
|
+
prompts: this.prompts,
|
|
22313
|
+
...jobs !== void 0 ? { jobs } : {},
|
|
22314
|
+
...this.denied ? { denied: this.denied } : {},
|
|
22315
|
+
at: this.options.now()
|
|
22316
|
+
};
|
|
22317
|
+
}
|
|
22318
|
+
settle() {
|
|
22319
|
+
if (this.state === "exited" || this.turns > 0 || this.holds > 0 || this.waits > 0) return;
|
|
22320
|
+
if (this.state !== "idle") this.set("idle");
|
|
22321
|
+
}
|
|
22322
|
+
set(state, detail) {
|
|
22323
|
+
if (this.state === "exited") return;
|
|
22324
|
+
this.state = state;
|
|
22325
|
+
this.detail = detail;
|
|
22326
|
+
this.write();
|
|
22327
|
+
}
|
|
22328
|
+
write() {
|
|
22329
|
+
try {
|
|
22330
|
+
mkdirSync12(this.options.dir, { recursive: true, mode: 448 });
|
|
22331
|
+
const tmp = `${this.file}.${process.pid}.tmp`;
|
|
22332
|
+
writeFileSync9(tmp, JSON.stringify(this.snapshot()) + "\n");
|
|
22333
|
+
renameSync3(tmp, this.file);
|
|
22334
|
+
} catch (e) {
|
|
22335
|
+
log47.debug("live status write failed", e);
|
|
22336
|
+
}
|
|
22337
|
+
}
|
|
22338
|
+
};
|
|
22339
|
+
var live;
|
|
22340
|
+
function setLive(s) {
|
|
22341
|
+
live = s;
|
|
22342
|
+
}
|
|
22343
|
+
function liveWait(detail, fn) {
|
|
22344
|
+
return live ? live.wait(detail, fn) : fn();
|
|
22345
|
+
}
|
|
22346
|
+
|
|
22012
22347
|
// cli/cli.ts
|
|
22013
22348
|
var forceColor = process.env.FORCE_COLOR != null && process.env.FORCE_COLOR !== "" && process.env.FORCE_COLOR !== "0";
|
|
22014
22349
|
var useColor = forceColor || !process.env.NO_COLOR && !!process.stdout.isTTY && !!process.stderr.isTTY;
|
|
@@ -22025,7 +22360,7 @@ var strike = C("9");
|
|
|
22025
22360
|
var link = (text, url) => useColor ? `\x1B]8;;${url}\x1B\\${cyan(text)}\x1B]8;;\x1B\\` : `${text} (${url})`;
|
|
22026
22361
|
var mdPalette = { bold, dim, cyan, italic, strike, green, link };
|
|
22027
22362
|
var err = (s) => process.stderr.write(s);
|
|
22028
|
-
var
|
|
22363
|
+
var log48 = forComponent("cli");
|
|
22029
22364
|
var VERSION = (() => {
|
|
22030
22365
|
try {
|
|
22031
22366
|
return JSON.parse(readFileSync10(new URL("../package.json", import.meta.url), "utf8")).version ?? "?";
|
|
@@ -22151,7 +22486,12 @@ function parseArgs(argv) {
|
|
|
22151
22486
|
else if (x === "--plan") a.plan = true;
|
|
22152
22487
|
else if (x === "--ask") a.ask = true;
|
|
22153
22488
|
else if (x === "--yes" || x === "-y") a.yes = true;
|
|
22154
|
-
else if (x === "--
|
|
22489
|
+
else if (x === "--trust") a.trust = true;
|
|
22490
|
+
else if (x === "--prompt") {
|
|
22491
|
+
a.prompt = argv.slice(i + 1).join(" ").trim();
|
|
22492
|
+
if (!a.prompt) throw new Error("--prompt requires a value (and must be the last argument)");
|
|
22493
|
+
break;
|
|
22494
|
+
} else if (x === "--vfs" || x === "--sandbox") a.vfs = true;
|
|
22155
22495
|
else if (x === "--scratch") a.scratch = true;
|
|
22156
22496
|
else if (x === "--no-scratch") a.scratch = false;
|
|
22157
22497
|
else if (x === "--update") a.update = true;
|
|
@@ -22236,6 +22576,7 @@ function parseArgs(argv) {
|
|
|
22236
22576
|
if (a.boddb && a.vfs) throw new Error("--boddb and --sandbox are mutually exclusive (both are non-disk filesystems; pick one)");
|
|
22237
22577
|
if (a.seed && !a.boddb) throw new Error("--seed only applies with --boddb (it seeds the database from cwd on first run)");
|
|
22238
22578
|
if (a.worktree && (a.vfs || a.boddb)) throw new Error("--worktree is a real-disk concept \u2014 incompatible with --vfs/--boddb");
|
|
22579
|
+
if (a.prompt !== void 0 && (a.task || a.print)) throw new Error("--prompt seeds an interactive session \u2014 drop the task/-p (a task runs one-shot and exits)");
|
|
22239
22580
|
if (a.duplex && (a.task || a.print)) throw new Error("--duplex is interactive-only (a conversational mode) \u2014 drop the task/-p");
|
|
22240
22581
|
if (a.inputFormat && (!a.duplex && !a.print && !a.channelOnly || a.outputFormat !== "stream-json")) throw new Error("--input-format stream-json needs --output-format stream-json and --duplex (or --voice), --channel-only or -p");
|
|
22241
22582
|
if (a.keepAlive && (!a.print || !a.inputFormat)) throw new Error("--keep-alive needs -p --input-format stream-json --output-format stream-json");
|
|
@@ -22289,6 +22630,8 @@ Flags:
|
|
|
22289
22630
|
--ask confirm each mutating tool (bash/Shell/Write/Edit/\u2026) \u2014 needs a terminal to
|
|
22290
22631
|
approve on; rejected up front when detached (use --yes / permissions rules)
|
|
22291
22632
|
--yes, -y auto-approve mutating tools (no prompts) \u2014 for trusted/unattended runs
|
|
22633
|
+
--trust trust this directory without asking (permission prompts unchanged)
|
|
22634
|
+
--prompt <text> start the REPL with this line typed in (/slash and /skill expand), stay open \u2014 LAST arg: the rest of argv is the text
|
|
22292
22635
|
--update check for updates and install if available (no keys needed)
|
|
22293
22636
|
--no-update-check skip the automatic update check on startup
|
|
22294
22637
|
--verbose, --debug verbose logs (sets DEBUG=* \u2014 tool args, hook decisions, retries)
|
|
@@ -22440,10 +22783,10 @@ function loadEnvFile(file) {
|
|
|
22440
22783
|
}
|
|
22441
22784
|
function loadInstallEnv() {
|
|
22442
22785
|
let dir = dirname6(import.meta.path);
|
|
22443
|
-
for (let i = 0; i < 5 && !existsSync9(
|
|
22786
|
+
for (let i = 0; i < 5 && !existsSync9(join17(dir, "package.json")); i++) dir = dirname6(dir);
|
|
22444
22787
|
for (const name of [".env", ".env.local"]) {
|
|
22445
|
-
loadEnvFile(
|
|
22446
|
-
loadEnvFile(
|
|
22788
|
+
loadEnvFile(join17(dir, name));
|
|
22789
|
+
loadEnvFile(join17(homedir11(), ".agent", name));
|
|
22447
22790
|
}
|
|
22448
22791
|
}
|
|
22449
22792
|
function paraVaultToken() {
|
|
@@ -22482,20 +22825,19 @@ function apiKeysFromEnv() {
|
|
|
22482
22825
|
}
|
|
22483
22826
|
return keys;
|
|
22484
22827
|
}
|
|
22485
|
-
var KEYLESS_PROVIDERS = /* @__PURE__ */ new Set(["claude-code"]);
|
|
22486
22828
|
function modelUsable(model, apiKeys) {
|
|
22487
22829
|
const p = model.split("/")[0];
|
|
22488
|
-
return
|
|
22830
|
+
return isKeyless(p) || !!apiKeys[p];
|
|
22489
22831
|
}
|
|
22490
22832
|
function duplexModels(o) {
|
|
22491
22833
|
const dflt = new DuplexAgentOptions(), notes = [];
|
|
22492
|
-
const cc = o.actModel
|
|
22834
|
+
const cc = isClaudeCode(o.actModel), anthropic = !!o.apiKeys.anthropic;
|
|
22493
22835
|
const why = (m) => `no ${m.split("/")[0].toUpperCase()}_API_KEY`;
|
|
22494
22836
|
const asked = o.voiceModel ?? o.reflexModel;
|
|
22495
22837
|
let reflexModel = asked ? resolveModelOrNewest(asked) : void 0;
|
|
22496
22838
|
const reflex = reflexModel ?? dflt.reflexModel;
|
|
22497
22839
|
if (!modelUsable(reflex, o.apiKeys)) {
|
|
22498
|
-
const to = anthropic ? latestClaude("haiku") : cc ? "claude-code/haiku" : o.actModel
|
|
22840
|
+
const to = anthropic ? latestClaude("haiku") : cc ? "claude-code/haiku" : isCursor(o.actModel) ? void 0 : o.actModel;
|
|
22499
22841
|
if (to) reflexModel = to;
|
|
22500
22842
|
notes.push(`voice model ${reflex} can't run here (${why(reflex)})${to ? ` \u2014 using ${to}` : ""}`);
|
|
22501
22843
|
}
|
|
@@ -22626,14 +22968,16 @@ function makeHost(format = "text", opts) {
|
|
|
22626
22968
|
`));
|
|
22627
22969
|
},
|
|
22628
22970
|
async confirm(prompt) {
|
|
22629
|
-
|
|
22630
|
-
|
|
22631
|
-
|
|
22632
|
-
|
|
22633
|
-
|
|
22634
|
-
|
|
22635
|
-
|
|
22636
|
-
|
|
22971
|
+
return liveWait(`confirm: ${prompt}`, async () => {
|
|
22972
|
+
const v = await selectMenu(process.stderr, { title: `? ${prompt}`, items: [{ label: "Yes", value: "y" }, { label: "No", value: "n" }], current: "n" });
|
|
22973
|
+
if (v !== null) return v === "y";
|
|
22974
|
+
const io = createInterface({ input: keyInput, output: process.stderr });
|
|
22975
|
+
try {
|
|
22976
|
+
return /^y(es)?$/i.test((await io.question(yellow(` ? ${prompt} [y/N] `))).trim());
|
|
22977
|
+
} finally {
|
|
22978
|
+
io.close();
|
|
22979
|
+
}
|
|
22980
|
+
});
|
|
22637
22981
|
},
|
|
22638
22982
|
// Only offer `ask` when a human can actually SEE the prompt. Headless/piped (`-p`, redirected,
|
|
22639
22983
|
// no TTY) → omit it: AskUserQuestion then parks the question and ends the run with
|
|
@@ -22644,18 +22988,20 @@ function makeHost(format = "text", opts) {
|
|
|
22644
22988
|
async ask(q2) {
|
|
22645
22989
|
const title = `? ${q2.header ? "[" + q2.header + "] " : ""}${q2.question}`;
|
|
22646
22990
|
spinner.stop();
|
|
22647
|
-
|
|
22648
|
-
|
|
22649
|
-
|
|
22650
|
-
|
|
22651
|
-
|
|
22652
|
-
|
|
22653
|
-
|
|
22654
|
-
|
|
22655
|
-
|
|
22656
|
-
|
|
22657
|
-
|
|
22658
|
-
|
|
22991
|
+
return liveWait(`question: ${q2.question}`, async () => {
|
|
22992
|
+
const v = await selectMenu(process.stderr, { title, items: q2.options.map((o) => ({ label: o.label, value: o.label, desc: o.description })) });
|
|
22993
|
+
if (v !== null) return v;
|
|
22994
|
+
const io = createInterface({ input: keyInput, output: process.stderr });
|
|
22995
|
+
try {
|
|
22996
|
+
const lines = [yellow(" " + title)];
|
|
22997
|
+
q2.options.forEach((o, i) => lines.push(` ${i + 1}) ${o.label}${o.description ? dim(" \u2014 " + o.description) : ""}`));
|
|
22998
|
+
const ans = (await io.question(lines.join("\n") + "\n > ")).trim();
|
|
22999
|
+
const n = Number(ans);
|
|
23000
|
+
return Number.isInteger(n) && q2.options[n - 1] ? q2.options[n - 1].label : ans;
|
|
23001
|
+
} finally {
|
|
23002
|
+
io.close();
|
|
23003
|
+
}
|
|
23004
|
+
});
|
|
22659
23005
|
}
|
|
22660
23006
|
} : {}
|
|
22661
23007
|
};
|
|
@@ -22942,10 +23288,10 @@ function autoRouteSend(args, agent, session, pof) {
|
|
|
22942
23288
|
};
|
|
22943
23289
|
}
|
|
22944
23290
|
function turnCost(model, usage) {
|
|
22945
|
-
const priced = model
|
|
23291
|
+
const priced = isClaudeCode(model) ? `anthropic/${resolveModelAlias(model.slice("claude-code/".length))}` : model;
|
|
22946
23292
|
return costOf(getModelInfo(priced)?.pricing, usage?.promptTokens ?? 0, usage?.completionTokens ?? 0, usage?.cacheCreationTokens ?? 0, usage?.cacheReadTokens ?? 0, priced);
|
|
22947
23293
|
}
|
|
22948
|
-
async function evaluateGoal(ai, condition, transcript,
|
|
23294
|
+
async function evaluateGoal(ai, condition, transcript, log49) {
|
|
22949
23295
|
const recent = transcript.filter((m) => m.role === "assistant").slice(-8).map((m) => {
|
|
22950
23296
|
const text = typeof m.content === "string" ? m.content : m.content.filter((p) => p.type === "text").map((p) => p.text).join(" ");
|
|
22951
23297
|
return text.slice(0, 600);
|
|
@@ -22965,7 +23311,7 @@ ${recent}` }
|
|
|
22965
23311
|
const match = r.content.match(/\{[\s\S]*\}/);
|
|
22966
23312
|
if (match) return JSON.parse(match[0]);
|
|
22967
23313
|
} catch (e) {
|
|
22968
|
-
|
|
23314
|
+
log49(dim(` (goal evaluator error: ${e?.message ?? e})
|
|
22969
23315
|
`));
|
|
22970
23316
|
}
|
|
22971
23317
|
return { met: false, reason: "evaluation unclear" };
|
|
@@ -23035,7 +23381,12 @@ function resolvePermMode(args, interactiveCapable) {
|
|
|
23035
23381
|
if (interactiveCapable && args.outputFormat === "text") return { gate: "ask" };
|
|
23036
23382
|
return { gate: "allow", notice: "unattended: mutating tools auto-approved \u2014 pass --ask to gate, --vfs to sandbox, --yes to silence" };
|
|
23037
23383
|
}
|
|
23384
|
+
var liveDeny = (call, reason) => live?.deny({ tool: call.name, what: summarizeCall(call.name, call.args).slice(0, 120), reason });
|
|
23038
23385
|
function makeAskResolver(cwd) {
|
|
23386
|
+
const resolve1 = askResolver(cwd);
|
|
23387
|
+
return (call) => canPrompt ? liveWait(`permission: ${call.name}`, () => resolve1(call)) : resolve1(call);
|
|
23388
|
+
}
|
|
23389
|
+
function askResolver(cwd) {
|
|
23039
23390
|
return async (call) => {
|
|
23040
23391
|
if (!canPrompt) {
|
|
23041
23392
|
err(dim(` \u26A0 ${call.name} needs approval but no terminal is attached \u2014 denied. Use --yes, or an allow rule in .agent/permissions.json.
|
|
@@ -23116,7 +23467,7 @@ function optsFor(args, ai, cfg = {}, extraTools = []) {
|
|
|
23116
23467
|
stream: args.stream,
|
|
23117
23468
|
host: makeHost(args.outputFormat, { stream: true }),
|
|
23118
23469
|
planMode: args.plan || cfg.planMode || false,
|
|
23119
|
-
permissions: rules.length || args.onlyTools ? new PermissionPolicy({ rules, default: args.onlyTools ? "deny" : "allow", host: makeHost(), ask: makeAskResolver(resolve5(args.cwd ?? process.cwd())) }) : void 0,
|
|
23470
|
+
permissions: rules.length || args.onlyTools ? new PermissionPolicy({ rules, default: args.onlyTools ? "deny" : "allow", host: makeHost(), ask: makeAskResolver(resolve5(args.cwd ?? process.cwd())), onDeny: liveDeny }) : void 0,
|
|
23120
23471
|
subagents: args.subagents || cfg.subagents || false,
|
|
23121
23472
|
maxSteps: args.maxSteps ?? cfg.maxSteps,
|
|
23122
23473
|
reasoning: args.reasoning ?? cfg.reasoning,
|
|
@@ -23194,13 +23545,13 @@ function mcpAgentTools(mounted, opts) {
|
|
|
23194
23545
|
return tools;
|
|
23195
23546
|
}
|
|
23196
23547
|
async function closeMcp(mounted) {
|
|
23197
|
-
await Promise.all(mounted.map((m) => m.client.close().catch((e) =>
|
|
23548
|
+
await Promise.all(mounted.map((m) => m.client.close().catch((e) => log48.debug("mcp close failed", e))));
|
|
23198
23549
|
}
|
|
23199
23550
|
var IMG_EXT = { ".png": "image/png", ".jpg": "image/jpeg", ".jpeg": "image/jpeg", ".gif": "image/gif", ".webp": "image/webp" };
|
|
23200
23551
|
function mentionRefs(line) {
|
|
23201
23552
|
return [...line.matchAll(/(?:^|\s)@(?:"([^"]+)"|(\S+))/g)].map((m) => m[1] ?? m[2].replace(/[?!.,;:)\]}'">]+$/, "")).filter(Boolean);
|
|
23202
23553
|
}
|
|
23203
|
-
var untilde = (p) => p.startsWith("~/") || IS_WIN && p.startsWith("~\\") ?
|
|
23554
|
+
var untilde = (p) => p.startsWith("~/") || IS_WIN && p.startsWith("~\\") ? join17(homedir11(), p.slice(2)) : p;
|
|
23204
23555
|
var PATH_LIKE = IS_WIN ? /^(\/|~[\\/]|\.\.?[\\/]|[A-Za-z]:[\\/]|\\\\)/ : /^(\/|~\/|\.\/|\.\.\/)/;
|
|
23205
23556
|
var userPath = (cwd, p) => {
|
|
23206
23557
|
const t = untilde(p);
|
|
@@ -23216,7 +23567,7 @@ function readImageParts(cwd, line) {
|
|
|
23216
23567
|
if (!mime) continue;
|
|
23217
23568
|
const abs = userPath(cwd, ref);
|
|
23218
23569
|
try {
|
|
23219
|
-
|
|
23570
|
+
statSync7(abs);
|
|
23220
23571
|
} catch {
|
|
23221
23572
|
continue;
|
|
23222
23573
|
}
|
|
@@ -23232,7 +23583,7 @@ function pastePathClassifier(cwd) {
|
|
|
23232
23583
|
if (!PATH_LIKE.test(t)) return null;
|
|
23233
23584
|
const abs = userPath(cwd, t);
|
|
23234
23585
|
try {
|
|
23235
|
-
if (!
|
|
23586
|
+
if (!statSync7(abs).isFile()) return null;
|
|
23236
23587
|
} catch {
|
|
23237
23588
|
return null;
|
|
23238
23589
|
}
|
|
@@ -23253,7 +23604,7 @@ async function expandMentions(fs, line) {
|
|
|
23253
23604
|
if (loaded.includes(ref) || missing.includes(ref)) continue;
|
|
23254
23605
|
if (ref.includes(":") && mcpMentionResolver) {
|
|
23255
23606
|
const body = await mcpMentionResolver(ref).catch((e) => {
|
|
23256
|
-
|
|
23607
|
+
log48.debug("mcp mention resolve failed", e);
|
|
23257
23608
|
return null;
|
|
23258
23609
|
});
|
|
23259
23610
|
if (body != null) {
|
|
@@ -23279,7 +23630,7 @@ ${await fs.readFile(path)}`);
|
|
|
23279
23630
|
${blocks.join("\n\n")}` : line, loaded, missing };
|
|
23280
23631
|
}
|
|
23281
23632
|
function applyTurnMode(agent, session, task, flags = {}, onModel) {
|
|
23282
|
-
const p = parseDirectives(task, { strict: true, keys: ["model", "turns", "delegate", "advisor", "mode"], warn: (m) =>
|
|
23633
|
+
const p = parseDirectives(task, { strict: true, keys: ["model", "turns", "delegate", "advisor", "mode"], warn: (m) => log48.debug(m) });
|
|
23283
23634
|
const d = p.directives, isMode = !!(d.delegate || d.advisor || d.modeOff);
|
|
23284
23635
|
if (p.unresolvedModel && /->|<-|delegate:|advisor:/.test(task.slice(0, task.length - p.prompt.length))) {
|
|
23285
23636
|
err(red(` \u2717 unknown model "${p.unresolvedModel}"${p.ambiguous ? ` (could be: ${p.ambiguous.join(", ")})` : ""} \u2014 turn not sent
|
|
@@ -23372,7 +23723,7 @@ async function runTurn(agent, store, session, task, cp, cwd = process.cwd(), sen
|
|
|
23372
23723
|
try {
|
|
23373
23724
|
store.save(session);
|
|
23374
23725
|
} catch (ex) {
|
|
23375
|
-
|
|
23726
|
+
log48.debug("mid-turn session flush failed", ex);
|
|
23376
23727
|
}
|
|
23377
23728
|
}
|
|
23378
23729
|
return origNotify(e);
|
|
@@ -23455,7 +23806,7 @@ function bindClaudeCodeSession(agent, session) {
|
|
|
23455
23806
|
session.meta.cc = ok && id ? { id, n: agent.transcript.length, model } : void 0;
|
|
23456
23807
|
};
|
|
23457
23808
|
}
|
|
23458
|
-
var remintSessionImages = (data, store, cwd) => remintImageRefs(data.messages, [
|
|
23809
|
+
var remintSessionImages = (data, store, cwd) => remintImageRefs(data.messages, [join17(store.dir, `${data.meta.id}.images`), cwd]);
|
|
23459
23810
|
function startSession(args, store, agent, cwd) {
|
|
23460
23811
|
if (args.resume || args.cont) {
|
|
23461
23812
|
const data = args.resume ? store.load(args.resume) ?? globalSessionLoad(args.resume) : store.latestData();
|
|
@@ -23502,25 +23853,25 @@ var AGENTS_MD_TEMPLATE = `# ${"${name}"}
|
|
|
23502
23853
|
`;
|
|
23503
23854
|
function initInstructions(cwd) {
|
|
23504
23855
|
for (const f of ["AGENTS.md", "CLAUDE.md"]) {
|
|
23505
|
-
if (existsSync9(
|
|
23856
|
+
if (existsSync9(join17(cwd, f))) {
|
|
23506
23857
|
err(yellow(` ${f} already exists \u2014 leaving it as-is
|
|
23507
23858
|
`));
|
|
23508
23859
|
return;
|
|
23509
23860
|
}
|
|
23510
23861
|
}
|
|
23511
|
-
const path =
|
|
23512
|
-
|
|
23862
|
+
const path = join17(cwd, "AGENTS.md");
|
|
23863
|
+
writeFileSync10(path, AGENTS_MD_TEMPLATE.replace("${name}", basename4(cwd)));
|
|
23513
23864
|
err(green(` created ${path}
|
|
23514
23865
|
`) + dim(" edit it, then it auto-loads into every run.\n"));
|
|
23515
23866
|
}
|
|
23516
23867
|
function persistSetting(cwd, key, value) {
|
|
23517
|
-
const path =
|
|
23868
|
+
const path = join17(cwd, ".agent", "settings.json");
|
|
23518
23869
|
try {
|
|
23519
23870
|
const obj = existsSync9(path) ? JSON.parse(readFileSync10(path, "utf8")) : {};
|
|
23520
23871
|
if (obj[key] === value) return;
|
|
23521
23872
|
obj[key] = value;
|
|
23522
|
-
|
|
23523
|
-
|
|
23873
|
+
mkdirSync13(dirname6(path), { recursive: true });
|
|
23874
|
+
writeFileSync10(path, JSON.stringify(obj, null, 2) + "\n");
|
|
23524
23875
|
} catch (e) {
|
|
23525
23876
|
err(yellow(` \u26A0 couldn't persist ${key} to ${path} \u2014 ${e?.message ?? e}
|
|
23526
23877
|
`));
|
|
@@ -23536,23 +23887,24 @@ var isCancelTeardown = (e) => {
|
|
|
23536
23887
|
function installCancelGuards(mounted) {
|
|
23537
23888
|
process.on("unhandledRejection", (e) => {
|
|
23538
23889
|
if (isCancelTeardown(e)) {
|
|
23539
|
-
|
|
23890
|
+
log48.debug("suppressed unhandledRejection (cursor stream cancel)", e);
|
|
23540
23891
|
return;
|
|
23541
23892
|
}
|
|
23542
|
-
|
|
23893
|
+
log48.error("unhandledRejection", e);
|
|
23543
23894
|
});
|
|
23544
23895
|
process.on("uncaughtException", (e) => {
|
|
23545
23896
|
if (isCancelTeardown(e)) {
|
|
23546
|
-
|
|
23897
|
+
log48.debug("suppressed uncaughtException (cursor stream cancel)", e);
|
|
23547
23898
|
return;
|
|
23548
23899
|
}
|
|
23549
23900
|
console.error(e);
|
|
23901
|
+
live?.exited("crash");
|
|
23550
23902
|
void closeMcp(mounted);
|
|
23551
23903
|
process.exit(1);
|
|
23552
23904
|
});
|
|
23553
23905
|
}
|
|
23554
23906
|
async function repl(args, ai, cfg, cwd) {
|
|
23555
|
-
const oauth = new McpOAuth({ storePath:
|
|
23907
|
+
const oauth = new McpOAuth({ storePath: join17(cwd, ".agent", "mcp-auth.json") });
|
|
23556
23908
|
const mounted = await mountMcp(cfg, oauth);
|
|
23557
23909
|
let mcpToolNames = [];
|
|
23558
23910
|
const initialMcpTools = mcpAgentTools(mounted);
|
|
@@ -23662,11 +24014,11 @@ async function repl(args, ai, cfg, cwd) {
|
|
|
23662
24014
|
const hint = summarizeCall(call2.name, call2.args).slice(0, 80);
|
|
23663
24015
|
if (cfg.voiceAskUi !== "relay") {
|
|
23664
24016
|
editorRef?.suspend();
|
|
23665
|
-
const v = await selectMenu(process.stderr, {
|
|
24017
|
+
const v = await liveWait(`permission: ${call2.name}`, () => selectMenu(process.stderr, {
|
|
23666
24018
|
title: `? background worker asks to run ${call2.name} ${hint}`,
|
|
23667
24019
|
items: [{ label: "Allow once", value: "y" }, { label: "Allow always", value: "a" }, { label: "Deny", value: "n" }],
|
|
23668
24020
|
current: "y"
|
|
23669
|
-
});
|
|
24021
|
+
}));
|
|
23670
24022
|
editorRef?.resume();
|
|
23671
24023
|
editorRef?.redrawNow();
|
|
23672
24024
|
if (v === "a") {
|
|
@@ -23827,14 +24179,14 @@ async function repl(args, ai, cfg, cwd) {
|
|
|
23827
24179
|
onTaskStart: async (_id, label) => {
|
|
23828
24180
|
await checkpoints.begin(label);
|
|
23829
24181
|
},
|
|
23830
|
-
lookRoots: [
|
|
24182
|
+
lookRoots: [homedir11(), join17(homedir11(), "Documents")],
|
|
23831
24183
|
// QuickLook: a spoken "Projects/X" usually means ~/Documents/Projects/X
|
|
23832
24184
|
// The jail deny-lists .git/** (VCS internals can carry credentials), so the engine's fs-based
|
|
23833
24185
|
// 'branch' lookup can't see it — supply it host-side (one safe read-only file).
|
|
23834
24186
|
quickLook: {
|
|
23835
24187
|
branch: () => {
|
|
23836
24188
|
try {
|
|
23837
|
-
const head = readFileSync10(
|
|
24189
|
+
const head = readFileSync10(join17(cwd, ".git", "HEAD"), "utf8").trim();
|
|
23838
24190
|
return head.startsWith("ref: refs/heads/") ? `branch: ${head.slice("ref: refs/heads/".length)}` : `detached HEAD at ${head.slice(0, 12)}`;
|
|
23839
24191
|
} catch {
|
|
23840
24192
|
return "not a git repository";
|
|
@@ -23963,7 +24315,7 @@ ${SPOKEN_TURN}`, { id });
|
|
|
23963
24315
|
editorRef?.abort();
|
|
23964
24316
|
}
|
|
23965
24317
|
} catch (e) {
|
|
23966
|
-
|
|
24318
|
+
log48.error("call turn failed", e);
|
|
23967
24319
|
} finally {
|
|
23968
24320
|
rec.running = false;
|
|
23969
24321
|
call?.main({ type: "done", id });
|
|
@@ -24025,7 +24377,7 @@ ${SPOKEN_TURN}`, { id });
|
|
|
24025
24377
|
const applyPosture = (p) => {
|
|
24026
24378
|
posture = p;
|
|
24027
24379
|
const ask = p === "acceptEdits" ? askFor(["bash", "Shell"]) : askFor(ASK_MUTATING);
|
|
24028
|
-
work.permissions = new PermissionPolicy({ rules: [...baseRules(), ...ask], default: "allow", host: duplex ? void 0 : makeHost(), ask: duplex ? duplexAsk : makeAskResolver(cwd) });
|
|
24380
|
+
work.permissions = new PermissionPolicy({ rules: [...baseRules(), ...ask], default: "allow", host: duplex ? void 0 : makeHost(), ask: duplex ? duplexAsk : makeAskResolver(cwd), onDeny: liveDeny });
|
|
24029
24381
|
if (!duplex) {
|
|
24030
24382
|
agent.options.planMode = p === "plan";
|
|
24031
24383
|
agent.reprepare();
|
|
@@ -24113,16 +24465,17 @@ ${SPOKEN_TURN}`, { id });
|
|
|
24113
24465
|
const pendingImages = [];
|
|
24114
24466
|
const bangContext = [];
|
|
24115
24467
|
const grabClipboardAttachment = () => {
|
|
24116
|
-
const dir =
|
|
24468
|
+
const dir = join17(store.dir, `${session.meta.id}.images`);
|
|
24117
24469
|
try {
|
|
24118
|
-
|
|
24470
|
+
mkdirSync13(dir, { recursive: true });
|
|
24119
24471
|
} catch (e) {
|
|
24120
|
-
|
|
24472
|
+
log48.debug("paste image dir create failed", e);
|
|
24121
24473
|
}
|
|
24122
24474
|
const img = grabClipboardImage(dir, String(Date.now()));
|
|
24123
24475
|
return img ? { display: "Image", ref: "@" + img.path, path: img.path } : null;
|
|
24124
24476
|
};
|
|
24125
24477
|
const forceQuit = (code = 130) => {
|
|
24478
|
+
live?.exited(code === 130 ? "force-quit" : `exit ${code}`);
|
|
24126
24479
|
try {
|
|
24127
24480
|
voiceIO?.stop();
|
|
24128
24481
|
} catch {
|
|
@@ -24151,6 +24504,8 @@ ${SPOKEN_TURN}`, { id });
|
|
|
24151
24504
|
}
|
|
24152
24505
|
forceQuit();
|
|
24153
24506
|
});
|
|
24507
|
+
process.on("SIGHUP", () => forceQuit(129));
|
|
24508
|
+
process.on("SIGTERM", () => forceQuit(143));
|
|
24154
24509
|
installCancelGuards(mounted);
|
|
24155
24510
|
setMcpMentionResolver(async (ref) => {
|
|
24156
24511
|
const i = ref.indexOf(":");
|
|
@@ -24165,13 +24520,15 @@ ${SPOKEN_TURN}`, { id });
|
|
|
24165
24520
|
const store = new SessionStore(cwd);
|
|
24166
24521
|
let session = startSession(args, store, face, cwd);
|
|
24167
24522
|
triggerServer.start(session.meta.id);
|
|
24523
|
+
setLive(new LiveStatus({ cwd, model: () => session.meta.model ?? agent.options.model, jobs: () => agent.jobs.list().filter((j) => j.status === "running").length }));
|
|
24524
|
+
live.session(session.meta.id);
|
|
24168
24525
|
setTermTitle(`agentx \xB7 ${session.meta.title || cwd.split("/").pop() || "session"}`);
|
|
24169
24526
|
if (session.meta.scheduledJobs?.length) {
|
|
24170
24527
|
scheduler.restore(session.meta.scheduledJobs);
|
|
24171
24528
|
err(dim(` \u23F0 ${scheduler.size} scheduled job(s) re-armed
|
|
24172
24529
|
`));
|
|
24173
24530
|
}
|
|
24174
|
-
const checkpoints = args.vfs || args.boddb ? new CheckpointStack(agent.options.fs) : new GitCheckpoints({ workTree: cwd, gitDir:
|
|
24531
|
+
const checkpoints = args.vfs || args.boddb ? new CheckpointStack(agent.options.fs) : new GitCheckpoints({ workTree: cwd, gitDir: join17(cwd, ".agent", "checkpoints.git"), addDirs: args.addDirs, sessionId: session.meta.id });
|
|
24175
24532
|
const cpHooks = checkpoints.hooks?.();
|
|
24176
24533
|
if (cpHooks) {
|
|
24177
24534
|
agent.options.hooks = composeHooks(agent.options.hooks, cpHooks);
|
|
@@ -24223,14 +24580,14 @@ ${lines.join("\n")}
|
|
|
24223
24580
|
Added entries are loadable now via the Skill/SlashCommand tools; removed ones are gone even if still listed in the system prompt.
|
|
24224
24581
|
</system-reminder>`;
|
|
24225
24582
|
};
|
|
24226
|
-
const histPath =
|
|
24583
|
+
const histPath = join17(cwd, ".agent", "history");
|
|
24227
24584
|
const history = existsSync9(histPath) ? readFileSync10(histPath, "utf8").split("\n").filter(Boolean).reverse().slice(0, 500) : [];
|
|
24228
24585
|
const remember2 = (line) => {
|
|
24229
24586
|
try {
|
|
24230
|
-
|
|
24587
|
+
mkdirSync13(join17(cwd, ".agent"), { recursive: true });
|
|
24231
24588
|
appendFileSync2(histPath, line + "\n");
|
|
24232
24589
|
} catch (e) {
|
|
24233
|
-
|
|
24590
|
+
log48.debug("history write failed", e);
|
|
24234
24591
|
}
|
|
24235
24592
|
};
|
|
24236
24593
|
const ago = (t) => {
|
|
@@ -24243,6 +24600,7 @@ Added entries are loadable now via the Skill/SlashCommand tools; removed ones ar
|
|
|
24243
24600
|
session = data;
|
|
24244
24601
|
checkpoints.use?.(data.meta.id);
|
|
24245
24602
|
triggerServer.use(data.meta.id);
|
|
24603
|
+
live?.session(data.meta.id);
|
|
24246
24604
|
const m = data.meta;
|
|
24247
24605
|
goalCondition = m.goalCondition;
|
|
24248
24606
|
goalTurns = m.goalTurns ?? 0;
|
|
@@ -24302,7 +24660,7 @@ Added entries are loadable now via the Skill/SlashCommand tools; removed ones ar
|
|
|
24302
24660
|
try {
|
|
24303
24661
|
store.save(session);
|
|
24304
24662
|
} catch (e) {
|
|
24305
|
-
|
|
24663
|
+
log48.debug("session save after rewind failed", e);
|
|
24306
24664
|
}
|
|
24307
24665
|
err(green(" \u27F2 jumped back") + dim(` \u2014 ${face.transcript.length} message(s) kept; edit + resend
|
|
24308
24666
|
`));
|
|
@@ -24330,6 +24688,14 @@ Added entries are loadable now via the Skill/SlashCommand tools; removed ones ar
|
|
|
24330
24688
|
const announcedTasks = /* @__PURE__ */ new Set();
|
|
24331
24689
|
const replacedVoiceTurns = /* @__PURE__ */ new Set();
|
|
24332
24690
|
const turn = async (task, opts) => {
|
|
24691
|
+
live?.turnStart({ machine: opts?.machine });
|
|
24692
|
+
try {
|
|
24693
|
+
return await turnBody(task, opts);
|
|
24694
|
+
} finally {
|
|
24695
|
+
live?.turnEnd();
|
|
24696
|
+
}
|
|
24697
|
+
};
|
|
24698
|
+
const turnBody = async (task, opts) => {
|
|
24333
24699
|
if (bangContext.length) {
|
|
24334
24700
|
task = `${bangContext.join("\n\n")}
|
|
24335
24701
|
|
|
@@ -24337,7 +24703,7 @@ ${task}`;
|
|
|
24337
24703
|
bangContext.length = 0;
|
|
24338
24704
|
}
|
|
24339
24705
|
const delta = await refreshCatalogs().catch((e) => {
|
|
24340
|
-
|
|
24706
|
+
log48.debug("catalog refresh failed", e);
|
|
24341
24707
|
return "";
|
|
24342
24708
|
});
|
|
24343
24709
|
if (delta) {
|
|
@@ -24369,7 +24735,15 @@ ${task}`;
|
|
|
24369
24735
|
}
|
|
24370
24736
|
return r;
|
|
24371
24737
|
};
|
|
24372
|
-
scheduleTurn = turn;
|
|
24738
|
+
scheduleTurn = (prompt) => turn(prompt, { machine: true });
|
|
24739
|
+
if (!duplex) agent.options.onInject = () => setImmediate(() => {
|
|
24740
|
+
if (activeTurn || dispatchPending || live?.busy || exitRequested) return;
|
|
24741
|
+
const notes = agent.drainPendingSteers();
|
|
24742
|
+
if (!notes.length) return;
|
|
24743
|
+
err(dim(` \u2699 background job finished \u2014 resuming
|
|
24744
|
+
`));
|
|
24745
|
+
void turn(notes.join("\n\n"), { machine: true }).then(() => editorRef?.redrawNow());
|
|
24746
|
+
});
|
|
24373
24747
|
const runSkill = async (sk, extra = "") => {
|
|
24374
24748
|
try {
|
|
24375
24749
|
await turn(await expandEntry(fs, sk.path, extra));
|
|
@@ -24456,7 +24830,7 @@ ${task}`;
|
|
|
24456
24830
|
`));
|
|
24457
24831
|
aborting = false;
|
|
24458
24832
|
const tokensBefore = session.meta.tokens ?? 0;
|
|
24459
|
-
await turn(`Continue working toward the goal: ${goalCondition}
|
|
24833
|
+
await turn(`Continue working toward the goal: ${goalCondition}`, { machine: true });
|
|
24460
24834
|
goalTokens += (session.meta.tokens ?? 0) - tokensBefore;
|
|
24461
24835
|
goalTurns++;
|
|
24462
24836
|
persistGoal();
|
|
@@ -24578,12 +24952,12 @@ ${task}`;
|
|
|
24578
24952
|
}
|
|
24579
24953
|
const info = getModelInfo(work.model);
|
|
24580
24954
|
info?.pricing ? ok(`model ${work.model} \u2014 priced (${info.pricing.inputCostPer1K}/${info.pricing.outputCostPer1K} per 1k in/out)`) : warn(`model ${work.model} \u2014 no pricing in the catalog (costs will show ~$0; verify the id)`);
|
|
24581
|
-
const cfgFiles = ["ts", "js", "json"].flatMap((e) => [`${cwd}/.agent/config.${e}`, `${
|
|
24955
|
+
const cfgFiles = ["ts", "js", "json"].flatMap((e) => [`${cwd}/.agent/config.${e}`, `${homedir11()}/.agent/config.${e}`]).filter((p) => existsSync9(p));
|
|
24582
24956
|
cfgFiles.length ? ok(`config: ${cfgFiles.join(", ")}`) : warn("no .agent/config.* found (project or ~) \u2014 running on defaults");
|
|
24583
24957
|
try {
|
|
24584
24958
|
const probe = `${cwd}/.agent/sessions/.doctor-probe`;
|
|
24585
|
-
|
|
24586
|
-
|
|
24959
|
+
mkdirSync13(`${cwd}/.agent/sessions`, { recursive: true });
|
|
24960
|
+
writeFileSync10(probe, "ok");
|
|
24587
24961
|
unlinkSync5(probe);
|
|
24588
24962
|
ok(`session store writable (${cwd}/.agent/sessions)`);
|
|
24589
24963
|
} catch (e) {
|
|
@@ -24611,7 +24985,7 @@ ${task}`;
|
|
|
24611
24985
|
desc: "rescan skills/commands dirs and rebuild the system prompt (one cache miss) \u2014 picks up entries created mid-session",
|
|
24612
24986
|
run: async () => {
|
|
24613
24987
|
await refreshCatalogs().catch((e) => {
|
|
24614
|
-
|
|
24988
|
+
log48.debug("catalog refresh failed", e);
|
|
24615
24989
|
});
|
|
24616
24990
|
face.reprepare();
|
|
24617
24991
|
err(green(` \u2713 reloaded \u2014 ${skills.length} skill(s), ${cmds.length} command(s); system prompt rebuilds on next message
|
|
@@ -25045,6 +25419,7 @@ ${task}`;
|
|
|
25045
25419
|
bangContext.length = 0;
|
|
25046
25420
|
session = startSession({ ...args, cont: false, resume: void 0 }, store, face, cwd);
|
|
25047
25421
|
triggerServer.use(session.meta.id);
|
|
25422
|
+
live?.session(session.meta.id);
|
|
25048
25423
|
err("\x1Bc");
|
|
25049
25424
|
}
|
|
25050
25425
|
},
|
|
@@ -25114,7 +25489,7 @@ ${task}`;
|
|
|
25114
25489
|
try {
|
|
25115
25490
|
for (const def of (await loadAgents(fs2, d)).agents) if (!seen.has(def.name)) seen.set(def.name, { def, from: d });
|
|
25116
25491
|
} catch (e) {
|
|
25117
|
-
|
|
25492
|
+
log48.debug(`loadAgents(${d}) failed`, e);
|
|
25118
25493
|
}
|
|
25119
25494
|
}
|
|
25120
25495
|
if (!seen.size) {
|
|
@@ -25202,7 +25577,7 @@ ${task}`;
|
|
|
25202
25577
|
}
|
|
25203
25578
|
if (idx >= 0) {
|
|
25204
25579
|
const old = mounted.splice(idx, 1)[0];
|
|
25205
|
-
await old.client.close().catch((e) =>
|
|
25580
|
+
await old.client.close().catch((e) => log48.debug("mcp close failed", e));
|
|
25206
25581
|
}
|
|
25207
25582
|
try {
|
|
25208
25583
|
const m = await mountMcpServer(name, conf);
|
|
@@ -25230,7 +25605,7 @@ ${task}`;
|
|
|
25230
25605
|
}
|
|
25231
25606
|
const m = mounted.splice(idx, 1)[0];
|
|
25232
25607
|
remountMcpTools();
|
|
25233
|
-
await m.client.close().catch((e) =>
|
|
25608
|
+
await m.client.close().catch((e) => log48.debug("mcp close failed", e));
|
|
25234
25609
|
err(dim(` removed "${name}"
|
|
25235
25610
|
`));
|
|
25236
25611
|
return;
|
|
@@ -25345,11 +25720,11 @@ ${task}`;
|
|
|
25345
25720
|
return;
|
|
25346
25721
|
}
|
|
25347
25722
|
const md = exportMarkdown(session.meta, shown);
|
|
25348
|
-
const name = a[0] ? extname(a[0]) ? a[0] : a[0] + ".md" :
|
|
25723
|
+
const name = a[0] ? extname(a[0]) ? a[0] : a[0] + ".md" : join17(".agent", "exports", `${session.meta.id}.md`);
|
|
25349
25724
|
const path = resolve5(cwd, name);
|
|
25350
25725
|
try {
|
|
25351
|
-
|
|
25352
|
-
|
|
25726
|
+
mkdirSync13(dirname6(path), { recursive: true });
|
|
25727
|
+
writeFileSync10(path, md);
|
|
25353
25728
|
err(green(` \u2713 exported \u2192 ${path}
|
|
25354
25729
|
`) + dim(` ${shown.length} message(s) \xB7 ${md.length} chars
|
|
25355
25730
|
`));
|
|
@@ -25431,9 +25806,9 @@ ${task}`;
|
|
|
25431
25806
|
});
|
|
25432
25807
|
const listDir = (absDir) => {
|
|
25433
25808
|
try {
|
|
25434
|
-
return readdirSync4(
|
|
25809
|
+
return readdirSync4(join17(cwd, absDir.replace(/^\/+/, "")), { withFileTypes: true }).map((d) => ({ name: d.name, dir: d.isDirectory() }));
|
|
25435
25810
|
} catch (e) {
|
|
25436
|
-
|
|
25811
|
+
log48.debug("completion readdir failed", absDir, e);
|
|
25437
25812
|
return null;
|
|
25438
25813
|
}
|
|
25439
25814
|
};
|
|
@@ -25535,6 +25910,14 @@ ${task}`;
|
|
|
25535
25910
|
let prefill;
|
|
25536
25911
|
let tick = 0;
|
|
25537
25912
|
const dispatchLine = async (line, opts) => {
|
|
25913
|
+
live?.hold();
|
|
25914
|
+
try {
|
|
25915
|
+
return await dispatchLineBody(line, opts);
|
|
25916
|
+
} finally {
|
|
25917
|
+
live?.release();
|
|
25918
|
+
}
|
|
25919
|
+
};
|
|
25920
|
+
const dispatchLineBody = async (line, opts) => {
|
|
25538
25921
|
if (!opts?.id) takeCut(voiceIO, false);
|
|
25539
25922
|
if (/^[!#/]/.test(line)) dispatchPending = false;
|
|
25540
25923
|
history.unshift(line.replace(/\n+/g, " \u23CE "));
|
|
@@ -25572,7 +25955,7 @@ ${out}
|
|
|
25572
25955
|
return;
|
|
25573
25956
|
}
|
|
25574
25957
|
await refreshCatalogs().catch((e) => {
|
|
25575
|
-
|
|
25958
|
+
log48.debug("catalog refresh failed", e);
|
|
25576
25959
|
});
|
|
25577
25960
|
const sk = skills.find((x) => x.name === name);
|
|
25578
25961
|
if (sk) {
|
|
@@ -25623,7 +26006,7 @@ ${out}
|
|
|
25623
26006
|
return false;
|
|
25624
26007
|
}
|
|
25625
26008
|
const fakeVoice = process.env.AGENTX_VOICE_FAKE ? fakeVoiceParts(process.env.AGENTX_VOICE_FAKE) : null;
|
|
25626
|
-
voiceDiag = new JsonlDiagSink(
|
|
26009
|
+
voiceDiag = new JsonlDiagSink(join17(store.dir, `${session.meta.id}.voice.jsonl`));
|
|
25627
26010
|
const sttTerms = agent.options.fs && agent.options.memoryDir ? await memoryTerms(agent.options.fs, agent.options.memoryDir, [basename4(agent.options.fs?.getCwd() ?? process.cwd())]).catch((e) => {
|
|
25628
26011
|
err(dim(` (stt terms: ${e?.message ?? e})
|
|
25629
26012
|
`));
|
|
@@ -25702,7 +26085,7 @@ ${out}
|
|
|
25702
26085
|
if (delivery || cut) dx?.parkCutDelivery(delivery, !!cut, heard);
|
|
25703
26086
|
const cutReply = cut && cut.full.length - cut.heard.length > 40 ? cut : null;
|
|
25704
26087
|
const noteP = replaces ? replaces.note : !cutReply ? Promise.resolve("") : (instinct ? instinct.bargeIntent(text).catch((e) => {
|
|
25705
|
-
|
|
26088
|
+
log48.warn(`barge intent failed \u2014 model decides: ${e.message}`);
|
|
25706
26089
|
return void 0;
|
|
25707
26090
|
}) : Promise.resolve(void 0)).then(async (intent) => interruptionNote(cutReply, intent) + ackedNote(await instinct?.ackFor(text)));
|
|
25708
26091
|
const cutIn = replaces ? replaces.cutIn : interjectNote;
|
|
@@ -25839,7 +26222,7 @@ ${out}
|
|
|
25839
26222
|
const where = cwd.split("/").pop();
|
|
25840
26223
|
const resumed = session.messages.length > 0;
|
|
25841
26224
|
const prompt = resumed ? `[session resumed] You're rejoining a live voice conversation already in progress \u2014 the full history, including the user's memory/preferences, is already in context, so do NOT call QuickLook again. In one short spoken line, welcome the user back and pick the thread up where it left off: if your last turn ended on an open question or offer, continue it naturally rather than asking what they'd like to do.` : `[session started] First call QuickLook with what:"memory" \u2014 if it knows the user's name or preferences, use them. Then greet the user warmly in one or two short sentences, as the opener of a live voice conversation. Context: working directory "${where}". Personalize from whatever you learned (memory). Then ask what they'd like to do.`;
|
|
25842
|
-
void turn(prompt).finally(() => editorRef?.redrawNow());
|
|
26225
|
+
void turn(prompt, { machine: true }).finally(() => editorRef?.redrawNow());
|
|
25843
26226
|
}
|
|
25844
26227
|
return true;
|
|
25845
26228
|
} catch (e) {
|
|
@@ -25875,6 +26258,7 @@ ${out}
|
|
|
25875
26258
|
};
|
|
25876
26259
|
if (args.voice && (duplex || call) && process.stdin.isTTY) await startVoice(process.env.VOICE_GREETING !== "0");
|
|
25877
26260
|
let ctxWarned = 0;
|
|
26261
|
+
let seedLine = args.prompt;
|
|
25878
26262
|
while (true) {
|
|
25879
26263
|
if (pendingRewind) {
|
|
25880
26264
|
pendingRewind = false;
|
|
@@ -25932,7 +26316,13 @@ ${out}
|
|
|
25932
26316
|
const q2 = ask.question.replace(/\s+/g, " ").slice(0, 64);
|
|
25933
26317
|
return bold(yellow(`? ${q2}${ask.question.length > 64 ? "\u2026" : ""} \u2039yes/no\u203A `));
|
|
25934
26318
|
};
|
|
25935
|
-
const result =
|
|
26319
|
+
const result = seedLine !== void 0 ? (() => {
|
|
26320
|
+
const s = seedLine;
|
|
26321
|
+
seedLine = void 0;
|
|
26322
|
+
err(promptStr + s + "\n");
|
|
26323
|
+
dispatchPending = true;
|
|
26324
|
+
return s;
|
|
26325
|
+
})() : await readMultiline((cont) => {
|
|
25936
26326
|
dispatchPending = false;
|
|
25937
26327
|
return editor.readLine({
|
|
25938
26328
|
prompt: cont ? contPrompt : livePrompt,
|
|
@@ -25992,6 +26382,7 @@ ${out}
|
|
|
25992
26382
|
`));
|
|
25993
26383
|
continue;
|
|
25994
26384
|
}
|
|
26385
|
+
live?.hold();
|
|
25995
26386
|
let quit = await dispatchLine(line) === "quit";
|
|
25996
26387
|
const wasLocal = /^[!#/]/.test(line);
|
|
25997
26388
|
if (wasLocal) agent.clearInjections();
|
|
@@ -26006,7 +26397,7 @@ ${out}
|
|
|
26006
26397
|
const prompt = scheduleQueue.shift();
|
|
26007
26398
|
err(dim(` \u23F0 scheduled \u203A ${prompt.slice(0, 60)}${prompt.length > 60 ? "\u2026" : ""}
|
|
26008
26399
|
`));
|
|
26009
|
-
await turn(prompt);
|
|
26400
|
+
await turn(prompt, { machine: true });
|
|
26010
26401
|
}
|
|
26011
26402
|
dispatchPending = false;
|
|
26012
26403
|
session.meta.scheduledJobs = scheduler.snapshot();
|
|
@@ -26014,10 +26405,12 @@ ${out}
|
|
|
26014
26405
|
store.save(session);
|
|
26015
26406
|
} catch {
|
|
26016
26407
|
}
|
|
26408
|
+
live?.release();
|
|
26017
26409
|
if (quit) break;
|
|
26018
26410
|
}
|
|
26019
26411
|
scheduler.destroy();
|
|
26020
26412
|
triggerServer.stop();
|
|
26413
|
+
live?.exited("exit");
|
|
26021
26414
|
voiceIO?.stop();
|
|
26022
26415
|
if (dx) {
|
|
26023
26416
|
const running = [...dx.tasks.values()].filter((t) => t.status === "running");
|
|
@@ -26103,13 +26496,13 @@ function channelOptions(ai, model, gender) {
|
|
|
26103
26496
|
// 0: the reactive live path
|
|
26104
26497
|
pickLeaf: fastLeafPicker(ai, process.env.AGENTX_LEAF_MODEL || "groq/openai/gpt-oss-120b"),
|
|
26105
26498
|
persona: process.env.AGENTX_CALL_PERSONA ?? "",
|
|
26106
|
-
onTree: (e) =>
|
|
26499
|
+
onTree: (e) => log48.debug(`voice tree: ${e.branches} branches in ${e.ms}ms${e.tokens ? ` tokens ${e.tokens.input}/${e.tokens.output}` : ""}${e.error ? ` error ${e.error}` : ""}`),
|
|
26107
26500
|
onEvent: (e) => {
|
|
26108
|
-
if (e.moment)
|
|
26109
|
-
else
|
|
26501
|
+
if (e.moment) log48.debug(`voice leaf: ${e.moment} ${e.conf} "${e.text}" ${e.acted}`);
|
|
26502
|
+
else log48.debug(`channel ${e.trigger}: rule=${e.rule} choice=${e.choice ?? "-"} \u2192 ${e.acted}${e.text ? ` "${e.text}"` : ""}${e.cue ? " (planned cue)" : ""} ${e.ms}ms`);
|
|
26110
26503
|
},
|
|
26111
26504
|
// Banks in the user's language: generated once per language, cached + topped up across sessions (~/.agent/cache).
|
|
26112
|
-
banks: new ChannelBanks({ generate: fastBankGenerator(ai, model), cacheDir:
|
|
26505
|
+
banks: new ChannelBanks({ generate: fastBankGenerator(ai, model), cacheDir: join17(homedir11(), ".agent", "cache", "channel-banks") }),
|
|
26113
26506
|
decide: channelDecide(ai, instinct),
|
|
26114
26507
|
generate: fastLineGenerator(ai, model, gender),
|
|
26115
26508
|
// Anticipated backchannels: on in chatty mode (its preset), else off until the offline replay proves them (tests/voice-bc-anticipate-eval.ts)
|
|
@@ -26141,7 +26534,7 @@ function overlapResponder(ai, mode, out, aside) {
|
|
|
26141
26534
|
}
|
|
26142
26535
|
async function duplexServe(args, ai, cfg, cwd) {
|
|
26143
26536
|
const out = (o) => process.stdout.write(JSON.stringify(o) + "\n");
|
|
26144
|
-
const mounted = await mountMcp(cfg, new McpOAuth({ storePath:
|
|
26537
|
+
const mounted = await mountMcp(cfg, new McpOAuth({ storePath: join17(cwd, ".agent", "mcp-auth.json") }));
|
|
26145
26538
|
installCancelGuards(mounted);
|
|
26146
26539
|
const agent = await makeAgent(args, ai, cfg, mcpAgentTools(mounted, { quiet: true }), mounted.map((m) => m.name));
|
|
26147
26540
|
const { host: _h, stream: _s, signal: _g, providerOptions: _po, ...wo } = agent.options;
|
|
@@ -26200,7 +26593,7 @@ async function duplexServe(args, ai, cfg, cwd) {
|
|
|
26200
26593
|
try {
|
|
26201
26594
|
store.save(session);
|
|
26202
26595
|
} catch (e) {
|
|
26203
|
-
|
|
26596
|
+
log48.warn("duplex session save failed", e);
|
|
26204
26597
|
}
|
|
26205
26598
|
};
|
|
26206
26599
|
const overlap2 = overlapResponder(ai, args.duplexV2 ? args.channelMode : void 0, out);
|
|
@@ -26240,7 +26633,7 @@ async function duplexServe(args, ai, cfg, cwd) {
|
|
|
26240
26633
|
done2();
|
|
26241
26634
|
out({ type: "turn_done", id, finishReason: res?.finishReason ?? "error", ...why ? { error: why } : {} });
|
|
26242
26635
|
}).catch((e) => {
|
|
26243
|
-
|
|
26636
|
+
log48.error("duplex turn failed", e);
|
|
26244
26637
|
done2();
|
|
26245
26638
|
out({ type: "turn_done", id, finishReason: "error", error: String(e?.message ?? e) });
|
|
26246
26639
|
});
|
|
@@ -26399,7 +26792,7 @@ async function rollbackTurn(agent, store, session, start) {
|
|
|
26399
26792
|
session.meta.updated = Date.now();
|
|
26400
26793
|
session.meta.cc = void 0;
|
|
26401
26794
|
const cc = agent.options.providerOptions?.claudeCodeSession;
|
|
26402
|
-
if (typeof cc === "string" && agent.options.model
|
|
26795
|
+
if (typeof cc === "string" && isClaudeCode(agent.options.model)) await rewindClaudeCodeSession(cc);
|
|
26403
26796
|
store.save(session);
|
|
26404
26797
|
return dropped;
|
|
26405
26798
|
}
|
|
@@ -26466,7 +26859,7 @@ async function main() {
|
|
|
26466
26859
|
}
|
|
26467
26860
|
cfg.permissions = mergePerms(loadClaudeSettings(cwd), mergePerms(loadPersistedRules(cwd), cfg.permissions));
|
|
26468
26861
|
if (canPrompt && !args.yes && !isTrusted(cwd)) {
|
|
26469
|
-
const ok = await makeHost().confirm?.(`Trust this directory? agent.libx will read and edit files in:
|
|
26862
|
+
const ok = args.trust || await makeHost().confirm?.(`Trust this directory? agent.libx will read and edit files in:
|
|
26470
26863
|
${cwd}`);
|
|
26471
26864
|
if (!ok) {
|
|
26472
26865
|
console.error(red(" not trusted \u2014 exiting (re-run with --yes to skip this prompt)."));
|
|
@@ -26491,7 +26884,7 @@ async function main() {
|
|
|
26491
26884
|
loadInstallEnv();
|
|
26492
26885
|
await loadBodifySecrets();
|
|
26493
26886
|
const apiKeys = { ...cfg.apiKeys, ...apiKeysFromEnv() };
|
|
26494
|
-
const keyless = String(args.model ?? cfg.model ?? "")
|
|
26887
|
+
const keyless = isKeyless(String(args.model ?? cfg.model ?? ""));
|
|
26495
26888
|
if (!Object.keys(apiKeys).length && !keyless) {
|
|
26496
26889
|
console.error(red("No provider key found. Set ANTHROPIC_API_KEY (or OPENAI_API_KEY / GOOGLE_API_KEY / GROQ_API_KEY) in ~/.agent/.env, or set BODIFY_API_KEY + BODIFY_APP_ID to pull from Bodify."));
|
|
26497
26890
|
process.exit(1);
|
|
@@ -26525,7 +26918,7 @@ async function main() {
|
|
|
26525
26918
|
worktreeCleanup?.();
|
|
26526
26919
|
process.exit(0);
|
|
26527
26920
|
}
|
|
26528
|
-
const mounted = await mountMcp(cfg, new McpOAuth({ storePath:
|
|
26921
|
+
const mounted = await mountMcp(cfg, new McpOAuth({ storePath: join17(cwd, ".agent", "mcp-auth.json") }));
|
|
26529
26922
|
const agent = await makeAgent(args, ai, cfg, mcpAgentTools(mounted), mounted.map((m) => m.name));
|
|
26530
26923
|
const store = new SessionStore(cwd);
|
|
26531
26924
|
const session = startSession(args, store, agent, cwd);
|