acpx 0.15.0 → 0.16.0
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/agent-registry-DU6mhZBL.js +785 -0
- package/dist/agent-registry-DU6mhZBL.js.map +1 -0
- package/dist/agent-registry.d.ts +70 -0
- package/dist/agent-registry.d.ts.map +1 -0
- package/dist/agent-registry.js +2 -0
- package/dist/{cli-Cen2Rb6S.js → cli-BkYIxj_N.js} +6 -14
- package/dist/cli-BkYIxj_N.js.map +1 -0
- package/dist/cli.d.ts +1 -1
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +137 -333
- package/dist/cli.js.map +1 -1
- package/dist/{client-Cvz6msGc.d.ts → client-5levcBIs.d.ts} +11 -9
- package/dist/client-5levcBIs.d.ts.map +1 -0
- package/dist/{flows-D-F3Y2o9.js → flows-Bxs4udrs.js} +205 -277
- package/dist/flows-Bxs4udrs.js.map +1 -0
- package/dist/flows.d.ts +6 -17
- package/dist/flows.d.ts.map +1 -1
- package/dist/flows.js +1 -1
- package/dist/{flags-CRh8BJre.js → invocation-options-BY4lxkn3.js} +82 -58
- package/dist/invocation-options-BY4lxkn3.js.map +1 -0
- package/dist/{live-checkpoint-CYRs-D9t.js → live-checkpoint-BEfxBKCh.js} +1033 -1437
- package/dist/live-checkpoint-BEfxBKCh.js.map +1 -0
- package/dist/{output-CIVecnHU.js → output-uo5a27KB.js} +487 -490
- package/dist/output-uo5a27KB.js.map +1 -0
- package/dist/runtime.d.ts +105 -22
- package/dist/runtime.d.ts.map +1 -1
- package/dist/runtime.js +582 -366
- package/dist/runtime.js.map +1 -1
- package/dist/{session-options-DyIGRNfu.d.ts → session-options-t3d-F4dn.d.ts} +8 -6
- package/dist/session-options-t3d-F4dn.d.ts.map +1 -0
- package/package.json +27 -25
- package/skills/acpx/SKILL.md +19 -17
- package/dist/cli-Cen2Rb6S.js.map +0 -1
- package/dist/client-Cvz6msGc.d.ts.map +0 -1
- package/dist/flags-CRh8BJre.js.map +0 -1
- package/dist/flows-D-F3Y2o9.js.map +0 -1
- package/dist/live-checkpoint-CYRs-D9t.js.map +0 -1
- package/dist/output-CIVecnHU.js.map +0 -1
- package/dist/session-options-DyIGRNfu.d.ts.map +0 -1
package/dist/cli.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { a as runSessionQueueOwner, c as
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
2
|
+
import { a as runSessionQueueOwner, c as DISCARD_OUTPUT_FORMATTER, d as installPerfMetricsCapture, g as __exportAll, l as buildQueueOwnerArgOverride, m as probeQueueOwnerHealth, n as getTextErrorRemediationHints, o as runOnce, t as createOutputFormatter, u as flushPerfMetricsCapture } from "./output-uo5a27KB.js";
|
|
3
|
+
import { Bt as OUTPUT_FORMATS, Ct as isLegacyZedCodexAcpInvocation, F as parsePromptSource, G as listSessions, Gt as AgentSpawnError, H as findSession, It as EXIT_CODES, L as textPrompt, M as PromptInputValidationError, Ot as exitCodeForOutputErrorCode, P as mergePromptSourceWithText, Tt as TimeoutError, U as findSessionByDirectoryWalk, V as findGitRepositoryRoot, Wt as AcpxOperationalError, X as writeSessionRecord, _t as isProcessAlive, ct as normalizeAgentSessionId, ft as sessionEventActivePath, ht as writePrivateFile, j as getAcpxVersion, jt as normalizeOutputError, mt as sessionEventSegmentPath, ot as parseSessionRecord, pt as sessionEventLockPath, q as normalizeName, st as serializeSessionRecordForDisk, ut as defaultSessionEventLog, wt as InterruptedError, yt as isAcpJsonRpcMessage } from "./live-checkpoint-BEfxBKCh.js";
|
|
4
|
+
import { O as renderArgvIdentity, i as DEFAULT_AGENT_NAME, l as normalizeAgentName$1, s as listBuiltInAgents } from "./agent-registry-DU6mhZBL.js";
|
|
5
|
+
import { C as resolvePermissionMode, S as resolveOutputPolicy, T as toTimerMilliseconds, _ as parseSessionName, a as addGlobalFlags, b as resolveAgentInvocation, c as addSessionOption, d as parseDaysOlderThan, f as parseHistoryLimit, g as parsePruneBeforeDate, h as parseOutputFormat$1, i as addExecConfigOption, m as parseNonEmptyValue, n as sessionConnectionOptions, o as addPromptInputOption, p as parseMaxTurns, r as sessionOptionsFromGlobalFlags, s as addSessionNameOption, t as resolvePermissionPolicyFromFlags, u as parseAllowedTools, v as parseTimeoutSeconds, w as resolveSessionNameFromFlags, x as resolveGlobalFlags, y as parseTtlSeconds } from "./invocation-options-BY4lxkn3.js";
|
|
5
6
|
import { realpathSync } from "node:fs";
|
|
6
7
|
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
7
8
|
import path from "node:path";
|
|
@@ -10,6 +11,7 @@ import fs$1 from "node:fs/promises";
|
|
|
10
11
|
import os from "node:os";
|
|
11
12
|
import { createHash, randomUUID } from "node:crypto";
|
|
12
13
|
import { ZodError, z } from "zod";
|
|
14
|
+
import { text } from "node:stream/consumers";
|
|
13
15
|
import { performance } from "node:perf_hooks";
|
|
14
16
|
//#region src/cli-public.ts
|
|
15
17
|
function configurePublicCli(options) {
|
|
@@ -51,11 +53,6 @@ Examples:
|
|
|
51
53
|
acpx --agent ./my-custom-server "do something"`);
|
|
52
54
|
}
|
|
53
55
|
//#endregion
|
|
54
|
-
//#region src/acp/codex-compat.ts
|
|
55
|
-
function isLegacyZedCodexAcpInvocation(agentCommand) {
|
|
56
|
-
return /@zed-industries\/codex-acp\b/u.test(agentCommand);
|
|
57
|
-
}
|
|
58
|
-
//#endregion
|
|
59
56
|
//#region src/session/export.ts
|
|
60
57
|
var SessionExportError = class extends AcpxOperationalError {
|
|
61
58
|
code;
|
|
@@ -119,23 +116,21 @@ async function isSessionActive(record) {
|
|
|
119
116
|
if (record.closed) return false;
|
|
120
117
|
return isProcessAlive(record.pid) || await hasLiveEventLock(record.acpxRecordId);
|
|
121
118
|
}
|
|
122
|
-
async function
|
|
119
|
+
async function appendHistoryFile(filePath, history) {
|
|
123
120
|
const payload = await fs$1.readFile(filePath, "utf8").catch((error) => {
|
|
124
121
|
if (error.code === "ENOENT") return "";
|
|
125
122
|
throw error;
|
|
126
123
|
});
|
|
127
|
-
const history = [];
|
|
128
124
|
for (const line of payload.split("\n").filter((entry) => entry.trim().length > 0)) try {
|
|
129
125
|
const parsed = JSON.parse(line);
|
|
130
126
|
if (isAcpJsonRpcMessage(parsed)) history.push(parsed);
|
|
131
127
|
} catch {}
|
|
132
|
-
return history;
|
|
133
128
|
}
|
|
134
129
|
async function readSessionHistory(record) {
|
|
135
130
|
const history = [];
|
|
136
131
|
const maxSegments = Number.isInteger(record.eventLog.max_segments) ? record.eventLog.max_segments : 0;
|
|
137
|
-
for (let segment = maxSegments; segment >= 1; segment -= 1)
|
|
138
|
-
|
|
132
|
+
for (let segment = maxSegments; segment >= 1; segment -= 1) await appendHistoryFile(sessionEventSegmentPath(record.acpxRecordId, segment), history);
|
|
133
|
+
await appendHistoryFile(sessionEventActivePath(record.acpxRecordId), history);
|
|
139
134
|
return history;
|
|
140
135
|
}
|
|
141
136
|
function cwdRelativeToHome(cwd, home) {
|
|
@@ -176,8 +171,21 @@ async function exportSession(sessionLookup, outputPath) {
|
|
|
176
171
|
},
|
|
177
172
|
history: await readSessionHistory(record)
|
|
178
173
|
};
|
|
179
|
-
await
|
|
180
|
-
await
|
|
174
|
+
const target = await resolveExportTarget(outputPath);
|
|
175
|
+
await writePrivateFile(target, `${JSON.stringify(exported, null, 2)}\n`, { privateDirectory: false });
|
|
176
|
+
}
|
|
177
|
+
async function resolveExportTarget(filePath) {
|
|
178
|
+
for (let hops = 0; hops < 40; hops += 1) {
|
|
179
|
+
const stat = await fs$1.lstat(filePath).catch((error) => {
|
|
180
|
+
if (error.code === "ENOENT") return;
|
|
181
|
+
throw error;
|
|
182
|
+
});
|
|
183
|
+
if (!stat || stat.isFile()) return filePath;
|
|
184
|
+
if (!stat.isSymbolicLink()) throw new Error("Session export output must be a regular file");
|
|
185
|
+
const target = await fs$1.readlink(filePath);
|
|
186
|
+
filePath = path.isAbsolute(target) ? target : `${path.dirname(filePath)}${path.sep}${target}`;
|
|
187
|
+
}
|
|
188
|
+
throw new Error("Too many symbolic links in session export output");
|
|
181
189
|
}
|
|
182
190
|
function normalizeAgentName(agentName) {
|
|
183
191
|
const normalized = agentName?.trim().toLowerCase();
|
|
@@ -362,7 +370,7 @@ async function importSession(archivePath, options = {}) {
|
|
|
362
370
|
await writeSessionRecord(newRecord);
|
|
363
371
|
if (parsed.history.length > 0) {
|
|
364
372
|
const history = parsed.history;
|
|
365
|
-
await
|
|
373
|
+
await writePrivateFile(sessionEventActivePath(newRecordId), `${history.map((entry) => JSON.stringify(entry)).join("\n")}\n`);
|
|
366
374
|
}
|
|
367
375
|
return {
|
|
368
376
|
record_id: newRecordId,
|
|
@@ -377,6 +385,28 @@ function emitJsonResult(format, payload) {
|
|
|
377
385
|
return true;
|
|
378
386
|
}
|
|
379
387
|
//#endregion
|
|
388
|
+
//#region src/cli/prompt-input.ts
|
|
389
|
+
async function readPromptInput(filePath, promptText, cwd, positionalLabel = "argument") {
|
|
390
|
+
try {
|
|
391
|
+
if (filePath) return await readPromptFile(filePath, promptText, cwd);
|
|
392
|
+
const joined = promptText.trim();
|
|
393
|
+
if (joined.length > 0) return textPrompt(joined);
|
|
394
|
+
if (process.stdin.isTTY) throw new InvalidArgumentError(`Prompt is required (pass as ${positionalLabel}, --file, or pipe via stdin)`);
|
|
395
|
+
const prompt = parsePromptSource(await text(process.stdin));
|
|
396
|
+
if (prompt.length === 0) throw new InvalidArgumentError("Prompt from stdin is empty");
|
|
397
|
+
return prompt;
|
|
398
|
+
} catch (error) {
|
|
399
|
+
if (error instanceof PromptInputValidationError) throw new InvalidArgumentError(error.message);
|
|
400
|
+
throw error;
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
async function readPromptFile(filePath, promptText, cwd) {
|
|
404
|
+
const source = filePath === "-" ? await text(process.stdin) : await fs$1.readFile(path.resolve(cwd, filePath), "utf8");
|
|
405
|
+
const prompt = mergePromptSourceWithText(source, promptText);
|
|
406
|
+
if (prompt.length === 0) throw new InvalidArgumentError("Prompt from --file is empty");
|
|
407
|
+
return prompt;
|
|
408
|
+
}
|
|
409
|
+
//#endregion
|
|
380
410
|
//#region src/cli/command-handlers.ts
|
|
381
411
|
var NoSessionError = class extends Error {
|
|
382
412
|
constructor(message) {
|
|
@@ -388,42 +418,17 @@ let sessionModulePromise;
|
|
|
388
418
|
let outputModulePromise;
|
|
389
419
|
let outputRenderModulePromise;
|
|
390
420
|
function loadSessionModule() {
|
|
391
|
-
sessionModulePromise ??= import("./output-
|
|
421
|
+
sessionModulePromise ??= import("./output-uo5a27KB.js").then((n) => n.i);
|
|
392
422
|
return sessionModulePromise;
|
|
393
423
|
}
|
|
394
424
|
function loadOutputModule() {
|
|
395
|
-
outputModulePromise ??= import("./output-
|
|
425
|
+
outputModulePromise ??= import("./output-uo5a27KB.js").then((n) => n.r);
|
|
396
426
|
return outputModulePromise;
|
|
397
427
|
}
|
|
398
428
|
function loadOutputRenderModule() {
|
|
399
429
|
outputRenderModulePromise ??= Promise.resolve().then(() => render_exports);
|
|
400
430
|
return outputRenderModulePromise;
|
|
401
431
|
}
|
|
402
|
-
async function readPromptInputFromStdin() {
|
|
403
|
-
let data = "";
|
|
404
|
-
for await (const chunk of process.stdin) data += String(chunk);
|
|
405
|
-
return data;
|
|
406
|
-
}
|
|
407
|
-
async function readPrompt(promptParts, filePath, cwd) {
|
|
408
|
-
try {
|
|
409
|
-
if (filePath) return await readPromptFromFile(filePath, cwd, promptParts);
|
|
410
|
-
const joined = promptParts.join(" ").trim();
|
|
411
|
-
if (joined.length > 0) return textPrompt(joined);
|
|
412
|
-
if (process.stdin.isTTY) throw new InvalidArgumentError("Prompt is required (pass as argument, --file, or pipe via stdin)");
|
|
413
|
-
const prompt = parsePromptSource(await readPromptInputFromStdin());
|
|
414
|
-
if (prompt.length === 0) throw new InvalidArgumentError("Prompt from stdin is empty");
|
|
415
|
-
return prompt;
|
|
416
|
-
} catch (error) {
|
|
417
|
-
if (error instanceof PromptInputValidationError) throw new InvalidArgumentError(error.message);
|
|
418
|
-
throw error;
|
|
419
|
-
}
|
|
420
|
-
}
|
|
421
|
-
async function readPromptFromFile(filePath, cwd, promptParts) {
|
|
422
|
-
const source = filePath === "-" ? await readPromptInputFromStdin() : await fs$1.readFile(path.resolve(cwd, filePath), "utf8");
|
|
423
|
-
const prompt = mergePromptSourceWithText(source, promptParts.join(" "));
|
|
424
|
-
if (prompt.length === 0) throw new InvalidArgumentError("Prompt from --file is empty");
|
|
425
|
-
return prompt;
|
|
426
|
-
}
|
|
427
432
|
function applyPermissionExitCode(result, quietOutput) {
|
|
428
433
|
const stats = result.permissionStats;
|
|
429
434
|
const deniedOrCancelled = stats.denied + stats.cancelled;
|
|
@@ -447,40 +452,17 @@ function resolveRequestedOutputPolicy(globalFlags) {
|
|
|
447
452
|
suppressReads: globalFlags.suppressReads === true
|
|
448
453
|
};
|
|
449
454
|
}
|
|
450
|
-
function sessionOptionsFromGlobalFlags$1(globalFlags) {
|
|
451
|
-
return {
|
|
452
|
-
model: globalFlags.model,
|
|
453
|
-
allowedTools: globalFlags.allowedTools,
|
|
454
|
-
maxTurns: globalFlags.maxTurns,
|
|
455
|
-
systemPrompt: globalFlags.systemPrompt
|
|
456
|
-
};
|
|
457
|
-
}
|
|
458
|
-
async function resolvePermissionPolicyFromFlags$1(globalFlags) {
|
|
459
|
-
try {
|
|
460
|
-
return await loadPermissionPolicySpec(globalFlags.permissionPolicy, globalFlags.cwd);
|
|
461
|
-
} catch (error) {
|
|
462
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
463
|
-
throw new InvalidArgumentError(`Invalid permission policy: ${message}`);
|
|
464
|
-
}
|
|
465
|
-
}
|
|
466
455
|
function buildSessionStartOptions(params) {
|
|
467
456
|
return {
|
|
457
|
+
...sessionConnectionOptions(params.globalFlags, params.config),
|
|
468
458
|
agentCommand: params.agent.agentCommand,
|
|
469
459
|
agentArgv: params.agent.agentArgv,
|
|
470
460
|
cwd: params.agent.cwd,
|
|
471
461
|
name: params.flags.name,
|
|
472
462
|
resumeSessionId: params.flags.resumeSession,
|
|
473
|
-
mcpServers: params.config.mcpServers,
|
|
474
463
|
permissionMode: params.permissionMode,
|
|
475
|
-
nonInteractivePermissions: params.globalFlags.nonInteractivePermissions,
|
|
476
464
|
permissionPolicy: params.permissionPolicy,
|
|
477
|
-
|
|
478
|
-
authPolicy: params.globalFlags.authPolicy,
|
|
479
|
-
fs: params.globalFlags.fs,
|
|
480
|
-
terminal: params.globalFlags.terminal,
|
|
481
|
-
timeoutMs: params.globalFlags.timeout,
|
|
482
|
-
verbose: params.globalFlags.verbose,
|
|
483
|
-
sessionOptions: sessionOptionsFromGlobalFlags$1(params.globalFlags),
|
|
465
|
+
sessionOptions: sessionOptionsFromGlobalFlags(params.globalFlags),
|
|
484
466
|
onModelWarning: params.globalFlags.jsonStrict ? void 0 : (message) => process.stderr.write(`[acpx] warning: ${message}\n`)
|
|
485
467
|
};
|
|
486
468
|
}
|
|
@@ -520,8 +502,8 @@ async function handlePrompt(explicitAgentName, promptParts, flags, command, conf
|
|
|
520
502
|
const globalFlags = resolveGlobalFlags(command, config);
|
|
521
503
|
const outputPolicy = resolveRequestedOutputPolicy(globalFlags);
|
|
522
504
|
const permissionMode = resolvePermissionMode(globalFlags, config.defaultPermissions);
|
|
523
|
-
const permissionPolicy = await resolvePermissionPolicyFromFlags
|
|
524
|
-
const prompt = await
|
|
505
|
+
const permissionPolicy = await resolvePermissionPolicyFromFlags(globalFlags);
|
|
506
|
+
const prompt = await readPromptInput(flags.file, promptParts.join(" "), globalFlags.cwd);
|
|
525
507
|
const agent = resolveAgentInvocation(explicitAgentName, globalFlags, config);
|
|
526
508
|
const [{ createOutputFormatter }, { printPromptSessionBanner, printQueuedPromptByFormat }, { sendSession }] = await Promise.all([
|
|
527
509
|
loadOutputModule(),
|
|
@@ -535,33 +517,21 @@ async function handlePrompt(explicitAgentName, promptParts, flags, command, conf
|
|
|
535
517
|
});
|
|
536
518
|
await printPromptSessionBanner(record, agent.cwd, outputPolicy.format, outputPolicy.jsonStrict);
|
|
537
519
|
const result = await sendSession({
|
|
520
|
+
...sessionConnectionOptions(globalFlags, config),
|
|
538
521
|
sessionId: record.acpxRecordId,
|
|
539
522
|
prompt,
|
|
540
|
-
mcpServers: config.mcpServers,
|
|
541
523
|
mcpConfigPath: config.mcpConfigPath,
|
|
542
524
|
mcpConfigFingerprint: config.mcpConfigFingerprint,
|
|
543
525
|
permissionMode,
|
|
544
|
-
nonInteractivePermissions: globalFlags.nonInteractivePermissions,
|
|
545
526
|
permissionPolicy,
|
|
546
|
-
authCredentials: config.auth,
|
|
547
|
-
authPolicy: globalFlags.authPolicy,
|
|
548
|
-
fs: globalFlags.fs,
|
|
549
|
-
terminal: globalFlags.terminal,
|
|
550
527
|
outputFormatter,
|
|
551
528
|
errorEmissionPolicy: { queueErrorAlreadyEmitted: outputPolicy.queueErrorAlreadyEmitted },
|
|
552
529
|
suppressSdkConsoleErrors: outputPolicy.suppressSdkConsoleErrors,
|
|
553
|
-
timeoutMs: globalFlags.timeout,
|
|
554
530
|
ttlMs: globalFlags.ttl,
|
|
555
531
|
maxQueueDepth: config.queueMaxDepth,
|
|
556
532
|
promptRetries: globalFlags.promptRetries,
|
|
557
|
-
verbose: globalFlags.verbose,
|
|
558
533
|
waitForCompletion: flags.wait !== false,
|
|
559
|
-
sessionOptions:
|
|
560
|
-
model: globalFlags.model,
|
|
561
|
-
allowedTools: globalFlags.allowedTools,
|
|
562
|
-
maxTurns: globalFlags.maxTurns,
|
|
563
|
-
systemPrompt: globalFlags.systemPrompt
|
|
564
|
-
}
|
|
534
|
+
sessionOptions: sessionOptionsFromGlobalFlags(globalFlags)
|
|
565
535
|
});
|
|
566
536
|
if ("queued" in result) {
|
|
567
537
|
printQueuedPromptByFormat(result, outputPolicy.format);
|
|
@@ -587,36 +557,24 @@ async function handleExec(explicitAgentName, promptParts, flags, command, config
|
|
|
587
557
|
const globalFlags = resolveGlobalFlags(command, config);
|
|
588
558
|
const outputPolicy = resolveRequestedOutputPolicy(globalFlags);
|
|
589
559
|
const permissionMode = resolvePermissionMode(globalFlags, config.defaultPermissions);
|
|
590
|
-
const permissionPolicy = await resolvePermissionPolicyFromFlags
|
|
591
|
-
const prompt = await
|
|
560
|
+
const permissionPolicy = await resolvePermissionPolicyFromFlags(globalFlags);
|
|
561
|
+
const prompt = await readPromptInput(flags.file, promptParts.join(" "), globalFlags.cwd);
|
|
592
562
|
const [{ createOutputFormatter }, { runOnce }] = await Promise.all([loadOutputModule(), loadSessionModule()]);
|
|
593
563
|
const outputFormatter = createOutputFormatter(outputPolicy.format, { suppressReads: outputPolicy.suppressReads });
|
|
594
564
|
const agent = resolveAgentInvocation(explicitAgentName, globalFlags, config);
|
|
595
565
|
applyPermissionExitCode(await runOnce({
|
|
566
|
+
...sessionConnectionOptions(globalFlags, config),
|
|
596
567
|
agentCommand: agent.agentCommand,
|
|
597
568
|
agentArgv: agent.agentArgv,
|
|
598
569
|
cwd: agent.cwd,
|
|
599
570
|
prompt,
|
|
600
|
-
mcpServers: config.mcpServers,
|
|
601
571
|
permissionMode,
|
|
602
|
-
nonInteractivePermissions: globalFlags.nonInteractivePermissions,
|
|
603
572
|
permissionPolicy,
|
|
604
|
-
authCredentials: config.auth,
|
|
605
|
-
authPolicy: globalFlags.authPolicy,
|
|
606
|
-
fs: globalFlags.fs,
|
|
607
|
-
terminal: globalFlags.terminal,
|
|
608
573
|
outputFormatter,
|
|
609
574
|
errorEmissionPolicy: { queueErrorAlreadyEmitted: outputPolicy.queueErrorAlreadyEmitted },
|
|
610
575
|
suppressSdkConsoleErrors: outputPolicy.suppressSdkConsoleErrors,
|
|
611
|
-
timeoutMs: globalFlags.timeout,
|
|
612
|
-
verbose: globalFlags.verbose,
|
|
613
576
|
promptRetries: globalFlags.promptRetries,
|
|
614
|
-
sessionOptions:
|
|
615
|
-
model: globalFlags.model,
|
|
616
|
-
allowedTools: globalFlags.allowedTools,
|
|
617
|
-
maxTurns: globalFlags.maxTurns,
|
|
618
|
-
systemPrompt: globalFlags.systemPrompt
|
|
619
|
-
},
|
|
577
|
+
sessionOptions: sessionOptionsFromGlobalFlags(globalFlags),
|
|
620
578
|
configOptions: flags.configOption
|
|
621
579
|
}), outputPolicy.format === "quiet" ? outputFormatter : void 0);
|
|
622
580
|
}
|
|
@@ -690,17 +648,11 @@ async function handleSetMode(explicitAgentName, modeId, flags, command, config)
|
|
|
690
648
|
const globalFlags = resolveGlobalFlags(command, config);
|
|
691
649
|
const agent = resolveAgentInvocation(explicitAgentName, globalFlags, config);
|
|
692
650
|
const { setSessionMode } = await loadSessionModule();
|
|
651
|
+
const record = await findRoutedSessionOrThrow(agent.agentCommand, agent.agentName, agent.cwd, resolveSessionNameFromFlags(flags, command));
|
|
693
652
|
const result = await setSessionMode({
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
nonInteractivePermissions: globalFlags.nonInteractivePermissions,
|
|
698
|
-
authCredentials: config.auth,
|
|
699
|
-
authPolicy: globalFlags.authPolicy,
|
|
700
|
-
fs: globalFlags.fs,
|
|
701
|
-
terminal: globalFlags.terminal,
|
|
702
|
-
timeoutMs: globalFlags.timeout,
|
|
703
|
-
verbose: globalFlags.verbose
|
|
653
|
+
...sessionConnectionOptions(globalFlags, config),
|
|
654
|
+
sessionId: record.acpxRecordId,
|
|
655
|
+
modeId
|
|
704
656
|
});
|
|
705
657
|
if (globalFlags.verbose && result.loadError) process.stderr.write(`[acpx] session reconnect failed, started fresh session: ${result.loadError}\n`);
|
|
706
658
|
printSetModeResultByFormat(modeId, result, globalFlags.format);
|
|
@@ -709,17 +661,11 @@ async function handleSetModel(explicitAgentName, modelId, flags, command, config
|
|
|
709
661
|
const globalFlags = resolveGlobalFlags(command, config);
|
|
710
662
|
const agent = resolveAgentInvocation(explicitAgentName, globalFlags, config);
|
|
711
663
|
const { setSessionModel } = await loadSessionModule();
|
|
664
|
+
const record = await findRoutedSessionOrThrow(agent.agentCommand, agent.agentName, agent.cwd, resolveSessionNameFromFlags(flags, command));
|
|
712
665
|
const result = await setSessionModel({
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
nonInteractivePermissions: globalFlags.nonInteractivePermissions,
|
|
717
|
-
authCredentials: config.auth,
|
|
718
|
-
authPolicy: globalFlags.authPolicy,
|
|
719
|
-
fs: globalFlags.fs,
|
|
720
|
-
terminal: globalFlags.terminal,
|
|
721
|
-
timeoutMs: globalFlags.timeout,
|
|
722
|
-
verbose: globalFlags.verbose
|
|
666
|
+
...sessionConnectionOptions(globalFlags, config),
|
|
667
|
+
sessionId: record.acpxRecordId,
|
|
668
|
+
modelId
|
|
723
669
|
});
|
|
724
670
|
if (globalFlags.verbose && result.loadError) process.stderr.write(`[acpx] session reconnect failed, started fresh session: ${result.loadError}\n`);
|
|
725
671
|
printSetModelResultByFormat(modelId, result, globalFlags.format);
|
|
@@ -733,43 +679,30 @@ async function handleSetConfigOption(explicitAgentName, configId, value, flags,
|
|
|
733
679
|
}
|
|
734
680
|
const resolvedConfigId = resolveCompatibleConfigId(agent, configId);
|
|
735
681
|
const { setSessionConfigOption } = await loadSessionModule();
|
|
682
|
+
const record = await findRoutedSessionOrThrow(agent.agentCommand, agent.agentName, agent.cwd, resolveSessionNameFromFlags(flags, command));
|
|
736
683
|
const result = await setSessionConfigOption({
|
|
737
|
-
|
|
684
|
+
...sessionConnectionOptions(globalFlags, config),
|
|
685
|
+
sessionId: record.acpxRecordId,
|
|
738
686
|
configId: resolvedConfigId,
|
|
739
|
-
value
|
|
740
|
-
mcpServers: config.mcpServers,
|
|
741
|
-
nonInteractivePermissions: globalFlags.nonInteractivePermissions,
|
|
742
|
-
authCredentials: config.auth,
|
|
743
|
-
authPolicy: globalFlags.authPolicy,
|
|
744
|
-
fs: globalFlags.fs,
|
|
745
|
-
terminal: globalFlags.terminal,
|
|
746
|
-
timeoutMs: globalFlags.timeout,
|
|
747
|
-
verbose: globalFlags.verbose
|
|
687
|
+
value
|
|
748
688
|
});
|
|
749
689
|
if (globalFlags.verbose && result.loadError) process.stderr.write(`[acpx] session reconnect failed, started fresh session: ${result.loadError}\n`);
|
|
750
690
|
printSetConfigOptionResultByFormat(configId, value, result, globalFlags.format);
|
|
751
691
|
}
|
|
752
692
|
async function tryListAgentSessions(agent, flags, globalFlags, config) {
|
|
753
693
|
const permissionMode = resolvePermissionMode(globalFlags, config.defaultPermissions);
|
|
754
|
-
const permissionPolicy = await resolvePermissionPolicyFromFlags
|
|
694
|
+
const permissionPolicy = await resolvePermissionPolicyFromFlags(globalFlags);
|
|
755
695
|
const { listAgentSessions } = await loadSessionModule();
|
|
756
696
|
try {
|
|
757
697
|
return await listAgentSessions({
|
|
698
|
+
...sessionConnectionOptions(globalFlags, config),
|
|
758
699
|
agentCommand: agent.agentCommand,
|
|
759
700
|
agentArgv: agent.agentArgv,
|
|
760
701
|
cwd: agent.cwd,
|
|
761
702
|
cursor: flags.cursor,
|
|
762
703
|
filterCwd: resolveSessionListFilterCwd(flags, agent.cwd),
|
|
763
|
-
mcpServers: config.mcpServers,
|
|
764
704
|
permissionMode,
|
|
765
|
-
|
|
766
|
-
permissionPolicy,
|
|
767
|
-
authCredentials: config.auth,
|
|
768
|
-
authPolicy: globalFlags.authPolicy,
|
|
769
|
-
fs: globalFlags.fs,
|
|
770
|
-
terminal: globalFlags.terminal,
|
|
771
|
-
timeoutMs: globalFlags.timeout,
|
|
772
|
-
verbose: globalFlags.verbose
|
|
705
|
+
permissionPolicy
|
|
773
706
|
});
|
|
774
707
|
} catch (error) {
|
|
775
708
|
if (error instanceof AgentSpawnError) return "spawn-failed";
|
|
@@ -808,7 +741,7 @@ async function handleSessionsClose(explicitAgentName, sessionName, command, conf
|
|
|
808
741
|
async function handleSessionsNew(explicitAgentName, flags, command, config) {
|
|
809
742
|
const globalFlags = resolveGlobalFlags(command, config);
|
|
810
743
|
const permissionMode = resolvePermissionMode(globalFlags, config.defaultPermissions);
|
|
811
|
-
const permissionPolicy = await resolvePermissionPolicyFromFlags
|
|
744
|
+
const permissionPolicy = await resolvePermissionPolicyFromFlags(globalFlags);
|
|
812
745
|
const agent = resolveAgentInvocation(explicitAgentName, globalFlags, config);
|
|
813
746
|
const [{ createSession, closeSession }, { printCreatedSessionBanner, printNewSessionByFormat }] = await Promise.all([loadSessionModule(), loadOutputRenderModule()]);
|
|
814
747
|
const replaced = await findSession({
|
|
@@ -838,7 +771,7 @@ async function handleSessionsNew(explicitAgentName, flags, command, config) {
|
|
|
838
771
|
async function handleSessionsEnsure(explicitAgentName, flags, command, config) {
|
|
839
772
|
const globalFlags = resolveGlobalFlags(command, config);
|
|
840
773
|
const permissionMode = resolvePermissionMode(globalFlags, config.defaultPermissions);
|
|
841
|
-
const permissionPolicy = await resolvePermissionPolicyFromFlags
|
|
774
|
+
const permissionPolicy = await resolvePermissionPolicyFromFlags(globalFlags);
|
|
842
775
|
const agent = resolveAgentInvocation(explicitAgentName, globalFlags, config);
|
|
843
776
|
const [{ ensureSession }, { printCreatedSessionBanner, printEnsuredSessionByFormat }] = await Promise.all([loadSessionModule(), loadOutputRenderModule()]);
|
|
844
777
|
const result = await ensureSession(buildSessionStartOptions({
|
|
@@ -1017,13 +950,6 @@ async function handleSessionsPrune(explicitAgentName, flags, command, config) {
|
|
|
1017
950
|
//#region src/cli/compare-command.ts
|
|
1018
951
|
const DEFAULT_COMPARE_TIMEOUT_MS = 3e5;
|
|
1019
952
|
const FINAL_MESSAGE_PREVIEW_CHARS = 200;
|
|
1020
|
-
var CaptureFormatter = class {
|
|
1021
|
-
setContext(_context) {}
|
|
1022
|
-
onAcpMessage(_message) {}
|
|
1023
|
-
onError(params) {}
|
|
1024
|
-
onPermissionEscalation(_event) {}
|
|
1025
|
-
flush() {}
|
|
1026
|
-
};
|
|
1027
953
|
function asRecord$2(value) {
|
|
1028
954
|
return Boolean(value) && typeof value === "object" && !Array.isArray(value) ? value : void 0;
|
|
1029
955
|
}
|
|
@@ -1042,34 +968,6 @@ function truncate(value, maxChars) {
|
|
|
1042
968
|
if (value.length <= maxChars) return value;
|
|
1043
969
|
return `${value.slice(0, Math.max(0, maxChars - 3))}...`;
|
|
1044
970
|
}
|
|
1045
|
-
async function readStdin() {
|
|
1046
|
-
let data = "";
|
|
1047
|
-
for await (const chunk of process.stdin) data += String(chunk);
|
|
1048
|
-
return data;
|
|
1049
|
-
}
|
|
1050
|
-
async function readPromptFile(filePath, promptText, cwd) {
|
|
1051
|
-
const source = filePath === "-" ? await readStdin() : await fs$1.readFile(path.resolve(cwd, filePath), "utf8");
|
|
1052
|
-
const prompt = mergePromptSourceWithText(source, promptText);
|
|
1053
|
-
if (prompt.length === 0) throw new InvalidArgumentError("Prompt from --file is empty");
|
|
1054
|
-
return prompt;
|
|
1055
|
-
}
|
|
1056
|
-
async function readPromptFromStdin() {
|
|
1057
|
-
if (process.stdin.isTTY) throw new InvalidArgumentError("Prompt is required (pass as final argument, --file, or pipe via stdin)");
|
|
1058
|
-
const prompt = parsePromptSource(await readStdin());
|
|
1059
|
-
if (prompt.length === 0) throw new InvalidArgumentError("Prompt from stdin is empty");
|
|
1060
|
-
return prompt;
|
|
1061
|
-
}
|
|
1062
|
-
async function readPromptInput(filePath, promptText, cwd) {
|
|
1063
|
-
try {
|
|
1064
|
-
if (filePath) return await readPromptFile(filePath, promptText, cwd);
|
|
1065
|
-
const joined = promptText.trim();
|
|
1066
|
-
if (joined.length > 0) return textPrompt(joined);
|
|
1067
|
-
return await readPromptFromStdin();
|
|
1068
|
-
} catch (error) {
|
|
1069
|
-
if (error instanceof PromptInputValidationError) throw new InvalidArgumentError(error.message);
|
|
1070
|
-
throw error;
|
|
1071
|
-
}
|
|
1072
|
-
}
|
|
1073
971
|
function promptTokensAfterDoubleDash(command) {
|
|
1074
972
|
const commandName = command.name();
|
|
1075
973
|
const commandIndex = process.argv.findIndex((token, index) => index >= 2 && token === commandName);
|
|
@@ -1126,22 +1024,6 @@ function captureSessionUpdate(notification, capture) {
|
|
|
1126
1024
|
function rowStatusFromPermissionStats(stats) {
|
|
1127
1025
|
return stats.denied + stats.cancelled > 0 ? "permission_denied" : "ok";
|
|
1128
1026
|
}
|
|
1129
|
-
function sessionOptionsFromGlobalFlags(globalFlags) {
|
|
1130
|
-
return {
|
|
1131
|
-
model: globalFlags.model,
|
|
1132
|
-
allowedTools: globalFlags.allowedTools,
|
|
1133
|
-
maxTurns: globalFlags.maxTurns,
|
|
1134
|
-
systemPrompt: globalFlags.systemPrompt
|
|
1135
|
-
};
|
|
1136
|
-
}
|
|
1137
|
-
async function resolvePermissionPolicyFromFlags(globalFlags) {
|
|
1138
|
-
try {
|
|
1139
|
-
return await loadPermissionPolicySpec(globalFlags.permissionPolicy, globalFlags.cwd);
|
|
1140
|
-
} catch (error) {
|
|
1141
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
1142
|
-
throw new InvalidArgumentError(`Invalid permission policy: ${message}`);
|
|
1143
|
-
}
|
|
1144
|
-
}
|
|
1145
1027
|
function buildSuccessRow(agentName, result, capture, startedAt) {
|
|
1146
1028
|
const permissionStats = result.permissionStats;
|
|
1147
1029
|
return {
|
|
@@ -1177,30 +1059,22 @@ function buildErrorRow(agentName, caught, capture, startedAt) {
|
|
|
1177
1059
|
async function runAgentForCompare(params) {
|
|
1178
1060
|
const capture = {
|
|
1179
1061
|
finalMessage: "",
|
|
1180
|
-
usage: {}
|
|
1181
|
-
errors: []
|
|
1062
|
+
usage: {}
|
|
1182
1063
|
};
|
|
1183
|
-
const formatter = new CaptureFormatter();
|
|
1184
1064
|
const t0 = performance.now();
|
|
1185
1065
|
try {
|
|
1186
1066
|
const agent = resolveAgentInvocation(params.agentName, params.globalFlags, params.config);
|
|
1187
1067
|
const result = await runOnce({
|
|
1068
|
+
...sessionConnectionOptions(params.globalFlags, params.config),
|
|
1188
1069
|
agentCommand: agent.agentCommand,
|
|
1189
1070
|
agentArgv: agent.agentArgv,
|
|
1190
1071
|
cwd: agent.cwd,
|
|
1191
1072
|
prompt: params.prompt,
|
|
1192
|
-
mcpServers: params.config.mcpServers,
|
|
1193
1073
|
permissionMode: resolvePermissionMode(params.globalFlags, params.config.defaultPermissions),
|
|
1194
|
-
nonInteractivePermissions: params.globalFlags.nonInteractivePermissions,
|
|
1195
1074
|
permissionPolicy: params.permissionPolicy,
|
|
1196
|
-
|
|
1197
|
-
authPolicy: params.globalFlags.authPolicy,
|
|
1198
|
-
fs: params.globalFlags.fs,
|
|
1199
|
-
terminal: params.globalFlags.terminal,
|
|
1200
|
-
outputFormatter: formatter,
|
|
1075
|
+
outputFormatter: DISCARD_OUTPUT_FORMATTER,
|
|
1201
1076
|
suppressSdkConsoleErrors: true,
|
|
1202
1077
|
timeoutMs: params.globalFlags.timeout ?? DEFAULT_COMPARE_TIMEOUT_MS,
|
|
1203
|
-
verbose: params.globalFlags.verbose,
|
|
1204
1078
|
promptRetries: params.globalFlags.promptRetries,
|
|
1205
1079
|
sessionOptions: sessionOptionsFromGlobalFlags(params.globalFlags),
|
|
1206
1080
|
onSessionUpdate: (notification) => captureSessionUpdate(notification, capture)
|
|
@@ -1283,7 +1157,7 @@ function registerCompareCommand(program, config) {
|
|
|
1283
1157
|
const outputPolicy = resolveOutputPolicy(flags.json === true ? "json" : globalFlags.format, globalFlags.jsonStrict === true);
|
|
1284
1158
|
const promptFile = resolvePromptFile(flags);
|
|
1285
1159
|
const { agents, promptText } = splitCompareArgs(args, promptFile, this);
|
|
1286
|
-
const prompt = await readPromptInput(promptFile, promptText, globalFlags.cwd);
|
|
1160
|
+
const prompt = await readPromptInput(promptFile, promptText, globalFlags.cwd, "final argument");
|
|
1287
1161
|
const permissionPolicy = await resolvePermissionPolicyFromFlags(globalFlags);
|
|
1288
1162
|
const rows = [];
|
|
1289
1163
|
for (const agentName of agents) rows.push(await runAgentForCompare({
|
|
@@ -1307,21 +1181,19 @@ function parseNonEmptyString(value, path) {
|
|
|
1307
1181
|
if (typeof value !== "string" || value.trim().length === 0) throw new Error(`Invalid ${path}: expected non-empty string`);
|
|
1308
1182
|
return value.trim();
|
|
1309
1183
|
}
|
|
1310
|
-
function
|
|
1184
|
+
function parseNameValuePairs(value, path) {
|
|
1311
1185
|
if (value == null) return [];
|
|
1312
1186
|
if (!Array.isArray(value)) throw new Error(`Invalid ${path}: expected array`);
|
|
1313
|
-
const
|
|
1314
|
-
for (const [index,
|
|
1315
|
-
const
|
|
1316
|
-
if (!
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
name,
|
|
1321
|
-
value: headerValue
|
|
1187
|
+
const entries = [];
|
|
1188
|
+
for (const [index, rawEntry] of value.entries()) {
|
|
1189
|
+
const entry = asRecord$1(rawEntry);
|
|
1190
|
+
if (!entry) throw new Error(`Invalid ${path}[${index}]: expected object`);
|
|
1191
|
+
entries.push({
|
|
1192
|
+
name: parseNonEmptyString(entry.name, `${path}[${index}].name`),
|
|
1193
|
+
value: parseNonEmptyString(entry.value, `${path}[${index}].value`)
|
|
1322
1194
|
});
|
|
1323
1195
|
}
|
|
1324
|
-
return
|
|
1196
|
+
return entries;
|
|
1325
1197
|
}
|
|
1326
1198
|
function parseArgs(value, path) {
|
|
1327
1199
|
if (value == null) return [];
|
|
@@ -1333,22 +1205,6 @@ function parseArgs(value, path) {
|
|
|
1333
1205
|
}
|
|
1334
1206
|
return args;
|
|
1335
1207
|
}
|
|
1336
|
-
function parseEnv(value, path) {
|
|
1337
|
-
if (value == null) return [];
|
|
1338
|
-
if (!Array.isArray(value)) throw new Error(`Invalid ${path}: expected array`);
|
|
1339
|
-
const env = [];
|
|
1340
|
-
for (const [index, rawEntry] of value.entries()) {
|
|
1341
|
-
const entry = asRecord$1(rawEntry);
|
|
1342
|
-
if (!entry) throw new Error(`Invalid ${path}[${index}]: expected object`);
|
|
1343
|
-
const name = parseNonEmptyString(entry.name, `${path}[${index}].name`);
|
|
1344
|
-
const envValue = parseNonEmptyString(entry.value, `${path}[${index}].value`);
|
|
1345
|
-
env.push({
|
|
1346
|
-
name,
|
|
1347
|
-
value: envValue
|
|
1348
|
-
});
|
|
1349
|
-
}
|
|
1350
|
-
return env;
|
|
1351
|
-
}
|
|
1352
1208
|
function parseMeta(value, path) {
|
|
1353
1209
|
if (value === void 0) return;
|
|
1354
1210
|
if (value === null) return null;
|
|
@@ -1366,7 +1222,7 @@ function parseHttpServer(serverRecord, path, type, name, _meta) {
|
|
|
1366
1222
|
type,
|
|
1367
1223
|
name,
|
|
1368
1224
|
url: parseNonEmptyString(serverRecord.url, `${path}.url`),
|
|
1369
|
-
headers:
|
|
1225
|
+
headers: parseNameValuePairs(serverRecord.headers, `${path}.headers`),
|
|
1370
1226
|
_meta
|
|
1371
1227
|
};
|
|
1372
1228
|
}
|
|
@@ -1375,7 +1231,7 @@ function parseStdioServer(serverRecord, path, name, _meta) {
|
|
|
1375
1231
|
name,
|
|
1376
1232
|
command: parseNonEmptyString(serverRecord.command, `${path}.command`),
|
|
1377
1233
|
args: parseArgs(serverRecord.args, `${path}.args`),
|
|
1378
|
-
env:
|
|
1234
|
+
env: parseNameValuePairs(serverRecord.env, `${path}.env`),
|
|
1379
1235
|
_meta
|
|
1380
1236
|
};
|
|
1381
1237
|
}
|
|
@@ -1488,7 +1344,7 @@ function parseArgvAgentEntry(raw, name, sourcePath) {
|
|
|
1488
1344
|
if (Object.prototype.hasOwnProperty.call(raw, "command") || Object.prototype.hasOwnProperty.call(raw, "args")) throw new Error(`Invalid config agents.${name} in ${sourcePath}: use argv alone, not command or args`);
|
|
1489
1345
|
const argv = parseAgentArgv(raw.argv, name, sourcePath);
|
|
1490
1346
|
return {
|
|
1491
|
-
command:
|
|
1347
|
+
command: renderArgvIdentity(argv),
|
|
1492
1348
|
argv
|
|
1493
1349
|
};
|
|
1494
1350
|
}
|
|
@@ -1524,9 +1380,6 @@ function parseAgentArgs(value, agentName, sourcePath) {
|
|
|
1524
1380
|
function quoteCommandArg(value) {
|
|
1525
1381
|
return JSON.stringify(value);
|
|
1526
1382
|
}
|
|
1527
|
-
function renderArgv(argv) {
|
|
1528
|
-
return renderArgvIdentity(argv);
|
|
1529
|
-
}
|
|
1530
1383
|
function parseAuth(value, sourcePath) {
|
|
1531
1384
|
if (value == null) return;
|
|
1532
1385
|
if (!isObject(value)) throw new Error(`Invalid config auth in ${sourcePath}: expected object`);
|
|
@@ -1572,18 +1425,6 @@ async function loadExplicitMcpConfig(cwd, configuredPath) {
|
|
|
1572
1425
|
config: result.config
|
|
1573
1426
|
};
|
|
1574
1427
|
}
|
|
1575
|
-
function mergeAgents(globalAgents, projectAgents) {
|
|
1576
|
-
return {
|
|
1577
|
-
...globalAgents,
|
|
1578
|
-
...projectAgents
|
|
1579
|
-
};
|
|
1580
|
-
}
|
|
1581
|
-
function mergeAuth(globalAuth, projectAuth) {
|
|
1582
|
-
return {
|
|
1583
|
-
...globalAuth,
|
|
1584
|
-
...projectAuth
|
|
1585
|
-
};
|
|
1586
|
-
}
|
|
1587
1428
|
async function loadResolvedConfig(cwd, options = {}) {
|
|
1588
1429
|
const globalPath = defaultGlobalConfigPath();
|
|
1589
1430
|
const projectPath = projectConfigPath(cwd);
|
|
@@ -1594,11 +1435,29 @@ async function loadResolvedConfig(cwd, options = {}) {
|
|
|
1594
1435
|
]);
|
|
1595
1436
|
const globalConfig = globalResult.config;
|
|
1596
1437
|
const projectConfig = projectResult.config;
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1438
|
+
function resolveScalar(key, parse, fallback) {
|
|
1439
|
+
return parse(projectConfig?.[key], projectPath) ?? parse(globalConfig?.[key], globalPath) ?? fallback;
|
|
1440
|
+
}
|
|
1441
|
+
const scalar = {
|
|
1442
|
+
defaultAgent: resolveScalar("defaultAgent", parseDefaultAgent, DEFAULT_AGENT_NAME),
|
|
1443
|
+
defaultPermissions: resolveScalar("defaultPermissions", parsePermissionMode, DEFAULT_PERMISSION_MODE),
|
|
1444
|
+
nonInteractivePermissions: resolveScalar("nonInteractivePermissions", parseNonInteractivePermissionPolicy, DEFAULT_NON_INTERACTIVE_PERMISSION_POLICY),
|
|
1445
|
+
authPolicy: resolveScalar("authPolicy", parseAuthPolicy, DEFAULT_AUTH_POLICY),
|
|
1446
|
+
ttlMs: resolveScalar("ttl", parseTtlMs, DEFAULT_TTL_MS),
|
|
1447
|
+
timeoutMs: resolveTimeoutMs(projectConfig, projectPath, globalConfig, globalPath),
|
|
1448
|
+
queueMaxDepth: resolveScalar("queueMaxDepth", parseQueueMaxDepth, DEFAULT_QUEUE_MAX_DEPTH),
|
|
1449
|
+
format: resolveScalar("format", parseOutputFormat, DEFAULT_OUTPUT_FORMAT)
|
|
1450
|
+
};
|
|
1451
|
+
const agents = {
|
|
1452
|
+
...parseAgents(globalConfig?.agents, globalPath),
|
|
1453
|
+
...parseAgents(projectConfig?.agents, projectPath)
|
|
1454
|
+
};
|
|
1455
|
+
const auth = {
|
|
1456
|
+
...parseAuth(globalConfig?.auth, globalPath),
|
|
1457
|
+
...parseAuth(projectConfig?.auth, projectPath)
|
|
1458
|
+
};
|
|
1600
1459
|
const mcpServers = resolveMcpServers(projectConfig, projectPath, globalConfig, globalPath, explicitMcp.config, explicitMcp.path);
|
|
1601
|
-
const disableExec =
|
|
1460
|
+
const disableExec = resolveScalar("disableExec", parseDisableExec, DEFAULT_DISABLE_EXEC);
|
|
1602
1461
|
return {
|
|
1603
1462
|
...scalar,
|
|
1604
1463
|
agents,
|
|
@@ -1613,39 +1472,6 @@ async function loadResolvedConfig(cwd, options = {}) {
|
|
|
1613
1472
|
hasProjectConfig: projectResult.exists
|
|
1614
1473
|
};
|
|
1615
1474
|
}
|
|
1616
|
-
function resolveScalarConfigValues(projectConfig, projectPath, globalConfig, globalPath) {
|
|
1617
|
-
return {
|
|
1618
|
-
defaultAgent: resolveDefaultAgent(projectConfig, projectPath, globalConfig, globalPath),
|
|
1619
|
-
defaultPermissions: resolveDefaultPermissions(projectConfig, projectPath, globalConfig, globalPath),
|
|
1620
|
-
nonInteractivePermissions: resolveNonInteractivePermissions(projectConfig, projectPath, globalConfig, globalPath),
|
|
1621
|
-
authPolicy: resolveAuthPolicy(projectConfig, projectPath, globalConfig, globalPath),
|
|
1622
|
-
ttlMs: resolveTtlMs(projectConfig, projectPath, globalConfig, globalPath),
|
|
1623
|
-
timeoutMs: resolveTimeoutMs(projectConfig, projectPath, globalConfig, globalPath),
|
|
1624
|
-
queueMaxDepth: resolveQueueMaxDepth(projectConfig, projectPath, globalConfig, globalPath),
|
|
1625
|
-
format: resolveFormat(projectConfig, projectPath, globalConfig, globalPath)
|
|
1626
|
-
};
|
|
1627
|
-
}
|
|
1628
|
-
function resolveDefaultAgent(projectConfig, projectPath, globalConfig, globalPath) {
|
|
1629
|
-
return parseDefaultAgent(projectConfig?.defaultAgent, projectPath) ?? parseDefaultAgent(globalConfig?.defaultAgent, globalPath) ?? "codex";
|
|
1630
|
-
}
|
|
1631
|
-
function resolveDefaultPermissions(projectConfig, projectPath, globalConfig, globalPath) {
|
|
1632
|
-
return parsePermissionMode(projectConfig?.defaultPermissions, projectPath) ?? parsePermissionMode(globalConfig?.defaultPermissions, globalPath) ?? DEFAULT_PERMISSION_MODE;
|
|
1633
|
-
}
|
|
1634
|
-
function resolveNonInteractivePermissions(projectConfig, projectPath, globalConfig, globalPath) {
|
|
1635
|
-
return parseNonInteractivePermissionPolicy(projectConfig?.nonInteractivePermissions, projectPath) ?? parseNonInteractivePermissionPolicy(globalConfig?.nonInteractivePermissions, globalPath) ?? DEFAULT_NON_INTERACTIVE_PERMISSION_POLICY;
|
|
1636
|
-
}
|
|
1637
|
-
function resolveAuthPolicy(projectConfig, projectPath, globalConfig, globalPath) {
|
|
1638
|
-
return parseAuthPolicy(projectConfig?.authPolicy, projectPath) ?? parseAuthPolicy(globalConfig?.authPolicy, globalPath) ?? DEFAULT_AUTH_POLICY;
|
|
1639
|
-
}
|
|
1640
|
-
function resolveTtlMs(projectConfig, projectPath, globalConfig, globalPath) {
|
|
1641
|
-
return parseTtlMs(projectConfig?.ttl, projectPath) ?? parseTtlMs(globalConfig?.ttl, globalPath) ?? DEFAULT_TTL_MS;
|
|
1642
|
-
}
|
|
1643
|
-
function resolveQueueMaxDepth(projectConfig, projectPath, globalConfig, globalPath) {
|
|
1644
|
-
return parseQueueMaxDepth(projectConfig?.queueMaxDepth, projectPath) ?? parseQueueMaxDepth(globalConfig?.queueMaxDepth, globalPath) ?? DEFAULT_QUEUE_MAX_DEPTH;
|
|
1645
|
-
}
|
|
1646
|
-
function resolveFormat(projectConfig, projectPath, globalConfig, globalPath) {
|
|
1647
|
-
return parseOutputFormat(projectConfig?.format, projectPath) ?? parseOutputFormat(globalConfig?.format, globalPath) ?? DEFAULT_OUTPUT_FORMAT;
|
|
1648
|
-
}
|
|
1649
1475
|
function hasConfigKey(config, key) {
|
|
1650
1476
|
return config != null && Object.prototype.hasOwnProperty.call(config, key);
|
|
1651
1477
|
}
|
|
@@ -1659,9 +1485,6 @@ function resolveMcpServers(projectConfig, projectPath, globalConfig, globalPath,
|
|
|
1659
1485
|
if (hasConfigKey(globalConfig, "mcpServers")) return parseMcpServers(globalConfig?.mcpServers, globalPath);
|
|
1660
1486
|
return [];
|
|
1661
1487
|
}
|
|
1662
|
-
function resolveDisableExec(projectConfig, projectPath, globalConfig, globalPath) {
|
|
1663
|
-
return parseDisableExec(projectConfig?.disableExec, projectPath) ?? parseDisableExec(globalConfig?.disableExec, globalPath) ?? DEFAULT_DISABLE_EXEC;
|
|
1664
|
-
}
|
|
1665
1488
|
function toConfigDisplay(config) {
|
|
1666
1489
|
const agents = {};
|
|
1667
1490
|
for (const [name, agent] of Object.entries(config.agents)) agents[name] = agent.argv ? { argv: [...agent.argv] } : { command: agent.command };
|
|
@@ -1681,7 +1504,10 @@ function toConfigDisplay(config) {
|
|
|
1681
1504
|
}
|
|
1682
1505
|
async function initGlobalConfigFile() {
|
|
1683
1506
|
const configPath = defaultGlobalConfigPath();
|
|
1684
|
-
await fs$1.mkdir(path.dirname(configPath), {
|
|
1507
|
+
await fs$1.mkdir(path.dirname(configPath), {
|
|
1508
|
+
recursive: true,
|
|
1509
|
+
mode: 448
|
|
1510
|
+
});
|
|
1685
1511
|
try {
|
|
1686
1512
|
await fs$1.access(configPath);
|
|
1687
1513
|
return {
|
|
@@ -1704,7 +1530,8 @@ async function initGlobalConfigFile() {
|
|
|
1704
1530
|
try {
|
|
1705
1531
|
await fs$1.writeFile(configPath, `${JSON.stringify(payload, null, 2)}\n`, {
|
|
1706
1532
|
encoding: "utf8",
|
|
1707
|
-
flag: "wx"
|
|
1533
|
+
flag: "wx",
|
|
1534
|
+
mode: 384
|
|
1708
1535
|
});
|
|
1709
1536
|
} catch (error) {
|
|
1710
1537
|
if (error.code === "EEXIST") return {
|
|
@@ -1968,7 +1795,7 @@ function formatPruneSummaryLine(result, count) {
|
|
|
1968
1795
|
return `${prefix} ${count} session${count === 1 ? "" : "s"}${bytesSuffix}`;
|
|
1969
1796
|
}
|
|
1970
1797
|
function agentSessionIdPayload(agentSessionId) {
|
|
1971
|
-
const normalized =
|
|
1798
|
+
const normalized = normalizeAgentSessionId(agentSessionId);
|
|
1972
1799
|
if (!normalized) return {};
|
|
1973
1800
|
return { agentSessionId: normalized };
|
|
1974
1801
|
}
|
|
@@ -2240,7 +2067,7 @@ function registerAgentCommand(program, agentName, config) {
|
|
|
2240
2067
|
}
|
|
2241
2068
|
function registerFlowCommand(program, config) {
|
|
2242
2069
|
program.command("flow").description("Run multi-step ACP workflows from flow files").command("run").description("Run a flow file").argument("<file>", "Flow module path").option("--input-json <json>", "Flow input as JSON").option("--input-file <path>", "Read flow input JSON from file").option("--default-agent <name>", "Default agent profile for ACP nodes without profile", (value) => parseNonEmptyValue("Default agent", value)).action(async function(file, flags) {
|
|
2243
|
-
const { handleFlowRun } = await import("./cli-
|
|
2070
|
+
const { handleFlowRun } = await import("./cli-BkYIxj_N.js");
|
|
2244
2071
|
await handleFlowRun(file, flags, this, config);
|
|
2245
2072
|
});
|
|
2246
2073
|
}
|
|
@@ -2259,15 +2086,19 @@ function registerDefaultCommands(program, config) {
|
|
|
2259
2086
|
registerFlowCommand(program, config);
|
|
2260
2087
|
}
|
|
2261
2088
|
//#endregion
|
|
2262
|
-
//#region src/cli/queue/owner-
|
|
2263
|
-
const QUEUE_OWNER_PAYLOAD_FILE_ENV = "ACPX_QUEUE_OWNER_PAYLOAD_FILE";
|
|
2264
|
-
const QUEUE_OWNER_PAYLOAD_ENV = "ACPX_QUEUE_OWNER_PAYLOAD";
|
|
2089
|
+
//#region src/cli/queue/owner-input.ts
|
|
2265
2090
|
function asRecord(value) {
|
|
2266
2091
|
if (!value || typeof value !== "object" || Array.isArray(value)) return;
|
|
2267
2092
|
return value;
|
|
2268
2093
|
}
|
|
2269
2094
|
function parseQueueOwnerPayload(raw) {
|
|
2270
|
-
|
|
2095
|
+
let parsed;
|
|
2096
|
+
try {
|
|
2097
|
+
parsed = JSON.parse(raw);
|
|
2098
|
+
} catch {
|
|
2099
|
+
throw new Error("queue owner payload must be valid JSON");
|
|
2100
|
+
}
|
|
2101
|
+
const record = asRecord(parsed);
|
|
2271
2102
|
if (!record) throw new Error("queue owner payload must be an object");
|
|
2272
2103
|
if (typeof record.sessionId !== "string" || record.sessionId.trim().length === 0) throw new Error("queue owner payload missing sessionId");
|
|
2273
2104
|
if (record.permissionMode !== "approve-all" && record.permissionMode !== "approve-reads" && record.permissionMode !== "deny-all") throw new Error("queue owner payload has invalid permissionMode");
|
|
@@ -2343,30 +2174,10 @@ function assignSessionEnv(options, value) {
|
|
|
2343
2174
|
const entries = Object.entries(env).filter((entry) => typeof entry[1] === "string");
|
|
2344
2175
|
if (entries.length > 0) options.env = Object.fromEntries(entries);
|
|
2345
2176
|
}
|
|
2346
|
-
async function
|
|
2347
|
-
const
|
|
2348
|
-
|
|
2349
|
-
|
|
2350
|
-
async function readQueueOwnerPayloadFromEnv(env) {
|
|
2351
|
-
const payloadFile = env[QUEUE_OWNER_PAYLOAD_FILE_ENV];
|
|
2352
|
-
if (payloadFile) {
|
|
2353
|
-
const payload = await fs$1.readFile(payloadFile, "utf8");
|
|
2354
|
-
await cleanupQueueOwnerPayloadFile(payloadFile).catch(() => {});
|
|
2355
|
-
return payload;
|
|
2356
|
-
}
|
|
2357
|
-
const payload = env[QUEUE_OWNER_PAYLOAD_ENV];
|
|
2358
|
-
if (!payload) throw new Error(`missing ${QUEUE_OWNER_PAYLOAD_ENV}`);
|
|
2359
|
-
return payload;
|
|
2360
|
-
}
|
|
2361
|
-
async function cleanupQueueOwnerPayloadFile(payloadFile) {
|
|
2362
|
-
if (!isQueueOwnerPayloadFile(payloadFile)) return;
|
|
2363
|
-
await fs$1.unlink(payloadFile).catch(() => {});
|
|
2364
|
-
await fs$1.rmdir(path.dirname(payloadFile)).catch(() => {});
|
|
2365
|
-
}
|
|
2366
|
-
function isQueueOwnerPayloadFile(payloadFile) {
|
|
2367
|
-
const resolved = path.resolve(payloadFile);
|
|
2368
|
-
const payloadDir = path.dirname(resolved);
|
|
2369
|
-
return path.dirname(payloadDir) === path.resolve(os.tmpdir()) && path.basename(payloadDir).startsWith("acpx-queue-owner-") && path.basename(resolved) === "payload.json";
|
|
2177
|
+
async function runQueueOwnerFromStdin() {
|
|
2178
|
+
const payload = await text(process.stdin);
|
|
2179
|
+
if (!payload) throw new Error("queue owner startup payload is empty");
|
|
2180
|
+
await runSessionQueueOwner(parseQueueOwnerPayload(payload));
|
|
2370
2181
|
}
|
|
2371
2182
|
//#endregion
|
|
2372
2183
|
//#region src/cli-core.ts
|
|
@@ -2608,9 +2419,6 @@ async function emitRequestedError(error, normalized, outputPolicy) {
|
|
|
2608
2419
|
if (outputPolicy.format === "text") for (const hint of getTextErrorRemediationHints(normalized)) process.stderr.write(`${hint}\n`);
|
|
2609
2420
|
}
|
|
2610
2421
|
}
|
|
2611
|
-
async function runWithOutputPolicy(_outputPolicy, run) {
|
|
2612
|
-
return await run();
|
|
2613
|
-
}
|
|
2614
2422
|
async function handleQueueOwnerCommand(argv) {
|
|
2615
2423
|
installPerfMetricsCapture({
|
|
2616
2424
|
argv: argv.slice(2),
|
|
@@ -2618,7 +2426,7 @@ async function handleQueueOwnerCommand(argv) {
|
|
|
2618
2426
|
});
|
|
2619
2427
|
if (argv[2] !== "__queue-owner") return false;
|
|
2620
2428
|
try {
|
|
2621
|
-
await
|
|
2429
|
+
await runQueueOwnerFromStdin();
|
|
2622
2430
|
return true;
|
|
2623
2431
|
} catch (error) {
|
|
2624
2432
|
const message = error instanceof Error ? error.message : String(error);
|
|
@@ -2700,13 +2508,9 @@ async function main(argv = process.argv) {
|
|
|
2700
2508
|
throw error;
|
|
2701
2509
|
});
|
|
2702
2510
|
try {
|
|
2703
|
-
await
|
|
2704
|
-
|
|
2705
|
-
|
|
2706
|
-
} catch (error) {
|
|
2707
|
-
await handleProgramParseError(error, requestedOutputPolicy);
|
|
2708
|
-
}
|
|
2709
|
-
});
|
|
2511
|
+
await program.parseAsync(normalizedArgv);
|
|
2512
|
+
} catch (error) {
|
|
2513
|
+
await handleProgramParseError(error, requestedOutputPolicy);
|
|
2710
2514
|
} finally {
|
|
2711
2515
|
flushPerfMetricsCapture();
|
|
2712
2516
|
}
|