agent-valley 4.8.5 → 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 +1147 -657
- package/dist/supervisor.js +15 -2
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -7086,6 +7086,7 @@ var init_contracts = __esm(() => {
|
|
|
7086
7086
|
"authentication",
|
|
7087
7087
|
"rate-limit",
|
|
7088
7088
|
"provider",
|
|
7089
|
+
"actor-cooldown",
|
|
7089
7090
|
"environment",
|
|
7090
7091
|
"implementation",
|
|
7091
7092
|
"unknown-effect",
|
|
@@ -7467,7 +7468,7 @@ var init_review_gates = __esm(() => {
|
|
|
7467
7468
|
});
|
|
7468
7469
|
|
|
7469
7470
|
// ../../packages/core/src/chief/operations.ts
|
|
7470
|
-
var actorType, text3, amount, routingCandidateSchema, chiefOperatingPolicySchema, operatingRunSchema, routeEvidenceSchema, reviewDecisionSchema, chiefOperationsSchema;
|
|
7471
|
+
var actorType, text3, amount, routingCandidateSchema, chiefOperatingPolicySchema, operatingRunSchema, providerHealthSchema, providerHealthEvidenceSchema, routeEvidenceSchema, reviewDecisionSchema, chiefOperationsSchema;
|
|
7471
7472
|
var init_operations = __esm(() => {
|
|
7472
7473
|
init_zod();
|
|
7473
7474
|
init_skill_matrix_schema();
|
|
@@ -7526,6 +7527,7 @@ var init_operations = __esm(() => {
|
|
|
7526
7527
|
costUsd: amount.nullable(),
|
|
7527
7528
|
outcome: _enum(["pending", "passed", "rejected", "failed"]),
|
|
7528
7529
|
executionState: _enum(["running", "settled", "unknown"]).optional(),
|
|
7530
|
+
nativeOutcome: _enum(["passed", "failed", "cancelled"]).optional(),
|
|
7529
7531
|
executionRecovery: _enum(["local-process", "reconcile"]).optional(),
|
|
7530
7532
|
routingExclusion: strictObject({
|
|
7531
7533
|
reason: literal("coordinator-cancelled"),
|
|
@@ -7536,13 +7538,24 @@ var init_operations = __esm(() => {
|
|
|
7536
7538
|
evidence: text3.optional(),
|
|
7537
7539
|
fingerprint: text3.optional()
|
|
7538
7540
|
});
|
|
7541
|
+
providerHealthSchema = strictObject({
|
|
7542
|
+
consecutiveFailures: number2().int().nonnegative(),
|
|
7543
|
+
lastOutcomeAt: exports_iso.datetime(),
|
|
7544
|
+
cooldownUntil: exports_iso.datetime().optional()
|
|
7545
|
+
});
|
|
7546
|
+
providerHealthEvidenceSchema = strictObject({
|
|
7547
|
+
actorType,
|
|
7548
|
+
model: text3.optional(),
|
|
7549
|
+
providerHealth: providerHealthSchema
|
|
7550
|
+
});
|
|
7539
7551
|
routeEvidenceSchema = strictObject({
|
|
7540
7552
|
actorType,
|
|
7541
7553
|
model: text3.optional(),
|
|
7542
7554
|
samples: number2().int().nonnegative(),
|
|
7543
7555
|
successes: number2().int().nonnegative(),
|
|
7544
7556
|
totalCostUsd: amount.nullable(),
|
|
7545
|
-
successfulDeliverableCostUsd: amount.nullable()
|
|
7557
|
+
successfulDeliverableCostUsd: amount.nullable(),
|
|
7558
|
+
providerHealth: providerHealthSchema.optional()
|
|
7546
7559
|
}).refine((entry) => entry.successes <= entry.samples, "Route successes cannot exceed actual samples.");
|
|
7547
7560
|
reviewDecisionSchema = strictObject({
|
|
7548
7561
|
taskId: text3,
|
|
@@ -17599,10 +17612,47 @@ var init_claude_session = __esm(() => {
|
|
|
17599
17612
|
});
|
|
17600
17613
|
|
|
17601
17614
|
// ../../packages/core/src/sessions/qwen-session.ts
|
|
17602
|
-
var QwenSession;
|
|
17615
|
+
var computerUseTools, QwenSession;
|
|
17603
17616
|
var init_qwen_session = __esm(() => {
|
|
17604
17617
|
init_claude_session();
|
|
17605
17618
|
init_native_failure();
|
|
17619
|
+
computerUseTools = [
|
|
17620
|
+
"bring_to_front",
|
|
17621
|
+
"check_for_update",
|
|
17622
|
+
"check_permissions",
|
|
17623
|
+
"click",
|
|
17624
|
+
"double_click",
|
|
17625
|
+
"drag",
|
|
17626
|
+
"end_session",
|
|
17627
|
+
"get_accessibility_tree",
|
|
17628
|
+
"get_agent_cursor_state",
|
|
17629
|
+
"get_config",
|
|
17630
|
+
"get_cursor_position",
|
|
17631
|
+
"get_recording_state",
|
|
17632
|
+
"get_screen_size",
|
|
17633
|
+
"get_window_state",
|
|
17634
|
+
"hotkey",
|
|
17635
|
+
"kill_app",
|
|
17636
|
+
"launch_app",
|
|
17637
|
+
"list_apps",
|
|
17638
|
+
"list_windows",
|
|
17639
|
+
"move_cursor",
|
|
17640
|
+
"page",
|
|
17641
|
+
"press_key",
|
|
17642
|
+
"replay_trajectory",
|
|
17643
|
+
"right_click",
|
|
17644
|
+
"scroll",
|
|
17645
|
+
"set_agent_cursor_enabled",
|
|
17646
|
+
"set_agent_cursor_motion",
|
|
17647
|
+
"set_agent_cursor_style",
|
|
17648
|
+
"set_config",
|
|
17649
|
+
"set_value",
|
|
17650
|
+
"start_recording",
|
|
17651
|
+
"start_session",
|
|
17652
|
+
"stop_recording",
|
|
17653
|
+
"type_text",
|
|
17654
|
+
"zoom"
|
|
17655
|
+
].map((name) => `computer_use__${name}`);
|
|
17606
17656
|
QwenSession = class QwenSession extends ClaudeSession {
|
|
17607
17657
|
vendor = "qwen";
|
|
17608
17658
|
actualModel;
|
|
@@ -17610,6 +17660,9 @@ var init_qwen_session = __esm(() => {
|
|
|
17610
17660
|
resultEvent;
|
|
17611
17661
|
buildArgs() {
|
|
17612
17662
|
const args = ["--output-format", "stream-json", "--yolo"];
|
|
17663
|
+
const purpose = this.config?.options?.computerUsePurpose;
|
|
17664
|
+
if (typeof purpose !== "string" || !purpose.trim())
|
|
17665
|
+
args.push("--exclude-tools", computerUseTools.join(","));
|
|
17613
17666
|
if (this.config?.model)
|
|
17614
17667
|
args.push("--model", this.config.model);
|
|
17615
17668
|
return args;
|
|
@@ -21280,12 +21333,12 @@ var require_cross_spawn = __commonJS(function(exports, module) {
|
|
|
21280
21333
|
// src/doctor-checks.ts
|
|
21281
21334
|
import { spawnSync } from "node:child_process";
|
|
21282
21335
|
import { existsSync as existsSync3, readFileSync as readFileSync6 } from "node:fs";
|
|
21283
|
-
import { homedir as
|
|
21284
|
-
import { join as
|
|
21336
|
+
import { homedir as homedir6 } from "node:os";
|
|
21337
|
+
import { join as join24 } from "node:path";
|
|
21285
21338
|
function defaultDoctorDeps() {
|
|
21286
21339
|
return {
|
|
21287
21340
|
cwd: process.cwd(),
|
|
21288
|
-
home:
|
|
21341
|
+
home: homedir6(),
|
|
21289
21342
|
platform: process.platform,
|
|
21290
21343
|
env: process.env,
|
|
21291
21344
|
existsSync: existsSync3,
|
|
@@ -21308,19 +21361,19 @@ function probeAgentAuth(agent, deps) {
|
|
|
21308
21361
|
case "qwen":
|
|
21309
21362
|
return { status: "unknown", message: "Qwen needs a selected API provider/model; configure qwen /auth" };
|
|
21310
21363
|
case "claude": {
|
|
21311
|
-
const p =
|
|
21364
|
+
const p = join24(home, ".claude");
|
|
21312
21365
|
return exists(p) ? { status: "pass", message: `${p} present` } : { status: "fail", message: `${p} not found` };
|
|
21313
21366
|
}
|
|
21314
21367
|
case "codex": {
|
|
21315
|
-
const p =
|
|
21368
|
+
const p = join24(home, ".codex");
|
|
21316
21369
|
return exists(p) ? { status: "pass", message: `${p} present` } : { status: "fail", message: `${p} not found` };
|
|
21317
21370
|
}
|
|
21318
21371
|
case "grok": {
|
|
21319
|
-
const p =
|
|
21372
|
+
const p = join24(home, ".grok", "config.toml");
|
|
21320
21373
|
return exists(p) ? { status: "pass", message: `${p} present` } : { status: "fail", message: `${p} not found` };
|
|
21321
21374
|
}
|
|
21322
21375
|
case "kimi": {
|
|
21323
|
-
const p =
|
|
21376
|
+
const p = join24(home, ".kimi-code", "config.toml");
|
|
21324
21377
|
if (!exists(p))
|
|
21325
21378
|
return { status: "fail", message: `${p} not found` };
|
|
21326
21379
|
try {
|
|
@@ -21331,7 +21384,7 @@ function probeAgentAuth(agent, deps) {
|
|
|
21331
21384
|
}
|
|
21332
21385
|
}
|
|
21333
21386
|
case "opencode": {
|
|
21334
|
-
const p =
|
|
21387
|
+
const p = join24(home, ".local", "share", "opencode", "auth.json");
|
|
21335
21388
|
return exists(p) ? { status: "pass", message: `${p} present` } : { status: "fail", message: `${p} not found` };
|
|
21336
21389
|
}
|
|
21337
21390
|
case "antigravity":
|
|
@@ -21437,7 +21490,7 @@ var init_doctor_checks = __esm(() => {
|
|
|
21437
21490
|
});
|
|
21438
21491
|
|
|
21439
21492
|
// src/qwen-discovery.ts
|
|
21440
|
-
import { join as
|
|
21493
|
+
import { join as join25 } from "node:path";
|
|
21441
21494
|
function record2(value) {
|
|
21442
21495
|
return value && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
21443
21496
|
}
|
|
@@ -21454,7 +21507,7 @@ function qwenAuth(deps, read) {
|
|
|
21454
21507
|
const home = qwenProfilePath(deps.home, deps.env);
|
|
21455
21508
|
if (!home)
|
|
21456
21509
|
return problem("Use an absolute QWEN_HOME so discovery and mission worktrees share the same profile");
|
|
21457
|
-
const settings = record2(read(
|
|
21510
|
+
const settings = record2(read(join25(home, "settings.json")));
|
|
21458
21511
|
const localEnv = record2(settings.env);
|
|
21459
21512
|
const allowed = new Set(getAgentAuthEnvKeys("qwen"));
|
|
21460
21513
|
const env = (key) => deps.env[key] ?? localEnv[key];
|
|
@@ -21500,9 +21553,9 @@ var init_qwen_discovery = __esm(() => {
|
|
|
21500
21553
|
|
|
21501
21554
|
// src/agent-discovery.ts
|
|
21502
21555
|
import { spawn as spawn8 } from "node:child_process";
|
|
21503
|
-
import { accessSync, constants as
|
|
21504
|
-
import { homedir as
|
|
21505
|
-
import { join as
|
|
21556
|
+
import { accessSync, constants as constants11, readFileSync as readFileSync7, statSync as statSync3 } from "node:fs";
|
|
21557
|
+
import { homedir as homedir7 } from "node:os";
|
|
21558
|
+
import { join as join26 } from "node:path";
|
|
21506
21559
|
import { stripVTControlCharacters as stripVTControlCharacters3 } from "node:util";
|
|
21507
21560
|
function record3(value) {
|
|
21508
21561
|
return value !== null && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
@@ -21593,13 +21646,13 @@ function probeNativeCli(path, args, options) {
|
|
|
21593
21646
|
}
|
|
21594
21647
|
function defaultDeps() {
|
|
21595
21648
|
return {
|
|
21596
|
-
home:
|
|
21649
|
+
home: homedir7(),
|
|
21597
21650
|
env: process.env,
|
|
21598
21651
|
now: Date.now,
|
|
21599
21652
|
resolveBinary: resolveBinaryPath,
|
|
21600
21653
|
isExecutableFile: (path) => {
|
|
21601
21654
|
try {
|
|
21602
|
-
accessSync(path,
|
|
21655
|
+
accessSync(path, constants11.X_OK);
|
|
21603
21656
|
return statSync3(path).isFile();
|
|
21604
21657
|
} catch {
|
|
21605
21658
|
return false;
|
|
@@ -21656,8 +21709,8 @@ function expired(token, expiresAt, now, unit = 1) {
|
|
|
21656
21709
|
return false;
|
|
21657
21710
|
}
|
|
21658
21711
|
function kimiAuth(deps) {
|
|
21659
|
-
const home = nonempty(deps.env.KIMI_CODE_HOME) ? deps.env.KIMI_CODE_HOME :
|
|
21660
|
-
const config = record3(readState(
|
|
21712
|
+
const home = nonempty(deps.env.KIMI_CODE_HOME) ? deps.env.KIMI_CODE_HOME : join26(deps.home, ".kimi-code");
|
|
21713
|
+
const config = record3(readState(join26(home, "config.toml"), deps, deps.parseToml));
|
|
21661
21714
|
const model = record3(record3(config.models)[String(config.default_model ?? "")]);
|
|
21662
21715
|
const provider = record3(record3(config.providers)[String(model.provider ?? "")]);
|
|
21663
21716
|
if (nonempty(model.model) && nonempty(provider.type) && nonempty(provider.base_url)) {
|
|
@@ -21671,7 +21724,7 @@ function kimiAuth(deps) {
|
|
|
21671
21724
|
if (nonempty(oauth.key) && (oauth.storage === "file" || oauth.storage === "keyring")) {
|
|
21672
21725
|
const name = oauth.key.split("/").at(-1);
|
|
21673
21726
|
if (name && /^[\w-]+$/.test(name)) {
|
|
21674
|
-
const token = record3(readState(
|
|
21727
|
+
const token = record3(readState(join26(home, "credentials", `${name}.json`), deps));
|
|
21675
21728
|
if (nonempty(token.access_token) && nonempty(token.refresh_token) && typeof token.expires_at === "number" && !expired(token.access_token, token.expires_at, deps.now(), 1000)) {
|
|
21676
21729
|
return { readiness: "ready", reason: "Kimi native OAuth credentials found" };
|
|
21677
21730
|
}
|
|
@@ -21689,15 +21742,15 @@ function localAuth(agent, deps) {
|
|
|
21689
21742
|
if (agent === "kimi")
|
|
21690
21743
|
return kimiAuth(deps);
|
|
21691
21744
|
if (agent === "antigravity") {
|
|
21692
|
-
const settings = record3(readState(
|
|
21745
|
+
const settings = record3(readState(join26(deps.home, ".gemini", "antigravity-cli", "settings.json"), deps));
|
|
21693
21746
|
if (settings.modelProvider === "gemini") {
|
|
21694
21747
|
return nonempty(deps.env.GEMINI_API_KEY) ? { readiness: "ready", reason: "Antigravity Gemini provider and credentials are configured" } : missing(agent, "Set GEMINI_API_KEY for the configured Gemini provider");
|
|
21695
21748
|
}
|
|
21696
21749
|
return null;
|
|
21697
21750
|
}
|
|
21698
21751
|
if (agent === "codex") {
|
|
21699
|
-
const home = nonempty(deps.env.CODEX_HOME) ? deps.env.CODEX_HOME :
|
|
21700
|
-
const value = readState(
|
|
21752
|
+
const home = nonempty(deps.env.CODEX_HOME) ? deps.env.CODEX_HOME : join26(deps.home, ".codex");
|
|
21753
|
+
const value = readState(join26(home, "auth.json"), deps);
|
|
21701
21754
|
if (value === null)
|
|
21702
21755
|
return null;
|
|
21703
21756
|
const auth = record3(value);
|
|
@@ -21713,8 +21766,8 @@ function localAuth(agent, deps) {
|
|
|
21713
21766
|
return missing(agent, "Codex authentication file has no complete credentials");
|
|
21714
21767
|
}
|
|
21715
21768
|
if (agent === "claude") {
|
|
21716
|
-
const home = nonempty(deps.env.CLAUDE_CONFIG_DIR) ? deps.env.CLAUDE_CONFIG_DIR :
|
|
21717
|
-
const value = readState(
|
|
21769
|
+
const home = nonempty(deps.env.CLAUDE_CONFIG_DIR) ? deps.env.CLAUDE_CONFIG_DIR : join26(deps.home, ".claude");
|
|
21770
|
+
const value = readState(join26(home, ".credentials.json"), deps);
|
|
21718
21771
|
if (value === null)
|
|
21719
21772
|
return null;
|
|
21720
21773
|
const oauth = record3(record3(value).claudeAiOauth);
|
|
@@ -21724,8 +21777,8 @@ function localAuth(agent, deps) {
|
|
|
21724
21777
|
return missing(agent, "Claude authentication file has no complete credentials");
|
|
21725
21778
|
}
|
|
21726
21779
|
if (agent === "opencode") {
|
|
21727
|
-
const home = nonempty(deps.env.XDG_DATA_HOME) ? deps.env.XDG_DATA_HOME :
|
|
21728
|
-
const auth = record3(readState(
|
|
21780
|
+
const home = nonempty(deps.env.XDG_DATA_HOME) ? deps.env.XDG_DATA_HOME : join26(deps.home, ".local", "share");
|
|
21781
|
+
const auth = record3(readState(join26(home, "opencode", "auth.json"), deps));
|
|
21729
21782
|
for (const value of Object.values(auth)) {
|
|
21730
21783
|
const credential = record3(value);
|
|
21731
21784
|
if (credential.type === "api" && nonempty(credential.key)) {
|
|
@@ -22393,7 +22446,7 @@ var require_dist3 = __commonJS(function(exports) {
|
|
|
22393
22446
|
});
|
|
22394
22447
|
|
|
22395
22448
|
// ../../node_modules/.bun/readdirp@5.1.1/node_modules/readdirp/index.js
|
|
22396
|
-
import { lstat as
|
|
22449
|
+
import { lstat as lstat29, readdir as readdir19, realpath as realpath38, stat as stat9 } from "node:fs/promises";
|
|
22397
22450
|
import { join as pjoin, resolve as presolve, sep as psep } from "node:path";
|
|
22398
22451
|
import { Readable as Readable2 } from "node:stream";
|
|
22399
22452
|
function readdirp(root, options = {}) {
|
|
@@ -22490,7 +22543,7 @@ var init_readdirp = __esm(() => {
|
|
|
22490
22543
|
const type = opts.type ?? defaultOptions4.type;
|
|
22491
22544
|
this._fileFilter = normalizeFilter(opts.fileFilter);
|
|
22492
22545
|
this._directoryFilter = normalizeFilter(opts.directoryFilter);
|
|
22493
|
-
const statMethod = opts.lstat ?
|
|
22546
|
+
const statMethod = opts.lstat ? lstat29 : stat9;
|
|
22494
22547
|
if (wantBigintFsStats) {
|
|
22495
22548
|
this._stat = (path) => statMethod(path, { bigint: true });
|
|
22496
22549
|
} else {
|
|
@@ -22571,7 +22624,7 @@ var init_readdirp = __esm(() => {
|
|
|
22571
22624
|
async _exploreDir(path, depth) {
|
|
22572
22625
|
let files;
|
|
22573
22626
|
try {
|
|
22574
|
-
files = await
|
|
22627
|
+
files = await readdir19(path, this._rdOptions);
|
|
22575
22628
|
} catch (error) {
|
|
22576
22629
|
this._onError(error);
|
|
22577
22630
|
}
|
|
@@ -22617,7 +22670,7 @@ var init_readdirp = __esm(() => {
|
|
|
22617
22670
|
const full = entry.fullPath;
|
|
22618
22671
|
try {
|
|
22619
22672
|
const entryRealPath = await realpath38(full);
|
|
22620
|
-
const entryRealPathStats = await
|
|
22673
|
+
const entryRealPathStats = await lstat29(entryRealPath);
|
|
22621
22674
|
if (entryRealPathStats.isFile()) {
|
|
22622
22675
|
return "file";
|
|
22623
22676
|
}
|
|
@@ -22645,7 +22698,7 @@ var init_readdirp = __esm(() => {
|
|
|
22645
22698
|
|
|
22646
22699
|
// ../../node_modules/.bun/chokidar@5.0.0/node_modules/chokidar/handler.js
|
|
22647
22700
|
import { watch as fs_watch, unwatchFile, watchFile } from "node:fs";
|
|
22648
|
-
import { realpath as fsrealpath, lstat as
|
|
22701
|
+
import { realpath as fsrealpath, lstat as lstat30, open as open19, stat as stat10 } from "node:fs/promises";
|
|
22649
22702
|
import { type as osType } from "node:os";
|
|
22650
22703
|
import * as sp from "node:path";
|
|
22651
22704
|
function createFsWatchInstance(path, options, listener, errHandler, emitRaw) {
|
|
@@ -22717,7 +22770,7 @@ class NodeFsHandler {
|
|
|
22717
22770
|
return;
|
|
22718
22771
|
if (!newStats || newStats.mtimeMs === 0) {
|
|
22719
22772
|
try {
|
|
22720
|
-
const newStats = await
|
|
22773
|
+
const newStats = await stat10(file);
|
|
22721
22774
|
if (this.fsw.closed)
|
|
22722
22775
|
return;
|
|
22723
22776
|
const at = newStats.atimeMs;
|
|
@@ -23073,7 +23126,7 @@ var init_handler = __esm(() => {
|
|
|
23073
23126
|
ERROR: "error"
|
|
23074
23127
|
};
|
|
23075
23128
|
EV = EVENTS;
|
|
23076
|
-
statMethods = { lstat:
|
|
23129
|
+
statMethods = { lstat: lstat30, stat: stat10 };
|
|
23077
23130
|
HANDLER_KEYS = [KEY_LISTENERS, KEY_ERR, KEY_RAW];
|
|
23078
23131
|
binaryExtensions = new Set([
|
|
23079
23132
|
"3dm",
|
|
@@ -23345,7 +23398,7 @@ var init_handler = __esm(() => {
|
|
|
23345
23398
|
// ../../node_modules/.bun/chokidar@5.0.0/node_modules/chokidar/index.js
|
|
23346
23399
|
import { EventEmitter as EventEmitter2 } from "node:events";
|
|
23347
23400
|
import { stat as statcb, Stats } from "node:fs";
|
|
23348
|
-
import { readdir as
|
|
23401
|
+
import { readdir as readdir20, stat as stat11 } from "node:fs/promises";
|
|
23349
23402
|
import * as sp2 from "node:path";
|
|
23350
23403
|
function arrify(item) {
|
|
23351
23404
|
return Array.isArray(item) ? item : [item];
|
|
@@ -23435,7 +23488,7 @@ class DirEntry {
|
|
|
23435
23488
|
return;
|
|
23436
23489
|
const dir = this.path;
|
|
23437
23490
|
try {
|
|
23438
|
-
await
|
|
23491
|
+
await readdir20(dir);
|
|
23439
23492
|
} catch (err) {
|
|
23440
23493
|
if (this._removeWatcher) {
|
|
23441
23494
|
this._removeWatcher(sp2.dirname(dir), sp2.basename(dir));
|
|
@@ -23799,7 +23852,7 @@ var init_chokidar = __esm(() => {
|
|
|
23799
23852
|
const fullPath = opts.cwd ? sp2.join(opts.cwd, path) : path;
|
|
23800
23853
|
let stats;
|
|
23801
23854
|
try {
|
|
23802
|
-
stats = await
|
|
23855
|
+
stats = await stat11(fullPath);
|
|
23803
23856
|
} catch (err) {}
|
|
23804
23857
|
if (!stats || this.closed)
|
|
23805
23858
|
return;
|
|
@@ -24368,8 +24421,8 @@ function canonicalConfig(config) {
|
|
|
24368
24421
|
// src/agent-provisioning.ts
|
|
24369
24422
|
import { spawn as spawn12 } from "node:child_process";
|
|
24370
24423
|
import { mkdtempSync, rmSync as rmSync2 } from "node:fs";
|
|
24371
|
-
import { homedir as
|
|
24372
|
-
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";
|
|
24373
24426
|
function runTerminalCommand(request, spawnCommand = spawn12) {
|
|
24374
24427
|
return new Promise((resolve) => {
|
|
24375
24428
|
let child;
|
|
@@ -24412,13 +24465,13 @@ function runTerminalCommand(request, spawnCommand = spawn12) {
|
|
|
24412
24465
|
function defaults2() {
|
|
24413
24466
|
return {
|
|
24414
24467
|
platform: process.platform,
|
|
24415
|
-
home:
|
|
24468
|
+
home: homedir11(),
|
|
24416
24469
|
env: process.env,
|
|
24417
24470
|
resolveBinary: resolveBinaryPath,
|
|
24418
24471
|
discover: discoverAgents,
|
|
24419
24472
|
runCommand: runTerminalCommand,
|
|
24420
24473
|
supportsLoginCommand: (agent, path, env) => supportsNativeLoginCommand(agent, path, { env }),
|
|
24421
|
-
makeTempDir: () => mkdtempSync(
|
|
24474
|
+
makeTempDir: () => mkdtempSync(join70(tmpdir4(), "av-agent-install-")),
|
|
24422
24475
|
removeTempDir: (path) => rmSync2(path, { recursive: true, force: true })
|
|
24423
24476
|
};
|
|
24424
24477
|
}
|
|
@@ -24445,7 +24498,7 @@ async function runOfficialInstaller(installerUrl, deps, options = {}) {
|
|
|
24445
24498
|
let directory;
|
|
24446
24499
|
try {
|
|
24447
24500
|
directory = deps.makeTempDir();
|
|
24448
|
-
const scriptPath =
|
|
24501
|
+
const scriptPath = join70(directory, "install.sh");
|
|
24449
24502
|
const request = { env: options.env ?? deps.env, ...options.cwd ? { cwd: options.cwd } : {} };
|
|
24450
24503
|
const download = await deps.runCommand({
|
|
24451
24504
|
command: curl,
|
|
@@ -24516,10 +24569,10 @@ async function installChiefAgent(agent, overrides = {}) {
|
|
|
24516
24569
|
const install = await runOfficialInstaller(plan.installerUrl, deps);
|
|
24517
24570
|
if (!install.success)
|
|
24518
24571
|
return commandFailure(install.stage === "download" ? "Installer download" : "Installation", install, plan.documentation);
|
|
24519
|
-
const localBin =
|
|
24520
|
-
const pathParts = (deps.env.PATH ?? "").split(
|
|
24572
|
+
const localBin = join70(deps.home, ".local", "bin");
|
|
24573
|
+
const pathParts = (deps.env.PATH ?? "").split(delimiter4);
|
|
24521
24574
|
if (!pathParts.includes(localBin))
|
|
24522
|
-
deps.env.PATH = [localBin, ...pathParts.filter(Boolean)].join(
|
|
24575
|
+
deps.env.PATH = [localBin, ...pathParts.filter(Boolean)].join(delimiter4);
|
|
24523
24576
|
return { success: true, message: "Installation finished; checking the CLI next." };
|
|
24524
24577
|
} catch {
|
|
24525
24578
|
return { success: false, message: `Installation did not complete. Retry or follow ${plan.documentation}.` };
|
|
@@ -24617,31 +24670,31 @@ var init_agent_provisioning = __esm(() => {
|
|
|
24617
24670
|
|
|
24618
24671
|
// src/oma-provisioning.ts
|
|
24619
24672
|
import { mkdtempSync as mkdtempSync2, rmSync as rmSync3 } from "node:fs";
|
|
24620
|
-
import { chmod as chmod5, lstat as
|
|
24621
|
-
import { homedir as
|
|
24622
|
-
import { delimiter as
|
|
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";
|
|
24623
24676
|
function defaults3() {
|
|
24624
|
-
const home =
|
|
24677
|
+
const home = homedir12();
|
|
24625
24678
|
return {
|
|
24626
24679
|
platform: process.platform,
|
|
24627
24680
|
home,
|
|
24628
24681
|
env: process.env,
|
|
24629
|
-
resolveBinary: (name) => resolveBinaryPath(name, name === "bun" ? [
|
|
24682
|
+
resolveBinary: (name) => resolveBinaryPath(name, name === "bun" ? [join71(process.env.BUN_INSTALL ?? join71(home, ".bun"), "bin", "bun")] : []),
|
|
24630
24683
|
runCommand: runTerminalCommand,
|
|
24631
|
-
makeTempDir: () => mkdtempSync2(
|
|
24684
|
+
makeTempDir: () => mkdtempSync2(join71(tmpdir5(), "av-oma-install-")),
|
|
24632
24685
|
removeTempDir: (path) => rmSync3(path, { recursive: true, force: true })
|
|
24633
24686
|
};
|
|
24634
24687
|
}
|
|
24635
24688
|
async function directory2(path) {
|
|
24636
24689
|
try {
|
|
24637
|
-
return (await
|
|
24690
|
+
return (await lstat31(path)).isDirectory();
|
|
24638
24691
|
} catch {
|
|
24639
24692
|
return false;
|
|
24640
24693
|
}
|
|
24641
24694
|
}
|
|
24642
24695
|
async function present(path) {
|
|
24643
24696
|
try {
|
|
24644
|
-
await
|
|
24697
|
+
await lstat31(path);
|
|
24645
24698
|
return true;
|
|
24646
24699
|
} catch {
|
|
24647
24700
|
return false;
|
|
@@ -24649,7 +24702,7 @@ async function present(path) {
|
|
|
24649
24702
|
}
|
|
24650
24703
|
async function installedVersion2(skills) {
|
|
24651
24704
|
try {
|
|
24652
|
-
const marker = JSON.parse(await
|
|
24705
|
+
const marker = JSON.parse(await readFile24(join71(skills, "_version.json"), "utf8"));
|
|
24653
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;
|
|
24654
24707
|
} catch {
|
|
24655
24708
|
return null;
|
|
@@ -24658,13 +24711,13 @@ async function installedVersion2(skills) {
|
|
|
24658
24711
|
async function snapshotConfig(agents) {
|
|
24659
24712
|
const snapshots = [];
|
|
24660
24713
|
for (const name of CUSTOM_CONFIG_NAMES) {
|
|
24661
|
-
const path =
|
|
24714
|
+
const path = join71(agents, name);
|
|
24662
24715
|
if (!await present(path))
|
|
24663
24716
|
continue;
|
|
24664
|
-
const file = await
|
|
24717
|
+
const file = await lstat31(path);
|
|
24665
24718
|
if (!file.isFile())
|
|
24666
24719
|
throw new Error("Custom configuration must be a project-local regular file.");
|
|
24667
|
-
snapshots.push({ path, bytes: await
|
|
24720
|
+
snapshots.push({ path, bytes: await readFile24(path), mode: file.mode & 511 });
|
|
24668
24721
|
}
|
|
24669
24722
|
return snapshots;
|
|
24670
24723
|
}
|
|
@@ -24678,10 +24731,10 @@ async function restoreConfig(agents, snapshots) {
|
|
|
24678
24731
|
["oma-config.yaml", "oma-config.cue"],
|
|
24679
24732
|
["oma-config.local.yaml", "oma-config.local.cue"]
|
|
24680
24733
|
]) {
|
|
24681
|
-
if (!pair.some((name) => original.has(
|
|
24734
|
+
if (!pair.some((name) => original.has(join71(agents, name))))
|
|
24682
24735
|
continue;
|
|
24683
24736
|
for (const name of pair) {
|
|
24684
|
-
const path =
|
|
24737
|
+
const path = join71(agents, name);
|
|
24685
24738
|
if (!original.has(path))
|
|
24686
24739
|
await unlink7(path).catch((error) => {
|
|
24687
24740
|
if (error.code !== "ENOENT")
|
|
@@ -24691,17 +24744,17 @@ async function restoreConfig(agents, snapshots) {
|
|
|
24691
24744
|
}
|
|
24692
24745
|
}
|
|
24693
24746
|
async function workspacePath(input) {
|
|
24694
|
-
if (!input.trim() || !
|
|
24747
|
+
if (!input.trim() || !isAbsolute23(input))
|
|
24695
24748
|
return null;
|
|
24696
24749
|
const root = resolve44(input);
|
|
24697
24750
|
if (!await directory2(root))
|
|
24698
24751
|
return null;
|
|
24699
|
-
for (const path of [
|
|
24752
|
+
for (const path of [join71(root, ".agents"), join71(root, ".agents", "skills")]) {
|
|
24700
24753
|
if (!await present(path))
|
|
24701
24754
|
continue;
|
|
24702
24755
|
const actual = await realpath39(path);
|
|
24703
24756
|
const location2 = relative22(await realpath39(root), actual);
|
|
24704
|
-
if (location2 === ".." || location2.startsWith(`..${process.platform === "win32" ? "\\" : "/"}`) ||
|
|
24757
|
+
if (location2 === ".." || location2.startsWith(`..${process.platform === "win32" ? "\\" : "/"}`) || isAbsolute23(location2))
|
|
24705
24758
|
return null;
|
|
24706
24759
|
}
|
|
24707
24760
|
return root;
|
|
@@ -24711,15 +24764,15 @@ async function inspectOma(workspaceRoot, _overrides = {}) {
|
|
|
24711
24764
|
const root = await workspacePath(workspaceRoot);
|
|
24712
24765
|
if (!root)
|
|
24713
24766
|
return { success: false, message: "Choose an existing absolute workspace with project-local OMA files." };
|
|
24714
|
-
const skills =
|
|
24767
|
+
const skills = join71(root, ".agents", "skills");
|
|
24715
24768
|
const version = await installedVersion2(skills);
|
|
24716
24769
|
if (!version)
|
|
24717
24770
|
throw new Error("Invalid installed metadata");
|
|
24718
|
-
const entries = (await
|
|
24771
|
+
const entries = (await readdir21(skills, { withFileTypes: true })).filter((entry) => /^oma-[a-z0-9-]+$/.test(entry.name));
|
|
24719
24772
|
if (!entries.length)
|
|
24720
24773
|
throw new Error("No installed skills");
|
|
24721
24774
|
for (const entry of entries) {
|
|
24722
|
-
if (!entry.isDirectory() || !(await
|
|
24775
|
+
if (!entry.isDirectory() || !(await lstat31(join71(skills, entry.name, "SKILL.md"))).isFile())
|
|
24723
24776
|
throw new Error("Incomplete installed skill");
|
|
24724
24777
|
}
|
|
24725
24778
|
return {
|
|
@@ -24767,16 +24820,16 @@ async function prepareOma(workspaceRoot, overrides = {}) {
|
|
|
24767
24820
|
delete environment.OMA_YES;
|
|
24768
24821
|
environment.CI = "true";
|
|
24769
24822
|
const paths = [
|
|
24770
|
-
deps.env.BUN_INSTALL_BIN ??
|
|
24771
|
-
|
|
24823
|
+
deps.env.BUN_INSTALL_BIN ?? join71(deps.env.BUN_INSTALL ?? join71(deps.home, ".bun"), "bin"),
|
|
24824
|
+
join71(deps.home, ".local", "bin")
|
|
24772
24825
|
];
|
|
24773
|
-
environment.PATH = [...new Set([...paths, ...(environment.PATH ?? "").split(
|
|
24826
|
+
environment.PATH = [...new Set([...paths, ...(environment.PATH ?? "").split(delimiter5).filter(Boolean)])].join(delimiter5);
|
|
24774
24827
|
const request = { command: bun, env: environment, cwd: root, timeoutMs: 300000 };
|
|
24775
24828
|
const latest = await deps.runCommand({ ...request, args: ["install", "--global", LATEST_PACKAGE] });
|
|
24776
24829
|
if (!latest.success)
|
|
24777
24830
|
return failure4("OMA CLI update", latest);
|
|
24778
|
-
const agents =
|
|
24779
|
-
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")));
|
|
24780
24833
|
const custom = await snapshotConfig(agents);
|
|
24781
24834
|
const args = existing ? ["update", "--yes", "--with-new-skills", "--all"] : ["install"];
|
|
24782
24835
|
let installed;
|
|
@@ -26263,9 +26316,9 @@ var init_ui = __esm(() => {
|
|
|
26263
26316
|
|
|
26264
26317
|
// src/setup/workspace-step.ts
|
|
26265
26318
|
import { statSync as statSync6 } from "node:fs";
|
|
26266
|
-
import { isAbsolute as
|
|
26319
|
+
import { isAbsolute as isAbsolute24 } from "node:path";
|
|
26267
26320
|
async function validateOrderWorkspace(path) {
|
|
26268
|
-
if (!
|
|
26321
|
+
if (!isAbsolute24(path))
|
|
26269
26322
|
return "Set workspace.root in av.yaml to an absolute Git repository path.";
|
|
26270
26323
|
try {
|
|
26271
26324
|
if (!statSync6(path).isDirectory())
|
|
@@ -26292,7 +26345,7 @@ async function stepWorkspace(ctx, step, total) {
|
|
|
26292
26345
|
validate: (v) => {
|
|
26293
26346
|
if (!v?.trim())
|
|
26294
26347
|
return "Required";
|
|
26295
|
-
if (!
|
|
26348
|
+
if (!isAbsolute24(v.trim()))
|
|
26296
26349
|
return "Must be an absolute path";
|
|
26297
26350
|
}
|
|
26298
26351
|
});
|
|
@@ -26318,8 +26371,8 @@ var init_workspace_step = __esm(() => {
|
|
|
26318
26371
|
});
|
|
26319
26372
|
|
|
26320
26373
|
// src/setup/noninteractive-config.ts
|
|
26321
|
-
import { lstat as
|
|
26322
|
-
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";
|
|
26323
26376
|
function validateNoninteractiveOptions(options) {
|
|
26324
26377
|
if (!options.yes || options.edit || options.mode !== undefined && options.mode !== "order")
|
|
26325
26378
|
throw new Error("Use av setup --yes only for local order setup; --edit and --mode tracker require interactive setup.");
|
|
@@ -26363,7 +26416,7 @@ function selectChief(options, deps, project, global2) {
|
|
|
26363
26416
|
const globalActor = actor(global2);
|
|
26364
26417
|
const selected = options.actor ?? runtime?.actorType ?? projectActor.type ?? globalActor.type;
|
|
26365
26418
|
if (!selected)
|
|
26366
|
-
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>.`);
|
|
26367
26420
|
const actorType = selected;
|
|
26368
26421
|
const actorSource = options.actor !== undefined ? "explicit" : runtime ? "runtime" : projectActor.type ? "project" : "global";
|
|
26369
26422
|
const previousType = projectActor.type ?? globalActor.type;
|
|
@@ -26402,13 +26455,13 @@ async function prepareNoninteractiveConfig(options, deps) {
|
|
|
26402
26455
|
let projectRoot;
|
|
26403
26456
|
try {
|
|
26404
26457
|
projectRoot = await realpath40(resolve45(deps.projectRoot));
|
|
26405
|
-
if (!(await
|
|
26458
|
+
if (!(await lstat32(projectRoot)).isDirectory())
|
|
26406
26459
|
throw new Error("not a directory");
|
|
26407
26460
|
} catch {
|
|
26408
26461
|
throw new Error(`AV configuration directory ${deps.projectRoot} does not exist. Run av setup from an existing directory.`);
|
|
26409
26462
|
}
|
|
26410
26463
|
const globalPath = resolve45(deps.globalConfigPath);
|
|
26411
|
-
const projectPath =
|
|
26464
|
+
const projectPath = join72(projectRoot, "av.yaml");
|
|
26412
26465
|
const project = await configFile(projectPath, projectConfigSchema);
|
|
26413
26466
|
const global2 = await configFile(globalPath, globalConfigSchema);
|
|
26414
26467
|
const chief = selectChief(options, { ...deps, projectRoot, globalConfigPath: globalPath }, project.raw, global2.raw);
|
|
@@ -26425,7 +26478,7 @@ async function prepareNoninteractiveConfig(options, deps) {
|
|
|
26425
26478
|
}
|
|
26426
26479
|
const savedWorkspace = project.raw.workspace?.root;
|
|
26427
26480
|
const selectedWorkspace = options.workspace ?? savedWorkspace ?? projectRoot;
|
|
26428
|
-
const workspacePath =
|
|
26481
|
+
const workspacePath = isAbsolute25(selectedWorkspace) ? selectedWorkspace : resolve45(projectRoot, selectedWorkspace);
|
|
26429
26482
|
const workspaceError = await validateOrderWorkspace(workspacePath);
|
|
26430
26483
|
if (workspaceError)
|
|
26431
26484
|
throw new Error(workspaceError);
|
|
@@ -26472,7 +26525,7 @@ var init_noninteractive_config = __esm(() => {
|
|
|
26472
26525
|
});
|
|
26473
26526
|
|
|
26474
26527
|
// src/setup/noninteractive.ts
|
|
26475
|
-
import { join as
|
|
26528
|
+
import { join as join73, parse as parsePath2, resolve as resolve46 } from "node:path";
|
|
26476
26529
|
function rerunCommand(result, options) {
|
|
26477
26530
|
const quote = (value) => `'${value.replace(/'/g, "'\\''")}'`;
|
|
26478
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`;
|
|
@@ -26486,7 +26539,7 @@ async function setupNoninteractive(options, overrides = {}) {
|
|
|
26486
26539
|
projectRoot: resolve46(deps.projectRoot),
|
|
26487
26540
|
workspace: null,
|
|
26488
26541
|
config: {
|
|
26489
|
-
project:
|
|
26542
|
+
project: join73(resolve46(deps.projectRoot), "av.yaml"),
|
|
26490
26543
|
global: resolve46(deps.globalConfigPath),
|
|
26491
26544
|
saved: false
|
|
26492
26545
|
},
|
|
@@ -26973,7 +27026,7 @@ var init_container_step = __esm(() => {
|
|
|
26973
27026
|
});
|
|
26974
27027
|
|
|
26975
27028
|
// src/setup/metric-step.ts
|
|
26976
|
-
import { isAbsolute as
|
|
27029
|
+
import { isAbsolute as isAbsolute26 } from "node:path";
|
|
26977
27030
|
async function text13(message, initialValue, validate) {
|
|
26978
27031
|
const value = await text11({
|
|
26979
27032
|
message: `${message} (:back goes back)`,
|
|
@@ -27057,7 +27110,7 @@ async function stepMetrics(ctx) {
|
|
|
27057
27110
|
draft.token_env = token;
|
|
27058
27111
|
} else {
|
|
27059
27112
|
const file = await text13("Repository-relative JSON file", old?.file ?? "metrics/revenue.json", (value) => {
|
|
27060
|
-
if (!value || value.length > 2000 ||
|
|
27113
|
+
if (!value || value.length > 2000 || isAbsolute26(value) || /^[A-Za-z]:/.test(value) || value.startsWith("\\") || value.split(/[\\/]/).includes(".."))
|
|
27061
27114
|
return "Use a relative file inside the repository, without ..";
|
|
27062
27115
|
});
|
|
27063
27116
|
if (navigated2(file))
|
|
@@ -28946,10 +28999,10 @@ var init_setup = __esm(() => {
|
|
|
28946
28999
|
|
|
28947
29000
|
// ../../packages/core/src/relay/credentials.ts
|
|
28948
29001
|
import { readFileSync as readFileSync14 } from "node:fs";
|
|
28949
|
-
import { homedir as
|
|
28950
|
-
import { join as
|
|
29002
|
+
import { homedir as homedir13 } from "node:os";
|
|
29003
|
+
import { join as join74 } from "node:path";
|
|
28951
29004
|
function defaultCredentialsPath() {
|
|
28952
|
-
return
|
|
29005
|
+
return join74(homedir13(), ".agent-valley", "credentials.json");
|
|
28953
29006
|
}
|
|
28954
29007
|
function validateRelayCredentials(value, binding, now = Date.now()) {
|
|
28955
29008
|
const result = credentialsSchema.safeParse(value);
|
|
@@ -53231,8 +53284,8 @@ async function startAvMcpHttp(api, options) {
|
|
|
53231
53284
|
|
|
53232
53285
|
// src/mission-api.ts
|
|
53233
53286
|
import { randomUUID as randomUUID22 } from "node:crypto";
|
|
53234
|
-
import { lstat as
|
|
53235
|
-
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";
|
|
53236
53289
|
|
|
53237
53290
|
// ../../packages/core/src/chief/reports.ts
|
|
53238
53291
|
init_zod();
|
|
@@ -54148,7 +54201,103 @@ async function cargoVerificationInputs(root, budget) {
|
|
|
54148
54201
|
// ../../packages/core/src/chief/verification-command.ts
|
|
54149
54202
|
import { spawn as spawn5 } from "node:child_process";
|
|
54150
54203
|
import { realpath as realpath12 } from "node:fs/promises";
|
|
54151
|
-
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
|
|
54152
54301
|
var MAX_VERIFICATION_OUTPUT_BYTES = 1048576;
|
|
54153
54302
|
async function joinVerificationGroup(pid, detached) {
|
|
54154
54303
|
if (!pid || !detached)
|
|
@@ -54183,8 +54332,8 @@ async function verificationCommandInputs(root, program, args, budget) {
|
|
|
54183
54332
|
return cargoVerificationInputs(root, budget);
|
|
54184
54333
|
const names = verificationCommandTestPaths(program, args);
|
|
54185
54334
|
if (program === "node" && args[0] === "node_modules/vitest/vitest.mjs") {
|
|
54186
|
-
const launcher = await realpath12(
|
|
54187
|
-
if (!launcher.startsWith(`${
|
|
54335
|
+
const launcher = await realpath12(join18(root, args[0]));
|
|
54336
|
+
if (!launcher.startsWith(`${join18(root, "node_modules")}${sep8}`))
|
|
54188
54337
|
throw new Error("Installed Vitest launcher escapes this worktree. Install its dependency inside node_modules.");
|
|
54189
54338
|
names.unshift(relative8(root, launcher));
|
|
54190
54339
|
}
|
|
@@ -54195,94 +54344,102 @@ async function verificationCommandInputs(root, program, args, budget) {
|
|
|
54195
54344
|
}
|
|
54196
54345
|
return inputs;
|
|
54197
54346
|
}
|
|
54198
|
-
var executeVerificationCommand = (program, args, options) =>
|
|
54199
|
-
if (!safeVerificationCommand(program, args))
|
|
54200
|
-
|
|
54201
|
-
|
|
54202
|
-
|
|
54203
|
-
|
|
54204
|
-
|
|
54205
|
-
|
|
54206
|
-
|
|
54207
|
-
|
|
54208
|
-
|
|
54209
|
-
for (const key of [
|
|
54210
|
-
"GIT_DIR",
|
|
54211
|
-
"GIT_WORK_TREE",
|
|
54212
|
-
"GIT_COMMON_DIR",
|
|
54213
|
-
"GIT_INDEX_FILE",
|
|
54214
|
-
"GIT_OBJECT_DIRECTORY",
|
|
54215
|
-
"GIT_ALTERNATE_OBJECT_DIRECTORIES"
|
|
54216
|
-
])
|
|
54217
|
-
delete env[key];
|
|
54218
|
-
Object.assign(env, { GIT_OPTIONAL_LOCKS: "0", GIT_NO_LAZY_FETCH: "1", GIT_LITERAL_PATHSPECS: "1" });
|
|
54219
|
-
if (program === "cargo")
|
|
54220
|
-
Object.assign(env, { CARGO_NET_OFFLINE: "true", CARGO_TERM_COLOR: "never" });
|
|
54221
|
-
const argv = program === "git" ? ["-c", "core.fsmonitor=false", "-c", "diff.external=", "-c", "core.pager=cat", "--no-pager", ...args] : args;
|
|
54222
|
-
const child = spawn5(program, argv, {
|
|
54223
|
-
cwd: options.cwd,
|
|
54224
|
-
detached,
|
|
54225
|
-
shell: false,
|
|
54226
|
-
stdio: ["ignore", "pipe", "pipe"],
|
|
54227
|
-
env
|
|
54228
|
-
});
|
|
54229
|
-
let stdout = "";
|
|
54230
|
-
let stderr = "";
|
|
54231
|
-
let bytes = 0;
|
|
54232
|
-
let failure;
|
|
54233
|
-
const stop = (error) => {
|
|
54234
|
-
failure ??= error;
|
|
54235
|
-
if (detached && child.pid) {
|
|
54236
|
-
try {
|
|
54237
|
-
process.kill(-child.pid, "SIGKILL");
|
|
54238
|
-
return;
|
|
54239
|
-
} catch {}
|
|
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;
|
|
54240
54358
|
}
|
|
54241
|
-
|
|
54242
|
-
|
|
54243
|
-
|
|
54244
|
-
const timer = setTimeout(() => stop(new Error("Verification timed out. Repair the test or increase its bounded timeout.")), options.timeoutMs);
|
|
54245
|
-
timer.unref();
|
|
54246
|
-
const capture = (chunk, stream) => {
|
|
54247
|
-
bytes += chunk.length;
|
|
54248
|
-
if (bytes > options.maxOutputBytes) {
|
|
54249
|
-
stop(new Error("Verification output exceeds its evidence budget. Reduce noisy test output and retry."));
|
|
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."));
|
|
54250
54362
|
return;
|
|
54251
54363
|
}
|
|
54252
|
-
|
|
54253
|
-
|
|
54254
|
-
|
|
54255
|
-
|
|
54256
|
-
|
|
54257
|
-
|
|
54258
|
-
|
|
54259
|
-
|
|
54260
|
-
|
|
54261
|
-
|
|
54262
|
-
|
|
54263
|
-
|
|
54264
|
-
|
|
54265
|
-
|
|
54266
|
-
|
|
54267
|
-
|
|
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
|
+
}
|
|
54268
54440
|
}
|
|
54269
|
-
options.signal?.removeEventListener("abort", abort);
|
|
54270
|
-
if (failure)
|
|
54271
|
-
rejectCommand(failure);
|
|
54272
|
-
else
|
|
54273
|
-
resolveCommand({ exitCode, stdout, stderr });
|
|
54274
54441
|
});
|
|
54275
|
-
|
|
54276
|
-
if (options.signal?.aborted)
|
|
54277
|
-
abort();
|
|
54278
|
-
if (child.pid && options.onSpawned) {
|
|
54279
|
-
try {
|
|
54280
|
-
options.onSpawned(child.pid, detached);
|
|
54281
|
-
} catch (error) {
|
|
54282
|
-
stop(error instanceof Error ? error : new Error("Cannot register automatic verification process."));
|
|
54283
|
-
}
|
|
54284
|
-
}
|
|
54285
|
-
});
|
|
54442
|
+
};
|
|
54286
54443
|
|
|
54287
54444
|
// ../../packages/core/src/chief/verification.ts
|
|
54288
54445
|
var digest4 = string2().regex(/^[a-f0-9]{64}$/);
|
|
@@ -54476,6 +54633,150 @@ function validateFinalReview(review, mission) {
|
|
|
54476
54633
|
return review;
|
|
54477
54634
|
}
|
|
54478
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
|
+
|
|
54479
54780
|
// ../../packages/core/src/chief/bounded-work-routing.ts
|
|
54480
54781
|
import { createHash as createHash13 } from "node:crypto";
|
|
54481
54782
|
function repairDecision(mission, taskId, taskRuns) {
|
|
@@ -54569,7 +54870,7 @@ function routeEvidence(mission) {
|
|
|
54569
54870
|
totalCostUsd: 0,
|
|
54570
54871
|
successfulDeliverableCostUsd: null
|
|
54571
54872
|
};
|
|
54572
|
-
if (!cancelled.has(run.runId))
|
|
54873
|
+
if (!cancelled.has(run.runId) && run.nativeOutcome !== "cancelled")
|
|
54573
54874
|
item.samples += 1;
|
|
54574
54875
|
if (run.outcome === "passed")
|
|
54575
54876
|
item.successes += 1;
|
|
@@ -54577,6 +54878,19 @@ function routeEvidence(mission) {
|
|
|
54577
54878
|
item.successfulDeliverableCostUsd = item.successes && item.totalCostUsd !== null ? item.totalCostUsd / item.successes : null;
|
|
54578
54879
|
evidence.set(key, item);
|
|
54579
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
|
+
}
|
|
54580
54894
|
return [...evidence.values()];
|
|
54581
54895
|
}
|
|
54582
54896
|
function price2(candidate) {
|
|
@@ -54606,14 +54920,16 @@ function selectWorkActor(mission, actor, taskId, compatibleRoutes) {
|
|
|
54606
54920
|
if (!routing || actor.id === mission.chiefId || !mission.availableAgents && (actor.model || compatibleRoutes)) {
|
|
54607
54921
|
if (compatibleRoutes && !compatibleRoutes.has(routeKey({ actorType: actor.agentType, model: actor.model })))
|
|
54608
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 }]);
|
|
54609
54924
|
return { actor, reason: "Preserved the configured Actor and explicit model." };
|
|
54610
54925
|
}
|
|
54611
54926
|
const candidates = readyWorkCandidates(mission);
|
|
54612
54927
|
if (!candidates.length)
|
|
54613
54928
|
throw new Error("No configured work routing candidate is ready. Install/login a candidate CLI or update chief.routing.candidates in av.yaml.");
|
|
54614
|
-
const
|
|
54615
|
-
if (!
|
|
54929
|
+
const compatiblePool = compatibleRoutes ? candidates.filter((candidate) => compatibleRoutes.has(routeKey(candidate))) : candidates;
|
|
54930
|
+
if (!compatiblePool.length)
|
|
54616
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);
|
|
54617
54933
|
const evidence = routeEvidence(mission);
|
|
54618
54934
|
const eligible = compatible.filter((candidate) => {
|
|
54619
54935
|
const observed = evidence.find((item) => routeKey(item) === routeKey(candidate));
|
|
@@ -54623,7 +54939,7 @@ function selectWorkActor(mission, actor, taskId, compatibleRoutes) {
|
|
|
54623
54939
|
const measured = qualified.at(0);
|
|
54624
54940
|
const initial = measured?.candidate ?? [...eligible].sort((a, b) => price2(a) - price2(b)).at(0);
|
|
54625
54941
|
const cancelled = cancelledWorkRunProofs(mission);
|
|
54626
|
-
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");
|
|
54627
54943
|
if (hasUnreviewedRoutingProbe(mission, taskId, taskRuns))
|
|
54628
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.");
|
|
54629
54945
|
const failed = new Set;
|
|
@@ -54715,6 +55031,10 @@ function operationsReportLines(mission) {
|
|
|
54715
55031
|
...evidence.metricAssessments.map((metric) => `${metric.criterion}: ${metric.passed ? "기록된 측정값 기준 통과" : "미충족"}; ${metric.evidence}`),
|
|
54716
55032
|
"비용은 실제 청구액이 아닙니다. 미보고 cache·reasoning·하위 agent token 및 구독 요금은 포함하지 않습니다.",
|
|
54717
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
|
+
}),
|
|
54718
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"}`),
|
|
54719
55039
|
...evidence.crossVendorReviews.map((review) => `${review.taskId}${review.gateId ? ` [${review.gateId}]` : ""}: 작업 ${review.workerActorType} → 리뷰 ${review.reviewerActorType}, ${review.crossVendor ? "다른 vendor" : "동일 vendor fallback"}, 결과 ${review.outcome ?? "배정만 기록"}; ${review.reason}`),
|
|
54720
55040
|
...mission.organizationContext ? [
|
|
@@ -55104,9 +55424,9 @@ function renderReport(mission) {
|
|
|
55104
55424
|
|
|
55105
55425
|
// ../../packages/core/src/chief/store.ts
|
|
55106
55426
|
init_atomic_json();
|
|
55107
|
-
import { constants as
|
|
55108
|
-
import { mkdir as mkdir11, open as open11, readdir as
|
|
55109
|
-
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";
|
|
55110
55430
|
init_execution();
|
|
55111
55431
|
|
|
55112
55432
|
// ../../packages/core/src/domain/dag.ts
|
|
@@ -55304,17 +55624,17 @@ function parseSupervisionResponse(source, mission) {
|
|
|
55304
55624
|
init_mission_state_schema();
|
|
55305
55625
|
init_mission_state_schema();
|
|
55306
55626
|
init_zod();
|
|
55307
|
-
import { isAbsolute as
|
|
55627
|
+
import { isAbsolute as isAbsolute11 } from "node:path";
|
|
55308
55628
|
|
|
55309
55629
|
// ../../packages/core/src/chief/capture.ts
|
|
55310
55630
|
import { spawn as spawn7 } from "node:child_process";
|
|
55311
55631
|
import { createHash as createHash14, randomUUID as randomUUID11 } from "node:crypto";
|
|
55312
|
-
import { chmod as chmod4, mkdir as mkdir9, readFile as
|
|
55313
|
-
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";
|
|
55314
55634
|
|
|
55315
55635
|
// ../../packages/core/src/chief/capture-mcp.ts
|
|
55316
|
-
import { readFile as
|
|
55317
|
-
import { join as
|
|
55636
|
+
import { readFile as readFile7 } from "node:fs/promises";
|
|
55637
|
+
import { join as join19 } from "node:path";
|
|
55318
55638
|
|
|
55319
55639
|
// ../../node_modules/.bun/@modelcontextprotocol+client@2.3.0/node_modules/@modelcontextprotocol/client/dist/chunk-Br0eD_fh.mjs
|
|
55320
55640
|
var __create3 = Object.create;
|
|
@@ -69681,7 +70001,7 @@ console.log(${JSON.stringify(prefix)} + JSON.stringify({base64: bytes.toString("
|
|
|
69681
70001
|
async function connectAsideBrowser(repository, policy) {
|
|
69682
70002
|
let config = { command: "aside", args: ["mcp"] };
|
|
69683
70003
|
try {
|
|
69684
|
-
const raw = JSON.parse(await
|
|
70004
|
+
const raw = JSON.parse(await readFile7(join19(repository, ".mcp.json"), "utf8"));
|
|
69685
70005
|
if (raw.mcpServers?.aside)
|
|
69686
70006
|
config = serverSchema.parse(raw.mcpServers.aside);
|
|
69687
70007
|
} catch (error) {
|
|
@@ -69782,7 +70102,7 @@ class MissionCapture {
|
|
|
69782
70102
|
capturePolicySchema.parse(policy);
|
|
69783
70103
|
if (!/^[a-zA-Z0-9][a-zA-Z0-9_-]{0,127}$/.test(missionId))
|
|
69784
70104
|
throw new Error("Use a safe mission ID for capture artifacts.");
|
|
69785
|
-
this.directory =
|
|
70105
|
+
this.directory = join20(repository, ".agent-valley/captures", missionId, randomUUID11());
|
|
69786
70106
|
this.deps = { connect: connectAsideBrowser, encode: encodeCaptureVideo, now: () => new Date, ...deps };
|
|
69787
70107
|
this.startedAt = this.deps.now().toISOString();
|
|
69788
70108
|
}
|
|
@@ -69817,10 +70137,10 @@ class MissionCapture {
|
|
|
69817
70137
|
}, this.policy.intervalMs);
|
|
69818
70138
|
}
|
|
69819
70139
|
async attachment(name, mimeType, bytes) {
|
|
69820
|
-
const path =
|
|
70140
|
+
const path = join20(this.directory, name);
|
|
69821
70141
|
if (bytes)
|
|
69822
70142
|
await writeFile4(path, bytes, { mode: 384 });
|
|
69823
|
-
const contents = bytes ?? await
|
|
70143
|
+
const contents = bytes ?? await readFile8(path);
|
|
69824
70144
|
if (!contents.length || contents.length > 200 * 1024 * 1024)
|
|
69825
70145
|
throw new Error("Capture artifact must contain bytes and be at most 200 MB.");
|
|
69826
70146
|
return {
|
|
@@ -69884,8 +70204,8 @@ duration ${duration}`;
|
|
|
69884
70204
|
`)}
|
|
69885
70205
|
file '${this.frames.at(-1)?.attachment.name}'
|
|
69886
70206
|
`;
|
|
69887
|
-
const manifestPath =
|
|
69888
|
-
const output =
|
|
70207
|
+
const manifestPath = join20(this.directory, "frames.txt");
|
|
70208
|
+
const output = join20(this.directory, "recording.mp4");
|
|
69889
70209
|
await writeFile4(manifestPath, concat, { mode: 384 });
|
|
69890
70210
|
await this.deps.encode(this.directory, manifestPath, output);
|
|
69891
70211
|
await chmod4(output, 384);
|
|
@@ -70168,15 +70488,15 @@ init_metric_source_policy();
|
|
|
70168
70488
|
// ../../packages/core/src/chief/oma-actor.ts
|
|
70169
70489
|
init_dist();
|
|
70170
70490
|
import { createHash as createHash16 } from "node:crypto";
|
|
70171
|
-
import { constants as
|
|
70172
|
-
import { open as open10, readdir as
|
|
70173
|
-
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";
|
|
70174
70494
|
|
|
70175
70495
|
// ../../packages/core/src/chief/skills.ts
|
|
70176
70496
|
init_dist();
|
|
70177
|
-
import { constants as
|
|
70178
|
-
import { lstat as
|
|
70179
|
-
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";
|
|
70180
70500
|
var MAX_SKILL_BYTES = 256000;
|
|
70181
70501
|
var MAX_METADATA_BYTES = 16384;
|
|
70182
70502
|
var MAX_CATALOG_SIZE = 100;
|
|
@@ -70186,7 +70506,7 @@ var SKILL_NAME = /^[a-z0-9][a-z0-9-]{0,127}$/;
|
|
|
70186
70506
|
var OMA_SKILL_NAME = /^oma-[a-z0-9][a-z0-9-]{0,123}$/;
|
|
70187
70507
|
function inside(root, path) {
|
|
70188
70508
|
const child = relative9(root, path);
|
|
70189
|
-
return child !== "" && child !== ".." && !child.startsWith(`..${sep9}`) && !
|
|
70509
|
+
return child !== "" && child !== ".." && !child.startsWith(`..${sep9}`) && !isAbsolute9(child);
|
|
70190
70510
|
}
|
|
70191
70511
|
function excludedResource(name) {
|
|
70192
70512
|
return [
|
|
@@ -70214,7 +70534,7 @@ async function prepareMissionSkills(sourceRepositoryPath, workspacePath) {
|
|
|
70214
70534
|
if (!sources.length)
|
|
70215
70535
|
return;
|
|
70216
70536
|
const workspace = await realpath13(workspacePath);
|
|
70217
|
-
const agents =
|
|
70537
|
+
const agents = join21(workspace, ".agents");
|
|
70218
70538
|
await mkdir10(agents, { recursive: true });
|
|
70219
70539
|
if (!inside(workspace, await realpath13(agents)))
|
|
70220
70540
|
throw new Error("The target .agents directory escapes the mission worktree. Fix its symlink before creating this order.");
|
|
@@ -70225,19 +70545,19 @@ async function prepareMissionSkills(sourceRepositoryPath, workspacePath) {
|
|
|
70225
70545
|
if (seen.has(sourceDirectory))
|
|
70226
70546
|
return;
|
|
70227
70547
|
seen.add(sourceDirectory);
|
|
70228
|
-
for (const name of (await
|
|
70548
|
+
for (const name of (await readdir6(sourceDirectory)).sort()) {
|
|
70229
70549
|
if (excludedResource(name))
|
|
70230
70550
|
continue;
|
|
70231
70551
|
if (++entries > MAX_HARNESS_ENTRIES)
|
|
70232
70552
|
throw new Error("The installed harness resources exceed 5,000 entries. Remove unused resources before creating this order.");
|
|
70233
|
-
const from = await realpath13(
|
|
70553
|
+
const from = await realpath13(join21(sourceDirectory, name)).catch(() => {
|
|
70234
70554
|
return;
|
|
70235
70555
|
});
|
|
70236
70556
|
if (!from || !inside(sourceRoot, from))
|
|
70237
70557
|
continue;
|
|
70238
|
-
const info = await
|
|
70239
|
-
const to =
|
|
70240
|
-
const existing = await
|
|
70558
|
+
const info = await stat3(from);
|
|
70559
|
+
const to = join21(targetDirectory, name);
|
|
70560
|
+
const existing = await lstat11(to).catch(() => {
|
|
70241
70561
|
return;
|
|
70242
70562
|
});
|
|
70243
70563
|
if (info.isDirectory()) {
|
|
@@ -70252,7 +70572,7 @@ async function prepareMissionSkills(sourceRepositoryPath, workspacePath) {
|
|
|
70252
70572
|
const parent = await realpath13(targetDirectory);
|
|
70253
70573
|
if (parent !== destinationRoot && !inside(destinationRoot, parent))
|
|
70254
70574
|
throw new Error("A target harness resource escapes the mission worktree. Fix its symlink before creating this order.");
|
|
70255
|
-
const file = await open9(from,
|
|
70575
|
+
const file = await open9(from, constants8.O_RDONLY | constants8.O_NOFOLLOW | constants8.O_NONBLOCK);
|
|
70256
70576
|
try {
|
|
70257
70577
|
const current = await file.stat();
|
|
70258
70578
|
if (!current.isFile())
|
|
@@ -70284,7 +70604,7 @@ async function prepareMissionSkills(sourceRepositoryPath, workspacePath) {
|
|
|
70284
70604
|
seen.delete(sourceDirectory);
|
|
70285
70605
|
}
|
|
70286
70606
|
for (const source of sources) {
|
|
70287
|
-
await mkdir10(
|
|
70607
|
+
await mkdir10(join21(agents, source.name), { recursive: true });
|
|
70288
70608
|
const targetRoot = await harnessResourceRoot(workspace, source.name);
|
|
70289
70609
|
if (!targetRoot)
|
|
70290
70610
|
throw new Error(`Cannot prepare .agents/${source.name} in the mission worktree. Restore that directory.`);
|
|
@@ -70301,21 +70621,21 @@ async function harnessResourceRoot(workspacePath, name) {
|
|
|
70301
70621
|
});
|
|
70302
70622
|
if (!workspace)
|
|
70303
70623
|
return;
|
|
70304
|
-
const root = await realpath13(
|
|
70624
|
+
const root = await realpath13(join21(workspace, ".agents", name)).catch(() => {
|
|
70305
70625
|
return;
|
|
70306
70626
|
});
|
|
70307
70627
|
if (!root)
|
|
70308
70628
|
return;
|
|
70309
70629
|
if (!inside(workspace, root))
|
|
70310
70630
|
throw new Error(`The ${name === "skills" ? "skill" : "agent"} directory escapes the mission worktree. Install the OMA harness inside this repository.`);
|
|
70311
|
-
if (!(await
|
|
70631
|
+
if (!(await stat3(root)).isDirectory())
|
|
70312
70632
|
return;
|
|
70313
70633
|
return root;
|
|
70314
70634
|
}
|
|
70315
70635
|
async function skillPath(root, name) {
|
|
70316
70636
|
if (!SKILL_NAME.test(name))
|
|
70317
70637
|
throw new Error(`Invalid skill name: ${name}. Select an installed skill directory name.`);
|
|
70318
|
-
const path = await realpath13(
|
|
70638
|
+
const path = await realpath13(join21(root, name, "SKILL.md")).catch(() => {
|
|
70319
70639
|
throw new Error(`Skill ${name}/SKILL.md is missing. Restore that installed skill in ${root} before resuming.`);
|
|
70320
70640
|
});
|
|
70321
70641
|
if (!inside(root, path))
|
|
@@ -70323,7 +70643,7 @@ async function skillPath(root, name) {
|
|
|
70323
70643
|
return path;
|
|
70324
70644
|
}
|
|
70325
70645
|
async function readSkill(path, metadataOnly) {
|
|
70326
|
-
const file = await open9(path,
|
|
70646
|
+
const file = await open9(path, constants8.O_RDONLY | constants8.O_NOFOLLOW | constants8.O_NONBLOCK);
|
|
70327
70647
|
try {
|
|
70328
70648
|
const info = await file.stat();
|
|
70329
70649
|
if (!info.isFile())
|
|
@@ -70371,8 +70691,8 @@ function metadata2(source, name, path) {
|
|
|
70371
70691
|
async function descriptor(root, name) {
|
|
70372
70692
|
if (!OMA_SKILL_NAME.test(name))
|
|
70373
70693
|
return;
|
|
70374
|
-
const directory = await realpath13(
|
|
70375
|
-
if (!inside(root, directory) || !(await
|
|
70694
|
+
const directory = await realpath13(join21(root, name));
|
|
70695
|
+
if (!inside(root, directory) || !(await stat3(directory)).isDirectory())
|
|
70376
70696
|
return;
|
|
70377
70697
|
const path = await skillPath(root, name);
|
|
70378
70698
|
return metadata2(await readSkill(path, true), name, path);
|
|
@@ -70383,7 +70703,7 @@ async function discoverMissionSkills(workspacePath) {
|
|
|
70383
70703
|
});
|
|
70384
70704
|
if (!root)
|
|
70385
70705
|
return [];
|
|
70386
|
-
const entries = await
|
|
70706
|
+
const entries = await readdir6(root).catch(() => []);
|
|
70387
70707
|
const catalog = [];
|
|
70388
70708
|
for (const name of entries.sort()) {
|
|
70389
70709
|
const skill = await descriptor(root, name).catch(() => {
|
|
@@ -70471,7 +70791,7 @@ var MAX_GUIDANCE_BYTES = 256000;
|
|
|
70471
70791
|
var MAX_PROFILES = 100;
|
|
70472
70792
|
function inside2(root, path) {
|
|
70473
70793
|
const child = relative10(root, path);
|
|
70474
|
-
return child !== "" && child !== ".." && !child.startsWith(`..${sep10}`) && !
|
|
70794
|
+
return child !== "" && child !== ".." && !child.startsWith(`..${sep10}`) && !isAbsolute10(child);
|
|
70475
70795
|
}
|
|
70476
70796
|
function invalidProfile(path) {
|
|
70477
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.`);
|
|
@@ -70497,7 +70817,7 @@ function profileSkills(source, agentId, path) {
|
|
|
70497
70817
|
}
|
|
70498
70818
|
async function readProfile(root, filename) {
|
|
70499
70819
|
const agentId = filename.slice(0, -3);
|
|
70500
|
-
const requested =
|
|
70820
|
+
const requested = join22(root, filename);
|
|
70501
70821
|
if (!NAME.test(agentId))
|
|
70502
70822
|
throw invalidProfile(requested);
|
|
70503
70823
|
const path = await realpath14(requested).catch(() => {
|
|
@@ -70505,7 +70825,7 @@ async function readProfile(root, filename) {
|
|
|
70505
70825
|
});
|
|
70506
70826
|
if (!inside2(root, path))
|
|
70507
70827
|
throw new Error(`OMA agent profile ${requested} escapes .agents/agents. Fix its symlink before resuming.`);
|
|
70508
|
-
const file = await open10(path,
|
|
70828
|
+
const file = await open10(path, constants9.O_RDONLY | constants9.O_NOFOLLOW | constants9.O_NONBLOCK).catch(() => {
|
|
70509
70829
|
throw new Error(`OMA agent profile ${requested} is unreadable. Restore its file permissions before resuming.`);
|
|
70510
70830
|
});
|
|
70511
70831
|
try {
|
|
@@ -70538,15 +70858,15 @@ async function prepareOmaActor(workspacePath, selectedSkills) {
|
|
|
70538
70858
|
throw new Error(`Invalid skill name: ${name}. Select an installed skill directory name.`);
|
|
70539
70859
|
const selected = [...new Set(selectedSkills)].sort();
|
|
70540
70860
|
const workspace = await realpath14(workspacePath);
|
|
70541
|
-
const directory =
|
|
70861
|
+
const directory = join22(workspace, ".agents", "agents");
|
|
70542
70862
|
const root = await realpath14(directory).catch(() => {
|
|
70543
70863
|
throw new Error(`OMA work requires installed agent profiles in ${directory}. Install the OMA harness before resuming.`);
|
|
70544
70864
|
});
|
|
70545
70865
|
if (!inside2(workspace, root))
|
|
70546
70866
|
throw new Error("The OMA agent directory escapes the mission worktree. Install .agents/agents inside this repository.");
|
|
70547
|
-
if (!(await
|
|
70867
|
+
if (!(await stat4(root)).isDirectory())
|
|
70548
70868
|
throw new Error(`OMA agent profiles require a directory at ${directory}. Restore the installed OMA harness.`);
|
|
70549
|
-
const filenames = (await
|
|
70869
|
+
const filenames = (await readdir7(root)).filter((name) => name.endsWith(".md")).sort();
|
|
70550
70870
|
if (filenames.length > MAX_PROFILES)
|
|
70551
70871
|
throw new Error("The worktree has more than 100 OMA agent profiles. Remove unused profiles before resuming.");
|
|
70552
70872
|
let chosen;
|
|
@@ -70599,14 +70919,14 @@ var goalBriefSchema = strictObject({
|
|
|
70599
70919
|
var skillDescriptorSchema = strictObject({
|
|
70600
70920
|
name: string2().regex(/^oma-[a-z0-9][a-z0-9-]{0,123}$/),
|
|
70601
70921
|
description: string2().trim().min(1).max(1000),
|
|
70602
|
-
path: text9.refine(
|
|
70922
|
+
path: text9.refine(isAbsolute11, "Skill paths must be absolute verified SKILL.md paths.")
|
|
70603
70923
|
});
|
|
70604
70924
|
var planSchema = strictObject({
|
|
70605
70925
|
tasks: array(actorTaskSchema).min(1).max(12)
|
|
70606
70926
|
});
|
|
70607
70927
|
var missionSchema = strictObject({
|
|
70608
70928
|
id: id5,
|
|
70609
|
-
repositoryRoot: text9.refine(
|
|
70929
|
+
repositoryRoot: text9.refine(isAbsolute11, "Original repository root must be absolute.").optional(),
|
|
70610
70930
|
toolEnvKeys: toolEnvKeysSchema.optional(),
|
|
70611
70931
|
goal: text9,
|
|
70612
70932
|
chiefId: id5,
|
|
@@ -70891,7 +71211,7 @@ class MissionStore {
|
|
|
70891
71211
|
const path = `${this.path(id)}.lock`;
|
|
70892
71212
|
let file;
|
|
70893
71213
|
try {
|
|
70894
|
-
file = await open11(path,
|
|
71214
|
+
file = await open11(path, constants10.O_RDONLY | (constants10.O_NOFOLLOW ?? 0) | (constants10.O_NONBLOCK ?? 0));
|
|
70895
71215
|
const stat = await file.stat();
|
|
70896
71216
|
if (!stat.isFile() || stat.size < 1 || stat.size > 1024)
|
|
70897
71217
|
return true;
|
|
@@ -70920,7 +71240,7 @@ class MissionStore {
|
|
|
70920
71240
|
this.path(id);
|
|
70921
71241
|
if (mission && mission.id !== id)
|
|
70922
71242
|
throw new Error("Process recovery mission identity differs from its record. Restore the matching checkpoint.");
|
|
70923
|
-
const names = await
|
|
71243
|
+
const names = await readdir8(this.directory);
|
|
70924
71244
|
for (const name of names) {
|
|
70925
71245
|
if (name === `${id}.active`)
|
|
70926
71246
|
await this.processGuard(id).recoverOrphan();
|
|
@@ -70938,7 +71258,7 @@ class MissionStore {
|
|
|
70938
71258
|
path(id) {
|
|
70939
71259
|
if (!/^[a-zA-Z0-9][a-zA-Z0-9-]{0,79}$/.test(id))
|
|
70940
71260
|
throw new Error("Invalid mission ID. Use the ID printed by av order.");
|
|
70941
|
-
return
|
|
71261
|
+
return join23(this.directory, `${id}.json`);
|
|
70942
71262
|
}
|
|
70943
71263
|
save(mission) {
|
|
70944
71264
|
const write = this.writes.then(() => this.persist(mission));
|
|
@@ -70952,7 +71272,7 @@ class MissionStore {
|
|
|
70952
71272
|
await writeJsonAtomic(path, { version: 1, mission });
|
|
70953
71273
|
}
|
|
70954
71274
|
async load(id) {
|
|
70955
|
-
const content = JSON.parse(await
|
|
71275
|
+
const content = JSON.parse(await readFile9(this.path(id), "utf8"));
|
|
70956
71276
|
if (content.version !== 1)
|
|
70957
71277
|
throw new Error("Unsupported mission record version. Use the Agent Valley version that created this mission.");
|
|
70958
71278
|
const mission = missionSchema.parse(content.mission);
|
|
@@ -70963,7 +71283,7 @@ class MissionStore {
|
|
|
70963
71283
|
async list() {
|
|
70964
71284
|
let names;
|
|
70965
71285
|
try {
|
|
70966
|
-
names = await
|
|
71286
|
+
names = await readdir8(this.directory);
|
|
70967
71287
|
} catch (error) {
|
|
70968
71288
|
if (error.code === "ENOENT")
|
|
70969
71289
|
return [];
|
|
@@ -70980,7 +71300,7 @@ class MissionStore {
|
|
|
70980
71300
|
init_yaml_loader();
|
|
70981
71301
|
|
|
70982
71302
|
// src/chief-config.ts
|
|
70983
|
-
import { isAbsolute as
|
|
71303
|
+
import { isAbsolute as isAbsolute12, resolve as resolve18 } from "node:path";
|
|
70984
71304
|
|
|
70985
71305
|
// ../../packages/core/src/chief/advisory-evidence.ts
|
|
70986
71306
|
function unavailableDirectorAdvice(mission) {
|
|
@@ -71298,7 +71618,7 @@ async function resolveOrderConfig(root, options, discover = discoverAgents) {
|
|
|
71298
71618
|
const global2 = loadGlobalConfig();
|
|
71299
71619
|
const chiefConfig = mergeChiefConfig(global2?.chief, project?.chief);
|
|
71300
71620
|
const workspace = options.workspace ?? project?.workspace?.root;
|
|
71301
|
-
if (!workspace || !
|
|
71621
|
+
if (!workspace || !isAbsolute12(workspace))
|
|
71302
71622
|
throw new Error("Set --workspace to an absolute Git repository path, or set workspace.root in av.yaml.");
|
|
71303
71623
|
const verifyCommand = options.verify ?? project?.verify?.command ?? "";
|
|
71304
71624
|
if (actorOption !== undefined && !agents.has(actorOption))
|
|
@@ -71410,6 +71730,22 @@ ${details}` : ""}`);
|
|
|
71410
71730
|
|
|
71411
71731
|
// ../../packages/core/src/chief/continuous-recovery.ts
|
|
71412
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
|
|
71413
71749
|
function verifiedMissionEvidence(mission) {
|
|
71414
71750
|
const plan = mission.plan;
|
|
71415
71751
|
const review = mission.finalReview;
|
|
@@ -71424,9 +71760,6 @@ function verifiedMissionEvidence(mission) {
|
|
|
71424
71760
|
return false;
|
|
71425
71761
|
}
|
|
71426
71762
|
}
|
|
71427
|
-
function scheduledChiefWait(mission) {
|
|
71428
|
-
return mission.status === "waiting" && mission.execution?.failureKind === "chief-wait" && mission.supervision?.decisions.at(-1)?.action === "wait" && Number.isFinite(Date.parse(mission.execution.nextRunAt ?? ""));
|
|
71429
|
-
}
|
|
71430
71763
|
function automaticMissionRecovery(mission, now = Date.now(), context = {}) {
|
|
71431
71764
|
const stop = (reason) => ({ retry: false, reason });
|
|
71432
71765
|
if (!mission.executionPolicy?.autoResume)
|
|
@@ -71463,6 +71796,12 @@ function automaticMissionRecovery(mission, now = Date.now(), context = {}) {
|
|
|
71463
71796
|
return stop(error.message);
|
|
71464
71797
|
throw error;
|
|
71465
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
|
+
};
|
|
71466
71805
|
const supervision = mission.supervision;
|
|
71467
71806
|
if (supervision && (supervision.rounds >= supervision.maxRounds || supervision.stalledRounds >= 3))
|
|
71468
71807
|
return stop("The Chief exhausted its saved recovery rounds; the goal remains unresolved.");
|
|
@@ -71495,12 +71834,12 @@ init_execution();
|
|
|
71495
71834
|
|
|
71496
71835
|
// src/chief-delivery-resume.ts
|
|
71497
71836
|
import { realpath as realpath17 } from "node:fs/promises";
|
|
71498
|
-
import { join as
|
|
71837
|
+
import { join as join29 } from "node:path";
|
|
71499
71838
|
|
|
71500
71839
|
// src/chief-code-delivery.ts
|
|
71501
71840
|
import { createHash as createHash18, randomUUID as randomUUID12 } from "node:crypto";
|
|
71502
|
-
import { lstat as
|
|
71503
|
-
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";
|
|
71504
71843
|
init_execution();
|
|
71505
71844
|
|
|
71506
71845
|
// ../../packages/core/src/chief/execution-signal.ts
|
|
@@ -71594,8 +71933,8 @@ function recordServiceShutdown(mission, unconfirmedTermination) {
|
|
|
71594
71933
|
// src/chief-code-delivery-git.ts
|
|
71595
71934
|
import { execFile as execFile2 } from "node:child_process";
|
|
71596
71935
|
import { createHash as createHash17 } from "node:crypto";
|
|
71597
|
-
import { lstat as
|
|
71598
|
-
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";
|
|
71599
71938
|
import { promisify as promisify2 } from "node:util";
|
|
71600
71939
|
init_git_environment();
|
|
71601
71940
|
init_worktree_lifecycle();
|
|
@@ -71618,9 +71957,9 @@ function shellQuote(value) {
|
|
|
71618
71957
|
return `'${value.replace(/'/g, "'\\''")}'`;
|
|
71619
71958
|
}
|
|
71620
71959
|
async function canonicalDirectory(path, description) {
|
|
71621
|
-
if (!
|
|
71960
|
+
if (!isAbsolute13(path))
|
|
71622
71961
|
throw new Error(`Use an absolute ${description} path before preparing code delivery.`);
|
|
71623
|
-
const entry = await
|
|
71962
|
+
const entry = await lstat12(path);
|
|
71624
71963
|
if (entry.isSymbolicLink() || !entry.isDirectory())
|
|
71625
71964
|
throw new Error(`The ${description} must be a real directory. Restore its original location before retrying.`);
|
|
71626
71965
|
return realpath15(path);
|
|
@@ -71630,13 +71969,13 @@ async function inspectProductPath(workspace, path) {
|
|
|
71630
71969
|
throw new Error(`Code delivery path ${JSON.stringify(path)} is private or invalid. Select an exact product file.`);
|
|
71631
71970
|
const destination = resolve19(workspace, path);
|
|
71632
71971
|
const within = relative11(workspace, destination);
|
|
71633
|
-
if (!within || within === ".." || within.startsWith(`..${sep11}`) ||
|
|
71972
|
+
if (!within || within === ".." || within.startsWith(`..${sep11}`) || isAbsolute13(within))
|
|
71634
71973
|
throw new Error("Code delivery escaped its source workspace. Restore the pinned product paths before retrying.");
|
|
71635
71974
|
const parts = path.split("/");
|
|
71636
71975
|
let current = workspace;
|
|
71637
71976
|
for (let index = 0;index < parts.length; index += 1) {
|
|
71638
|
-
current =
|
|
71639
|
-
const entry = await
|
|
71977
|
+
current = join27(current, parts[index] ?? "");
|
|
71978
|
+
const entry = await lstat12(current).catch((error) => {
|
|
71640
71979
|
if (error.code === "ENOENT")
|
|
71641
71980
|
return;
|
|
71642
71981
|
throw error;
|
|
@@ -71680,9 +72019,9 @@ async function prepareDeliveryPatch(workspace, baseSha, allowedPaths, directory)
|
|
|
71680
72019
|
throw new Error(`Changed path ${JSON.stringify(path)} is outside code delivery scope. Reconcile the exact allowlist.`);
|
|
71681
72020
|
await inspectProductPath(workspace, path);
|
|
71682
72021
|
}
|
|
71683
|
-
const temporary = await mkdtemp(
|
|
71684
|
-
const indexPath =
|
|
71685
|
-
const patchPath =
|
|
72022
|
+
const temporary = await mkdtemp(join27(directory, "patch-"));
|
|
72023
|
+
const indexPath = join27(temporary, "index");
|
|
72024
|
+
const patchPath = join27(temporary, "delivery.patch");
|
|
71686
72025
|
const env = { GIT_INDEX_FILE: indexPath };
|
|
71687
72026
|
try {
|
|
71688
72027
|
await gitRead(workspace, ["read-tree", baseSha], env);
|
|
@@ -71734,8 +72073,8 @@ async function artifact(path, content) {
|
|
|
71734
72073
|
} catch (error) {
|
|
71735
72074
|
if (error.code !== "EEXIST")
|
|
71736
72075
|
throw error;
|
|
71737
|
-
const entry = await
|
|
71738
|
-
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)))
|
|
71739
72078
|
throw new DeliveryBlocked("Private delivery artifact changed. Restore its original bytes before resuming.");
|
|
71740
72079
|
}
|
|
71741
72080
|
}
|
|
@@ -71769,9 +72108,9 @@ async function privateDirectory(root, id) {
|
|
|
71769
72108
|
throw new DeliveryBlocked("Restore the original Mission identity before delivery.");
|
|
71770
72109
|
let current = root;
|
|
71771
72110
|
for (const part of [".agent-valley", "code-delivery", id]) {
|
|
71772
|
-
current =
|
|
72111
|
+
current = join28(current, part);
|
|
71773
72112
|
await mkdir12(current, { recursive: true, mode: 448 });
|
|
71774
|
-
const stat = await
|
|
72113
|
+
const stat = await lstat13(current);
|
|
71775
72114
|
if (!stat.isDirectory() || stat.isSymbolicLink() || await realpath16(current) !== current)
|
|
71776
72115
|
throw new DeliveryBlocked("Code delivery storage redirects through a symlink. Restore its private local directory.");
|
|
71777
72116
|
}
|
|
@@ -71877,10 +72216,10 @@ async function deliverMissionCode(mission, store, signal) {
|
|
|
71877
72216
|
throw new DeliveryBlocked("Restore the saved source repository identity before delivery.");
|
|
71878
72217
|
const root = await repositoryRoot(mission.repositoryRoot);
|
|
71879
72218
|
const gitDirectory = await realpath16(resolve20(root, (await gitRead(root, ["rev-parse", "--git-common-dir"])).trim()));
|
|
71880
|
-
unlock = await lockRecord(
|
|
72219
|
+
unlock = await lockRecord(join28(gitDirectory, "agent-valley-delivery.lock"), "Code delivery", "code-delivery");
|
|
71881
72220
|
await assertTarget(root, delivery);
|
|
71882
72221
|
const directory = await privateDirectory(root, mission.id);
|
|
71883
|
-
const patchPath =
|
|
72222
|
+
const patchPath = join28(directory, "changes.patch");
|
|
71884
72223
|
if (delivery.phase === "pending") {
|
|
71885
72224
|
if ((await gitRead(root, ["rev-parse", "HEAD"])).trim() !== delivery.policy.baseSha || !await clean(root))
|
|
71886
72225
|
throw new DeliveryBlocked("Source HEAD or its clean index changed since delivery was authorized. Preserve edits and restore the pinned source before resuming.");
|
|
@@ -71899,7 +72238,7 @@ async function deliverMissionCode(mission, store, signal) {
|
|
|
71899
72238
|
await save();
|
|
71900
72239
|
return;
|
|
71901
72240
|
}
|
|
71902
|
-
await artifact(patchPath, await
|
|
72241
|
+
await artifact(patchPath, await readFile10(prepared.patchPath));
|
|
71903
72242
|
delivery.treeSha = prepared.treeSha;
|
|
71904
72243
|
delivery.patchSha256 = prepared.patchSha256;
|
|
71905
72244
|
delivery.verifiedFingerprint = mission.fingerprint;
|
|
@@ -71909,7 +72248,7 @@ async function deliverMissionCode(mission, store, signal) {
|
|
|
71909
72248
|
}
|
|
71910
72249
|
if (!delivery.nonce || delivery.verifiedFingerprint !== mission.fingerprint)
|
|
71911
72250
|
throw new DeliveryBlocked("Restore the prepared delivery nonce and verified fingerprint before resuming.");
|
|
71912
|
-
if (createHash18("sha256").update(await
|
|
72251
|
+
if (createHash18("sha256").update(await readFile10(patchPath)).digest("hex") !== delivery.patchSha256)
|
|
71913
72252
|
throw new DeliveryBlocked("Prepared patch bytes changed. Preserve the delivery record and restore its original patch.");
|
|
71914
72253
|
const message = `${delivery.policy.message}
|
|
71915
72254
|
|
|
@@ -71956,7 +72295,7 @@ AV-Delivery: ${delivery.nonce}
|
|
|
71956
72295
|
if ((await gitRead(root, ["write-tree"])).trim() !== delivery.treeSha)
|
|
71957
72296
|
throw new DeliveryBlocked("Staged delivery differs from its verified tree. Preserve the index for inspection.");
|
|
71958
72297
|
assertLive(mission, signal);
|
|
71959
|
-
const messagePath =
|
|
72298
|
+
const messagePath = join28(directory, "commit-message.txt");
|
|
71960
72299
|
await artifact(messagePath, message);
|
|
71961
72300
|
await managedGit(mission, store, root, ["commit", "--file", messagePath], signal);
|
|
71962
72301
|
delivery.commitSha = await committedHead(root, delivery, message);
|
|
@@ -72098,7 +72437,7 @@ async function enableOperationDelivery(operation, options, root, save, onEnable)
|
|
|
72098
72437
|
let unlock;
|
|
72099
72438
|
try {
|
|
72100
72439
|
if (operation.currentMissionId) {
|
|
72101
|
-
const missions = new MissionStore(
|
|
72440
|
+
const missions = new MissionStore(join29(root, ".agent-valley", "missions"));
|
|
72102
72441
|
unlock = await missions.lock(operation.currentMissionId);
|
|
72103
72442
|
const child = await missions.load(operation.currentMissionId);
|
|
72104
72443
|
if (child.repositoryRoot !== operation.repositoryRoot || child.goal !== (operation.decision?.action === "execute" ? operation.decision.goal : undefined))
|
|
@@ -72213,8 +72552,8 @@ function applyResumeOptions(mission, goal, options) {
|
|
|
72213
72552
|
|
|
72214
72553
|
// src/mission-jobs.ts
|
|
72215
72554
|
import { createHash as createHash19 } from "node:crypto";
|
|
72216
|
-
import { lstat as
|
|
72217
|
-
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";
|
|
72218
72557
|
init_atomic_json();
|
|
72219
72558
|
init_runtime_ignore();
|
|
72220
72559
|
init_zod();
|
|
@@ -72248,12 +72587,12 @@ function jobLiveness(job) {
|
|
|
72248
72587
|
async function ensureAvDirectory(root, parts) {
|
|
72249
72588
|
let path = root;
|
|
72250
72589
|
for (const part of [".agent-valley", ...parts]) {
|
|
72251
|
-
path =
|
|
72590
|
+
path = join30(path, part);
|
|
72252
72591
|
await mkdir13(path, { mode: 448 }).catch((error) => {
|
|
72253
72592
|
if (error.code !== "EEXIST")
|
|
72254
72593
|
throw error;
|
|
72255
72594
|
});
|
|
72256
|
-
const stat = await
|
|
72595
|
+
const stat = await lstat14(path);
|
|
72257
72596
|
if (!stat.isDirectory() || stat.isSymbolicLink())
|
|
72258
72597
|
throw new Error(`AV control directory must be a real directory: ${path}. Remove the symlink before retrying.`);
|
|
72259
72598
|
}
|
|
@@ -72267,7 +72606,7 @@ class MissionJobs {
|
|
|
72267
72606
|
constructor(root, directoryName = "jobs") {
|
|
72268
72607
|
this.root = root;
|
|
72269
72608
|
this.directoryName = directoryName;
|
|
72270
|
-
this.directory =
|
|
72609
|
+
this.directory = join30(root, ".agent-valley/control", directoryName);
|
|
72271
72610
|
}
|
|
72272
72611
|
async locked(operation) {
|
|
72273
72612
|
await ensureRuntimeGitignore(this.root);
|
|
@@ -72283,9 +72622,9 @@ class MissionJobs {
|
|
|
72283
72622
|
await ensureAvDirectory(this.root, ["control", this.directoryName]);
|
|
72284
72623
|
try {
|
|
72285
72624
|
const path = this.path(requestId);
|
|
72286
|
-
if ((await
|
|
72625
|
+
if ((await lstat14(path)).isSymbolicLink())
|
|
72287
72626
|
throw new Error("AV launch receipt cannot be a symlink.");
|
|
72288
|
-
return jobSchema.parse(JSON.parse(await
|
|
72627
|
+
return jobSchema.parse(JSON.parse(await readFile11(path, "utf8")));
|
|
72289
72628
|
} catch (error) {
|
|
72290
72629
|
if (error.code === "ENOENT")
|
|
72291
72630
|
return;
|
|
@@ -72296,16 +72635,16 @@ class MissionJobs {
|
|
|
72296
72635
|
}
|
|
72297
72636
|
async list() {
|
|
72298
72637
|
await ensureAvDirectory(this.root, ["control", this.directoryName]);
|
|
72299
|
-
const files = await
|
|
72638
|
+
const files = await readdir9(this.directory).catch((error) => {
|
|
72300
72639
|
if (error.code === "ENOENT")
|
|
72301
72640
|
return [];
|
|
72302
72641
|
throw error;
|
|
72303
72642
|
});
|
|
72304
72643
|
return Promise.all(files.filter((file) => /^[a-f0-9]{64}\.json$/.test(file)).map(async (file) => {
|
|
72305
|
-
const path =
|
|
72306
|
-
if ((await
|
|
72644
|
+
const path = join30(this.directory, file);
|
|
72645
|
+
if ((await lstat14(path)).isSymbolicLink())
|
|
72307
72646
|
throw new Error(`AV launch receipt cannot be a symlink: ${path}`);
|
|
72308
|
-
return jobSchema.parse(JSON.parse(await
|
|
72647
|
+
return jobSchema.parse(JSON.parse(await readFile11(path, "utf8")));
|
|
72309
72648
|
}));
|
|
72310
72649
|
}
|
|
72311
72650
|
async latest(missionId) {
|
|
@@ -72317,10 +72656,10 @@ class MissionJobs {
|
|
|
72317
72656
|
await writeJsonAtomic(this.path(job.requestId), job, { pretty: false });
|
|
72318
72657
|
}
|
|
72319
72658
|
logPath(job) {
|
|
72320
|
-
return
|
|
72659
|
+
return join30(this.directory, `${digest6(job.requestId)}.log`);
|
|
72321
72660
|
}
|
|
72322
72661
|
path(requestId) {
|
|
72323
|
-
return
|
|
72662
|
+
return join30(this.directory, `${digest6(requestId)}.json`);
|
|
72324
72663
|
}
|
|
72325
72664
|
}
|
|
72326
72665
|
|
|
@@ -72355,16 +72694,17 @@ async function launchMission(input) {
|
|
|
72355
72694
|
// src/operation-api.ts
|
|
72356
72695
|
import { randomUUID as randomUUID21 } from "node:crypto";
|
|
72357
72696
|
import { realpath as realpath32 } from "node:fs/promises";
|
|
72358
|
-
import { join as
|
|
72697
|
+
import { join as join54 } from "node:path";
|
|
72359
72698
|
|
|
72360
72699
|
// ../../packages/core/src/chief/continuous-store.ts
|
|
72361
72700
|
init_atomic_json();
|
|
72362
|
-
import { lstat as
|
|
72363
|
-
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";
|
|
72364
72703
|
|
|
72365
72704
|
// ../../packages/core/src/chief/continuous-contract.ts
|
|
72366
72705
|
init_zod();
|
|
72367
72706
|
init_container_observation_policy();
|
|
72707
|
+
init_operations();
|
|
72368
72708
|
|
|
72369
72709
|
// ../../packages/core/src/chief/source-integration-contract.ts
|
|
72370
72710
|
init_zod();
|
|
@@ -72436,6 +72776,7 @@ var operationSchema = strictObject({
|
|
|
72436
72776
|
repositoryRoot: pathSchema,
|
|
72437
72777
|
charter: string2().trim().min(1).max(32000),
|
|
72438
72778
|
settings: record(string2().min(1).max(80), union([string2().max(32000), boolean2()])),
|
|
72779
|
+
actorHealth: array(providerHealthEvidenceSchema).max(100).optional(),
|
|
72439
72780
|
phase: _enum(["deciding", "running", "accepting", "waiting", "paused", "completed"]),
|
|
72440
72781
|
pauseKind: _enum(["interrupted", "blocked", "service-shutdown"]).optional(),
|
|
72441
72782
|
createdAt: timestampSchema,
|
|
@@ -72530,7 +72871,7 @@ class ContinuousOperationStore {
|
|
|
72530
72871
|
}
|
|
72531
72872
|
path(id) {
|
|
72532
72873
|
operationIdSchema.parse(id);
|
|
72533
|
-
return
|
|
72874
|
+
return join31(this.directory, `${id}.json`);
|
|
72534
72875
|
}
|
|
72535
72876
|
async ensureDirectory() {
|
|
72536
72877
|
await mkdir14(this.directory, { recursive: true, mode: 448 });
|
|
@@ -72550,9 +72891,9 @@ class ContinuousOperationStore {
|
|
|
72550
72891
|
}
|
|
72551
72892
|
async load(id) {
|
|
72552
72893
|
const path = this.path(id);
|
|
72553
|
-
if (await realpath18(this.directory) !== resolve21(this.directory) || !(await
|
|
72894
|
+
if (await realpath18(this.directory) !== resolve21(this.directory) || !(await lstat15(path)).isFile())
|
|
72554
72895
|
throw new Error("Operation record must remain a regular file in its original local storage directory.");
|
|
72555
|
-
const content = JSON.parse(await
|
|
72896
|
+
const content = JSON.parse(await readFile12(path, "utf8"));
|
|
72556
72897
|
if (content.version !== 1)
|
|
72557
72898
|
throw new Error("Unsupported operation record version. Use the AV version that created this operation.");
|
|
72558
72899
|
const operation = operationSchema.parse(content.operation);
|
|
@@ -72563,7 +72904,7 @@ class ContinuousOperationStore {
|
|
|
72563
72904
|
async list() {
|
|
72564
72905
|
let names;
|
|
72565
72906
|
try {
|
|
72566
|
-
names = await
|
|
72907
|
+
names = await readdir10(this.directory);
|
|
72567
72908
|
} catch (error) {
|
|
72568
72909
|
if (error.code === "ENOENT")
|
|
72569
72910
|
return [];
|
|
@@ -72582,7 +72923,7 @@ class ContinuousOperationStore {
|
|
|
72582
72923
|
import { execFile as execFile6 } from "node:child_process";
|
|
72583
72924
|
import { randomUUID as randomUUID20 } from "node:crypto";
|
|
72584
72925
|
import { realpath as realpath31 } from "node:fs/promises";
|
|
72585
|
-
import { join as
|
|
72926
|
+
import { join as join53, resolve as resolve33 } from "node:path";
|
|
72586
72927
|
import { promisify as promisify4 } from "node:util";
|
|
72587
72928
|
|
|
72588
72929
|
// ../../packages/core/src/chief/container-observation-command.ts
|
|
@@ -73069,9 +73410,9 @@ async function collectContainerObservation(input, previous, dependencies = {}) {
|
|
|
73069
73410
|
|
|
73070
73411
|
// ../../packages/core/src/chief/continuous-acceptance-record.ts
|
|
73071
73412
|
init_zod();
|
|
73072
|
-
import { constants as
|
|
73073
|
-
import { lstat as
|
|
73074
|
-
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";
|
|
73075
73416
|
var objectId3 = string2().regex(/^[a-f0-9]{40,64}$/);
|
|
73076
73417
|
var continuousAcceptanceSchema = strictObject({
|
|
73077
73418
|
version: literal(1),
|
|
@@ -73089,8 +73430,8 @@ async function recordContinuousAcceptance(operation) {
|
|
|
73089
73430
|
const entry = operation.history.at(-1);
|
|
73090
73431
|
if (!snapshot?.missionId || !entry || entry.missionId !== snapshot.missionId || entry.baselinePath !== snapshot.path)
|
|
73091
73432
|
return;
|
|
73092
|
-
const directory =
|
|
73093
|
-
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)
|
|
73094
73435
|
throw new Error("Acceptance journal paths changed. Restore the original accepted snapshot before continuing.");
|
|
73095
73436
|
const record = continuousAcceptanceSchema.parse({
|
|
73096
73437
|
version: 1,
|
|
@@ -73103,10 +73444,10 @@ async function recordContinuousAcceptance(operation) {
|
|
|
73103
73444
|
tree: snapshot.baselineTree,
|
|
73104
73445
|
completedAt: entry.completedAt
|
|
73105
73446
|
});
|
|
73106
|
-
const path =
|
|
73447
|
+
const path = join32(directory, "acceptance.json");
|
|
73107
73448
|
let existing;
|
|
73108
73449
|
try {
|
|
73109
|
-
existing = await open13(path,
|
|
73450
|
+
existing = await open13(path, constants12.O_RDONLY | (constants12.O_NOFOLLOW ?? 0) | (constants12.O_NONBLOCK ?? 0));
|
|
73110
73451
|
const stat = await existing.stat();
|
|
73111
73452
|
if (!stat.isFile() || stat.size > 16384)
|
|
73112
73453
|
throw new Error("Unsupported acceptance journal receipt.");
|
|
@@ -73120,7 +73461,7 @@ async function recordContinuousAcceptance(operation) {
|
|
|
73120
73461
|
} finally {
|
|
73121
73462
|
await existing?.close();
|
|
73122
73463
|
}
|
|
73123
|
-
if (!(await
|
|
73464
|
+
if (!(await lstat16(dirname6(path))).isDirectory())
|
|
73124
73465
|
throw new Error("Acceptance journal requires its original private directory.");
|
|
73125
73466
|
const handle = await open13(path, "wx", 384);
|
|
73126
73467
|
try {
|
|
@@ -73134,6 +73475,43 @@ async function recordContinuousAcceptance(operation) {
|
|
|
73134
73475
|
// ../../packages/core/src/chief/continuous-operation.ts
|
|
73135
73476
|
import { createHash as createHash21, randomUUID as randomUUID13 } from "node:crypto";
|
|
73136
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
|
+
|
|
73137
73515
|
// ../../packages/core/src/chief/continuous-acceptance.ts
|
|
73138
73516
|
async function acceptContinuousChild(operation, mission, ports, save, now) {
|
|
73139
73517
|
const previous = operation.baseline;
|
|
@@ -73197,6 +73575,23 @@ async function runContinuousOperation(operation, ports) {
|
|
|
73197
73575
|
operation.updatedAt = now();
|
|
73198
73576
|
await ports.save(operation);
|
|
73199
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));
|
|
73200
73595
|
const pause = async (message) => {
|
|
73201
73596
|
if (operation.phase !== "paused" && operation.phase !== "completed")
|
|
73202
73597
|
operation.resumePhase = operation.phase;
|
|
@@ -73252,11 +73647,13 @@ async function runContinuousOperation(operation, ports) {
|
|
|
73252
73647
|
const previous = operation.recovery?.target === "child" && operation.recovery.checkpointId === mission.id ? operation.recovery : undefined;
|
|
73253
73648
|
const prior = previous?.attempts ?? 0;
|
|
73254
73649
|
const failedAttempts = previous?.failedAttempts ?? prior;
|
|
73255
|
-
const
|
|
73256
|
-
|
|
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) },
|
|
73257
73653
|
nextRunAt: mission.execution?.nextRunAt
|
|
73258
73654
|
})).digest("hex") : undefined;
|
|
73259
|
-
const
|
|
73655
|
+
const pendingCooldown = actorCooldown && previous?.nextRunAt === mission.execution?.nextRunAt;
|
|
73656
|
+
const continuation = !!waitKey && (waitKey !== previous?.waitContinuationKey || pendingCooldown);
|
|
73260
73657
|
operation.recovery = {
|
|
73261
73658
|
target: "child",
|
|
73262
73659
|
checkpointId: mission.id,
|
|
@@ -73286,7 +73683,7 @@ async function runContinuousOperation(operation, ports) {
|
|
|
73286
73683
|
if (!operation.baseline)
|
|
73287
73684
|
throw new Error("The original accepted baseline is missing from the recovery checkpoint.");
|
|
73288
73685
|
try {
|
|
73289
|
-
const resumed = await
|
|
73686
|
+
const resumed = await runChild(mission.id, mission.goal, operation.baseline.path);
|
|
73290
73687
|
if (isServiceShutdown(ports.signal) && resumed.execution?.failureKind === "service-shutdown") {
|
|
73291
73688
|
operation.recovery = pendingRecovery;
|
|
73292
73689
|
throw interruptionPause(ports.signal, "Operation child recovery interrupted.");
|
|
@@ -73372,15 +73769,9 @@ async function runContinuousOperation(operation, ports) {
|
|
|
73372
73769
|
const decision = operation.decision;
|
|
73373
73770
|
if (decision?.action !== "execute")
|
|
73374
73771
|
throw new Error("Restore the saved child execution decision before resuming.");
|
|
73375
|
-
const assertIdentity = (child) => {
|
|
73376
|
-
if (child.id !== id || child.repositoryRoot !== operation.repositoryRoot || child.goal !== decision.goal)
|
|
73377
|
-
throw new Error("Saved child identity, repository or goal does not match this operation. Restore the original child before continuing.");
|
|
73378
|
-
if (JSON.stringify(child.containerObservationPolicy) !== JSON.stringify(operation.containerObservationPolicy))
|
|
73379
|
-
throw new Error("Saved child container targets differ from the pinned operation contract. Restore the original child policy before continuing.");
|
|
73380
|
-
};
|
|
73381
73772
|
let mission = await ports.findMission(id);
|
|
73382
73773
|
if (mission) {
|
|
73383
|
-
|
|
73774
|
+
await rememberHealth(mission);
|
|
73384
73775
|
if (mission.tasks.some((task) => task.effectState === "unknown")) {
|
|
73385
73776
|
if (await recoverChild(mission))
|
|
73386
73777
|
continue;
|
|
@@ -73395,7 +73786,7 @@ async function runContinuousOperation(operation, ports) {
|
|
|
73395
73786
|
if (!mission) {
|
|
73396
73787
|
if (operation.phase === "accepting")
|
|
73397
73788
|
return pause(`Completed child ${id} is missing. Restore its saved mission record before continuing.`);
|
|
73398
|
-
mission = await
|
|
73789
|
+
mission = await runChild(id, decision.goal, operation.baseline.path);
|
|
73399
73790
|
} else if (mission.status !== "completed" && mission.status !== "paused" && mission.status !== "failed") {
|
|
73400
73791
|
const recovery = operation.recovery;
|
|
73401
73792
|
if (recovery?.target === "child" && recovery.checkpointId === id && recovery.disposition === "protected" && !mission.tasks.some((task) => task.effectState === "running") && automaticMissionRecovery(mission, Date.parse(now())).retry) {
|
|
@@ -73403,7 +73794,7 @@ async function runContinuousOperation(operation, ports) {
|
|
|
73403
73794
|
recovery.reason = `The original child resumed ${mission.status}; joining its saved coordinator without spending another recovery attempt.`;
|
|
73404
73795
|
await save();
|
|
73405
73796
|
}
|
|
73406
|
-
mission = await
|
|
73797
|
+
mission = await runChild(id, decision.goal, operation.baseline.path);
|
|
73407
73798
|
}
|
|
73408
73799
|
assertIdentity(mission);
|
|
73409
73800
|
if (mission.status !== "completed") {
|
|
@@ -73420,7 +73811,7 @@ async function runContinuousOperation(operation, ports) {
|
|
|
73420
73811
|
if (!mission.executionPolicy?.autoResume)
|
|
73421
73812
|
return pause(`Child ${id} has pending code delivery with automatic recovery disabled.`);
|
|
73422
73813
|
await waitForRecovery(mission.codeDelivery?.nextRunAt, mission);
|
|
73423
|
-
await
|
|
73814
|
+
await runChild(id, decision.goal, operation.baseline.path);
|
|
73424
73815
|
continue;
|
|
73425
73816
|
}
|
|
73426
73817
|
if (!successfulCodeDelivery(mission))
|
|
@@ -73516,12 +73907,12 @@ async function runContinuousOperation(operation, ports) {
|
|
|
73516
73907
|
// ../../packages/core/src/chief/continuous-source-integration.ts
|
|
73517
73908
|
init_zod();
|
|
73518
73909
|
import { createHash as createHash23 } from "node:crypto";
|
|
73519
|
-
import { lstat as
|
|
73520
|
-
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";
|
|
73521
73912
|
|
|
73522
73913
|
// ../../packages/core/src/chief/content-transaction.ts
|
|
73523
73914
|
import { createHash as createHash22 } from "node:crypto";
|
|
73524
|
-
import { readFile as
|
|
73915
|
+
import { readFile as readFile13 } from "node:fs/promises";
|
|
73525
73916
|
|
|
73526
73917
|
// ../../packages/core/src/chief/parallel-git.ts
|
|
73527
73918
|
init_atomic_json();
|
|
@@ -73530,7 +73921,7 @@ init_git_environment();
|
|
|
73530
73921
|
import { execFile as execFile4 } from "node:child_process";
|
|
73531
73922
|
import { randomUUID as randomUUID14 } from "node:crypto";
|
|
73532
73923
|
import { mkdir as mkdir15, realpath as realpath20, rm as rm4, writeFile as writeFile8 } from "node:fs/promises";
|
|
73533
|
-
import { join as
|
|
73924
|
+
import { join as join33, relative as relative12, resolve as resolve23, sep as sep12 } from "node:path";
|
|
73534
73925
|
import { promisify as promisify3 } from "node:util";
|
|
73535
73926
|
var exec2 = promisify3(execFile4);
|
|
73536
73927
|
var productPaths = ["--", ".", ":(exclude,glob).agent-valley/**", ":(exclude,glob).agents/**"];
|
|
@@ -73551,7 +73942,7 @@ async function parallelGit(cwd, args, env = {}) {
|
|
|
73551
73942
|
}
|
|
73552
73943
|
async function parallelRoot(workspace) {
|
|
73553
73944
|
const root = await realpath20(workspace);
|
|
73554
|
-
const directory =
|
|
73945
|
+
const directory = join33(root, ".agent-valley", "parallel");
|
|
73555
73946
|
await mkdir15(directory, { recursive: true, mode: 448 });
|
|
73556
73947
|
const actual = await realpath20(directory);
|
|
73557
73948
|
if (actual !== directory)
|
|
@@ -73568,7 +73959,7 @@ async function writeParallelJson(path, value) {
|
|
|
73568
73959
|
}
|
|
73569
73960
|
async function captureParallelBaseline(workspace) {
|
|
73570
73961
|
const directory = await parallelRoot(workspace);
|
|
73571
|
-
const index =
|
|
73962
|
+
const index = join33(directory, `index-${randomUUID14()}`);
|
|
73572
73963
|
const pathsFile = `${index}.paths`;
|
|
73573
73964
|
const env = { GIT_INDEX_FILE: index };
|
|
73574
73965
|
try {
|
|
@@ -73614,7 +74005,7 @@ async function parallelTreeImages(workspace, tree) {
|
|
|
73614
74005
|
// ../../packages/core/src/chief/content-transaction.ts
|
|
73615
74006
|
async function integrateContentTransaction(workspace, transaction, hooks) {
|
|
73616
74007
|
await hooks.assertLive?.();
|
|
73617
|
-
const patch = await
|
|
74008
|
+
const patch = await readFile13(transaction.patchPath);
|
|
73618
74009
|
if (createHash22("sha256").update(patch).digest("hex") !== transaction.patchSha256)
|
|
73619
74010
|
throw new Error("Integration patch changed. Restore its saved SHA256 before integration.");
|
|
73620
74011
|
const current = await captureParallelBaseline(workspace);
|
|
@@ -73658,8 +74049,8 @@ init_zod();
|
|
|
73658
74049
|
init_runtime_ignore();
|
|
73659
74050
|
init_parallel_contract();
|
|
73660
74051
|
import { randomUUID as randomUUID15 } from "node:crypto";
|
|
73661
|
-
import { lstat as
|
|
73662
|
-
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";
|
|
73663
74054
|
var imageSchema2 = parallelDeliverySchema.shape.changes.element.shape.before;
|
|
73664
74055
|
var gitignoreProjectionSchema = strictObject({
|
|
73665
74056
|
path: literal(".gitignore"),
|
|
@@ -73674,13 +74065,13 @@ async function artifact2(path, value) {
|
|
|
73674
74065
|
} catch (error) {
|
|
73675
74066
|
if (error.code !== "EEXIST")
|
|
73676
74067
|
throw error;
|
|
73677
|
-
const info = await
|
|
73678
|
-
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)))
|
|
73679
74070
|
throw new Error("Projected runtime-ignore bytes changed. Restore the original source integration artifacts before retrying.");
|
|
73680
74071
|
}
|
|
73681
74072
|
}
|
|
73682
74073
|
async function projectedPatch(workspace, directory, before, after) {
|
|
73683
|
-
const index =
|
|
74074
|
+
const index = join34(directory, `gitignore-index-${randomUUID15()}`);
|
|
73684
74075
|
const env = { GIT_INDEX_FILE: index };
|
|
73685
74076
|
try {
|
|
73686
74077
|
await parallelGit(workspace, ["read-tree", "--empty"], env);
|
|
@@ -73745,7 +74136,7 @@ async function projectContinuousGitignore(workspace, sourceWorkspace, directory,
|
|
|
73745
74136
|
throw new Error("Runtime-ignore projection requires unchanged UTF-8 ignore-file text. Preserve its bytes and reconcile before retrying.");
|
|
73746
74137
|
}
|
|
73747
74138
|
const blob = async (name, content, mode) => {
|
|
73748
|
-
const path =
|
|
74139
|
+
const path = join34(directory, name);
|
|
73749
74140
|
await artifact2(path, content);
|
|
73750
74141
|
return { mode, oid: (await parallelGit(workspace, ["hash-object", "-w", "--", path])).trim() };
|
|
73751
74142
|
};
|
|
@@ -73769,8 +74160,8 @@ async function projectContinuousGitignore(workspace, sourceWorkspace, directory,
|
|
|
73769
74160
|
|
|
73770
74161
|
// ../../packages/core/src/chief/continuous-workspace.ts
|
|
73771
74162
|
init_zod();
|
|
73772
|
-
import { lstat as
|
|
73773
|
-
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";
|
|
73774
74165
|
async function localDirectory(path) {
|
|
73775
74166
|
await mkdir16(path, { recursive: true, mode: 448 });
|
|
73776
74167
|
if (await realpath21(path) !== resolve24(path))
|
|
@@ -73782,12 +74173,12 @@ async function operationDirectory(repositoryRoot, operationId) {
|
|
|
73782
74173
|
const top = (await parallelGit(root, ["rev-parse", "--show-toplevel"])).trim();
|
|
73783
74174
|
if (root !== resolve24(repositoryRoot) || await realpath21(top) !== root)
|
|
73784
74175
|
throw new Error("Use the operation's original canonical Git repository root before resuming.");
|
|
73785
|
-
const directory =
|
|
74176
|
+
const directory = join35(root, ".agent-valley", "operations", operationId);
|
|
73786
74177
|
await localDirectory(directory);
|
|
73787
74178
|
return directory;
|
|
73788
74179
|
}
|
|
73789
74180
|
async function readJson2(path) {
|
|
73790
|
-
const stats = await
|
|
74181
|
+
const stats = await lstat18(path).catch((error) => {
|
|
73791
74182
|
if (error.code === "ENOENT")
|
|
73792
74183
|
return;
|
|
73793
74184
|
throw error;
|
|
@@ -73796,10 +74187,10 @@ async function readJson2(path) {
|
|
|
73796
74187
|
return;
|
|
73797
74188
|
if (!stats.isFile())
|
|
73798
74189
|
throw new Error("Operation receipts must be regular local files. Restore the original receipt.");
|
|
73799
|
-
return JSON.parse(await
|
|
74190
|
+
return JSON.parse(await readFile15(path, "utf8"));
|
|
73800
74191
|
}
|
|
73801
74192
|
async function assertRepository(path, branch, commit) {
|
|
73802
|
-
if (await realpath21(path) !== path || !(await
|
|
74193
|
+
if (await realpath21(path) !== path || !(await lstat18(join35(path, ".git"))).isDirectory())
|
|
73803
74194
|
throw new Error("Operation workspace must remain an independent local Git repository.");
|
|
73804
74195
|
const [top, currentBranch, head] = await Promise.all([
|
|
73805
74196
|
parallelGit(path, ["rev-parse", "--show-toplevel"]),
|
|
@@ -73814,11 +74205,11 @@ async function prepareContinuousBaseline(repositoryRoot, operationId, sourceWork
|
|
|
73814
74205
|
operationIdSchema.parse(missionId);
|
|
73815
74206
|
if (expectedFingerprint !== undefined && !/^[a-f0-9]{64}$/.test(expectedFingerprint))
|
|
73816
74207
|
throw new Error("Use the completed child's original SHA256 verification fingerprint when accepting a snapshot.");
|
|
73817
|
-
const directory =
|
|
74208
|
+
const directory = join35(await operationDirectory(repositoryRoot, operationId), "baselines", missionId ?? "initial");
|
|
73818
74209
|
await localDirectory(directory);
|
|
73819
|
-
const recordPath =
|
|
73820
|
-
const preparedPath =
|
|
73821
|
-
const path =
|
|
74210
|
+
const recordPath = join35(directory, "baseline.json");
|
|
74211
|
+
const preparedPath = join35(directory, "snapshot.json");
|
|
74212
|
+
const path = join35(directory, "workspace");
|
|
73822
74213
|
const source = await realpath21(sourceWorkspacePath);
|
|
73823
74214
|
const existing = await readJson2(recordPath);
|
|
73824
74215
|
if (existing) {
|
|
@@ -73876,7 +74267,7 @@ async function prepareContinuousBaseline(repositoryRoot, operationId, sourceWork
|
|
|
73876
74267
|
return validateContinuousBaseline(repositoryRoot, operationId, snapshot.path);
|
|
73877
74268
|
}
|
|
73878
74269
|
async function ensureClone(source, path, branch, commit) {
|
|
73879
|
-
const exists = await
|
|
74270
|
+
const exists = await lstat18(path).catch((error) => {
|
|
73880
74271
|
if (error.code === "ENOENT")
|
|
73881
74272
|
return;
|
|
73882
74273
|
throw error;
|
|
@@ -73886,11 +74277,11 @@ async function ensureClone(source, path, branch, commit) {
|
|
|
73886
74277
|
} else if (!exists.isDirectory() || await realpath21(path) !== path) {
|
|
73887
74278
|
throw new Error("Operation workspace path redirects outside its private directory. Restore it before resuming.");
|
|
73888
74279
|
}
|
|
73889
|
-
if (!(await
|
|
74280
|
+
if (!(await lstat18(join35(path, ".git"))).isDirectory() || await realpath21(join35(path, ".git")) !== join35(path, ".git"))
|
|
73890
74281
|
throw new Error("Operation clone Git metadata must remain within its independent private repository.");
|
|
73891
74282
|
const currentBranch = (await parallelGit(path, ["symbolic-ref", "--quiet", "--short", "HEAD"])).trim();
|
|
73892
74283
|
if (currentBranch !== branch) {
|
|
73893
|
-
const index = await
|
|
74284
|
+
const index = await lstat18(join35(path, ".git", "index")).catch(() => {
|
|
73894
74285
|
return;
|
|
73895
74286
|
});
|
|
73896
74287
|
if (index)
|
|
@@ -73908,10 +74299,10 @@ async function validateContinuousBaseline(repositoryRoot, operationId, baselineP
|
|
|
73908
74299
|
const path = resolve24(baselinePath);
|
|
73909
74300
|
const key = dirname7(path).split(/[\\/]/).at(-1) ?? "";
|
|
73910
74301
|
operationIdSchema.parse(key);
|
|
73911
|
-
if (path !==
|
|
74302
|
+
if (path !== join35(root, "baselines", key, "workspace") || await realpath21(dirname7(path)) !== dirname7(path))
|
|
73912
74303
|
throw new Error("Accepted baseline path is outside this operation's private snapshot directory.");
|
|
73913
|
-
const snapshot = continuousBaselineSchema.parse(await readJson2(
|
|
73914
|
-
const expected =
|
|
74304
|
+
const snapshot = continuousBaselineSchema.parse(await readJson2(join35(dirname7(path), "baseline.json")));
|
|
74305
|
+
const expected = join35(root, "baselines", snapshot.missionId ?? "initial", "workspace");
|
|
73915
74306
|
if (snapshot.operationId !== operationId || snapshot.repositoryRoot !== repositoryRoot || snapshot.path !== path || path !== expected || await realpath21(dirname7(path)) !== dirname7(path))
|
|
73916
74307
|
throw new Error("Accepted baseline does not belong to this operation or repository. Restore its original local receipt.");
|
|
73917
74308
|
await assertRepository(path, snapshot.branch, snapshot.commit);
|
|
@@ -73934,11 +74325,11 @@ async function createContinuousMissionWorkspace(repositoryRoot, operationId, bas
|
|
|
73934
74325
|
operationIdSchema.parse(missionId);
|
|
73935
74326
|
const baseline = await validateContinuousBaseline(repositoryRoot, operationId, baselinePath);
|
|
73936
74327
|
const root = await operationDirectory(repositoryRoot, operationId);
|
|
73937
|
-
const directory =
|
|
74328
|
+
const directory = join35(root, "workspaces", missionId);
|
|
73938
74329
|
await localDirectory(directory);
|
|
73939
|
-
const path =
|
|
74330
|
+
const path = join35(directory, "workspace");
|
|
73940
74331
|
const branch = `av-operation/${operationId}/${missionId}`;
|
|
73941
|
-
const recordPath =
|
|
74332
|
+
const recordPath = join35(directory, "workspace.json");
|
|
73942
74333
|
const raw = await readJson2(recordPath);
|
|
73943
74334
|
const record = raw ? missionWorkspaceSchema.parse(raw) : {
|
|
73944
74335
|
operationId,
|
|
@@ -73953,7 +74344,7 @@ async function createContinuousMissionWorkspace(repositoryRoot, operationId, bas
|
|
|
73953
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)
|
|
73954
74345
|
throw new Error("Child workspace identity does not match this operation's saved baseline. Restore its original receipt.");
|
|
73955
74346
|
if (!raw) {
|
|
73956
|
-
const preparedPath =
|
|
74347
|
+
const preparedPath = join35(directory, "prepared.json");
|
|
73957
74348
|
const prepared = await readJson2(preparedPath);
|
|
73958
74349
|
if (prepared && JSON.stringify(missionWorkspaceSchema.parse(prepared)) !== JSON.stringify(record)) {
|
|
73959
74350
|
const saved = missionWorkspaceSchema.parse(prepared);
|
|
@@ -74000,21 +74391,21 @@ var receiptSchema = strictObject({
|
|
|
74000
74391
|
at: exports_iso.datetime().optional()
|
|
74001
74392
|
});
|
|
74002
74393
|
async function localDirectory2(parent, name) {
|
|
74003
|
-
const path =
|
|
74004
|
-
const entry = await
|
|
74394
|
+
const path = join36(parent, name);
|
|
74395
|
+
const entry = await lstat19(path).catch((error) => {
|
|
74005
74396
|
if (error.code === "ENOENT")
|
|
74006
74397
|
return;
|
|
74007
74398
|
throw error;
|
|
74008
74399
|
});
|
|
74009
74400
|
if (!entry)
|
|
74010
74401
|
await mkdir17(path, { mode: 448 });
|
|
74011
|
-
const current = entry ?? await
|
|
74402
|
+
const current = entry ?? await lstat19(path);
|
|
74012
74403
|
if (current.isSymbolicLink() || !current.isDirectory() || await realpath22(path) !== path)
|
|
74013
74404
|
throw new Error("Source integration storage redirects. Restore its original private local directory before retrying.");
|
|
74014
74405
|
return path;
|
|
74015
74406
|
}
|
|
74016
74407
|
async function regularFile(path) {
|
|
74017
|
-
const entry = await
|
|
74408
|
+
const entry = await lstat19(path).catch((error) => {
|
|
74018
74409
|
if (error.code === "ENOENT")
|
|
74019
74410
|
return;
|
|
74020
74411
|
throw error;
|
|
@@ -74023,7 +74414,7 @@ async function regularFile(path) {
|
|
|
74023
74414
|
return;
|
|
74024
74415
|
if (entry.isSymbolicLink() || !entry.isFile())
|
|
74025
74416
|
throw new Error("Source integration receipts must be regular local files. Restore their original bytes before retrying.");
|
|
74026
|
-
return
|
|
74417
|
+
return readFile16(path);
|
|
74027
74418
|
}
|
|
74028
74419
|
async function sourceRoot(repositoryRoot) {
|
|
74029
74420
|
const root = await realpath22(repositoryRoot);
|
|
@@ -74042,8 +74433,8 @@ async function assertSettledSourceIntegrations(repositoryRoot, operationId, pend
|
|
|
74042
74433
|
operationIdSchema.parse(operationId);
|
|
74043
74434
|
let directory = await sourceRoot(repositoryRoot);
|
|
74044
74435
|
for (const part of [".agent-valley", "operations", operationId, "source-integrations"]) {
|
|
74045
|
-
directory =
|
|
74046
|
-
const entry = await
|
|
74436
|
+
directory = join36(directory, part);
|
|
74437
|
+
const entry = await lstat19(directory).catch((error) => {
|
|
74047
74438
|
if (error.code === "ENOENT")
|
|
74048
74439
|
return;
|
|
74049
74440
|
throw error;
|
|
@@ -74053,14 +74444,14 @@ async function assertSettledSourceIntegrations(repositoryRoot, operationId, pend
|
|
|
74053
74444
|
if (entry.isSymbolicLink() || !entry.isDirectory() || await realpath22(directory) !== directory)
|
|
74054
74445
|
throw new Error("Source integration storage redirects. Restore its original private directory before changing modes.");
|
|
74055
74446
|
}
|
|
74056
|
-
for (const entry of await
|
|
74447
|
+
for (const entry of await readdir11(directory, { withFileTypes: true })) {
|
|
74057
74448
|
operationIdSchema.parse(entry.name);
|
|
74058
|
-
const path =
|
|
74449
|
+
const path = join36(directory, entry.name);
|
|
74059
74450
|
if (entry.isSymbolicLink() || !entry.isDirectory() || await realpath22(path) !== path)
|
|
74060
74451
|
throw new Error("Source integration receipt storage redirects. Restore its original directory before changing modes.");
|
|
74061
|
-
const raw = await regularFile(
|
|
74452
|
+
const raw = await regularFile(join36(path, "integration.json"));
|
|
74062
74453
|
if (!raw) {
|
|
74063
|
-
if ((await
|
|
74454
|
+
if ((await readdir11(path)).length)
|
|
74064
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.");
|
|
74065
74456
|
continue;
|
|
74066
74457
|
}
|
|
@@ -74079,8 +74470,8 @@ async function inspectPath(root, path) {
|
|
|
74079
74470
|
let current = root;
|
|
74080
74471
|
const parts = path.split("/");
|
|
74081
74472
|
for (let index = 0;index < parts.length; index += 1) {
|
|
74082
|
-
current =
|
|
74083
|
-
const entry = await
|
|
74473
|
+
current = join36(current, parts[index] ?? "");
|
|
74474
|
+
const entry = await lstat19(current).catch((error) => {
|
|
74084
74475
|
if (error.code === "ENOENT")
|
|
74085
74476
|
return;
|
|
74086
74477
|
throw error;
|
|
@@ -74142,7 +74533,7 @@ async function integrateContinuousSource(operation, previous, next, signal) {
|
|
|
74142
74533
|
throw new Error("Source integration snapshot differs from its original receipt. Restore the accepted baseline before retrying.");
|
|
74143
74534
|
}
|
|
74144
74535
|
const gitDirectory = await realpath22(resolve25(root, (await parallelGit(root, ["rev-parse", "--git-common-dir"])).trim()));
|
|
74145
|
-
const unlock = await lockRecord(
|
|
74536
|
+
const unlock = await lockRecord(join36(gitDirectory, "agent-valley-delivery.lock"), "Source integration", "source-integration");
|
|
74146
74537
|
try {
|
|
74147
74538
|
const assertIdentity = async () => {
|
|
74148
74539
|
signal?.throwIfAborted();
|
|
@@ -74154,8 +74545,8 @@ async function integrateContinuousSource(operation, previous, next, signal) {
|
|
|
74154
74545
|
let directory = root;
|
|
74155
74546
|
for (const part of [".agent-valley", "operations", operation.id, "source-integrations", missionId])
|
|
74156
74547
|
directory = await localDirectory2(directory, part);
|
|
74157
|
-
const recordPath =
|
|
74158
|
-
const patchPath =
|
|
74548
|
+
const recordPath = join36(directory, "integration.json");
|
|
74549
|
+
const patchPath = join36(directory, "changes.patch");
|
|
74159
74550
|
const saved = await regularFile(recordPath);
|
|
74160
74551
|
const before = await parallelTreeImages(next.path, previous.baselineTree);
|
|
74161
74552
|
const after = await parallelTreeImages(next.path, next.baselineTree);
|
|
@@ -74268,7 +74659,7 @@ init_execution();
|
|
|
74268
74659
|
init_runtime_ignore();
|
|
74269
74660
|
|
|
74270
74661
|
// src/chief-continuous-decision.ts
|
|
74271
|
-
import { join as
|
|
74662
|
+
import { join as join49 } from "node:path";
|
|
74272
74663
|
// ../../packages/core/src/chief/coordinator-checkpoint.ts
|
|
74273
74664
|
class CheckpointError extends Error {
|
|
74274
74665
|
}
|
|
@@ -74516,39 +74907,54 @@ function createMissionRun(mission, ports, assertContract, checkAbort, persist =
|
|
|
74516
74907
|
recordHandoffReview(mission, actor, stage, taskId);
|
|
74517
74908
|
checkAbort();
|
|
74518
74909
|
assertContract();
|
|
74519
|
-
|
|
74520
|
-
|
|
74521
|
-
|
|
74522
|
-
|
|
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();
|
|
74523
74918
|
const before = await ports.fingerprint(mission);
|
|
74524
74919
|
checkAbort();
|
|
74525
74920
|
assertContract();
|
|
74526
|
-
|
|
74527
|
-
|
|
74528
|
-
|
|
74529
|
-
|
|
74530
|
-
|
|
74531
|
-
|
|
74532
|
-
|
|
74533
|
-
|
|
74534
|
-
|
|
74535
|
-
|
|
74536
|
-
|
|
74537
|
-
|
|
74538
|
-
|
|
74539
|
-
|
|
74540
|
-
|
|
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
|
+
}
|
|
74541
74943
|
}
|
|
74542
|
-
|
|
74944
|
+
dispatchAdmitted = true;
|
|
74945
|
+
};
|
|
74946
|
+
if (!ports.deferredDispatchAdmission)
|
|
74947
|
+
await beforeDispatch();
|
|
74543
74948
|
let output;
|
|
74544
74949
|
try {
|
|
74545
|
-
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, {
|
|
74546
74951
|
...context,
|
|
74547
74952
|
...taskId ? { taskId } : {},
|
|
74548
|
-
...omaActor ? { omaActor } : {}
|
|
74953
|
+
...omaActor ? { omaActor } : {},
|
|
74954
|
+
...ports.deferredDispatchAdmission ? { beforeDispatch } : {}
|
|
74549
74955
|
}) : await ports.runAgent(actor, prompt, mission, stage);
|
|
74550
74956
|
} catch (error) {
|
|
74551
|
-
if (effect)
|
|
74957
|
+
if (effect && dispatchAdmitted)
|
|
74552
74958
|
effect.effectState = "unknown";
|
|
74553
74959
|
assertNoUncertainExecution(mission);
|
|
74554
74960
|
mission.fingerprint = await ports.fingerprint(mission);
|
|
@@ -74656,17 +75062,17 @@ init_execution();
|
|
|
74656
75062
|
|
|
74657
75063
|
// ../../packages/core/src/chief/runtime.ts
|
|
74658
75064
|
import { randomUUID as randomUUID16 } from "node:crypto";
|
|
74659
|
-
import { join as
|
|
75065
|
+
import { join as join41, resolve as resolve28 } from "node:path";
|
|
74660
75066
|
|
|
74661
75067
|
// ../../packages/core/src/oma/receipt-adapter.ts
|
|
74662
75068
|
import { spawnSync as spawnSync2 } from "node:child_process";
|
|
74663
75069
|
import { existsSync as existsSync4, lstatSync as lstatSync3, readFileSync as readFileSync9 } from "node:fs";
|
|
74664
75070
|
import { mkdir as mkdir18, writeFile as writeFile11 } from "node:fs/promises";
|
|
74665
|
-
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";
|
|
74666
75072
|
|
|
74667
75073
|
// ../../packages/core/src/config/workflow-router.ts
|
|
74668
75074
|
import { readFileSync as readFileSync8 } from "node:fs";
|
|
74669
|
-
import { join as
|
|
75075
|
+
import { join as join37 } from "node:path";
|
|
74670
75076
|
var INFORMATIONAL_WINDOW = 60;
|
|
74671
75077
|
function normalizeForRouting(text) {
|
|
74672
75078
|
return text.normalize("NFKC").toLowerCase().replace(/\s+/g, " ");
|
|
@@ -74833,7 +75239,7 @@ function parseTriggerTable(content) {
|
|
|
74833
75239
|
}
|
|
74834
75240
|
var triggerTableCache = new Map;
|
|
74835
75241
|
function getCachedTriggerTable(rootDir = process.cwd()) {
|
|
74836
|
-
const path =
|
|
75242
|
+
const path = join37(rootDir, ".agents", "hooks", "core", "triggers.json");
|
|
74837
75243
|
let content = null;
|
|
74838
75244
|
try {
|
|
74839
75245
|
content = readFileSync8(path, "utf-8");
|
|
@@ -74981,11 +75387,11 @@ function ensureLatestOmaCli(options = {}) {
|
|
|
74981
75387
|
// ../../packages/core/src/oma/receipt-storage.ts
|
|
74982
75388
|
import { createHash as createHash24 } from "node:crypto";
|
|
74983
75389
|
import { lstatSync as lstatSync2, readdirSync, realpathSync as realpathSync6 } from "node:fs";
|
|
74984
|
-
import { homedir as
|
|
74985
|
-
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";
|
|
74986
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;
|
|
74987
75393
|
function absolutePath(value, key) {
|
|
74988
|
-
if (!
|
|
75394
|
+
if (!isAbsolute14(value) || Array.from(value).some((character) => character.charCodeAt(0) < 32 || character.charCodeAt(0) === 127))
|
|
74989
75395
|
throw new Error(`${key} must be an absolute path without control characters`);
|
|
74990
75396
|
return resolve26(value);
|
|
74991
75397
|
}
|
|
@@ -74994,11 +75400,11 @@ function omaReceiptDirectories(workspace, options = {}) {
|
|
|
74994
75400
|
const profile = env.OMA_PROFILE ?? "0";
|
|
74995
75401
|
if (!/^(0|[1-9][0-9]{0,9})$/.test(profile))
|
|
74996
75402
|
throw new Error("OMA_PROFILE must be a non-negative profile number");
|
|
74997
|
-
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");
|
|
74998
75404
|
const project = createHash24("sha256").update(realpathSync6(resolve26(workspace))).digest("hex");
|
|
74999
75405
|
return [
|
|
75000
|
-
|
|
75001
|
-
...profile === "0" ? [
|
|
75406
|
+
join38(stateHome, "u", profile, "projects", project, "agent-runs"),
|
|
75407
|
+
...profile === "0" ? [join38(resolve26(workspace), ".agents", "state", "agent-runs")] : []
|
|
75002
75408
|
];
|
|
75003
75409
|
}
|
|
75004
75410
|
function regularDirectory(path) {
|
|
@@ -75016,12 +75422,12 @@ function regularDirectory(path) {
|
|
|
75016
75422
|
function validateDirectory(directory, workspace) {
|
|
75017
75423
|
if (!regularDirectory(directory))
|
|
75018
75424
|
return false;
|
|
75019
|
-
const legacy =
|
|
75425
|
+
const legacy = join38(resolve26(workspace), ".agents", "state", "agent-runs");
|
|
75020
75426
|
const boundary = directory === legacy ? resolve26(workspace) : dirname8(dirname8(dirname8(dirname8(dirname8(directory)))));
|
|
75021
75427
|
const components = relative13(boundary, directory).split(sep13).filter(Boolean);
|
|
75022
75428
|
let path = boundary;
|
|
75023
75429
|
for (const component of components) {
|
|
75024
|
-
path =
|
|
75430
|
+
path = join38(path, component);
|
|
75025
75431
|
if (!regularDirectory(path))
|
|
75026
75432
|
throw new Error("OMA receipt directory changed during inspection");
|
|
75027
75433
|
}
|
|
@@ -75031,7 +75437,7 @@ function listOmaRunFiles(workspace, options = {}) {
|
|
|
75031
75437
|
return omaReceiptDirectories(workspace, options).flatMap((directory) => {
|
|
75032
75438
|
if (!validateDirectory(directory, workspace))
|
|
75033
75439
|
return [];
|
|
75034
|
-
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));
|
|
75035
75441
|
});
|
|
75036
75442
|
}
|
|
75037
75443
|
function resolveOmaReceiptPath(workspace, entry, options = {}) {
|
|
@@ -75039,8 +75445,8 @@ function resolveOmaReceiptPath(workspace, entry, options = {}) {
|
|
|
75039
75445
|
if (!name.endsWith(".json") || !OMA_RUN_ID.test(name.slice(0, -5)))
|
|
75040
75446
|
throw new Error("Invalid receipt filename");
|
|
75041
75447
|
if (entry === name)
|
|
75042
|
-
return
|
|
75043
|
-
if (!
|
|
75448
|
+
return join38(resolve26(workspace), ".agents", "state", "agent-runs", name);
|
|
75449
|
+
if (!isAbsolute14(entry) || resolve26(entry) !== entry)
|
|
75044
75450
|
throw new Error("Invalid receipt path");
|
|
75045
75451
|
if (!omaReceiptDirectories(workspace, options).includes(dirname8(entry)))
|
|
75046
75452
|
throw new Error("OMA receipt is outside the selected project/profile");
|
|
@@ -75055,7 +75461,7 @@ var HASH = /^[a-f0-9]{64}$/;
|
|
|
75055
75461
|
function createOmaEvidenceIO(options = {}) {
|
|
75056
75462
|
const env = { ...options.env ?? process.env, OMA_SKIP_VERSION_CHECK: "1" };
|
|
75057
75463
|
if (options.home !== undefined && !env.OMA_HOME)
|
|
75058
|
-
env.OMA_HOME =
|
|
75464
|
+
env.OMA_HOME = join39(options.home, ".oma");
|
|
75059
75465
|
const storage = { ...options, env };
|
|
75060
75466
|
return {
|
|
75061
75467
|
listRunFiles: (workspacePath) => listOmaRunFiles(workspacePath, storage),
|
|
@@ -75102,12 +75508,12 @@ async function prepareOmaAttempt(request, dependencies = {}) {
|
|
|
75102
75508
|
const routed = routeIssue(`${request.issue.title}
|
|
75103
75509
|
${request.issue.description ?? ""}`, table);
|
|
75104
75510
|
for (const workflow of routed.workflows) {
|
|
75105
|
-
const file =
|
|
75511
|
+
const file = join39(request.workspace.path, ".agents", "workflows", `${workflow}.md`);
|
|
75106
75512
|
if (!existsSync4(file))
|
|
75107
75513
|
throw new Error(`OMA workflow file missing in target worktree: ${file}`);
|
|
75108
75514
|
}
|
|
75109
75515
|
await ensureLatestOmaCli({ io: dependencies.latestCliIO });
|
|
75110
|
-
const path =
|
|
75516
|
+
const path = join39(request.workspace.path, ".agents", "results", `plan-${request.attempt.id}.json`);
|
|
75111
75517
|
const plan = {
|
|
75112
75518
|
session_id: request.attempt.id,
|
|
75113
75519
|
lineage_id: request.attempt.id,
|
|
@@ -75132,7 +75538,7 @@ ${request.issue.description ?? ""}`, table);
|
|
|
75132
75538
|
}
|
|
75133
75539
|
]
|
|
75134
75540
|
};
|
|
75135
|
-
await mkdir18(
|
|
75541
|
+
await mkdir18(join39(request.workspace.path, ".agents", "results"), { recursive: true });
|
|
75136
75542
|
await writeFile11(path, JSON.stringify(plan, null, 2), { encoding: "utf-8", flag: "wx" });
|
|
75137
75543
|
return path;
|
|
75138
75544
|
}
|
|
@@ -75241,10 +75647,10 @@ function validateOmaEvidence(request, io = createOmaEvidenceIO()) {
|
|
|
75241
75647
|
const expanded = template.replaceAll("{{attempt.id}}", request.attempt.id);
|
|
75242
75648
|
const target = resolve27(root, expanded);
|
|
75243
75649
|
const subpath = relative14(root, target);
|
|
75244
|
-
if (
|
|
75650
|
+
if (isAbsolute15(expanded) || expanded.split(/[\\/]/).includes("..") || subpath === "" || subpath === ".." || subpath.startsWith(`..${sep14}`) || isAbsolute15(subpath)) {
|
|
75245
75651
|
return fail("Configured analysis report escapes the workspace");
|
|
75246
75652
|
}
|
|
75247
|
-
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)))) {
|
|
75248
75654
|
return fail("OMA receipt does not bind the configured current-attempt report");
|
|
75249
75655
|
}
|
|
75250
75656
|
}
|
|
@@ -75289,7 +75695,7 @@ import { posix } from "node:path";
|
|
|
75289
75695
|
// ../../packages/core/src/oma/skill-matrix-io.ts
|
|
75290
75696
|
init_skill_matrix_schema();
|
|
75291
75697
|
import { execFile as execFile5 } from "node:child_process";
|
|
75292
|
-
import { constants as
|
|
75698
|
+
import { constants as constants13 } from "node:fs";
|
|
75293
75699
|
import { open as open14 } from "node:fs/promises";
|
|
75294
75700
|
var MAX_BYTES = 4 * 1024 * 1024;
|
|
75295
75701
|
async function command(binary, args, signal) {
|
|
@@ -75309,7 +75715,7 @@ async function command(binary, args, signal) {
|
|
|
75309
75715
|
});
|
|
75310
75716
|
}
|
|
75311
75717
|
async function readReport(path) {
|
|
75312
|
-
const file = await open14(path,
|
|
75718
|
+
const file = await open14(path, constants13.O_RDONLY | constants13.O_NOFOLLOW | constants13.O_NONBLOCK);
|
|
75313
75719
|
try {
|
|
75314
75720
|
const info = await file.stat();
|
|
75315
75721
|
if (!info.isFile() || info.size > MAX_BYTES)
|
|
@@ -75492,13 +75898,12 @@ function assertCompatibleRoute(route, inspection) {
|
|
|
75492
75898
|
}
|
|
75493
75899
|
|
|
75494
75900
|
// ../../packages/core/src/chief/runtime.ts
|
|
75495
|
-
init_worktree_lifecycle();
|
|
75496
75901
|
init_execution();
|
|
75497
75902
|
|
|
75498
75903
|
// ../../packages/core/src/chief/parallel-workspace.ts
|
|
75499
75904
|
import { createHash as createHash25 } from "node:crypto";
|
|
75500
|
-
import { lstat as
|
|
75501
|
-
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";
|
|
75502
75907
|
init_parallel_contract();
|
|
75503
75908
|
|
|
75504
75909
|
// ../../packages/core/src/chief/workspace.ts
|
|
@@ -75529,7 +75934,7 @@ function identity3(missionId, taskId, attempt) {
|
|
|
75529
75934
|
async function paths(source, missionId, taskId, attempt) {
|
|
75530
75935
|
const root = await parallelRoot(source);
|
|
75531
75936
|
const key = identity3(missionId, taskId, attempt);
|
|
75532
|
-
const directory =
|
|
75937
|
+
const directory = join40(root, "deliveries", key);
|
|
75533
75938
|
await mkdir19(directory, { recursive: true, mode: 448 });
|
|
75534
75939
|
const actual = await realpath24(directory);
|
|
75535
75940
|
if (actual !== directory)
|
|
@@ -75537,10 +75942,10 @@ async function paths(source, missionId, taskId, attempt) {
|
|
|
75537
75942
|
return {
|
|
75538
75943
|
root,
|
|
75539
75944
|
directory: actual,
|
|
75540
|
-
path:
|
|
75541
|
-
record:
|
|
75542
|
-
delivery:
|
|
75543
|
-
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"),
|
|
75544
75949
|
branch: `av-task/${key}`
|
|
75545
75950
|
};
|
|
75546
75951
|
}
|
|
@@ -75566,7 +75971,7 @@ async function validateWorkspace(mission, workspace) {
|
|
|
75566
75971
|
async function prepareTaskWorktree(mission, taskId, attempt, baseline) {
|
|
75567
75972
|
await assertMissionWorkspace(mission);
|
|
75568
75973
|
const location2 = await paths(mission.workspace.path, mission.id, taskId, attempt);
|
|
75569
|
-
const existing = await
|
|
75974
|
+
const existing = await readFile17(location2.record, "utf8").catch((error) => {
|
|
75570
75975
|
if (error.code === "ENOENT")
|
|
75571
75976
|
return;
|
|
75572
75977
|
throw error;
|
|
@@ -75581,7 +75986,7 @@ async function prepareTaskWorktree(mission, taskId, attempt, baseline) {
|
|
|
75581
75986
|
await mkdir19(dirname10(location2.path), { recursive: true, mode: 448 });
|
|
75582
75987
|
if (await realpath24(dirname10(location2.path)) !== dirname10(location2.path))
|
|
75583
75988
|
throw new Error("Parallel workspaces directory must not redirect through a symlink.");
|
|
75584
|
-
if (await
|
|
75989
|
+
if (await lstat20(location2.path).catch(() => {
|
|
75585
75990
|
return;
|
|
75586
75991
|
}))
|
|
75587
75992
|
throw new Error(`Unrecorded parallel workspace exists at ${location2.path}. Preserve its edits and inspect it before retrying.`);
|
|
@@ -75625,7 +76030,7 @@ async function collectTaskDelivery(mission, workspace) {
|
|
|
75625
76030
|
const location2 = await paths(mission.workspace.path, mission.id, workspace.taskId, workspace.attempt);
|
|
75626
76031
|
if (workspace.path !== location2.path || workspace.branch !== location2.branch)
|
|
75627
76032
|
throw new Error("Restore the recorded private task workspace path and branch before resuming.");
|
|
75628
|
-
const existing = await
|
|
76033
|
+
const existing = await readFile17(location2.delivery, "utf8").catch((error) => {
|
|
75629
76034
|
if (error.code === "ENOENT")
|
|
75630
76035
|
return;
|
|
75631
76036
|
throw error;
|
|
@@ -75661,7 +76066,7 @@ async function collectTaskDelivery(mission, workspace) {
|
|
|
75661
76066
|
try {
|
|
75662
76067
|
await writeFile12(location2.patch, patch, { flag: "wx", mode: 384 });
|
|
75663
76068
|
} catch (error) {
|
|
75664
|
-
if (error.code !== "EEXIST" || !same(await
|
|
76069
|
+
if (error.code !== "EEXIST" || !same(await readFile17(location2.patch, "utf8"), patch))
|
|
75665
76070
|
throw error;
|
|
75666
76071
|
}
|
|
75667
76072
|
const delivery = {
|
|
@@ -75680,7 +76085,7 @@ async function integrateTaskDelivery(mission, input) {
|
|
|
75680
76085
|
await assertMissionWorkspace(mission);
|
|
75681
76086
|
parallelDeliverySchema.parse(input);
|
|
75682
76087
|
const location2 = await paths(mission.workspace.path, mission.id, input.workspace.taskId, input.workspace.attempt);
|
|
75683
|
-
const delivery = parallelDeliverySchema.parse(JSON.parse(await
|
|
76088
|
+
const delivery = parallelDeliverySchema.parse(JSON.parse(await readFile17(location2.delivery, "utf8")));
|
|
75684
76089
|
if (delivery.workspace.missionId !== mission.id || !same(delivery.workspace, input.workspace) || delivery.patchSha256 !== input.patchSha256 || delivery.patchPath !== location2.patch)
|
|
75685
76090
|
throw new Error("Parallel delivery does not match its persisted task identity and patch. Inspect the saved artifacts before recovery.");
|
|
75686
76091
|
const result = await integrateContentTransaction(mission.workspace.path, delivery, {
|
|
@@ -75693,7 +76098,7 @@ async function integrateTaskDelivery(mission, input) {
|
|
|
75693
76098
|
async function disposeTaskWorktree(workspace) {
|
|
75694
76099
|
parallelWorkspaceSchema.parse(workspace);
|
|
75695
76100
|
const location2 = await paths(workspace.sourceWorkspacePath, workspace.missionId, workspace.taskId, workspace.attempt);
|
|
75696
|
-
const raw = await
|
|
76101
|
+
const raw = await readFile17(location2.delivery, "utf8").catch(() => {
|
|
75697
76102
|
return;
|
|
75698
76103
|
});
|
|
75699
76104
|
if (!raw)
|
|
@@ -75708,7 +76113,7 @@ async function disposeTaskWorktree(workspace) {
|
|
|
75708
76113
|
assertParallelPath(location2.root, workspace.path);
|
|
75709
76114
|
if (workspace.path !== location2.path)
|
|
75710
76115
|
throw new Error("Refusing to remove an unrecognized parallel Actor workspace.");
|
|
75711
|
-
if (await
|
|
76116
|
+
if (await lstat20(workspace.path).catch(() => {
|
|
75712
76117
|
return;
|
|
75713
76118
|
})) {
|
|
75714
76119
|
const child = await captureParallelBaseline(workspace.path);
|
|
@@ -75726,8 +76131,34 @@ async function integrateTaskWorktree(mission, workspace) {
|
|
|
75726
76131
|
return integrateTaskDelivery(mission, await collectTaskDelivery(mission, workspace));
|
|
75727
76132
|
}
|
|
75728
76133
|
|
|
75729
|
-
// ../../packages/core/src/chief/runtime.ts
|
|
75730
|
-
|
|
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();
|
|
75731
76162
|
function missionIssue(id, goal) {
|
|
75732
76163
|
return {
|
|
75733
76164
|
id,
|
|
@@ -75747,9 +76178,8 @@ function missionIssue(id, goal) {
|
|
|
75747
76178
|
async function intermediateVerifyCommand(workspacePath) {
|
|
75748
76179
|
const head = await runCommand("git", ["rev-parse", "HEAD"], { cwd: workspacePath });
|
|
75749
76180
|
const hash = head.stdout.trim();
|
|
75750
|
-
if (head.exitCode !== 0 || !/^[a-f0-9]{40,64}$/.test(hash))
|
|
76181
|
+
if (head.exitCode !== 0 || !/^[a-f0-9]{40,64}$/.test(hash))
|
|
75751
76182
|
throw new Error("Cannot bind the OMA task check to its starting commit. Restore the mission worktree's Git HEAD before resuming.");
|
|
75752
|
-
}
|
|
75753
76183
|
return `git diff --check ${hash} --`;
|
|
75754
76184
|
}
|
|
75755
76185
|
async function personaSkills(persona, mission, stage) {
|
|
@@ -75758,9 +76188,8 @@ async function personaSkills(persona, mission, stage) {
|
|
|
75758
76188
|
await validateMissionSkills(mission.workspace.path, catalog);
|
|
75759
76189
|
const selected = await loadMissionSkillBodies(mission.workspace.path, persona.skills, mission.availableAgents ? catalog : undefined);
|
|
75760
76190
|
const guidance = [];
|
|
75761
|
-
if (persona.id === mission.chiefId)
|
|
76191
|
+
if (persona.id === mission.chiefId)
|
|
75762
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.");
|
|
75763
|
-
}
|
|
75764
76193
|
if (selected)
|
|
75765
76194
|
guidance.push("Use these selected skills within the assigned role and acceptance criteria.", selected);
|
|
75766
76195
|
if (guidance.length && stage !== "work")
|
|
@@ -75771,7 +76200,17 @@ ${guidance.join(`
|
|
|
75771
76200
|
|
|
75772
76201
|
`)}` : "";
|
|
75773
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
|
+
}
|
|
75774
76211
|
|
|
76212
|
+
// ../../packages/core/src/chief/runtime.ts
|
|
76213
|
+
init_tool_environment();
|
|
75775
76214
|
class ChiefRuntime {
|
|
75776
76215
|
store;
|
|
75777
76216
|
signal;
|
|
@@ -75795,6 +76234,7 @@ class ChiefRuntime {
|
|
|
75795
76234
|
ports() {
|
|
75796
76235
|
return {
|
|
75797
76236
|
signal: this.signal,
|
|
76237
|
+
deferredDispatchAdmission: true,
|
|
75798
76238
|
...this.discoverReadyAgents ? { discoverReadyAgents: this.discoverReadyAgents } : {},
|
|
75799
76239
|
...this.discoverFreeModels ? { discoverFreeModels: this.discoverFreeModels } : {},
|
|
75800
76240
|
prepareWork: (persona, mission, context) => this.prepareWork(persona, mission, context),
|
|
@@ -75832,7 +76272,7 @@ class ChiefRuntime {
|
|
|
75832
76272
|
const workspace = context?.workspace ?? mission.workspace;
|
|
75833
76273
|
const savedCatalog = workspace === mission.workspace ? mission.availableSkills : mission.availableSkills?.map((skill) => ({
|
|
75834
76274
|
...skill,
|
|
75835
|
-
path:
|
|
76275
|
+
path: join41(workspace.path, ".agents", "skills", skill.name, "SKILL.md")
|
|
75836
76276
|
}));
|
|
75837
76277
|
const catalog = savedCatalog ?? await discoverMissionSkills(workspace.path);
|
|
75838
76278
|
if (!requiresOmaActor({ oma: mission.oma, availableSkills: catalog }))
|
|
@@ -75881,6 +76321,7 @@ class ChiefRuntime {
|
|
|
75881
76321
|
async executeAgent(persona, prompt, mission, stage, context) {
|
|
75882
76322
|
const signal = context?.signal ?? this.signal;
|
|
75883
76323
|
const workspace = context?.workspace ?? mission.workspace;
|
|
76324
|
+
const requestedPersona = persona;
|
|
75884
76325
|
if (stage === "plan" && mission.availableSkills === undefined) {
|
|
75885
76326
|
signal?.throwIfAborted();
|
|
75886
76327
|
mission.availableSkills = await discoverMissionSkills(mission.workspace.path);
|
|
@@ -75890,7 +76331,7 @@ class ChiefRuntime {
|
|
|
75890
76331
|
workspace,
|
|
75891
76332
|
availableSkills: mission.availableSkills?.map((skill) => ({
|
|
75892
76333
|
...skill,
|
|
75893
|
-
path:
|
|
76334
|
+
path: join41(workspace.path, ".agents", "skills", skill.name, "SKILL.md")
|
|
75894
76335
|
}))
|
|
75895
76336
|
};
|
|
75896
76337
|
if (signal?.aborted)
|
|
@@ -75906,13 +76347,12 @@ class ChiefRuntime {
|
|
|
75906
76347
|
message: `${compatibilityPolicy.mode}: ${compatibility.routes.map((entry) => `${entry.actorType}/${entry.model ?? "native default"} ${entry.status}: ${entry.reason}`).join("; ")} Scope: ${compatibility.scope}.`,
|
|
75907
76348
|
...context?.taskId ? { taskId: context.taskId } : {}
|
|
75908
76349
|
});
|
|
75909
|
-
|
|
76350
|
+
let route = context?.handoff ? { actor: persona, reason: context.handoff } : stage === "work" ? selectWorkActor(mission, persona, context?.taskId, compatibleRoutes) : undefined;
|
|
75910
76351
|
persona = route?.actor ?? persona;
|
|
75911
76352
|
if (compatibility && compatibilityPolicy) {
|
|
75912
76353
|
if (compatibilityPolicy.mode === "require")
|
|
75913
76354
|
assertCompatibleRoute({ actorType: persona.agentType, model: persona.model }, compatibility);
|
|
75914
76355
|
}
|
|
75915
|
-
this.onStage(stage, persona);
|
|
75916
76356
|
const attempt = {
|
|
75917
76357
|
id: randomUUID16(),
|
|
75918
76358
|
issueId: mission.id,
|
|
@@ -75935,6 +76375,9 @@ class ChiefRuntime {
|
|
|
75935
76375
|
|
|
75936
76376
|
${buildOmaGuidance(evidence)}`;
|
|
75937
76377
|
}
|
|
76378
|
+
prompt += `
|
|
76379
|
+
|
|
76380
|
+
${unattendedVerificationGuidance(stage)}`;
|
|
75938
76381
|
prompt += omaActor ? `
|
|
75939
76382
|
|
|
75940
76383
|
${omaActor.guidance}` : await personaSkills(persona, localMission, stage);
|
|
@@ -75945,12 +76388,16 @@ The operator explicitly forwards these tool environment variable names: ${JSON.s
|
|
|
75945
76388
|
prompt += `
|
|
75946
76389
|
|
|
75947
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);
|
|
75948
76396
|
if (route)
|
|
75949
76397
|
prompt += `
|
|
75950
76398
|
|
|
75951
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.`;
|
|
75952
|
-
const entry =
|
|
75953
|
-
entry.executionRecovery = this.localExecution ? "local-process" : "reconcile";
|
|
76400
|
+
const entry = await admitNativeDispatch(mission, persona, attempt, stage, context, this.localExecution, route?.reason);
|
|
75954
76401
|
let run;
|
|
75955
76402
|
if (omaActor)
|
|
75956
76403
|
mission.history.push({
|
|
@@ -75997,6 +76444,7 @@ Actual work route: ${JSON.stringify({ actorType: persona.agentType, model: perso
|
|
|
75997
76444
|
throw new AgentRunError("Runtime returned incomplete terminal evidence. Reconcile the execution before resuming.", attempt, { outcomeUnknown: true });
|
|
75998
76445
|
observed = completed;
|
|
75999
76446
|
executionSettled = true;
|
|
76447
|
+
entry.nativeOutcome = completed.exitCode === 0 ? "passed" : "failed";
|
|
76000
76448
|
if (completed.exitCode !== 0)
|
|
76001
76449
|
throw new AgentRunError("Runtime execution did not complete successfully. Inspect the failed attempt before retrying.", completed);
|
|
76002
76450
|
if (mission.oma && stage === "work") {
|
|
@@ -76012,11 +76460,14 @@ Actual work route: ${JSON.stringify({ actorType: persona.agentType, model: perso
|
|
|
76012
76460
|
try {
|
|
76013
76461
|
observed = this.observeAttempt(attempt, error.attempt);
|
|
76014
76462
|
executionSettled = !error.outcomeUnknown;
|
|
76463
|
+
if (executionSettled)
|
|
76464
|
+
entry.nativeOutcome = "failed";
|
|
76015
76465
|
} catch (identityError) {
|
|
76016
76466
|
error = identityError;
|
|
76017
76467
|
}
|
|
76018
76468
|
}
|
|
76019
76469
|
failure = error;
|
|
76470
|
+
entry.evidence = (error instanceof Error ? error.message : String(error)).slice(-2000);
|
|
76020
76471
|
if (error instanceof AgentRunError && error.outcomeUnknown || !this.localExecution && !executionSettled) {
|
|
76021
76472
|
markOperatingRunUnknown(entry, error instanceof Error ? error.message : String(error));
|
|
76022
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");
|
|
@@ -76034,6 +76485,10 @@ Actual work route: ${JSON.stringify({ actorType: persona.agentType, model: perso
|
|
|
76034
76485
|
if (run)
|
|
76035
76486
|
this.runs.delete(run);
|
|
76036
76487
|
finishOperatingRun(mission, entry, observed, failed);
|
|
76488
|
+
if (entry.executionState === "unknown")
|
|
76489
|
+
delete entry.nativeOutcome;
|
|
76490
|
+
else if (signal?.aborted)
|
|
76491
|
+
entry.nativeOutcome = "cancelled";
|
|
76037
76492
|
await this.store.save(mission);
|
|
76038
76493
|
}
|
|
76039
76494
|
if (failed)
|
|
@@ -76560,15 +77015,15 @@ init_execution();
|
|
|
76560
77015
|
|
|
76561
77016
|
// src/chief-supervisor.ts
|
|
76562
77017
|
import { randomUUID as randomUUID17 } from "node:crypto";
|
|
76563
|
-
import { join as
|
|
77018
|
+
import { join as join45 } from "node:path";
|
|
76564
77019
|
init_execution();
|
|
76565
77020
|
// src/chief-delivery.ts
|
|
76566
77021
|
import { createHash as createHash28 } from "node:crypto";
|
|
76567
77022
|
import { mkdir as mkdir21, writeFile as writeFile13 } from "node:fs/promises";
|
|
76568
|
-
import { join as
|
|
77023
|
+
import { join as join44 } from "node:path";
|
|
76569
77024
|
|
|
76570
77025
|
// ../../packages/core/src/chief/report-delivery.ts
|
|
76571
|
-
import { join as
|
|
77026
|
+
import { join as join43 } from "node:path";
|
|
76572
77027
|
|
|
76573
77028
|
// ../../packages/core/src/chief/report-delivery-adapters.ts
|
|
76574
77029
|
init_report_delivery_contract();
|
|
@@ -76951,9 +77406,9 @@ init_zod();
|
|
|
76951
77406
|
init_atomic_json();
|
|
76952
77407
|
init_report_delivery_contract();
|
|
76953
77408
|
import { createHash as createHash27 } from "node:crypto";
|
|
76954
|
-
import { constants as
|
|
76955
|
-
import { mkdir as mkdir20, open as open15, readdir as
|
|
76956
|
-
import { isAbsolute as
|
|
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";
|
|
76957
77412
|
var hash3 = string2().regex(/^[a-f0-9]{64}$/);
|
|
76958
77413
|
var outboxRecordSchema = strictObject({
|
|
76959
77414
|
version: literal(1),
|
|
@@ -76995,12 +77450,12 @@ function receipt(record) {
|
|
|
76995
77450
|
class ReportOutbox {
|
|
76996
77451
|
directory;
|
|
76997
77452
|
constructor(stateDir) {
|
|
76998
|
-
this.directory =
|
|
77453
|
+
this.directory = join42(stateDir, "report-outbox");
|
|
76999
77454
|
}
|
|
77000
77455
|
path(id) {
|
|
77001
77456
|
if (!hash3.safeParse(id).success)
|
|
77002
77457
|
throw new Error("Invalid report receipt ID. Use av reports to find a receipt.");
|
|
77003
|
-
return
|
|
77458
|
+
return join42(this.directory, `${id}.json`);
|
|
77004
77459
|
}
|
|
77005
77460
|
lock(id) {
|
|
77006
77461
|
return new MissionStore(this.directory).lock(id);
|
|
@@ -77008,7 +77463,7 @@ class ReportOutbox {
|
|
|
77008
77463
|
async load(id) {
|
|
77009
77464
|
let content;
|
|
77010
77465
|
try {
|
|
77011
|
-
content = await
|
|
77466
|
+
content = await readFile18(this.path(id), "utf8");
|
|
77012
77467
|
} catch (error) {
|
|
77013
77468
|
if (error.code === "ENOENT")
|
|
77014
77469
|
return null;
|
|
@@ -77029,7 +77484,7 @@ class ReportOutbox {
|
|
|
77029
77484
|
await writeJsonAtomic(this.path(record.id), record);
|
|
77030
77485
|
}
|
|
77031
77486
|
async list() {
|
|
77032
|
-
const names = await
|
|
77487
|
+
const names = await readdir12(this.directory).catch((error) => {
|
|
77033
77488
|
if (error.code === "ENOENT")
|
|
77034
77489
|
return [];
|
|
77035
77490
|
throw new Error("Cannot list report outbox. Restore access to the Chief Director state directory.");
|
|
@@ -77050,11 +77505,11 @@ async function verifiedAttachment(attachment, artifactRoot, readBytes) {
|
|
|
77050
77505
|
const root = await realpath25(artifactRoot);
|
|
77051
77506
|
const path = await realpath25(attachment.path);
|
|
77052
77507
|
const local = relative15(root, path);
|
|
77053
|
-
if (!local || local.startsWith(`..${process.platform === "win32" ? "\\" : "/"}`) || local === ".." ||
|
|
77508
|
+
if (!local || local.startsWith(`..${process.platform === "win32" ? "\\" : "/"}`) || local === ".." || isAbsolute16(local))
|
|
77054
77509
|
throw failure;
|
|
77055
77510
|
if (resolve29(attachment.path) !== attachment.path)
|
|
77056
77511
|
throw failure;
|
|
77057
|
-
const file = await open15(attachment.path,
|
|
77512
|
+
const file = await open15(attachment.path, constants14.O_RDONLY | constants14.O_NOFOLLOW);
|
|
77058
77513
|
try {
|
|
77059
77514
|
const stat = await file.stat();
|
|
77060
77515
|
if (!stat.isFile() || stat.size !== attachment.sizeBytes)
|
|
@@ -77107,7 +77562,7 @@ function dependencies(stateDir, overrides) {
|
|
|
77107
77562
|
env: overrides.env ?? process.env,
|
|
77108
77563
|
registry: { ...createReportChannelRegistry(fetch2), ...overrides.registry },
|
|
77109
77564
|
attachments: overrides.attachments ?? [],
|
|
77110
|
-
artifactRoot: overrides.artifactRoot ??
|
|
77565
|
+
artifactRoot: overrides.artifactRoot ?? join43(stateDir, "captures"),
|
|
77111
77566
|
now: overrides.now ?? (() => new Date)
|
|
77112
77567
|
};
|
|
77113
77568
|
}
|
|
@@ -77288,8 +77743,8 @@ init_chief_schema();
|
|
|
77288
77743
|
init_yaml_loader();
|
|
77289
77744
|
async function saveAndDeliverMissionReport(mission, root) {
|
|
77290
77745
|
const repository = mission.repositoryRoot ?? root;
|
|
77291
|
-
const directory =
|
|
77292
|
-
const reportPath =
|
|
77746
|
+
const directory = join44(root, ".agent-valley/reports");
|
|
77747
|
+
const reportPath = join44(directory, `${mission.id}.md`);
|
|
77293
77748
|
const report = renderReport(mission);
|
|
77294
77749
|
await mkdir21(directory, { recursive: true, mode: 448 });
|
|
77295
77750
|
await writeFile13(reportPath, report, { mode: 384 });
|
|
@@ -77304,12 +77759,12 @@ ${explanation.eli5}`);
|
|
|
77304
77759
|
try {
|
|
77305
77760
|
const config = mergeChiefConfig(loadGlobalConfig()?.chief, loadProjectConfig(root)?.chief);
|
|
77306
77761
|
const attachments = [...mission.capture?.attachments ?? []];
|
|
77307
|
-
const artifactRoot =
|
|
77762
|
+
const artifactRoot = join44(repository, ".agent-valley/captures");
|
|
77308
77763
|
if (config.reporting?.destinations.length) {
|
|
77309
77764
|
const bytes = Buffer.from(report);
|
|
77310
77765
|
const sha256 = createHash28("sha256").update(bytes).digest("hex");
|
|
77311
|
-
const reportDirectory =
|
|
77312
|
-
const attachmentPath =
|
|
77766
|
+
const reportDirectory = join44(artifactRoot, mission.id);
|
|
77767
|
+
const attachmentPath = join44(reportDirectory, `report-${sha256}.md`);
|
|
77313
77768
|
await mkdir21(reportDirectory, { recursive: true, mode: 448 });
|
|
77314
77769
|
await writeFile13(attachmentPath, bytes, { mode: 384 });
|
|
77315
77770
|
attachments.push({
|
|
@@ -77320,7 +77775,7 @@ ${explanation.eli5}`);
|
|
|
77320
77775
|
sha256
|
|
77321
77776
|
});
|
|
77322
77777
|
}
|
|
77323
|
-
const receipts = await dispatchMissionReport(mission, report, reportPath, config.reporting,
|
|
77778
|
+
const receipts = await dispatchMissionReport(mission, report, reportPath, config.reporting, join44(repository, ".agent-valley"), {
|
|
77324
77779
|
attachments,
|
|
77325
77780
|
artifactRoot
|
|
77326
77781
|
});
|
|
@@ -77574,7 +78029,7 @@ function abortableDelay(ms, signal) {
|
|
|
77574
78029
|
async function superviseOrder(goal, options, root, dependencies = {}) {
|
|
77575
78030
|
assertNotManagedRun();
|
|
77576
78031
|
const id = options.resume ?? options.missionId ?? randomUUID17();
|
|
77577
|
-
const store = new MissionStore(
|
|
78032
|
+
const store = new MissionStore(join45(root, ".agent-valley/missions"));
|
|
77578
78033
|
const controller = new AbortController;
|
|
77579
78034
|
const interrupt = () => controller.abort(dependencies.signal?.reason);
|
|
77580
78035
|
const terminate = () => controller.abort(options.service ? serviceShutdownPause() : undefined);
|
|
@@ -77914,8 +78369,8 @@ init_base_session();
|
|
|
77914
78369
|
init_sandbox_binary();
|
|
77915
78370
|
init_agent_discovery();
|
|
77916
78371
|
import { readFileSync as readFileSync10, statSync as statSync4 } from "node:fs";
|
|
77917
|
-
import { homedir as
|
|
77918
|
-
import { join as
|
|
78372
|
+
import { homedir as homedir9 } from "node:os";
|
|
78373
|
+
import { join as join46 } from "node:path";
|
|
77919
78374
|
import { stripVTControlCharacters as stripVTControlCharacters4 } from "node:util";
|
|
77920
78375
|
var MAX_OUTPUT_BYTES5 = 2097152;
|
|
77921
78376
|
var PROBE_TIMEOUT_MS2 = 15000;
|
|
@@ -78040,8 +78495,8 @@ async function discoverFreeModels(agentType, workspacePath, signal, overrides =
|
|
|
78040
78495
|
};
|
|
78041
78496
|
let state;
|
|
78042
78497
|
try {
|
|
78043
|
-
const home = env.XDG_STATE_HOME ||
|
|
78044
|
-
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"));
|
|
78045
78500
|
state = content && Buffer.byteLength(content) <= MAX_OUTPUT_BYTES5 ? JSON.parse(content) : undefined;
|
|
78046
78501
|
} catch {
|
|
78047
78502
|
state = undefined;
|
|
@@ -78070,9 +78525,9 @@ async function discoverFreeModels(agentType, workspacePath, signal, overrides =
|
|
|
78070
78525
|
|
|
78071
78526
|
// ../../packages/core/src/chief/metric-source-adapters.ts
|
|
78072
78527
|
init_metric_source_policy();
|
|
78073
|
-
import { constants as
|
|
78074
|
-
import { lstat as
|
|
78075
|
-
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";
|
|
78076
78531
|
var MAX_METRIC_RESPONSE_BYTES = 2000000;
|
|
78077
78532
|
function metricSourceEnvironment(request, name) {
|
|
78078
78533
|
if (!name || !request.env[name]?.trim())
|
|
@@ -78157,19 +78612,19 @@ var jsonFileMetricAdapter = {
|
|
|
78157
78612
|
async collect(request) {
|
|
78158
78613
|
const root = await realpath26(request.repositoryRoot);
|
|
78159
78614
|
const name = request.source.file;
|
|
78160
|
-
if (!name ||
|
|
78615
|
+
if (!name || isAbsolute17(name))
|
|
78161
78616
|
throw new MetricSourceError("Metric file must be relative to the source repository. Set chief.metric_sources.sources[].file in av.yaml.");
|
|
78162
78617
|
const path = resolve30(root, name);
|
|
78163
78618
|
const within = relative16(root, path);
|
|
78164
|
-
if (!within || within.startsWith(`..${sep16}`) || within === ".." ||
|
|
78619
|
+
if (!within || within.startsWith(`..${sep16}`) || within === ".." || isAbsolute17(within))
|
|
78165
78620
|
throw new MetricSourceError("Metric file escapes the source repository. Choose a repository-relative JSON file.");
|
|
78166
78621
|
let current = root;
|
|
78167
78622
|
for (const part of within.split(sep16)) {
|
|
78168
78623
|
current = resolve30(current, part);
|
|
78169
|
-
if ((await
|
|
78624
|
+
if ((await lstat21(current)).isSymbolicLink())
|
|
78170
78625
|
throw new MetricSourceError("Metric file and parent directories must not be symlinks. Choose a regular JSON file inside the source repository.");
|
|
78171
78626
|
}
|
|
78172
|
-
const file = await open16(path,
|
|
78627
|
+
const file = await open16(path, constants15.O_RDONLY | constants15.O_NOFOLLOW);
|
|
78173
78628
|
try {
|
|
78174
78629
|
const stat = await file.stat();
|
|
78175
78630
|
if (!stat.isFile() || stat.size > MAX_METRIC_RESPONSE_BYTES || await realpath26(path) !== path)
|
|
@@ -78570,9 +79025,9 @@ function createMissionMetricPorts(repository, mission, dependencies = {}) {
|
|
|
78570
79025
|
|
|
78571
79026
|
// src/chief-tool-config.ts
|
|
78572
79027
|
import { randomUUID as randomUUID19 } from "node:crypto";
|
|
78573
|
-
import { constants as
|
|
78574
|
-
import { link as link2, lstat as
|
|
78575
|
-
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";
|
|
78576
79031
|
init_dist2();
|
|
78577
79032
|
init_client_toml();
|
|
78578
79033
|
var maximumBytes = 1024 * 1024;
|
|
@@ -78591,8 +79046,8 @@ async function assertLocalPath(root, local) {
|
|
|
78591
79046
|
const parts = local.split("/");
|
|
78592
79047
|
let current = root;
|
|
78593
79048
|
for (const [index, part] of parts.entries()) {
|
|
78594
|
-
current =
|
|
78595
|
-
const stats = await
|
|
79049
|
+
current = join47(current, part);
|
|
79050
|
+
const stats = await lstat22(current).catch((error) => {
|
|
78596
79051
|
if (error.code === "ENOENT")
|
|
78597
79052
|
return;
|
|
78598
79053
|
throw error;
|
|
@@ -78605,7 +79060,7 @@ async function assertLocalPath(root, local) {
|
|
|
78605
79060
|
return true;
|
|
78606
79061
|
}
|
|
78607
79062
|
async function readPrivateFile(path) {
|
|
78608
|
-
const file = await open17(path,
|
|
79063
|
+
const file = await open17(path, constants16.O_RDONLY | constants16.O_NOFOLLOW);
|
|
78609
79064
|
try {
|
|
78610
79065
|
const stats = await file.stat();
|
|
78611
79066
|
if (!stats.isFile() || stats.size > maximumBytes)
|
|
@@ -78648,10 +79103,10 @@ async function privateExclude(original, target, paths) {
|
|
|
78648
79103
|
]);
|
|
78649
79104
|
const common = targetCommon.trim();
|
|
78650
79105
|
const path = exclude.trim();
|
|
78651
|
-
if (common !==
|
|
79106
|
+
if (common !== join47(target, ".git") && common !== originalCommon.trim() || path !== join47(common, "info", "exclude") || await realpath27(common) !== common)
|
|
78652
79107
|
throw new ChiefToolConfigError("Chief MCP configuration requires the workspace's own Git metadata or its original repository's shared worktree metadata.");
|
|
78653
|
-
const info =
|
|
78654
|
-
const infoStats = await
|
|
79108
|
+
const info = join47(common, "info");
|
|
79109
|
+
const infoStats = await lstat22(info).catch((error) => {
|
|
78655
79110
|
if (error.code === "ENOENT")
|
|
78656
79111
|
return;
|
|
78657
79112
|
throw error;
|
|
@@ -78668,7 +79123,7 @@ async function privateExclude(original, target, paths) {
|
|
|
78668
79123
|
const patterns = paths.flatMap((local) => [`/${local}`, `/${local}.av-mcp-*.tmp`]).filter((pattern) => !lines.has(pattern));
|
|
78669
79124
|
if (!patterns.length)
|
|
78670
79125
|
return;
|
|
78671
|
-
const file = await open17(path,
|
|
79126
|
+
const file = await open17(path, constants16.O_WRONLY | constants16.O_APPEND | constants16.O_CREAT | constants16.O_NOFOLLOW, 384);
|
|
78672
79127
|
try {
|
|
78673
79128
|
await file.writeFile(`${content && !content.endsWith(`
|
|
78674
79129
|
`) ? `
|
|
@@ -78689,14 +79144,14 @@ async function prepareToolConfig(originalRepository, targetWorkspace) {
|
|
|
78689
79144
|
continue;
|
|
78690
79145
|
if (!await assertLocalPath(original, config.path))
|
|
78691
79146
|
continue;
|
|
78692
|
-
const content = selectedNamespace(await readPrivateFile(
|
|
79147
|
+
const content = selectedNamespace(await readPrivateFile(join47(original, config.path)), config.namespace, config.toml);
|
|
78693
79148
|
if (content)
|
|
78694
79149
|
selected.push({ path: config.path, content });
|
|
78695
79150
|
}
|
|
78696
79151
|
if (!selected.length)
|
|
78697
79152
|
return;
|
|
78698
79153
|
for (const root of [original, target]) {
|
|
78699
|
-
const stats = await
|
|
79154
|
+
const stats = await lstat22(join47(root, ".git"));
|
|
78700
79155
|
if (stats.isSymbolicLink() || !stats.isFile() && !stats.isDirectory() || await realpath27((await parallelGit(root, ["rev-parse", "--show-toplevel"])).trim()) !== root)
|
|
78701
79156
|
throw new ChiefToolConfigError("Chief MCP tools require original local Git repository metadata. Restore the workspace before starting Chief.");
|
|
78702
79157
|
}
|
|
@@ -78704,14 +79159,14 @@ async function prepareToolConfig(originalRepository, targetWorkspace) {
|
|
|
78704
79159
|
for (const config of selected) {
|
|
78705
79160
|
const parts = config.path.split("/");
|
|
78706
79161
|
if (parts.length > 1) {
|
|
78707
|
-
const parent =
|
|
79162
|
+
const parent = join47(target, ...parts.slice(0, -1));
|
|
78708
79163
|
await mkdir22(parent, { recursive: true, mode: 448 });
|
|
78709
79164
|
if (await realpath27(parent) !== parent)
|
|
78710
79165
|
throw new ChiefToolConfigError("Chief MCP configuration parent redirects through a symlink. Restore its local directory.");
|
|
78711
79166
|
}
|
|
78712
79167
|
if (await assertLocalPath(target, config.path))
|
|
78713
79168
|
continue;
|
|
78714
|
-
const path =
|
|
79169
|
+
const path = join47(target, config.path);
|
|
78715
79170
|
const temporary = `${path}.av-mcp-${randomUUID19()}.tmp`;
|
|
78716
79171
|
const file = await open17(temporary, "wx", 384);
|
|
78717
79172
|
try {
|
|
@@ -78742,10 +79197,10 @@ async function prepareChiefToolConfig(originalRepository, targetWorkspace) {
|
|
|
78742
79197
|
|
|
78743
79198
|
// src/tool-discovery.ts
|
|
78744
79199
|
init_client_toml();
|
|
78745
|
-
import { constants as
|
|
78746
|
-
import { access, lstat as
|
|
78747
|
-
import { homedir as
|
|
78748
|
-
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";
|
|
78749
79204
|
var binaries = [
|
|
78750
79205
|
"docker",
|
|
78751
79206
|
"orb",
|
|
@@ -78760,12 +79215,12 @@ var binaries = [
|
|
|
78760
79215
|
];
|
|
78761
79216
|
var MAX_CONFIG_BYTES = 1048576;
|
|
78762
79217
|
var record5 = (value) => value !== null && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
78763
|
-
async function
|
|
78764
|
-
for (const directory of (env.PATH ?? "").split(
|
|
79218
|
+
async function executable2(name, env) {
|
|
79219
|
+
for (const directory of (env.PATH ?? "").split(delimiter3).filter(isAbsolute18)) {
|
|
78765
79220
|
try {
|
|
78766
|
-
const path =
|
|
78767
|
-
await
|
|
78768
|
-
if ((await
|
|
79221
|
+
const path = join48(directory, name);
|
|
79222
|
+
await access2(path, constants17.X_OK);
|
|
79223
|
+
if ((await lstat23(await realpath28(path))).isFile())
|
|
78769
79224
|
return true;
|
|
78770
79225
|
} catch {}
|
|
78771
79226
|
}
|
|
@@ -78774,10 +79229,10 @@ async function executable(name, env) {
|
|
|
78774
79229
|
async function mcpNames(path, scope, project, requestedRoot) {
|
|
78775
79230
|
const base = { kind: "mcp", scope, authentication: "unknown", source: path };
|
|
78776
79231
|
try {
|
|
78777
|
-
const info = await
|
|
79232
|
+
const info = await lstat23(path);
|
|
78778
79233
|
if (!info.isFile() || info.isSymbolicLink() || info.size > MAX_CONFIG_BYTES)
|
|
78779
79234
|
throw new Error("Invalid config");
|
|
78780
|
-
const source = await
|
|
79235
|
+
const source = await readFile19(path, "utf8");
|
|
78781
79236
|
if (Buffer.byteLength(source) > MAX_CONFIG_BYTES)
|
|
78782
79237
|
throw new Error("Invalid config");
|
|
78783
79238
|
const config = record5(path.endsWith(".toml") ? parseClientToml(source) : JSON.parse(source));
|
|
@@ -78817,7 +79272,7 @@ async function mcpNames(path, scope, project, requestedRoot) {
|
|
|
78817
79272
|
}
|
|
78818
79273
|
async function discoverTools(root, dependencies = {}) {
|
|
78819
79274
|
const env = dependencies.env ?? process.env;
|
|
78820
|
-
const home = dependencies.home ??
|
|
79275
|
+
const home = dependencies.home ?? homedir10();
|
|
78821
79276
|
const project = await realpath28(root);
|
|
78822
79277
|
const projectFiles = [
|
|
78823
79278
|
".mcp.json",
|
|
@@ -78828,11 +79283,11 @@ async function discoverTools(root, dependencies = {}) {
|
|
|
78828
79283
|
".codex/config.toml"
|
|
78829
79284
|
];
|
|
78830
79285
|
const userFiles = [".claude.json", ".cursor/mcp.json", ".qwen/settings.json", ".gemini/settings.json"];
|
|
78831
|
-
const codexHome = env.CODEX_HOME &&
|
|
79286
|
+
const codexHome = env.CODEX_HOME && isAbsolute18(env.CODEX_HOME) ? env.CODEX_HOME : join48(home, ".codex");
|
|
78832
79287
|
const configs = [
|
|
78833
|
-
...projectFiles.map((path) => ({ path:
|
|
79288
|
+
...projectFiles.map((path) => ({ path: join48(project, path), scope: "project" })),
|
|
78834
79289
|
...userFiles.map((path) => ({ path: resolve31(home, path), scope: "user" })),
|
|
78835
|
-
{ path:
|
|
79290
|
+
{ path: join48(codexHome, "config.toml"), scope: "user" }
|
|
78836
79291
|
];
|
|
78837
79292
|
const [cli, mcp] = await Promise.all([
|
|
78838
79293
|
Promise.all(binaries.map(async (name) => ({
|
|
@@ -78841,7 +79296,7 @@ async function discoverTools(root, dependencies = {}) {
|
|
|
78841
79296
|
kind: "cli",
|
|
78842
79297
|
scope: "user",
|
|
78843
79298
|
authentication: "unknown",
|
|
78844
|
-
availability: await
|
|
79299
|
+
availability: await executable2(name, env) ? "available" : "unavailable",
|
|
78845
79300
|
reason: "Executable presence only; service access, daemon state and login are unverified."
|
|
78846
79301
|
}))),
|
|
78847
79302
|
Promise.all(configs.map(({ path, scope }) => mcpNames(path, scope, project, resolve31(root))))
|
|
@@ -78879,7 +79334,7 @@ function continuousDecisionPrompt(operation, mission, tools, previousReport) {
|
|
|
78879
79334
|
async function decideContinuousGoal(operation, decisionId, root, dependencies = {}) {
|
|
78880
79335
|
if (!operation.baseline)
|
|
78881
79336
|
throw new Error("An accepted operation baseline is required before selecting a goal.");
|
|
78882
|
-
const store = new MissionStore(
|
|
79337
|
+
const store = new MissionStore(join49(root, ".agent-valley", "operation-decisions", operation.id));
|
|
78883
79338
|
const unlock = await store.lock(decisionId);
|
|
78884
79339
|
const runtime = (dependencies.runtime ?? ((storage, signal) => new ChiefRuntime(storage, signal, undefined, undefined, undefined, discoverReadyAgents, discoverFreeModels)))(store, dependencies.signal);
|
|
78885
79340
|
let mission;
|
|
@@ -78992,7 +79447,7 @@ async function decideContinuousGoal(operation, decisionId, root, dependencies =
|
|
|
78992
79447
|
const previousId = operation.history.at(-1)?.missionId;
|
|
78993
79448
|
let previousReport;
|
|
78994
79449
|
if (previousId) {
|
|
78995
|
-
const previous = await new MissionStore(
|
|
79450
|
+
const previous = await new MissionStore(join49(root, ".agent-valley", "missions")).load(previousId);
|
|
78996
79451
|
if (previous.repositoryRoot !== operation.repositoryRoot || previous.status !== "completed")
|
|
78997
79452
|
throw new Error("The previous accepted child's evidence no longer matches this operation. Restore its saved checkpoint before selecting another goal.");
|
|
78998
79453
|
previousReport = renderReport(previous).slice(0, 16000);
|
|
@@ -79031,7 +79486,7 @@ async function decideContinuousGoal(operation, decisionId, root, dependencies =
|
|
|
79031
79486
|
|
|
79032
79487
|
// src/chief-continuous-report.ts
|
|
79033
79488
|
import { mkdir as mkdir23 } from "node:fs/promises";
|
|
79034
|
-
import { join as
|
|
79489
|
+
import { join as join50 } from "node:path";
|
|
79035
79490
|
init_atomic_json();
|
|
79036
79491
|
function operationDeliveryLines(operation, delivery, unavailable = false) {
|
|
79037
79492
|
const integration = operation.sourceIntegration;
|
|
@@ -79090,17 +79545,17 @@ function renderOperationReport(operation, delivery, unavailable = false) {
|
|
|
79090
79545
|
`);
|
|
79091
79546
|
}
|
|
79092
79547
|
async function saveOperationReport(root, operation) {
|
|
79093
|
-
const directory =
|
|
79548
|
+
const directory = join50(root, ".agent-valley", "operation-reports");
|
|
79094
79549
|
await mkdir23(directory, { recursive: true, mode: 448 });
|
|
79095
79550
|
const evidence = await deliveryFor(root, operation);
|
|
79096
|
-
await writeTextAtomic(
|
|
79551
|
+
await writeTextAtomic(join50(directory, `${operation.id}.md`), renderOperationReport(operation, evidence.delivery, evidence.unavailable));
|
|
79097
79552
|
}
|
|
79098
79553
|
async function deliveryFor(root, operation) {
|
|
79099
79554
|
const id = operation.currentMissionId ?? operation.history.at(-1)?.missionId;
|
|
79100
79555
|
if (!id)
|
|
79101
79556
|
return {};
|
|
79102
79557
|
try {
|
|
79103
|
-
const mission = await new MissionStore(
|
|
79558
|
+
const mission = await new MissionStore(join50(root, ".agent-valley", "missions")).load(id);
|
|
79104
79559
|
return mission.repositoryRoot === operation.repositoryRoot ? { delivery: mission.codeDelivery } : { unavailable: true };
|
|
79105
79560
|
} catch {
|
|
79106
79561
|
return { unavailable: true };
|
|
@@ -79133,7 +79588,7 @@ function createOperationProgressReporter(root, write = console.log) {
|
|
|
79133
79588
|
};
|
|
79134
79589
|
}
|
|
79135
79590
|
// src/chief-source-integration.ts
|
|
79136
|
-
import { join as
|
|
79591
|
+
import { join as join51 } from "node:path";
|
|
79137
79592
|
init_execution();
|
|
79138
79593
|
function sourceIntegrationCheckpoint(operation) {
|
|
79139
79594
|
const accepted = operation.baseline;
|
|
@@ -79156,7 +79611,7 @@ async function initialSourceIntegration(repositoryRoot, id, mode, remoteDelivery
|
|
|
79156
79611
|
async function assertChildSettled(operation, storageRoot) {
|
|
79157
79612
|
if (!operation.currentMissionId)
|
|
79158
79613
|
return;
|
|
79159
|
-
const missions = new MissionStore(
|
|
79614
|
+
const missions = new MissionStore(join51(storageRoot, ".agent-valley", "missions"));
|
|
79160
79615
|
if (await missions.isLocked(operation.currentMissionId))
|
|
79161
79616
|
throw new Error("The current child is still owned by another coordinator. Resume source integration after its checkpoint is settled.");
|
|
79162
79617
|
const child = await missions.load(operation.currentMissionId).catch((error) => {
|
|
@@ -79178,7 +79633,7 @@ async function resumeSourceIntegration(operation, mode, storageRoot, signal, sav
|
|
|
79178
79633
|
if (selected !== "snapshot-only")
|
|
79179
79634
|
throw new Error("This operation already uses explicit commit and push delivery. Keep its saved delivery policy instead of adding worktree application.");
|
|
79180
79635
|
}
|
|
79181
|
-
const persist = save ?? ((current) => new ContinuousOperationStore(
|
|
79636
|
+
const persist = save ?? ((current) => new ContinuousOperationStore(join51(storageRoot, ".agent-valley", "operations")).save(current));
|
|
79182
79637
|
const { accepted, applied, caughtUp, pendingIds } = sourceIntegrationCheckpoint(operation);
|
|
79183
79638
|
const activation = selected === "worktree" && operation.sourceIntegrationPolicy?.mode !== "worktree";
|
|
79184
79639
|
if (activation) {
|
|
@@ -79216,7 +79671,7 @@ async function resumeSourceIntegration(operation, mode, storageRoot, signal, sav
|
|
|
79216
79671
|
if (policy?.mode === "worktree" && accepted?.missionId && (applied?.missionId !== accepted.missionId || applied.nextTree !== accepted.baselineTree)) {
|
|
79217
79672
|
if (applied?.missionId === accepted.missionId)
|
|
79218
79673
|
throw new Error("The saved source application summary differs from its accepted snapshot. Restore the original verified receipt before resuming.");
|
|
79219
|
-
const previous = await validateContinuousBaseline(operation.repositoryRoot, operation.id,
|
|
79674
|
+
const previous = await validateContinuousBaseline(operation.repositoryRoot, operation.id, join51(operation.repositoryRoot, ".agent-valley", "operations", operation.id, "baselines", applied?.missionId ?? "initial", "workspace"));
|
|
79220
79675
|
if (applied && previous.baselineTree !== applied.nextTree)
|
|
79221
79676
|
throw new Error("The last applied source snapshot no longer matches its saved summary. Restore its original baseline before resuming.");
|
|
79222
79677
|
operation.sourceIntegration = await integrateContinuousSource(operation, previous, accepted, signal);
|
|
@@ -79241,9 +79696,9 @@ import { realpath as realpath30 } from "node:fs/promises";
|
|
|
79241
79696
|
// ../../packages/core/src/chief/continuous-retention.ts
|
|
79242
79697
|
init_zod();
|
|
79243
79698
|
import { createHash as createHash29 } from "node:crypto";
|
|
79244
|
-
import { constants as
|
|
79245
|
-
import { lstat as
|
|
79246
|
-
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";
|
|
79247
79702
|
var digest7 = (content) => createHash29("sha256").update(content).digest("hex");
|
|
79248
79703
|
var sha2 = string2().regex(/^[a-f0-9]{40,64}$/);
|
|
79249
79704
|
var preparedSchema = strictObject({
|
|
@@ -79267,7 +79722,7 @@ var completedSchema = strictObject({
|
|
|
79267
79722
|
});
|
|
79268
79723
|
async function exists(path) {
|
|
79269
79724
|
try {
|
|
79270
|
-
await
|
|
79725
|
+
await lstat24(path);
|
|
79271
79726
|
return true;
|
|
79272
79727
|
} catch (error) {
|
|
79273
79728
|
if (error.code === "ENOENT")
|
|
@@ -79276,13 +79731,13 @@ async function exists(path) {
|
|
|
79276
79731
|
}
|
|
79277
79732
|
}
|
|
79278
79733
|
async function localDirectory3(path) {
|
|
79279
|
-
if (!(await
|
|
79734
|
+
if (!(await lstat24(path)).isDirectory() || await realpath29(path) !== resolve32(path))
|
|
79280
79735
|
throw new Error("Pruning requires canonical local directories. Preserve redirected artifacts and restore their original paths.");
|
|
79281
79736
|
}
|
|
79282
79737
|
async function readLocal(path) {
|
|
79283
79738
|
let handle;
|
|
79284
79739
|
try {
|
|
79285
|
-
handle = await open18(path,
|
|
79740
|
+
handle = await open18(path, constants18.O_RDONLY | (constants18.O_NOFOLLOW ?? 0) | (constants18.O_NONBLOCK ?? 0));
|
|
79286
79741
|
const stat = await handle.stat();
|
|
79287
79742
|
if (!stat.isFile() || stat.size > 16777216)
|
|
79288
79743
|
throw new Error("Unsupported local pruning receipt.");
|
|
@@ -79314,7 +79769,7 @@ async function independentGitMetadata(path) {
|
|
|
79314
79769
|
const directory = pending.pop();
|
|
79315
79770
|
if (!directory)
|
|
79316
79771
|
break;
|
|
79317
|
-
for (const entry of await
|
|
79772
|
+
for (const entry of await readdir13(directory, { withFileTypes: true })) {
|
|
79318
79773
|
if (++entries > 1e5)
|
|
79319
79774
|
throw new Error("Git metadata inspection exceeded its bound; retain this clone.");
|
|
79320
79775
|
if (entry.name.endsWith(".lock"))
|
|
@@ -79322,29 +79777,29 @@ async function independentGitMetadata(path) {
|
|
|
79322
79777
|
if (entry.isSymbolicLink())
|
|
79323
79778
|
throw new Error("Git metadata redirects through a symbolic link.");
|
|
79324
79779
|
if (entry.isDirectory())
|
|
79325
|
-
pending.push(
|
|
79780
|
+
pending.push(join52(directory, entry.name));
|
|
79326
79781
|
else if (!entry.isFile())
|
|
79327
79782
|
throw new Error("Git metadata contains an unsupported file type; preserve this clone.");
|
|
79328
79783
|
}
|
|
79329
79784
|
}
|
|
79330
79785
|
}
|
|
79331
79786
|
async function emptyScratch(path, depth = 0) {
|
|
79332
|
-
if (depth > 8 || !(await
|
|
79787
|
+
if (depth > 8 || !(await lstat24(path)).isDirectory() || await realpath29(path) !== path)
|
|
79333
79788
|
return false;
|
|
79334
|
-
const entries = await
|
|
79789
|
+
const entries = await readdir13(path);
|
|
79335
79790
|
if (entries.length > 100)
|
|
79336
79791
|
return false;
|
|
79337
79792
|
for (const name of entries)
|
|
79338
|
-
if (!await emptyScratch(
|
|
79793
|
+
if (!await emptyScratch(join52(path, name), depth + 1))
|
|
79339
79794
|
return false;
|
|
79340
79795
|
return true;
|
|
79341
79796
|
}
|
|
79342
79797
|
async function inspectClone(path, baseline) {
|
|
79343
79798
|
await localDirectory3(path);
|
|
79344
|
-
await localDirectory3(
|
|
79345
|
-
await independentGitMetadata(
|
|
79799
|
+
await localDirectory3(join52(path, ".git"));
|
|
79800
|
+
await independentGitMetadata(join52(path, ".git"));
|
|
79346
79801
|
for (const key of ["commondir", "objects/info/alternates", "objects/info/http-alternates", "info/grafts", "shallow"])
|
|
79347
|
-
if (await exists(
|
|
79802
|
+
if (await exists(join52(path, ".git", key)))
|
|
79348
79803
|
throw new Error("Git metadata depends on another repository.");
|
|
79349
79804
|
const [top, branch, head, refs, status, worktrees, remotes] = await Promise.all([
|
|
79350
79805
|
git(path, ["rev-parse", "--show-toplevel"]),
|
|
@@ -79369,7 +79824,7 @@ async function inspectClone(path, baseline) {
|
|
|
79369
79824
|
`) !== `worktree ${path}`)
|
|
79370
79825
|
throw new Error("Frozen baseline has linked worktrees.");
|
|
79371
79826
|
for (const entry of status.split("\x00").filter(Boolean)) {
|
|
79372
|
-
if (entry === "!! .agent-valley/" && await emptyScratch(
|
|
79827
|
+
if (entry === "!! .agent-valley/" && await emptyScratch(join52(path, ".agent-valley")))
|
|
79373
79828
|
continue;
|
|
79374
79829
|
throw new Error("Frozen baseline has tracked, untracked or ignored changes.");
|
|
79375
79830
|
}
|
|
@@ -79402,22 +79857,22 @@ async function recoverable(current, baseline) {
|
|
|
79402
79857
|
throw new Error("The current baseline is missing recovery objects.");
|
|
79403
79858
|
}
|
|
79404
79859
|
async function processEvidence(storePath, missionId) {
|
|
79405
|
-
if (await exists(
|
|
79860
|
+
if (await exists(join52(storePath, `${missionId}.json.lock`)))
|
|
79406
79861
|
return true;
|
|
79407
|
-
if (await exists(
|
|
79862
|
+
if (await exists(join52(storePath, `${missionId}.json.lock.reclaim`)))
|
|
79408
79863
|
return true;
|
|
79409
|
-
return (await
|
|
79864
|
+
return (await readdir13(storePath)).some((name) => name === `${missionId}.active` || name.startsWith(`${missionId}.run-`) && name.endsWith(".active"));
|
|
79410
79865
|
}
|
|
79411
79866
|
async function protectMissionBaseline(mission, protectedPaths) {
|
|
79412
79867
|
if (!mission.repositoryRoot)
|
|
79413
79868
|
throw new Error("An unresolved mission has no repository identity; preserve all baselines.");
|
|
79414
79869
|
protectedPaths.add(mission.workspace.path);
|
|
79415
79870
|
const workspace = mission.workspace.path;
|
|
79416
|
-
const prefix =
|
|
79871
|
+
const prefix = join52(mission.repositoryRoot, ".agent-valley", "operations");
|
|
79417
79872
|
if (!workspace.startsWith(`${prefix}/`))
|
|
79418
79873
|
return;
|
|
79419
79874
|
await localDirectory3(dirname11(workspace));
|
|
79420
|
-
const raw = await readLocal(
|
|
79875
|
+
const raw = await readLocal(join52(dirname11(workspace), "workspace.json"));
|
|
79421
79876
|
if (!raw)
|
|
79422
79877
|
throw new Error("An unresolved mission is missing its workspace receipt; preserve all baselines.");
|
|
79423
79878
|
const value = JSON.parse(raw);
|
|
@@ -79427,37 +79882,37 @@ async function protectMissionBaseline(mission, protectedPaths) {
|
|
|
79427
79882
|
}
|
|
79428
79883
|
async function referencedBaselines(storageRoot, operations) {
|
|
79429
79884
|
const protectedPaths = new Set;
|
|
79430
|
-
const missionDirectories = [
|
|
79885
|
+
const missionDirectories = [join52(storageRoot, ".agent-valley", "missions")];
|
|
79431
79886
|
for (const operation of operations) {
|
|
79432
79887
|
if (operation.baseline)
|
|
79433
79888
|
protectedPaths.add(operation.baseline.path);
|
|
79434
79889
|
if (operation.sourceIntegration)
|
|
79435
|
-
protectedPaths.add(
|
|
79890
|
+
protectedPaths.add(join52(operation.repositoryRoot, ".agent-valley", "operations", operation.id, "baselines", operation.sourceIntegration.missionId, "workspace"));
|
|
79436
79891
|
for (const id of [operation.currentMissionId, operation.decisionId]) {
|
|
79437
79892
|
if (!id)
|
|
79438
79893
|
continue;
|
|
79439
|
-
const container =
|
|
79894
|
+
const container = join52(operation.repositoryRoot, ".agent-valley", "operations", operation.id, "workspaces", id);
|
|
79440
79895
|
await localDirectory3(container);
|
|
79441
|
-
const raw = await readLocal(
|
|
79896
|
+
const raw = await readLocal(join52(container, "workspace.json"));
|
|
79442
79897
|
if (!raw)
|
|
79443
79898
|
throw new Error("An active child or decision has no workspace receipt; preserve all baselines.");
|
|
79444
79899
|
const value = JSON.parse(raw);
|
|
79445
79900
|
if (value.operationId !== operation.id || value.missionId !== id || typeof value.baselinePath !== "string")
|
|
79446
79901
|
throw new Error("An active workspace has an ambiguous baseline reference.");
|
|
79447
79902
|
protectedPaths.add(await realpath29(value.baselinePath));
|
|
79448
|
-
protectedPaths.add(
|
|
79903
|
+
protectedPaths.add(join52(operation.repositoryRoot, ".agent-valley", "operations", operation.id, "baselines", id, "workspace"));
|
|
79449
79904
|
}
|
|
79450
|
-
missionDirectories.push(
|
|
79905
|
+
missionDirectories.push(join52(storageRoot, ".agent-valley", "operation-decisions", operation.id));
|
|
79451
79906
|
}
|
|
79452
79907
|
for (const directory of missionDirectories) {
|
|
79453
79908
|
if (!await exists(directory))
|
|
79454
79909
|
continue;
|
|
79455
79910
|
await localDirectory3(directory);
|
|
79456
79911
|
const store = new MissionStore(directory);
|
|
79457
|
-
for (const name of await
|
|
79912
|
+
for (const name of await readdir13(directory)) {
|
|
79458
79913
|
if (!name.endsWith(".json"))
|
|
79459
79914
|
continue;
|
|
79460
|
-
await readLocal(
|
|
79915
|
+
await readLocal(join52(directory, name));
|
|
79461
79916
|
const mission = await store.load(name.slice(0, -5));
|
|
79462
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))
|
|
79463
79918
|
await protectMissionBaseline(mission, protectedPaths);
|
|
@@ -79469,7 +79924,7 @@ async function pruneContinuousBaselines(storageRoot, operationId, options = {})
|
|
|
79469
79924
|
operationIdSchema.parse(operationId);
|
|
79470
79925
|
if (await realpath29(storageRoot) !== resolve32(storageRoot))
|
|
79471
79926
|
throw new Error("Use the original canonical operation storage root.");
|
|
79472
|
-
const directory =
|
|
79927
|
+
const directory = join52(storageRoot, ".agent-valley", "operations");
|
|
79473
79928
|
await localDirectory3(directory);
|
|
79474
79929
|
const store = new ContinuousOperationStore(directory);
|
|
79475
79930
|
const unlock = await store.lock(operationId);
|
|
@@ -79479,26 +79934,26 @@ async function pruneContinuousBaselines(storageRoot, operationId, options = {})
|
|
|
79479
79934
|
await localDirectory3(root);
|
|
79480
79935
|
if ((await git(root, ["rev-parse", "--show-toplevel"])).trim() !== root)
|
|
79481
79936
|
throw new Error("Restore the original Git repository before pruning.");
|
|
79482
|
-
const artifacts =
|
|
79483
|
-
const baselines =
|
|
79937
|
+
const artifacts = join52(root, ".agent-valley", "operations", operationId);
|
|
79938
|
+
const baselines = join52(artifacts, "baselines");
|
|
79484
79939
|
await localDirectory3(artifacts);
|
|
79485
79940
|
await localDirectory3(baselines);
|
|
79486
79941
|
const current = operation.baseline;
|
|
79487
79942
|
if (!current)
|
|
79488
79943
|
throw new Error("No accepted baseline exists. Preserve the operation artifacts.");
|
|
79489
79944
|
const protectedPaths = await referencedBaselines(storageRoot, await store.list());
|
|
79490
|
-
protectedPaths.add(
|
|
79945
|
+
protectedPaths.add(join52(baselines, "initial", "workspace"));
|
|
79491
79946
|
for (const entry of operation.history.slice(-2))
|
|
79492
79947
|
protectedPaths.add(entry.baselinePath);
|
|
79493
|
-
const currentReceipt = continuousBaselineSchema.parse(JSON.parse(await readLocal(
|
|
79948
|
+
const currentReceipt = continuousBaselineSchema.parse(JSON.parse(await readLocal(join52(dirname11(current.path), "baseline.json")) ?? "null"));
|
|
79494
79949
|
if (JSON.stringify(currentReceipt) !== JSON.stringify(current))
|
|
79495
79950
|
throw new Error("The accepted baseline receipt changed.");
|
|
79496
79951
|
await inspectClone(current.path, current);
|
|
79497
|
-
const missionsPath =
|
|
79952
|
+
const missionsPath = join52(storageRoot, ".agent-valley", "missions");
|
|
79498
79953
|
const missions = new MissionStore(missionsPath);
|
|
79499
79954
|
const candidates = [];
|
|
79500
|
-
for (const key of (await
|
|
79501
|
-
const path =
|
|
79955
|
+
for (const key of (await readdir13(baselines)).sort()) {
|
|
79956
|
+
const path = join52(baselines, key, "workspace");
|
|
79502
79957
|
let release;
|
|
79503
79958
|
let result = { key, path, status: "kept", reason: "Retained for inspection." };
|
|
79504
79959
|
try {
|
|
@@ -79506,16 +79961,16 @@ async function pruneContinuousBaselines(storageRoot, operationId, options = {})
|
|
|
79506
79961
|
await localDirectory3(dirname11(path));
|
|
79507
79962
|
if (protectedPaths.has(path))
|
|
79508
79963
|
throw new Error("Initial, current, previous or referenced baseline is protected.");
|
|
79509
|
-
const raw = await readLocal(
|
|
79964
|
+
const raw = await readLocal(join52(dirname11(path), "baseline.json"));
|
|
79510
79965
|
const snapshot = continuousBaselineSchema.parse(JSON.parse(raw ?? "null"));
|
|
79511
|
-
const transaction = continuousBaselineSchema.parse(JSON.parse(await readLocal(
|
|
79966
|
+
const transaction = continuousBaselineSchema.parse(JSON.parse(await readLocal(join52(dirname11(path), "snapshot.json")) ?? "null"));
|
|
79512
79967
|
if (JSON.stringify(transaction) !== JSON.stringify(snapshot))
|
|
79513
79968
|
throw new Error("Original snapshot transaction and baseline receipts differ.");
|
|
79514
79969
|
if (snapshot.operationId !== operationId || snapshot.repositoryRoot !== root || snapshot.path !== path || snapshot.missionId !== key || snapshot.branch !== `av-operation/${operationId}/baseline-${key}`)
|
|
79515
79970
|
throw new Error("Baseline identity does not match its private directory.");
|
|
79516
|
-
const preparedPath =
|
|
79517
|
-
const completedPath =
|
|
79518
|
-
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");
|
|
79519
79974
|
const preparedRaw = await readLocal(preparedPath);
|
|
79520
79975
|
const prepared = preparedRaw ? preparedSchema.parse(JSON.parse(preparedRaw)) : undefined;
|
|
79521
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)))
|
|
@@ -79530,7 +79985,7 @@ async function pruneContinuousBaselines(storageRoot, operationId, options = {})
|
|
|
79530
79985
|
continue;
|
|
79531
79986
|
}
|
|
79532
79987
|
const accepted = operation.history.some((entry) => entry.missionId === key && entry.baselinePath === path);
|
|
79533
|
-
const journalRaw = await readLocal(
|
|
79988
|
+
const journalRaw = await readLocal(join52(dirname11(path), "acceptance.json"));
|
|
79534
79989
|
const journal = journalRaw ? continuousAcceptanceSchema.parse(JSON.parse(journalRaw)) : undefined;
|
|
79535
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))
|
|
79536
79991
|
throw new Error("Acceptance journal does not match this frozen baseline.");
|
|
@@ -79566,7 +80021,7 @@ async function pruneContinuousBaselines(storageRoot, operationId, options = {})
|
|
|
79566
80021
|
if (hasQuarantine && !prepared)
|
|
79567
80022
|
throw new Error("Unrecorded pruning quarantine is protected.");
|
|
79568
80023
|
await inspectClone(physicalPath, snapshot);
|
|
79569
|
-
const identity = await
|
|
80024
|
+
const identity = await lstat24(physicalPath);
|
|
79570
80025
|
if (prepared && (identity.dev !== prepared.device || identity.ino !== prepared.inode))
|
|
79571
80026
|
throw new Error("Workspace identity changed after pruning was prepared.");
|
|
79572
80027
|
result = {
|
|
@@ -79590,13 +80045,13 @@ async function pruneContinuousBaselines(storageRoot, operationId, options = {})
|
|
|
79590
80045
|
at: (options.now?.() ?? new Date).toISOString()
|
|
79591
80046
|
});
|
|
79592
80047
|
await inspectClone(physicalPath, snapshot);
|
|
79593
|
-
const checked = await
|
|
80048
|
+
const checked = await lstat24(physicalPath);
|
|
79594
80049
|
if (checked.dev !== identity.dev || checked.ino !== identity.ino)
|
|
79595
80050
|
throw new Error("Workspace identity changed before pruning.");
|
|
79596
80051
|
if (!hasQuarantine)
|
|
79597
80052
|
await rename4(path, quarantine);
|
|
79598
80053
|
await localDirectory3(quarantine);
|
|
79599
|
-
const moved = await
|
|
80054
|
+
const moved = await lstat24(quarantine);
|
|
79600
80055
|
if (moved.dev !== identity.dev || moved.ino !== identity.ino)
|
|
79601
80056
|
throw new Error("Pruning quarantine identity changed.");
|
|
79602
80057
|
await rm7(quarantine, { recursive: true });
|
|
@@ -79675,7 +80130,7 @@ function integerOption(value, name, maximum) {
|
|
|
79675
80130
|
return number;
|
|
79676
80131
|
}
|
|
79677
80132
|
function operationStore(root) {
|
|
79678
|
-
return new ContinuousOperationStore(
|
|
80133
|
+
return new ContinuousOperationStore(join53(resolve33(root), ".agent-valley", "operations"));
|
|
79679
80134
|
}
|
|
79680
80135
|
async function restoreOperationOrigin(repository, workspace) {
|
|
79681
80136
|
const env = { ...process.env, ...clearedGitEnvironment };
|
|
@@ -79783,7 +80238,7 @@ async function runOperation(charter, options, root = process.cwd(), dependencies
|
|
|
79783
80238
|
if (options.retry || decisionBudgetKeys.some((key) => options[key] !== undefined)) {
|
|
79784
80239
|
if (operation.currentMissionId || !operation.decisionId)
|
|
79785
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>.");
|
|
79786
|
-
const decisions = new MissionStore(
|
|
80241
|
+
const decisions = new MissionStore(join53(root, ".agent-valley", "operation-decisions", operation.id));
|
|
79787
80242
|
const unlockDecision = await decisions.lock(operation.decisionId);
|
|
79788
80243
|
try {
|
|
79789
80244
|
const decision = await decisions.load(operation.decisionId);
|
|
@@ -79855,7 +80310,7 @@ async function runOperation(charter, options, root = process.cwd(), dependencies
|
|
|
79855
80310
|
console.log(`Operation ${id}
|
|
79856
80311
|
Charter: ${operation.charter}
|
|
79857
80312
|
Resume: av order --resume ${id}`);
|
|
79858
|
-
const missions = new MissionStore(
|
|
80313
|
+
const missions = new MissionStore(join53(root, ".agent-valley", "missions"));
|
|
79859
80314
|
return await runContinuousOperation(operation, {
|
|
79860
80315
|
signal: controller.signal,
|
|
79861
80316
|
...options.retry ? { retryDecision: true } : {},
|
|
@@ -79993,7 +80448,7 @@ class OperationApi {
|
|
|
79993
80448
|
this.root = root;
|
|
79994
80449
|
this.workspace = workspace;
|
|
79995
80450
|
this.dependencies = dependencies;
|
|
79996
|
-
this.store = new ContinuousOperationStore(
|
|
80451
|
+
this.store = new ContinuousOperationStore(join54(root, ".agent-valley/operations"));
|
|
79997
80452
|
this.jobs = new MissionJobs(root, "operation-jobs");
|
|
79998
80453
|
}
|
|
79999
80454
|
order(raw) {
|
|
@@ -80242,17 +80697,17 @@ class MissionApi {
|
|
|
80242
80697
|
this.projectRoot = projectRoot;
|
|
80243
80698
|
this.workspace = workspace;
|
|
80244
80699
|
this.dependencies = dependencies;
|
|
80245
|
-
this.store = new MissionStore(
|
|
80700
|
+
this.store = new MissionStore(join55(projectRoot, ".agent-valley/missions"));
|
|
80246
80701
|
this.jobs = new MissionJobs(projectRoot);
|
|
80247
80702
|
this.operationApi = new OperationApi(projectRoot, workspace, dependencies);
|
|
80248
80703
|
this.operationJobs = new MissionJobs(projectRoot, "operation-jobs");
|
|
80249
80704
|
}
|
|
80250
80705
|
static async create(workspace, dependencies = {}) {
|
|
80251
|
-
if (!
|
|
80706
|
+
if (!isAbsolute19(workspace))
|
|
80252
80707
|
throw new Error("Set an absolute Git repository path in av mcp --workspace <path>.");
|
|
80253
80708
|
const projectRoot = await realpath33(workspace);
|
|
80254
80709
|
const target = loadProjectConfig(projectRoot)?.workspace?.root ?? projectRoot;
|
|
80255
|
-
if (!
|
|
80710
|
+
if (!isAbsolute19(target))
|
|
80256
80711
|
throw new Error("Set workspace.root in av.yaml to an absolute Git repository path.");
|
|
80257
80712
|
return new MissionApi(projectRoot, await realpath33(target), dependencies);
|
|
80258
80713
|
}
|
|
@@ -80281,7 +80736,7 @@ class MissionApi {
|
|
|
80281
80736
|
async order(raw) {
|
|
80282
80737
|
assertNotManagedRun(this.dependencies.env);
|
|
80283
80738
|
const input = mcpOrderSchema.parse(raw);
|
|
80284
|
-
if (input.workspace && (!
|
|
80739
|
+
if (input.workspace && (!isAbsolute19(input.workspace) || await realpath33(input.workspace) !== this.workspace))
|
|
80285
80740
|
throw new Error("This AV server is bound to another workspace. Start av mcp --workspace for the target repository.");
|
|
80286
80741
|
return this.serializeOrder(async () => {
|
|
80287
80742
|
if (input.requestId) {
|
|
@@ -80304,7 +80759,7 @@ class MissionApi {
|
|
|
80304
80759
|
async list() {
|
|
80305
80760
|
this.assertOpen();
|
|
80306
80761
|
await ensureAvDirectory(this.projectRoot, ["missions"]);
|
|
80307
|
-
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))));
|
|
80308
80763
|
for (const job of await this.jobs.list())
|
|
80309
80764
|
ids.add(job.missionId);
|
|
80310
80765
|
return {
|
|
@@ -80458,8 +80913,8 @@ class MissionApi {
|
|
|
80458
80913
|
async load(id) {
|
|
80459
80914
|
await ensureAvDirectory(this.projectRoot, ["missions"]);
|
|
80460
80915
|
try {
|
|
80461
|
-
const path =
|
|
80462
|
-
const stat = await
|
|
80916
|
+
const path = join55(this.projectRoot, ".agent-valley/missions", `${missionIdSchema.parse(id)}.json`);
|
|
80917
|
+
const stat = await lstat25(path);
|
|
80463
80918
|
if (!stat.isFile() || stat.isSymbolicLink())
|
|
80464
80919
|
throw new Error(`Mission record must be a regular file: ${path}. Remove the symlink before retrying.`);
|
|
80465
80920
|
return await this.store.load(id);
|
|
@@ -80483,11 +80938,11 @@ class MissionApi {
|
|
|
80483
80938
|
// src/plugin-export.ts
|
|
80484
80939
|
init_client_integrations_assets();
|
|
80485
80940
|
init_client_integrations_files();
|
|
80486
|
-
import { lstat as
|
|
80487
|
-
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";
|
|
80488
80943
|
|
|
80489
80944
|
// src/plugin-assets.ts
|
|
80490
|
-
import { copyFile as copyFile2, mkdir as mkdir24, readFile as
|
|
80945
|
+
import { copyFile as copyFile2, mkdir as mkdir24, readFile as readFile20 } from "node:fs/promises";
|
|
80491
80946
|
init_zod();
|
|
80492
80947
|
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
80493
80948
|
var pluginSchemaUrl = "https://agent-plugins.org/schemas/1.0.0/plugin.schema.json";
|
|
@@ -80519,7 +80974,7 @@ async function loadPluginLicenseAsset(candidates = pluginLicenseAssetCandidates(
|
|
|
80519
80974
|
for (const path of candidates) {
|
|
80520
80975
|
let content;
|
|
80521
80976
|
try {
|
|
80522
|
-
content = await
|
|
80977
|
+
content = await readFile20(path, "utf8");
|
|
80523
80978
|
} catch (error) {
|
|
80524
80979
|
if (error.code === "ENOENT")
|
|
80525
80980
|
continue;
|
|
@@ -80535,7 +80990,7 @@ async function loadPluginManifestAsset(candidates = pluginManifestAssetCandidate
|
|
|
80535
80990
|
for (const path of candidates) {
|
|
80536
80991
|
let content;
|
|
80537
80992
|
try {
|
|
80538
|
-
content = await
|
|
80993
|
+
content = await readFile20(path, "utf8");
|
|
80539
80994
|
} catch (error) {
|
|
80540
80995
|
if (error.code === "ENOENT")
|
|
80541
80996
|
continue;
|
|
@@ -80652,7 +81107,7 @@ async function projectDirectory(workspace) {
|
|
|
80652
81107
|
throw new Error("Pass --workspace /absolute/AV-project to bind every exported MCP server to its AV configuration.");
|
|
80653
81108
|
try {
|
|
80654
81109
|
const project = await realpath34(resolve34(workspace));
|
|
80655
|
-
if (!(await
|
|
81110
|
+
if (!(await lstat26(project)).isDirectory())
|
|
80656
81111
|
throw new Error("not a directory");
|
|
80657
81112
|
return project;
|
|
80658
81113
|
} catch {
|
|
@@ -80678,12 +81133,12 @@ async function outputDirectory(output) {
|
|
|
80678
81133
|
let ancestor = target;
|
|
80679
81134
|
for (;; ) {
|
|
80680
81135
|
try {
|
|
80681
|
-
const info = await
|
|
81136
|
+
const info = await lstat26(ancestor);
|
|
80682
81137
|
if (info.isSymbolicLink())
|
|
80683
81138
|
throw exportConflict(ancestor, "symbolic link exports are not modified");
|
|
80684
81139
|
if (!info.isDirectory())
|
|
80685
81140
|
throw exportConflict(ancestor, "expected an output directory");
|
|
80686
|
-
return
|
|
81141
|
+
return join56(await realpath34(ancestor), relative17(ancestor, target));
|
|
80687
81142
|
} catch (error) {
|
|
80688
81143
|
if (error.code !== "ENOENT")
|
|
80689
81144
|
throw error;
|
|
@@ -80694,7 +81149,7 @@ async function outputDirectory(output) {
|
|
|
80694
81149
|
async function outputFiles(root, directory = root) {
|
|
80695
81150
|
let entries;
|
|
80696
81151
|
try {
|
|
80697
|
-
entries = await
|
|
81152
|
+
entries = await readdir15(directory, { withFileTypes: true });
|
|
80698
81153
|
} catch (error) {
|
|
80699
81154
|
if (error.code === "ENOENT")
|
|
80700
81155
|
return [];
|
|
@@ -80702,7 +81157,7 @@ async function outputFiles(root, directory = root) {
|
|
|
80702
81157
|
}
|
|
80703
81158
|
const files = [];
|
|
80704
81159
|
for (const entry of entries) {
|
|
80705
|
-
const path =
|
|
81160
|
+
const path = join56(directory, entry.name);
|
|
80706
81161
|
if (entry.isSymbolicLink())
|
|
80707
81162
|
throw exportConflict(path, "symbolic links are not modified");
|
|
80708
81163
|
if (entry.isDirectory())
|
|
@@ -80739,21 +81194,21 @@ async function exportPluginPackages(options) {
|
|
|
80739
81194
|
if (output === workspace)
|
|
80740
81195
|
throw exportConflict(output, "the output directory must be separate from the AV project root");
|
|
80741
81196
|
const { manifest } = await loadPluginManifestAsset(options.sourceManifest ? [options.sourceManifest] : undefined);
|
|
80742
|
-
const { content: skill } = await loadClientSkillAsset(options.sourceSkillRoot ? [
|
|
81197
|
+
const { content: skill } = await loadClientSkillAsset(options.sourceSkillRoot ? [join56(options.sourceSkillRoot, "SKILL.md")] : clientSkillAssetCandidates());
|
|
80743
81198
|
const { content: license } = await loadPluginLicenseAsset(options.sourceLicense ? [options.sourceLicense] : undefined);
|
|
80744
81199
|
const packageFiles = pluginPackageFiles(manifest, skill, license, { workspace, remoteUrl });
|
|
80745
|
-
const receipt = await integrationFile(output,
|
|
81200
|
+
const receipt = await integrationFile(output, join56(output, receiptName2), "", 384);
|
|
80746
81201
|
const hashes = ownedFileHashes(receipt.before, receipt.path);
|
|
80747
81202
|
const existing = await outputFiles(output);
|
|
80748
81203
|
for (const path of existing) {
|
|
80749
81204
|
if (path === receiptName2)
|
|
80750
81205
|
continue;
|
|
80751
81206
|
if (!packageFiles.has(path) || hashes[path] === undefined)
|
|
80752
|
-
throw exportConflict(
|
|
81207
|
+
throw exportConflict(join56(output, path), "unowned files are retained");
|
|
80753
81208
|
}
|
|
80754
81209
|
const files = [];
|
|
80755
81210
|
for (const [path, content] of packageFiles) {
|
|
80756
|
-
const file = await integrationFile(output,
|
|
81211
|
+
const file = await integrationFile(output, join56(output, path), content, 420);
|
|
80757
81212
|
if (hashes[path] !== undefined && (file.before === null || contentHash(file.before) !== hashes[path]))
|
|
80758
81213
|
throw exportConflict(file.path, "the exported file was changed or removed locally");
|
|
80759
81214
|
if (hashes[path] === undefined && file.before !== null)
|
|
@@ -80772,11 +81227,11 @@ async function exportPluginPackages(options) {
|
|
|
80772
81227
|
transport: remoteUrl ? "streamable-http" : "stdio",
|
|
80773
81228
|
files: await applyIntegrationFiles(output, [...files, receipt]),
|
|
80774
81229
|
packages: {
|
|
80775
|
-
portable:
|
|
80776
|
-
claude:
|
|
80777
|
-
cursor:
|
|
80778
|
-
qwen:
|
|
80779
|
-
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")
|
|
80780
81235
|
}
|
|
80781
81236
|
};
|
|
80782
81237
|
}
|
|
@@ -80839,7 +81294,7 @@ function registerAgentClientCommands(program) {
|
|
|
80839
81294
|
// src/chief.ts
|
|
80840
81295
|
import { randomUUID as randomUUID24 } from "node:crypto";
|
|
80841
81296
|
import { realpath as realpath37 } from "node:fs/promises";
|
|
80842
|
-
import { join as
|
|
81297
|
+
import { join as join64 } from "node:path";
|
|
80843
81298
|
|
|
80844
81299
|
// ../../node_modules/.bun/@langchain+core@1.2.20+ea9f70ecde856c26/node_modules/@langchain/core/dist/_virtual/_rolldown/runtime.js
|
|
80845
81300
|
var __defProp4 = Object.defineProperty;
|
|
@@ -89796,10 +90251,10 @@ async function writeFileAtomic(filePath, content) {
|
|
|
89796
90251
|
});
|
|
89797
90252
|
await nodeFsPromises.rename(tempPath, filePath);
|
|
89798
90253
|
}
|
|
89799
|
-
async function
|
|
90254
|
+
async function readdir17(dir) {
|
|
89800
90255
|
return nodeFsPromises.readdir(dir);
|
|
89801
90256
|
}
|
|
89802
|
-
async function
|
|
90257
|
+
async function stat6(filePath) {
|
|
89803
90258
|
return nodeFsPromises.stat(filePath);
|
|
89804
90259
|
}
|
|
89805
90260
|
function existsSync6(p) {
|
|
@@ -92284,11 +92739,11 @@ class Client2 {
|
|
|
92284
92739
|
}
|
|
92285
92740
|
if (maxBytes !== undefined && maxBytes > 0) {
|
|
92286
92741
|
try {
|
|
92287
|
-
const entries = await
|
|
92742
|
+
const entries = await readdir17(directory);
|
|
92288
92743
|
const traceFiles = entries.filter((f) => f.startsWith("trace_") && f.endsWith(".json"));
|
|
92289
92744
|
let total = 0;
|
|
92290
92745
|
for (const name of traceFiles) {
|
|
92291
|
-
const { size } = await
|
|
92746
|
+
const { size } = await stat6(path6.join(directory, name));
|
|
92292
92747
|
total += size;
|
|
92293
92748
|
}
|
|
92294
92749
|
if (total >= maxBytes) {
|
|
@@ -131330,7 +131785,8 @@ function applyVerificationResult(mission, result, fingerprint) {
|
|
|
131330
131785
|
init_execution();
|
|
131331
131786
|
|
|
131332
131787
|
// ../../packages/core/src/chief/review-routing.ts
|
|
131333
|
-
|
|
131788
|
+
init_execution();
|
|
131789
|
+
function addReviewer(mission, vendor, model) {
|
|
131334
131790
|
if (mission.personas.length >= 20)
|
|
131335
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.");
|
|
131336
131792
|
let id = `review-${vendor}`;
|
|
@@ -131341,6 +131797,7 @@ function addReviewer(mission, vendor) {
|
|
|
131341
131797
|
name: `Independent ${vendor} reviewer`,
|
|
131342
131798
|
role: "Independently inspect actual files and task acceptance evidence; report blockers without editing files.",
|
|
131343
131799
|
agentType: vendor,
|
|
131800
|
+
...model ? { model } : {},
|
|
131344
131801
|
skills: []
|
|
131345
131802
|
};
|
|
131346
131803
|
mission.personas.push(reviewer);
|
|
@@ -131351,30 +131808,36 @@ function selectTaskReviewer(mission, task, state, gateId) {
|
|
|
131351
131808
|
if (!configured)
|
|
131352
131809
|
throw new Error("Restore the configured task reviewer before resuming.");
|
|
131353
131810
|
const policy = mission.operatingPolicy;
|
|
131354
|
-
if (!policy || policy.reviewVendor === "off")
|
|
131811
|
+
if (!policy || policy.reviewVendor === "off") {
|
|
131812
|
+
availableActorRoutes(mission, [{ actorType: configured.agentType, model: configured.model }]);
|
|
131355
131813
|
return configured;
|
|
131814
|
+
}
|
|
131356
131815
|
const run = latestWorkRun(mission, task.id);
|
|
131357
131816
|
const worker = run?.actorType ?? mission.personas.find((actor) => actor.id === task.personaId)?.agentType;
|
|
131358
131817
|
if (!worker)
|
|
131359
131818
|
throw new Error("Restore this task's actual work Actor before reviewing it.");
|
|
131360
131819
|
const blocked = unavailableProviders(mission.handoff);
|
|
131361
|
-
const
|
|
131362
|
-
const
|
|
131363
|
-
|
|
131364
|
-
|
|
131365
|
-
|
|
131366
|
-
|
|
131367
|
-
if (
|
|
131368
|
-
|
|
131369
|
-
|
|
131370
|
-
|
|
131371
|
-
|
|
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") {
|
|
131372
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.`);
|
|
131373
|
-
} else if (configured.agentType !== worker && ready.includes(worker)) {
|
|
131374
|
-
reviewer = mission.personas.find((actor) => actor.id !== task.personaId && actor.agentType === worker) ?? addReviewer(mission, worker);
|
|
131375
|
-
} else if (!ready.length) {
|
|
131376
|
-
reason = "No vendor readiness pool is recorded; the configured independent Actor is attempted with readiness unknown.";
|
|
131377
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.";
|
|
131378
131841
|
state.reviewerId = reviewer.id;
|
|
131379
131842
|
mission.operations ??= { runs: [], routingEvidence: [], reviewDecisions: [] };
|
|
131380
131843
|
mission.operations.reviewDecisions.push({
|
|
@@ -131589,7 +132052,9 @@ async function resumeMission(context) {
|
|
|
131589
132052
|
assertNoUncertainExecution(mission);
|
|
131590
132053
|
checkAbort();
|
|
131591
132054
|
assertExecutionDeadline(mission);
|
|
131592
|
-
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");
|
|
131593
132058
|
if (Date.parse(mission.execution.nextRunAt ?? "") > Date.now())
|
|
131594
132059
|
return { kind: "return" };
|
|
131595
132060
|
delete mission.execution.nextRunAt;
|
|
@@ -131654,6 +132119,9 @@ async function planMission(context) {
|
|
|
131654
132119
|
return { kind: "next", stage: "tasks" };
|
|
131655
132120
|
}
|
|
131656
132121
|
|
|
132122
|
+
// ../../packages/core/src/chief/coordinator-parallel.ts
|
|
132123
|
+
init_execution();
|
|
132124
|
+
|
|
131657
132125
|
// ../../packages/core/src/chief/parallel.ts
|
|
131658
132126
|
function readyTaskWave(plan, states, limit) {
|
|
131659
132127
|
if (!Number.isInteger(limit) || limit < 1 || limit > 20)
|
|
@@ -131725,6 +132193,8 @@ async function performParallelWave(mission, ports, wave, hooks) {
|
|
|
131725
132193
|
continue;
|
|
131726
132194
|
}
|
|
131727
132195
|
try {
|
|
132196
|
+
const previousAttempts = state.attempts;
|
|
132197
|
+
const workRunsBefore = mission.operations?.runs.filter((run) => run.stage === "work" && run.taskId === task.id).length ?? 0;
|
|
131728
132198
|
const previousOutput = state.parallel ? undefined : state.output;
|
|
131729
132199
|
if (!state.parallel)
|
|
131730
132200
|
delete state.output;
|
|
@@ -131740,7 +132210,7 @@ async function performParallelWave(mission, ports, wave, hooks) {
|
|
|
131740
132210
|
path: state.parallel.path,
|
|
131741
132211
|
branch: state.parallel.branch
|
|
131742
132212
|
};
|
|
131743
|
-
prepared.push({ task, state, actor, workspace, previousOutput });
|
|
132213
|
+
prepared.push({ task, state, actor, workspace, previousOutput, previousAttempts, workRunsBefore });
|
|
131744
132214
|
} catch (error) {
|
|
131745
132215
|
state.status = "pending";
|
|
131746
132216
|
fail(task.id, error);
|
|
@@ -131771,6 +132241,8 @@ ${JSON.stringify(previousOutput)}`;
|
|
|
131771
132241
|
const entry = pending[index];
|
|
131772
132242
|
if (entry && result.status === "rejected") {
|
|
131773
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;
|
|
131774
132246
|
fail(entry.task.id, result.reason);
|
|
131775
132247
|
}
|
|
131776
132248
|
});
|
|
@@ -131860,6 +132332,8 @@ async function runTaskStage(context) {
|
|
|
131860
132332
|
const performTask = async (task, state) => {
|
|
131861
132333
|
while (state.status !== "completed") {
|
|
131862
132334
|
checkAbort();
|
|
132335
|
+
const attemptsBefore = state.attempts;
|
|
132336
|
+
const workRunsBefore = mission.operations?.runs.filter((run) => run.stage === "work" && run.taskId === task.id).length ?? 0;
|
|
131863
132337
|
const awaitingReview = state.output !== undefined && state.review === undefined;
|
|
131864
132338
|
state.status = awaitingReview ? "reviewing" : "running";
|
|
131865
132339
|
if (!awaitingReview && (task.effectScope !== "external" || state.effectState !== "completed"))
|
|
@@ -131888,6 +132362,8 @@ async function runTaskStage(context) {
|
|
|
131888
132362
|
reviewStarted = true;
|
|
131889
132363
|
await taskReview(task, state);
|
|
131890
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;
|
|
131891
132367
|
if (!mission.supervision || protectedFailure(error))
|
|
131892
132368
|
throw error;
|
|
131893
132369
|
state.status = reviewStarted ? "reviewing" : "pending";
|
|
@@ -131934,12 +132410,17 @@ async function runTaskStage(context) {
|
|
|
131934
132410
|
const limit = mission.executionPolicy?.maxParallel ?? 1;
|
|
131935
132411
|
const wave = readyTaskWave(plan, mission.tasks, limit).filter((task) => task.effectScope !== "external");
|
|
131936
132412
|
if (ports.parallel && limit > 1 && (wave.length > 1 || wave.some((task) => mission.tasks.find((state) => state.id === task.id)?.parallel))) {
|
|
131937
|
-
|
|
132413
|
+
let failures = await performParallelWave(mission, ports, wave, {
|
|
131938
132414
|
run,
|
|
131939
132415
|
save,
|
|
131940
132416
|
review: taskReview,
|
|
131941
132417
|
fatal: protectedFailure
|
|
131942
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
|
+
});
|
|
131943
132424
|
const unrecoverable = failures.find((failure) => protectedFailure(failure.error));
|
|
131944
132425
|
if (unrecoverable)
|
|
131945
132426
|
throw unrecoverable.error;
|
|
@@ -132226,7 +132707,7 @@ init_worktree_lifecycle();
|
|
|
132226
132707
|
import { randomUUID as randomUUID23 } from "node:crypto";
|
|
132227
132708
|
import { mkdtemp as mkdtemp2, rm as rm9 } from "node:fs/promises";
|
|
132228
132709
|
import { tmpdir as tmpdir3 } from "node:os";
|
|
132229
|
-
import { join as
|
|
132710
|
+
import { join as join57 } from "node:path";
|
|
132230
132711
|
async function importIsolatedBranch(workspace, root) {
|
|
132231
132712
|
if (!isIsolatedGitWorkspace(workspace))
|
|
132232
132713
|
return null;
|
|
@@ -132273,7 +132754,7 @@ async function importIsolatedBranch(workspace, root) {
|
|
|
132273
132754
|
`).filter(Boolean);
|
|
132274
132755
|
if (commits.length === 0)
|
|
132275
132756
|
return null;
|
|
132276
|
-
temporaryWorktree = await mkdtemp2(
|
|
132757
|
+
temporaryWorktree = await mkdtemp2(join57(tmpdir3(), "av-branch-import-"));
|
|
132277
132758
|
const added = await runCommand("git", ["worktree", "add", "--detach", temporaryWorktree, currentHead], {
|
|
132278
132759
|
cwd: root
|
|
132279
132760
|
});
|
|
@@ -132313,8 +132794,8 @@ async function importIsolatedBranch(workspace, root) {
|
|
|
132313
132794
|
// ../../packages/core/src/workspace/safety-net.ts
|
|
132314
132795
|
init_logger();
|
|
132315
132796
|
init_worktree_lifecycle();
|
|
132316
|
-
import { lstat as
|
|
132317
|
-
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";
|
|
132318
132799
|
var CONFLICT_MARKER_PATTERN = /^(<<<<<<<|=======|>>>>>>>)( .*)?$/m;
|
|
132319
132800
|
var REGENERATABLE_LOCKFILE_PATTERNS = [
|
|
132320
132801
|
/(^|\/)package-lock\.json$/,
|
|
@@ -132406,7 +132887,7 @@ async function findConflictMarkerFiles(root, files) {
|
|
|
132406
132887
|
const conflicts = [];
|
|
132407
132888
|
for (const file of files) {
|
|
132408
132889
|
try {
|
|
132409
|
-
const content = await
|
|
132890
|
+
const content = await readFile21(`${root}/${file}`, "utf-8");
|
|
132410
132891
|
if (CONFLICT_MARKER_PATTERN.test(content)) {
|
|
132411
132892
|
conflicts.push(file);
|
|
132412
132893
|
}
|
|
@@ -132416,7 +132897,7 @@ async function findConflictMarkerFiles(root, files) {
|
|
|
132416
132897
|
}
|
|
132417
132898
|
function isInside(parent, child) {
|
|
132418
132899
|
const rel = relative18(parent, child);
|
|
132419
|
-
return rel === "" || rel !== ".." && !rel.startsWith(`..${sep17}`) && !
|
|
132900
|
+
return rel === "" || rel !== ".." && !rel.startsWith(`..${sep17}`) && !isAbsolute20(rel);
|
|
132420
132901
|
}
|
|
132421
132902
|
function untrustedGitError(detail) {
|
|
132422
132903
|
return {
|
|
@@ -132426,14 +132907,14 @@ function untrustedGitError(detail) {
|
|
|
132426
132907
|
};
|
|
132427
132908
|
}
|
|
132428
132909
|
async function validateTrustedWorktree(cwd, repoRoot) {
|
|
132429
|
-
const dotGit =
|
|
132430
|
-
const entry = await
|
|
132910
|
+
const dotGit = join58(cwd, ".git");
|
|
132911
|
+
const entry = await lstat27(dotGit).catch(() => null);
|
|
132431
132912
|
if (!entry)
|
|
132432
132913
|
return untrustedGitError(`missing ${dotGit}`);
|
|
132433
132914
|
if (entry.isSymbolicLink())
|
|
132434
132915
|
return untrustedGitError(`${dotGit} is a symlink`);
|
|
132435
132916
|
if (entry.isFile()) {
|
|
132436
|
-
const contents = await
|
|
132917
|
+
const contents = await readFile21(dotGit, "utf8");
|
|
132437
132918
|
const match = /^gitdir:\s*(.+)$/m.exec(contents);
|
|
132438
132919
|
if (!match?.[1])
|
|
132439
132920
|
return untrustedGitError(`${dotGit} has no gitdir pointer`);
|
|
@@ -132442,14 +132923,14 @@ async function validateTrustedWorktree(cwd, repoRoot) {
|
|
|
132442
132923
|
return untrustedGitError(`${dotGit} does not point into a worktrees directory`);
|
|
132443
132924
|
if (isInside(cwd, gitDir))
|
|
132444
132925
|
return untrustedGitError(`${dotGit} points inside the agent-writable workspace`);
|
|
132445
|
-
const gitDirStat = await
|
|
132926
|
+
const gitDirStat = await lstat27(gitDir).catch(() => null);
|
|
132446
132927
|
if (!gitDirStat?.isDirectory())
|
|
132447
132928
|
return untrustedGitError(`${dotGit} points at a missing directory`);
|
|
132448
132929
|
if (repoRoot) {
|
|
132449
132930
|
const commonDir = resolve36(gitDir, "..", "..");
|
|
132450
132931
|
const [actualCommon, expectedCommon] = await Promise.all([
|
|
132451
132932
|
realpath35(commonDir).catch(() => null),
|
|
132452
|
-
realpath35(
|
|
132933
|
+
realpath35(join58(repoRoot, ".git")).catch(() => null)
|
|
132453
132934
|
]);
|
|
132454
132935
|
if (!expectedCommon || actualCommon !== expectedCommon) {
|
|
132455
132936
|
return untrustedGitError(`${dotGit} points outside the configured repository`);
|
|
@@ -132899,18 +133380,18 @@ function createMissionContainerPorts(dependencies = {}) {
|
|
|
132899
133380
|
}
|
|
132900
133381
|
|
|
132901
133382
|
// src/chief-missions.ts
|
|
132902
|
-
import { join as
|
|
133383
|
+
import { join as join61 } from "node:path";
|
|
132903
133384
|
|
|
132904
133385
|
// src/chief-reconcile.ts
|
|
132905
133386
|
init_execution();
|
|
132906
|
-
import { join as
|
|
133387
|
+
import { join as join59 } from "node:path";
|
|
132907
133388
|
async function reconcileMissionExecution(missionId, options, root = process.cwd()) {
|
|
132908
133389
|
assertNotManagedRun();
|
|
132909
133390
|
const runId = options.run?.trim();
|
|
132910
133391
|
const evidence = options.evidence?.trim();
|
|
132911
133392
|
if (!runId || runId.length > 2000 || !evidence || evidence.length > 2000)
|
|
132912
133393
|
throw new Error("Set --run to the uncertain execution ID and --evidence to 1–2,000 characters describing how you confirmed it stopped.");
|
|
132913
|
-
const store = new MissionStore(
|
|
133394
|
+
const store = new MissionStore(join59(root, ".agent-valley", "missions"));
|
|
132914
133395
|
const unlock = await store.lock(missionId);
|
|
132915
133396
|
try {
|
|
132916
133397
|
const mission = await store.load(missionId);
|
|
@@ -132939,7 +133420,7 @@ function registerMissionReconciliation(missions, root = process.cwd()) {
|
|
|
132939
133420
|
}
|
|
132940
133421
|
|
|
132941
133422
|
// src/chief-watch.ts
|
|
132942
|
-
import { join as
|
|
133423
|
+
import { join as join60 } from "node:path";
|
|
132943
133424
|
async function watchOrders(root = process.cwd(), dependencies = {}) {
|
|
132944
133425
|
assertNotManagedRun();
|
|
132945
133426
|
const controller = new AbortController;
|
|
@@ -132952,7 +133433,7 @@ async function watchOrders(root = process.cwd(), dependencies = {}) {
|
|
|
132952
133433
|
process.once("SIGINT", stop);
|
|
132953
133434
|
process.once("SIGTERM", terminate);
|
|
132954
133435
|
}
|
|
132955
|
-
const missions = new MissionStore(
|
|
133436
|
+
const missions = new MissionStore(join60(root, ".agent-valley", "missions"));
|
|
132956
133437
|
try {
|
|
132957
133438
|
while (!controller.signal.aborted) {
|
|
132958
133439
|
const operations = await operationStore(root).list();
|
|
@@ -133040,7 +133521,7 @@ function registerMissionCommands(program) {
|
|
|
133040
133521
|
await watchOrders(process.cwd(), { service: options.service });
|
|
133041
133522
|
return;
|
|
133042
133523
|
}
|
|
133043
|
-
const missions = await new MissionStore(
|
|
133524
|
+
const missions = await new MissionStore(join61(process.cwd(), ".agent-valley/missions")).list();
|
|
133044
133525
|
if (options.json) {
|
|
133045
133526
|
console.log(JSON.stringify(missions.map((mission) => ({
|
|
133046
133527
|
id: mission.id,
|
|
@@ -133068,11 +133549,11 @@ function registerMissionCommands(program) {
|
|
|
133068
133549
|
}
|
|
133069
133550
|
|
|
133070
133551
|
// src/chief-parent-resume.ts
|
|
133071
|
-
import { join as
|
|
133552
|
+
import { join as join62 } from "node:path";
|
|
133072
133553
|
async function resumeParentForChild(root, child, resume) {
|
|
133073
133554
|
if (child.status !== "completed" || !verifiedMissionEvidence(child))
|
|
133074
133555
|
return child;
|
|
133075
|
-
const directory =
|
|
133556
|
+
const directory = join62(root, ".agent-valley", "operations");
|
|
133076
133557
|
const owners = (await new ContinuousOperationStore(directory).list()).filter((operation) => operation.currentMissionId === child.id);
|
|
133077
133558
|
if (owners.length > 1)
|
|
133078
133559
|
throw new Error("Multiple orders claim this child. Restore a single owning operation before resuming its accepted result.");
|
|
@@ -133096,8 +133577,8 @@ async function resumeParentForChild(root, child, resume) {
|
|
|
133096
133577
|
}
|
|
133097
133578
|
|
|
133098
133579
|
// src/chief-workspace-dependencies.ts
|
|
133099
|
-
import { lstat as
|
|
133100
|
-
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";
|
|
133101
133582
|
var caches = new Set([".cache", ".vite", ".vite-temp"]);
|
|
133102
133583
|
var inside3 = (root, path) => path === root || path.startsWith(`${root}${sep18}`);
|
|
133103
133584
|
async function prepareMissionDependencies(repository, workspace) {
|
|
@@ -133105,8 +133586,8 @@ async function prepareMissionDependencies(repository, workspace) {
|
|
|
133105
133586
|
const target = await realpath36(workspace);
|
|
133106
133587
|
if (source === target)
|
|
133107
133588
|
throw new Error("Dependency preparation requires a separate mission workspace.");
|
|
133108
|
-
const packagePath =
|
|
133109
|
-
const metadata = await
|
|
133589
|
+
const packagePath = join63(source, "package.json");
|
|
133590
|
+
const metadata = await readFile22(packagePath, "utf8").catch((error) => {
|
|
133110
133591
|
if (error.code === "ENOENT")
|
|
133111
133592
|
return null;
|
|
133112
133593
|
throw error;
|
|
@@ -133135,12 +133616,12 @@ async function prepareMissionDependencies(repository, workspace) {
|
|
|
133135
133616
|
}
|
|
133136
133617
|
const [segment, ...rest] = segments;
|
|
133137
133618
|
if (segment === "*") {
|
|
133138
|
-
for (const entry of await
|
|
133619
|
+
for (const entry of await readdir18(directory, { withFileTypes: true }).catch(() => [])) {
|
|
133139
133620
|
if (entry.isDirectory() && !entry.name.startsWith(".") && entry.name !== "node_modules")
|
|
133140
|
-
await expand(
|
|
133621
|
+
await expand(join63(directory, entry.name), rest);
|
|
133141
133622
|
}
|
|
133142
133623
|
} else if (segment)
|
|
133143
|
-
await expand(
|
|
133624
|
+
await expand(join63(directory, segment), rest);
|
|
133144
133625
|
}
|
|
133145
133626
|
for (const pattern of patterns) {
|
|
133146
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)
|
|
@@ -133163,7 +133644,7 @@ async function prepareMissionDependencies(repository, workspace) {
|
|
|
133163
133644
|
throw new Error("A workspace dependency is missing or escapes the mission workspace. Restore that package.");
|
|
133164
133645
|
installed = destination;
|
|
133165
133646
|
}
|
|
133166
|
-
const existing = await
|
|
133647
|
+
const existing = await lstat28(to).catch((error) => {
|
|
133167
133648
|
if (error.code === "ENOENT")
|
|
133168
133649
|
return;
|
|
133169
133650
|
throw error;
|
|
@@ -133173,11 +133654,11 @@ async function prepareMissionDependencies(repository, workspace) {
|
|
|
133173
133654
|
throw new Error("An existing mission dependency differs from the installed package. Preserve it and repair setup.");
|
|
133174
133655
|
return;
|
|
133175
133656
|
}
|
|
133176
|
-
await symlink(installed, to, (await
|
|
133657
|
+
await symlink(installed, to, (await stat7(installed)).isDirectory() ? "dir" : "file");
|
|
133177
133658
|
}
|
|
133178
133659
|
for (const root of roots) {
|
|
133179
|
-
const modules =
|
|
133180
|
-
const installed = await
|
|
133660
|
+
const modules = join63(root, "node_modules");
|
|
133661
|
+
const installed = await stat7(modules).catch(() => {
|
|
133181
133662
|
return;
|
|
133182
133663
|
});
|
|
133183
133664
|
if (!installed?.isDirectory())
|
|
@@ -133185,27 +133666,27 @@ async function prepareMissionDependencies(repository, workspace) {
|
|
|
133185
133666
|
const destinationRoot = await realpath36(resolve37(target, relative19(source, root)));
|
|
133186
133667
|
if (!inside3(target, destinationRoot))
|
|
133187
133668
|
throw new Error("A mission package directory escapes its workspace.");
|
|
133188
|
-
const destination =
|
|
133189
|
-
const existing = await
|
|
133669
|
+
const destination = join63(destinationRoot, "node_modules");
|
|
133670
|
+
const existing = await lstat28(destination).catch(() => {
|
|
133190
133671
|
return;
|
|
133191
133672
|
});
|
|
133192
133673
|
if (existing && !existing.isDirectory())
|
|
133193
133674
|
throw new Error("Mission node_modules must be a local directory.");
|
|
133194
133675
|
await mkdir27(destination, { recursive: true });
|
|
133195
|
-
for (const entry of await
|
|
133676
|
+
for (const entry of await readdir18(modules, { withFileTypes: true })) {
|
|
133196
133677
|
if (caches.has(entry.name))
|
|
133197
133678
|
continue;
|
|
133198
|
-
const from =
|
|
133199
|
-
const to =
|
|
133679
|
+
const from = join63(modules, entry.name);
|
|
133680
|
+
const to = join63(destination, entry.name);
|
|
133200
133681
|
if (entry.name.startsWith("@") && entry.isDirectory()) {
|
|
133201
|
-
const scope = await
|
|
133682
|
+
const scope = await lstat28(to).catch(() => {
|
|
133202
133683
|
return;
|
|
133203
133684
|
});
|
|
133204
133685
|
if (scope && !scope.isDirectory())
|
|
133205
133686
|
throw new Error("A dependency scope must be a local directory.");
|
|
133206
133687
|
await mkdir27(to, { recursive: true });
|
|
133207
|
-
for (const member of await
|
|
133208
|
-
await link(
|
|
133688
|
+
for (const member of await readdir18(from))
|
|
133689
|
+
await link(join63(from, member), join63(to, member));
|
|
133209
133690
|
} else
|
|
133210
133691
|
await link(from, to);
|
|
133211
133692
|
}
|
|
@@ -133228,7 +133709,7 @@ async function runOrder(goal, options, root = process.cwd()) {
|
|
|
133228
133709
|
if (!options.resume && [options.retry, options.resolveEffect, options.effectResult, options.accountRun, options.accountCost].some((value) => value !== undefined && value !== false))
|
|
133229
133710
|
throw new Error("Use --resume <id> for retry, external-effect resolution or cost reconciliation.");
|
|
133230
133711
|
await ensureRuntimeGitignore(root);
|
|
133231
|
-
const store = new MissionStore(
|
|
133712
|
+
const store = new MissionStore(join64(root, ".agent-valley/missions"));
|
|
133232
133713
|
const id = options.resume ?? options.missionId ?? randomUUID24();
|
|
133233
133714
|
const unlock = await store.lock(id);
|
|
133234
133715
|
const abortController = new AbortController;
|
|
@@ -133277,7 +133758,7 @@ async function runOrder(goal, options, root = process.cwd()) {
|
|
|
133277
133758
|
throw new Error("Internal child launch does not match its saved operation, goal and accepted baseline. Restore the original operation checkpoint.");
|
|
133278
133759
|
if (Boolean(options.baselineWorkspace) !== Boolean(options.operationId))
|
|
133279
133760
|
throw new Error("An internal operation snapshot requires both its operation identity and accepted baseline.");
|
|
133280
|
-
const workspace = options.baselineWorkspace && options.operationId ? await createContinuousMissionWorkspace(config.workspace, options.operationId, options.baselineWorkspace, id, goal) : await new WorkspaceManager(config.workspace).create(missionIssue(id, goal), undefined, codeDelivery ?
|
|
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);
|
|
133281
133762
|
if (options.operationId)
|
|
133282
133763
|
await restoreOperationOrigin(config.workspace, workspace.path);
|
|
133283
133764
|
if (!codeDelivery)
|
|
@@ -133308,6 +133789,13 @@ async function runOrder(goal, options, root = process.cwd()) {
|
|
|
133308
133789
|
containerObservationPolicy: operation ? operation.containerObservationPolicy : config.containerObservationPolicy,
|
|
133309
133790
|
containerObservation: operation?.containerObservation,
|
|
133310
133791
|
toolEnvKeys: config.toolEnvKeys,
|
|
133792
|
+
...operation?.actorHealth?.length ? {
|
|
133793
|
+
operations: {
|
|
133794
|
+
runs: [],
|
|
133795
|
+
routingEvidence: seedProviderHealthEvidence([], operation.actorHealth),
|
|
133796
|
+
reviewDecisions: []
|
|
133797
|
+
}
|
|
133798
|
+
} : {},
|
|
133311
133799
|
capturePolicy: config.capturePolicy,
|
|
133312
133800
|
status: "pending",
|
|
133313
133801
|
tasks: [],
|
|
@@ -133352,6 +133840,8 @@ Resume: bun av order --resume ${id}`);
|
|
|
133352
133840
|
}
|
|
133353
133841
|
if (mission.operatingPolicy?.memory || mission.operatingPolicy?.metricTargets?.length) {
|
|
133354
133842
|
mission.organizationContext = await organizationContext2(repository, mission);
|
|
133843
|
+
if (!options.resume && mission.operations)
|
|
133844
|
+
mission.operations.routingEvidence = seedProviderHealthEvidence(mission.organizationContext.routeEvidence, aggregateProviderHealth(mission));
|
|
133355
133845
|
mission.operations ??= {
|
|
133356
133846
|
runs: [],
|
|
133357
133847
|
routingEvidence: mission.organizationContext.routeEvidence,
|
|
@@ -133442,7 +133932,7 @@ async function dispatchOrder(goal, options, root = process.cwd(), dependencies =
|
|
|
133442
133932
|
};
|
|
133443
133933
|
const [operation, mission] = await Promise.all([
|
|
133444
133934
|
operationStore(root).load(options.resume).catch(missing),
|
|
133445
|
-
new MissionStore(
|
|
133935
|
+
new MissionStore(join64(root, ".agent-valley", "missions")).load(options.resume).catch(missing)
|
|
133446
133936
|
]);
|
|
133447
133937
|
if (operation && mission)
|
|
133448
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.`);
|
|
@@ -133498,22 +133988,22 @@ function registerChiefCommands(program) {
|
|
|
133498
133988
|
}
|
|
133499
133989
|
|
|
133500
133990
|
// src/chief-organization.ts
|
|
133501
|
-
import { readFile as
|
|
133502
|
-
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";
|
|
133503
133993
|
init_chief_schema();
|
|
133504
133994
|
init_yaml_loader();
|
|
133505
133995
|
function organizationRepository(root, workspace) {
|
|
133506
133996
|
const repository = workspace ?? loadProjectConfig(root)?.workspace?.root ?? root;
|
|
133507
|
-
if (!
|
|
133997
|
+
if (!isAbsolute21(repository))
|
|
133508
133998
|
throw new Error("Set workspace.root in av.yaml or --workspace to an absolute source repository path.");
|
|
133509
133999
|
return repository;
|
|
133510
134000
|
}
|
|
133511
134001
|
async function inputFile(file) {
|
|
133512
134002
|
const path = resolve38(file);
|
|
133513
|
-
const info = await
|
|
134003
|
+
const info = await stat8(path);
|
|
133514
134004
|
if (!info.isFile() || info.size > 2000000)
|
|
133515
134005
|
throw new Error("Use a regular JSON input file no larger than 2 MB.");
|
|
133516
|
-
return
|
|
134006
|
+
return readFile23(path, "utf8");
|
|
133517
134007
|
}
|
|
133518
134008
|
function registerOrganizationCommands(program) {
|
|
133519
134009
|
const memory = program.command("memory").description("Repository organization decisions and standards");
|
|
@@ -133553,13 +134043,13 @@ function registerOrganizationCommands(program) {
|
|
|
133553
134043
|
});
|
|
133554
134044
|
const reports = program.command("reports").description("Inspect and retry third-party report attachments");
|
|
133555
134045
|
reports.command("list").option("--workspace <path>", "Source repository").action(async (opts) => {
|
|
133556
|
-
console.log(JSON.stringify(await listReportDeliveries(
|
|
134046
|
+
console.log(JSON.stringify(await listReportDeliveries(join65(organizationRepository(process.cwd(), opts.workspace), ".agent-valley")), null, 2));
|
|
133557
134047
|
});
|
|
133558
134048
|
reports.command("retry").option("--workspace <path>", "Source repository").action(async (opts) => {
|
|
133559
134049
|
const config = mergeChiefConfig(loadGlobalConfig()?.chief, loadProjectConfig()?.chief);
|
|
133560
134050
|
if (!config.reporting)
|
|
133561
134051
|
throw new Error("Set chief.reporting.destinations in av.yaml before retrying reports.");
|
|
133562
|
-
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));
|
|
133563
134053
|
});
|
|
133564
134054
|
}
|
|
133565
134055
|
|
|
@@ -133584,10 +134074,10 @@ var import_picocolors = __toESM(require_picocolors(), 1);
|
|
|
133584
134074
|
init_project_config_path();
|
|
133585
134075
|
init_yaml_loader();
|
|
133586
134076
|
init_doctor_checks();
|
|
133587
|
-
import { join as
|
|
134077
|
+
import { join as join69 } from "node:path";
|
|
133588
134078
|
|
|
133589
134079
|
// src/doctor-oma-checks.ts
|
|
133590
|
-
import { join as
|
|
134080
|
+
import { join as join68 } from "node:path";
|
|
133591
134081
|
function checkOma(project, deps) {
|
|
133592
134082
|
const strict = project?.oma?.mode === "strict";
|
|
133593
134083
|
const order = !!project && !project.tracker && !project.linear && !project.github;
|
|
@@ -133675,7 +134165,7 @@ function checkOma(project, deps) {
|
|
|
133675
134165
|
fix: "Set verify.command to a deterministic non-build check in av.yaml before using oma.mode: strict.",
|
|
133676
134166
|
critical: true
|
|
133677
134167
|
});
|
|
133678
|
-
const triggerPath =
|
|
134168
|
+
const triggerPath = join68(deps.cwd, ".agents", "hooks", "core", "triggers.json");
|
|
133679
134169
|
let table = null;
|
|
133680
134170
|
try {
|
|
133681
134171
|
table = parseTriggerTable(deps.readFileSync(triggerPath));
|
|
@@ -133692,7 +134182,7 @@ function checkOma(project, deps) {
|
|
|
133692
134182
|
return results;
|
|
133693
134183
|
}
|
|
133694
134184
|
results.push({ id: "oma.triggers", name: "OMA trigger table", status: "pass", message: triggerPath, critical: false });
|
|
133695
|
-
const missing = Object.entries(table.workflows).filter(([name, workflow]) => !workflow.persistent && !table.excludedWorkflows.includes(name)).map(([name]) =>
|
|
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));
|
|
133696
134186
|
results.push(missing.length === 0 ? {
|
|
133697
134187
|
id: "oma.workflows",
|
|
133698
134188
|
name: "OMA workflow files",
|
|
@@ -133767,7 +134257,7 @@ function checkTunnel(project, deps) {
|
|
|
133767
134257
|
}
|
|
133768
134258
|
const mode = project?.tunnel?.cloudflare?.mode ?? "quick";
|
|
133769
134259
|
if (mode === "named") {
|
|
133770
|
-
const certPath =
|
|
134260
|
+
const certPath = join69(deps.home, ".cloudflared", "cert.pem");
|
|
133771
134261
|
if (!deps.existsSync(certPath)) {
|
|
133772
134262
|
return {
|
|
133773
134263
|
id: "tunnel",
|
|
@@ -133807,7 +134297,7 @@ function checkTunnel(project, deps) {
|
|
|
133807
134297
|
critical: false
|
|
133808
134298
|
};
|
|
133809
134299
|
}
|
|
133810
|
-
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");
|
|
133811
134301
|
if (!deps.existsSync(ngrokConfigPath)) {
|
|
133812
134302
|
return {
|
|
133813
134303
|
id: "tunnel",
|
|
@@ -133878,7 +134368,7 @@ function checkConfig(deps) {
|
|
|
133878
134368
|
critical: true
|
|
133879
134369
|
});
|
|
133880
134370
|
}
|
|
133881
|
-
const projectPath =
|
|
134371
|
+
const projectPath = join69(deps.cwd, PROJECT_CONFIG_FILENAME);
|
|
133882
134372
|
try {
|
|
133883
134373
|
project = deps.loadProjectConfig(deps.cwd);
|
|
133884
134374
|
results.push(project ? {
|
|
@@ -138434,8 +138924,8 @@ init_team_relay_error();
|
|
|
138434
138924
|
|
|
138435
138925
|
// ../../packages/core/src/relay/turso-migration-assets.ts
|
|
138436
138926
|
init_zod();
|
|
138437
|
-
import { copyFile as copyFile3, lstat as
|
|
138438
|
-
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";
|
|
138439
138929
|
import { fileURLToPath as fileURLToPath3 } from "node:url";
|
|
138440
138930
|
var TURSO_MIGRATION_ASSET_PATH = "assets/turso/migrations";
|
|
138441
138931
|
var journalSchema = object({
|
|
@@ -138456,7 +138946,7 @@ function tursoMigrationAssetCandidates(moduleUrl = import.meta.url) {
|
|
|
138456
138946
|
];
|
|
138457
138947
|
}
|
|
138458
138948
|
async function regularFile2(path) {
|
|
138459
|
-
const info = await
|
|
138949
|
+
const info = await lstat33(path);
|
|
138460
138950
|
if (!info.isFile() || info.isSymbolicLink())
|
|
138461
138951
|
throw new Error(`Turso migration asset ${path} must be a regular file. Restore the checkout or reinstall the CLI package.`);
|
|
138462
138952
|
}
|
|
@@ -138464,7 +138954,7 @@ async function loadTursoMigrationAssets(candidates = tursoMigrationAssetCandidat
|
|
|
138464
138954
|
for (const directory of candidates) {
|
|
138465
138955
|
let info;
|
|
138466
138956
|
try {
|
|
138467
|
-
info = await
|
|
138957
|
+
info = await lstat33(directory);
|
|
138468
138958
|
} catch (error) {
|
|
138469
138959
|
if (error.code === "ENOENT")
|
|
138470
138960
|
continue;
|
|
@@ -138473,19 +138963,19 @@ async function loadTursoMigrationAssets(candidates = tursoMigrationAssetCandidat
|
|
|
138473
138963
|
if (!info.isDirectory() || info.isSymbolicLink())
|
|
138474
138964
|
throw new Error(`Turso migration directory ${directory} must be a regular directory. Restore the checkout or reinstall the CLI package.`);
|
|
138475
138965
|
try {
|
|
138476
|
-
const meta = await
|
|
138966
|
+
const meta = await lstat33(join75(directory, "meta"));
|
|
138477
138967
|
if (!meta.isDirectory() || meta.isSymbolicLink())
|
|
138478
138968
|
throw new Error("Invalid migration metadata directory");
|
|
138479
|
-
const journalPath =
|
|
138969
|
+
const journalPath = join75(directory, "meta/_journal.json");
|
|
138480
138970
|
await regularFile2(journalPath);
|
|
138481
|
-
const journal = journalSchema.parse(JSON.parse(await
|
|
138971
|
+
const journal = journalSchema.parse(JSON.parse(await readFile25(journalPath, "utf8")));
|
|
138482
138972
|
const tags = journal.entries.map((entry) => entry.tag);
|
|
138483
138973
|
if (new Set(tags).size !== tags.length)
|
|
138484
138974
|
throw new Error("Duplicate migration tags");
|
|
138485
138975
|
const files = ["meta/_journal.json", ...tags.map((tag) => `${tag}.sql`)];
|
|
138486
138976
|
for (const file of files.slice(1)) {
|
|
138487
|
-
await regularFile2(
|
|
138488
|
-
if (!(await
|
|
138977
|
+
await regularFile2(join75(directory, file));
|
|
138978
|
+
if (!(await readFile25(join75(directory, file), "utf8")).trim())
|
|
138489
138979
|
throw new Error("Empty migration SQL");
|
|
138490
138980
|
}
|
|
138491
138981
|
return { directory, files };
|