agent-valley 4.8.5 → 4.8.7
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 +1199 -670
- package/dist/supervisor.js +15 -2
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -7086,6 +7086,7 @@ var init_contracts = __esm(() => {
|
|
|
7086
7086
|
"authentication",
|
|
7087
7087
|
"rate-limit",
|
|
7088
7088
|
"provider",
|
|
7089
|
+
"actor-cooldown",
|
|
7089
7090
|
"environment",
|
|
7090
7091
|
"implementation",
|
|
7091
7092
|
"unknown-effect",
|
|
@@ -7467,7 +7468,7 @@ var init_review_gates = __esm(() => {
|
|
|
7467
7468
|
});
|
|
7468
7469
|
|
|
7469
7470
|
// ../../packages/core/src/chief/operations.ts
|
|
7470
|
-
var actorType, text3, amount, routingCandidateSchema, chiefOperatingPolicySchema, operatingRunSchema, routeEvidenceSchema, reviewDecisionSchema, chiefOperationsSchema;
|
|
7471
|
+
var actorType, text3, amount, routingCandidateSchema, chiefOperatingPolicySchema, operatingRunSchema, providerHealthSchema, providerHealthEvidenceSchema, routeEvidenceSchema, reviewDecisionSchema, chiefOperationsSchema;
|
|
7471
7472
|
var init_operations = __esm(() => {
|
|
7472
7473
|
init_zod();
|
|
7473
7474
|
init_skill_matrix_schema();
|
|
@@ -7526,6 +7527,7 @@ var init_operations = __esm(() => {
|
|
|
7526
7527
|
costUsd: amount.nullable(),
|
|
7527
7528
|
outcome: _enum(["pending", "passed", "rejected", "failed"]),
|
|
7528
7529
|
executionState: _enum(["running", "settled", "unknown"]).optional(),
|
|
7530
|
+
nativeOutcome: _enum(["passed", "failed", "cancelled"]).optional(),
|
|
7529
7531
|
executionRecovery: _enum(["local-process", "reconcile"]).optional(),
|
|
7530
7532
|
routingExclusion: strictObject({
|
|
7531
7533
|
reason: literal("coordinator-cancelled"),
|
|
@@ -7536,13 +7538,24 @@ var init_operations = __esm(() => {
|
|
|
7536
7538
|
evidence: text3.optional(),
|
|
7537
7539
|
fingerprint: text3.optional()
|
|
7538
7540
|
});
|
|
7541
|
+
providerHealthSchema = strictObject({
|
|
7542
|
+
consecutiveFailures: number2().int().nonnegative(),
|
|
7543
|
+
lastOutcomeAt: exports_iso.datetime(),
|
|
7544
|
+
cooldownUntil: exports_iso.datetime().optional()
|
|
7545
|
+
});
|
|
7546
|
+
providerHealthEvidenceSchema = strictObject({
|
|
7547
|
+
actorType,
|
|
7548
|
+
model: text3.optional(),
|
|
7549
|
+
providerHealth: providerHealthSchema
|
|
7550
|
+
});
|
|
7539
7551
|
routeEvidenceSchema = strictObject({
|
|
7540
7552
|
actorType,
|
|
7541
7553
|
model: text3.optional(),
|
|
7542
7554
|
samples: number2().int().nonnegative(),
|
|
7543
7555
|
successes: number2().int().nonnegative(),
|
|
7544
7556
|
totalCostUsd: amount.nullable(),
|
|
7545
|
-
successfulDeliverableCostUsd: amount.nullable()
|
|
7557
|
+
successfulDeliverableCostUsd: amount.nullable(),
|
|
7558
|
+
providerHealth: providerHealthSchema.optional()
|
|
7546
7559
|
}).refine((entry) => entry.successes <= entry.samples, "Route successes cannot exceed actual samples.");
|
|
7547
7560
|
reviewDecisionSchema = strictObject({
|
|
7548
7561
|
taskId: text3,
|
|
@@ -17599,10 +17612,47 @@ var init_claude_session = __esm(() => {
|
|
|
17599
17612
|
});
|
|
17600
17613
|
|
|
17601
17614
|
// ../../packages/core/src/sessions/qwen-session.ts
|
|
17602
|
-
var QwenSession;
|
|
17615
|
+
var computerUseTools, QwenSession;
|
|
17603
17616
|
var init_qwen_session = __esm(() => {
|
|
17604
17617
|
init_claude_session();
|
|
17605
17618
|
init_native_failure();
|
|
17619
|
+
computerUseTools = [
|
|
17620
|
+
"bring_to_front",
|
|
17621
|
+
"check_for_update",
|
|
17622
|
+
"check_permissions",
|
|
17623
|
+
"click",
|
|
17624
|
+
"double_click",
|
|
17625
|
+
"drag",
|
|
17626
|
+
"end_session",
|
|
17627
|
+
"get_accessibility_tree",
|
|
17628
|
+
"get_agent_cursor_state",
|
|
17629
|
+
"get_config",
|
|
17630
|
+
"get_cursor_position",
|
|
17631
|
+
"get_recording_state",
|
|
17632
|
+
"get_screen_size",
|
|
17633
|
+
"get_window_state",
|
|
17634
|
+
"hotkey",
|
|
17635
|
+
"kill_app",
|
|
17636
|
+
"launch_app",
|
|
17637
|
+
"list_apps",
|
|
17638
|
+
"list_windows",
|
|
17639
|
+
"move_cursor",
|
|
17640
|
+
"page",
|
|
17641
|
+
"press_key",
|
|
17642
|
+
"replay_trajectory",
|
|
17643
|
+
"right_click",
|
|
17644
|
+
"scroll",
|
|
17645
|
+
"set_agent_cursor_enabled",
|
|
17646
|
+
"set_agent_cursor_motion",
|
|
17647
|
+
"set_agent_cursor_style",
|
|
17648
|
+
"set_config",
|
|
17649
|
+
"set_value",
|
|
17650
|
+
"start_recording",
|
|
17651
|
+
"start_session",
|
|
17652
|
+
"stop_recording",
|
|
17653
|
+
"type_text",
|
|
17654
|
+
"zoom"
|
|
17655
|
+
].map((name) => `computer_use__${name}`);
|
|
17606
17656
|
QwenSession = class QwenSession extends ClaudeSession {
|
|
17607
17657
|
vendor = "qwen";
|
|
17608
17658
|
actualModel;
|
|
@@ -17610,6 +17660,9 @@ var init_qwen_session = __esm(() => {
|
|
|
17610
17660
|
resultEvent;
|
|
17611
17661
|
buildArgs() {
|
|
17612
17662
|
const args = ["--output-format", "stream-json", "--yolo"];
|
|
17663
|
+
const purpose = this.config?.options?.computerUsePurpose;
|
|
17664
|
+
if (typeof purpose !== "string" || !purpose.trim())
|
|
17665
|
+
args.push("--exclude-tools", computerUseTools.join(","));
|
|
17613
17666
|
if (this.config?.model)
|
|
17614
17667
|
args.push("--model", this.config.model);
|
|
17615
17668
|
return args;
|
|
@@ -21280,12 +21333,12 @@ var require_cross_spawn = __commonJS(function(exports, module) {
|
|
|
21280
21333
|
// src/doctor-checks.ts
|
|
21281
21334
|
import { spawnSync } from "node:child_process";
|
|
21282
21335
|
import { existsSync as existsSync3, readFileSync as readFileSync6 } from "node:fs";
|
|
21283
|
-
import { homedir as
|
|
21284
|
-
import { join as
|
|
21336
|
+
import { homedir as homedir6 } from "node:os";
|
|
21337
|
+
import { join as join24 } from "node:path";
|
|
21285
21338
|
function defaultDoctorDeps() {
|
|
21286
21339
|
return {
|
|
21287
21340
|
cwd: process.cwd(),
|
|
21288
|
-
home:
|
|
21341
|
+
home: homedir6(),
|
|
21289
21342
|
platform: process.platform,
|
|
21290
21343
|
env: process.env,
|
|
21291
21344
|
existsSync: existsSync3,
|
|
@@ -21308,19 +21361,19 @@ function probeAgentAuth(agent, deps) {
|
|
|
21308
21361
|
case "qwen":
|
|
21309
21362
|
return { status: "unknown", message: "Qwen needs a selected API provider/model; configure qwen /auth" };
|
|
21310
21363
|
case "claude": {
|
|
21311
|
-
const p =
|
|
21364
|
+
const p = join24(home, ".claude");
|
|
21312
21365
|
return exists(p) ? { status: "pass", message: `${p} present` } : { status: "fail", message: `${p} not found` };
|
|
21313
21366
|
}
|
|
21314
21367
|
case "codex": {
|
|
21315
|
-
const p =
|
|
21368
|
+
const p = join24(home, ".codex");
|
|
21316
21369
|
return exists(p) ? { status: "pass", message: `${p} present` } : { status: "fail", message: `${p} not found` };
|
|
21317
21370
|
}
|
|
21318
21371
|
case "grok": {
|
|
21319
|
-
const p =
|
|
21372
|
+
const p = join24(home, ".grok", "config.toml");
|
|
21320
21373
|
return exists(p) ? { status: "pass", message: `${p} present` } : { status: "fail", message: `${p} not found` };
|
|
21321
21374
|
}
|
|
21322
21375
|
case "kimi": {
|
|
21323
|
-
const p =
|
|
21376
|
+
const p = join24(home, ".kimi-code", "config.toml");
|
|
21324
21377
|
if (!exists(p))
|
|
21325
21378
|
return { status: "fail", message: `${p} not found` };
|
|
21326
21379
|
try {
|
|
@@ -21331,7 +21384,7 @@ function probeAgentAuth(agent, deps) {
|
|
|
21331
21384
|
}
|
|
21332
21385
|
}
|
|
21333
21386
|
case "opencode": {
|
|
21334
|
-
const p =
|
|
21387
|
+
const p = join24(home, ".local", "share", "opencode", "auth.json");
|
|
21335
21388
|
return exists(p) ? { status: "pass", message: `${p} present` } : { status: "fail", message: `${p} not found` };
|
|
21336
21389
|
}
|
|
21337
21390
|
case "antigravity":
|
|
@@ -21437,7 +21490,7 @@ var init_doctor_checks = __esm(() => {
|
|
|
21437
21490
|
});
|
|
21438
21491
|
|
|
21439
21492
|
// src/qwen-discovery.ts
|
|
21440
|
-
import { join as
|
|
21493
|
+
import { join as join25 } from "node:path";
|
|
21441
21494
|
function record2(value) {
|
|
21442
21495
|
return value && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
21443
21496
|
}
|
|
@@ -21454,7 +21507,7 @@ function qwenAuth(deps, read) {
|
|
|
21454
21507
|
const home = qwenProfilePath(deps.home, deps.env);
|
|
21455
21508
|
if (!home)
|
|
21456
21509
|
return problem("Use an absolute QWEN_HOME so discovery and mission worktrees share the same profile");
|
|
21457
|
-
const settings = record2(read(
|
|
21510
|
+
const settings = record2(read(join25(home, "settings.json")));
|
|
21458
21511
|
const localEnv = record2(settings.env);
|
|
21459
21512
|
const allowed = new Set(getAgentAuthEnvKeys("qwen"));
|
|
21460
21513
|
const env = (key) => deps.env[key] ?? localEnv[key];
|
|
@@ -21500,9 +21553,9 @@ var init_qwen_discovery = __esm(() => {
|
|
|
21500
21553
|
|
|
21501
21554
|
// src/agent-discovery.ts
|
|
21502
21555
|
import { spawn as spawn8 } from "node:child_process";
|
|
21503
|
-
import { accessSync, constants as
|
|
21504
|
-
import { homedir as
|
|
21505
|
-
import { join as
|
|
21556
|
+
import { accessSync, constants as constants11, readFileSync as readFileSync7, statSync as statSync3 } from "node:fs";
|
|
21557
|
+
import { homedir as homedir7 } from "node:os";
|
|
21558
|
+
import { join as join26 } from "node:path";
|
|
21506
21559
|
import { stripVTControlCharacters as stripVTControlCharacters3 } from "node:util";
|
|
21507
21560
|
function record3(value) {
|
|
21508
21561
|
return value !== null && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
@@ -21593,13 +21646,13 @@ function probeNativeCli(path, args, options) {
|
|
|
21593
21646
|
}
|
|
21594
21647
|
function defaultDeps() {
|
|
21595
21648
|
return {
|
|
21596
|
-
home:
|
|
21649
|
+
home: homedir7(),
|
|
21597
21650
|
env: process.env,
|
|
21598
21651
|
now: Date.now,
|
|
21599
21652
|
resolveBinary: resolveBinaryPath,
|
|
21600
21653
|
isExecutableFile: (path) => {
|
|
21601
21654
|
try {
|
|
21602
|
-
accessSync(path,
|
|
21655
|
+
accessSync(path, constants11.X_OK);
|
|
21603
21656
|
return statSync3(path).isFile();
|
|
21604
21657
|
} catch {
|
|
21605
21658
|
return false;
|
|
@@ -21656,8 +21709,8 @@ function expired(token, expiresAt, now, unit = 1) {
|
|
|
21656
21709
|
return false;
|
|
21657
21710
|
}
|
|
21658
21711
|
function kimiAuth(deps) {
|
|
21659
|
-
const home = nonempty(deps.env.KIMI_CODE_HOME) ? deps.env.KIMI_CODE_HOME :
|
|
21660
|
-
const config = record3(readState(
|
|
21712
|
+
const home = nonempty(deps.env.KIMI_CODE_HOME) ? deps.env.KIMI_CODE_HOME : join26(deps.home, ".kimi-code");
|
|
21713
|
+
const config = record3(readState(join26(home, "config.toml"), deps, deps.parseToml));
|
|
21661
21714
|
const model = record3(record3(config.models)[String(config.default_model ?? "")]);
|
|
21662
21715
|
const provider = record3(record3(config.providers)[String(model.provider ?? "")]);
|
|
21663
21716
|
if (nonempty(model.model) && nonempty(provider.type) && nonempty(provider.base_url)) {
|
|
@@ -21671,7 +21724,7 @@ function kimiAuth(deps) {
|
|
|
21671
21724
|
if (nonempty(oauth.key) && (oauth.storage === "file" || oauth.storage === "keyring")) {
|
|
21672
21725
|
const name = oauth.key.split("/").at(-1);
|
|
21673
21726
|
if (name && /^[\w-]+$/.test(name)) {
|
|
21674
|
-
const token = record3(readState(
|
|
21727
|
+
const token = record3(readState(join26(home, "credentials", `${name}.json`), deps));
|
|
21675
21728
|
if (nonempty(token.access_token) && nonempty(token.refresh_token) && typeof token.expires_at === "number" && !expired(token.access_token, token.expires_at, deps.now(), 1000)) {
|
|
21676
21729
|
return { readiness: "ready", reason: "Kimi native OAuth credentials found" };
|
|
21677
21730
|
}
|
|
@@ -21689,15 +21742,15 @@ function localAuth(agent, deps) {
|
|
|
21689
21742
|
if (agent === "kimi")
|
|
21690
21743
|
return kimiAuth(deps);
|
|
21691
21744
|
if (agent === "antigravity") {
|
|
21692
|
-
const settings = record3(readState(
|
|
21745
|
+
const settings = record3(readState(join26(deps.home, ".gemini", "antigravity-cli", "settings.json"), deps));
|
|
21693
21746
|
if (settings.modelProvider === "gemini") {
|
|
21694
21747
|
return nonempty(deps.env.GEMINI_API_KEY) ? { readiness: "ready", reason: "Antigravity Gemini provider and credentials are configured" } : missing(agent, "Set GEMINI_API_KEY for the configured Gemini provider");
|
|
21695
21748
|
}
|
|
21696
21749
|
return null;
|
|
21697
21750
|
}
|
|
21698
21751
|
if (agent === "codex") {
|
|
21699
|
-
const home = nonempty(deps.env.CODEX_HOME) ? deps.env.CODEX_HOME :
|
|
21700
|
-
const value = readState(
|
|
21752
|
+
const home = nonempty(deps.env.CODEX_HOME) ? deps.env.CODEX_HOME : join26(deps.home, ".codex");
|
|
21753
|
+
const value = readState(join26(home, "auth.json"), deps);
|
|
21701
21754
|
if (value === null)
|
|
21702
21755
|
return null;
|
|
21703
21756
|
const auth = record3(value);
|
|
@@ -21713,8 +21766,8 @@ function localAuth(agent, deps) {
|
|
|
21713
21766
|
return missing(agent, "Codex authentication file has no complete credentials");
|
|
21714
21767
|
}
|
|
21715
21768
|
if (agent === "claude") {
|
|
21716
|
-
const home = nonempty(deps.env.CLAUDE_CONFIG_DIR) ? deps.env.CLAUDE_CONFIG_DIR :
|
|
21717
|
-
const value = readState(
|
|
21769
|
+
const home = nonempty(deps.env.CLAUDE_CONFIG_DIR) ? deps.env.CLAUDE_CONFIG_DIR : join26(deps.home, ".claude");
|
|
21770
|
+
const value = readState(join26(home, ".credentials.json"), deps);
|
|
21718
21771
|
if (value === null)
|
|
21719
21772
|
return null;
|
|
21720
21773
|
const oauth = record3(record3(value).claudeAiOauth);
|
|
@@ -21724,8 +21777,8 @@ function localAuth(agent, deps) {
|
|
|
21724
21777
|
return missing(agent, "Claude authentication file has no complete credentials");
|
|
21725
21778
|
}
|
|
21726
21779
|
if (agent === "opencode") {
|
|
21727
|
-
const home = nonempty(deps.env.XDG_DATA_HOME) ? deps.env.XDG_DATA_HOME :
|
|
21728
|
-
const auth = record3(readState(
|
|
21780
|
+
const home = nonempty(deps.env.XDG_DATA_HOME) ? deps.env.XDG_DATA_HOME : join26(deps.home, ".local", "share");
|
|
21781
|
+
const auth = record3(readState(join26(home, "opencode", "auth.json"), deps));
|
|
21729
21782
|
for (const value of Object.values(auth)) {
|
|
21730
21783
|
const credential = record3(value);
|
|
21731
21784
|
if (credential.type === "api" && nonempty(credential.key)) {
|
|
@@ -21770,7 +21823,11 @@ async function boundedProbe(path, args, deps) {
|
|
|
21770
21823
|
}
|
|
21771
21824
|
async function nativeAuth(agent, path, deps) {
|
|
21772
21825
|
if (agent !== "claude" && agent !== "codex" && agent !== "cursor") {
|
|
21773
|
-
return
|
|
21826
|
+
return {
|
|
21827
|
+
readiness: "unknown",
|
|
21828
|
+
reason: "This CLI has no supported read-only authentication status probe. Authentication remains unverified.",
|
|
21829
|
+
authStatusProbe: "unsupported"
|
|
21830
|
+
};
|
|
21774
21831
|
}
|
|
21775
21832
|
const command = agent === "claude" ? "auth" : agent === "codex" ? "login" : "status";
|
|
21776
21833
|
const probeDeps = { ...deps, env: buildAgentEnv(agent, {}, deps.env) };
|
|
@@ -22393,7 +22450,7 @@ var require_dist3 = __commonJS(function(exports) {
|
|
|
22393
22450
|
});
|
|
22394
22451
|
|
|
22395
22452
|
// ../../node_modules/.bun/readdirp@5.1.1/node_modules/readdirp/index.js
|
|
22396
|
-
import { lstat as
|
|
22453
|
+
import { lstat as lstat29, readdir as readdir19, realpath as realpath38, stat as stat9 } from "node:fs/promises";
|
|
22397
22454
|
import { join as pjoin, resolve as presolve, sep as psep } from "node:path";
|
|
22398
22455
|
import { Readable as Readable2 } from "node:stream";
|
|
22399
22456
|
function readdirp(root, options = {}) {
|
|
@@ -22490,7 +22547,7 @@ var init_readdirp = __esm(() => {
|
|
|
22490
22547
|
const type = opts.type ?? defaultOptions4.type;
|
|
22491
22548
|
this._fileFilter = normalizeFilter(opts.fileFilter);
|
|
22492
22549
|
this._directoryFilter = normalizeFilter(opts.directoryFilter);
|
|
22493
|
-
const statMethod = opts.lstat ?
|
|
22550
|
+
const statMethod = opts.lstat ? lstat29 : stat9;
|
|
22494
22551
|
if (wantBigintFsStats) {
|
|
22495
22552
|
this._stat = (path) => statMethod(path, { bigint: true });
|
|
22496
22553
|
} else {
|
|
@@ -22571,7 +22628,7 @@ var init_readdirp = __esm(() => {
|
|
|
22571
22628
|
async _exploreDir(path, depth) {
|
|
22572
22629
|
let files;
|
|
22573
22630
|
try {
|
|
22574
|
-
files = await
|
|
22631
|
+
files = await readdir19(path, this._rdOptions);
|
|
22575
22632
|
} catch (error) {
|
|
22576
22633
|
this._onError(error);
|
|
22577
22634
|
}
|
|
@@ -22617,7 +22674,7 @@ var init_readdirp = __esm(() => {
|
|
|
22617
22674
|
const full = entry.fullPath;
|
|
22618
22675
|
try {
|
|
22619
22676
|
const entryRealPath = await realpath38(full);
|
|
22620
|
-
const entryRealPathStats = await
|
|
22677
|
+
const entryRealPathStats = await lstat29(entryRealPath);
|
|
22621
22678
|
if (entryRealPathStats.isFile()) {
|
|
22622
22679
|
return "file";
|
|
22623
22680
|
}
|
|
@@ -22645,7 +22702,7 @@ var init_readdirp = __esm(() => {
|
|
|
22645
22702
|
|
|
22646
22703
|
// ../../node_modules/.bun/chokidar@5.0.0/node_modules/chokidar/handler.js
|
|
22647
22704
|
import { watch as fs_watch, unwatchFile, watchFile } from "node:fs";
|
|
22648
|
-
import { realpath as fsrealpath, lstat as
|
|
22705
|
+
import { realpath as fsrealpath, lstat as lstat30, open as open19, stat as stat10 } from "node:fs/promises";
|
|
22649
22706
|
import { type as osType } from "node:os";
|
|
22650
22707
|
import * as sp from "node:path";
|
|
22651
22708
|
function createFsWatchInstance(path, options, listener, errHandler, emitRaw) {
|
|
@@ -22717,7 +22774,7 @@ class NodeFsHandler {
|
|
|
22717
22774
|
return;
|
|
22718
22775
|
if (!newStats || newStats.mtimeMs === 0) {
|
|
22719
22776
|
try {
|
|
22720
|
-
const newStats = await
|
|
22777
|
+
const newStats = await stat10(file);
|
|
22721
22778
|
if (this.fsw.closed)
|
|
22722
22779
|
return;
|
|
22723
22780
|
const at = newStats.atimeMs;
|
|
@@ -23073,7 +23130,7 @@ var init_handler = __esm(() => {
|
|
|
23073
23130
|
ERROR: "error"
|
|
23074
23131
|
};
|
|
23075
23132
|
EV = EVENTS;
|
|
23076
|
-
statMethods = { lstat:
|
|
23133
|
+
statMethods = { lstat: lstat30, stat: stat10 };
|
|
23077
23134
|
HANDLER_KEYS = [KEY_LISTENERS, KEY_ERR, KEY_RAW];
|
|
23078
23135
|
binaryExtensions = new Set([
|
|
23079
23136
|
"3dm",
|
|
@@ -23345,7 +23402,7 @@ var init_handler = __esm(() => {
|
|
|
23345
23402
|
// ../../node_modules/.bun/chokidar@5.0.0/node_modules/chokidar/index.js
|
|
23346
23403
|
import { EventEmitter as EventEmitter2 } from "node:events";
|
|
23347
23404
|
import { stat as statcb, Stats } from "node:fs";
|
|
23348
|
-
import { readdir as
|
|
23405
|
+
import { readdir as readdir20, stat as stat11 } from "node:fs/promises";
|
|
23349
23406
|
import * as sp2 from "node:path";
|
|
23350
23407
|
function arrify(item) {
|
|
23351
23408
|
return Array.isArray(item) ? item : [item];
|
|
@@ -23435,7 +23492,7 @@ class DirEntry {
|
|
|
23435
23492
|
return;
|
|
23436
23493
|
const dir = this.path;
|
|
23437
23494
|
try {
|
|
23438
|
-
await
|
|
23495
|
+
await readdir20(dir);
|
|
23439
23496
|
} catch (err) {
|
|
23440
23497
|
if (this._removeWatcher) {
|
|
23441
23498
|
this._removeWatcher(sp2.dirname(dir), sp2.basename(dir));
|
|
@@ -23799,7 +23856,7 @@ var init_chokidar = __esm(() => {
|
|
|
23799
23856
|
const fullPath = opts.cwd ? sp2.join(opts.cwd, path) : path;
|
|
23800
23857
|
let stats;
|
|
23801
23858
|
try {
|
|
23802
|
-
stats = await
|
|
23859
|
+
stats = await stat11(fullPath);
|
|
23803
23860
|
} catch (err) {}
|
|
23804
23861
|
if (!stats || this.closed)
|
|
23805
23862
|
return;
|
|
@@ -24358,6 +24415,11 @@ var init_linear_webhook_client = __esm(() => {
|
|
|
24358
24415
|
});
|
|
24359
24416
|
});
|
|
24360
24417
|
|
|
24418
|
+
// src/setup/actor-readiness.ts
|
|
24419
|
+
function hasUnsupportedAuthProbe(state) {
|
|
24420
|
+
return state.readiness === "unknown" && state.authStatusProbe === "unsupported" && Boolean(state.binaryPath);
|
|
24421
|
+
}
|
|
24422
|
+
|
|
24361
24423
|
// src/setup/config-write.ts
|
|
24362
24424
|
function canonicalConfig(config) {
|
|
24363
24425
|
const { agent, actor, ...rest } = config;
|
|
@@ -24368,8 +24430,8 @@ function canonicalConfig(config) {
|
|
|
24368
24430
|
// src/agent-provisioning.ts
|
|
24369
24431
|
import { spawn as spawn12 } from "node:child_process";
|
|
24370
24432
|
import { mkdtempSync, rmSync as rmSync2 } from "node:fs";
|
|
24371
|
-
import { homedir as
|
|
24372
|
-
import { delimiter as
|
|
24433
|
+
import { homedir as homedir11, tmpdir as tmpdir4 } from "node:os";
|
|
24434
|
+
import { delimiter as delimiter4, join as join70 } from "node:path";
|
|
24373
24435
|
function runTerminalCommand(request, spawnCommand = spawn12) {
|
|
24374
24436
|
return new Promise((resolve) => {
|
|
24375
24437
|
let child;
|
|
@@ -24412,13 +24474,13 @@ function runTerminalCommand(request, spawnCommand = spawn12) {
|
|
|
24412
24474
|
function defaults2() {
|
|
24413
24475
|
return {
|
|
24414
24476
|
platform: process.platform,
|
|
24415
|
-
home:
|
|
24477
|
+
home: homedir11(),
|
|
24416
24478
|
env: process.env,
|
|
24417
24479
|
resolveBinary: resolveBinaryPath,
|
|
24418
24480
|
discover: discoverAgents,
|
|
24419
24481
|
runCommand: runTerminalCommand,
|
|
24420
24482
|
supportsLoginCommand: (agent, path, env) => supportsNativeLoginCommand(agent, path, { env }),
|
|
24421
|
-
makeTempDir: () => mkdtempSync(
|
|
24483
|
+
makeTempDir: () => mkdtempSync(join70(tmpdir4(), "av-agent-install-")),
|
|
24422
24484
|
removeTempDir: (path) => rmSync2(path, { recursive: true, force: true })
|
|
24423
24485
|
};
|
|
24424
24486
|
}
|
|
@@ -24445,7 +24507,7 @@ async function runOfficialInstaller(installerUrl, deps, options = {}) {
|
|
|
24445
24507
|
let directory;
|
|
24446
24508
|
try {
|
|
24447
24509
|
directory = deps.makeTempDir();
|
|
24448
|
-
const scriptPath =
|
|
24510
|
+
const scriptPath = join70(directory, "install.sh");
|
|
24449
24511
|
const request = { env: options.env ?? deps.env, ...options.cwd ? { cwd: options.cwd } : {} };
|
|
24450
24512
|
const download = await deps.runCommand({
|
|
24451
24513
|
command: curl,
|
|
@@ -24516,10 +24578,10 @@ async function installChiefAgent(agent, overrides = {}) {
|
|
|
24516
24578
|
const install = await runOfficialInstaller(plan.installerUrl, deps);
|
|
24517
24579
|
if (!install.success)
|
|
24518
24580
|
return commandFailure(install.stage === "download" ? "Installer download" : "Installation", install, plan.documentation);
|
|
24519
|
-
const localBin =
|
|
24520
|
-
const pathParts = (deps.env.PATH ?? "").split(
|
|
24581
|
+
const localBin = join70(deps.home, ".local", "bin");
|
|
24582
|
+
const pathParts = (deps.env.PATH ?? "").split(delimiter4);
|
|
24521
24583
|
if (!pathParts.includes(localBin))
|
|
24522
|
-
deps.env.PATH = [localBin, ...pathParts.filter(Boolean)].join(
|
|
24584
|
+
deps.env.PATH = [localBin, ...pathParts.filter(Boolean)].join(delimiter4);
|
|
24523
24585
|
return { success: true, message: "Installation finished; checking the CLI next." };
|
|
24524
24586
|
} catch {
|
|
24525
24587
|
return { success: false, message: `Installation did not complete. Retry or follow ${plan.documentation}.` };
|
|
@@ -24617,31 +24679,31 @@ var init_agent_provisioning = __esm(() => {
|
|
|
24617
24679
|
|
|
24618
24680
|
// src/oma-provisioning.ts
|
|
24619
24681
|
import { mkdtempSync as mkdtempSync2, rmSync as rmSync3 } from "node:fs";
|
|
24620
|
-
import { chmod as chmod5, lstat as
|
|
24621
|
-
import { homedir as
|
|
24622
|
-
import { delimiter as
|
|
24682
|
+
import { chmod as chmod5, lstat as lstat31, readdir as readdir21, readFile as readFile24, realpath as realpath39, unlink as unlink7, writeFile as writeFile15 } from "node:fs/promises";
|
|
24683
|
+
import { homedir as homedir12, tmpdir as tmpdir5 } from "node:os";
|
|
24684
|
+
import { delimiter as delimiter5, isAbsolute as isAbsolute23, join as join71, relative as relative22, resolve as resolve44 } from "node:path";
|
|
24623
24685
|
function defaults3() {
|
|
24624
|
-
const home =
|
|
24686
|
+
const home = homedir12();
|
|
24625
24687
|
return {
|
|
24626
24688
|
platform: process.platform,
|
|
24627
24689
|
home,
|
|
24628
24690
|
env: process.env,
|
|
24629
|
-
resolveBinary: (name) => resolveBinaryPath(name, name === "bun" ? [
|
|
24691
|
+
resolveBinary: (name) => resolveBinaryPath(name, name === "bun" ? [join71(process.env.BUN_INSTALL ?? join71(home, ".bun"), "bin", "bun")] : []),
|
|
24630
24692
|
runCommand: runTerminalCommand,
|
|
24631
|
-
makeTempDir: () => mkdtempSync2(
|
|
24693
|
+
makeTempDir: () => mkdtempSync2(join71(tmpdir5(), "av-oma-install-")),
|
|
24632
24694
|
removeTempDir: (path) => rmSync3(path, { recursive: true, force: true })
|
|
24633
24695
|
};
|
|
24634
24696
|
}
|
|
24635
24697
|
async function directory2(path) {
|
|
24636
24698
|
try {
|
|
24637
|
-
return (await
|
|
24699
|
+
return (await lstat31(path)).isDirectory();
|
|
24638
24700
|
} catch {
|
|
24639
24701
|
return false;
|
|
24640
24702
|
}
|
|
24641
24703
|
}
|
|
24642
24704
|
async function present(path) {
|
|
24643
24705
|
try {
|
|
24644
|
-
await
|
|
24706
|
+
await lstat31(path);
|
|
24645
24707
|
return true;
|
|
24646
24708
|
} catch {
|
|
24647
24709
|
return false;
|
|
@@ -24649,7 +24711,7 @@ async function present(path) {
|
|
|
24649
24711
|
}
|
|
24650
24712
|
async function installedVersion2(skills) {
|
|
24651
24713
|
try {
|
|
24652
|
-
const marker = JSON.parse(await
|
|
24714
|
+
const marker = JSON.parse(await readFile24(join71(skills, "_version.json"), "utf8"));
|
|
24653
24715
|
return marker.schemaVersion === 2 && marker.mode === "project" && typeof marker.version === "string" && /^\d+\.\d+\.\d+(?:-[a-zA-Z0-9.-]+)?$/.test(marker.version) ? marker.version : null;
|
|
24654
24716
|
} catch {
|
|
24655
24717
|
return null;
|
|
@@ -24658,13 +24720,13 @@ async function installedVersion2(skills) {
|
|
|
24658
24720
|
async function snapshotConfig(agents) {
|
|
24659
24721
|
const snapshots = [];
|
|
24660
24722
|
for (const name of CUSTOM_CONFIG_NAMES) {
|
|
24661
|
-
const path =
|
|
24723
|
+
const path = join71(agents, name);
|
|
24662
24724
|
if (!await present(path))
|
|
24663
24725
|
continue;
|
|
24664
|
-
const file = await
|
|
24726
|
+
const file = await lstat31(path);
|
|
24665
24727
|
if (!file.isFile())
|
|
24666
24728
|
throw new Error("Custom configuration must be a project-local regular file.");
|
|
24667
|
-
snapshots.push({ path, bytes: await
|
|
24729
|
+
snapshots.push({ path, bytes: await readFile24(path), mode: file.mode & 511 });
|
|
24668
24730
|
}
|
|
24669
24731
|
return snapshots;
|
|
24670
24732
|
}
|
|
@@ -24678,10 +24740,10 @@ async function restoreConfig(agents, snapshots) {
|
|
|
24678
24740
|
["oma-config.yaml", "oma-config.cue"],
|
|
24679
24741
|
["oma-config.local.yaml", "oma-config.local.cue"]
|
|
24680
24742
|
]) {
|
|
24681
|
-
if (!pair.some((name) => original.has(
|
|
24743
|
+
if (!pair.some((name) => original.has(join71(agents, name))))
|
|
24682
24744
|
continue;
|
|
24683
24745
|
for (const name of pair) {
|
|
24684
|
-
const path =
|
|
24746
|
+
const path = join71(agents, name);
|
|
24685
24747
|
if (!original.has(path))
|
|
24686
24748
|
await unlink7(path).catch((error) => {
|
|
24687
24749
|
if (error.code !== "ENOENT")
|
|
@@ -24691,17 +24753,17 @@ async function restoreConfig(agents, snapshots) {
|
|
|
24691
24753
|
}
|
|
24692
24754
|
}
|
|
24693
24755
|
async function workspacePath(input) {
|
|
24694
|
-
if (!input.trim() || !
|
|
24756
|
+
if (!input.trim() || !isAbsolute23(input))
|
|
24695
24757
|
return null;
|
|
24696
24758
|
const root = resolve44(input);
|
|
24697
24759
|
if (!await directory2(root))
|
|
24698
24760
|
return null;
|
|
24699
|
-
for (const path of [
|
|
24761
|
+
for (const path of [join71(root, ".agents"), join71(root, ".agents", "skills")]) {
|
|
24700
24762
|
if (!await present(path))
|
|
24701
24763
|
continue;
|
|
24702
24764
|
const actual = await realpath39(path);
|
|
24703
24765
|
const location2 = relative22(await realpath39(root), actual);
|
|
24704
|
-
if (location2 === ".." || location2.startsWith(`..${process.platform === "win32" ? "\\" : "/"}`) ||
|
|
24766
|
+
if (location2 === ".." || location2.startsWith(`..${process.platform === "win32" ? "\\" : "/"}`) || isAbsolute23(location2))
|
|
24705
24767
|
return null;
|
|
24706
24768
|
}
|
|
24707
24769
|
return root;
|
|
@@ -24711,15 +24773,15 @@ async function inspectOma(workspaceRoot, _overrides = {}) {
|
|
|
24711
24773
|
const root = await workspacePath(workspaceRoot);
|
|
24712
24774
|
if (!root)
|
|
24713
24775
|
return { success: false, message: "Choose an existing absolute workspace with project-local OMA files." };
|
|
24714
|
-
const skills =
|
|
24776
|
+
const skills = join71(root, ".agents", "skills");
|
|
24715
24777
|
const version = await installedVersion2(skills);
|
|
24716
24778
|
if (!version)
|
|
24717
24779
|
throw new Error("Invalid installed metadata");
|
|
24718
|
-
const entries = (await
|
|
24780
|
+
const entries = (await readdir21(skills, { withFileTypes: true })).filter((entry) => /^oma-[a-z0-9-]+$/.test(entry.name));
|
|
24719
24781
|
if (!entries.length)
|
|
24720
24782
|
throw new Error("No installed skills");
|
|
24721
24783
|
for (const entry of entries) {
|
|
24722
|
-
if (!entry.isDirectory() || !(await
|
|
24784
|
+
if (!entry.isDirectory() || !(await lstat31(join71(skills, entry.name, "SKILL.md"))).isFile())
|
|
24723
24785
|
throw new Error("Incomplete installed skill");
|
|
24724
24786
|
}
|
|
24725
24787
|
return {
|
|
@@ -24767,16 +24829,16 @@ async function prepareOma(workspaceRoot, overrides = {}) {
|
|
|
24767
24829
|
delete environment.OMA_YES;
|
|
24768
24830
|
environment.CI = "true";
|
|
24769
24831
|
const paths = [
|
|
24770
|
-
deps.env.BUN_INSTALL_BIN ??
|
|
24771
|
-
|
|
24832
|
+
deps.env.BUN_INSTALL_BIN ?? join71(deps.env.BUN_INSTALL ?? join71(deps.home, ".bun"), "bin"),
|
|
24833
|
+
join71(deps.home, ".local", "bin")
|
|
24772
24834
|
];
|
|
24773
|
-
environment.PATH = [...new Set([...paths, ...(environment.PATH ?? "").split(
|
|
24835
|
+
environment.PATH = [...new Set([...paths, ...(environment.PATH ?? "").split(delimiter5).filter(Boolean)])].join(delimiter5);
|
|
24774
24836
|
const request = { command: bun, env: environment, cwd: root, timeoutMs: 300000 };
|
|
24775
24837
|
const latest = await deps.runCommand({ ...request, args: ["install", "--global", LATEST_PACKAGE] });
|
|
24776
24838
|
if (!latest.success)
|
|
24777
24839
|
return failure4("OMA CLI update", latest);
|
|
24778
|
-
const agents =
|
|
24779
|
-
const existing = await installedVersion2(
|
|
24840
|
+
const agents = join71(root, ".agents");
|
|
24841
|
+
const existing = await installedVersion2(join71(agents, "skills")) !== null || await directory2(join71(agents, "skills")) && (await present(join71(agents, "oma-config.yaml")) || await present(join71(agents, "mcp.json")) || await directory2(join71(agents, "workflows")));
|
|
24780
24842
|
const custom = await snapshotConfig(agents);
|
|
24781
24843
|
const args = existing ? ["update", "--yes", "--with-new-skills", "--all"] : ["install"];
|
|
24782
24844
|
let installed;
|
|
@@ -24842,10 +24904,10 @@ function currentRuntimeIdentity(env) {
|
|
|
24842
24904
|
if (claude)
|
|
24843
24905
|
identities.push({ actorType: "claude", source: claude });
|
|
24844
24906
|
if (identities.length > 1)
|
|
24845
|
-
throw new
|
|
24907
|
+
throw new SetupIdentityRequiredError("Current runtime identity is ambiguous. Rerun av setup --yes --actor <current-vendor> --model <current-model-or-empty>; do not use OMA defaults to identify the caller.");
|
|
24846
24908
|
return identities[0];
|
|
24847
24909
|
}
|
|
24848
|
-
var quietSpawn = (command, args, options) => spawn13(command, args, { ...options, stdio: "ignore" });
|
|
24910
|
+
var quietSpawn = (command, args, options) => spawn13(command, args, { ...options, stdio: "ignore" }), SetupIdentityRequiredError;
|
|
24849
24911
|
var init_noninteractive_runtime = __esm(() => {
|
|
24850
24912
|
init_yaml_loader();
|
|
24851
24913
|
init_agent_discovery();
|
|
@@ -24853,6 +24915,8 @@ var init_noninteractive_runtime = __esm(() => {
|
|
|
24853
24915
|
init_client_integrations();
|
|
24854
24916
|
init_client_integrations_files();
|
|
24855
24917
|
init_oma_provisioning();
|
|
24918
|
+
SetupIdentityRequiredError = class SetupIdentityRequiredError extends Error {
|
|
24919
|
+
};
|
|
24856
24920
|
});
|
|
24857
24921
|
|
|
24858
24922
|
// ../../node_modules/.bun/fast-string-truncated-width@3.0.3/node_modules/fast-string-truncated-width/dist/utils.js
|
|
@@ -26263,9 +26327,9 @@ var init_ui = __esm(() => {
|
|
|
26263
26327
|
|
|
26264
26328
|
// src/setup/workspace-step.ts
|
|
26265
26329
|
import { statSync as statSync6 } from "node:fs";
|
|
26266
|
-
import { isAbsolute as
|
|
26330
|
+
import { isAbsolute as isAbsolute24 } from "node:path";
|
|
26267
26331
|
async function validateOrderWorkspace(path) {
|
|
26268
|
-
if (!
|
|
26332
|
+
if (!isAbsolute24(path))
|
|
26269
26333
|
return "Set workspace.root in av.yaml to an absolute Git repository path.";
|
|
26270
26334
|
try {
|
|
26271
26335
|
if (!statSync6(path).isDirectory())
|
|
@@ -26292,7 +26356,7 @@ async function stepWorkspace(ctx, step, total) {
|
|
|
26292
26356
|
validate: (v) => {
|
|
26293
26357
|
if (!v?.trim())
|
|
26294
26358
|
return "Required";
|
|
26295
|
-
if (!
|
|
26359
|
+
if (!isAbsolute24(v.trim()))
|
|
26296
26360
|
return "Must be an absolute path";
|
|
26297
26361
|
}
|
|
26298
26362
|
});
|
|
@@ -26318,8 +26382,8 @@ var init_workspace_step = __esm(() => {
|
|
|
26318
26382
|
});
|
|
26319
26383
|
|
|
26320
26384
|
// src/setup/noninteractive-config.ts
|
|
26321
|
-
import { lstat as
|
|
26322
|
-
import { isAbsolute as
|
|
26385
|
+
import { lstat as lstat32, realpath as realpath40 } from "node:fs/promises";
|
|
26386
|
+
import { isAbsolute as isAbsolute25, join as join72, parse as parsePath, resolve as resolve45 } from "node:path";
|
|
26323
26387
|
function validateNoninteractiveOptions(options) {
|
|
26324
26388
|
if (!options.yes || options.edit || options.mode !== undefined && options.mode !== "order")
|
|
26325
26389
|
throw new Error("Use av setup --yes only for local order setup; --edit and --mode tracker require interactive setup.");
|
|
@@ -26357,16 +26421,17 @@ async function configFile(path, schema) {
|
|
|
26357
26421
|
function actor(raw) {
|
|
26358
26422
|
return raw.actor ?? raw.agent ?? {};
|
|
26359
26423
|
}
|
|
26360
|
-
function selectChief(options, deps, project, global2) {
|
|
26424
|
+
function selectChief(options, deps, project, global2, existingProject) {
|
|
26361
26425
|
const runtime = options.actor === undefined ? currentRuntimeIdentity(deps.env) : undefined;
|
|
26362
26426
|
const projectActor = actor(project);
|
|
26363
26427
|
const globalActor = actor(global2);
|
|
26364
|
-
const
|
|
26428
|
+
const savedType = projectActor.type ?? (existingProject ? globalActor.type : undefined);
|
|
26429
|
+
const selected = options.actor ?? runtime?.actorType ?? savedType;
|
|
26365
26430
|
if (!selected)
|
|
26366
|
-
throw new
|
|
26431
|
+
throw new SetupIdentityRequiredError(`actor.type is not selected for ${join72(deps.projectRoot, "av.yaml")}, and the current agent runtime is unknown. Defaults in ${deps.globalConfigPath} do not identify a new project's initiating agent. Rerun av setup --yes --actor <current-vendor> --model <current-model-or-empty>.`);
|
|
26367
26432
|
const actorType = selected;
|
|
26368
26433
|
const actorSource = options.actor !== undefined ? "explicit" : runtime ? "runtime" : projectActor.type ? "project" : "global";
|
|
26369
|
-
const previousType =
|
|
26434
|
+
const previousType = savedType;
|
|
26370
26435
|
let model = null;
|
|
26371
26436
|
let modelSource = "native-default";
|
|
26372
26437
|
if (options.model !== undefined) {
|
|
@@ -26402,16 +26467,16 @@ async function prepareNoninteractiveConfig(options, deps) {
|
|
|
26402
26467
|
let projectRoot;
|
|
26403
26468
|
try {
|
|
26404
26469
|
projectRoot = await realpath40(resolve45(deps.projectRoot));
|
|
26405
|
-
if (!(await
|
|
26470
|
+
if (!(await lstat32(projectRoot)).isDirectory())
|
|
26406
26471
|
throw new Error("not a directory");
|
|
26407
26472
|
} catch {
|
|
26408
26473
|
throw new Error(`AV configuration directory ${deps.projectRoot} does not exist. Run av setup from an existing directory.`);
|
|
26409
26474
|
}
|
|
26410
26475
|
const globalPath = resolve45(deps.globalConfigPath);
|
|
26411
|
-
const projectPath =
|
|
26476
|
+
const projectPath = join72(projectRoot, "av.yaml");
|
|
26412
26477
|
const project = await configFile(projectPath, projectConfigSchema);
|
|
26413
26478
|
const global2 = await configFile(globalPath, globalConfigSchema);
|
|
26414
|
-
const chief = selectChief(options, { ...deps, projectRoot, globalConfigPath: globalPath }, project.raw, global2.raw);
|
|
26479
|
+
const chief = selectChief(options, { ...deps, projectRoot, globalConfigPath: globalPath }, project.raw, global2.raw, project.file.before !== null);
|
|
26415
26480
|
for (const [raw, path] of [
|
|
26416
26481
|
[project.raw, projectPath],
|
|
26417
26482
|
[global2.raw, globalPath]
|
|
@@ -26425,7 +26490,7 @@ async function prepareNoninteractiveConfig(options, deps) {
|
|
|
26425
26490
|
}
|
|
26426
26491
|
const savedWorkspace = project.raw.workspace?.root;
|
|
26427
26492
|
const selectedWorkspace = options.workspace ?? savedWorkspace ?? projectRoot;
|
|
26428
|
-
const workspacePath =
|
|
26493
|
+
const workspacePath = isAbsolute25(selectedWorkspace) ? selectedWorkspace : resolve45(projectRoot, selectedWorkspace);
|
|
26429
26494
|
const workspaceError = await validateOrderWorkspace(workspacePath);
|
|
26430
26495
|
if (workspaceError)
|
|
26431
26496
|
throw new Error(workspaceError);
|
|
@@ -26472,7 +26537,7 @@ var init_noninteractive_config = __esm(() => {
|
|
|
26472
26537
|
});
|
|
26473
26538
|
|
|
26474
26539
|
// src/setup/noninteractive.ts
|
|
26475
|
-
import { join as
|
|
26540
|
+
import { join as join73, parse as parsePath2, resolve as resolve46 } from "node:path";
|
|
26476
26541
|
function rerunCommand(result, options) {
|
|
26477
26542
|
const quote = (value) => `'${value.replace(/'/g, "'\\''")}'`;
|
|
26478
26543
|
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`;
|
|
@@ -26486,7 +26551,7 @@ async function setupNoninteractive(options, overrides = {}) {
|
|
|
26486
26551
|
projectRoot: resolve46(deps.projectRoot),
|
|
26487
26552
|
workspace: null,
|
|
26488
26553
|
config: {
|
|
26489
|
-
project:
|
|
26554
|
+
project: join73(resolve46(deps.projectRoot), "av.yaml"),
|
|
26490
26555
|
global: resolve46(deps.globalConfigPath),
|
|
26491
26556
|
saved: false
|
|
26492
26557
|
},
|
|
@@ -26528,8 +26593,12 @@ async function setupNoninteractive(options, overrides = {}) {
|
|
|
26528
26593
|
result.nextActions.push(installation.message);
|
|
26529
26594
|
}
|
|
26530
26595
|
result.chief.readiness = availability.readiness;
|
|
26596
|
+
result.chief.authStatusProbe = availability.authStatusProbe;
|
|
26531
26597
|
result.chief.message = availability.reason;
|
|
26532
|
-
|
|
26598
|
+
const unsupportedAuthProbe = hasUnsupportedAuthProbe(availability);
|
|
26599
|
+
if (unsupportedAuthProbe)
|
|
26600
|
+
result.chief.message += " Chief authentication remains unverified.";
|
|
26601
|
+
else if (availability.readiness !== "ready")
|
|
26533
26602
|
result.nextActions.push(AGENT_LOGIN_HINT[selected]);
|
|
26534
26603
|
if (options.oma === "skip") {
|
|
26535
26604
|
result.oma = {
|
|
@@ -26564,7 +26633,7 @@ async function setupNoninteractive(options, overrides = {}) {
|
|
|
26564
26633
|
result.nextActions.push(rerunCommand(result, options));
|
|
26565
26634
|
return result;
|
|
26566
26635
|
}
|
|
26567
|
-
if (availability.readiness !== "ready") {
|
|
26636
|
+
if (availability.readiness !== "ready" && !unsupportedAuthProbe) {
|
|
26568
26637
|
result.status = "action_required";
|
|
26569
26638
|
result.exitCode = 2;
|
|
26570
26639
|
result.nextActions.push(rerunCommand(result, options));
|
|
@@ -26575,6 +26644,10 @@ async function setupNoninteractive(options, overrides = {}) {
|
|
|
26575
26644
|
result.nextActions.push(`Run av order "your goal" from ${result.projectRoot}.`, "Restart/reload the agent client and complete its normal workspace/MCP trust steps if needed.");
|
|
26576
26645
|
return result;
|
|
26577
26646
|
} catch (error) {
|
|
26647
|
+
if (error instanceof SetupIdentityRequiredError) {
|
|
26648
|
+
result.status = "action_required";
|
|
26649
|
+
result.exitCode = 2;
|
|
26650
|
+
}
|
|
26578
26651
|
result.error = error instanceof Error ? error.message : "AV setup failed. Correct the reported settings and rerun av setup --yes.";
|
|
26579
26652
|
result.nextActions.push(result.error);
|
|
26580
26653
|
return result;
|
|
@@ -26591,7 +26664,8 @@ function printNoninteractiveSetupResult(result, json = false) {
|
|
|
26591
26664
|
Workspace: ${result.workspace ?? "not selected"}
|
|
26592
26665
|
Project config: ${result.config.project}
|
|
26593
26666
|
Global config: ${result.config.global}
|
|
26594
|
-
Chief Director: ${chief} (${result.chief.readiness})
|
|
26667
|
+
Chief Director: ${chief} (${result.chief.readiness}; source: ${result.chief.actorSource ?? "unknown"})
|
|
26668
|
+
Chief readiness: ${result.chief.message}
|
|
26595
26669
|
OMA: ${result.oma.status}
|
|
26596
26670
|
Client integrations: ${result.integrations.status}`);
|
|
26597
26671
|
for (const action of result.nextActions)
|
|
@@ -26774,6 +26848,10 @@ async function stepAgentType(ctx, step, total) {
|
|
|
26774
26848
|
log2.success(`${plan.label} Chief Director is ready. Available worker CLIs are selected automatically.`);
|
|
26775
26849
|
return;
|
|
26776
26850
|
}
|
|
26851
|
+
if (hasUnsupportedAuthProbe(state)) {
|
|
26852
|
+
log2.warn(`${plan.label} is installed. Authentication remains unverified because its status probe is unsupported.`);
|
|
26853
|
+
return;
|
|
26854
|
+
}
|
|
26777
26855
|
note(state.reason, `${plan.label} setup`);
|
|
26778
26856
|
const action = await select({
|
|
26779
26857
|
message: state.readiness === "unavailable" ? `Install and sign in to ${plan.label}?` : `Sign in to ${plan.label}?`,
|
|
@@ -26811,7 +26889,7 @@ async function stepAgentType(ctx, step, total) {
|
|
|
26811
26889
|
continue;
|
|
26812
26890
|
}
|
|
26813
26891
|
const afterInstall = await inspectChiefAgent(selected);
|
|
26814
|
-
if (afterInstall.readiness === "ready")
|
|
26892
|
+
if (afterInstall.readiness === "ready" || hasUnsupportedAuthProbe(afterInstall))
|
|
26815
26893
|
continue;
|
|
26816
26894
|
if (afterInstall.readiness === "unavailable") {
|
|
26817
26895
|
log2.warn("The CLI is still unavailable. Check your PATH, open a new terminal if needed, and choose Recheck.");
|
|
@@ -26973,7 +27051,7 @@ var init_container_step = __esm(() => {
|
|
|
26973
27051
|
});
|
|
26974
27052
|
|
|
26975
27053
|
// src/setup/metric-step.ts
|
|
26976
|
-
import { isAbsolute as
|
|
27054
|
+
import { isAbsolute as isAbsolute26 } from "node:path";
|
|
26977
27055
|
async function text13(message, initialValue, validate) {
|
|
26978
27056
|
const value = await text11({
|
|
26979
27057
|
message: `${message} (:back goes back)`,
|
|
@@ -27057,7 +27135,7 @@ async function stepMetrics(ctx) {
|
|
|
27057
27135
|
draft.token_env = token;
|
|
27058
27136
|
} else {
|
|
27059
27137
|
const file = await text13("Repository-relative JSON file", old?.file ?? "metrics/revenue.json", (value) => {
|
|
27060
|
-
if (!value || value.length > 2000 ||
|
|
27138
|
+
if (!value || value.length > 2000 || isAbsolute26(value) || /^[A-Za-z]:/.test(value) || value.startsWith("\\") || value.split(/[\\/]/).includes(".."))
|
|
27061
27139
|
return "Use a relative file inside the repository, without ..";
|
|
27062
27140
|
});
|
|
27063
27141
|
if (navigated2(file))
|
|
@@ -28877,8 +28955,10 @@ async function setup(options = {}) {
|
|
|
28877
28955
|
const existing = globalSettings.config;
|
|
28878
28956
|
if (existing.linear?.api_key)
|
|
28879
28957
|
ctx.linear = { apiKey: existing.linear.api_key };
|
|
28880
|
-
|
|
28881
|
-
|
|
28958
|
+
if (hasProject) {
|
|
28959
|
+
ctx.agentType = existing.agent?.type;
|
|
28960
|
+
ctx.agentModel = existing.agent?.model;
|
|
28961
|
+
}
|
|
28882
28962
|
ctx.chief = existing.chief;
|
|
28883
28963
|
let replaceInvalidProject = false;
|
|
28884
28964
|
if (hasProject) {
|
|
@@ -28888,6 +28968,12 @@ async function setup(options = {}) {
|
|
|
28888
28968
|
ctx.verifyCommand = existing?.verify?.command;
|
|
28889
28969
|
ctx.task = existing?.task;
|
|
28890
28970
|
ctx.chief = mergeChiefConfig(ctx.chief, existing?.chief);
|
|
28971
|
+
if (existing?.agent?.type) {
|
|
28972
|
+
if (ctx.agentType !== existing.agent.type)
|
|
28973
|
+
delete ctx.agentModel;
|
|
28974
|
+
ctx.agentType = existing.agent.type;
|
|
28975
|
+
ctx.agentModel = existing.agent.model ?? ctx.agentModel;
|
|
28976
|
+
}
|
|
28891
28977
|
} catch (error) {
|
|
28892
28978
|
if (error instanceof TeamConfigMigrationError)
|
|
28893
28979
|
throw error;
|
|
@@ -28895,6 +28981,11 @@ async function setup(options = {}) {
|
|
|
28895
28981
|
log2.warn("Existing av.yaml cannot be read. Re-enter the workspace and verification settings to replace it.");
|
|
28896
28982
|
}
|
|
28897
28983
|
}
|
|
28984
|
+
const runtime = currentRuntimeIdentity(process.env);
|
|
28985
|
+
if (runtime) {
|
|
28986
|
+
ctx.agentType = runtime.actorType;
|
|
28987
|
+
delete ctx.agentModel;
|
|
28988
|
+
}
|
|
28898
28989
|
await runStepLoop(ctx);
|
|
28899
28990
|
const resolved = resolveContext(ctx);
|
|
28900
28991
|
if (!resolved.ok) {
|
|
@@ -28930,6 +29021,7 @@ var init_setup = __esm(() => {
|
|
|
28930
29021
|
init_github_step();
|
|
28931
29022
|
init_global_settings();
|
|
28932
29023
|
init_linear_step();
|
|
29024
|
+
init_noninteractive_runtime();
|
|
28933
29025
|
init_oma_step();
|
|
28934
29026
|
init_parallel_step();
|
|
28935
29027
|
init_preview();
|
|
@@ -28946,10 +29038,10 @@ var init_setup = __esm(() => {
|
|
|
28946
29038
|
|
|
28947
29039
|
// ../../packages/core/src/relay/credentials.ts
|
|
28948
29040
|
import { readFileSync as readFileSync14 } from "node:fs";
|
|
28949
|
-
import { homedir as
|
|
28950
|
-
import { join as
|
|
29041
|
+
import { homedir as homedir13 } from "node:os";
|
|
29042
|
+
import { join as join74 } from "node:path";
|
|
28951
29043
|
function defaultCredentialsPath() {
|
|
28952
|
-
return
|
|
29044
|
+
return join74(homedir13(), ".agent-valley", "credentials.json");
|
|
28953
29045
|
}
|
|
28954
29046
|
function validateRelayCredentials(value, binding, now = Date.now()) {
|
|
28955
29047
|
const result = credentialsSchema.safeParse(value);
|
|
@@ -53231,8 +53323,8 @@ async function startAvMcpHttp(api, options) {
|
|
|
53231
53323
|
|
|
53232
53324
|
// src/mission-api.ts
|
|
53233
53325
|
import { randomUUID as randomUUID22 } from "node:crypto";
|
|
53234
|
-
import { lstat as
|
|
53235
|
-
import { isAbsolute as
|
|
53326
|
+
import { lstat as lstat25, readdir as readdir14, realpath as realpath33 } from "node:fs/promises";
|
|
53327
|
+
import { isAbsolute as isAbsolute19, join as join55 } from "node:path";
|
|
53236
53328
|
|
|
53237
53329
|
// ../../packages/core/src/chief/reports.ts
|
|
53238
53330
|
init_zod();
|
|
@@ -54148,7 +54240,103 @@ async function cargoVerificationInputs(root, budget) {
|
|
|
54148
54240
|
// ../../packages/core/src/chief/verification-command.ts
|
|
54149
54241
|
import { spawn as spawn5 } from "node:child_process";
|
|
54150
54242
|
import { realpath as realpath12 } from "node:fs/promises";
|
|
54151
|
-
import { join as
|
|
54243
|
+
import { join as join18, relative as relative8, sep as sep8 } from "node:path";
|
|
54244
|
+
|
|
54245
|
+
// ../../packages/core/src/chief/cargo-toolchain.ts
|
|
54246
|
+
import { constants as constants7 } from "node:fs";
|
|
54247
|
+
import { access, lstat as lstat10, readdir as readdir5, readFile as readFile6, stat as stat2 } from "node:fs/promises";
|
|
54248
|
+
import { homedir as homedir5 } from "node:os";
|
|
54249
|
+
import { delimiter as delimiter2, isAbsolute as isAbsolute8, join as join17 } from "node:path";
|
|
54250
|
+
var channelName = /^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/;
|
|
54251
|
+
var hostTriple = /^[A-Za-z][A-Za-z0-9_]*(?:-[A-Za-z0-9_]+){2,5}$/;
|
|
54252
|
+
function toolchainChannel(source, legacy) {
|
|
54253
|
+
const lines = source.split(/\r?\n/).map((line) => line.trim());
|
|
54254
|
+
const meaningful = lines.filter((line) => line && !line.startsWith("#"));
|
|
54255
|
+
if (legacy && meaningful.length === 1 && channelName.test(meaningful[0] ?? ""))
|
|
54256
|
+
return meaningful[0];
|
|
54257
|
+
let inToolchain = false;
|
|
54258
|
+
let seenToolchain = false;
|
|
54259
|
+
let channel;
|
|
54260
|
+
for (const line of meaningful) {
|
|
54261
|
+
const section = /^\[([^\]]+)\]\s*(?:#.*)?$/.exec(line);
|
|
54262
|
+
if (section) {
|
|
54263
|
+
inToolchain = section[1] === "toolchain";
|
|
54264
|
+
if (inToolchain && seenToolchain)
|
|
54265
|
+
return;
|
|
54266
|
+
if (inToolchain)
|
|
54267
|
+
seenToolchain = true;
|
|
54268
|
+
} else if (inToolchain && /^path\s*=/.test(line))
|
|
54269
|
+
return;
|
|
54270
|
+
else if (inToolchain && /^channel\s*=/.test(line)) {
|
|
54271
|
+
if (channel !== undefined)
|
|
54272
|
+
return;
|
|
54273
|
+
const match = /^channel\s*=\s*(["'])([A-Za-z0-9][A-Za-z0-9._-]{0,127})\1\s*(?:#.*)?$/.exec(line);
|
|
54274
|
+
if (!match)
|
|
54275
|
+
return;
|
|
54276
|
+
channel = match[2];
|
|
54277
|
+
}
|
|
54278
|
+
}
|
|
54279
|
+
return channel;
|
|
54280
|
+
}
|
|
54281
|
+
async function projectChannel(root) {
|
|
54282
|
+
for (const name of ["rust-toolchain", "rust-toolchain.toml"]) {
|
|
54283
|
+
try {
|
|
54284
|
+
const path = join17(root, name);
|
|
54285
|
+
const metadata = await lstat10(path);
|
|
54286
|
+
if (!metadata.isFile() || metadata.size > 16384)
|
|
54287
|
+
return;
|
|
54288
|
+
return toolchainChannel(await readFile6(path, "utf8"), name === "rust-toolchain");
|
|
54289
|
+
} catch (error) {
|
|
54290
|
+
if (error.code !== "ENOENT")
|
|
54291
|
+
return;
|
|
54292
|
+
}
|
|
54293
|
+
}
|
|
54294
|
+
return;
|
|
54295
|
+
}
|
|
54296
|
+
async function executable(path) {
|
|
54297
|
+
try {
|
|
54298
|
+
if (!(await stat2(path)).isFile())
|
|
54299
|
+
return false;
|
|
54300
|
+
await access(path, constants7.X_OK);
|
|
54301
|
+
return true;
|
|
54302
|
+
} catch {
|
|
54303
|
+
return false;
|
|
54304
|
+
}
|
|
54305
|
+
}
|
|
54306
|
+
async function cargoVerificationEnvironment(root, source) {
|
|
54307
|
+
const env = { ...source, RUSTUP_AUTO_INSTALL: "0" };
|
|
54308
|
+
if (source.RUSTUP_TOOLCHAIN !== undefined)
|
|
54309
|
+
return env;
|
|
54310
|
+
const channel = await projectChannel(root);
|
|
54311
|
+
if (!channel)
|
|
54312
|
+
return env;
|
|
54313
|
+
const rustupHome = source.RUSTUP_HOME ?? join17(source.HOME ?? homedir5(), ".rustup");
|
|
54314
|
+
if (!isAbsolute8(rustupHome))
|
|
54315
|
+
return env;
|
|
54316
|
+
const directory = join17(rustupHome, "toolchains");
|
|
54317
|
+
let names;
|
|
54318
|
+
try {
|
|
54319
|
+
names = (await readdir5(directory, { withFileTypes: true })).filter((entry) => entry.isDirectory() || entry.isSymbolicLink()).map((entry) => entry.name).filter((name) => name === channel || name.startsWith(`${channel}-`) && hostTriple.test(name.slice(channel.length + 1)));
|
|
54320
|
+
} catch {
|
|
54321
|
+
return env;
|
|
54322
|
+
}
|
|
54323
|
+
const suffix = process.platform === "win32" ? ".exe" : "";
|
|
54324
|
+
const installed = await Promise.all(names.map(async (name) => {
|
|
54325
|
+
const bin = join17(directory, name, "bin");
|
|
54326
|
+
return await executable(join17(bin, `cargo${suffix}`)) && await executable(join17(bin, `rustc${suffix}`)) ? { name, bin } : undefined;
|
|
54327
|
+
}));
|
|
54328
|
+
const available = installed.filter((entry) => entry !== undefined);
|
|
54329
|
+
const selected = available.find((entry) => entry.name === channel) ?? (available.length === 1 ? available[0] : undefined);
|
|
54330
|
+
if (!selected)
|
|
54331
|
+
return env;
|
|
54332
|
+
return {
|
|
54333
|
+
...env,
|
|
54334
|
+
PATH: source.PATH ? `${selected.bin}${delimiter2}${source.PATH}` : selected.bin,
|
|
54335
|
+
RUSTUP_TOOLCHAIN: selected.name
|
|
54336
|
+
};
|
|
54337
|
+
}
|
|
54338
|
+
|
|
54339
|
+
// ../../packages/core/src/chief/verification-command.ts
|
|
54152
54340
|
var MAX_VERIFICATION_OUTPUT_BYTES = 1048576;
|
|
54153
54341
|
async function joinVerificationGroup(pid, detached) {
|
|
54154
54342
|
if (!pid || !detached)
|
|
@@ -54183,8 +54371,8 @@ async function verificationCommandInputs(root, program, args, budget) {
|
|
|
54183
54371
|
return cargoVerificationInputs(root, budget);
|
|
54184
54372
|
const names = verificationCommandTestPaths(program, args);
|
|
54185
54373
|
if (program === "node" && args[0] === "node_modules/vitest/vitest.mjs") {
|
|
54186
|
-
const launcher = await realpath12(
|
|
54187
|
-
if (!launcher.startsWith(`${
|
|
54374
|
+
const launcher = await realpath12(join18(root, args[0]));
|
|
54375
|
+
if (!launcher.startsWith(`${join18(root, "node_modules")}${sep8}`))
|
|
54188
54376
|
throw new Error("Installed Vitest launcher escapes this worktree. Install its dependency inside node_modules.");
|
|
54189
54377
|
names.unshift(relative8(root, launcher));
|
|
54190
54378
|
}
|
|
@@ -54195,94 +54383,102 @@ async function verificationCommandInputs(root, program, args, budget) {
|
|
|
54195
54383
|
}
|
|
54196
54384
|
return inputs;
|
|
54197
54385
|
}
|
|
54198
|
-
var executeVerificationCommand = (program, args, options) =>
|
|
54199
|
-
if (!safeVerificationCommand(program, args))
|
|
54200
|
-
|
|
54201
|
-
|
|
54202
|
-
|
|
54203
|
-
|
|
54204
|
-
|
|
54205
|
-
|
|
54206
|
-
|
|
54207
|
-
|
|
54208
|
-
|
|
54209
|
-
for (const key of [
|
|
54210
|
-
"GIT_DIR",
|
|
54211
|
-
"GIT_WORK_TREE",
|
|
54212
|
-
"GIT_COMMON_DIR",
|
|
54213
|
-
"GIT_INDEX_FILE",
|
|
54214
|
-
"GIT_OBJECT_DIRECTORY",
|
|
54215
|
-
"GIT_ALTERNATE_OBJECT_DIRECTORIES"
|
|
54216
|
-
])
|
|
54217
|
-
delete env[key];
|
|
54218
|
-
Object.assign(env, { GIT_OPTIONAL_LOCKS: "0", GIT_NO_LAZY_FETCH: "1", GIT_LITERAL_PATHSPECS: "1" });
|
|
54219
|
-
if (program === "cargo")
|
|
54220
|
-
Object.assign(env, { CARGO_NET_OFFLINE: "true", CARGO_TERM_COLOR: "never" });
|
|
54221
|
-
const argv = program === "git" ? ["-c", "core.fsmonitor=false", "-c", "diff.external=", "-c", "core.pager=cat", "--no-pager", ...args] : args;
|
|
54222
|
-
const child = spawn5(program, argv, {
|
|
54223
|
-
cwd: options.cwd,
|
|
54224
|
-
detached,
|
|
54225
|
-
shell: false,
|
|
54226
|
-
stdio: ["ignore", "pipe", "pipe"],
|
|
54227
|
-
env
|
|
54228
|
-
});
|
|
54229
|
-
let stdout = "";
|
|
54230
|
-
let stderr = "";
|
|
54231
|
-
let bytes = 0;
|
|
54232
|
-
let failure;
|
|
54233
|
-
const stop = (error) => {
|
|
54234
|
-
failure ??= error;
|
|
54235
|
-
if (detached && child.pid) {
|
|
54236
|
-
try {
|
|
54237
|
-
process.kill(-child.pid, "SIGKILL");
|
|
54238
|
-
return;
|
|
54239
|
-
} catch {}
|
|
54386
|
+
var executeVerificationCommand = async (program, args, options) => {
|
|
54387
|
+
if (!safeVerificationCommand(program, args))
|
|
54388
|
+
throw new Error("Unsupported automatic verification command. Use explicit tests or read-only Git argv.");
|
|
54389
|
+
if (options.signal?.aborted)
|
|
54390
|
+
throw new Error("Verification interrupted. Resume the mission to rerun its evidence checks.");
|
|
54391
|
+
const startedAt = performance.now();
|
|
54392
|
+
const env = program === "cargo" ? await cargoVerificationEnvironment(options.cwd, process.env) : { ...process.env };
|
|
54393
|
+
return new Promise((resolveCommand, rejectCommand) => {
|
|
54394
|
+
if (options.signal?.aborted) {
|
|
54395
|
+
rejectCommand(new Error("Verification interrupted. Resume the mission to rerun its evidence checks."));
|
|
54396
|
+
return;
|
|
54240
54397
|
}
|
|
54241
|
-
|
|
54242
|
-
|
|
54243
|
-
|
|
54244
|
-
const timer = setTimeout(() => stop(new Error("Verification timed out. Repair the test or increase its bounded timeout.")), options.timeoutMs);
|
|
54245
|
-
timer.unref();
|
|
54246
|
-
const capture = (chunk, stream) => {
|
|
54247
|
-
bytes += chunk.length;
|
|
54248
|
-
if (bytes > options.maxOutputBytes) {
|
|
54249
|
-
stop(new Error("Verification output exceeds its evidence budget. Reduce noisy test output and retry."));
|
|
54398
|
+
const timeoutMs = options.timeoutMs - (performance.now() - startedAt);
|
|
54399
|
+
if (timeoutMs <= 0) {
|
|
54400
|
+
rejectCommand(new Error("Verification timed out. Repair the test or increase its bounded timeout."));
|
|
54250
54401
|
return;
|
|
54251
54402
|
}
|
|
54252
|
-
|
|
54253
|
-
|
|
54254
|
-
|
|
54255
|
-
|
|
54256
|
-
|
|
54257
|
-
|
|
54258
|
-
|
|
54259
|
-
|
|
54260
|
-
|
|
54261
|
-
|
|
54262
|
-
|
|
54263
|
-
|
|
54264
|
-
|
|
54265
|
-
|
|
54266
|
-
|
|
54267
|
-
|
|
54403
|
+
const detached = process.platform !== "win32";
|
|
54404
|
+
for (const key of [
|
|
54405
|
+
"GIT_DIR",
|
|
54406
|
+
"GIT_WORK_TREE",
|
|
54407
|
+
"GIT_COMMON_DIR",
|
|
54408
|
+
"GIT_INDEX_FILE",
|
|
54409
|
+
"GIT_OBJECT_DIRECTORY",
|
|
54410
|
+
"GIT_ALTERNATE_OBJECT_DIRECTORIES"
|
|
54411
|
+
])
|
|
54412
|
+
delete env[key];
|
|
54413
|
+
Object.assign(env, { GIT_OPTIONAL_LOCKS: "0", GIT_NO_LAZY_FETCH: "1", GIT_LITERAL_PATHSPECS: "1" });
|
|
54414
|
+
if (program === "cargo")
|
|
54415
|
+
Object.assign(env, { CARGO_NET_OFFLINE: "true", CARGO_TERM_COLOR: "never" });
|
|
54416
|
+
const argv = program === "git" ? ["-c", "core.fsmonitor=false", "-c", "diff.external=", "-c", "core.pager=cat", "--no-pager", ...args] : args;
|
|
54417
|
+
const child = spawn5(program, argv, {
|
|
54418
|
+
cwd: options.cwd,
|
|
54419
|
+
detached,
|
|
54420
|
+
shell: false,
|
|
54421
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
54422
|
+
env
|
|
54423
|
+
});
|
|
54424
|
+
let stdout = "";
|
|
54425
|
+
let stderr = "";
|
|
54426
|
+
let bytes = 0;
|
|
54427
|
+
let failure;
|
|
54428
|
+
const stop = (error) => {
|
|
54429
|
+
failure ??= error;
|
|
54430
|
+
if (detached && child.pid) {
|
|
54431
|
+
try {
|
|
54432
|
+
process.kill(-child.pid, "SIGKILL");
|
|
54433
|
+
return;
|
|
54434
|
+
} catch {}
|
|
54435
|
+
}
|
|
54436
|
+
child.kill("SIGKILL");
|
|
54437
|
+
};
|
|
54438
|
+
const abort = () => stop(new Error("Verification interrupted. Resume the mission to rerun evidence checks."));
|
|
54439
|
+
const timer = setTimeout(() => stop(new Error("Verification timed out. Repair the test or increase its bounded timeout.")), timeoutMs);
|
|
54440
|
+
timer.unref();
|
|
54441
|
+
const capture = (chunk, stream) => {
|
|
54442
|
+
bytes += chunk.length;
|
|
54443
|
+
if (bytes > options.maxOutputBytes) {
|
|
54444
|
+
stop(new Error("Verification output exceeds its evidence budget. Reduce noisy test output and retry."));
|
|
54445
|
+
return;
|
|
54446
|
+
}
|
|
54447
|
+
if (stream === "stdout")
|
|
54448
|
+
stdout += chunk.toString("utf8");
|
|
54449
|
+
else
|
|
54450
|
+
stderr += chunk.toString("utf8");
|
|
54451
|
+
};
|
|
54452
|
+
child.stdout?.on("data", (chunk) => capture(chunk, "stdout"));
|
|
54453
|
+
child.stderr?.on("data", (chunk) => capture(chunk, "stderr"));
|
|
54454
|
+
child.once("error", (error) => {
|
|
54455
|
+
failure = error;
|
|
54456
|
+
});
|
|
54457
|
+
child.once("close", async (exitCode) => {
|
|
54458
|
+
clearTimeout(timer);
|
|
54459
|
+
try {
|
|
54460
|
+
await joinVerificationGroup(child.pid, detached);
|
|
54461
|
+
} catch (error) {
|
|
54462
|
+
failure ??= error instanceof Error ? error : new Error("Cannot join verification child processes.");
|
|
54463
|
+
}
|
|
54464
|
+
options.signal?.removeEventListener("abort", abort);
|
|
54465
|
+
if (failure)
|
|
54466
|
+
rejectCommand(failure);
|
|
54467
|
+
else
|
|
54468
|
+
resolveCommand({ exitCode, stdout, stderr });
|
|
54469
|
+
});
|
|
54470
|
+
options.signal?.addEventListener("abort", abort, { once: true });
|
|
54471
|
+
if (options.signal?.aborted)
|
|
54472
|
+
abort();
|
|
54473
|
+
if (child.pid && options.onSpawned) {
|
|
54474
|
+
try {
|
|
54475
|
+
options.onSpawned(child.pid, detached);
|
|
54476
|
+
} catch (error) {
|
|
54477
|
+
stop(error instanceof Error ? error : new Error("Cannot register automatic verification process."));
|
|
54478
|
+
}
|
|
54268
54479
|
}
|
|
54269
|
-
options.signal?.removeEventListener("abort", abort);
|
|
54270
|
-
if (failure)
|
|
54271
|
-
rejectCommand(failure);
|
|
54272
|
-
else
|
|
54273
|
-
resolveCommand({ exitCode, stdout, stderr });
|
|
54274
54480
|
});
|
|
54275
|
-
|
|
54276
|
-
if (options.signal?.aborted)
|
|
54277
|
-
abort();
|
|
54278
|
-
if (child.pid && options.onSpawned) {
|
|
54279
|
-
try {
|
|
54280
|
-
options.onSpawned(child.pid, detached);
|
|
54281
|
-
} catch (error) {
|
|
54282
|
-
stop(error instanceof Error ? error : new Error("Cannot register automatic verification process."));
|
|
54283
|
-
}
|
|
54284
|
-
}
|
|
54285
|
-
});
|
|
54481
|
+
};
|
|
54286
54482
|
|
|
54287
54483
|
// ../../packages/core/src/chief/verification.ts
|
|
54288
54484
|
var digest4 = string2().regex(/^[a-f0-9]{64}$/);
|
|
@@ -54476,6 +54672,150 @@ function validateFinalReview(review, mission) {
|
|
|
54476
54672
|
return review;
|
|
54477
54673
|
}
|
|
54478
54674
|
|
|
54675
|
+
// ../../packages/core/src/chief/actor-health.ts
|
|
54676
|
+
var ACTOR_COOLDOWN_BASE_MS = 15 * 60000;
|
|
54677
|
+
var ACTOR_COOLDOWN_MAX_MS = 6 * 60 * 60000;
|
|
54678
|
+
var ACTOR_PROBE_GRACE_MS = 60000;
|
|
54679
|
+
var healthStages = new Set(["work", "review", "gate-review", "final-review"]);
|
|
54680
|
+
var key = (route) => JSON.stringify([route.actorType, route.model ?? null]);
|
|
54681
|
+
function frameworkFailure(reason) {
|
|
54682
|
+
return !!reason && /OMA completion evidence failed|Coordinator process ended before usage could be reconciled|Order interrupted\. Resume the saved mission|Operator stopped the order|Mission interrupted\.|OS-owned service is shutting down|\b(?:ENOENT|EACCES|ENOSPC)\b|command not found|verification command|verifyCommand/i.test(reason);
|
|
54683
|
+
}
|
|
54684
|
+
function nativeOutcome(run) {
|
|
54685
|
+
if (run.nativeOutcome === "cancelled")
|
|
54686
|
+
return;
|
|
54687
|
+
if (run.nativeOutcome)
|
|
54688
|
+
return run.nativeOutcome;
|
|
54689
|
+
if (run.outcome !== "failed")
|
|
54690
|
+
return "passed";
|
|
54691
|
+
if (run.executionState === "settled" && !frameworkFailure(run.evidence))
|
|
54692
|
+
return "failed";
|
|
54693
|
+
return;
|
|
54694
|
+
}
|
|
54695
|
+
function cooldownMs(failures) {
|
|
54696
|
+
return Math.min(ACTOR_COOLDOWN_MAX_MS, ACTOR_COOLDOWN_BASE_MS * 2 ** Math.min(5, failures - 1));
|
|
54697
|
+
}
|
|
54698
|
+
function cooldownUntil(health) {
|
|
54699
|
+
return Math.max(Date.parse(health.lastOutcomeAt) + cooldownMs(health.consecutiveFailures), Date.parse(health.cooldownUntil ?? "") || 0);
|
|
54700
|
+
}
|
|
54701
|
+
function aggregateProviderHealth(mission) {
|
|
54702
|
+
const evidence = new Map;
|
|
54703
|
+
const seedTimes = new Map;
|
|
54704
|
+
for (const route of mission.operations?.routingEvidence ?? [])
|
|
54705
|
+
if (route.providerHealth) {
|
|
54706
|
+
evidence.set(key(route), {
|
|
54707
|
+
actorType: route.actorType,
|
|
54708
|
+
...route.model ? { model: route.model } : {},
|
|
54709
|
+
providerHealth: { ...route.providerHealth }
|
|
54710
|
+
});
|
|
54711
|
+
seedTimes.set(key(route), Date.parse(route.providerHealth.lastOutcomeAt));
|
|
54712
|
+
}
|
|
54713
|
+
const cancelled = cancelledWorkRunProofs(mission);
|
|
54714
|
+
const runs = (mission.operations?.runs ?? []).filter((run) => healthStages.has(run.stage) && !cancelled.has(run.runId)).filter((run) => run.executionState !== "unknown" && run.executionState !== "running").filter((run) => {
|
|
54715
|
+
const start = Date.parse(run.startedAt);
|
|
54716
|
+
const finish = Date.parse(run.finishedAt ?? "");
|
|
54717
|
+
return Number.isFinite(start) && Number.isFinite(finish) && finish >= start;
|
|
54718
|
+
}).sort((a, b) => Date.parse(a.finishedAt ?? "") - Date.parse(b.finishedAt ?? ""));
|
|
54719
|
+
for (const run of runs) {
|
|
54720
|
+
const outcome = nativeOutcome(run);
|
|
54721
|
+
if (!outcome || !run.finishedAt)
|
|
54722
|
+
continue;
|
|
54723
|
+
const previous = evidence.get(key(run))?.providerHealth;
|
|
54724
|
+
if (Date.parse(run.finishedAt) <= (seedTimes.get(key(run)) ?? -Infinity))
|
|
54725
|
+
continue;
|
|
54726
|
+
const failures = outcome === "failed" ? (previous?.consecutiveFailures ?? 0) + 1 : 0;
|
|
54727
|
+
evidence.set(key(run), {
|
|
54728
|
+
actorType: run.actorType,
|
|
54729
|
+
...run.model ? { model: run.model } : {},
|
|
54730
|
+
providerHealth: {
|
|
54731
|
+
consecutiveFailures: failures,
|
|
54732
|
+
lastOutcomeAt: run.finishedAt,
|
|
54733
|
+
...failures ? { cooldownUntil: new Date(Date.parse(run.finishedAt) + cooldownMs(failures)).toISOString() } : {}
|
|
54734
|
+
}
|
|
54735
|
+
});
|
|
54736
|
+
}
|
|
54737
|
+
return [...evidence.values()];
|
|
54738
|
+
}
|
|
54739
|
+
function actorRouteHealth(mission, requested, now = Date.now()) {
|
|
54740
|
+
const health = aggregateProviderHealth(mission).find((route) => key(route) === key(requested))?.providerHealth;
|
|
54741
|
+
const consecutiveFailures = health?.consecutiveFailures ?? 0;
|
|
54742
|
+
const base = { consecutiveFailures };
|
|
54743
|
+
const runs = (mission.operations?.runs ?? []).filter((run) => healthStages.has(run.stage) && key(run) === key(requested));
|
|
54744
|
+
const uncertain = runs.some((run) => {
|
|
54745
|
+
const start = Date.parse(run.startedAt);
|
|
54746
|
+
const finish = Date.parse(run.finishedAt ?? "");
|
|
54747
|
+
return run.executionState === "unknown" || !Number.isFinite(start) || run.executionState !== "running" && (!Number.isFinite(finish) || finish < start) || run.executionState === "running" && run.finishedAt !== null;
|
|
54748
|
+
});
|
|
54749
|
+
if (!Number.isFinite(now) || uncertain)
|
|
54750
|
+
return {
|
|
54751
|
+
...base,
|
|
54752
|
+
state: "unknown",
|
|
54753
|
+
reason: "Actor execution outcome is uncertain. Reconcile the saved run before retrying."
|
|
54754
|
+
};
|
|
54755
|
+
const active = runs.filter((run) => run.executionState === "running");
|
|
54756
|
+
if (consecutiveFailures && active.length) {
|
|
54757
|
+
const timeout = Math.max(0, mission.timeoutSec) * 1000;
|
|
54758
|
+
const retry = Math.max(now + ACTOR_PROBE_GRACE_MS, ...active.map((run) => Date.parse(run.startedAt) + timeout + ACTOR_PROBE_GRACE_MS));
|
|
54759
|
+
return {
|
|
54760
|
+
...base,
|
|
54761
|
+
state: "probe-in-flight",
|
|
54762
|
+
retryAt: new Date(retry).toISOString(),
|
|
54763
|
+
reason: "An Actor recovery probe is already running. Wait for its terminal result before another probe."
|
|
54764
|
+
};
|
|
54765
|
+
}
|
|
54766
|
+
if (health && consecutiveFailures && now < cooldownUntil(health)) {
|
|
54767
|
+
const retryAt = new Date(cooldownUntil(health)).toISOString();
|
|
54768
|
+
return {
|
|
54769
|
+
...base,
|
|
54770
|
+
state: "cooling",
|
|
54771
|
+
retryAt,
|
|
54772
|
+
reason: `Actor route has ${consecutiveFailures} consecutive execution failures; cooldown ends at ${retryAt}.`
|
|
54773
|
+
};
|
|
54774
|
+
}
|
|
54775
|
+
return {
|
|
54776
|
+
...base,
|
|
54777
|
+
state: "ready",
|
|
54778
|
+
reason: consecutiveFailures ? "Actor cooldown elapsed; allow one recovery probe." : "Actor route has no unresolved execution failure cooldown."
|
|
54779
|
+
};
|
|
54780
|
+
}
|
|
54781
|
+
|
|
54782
|
+
// ../../packages/core/src/chief/actor-availability.ts
|
|
54783
|
+
init_execution();
|
|
54784
|
+
|
|
54785
|
+
class ActorCooldown extends MissionPause {
|
|
54786
|
+
routes;
|
|
54787
|
+
constructor(message, nextRunAt, routes) {
|
|
54788
|
+
super(message, "actor-cooldown", nextRunAt);
|
|
54789
|
+
this.routes = routes;
|
|
54790
|
+
}
|
|
54791
|
+
}
|
|
54792
|
+
function availableActorRoutes(mission, candidates) {
|
|
54793
|
+
const inspected = candidates.map((route) => ({ route, health: actorRouteHealth(mission, route) }));
|
|
54794
|
+
const uncertain = inspected.find((entry) => entry.health.state === "unknown");
|
|
54795
|
+
if (uncertain)
|
|
54796
|
+
throw new MissionPause(uncertain.health.reason, "unknown-effect");
|
|
54797
|
+
const ready = inspected.filter((entry) => entry.health.state === "ready").map((entry) => entry.route);
|
|
54798
|
+
if (ready.length || !candidates.length)
|
|
54799
|
+
return ready;
|
|
54800
|
+
const next = inspected.flatMap(({ health }) => health.retryAt ? [health.retryAt] : []).sort((a, b) => Date.parse(a) - Date.parse(b))[0];
|
|
54801
|
+
throw new ActorCooldown(`All eligible Actor routes are cooling down or already probing. ${inspected.map(({ route, health }) => `${route.actorType}/${route.model ?? "native default"}: ${health.reason}`).join(" ")} The saved work and spent limits are retained.`, next, candidates.map(({ actorType, model }) => ({ actorType, model })));
|
|
54802
|
+
}
|
|
54803
|
+
function refreshActorCooldown(mission, error) {
|
|
54804
|
+
if (!(error instanceof ActorCooldown))
|
|
54805
|
+
return error;
|
|
54806
|
+
try {
|
|
54807
|
+
availableActorRoutes(mission, error.routes);
|
|
54808
|
+
return;
|
|
54809
|
+
} catch (current) {
|
|
54810
|
+
return current;
|
|
54811
|
+
}
|
|
54812
|
+
}
|
|
54813
|
+
function assertActorAvailable(mission, actor, stage) {
|
|
54814
|
+
if (!["work", "review", "gate-review", "final-review"].includes(stage))
|
|
54815
|
+
return;
|
|
54816
|
+
availableActorRoutes(mission, [{ actorType: actor.agentType, model: actor.model }]);
|
|
54817
|
+
}
|
|
54818
|
+
|
|
54479
54819
|
// ../../packages/core/src/chief/bounded-work-routing.ts
|
|
54480
54820
|
import { createHash as createHash13 } from "node:crypto";
|
|
54481
54821
|
function repairDecision(mission, taskId, taskRuns) {
|
|
@@ -54569,7 +54909,7 @@ function routeEvidence(mission) {
|
|
|
54569
54909
|
totalCostUsd: 0,
|
|
54570
54910
|
successfulDeliverableCostUsd: null
|
|
54571
54911
|
};
|
|
54572
|
-
if (!cancelled.has(run.runId))
|
|
54912
|
+
if (!cancelled.has(run.runId) && run.nativeOutcome !== "cancelled")
|
|
54573
54913
|
item.samples += 1;
|
|
54574
54914
|
if (run.outcome === "passed")
|
|
54575
54915
|
item.successes += 1;
|
|
@@ -54577,6 +54917,19 @@ function routeEvidence(mission) {
|
|
|
54577
54917
|
item.successfulDeliverableCostUsd = item.successes && item.totalCostUsd !== null ? item.totalCostUsd / item.successes : null;
|
|
54578
54918
|
evidence.set(key, item);
|
|
54579
54919
|
}
|
|
54920
|
+
for (const health of aggregateProviderHealth(mission)) {
|
|
54921
|
+
if (!health.providerHealth.consecutiveFailures && !evidence.get(routeKey(health))?.providerHealth)
|
|
54922
|
+
continue;
|
|
54923
|
+
const item = evidence.get(routeKey(health)) ?? {
|
|
54924
|
+
actorType: health.actorType,
|
|
54925
|
+
...health.model ? { model: health.model } : {},
|
|
54926
|
+
samples: 0,
|
|
54927
|
+
successes: 0,
|
|
54928
|
+
totalCostUsd: 0,
|
|
54929
|
+
successfulDeliverableCostUsd: null
|
|
54930
|
+
};
|
|
54931
|
+
evidence.set(routeKey(health), { ...item, providerHealth: health.providerHealth });
|
|
54932
|
+
}
|
|
54580
54933
|
return [...evidence.values()];
|
|
54581
54934
|
}
|
|
54582
54935
|
function price2(candidate) {
|
|
@@ -54606,14 +54959,16 @@ function selectWorkActor(mission, actor, taskId, compatibleRoutes) {
|
|
|
54606
54959
|
if (!routing || actor.id === mission.chiefId || !mission.availableAgents && (actor.model || compatibleRoutes)) {
|
|
54607
54960
|
if (compatibleRoutes && !compatibleRoutes.has(routeKey({ actorType: actor.agentType, model: actor.model })))
|
|
54608
54961
|
throw new Error("Skill compatibility required: the configured Actor/model has no current passing evidence. Refresh oma.skill_compatibility.report_path in av.yaml; explicit Actors are not rerouted.");
|
|
54962
|
+
availableActorRoutes(mission, [{ actorType: actor.agentType, model: actor.model }]);
|
|
54609
54963
|
return { actor, reason: "Preserved the configured Actor and explicit model." };
|
|
54610
54964
|
}
|
|
54611
54965
|
const candidates = readyWorkCandidates(mission);
|
|
54612
54966
|
if (!candidates.length)
|
|
54613
54967
|
throw new Error("No configured work routing candidate is ready. Install/login a candidate CLI or update chief.routing.candidates in av.yaml.");
|
|
54614
|
-
const
|
|
54615
|
-
if (!
|
|
54968
|
+
const compatiblePool = compatibleRoutes ? candidates.filter((candidate) => compatibleRoutes.has(routeKey(candidate))) : candidates;
|
|
54969
|
+
if (!compatiblePool.length)
|
|
54616
54970
|
throw new Error("Skill compatibility required: no ready work candidate has current passing installed evidence. Refresh oma.skill_compatibility.report_path in av.yaml with explicit models before retrying.");
|
|
54971
|
+
const compatible = availableActorRoutes(mission, compatiblePool);
|
|
54617
54972
|
const evidence = routeEvidence(mission);
|
|
54618
54973
|
const eligible = compatible.filter((candidate) => {
|
|
54619
54974
|
const observed = evidence.find((item) => routeKey(item) === routeKey(candidate));
|
|
@@ -54623,7 +54978,7 @@ function selectWorkActor(mission, actor, taskId, compatibleRoutes) {
|
|
|
54623
54978
|
const measured = qualified.at(0);
|
|
54624
54979
|
const initial = measured?.candidate ?? [...eligible].sort((a, b) => price2(a) - price2(b)).at(0);
|
|
54625
54980
|
const cancelled = cancelledWorkRunProofs(mission);
|
|
54626
|
-
const taskRuns = (mission.operations?.runs ?? []).filter((run) => run.stage === "work" && run.taskId === taskId && !cancelled.has(run.runId));
|
|
54981
|
+
const taskRuns = (mission.operations?.runs ?? []).filter((run) => run.stage === "work" && run.taskId === taskId && !cancelled.has(run.runId) && run.nativeOutcome !== "cancelled");
|
|
54627
54982
|
if (hasUnreviewedRoutingProbe(mission, taskId, taskRuns))
|
|
54628
54983
|
throw new Error("This task has an unreviewed bounded routing probe. Resume its retained review or obtain a later Chief repair decision before dispatching more work.");
|
|
54629
54984
|
const failed = new Set;
|
|
@@ -54715,6 +55070,10 @@ function operationsReportLines(mission) {
|
|
|
54715
55070
|
...evidence.metricAssessments.map((metric) => `${metric.criterion}: ${metric.passed ? "기록된 측정값 기준 통과" : "미충족"}; ${metric.evidence}`),
|
|
54716
55071
|
"비용은 실제 청구액이 아닙니다. 미보고 cache·reasoning·하위 agent token 및 구독 요금은 포함하지 않습니다.",
|
|
54717
55072
|
...evidence.routeQuality.map((route) => `${route.actorType}/${route.model ?? "CLI 기본값"}: 실제 work ${route.samples}회, 독립 리뷰 통과 ${route.successes}회, 성공 산출물당 누적 비용 추정 ${route.successfulDeliverableCostUsd === null ? "미확인" : `USD ${route.successfulDeliverableCostUsd.toFixed(6)}`}`),
|
|
55073
|
+
...evidence.routeQuality.filter((route) => route.providerHealth?.consecutiveFailures).map((route) => {
|
|
55074
|
+
const health = actorRouteHealth(mission, route);
|
|
55075
|
+
return `${route.actorType}/${route.model ?? "CLI 기본값"}: 연속 실행 실패 ${health.consecutiveFailures}회 / 상태 ${health.state} / ${health.retryAt ? `다음 확인 ${health.retryAt}` : "쿨다운 만료, 단일 재시험 가능"}`;
|
|
55076
|
+
}),
|
|
54718
55077
|
...evidence.recentRuns.filter((run) => run.stage === "work").map((run) => `${run.taskId ?? run.runId}: 실제 ${run.actorType}/${run.model ?? "CLI 기본값"}, 보고 모델 ${run.actualModel ?? "미확인"}, ${run.elapsedMs === null ? "소요시간 미확인" : `${run.elapsedMs}ms`}, ${run.outcome}; ${run.routingReason ?? "지정된 Actor"}`),
|
|
54719
55078
|
...evidence.crossVendorReviews.map((review) => `${review.taskId}${review.gateId ? ` [${review.gateId}]` : ""}: 작업 ${review.workerActorType} → 리뷰 ${review.reviewerActorType}, ${review.crossVendor ? "다른 vendor" : "동일 vendor fallback"}, 결과 ${review.outcome ?? "배정만 기록"}; ${review.reason}`),
|
|
54720
55079
|
...mission.organizationContext ? [
|
|
@@ -55104,9 +55463,9 @@ function renderReport(mission) {
|
|
|
55104
55463
|
|
|
55105
55464
|
// ../../packages/core/src/chief/store.ts
|
|
55106
55465
|
init_atomic_json();
|
|
55107
|
-
import { constants as
|
|
55108
|
-
import { mkdir as mkdir11, open as open11, readdir as
|
|
55109
|
-
import { join as
|
|
55466
|
+
import { constants as constants10 } from "node:fs";
|
|
55467
|
+
import { mkdir as mkdir11, open as open11, readdir as readdir8, readFile as readFile9 } from "node:fs/promises";
|
|
55468
|
+
import { join as join23 } from "node:path";
|
|
55110
55469
|
init_execution();
|
|
55111
55470
|
|
|
55112
55471
|
// ../../packages/core/src/domain/dag.ts
|
|
@@ -55304,17 +55663,17 @@ function parseSupervisionResponse(source, mission) {
|
|
|
55304
55663
|
init_mission_state_schema();
|
|
55305
55664
|
init_mission_state_schema();
|
|
55306
55665
|
init_zod();
|
|
55307
|
-
import { isAbsolute as
|
|
55666
|
+
import { isAbsolute as isAbsolute11 } from "node:path";
|
|
55308
55667
|
|
|
55309
55668
|
// ../../packages/core/src/chief/capture.ts
|
|
55310
55669
|
import { spawn as spawn7 } from "node:child_process";
|
|
55311
55670
|
import { createHash as createHash14, randomUUID as randomUUID11 } from "node:crypto";
|
|
55312
|
-
import { chmod as chmod4, mkdir as mkdir9, readFile as
|
|
55313
|
-
import { join as
|
|
55671
|
+
import { chmod as chmod4, mkdir as mkdir9, readFile as readFile8, writeFile as writeFile4 } from "node:fs/promises";
|
|
55672
|
+
import { join as join20 } from "node:path";
|
|
55314
55673
|
|
|
55315
55674
|
// ../../packages/core/src/chief/capture-mcp.ts
|
|
55316
|
-
import { readFile as
|
|
55317
|
-
import { join as
|
|
55675
|
+
import { readFile as readFile7 } from "node:fs/promises";
|
|
55676
|
+
import { join as join19 } from "node:path";
|
|
55318
55677
|
|
|
55319
55678
|
// ../../node_modules/.bun/@modelcontextprotocol+client@2.3.0/node_modules/@modelcontextprotocol/client/dist/chunk-Br0eD_fh.mjs
|
|
55320
55679
|
var __create3 = Object.create;
|
|
@@ -69681,7 +70040,7 @@ console.log(${JSON.stringify(prefix)} + JSON.stringify({base64: bytes.toString("
|
|
|
69681
70040
|
async function connectAsideBrowser(repository, policy) {
|
|
69682
70041
|
let config = { command: "aside", args: ["mcp"] };
|
|
69683
70042
|
try {
|
|
69684
|
-
const raw = JSON.parse(await
|
|
70043
|
+
const raw = JSON.parse(await readFile7(join19(repository, ".mcp.json"), "utf8"));
|
|
69685
70044
|
if (raw.mcpServers?.aside)
|
|
69686
70045
|
config = serverSchema.parse(raw.mcpServers.aside);
|
|
69687
70046
|
} catch (error) {
|
|
@@ -69782,7 +70141,7 @@ class MissionCapture {
|
|
|
69782
70141
|
capturePolicySchema.parse(policy);
|
|
69783
70142
|
if (!/^[a-zA-Z0-9][a-zA-Z0-9_-]{0,127}$/.test(missionId))
|
|
69784
70143
|
throw new Error("Use a safe mission ID for capture artifacts.");
|
|
69785
|
-
this.directory =
|
|
70144
|
+
this.directory = join20(repository, ".agent-valley/captures", missionId, randomUUID11());
|
|
69786
70145
|
this.deps = { connect: connectAsideBrowser, encode: encodeCaptureVideo, now: () => new Date, ...deps };
|
|
69787
70146
|
this.startedAt = this.deps.now().toISOString();
|
|
69788
70147
|
}
|
|
@@ -69817,10 +70176,10 @@ class MissionCapture {
|
|
|
69817
70176
|
}, this.policy.intervalMs);
|
|
69818
70177
|
}
|
|
69819
70178
|
async attachment(name, mimeType, bytes) {
|
|
69820
|
-
const path =
|
|
70179
|
+
const path = join20(this.directory, name);
|
|
69821
70180
|
if (bytes)
|
|
69822
70181
|
await writeFile4(path, bytes, { mode: 384 });
|
|
69823
|
-
const contents = bytes ?? await
|
|
70182
|
+
const contents = bytes ?? await readFile8(path);
|
|
69824
70183
|
if (!contents.length || contents.length > 200 * 1024 * 1024)
|
|
69825
70184
|
throw new Error("Capture artifact must contain bytes and be at most 200 MB.");
|
|
69826
70185
|
return {
|
|
@@ -69884,8 +70243,8 @@ duration ${duration}`;
|
|
|
69884
70243
|
`)}
|
|
69885
70244
|
file '${this.frames.at(-1)?.attachment.name}'
|
|
69886
70245
|
`;
|
|
69887
|
-
const manifestPath =
|
|
69888
|
-
const output =
|
|
70246
|
+
const manifestPath = join20(this.directory, "frames.txt");
|
|
70247
|
+
const output = join20(this.directory, "recording.mp4");
|
|
69889
70248
|
await writeFile4(manifestPath, concat, { mode: 384 });
|
|
69890
70249
|
await this.deps.encode(this.directory, manifestPath, output);
|
|
69891
70250
|
await chmod4(output, 384);
|
|
@@ -70168,15 +70527,15 @@ init_metric_source_policy();
|
|
|
70168
70527
|
// ../../packages/core/src/chief/oma-actor.ts
|
|
70169
70528
|
init_dist();
|
|
70170
70529
|
import { createHash as createHash16 } from "node:crypto";
|
|
70171
|
-
import { constants as
|
|
70172
|
-
import { open as open10, readdir as
|
|
70173
|
-
import { isAbsolute as
|
|
70530
|
+
import { constants as constants9 } from "node:fs";
|
|
70531
|
+
import { open as open10, readdir as readdir7, realpath as realpath14, stat as stat4 } from "node:fs/promises";
|
|
70532
|
+
import { isAbsolute as isAbsolute10, join as join22, relative as relative10, sep as sep10 } from "node:path";
|
|
70174
70533
|
|
|
70175
70534
|
// ../../packages/core/src/chief/skills.ts
|
|
70176
70535
|
init_dist();
|
|
70177
|
-
import { constants as
|
|
70178
|
-
import { lstat as
|
|
70179
|
-
import { isAbsolute as
|
|
70536
|
+
import { constants as constants8 } from "node:fs";
|
|
70537
|
+
import { lstat as lstat11, mkdir as mkdir10, open as open9, readdir as readdir6, realpath as realpath13, stat as stat3, writeFile as writeFile5 } from "node:fs/promises";
|
|
70538
|
+
import { isAbsolute as isAbsolute9, join as join21, relative as relative9, sep as sep9 } from "node:path";
|
|
70180
70539
|
var MAX_SKILL_BYTES = 256000;
|
|
70181
70540
|
var MAX_METADATA_BYTES = 16384;
|
|
70182
70541
|
var MAX_CATALOG_SIZE = 100;
|
|
@@ -70186,7 +70545,7 @@ var SKILL_NAME = /^[a-z0-9][a-z0-9-]{0,127}$/;
|
|
|
70186
70545
|
var OMA_SKILL_NAME = /^oma-[a-z0-9][a-z0-9-]{0,123}$/;
|
|
70187
70546
|
function inside(root, path) {
|
|
70188
70547
|
const child = relative9(root, path);
|
|
70189
|
-
return child !== "" && child !== ".." && !child.startsWith(`..${sep9}`) && !
|
|
70548
|
+
return child !== "" && child !== ".." && !child.startsWith(`..${sep9}`) && !isAbsolute9(child);
|
|
70190
70549
|
}
|
|
70191
70550
|
function excludedResource(name) {
|
|
70192
70551
|
return [
|
|
@@ -70214,7 +70573,7 @@ async function prepareMissionSkills(sourceRepositoryPath, workspacePath) {
|
|
|
70214
70573
|
if (!sources.length)
|
|
70215
70574
|
return;
|
|
70216
70575
|
const workspace = await realpath13(workspacePath);
|
|
70217
|
-
const agents =
|
|
70576
|
+
const agents = join21(workspace, ".agents");
|
|
70218
70577
|
await mkdir10(agents, { recursive: true });
|
|
70219
70578
|
if (!inside(workspace, await realpath13(agents)))
|
|
70220
70579
|
throw new Error("The target .agents directory escapes the mission worktree. Fix its symlink before creating this order.");
|
|
@@ -70225,19 +70584,19 @@ async function prepareMissionSkills(sourceRepositoryPath, workspacePath) {
|
|
|
70225
70584
|
if (seen.has(sourceDirectory))
|
|
70226
70585
|
return;
|
|
70227
70586
|
seen.add(sourceDirectory);
|
|
70228
|
-
for (const name of (await
|
|
70587
|
+
for (const name of (await readdir6(sourceDirectory)).sort()) {
|
|
70229
70588
|
if (excludedResource(name))
|
|
70230
70589
|
continue;
|
|
70231
70590
|
if (++entries > MAX_HARNESS_ENTRIES)
|
|
70232
70591
|
throw new Error("The installed harness resources exceed 5,000 entries. Remove unused resources before creating this order.");
|
|
70233
|
-
const from = await realpath13(
|
|
70592
|
+
const from = await realpath13(join21(sourceDirectory, name)).catch(() => {
|
|
70234
70593
|
return;
|
|
70235
70594
|
});
|
|
70236
70595
|
if (!from || !inside(sourceRoot, from))
|
|
70237
70596
|
continue;
|
|
70238
|
-
const info = await
|
|
70239
|
-
const to =
|
|
70240
|
-
const existing = await
|
|
70597
|
+
const info = await stat3(from);
|
|
70598
|
+
const to = join21(targetDirectory, name);
|
|
70599
|
+
const existing = await lstat11(to).catch(() => {
|
|
70241
70600
|
return;
|
|
70242
70601
|
});
|
|
70243
70602
|
if (info.isDirectory()) {
|
|
@@ -70252,7 +70611,7 @@ async function prepareMissionSkills(sourceRepositoryPath, workspacePath) {
|
|
|
70252
70611
|
const parent = await realpath13(targetDirectory);
|
|
70253
70612
|
if (parent !== destinationRoot && !inside(destinationRoot, parent))
|
|
70254
70613
|
throw new Error("A target harness resource escapes the mission worktree. Fix its symlink before creating this order.");
|
|
70255
|
-
const file = await open9(from,
|
|
70614
|
+
const file = await open9(from, constants8.O_RDONLY | constants8.O_NOFOLLOW | constants8.O_NONBLOCK);
|
|
70256
70615
|
try {
|
|
70257
70616
|
const current = await file.stat();
|
|
70258
70617
|
if (!current.isFile())
|
|
@@ -70284,7 +70643,7 @@ async function prepareMissionSkills(sourceRepositoryPath, workspacePath) {
|
|
|
70284
70643
|
seen.delete(sourceDirectory);
|
|
70285
70644
|
}
|
|
70286
70645
|
for (const source of sources) {
|
|
70287
|
-
await mkdir10(
|
|
70646
|
+
await mkdir10(join21(agents, source.name), { recursive: true });
|
|
70288
70647
|
const targetRoot = await harnessResourceRoot(workspace, source.name);
|
|
70289
70648
|
if (!targetRoot)
|
|
70290
70649
|
throw new Error(`Cannot prepare .agents/${source.name} in the mission worktree. Restore that directory.`);
|
|
@@ -70301,21 +70660,21 @@ async function harnessResourceRoot(workspacePath, name) {
|
|
|
70301
70660
|
});
|
|
70302
70661
|
if (!workspace)
|
|
70303
70662
|
return;
|
|
70304
|
-
const root = await realpath13(
|
|
70663
|
+
const root = await realpath13(join21(workspace, ".agents", name)).catch(() => {
|
|
70305
70664
|
return;
|
|
70306
70665
|
});
|
|
70307
70666
|
if (!root)
|
|
70308
70667
|
return;
|
|
70309
70668
|
if (!inside(workspace, root))
|
|
70310
70669
|
throw new Error(`The ${name === "skills" ? "skill" : "agent"} directory escapes the mission worktree. Install the OMA harness inside this repository.`);
|
|
70311
|
-
if (!(await
|
|
70670
|
+
if (!(await stat3(root)).isDirectory())
|
|
70312
70671
|
return;
|
|
70313
70672
|
return root;
|
|
70314
70673
|
}
|
|
70315
70674
|
async function skillPath(root, name) {
|
|
70316
70675
|
if (!SKILL_NAME.test(name))
|
|
70317
70676
|
throw new Error(`Invalid skill name: ${name}. Select an installed skill directory name.`);
|
|
70318
|
-
const path = await realpath13(
|
|
70677
|
+
const path = await realpath13(join21(root, name, "SKILL.md")).catch(() => {
|
|
70319
70678
|
throw new Error(`Skill ${name}/SKILL.md is missing. Restore that installed skill in ${root} before resuming.`);
|
|
70320
70679
|
});
|
|
70321
70680
|
if (!inside(root, path))
|
|
@@ -70323,7 +70682,7 @@ async function skillPath(root, name) {
|
|
|
70323
70682
|
return path;
|
|
70324
70683
|
}
|
|
70325
70684
|
async function readSkill(path, metadataOnly) {
|
|
70326
|
-
const file = await open9(path,
|
|
70685
|
+
const file = await open9(path, constants8.O_RDONLY | constants8.O_NOFOLLOW | constants8.O_NONBLOCK);
|
|
70327
70686
|
try {
|
|
70328
70687
|
const info = await file.stat();
|
|
70329
70688
|
if (!info.isFile())
|
|
@@ -70371,8 +70730,8 @@ function metadata2(source, name, path) {
|
|
|
70371
70730
|
async function descriptor(root, name) {
|
|
70372
70731
|
if (!OMA_SKILL_NAME.test(name))
|
|
70373
70732
|
return;
|
|
70374
|
-
const directory = await realpath13(
|
|
70375
|
-
if (!inside(root, directory) || !(await
|
|
70733
|
+
const directory = await realpath13(join21(root, name));
|
|
70734
|
+
if (!inside(root, directory) || !(await stat3(directory)).isDirectory())
|
|
70376
70735
|
return;
|
|
70377
70736
|
const path = await skillPath(root, name);
|
|
70378
70737
|
return metadata2(await readSkill(path, true), name, path);
|
|
@@ -70383,7 +70742,7 @@ async function discoverMissionSkills(workspacePath) {
|
|
|
70383
70742
|
});
|
|
70384
70743
|
if (!root)
|
|
70385
70744
|
return [];
|
|
70386
|
-
const entries = await
|
|
70745
|
+
const entries = await readdir6(root).catch(() => []);
|
|
70387
70746
|
const catalog = [];
|
|
70388
70747
|
for (const name of entries.sort()) {
|
|
70389
70748
|
const skill = await descriptor(root, name).catch(() => {
|
|
@@ -70471,7 +70830,7 @@ var MAX_GUIDANCE_BYTES = 256000;
|
|
|
70471
70830
|
var MAX_PROFILES = 100;
|
|
70472
70831
|
function inside2(root, path) {
|
|
70473
70832
|
const child = relative10(root, path);
|
|
70474
|
-
return child !== "" && child !== ".." && !child.startsWith(`..${sep10}`) && !
|
|
70833
|
+
return child !== "" && child !== ".." && !child.startsWith(`..${sep10}`) && !isAbsolute10(child);
|
|
70475
70834
|
}
|
|
70476
70835
|
function invalidProfile(path) {
|
|
70477
70836
|
return new Error(`OMA agent profile ${path} is invalid. Restore YAML frontmatter with name matching its filename and a nonempty skills list of installed skill names.`);
|
|
@@ -70497,7 +70856,7 @@ function profileSkills(source, agentId, path) {
|
|
|
70497
70856
|
}
|
|
70498
70857
|
async function readProfile(root, filename) {
|
|
70499
70858
|
const agentId = filename.slice(0, -3);
|
|
70500
|
-
const requested =
|
|
70859
|
+
const requested = join22(root, filename);
|
|
70501
70860
|
if (!NAME.test(agentId))
|
|
70502
70861
|
throw invalidProfile(requested);
|
|
70503
70862
|
const path = await realpath14(requested).catch(() => {
|
|
@@ -70505,7 +70864,7 @@ async function readProfile(root, filename) {
|
|
|
70505
70864
|
});
|
|
70506
70865
|
if (!inside2(root, path))
|
|
70507
70866
|
throw new Error(`OMA agent profile ${requested} escapes .agents/agents. Fix its symlink before resuming.`);
|
|
70508
|
-
const file = await open10(path,
|
|
70867
|
+
const file = await open10(path, constants9.O_RDONLY | constants9.O_NOFOLLOW | constants9.O_NONBLOCK).catch(() => {
|
|
70509
70868
|
throw new Error(`OMA agent profile ${requested} is unreadable. Restore its file permissions before resuming.`);
|
|
70510
70869
|
});
|
|
70511
70870
|
try {
|
|
@@ -70538,15 +70897,15 @@ async function prepareOmaActor(workspacePath, selectedSkills) {
|
|
|
70538
70897
|
throw new Error(`Invalid skill name: ${name}. Select an installed skill directory name.`);
|
|
70539
70898
|
const selected = [...new Set(selectedSkills)].sort();
|
|
70540
70899
|
const workspace = await realpath14(workspacePath);
|
|
70541
|
-
const directory =
|
|
70900
|
+
const directory = join22(workspace, ".agents", "agents");
|
|
70542
70901
|
const root = await realpath14(directory).catch(() => {
|
|
70543
70902
|
throw new Error(`OMA work requires installed agent profiles in ${directory}. Install the OMA harness before resuming.`);
|
|
70544
70903
|
});
|
|
70545
70904
|
if (!inside2(workspace, root))
|
|
70546
70905
|
throw new Error("The OMA agent directory escapes the mission worktree. Install .agents/agents inside this repository.");
|
|
70547
|
-
if (!(await
|
|
70906
|
+
if (!(await stat4(root)).isDirectory())
|
|
70548
70907
|
throw new Error(`OMA agent profiles require a directory at ${directory}. Restore the installed OMA harness.`);
|
|
70549
|
-
const filenames = (await
|
|
70908
|
+
const filenames = (await readdir7(root)).filter((name) => name.endsWith(".md")).sort();
|
|
70550
70909
|
if (filenames.length > MAX_PROFILES)
|
|
70551
70910
|
throw new Error("The worktree has more than 100 OMA agent profiles. Remove unused profiles before resuming.");
|
|
70552
70911
|
let chosen;
|
|
@@ -70599,14 +70958,14 @@ var goalBriefSchema = strictObject({
|
|
|
70599
70958
|
var skillDescriptorSchema = strictObject({
|
|
70600
70959
|
name: string2().regex(/^oma-[a-z0-9][a-z0-9-]{0,123}$/),
|
|
70601
70960
|
description: string2().trim().min(1).max(1000),
|
|
70602
|
-
path: text9.refine(
|
|
70961
|
+
path: text9.refine(isAbsolute11, "Skill paths must be absolute verified SKILL.md paths.")
|
|
70603
70962
|
});
|
|
70604
70963
|
var planSchema = strictObject({
|
|
70605
70964
|
tasks: array(actorTaskSchema).min(1).max(12)
|
|
70606
70965
|
});
|
|
70607
70966
|
var missionSchema = strictObject({
|
|
70608
70967
|
id: id5,
|
|
70609
|
-
repositoryRoot: text9.refine(
|
|
70968
|
+
repositoryRoot: text9.refine(isAbsolute11, "Original repository root must be absolute.").optional(),
|
|
70610
70969
|
toolEnvKeys: toolEnvKeysSchema.optional(),
|
|
70611
70970
|
goal: text9,
|
|
70612
70971
|
chiefId: id5,
|
|
@@ -70891,7 +71250,7 @@ class MissionStore {
|
|
|
70891
71250
|
const path = `${this.path(id)}.lock`;
|
|
70892
71251
|
let file;
|
|
70893
71252
|
try {
|
|
70894
|
-
file = await open11(path,
|
|
71253
|
+
file = await open11(path, constants10.O_RDONLY | (constants10.O_NOFOLLOW ?? 0) | (constants10.O_NONBLOCK ?? 0));
|
|
70895
71254
|
const stat = await file.stat();
|
|
70896
71255
|
if (!stat.isFile() || stat.size < 1 || stat.size > 1024)
|
|
70897
71256
|
return true;
|
|
@@ -70920,7 +71279,7 @@ class MissionStore {
|
|
|
70920
71279
|
this.path(id);
|
|
70921
71280
|
if (mission && mission.id !== id)
|
|
70922
71281
|
throw new Error("Process recovery mission identity differs from its record. Restore the matching checkpoint.");
|
|
70923
|
-
const names = await
|
|
71282
|
+
const names = await readdir8(this.directory);
|
|
70924
71283
|
for (const name of names) {
|
|
70925
71284
|
if (name === `${id}.active`)
|
|
70926
71285
|
await this.processGuard(id).recoverOrphan();
|
|
@@ -70938,7 +71297,7 @@ class MissionStore {
|
|
|
70938
71297
|
path(id) {
|
|
70939
71298
|
if (!/^[a-zA-Z0-9][a-zA-Z0-9-]{0,79}$/.test(id))
|
|
70940
71299
|
throw new Error("Invalid mission ID. Use the ID printed by av order.");
|
|
70941
|
-
return
|
|
71300
|
+
return join23(this.directory, `${id}.json`);
|
|
70942
71301
|
}
|
|
70943
71302
|
save(mission) {
|
|
70944
71303
|
const write = this.writes.then(() => this.persist(mission));
|
|
@@ -70952,7 +71311,7 @@ class MissionStore {
|
|
|
70952
71311
|
await writeJsonAtomic(path, { version: 1, mission });
|
|
70953
71312
|
}
|
|
70954
71313
|
async load(id) {
|
|
70955
|
-
const content = JSON.parse(await
|
|
71314
|
+
const content = JSON.parse(await readFile9(this.path(id), "utf8"));
|
|
70956
71315
|
if (content.version !== 1)
|
|
70957
71316
|
throw new Error("Unsupported mission record version. Use the Agent Valley version that created this mission.");
|
|
70958
71317
|
const mission = missionSchema.parse(content.mission);
|
|
@@ -70963,7 +71322,7 @@ class MissionStore {
|
|
|
70963
71322
|
async list() {
|
|
70964
71323
|
let names;
|
|
70965
71324
|
try {
|
|
70966
|
-
names = await
|
|
71325
|
+
names = await readdir8(this.directory);
|
|
70967
71326
|
} catch (error) {
|
|
70968
71327
|
if (error.code === "ENOENT")
|
|
70969
71328
|
return [];
|
|
@@ -70980,7 +71339,7 @@ class MissionStore {
|
|
|
70980
71339
|
init_yaml_loader();
|
|
70981
71340
|
|
|
70982
71341
|
// src/chief-config.ts
|
|
70983
|
-
import { isAbsolute as
|
|
71342
|
+
import { isAbsolute as isAbsolute12, resolve as resolve18 } from "node:path";
|
|
70984
71343
|
|
|
70985
71344
|
// ../../packages/core/src/chief/advisory-evidence.ts
|
|
70986
71345
|
function unavailableDirectorAdvice(mission) {
|
|
@@ -71298,7 +71657,7 @@ async function resolveOrderConfig(root, options, discover = discoverAgents) {
|
|
|
71298
71657
|
const global2 = loadGlobalConfig();
|
|
71299
71658
|
const chiefConfig = mergeChiefConfig(global2?.chief, project?.chief);
|
|
71300
71659
|
const workspace = options.workspace ?? project?.workspace?.root;
|
|
71301
|
-
if (!workspace || !
|
|
71660
|
+
if (!workspace || !isAbsolute12(workspace))
|
|
71302
71661
|
throw new Error("Set --workspace to an absolute Git repository path, or set workspace.root in av.yaml.");
|
|
71303
71662
|
const verifyCommand = options.verify ?? project?.verify?.command ?? "";
|
|
71304
71663
|
if (actorOption !== undefined && !agents.has(actorOption))
|
|
@@ -71410,6 +71769,22 @@ ${details}` : ""}`);
|
|
|
71410
71769
|
|
|
71411
71770
|
// ../../packages/core/src/chief/continuous-recovery.ts
|
|
71412
71771
|
init_execution();
|
|
71772
|
+
|
|
71773
|
+
// ../../packages/core/src/chief/scheduled-wait.ts
|
|
71774
|
+
function hasSchedule(mission) {
|
|
71775
|
+
return mission.status === "waiting" && Number.isFinite(Date.parse(mission.execution?.nextRunAt ?? ""));
|
|
71776
|
+
}
|
|
71777
|
+
function scheduledChiefWait(mission) {
|
|
71778
|
+
return hasSchedule(mission) && mission.execution?.failureKind === "chief-wait" && mission.supervision?.decisions.at(-1)?.action === "wait";
|
|
71779
|
+
}
|
|
71780
|
+
function scheduledActorCooldown(mission) {
|
|
71781
|
+
return hasSchedule(mission) && mission.execution?.failureKind === "actor-cooldown";
|
|
71782
|
+
}
|
|
71783
|
+
function scheduledMissionWait(mission) {
|
|
71784
|
+
return scheduledChiefWait(mission) || scheduledActorCooldown(mission);
|
|
71785
|
+
}
|
|
71786
|
+
|
|
71787
|
+
// ../../packages/core/src/chief/continuous-recovery.ts
|
|
71413
71788
|
function verifiedMissionEvidence(mission) {
|
|
71414
71789
|
const plan = mission.plan;
|
|
71415
71790
|
const review = mission.finalReview;
|
|
@@ -71424,9 +71799,6 @@ function verifiedMissionEvidence(mission) {
|
|
|
71424
71799
|
return false;
|
|
71425
71800
|
}
|
|
71426
71801
|
}
|
|
71427
|
-
function scheduledChiefWait(mission) {
|
|
71428
|
-
return mission.status === "waiting" && mission.execution?.failureKind === "chief-wait" && mission.supervision?.decisions.at(-1)?.action === "wait" && Number.isFinite(Date.parse(mission.execution.nextRunAt ?? ""));
|
|
71429
|
-
}
|
|
71430
71802
|
function automaticMissionRecovery(mission, now = Date.now(), context = {}) {
|
|
71431
71803
|
const stop = (reason) => ({ retry: false, reason });
|
|
71432
71804
|
if (!mission.executionPolicy?.autoResume)
|
|
@@ -71463,6 +71835,12 @@ function automaticMissionRecovery(mission, now = Date.now(), context = {}) {
|
|
|
71463
71835
|
return stop(error.message);
|
|
71464
71836
|
throw error;
|
|
71465
71837
|
}
|
|
71838
|
+
if (scheduledActorCooldown(mission))
|
|
71839
|
+
return {
|
|
71840
|
+
retry: true,
|
|
71841
|
+
reason: state?.pauseReason ?? "Continue the saved Actor cooldown without another Chief recovery decision.",
|
|
71842
|
+
waitUntil: state?.nextRunAt
|
|
71843
|
+
};
|
|
71466
71844
|
const supervision = mission.supervision;
|
|
71467
71845
|
if (supervision && (supervision.rounds >= supervision.maxRounds || supervision.stalledRounds >= 3))
|
|
71468
71846
|
return stop("The Chief exhausted its saved recovery rounds; the goal remains unresolved.");
|
|
@@ -71495,12 +71873,12 @@ init_execution();
|
|
|
71495
71873
|
|
|
71496
71874
|
// src/chief-delivery-resume.ts
|
|
71497
71875
|
import { realpath as realpath17 } from "node:fs/promises";
|
|
71498
|
-
import { join as
|
|
71876
|
+
import { join as join29 } from "node:path";
|
|
71499
71877
|
|
|
71500
71878
|
// src/chief-code-delivery.ts
|
|
71501
71879
|
import { createHash as createHash18, randomUUID as randomUUID12 } from "node:crypto";
|
|
71502
|
-
import { lstat as
|
|
71503
|
-
import { join as
|
|
71880
|
+
import { lstat as lstat13, mkdir as mkdir12, readFile as readFile10, realpath as realpath16, writeFile as writeFile7 } from "node:fs/promises";
|
|
71881
|
+
import { join as join28, resolve as resolve20 } from "node:path";
|
|
71504
71882
|
init_execution();
|
|
71505
71883
|
|
|
71506
71884
|
// ../../packages/core/src/chief/execution-signal.ts
|
|
@@ -71594,8 +71972,8 @@ function recordServiceShutdown(mission, unconfirmedTermination) {
|
|
|
71594
71972
|
// src/chief-code-delivery-git.ts
|
|
71595
71973
|
import { execFile as execFile2 } from "node:child_process";
|
|
71596
71974
|
import { createHash as createHash17 } from "node:crypto";
|
|
71597
|
-
import { lstat as
|
|
71598
|
-
import { isAbsolute as
|
|
71975
|
+
import { lstat as lstat12, mkdtemp, realpath as realpath15, rm as rm3, writeFile as writeFile6 } from "node:fs/promises";
|
|
71976
|
+
import { isAbsolute as isAbsolute13, join as join27, relative as relative11, resolve as resolve19, sep as sep11 } from "node:path";
|
|
71599
71977
|
import { promisify as promisify2 } from "node:util";
|
|
71600
71978
|
init_git_environment();
|
|
71601
71979
|
init_worktree_lifecycle();
|
|
@@ -71618,9 +71996,9 @@ function shellQuote(value) {
|
|
|
71618
71996
|
return `'${value.replace(/'/g, "'\\''")}'`;
|
|
71619
71997
|
}
|
|
71620
71998
|
async function canonicalDirectory(path, description) {
|
|
71621
|
-
if (!
|
|
71999
|
+
if (!isAbsolute13(path))
|
|
71622
72000
|
throw new Error(`Use an absolute ${description} path before preparing code delivery.`);
|
|
71623
|
-
const entry = await
|
|
72001
|
+
const entry = await lstat12(path);
|
|
71624
72002
|
if (entry.isSymbolicLink() || !entry.isDirectory())
|
|
71625
72003
|
throw new Error(`The ${description} must be a real directory. Restore its original location before retrying.`);
|
|
71626
72004
|
return realpath15(path);
|
|
@@ -71630,13 +72008,13 @@ async function inspectProductPath(workspace, path) {
|
|
|
71630
72008
|
throw new Error(`Code delivery path ${JSON.stringify(path)} is private or invalid. Select an exact product file.`);
|
|
71631
72009
|
const destination = resolve19(workspace, path);
|
|
71632
72010
|
const within = relative11(workspace, destination);
|
|
71633
|
-
if (!within || within === ".." || within.startsWith(`..${sep11}`) ||
|
|
72011
|
+
if (!within || within === ".." || within.startsWith(`..${sep11}`) || isAbsolute13(within))
|
|
71634
72012
|
throw new Error("Code delivery escaped its source workspace. Restore the pinned product paths before retrying.");
|
|
71635
72013
|
const parts = path.split("/");
|
|
71636
72014
|
let current = workspace;
|
|
71637
72015
|
for (let index = 0;index < parts.length; index += 1) {
|
|
71638
|
-
current =
|
|
71639
|
-
const entry = await
|
|
72016
|
+
current = join27(current, parts[index] ?? "");
|
|
72017
|
+
const entry = await lstat12(current).catch((error) => {
|
|
71640
72018
|
if (error.code === "ENOENT")
|
|
71641
72019
|
return;
|
|
71642
72020
|
throw error;
|
|
@@ -71680,9 +72058,9 @@ async function prepareDeliveryPatch(workspace, baseSha, allowedPaths, directory)
|
|
|
71680
72058
|
throw new Error(`Changed path ${JSON.stringify(path)} is outside code delivery scope. Reconcile the exact allowlist.`);
|
|
71681
72059
|
await inspectProductPath(workspace, path);
|
|
71682
72060
|
}
|
|
71683
|
-
const temporary = await mkdtemp(
|
|
71684
|
-
const indexPath =
|
|
71685
|
-
const patchPath =
|
|
72061
|
+
const temporary = await mkdtemp(join27(directory, "patch-"));
|
|
72062
|
+
const indexPath = join27(temporary, "index");
|
|
72063
|
+
const patchPath = join27(temporary, "delivery.patch");
|
|
71686
72064
|
const env = { GIT_INDEX_FILE: indexPath };
|
|
71687
72065
|
try {
|
|
71688
72066
|
await gitRead(workspace, ["read-tree", baseSha], env);
|
|
@@ -71734,8 +72112,8 @@ async function artifact(path, content) {
|
|
|
71734
72112
|
} catch (error) {
|
|
71735
72113
|
if (error.code !== "EEXIST")
|
|
71736
72114
|
throw error;
|
|
71737
|
-
const entry = await
|
|
71738
|
-
if (!entry.isFile() || entry.isSymbolicLink() || !Buffer.from(content).equals(await
|
|
72115
|
+
const entry = await lstat13(path);
|
|
72116
|
+
if (!entry.isFile() || entry.isSymbolicLink() || !Buffer.from(content).equals(await readFile10(path)))
|
|
71739
72117
|
throw new DeliveryBlocked("Private delivery artifact changed. Restore its original bytes before resuming.");
|
|
71740
72118
|
}
|
|
71741
72119
|
}
|
|
@@ -71769,9 +72147,9 @@ async function privateDirectory(root, id) {
|
|
|
71769
72147
|
throw new DeliveryBlocked("Restore the original Mission identity before delivery.");
|
|
71770
72148
|
let current = root;
|
|
71771
72149
|
for (const part of [".agent-valley", "code-delivery", id]) {
|
|
71772
|
-
current =
|
|
72150
|
+
current = join28(current, part);
|
|
71773
72151
|
await mkdir12(current, { recursive: true, mode: 448 });
|
|
71774
|
-
const stat = await
|
|
72152
|
+
const stat = await lstat13(current);
|
|
71775
72153
|
if (!stat.isDirectory() || stat.isSymbolicLink() || await realpath16(current) !== current)
|
|
71776
72154
|
throw new DeliveryBlocked("Code delivery storage redirects through a symlink. Restore its private local directory.");
|
|
71777
72155
|
}
|
|
@@ -71877,10 +72255,10 @@ async function deliverMissionCode(mission, store, signal) {
|
|
|
71877
72255
|
throw new DeliveryBlocked("Restore the saved source repository identity before delivery.");
|
|
71878
72256
|
const root = await repositoryRoot(mission.repositoryRoot);
|
|
71879
72257
|
const gitDirectory = await realpath16(resolve20(root, (await gitRead(root, ["rev-parse", "--git-common-dir"])).trim()));
|
|
71880
|
-
unlock = await lockRecord(
|
|
72258
|
+
unlock = await lockRecord(join28(gitDirectory, "agent-valley-delivery.lock"), "Code delivery", "code-delivery");
|
|
71881
72259
|
await assertTarget(root, delivery);
|
|
71882
72260
|
const directory = await privateDirectory(root, mission.id);
|
|
71883
|
-
const patchPath =
|
|
72261
|
+
const patchPath = join28(directory, "changes.patch");
|
|
71884
72262
|
if (delivery.phase === "pending") {
|
|
71885
72263
|
if ((await gitRead(root, ["rev-parse", "HEAD"])).trim() !== delivery.policy.baseSha || !await clean(root))
|
|
71886
72264
|
throw new DeliveryBlocked("Source HEAD or its clean index changed since delivery was authorized. Preserve edits and restore the pinned source before resuming.");
|
|
@@ -71899,7 +72277,7 @@ async function deliverMissionCode(mission, store, signal) {
|
|
|
71899
72277
|
await save();
|
|
71900
72278
|
return;
|
|
71901
72279
|
}
|
|
71902
|
-
await artifact(patchPath, await
|
|
72280
|
+
await artifact(patchPath, await readFile10(prepared.patchPath));
|
|
71903
72281
|
delivery.treeSha = prepared.treeSha;
|
|
71904
72282
|
delivery.patchSha256 = prepared.patchSha256;
|
|
71905
72283
|
delivery.verifiedFingerprint = mission.fingerprint;
|
|
@@ -71909,7 +72287,7 @@ async function deliverMissionCode(mission, store, signal) {
|
|
|
71909
72287
|
}
|
|
71910
72288
|
if (!delivery.nonce || delivery.verifiedFingerprint !== mission.fingerprint)
|
|
71911
72289
|
throw new DeliveryBlocked("Restore the prepared delivery nonce and verified fingerprint before resuming.");
|
|
71912
|
-
if (createHash18("sha256").update(await
|
|
72290
|
+
if (createHash18("sha256").update(await readFile10(patchPath)).digest("hex") !== delivery.patchSha256)
|
|
71913
72291
|
throw new DeliveryBlocked("Prepared patch bytes changed. Preserve the delivery record and restore its original patch.");
|
|
71914
72292
|
const message = `${delivery.policy.message}
|
|
71915
72293
|
|
|
@@ -71956,7 +72334,7 @@ AV-Delivery: ${delivery.nonce}
|
|
|
71956
72334
|
if ((await gitRead(root, ["write-tree"])).trim() !== delivery.treeSha)
|
|
71957
72335
|
throw new DeliveryBlocked("Staged delivery differs from its verified tree. Preserve the index for inspection.");
|
|
71958
72336
|
assertLive(mission, signal);
|
|
71959
|
-
const messagePath =
|
|
72337
|
+
const messagePath = join28(directory, "commit-message.txt");
|
|
71960
72338
|
await artifact(messagePath, message);
|
|
71961
72339
|
await managedGit(mission, store, root, ["commit", "--file", messagePath], signal);
|
|
71962
72340
|
delivery.commitSha = await committedHead(root, delivery, message);
|
|
@@ -72098,7 +72476,7 @@ async function enableOperationDelivery(operation, options, root, save, onEnable)
|
|
|
72098
72476
|
let unlock;
|
|
72099
72477
|
try {
|
|
72100
72478
|
if (operation.currentMissionId) {
|
|
72101
|
-
const missions = new MissionStore(
|
|
72479
|
+
const missions = new MissionStore(join29(root, ".agent-valley", "missions"));
|
|
72102
72480
|
unlock = await missions.lock(operation.currentMissionId);
|
|
72103
72481
|
const child = await missions.load(operation.currentMissionId);
|
|
72104
72482
|
if (child.repositoryRoot !== operation.repositoryRoot || child.goal !== (operation.decision?.action === "execute" ? operation.decision.goal : undefined))
|
|
@@ -72213,8 +72591,8 @@ function applyResumeOptions(mission, goal, options) {
|
|
|
72213
72591
|
|
|
72214
72592
|
// src/mission-jobs.ts
|
|
72215
72593
|
import { createHash as createHash19 } from "node:crypto";
|
|
72216
|
-
import { lstat as
|
|
72217
|
-
import { join as
|
|
72594
|
+
import { lstat as lstat14, mkdir as mkdir13, readdir as readdir9, readFile as readFile11 } from "node:fs/promises";
|
|
72595
|
+
import { join as join30 } from "node:path";
|
|
72218
72596
|
init_atomic_json();
|
|
72219
72597
|
init_runtime_ignore();
|
|
72220
72598
|
init_zod();
|
|
@@ -72248,12 +72626,12 @@ function jobLiveness(job) {
|
|
|
72248
72626
|
async function ensureAvDirectory(root, parts) {
|
|
72249
72627
|
let path = root;
|
|
72250
72628
|
for (const part of [".agent-valley", ...parts]) {
|
|
72251
|
-
path =
|
|
72629
|
+
path = join30(path, part);
|
|
72252
72630
|
await mkdir13(path, { mode: 448 }).catch((error) => {
|
|
72253
72631
|
if (error.code !== "EEXIST")
|
|
72254
72632
|
throw error;
|
|
72255
72633
|
});
|
|
72256
|
-
const stat = await
|
|
72634
|
+
const stat = await lstat14(path);
|
|
72257
72635
|
if (!stat.isDirectory() || stat.isSymbolicLink())
|
|
72258
72636
|
throw new Error(`AV control directory must be a real directory: ${path}. Remove the symlink before retrying.`);
|
|
72259
72637
|
}
|
|
@@ -72267,7 +72645,7 @@ class MissionJobs {
|
|
|
72267
72645
|
constructor(root, directoryName = "jobs") {
|
|
72268
72646
|
this.root = root;
|
|
72269
72647
|
this.directoryName = directoryName;
|
|
72270
|
-
this.directory =
|
|
72648
|
+
this.directory = join30(root, ".agent-valley/control", directoryName);
|
|
72271
72649
|
}
|
|
72272
72650
|
async locked(operation) {
|
|
72273
72651
|
await ensureRuntimeGitignore(this.root);
|
|
@@ -72283,9 +72661,9 @@ class MissionJobs {
|
|
|
72283
72661
|
await ensureAvDirectory(this.root, ["control", this.directoryName]);
|
|
72284
72662
|
try {
|
|
72285
72663
|
const path = this.path(requestId);
|
|
72286
|
-
if ((await
|
|
72664
|
+
if ((await lstat14(path)).isSymbolicLink())
|
|
72287
72665
|
throw new Error("AV launch receipt cannot be a symlink.");
|
|
72288
|
-
return jobSchema.parse(JSON.parse(await
|
|
72666
|
+
return jobSchema.parse(JSON.parse(await readFile11(path, "utf8")));
|
|
72289
72667
|
} catch (error) {
|
|
72290
72668
|
if (error.code === "ENOENT")
|
|
72291
72669
|
return;
|
|
@@ -72296,16 +72674,16 @@ class MissionJobs {
|
|
|
72296
72674
|
}
|
|
72297
72675
|
async list() {
|
|
72298
72676
|
await ensureAvDirectory(this.root, ["control", this.directoryName]);
|
|
72299
|
-
const files = await
|
|
72677
|
+
const files = await readdir9(this.directory).catch((error) => {
|
|
72300
72678
|
if (error.code === "ENOENT")
|
|
72301
72679
|
return [];
|
|
72302
72680
|
throw error;
|
|
72303
72681
|
});
|
|
72304
72682
|
return Promise.all(files.filter((file) => /^[a-f0-9]{64}\.json$/.test(file)).map(async (file) => {
|
|
72305
|
-
const path =
|
|
72306
|
-
if ((await
|
|
72683
|
+
const path = join30(this.directory, file);
|
|
72684
|
+
if ((await lstat14(path)).isSymbolicLink())
|
|
72307
72685
|
throw new Error(`AV launch receipt cannot be a symlink: ${path}`);
|
|
72308
|
-
return jobSchema.parse(JSON.parse(await
|
|
72686
|
+
return jobSchema.parse(JSON.parse(await readFile11(path, "utf8")));
|
|
72309
72687
|
}));
|
|
72310
72688
|
}
|
|
72311
72689
|
async latest(missionId) {
|
|
@@ -72317,10 +72695,10 @@ class MissionJobs {
|
|
|
72317
72695
|
await writeJsonAtomic(this.path(job.requestId), job, { pretty: false });
|
|
72318
72696
|
}
|
|
72319
72697
|
logPath(job) {
|
|
72320
|
-
return
|
|
72698
|
+
return join30(this.directory, `${digest6(job.requestId)}.log`);
|
|
72321
72699
|
}
|
|
72322
72700
|
path(requestId) {
|
|
72323
|
-
return
|
|
72701
|
+
return join30(this.directory, `${digest6(requestId)}.json`);
|
|
72324
72702
|
}
|
|
72325
72703
|
}
|
|
72326
72704
|
|
|
@@ -72355,16 +72733,17 @@ async function launchMission(input) {
|
|
|
72355
72733
|
// src/operation-api.ts
|
|
72356
72734
|
import { randomUUID as randomUUID21 } from "node:crypto";
|
|
72357
72735
|
import { realpath as realpath32 } from "node:fs/promises";
|
|
72358
|
-
import { join as
|
|
72736
|
+
import { join as join54 } from "node:path";
|
|
72359
72737
|
|
|
72360
72738
|
// ../../packages/core/src/chief/continuous-store.ts
|
|
72361
72739
|
init_atomic_json();
|
|
72362
|
-
import { lstat as
|
|
72363
|
-
import { join as
|
|
72740
|
+
import { lstat as lstat15, mkdir as mkdir14, readdir as readdir10, readFile as readFile12, realpath as realpath18 } from "node:fs/promises";
|
|
72741
|
+
import { join as join31, resolve as resolve21 } from "node:path";
|
|
72364
72742
|
|
|
72365
72743
|
// ../../packages/core/src/chief/continuous-contract.ts
|
|
72366
72744
|
init_zod();
|
|
72367
72745
|
init_container_observation_policy();
|
|
72746
|
+
init_operations();
|
|
72368
72747
|
|
|
72369
72748
|
// ../../packages/core/src/chief/source-integration-contract.ts
|
|
72370
72749
|
init_zod();
|
|
@@ -72436,6 +72815,7 @@ var operationSchema = strictObject({
|
|
|
72436
72815
|
repositoryRoot: pathSchema,
|
|
72437
72816
|
charter: string2().trim().min(1).max(32000),
|
|
72438
72817
|
settings: record(string2().min(1).max(80), union([string2().max(32000), boolean2()])),
|
|
72818
|
+
actorHealth: array(providerHealthEvidenceSchema).max(100).optional(),
|
|
72439
72819
|
phase: _enum(["deciding", "running", "accepting", "waiting", "paused", "completed"]),
|
|
72440
72820
|
pauseKind: _enum(["interrupted", "blocked", "service-shutdown"]).optional(),
|
|
72441
72821
|
createdAt: timestampSchema,
|
|
@@ -72530,7 +72910,7 @@ class ContinuousOperationStore {
|
|
|
72530
72910
|
}
|
|
72531
72911
|
path(id) {
|
|
72532
72912
|
operationIdSchema.parse(id);
|
|
72533
|
-
return
|
|
72913
|
+
return join31(this.directory, `${id}.json`);
|
|
72534
72914
|
}
|
|
72535
72915
|
async ensureDirectory() {
|
|
72536
72916
|
await mkdir14(this.directory, { recursive: true, mode: 448 });
|
|
@@ -72550,9 +72930,9 @@ class ContinuousOperationStore {
|
|
|
72550
72930
|
}
|
|
72551
72931
|
async load(id) {
|
|
72552
72932
|
const path = this.path(id);
|
|
72553
|
-
if (await realpath18(this.directory) !== resolve21(this.directory) || !(await
|
|
72933
|
+
if (await realpath18(this.directory) !== resolve21(this.directory) || !(await lstat15(path)).isFile())
|
|
72554
72934
|
throw new Error("Operation record must remain a regular file in its original local storage directory.");
|
|
72555
|
-
const content = JSON.parse(await
|
|
72935
|
+
const content = JSON.parse(await readFile12(path, "utf8"));
|
|
72556
72936
|
if (content.version !== 1)
|
|
72557
72937
|
throw new Error("Unsupported operation record version. Use the AV version that created this operation.");
|
|
72558
72938
|
const operation = operationSchema.parse(content.operation);
|
|
@@ -72563,7 +72943,7 @@ class ContinuousOperationStore {
|
|
|
72563
72943
|
async list() {
|
|
72564
72944
|
let names;
|
|
72565
72945
|
try {
|
|
72566
|
-
names = await
|
|
72946
|
+
names = await readdir10(this.directory);
|
|
72567
72947
|
} catch (error) {
|
|
72568
72948
|
if (error.code === "ENOENT")
|
|
72569
72949
|
return [];
|
|
@@ -72582,7 +72962,7 @@ class ContinuousOperationStore {
|
|
|
72582
72962
|
import { execFile as execFile6 } from "node:child_process";
|
|
72583
72963
|
import { randomUUID as randomUUID20 } from "node:crypto";
|
|
72584
72964
|
import { realpath as realpath31 } from "node:fs/promises";
|
|
72585
|
-
import { join as
|
|
72965
|
+
import { join as join53, resolve as resolve33 } from "node:path";
|
|
72586
72966
|
import { promisify as promisify4 } from "node:util";
|
|
72587
72967
|
|
|
72588
72968
|
// ../../packages/core/src/chief/container-observation-command.ts
|
|
@@ -73069,9 +73449,9 @@ async function collectContainerObservation(input, previous, dependencies = {}) {
|
|
|
73069
73449
|
|
|
73070
73450
|
// ../../packages/core/src/chief/continuous-acceptance-record.ts
|
|
73071
73451
|
init_zod();
|
|
73072
|
-
import { constants as
|
|
73073
|
-
import { lstat as
|
|
73074
|
-
import { dirname as dirname6, join as
|
|
73452
|
+
import { constants as constants12 } from "node:fs";
|
|
73453
|
+
import { lstat as lstat16, open as open13, realpath as realpath19 } from "node:fs/promises";
|
|
73454
|
+
import { dirname as dirname6, join as join32, resolve as resolve22 } from "node:path";
|
|
73075
73455
|
var objectId3 = string2().regex(/^[a-f0-9]{40,64}$/);
|
|
73076
73456
|
var continuousAcceptanceSchema = strictObject({
|
|
73077
73457
|
version: literal(1),
|
|
@@ -73089,8 +73469,8 @@ async function recordContinuousAcceptance(operation) {
|
|
|
73089
73469
|
const entry = operation.history.at(-1);
|
|
73090
73470
|
if (!snapshot?.missionId || !entry || entry.missionId !== snapshot.missionId || entry.baselinePath !== snapshot.path)
|
|
73091
73471
|
return;
|
|
73092
|
-
const directory =
|
|
73093
|
-
if (snapshot.operationId !== operation.id || snapshot.repositoryRoot !== operation.repositoryRoot || snapshot.path !==
|
|
73472
|
+
const directory = join32(operation.repositoryRoot, ".agent-valley", "operations", operation.id, "baselines", snapshot.missionId);
|
|
73473
|
+
if (snapshot.operationId !== operation.id || snapshot.repositoryRoot !== operation.repositoryRoot || snapshot.path !== join32(directory, "workspace") || await realpath19(directory) !== resolve22(directory) || await realpath19(operation.repositoryRoot) !== operation.repositoryRoot)
|
|
73094
73474
|
throw new Error("Acceptance journal paths changed. Restore the original accepted snapshot before continuing.");
|
|
73095
73475
|
const record = continuousAcceptanceSchema.parse({
|
|
73096
73476
|
version: 1,
|
|
@@ -73103,10 +73483,10 @@ async function recordContinuousAcceptance(operation) {
|
|
|
73103
73483
|
tree: snapshot.baselineTree,
|
|
73104
73484
|
completedAt: entry.completedAt
|
|
73105
73485
|
});
|
|
73106
|
-
const path =
|
|
73486
|
+
const path = join32(directory, "acceptance.json");
|
|
73107
73487
|
let existing;
|
|
73108
73488
|
try {
|
|
73109
|
-
existing = await open13(path,
|
|
73489
|
+
existing = await open13(path, constants12.O_RDONLY | (constants12.O_NOFOLLOW ?? 0) | (constants12.O_NONBLOCK ?? 0));
|
|
73110
73490
|
const stat = await existing.stat();
|
|
73111
73491
|
if (!stat.isFile() || stat.size > 16384)
|
|
73112
73492
|
throw new Error("Unsupported acceptance journal receipt.");
|
|
@@ -73120,7 +73500,7 @@ async function recordContinuousAcceptance(operation) {
|
|
|
73120
73500
|
} finally {
|
|
73121
73501
|
await existing?.close();
|
|
73122
73502
|
}
|
|
73123
|
-
if (!(await
|
|
73503
|
+
if (!(await lstat16(dirname6(path))).isDirectory())
|
|
73124
73504
|
throw new Error("Acceptance journal requires its original private directory.");
|
|
73125
73505
|
const handle = await open13(path, "wx", 384);
|
|
73126
73506
|
try {
|
|
@@ -73134,6 +73514,43 @@ async function recordContinuousAcceptance(operation) {
|
|
|
73134
73514
|
// ../../packages/core/src/chief/continuous-operation.ts
|
|
73135
73515
|
import { createHash as createHash21, randomUUID as randomUUID13 } from "node:crypto";
|
|
73136
73516
|
|
|
73517
|
+
// ../../packages/core/src/chief/actor-health-seed.ts
|
|
73518
|
+
var routeKey2 = (route) => JSON.stringify([route.actorType, route.model ?? null]);
|
|
73519
|
+
function mergeProviderHealthSnapshots(previous, updates) {
|
|
73520
|
+
const merged = new Map;
|
|
73521
|
+
for (const route of [...previous, ...updates]) {
|
|
73522
|
+
const key = routeKey2(route);
|
|
73523
|
+
const existing = merged.get(key);
|
|
73524
|
+
if (existing && Date.parse(existing.providerHealth.lastOutcomeAt) > Date.parse(route.providerHealth.lastOutcomeAt))
|
|
73525
|
+
continue;
|
|
73526
|
+
merged.set(key, {
|
|
73527
|
+
actorType: route.actorType,
|
|
73528
|
+
...route.model ? { model: route.model } : {},
|
|
73529
|
+
providerHealth: { ...route.providerHealth }
|
|
73530
|
+
});
|
|
73531
|
+
}
|
|
73532
|
+
return [...merged.values()];
|
|
73533
|
+
}
|
|
73534
|
+
function seedProviderHealthEvidence(quality, health) {
|
|
73535
|
+
const merged = new Map(quality.map((route) => [routeKey2(route), { ...route }]));
|
|
73536
|
+
const newest = mergeProviderHealthSnapshots(quality.flatMap((route) => route.providerHealth ? [{ ...route, providerHealth: route.providerHealth }] : []), health);
|
|
73537
|
+
for (const route of newest) {
|
|
73538
|
+
const key = routeKey2(route);
|
|
73539
|
+
merged.set(key, {
|
|
73540
|
+
...merged.get(key) ?? {
|
|
73541
|
+
actorType: route.actorType,
|
|
73542
|
+
...route.model ? { model: route.model } : {},
|
|
73543
|
+
samples: 0,
|
|
73544
|
+
successes: 0,
|
|
73545
|
+
totalCostUsd: null,
|
|
73546
|
+
successfulDeliverableCostUsd: null
|
|
73547
|
+
},
|
|
73548
|
+
providerHealth: { ...route.providerHealth }
|
|
73549
|
+
});
|
|
73550
|
+
}
|
|
73551
|
+
return [...merged.values()];
|
|
73552
|
+
}
|
|
73553
|
+
|
|
73137
73554
|
// ../../packages/core/src/chief/continuous-acceptance.ts
|
|
73138
73555
|
async function acceptContinuousChild(operation, mission, ports, save, now) {
|
|
73139
73556
|
const previous = operation.baseline;
|
|
@@ -73197,6 +73614,23 @@ async function runContinuousOperation(operation, ports) {
|
|
|
73197
73614
|
operation.updatedAt = now();
|
|
73198
73615
|
await ports.save(operation);
|
|
73199
73616
|
};
|
|
73617
|
+
const assertIdentity = (child) => {
|
|
73618
|
+
const decision = operation.decision;
|
|
73619
|
+
if (child.id !== operation.currentMissionId || child.repositoryRoot !== operation.repositoryRoot || decision?.action !== "execute" || child.goal !== decision.goal)
|
|
73620
|
+
throw new Error("Saved child identity, repository or goal does not match this operation. Restore the original child before continuing.");
|
|
73621
|
+
if (JSON.stringify(child.containerObservationPolicy) !== JSON.stringify(operation.containerObservationPolicy))
|
|
73622
|
+
throw new Error("Saved child container targets differ from the pinned operation contract. Restore the original child policy before continuing.");
|
|
73623
|
+
};
|
|
73624
|
+
const rememberHealth = async (child) => {
|
|
73625
|
+
assertIdentity(child);
|
|
73626
|
+
const health = mergeProviderHealthSnapshots(operation.actorHealth ?? [], aggregateProviderHealth(child));
|
|
73627
|
+
if (JSON.stringify(health) !== JSON.stringify(operation.actorHealth ?? [])) {
|
|
73628
|
+
operation.actorHealth = health;
|
|
73629
|
+
await save();
|
|
73630
|
+
}
|
|
73631
|
+
return child;
|
|
73632
|
+
};
|
|
73633
|
+
const runChild = async (id, goal, baseline) => rememberHealth(await ports.runMission(operation, id, goal, baseline));
|
|
73200
73634
|
const pause = async (message) => {
|
|
73201
73635
|
if (operation.phase !== "paused" && operation.phase !== "completed")
|
|
73202
73636
|
operation.resumePhase = operation.phase;
|
|
@@ -73252,11 +73686,13 @@ async function runContinuousOperation(operation, ports) {
|
|
|
73252
73686
|
const previous = operation.recovery?.target === "child" && operation.recovery.checkpointId === mission.id ? operation.recovery : undefined;
|
|
73253
73687
|
const prior = previous?.attempts ?? 0;
|
|
73254
73688
|
const failedAttempts = previous?.failedAttempts ?? prior;
|
|
73255
|
-
const
|
|
73256
|
-
|
|
73689
|
+
const actorCooldown = scheduledActorCooldown(mission);
|
|
73690
|
+
const waitKey = scheduledMissionWait(mission) ? createHash21("sha256").update(JSON.stringify({
|
|
73691
|
+
...actorCooldown ? { kind: "actor-cooldown" } : { decision: mission.supervision?.decisions.at(-1) },
|
|
73257
73692
|
nextRunAt: mission.execution?.nextRunAt
|
|
73258
73693
|
})).digest("hex") : undefined;
|
|
73259
|
-
const
|
|
73694
|
+
const pendingCooldown = actorCooldown && previous?.nextRunAt === mission.execution?.nextRunAt;
|
|
73695
|
+
const continuation = !!waitKey && (waitKey !== previous?.waitContinuationKey || pendingCooldown);
|
|
73260
73696
|
operation.recovery = {
|
|
73261
73697
|
target: "child",
|
|
73262
73698
|
checkpointId: mission.id,
|
|
@@ -73286,7 +73722,7 @@ async function runContinuousOperation(operation, ports) {
|
|
|
73286
73722
|
if (!operation.baseline)
|
|
73287
73723
|
throw new Error("The original accepted baseline is missing from the recovery checkpoint.");
|
|
73288
73724
|
try {
|
|
73289
|
-
const resumed = await
|
|
73725
|
+
const resumed = await runChild(mission.id, mission.goal, operation.baseline.path);
|
|
73290
73726
|
if (isServiceShutdown(ports.signal) && resumed.execution?.failureKind === "service-shutdown") {
|
|
73291
73727
|
operation.recovery = pendingRecovery;
|
|
73292
73728
|
throw interruptionPause(ports.signal, "Operation child recovery interrupted.");
|
|
@@ -73372,15 +73808,9 @@ async function runContinuousOperation(operation, ports) {
|
|
|
73372
73808
|
const decision = operation.decision;
|
|
73373
73809
|
if (decision?.action !== "execute")
|
|
73374
73810
|
throw new Error("Restore the saved child execution decision before resuming.");
|
|
73375
|
-
const assertIdentity = (child) => {
|
|
73376
|
-
if (child.id !== id || child.repositoryRoot !== operation.repositoryRoot || child.goal !== decision.goal)
|
|
73377
|
-
throw new Error("Saved child identity, repository or goal does not match this operation. Restore the original child before continuing.");
|
|
73378
|
-
if (JSON.stringify(child.containerObservationPolicy) !== JSON.stringify(operation.containerObservationPolicy))
|
|
73379
|
-
throw new Error("Saved child container targets differ from the pinned operation contract. Restore the original child policy before continuing.");
|
|
73380
|
-
};
|
|
73381
73811
|
let mission = await ports.findMission(id);
|
|
73382
73812
|
if (mission) {
|
|
73383
|
-
|
|
73813
|
+
await rememberHealth(mission);
|
|
73384
73814
|
if (mission.tasks.some((task) => task.effectState === "unknown")) {
|
|
73385
73815
|
if (await recoverChild(mission))
|
|
73386
73816
|
continue;
|
|
@@ -73395,7 +73825,7 @@ async function runContinuousOperation(operation, ports) {
|
|
|
73395
73825
|
if (!mission) {
|
|
73396
73826
|
if (operation.phase === "accepting")
|
|
73397
73827
|
return pause(`Completed child ${id} is missing. Restore its saved mission record before continuing.`);
|
|
73398
|
-
mission = await
|
|
73828
|
+
mission = await runChild(id, decision.goal, operation.baseline.path);
|
|
73399
73829
|
} else if (mission.status !== "completed" && mission.status !== "paused" && mission.status !== "failed") {
|
|
73400
73830
|
const recovery = operation.recovery;
|
|
73401
73831
|
if (recovery?.target === "child" && recovery.checkpointId === id && recovery.disposition === "protected" && !mission.tasks.some((task) => task.effectState === "running") && automaticMissionRecovery(mission, Date.parse(now())).retry) {
|
|
@@ -73403,7 +73833,7 @@ async function runContinuousOperation(operation, ports) {
|
|
|
73403
73833
|
recovery.reason = `The original child resumed ${mission.status}; joining its saved coordinator without spending another recovery attempt.`;
|
|
73404
73834
|
await save();
|
|
73405
73835
|
}
|
|
73406
|
-
mission = await
|
|
73836
|
+
mission = await runChild(id, decision.goal, operation.baseline.path);
|
|
73407
73837
|
}
|
|
73408
73838
|
assertIdentity(mission);
|
|
73409
73839
|
if (mission.status !== "completed") {
|
|
@@ -73420,7 +73850,7 @@ async function runContinuousOperation(operation, ports) {
|
|
|
73420
73850
|
if (!mission.executionPolicy?.autoResume)
|
|
73421
73851
|
return pause(`Child ${id} has pending code delivery with automatic recovery disabled.`);
|
|
73422
73852
|
await waitForRecovery(mission.codeDelivery?.nextRunAt, mission);
|
|
73423
|
-
await
|
|
73853
|
+
await runChild(id, decision.goal, operation.baseline.path);
|
|
73424
73854
|
continue;
|
|
73425
73855
|
}
|
|
73426
73856
|
if (!successfulCodeDelivery(mission))
|
|
@@ -73516,12 +73946,12 @@ async function runContinuousOperation(operation, ports) {
|
|
|
73516
73946
|
// ../../packages/core/src/chief/continuous-source-integration.ts
|
|
73517
73947
|
init_zod();
|
|
73518
73948
|
import { createHash as createHash23 } from "node:crypto";
|
|
73519
|
-
import { lstat as
|
|
73520
|
-
import { join as
|
|
73949
|
+
import { lstat as lstat19, mkdir as mkdir17, readdir as readdir11, readFile as readFile16, realpath as realpath22, writeFile as writeFile10 } from "node:fs/promises";
|
|
73950
|
+
import { join as join36, resolve as resolve25 } from "node:path";
|
|
73521
73951
|
|
|
73522
73952
|
// ../../packages/core/src/chief/content-transaction.ts
|
|
73523
73953
|
import { createHash as createHash22 } from "node:crypto";
|
|
73524
|
-
import { readFile as
|
|
73954
|
+
import { readFile as readFile13 } from "node:fs/promises";
|
|
73525
73955
|
|
|
73526
73956
|
// ../../packages/core/src/chief/parallel-git.ts
|
|
73527
73957
|
init_atomic_json();
|
|
@@ -73530,7 +73960,7 @@ init_git_environment();
|
|
|
73530
73960
|
import { execFile as execFile4 } from "node:child_process";
|
|
73531
73961
|
import { randomUUID as randomUUID14 } from "node:crypto";
|
|
73532
73962
|
import { mkdir as mkdir15, realpath as realpath20, rm as rm4, writeFile as writeFile8 } from "node:fs/promises";
|
|
73533
|
-
import { join as
|
|
73963
|
+
import { join as join33, relative as relative12, resolve as resolve23, sep as sep12 } from "node:path";
|
|
73534
73964
|
import { promisify as promisify3 } from "node:util";
|
|
73535
73965
|
var exec2 = promisify3(execFile4);
|
|
73536
73966
|
var productPaths = ["--", ".", ":(exclude,glob).agent-valley/**", ":(exclude,glob).agents/**"];
|
|
@@ -73551,7 +73981,7 @@ async function parallelGit(cwd, args, env = {}) {
|
|
|
73551
73981
|
}
|
|
73552
73982
|
async function parallelRoot(workspace) {
|
|
73553
73983
|
const root = await realpath20(workspace);
|
|
73554
|
-
const directory =
|
|
73984
|
+
const directory = join33(root, ".agent-valley", "parallel");
|
|
73555
73985
|
await mkdir15(directory, { recursive: true, mode: 448 });
|
|
73556
73986
|
const actual = await realpath20(directory);
|
|
73557
73987
|
if (actual !== directory)
|
|
@@ -73568,7 +73998,7 @@ async function writeParallelJson(path, value) {
|
|
|
73568
73998
|
}
|
|
73569
73999
|
async function captureParallelBaseline(workspace) {
|
|
73570
74000
|
const directory = await parallelRoot(workspace);
|
|
73571
|
-
const index =
|
|
74001
|
+
const index = join33(directory, `index-${randomUUID14()}`);
|
|
73572
74002
|
const pathsFile = `${index}.paths`;
|
|
73573
74003
|
const env = { GIT_INDEX_FILE: index };
|
|
73574
74004
|
try {
|
|
@@ -73614,7 +74044,7 @@ async function parallelTreeImages(workspace, tree) {
|
|
|
73614
74044
|
// ../../packages/core/src/chief/content-transaction.ts
|
|
73615
74045
|
async function integrateContentTransaction(workspace, transaction, hooks) {
|
|
73616
74046
|
await hooks.assertLive?.();
|
|
73617
|
-
const patch = await
|
|
74047
|
+
const patch = await readFile13(transaction.patchPath);
|
|
73618
74048
|
if (createHash22("sha256").update(patch).digest("hex") !== transaction.patchSha256)
|
|
73619
74049
|
throw new Error("Integration patch changed. Restore its saved SHA256 before integration.");
|
|
73620
74050
|
const current = await captureParallelBaseline(workspace);
|
|
@@ -73658,8 +74088,8 @@ init_zod();
|
|
|
73658
74088
|
init_runtime_ignore();
|
|
73659
74089
|
init_parallel_contract();
|
|
73660
74090
|
import { randomUUID as randomUUID15 } from "node:crypto";
|
|
73661
|
-
import { lstat as
|
|
73662
|
-
import { join as
|
|
74091
|
+
import { lstat as lstat17, readFile as readFile14, rm as rm5, writeFile as writeFile9 } from "node:fs/promises";
|
|
74092
|
+
import { join as join34 } from "node:path";
|
|
73663
74093
|
var imageSchema2 = parallelDeliverySchema.shape.changes.element.shape.before;
|
|
73664
74094
|
var gitignoreProjectionSchema = strictObject({
|
|
73665
74095
|
path: literal(".gitignore"),
|
|
@@ -73674,13 +74104,13 @@ async function artifact2(path, value) {
|
|
|
73674
74104
|
} catch (error) {
|
|
73675
74105
|
if (error.code !== "EEXIST")
|
|
73676
74106
|
throw error;
|
|
73677
|
-
const info = await
|
|
73678
|
-
if (info.isSymbolicLink() || !info.isFile() || !(await
|
|
74107
|
+
const info = await lstat17(path);
|
|
74108
|
+
if (info.isSymbolicLink() || !info.isFile() || !(await readFile14(path)).equals(Buffer.from(value)))
|
|
73679
74109
|
throw new Error("Projected runtime-ignore bytes changed. Restore the original source integration artifacts before retrying.");
|
|
73680
74110
|
}
|
|
73681
74111
|
}
|
|
73682
74112
|
async function projectedPatch(workspace, directory, before, after) {
|
|
73683
|
-
const index =
|
|
74113
|
+
const index = join34(directory, `gitignore-index-${randomUUID15()}`);
|
|
73684
74114
|
const env = { GIT_INDEX_FILE: index };
|
|
73685
74115
|
try {
|
|
73686
74116
|
await parallelGit(workspace, ["read-tree", "--empty"], env);
|
|
@@ -73745,7 +74175,7 @@ async function projectContinuousGitignore(workspace, sourceWorkspace, directory,
|
|
|
73745
74175
|
throw new Error("Runtime-ignore projection requires unchanged UTF-8 ignore-file text. Preserve its bytes and reconcile before retrying.");
|
|
73746
74176
|
}
|
|
73747
74177
|
const blob = async (name, content, mode) => {
|
|
73748
|
-
const path =
|
|
74178
|
+
const path = join34(directory, name);
|
|
73749
74179
|
await artifact2(path, content);
|
|
73750
74180
|
return { mode, oid: (await parallelGit(workspace, ["hash-object", "-w", "--", path])).trim() };
|
|
73751
74181
|
};
|
|
@@ -73769,8 +74199,8 @@ async function projectContinuousGitignore(workspace, sourceWorkspace, directory,
|
|
|
73769
74199
|
|
|
73770
74200
|
// ../../packages/core/src/chief/continuous-workspace.ts
|
|
73771
74201
|
init_zod();
|
|
73772
|
-
import { lstat as
|
|
73773
|
-
import { dirname as dirname7, join as
|
|
74202
|
+
import { lstat as lstat18, mkdir as mkdir16, readFile as readFile15, realpath as realpath21 } from "node:fs/promises";
|
|
74203
|
+
import { dirname as dirname7, join as join35, resolve as resolve24 } from "node:path";
|
|
73774
74204
|
async function localDirectory(path) {
|
|
73775
74205
|
await mkdir16(path, { recursive: true, mode: 448 });
|
|
73776
74206
|
if (await realpath21(path) !== resolve24(path))
|
|
@@ -73782,12 +74212,12 @@ async function operationDirectory(repositoryRoot, operationId) {
|
|
|
73782
74212
|
const top = (await parallelGit(root, ["rev-parse", "--show-toplevel"])).trim();
|
|
73783
74213
|
if (root !== resolve24(repositoryRoot) || await realpath21(top) !== root)
|
|
73784
74214
|
throw new Error("Use the operation's original canonical Git repository root before resuming.");
|
|
73785
|
-
const directory =
|
|
74215
|
+
const directory = join35(root, ".agent-valley", "operations", operationId);
|
|
73786
74216
|
await localDirectory(directory);
|
|
73787
74217
|
return directory;
|
|
73788
74218
|
}
|
|
73789
74219
|
async function readJson2(path) {
|
|
73790
|
-
const stats = await
|
|
74220
|
+
const stats = await lstat18(path).catch((error) => {
|
|
73791
74221
|
if (error.code === "ENOENT")
|
|
73792
74222
|
return;
|
|
73793
74223
|
throw error;
|
|
@@ -73796,10 +74226,10 @@ async function readJson2(path) {
|
|
|
73796
74226
|
return;
|
|
73797
74227
|
if (!stats.isFile())
|
|
73798
74228
|
throw new Error("Operation receipts must be regular local files. Restore the original receipt.");
|
|
73799
|
-
return JSON.parse(await
|
|
74229
|
+
return JSON.parse(await readFile15(path, "utf8"));
|
|
73800
74230
|
}
|
|
73801
74231
|
async function assertRepository(path, branch, commit) {
|
|
73802
|
-
if (await realpath21(path) !== path || !(await
|
|
74232
|
+
if (await realpath21(path) !== path || !(await lstat18(join35(path, ".git"))).isDirectory())
|
|
73803
74233
|
throw new Error("Operation workspace must remain an independent local Git repository.");
|
|
73804
74234
|
const [top, currentBranch, head] = await Promise.all([
|
|
73805
74235
|
parallelGit(path, ["rev-parse", "--show-toplevel"]),
|
|
@@ -73814,11 +74244,11 @@ async function prepareContinuousBaseline(repositoryRoot, operationId, sourceWork
|
|
|
73814
74244
|
operationIdSchema.parse(missionId);
|
|
73815
74245
|
if (expectedFingerprint !== undefined && !/^[a-f0-9]{64}$/.test(expectedFingerprint))
|
|
73816
74246
|
throw new Error("Use the completed child's original SHA256 verification fingerprint when accepting a snapshot.");
|
|
73817
|
-
const directory =
|
|
74247
|
+
const directory = join35(await operationDirectory(repositoryRoot, operationId), "baselines", missionId ?? "initial");
|
|
73818
74248
|
await localDirectory(directory);
|
|
73819
|
-
const recordPath =
|
|
73820
|
-
const preparedPath =
|
|
73821
|
-
const path =
|
|
74249
|
+
const recordPath = join35(directory, "baseline.json");
|
|
74250
|
+
const preparedPath = join35(directory, "snapshot.json");
|
|
74251
|
+
const path = join35(directory, "workspace");
|
|
73822
74252
|
const source = await realpath21(sourceWorkspacePath);
|
|
73823
74253
|
const existing = await readJson2(recordPath);
|
|
73824
74254
|
if (existing) {
|
|
@@ -73876,7 +74306,7 @@ async function prepareContinuousBaseline(repositoryRoot, operationId, sourceWork
|
|
|
73876
74306
|
return validateContinuousBaseline(repositoryRoot, operationId, snapshot.path);
|
|
73877
74307
|
}
|
|
73878
74308
|
async function ensureClone(source, path, branch, commit) {
|
|
73879
|
-
const exists = await
|
|
74309
|
+
const exists = await lstat18(path).catch((error) => {
|
|
73880
74310
|
if (error.code === "ENOENT")
|
|
73881
74311
|
return;
|
|
73882
74312
|
throw error;
|
|
@@ -73886,11 +74316,11 @@ async function ensureClone(source, path, branch, commit) {
|
|
|
73886
74316
|
} else if (!exists.isDirectory() || await realpath21(path) !== path) {
|
|
73887
74317
|
throw new Error("Operation workspace path redirects outside its private directory. Restore it before resuming.");
|
|
73888
74318
|
}
|
|
73889
|
-
if (!(await
|
|
74319
|
+
if (!(await lstat18(join35(path, ".git"))).isDirectory() || await realpath21(join35(path, ".git")) !== join35(path, ".git"))
|
|
73890
74320
|
throw new Error("Operation clone Git metadata must remain within its independent private repository.");
|
|
73891
74321
|
const currentBranch = (await parallelGit(path, ["symbolic-ref", "--quiet", "--short", "HEAD"])).trim();
|
|
73892
74322
|
if (currentBranch !== branch) {
|
|
73893
|
-
const index = await
|
|
74323
|
+
const index = await lstat18(join35(path, ".git", "index")).catch(() => {
|
|
73894
74324
|
return;
|
|
73895
74325
|
});
|
|
73896
74326
|
if (index)
|
|
@@ -73908,10 +74338,10 @@ async function validateContinuousBaseline(repositoryRoot, operationId, baselineP
|
|
|
73908
74338
|
const path = resolve24(baselinePath);
|
|
73909
74339
|
const key = dirname7(path).split(/[\\/]/).at(-1) ?? "";
|
|
73910
74340
|
operationIdSchema.parse(key);
|
|
73911
|
-
if (path !==
|
|
74341
|
+
if (path !== join35(root, "baselines", key, "workspace") || await realpath21(dirname7(path)) !== dirname7(path))
|
|
73912
74342
|
throw new Error("Accepted baseline path is outside this operation's private snapshot directory.");
|
|
73913
|
-
const snapshot = continuousBaselineSchema.parse(await readJson2(
|
|
73914
|
-
const expected =
|
|
74343
|
+
const snapshot = continuousBaselineSchema.parse(await readJson2(join35(dirname7(path), "baseline.json")));
|
|
74344
|
+
const expected = join35(root, "baselines", snapshot.missionId ?? "initial", "workspace");
|
|
73915
74345
|
if (snapshot.operationId !== operationId || snapshot.repositoryRoot !== repositoryRoot || snapshot.path !== path || path !== expected || await realpath21(dirname7(path)) !== dirname7(path))
|
|
73916
74346
|
throw new Error("Accepted baseline does not belong to this operation or repository. Restore its original local receipt.");
|
|
73917
74347
|
await assertRepository(path, snapshot.branch, snapshot.commit);
|
|
@@ -73934,11 +74364,11 @@ async function createContinuousMissionWorkspace(repositoryRoot, operationId, bas
|
|
|
73934
74364
|
operationIdSchema.parse(missionId);
|
|
73935
74365
|
const baseline = await validateContinuousBaseline(repositoryRoot, operationId, baselinePath);
|
|
73936
74366
|
const root = await operationDirectory(repositoryRoot, operationId);
|
|
73937
|
-
const directory =
|
|
74367
|
+
const directory = join35(root, "workspaces", missionId);
|
|
73938
74368
|
await localDirectory(directory);
|
|
73939
|
-
const path =
|
|
74369
|
+
const path = join35(directory, "workspace");
|
|
73940
74370
|
const branch = `av-operation/${operationId}/${missionId}`;
|
|
73941
|
-
const recordPath =
|
|
74371
|
+
const recordPath = join35(directory, "workspace.json");
|
|
73942
74372
|
const raw = await readJson2(recordPath);
|
|
73943
74373
|
const record = raw ? missionWorkspaceSchema.parse(raw) : {
|
|
73944
74374
|
operationId,
|
|
@@ -73953,7 +74383,7 @@ async function createContinuousMissionWorkspace(repositoryRoot, operationId, bas
|
|
|
73953
74383
|
if (record.operationId !== operationId || record.repositoryRoot !== repositoryRoot || record.missionId !== missionId || record.baselinePath !== baseline.path || record.baselineCommit !== baseline.commit || record.path !== path || record.branch !== branch)
|
|
73954
74384
|
throw new Error("Child workspace identity does not match this operation's saved baseline. Restore its original receipt.");
|
|
73955
74385
|
if (!raw) {
|
|
73956
|
-
const preparedPath =
|
|
74386
|
+
const preparedPath = join35(directory, "prepared.json");
|
|
73957
74387
|
const prepared = await readJson2(preparedPath);
|
|
73958
74388
|
if (prepared && JSON.stringify(missionWorkspaceSchema.parse(prepared)) !== JSON.stringify(record)) {
|
|
73959
74389
|
const saved = missionWorkspaceSchema.parse(prepared);
|
|
@@ -74000,21 +74430,21 @@ var receiptSchema = strictObject({
|
|
|
74000
74430
|
at: exports_iso.datetime().optional()
|
|
74001
74431
|
});
|
|
74002
74432
|
async function localDirectory2(parent, name) {
|
|
74003
|
-
const path =
|
|
74004
|
-
const entry = await
|
|
74433
|
+
const path = join36(parent, name);
|
|
74434
|
+
const entry = await lstat19(path).catch((error) => {
|
|
74005
74435
|
if (error.code === "ENOENT")
|
|
74006
74436
|
return;
|
|
74007
74437
|
throw error;
|
|
74008
74438
|
});
|
|
74009
74439
|
if (!entry)
|
|
74010
74440
|
await mkdir17(path, { mode: 448 });
|
|
74011
|
-
const current = entry ?? await
|
|
74441
|
+
const current = entry ?? await lstat19(path);
|
|
74012
74442
|
if (current.isSymbolicLink() || !current.isDirectory() || await realpath22(path) !== path)
|
|
74013
74443
|
throw new Error("Source integration storage redirects. Restore its original private local directory before retrying.");
|
|
74014
74444
|
return path;
|
|
74015
74445
|
}
|
|
74016
74446
|
async function regularFile(path) {
|
|
74017
|
-
const entry = await
|
|
74447
|
+
const entry = await lstat19(path).catch((error) => {
|
|
74018
74448
|
if (error.code === "ENOENT")
|
|
74019
74449
|
return;
|
|
74020
74450
|
throw error;
|
|
@@ -74023,7 +74453,7 @@ async function regularFile(path) {
|
|
|
74023
74453
|
return;
|
|
74024
74454
|
if (entry.isSymbolicLink() || !entry.isFile())
|
|
74025
74455
|
throw new Error("Source integration receipts must be regular local files. Restore their original bytes before retrying.");
|
|
74026
|
-
return
|
|
74456
|
+
return readFile16(path);
|
|
74027
74457
|
}
|
|
74028
74458
|
async function sourceRoot(repositoryRoot) {
|
|
74029
74459
|
const root = await realpath22(repositoryRoot);
|
|
@@ -74042,8 +74472,8 @@ async function assertSettledSourceIntegrations(repositoryRoot, operationId, pend
|
|
|
74042
74472
|
operationIdSchema.parse(operationId);
|
|
74043
74473
|
let directory = await sourceRoot(repositoryRoot);
|
|
74044
74474
|
for (const part of [".agent-valley", "operations", operationId, "source-integrations"]) {
|
|
74045
|
-
directory =
|
|
74046
|
-
const entry = await
|
|
74475
|
+
directory = join36(directory, part);
|
|
74476
|
+
const entry = await lstat19(directory).catch((error) => {
|
|
74047
74477
|
if (error.code === "ENOENT")
|
|
74048
74478
|
return;
|
|
74049
74479
|
throw error;
|
|
@@ -74053,14 +74483,14 @@ async function assertSettledSourceIntegrations(repositoryRoot, operationId, pend
|
|
|
74053
74483
|
if (entry.isSymbolicLink() || !entry.isDirectory() || await realpath22(directory) !== directory)
|
|
74054
74484
|
throw new Error("Source integration storage redirects. Restore its original private directory before changing modes.");
|
|
74055
74485
|
}
|
|
74056
|
-
for (const entry of await
|
|
74486
|
+
for (const entry of await readdir11(directory, { withFileTypes: true })) {
|
|
74057
74487
|
operationIdSchema.parse(entry.name);
|
|
74058
|
-
const path =
|
|
74488
|
+
const path = join36(directory, entry.name);
|
|
74059
74489
|
if (entry.isSymbolicLink() || !entry.isDirectory() || await realpath22(path) !== path)
|
|
74060
74490
|
throw new Error("Source integration receipt storage redirects. Restore its original directory before changing modes.");
|
|
74061
|
-
const raw = await regularFile(
|
|
74491
|
+
const raw = await regularFile(join36(path, "integration.json"));
|
|
74062
74492
|
if (!raw) {
|
|
74063
|
-
if ((await
|
|
74493
|
+
if ((await readdir11(path)).length)
|
|
74064
74494
|
throw new Error("A source integration receipt is missing beside retained artifacts. Resume worktree integration and reconcile the original transaction before selecting snapshot-only.");
|
|
74065
74495
|
continue;
|
|
74066
74496
|
}
|
|
@@ -74079,8 +74509,8 @@ async function inspectPath(root, path) {
|
|
|
74079
74509
|
let current = root;
|
|
74080
74510
|
const parts = path.split("/");
|
|
74081
74511
|
for (let index = 0;index < parts.length; index += 1) {
|
|
74082
|
-
current =
|
|
74083
|
-
const entry = await
|
|
74512
|
+
current = join36(current, parts[index] ?? "");
|
|
74513
|
+
const entry = await lstat19(current).catch((error) => {
|
|
74084
74514
|
if (error.code === "ENOENT")
|
|
74085
74515
|
return;
|
|
74086
74516
|
throw error;
|
|
@@ -74142,7 +74572,7 @@ async function integrateContinuousSource(operation, previous, next, signal) {
|
|
|
74142
74572
|
throw new Error("Source integration snapshot differs from its original receipt. Restore the accepted baseline before retrying.");
|
|
74143
74573
|
}
|
|
74144
74574
|
const gitDirectory = await realpath22(resolve25(root, (await parallelGit(root, ["rev-parse", "--git-common-dir"])).trim()));
|
|
74145
|
-
const unlock = await lockRecord(
|
|
74575
|
+
const unlock = await lockRecord(join36(gitDirectory, "agent-valley-delivery.lock"), "Source integration", "source-integration");
|
|
74146
74576
|
try {
|
|
74147
74577
|
const assertIdentity = async () => {
|
|
74148
74578
|
signal?.throwIfAborted();
|
|
@@ -74154,8 +74584,8 @@ async function integrateContinuousSource(operation, previous, next, signal) {
|
|
|
74154
74584
|
let directory = root;
|
|
74155
74585
|
for (const part of [".agent-valley", "operations", operation.id, "source-integrations", missionId])
|
|
74156
74586
|
directory = await localDirectory2(directory, part);
|
|
74157
|
-
const recordPath =
|
|
74158
|
-
const patchPath =
|
|
74587
|
+
const recordPath = join36(directory, "integration.json");
|
|
74588
|
+
const patchPath = join36(directory, "changes.patch");
|
|
74159
74589
|
const saved = await regularFile(recordPath);
|
|
74160
74590
|
const before = await parallelTreeImages(next.path, previous.baselineTree);
|
|
74161
74591
|
const after = await parallelTreeImages(next.path, next.baselineTree);
|
|
@@ -74268,7 +74698,7 @@ init_execution();
|
|
|
74268
74698
|
init_runtime_ignore();
|
|
74269
74699
|
|
|
74270
74700
|
// src/chief-continuous-decision.ts
|
|
74271
|
-
import { join as
|
|
74701
|
+
import { join as join49 } from "node:path";
|
|
74272
74702
|
// ../../packages/core/src/chief/coordinator-checkpoint.ts
|
|
74273
74703
|
class CheckpointError extends Error {
|
|
74274
74704
|
}
|
|
@@ -74516,39 +74946,54 @@ function createMissionRun(mission, ports, assertContract, checkAbort, persist =
|
|
|
74516
74946
|
recordHandoffReview(mission, actor, stage, taskId);
|
|
74517
74947
|
checkAbort();
|
|
74518
74948
|
assertContract();
|
|
74519
|
-
|
|
74520
|
-
|
|
74521
|
-
|
|
74522
|
-
|
|
74949
|
+
const reserve = async (claim = () => {}) => {
|
|
74950
|
+
reserveExecutionRun(mission);
|
|
74951
|
+
claim();
|
|
74952
|
+
if (mission.executionPolicy)
|
|
74953
|
+
await persist("Actor budget reservation could not be saved. Restore writable mission storage before resuming.");
|
|
74954
|
+
};
|
|
74955
|
+
if (!ports.deferredDispatchAdmission)
|
|
74956
|
+
await reserve();
|
|
74523
74957
|
const before = await ports.fingerprint(mission);
|
|
74524
74958
|
checkAbort();
|
|
74525
74959
|
assertContract();
|
|
74526
|
-
|
|
74527
|
-
|
|
74528
|
-
|
|
74529
|
-
|
|
74530
|
-
|
|
74531
|
-
|
|
74532
|
-
|
|
74533
|
-
|
|
74534
|
-
|
|
74535
|
-
|
|
74536
|
-
|
|
74537
|
-
|
|
74538
|
-
|
|
74539
|
-
|
|
74540
|
-
|
|
74960
|
+
let dispatchAdmitted = false;
|
|
74961
|
+
const beforeDispatch = async (claim = () => {}) => {
|
|
74962
|
+
checkAbort();
|
|
74963
|
+
assertContract();
|
|
74964
|
+
if (ports.deferredDispatchAdmission)
|
|
74965
|
+
await reserve(claim);
|
|
74966
|
+
if (effect) {
|
|
74967
|
+
const previous = effect.effectState ?? "not-started";
|
|
74968
|
+
effect.effectState = "running";
|
|
74969
|
+
try {
|
|
74970
|
+
await persist("External dispatch checkpoint could not be saved. The Actor was not invoked and the effect remains not started.");
|
|
74971
|
+
} catch (error) {
|
|
74972
|
+
effect.effectState = previous;
|
|
74973
|
+
throw error;
|
|
74974
|
+
}
|
|
74975
|
+
try {
|
|
74976
|
+
checkAbort();
|
|
74977
|
+
} catch (error) {
|
|
74978
|
+
effect.effectState = previous;
|
|
74979
|
+
await persist("The Actor was not invoked, but its cancelled dispatch checkpoint could not be saved. The effect remains not started in the retained coordinator state.");
|
|
74980
|
+
throw error;
|
|
74981
|
+
}
|
|
74541
74982
|
}
|
|
74542
|
-
|
|
74983
|
+
dispatchAdmitted = true;
|
|
74984
|
+
};
|
|
74985
|
+
if (!ports.deferredDispatchAdmission)
|
|
74986
|
+
await beforeDispatch();
|
|
74543
74987
|
let output;
|
|
74544
74988
|
try {
|
|
74545
|
-
output = taskId || context || omaActor ? await ports.runAgent(actor, prompt, mission, stage, {
|
|
74989
|
+
output = taskId || context || omaActor || ports.deferredDispatchAdmission ? await ports.runAgent(actor, prompt, mission, stage, {
|
|
74546
74990
|
...context,
|
|
74547
74991
|
...taskId ? { taskId } : {},
|
|
74548
|
-
...omaActor ? { omaActor } : {}
|
|
74992
|
+
...omaActor ? { omaActor } : {},
|
|
74993
|
+
...ports.deferredDispatchAdmission ? { beforeDispatch } : {}
|
|
74549
74994
|
}) : await ports.runAgent(actor, prompt, mission, stage);
|
|
74550
74995
|
} catch (error) {
|
|
74551
|
-
if (effect)
|
|
74996
|
+
if (effect && dispatchAdmitted)
|
|
74552
74997
|
effect.effectState = "unknown";
|
|
74553
74998
|
assertNoUncertainExecution(mission);
|
|
74554
74999
|
mission.fingerprint = await ports.fingerprint(mission);
|
|
@@ -74656,17 +75101,17 @@ init_execution();
|
|
|
74656
75101
|
|
|
74657
75102
|
// ../../packages/core/src/chief/runtime.ts
|
|
74658
75103
|
import { randomUUID as randomUUID16 } from "node:crypto";
|
|
74659
|
-
import { join as
|
|
75104
|
+
import { join as join41, resolve as resolve28 } from "node:path";
|
|
74660
75105
|
|
|
74661
75106
|
// ../../packages/core/src/oma/receipt-adapter.ts
|
|
74662
75107
|
import { spawnSync as spawnSync2 } from "node:child_process";
|
|
74663
75108
|
import { existsSync as existsSync4, lstatSync as lstatSync3, readFileSync as readFileSync9 } from "node:fs";
|
|
74664
75109
|
import { mkdir as mkdir18, writeFile as writeFile11 } from "node:fs/promises";
|
|
74665
|
-
import { basename as basename2, dirname as dirname9, isAbsolute as
|
|
75110
|
+
import { basename as basename2, dirname as dirname9, isAbsolute as isAbsolute15, join as join39, relative as relative14, resolve as resolve27, sep as sep14 } from "node:path";
|
|
74666
75111
|
|
|
74667
75112
|
// ../../packages/core/src/config/workflow-router.ts
|
|
74668
75113
|
import { readFileSync as readFileSync8 } from "node:fs";
|
|
74669
|
-
import { join as
|
|
75114
|
+
import { join as join37 } from "node:path";
|
|
74670
75115
|
var INFORMATIONAL_WINDOW = 60;
|
|
74671
75116
|
function normalizeForRouting(text) {
|
|
74672
75117
|
return text.normalize("NFKC").toLowerCase().replace(/\s+/g, " ");
|
|
@@ -74833,7 +75278,7 @@ function parseTriggerTable(content) {
|
|
|
74833
75278
|
}
|
|
74834
75279
|
var triggerTableCache = new Map;
|
|
74835
75280
|
function getCachedTriggerTable(rootDir = process.cwd()) {
|
|
74836
|
-
const path =
|
|
75281
|
+
const path = join37(rootDir, ".agents", "hooks", "core", "triggers.json");
|
|
74837
75282
|
let content = null;
|
|
74838
75283
|
try {
|
|
74839
75284
|
content = readFileSync8(path, "utf-8");
|
|
@@ -74981,11 +75426,11 @@ function ensureLatestOmaCli(options = {}) {
|
|
|
74981
75426
|
// ../../packages/core/src/oma/receipt-storage.ts
|
|
74982
75427
|
import { createHash as createHash24 } from "node:crypto";
|
|
74983
75428
|
import { lstatSync as lstatSync2, readdirSync, realpathSync as realpathSync6 } from "node:fs";
|
|
74984
|
-
import { homedir as
|
|
74985
|
-
import { basename, dirname as dirname8, isAbsolute as
|
|
75429
|
+
import { homedir as homedir8 } from "node:os";
|
|
75430
|
+
import { basename, dirname as dirname8, isAbsolute as isAbsolute14, join as join38, relative as relative13, resolve as resolve26, sep as sep13 } from "node:path";
|
|
74986
75431
|
var OMA_RUN_ID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
74987
75432
|
function absolutePath(value, key) {
|
|
74988
|
-
if (!
|
|
75433
|
+
if (!isAbsolute14(value) || Array.from(value).some((character) => character.charCodeAt(0) < 32 || character.charCodeAt(0) === 127))
|
|
74989
75434
|
throw new Error(`${key} must be an absolute path without control characters`);
|
|
74990
75435
|
return resolve26(value);
|
|
74991
75436
|
}
|
|
@@ -74994,11 +75439,11 @@ function omaReceiptDirectories(workspace, options = {}) {
|
|
|
74994
75439
|
const profile = env.OMA_PROFILE ?? "0";
|
|
74995
75440
|
if (!/^(0|[1-9][0-9]{0,9})$/.test(profile))
|
|
74996
75441
|
throw new Error("OMA_PROFILE must be a non-negative profile number");
|
|
74997
|
-
const stateHome = env.OMA_STATE_HOME === undefined ? absolutePath(env.OMA_HOME ||
|
|
75442
|
+
const stateHome = env.OMA_STATE_HOME === undefined ? absolutePath(env.OMA_HOME || join38(options.home ?? homedir8(), ".oma"), "OMA_HOME") : absolutePath(env.OMA_STATE_HOME, "OMA_STATE_HOME");
|
|
74998
75443
|
const project = createHash24("sha256").update(realpathSync6(resolve26(workspace))).digest("hex");
|
|
74999
75444
|
return [
|
|
75000
|
-
|
|
75001
|
-
...profile === "0" ? [
|
|
75445
|
+
join38(stateHome, "u", profile, "projects", project, "agent-runs"),
|
|
75446
|
+
...profile === "0" ? [join38(resolve26(workspace), ".agents", "state", "agent-runs")] : []
|
|
75002
75447
|
];
|
|
75003
75448
|
}
|
|
75004
75449
|
function regularDirectory(path) {
|
|
@@ -75016,12 +75461,12 @@ function regularDirectory(path) {
|
|
|
75016
75461
|
function validateDirectory(directory, workspace) {
|
|
75017
75462
|
if (!regularDirectory(directory))
|
|
75018
75463
|
return false;
|
|
75019
|
-
const legacy =
|
|
75464
|
+
const legacy = join38(resolve26(workspace), ".agents", "state", "agent-runs");
|
|
75020
75465
|
const boundary = directory === legacy ? resolve26(workspace) : dirname8(dirname8(dirname8(dirname8(dirname8(directory)))));
|
|
75021
75466
|
const components = relative13(boundary, directory).split(sep13).filter(Boolean);
|
|
75022
75467
|
let path = boundary;
|
|
75023
75468
|
for (const component of components) {
|
|
75024
|
-
path =
|
|
75469
|
+
path = join38(path, component);
|
|
75025
75470
|
if (!regularDirectory(path))
|
|
75026
75471
|
throw new Error("OMA receipt directory changed during inspection");
|
|
75027
75472
|
}
|
|
@@ -75031,7 +75476,7 @@ function listOmaRunFiles(workspace, options = {}) {
|
|
|
75031
75476
|
return omaReceiptDirectories(workspace, options).flatMap((directory) => {
|
|
75032
75477
|
if (!validateDirectory(directory, workspace))
|
|
75033
75478
|
return [];
|
|
75034
|
-
return readdirSync(directory).filter((name) => name.endsWith(".json") && OMA_RUN_ID.test(name.slice(0, -5))).map((name) =>
|
|
75479
|
+
return readdirSync(directory).filter((name) => name.endsWith(".json") && OMA_RUN_ID.test(name.slice(0, -5))).map((name) => join38(directory, name));
|
|
75035
75480
|
});
|
|
75036
75481
|
}
|
|
75037
75482
|
function resolveOmaReceiptPath(workspace, entry, options = {}) {
|
|
@@ -75039,8 +75484,8 @@ function resolveOmaReceiptPath(workspace, entry, options = {}) {
|
|
|
75039
75484
|
if (!name.endsWith(".json") || !OMA_RUN_ID.test(name.slice(0, -5)))
|
|
75040
75485
|
throw new Error("Invalid receipt filename");
|
|
75041
75486
|
if (entry === name)
|
|
75042
|
-
return
|
|
75043
|
-
if (!
|
|
75487
|
+
return join38(resolve26(workspace), ".agents", "state", "agent-runs", name);
|
|
75488
|
+
if (!isAbsolute14(entry) || resolve26(entry) !== entry)
|
|
75044
75489
|
throw new Error("Invalid receipt path");
|
|
75045
75490
|
if (!omaReceiptDirectories(workspace, options).includes(dirname8(entry)))
|
|
75046
75491
|
throw new Error("OMA receipt is outside the selected project/profile");
|
|
@@ -75055,7 +75500,7 @@ var HASH = /^[a-f0-9]{64}$/;
|
|
|
75055
75500
|
function createOmaEvidenceIO(options = {}) {
|
|
75056
75501
|
const env = { ...options.env ?? process.env, OMA_SKIP_VERSION_CHECK: "1" };
|
|
75057
75502
|
if (options.home !== undefined && !env.OMA_HOME)
|
|
75058
|
-
env.OMA_HOME =
|
|
75503
|
+
env.OMA_HOME = join39(options.home, ".oma");
|
|
75059
75504
|
const storage = { ...options, env };
|
|
75060
75505
|
return {
|
|
75061
75506
|
listRunFiles: (workspacePath) => listOmaRunFiles(workspacePath, storage),
|
|
@@ -75102,12 +75547,12 @@ async function prepareOmaAttempt(request, dependencies = {}) {
|
|
|
75102
75547
|
const routed = routeIssue(`${request.issue.title}
|
|
75103
75548
|
${request.issue.description ?? ""}`, table);
|
|
75104
75549
|
for (const workflow of routed.workflows) {
|
|
75105
|
-
const file =
|
|
75550
|
+
const file = join39(request.workspace.path, ".agents", "workflows", `${workflow}.md`);
|
|
75106
75551
|
if (!existsSync4(file))
|
|
75107
75552
|
throw new Error(`OMA workflow file missing in target worktree: ${file}`);
|
|
75108
75553
|
}
|
|
75109
75554
|
await ensureLatestOmaCli({ io: dependencies.latestCliIO });
|
|
75110
|
-
const path =
|
|
75555
|
+
const path = join39(request.workspace.path, ".agents", "results", `plan-${request.attempt.id}.json`);
|
|
75111
75556
|
const plan = {
|
|
75112
75557
|
session_id: request.attempt.id,
|
|
75113
75558
|
lineage_id: request.attempt.id,
|
|
@@ -75132,7 +75577,7 @@ ${request.issue.description ?? ""}`, table);
|
|
|
75132
75577
|
}
|
|
75133
75578
|
]
|
|
75134
75579
|
};
|
|
75135
|
-
await mkdir18(
|
|
75580
|
+
await mkdir18(join39(request.workspace.path, ".agents", "results"), { recursive: true });
|
|
75136
75581
|
await writeFile11(path, JSON.stringify(plan, null, 2), { encoding: "utf-8", flag: "wx" });
|
|
75137
75582
|
return path;
|
|
75138
75583
|
}
|
|
@@ -75241,10 +75686,10 @@ function validateOmaEvidence(request, io = createOmaEvidenceIO()) {
|
|
|
75241
75686
|
const expanded = template.replaceAll("{{attempt.id}}", request.attempt.id);
|
|
75242
75687
|
const target = resolve27(root, expanded);
|
|
75243
75688
|
const subpath = relative14(root, target);
|
|
75244
|
-
if (
|
|
75689
|
+
if (isAbsolute15(expanded) || expanded.split(/[\\/]/).includes("..") || subpath === "" || subpath === ".." || subpath.startsWith(`..${sep14}`) || isAbsolute15(subpath)) {
|
|
75245
75690
|
return fail("Configured analysis report escapes the workspace");
|
|
75246
75691
|
}
|
|
75247
|
-
if (!isRecord(run.artifacts) || !Object.entries(run.artifacts).some(([path, hash]) => !
|
|
75692
|
+
if (!isRecord(run.artifacts) || !Object.entries(run.artifacts).some(([path, hash]) => !isAbsolute15(path) && !path.split(/[\\/]/).includes("..") && resolve27(root, path) === target && HASH.test(String(hash)))) {
|
|
75248
75693
|
return fail("OMA receipt does not bind the configured current-attempt report");
|
|
75249
75694
|
}
|
|
75250
75695
|
}
|
|
@@ -75289,7 +75734,7 @@ import { posix } from "node:path";
|
|
|
75289
75734
|
// ../../packages/core/src/oma/skill-matrix-io.ts
|
|
75290
75735
|
init_skill_matrix_schema();
|
|
75291
75736
|
import { execFile as execFile5 } from "node:child_process";
|
|
75292
|
-
import { constants as
|
|
75737
|
+
import { constants as constants13 } from "node:fs";
|
|
75293
75738
|
import { open as open14 } from "node:fs/promises";
|
|
75294
75739
|
var MAX_BYTES = 4 * 1024 * 1024;
|
|
75295
75740
|
async function command(binary, args, signal) {
|
|
@@ -75309,7 +75754,7 @@ async function command(binary, args, signal) {
|
|
|
75309
75754
|
});
|
|
75310
75755
|
}
|
|
75311
75756
|
async function readReport(path) {
|
|
75312
|
-
const file = await open14(path,
|
|
75757
|
+
const file = await open14(path, constants13.O_RDONLY | constants13.O_NOFOLLOW | constants13.O_NONBLOCK);
|
|
75313
75758
|
try {
|
|
75314
75759
|
const info = await file.stat();
|
|
75315
75760
|
if (!info.isFile() || info.size > MAX_BYTES)
|
|
@@ -75492,13 +75937,12 @@ function assertCompatibleRoute(route, inspection) {
|
|
|
75492
75937
|
}
|
|
75493
75938
|
|
|
75494
75939
|
// ../../packages/core/src/chief/runtime.ts
|
|
75495
|
-
init_worktree_lifecycle();
|
|
75496
75940
|
init_execution();
|
|
75497
75941
|
|
|
75498
75942
|
// ../../packages/core/src/chief/parallel-workspace.ts
|
|
75499
75943
|
import { createHash as createHash25 } from "node:crypto";
|
|
75500
|
-
import { lstat as
|
|
75501
|
-
import { dirname as dirname10, join as
|
|
75944
|
+
import { lstat as lstat20, mkdir as mkdir19, readFile as readFile17, realpath as realpath24, rm as rm6, writeFile as writeFile12 } from "node:fs/promises";
|
|
75945
|
+
import { dirname as dirname10, join as join40, sep as sep15 } from "node:path";
|
|
75502
75946
|
init_parallel_contract();
|
|
75503
75947
|
|
|
75504
75948
|
// ../../packages/core/src/chief/workspace.ts
|
|
@@ -75529,7 +75973,7 @@ function identity3(missionId, taskId, attempt) {
|
|
|
75529
75973
|
async function paths(source, missionId, taskId, attempt) {
|
|
75530
75974
|
const root = await parallelRoot(source);
|
|
75531
75975
|
const key = identity3(missionId, taskId, attempt);
|
|
75532
|
-
const directory =
|
|
75976
|
+
const directory = join40(root, "deliveries", key);
|
|
75533
75977
|
await mkdir19(directory, { recursive: true, mode: 448 });
|
|
75534
75978
|
const actual = await realpath24(directory);
|
|
75535
75979
|
if (actual !== directory)
|
|
@@ -75537,10 +75981,10 @@ async function paths(source, missionId, taskId, attempt) {
|
|
|
75537
75981
|
return {
|
|
75538
75982
|
root,
|
|
75539
75983
|
directory: actual,
|
|
75540
|
-
path:
|
|
75541
|
-
record:
|
|
75542
|
-
delivery:
|
|
75543
|
-
patch:
|
|
75984
|
+
path: join40(root, "workspaces", key),
|
|
75985
|
+
record: join40(actual, "workspace.json"),
|
|
75986
|
+
delivery: join40(actual, "delivery.json"),
|
|
75987
|
+
patch: join40(actual, "changes.patch"),
|
|
75544
75988
|
branch: `av-task/${key}`
|
|
75545
75989
|
};
|
|
75546
75990
|
}
|
|
@@ -75566,7 +76010,7 @@ async function validateWorkspace(mission, workspace) {
|
|
|
75566
76010
|
async function prepareTaskWorktree(mission, taskId, attempt, baseline) {
|
|
75567
76011
|
await assertMissionWorkspace(mission);
|
|
75568
76012
|
const location2 = await paths(mission.workspace.path, mission.id, taskId, attempt);
|
|
75569
|
-
const existing = await
|
|
76013
|
+
const existing = await readFile17(location2.record, "utf8").catch((error) => {
|
|
75570
76014
|
if (error.code === "ENOENT")
|
|
75571
76015
|
return;
|
|
75572
76016
|
throw error;
|
|
@@ -75581,7 +76025,7 @@ async function prepareTaskWorktree(mission, taskId, attempt, baseline) {
|
|
|
75581
76025
|
await mkdir19(dirname10(location2.path), { recursive: true, mode: 448 });
|
|
75582
76026
|
if (await realpath24(dirname10(location2.path)) !== dirname10(location2.path))
|
|
75583
76027
|
throw new Error("Parallel workspaces directory must not redirect through a symlink.");
|
|
75584
|
-
if (await
|
|
76028
|
+
if (await lstat20(location2.path).catch(() => {
|
|
75585
76029
|
return;
|
|
75586
76030
|
}))
|
|
75587
76031
|
throw new Error(`Unrecorded parallel workspace exists at ${location2.path}. Preserve its edits and inspect it before retrying.`);
|
|
@@ -75625,7 +76069,7 @@ async function collectTaskDelivery(mission, workspace) {
|
|
|
75625
76069
|
const location2 = await paths(mission.workspace.path, mission.id, workspace.taskId, workspace.attempt);
|
|
75626
76070
|
if (workspace.path !== location2.path || workspace.branch !== location2.branch)
|
|
75627
76071
|
throw new Error("Restore the recorded private task workspace path and branch before resuming.");
|
|
75628
|
-
const existing = await
|
|
76072
|
+
const existing = await readFile17(location2.delivery, "utf8").catch((error) => {
|
|
75629
76073
|
if (error.code === "ENOENT")
|
|
75630
76074
|
return;
|
|
75631
76075
|
throw error;
|
|
@@ -75661,7 +76105,7 @@ async function collectTaskDelivery(mission, workspace) {
|
|
|
75661
76105
|
try {
|
|
75662
76106
|
await writeFile12(location2.patch, patch, { flag: "wx", mode: 384 });
|
|
75663
76107
|
} catch (error) {
|
|
75664
|
-
if (error.code !== "EEXIST" || !same(await
|
|
76108
|
+
if (error.code !== "EEXIST" || !same(await readFile17(location2.patch, "utf8"), patch))
|
|
75665
76109
|
throw error;
|
|
75666
76110
|
}
|
|
75667
76111
|
const delivery = {
|
|
@@ -75680,7 +76124,7 @@ async function integrateTaskDelivery(mission, input) {
|
|
|
75680
76124
|
await assertMissionWorkspace(mission);
|
|
75681
76125
|
parallelDeliverySchema.parse(input);
|
|
75682
76126
|
const location2 = await paths(mission.workspace.path, mission.id, input.workspace.taskId, input.workspace.attempt);
|
|
75683
|
-
const delivery = parallelDeliverySchema.parse(JSON.parse(await
|
|
76127
|
+
const delivery = parallelDeliverySchema.parse(JSON.parse(await readFile17(location2.delivery, "utf8")));
|
|
75684
76128
|
if (delivery.workspace.missionId !== mission.id || !same(delivery.workspace, input.workspace) || delivery.patchSha256 !== input.patchSha256 || delivery.patchPath !== location2.patch)
|
|
75685
76129
|
throw new Error("Parallel delivery does not match its persisted task identity and patch. Inspect the saved artifacts before recovery.");
|
|
75686
76130
|
const result = await integrateContentTransaction(mission.workspace.path, delivery, {
|
|
@@ -75693,7 +76137,7 @@ async function integrateTaskDelivery(mission, input) {
|
|
|
75693
76137
|
async function disposeTaskWorktree(workspace) {
|
|
75694
76138
|
parallelWorkspaceSchema.parse(workspace);
|
|
75695
76139
|
const location2 = await paths(workspace.sourceWorkspacePath, workspace.missionId, workspace.taskId, workspace.attempt);
|
|
75696
|
-
const raw = await
|
|
76140
|
+
const raw = await readFile17(location2.delivery, "utf8").catch(() => {
|
|
75697
76141
|
return;
|
|
75698
76142
|
});
|
|
75699
76143
|
if (!raw)
|
|
@@ -75708,7 +76152,7 @@ async function disposeTaskWorktree(workspace) {
|
|
|
75708
76152
|
assertParallelPath(location2.root, workspace.path);
|
|
75709
76153
|
if (workspace.path !== location2.path)
|
|
75710
76154
|
throw new Error("Refusing to remove an unrecognized parallel Actor workspace.");
|
|
75711
|
-
if (await
|
|
76155
|
+
if (await lstat20(workspace.path).catch(() => {
|
|
75712
76156
|
return;
|
|
75713
76157
|
})) {
|
|
75714
76158
|
const child = await captureParallelBaseline(workspace.path);
|
|
@@ -75726,8 +76170,34 @@ async function integrateTaskWorktree(mission, workspace) {
|
|
|
75726
76170
|
return integrateTaskDelivery(mission, await collectTaskDelivery(mission, workspace));
|
|
75727
76171
|
}
|
|
75728
76172
|
|
|
75729
|
-
// ../../packages/core/src/chief/runtime.ts
|
|
75730
|
-
|
|
76173
|
+
// ../../packages/core/src/chief/runtime-admission.ts
|
|
76174
|
+
async function admitNativeDispatch(mission, actor, attempt, stage, context, local, reason) {
|
|
76175
|
+
assertActorAvailable(mission, actor, stage);
|
|
76176
|
+
let entry;
|
|
76177
|
+
const claim = () => {
|
|
76178
|
+
if (entry)
|
|
76179
|
+
throw new Error("Native dispatch admission claimed the same Actor call twice.");
|
|
76180
|
+
assertActorAvailable(mission, actor, stage);
|
|
76181
|
+
entry = startOperatingRun(mission, actor, attempt, stage, context?.taskId, reason);
|
|
76182
|
+
entry.executionRecovery = local ? "local-process" : "reconcile";
|
|
76183
|
+
};
|
|
76184
|
+
try {
|
|
76185
|
+
if (context?.beforeDispatch)
|
|
76186
|
+
await context.beforeDispatch(claim);
|
|
76187
|
+
else
|
|
76188
|
+
claim();
|
|
76189
|
+
if (!entry)
|
|
76190
|
+
throw new Error("Native dispatch admission did not claim its Actor call.");
|
|
76191
|
+
return entry;
|
|
76192
|
+
} catch (error) {
|
|
76193
|
+
if (entry)
|
|
76194
|
+
mission.operations?.runs.splice(mission.operations.runs.indexOf(entry), 1);
|
|
76195
|
+
throw error;
|
|
76196
|
+
}
|
|
76197
|
+
}
|
|
76198
|
+
|
|
76199
|
+
// ../../packages/core/src/chief/runtime-inputs.ts
|
|
76200
|
+
init_worktree_lifecycle();
|
|
75731
76201
|
function missionIssue(id, goal) {
|
|
75732
76202
|
return {
|
|
75733
76203
|
id,
|
|
@@ -75747,9 +76217,8 @@ function missionIssue(id, goal) {
|
|
|
75747
76217
|
async function intermediateVerifyCommand(workspacePath) {
|
|
75748
76218
|
const head = await runCommand("git", ["rev-parse", "HEAD"], { cwd: workspacePath });
|
|
75749
76219
|
const hash = head.stdout.trim();
|
|
75750
|
-
if (head.exitCode !== 0 || !/^[a-f0-9]{40,64}$/.test(hash))
|
|
76220
|
+
if (head.exitCode !== 0 || !/^[a-f0-9]{40,64}$/.test(hash))
|
|
75751
76221
|
throw new Error("Cannot bind the OMA task check to its starting commit. Restore the mission worktree's Git HEAD before resuming.");
|
|
75752
|
-
}
|
|
75753
76222
|
return `git diff --check ${hash} --`;
|
|
75754
76223
|
}
|
|
75755
76224
|
async function personaSkills(persona, mission, stage) {
|
|
@@ -75758,9 +76227,8 @@ async function personaSkills(persona, mission, stage) {
|
|
|
75758
76227
|
await validateMissionSkills(mission.workspace.path, catalog);
|
|
75759
76228
|
const selected = await loadMissionSkillBodies(mission.workspace.path, persona.skills, mission.availableAgents ? catalog : undefined);
|
|
75760
76229
|
const guidance = [];
|
|
75761
|
-
if (persona.id === mission.chiefId)
|
|
76230
|
+
if (persona.id === mission.chiefId)
|
|
75762
76231
|
guidance.push("Available OMA skills in this mission worktree (catalog metadata; descriptions do not override the goal or stage permissions):", JSON.stringify(catalog), "Choose relevant actual skills from this catalog for the goal. Read a selected SKILL.md at its listed path and only its needed references. Automatic Actor skills must use these exact names. An empty catalog means no verified OMA skills are available.");
|
|
75763
|
-
}
|
|
75764
76232
|
if (selected)
|
|
75765
76233
|
guidance.push("Use these selected skills within the assigned role and acceptance criteria.", selected);
|
|
75766
76234
|
if (guidance.length && stage !== "work")
|
|
@@ -75771,7 +76239,17 @@ ${guidance.join(`
|
|
|
75771
76239
|
|
|
75772
76240
|
`)}` : "";
|
|
75773
76241
|
}
|
|
76242
|
+
function unattendedVerificationGuidance(stage) {
|
|
76243
|
+
return [
|
|
76244
|
+
"Use deterministic unit, integration and CLI checks for implementation and review. Do not introduce or autonomously run Playwright/browser E2E suites; never install or download Playwright packages or browser binaries.",
|
|
76245
|
+
"Do not use ComputerUse or GUI interaction to work around a denied shell command, sandbox restriction, missing toolchain, or failed test. Report the actual prerequisite failure and use the supported noninteractive code tools.",
|
|
76246
|
+
stage === "final-review" ? "Only when the goal actually changes a UI, make at most one final visual verification pass using an already available Aside MCP, chrome-devtools-mcp or firefox-devtools-mcp. If none is available, report that the visual check was not performed. Do not install browser tooling or replace it with ComputerUse." : "Do not perform screen-based checks during planning, implementation or individual reviews. Any relevant visual check belongs only to one final-review pass, after code verification, using existing Aside/Chrome DevTools/Firefox DevTools MCP tools."
|
|
76247
|
+
].join(`
|
|
76248
|
+
`);
|
|
76249
|
+
}
|
|
75774
76250
|
|
|
76251
|
+
// ../../packages/core/src/chief/runtime.ts
|
|
76252
|
+
init_tool_environment();
|
|
75775
76253
|
class ChiefRuntime {
|
|
75776
76254
|
store;
|
|
75777
76255
|
signal;
|
|
@@ -75795,6 +76273,7 @@ class ChiefRuntime {
|
|
|
75795
76273
|
ports() {
|
|
75796
76274
|
return {
|
|
75797
76275
|
signal: this.signal,
|
|
76276
|
+
deferredDispatchAdmission: true,
|
|
75798
76277
|
...this.discoverReadyAgents ? { discoverReadyAgents: this.discoverReadyAgents } : {},
|
|
75799
76278
|
...this.discoverFreeModels ? { discoverFreeModels: this.discoverFreeModels } : {},
|
|
75800
76279
|
prepareWork: (persona, mission, context) => this.prepareWork(persona, mission, context),
|
|
@@ -75832,7 +76311,7 @@ class ChiefRuntime {
|
|
|
75832
76311
|
const workspace = context?.workspace ?? mission.workspace;
|
|
75833
76312
|
const savedCatalog = workspace === mission.workspace ? mission.availableSkills : mission.availableSkills?.map((skill) => ({
|
|
75834
76313
|
...skill,
|
|
75835
|
-
path:
|
|
76314
|
+
path: join41(workspace.path, ".agents", "skills", skill.name, "SKILL.md")
|
|
75836
76315
|
}));
|
|
75837
76316
|
const catalog = savedCatalog ?? await discoverMissionSkills(workspace.path);
|
|
75838
76317
|
if (!requiresOmaActor({ oma: mission.oma, availableSkills: catalog }))
|
|
@@ -75881,6 +76360,7 @@ class ChiefRuntime {
|
|
|
75881
76360
|
async executeAgent(persona, prompt, mission, stage, context) {
|
|
75882
76361
|
const signal = context?.signal ?? this.signal;
|
|
75883
76362
|
const workspace = context?.workspace ?? mission.workspace;
|
|
76363
|
+
const requestedPersona = persona;
|
|
75884
76364
|
if (stage === "plan" && mission.availableSkills === undefined) {
|
|
75885
76365
|
signal?.throwIfAborted();
|
|
75886
76366
|
mission.availableSkills = await discoverMissionSkills(mission.workspace.path);
|
|
@@ -75890,7 +76370,7 @@ class ChiefRuntime {
|
|
|
75890
76370
|
workspace,
|
|
75891
76371
|
availableSkills: mission.availableSkills?.map((skill) => ({
|
|
75892
76372
|
...skill,
|
|
75893
|
-
path:
|
|
76373
|
+
path: join41(workspace.path, ".agents", "skills", skill.name, "SKILL.md")
|
|
75894
76374
|
}))
|
|
75895
76375
|
};
|
|
75896
76376
|
if (signal?.aborted)
|
|
@@ -75906,13 +76386,12 @@ class ChiefRuntime {
|
|
|
75906
76386
|
message: `${compatibilityPolicy.mode}: ${compatibility.routes.map((entry) => `${entry.actorType}/${entry.model ?? "native default"} ${entry.status}: ${entry.reason}`).join("; ")} Scope: ${compatibility.scope}.`,
|
|
75907
76387
|
...context?.taskId ? { taskId: context.taskId } : {}
|
|
75908
76388
|
});
|
|
75909
|
-
|
|
76389
|
+
let route = context?.handoff ? { actor: persona, reason: context.handoff } : stage === "work" ? selectWorkActor(mission, persona, context?.taskId, compatibleRoutes) : undefined;
|
|
75910
76390
|
persona = route?.actor ?? persona;
|
|
75911
76391
|
if (compatibility && compatibilityPolicy) {
|
|
75912
76392
|
if (compatibilityPolicy.mode === "require")
|
|
75913
76393
|
assertCompatibleRoute({ actorType: persona.agentType, model: persona.model }, compatibility);
|
|
75914
76394
|
}
|
|
75915
|
-
this.onStage(stage, persona);
|
|
75916
76395
|
const attempt = {
|
|
75917
76396
|
id: randomUUID16(),
|
|
75918
76397
|
issueId: mission.id,
|
|
@@ -75935,6 +76414,9 @@ class ChiefRuntime {
|
|
|
75935
76414
|
|
|
75936
76415
|
${buildOmaGuidance(evidence)}`;
|
|
75937
76416
|
}
|
|
76417
|
+
prompt += `
|
|
76418
|
+
|
|
76419
|
+
${unattendedVerificationGuidance(stage)}`;
|
|
75938
76420
|
prompt += omaActor ? `
|
|
75939
76421
|
|
|
75940
76422
|
${omaActor.guidance}` : await personaSkills(persona, localMission, stage);
|
|
@@ -75945,12 +76427,16 @@ The operator explicitly forwards these tool environment variable names: ${JSON.s
|
|
|
75945
76427
|
prompt += `
|
|
75946
76428
|
|
|
75947
76429
|
You are already running inside an AV managed mission. Complete this assigned work directly. Do not invoke av order, av_resume, av operate, av_operate, av_operation_resume, or delegate this mission back to AV. AGENT_VALLEY_MANAGED_RUN=1 applies to this run.`;
|
|
76430
|
+
if (stage === "work" && !context?.handoff) {
|
|
76431
|
+
route = selectWorkActor(mission, requestedPersona, context?.taskId, compatibleRoutes);
|
|
76432
|
+
persona = route.actor;
|
|
76433
|
+
}
|
|
76434
|
+
this.onStage(stage, persona);
|
|
75948
76435
|
if (route)
|
|
75949
76436
|
prompt += `
|
|
75950
76437
|
|
|
75951
76438
|
Actual work route: ${JSON.stringify({ actorType: persona.agentType, model: persona.model ?? "native default", reason: route.reason })}. This route does not alter the user's Chief Director choice or acceptance contract.`;
|
|
75952
|
-
const entry =
|
|
75953
|
-
entry.executionRecovery = this.localExecution ? "local-process" : "reconcile";
|
|
76439
|
+
const entry = await admitNativeDispatch(mission, persona, attempt, stage, context, this.localExecution, route?.reason);
|
|
75954
76440
|
let run;
|
|
75955
76441
|
if (omaActor)
|
|
75956
76442
|
mission.history.push({
|
|
@@ -75997,6 +76483,7 @@ Actual work route: ${JSON.stringify({ actorType: persona.agentType, model: perso
|
|
|
75997
76483
|
throw new AgentRunError("Runtime returned incomplete terminal evidence. Reconcile the execution before resuming.", attempt, { outcomeUnknown: true });
|
|
75998
76484
|
observed = completed;
|
|
75999
76485
|
executionSettled = true;
|
|
76486
|
+
entry.nativeOutcome = completed.exitCode === 0 ? "passed" : "failed";
|
|
76000
76487
|
if (completed.exitCode !== 0)
|
|
76001
76488
|
throw new AgentRunError("Runtime execution did not complete successfully. Inspect the failed attempt before retrying.", completed);
|
|
76002
76489
|
if (mission.oma && stage === "work") {
|
|
@@ -76012,11 +76499,14 @@ Actual work route: ${JSON.stringify({ actorType: persona.agentType, model: perso
|
|
|
76012
76499
|
try {
|
|
76013
76500
|
observed = this.observeAttempt(attempt, error.attempt);
|
|
76014
76501
|
executionSettled = !error.outcomeUnknown;
|
|
76502
|
+
if (executionSettled)
|
|
76503
|
+
entry.nativeOutcome = "failed";
|
|
76015
76504
|
} catch (identityError) {
|
|
76016
76505
|
error = identityError;
|
|
76017
76506
|
}
|
|
76018
76507
|
}
|
|
76019
76508
|
failure = error;
|
|
76509
|
+
entry.evidence = (error instanceof Error ? error.message : String(error)).slice(-2000);
|
|
76020
76510
|
if (error instanceof AgentRunError && error.outcomeUnknown || !this.localExecution && !executionSettled) {
|
|
76021
76511
|
markOperatingRunUnknown(entry, error instanceof Error ? error.message : String(error));
|
|
76022
76512
|
failure = new MissionPause(`Execution ${attempt.id} outcome is uncertain: ${(error instanceof Error ? error.message : String(error)).slice(0, 1000)}. Reconcile the saved run before resuming.`, "unknown-effect");
|
|
@@ -76034,6 +76524,10 @@ Actual work route: ${JSON.stringify({ actorType: persona.agentType, model: perso
|
|
|
76034
76524
|
if (run)
|
|
76035
76525
|
this.runs.delete(run);
|
|
76036
76526
|
finishOperatingRun(mission, entry, observed, failed);
|
|
76527
|
+
if (entry.executionState === "unknown")
|
|
76528
|
+
delete entry.nativeOutcome;
|
|
76529
|
+
else if (signal?.aborted)
|
|
76530
|
+
entry.nativeOutcome = "cancelled";
|
|
76037
76531
|
await this.store.save(mission);
|
|
76038
76532
|
}
|
|
76039
76533
|
if (failed)
|
|
@@ -76560,15 +77054,15 @@ init_execution();
|
|
|
76560
77054
|
|
|
76561
77055
|
// src/chief-supervisor.ts
|
|
76562
77056
|
import { randomUUID as randomUUID17 } from "node:crypto";
|
|
76563
|
-
import { join as
|
|
77057
|
+
import { join as join45 } from "node:path";
|
|
76564
77058
|
init_execution();
|
|
76565
77059
|
// src/chief-delivery.ts
|
|
76566
77060
|
import { createHash as createHash28 } from "node:crypto";
|
|
76567
77061
|
import { mkdir as mkdir21, writeFile as writeFile13 } from "node:fs/promises";
|
|
76568
|
-
import { join as
|
|
77062
|
+
import { join as join44 } from "node:path";
|
|
76569
77063
|
|
|
76570
77064
|
// ../../packages/core/src/chief/report-delivery.ts
|
|
76571
|
-
import { join as
|
|
77065
|
+
import { join as join43 } from "node:path";
|
|
76572
77066
|
|
|
76573
77067
|
// ../../packages/core/src/chief/report-delivery-adapters.ts
|
|
76574
77068
|
init_report_delivery_contract();
|
|
@@ -76951,9 +77445,9 @@ init_zod();
|
|
|
76951
77445
|
init_atomic_json();
|
|
76952
77446
|
init_report_delivery_contract();
|
|
76953
77447
|
import { createHash as createHash27 } from "node:crypto";
|
|
76954
|
-
import { constants as
|
|
76955
|
-
import { mkdir as mkdir20, open as open15, readdir as
|
|
76956
|
-
import { isAbsolute as
|
|
77448
|
+
import { constants as constants14 } from "node:fs";
|
|
77449
|
+
import { mkdir as mkdir20, open as open15, readdir as readdir12, readFile as readFile18, realpath as realpath25 } from "node:fs/promises";
|
|
77450
|
+
import { isAbsolute as isAbsolute16, join as join42, relative as relative15, resolve as resolve29 } from "node:path";
|
|
76957
77451
|
var hash3 = string2().regex(/^[a-f0-9]{64}$/);
|
|
76958
77452
|
var outboxRecordSchema = strictObject({
|
|
76959
77453
|
version: literal(1),
|
|
@@ -76995,12 +77489,12 @@ function receipt(record) {
|
|
|
76995
77489
|
class ReportOutbox {
|
|
76996
77490
|
directory;
|
|
76997
77491
|
constructor(stateDir) {
|
|
76998
|
-
this.directory =
|
|
77492
|
+
this.directory = join42(stateDir, "report-outbox");
|
|
76999
77493
|
}
|
|
77000
77494
|
path(id) {
|
|
77001
77495
|
if (!hash3.safeParse(id).success)
|
|
77002
77496
|
throw new Error("Invalid report receipt ID. Use av reports to find a receipt.");
|
|
77003
|
-
return
|
|
77497
|
+
return join42(this.directory, `${id}.json`);
|
|
77004
77498
|
}
|
|
77005
77499
|
lock(id) {
|
|
77006
77500
|
return new MissionStore(this.directory).lock(id);
|
|
@@ -77008,7 +77502,7 @@ class ReportOutbox {
|
|
|
77008
77502
|
async load(id) {
|
|
77009
77503
|
let content;
|
|
77010
77504
|
try {
|
|
77011
|
-
content = await
|
|
77505
|
+
content = await readFile18(this.path(id), "utf8");
|
|
77012
77506
|
} catch (error) {
|
|
77013
77507
|
if (error.code === "ENOENT")
|
|
77014
77508
|
return null;
|
|
@@ -77029,7 +77523,7 @@ class ReportOutbox {
|
|
|
77029
77523
|
await writeJsonAtomic(this.path(record.id), record);
|
|
77030
77524
|
}
|
|
77031
77525
|
async list() {
|
|
77032
|
-
const names = await
|
|
77526
|
+
const names = await readdir12(this.directory).catch((error) => {
|
|
77033
77527
|
if (error.code === "ENOENT")
|
|
77034
77528
|
return [];
|
|
77035
77529
|
throw new Error("Cannot list report outbox. Restore access to the Chief Director state directory.");
|
|
@@ -77050,11 +77544,11 @@ async function verifiedAttachment(attachment, artifactRoot, readBytes) {
|
|
|
77050
77544
|
const root = await realpath25(artifactRoot);
|
|
77051
77545
|
const path = await realpath25(attachment.path);
|
|
77052
77546
|
const local = relative15(root, path);
|
|
77053
|
-
if (!local || local.startsWith(`..${process.platform === "win32" ? "\\" : "/"}`) || local === ".." ||
|
|
77547
|
+
if (!local || local.startsWith(`..${process.platform === "win32" ? "\\" : "/"}`) || local === ".." || isAbsolute16(local))
|
|
77054
77548
|
throw failure;
|
|
77055
77549
|
if (resolve29(attachment.path) !== attachment.path)
|
|
77056
77550
|
throw failure;
|
|
77057
|
-
const file = await open15(attachment.path,
|
|
77551
|
+
const file = await open15(attachment.path, constants14.O_RDONLY | constants14.O_NOFOLLOW);
|
|
77058
77552
|
try {
|
|
77059
77553
|
const stat = await file.stat();
|
|
77060
77554
|
if (!stat.isFile() || stat.size !== attachment.sizeBytes)
|
|
@@ -77107,7 +77601,7 @@ function dependencies(stateDir, overrides) {
|
|
|
77107
77601
|
env: overrides.env ?? process.env,
|
|
77108
77602
|
registry: { ...createReportChannelRegistry(fetch2), ...overrides.registry },
|
|
77109
77603
|
attachments: overrides.attachments ?? [],
|
|
77110
|
-
artifactRoot: overrides.artifactRoot ??
|
|
77604
|
+
artifactRoot: overrides.artifactRoot ?? join43(stateDir, "captures"),
|
|
77111
77605
|
now: overrides.now ?? (() => new Date)
|
|
77112
77606
|
};
|
|
77113
77607
|
}
|
|
@@ -77288,8 +77782,8 @@ init_chief_schema();
|
|
|
77288
77782
|
init_yaml_loader();
|
|
77289
77783
|
async function saveAndDeliverMissionReport(mission, root) {
|
|
77290
77784
|
const repository = mission.repositoryRoot ?? root;
|
|
77291
|
-
const directory =
|
|
77292
|
-
const reportPath =
|
|
77785
|
+
const directory = join44(root, ".agent-valley/reports");
|
|
77786
|
+
const reportPath = join44(directory, `${mission.id}.md`);
|
|
77293
77787
|
const report = renderReport(mission);
|
|
77294
77788
|
await mkdir21(directory, { recursive: true, mode: 448 });
|
|
77295
77789
|
await writeFile13(reportPath, report, { mode: 384 });
|
|
@@ -77304,12 +77798,12 @@ ${explanation.eli5}`);
|
|
|
77304
77798
|
try {
|
|
77305
77799
|
const config = mergeChiefConfig(loadGlobalConfig()?.chief, loadProjectConfig(root)?.chief);
|
|
77306
77800
|
const attachments = [...mission.capture?.attachments ?? []];
|
|
77307
|
-
const artifactRoot =
|
|
77801
|
+
const artifactRoot = join44(repository, ".agent-valley/captures");
|
|
77308
77802
|
if (config.reporting?.destinations.length) {
|
|
77309
77803
|
const bytes = Buffer.from(report);
|
|
77310
77804
|
const sha256 = createHash28("sha256").update(bytes).digest("hex");
|
|
77311
|
-
const reportDirectory =
|
|
77312
|
-
const attachmentPath =
|
|
77805
|
+
const reportDirectory = join44(artifactRoot, mission.id);
|
|
77806
|
+
const attachmentPath = join44(reportDirectory, `report-${sha256}.md`);
|
|
77313
77807
|
await mkdir21(reportDirectory, { recursive: true, mode: 448 });
|
|
77314
77808
|
await writeFile13(attachmentPath, bytes, { mode: 384 });
|
|
77315
77809
|
attachments.push({
|
|
@@ -77320,7 +77814,7 @@ ${explanation.eli5}`);
|
|
|
77320
77814
|
sha256
|
|
77321
77815
|
});
|
|
77322
77816
|
}
|
|
77323
|
-
const receipts = await dispatchMissionReport(mission, report, reportPath, config.reporting,
|
|
77817
|
+
const receipts = await dispatchMissionReport(mission, report, reportPath, config.reporting, join44(repository, ".agent-valley"), {
|
|
77324
77818
|
attachments,
|
|
77325
77819
|
artifactRoot
|
|
77326
77820
|
});
|
|
@@ -77574,7 +78068,7 @@ function abortableDelay(ms, signal) {
|
|
|
77574
78068
|
async function superviseOrder(goal, options, root, dependencies = {}) {
|
|
77575
78069
|
assertNotManagedRun();
|
|
77576
78070
|
const id = options.resume ?? options.missionId ?? randomUUID17();
|
|
77577
|
-
const store = new MissionStore(
|
|
78071
|
+
const store = new MissionStore(join45(root, ".agent-valley/missions"));
|
|
77578
78072
|
const controller = new AbortController;
|
|
77579
78073
|
const interrupt = () => controller.abort(dependencies.signal?.reason);
|
|
77580
78074
|
const terminate = () => controller.abort(options.service ? serviceShutdownPause() : undefined);
|
|
@@ -77914,8 +78408,8 @@ init_base_session();
|
|
|
77914
78408
|
init_sandbox_binary();
|
|
77915
78409
|
init_agent_discovery();
|
|
77916
78410
|
import { readFileSync as readFileSync10, statSync as statSync4 } from "node:fs";
|
|
77917
|
-
import { homedir as
|
|
77918
|
-
import { join as
|
|
78411
|
+
import { homedir as homedir9 } from "node:os";
|
|
78412
|
+
import { join as join46 } from "node:path";
|
|
77919
78413
|
import { stripVTControlCharacters as stripVTControlCharacters4 } from "node:util";
|
|
77920
78414
|
var MAX_OUTPUT_BYTES5 = 2097152;
|
|
77921
78415
|
var PROBE_TIMEOUT_MS2 = 15000;
|
|
@@ -78040,8 +78534,8 @@ async function discoverFreeModels(agentType, workspacePath, signal, overrides =
|
|
|
78040
78534
|
};
|
|
78041
78535
|
let state;
|
|
78042
78536
|
try {
|
|
78043
|
-
const home = env.XDG_STATE_HOME ||
|
|
78044
|
-
const content = deps.readState(
|
|
78537
|
+
const home = env.XDG_STATE_HOME || join46(env.HOME || homedir9(), ".local", "state");
|
|
78538
|
+
const content = deps.readState(join46(home, "opencode", "model.json"));
|
|
78045
78539
|
state = content && Buffer.byteLength(content) <= MAX_OUTPUT_BYTES5 ? JSON.parse(content) : undefined;
|
|
78046
78540
|
} catch {
|
|
78047
78541
|
state = undefined;
|
|
@@ -78070,9 +78564,9 @@ async function discoverFreeModels(agentType, workspacePath, signal, overrides =
|
|
|
78070
78564
|
|
|
78071
78565
|
// ../../packages/core/src/chief/metric-source-adapters.ts
|
|
78072
78566
|
init_metric_source_policy();
|
|
78073
|
-
import { constants as
|
|
78074
|
-
import { lstat as
|
|
78075
|
-
import { isAbsolute as
|
|
78567
|
+
import { constants as constants15 } from "node:fs";
|
|
78568
|
+
import { lstat as lstat21, open as open16, realpath as realpath26 } from "node:fs/promises";
|
|
78569
|
+
import { isAbsolute as isAbsolute17, relative as relative16, resolve as resolve30, sep as sep16 } from "node:path";
|
|
78076
78570
|
var MAX_METRIC_RESPONSE_BYTES = 2000000;
|
|
78077
78571
|
function metricSourceEnvironment(request, name) {
|
|
78078
78572
|
if (!name || !request.env[name]?.trim())
|
|
@@ -78157,19 +78651,19 @@ var jsonFileMetricAdapter = {
|
|
|
78157
78651
|
async collect(request) {
|
|
78158
78652
|
const root = await realpath26(request.repositoryRoot);
|
|
78159
78653
|
const name = request.source.file;
|
|
78160
|
-
if (!name ||
|
|
78654
|
+
if (!name || isAbsolute17(name))
|
|
78161
78655
|
throw new MetricSourceError("Metric file must be relative to the source repository. Set chief.metric_sources.sources[].file in av.yaml.");
|
|
78162
78656
|
const path = resolve30(root, name);
|
|
78163
78657
|
const within = relative16(root, path);
|
|
78164
|
-
if (!within || within.startsWith(`..${sep16}`) || within === ".." ||
|
|
78658
|
+
if (!within || within.startsWith(`..${sep16}`) || within === ".." || isAbsolute17(within))
|
|
78165
78659
|
throw new MetricSourceError("Metric file escapes the source repository. Choose a repository-relative JSON file.");
|
|
78166
78660
|
let current = root;
|
|
78167
78661
|
for (const part of within.split(sep16)) {
|
|
78168
78662
|
current = resolve30(current, part);
|
|
78169
|
-
if ((await
|
|
78663
|
+
if ((await lstat21(current)).isSymbolicLink())
|
|
78170
78664
|
throw new MetricSourceError("Metric file and parent directories must not be symlinks. Choose a regular JSON file inside the source repository.");
|
|
78171
78665
|
}
|
|
78172
|
-
const file = await open16(path,
|
|
78666
|
+
const file = await open16(path, constants15.O_RDONLY | constants15.O_NOFOLLOW);
|
|
78173
78667
|
try {
|
|
78174
78668
|
const stat = await file.stat();
|
|
78175
78669
|
if (!stat.isFile() || stat.size > MAX_METRIC_RESPONSE_BYTES || await realpath26(path) !== path)
|
|
@@ -78570,9 +79064,9 @@ function createMissionMetricPorts(repository, mission, dependencies = {}) {
|
|
|
78570
79064
|
|
|
78571
79065
|
// src/chief-tool-config.ts
|
|
78572
79066
|
import { randomUUID as randomUUID19 } from "node:crypto";
|
|
78573
|
-
import { constants as
|
|
78574
|
-
import { link as link2, lstat as
|
|
78575
|
-
import { join as
|
|
79067
|
+
import { constants as constants16 } from "node:fs";
|
|
79068
|
+
import { link as link2, lstat as lstat22, mkdir as mkdir22, open as open17, realpath as realpath27, unlink as unlink5 } from "node:fs/promises";
|
|
79069
|
+
import { join as join47 } from "node:path";
|
|
78576
79070
|
init_dist2();
|
|
78577
79071
|
init_client_toml();
|
|
78578
79072
|
var maximumBytes = 1024 * 1024;
|
|
@@ -78591,8 +79085,8 @@ async function assertLocalPath(root, local) {
|
|
|
78591
79085
|
const parts = local.split("/");
|
|
78592
79086
|
let current = root;
|
|
78593
79087
|
for (const [index, part] of parts.entries()) {
|
|
78594
|
-
current =
|
|
78595
|
-
const stats = await
|
|
79088
|
+
current = join47(current, part);
|
|
79089
|
+
const stats = await lstat22(current).catch((error) => {
|
|
78596
79090
|
if (error.code === "ENOENT")
|
|
78597
79091
|
return;
|
|
78598
79092
|
throw error;
|
|
@@ -78605,7 +79099,7 @@ async function assertLocalPath(root, local) {
|
|
|
78605
79099
|
return true;
|
|
78606
79100
|
}
|
|
78607
79101
|
async function readPrivateFile(path) {
|
|
78608
|
-
const file = await open17(path,
|
|
79102
|
+
const file = await open17(path, constants16.O_RDONLY | constants16.O_NOFOLLOW);
|
|
78609
79103
|
try {
|
|
78610
79104
|
const stats = await file.stat();
|
|
78611
79105
|
if (!stats.isFile() || stats.size > maximumBytes)
|
|
@@ -78648,10 +79142,10 @@ async function privateExclude(original, target, paths) {
|
|
|
78648
79142
|
]);
|
|
78649
79143
|
const common = targetCommon.trim();
|
|
78650
79144
|
const path = exclude.trim();
|
|
78651
|
-
if (common !==
|
|
79145
|
+
if (common !== join47(target, ".git") && common !== originalCommon.trim() || path !== join47(common, "info", "exclude") || await realpath27(common) !== common)
|
|
78652
79146
|
throw new ChiefToolConfigError("Chief MCP configuration requires the workspace's own Git metadata or its original repository's shared worktree metadata.");
|
|
78653
|
-
const info =
|
|
78654
|
-
const infoStats = await
|
|
79147
|
+
const info = join47(common, "info");
|
|
79148
|
+
const infoStats = await lstat22(info).catch((error) => {
|
|
78655
79149
|
if (error.code === "ENOENT")
|
|
78656
79150
|
return;
|
|
78657
79151
|
throw error;
|
|
@@ -78668,7 +79162,7 @@ async function privateExclude(original, target, paths) {
|
|
|
78668
79162
|
const patterns = paths.flatMap((local) => [`/${local}`, `/${local}.av-mcp-*.tmp`]).filter((pattern) => !lines.has(pattern));
|
|
78669
79163
|
if (!patterns.length)
|
|
78670
79164
|
return;
|
|
78671
|
-
const file = await open17(path,
|
|
79165
|
+
const file = await open17(path, constants16.O_WRONLY | constants16.O_APPEND | constants16.O_CREAT | constants16.O_NOFOLLOW, 384);
|
|
78672
79166
|
try {
|
|
78673
79167
|
await file.writeFile(`${content && !content.endsWith(`
|
|
78674
79168
|
`) ? `
|
|
@@ -78689,14 +79183,14 @@ async function prepareToolConfig(originalRepository, targetWorkspace) {
|
|
|
78689
79183
|
continue;
|
|
78690
79184
|
if (!await assertLocalPath(original, config.path))
|
|
78691
79185
|
continue;
|
|
78692
|
-
const content = selectedNamespace(await readPrivateFile(
|
|
79186
|
+
const content = selectedNamespace(await readPrivateFile(join47(original, config.path)), config.namespace, config.toml);
|
|
78693
79187
|
if (content)
|
|
78694
79188
|
selected.push({ path: config.path, content });
|
|
78695
79189
|
}
|
|
78696
79190
|
if (!selected.length)
|
|
78697
79191
|
return;
|
|
78698
79192
|
for (const root of [original, target]) {
|
|
78699
|
-
const stats = await
|
|
79193
|
+
const stats = await lstat22(join47(root, ".git"));
|
|
78700
79194
|
if (stats.isSymbolicLink() || !stats.isFile() && !stats.isDirectory() || await realpath27((await parallelGit(root, ["rev-parse", "--show-toplevel"])).trim()) !== root)
|
|
78701
79195
|
throw new ChiefToolConfigError("Chief MCP tools require original local Git repository metadata. Restore the workspace before starting Chief.");
|
|
78702
79196
|
}
|
|
@@ -78704,14 +79198,14 @@ async function prepareToolConfig(originalRepository, targetWorkspace) {
|
|
|
78704
79198
|
for (const config of selected) {
|
|
78705
79199
|
const parts = config.path.split("/");
|
|
78706
79200
|
if (parts.length > 1) {
|
|
78707
|
-
const parent =
|
|
79201
|
+
const parent = join47(target, ...parts.slice(0, -1));
|
|
78708
79202
|
await mkdir22(parent, { recursive: true, mode: 448 });
|
|
78709
79203
|
if (await realpath27(parent) !== parent)
|
|
78710
79204
|
throw new ChiefToolConfigError("Chief MCP configuration parent redirects through a symlink. Restore its local directory.");
|
|
78711
79205
|
}
|
|
78712
79206
|
if (await assertLocalPath(target, config.path))
|
|
78713
79207
|
continue;
|
|
78714
|
-
const path =
|
|
79208
|
+
const path = join47(target, config.path);
|
|
78715
79209
|
const temporary = `${path}.av-mcp-${randomUUID19()}.tmp`;
|
|
78716
79210
|
const file = await open17(temporary, "wx", 384);
|
|
78717
79211
|
try {
|
|
@@ -78742,10 +79236,10 @@ async function prepareChiefToolConfig(originalRepository, targetWorkspace) {
|
|
|
78742
79236
|
|
|
78743
79237
|
// src/tool-discovery.ts
|
|
78744
79238
|
init_client_toml();
|
|
78745
|
-
import { constants as
|
|
78746
|
-
import { access, lstat as
|
|
78747
|
-
import { homedir as
|
|
78748
|
-
import { delimiter as
|
|
79239
|
+
import { constants as constants17 } from "node:fs";
|
|
79240
|
+
import { access as access2, lstat as lstat23, readFile as readFile19, realpath as realpath28 } from "node:fs/promises";
|
|
79241
|
+
import { homedir as homedir10 } from "node:os";
|
|
79242
|
+
import { delimiter as delimiter3, isAbsolute as isAbsolute18, join as join48, resolve as resolve31 } from "node:path";
|
|
78749
79243
|
var binaries = [
|
|
78750
79244
|
"docker",
|
|
78751
79245
|
"orb",
|
|
@@ -78760,12 +79254,12 @@ var binaries = [
|
|
|
78760
79254
|
];
|
|
78761
79255
|
var MAX_CONFIG_BYTES = 1048576;
|
|
78762
79256
|
var record5 = (value) => value !== null && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
78763
|
-
async function
|
|
78764
|
-
for (const directory of (env.PATH ?? "").split(
|
|
79257
|
+
async function executable2(name, env) {
|
|
79258
|
+
for (const directory of (env.PATH ?? "").split(delimiter3).filter(isAbsolute18)) {
|
|
78765
79259
|
try {
|
|
78766
|
-
const path =
|
|
78767
|
-
await
|
|
78768
|
-
if ((await
|
|
79260
|
+
const path = join48(directory, name);
|
|
79261
|
+
await access2(path, constants17.X_OK);
|
|
79262
|
+
if ((await lstat23(await realpath28(path))).isFile())
|
|
78769
79263
|
return true;
|
|
78770
79264
|
} catch {}
|
|
78771
79265
|
}
|
|
@@ -78774,10 +79268,10 @@ async function executable(name, env) {
|
|
|
78774
79268
|
async function mcpNames(path, scope, project, requestedRoot) {
|
|
78775
79269
|
const base = { kind: "mcp", scope, authentication: "unknown", source: path };
|
|
78776
79270
|
try {
|
|
78777
|
-
const info = await
|
|
79271
|
+
const info = await lstat23(path);
|
|
78778
79272
|
if (!info.isFile() || info.isSymbolicLink() || info.size > MAX_CONFIG_BYTES)
|
|
78779
79273
|
throw new Error("Invalid config");
|
|
78780
|
-
const source = await
|
|
79274
|
+
const source = await readFile19(path, "utf8");
|
|
78781
79275
|
if (Buffer.byteLength(source) > MAX_CONFIG_BYTES)
|
|
78782
79276
|
throw new Error("Invalid config");
|
|
78783
79277
|
const config = record5(path.endsWith(".toml") ? parseClientToml(source) : JSON.parse(source));
|
|
@@ -78817,7 +79311,7 @@ async function mcpNames(path, scope, project, requestedRoot) {
|
|
|
78817
79311
|
}
|
|
78818
79312
|
async function discoverTools(root, dependencies = {}) {
|
|
78819
79313
|
const env = dependencies.env ?? process.env;
|
|
78820
|
-
const home = dependencies.home ??
|
|
79314
|
+
const home = dependencies.home ?? homedir10();
|
|
78821
79315
|
const project = await realpath28(root);
|
|
78822
79316
|
const projectFiles = [
|
|
78823
79317
|
".mcp.json",
|
|
@@ -78828,11 +79322,11 @@ async function discoverTools(root, dependencies = {}) {
|
|
|
78828
79322
|
".codex/config.toml"
|
|
78829
79323
|
];
|
|
78830
79324
|
const userFiles = [".claude.json", ".cursor/mcp.json", ".qwen/settings.json", ".gemini/settings.json"];
|
|
78831
|
-
const codexHome = env.CODEX_HOME &&
|
|
79325
|
+
const codexHome = env.CODEX_HOME && isAbsolute18(env.CODEX_HOME) ? env.CODEX_HOME : join48(home, ".codex");
|
|
78832
79326
|
const configs = [
|
|
78833
|
-
...projectFiles.map((path) => ({ path:
|
|
79327
|
+
...projectFiles.map((path) => ({ path: join48(project, path), scope: "project" })),
|
|
78834
79328
|
...userFiles.map((path) => ({ path: resolve31(home, path), scope: "user" })),
|
|
78835
|
-
{ path:
|
|
79329
|
+
{ path: join48(codexHome, "config.toml"), scope: "user" }
|
|
78836
79330
|
];
|
|
78837
79331
|
const [cli, mcp] = await Promise.all([
|
|
78838
79332
|
Promise.all(binaries.map(async (name) => ({
|
|
@@ -78841,7 +79335,7 @@ async function discoverTools(root, dependencies = {}) {
|
|
|
78841
79335
|
kind: "cli",
|
|
78842
79336
|
scope: "user",
|
|
78843
79337
|
authentication: "unknown",
|
|
78844
|
-
availability: await
|
|
79338
|
+
availability: await executable2(name, env) ? "available" : "unavailable",
|
|
78845
79339
|
reason: "Executable presence only; service access, daemon state and login are unverified."
|
|
78846
79340
|
}))),
|
|
78847
79341
|
Promise.all(configs.map(({ path, scope }) => mcpNames(path, scope, project, resolve31(root))))
|
|
@@ -78879,7 +79373,7 @@ function continuousDecisionPrompt(operation, mission, tools, previousReport) {
|
|
|
78879
79373
|
async function decideContinuousGoal(operation, decisionId, root, dependencies = {}) {
|
|
78880
79374
|
if (!operation.baseline)
|
|
78881
79375
|
throw new Error("An accepted operation baseline is required before selecting a goal.");
|
|
78882
|
-
const store = new MissionStore(
|
|
79376
|
+
const store = new MissionStore(join49(root, ".agent-valley", "operation-decisions", operation.id));
|
|
78883
79377
|
const unlock = await store.lock(decisionId);
|
|
78884
79378
|
const runtime = (dependencies.runtime ?? ((storage, signal) => new ChiefRuntime(storage, signal, undefined, undefined, undefined, discoverReadyAgents, discoverFreeModels)))(store, dependencies.signal);
|
|
78885
79379
|
let mission;
|
|
@@ -78992,7 +79486,7 @@ async function decideContinuousGoal(operation, decisionId, root, dependencies =
|
|
|
78992
79486
|
const previousId = operation.history.at(-1)?.missionId;
|
|
78993
79487
|
let previousReport;
|
|
78994
79488
|
if (previousId) {
|
|
78995
|
-
const previous = await new MissionStore(
|
|
79489
|
+
const previous = await new MissionStore(join49(root, ".agent-valley", "missions")).load(previousId);
|
|
78996
79490
|
if (previous.repositoryRoot !== operation.repositoryRoot || previous.status !== "completed")
|
|
78997
79491
|
throw new Error("The previous accepted child's evidence no longer matches this operation. Restore its saved checkpoint before selecting another goal.");
|
|
78998
79492
|
previousReport = renderReport(previous).slice(0, 16000);
|
|
@@ -79031,7 +79525,7 @@ async function decideContinuousGoal(operation, decisionId, root, dependencies =
|
|
|
79031
79525
|
|
|
79032
79526
|
// src/chief-continuous-report.ts
|
|
79033
79527
|
import { mkdir as mkdir23 } from "node:fs/promises";
|
|
79034
|
-
import { join as
|
|
79528
|
+
import { join as join50 } from "node:path";
|
|
79035
79529
|
init_atomic_json();
|
|
79036
79530
|
function operationDeliveryLines(operation, delivery, unavailable = false) {
|
|
79037
79531
|
const integration = operation.sourceIntegration;
|
|
@@ -79090,17 +79584,17 @@ function renderOperationReport(operation, delivery, unavailable = false) {
|
|
|
79090
79584
|
`);
|
|
79091
79585
|
}
|
|
79092
79586
|
async function saveOperationReport(root, operation) {
|
|
79093
|
-
const directory =
|
|
79587
|
+
const directory = join50(root, ".agent-valley", "operation-reports");
|
|
79094
79588
|
await mkdir23(directory, { recursive: true, mode: 448 });
|
|
79095
79589
|
const evidence = await deliveryFor(root, operation);
|
|
79096
|
-
await writeTextAtomic(
|
|
79590
|
+
await writeTextAtomic(join50(directory, `${operation.id}.md`), renderOperationReport(operation, evidence.delivery, evidence.unavailable));
|
|
79097
79591
|
}
|
|
79098
79592
|
async function deliveryFor(root, operation) {
|
|
79099
79593
|
const id = operation.currentMissionId ?? operation.history.at(-1)?.missionId;
|
|
79100
79594
|
if (!id)
|
|
79101
79595
|
return {};
|
|
79102
79596
|
try {
|
|
79103
|
-
const mission = await new MissionStore(
|
|
79597
|
+
const mission = await new MissionStore(join50(root, ".agent-valley", "missions")).load(id);
|
|
79104
79598
|
return mission.repositoryRoot === operation.repositoryRoot ? { delivery: mission.codeDelivery } : { unavailable: true };
|
|
79105
79599
|
} catch {
|
|
79106
79600
|
return { unavailable: true };
|
|
@@ -79133,7 +79627,7 @@ function createOperationProgressReporter(root, write = console.log) {
|
|
|
79133
79627
|
};
|
|
79134
79628
|
}
|
|
79135
79629
|
// src/chief-source-integration.ts
|
|
79136
|
-
import { join as
|
|
79630
|
+
import { join as join51 } from "node:path";
|
|
79137
79631
|
init_execution();
|
|
79138
79632
|
function sourceIntegrationCheckpoint(operation) {
|
|
79139
79633
|
const accepted = operation.baseline;
|
|
@@ -79156,7 +79650,7 @@ async function initialSourceIntegration(repositoryRoot, id, mode, remoteDelivery
|
|
|
79156
79650
|
async function assertChildSettled(operation, storageRoot) {
|
|
79157
79651
|
if (!operation.currentMissionId)
|
|
79158
79652
|
return;
|
|
79159
|
-
const missions = new MissionStore(
|
|
79653
|
+
const missions = new MissionStore(join51(storageRoot, ".agent-valley", "missions"));
|
|
79160
79654
|
if (await missions.isLocked(operation.currentMissionId))
|
|
79161
79655
|
throw new Error("The current child is still owned by another coordinator. Resume source integration after its checkpoint is settled.");
|
|
79162
79656
|
const child = await missions.load(operation.currentMissionId).catch((error) => {
|
|
@@ -79178,7 +79672,7 @@ async function resumeSourceIntegration(operation, mode, storageRoot, signal, sav
|
|
|
79178
79672
|
if (selected !== "snapshot-only")
|
|
79179
79673
|
throw new Error("This operation already uses explicit commit and push delivery. Keep its saved delivery policy instead of adding worktree application.");
|
|
79180
79674
|
}
|
|
79181
|
-
const persist = save ?? ((current) => new ContinuousOperationStore(
|
|
79675
|
+
const persist = save ?? ((current) => new ContinuousOperationStore(join51(storageRoot, ".agent-valley", "operations")).save(current));
|
|
79182
79676
|
const { accepted, applied, caughtUp, pendingIds } = sourceIntegrationCheckpoint(operation);
|
|
79183
79677
|
const activation = selected === "worktree" && operation.sourceIntegrationPolicy?.mode !== "worktree";
|
|
79184
79678
|
if (activation) {
|
|
@@ -79216,7 +79710,7 @@ async function resumeSourceIntegration(operation, mode, storageRoot, signal, sav
|
|
|
79216
79710
|
if (policy?.mode === "worktree" && accepted?.missionId && (applied?.missionId !== accepted.missionId || applied.nextTree !== accepted.baselineTree)) {
|
|
79217
79711
|
if (applied?.missionId === accepted.missionId)
|
|
79218
79712
|
throw new Error("The saved source application summary differs from its accepted snapshot. Restore the original verified receipt before resuming.");
|
|
79219
|
-
const previous = await validateContinuousBaseline(operation.repositoryRoot, operation.id,
|
|
79713
|
+
const previous = await validateContinuousBaseline(operation.repositoryRoot, operation.id, join51(operation.repositoryRoot, ".agent-valley", "operations", operation.id, "baselines", applied?.missionId ?? "initial", "workspace"));
|
|
79220
79714
|
if (applied && previous.baselineTree !== applied.nextTree)
|
|
79221
79715
|
throw new Error("The last applied source snapshot no longer matches its saved summary. Restore its original baseline before resuming.");
|
|
79222
79716
|
operation.sourceIntegration = await integrateContinuousSource(operation, previous, accepted, signal);
|
|
@@ -79241,9 +79735,9 @@ import { realpath as realpath30 } from "node:fs/promises";
|
|
|
79241
79735
|
// ../../packages/core/src/chief/continuous-retention.ts
|
|
79242
79736
|
init_zod();
|
|
79243
79737
|
import { createHash as createHash29 } from "node:crypto";
|
|
79244
|
-
import { constants as
|
|
79245
|
-
import { lstat as
|
|
79246
|
-
import { dirname as dirname11, join as
|
|
79738
|
+
import { constants as constants18 } from "node:fs";
|
|
79739
|
+
import { lstat as lstat24, open as open18, readdir as readdir13, realpath as realpath29, rename as rename4, rm as rm7 } from "node:fs/promises";
|
|
79740
|
+
import { dirname as dirname11, join as join52, resolve as resolve32 } from "node:path";
|
|
79247
79741
|
var digest7 = (content) => createHash29("sha256").update(content).digest("hex");
|
|
79248
79742
|
var sha2 = string2().regex(/^[a-f0-9]{40,64}$/);
|
|
79249
79743
|
var preparedSchema = strictObject({
|
|
@@ -79267,7 +79761,7 @@ var completedSchema = strictObject({
|
|
|
79267
79761
|
});
|
|
79268
79762
|
async function exists(path) {
|
|
79269
79763
|
try {
|
|
79270
|
-
await
|
|
79764
|
+
await lstat24(path);
|
|
79271
79765
|
return true;
|
|
79272
79766
|
} catch (error) {
|
|
79273
79767
|
if (error.code === "ENOENT")
|
|
@@ -79276,13 +79770,13 @@ async function exists(path) {
|
|
|
79276
79770
|
}
|
|
79277
79771
|
}
|
|
79278
79772
|
async function localDirectory3(path) {
|
|
79279
|
-
if (!(await
|
|
79773
|
+
if (!(await lstat24(path)).isDirectory() || await realpath29(path) !== resolve32(path))
|
|
79280
79774
|
throw new Error("Pruning requires canonical local directories. Preserve redirected artifacts and restore their original paths.");
|
|
79281
79775
|
}
|
|
79282
79776
|
async function readLocal(path) {
|
|
79283
79777
|
let handle;
|
|
79284
79778
|
try {
|
|
79285
|
-
handle = await open18(path,
|
|
79779
|
+
handle = await open18(path, constants18.O_RDONLY | (constants18.O_NOFOLLOW ?? 0) | (constants18.O_NONBLOCK ?? 0));
|
|
79286
79780
|
const stat = await handle.stat();
|
|
79287
79781
|
if (!stat.isFile() || stat.size > 16777216)
|
|
79288
79782
|
throw new Error("Unsupported local pruning receipt.");
|
|
@@ -79314,7 +79808,7 @@ async function independentGitMetadata(path) {
|
|
|
79314
79808
|
const directory = pending.pop();
|
|
79315
79809
|
if (!directory)
|
|
79316
79810
|
break;
|
|
79317
|
-
for (const entry of await
|
|
79811
|
+
for (const entry of await readdir13(directory, { withFileTypes: true })) {
|
|
79318
79812
|
if (++entries > 1e5)
|
|
79319
79813
|
throw new Error("Git metadata inspection exceeded its bound; retain this clone.");
|
|
79320
79814
|
if (entry.name.endsWith(".lock"))
|
|
@@ -79322,29 +79816,29 @@ async function independentGitMetadata(path) {
|
|
|
79322
79816
|
if (entry.isSymbolicLink())
|
|
79323
79817
|
throw new Error("Git metadata redirects through a symbolic link.");
|
|
79324
79818
|
if (entry.isDirectory())
|
|
79325
|
-
pending.push(
|
|
79819
|
+
pending.push(join52(directory, entry.name));
|
|
79326
79820
|
else if (!entry.isFile())
|
|
79327
79821
|
throw new Error("Git metadata contains an unsupported file type; preserve this clone.");
|
|
79328
79822
|
}
|
|
79329
79823
|
}
|
|
79330
79824
|
}
|
|
79331
79825
|
async function emptyScratch(path, depth = 0) {
|
|
79332
|
-
if (depth > 8 || !(await
|
|
79826
|
+
if (depth > 8 || !(await lstat24(path)).isDirectory() || await realpath29(path) !== path)
|
|
79333
79827
|
return false;
|
|
79334
|
-
const entries = await
|
|
79828
|
+
const entries = await readdir13(path);
|
|
79335
79829
|
if (entries.length > 100)
|
|
79336
79830
|
return false;
|
|
79337
79831
|
for (const name of entries)
|
|
79338
|
-
if (!await emptyScratch(
|
|
79832
|
+
if (!await emptyScratch(join52(path, name), depth + 1))
|
|
79339
79833
|
return false;
|
|
79340
79834
|
return true;
|
|
79341
79835
|
}
|
|
79342
79836
|
async function inspectClone(path, baseline) {
|
|
79343
79837
|
await localDirectory3(path);
|
|
79344
|
-
await localDirectory3(
|
|
79345
|
-
await independentGitMetadata(
|
|
79838
|
+
await localDirectory3(join52(path, ".git"));
|
|
79839
|
+
await independentGitMetadata(join52(path, ".git"));
|
|
79346
79840
|
for (const key of ["commondir", "objects/info/alternates", "objects/info/http-alternates", "info/grafts", "shallow"])
|
|
79347
|
-
if (await exists(
|
|
79841
|
+
if (await exists(join52(path, ".git", key)))
|
|
79348
79842
|
throw new Error("Git metadata depends on another repository.");
|
|
79349
79843
|
const [top, branch, head, refs, status, worktrees, remotes] = await Promise.all([
|
|
79350
79844
|
git(path, ["rev-parse", "--show-toplevel"]),
|
|
@@ -79369,7 +79863,7 @@ async function inspectClone(path, baseline) {
|
|
|
79369
79863
|
`) !== `worktree ${path}`)
|
|
79370
79864
|
throw new Error("Frozen baseline has linked worktrees.");
|
|
79371
79865
|
for (const entry of status.split("\x00").filter(Boolean)) {
|
|
79372
|
-
if (entry === "!! .agent-valley/" && await emptyScratch(
|
|
79866
|
+
if (entry === "!! .agent-valley/" && await emptyScratch(join52(path, ".agent-valley")))
|
|
79373
79867
|
continue;
|
|
79374
79868
|
throw new Error("Frozen baseline has tracked, untracked or ignored changes.");
|
|
79375
79869
|
}
|
|
@@ -79402,22 +79896,22 @@ async function recoverable(current, baseline) {
|
|
|
79402
79896
|
throw new Error("The current baseline is missing recovery objects.");
|
|
79403
79897
|
}
|
|
79404
79898
|
async function processEvidence(storePath, missionId) {
|
|
79405
|
-
if (await exists(
|
|
79899
|
+
if (await exists(join52(storePath, `${missionId}.json.lock`)))
|
|
79406
79900
|
return true;
|
|
79407
|
-
if (await exists(
|
|
79901
|
+
if (await exists(join52(storePath, `${missionId}.json.lock.reclaim`)))
|
|
79408
79902
|
return true;
|
|
79409
|
-
return (await
|
|
79903
|
+
return (await readdir13(storePath)).some((name) => name === `${missionId}.active` || name.startsWith(`${missionId}.run-`) && name.endsWith(".active"));
|
|
79410
79904
|
}
|
|
79411
79905
|
async function protectMissionBaseline(mission, protectedPaths) {
|
|
79412
79906
|
if (!mission.repositoryRoot)
|
|
79413
79907
|
throw new Error("An unresolved mission has no repository identity; preserve all baselines.");
|
|
79414
79908
|
protectedPaths.add(mission.workspace.path);
|
|
79415
79909
|
const workspace = mission.workspace.path;
|
|
79416
|
-
const prefix =
|
|
79910
|
+
const prefix = join52(mission.repositoryRoot, ".agent-valley", "operations");
|
|
79417
79911
|
if (!workspace.startsWith(`${prefix}/`))
|
|
79418
79912
|
return;
|
|
79419
79913
|
await localDirectory3(dirname11(workspace));
|
|
79420
|
-
const raw = await readLocal(
|
|
79914
|
+
const raw = await readLocal(join52(dirname11(workspace), "workspace.json"));
|
|
79421
79915
|
if (!raw)
|
|
79422
79916
|
throw new Error("An unresolved mission is missing its workspace receipt; preserve all baselines.");
|
|
79423
79917
|
const value = JSON.parse(raw);
|
|
@@ -79427,37 +79921,37 @@ async function protectMissionBaseline(mission, protectedPaths) {
|
|
|
79427
79921
|
}
|
|
79428
79922
|
async function referencedBaselines(storageRoot, operations) {
|
|
79429
79923
|
const protectedPaths = new Set;
|
|
79430
|
-
const missionDirectories = [
|
|
79924
|
+
const missionDirectories = [join52(storageRoot, ".agent-valley", "missions")];
|
|
79431
79925
|
for (const operation of operations) {
|
|
79432
79926
|
if (operation.baseline)
|
|
79433
79927
|
protectedPaths.add(operation.baseline.path);
|
|
79434
79928
|
if (operation.sourceIntegration)
|
|
79435
|
-
protectedPaths.add(
|
|
79929
|
+
protectedPaths.add(join52(operation.repositoryRoot, ".agent-valley", "operations", operation.id, "baselines", operation.sourceIntegration.missionId, "workspace"));
|
|
79436
79930
|
for (const id of [operation.currentMissionId, operation.decisionId]) {
|
|
79437
79931
|
if (!id)
|
|
79438
79932
|
continue;
|
|
79439
|
-
const container =
|
|
79933
|
+
const container = join52(operation.repositoryRoot, ".agent-valley", "operations", operation.id, "workspaces", id);
|
|
79440
79934
|
await localDirectory3(container);
|
|
79441
|
-
const raw = await readLocal(
|
|
79935
|
+
const raw = await readLocal(join52(container, "workspace.json"));
|
|
79442
79936
|
if (!raw)
|
|
79443
79937
|
throw new Error("An active child or decision has no workspace receipt; preserve all baselines.");
|
|
79444
79938
|
const value = JSON.parse(raw);
|
|
79445
79939
|
if (value.operationId !== operation.id || value.missionId !== id || typeof value.baselinePath !== "string")
|
|
79446
79940
|
throw new Error("An active workspace has an ambiguous baseline reference.");
|
|
79447
79941
|
protectedPaths.add(await realpath29(value.baselinePath));
|
|
79448
|
-
protectedPaths.add(
|
|
79942
|
+
protectedPaths.add(join52(operation.repositoryRoot, ".agent-valley", "operations", operation.id, "baselines", id, "workspace"));
|
|
79449
79943
|
}
|
|
79450
|
-
missionDirectories.push(
|
|
79944
|
+
missionDirectories.push(join52(storageRoot, ".agent-valley", "operation-decisions", operation.id));
|
|
79451
79945
|
}
|
|
79452
79946
|
for (const directory of missionDirectories) {
|
|
79453
79947
|
if (!await exists(directory))
|
|
79454
79948
|
continue;
|
|
79455
79949
|
await localDirectory3(directory);
|
|
79456
79950
|
const store = new MissionStore(directory);
|
|
79457
|
-
for (const name of await
|
|
79951
|
+
for (const name of await readdir13(directory)) {
|
|
79458
79952
|
if (!name.endsWith(".json"))
|
|
79459
79953
|
continue;
|
|
79460
|
-
await readLocal(
|
|
79954
|
+
await readLocal(join52(directory, name));
|
|
79461
79955
|
const mission = await store.load(name.slice(0, -5));
|
|
79462
79956
|
if (mission.status !== "completed" || mission.tasks.some((task) => task.effectState === "unknown") || mission.operations?.runs.some((run) => run.executionState && run.executionState !== "settled") || await processEvidence(directory, mission.id))
|
|
79463
79957
|
await protectMissionBaseline(mission, protectedPaths);
|
|
@@ -79469,7 +79963,7 @@ async function pruneContinuousBaselines(storageRoot, operationId, options = {})
|
|
|
79469
79963
|
operationIdSchema.parse(operationId);
|
|
79470
79964
|
if (await realpath29(storageRoot) !== resolve32(storageRoot))
|
|
79471
79965
|
throw new Error("Use the original canonical operation storage root.");
|
|
79472
|
-
const directory =
|
|
79966
|
+
const directory = join52(storageRoot, ".agent-valley", "operations");
|
|
79473
79967
|
await localDirectory3(directory);
|
|
79474
79968
|
const store = new ContinuousOperationStore(directory);
|
|
79475
79969
|
const unlock = await store.lock(operationId);
|
|
@@ -79479,26 +79973,26 @@ async function pruneContinuousBaselines(storageRoot, operationId, options = {})
|
|
|
79479
79973
|
await localDirectory3(root);
|
|
79480
79974
|
if ((await git(root, ["rev-parse", "--show-toplevel"])).trim() !== root)
|
|
79481
79975
|
throw new Error("Restore the original Git repository before pruning.");
|
|
79482
|
-
const artifacts =
|
|
79483
|
-
const baselines =
|
|
79976
|
+
const artifacts = join52(root, ".agent-valley", "operations", operationId);
|
|
79977
|
+
const baselines = join52(artifacts, "baselines");
|
|
79484
79978
|
await localDirectory3(artifacts);
|
|
79485
79979
|
await localDirectory3(baselines);
|
|
79486
79980
|
const current = operation.baseline;
|
|
79487
79981
|
if (!current)
|
|
79488
79982
|
throw new Error("No accepted baseline exists. Preserve the operation artifacts.");
|
|
79489
79983
|
const protectedPaths = await referencedBaselines(storageRoot, await store.list());
|
|
79490
|
-
protectedPaths.add(
|
|
79984
|
+
protectedPaths.add(join52(baselines, "initial", "workspace"));
|
|
79491
79985
|
for (const entry of operation.history.slice(-2))
|
|
79492
79986
|
protectedPaths.add(entry.baselinePath);
|
|
79493
|
-
const currentReceipt = continuousBaselineSchema.parse(JSON.parse(await readLocal(
|
|
79987
|
+
const currentReceipt = continuousBaselineSchema.parse(JSON.parse(await readLocal(join52(dirname11(current.path), "baseline.json")) ?? "null"));
|
|
79494
79988
|
if (JSON.stringify(currentReceipt) !== JSON.stringify(current))
|
|
79495
79989
|
throw new Error("The accepted baseline receipt changed.");
|
|
79496
79990
|
await inspectClone(current.path, current);
|
|
79497
|
-
const missionsPath =
|
|
79991
|
+
const missionsPath = join52(storageRoot, ".agent-valley", "missions");
|
|
79498
79992
|
const missions = new MissionStore(missionsPath);
|
|
79499
79993
|
const candidates = [];
|
|
79500
|
-
for (const key of (await
|
|
79501
|
-
const path =
|
|
79994
|
+
for (const key of (await readdir13(baselines)).sort()) {
|
|
79995
|
+
const path = join52(baselines, key, "workspace");
|
|
79502
79996
|
let release;
|
|
79503
79997
|
let result = { key, path, status: "kept", reason: "Retained for inspection." };
|
|
79504
79998
|
try {
|
|
@@ -79506,16 +80000,16 @@ async function pruneContinuousBaselines(storageRoot, operationId, options = {})
|
|
|
79506
80000
|
await localDirectory3(dirname11(path));
|
|
79507
80001
|
if (protectedPaths.has(path))
|
|
79508
80002
|
throw new Error("Initial, current, previous or referenced baseline is protected.");
|
|
79509
|
-
const raw = await readLocal(
|
|
80003
|
+
const raw = await readLocal(join52(dirname11(path), "baseline.json"));
|
|
79510
80004
|
const snapshot = continuousBaselineSchema.parse(JSON.parse(raw ?? "null"));
|
|
79511
|
-
const transaction = continuousBaselineSchema.parse(JSON.parse(await readLocal(
|
|
80005
|
+
const transaction = continuousBaselineSchema.parse(JSON.parse(await readLocal(join52(dirname11(path), "snapshot.json")) ?? "null"));
|
|
79512
80006
|
if (JSON.stringify(transaction) !== JSON.stringify(snapshot))
|
|
79513
80007
|
throw new Error("Original snapshot transaction and baseline receipts differ.");
|
|
79514
80008
|
if (snapshot.operationId !== operationId || snapshot.repositoryRoot !== root || snapshot.path !== path || snapshot.missionId !== key || snapshot.branch !== `av-operation/${operationId}/baseline-${key}`)
|
|
79515
80009
|
throw new Error("Baseline identity does not match its private directory.");
|
|
79516
|
-
const preparedPath =
|
|
79517
|
-
const completedPath =
|
|
79518
|
-
const quarantine =
|
|
80010
|
+
const preparedPath = join52(dirname11(path), "pruning.json");
|
|
80011
|
+
const completedPath = join52(dirname11(path), "pruned.json");
|
|
80012
|
+
const quarantine = join52(dirname11(path), "workspace.pruning");
|
|
79519
80013
|
const preparedRaw = await readLocal(preparedPath);
|
|
79520
80014
|
const prepared = preparedRaw ? preparedSchema.parse(JSON.parse(preparedRaw)) : undefined;
|
|
79521
80015
|
if (prepared && (prepared.operationId !== operationId || prepared.missionId !== key || prepared.path !== path || prepared.quarantine !== quarantine || prepared.commit !== snapshot.commit || prepared.tree !== snapshot.baselineTree || prepared.baselineDigest !== digest7(raw)))
|
|
@@ -79530,7 +80024,7 @@ async function pruneContinuousBaselines(storageRoot, operationId, options = {})
|
|
|
79530
80024
|
continue;
|
|
79531
80025
|
}
|
|
79532
80026
|
const accepted = operation.history.some((entry) => entry.missionId === key && entry.baselinePath === path);
|
|
79533
|
-
const journalRaw = await readLocal(
|
|
80027
|
+
const journalRaw = await readLocal(join52(dirname11(path), "acceptance.json"));
|
|
79534
80028
|
const journal = journalRaw ? continuousAcceptanceSchema.parse(JSON.parse(journalRaw)) : undefined;
|
|
79535
80029
|
if (journal && (journal.operationId !== operationId || journal.repositoryRoot !== root || journal.missionId !== key || journal.baselinePath !== path || journal.commit !== snapshot.commit || journal.tree !== snapshot.baselineTree || journal.cycle > operation.completedCycles))
|
|
79536
80030
|
throw new Error("Acceptance journal does not match this frozen baseline.");
|
|
@@ -79566,7 +80060,7 @@ async function pruneContinuousBaselines(storageRoot, operationId, options = {})
|
|
|
79566
80060
|
if (hasQuarantine && !prepared)
|
|
79567
80061
|
throw new Error("Unrecorded pruning quarantine is protected.");
|
|
79568
80062
|
await inspectClone(physicalPath, snapshot);
|
|
79569
|
-
const identity = await
|
|
80063
|
+
const identity = await lstat24(physicalPath);
|
|
79570
80064
|
if (prepared && (identity.dev !== prepared.device || identity.ino !== prepared.inode))
|
|
79571
80065
|
throw new Error("Workspace identity changed after pruning was prepared.");
|
|
79572
80066
|
result = {
|
|
@@ -79590,13 +80084,13 @@ async function pruneContinuousBaselines(storageRoot, operationId, options = {})
|
|
|
79590
80084
|
at: (options.now?.() ?? new Date).toISOString()
|
|
79591
80085
|
});
|
|
79592
80086
|
await inspectClone(physicalPath, snapshot);
|
|
79593
|
-
const checked = await
|
|
80087
|
+
const checked = await lstat24(physicalPath);
|
|
79594
80088
|
if (checked.dev !== identity.dev || checked.ino !== identity.ino)
|
|
79595
80089
|
throw new Error("Workspace identity changed before pruning.");
|
|
79596
80090
|
if (!hasQuarantine)
|
|
79597
80091
|
await rename4(path, quarantine);
|
|
79598
80092
|
await localDirectory3(quarantine);
|
|
79599
|
-
const moved = await
|
|
80093
|
+
const moved = await lstat24(quarantine);
|
|
79600
80094
|
if (moved.dev !== identity.dev || moved.ino !== identity.ino)
|
|
79601
80095
|
throw new Error("Pruning quarantine identity changed.");
|
|
79602
80096
|
await rm7(quarantine, { recursive: true });
|
|
@@ -79675,7 +80169,7 @@ function integerOption(value, name, maximum) {
|
|
|
79675
80169
|
return number;
|
|
79676
80170
|
}
|
|
79677
80171
|
function operationStore(root) {
|
|
79678
|
-
return new ContinuousOperationStore(
|
|
80172
|
+
return new ContinuousOperationStore(join53(resolve33(root), ".agent-valley", "operations"));
|
|
79679
80173
|
}
|
|
79680
80174
|
async function restoreOperationOrigin(repository, workspace) {
|
|
79681
80175
|
const env = { ...process.env, ...clearedGitEnvironment };
|
|
@@ -79783,7 +80277,7 @@ async function runOperation(charter, options, root = process.cwd(), dependencies
|
|
|
79783
80277
|
if (options.retry || decisionBudgetKeys.some((key) => options[key] !== undefined)) {
|
|
79784
80278
|
if (operation.currentMissionId || !operation.decisionId)
|
|
79785
80279
|
throw new Error("Operation resume budget reconciliation applies only to an active decision checkpoint. Adjust the current child's budget with av order --resume <child-id>.");
|
|
79786
|
-
const decisions = new MissionStore(
|
|
80280
|
+
const decisions = new MissionStore(join53(root, ".agent-valley", "operation-decisions", operation.id));
|
|
79787
80281
|
const unlockDecision = await decisions.lock(operation.decisionId);
|
|
79788
80282
|
try {
|
|
79789
80283
|
const decision = await decisions.load(operation.decisionId);
|
|
@@ -79855,7 +80349,7 @@ async function runOperation(charter, options, root = process.cwd(), dependencies
|
|
|
79855
80349
|
console.log(`Operation ${id}
|
|
79856
80350
|
Charter: ${operation.charter}
|
|
79857
80351
|
Resume: av order --resume ${id}`);
|
|
79858
|
-
const missions = new MissionStore(
|
|
80352
|
+
const missions = new MissionStore(join53(root, ".agent-valley", "missions"));
|
|
79859
80353
|
return await runContinuousOperation(operation, {
|
|
79860
80354
|
signal: controller.signal,
|
|
79861
80355
|
...options.retry ? { retryDecision: true } : {},
|
|
@@ -79993,7 +80487,7 @@ class OperationApi {
|
|
|
79993
80487
|
this.root = root;
|
|
79994
80488
|
this.workspace = workspace;
|
|
79995
80489
|
this.dependencies = dependencies;
|
|
79996
|
-
this.store = new ContinuousOperationStore(
|
|
80490
|
+
this.store = new ContinuousOperationStore(join54(root, ".agent-valley/operations"));
|
|
79997
80491
|
this.jobs = new MissionJobs(root, "operation-jobs");
|
|
79998
80492
|
}
|
|
79999
80493
|
order(raw) {
|
|
@@ -80242,17 +80736,17 @@ class MissionApi {
|
|
|
80242
80736
|
this.projectRoot = projectRoot;
|
|
80243
80737
|
this.workspace = workspace;
|
|
80244
80738
|
this.dependencies = dependencies;
|
|
80245
|
-
this.store = new MissionStore(
|
|
80739
|
+
this.store = new MissionStore(join55(projectRoot, ".agent-valley/missions"));
|
|
80246
80740
|
this.jobs = new MissionJobs(projectRoot);
|
|
80247
80741
|
this.operationApi = new OperationApi(projectRoot, workspace, dependencies);
|
|
80248
80742
|
this.operationJobs = new MissionJobs(projectRoot, "operation-jobs");
|
|
80249
80743
|
}
|
|
80250
80744
|
static async create(workspace, dependencies = {}) {
|
|
80251
|
-
if (!
|
|
80745
|
+
if (!isAbsolute19(workspace))
|
|
80252
80746
|
throw new Error("Set an absolute Git repository path in av mcp --workspace <path>.");
|
|
80253
80747
|
const projectRoot = await realpath33(workspace);
|
|
80254
80748
|
const target = loadProjectConfig(projectRoot)?.workspace?.root ?? projectRoot;
|
|
80255
|
-
if (!
|
|
80749
|
+
if (!isAbsolute19(target))
|
|
80256
80750
|
throw new Error("Set workspace.root in av.yaml to an absolute Git repository path.");
|
|
80257
80751
|
return new MissionApi(projectRoot, await realpath33(target), dependencies);
|
|
80258
80752
|
}
|
|
@@ -80281,7 +80775,7 @@ class MissionApi {
|
|
|
80281
80775
|
async order(raw) {
|
|
80282
80776
|
assertNotManagedRun(this.dependencies.env);
|
|
80283
80777
|
const input = mcpOrderSchema.parse(raw);
|
|
80284
|
-
if (input.workspace && (!
|
|
80778
|
+
if (input.workspace && (!isAbsolute19(input.workspace) || await realpath33(input.workspace) !== this.workspace))
|
|
80285
80779
|
throw new Error("This AV server is bound to another workspace. Start av mcp --workspace for the target repository.");
|
|
80286
80780
|
return this.serializeOrder(async () => {
|
|
80287
80781
|
if (input.requestId) {
|
|
@@ -80304,7 +80798,7 @@ class MissionApi {
|
|
|
80304
80798
|
async list() {
|
|
80305
80799
|
this.assertOpen();
|
|
80306
80800
|
await ensureAvDirectory(this.projectRoot, ["missions"]);
|
|
80307
|
-
const ids = new Set((await
|
|
80801
|
+
const ids = new Set((await readdir14(join55(this.projectRoot, ".agent-valley/missions"))).filter((name) => name.endsWith(".json")).map((name) => missionIdSchema.parse(name.slice(0, -5))));
|
|
80308
80802
|
for (const job of await this.jobs.list())
|
|
80309
80803
|
ids.add(job.missionId);
|
|
80310
80804
|
return {
|
|
@@ -80458,8 +80952,8 @@ class MissionApi {
|
|
|
80458
80952
|
async load(id) {
|
|
80459
80953
|
await ensureAvDirectory(this.projectRoot, ["missions"]);
|
|
80460
80954
|
try {
|
|
80461
|
-
const path =
|
|
80462
|
-
const stat = await
|
|
80955
|
+
const path = join55(this.projectRoot, ".agent-valley/missions", `${missionIdSchema.parse(id)}.json`);
|
|
80956
|
+
const stat = await lstat25(path);
|
|
80463
80957
|
if (!stat.isFile() || stat.isSymbolicLink())
|
|
80464
80958
|
throw new Error(`Mission record must be a regular file: ${path}. Remove the symlink before retrying.`);
|
|
80465
80959
|
return await this.store.load(id);
|
|
@@ -80483,11 +80977,11 @@ class MissionApi {
|
|
|
80483
80977
|
// src/plugin-export.ts
|
|
80484
80978
|
init_client_integrations_assets();
|
|
80485
80979
|
init_client_integrations_files();
|
|
80486
|
-
import { lstat as
|
|
80487
|
-
import { dirname as dirname12, join as
|
|
80980
|
+
import { lstat as lstat26, readdir as readdir15, realpath as realpath34 } from "node:fs/promises";
|
|
80981
|
+
import { dirname as dirname12, join as join56, relative as relative17, resolve as resolve34 } from "node:path";
|
|
80488
80982
|
|
|
80489
80983
|
// src/plugin-assets.ts
|
|
80490
|
-
import { copyFile as copyFile2, mkdir as mkdir24, readFile as
|
|
80984
|
+
import { copyFile as copyFile2, mkdir as mkdir24, readFile as readFile20 } from "node:fs/promises";
|
|
80491
80985
|
init_zod();
|
|
80492
80986
|
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
80493
80987
|
var pluginSchemaUrl = "https://agent-plugins.org/schemas/1.0.0/plugin.schema.json";
|
|
@@ -80519,7 +81013,7 @@ async function loadPluginLicenseAsset(candidates = pluginLicenseAssetCandidates(
|
|
|
80519
81013
|
for (const path of candidates) {
|
|
80520
81014
|
let content;
|
|
80521
81015
|
try {
|
|
80522
|
-
content = await
|
|
81016
|
+
content = await readFile20(path, "utf8");
|
|
80523
81017
|
} catch (error) {
|
|
80524
81018
|
if (error.code === "ENOENT")
|
|
80525
81019
|
continue;
|
|
@@ -80535,7 +81029,7 @@ async function loadPluginManifestAsset(candidates = pluginManifestAssetCandidate
|
|
|
80535
81029
|
for (const path of candidates) {
|
|
80536
81030
|
let content;
|
|
80537
81031
|
try {
|
|
80538
|
-
content = await
|
|
81032
|
+
content = await readFile20(path, "utf8");
|
|
80539
81033
|
} catch (error) {
|
|
80540
81034
|
if (error.code === "ENOENT")
|
|
80541
81035
|
continue;
|
|
@@ -80652,7 +81146,7 @@ async function projectDirectory(workspace) {
|
|
|
80652
81146
|
throw new Error("Pass --workspace /absolute/AV-project to bind every exported MCP server to its AV configuration.");
|
|
80653
81147
|
try {
|
|
80654
81148
|
const project = await realpath34(resolve34(workspace));
|
|
80655
|
-
if (!(await
|
|
81149
|
+
if (!(await lstat26(project)).isDirectory())
|
|
80656
81150
|
throw new Error("not a directory");
|
|
80657
81151
|
return project;
|
|
80658
81152
|
} catch {
|
|
@@ -80678,12 +81172,12 @@ async function outputDirectory(output) {
|
|
|
80678
81172
|
let ancestor = target;
|
|
80679
81173
|
for (;; ) {
|
|
80680
81174
|
try {
|
|
80681
|
-
const info = await
|
|
81175
|
+
const info = await lstat26(ancestor);
|
|
80682
81176
|
if (info.isSymbolicLink())
|
|
80683
81177
|
throw exportConflict(ancestor, "symbolic link exports are not modified");
|
|
80684
81178
|
if (!info.isDirectory())
|
|
80685
81179
|
throw exportConflict(ancestor, "expected an output directory");
|
|
80686
|
-
return
|
|
81180
|
+
return join56(await realpath34(ancestor), relative17(ancestor, target));
|
|
80687
81181
|
} catch (error) {
|
|
80688
81182
|
if (error.code !== "ENOENT")
|
|
80689
81183
|
throw error;
|
|
@@ -80694,7 +81188,7 @@ async function outputDirectory(output) {
|
|
|
80694
81188
|
async function outputFiles(root, directory = root) {
|
|
80695
81189
|
let entries;
|
|
80696
81190
|
try {
|
|
80697
|
-
entries = await
|
|
81191
|
+
entries = await readdir15(directory, { withFileTypes: true });
|
|
80698
81192
|
} catch (error) {
|
|
80699
81193
|
if (error.code === "ENOENT")
|
|
80700
81194
|
return [];
|
|
@@ -80702,7 +81196,7 @@ async function outputFiles(root, directory = root) {
|
|
|
80702
81196
|
}
|
|
80703
81197
|
const files = [];
|
|
80704
81198
|
for (const entry of entries) {
|
|
80705
|
-
const path =
|
|
81199
|
+
const path = join56(directory, entry.name);
|
|
80706
81200
|
if (entry.isSymbolicLink())
|
|
80707
81201
|
throw exportConflict(path, "symbolic links are not modified");
|
|
80708
81202
|
if (entry.isDirectory())
|
|
@@ -80739,21 +81233,21 @@ async function exportPluginPackages(options) {
|
|
|
80739
81233
|
if (output === workspace)
|
|
80740
81234
|
throw exportConflict(output, "the output directory must be separate from the AV project root");
|
|
80741
81235
|
const { manifest } = await loadPluginManifestAsset(options.sourceManifest ? [options.sourceManifest] : undefined);
|
|
80742
|
-
const { content: skill } = await loadClientSkillAsset(options.sourceSkillRoot ? [
|
|
81236
|
+
const { content: skill } = await loadClientSkillAsset(options.sourceSkillRoot ? [join56(options.sourceSkillRoot, "SKILL.md")] : clientSkillAssetCandidates());
|
|
80743
81237
|
const { content: license } = await loadPluginLicenseAsset(options.sourceLicense ? [options.sourceLicense] : undefined);
|
|
80744
81238
|
const packageFiles = pluginPackageFiles(manifest, skill, license, { workspace, remoteUrl });
|
|
80745
|
-
const receipt = await integrationFile(output,
|
|
81239
|
+
const receipt = await integrationFile(output, join56(output, receiptName2), "", 384);
|
|
80746
81240
|
const hashes = ownedFileHashes(receipt.before, receipt.path);
|
|
80747
81241
|
const existing = await outputFiles(output);
|
|
80748
81242
|
for (const path of existing) {
|
|
80749
81243
|
if (path === receiptName2)
|
|
80750
81244
|
continue;
|
|
80751
81245
|
if (!packageFiles.has(path) || hashes[path] === undefined)
|
|
80752
|
-
throw exportConflict(
|
|
81246
|
+
throw exportConflict(join56(output, path), "unowned files are retained");
|
|
80753
81247
|
}
|
|
80754
81248
|
const files = [];
|
|
80755
81249
|
for (const [path, content] of packageFiles) {
|
|
80756
|
-
const file = await integrationFile(output,
|
|
81250
|
+
const file = await integrationFile(output, join56(output, path), content, 420);
|
|
80757
81251
|
if (hashes[path] !== undefined && (file.before === null || contentHash(file.before) !== hashes[path]))
|
|
80758
81252
|
throw exportConflict(file.path, "the exported file was changed or removed locally");
|
|
80759
81253
|
if (hashes[path] === undefined && file.before !== null)
|
|
@@ -80772,11 +81266,11 @@ async function exportPluginPackages(options) {
|
|
|
80772
81266
|
transport: remoteUrl ? "streamable-http" : "stdio",
|
|
80773
81267
|
files: await applyIntegrationFiles(output, [...files, receipt]),
|
|
80774
81268
|
packages: {
|
|
80775
|
-
portable:
|
|
80776
|
-
claude:
|
|
80777
|
-
cursor:
|
|
80778
|
-
qwen:
|
|
80779
|
-
antigravity:
|
|
81269
|
+
portable: join56(output, "portable/av"),
|
|
81270
|
+
claude: join56(output, "claude/plugins/av"),
|
|
81271
|
+
cursor: join56(output, "cursor/plugins/av"),
|
|
81272
|
+
qwen: join56(output, "qwen/av"),
|
|
81273
|
+
antigravity: join56(output, "antigravity/av")
|
|
80780
81274
|
}
|
|
80781
81275
|
};
|
|
80782
81276
|
}
|
|
@@ -80839,7 +81333,7 @@ function registerAgentClientCommands(program) {
|
|
|
80839
81333
|
// src/chief.ts
|
|
80840
81334
|
import { randomUUID as randomUUID24 } from "node:crypto";
|
|
80841
81335
|
import { realpath as realpath37 } from "node:fs/promises";
|
|
80842
|
-
import { join as
|
|
81336
|
+
import { join as join64 } from "node:path";
|
|
80843
81337
|
|
|
80844
81338
|
// ../../node_modules/.bun/@langchain+core@1.2.20+ea9f70ecde856c26/node_modules/@langchain/core/dist/_virtual/_rolldown/runtime.js
|
|
80845
81339
|
var __defProp4 = Object.defineProperty;
|
|
@@ -89796,10 +90290,10 @@ async function writeFileAtomic(filePath, content) {
|
|
|
89796
90290
|
});
|
|
89797
90291
|
await nodeFsPromises.rename(tempPath, filePath);
|
|
89798
90292
|
}
|
|
89799
|
-
async function
|
|
90293
|
+
async function readdir17(dir) {
|
|
89800
90294
|
return nodeFsPromises.readdir(dir);
|
|
89801
90295
|
}
|
|
89802
|
-
async function
|
|
90296
|
+
async function stat6(filePath) {
|
|
89803
90297
|
return nodeFsPromises.stat(filePath);
|
|
89804
90298
|
}
|
|
89805
90299
|
function existsSync6(p) {
|
|
@@ -92284,11 +92778,11 @@ class Client2 {
|
|
|
92284
92778
|
}
|
|
92285
92779
|
if (maxBytes !== undefined && maxBytes > 0) {
|
|
92286
92780
|
try {
|
|
92287
|
-
const entries = await
|
|
92781
|
+
const entries = await readdir17(directory);
|
|
92288
92782
|
const traceFiles = entries.filter((f) => f.startsWith("trace_") && f.endsWith(".json"));
|
|
92289
92783
|
let total = 0;
|
|
92290
92784
|
for (const name of traceFiles) {
|
|
92291
|
-
const { size } = await
|
|
92785
|
+
const { size } = await stat6(path6.join(directory, name));
|
|
92292
92786
|
total += size;
|
|
92293
92787
|
}
|
|
92294
92788
|
if (total >= maxBytes) {
|
|
@@ -131330,7 +131824,8 @@ function applyVerificationResult(mission, result, fingerprint) {
|
|
|
131330
131824
|
init_execution();
|
|
131331
131825
|
|
|
131332
131826
|
// ../../packages/core/src/chief/review-routing.ts
|
|
131333
|
-
|
|
131827
|
+
init_execution();
|
|
131828
|
+
function addReviewer(mission, vendor, model) {
|
|
131334
131829
|
if (mission.personas.length >= 20)
|
|
131335
131830
|
throw new Error("Independent vendor review needs a roster slot. Add a reviewer using the required ready vendor or leave a slot free in the --actors roster.");
|
|
131336
131831
|
let id = `review-${vendor}`;
|
|
@@ -131341,6 +131836,7 @@ function addReviewer(mission, vendor) {
|
|
|
131341
131836
|
name: `Independent ${vendor} reviewer`,
|
|
131342
131837
|
role: "Independently inspect actual files and task acceptance evidence; report blockers without editing files.",
|
|
131343
131838
|
agentType: vendor,
|
|
131839
|
+
...model ? { model } : {},
|
|
131344
131840
|
skills: []
|
|
131345
131841
|
};
|
|
131346
131842
|
mission.personas.push(reviewer);
|
|
@@ -131351,30 +131847,36 @@ function selectTaskReviewer(mission, task, state, gateId) {
|
|
|
131351
131847
|
if (!configured)
|
|
131352
131848
|
throw new Error("Restore the configured task reviewer before resuming.");
|
|
131353
131849
|
const policy = mission.operatingPolicy;
|
|
131354
|
-
if (!policy || policy.reviewVendor === "off")
|
|
131850
|
+
if (!policy || policy.reviewVendor === "off") {
|
|
131851
|
+
availableActorRoutes(mission, [{ actorType: configured.agentType, model: configured.model }]);
|
|
131355
131852
|
return configured;
|
|
131853
|
+
}
|
|
131356
131854
|
const run = latestWorkRun(mission, task.id);
|
|
131357
131855
|
const worker = run?.actorType ?? mission.personas.find((actor) => actor.id === task.personaId)?.agentType;
|
|
131358
131856
|
if (!worker)
|
|
131359
131857
|
throw new Error("Restore this task's actual work Actor before reviewing it.");
|
|
131360
131858
|
const blocked = unavailableProviders(mission.handoff);
|
|
131361
|
-
const
|
|
131362
|
-
const
|
|
131363
|
-
|
|
131364
|
-
|
|
131365
|
-
|
|
131366
|
-
|
|
131367
|
-
if (
|
|
131368
|
-
|
|
131369
|
-
|
|
131370
|
-
|
|
131371
|
-
|
|
131859
|
+
const recordedReady = policy.readyActors ?? mission.availableAgents ?? [];
|
|
131860
|
+
const ready = recordedReady.filter((vendor) => !blocked.has(vendor));
|
|
131861
|
+
if (recordedReady.length && !ready.length)
|
|
131862
|
+
throw new MissionPause("No recorded ready reviewer remains after saved provider availability exclusions. Restore access to an eligible Actor before continuing; the completed work remains pending review.", "handoff-unavailable");
|
|
131863
|
+
const pool = [configured, ...mission.personas.filter((actor) => actor.id !== configured.id)].filter((actor) => actor.id !== task.personaId && ready.includes(actor.agentType)).map((actor) => ({ actorType: actor.agentType, model: actor.model, actor }));
|
|
131864
|
+
for (const vendor of ready)
|
|
131865
|
+
if (!pool.some((entry) => entry.actorType === vendor)) {
|
|
131866
|
+
const model = mission.operatingPolicy?.routing?.candidates.find((entry) => entry.actorType === vendor)?.model;
|
|
131867
|
+
pool.push({ actorType: vendor, model, actor: undefined });
|
|
131868
|
+
}
|
|
131869
|
+
const crossVendor = pool.filter((entry) => entry.actorType !== worker);
|
|
131870
|
+
if (!crossVendor.length && policy.reviewVendor === "require") {
|
|
131372
131871
|
throw new Error(`Cross-vendor review is required but no ready vendor differs from ${worker}. Install/login another Actor CLI and start a new mission, or set chief.review_vendor to prefer before creating an order.`);
|
|
131373
|
-
} else if (configured.agentType !== worker && ready.includes(worker)) {
|
|
131374
|
-
reviewer = mission.personas.find((actor) => actor.id !== task.personaId && actor.agentType === worker) ?? addReviewer(mission, worker);
|
|
131375
|
-
} else if (!ready.length) {
|
|
131376
|
-
reason = "No vendor readiness pool is recorded; the configured independent Actor is attempted with readiness unknown.";
|
|
131377
131872
|
}
|
|
131873
|
+
const healthyCrossVendor = crossVendor.filter((entry) => actorRouteHealth(mission, entry).state === "ready");
|
|
131874
|
+
const candidates = policy.reviewVendor === "require" ? crossVendor : healthyCrossVendor.length ? crossVendor : pool;
|
|
131875
|
+
const selected = availableActorRoutes(mission, candidates).at(0);
|
|
131876
|
+
const reviewer = selected?.actor ?? (selected ? addReviewer(mission, selected.actorType, selected.model) : configured);
|
|
131877
|
+
if (!selected)
|
|
131878
|
+
availableActorRoutes(mission, [{ actorType: reviewer.agentType, model: reviewer.model }]);
|
|
131879
|
+
const reason = !ready.length ? "No vendor readiness pool is recorded; the configured independent Actor is attempted with readiness unknown." : reviewer.agentType !== worker ? "Independent review uses a different healthy ready vendor from the actual work run." : "Cross-vendor review is preferred, but other vendors are unavailable or cooling down; an independent Actor uses the same healthy vendor.";
|
|
131378
131880
|
state.reviewerId = reviewer.id;
|
|
131379
131881
|
mission.operations ??= { runs: [], routingEvidence: [], reviewDecisions: [] };
|
|
131380
131882
|
mission.operations.reviewDecisions.push({
|
|
@@ -131589,7 +132091,9 @@ async function resumeMission(context) {
|
|
|
131589
132091
|
assertNoUncertainExecution(mission);
|
|
131590
132092
|
checkAbort();
|
|
131591
132093
|
assertExecutionDeadline(mission);
|
|
131592
|
-
if (mission.execution?.failureKind
|
|
132094
|
+
if (["chief-wait", "actor-cooldown"].includes(mission.execution?.failureKind ?? "") && mission.execution) {
|
|
132095
|
+
if (mission.execution.failureKind === "actor-cooldown" && !Number.isFinite(Date.parse(mission.execution.nextRunAt ?? "")))
|
|
132096
|
+
throw new MissionPause("The saved Actor cooldown timestamp is missing or invalid. Restore its original nextRunAt before resuming.", "integrity");
|
|
131593
132097
|
if (Date.parse(mission.execution.nextRunAt ?? "") > Date.now())
|
|
131594
132098
|
return { kind: "return" };
|
|
131595
132099
|
delete mission.execution.nextRunAt;
|
|
@@ -131654,6 +132158,9 @@ async function planMission(context) {
|
|
|
131654
132158
|
return { kind: "next", stage: "tasks" };
|
|
131655
132159
|
}
|
|
131656
132160
|
|
|
132161
|
+
// ../../packages/core/src/chief/coordinator-parallel.ts
|
|
132162
|
+
init_execution();
|
|
132163
|
+
|
|
131657
132164
|
// ../../packages/core/src/chief/parallel.ts
|
|
131658
132165
|
function readyTaskWave(plan, states, limit) {
|
|
131659
132166
|
if (!Number.isInteger(limit) || limit < 1 || limit > 20)
|
|
@@ -131725,6 +132232,8 @@ async function performParallelWave(mission, ports, wave, hooks) {
|
|
|
131725
132232
|
continue;
|
|
131726
132233
|
}
|
|
131727
132234
|
try {
|
|
132235
|
+
const previousAttempts = state.attempts;
|
|
132236
|
+
const workRunsBefore = mission.operations?.runs.filter((run) => run.stage === "work" && run.taskId === task.id).length ?? 0;
|
|
131728
132237
|
const previousOutput = state.parallel ? undefined : state.output;
|
|
131729
132238
|
if (!state.parallel)
|
|
131730
132239
|
delete state.output;
|
|
@@ -131740,7 +132249,7 @@ async function performParallelWave(mission, ports, wave, hooks) {
|
|
|
131740
132249
|
path: state.parallel.path,
|
|
131741
132250
|
branch: state.parallel.branch
|
|
131742
132251
|
};
|
|
131743
|
-
prepared.push({ task, state, actor, workspace, previousOutput });
|
|
132252
|
+
prepared.push({ task, state, actor, workspace, previousOutput, previousAttempts, workRunsBefore });
|
|
131744
132253
|
} catch (error) {
|
|
131745
132254
|
state.status = "pending";
|
|
131746
132255
|
fail(task.id, error);
|
|
@@ -131771,6 +132280,8 @@ ${JSON.stringify(previousOutput)}`;
|
|
|
131771
132280
|
const entry = pending[index];
|
|
131772
132281
|
if (entry && result.status === "rejected") {
|
|
131773
132282
|
entry.state.status = "pending";
|
|
132283
|
+
if (result.reason instanceof MissionPause && result.reason.kind === "actor-cooldown" && (mission.operations?.runs.filter((run) => run.stage === "work" && run.taskId === entry.task.id).length ?? 0) === entry.workRunsBefore)
|
|
132284
|
+
entry.state.attempts = entry.previousAttempts;
|
|
131774
132285
|
fail(entry.task.id, result.reason);
|
|
131775
132286
|
}
|
|
131776
132287
|
});
|
|
@@ -131860,6 +132371,8 @@ async function runTaskStage(context) {
|
|
|
131860
132371
|
const performTask = async (task, state) => {
|
|
131861
132372
|
while (state.status !== "completed") {
|
|
131862
132373
|
checkAbort();
|
|
132374
|
+
const attemptsBefore = state.attempts;
|
|
132375
|
+
const workRunsBefore = mission.operations?.runs.filter((run) => run.stage === "work" && run.taskId === task.id).length ?? 0;
|
|
131863
132376
|
const awaitingReview = state.output !== undefined && state.review === undefined;
|
|
131864
132377
|
state.status = awaitingReview ? "reviewing" : "running";
|
|
131865
132378
|
if (!awaitingReview && (task.effectScope !== "external" || state.effectState !== "completed"))
|
|
@@ -131888,6 +132401,8 @@ async function runTaskStage(context) {
|
|
|
131888
132401
|
reviewStarted = true;
|
|
131889
132402
|
await taskReview(task, state);
|
|
131890
132403
|
} catch (error) {
|
|
132404
|
+
if (!reviewStarted && error instanceof MissionPause && error.kind === "actor-cooldown" && (mission.operations?.runs.filter((run) => run.stage === "work" && run.taskId === task.id).length ?? 0) === workRunsBefore)
|
|
132405
|
+
state.attempts = attemptsBefore;
|
|
131891
132406
|
if (!mission.supervision || protectedFailure(error))
|
|
131892
132407
|
throw error;
|
|
131893
132408
|
state.status = reviewStarted ? "reviewing" : "pending";
|
|
@@ -131934,12 +132449,17 @@ async function runTaskStage(context) {
|
|
|
131934
132449
|
const limit = mission.executionPolicy?.maxParallel ?? 1;
|
|
131935
132450
|
const wave = readyTaskWave(plan, mission.tasks, limit).filter((task) => task.effectScope !== "external");
|
|
131936
132451
|
if (ports.parallel && limit > 1 && (wave.length > 1 || wave.some((task) => mission.tasks.find((state) => state.id === task.id)?.parallel))) {
|
|
131937
|
-
|
|
132452
|
+
let failures = await performParallelWave(mission, ports, wave, {
|
|
131938
132453
|
run,
|
|
131939
132454
|
save,
|
|
131940
132455
|
review: taskReview,
|
|
131941
132456
|
fatal: protectedFailure
|
|
131942
132457
|
});
|
|
132458
|
+
const primary = failures.filter((failure) => !(failure.error instanceof MissionPause && failure.error.kind === "actor-cooldown"));
|
|
132459
|
+
failures = primary.length ? primary : failures.flatMap((failure) => {
|
|
132460
|
+
const error = refreshActorCooldown(mission, failure.error);
|
|
132461
|
+
return error === undefined ? [] : [{ ...failure, error, reason: error instanceof Error ? error.message : String(error) }];
|
|
132462
|
+
});
|
|
131943
132463
|
const unrecoverable = failures.find((failure) => protectedFailure(failure.error));
|
|
131944
132464
|
if (unrecoverable)
|
|
131945
132465
|
throw unrecoverable.error;
|
|
@@ -132226,7 +132746,7 @@ init_worktree_lifecycle();
|
|
|
132226
132746
|
import { randomUUID as randomUUID23 } from "node:crypto";
|
|
132227
132747
|
import { mkdtemp as mkdtemp2, rm as rm9 } from "node:fs/promises";
|
|
132228
132748
|
import { tmpdir as tmpdir3 } from "node:os";
|
|
132229
|
-
import { join as
|
|
132749
|
+
import { join as join57 } from "node:path";
|
|
132230
132750
|
async function importIsolatedBranch(workspace, root) {
|
|
132231
132751
|
if (!isIsolatedGitWorkspace(workspace))
|
|
132232
132752
|
return null;
|
|
@@ -132273,7 +132793,7 @@ async function importIsolatedBranch(workspace, root) {
|
|
|
132273
132793
|
`).filter(Boolean);
|
|
132274
132794
|
if (commits.length === 0)
|
|
132275
132795
|
return null;
|
|
132276
|
-
temporaryWorktree = await mkdtemp2(
|
|
132796
|
+
temporaryWorktree = await mkdtemp2(join57(tmpdir3(), "av-branch-import-"));
|
|
132277
132797
|
const added = await runCommand("git", ["worktree", "add", "--detach", temporaryWorktree, currentHead], {
|
|
132278
132798
|
cwd: root
|
|
132279
132799
|
});
|
|
@@ -132313,8 +132833,8 @@ async function importIsolatedBranch(workspace, root) {
|
|
|
132313
132833
|
// ../../packages/core/src/workspace/safety-net.ts
|
|
132314
132834
|
init_logger();
|
|
132315
132835
|
init_worktree_lifecycle();
|
|
132316
|
-
import { lstat as
|
|
132317
|
-
import { isAbsolute as
|
|
132836
|
+
import { lstat as lstat27, readFile as readFile21, realpath as realpath35 } from "node:fs/promises";
|
|
132837
|
+
import { isAbsolute as isAbsolute20, join as join58, relative as relative18, resolve as resolve36, sep as sep17 } from "node:path";
|
|
132318
132838
|
var CONFLICT_MARKER_PATTERN = /^(<<<<<<<|=======|>>>>>>>)( .*)?$/m;
|
|
132319
132839
|
var REGENERATABLE_LOCKFILE_PATTERNS = [
|
|
132320
132840
|
/(^|\/)package-lock\.json$/,
|
|
@@ -132406,7 +132926,7 @@ async function findConflictMarkerFiles(root, files) {
|
|
|
132406
132926
|
const conflicts = [];
|
|
132407
132927
|
for (const file of files) {
|
|
132408
132928
|
try {
|
|
132409
|
-
const content = await
|
|
132929
|
+
const content = await readFile21(`${root}/${file}`, "utf-8");
|
|
132410
132930
|
if (CONFLICT_MARKER_PATTERN.test(content)) {
|
|
132411
132931
|
conflicts.push(file);
|
|
132412
132932
|
}
|
|
@@ -132416,7 +132936,7 @@ async function findConflictMarkerFiles(root, files) {
|
|
|
132416
132936
|
}
|
|
132417
132937
|
function isInside(parent, child) {
|
|
132418
132938
|
const rel = relative18(parent, child);
|
|
132419
|
-
return rel === "" || rel !== ".." && !rel.startsWith(`..${sep17}`) && !
|
|
132939
|
+
return rel === "" || rel !== ".." && !rel.startsWith(`..${sep17}`) && !isAbsolute20(rel);
|
|
132420
132940
|
}
|
|
132421
132941
|
function untrustedGitError(detail) {
|
|
132422
132942
|
return {
|
|
@@ -132426,14 +132946,14 @@ function untrustedGitError(detail) {
|
|
|
132426
132946
|
};
|
|
132427
132947
|
}
|
|
132428
132948
|
async function validateTrustedWorktree(cwd, repoRoot) {
|
|
132429
|
-
const dotGit =
|
|
132430
|
-
const entry = await
|
|
132949
|
+
const dotGit = join58(cwd, ".git");
|
|
132950
|
+
const entry = await lstat27(dotGit).catch(() => null);
|
|
132431
132951
|
if (!entry)
|
|
132432
132952
|
return untrustedGitError(`missing ${dotGit}`);
|
|
132433
132953
|
if (entry.isSymbolicLink())
|
|
132434
132954
|
return untrustedGitError(`${dotGit} is a symlink`);
|
|
132435
132955
|
if (entry.isFile()) {
|
|
132436
|
-
const contents = await
|
|
132956
|
+
const contents = await readFile21(dotGit, "utf8");
|
|
132437
132957
|
const match = /^gitdir:\s*(.+)$/m.exec(contents);
|
|
132438
132958
|
if (!match?.[1])
|
|
132439
132959
|
return untrustedGitError(`${dotGit} has no gitdir pointer`);
|
|
@@ -132442,14 +132962,14 @@ async function validateTrustedWorktree(cwd, repoRoot) {
|
|
|
132442
132962
|
return untrustedGitError(`${dotGit} does not point into a worktrees directory`);
|
|
132443
132963
|
if (isInside(cwd, gitDir))
|
|
132444
132964
|
return untrustedGitError(`${dotGit} points inside the agent-writable workspace`);
|
|
132445
|
-
const gitDirStat = await
|
|
132965
|
+
const gitDirStat = await lstat27(gitDir).catch(() => null);
|
|
132446
132966
|
if (!gitDirStat?.isDirectory())
|
|
132447
132967
|
return untrustedGitError(`${dotGit} points at a missing directory`);
|
|
132448
132968
|
if (repoRoot) {
|
|
132449
132969
|
const commonDir = resolve36(gitDir, "..", "..");
|
|
132450
132970
|
const [actualCommon, expectedCommon] = await Promise.all([
|
|
132451
132971
|
realpath35(commonDir).catch(() => null),
|
|
132452
|
-
realpath35(
|
|
132972
|
+
realpath35(join58(repoRoot, ".git")).catch(() => null)
|
|
132453
132973
|
]);
|
|
132454
132974
|
if (!expectedCommon || actualCommon !== expectedCommon) {
|
|
132455
132975
|
return untrustedGitError(`${dotGit} points outside the configured repository`);
|
|
@@ -132899,18 +133419,18 @@ function createMissionContainerPorts(dependencies = {}) {
|
|
|
132899
133419
|
}
|
|
132900
133420
|
|
|
132901
133421
|
// src/chief-missions.ts
|
|
132902
|
-
import { join as
|
|
133422
|
+
import { join as join61 } from "node:path";
|
|
132903
133423
|
|
|
132904
133424
|
// src/chief-reconcile.ts
|
|
132905
133425
|
init_execution();
|
|
132906
|
-
import { join as
|
|
133426
|
+
import { join as join59 } from "node:path";
|
|
132907
133427
|
async function reconcileMissionExecution(missionId, options, root = process.cwd()) {
|
|
132908
133428
|
assertNotManagedRun();
|
|
132909
133429
|
const runId = options.run?.trim();
|
|
132910
133430
|
const evidence = options.evidence?.trim();
|
|
132911
133431
|
if (!runId || runId.length > 2000 || !evidence || evidence.length > 2000)
|
|
132912
133432
|
throw new Error("Set --run to the uncertain execution ID and --evidence to 1–2,000 characters describing how you confirmed it stopped.");
|
|
132913
|
-
const store = new MissionStore(
|
|
133433
|
+
const store = new MissionStore(join59(root, ".agent-valley", "missions"));
|
|
132914
133434
|
const unlock = await store.lock(missionId);
|
|
132915
133435
|
try {
|
|
132916
133436
|
const mission = await store.load(missionId);
|
|
@@ -132939,7 +133459,7 @@ function registerMissionReconciliation(missions, root = process.cwd()) {
|
|
|
132939
133459
|
}
|
|
132940
133460
|
|
|
132941
133461
|
// src/chief-watch.ts
|
|
132942
|
-
import { join as
|
|
133462
|
+
import { join as join60 } from "node:path";
|
|
132943
133463
|
async function watchOrders(root = process.cwd(), dependencies = {}) {
|
|
132944
133464
|
assertNotManagedRun();
|
|
132945
133465
|
const controller = new AbortController;
|
|
@@ -132952,7 +133472,7 @@ async function watchOrders(root = process.cwd(), dependencies = {}) {
|
|
|
132952
133472
|
process.once("SIGINT", stop);
|
|
132953
133473
|
process.once("SIGTERM", terminate);
|
|
132954
133474
|
}
|
|
132955
|
-
const missions = new MissionStore(
|
|
133475
|
+
const missions = new MissionStore(join60(root, ".agent-valley", "missions"));
|
|
132956
133476
|
try {
|
|
132957
133477
|
while (!controller.signal.aborted) {
|
|
132958
133478
|
const operations = await operationStore(root).list();
|
|
@@ -133040,7 +133560,7 @@ function registerMissionCommands(program) {
|
|
|
133040
133560
|
await watchOrders(process.cwd(), { service: options.service });
|
|
133041
133561
|
return;
|
|
133042
133562
|
}
|
|
133043
|
-
const missions = await new MissionStore(
|
|
133563
|
+
const missions = await new MissionStore(join61(process.cwd(), ".agent-valley/missions")).list();
|
|
133044
133564
|
if (options.json) {
|
|
133045
133565
|
console.log(JSON.stringify(missions.map((mission) => ({
|
|
133046
133566
|
id: mission.id,
|
|
@@ -133068,11 +133588,11 @@ function registerMissionCommands(program) {
|
|
|
133068
133588
|
}
|
|
133069
133589
|
|
|
133070
133590
|
// src/chief-parent-resume.ts
|
|
133071
|
-
import { join as
|
|
133591
|
+
import { join as join62 } from "node:path";
|
|
133072
133592
|
async function resumeParentForChild(root, child, resume) {
|
|
133073
133593
|
if (child.status !== "completed" || !verifiedMissionEvidence(child))
|
|
133074
133594
|
return child;
|
|
133075
|
-
const directory =
|
|
133595
|
+
const directory = join62(root, ".agent-valley", "operations");
|
|
133076
133596
|
const owners = (await new ContinuousOperationStore(directory).list()).filter((operation) => operation.currentMissionId === child.id);
|
|
133077
133597
|
if (owners.length > 1)
|
|
133078
133598
|
throw new Error("Multiple orders claim this child. Restore a single owning operation before resuming its accepted result.");
|
|
@@ -133096,8 +133616,8 @@ async function resumeParentForChild(root, child, resume) {
|
|
|
133096
133616
|
}
|
|
133097
133617
|
|
|
133098
133618
|
// src/chief-workspace-dependencies.ts
|
|
133099
|
-
import { lstat as
|
|
133100
|
-
import { join as
|
|
133619
|
+
import { lstat as lstat28, mkdir as mkdir27, readdir as readdir18, readFile as readFile22, realpath as realpath36, stat as stat7, symlink } from "node:fs/promises";
|
|
133620
|
+
import { join as join63, relative as relative19, resolve as resolve37, sep as sep18 } from "node:path";
|
|
133101
133621
|
var caches = new Set([".cache", ".vite", ".vite-temp"]);
|
|
133102
133622
|
var inside3 = (root, path) => path === root || path.startsWith(`${root}${sep18}`);
|
|
133103
133623
|
async function prepareMissionDependencies(repository, workspace) {
|
|
@@ -133105,8 +133625,8 @@ async function prepareMissionDependencies(repository, workspace) {
|
|
|
133105
133625
|
const target = await realpath36(workspace);
|
|
133106
133626
|
if (source === target)
|
|
133107
133627
|
throw new Error("Dependency preparation requires a separate mission workspace.");
|
|
133108
|
-
const packagePath =
|
|
133109
|
-
const metadata = await
|
|
133628
|
+
const packagePath = join63(source, "package.json");
|
|
133629
|
+
const metadata = await readFile22(packagePath, "utf8").catch((error) => {
|
|
133110
133630
|
if (error.code === "ENOENT")
|
|
133111
133631
|
return null;
|
|
133112
133632
|
throw error;
|
|
@@ -133135,12 +133655,12 @@ async function prepareMissionDependencies(repository, workspace) {
|
|
|
133135
133655
|
}
|
|
133136
133656
|
const [segment, ...rest] = segments;
|
|
133137
133657
|
if (segment === "*") {
|
|
133138
|
-
for (const entry of await
|
|
133658
|
+
for (const entry of await readdir18(directory, { withFileTypes: true }).catch(() => [])) {
|
|
133139
133659
|
if (entry.isDirectory() && !entry.name.startsWith(".") && entry.name !== "node_modules")
|
|
133140
|
-
await expand(
|
|
133660
|
+
await expand(join63(directory, entry.name), rest);
|
|
133141
133661
|
}
|
|
133142
133662
|
} else if (segment)
|
|
133143
|
-
await expand(
|
|
133663
|
+
await expand(join63(directory, segment), rest);
|
|
133144
133664
|
}
|
|
133145
133665
|
for (const pattern of patterns) {
|
|
133146
133666
|
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)
|
|
@@ -133163,7 +133683,7 @@ async function prepareMissionDependencies(repository, workspace) {
|
|
|
133163
133683
|
throw new Error("A workspace dependency is missing or escapes the mission workspace. Restore that package.");
|
|
133164
133684
|
installed = destination;
|
|
133165
133685
|
}
|
|
133166
|
-
const existing = await
|
|
133686
|
+
const existing = await lstat28(to).catch((error) => {
|
|
133167
133687
|
if (error.code === "ENOENT")
|
|
133168
133688
|
return;
|
|
133169
133689
|
throw error;
|
|
@@ -133173,11 +133693,11 @@ async function prepareMissionDependencies(repository, workspace) {
|
|
|
133173
133693
|
throw new Error("An existing mission dependency differs from the installed package. Preserve it and repair setup.");
|
|
133174
133694
|
return;
|
|
133175
133695
|
}
|
|
133176
|
-
await symlink(installed, to, (await
|
|
133696
|
+
await symlink(installed, to, (await stat7(installed)).isDirectory() ? "dir" : "file");
|
|
133177
133697
|
}
|
|
133178
133698
|
for (const root of roots) {
|
|
133179
|
-
const modules =
|
|
133180
|
-
const installed = await
|
|
133699
|
+
const modules = join63(root, "node_modules");
|
|
133700
|
+
const installed = await stat7(modules).catch(() => {
|
|
133181
133701
|
return;
|
|
133182
133702
|
});
|
|
133183
133703
|
if (!installed?.isDirectory())
|
|
@@ -133185,27 +133705,27 @@ async function prepareMissionDependencies(repository, workspace) {
|
|
|
133185
133705
|
const destinationRoot = await realpath36(resolve37(target, relative19(source, root)));
|
|
133186
133706
|
if (!inside3(target, destinationRoot))
|
|
133187
133707
|
throw new Error("A mission package directory escapes its workspace.");
|
|
133188
|
-
const destination =
|
|
133189
|
-
const existing = await
|
|
133708
|
+
const destination = join63(destinationRoot, "node_modules");
|
|
133709
|
+
const existing = await lstat28(destination).catch(() => {
|
|
133190
133710
|
return;
|
|
133191
133711
|
});
|
|
133192
133712
|
if (existing && !existing.isDirectory())
|
|
133193
133713
|
throw new Error("Mission node_modules must be a local directory.");
|
|
133194
133714
|
await mkdir27(destination, { recursive: true });
|
|
133195
|
-
for (const entry of await
|
|
133715
|
+
for (const entry of await readdir18(modules, { withFileTypes: true })) {
|
|
133196
133716
|
if (caches.has(entry.name))
|
|
133197
133717
|
continue;
|
|
133198
|
-
const from =
|
|
133199
|
-
const to =
|
|
133718
|
+
const from = join63(modules, entry.name);
|
|
133719
|
+
const to = join63(destination, entry.name);
|
|
133200
133720
|
if (entry.name.startsWith("@") && entry.isDirectory()) {
|
|
133201
|
-
const scope = await
|
|
133721
|
+
const scope = await lstat28(to).catch(() => {
|
|
133202
133722
|
return;
|
|
133203
133723
|
});
|
|
133204
133724
|
if (scope && !scope.isDirectory())
|
|
133205
133725
|
throw new Error("A dependency scope must be a local directory.");
|
|
133206
133726
|
await mkdir27(to, { recursive: true });
|
|
133207
|
-
for (const member of await
|
|
133208
|
-
await link(
|
|
133727
|
+
for (const member of await readdir18(from))
|
|
133728
|
+
await link(join63(from, member), join63(to, member));
|
|
133209
133729
|
} else
|
|
133210
133730
|
await link(from, to);
|
|
133211
133731
|
}
|
|
@@ -133228,7 +133748,7 @@ async function runOrder(goal, options, root = process.cwd()) {
|
|
|
133228
133748
|
if (!options.resume && [options.retry, options.resolveEffect, options.effectResult, options.accountRun, options.accountCost].some((value) => value !== undefined && value !== false))
|
|
133229
133749
|
throw new Error("Use --resume <id> for retry, external-effect resolution or cost reconciliation.");
|
|
133230
133750
|
await ensureRuntimeGitignore(root);
|
|
133231
|
-
const store = new MissionStore(
|
|
133751
|
+
const store = new MissionStore(join64(root, ".agent-valley/missions"));
|
|
133232
133752
|
const id = options.resume ?? options.missionId ?? randomUUID24();
|
|
133233
133753
|
const unlock = await store.lock(id);
|
|
133234
133754
|
const abortController = new AbortController;
|
|
@@ -133277,7 +133797,7 @@ async function runOrder(goal, options, root = process.cwd()) {
|
|
|
133277
133797
|
throw new Error("Internal child launch does not match its saved operation, goal and accepted baseline. Restore the original operation checkpoint.");
|
|
133278
133798
|
if (Boolean(options.baselineWorkspace) !== Boolean(options.operationId))
|
|
133279
133799
|
throw new Error("An internal operation snapshot requires both its operation identity and accepted baseline.");
|
|
133280
|
-
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 ?
|
|
133800
|
+
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 ? join64(config.workspace, ".agent-valley", "workspaces") : undefined);
|
|
133281
133801
|
if (options.operationId)
|
|
133282
133802
|
await restoreOperationOrigin(config.workspace, workspace.path);
|
|
133283
133803
|
if (!codeDelivery)
|
|
@@ -133308,6 +133828,13 @@ async function runOrder(goal, options, root = process.cwd()) {
|
|
|
133308
133828
|
containerObservationPolicy: operation ? operation.containerObservationPolicy : config.containerObservationPolicy,
|
|
133309
133829
|
containerObservation: operation?.containerObservation,
|
|
133310
133830
|
toolEnvKeys: config.toolEnvKeys,
|
|
133831
|
+
...operation?.actorHealth?.length ? {
|
|
133832
|
+
operations: {
|
|
133833
|
+
runs: [],
|
|
133834
|
+
routingEvidence: seedProviderHealthEvidence([], operation.actorHealth),
|
|
133835
|
+
reviewDecisions: []
|
|
133836
|
+
}
|
|
133837
|
+
} : {},
|
|
133311
133838
|
capturePolicy: config.capturePolicy,
|
|
133312
133839
|
status: "pending",
|
|
133313
133840
|
tasks: [],
|
|
@@ -133352,6 +133879,8 @@ Resume: bun av order --resume ${id}`);
|
|
|
133352
133879
|
}
|
|
133353
133880
|
if (mission.operatingPolicy?.memory || mission.operatingPolicy?.metricTargets?.length) {
|
|
133354
133881
|
mission.organizationContext = await organizationContext2(repository, mission);
|
|
133882
|
+
if (!options.resume && mission.operations)
|
|
133883
|
+
mission.operations.routingEvidence = seedProviderHealthEvidence(mission.organizationContext.routeEvidence, aggregateProviderHealth(mission));
|
|
133355
133884
|
mission.operations ??= {
|
|
133356
133885
|
runs: [],
|
|
133357
133886
|
routingEvidence: mission.organizationContext.routeEvidence,
|
|
@@ -133442,7 +133971,7 @@ async function dispatchOrder(goal, options, root = process.cwd(), dependencies =
|
|
|
133442
133971
|
};
|
|
133443
133972
|
const [operation, mission] = await Promise.all([
|
|
133444
133973
|
operationStore(root).load(options.resume).catch(missing),
|
|
133445
|
-
new MissionStore(
|
|
133974
|
+
new MissionStore(join64(root, ".agent-valley", "missions")).load(options.resume).catch(missing)
|
|
133446
133975
|
]);
|
|
133447
133976
|
if (operation && mission)
|
|
133448
133977
|
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.`);
|
|
@@ -133498,22 +134027,22 @@ function registerChiefCommands(program) {
|
|
|
133498
134027
|
}
|
|
133499
134028
|
|
|
133500
134029
|
// src/chief-organization.ts
|
|
133501
|
-
import { readFile as
|
|
133502
|
-
import { isAbsolute as
|
|
134030
|
+
import { readFile as readFile23, stat as stat8 } from "node:fs/promises";
|
|
134031
|
+
import { isAbsolute as isAbsolute21, join as join65, resolve as resolve38 } from "node:path";
|
|
133503
134032
|
init_chief_schema();
|
|
133504
134033
|
init_yaml_loader();
|
|
133505
134034
|
function organizationRepository(root, workspace) {
|
|
133506
134035
|
const repository = workspace ?? loadProjectConfig(root)?.workspace?.root ?? root;
|
|
133507
|
-
if (!
|
|
134036
|
+
if (!isAbsolute21(repository))
|
|
133508
134037
|
throw new Error("Set workspace.root in av.yaml or --workspace to an absolute source repository path.");
|
|
133509
134038
|
return repository;
|
|
133510
134039
|
}
|
|
133511
134040
|
async function inputFile(file) {
|
|
133512
134041
|
const path = resolve38(file);
|
|
133513
|
-
const info = await
|
|
134042
|
+
const info = await stat8(path);
|
|
133514
134043
|
if (!info.isFile() || info.size > 2000000)
|
|
133515
134044
|
throw new Error("Use a regular JSON input file no larger than 2 MB.");
|
|
133516
|
-
return
|
|
134045
|
+
return readFile23(path, "utf8");
|
|
133517
134046
|
}
|
|
133518
134047
|
function registerOrganizationCommands(program) {
|
|
133519
134048
|
const memory = program.command("memory").description("Repository organization decisions and standards");
|
|
@@ -133553,13 +134082,13 @@ function registerOrganizationCommands(program) {
|
|
|
133553
134082
|
});
|
|
133554
134083
|
const reports = program.command("reports").description("Inspect and retry third-party report attachments");
|
|
133555
134084
|
reports.command("list").option("--workspace <path>", "Source repository").action(async (opts) => {
|
|
133556
|
-
console.log(JSON.stringify(await listReportDeliveries(
|
|
134085
|
+
console.log(JSON.stringify(await listReportDeliveries(join65(organizationRepository(process.cwd(), opts.workspace), ".agent-valley")), null, 2));
|
|
133557
134086
|
});
|
|
133558
134087
|
reports.command("retry").option("--workspace <path>", "Source repository").action(async (opts) => {
|
|
133559
134088
|
const config = mergeChiefConfig(loadGlobalConfig()?.chief, loadProjectConfig()?.chief);
|
|
133560
134089
|
if (!config.reporting)
|
|
133561
134090
|
throw new Error("Set chief.reporting.destinations in av.yaml before retrying reports.");
|
|
133562
|
-
console.log(JSON.stringify(await retryPendingReports(config.reporting,
|
|
134091
|
+
console.log(JSON.stringify(await retryPendingReports(config.reporting, join65(organizationRepository(process.cwd(), opts.workspace), ".agent-valley")), null, 2));
|
|
133563
134092
|
});
|
|
133564
134093
|
}
|
|
133565
134094
|
|
|
@@ -133584,10 +134113,10 @@ var import_picocolors = __toESM(require_picocolors(), 1);
|
|
|
133584
134113
|
init_project_config_path();
|
|
133585
134114
|
init_yaml_loader();
|
|
133586
134115
|
init_doctor_checks();
|
|
133587
|
-
import { join as
|
|
134116
|
+
import { join as join69 } from "node:path";
|
|
133588
134117
|
|
|
133589
134118
|
// src/doctor-oma-checks.ts
|
|
133590
|
-
import { join as
|
|
134119
|
+
import { join as join68 } from "node:path";
|
|
133591
134120
|
function checkOma(project, deps) {
|
|
133592
134121
|
const strict = project?.oma?.mode === "strict";
|
|
133593
134122
|
const order = !!project && !project.tracker && !project.linear && !project.github;
|
|
@@ -133675,7 +134204,7 @@ function checkOma(project, deps) {
|
|
|
133675
134204
|
fix: "Set verify.command to a deterministic non-build check in av.yaml before using oma.mode: strict.",
|
|
133676
134205
|
critical: true
|
|
133677
134206
|
});
|
|
133678
|
-
const triggerPath =
|
|
134207
|
+
const triggerPath = join68(deps.cwd, ".agents", "hooks", "core", "triggers.json");
|
|
133679
134208
|
let table = null;
|
|
133680
134209
|
try {
|
|
133681
134210
|
table = parseTriggerTable(deps.readFileSync(triggerPath));
|
|
@@ -133692,7 +134221,7 @@ function checkOma(project, deps) {
|
|
|
133692
134221
|
return results;
|
|
133693
134222
|
}
|
|
133694
134223
|
results.push({ id: "oma.triggers", name: "OMA trigger table", status: "pass", message: triggerPath, critical: false });
|
|
133695
|
-
const missing = Object.entries(table.workflows).filter(([name, workflow]) => !workflow.persistent && !table.excludedWorkflows.includes(name)).map(([name]) =>
|
|
134224
|
+
const missing = Object.entries(table.workflows).filter(([name, workflow]) => !workflow.persistent && !table.excludedWorkflows.includes(name)).map(([name]) => join68(deps.cwd, ".agents", "workflows", `${name}.md`)).filter((path) => !deps.existsSync(path));
|
|
133696
134225
|
results.push(missing.length === 0 ? {
|
|
133697
134226
|
id: "oma.workflows",
|
|
133698
134227
|
name: "OMA workflow files",
|
|
@@ -133767,7 +134296,7 @@ function checkTunnel(project, deps) {
|
|
|
133767
134296
|
}
|
|
133768
134297
|
const mode = project?.tunnel?.cloudflare?.mode ?? "quick";
|
|
133769
134298
|
if (mode === "named") {
|
|
133770
|
-
const certPath =
|
|
134299
|
+
const certPath = join69(deps.home, ".cloudflared", "cert.pem");
|
|
133771
134300
|
if (!deps.existsSync(certPath)) {
|
|
133772
134301
|
return {
|
|
133773
134302
|
id: "tunnel",
|
|
@@ -133807,7 +134336,7 @@ function checkTunnel(project, deps) {
|
|
|
133807
134336
|
critical: false
|
|
133808
134337
|
};
|
|
133809
134338
|
}
|
|
133810
|
-
const ngrokConfigPath = deps.platform === "darwin" ?
|
|
134339
|
+
const ngrokConfigPath = deps.platform === "darwin" ? join69(deps.home, "Library", "Application Support", "ngrok", "ngrok.yml") : join69(deps.home, ".config", "ngrok", "ngrok.yml");
|
|
133811
134340
|
if (!deps.existsSync(ngrokConfigPath)) {
|
|
133812
134341
|
return {
|
|
133813
134342
|
id: "tunnel",
|
|
@@ -133878,7 +134407,7 @@ function checkConfig(deps) {
|
|
|
133878
134407
|
critical: true
|
|
133879
134408
|
});
|
|
133880
134409
|
}
|
|
133881
|
-
const projectPath =
|
|
134410
|
+
const projectPath = join69(deps.cwd, PROJECT_CONFIG_FILENAME);
|
|
133882
134411
|
try {
|
|
133883
134412
|
project = deps.loadProjectConfig(deps.cwd);
|
|
133884
134413
|
results.push(project ? {
|
|
@@ -138434,8 +138963,8 @@ init_team_relay_error();
|
|
|
138434
138963
|
|
|
138435
138964
|
// ../../packages/core/src/relay/turso-migration-assets.ts
|
|
138436
138965
|
init_zod();
|
|
138437
|
-
import { copyFile as copyFile3, lstat as
|
|
138438
|
-
import { dirname as dirname15, join as
|
|
138966
|
+
import { copyFile as copyFile3, lstat as lstat33, mkdir as mkdir28, readFile as readFile25 } from "node:fs/promises";
|
|
138967
|
+
import { dirname as dirname15, join as join75 } from "node:path";
|
|
138439
138968
|
import { fileURLToPath as fileURLToPath3 } from "node:url";
|
|
138440
138969
|
var TURSO_MIGRATION_ASSET_PATH = "assets/turso/migrations";
|
|
138441
138970
|
var journalSchema = object({
|
|
@@ -138456,7 +138985,7 @@ function tursoMigrationAssetCandidates(moduleUrl = import.meta.url) {
|
|
|
138456
138985
|
];
|
|
138457
138986
|
}
|
|
138458
138987
|
async function regularFile2(path) {
|
|
138459
|
-
const info = await
|
|
138988
|
+
const info = await lstat33(path);
|
|
138460
138989
|
if (!info.isFile() || info.isSymbolicLink())
|
|
138461
138990
|
throw new Error(`Turso migration asset ${path} must be a regular file. Restore the checkout or reinstall the CLI package.`);
|
|
138462
138991
|
}
|
|
@@ -138464,7 +138993,7 @@ async function loadTursoMigrationAssets(candidates = tursoMigrationAssetCandidat
|
|
|
138464
138993
|
for (const directory of candidates) {
|
|
138465
138994
|
let info;
|
|
138466
138995
|
try {
|
|
138467
|
-
info = await
|
|
138996
|
+
info = await lstat33(directory);
|
|
138468
138997
|
} catch (error) {
|
|
138469
138998
|
if (error.code === "ENOENT")
|
|
138470
138999
|
continue;
|
|
@@ -138473,19 +139002,19 @@ async function loadTursoMigrationAssets(candidates = tursoMigrationAssetCandidat
|
|
|
138473
139002
|
if (!info.isDirectory() || info.isSymbolicLink())
|
|
138474
139003
|
throw new Error(`Turso migration directory ${directory} must be a regular directory. Restore the checkout or reinstall the CLI package.`);
|
|
138475
139004
|
try {
|
|
138476
|
-
const meta = await
|
|
139005
|
+
const meta = await lstat33(join75(directory, "meta"));
|
|
138477
139006
|
if (!meta.isDirectory() || meta.isSymbolicLink())
|
|
138478
139007
|
throw new Error("Invalid migration metadata directory");
|
|
138479
|
-
const journalPath =
|
|
139008
|
+
const journalPath = join75(directory, "meta/_journal.json");
|
|
138480
139009
|
await regularFile2(journalPath);
|
|
138481
|
-
const journal = journalSchema.parse(JSON.parse(await
|
|
139010
|
+
const journal = journalSchema.parse(JSON.parse(await readFile25(journalPath, "utf8")));
|
|
138482
139011
|
const tags = journal.entries.map((entry) => entry.tag);
|
|
138483
139012
|
if (new Set(tags).size !== tags.length)
|
|
138484
139013
|
throw new Error("Duplicate migration tags");
|
|
138485
139014
|
const files = ["meta/_journal.json", ...tags.map((tag) => `${tag}.sql`)];
|
|
138486
139015
|
for (const file of files.slice(1)) {
|
|
138487
|
-
await regularFile2(
|
|
138488
|
-
if (!(await
|
|
139016
|
+
await regularFile2(join75(directory, file));
|
|
139017
|
+
if (!(await readFile25(join75(directory, file), "utf8")).trim())
|
|
138489
139018
|
throw new Error("Empty migration SQL");
|
|
138490
139019
|
}
|
|
138491
139020
|
return { directory, files };
|