agent-valley 4.8.4 → 4.8.6
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 +1154 -660
- 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,
|
|
@@ -16339,11 +16352,12 @@ function buildDarwinSandboxCommand(req, sandboxExecPath = "/usr/bin/sandbox-exec
|
|
|
16339
16352
|
};
|
|
16340
16353
|
}
|
|
16341
16354
|
function buildSeatbeltProfile(req, home) {
|
|
16355
|
+
const workspacePaths = pathAliases(req.workspacePath);
|
|
16342
16356
|
const tmpPaths = pathAliases(tmpdir());
|
|
16343
16357
|
const git = linkedWorktreeGitPaths(req.workspacePath);
|
|
16344
16358
|
const agentPaths = agentHomeAccess(req.agentType, home, req.env);
|
|
16345
16359
|
const writablePaths = [
|
|
16346
|
-
|
|
16360
|
+
...workspacePaths,
|
|
16347
16361
|
...tmpPaths,
|
|
16348
16362
|
...agentPaths.active,
|
|
16349
16363
|
`${home}/.cache`,
|
|
@@ -16351,6 +16365,8 @@ function buildSeatbeltProfile(req, home) {
|
|
|
16351
16365
|
`${home}/.bun`
|
|
16352
16366
|
];
|
|
16353
16367
|
const writeRules = writablePaths.map((p) => `(allow file-write* (subpath ${seatbeltString(p)}))`).join(`
|
|
16368
|
+
`);
|
|
16369
|
+
const unixListenerRules = [...new Set([...workspacePaths, ...tmpPaths])].flatMap((path) => ["network-bind", "network-inbound"].map((operation) => `(allow ${operation} (local unix-socket (subpath ${seatbeltString(path)})))`)).join(`
|
|
16354
16370
|
`);
|
|
16355
16371
|
const gitWriteRules = git ? [git.gitDir, git.objectsDir].map((p) => `(allow file-write* (subpath ${seatbeltString(p)}))`).concat([
|
|
16356
16372
|
git.branchRef,
|
|
@@ -16417,6 +16433,9 @@ ${denyWriteRules}
|
|
|
16417
16433
|
; why per-domain scoping is not possible via sandbox-exec on this OS).
|
|
16418
16434
|
(deny network-outbound)
|
|
16419
16435
|
(allow network-outbound (remote unix-socket))
|
|
16436
|
+
; Local named Unix servers are needed by workspace IPC tests and resident tools.
|
|
16437
|
+
; This does not permit TCP listeners or Unix binds in caches/vendor homes.
|
|
16438
|
+
${unixListenerRules}
|
|
16420
16439
|
(allow mach-lookup (global-name "com.apple.mDNSResponder"))
|
|
16421
16440
|
(allow network-outbound (remote udp "*:53"))
|
|
16422
16441
|
(allow network-outbound (remote tcp "*:443"))
|
|
@@ -17593,10 +17612,47 @@ var init_claude_session = __esm(() => {
|
|
|
17593
17612
|
});
|
|
17594
17613
|
|
|
17595
17614
|
// ../../packages/core/src/sessions/qwen-session.ts
|
|
17596
|
-
var QwenSession;
|
|
17615
|
+
var computerUseTools, QwenSession;
|
|
17597
17616
|
var init_qwen_session = __esm(() => {
|
|
17598
17617
|
init_claude_session();
|
|
17599
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}`);
|
|
17600
17656
|
QwenSession = class QwenSession extends ClaudeSession {
|
|
17601
17657
|
vendor = "qwen";
|
|
17602
17658
|
actualModel;
|
|
@@ -17604,6 +17660,9 @@ var init_qwen_session = __esm(() => {
|
|
|
17604
17660
|
resultEvent;
|
|
17605
17661
|
buildArgs() {
|
|
17606
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(","));
|
|
17607
17666
|
if (this.config?.model)
|
|
17608
17667
|
args.push("--model", this.config.model);
|
|
17609
17668
|
return args;
|
|
@@ -21274,12 +21333,12 @@ var require_cross_spawn = __commonJS(function(exports, module) {
|
|
|
21274
21333
|
// src/doctor-checks.ts
|
|
21275
21334
|
import { spawnSync } from "node:child_process";
|
|
21276
21335
|
import { existsSync as existsSync3, readFileSync as readFileSync6 } from "node:fs";
|
|
21277
|
-
import { homedir as
|
|
21278
|
-
import { join as
|
|
21336
|
+
import { homedir as homedir6 } from "node:os";
|
|
21337
|
+
import { join as join24 } from "node:path";
|
|
21279
21338
|
function defaultDoctorDeps() {
|
|
21280
21339
|
return {
|
|
21281
21340
|
cwd: process.cwd(),
|
|
21282
|
-
home:
|
|
21341
|
+
home: homedir6(),
|
|
21283
21342
|
platform: process.platform,
|
|
21284
21343
|
env: process.env,
|
|
21285
21344
|
existsSync: existsSync3,
|
|
@@ -21302,19 +21361,19 @@ function probeAgentAuth(agent, deps) {
|
|
|
21302
21361
|
case "qwen":
|
|
21303
21362
|
return { status: "unknown", message: "Qwen needs a selected API provider/model; configure qwen /auth" };
|
|
21304
21363
|
case "claude": {
|
|
21305
|
-
const p =
|
|
21364
|
+
const p = join24(home, ".claude");
|
|
21306
21365
|
return exists(p) ? { status: "pass", message: `${p} present` } : { status: "fail", message: `${p} not found` };
|
|
21307
21366
|
}
|
|
21308
21367
|
case "codex": {
|
|
21309
|
-
const p =
|
|
21368
|
+
const p = join24(home, ".codex");
|
|
21310
21369
|
return exists(p) ? { status: "pass", message: `${p} present` } : { status: "fail", message: `${p} not found` };
|
|
21311
21370
|
}
|
|
21312
21371
|
case "grok": {
|
|
21313
|
-
const p =
|
|
21372
|
+
const p = join24(home, ".grok", "config.toml");
|
|
21314
21373
|
return exists(p) ? { status: "pass", message: `${p} present` } : { status: "fail", message: `${p} not found` };
|
|
21315
21374
|
}
|
|
21316
21375
|
case "kimi": {
|
|
21317
|
-
const p =
|
|
21376
|
+
const p = join24(home, ".kimi-code", "config.toml");
|
|
21318
21377
|
if (!exists(p))
|
|
21319
21378
|
return { status: "fail", message: `${p} not found` };
|
|
21320
21379
|
try {
|
|
@@ -21325,7 +21384,7 @@ function probeAgentAuth(agent, deps) {
|
|
|
21325
21384
|
}
|
|
21326
21385
|
}
|
|
21327
21386
|
case "opencode": {
|
|
21328
|
-
const p =
|
|
21387
|
+
const p = join24(home, ".local", "share", "opencode", "auth.json");
|
|
21329
21388
|
return exists(p) ? { status: "pass", message: `${p} present` } : { status: "fail", message: `${p} not found` };
|
|
21330
21389
|
}
|
|
21331
21390
|
case "antigravity":
|
|
@@ -21431,7 +21490,7 @@ var init_doctor_checks = __esm(() => {
|
|
|
21431
21490
|
});
|
|
21432
21491
|
|
|
21433
21492
|
// src/qwen-discovery.ts
|
|
21434
|
-
import { join as
|
|
21493
|
+
import { join as join25 } from "node:path";
|
|
21435
21494
|
function record2(value) {
|
|
21436
21495
|
return value && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
21437
21496
|
}
|
|
@@ -21448,7 +21507,7 @@ function qwenAuth(deps, read) {
|
|
|
21448
21507
|
const home = qwenProfilePath(deps.home, deps.env);
|
|
21449
21508
|
if (!home)
|
|
21450
21509
|
return problem("Use an absolute QWEN_HOME so discovery and mission worktrees share the same profile");
|
|
21451
|
-
const settings = record2(read(
|
|
21510
|
+
const settings = record2(read(join25(home, "settings.json")));
|
|
21452
21511
|
const localEnv = record2(settings.env);
|
|
21453
21512
|
const allowed = new Set(getAgentAuthEnvKeys("qwen"));
|
|
21454
21513
|
const env = (key) => deps.env[key] ?? localEnv[key];
|
|
@@ -21494,9 +21553,9 @@ var init_qwen_discovery = __esm(() => {
|
|
|
21494
21553
|
|
|
21495
21554
|
// src/agent-discovery.ts
|
|
21496
21555
|
import { spawn as spawn8 } from "node:child_process";
|
|
21497
|
-
import { accessSync, constants as
|
|
21498
|
-
import { homedir as
|
|
21499
|
-
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";
|
|
21500
21559
|
import { stripVTControlCharacters as stripVTControlCharacters3 } from "node:util";
|
|
21501
21560
|
function record3(value) {
|
|
21502
21561
|
return value !== null && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
@@ -21587,13 +21646,13 @@ function probeNativeCli(path, args, options) {
|
|
|
21587
21646
|
}
|
|
21588
21647
|
function defaultDeps() {
|
|
21589
21648
|
return {
|
|
21590
|
-
home:
|
|
21649
|
+
home: homedir7(),
|
|
21591
21650
|
env: process.env,
|
|
21592
21651
|
now: Date.now,
|
|
21593
21652
|
resolveBinary: resolveBinaryPath,
|
|
21594
21653
|
isExecutableFile: (path) => {
|
|
21595
21654
|
try {
|
|
21596
|
-
accessSync(path,
|
|
21655
|
+
accessSync(path, constants11.X_OK);
|
|
21597
21656
|
return statSync3(path).isFile();
|
|
21598
21657
|
} catch {
|
|
21599
21658
|
return false;
|
|
@@ -21650,8 +21709,8 @@ function expired(token, expiresAt, now, unit = 1) {
|
|
|
21650
21709
|
return false;
|
|
21651
21710
|
}
|
|
21652
21711
|
function kimiAuth(deps) {
|
|
21653
|
-
const home = nonempty(deps.env.KIMI_CODE_HOME) ? deps.env.KIMI_CODE_HOME :
|
|
21654
|
-
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));
|
|
21655
21714
|
const model = record3(record3(config.models)[String(config.default_model ?? "")]);
|
|
21656
21715
|
const provider = record3(record3(config.providers)[String(model.provider ?? "")]);
|
|
21657
21716
|
if (nonempty(model.model) && nonempty(provider.type) && nonempty(provider.base_url)) {
|
|
@@ -21665,7 +21724,7 @@ function kimiAuth(deps) {
|
|
|
21665
21724
|
if (nonempty(oauth.key) && (oauth.storage === "file" || oauth.storage === "keyring")) {
|
|
21666
21725
|
const name = oauth.key.split("/").at(-1);
|
|
21667
21726
|
if (name && /^[\w-]+$/.test(name)) {
|
|
21668
|
-
const token = record3(readState(
|
|
21727
|
+
const token = record3(readState(join26(home, "credentials", `${name}.json`), deps));
|
|
21669
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)) {
|
|
21670
21729
|
return { readiness: "ready", reason: "Kimi native OAuth credentials found" };
|
|
21671
21730
|
}
|
|
@@ -21683,15 +21742,15 @@ function localAuth(agent, deps) {
|
|
|
21683
21742
|
if (agent === "kimi")
|
|
21684
21743
|
return kimiAuth(deps);
|
|
21685
21744
|
if (agent === "antigravity") {
|
|
21686
|
-
const settings = record3(readState(
|
|
21745
|
+
const settings = record3(readState(join26(deps.home, ".gemini", "antigravity-cli", "settings.json"), deps));
|
|
21687
21746
|
if (settings.modelProvider === "gemini") {
|
|
21688
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");
|
|
21689
21748
|
}
|
|
21690
21749
|
return null;
|
|
21691
21750
|
}
|
|
21692
21751
|
if (agent === "codex") {
|
|
21693
|
-
const home = nonempty(deps.env.CODEX_HOME) ? deps.env.CODEX_HOME :
|
|
21694
|
-
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);
|
|
21695
21754
|
if (value === null)
|
|
21696
21755
|
return null;
|
|
21697
21756
|
const auth = record3(value);
|
|
@@ -21707,8 +21766,8 @@ function localAuth(agent, deps) {
|
|
|
21707
21766
|
return missing(agent, "Codex authentication file has no complete credentials");
|
|
21708
21767
|
}
|
|
21709
21768
|
if (agent === "claude") {
|
|
21710
|
-
const home = nonempty(deps.env.CLAUDE_CONFIG_DIR) ? deps.env.CLAUDE_CONFIG_DIR :
|
|
21711
|
-
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);
|
|
21712
21771
|
if (value === null)
|
|
21713
21772
|
return null;
|
|
21714
21773
|
const oauth = record3(record3(value).claudeAiOauth);
|
|
@@ -21718,8 +21777,8 @@ function localAuth(agent, deps) {
|
|
|
21718
21777
|
return missing(agent, "Claude authentication file has no complete credentials");
|
|
21719
21778
|
}
|
|
21720
21779
|
if (agent === "opencode") {
|
|
21721
|
-
const home = nonempty(deps.env.XDG_DATA_HOME) ? deps.env.XDG_DATA_HOME :
|
|
21722
|
-
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));
|
|
21723
21782
|
for (const value of Object.values(auth)) {
|
|
21724
21783
|
const credential = record3(value);
|
|
21725
21784
|
if (credential.type === "api" && nonempty(credential.key)) {
|
|
@@ -22387,7 +22446,7 @@ var require_dist3 = __commonJS(function(exports) {
|
|
|
22387
22446
|
});
|
|
22388
22447
|
|
|
22389
22448
|
// ../../node_modules/.bun/readdirp@5.1.1/node_modules/readdirp/index.js
|
|
22390
|
-
import { lstat as
|
|
22449
|
+
import { lstat as lstat29, readdir as readdir19, realpath as realpath38, stat as stat9 } from "node:fs/promises";
|
|
22391
22450
|
import { join as pjoin, resolve as presolve, sep as psep } from "node:path";
|
|
22392
22451
|
import { Readable as Readable2 } from "node:stream";
|
|
22393
22452
|
function readdirp(root, options = {}) {
|
|
@@ -22484,7 +22543,7 @@ var init_readdirp = __esm(() => {
|
|
|
22484
22543
|
const type = opts.type ?? defaultOptions4.type;
|
|
22485
22544
|
this._fileFilter = normalizeFilter(opts.fileFilter);
|
|
22486
22545
|
this._directoryFilter = normalizeFilter(opts.directoryFilter);
|
|
22487
|
-
const statMethod = opts.lstat ?
|
|
22546
|
+
const statMethod = opts.lstat ? lstat29 : stat9;
|
|
22488
22547
|
if (wantBigintFsStats) {
|
|
22489
22548
|
this._stat = (path) => statMethod(path, { bigint: true });
|
|
22490
22549
|
} else {
|
|
@@ -22565,7 +22624,7 @@ var init_readdirp = __esm(() => {
|
|
|
22565
22624
|
async _exploreDir(path, depth) {
|
|
22566
22625
|
let files;
|
|
22567
22626
|
try {
|
|
22568
|
-
files = await
|
|
22627
|
+
files = await readdir19(path, this._rdOptions);
|
|
22569
22628
|
} catch (error) {
|
|
22570
22629
|
this._onError(error);
|
|
22571
22630
|
}
|
|
@@ -22611,7 +22670,7 @@ var init_readdirp = __esm(() => {
|
|
|
22611
22670
|
const full = entry.fullPath;
|
|
22612
22671
|
try {
|
|
22613
22672
|
const entryRealPath = await realpath38(full);
|
|
22614
|
-
const entryRealPathStats = await
|
|
22673
|
+
const entryRealPathStats = await lstat29(entryRealPath);
|
|
22615
22674
|
if (entryRealPathStats.isFile()) {
|
|
22616
22675
|
return "file";
|
|
22617
22676
|
}
|
|
@@ -22639,7 +22698,7 @@ var init_readdirp = __esm(() => {
|
|
|
22639
22698
|
|
|
22640
22699
|
// ../../node_modules/.bun/chokidar@5.0.0/node_modules/chokidar/handler.js
|
|
22641
22700
|
import { watch as fs_watch, unwatchFile, watchFile } from "node:fs";
|
|
22642
|
-
import { realpath as fsrealpath, lstat as
|
|
22701
|
+
import { realpath as fsrealpath, lstat as lstat30, open as open19, stat as stat10 } from "node:fs/promises";
|
|
22643
22702
|
import { type as osType } from "node:os";
|
|
22644
22703
|
import * as sp from "node:path";
|
|
22645
22704
|
function createFsWatchInstance(path, options, listener, errHandler, emitRaw) {
|
|
@@ -22711,7 +22770,7 @@ class NodeFsHandler {
|
|
|
22711
22770
|
return;
|
|
22712
22771
|
if (!newStats || newStats.mtimeMs === 0) {
|
|
22713
22772
|
try {
|
|
22714
|
-
const newStats = await
|
|
22773
|
+
const newStats = await stat10(file);
|
|
22715
22774
|
if (this.fsw.closed)
|
|
22716
22775
|
return;
|
|
22717
22776
|
const at = newStats.atimeMs;
|
|
@@ -23067,7 +23126,7 @@ var init_handler = __esm(() => {
|
|
|
23067
23126
|
ERROR: "error"
|
|
23068
23127
|
};
|
|
23069
23128
|
EV = EVENTS;
|
|
23070
|
-
statMethods = { lstat:
|
|
23129
|
+
statMethods = { lstat: lstat30, stat: stat10 };
|
|
23071
23130
|
HANDLER_KEYS = [KEY_LISTENERS, KEY_ERR, KEY_RAW];
|
|
23072
23131
|
binaryExtensions = new Set([
|
|
23073
23132
|
"3dm",
|
|
@@ -23339,7 +23398,7 @@ var init_handler = __esm(() => {
|
|
|
23339
23398
|
// ../../node_modules/.bun/chokidar@5.0.0/node_modules/chokidar/index.js
|
|
23340
23399
|
import { EventEmitter as EventEmitter2 } from "node:events";
|
|
23341
23400
|
import { stat as statcb, Stats } from "node:fs";
|
|
23342
|
-
import { readdir as
|
|
23401
|
+
import { readdir as readdir20, stat as stat11 } from "node:fs/promises";
|
|
23343
23402
|
import * as sp2 from "node:path";
|
|
23344
23403
|
function arrify(item) {
|
|
23345
23404
|
return Array.isArray(item) ? item : [item];
|
|
@@ -23429,7 +23488,7 @@ class DirEntry {
|
|
|
23429
23488
|
return;
|
|
23430
23489
|
const dir = this.path;
|
|
23431
23490
|
try {
|
|
23432
|
-
await
|
|
23491
|
+
await readdir20(dir);
|
|
23433
23492
|
} catch (err) {
|
|
23434
23493
|
if (this._removeWatcher) {
|
|
23435
23494
|
this._removeWatcher(sp2.dirname(dir), sp2.basename(dir));
|
|
@@ -23793,7 +23852,7 @@ var init_chokidar = __esm(() => {
|
|
|
23793
23852
|
const fullPath = opts.cwd ? sp2.join(opts.cwd, path) : path;
|
|
23794
23853
|
let stats;
|
|
23795
23854
|
try {
|
|
23796
|
-
stats = await
|
|
23855
|
+
stats = await stat11(fullPath);
|
|
23797
23856
|
} catch (err) {}
|
|
23798
23857
|
if (!stats || this.closed)
|
|
23799
23858
|
return;
|
|
@@ -24362,8 +24421,8 @@ function canonicalConfig(config) {
|
|
|
24362
24421
|
// src/agent-provisioning.ts
|
|
24363
24422
|
import { spawn as spawn12 } from "node:child_process";
|
|
24364
24423
|
import { mkdtempSync, rmSync as rmSync2 } from "node:fs";
|
|
24365
|
-
import { homedir as
|
|
24366
|
-
import { delimiter as
|
|
24424
|
+
import { homedir as homedir11, tmpdir as tmpdir4 } from "node:os";
|
|
24425
|
+
import { delimiter as delimiter4, join as join70 } from "node:path";
|
|
24367
24426
|
function runTerminalCommand(request, spawnCommand = spawn12) {
|
|
24368
24427
|
return new Promise((resolve) => {
|
|
24369
24428
|
let child;
|
|
@@ -24406,13 +24465,13 @@ function runTerminalCommand(request, spawnCommand = spawn12) {
|
|
|
24406
24465
|
function defaults2() {
|
|
24407
24466
|
return {
|
|
24408
24467
|
platform: process.platform,
|
|
24409
|
-
home:
|
|
24468
|
+
home: homedir11(),
|
|
24410
24469
|
env: process.env,
|
|
24411
24470
|
resolveBinary: resolveBinaryPath,
|
|
24412
24471
|
discover: discoverAgents,
|
|
24413
24472
|
runCommand: runTerminalCommand,
|
|
24414
24473
|
supportsLoginCommand: (agent, path, env) => supportsNativeLoginCommand(agent, path, { env }),
|
|
24415
|
-
makeTempDir: () => mkdtempSync(
|
|
24474
|
+
makeTempDir: () => mkdtempSync(join70(tmpdir4(), "av-agent-install-")),
|
|
24416
24475
|
removeTempDir: (path) => rmSync2(path, { recursive: true, force: true })
|
|
24417
24476
|
};
|
|
24418
24477
|
}
|
|
@@ -24439,7 +24498,7 @@ async function runOfficialInstaller(installerUrl, deps, options = {}) {
|
|
|
24439
24498
|
let directory;
|
|
24440
24499
|
try {
|
|
24441
24500
|
directory = deps.makeTempDir();
|
|
24442
|
-
const scriptPath =
|
|
24501
|
+
const scriptPath = join70(directory, "install.sh");
|
|
24443
24502
|
const request = { env: options.env ?? deps.env, ...options.cwd ? { cwd: options.cwd } : {} };
|
|
24444
24503
|
const download = await deps.runCommand({
|
|
24445
24504
|
command: curl,
|
|
@@ -24510,10 +24569,10 @@ async function installChiefAgent(agent, overrides = {}) {
|
|
|
24510
24569
|
const install = await runOfficialInstaller(plan.installerUrl, deps);
|
|
24511
24570
|
if (!install.success)
|
|
24512
24571
|
return commandFailure(install.stage === "download" ? "Installer download" : "Installation", install, plan.documentation);
|
|
24513
|
-
const localBin =
|
|
24514
|
-
const pathParts = (deps.env.PATH ?? "").split(
|
|
24572
|
+
const localBin = join70(deps.home, ".local", "bin");
|
|
24573
|
+
const pathParts = (deps.env.PATH ?? "").split(delimiter4);
|
|
24515
24574
|
if (!pathParts.includes(localBin))
|
|
24516
|
-
deps.env.PATH = [localBin, ...pathParts.filter(Boolean)].join(
|
|
24575
|
+
deps.env.PATH = [localBin, ...pathParts.filter(Boolean)].join(delimiter4);
|
|
24517
24576
|
return { success: true, message: "Installation finished; checking the CLI next." };
|
|
24518
24577
|
} catch {
|
|
24519
24578
|
return { success: false, message: `Installation did not complete. Retry or follow ${plan.documentation}.` };
|
|
@@ -24611,31 +24670,31 @@ var init_agent_provisioning = __esm(() => {
|
|
|
24611
24670
|
|
|
24612
24671
|
// src/oma-provisioning.ts
|
|
24613
24672
|
import { mkdtempSync as mkdtempSync2, rmSync as rmSync3 } from "node:fs";
|
|
24614
|
-
import { chmod as chmod5, lstat as
|
|
24615
|
-
import { homedir as
|
|
24616
|
-
import { delimiter as
|
|
24673
|
+
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";
|
|
24674
|
+
import { homedir as homedir12, tmpdir as tmpdir5 } from "node:os";
|
|
24675
|
+
import { delimiter as delimiter5, isAbsolute as isAbsolute23, join as join71, relative as relative22, resolve as resolve44 } from "node:path";
|
|
24617
24676
|
function defaults3() {
|
|
24618
|
-
const home =
|
|
24677
|
+
const home = homedir12();
|
|
24619
24678
|
return {
|
|
24620
24679
|
platform: process.platform,
|
|
24621
24680
|
home,
|
|
24622
24681
|
env: process.env,
|
|
24623
|
-
resolveBinary: (name) => resolveBinaryPath(name, name === "bun" ? [
|
|
24682
|
+
resolveBinary: (name) => resolveBinaryPath(name, name === "bun" ? [join71(process.env.BUN_INSTALL ?? join71(home, ".bun"), "bin", "bun")] : []),
|
|
24624
24683
|
runCommand: runTerminalCommand,
|
|
24625
|
-
makeTempDir: () => mkdtempSync2(
|
|
24684
|
+
makeTempDir: () => mkdtempSync2(join71(tmpdir5(), "av-oma-install-")),
|
|
24626
24685
|
removeTempDir: (path) => rmSync3(path, { recursive: true, force: true })
|
|
24627
24686
|
};
|
|
24628
24687
|
}
|
|
24629
24688
|
async function directory2(path) {
|
|
24630
24689
|
try {
|
|
24631
|
-
return (await
|
|
24690
|
+
return (await lstat31(path)).isDirectory();
|
|
24632
24691
|
} catch {
|
|
24633
24692
|
return false;
|
|
24634
24693
|
}
|
|
24635
24694
|
}
|
|
24636
24695
|
async function present(path) {
|
|
24637
24696
|
try {
|
|
24638
|
-
await
|
|
24697
|
+
await lstat31(path);
|
|
24639
24698
|
return true;
|
|
24640
24699
|
} catch {
|
|
24641
24700
|
return false;
|
|
@@ -24643,7 +24702,7 @@ async function present(path) {
|
|
|
24643
24702
|
}
|
|
24644
24703
|
async function installedVersion2(skills) {
|
|
24645
24704
|
try {
|
|
24646
|
-
const marker = JSON.parse(await
|
|
24705
|
+
const marker = JSON.parse(await readFile24(join71(skills, "_version.json"), "utf8"));
|
|
24647
24706
|
return marker.schemaVersion === 2 && marker.mode === "project" && typeof marker.version === "string" && /^\d+\.\d+\.\d+(?:-[a-zA-Z0-9.-]+)?$/.test(marker.version) ? marker.version : null;
|
|
24648
24707
|
} catch {
|
|
24649
24708
|
return null;
|
|
@@ -24652,13 +24711,13 @@ async function installedVersion2(skills) {
|
|
|
24652
24711
|
async function snapshotConfig(agents) {
|
|
24653
24712
|
const snapshots = [];
|
|
24654
24713
|
for (const name of CUSTOM_CONFIG_NAMES) {
|
|
24655
|
-
const path =
|
|
24714
|
+
const path = join71(agents, name);
|
|
24656
24715
|
if (!await present(path))
|
|
24657
24716
|
continue;
|
|
24658
|
-
const file = await
|
|
24717
|
+
const file = await lstat31(path);
|
|
24659
24718
|
if (!file.isFile())
|
|
24660
24719
|
throw new Error("Custom configuration must be a project-local regular file.");
|
|
24661
|
-
snapshots.push({ path, bytes: await
|
|
24720
|
+
snapshots.push({ path, bytes: await readFile24(path), mode: file.mode & 511 });
|
|
24662
24721
|
}
|
|
24663
24722
|
return snapshots;
|
|
24664
24723
|
}
|
|
@@ -24672,10 +24731,10 @@ async function restoreConfig(agents, snapshots) {
|
|
|
24672
24731
|
["oma-config.yaml", "oma-config.cue"],
|
|
24673
24732
|
["oma-config.local.yaml", "oma-config.local.cue"]
|
|
24674
24733
|
]) {
|
|
24675
|
-
if (!pair.some((name) => original.has(
|
|
24734
|
+
if (!pair.some((name) => original.has(join71(agents, name))))
|
|
24676
24735
|
continue;
|
|
24677
24736
|
for (const name of pair) {
|
|
24678
|
-
const path =
|
|
24737
|
+
const path = join71(agents, name);
|
|
24679
24738
|
if (!original.has(path))
|
|
24680
24739
|
await unlink7(path).catch((error) => {
|
|
24681
24740
|
if (error.code !== "ENOENT")
|
|
@@ -24685,17 +24744,17 @@ async function restoreConfig(agents, snapshots) {
|
|
|
24685
24744
|
}
|
|
24686
24745
|
}
|
|
24687
24746
|
async function workspacePath(input) {
|
|
24688
|
-
if (!input.trim() || !
|
|
24747
|
+
if (!input.trim() || !isAbsolute23(input))
|
|
24689
24748
|
return null;
|
|
24690
24749
|
const root = resolve44(input);
|
|
24691
24750
|
if (!await directory2(root))
|
|
24692
24751
|
return null;
|
|
24693
|
-
for (const path of [
|
|
24752
|
+
for (const path of [join71(root, ".agents"), join71(root, ".agents", "skills")]) {
|
|
24694
24753
|
if (!await present(path))
|
|
24695
24754
|
continue;
|
|
24696
24755
|
const actual = await realpath39(path);
|
|
24697
24756
|
const location2 = relative22(await realpath39(root), actual);
|
|
24698
|
-
if (location2 === ".." || location2.startsWith(`..${process.platform === "win32" ? "\\" : "/"}`) ||
|
|
24757
|
+
if (location2 === ".." || location2.startsWith(`..${process.platform === "win32" ? "\\" : "/"}`) || isAbsolute23(location2))
|
|
24699
24758
|
return null;
|
|
24700
24759
|
}
|
|
24701
24760
|
return root;
|
|
@@ -24705,15 +24764,15 @@ async function inspectOma(workspaceRoot, _overrides = {}) {
|
|
|
24705
24764
|
const root = await workspacePath(workspaceRoot);
|
|
24706
24765
|
if (!root)
|
|
24707
24766
|
return { success: false, message: "Choose an existing absolute workspace with project-local OMA files." };
|
|
24708
|
-
const skills =
|
|
24767
|
+
const skills = join71(root, ".agents", "skills");
|
|
24709
24768
|
const version = await installedVersion2(skills);
|
|
24710
24769
|
if (!version)
|
|
24711
24770
|
throw new Error("Invalid installed metadata");
|
|
24712
|
-
const entries = (await
|
|
24771
|
+
const entries = (await readdir21(skills, { withFileTypes: true })).filter((entry) => /^oma-[a-z0-9-]+$/.test(entry.name));
|
|
24713
24772
|
if (!entries.length)
|
|
24714
24773
|
throw new Error("No installed skills");
|
|
24715
24774
|
for (const entry of entries) {
|
|
24716
|
-
if (!entry.isDirectory() || !(await
|
|
24775
|
+
if (!entry.isDirectory() || !(await lstat31(join71(skills, entry.name, "SKILL.md"))).isFile())
|
|
24717
24776
|
throw new Error("Incomplete installed skill");
|
|
24718
24777
|
}
|
|
24719
24778
|
return {
|
|
@@ -24761,16 +24820,16 @@ async function prepareOma(workspaceRoot, overrides = {}) {
|
|
|
24761
24820
|
delete environment.OMA_YES;
|
|
24762
24821
|
environment.CI = "true";
|
|
24763
24822
|
const paths = [
|
|
24764
|
-
deps.env.BUN_INSTALL_BIN ??
|
|
24765
|
-
|
|
24823
|
+
deps.env.BUN_INSTALL_BIN ?? join71(deps.env.BUN_INSTALL ?? join71(deps.home, ".bun"), "bin"),
|
|
24824
|
+
join71(deps.home, ".local", "bin")
|
|
24766
24825
|
];
|
|
24767
|
-
environment.PATH = [...new Set([...paths, ...(environment.PATH ?? "").split(
|
|
24826
|
+
environment.PATH = [...new Set([...paths, ...(environment.PATH ?? "").split(delimiter5).filter(Boolean)])].join(delimiter5);
|
|
24768
24827
|
const request = { command: bun, env: environment, cwd: root, timeoutMs: 300000 };
|
|
24769
24828
|
const latest = await deps.runCommand({ ...request, args: ["install", "--global", LATEST_PACKAGE] });
|
|
24770
24829
|
if (!latest.success)
|
|
24771
24830
|
return failure4("OMA CLI update", latest);
|
|
24772
|
-
const agents =
|
|
24773
|
-
const existing = await installedVersion2(
|
|
24831
|
+
const agents = join71(root, ".agents");
|
|
24832
|
+
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")));
|
|
24774
24833
|
const custom = await snapshotConfig(agents);
|
|
24775
24834
|
const args = existing ? ["update", "--yes", "--with-new-skills", "--all"] : ["install"];
|
|
24776
24835
|
let installed;
|
|
@@ -26257,9 +26316,9 @@ var init_ui = __esm(() => {
|
|
|
26257
26316
|
|
|
26258
26317
|
// src/setup/workspace-step.ts
|
|
26259
26318
|
import { statSync as statSync6 } from "node:fs";
|
|
26260
|
-
import { isAbsolute as
|
|
26319
|
+
import { isAbsolute as isAbsolute24 } from "node:path";
|
|
26261
26320
|
async function validateOrderWorkspace(path) {
|
|
26262
|
-
if (!
|
|
26321
|
+
if (!isAbsolute24(path))
|
|
26263
26322
|
return "Set workspace.root in av.yaml to an absolute Git repository path.";
|
|
26264
26323
|
try {
|
|
26265
26324
|
if (!statSync6(path).isDirectory())
|
|
@@ -26286,7 +26345,7 @@ async function stepWorkspace(ctx, step, total) {
|
|
|
26286
26345
|
validate: (v) => {
|
|
26287
26346
|
if (!v?.trim())
|
|
26288
26347
|
return "Required";
|
|
26289
|
-
if (!
|
|
26348
|
+
if (!isAbsolute24(v.trim()))
|
|
26290
26349
|
return "Must be an absolute path";
|
|
26291
26350
|
}
|
|
26292
26351
|
});
|
|
@@ -26312,8 +26371,8 @@ var init_workspace_step = __esm(() => {
|
|
|
26312
26371
|
});
|
|
26313
26372
|
|
|
26314
26373
|
// src/setup/noninteractive-config.ts
|
|
26315
|
-
import { lstat as
|
|
26316
|
-
import { isAbsolute as
|
|
26374
|
+
import { lstat as lstat32, realpath as realpath40 } from "node:fs/promises";
|
|
26375
|
+
import { isAbsolute as isAbsolute25, join as join72, parse as parsePath, resolve as resolve45 } from "node:path";
|
|
26317
26376
|
function validateNoninteractiveOptions(options) {
|
|
26318
26377
|
if (!options.yes || options.edit || options.mode !== undefined && options.mode !== "order")
|
|
26319
26378
|
throw new Error("Use av setup --yes only for local order setup; --edit and --mode tracker require interactive setup.");
|
|
@@ -26357,7 +26416,7 @@ function selectChief(options, deps, project, global2) {
|
|
|
26357
26416
|
const globalActor = actor(global2);
|
|
26358
26417
|
const selected = options.actor ?? runtime?.actorType ?? projectActor.type ?? globalActor.type;
|
|
26359
26418
|
if (!selected)
|
|
26360
|
-
throw new Error(`actor.type is missing in ${
|
|
26419
|
+
throw new Error(`actor.type is missing in ${join72(deps.projectRoot, "av.yaml")} and ${deps.globalConfigPath}, and the current agent runtime is unknown. Rerun av setup --yes --actor <current-vendor> --model <current-model-or-empty>.`);
|
|
26361
26420
|
const actorType = selected;
|
|
26362
26421
|
const actorSource = options.actor !== undefined ? "explicit" : runtime ? "runtime" : projectActor.type ? "project" : "global";
|
|
26363
26422
|
const previousType = projectActor.type ?? globalActor.type;
|
|
@@ -26396,13 +26455,13 @@ async function prepareNoninteractiveConfig(options, deps) {
|
|
|
26396
26455
|
let projectRoot;
|
|
26397
26456
|
try {
|
|
26398
26457
|
projectRoot = await realpath40(resolve45(deps.projectRoot));
|
|
26399
|
-
if (!(await
|
|
26458
|
+
if (!(await lstat32(projectRoot)).isDirectory())
|
|
26400
26459
|
throw new Error("not a directory");
|
|
26401
26460
|
} catch {
|
|
26402
26461
|
throw new Error(`AV configuration directory ${deps.projectRoot} does not exist. Run av setup from an existing directory.`);
|
|
26403
26462
|
}
|
|
26404
26463
|
const globalPath = resolve45(deps.globalConfigPath);
|
|
26405
|
-
const projectPath =
|
|
26464
|
+
const projectPath = join72(projectRoot, "av.yaml");
|
|
26406
26465
|
const project = await configFile(projectPath, projectConfigSchema);
|
|
26407
26466
|
const global2 = await configFile(globalPath, globalConfigSchema);
|
|
26408
26467
|
const chief = selectChief(options, { ...deps, projectRoot, globalConfigPath: globalPath }, project.raw, global2.raw);
|
|
@@ -26419,7 +26478,7 @@ async function prepareNoninteractiveConfig(options, deps) {
|
|
|
26419
26478
|
}
|
|
26420
26479
|
const savedWorkspace = project.raw.workspace?.root;
|
|
26421
26480
|
const selectedWorkspace = options.workspace ?? savedWorkspace ?? projectRoot;
|
|
26422
|
-
const workspacePath =
|
|
26481
|
+
const workspacePath = isAbsolute25(selectedWorkspace) ? selectedWorkspace : resolve45(projectRoot, selectedWorkspace);
|
|
26423
26482
|
const workspaceError = await validateOrderWorkspace(workspacePath);
|
|
26424
26483
|
if (workspaceError)
|
|
26425
26484
|
throw new Error(workspaceError);
|
|
@@ -26466,7 +26525,7 @@ var init_noninteractive_config = __esm(() => {
|
|
|
26466
26525
|
});
|
|
26467
26526
|
|
|
26468
26527
|
// src/setup/noninteractive.ts
|
|
26469
|
-
import { join as
|
|
26528
|
+
import { join as join73, parse as parsePath2, resolve as resolve46 } from "node:path";
|
|
26470
26529
|
function rerunCommand(result, options) {
|
|
26471
26530
|
const quote = (value) => `'${value.replace(/'/g, "'\\''")}'`;
|
|
26472
26531
|
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`;
|
|
@@ -26480,7 +26539,7 @@ async function setupNoninteractive(options, overrides = {}) {
|
|
|
26480
26539
|
projectRoot: resolve46(deps.projectRoot),
|
|
26481
26540
|
workspace: null,
|
|
26482
26541
|
config: {
|
|
26483
|
-
project:
|
|
26542
|
+
project: join73(resolve46(deps.projectRoot), "av.yaml"),
|
|
26484
26543
|
global: resolve46(deps.globalConfigPath),
|
|
26485
26544
|
saved: false
|
|
26486
26545
|
},
|
|
@@ -26967,7 +27026,7 @@ var init_container_step = __esm(() => {
|
|
|
26967
27026
|
});
|
|
26968
27027
|
|
|
26969
27028
|
// src/setup/metric-step.ts
|
|
26970
|
-
import { isAbsolute as
|
|
27029
|
+
import { isAbsolute as isAbsolute26 } from "node:path";
|
|
26971
27030
|
async function text13(message, initialValue, validate) {
|
|
26972
27031
|
const value = await text11({
|
|
26973
27032
|
message: `${message} (:back goes back)`,
|
|
@@ -27051,7 +27110,7 @@ async function stepMetrics(ctx) {
|
|
|
27051
27110
|
draft.token_env = token;
|
|
27052
27111
|
} else {
|
|
27053
27112
|
const file = await text13("Repository-relative JSON file", old?.file ?? "metrics/revenue.json", (value) => {
|
|
27054
|
-
if (!value || value.length > 2000 ||
|
|
27113
|
+
if (!value || value.length > 2000 || isAbsolute26(value) || /^[A-Za-z]:/.test(value) || value.startsWith("\\") || value.split(/[\\/]/).includes(".."))
|
|
27055
27114
|
return "Use a relative file inside the repository, without ..";
|
|
27056
27115
|
});
|
|
27057
27116
|
if (navigated2(file))
|
|
@@ -28940,10 +28999,10 @@ var init_setup = __esm(() => {
|
|
|
28940
28999
|
|
|
28941
29000
|
// ../../packages/core/src/relay/credentials.ts
|
|
28942
29001
|
import { readFileSync as readFileSync14 } from "node:fs";
|
|
28943
|
-
import { homedir as
|
|
28944
|
-
import { join as
|
|
29002
|
+
import { homedir as homedir13 } from "node:os";
|
|
29003
|
+
import { join as join74 } from "node:path";
|
|
28945
29004
|
function defaultCredentialsPath() {
|
|
28946
|
-
return
|
|
29005
|
+
return join74(homedir13(), ".agent-valley", "credentials.json");
|
|
28947
29006
|
}
|
|
28948
29007
|
function validateRelayCredentials(value, binding, now = Date.now()) {
|
|
28949
29008
|
const result = credentialsSchema.safeParse(value);
|
|
@@ -53225,8 +53284,8 @@ async function startAvMcpHttp(api, options) {
|
|
|
53225
53284
|
|
|
53226
53285
|
// src/mission-api.ts
|
|
53227
53286
|
import { randomUUID as randomUUID22 } from "node:crypto";
|
|
53228
|
-
import { lstat as
|
|
53229
|
-
import { isAbsolute as
|
|
53287
|
+
import { lstat as lstat25, readdir as readdir14, realpath as realpath33 } from "node:fs/promises";
|
|
53288
|
+
import { isAbsolute as isAbsolute19, join as join55 } from "node:path";
|
|
53230
53289
|
|
|
53231
53290
|
// ../../packages/core/src/chief/reports.ts
|
|
53232
53291
|
init_zod();
|
|
@@ -54142,7 +54201,103 @@ async function cargoVerificationInputs(root, budget) {
|
|
|
54142
54201
|
// ../../packages/core/src/chief/verification-command.ts
|
|
54143
54202
|
import { spawn as spawn5 } from "node:child_process";
|
|
54144
54203
|
import { realpath as realpath12 } from "node:fs/promises";
|
|
54145
|
-
import { join as
|
|
54204
|
+
import { join as join18, relative as relative8, sep as sep8 } from "node:path";
|
|
54205
|
+
|
|
54206
|
+
// ../../packages/core/src/chief/cargo-toolchain.ts
|
|
54207
|
+
import { constants as constants7 } from "node:fs";
|
|
54208
|
+
import { access, lstat as lstat10, readdir as readdir5, readFile as readFile6, stat as stat2 } from "node:fs/promises";
|
|
54209
|
+
import { homedir as homedir5 } from "node:os";
|
|
54210
|
+
import { delimiter as delimiter2, isAbsolute as isAbsolute8, join as join17 } from "node:path";
|
|
54211
|
+
var channelName = /^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/;
|
|
54212
|
+
var hostTriple = /^[A-Za-z][A-Za-z0-9_]*(?:-[A-Za-z0-9_]+){2,5}$/;
|
|
54213
|
+
function toolchainChannel(source, legacy) {
|
|
54214
|
+
const lines = source.split(/\r?\n/).map((line) => line.trim());
|
|
54215
|
+
const meaningful = lines.filter((line) => line && !line.startsWith("#"));
|
|
54216
|
+
if (legacy && meaningful.length === 1 && channelName.test(meaningful[0] ?? ""))
|
|
54217
|
+
return meaningful[0];
|
|
54218
|
+
let inToolchain = false;
|
|
54219
|
+
let seenToolchain = false;
|
|
54220
|
+
let channel;
|
|
54221
|
+
for (const line of meaningful) {
|
|
54222
|
+
const section = /^\[([^\]]+)\]\s*(?:#.*)?$/.exec(line);
|
|
54223
|
+
if (section) {
|
|
54224
|
+
inToolchain = section[1] === "toolchain";
|
|
54225
|
+
if (inToolchain && seenToolchain)
|
|
54226
|
+
return;
|
|
54227
|
+
if (inToolchain)
|
|
54228
|
+
seenToolchain = true;
|
|
54229
|
+
} else if (inToolchain && /^path\s*=/.test(line))
|
|
54230
|
+
return;
|
|
54231
|
+
else if (inToolchain && /^channel\s*=/.test(line)) {
|
|
54232
|
+
if (channel !== undefined)
|
|
54233
|
+
return;
|
|
54234
|
+
const match = /^channel\s*=\s*(["'])([A-Za-z0-9][A-Za-z0-9._-]{0,127})\1\s*(?:#.*)?$/.exec(line);
|
|
54235
|
+
if (!match)
|
|
54236
|
+
return;
|
|
54237
|
+
channel = match[2];
|
|
54238
|
+
}
|
|
54239
|
+
}
|
|
54240
|
+
return channel;
|
|
54241
|
+
}
|
|
54242
|
+
async function projectChannel(root) {
|
|
54243
|
+
for (const name of ["rust-toolchain", "rust-toolchain.toml"]) {
|
|
54244
|
+
try {
|
|
54245
|
+
const path = join17(root, name);
|
|
54246
|
+
const metadata = await lstat10(path);
|
|
54247
|
+
if (!metadata.isFile() || metadata.size > 16384)
|
|
54248
|
+
return;
|
|
54249
|
+
return toolchainChannel(await readFile6(path, "utf8"), name === "rust-toolchain");
|
|
54250
|
+
} catch (error) {
|
|
54251
|
+
if (error.code !== "ENOENT")
|
|
54252
|
+
return;
|
|
54253
|
+
}
|
|
54254
|
+
}
|
|
54255
|
+
return;
|
|
54256
|
+
}
|
|
54257
|
+
async function executable(path) {
|
|
54258
|
+
try {
|
|
54259
|
+
if (!(await stat2(path)).isFile())
|
|
54260
|
+
return false;
|
|
54261
|
+
await access(path, constants7.X_OK);
|
|
54262
|
+
return true;
|
|
54263
|
+
} catch {
|
|
54264
|
+
return false;
|
|
54265
|
+
}
|
|
54266
|
+
}
|
|
54267
|
+
async function cargoVerificationEnvironment(root, source) {
|
|
54268
|
+
const env = { ...source, RUSTUP_AUTO_INSTALL: "0" };
|
|
54269
|
+
if (source.RUSTUP_TOOLCHAIN !== undefined)
|
|
54270
|
+
return env;
|
|
54271
|
+
const channel = await projectChannel(root);
|
|
54272
|
+
if (!channel)
|
|
54273
|
+
return env;
|
|
54274
|
+
const rustupHome = source.RUSTUP_HOME ?? join17(source.HOME ?? homedir5(), ".rustup");
|
|
54275
|
+
if (!isAbsolute8(rustupHome))
|
|
54276
|
+
return env;
|
|
54277
|
+
const directory = join17(rustupHome, "toolchains");
|
|
54278
|
+
let names;
|
|
54279
|
+
try {
|
|
54280
|
+
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)));
|
|
54281
|
+
} catch {
|
|
54282
|
+
return env;
|
|
54283
|
+
}
|
|
54284
|
+
const suffix = process.platform === "win32" ? ".exe" : "";
|
|
54285
|
+
const installed = await Promise.all(names.map(async (name) => {
|
|
54286
|
+
const bin = join17(directory, name, "bin");
|
|
54287
|
+
return await executable(join17(bin, `cargo${suffix}`)) && await executable(join17(bin, `rustc${suffix}`)) ? { name, bin } : undefined;
|
|
54288
|
+
}));
|
|
54289
|
+
const available = installed.filter((entry) => entry !== undefined);
|
|
54290
|
+
const selected = available.find((entry) => entry.name === channel) ?? (available.length === 1 ? available[0] : undefined);
|
|
54291
|
+
if (!selected)
|
|
54292
|
+
return env;
|
|
54293
|
+
return {
|
|
54294
|
+
...env,
|
|
54295
|
+
PATH: source.PATH ? `${selected.bin}${delimiter2}${source.PATH}` : selected.bin,
|
|
54296
|
+
RUSTUP_TOOLCHAIN: selected.name
|
|
54297
|
+
};
|
|
54298
|
+
}
|
|
54299
|
+
|
|
54300
|
+
// ../../packages/core/src/chief/verification-command.ts
|
|
54146
54301
|
var MAX_VERIFICATION_OUTPUT_BYTES = 1048576;
|
|
54147
54302
|
async function joinVerificationGroup(pid, detached) {
|
|
54148
54303
|
if (!pid || !detached)
|
|
@@ -54177,8 +54332,8 @@ async function verificationCommandInputs(root, program, args, budget) {
|
|
|
54177
54332
|
return cargoVerificationInputs(root, budget);
|
|
54178
54333
|
const names = verificationCommandTestPaths(program, args);
|
|
54179
54334
|
if (program === "node" && args[0] === "node_modules/vitest/vitest.mjs") {
|
|
54180
|
-
const launcher = await realpath12(
|
|
54181
|
-
if (!launcher.startsWith(`${
|
|
54335
|
+
const launcher = await realpath12(join18(root, args[0]));
|
|
54336
|
+
if (!launcher.startsWith(`${join18(root, "node_modules")}${sep8}`))
|
|
54182
54337
|
throw new Error("Installed Vitest launcher escapes this worktree. Install its dependency inside node_modules.");
|
|
54183
54338
|
names.unshift(relative8(root, launcher));
|
|
54184
54339
|
}
|
|
@@ -54189,94 +54344,102 @@ async function verificationCommandInputs(root, program, args, budget) {
|
|
|
54189
54344
|
}
|
|
54190
54345
|
return inputs;
|
|
54191
54346
|
}
|
|
54192
|
-
var executeVerificationCommand = (program, args, options) =>
|
|
54193
|
-
if (!safeVerificationCommand(program, args))
|
|
54194
|
-
|
|
54195
|
-
|
|
54196
|
-
|
|
54197
|
-
|
|
54198
|
-
|
|
54199
|
-
|
|
54200
|
-
|
|
54201
|
-
|
|
54202
|
-
|
|
54203
|
-
for (const key of [
|
|
54204
|
-
"GIT_DIR",
|
|
54205
|
-
"GIT_WORK_TREE",
|
|
54206
|
-
"GIT_COMMON_DIR",
|
|
54207
|
-
"GIT_INDEX_FILE",
|
|
54208
|
-
"GIT_OBJECT_DIRECTORY",
|
|
54209
|
-
"GIT_ALTERNATE_OBJECT_DIRECTORIES"
|
|
54210
|
-
])
|
|
54211
|
-
delete env[key];
|
|
54212
|
-
Object.assign(env, { GIT_OPTIONAL_LOCKS: "0", GIT_NO_LAZY_FETCH: "1", GIT_LITERAL_PATHSPECS: "1" });
|
|
54213
|
-
if (program === "cargo")
|
|
54214
|
-
Object.assign(env, { CARGO_NET_OFFLINE: "true", CARGO_TERM_COLOR: "never" });
|
|
54215
|
-
const argv = program === "git" ? ["-c", "core.fsmonitor=false", "-c", "diff.external=", "-c", "core.pager=cat", "--no-pager", ...args] : args;
|
|
54216
|
-
const child = spawn5(program, argv, {
|
|
54217
|
-
cwd: options.cwd,
|
|
54218
|
-
detached,
|
|
54219
|
-
shell: false,
|
|
54220
|
-
stdio: ["ignore", "pipe", "pipe"],
|
|
54221
|
-
env
|
|
54222
|
-
});
|
|
54223
|
-
let stdout = "";
|
|
54224
|
-
let stderr = "";
|
|
54225
|
-
let bytes = 0;
|
|
54226
|
-
let failure;
|
|
54227
|
-
const stop = (error) => {
|
|
54228
|
-
failure ??= error;
|
|
54229
|
-
if (detached && child.pid) {
|
|
54230
|
-
try {
|
|
54231
|
-
process.kill(-child.pid, "SIGKILL");
|
|
54232
|
-
return;
|
|
54233
|
-
} catch {}
|
|
54347
|
+
var executeVerificationCommand = async (program, args, options) => {
|
|
54348
|
+
if (!safeVerificationCommand(program, args))
|
|
54349
|
+
throw new Error("Unsupported automatic verification command. Use explicit tests or read-only Git argv.");
|
|
54350
|
+
if (options.signal?.aborted)
|
|
54351
|
+
throw new Error("Verification interrupted. Resume the mission to rerun its evidence checks.");
|
|
54352
|
+
const startedAt = performance.now();
|
|
54353
|
+
const env = program === "cargo" ? await cargoVerificationEnvironment(options.cwd, process.env) : { ...process.env };
|
|
54354
|
+
return new Promise((resolveCommand, rejectCommand) => {
|
|
54355
|
+
if (options.signal?.aborted) {
|
|
54356
|
+
rejectCommand(new Error("Verification interrupted. Resume the mission to rerun its evidence checks."));
|
|
54357
|
+
return;
|
|
54234
54358
|
}
|
|
54235
|
-
|
|
54236
|
-
|
|
54237
|
-
|
|
54238
|
-
const timer = setTimeout(() => stop(new Error("Verification timed out. Repair the test or increase its bounded timeout.")), options.timeoutMs);
|
|
54239
|
-
timer.unref();
|
|
54240
|
-
const capture = (chunk, stream) => {
|
|
54241
|
-
bytes += chunk.length;
|
|
54242
|
-
if (bytes > options.maxOutputBytes) {
|
|
54243
|
-
stop(new Error("Verification output exceeds its evidence budget. Reduce noisy test output and retry."));
|
|
54359
|
+
const timeoutMs = options.timeoutMs - (performance.now() - startedAt);
|
|
54360
|
+
if (timeoutMs <= 0) {
|
|
54361
|
+
rejectCommand(new Error("Verification timed out. Repair the test or increase its bounded timeout."));
|
|
54244
54362
|
return;
|
|
54245
54363
|
}
|
|
54246
|
-
|
|
54247
|
-
|
|
54248
|
-
|
|
54249
|
-
|
|
54250
|
-
|
|
54251
|
-
|
|
54252
|
-
|
|
54253
|
-
|
|
54254
|
-
|
|
54255
|
-
|
|
54256
|
-
|
|
54257
|
-
|
|
54258
|
-
|
|
54259
|
-
|
|
54260
|
-
|
|
54261
|
-
|
|
54364
|
+
const detached = process.platform !== "win32";
|
|
54365
|
+
for (const key of [
|
|
54366
|
+
"GIT_DIR",
|
|
54367
|
+
"GIT_WORK_TREE",
|
|
54368
|
+
"GIT_COMMON_DIR",
|
|
54369
|
+
"GIT_INDEX_FILE",
|
|
54370
|
+
"GIT_OBJECT_DIRECTORY",
|
|
54371
|
+
"GIT_ALTERNATE_OBJECT_DIRECTORIES"
|
|
54372
|
+
])
|
|
54373
|
+
delete env[key];
|
|
54374
|
+
Object.assign(env, { GIT_OPTIONAL_LOCKS: "0", GIT_NO_LAZY_FETCH: "1", GIT_LITERAL_PATHSPECS: "1" });
|
|
54375
|
+
if (program === "cargo")
|
|
54376
|
+
Object.assign(env, { CARGO_NET_OFFLINE: "true", CARGO_TERM_COLOR: "never" });
|
|
54377
|
+
const argv = program === "git" ? ["-c", "core.fsmonitor=false", "-c", "diff.external=", "-c", "core.pager=cat", "--no-pager", ...args] : args;
|
|
54378
|
+
const child = spawn5(program, argv, {
|
|
54379
|
+
cwd: options.cwd,
|
|
54380
|
+
detached,
|
|
54381
|
+
shell: false,
|
|
54382
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
54383
|
+
env
|
|
54384
|
+
});
|
|
54385
|
+
let stdout = "";
|
|
54386
|
+
let stderr = "";
|
|
54387
|
+
let bytes = 0;
|
|
54388
|
+
let failure;
|
|
54389
|
+
const stop = (error) => {
|
|
54390
|
+
failure ??= error;
|
|
54391
|
+
if (detached && child.pid) {
|
|
54392
|
+
try {
|
|
54393
|
+
process.kill(-child.pid, "SIGKILL");
|
|
54394
|
+
return;
|
|
54395
|
+
} catch {}
|
|
54396
|
+
}
|
|
54397
|
+
child.kill("SIGKILL");
|
|
54398
|
+
};
|
|
54399
|
+
const abort = () => stop(new Error("Verification interrupted. Resume the mission to rerun evidence checks."));
|
|
54400
|
+
const timer = setTimeout(() => stop(new Error("Verification timed out. Repair the test or increase its bounded timeout.")), timeoutMs);
|
|
54401
|
+
timer.unref();
|
|
54402
|
+
const capture = (chunk, stream) => {
|
|
54403
|
+
bytes += chunk.length;
|
|
54404
|
+
if (bytes > options.maxOutputBytes) {
|
|
54405
|
+
stop(new Error("Verification output exceeds its evidence budget. Reduce noisy test output and retry."));
|
|
54406
|
+
return;
|
|
54407
|
+
}
|
|
54408
|
+
if (stream === "stdout")
|
|
54409
|
+
stdout += chunk.toString("utf8");
|
|
54410
|
+
else
|
|
54411
|
+
stderr += chunk.toString("utf8");
|
|
54412
|
+
};
|
|
54413
|
+
child.stdout?.on("data", (chunk) => capture(chunk, "stdout"));
|
|
54414
|
+
child.stderr?.on("data", (chunk) => capture(chunk, "stderr"));
|
|
54415
|
+
child.once("error", (error) => {
|
|
54416
|
+
failure = error;
|
|
54417
|
+
});
|
|
54418
|
+
child.once("close", async (exitCode) => {
|
|
54419
|
+
clearTimeout(timer);
|
|
54420
|
+
try {
|
|
54421
|
+
await joinVerificationGroup(child.pid, detached);
|
|
54422
|
+
} catch (error) {
|
|
54423
|
+
failure ??= error instanceof Error ? error : new Error("Cannot join verification child processes.");
|
|
54424
|
+
}
|
|
54425
|
+
options.signal?.removeEventListener("abort", abort);
|
|
54426
|
+
if (failure)
|
|
54427
|
+
rejectCommand(failure);
|
|
54428
|
+
else
|
|
54429
|
+
resolveCommand({ exitCode, stdout, stderr });
|
|
54430
|
+
});
|
|
54431
|
+
options.signal?.addEventListener("abort", abort, { once: true });
|
|
54432
|
+
if (options.signal?.aborted)
|
|
54433
|
+
abort();
|
|
54434
|
+
if (child.pid && options.onSpawned) {
|
|
54435
|
+
try {
|
|
54436
|
+
options.onSpawned(child.pid, detached);
|
|
54437
|
+
} catch (error) {
|
|
54438
|
+
stop(error instanceof Error ? error : new Error("Cannot register automatic verification process."));
|
|
54439
|
+
}
|
|
54262
54440
|
}
|
|
54263
|
-
options.signal?.removeEventListener("abort", abort);
|
|
54264
|
-
if (failure)
|
|
54265
|
-
rejectCommand(failure);
|
|
54266
|
-
else
|
|
54267
|
-
resolveCommand({ exitCode, stdout, stderr });
|
|
54268
54441
|
});
|
|
54269
|
-
|
|
54270
|
-
if (options.signal?.aborted)
|
|
54271
|
-
abort();
|
|
54272
|
-
if (child.pid && options.onSpawned) {
|
|
54273
|
-
try {
|
|
54274
|
-
options.onSpawned(child.pid, detached);
|
|
54275
|
-
} catch (error) {
|
|
54276
|
-
stop(error instanceof Error ? error : new Error("Cannot register automatic verification process."));
|
|
54277
|
-
}
|
|
54278
|
-
}
|
|
54279
|
-
});
|
|
54442
|
+
};
|
|
54280
54443
|
|
|
54281
54444
|
// ../../packages/core/src/chief/verification.ts
|
|
54282
54445
|
var digest4 = string2().regex(/^[a-f0-9]{64}$/);
|
|
@@ -54470,6 +54633,150 @@ function validateFinalReview(review, mission) {
|
|
|
54470
54633
|
return review;
|
|
54471
54634
|
}
|
|
54472
54635
|
|
|
54636
|
+
// ../../packages/core/src/chief/actor-health.ts
|
|
54637
|
+
var ACTOR_COOLDOWN_BASE_MS = 15 * 60000;
|
|
54638
|
+
var ACTOR_COOLDOWN_MAX_MS = 6 * 60 * 60000;
|
|
54639
|
+
var ACTOR_PROBE_GRACE_MS = 60000;
|
|
54640
|
+
var healthStages = new Set(["work", "review", "gate-review", "final-review"]);
|
|
54641
|
+
var key = (route) => JSON.stringify([route.actorType, route.model ?? null]);
|
|
54642
|
+
function frameworkFailure(reason) {
|
|
54643
|
+
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);
|
|
54644
|
+
}
|
|
54645
|
+
function nativeOutcome(run) {
|
|
54646
|
+
if (run.nativeOutcome === "cancelled")
|
|
54647
|
+
return;
|
|
54648
|
+
if (run.nativeOutcome)
|
|
54649
|
+
return run.nativeOutcome;
|
|
54650
|
+
if (run.outcome !== "failed")
|
|
54651
|
+
return "passed";
|
|
54652
|
+
if (run.executionState === "settled" && !frameworkFailure(run.evidence))
|
|
54653
|
+
return "failed";
|
|
54654
|
+
return;
|
|
54655
|
+
}
|
|
54656
|
+
function cooldownMs(failures) {
|
|
54657
|
+
return Math.min(ACTOR_COOLDOWN_MAX_MS, ACTOR_COOLDOWN_BASE_MS * 2 ** Math.min(5, failures - 1));
|
|
54658
|
+
}
|
|
54659
|
+
function cooldownUntil(health) {
|
|
54660
|
+
return Math.max(Date.parse(health.lastOutcomeAt) + cooldownMs(health.consecutiveFailures), Date.parse(health.cooldownUntil ?? "") || 0);
|
|
54661
|
+
}
|
|
54662
|
+
function aggregateProviderHealth(mission) {
|
|
54663
|
+
const evidence = new Map;
|
|
54664
|
+
const seedTimes = new Map;
|
|
54665
|
+
for (const route of mission.operations?.routingEvidence ?? [])
|
|
54666
|
+
if (route.providerHealth) {
|
|
54667
|
+
evidence.set(key(route), {
|
|
54668
|
+
actorType: route.actorType,
|
|
54669
|
+
...route.model ? { model: route.model } : {},
|
|
54670
|
+
providerHealth: { ...route.providerHealth }
|
|
54671
|
+
});
|
|
54672
|
+
seedTimes.set(key(route), Date.parse(route.providerHealth.lastOutcomeAt));
|
|
54673
|
+
}
|
|
54674
|
+
const cancelled = cancelledWorkRunProofs(mission);
|
|
54675
|
+
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) => {
|
|
54676
|
+
const start = Date.parse(run.startedAt);
|
|
54677
|
+
const finish = Date.parse(run.finishedAt ?? "");
|
|
54678
|
+
return Number.isFinite(start) && Number.isFinite(finish) && finish >= start;
|
|
54679
|
+
}).sort((a, b) => Date.parse(a.finishedAt ?? "") - Date.parse(b.finishedAt ?? ""));
|
|
54680
|
+
for (const run of runs) {
|
|
54681
|
+
const outcome = nativeOutcome(run);
|
|
54682
|
+
if (!outcome || !run.finishedAt)
|
|
54683
|
+
continue;
|
|
54684
|
+
const previous = evidence.get(key(run))?.providerHealth;
|
|
54685
|
+
if (Date.parse(run.finishedAt) <= (seedTimes.get(key(run)) ?? -Infinity))
|
|
54686
|
+
continue;
|
|
54687
|
+
const failures = outcome === "failed" ? (previous?.consecutiveFailures ?? 0) + 1 : 0;
|
|
54688
|
+
evidence.set(key(run), {
|
|
54689
|
+
actorType: run.actorType,
|
|
54690
|
+
...run.model ? { model: run.model } : {},
|
|
54691
|
+
providerHealth: {
|
|
54692
|
+
consecutiveFailures: failures,
|
|
54693
|
+
lastOutcomeAt: run.finishedAt,
|
|
54694
|
+
...failures ? { cooldownUntil: new Date(Date.parse(run.finishedAt) + cooldownMs(failures)).toISOString() } : {}
|
|
54695
|
+
}
|
|
54696
|
+
});
|
|
54697
|
+
}
|
|
54698
|
+
return [...evidence.values()];
|
|
54699
|
+
}
|
|
54700
|
+
function actorRouteHealth(mission, requested, now = Date.now()) {
|
|
54701
|
+
const health = aggregateProviderHealth(mission).find((route) => key(route) === key(requested))?.providerHealth;
|
|
54702
|
+
const consecutiveFailures = health?.consecutiveFailures ?? 0;
|
|
54703
|
+
const base = { consecutiveFailures };
|
|
54704
|
+
const runs = (mission.operations?.runs ?? []).filter((run) => healthStages.has(run.stage) && key(run) === key(requested));
|
|
54705
|
+
const uncertain = runs.some((run) => {
|
|
54706
|
+
const start = Date.parse(run.startedAt);
|
|
54707
|
+
const finish = Date.parse(run.finishedAt ?? "");
|
|
54708
|
+
return run.executionState === "unknown" || !Number.isFinite(start) || run.executionState !== "running" && (!Number.isFinite(finish) || finish < start) || run.executionState === "running" && run.finishedAt !== null;
|
|
54709
|
+
});
|
|
54710
|
+
if (!Number.isFinite(now) || uncertain)
|
|
54711
|
+
return {
|
|
54712
|
+
...base,
|
|
54713
|
+
state: "unknown",
|
|
54714
|
+
reason: "Actor execution outcome is uncertain. Reconcile the saved run before retrying."
|
|
54715
|
+
};
|
|
54716
|
+
const active = runs.filter((run) => run.executionState === "running");
|
|
54717
|
+
if (consecutiveFailures && active.length) {
|
|
54718
|
+
const timeout = Math.max(0, mission.timeoutSec) * 1000;
|
|
54719
|
+
const retry = Math.max(now + ACTOR_PROBE_GRACE_MS, ...active.map((run) => Date.parse(run.startedAt) + timeout + ACTOR_PROBE_GRACE_MS));
|
|
54720
|
+
return {
|
|
54721
|
+
...base,
|
|
54722
|
+
state: "probe-in-flight",
|
|
54723
|
+
retryAt: new Date(retry).toISOString(),
|
|
54724
|
+
reason: "An Actor recovery probe is already running. Wait for its terminal result before another probe."
|
|
54725
|
+
};
|
|
54726
|
+
}
|
|
54727
|
+
if (health && consecutiveFailures && now < cooldownUntil(health)) {
|
|
54728
|
+
const retryAt = new Date(cooldownUntil(health)).toISOString();
|
|
54729
|
+
return {
|
|
54730
|
+
...base,
|
|
54731
|
+
state: "cooling",
|
|
54732
|
+
retryAt,
|
|
54733
|
+
reason: `Actor route has ${consecutiveFailures} consecutive execution failures; cooldown ends at ${retryAt}.`
|
|
54734
|
+
};
|
|
54735
|
+
}
|
|
54736
|
+
return {
|
|
54737
|
+
...base,
|
|
54738
|
+
state: "ready",
|
|
54739
|
+
reason: consecutiveFailures ? "Actor cooldown elapsed; allow one recovery probe." : "Actor route has no unresolved execution failure cooldown."
|
|
54740
|
+
};
|
|
54741
|
+
}
|
|
54742
|
+
|
|
54743
|
+
// ../../packages/core/src/chief/actor-availability.ts
|
|
54744
|
+
init_execution();
|
|
54745
|
+
|
|
54746
|
+
class ActorCooldown extends MissionPause {
|
|
54747
|
+
routes;
|
|
54748
|
+
constructor(message, nextRunAt, routes) {
|
|
54749
|
+
super(message, "actor-cooldown", nextRunAt);
|
|
54750
|
+
this.routes = routes;
|
|
54751
|
+
}
|
|
54752
|
+
}
|
|
54753
|
+
function availableActorRoutes(mission, candidates) {
|
|
54754
|
+
const inspected = candidates.map((route) => ({ route, health: actorRouteHealth(mission, route) }));
|
|
54755
|
+
const uncertain = inspected.find((entry) => entry.health.state === "unknown");
|
|
54756
|
+
if (uncertain)
|
|
54757
|
+
throw new MissionPause(uncertain.health.reason, "unknown-effect");
|
|
54758
|
+
const ready = inspected.filter((entry) => entry.health.state === "ready").map((entry) => entry.route);
|
|
54759
|
+
if (ready.length || !candidates.length)
|
|
54760
|
+
return ready;
|
|
54761
|
+
const next = inspected.flatMap(({ health }) => health.retryAt ? [health.retryAt] : []).sort((a, b) => Date.parse(a) - Date.parse(b))[0];
|
|
54762
|
+
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 })));
|
|
54763
|
+
}
|
|
54764
|
+
function refreshActorCooldown(mission, error) {
|
|
54765
|
+
if (!(error instanceof ActorCooldown))
|
|
54766
|
+
return error;
|
|
54767
|
+
try {
|
|
54768
|
+
availableActorRoutes(mission, error.routes);
|
|
54769
|
+
return;
|
|
54770
|
+
} catch (current) {
|
|
54771
|
+
return current;
|
|
54772
|
+
}
|
|
54773
|
+
}
|
|
54774
|
+
function assertActorAvailable(mission, actor, stage) {
|
|
54775
|
+
if (!["work", "review", "gate-review", "final-review"].includes(stage))
|
|
54776
|
+
return;
|
|
54777
|
+
availableActorRoutes(mission, [{ actorType: actor.agentType, model: actor.model }]);
|
|
54778
|
+
}
|
|
54779
|
+
|
|
54473
54780
|
// ../../packages/core/src/chief/bounded-work-routing.ts
|
|
54474
54781
|
import { createHash as createHash13 } from "node:crypto";
|
|
54475
54782
|
function repairDecision(mission, taskId, taskRuns) {
|
|
@@ -54563,7 +54870,7 @@ function routeEvidence(mission) {
|
|
|
54563
54870
|
totalCostUsd: 0,
|
|
54564
54871
|
successfulDeliverableCostUsd: null
|
|
54565
54872
|
};
|
|
54566
|
-
if (!cancelled.has(run.runId))
|
|
54873
|
+
if (!cancelled.has(run.runId) && run.nativeOutcome !== "cancelled")
|
|
54567
54874
|
item.samples += 1;
|
|
54568
54875
|
if (run.outcome === "passed")
|
|
54569
54876
|
item.successes += 1;
|
|
@@ -54571,6 +54878,19 @@ function routeEvidence(mission) {
|
|
|
54571
54878
|
item.successfulDeliverableCostUsd = item.successes && item.totalCostUsd !== null ? item.totalCostUsd / item.successes : null;
|
|
54572
54879
|
evidence.set(key, item);
|
|
54573
54880
|
}
|
|
54881
|
+
for (const health of aggregateProviderHealth(mission)) {
|
|
54882
|
+
if (!health.providerHealth.consecutiveFailures && !evidence.get(routeKey(health))?.providerHealth)
|
|
54883
|
+
continue;
|
|
54884
|
+
const item = evidence.get(routeKey(health)) ?? {
|
|
54885
|
+
actorType: health.actorType,
|
|
54886
|
+
...health.model ? { model: health.model } : {},
|
|
54887
|
+
samples: 0,
|
|
54888
|
+
successes: 0,
|
|
54889
|
+
totalCostUsd: 0,
|
|
54890
|
+
successfulDeliverableCostUsd: null
|
|
54891
|
+
};
|
|
54892
|
+
evidence.set(routeKey(health), { ...item, providerHealth: health.providerHealth });
|
|
54893
|
+
}
|
|
54574
54894
|
return [...evidence.values()];
|
|
54575
54895
|
}
|
|
54576
54896
|
function price2(candidate) {
|
|
@@ -54600,14 +54920,16 @@ function selectWorkActor(mission, actor, taskId, compatibleRoutes) {
|
|
|
54600
54920
|
if (!routing || actor.id === mission.chiefId || !mission.availableAgents && (actor.model || compatibleRoutes)) {
|
|
54601
54921
|
if (compatibleRoutes && !compatibleRoutes.has(routeKey({ actorType: actor.agentType, model: actor.model })))
|
|
54602
54922
|
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.");
|
|
54923
|
+
availableActorRoutes(mission, [{ actorType: actor.agentType, model: actor.model }]);
|
|
54603
54924
|
return { actor, reason: "Preserved the configured Actor and explicit model." };
|
|
54604
54925
|
}
|
|
54605
54926
|
const candidates = readyWorkCandidates(mission);
|
|
54606
54927
|
if (!candidates.length)
|
|
54607
54928
|
throw new Error("No configured work routing candidate is ready. Install/login a candidate CLI or update chief.routing.candidates in av.yaml.");
|
|
54608
|
-
const
|
|
54609
|
-
if (!
|
|
54929
|
+
const compatiblePool = compatibleRoutes ? candidates.filter((candidate) => compatibleRoutes.has(routeKey(candidate))) : candidates;
|
|
54930
|
+
if (!compatiblePool.length)
|
|
54610
54931
|
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.");
|
|
54932
|
+
const compatible = availableActorRoutes(mission, compatiblePool);
|
|
54611
54933
|
const evidence = routeEvidence(mission);
|
|
54612
54934
|
const eligible = compatible.filter((candidate) => {
|
|
54613
54935
|
const observed = evidence.find((item) => routeKey(item) === routeKey(candidate));
|
|
@@ -54617,7 +54939,7 @@ function selectWorkActor(mission, actor, taskId, compatibleRoutes) {
|
|
|
54617
54939
|
const measured = qualified.at(0);
|
|
54618
54940
|
const initial = measured?.candidate ?? [...eligible].sort((a, b) => price2(a) - price2(b)).at(0);
|
|
54619
54941
|
const cancelled = cancelledWorkRunProofs(mission);
|
|
54620
|
-
const taskRuns = (mission.operations?.runs ?? []).filter((run) => run.stage === "work" && run.taskId === taskId && !cancelled.has(run.runId));
|
|
54942
|
+
const taskRuns = (mission.operations?.runs ?? []).filter((run) => run.stage === "work" && run.taskId === taskId && !cancelled.has(run.runId) && run.nativeOutcome !== "cancelled");
|
|
54621
54943
|
if (hasUnreviewedRoutingProbe(mission, taskId, taskRuns))
|
|
54622
54944
|
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.");
|
|
54623
54945
|
const failed = new Set;
|
|
@@ -54709,6 +55031,10 @@ function operationsReportLines(mission) {
|
|
|
54709
55031
|
...evidence.metricAssessments.map((metric) => `${metric.criterion}: ${metric.passed ? "기록된 측정값 기준 통과" : "미충족"}; ${metric.evidence}`),
|
|
54710
55032
|
"비용은 실제 청구액이 아닙니다. 미보고 cache·reasoning·하위 agent token 및 구독 요금은 포함하지 않습니다.",
|
|
54711
55033
|
...evidence.routeQuality.map((route) => `${route.actorType}/${route.model ?? "CLI 기본값"}: 실제 work ${route.samples}회, 독립 리뷰 통과 ${route.successes}회, 성공 산출물당 누적 비용 추정 ${route.successfulDeliverableCostUsd === null ? "미확인" : `USD ${route.successfulDeliverableCostUsd.toFixed(6)}`}`),
|
|
55034
|
+
...evidence.routeQuality.filter((route) => route.providerHealth?.consecutiveFailures).map((route) => {
|
|
55035
|
+
const health = actorRouteHealth(mission, route);
|
|
55036
|
+
return `${route.actorType}/${route.model ?? "CLI 기본값"}: 연속 실행 실패 ${health.consecutiveFailures}회 / 상태 ${health.state} / ${health.retryAt ? `다음 확인 ${health.retryAt}` : "쿨다운 만료, 단일 재시험 가능"}`;
|
|
55037
|
+
}),
|
|
54712
55038
|
...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"}`),
|
|
54713
55039
|
...evidence.crossVendorReviews.map((review) => `${review.taskId}${review.gateId ? ` [${review.gateId}]` : ""}: 작업 ${review.workerActorType} → 리뷰 ${review.reviewerActorType}, ${review.crossVendor ? "다른 vendor" : "동일 vendor fallback"}, 결과 ${review.outcome ?? "배정만 기록"}; ${review.reason}`),
|
|
54714
55040
|
...mission.organizationContext ? [
|
|
@@ -55098,9 +55424,9 @@ function renderReport(mission) {
|
|
|
55098
55424
|
|
|
55099
55425
|
// ../../packages/core/src/chief/store.ts
|
|
55100
55426
|
init_atomic_json();
|
|
55101
|
-
import { constants as
|
|
55102
|
-
import { mkdir as mkdir11, open as open11, readdir as
|
|
55103
|
-
import { join as
|
|
55427
|
+
import { constants as constants10 } from "node:fs";
|
|
55428
|
+
import { mkdir as mkdir11, open as open11, readdir as readdir8, readFile as readFile9 } from "node:fs/promises";
|
|
55429
|
+
import { join as join23 } from "node:path";
|
|
55104
55430
|
init_execution();
|
|
55105
55431
|
|
|
55106
55432
|
// ../../packages/core/src/domain/dag.ts
|
|
@@ -55298,17 +55624,17 @@ function parseSupervisionResponse(source, mission) {
|
|
|
55298
55624
|
init_mission_state_schema();
|
|
55299
55625
|
init_mission_state_schema();
|
|
55300
55626
|
init_zod();
|
|
55301
|
-
import { isAbsolute as
|
|
55627
|
+
import { isAbsolute as isAbsolute11 } from "node:path";
|
|
55302
55628
|
|
|
55303
55629
|
// ../../packages/core/src/chief/capture.ts
|
|
55304
55630
|
import { spawn as spawn7 } from "node:child_process";
|
|
55305
55631
|
import { createHash as createHash14, randomUUID as randomUUID11 } from "node:crypto";
|
|
55306
|
-
import { chmod as chmod4, mkdir as mkdir9, readFile as
|
|
55307
|
-
import { join as
|
|
55632
|
+
import { chmod as chmod4, mkdir as mkdir9, readFile as readFile8, writeFile as writeFile4 } from "node:fs/promises";
|
|
55633
|
+
import { join as join20 } from "node:path";
|
|
55308
55634
|
|
|
55309
55635
|
// ../../packages/core/src/chief/capture-mcp.ts
|
|
55310
|
-
import { readFile as
|
|
55311
|
-
import { join as
|
|
55636
|
+
import { readFile as readFile7 } from "node:fs/promises";
|
|
55637
|
+
import { join as join19 } from "node:path";
|
|
55312
55638
|
|
|
55313
55639
|
// ../../node_modules/.bun/@modelcontextprotocol+client@2.3.0/node_modules/@modelcontextprotocol/client/dist/chunk-Br0eD_fh.mjs
|
|
55314
55640
|
var __create3 = Object.create;
|
|
@@ -69675,7 +70001,7 @@ console.log(${JSON.stringify(prefix)} + JSON.stringify({base64: bytes.toString("
|
|
|
69675
70001
|
async function connectAsideBrowser(repository, policy) {
|
|
69676
70002
|
let config = { command: "aside", args: ["mcp"] };
|
|
69677
70003
|
try {
|
|
69678
|
-
const raw = JSON.parse(await
|
|
70004
|
+
const raw = JSON.parse(await readFile7(join19(repository, ".mcp.json"), "utf8"));
|
|
69679
70005
|
if (raw.mcpServers?.aside)
|
|
69680
70006
|
config = serverSchema.parse(raw.mcpServers.aside);
|
|
69681
70007
|
} catch (error) {
|
|
@@ -69776,7 +70102,7 @@ class MissionCapture {
|
|
|
69776
70102
|
capturePolicySchema.parse(policy);
|
|
69777
70103
|
if (!/^[a-zA-Z0-9][a-zA-Z0-9_-]{0,127}$/.test(missionId))
|
|
69778
70104
|
throw new Error("Use a safe mission ID for capture artifacts.");
|
|
69779
|
-
this.directory =
|
|
70105
|
+
this.directory = join20(repository, ".agent-valley/captures", missionId, randomUUID11());
|
|
69780
70106
|
this.deps = { connect: connectAsideBrowser, encode: encodeCaptureVideo, now: () => new Date, ...deps };
|
|
69781
70107
|
this.startedAt = this.deps.now().toISOString();
|
|
69782
70108
|
}
|
|
@@ -69811,10 +70137,10 @@ class MissionCapture {
|
|
|
69811
70137
|
}, this.policy.intervalMs);
|
|
69812
70138
|
}
|
|
69813
70139
|
async attachment(name, mimeType, bytes) {
|
|
69814
|
-
const path =
|
|
70140
|
+
const path = join20(this.directory, name);
|
|
69815
70141
|
if (bytes)
|
|
69816
70142
|
await writeFile4(path, bytes, { mode: 384 });
|
|
69817
|
-
const contents = bytes ?? await
|
|
70143
|
+
const contents = bytes ?? await readFile8(path);
|
|
69818
70144
|
if (!contents.length || contents.length > 200 * 1024 * 1024)
|
|
69819
70145
|
throw new Error("Capture artifact must contain bytes and be at most 200 MB.");
|
|
69820
70146
|
return {
|
|
@@ -69878,8 +70204,8 @@ duration ${duration}`;
|
|
|
69878
70204
|
`)}
|
|
69879
70205
|
file '${this.frames.at(-1)?.attachment.name}'
|
|
69880
70206
|
`;
|
|
69881
|
-
const manifestPath =
|
|
69882
|
-
const output =
|
|
70207
|
+
const manifestPath = join20(this.directory, "frames.txt");
|
|
70208
|
+
const output = join20(this.directory, "recording.mp4");
|
|
69883
70209
|
await writeFile4(manifestPath, concat, { mode: 384 });
|
|
69884
70210
|
await this.deps.encode(this.directory, manifestPath, output);
|
|
69885
70211
|
await chmod4(output, 384);
|
|
@@ -70162,15 +70488,15 @@ init_metric_source_policy();
|
|
|
70162
70488
|
// ../../packages/core/src/chief/oma-actor.ts
|
|
70163
70489
|
init_dist();
|
|
70164
70490
|
import { createHash as createHash16 } from "node:crypto";
|
|
70165
|
-
import { constants as
|
|
70166
|
-
import { open as open10, readdir as
|
|
70167
|
-
import { isAbsolute as
|
|
70491
|
+
import { constants as constants9 } from "node:fs";
|
|
70492
|
+
import { open as open10, readdir as readdir7, realpath as realpath14, stat as stat4 } from "node:fs/promises";
|
|
70493
|
+
import { isAbsolute as isAbsolute10, join as join22, relative as relative10, sep as sep10 } from "node:path";
|
|
70168
70494
|
|
|
70169
70495
|
// ../../packages/core/src/chief/skills.ts
|
|
70170
70496
|
init_dist();
|
|
70171
|
-
import { constants as
|
|
70172
|
-
import { lstat as
|
|
70173
|
-
import { isAbsolute as
|
|
70497
|
+
import { constants as constants8 } from "node:fs";
|
|
70498
|
+
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";
|
|
70499
|
+
import { isAbsolute as isAbsolute9, join as join21, relative as relative9, sep as sep9 } from "node:path";
|
|
70174
70500
|
var MAX_SKILL_BYTES = 256000;
|
|
70175
70501
|
var MAX_METADATA_BYTES = 16384;
|
|
70176
70502
|
var MAX_CATALOG_SIZE = 100;
|
|
@@ -70180,7 +70506,7 @@ var SKILL_NAME = /^[a-z0-9][a-z0-9-]{0,127}$/;
|
|
|
70180
70506
|
var OMA_SKILL_NAME = /^oma-[a-z0-9][a-z0-9-]{0,123}$/;
|
|
70181
70507
|
function inside(root, path) {
|
|
70182
70508
|
const child = relative9(root, path);
|
|
70183
|
-
return child !== "" && child !== ".." && !child.startsWith(`..${sep9}`) && !
|
|
70509
|
+
return child !== "" && child !== ".." && !child.startsWith(`..${sep9}`) && !isAbsolute9(child);
|
|
70184
70510
|
}
|
|
70185
70511
|
function excludedResource(name) {
|
|
70186
70512
|
return [
|
|
@@ -70208,7 +70534,7 @@ async function prepareMissionSkills(sourceRepositoryPath, workspacePath) {
|
|
|
70208
70534
|
if (!sources.length)
|
|
70209
70535
|
return;
|
|
70210
70536
|
const workspace = await realpath13(workspacePath);
|
|
70211
|
-
const agents =
|
|
70537
|
+
const agents = join21(workspace, ".agents");
|
|
70212
70538
|
await mkdir10(agents, { recursive: true });
|
|
70213
70539
|
if (!inside(workspace, await realpath13(agents)))
|
|
70214
70540
|
throw new Error("The target .agents directory escapes the mission worktree. Fix its symlink before creating this order.");
|
|
@@ -70219,19 +70545,19 @@ async function prepareMissionSkills(sourceRepositoryPath, workspacePath) {
|
|
|
70219
70545
|
if (seen.has(sourceDirectory))
|
|
70220
70546
|
return;
|
|
70221
70547
|
seen.add(sourceDirectory);
|
|
70222
|
-
for (const name of (await
|
|
70548
|
+
for (const name of (await readdir6(sourceDirectory)).sort()) {
|
|
70223
70549
|
if (excludedResource(name))
|
|
70224
70550
|
continue;
|
|
70225
70551
|
if (++entries > MAX_HARNESS_ENTRIES)
|
|
70226
70552
|
throw new Error("The installed harness resources exceed 5,000 entries. Remove unused resources before creating this order.");
|
|
70227
|
-
const from = await realpath13(
|
|
70553
|
+
const from = await realpath13(join21(sourceDirectory, name)).catch(() => {
|
|
70228
70554
|
return;
|
|
70229
70555
|
});
|
|
70230
70556
|
if (!from || !inside(sourceRoot, from))
|
|
70231
70557
|
continue;
|
|
70232
|
-
const info = await
|
|
70233
|
-
const to =
|
|
70234
|
-
const existing = await
|
|
70558
|
+
const info = await stat3(from);
|
|
70559
|
+
const to = join21(targetDirectory, name);
|
|
70560
|
+
const existing = await lstat11(to).catch(() => {
|
|
70235
70561
|
return;
|
|
70236
70562
|
});
|
|
70237
70563
|
if (info.isDirectory()) {
|
|
@@ -70246,7 +70572,7 @@ async function prepareMissionSkills(sourceRepositoryPath, workspacePath) {
|
|
|
70246
70572
|
const parent = await realpath13(targetDirectory);
|
|
70247
70573
|
if (parent !== destinationRoot && !inside(destinationRoot, parent))
|
|
70248
70574
|
throw new Error("A target harness resource escapes the mission worktree. Fix its symlink before creating this order.");
|
|
70249
|
-
const file = await open9(from,
|
|
70575
|
+
const file = await open9(from, constants8.O_RDONLY | constants8.O_NOFOLLOW | constants8.O_NONBLOCK);
|
|
70250
70576
|
try {
|
|
70251
70577
|
const current = await file.stat();
|
|
70252
70578
|
if (!current.isFile())
|
|
@@ -70278,7 +70604,7 @@ async function prepareMissionSkills(sourceRepositoryPath, workspacePath) {
|
|
|
70278
70604
|
seen.delete(sourceDirectory);
|
|
70279
70605
|
}
|
|
70280
70606
|
for (const source of sources) {
|
|
70281
|
-
await mkdir10(
|
|
70607
|
+
await mkdir10(join21(agents, source.name), { recursive: true });
|
|
70282
70608
|
const targetRoot = await harnessResourceRoot(workspace, source.name);
|
|
70283
70609
|
if (!targetRoot)
|
|
70284
70610
|
throw new Error(`Cannot prepare .agents/${source.name} in the mission worktree. Restore that directory.`);
|
|
@@ -70295,21 +70621,21 @@ async function harnessResourceRoot(workspacePath, name) {
|
|
|
70295
70621
|
});
|
|
70296
70622
|
if (!workspace)
|
|
70297
70623
|
return;
|
|
70298
|
-
const root = await realpath13(
|
|
70624
|
+
const root = await realpath13(join21(workspace, ".agents", name)).catch(() => {
|
|
70299
70625
|
return;
|
|
70300
70626
|
});
|
|
70301
70627
|
if (!root)
|
|
70302
70628
|
return;
|
|
70303
70629
|
if (!inside(workspace, root))
|
|
70304
70630
|
throw new Error(`The ${name === "skills" ? "skill" : "agent"} directory escapes the mission worktree. Install the OMA harness inside this repository.`);
|
|
70305
|
-
if (!(await
|
|
70631
|
+
if (!(await stat3(root)).isDirectory())
|
|
70306
70632
|
return;
|
|
70307
70633
|
return root;
|
|
70308
70634
|
}
|
|
70309
70635
|
async function skillPath(root, name) {
|
|
70310
70636
|
if (!SKILL_NAME.test(name))
|
|
70311
70637
|
throw new Error(`Invalid skill name: ${name}. Select an installed skill directory name.`);
|
|
70312
|
-
const path = await realpath13(
|
|
70638
|
+
const path = await realpath13(join21(root, name, "SKILL.md")).catch(() => {
|
|
70313
70639
|
throw new Error(`Skill ${name}/SKILL.md is missing. Restore that installed skill in ${root} before resuming.`);
|
|
70314
70640
|
});
|
|
70315
70641
|
if (!inside(root, path))
|
|
@@ -70317,7 +70643,7 @@ async function skillPath(root, name) {
|
|
|
70317
70643
|
return path;
|
|
70318
70644
|
}
|
|
70319
70645
|
async function readSkill(path, metadataOnly) {
|
|
70320
|
-
const file = await open9(path,
|
|
70646
|
+
const file = await open9(path, constants8.O_RDONLY | constants8.O_NOFOLLOW | constants8.O_NONBLOCK);
|
|
70321
70647
|
try {
|
|
70322
70648
|
const info = await file.stat();
|
|
70323
70649
|
if (!info.isFile())
|
|
@@ -70365,8 +70691,8 @@ function metadata2(source, name, path) {
|
|
|
70365
70691
|
async function descriptor(root, name) {
|
|
70366
70692
|
if (!OMA_SKILL_NAME.test(name))
|
|
70367
70693
|
return;
|
|
70368
|
-
const directory = await realpath13(
|
|
70369
|
-
if (!inside(root, directory) || !(await
|
|
70694
|
+
const directory = await realpath13(join21(root, name));
|
|
70695
|
+
if (!inside(root, directory) || !(await stat3(directory)).isDirectory())
|
|
70370
70696
|
return;
|
|
70371
70697
|
const path = await skillPath(root, name);
|
|
70372
70698
|
return metadata2(await readSkill(path, true), name, path);
|
|
@@ -70377,7 +70703,7 @@ async function discoverMissionSkills(workspacePath) {
|
|
|
70377
70703
|
});
|
|
70378
70704
|
if (!root)
|
|
70379
70705
|
return [];
|
|
70380
|
-
const entries = await
|
|
70706
|
+
const entries = await readdir6(root).catch(() => []);
|
|
70381
70707
|
const catalog = [];
|
|
70382
70708
|
for (const name of entries.sort()) {
|
|
70383
70709
|
const skill = await descriptor(root, name).catch(() => {
|
|
@@ -70465,7 +70791,7 @@ var MAX_GUIDANCE_BYTES = 256000;
|
|
|
70465
70791
|
var MAX_PROFILES = 100;
|
|
70466
70792
|
function inside2(root, path) {
|
|
70467
70793
|
const child = relative10(root, path);
|
|
70468
|
-
return child !== "" && child !== ".." && !child.startsWith(`..${sep10}`) && !
|
|
70794
|
+
return child !== "" && child !== ".." && !child.startsWith(`..${sep10}`) && !isAbsolute10(child);
|
|
70469
70795
|
}
|
|
70470
70796
|
function invalidProfile(path) {
|
|
70471
70797
|
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.`);
|
|
@@ -70491,7 +70817,7 @@ function profileSkills(source, agentId, path) {
|
|
|
70491
70817
|
}
|
|
70492
70818
|
async function readProfile(root, filename) {
|
|
70493
70819
|
const agentId = filename.slice(0, -3);
|
|
70494
|
-
const requested =
|
|
70820
|
+
const requested = join22(root, filename);
|
|
70495
70821
|
if (!NAME.test(agentId))
|
|
70496
70822
|
throw invalidProfile(requested);
|
|
70497
70823
|
const path = await realpath14(requested).catch(() => {
|
|
@@ -70499,7 +70825,7 @@ async function readProfile(root, filename) {
|
|
|
70499
70825
|
});
|
|
70500
70826
|
if (!inside2(root, path))
|
|
70501
70827
|
throw new Error(`OMA agent profile ${requested} escapes .agents/agents. Fix its symlink before resuming.`);
|
|
70502
|
-
const file = await open10(path,
|
|
70828
|
+
const file = await open10(path, constants9.O_RDONLY | constants9.O_NOFOLLOW | constants9.O_NONBLOCK).catch(() => {
|
|
70503
70829
|
throw new Error(`OMA agent profile ${requested} is unreadable. Restore its file permissions before resuming.`);
|
|
70504
70830
|
});
|
|
70505
70831
|
try {
|
|
@@ -70532,15 +70858,15 @@ async function prepareOmaActor(workspacePath, selectedSkills) {
|
|
|
70532
70858
|
throw new Error(`Invalid skill name: ${name}. Select an installed skill directory name.`);
|
|
70533
70859
|
const selected = [...new Set(selectedSkills)].sort();
|
|
70534
70860
|
const workspace = await realpath14(workspacePath);
|
|
70535
|
-
const directory =
|
|
70861
|
+
const directory = join22(workspace, ".agents", "agents");
|
|
70536
70862
|
const root = await realpath14(directory).catch(() => {
|
|
70537
70863
|
throw new Error(`OMA work requires installed agent profiles in ${directory}. Install the OMA harness before resuming.`);
|
|
70538
70864
|
});
|
|
70539
70865
|
if (!inside2(workspace, root))
|
|
70540
70866
|
throw new Error("The OMA agent directory escapes the mission worktree. Install .agents/agents inside this repository.");
|
|
70541
|
-
if (!(await
|
|
70867
|
+
if (!(await stat4(root)).isDirectory())
|
|
70542
70868
|
throw new Error(`OMA agent profiles require a directory at ${directory}. Restore the installed OMA harness.`);
|
|
70543
|
-
const filenames = (await
|
|
70869
|
+
const filenames = (await readdir7(root)).filter((name) => name.endsWith(".md")).sort();
|
|
70544
70870
|
if (filenames.length > MAX_PROFILES)
|
|
70545
70871
|
throw new Error("The worktree has more than 100 OMA agent profiles. Remove unused profiles before resuming.");
|
|
70546
70872
|
let chosen;
|
|
@@ -70593,14 +70919,14 @@ var goalBriefSchema = strictObject({
|
|
|
70593
70919
|
var skillDescriptorSchema = strictObject({
|
|
70594
70920
|
name: string2().regex(/^oma-[a-z0-9][a-z0-9-]{0,123}$/),
|
|
70595
70921
|
description: string2().trim().min(1).max(1000),
|
|
70596
|
-
path: text9.refine(
|
|
70922
|
+
path: text9.refine(isAbsolute11, "Skill paths must be absolute verified SKILL.md paths.")
|
|
70597
70923
|
});
|
|
70598
70924
|
var planSchema = strictObject({
|
|
70599
70925
|
tasks: array(actorTaskSchema).min(1).max(12)
|
|
70600
70926
|
});
|
|
70601
70927
|
var missionSchema = strictObject({
|
|
70602
70928
|
id: id5,
|
|
70603
|
-
repositoryRoot: text9.refine(
|
|
70929
|
+
repositoryRoot: text9.refine(isAbsolute11, "Original repository root must be absolute.").optional(),
|
|
70604
70930
|
toolEnvKeys: toolEnvKeysSchema.optional(),
|
|
70605
70931
|
goal: text9,
|
|
70606
70932
|
chiefId: id5,
|
|
@@ -70885,7 +71211,7 @@ class MissionStore {
|
|
|
70885
71211
|
const path = `${this.path(id)}.lock`;
|
|
70886
71212
|
let file;
|
|
70887
71213
|
try {
|
|
70888
|
-
file = await open11(path,
|
|
71214
|
+
file = await open11(path, constants10.O_RDONLY | (constants10.O_NOFOLLOW ?? 0) | (constants10.O_NONBLOCK ?? 0));
|
|
70889
71215
|
const stat = await file.stat();
|
|
70890
71216
|
if (!stat.isFile() || stat.size < 1 || stat.size > 1024)
|
|
70891
71217
|
return true;
|
|
@@ -70914,7 +71240,7 @@ class MissionStore {
|
|
|
70914
71240
|
this.path(id);
|
|
70915
71241
|
if (mission && mission.id !== id)
|
|
70916
71242
|
throw new Error("Process recovery mission identity differs from its record. Restore the matching checkpoint.");
|
|
70917
|
-
const names = await
|
|
71243
|
+
const names = await readdir8(this.directory);
|
|
70918
71244
|
for (const name of names) {
|
|
70919
71245
|
if (name === `${id}.active`)
|
|
70920
71246
|
await this.processGuard(id).recoverOrphan();
|
|
@@ -70932,7 +71258,7 @@ class MissionStore {
|
|
|
70932
71258
|
path(id) {
|
|
70933
71259
|
if (!/^[a-zA-Z0-9][a-zA-Z0-9-]{0,79}$/.test(id))
|
|
70934
71260
|
throw new Error("Invalid mission ID. Use the ID printed by av order.");
|
|
70935
|
-
return
|
|
71261
|
+
return join23(this.directory, `${id}.json`);
|
|
70936
71262
|
}
|
|
70937
71263
|
save(mission) {
|
|
70938
71264
|
const write = this.writes.then(() => this.persist(mission));
|
|
@@ -70946,7 +71272,7 @@ class MissionStore {
|
|
|
70946
71272
|
await writeJsonAtomic(path, { version: 1, mission });
|
|
70947
71273
|
}
|
|
70948
71274
|
async load(id) {
|
|
70949
|
-
const content = JSON.parse(await
|
|
71275
|
+
const content = JSON.parse(await readFile9(this.path(id), "utf8"));
|
|
70950
71276
|
if (content.version !== 1)
|
|
70951
71277
|
throw new Error("Unsupported mission record version. Use the Agent Valley version that created this mission.");
|
|
70952
71278
|
const mission = missionSchema.parse(content.mission);
|
|
@@ -70957,7 +71283,7 @@ class MissionStore {
|
|
|
70957
71283
|
async list() {
|
|
70958
71284
|
let names;
|
|
70959
71285
|
try {
|
|
70960
|
-
names = await
|
|
71286
|
+
names = await readdir8(this.directory);
|
|
70961
71287
|
} catch (error) {
|
|
70962
71288
|
if (error.code === "ENOENT")
|
|
70963
71289
|
return [];
|
|
@@ -70974,7 +71300,7 @@ class MissionStore {
|
|
|
70974
71300
|
init_yaml_loader();
|
|
70975
71301
|
|
|
70976
71302
|
// src/chief-config.ts
|
|
70977
|
-
import { isAbsolute as
|
|
71303
|
+
import { isAbsolute as isAbsolute12, resolve as resolve18 } from "node:path";
|
|
70978
71304
|
|
|
70979
71305
|
// ../../packages/core/src/chief/advisory-evidence.ts
|
|
70980
71306
|
function unavailableDirectorAdvice(mission) {
|
|
@@ -71292,7 +71618,7 @@ async function resolveOrderConfig(root, options, discover = discoverAgents) {
|
|
|
71292
71618
|
const global2 = loadGlobalConfig();
|
|
71293
71619
|
const chiefConfig = mergeChiefConfig(global2?.chief, project?.chief);
|
|
71294
71620
|
const workspace = options.workspace ?? project?.workspace?.root;
|
|
71295
|
-
if (!workspace || !
|
|
71621
|
+
if (!workspace || !isAbsolute12(workspace))
|
|
71296
71622
|
throw new Error("Set --workspace to an absolute Git repository path, or set workspace.root in av.yaml.");
|
|
71297
71623
|
const verifyCommand = options.verify ?? project?.verify?.command ?? "";
|
|
71298
71624
|
if (actorOption !== undefined && !agents.has(actorOption))
|
|
@@ -71404,6 +71730,22 @@ ${details}` : ""}`);
|
|
|
71404
71730
|
|
|
71405
71731
|
// ../../packages/core/src/chief/continuous-recovery.ts
|
|
71406
71732
|
init_execution();
|
|
71733
|
+
|
|
71734
|
+
// ../../packages/core/src/chief/scheduled-wait.ts
|
|
71735
|
+
function hasSchedule(mission) {
|
|
71736
|
+
return mission.status === "waiting" && Number.isFinite(Date.parse(mission.execution?.nextRunAt ?? ""));
|
|
71737
|
+
}
|
|
71738
|
+
function scheduledChiefWait(mission) {
|
|
71739
|
+
return hasSchedule(mission) && mission.execution?.failureKind === "chief-wait" && mission.supervision?.decisions.at(-1)?.action === "wait";
|
|
71740
|
+
}
|
|
71741
|
+
function scheduledActorCooldown(mission) {
|
|
71742
|
+
return hasSchedule(mission) && mission.execution?.failureKind === "actor-cooldown";
|
|
71743
|
+
}
|
|
71744
|
+
function scheduledMissionWait(mission) {
|
|
71745
|
+
return scheduledChiefWait(mission) || scheduledActorCooldown(mission);
|
|
71746
|
+
}
|
|
71747
|
+
|
|
71748
|
+
// ../../packages/core/src/chief/continuous-recovery.ts
|
|
71407
71749
|
function verifiedMissionEvidence(mission) {
|
|
71408
71750
|
const plan = mission.plan;
|
|
71409
71751
|
const review = mission.finalReview;
|
|
@@ -71418,9 +71760,6 @@ function verifiedMissionEvidence(mission) {
|
|
|
71418
71760
|
return false;
|
|
71419
71761
|
}
|
|
71420
71762
|
}
|
|
71421
|
-
function scheduledChiefWait(mission) {
|
|
71422
|
-
return mission.status === "waiting" && mission.execution?.failureKind === "chief-wait" && mission.supervision?.decisions.at(-1)?.action === "wait" && Number.isFinite(Date.parse(mission.execution.nextRunAt ?? ""));
|
|
71423
|
-
}
|
|
71424
71763
|
function automaticMissionRecovery(mission, now = Date.now(), context = {}) {
|
|
71425
71764
|
const stop = (reason) => ({ retry: false, reason });
|
|
71426
71765
|
if (!mission.executionPolicy?.autoResume)
|
|
@@ -71457,6 +71796,12 @@ function automaticMissionRecovery(mission, now = Date.now(), context = {}) {
|
|
|
71457
71796
|
return stop(error.message);
|
|
71458
71797
|
throw error;
|
|
71459
71798
|
}
|
|
71799
|
+
if (scheduledActorCooldown(mission))
|
|
71800
|
+
return {
|
|
71801
|
+
retry: true,
|
|
71802
|
+
reason: state?.pauseReason ?? "Continue the saved Actor cooldown without another Chief recovery decision.",
|
|
71803
|
+
waitUntil: state?.nextRunAt
|
|
71804
|
+
};
|
|
71460
71805
|
const supervision = mission.supervision;
|
|
71461
71806
|
if (supervision && (supervision.rounds >= supervision.maxRounds || supervision.stalledRounds >= 3))
|
|
71462
71807
|
return stop("The Chief exhausted its saved recovery rounds; the goal remains unresolved.");
|
|
@@ -71489,12 +71834,12 @@ init_execution();
|
|
|
71489
71834
|
|
|
71490
71835
|
// src/chief-delivery-resume.ts
|
|
71491
71836
|
import { realpath as realpath17 } from "node:fs/promises";
|
|
71492
|
-
import { join as
|
|
71837
|
+
import { join as join29 } from "node:path";
|
|
71493
71838
|
|
|
71494
71839
|
// src/chief-code-delivery.ts
|
|
71495
71840
|
import { createHash as createHash18, randomUUID as randomUUID12 } from "node:crypto";
|
|
71496
|
-
import { lstat as
|
|
71497
|
-
import { join as
|
|
71841
|
+
import { lstat as lstat13, mkdir as mkdir12, readFile as readFile10, realpath as realpath16, writeFile as writeFile7 } from "node:fs/promises";
|
|
71842
|
+
import { join as join28, resolve as resolve20 } from "node:path";
|
|
71498
71843
|
init_execution();
|
|
71499
71844
|
|
|
71500
71845
|
// ../../packages/core/src/chief/execution-signal.ts
|
|
@@ -71588,8 +71933,8 @@ function recordServiceShutdown(mission, unconfirmedTermination) {
|
|
|
71588
71933
|
// src/chief-code-delivery-git.ts
|
|
71589
71934
|
import { execFile as execFile2 } from "node:child_process";
|
|
71590
71935
|
import { createHash as createHash17 } from "node:crypto";
|
|
71591
|
-
import { lstat as
|
|
71592
|
-
import { isAbsolute as
|
|
71936
|
+
import { lstat as lstat12, mkdtemp, realpath as realpath15, rm as rm3, writeFile as writeFile6 } from "node:fs/promises";
|
|
71937
|
+
import { isAbsolute as isAbsolute13, join as join27, relative as relative11, resolve as resolve19, sep as sep11 } from "node:path";
|
|
71593
71938
|
import { promisify as promisify2 } from "node:util";
|
|
71594
71939
|
init_git_environment();
|
|
71595
71940
|
init_worktree_lifecycle();
|
|
@@ -71612,9 +71957,9 @@ function shellQuote(value) {
|
|
|
71612
71957
|
return `'${value.replace(/'/g, "'\\''")}'`;
|
|
71613
71958
|
}
|
|
71614
71959
|
async function canonicalDirectory(path, description) {
|
|
71615
|
-
if (!
|
|
71960
|
+
if (!isAbsolute13(path))
|
|
71616
71961
|
throw new Error(`Use an absolute ${description} path before preparing code delivery.`);
|
|
71617
|
-
const entry = await
|
|
71962
|
+
const entry = await lstat12(path);
|
|
71618
71963
|
if (entry.isSymbolicLink() || !entry.isDirectory())
|
|
71619
71964
|
throw new Error(`The ${description} must be a real directory. Restore its original location before retrying.`);
|
|
71620
71965
|
return realpath15(path);
|
|
@@ -71624,13 +71969,13 @@ async function inspectProductPath(workspace, path) {
|
|
|
71624
71969
|
throw new Error(`Code delivery path ${JSON.stringify(path)} is private or invalid. Select an exact product file.`);
|
|
71625
71970
|
const destination = resolve19(workspace, path);
|
|
71626
71971
|
const within = relative11(workspace, destination);
|
|
71627
|
-
if (!within || within === ".." || within.startsWith(`..${sep11}`) ||
|
|
71972
|
+
if (!within || within === ".." || within.startsWith(`..${sep11}`) || isAbsolute13(within))
|
|
71628
71973
|
throw new Error("Code delivery escaped its source workspace. Restore the pinned product paths before retrying.");
|
|
71629
71974
|
const parts = path.split("/");
|
|
71630
71975
|
let current = workspace;
|
|
71631
71976
|
for (let index = 0;index < parts.length; index += 1) {
|
|
71632
|
-
current =
|
|
71633
|
-
const entry = await
|
|
71977
|
+
current = join27(current, parts[index] ?? "");
|
|
71978
|
+
const entry = await lstat12(current).catch((error) => {
|
|
71634
71979
|
if (error.code === "ENOENT")
|
|
71635
71980
|
return;
|
|
71636
71981
|
throw error;
|
|
@@ -71674,9 +72019,9 @@ async function prepareDeliveryPatch(workspace, baseSha, allowedPaths, directory)
|
|
|
71674
72019
|
throw new Error(`Changed path ${JSON.stringify(path)} is outside code delivery scope. Reconcile the exact allowlist.`);
|
|
71675
72020
|
await inspectProductPath(workspace, path);
|
|
71676
72021
|
}
|
|
71677
|
-
const temporary = await mkdtemp(
|
|
71678
|
-
const indexPath =
|
|
71679
|
-
const patchPath =
|
|
72022
|
+
const temporary = await mkdtemp(join27(directory, "patch-"));
|
|
72023
|
+
const indexPath = join27(temporary, "index");
|
|
72024
|
+
const patchPath = join27(temporary, "delivery.patch");
|
|
71680
72025
|
const env = { GIT_INDEX_FILE: indexPath };
|
|
71681
72026
|
try {
|
|
71682
72027
|
await gitRead(workspace, ["read-tree", baseSha], env);
|
|
@@ -71728,8 +72073,8 @@ async function artifact(path, content) {
|
|
|
71728
72073
|
} catch (error) {
|
|
71729
72074
|
if (error.code !== "EEXIST")
|
|
71730
72075
|
throw error;
|
|
71731
|
-
const entry = await
|
|
71732
|
-
if (!entry.isFile() || entry.isSymbolicLink() || !Buffer.from(content).equals(await
|
|
72076
|
+
const entry = await lstat13(path);
|
|
72077
|
+
if (!entry.isFile() || entry.isSymbolicLink() || !Buffer.from(content).equals(await readFile10(path)))
|
|
71733
72078
|
throw new DeliveryBlocked("Private delivery artifact changed. Restore its original bytes before resuming.");
|
|
71734
72079
|
}
|
|
71735
72080
|
}
|
|
@@ -71763,9 +72108,9 @@ async function privateDirectory(root, id) {
|
|
|
71763
72108
|
throw new DeliveryBlocked("Restore the original Mission identity before delivery.");
|
|
71764
72109
|
let current = root;
|
|
71765
72110
|
for (const part of [".agent-valley", "code-delivery", id]) {
|
|
71766
|
-
current =
|
|
72111
|
+
current = join28(current, part);
|
|
71767
72112
|
await mkdir12(current, { recursive: true, mode: 448 });
|
|
71768
|
-
const stat = await
|
|
72113
|
+
const stat = await lstat13(current);
|
|
71769
72114
|
if (!stat.isDirectory() || stat.isSymbolicLink() || await realpath16(current) !== current)
|
|
71770
72115
|
throw new DeliveryBlocked("Code delivery storage redirects through a symlink. Restore its private local directory.");
|
|
71771
72116
|
}
|
|
@@ -71871,10 +72216,10 @@ async function deliverMissionCode(mission, store, signal) {
|
|
|
71871
72216
|
throw new DeliveryBlocked("Restore the saved source repository identity before delivery.");
|
|
71872
72217
|
const root = await repositoryRoot(mission.repositoryRoot);
|
|
71873
72218
|
const gitDirectory = await realpath16(resolve20(root, (await gitRead(root, ["rev-parse", "--git-common-dir"])).trim()));
|
|
71874
|
-
unlock = await lockRecord(
|
|
72219
|
+
unlock = await lockRecord(join28(gitDirectory, "agent-valley-delivery.lock"), "Code delivery", "code-delivery");
|
|
71875
72220
|
await assertTarget(root, delivery);
|
|
71876
72221
|
const directory = await privateDirectory(root, mission.id);
|
|
71877
|
-
const patchPath =
|
|
72222
|
+
const patchPath = join28(directory, "changes.patch");
|
|
71878
72223
|
if (delivery.phase === "pending") {
|
|
71879
72224
|
if ((await gitRead(root, ["rev-parse", "HEAD"])).trim() !== delivery.policy.baseSha || !await clean(root))
|
|
71880
72225
|
throw new DeliveryBlocked("Source HEAD or its clean index changed since delivery was authorized. Preserve edits and restore the pinned source before resuming.");
|
|
@@ -71893,7 +72238,7 @@ async function deliverMissionCode(mission, store, signal) {
|
|
|
71893
72238
|
await save();
|
|
71894
72239
|
return;
|
|
71895
72240
|
}
|
|
71896
|
-
await artifact(patchPath, await
|
|
72241
|
+
await artifact(patchPath, await readFile10(prepared.patchPath));
|
|
71897
72242
|
delivery.treeSha = prepared.treeSha;
|
|
71898
72243
|
delivery.patchSha256 = prepared.patchSha256;
|
|
71899
72244
|
delivery.verifiedFingerprint = mission.fingerprint;
|
|
@@ -71903,7 +72248,7 @@ async function deliverMissionCode(mission, store, signal) {
|
|
|
71903
72248
|
}
|
|
71904
72249
|
if (!delivery.nonce || delivery.verifiedFingerprint !== mission.fingerprint)
|
|
71905
72250
|
throw new DeliveryBlocked("Restore the prepared delivery nonce and verified fingerprint before resuming.");
|
|
71906
|
-
if (createHash18("sha256").update(await
|
|
72251
|
+
if (createHash18("sha256").update(await readFile10(patchPath)).digest("hex") !== delivery.patchSha256)
|
|
71907
72252
|
throw new DeliveryBlocked("Prepared patch bytes changed. Preserve the delivery record and restore its original patch.");
|
|
71908
72253
|
const message = `${delivery.policy.message}
|
|
71909
72254
|
|
|
@@ -71950,7 +72295,7 @@ AV-Delivery: ${delivery.nonce}
|
|
|
71950
72295
|
if ((await gitRead(root, ["write-tree"])).trim() !== delivery.treeSha)
|
|
71951
72296
|
throw new DeliveryBlocked("Staged delivery differs from its verified tree. Preserve the index for inspection.");
|
|
71952
72297
|
assertLive(mission, signal);
|
|
71953
|
-
const messagePath =
|
|
72298
|
+
const messagePath = join28(directory, "commit-message.txt");
|
|
71954
72299
|
await artifact(messagePath, message);
|
|
71955
72300
|
await managedGit(mission, store, root, ["commit", "--file", messagePath], signal);
|
|
71956
72301
|
delivery.commitSha = await committedHead(root, delivery, message);
|
|
@@ -72092,7 +72437,7 @@ async function enableOperationDelivery(operation, options, root, save, onEnable)
|
|
|
72092
72437
|
let unlock;
|
|
72093
72438
|
try {
|
|
72094
72439
|
if (operation.currentMissionId) {
|
|
72095
|
-
const missions = new MissionStore(
|
|
72440
|
+
const missions = new MissionStore(join29(root, ".agent-valley", "missions"));
|
|
72096
72441
|
unlock = await missions.lock(operation.currentMissionId);
|
|
72097
72442
|
const child = await missions.load(operation.currentMissionId);
|
|
72098
72443
|
if (child.repositoryRoot !== operation.repositoryRoot || child.goal !== (operation.decision?.action === "execute" ? operation.decision.goal : undefined))
|
|
@@ -72181,8 +72526,6 @@ function applyResumeOptions(mission, goal, options) {
|
|
|
72181
72526
|
if (changed) {
|
|
72182
72527
|
const state = executionState(mission);
|
|
72183
72528
|
state.interventionAt = new Date().toISOString();
|
|
72184
|
-
state.retries = 0;
|
|
72185
|
-
state.crashRestarts = 0;
|
|
72186
72529
|
delete state.pauseReason;
|
|
72187
72530
|
delete state.nextRunAt;
|
|
72188
72531
|
delete state.failureKind;
|
|
@@ -72209,8 +72552,8 @@ function applyResumeOptions(mission, goal, options) {
|
|
|
72209
72552
|
|
|
72210
72553
|
// src/mission-jobs.ts
|
|
72211
72554
|
import { createHash as createHash19 } from "node:crypto";
|
|
72212
|
-
import { lstat as
|
|
72213
|
-
import { join as
|
|
72555
|
+
import { lstat as lstat14, mkdir as mkdir13, readdir as readdir9, readFile as readFile11 } from "node:fs/promises";
|
|
72556
|
+
import { join as join30 } from "node:path";
|
|
72214
72557
|
init_atomic_json();
|
|
72215
72558
|
init_runtime_ignore();
|
|
72216
72559
|
init_zod();
|
|
@@ -72244,12 +72587,12 @@ function jobLiveness(job) {
|
|
|
72244
72587
|
async function ensureAvDirectory(root, parts) {
|
|
72245
72588
|
let path = root;
|
|
72246
72589
|
for (const part of [".agent-valley", ...parts]) {
|
|
72247
|
-
path =
|
|
72590
|
+
path = join30(path, part);
|
|
72248
72591
|
await mkdir13(path, { mode: 448 }).catch((error) => {
|
|
72249
72592
|
if (error.code !== "EEXIST")
|
|
72250
72593
|
throw error;
|
|
72251
72594
|
});
|
|
72252
|
-
const stat = await
|
|
72595
|
+
const stat = await lstat14(path);
|
|
72253
72596
|
if (!stat.isDirectory() || stat.isSymbolicLink())
|
|
72254
72597
|
throw new Error(`AV control directory must be a real directory: ${path}. Remove the symlink before retrying.`);
|
|
72255
72598
|
}
|
|
@@ -72263,7 +72606,7 @@ class MissionJobs {
|
|
|
72263
72606
|
constructor(root, directoryName = "jobs") {
|
|
72264
72607
|
this.root = root;
|
|
72265
72608
|
this.directoryName = directoryName;
|
|
72266
|
-
this.directory =
|
|
72609
|
+
this.directory = join30(root, ".agent-valley/control", directoryName);
|
|
72267
72610
|
}
|
|
72268
72611
|
async locked(operation) {
|
|
72269
72612
|
await ensureRuntimeGitignore(this.root);
|
|
@@ -72279,9 +72622,9 @@ class MissionJobs {
|
|
|
72279
72622
|
await ensureAvDirectory(this.root, ["control", this.directoryName]);
|
|
72280
72623
|
try {
|
|
72281
72624
|
const path = this.path(requestId);
|
|
72282
|
-
if ((await
|
|
72625
|
+
if ((await lstat14(path)).isSymbolicLink())
|
|
72283
72626
|
throw new Error("AV launch receipt cannot be a symlink.");
|
|
72284
|
-
return jobSchema.parse(JSON.parse(await
|
|
72627
|
+
return jobSchema.parse(JSON.parse(await readFile11(path, "utf8")));
|
|
72285
72628
|
} catch (error) {
|
|
72286
72629
|
if (error.code === "ENOENT")
|
|
72287
72630
|
return;
|
|
@@ -72292,16 +72635,16 @@ class MissionJobs {
|
|
|
72292
72635
|
}
|
|
72293
72636
|
async list() {
|
|
72294
72637
|
await ensureAvDirectory(this.root, ["control", this.directoryName]);
|
|
72295
|
-
const files = await
|
|
72638
|
+
const files = await readdir9(this.directory).catch((error) => {
|
|
72296
72639
|
if (error.code === "ENOENT")
|
|
72297
72640
|
return [];
|
|
72298
72641
|
throw error;
|
|
72299
72642
|
});
|
|
72300
72643
|
return Promise.all(files.filter((file) => /^[a-f0-9]{64}\.json$/.test(file)).map(async (file) => {
|
|
72301
|
-
const path =
|
|
72302
|
-
if ((await
|
|
72644
|
+
const path = join30(this.directory, file);
|
|
72645
|
+
if ((await lstat14(path)).isSymbolicLink())
|
|
72303
72646
|
throw new Error(`AV launch receipt cannot be a symlink: ${path}`);
|
|
72304
|
-
return jobSchema.parse(JSON.parse(await
|
|
72647
|
+
return jobSchema.parse(JSON.parse(await readFile11(path, "utf8")));
|
|
72305
72648
|
}));
|
|
72306
72649
|
}
|
|
72307
72650
|
async latest(missionId) {
|
|
@@ -72313,10 +72656,10 @@ class MissionJobs {
|
|
|
72313
72656
|
await writeJsonAtomic(this.path(job.requestId), job, { pretty: false });
|
|
72314
72657
|
}
|
|
72315
72658
|
logPath(job) {
|
|
72316
|
-
return
|
|
72659
|
+
return join30(this.directory, `${digest6(job.requestId)}.log`);
|
|
72317
72660
|
}
|
|
72318
72661
|
path(requestId) {
|
|
72319
|
-
return
|
|
72662
|
+
return join30(this.directory, `${digest6(requestId)}.json`);
|
|
72320
72663
|
}
|
|
72321
72664
|
}
|
|
72322
72665
|
|
|
@@ -72351,16 +72694,17 @@ async function launchMission(input) {
|
|
|
72351
72694
|
// src/operation-api.ts
|
|
72352
72695
|
import { randomUUID as randomUUID21 } from "node:crypto";
|
|
72353
72696
|
import { realpath as realpath32 } from "node:fs/promises";
|
|
72354
|
-
import { join as
|
|
72697
|
+
import { join as join54 } from "node:path";
|
|
72355
72698
|
|
|
72356
72699
|
// ../../packages/core/src/chief/continuous-store.ts
|
|
72357
72700
|
init_atomic_json();
|
|
72358
|
-
import { lstat as
|
|
72359
|
-
import { join as
|
|
72701
|
+
import { lstat as lstat15, mkdir as mkdir14, readdir as readdir10, readFile as readFile12, realpath as realpath18 } from "node:fs/promises";
|
|
72702
|
+
import { join as join31, resolve as resolve21 } from "node:path";
|
|
72360
72703
|
|
|
72361
72704
|
// ../../packages/core/src/chief/continuous-contract.ts
|
|
72362
72705
|
init_zod();
|
|
72363
72706
|
init_container_observation_policy();
|
|
72707
|
+
init_operations();
|
|
72364
72708
|
|
|
72365
72709
|
// ../../packages/core/src/chief/source-integration-contract.ts
|
|
72366
72710
|
init_zod();
|
|
@@ -72432,6 +72776,7 @@ var operationSchema = strictObject({
|
|
|
72432
72776
|
repositoryRoot: pathSchema,
|
|
72433
72777
|
charter: string2().trim().min(1).max(32000),
|
|
72434
72778
|
settings: record(string2().min(1).max(80), union([string2().max(32000), boolean2()])),
|
|
72779
|
+
actorHealth: array(providerHealthEvidenceSchema).max(100).optional(),
|
|
72435
72780
|
phase: _enum(["deciding", "running", "accepting", "waiting", "paused", "completed"]),
|
|
72436
72781
|
pauseKind: _enum(["interrupted", "blocked", "service-shutdown"]).optional(),
|
|
72437
72782
|
createdAt: timestampSchema,
|
|
@@ -72526,7 +72871,7 @@ class ContinuousOperationStore {
|
|
|
72526
72871
|
}
|
|
72527
72872
|
path(id) {
|
|
72528
72873
|
operationIdSchema.parse(id);
|
|
72529
|
-
return
|
|
72874
|
+
return join31(this.directory, `${id}.json`);
|
|
72530
72875
|
}
|
|
72531
72876
|
async ensureDirectory() {
|
|
72532
72877
|
await mkdir14(this.directory, { recursive: true, mode: 448 });
|
|
@@ -72546,9 +72891,9 @@ class ContinuousOperationStore {
|
|
|
72546
72891
|
}
|
|
72547
72892
|
async load(id) {
|
|
72548
72893
|
const path = this.path(id);
|
|
72549
|
-
if (await realpath18(this.directory) !== resolve21(this.directory) || !(await
|
|
72894
|
+
if (await realpath18(this.directory) !== resolve21(this.directory) || !(await lstat15(path)).isFile())
|
|
72550
72895
|
throw new Error("Operation record must remain a regular file in its original local storage directory.");
|
|
72551
|
-
const content = JSON.parse(await
|
|
72896
|
+
const content = JSON.parse(await readFile12(path, "utf8"));
|
|
72552
72897
|
if (content.version !== 1)
|
|
72553
72898
|
throw new Error("Unsupported operation record version. Use the AV version that created this operation.");
|
|
72554
72899
|
const operation = operationSchema.parse(content.operation);
|
|
@@ -72559,7 +72904,7 @@ class ContinuousOperationStore {
|
|
|
72559
72904
|
async list() {
|
|
72560
72905
|
let names;
|
|
72561
72906
|
try {
|
|
72562
|
-
names = await
|
|
72907
|
+
names = await readdir10(this.directory);
|
|
72563
72908
|
} catch (error) {
|
|
72564
72909
|
if (error.code === "ENOENT")
|
|
72565
72910
|
return [];
|
|
@@ -72578,7 +72923,7 @@ class ContinuousOperationStore {
|
|
|
72578
72923
|
import { execFile as execFile6 } from "node:child_process";
|
|
72579
72924
|
import { randomUUID as randomUUID20 } from "node:crypto";
|
|
72580
72925
|
import { realpath as realpath31 } from "node:fs/promises";
|
|
72581
|
-
import { join as
|
|
72926
|
+
import { join as join53, resolve as resolve33 } from "node:path";
|
|
72582
72927
|
import { promisify as promisify4 } from "node:util";
|
|
72583
72928
|
|
|
72584
72929
|
// ../../packages/core/src/chief/container-observation-command.ts
|
|
@@ -73065,9 +73410,9 @@ async function collectContainerObservation(input, previous, dependencies = {}) {
|
|
|
73065
73410
|
|
|
73066
73411
|
// ../../packages/core/src/chief/continuous-acceptance-record.ts
|
|
73067
73412
|
init_zod();
|
|
73068
|
-
import { constants as
|
|
73069
|
-
import { lstat as
|
|
73070
|
-
import { dirname as dirname6, join as
|
|
73413
|
+
import { constants as constants12 } from "node:fs";
|
|
73414
|
+
import { lstat as lstat16, open as open13, realpath as realpath19 } from "node:fs/promises";
|
|
73415
|
+
import { dirname as dirname6, join as join32, resolve as resolve22 } from "node:path";
|
|
73071
73416
|
var objectId3 = string2().regex(/^[a-f0-9]{40,64}$/);
|
|
73072
73417
|
var continuousAcceptanceSchema = strictObject({
|
|
73073
73418
|
version: literal(1),
|
|
@@ -73085,8 +73430,8 @@ async function recordContinuousAcceptance(operation) {
|
|
|
73085
73430
|
const entry = operation.history.at(-1);
|
|
73086
73431
|
if (!snapshot?.missionId || !entry || entry.missionId !== snapshot.missionId || entry.baselinePath !== snapshot.path)
|
|
73087
73432
|
return;
|
|
73088
|
-
const directory =
|
|
73089
|
-
if (snapshot.operationId !== operation.id || snapshot.repositoryRoot !== operation.repositoryRoot || snapshot.path !==
|
|
73433
|
+
const directory = join32(operation.repositoryRoot, ".agent-valley", "operations", operation.id, "baselines", snapshot.missionId);
|
|
73434
|
+
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)
|
|
73090
73435
|
throw new Error("Acceptance journal paths changed. Restore the original accepted snapshot before continuing.");
|
|
73091
73436
|
const record = continuousAcceptanceSchema.parse({
|
|
73092
73437
|
version: 1,
|
|
@@ -73099,10 +73444,10 @@ async function recordContinuousAcceptance(operation) {
|
|
|
73099
73444
|
tree: snapshot.baselineTree,
|
|
73100
73445
|
completedAt: entry.completedAt
|
|
73101
73446
|
});
|
|
73102
|
-
const path =
|
|
73447
|
+
const path = join32(directory, "acceptance.json");
|
|
73103
73448
|
let existing;
|
|
73104
73449
|
try {
|
|
73105
|
-
existing = await open13(path,
|
|
73450
|
+
existing = await open13(path, constants12.O_RDONLY | (constants12.O_NOFOLLOW ?? 0) | (constants12.O_NONBLOCK ?? 0));
|
|
73106
73451
|
const stat = await existing.stat();
|
|
73107
73452
|
if (!stat.isFile() || stat.size > 16384)
|
|
73108
73453
|
throw new Error("Unsupported acceptance journal receipt.");
|
|
@@ -73116,7 +73461,7 @@ async function recordContinuousAcceptance(operation) {
|
|
|
73116
73461
|
} finally {
|
|
73117
73462
|
await existing?.close();
|
|
73118
73463
|
}
|
|
73119
|
-
if (!(await
|
|
73464
|
+
if (!(await lstat16(dirname6(path))).isDirectory())
|
|
73120
73465
|
throw new Error("Acceptance journal requires its original private directory.");
|
|
73121
73466
|
const handle = await open13(path, "wx", 384);
|
|
73122
73467
|
try {
|
|
@@ -73130,6 +73475,43 @@ async function recordContinuousAcceptance(operation) {
|
|
|
73130
73475
|
// ../../packages/core/src/chief/continuous-operation.ts
|
|
73131
73476
|
import { createHash as createHash21, randomUUID as randomUUID13 } from "node:crypto";
|
|
73132
73477
|
|
|
73478
|
+
// ../../packages/core/src/chief/actor-health-seed.ts
|
|
73479
|
+
var routeKey2 = (route) => JSON.stringify([route.actorType, route.model ?? null]);
|
|
73480
|
+
function mergeProviderHealthSnapshots(previous, updates) {
|
|
73481
|
+
const merged = new Map;
|
|
73482
|
+
for (const route of [...previous, ...updates]) {
|
|
73483
|
+
const key = routeKey2(route);
|
|
73484
|
+
const existing = merged.get(key);
|
|
73485
|
+
if (existing && Date.parse(existing.providerHealth.lastOutcomeAt) > Date.parse(route.providerHealth.lastOutcomeAt))
|
|
73486
|
+
continue;
|
|
73487
|
+
merged.set(key, {
|
|
73488
|
+
actorType: route.actorType,
|
|
73489
|
+
...route.model ? { model: route.model } : {},
|
|
73490
|
+
providerHealth: { ...route.providerHealth }
|
|
73491
|
+
});
|
|
73492
|
+
}
|
|
73493
|
+
return [...merged.values()];
|
|
73494
|
+
}
|
|
73495
|
+
function seedProviderHealthEvidence(quality, health) {
|
|
73496
|
+
const merged = new Map(quality.map((route) => [routeKey2(route), { ...route }]));
|
|
73497
|
+
const newest = mergeProviderHealthSnapshots(quality.flatMap((route) => route.providerHealth ? [{ ...route, providerHealth: route.providerHealth }] : []), health);
|
|
73498
|
+
for (const route of newest) {
|
|
73499
|
+
const key = routeKey2(route);
|
|
73500
|
+
merged.set(key, {
|
|
73501
|
+
...merged.get(key) ?? {
|
|
73502
|
+
actorType: route.actorType,
|
|
73503
|
+
...route.model ? { model: route.model } : {},
|
|
73504
|
+
samples: 0,
|
|
73505
|
+
successes: 0,
|
|
73506
|
+
totalCostUsd: null,
|
|
73507
|
+
successfulDeliverableCostUsd: null
|
|
73508
|
+
},
|
|
73509
|
+
providerHealth: { ...route.providerHealth }
|
|
73510
|
+
});
|
|
73511
|
+
}
|
|
73512
|
+
return [...merged.values()];
|
|
73513
|
+
}
|
|
73514
|
+
|
|
73133
73515
|
// ../../packages/core/src/chief/continuous-acceptance.ts
|
|
73134
73516
|
async function acceptContinuousChild(operation, mission, ports, save, now) {
|
|
73135
73517
|
const previous = operation.baseline;
|
|
@@ -73193,6 +73575,23 @@ async function runContinuousOperation(operation, ports) {
|
|
|
73193
73575
|
operation.updatedAt = now();
|
|
73194
73576
|
await ports.save(operation);
|
|
73195
73577
|
};
|
|
73578
|
+
const assertIdentity = (child) => {
|
|
73579
|
+
const decision = operation.decision;
|
|
73580
|
+
if (child.id !== operation.currentMissionId || child.repositoryRoot !== operation.repositoryRoot || decision?.action !== "execute" || child.goal !== decision.goal)
|
|
73581
|
+
throw new Error("Saved child identity, repository or goal does not match this operation. Restore the original child before continuing.");
|
|
73582
|
+
if (JSON.stringify(child.containerObservationPolicy) !== JSON.stringify(operation.containerObservationPolicy))
|
|
73583
|
+
throw new Error("Saved child container targets differ from the pinned operation contract. Restore the original child policy before continuing.");
|
|
73584
|
+
};
|
|
73585
|
+
const rememberHealth = async (child) => {
|
|
73586
|
+
assertIdentity(child);
|
|
73587
|
+
const health = mergeProviderHealthSnapshots(operation.actorHealth ?? [], aggregateProviderHealth(child));
|
|
73588
|
+
if (JSON.stringify(health) !== JSON.stringify(operation.actorHealth ?? [])) {
|
|
73589
|
+
operation.actorHealth = health;
|
|
73590
|
+
await save();
|
|
73591
|
+
}
|
|
73592
|
+
return child;
|
|
73593
|
+
};
|
|
73594
|
+
const runChild = async (id, goal, baseline) => rememberHealth(await ports.runMission(operation, id, goal, baseline));
|
|
73196
73595
|
const pause = async (message) => {
|
|
73197
73596
|
if (operation.phase !== "paused" && operation.phase !== "completed")
|
|
73198
73597
|
operation.resumePhase = operation.phase;
|
|
@@ -73248,11 +73647,13 @@ async function runContinuousOperation(operation, ports) {
|
|
|
73248
73647
|
const previous = operation.recovery?.target === "child" && operation.recovery.checkpointId === mission.id ? operation.recovery : undefined;
|
|
73249
73648
|
const prior = previous?.attempts ?? 0;
|
|
73250
73649
|
const failedAttempts = previous?.failedAttempts ?? prior;
|
|
73251
|
-
const
|
|
73252
|
-
|
|
73650
|
+
const actorCooldown = scheduledActorCooldown(mission);
|
|
73651
|
+
const waitKey = scheduledMissionWait(mission) ? createHash21("sha256").update(JSON.stringify({
|
|
73652
|
+
...actorCooldown ? { kind: "actor-cooldown" } : { decision: mission.supervision?.decisions.at(-1) },
|
|
73253
73653
|
nextRunAt: mission.execution?.nextRunAt
|
|
73254
73654
|
})).digest("hex") : undefined;
|
|
73255
|
-
const
|
|
73655
|
+
const pendingCooldown = actorCooldown && previous?.nextRunAt === mission.execution?.nextRunAt;
|
|
73656
|
+
const continuation = !!waitKey && (waitKey !== previous?.waitContinuationKey || pendingCooldown);
|
|
73256
73657
|
operation.recovery = {
|
|
73257
73658
|
target: "child",
|
|
73258
73659
|
checkpointId: mission.id,
|
|
@@ -73282,7 +73683,7 @@ async function runContinuousOperation(operation, ports) {
|
|
|
73282
73683
|
if (!operation.baseline)
|
|
73283
73684
|
throw new Error("The original accepted baseline is missing from the recovery checkpoint.");
|
|
73284
73685
|
try {
|
|
73285
|
-
const resumed = await
|
|
73686
|
+
const resumed = await runChild(mission.id, mission.goal, operation.baseline.path);
|
|
73286
73687
|
if (isServiceShutdown(ports.signal) && resumed.execution?.failureKind === "service-shutdown") {
|
|
73287
73688
|
operation.recovery = pendingRecovery;
|
|
73288
73689
|
throw interruptionPause(ports.signal, "Operation child recovery interrupted.");
|
|
@@ -73368,15 +73769,9 @@ async function runContinuousOperation(operation, ports) {
|
|
|
73368
73769
|
const decision = operation.decision;
|
|
73369
73770
|
if (decision?.action !== "execute")
|
|
73370
73771
|
throw new Error("Restore the saved child execution decision before resuming.");
|
|
73371
|
-
const assertIdentity = (child) => {
|
|
73372
|
-
if (child.id !== id || child.repositoryRoot !== operation.repositoryRoot || child.goal !== decision.goal)
|
|
73373
|
-
throw new Error("Saved child identity, repository or goal does not match this operation. Restore the original child before continuing.");
|
|
73374
|
-
if (JSON.stringify(child.containerObservationPolicy) !== JSON.stringify(operation.containerObservationPolicy))
|
|
73375
|
-
throw new Error("Saved child container targets differ from the pinned operation contract. Restore the original child policy before continuing.");
|
|
73376
|
-
};
|
|
73377
73772
|
let mission = await ports.findMission(id);
|
|
73378
73773
|
if (mission) {
|
|
73379
|
-
|
|
73774
|
+
await rememberHealth(mission);
|
|
73380
73775
|
if (mission.tasks.some((task) => task.effectState === "unknown")) {
|
|
73381
73776
|
if (await recoverChild(mission))
|
|
73382
73777
|
continue;
|
|
@@ -73391,7 +73786,7 @@ async function runContinuousOperation(operation, ports) {
|
|
|
73391
73786
|
if (!mission) {
|
|
73392
73787
|
if (operation.phase === "accepting")
|
|
73393
73788
|
return pause(`Completed child ${id} is missing. Restore its saved mission record before continuing.`);
|
|
73394
|
-
mission = await
|
|
73789
|
+
mission = await runChild(id, decision.goal, operation.baseline.path);
|
|
73395
73790
|
} else if (mission.status !== "completed" && mission.status !== "paused" && mission.status !== "failed") {
|
|
73396
73791
|
const recovery = operation.recovery;
|
|
73397
73792
|
if (recovery?.target === "child" && recovery.checkpointId === id && recovery.disposition === "protected" && !mission.tasks.some((task) => task.effectState === "running") && automaticMissionRecovery(mission, Date.parse(now())).retry) {
|
|
@@ -73399,7 +73794,7 @@ async function runContinuousOperation(operation, ports) {
|
|
|
73399
73794
|
recovery.reason = `The original child resumed ${mission.status}; joining its saved coordinator without spending another recovery attempt.`;
|
|
73400
73795
|
await save();
|
|
73401
73796
|
}
|
|
73402
|
-
mission = await
|
|
73797
|
+
mission = await runChild(id, decision.goal, operation.baseline.path);
|
|
73403
73798
|
}
|
|
73404
73799
|
assertIdentity(mission);
|
|
73405
73800
|
if (mission.status !== "completed") {
|
|
@@ -73416,7 +73811,7 @@ async function runContinuousOperation(operation, ports) {
|
|
|
73416
73811
|
if (!mission.executionPolicy?.autoResume)
|
|
73417
73812
|
return pause(`Child ${id} has pending code delivery with automatic recovery disabled.`);
|
|
73418
73813
|
await waitForRecovery(mission.codeDelivery?.nextRunAt, mission);
|
|
73419
|
-
await
|
|
73814
|
+
await runChild(id, decision.goal, operation.baseline.path);
|
|
73420
73815
|
continue;
|
|
73421
73816
|
}
|
|
73422
73817
|
if (!successfulCodeDelivery(mission))
|
|
@@ -73512,12 +73907,12 @@ async function runContinuousOperation(operation, ports) {
|
|
|
73512
73907
|
// ../../packages/core/src/chief/continuous-source-integration.ts
|
|
73513
73908
|
init_zod();
|
|
73514
73909
|
import { createHash as createHash23 } from "node:crypto";
|
|
73515
|
-
import { lstat as
|
|
73516
|
-
import { join as
|
|
73910
|
+
import { lstat as lstat19, mkdir as mkdir17, readdir as readdir11, readFile as readFile16, realpath as realpath22, writeFile as writeFile10 } from "node:fs/promises";
|
|
73911
|
+
import { join as join36, resolve as resolve25 } from "node:path";
|
|
73517
73912
|
|
|
73518
73913
|
// ../../packages/core/src/chief/content-transaction.ts
|
|
73519
73914
|
import { createHash as createHash22 } from "node:crypto";
|
|
73520
|
-
import { readFile as
|
|
73915
|
+
import { readFile as readFile13 } from "node:fs/promises";
|
|
73521
73916
|
|
|
73522
73917
|
// ../../packages/core/src/chief/parallel-git.ts
|
|
73523
73918
|
init_atomic_json();
|
|
@@ -73526,7 +73921,7 @@ init_git_environment();
|
|
|
73526
73921
|
import { execFile as execFile4 } from "node:child_process";
|
|
73527
73922
|
import { randomUUID as randomUUID14 } from "node:crypto";
|
|
73528
73923
|
import { mkdir as mkdir15, realpath as realpath20, rm as rm4, writeFile as writeFile8 } from "node:fs/promises";
|
|
73529
|
-
import { join as
|
|
73924
|
+
import { join as join33, relative as relative12, resolve as resolve23, sep as sep12 } from "node:path";
|
|
73530
73925
|
import { promisify as promisify3 } from "node:util";
|
|
73531
73926
|
var exec2 = promisify3(execFile4);
|
|
73532
73927
|
var productPaths = ["--", ".", ":(exclude,glob).agent-valley/**", ":(exclude,glob).agents/**"];
|
|
@@ -73547,7 +73942,7 @@ async function parallelGit(cwd, args, env = {}) {
|
|
|
73547
73942
|
}
|
|
73548
73943
|
async function parallelRoot(workspace) {
|
|
73549
73944
|
const root = await realpath20(workspace);
|
|
73550
|
-
const directory =
|
|
73945
|
+
const directory = join33(root, ".agent-valley", "parallel");
|
|
73551
73946
|
await mkdir15(directory, { recursive: true, mode: 448 });
|
|
73552
73947
|
const actual = await realpath20(directory);
|
|
73553
73948
|
if (actual !== directory)
|
|
@@ -73564,7 +73959,7 @@ async function writeParallelJson(path, value) {
|
|
|
73564
73959
|
}
|
|
73565
73960
|
async function captureParallelBaseline(workspace) {
|
|
73566
73961
|
const directory = await parallelRoot(workspace);
|
|
73567
|
-
const index =
|
|
73962
|
+
const index = join33(directory, `index-${randomUUID14()}`);
|
|
73568
73963
|
const pathsFile = `${index}.paths`;
|
|
73569
73964
|
const env = { GIT_INDEX_FILE: index };
|
|
73570
73965
|
try {
|
|
@@ -73610,7 +74005,7 @@ async function parallelTreeImages(workspace, tree) {
|
|
|
73610
74005
|
// ../../packages/core/src/chief/content-transaction.ts
|
|
73611
74006
|
async function integrateContentTransaction(workspace, transaction, hooks) {
|
|
73612
74007
|
await hooks.assertLive?.();
|
|
73613
|
-
const patch = await
|
|
74008
|
+
const patch = await readFile13(transaction.patchPath);
|
|
73614
74009
|
if (createHash22("sha256").update(patch).digest("hex") !== transaction.patchSha256)
|
|
73615
74010
|
throw new Error("Integration patch changed. Restore its saved SHA256 before integration.");
|
|
73616
74011
|
const current = await captureParallelBaseline(workspace);
|
|
@@ -73654,8 +74049,8 @@ init_zod();
|
|
|
73654
74049
|
init_runtime_ignore();
|
|
73655
74050
|
init_parallel_contract();
|
|
73656
74051
|
import { randomUUID as randomUUID15 } from "node:crypto";
|
|
73657
|
-
import { lstat as
|
|
73658
|
-
import { join as
|
|
74052
|
+
import { lstat as lstat17, readFile as readFile14, rm as rm5, writeFile as writeFile9 } from "node:fs/promises";
|
|
74053
|
+
import { join as join34 } from "node:path";
|
|
73659
74054
|
var imageSchema2 = parallelDeliverySchema.shape.changes.element.shape.before;
|
|
73660
74055
|
var gitignoreProjectionSchema = strictObject({
|
|
73661
74056
|
path: literal(".gitignore"),
|
|
@@ -73670,13 +74065,13 @@ async function artifact2(path, value) {
|
|
|
73670
74065
|
} catch (error) {
|
|
73671
74066
|
if (error.code !== "EEXIST")
|
|
73672
74067
|
throw error;
|
|
73673
|
-
const info = await
|
|
73674
|
-
if (info.isSymbolicLink() || !info.isFile() || !(await
|
|
74068
|
+
const info = await lstat17(path);
|
|
74069
|
+
if (info.isSymbolicLink() || !info.isFile() || !(await readFile14(path)).equals(Buffer.from(value)))
|
|
73675
74070
|
throw new Error("Projected runtime-ignore bytes changed. Restore the original source integration artifacts before retrying.");
|
|
73676
74071
|
}
|
|
73677
74072
|
}
|
|
73678
74073
|
async function projectedPatch(workspace, directory, before, after) {
|
|
73679
|
-
const index =
|
|
74074
|
+
const index = join34(directory, `gitignore-index-${randomUUID15()}`);
|
|
73680
74075
|
const env = { GIT_INDEX_FILE: index };
|
|
73681
74076
|
try {
|
|
73682
74077
|
await parallelGit(workspace, ["read-tree", "--empty"], env);
|
|
@@ -73741,7 +74136,7 @@ async function projectContinuousGitignore(workspace, sourceWorkspace, directory,
|
|
|
73741
74136
|
throw new Error("Runtime-ignore projection requires unchanged UTF-8 ignore-file text. Preserve its bytes and reconcile before retrying.");
|
|
73742
74137
|
}
|
|
73743
74138
|
const blob = async (name, content, mode) => {
|
|
73744
|
-
const path =
|
|
74139
|
+
const path = join34(directory, name);
|
|
73745
74140
|
await artifact2(path, content);
|
|
73746
74141
|
return { mode, oid: (await parallelGit(workspace, ["hash-object", "-w", "--", path])).trim() };
|
|
73747
74142
|
};
|
|
@@ -73765,8 +74160,8 @@ async function projectContinuousGitignore(workspace, sourceWorkspace, directory,
|
|
|
73765
74160
|
|
|
73766
74161
|
// ../../packages/core/src/chief/continuous-workspace.ts
|
|
73767
74162
|
init_zod();
|
|
73768
|
-
import { lstat as
|
|
73769
|
-
import { dirname as dirname7, join as
|
|
74163
|
+
import { lstat as lstat18, mkdir as mkdir16, readFile as readFile15, realpath as realpath21 } from "node:fs/promises";
|
|
74164
|
+
import { dirname as dirname7, join as join35, resolve as resolve24 } from "node:path";
|
|
73770
74165
|
async function localDirectory(path) {
|
|
73771
74166
|
await mkdir16(path, { recursive: true, mode: 448 });
|
|
73772
74167
|
if (await realpath21(path) !== resolve24(path))
|
|
@@ -73778,12 +74173,12 @@ async function operationDirectory(repositoryRoot, operationId) {
|
|
|
73778
74173
|
const top = (await parallelGit(root, ["rev-parse", "--show-toplevel"])).trim();
|
|
73779
74174
|
if (root !== resolve24(repositoryRoot) || await realpath21(top) !== root)
|
|
73780
74175
|
throw new Error("Use the operation's original canonical Git repository root before resuming.");
|
|
73781
|
-
const directory =
|
|
74176
|
+
const directory = join35(root, ".agent-valley", "operations", operationId);
|
|
73782
74177
|
await localDirectory(directory);
|
|
73783
74178
|
return directory;
|
|
73784
74179
|
}
|
|
73785
74180
|
async function readJson2(path) {
|
|
73786
|
-
const stats = await
|
|
74181
|
+
const stats = await lstat18(path).catch((error) => {
|
|
73787
74182
|
if (error.code === "ENOENT")
|
|
73788
74183
|
return;
|
|
73789
74184
|
throw error;
|
|
@@ -73792,10 +74187,10 @@ async function readJson2(path) {
|
|
|
73792
74187
|
return;
|
|
73793
74188
|
if (!stats.isFile())
|
|
73794
74189
|
throw new Error("Operation receipts must be regular local files. Restore the original receipt.");
|
|
73795
|
-
return JSON.parse(await
|
|
74190
|
+
return JSON.parse(await readFile15(path, "utf8"));
|
|
73796
74191
|
}
|
|
73797
74192
|
async function assertRepository(path, branch, commit) {
|
|
73798
|
-
if (await realpath21(path) !== path || !(await
|
|
74193
|
+
if (await realpath21(path) !== path || !(await lstat18(join35(path, ".git"))).isDirectory())
|
|
73799
74194
|
throw new Error("Operation workspace must remain an independent local Git repository.");
|
|
73800
74195
|
const [top, currentBranch, head] = await Promise.all([
|
|
73801
74196
|
parallelGit(path, ["rev-parse", "--show-toplevel"]),
|
|
@@ -73810,11 +74205,11 @@ async function prepareContinuousBaseline(repositoryRoot, operationId, sourceWork
|
|
|
73810
74205
|
operationIdSchema.parse(missionId);
|
|
73811
74206
|
if (expectedFingerprint !== undefined && !/^[a-f0-9]{64}$/.test(expectedFingerprint))
|
|
73812
74207
|
throw new Error("Use the completed child's original SHA256 verification fingerprint when accepting a snapshot.");
|
|
73813
|
-
const directory =
|
|
74208
|
+
const directory = join35(await operationDirectory(repositoryRoot, operationId), "baselines", missionId ?? "initial");
|
|
73814
74209
|
await localDirectory(directory);
|
|
73815
|
-
const recordPath =
|
|
73816
|
-
const preparedPath =
|
|
73817
|
-
const path =
|
|
74210
|
+
const recordPath = join35(directory, "baseline.json");
|
|
74211
|
+
const preparedPath = join35(directory, "snapshot.json");
|
|
74212
|
+
const path = join35(directory, "workspace");
|
|
73818
74213
|
const source = await realpath21(sourceWorkspacePath);
|
|
73819
74214
|
const existing = await readJson2(recordPath);
|
|
73820
74215
|
if (existing) {
|
|
@@ -73872,7 +74267,7 @@ async function prepareContinuousBaseline(repositoryRoot, operationId, sourceWork
|
|
|
73872
74267
|
return validateContinuousBaseline(repositoryRoot, operationId, snapshot.path);
|
|
73873
74268
|
}
|
|
73874
74269
|
async function ensureClone(source, path, branch, commit) {
|
|
73875
|
-
const exists = await
|
|
74270
|
+
const exists = await lstat18(path).catch((error) => {
|
|
73876
74271
|
if (error.code === "ENOENT")
|
|
73877
74272
|
return;
|
|
73878
74273
|
throw error;
|
|
@@ -73882,11 +74277,11 @@ async function ensureClone(source, path, branch, commit) {
|
|
|
73882
74277
|
} else if (!exists.isDirectory() || await realpath21(path) !== path) {
|
|
73883
74278
|
throw new Error("Operation workspace path redirects outside its private directory. Restore it before resuming.");
|
|
73884
74279
|
}
|
|
73885
|
-
if (!(await
|
|
74280
|
+
if (!(await lstat18(join35(path, ".git"))).isDirectory() || await realpath21(join35(path, ".git")) !== join35(path, ".git"))
|
|
73886
74281
|
throw new Error("Operation clone Git metadata must remain within its independent private repository.");
|
|
73887
74282
|
const currentBranch = (await parallelGit(path, ["symbolic-ref", "--quiet", "--short", "HEAD"])).trim();
|
|
73888
74283
|
if (currentBranch !== branch) {
|
|
73889
|
-
const index = await
|
|
74284
|
+
const index = await lstat18(join35(path, ".git", "index")).catch(() => {
|
|
73890
74285
|
return;
|
|
73891
74286
|
});
|
|
73892
74287
|
if (index)
|
|
@@ -73904,10 +74299,10 @@ async function validateContinuousBaseline(repositoryRoot, operationId, baselineP
|
|
|
73904
74299
|
const path = resolve24(baselinePath);
|
|
73905
74300
|
const key = dirname7(path).split(/[\\/]/).at(-1) ?? "";
|
|
73906
74301
|
operationIdSchema.parse(key);
|
|
73907
|
-
if (path !==
|
|
74302
|
+
if (path !== join35(root, "baselines", key, "workspace") || await realpath21(dirname7(path)) !== dirname7(path))
|
|
73908
74303
|
throw new Error("Accepted baseline path is outside this operation's private snapshot directory.");
|
|
73909
|
-
const snapshot = continuousBaselineSchema.parse(await readJson2(
|
|
73910
|
-
const expected =
|
|
74304
|
+
const snapshot = continuousBaselineSchema.parse(await readJson2(join35(dirname7(path), "baseline.json")));
|
|
74305
|
+
const expected = join35(root, "baselines", snapshot.missionId ?? "initial", "workspace");
|
|
73911
74306
|
if (snapshot.operationId !== operationId || snapshot.repositoryRoot !== repositoryRoot || snapshot.path !== path || path !== expected || await realpath21(dirname7(path)) !== dirname7(path))
|
|
73912
74307
|
throw new Error("Accepted baseline does not belong to this operation or repository. Restore its original local receipt.");
|
|
73913
74308
|
await assertRepository(path, snapshot.branch, snapshot.commit);
|
|
@@ -73930,11 +74325,11 @@ async function createContinuousMissionWorkspace(repositoryRoot, operationId, bas
|
|
|
73930
74325
|
operationIdSchema.parse(missionId);
|
|
73931
74326
|
const baseline = await validateContinuousBaseline(repositoryRoot, operationId, baselinePath);
|
|
73932
74327
|
const root = await operationDirectory(repositoryRoot, operationId);
|
|
73933
|
-
const directory =
|
|
74328
|
+
const directory = join35(root, "workspaces", missionId);
|
|
73934
74329
|
await localDirectory(directory);
|
|
73935
|
-
const path =
|
|
74330
|
+
const path = join35(directory, "workspace");
|
|
73936
74331
|
const branch = `av-operation/${operationId}/${missionId}`;
|
|
73937
|
-
const recordPath =
|
|
74332
|
+
const recordPath = join35(directory, "workspace.json");
|
|
73938
74333
|
const raw = await readJson2(recordPath);
|
|
73939
74334
|
const record = raw ? missionWorkspaceSchema.parse(raw) : {
|
|
73940
74335
|
operationId,
|
|
@@ -73949,7 +74344,7 @@ async function createContinuousMissionWorkspace(repositoryRoot, operationId, bas
|
|
|
73949
74344
|
if (record.operationId !== operationId || record.repositoryRoot !== repositoryRoot || record.missionId !== missionId || record.baselinePath !== baseline.path || record.baselineCommit !== baseline.commit || record.path !== path || record.branch !== branch)
|
|
73950
74345
|
throw new Error("Child workspace identity does not match this operation's saved baseline. Restore its original receipt.");
|
|
73951
74346
|
if (!raw) {
|
|
73952
|
-
const preparedPath =
|
|
74347
|
+
const preparedPath = join35(directory, "prepared.json");
|
|
73953
74348
|
const prepared = await readJson2(preparedPath);
|
|
73954
74349
|
if (prepared && JSON.stringify(missionWorkspaceSchema.parse(prepared)) !== JSON.stringify(record)) {
|
|
73955
74350
|
const saved = missionWorkspaceSchema.parse(prepared);
|
|
@@ -73996,21 +74391,21 @@ var receiptSchema = strictObject({
|
|
|
73996
74391
|
at: exports_iso.datetime().optional()
|
|
73997
74392
|
});
|
|
73998
74393
|
async function localDirectory2(parent, name) {
|
|
73999
|
-
const path =
|
|
74000
|
-
const entry = await
|
|
74394
|
+
const path = join36(parent, name);
|
|
74395
|
+
const entry = await lstat19(path).catch((error) => {
|
|
74001
74396
|
if (error.code === "ENOENT")
|
|
74002
74397
|
return;
|
|
74003
74398
|
throw error;
|
|
74004
74399
|
});
|
|
74005
74400
|
if (!entry)
|
|
74006
74401
|
await mkdir17(path, { mode: 448 });
|
|
74007
|
-
const current = entry ?? await
|
|
74402
|
+
const current = entry ?? await lstat19(path);
|
|
74008
74403
|
if (current.isSymbolicLink() || !current.isDirectory() || await realpath22(path) !== path)
|
|
74009
74404
|
throw new Error("Source integration storage redirects. Restore its original private local directory before retrying.");
|
|
74010
74405
|
return path;
|
|
74011
74406
|
}
|
|
74012
74407
|
async function regularFile(path) {
|
|
74013
|
-
const entry = await
|
|
74408
|
+
const entry = await lstat19(path).catch((error) => {
|
|
74014
74409
|
if (error.code === "ENOENT")
|
|
74015
74410
|
return;
|
|
74016
74411
|
throw error;
|
|
@@ -74019,7 +74414,7 @@ async function regularFile(path) {
|
|
|
74019
74414
|
return;
|
|
74020
74415
|
if (entry.isSymbolicLink() || !entry.isFile())
|
|
74021
74416
|
throw new Error("Source integration receipts must be regular local files. Restore their original bytes before retrying.");
|
|
74022
|
-
return
|
|
74417
|
+
return readFile16(path);
|
|
74023
74418
|
}
|
|
74024
74419
|
async function sourceRoot(repositoryRoot) {
|
|
74025
74420
|
const root = await realpath22(repositoryRoot);
|
|
@@ -74038,8 +74433,8 @@ async function assertSettledSourceIntegrations(repositoryRoot, operationId, pend
|
|
|
74038
74433
|
operationIdSchema.parse(operationId);
|
|
74039
74434
|
let directory = await sourceRoot(repositoryRoot);
|
|
74040
74435
|
for (const part of [".agent-valley", "operations", operationId, "source-integrations"]) {
|
|
74041
|
-
directory =
|
|
74042
|
-
const entry = await
|
|
74436
|
+
directory = join36(directory, part);
|
|
74437
|
+
const entry = await lstat19(directory).catch((error) => {
|
|
74043
74438
|
if (error.code === "ENOENT")
|
|
74044
74439
|
return;
|
|
74045
74440
|
throw error;
|
|
@@ -74049,14 +74444,14 @@ async function assertSettledSourceIntegrations(repositoryRoot, operationId, pend
|
|
|
74049
74444
|
if (entry.isSymbolicLink() || !entry.isDirectory() || await realpath22(directory) !== directory)
|
|
74050
74445
|
throw new Error("Source integration storage redirects. Restore its original private directory before changing modes.");
|
|
74051
74446
|
}
|
|
74052
|
-
for (const entry of await
|
|
74447
|
+
for (const entry of await readdir11(directory, { withFileTypes: true })) {
|
|
74053
74448
|
operationIdSchema.parse(entry.name);
|
|
74054
|
-
const path =
|
|
74449
|
+
const path = join36(directory, entry.name);
|
|
74055
74450
|
if (entry.isSymbolicLink() || !entry.isDirectory() || await realpath22(path) !== path)
|
|
74056
74451
|
throw new Error("Source integration receipt storage redirects. Restore its original directory before changing modes.");
|
|
74057
|
-
const raw = await regularFile(
|
|
74452
|
+
const raw = await regularFile(join36(path, "integration.json"));
|
|
74058
74453
|
if (!raw) {
|
|
74059
|
-
if ((await
|
|
74454
|
+
if ((await readdir11(path)).length)
|
|
74060
74455
|
throw new Error("A source integration receipt is missing beside retained artifacts. Resume worktree integration and reconcile the original transaction before selecting snapshot-only.");
|
|
74061
74456
|
continue;
|
|
74062
74457
|
}
|
|
@@ -74075,8 +74470,8 @@ async function inspectPath(root, path) {
|
|
|
74075
74470
|
let current = root;
|
|
74076
74471
|
const parts = path.split("/");
|
|
74077
74472
|
for (let index = 0;index < parts.length; index += 1) {
|
|
74078
|
-
current =
|
|
74079
|
-
const entry = await
|
|
74473
|
+
current = join36(current, parts[index] ?? "");
|
|
74474
|
+
const entry = await lstat19(current).catch((error) => {
|
|
74080
74475
|
if (error.code === "ENOENT")
|
|
74081
74476
|
return;
|
|
74082
74477
|
throw error;
|
|
@@ -74138,7 +74533,7 @@ async function integrateContinuousSource(operation, previous, next, signal) {
|
|
|
74138
74533
|
throw new Error("Source integration snapshot differs from its original receipt. Restore the accepted baseline before retrying.");
|
|
74139
74534
|
}
|
|
74140
74535
|
const gitDirectory = await realpath22(resolve25(root, (await parallelGit(root, ["rev-parse", "--git-common-dir"])).trim()));
|
|
74141
|
-
const unlock = await lockRecord(
|
|
74536
|
+
const unlock = await lockRecord(join36(gitDirectory, "agent-valley-delivery.lock"), "Source integration", "source-integration");
|
|
74142
74537
|
try {
|
|
74143
74538
|
const assertIdentity = async () => {
|
|
74144
74539
|
signal?.throwIfAborted();
|
|
@@ -74150,8 +74545,8 @@ async function integrateContinuousSource(operation, previous, next, signal) {
|
|
|
74150
74545
|
let directory = root;
|
|
74151
74546
|
for (const part of [".agent-valley", "operations", operation.id, "source-integrations", missionId])
|
|
74152
74547
|
directory = await localDirectory2(directory, part);
|
|
74153
|
-
const recordPath =
|
|
74154
|
-
const patchPath =
|
|
74548
|
+
const recordPath = join36(directory, "integration.json");
|
|
74549
|
+
const patchPath = join36(directory, "changes.patch");
|
|
74155
74550
|
const saved = await regularFile(recordPath);
|
|
74156
74551
|
const before = await parallelTreeImages(next.path, previous.baselineTree);
|
|
74157
74552
|
const after = await parallelTreeImages(next.path, next.baselineTree);
|
|
@@ -74264,7 +74659,7 @@ init_execution();
|
|
|
74264
74659
|
init_runtime_ignore();
|
|
74265
74660
|
|
|
74266
74661
|
// src/chief-continuous-decision.ts
|
|
74267
|
-
import { join as
|
|
74662
|
+
import { join as join49 } from "node:path";
|
|
74268
74663
|
// ../../packages/core/src/chief/coordinator-checkpoint.ts
|
|
74269
74664
|
class CheckpointError extends Error {
|
|
74270
74665
|
}
|
|
@@ -74512,39 +74907,54 @@ function createMissionRun(mission, ports, assertContract, checkAbort, persist =
|
|
|
74512
74907
|
recordHandoffReview(mission, actor, stage, taskId);
|
|
74513
74908
|
checkAbort();
|
|
74514
74909
|
assertContract();
|
|
74515
|
-
|
|
74516
|
-
|
|
74517
|
-
|
|
74518
|
-
|
|
74910
|
+
const reserve = async (claim = () => {}) => {
|
|
74911
|
+
reserveExecutionRun(mission);
|
|
74912
|
+
claim();
|
|
74913
|
+
if (mission.executionPolicy)
|
|
74914
|
+
await persist("Actor budget reservation could not be saved. Restore writable mission storage before resuming.");
|
|
74915
|
+
};
|
|
74916
|
+
if (!ports.deferredDispatchAdmission)
|
|
74917
|
+
await reserve();
|
|
74519
74918
|
const before = await ports.fingerprint(mission);
|
|
74520
74919
|
checkAbort();
|
|
74521
74920
|
assertContract();
|
|
74522
|
-
|
|
74523
|
-
|
|
74524
|
-
|
|
74525
|
-
|
|
74526
|
-
|
|
74527
|
-
|
|
74528
|
-
|
|
74529
|
-
|
|
74530
|
-
|
|
74531
|
-
|
|
74532
|
-
|
|
74533
|
-
|
|
74534
|
-
|
|
74535
|
-
|
|
74536
|
-
|
|
74921
|
+
let dispatchAdmitted = false;
|
|
74922
|
+
const beforeDispatch = async (claim = () => {}) => {
|
|
74923
|
+
checkAbort();
|
|
74924
|
+
assertContract();
|
|
74925
|
+
if (ports.deferredDispatchAdmission)
|
|
74926
|
+
await reserve(claim);
|
|
74927
|
+
if (effect) {
|
|
74928
|
+
const previous = effect.effectState ?? "not-started";
|
|
74929
|
+
effect.effectState = "running";
|
|
74930
|
+
try {
|
|
74931
|
+
await persist("External dispatch checkpoint could not be saved. The Actor was not invoked and the effect remains not started.");
|
|
74932
|
+
} catch (error) {
|
|
74933
|
+
effect.effectState = previous;
|
|
74934
|
+
throw error;
|
|
74935
|
+
}
|
|
74936
|
+
try {
|
|
74937
|
+
checkAbort();
|
|
74938
|
+
} catch (error) {
|
|
74939
|
+
effect.effectState = previous;
|
|
74940
|
+
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.");
|
|
74941
|
+
throw error;
|
|
74942
|
+
}
|
|
74537
74943
|
}
|
|
74538
|
-
|
|
74944
|
+
dispatchAdmitted = true;
|
|
74945
|
+
};
|
|
74946
|
+
if (!ports.deferredDispatchAdmission)
|
|
74947
|
+
await beforeDispatch();
|
|
74539
74948
|
let output;
|
|
74540
74949
|
try {
|
|
74541
|
-
output = taskId || context || omaActor ? await ports.runAgent(actor, prompt, mission, stage, {
|
|
74950
|
+
output = taskId || context || omaActor || ports.deferredDispatchAdmission ? await ports.runAgent(actor, prompt, mission, stage, {
|
|
74542
74951
|
...context,
|
|
74543
74952
|
...taskId ? { taskId } : {},
|
|
74544
|
-
...omaActor ? { omaActor } : {}
|
|
74953
|
+
...omaActor ? { omaActor } : {},
|
|
74954
|
+
...ports.deferredDispatchAdmission ? { beforeDispatch } : {}
|
|
74545
74955
|
}) : await ports.runAgent(actor, prompt, mission, stage);
|
|
74546
74956
|
} catch (error) {
|
|
74547
|
-
if (effect)
|
|
74957
|
+
if (effect && dispatchAdmitted)
|
|
74548
74958
|
effect.effectState = "unknown";
|
|
74549
74959
|
assertNoUncertainExecution(mission);
|
|
74550
74960
|
mission.fingerprint = await ports.fingerprint(mission);
|
|
@@ -74652,17 +75062,17 @@ init_execution();
|
|
|
74652
75062
|
|
|
74653
75063
|
// ../../packages/core/src/chief/runtime.ts
|
|
74654
75064
|
import { randomUUID as randomUUID16 } from "node:crypto";
|
|
74655
|
-
import { join as
|
|
75065
|
+
import { join as join41, resolve as resolve28 } from "node:path";
|
|
74656
75066
|
|
|
74657
75067
|
// ../../packages/core/src/oma/receipt-adapter.ts
|
|
74658
75068
|
import { spawnSync as spawnSync2 } from "node:child_process";
|
|
74659
75069
|
import { existsSync as existsSync4, lstatSync as lstatSync3, readFileSync as readFileSync9 } from "node:fs";
|
|
74660
75070
|
import { mkdir as mkdir18, writeFile as writeFile11 } from "node:fs/promises";
|
|
74661
|
-
import { basename as basename2, dirname as dirname9, isAbsolute as
|
|
75071
|
+
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";
|
|
74662
75072
|
|
|
74663
75073
|
// ../../packages/core/src/config/workflow-router.ts
|
|
74664
75074
|
import { readFileSync as readFileSync8 } from "node:fs";
|
|
74665
|
-
import { join as
|
|
75075
|
+
import { join as join37 } from "node:path";
|
|
74666
75076
|
var INFORMATIONAL_WINDOW = 60;
|
|
74667
75077
|
function normalizeForRouting(text) {
|
|
74668
75078
|
return text.normalize("NFKC").toLowerCase().replace(/\s+/g, " ");
|
|
@@ -74829,7 +75239,7 @@ function parseTriggerTable(content) {
|
|
|
74829
75239
|
}
|
|
74830
75240
|
var triggerTableCache = new Map;
|
|
74831
75241
|
function getCachedTriggerTable(rootDir = process.cwd()) {
|
|
74832
|
-
const path =
|
|
75242
|
+
const path = join37(rootDir, ".agents", "hooks", "core", "triggers.json");
|
|
74833
75243
|
let content = null;
|
|
74834
75244
|
try {
|
|
74835
75245
|
content = readFileSync8(path, "utf-8");
|
|
@@ -74977,11 +75387,11 @@ function ensureLatestOmaCli(options = {}) {
|
|
|
74977
75387
|
// ../../packages/core/src/oma/receipt-storage.ts
|
|
74978
75388
|
import { createHash as createHash24 } from "node:crypto";
|
|
74979
75389
|
import { lstatSync as lstatSync2, readdirSync, realpathSync as realpathSync6 } from "node:fs";
|
|
74980
|
-
import { homedir as
|
|
74981
|
-
import { basename, dirname as dirname8, isAbsolute as
|
|
75390
|
+
import { homedir as homedir8 } from "node:os";
|
|
75391
|
+
import { basename, dirname as dirname8, isAbsolute as isAbsolute14, join as join38, relative as relative13, resolve as resolve26, sep as sep13 } from "node:path";
|
|
74982
75392
|
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;
|
|
74983
75393
|
function absolutePath(value, key) {
|
|
74984
|
-
if (!
|
|
75394
|
+
if (!isAbsolute14(value) || Array.from(value).some((character) => character.charCodeAt(0) < 32 || character.charCodeAt(0) === 127))
|
|
74985
75395
|
throw new Error(`${key} must be an absolute path without control characters`);
|
|
74986
75396
|
return resolve26(value);
|
|
74987
75397
|
}
|
|
@@ -74990,11 +75400,11 @@ function omaReceiptDirectories(workspace, options = {}) {
|
|
|
74990
75400
|
const profile = env.OMA_PROFILE ?? "0";
|
|
74991
75401
|
if (!/^(0|[1-9][0-9]{0,9})$/.test(profile))
|
|
74992
75402
|
throw new Error("OMA_PROFILE must be a non-negative profile number");
|
|
74993
|
-
const stateHome = env.OMA_STATE_HOME === undefined ? absolutePath(env.OMA_HOME ||
|
|
75403
|
+
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");
|
|
74994
75404
|
const project = createHash24("sha256").update(realpathSync6(resolve26(workspace))).digest("hex");
|
|
74995
75405
|
return [
|
|
74996
|
-
|
|
74997
|
-
...profile === "0" ? [
|
|
75406
|
+
join38(stateHome, "u", profile, "projects", project, "agent-runs"),
|
|
75407
|
+
...profile === "0" ? [join38(resolve26(workspace), ".agents", "state", "agent-runs")] : []
|
|
74998
75408
|
];
|
|
74999
75409
|
}
|
|
75000
75410
|
function regularDirectory(path) {
|
|
@@ -75012,12 +75422,12 @@ function regularDirectory(path) {
|
|
|
75012
75422
|
function validateDirectory(directory, workspace) {
|
|
75013
75423
|
if (!regularDirectory(directory))
|
|
75014
75424
|
return false;
|
|
75015
|
-
const legacy =
|
|
75425
|
+
const legacy = join38(resolve26(workspace), ".agents", "state", "agent-runs");
|
|
75016
75426
|
const boundary = directory === legacy ? resolve26(workspace) : dirname8(dirname8(dirname8(dirname8(dirname8(directory)))));
|
|
75017
75427
|
const components = relative13(boundary, directory).split(sep13).filter(Boolean);
|
|
75018
75428
|
let path = boundary;
|
|
75019
75429
|
for (const component of components) {
|
|
75020
|
-
path =
|
|
75430
|
+
path = join38(path, component);
|
|
75021
75431
|
if (!regularDirectory(path))
|
|
75022
75432
|
throw new Error("OMA receipt directory changed during inspection");
|
|
75023
75433
|
}
|
|
@@ -75027,7 +75437,7 @@ function listOmaRunFiles(workspace, options = {}) {
|
|
|
75027
75437
|
return omaReceiptDirectories(workspace, options).flatMap((directory) => {
|
|
75028
75438
|
if (!validateDirectory(directory, workspace))
|
|
75029
75439
|
return [];
|
|
75030
|
-
return readdirSync(directory).filter((name) => name.endsWith(".json") && OMA_RUN_ID.test(name.slice(0, -5))).map((name) =>
|
|
75440
|
+
return readdirSync(directory).filter((name) => name.endsWith(".json") && OMA_RUN_ID.test(name.slice(0, -5))).map((name) => join38(directory, name));
|
|
75031
75441
|
});
|
|
75032
75442
|
}
|
|
75033
75443
|
function resolveOmaReceiptPath(workspace, entry, options = {}) {
|
|
@@ -75035,8 +75445,8 @@ function resolveOmaReceiptPath(workspace, entry, options = {}) {
|
|
|
75035
75445
|
if (!name.endsWith(".json") || !OMA_RUN_ID.test(name.slice(0, -5)))
|
|
75036
75446
|
throw new Error("Invalid receipt filename");
|
|
75037
75447
|
if (entry === name)
|
|
75038
|
-
return
|
|
75039
|
-
if (!
|
|
75448
|
+
return join38(resolve26(workspace), ".agents", "state", "agent-runs", name);
|
|
75449
|
+
if (!isAbsolute14(entry) || resolve26(entry) !== entry)
|
|
75040
75450
|
throw new Error("Invalid receipt path");
|
|
75041
75451
|
if (!omaReceiptDirectories(workspace, options).includes(dirname8(entry)))
|
|
75042
75452
|
throw new Error("OMA receipt is outside the selected project/profile");
|
|
@@ -75051,7 +75461,7 @@ var HASH = /^[a-f0-9]{64}$/;
|
|
|
75051
75461
|
function createOmaEvidenceIO(options = {}) {
|
|
75052
75462
|
const env = { ...options.env ?? process.env, OMA_SKIP_VERSION_CHECK: "1" };
|
|
75053
75463
|
if (options.home !== undefined && !env.OMA_HOME)
|
|
75054
|
-
env.OMA_HOME =
|
|
75464
|
+
env.OMA_HOME = join39(options.home, ".oma");
|
|
75055
75465
|
const storage = { ...options, env };
|
|
75056
75466
|
return {
|
|
75057
75467
|
listRunFiles: (workspacePath) => listOmaRunFiles(workspacePath, storage),
|
|
@@ -75098,12 +75508,12 @@ async function prepareOmaAttempt(request, dependencies = {}) {
|
|
|
75098
75508
|
const routed = routeIssue(`${request.issue.title}
|
|
75099
75509
|
${request.issue.description ?? ""}`, table);
|
|
75100
75510
|
for (const workflow of routed.workflows) {
|
|
75101
|
-
const file =
|
|
75511
|
+
const file = join39(request.workspace.path, ".agents", "workflows", `${workflow}.md`);
|
|
75102
75512
|
if (!existsSync4(file))
|
|
75103
75513
|
throw new Error(`OMA workflow file missing in target worktree: ${file}`);
|
|
75104
75514
|
}
|
|
75105
75515
|
await ensureLatestOmaCli({ io: dependencies.latestCliIO });
|
|
75106
|
-
const path =
|
|
75516
|
+
const path = join39(request.workspace.path, ".agents", "results", `plan-${request.attempt.id}.json`);
|
|
75107
75517
|
const plan = {
|
|
75108
75518
|
session_id: request.attempt.id,
|
|
75109
75519
|
lineage_id: request.attempt.id,
|
|
@@ -75128,7 +75538,7 @@ ${request.issue.description ?? ""}`, table);
|
|
|
75128
75538
|
}
|
|
75129
75539
|
]
|
|
75130
75540
|
};
|
|
75131
|
-
await mkdir18(
|
|
75541
|
+
await mkdir18(join39(request.workspace.path, ".agents", "results"), { recursive: true });
|
|
75132
75542
|
await writeFile11(path, JSON.stringify(plan, null, 2), { encoding: "utf-8", flag: "wx" });
|
|
75133
75543
|
return path;
|
|
75134
75544
|
}
|
|
@@ -75237,10 +75647,10 @@ function validateOmaEvidence(request, io = createOmaEvidenceIO()) {
|
|
|
75237
75647
|
const expanded = template.replaceAll("{{attempt.id}}", request.attempt.id);
|
|
75238
75648
|
const target = resolve27(root, expanded);
|
|
75239
75649
|
const subpath = relative14(root, target);
|
|
75240
|
-
if (
|
|
75650
|
+
if (isAbsolute15(expanded) || expanded.split(/[\\/]/).includes("..") || subpath === "" || subpath === ".." || subpath.startsWith(`..${sep14}`) || isAbsolute15(subpath)) {
|
|
75241
75651
|
return fail("Configured analysis report escapes the workspace");
|
|
75242
75652
|
}
|
|
75243
|
-
if (!isRecord(run.artifacts) || !Object.entries(run.artifacts).some(([path, hash]) => !
|
|
75653
|
+
if (!isRecord(run.artifacts) || !Object.entries(run.artifacts).some(([path, hash]) => !isAbsolute15(path) && !path.split(/[\\/]/).includes("..") && resolve27(root, path) === target && HASH.test(String(hash)))) {
|
|
75244
75654
|
return fail("OMA receipt does not bind the configured current-attempt report");
|
|
75245
75655
|
}
|
|
75246
75656
|
}
|
|
@@ -75285,7 +75695,7 @@ import { posix } from "node:path";
|
|
|
75285
75695
|
// ../../packages/core/src/oma/skill-matrix-io.ts
|
|
75286
75696
|
init_skill_matrix_schema();
|
|
75287
75697
|
import { execFile as execFile5 } from "node:child_process";
|
|
75288
|
-
import { constants as
|
|
75698
|
+
import { constants as constants13 } from "node:fs";
|
|
75289
75699
|
import { open as open14 } from "node:fs/promises";
|
|
75290
75700
|
var MAX_BYTES = 4 * 1024 * 1024;
|
|
75291
75701
|
async function command(binary, args, signal) {
|
|
@@ -75305,7 +75715,7 @@ async function command(binary, args, signal) {
|
|
|
75305
75715
|
});
|
|
75306
75716
|
}
|
|
75307
75717
|
async function readReport(path) {
|
|
75308
|
-
const file = await open14(path,
|
|
75718
|
+
const file = await open14(path, constants13.O_RDONLY | constants13.O_NOFOLLOW | constants13.O_NONBLOCK);
|
|
75309
75719
|
try {
|
|
75310
75720
|
const info = await file.stat();
|
|
75311
75721
|
if (!info.isFile() || info.size > MAX_BYTES)
|
|
@@ -75488,13 +75898,12 @@ function assertCompatibleRoute(route, inspection) {
|
|
|
75488
75898
|
}
|
|
75489
75899
|
|
|
75490
75900
|
// ../../packages/core/src/chief/runtime.ts
|
|
75491
|
-
init_worktree_lifecycle();
|
|
75492
75901
|
init_execution();
|
|
75493
75902
|
|
|
75494
75903
|
// ../../packages/core/src/chief/parallel-workspace.ts
|
|
75495
75904
|
import { createHash as createHash25 } from "node:crypto";
|
|
75496
|
-
import { lstat as
|
|
75497
|
-
import { dirname as dirname10, join as
|
|
75905
|
+
import { lstat as lstat20, mkdir as mkdir19, readFile as readFile17, realpath as realpath24, rm as rm6, writeFile as writeFile12 } from "node:fs/promises";
|
|
75906
|
+
import { dirname as dirname10, join as join40, sep as sep15 } from "node:path";
|
|
75498
75907
|
init_parallel_contract();
|
|
75499
75908
|
|
|
75500
75909
|
// ../../packages/core/src/chief/workspace.ts
|
|
@@ -75525,7 +75934,7 @@ function identity3(missionId, taskId, attempt) {
|
|
|
75525
75934
|
async function paths(source, missionId, taskId, attempt) {
|
|
75526
75935
|
const root = await parallelRoot(source);
|
|
75527
75936
|
const key = identity3(missionId, taskId, attempt);
|
|
75528
|
-
const directory =
|
|
75937
|
+
const directory = join40(root, "deliveries", key);
|
|
75529
75938
|
await mkdir19(directory, { recursive: true, mode: 448 });
|
|
75530
75939
|
const actual = await realpath24(directory);
|
|
75531
75940
|
if (actual !== directory)
|
|
@@ -75533,10 +75942,10 @@ async function paths(source, missionId, taskId, attempt) {
|
|
|
75533
75942
|
return {
|
|
75534
75943
|
root,
|
|
75535
75944
|
directory: actual,
|
|
75536
|
-
path:
|
|
75537
|
-
record:
|
|
75538
|
-
delivery:
|
|
75539
|
-
patch:
|
|
75945
|
+
path: join40(root, "workspaces", key),
|
|
75946
|
+
record: join40(actual, "workspace.json"),
|
|
75947
|
+
delivery: join40(actual, "delivery.json"),
|
|
75948
|
+
patch: join40(actual, "changes.patch"),
|
|
75540
75949
|
branch: `av-task/${key}`
|
|
75541
75950
|
};
|
|
75542
75951
|
}
|
|
@@ -75562,7 +75971,7 @@ async function validateWorkspace(mission, workspace) {
|
|
|
75562
75971
|
async function prepareTaskWorktree(mission, taskId, attempt, baseline) {
|
|
75563
75972
|
await assertMissionWorkspace(mission);
|
|
75564
75973
|
const location2 = await paths(mission.workspace.path, mission.id, taskId, attempt);
|
|
75565
|
-
const existing = await
|
|
75974
|
+
const existing = await readFile17(location2.record, "utf8").catch((error) => {
|
|
75566
75975
|
if (error.code === "ENOENT")
|
|
75567
75976
|
return;
|
|
75568
75977
|
throw error;
|
|
@@ -75577,7 +75986,7 @@ async function prepareTaskWorktree(mission, taskId, attempt, baseline) {
|
|
|
75577
75986
|
await mkdir19(dirname10(location2.path), { recursive: true, mode: 448 });
|
|
75578
75987
|
if (await realpath24(dirname10(location2.path)) !== dirname10(location2.path))
|
|
75579
75988
|
throw new Error("Parallel workspaces directory must not redirect through a symlink.");
|
|
75580
|
-
if (await
|
|
75989
|
+
if (await lstat20(location2.path).catch(() => {
|
|
75581
75990
|
return;
|
|
75582
75991
|
}))
|
|
75583
75992
|
throw new Error(`Unrecorded parallel workspace exists at ${location2.path}. Preserve its edits and inspect it before retrying.`);
|
|
@@ -75621,7 +76030,7 @@ async function collectTaskDelivery(mission, workspace) {
|
|
|
75621
76030
|
const location2 = await paths(mission.workspace.path, mission.id, workspace.taskId, workspace.attempt);
|
|
75622
76031
|
if (workspace.path !== location2.path || workspace.branch !== location2.branch)
|
|
75623
76032
|
throw new Error("Restore the recorded private task workspace path and branch before resuming.");
|
|
75624
|
-
const existing = await
|
|
76033
|
+
const existing = await readFile17(location2.delivery, "utf8").catch((error) => {
|
|
75625
76034
|
if (error.code === "ENOENT")
|
|
75626
76035
|
return;
|
|
75627
76036
|
throw error;
|
|
@@ -75657,7 +76066,7 @@ async function collectTaskDelivery(mission, workspace) {
|
|
|
75657
76066
|
try {
|
|
75658
76067
|
await writeFile12(location2.patch, patch, { flag: "wx", mode: 384 });
|
|
75659
76068
|
} catch (error) {
|
|
75660
|
-
if (error.code !== "EEXIST" || !same(await
|
|
76069
|
+
if (error.code !== "EEXIST" || !same(await readFile17(location2.patch, "utf8"), patch))
|
|
75661
76070
|
throw error;
|
|
75662
76071
|
}
|
|
75663
76072
|
const delivery = {
|
|
@@ -75676,7 +76085,7 @@ async function integrateTaskDelivery(mission, input) {
|
|
|
75676
76085
|
await assertMissionWorkspace(mission);
|
|
75677
76086
|
parallelDeliverySchema.parse(input);
|
|
75678
76087
|
const location2 = await paths(mission.workspace.path, mission.id, input.workspace.taskId, input.workspace.attempt);
|
|
75679
|
-
const delivery = parallelDeliverySchema.parse(JSON.parse(await
|
|
76088
|
+
const delivery = parallelDeliverySchema.parse(JSON.parse(await readFile17(location2.delivery, "utf8")));
|
|
75680
76089
|
if (delivery.workspace.missionId !== mission.id || !same(delivery.workspace, input.workspace) || delivery.patchSha256 !== input.patchSha256 || delivery.patchPath !== location2.patch)
|
|
75681
76090
|
throw new Error("Parallel delivery does not match its persisted task identity and patch. Inspect the saved artifacts before recovery.");
|
|
75682
76091
|
const result = await integrateContentTransaction(mission.workspace.path, delivery, {
|
|
@@ -75689,7 +76098,7 @@ async function integrateTaskDelivery(mission, input) {
|
|
|
75689
76098
|
async function disposeTaskWorktree(workspace) {
|
|
75690
76099
|
parallelWorkspaceSchema.parse(workspace);
|
|
75691
76100
|
const location2 = await paths(workspace.sourceWorkspacePath, workspace.missionId, workspace.taskId, workspace.attempt);
|
|
75692
|
-
const raw = await
|
|
76101
|
+
const raw = await readFile17(location2.delivery, "utf8").catch(() => {
|
|
75693
76102
|
return;
|
|
75694
76103
|
});
|
|
75695
76104
|
if (!raw)
|
|
@@ -75704,7 +76113,7 @@ async function disposeTaskWorktree(workspace) {
|
|
|
75704
76113
|
assertParallelPath(location2.root, workspace.path);
|
|
75705
76114
|
if (workspace.path !== location2.path)
|
|
75706
76115
|
throw new Error("Refusing to remove an unrecognized parallel Actor workspace.");
|
|
75707
|
-
if (await
|
|
76116
|
+
if (await lstat20(workspace.path).catch(() => {
|
|
75708
76117
|
return;
|
|
75709
76118
|
})) {
|
|
75710
76119
|
const child = await captureParallelBaseline(workspace.path);
|
|
@@ -75722,8 +76131,34 @@ async function integrateTaskWorktree(mission, workspace) {
|
|
|
75722
76131
|
return integrateTaskDelivery(mission, await collectTaskDelivery(mission, workspace));
|
|
75723
76132
|
}
|
|
75724
76133
|
|
|
75725
|
-
// ../../packages/core/src/chief/runtime.ts
|
|
75726
|
-
|
|
76134
|
+
// ../../packages/core/src/chief/runtime-admission.ts
|
|
76135
|
+
async function admitNativeDispatch(mission, actor, attempt, stage, context, local, reason) {
|
|
76136
|
+
assertActorAvailable(mission, actor, stage);
|
|
76137
|
+
let entry;
|
|
76138
|
+
const claim = () => {
|
|
76139
|
+
if (entry)
|
|
76140
|
+
throw new Error("Native dispatch admission claimed the same Actor call twice.");
|
|
76141
|
+
assertActorAvailable(mission, actor, stage);
|
|
76142
|
+
entry = startOperatingRun(mission, actor, attempt, stage, context?.taskId, reason);
|
|
76143
|
+
entry.executionRecovery = local ? "local-process" : "reconcile";
|
|
76144
|
+
};
|
|
76145
|
+
try {
|
|
76146
|
+
if (context?.beforeDispatch)
|
|
76147
|
+
await context.beforeDispatch(claim);
|
|
76148
|
+
else
|
|
76149
|
+
claim();
|
|
76150
|
+
if (!entry)
|
|
76151
|
+
throw new Error("Native dispatch admission did not claim its Actor call.");
|
|
76152
|
+
return entry;
|
|
76153
|
+
} catch (error) {
|
|
76154
|
+
if (entry)
|
|
76155
|
+
mission.operations?.runs.splice(mission.operations.runs.indexOf(entry), 1);
|
|
76156
|
+
throw error;
|
|
76157
|
+
}
|
|
76158
|
+
}
|
|
76159
|
+
|
|
76160
|
+
// ../../packages/core/src/chief/runtime-inputs.ts
|
|
76161
|
+
init_worktree_lifecycle();
|
|
75727
76162
|
function missionIssue(id, goal) {
|
|
75728
76163
|
return {
|
|
75729
76164
|
id,
|
|
@@ -75743,9 +76178,8 @@ function missionIssue(id, goal) {
|
|
|
75743
76178
|
async function intermediateVerifyCommand(workspacePath) {
|
|
75744
76179
|
const head = await runCommand("git", ["rev-parse", "HEAD"], { cwd: workspacePath });
|
|
75745
76180
|
const hash = head.stdout.trim();
|
|
75746
|
-
if (head.exitCode !== 0 || !/^[a-f0-9]{40,64}$/.test(hash))
|
|
76181
|
+
if (head.exitCode !== 0 || !/^[a-f0-9]{40,64}$/.test(hash))
|
|
75747
76182
|
throw new Error("Cannot bind the OMA task check to its starting commit. Restore the mission worktree's Git HEAD before resuming.");
|
|
75748
|
-
}
|
|
75749
76183
|
return `git diff --check ${hash} --`;
|
|
75750
76184
|
}
|
|
75751
76185
|
async function personaSkills(persona, mission, stage) {
|
|
@@ -75754,9 +76188,8 @@ async function personaSkills(persona, mission, stage) {
|
|
|
75754
76188
|
await validateMissionSkills(mission.workspace.path, catalog);
|
|
75755
76189
|
const selected = await loadMissionSkillBodies(mission.workspace.path, persona.skills, mission.availableAgents ? catalog : undefined);
|
|
75756
76190
|
const guidance = [];
|
|
75757
|
-
if (persona.id === mission.chiefId)
|
|
76191
|
+
if (persona.id === mission.chiefId)
|
|
75758
76192
|
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.");
|
|
75759
|
-
}
|
|
75760
76193
|
if (selected)
|
|
75761
76194
|
guidance.push("Use these selected skills within the assigned role and acceptance criteria.", selected);
|
|
75762
76195
|
if (guidance.length && stage !== "work")
|
|
@@ -75767,7 +76200,17 @@ ${guidance.join(`
|
|
|
75767
76200
|
|
|
75768
76201
|
`)}` : "";
|
|
75769
76202
|
}
|
|
76203
|
+
function unattendedVerificationGuidance(stage) {
|
|
76204
|
+
return [
|
|
76205
|
+
"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.",
|
|
76206
|
+
"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.",
|
|
76207
|
+
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."
|
|
76208
|
+
].join(`
|
|
76209
|
+
`);
|
|
76210
|
+
}
|
|
75770
76211
|
|
|
76212
|
+
// ../../packages/core/src/chief/runtime.ts
|
|
76213
|
+
init_tool_environment();
|
|
75771
76214
|
class ChiefRuntime {
|
|
75772
76215
|
store;
|
|
75773
76216
|
signal;
|
|
@@ -75791,6 +76234,7 @@ class ChiefRuntime {
|
|
|
75791
76234
|
ports() {
|
|
75792
76235
|
return {
|
|
75793
76236
|
signal: this.signal,
|
|
76237
|
+
deferredDispatchAdmission: true,
|
|
75794
76238
|
...this.discoverReadyAgents ? { discoverReadyAgents: this.discoverReadyAgents } : {},
|
|
75795
76239
|
...this.discoverFreeModels ? { discoverFreeModels: this.discoverFreeModels } : {},
|
|
75796
76240
|
prepareWork: (persona, mission, context) => this.prepareWork(persona, mission, context),
|
|
@@ -75828,7 +76272,7 @@ class ChiefRuntime {
|
|
|
75828
76272
|
const workspace = context?.workspace ?? mission.workspace;
|
|
75829
76273
|
const savedCatalog = workspace === mission.workspace ? mission.availableSkills : mission.availableSkills?.map((skill) => ({
|
|
75830
76274
|
...skill,
|
|
75831
|
-
path:
|
|
76275
|
+
path: join41(workspace.path, ".agents", "skills", skill.name, "SKILL.md")
|
|
75832
76276
|
}));
|
|
75833
76277
|
const catalog = savedCatalog ?? await discoverMissionSkills(workspace.path);
|
|
75834
76278
|
if (!requiresOmaActor({ oma: mission.oma, availableSkills: catalog }))
|
|
@@ -75877,6 +76321,7 @@ class ChiefRuntime {
|
|
|
75877
76321
|
async executeAgent(persona, prompt, mission, stage, context) {
|
|
75878
76322
|
const signal = context?.signal ?? this.signal;
|
|
75879
76323
|
const workspace = context?.workspace ?? mission.workspace;
|
|
76324
|
+
const requestedPersona = persona;
|
|
75880
76325
|
if (stage === "plan" && mission.availableSkills === undefined) {
|
|
75881
76326
|
signal?.throwIfAborted();
|
|
75882
76327
|
mission.availableSkills = await discoverMissionSkills(mission.workspace.path);
|
|
@@ -75886,7 +76331,7 @@ class ChiefRuntime {
|
|
|
75886
76331
|
workspace,
|
|
75887
76332
|
availableSkills: mission.availableSkills?.map((skill) => ({
|
|
75888
76333
|
...skill,
|
|
75889
|
-
path:
|
|
76334
|
+
path: join41(workspace.path, ".agents", "skills", skill.name, "SKILL.md")
|
|
75890
76335
|
}))
|
|
75891
76336
|
};
|
|
75892
76337
|
if (signal?.aborted)
|
|
@@ -75902,13 +76347,12 @@ class ChiefRuntime {
|
|
|
75902
76347
|
message: `${compatibilityPolicy.mode}: ${compatibility.routes.map((entry) => `${entry.actorType}/${entry.model ?? "native default"} ${entry.status}: ${entry.reason}`).join("; ")} Scope: ${compatibility.scope}.`,
|
|
75903
76348
|
...context?.taskId ? { taskId: context.taskId } : {}
|
|
75904
76349
|
});
|
|
75905
|
-
|
|
76350
|
+
let route = context?.handoff ? { actor: persona, reason: context.handoff } : stage === "work" ? selectWorkActor(mission, persona, context?.taskId, compatibleRoutes) : undefined;
|
|
75906
76351
|
persona = route?.actor ?? persona;
|
|
75907
76352
|
if (compatibility && compatibilityPolicy) {
|
|
75908
76353
|
if (compatibilityPolicy.mode === "require")
|
|
75909
76354
|
assertCompatibleRoute({ actorType: persona.agentType, model: persona.model }, compatibility);
|
|
75910
76355
|
}
|
|
75911
|
-
this.onStage(stage, persona);
|
|
75912
76356
|
const attempt = {
|
|
75913
76357
|
id: randomUUID16(),
|
|
75914
76358
|
issueId: mission.id,
|
|
@@ -75931,6 +76375,9 @@ class ChiefRuntime {
|
|
|
75931
76375
|
|
|
75932
76376
|
${buildOmaGuidance(evidence)}`;
|
|
75933
76377
|
}
|
|
76378
|
+
prompt += `
|
|
76379
|
+
|
|
76380
|
+
${unattendedVerificationGuidance(stage)}`;
|
|
75934
76381
|
prompt += omaActor ? `
|
|
75935
76382
|
|
|
75936
76383
|
${omaActor.guidance}` : await personaSkills(persona, localMission, stage);
|
|
@@ -75941,12 +76388,16 @@ The operator explicitly forwards these tool environment variable names: ${JSON.s
|
|
|
75941
76388
|
prompt += `
|
|
75942
76389
|
|
|
75943
76390
|
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.`;
|
|
76391
|
+
if (stage === "work" && !context?.handoff) {
|
|
76392
|
+
route = selectWorkActor(mission, requestedPersona, context?.taskId, compatibleRoutes);
|
|
76393
|
+
persona = route.actor;
|
|
76394
|
+
}
|
|
76395
|
+
this.onStage(stage, persona);
|
|
75944
76396
|
if (route)
|
|
75945
76397
|
prompt += `
|
|
75946
76398
|
|
|
75947
76399
|
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.`;
|
|
75948
|
-
const entry =
|
|
75949
|
-
entry.executionRecovery = this.localExecution ? "local-process" : "reconcile";
|
|
76400
|
+
const entry = await admitNativeDispatch(mission, persona, attempt, stage, context, this.localExecution, route?.reason);
|
|
75950
76401
|
let run;
|
|
75951
76402
|
if (omaActor)
|
|
75952
76403
|
mission.history.push({
|
|
@@ -75993,6 +76444,7 @@ Actual work route: ${JSON.stringify({ actorType: persona.agentType, model: perso
|
|
|
75993
76444
|
throw new AgentRunError("Runtime returned incomplete terminal evidence. Reconcile the execution before resuming.", attempt, { outcomeUnknown: true });
|
|
75994
76445
|
observed = completed;
|
|
75995
76446
|
executionSettled = true;
|
|
76447
|
+
entry.nativeOutcome = completed.exitCode === 0 ? "passed" : "failed";
|
|
75996
76448
|
if (completed.exitCode !== 0)
|
|
75997
76449
|
throw new AgentRunError("Runtime execution did not complete successfully. Inspect the failed attempt before retrying.", completed);
|
|
75998
76450
|
if (mission.oma && stage === "work") {
|
|
@@ -76008,11 +76460,14 @@ Actual work route: ${JSON.stringify({ actorType: persona.agentType, model: perso
|
|
|
76008
76460
|
try {
|
|
76009
76461
|
observed = this.observeAttempt(attempt, error.attempt);
|
|
76010
76462
|
executionSettled = !error.outcomeUnknown;
|
|
76463
|
+
if (executionSettled)
|
|
76464
|
+
entry.nativeOutcome = "failed";
|
|
76011
76465
|
} catch (identityError) {
|
|
76012
76466
|
error = identityError;
|
|
76013
76467
|
}
|
|
76014
76468
|
}
|
|
76015
76469
|
failure = error;
|
|
76470
|
+
entry.evidence = (error instanceof Error ? error.message : String(error)).slice(-2000);
|
|
76016
76471
|
if (error instanceof AgentRunError && error.outcomeUnknown || !this.localExecution && !executionSettled) {
|
|
76017
76472
|
markOperatingRunUnknown(entry, error instanceof Error ? error.message : String(error));
|
|
76018
76473
|
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");
|
|
@@ -76030,6 +76485,10 @@ Actual work route: ${JSON.stringify({ actorType: persona.agentType, model: perso
|
|
|
76030
76485
|
if (run)
|
|
76031
76486
|
this.runs.delete(run);
|
|
76032
76487
|
finishOperatingRun(mission, entry, observed, failed);
|
|
76488
|
+
if (entry.executionState === "unknown")
|
|
76489
|
+
delete entry.nativeOutcome;
|
|
76490
|
+
else if (signal?.aborted)
|
|
76491
|
+
entry.nativeOutcome = "cancelled";
|
|
76033
76492
|
await this.store.save(mission);
|
|
76034
76493
|
}
|
|
76035
76494
|
if (failed)
|
|
@@ -76556,15 +77015,15 @@ init_execution();
|
|
|
76556
77015
|
|
|
76557
77016
|
// src/chief-supervisor.ts
|
|
76558
77017
|
import { randomUUID as randomUUID17 } from "node:crypto";
|
|
76559
|
-
import { join as
|
|
77018
|
+
import { join as join45 } from "node:path";
|
|
76560
77019
|
init_execution();
|
|
76561
77020
|
// src/chief-delivery.ts
|
|
76562
77021
|
import { createHash as createHash28 } from "node:crypto";
|
|
76563
77022
|
import { mkdir as mkdir21, writeFile as writeFile13 } from "node:fs/promises";
|
|
76564
|
-
import { join as
|
|
77023
|
+
import { join as join44 } from "node:path";
|
|
76565
77024
|
|
|
76566
77025
|
// ../../packages/core/src/chief/report-delivery.ts
|
|
76567
|
-
import { join as
|
|
77026
|
+
import { join as join43 } from "node:path";
|
|
76568
77027
|
|
|
76569
77028
|
// ../../packages/core/src/chief/report-delivery-adapters.ts
|
|
76570
77029
|
init_report_delivery_contract();
|
|
@@ -76947,9 +77406,9 @@ init_zod();
|
|
|
76947
77406
|
init_atomic_json();
|
|
76948
77407
|
init_report_delivery_contract();
|
|
76949
77408
|
import { createHash as createHash27 } from "node:crypto";
|
|
76950
|
-
import { constants as
|
|
76951
|
-
import { mkdir as mkdir20, open as open15, readdir as
|
|
76952
|
-
import { isAbsolute as
|
|
77409
|
+
import { constants as constants14 } from "node:fs";
|
|
77410
|
+
import { mkdir as mkdir20, open as open15, readdir as readdir12, readFile as readFile18, realpath as realpath25 } from "node:fs/promises";
|
|
77411
|
+
import { isAbsolute as isAbsolute16, join as join42, relative as relative15, resolve as resolve29 } from "node:path";
|
|
76953
77412
|
var hash3 = string2().regex(/^[a-f0-9]{64}$/);
|
|
76954
77413
|
var outboxRecordSchema = strictObject({
|
|
76955
77414
|
version: literal(1),
|
|
@@ -76991,12 +77450,12 @@ function receipt(record) {
|
|
|
76991
77450
|
class ReportOutbox {
|
|
76992
77451
|
directory;
|
|
76993
77452
|
constructor(stateDir) {
|
|
76994
|
-
this.directory =
|
|
77453
|
+
this.directory = join42(stateDir, "report-outbox");
|
|
76995
77454
|
}
|
|
76996
77455
|
path(id) {
|
|
76997
77456
|
if (!hash3.safeParse(id).success)
|
|
76998
77457
|
throw new Error("Invalid report receipt ID. Use av reports to find a receipt.");
|
|
76999
|
-
return
|
|
77458
|
+
return join42(this.directory, `${id}.json`);
|
|
77000
77459
|
}
|
|
77001
77460
|
lock(id) {
|
|
77002
77461
|
return new MissionStore(this.directory).lock(id);
|
|
@@ -77004,7 +77463,7 @@ class ReportOutbox {
|
|
|
77004
77463
|
async load(id) {
|
|
77005
77464
|
let content;
|
|
77006
77465
|
try {
|
|
77007
|
-
content = await
|
|
77466
|
+
content = await readFile18(this.path(id), "utf8");
|
|
77008
77467
|
} catch (error) {
|
|
77009
77468
|
if (error.code === "ENOENT")
|
|
77010
77469
|
return null;
|
|
@@ -77025,7 +77484,7 @@ class ReportOutbox {
|
|
|
77025
77484
|
await writeJsonAtomic(this.path(record.id), record);
|
|
77026
77485
|
}
|
|
77027
77486
|
async list() {
|
|
77028
|
-
const names = await
|
|
77487
|
+
const names = await readdir12(this.directory).catch((error) => {
|
|
77029
77488
|
if (error.code === "ENOENT")
|
|
77030
77489
|
return [];
|
|
77031
77490
|
throw new Error("Cannot list report outbox. Restore access to the Chief Director state directory.");
|
|
@@ -77046,11 +77505,11 @@ async function verifiedAttachment(attachment, artifactRoot, readBytes) {
|
|
|
77046
77505
|
const root = await realpath25(artifactRoot);
|
|
77047
77506
|
const path = await realpath25(attachment.path);
|
|
77048
77507
|
const local = relative15(root, path);
|
|
77049
|
-
if (!local || local.startsWith(`..${process.platform === "win32" ? "\\" : "/"}`) || local === ".." ||
|
|
77508
|
+
if (!local || local.startsWith(`..${process.platform === "win32" ? "\\" : "/"}`) || local === ".." || isAbsolute16(local))
|
|
77050
77509
|
throw failure;
|
|
77051
77510
|
if (resolve29(attachment.path) !== attachment.path)
|
|
77052
77511
|
throw failure;
|
|
77053
|
-
const file = await open15(attachment.path,
|
|
77512
|
+
const file = await open15(attachment.path, constants14.O_RDONLY | constants14.O_NOFOLLOW);
|
|
77054
77513
|
try {
|
|
77055
77514
|
const stat = await file.stat();
|
|
77056
77515
|
if (!stat.isFile() || stat.size !== attachment.sizeBytes)
|
|
@@ -77103,7 +77562,7 @@ function dependencies(stateDir, overrides) {
|
|
|
77103
77562
|
env: overrides.env ?? process.env,
|
|
77104
77563
|
registry: { ...createReportChannelRegistry(fetch2), ...overrides.registry },
|
|
77105
77564
|
attachments: overrides.attachments ?? [],
|
|
77106
|
-
artifactRoot: overrides.artifactRoot ??
|
|
77565
|
+
artifactRoot: overrides.artifactRoot ?? join43(stateDir, "captures"),
|
|
77107
77566
|
now: overrides.now ?? (() => new Date)
|
|
77108
77567
|
};
|
|
77109
77568
|
}
|
|
@@ -77284,8 +77743,8 @@ init_chief_schema();
|
|
|
77284
77743
|
init_yaml_loader();
|
|
77285
77744
|
async function saveAndDeliverMissionReport(mission, root) {
|
|
77286
77745
|
const repository = mission.repositoryRoot ?? root;
|
|
77287
|
-
const directory =
|
|
77288
|
-
const reportPath =
|
|
77746
|
+
const directory = join44(root, ".agent-valley/reports");
|
|
77747
|
+
const reportPath = join44(directory, `${mission.id}.md`);
|
|
77289
77748
|
const report = renderReport(mission);
|
|
77290
77749
|
await mkdir21(directory, { recursive: true, mode: 448 });
|
|
77291
77750
|
await writeFile13(reportPath, report, { mode: 384 });
|
|
@@ -77300,12 +77759,12 @@ ${explanation.eli5}`);
|
|
|
77300
77759
|
try {
|
|
77301
77760
|
const config = mergeChiefConfig(loadGlobalConfig()?.chief, loadProjectConfig(root)?.chief);
|
|
77302
77761
|
const attachments = [...mission.capture?.attachments ?? []];
|
|
77303
|
-
const artifactRoot =
|
|
77762
|
+
const artifactRoot = join44(repository, ".agent-valley/captures");
|
|
77304
77763
|
if (config.reporting?.destinations.length) {
|
|
77305
77764
|
const bytes = Buffer.from(report);
|
|
77306
77765
|
const sha256 = createHash28("sha256").update(bytes).digest("hex");
|
|
77307
|
-
const reportDirectory =
|
|
77308
|
-
const attachmentPath =
|
|
77766
|
+
const reportDirectory = join44(artifactRoot, mission.id);
|
|
77767
|
+
const attachmentPath = join44(reportDirectory, `report-${sha256}.md`);
|
|
77309
77768
|
await mkdir21(reportDirectory, { recursive: true, mode: 448 });
|
|
77310
77769
|
await writeFile13(attachmentPath, bytes, { mode: 384 });
|
|
77311
77770
|
attachments.push({
|
|
@@ -77316,7 +77775,7 @@ ${explanation.eli5}`);
|
|
|
77316
77775
|
sha256
|
|
77317
77776
|
});
|
|
77318
77777
|
}
|
|
77319
|
-
const receipts = await dispatchMissionReport(mission, report, reportPath, config.reporting,
|
|
77778
|
+
const receipts = await dispatchMissionReport(mission, report, reportPath, config.reporting, join44(repository, ".agent-valley"), {
|
|
77320
77779
|
attachments,
|
|
77321
77780
|
artifactRoot
|
|
77322
77781
|
});
|
|
@@ -77570,7 +78029,7 @@ function abortableDelay(ms, signal) {
|
|
|
77570
78029
|
async function superviseOrder(goal, options, root, dependencies = {}) {
|
|
77571
78030
|
assertNotManagedRun();
|
|
77572
78031
|
const id = options.resume ?? options.missionId ?? randomUUID17();
|
|
77573
|
-
const store = new MissionStore(
|
|
78032
|
+
const store = new MissionStore(join45(root, ".agent-valley/missions"));
|
|
77574
78033
|
const controller = new AbortController;
|
|
77575
78034
|
const interrupt = () => controller.abort(dependencies.signal?.reason);
|
|
77576
78035
|
const terminate = () => controller.abort(options.service ? serviceShutdownPause() : undefined);
|
|
@@ -77910,8 +78369,8 @@ init_base_session();
|
|
|
77910
78369
|
init_sandbox_binary();
|
|
77911
78370
|
init_agent_discovery();
|
|
77912
78371
|
import { readFileSync as readFileSync10, statSync as statSync4 } from "node:fs";
|
|
77913
|
-
import { homedir as
|
|
77914
|
-
import { join as
|
|
78372
|
+
import { homedir as homedir9 } from "node:os";
|
|
78373
|
+
import { join as join46 } from "node:path";
|
|
77915
78374
|
import { stripVTControlCharacters as stripVTControlCharacters4 } from "node:util";
|
|
77916
78375
|
var MAX_OUTPUT_BYTES5 = 2097152;
|
|
77917
78376
|
var PROBE_TIMEOUT_MS2 = 15000;
|
|
@@ -78036,8 +78495,8 @@ async function discoverFreeModels(agentType, workspacePath, signal, overrides =
|
|
|
78036
78495
|
};
|
|
78037
78496
|
let state;
|
|
78038
78497
|
try {
|
|
78039
|
-
const home = env.XDG_STATE_HOME ||
|
|
78040
|
-
const content = deps.readState(
|
|
78498
|
+
const home = env.XDG_STATE_HOME || join46(env.HOME || homedir9(), ".local", "state");
|
|
78499
|
+
const content = deps.readState(join46(home, "opencode", "model.json"));
|
|
78041
78500
|
state = content && Buffer.byteLength(content) <= MAX_OUTPUT_BYTES5 ? JSON.parse(content) : undefined;
|
|
78042
78501
|
} catch {
|
|
78043
78502
|
state = undefined;
|
|
@@ -78066,9 +78525,9 @@ async function discoverFreeModels(agentType, workspacePath, signal, overrides =
|
|
|
78066
78525
|
|
|
78067
78526
|
// ../../packages/core/src/chief/metric-source-adapters.ts
|
|
78068
78527
|
init_metric_source_policy();
|
|
78069
|
-
import { constants as
|
|
78070
|
-
import { lstat as
|
|
78071
|
-
import { isAbsolute as
|
|
78528
|
+
import { constants as constants15 } from "node:fs";
|
|
78529
|
+
import { lstat as lstat21, open as open16, realpath as realpath26 } from "node:fs/promises";
|
|
78530
|
+
import { isAbsolute as isAbsolute17, relative as relative16, resolve as resolve30, sep as sep16 } from "node:path";
|
|
78072
78531
|
var MAX_METRIC_RESPONSE_BYTES = 2000000;
|
|
78073
78532
|
function metricSourceEnvironment(request, name) {
|
|
78074
78533
|
if (!name || !request.env[name]?.trim())
|
|
@@ -78153,19 +78612,19 @@ var jsonFileMetricAdapter = {
|
|
|
78153
78612
|
async collect(request) {
|
|
78154
78613
|
const root = await realpath26(request.repositoryRoot);
|
|
78155
78614
|
const name = request.source.file;
|
|
78156
|
-
if (!name ||
|
|
78615
|
+
if (!name || isAbsolute17(name))
|
|
78157
78616
|
throw new MetricSourceError("Metric file must be relative to the source repository. Set chief.metric_sources.sources[].file in av.yaml.");
|
|
78158
78617
|
const path = resolve30(root, name);
|
|
78159
78618
|
const within = relative16(root, path);
|
|
78160
|
-
if (!within || within.startsWith(`..${sep16}`) || within === ".." ||
|
|
78619
|
+
if (!within || within.startsWith(`..${sep16}`) || within === ".." || isAbsolute17(within))
|
|
78161
78620
|
throw new MetricSourceError("Metric file escapes the source repository. Choose a repository-relative JSON file.");
|
|
78162
78621
|
let current = root;
|
|
78163
78622
|
for (const part of within.split(sep16)) {
|
|
78164
78623
|
current = resolve30(current, part);
|
|
78165
|
-
if ((await
|
|
78624
|
+
if ((await lstat21(current)).isSymbolicLink())
|
|
78166
78625
|
throw new MetricSourceError("Metric file and parent directories must not be symlinks. Choose a regular JSON file inside the source repository.");
|
|
78167
78626
|
}
|
|
78168
|
-
const file = await open16(path,
|
|
78627
|
+
const file = await open16(path, constants15.O_RDONLY | constants15.O_NOFOLLOW);
|
|
78169
78628
|
try {
|
|
78170
78629
|
const stat = await file.stat();
|
|
78171
78630
|
if (!stat.isFile() || stat.size > MAX_METRIC_RESPONSE_BYTES || await realpath26(path) !== path)
|
|
@@ -78566,9 +79025,9 @@ function createMissionMetricPorts(repository, mission, dependencies = {}) {
|
|
|
78566
79025
|
|
|
78567
79026
|
// src/chief-tool-config.ts
|
|
78568
79027
|
import { randomUUID as randomUUID19 } from "node:crypto";
|
|
78569
|
-
import { constants as
|
|
78570
|
-
import { link as link2, lstat as
|
|
78571
|
-
import { join as
|
|
79028
|
+
import { constants as constants16 } from "node:fs";
|
|
79029
|
+
import { link as link2, lstat as lstat22, mkdir as mkdir22, open as open17, realpath as realpath27, unlink as unlink5 } from "node:fs/promises";
|
|
79030
|
+
import { join as join47 } from "node:path";
|
|
78572
79031
|
init_dist2();
|
|
78573
79032
|
init_client_toml();
|
|
78574
79033
|
var maximumBytes = 1024 * 1024;
|
|
@@ -78587,8 +79046,8 @@ async function assertLocalPath(root, local) {
|
|
|
78587
79046
|
const parts = local.split("/");
|
|
78588
79047
|
let current = root;
|
|
78589
79048
|
for (const [index, part] of parts.entries()) {
|
|
78590
|
-
current =
|
|
78591
|
-
const stats = await
|
|
79049
|
+
current = join47(current, part);
|
|
79050
|
+
const stats = await lstat22(current).catch((error) => {
|
|
78592
79051
|
if (error.code === "ENOENT")
|
|
78593
79052
|
return;
|
|
78594
79053
|
throw error;
|
|
@@ -78601,7 +79060,7 @@ async function assertLocalPath(root, local) {
|
|
|
78601
79060
|
return true;
|
|
78602
79061
|
}
|
|
78603
79062
|
async function readPrivateFile(path) {
|
|
78604
|
-
const file = await open17(path,
|
|
79063
|
+
const file = await open17(path, constants16.O_RDONLY | constants16.O_NOFOLLOW);
|
|
78605
79064
|
try {
|
|
78606
79065
|
const stats = await file.stat();
|
|
78607
79066
|
if (!stats.isFile() || stats.size > maximumBytes)
|
|
@@ -78644,10 +79103,10 @@ async function privateExclude(original, target, paths) {
|
|
|
78644
79103
|
]);
|
|
78645
79104
|
const common = targetCommon.trim();
|
|
78646
79105
|
const path = exclude.trim();
|
|
78647
|
-
if (common !==
|
|
79106
|
+
if (common !== join47(target, ".git") && common !== originalCommon.trim() || path !== join47(common, "info", "exclude") || await realpath27(common) !== common)
|
|
78648
79107
|
throw new ChiefToolConfigError("Chief MCP configuration requires the workspace's own Git metadata or its original repository's shared worktree metadata.");
|
|
78649
|
-
const info =
|
|
78650
|
-
const infoStats = await
|
|
79108
|
+
const info = join47(common, "info");
|
|
79109
|
+
const infoStats = await lstat22(info).catch((error) => {
|
|
78651
79110
|
if (error.code === "ENOENT")
|
|
78652
79111
|
return;
|
|
78653
79112
|
throw error;
|
|
@@ -78664,7 +79123,7 @@ async function privateExclude(original, target, paths) {
|
|
|
78664
79123
|
const patterns = paths.flatMap((local) => [`/${local}`, `/${local}.av-mcp-*.tmp`]).filter((pattern) => !lines.has(pattern));
|
|
78665
79124
|
if (!patterns.length)
|
|
78666
79125
|
return;
|
|
78667
|
-
const file = await open17(path,
|
|
79126
|
+
const file = await open17(path, constants16.O_WRONLY | constants16.O_APPEND | constants16.O_CREAT | constants16.O_NOFOLLOW, 384);
|
|
78668
79127
|
try {
|
|
78669
79128
|
await file.writeFile(`${content && !content.endsWith(`
|
|
78670
79129
|
`) ? `
|
|
@@ -78685,14 +79144,14 @@ async function prepareToolConfig(originalRepository, targetWorkspace) {
|
|
|
78685
79144
|
continue;
|
|
78686
79145
|
if (!await assertLocalPath(original, config.path))
|
|
78687
79146
|
continue;
|
|
78688
|
-
const content = selectedNamespace(await readPrivateFile(
|
|
79147
|
+
const content = selectedNamespace(await readPrivateFile(join47(original, config.path)), config.namespace, config.toml);
|
|
78689
79148
|
if (content)
|
|
78690
79149
|
selected.push({ path: config.path, content });
|
|
78691
79150
|
}
|
|
78692
79151
|
if (!selected.length)
|
|
78693
79152
|
return;
|
|
78694
79153
|
for (const root of [original, target]) {
|
|
78695
|
-
const stats = await
|
|
79154
|
+
const stats = await lstat22(join47(root, ".git"));
|
|
78696
79155
|
if (stats.isSymbolicLink() || !stats.isFile() && !stats.isDirectory() || await realpath27((await parallelGit(root, ["rev-parse", "--show-toplevel"])).trim()) !== root)
|
|
78697
79156
|
throw new ChiefToolConfigError("Chief MCP tools require original local Git repository metadata. Restore the workspace before starting Chief.");
|
|
78698
79157
|
}
|
|
@@ -78700,14 +79159,14 @@ async function prepareToolConfig(originalRepository, targetWorkspace) {
|
|
|
78700
79159
|
for (const config of selected) {
|
|
78701
79160
|
const parts = config.path.split("/");
|
|
78702
79161
|
if (parts.length > 1) {
|
|
78703
|
-
const parent =
|
|
79162
|
+
const parent = join47(target, ...parts.slice(0, -1));
|
|
78704
79163
|
await mkdir22(parent, { recursive: true, mode: 448 });
|
|
78705
79164
|
if (await realpath27(parent) !== parent)
|
|
78706
79165
|
throw new ChiefToolConfigError("Chief MCP configuration parent redirects through a symlink. Restore its local directory.");
|
|
78707
79166
|
}
|
|
78708
79167
|
if (await assertLocalPath(target, config.path))
|
|
78709
79168
|
continue;
|
|
78710
|
-
const path =
|
|
79169
|
+
const path = join47(target, config.path);
|
|
78711
79170
|
const temporary = `${path}.av-mcp-${randomUUID19()}.tmp`;
|
|
78712
79171
|
const file = await open17(temporary, "wx", 384);
|
|
78713
79172
|
try {
|
|
@@ -78738,10 +79197,10 @@ async function prepareChiefToolConfig(originalRepository, targetWorkspace) {
|
|
|
78738
79197
|
|
|
78739
79198
|
// src/tool-discovery.ts
|
|
78740
79199
|
init_client_toml();
|
|
78741
|
-
import { constants as
|
|
78742
|
-
import { access, lstat as
|
|
78743
|
-
import { homedir as
|
|
78744
|
-
import { delimiter as
|
|
79200
|
+
import { constants as constants17 } from "node:fs";
|
|
79201
|
+
import { access as access2, lstat as lstat23, readFile as readFile19, realpath as realpath28 } from "node:fs/promises";
|
|
79202
|
+
import { homedir as homedir10 } from "node:os";
|
|
79203
|
+
import { delimiter as delimiter3, isAbsolute as isAbsolute18, join as join48, resolve as resolve31 } from "node:path";
|
|
78745
79204
|
var binaries = [
|
|
78746
79205
|
"docker",
|
|
78747
79206
|
"orb",
|
|
@@ -78756,12 +79215,12 @@ var binaries = [
|
|
|
78756
79215
|
];
|
|
78757
79216
|
var MAX_CONFIG_BYTES = 1048576;
|
|
78758
79217
|
var record5 = (value) => value !== null && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
78759
|
-
async function
|
|
78760
|
-
for (const directory of (env.PATH ?? "").split(
|
|
79218
|
+
async function executable2(name, env) {
|
|
79219
|
+
for (const directory of (env.PATH ?? "").split(delimiter3).filter(isAbsolute18)) {
|
|
78761
79220
|
try {
|
|
78762
|
-
const path =
|
|
78763
|
-
await
|
|
78764
|
-
if ((await
|
|
79221
|
+
const path = join48(directory, name);
|
|
79222
|
+
await access2(path, constants17.X_OK);
|
|
79223
|
+
if ((await lstat23(await realpath28(path))).isFile())
|
|
78765
79224
|
return true;
|
|
78766
79225
|
} catch {}
|
|
78767
79226
|
}
|
|
@@ -78770,10 +79229,10 @@ async function executable(name, env) {
|
|
|
78770
79229
|
async function mcpNames(path, scope, project, requestedRoot) {
|
|
78771
79230
|
const base = { kind: "mcp", scope, authentication: "unknown", source: path };
|
|
78772
79231
|
try {
|
|
78773
|
-
const info = await
|
|
79232
|
+
const info = await lstat23(path);
|
|
78774
79233
|
if (!info.isFile() || info.isSymbolicLink() || info.size > MAX_CONFIG_BYTES)
|
|
78775
79234
|
throw new Error("Invalid config");
|
|
78776
|
-
const source = await
|
|
79235
|
+
const source = await readFile19(path, "utf8");
|
|
78777
79236
|
if (Buffer.byteLength(source) > MAX_CONFIG_BYTES)
|
|
78778
79237
|
throw new Error("Invalid config");
|
|
78779
79238
|
const config = record5(path.endsWith(".toml") ? parseClientToml(source) : JSON.parse(source));
|
|
@@ -78813,7 +79272,7 @@ async function mcpNames(path, scope, project, requestedRoot) {
|
|
|
78813
79272
|
}
|
|
78814
79273
|
async function discoverTools(root, dependencies = {}) {
|
|
78815
79274
|
const env = dependencies.env ?? process.env;
|
|
78816
|
-
const home = dependencies.home ??
|
|
79275
|
+
const home = dependencies.home ?? homedir10();
|
|
78817
79276
|
const project = await realpath28(root);
|
|
78818
79277
|
const projectFiles = [
|
|
78819
79278
|
".mcp.json",
|
|
@@ -78824,11 +79283,11 @@ async function discoverTools(root, dependencies = {}) {
|
|
|
78824
79283
|
".codex/config.toml"
|
|
78825
79284
|
];
|
|
78826
79285
|
const userFiles = [".claude.json", ".cursor/mcp.json", ".qwen/settings.json", ".gemini/settings.json"];
|
|
78827
|
-
const codexHome = env.CODEX_HOME &&
|
|
79286
|
+
const codexHome = env.CODEX_HOME && isAbsolute18(env.CODEX_HOME) ? env.CODEX_HOME : join48(home, ".codex");
|
|
78828
79287
|
const configs = [
|
|
78829
|
-
...projectFiles.map((path) => ({ path:
|
|
79288
|
+
...projectFiles.map((path) => ({ path: join48(project, path), scope: "project" })),
|
|
78830
79289
|
...userFiles.map((path) => ({ path: resolve31(home, path), scope: "user" })),
|
|
78831
|
-
{ path:
|
|
79290
|
+
{ path: join48(codexHome, "config.toml"), scope: "user" }
|
|
78832
79291
|
];
|
|
78833
79292
|
const [cli, mcp] = await Promise.all([
|
|
78834
79293
|
Promise.all(binaries.map(async (name) => ({
|
|
@@ -78837,7 +79296,7 @@ async function discoverTools(root, dependencies = {}) {
|
|
|
78837
79296
|
kind: "cli",
|
|
78838
79297
|
scope: "user",
|
|
78839
79298
|
authentication: "unknown",
|
|
78840
|
-
availability: await
|
|
79299
|
+
availability: await executable2(name, env) ? "available" : "unavailable",
|
|
78841
79300
|
reason: "Executable presence only; service access, daemon state and login are unverified."
|
|
78842
79301
|
}))),
|
|
78843
79302
|
Promise.all(configs.map(({ path, scope }) => mcpNames(path, scope, project, resolve31(root))))
|
|
@@ -78875,7 +79334,7 @@ function continuousDecisionPrompt(operation, mission, tools, previousReport) {
|
|
|
78875
79334
|
async function decideContinuousGoal(operation, decisionId, root, dependencies = {}) {
|
|
78876
79335
|
if (!operation.baseline)
|
|
78877
79336
|
throw new Error("An accepted operation baseline is required before selecting a goal.");
|
|
78878
|
-
const store = new MissionStore(
|
|
79337
|
+
const store = new MissionStore(join49(root, ".agent-valley", "operation-decisions", operation.id));
|
|
78879
79338
|
const unlock = await store.lock(decisionId);
|
|
78880
79339
|
const runtime = (dependencies.runtime ?? ((storage, signal) => new ChiefRuntime(storage, signal, undefined, undefined, undefined, discoverReadyAgents, discoverFreeModels)))(store, dependencies.signal);
|
|
78881
79340
|
let mission;
|
|
@@ -78988,7 +79447,7 @@ async function decideContinuousGoal(operation, decisionId, root, dependencies =
|
|
|
78988
79447
|
const previousId = operation.history.at(-1)?.missionId;
|
|
78989
79448
|
let previousReport;
|
|
78990
79449
|
if (previousId) {
|
|
78991
|
-
const previous = await new MissionStore(
|
|
79450
|
+
const previous = await new MissionStore(join49(root, ".agent-valley", "missions")).load(previousId);
|
|
78992
79451
|
if (previous.repositoryRoot !== operation.repositoryRoot || previous.status !== "completed")
|
|
78993
79452
|
throw new Error("The previous accepted child's evidence no longer matches this operation. Restore its saved checkpoint before selecting another goal.");
|
|
78994
79453
|
previousReport = renderReport(previous).slice(0, 16000);
|
|
@@ -79027,7 +79486,7 @@ async function decideContinuousGoal(operation, decisionId, root, dependencies =
|
|
|
79027
79486
|
|
|
79028
79487
|
// src/chief-continuous-report.ts
|
|
79029
79488
|
import { mkdir as mkdir23 } from "node:fs/promises";
|
|
79030
|
-
import { join as
|
|
79489
|
+
import { join as join50 } from "node:path";
|
|
79031
79490
|
init_atomic_json();
|
|
79032
79491
|
function operationDeliveryLines(operation, delivery, unavailable = false) {
|
|
79033
79492
|
const integration = operation.sourceIntegration;
|
|
@@ -79086,17 +79545,17 @@ function renderOperationReport(operation, delivery, unavailable = false) {
|
|
|
79086
79545
|
`);
|
|
79087
79546
|
}
|
|
79088
79547
|
async function saveOperationReport(root, operation) {
|
|
79089
|
-
const directory =
|
|
79548
|
+
const directory = join50(root, ".agent-valley", "operation-reports");
|
|
79090
79549
|
await mkdir23(directory, { recursive: true, mode: 448 });
|
|
79091
79550
|
const evidence = await deliveryFor(root, operation);
|
|
79092
|
-
await writeTextAtomic(
|
|
79551
|
+
await writeTextAtomic(join50(directory, `${operation.id}.md`), renderOperationReport(operation, evidence.delivery, evidence.unavailable));
|
|
79093
79552
|
}
|
|
79094
79553
|
async function deliveryFor(root, operation) {
|
|
79095
79554
|
const id = operation.currentMissionId ?? operation.history.at(-1)?.missionId;
|
|
79096
79555
|
if (!id)
|
|
79097
79556
|
return {};
|
|
79098
79557
|
try {
|
|
79099
|
-
const mission = await new MissionStore(
|
|
79558
|
+
const mission = await new MissionStore(join50(root, ".agent-valley", "missions")).load(id);
|
|
79100
79559
|
return mission.repositoryRoot === operation.repositoryRoot ? { delivery: mission.codeDelivery } : { unavailable: true };
|
|
79101
79560
|
} catch {
|
|
79102
79561
|
return { unavailable: true };
|
|
@@ -79129,7 +79588,7 @@ function createOperationProgressReporter(root, write = console.log) {
|
|
|
79129
79588
|
};
|
|
79130
79589
|
}
|
|
79131
79590
|
// src/chief-source-integration.ts
|
|
79132
|
-
import { join as
|
|
79591
|
+
import { join as join51 } from "node:path";
|
|
79133
79592
|
init_execution();
|
|
79134
79593
|
function sourceIntegrationCheckpoint(operation) {
|
|
79135
79594
|
const accepted = operation.baseline;
|
|
@@ -79152,7 +79611,7 @@ async function initialSourceIntegration(repositoryRoot, id, mode, remoteDelivery
|
|
|
79152
79611
|
async function assertChildSettled(operation, storageRoot) {
|
|
79153
79612
|
if (!operation.currentMissionId)
|
|
79154
79613
|
return;
|
|
79155
|
-
const missions = new MissionStore(
|
|
79614
|
+
const missions = new MissionStore(join51(storageRoot, ".agent-valley", "missions"));
|
|
79156
79615
|
if (await missions.isLocked(operation.currentMissionId))
|
|
79157
79616
|
throw new Error("The current child is still owned by another coordinator. Resume source integration after its checkpoint is settled.");
|
|
79158
79617
|
const child = await missions.load(operation.currentMissionId).catch((error) => {
|
|
@@ -79174,7 +79633,7 @@ async function resumeSourceIntegration(operation, mode, storageRoot, signal, sav
|
|
|
79174
79633
|
if (selected !== "snapshot-only")
|
|
79175
79634
|
throw new Error("This operation already uses explicit commit and push delivery. Keep its saved delivery policy instead of adding worktree application.");
|
|
79176
79635
|
}
|
|
79177
|
-
const persist = save ?? ((current) => new ContinuousOperationStore(
|
|
79636
|
+
const persist = save ?? ((current) => new ContinuousOperationStore(join51(storageRoot, ".agent-valley", "operations")).save(current));
|
|
79178
79637
|
const { accepted, applied, caughtUp, pendingIds } = sourceIntegrationCheckpoint(operation);
|
|
79179
79638
|
const activation = selected === "worktree" && operation.sourceIntegrationPolicy?.mode !== "worktree";
|
|
79180
79639
|
if (activation) {
|
|
@@ -79212,7 +79671,7 @@ async function resumeSourceIntegration(operation, mode, storageRoot, signal, sav
|
|
|
79212
79671
|
if (policy?.mode === "worktree" && accepted?.missionId && (applied?.missionId !== accepted.missionId || applied.nextTree !== accepted.baselineTree)) {
|
|
79213
79672
|
if (applied?.missionId === accepted.missionId)
|
|
79214
79673
|
throw new Error("The saved source application summary differs from its accepted snapshot. Restore the original verified receipt before resuming.");
|
|
79215
|
-
const previous = await validateContinuousBaseline(operation.repositoryRoot, operation.id,
|
|
79674
|
+
const previous = await validateContinuousBaseline(operation.repositoryRoot, operation.id, join51(operation.repositoryRoot, ".agent-valley", "operations", operation.id, "baselines", applied?.missionId ?? "initial", "workspace"));
|
|
79216
79675
|
if (applied && previous.baselineTree !== applied.nextTree)
|
|
79217
79676
|
throw new Error("The last applied source snapshot no longer matches its saved summary. Restore its original baseline before resuming.");
|
|
79218
79677
|
operation.sourceIntegration = await integrateContinuousSource(operation, previous, accepted, signal);
|
|
@@ -79237,9 +79696,9 @@ import { realpath as realpath30 } from "node:fs/promises";
|
|
|
79237
79696
|
// ../../packages/core/src/chief/continuous-retention.ts
|
|
79238
79697
|
init_zod();
|
|
79239
79698
|
import { createHash as createHash29 } from "node:crypto";
|
|
79240
|
-
import { constants as
|
|
79241
|
-
import { lstat as
|
|
79242
|
-
import { dirname as dirname11, join as
|
|
79699
|
+
import { constants as constants18 } from "node:fs";
|
|
79700
|
+
import { lstat as lstat24, open as open18, readdir as readdir13, realpath as realpath29, rename as rename4, rm as rm7 } from "node:fs/promises";
|
|
79701
|
+
import { dirname as dirname11, join as join52, resolve as resolve32 } from "node:path";
|
|
79243
79702
|
var digest7 = (content) => createHash29("sha256").update(content).digest("hex");
|
|
79244
79703
|
var sha2 = string2().regex(/^[a-f0-9]{40,64}$/);
|
|
79245
79704
|
var preparedSchema = strictObject({
|
|
@@ -79263,7 +79722,7 @@ var completedSchema = strictObject({
|
|
|
79263
79722
|
});
|
|
79264
79723
|
async function exists(path) {
|
|
79265
79724
|
try {
|
|
79266
|
-
await
|
|
79725
|
+
await lstat24(path);
|
|
79267
79726
|
return true;
|
|
79268
79727
|
} catch (error) {
|
|
79269
79728
|
if (error.code === "ENOENT")
|
|
@@ -79272,13 +79731,13 @@ async function exists(path) {
|
|
|
79272
79731
|
}
|
|
79273
79732
|
}
|
|
79274
79733
|
async function localDirectory3(path) {
|
|
79275
|
-
if (!(await
|
|
79734
|
+
if (!(await lstat24(path)).isDirectory() || await realpath29(path) !== resolve32(path))
|
|
79276
79735
|
throw new Error("Pruning requires canonical local directories. Preserve redirected artifacts and restore their original paths.");
|
|
79277
79736
|
}
|
|
79278
79737
|
async function readLocal(path) {
|
|
79279
79738
|
let handle;
|
|
79280
79739
|
try {
|
|
79281
|
-
handle = await open18(path,
|
|
79740
|
+
handle = await open18(path, constants18.O_RDONLY | (constants18.O_NOFOLLOW ?? 0) | (constants18.O_NONBLOCK ?? 0));
|
|
79282
79741
|
const stat = await handle.stat();
|
|
79283
79742
|
if (!stat.isFile() || stat.size > 16777216)
|
|
79284
79743
|
throw new Error("Unsupported local pruning receipt.");
|
|
@@ -79310,7 +79769,7 @@ async function independentGitMetadata(path) {
|
|
|
79310
79769
|
const directory = pending.pop();
|
|
79311
79770
|
if (!directory)
|
|
79312
79771
|
break;
|
|
79313
|
-
for (const entry of await
|
|
79772
|
+
for (const entry of await readdir13(directory, { withFileTypes: true })) {
|
|
79314
79773
|
if (++entries > 1e5)
|
|
79315
79774
|
throw new Error("Git metadata inspection exceeded its bound; retain this clone.");
|
|
79316
79775
|
if (entry.name.endsWith(".lock"))
|
|
@@ -79318,29 +79777,29 @@ async function independentGitMetadata(path) {
|
|
|
79318
79777
|
if (entry.isSymbolicLink())
|
|
79319
79778
|
throw new Error("Git metadata redirects through a symbolic link.");
|
|
79320
79779
|
if (entry.isDirectory())
|
|
79321
|
-
pending.push(
|
|
79780
|
+
pending.push(join52(directory, entry.name));
|
|
79322
79781
|
else if (!entry.isFile())
|
|
79323
79782
|
throw new Error("Git metadata contains an unsupported file type; preserve this clone.");
|
|
79324
79783
|
}
|
|
79325
79784
|
}
|
|
79326
79785
|
}
|
|
79327
79786
|
async function emptyScratch(path, depth = 0) {
|
|
79328
|
-
if (depth > 8 || !(await
|
|
79787
|
+
if (depth > 8 || !(await lstat24(path)).isDirectory() || await realpath29(path) !== path)
|
|
79329
79788
|
return false;
|
|
79330
|
-
const entries = await
|
|
79789
|
+
const entries = await readdir13(path);
|
|
79331
79790
|
if (entries.length > 100)
|
|
79332
79791
|
return false;
|
|
79333
79792
|
for (const name of entries)
|
|
79334
|
-
if (!await emptyScratch(
|
|
79793
|
+
if (!await emptyScratch(join52(path, name), depth + 1))
|
|
79335
79794
|
return false;
|
|
79336
79795
|
return true;
|
|
79337
79796
|
}
|
|
79338
79797
|
async function inspectClone(path, baseline) {
|
|
79339
79798
|
await localDirectory3(path);
|
|
79340
|
-
await localDirectory3(
|
|
79341
|
-
await independentGitMetadata(
|
|
79799
|
+
await localDirectory3(join52(path, ".git"));
|
|
79800
|
+
await independentGitMetadata(join52(path, ".git"));
|
|
79342
79801
|
for (const key of ["commondir", "objects/info/alternates", "objects/info/http-alternates", "info/grafts", "shallow"])
|
|
79343
|
-
if (await exists(
|
|
79802
|
+
if (await exists(join52(path, ".git", key)))
|
|
79344
79803
|
throw new Error("Git metadata depends on another repository.");
|
|
79345
79804
|
const [top, branch, head, refs, status, worktrees, remotes] = await Promise.all([
|
|
79346
79805
|
git(path, ["rev-parse", "--show-toplevel"]),
|
|
@@ -79365,7 +79824,7 @@ async function inspectClone(path, baseline) {
|
|
|
79365
79824
|
`) !== `worktree ${path}`)
|
|
79366
79825
|
throw new Error("Frozen baseline has linked worktrees.");
|
|
79367
79826
|
for (const entry of status.split("\x00").filter(Boolean)) {
|
|
79368
|
-
if (entry === "!! .agent-valley/" && await emptyScratch(
|
|
79827
|
+
if (entry === "!! .agent-valley/" && await emptyScratch(join52(path, ".agent-valley")))
|
|
79369
79828
|
continue;
|
|
79370
79829
|
throw new Error("Frozen baseline has tracked, untracked or ignored changes.");
|
|
79371
79830
|
}
|
|
@@ -79398,22 +79857,22 @@ async function recoverable(current, baseline) {
|
|
|
79398
79857
|
throw new Error("The current baseline is missing recovery objects.");
|
|
79399
79858
|
}
|
|
79400
79859
|
async function processEvidence(storePath, missionId) {
|
|
79401
|
-
if (await exists(
|
|
79860
|
+
if (await exists(join52(storePath, `${missionId}.json.lock`)))
|
|
79402
79861
|
return true;
|
|
79403
|
-
if (await exists(
|
|
79862
|
+
if (await exists(join52(storePath, `${missionId}.json.lock.reclaim`)))
|
|
79404
79863
|
return true;
|
|
79405
|
-
return (await
|
|
79864
|
+
return (await readdir13(storePath)).some((name) => name === `${missionId}.active` || name.startsWith(`${missionId}.run-`) && name.endsWith(".active"));
|
|
79406
79865
|
}
|
|
79407
79866
|
async function protectMissionBaseline(mission, protectedPaths) {
|
|
79408
79867
|
if (!mission.repositoryRoot)
|
|
79409
79868
|
throw new Error("An unresolved mission has no repository identity; preserve all baselines.");
|
|
79410
79869
|
protectedPaths.add(mission.workspace.path);
|
|
79411
79870
|
const workspace = mission.workspace.path;
|
|
79412
|
-
const prefix =
|
|
79871
|
+
const prefix = join52(mission.repositoryRoot, ".agent-valley", "operations");
|
|
79413
79872
|
if (!workspace.startsWith(`${prefix}/`))
|
|
79414
79873
|
return;
|
|
79415
79874
|
await localDirectory3(dirname11(workspace));
|
|
79416
|
-
const raw = await readLocal(
|
|
79875
|
+
const raw = await readLocal(join52(dirname11(workspace), "workspace.json"));
|
|
79417
79876
|
if (!raw)
|
|
79418
79877
|
throw new Error("An unresolved mission is missing its workspace receipt; preserve all baselines.");
|
|
79419
79878
|
const value = JSON.parse(raw);
|
|
@@ -79423,37 +79882,37 @@ async function protectMissionBaseline(mission, protectedPaths) {
|
|
|
79423
79882
|
}
|
|
79424
79883
|
async function referencedBaselines(storageRoot, operations) {
|
|
79425
79884
|
const protectedPaths = new Set;
|
|
79426
|
-
const missionDirectories = [
|
|
79885
|
+
const missionDirectories = [join52(storageRoot, ".agent-valley", "missions")];
|
|
79427
79886
|
for (const operation of operations) {
|
|
79428
79887
|
if (operation.baseline)
|
|
79429
79888
|
protectedPaths.add(operation.baseline.path);
|
|
79430
79889
|
if (operation.sourceIntegration)
|
|
79431
|
-
protectedPaths.add(
|
|
79890
|
+
protectedPaths.add(join52(operation.repositoryRoot, ".agent-valley", "operations", operation.id, "baselines", operation.sourceIntegration.missionId, "workspace"));
|
|
79432
79891
|
for (const id of [operation.currentMissionId, operation.decisionId]) {
|
|
79433
79892
|
if (!id)
|
|
79434
79893
|
continue;
|
|
79435
|
-
const container =
|
|
79894
|
+
const container = join52(operation.repositoryRoot, ".agent-valley", "operations", operation.id, "workspaces", id);
|
|
79436
79895
|
await localDirectory3(container);
|
|
79437
|
-
const raw = await readLocal(
|
|
79896
|
+
const raw = await readLocal(join52(container, "workspace.json"));
|
|
79438
79897
|
if (!raw)
|
|
79439
79898
|
throw new Error("An active child or decision has no workspace receipt; preserve all baselines.");
|
|
79440
79899
|
const value = JSON.parse(raw);
|
|
79441
79900
|
if (value.operationId !== operation.id || value.missionId !== id || typeof value.baselinePath !== "string")
|
|
79442
79901
|
throw new Error("An active workspace has an ambiguous baseline reference.");
|
|
79443
79902
|
protectedPaths.add(await realpath29(value.baselinePath));
|
|
79444
|
-
protectedPaths.add(
|
|
79903
|
+
protectedPaths.add(join52(operation.repositoryRoot, ".agent-valley", "operations", operation.id, "baselines", id, "workspace"));
|
|
79445
79904
|
}
|
|
79446
|
-
missionDirectories.push(
|
|
79905
|
+
missionDirectories.push(join52(storageRoot, ".agent-valley", "operation-decisions", operation.id));
|
|
79447
79906
|
}
|
|
79448
79907
|
for (const directory of missionDirectories) {
|
|
79449
79908
|
if (!await exists(directory))
|
|
79450
79909
|
continue;
|
|
79451
79910
|
await localDirectory3(directory);
|
|
79452
79911
|
const store = new MissionStore(directory);
|
|
79453
|
-
for (const name of await
|
|
79912
|
+
for (const name of await readdir13(directory)) {
|
|
79454
79913
|
if (!name.endsWith(".json"))
|
|
79455
79914
|
continue;
|
|
79456
|
-
await readLocal(
|
|
79915
|
+
await readLocal(join52(directory, name));
|
|
79457
79916
|
const mission = await store.load(name.slice(0, -5));
|
|
79458
79917
|
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))
|
|
79459
79918
|
await protectMissionBaseline(mission, protectedPaths);
|
|
@@ -79465,7 +79924,7 @@ async function pruneContinuousBaselines(storageRoot, operationId, options = {})
|
|
|
79465
79924
|
operationIdSchema.parse(operationId);
|
|
79466
79925
|
if (await realpath29(storageRoot) !== resolve32(storageRoot))
|
|
79467
79926
|
throw new Error("Use the original canonical operation storage root.");
|
|
79468
|
-
const directory =
|
|
79927
|
+
const directory = join52(storageRoot, ".agent-valley", "operations");
|
|
79469
79928
|
await localDirectory3(directory);
|
|
79470
79929
|
const store = new ContinuousOperationStore(directory);
|
|
79471
79930
|
const unlock = await store.lock(operationId);
|
|
@@ -79475,26 +79934,26 @@ async function pruneContinuousBaselines(storageRoot, operationId, options = {})
|
|
|
79475
79934
|
await localDirectory3(root);
|
|
79476
79935
|
if ((await git(root, ["rev-parse", "--show-toplevel"])).trim() !== root)
|
|
79477
79936
|
throw new Error("Restore the original Git repository before pruning.");
|
|
79478
|
-
const artifacts =
|
|
79479
|
-
const baselines =
|
|
79937
|
+
const artifacts = join52(root, ".agent-valley", "operations", operationId);
|
|
79938
|
+
const baselines = join52(artifacts, "baselines");
|
|
79480
79939
|
await localDirectory3(artifacts);
|
|
79481
79940
|
await localDirectory3(baselines);
|
|
79482
79941
|
const current = operation.baseline;
|
|
79483
79942
|
if (!current)
|
|
79484
79943
|
throw new Error("No accepted baseline exists. Preserve the operation artifacts.");
|
|
79485
79944
|
const protectedPaths = await referencedBaselines(storageRoot, await store.list());
|
|
79486
|
-
protectedPaths.add(
|
|
79945
|
+
protectedPaths.add(join52(baselines, "initial", "workspace"));
|
|
79487
79946
|
for (const entry of operation.history.slice(-2))
|
|
79488
79947
|
protectedPaths.add(entry.baselinePath);
|
|
79489
|
-
const currentReceipt = continuousBaselineSchema.parse(JSON.parse(await readLocal(
|
|
79948
|
+
const currentReceipt = continuousBaselineSchema.parse(JSON.parse(await readLocal(join52(dirname11(current.path), "baseline.json")) ?? "null"));
|
|
79490
79949
|
if (JSON.stringify(currentReceipt) !== JSON.stringify(current))
|
|
79491
79950
|
throw new Error("The accepted baseline receipt changed.");
|
|
79492
79951
|
await inspectClone(current.path, current);
|
|
79493
|
-
const missionsPath =
|
|
79952
|
+
const missionsPath = join52(storageRoot, ".agent-valley", "missions");
|
|
79494
79953
|
const missions = new MissionStore(missionsPath);
|
|
79495
79954
|
const candidates = [];
|
|
79496
|
-
for (const key of (await
|
|
79497
|
-
const path =
|
|
79955
|
+
for (const key of (await readdir13(baselines)).sort()) {
|
|
79956
|
+
const path = join52(baselines, key, "workspace");
|
|
79498
79957
|
let release;
|
|
79499
79958
|
let result = { key, path, status: "kept", reason: "Retained for inspection." };
|
|
79500
79959
|
try {
|
|
@@ -79502,16 +79961,16 @@ async function pruneContinuousBaselines(storageRoot, operationId, options = {})
|
|
|
79502
79961
|
await localDirectory3(dirname11(path));
|
|
79503
79962
|
if (protectedPaths.has(path))
|
|
79504
79963
|
throw new Error("Initial, current, previous or referenced baseline is protected.");
|
|
79505
|
-
const raw = await readLocal(
|
|
79964
|
+
const raw = await readLocal(join52(dirname11(path), "baseline.json"));
|
|
79506
79965
|
const snapshot = continuousBaselineSchema.parse(JSON.parse(raw ?? "null"));
|
|
79507
|
-
const transaction = continuousBaselineSchema.parse(JSON.parse(await readLocal(
|
|
79966
|
+
const transaction = continuousBaselineSchema.parse(JSON.parse(await readLocal(join52(dirname11(path), "snapshot.json")) ?? "null"));
|
|
79508
79967
|
if (JSON.stringify(transaction) !== JSON.stringify(snapshot))
|
|
79509
79968
|
throw new Error("Original snapshot transaction and baseline receipts differ.");
|
|
79510
79969
|
if (snapshot.operationId !== operationId || snapshot.repositoryRoot !== root || snapshot.path !== path || snapshot.missionId !== key || snapshot.branch !== `av-operation/${operationId}/baseline-${key}`)
|
|
79511
79970
|
throw new Error("Baseline identity does not match its private directory.");
|
|
79512
|
-
const preparedPath =
|
|
79513
|
-
const completedPath =
|
|
79514
|
-
const quarantine =
|
|
79971
|
+
const preparedPath = join52(dirname11(path), "pruning.json");
|
|
79972
|
+
const completedPath = join52(dirname11(path), "pruned.json");
|
|
79973
|
+
const quarantine = join52(dirname11(path), "workspace.pruning");
|
|
79515
79974
|
const preparedRaw = await readLocal(preparedPath);
|
|
79516
79975
|
const prepared = preparedRaw ? preparedSchema.parse(JSON.parse(preparedRaw)) : undefined;
|
|
79517
79976
|
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)))
|
|
@@ -79526,7 +79985,7 @@ async function pruneContinuousBaselines(storageRoot, operationId, options = {})
|
|
|
79526
79985
|
continue;
|
|
79527
79986
|
}
|
|
79528
79987
|
const accepted = operation.history.some((entry) => entry.missionId === key && entry.baselinePath === path);
|
|
79529
|
-
const journalRaw = await readLocal(
|
|
79988
|
+
const journalRaw = await readLocal(join52(dirname11(path), "acceptance.json"));
|
|
79530
79989
|
const journal = journalRaw ? continuousAcceptanceSchema.parse(JSON.parse(journalRaw)) : undefined;
|
|
79531
79990
|
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))
|
|
79532
79991
|
throw new Error("Acceptance journal does not match this frozen baseline.");
|
|
@@ -79562,7 +80021,7 @@ async function pruneContinuousBaselines(storageRoot, operationId, options = {})
|
|
|
79562
80021
|
if (hasQuarantine && !prepared)
|
|
79563
80022
|
throw new Error("Unrecorded pruning quarantine is protected.");
|
|
79564
80023
|
await inspectClone(physicalPath, snapshot);
|
|
79565
|
-
const identity = await
|
|
80024
|
+
const identity = await lstat24(physicalPath);
|
|
79566
80025
|
if (prepared && (identity.dev !== prepared.device || identity.ino !== prepared.inode))
|
|
79567
80026
|
throw new Error("Workspace identity changed after pruning was prepared.");
|
|
79568
80027
|
result = {
|
|
@@ -79586,13 +80045,13 @@ async function pruneContinuousBaselines(storageRoot, operationId, options = {})
|
|
|
79586
80045
|
at: (options.now?.() ?? new Date).toISOString()
|
|
79587
80046
|
});
|
|
79588
80047
|
await inspectClone(physicalPath, snapshot);
|
|
79589
|
-
const checked = await
|
|
80048
|
+
const checked = await lstat24(physicalPath);
|
|
79590
80049
|
if (checked.dev !== identity.dev || checked.ino !== identity.ino)
|
|
79591
80050
|
throw new Error("Workspace identity changed before pruning.");
|
|
79592
80051
|
if (!hasQuarantine)
|
|
79593
80052
|
await rename4(path, quarantine);
|
|
79594
80053
|
await localDirectory3(quarantine);
|
|
79595
|
-
const moved = await
|
|
80054
|
+
const moved = await lstat24(quarantine);
|
|
79596
80055
|
if (moved.dev !== identity.dev || moved.ino !== identity.ino)
|
|
79597
80056
|
throw new Error("Pruning quarantine identity changed.");
|
|
79598
80057
|
await rm7(quarantine, { recursive: true });
|
|
@@ -79671,7 +80130,7 @@ function integerOption(value, name, maximum) {
|
|
|
79671
80130
|
return number;
|
|
79672
80131
|
}
|
|
79673
80132
|
function operationStore(root) {
|
|
79674
|
-
return new ContinuousOperationStore(
|
|
80133
|
+
return new ContinuousOperationStore(join53(resolve33(root), ".agent-valley", "operations"));
|
|
79675
80134
|
}
|
|
79676
80135
|
async function restoreOperationOrigin(repository, workspace) {
|
|
79677
80136
|
const env = { ...process.env, ...clearedGitEnvironment };
|
|
@@ -79779,7 +80238,7 @@ async function runOperation(charter, options, root = process.cwd(), dependencies
|
|
|
79779
80238
|
if (options.retry || decisionBudgetKeys.some((key) => options[key] !== undefined)) {
|
|
79780
80239
|
if (operation.currentMissionId || !operation.decisionId)
|
|
79781
80240
|
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>.");
|
|
79782
|
-
const decisions = new MissionStore(
|
|
80241
|
+
const decisions = new MissionStore(join53(root, ".agent-valley", "operation-decisions", operation.id));
|
|
79783
80242
|
const unlockDecision = await decisions.lock(operation.decisionId);
|
|
79784
80243
|
try {
|
|
79785
80244
|
const decision = await decisions.load(operation.decisionId);
|
|
@@ -79851,7 +80310,7 @@ async function runOperation(charter, options, root = process.cwd(), dependencies
|
|
|
79851
80310
|
console.log(`Operation ${id}
|
|
79852
80311
|
Charter: ${operation.charter}
|
|
79853
80312
|
Resume: av order --resume ${id}`);
|
|
79854
|
-
const missions = new MissionStore(
|
|
80313
|
+
const missions = new MissionStore(join53(root, ".agent-valley", "missions"));
|
|
79855
80314
|
return await runContinuousOperation(operation, {
|
|
79856
80315
|
signal: controller.signal,
|
|
79857
80316
|
...options.retry ? { retryDecision: true } : {},
|
|
@@ -79989,7 +80448,7 @@ class OperationApi {
|
|
|
79989
80448
|
this.root = root;
|
|
79990
80449
|
this.workspace = workspace;
|
|
79991
80450
|
this.dependencies = dependencies;
|
|
79992
|
-
this.store = new ContinuousOperationStore(
|
|
80451
|
+
this.store = new ContinuousOperationStore(join54(root, ".agent-valley/operations"));
|
|
79993
80452
|
this.jobs = new MissionJobs(root, "operation-jobs");
|
|
79994
80453
|
}
|
|
79995
80454
|
order(raw) {
|
|
@@ -80238,17 +80697,17 @@ class MissionApi {
|
|
|
80238
80697
|
this.projectRoot = projectRoot;
|
|
80239
80698
|
this.workspace = workspace;
|
|
80240
80699
|
this.dependencies = dependencies;
|
|
80241
|
-
this.store = new MissionStore(
|
|
80700
|
+
this.store = new MissionStore(join55(projectRoot, ".agent-valley/missions"));
|
|
80242
80701
|
this.jobs = new MissionJobs(projectRoot);
|
|
80243
80702
|
this.operationApi = new OperationApi(projectRoot, workspace, dependencies);
|
|
80244
80703
|
this.operationJobs = new MissionJobs(projectRoot, "operation-jobs");
|
|
80245
80704
|
}
|
|
80246
80705
|
static async create(workspace, dependencies = {}) {
|
|
80247
|
-
if (!
|
|
80706
|
+
if (!isAbsolute19(workspace))
|
|
80248
80707
|
throw new Error("Set an absolute Git repository path in av mcp --workspace <path>.");
|
|
80249
80708
|
const projectRoot = await realpath33(workspace);
|
|
80250
80709
|
const target = loadProjectConfig(projectRoot)?.workspace?.root ?? projectRoot;
|
|
80251
|
-
if (!
|
|
80710
|
+
if (!isAbsolute19(target))
|
|
80252
80711
|
throw new Error("Set workspace.root in av.yaml to an absolute Git repository path.");
|
|
80253
80712
|
return new MissionApi(projectRoot, await realpath33(target), dependencies);
|
|
80254
80713
|
}
|
|
@@ -80277,7 +80736,7 @@ class MissionApi {
|
|
|
80277
80736
|
async order(raw) {
|
|
80278
80737
|
assertNotManagedRun(this.dependencies.env);
|
|
80279
80738
|
const input = mcpOrderSchema.parse(raw);
|
|
80280
|
-
if (input.workspace && (!
|
|
80739
|
+
if (input.workspace && (!isAbsolute19(input.workspace) || await realpath33(input.workspace) !== this.workspace))
|
|
80281
80740
|
throw new Error("This AV server is bound to another workspace. Start av mcp --workspace for the target repository.");
|
|
80282
80741
|
return this.serializeOrder(async () => {
|
|
80283
80742
|
if (input.requestId) {
|
|
@@ -80300,7 +80759,7 @@ class MissionApi {
|
|
|
80300
80759
|
async list() {
|
|
80301
80760
|
this.assertOpen();
|
|
80302
80761
|
await ensureAvDirectory(this.projectRoot, ["missions"]);
|
|
80303
|
-
const ids = new Set((await
|
|
80762
|
+
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))));
|
|
80304
80763
|
for (const job of await this.jobs.list())
|
|
80305
80764
|
ids.add(job.missionId);
|
|
80306
80765
|
return {
|
|
@@ -80454,8 +80913,8 @@ class MissionApi {
|
|
|
80454
80913
|
async load(id) {
|
|
80455
80914
|
await ensureAvDirectory(this.projectRoot, ["missions"]);
|
|
80456
80915
|
try {
|
|
80457
|
-
const path =
|
|
80458
|
-
const stat = await
|
|
80916
|
+
const path = join55(this.projectRoot, ".agent-valley/missions", `${missionIdSchema.parse(id)}.json`);
|
|
80917
|
+
const stat = await lstat25(path);
|
|
80459
80918
|
if (!stat.isFile() || stat.isSymbolicLink())
|
|
80460
80919
|
throw new Error(`Mission record must be a regular file: ${path}. Remove the symlink before retrying.`);
|
|
80461
80920
|
return await this.store.load(id);
|
|
@@ -80479,11 +80938,11 @@ class MissionApi {
|
|
|
80479
80938
|
// src/plugin-export.ts
|
|
80480
80939
|
init_client_integrations_assets();
|
|
80481
80940
|
init_client_integrations_files();
|
|
80482
|
-
import { lstat as
|
|
80483
|
-
import { dirname as dirname12, join as
|
|
80941
|
+
import { lstat as lstat26, readdir as readdir15, realpath as realpath34 } from "node:fs/promises";
|
|
80942
|
+
import { dirname as dirname12, join as join56, relative as relative17, resolve as resolve34 } from "node:path";
|
|
80484
80943
|
|
|
80485
80944
|
// src/plugin-assets.ts
|
|
80486
|
-
import { copyFile as copyFile2, mkdir as mkdir24, readFile as
|
|
80945
|
+
import { copyFile as copyFile2, mkdir as mkdir24, readFile as readFile20 } from "node:fs/promises";
|
|
80487
80946
|
init_zod();
|
|
80488
80947
|
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
80489
80948
|
var pluginSchemaUrl = "https://agent-plugins.org/schemas/1.0.0/plugin.schema.json";
|
|
@@ -80515,7 +80974,7 @@ async function loadPluginLicenseAsset(candidates = pluginLicenseAssetCandidates(
|
|
|
80515
80974
|
for (const path of candidates) {
|
|
80516
80975
|
let content;
|
|
80517
80976
|
try {
|
|
80518
|
-
content = await
|
|
80977
|
+
content = await readFile20(path, "utf8");
|
|
80519
80978
|
} catch (error) {
|
|
80520
80979
|
if (error.code === "ENOENT")
|
|
80521
80980
|
continue;
|
|
@@ -80531,7 +80990,7 @@ async function loadPluginManifestAsset(candidates = pluginManifestAssetCandidate
|
|
|
80531
80990
|
for (const path of candidates) {
|
|
80532
80991
|
let content;
|
|
80533
80992
|
try {
|
|
80534
|
-
content = await
|
|
80993
|
+
content = await readFile20(path, "utf8");
|
|
80535
80994
|
} catch (error) {
|
|
80536
80995
|
if (error.code === "ENOENT")
|
|
80537
80996
|
continue;
|
|
@@ -80648,7 +81107,7 @@ async function projectDirectory(workspace) {
|
|
|
80648
81107
|
throw new Error("Pass --workspace /absolute/AV-project to bind every exported MCP server to its AV configuration.");
|
|
80649
81108
|
try {
|
|
80650
81109
|
const project = await realpath34(resolve34(workspace));
|
|
80651
|
-
if (!(await
|
|
81110
|
+
if (!(await lstat26(project)).isDirectory())
|
|
80652
81111
|
throw new Error("not a directory");
|
|
80653
81112
|
return project;
|
|
80654
81113
|
} catch {
|
|
@@ -80674,12 +81133,12 @@ async function outputDirectory(output) {
|
|
|
80674
81133
|
let ancestor = target;
|
|
80675
81134
|
for (;; ) {
|
|
80676
81135
|
try {
|
|
80677
|
-
const info = await
|
|
81136
|
+
const info = await lstat26(ancestor);
|
|
80678
81137
|
if (info.isSymbolicLink())
|
|
80679
81138
|
throw exportConflict(ancestor, "symbolic link exports are not modified");
|
|
80680
81139
|
if (!info.isDirectory())
|
|
80681
81140
|
throw exportConflict(ancestor, "expected an output directory");
|
|
80682
|
-
return
|
|
81141
|
+
return join56(await realpath34(ancestor), relative17(ancestor, target));
|
|
80683
81142
|
} catch (error) {
|
|
80684
81143
|
if (error.code !== "ENOENT")
|
|
80685
81144
|
throw error;
|
|
@@ -80690,7 +81149,7 @@ async function outputDirectory(output) {
|
|
|
80690
81149
|
async function outputFiles(root, directory = root) {
|
|
80691
81150
|
let entries;
|
|
80692
81151
|
try {
|
|
80693
|
-
entries = await
|
|
81152
|
+
entries = await readdir15(directory, { withFileTypes: true });
|
|
80694
81153
|
} catch (error) {
|
|
80695
81154
|
if (error.code === "ENOENT")
|
|
80696
81155
|
return [];
|
|
@@ -80698,7 +81157,7 @@ async function outputFiles(root, directory = root) {
|
|
|
80698
81157
|
}
|
|
80699
81158
|
const files = [];
|
|
80700
81159
|
for (const entry of entries) {
|
|
80701
|
-
const path =
|
|
81160
|
+
const path = join56(directory, entry.name);
|
|
80702
81161
|
if (entry.isSymbolicLink())
|
|
80703
81162
|
throw exportConflict(path, "symbolic links are not modified");
|
|
80704
81163
|
if (entry.isDirectory())
|
|
@@ -80735,21 +81194,21 @@ async function exportPluginPackages(options) {
|
|
|
80735
81194
|
if (output === workspace)
|
|
80736
81195
|
throw exportConflict(output, "the output directory must be separate from the AV project root");
|
|
80737
81196
|
const { manifest } = await loadPluginManifestAsset(options.sourceManifest ? [options.sourceManifest] : undefined);
|
|
80738
|
-
const { content: skill } = await loadClientSkillAsset(options.sourceSkillRoot ? [
|
|
81197
|
+
const { content: skill } = await loadClientSkillAsset(options.sourceSkillRoot ? [join56(options.sourceSkillRoot, "SKILL.md")] : clientSkillAssetCandidates());
|
|
80739
81198
|
const { content: license } = await loadPluginLicenseAsset(options.sourceLicense ? [options.sourceLicense] : undefined);
|
|
80740
81199
|
const packageFiles = pluginPackageFiles(manifest, skill, license, { workspace, remoteUrl });
|
|
80741
|
-
const receipt = await integrationFile(output,
|
|
81200
|
+
const receipt = await integrationFile(output, join56(output, receiptName2), "", 384);
|
|
80742
81201
|
const hashes = ownedFileHashes(receipt.before, receipt.path);
|
|
80743
81202
|
const existing = await outputFiles(output);
|
|
80744
81203
|
for (const path of existing) {
|
|
80745
81204
|
if (path === receiptName2)
|
|
80746
81205
|
continue;
|
|
80747
81206
|
if (!packageFiles.has(path) || hashes[path] === undefined)
|
|
80748
|
-
throw exportConflict(
|
|
81207
|
+
throw exportConflict(join56(output, path), "unowned files are retained");
|
|
80749
81208
|
}
|
|
80750
81209
|
const files = [];
|
|
80751
81210
|
for (const [path, content] of packageFiles) {
|
|
80752
|
-
const file = await integrationFile(output,
|
|
81211
|
+
const file = await integrationFile(output, join56(output, path), content, 420);
|
|
80753
81212
|
if (hashes[path] !== undefined && (file.before === null || contentHash(file.before) !== hashes[path]))
|
|
80754
81213
|
throw exportConflict(file.path, "the exported file was changed or removed locally");
|
|
80755
81214
|
if (hashes[path] === undefined && file.before !== null)
|
|
@@ -80768,11 +81227,11 @@ async function exportPluginPackages(options) {
|
|
|
80768
81227
|
transport: remoteUrl ? "streamable-http" : "stdio",
|
|
80769
81228
|
files: await applyIntegrationFiles(output, [...files, receipt]),
|
|
80770
81229
|
packages: {
|
|
80771
|
-
portable:
|
|
80772
|
-
claude:
|
|
80773
|
-
cursor:
|
|
80774
|
-
qwen:
|
|
80775
|
-
antigravity:
|
|
81230
|
+
portable: join56(output, "portable/av"),
|
|
81231
|
+
claude: join56(output, "claude/plugins/av"),
|
|
81232
|
+
cursor: join56(output, "cursor/plugins/av"),
|
|
81233
|
+
qwen: join56(output, "qwen/av"),
|
|
81234
|
+
antigravity: join56(output, "antigravity/av")
|
|
80776
81235
|
}
|
|
80777
81236
|
};
|
|
80778
81237
|
}
|
|
@@ -80835,7 +81294,7 @@ function registerAgentClientCommands(program) {
|
|
|
80835
81294
|
// src/chief.ts
|
|
80836
81295
|
import { randomUUID as randomUUID24 } from "node:crypto";
|
|
80837
81296
|
import { realpath as realpath37 } from "node:fs/promises";
|
|
80838
|
-
import { join as
|
|
81297
|
+
import { join as join64 } from "node:path";
|
|
80839
81298
|
|
|
80840
81299
|
// ../../node_modules/.bun/@langchain+core@1.2.20+ea9f70ecde856c26/node_modules/@langchain/core/dist/_virtual/_rolldown/runtime.js
|
|
80841
81300
|
var __defProp4 = Object.defineProperty;
|
|
@@ -89792,10 +90251,10 @@ async function writeFileAtomic(filePath, content) {
|
|
|
89792
90251
|
});
|
|
89793
90252
|
await nodeFsPromises.rename(tempPath, filePath);
|
|
89794
90253
|
}
|
|
89795
|
-
async function
|
|
90254
|
+
async function readdir17(dir) {
|
|
89796
90255
|
return nodeFsPromises.readdir(dir);
|
|
89797
90256
|
}
|
|
89798
|
-
async function
|
|
90257
|
+
async function stat6(filePath) {
|
|
89799
90258
|
return nodeFsPromises.stat(filePath);
|
|
89800
90259
|
}
|
|
89801
90260
|
function existsSync6(p) {
|
|
@@ -92280,11 +92739,11 @@ class Client2 {
|
|
|
92280
92739
|
}
|
|
92281
92740
|
if (maxBytes !== undefined && maxBytes > 0) {
|
|
92282
92741
|
try {
|
|
92283
|
-
const entries = await
|
|
92742
|
+
const entries = await readdir17(directory);
|
|
92284
92743
|
const traceFiles = entries.filter((f) => f.startsWith("trace_") && f.endsWith(".json"));
|
|
92285
92744
|
let total = 0;
|
|
92286
92745
|
for (const name of traceFiles) {
|
|
92287
|
-
const { size } = await
|
|
92746
|
+
const { size } = await stat6(path6.join(directory, name));
|
|
92288
92747
|
total += size;
|
|
92289
92748
|
}
|
|
92290
92749
|
if (total >= maxBytes) {
|
|
@@ -131326,7 +131785,8 @@ function applyVerificationResult(mission, result, fingerprint) {
|
|
|
131326
131785
|
init_execution();
|
|
131327
131786
|
|
|
131328
131787
|
// ../../packages/core/src/chief/review-routing.ts
|
|
131329
|
-
|
|
131788
|
+
init_execution();
|
|
131789
|
+
function addReviewer(mission, vendor, model) {
|
|
131330
131790
|
if (mission.personas.length >= 20)
|
|
131331
131791
|
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.");
|
|
131332
131792
|
let id = `review-${vendor}`;
|
|
@@ -131337,6 +131797,7 @@ function addReviewer(mission, vendor) {
|
|
|
131337
131797
|
name: `Independent ${vendor} reviewer`,
|
|
131338
131798
|
role: "Independently inspect actual files and task acceptance evidence; report blockers without editing files.",
|
|
131339
131799
|
agentType: vendor,
|
|
131800
|
+
...model ? { model } : {},
|
|
131340
131801
|
skills: []
|
|
131341
131802
|
};
|
|
131342
131803
|
mission.personas.push(reviewer);
|
|
@@ -131347,30 +131808,36 @@ function selectTaskReviewer(mission, task, state, gateId) {
|
|
|
131347
131808
|
if (!configured)
|
|
131348
131809
|
throw new Error("Restore the configured task reviewer before resuming.");
|
|
131349
131810
|
const policy = mission.operatingPolicy;
|
|
131350
|
-
if (!policy || policy.reviewVendor === "off")
|
|
131811
|
+
if (!policy || policy.reviewVendor === "off") {
|
|
131812
|
+
availableActorRoutes(mission, [{ actorType: configured.agentType, model: configured.model }]);
|
|
131351
131813
|
return configured;
|
|
131814
|
+
}
|
|
131352
131815
|
const run = latestWorkRun(mission, task.id);
|
|
131353
131816
|
const worker = run?.actorType ?? mission.personas.find((actor) => actor.id === task.personaId)?.agentType;
|
|
131354
131817
|
if (!worker)
|
|
131355
131818
|
throw new Error("Restore this task's actual work Actor before reviewing it.");
|
|
131356
131819
|
const blocked = unavailableProviders(mission.handoff);
|
|
131357
|
-
const
|
|
131358
|
-
const
|
|
131359
|
-
|
|
131360
|
-
|
|
131361
|
-
|
|
131362
|
-
|
|
131363
|
-
if (
|
|
131364
|
-
|
|
131365
|
-
|
|
131366
|
-
|
|
131367
|
-
|
|
131820
|
+
const recordedReady = policy.readyActors ?? mission.availableAgents ?? [];
|
|
131821
|
+
const ready = recordedReady.filter((vendor) => !blocked.has(vendor));
|
|
131822
|
+
if (recordedReady.length && !ready.length)
|
|
131823
|
+
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");
|
|
131824
|
+
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 }));
|
|
131825
|
+
for (const vendor of ready)
|
|
131826
|
+
if (!pool.some((entry) => entry.actorType === vendor)) {
|
|
131827
|
+
const model = mission.operatingPolicy?.routing?.candidates.find((entry) => entry.actorType === vendor)?.model;
|
|
131828
|
+
pool.push({ actorType: vendor, model, actor: undefined });
|
|
131829
|
+
}
|
|
131830
|
+
const crossVendor = pool.filter((entry) => entry.actorType !== worker);
|
|
131831
|
+
if (!crossVendor.length && policy.reviewVendor === "require") {
|
|
131368
131832
|
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.`);
|
|
131369
|
-
} else if (configured.agentType !== worker && ready.includes(worker)) {
|
|
131370
|
-
reviewer = mission.personas.find((actor) => actor.id !== task.personaId && actor.agentType === worker) ?? addReviewer(mission, worker);
|
|
131371
|
-
} else if (!ready.length) {
|
|
131372
|
-
reason = "No vendor readiness pool is recorded; the configured independent Actor is attempted with readiness unknown.";
|
|
131373
131833
|
}
|
|
131834
|
+
const healthyCrossVendor = crossVendor.filter((entry) => actorRouteHealth(mission, entry).state === "ready");
|
|
131835
|
+
const candidates = policy.reviewVendor === "require" ? crossVendor : healthyCrossVendor.length ? crossVendor : pool;
|
|
131836
|
+
const selected = availableActorRoutes(mission, candidates).at(0);
|
|
131837
|
+
const reviewer = selected?.actor ?? (selected ? addReviewer(mission, selected.actorType, selected.model) : configured);
|
|
131838
|
+
if (!selected)
|
|
131839
|
+
availableActorRoutes(mission, [{ actorType: reviewer.agentType, model: reviewer.model }]);
|
|
131840
|
+
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.";
|
|
131374
131841
|
state.reviewerId = reviewer.id;
|
|
131375
131842
|
mission.operations ??= { runs: [], routingEvidence: [], reviewDecisions: [] };
|
|
131376
131843
|
mission.operations.reviewDecisions.push({
|
|
@@ -131585,7 +132052,9 @@ async function resumeMission(context) {
|
|
|
131585
132052
|
assertNoUncertainExecution(mission);
|
|
131586
132053
|
checkAbort();
|
|
131587
132054
|
assertExecutionDeadline(mission);
|
|
131588
|
-
if (mission.execution?.failureKind
|
|
132055
|
+
if (["chief-wait", "actor-cooldown"].includes(mission.execution?.failureKind ?? "") && mission.execution) {
|
|
132056
|
+
if (mission.execution.failureKind === "actor-cooldown" && !Number.isFinite(Date.parse(mission.execution.nextRunAt ?? "")))
|
|
132057
|
+
throw new MissionPause("The saved Actor cooldown timestamp is missing or invalid. Restore its original nextRunAt before resuming.", "integrity");
|
|
131589
132058
|
if (Date.parse(mission.execution.nextRunAt ?? "") > Date.now())
|
|
131590
132059
|
return { kind: "return" };
|
|
131591
132060
|
delete mission.execution.nextRunAt;
|
|
@@ -131650,6 +132119,9 @@ async function planMission(context) {
|
|
|
131650
132119
|
return { kind: "next", stage: "tasks" };
|
|
131651
132120
|
}
|
|
131652
132121
|
|
|
132122
|
+
// ../../packages/core/src/chief/coordinator-parallel.ts
|
|
132123
|
+
init_execution();
|
|
132124
|
+
|
|
131653
132125
|
// ../../packages/core/src/chief/parallel.ts
|
|
131654
132126
|
function readyTaskWave(plan, states, limit) {
|
|
131655
132127
|
if (!Number.isInteger(limit) || limit < 1 || limit > 20)
|
|
@@ -131721,6 +132193,8 @@ async function performParallelWave(mission, ports, wave, hooks) {
|
|
|
131721
132193
|
continue;
|
|
131722
132194
|
}
|
|
131723
132195
|
try {
|
|
132196
|
+
const previousAttempts = state.attempts;
|
|
132197
|
+
const workRunsBefore = mission.operations?.runs.filter((run) => run.stage === "work" && run.taskId === task.id).length ?? 0;
|
|
131724
132198
|
const previousOutput = state.parallel ? undefined : state.output;
|
|
131725
132199
|
if (!state.parallel)
|
|
131726
132200
|
delete state.output;
|
|
@@ -131736,7 +132210,7 @@ async function performParallelWave(mission, ports, wave, hooks) {
|
|
|
131736
132210
|
path: state.parallel.path,
|
|
131737
132211
|
branch: state.parallel.branch
|
|
131738
132212
|
};
|
|
131739
|
-
prepared.push({ task, state, actor, workspace, previousOutput });
|
|
132213
|
+
prepared.push({ task, state, actor, workspace, previousOutput, previousAttempts, workRunsBefore });
|
|
131740
132214
|
} catch (error) {
|
|
131741
132215
|
state.status = "pending";
|
|
131742
132216
|
fail(task.id, error);
|
|
@@ -131767,6 +132241,8 @@ ${JSON.stringify(previousOutput)}`;
|
|
|
131767
132241
|
const entry = pending[index];
|
|
131768
132242
|
if (entry && result.status === "rejected") {
|
|
131769
132243
|
entry.state.status = "pending";
|
|
132244
|
+
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)
|
|
132245
|
+
entry.state.attempts = entry.previousAttempts;
|
|
131770
132246
|
fail(entry.task.id, result.reason);
|
|
131771
132247
|
}
|
|
131772
132248
|
});
|
|
@@ -131856,6 +132332,8 @@ async function runTaskStage(context) {
|
|
|
131856
132332
|
const performTask = async (task, state) => {
|
|
131857
132333
|
while (state.status !== "completed") {
|
|
131858
132334
|
checkAbort();
|
|
132335
|
+
const attemptsBefore = state.attempts;
|
|
132336
|
+
const workRunsBefore = mission.operations?.runs.filter((run) => run.stage === "work" && run.taskId === task.id).length ?? 0;
|
|
131859
132337
|
const awaitingReview = state.output !== undefined && state.review === undefined;
|
|
131860
132338
|
state.status = awaitingReview ? "reviewing" : "running";
|
|
131861
132339
|
if (!awaitingReview && (task.effectScope !== "external" || state.effectState !== "completed"))
|
|
@@ -131884,6 +132362,8 @@ async function runTaskStage(context) {
|
|
|
131884
132362
|
reviewStarted = true;
|
|
131885
132363
|
await taskReview(task, state);
|
|
131886
132364
|
} catch (error) {
|
|
132365
|
+
if (!reviewStarted && error instanceof MissionPause && error.kind === "actor-cooldown" && (mission.operations?.runs.filter((run) => run.stage === "work" && run.taskId === task.id).length ?? 0) === workRunsBefore)
|
|
132366
|
+
state.attempts = attemptsBefore;
|
|
131887
132367
|
if (!mission.supervision || protectedFailure(error))
|
|
131888
132368
|
throw error;
|
|
131889
132369
|
state.status = reviewStarted ? "reviewing" : "pending";
|
|
@@ -131930,12 +132410,17 @@ async function runTaskStage(context) {
|
|
|
131930
132410
|
const limit = mission.executionPolicy?.maxParallel ?? 1;
|
|
131931
132411
|
const wave = readyTaskWave(plan, mission.tasks, limit).filter((task) => task.effectScope !== "external");
|
|
131932
132412
|
if (ports.parallel && limit > 1 && (wave.length > 1 || wave.some((task) => mission.tasks.find((state) => state.id === task.id)?.parallel))) {
|
|
131933
|
-
|
|
132413
|
+
let failures = await performParallelWave(mission, ports, wave, {
|
|
131934
132414
|
run,
|
|
131935
132415
|
save,
|
|
131936
132416
|
review: taskReview,
|
|
131937
132417
|
fatal: protectedFailure
|
|
131938
132418
|
});
|
|
132419
|
+
const primary = failures.filter((failure) => !(failure.error instanceof MissionPause && failure.error.kind === "actor-cooldown"));
|
|
132420
|
+
failures = primary.length ? primary : failures.flatMap((failure) => {
|
|
132421
|
+
const error = refreshActorCooldown(mission, failure.error);
|
|
132422
|
+
return error === undefined ? [] : [{ ...failure, error, reason: error instanceof Error ? error.message : String(error) }];
|
|
132423
|
+
});
|
|
131939
132424
|
const unrecoverable = failures.find((failure) => protectedFailure(failure.error));
|
|
131940
132425
|
if (unrecoverable)
|
|
131941
132426
|
throw unrecoverable.error;
|
|
@@ -132222,7 +132707,7 @@ init_worktree_lifecycle();
|
|
|
132222
132707
|
import { randomUUID as randomUUID23 } from "node:crypto";
|
|
132223
132708
|
import { mkdtemp as mkdtemp2, rm as rm9 } from "node:fs/promises";
|
|
132224
132709
|
import { tmpdir as tmpdir3 } from "node:os";
|
|
132225
|
-
import { join as
|
|
132710
|
+
import { join as join57 } from "node:path";
|
|
132226
132711
|
async function importIsolatedBranch(workspace, root) {
|
|
132227
132712
|
if (!isIsolatedGitWorkspace(workspace))
|
|
132228
132713
|
return null;
|
|
@@ -132269,7 +132754,7 @@ async function importIsolatedBranch(workspace, root) {
|
|
|
132269
132754
|
`).filter(Boolean);
|
|
132270
132755
|
if (commits.length === 0)
|
|
132271
132756
|
return null;
|
|
132272
|
-
temporaryWorktree = await mkdtemp2(
|
|
132757
|
+
temporaryWorktree = await mkdtemp2(join57(tmpdir3(), "av-branch-import-"));
|
|
132273
132758
|
const added = await runCommand("git", ["worktree", "add", "--detach", temporaryWorktree, currentHead], {
|
|
132274
132759
|
cwd: root
|
|
132275
132760
|
});
|
|
@@ -132309,8 +132794,8 @@ async function importIsolatedBranch(workspace, root) {
|
|
|
132309
132794
|
// ../../packages/core/src/workspace/safety-net.ts
|
|
132310
132795
|
init_logger();
|
|
132311
132796
|
init_worktree_lifecycle();
|
|
132312
|
-
import { lstat as
|
|
132313
|
-
import { isAbsolute as
|
|
132797
|
+
import { lstat as lstat27, readFile as readFile21, realpath as realpath35 } from "node:fs/promises";
|
|
132798
|
+
import { isAbsolute as isAbsolute20, join as join58, relative as relative18, resolve as resolve36, sep as sep17 } from "node:path";
|
|
132314
132799
|
var CONFLICT_MARKER_PATTERN = /^(<<<<<<<|=======|>>>>>>>)( .*)?$/m;
|
|
132315
132800
|
var REGENERATABLE_LOCKFILE_PATTERNS = [
|
|
132316
132801
|
/(^|\/)package-lock\.json$/,
|
|
@@ -132402,7 +132887,7 @@ async function findConflictMarkerFiles(root, files) {
|
|
|
132402
132887
|
const conflicts = [];
|
|
132403
132888
|
for (const file of files) {
|
|
132404
132889
|
try {
|
|
132405
|
-
const content = await
|
|
132890
|
+
const content = await readFile21(`${root}/${file}`, "utf-8");
|
|
132406
132891
|
if (CONFLICT_MARKER_PATTERN.test(content)) {
|
|
132407
132892
|
conflicts.push(file);
|
|
132408
132893
|
}
|
|
@@ -132412,7 +132897,7 @@ async function findConflictMarkerFiles(root, files) {
|
|
|
132412
132897
|
}
|
|
132413
132898
|
function isInside(parent, child) {
|
|
132414
132899
|
const rel = relative18(parent, child);
|
|
132415
|
-
return rel === "" || rel !== ".." && !rel.startsWith(`..${sep17}`) && !
|
|
132900
|
+
return rel === "" || rel !== ".." && !rel.startsWith(`..${sep17}`) && !isAbsolute20(rel);
|
|
132416
132901
|
}
|
|
132417
132902
|
function untrustedGitError(detail) {
|
|
132418
132903
|
return {
|
|
@@ -132422,14 +132907,14 @@ function untrustedGitError(detail) {
|
|
|
132422
132907
|
};
|
|
132423
132908
|
}
|
|
132424
132909
|
async function validateTrustedWorktree(cwd, repoRoot) {
|
|
132425
|
-
const dotGit =
|
|
132426
|
-
const entry = await
|
|
132910
|
+
const dotGit = join58(cwd, ".git");
|
|
132911
|
+
const entry = await lstat27(dotGit).catch(() => null);
|
|
132427
132912
|
if (!entry)
|
|
132428
132913
|
return untrustedGitError(`missing ${dotGit}`);
|
|
132429
132914
|
if (entry.isSymbolicLink())
|
|
132430
132915
|
return untrustedGitError(`${dotGit} is a symlink`);
|
|
132431
132916
|
if (entry.isFile()) {
|
|
132432
|
-
const contents = await
|
|
132917
|
+
const contents = await readFile21(dotGit, "utf8");
|
|
132433
132918
|
const match = /^gitdir:\s*(.+)$/m.exec(contents);
|
|
132434
132919
|
if (!match?.[1])
|
|
132435
132920
|
return untrustedGitError(`${dotGit} has no gitdir pointer`);
|
|
@@ -132438,14 +132923,14 @@ async function validateTrustedWorktree(cwd, repoRoot) {
|
|
|
132438
132923
|
return untrustedGitError(`${dotGit} does not point into a worktrees directory`);
|
|
132439
132924
|
if (isInside(cwd, gitDir))
|
|
132440
132925
|
return untrustedGitError(`${dotGit} points inside the agent-writable workspace`);
|
|
132441
|
-
const gitDirStat = await
|
|
132926
|
+
const gitDirStat = await lstat27(gitDir).catch(() => null);
|
|
132442
132927
|
if (!gitDirStat?.isDirectory())
|
|
132443
132928
|
return untrustedGitError(`${dotGit} points at a missing directory`);
|
|
132444
132929
|
if (repoRoot) {
|
|
132445
132930
|
const commonDir = resolve36(gitDir, "..", "..");
|
|
132446
132931
|
const [actualCommon, expectedCommon] = await Promise.all([
|
|
132447
132932
|
realpath35(commonDir).catch(() => null),
|
|
132448
|
-
realpath35(
|
|
132933
|
+
realpath35(join58(repoRoot, ".git")).catch(() => null)
|
|
132449
132934
|
]);
|
|
132450
132935
|
if (!expectedCommon || actualCommon !== expectedCommon) {
|
|
132451
132936
|
return untrustedGitError(`${dotGit} points outside the configured repository`);
|
|
@@ -132895,18 +133380,18 @@ function createMissionContainerPorts(dependencies = {}) {
|
|
|
132895
133380
|
}
|
|
132896
133381
|
|
|
132897
133382
|
// src/chief-missions.ts
|
|
132898
|
-
import { join as
|
|
133383
|
+
import { join as join61 } from "node:path";
|
|
132899
133384
|
|
|
132900
133385
|
// src/chief-reconcile.ts
|
|
132901
133386
|
init_execution();
|
|
132902
|
-
import { join as
|
|
133387
|
+
import { join as join59 } from "node:path";
|
|
132903
133388
|
async function reconcileMissionExecution(missionId, options, root = process.cwd()) {
|
|
132904
133389
|
assertNotManagedRun();
|
|
132905
133390
|
const runId = options.run?.trim();
|
|
132906
133391
|
const evidence = options.evidence?.trim();
|
|
132907
133392
|
if (!runId || runId.length > 2000 || !evidence || evidence.length > 2000)
|
|
132908
133393
|
throw new Error("Set --run to the uncertain execution ID and --evidence to 1–2,000 characters describing how you confirmed it stopped.");
|
|
132909
|
-
const store = new MissionStore(
|
|
133394
|
+
const store = new MissionStore(join59(root, ".agent-valley", "missions"));
|
|
132910
133395
|
const unlock = await store.lock(missionId);
|
|
132911
133396
|
try {
|
|
132912
133397
|
const mission = await store.load(missionId);
|
|
@@ -132935,7 +133420,7 @@ function registerMissionReconciliation(missions, root = process.cwd()) {
|
|
|
132935
133420
|
}
|
|
132936
133421
|
|
|
132937
133422
|
// src/chief-watch.ts
|
|
132938
|
-
import { join as
|
|
133423
|
+
import { join as join60 } from "node:path";
|
|
132939
133424
|
async function watchOrders(root = process.cwd(), dependencies = {}) {
|
|
132940
133425
|
assertNotManagedRun();
|
|
132941
133426
|
const controller = new AbortController;
|
|
@@ -132948,7 +133433,7 @@ async function watchOrders(root = process.cwd(), dependencies = {}) {
|
|
|
132948
133433
|
process.once("SIGINT", stop);
|
|
132949
133434
|
process.once("SIGTERM", terminate);
|
|
132950
133435
|
}
|
|
132951
|
-
const missions = new MissionStore(
|
|
133436
|
+
const missions = new MissionStore(join60(root, ".agent-valley", "missions"));
|
|
132952
133437
|
try {
|
|
132953
133438
|
while (!controller.signal.aborted) {
|
|
132954
133439
|
const operations = await operationStore(root).list();
|
|
@@ -133036,7 +133521,7 @@ function registerMissionCommands(program) {
|
|
|
133036
133521
|
await watchOrders(process.cwd(), { service: options.service });
|
|
133037
133522
|
return;
|
|
133038
133523
|
}
|
|
133039
|
-
const missions = await new MissionStore(
|
|
133524
|
+
const missions = await new MissionStore(join61(process.cwd(), ".agent-valley/missions")).list();
|
|
133040
133525
|
if (options.json) {
|
|
133041
133526
|
console.log(JSON.stringify(missions.map((mission) => ({
|
|
133042
133527
|
id: mission.id,
|
|
@@ -133064,11 +133549,11 @@ function registerMissionCommands(program) {
|
|
|
133064
133549
|
}
|
|
133065
133550
|
|
|
133066
133551
|
// src/chief-parent-resume.ts
|
|
133067
|
-
import { join as
|
|
133552
|
+
import { join as join62 } from "node:path";
|
|
133068
133553
|
async function resumeParentForChild(root, child, resume) {
|
|
133069
133554
|
if (child.status !== "completed" || !verifiedMissionEvidence(child))
|
|
133070
133555
|
return child;
|
|
133071
|
-
const directory =
|
|
133556
|
+
const directory = join62(root, ".agent-valley", "operations");
|
|
133072
133557
|
const owners = (await new ContinuousOperationStore(directory).list()).filter((operation) => operation.currentMissionId === child.id);
|
|
133073
133558
|
if (owners.length > 1)
|
|
133074
133559
|
throw new Error("Multiple orders claim this child. Restore a single owning operation before resuming its accepted result.");
|
|
@@ -133092,8 +133577,8 @@ async function resumeParentForChild(root, child, resume) {
|
|
|
133092
133577
|
}
|
|
133093
133578
|
|
|
133094
133579
|
// src/chief-workspace-dependencies.ts
|
|
133095
|
-
import { lstat as
|
|
133096
|
-
import { join as
|
|
133580
|
+
import { lstat as lstat28, mkdir as mkdir27, readdir as readdir18, readFile as readFile22, realpath as realpath36, stat as stat7, symlink } from "node:fs/promises";
|
|
133581
|
+
import { join as join63, relative as relative19, resolve as resolve37, sep as sep18 } from "node:path";
|
|
133097
133582
|
var caches = new Set([".cache", ".vite", ".vite-temp"]);
|
|
133098
133583
|
var inside3 = (root, path) => path === root || path.startsWith(`${root}${sep18}`);
|
|
133099
133584
|
async function prepareMissionDependencies(repository, workspace) {
|
|
@@ -133101,8 +133586,8 @@ async function prepareMissionDependencies(repository, workspace) {
|
|
|
133101
133586
|
const target = await realpath36(workspace);
|
|
133102
133587
|
if (source === target)
|
|
133103
133588
|
throw new Error("Dependency preparation requires a separate mission workspace.");
|
|
133104
|
-
const packagePath =
|
|
133105
|
-
const metadata = await
|
|
133589
|
+
const packagePath = join63(source, "package.json");
|
|
133590
|
+
const metadata = await readFile22(packagePath, "utf8").catch((error) => {
|
|
133106
133591
|
if (error.code === "ENOENT")
|
|
133107
133592
|
return null;
|
|
133108
133593
|
throw error;
|
|
@@ -133131,12 +133616,12 @@ async function prepareMissionDependencies(repository, workspace) {
|
|
|
133131
133616
|
}
|
|
133132
133617
|
const [segment, ...rest] = segments;
|
|
133133
133618
|
if (segment === "*") {
|
|
133134
|
-
for (const entry of await
|
|
133619
|
+
for (const entry of await readdir18(directory, { withFileTypes: true }).catch(() => [])) {
|
|
133135
133620
|
if (entry.isDirectory() && !entry.name.startsWith(".") && entry.name !== "node_modules")
|
|
133136
|
-
await expand(
|
|
133621
|
+
await expand(join63(directory, entry.name), rest);
|
|
133137
133622
|
}
|
|
133138
133623
|
} else if (segment)
|
|
133139
|
-
await expand(
|
|
133624
|
+
await expand(join63(directory, segment), rest);
|
|
133140
133625
|
}
|
|
133141
133626
|
for (const pattern of patterns) {
|
|
133142
133627
|
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)
|
|
@@ -133159,7 +133644,7 @@ async function prepareMissionDependencies(repository, workspace) {
|
|
|
133159
133644
|
throw new Error("A workspace dependency is missing or escapes the mission workspace. Restore that package.");
|
|
133160
133645
|
installed = destination;
|
|
133161
133646
|
}
|
|
133162
|
-
const existing = await
|
|
133647
|
+
const existing = await lstat28(to).catch((error) => {
|
|
133163
133648
|
if (error.code === "ENOENT")
|
|
133164
133649
|
return;
|
|
133165
133650
|
throw error;
|
|
@@ -133169,11 +133654,11 @@ async function prepareMissionDependencies(repository, workspace) {
|
|
|
133169
133654
|
throw new Error("An existing mission dependency differs from the installed package. Preserve it and repair setup.");
|
|
133170
133655
|
return;
|
|
133171
133656
|
}
|
|
133172
|
-
await symlink(installed, to, (await
|
|
133657
|
+
await symlink(installed, to, (await stat7(installed)).isDirectory() ? "dir" : "file");
|
|
133173
133658
|
}
|
|
133174
133659
|
for (const root of roots) {
|
|
133175
|
-
const modules =
|
|
133176
|
-
const installed = await
|
|
133660
|
+
const modules = join63(root, "node_modules");
|
|
133661
|
+
const installed = await stat7(modules).catch(() => {
|
|
133177
133662
|
return;
|
|
133178
133663
|
});
|
|
133179
133664
|
if (!installed?.isDirectory())
|
|
@@ -133181,27 +133666,27 @@ async function prepareMissionDependencies(repository, workspace) {
|
|
|
133181
133666
|
const destinationRoot = await realpath36(resolve37(target, relative19(source, root)));
|
|
133182
133667
|
if (!inside3(target, destinationRoot))
|
|
133183
133668
|
throw new Error("A mission package directory escapes its workspace.");
|
|
133184
|
-
const destination =
|
|
133185
|
-
const existing = await
|
|
133669
|
+
const destination = join63(destinationRoot, "node_modules");
|
|
133670
|
+
const existing = await lstat28(destination).catch(() => {
|
|
133186
133671
|
return;
|
|
133187
133672
|
});
|
|
133188
133673
|
if (existing && !existing.isDirectory())
|
|
133189
133674
|
throw new Error("Mission node_modules must be a local directory.");
|
|
133190
133675
|
await mkdir27(destination, { recursive: true });
|
|
133191
|
-
for (const entry of await
|
|
133676
|
+
for (const entry of await readdir18(modules, { withFileTypes: true })) {
|
|
133192
133677
|
if (caches.has(entry.name))
|
|
133193
133678
|
continue;
|
|
133194
|
-
const from =
|
|
133195
|
-
const to =
|
|
133679
|
+
const from = join63(modules, entry.name);
|
|
133680
|
+
const to = join63(destination, entry.name);
|
|
133196
133681
|
if (entry.name.startsWith("@") && entry.isDirectory()) {
|
|
133197
|
-
const scope = await
|
|
133682
|
+
const scope = await lstat28(to).catch(() => {
|
|
133198
133683
|
return;
|
|
133199
133684
|
});
|
|
133200
133685
|
if (scope && !scope.isDirectory())
|
|
133201
133686
|
throw new Error("A dependency scope must be a local directory.");
|
|
133202
133687
|
await mkdir27(to, { recursive: true });
|
|
133203
|
-
for (const member of await
|
|
133204
|
-
await link(
|
|
133688
|
+
for (const member of await readdir18(from))
|
|
133689
|
+
await link(join63(from, member), join63(to, member));
|
|
133205
133690
|
} else
|
|
133206
133691
|
await link(from, to);
|
|
133207
133692
|
}
|
|
@@ -133224,7 +133709,7 @@ async function runOrder(goal, options, root = process.cwd()) {
|
|
|
133224
133709
|
if (!options.resume && [options.retry, options.resolveEffect, options.effectResult, options.accountRun, options.accountCost].some((value) => value !== undefined && value !== false))
|
|
133225
133710
|
throw new Error("Use --resume <id> for retry, external-effect resolution or cost reconciliation.");
|
|
133226
133711
|
await ensureRuntimeGitignore(root);
|
|
133227
|
-
const store = new MissionStore(
|
|
133712
|
+
const store = new MissionStore(join64(root, ".agent-valley/missions"));
|
|
133228
133713
|
const id = options.resume ?? options.missionId ?? randomUUID24();
|
|
133229
133714
|
const unlock = await store.lock(id);
|
|
133230
133715
|
const abortController = new AbortController;
|
|
@@ -133273,7 +133758,7 @@ async function runOrder(goal, options, root = process.cwd()) {
|
|
|
133273
133758
|
throw new Error("Internal child launch does not match its saved operation, goal and accepted baseline. Restore the original operation checkpoint.");
|
|
133274
133759
|
if (Boolean(options.baselineWorkspace) !== Boolean(options.operationId))
|
|
133275
133760
|
throw new Error("An internal operation snapshot requires both its operation identity and accepted baseline.");
|
|
133276
|
-
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 ?
|
|
133761
|
+
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);
|
|
133277
133762
|
if (options.operationId)
|
|
133278
133763
|
await restoreOperationOrigin(config.workspace, workspace.path);
|
|
133279
133764
|
if (!codeDelivery)
|
|
@@ -133304,6 +133789,13 @@ async function runOrder(goal, options, root = process.cwd()) {
|
|
|
133304
133789
|
containerObservationPolicy: operation ? operation.containerObservationPolicy : config.containerObservationPolicy,
|
|
133305
133790
|
containerObservation: operation?.containerObservation,
|
|
133306
133791
|
toolEnvKeys: config.toolEnvKeys,
|
|
133792
|
+
...operation?.actorHealth?.length ? {
|
|
133793
|
+
operations: {
|
|
133794
|
+
runs: [],
|
|
133795
|
+
routingEvidence: seedProviderHealthEvidence([], operation.actorHealth),
|
|
133796
|
+
reviewDecisions: []
|
|
133797
|
+
}
|
|
133798
|
+
} : {},
|
|
133307
133799
|
capturePolicy: config.capturePolicy,
|
|
133308
133800
|
status: "pending",
|
|
133309
133801
|
tasks: [],
|
|
@@ -133348,6 +133840,8 @@ Resume: bun av order --resume ${id}`);
|
|
|
133348
133840
|
}
|
|
133349
133841
|
if (mission.operatingPolicy?.memory || mission.operatingPolicy?.metricTargets?.length) {
|
|
133350
133842
|
mission.organizationContext = await organizationContext2(repository, mission);
|
|
133843
|
+
if (!options.resume && mission.operations)
|
|
133844
|
+
mission.operations.routingEvidence = seedProviderHealthEvidence(mission.organizationContext.routeEvidence, aggregateProviderHealth(mission));
|
|
133351
133845
|
mission.operations ??= {
|
|
133352
133846
|
runs: [],
|
|
133353
133847
|
routingEvidence: mission.organizationContext.routeEvidence,
|
|
@@ -133438,7 +133932,7 @@ async function dispatchOrder(goal, options, root = process.cwd(), dependencies =
|
|
|
133438
133932
|
};
|
|
133439
133933
|
const [operation, mission] = await Promise.all([
|
|
133440
133934
|
operationStore(root).load(options.resume).catch(missing),
|
|
133441
|
-
new MissionStore(
|
|
133935
|
+
new MissionStore(join64(root, ".agent-valley", "missions")).load(options.resume).catch(missing)
|
|
133442
133936
|
]);
|
|
133443
133937
|
if (operation && mission)
|
|
133444
133938
|
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.`);
|
|
@@ -133494,22 +133988,22 @@ function registerChiefCommands(program) {
|
|
|
133494
133988
|
}
|
|
133495
133989
|
|
|
133496
133990
|
// src/chief-organization.ts
|
|
133497
|
-
import { readFile as
|
|
133498
|
-
import { isAbsolute as
|
|
133991
|
+
import { readFile as readFile23, stat as stat8 } from "node:fs/promises";
|
|
133992
|
+
import { isAbsolute as isAbsolute21, join as join65, resolve as resolve38 } from "node:path";
|
|
133499
133993
|
init_chief_schema();
|
|
133500
133994
|
init_yaml_loader();
|
|
133501
133995
|
function organizationRepository(root, workspace) {
|
|
133502
133996
|
const repository = workspace ?? loadProjectConfig(root)?.workspace?.root ?? root;
|
|
133503
|
-
if (!
|
|
133997
|
+
if (!isAbsolute21(repository))
|
|
133504
133998
|
throw new Error("Set workspace.root in av.yaml or --workspace to an absolute source repository path.");
|
|
133505
133999
|
return repository;
|
|
133506
134000
|
}
|
|
133507
134001
|
async function inputFile(file) {
|
|
133508
134002
|
const path = resolve38(file);
|
|
133509
|
-
const info = await
|
|
134003
|
+
const info = await stat8(path);
|
|
133510
134004
|
if (!info.isFile() || info.size > 2000000)
|
|
133511
134005
|
throw new Error("Use a regular JSON input file no larger than 2 MB.");
|
|
133512
|
-
return
|
|
134006
|
+
return readFile23(path, "utf8");
|
|
133513
134007
|
}
|
|
133514
134008
|
function registerOrganizationCommands(program) {
|
|
133515
134009
|
const memory = program.command("memory").description("Repository organization decisions and standards");
|
|
@@ -133549,13 +134043,13 @@ function registerOrganizationCommands(program) {
|
|
|
133549
134043
|
});
|
|
133550
134044
|
const reports = program.command("reports").description("Inspect and retry third-party report attachments");
|
|
133551
134045
|
reports.command("list").option("--workspace <path>", "Source repository").action(async (opts) => {
|
|
133552
|
-
console.log(JSON.stringify(await listReportDeliveries(
|
|
134046
|
+
console.log(JSON.stringify(await listReportDeliveries(join65(organizationRepository(process.cwd(), opts.workspace), ".agent-valley")), null, 2));
|
|
133553
134047
|
});
|
|
133554
134048
|
reports.command("retry").option("--workspace <path>", "Source repository").action(async (opts) => {
|
|
133555
134049
|
const config = mergeChiefConfig(loadGlobalConfig()?.chief, loadProjectConfig()?.chief);
|
|
133556
134050
|
if (!config.reporting)
|
|
133557
134051
|
throw new Error("Set chief.reporting.destinations in av.yaml before retrying reports.");
|
|
133558
|
-
console.log(JSON.stringify(await retryPendingReports(config.reporting,
|
|
134052
|
+
console.log(JSON.stringify(await retryPendingReports(config.reporting, join65(organizationRepository(process.cwd(), opts.workspace), ".agent-valley")), null, 2));
|
|
133559
134053
|
});
|
|
133560
134054
|
}
|
|
133561
134055
|
|
|
@@ -133580,10 +134074,10 @@ var import_picocolors = __toESM(require_picocolors(), 1);
|
|
|
133580
134074
|
init_project_config_path();
|
|
133581
134075
|
init_yaml_loader();
|
|
133582
134076
|
init_doctor_checks();
|
|
133583
|
-
import { join as
|
|
134077
|
+
import { join as join69 } from "node:path";
|
|
133584
134078
|
|
|
133585
134079
|
// src/doctor-oma-checks.ts
|
|
133586
|
-
import { join as
|
|
134080
|
+
import { join as join68 } from "node:path";
|
|
133587
134081
|
function checkOma(project, deps) {
|
|
133588
134082
|
const strict = project?.oma?.mode === "strict";
|
|
133589
134083
|
const order = !!project && !project.tracker && !project.linear && !project.github;
|
|
@@ -133671,7 +134165,7 @@ function checkOma(project, deps) {
|
|
|
133671
134165
|
fix: "Set verify.command to a deterministic non-build check in av.yaml before using oma.mode: strict.",
|
|
133672
134166
|
critical: true
|
|
133673
134167
|
});
|
|
133674
|
-
const triggerPath =
|
|
134168
|
+
const triggerPath = join68(deps.cwd, ".agents", "hooks", "core", "triggers.json");
|
|
133675
134169
|
let table = null;
|
|
133676
134170
|
try {
|
|
133677
134171
|
table = parseTriggerTable(deps.readFileSync(triggerPath));
|
|
@@ -133688,7 +134182,7 @@ function checkOma(project, deps) {
|
|
|
133688
134182
|
return results;
|
|
133689
134183
|
}
|
|
133690
134184
|
results.push({ id: "oma.triggers", name: "OMA trigger table", status: "pass", message: triggerPath, critical: false });
|
|
133691
|
-
const missing = Object.entries(table.workflows).filter(([name, workflow]) => !workflow.persistent && !table.excludedWorkflows.includes(name)).map(([name]) =>
|
|
134185
|
+
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));
|
|
133692
134186
|
results.push(missing.length === 0 ? {
|
|
133693
134187
|
id: "oma.workflows",
|
|
133694
134188
|
name: "OMA workflow files",
|
|
@@ -133763,7 +134257,7 @@ function checkTunnel(project, deps) {
|
|
|
133763
134257
|
}
|
|
133764
134258
|
const mode = project?.tunnel?.cloudflare?.mode ?? "quick";
|
|
133765
134259
|
if (mode === "named") {
|
|
133766
|
-
const certPath =
|
|
134260
|
+
const certPath = join69(deps.home, ".cloudflared", "cert.pem");
|
|
133767
134261
|
if (!deps.existsSync(certPath)) {
|
|
133768
134262
|
return {
|
|
133769
134263
|
id: "tunnel",
|
|
@@ -133803,7 +134297,7 @@ function checkTunnel(project, deps) {
|
|
|
133803
134297
|
critical: false
|
|
133804
134298
|
};
|
|
133805
134299
|
}
|
|
133806
|
-
const ngrokConfigPath = deps.platform === "darwin" ?
|
|
134300
|
+
const ngrokConfigPath = deps.platform === "darwin" ? join69(deps.home, "Library", "Application Support", "ngrok", "ngrok.yml") : join69(deps.home, ".config", "ngrok", "ngrok.yml");
|
|
133807
134301
|
if (!deps.existsSync(ngrokConfigPath)) {
|
|
133808
134302
|
return {
|
|
133809
134303
|
id: "tunnel",
|
|
@@ -133874,7 +134368,7 @@ function checkConfig(deps) {
|
|
|
133874
134368
|
critical: true
|
|
133875
134369
|
});
|
|
133876
134370
|
}
|
|
133877
|
-
const projectPath =
|
|
134371
|
+
const projectPath = join69(deps.cwd, PROJECT_CONFIG_FILENAME);
|
|
133878
134372
|
try {
|
|
133879
134373
|
project = deps.loadProjectConfig(deps.cwd);
|
|
133880
134374
|
results.push(project ? {
|
|
@@ -138430,8 +138924,8 @@ init_team_relay_error();
|
|
|
138430
138924
|
|
|
138431
138925
|
// ../../packages/core/src/relay/turso-migration-assets.ts
|
|
138432
138926
|
init_zod();
|
|
138433
|
-
import { copyFile as copyFile3, lstat as
|
|
138434
|
-
import { dirname as dirname15, join as
|
|
138927
|
+
import { copyFile as copyFile3, lstat as lstat33, mkdir as mkdir28, readFile as readFile25 } from "node:fs/promises";
|
|
138928
|
+
import { dirname as dirname15, join as join75 } from "node:path";
|
|
138435
138929
|
import { fileURLToPath as fileURLToPath3 } from "node:url";
|
|
138436
138930
|
var TURSO_MIGRATION_ASSET_PATH = "assets/turso/migrations";
|
|
138437
138931
|
var journalSchema = object({
|
|
@@ -138452,7 +138946,7 @@ function tursoMigrationAssetCandidates(moduleUrl = import.meta.url) {
|
|
|
138452
138946
|
];
|
|
138453
138947
|
}
|
|
138454
138948
|
async function regularFile2(path) {
|
|
138455
|
-
const info = await
|
|
138949
|
+
const info = await lstat33(path);
|
|
138456
138950
|
if (!info.isFile() || info.isSymbolicLink())
|
|
138457
138951
|
throw new Error(`Turso migration asset ${path} must be a regular file. Restore the checkout or reinstall the CLI package.`);
|
|
138458
138952
|
}
|
|
@@ -138460,7 +138954,7 @@ async function loadTursoMigrationAssets(candidates = tursoMigrationAssetCandidat
|
|
|
138460
138954
|
for (const directory of candidates) {
|
|
138461
138955
|
let info;
|
|
138462
138956
|
try {
|
|
138463
|
-
info = await
|
|
138957
|
+
info = await lstat33(directory);
|
|
138464
138958
|
} catch (error) {
|
|
138465
138959
|
if (error.code === "ENOENT")
|
|
138466
138960
|
continue;
|
|
@@ -138469,19 +138963,19 @@ async function loadTursoMigrationAssets(candidates = tursoMigrationAssetCandidat
|
|
|
138469
138963
|
if (!info.isDirectory() || info.isSymbolicLink())
|
|
138470
138964
|
throw new Error(`Turso migration directory ${directory} must be a regular directory. Restore the checkout or reinstall the CLI package.`);
|
|
138471
138965
|
try {
|
|
138472
|
-
const meta = await
|
|
138966
|
+
const meta = await lstat33(join75(directory, "meta"));
|
|
138473
138967
|
if (!meta.isDirectory() || meta.isSymbolicLink())
|
|
138474
138968
|
throw new Error("Invalid migration metadata directory");
|
|
138475
|
-
const journalPath =
|
|
138969
|
+
const journalPath = join75(directory, "meta/_journal.json");
|
|
138476
138970
|
await regularFile2(journalPath);
|
|
138477
|
-
const journal = journalSchema.parse(JSON.parse(await
|
|
138971
|
+
const journal = journalSchema.parse(JSON.parse(await readFile25(journalPath, "utf8")));
|
|
138478
138972
|
const tags = journal.entries.map((entry) => entry.tag);
|
|
138479
138973
|
if (new Set(tags).size !== tags.length)
|
|
138480
138974
|
throw new Error("Duplicate migration tags");
|
|
138481
138975
|
const files = ["meta/_journal.json", ...tags.map((tag) => `${tag}.sql`)];
|
|
138482
138976
|
for (const file of files.slice(1)) {
|
|
138483
|
-
await regularFile2(
|
|
138484
|
-
if (!(await
|
|
138977
|
+
await regularFile2(join75(directory, file));
|
|
138978
|
+
if (!(await readFile25(join75(directory, file), "utf8")).trim())
|
|
138485
138979
|
throw new Error("Empty migration SQL");
|
|
138486
138980
|
}
|
|
138487
138981
|
return { directory, files };
|