@livx.cc/agentx 0.99.166 → 0.99.168
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 +21 -2
- package/dist/cli.js +486 -156
- package/dist/cli.js.map +1 -1
- package/dist/directives.js +2 -0
- package/dist/directives.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +60 -11
- package/dist/index.js.map +1 -1
- package/dist/{secondChannel-BNDDJv6d.d.ts → secondChannel-CaP6zhH6.d.ts} +9 -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,35 @@ 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
|
+
codex: { keyless: true, ownsTools: true }
|
|
3372
|
+
// `codex app-server` on the ChatGPT subscription login; MCP via per-thread config
|
|
3373
|
+
};
|
|
3374
|
+
function runtimeOf(model) {
|
|
3375
|
+
const p = (model ?? "").split("/")[0];
|
|
3376
|
+
return (model ?? "").includes("/") && p in RUNTIMES ? p : void 0;
|
|
3377
|
+
}
|
|
3378
|
+
var isDelegated = (model) => !!runtimeOf(model);
|
|
3379
|
+
var isClaudeCode = (model) => runtimeOf(model) === "claude-code";
|
|
3380
|
+
var isCursor = (model) => runtimeOf(model) === "cursor";
|
|
3381
|
+
var isCodex = (model) => runtimeOf(model) === "codex";
|
|
3382
|
+
var isKeyless = (modelOrProvider) => {
|
|
3383
|
+
const p = (modelOrProvider ?? "").split("/")[0];
|
|
3384
|
+
return !!RUNTIMES[p]?.keyless;
|
|
3385
|
+
};
|
|
3386
|
+
var ownsTools = (model) => {
|
|
3387
|
+
const r = runtimeOf(model);
|
|
3388
|
+
return !!r && RUNTIMES[r].ownsTools;
|
|
3389
|
+
};
|
|
3390
|
+
|
|
3366
3391
|
// cli/clipboard.ts
|
|
3367
3392
|
import { execFileSync } from "child_process";
|
|
3368
3393
|
import { statSync, writeFileSync } from "fs";
|
|
@@ -3440,8 +3465,8 @@ function copyTextToClipboard(text, platform2 = process.platform) {
|
|
|
3440
3465
|
}
|
|
3441
3466
|
|
|
3442
3467
|
// cli/cli.ts
|
|
3443
|
-
import { join as
|
|
3444
|
-
import { AIClient as AIClient2, listModels, listProviders, getProviderFromModel, getModelInfo, resolveModel, isModelSupported, disposeCursorSessions, disposeClaudeCodeSessions, rewindClaudeCodeSession } from "ai.libx.js";
|
|
3468
|
+
import { join as join17, resolve as resolve5, basename as basename4, extname, dirname as dirname6 } from "path";
|
|
3469
|
+
import { AIClient as AIClient2, listModels, listProviders, getProviderFromModel, getModelInfo, resolveModel, isModelSupported, disposeCursorSessions, disposeClaudeCodeSessions, rewindClaudeCodeSession, disposeCodexSessions, listCliModels } from "ai.libx.js";
|
|
3445
3470
|
|
|
3446
3471
|
// src/ccBridge.ts
|
|
3447
3472
|
var CC_BRIDGED = /* @__PURE__ */ new Set(["Recall", "Remember", "MemorySearch", "Forget"]);
|
|
@@ -4239,7 +4264,11 @@ var PermissionPolicy = class {
|
|
|
4239
4264
|
preToolUse: async (call) => {
|
|
4240
4265
|
const d = this.decide(call);
|
|
4241
4266
|
if (d === "allow") return;
|
|
4242
|
-
if (d === "deny")
|
|
4267
|
+
if (d === "deny") {
|
|
4268
|
+
const reason = `denied by permission policy (${call.name})`;
|
|
4269
|
+
this.options.onDeny?.(call, reason);
|
|
4270
|
+
return { block: true, reason };
|
|
4271
|
+
}
|
|
4243
4272
|
if (this.options.ask) {
|
|
4244
4273
|
const r = await this.options.ask(call);
|
|
4245
4274
|
const decision = r?.decision ?? "deny";
|
|
@@ -4738,7 +4767,7 @@ function pairOk(kind, main2, other) {
|
|
|
4738
4767
|
log8.warn(`${kind} off: both sides are ${main2}`);
|
|
4739
4768
|
return false;
|
|
4740
4769
|
}
|
|
4741
|
-
if (main2
|
|
4770
|
+
if (isCursor(main2) || isCursor(other)) {
|
|
4742
4771
|
log8.warn(`${kind} off: cursor models are not supported (${main2} / ${other})`);
|
|
4743
4772
|
return false;
|
|
4744
4773
|
}
|
|
@@ -5141,6 +5170,9 @@ var AgentOptions = class {
|
|
|
5141
5170
|
* caps, MCP soft timeout) live on `JobRegistryOptions`. Completion notices reach the model via `inject` unless
|
|
5142
5171
|
* the host set its own `onExit`. */
|
|
5143
5172
|
jobs;
|
|
5173
|
+
/** Called after every `inject()` (a background job's completion notice, a host steer). A REPL uses it to wake an
|
|
5174
|
+
* IDLE session — between turns nothing drains the queue, so a finished job would otherwise wait for the next prompt. */
|
|
5175
|
+
onInject;
|
|
5144
5176
|
/** Plan mode: block mutating tools until the agent calls `ExitPlanMode` (host-approved). */
|
|
5145
5177
|
planMode = false;
|
|
5146
5178
|
/** Permission policy gating each tool call (allow / ask / deny). */
|
|
@@ -5258,6 +5290,20 @@ var Agent = class _Agent {
|
|
|
5258
5290
|
this.parkedMs += Date.now() - t;
|
|
5259
5291
|
}
|
|
5260
5292
|
}
|
|
5293
|
+
/** codex/*: Codex runs its own tools, so its approval requests (a command, a file change) go through the SAME hooks an
|
|
5294
|
+
* agentx tool call does: permission policy (allow/deny/ask resolver -> live `waiting`/`denied`), plan mode. The wait
|
|
5295
|
+
* holds the stall watchdog (a human may take minutes; Codex is silent meanwhile) and is parked out of the timeout. */
|
|
5296
|
+
async codexApprove(req) {
|
|
5297
|
+
const call = codexApprovalCall(req);
|
|
5298
|
+
const job = this.jobs.track({ kind: "host", label: `approve:${call.name}`, holds: true });
|
|
5299
|
+
try {
|
|
5300
|
+
const r = await this.park(Promise.resolve(this.activeHooks?.preToolUse?.(call, { id: "codex-approval" })));
|
|
5301
|
+
return r?.block ? "decline" : "accept";
|
|
5302
|
+
} finally {
|
|
5303
|
+
job.finish("done");
|
|
5304
|
+
this.stallPoke?.();
|
|
5305
|
+
}
|
|
5306
|
+
}
|
|
5261
5307
|
/** Force the next `send()`/`run()` to rebuild the system prompt, tools, plan-mode and permission hooks
|
|
5262
5308
|
* from `options` — apply mid-conversation changes to `planMode`/`permissions`/`model` etc. (prepare()
|
|
5263
5309
|
* is otherwise memoized per conversation). */
|
|
@@ -5298,6 +5344,7 @@ var Agent = class _Agent {
|
|
|
5298
5344
|
* Pushing onto `transcript` directly from outside would race the loop — this drains inside it. */
|
|
5299
5345
|
inject(content) {
|
|
5300
5346
|
this.pendingInjections.push(content);
|
|
5347
|
+
this.options.onInject?.();
|
|
5301
5348
|
}
|
|
5302
5349
|
/** Drop any queued-but-unconsumed injections. The REPL calls this after a LOCAL command (/cmd, !bash)
|
|
5303
5350
|
* — which runs no send() to drain them — so a mid-command steer can't leak into the next real turn. */
|
|
@@ -5311,7 +5358,7 @@ var Agent = class _Agent {
|
|
|
5311
5358
|
/** claude-code/*: the providerOptions every step adds (and prewarm, so the session it starts is the one step 1 reuses). */
|
|
5312
5359
|
claudeCodePo() {
|
|
5313
5360
|
const o = this.options;
|
|
5314
|
-
if (!o.model
|
|
5361
|
+
if (!isClaudeCode(o.model)) return void 0;
|
|
5315
5362
|
const po = { steer: () => this.drainPendingSteers() };
|
|
5316
5363
|
const mode = ccModeOptions(this.modeKind, o.providerOptions?.hooks, () => this.adv?.used() ?? 0);
|
|
5317
5364
|
const bridged = (t) => o.ccBridge === "all" || CC_BRIDGED.has(t.name) || mode.bridge.has(t.name);
|
|
@@ -5341,7 +5388,7 @@ var Agent = class _Agent {
|
|
|
5341
5388
|
async prewarm() {
|
|
5342
5389
|
const o = this.options;
|
|
5343
5390
|
const api = o.model.startsWith("anthropic/") && o.promptCache;
|
|
5344
|
-
if (!api && (!o.model
|
|
5391
|
+
if (!api && (!isClaudeCode(o.model) || !o.providerOptions?.claudeCodeSession)) return;
|
|
5345
5392
|
await this.ensureFs();
|
|
5346
5393
|
const systemPrompt = await this.prepare(), startCtx = await this.fireSessionStart();
|
|
5347
5394
|
const sys = { role: "system", content: systemPrompt + (startCtx ? "\n\n" + startCtx : "") };
|
|
@@ -5490,7 +5537,7 @@ var Agent = class _Agent {
|
|
|
5490
5537
|
tools: worker ? delegateTools([...o.tools, ...this.injectedTools], o.model, o.delegate?.plannerMay) : [...o.tools, ...this.injectedTools],
|
|
5491
5538
|
systemPrompt: o.systemPrompt,
|
|
5492
5539
|
// A child never resumes the parent's own claude-code session (the host's `resume` link is the parent's).
|
|
5493
|
-
providerOptionsFor: o.providerOptionsFor ?? ((m) => modelProvider(m) === modelProvider(o.model) && o.providerOptions ? { ...o.providerOptions, resume: void 0, onClaudeCodeSession: void 0 } : void 0)
|
|
5540
|
+
providerOptionsFor: o.providerOptionsFor ?? ((m) => modelProvider(m) === modelProvider(o.model) && o.providerOptions ? { ...o.providerOptions, resume: void 0, onClaudeCodeSession: void 0, onCodexThread: void 0 } : void 0)
|
|
5494
5541
|
};
|
|
5495
5542
|
tools = [...tools, makeTaskTool(taskOpts), makeTaskBatchTool(taskOpts)];
|
|
5496
5543
|
}
|
|
@@ -5658,8 +5705,8 @@ var Agent = class _Agent {
|
|
|
5658
5705
|
let res;
|
|
5659
5706
|
let sent = this.trimContext();
|
|
5660
5707
|
const frag = reasoningToChatFragment(o.model, o.reasoning);
|
|
5661
|
-
const sentTools = o.model
|
|
5662
|
-
const isCursorWithTools = o.model
|
|
5708
|
+
const sentTools = ownsTools(o.model) ? [] : wireTools;
|
|
5709
|
+
const isCursorWithTools = isCursor(o.model) && wireTools.length > 0;
|
|
5663
5710
|
const hostToolTimeoutMs = o.providerOptions?.toolTimeoutMs;
|
|
5664
5711
|
const derivedToolTimeoutMs = Math.max(TRANSPORT_TOOL_TIMEOUT_FLOOR_MS, ...this.activeTools.map(transportHeadroomMs));
|
|
5665
5712
|
const effectiveToolTimeoutMs = typeof hostToolTimeoutMs === "number" ? Math.max(hostToolTimeoutMs, derivedToolTimeoutMs) : derivedToolTimeoutMs;
|
|
@@ -5688,16 +5735,17 @@ var Agent = class _Agent {
|
|
|
5688
5735
|
};
|
|
5689
5736
|
const cursorPo = isCursorWithTools ? { toolTimeoutMs: effectiveToolTimeoutMs, toolExecutor: hostExec } : void 0;
|
|
5690
5737
|
const claudeSteerPo = this.claudeCodePo();
|
|
5738
|
+
const codexPo = isCodex(o.model) ? { onApproval: (req) => this.codexApprove(req) } : void 0;
|
|
5691
5739
|
if (this.ccServer) this.ccExec = hostExec;
|
|
5692
|
-
const cursorDeny = o.model
|
|
5693
|
-
if (o.model
|
|
5740
|
+
const cursorDeny = isCursor(o.model) ? o.permissions?.denyRules(true) ?? [] : [];
|
|
5741
|
+
if (isCursor(o.model) && o.permissions?.options.default === "deny")
|
|
5694
5742
|
throw new Error("cursor/* cannot enforce --onlyTools: its native tools bypass it. Refusing to run \u2014 use a claude-code/* or API model.");
|
|
5695
5743
|
if (cursorDeny.length)
|
|
5696
5744
|
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.`);
|
|
5697
5745
|
const reasonOpts = {
|
|
5698
5746
|
...frag,
|
|
5699
5747
|
...o.promptCache ? { promptCache: true } : {},
|
|
5700
|
-
...o.providerOptions || cursorPo || claudeSteerPo ? { providerOptions: { ...frag.providerOptions, ...o.providerOptions, ...cursorPo, ...claudeSteerPo } } : {}
|
|
5748
|
+
...o.providerOptions || cursorPo || claudeSteerPo || codexPo ? { providerOptions: { ...frag.providerOptions, ...o.providerOptions, ...cursorPo, ...claudeSteerPo, ...codexPo } } : {}
|
|
5701
5749
|
};
|
|
5702
5750
|
try {
|
|
5703
5751
|
for (let attempt = 0; ; attempt++) {
|
|
@@ -6543,6 +6591,12 @@ function toolKey(name) {
|
|
|
6543
6591
|
const k = name.toLowerCase();
|
|
6544
6592
|
return TOOL_ALIASES[k] ?? k;
|
|
6545
6593
|
}
|
|
6594
|
+
function codexApprovalCall(req) {
|
|
6595
|
+
if (req.kind === "command") return { name: "bash", args: { command: req.command ?? "", ...req.cwd ? { cwd: req.cwd } : {} } };
|
|
6596
|
+
if (req.kind === "mcpToolCall") return { name: `mcp__${req.server ?? ""}__${req.tool ?? ""}`, args: req.args ?? {} };
|
|
6597
|
+
const paths = (req.changes ?? []).map((c) => c.path);
|
|
6598
|
+
return { name: "Edit", args: { path: paths[0] ?? "", ...paths.length > 1 ? { paths } : {} } };
|
|
6599
|
+
}
|
|
6546
6600
|
|
|
6547
6601
|
// src/index.ts
|
|
6548
6602
|
init_models();
|
|
@@ -9768,9 +9822,9 @@ var VoiceEngine = class _VoiceEngine {
|
|
|
9768
9822
|
return false;
|
|
9769
9823
|
}
|
|
9770
9824
|
const epoch = ++this.asideEpoch, chunks = [], t0 = this.clock.now();
|
|
9771
|
-
const
|
|
9825
|
+
const live2 = () => epoch === this.asideEpoch;
|
|
9772
9826
|
const give = (reason) => {
|
|
9773
|
-
if (!
|
|
9827
|
+
if (!live2()) return;
|
|
9774
9828
|
this.asideEpoch++;
|
|
9775
9829
|
this.diag("aside_skipped", { reason, text: text.slice(0, 40) });
|
|
9776
9830
|
try {
|
|
@@ -9785,10 +9839,10 @@ var VoiceEngine = class _VoiceEngine {
|
|
|
9785
9839
|
this.lastAck = text;
|
|
9786
9840
|
this.echoUntil = Math.max(this.echoUntil, t0 + 2500 + this.options.asideMaxMs);
|
|
9787
9841
|
t.onAudio = (c) => {
|
|
9788
|
-
if (
|
|
9842
|
+
if (live2()) chunks.push(c);
|
|
9789
9843
|
};
|
|
9790
9844
|
t.onDone = () => {
|
|
9791
|
-
if (!
|
|
9845
|
+
if (!live2()) return;
|
|
9792
9846
|
this.clock.clearTimeout(timer);
|
|
9793
9847
|
const n = chunks.reduce((a, c) => a + c.length, 0);
|
|
9794
9848
|
if (!n || !this.speaking || this.pausedAt) return give(!n ? "no_audio" : this.pausedAt ? "held_again" : "turn_over");
|
|
@@ -12429,7 +12483,7 @@ ${nowLine()}. Anchor every relative or time-sensitive reference \u2014 "today",
|
|
|
12429
12483
|
* no other MCP server — the reflex only talks and routes; real work still goes through Act and its policy. */
|
|
12430
12484
|
claudeCodeReflex() {
|
|
12431
12485
|
const o = this.options;
|
|
12432
|
-
if (!o.reflexModel
|
|
12486
|
+
if (!isClaudeCode(o.reflexModel)) return {};
|
|
12433
12487
|
const po = o.providerOptionsFor?.(o.reflexModel) ?? {};
|
|
12434
12488
|
return {
|
|
12435
12489
|
ccBridge: "all",
|
|
@@ -17326,6 +17380,16 @@ function dotDirs(base, sub, opts = {}) {
|
|
|
17326
17380
|
const dirs = [`${base}/.agent/${sub}`, `${base}/.claude/${sub}`, `${home}/.agent/${sub}`, `${home}/.claude/${sub}`, ...extraDirs().map((d) => `${d}/${sub}`)];
|
|
17327
17381
|
return opts.existing ? dirs.filter((d) => existsSync2(d)) : dirs;
|
|
17328
17382
|
}
|
|
17383
|
+
function userInstructionFiles(o = {}) {
|
|
17384
|
+
const home = o.home ?? homedir(), cwd = o.cwd ?? process.cwd();
|
|
17385
|
+
const project = new Set(["AGENT.md", "AGENTS.md", "CLAUDE.md"].flatMap((n) => [`${cwd}/${n}`, `${cwd}/.claude/${n}`]));
|
|
17386
|
+
const tiers = [[`${home}/.agent/AGENTS.md`], extraDirs(o.env).map((d) => `${d.replace(/\/+$/, "")}/CLAUDE.md`), [`${home}/.claude/CLAUDE.md`]];
|
|
17387
|
+
for (const tier of tiers) {
|
|
17388
|
+
const hit = tier.filter((p) => existsSync2(p));
|
|
17389
|
+
if (hit.length) return hit.filter((p) => !project.has(p));
|
|
17390
|
+
}
|
|
17391
|
+
return [];
|
|
17392
|
+
}
|
|
17329
17393
|
function truncate(s, n, suffix = "\u2026") {
|
|
17330
17394
|
const t = s ?? "";
|
|
17331
17395
|
return t.length > n ? t.slice(0, n) + suffix : t;
|
|
@@ -17406,7 +17470,7 @@ function toCursorMcp(servers) {
|
|
|
17406
17470
|
return Object.keys(out).length ? { mcpServers: out } : void 0;
|
|
17407
17471
|
}
|
|
17408
17472
|
function cursorProviderOptions(model, cwd, mcpServers, hostMcpServers) {
|
|
17409
|
-
if (!(model
|
|
17473
|
+
if (!isCursor(model)) return void 0;
|
|
17410
17474
|
return { cwd, ...toCursorMcp(mcpServers) ?? {}, ...hostMcpServers?.length ? { hostMcpServers } : {}, ...process.env.CURSOR_WARM === "0" ? {} : { cursorSession: randomUUID() } };
|
|
17411
17475
|
}
|
|
17412
17476
|
function toClaudeCodeMcp(servers) {
|
|
@@ -17425,7 +17489,7 @@ function toClaudeCodeMcp(servers) {
|
|
|
17425
17489
|
return Object.keys(out).length ? { mcpServers: out } : void 0;
|
|
17426
17490
|
}
|
|
17427
17491
|
function claudeCodeProviderOptions(model, cwd, mcpServers) {
|
|
17428
|
-
if (!(model
|
|
17492
|
+
if (!isClaudeCode(model)) return void 0;
|
|
17429
17493
|
const env = (() => {
|
|
17430
17494
|
const base = plainEnv(process.env, process.env.AGENTX_CC_USE_API_KEY ? [] : ["ANTHROPIC_API_KEY", "ANTHROPIC_AUTH_TOKEN"]);
|
|
17431
17495
|
return { ENABLE_CLAUDEAI_MCP_SERVERS: "false", ...base };
|
|
@@ -17433,8 +17497,33 @@ function claudeCodeProviderOptions(model, cwd, mcpServers) {
|
|
|
17433
17497
|
const warm = process.env.AGENTX_CC_WARM === "0" ? {} : { claudeCodeSession: randomUUID() };
|
|
17434
17498
|
return { cwd, env, ...warm, ...toClaudeCodeMcp(mcpServers) ?? {} };
|
|
17435
17499
|
}
|
|
17500
|
+
function toCodexMcp(servers) {
|
|
17501
|
+
if (!servers) return void 0;
|
|
17502
|
+
const out = {};
|
|
17503
|
+
for (const [name, s] of Object.entries(servers)) {
|
|
17504
|
+
if (!s || s.disabled) continue;
|
|
17505
|
+
if (s.command) {
|
|
17506
|
+
out[`mcp_servers.${name}`] = { command: s.command, ...s.args ? { args: s.args } : {}, ...s.env ? { env: s.env } : {}, ...s.cwd ? { cwd: s.cwd } : {} };
|
|
17507
|
+
} else if (s.url) {
|
|
17508
|
+
if (s.auth === "oauth" && !s.bearerToken) continue;
|
|
17509
|
+
const headers = { ...s.headers ?? {}, ...s.bearerToken ? { Authorization: `Bearer ${s.bearerToken}` } : {} };
|
|
17510
|
+
out[`mcp_servers.${name}`] = { url: s.url, ...Object.keys(headers).length ? { http_headers: headers } : {} };
|
|
17511
|
+
}
|
|
17512
|
+
}
|
|
17513
|
+
return Object.keys(out).length ? out : void 0;
|
|
17514
|
+
}
|
|
17515
|
+
function codexProviderOptions(model, cwd, mcpServers) {
|
|
17516
|
+
if (!isCodex(model)) return void 0;
|
|
17517
|
+
const config = toCodexMcp(mcpServers);
|
|
17518
|
+
return {
|
|
17519
|
+
cwd,
|
|
17520
|
+
...process.env.CODEX_HOME ? { codexHome: process.env.CODEX_HOME } : {},
|
|
17521
|
+
...config ? { config } : {},
|
|
17522
|
+
...process.env.AGENTX_CODEX_WARM === "0" ? {} : { codexSession: randomUUID() }
|
|
17523
|
+
};
|
|
17524
|
+
}
|
|
17436
17525
|
function providerOptionsFor(model, cwd, mcpServers, hostMcpServers) {
|
|
17437
|
-
return cursorProviderOptions(model, cwd, mcpServers, hostMcpServers) ?? claudeCodeProviderOptions(model, cwd, mcpServers);
|
|
17526
|
+
return cursorProviderOptions(model, cwd, mcpServers, hostMcpServers) ?? claudeCodeProviderOptions(model, cwd, mcpServers) ?? codexProviderOptions(model, cwd, mcpServers);
|
|
17438
17527
|
}
|
|
17439
17528
|
var CONFINE_DENY = ["**/.agent", "**/.agent/**", "**/.claude", "**/.claude/**", "**/.mcp.json", "**/AGENTS.md", "**/CLAUDE.md", "**/CLAUDE.local.md"];
|
|
17440
17529
|
async function buildAgent(o) {
|
|
@@ -17448,12 +17537,12 @@ async function buildAgent(o) {
|
|
|
17448
17537
|
const jailedDisk = new JailedFilesystem(disk);
|
|
17449
17538
|
jailedDisk.setCwd(cwd);
|
|
17450
17539
|
const virtual = o.sandbox || !!o.boddb;
|
|
17451
|
-
const
|
|
17452
|
-
const
|
|
17453
|
-
const
|
|
17454
|
-
if (virtual &&
|
|
17540
|
+
const isCursor2 = isCursor(o.model);
|
|
17541
|
+
const isClaudeCode2 = isClaudeCode(o.model);
|
|
17542
|
+
const isDelegated2 = isDelegated(o.model);
|
|
17543
|
+
if (virtual && isDelegated2)
|
|
17455
17544
|
throw new Error(
|
|
17456
|
-
`${
|
|
17545
|
+
`${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).`
|
|
17457
17546
|
);
|
|
17458
17547
|
let fs = jailedDisk;
|
|
17459
17548
|
const vcwd = toVfsPath(cwd);
|
|
@@ -17477,7 +17566,7 @@ async function buildAgent(o) {
|
|
|
17477
17566
|
let mountNote = "";
|
|
17478
17567
|
if (o.confine) {
|
|
17479
17568
|
if (virtual) throw new Error("--confine is a disk-mode jail; --sandbox/--boddb already contain the agent.");
|
|
17480
|
-
if (
|
|
17569
|
+
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.");
|
|
17481
17570
|
const roots = [...new Set([cwd, ...o.addDirs ?? []].map((d) => realpathSync3(resolve3(d))))];
|
|
17482
17571
|
const mem = new MemFilesystem3();
|
|
17483
17572
|
for (const r of roots) await mkdirp(mem, r);
|
|
@@ -17539,7 +17628,7 @@ Reference files in them by their mount path (the left side).`;
|
|
|
17539
17628
|
const agentRef = {};
|
|
17540
17629
|
const jobRegistry = new JobRegistry();
|
|
17541
17630
|
const useRealShell = o.realShell ?? !virtual;
|
|
17542
|
-
if (useRealShell && !virtual && !
|
|
17631
|
+
if (useRealShell && !virtual && !isClaudeCode2) {
|
|
17543
17632
|
const jobs = new ShellJobRegistry({
|
|
17544
17633
|
cwd,
|
|
17545
17634
|
killOnExit: true,
|
|
@@ -17566,8 +17655,8 @@ Reference files in them by their mount path (the left side).`;
|
|
|
17566
17655
|
// turns, amortising the ~2s Agent.create + h2 handshake. Keyed per agentx launch.
|
|
17567
17656
|
...(() => {
|
|
17568
17657
|
let po = providerOptionsFor(o.model, cwd, o.mcpServers, o.hostMcpServers);
|
|
17569
|
-
if (po && o.lean &&
|
|
17570
|
-
if (po && o.confine &&
|
|
17658
|
+
if (po && o.lean && isClaudeCode2) po = { ...po, settingSources: [] };
|
|
17659
|
+
if (po && o.confine && isClaudeCode2) {
|
|
17571
17660
|
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.");
|
|
17572
17661
|
return { providerOptions: { ...po, tools: [] }, ccBridge: "all" };
|
|
17573
17662
|
}
|
|
@@ -17578,7 +17667,7 @@ Reference files in them by their mount path (the left side).`;
|
|
|
17578
17667
|
// worker under an anthropic planner ran with none. Same provider: the Agent default (parent's, minus its resume).
|
|
17579
17668
|
providerOptionsFor: (m) => {
|
|
17580
17669
|
const a = agentRef.agent, po = a?.options.providerOptions;
|
|
17581
|
-
if (modelProvider(m) === modelProvider(a?.options.model ?? "")) return po ? { ...po, resume: void 0, onClaudeCodeSession: void 0 } : void 0;
|
|
17670
|
+
if (modelProvider(m) === modelProvider(a?.options.model ?? "")) return po ? { ...po, resume: void 0, onClaudeCodeSession: void 0, onCodexThread: void 0 } : void 0;
|
|
17582
17671
|
return providerOptionsFor(m, cwd, o.mcpServers, o.hostMcpServers);
|
|
17583
17672
|
},
|
|
17584
17673
|
...(() => {
|
|
@@ -17601,7 +17690,7 @@ Windows paths: file tools accept ${cwd} style paths and the same path written ${
|
|
|
17601
17690
|
const list = [...names];
|
|
17602
17691
|
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.`;
|
|
17603
17692
|
})();
|
|
17604
|
-
const closureNote =
|
|
17693
|
+
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." : "";
|
|
17605
17694
|
const extra = [o.appendSystemPrompt, envNote, cwdNote, shellNote, toneNote, mountNote, mcpNote, closureNote].filter(Boolean).join("\n\n");
|
|
17606
17695
|
const basePrompt = (() => {
|
|
17607
17696
|
let p = new AgentOptions().systemPrompt;
|
|
@@ -17612,7 +17701,7 @@ Windows paths: file tools accept ${cwd} style paths and the same path written ${
|
|
|
17612
17701
|
return { systemPrompt: basePrompt + "\n\n" + extra };
|
|
17613
17702
|
})(),
|
|
17614
17703
|
tools: (() => {
|
|
17615
|
-
if (
|
|
17704
|
+
if (isClaudeCode2) return o.confine ? toolsByName(o.tools ?? DEFAULT_TOOLS).filter((t) => o.permissions?.decide({ name: t.name, args: {} }) !== "deny") : [];
|
|
17616
17705
|
const requested = o.tools ?? DEFAULT_TOOLS;
|
|
17617
17706
|
const base = toolsByName([...requested, ...autoWebTools()]);
|
|
17618
17707
|
const tail = [...o.extraTools ?? []];
|
|
@@ -17646,6 +17735,11 @@ Windows paths: file tools accept ${cwd} style paths and the same path written ${
|
|
|
17646
17735
|
memoryUserDir,
|
|
17647
17736
|
agentsDir: dot("agents"),
|
|
17648
17737
|
instructionFiles: o.lean ? false : o.instructionFiles ?? ["AGENTS.md", "CLAUDE.md"],
|
|
17738
|
+
// the user's global rules (~/.agent/AGENTS.md › AGENTX_EXTRA_DIRS/CLAUDE.md › ~/.claude/CLAUDE.md) — real disk only
|
|
17739
|
+
...o.lean || virtual ? {} : (() => {
|
|
17740
|
+
const f = userInstructionFiles({ cwd });
|
|
17741
|
+
return f.length ? { contextFiles: f.map((p) => ({ path: toVfsPath(p), label: "User instructions (global)" })) } : {};
|
|
17742
|
+
})(),
|
|
17649
17743
|
// Only override the Agent's safety defaults when explicitly configured.
|
|
17650
17744
|
...o.maxTokens != null ? { maxTokens: o.maxTokens } : {},
|
|
17651
17745
|
...o.timeoutMs != null ? { timeoutMs: o.timeoutMs } : {},
|
|
@@ -18096,27 +18190,27 @@ function takeCut(v, forVoiceLine) {
|
|
|
18096
18190
|
const cut = v?.takeInterruptedReply() ?? null;
|
|
18097
18191
|
return splitCut(forVoiceLine ? cut : null);
|
|
18098
18192
|
}
|
|
18099
|
-
function bindOverlapInstinct(v, instinct,
|
|
18193
|
+
function bindOverlapInstinct(v, instinct, live2, decideMs = 900) {
|
|
18100
18194
|
const o = v.options;
|
|
18101
18195
|
const { onDiag } = o;
|
|
18102
18196
|
o.overlapDecideMs = decideMs;
|
|
18103
18197
|
instinct.options.overlapSettleMs = 0;
|
|
18104
18198
|
o.onDiag = (ev) => {
|
|
18105
18199
|
onDiag(ev);
|
|
18106
|
-
if (!
|
|
18200
|
+
if (!live2()) return;
|
|
18107
18201
|
if (ev.kind === "overlap_pause") void instinct.overlap(String(ev.text ?? ""));
|
|
18108
18202
|
else if (/^(?:barge_in|overlap_resume|overlap_end|interrupt|tts_turn_begin)$/.test(ev.kind)) instinct.overlapEnded();
|
|
18109
18203
|
};
|
|
18110
18204
|
Object.assign(instinct.options, {
|
|
18111
18205
|
onYield: () => {
|
|
18112
|
-
if (!
|
|
18206
|
+
if (!live2()) return false;
|
|
18113
18207
|
if (v.decideOverlap("yield")) return;
|
|
18114
18208
|
if (!v.audible) return false;
|
|
18115
18209
|
v.interrupt();
|
|
18116
18210
|
o.onBargeIn("speaking");
|
|
18117
18211
|
},
|
|
18118
18212
|
// `heard` = what Jev judged: the engine absorbs only those words — a reaction that grows past them is re-decided.
|
|
18119
|
-
onKeepTalking: (heard) =>
|
|
18213
|
+
onKeepTalking: (heard) => live2() ? v.decideOverlap("keep_talking", heard) : false
|
|
18120
18214
|
});
|
|
18121
18215
|
}
|
|
18122
18216
|
function bindAckInstinct(v, instinct) {
|
|
@@ -18134,7 +18228,7 @@ function bindAckInstinct(v, instinct) {
|
|
|
18134
18228
|
onDiag(ev);
|
|
18135
18229
|
};
|
|
18136
18230
|
}
|
|
18137
|
-
function bindSecondChannel(v, sc,
|
|
18231
|
+
function bindSecondChannel(v, sc, live2) {
|
|
18138
18232
|
const o = v.options;
|
|
18139
18233
|
const { onPartial, onUtterance, onState, onBargeIn } = o;
|
|
18140
18234
|
let own = false;
|
|
@@ -18145,15 +18239,15 @@ function bindSecondChannel(v, sc, live) {
|
|
|
18145
18239
|
return r.queued.length ? { ...r, full: "", heard: "" } : null;
|
|
18146
18240
|
};
|
|
18147
18241
|
o.onPartial = (t) => {
|
|
18148
|
-
if (
|
|
18242
|
+
if (live2() && (own || !v.audible)) sc.onInterim(t);
|
|
18149
18243
|
onPartial(t);
|
|
18150
18244
|
};
|
|
18151
18245
|
o.onUtterance = ((t, meta) => {
|
|
18152
|
-
if (
|
|
18246
|
+
if (live2() && t.trim()) sc.onUserTurn(t);
|
|
18153
18247
|
onUtterance(t, meta);
|
|
18154
18248
|
});
|
|
18155
18249
|
o.onState = (s) => {
|
|
18156
|
-
if (
|
|
18250
|
+
if (live2() && !own) {
|
|
18157
18251
|
if (s === "speaking") sc.onAgentState("first_audio");
|
|
18158
18252
|
else if (s === "listening") sc.onAgentState("idle");
|
|
18159
18253
|
}
|
|
@@ -18165,14 +18259,14 @@ function bindSecondChannel(v, sc, live) {
|
|
|
18165
18259
|
};
|
|
18166
18260
|
const speakDelta = v.speakDelta.bind(v);
|
|
18167
18261
|
v.speakDelta = ((t, ...rest) => {
|
|
18168
|
-
if (
|
|
18262
|
+
if (live2()) sc.noteReply(t);
|
|
18169
18263
|
return speakDelta(t, ...rest);
|
|
18170
18264
|
});
|
|
18171
18265
|
Object.defineProperty(sc.options, "aec", { get: () => v.usingAec, set: () => {
|
|
18172
18266
|
}, enumerable: true, configurable: true });
|
|
18173
18267
|
Object.assign(sc.options, {
|
|
18174
18268
|
speak: (text, kind) => {
|
|
18175
|
-
if (!
|
|
18269
|
+
if (!live2() || v.audible) return false;
|
|
18176
18270
|
if (kind === "backchannel") return speakBlip(v, text);
|
|
18177
18271
|
own = true;
|
|
18178
18272
|
v.speakFiller(text);
|
|
@@ -18182,7 +18276,7 @@ function bindSecondChannel(v, sc, live) {
|
|
|
18182
18276
|
}
|
|
18183
18277
|
});
|
|
18184
18278
|
}
|
|
18185
|
-
function bindVoiceCall(v, call,
|
|
18279
|
+
function bindVoiceCall(v, call, live2, decideMs = 900) {
|
|
18186
18280
|
const o = v.options;
|
|
18187
18281
|
const { onPartial, onState, onBargeIn, onDiag } = o;
|
|
18188
18282
|
let own = false;
|
|
@@ -18209,17 +18303,17 @@ function bindVoiceCall(v, call, live, decideMs = 900) {
|
|
|
18209
18303
|
v.takeInterruptedReply();
|
|
18210
18304
|
};
|
|
18211
18305
|
o.onPartial = (t) => {
|
|
18212
|
-
if (
|
|
18306
|
+
if (live2() && (own || !v.audible)) call.interim(t, performance.now(), v.usingAec);
|
|
18213
18307
|
onPartial(t);
|
|
18214
18308
|
};
|
|
18215
18309
|
o.onState = (s) => {
|
|
18216
|
-
if (
|
|
18310
|
+
if (live2() && !own && s === "speaking") call.main({ type: "audio" });
|
|
18217
18311
|
onState(s);
|
|
18218
18312
|
};
|
|
18219
18313
|
let filling = false;
|
|
18220
18314
|
const beginSpeech = v.beginSpeech.bind(v);
|
|
18221
18315
|
v.beginSpeech = ((...a) => {
|
|
18222
|
-
if (own && !filling &&
|
|
18316
|
+
if (own && !filling && live2()) {
|
|
18223
18317
|
own = false;
|
|
18224
18318
|
call.main({ type: "audio" }, v.player?.drainMs() ?? 0);
|
|
18225
18319
|
}
|
|
@@ -18227,16 +18321,16 @@ function bindVoiceCall(v, call, live, decideMs = 900) {
|
|
|
18227
18321
|
});
|
|
18228
18322
|
o.onBargeIn = (phase) => {
|
|
18229
18323
|
held2 = void 0;
|
|
18230
|
-
if (
|
|
18324
|
+
if (live2()) call.barge();
|
|
18231
18325
|
onBargeIn(phase);
|
|
18232
18326
|
};
|
|
18233
18327
|
o.overlapDecideMs = decideMs;
|
|
18234
18328
|
o.onDiag = (ev) => {
|
|
18235
18329
|
onDiag(ev);
|
|
18236
|
-
if (!
|
|
18330
|
+
if (!live2() || ev.kind !== "overlap_pause") return;
|
|
18237
18331
|
const heard = String(ev.text ?? "");
|
|
18238
18332
|
void call.overlap(heard).then((verdict) => {
|
|
18239
|
-
if (!
|
|
18333
|
+
if (!live2()) return;
|
|
18240
18334
|
if (verdict === "keep") v.decideOverlap("keep_talking", heard, call.aside(heard) ?? void 0);
|
|
18241
18335
|
else if (verdict === "cut") v.decideOverlap("yield", heard);
|
|
18242
18336
|
});
|
|
@@ -18244,7 +18338,7 @@ function bindVoiceCall(v, call, live, decideMs = 900) {
|
|
|
18244
18338
|
Object.defineProperty(call.fill.options, "aec", { get: () => v.usingAec, set: () => {
|
|
18245
18339
|
}, enumerable: true, configurable: true });
|
|
18246
18340
|
call.options.speak = (text, kind) => {
|
|
18247
|
-
if (!
|
|
18341
|
+
if (!live2() || v.audible) return false;
|
|
18248
18342
|
if (kind === "backchannel") return speakBlip(v, text);
|
|
18249
18343
|
own = true;
|
|
18250
18344
|
filling = true;
|
|
@@ -18716,14 +18810,14 @@ YOU PRESSED: ${s.pressed}` : ""}`).join("\n");
|
|
|
18716
18810
|
You placed this call and an automated phone menu is playing. What it said so far, oldest first:
|
|
18717
18811
|
${menu}
|
|
18718
18812
|
|
|
18719
|
-
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
|
|
18813
|
+
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.`;
|
|
18720
18814
|
}
|
|
18721
18815
|
/** "1", "2#", "WAIT", "Press 1." … → the keys, or '' (wait). */
|
|
18722
18816
|
static parse(raw) {
|
|
18723
18817
|
const t = raw.trim().replace(/^["'`]+|["'`.]+$/g, "");
|
|
18724
18818
|
if (/^wait\b/i.test(t)) return "";
|
|
18725
|
-
const m = t.match(/^(?:press\s*)?([0-9*#]{
|
|
18726
|
-
return m ? m[1] : "";
|
|
18819
|
+
const m = t.match(/^(?:press\s*)?((?:SMS)?[0-9*#]{0,12})$/i);
|
|
18820
|
+
return m && m[1] ? m[1].replace(/sms/i, "SMS") : "";
|
|
18727
18821
|
}
|
|
18728
18822
|
/** A menu line was heard: the keys to press now, or '' (wait). */
|
|
18729
18823
|
async hear(line) {
|
|
@@ -22129,8 +22223,8 @@ function makeRemoteTriggerTool(opts) {
|
|
|
22129
22223
|
if (!target) return `Error: no session matching '${id}' in the global index (~/.agent/sessions).`;
|
|
22130
22224
|
const full = target.meta.id;
|
|
22131
22225
|
if (opts.selfId && full === opts.selfId()) return "Error: that is THIS session \u2014 use Task/TaskBatch for self-delegation.";
|
|
22132
|
-
const
|
|
22133
|
-
if (
|
|
22226
|
+
const live2 = await triggerLive(full, { prompt: text, from: opts.selfId?.() }, dir);
|
|
22227
|
+
if (live2?.ok) return `Delivered to live session ${full} \u2014 it runs there; the user sees it in that terminal.`;
|
|
22134
22228
|
if (!target.meta.cwd || !existsSync8(target.meta.cwd)) return `Error: session ${full} has no reachable cwd (${target.meta.cwd ?? "unknown"}).`;
|
|
22135
22229
|
return new Promise((res) => {
|
|
22136
22230
|
const child = doSpawn(...headlessArgv(opts, text, full), {
|
|
@@ -22163,6 +22257,142 @@ ${answer || "(no output)"}` : `Error: headless run of ${full} exited ${code}: ${
|
|
|
22163
22257
|
};
|
|
22164
22258
|
}
|
|
22165
22259
|
|
|
22260
|
+
// cli/liveStatus.ts
|
|
22261
|
+
import { mkdirSync as mkdirSync12, renameSync as renameSync3, writeFileSync as writeFileSync9 } from "fs";
|
|
22262
|
+
import { homedir as homedir10 } from "os";
|
|
22263
|
+
import { join as join16 } from "path";
|
|
22264
|
+
var log47 = forComponent("live-status");
|
|
22265
|
+
var LiveStatusOptions = class {
|
|
22266
|
+
dir = join16(homedir10(), ".agent", "live");
|
|
22267
|
+
pid = process.pid;
|
|
22268
|
+
cwd = process.cwd();
|
|
22269
|
+
model = () => void 0;
|
|
22270
|
+
jobs = () => void 0;
|
|
22271
|
+
now = () => Date.now();
|
|
22272
|
+
};
|
|
22273
|
+
var LiveStatus = class {
|
|
22274
|
+
options;
|
|
22275
|
+
state = "idle";
|
|
22276
|
+
detail;
|
|
22277
|
+
sessionId;
|
|
22278
|
+
prompts = 0;
|
|
22279
|
+
denied;
|
|
22280
|
+
turns = 0;
|
|
22281
|
+
// turns in flight
|
|
22282
|
+
holds = 0;
|
|
22283
|
+
// open dispatch regions
|
|
22284
|
+
waits = 0;
|
|
22285
|
+
constructor(options) {
|
|
22286
|
+
this.options = { ...new LiveStatusOptions(), ...options };
|
|
22287
|
+
}
|
|
22288
|
+
get file() {
|
|
22289
|
+
return join16(this.options.dir, `${this.options.pid}.json`);
|
|
22290
|
+
}
|
|
22291
|
+
/** A turn, a dispatch region or a human wait is open (the REPL is not at rest). */
|
|
22292
|
+
get busy() {
|
|
22293
|
+
return this.turns > 0 || this.holds > 0 || this.waits > 0;
|
|
22294
|
+
}
|
|
22295
|
+
/** Session started or its id changed (/resume, /clear). */
|
|
22296
|
+
session(id) {
|
|
22297
|
+
this.sessionId = id;
|
|
22298
|
+
this.write();
|
|
22299
|
+
}
|
|
22300
|
+
/** A dispatch region opens: no `idle` until it closes. */
|
|
22301
|
+
hold() {
|
|
22302
|
+
this.holds++;
|
|
22303
|
+
}
|
|
22304
|
+
release() {
|
|
22305
|
+
this.holds = Math.max(0, this.holds - 1);
|
|
22306
|
+
this.settle();
|
|
22307
|
+
}
|
|
22308
|
+
/** A model turn starts. `machine` = not a human prompt (trigger / job wake / schedule): not counted. */
|
|
22309
|
+
turnStart(o = {}) {
|
|
22310
|
+
this.turns++;
|
|
22311
|
+
if (!o.machine) this.prompts++;
|
|
22312
|
+
this.denied = void 0;
|
|
22313
|
+
this.set("running", o.detail);
|
|
22314
|
+
}
|
|
22315
|
+
turnEnd() {
|
|
22316
|
+
this.turns = Math.max(0, this.turns - 1);
|
|
22317
|
+
this.settle();
|
|
22318
|
+
}
|
|
22319
|
+
/** A human wait (question, permission, confirm). Returns the release: back to running (or idle when nothing runs). */
|
|
22320
|
+
waiting(detail) {
|
|
22321
|
+
const prev = this.state === "waiting" ? void 0 : this.state;
|
|
22322
|
+
this.waits++;
|
|
22323
|
+
this.set("waiting", detail);
|
|
22324
|
+
let done = false;
|
|
22325
|
+
return () => {
|
|
22326
|
+
if (done) return;
|
|
22327
|
+
done = true;
|
|
22328
|
+
this.waits--;
|
|
22329
|
+
if (this.state === "exited" || this.waits > 0) return;
|
|
22330
|
+
this.set(this.turns > 0 ? "running" : prev ?? "idle");
|
|
22331
|
+
this.settle();
|
|
22332
|
+
};
|
|
22333
|
+
}
|
|
22334
|
+
/** Wrap a human wait. */
|
|
22335
|
+
async wait(detail, fn) {
|
|
22336
|
+
const end = this.waiting(detail);
|
|
22337
|
+
try {
|
|
22338
|
+
return await fn();
|
|
22339
|
+
} finally {
|
|
22340
|
+
end();
|
|
22341
|
+
}
|
|
22342
|
+
}
|
|
22343
|
+
/** The permission policy refused a tool: recorded on the current state until the next turn starts. */
|
|
22344
|
+
deny(d) {
|
|
22345
|
+
this.denied = d;
|
|
22346
|
+
this.write();
|
|
22347
|
+
}
|
|
22348
|
+
exited(detail) {
|
|
22349
|
+
if (this.state === "exited") return;
|
|
22350
|
+
this.set("exited", detail);
|
|
22351
|
+
}
|
|
22352
|
+
snapshot() {
|
|
22353
|
+
const jobs = this.options.jobs();
|
|
22354
|
+
return {
|
|
22355
|
+
state: this.state,
|
|
22356
|
+
...this.detail ? { detail: this.detail } : {},
|
|
22357
|
+
pid: this.options.pid,
|
|
22358
|
+
...this.sessionId ? { sessionId: this.sessionId } : {},
|
|
22359
|
+
cwd: this.options.cwd,
|
|
22360
|
+
...this.options.model() ? { model: this.options.model() } : {},
|
|
22361
|
+
prompts: this.prompts,
|
|
22362
|
+
...jobs !== void 0 ? { jobs } : {},
|
|
22363
|
+
...this.denied ? { denied: this.denied } : {},
|
|
22364
|
+
at: this.options.now()
|
|
22365
|
+
};
|
|
22366
|
+
}
|
|
22367
|
+
settle() {
|
|
22368
|
+
if (this.state === "exited" || this.turns > 0 || this.holds > 0 || this.waits > 0) return;
|
|
22369
|
+
if (this.state !== "idle") this.set("idle");
|
|
22370
|
+
}
|
|
22371
|
+
set(state, detail) {
|
|
22372
|
+
if (this.state === "exited") return;
|
|
22373
|
+
this.state = state;
|
|
22374
|
+
this.detail = detail;
|
|
22375
|
+
this.write();
|
|
22376
|
+
}
|
|
22377
|
+
write() {
|
|
22378
|
+
try {
|
|
22379
|
+
mkdirSync12(this.options.dir, { recursive: true, mode: 448 });
|
|
22380
|
+
const tmp = `${this.file}.${process.pid}.tmp`;
|
|
22381
|
+
writeFileSync9(tmp, JSON.stringify(this.snapshot()) + "\n");
|
|
22382
|
+
renameSync3(tmp, this.file);
|
|
22383
|
+
} catch (e) {
|
|
22384
|
+
log47.debug("live status write failed", e);
|
|
22385
|
+
}
|
|
22386
|
+
}
|
|
22387
|
+
};
|
|
22388
|
+
var live;
|
|
22389
|
+
function setLive(s) {
|
|
22390
|
+
live = s;
|
|
22391
|
+
}
|
|
22392
|
+
function liveWait(detail, fn) {
|
|
22393
|
+
return live ? live.wait(detail, fn) : fn();
|
|
22394
|
+
}
|
|
22395
|
+
|
|
22166
22396
|
// cli/cli.ts
|
|
22167
22397
|
var forceColor = process.env.FORCE_COLOR != null && process.env.FORCE_COLOR !== "" && process.env.FORCE_COLOR !== "0";
|
|
22168
22398
|
var useColor = forceColor || !process.env.NO_COLOR && !!process.stdout.isTTY && !!process.stderr.isTTY;
|
|
@@ -22179,7 +22409,7 @@ var strike = C("9");
|
|
|
22179
22409
|
var link = (text, url) => useColor ? `\x1B]8;;${url}\x1B\\${cyan(text)}\x1B]8;;\x1B\\` : `${text} (${url})`;
|
|
22180
22410
|
var mdPalette = { bold, dim, cyan, italic, strike, green, link };
|
|
22181
22411
|
var err = (s) => process.stderr.write(s);
|
|
22182
|
-
var
|
|
22412
|
+
var log48 = forComponent("cli");
|
|
22183
22413
|
var VERSION = (() => {
|
|
22184
22414
|
try {
|
|
22185
22415
|
return JSON.parse(readFileSync10(new URL("../package.json", import.meta.url), "utf8")).version ?? "?";
|
|
@@ -22305,7 +22535,12 @@ function parseArgs(argv) {
|
|
|
22305
22535
|
else if (x === "--plan") a.plan = true;
|
|
22306
22536
|
else if (x === "--ask") a.ask = true;
|
|
22307
22537
|
else if (x === "--yes" || x === "-y") a.yes = true;
|
|
22308
|
-
else if (x === "--
|
|
22538
|
+
else if (x === "--trust") a.trust = true;
|
|
22539
|
+
else if (x === "--prompt") {
|
|
22540
|
+
a.prompt = argv.slice(i + 1).join(" ").trim();
|
|
22541
|
+
if (!a.prompt) throw new Error("--prompt requires a value (and must be the last argument)");
|
|
22542
|
+
break;
|
|
22543
|
+
} else if (x === "--vfs" || x === "--sandbox") a.vfs = true;
|
|
22309
22544
|
else if (x === "--scratch") a.scratch = true;
|
|
22310
22545
|
else if (x === "--no-scratch") a.scratch = false;
|
|
22311
22546
|
else if (x === "--update") a.update = true;
|
|
@@ -22390,6 +22625,7 @@ function parseArgs(argv) {
|
|
|
22390
22625
|
if (a.boddb && a.vfs) throw new Error("--boddb and --sandbox are mutually exclusive (both are non-disk filesystems; pick one)");
|
|
22391
22626
|
if (a.seed && !a.boddb) throw new Error("--seed only applies with --boddb (it seeds the database from cwd on first run)");
|
|
22392
22627
|
if (a.worktree && (a.vfs || a.boddb)) throw new Error("--worktree is a real-disk concept \u2014 incompatible with --vfs/--boddb");
|
|
22628
|
+
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)");
|
|
22393
22629
|
if (a.duplex && (a.task || a.print)) throw new Error("--duplex is interactive-only (a conversational mode) \u2014 drop the task/-p");
|
|
22394
22630
|
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");
|
|
22395
22631
|
if (a.keepAlive && (!a.print || !a.inputFormat)) throw new Error("--keep-alive needs -p --input-format stream-json --output-format stream-json");
|
|
@@ -22443,6 +22679,8 @@ Flags:
|
|
|
22443
22679
|
--ask confirm each mutating tool (bash/Shell/Write/Edit/\u2026) \u2014 needs a terminal to
|
|
22444
22680
|
approve on; rejected up front when detached (use --yes / permissions rules)
|
|
22445
22681
|
--yes, -y auto-approve mutating tools (no prompts) \u2014 for trusted/unattended runs
|
|
22682
|
+
--trust trust this directory without asking (permission prompts unchanged)
|
|
22683
|
+
--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
|
|
22446
22684
|
--update check for updates and install if available (no keys needed)
|
|
22447
22685
|
--no-update-check skip the automatic update check on startup
|
|
22448
22686
|
--verbose, --debug verbose logs (sets DEBUG=* \u2014 tool args, hook decisions, retries)
|
|
@@ -22556,10 +22794,12 @@ function printModels() {
|
|
|
22556
22794
|
if (!byProvider.has(provider)) byProvider.set(provider, []);
|
|
22557
22795
|
byProvider.get(provider).push(id);
|
|
22558
22796
|
}
|
|
22797
|
+
if (codexModels().length) byProvider.set("codex", codexModels().map((m) => `codex/${m}`));
|
|
22559
22798
|
for (const [provider, ids] of Array.from(byProvider.entries()).sort((a, b) => a[0].localeCompare(b[0]))) {
|
|
22560
22799
|
console.log(`
|
|
22561
22800
|
${provider}`);
|
|
22562
|
-
|
|
22801
|
+
if (provider === "codex") console.log(` (Codex subscription \xB7 ${process.env.CODEX_HOME ?? "~/.codex"})`);
|
|
22802
|
+
else ids.sort((a, b) => (getModelInfo(b)?.releaseDate ?? "").localeCompare(getModelInfo(a)?.releaseDate ?? ""));
|
|
22563
22803
|
for (const id of ids) {
|
|
22564
22804
|
const info = getModelInfo(id);
|
|
22565
22805
|
const meta = [info?.displayName, info?.releaseDate].filter(Boolean).join(" \xB7 ");
|
|
@@ -22567,8 +22807,27 @@ ${provider}`);
|
|
|
22567
22807
|
}
|
|
22568
22808
|
}
|
|
22569
22809
|
}
|
|
22810
|
+
var codexModels = /* @__PURE__ */ (() => {
|
|
22811
|
+
let c;
|
|
22812
|
+
return () => c ??= hasCommand("codex") ? listCliModels("codex").map((m) => m.value) : [];
|
|
22813
|
+
})();
|
|
22814
|
+
function codexRoute(want, served) {
|
|
22815
|
+
if (want.startsWith("codex/")) {
|
|
22816
|
+
const id = want.slice("codex/".length);
|
|
22817
|
+
if (served.includes(id)) return want;
|
|
22818
|
+
throw new Error(served.length ? `model "${want}" is not served by this Codex login (${process.env.CODEX_HOME ?? "~/.codex"}). Available: ${served.map((m) => `codex/${m}`).join(", ")}` : `model "${want}" needs the Codex CLI signed in to a ChatGPT subscription (no \`codex\` on PATH, or no models_cache.json in ${process.env.CODEX_HOME ?? "~/.codex"}). Run \`CODEX_HOME=<profile> codex login\`.`);
|
|
22819
|
+
}
|
|
22820
|
+
return !want.includes("/") && served.includes(want) ? `codex/${want}` : void 0;
|
|
22821
|
+
}
|
|
22822
|
+
function codexBilling(model, home = process.env.CODEX_HOME) {
|
|
22823
|
+
if (!model.startsWith("codex/")) return "";
|
|
22824
|
+
const base = home ? home.replace(/\/+$/, "").split("/").pop() : ".codex";
|
|
22825
|
+
return ` \xB7 Codex subscription \xB7 ${base.replace(/^\.codex-?/, "") || "default"}`;
|
|
22826
|
+
}
|
|
22570
22827
|
function resolveModelOrNewest(model) {
|
|
22571
22828
|
const want = model ?? new AgentOptions().model;
|
|
22829
|
+
const routed = codexRoute(want, codexModels());
|
|
22830
|
+
if (routed) return routed;
|
|
22572
22831
|
const resolved = resolveModel(want);
|
|
22573
22832
|
if (isModelSupported(resolved)) return resolved;
|
|
22574
22833
|
const provider = getProviderFromModel(want) ?? void 0;
|
|
@@ -22594,10 +22853,10 @@ function loadEnvFile(file) {
|
|
|
22594
22853
|
}
|
|
22595
22854
|
function loadInstallEnv() {
|
|
22596
22855
|
let dir = dirname6(import.meta.path);
|
|
22597
|
-
for (let i = 0; i < 5 && !existsSync9(
|
|
22856
|
+
for (let i = 0; i < 5 && !existsSync9(join17(dir, "package.json")); i++) dir = dirname6(dir);
|
|
22598
22857
|
for (const name of [".env", ".env.local"]) {
|
|
22599
|
-
loadEnvFile(
|
|
22600
|
-
loadEnvFile(
|
|
22858
|
+
loadEnvFile(join17(dir, name));
|
|
22859
|
+
loadEnvFile(join17(homedir11(), ".agent", name));
|
|
22601
22860
|
}
|
|
22602
22861
|
}
|
|
22603
22862
|
function paraVaultToken() {
|
|
@@ -22636,20 +22895,19 @@ function apiKeysFromEnv() {
|
|
|
22636
22895
|
}
|
|
22637
22896
|
return keys;
|
|
22638
22897
|
}
|
|
22639
|
-
var KEYLESS_PROVIDERS = /* @__PURE__ */ new Set(["claude-code"]);
|
|
22640
22898
|
function modelUsable(model, apiKeys) {
|
|
22641
22899
|
const p = model.split("/")[0];
|
|
22642
|
-
return
|
|
22900
|
+
return isKeyless(p) || !!apiKeys[p];
|
|
22643
22901
|
}
|
|
22644
22902
|
function duplexModels(o) {
|
|
22645
22903
|
const dflt = new DuplexAgentOptions(), notes = [];
|
|
22646
|
-
const cc = o.actModel
|
|
22904
|
+
const cc = isClaudeCode(o.actModel), anthropic = !!o.apiKeys.anthropic;
|
|
22647
22905
|
const why = (m) => `no ${m.split("/")[0].toUpperCase()}_API_KEY`;
|
|
22648
22906
|
const asked = o.voiceModel ?? o.reflexModel;
|
|
22649
22907
|
let reflexModel = asked ? resolveModelOrNewest(asked) : void 0;
|
|
22650
22908
|
const reflex = reflexModel ?? dflt.reflexModel;
|
|
22651
22909
|
if (!modelUsable(reflex, o.apiKeys)) {
|
|
22652
|
-
const to = anthropic ? latestClaude("haiku") : cc ? "claude-code/haiku" : o.actModel
|
|
22910
|
+
const to = anthropic ? latestClaude("haiku") : cc ? "claude-code/haiku" : isCursor(o.actModel) ? void 0 : o.actModel;
|
|
22653
22911
|
if (to) reflexModel = to;
|
|
22654
22912
|
notes.push(`voice model ${reflex} can't run here (${why(reflex)})${to ? ` \u2014 using ${to}` : ""}`);
|
|
22655
22913
|
}
|
|
@@ -22780,14 +23038,16 @@ function makeHost(format = "text", opts) {
|
|
|
22780
23038
|
`));
|
|
22781
23039
|
},
|
|
22782
23040
|
async confirm(prompt) {
|
|
22783
|
-
|
|
22784
|
-
|
|
22785
|
-
|
|
22786
|
-
|
|
22787
|
-
|
|
22788
|
-
|
|
22789
|
-
|
|
22790
|
-
|
|
23041
|
+
return liveWait(`confirm: ${prompt}`, async () => {
|
|
23042
|
+
const v = await selectMenu(process.stderr, { title: `? ${prompt}`, items: [{ label: "Yes", value: "y" }, { label: "No", value: "n" }], current: "n" });
|
|
23043
|
+
if (v !== null) return v === "y";
|
|
23044
|
+
const io = createInterface({ input: keyInput, output: process.stderr });
|
|
23045
|
+
try {
|
|
23046
|
+
return /^y(es)?$/i.test((await io.question(yellow(` ? ${prompt} [y/N] `))).trim());
|
|
23047
|
+
} finally {
|
|
23048
|
+
io.close();
|
|
23049
|
+
}
|
|
23050
|
+
});
|
|
22791
23051
|
},
|
|
22792
23052
|
// Only offer `ask` when a human can actually SEE the prompt. Headless/piped (`-p`, redirected,
|
|
22793
23053
|
// no TTY) → omit it: AskUserQuestion then parks the question and ends the run with
|
|
@@ -22798,18 +23058,20 @@ function makeHost(format = "text", opts) {
|
|
|
22798
23058
|
async ask(q2) {
|
|
22799
23059
|
const title = `? ${q2.header ? "[" + q2.header + "] " : ""}${q2.question}`;
|
|
22800
23060
|
spinner.stop();
|
|
22801
|
-
|
|
22802
|
-
|
|
22803
|
-
|
|
22804
|
-
|
|
22805
|
-
|
|
22806
|
-
|
|
22807
|
-
|
|
22808
|
-
|
|
22809
|
-
|
|
22810
|
-
|
|
22811
|
-
|
|
22812
|
-
|
|
23061
|
+
return liveWait(`question: ${q2.question}`, async () => {
|
|
23062
|
+
const v = await selectMenu(process.stderr, { title, items: q2.options.map((o) => ({ label: o.label, value: o.label, desc: o.description })) });
|
|
23063
|
+
if (v !== null) return v;
|
|
23064
|
+
const io = createInterface({ input: keyInput, output: process.stderr });
|
|
23065
|
+
try {
|
|
23066
|
+
const lines = [yellow(" " + title)];
|
|
23067
|
+
q2.options.forEach((o, i) => lines.push(` ${i + 1}) ${o.label}${o.description ? dim(" \u2014 " + o.description) : ""}`));
|
|
23068
|
+
const ans = (await io.question(lines.join("\n") + "\n > ")).trim();
|
|
23069
|
+
const n = Number(ans);
|
|
23070
|
+
return Number.isInteger(n) && q2.options[n - 1] ? q2.options[n - 1].label : ans;
|
|
23071
|
+
} finally {
|
|
23072
|
+
io.close();
|
|
23073
|
+
}
|
|
23074
|
+
});
|
|
22813
23075
|
}
|
|
22814
23076
|
} : {}
|
|
22815
23077
|
};
|
|
@@ -23096,10 +23358,10 @@ function autoRouteSend(args, agent, session, pof) {
|
|
|
23096
23358
|
};
|
|
23097
23359
|
}
|
|
23098
23360
|
function turnCost(model, usage) {
|
|
23099
|
-
const priced = model
|
|
23361
|
+
const priced = isClaudeCode(model) ? `anthropic/${resolveModelAlias(model.slice("claude-code/".length))}` : model;
|
|
23100
23362
|
return costOf(getModelInfo(priced)?.pricing, usage?.promptTokens ?? 0, usage?.completionTokens ?? 0, usage?.cacheCreationTokens ?? 0, usage?.cacheReadTokens ?? 0, priced);
|
|
23101
23363
|
}
|
|
23102
|
-
async function evaluateGoal(ai, condition, transcript,
|
|
23364
|
+
async function evaluateGoal(ai, condition, transcript, log49) {
|
|
23103
23365
|
const recent = transcript.filter((m) => m.role === "assistant").slice(-8).map((m) => {
|
|
23104
23366
|
const text = typeof m.content === "string" ? m.content : m.content.filter((p) => p.type === "text").map((p) => p.text).join(" ");
|
|
23105
23367
|
return text.slice(0, 600);
|
|
@@ -23119,7 +23381,7 @@ ${recent}` }
|
|
|
23119
23381
|
const match = r.content.match(/\{[\s\S]*\}/);
|
|
23120
23382
|
if (match) return JSON.parse(match[0]);
|
|
23121
23383
|
} catch (e) {
|
|
23122
|
-
|
|
23384
|
+
log49(dim(` (goal evaluator error: ${e?.message ?? e})
|
|
23123
23385
|
`));
|
|
23124
23386
|
}
|
|
23125
23387
|
return { met: false, reason: "evaluation unclear" };
|
|
@@ -23189,7 +23451,12 @@ function resolvePermMode(args, interactiveCapable) {
|
|
|
23189
23451
|
if (interactiveCapable && args.outputFormat === "text") return { gate: "ask" };
|
|
23190
23452
|
return { gate: "allow", notice: "unattended: mutating tools auto-approved \u2014 pass --ask to gate, --vfs to sandbox, --yes to silence" };
|
|
23191
23453
|
}
|
|
23454
|
+
var liveDeny = (call, reason) => live?.deny({ tool: call.name, what: summarizeCall(call.name, call.args).slice(0, 120), reason });
|
|
23192
23455
|
function makeAskResolver(cwd) {
|
|
23456
|
+
const resolve1 = askResolver(cwd);
|
|
23457
|
+
return (call) => canPrompt ? liveWait(`permission: ${call.name}`, () => resolve1(call)) : resolve1(call);
|
|
23458
|
+
}
|
|
23459
|
+
function askResolver(cwd) {
|
|
23193
23460
|
return async (call) => {
|
|
23194
23461
|
if (!canPrompt) {
|
|
23195
23462
|
err(dim(` \u26A0 ${call.name} needs approval but no terminal is attached \u2014 denied. Use --yes, or an allow rule in .agent/permissions.json.
|
|
@@ -23270,7 +23537,7 @@ function optsFor(args, ai, cfg = {}, extraTools = []) {
|
|
|
23270
23537
|
stream: args.stream,
|
|
23271
23538
|
host: makeHost(args.outputFormat, { stream: true }),
|
|
23272
23539
|
planMode: args.plan || cfg.planMode || false,
|
|
23273
|
-
permissions: rules.length || args.onlyTools ? new PermissionPolicy({ rules, default: args.onlyTools ? "deny" : "allow", host: makeHost(), ask: makeAskResolver(resolve5(args.cwd ?? process.cwd())) }) : void 0,
|
|
23540
|
+
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,
|
|
23274
23541
|
subagents: args.subagents || cfg.subagents || false,
|
|
23275
23542
|
maxSteps: args.maxSteps ?? cfg.maxSteps,
|
|
23276
23543
|
reasoning: args.reasoning ?? cfg.reasoning,
|
|
@@ -23348,13 +23615,13 @@ function mcpAgentTools(mounted, opts) {
|
|
|
23348
23615
|
return tools;
|
|
23349
23616
|
}
|
|
23350
23617
|
async function closeMcp(mounted) {
|
|
23351
|
-
await Promise.all(mounted.map((m) => m.client.close().catch((e) =>
|
|
23618
|
+
await Promise.all(mounted.map((m) => m.client.close().catch((e) => log48.debug("mcp close failed", e))));
|
|
23352
23619
|
}
|
|
23353
23620
|
var IMG_EXT = { ".png": "image/png", ".jpg": "image/jpeg", ".jpeg": "image/jpeg", ".gif": "image/gif", ".webp": "image/webp" };
|
|
23354
23621
|
function mentionRefs(line) {
|
|
23355
23622
|
return [...line.matchAll(/(?:^|\s)@(?:"([^"]+)"|(\S+))/g)].map((m) => m[1] ?? m[2].replace(/[?!.,;:)\]}'">]+$/, "")).filter(Boolean);
|
|
23356
23623
|
}
|
|
23357
|
-
var untilde = (p) => p.startsWith("~/") || IS_WIN && p.startsWith("~\\") ?
|
|
23624
|
+
var untilde = (p) => p.startsWith("~/") || IS_WIN && p.startsWith("~\\") ? join17(homedir11(), p.slice(2)) : p;
|
|
23358
23625
|
var PATH_LIKE = IS_WIN ? /^(\/|~[\\/]|\.\.?[\\/]|[A-Za-z]:[\\/]|\\\\)/ : /^(\/|~\/|\.\/|\.\.\/)/;
|
|
23359
23626
|
var userPath = (cwd, p) => {
|
|
23360
23627
|
const t = untilde(p);
|
|
@@ -23407,7 +23674,7 @@ async function expandMentions(fs, line) {
|
|
|
23407
23674
|
if (loaded.includes(ref) || missing.includes(ref)) continue;
|
|
23408
23675
|
if (ref.includes(":") && mcpMentionResolver) {
|
|
23409
23676
|
const body = await mcpMentionResolver(ref).catch((e) => {
|
|
23410
|
-
|
|
23677
|
+
log48.debug("mcp mention resolve failed", e);
|
|
23411
23678
|
return null;
|
|
23412
23679
|
});
|
|
23413
23680
|
if (body != null) {
|
|
@@ -23433,7 +23700,7 @@ ${await fs.readFile(path)}`);
|
|
|
23433
23700
|
${blocks.join("\n\n")}` : line, loaded, missing };
|
|
23434
23701
|
}
|
|
23435
23702
|
function applyTurnMode(agent, session, task, flags = {}, onModel) {
|
|
23436
|
-
const p = parseDirectives(task, { strict: true, keys: ["model", "turns", "delegate", "advisor", "mode"], warn: (m) =>
|
|
23703
|
+
const p = parseDirectives(task, { strict: true, keys: ["model", "turns", "delegate", "advisor", "mode"], warn: (m) => log48.debug(m) });
|
|
23437
23704
|
const d = p.directives, isMode = !!(d.delegate || d.advisor || d.modeOff);
|
|
23438
23705
|
if (p.unresolvedModel && /->|<-|delegate:|advisor:/.test(task.slice(0, task.length - p.prompt.length))) {
|
|
23439
23706
|
err(red(` \u2717 unknown model "${p.unresolvedModel}"${p.ambiguous ? ` (could be: ${p.ambiguous.join(", ")})` : ""} \u2014 turn not sent
|
|
@@ -23526,7 +23793,7 @@ async function runTurn(agent, store, session, task, cp, cwd = process.cwd(), sen
|
|
|
23526
23793
|
try {
|
|
23527
23794
|
store.save(session);
|
|
23528
23795
|
} catch (ex) {
|
|
23529
|
-
|
|
23796
|
+
log48.debug("mid-turn session flush failed", ex);
|
|
23530
23797
|
}
|
|
23531
23798
|
}
|
|
23532
23799
|
return origNotify(e);
|
|
@@ -23598,6 +23865,7 @@ async function runTurn(agent, store, session, task, cp, cwd = process.cwd(), sen
|
|
|
23598
23865
|
}
|
|
23599
23866
|
function bindClaudeCodeSession(agent, session) {
|
|
23600
23867
|
const po = agent.options.providerOptions;
|
|
23868
|
+
if (po?.codexSession) return bindCodexThread(agent, session, po);
|
|
23601
23869
|
if (!po?.claudeCodeSession) return void 0;
|
|
23602
23870
|
const cc = session.meta.cc, model = agent.options.model;
|
|
23603
23871
|
let id;
|
|
@@ -23609,7 +23877,18 @@ function bindClaudeCodeSession(agent, session) {
|
|
|
23609
23877
|
session.meta.cc = ok && id ? { id, n: agent.transcript.length, model } : void 0;
|
|
23610
23878
|
};
|
|
23611
23879
|
}
|
|
23612
|
-
|
|
23880
|
+
function bindCodexThread(agent, session, po) {
|
|
23881
|
+
const cx = session.meta.codex, model = agent.options.model;
|
|
23882
|
+
let id;
|
|
23883
|
+
const resume = cx && cx.model === model && cx.n === agent.transcript.length ? cx.thread : void 0;
|
|
23884
|
+
agent.options.providerOptions = { ...po, resume, onCodexThread: (t) => {
|
|
23885
|
+
id = t;
|
|
23886
|
+
} };
|
|
23887
|
+
return (ok) => {
|
|
23888
|
+
session.meta.codex = ok && id ? { thread: id, n: agent.transcript.length, model } : void 0;
|
|
23889
|
+
};
|
|
23890
|
+
}
|
|
23891
|
+
var remintSessionImages = (data, store, cwd) => remintImageRefs(data.messages, [join17(store.dir, `${data.meta.id}.images`), cwd]);
|
|
23613
23892
|
function startSession(args, store, agent, cwd) {
|
|
23614
23893
|
if (args.resume || args.cont) {
|
|
23615
23894
|
const data = args.resume ? store.load(args.resume) ?? globalSessionLoad(args.resume) : store.latestData();
|
|
@@ -23656,25 +23935,25 @@ var AGENTS_MD_TEMPLATE = `# ${"${name}"}
|
|
|
23656
23935
|
`;
|
|
23657
23936
|
function initInstructions(cwd) {
|
|
23658
23937
|
for (const f of ["AGENTS.md", "CLAUDE.md"]) {
|
|
23659
|
-
if (existsSync9(
|
|
23938
|
+
if (existsSync9(join17(cwd, f))) {
|
|
23660
23939
|
err(yellow(` ${f} already exists \u2014 leaving it as-is
|
|
23661
23940
|
`));
|
|
23662
23941
|
return;
|
|
23663
23942
|
}
|
|
23664
23943
|
}
|
|
23665
|
-
const path =
|
|
23666
|
-
|
|
23944
|
+
const path = join17(cwd, "AGENTS.md");
|
|
23945
|
+
writeFileSync10(path, AGENTS_MD_TEMPLATE.replace("${name}", basename4(cwd)));
|
|
23667
23946
|
err(green(` created ${path}
|
|
23668
23947
|
`) + dim(" edit it, then it auto-loads into every run.\n"));
|
|
23669
23948
|
}
|
|
23670
23949
|
function persistSetting(cwd, key, value) {
|
|
23671
|
-
const path =
|
|
23950
|
+
const path = join17(cwd, ".agent", "settings.json");
|
|
23672
23951
|
try {
|
|
23673
23952
|
const obj = existsSync9(path) ? JSON.parse(readFileSync10(path, "utf8")) : {};
|
|
23674
23953
|
if (obj[key] === value) return;
|
|
23675
23954
|
obj[key] = value;
|
|
23676
|
-
|
|
23677
|
-
|
|
23955
|
+
mkdirSync13(dirname6(path), { recursive: true });
|
|
23956
|
+
writeFileSync10(path, JSON.stringify(obj, null, 2) + "\n");
|
|
23678
23957
|
} catch (e) {
|
|
23679
23958
|
err(yellow(` \u26A0 couldn't persist ${key} to ${path} \u2014 ${e?.message ?? e}
|
|
23680
23959
|
`));
|
|
@@ -23690,23 +23969,24 @@ var isCancelTeardown = (e) => {
|
|
|
23690
23969
|
function installCancelGuards(mounted) {
|
|
23691
23970
|
process.on("unhandledRejection", (e) => {
|
|
23692
23971
|
if (isCancelTeardown(e)) {
|
|
23693
|
-
|
|
23972
|
+
log48.debug("suppressed unhandledRejection (cursor stream cancel)", e);
|
|
23694
23973
|
return;
|
|
23695
23974
|
}
|
|
23696
|
-
|
|
23975
|
+
log48.error("unhandledRejection", e);
|
|
23697
23976
|
});
|
|
23698
23977
|
process.on("uncaughtException", (e) => {
|
|
23699
23978
|
if (isCancelTeardown(e)) {
|
|
23700
|
-
|
|
23979
|
+
log48.debug("suppressed uncaughtException (cursor stream cancel)", e);
|
|
23701
23980
|
return;
|
|
23702
23981
|
}
|
|
23703
23982
|
console.error(e);
|
|
23983
|
+
live?.exited("crash");
|
|
23704
23984
|
void closeMcp(mounted);
|
|
23705
23985
|
process.exit(1);
|
|
23706
23986
|
});
|
|
23707
23987
|
}
|
|
23708
23988
|
async function repl(args, ai, cfg, cwd) {
|
|
23709
|
-
const oauth = new McpOAuth({ storePath:
|
|
23989
|
+
const oauth = new McpOAuth({ storePath: join17(cwd, ".agent", "mcp-auth.json") });
|
|
23710
23990
|
const mounted = await mountMcp(cfg, oauth);
|
|
23711
23991
|
let mcpToolNames = [];
|
|
23712
23992
|
const initialMcpTools = mcpAgentTools(mounted);
|
|
@@ -23816,11 +24096,11 @@ async function repl(args, ai, cfg, cwd) {
|
|
|
23816
24096
|
const hint = summarizeCall(call2.name, call2.args).slice(0, 80);
|
|
23817
24097
|
if (cfg.voiceAskUi !== "relay") {
|
|
23818
24098
|
editorRef?.suspend();
|
|
23819
|
-
const v = await selectMenu(process.stderr, {
|
|
24099
|
+
const v = await liveWait(`permission: ${call2.name}`, () => selectMenu(process.stderr, {
|
|
23820
24100
|
title: `? background worker asks to run ${call2.name} ${hint}`,
|
|
23821
24101
|
items: [{ label: "Allow once", value: "y" }, { label: "Allow always", value: "a" }, { label: "Deny", value: "n" }],
|
|
23822
24102
|
current: "y"
|
|
23823
|
-
});
|
|
24103
|
+
}));
|
|
23824
24104
|
editorRef?.resume();
|
|
23825
24105
|
editorRef?.redrawNow();
|
|
23826
24106
|
if (v === "a") {
|
|
@@ -23981,14 +24261,14 @@ async function repl(args, ai, cfg, cwd) {
|
|
|
23981
24261
|
onTaskStart: async (_id, label) => {
|
|
23982
24262
|
await checkpoints.begin(label);
|
|
23983
24263
|
},
|
|
23984
|
-
lookRoots: [
|
|
24264
|
+
lookRoots: [homedir11(), join17(homedir11(), "Documents")],
|
|
23985
24265
|
// QuickLook: a spoken "Projects/X" usually means ~/Documents/Projects/X
|
|
23986
24266
|
// The jail deny-lists .git/** (VCS internals can carry credentials), so the engine's fs-based
|
|
23987
24267
|
// 'branch' lookup can't see it — supply it host-side (one safe read-only file).
|
|
23988
24268
|
quickLook: {
|
|
23989
24269
|
branch: () => {
|
|
23990
24270
|
try {
|
|
23991
|
-
const head = readFileSync10(
|
|
24271
|
+
const head = readFileSync10(join17(cwd, ".git", "HEAD"), "utf8").trim();
|
|
23992
24272
|
return head.startsWith("ref: refs/heads/") ? `branch: ${head.slice("ref: refs/heads/".length)}` : `detached HEAD at ${head.slice(0, 12)}`;
|
|
23993
24273
|
} catch {
|
|
23994
24274
|
return "not a git repository";
|
|
@@ -24117,7 +24397,7 @@ ${SPOKEN_TURN}`, { id });
|
|
|
24117
24397
|
editorRef?.abort();
|
|
24118
24398
|
}
|
|
24119
24399
|
} catch (e) {
|
|
24120
|
-
|
|
24400
|
+
log48.error("call turn failed", e);
|
|
24121
24401
|
} finally {
|
|
24122
24402
|
rec.running = false;
|
|
24123
24403
|
call?.main({ type: "done", id });
|
|
@@ -24179,7 +24459,7 @@ ${SPOKEN_TURN}`, { id });
|
|
|
24179
24459
|
const applyPosture = (p) => {
|
|
24180
24460
|
posture = p;
|
|
24181
24461
|
const ask = p === "acceptEdits" ? askFor(["bash", "Shell"]) : askFor(ASK_MUTATING);
|
|
24182
|
-
work.permissions = new PermissionPolicy({ rules: [...baseRules(), ...ask], default: "allow", host: duplex ? void 0 : makeHost(), ask: duplex ? duplexAsk : makeAskResolver(cwd) });
|
|
24462
|
+
work.permissions = new PermissionPolicy({ rules: [...baseRules(), ...ask], default: "allow", host: duplex ? void 0 : makeHost(), ask: duplex ? duplexAsk : makeAskResolver(cwd), onDeny: liveDeny });
|
|
24183
24463
|
if (!duplex) {
|
|
24184
24464
|
agent.options.planMode = p === "plan";
|
|
24185
24465
|
agent.reprepare();
|
|
@@ -24267,16 +24547,17 @@ ${SPOKEN_TURN}`, { id });
|
|
|
24267
24547
|
const pendingImages = [];
|
|
24268
24548
|
const bangContext = [];
|
|
24269
24549
|
const grabClipboardAttachment = () => {
|
|
24270
|
-
const dir =
|
|
24550
|
+
const dir = join17(store.dir, `${session.meta.id}.images`);
|
|
24271
24551
|
try {
|
|
24272
|
-
|
|
24552
|
+
mkdirSync13(dir, { recursive: true });
|
|
24273
24553
|
} catch (e) {
|
|
24274
|
-
|
|
24554
|
+
log48.debug("paste image dir create failed", e);
|
|
24275
24555
|
}
|
|
24276
24556
|
const img = grabClipboardImage(dir, String(Date.now()));
|
|
24277
24557
|
return img ? { display: "Image", ref: "@" + img.path, path: img.path } : null;
|
|
24278
24558
|
};
|
|
24279
24559
|
const forceQuit = (code = 130) => {
|
|
24560
|
+
live?.exited(code === 130 ? "force-quit" : `exit ${code}`);
|
|
24280
24561
|
try {
|
|
24281
24562
|
voiceIO?.stop();
|
|
24282
24563
|
} catch {
|
|
@@ -24289,6 +24570,10 @@ ${SPOKEN_TURN}`, { id });
|
|
|
24289
24570
|
disposeClaudeCodeSessions();
|
|
24290
24571
|
} catch {
|
|
24291
24572
|
}
|
|
24573
|
+
try {
|
|
24574
|
+
disposeCodexSessions();
|
|
24575
|
+
} catch {
|
|
24576
|
+
}
|
|
24292
24577
|
void closeMcp(mounted);
|
|
24293
24578
|
process.exit(code);
|
|
24294
24579
|
};
|
|
@@ -24305,6 +24590,8 @@ ${SPOKEN_TURN}`, { id });
|
|
|
24305
24590
|
}
|
|
24306
24591
|
forceQuit();
|
|
24307
24592
|
});
|
|
24593
|
+
process.on("SIGHUP", () => forceQuit(129));
|
|
24594
|
+
process.on("SIGTERM", () => forceQuit(143));
|
|
24308
24595
|
installCancelGuards(mounted);
|
|
24309
24596
|
setMcpMentionResolver(async (ref) => {
|
|
24310
24597
|
const i = ref.indexOf(":");
|
|
@@ -24319,13 +24606,15 @@ ${SPOKEN_TURN}`, { id });
|
|
|
24319
24606
|
const store = new SessionStore(cwd);
|
|
24320
24607
|
let session = startSession(args, store, face, cwd);
|
|
24321
24608
|
triggerServer.start(session.meta.id);
|
|
24609
|
+
setLive(new LiveStatus({ cwd, model: () => session.meta.model ?? agent.options.model, jobs: () => agent.jobs.list().filter((j) => j.status === "running").length }));
|
|
24610
|
+
live.session(session.meta.id);
|
|
24322
24611
|
setTermTitle(`agentx \xB7 ${session.meta.title || cwd.split("/").pop() || "session"}`);
|
|
24323
24612
|
if (session.meta.scheduledJobs?.length) {
|
|
24324
24613
|
scheduler.restore(session.meta.scheduledJobs);
|
|
24325
24614
|
err(dim(` \u23F0 ${scheduler.size} scheduled job(s) re-armed
|
|
24326
24615
|
`));
|
|
24327
24616
|
}
|
|
24328
|
-
const checkpoints = args.vfs || args.boddb ? new CheckpointStack(agent.options.fs) : new GitCheckpoints({ workTree: cwd, gitDir:
|
|
24617
|
+
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 });
|
|
24329
24618
|
const cpHooks = checkpoints.hooks?.();
|
|
24330
24619
|
if (cpHooks) {
|
|
24331
24620
|
agent.options.hooks = composeHooks(agent.options.hooks, cpHooks);
|
|
@@ -24377,14 +24666,14 @@ ${lines.join("\n")}
|
|
|
24377
24666
|
Added entries are loadable now via the Skill/SlashCommand tools; removed ones are gone even if still listed in the system prompt.
|
|
24378
24667
|
</system-reminder>`;
|
|
24379
24668
|
};
|
|
24380
|
-
const histPath =
|
|
24669
|
+
const histPath = join17(cwd, ".agent", "history");
|
|
24381
24670
|
const history = existsSync9(histPath) ? readFileSync10(histPath, "utf8").split("\n").filter(Boolean).reverse().slice(0, 500) : [];
|
|
24382
24671
|
const remember2 = (line) => {
|
|
24383
24672
|
try {
|
|
24384
|
-
|
|
24673
|
+
mkdirSync13(join17(cwd, ".agent"), { recursive: true });
|
|
24385
24674
|
appendFileSync2(histPath, line + "\n");
|
|
24386
24675
|
} catch (e) {
|
|
24387
|
-
|
|
24676
|
+
log48.debug("history write failed", e);
|
|
24388
24677
|
}
|
|
24389
24678
|
};
|
|
24390
24679
|
const ago = (t) => {
|
|
@@ -24397,6 +24686,7 @@ Added entries are loadable now via the Skill/SlashCommand tools; removed ones ar
|
|
|
24397
24686
|
session = data;
|
|
24398
24687
|
checkpoints.use?.(data.meta.id);
|
|
24399
24688
|
triggerServer.use(data.meta.id);
|
|
24689
|
+
live?.session(data.meta.id);
|
|
24400
24690
|
const m = data.meta;
|
|
24401
24691
|
goalCondition = m.goalCondition;
|
|
24402
24692
|
goalTurns = m.goalTurns ?? 0;
|
|
@@ -24456,7 +24746,7 @@ Added entries are loadable now via the Skill/SlashCommand tools; removed ones ar
|
|
|
24456
24746
|
try {
|
|
24457
24747
|
store.save(session);
|
|
24458
24748
|
} catch (e) {
|
|
24459
|
-
|
|
24749
|
+
log48.debug("session save after rewind failed", e);
|
|
24460
24750
|
}
|
|
24461
24751
|
err(green(" \u27F2 jumped back") + dim(` \u2014 ${face.transcript.length} message(s) kept; edit + resend
|
|
24462
24752
|
`));
|
|
@@ -24484,6 +24774,14 @@ Added entries are loadable now via the Skill/SlashCommand tools; removed ones ar
|
|
|
24484
24774
|
const announcedTasks = /* @__PURE__ */ new Set();
|
|
24485
24775
|
const replacedVoiceTurns = /* @__PURE__ */ new Set();
|
|
24486
24776
|
const turn = async (task, opts) => {
|
|
24777
|
+
live?.turnStart({ machine: opts?.machine });
|
|
24778
|
+
try {
|
|
24779
|
+
return await turnBody(task, opts);
|
|
24780
|
+
} finally {
|
|
24781
|
+
live?.turnEnd();
|
|
24782
|
+
}
|
|
24783
|
+
};
|
|
24784
|
+
const turnBody = async (task, opts) => {
|
|
24487
24785
|
if (bangContext.length) {
|
|
24488
24786
|
task = `${bangContext.join("\n\n")}
|
|
24489
24787
|
|
|
@@ -24491,7 +24789,7 @@ ${task}`;
|
|
|
24491
24789
|
bangContext.length = 0;
|
|
24492
24790
|
}
|
|
24493
24791
|
const delta = await refreshCatalogs().catch((e) => {
|
|
24494
|
-
|
|
24792
|
+
log48.debug("catalog refresh failed", e);
|
|
24495
24793
|
return "";
|
|
24496
24794
|
});
|
|
24497
24795
|
if (delta) {
|
|
@@ -24523,7 +24821,15 @@ ${task}`;
|
|
|
24523
24821
|
}
|
|
24524
24822
|
return r;
|
|
24525
24823
|
};
|
|
24526
|
-
scheduleTurn = turn;
|
|
24824
|
+
scheduleTurn = (prompt) => turn(prompt, { machine: true });
|
|
24825
|
+
if (!duplex) agent.options.onInject = () => setImmediate(() => {
|
|
24826
|
+
if (activeTurn || dispatchPending || live?.busy || exitRequested) return;
|
|
24827
|
+
const notes = agent.drainPendingSteers();
|
|
24828
|
+
if (!notes.length) return;
|
|
24829
|
+
err(dim(` \u2699 background job finished \u2014 resuming
|
|
24830
|
+
`));
|
|
24831
|
+
void turn(notes.join("\n\n"), { machine: true }).then(() => editorRef?.redrawNow());
|
|
24832
|
+
});
|
|
24527
24833
|
const runSkill = async (sk, extra = "") => {
|
|
24528
24834
|
try {
|
|
24529
24835
|
await turn(await expandEntry(fs, sk.path, extra));
|
|
@@ -24610,7 +24916,7 @@ ${task}`;
|
|
|
24610
24916
|
`));
|
|
24611
24917
|
aborting = false;
|
|
24612
24918
|
const tokensBefore = session.meta.tokens ?? 0;
|
|
24613
|
-
await turn(`Continue working toward the goal: ${goalCondition}
|
|
24919
|
+
await turn(`Continue working toward the goal: ${goalCondition}`, { machine: true });
|
|
24614
24920
|
goalTokens += (session.meta.tokens ?? 0) - tokensBefore;
|
|
24615
24921
|
goalTurns++;
|
|
24616
24922
|
persistGoal();
|
|
@@ -24732,12 +25038,12 @@ ${task}`;
|
|
|
24732
25038
|
}
|
|
24733
25039
|
const info = getModelInfo(work.model);
|
|
24734
25040
|
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)`);
|
|
24735
|
-
const cfgFiles = ["ts", "js", "json"].flatMap((e) => [`${cwd}/.agent/config.${e}`, `${
|
|
25041
|
+
const cfgFiles = ["ts", "js", "json"].flatMap((e) => [`${cwd}/.agent/config.${e}`, `${homedir11()}/.agent/config.${e}`]).filter((p) => existsSync9(p));
|
|
24736
25042
|
cfgFiles.length ? ok(`config: ${cfgFiles.join(", ")}`) : warn("no .agent/config.* found (project or ~) \u2014 running on defaults");
|
|
24737
25043
|
try {
|
|
24738
25044
|
const probe = `${cwd}/.agent/sessions/.doctor-probe`;
|
|
24739
|
-
|
|
24740
|
-
|
|
25045
|
+
mkdirSync13(`${cwd}/.agent/sessions`, { recursive: true });
|
|
25046
|
+
writeFileSync10(probe, "ok");
|
|
24741
25047
|
unlinkSync5(probe);
|
|
24742
25048
|
ok(`session store writable (${cwd}/.agent/sessions)`);
|
|
24743
25049
|
} catch (e) {
|
|
@@ -24765,7 +25071,7 @@ ${task}`;
|
|
|
24765
25071
|
desc: "rescan skills/commands dirs and rebuild the system prompt (one cache miss) \u2014 picks up entries created mid-session",
|
|
24766
25072
|
run: async () => {
|
|
24767
25073
|
await refreshCatalogs().catch((e) => {
|
|
24768
|
-
|
|
25074
|
+
log48.debug("catalog refresh failed", e);
|
|
24769
25075
|
});
|
|
24770
25076
|
face.reprepare();
|
|
24771
25077
|
err(green(` \u2713 reloaded \u2014 ${skills.length} skill(s), ${cmds.length} command(s); system prompt rebuilds on next message
|
|
@@ -25199,6 +25505,7 @@ ${task}`;
|
|
|
25199
25505
|
bangContext.length = 0;
|
|
25200
25506
|
session = startSession({ ...args, cont: false, resume: void 0 }, store, face, cwd);
|
|
25201
25507
|
triggerServer.use(session.meta.id);
|
|
25508
|
+
live?.session(session.meta.id);
|
|
25202
25509
|
err("\x1Bc");
|
|
25203
25510
|
}
|
|
25204
25511
|
},
|
|
@@ -25268,7 +25575,7 @@ ${task}`;
|
|
|
25268
25575
|
try {
|
|
25269
25576
|
for (const def of (await loadAgents(fs2, d)).agents) if (!seen.has(def.name)) seen.set(def.name, { def, from: d });
|
|
25270
25577
|
} catch (e) {
|
|
25271
|
-
|
|
25578
|
+
log48.debug(`loadAgents(${d}) failed`, e);
|
|
25272
25579
|
}
|
|
25273
25580
|
}
|
|
25274
25581
|
if (!seen.size) {
|
|
@@ -25356,7 +25663,7 @@ ${task}`;
|
|
|
25356
25663
|
}
|
|
25357
25664
|
if (idx >= 0) {
|
|
25358
25665
|
const old = mounted.splice(idx, 1)[0];
|
|
25359
|
-
await old.client.close().catch((e) =>
|
|
25666
|
+
await old.client.close().catch((e) => log48.debug("mcp close failed", e));
|
|
25360
25667
|
}
|
|
25361
25668
|
try {
|
|
25362
25669
|
const m = await mountMcpServer(name, conf);
|
|
@@ -25384,7 +25691,7 @@ ${task}`;
|
|
|
25384
25691
|
}
|
|
25385
25692
|
const m = mounted.splice(idx, 1)[0];
|
|
25386
25693
|
remountMcpTools();
|
|
25387
|
-
await m.client.close().catch((e) =>
|
|
25694
|
+
await m.client.close().catch((e) => log48.debug("mcp close failed", e));
|
|
25388
25695
|
err(dim(` removed "${name}"
|
|
25389
25696
|
`));
|
|
25390
25697
|
return;
|
|
@@ -25499,11 +25806,11 @@ ${task}`;
|
|
|
25499
25806
|
return;
|
|
25500
25807
|
}
|
|
25501
25808
|
const md = exportMarkdown(session.meta, shown);
|
|
25502
|
-
const name = a[0] ? extname(a[0]) ? a[0] : a[0] + ".md" :
|
|
25809
|
+
const name = a[0] ? extname(a[0]) ? a[0] : a[0] + ".md" : join17(".agent", "exports", `${session.meta.id}.md`);
|
|
25503
25810
|
const path = resolve5(cwd, name);
|
|
25504
25811
|
try {
|
|
25505
|
-
|
|
25506
|
-
|
|
25812
|
+
mkdirSync13(dirname6(path), { recursive: true });
|
|
25813
|
+
writeFileSync10(path, md);
|
|
25507
25814
|
err(green(` \u2713 exported \u2192 ${path}
|
|
25508
25815
|
`) + dim(` ${shown.length} message(s) \xB7 ${md.length} chars
|
|
25509
25816
|
`));
|
|
@@ -25575,7 +25882,7 @@ ${task}`;
|
|
|
25575
25882
|
quit: { desc: "quit", run: () => true }
|
|
25576
25883
|
};
|
|
25577
25884
|
const banner = (line) => err((process.stderr.isTTY ? wrapAnsi(line, process.stderr.columns ?? 80, " ") : line) + "\n");
|
|
25578
|
-
banner(bold("agentx") + cyan(" v" + VERSION) + dim(` \u2014 ${work.model} \xB7 ${cwd}`));
|
|
25885
|
+
banner(bold("agentx") + cyan(" v" + VERSION) + dim(` \u2014 ${work.model}${codexBilling(work.model)} \xB7 ${cwd}`));
|
|
25579
25886
|
banner(dim("Type a task, or /help. Type / or @ for live suggestions (\u2191/\u2193 \u23CE). Esc cancels/clears; double-Esc jumps back; Ctrl-D exits."));
|
|
25580
25887
|
if (dx) banner(dim(`\u25D1 duplex \u2014 reflex: ${dx.options.reflexModel} \xB7 act: ${work.model}${dx.options.thinkModel !== false ? ` \xB7 think: ${dx.options.thinkModel}` : ""} (real work runs in background tasks, re-voiced when done)`));
|
|
25581
25888
|
if (args.updateCheck !== false && cfg.updateCheck !== false) checkForUpdate(VERSION).then((msg) => {
|
|
@@ -25585,9 +25892,9 @@ ${task}`;
|
|
|
25585
25892
|
});
|
|
25586
25893
|
const listDir = (absDir) => {
|
|
25587
25894
|
try {
|
|
25588
|
-
return readdirSync4(
|
|
25895
|
+
return readdirSync4(join17(cwd, absDir.replace(/^\/+/, "")), { withFileTypes: true }).map((d) => ({ name: d.name, dir: d.isDirectory() }));
|
|
25589
25896
|
} catch (e) {
|
|
25590
|
-
|
|
25897
|
+
log48.debug("completion readdir failed", absDir, e);
|
|
25591
25898
|
return null;
|
|
25592
25899
|
}
|
|
25593
25900
|
};
|
|
@@ -25689,6 +25996,14 @@ ${task}`;
|
|
|
25689
25996
|
let prefill;
|
|
25690
25997
|
let tick = 0;
|
|
25691
25998
|
const dispatchLine = async (line, opts) => {
|
|
25999
|
+
live?.hold();
|
|
26000
|
+
try {
|
|
26001
|
+
return await dispatchLineBody(line, opts);
|
|
26002
|
+
} finally {
|
|
26003
|
+
live?.release();
|
|
26004
|
+
}
|
|
26005
|
+
};
|
|
26006
|
+
const dispatchLineBody = async (line, opts) => {
|
|
25692
26007
|
if (!opts?.id) takeCut(voiceIO, false);
|
|
25693
26008
|
if (/^[!#/]/.test(line)) dispatchPending = false;
|
|
25694
26009
|
history.unshift(line.replace(/\n+/g, " \u23CE "));
|
|
@@ -25726,7 +26041,7 @@ ${out}
|
|
|
25726
26041
|
return;
|
|
25727
26042
|
}
|
|
25728
26043
|
await refreshCatalogs().catch((e) => {
|
|
25729
|
-
|
|
26044
|
+
log48.debug("catalog refresh failed", e);
|
|
25730
26045
|
});
|
|
25731
26046
|
const sk = skills.find((x) => x.name === name);
|
|
25732
26047
|
if (sk) {
|
|
@@ -25777,7 +26092,7 @@ ${out}
|
|
|
25777
26092
|
return false;
|
|
25778
26093
|
}
|
|
25779
26094
|
const fakeVoice = process.env.AGENTX_VOICE_FAKE ? fakeVoiceParts(process.env.AGENTX_VOICE_FAKE) : null;
|
|
25780
|
-
voiceDiag = new JsonlDiagSink(
|
|
26095
|
+
voiceDiag = new JsonlDiagSink(join17(store.dir, `${session.meta.id}.voice.jsonl`));
|
|
25781
26096
|
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) => {
|
|
25782
26097
|
err(dim(` (stt terms: ${e?.message ?? e})
|
|
25783
26098
|
`));
|
|
@@ -25856,7 +26171,7 @@ ${out}
|
|
|
25856
26171
|
if (delivery || cut) dx?.parkCutDelivery(delivery, !!cut, heard);
|
|
25857
26172
|
const cutReply = cut && cut.full.length - cut.heard.length > 40 ? cut : null;
|
|
25858
26173
|
const noteP = replaces ? replaces.note : !cutReply ? Promise.resolve("") : (instinct ? instinct.bargeIntent(text).catch((e) => {
|
|
25859
|
-
|
|
26174
|
+
log48.warn(`barge intent failed \u2014 model decides: ${e.message}`);
|
|
25860
26175
|
return void 0;
|
|
25861
26176
|
}) : Promise.resolve(void 0)).then(async (intent) => interruptionNote(cutReply, intent) + ackedNote(await instinct?.ackFor(text)));
|
|
25862
26177
|
const cutIn = replaces ? replaces.cutIn : interjectNote;
|
|
@@ -25993,7 +26308,7 @@ ${out}
|
|
|
25993
26308
|
const where = cwd.split("/").pop();
|
|
25994
26309
|
const resumed = session.messages.length > 0;
|
|
25995
26310
|
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.`;
|
|
25996
|
-
void turn(prompt).finally(() => editorRef?.redrawNow());
|
|
26311
|
+
void turn(prompt, { machine: true }).finally(() => editorRef?.redrawNow());
|
|
25997
26312
|
}
|
|
25998
26313
|
return true;
|
|
25999
26314
|
} catch (e) {
|
|
@@ -26029,6 +26344,7 @@ ${out}
|
|
|
26029
26344
|
};
|
|
26030
26345
|
if (args.voice && (duplex || call) && process.stdin.isTTY) await startVoice(process.env.VOICE_GREETING !== "0");
|
|
26031
26346
|
let ctxWarned = 0;
|
|
26347
|
+
let seedLine = args.prompt;
|
|
26032
26348
|
while (true) {
|
|
26033
26349
|
if (pendingRewind) {
|
|
26034
26350
|
pendingRewind = false;
|
|
@@ -26086,7 +26402,13 @@ ${out}
|
|
|
26086
26402
|
const q2 = ask.question.replace(/\s+/g, " ").slice(0, 64);
|
|
26087
26403
|
return bold(yellow(`? ${q2}${ask.question.length > 64 ? "\u2026" : ""} \u2039yes/no\u203A `));
|
|
26088
26404
|
};
|
|
26089
|
-
const result =
|
|
26405
|
+
const result = seedLine !== void 0 ? (() => {
|
|
26406
|
+
const s = seedLine;
|
|
26407
|
+
seedLine = void 0;
|
|
26408
|
+
err(promptStr + s + "\n");
|
|
26409
|
+
dispatchPending = true;
|
|
26410
|
+
return s;
|
|
26411
|
+
})() : await readMultiline((cont) => {
|
|
26090
26412
|
dispatchPending = false;
|
|
26091
26413
|
return editor.readLine({
|
|
26092
26414
|
prompt: cont ? contPrompt : livePrompt,
|
|
@@ -26146,6 +26468,7 @@ ${out}
|
|
|
26146
26468
|
`));
|
|
26147
26469
|
continue;
|
|
26148
26470
|
}
|
|
26471
|
+
live?.hold();
|
|
26149
26472
|
let quit = await dispatchLine(line) === "quit";
|
|
26150
26473
|
const wasLocal = /^[!#/]/.test(line);
|
|
26151
26474
|
if (wasLocal) agent.clearInjections();
|
|
@@ -26160,7 +26483,7 @@ ${out}
|
|
|
26160
26483
|
const prompt = scheduleQueue.shift();
|
|
26161
26484
|
err(dim(` \u23F0 scheduled \u203A ${prompt.slice(0, 60)}${prompt.length > 60 ? "\u2026" : ""}
|
|
26162
26485
|
`));
|
|
26163
|
-
await turn(prompt);
|
|
26486
|
+
await turn(prompt, { machine: true });
|
|
26164
26487
|
}
|
|
26165
26488
|
dispatchPending = false;
|
|
26166
26489
|
session.meta.scheduledJobs = scheduler.snapshot();
|
|
@@ -26168,10 +26491,12 @@ ${out}
|
|
|
26168
26491
|
store.save(session);
|
|
26169
26492
|
} catch {
|
|
26170
26493
|
}
|
|
26494
|
+
live?.release();
|
|
26171
26495
|
if (quit) break;
|
|
26172
26496
|
}
|
|
26173
26497
|
scheduler.destroy();
|
|
26174
26498
|
triggerServer.stop();
|
|
26499
|
+
live?.exited("exit");
|
|
26175
26500
|
voiceIO?.stop();
|
|
26176
26501
|
if (dx) {
|
|
26177
26502
|
const running = [...dx.tasks.values()].filter((t) => t.status === "running");
|
|
@@ -26210,6 +26535,7 @@ ${out}
|
|
|
26210
26535
|
releaseStdin();
|
|
26211
26536
|
disposeCursorSessions();
|
|
26212
26537
|
disposeClaudeCodeSessions();
|
|
26538
|
+
disposeCodexSessions();
|
|
26213
26539
|
await closeMcp(mounted);
|
|
26214
26540
|
process.exit(130);
|
|
26215
26541
|
}
|
|
@@ -26220,6 +26546,7 @@ ${out}
|
|
|
26220
26546
|
releaseStdin();
|
|
26221
26547
|
disposeCursorSessions();
|
|
26222
26548
|
disposeClaudeCodeSessions();
|
|
26549
|
+
disposeCodexSessions();
|
|
26223
26550
|
await closeMcp(mounted);
|
|
26224
26551
|
}
|
|
26225
26552
|
function duplexError(e, reflexModel) {
|
|
@@ -26257,13 +26584,13 @@ function channelOptions(ai, model, gender) {
|
|
|
26257
26584
|
// 0: the reactive live path
|
|
26258
26585
|
pickLeaf: fastLeafPicker(ai, process.env.AGENTX_LEAF_MODEL || "groq/openai/gpt-oss-120b"),
|
|
26259
26586
|
persona: process.env.AGENTX_CALL_PERSONA ?? "",
|
|
26260
|
-
onTree: (e) =>
|
|
26587
|
+
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}` : ""}`),
|
|
26261
26588
|
onEvent: (e) => {
|
|
26262
|
-
if (e.moment)
|
|
26263
|
-
else
|
|
26589
|
+
if (e.moment) log48.debug(`voice leaf: ${e.moment} ${e.conf} "${e.text}" ${e.acted}`);
|
|
26590
|
+
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`);
|
|
26264
26591
|
},
|
|
26265
26592
|
// Banks in the user's language: generated once per language, cached + topped up across sessions (~/.agent/cache).
|
|
26266
|
-
banks: new ChannelBanks({ generate: fastBankGenerator(ai, model), cacheDir:
|
|
26593
|
+
banks: new ChannelBanks({ generate: fastBankGenerator(ai, model), cacheDir: join17(homedir11(), ".agent", "cache", "channel-banks") }),
|
|
26267
26594
|
decide: channelDecide(ai, instinct),
|
|
26268
26595
|
generate: fastLineGenerator(ai, model, gender),
|
|
26269
26596
|
// Anticipated backchannels: on in chatty mode (its preset), else off until the offline replay proves them (tests/voice-bc-anticipate-eval.ts)
|
|
@@ -26295,7 +26622,7 @@ function overlapResponder(ai, mode, out, aside) {
|
|
|
26295
26622
|
}
|
|
26296
26623
|
async function duplexServe(args, ai, cfg, cwd) {
|
|
26297
26624
|
const out = (o) => process.stdout.write(JSON.stringify(o) + "\n");
|
|
26298
|
-
const mounted = await mountMcp(cfg, new McpOAuth({ storePath:
|
|
26625
|
+
const mounted = await mountMcp(cfg, new McpOAuth({ storePath: join17(cwd, ".agent", "mcp-auth.json") }));
|
|
26299
26626
|
installCancelGuards(mounted);
|
|
26300
26627
|
const agent = await makeAgent(args, ai, cfg, mcpAgentTools(mounted, { quiet: true }), mounted.map((m) => m.name));
|
|
26301
26628
|
const { host: _h, stream: _s, signal: _g, providerOptions: _po, ...wo } = agent.options;
|
|
@@ -26354,7 +26681,7 @@ async function duplexServe(args, ai, cfg, cwd) {
|
|
|
26354
26681
|
try {
|
|
26355
26682
|
store.save(session);
|
|
26356
26683
|
} catch (e) {
|
|
26357
|
-
|
|
26684
|
+
log48.warn("duplex session save failed", e);
|
|
26358
26685
|
}
|
|
26359
26686
|
};
|
|
26360
26687
|
const overlap2 = overlapResponder(ai, args.duplexV2 ? args.channelMode : void 0, out);
|
|
@@ -26394,7 +26721,7 @@ async function duplexServe(args, ai, cfg, cwd) {
|
|
|
26394
26721
|
done2();
|
|
26395
26722
|
out({ type: "turn_done", id, finishReason: res?.finishReason ?? "error", ...why ? { error: why } : {} });
|
|
26396
26723
|
}).catch((e) => {
|
|
26397
|
-
|
|
26724
|
+
log48.error("duplex turn failed", e);
|
|
26398
26725
|
done2();
|
|
26399
26726
|
out({ type: "turn_done", id, finishReason: "error", error: String(e?.message ?? e) });
|
|
26400
26727
|
});
|
|
@@ -26551,9 +26878,10 @@ async function rollbackTurn(agent, store, session, start) {
|
|
|
26551
26878
|
agent.transcript.splice(start);
|
|
26552
26879
|
session.messages = agent.transcript;
|
|
26553
26880
|
session.meta.updated = Date.now();
|
|
26881
|
+
session.meta.codex = void 0;
|
|
26554
26882
|
session.meta.cc = void 0;
|
|
26555
26883
|
const cc = agent.options.providerOptions?.claudeCodeSession;
|
|
26556
|
-
if (typeof cc === "string" && agent.options.model
|
|
26884
|
+
if (typeof cc === "string" && isClaudeCode(agent.options.model)) await rewindClaudeCodeSession(cc);
|
|
26557
26885
|
store.save(session);
|
|
26558
26886
|
return dropped;
|
|
26559
26887
|
}
|
|
@@ -26620,7 +26948,7 @@ async function main() {
|
|
|
26620
26948
|
}
|
|
26621
26949
|
cfg.permissions = mergePerms(loadClaudeSettings(cwd), mergePerms(loadPersistedRules(cwd), cfg.permissions));
|
|
26622
26950
|
if (canPrompt && !args.yes && !isTrusted(cwd)) {
|
|
26623
|
-
const ok = await makeHost().confirm?.(`Trust this directory? agent.libx will read and edit files in:
|
|
26951
|
+
const ok = args.trust || await makeHost().confirm?.(`Trust this directory? agent.libx will read and edit files in:
|
|
26624
26952
|
${cwd}`);
|
|
26625
26953
|
if (!ok) {
|
|
26626
26954
|
console.error(red(" not trusted \u2014 exiting (re-run with --yes to skip this prompt)."));
|
|
@@ -26645,7 +26973,7 @@ async function main() {
|
|
|
26645
26973
|
loadInstallEnv();
|
|
26646
26974
|
await loadBodifySecrets();
|
|
26647
26975
|
const apiKeys = { ...cfg.apiKeys, ...apiKeysFromEnv() };
|
|
26648
|
-
const keyless = String(args.model ?? cfg.model ?? "")
|
|
26976
|
+
const keyless = isKeyless(String(args.model ?? cfg.model ?? ""));
|
|
26649
26977
|
if (!Object.keys(apiKeys).length && !keyless) {
|
|
26650
26978
|
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."));
|
|
26651
26979
|
process.exit(1);
|
|
@@ -26679,7 +27007,7 @@ async function main() {
|
|
|
26679
27007
|
worktreeCleanup?.();
|
|
26680
27008
|
process.exit(0);
|
|
26681
27009
|
}
|
|
26682
|
-
const mounted = await mountMcp(cfg, new McpOAuth({ storePath:
|
|
27010
|
+
const mounted = await mountMcp(cfg, new McpOAuth({ storePath: join17(cwd, ".agent", "mcp-auth.json") }));
|
|
26683
27011
|
const agent = await makeAgent(args, ai, cfg, mcpAgentTools(mounted), mounted.map((m) => m.name));
|
|
26684
27012
|
const store = new SessionStore(cwd);
|
|
26685
27013
|
const session = startSession(args, store, agent, cwd);
|
|
@@ -26754,6 +27082,8 @@ export {
|
|
|
26754
27082
|
appendMemoryNote,
|
|
26755
27083
|
applyTurnMode,
|
|
26756
27084
|
cacheMultipliers,
|
|
27085
|
+
codexBilling,
|
|
27086
|
+
codexRoute,
|
|
26757
27087
|
condenseReplay,
|
|
26758
27088
|
costOf,
|
|
26759
27089
|
duplexError,
|