agent-valley 4.2.0 → 4.3.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/assets/plugin.json +1 -1
- package/dist/index.js +294 -119
- package/dist/supervisor.js +2 -1
- package/package.json +1 -1
package/dist/assets/plugin.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://agent-plugins.org/schemas/1.0.0/plugin.schema.json",
|
|
3
3
|
"name": "av",
|
|
4
|
-
"version": "4.
|
|
4
|
+
"version": "4.3.0",
|
|
5
5
|
"description": "Delegate repository goals to Agent Valley and inspect mission progress and verification evidence.",
|
|
6
6
|
"author": {
|
|
7
7
|
"name": "Agent Valley"
|
package/dist/index.js
CHANGED
|
@@ -7091,6 +7091,7 @@ var init_contracts = __esm(() => {
|
|
|
7091
7091
|
"unknown-effect",
|
|
7092
7092
|
"budget",
|
|
7093
7093
|
"interrupted",
|
|
7094
|
+
"service-shutdown",
|
|
7094
7095
|
"chief-wait",
|
|
7095
7096
|
"chief-unavailable",
|
|
7096
7097
|
"integrity"
|
|
@@ -7264,7 +7265,7 @@ function recordPause(mission, pause) {
|
|
|
7264
7265
|
state.failureKind = pause.kind;
|
|
7265
7266
|
if (pause.nextRunAt)
|
|
7266
7267
|
state.nextRunAt = pause.nextRunAt;
|
|
7267
|
-
else
|
|
7268
|
+
else if (pause.kind !== "service-shutdown")
|
|
7268
7269
|
delete state.nextRunAt;
|
|
7269
7270
|
mission.status = pause.nextRunAt ? "waiting" : "paused";
|
|
7270
7271
|
mission.error = pause.message;
|
|
@@ -23964,7 +23965,7 @@ function canonicalConfig(config) {
|
|
|
23964
23965
|
import { spawn as spawn11 } from "node:child_process";
|
|
23965
23966
|
import { mkdtempSync, rmSync as rmSync2 } from "node:fs";
|
|
23966
23967
|
import { homedir as homedir8, tmpdir as tmpdir4 } from "node:os";
|
|
23967
|
-
import { delimiter as delimiter3, join as
|
|
23968
|
+
import { delimiter as delimiter3, join as join58 } from "node:path";
|
|
23968
23969
|
function runTerminalCommand(request, spawnCommand = spawn11) {
|
|
23969
23970
|
return new Promise((resolve) => {
|
|
23970
23971
|
let child;
|
|
@@ -24013,7 +24014,7 @@ function defaults2() {
|
|
|
24013
24014
|
discover: discoverAgents,
|
|
24014
24015
|
runCommand: runTerminalCommand,
|
|
24015
24016
|
supportsLoginCommand: (agent, path, env) => supportsNativeLoginCommand(agent, path, { env }),
|
|
24016
|
-
makeTempDir: () => mkdtempSync(
|
|
24017
|
+
makeTempDir: () => mkdtempSync(join58(tmpdir4(), "av-agent-install-")),
|
|
24017
24018
|
removeTempDir: (path) => rmSync2(path, { recursive: true, force: true })
|
|
24018
24019
|
};
|
|
24019
24020
|
}
|
|
@@ -24040,7 +24041,7 @@ async function runOfficialInstaller(installerUrl, deps, options = {}) {
|
|
|
24040
24041
|
let directory;
|
|
24041
24042
|
try {
|
|
24042
24043
|
directory = deps.makeTempDir();
|
|
24043
|
-
const scriptPath =
|
|
24044
|
+
const scriptPath = join58(directory, "install.sh");
|
|
24044
24045
|
const request = { env: options.env ?? deps.env, ...options.cwd ? { cwd: options.cwd } : {} };
|
|
24045
24046
|
const download = await deps.runCommand({
|
|
24046
24047
|
command: curl,
|
|
@@ -24111,7 +24112,7 @@ async function installChiefAgent(agent, overrides = {}) {
|
|
|
24111
24112
|
const install = await runOfficialInstaller(plan.installerUrl, deps);
|
|
24112
24113
|
if (!install.success)
|
|
24113
24114
|
return commandFailure(install.stage === "download" ? "Installer download" : "Installation", install, plan.documentation);
|
|
24114
|
-
const localBin =
|
|
24115
|
+
const localBin = join58(deps.home, ".local", "bin");
|
|
24115
24116
|
const pathParts = (deps.env.PATH ?? "").split(delimiter3);
|
|
24116
24117
|
if (!pathParts.includes(localBin))
|
|
24117
24118
|
deps.env.PATH = [localBin, ...pathParts.filter(Boolean)].join(delimiter3);
|
|
@@ -24214,16 +24215,16 @@ var init_agent_provisioning = __esm(() => {
|
|
|
24214
24215
|
import { mkdtempSync as mkdtempSync2, rmSync as rmSync3 } from "node:fs";
|
|
24215
24216
|
import { chmod as chmod5, lstat as lstat24, readdir as readdir17, readFile as readFile20, realpath as realpath33, unlink as unlink7, writeFile as writeFile13 } from "node:fs/promises";
|
|
24216
24217
|
import { homedir as homedir9, tmpdir as tmpdir5 } from "node:os";
|
|
24217
|
-
import { delimiter as delimiter4, isAbsolute as isAbsolute22, join as
|
|
24218
|
+
import { delimiter as delimiter4, isAbsolute as isAbsolute22, join as join59, relative as relative21, resolve as resolve40 } from "node:path";
|
|
24218
24219
|
function defaults3() {
|
|
24219
24220
|
const home = homedir9();
|
|
24220
24221
|
return {
|
|
24221
24222
|
platform: process.platform,
|
|
24222
24223
|
home,
|
|
24223
24224
|
env: process.env,
|
|
24224
|
-
resolveBinary: (name) => resolveBinaryPath(name, name === "bun" ? [
|
|
24225
|
+
resolveBinary: (name) => resolveBinaryPath(name, name === "bun" ? [join59(process.env.BUN_INSTALL ?? join59(home, ".bun"), "bin", "bun")] : []),
|
|
24225
24226
|
runCommand: runTerminalCommand,
|
|
24226
|
-
makeTempDir: () => mkdtempSync2(
|
|
24227
|
+
makeTempDir: () => mkdtempSync2(join59(tmpdir5(), "av-oma-install-")),
|
|
24227
24228
|
removeTempDir: (path) => rmSync3(path, { recursive: true, force: true })
|
|
24228
24229
|
};
|
|
24229
24230
|
}
|
|
@@ -24244,7 +24245,7 @@ async function present(path) {
|
|
|
24244
24245
|
}
|
|
24245
24246
|
async function installedVersion2(skills) {
|
|
24246
24247
|
try {
|
|
24247
|
-
const marker = JSON.parse(await readFile20(
|
|
24248
|
+
const marker = JSON.parse(await readFile20(join59(skills, "_version.json"), "utf8"));
|
|
24248
24249
|
return marker.schemaVersion === 2 && marker.mode === "project" && typeof marker.version === "string" && /^\d+\.\d+\.\d+(?:-[a-zA-Z0-9.-]+)?$/.test(marker.version) ? marker.version : null;
|
|
24249
24250
|
} catch {
|
|
24250
24251
|
return null;
|
|
@@ -24253,7 +24254,7 @@ async function installedVersion2(skills) {
|
|
|
24253
24254
|
async function snapshotConfig(agents) {
|
|
24254
24255
|
const snapshots = [];
|
|
24255
24256
|
for (const name of CUSTOM_CONFIG_NAMES) {
|
|
24256
|
-
const path =
|
|
24257
|
+
const path = join59(agents, name);
|
|
24257
24258
|
if (!await present(path))
|
|
24258
24259
|
continue;
|
|
24259
24260
|
const file = await lstat24(path);
|
|
@@ -24273,10 +24274,10 @@ async function restoreConfig(agents, snapshots) {
|
|
|
24273
24274
|
["oma-config.yaml", "oma-config.cue"],
|
|
24274
24275
|
["oma-config.local.yaml", "oma-config.local.cue"]
|
|
24275
24276
|
]) {
|
|
24276
|
-
if (!pair.some((name) => original.has(
|
|
24277
|
+
if (!pair.some((name) => original.has(join59(agents, name))))
|
|
24277
24278
|
continue;
|
|
24278
24279
|
for (const name of pair) {
|
|
24279
|
-
const path =
|
|
24280
|
+
const path = join59(agents, name);
|
|
24280
24281
|
if (!original.has(path))
|
|
24281
24282
|
await unlink7(path).catch((error) => {
|
|
24282
24283
|
if (error.code !== "ENOENT")
|
|
@@ -24291,7 +24292,7 @@ async function workspacePath(input) {
|
|
|
24291
24292
|
const root = resolve40(input);
|
|
24292
24293
|
if (!await directory2(root))
|
|
24293
24294
|
return null;
|
|
24294
|
-
for (const path of [
|
|
24295
|
+
for (const path of [join59(root, ".agents"), join59(root, ".agents", "skills")]) {
|
|
24295
24296
|
if (!await present(path))
|
|
24296
24297
|
continue;
|
|
24297
24298
|
const actual = await realpath33(path);
|
|
@@ -24306,7 +24307,7 @@ async function inspectOma(workspaceRoot, _overrides = {}) {
|
|
|
24306
24307
|
const root = await workspacePath(workspaceRoot);
|
|
24307
24308
|
if (!root)
|
|
24308
24309
|
return { success: false, message: "Choose an existing absolute workspace with project-local OMA files." };
|
|
24309
|
-
const skills =
|
|
24310
|
+
const skills = join59(root, ".agents", "skills");
|
|
24310
24311
|
const version = await installedVersion2(skills);
|
|
24311
24312
|
if (!version)
|
|
24312
24313
|
throw new Error("Invalid installed metadata");
|
|
@@ -24314,7 +24315,7 @@ async function inspectOma(workspaceRoot, _overrides = {}) {
|
|
|
24314
24315
|
if (!entries.length)
|
|
24315
24316
|
throw new Error("No installed skills");
|
|
24316
24317
|
for (const entry of entries) {
|
|
24317
|
-
if (!entry.isDirectory() || !(await lstat24(
|
|
24318
|
+
if (!entry.isDirectory() || !(await lstat24(join59(skills, entry.name, "SKILL.md"))).isFile())
|
|
24318
24319
|
throw new Error("Incomplete installed skill");
|
|
24319
24320
|
}
|
|
24320
24321
|
return {
|
|
@@ -24362,16 +24363,16 @@ async function prepareOma(workspaceRoot, overrides = {}) {
|
|
|
24362
24363
|
delete environment.OMA_YES;
|
|
24363
24364
|
environment.CI = "true";
|
|
24364
24365
|
const paths = [
|
|
24365
|
-
deps.env.BUN_INSTALL_BIN ??
|
|
24366
|
-
|
|
24366
|
+
deps.env.BUN_INSTALL_BIN ?? join59(deps.env.BUN_INSTALL ?? join59(deps.home, ".bun"), "bin"),
|
|
24367
|
+
join59(deps.home, ".local", "bin")
|
|
24367
24368
|
];
|
|
24368
24369
|
environment.PATH = [...new Set([...paths, ...(environment.PATH ?? "").split(delimiter4).filter(Boolean)])].join(delimiter4);
|
|
24369
24370
|
const request = { command: bun, env: environment, cwd: root, timeoutMs: 300000 };
|
|
24370
24371
|
const latest = await deps.runCommand({ ...request, args: ["install", "--global", LATEST_PACKAGE] });
|
|
24371
24372
|
if (!latest.success)
|
|
24372
24373
|
return failure3("OMA CLI update", latest);
|
|
24373
|
-
const agents =
|
|
24374
|
-
const existing = await installedVersion2(
|
|
24374
|
+
const agents = join59(root, ".agents");
|
|
24375
|
+
const existing = await installedVersion2(join59(agents, "skills")) !== null || await directory2(join59(agents, "skills")) && (await present(join59(agents, "oma-config.yaml")) || await present(join59(agents, "mcp.json")) || await directory2(join59(agents, "workflows")));
|
|
24375
24376
|
const custom = await snapshotConfig(agents);
|
|
24376
24377
|
const args = existing ? ["update", "--yes", "--with-new-skills", "--all"] : ["install"];
|
|
24377
24378
|
let installed;
|
|
@@ -25914,7 +25915,7 @@ var init_workspace_step = __esm(() => {
|
|
|
25914
25915
|
|
|
25915
25916
|
// src/setup/noninteractive-config.ts
|
|
25916
25917
|
import { lstat as lstat25, realpath as realpath34 } from "node:fs/promises";
|
|
25917
|
-
import { isAbsolute as isAbsolute24, join as
|
|
25918
|
+
import { isAbsolute as isAbsolute24, join as join60, parse as parsePath, resolve as resolve41 } from "node:path";
|
|
25918
25919
|
function validateNoninteractiveOptions(options) {
|
|
25919
25920
|
if (!options.yes || options.edit || options.mode !== undefined && options.mode !== "order")
|
|
25920
25921
|
throw new Error("Use av setup --yes only for local order setup; --edit and --mode tracker require interactive setup.");
|
|
@@ -25958,7 +25959,7 @@ function selectChief(options, deps, project, global2) {
|
|
|
25958
25959
|
const globalActor = actor(global2);
|
|
25959
25960
|
const selected = options.actor ?? runtime?.actorType ?? projectActor.type ?? globalActor.type;
|
|
25960
25961
|
if (!selected)
|
|
25961
|
-
throw new Error(`actor.type is missing in ${
|
|
25962
|
+
throw new Error(`actor.type is missing in ${join60(deps.projectRoot, "av.yaml")} and ${deps.globalConfigPath}, and the current agent runtime is unknown. Rerun av setup --yes --actor <current-vendor> --model <current-model-or-empty>.`);
|
|
25962
25963
|
const actorType = selected;
|
|
25963
25964
|
const actorSource = options.actor !== undefined ? "explicit" : runtime ? "runtime" : projectActor.type ? "project" : "global";
|
|
25964
25965
|
const previousType = projectActor.type ?? globalActor.type;
|
|
@@ -26003,7 +26004,7 @@ async function prepareNoninteractiveConfig(options, deps) {
|
|
|
26003
26004
|
throw new Error(`AV configuration directory ${deps.projectRoot} does not exist. Run av setup from an existing directory.`);
|
|
26004
26005
|
}
|
|
26005
26006
|
const globalPath = resolve41(deps.globalConfigPath);
|
|
26006
|
-
const projectPath =
|
|
26007
|
+
const projectPath = join60(projectRoot, "av.yaml");
|
|
26007
26008
|
const project = await configFile(projectPath, projectConfigSchema);
|
|
26008
26009
|
const global2 = await configFile(globalPath, globalConfigSchema);
|
|
26009
26010
|
const chief = selectChief(options, { ...deps, projectRoot, globalConfigPath: globalPath }, project.raw, global2.raw);
|
|
@@ -26056,7 +26057,7 @@ var init_noninteractive_config = __esm(() => {
|
|
|
26056
26057
|
});
|
|
26057
26058
|
|
|
26058
26059
|
// src/setup/noninteractive.ts
|
|
26059
|
-
import { join as
|
|
26060
|
+
import { join as join61, parse as parsePath2, resolve as resolve42 } from "node:path";
|
|
26060
26061
|
function rerunCommand(result, options) {
|
|
26061
26062
|
const quote = (value) => `'${value.replace(/'/g, "'\\''")}'`;
|
|
26062
26063
|
return `cd ${quote(result.projectRoot)} && av setup --yes --actor ${result.chief.actorType} --model ${quote(result.chief.model ?? "")} --workspace ${quote(result.workspace ?? result.projectRoot)} --oma ${options.oma ?? "prepare"} --json`;
|
|
@@ -26070,7 +26071,7 @@ async function setupNoninteractive(options, overrides = {}) {
|
|
|
26070
26071
|
projectRoot: resolve42(deps.projectRoot),
|
|
26071
26072
|
workspace: null,
|
|
26072
26073
|
config: {
|
|
26073
|
-
project:
|
|
26074
|
+
project: join61(resolve42(deps.projectRoot), "av.yaml"),
|
|
26074
26075
|
global: resolve42(deps.globalConfigPath),
|
|
26075
26076
|
saved: false
|
|
26076
26077
|
},
|
|
@@ -28523,9 +28524,9 @@ var init_setup = __esm(() => {
|
|
|
28523
28524
|
// ../../packages/core/src/relay/credentials.ts
|
|
28524
28525
|
import { readFileSync as readFileSync13 } from "node:fs";
|
|
28525
28526
|
import { homedir as homedir10 } from "node:os";
|
|
28526
|
-
import { join as
|
|
28527
|
+
import { join as join62 } from "node:path";
|
|
28527
28528
|
function defaultCredentialsPath() {
|
|
28528
|
-
return
|
|
28529
|
+
return join62(homedir10(), ".agent-valley", "credentials.json");
|
|
28529
28530
|
}
|
|
28530
28531
|
function validateRelayCredentials(value, binding, now = Date.now()) {
|
|
28531
28532
|
const result = credentialsSchema.safeParse(value);
|
|
@@ -70784,6 +70785,7 @@ function validateResumeOptions(goal, options) {
|
|
|
70784
70785
|
"resume",
|
|
70785
70786
|
"worker",
|
|
70786
70787
|
"supervise",
|
|
70788
|
+
"service",
|
|
70787
70789
|
"retry",
|
|
70788
70790
|
"runs",
|
|
70789
70791
|
"duration",
|
|
@@ -71068,7 +71070,7 @@ var operationSchema = strictObject({
|
|
|
71068
71070
|
charter: string2().trim().min(1).max(32000),
|
|
71069
71071
|
settings: record(string2().min(1).max(80), union([string2().max(32000), boolean2()])),
|
|
71070
71072
|
phase: _enum(["deciding", "running", "accepting", "waiting", "paused", "completed"]),
|
|
71071
|
-
pauseKind: _enum(["interrupted", "blocked"]).optional(),
|
|
71073
|
+
pauseKind: _enum(["interrupted", "blocked", "service-shutdown"]).optional(),
|
|
71072
71074
|
createdAt: timestampSchema,
|
|
71073
71075
|
updatedAt: timestampSchema,
|
|
71074
71076
|
completedCycles: number2().int().min(0),
|
|
@@ -71699,6 +71701,67 @@ async function collectContainerObservation(input, previous, dependencies = {}) {
|
|
|
71699
71701
|
// ../../packages/core/src/chief/continuous-operation.ts
|
|
71700
71702
|
import { createHash as createHash18, randomUUID as randomUUID12 } from "node:crypto";
|
|
71701
71703
|
init_execution();
|
|
71704
|
+
|
|
71705
|
+
// ../../packages/core/src/chief/service-shutdown.ts
|
|
71706
|
+
init_execution();
|
|
71707
|
+
function serviceShutdownPause() {
|
|
71708
|
+
return new MissionPause("The OS-owned service is shutting down. Re-observe the saved execution before continuing the same goal within its original limits.", "service-shutdown");
|
|
71709
|
+
}
|
|
71710
|
+
function isServiceShutdown(signal) {
|
|
71711
|
+
return signal?.reason instanceof MissionPause && signal.reason.kind === "service-shutdown";
|
|
71712
|
+
}
|
|
71713
|
+
function interruptionPause(signal, fallback) {
|
|
71714
|
+
return signal?.reason instanceof MissionPause ? signal.reason : new MissionPause(fallback, "interrupted");
|
|
71715
|
+
}
|
|
71716
|
+
function recordServiceShutdown(mission, unconfirmedTermination) {
|
|
71717
|
+
const pause = serviceShutdownPause();
|
|
71718
|
+
if (mission.history.at(-1)?.stage !== "service-shutdown")
|
|
71719
|
+
mission.history.push({ at: new Date().toISOString(), stage: "service-shutdown", message: pause.message });
|
|
71720
|
+
const protectedKinds = ["interrupted", "budget", "integrity", "unknown-effect", "chief-unavailable"];
|
|
71721
|
+
if (protectedKinds.includes(mission.execution?.failureKind ?? ""))
|
|
71722
|
+
return;
|
|
71723
|
+
if (mission.status === "paused" && mission.execution?.failureKind && mission.execution.failureKind !== "service-shutdown")
|
|
71724
|
+
return;
|
|
71725
|
+
if (mission.status === "failed" && mission.execution?.failureKind !== "service-shutdown")
|
|
71726
|
+
return;
|
|
71727
|
+
if (unconfirmedTermination) {
|
|
71728
|
+
recordPause(mission, new MissionPause(unconfirmedTermination.message, "unknown-effect"));
|
|
71729
|
+
return;
|
|
71730
|
+
}
|
|
71731
|
+
if (mission.status === "completed") {
|
|
71732
|
+
if (pendingCodeDelivery(mission)) {
|
|
71733
|
+
try {
|
|
71734
|
+
assertExecutionDeadline(mission);
|
|
71735
|
+
} catch (error) {
|
|
71736
|
+
if (!(error instanceof MissionPause))
|
|
71737
|
+
throw error;
|
|
71738
|
+
if (mission.codeDelivery) {
|
|
71739
|
+
mission.codeDelivery.phase = "blocked";
|
|
71740
|
+
mission.codeDelivery.error = error.message;
|
|
71741
|
+
delete mission.codeDelivery.nextRunAt;
|
|
71742
|
+
}
|
|
71743
|
+
}
|
|
71744
|
+
}
|
|
71745
|
+
} else {
|
|
71746
|
+
for (const run of mission.operations?.runs ?? []) {
|
|
71747
|
+
if (!run.finishedAt && run.executionState !== "settled")
|
|
71748
|
+
markOperatingRunUnknown(run, "Service shutdown interrupted this execution. Matching process-guard proof is required before recovery.");
|
|
71749
|
+
}
|
|
71750
|
+
let disposition = pause;
|
|
71751
|
+
try {
|
|
71752
|
+
assertExecutionBudget(mission);
|
|
71753
|
+
} catch (error) {
|
|
71754
|
+
if (!(error instanceof MissionPause))
|
|
71755
|
+
throw error;
|
|
71756
|
+
disposition = error;
|
|
71757
|
+
}
|
|
71758
|
+
recordPause(mission, disposition);
|
|
71759
|
+
if (disposition.kind === "service-shutdown" && mission.supervision)
|
|
71760
|
+
mission.supervision.pendingRecovery ??= { reason: pause.message };
|
|
71761
|
+
}
|
|
71762
|
+
}
|
|
71763
|
+
|
|
71764
|
+
// ../../packages/core/src/chief/continuous-operation.ts
|
|
71702
71765
|
function continuousDecisionKey(decision, observationFingerprint, observationRevision) {
|
|
71703
71766
|
return createHash18("sha256").update(JSON.stringify({ goal: decision.goal, evidence: decision.evidence, observationFingerprint, observationRevision })).digest("hex");
|
|
71704
71767
|
}
|
|
@@ -71713,8 +71776,9 @@ async function runContinuousOperation(operation, ports) {
|
|
|
71713
71776
|
if (operation.phase !== "paused" && operation.phase !== "completed")
|
|
71714
71777
|
operation.resumePhase = operation.phase;
|
|
71715
71778
|
operation.phase = "paused";
|
|
71716
|
-
|
|
71717
|
-
operation.
|
|
71779
|
+
const shutdown = isServiceShutdown(ports.signal);
|
|
71780
|
+
operation.pauseKind = shutdown ? "service-shutdown" : ports.signal?.aborted ? "interrupted" : "blocked";
|
|
71781
|
+
operation.error = (shutdown ? "The OS-owned service is shutting down. The operation retained its child, decision and recovery checkpoints for automatic resumption within their original limits." : message).slice(0, 16000);
|
|
71718
71782
|
await save();
|
|
71719
71783
|
return operation;
|
|
71720
71784
|
};
|
|
@@ -71741,12 +71805,22 @@ async function runContinuousOperation(operation, ports) {
|
|
|
71741
71805
|
if (mission)
|
|
71742
71806
|
assertExecutionDeadline(mission, Date.parse(now()));
|
|
71743
71807
|
const remaining = mission?.executionPolicy && mission.execution ? Date.parse(mission.execution.startedAt) + mission.executionPolicy.maxDurationSec * 1000 - Date.parse(now()) : Infinity;
|
|
71744
|
-
|
|
71808
|
+
try {
|
|
71809
|
+
await ports.delay(Math.min(Date.parse(nextRunAt) - Date.parse(now()), remaining, 30000), ports.signal);
|
|
71810
|
+
} catch (error) {
|
|
71811
|
+
if (mission)
|
|
71812
|
+
assertExecutionDeadline(mission, Date.parse(now()));
|
|
71813
|
+
if (error instanceof MissionPause && error.kind !== "interrupted" && error.kind !== "service-shutdown")
|
|
71814
|
+
throw error;
|
|
71815
|
+
if (ports.signal?.aborted)
|
|
71816
|
+
throw interruptionPause(ports.signal, "Operation recovery interrupted.");
|
|
71817
|
+
throw error;
|
|
71818
|
+
}
|
|
71745
71819
|
}
|
|
71746
71820
|
if (mission)
|
|
71747
71821
|
assertExecutionDeadline(mission, Date.parse(now()));
|
|
71748
71822
|
if (ports.signal?.aborted)
|
|
71749
|
-
throw
|
|
71823
|
+
throw interruptionPause(ports.signal, "Operation recovery interrupted.");
|
|
71750
71824
|
};
|
|
71751
71825
|
const recoverChild = async (mission, context) => {
|
|
71752
71826
|
const disposition = automaticMissionRecovery(mission, Date.parse(now()), context);
|
|
@@ -71777,6 +71851,7 @@ async function runContinuousOperation(operation, ports) {
|
|
|
71777
71851
|
}
|
|
71778
71852
|
await save();
|
|
71779
71853
|
await waitForRecovery(disposition.waitUntil, mission);
|
|
71854
|
+
const pendingRecovery = structuredClone(operation.recovery);
|
|
71780
71855
|
operation.recovery.attempts += 1;
|
|
71781
71856
|
if (!continuation)
|
|
71782
71857
|
operation.recovery.failedAttempts = failedAttempts + 1;
|
|
@@ -71785,11 +71860,22 @@ async function runContinuousOperation(operation, ports) {
|
|
|
71785
71860
|
await save();
|
|
71786
71861
|
if (!operation.baseline)
|
|
71787
71862
|
throw new Error("The original accepted baseline is missing from the recovery checkpoint.");
|
|
71788
|
-
|
|
71863
|
+
try {
|
|
71864
|
+
const resumed = await ports.runMission(operation, mission.id, mission.goal, operation.baseline.path);
|
|
71865
|
+
if (isServiceShutdown(ports.signal) && resumed.execution?.failureKind === "service-shutdown") {
|
|
71866
|
+
operation.recovery = pendingRecovery;
|
|
71867
|
+
throw interruptionPause(ports.signal, "Operation child recovery interrupted.");
|
|
71868
|
+
}
|
|
71869
|
+
} catch (error) {
|
|
71870
|
+
if (error instanceof MissionPause && error.kind === "service-shutdown")
|
|
71871
|
+
operation.recovery = pendingRecovery;
|
|
71872
|
+
throw error;
|
|
71873
|
+
}
|
|
71789
71874
|
return true;
|
|
71790
71875
|
};
|
|
71791
71876
|
const selectDecision = async (id) => {
|
|
71792
71877
|
while (true) {
|
|
71878
|
+
const previous = operation.recovery?.target === "decision" && operation.recovery.checkpointId === id ? structuredClone(operation.recovery) : undefined;
|
|
71793
71879
|
const prior = operation.recovery?.target === "decision" && operation.recovery.checkpointId === id ? operation.recovery.attempts : 0;
|
|
71794
71880
|
if (prior >= automaticRecoveryLimit)
|
|
71795
71881
|
throw new Error("Bounded automatic goal-selection recovery exhausted its attempts; the saved decision remains unresolved.");
|
|
@@ -71805,6 +71891,16 @@ async function runContinuousOperation(operation, ports) {
|
|
|
71805
71891
|
try {
|
|
71806
71892
|
return continuousDecisionSchema.parse(await ports.decide(operation, id));
|
|
71807
71893
|
} catch (error) {
|
|
71894
|
+
if (error instanceof MissionPause && error.kind === "service-shutdown") {
|
|
71895
|
+
operation.recovery = previous ?? {
|
|
71896
|
+
target: "decision",
|
|
71897
|
+
checkpointId: id,
|
|
71898
|
+
attempts: prior,
|
|
71899
|
+
disposition: "waiting",
|
|
71900
|
+
reason: error.message.slice(0, 16000)
|
|
71901
|
+
};
|
|
71902
|
+
throw error;
|
|
71903
|
+
}
|
|
71808
71904
|
const reason = error instanceof Error ? error.message : String(error);
|
|
71809
71905
|
const kind = error instanceof MissionPause ? error.kind : classifyFailure(reason);
|
|
71810
71906
|
const invalid = error instanceof Error && (error.name === "ZodError" || reason.startsWith("Invalid Chief decision"));
|
|
@@ -71997,7 +72093,7 @@ async function runContinuousOperation(operation, ports) {
|
|
|
71997
72093
|
await save();
|
|
71998
72094
|
}
|
|
71999
72095
|
} catch (error) {
|
|
72000
|
-
if (operation.recovery && error instanceof MissionPause) {
|
|
72096
|
+
if (operation.recovery && error instanceof MissionPause && error.kind !== "service-shutdown") {
|
|
72001
72097
|
operation.recovery.disposition = "protected";
|
|
72002
72098
|
operation.recovery.reason = error.message.slice(0, 16000);
|
|
72003
72099
|
}
|
|
@@ -75165,7 +75261,7 @@ function abortableDelay(ms, signal) {
|
|
|
75165
75261
|
const abort = () => {
|
|
75166
75262
|
clearTimeout(timer);
|
|
75167
75263
|
signal?.removeEventListener("abort", abort);
|
|
75168
|
-
reject(new Error("Order supervision interrupted."));
|
|
75264
|
+
reject(signal?.reason instanceof MissionPause ? signal.reason : new Error("Order supervision interrupted."));
|
|
75169
75265
|
};
|
|
75170
75266
|
const timer = setTimeout(() => {
|
|
75171
75267
|
signal?.removeEventListener("abort", abort);
|
|
@@ -75181,17 +75277,23 @@ async function superviseOrder(goal, options, root, dependencies = {}) {
|
|
|
75181
75277
|
const id = options.resume ?? options.missionId ?? randomUUID15();
|
|
75182
75278
|
const store = new MissionStore(join36(root, ".agent-valley/missions"));
|
|
75183
75279
|
const controller = new AbortController;
|
|
75184
|
-
const interrupt = () => controller.abort();
|
|
75280
|
+
const interrupt = () => controller.abort(dependencies.signal?.reason);
|
|
75281
|
+
const terminate = () => controller.abort(options.service ? serviceShutdownPause() : undefined);
|
|
75185
75282
|
dependencies.signal?.addEventListener("abort", interrupt, { once: true });
|
|
75186
75283
|
if (dependencies.signal?.aborted)
|
|
75187
75284
|
interrupt();
|
|
75188
75285
|
if (!dependencies.signal) {
|
|
75189
75286
|
process.once("SIGINT", interrupt);
|
|
75190
|
-
process.once("SIGTERM",
|
|
75287
|
+
process.once("SIGTERM", terminate);
|
|
75191
75288
|
}
|
|
75192
75289
|
const runWorker = createDeadlineWorkerRunner(store, id, controller.signal);
|
|
75193
|
-
|
|
75290
|
+
const workerArgs = (goal, current) => orderWorkerArgs(goal, {
|
|
75291
|
+
...current,
|
|
75292
|
+
...options.service ? { service: true } : {}
|
|
75293
|
+
}, id);
|
|
75294
|
+
let args = workerArgs(goal, options);
|
|
75194
75295
|
let returned;
|
|
75296
|
+
let terminationFailure;
|
|
75195
75297
|
const waitForOwner = async () => {
|
|
75196
75298
|
let observed = false;
|
|
75197
75299
|
while (await store.isLocked(id)) {
|
|
@@ -75214,7 +75316,7 @@ async function superviseOrder(goal, options, root, dependencies = {}) {
|
|
|
75214
75316
|
returned = current;
|
|
75215
75317
|
if (controller.signal.aborted || current.status === "completed" && !pendingCodeDelivery(current) || ["paused", "failed"].includes(current.status) && !automaticMissionRecovery(current).retry)
|
|
75216
75318
|
return current;
|
|
75217
|
-
args =
|
|
75319
|
+
args = workerArgs(undefined, { resume: id });
|
|
75218
75320
|
}
|
|
75219
75321
|
if (controller.signal.aborted)
|
|
75220
75322
|
break;
|
|
@@ -75263,7 +75365,7 @@ async function superviseOrder(goal, options, root, dependencies = {}) {
|
|
|
75263
75365
|
await (dependencies.delay ?? abortableDelay)(Math.min(Date.parse(mission.codeDelivery.nextRunAt) - Date.now(), 30000), controller.signal);
|
|
75264
75366
|
}
|
|
75265
75367
|
assertExecutionDeadline(mission);
|
|
75266
|
-
args =
|
|
75368
|
+
args = workerArgs(undefined, { resume: id });
|
|
75267
75369
|
continue;
|
|
75268
75370
|
}
|
|
75269
75371
|
const recovery = automaticMissionRecovery(mission);
|
|
@@ -75302,13 +75404,15 @@ async function superviseOrder(goal, options, root, dependencies = {}) {
|
|
|
75302
75404
|
await (dependencies.delay ?? abortableDelay)(Math.min(1000, remainingTime()), controller.signal);
|
|
75303
75405
|
}
|
|
75304
75406
|
assertExecutionDeadline(mission);
|
|
75305
|
-
args =
|
|
75407
|
+
args = workerArgs(undefined, { resume: id });
|
|
75306
75408
|
}
|
|
75307
75409
|
returned = await store.load(id);
|
|
75308
75410
|
return returned;
|
|
75309
75411
|
} catch (error) {
|
|
75310
|
-
if (error instanceof WorkerTerminationError)
|
|
75412
|
+
if (error instanceof WorkerTerminationError) {
|
|
75413
|
+
terminationFailure = error;
|
|
75311
75414
|
throw error;
|
|
75415
|
+
}
|
|
75312
75416
|
if (await store.isLocked(id)) {
|
|
75313
75417
|
if (!controller.signal.aborted)
|
|
75314
75418
|
await waitForOwner();
|
|
@@ -75371,7 +75475,18 @@ async function superviseOrder(goal, options, root, dependencies = {}) {
|
|
|
75371
75475
|
const existing = await store.load(id).catch(() => {
|
|
75372
75476
|
return;
|
|
75373
75477
|
});
|
|
75374
|
-
if (existing
|
|
75478
|
+
if (existing && isServiceShutdown(controller.signal)) {
|
|
75479
|
+
const unlock = await store.lock(id);
|
|
75480
|
+
try {
|
|
75481
|
+
const latest = await store.load(id);
|
|
75482
|
+
recordServiceShutdown(latest, terminationFailure);
|
|
75483
|
+
await store.save(latest);
|
|
75484
|
+
if (returned)
|
|
75485
|
+
Object.assign(returned, latest);
|
|
75486
|
+
} finally {
|
|
75487
|
+
await unlock();
|
|
75488
|
+
}
|
|
75489
|
+
} else if (existing?.status === "completed" && existing.codeDelivery && pendingCodeDelivery(existing)) {
|
|
75375
75490
|
const unlock = await store.lock(id);
|
|
75376
75491
|
try {
|
|
75377
75492
|
const latest = await store.load(id);
|
|
@@ -75409,7 +75524,7 @@ async function superviseOrder(goal, options, root, dependencies = {}) {
|
|
|
75409
75524
|
dependencies.signal?.removeEventListener("abort", interrupt);
|
|
75410
75525
|
if (!dependencies.signal) {
|
|
75411
75526
|
process.removeListener("SIGINT", interrupt);
|
|
75412
|
-
process.removeListener("SIGTERM",
|
|
75527
|
+
process.removeListener("SIGTERM", terminate);
|
|
75413
75528
|
}
|
|
75414
75529
|
}
|
|
75415
75530
|
}
|
|
@@ -75417,13 +75532,13 @@ async function superviseOrder(goal, options, root, dependencies = {}) {
|
|
|
75417
75532
|
// src/chief-continuous-recovery.ts
|
|
75418
75533
|
function assertContinuousDecisionRecovery(mission) {
|
|
75419
75534
|
const state = executionState(mission);
|
|
75420
|
-
if (mission.status === "paused" && state.failureKind !== "implementation" && state.failureKind !== "provider" && state.failureKind !== "rate-limit")
|
|
75535
|
+
if (mission.status === "paused" && state.failureKind !== "implementation" && state.failureKind !== "provider" && state.failureKind !== "rate-limit" && state.failureKind !== "service-shutdown")
|
|
75421
75536
|
throw new MissionPause(mission.error ?? state.pauseReason ?? "The saved decision remains unresolved.", state.failureKind ?? "implementation");
|
|
75422
75537
|
}
|
|
75423
75538
|
async function runContinuousDecision(mission, prompt, run, store, signal, delay = abortableDelay) {
|
|
75424
75539
|
assertContinuousDecisionRecovery(mission);
|
|
75425
75540
|
const state = executionState(mission);
|
|
75426
|
-
if (mission.status === "paused" && state.retries >= (mission.executionPolicy?.maxRetries ?? 0))
|
|
75541
|
+
if (mission.status === "paused" && state.failureKind !== "service-shutdown" && state.retries >= (mission.executionPolicy?.maxRetries ?? 0))
|
|
75427
75542
|
throw new MissionPause(mission.error ?? "Bounded Chief decision recovery exhausted its attempts.", state.failureKind ?? "implementation");
|
|
75428
75543
|
let correction = mission.history.findLast((entry) => entry.stage === "continuous-decision-invalid")?.message;
|
|
75429
75544
|
while (true) {
|
|
@@ -75433,7 +75548,7 @@ async function runContinuousDecision(mission, prompt, run, store, signal, delay
|
|
|
75433
75548
|
await delay(Math.min(Date.parse(state.nextRunAt) - Date.now(), remaining, 30000), signal);
|
|
75434
75549
|
}
|
|
75435
75550
|
if (signal?.aborted)
|
|
75436
|
-
throw
|
|
75551
|
+
throw interruptionPause(signal, "Operation decision interrupted.");
|
|
75437
75552
|
mission.status = "planning";
|
|
75438
75553
|
delete mission.error;
|
|
75439
75554
|
delete state.pauseReason;
|
|
@@ -76314,8 +76429,12 @@ async function decideContinuousGoal(operation, decisionId, root, dependencies =
|
|
|
76314
76429
|
return parseContinuousDecision(result.message);
|
|
76315
76430
|
}
|
|
76316
76431
|
if (mission) {
|
|
76432
|
+
const serviceRuns = mission.history.at(-1)?.stage === "service-shutdown" && mission.execution?.failureKind === "unknown-effect" ? mission.operations?.runs.filter((run) => run.executionState === "unknown") ?? [] : [];
|
|
76317
76433
|
await store.recoverProcesses(decisionId, mission);
|
|
76318
76434
|
finalizeAbandonedRuns(mission);
|
|
76435
|
+
if (serviceRuns.length && serviceRuns.every((run) => run.executionRecovery === "local-process" && run.executionState === "settled") && !mission.tasks.some((task) => task.effectState === "unknown") && mission.execution) {
|
|
76436
|
+
mission.execution.failureKind = "service-shutdown";
|
|
76437
|
+
}
|
|
76319
76438
|
assertContinuousDecisionRecovery(mission);
|
|
76320
76439
|
await store.save(mission);
|
|
76321
76440
|
} else {
|
|
@@ -76383,7 +76502,7 @@ async function decideContinuousGoal(operation, decisionId, root, dependencies =
|
|
|
76383
76502
|
throw new MissionPause("Decision stage changed its saved charter, workspace, Chief Director or pinned evidence.", "integrity");
|
|
76384
76503
|
}, () => {
|
|
76385
76504
|
if (dependencies.signal?.aborted)
|
|
76386
|
-
throw
|
|
76505
|
+
throw interruptionPause(dependencies.signal, "Operation decision interrupted.");
|
|
76387
76506
|
});
|
|
76388
76507
|
await consultContinuousDirectors(mission, ports, run);
|
|
76389
76508
|
const tools = await (dependencies.tools ?? discoverTools)(operation.repositoryRoot);
|
|
@@ -76413,7 +76532,14 @@ async function decideContinuousGoal(operation, decisionId, root, dependencies =
|
|
|
76413
76532
|
throw error;
|
|
76414
76533
|
} finally {
|
|
76415
76534
|
try {
|
|
76416
|
-
|
|
76535
|
+
try {
|
|
76536
|
+
await runtime.close();
|
|
76537
|
+
} finally {
|
|
76538
|
+
if (mission && isServiceShutdown(dependencies.signal)) {
|
|
76539
|
+
recordServiceShutdown(mission);
|
|
76540
|
+
await store.save(mission);
|
|
76541
|
+
}
|
|
76542
|
+
}
|
|
76417
76543
|
} finally {
|
|
76418
76544
|
await unlock();
|
|
76419
76545
|
}
|
|
@@ -76585,13 +76711,14 @@ async function runOperation(charter, options, root = process.cwd(), dependencies
|
|
|
76585
76711
|
const storage = operationStore(root);
|
|
76586
76712
|
const unlock = await storage.lock(id);
|
|
76587
76713
|
const controller = new AbortController;
|
|
76588
|
-
const stop = () => controller.abort();
|
|
76714
|
+
const stop = () => controller.abort(dependencies.signal?.reason);
|
|
76715
|
+
const terminate = () => controller.abort(options.service ? serviceShutdownPause() : undefined);
|
|
76589
76716
|
dependencies.signal?.addEventListener("abort", stop, { once: true });
|
|
76590
76717
|
if (dependencies.signal?.aborted)
|
|
76591
76718
|
stop();
|
|
76592
76719
|
if (!dependencies.signal) {
|
|
76593
76720
|
process.once("SIGINT", stop);
|
|
76594
|
-
process.once("SIGTERM",
|
|
76721
|
+
process.once("SIGTERM", terminate);
|
|
76595
76722
|
}
|
|
76596
76723
|
try {
|
|
76597
76724
|
let operation;
|
|
@@ -76677,12 +76804,13 @@ Resume: av order --resume ${id}`);
|
|
|
76677
76804
|
return;
|
|
76678
76805
|
throw error;
|
|
76679
76806
|
});
|
|
76680
|
-
return superviseOrder(saved ? undefined : goal, saved ? { resume: missionId, once: true } : {
|
|
76807
|
+
return superviseOrder(saved ? undefined : goal, saved ? { resume: missionId, once: true, ...options.service ? { service: true } : {} } : {
|
|
76681
76808
|
...current.settings,
|
|
76682
76809
|
once: true,
|
|
76683
76810
|
missionId,
|
|
76684
76811
|
baselineWorkspace: baselinePath,
|
|
76685
|
-
operationId: current.id
|
|
76812
|
+
operationId: current.id,
|
|
76813
|
+
...options.service ? { service: true } : {}
|
|
76686
76814
|
}, root, { signal: controller.signal });
|
|
76687
76815
|
}),
|
|
76688
76816
|
accept: async (current, mission) => {
|
|
@@ -76698,13 +76826,13 @@ Resume: av order --resume ${id}`);
|
|
|
76698
76826
|
dependencies.signal?.removeEventListener("abort", stop);
|
|
76699
76827
|
if (!dependencies.signal) {
|
|
76700
76828
|
process.removeListener("SIGINT", stop);
|
|
76701
|
-
process.removeListener("SIGTERM",
|
|
76829
|
+
process.removeListener("SIGTERM", terminate);
|
|
76702
76830
|
}
|
|
76703
76831
|
await unlock();
|
|
76704
76832
|
}
|
|
76705
76833
|
}
|
|
76706
76834
|
function registerContinuousCommands(program) {
|
|
76707
|
-
program.command("operate [charter]", { hidden: true }).description("Deprecated alias for av order; resume existing operating charters").option("--workspace <path>", "Target Git repository (defaults to av.yaml)").option("--verify <command>", "Trusted completion check for each improvement").option("--actor <type>", "Pinned Chief Director CLI").option("--model <id>", "Pinned Chief Director model").option("--director <id>", "Chief Director Actor ID").option("--actors <file>", "Configured YAML Actor roster").option("--oma", "Require OMA completion receipts for workers").option("--timeout <seconds>", "Timeout per Actor/check").option("--repairs <count>", "Repair limit per task/final review").option("--rounds <count>", "Recovery decision limit per improvement").option("--parallel <count>", "Actor concurrency per improvement").option("--runs <count>", "Initial Actor call limit; on resume, increase the active decision checkpoint limit").option("--duration <seconds>", "Initial wall-time limit; on resume, increase the active decision checkpoint limit").option("--cost <usd>", "Initial estimated cost limit; on resume, increase the active decision checkpoint limit").option("--account-run <run-id>", "On resume, reconcile an active decision run whose usage/cost was lost").option("--account-cost <usd>", "Observed USD cost for the decision --account-run after inspecting billing").option("--cycles <count>", "Cumulative verified improvement limit; default continues until stopped").option("--interval <seconds>", "Wait before selecting again when no new goal is justified (default 300)").option("--resume <id>", "Resume the saved charter and accepted work").addOption(new Option("--operation-id <id>", "Internal operation identity").hideHelp()).action(async (charter, options) => {
|
|
76835
|
+
program.command("operate [charter]", { hidden: true }).description("Deprecated alias for av order; resume existing operating charters").option("--workspace <path>", "Target Git repository (defaults to av.yaml)").option("--verify <command>", "Trusted completion check for each improvement").option("--actor <type>", "Pinned Chief Director CLI").option("--model <id>", "Pinned Chief Director model").option("--director <id>", "Chief Director Actor ID").option("--actors <file>", "Configured YAML Actor roster").option("--oma", "Require OMA completion receipts for workers").option("--service", "Resume after OS service SIGTERM within saved limits; SIGINT still cancels").option("--timeout <seconds>", "Timeout per Actor/check").option("--repairs <count>", "Repair limit per task/final review").option("--rounds <count>", "Recovery decision limit per improvement").option("--parallel <count>", "Actor concurrency per improvement").option("--runs <count>", "Initial Actor call limit; on resume, increase the active decision checkpoint limit").option("--duration <seconds>", "Initial wall-time limit; on resume, increase the active decision checkpoint limit").option("--cost <usd>", "Initial estimated cost limit; on resume, increase the active decision checkpoint limit").option("--account-run <run-id>", "On resume, reconcile an active decision run whose usage/cost was lost").option("--account-cost <usd>", "Observed USD cost for the decision --account-run after inspecting billing").option("--cycles <count>", "Cumulative verified improvement limit; default continues until stopped").option("--interval <seconds>", "Wait before selecting again when no new goal is justified (default 300)").option("--resume <id>", "Resume the saved charter and accepted work").addOption(new Option("--operation-id <id>", "Internal operation identity").hideHelp()).action(async (charter, options) => {
|
|
76708
76836
|
const operation = await runOperation(charter, options);
|
|
76709
76837
|
console.log(`Operation ${operation.id}: ${operation.phase}; ${operation.completedCycles} verified improvements.`);
|
|
76710
76838
|
if (operation.error)
|
|
@@ -76831,7 +76959,7 @@ class OperationApi {
|
|
|
76831
76959
|
if (checked === "unknown")
|
|
76832
76960
|
throw new Error("Operation process identity changed. No signal was sent.");
|
|
76833
76961
|
if (checked === "running")
|
|
76834
|
-
(this.dependencies.signal ?? ((pid) => process.kill(pid, "
|
|
76962
|
+
(this.dependencies.signal ?? ((pid) => process.kill(pid, "SIGINT")))(job.pid);
|
|
76835
76963
|
}
|
|
76836
76964
|
return { ...await this.status(id), cancelRequested: current === "running" };
|
|
76837
76965
|
});
|
|
@@ -77122,7 +77250,7 @@ class MissionApi {
|
|
|
77122
77250
|
throw new Error("Supervisor identity changed during cancellation. Inspect the original process; no signal was sent.");
|
|
77123
77251
|
if (current === "stopped")
|
|
77124
77252
|
return { ...await this.status(id), cancelRequested: false };
|
|
77125
|
-
(this.dependencies.signal ?? ((pid) => process.kill(pid, "
|
|
77253
|
+
(this.dependencies.signal ?? ((pid) => process.kill(pid, "SIGINT")))(job.pid);
|
|
77126
77254
|
}
|
|
77127
77255
|
return { ...await this.status(id), cancelRequested: liveness === "running" };
|
|
77128
77256
|
});
|
|
@@ -77596,7 +77724,7 @@ function registerAgentClientCommands(program) {
|
|
|
77596
77724
|
// src/chief.ts
|
|
77597
77725
|
import { randomUUID as randomUUID22 } from "node:crypto";
|
|
77598
77726
|
import { realpath as realpath31 } from "node:fs/promises";
|
|
77599
|
-
import { join as
|
|
77727
|
+
import { join as join52 } from "node:path";
|
|
77600
77728
|
|
|
77601
77729
|
// ../../node_modules/.bun/@langchain+core@1.2.20+ea9f70ecde856c26/node_modules/@langchain/core/dist/_virtual/_rolldown/runtime.js
|
|
77602
77730
|
var __defProp4 = Object.defineProperty;
|
|
@@ -129792,6 +129920,10 @@ async function privateDirectory(root, id) {
|
|
|
129792
129920
|
return current;
|
|
129793
129921
|
}
|
|
129794
129922
|
function assertLive(mission, signal) {
|
|
129923
|
+
if (isServiceShutdown(signal)) {
|
|
129924
|
+
assertExecutionDeadline(mission);
|
|
129925
|
+
throw interruptionPause(signal, "Code delivery service is shutting down.");
|
|
129926
|
+
}
|
|
129795
129927
|
if (signal?.aborted)
|
|
129796
129928
|
throw new DeliveryBlocked("Code delivery was explicitly interrupted. Preserve its checkpoint and inspect the target before resuming.");
|
|
129797
129929
|
assertExecutionDeadline(mission);
|
|
@@ -130004,9 +130136,14 @@ AV-Delivery: ${delivery.nonce}
|
|
|
130004
130136
|
delete delivery.error;
|
|
130005
130137
|
await save();
|
|
130006
130138
|
} catch (error) {
|
|
130139
|
+
const deadline = mission.execution && mission.executionPolicy && Date.now() >= Date.parse(mission.execution.startedAt) + mission.executionPolicy.maxDurationSec * 1000;
|
|
130140
|
+
if (error instanceof MissionPause && error.kind === "service-shutdown" && !deadline) {
|
|
130141
|
+
delivery.error = error.message;
|
|
130142
|
+
await save();
|
|
130143
|
+
return;
|
|
130144
|
+
}
|
|
130007
130145
|
if (delivery.attempts === previousAttempts)
|
|
130008
130146
|
delivery.attempts = Math.min(3, previousAttempts + 1);
|
|
130009
|
-
const deadline = mission.execution && mission.executionPolicy && Date.now() >= Date.parse(mission.execution.startedAt) + mission.executionPolicy.maxDurationSec * 1000;
|
|
130010
130147
|
const blocked = error instanceof DeliveryBlocked || error instanceof MissionPause || signal?.aborted || deadline;
|
|
130011
130148
|
if (blocked || delivery.attempts >= 3)
|
|
130012
130149
|
delivery.phase = "blocked";
|
|
@@ -130030,6 +130167,9 @@ function createMissionContainerPorts(dependencies = {}) {
|
|
|
130030
130167
|
};
|
|
130031
130168
|
}
|
|
130032
130169
|
|
|
130170
|
+
// src/chief-missions.ts
|
|
130171
|
+
import { join as join50 } from "node:path";
|
|
130172
|
+
|
|
130033
130173
|
// src/chief-reconcile.ts
|
|
130034
130174
|
init_execution();
|
|
130035
130175
|
import { join as join48 } from "node:path";
|
|
@@ -130072,13 +130212,14 @@ import { join as join49 } from "node:path";
|
|
|
130072
130212
|
async function watchOrders(root = process.cwd(), dependencies = {}) {
|
|
130073
130213
|
assertNotManagedRun();
|
|
130074
130214
|
const controller = new AbortController;
|
|
130075
|
-
const stop = () => controller.abort();
|
|
130215
|
+
const stop = () => controller.abort(dependencies.signal?.reason);
|
|
130216
|
+
const terminate = () => controller.abort(dependencies.service ? serviceShutdownPause() : undefined);
|
|
130076
130217
|
dependencies.signal?.addEventListener("abort", stop, { once: true });
|
|
130077
130218
|
if (dependencies.signal?.aborted)
|
|
130078
130219
|
stop();
|
|
130079
130220
|
if (!dependencies.signal) {
|
|
130080
130221
|
process.once("SIGINT", stop);
|
|
130081
|
-
process.once("SIGTERM",
|
|
130222
|
+
process.once("SIGTERM", terminate);
|
|
130082
130223
|
}
|
|
130083
130224
|
const missions = new MissionStore(join49(root, ".agent-valley", "missions"));
|
|
130084
130225
|
try {
|
|
@@ -130097,7 +130238,7 @@ async function watchOrders(root = process.cwd(), dependencies = {}) {
|
|
|
130097
130238
|
if (mission.status === "completed") {
|
|
130098
130239
|
if (!pendingCodeDelivery(mission) || mission.codeDelivery?.nextRunAt && Date.parse(mission.codeDelivery.nextRunAt) > Date.now())
|
|
130099
130240
|
continue;
|
|
130100
|
-
await (dependencies.mission ?? superviseOrder)(undefined, { resume: mission.id }, root, {
|
|
130241
|
+
await (dependencies.mission ?? superviseOrder)(undefined, { resume: mission.id, ...dependencies.service ? { service: true } : {} }, root, {
|
|
130101
130242
|
signal: controller.signal
|
|
130102
130243
|
}).then(printOrderOutcome);
|
|
130103
130244
|
continue;
|
|
@@ -130105,7 +130246,7 @@ async function watchOrders(root = process.cwd(), dependencies = {}) {
|
|
|
130105
130246
|
const recovery = automaticMissionRecovery(mission);
|
|
130106
130247
|
if (!recovery.retry || recovery.waitUntil && Date.parse(recovery.waitUntil) > Date.now())
|
|
130107
130248
|
continue;
|
|
130108
|
-
await (dependencies.mission ?? superviseOrder)(undefined, { resume: mission.id }, root, {
|
|
130249
|
+
await (dependencies.mission ?? superviseOrder)(undefined, { resume: mission.id, ...dependencies.service ? { service: true } : {} }, root, {
|
|
130109
130250
|
signal: controller.signal
|
|
130110
130251
|
}).then(printOrderOutcome);
|
|
130111
130252
|
} catch (error) {
|
|
@@ -130120,21 +130261,23 @@ async function watchOrders(root = process.cwd(), dependencies = {}) {
|
|
|
130120
130261
|
if (operation.currentMissionId && await missions.isLocked(operation.currentMissionId))
|
|
130121
130262
|
continue;
|
|
130122
130263
|
if (operation.phase === "paused") {
|
|
130123
|
-
if (operation.pauseKind !== "blocked" || !operation.currentMissionId)
|
|
130264
|
+
if (operation.pauseKind !== "service-shutdown" && (operation.pauseKind !== "blocked" || !operation.currentMissionId))
|
|
130124
130265
|
continue;
|
|
130125
|
-
|
|
130126
|
-
|
|
130127
|
-
|
|
130128
|
-
|
|
130129
|
-
|
|
130266
|
+
if (operation.currentMissionId) {
|
|
130267
|
+
try {
|
|
130268
|
+
const child = await reobserveLocalExecutions(await missions.load(operation.currentMissionId), missions);
|
|
130269
|
+
if (child.codeDelivery?.phase === "blocked")
|
|
130270
|
+
continue;
|
|
130271
|
+
if (!automaticMissionRecovery(child).retry && !(child.status === "completed" && verifiedMissionEvidence(child)))
|
|
130272
|
+
continue;
|
|
130273
|
+
} catch (error) {
|
|
130274
|
+
console.error(String(error));
|
|
130130
130275
|
continue;
|
|
130131
|
-
|
|
130132
|
-
console.error(String(error));
|
|
130133
|
-
continue;
|
|
130276
|
+
}
|
|
130134
130277
|
}
|
|
130135
130278
|
}
|
|
130136
130279
|
try {
|
|
130137
|
-
await (dependencies.operation ?? runOperation)(undefined, { resume: operation.id }, root, {
|
|
130280
|
+
await (dependencies.operation ?? runOperation)(undefined, { resume: operation.id, ...dependencies.service ? { service: true } : {} }, root, {
|
|
130138
130281
|
signal: controller.signal
|
|
130139
130282
|
});
|
|
130140
130283
|
} catch (error) {
|
|
@@ -130150,14 +130293,52 @@ async function watchOrders(root = process.cwd(), dependencies = {}) {
|
|
|
130150
130293
|
dependencies.signal?.removeEventListener("abort", stop);
|
|
130151
130294
|
if (!dependencies.signal) {
|
|
130152
130295
|
process.removeListener("SIGINT", stop);
|
|
130153
|
-
process.removeListener("SIGTERM",
|
|
130296
|
+
process.removeListener("SIGTERM", terminate);
|
|
130154
130297
|
}
|
|
130155
130298
|
}
|
|
130156
130299
|
}
|
|
130157
130300
|
|
|
130301
|
+
// src/chief-missions.ts
|
|
130302
|
+
function registerMissionCommands(program) {
|
|
130303
|
+
const missions = program.command("missions").description("List saved Chief Director orders and their workspaces").option("--json", "Print a JSON snapshot of saved order status").option("--watch", "Resume due or interrupted orders from their saved checkpoints").option("--service", "Treat watcher SIGTERM as recoverable service shutdown; requires --watch").action(async (options) => {
|
|
130304
|
+
if (options.json && options.watch)
|
|
130305
|
+
throw new Error("Use av missions --json for a snapshot, or av missions --watch to resume eligible orders; choose one.");
|
|
130306
|
+
if (options.service && !options.watch)
|
|
130307
|
+
throw new Error("Use --service with av missions --watch.");
|
|
130308
|
+
if (options.watch) {
|
|
130309
|
+
await watchOrders(process.cwd(), { service: options.service });
|
|
130310
|
+
return;
|
|
130311
|
+
}
|
|
130312
|
+
const missions = await new MissionStore(join50(process.cwd(), ".agent-valley/missions")).list();
|
|
130313
|
+
if (options.json) {
|
|
130314
|
+
console.log(JSON.stringify(missions.map((mission) => ({
|
|
130315
|
+
id: mission.id,
|
|
130316
|
+
status: mission.status,
|
|
130317
|
+
goal: mission.goal,
|
|
130318
|
+
workspacePath: mission.workspace.path,
|
|
130319
|
+
branch: mission.workspace.branch,
|
|
130320
|
+
completedTasks: mission.tasks.filter((task) => task.status === "completed").length,
|
|
130321
|
+
totalTasks: mission.tasks.length,
|
|
130322
|
+
reason: mission.codeDelivery?.error ?? mission.execution?.pauseReason ?? mission.error ?? null,
|
|
130323
|
+
nextRunAt: mission.codeDelivery?.nextRunAt ?? mission.execution?.nextRunAt ?? null,
|
|
130324
|
+
delivery: mission.codeDelivery ? { phase: mission.codeDelivery.phase, commitSha: mission.codeDelivery.commitSha ?? null } : null
|
|
130325
|
+
}))));
|
|
130326
|
+
return;
|
|
130327
|
+
}
|
|
130328
|
+
if (!missions.length)
|
|
130329
|
+
console.log("No orders yet. Run bun av order --help.");
|
|
130330
|
+
for (const mission of missions) {
|
|
130331
|
+
console.log(`${mission.id} ${mission.status} ${mission.tasks.filter((task) => task.status === "completed").length}/${mission.tasks.length} ${mission.goal.slice(0, 100)}`);
|
|
130332
|
+
console.log(` ${mission.workspace.path}${mission.error ? `
|
|
130333
|
+
${mission.error}` : ""}`);
|
|
130334
|
+
}
|
|
130335
|
+
});
|
|
130336
|
+
registerMissionReconciliation(missions);
|
|
130337
|
+
}
|
|
130338
|
+
|
|
130158
130339
|
// src/chief-workspace-dependencies.ts
|
|
130159
130340
|
import { lstat as lstat21, mkdir as mkdir26, readdir as readdir14, readFile as readFile18, realpath as realpath30, stat as stat5, symlink } from "node:fs/promises";
|
|
130160
|
-
import { join as
|
|
130341
|
+
import { join as join51, relative as relative18, resolve as resolve33, sep as sep17 } from "node:path";
|
|
130161
130342
|
var caches = new Set([".cache", ".vite", ".vite-temp"]);
|
|
130162
130343
|
var inside3 = (root, path) => path === root || path.startsWith(`${root}${sep17}`);
|
|
130163
130344
|
async function prepareMissionDependencies(repository, workspace) {
|
|
@@ -130165,7 +130346,7 @@ async function prepareMissionDependencies(repository, workspace) {
|
|
|
130165
130346
|
const target = await realpath30(workspace);
|
|
130166
130347
|
if (source === target)
|
|
130167
130348
|
throw new Error("Dependency preparation requires a separate mission workspace.");
|
|
130168
|
-
const packagePath =
|
|
130349
|
+
const packagePath = join51(source, "package.json");
|
|
130169
130350
|
const metadata = await readFile18(packagePath, "utf8").catch((error) => {
|
|
130170
130351
|
if (error.code === "ENOENT")
|
|
130171
130352
|
return null;
|
|
@@ -130197,10 +130378,10 @@ async function prepareMissionDependencies(repository, workspace) {
|
|
|
130197
130378
|
if (segment === "*") {
|
|
130198
130379
|
for (const entry of await readdir14(directory, { withFileTypes: true }).catch(() => [])) {
|
|
130199
130380
|
if (entry.isDirectory() && !entry.name.startsWith(".") && entry.name !== "node_modules")
|
|
130200
|
-
await expand(
|
|
130381
|
+
await expand(join51(directory, entry.name), rest);
|
|
130201
130382
|
}
|
|
130202
130383
|
} else if (segment)
|
|
130203
|
-
await expand(
|
|
130384
|
+
await expand(join51(directory, segment), rest);
|
|
130204
130385
|
}
|
|
130205
130386
|
for (const pattern of patterns) {
|
|
130206
130387
|
if (typeof pattern !== "string" || pattern.length > 1024 || pattern.startsWith("/") || pattern.split("/").some((part) => !part || part === "." || part === ".." || part.startsWith(".") || part === "node_modules" || part !== "*" && /[*?\\:]/.test(part)) || pattern.split("/").length > 8)
|
|
@@ -130236,7 +130417,7 @@ async function prepareMissionDependencies(repository, workspace) {
|
|
|
130236
130417
|
await symlink(installed, to, (await stat5(installed)).isDirectory() ? "dir" : "file");
|
|
130237
130418
|
}
|
|
130238
130419
|
for (const root of roots) {
|
|
130239
|
-
const modules =
|
|
130420
|
+
const modules = join51(root, "node_modules");
|
|
130240
130421
|
const installed = await stat5(modules).catch(() => {
|
|
130241
130422
|
return;
|
|
130242
130423
|
});
|
|
@@ -130245,7 +130426,7 @@ async function prepareMissionDependencies(repository, workspace) {
|
|
|
130245
130426
|
const destinationRoot = await realpath30(resolve33(target, relative18(source, root)));
|
|
130246
130427
|
if (!inside3(target, destinationRoot))
|
|
130247
130428
|
throw new Error("A mission package directory escapes its workspace.");
|
|
130248
|
-
const destination =
|
|
130429
|
+
const destination = join51(destinationRoot, "node_modules");
|
|
130249
130430
|
const existing = await lstat21(destination).catch(() => {
|
|
130250
130431
|
return;
|
|
130251
130432
|
});
|
|
@@ -130255,8 +130436,8 @@ async function prepareMissionDependencies(repository, workspace) {
|
|
|
130255
130436
|
for (const entry of await readdir14(modules, { withFileTypes: true })) {
|
|
130256
130437
|
if (caches.has(entry.name))
|
|
130257
130438
|
continue;
|
|
130258
|
-
const from =
|
|
130259
|
-
const to =
|
|
130439
|
+
const from = join51(modules, entry.name);
|
|
130440
|
+
const to = join51(destination, entry.name);
|
|
130260
130441
|
if (entry.name.startsWith("@") && entry.isDirectory()) {
|
|
130261
130442
|
const scope = await lstat21(to).catch(() => {
|
|
130262
130443
|
return;
|
|
@@ -130265,7 +130446,7 @@ async function prepareMissionDependencies(repository, workspace) {
|
|
|
130265
130446
|
throw new Error("A dependency scope must be a local directory.");
|
|
130266
130447
|
await mkdir26(to, { recursive: true });
|
|
130267
130448
|
for (const member of await readdir14(from))
|
|
130268
|
-
await link(
|
|
130449
|
+
await link(join51(from, member), join51(to, member));
|
|
130269
130450
|
} else
|
|
130270
130451
|
await link(from, to);
|
|
130271
130452
|
}
|
|
@@ -130295,14 +130476,15 @@ async function runOrder(goal, options, root = process.cwd()) {
|
|
|
130295
130476
|
throw new Error("Code delivery retains its saved branch, paths, commit message and hook policy. Resume without replacement delivery options.");
|
|
130296
130477
|
if (!options.resume && [options.retry, options.resolveEffect, options.effectResult, options.accountRun, options.accountCost].some((value) => value !== undefined && value !== false))
|
|
130297
130478
|
throw new Error("Use --resume <id> for retry, external-effect resolution or cost reconciliation.");
|
|
130298
|
-
const store = new MissionStore(
|
|
130479
|
+
const store = new MissionStore(join52(root, ".agent-valley/missions"));
|
|
130299
130480
|
const id = options.resume ?? options.missionId ?? randomUUID22();
|
|
130300
130481
|
const unlock = await store.lock(id);
|
|
130301
130482
|
const abortController = new AbortController;
|
|
130302
130483
|
const interrupt = () => abortController.abort(new MissionPause("Operator stopped the order. Its checks and worktree were retained; repair any interrupted effects before resuming with --retry.", "interrupted"));
|
|
130484
|
+
const terminate = () => options.service ? abortController.abort(serviceShutdownPause()) : interrupt();
|
|
130303
130485
|
const runtime = new ChiefRuntime(store, abortController.signal, (stage, persona) => console.log(`[${stage}] ${persona.name} (${persona.agentType})`));
|
|
130304
130486
|
process.once("SIGINT", interrupt);
|
|
130305
|
-
process.once("SIGTERM",
|
|
130487
|
+
process.once("SIGTERM", terminate);
|
|
130306
130488
|
let mission;
|
|
130307
130489
|
let capture;
|
|
130308
130490
|
let reportSaved = false;
|
|
@@ -130339,7 +130521,7 @@ async function runOrder(goal, options, root = process.cwd()) {
|
|
|
130339
130521
|
throw new Error("Internal child launch does not match its saved operation, goal and accepted baseline. Restore the original operation checkpoint.");
|
|
130340
130522
|
if (Boolean(options.baselineWorkspace) !== Boolean(options.operationId))
|
|
130341
130523
|
throw new Error("An internal operation snapshot requires both its operation identity and accepted baseline.");
|
|
130342
|
-
const workspace = options.baselineWorkspace && options.operationId ? await createContinuousMissionWorkspace(config.workspace, options.operationId, options.baselineWorkspace, id, goal) : await new WorkspaceManager(config.workspace).create(missionIssue(id, goal), undefined, codeDelivery ?
|
|
130524
|
+
const workspace = options.baselineWorkspace && options.operationId ? await createContinuousMissionWorkspace(config.workspace, options.operationId, options.baselineWorkspace, id, goal) : await new WorkspaceManager(config.workspace).create(missionIssue(id, goal), undefined, codeDelivery ? join52(config.workspace, ".agent-valley", "workspaces") : undefined);
|
|
130343
130525
|
if (options.operationId)
|
|
130344
130526
|
await restoreOperationOrigin(config.workspace, workspace.path);
|
|
130345
130527
|
if (!codeDelivery)
|
|
@@ -130473,12 +130655,19 @@ Resume: bun av order --resume ${id}`);
|
|
|
130473
130655
|
} finally {
|
|
130474
130656
|
clearTimeout(deadlineTimer);
|
|
130475
130657
|
process.removeListener("SIGINT", interrupt);
|
|
130476
|
-
process.removeListener("SIGTERM",
|
|
130658
|
+
process.removeListener("SIGTERM", terminate);
|
|
130477
130659
|
try {
|
|
130478
130660
|
try {
|
|
130479
130661
|
await finishCapture();
|
|
130480
130662
|
} finally {
|
|
130481
|
-
|
|
130663
|
+
try {
|
|
130664
|
+
await runtime.close();
|
|
130665
|
+
} finally {
|
|
130666
|
+
if (mission && isServiceShutdown(abortController.signal)) {
|
|
130667
|
+
recordServiceShutdown(mission);
|
|
130668
|
+
await store.save(mission);
|
|
130669
|
+
}
|
|
130670
|
+
}
|
|
130482
130671
|
}
|
|
130483
130672
|
} finally {
|
|
130484
130673
|
await unlock();
|
|
@@ -130497,7 +130686,7 @@ async function dispatchOrder(goal, options, root = process.cwd(), dependencies =
|
|
|
130497
130686
|
};
|
|
130498
130687
|
const [operation, mission] = await Promise.all([
|
|
130499
130688
|
operationStore(root).load(options.resume).catch(missing),
|
|
130500
|
-
new MissionStore(
|
|
130689
|
+
new MissionStore(join52(root, ".agent-valley", "missions")).load(options.resume).catch(missing)
|
|
130501
130690
|
]);
|
|
130502
130691
|
if (operation && mission)
|
|
130503
130692
|
throw new Error(`Saved ID ${options.resume} names both an operation and a mission. Use --once to resume the mission; inspect av operations before resuming the operation.`);
|
|
@@ -130533,7 +130722,7 @@ async function dispatchOrder(goal, options, root = process.cwd(), dependencies =
|
|
|
130533
130722
|
}
|
|
130534
130723
|
function registerChiefCommands(program) {
|
|
130535
130724
|
registerContinuousCommands(program);
|
|
130536
|
-
program.command("order [goal]").description("Give the Chief Director a goal; continuously select, execute, review and verify improvements").option("--once", "Stop after one verified goal instead of continuing improvements").option("--cycles <count>", "Cumulative verified improvement limit; default continues until stopped").option("--interval <seconds>", "Wait before selecting again when no new goal is justified (default 300)").option("--workspace <path>", "Target Git repository (defaults to av.yaml)").option("--verify <command>", "Trusted completion check (defaults to av.yaml)").option("--deliver <branch>", "Commit and push only verified, reviewed work to the selected source branch").option("--delivery-paths <json>", "JSON array of exact product files allowed for code delivery").option("--delivery-message <text>", "Commit message for the approved delivery, including required repository trailers").option("--delivery-remote <name>", "Configured Git remote for code delivery (default origin)").option("--delivery-skip-pre-push", "Authorize git push --no-verify for this delivery; commit hooks remain enabled").option("--actor <type>", "Chief Director CLI (default: saved actor.type, otherwise an authenticated CLI)").option("--model <id>", "Chief Director model (default: actor.model from config, otherwise the CLI default)").option("--director <id>", "Chief Director Actor ID").option("--actors <file>", "Use a configured YAML Actor roster instead of generating goal-specific Actors").addOption(new Option("--agent <type>", "Legacy alias for --actor").hideHelp()).addOption(new Option("--chief <id>", "Legacy alias for --director").hideHelp()).addOption(new Option("--personas <file>", "Legacy alias for --actors").hideHelp()).option("--oma", "Require OMA completion receipts for workers (installed skill selection is automatic)").option("--timeout <seconds>", "Timeout per actor/check (default 600 or actor.timeout)").option("--repairs <count>", "Repair limit per task/final review (default 2)").option("--rounds <count>", "Chief Director recovery decision limit, preserved on resume (default 8, maximum 50)").option("--parallel <count>", "Independent Actor concurrency (default 3, maximum 8)").option("--runs <count>", "Actor call limit per goal/decision; may be increased on saved checkpoint resume (default 200)").option("--duration <seconds>", "Wall-time limit per goal/decision; may be increased on resume (default 86400)").option("--cost <usd>", "Configured-price estimated cost limit; unknown cost pauses further calls").option("--account-run <run-id>", "Reconcile a finished run whose usage/cost was lost").option("--account-cost <usd>", "Operator-observed USD cost for --account-run; stored separately from native usage").option("--retry", "Resume after repairing a blocker; retain prior evidence and spent budget").option("--resolve-effect <task-id>", "Reconcile an interrupted external action before resuming").option("--effect-result <result>", "External destination inspection result: completed or not-applied").option("--no-supervise", "With --once, run directly without worker crash restart or observation polling").addOption(new Option("--worker", "Internal supervised worker").hideHelp()).addOption(new Option("--mission-id <id>", "Internal mission identity").hideHelp()).addOption(new Option("--baseline-workspace <path>", "Internal accepted operation snapshot").hideHelp()).addOption(new Option("--operation-id <id>", "Internal operation identity").hideHelp()).addOption(new Option("--native-model", "Internal pinned Chief native model default").hideHelp()).option("--resume <id>", "Resume the saved continuing order or single mission with its original contract").action(async (goal, options) => {
|
|
130725
|
+
program.command("order [goal]").description("Give the Chief Director a goal; continuously select, execute, review and verify improvements").option("--once", "Stop after one verified goal instead of continuing improvements").option("--cycles <count>", "Cumulative verified improvement limit; default continues until stopped").option("--interval <seconds>", "Wait before selecting again when no new goal is justified (default 300)").option("--workspace <path>", "Target Git repository (defaults to av.yaml)").option("--verify <command>", "Trusted completion check (defaults to av.yaml)").option("--deliver <branch>", "Commit and push only verified, reviewed work to the selected source branch").option("--delivery-paths <json>", "JSON array of exact product files allowed for code delivery").option("--delivery-message <text>", "Commit message for the approved delivery, including required repository trailers").option("--delivery-remote <name>", "Configured Git remote for code delivery (default origin)").option("--delivery-skip-pre-push", "Authorize git push --no-verify for this delivery; commit hooks remain enabled").option("--actor <type>", "Chief Director CLI (default: saved actor.type, otherwise an authenticated CLI)").option("--model <id>", "Chief Director model (default: actor.model from config, otherwise the CLI default)").option("--director <id>", "Chief Director Actor ID").option("--actors <file>", "Use a configured YAML Actor roster instead of generating goal-specific Actors").addOption(new Option("--agent <type>", "Legacy alias for --actor").hideHelp()).addOption(new Option("--chief <id>", "Legacy alias for --director").hideHelp()).addOption(new Option("--personas <file>", "Legacy alias for --actors").hideHelp()).option("--oma", "Require OMA completion receipts for workers (installed skill selection is automatic)").option("--timeout <seconds>", "Timeout per actor/check (default 600 or actor.timeout)").option("--repairs <count>", "Repair limit per task/final review (default 2)").option("--rounds <count>", "Chief Director recovery decision limit, preserved on resume (default 8, maximum 50)").option("--parallel <count>", "Independent Actor concurrency (default 3, maximum 8)").option("--runs <count>", "Actor call limit per goal/decision; may be increased on saved checkpoint resume (default 200)").option("--duration <seconds>", "Wall-time limit per goal/decision; may be increased on resume (default 86400)").option("--cost <usd>", "Configured-price estimated cost limit; unknown cost pauses further calls").option("--account-run <run-id>", "Reconcile a finished run whose usage/cost was lost").option("--account-cost <usd>", "Operator-observed USD cost for --account-run; stored separately from native usage").option("--retry", "Resume after repairing a blocker; retain prior evidence and spent budget").option("--resolve-effect <task-id>", "Reconcile an interrupted external action before resuming").option("--effect-result <result>", "External destination inspection result: completed or not-applied").option("--no-supervise", "With --once, run directly without worker crash restart or observation polling").option("--service", "Resume after OS service SIGTERM within saved limits; SIGINT still cancels").addOption(new Option("--worker", "Internal supervised worker").hideHelp()).addOption(new Option("--mission-id <id>", "Internal mission identity").hideHelp()).addOption(new Option("--baseline-workspace <path>", "Internal accepted operation snapshot").hideHelp()).addOption(new Option("--operation-id <id>", "Internal operation identity").hideHelp()).addOption(new Option("--native-model", "Internal pinned Chief native model default").hideHelp()).option("--resume <id>", "Resume the saved continuing order or single mission with its original contract").action(async (goal, options) => {
|
|
130537
130726
|
const result = await dispatchOrder(goal, options);
|
|
130538
130727
|
if ("phase" in result) {
|
|
130539
130728
|
console.log(`Order ${result.id}: ${result.phase}; ${result.completedCycles} verified improvements.`);
|
|
@@ -130546,26 +130735,12 @@ function registerChiefCommands(program) {
|
|
|
130546
130735
|
process.exitCode = orderExitCode(result);
|
|
130547
130736
|
}
|
|
130548
130737
|
});
|
|
130549
|
-
|
|
130550
|
-
if (options.watch) {
|
|
130551
|
-
await watchOrders(process.cwd());
|
|
130552
|
-
return;
|
|
130553
|
-
}
|
|
130554
|
-
const missions = await new MissionStore(join51(process.cwd(), ".agent-valley/missions")).list();
|
|
130555
|
-
if (!missions.length)
|
|
130556
|
-
console.log("No orders yet. Run bun av order --help.");
|
|
130557
|
-
for (const mission of missions) {
|
|
130558
|
-
console.log(`${mission.id} ${mission.status} ${mission.tasks.filter((task) => task.status === "completed").length}/${mission.tasks.length} ${mission.goal.slice(0, 100)}`);
|
|
130559
|
-
console.log(` ${mission.workspace.path}${mission.error ? `
|
|
130560
|
-
${mission.error}` : ""}`);
|
|
130561
|
-
}
|
|
130562
|
-
});
|
|
130563
|
-
registerMissionReconciliation(missions);
|
|
130738
|
+
registerMissionCommands(program);
|
|
130564
130739
|
}
|
|
130565
130740
|
|
|
130566
130741
|
// src/chief-organization.ts
|
|
130567
130742
|
import { readFile as readFile19, stat as stat6 } from "node:fs/promises";
|
|
130568
|
-
import { isAbsolute as isAbsolute20, join as
|
|
130743
|
+
import { isAbsolute as isAbsolute20, join as join53, resolve as resolve34 } from "node:path";
|
|
130569
130744
|
init_chief_schema();
|
|
130570
130745
|
init_yaml_loader();
|
|
130571
130746
|
function organizationRepository(root, workspace) {
|
|
@@ -130619,13 +130794,13 @@ function registerOrganizationCommands(program) {
|
|
|
130619
130794
|
});
|
|
130620
130795
|
const reports = program.command("reports").description("Inspect and retry third-party report attachments");
|
|
130621
130796
|
reports.command("list").option("--workspace <path>", "Source repository").action(async (opts) => {
|
|
130622
|
-
console.log(JSON.stringify(await listReportDeliveries(
|
|
130797
|
+
console.log(JSON.stringify(await listReportDeliveries(join53(organizationRepository(process.cwd(), opts.workspace), ".agent-valley")), null, 2));
|
|
130623
130798
|
});
|
|
130624
130799
|
reports.command("retry").option("--workspace <path>", "Source repository").action(async (opts) => {
|
|
130625
130800
|
const config = mergeChiefConfig(loadGlobalConfig()?.chief, loadProjectConfig()?.chief);
|
|
130626
130801
|
if (!config.reporting)
|
|
130627
130802
|
throw new Error("Set chief.reporting.destinations in av.yaml before retrying reports.");
|
|
130628
|
-
console.log(JSON.stringify(await retryPendingReports(config.reporting,
|
|
130803
|
+
console.log(JSON.stringify(await retryPendingReports(config.reporting, join53(organizationRepository(process.cwd(), opts.workspace), ".agent-valley")), null, 2));
|
|
130629
130804
|
});
|
|
130630
130805
|
}
|
|
130631
130806
|
|
|
@@ -130650,10 +130825,10 @@ var import_picocolors = __toESM(require_picocolors(), 1);
|
|
|
130650
130825
|
init_project_config_path();
|
|
130651
130826
|
init_yaml_loader();
|
|
130652
130827
|
init_doctor_checks();
|
|
130653
|
-
import { join as
|
|
130828
|
+
import { join as join57 } from "node:path";
|
|
130654
130829
|
|
|
130655
130830
|
// src/doctor-oma-checks.ts
|
|
130656
|
-
import { join as
|
|
130831
|
+
import { join as join56 } from "node:path";
|
|
130657
130832
|
function checkOma(project, deps) {
|
|
130658
130833
|
const strict = project?.oma?.mode === "strict";
|
|
130659
130834
|
const order = !!project && !project.tracker && !project.linear && !project.github;
|
|
@@ -130741,7 +130916,7 @@ function checkOma(project, deps) {
|
|
|
130741
130916
|
fix: "Set verify.command to a deterministic non-build check in av.yaml before using oma.mode: strict.",
|
|
130742
130917
|
critical: true
|
|
130743
130918
|
});
|
|
130744
|
-
const triggerPath =
|
|
130919
|
+
const triggerPath = join56(deps.cwd, ".agents", "hooks", "core", "triggers.json");
|
|
130745
130920
|
let table = null;
|
|
130746
130921
|
try {
|
|
130747
130922
|
table = parseTriggerTable(deps.readFileSync(triggerPath));
|
|
@@ -130758,7 +130933,7 @@ function checkOma(project, deps) {
|
|
|
130758
130933
|
return results;
|
|
130759
130934
|
}
|
|
130760
130935
|
results.push({ id: "oma.triggers", name: "OMA trigger table", status: "pass", message: triggerPath, critical: false });
|
|
130761
|
-
const missing = Object.entries(table.workflows).filter(([name, workflow]) => !workflow.persistent && !table.excludedWorkflows.includes(name)).map(([name]) =>
|
|
130936
|
+
const missing = Object.entries(table.workflows).filter(([name, workflow]) => !workflow.persistent && !table.excludedWorkflows.includes(name)).map(([name]) => join56(deps.cwd, ".agents", "workflows", `${name}.md`)).filter((path) => !deps.existsSync(path));
|
|
130762
130937
|
results.push(missing.length === 0 ? {
|
|
130763
130938
|
id: "oma.workflows",
|
|
130764
130939
|
name: "OMA workflow files",
|
|
@@ -130833,7 +131008,7 @@ function checkTunnel(project, deps) {
|
|
|
130833
131008
|
}
|
|
130834
131009
|
const mode = project?.tunnel?.cloudflare?.mode ?? "quick";
|
|
130835
131010
|
if (mode === "named") {
|
|
130836
|
-
const certPath =
|
|
131011
|
+
const certPath = join57(deps.home, ".cloudflared", "cert.pem");
|
|
130837
131012
|
if (!deps.existsSync(certPath)) {
|
|
130838
131013
|
return {
|
|
130839
131014
|
id: "tunnel",
|
|
@@ -130873,7 +131048,7 @@ function checkTunnel(project, deps) {
|
|
|
130873
131048
|
critical: false
|
|
130874
131049
|
};
|
|
130875
131050
|
}
|
|
130876
|
-
const ngrokConfigPath = deps.platform === "darwin" ?
|
|
131051
|
+
const ngrokConfigPath = deps.platform === "darwin" ? join57(deps.home, "Library", "Application Support", "ngrok", "ngrok.yml") : join57(deps.home, ".config", "ngrok", "ngrok.yml");
|
|
130877
131052
|
if (!deps.existsSync(ngrokConfigPath)) {
|
|
130878
131053
|
return {
|
|
130879
131054
|
id: "tunnel",
|
|
@@ -130944,7 +131119,7 @@ function checkConfig(deps) {
|
|
|
130944
131119
|
critical: true
|
|
130945
131120
|
});
|
|
130946
131121
|
}
|
|
130947
|
-
const projectPath =
|
|
131122
|
+
const projectPath = join57(deps.cwd, PROJECT_CONFIG_FILENAME);
|
|
130948
131123
|
try {
|
|
130949
131124
|
project = deps.loadProjectConfig(deps.cwd);
|
|
130950
131125
|
results.push(project ? {
|
|
@@ -135501,7 +135676,7 @@ init_team_relay_error();
|
|
|
135501
135676
|
// ../../packages/core/src/relay/turso-migration-assets.ts
|
|
135502
135677
|
init_zod();
|
|
135503
135678
|
import { copyFile as copyFile3, lstat as lstat26, mkdir as mkdir27, readFile as readFile21 } from "node:fs/promises";
|
|
135504
|
-
import { dirname as dirname13, join as
|
|
135679
|
+
import { dirname as dirname13, join as join63 } from "node:path";
|
|
135505
135680
|
import { fileURLToPath as fileURLToPath3 } from "node:url";
|
|
135506
135681
|
var TURSO_MIGRATION_ASSET_PATH = "assets/turso/migrations";
|
|
135507
135682
|
var journalSchema = object({
|
|
@@ -135539,10 +135714,10 @@ async function loadTursoMigrationAssets(candidates = tursoMigrationAssetCandidat
|
|
|
135539
135714
|
if (!info.isDirectory() || info.isSymbolicLink())
|
|
135540
135715
|
throw new Error(`Turso migration directory ${directory} must be a regular directory. Restore the checkout or reinstall the CLI package.`);
|
|
135541
135716
|
try {
|
|
135542
|
-
const meta = await lstat26(
|
|
135717
|
+
const meta = await lstat26(join63(directory, "meta"));
|
|
135543
135718
|
if (!meta.isDirectory() || meta.isSymbolicLink())
|
|
135544
135719
|
throw new Error("Invalid migration metadata directory");
|
|
135545
|
-
const journalPath =
|
|
135720
|
+
const journalPath = join63(directory, "meta/_journal.json");
|
|
135546
135721
|
await regularFile(journalPath);
|
|
135547
135722
|
const journal = journalSchema.parse(JSON.parse(await readFile21(journalPath, "utf8")));
|
|
135548
135723
|
const tags = journal.entries.map((entry) => entry.tag);
|
|
@@ -135550,8 +135725,8 @@ async function loadTursoMigrationAssets(candidates = tursoMigrationAssetCandidat
|
|
|
135550
135725
|
throw new Error("Duplicate migration tags");
|
|
135551
135726
|
const files = ["meta/_journal.json", ...tags.map((tag) => `${tag}.sql`)];
|
|
135552
135727
|
for (const file of files.slice(1)) {
|
|
135553
|
-
await regularFile(
|
|
135554
|
-
if (!(await readFile21(
|
|
135728
|
+
await regularFile(join63(directory, file));
|
|
135729
|
+
if (!(await readFile21(join63(directory, file), "utf8")).trim())
|
|
135555
135730
|
throw new Error("Empty migration SQL");
|
|
135556
135731
|
}
|
|
135557
135732
|
return { directory, files };
|
package/dist/supervisor.js
CHANGED
|
@@ -7083,6 +7083,7 @@ var init_contracts = __esm(() => {
|
|
|
7083
7083
|
"unknown-effect",
|
|
7084
7084
|
"budget",
|
|
7085
7085
|
"interrupted",
|
|
7086
|
+
"service-shutdown",
|
|
7086
7087
|
"chief-wait",
|
|
7087
7088
|
"chief-unavailable",
|
|
7088
7089
|
"integrity"
|
|
@@ -7256,7 +7257,7 @@ function recordPause(mission, pause) {
|
|
|
7256
7257
|
state.failureKind = pause.kind;
|
|
7257
7258
|
if (pause.nextRunAt)
|
|
7258
7259
|
state.nextRunAt = pause.nextRunAt;
|
|
7259
|
-
else
|
|
7260
|
+
else if (pause.kind !== "service-shutdown")
|
|
7260
7261
|
delete state.nextRunAt;
|
|
7261
7262
|
mission.status = pause.nextRunAt ? "waiting" : "paused";
|
|
7262
7263
|
mission.error = pause.message;
|