@akagilnc/pi-workflow-roles 0.1.4620 → 0.1.4641
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/README.zh-CN.md +1 -1
- package/dist/acp-host/production-host.js +962 -547
- package/dist/activation-ledger-topology.js +0 -4
- package/dist/gatekeeper-role.js +76 -6
- package/dist/headless-host/production-host.js +923 -508
- package/dist/migrate-book-topology.js +9 -0
- package/dist/pi/role-turn-host.js +0 -3
- package/dist/public-cli/auto-resume.js +26 -0
- package/dist/public-cli/countersign-run.js +31 -10
- package/dist/public-cli/main.js +1456 -1068
- package/dist/public-cli/post-admission.js +101 -7
- package/dist/public-cli/process-cancel.js +57 -0
- package/dist/public-cli/settlement.js +95 -2
- package/dist/public-role-summons.js +19 -0
- package/dist/secretariat-contracts.js +4 -0
- package/package.json +1 -1
- package/scripts/build-package.mjs +0 -1
- package/src/activation-ledger-topology.ts +1 -6
- package/src/activation-ledger.ts +5 -236
- package/src/analyst-entry.ts +19 -2
- package/src/analyst-ledger.ts +111 -6
- package/src/archivist-record-entry.ts +3 -3
- package/src/audit-escalation.ts +1 -1
- package/src/gatekeeper-pass-envelope.ts +37 -5
- package/src/gatekeeper-role.ts +125 -20
- package/src/host-contracts.ts +22 -2
- package/src/pi/adapter.ts +5 -1
- package/src/pi/role-turn-host.ts +0 -3
- package/src/public-cli/auto-resume.ts +34 -0
- package/src/public-cli/cli.ts +30 -0
- package/src/public-cli/countersign-run.ts +50 -13
- package/src/public-cli/main.ts +25 -3
- package/src/public-cli/post-admission.ts +173 -6
- package/src/public-cli/process-cancel.ts +75 -0
- package/src/public-cli/settlement.ts +117 -1
- package/src/public-role-summons.ts +30 -4
- package/src/role-envelope.ts +27 -10
- package/src/role-runtime.ts +146 -55
- package/src/secretariat-contracts.ts +18 -0
- package/dist/activation-reconciliation.js +0 -61
- package/src/activation-reconciliation.ts +0 -163
|
@@ -62,7 +62,7 @@ async function spawnEngineDetourOnce(input) {
|
|
|
62
62
|
}
|
|
63
63
|
const command = input.argv[0];
|
|
64
64
|
const args = input.argv.slice(1);
|
|
65
|
-
return await new Promise((
|
|
65
|
+
return await new Promise((resolve21, reject) => {
|
|
66
66
|
let settled = false;
|
|
67
67
|
const signal = input.signal;
|
|
68
68
|
const child = spawn(command, args, {
|
|
@@ -92,7 +92,7 @@ async function spawnEngineDetourOnce(input) {
|
|
|
92
92
|
if (signal !== void 0) {
|
|
93
93
|
signal.removeEventListener("abort", onAbort);
|
|
94
94
|
}
|
|
95
|
-
|
|
95
|
+
resolve21(result);
|
|
96
96
|
};
|
|
97
97
|
const onAbort = () => {
|
|
98
98
|
fail4(signal !== void 0 ? abortReasonError(signal) : new Error("aborted"));
|
|
@@ -202,7 +202,6 @@ var activation_ledger_topology_exports = {};
|
|
|
202
202
|
__export(activation_ledger_topology_exports, {
|
|
203
203
|
ActivationLedgerError: () => ActivationLedgerError,
|
|
204
204
|
activationBookDirectory: () => activationBookDirectory,
|
|
205
|
-
activationWaitingLedgerPath: () => activationWaitingLedgerPath,
|
|
206
205
|
assertLedgerFileInsideHome: () => assertLedgerFileInsideHome,
|
|
207
206
|
ensureRealDirectoryTree: () => ensureRealDirectoryTree,
|
|
208
207
|
errnoCode: () => errnoCode,
|
|
@@ -265,9 +264,6 @@ function resolveActivationLedgerHomeForPath(path) {
|
|
|
265
264
|
function activationBookDirectory(ledgerHome, bookKey) {
|
|
266
265
|
return join2(ledgerHome, "books", bookKey);
|
|
267
266
|
}
|
|
268
|
-
function activationWaitingLedgerPath(ledgerHome, bookKey) {
|
|
269
|
-
return join2(activationBookDirectory(ledgerHome, bookKey), "waiting.jsonl");
|
|
270
|
-
}
|
|
271
267
|
function pathContainedIn(root, candidate) {
|
|
272
268
|
const rel = relative(root, candidate);
|
|
273
269
|
return rel !== "" && rel !== ".." && !rel.startsWith(`..${sep}`) && !isAbsolute(rel);
|
|
@@ -930,6 +926,15 @@ var init_archivist_record_entry = __esm({
|
|
|
930
926
|
});
|
|
931
927
|
|
|
932
928
|
// src/run-ticket-number.ts
|
|
929
|
+
var run_ticket_number_exports = {};
|
|
930
|
+
__export(run_ticket_number_exports, {
|
|
931
|
+
MIGRATION_TICKET_DERIVATION_PAGE: () => MIGRATION_TICKET_DERIVATION_PAGE,
|
|
932
|
+
isSafePositiveTicketNumber: () => isSafePositiveTicketNumber,
|
|
933
|
+
readBoardTicketNumber: () => readBoardTicketNumber,
|
|
934
|
+
readMigrationDerivedTicketNumber: () => readMigrationDerivedTicketNumber,
|
|
935
|
+
readRunTicketNumber: () => readRunTicketNumber,
|
|
936
|
+
requireSafePositiveTicketNumber: () => requireSafePositiveTicketNumber
|
|
937
|
+
});
|
|
933
938
|
import { readFile } from "node:fs/promises";
|
|
934
939
|
import { join as join5 } from "node:path";
|
|
935
940
|
function isEnoent(error) {
|
|
@@ -969,9 +974,22 @@ async function readBoardPageTicketNumber(runDirectory, page) {
|
|
|
969
974
|
async function readBoardTicketNumber(runDirectory) {
|
|
970
975
|
return await readBoardPageTicketNumber(runDirectory, "admitted-request.json") ?? await readBoardPageTicketNumber(runDirectory, "invocation.json");
|
|
971
976
|
}
|
|
977
|
+
async function readMigrationDerivedTicketNumber(runDirectory) {
|
|
978
|
+
const record4 = await readJsonObject(
|
|
979
|
+
join5(runDirectory, MIGRATION_TICKET_DERIVATION_PAGE)
|
|
980
|
+
);
|
|
981
|
+
if (record4 === void 0) return void 0;
|
|
982
|
+
if (record4.derivation !== "worktree-path-basename") return void 0;
|
|
983
|
+
return ticketFromRecord(record4);
|
|
984
|
+
}
|
|
985
|
+
async function readRunTicketNumber(runDirectory) {
|
|
986
|
+
return await readBoardTicketNumber(runDirectory) ?? await readMigrationDerivedTicketNumber(runDirectory);
|
|
987
|
+
}
|
|
988
|
+
var MIGRATION_TICKET_DERIVATION_PAGE;
|
|
972
989
|
var init_run_ticket_number = __esm({
|
|
973
990
|
"src/run-ticket-number.ts"() {
|
|
974
991
|
"use strict";
|
|
992
|
+
MIGRATION_TICKET_DERIVATION_PAGE = "migration-ticket-derivation.json";
|
|
975
993
|
}
|
|
976
994
|
});
|
|
977
995
|
|
|
@@ -1354,15 +1372,165 @@ var init_gatekeeper_output = __esm({
|
|
|
1354
1372
|
}
|
|
1355
1373
|
});
|
|
1356
1374
|
|
|
1375
|
+
// src/run-terminal-artifacts.ts
|
|
1376
|
+
var run_terminal_artifacts_exports = {};
|
|
1377
|
+
__export(run_terminal_artifacts_exports, {
|
|
1378
|
+
RUN_TERMINAL_ARTIFACT_FILES: () => RUN_TERMINAL_ARTIFACT_FILES,
|
|
1379
|
+
RUN_TERMINAL_ERROR_FALLBACK_RELATIVE_PATHS: () => RUN_TERMINAL_ERROR_FALLBACK_RELATIVE_PATHS,
|
|
1380
|
+
isUniqueErrorFallbackName: () => isUniqueErrorFallbackName,
|
|
1381
|
+
readRunTerminalArtifact: () => readRunTerminalArtifact,
|
|
1382
|
+
runIdFromRunDirectory: () => runIdFromRunDirectory
|
|
1383
|
+
});
|
|
1384
|
+
import { readdir as readdir2, readFile as readFile2 } from "node:fs/promises";
|
|
1385
|
+
import { basename as basename3, dirname as dirname5, join as join8 } from "node:path";
|
|
1386
|
+
function isMissingPathError2(error) {
|
|
1387
|
+
return error instanceof Error && "code" in error && (error.code === "ENOENT" || error.code === "ENOTDIR");
|
|
1388
|
+
}
|
|
1389
|
+
function errorText2(error) {
|
|
1390
|
+
return error instanceof Error ? error.message : String(error);
|
|
1391
|
+
}
|
|
1392
|
+
function isRecord(value) {
|
|
1393
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
1394
|
+
}
|
|
1395
|
+
function readUsableTerminalArtifactBody(body) {
|
|
1396
|
+
if (body === null) {
|
|
1397
|
+
return { ok: false, reason: "terminal artifact JSON value is null" };
|
|
1398
|
+
}
|
|
1399
|
+
if (!isRecord(body)) {
|
|
1400
|
+
return {
|
|
1401
|
+
ok: false,
|
|
1402
|
+
reason: `terminal artifact JSON value is not a typed object (${Array.isArray(body) ? "array" : typeof body})`
|
|
1403
|
+
};
|
|
1404
|
+
}
|
|
1405
|
+
if (typeof body.role !== "string" || body.role.trim() === "") {
|
|
1406
|
+
return {
|
|
1407
|
+
ok: false,
|
|
1408
|
+
reason: "terminal artifact missing nonblank producer-owned role field"
|
|
1409
|
+
};
|
|
1410
|
+
}
|
|
1411
|
+
return { ok: true, body };
|
|
1412
|
+
}
|
|
1413
|
+
async function readTerminalArtifactAtPath(path, file) {
|
|
1414
|
+
let raw;
|
|
1415
|
+
try {
|
|
1416
|
+
raw = await readFile2(path, "utf8");
|
|
1417
|
+
} catch (error) {
|
|
1418
|
+
if (isMissingPathError2(error)) return void 0;
|
|
1419
|
+
return {
|
|
1420
|
+
status: "unreadable",
|
|
1421
|
+
file,
|
|
1422
|
+
path,
|
|
1423
|
+
reason: errorText2(error)
|
|
1424
|
+
};
|
|
1425
|
+
}
|
|
1426
|
+
let parsed;
|
|
1427
|
+
try {
|
|
1428
|
+
parsed = JSON.parse(raw);
|
|
1429
|
+
} catch (error) {
|
|
1430
|
+
return {
|
|
1431
|
+
status: "unreadable",
|
|
1432
|
+
file,
|
|
1433
|
+
path,
|
|
1434
|
+
reason: error instanceof Error ? error.message : `terminal artifact JSON parse failed: ${String(error)}`
|
|
1435
|
+
};
|
|
1436
|
+
}
|
|
1437
|
+
const usable = readUsableTerminalArtifactBody(parsed);
|
|
1438
|
+
if (!usable.ok) {
|
|
1439
|
+
return {
|
|
1440
|
+
status: "unreadable",
|
|
1441
|
+
file,
|
|
1442
|
+
path,
|
|
1443
|
+
reason: usable.reason
|
|
1444
|
+
};
|
|
1445
|
+
}
|
|
1446
|
+
return { status: "present", file, path, body: usable.body };
|
|
1447
|
+
}
|
|
1448
|
+
async function listUniqueErrorFallbackPaths(directories) {
|
|
1449
|
+
const found = [];
|
|
1450
|
+
for (const dir of directories) {
|
|
1451
|
+
let names;
|
|
1452
|
+
try {
|
|
1453
|
+
names = await readdir2(dir);
|
|
1454
|
+
} catch (error) {
|
|
1455
|
+
if (isMissingPathError2(error)) continue;
|
|
1456
|
+
throw error;
|
|
1457
|
+
}
|
|
1458
|
+
for (const name of names.sort((a, b) => a.localeCompare(b))) {
|
|
1459
|
+
if (!UNIQUE_ERROR_FALLBACK_NAME.test(name)) continue;
|
|
1460
|
+
found.push(join8(dir, name));
|
|
1461
|
+
}
|
|
1462
|
+
}
|
|
1463
|
+
return found;
|
|
1464
|
+
}
|
|
1465
|
+
function runIdFromRunDirectory(runDirectory) {
|
|
1466
|
+
const name = basename3(runDirectory);
|
|
1467
|
+
const at = name.lastIndexOf("@");
|
|
1468
|
+
if (at <= 0 || at === name.length - 1) return void 0;
|
|
1469
|
+
return name.slice(0, at);
|
|
1470
|
+
}
|
|
1471
|
+
function presentUniqueFallbackBoundToRun(body, expectedRunId) {
|
|
1472
|
+
if (expectedRunId === void 0) return false;
|
|
1473
|
+
return typeof body.runId === "string" && body.runId === expectedRunId;
|
|
1474
|
+
}
|
|
1475
|
+
async function readRunTerminalArtifact(runDirectory) {
|
|
1476
|
+
const artifactsDir = roleRunArtifactsDirectory(runDirectory);
|
|
1477
|
+
for (const file of RUN_TERMINAL_ARTIFACT_FILES) {
|
|
1478
|
+
const path = join8(artifactsDir, file);
|
|
1479
|
+
const read = await readTerminalArtifactAtPath(path, file);
|
|
1480
|
+
if (read !== void 0) return read;
|
|
1481
|
+
}
|
|
1482
|
+
for (const relative5 of RUN_TERMINAL_ERROR_FALLBACK_RELATIVE_PATHS) {
|
|
1483
|
+
const path = join8(runDirectory, relative5);
|
|
1484
|
+
const read = await readTerminalArtifactAtPath(path, "error.json");
|
|
1485
|
+
if (read !== void 0) return read;
|
|
1486
|
+
}
|
|
1487
|
+
for (const path of await listUniqueErrorFallbackPaths([artifactsDir, runDirectory])) {
|
|
1488
|
+
const read = await readTerminalArtifactAtPath(path, "error.json");
|
|
1489
|
+
if (read !== void 0) return read;
|
|
1490
|
+
}
|
|
1491
|
+
const expectedRunId = runIdFromRunDirectory(runDirectory);
|
|
1492
|
+
for (const path of await listUniqueErrorFallbackPaths([dirname5(runDirectory)])) {
|
|
1493
|
+
const read = await readTerminalArtifactAtPath(path, "error.json");
|
|
1494
|
+
if (read === void 0) continue;
|
|
1495
|
+
if (read.status === "present") {
|
|
1496
|
+
if (!presentUniqueFallbackBoundToRun(read.body, expectedRunId)) continue;
|
|
1497
|
+
return read;
|
|
1498
|
+
}
|
|
1499
|
+
}
|
|
1500
|
+
return { status: "absent" };
|
|
1501
|
+
}
|
|
1502
|
+
function isUniqueErrorFallbackName(name) {
|
|
1503
|
+
return UNIQUE_ERROR_FALLBACK_NAME.test(basename3(name));
|
|
1504
|
+
}
|
|
1505
|
+
var RUN_TERMINAL_ARTIFACT_FILES, RUN_TERMINAL_ERROR_FALLBACK_RELATIVE_PATHS, UNIQUE_ERROR_FALLBACK_NAME;
|
|
1506
|
+
var init_run_terminal_artifacts = __esm({
|
|
1507
|
+
"src/run-terminal-artifacts.ts"() {
|
|
1508
|
+
"use strict";
|
|
1509
|
+
init_role_run_placement();
|
|
1510
|
+
RUN_TERMINAL_ARTIFACT_FILES = [
|
|
1511
|
+
"report.json",
|
|
1512
|
+
"error.json",
|
|
1513
|
+
"audit-incomplete.json"
|
|
1514
|
+
];
|
|
1515
|
+
RUN_TERMINAL_ERROR_FALLBACK_RELATIVE_PATHS = [
|
|
1516
|
+
"artifacts/error.settlement.json",
|
|
1517
|
+
"error.settlement.json"
|
|
1518
|
+
];
|
|
1519
|
+
UNIQUE_ERROR_FALLBACK_NAME = /^error\.[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\.json$/i;
|
|
1520
|
+
}
|
|
1521
|
+
});
|
|
1522
|
+
|
|
1357
1523
|
// src/gatekeeper-role.ts
|
|
1358
1524
|
function gateSeatLabel(stage) {
|
|
1359
1525
|
if (stage === "inspector") return "\u53F0\u9662";
|
|
1360
1526
|
if (stage === "auditor") return "\u5BA1\u5211\u9662";
|
|
1527
|
+
if (stage === "countersign") return "\u7ED9\u4E8B\u4E2D";
|
|
1361
1528
|
return "\u7B26\u5B9D\u90CE";
|
|
1362
1529
|
}
|
|
1363
1530
|
function gateOfficerForSubject(subject) {
|
|
1364
1531
|
if (subject.kind === "worker_completion") return "inspector";
|
|
1365
1532
|
if (subject.kind === "judge_compliance") return "auditor";
|
|
1533
|
+
if (subject.kind === "secretariat_verdict") return "countersign";
|
|
1366
1534
|
return "notary";
|
|
1367
1535
|
}
|
|
1368
1536
|
function failureReason(error) {
|
|
@@ -1376,9 +1544,26 @@ function readRecord(value) {
|
|
|
1376
1544
|
if (typeof value !== "object" || value === null || Array.isArray(value)) return void 0;
|
|
1377
1545
|
return value;
|
|
1378
1546
|
}
|
|
1547
|
+
function gateStatusFromCountersign(status) {
|
|
1548
|
+
if (status === "converged") return "pass";
|
|
1549
|
+
if (status === "continue") return "bounce";
|
|
1550
|
+
if (status === "escalate") return "escalate";
|
|
1551
|
+
return void 0;
|
|
1552
|
+
}
|
|
1379
1553
|
function projectOfficerDecision(officer, decision, fallbackStatus) {
|
|
1380
1554
|
const receipt = retainedReceipt(decision);
|
|
1381
1555
|
const record4 = readRecord(decision);
|
|
1556
|
+
if (officer === "countersign") {
|
|
1557
|
+
const countersignStatus = record4 !== void 0 && typeof record4.countersignStatus === "string" ? record4.countersignStatus : void 0;
|
|
1558
|
+
const status2 = typeof countersignStatus === "string" ? gateStatusFromCountersign(countersignStatus) : void 0;
|
|
1559
|
+
if (status2 === "pass") {
|
|
1560
|
+
return { status: "pass", officer, receipt };
|
|
1561
|
+
}
|
|
1562
|
+
if (status2 === "bounce" || status2 === "escalate") {
|
|
1563
|
+
return { status: status2, officer, receipt };
|
|
1564
|
+
}
|
|
1565
|
+
return { status: "needs_reask", officer, receipt };
|
|
1566
|
+
}
|
|
1382
1567
|
const status = (record4 !== void 0 && typeof record4.status === "string" ? record4.status : void 0) ?? fallbackStatus;
|
|
1383
1568
|
if (status === "pass") {
|
|
1384
1569
|
return { status: "pass", officer, receipt };
|
|
@@ -1409,6 +1594,26 @@ function projectOfficerPayloads(officer, payloads, fallbackStatus) {
|
|
|
1409
1594
|
}
|
|
1410
1595
|
return projectOfficerDecision(officer, payloads[payloads.length - 1], fallbackStatus);
|
|
1411
1596
|
}
|
|
1597
|
+
function officerRunIdFromSummoned(summoned) {
|
|
1598
|
+
if (typeof summoned.runDirectory === "string" && summoned.runDirectory.trim() !== "") {
|
|
1599
|
+
const fromDir = runIdFromRunDirectory(summoned.runDirectory);
|
|
1600
|
+
if (fromDir !== void 0) return fromDir;
|
|
1601
|
+
}
|
|
1602
|
+
const terminal = summoned.terminal;
|
|
1603
|
+
if (terminal !== void 0 && typeof terminal.runId === "string" && terminal.runId.trim() !== "") {
|
|
1604
|
+
return terminal.runId;
|
|
1605
|
+
}
|
|
1606
|
+
return void 0;
|
|
1607
|
+
}
|
|
1608
|
+
function withOfficerRunId(result, summoned) {
|
|
1609
|
+
if (result.status !== "pass" && result.status !== "bounce" && result.status !== "escalate" && result.status !== "needs_reask") {
|
|
1610
|
+
return result;
|
|
1611
|
+
}
|
|
1612
|
+
if (typeof result.runId === "string" && result.runId.trim() !== "") return result;
|
|
1613
|
+
const runId = officerRunIdFromSummoned(summoned);
|
|
1614
|
+
if (runId === void 0) return result;
|
|
1615
|
+
return { ...result, runId };
|
|
1616
|
+
}
|
|
1412
1617
|
function projectOfficerTerminal(officer, summoned) {
|
|
1413
1618
|
const terminal = summoned.terminal;
|
|
1414
1619
|
const outcome = terminal?.roleOutcome;
|
|
@@ -1441,22 +1646,34 @@ function projectOfficerTerminal(officer, summoned) {
|
|
|
1441
1646
|
};
|
|
1442
1647
|
}
|
|
1443
1648
|
if (outcome.kind === "audit_escalation") {
|
|
1444
|
-
return
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1649
|
+
return withOfficerRunId(
|
|
1650
|
+
{
|
|
1651
|
+
status: "escalate",
|
|
1652
|
+
officer,
|
|
1653
|
+
// This-court receipt only (#879) — historical rows remain on terminal.submissions.
|
|
1654
|
+
receipt: thisCourt.length > 0 ? thisCourt[thisCourt.length - 1] : retainedReceipt(outcome)
|
|
1655
|
+
},
|
|
1656
|
+
summoned
|
|
1657
|
+
);
|
|
1450
1658
|
}
|
|
1451
1659
|
if (outcome.kind === "accepted") {
|
|
1452
|
-
return
|
|
1660
|
+
return withOfficerRunId(
|
|
1661
|
+
projectOfficerPayloads(officer, thisCourt, outcome.status),
|
|
1662
|
+
summoned
|
|
1663
|
+
);
|
|
1453
1664
|
}
|
|
1454
|
-
return
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1665
|
+
return withOfficerRunId(
|
|
1666
|
+
{
|
|
1667
|
+
status: "needs_reask",
|
|
1668
|
+
officer,
|
|
1669
|
+
// This-court receipt only (#879).
|
|
1670
|
+
receipt: thisCourt.length > 0 ? thisCourt[thisCourt.length - 1] : retainedReceipt(outcome)
|
|
1671
|
+
},
|
|
1672
|
+
summoned
|
|
1673
|
+
);
|
|
1674
|
+
}
|
|
1675
|
+
function officerConclusionReask(officer) {
|
|
1676
|
+
return officer === "countersign" ? COUNTERSIGN_CONCLUSION_REASK : OFFICER_CONCLUSION_REASK;
|
|
1460
1677
|
}
|
|
1461
1678
|
async function projectGatekeeperRun(options) {
|
|
1462
1679
|
const officer = gateOfficerForSubject(options.subject);
|
|
@@ -1492,7 +1709,7 @@ async function projectGatekeeperRun(options) {
|
|
|
1492
1709
|
summoned
|
|
1493
1710
|
};
|
|
1494
1711
|
}
|
|
1495
|
-
var GATEKEEPER_TOOL_SPEC, OFFICER_CONCLUSION_REASK;
|
|
1712
|
+
var GATEKEEPER_TOOL_SPEC, OFFICER_CONCLUSION_REASK, COUNTERSIGN_CONCLUSION_REASK;
|
|
1496
1713
|
var init_gatekeeper_role = __esm({
|
|
1497
1714
|
"src/gatekeeper-role.ts"() {
|
|
1498
1715
|
"use strict";
|
|
@@ -1500,6 +1717,7 @@ var init_gatekeeper_role = __esm({
|
|
|
1500
1717
|
init_submission_errors();
|
|
1501
1718
|
init_inspector_contracts();
|
|
1502
1719
|
init_gatekeeper_output();
|
|
1720
|
+
init_run_terminal_artifacts();
|
|
1503
1721
|
init_submission_errors();
|
|
1504
1722
|
GATEKEEPER_TOOL_SPEC = {
|
|
1505
1723
|
name: GATEKEEPER_OUTPUT_TOOL_NAME,
|
|
@@ -1509,6 +1727,7 @@ var init_gatekeeper_role = __esm({
|
|
|
1509
1727
|
parameters: gatekeeperOutputSchema
|
|
1510
1728
|
};
|
|
1511
1729
|
OFFICER_CONCLUSION_REASK = "\u4E0A\u6B21\u4EA4\u5377\u7684\u7ED3\u8BBA\u4E0D\u662F pass\u3001bounce\u3001escalate \u4E09\u6001\u4E4B\u4E00\u3002\u8BF7\u91CD\u65B0\u8F93\u51FA\uFF0C\u7ED3\u8BBA\u5B57\u6BB5\u5199\u660E\u5176\u4E00\uFF1B\u6253\u56DE\u6216\u4E0A\u5448\u7684\u8BDD\u5C31\u662F\u7ED9\u5BF9\u65B9\u770B\u7684\u539F\u6587\u3002";
|
|
1730
|
+
COUNTERSIGN_CONCLUSION_REASK = "\u4E0A\u6B21\u4EA4\u5377\u7684 countersignStatus \u4E0D\u662F converged\u3001continue\u3001escalate \u4E09\u6001\u4E4B\u4E00\u3002\u8BF7\u91CD\u65B0\u8F93\u51FA\uFF0CcountersignStatus \u5199\u660E\u5176\u4E00\uFF1B\u5C01\u9A73\u6216\u4E0A\u5448\u7684\u8BDD\u5C31\u662F\u7ED9\u5BF9\u65B9\u770B\u7684\u539F\u6587\u3002";
|
|
1512
1731
|
}
|
|
1513
1732
|
});
|
|
1514
1733
|
|
|
@@ -1519,12 +1738,12 @@ __export(session_assistant_usage_exports, {
|
|
|
1519
1738
|
sessionFileFromPublicSummon: () => sessionFileFromPublicSummon,
|
|
1520
1739
|
usageFromPublicSummon: () => usageFromPublicSummon
|
|
1521
1740
|
});
|
|
1522
|
-
import { join as
|
|
1741
|
+
import { join as join9 } from "node:path";
|
|
1523
1742
|
async function readAssistantUsageFromSessionFile(sessionFile) {
|
|
1524
|
-
const { readFile:
|
|
1743
|
+
const { readFile: readFile24 } = await import("node:fs/promises");
|
|
1525
1744
|
let text;
|
|
1526
1745
|
try {
|
|
1527
|
-
text = await
|
|
1746
|
+
text = await readFile24(sessionFile, "utf8");
|
|
1528
1747
|
} catch (error) {
|
|
1529
1748
|
if (error?.code === "ENOENT") return void 0;
|
|
1530
1749
|
throw error;
|
|
@@ -1589,7 +1808,7 @@ async function readAssistantUsageFromSessionFile(sessionFile) {
|
|
|
1589
1808
|
}
|
|
1590
1809
|
function sessionFileFromPublicSummon(summoned) {
|
|
1591
1810
|
if (typeof summoned.runDirectory === "string" && summoned.runDirectory.trim() !== "") {
|
|
1592
|
-
return
|
|
1811
|
+
return join9(summoned.runDirectory, "session", "session.jsonl");
|
|
1593
1812
|
}
|
|
1594
1813
|
const fromArtifacts = summoned.terminal?.artifacts?.map((a) => a.path).find((p) => typeof p === "string" && p.endsWith("session.jsonl"));
|
|
1595
1814
|
if (fromArtifacts !== void 0) return fromArtifacts;
|
|
@@ -1598,7 +1817,7 @@ function sessionFileFromPublicSummon(summoned) {
|
|
|
1598
1817
|
const facts = outcome.decisiveFacts;
|
|
1599
1818
|
const pointer = facts?.runPointer;
|
|
1600
1819
|
if (typeof pointer === "string" && pointer.trim() !== "") {
|
|
1601
|
-
return
|
|
1820
|
+
return join9(pointer, "session", "session.jsonl");
|
|
1602
1821
|
}
|
|
1603
1822
|
return void 0;
|
|
1604
1823
|
}
|
|
@@ -1615,7 +1834,7 @@ var init_session_assistant_usage = __esm({
|
|
|
1615
1834
|
|
|
1616
1835
|
// src/package-resources/engine-material.ts
|
|
1617
1836
|
import { existsSync as existsSync2, readdirSync as readdirSync2 } from "node:fs";
|
|
1618
|
-
import { join as
|
|
1837
|
+
import { join as join10 } from "node:path";
|
|
1619
1838
|
function pickEngineAxis(source) {
|
|
1620
1839
|
return {
|
|
1621
1840
|
...source.engine === void 0 ? {} : { engine: source.engine },
|
|
@@ -1636,11 +1855,11 @@ function isEngineNameSyntax(name) {
|
|
|
1636
1855
|
return true;
|
|
1637
1856
|
}
|
|
1638
1857
|
function resolveEngineMaterialDirectory(packageRoot) {
|
|
1639
|
-
return
|
|
1858
|
+
return join10(packageRoot, ENGINE_MATERIAL_RELATIVE_ROOT);
|
|
1640
1859
|
}
|
|
1641
1860
|
function resolveEngineMaterialPath(packageRoot, name) {
|
|
1642
1861
|
const legal = assertLegalEngineName(name);
|
|
1643
|
-
return
|
|
1862
|
+
return join10(resolveEngineMaterialDirectory(packageRoot), `${legal}.md`);
|
|
1644
1863
|
}
|
|
1645
1864
|
function assertLegalEngineName(name) {
|
|
1646
1865
|
if (!isEngineNameSyntax(name)) {
|
|
@@ -1698,7 +1917,7 @@ __export(durable_principal_exports, {
|
|
|
1698
1917
|
piDurablePrincipalAuthority: () => piDurablePrincipalAuthority
|
|
1699
1918
|
});
|
|
1700
1919
|
import { lstat } from "node:fs/promises";
|
|
1701
|
-
import { join as
|
|
1920
|
+
import { join as join11 } from "node:path";
|
|
1702
1921
|
function encode(coordinates) {
|
|
1703
1922
|
return coordinates;
|
|
1704
1923
|
}
|
|
@@ -1748,7 +1967,7 @@ var init_durable_principal = __esm({
|
|
|
1748
1967
|
}
|
|
1749
1968
|
return {
|
|
1750
1969
|
sessionDirectory: record4.sessionDirectory,
|
|
1751
|
-
sessionFile: typeof record4.sessionFile === "string" && record4.sessionFile.trim() !== "" ? record4.sessionFile :
|
|
1970
|
+
sessionFile: typeof record4.sessionFile === "string" && record4.sessionFile.trim() !== "" ? record4.sessionFile : join11(record4.sessionDirectory, "session.jsonl")
|
|
1752
1971
|
};
|
|
1753
1972
|
},
|
|
1754
1973
|
async isAvailable(principal) {
|
|
@@ -2354,7 +2573,7 @@ var init_auditor_output = __esm({
|
|
|
2354
2573
|
});
|
|
2355
2574
|
|
|
2356
2575
|
// src/ticket-provenance-contracts.ts
|
|
2357
|
-
function
|
|
2576
|
+
function isRecord2(value) {
|
|
2358
2577
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
2359
2578
|
}
|
|
2360
2579
|
function positiveInteger(value) {
|
|
@@ -2377,7 +2596,7 @@ function projectSpeaker(value) {
|
|
|
2377
2596
|
return value === "owner" || value === "runner" ? value : void 0;
|
|
2378
2597
|
}
|
|
2379
2598
|
function projectBound(value) {
|
|
2380
|
-
if (!
|
|
2599
|
+
if (!isRecord2(value)) return void 0;
|
|
2381
2600
|
const id = typeof value.id === "string" && value.id !== "" ? value.id : void 0;
|
|
2382
2601
|
const line2 = positiveInteger(value.line);
|
|
2383
2602
|
if (id === void 0 && line2 === void 0) return void 0;
|
|
@@ -2388,13 +2607,13 @@ function projectTicketProvenanceSessions(value) {
|
|
|
2388
2607
|
if (value.length === 0) return [];
|
|
2389
2608
|
const sessions = [];
|
|
2390
2609
|
for (const raw of value) {
|
|
2391
|
-
if (!
|
|
2610
|
+
if (!isRecord2(raw)) return void 0;
|
|
2392
2611
|
const path = raw.path;
|
|
2393
2612
|
if (typeof path !== "string" || path.trim() === "") return void 0;
|
|
2394
2613
|
if (!Array.isArray(raw.ranges) || raw.ranges.length === 0) return void 0;
|
|
2395
2614
|
const ranges = [];
|
|
2396
2615
|
for (const rawRange of raw.ranges) {
|
|
2397
|
-
if (!
|
|
2616
|
+
if (!isRecord2(rawRange)) return void 0;
|
|
2398
2617
|
const from = projectBound(rawRange.from);
|
|
2399
2618
|
const to = projectBound(rawRange.to);
|
|
2400
2619
|
if (from === void 0 || to === void 0) return void 0;
|
|
@@ -2405,7 +2624,7 @@ function projectTicketProvenanceSessions(value) {
|
|
|
2405
2624
|
return sessions;
|
|
2406
2625
|
}
|
|
2407
2626
|
function projectTicketProvenanceHeader(value) {
|
|
2408
|
-
if (!
|
|
2627
|
+
if (!isRecord2(value)) return void 0;
|
|
2409
2628
|
const ticket = positiveInteger(value.ticket);
|
|
2410
2629
|
if (ticket === void 0) return void 0;
|
|
2411
2630
|
if (typeof value.repo !== "string") return void 0;
|
|
@@ -2423,7 +2642,7 @@ function projectTicketProvenanceHeader(value) {
|
|
|
2423
2642
|
};
|
|
2424
2643
|
}
|
|
2425
2644
|
function projectTicketProvenanceLine(value) {
|
|
2426
|
-
if (!
|
|
2645
|
+
if (!isRecord2(value)) return void 0;
|
|
2427
2646
|
const speaker = projectSpeaker(value.speaker);
|
|
2428
2647
|
const s = nonNegativeInteger(value.s);
|
|
2429
2648
|
if (speaker === void 0 || s === void 0) return void 0;
|
|
@@ -2539,13 +2758,23 @@ var init_diarist_contracts = __esm({
|
|
|
2539
2758
|
});
|
|
2540
2759
|
|
|
2541
2760
|
// src/secretariat-contracts.ts
|
|
2542
|
-
var
|
|
2761
|
+
var secretariat_contracts_exports = {};
|
|
2762
|
+
__export(secretariat_contracts_exports, {
|
|
2763
|
+
SECRETARIAT_ACCEPTED_TEXT: () => SECRETARIAT_ACCEPTED_TEXT,
|
|
2764
|
+
SECRETARIAT_COUNTERSIGN_TERMINAL_FACT_KEY: () => SECRETARIAT_COUNTERSIGN_TERMINAL_FACT_KEY,
|
|
2765
|
+
SECRETARIAT_GATE_OFFICER_ENTRY_TYPE: () => SECRETARIAT_GATE_OFFICER_ENTRY_TYPE,
|
|
2766
|
+
SECRETARIAT_OUTPUT_TOOL_NAME: () => SECRETARIAT_OUTPUT_TOOL_NAME,
|
|
2767
|
+
SECRETARIAT_SUMMON_COUNTERSIGN_TOOL_NAME: () => SECRETARIAT_SUMMON_COUNTERSIGN_TOOL_NAME
|
|
2768
|
+
});
|
|
2769
|
+
var SECRETARIAT_OUTPUT_TOOL_NAME, SECRETARIAT_SUMMON_COUNTERSIGN_TOOL_NAME, SECRETARIAT_ACCEPTED_TEXT, SECRETARIAT_GATE_OFFICER_ENTRY_TYPE, SECRETARIAT_COUNTERSIGN_TERMINAL_FACT_KEY;
|
|
2543
2770
|
var init_secretariat_contracts = __esm({
|
|
2544
2771
|
"src/secretariat-contracts.ts"() {
|
|
2545
2772
|
"use strict";
|
|
2546
2773
|
SECRETARIAT_OUTPUT_TOOL_NAME = "ak_secretariat_output";
|
|
2547
2774
|
SECRETARIAT_SUMMON_COUNTERSIGN_TOOL_NAME = "ak_secretariat_summon_countersign";
|
|
2548
2775
|
SECRETARIAT_ACCEPTED_TEXT = "\u4E2D\u4E66\u7701\u56DE\u6267\u5DF2\u63A5\u53D7";
|
|
2776
|
+
SECRETARIAT_GATE_OFFICER_ENTRY_TYPE = "ak-secretariat-gate-officer";
|
|
2777
|
+
SECRETARIAT_COUNTERSIGN_TERMINAL_FACT_KEY = "countersignTerminal";
|
|
2549
2778
|
}
|
|
2550
2779
|
});
|
|
2551
2780
|
|
|
@@ -2892,8 +3121,8 @@ import {
|
|
|
2892
3121
|
unlinkSync,
|
|
2893
3122
|
writeFileSync as writeFileSync2
|
|
2894
3123
|
} from "node:fs";
|
|
2895
|
-
import { dirname as
|
|
2896
|
-
function
|
|
3124
|
+
import { dirname as dirname6, join as join12 } from "node:path";
|
|
3125
|
+
function isRecord3(value) {
|
|
2897
3126
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
2898
3127
|
}
|
|
2899
3128
|
function errorCodeOf(error) {
|
|
@@ -2921,7 +3150,7 @@ function findIdentityPointer(recordFile, identity, kind, level) {
|
|
|
2921
3150
|
if (!trimmed) continue;
|
|
2922
3151
|
try {
|
|
2923
3152
|
const parsed = JSON.parse(trimmed);
|
|
2924
|
-
if (
|
|
3153
|
+
if (isRecord3(parsed) && parsed.identity === identity) {
|
|
2925
3154
|
return { identity, recordFile, kind, level };
|
|
2926
3155
|
}
|
|
2927
3156
|
} catch {
|
|
@@ -3020,8 +3249,8 @@ function resolveSitianVolumeCategory(kind) {
|
|
|
3020
3249
|
return kind;
|
|
3021
3250
|
}
|
|
3022
3251
|
function ticketProvenanceUnderBookPaths(ledgerHome, bookKey, ticketId) {
|
|
3023
|
-
const sessionDir =
|
|
3024
|
-
return { sessionDir, recordFile:
|
|
3252
|
+
const sessionDir = join12(activationBookDirectory(ledgerHome, bookKey), ticketId);
|
|
3253
|
+
return { sessionDir, recordFile: join12(sessionDir, SITIAN_RECORDS_LEAF) };
|
|
3025
3254
|
}
|
|
3026
3255
|
function resolveSitianRecordPathInLedger(input, ledgerHome) {
|
|
3027
3256
|
const category = resolveSitianVolumeCategory(input.kind);
|
|
@@ -3040,14 +3269,14 @@ function resolveSitianRecordPathInLedger(input, ledgerHome) {
|
|
|
3040
3269
|
if (input.sessionParent === void 0 || input.sessionParent.length === 0 || !physicallyContainedIn(ledgerHome, input.sessionParent)) {
|
|
3041
3270
|
throw new Error("Sitian record ownership requires a parent session inside the ledger home");
|
|
3042
3271
|
}
|
|
3043
|
-
sessionDir =
|
|
3044
|
-
recordFile =
|
|
3272
|
+
sessionDir = join12(dirname6(input.sessionParent), category);
|
|
3273
|
+
recordFile = join12(sessionDir, SITIAN_RECORDS_LEAF);
|
|
3045
3274
|
}
|
|
3046
3275
|
return { sessionDir, recordFile, ledgerHome };
|
|
3047
3276
|
}
|
|
3048
3277
|
function projectTicketRecordsPathShape() {
|
|
3049
3278
|
const { recordFile } = ticketProvenanceUnderBookPaths(
|
|
3050
|
-
|
|
3279
|
+
join12("~", ".ak-roles"),
|
|
3051
3280
|
"<\u7C3F>",
|
|
3052
3281
|
"<\u7968\u53F7>"
|
|
3053
3282
|
);
|
|
@@ -3109,15 +3338,15 @@ var init_sitian_appender = __esm({
|
|
|
3109
3338
|
|
|
3110
3339
|
// src/sitian-reader.ts
|
|
3111
3340
|
import { existsSync as existsSync4 } from "node:fs";
|
|
3112
|
-
import { readFile as
|
|
3113
|
-
function
|
|
3341
|
+
import { readFile as readFile3 } from "node:fs/promises";
|
|
3342
|
+
function isRecord4(value) {
|
|
3114
3343
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
3115
3344
|
}
|
|
3116
3345
|
async function readSitianRecords(recordFile) {
|
|
3117
3346
|
if (!existsSync4(recordFile)) {
|
|
3118
3347
|
return { records: [], diagnostics: [] };
|
|
3119
3348
|
}
|
|
3120
|
-
const text = await
|
|
3349
|
+
const text = await readFile3(recordFile, "utf8");
|
|
3121
3350
|
const lines = text.split("\n");
|
|
3122
3351
|
const records = [];
|
|
3123
3352
|
const diagnostics = [];
|
|
@@ -3126,7 +3355,7 @@ async function readSitianRecords(recordFile) {
|
|
|
3126
3355
|
if (!line2.trim()) continue;
|
|
3127
3356
|
try {
|
|
3128
3357
|
const parsed = JSON.parse(line2);
|
|
3129
|
-
if (
|
|
3358
|
+
if (isRecord4(parsed)) {
|
|
3130
3359
|
records.push(parsed);
|
|
3131
3360
|
} else {
|
|
3132
3361
|
const typeDesc = parsed === null ? "null" : Array.isArray(parsed) ? "array" : typeof parsed;
|
|
@@ -3182,13 +3411,13 @@ __export(role_turn_host_exports, {
|
|
|
3182
3411
|
});
|
|
3183
3412
|
import { execFile, spawn as spawn2 } from "node:child_process";
|
|
3184
3413
|
import { constants } from "node:fs";
|
|
3185
|
-
import { access, appendFile, readFile as
|
|
3186
|
-
import { basename as
|
|
3414
|
+
import { access, appendFile, readFile as readFile4, realpath } from "node:fs/promises";
|
|
3415
|
+
import { basename as basename4, delimiter, dirname as dirname7, isAbsolute as isAbsolute3, join as join13, resolve as resolve5 } from "node:path";
|
|
3187
3416
|
import { platform } from "node:process";
|
|
3188
3417
|
import { promisify } from "node:util";
|
|
3189
3418
|
import { randomUUID as randomUUID2 } from "node:crypto";
|
|
3190
3419
|
function resolveInternalRoleEntrypoint(packageRoot) {
|
|
3191
|
-
return
|
|
3420
|
+
return join13(packageRoot, INTERNAL_ROLE_ENTRYPOINT_RELATIVE);
|
|
3192
3421
|
}
|
|
3193
3422
|
function buildExplicitInternalActivationArgs(selectedRoleEntry, extraArgs = []) {
|
|
3194
3423
|
return ["--no-extensions", "-e", selectedRoleEntry, ...extraArgs];
|
|
@@ -3224,7 +3453,7 @@ function buildMethodArgs(methods) {
|
|
|
3224
3453
|
function applyPiNativeSkillInvocation(methods, prompt) {
|
|
3225
3454
|
const skills = methods.filter((method) => method.kind === "skill");
|
|
3226
3455
|
if (skills.length !== 1) return prompt;
|
|
3227
|
-
const name =
|
|
3456
|
+
const name = basename4(dirname7(skills[0].path));
|
|
3228
3457
|
if (name.length === 0) return prompt;
|
|
3229
3458
|
const token = `/skill:${name}`;
|
|
3230
3459
|
const trimmed = prompt.trimStart();
|
|
@@ -3443,9 +3672,6 @@ ${paths.join("\n")}`
|
|
|
3443
3672
|
if (typeof process.env.AK_ROLE_AUDITOR_SUBJECT === "string" && process.env.AK_ROLE_AUDITOR_SUBJECT.trim() !== "") {
|
|
3444
3673
|
env.AK_ROLE_AUDITOR_SUBJECT = process.env.AK_ROLE_AUDITOR_SUBJECT;
|
|
3445
3674
|
}
|
|
3446
|
-
if (request.correlationId !== void 0 && request.correlationId.trim() !== "") {
|
|
3447
|
-
env.AK_CORRELATION_ID = request.correlationId;
|
|
3448
|
-
}
|
|
3449
3675
|
if (config.recordLaunchedRolePackageIdentity !== void 0 && config.observeLaunchedRolePackageIdentity !== void 0) {
|
|
3450
3676
|
await config.recordLaunchedRolePackageIdentity(
|
|
3451
3677
|
request.runDirectory,
|
|
@@ -3465,7 +3691,7 @@ ${paths.join("\n")}`
|
|
|
3465
3691
|
}
|
|
3466
3692
|
async function appendPiSessionCustomEntry(authority, principal, customType, data) {
|
|
3467
3693
|
const { sessionFile } = authority.decode(principal);
|
|
3468
|
-
const text = await
|
|
3694
|
+
const text = await readFile4(sessionFile, "utf8");
|
|
3469
3695
|
let parentId = null;
|
|
3470
3696
|
for (const line2 of text.trim().split("\n").filter(Boolean)) {
|
|
3471
3697
|
const entry = JSON.parse(line2);
|
|
@@ -3756,8 +3982,8 @@ var init_compliance_transport = __esm({
|
|
|
3756
3982
|
|
|
3757
3983
|
// src/role-run-relocation.ts
|
|
3758
3984
|
import { existsSync as existsSync5 } from "node:fs";
|
|
3759
|
-
import { readdir as
|
|
3760
|
-
import { join as
|
|
3985
|
+
import { readdir as readdir3, readFile as readFile5, writeFile as writeFile2 } from "node:fs/promises";
|
|
3986
|
+
import { join as join14, sep as sep2 } from "node:path";
|
|
3761
3987
|
function isEnoent2(error) {
|
|
3762
3988
|
return error instanceof Error && "code" in error && error.code === "ENOENT";
|
|
3763
3989
|
}
|
|
@@ -3846,7 +4072,7 @@ function rewriteSummonsMaterials(value, rewrites) {
|
|
|
3846
4072
|
}
|
|
3847
4073
|
async function rewriteJsonObjectFile(path, fields, rewrites) {
|
|
3848
4074
|
if (!existsSync5(path)) return;
|
|
3849
|
-
const page = JSON.parse(await
|
|
4075
|
+
const page = JSON.parse(await readFile5(path, "utf8"));
|
|
3850
4076
|
if (!isPlainObject(page)) return;
|
|
3851
4077
|
rewriteRunDirectoryPathFieldsAgainstRewrites(page, fields, rewrites);
|
|
3852
4078
|
await writeFile2(path, `${JSON.stringify(page, null, 2)}
|
|
@@ -3854,7 +4080,7 @@ async function rewriteJsonObjectFile(path, fields, rewrites) {
|
|
|
3854
4080
|
}
|
|
3855
4081
|
async function rewriteOfficerPointerFile(path, rewrites) {
|
|
3856
4082
|
if (!existsSync5(path)) return;
|
|
3857
|
-
const page = JSON.parse(await
|
|
4083
|
+
const page = JSON.parse(await readFile5(path, "utf8"));
|
|
3858
4084
|
if (!isPlainObject(page)) return;
|
|
3859
4085
|
if (page.kind !== "direct-officer-run-pointer") return;
|
|
3860
4086
|
rewriteRunDirectoryPathFieldsAgainstRewrites(
|
|
@@ -3867,7 +4093,7 @@ async function rewriteOfficerPointerFile(path, rewrites) {
|
|
|
3867
4093
|
}
|
|
3868
4094
|
async function rewriteSitianRecordsJsonl(path, rewrites) {
|
|
3869
4095
|
if (!existsSync5(path)) return;
|
|
3870
|
-
const raw = await
|
|
4096
|
+
const raw = await readFile5(path, "utf8");
|
|
3871
4097
|
if (raw.length === 0) return;
|
|
3872
4098
|
const endsWithNewline = raw.endsWith("\n");
|
|
3873
4099
|
const lines = raw.split("\n");
|
|
@@ -3918,7 +4144,7 @@ async function rewriteSitianRecordsJsonl(path, rewrites) {
|
|
|
3918
4144
|
}
|
|
3919
4145
|
async function rewriteSessionTranscriptBindings(path, rewrites) {
|
|
3920
4146
|
if (!existsSync5(path)) return;
|
|
3921
|
-
const raw = await
|
|
4147
|
+
const raw = await readFile5(path, "utf8");
|
|
3922
4148
|
if (raw.length === 0) return;
|
|
3923
4149
|
const endsWithNewline = raw.endsWith("\n");
|
|
3924
4150
|
const lines = raw.split("\n");
|
|
@@ -3977,17 +4203,17 @@ async function rewriteSessionTranscriptBindings(path, rewrites) {
|
|
|
3977
4203
|
);
|
|
3978
4204
|
}
|
|
3979
4205
|
async function rewriteNestedMachinePathPages(pagesDirectory, rewrites) {
|
|
3980
|
-
const sessionRoot =
|
|
4206
|
+
const sessionRoot = join14(pagesDirectory, "session");
|
|
3981
4207
|
async function walk(directory) {
|
|
3982
4208
|
let entries;
|
|
3983
4209
|
try {
|
|
3984
|
-
entries = await
|
|
4210
|
+
entries = await readdir3(directory, { withFileTypes: true });
|
|
3985
4211
|
} catch (error) {
|
|
3986
4212
|
if (isEnoent2(error)) return;
|
|
3987
4213
|
throw error;
|
|
3988
4214
|
}
|
|
3989
4215
|
for (const entry of entries) {
|
|
3990
|
-
const path =
|
|
4216
|
+
const path = join14(directory, entry.name);
|
|
3991
4217
|
if (entry.isDirectory()) {
|
|
3992
4218
|
await walk(path);
|
|
3993
4219
|
continue;
|
|
@@ -4009,9 +4235,9 @@ async function rewriteNestedMachinePathPages(pagesDirectory, rewrites) {
|
|
|
4009
4235
|
async function rewriteRoleRunDurablePages(input) {
|
|
4010
4236
|
const { pagesDirectory } = input;
|
|
4011
4237
|
const rewrites = collectRewrites(input);
|
|
4012
|
-
const admittedPath =
|
|
4238
|
+
const admittedPath = join14(pagesDirectory, "admitted-request.json");
|
|
4013
4239
|
if (existsSync5(admittedPath)) {
|
|
4014
|
-
const page = JSON.parse(await
|
|
4240
|
+
const page = JSON.parse(await readFile5(admittedPath, "utf8"));
|
|
4015
4241
|
rewriteRunDirectoryPathFieldsAgainstRewrites(
|
|
4016
4242
|
page,
|
|
4017
4243
|
ADMITTED_PAGE_FIELDS,
|
|
@@ -4039,9 +4265,9 @@ async function rewriteRoleRunDurablePages(input) {
|
|
|
4039
4265
|
await writeFile2(admittedPath, `${JSON.stringify(page, null, 2)}
|
|
4040
4266
|
`, "utf8");
|
|
4041
4267
|
}
|
|
4042
|
-
const invocationPath =
|
|
4268
|
+
const invocationPath = join14(pagesDirectory, "invocation.json");
|
|
4043
4269
|
if (existsSync5(invocationPath)) {
|
|
4044
|
-
const page = JSON.parse(await
|
|
4270
|
+
const page = JSON.parse(await readFile5(invocationPath, "utf8"));
|
|
4045
4271
|
rewriteRunDirectoryPathFieldsAgainstRewrites(
|
|
4046
4272
|
page,
|
|
4047
4273
|
INVOCATION_PAGE_FIELDS,
|
|
@@ -4054,9 +4280,9 @@ async function rewriteRoleRunDurablePages(input) {
|
|
|
4054
4280
|
"utf8"
|
|
4055
4281
|
);
|
|
4056
4282
|
}
|
|
4057
|
-
const statePath =
|
|
4283
|
+
const statePath = join14(pagesDirectory, "run-state.json");
|
|
4058
4284
|
if (existsSync5(statePath)) {
|
|
4059
|
-
const page = JSON.parse(await
|
|
4285
|
+
const page = JSON.parse(await readFile5(statePath, "utf8"));
|
|
4060
4286
|
rewriteRunDirectoryPathFieldsAgainstRewrites(
|
|
4061
4287
|
page,
|
|
4062
4288
|
RUN_STATE_PAGE_FIELDS,
|
|
@@ -4244,15 +4470,15 @@ var init_terminating_tools = __esm({
|
|
|
4244
4470
|
});
|
|
4245
4471
|
|
|
4246
4472
|
// src/doctor-evidence.ts
|
|
4247
|
-
import { readdir as
|
|
4248
|
-
import { dirname as
|
|
4473
|
+
import { readdir as readdir4, readFile as readFile6, realpath as realpath2, stat } from "node:fs/promises";
|
|
4474
|
+
import { dirname as dirname8, relative as relative2, resolve as resolve6, sep as sep3 } from "node:path";
|
|
4249
4475
|
function record2(value) {
|
|
4250
4476
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
4251
4477
|
}
|
|
4252
4478
|
async function discoverCaseFiles(root) {
|
|
4253
4479
|
const found = [];
|
|
4254
4480
|
async function walk(dir, depth) {
|
|
4255
|
-
for (const item of await
|
|
4481
|
+
for (const item of await readdir4(dir, { withFileTypes: true })) {
|
|
4256
4482
|
const path = resolve6(dir, item.name);
|
|
4257
4483
|
if (item.isDirectory()) {
|
|
4258
4484
|
await walk(path, depth + 1);
|
|
@@ -4272,7 +4498,7 @@ function accumulate(metric, value, source) {
|
|
|
4272
4498
|
function timestamp(row) {
|
|
4273
4499
|
return typeof row.timestamp === "string" && Number.isFinite(Date.parse(row.timestamp)) ? row.timestamp : void 0;
|
|
4274
4500
|
}
|
|
4275
|
-
function
|
|
4501
|
+
function isMissingPathError3(error) {
|
|
4276
4502
|
return error instanceof Error && "code" in error && (error.code === "ENOENT" || error.code === "ENOTDIR");
|
|
4277
4503
|
}
|
|
4278
4504
|
async function stableRunsIdentity(root) {
|
|
@@ -4282,9 +4508,9 @@ async function stableRunsIdentity(root) {
|
|
|
4282
4508
|
const git3 = await stat(resolve6(cursor, ".git"));
|
|
4283
4509
|
if (git3.isDirectory() || git3.isFile()) return relative2(cursor, root).split(sep3).join("/");
|
|
4284
4510
|
} catch (error) {
|
|
4285
|
-
if (!
|
|
4511
|
+
if (!isMissingPathError3(error)) throw error;
|
|
4286
4512
|
}
|
|
4287
|
-
const parent =
|
|
4513
|
+
const parent = dirname8(cursor);
|
|
4288
4514
|
if (parent === cursor) return root;
|
|
4289
4515
|
cursor = parent;
|
|
4290
4516
|
}
|
|
@@ -4360,7 +4586,7 @@ async function loadDoctorCase(runsPath) {
|
|
|
4360
4586
|
const turns = { count: 0, sources: [] }, calls = { count: 0, sources: [] }, tokens = { count: 0, sources: [] };
|
|
4361
4587
|
for (const path of await discoverCaseFiles(root)) {
|
|
4362
4588
|
const id = relative2(root, path).split(sep3).join("/");
|
|
4363
|
-
const bytes = await
|
|
4589
|
+
const bytes = await readFile6(path);
|
|
4364
4590
|
const content = bytes.toString("utf8");
|
|
4365
4591
|
const kind = id.endsWith(".jsonl") ? "session" : "stderr";
|
|
4366
4592
|
evidence.push({ id, kind, byteLength: bytes.byteLength, contentLength: content.length, sha256: sha256Hex(bytes), content });
|
|
@@ -4373,7 +4599,7 @@ async function loadDoctorCase(runsPath) {
|
|
|
4373
4599
|
accumulate(calls, result.calls, id);
|
|
4374
4600
|
accumulate(tokens, result.tokens, id);
|
|
4375
4601
|
}
|
|
4376
|
-
const runDirs = (await
|
|
4602
|
+
const runDirs = (await readdir4(root, { withFileTypes: true })).filter((item) => item.isDirectory()).map((item) => item.name).sort();
|
|
4377
4603
|
const legs = evidence.filter((entry) => entry.kind === "session").map((entry) => entry.id);
|
|
4378
4604
|
const retryDirs = runDirs.filter((name) => /(?:^|[-_])retry(?:[-_]|$)/i.test(name));
|
|
4379
4605
|
const rawBytes = evidence.filter((entry) => entry.kind === "session").reduce((sum, entry) => sum + entry.byteLength, 0);
|
|
@@ -4390,7 +4616,7 @@ var init_doctor_evidence = __esm({
|
|
|
4390
4616
|
|
|
4391
4617
|
// src/collector-config.ts
|
|
4392
4618
|
import { createHash as createHash4 } from "node:crypto";
|
|
4393
|
-
import { readFile as
|
|
4619
|
+
import { readFile as readFile7 } from "node:fs/promises";
|
|
4394
4620
|
function fail3(message, cause) {
|
|
4395
4621
|
throw new Error(message, cause === void 0 ? void 0 : { cause });
|
|
4396
4622
|
}
|
|
@@ -4433,7 +4659,7 @@ function emptyCollectorManifest() {
|
|
|
4433
4659
|
async function loadCollectorManifest(path) {
|
|
4434
4660
|
let bytes;
|
|
4435
4661
|
try {
|
|
4436
|
-
bytes = await
|
|
4662
|
+
bytes = await readFile7(path);
|
|
4437
4663
|
} catch (error) {
|
|
4438
4664
|
fail3(`Collector request manifest is unreadable at ${path}`, error);
|
|
4439
4665
|
}
|
|
@@ -4469,7 +4695,7 @@ var init_collector_config = __esm({
|
|
|
4469
4695
|
// src/collector-github.ts
|
|
4470
4696
|
import { spawn as spawn3 } from "node:child_process";
|
|
4471
4697
|
import { createHash as createHash5 } from "node:crypto";
|
|
4472
|
-
function
|
|
4698
|
+
function isRecord5(value) {
|
|
4473
4699
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
4474
4700
|
}
|
|
4475
4701
|
function requireString(value, label) {
|
|
@@ -4508,7 +4734,7 @@ function parsePullRequestNumberList(raw, label) {
|
|
|
4508
4734
|
}
|
|
4509
4735
|
const numbers = [];
|
|
4510
4736
|
for (const item of raw) {
|
|
4511
|
-
if (!
|
|
4737
|
+
if (!isRecord5(item)) {
|
|
4512
4738
|
throw new Error(`GitHub ${label} payload contains a non-object pull request entry`);
|
|
4513
4739
|
}
|
|
4514
4740
|
try {
|
|
@@ -4576,7 +4802,7 @@ async function listPullRequestNumbersByTicket(runner, input) {
|
|
|
4576
4802
|
});
|
|
4577
4803
|
}
|
|
4578
4804
|
const issueRaw = parseJson(issueResponse.bodyText, issuePath);
|
|
4579
|
-
if (!
|
|
4805
|
+
if (!isRecord5(issueRaw)) {
|
|
4580
4806
|
throw new Error(`GitHub ${issuePath} payload is not an object`);
|
|
4581
4807
|
}
|
|
4582
4808
|
if (Object.hasOwn(issueRaw, "pull_request")) {
|
|
@@ -4635,7 +4861,7 @@ async function listPullRequestNumbersByTicket(runner, input) {
|
|
|
4635
4861
|
} catch (error) {
|
|
4636
4862
|
throw new Error("GitHub GraphQL issue\u2192PR returned malformed JSON", { cause: error });
|
|
4637
4863
|
}
|
|
4638
|
-
if (!
|
|
4864
|
+
if (!isRecord5(payload)) {
|
|
4639
4865
|
throw new Error("GitHub GraphQL issue\u2192PR payload is not an object");
|
|
4640
4866
|
}
|
|
4641
4867
|
if (payload.errors !== void 0) {
|
|
@@ -4644,30 +4870,30 @@ async function listPullRequestNumbersByTicket(runner, input) {
|
|
|
4644
4870
|
});
|
|
4645
4871
|
}
|
|
4646
4872
|
const data = payload.data;
|
|
4647
|
-
if (!
|
|
4873
|
+
if (!isRecord5(data)) return [];
|
|
4648
4874
|
const repository = data["repository"];
|
|
4649
|
-
if (!
|
|
4875
|
+
if (!isRecord5(repository)) return [];
|
|
4650
4876
|
const issue = repository["issue"];
|
|
4651
|
-
if (!
|
|
4877
|
+
if (!isRecord5(issue)) return [];
|
|
4652
4878
|
const numbers = [];
|
|
4653
4879
|
const closedBy = issue["closedByPullRequestsReferences"];
|
|
4654
|
-
if (
|
|
4880
|
+
if (isRecord5(closedBy) && Array.isArray(closedBy["nodes"])) {
|
|
4655
4881
|
for (const node of closedBy["nodes"]) {
|
|
4656
|
-
if (
|
|
4882
|
+
if (isRecord5(node) && typeof node["number"] === "number") {
|
|
4657
4883
|
numbers.push(parseCollectorPrNumber(node["number"]));
|
|
4658
4884
|
}
|
|
4659
4885
|
}
|
|
4660
4886
|
}
|
|
4661
4887
|
const timeline = issue["timelineItems"];
|
|
4662
|
-
if (
|
|
4888
|
+
if (isRecord5(timeline) && Array.isArray(timeline["nodes"])) {
|
|
4663
4889
|
for (const node of timeline["nodes"]) {
|
|
4664
|
-
if (!
|
|
4890
|
+
if (!isRecord5(node)) continue;
|
|
4665
4891
|
const source = node["source"];
|
|
4666
|
-
if (
|
|
4892
|
+
if (isRecord5(source) && typeof source["number"] === "number") {
|
|
4667
4893
|
numbers.push(parseCollectorPrNumber(source["number"]));
|
|
4668
4894
|
}
|
|
4669
4895
|
const subject = node["subject"];
|
|
4670
|
-
if (
|
|
4896
|
+
if (isRecord5(subject) && typeof subject["number"] === "number") {
|
|
4671
4897
|
numbers.push(parseCollectorPrNumber(subject["number"]));
|
|
4672
4898
|
}
|
|
4673
4899
|
}
|
|
@@ -4682,25 +4908,25 @@ function commentFailureCause(error) {
|
|
|
4682
4908
|
};
|
|
4683
4909
|
}
|
|
4684
4910
|
function requireUserLogin(raw) {
|
|
4685
|
-
if (!
|
|
4911
|
+
if (!isRecord5(raw) || typeof raw["login"] !== "string") {
|
|
4686
4912
|
throw new Error("GitHub payload missing user.login");
|
|
4687
4913
|
}
|
|
4688
4914
|
return raw["login"];
|
|
4689
4915
|
}
|
|
4690
4916
|
function optionalUserLogin(raw) {
|
|
4691
4917
|
if (raw === null) return null;
|
|
4692
|
-
if (!
|
|
4918
|
+
if (!isRecord5(raw) || typeof raw["login"] !== "string") {
|
|
4693
4919
|
throw new Error("GitHub payload missing user.login");
|
|
4694
4920
|
}
|
|
4695
4921
|
return raw["login"];
|
|
4696
4922
|
}
|
|
4697
4923
|
function machineIdentity(raw) {
|
|
4698
4924
|
const user = raw["user"];
|
|
4699
|
-
if (!
|
|
4925
|
+
if (!isRecord5(user) || typeof user["type"] !== "string" || typeof user["id"] !== "number") {
|
|
4700
4926
|
return null;
|
|
4701
4927
|
}
|
|
4702
4928
|
const app = raw["performed_via_github_app"];
|
|
4703
|
-
const appId =
|
|
4929
|
+
const appId = isRecord5(app) && typeof app["id"] === "number" ? app["id"] : void 0;
|
|
4704
4930
|
return {
|
|
4705
4931
|
userType: user["type"],
|
|
4706
4932
|
userId: user["id"],
|
|
@@ -4708,9 +4934,9 @@ function machineIdentity(raw) {
|
|
|
4708
4934
|
};
|
|
4709
4935
|
}
|
|
4710
4936
|
function normalizePullRequest(raw) {
|
|
4711
|
-
if (!
|
|
4937
|
+
if (!isRecord5(raw)) throw new Error("GitHub pull request payload must be an object");
|
|
4712
4938
|
const head = raw["head"];
|
|
4713
|
-
if (!
|
|
4939
|
+
if (!isRecord5(head) || typeof head["sha"] !== "string" || head["sha"].length === 0) {
|
|
4714
4940
|
throw new Error("GitHub pull request payload missing head.sha");
|
|
4715
4941
|
}
|
|
4716
4942
|
const number = requireNumber(raw["number"], "number");
|
|
@@ -4729,7 +4955,7 @@ function normalizePullRequest(raw) {
|
|
|
4729
4955
|
};
|
|
4730
4956
|
}
|
|
4731
4957
|
function normalizePullRequestReaction(raw) {
|
|
4732
|
-
if (!
|
|
4958
|
+
if (!isRecord5(raw)) throw new Error("GitHub reaction payload must be an object");
|
|
4733
4959
|
return {
|
|
4734
4960
|
id: requireNumber(raw["id"], "reaction.id"),
|
|
4735
4961
|
userLogin: optionalUserLogin(raw["user"]),
|
|
@@ -4740,7 +4966,7 @@ function normalizePullRequestReaction(raw) {
|
|
|
4740
4966
|
};
|
|
4741
4967
|
}
|
|
4742
4968
|
function normalizeReview(raw) {
|
|
4743
|
-
if (!
|
|
4969
|
+
if (!isRecord5(raw)) throw new Error("GitHub review payload must be an object");
|
|
4744
4970
|
return {
|
|
4745
4971
|
id: requireNumber(raw["id"], "review.id"),
|
|
4746
4972
|
...typeof raw["node_id"] === "string" ? { nodeId: raw["node_id"] } : {},
|
|
@@ -4755,7 +4981,7 @@ function normalizeReview(raw) {
|
|
|
4755
4981
|
};
|
|
4756
4982
|
}
|
|
4757
4983
|
function normalizeIssueComment(raw) {
|
|
4758
|
-
if (!
|
|
4984
|
+
if (!isRecord5(raw)) throw new Error("GitHub issue comment payload must be an object");
|
|
4759
4985
|
return {
|
|
4760
4986
|
id: requireNumber(raw["id"], "comment.id"),
|
|
4761
4987
|
userLogin: optionalUserLogin(raw["user"]),
|
|
@@ -4768,7 +4994,7 @@ function normalizeIssueComment(raw) {
|
|
|
4768
4994
|
};
|
|
4769
4995
|
}
|
|
4770
4996
|
function normalizeReviewComment(raw) {
|
|
4771
|
-
if (!
|
|
4997
|
+
if (!isRecord5(raw)) throw new Error("GitHub review comment payload must be an object");
|
|
4772
4998
|
return {
|
|
4773
4999
|
id: requireNumber(raw["id"], "review_comment.id"),
|
|
4774
5000
|
pullRequestReviewId: typeof raw["pull_request_review_id"] === "number" ? raw["pull_request_review_id"] : null,
|
|
@@ -4792,7 +5018,7 @@ function normalizeReviewComment(raw) {
|
|
|
4792
5018
|
function createGhApiRunner(options = {}) {
|
|
4793
5019
|
const spawnImpl = options.spawnImpl ?? spawn3;
|
|
4794
5020
|
return async (args, runOptions = {}) => {
|
|
4795
|
-
return await new Promise((
|
|
5021
|
+
return await new Promise((resolve21, reject) => {
|
|
4796
5022
|
const signal = runOptions.signal;
|
|
4797
5023
|
if (signal?.aborted) {
|
|
4798
5024
|
reject(signal.reason ?? new Error("aborted"));
|
|
@@ -4865,11 +5091,11 @@ function createGhApiRunner(options = {}) {
|
|
|
4865
5091
|
const value = line2.slice(idx + 1).trim();
|
|
4866
5092
|
headers[name] = value;
|
|
4867
5093
|
}
|
|
4868
|
-
|
|
5094
|
+
resolve21({ status, headers, bodyText });
|
|
4869
5095
|
return;
|
|
4870
5096
|
}
|
|
4871
5097
|
if (code === 0) {
|
|
4872
|
-
|
|
5098
|
+
resolve21({ status: 200, headers: {}, bodyText: stdout });
|
|
4873
5099
|
return;
|
|
4874
5100
|
}
|
|
4875
5101
|
const failure2 = new Error(
|
|
@@ -5027,11 +5253,11 @@ function createGhCollectorGitHubTransport(runner = createGhApiRunner()) {
|
|
|
5027
5253
|
if (input.signal?.aborted) {
|
|
5028
5254
|
throw error;
|
|
5029
5255
|
}
|
|
5030
|
-
if (
|
|
5256
|
+
if (isRecord5(error) && error["ambiguousGhFailure"] === true) {
|
|
5031
5257
|
const cause = commentFailureCause(error);
|
|
5032
5258
|
return { kind: "ambiguous_loss", diagnostics: cause.message, cause };
|
|
5033
5259
|
}
|
|
5034
|
-
if (
|
|
5260
|
+
if (isRecord5(error) && error["name"] === "AbortError") {
|
|
5035
5261
|
throw error;
|
|
5036
5262
|
}
|
|
5037
5263
|
throw error;
|
|
@@ -5273,7 +5499,7 @@ var init_git_object_id = __esm({
|
|
|
5273
5499
|
|
|
5274
5500
|
// src/merger-git-state.ts
|
|
5275
5501
|
import { execFile as execFile2 } from "node:child_process";
|
|
5276
|
-
import { access as access2, readFile as
|
|
5502
|
+
import { access as access2, readFile as readFile8 } from "node:fs/promises";
|
|
5277
5503
|
import { constants as fsConstants } from "node:fs";
|
|
5278
5504
|
import { isAbsolute as isAbsolute4, resolve as resolve7 } from "node:path";
|
|
5279
5505
|
import { promisify as promisify2 } from "node:util";
|
|
@@ -5343,7 +5569,7 @@ function createProductionMergerGitState(repositoryRoot = process.cwd()) {
|
|
|
5343
5569
|
const mergeHeadPath = isAbsolute4(mergeHeadReported) ? mergeHeadReported : resolve7(repositoryRoot, mergeHeadReported);
|
|
5344
5570
|
let sourceObjectId = "";
|
|
5345
5571
|
if (await pathExists(mergeHeadPath)) {
|
|
5346
|
-
const raw = exactUtf8(await
|
|
5572
|
+
const raw = exactUtf8(await readFile8(mergeHeadPath), "Git MERGE_HEAD");
|
|
5347
5573
|
const mergeHeads = raw.trim().split(/\r?\n/).map((row) => row.trim()).filter(Boolean);
|
|
5348
5574
|
if (mergeHeads.length === 0) throw new Error("Git MERGE_HEAD is empty");
|
|
5349
5575
|
if (mergeHeads.length !== 1) throw new Error("Assigned repository does not have one ordinary in-progress merge");
|
|
@@ -5395,10 +5621,10 @@ var init_uuidv7 = __esm({
|
|
|
5395
5621
|
});
|
|
5396
5622
|
|
|
5397
5623
|
// src/typed-provider-http.ts
|
|
5398
|
-
import { readFile as
|
|
5399
|
-
import { join as
|
|
5624
|
+
import { readFile as readFile9, unlink, writeFile as writeFile3 } from "node:fs/promises";
|
|
5625
|
+
import { join as join15 } from "node:path";
|
|
5400
5626
|
function typedProviderHttpPath(runDirectory) {
|
|
5401
|
-
return
|
|
5627
|
+
return join15(runDirectory, TYPED_HTTP_FILE);
|
|
5402
5628
|
}
|
|
5403
5629
|
async function clearTypedProviderHttpObservation(runDirectory) {
|
|
5404
5630
|
try {
|
|
@@ -5429,7 +5655,7 @@ async function recordTypedProviderHttpStatus(runDirectory, observation) {
|
|
|
5429
5655
|
async function readLatestTypedProviderHttpObservation(runDirectory) {
|
|
5430
5656
|
let text;
|
|
5431
5657
|
try {
|
|
5432
|
-
text = await
|
|
5658
|
+
text = await readFile9(typedProviderHttpPath(runDirectory), "utf8");
|
|
5433
5659
|
} catch (error) {
|
|
5434
5660
|
if (error instanceof Error && "code" in error && error.code === "ENOENT") {
|
|
5435
5661
|
return void 0;
|
|
@@ -5508,8 +5734,8 @@ __export(run_lifecycle_exports, {
|
|
|
5508
5734
|
selectResumeContinuationPrompt: () => selectResumeContinuationPrompt,
|
|
5509
5735
|
writeRoleRunState: () => writeRoleRunState
|
|
5510
5736
|
});
|
|
5511
|
-
import { chmod, lstat as lstat2, open, readdir as
|
|
5512
|
-
import { basename as
|
|
5737
|
+
import { chmod, lstat as lstat2, open, readdir as readdir5, readFile as readFile10, unlink as unlink2, writeFile as writeFile4 } from "node:fs/promises";
|
|
5738
|
+
import { basename as basename5, join as join16 } from "node:path";
|
|
5513
5739
|
function selectResumeContinuationPrompt(message, engineMaterial) {
|
|
5514
5740
|
const lines = message !== void 0 ? [message] : [];
|
|
5515
5741
|
return appendEngineSessionMaterial(lines, engineMaterial).join("\n");
|
|
@@ -5548,7 +5774,7 @@ function renderResumeCommand(runId) {
|
|
|
5548
5774
|
async function writeRoleRunState(runDirectory, record4) {
|
|
5549
5775
|
const payload = { ...record4, runDirectory };
|
|
5550
5776
|
await writeFile4(
|
|
5551
|
-
|
|
5777
|
+
join16(runDirectory, RUN_STATE_FILE),
|
|
5552
5778
|
`${JSON.stringify(payload, null, 2)}
|
|
5553
5779
|
`,
|
|
5554
5780
|
"utf8"
|
|
@@ -5598,7 +5824,7 @@ function parseCurrentCourtState(raw) {
|
|
|
5598
5824
|
async function readRoleRunStateDisk(runDirectory) {
|
|
5599
5825
|
let raw;
|
|
5600
5826
|
try {
|
|
5601
|
-
raw = JSON.parse(await
|
|
5827
|
+
raw = JSON.parse(await readFile10(join16(runDirectory, RUN_STATE_FILE), "utf8"));
|
|
5602
5828
|
} catch (error) {
|
|
5603
5829
|
if (errorCodeOf2(error) === "ENOENT") return void 0;
|
|
5604
5830
|
throw error;
|
|
@@ -5666,7 +5892,7 @@ async function writeRoleRunStateDisk(runDirectory, disk) {
|
|
|
5666
5892
|
...disk.currentCourt === void 0 ? {} : { currentCourt: disk.currentCourt }
|
|
5667
5893
|
};
|
|
5668
5894
|
await writeFile4(
|
|
5669
|
-
|
|
5895
|
+
join16(runDirectory, RUN_STATE_FILE),
|
|
5670
5896
|
`${JSON.stringify(payload, null, 2)}
|
|
5671
5897
|
`,
|
|
5672
5898
|
"utf8"
|
|
@@ -5838,7 +6064,7 @@ function isProcessAlive(pid) {
|
|
|
5838
6064
|
async function autopsyWriterLock(lockPath) {
|
|
5839
6065
|
let content;
|
|
5840
6066
|
try {
|
|
5841
|
-
content = await
|
|
6067
|
+
content = await readFile10(lockPath, "utf8");
|
|
5842
6068
|
} catch (error) {
|
|
5843
6069
|
if (errorCodeOf2(error) === "ENOENT") return { verdict: "absent" };
|
|
5844
6070
|
return { verdict: "unknown", reason: "unreadable", readFailure: error };
|
|
@@ -5897,7 +6123,7 @@ async function createWriterLease(lockPath, runDirectory, reportCleanupFailure) {
|
|
|
5897
6123
|
},
|
|
5898
6124
|
relocate(nextRunDirectory) {
|
|
5899
6125
|
currentRunDirectory = nextRunDirectory;
|
|
5900
|
-
currentLockPath =
|
|
6126
|
+
currentLockPath = join16(nextRunDirectory, WRITER_LOCK_FILE);
|
|
5901
6127
|
},
|
|
5902
6128
|
async release() {
|
|
5903
6129
|
if (released) return;
|
|
@@ -5936,10 +6162,10 @@ async function acquireRunWriterLease(runDirectory, onCleanupFailure) {
|
|
|
5936
6162
|
};
|
|
5937
6163
|
const reportReadFailure = (error) => {
|
|
5938
6164
|
reportDiagnostic(
|
|
5939
|
-
`writer lease lock read failed (holder liveness unverifiable; lock left in place) at ${
|
|
6165
|
+
`writer lease lock read failed (holder liveness unverifiable; lock left in place) at ${join16(runDirectory, WRITER_LOCK_FILE)}: ${describeErrorIdentity(error)}`
|
|
5940
6166
|
);
|
|
5941
6167
|
};
|
|
5942
|
-
const lockPath =
|
|
6168
|
+
const lockPath = join16(runDirectory, WRITER_LOCK_FILE);
|
|
5943
6169
|
let lastAutopsy = { verdict: "absent" };
|
|
5944
6170
|
let lastReclaimFailure;
|
|
5945
6171
|
for (let reclaimsLeft = WRITER_LEASE_RECLAIM_ROUNDS; ; reclaimsLeft -= 1) {
|
|
@@ -5994,10 +6220,10 @@ async function acquireRunWriterLease(runDirectory, onCleanupFailure) {
|
|
|
5994
6220
|
async function findRunDirectoryById(home, runId, onlyBookKey, onlyRole) {
|
|
5995
6221
|
if (runId.trim() === "") return void 0;
|
|
5996
6222
|
const ledgerHome = resolveActivationLedgerHome(home);
|
|
5997
|
-
const booksRoot =
|
|
6223
|
+
const booksRoot = join16(ledgerHome, "books");
|
|
5998
6224
|
let bookKeys;
|
|
5999
6225
|
try {
|
|
6000
|
-
bookKeys = await
|
|
6226
|
+
bookKeys = await readdir5(booksRoot);
|
|
6001
6227
|
} catch (error) {
|
|
6002
6228
|
if (errorCodeOf2(error) === "ENOENT") return void 0;
|
|
6003
6229
|
throw error;
|
|
@@ -6014,7 +6240,7 @@ async function findRunDirectoryById(home, runId, onlyBookKey, onlyRole) {
|
|
|
6014
6240
|
throw error;
|
|
6015
6241
|
}
|
|
6016
6242
|
for (const runDirectory of runDirectories) {
|
|
6017
|
-
const entry =
|
|
6243
|
+
const entry = basename5(runDirectory);
|
|
6018
6244
|
if (onlyRole === void 0 && (entry === `${runId}@judge` || entry.startsWith(`${runId}@`)) || entry === `${runId}@${onlyRole}`) {
|
|
6019
6245
|
matches.push(runDirectory);
|
|
6020
6246
|
}
|
|
@@ -6035,7 +6261,7 @@ async function readRunParentPath(runDirectory) {
|
|
|
6035
6261
|
let raw;
|
|
6036
6262
|
try {
|
|
6037
6263
|
raw = JSON.parse(
|
|
6038
|
-
await
|
|
6264
|
+
await readFile10(join16(runDirectory, "admitted-request.json"), "utf8")
|
|
6039
6265
|
);
|
|
6040
6266
|
} catch (error) {
|
|
6041
6267
|
if (errorCodeOf2(error) === "ENOENT") return void 0;
|
|
@@ -6056,7 +6282,7 @@ async function readRunParentPath(runDirectory) {
|
|
|
6056
6282
|
async function runHasFormedSessionPrincipal(runDirectory) {
|
|
6057
6283
|
const disk = await readRoleRunStateDisk(runDirectory);
|
|
6058
6284
|
if (disk === void 0) return false;
|
|
6059
|
-
const sessionFile = typeof disk.principalWire.sessionFile === "string" && disk.principalWire.sessionFile.trim() !== "" ? disk.principalWire.sessionFile :
|
|
6285
|
+
const sessionFile = typeof disk.principalWire.sessionFile === "string" && disk.principalWire.sessionFile.trim() !== "" ? disk.principalWire.sessionFile : join16(disk.principalWire.sessionDirectory, "session.jsonl");
|
|
6060
6286
|
try {
|
|
6061
6287
|
const stat2 = await lstat2(sessionFile);
|
|
6062
6288
|
return stat2.isFile() && !stat2.isSymbolicLink();
|
|
@@ -6081,7 +6307,7 @@ async function findLatestRunIdForSeatTicket(input) {
|
|
|
6081
6307
|
const suffix = `@${input.role}`;
|
|
6082
6308
|
let best;
|
|
6083
6309
|
for (const runDirectory of runDirectories) {
|
|
6084
|
-
const entry =
|
|
6310
|
+
const entry = basename5(runDirectory);
|
|
6085
6311
|
if (!entry.endsWith(suffix)) continue;
|
|
6086
6312
|
const runId = entry.slice(0, entry.length - suffix.length);
|
|
6087
6313
|
if (runId.length === 0) continue;
|
|
@@ -6204,7 +6430,7 @@ async function loadResumableRunRecord(home, runId, authority) {
|
|
|
6204
6430
|
let sourceRun;
|
|
6205
6431
|
try {
|
|
6206
6432
|
const raw = JSON.parse(
|
|
6207
|
-
await
|
|
6433
|
+
await readFile10(run.admittedRequestPath, "utf8")
|
|
6208
6434
|
);
|
|
6209
6435
|
if (raw !== null && typeof raw === "object" && !Array.isArray(raw)) {
|
|
6210
6436
|
const record4 = raw;
|
|
@@ -6322,7 +6548,7 @@ async function loadResumableRunRecord(home, runId, authority) {
|
|
|
6322
6548
|
let model;
|
|
6323
6549
|
try {
|
|
6324
6550
|
const invocationRaw = JSON.parse(
|
|
6325
|
-
await
|
|
6551
|
+
await readFile10(join16(run.runDirectory, "invocation.json"), "utf8")
|
|
6326
6552
|
);
|
|
6327
6553
|
if (invocationRaw !== null && typeof invocationRaw === "object" && !Array.isArray(invocationRaw)) {
|
|
6328
6554
|
const rec = invocationRaw;
|
|
@@ -6791,7 +7017,7 @@ __export(notary_source_run_exports, {
|
|
|
6791
7017
|
loadNotarySourceRunLocator: () => loadNotarySourceRunLocator,
|
|
6792
7018
|
resolveNotarySourceRunLocator: () => resolveNotarySourceRunLocator
|
|
6793
7019
|
});
|
|
6794
|
-
import { dirname as
|
|
7020
|
+
import { dirname as dirname9, isAbsolute as isAbsolute6, join as join17, resolve as resolve8, basename as basename6 } from "node:path";
|
|
6795
7021
|
import { lstat as lstat3, realpath as realpath3 } from "node:fs/promises";
|
|
6796
7022
|
function parseRunDirectoryName(name) {
|
|
6797
7023
|
const match = RUN_DIR_NAME.exec(name);
|
|
@@ -6822,10 +7048,10 @@ async function requireRunDirectory(candidate, display) {
|
|
|
6822
7048
|
`notary --source-run must be a run directory: ${display}`
|
|
6823
7049
|
);
|
|
6824
7050
|
}
|
|
6825
|
-
const identity = parseRunDirectoryName(
|
|
7051
|
+
const identity = parseRunDirectoryName(basename6(real));
|
|
6826
7052
|
if (identity === void 0) {
|
|
6827
7053
|
throw new NotarySourceRunError(
|
|
6828
|
-
`notary --source-run must be named <runId>@<role>: ${
|
|
7054
|
+
`notary --source-run must be named <runId>@<role>: ${basename6(real)}`
|
|
6829
7055
|
);
|
|
6830
7056
|
}
|
|
6831
7057
|
return real;
|
|
@@ -6837,20 +7063,20 @@ async function resolveNotarySourceRunLocator(options) {
|
|
|
6837
7063
|
}
|
|
6838
7064
|
const ledgerHome = resolveActivationLedgerHome(options.home);
|
|
6839
7065
|
const bookKey = resolveBookKeyFromGit(options.projectRoot);
|
|
6840
|
-
const bookRunsRoot =
|
|
7066
|
+
const bookRunsRoot = join17(activationBookDirectory(ledgerHome, bookKey), "runs");
|
|
6841
7067
|
let candidate;
|
|
6842
7068
|
const bare = parseRunDirectoryName(raw);
|
|
6843
7069
|
if (bare !== void 0 && !raw.includes("/") && !raw.includes("\\")) {
|
|
6844
|
-
candidate = await findRunDirectoryById(options.home, bare.runId, bookKey, bare.role) ??
|
|
7070
|
+
candidate = await findRunDirectoryById(options.home, bare.runId, bookKey, bare.role) ?? join17(bookRunsRoot, `${bare.runId}@${bare.role}`);
|
|
6845
7071
|
} else {
|
|
6846
7072
|
candidate = isAbsolute6(raw) ? raw : resolve8(options.projectRoot, raw);
|
|
6847
7073
|
}
|
|
6848
7074
|
const real = await requireRunDirectory(candidate, raw);
|
|
6849
|
-
const identity = parseRunDirectoryName(
|
|
7075
|
+
const identity = parseRunDirectoryName(basename6(real));
|
|
6850
7076
|
const bookIdentity = physicalPathIdentity(activationBookDirectory(ledgerHome, bookKey));
|
|
6851
|
-
const parentIdentity = physicalPathIdentity(
|
|
6852
|
-
const subjectBookIdentity = physicalPathIdentity(
|
|
6853
|
-
if (parentIdentity !== physicalPathIdentity(bookRunsRoot) && !(
|
|
7077
|
+
const parentIdentity = physicalPathIdentity(dirname9(real));
|
|
7078
|
+
const subjectBookIdentity = physicalPathIdentity(dirname9(dirname9(dirname9(real))));
|
|
7079
|
+
if (parentIdentity !== physicalPathIdentity(bookRunsRoot) && !(basename6(dirname9(real)) === "runs" && subjectBookIdentity === bookIdentity)) {
|
|
6854
7080
|
throw new NotarySourceRunError(
|
|
6855
7081
|
"notary --source-run must resolve to a retained run under the project machine-ledger book"
|
|
6856
7082
|
);
|
|
@@ -6884,7 +7110,7 @@ async function resolveNotarySourceRunLocator(options) {
|
|
|
6884
7110
|
}
|
|
6885
7111
|
async function loadNotarySourceRunLocator(path) {
|
|
6886
7112
|
const real = await requireRunDirectory(path, path);
|
|
6887
|
-
const identity = parseRunDirectoryName(
|
|
7113
|
+
const identity = parseRunDirectoryName(basename6(real));
|
|
6888
7114
|
const runState = await readRoleRunIdentity(real);
|
|
6889
7115
|
if (runState === void 0) {
|
|
6890
7116
|
throw new NotarySourceRunError(
|
|
@@ -8033,14 +8259,14 @@ import { existsSync as existsSync6 } from "node:fs";
|
|
|
8033
8259
|
import {
|
|
8034
8260
|
lstat as lstat4,
|
|
8035
8261
|
mkdtemp as mkdtemp2,
|
|
8036
|
-
readFile as
|
|
8262
|
+
readFile as readFile11,
|
|
8037
8263
|
realpath as realpath4,
|
|
8038
8264
|
rename,
|
|
8039
8265
|
rm as rm2,
|
|
8040
8266
|
writeFile as writeFile5
|
|
8041
8267
|
} from "node:fs/promises";
|
|
8042
8268
|
import { tmpdir as tmpdir2 } from "node:os";
|
|
8043
|
-
import { basename as
|
|
8269
|
+
import { basename as basename7, dirname as dirname10, isAbsolute as isAbsolute7, join as join18, resolve as resolve9, sep as sep4 } from "node:path";
|
|
8044
8270
|
function issueAdmissionPlacement(authority, request) {
|
|
8045
8271
|
const ledgerHome = resolveActivationLedgerHome(request.home);
|
|
8046
8272
|
const bookKey = resolveBookKeyFromGit(request.cwd);
|
|
@@ -8094,15 +8320,15 @@ async function writeRoleInvocationLedger(source, role, effectiveModel) {
|
|
|
8094
8320
|
...effectiveModelLedgerFields(effectiveModel)
|
|
8095
8321
|
};
|
|
8096
8322
|
await writeFile5(
|
|
8097
|
-
|
|
8323
|
+
join18(source.runDirectory, "invocation.json"),
|
|
8098
8324
|
`${JSON.stringify(identity, null, 2)}
|
|
8099
8325
|
`,
|
|
8100
8326
|
"utf8"
|
|
8101
8327
|
);
|
|
8102
8328
|
}
|
|
8103
8329
|
async function recordEffectiveInvocationModel(runDirectory, model, engine, host, engineModel) {
|
|
8104
|
-
const ledgerPath =
|
|
8105
|
-
const current = JSON.parse(await
|
|
8330
|
+
const ledgerPath = join18(runDirectory, "invocation.json");
|
|
8331
|
+
const current = JSON.parse(await readFile11(ledgerPath, "utf8"));
|
|
8106
8332
|
const next = { ...current };
|
|
8107
8333
|
if (model !== void 0) {
|
|
8108
8334
|
next.provider = model.provider;
|
|
@@ -8134,8 +8360,8 @@ async function recordEffectiveInvocationModel(runDirectory, model, engine, host,
|
|
|
8134
8360
|
);
|
|
8135
8361
|
}
|
|
8136
8362
|
async function mergeInvocationIdentityPage(runDirectory, fields) {
|
|
8137
|
-
const ledgerPath =
|
|
8138
|
-
const current = JSON.parse(await
|
|
8363
|
+
const ledgerPath = join18(runDirectory, "invocation.json");
|
|
8364
|
+
const current = JSON.parse(await readFile11(ledgerPath, "utf8"));
|
|
8139
8365
|
await writeFile5(
|
|
8140
8366
|
ledgerPath,
|
|
8141
8367
|
`${JSON.stringify({
|
|
@@ -8151,7 +8377,7 @@ async function persistAdmittedSourceRunPath(admitted, sourceRunPath) {
|
|
|
8151
8377
|
throw new Error("persistAdmittedSourceRunPath requires a non-empty sourceRunPath");
|
|
8152
8378
|
}
|
|
8153
8379
|
const admittedPath = admitted.admittedRequestPath;
|
|
8154
|
-
const current = JSON.parse(await
|
|
8380
|
+
const current = JSON.parse(await readFile11(admittedPath, "utf8"));
|
|
8155
8381
|
if (typeof current.sourceRunPath === "string") {
|
|
8156
8382
|
if (current.sourceRunPath === sourceRunPath) return;
|
|
8157
8383
|
throw new Error(
|
|
@@ -8177,7 +8403,7 @@ async function bindAdmittedTicketNumber(admitted, ticketNumber) {
|
|
|
8177
8403
|
}
|
|
8178
8404
|
async function recordAdmittedCorrelation(admitted, correlationId) {
|
|
8179
8405
|
const current = JSON.parse(
|
|
8180
|
-
await
|
|
8406
|
+
await readFile11(admitted.admittedRequestPath, "utf8")
|
|
8181
8407
|
);
|
|
8182
8408
|
const prior = [
|
|
8183
8409
|
...Array.isArray(current.correlationIds) ? current.correlationIds.filter(
|
|
@@ -8225,7 +8451,7 @@ async function bindCourtTicketNumbersOnAdmitted(admitted, courtTicketNumbers) {
|
|
|
8225
8451
|
}
|
|
8226
8452
|
const frozen = Object.freeze([...projected]);
|
|
8227
8453
|
const admittedPath = admitted.admittedRequestPath;
|
|
8228
|
-
const current = JSON.parse(await
|
|
8454
|
+
const current = JSON.parse(await readFile11(admittedPath, "utf8"));
|
|
8229
8455
|
await writeFile5(
|
|
8230
8456
|
admittedPath,
|
|
8231
8457
|
`${JSON.stringify({ ...current, courtTicketNumbers: frozen }, null, 2)}
|
|
@@ -8247,7 +8473,7 @@ async function relocateAdmittedRunToTicket(admitted, authority, heldLease) {
|
|
|
8247
8473
|
runId: admitted.runId,
|
|
8248
8474
|
role: admitted.role
|
|
8249
8475
|
});
|
|
8250
|
-
ensureRoleRunDirectory(ledgerHome,
|
|
8476
|
+
ensureRoleRunDirectory(ledgerHome, dirname10(target.runDirectory));
|
|
8251
8477
|
await rename(oldRunDirectory, target.runDirectory);
|
|
8252
8478
|
heldLease?.relocate(target.runDirectory);
|
|
8253
8479
|
const admittedRecord = admitted;
|
|
@@ -8285,9 +8511,9 @@ async function bindTicketNumberOnRunDirectory(runDirectory, ticketNumber) {
|
|
|
8285
8511
|
ticketNumber,
|
|
8286
8512
|
"bindTicketNumberOnRunDirectory"
|
|
8287
8513
|
);
|
|
8288
|
-
const admittedPath =
|
|
8289
|
-
const invocationPath =
|
|
8290
|
-
const admitted = JSON.parse(await
|
|
8514
|
+
const admittedPath = join18(runDirectory, "admitted-request.json");
|
|
8515
|
+
const invocationPath = join18(runDirectory, "invocation.json");
|
|
8516
|
+
const admitted = JSON.parse(await readFile11(admittedPath, "utf8"));
|
|
8291
8517
|
const existing = admitted.ticketNumber;
|
|
8292
8518
|
if (typeof existing === "number") {
|
|
8293
8519
|
if (existing === ticketNumber) return;
|
|
@@ -8297,7 +8523,7 @@ async function bindTicketNumberOnRunDirectory(runDirectory, ticketNumber) {
|
|
|
8297
8523
|
}
|
|
8298
8524
|
if (existsSync6(invocationPath)) {
|
|
8299
8525
|
const invocation = JSON.parse(
|
|
8300
|
-
await
|
|
8526
|
+
await readFile11(invocationPath, "utf8")
|
|
8301
8527
|
);
|
|
8302
8528
|
if (typeof invocation.ticketNumber === "number" && invocation.ticketNumber !== ticketNumber) {
|
|
8303
8529
|
throw new Error(
|
|
@@ -8322,7 +8548,7 @@ async function recordLaunchedPiIdentity(runDirectory, identity) {
|
|
|
8322
8548
|
async function observeLaunchedRolePackageIdentity(packageRoot, selectedRoleEntry) {
|
|
8323
8549
|
const rolePackageRoot = packageRoot;
|
|
8324
8550
|
const raw = JSON.parse(
|
|
8325
|
-
await
|
|
8551
|
+
await readFile11(join18(rolePackageRoot, "package.json"), "utf8")
|
|
8326
8552
|
);
|
|
8327
8553
|
if (typeof raw.version !== "string" || raw.version.trim() === "") {
|
|
8328
8554
|
throw new Error(
|
|
@@ -8607,7 +8833,7 @@ async function readRegularFileAttachment(sourcePath) {
|
|
|
8607
8833
|
);
|
|
8608
8834
|
}
|
|
8609
8835
|
try {
|
|
8610
|
-
return { absolute, bytes: await
|
|
8836
|
+
return { absolute, bytes: await readFile11(absolute) };
|
|
8611
8837
|
} catch (error) {
|
|
8612
8838
|
throw new CliUsageError(
|
|
8613
8839
|
`attachment is not a readable regular file: ${sourcePath}`,
|
|
@@ -8620,13 +8846,13 @@ async function removePreparedAttachmentDirectory(stagingDirectory) {
|
|
|
8620
8846
|
}
|
|
8621
8847
|
async function withPreparedAttachments(attachmentPaths, use) {
|
|
8622
8848
|
if (attachmentPaths.length === 0) return await use([]);
|
|
8623
|
-
const stagingDirectory = await mkdtemp2(
|
|
8849
|
+
const stagingDirectory = await mkdtemp2(join18(tmpdir2(), "ak-role-attachments-"));
|
|
8624
8850
|
const prepared = [];
|
|
8625
8851
|
let result;
|
|
8626
8852
|
try {
|
|
8627
8853
|
for (let index = 0; index < attachmentPaths.length; index += 1) {
|
|
8628
8854
|
const { absolute, bytes } = await readRegularFileAttachment(attachmentPaths[index]);
|
|
8629
|
-
const snapshotPath =
|
|
8855
|
+
const snapshotPath = join18(stagingDirectory, String(index).padStart(6, "0"));
|
|
8630
8856
|
await writeFile5(snapshotPath, bytes);
|
|
8631
8857
|
prepared.push({ absolute, snapshotPath });
|
|
8632
8858
|
}
|
|
@@ -8647,9 +8873,9 @@ async function withPreparedAttachments(attachmentPaths, use) {
|
|
|
8647
8873
|
return result;
|
|
8648
8874
|
}
|
|
8649
8875
|
async function freezeAttachmentBytes(provenancePath, bytes, destinationDir, index) {
|
|
8650
|
-
const frozenPath =
|
|
8876
|
+
const frozenPath = join18(
|
|
8651
8877
|
destinationDir,
|
|
8652
|
-
`${String(index).padStart(2, "0")}-${
|
|
8878
|
+
`${String(index).padStart(2, "0")}-${basename7(provenancePath)}`
|
|
8653
8879
|
);
|
|
8654
8880
|
await writeFile5(frozenPath, bytes);
|
|
8655
8881
|
return {
|
|
@@ -8663,7 +8889,7 @@ async function freezeAttachmentBytes(provenancePath, bytes, destinationDir, inde
|
|
|
8663
8889
|
async function freezePreparedAttachment(prepared, destinationDir, index) {
|
|
8664
8890
|
return freezeAttachmentBytes(
|
|
8665
8891
|
prepared.absolute,
|
|
8666
|
-
await
|
|
8892
|
+
await readFile11(prepared.snapshotPath),
|
|
8667
8893
|
destinationDir,
|
|
8668
8894
|
index
|
|
8669
8895
|
);
|
|
@@ -8690,14 +8916,14 @@ async function freezeAttachments(attachmentPaths, attachmentsDirectory) {
|
|
|
8690
8916
|
async function freezeAttachmentsIntoRun(attachmentPaths, runDirectory, summonsKey = `s-${Date.now().toString(36)}`) {
|
|
8691
8917
|
if (attachmentPaths.length === 0) return [];
|
|
8692
8918
|
const ledgerHome = resolveActivationLedgerHome(homeFromRunDirectory(runDirectory));
|
|
8693
|
-
const attachmentsDirectory =
|
|
8919
|
+
const attachmentsDirectory = join18(runDirectory, "attachments", summonsKey);
|
|
8694
8920
|
ensureRealDirectoryTree(ledgerHome, attachmentsDirectory);
|
|
8695
8921
|
return freezeAttachments(attachmentPaths, attachmentsDirectory);
|
|
8696
8922
|
}
|
|
8697
8923
|
async function freezePreparedAttachmentsIntoRun(prepared, runDirectory, summonsKey) {
|
|
8698
8924
|
if (prepared.length === 0) return [];
|
|
8699
8925
|
const ledgerHome = resolveActivationLedgerHome(homeFromRunDirectory(runDirectory));
|
|
8700
|
-
const attachmentsDirectory = summonsKey === void 0 ?
|
|
8926
|
+
const attachmentsDirectory = summonsKey === void 0 ? join18(runDirectory, "attachments") : join18(runDirectory, "attachments", summonsKey);
|
|
8701
8927
|
ensureRealDirectoryTree(ledgerHome, attachmentsDirectory);
|
|
8702
8928
|
const attachments = [];
|
|
8703
8929
|
for (let index = 0; index < prepared.length; index += 1) {
|
|
@@ -8759,7 +8985,7 @@ async function admitStandardMaterialInvocation(role, options) {
|
|
|
8759
8985
|
})),
|
|
8760
8986
|
...ticketFields
|
|
8761
8987
|
};
|
|
8762
|
-
const admittedRequestPath =
|
|
8988
|
+
const admittedRequestPath = join18(runDirectory, "admitted-request.json");
|
|
8763
8989
|
await writeAdmittedRequestPersistence(admittedRequestPath, admitted, {
|
|
8764
8990
|
sessionDirectory,
|
|
8765
8991
|
sessionFile
|
|
@@ -8868,7 +9094,7 @@ async function admitCountersignInvocation(options) {
|
|
|
8868
9094
|
mediaKind: a.mediaKind
|
|
8869
9095
|
}))
|
|
8870
9096
|
};
|
|
8871
|
-
const admittedRequestPath =
|
|
9097
|
+
const admittedRequestPath = join18(runDirectory, "admitted-request.json");
|
|
8872
9098
|
if (options.deferPersistence !== true) {
|
|
8873
9099
|
await writeAdmittedRequestPersistence(admittedRequestPath, admitted, {
|
|
8874
9100
|
sessionDirectory,
|
|
@@ -8919,7 +9145,7 @@ function buildCountersignTransportPrompt(admitted, engineMaterial) {
|
|
|
8919
9145
|
async function loadAdmittedJudgeRequest(runDirectory) {
|
|
8920
9146
|
try {
|
|
8921
9147
|
const raw = JSON.parse(
|
|
8922
|
-
await
|
|
9148
|
+
await readFile11(join18(runDirectory, "admitted-request.json"), "utf8")
|
|
8923
9149
|
);
|
|
8924
9150
|
if (raw === null || typeof raw !== "object" || Array.isArray(raw)) return void 0;
|
|
8925
9151
|
const record4 = raw;
|
|
@@ -8974,7 +9200,7 @@ async function admitCoderInvocation(options) {
|
|
|
8974
9200
|
home: options.home
|
|
8975
9201
|
});
|
|
8976
9202
|
const attachments = await freezeAttachments(options.attachmentPaths, attachmentsDirectory);
|
|
8977
|
-
const taskPath =
|
|
9203
|
+
const taskPath = join18(runDirectory, "task.md");
|
|
8978
9204
|
await writeFile5(taskPath, instruction, "utf8");
|
|
8979
9205
|
const admitted = {
|
|
8980
9206
|
role: "coder",
|
|
@@ -8995,7 +9221,7 @@ async function admitCoderInvocation(options) {
|
|
|
8995
9221
|
mediaKind: a.mediaKind
|
|
8996
9222
|
}))
|
|
8997
9223
|
};
|
|
8998
|
-
const admittedRequestPath =
|
|
9224
|
+
const admittedRequestPath = join18(runDirectory, "admitted-request.json");
|
|
8999
9225
|
await writeAdmittedRequestPersistence(admittedRequestPath, admitted, {
|
|
9000
9226
|
sessionDirectory,
|
|
9001
9227
|
sessionFile
|
|
@@ -9045,7 +9271,7 @@ async function admitFixerInvocation(options) {
|
|
|
9045
9271
|
if (options.prerequisitesPath !== void 0) {
|
|
9046
9272
|
const absolutePrereq = isAbsolute7(options.prerequisitesPath) ? options.prerequisitesPath : resolve9(options.prerequisitesPath);
|
|
9047
9273
|
try {
|
|
9048
|
-
prerequisitesSource = await
|
|
9274
|
+
prerequisitesSource = await readFile11(absolutePrereq, "utf8");
|
|
9049
9275
|
} catch (error) {
|
|
9050
9276
|
throw new CliUsageError(
|
|
9051
9277
|
`fixer prerequisites path is unreadable: ${options.prerequisitesPath}`,
|
|
@@ -9081,7 +9307,7 @@ async function admitFixerInvocation(options) {
|
|
|
9081
9307
|
const attachments = await freezeAttachments(options.attachmentPaths, attachmentsDirectory);
|
|
9082
9308
|
let prerequisitesPath;
|
|
9083
9309
|
if (prerequisitesSource !== void 0) {
|
|
9084
|
-
prerequisitesPath =
|
|
9310
|
+
prerequisitesPath = join18(runDirectory, "prerequisites.json");
|
|
9085
9311
|
await writeFile5(
|
|
9086
9312
|
prerequisitesPath,
|
|
9087
9313
|
`${JSON.stringify(prerequisites, null, 2)}
|
|
@@ -9089,7 +9315,7 @@ async function admitFixerInvocation(options) {
|
|
|
9089
9315
|
"utf8"
|
|
9090
9316
|
);
|
|
9091
9317
|
}
|
|
9092
|
-
const packetPath =
|
|
9318
|
+
const packetPath = join18(runDirectory, "fix-packet.md");
|
|
9093
9319
|
await writeFile5(packetPath, instruction, "utf8");
|
|
9094
9320
|
const admitted = {
|
|
9095
9321
|
role: "fixer",
|
|
@@ -9115,7 +9341,7 @@ async function admitFixerInvocation(options) {
|
|
|
9115
9341
|
mediaKind: a.mediaKind
|
|
9116
9342
|
}))
|
|
9117
9343
|
};
|
|
9118
|
-
const admittedRequestPath =
|
|
9344
|
+
const admittedRequestPath = join18(runDirectory, "admitted-request.json");
|
|
9119
9345
|
await writeAdmittedRequestPersistence(admittedRequestPath, admitted, {
|
|
9120
9346
|
sessionDirectory,
|
|
9121
9347
|
sessionFile
|
|
@@ -9335,7 +9561,7 @@ async function admitCollectorInvocation(options) {
|
|
|
9335
9561
|
const prNumber = target.kind === "bound" ? target.prNumber : void 0;
|
|
9336
9562
|
let requestManifestPath;
|
|
9337
9563
|
if (manifestCanonicalJson !== void 0) {
|
|
9338
|
-
requestManifestPath =
|
|
9564
|
+
requestManifestPath = join18(runDirectory, "request-manifest.json");
|
|
9339
9565
|
await writeFile5(requestManifestPath, manifestCanonicalJson, "utf8");
|
|
9340
9566
|
}
|
|
9341
9567
|
const admitted = {
|
|
@@ -9361,7 +9587,7 @@ async function admitCollectorInvocation(options) {
|
|
|
9361
9587
|
mediaKind: a.mediaKind
|
|
9362
9588
|
}))
|
|
9363
9589
|
};
|
|
9364
|
-
const admittedRequestPath =
|
|
9590
|
+
const admittedRequestPath = join18(runDirectory, "admitted-request.json");
|
|
9365
9591
|
await writeAdmittedRequestPersistence(admittedRequestPath, admitted, {
|
|
9366
9592
|
sessionDirectory,
|
|
9367
9593
|
sessionFile
|
|
@@ -9459,7 +9685,7 @@ function parseDoctorArgv(args) {
|
|
|
9459
9685
|
}
|
|
9460
9686
|
async function resolveDoctorCaseRunsPath(options) {
|
|
9461
9687
|
const ledgerHome = resolveActivationLedgerHome(options.home);
|
|
9462
|
-
const defaultRuns =
|
|
9688
|
+
const defaultRuns = join18(
|
|
9463
9689
|
activationBookDirectory(ledgerHome, options.bookKey),
|
|
9464
9690
|
String(options.issueNumber),
|
|
9465
9691
|
"runs"
|
|
@@ -9590,7 +9816,7 @@ async function admitDoctorInvocation(options) {
|
|
|
9590
9816
|
mediaKind: a.mediaKind
|
|
9591
9817
|
}))
|
|
9592
9818
|
};
|
|
9593
|
-
const admittedRequestPath =
|
|
9819
|
+
const admittedRequestPath = join18(runDirectory, "admitted-request.json");
|
|
9594
9820
|
await writeAdmittedRequestPersistence(admittedRequestPath, admitted, {
|
|
9595
9821
|
sessionDirectory,
|
|
9596
9822
|
sessionFile
|
|
@@ -9722,7 +9948,7 @@ async function admitNotaryInvocation(options) {
|
|
|
9722
9948
|
...ticketFields,
|
|
9723
9949
|
...options.correlationId === void 0 ? {} : { correlationId: options.correlationId }
|
|
9724
9950
|
};
|
|
9725
|
-
const admittedRequestPath =
|
|
9951
|
+
const admittedRequestPath = join18(runDirectory, "admitted-request.json");
|
|
9726
9952
|
await writeAdmittedRequestPersistence(admittedRequestPath, admitted, {
|
|
9727
9953
|
sessionDirectory,
|
|
9728
9954
|
sessionFile
|
|
@@ -9825,7 +10051,7 @@ async function admitGleanerLeftInvocation(options) {
|
|
|
9825
10051
|
attachments: [],
|
|
9826
10052
|
...options.correlationId === void 0 ? {} : { correlationId: options.correlationId }
|
|
9827
10053
|
};
|
|
9828
|
-
const admittedRequestPath =
|
|
10054
|
+
const admittedRequestPath = join18(runDirectory, "admitted-request.json");
|
|
9829
10055
|
await writeAdmittedRequestPersistence(admittedRequestPath, admitted, {
|
|
9830
10056
|
sessionDirectory,
|
|
9831
10057
|
sessionFile
|
|
@@ -9964,7 +10190,7 @@ async function admitReviewerInvocation(options) {
|
|
|
9964
10190
|
mediaKind: a.mediaKind
|
|
9965
10191
|
}))
|
|
9966
10192
|
};
|
|
9967
|
-
const admittedRequestPath =
|
|
10193
|
+
const admittedRequestPath = join18(runDirectory, "admitted-request.json");
|
|
9968
10194
|
await writeAdmittedRequestPersistence(admittedRequestPath, admitted, {
|
|
9969
10195
|
sessionDirectory,
|
|
9970
10196
|
sessionFile
|
|
@@ -10116,7 +10342,7 @@ async function admitMergerInvocation(options) {
|
|
|
10116
10342
|
resolutionScope: [...derived.resolutionScope],
|
|
10117
10343
|
authorizedChecks: []
|
|
10118
10344
|
});
|
|
10119
|
-
const mergerInputPath =
|
|
10345
|
+
const mergerInputPath = join18(runDirectory, "merger-input.json");
|
|
10120
10346
|
await writeFile5(
|
|
10121
10347
|
mergerInputPath,
|
|
10122
10348
|
`${JSON.stringify(mergerInput, null, 2)}
|
|
@@ -10147,7 +10373,7 @@ async function admitMergerInvocation(options) {
|
|
|
10147
10373
|
mediaKind: a.mediaKind
|
|
10148
10374
|
}))
|
|
10149
10375
|
};
|
|
10150
|
-
const admittedRequestPath =
|
|
10376
|
+
const admittedRequestPath = join18(runDirectory, "admitted-request.json");
|
|
10151
10377
|
await writeAdmittedRequestPersistence(admittedRequestPath, admitted, {
|
|
10152
10378
|
sessionDirectory,
|
|
10153
10379
|
sessionFile
|
|
@@ -10431,15 +10657,15 @@ var init_invocation = __esm({
|
|
|
10431
10657
|
|
|
10432
10658
|
// src/public-cli/load-production-acp-host.ts
|
|
10433
10659
|
import { existsSync as existsSync7 } from "node:fs";
|
|
10434
|
-
import { join as
|
|
10660
|
+
import { join as join19 } from "node:path";
|
|
10435
10661
|
import { pathToFileURL } from "node:url";
|
|
10436
10662
|
async function loadProductionAcpHostFactory(packageRoot, host) {
|
|
10437
10663
|
const description = lookupHostDescription(host);
|
|
10438
10664
|
if (description === void 0) {
|
|
10439
10665
|
throw new Error(`unregistered host: ${host}`);
|
|
10440
10666
|
}
|
|
10441
|
-
const built =
|
|
10442
|
-
const source =
|
|
10667
|
+
const built = join19(packageRoot, "dist/acp-host/production-host.js");
|
|
10668
|
+
const source = join19(packageRoot, "src/acp-host/production-host.ts");
|
|
10443
10669
|
const target = existsSync7(built) ? built : source;
|
|
10444
10670
|
const href = pathToFileURL(target).href;
|
|
10445
10671
|
const mod = await import(href);
|
|
@@ -10455,15 +10681,15 @@ var init_load_production_acp_host = __esm({
|
|
|
10455
10681
|
|
|
10456
10682
|
// src/public-cli/load-production-headless-host.ts
|
|
10457
10683
|
import { existsSync as existsSync8 } from "node:fs";
|
|
10458
|
-
import { join as
|
|
10684
|
+
import { join as join20 } from "node:path";
|
|
10459
10685
|
import { pathToFileURL as pathToFileURL2 } from "node:url";
|
|
10460
10686
|
async function loadProductionHeadlessHostFactory(packageRoot, host) {
|
|
10461
10687
|
const description = lookupHeadlessHostDescription(host);
|
|
10462
10688
|
if (description === void 0) {
|
|
10463
10689
|
throw new Error(`unregistered headless host: ${host}`);
|
|
10464
10690
|
}
|
|
10465
|
-
const built =
|
|
10466
|
-
const source =
|
|
10691
|
+
const built = join20(packageRoot, "dist/headless-host/production-host.js");
|
|
10692
|
+
const source = join20(packageRoot, "src/headless-host/production-host.ts");
|
|
10467
10693
|
const target = existsSync8(built) ? built : source;
|
|
10468
10694
|
const href = pathToFileURL2(target).href;
|
|
10469
10695
|
const mod = await import(href);
|
|
@@ -10712,8 +10938,8 @@ __export(config_exports, {
|
|
|
10712
10938
|
setPersistentSeatHost: () => setPersistentSeatHost,
|
|
10713
10939
|
validatePublicCliConfigAxes: () => validatePublicCliConfigAxes
|
|
10714
10940
|
});
|
|
10715
|
-
import { mkdir, readFile as
|
|
10716
|
-
import { dirname as
|
|
10941
|
+
import { mkdir, readFile as readFile12, writeFile as writeFile6 } from "node:fs/promises";
|
|
10942
|
+
import { dirname as dirname11, join as join21 } from "node:path";
|
|
10717
10943
|
function isGateOfficerSeat(value) {
|
|
10718
10944
|
return GATE_OFFICER_SEATS.includes(value);
|
|
10719
10945
|
}
|
|
@@ -10721,12 +10947,12 @@ function publicCliConfigPath(home) {
|
|
|
10721
10947
|
if (typeof home !== "string" || home.trim() === "") {
|
|
10722
10948
|
throw new Error("home must be explicitly provided");
|
|
10723
10949
|
}
|
|
10724
|
-
return
|
|
10950
|
+
return join21(home, ".ak-roles", "public-cli.json");
|
|
10725
10951
|
}
|
|
10726
10952
|
async function loadPublicCliConfig(home) {
|
|
10727
10953
|
const path = publicCliConfigPath(home);
|
|
10728
10954
|
try {
|
|
10729
|
-
const raw = await
|
|
10955
|
+
const raw = await readFile12(path, "utf8");
|
|
10730
10956
|
return parsePublicCliConfig(JSON.parse(raw));
|
|
10731
10957
|
} catch (error) {
|
|
10732
10958
|
if (error instanceof Error && "code" in error && error.code === "ENOENT") {
|
|
@@ -10737,7 +10963,7 @@ async function loadPublicCliConfig(home) {
|
|
|
10737
10963
|
}
|
|
10738
10964
|
async function savePublicCliConfig(config, home) {
|
|
10739
10965
|
const path = publicCliConfigPath(home);
|
|
10740
|
-
await mkdir(
|
|
10966
|
+
await mkdir(dirname11(path), { recursive: true });
|
|
10741
10967
|
const normalized = parsePublicCliConfig(config);
|
|
10742
10968
|
await writeFile6(
|
|
10743
10969
|
path,
|
|
@@ -11184,7 +11410,7 @@ function credentialProvidersFromAuthData(data) {
|
|
|
11184
11410
|
}
|
|
11185
11411
|
async function loadCredentialProviders(agentDir) {
|
|
11186
11412
|
try {
|
|
11187
|
-
const raw = await
|
|
11413
|
+
const raw = await readFile12(join21(agentDir, "auth.json"), "utf8");
|
|
11188
11414
|
return credentialProvidersFromAuthData(JSON.parse(raw));
|
|
11189
11415
|
} catch (error) {
|
|
11190
11416
|
if (error instanceof Error && "code" in error && error.code === "ENOENT") {
|
|
@@ -11223,15 +11449,15 @@ __export(host_providers_exports, {
|
|
|
11223
11449
|
renderHostProvidersTable: () => renderHostProvidersTable
|
|
11224
11450
|
});
|
|
11225
11451
|
import { readFileSync as readFileSync3 } from "node:fs";
|
|
11226
|
-
import { join as
|
|
11452
|
+
import { join as join22 } from "node:path";
|
|
11227
11453
|
function hostProvidersPath(home) {
|
|
11228
11454
|
if (typeof home !== "string" || home.trim() === "") {
|
|
11229
11455
|
throw new Error("home must be explicitly provided");
|
|
11230
11456
|
}
|
|
11231
|
-
return
|
|
11457
|
+
return join22(home, ".ak-roles", "host-providers.json");
|
|
11232
11458
|
}
|
|
11233
11459
|
function hermesProviderModelsCachePath(home) {
|
|
11234
|
-
return
|
|
11460
|
+
return join22(home, ".hermes", "provider_models_cache.json");
|
|
11235
11461
|
}
|
|
11236
11462
|
function parseHostProvidersTable(value) {
|
|
11237
11463
|
if (value === null || typeof value !== "object" || Array.isArray(value)) {
|
|
@@ -11386,12 +11612,12 @@ var init_host_providers = __esm({
|
|
|
11386
11612
|
});
|
|
11387
11613
|
|
|
11388
11614
|
// src/ledger-session-read.ts
|
|
11389
|
-
import { readFile as
|
|
11390
|
-
function
|
|
11615
|
+
import { readFile as readFile13 } from "node:fs/promises";
|
|
11616
|
+
function isRecord6(value) {
|
|
11391
11617
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
11392
11618
|
}
|
|
11393
11619
|
async function readLedgerSessionJsonlLines(path) {
|
|
11394
|
-
const text = await
|
|
11620
|
+
const text = await readFile13(path, "utf8");
|
|
11395
11621
|
const lines = text.split("\n");
|
|
11396
11622
|
const out = [];
|
|
11397
11623
|
for (let index = 0; index < lines.length; index += 1) {
|
|
@@ -11412,7 +11638,7 @@ async function readLedgerSessionJsonlLines(path) {
|
|
|
11412
11638
|
});
|
|
11413
11639
|
continue;
|
|
11414
11640
|
}
|
|
11415
|
-
if (!
|
|
11641
|
+
if (!isRecord6(row)) {
|
|
11416
11642
|
const kind = row === null ? "null" : Array.isArray(row) ? "array" : typeof row;
|
|
11417
11643
|
out.push({
|
|
11418
11644
|
line: lineNumber,
|
|
@@ -11489,9 +11715,9 @@ var init_ledger_session_read = __esm({
|
|
|
11489
11715
|
});
|
|
11490
11716
|
|
|
11491
11717
|
// src/analyst-gate-cycles-read.ts
|
|
11492
|
-
import { readdir as
|
|
11493
|
-
import { join as
|
|
11494
|
-
function
|
|
11718
|
+
import { readdir as readdir6 } from "node:fs/promises";
|
|
11719
|
+
import { join as join23 } from "node:path";
|
|
11720
|
+
function isRecord7(value) {
|
|
11495
11721
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
11496
11722
|
}
|
|
11497
11723
|
function isParentAttemptBindingRow(row) {
|
|
@@ -11521,7 +11747,7 @@ function isGateTerminatingToolName(toolName) {
|
|
|
11521
11747
|
function acceptedGateReceiptIds(rows) {
|
|
11522
11748
|
const accepted = /* @__PURE__ */ new Set();
|
|
11523
11749
|
for (const row of rows) {
|
|
11524
|
-
const message =
|
|
11750
|
+
const message = isRecord7(row.message) ? row.message : void 0;
|
|
11525
11751
|
if (message?.role !== "toolResult") continue;
|
|
11526
11752
|
if (typeof message.toolCallId !== "string" || message.toolCallId.length === 0) continue;
|
|
11527
11753
|
if (message.isError === false) accepted.add(message.toolCallId);
|
|
@@ -11556,7 +11782,7 @@ function nearestAttemptBindingBefore(rows, beforeIndex) {
|
|
|
11556
11782
|
for (let i = beforeIndex - 1; i >= 0; i -= 1) {
|
|
11557
11783
|
const row = rows[i];
|
|
11558
11784
|
if (!isParentAttemptBindingRow(row)) continue;
|
|
11559
|
-
if (!
|
|
11785
|
+
if (!isRecord7(row.data) || !isRecord7(row.data.parent)) continue;
|
|
11560
11786
|
const id = row.data.parent.attemptEntryId;
|
|
11561
11787
|
const sessionFile = row.data.parent.sessionFile;
|
|
11562
11788
|
return {
|
|
@@ -11571,10 +11797,10 @@ function extractAllAcceptedGateToolCalls(rows) {
|
|
|
11571
11797
|
const out = [];
|
|
11572
11798
|
for (let rowIndex = 0; rowIndex < rows.length; rowIndex += 1) {
|
|
11573
11799
|
const row = rows[rowIndex];
|
|
11574
|
-
const message =
|
|
11800
|
+
const message = isRecord7(row.message) ? row.message : void 0;
|
|
11575
11801
|
if (message?.role !== "assistant" || !Array.isArray(message.content)) continue;
|
|
11576
11802
|
for (const part of message.content) {
|
|
11577
|
-
if (!
|
|
11803
|
+
if (!isRecord7(part) || part.type !== "toolCall") continue;
|
|
11578
11804
|
if (typeof part.id !== "string" || part.id.length === 0) continue;
|
|
11579
11805
|
if (typeof part.name !== "string" || part.name.length === 0) continue;
|
|
11580
11806
|
if (!isGateTerminatingToolName(part.name)) continue;
|
|
@@ -11582,7 +11808,7 @@ function extractAllAcceptedGateToolCalls(rows) {
|
|
|
11582
11808
|
const binding = nearestAttemptBindingBefore(rows, rowIndex);
|
|
11583
11809
|
out.push({
|
|
11584
11810
|
toolName: part.name,
|
|
11585
|
-
args:
|
|
11811
|
+
args: isRecord7(part.arguments) ? part.arguments : void 0,
|
|
11586
11812
|
accepted: true,
|
|
11587
11813
|
rowIndex,
|
|
11588
11814
|
...binding
|
|
@@ -11705,17 +11931,17 @@ function pairGateRounds(volumes) {
|
|
|
11705
11931
|
return rounds.sort((a, b) => a.officerStartedAt.localeCompare(b.officerStartedAt)).map((round, index) => ({ ...round, roundIndex: index + 1 }));
|
|
11706
11932
|
}
|
|
11707
11933
|
async function resolveOfficerSessionFromPointerFile(pointerPath) {
|
|
11708
|
-
const { readFile:
|
|
11934
|
+
const { readFile: readFile24 } = await import("node:fs/promises");
|
|
11709
11935
|
let raw;
|
|
11710
11936
|
try {
|
|
11711
|
-
raw = JSON.parse(await
|
|
11937
|
+
raw = JSON.parse(await readFile24(pointerPath, "utf8"));
|
|
11712
11938
|
} catch (error) {
|
|
11713
11939
|
throw new Error(
|
|
11714
11940
|
`direct officer run pointer unreadable in ${pointerPath}: ${error instanceof Error ? error.message : String(error)}`,
|
|
11715
11941
|
{ cause: error }
|
|
11716
11942
|
);
|
|
11717
11943
|
}
|
|
11718
|
-
if (!
|
|
11944
|
+
if (!isRecord7(raw) || raw.kind !== "direct-officer-run-pointer" || raw.version !== 1) {
|
|
11719
11945
|
throw new Error(`direct officer run pointer has unknown shape in ${pointerPath}`);
|
|
11720
11946
|
}
|
|
11721
11947
|
const sessionFile = raw.sessionFile;
|
|
@@ -11731,7 +11957,7 @@ async function readAnalystGateCyclesFromAuditorRoles(auditorRolesDirectory, opti
|
|
|
11731
11957
|
for (const directory of directories) {
|
|
11732
11958
|
let names;
|
|
11733
11959
|
try {
|
|
11734
|
-
const entries = await
|
|
11960
|
+
const entries = await readdir6(directory, { withFileTypes: true });
|
|
11735
11961
|
names = entries.filter(
|
|
11736
11962
|
(e) => e.isFile() && (e.name.endsWith(".jsonl") || e.name.endsWith(".pointer.json"))
|
|
11737
11963
|
).map((e) => e.name).sort();
|
|
@@ -11740,7 +11966,7 @@ async function readAnalystGateCyclesFromAuditorRoles(auditorRolesDirectory, opti
|
|
|
11740
11966
|
throw error;
|
|
11741
11967
|
}
|
|
11742
11968
|
for (const name of names) {
|
|
11743
|
-
const path =
|
|
11969
|
+
const path = join23(directory, name);
|
|
11744
11970
|
const fromPointer = name.endsWith(".pointer.json");
|
|
11745
11971
|
const sessionPath = fromPointer ? await resolveOfficerSessionFromPointerFile(path) : path;
|
|
11746
11972
|
if (sessionPath === void 0) continue;
|
|
@@ -11782,6 +12008,15 @@ var init_analyst_gate_cycles_read = __esm({
|
|
|
11782
12008
|
});
|
|
11783
12009
|
|
|
11784
12010
|
// src/audit-escalation.ts
|
|
12011
|
+
var audit_escalation_exports = {};
|
|
12012
|
+
__export(audit_escalation_exports, {
|
|
12013
|
+
AUDIT_ESCALATION_KIND: () => AUDIT_ESCALATION_KIND,
|
|
12014
|
+
buildAuditEscalationResult: () => buildAuditEscalationResult,
|
|
12015
|
+
disposeComplianceDecision: () => disposeComplianceDecision,
|
|
12016
|
+
isAuditEscalationProjection: () => isAuditEscalationProjection,
|
|
12017
|
+
isAuditEscalationResult: () => isAuditEscalationResult,
|
|
12018
|
+
projectAuditEscalation: () => projectAuditEscalation
|
|
12019
|
+
});
|
|
11785
12020
|
function buildAuditEscalationResult(decision, deliveredOutput) {
|
|
11786
12021
|
const auditOwned = {
|
|
11787
12022
|
kind: AUDIT_ESCALATION_KIND
|
|
@@ -11878,21 +12113,6 @@ var init_audit_escalation = __esm({
|
|
|
11878
12113
|
}
|
|
11879
12114
|
});
|
|
11880
12115
|
|
|
11881
|
-
// src/run-terminal-artifacts.ts
|
|
11882
|
-
import { basename as basename7, dirname as dirname11, join as join23 } from "node:path";
|
|
11883
|
-
function runIdFromRunDirectory(runDirectory) {
|
|
11884
|
-
const name = basename7(runDirectory);
|
|
11885
|
-
const at = name.lastIndexOf("@");
|
|
11886
|
-
if (at <= 0 || at === name.length - 1) return void 0;
|
|
11887
|
-
return name.slice(0, at);
|
|
11888
|
-
}
|
|
11889
|
-
var init_run_terminal_artifacts = __esm({
|
|
11890
|
-
"src/run-terminal-artifacts.ts"() {
|
|
11891
|
-
"use strict";
|
|
11892
|
-
init_role_run_placement();
|
|
11893
|
-
}
|
|
11894
|
-
});
|
|
11895
|
-
|
|
11896
12116
|
// src/submission-ledger.ts
|
|
11897
12117
|
import { join as join24 } from "node:path";
|
|
11898
12118
|
function runIdentity(context) {
|
|
@@ -12316,7 +12536,7 @@ var init_submission_ledger = __esm({
|
|
|
12316
12536
|
|
|
12317
12537
|
// src/session-opening-materials.ts
|
|
12318
12538
|
import { existsSync as existsSync9 } from "node:fs";
|
|
12319
|
-
import { readFile as
|
|
12539
|
+
import { readFile as readFile14 } from "node:fs/promises";
|
|
12320
12540
|
import { dirname as dirname12, join as join25 } from "node:path";
|
|
12321
12541
|
import { fileURLToPath, pathToFileURL as pathToFileURL3 } from "node:url";
|
|
12322
12542
|
function resolvePackageRootDir(moduleUrl = import.meta.url) {
|
|
@@ -12332,7 +12552,7 @@ function resolvePackageRootDir(moduleUrl = import.meta.url) {
|
|
|
12332
12552
|
return fileURLToPath(new URL("..", moduleUrl));
|
|
12333
12553
|
}
|
|
12334
12554
|
async function readPackageMaterial(relativePath) {
|
|
12335
|
-
return
|
|
12555
|
+
return readFile14(fileURLToPath(new URL(relativePath, packageRootUrl)), "utf8");
|
|
12336
12556
|
}
|
|
12337
12557
|
async function joinPackageMaterials(relativePaths) {
|
|
12338
12558
|
const chunks = [];
|
|
@@ -12478,13 +12698,13 @@ function resolveAuditDossier(source) {
|
|
|
12478
12698
|
}
|
|
12479
12699
|
return { status: "ok", runDirectory };
|
|
12480
12700
|
}
|
|
12481
|
-
function
|
|
12701
|
+
function isRecord8(value) {
|
|
12482
12702
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
12483
12703
|
}
|
|
12484
12704
|
function readDoctorAuditSubjects(context) {
|
|
12485
12705
|
const entries = context.sessionManager.getEntries?.() ?? [];
|
|
12486
12706
|
for (const entry of entries) {
|
|
12487
|
-
if (
|
|
12707
|
+
if (isRecord8(entry) && entry.type === "custom" && entry.customType === DOCTOR_CANDIDATE_ENTRY_TYPE) {
|
|
12488
12708
|
return { status: "ok" };
|
|
12489
12709
|
}
|
|
12490
12710
|
}
|
|
@@ -12618,12 +12838,12 @@ function createSystemCollectorClock() {
|
|
|
12618
12838
|
return {
|
|
12619
12839
|
wallNow: () => /* @__PURE__ */ new Date(),
|
|
12620
12840
|
monoNow: () => Number(process.hrtime.bigint() - start) / 1e6,
|
|
12621
|
-
sleep: (ms, signal) => new Promise((
|
|
12841
|
+
sleep: (ms, signal) => new Promise((resolve21, reject) => {
|
|
12622
12842
|
if (signal?.aborted) {
|
|
12623
12843
|
reject(signal.reason ?? new Error("aborted"));
|
|
12624
12844
|
return;
|
|
12625
12845
|
}
|
|
12626
|
-
const timer = setTimeout(
|
|
12846
|
+
const timer = setTimeout(resolve21, ms);
|
|
12627
12847
|
const onAbort = () => {
|
|
12628
12848
|
clearTimeout(timer);
|
|
12629
12849
|
reject(signal?.reason ?? new Error("aborted"));
|
|
@@ -13825,11 +14045,11 @@ function reportEngineDetourCall(input) {
|
|
|
13825
14045
|
recordPointer: pointer
|
|
13826
14046
|
};
|
|
13827
14047
|
}
|
|
13828
|
-
function
|
|
14048
|
+
function isRecord9(value) {
|
|
13829
14049
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
13830
14050
|
}
|
|
13831
14051
|
function callFactFromSitianPayload(payload, pointer) {
|
|
13832
|
-
if (!
|
|
14052
|
+
if (!isRecord9(payload)) return void 0;
|
|
13833
14053
|
if (payload.tool !== ENGINE_DETOUR_TOOL_NAME) return void 0;
|
|
13834
14054
|
if (typeof payload.toolCallId !== "string" || payload.toolCallId.length === 0) {
|
|
13835
14055
|
return void 0;
|
|
@@ -13846,11 +14066,11 @@ function callFactFromSitianPayload(payload, pointer) {
|
|
|
13846
14066
|
};
|
|
13847
14067
|
}
|
|
13848
14068
|
function invocationScopeIdOfRecord(record4) {
|
|
13849
|
-
if (
|
|
14069
|
+
if (isRecord9(record4.subject)) {
|
|
13850
14070
|
const fromSubject = record4.subject.invocationScopeId;
|
|
13851
14071
|
if (typeof fromSubject === "string" && fromSubject.length > 0) return fromSubject;
|
|
13852
14072
|
}
|
|
13853
|
-
if (
|
|
14073
|
+
if (isRecord9(record4.payload)) {
|
|
13854
14074
|
const fromPayload = record4.payload.invocationScopeId;
|
|
13855
14075
|
if (typeof fromPayload === "string" && fromPayload.length > 0) return fromPayload;
|
|
13856
14076
|
}
|
|
@@ -13910,7 +14130,7 @@ function readInvocationRecord(runDirectory) {
|
|
|
13910
14130
|
const raw = JSON.parse(
|
|
13911
14131
|
readFileSync4(join26(runDirectory, "invocation.json"), "utf8")
|
|
13912
14132
|
);
|
|
13913
|
-
return
|
|
14133
|
+
return isRecord9(raw) ? raw : void 0;
|
|
13914
14134
|
} catch (error) {
|
|
13915
14135
|
if (error?.code === "ENOENT") return void 0;
|
|
13916
14136
|
throw error;
|
|
@@ -13928,7 +14148,7 @@ function readInvocationSelectedHost(runDirectory) {
|
|
|
13928
14148
|
}
|
|
13929
14149
|
function withEngineDetourToolUsageFact(outcome, usage) {
|
|
13930
14150
|
if (usage === void 0) return outcome;
|
|
13931
|
-
const prior =
|
|
14151
|
+
const prior = isRecord9(outcome.decisiveFacts) ? outcome.decisiveFacts : {};
|
|
13932
14152
|
return {
|
|
13933
14153
|
...outcome,
|
|
13934
14154
|
decisiveFacts: {
|
|
@@ -13971,7 +14191,7 @@ var init_engine_detour_usage = __esm({
|
|
|
13971
14191
|
|
|
13972
14192
|
// src/package-resources/method-skill.ts
|
|
13973
14193
|
import { createHash as createHash7 } from "node:crypto";
|
|
13974
|
-
import { readFile as
|
|
14194
|
+
import { readFile as readFile15, realpath as realpath5 } from "node:fs/promises";
|
|
13975
14195
|
import { join as join27 } from "node:path";
|
|
13976
14196
|
function gitBlobOid(bytes) {
|
|
13977
14197
|
const body = typeof bytes === "string" ? Buffer.from(bytes, "utf8") : Buffer.from(bytes);
|
|
@@ -13994,11 +14214,11 @@ function resolvePackagedMethodSkillRoot(packageRoot, name) {
|
|
|
13994
14214
|
function resolvePackagedMethodSkillPath(packageRoot, name) {
|
|
13995
14215
|
return join27(resolvePackagedMethodSkillRoot(packageRoot, name), "SKILL.md");
|
|
13996
14216
|
}
|
|
13997
|
-
function
|
|
14217
|
+
function isRecord10(value) {
|
|
13998
14218
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
13999
14219
|
}
|
|
14000
14220
|
function parseProvenance(raw, expectedName) {
|
|
14001
|
-
if (!
|
|
14221
|
+
if (!isRecord10(raw)) {
|
|
14002
14222
|
throw new Error(`Packaged method provenance must be an object for ${expectedName}`);
|
|
14003
14223
|
}
|
|
14004
14224
|
if (raw.name !== expectedName) {
|
|
@@ -14012,7 +14232,7 @@ function parseProvenance(raw, expectedName) {
|
|
|
14012
14232
|
if (typeof raw.packageAdaptation !== "string" || raw.packageAdaptation.trim() === "") {
|
|
14013
14233
|
throw new Error(`Packaged method provenance packageAdaptation must be nonblank`);
|
|
14014
14234
|
}
|
|
14015
|
-
if (!
|
|
14235
|
+
if (!isRecord10(raw.upstream)) {
|
|
14016
14236
|
throw new Error(`Packaged method provenance upstream must be an object`);
|
|
14017
14237
|
}
|
|
14018
14238
|
const upstream = raw.upstream;
|
|
@@ -14039,12 +14259,12 @@ function parseProvenance(raw, expectedName) {
|
|
|
14039
14259
|
`Packaged method provenance upstream must include nonblank tag or version`
|
|
14040
14260
|
);
|
|
14041
14261
|
}
|
|
14042
|
-
if (!
|
|
14262
|
+
if (!isRecord10(raw.files)) {
|
|
14043
14263
|
throw new Error(`Packaged method provenance files must be an object`);
|
|
14044
14264
|
}
|
|
14045
14265
|
const files = {};
|
|
14046
14266
|
for (const [rel, entry] of Object.entries(raw.files)) {
|
|
14047
|
-
if (!
|
|
14267
|
+
if (!isRecord10(entry)) {
|
|
14048
14268
|
throw new Error(`Packaged method provenance file entry must be an object: ${rel}`);
|
|
14049
14269
|
}
|
|
14050
14270
|
if (typeof entry.sha256 !== "string" || !SHA256_RE.test(entry.sha256)) {
|
|
@@ -14090,7 +14310,7 @@ async function loadPackagedMethodSkillMaterial(packageRoot, name) {
|
|
|
14090
14310
|
const provenancePath = join27(rootDirectory, "provenance.json");
|
|
14091
14311
|
let provenanceRaw;
|
|
14092
14312
|
try {
|
|
14093
|
-
provenanceRaw = await
|
|
14313
|
+
provenanceRaw = await readFile15(provenancePath, "utf8");
|
|
14094
14314
|
} catch (error) {
|
|
14095
14315
|
throw new PackagedMethodSkillUnavailableError(name, provenancePath, error);
|
|
14096
14316
|
}
|
|
@@ -14107,7 +14327,7 @@ async function loadPackagedMethodSkillMaterial(packageRoot, name) {
|
|
|
14107
14327
|
const absolute = join27(rootDirectory, rel);
|
|
14108
14328
|
let bytes;
|
|
14109
14329
|
try {
|
|
14110
|
-
bytes = await
|
|
14330
|
+
bytes = await readFile15(absolute);
|
|
14111
14331
|
} catch (error) {
|
|
14112
14332
|
throw new PackagedMethodSkillUnavailableError(name, absolute, error);
|
|
14113
14333
|
}
|
|
@@ -14123,7 +14343,7 @@ async function loadPackagedMethodSkillMaterial(packageRoot, name) {
|
|
|
14123
14343
|
let raw;
|
|
14124
14344
|
try {
|
|
14125
14345
|
skillPath = await realpath5(skillPathConfigured);
|
|
14126
|
-
raw = await
|
|
14346
|
+
raw = await readFile15(skillPath, "utf8");
|
|
14127
14347
|
} catch (error) {
|
|
14128
14348
|
throw new PackagedMethodSkillUnavailableError(name, skillPathConfigured, error);
|
|
14129
14349
|
}
|
|
@@ -14415,11 +14635,11 @@ var init_navigator_invocation_identity = __esm({
|
|
|
14415
14635
|
});
|
|
14416
14636
|
|
|
14417
14637
|
// src/receipt-delivery-policy.ts
|
|
14418
|
-
function
|
|
14638
|
+
function isRecord11(value) {
|
|
14419
14639
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
14420
14640
|
}
|
|
14421
14641
|
function parseNoReceiptLifecycleFacts(input) {
|
|
14422
|
-
if (!
|
|
14642
|
+
if (!isRecord11(input) || typeof input.terminalToolCalled !== "boolean" || input.deliveryTurns !== RECEIPT_DELIVERY_TURN_LIMIT || input.sessionCompletion !== "settled-without-accepted-receipt" || input.acceptedReceipt !== false || typeof input.runPointer !== "string" || input.runPointer.trim() === "" || typeof input.attemptPointer !== "string" || input.attemptPointer.trim() === "" || !Array.isArray(input.rejectedReceipts) || !input.rejectedReceipts.every((item) => isRecord11(item) && typeof item.reason === "string")) {
|
|
14423
14643
|
throw new TypeError("malformed no-receipt lifecycle facts");
|
|
14424
14644
|
}
|
|
14425
14645
|
return {
|
|
@@ -14678,7 +14898,7 @@ __export(settlement_exports, {
|
|
|
14678
14898
|
withSubmissions: () => withSubmissions
|
|
14679
14899
|
});
|
|
14680
14900
|
import { randomUUID as randomUUID4 } from "node:crypto";
|
|
14681
|
-
import { appendFile as appendFile2, readFile as
|
|
14901
|
+
import { appendFile as appendFile2, readFile as readFile16, readdir as readdir7, writeFile as writeFile7 } from "node:fs/promises";
|
|
14682
14902
|
import { dirname as dirname14, join as join28 } from "node:path";
|
|
14683
14903
|
function sealedLedgerHome(admitted) {
|
|
14684
14904
|
return homeFromRunDirectory(admitted.runDirectory);
|
|
@@ -14822,10 +15042,10 @@ function presentControlledFailure(failure2, io) {
|
|
|
14822
15042
|
}
|
|
14823
15043
|
async function inspectJudgeSession(sessionFile) {
|
|
14824
15044
|
try {
|
|
14825
|
-
await
|
|
15045
|
+
await readFile16(sessionFile, "utf8");
|
|
14826
15046
|
return { state: "present" };
|
|
14827
15047
|
} catch (error) {
|
|
14828
|
-
if (
|
|
15048
|
+
if (isMissingPathError4(error)) return { state: "missing" };
|
|
14829
15049
|
return {
|
|
14830
15050
|
state: "unreadable",
|
|
14831
15051
|
diagnostic: error instanceof Error ? error.message || error.name : String(error)
|
|
@@ -15025,7 +15245,7 @@ function explicitInternalKnownFailureClassificationInput(failure2) {
|
|
|
15025
15245
|
...failure2.details === void 0 ? {} : { knownDetails: failure2.details }
|
|
15026
15246
|
};
|
|
15027
15247
|
}
|
|
15028
|
-
function
|
|
15248
|
+
function isMissingPathError4(error) {
|
|
15029
15249
|
return error instanceof Error && "code" in error && error.code === "ENOENT";
|
|
15030
15250
|
}
|
|
15031
15251
|
function sessionReadFailure(error, fallbackMessage) {
|
|
@@ -15054,7 +15274,7 @@ function sessionReadFailure(error, fallbackMessage) {
|
|
|
15054
15274
|
return failed;
|
|
15055
15275
|
}
|
|
15056
15276
|
async function readBoundSessionEntries(sessionFile) {
|
|
15057
|
-
const text = await
|
|
15277
|
+
const text = await readFile16(sessionFile, "utf8");
|
|
15058
15278
|
const entries = [];
|
|
15059
15279
|
for (const line2 of text.trim().split("\n").filter(Boolean)) {
|
|
15060
15280
|
try {
|
|
@@ -15120,7 +15340,7 @@ async function readSitianRetainedAuditorProviderStop(sessionFile) {
|
|
|
15120
15340
|
const { records } = await readSitianRecords(recordFile);
|
|
15121
15341
|
for (let i = records.length - 1; i >= 0; i -= 1) {
|
|
15122
15342
|
const payload = records[i]?.payload;
|
|
15123
|
-
if (!
|
|
15343
|
+
if (!isRecord12(payload) || !isRecord12(payload.response)) continue;
|
|
15124
15344
|
if (typeof payload.type === "string") continue;
|
|
15125
15345
|
const stop = sessionProviderStopFromAssistant(payload.response);
|
|
15126
15346
|
if (stop !== void 0) return stop;
|
|
@@ -15145,7 +15365,7 @@ async function loadBoundAuditorVolumes(sessionFile) {
|
|
|
15145
15365
|
try {
|
|
15146
15366
|
parentEntries = await readBoundSessionEntries(sessionFile);
|
|
15147
15367
|
} catch (error) {
|
|
15148
|
-
if (
|
|
15368
|
+
if (isMissingPathError4(error)) return void 0;
|
|
15149
15369
|
throw sessionReadFailure(error, "failed to read parent session for auditor binding");
|
|
15150
15370
|
}
|
|
15151
15371
|
const parentId = parentEntries.find((entry) => entry.type === "session")?.id;
|
|
@@ -15156,10 +15376,10 @@ async function loadBoundAuditorVolumes(sessionFile) {
|
|
|
15156
15376
|
for (const childDirectory of childDirectories) {
|
|
15157
15377
|
let names;
|
|
15158
15378
|
try {
|
|
15159
|
-
names = await
|
|
15379
|
+
names = await readdir7(childDirectory);
|
|
15160
15380
|
sawAnyDirectory = true;
|
|
15161
15381
|
} catch (error) {
|
|
15162
|
-
if (
|
|
15382
|
+
if (isMissingPathError4(error)) continue;
|
|
15163
15383
|
throw sessionReadFailure(error, "failed to read bound auditor session directory");
|
|
15164
15384
|
}
|
|
15165
15385
|
for (const file of names.filter((name) => name.endsWith(".jsonl")).sort().reverse()) {
|
|
@@ -15170,7 +15390,7 @@ async function loadBoundAuditorVolumes(sessionFile) {
|
|
|
15170
15390
|
throw sessionReadFailure(error, "failed to read discovered auditor session");
|
|
15171
15391
|
}
|
|
15172
15392
|
const header = entries.find((entry) => entry.type === "session");
|
|
15173
|
-
if (!
|
|
15393
|
+
if (!isRecord12(header)) continue;
|
|
15174
15394
|
const bindingIndexes = [];
|
|
15175
15395
|
for (let i = 0; i < entries.length; i += 1) {
|
|
15176
15396
|
const entry = entries[i];
|
|
@@ -15184,7 +15404,7 @@ async function loadBoundAuditorVolumes(sessionFile) {
|
|
|
15184
15404
|
end: idx + 1 < bindingIndexes.length ? bindingIndexes[idx + 1] : entries.length
|
|
15185
15405
|
})) : [{ entry: void 0, start: 0, end: entries.length }];
|
|
15186
15406
|
for (const { entry: bindingEntry, start, end } of bindingPasses) {
|
|
15187
|
-
const bindingParent = bindingEntry !== void 0 &&
|
|
15407
|
+
const bindingParent = bindingEntry !== void 0 && isRecord12(bindingEntry.data) && isRecord12(bindingEntry.data.parent) ? bindingEntry.data.parent : void 0;
|
|
15188
15408
|
const attemptEntryId = typeof bindingParent?.attemptEntryId === "string" ? bindingParent.attemptEntryId : void 0;
|
|
15189
15409
|
const boundSessionFile = typeof bindingParent?.sessionFile === "string" ? bindingParent.sessionFile : typeof header.parentSession === "string" ? header.parentSession : void 0;
|
|
15190
15410
|
if (boundSessionFile !== sessionFile) continue;
|
|
@@ -15208,12 +15428,12 @@ function complianceFailureFromAuditorVolumes(volumes) {
|
|
|
15208
15428
|
if (stop === void 0) continue;
|
|
15209
15429
|
for (let i = entries.length - 1; i >= 0; i -= 1) {
|
|
15210
15430
|
const entry = entries[i];
|
|
15211
|
-
if (entry?.type !== "custom" || entry.customType !== AUDITOR_COMPLIANCE_FAILURE_ENTRY_TYPE || !
|
|
15212
|
-
const parent =
|
|
15213
|
-
const failure2 =
|
|
15431
|
+
if (entry?.type !== "custom" || entry.customType !== AUDITOR_COMPLIANCE_FAILURE_ENTRY_TYPE || !isRecord12(entry.data)) continue;
|
|
15432
|
+
const parent = isRecord12(entry.data.parent) ? entry.data.parent : void 0;
|
|
15433
|
+
const failure2 = isRecord12(entry.data.failure) ? entry.data.failure : void 0;
|
|
15214
15434
|
if (parent?.sessionId !== parentId || parent.sessionFile !== sessionFile || parent.attemptEntryId !== attemptEntryId) continue;
|
|
15215
15435
|
if (failure2 === void 0) continue;
|
|
15216
|
-
const identity =
|
|
15436
|
+
const identity = isRecord12(failure2.identity) ? failure2.identity : void 0;
|
|
15217
15437
|
const typedCause = failure2.cause === "provider" || failure2.cause === "activation" || failure2.cause === "session" || failure2.cause === "output" || failure2.cause === "timeout" ? failure2.cause : void 0;
|
|
15218
15438
|
return {
|
|
15219
15439
|
...typedCause === void 0 ? {} : { cause: typedCause },
|
|
@@ -15222,7 +15442,7 @@ function complianceFailureFromAuditorVolumes(volumes) {
|
|
|
15222
15442
|
...typeof identity.code === "string" || typeof identity.code === "number" ? { code: identity.code } : {}
|
|
15223
15443
|
} },
|
|
15224
15444
|
...typeof failure2.diagnostic === "string" ? { diagnostic: failure2.diagnostic } : {},
|
|
15225
|
-
...
|
|
15445
|
+
...isRecord12(failure2.details) ? { details: failure2.details } : {}
|
|
15226
15446
|
};
|
|
15227
15447
|
}
|
|
15228
15448
|
}
|
|
@@ -15269,9 +15489,9 @@ function typedFailedTerminatingToolKnownFailure(entries) {
|
|
|
15269
15489
|
if (classification.kind !== "infrastructure") continue;
|
|
15270
15490
|
if (typeof message.toolCallId !== "string" || typeof message.toolName !== "string") continue;
|
|
15271
15491
|
if (boundRoleToolCallForResult(attemptEntries, i, message, message.toolName) === void 0) continue;
|
|
15272
|
-
const textPart = Array.isArray(message.content) ? message.content.find((part) =>
|
|
15273
|
-
const diagnostic =
|
|
15274
|
-
const details =
|
|
15492
|
+
const textPart = Array.isArray(message.content) ? message.content.find((part) => isRecord12(part) && part.type === "text" && typeof part.text === "string") : void 0;
|
|
15493
|
+
const diagnostic = isRecord12(textPart) ? textPart.text : void 0;
|
|
15494
|
+
const details = isRecord12(message.details) ? message.details : classification.fact;
|
|
15275
15495
|
return {
|
|
15276
15496
|
cause: "activation",
|
|
15277
15497
|
identity: { name: message.toolName, code: message.toolCallId },
|
|
@@ -15307,7 +15527,7 @@ async function resolveAuditedRunnerFailureResolution(input) {
|
|
|
15307
15527
|
);
|
|
15308
15528
|
if (terminatingFailure !== void 0) return resolutionOf(terminatingFailure);
|
|
15309
15529
|
} catch (error) {
|
|
15310
|
-
if (!
|
|
15530
|
+
if (!isMissingPathError4(error)) {
|
|
15311
15531
|
const failure2 = sessionReadFailure(error, "failed to recover typed terminating-tool failure");
|
|
15312
15532
|
return resolutionOf({
|
|
15313
15533
|
cause: "session",
|
|
@@ -15408,7 +15628,7 @@ function controlledFailureInputFromResolution(resolution) {
|
|
|
15408
15628
|
} : {}
|
|
15409
15629
|
};
|
|
15410
15630
|
}
|
|
15411
|
-
function
|
|
15631
|
+
function isRecord12(value) {
|
|
15412
15632
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
15413
15633
|
}
|
|
15414
15634
|
function toolResultText(message) {
|
|
@@ -15433,7 +15653,7 @@ function extractCollectorTargetBindRejection(entries) {
|
|
|
15433
15653
|
const diagnostic = toolResultText(message);
|
|
15434
15654
|
if (diagnostic.length === 0) return void 0;
|
|
15435
15655
|
const details = message.details;
|
|
15436
|
-
const code =
|
|
15656
|
+
const code = isRecord12(details) && typeof details.code === "string" && details.code.trim() !== "" ? details.code : void 0;
|
|
15437
15657
|
return code === void 0 ? { diagnostic } : { diagnostic, code };
|
|
15438
15658
|
}
|
|
15439
15659
|
return void 0;
|
|
@@ -15515,7 +15735,7 @@ function boundRoleToolCallForResult(entries, resultIndex, message, outputToolNam
|
|
|
15515
15735
|
const candidateMessage = entries[index]?.message;
|
|
15516
15736
|
if (candidateMessage?.role === "assistant" && Array.isArray(candidateMessage.content)) {
|
|
15517
15737
|
for (const part of candidateMessage.content) {
|
|
15518
|
-
if (!
|
|
15738
|
+
if (!isRecord12(part) || part.type !== "toolCall" || part.id !== callId) {
|
|
15519
15739
|
continue;
|
|
15520
15740
|
}
|
|
15521
15741
|
if (part.name !== outputToolName) return void 0;
|
|
@@ -15586,7 +15806,7 @@ function parseNavigatorAttendanceDetails(details) {
|
|
|
15586
15806
|
if (typeof details.prose === "string" && details.prose.trim() !== "") {
|
|
15587
15807
|
prose = details.prose;
|
|
15588
15808
|
} else {
|
|
15589
|
-
const next =
|
|
15809
|
+
const next = isRecord12(details.next) && typeof details.next.role === "string" ? details.next.role : void 0;
|
|
15590
15810
|
const reason = typeof details.reason === "string" && details.reason.trim() !== "" ? details.reason : void 0;
|
|
15591
15811
|
const command = typeof details.command === "string" && details.command.trim() !== "" ? details.command : void 0;
|
|
15592
15812
|
if (reason !== void 0 && next !== void 0) {
|
|
@@ -15695,7 +15915,7 @@ function detourGateContext(admitted, scope) {
|
|
|
15695
15915
|
}
|
|
15696
15916
|
async function withOptionalGateProjection(base, sessionDirectory, gateContext = {}) {
|
|
15697
15917
|
const secondaryEvidence = base.roleOutcome.kind === "failure" ? base.roleOutcome.decisiveFacts.secondaryEvidence : void 0;
|
|
15698
|
-
const skipGate =
|
|
15918
|
+
const skipGate = isRecord12(secondaryEvidence) && secondaryEvidence.kind === "role_infrastructure_failure" && (secondaryEvidence.stage === "gatekeeper" || secondaryEvidence.stage === "inspector" || secondaryEvidence.stage === "notary");
|
|
15699
15919
|
let next = base;
|
|
15700
15920
|
if (!skipGate) {
|
|
15701
15921
|
const gate = await extractGateFactFromSessionDirectory(sessionDirectory, gateContext);
|
|
@@ -15739,7 +15959,7 @@ function extractNavigatorFact(entries) {
|
|
|
15739
15959
|
const entry = entries[i];
|
|
15740
15960
|
if (entry?.type === "custom_message" && entry.customType === "ak-navigator-attendance") {
|
|
15741
15961
|
const details = entry.message?.details ?? entry.details;
|
|
15742
|
-
if (!
|
|
15962
|
+
if (!isRecord12(details)) {
|
|
15743
15963
|
return {
|
|
15744
15964
|
disposition: "unavailable",
|
|
15745
15965
|
source: "unknown",
|
|
@@ -15772,7 +15992,7 @@ async function extractNavigatorFactFromAdmittedSession(sessionFile) {
|
|
|
15772
15992
|
const entries = await readBoundSessionEntries(sessionFile);
|
|
15773
15993
|
return extractNavigatorFact(entries);
|
|
15774
15994
|
} catch (error) {
|
|
15775
|
-
if (
|
|
15995
|
+
if (isMissingPathError4(error)) {
|
|
15776
15996
|
return {
|
|
15777
15997
|
disposition: "unavailable",
|
|
15778
15998
|
source: "unknown",
|
|
@@ -15885,7 +16105,7 @@ async function readLawfulSettlementEntries(sessionFile) {
|
|
|
15885
16105
|
try {
|
|
15886
16106
|
return await readBoundSessionEntries(sessionFile);
|
|
15887
16107
|
} catch (error) {
|
|
15888
|
-
if (
|
|
16108
|
+
if (isMissingPathError4(error)) return void 0;
|
|
15889
16109
|
throw error instanceof Error && error.knownCause === "session" ? error : sessionReadFailure(error, "session unreadable");
|
|
15890
16110
|
}
|
|
15891
16111
|
}
|
|
@@ -16149,7 +16369,7 @@ async function settleLawfulCollectorTerminalResult(admitted, authority, scope) {
|
|
|
16149
16369
|
const residual = boundErroredToolCandidate(entries, index, message, COLLECTOR_WAIT_TOOL);
|
|
16150
16370
|
if (residual === void 0) continue;
|
|
16151
16371
|
const candidate = residual.candidate;
|
|
16152
|
-
const details =
|
|
16372
|
+
const details = isRecord12(candidate) ? candidate : { candidate };
|
|
16153
16373
|
const failed = await settleFailureTerminalResult(
|
|
16154
16374
|
admitted,
|
|
16155
16375
|
{
|
|
@@ -16204,7 +16424,7 @@ function extractDoctorCandidateCostFact(entries) {
|
|
|
16204
16424
|
const entry = entries[i];
|
|
16205
16425
|
if (entry?.type === "custom" && entry.customType === DOCTOR_CANDIDATE_ENTRY_TYPE) {
|
|
16206
16426
|
const data = entry.data;
|
|
16207
|
-
return
|
|
16427
|
+
return isRecord12(data) ? data.cost : void 0;
|
|
16208
16428
|
}
|
|
16209
16429
|
}
|
|
16210
16430
|
return void 0;
|
|
@@ -16215,7 +16435,7 @@ function extractDoctorCandidateAuditNoReceiptFact(entries) {
|
|
|
16215
16435
|
const entry = entries[i];
|
|
16216
16436
|
if (entry?.type === "custom" && entry.customType === DOCTOR_CANDIDATE_ENTRY_TYPE) {
|
|
16217
16437
|
const data = entry.data;
|
|
16218
|
-
return
|
|
16438
|
+
return isRecord12(data) ? data.auditNoReceipt : void 0;
|
|
16219
16439
|
}
|
|
16220
16440
|
}
|
|
16221
16441
|
return void 0;
|
|
@@ -16380,7 +16600,7 @@ async function settleLawfulSeatAcceptedTerminalResult(admitted, authority, spec,
|
|
|
16380
16600
|
);
|
|
16381
16601
|
}
|
|
16382
16602
|
if (residual !== void 0) {
|
|
16383
|
-
const details =
|
|
16603
|
+
const details = isRecord12(residual.candidate) ? residual.candidate : { candidate: residual.candidate };
|
|
16384
16604
|
const failed = await settleFailureTerminalResult(
|
|
16385
16605
|
admitted,
|
|
16386
16606
|
{
|
|
@@ -16458,11 +16678,75 @@ async function settleLawfulDiaristTerminalResult(admitted, authority, scope) {
|
|
|
16458
16678
|
async function trySettleDiaristTerminalResult(admitted, authority, scope) {
|
|
16459
16679
|
return settleLawfulDiaristTerminalResult(admitted, authority, scope);
|
|
16460
16680
|
}
|
|
16681
|
+
function countersignTerminalFromEntries(entries) {
|
|
16682
|
+
for (let index = entries.length - 1; index >= 0; index -= 1) {
|
|
16683
|
+
const entry = entries[index];
|
|
16684
|
+
if (entry?.type !== "custom") continue;
|
|
16685
|
+
if (entry.customType !== SECRETARIAT_GATE_OFFICER_ENTRY_TYPE) continue;
|
|
16686
|
+
const data = entry.data !== null && typeof entry.data === "object" && !Array.isArray(entry.data) ? entry.data : void 0;
|
|
16687
|
+
if (data?.officer !== "countersign") continue;
|
|
16688
|
+
if (data.receipt === void 0) continue;
|
|
16689
|
+
const runId = typeof data.runId === "string" && data.runId.trim() !== "" ? data.runId : void 0;
|
|
16690
|
+
return {
|
|
16691
|
+
receipt: data.receipt,
|
|
16692
|
+
...runId === void 0 ? {} : { runId }
|
|
16693
|
+
};
|
|
16694
|
+
}
|
|
16695
|
+
return void 0;
|
|
16696
|
+
}
|
|
16697
|
+
function withCountersignTerminalFact(roleOutcome, officer) {
|
|
16698
|
+
const prior = roleOutcome.decisiveFacts !== void 0 && isRecord12(roleOutcome.decisiveFacts) ? roleOutcome.decisiveFacts : {};
|
|
16699
|
+
return {
|
|
16700
|
+
...roleOutcome,
|
|
16701
|
+
decisiveFacts: {
|
|
16702
|
+
...prior,
|
|
16703
|
+
[SECRETARIAT_COUNTERSIGN_TERMINAL_FACT_KEY]: officer
|
|
16704
|
+
}
|
|
16705
|
+
};
|
|
16706
|
+
}
|
|
16707
|
+
function acceptedSecretariatDefinesOfficerProjection(roleOutcome) {
|
|
16708
|
+
const payloads = roleOutcome.payloads ?? [];
|
|
16709
|
+
for (let index = payloads.length - 1; index >= 0; index -= 1) {
|
|
16710
|
+
const payload = payloads[index];
|
|
16711
|
+
if (!isRecord12(payload)) continue;
|
|
16712
|
+
const status = payload.secretariatStatus;
|
|
16713
|
+
if (typeof status !== "string") continue;
|
|
16714
|
+
return status === "converged";
|
|
16715
|
+
}
|
|
16716
|
+
return false;
|
|
16717
|
+
}
|
|
16461
16718
|
async function settleLawfulSecretariatTerminalResult(admitted, authority, scope) {
|
|
16462
|
-
|
|
16719
|
+
const settled = await settleLawfulSeatAcceptedTerminalResult(admitted, authority, {
|
|
16463
16720
|
role: "secretariat",
|
|
16464
16721
|
toolName: SECRETARIAT_OUTPUT_TOOL_NAME
|
|
16465
16722
|
}, scope);
|
|
16723
|
+
if (settled === void 0) return void 0;
|
|
16724
|
+
const coordinates = coordinatesFromAdmitted(authority, admitted);
|
|
16725
|
+
const entries = await readLawfulSettlementEntries(coordinates.sessionFile) ?? [];
|
|
16726
|
+
const officer = countersignTerminalFromEntries(entries);
|
|
16727
|
+
if (officer === void 0) return settled;
|
|
16728
|
+
if (settled.roleOutcome.kind === "audit_escalation") {
|
|
16729
|
+
return {
|
|
16730
|
+
...settled,
|
|
16731
|
+
roleOutcome: withCountersignTerminalFact(
|
|
16732
|
+
{
|
|
16733
|
+
...settled.roleOutcome,
|
|
16734
|
+
payloads: [officer.receipt]
|
|
16735
|
+
},
|
|
16736
|
+
officer
|
|
16737
|
+
)
|
|
16738
|
+
};
|
|
16739
|
+
}
|
|
16740
|
+
if (settled.roleOutcome.kind === "accepted") {
|
|
16741
|
+
if (!acceptedSecretariatDefinesOfficerProjection(settled.roleOutcome)) {
|
|
16742
|
+
return settled;
|
|
16743
|
+
}
|
|
16744
|
+
return {
|
|
16745
|
+
...settled,
|
|
16746
|
+
roleOutcome: withCountersignTerminalFact(settled.roleOutcome, officer)
|
|
16747
|
+
};
|
|
16748
|
+
}
|
|
16749
|
+
return settled;
|
|
16466
16750
|
}
|
|
16467
16751
|
async function trySettleSecretariatTerminalResult(admitted, authority, scope) {
|
|
16468
16752
|
return settleLawfulSecretariatTerminalResult(admitted, authority, scope);
|
|
@@ -16704,7 +16988,7 @@ async function settleLawfulMergerTerminalResult(admitted, authority, options, sc
|
|
|
16704
16988
|
const residual = boundErroredToolCandidate(entries, index, message, MERGER_OUTPUT_TOOL_NAME);
|
|
16705
16989
|
if (residual === void 0) continue;
|
|
16706
16990
|
const candidate = residual.candidate;
|
|
16707
|
-
const details =
|
|
16991
|
+
const details = isRecord12(candidate) ? candidate : { candidate };
|
|
16708
16992
|
const failed = await settleFailureTerminalResult(
|
|
16709
16993
|
admitted,
|
|
16710
16994
|
{
|
|
@@ -17033,10 +17317,10 @@ function presentFailureTerminal(terminal, io) {
|
|
|
17033
17317
|
}
|
|
17034
17318
|
function defaultNavigatorGraceSleep() {
|
|
17035
17319
|
let timer;
|
|
17036
|
-
const sleep = ((ms) => new Promise((
|
|
17320
|
+
const sleep = ((ms) => new Promise((resolve21) => {
|
|
17037
17321
|
timer = setTimeout(() => {
|
|
17038
17322
|
timer = void 0;
|
|
17039
|
-
|
|
17323
|
+
resolve21();
|
|
17040
17324
|
}, ms);
|
|
17041
17325
|
}));
|
|
17042
17326
|
sleep.cancel = () => {
|
|
@@ -17048,7 +17332,7 @@ function defaultNavigatorGraceSleep() {
|
|
|
17048
17332
|
return sleep;
|
|
17049
17333
|
}
|
|
17050
17334
|
function raceNavigatorGrace(work, graceMs = NAVIGATOR_POST_ROLE_GRACE_MS, sleep = defaultNavigatorGraceSleep()) {
|
|
17051
|
-
return new Promise((
|
|
17335
|
+
return new Promise((resolve21, reject) => {
|
|
17052
17336
|
let settled = false;
|
|
17053
17337
|
const finish = (action) => {
|
|
17054
17338
|
if (settled) return;
|
|
@@ -17057,11 +17341,11 @@ function raceNavigatorGrace(work, graceMs = NAVIGATOR_POST_ROLE_GRACE_MS, sleep
|
|
|
17057
17341
|
action();
|
|
17058
17342
|
};
|
|
17059
17343
|
void work.then(
|
|
17060
|
-
(value) => finish(() =>
|
|
17344
|
+
(value) => finish(() => resolve21({ status: "done", value })),
|
|
17061
17345
|
(error) => finish(() => reject(error))
|
|
17062
17346
|
);
|
|
17063
17347
|
void sleep(graceMs).then(() => {
|
|
17064
|
-
finish(() =>
|
|
17348
|
+
finish(() => resolve21({ status: "timeout" }));
|
|
17065
17349
|
});
|
|
17066
17350
|
});
|
|
17067
17351
|
}
|
|
@@ -17153,7 +17437,7 @@ var init_seat_ticket_binding = __esm({
|
|
|
17153
17437
|
});
|
|
17154
17438
|
|
|
17155
17439
|
// src/session-identity.ts
|
|
17156
|
-
import { mkdir as mkdir3, readFile as
|
|
17440
|
+
import { mkdir as mkdir3, readFile as readFile17, rename as rename2, writeFile as writeFile8 } from "node:fs/promises";
|
|
17157
17441
|
import { dirname as dirname15, join as join29 } from "node:path";
|
|
17158
17442
|
function createSessionIdentityAuthority(authority, sessionBindingFile) {
|
|
17159
17443
|
const bindingPath = (principal) => join29(authority.decode(principal).sessionDirectory, sessionBindingFile);
|
|
@@ -17163,7 +17447,7 @@ function createSessionIdentityAuthority(authority, sessionBindingFile) {
|
|
|
17163
17447
|
},
|
|
17164
17448
|
async load(principal) {
|
|
17165
17449
|
try {
|
|
17166
|
-
const value = JSON.parse(await
|
|
17450
|
+
const value = JSON.parse(await readFile17(bindingPath(principal), "utf8"));
|
|
17167
17451
|
if (typeof value !== "object" || value === null || typeof value.sessionId !== "string") {
|
|
17168
17452
|
throw new Error("durable session binding is invalid");
|
|
17169
17453
|
}
|
|
@@ -17202,7 +17486,7 @@ var init_session_identity = __esm({
|
|
|
17202
17486
|
});
|
|
17203
17487
|
|
|
17204
17488
|
// src/session-dialogue.ts
|
|
17205
|
-
function
|
|
17489
|
+
function isRecord13(value) {
|
|
17206
17490
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
17207
17491
|
}
|
|
17208
17492
|
function nativeEventId(row) {
|
|
@@ -17212,7 +17496,7 @@ function nativeEventId(row) {
|
|
|
17212
17496
|
}
|
|
17213
17497
|
for (const nestKey of ["message", "payload"]) {
|
|
17214
17498
|
const nested = row[nestKey];
|
|
17215
|
-
if (!
|
|
17499
|
+
if (!isRecord13(nested)) continue;
|
|
17216
17500
|
for (const key of ["uuid", "id"]) {
|
|
17217
17501
|
const value = nested[key];
|
|
17218
17502
|
if (typeof value === "string" && value !== "") return value;
|
|
@@ -17225,19 +17509,19 @@ function textParts(content) {
|
|
|
17225
17509
|
if (!Array.isArray(content)) return [];
|
|
17226
17510
|
const out = [];
|
|
17227
17511
|
for (const part of content) {
|
|
17228
|
-
if (!
|
|
17512
|
+
if (!isRecord13(part) || !SPEAKER_TEXT_PART_TYPES.has(String(part.type))) continue;
|
|
17229
17513
|
const text = part.text;
|
|
17230
17514
|
if (typeof text === "string" && text !== "") out.push(text);
|
|
17231
17515
|
}
|
|
17232
17516
|
return out;
|
|
17233
17517
|
}
|
|
17234
17518
|
function responseItemMessage(row) {
|
|
17235
|
-
if (row.type !== "response_item" || !
|
|
17519
|
+
if (row.type !== "response_item" || !isRecord13(row.payload)) return void 0;
|
|
17236
17520
|
if (row.payload.type !== "message") return void 0;
|
|
17237
17521
|
return row.payload;
|
|
17238
17522
|
}
|
|
17239
17523
|
function messageBody(row) {
|
|
17240
|
-
if (
|
|
17524
|
+
if (isRecord13(row.message)) return row.message;
|
|
17241
17525
|
return responseItemMessage(row);
|
|
17242
17526
|
}
|
|
17243
17527
|
function speakerOf(message) {
|
|
@@ -17247,7 +17531,7 @@ function speakerOf(message) {
|
|
|
17247
17531
|
}
|
|
17248
17532
|
function codexContentItemKinds(message) {
|
|
17249
17533
|
const pass = message.internal_chat_message_metadata_passthrough;
|
|
17250
|
-
if (!
|
|
17534
|
+
if (!isRecord13(pass) || !Array.isArray(pass.content_item_kinds)) return void 0;
|
|
17251
17535
|
const kinds = [];
|
|
17252
17536
|
for (const kind of pass.content_item_kinds) {
|
|
17253
17537
|
if (typeof kind === "string" && kind !== "") kinds.push(kind);
|
|
@@ -17276,7 +17560,7 @@ function isFixedNonOwnerEnqueueShape(content) {
|
|
|
17276
17560
|
return hasFixedOpenTagPrefix(content, TASK_NOTIFICATION_OPEN_TAG);
|
|
17277
17561
|
}
|
|
17278
17562
|
function materializationOriginKind(row) {
|
|
17279
|
-
if (!
|
|
17563
|
+
if (!isRecord13(row.origin)) return void 0;
|
|
17280
17564
|
const kind = row.origin.kind;
|
|
17281
17565
|
return typeof kind === "string" && kind !== "" ? kind : void 0;
|
|
17282
17566
|
}
|
|
@@ -17324,7 +17608,7 @@ var init_session_dialogue = __esm({
|
|
|
17324
17608
|
|
|
17325
17609
|
// src/ticket-provenance.ts
|
|
17326
17610
|
import { createHash as createHash8 } from "node:crypto";
|
|
17327
|
-
import { readFile as
|
|
17611
|
+
import { readFile as readFile18 } from "node:fs/promises";
|
|
17328
17612
|
import { basename as basename8, dirname as dirname16, join as join30, resolve as resolve12 } from "node:path";
|
|
17329
17613
|
function dialogueSessionSourceRoots(home) {
|
|
17330
17614
|
const machineHome = typeof home === "string" && home.trim() !== "" ? home : packageMachineHome();
|
|
@@ -17420,7 +17704,7 @@ async function readTicketProvenance(ticketNumber, cwd, home) {
|
|
|
17420
17704
|
const { recordFile } = resolveTicketProvenanceVolume(ticketNumber, cwd, home);
|
|
17421
17705
|
let text;
|
|
17422
17706
|
try {
|
|
17423
|
-
text = await
|
|
17707
|
+
text = await readFile18(recordFile, "utf8");
|
|
17424
17708
|
} catch (error) {
|
|
17425
17709
|
if (error.code === "ENOENT") {
|
|
17426
17710
|
return {
|
|
@@ -17900,7 +18184,7 @@ __export(case_dossier_delivery_exports, {
|
|
|
17900
18184
|
loadCaseDossierReadingMaterial: () => loadCaseDossierReadingMaterial,
|
|
17901
18185
|
projectCaseDossierPointerSection: () => projectCaseDossierPointerSection
|
|
17902
18186
|
});
|
|
17903
|
-
import { mkdtemp as mkdtemp3, readFile as
|
|
18187
|
+
import { mkdtemp as mkdtemp3, readFile as readFile19, rm as rm3, writeFile as writeFile9 } from "node:fs/promises";
|
|
17904
18188
|
import { tmpdir as tmpdir3 } from "node:os";
|
|
17905
18189
|
import { join as join31 } from "node:path";
|
|
17906
18190
|
async function projectCaseDossierPointerSection(input) {
|
|
@@ -17952,7 +18236,7 @@ async function loadCaseDossierReadingMaterial(runDirectory) {
|
|
|
17952
18236
|
);
|
|
17953
18237
|
let section;
|
|
17954
18238
|
try {
|
|
17955
|
-
section = await
|
|
18239
|
+
section = await readFile19(frozenPath, "utf8");
|
|
17956
18240
|
} catch (error) {
|
|
17957
18241
|
if (error.code === "ENOENT") return void 0;
|
|
17958
18242
|
throw error;
|
|
@@ -17975,7 +18259,7 @@ var init_case_dossier_delivery = __esm({
|
|
|
17975
18259
|
});
|
|
17976
18260
|
|
|
17977
18261
|
// src/host-transition-prior-native.ts
|
|
17978
|
-
import { access as access3, readdir as
|
|
18262
|
+
import { access as access3, readdir as readdir8 } from "node:fs/promises";
|
|
17979
18263
|
import { dirname as dirname17, join as join32 } from "node:path";
|
|
17980
18264
|
function isEnoent3(error) {
|
|
17981
18265
|
return typeof error === "object" && error !== null && error.code === "ENOENT";
|
|
@@ -17993,7 +18277,7 @@ async function listSitianRecordPaths(sessionParent) {
|
|
|
17993
18277
|
const sessionRoot = dirname17(sessionParent);
|
|
17994
18278
|
let entries;
|
|
17995
18279
|
try {
|
|
17996
|
-
entries = await
|
|
18280
|
+
entries = await readdir8(sessionRoot, { withFileTypes: true });
|
|
17997
18281
|
} catch (error) {
|
|
17998
18282
|
if (isEnoent3(error)) return [];
|
|
17999
18283
|
throw error;
|
|
@@ -18067,6 +18351,24 @@ var init_public_run_credentials = __esm({
|
|
|
18067
18351
|
}
|
|
18068
18352
|
});
|
|
18069
18353
|
|
|
18354
|
+
// src/public-cli/process-cancel.ts
|
|
18355
|
+
function processCancelSignalName(signal) {
|
|
18356
|
+
if (signal === void 0 || signal.aborted !== true) return void 0;
|
|
18357
|
+
const reason = signal.reason;
|
|
18358
|
+
if (reason === "SIGTERM" || reason === "SIGINT" || reason === "SIGHUP") {
|
|
18359
|
+
return reason;
|
|
18360
|
+
}
|
|
18361
|
+
return void 0;
|
|
18362
|
+
}
|
|
18363
|
+
function processCancelDiagnostic(signalName) {
|
|
18364
|
+
return `ak-role terminated by ${signalName}`;
|
|
18365
|
+
}
|
|
18366
|
+
var init_process_cancel = __esm({
|
|
18367
|
+
"src/public-cli/process-cancel.ts"() {
|
|
18368
|
+
"use strict";
|
|
18369
|
+
}
|
|
18370
|
+
});
|
|
18371
|
+
|
|
18070
18372
|
// src/public-cli/auto-resume.ts
|
|
18071
18373
|
import { constants as fsConstants2 } from "node:fs";
|
|
18072
18374
|
import { randomUUID as randomUUID5 } from "node:crypto";
|
|
@@ -18118,7 +18420,7 @@ async function ensureRealArtifactsDirectory(runDirectory) {
|
|
|
18118
18420
|
throw new Error("run artifact retention: artifacts path is not a real directory");
|
|
18119
18421
|
}
|
|
18120
18422
|
} catch (error) {
|
|
18121
|
-
if (!
|
|
18423
|
+
if (!isMissingPathError5(error)) throw error;
|
|
18122
18424
|
await mkdir4(artifactsDir, { recursive: true });
|
|
18123
18425
|
const created = await lstat6(artifactsDir);
|
|
18124
18426
|
if (created.isSymbolicLink() || !created.isDirectory()) {
|
|
@@ -18150,7 +18452,7 @@ function serializeThrownValue(value, depth = 0, seen = /* @__PURE__ */ new WeakS
|
|
|
18150
18452
|
}
|
|
18151
18453
|
return value;
|
|
18152
18454
|
}
|
|
18153
|
-
function
|
|
18455
|
+
function isMissingPathError5(error) {
|
|
18154
18456
|
return error instanceof Error && "code" in error && error.code === "ENOENT";
|
|
18155
18457
|
}
|
|
18156
18458
|
function transferNestedValue(value, depth, seen) {
|
|
@@ -18369,6 +18671,10 @@ async function runWithAutoResumeLoop(options) {
|
|
|
18369
18671
|
if (terminal !== void 0) presentTerminal(terminal, options.io);
|
|
18370
18672
|
return result;
|
|
18371
18673
|
}
|
|
18674
|
+
if (processCancelSignalName(options.signal) !== void 0) {
|
|
18675
|
+
if (terminal !== void 0) presentTerminal(terminal, options.io);
|
|
18676
|
+
return result;
|
|
18677
|
+
}
|
|
18372
18678
|
}
|
|
18373
18679
|
if (result !== void 0) {
|
|
18374
18680
|
const terminal = result.terminal;
|
|
@@ -18402,6 +18708,28 @@ async function runWithAutoResumeLoop(options) {
|
|
|
18402
18708
|
terminal
|
|
18403
18709
|
};
|
|
18404
18710
|
}
|
|
18711
|
+
const cancelName = processCancelSignalName(options.signal);
|
|
18712
|
+
if (cancelName !== void 0) {
|
|
18713
|
+
const terminal = await attachDispatchExceptionTerminal(
|
|
18714
|
+
options.admitted,
|
|
18715
|
+
dispatchExceptionFailureTerminal({
|
|
18716
|
+
role: options.admitted.role,
|
|
18717
|
+
runId: options.admitted.runId,
|
|
18718
|
+
causeError: lastThrownError,
|
|
18719
|
+
errorFiles: retainedErrorFiles,
|
|
18720
|
+
autoResumeAttempts,
|
|
18721
|
+
endReason: `ak-role terminated by ${cancelName}`,
|
|
18722
|
+
everyAttemptThrew
|
|
18723
|
+
}),
|
|
18724
|
+
options.io
|
|
18725
|
+
);
|
|
18726
|
+
await finalizeExceptionRunBestEffort(options.admitted.runDirectory, options.io);
|
|
18727
|
+
presentTerminal(terminal, options.io);
|
|
18728
|
+
return {
|
|
18729
|
+
exitCode: 1,
|
|
18730
|
+
terminal
|
|
18731
|
+
};
|
|
18732
|
+
}
|
|
18405
18733
|
if (!await isPrincipalAvailable(options.admitted.principal)) {
|
|
18406
18734
|
const terminal = await attachDispatchExceptionTerminal(
|
|
18407
18735
|
options.admitted,
|
|
@@ -18438,6 +18766,7 @@ var init_auto_resume = __esm({
|
|
|
18438
18766
|
init_role_run_placement();
|
|
18439
18767
|
init_run_lifecycle();
|
|
18440
18768
|
init_config();
|
|
18769
|
+
init_process_cancel();
|
|
18441
18770
|
init_terminal();
|
|
18442
18771
|
init_settlement();
|
|
18443
18772
|
dummyIo = { stdout: () => {
|
|
@@ -18470,6 +18799,36 @@ function describeCaughtError(error) {
|
|
|
18470
18799
|
function isStationChildOfficerDialogue(role, env) {
|
|
18471
18800
|
return env.stationChild === true && isOfficerReviewSeat(role);
|
|
18472
18801
|
}
|
|
18802
|
+
function withProcessCancelSkipAutoResume(result, signal) {
|
|
18803
|
+
if (processCancelSignalName(signal) === void 0) {
|
|
18804
|
+
return result;
|
|
18805
|
+
}
|
|
18806
|
+
return { ...result, skipAutoResume: true };
|
|
18807
|
+
}
|
|
18808
|
+
async function settleProcessCancelAfterTurn(input) {
|
|
18809
|
+
const failed = await settleAfterTurnStarted(
|
|
18810
|
+
input.admitted,
|
|
18811
|
+
withEngineDetourInvocationScope(
|
|
18812
|
+
{
|
|
18813
|
+
timedOut: input.result.timedOut,
|
|
18814
|
+
code: input.result.code,
|
|
18815
|
+
stderr: input.result.stderr,
|
|
18816
|
+
knownDiagnostic: processCancelDiagnostic(input.cancelName)
|
|
18817
|
+
},
|
|
18818
|
+
input.invocationScopeId
|
|
18819
|
+
),
|
|
18820
|
+
input.adapters,
|
|
18821
|
+
input.env.principalAuthority,
|
|
18822
|
+
input.io,
|
|
18823
|
+
input.persistRunState
|
|
18824
|
+
);
|
|
18825
|
+
return {
|
|
18826
|
+
...failed,
|
|
18827
|
+
turnDispatched: true,
|
|
18828
|
+
skipAutoResume: true,
|
|
18829
|
+
...input.deferredPersist
|
|
18830
|
+
};
|
|
18831
|
+
}
|
|
18473
18832
|
function withOnceSuccessfulBeforeDispatch(adapters) {
|
|
18474
18833
|
const hook = adapters.beforeDispatch;
|
|
18475
18834
|
if (hook === void 0) return adapters;
|
|
@@ -18630,6 +18989,31 @@ async function dispatchPostAdmissionTurn(input) {
|
|
|
18630
18989
|
const finishAfterTurn = async (result) => {
|
|
18631
18990
|
if (afterDispatchApplied) return result;
|
|
18632
18991
|
afterDispatchApplied = true;
|
|
18992
|
+
const cancelBeforeFinish = processCancelSignalName(env.signal);
|
|
18993
|
+
if (cancelBeforeFinish !== void 0 && result.terminal !== void 0 && isLawfulTypedTerminalOutcome(result.terminal.roleOutcome)) {
|
|
18994
|
+
result = {
|
|
18995
|
+
...await settleAfterTurnStarted(
|
|
18996
|
+
admitted,
|
|
18997
|
+
withEngineDetourInvocationScope(
|
|
18998
|
+
{
|
|
18999
|
+
timedOut: false,
|
|
19000
|
+
code: null,
|
|
19001
|
+
stderr: "",
|
|
19002
|
+
knownDiagnostic: processCancelDiagnostic(cancelBeforeFinish),
|
|
19003
|
+
skipRunStateWrite: true
|
|
19004
|
+
},
|
|
19005
|
+
request.invocationScopeId
|
|
19006
|
+
),
|
|
19007
|
+
adapters,
|
|
19008
|
+
env.principalAuthority,
|
|
19009
|
+
io,
|
|
19010
|
+
persistRunState
|
|
19011
|
+
),
|
|
19012
|
+
turnDispatched: true,
|
|
19013
|
+
skipAutoResume: true,
|
|
19014
|
+
...deferredPersist
|
|
19015
|
+
};
|
|
19016
|
+
}
|
|
18633
19017
|
try {
|
|
18634
19018
|
if (admitted.ticketNumber === void 0) {
|
|
18635
19019
|
const rows = await readRecordedSubmissionRows(
|
|
@@ -18776,20 +19160,26 @@ async function dispatchPostAdmissionTurn(input) {
|
|
|
18776
19160
|
try {
|
|
18777
19161
|
result = await env.roleTurnHost.executeTurn(turnRequest);
|
|
18778
19162
|
} catch (error) {
|
|
19163
|
+
const processCancelName = processCancelSignalName(env.signal);
|
|
18779
19164
|
const settled2 = await settleAfterTurnStarted(
|
|
18780
19165
|
admitted,
|
|
18781
19166
|
withEngineDetourInvocationScope({
|
|
18782
19167
|
timedOut: false,
|
|
18783
19168
|
code: null,
|
|
18784
19169
|
stderr: "",
|
|
18785
|
-
thrown: error
|
|
19170
|
+
thrown: processCancelName === void 0 ? error : new Error(processCancelDiagnostic(processCancelName), { cause: error })
|
|
18786
19171
|
}, request.invocationScopeId),
|
|
18787
19172
|
adapters,
|
|
18788
19173
|
env.principalAuthority,
|
|
18789
19174
|
io,
|
|
18790
19175
|
persistRunState
|
|
18791
19176
|
);
|
|
18792
|
-
return await finishAfterTurn(
|
|
19177
|
+
return await finishAfterTurn(
|
|
19178
|
+
withProcessCancelSkipAutoResume(
|
|
19179
|
+
{ ...settled2, turnDispatched: true, ...deferredPersist },
|
|
19180
|
+
env.signal
|
|
19181
|
+
)
|
|
19182
|
+
);
|
|
18793
19183
|
}
|
|
18794
19184
|
let stderrLogWriteFailure;
|
|
18795
19185
|
try {
|
|
@@ -18829,7 +19219,8 @@ async function dispatchPostAdmissionTurn(input) {
|
|
|
18829
19219
|
credential: credentialFailure,
|
|
18830
19220
|
runDirectory: admitted.runDirectory
|
|
18831
19221
|
});
|
|
18832
|
-
const
|
|
19222
|
+
const processCancelName = processCancelSignalName(env.signal);
|
|
19223
|
+
const directHostFailureSignal = result.timedOut || result.knownFailure !== void 0 || runnerKnownFailure !== void 0 || credentialFailure !== void 0 || processCancelName !== void 0;
|
|
18833
19224
|
hostSignalFailed = directHostFailureSignal || result.code !== null && result.code !== 0 || resolution.knownFailure !== void 0;
|
|
18834
19225
|
settled = await adapters.trySettle(admitted, env.principalAuthority, courtScope);
|
|
18835
19226
|
if (settled !== void 0) {
|
|
@@ -18837,7 +19228,8 @@ async function dispatchPostAdmissionTurn(input) {
|
|
|
18837
19228
|
}
|
|
18838
19229
|
const settledIsFreshThisAttempt = settled === void 0 || settled.roleOutcome.kind !== "accepted" && settled.roleOutcome.kind !== "audit_escalation" ? true : await attemptProducedFreshSubmission(admitted, courtScope);
|
|
18839
19230
|
const staleAcceptanceOutranksRealFailure = !settledIsFreshThisAttempt && hostSignalFailed;
|
|
18840
|
-
|
|
19231
|
+
const cancelAfterSettle = processCancelSignalName(env.signal);
|
|
19232
|
+
if (settled !== void 0 && shouldPresent(settled) && !directHostFailureSignal && !staleAcceptanceOutranksRealFailure && stderrLogWriteFailure === void 0 && cancelAfterSettle === void 0) {
|
|
18841
19233
|
if (settled.roleOutcome.kind === "accepted" && request.courtAttemptId !== void 0 && request.courtAttemptId.length > 0) {
|
|
18842
19234
|
try {
|
|
18843
19235
|
await clearCurrentCourt(admitted.runDirectory, request.courtAttemptId);
|
|
@@ -18874,6 +19266,22 @@ async function dispatchPostAdmissionTurn(input) {
|
|
|
18874
19266
|
return await finishAfterTurn({ ...settledFailure, turnDispatched: true, ...deferredPersist });
|
|
18875
19267
|
}
|
|
18876
19268
|
if (settledOutcome !== void 0) {
|
|
19269
|
+
const lateCancel = processCancelSignalName(env.signal);
|
|
19270
|
+
if (lateCancel !== void 0) {
|
|
19271
|
+
return await finishAfterTurn(
|
|
19272
|
+
await settleProcessCancelAfterTurn({
|
|
19273
|
+
admitted,
|
|
19274
|
+
cancelName: lateCancel,
|
|
19275
|
+
result,
|
|
19276
|
+
adapters,
|
|
19277
|
+
env,
|
|
19278
|
+
io,
|
|
19279
|
+
persistRunState,
|
|
19280
|
+
deferredPersist,
|
|
19281
|
+
invocationScopeId: request.invocationScopeId
|
|
19282
|
+
})
|
|
19283
|
+
);
|
|
19284
|
+
}
|
|
18877
19285
|
if (persistRunState) {
|
|
18878
19286
|
try {
|
|
18879
19287
|
await persistReturnedRunState(admitted, env.principalAuthority, { lawful: true });
|
|
@@ -18892,13 +19300,19 @@ async function dispatchPostAdmissionTurn(input) {
|
|
|
18892
19300
|
io,
|
|
18893
19301
|
persistRunState
|
|
18894
19302
|
);
|
|
18895
|
-
return await finishAfterTurn(
|
|
19303
|
+
return await finishAfterTurn(
|
|
19304
|
+
withProcessCancelSkipAutoResume(
|
|
19305
|
+
{ ...failed, turnDispatched: true, ...deferredPersist },
|
|
19306
|
+
env.signal
|
|
19307
|
+
)
|
|
19308
|
+
);
|
|
18896
19309
|
}
|
|
18897
19310
|
}
|
|
18898
19311
|
return await finishAfterTurn({ ...settledOutcome, ...deferredPersist });
|
|
18899
19312
|
}
|
|
18900
19313
|
if (hostSignalFailed) {
|
|
18901
19314
|
const resolutionInput = controlledFailureInputFromResolution(resolution);
|
|
19315
|
+
const processCancelName = processCancelSignalName(env.signal);
|
|
18902
19316
|
const stderrLogWriteDetails = stderrLogWriteFailure === void 0 ? void 0 : { stderrLogWriteFailure: describeCaughtError(stderrLogWriteFailure) };
|
|
18903
19317
|
const failed = await settleAfterTurnStarted(
|
|
18904
19318
|
admitted,
|
|
@@ -18907,6 +19321,7 @@ async function dispatchPostAdmissionTurn(input) {
|
|
|
18907
19321
|
code: result.code,
|
|
18908
19322
|
stderr: result.stderr,
|
|
18909
19323
|
...resolutionInput,
|
|
19324
|
+
...processCancelName === void 0 ? {} : { knownDiagnostic: processCancelDiagnostic(processCancelName) },
|
|
18910
19325
|
// Secondary fact only — never the cause. Rides on whichever channel
|
|
18911
19326
|
// classification actually reads (knownFailure.details owns it when
|
|
18912
19327
|
// a knownFailure exists; the top-level knownDetails otherwise).
|
|
@@ -18922,7 +19337,12 @@ async function dispatchPostAdmissionTurn(input) {
|
|
|
18922
19337
|
io,
|
|
18923
19338
|
persistRunState
|
|
18924
19339
|
);
|
|
18925
|
-
return await finishAfterTurn(
|
|
19340
|
+
return await finishAfterTurn(
|
|
19341
|
+
withProcessCancelSkipAutoResume(
|
|
19342
|
+
{ ...failed, turnDispatched: true, ...deferredPersist },
|
|
19343
|
+
env.signal
|
|
19344
|
+
)
|
|
19345
|
+
);
|
|
18926
19346
|
}
|
|
18927
19347
|
if (stderrLogWriteFailure !== void 0) {
|
|
18928
19348
|
const failed = await settleAfterTurnStarted(
|
|
@@ -18945,6 +19365,22 @@ async function dispatchPostAdmissionTurn(input) {
|
|
|
18945
19365
|
await settleHostEndedNoReceipt(admitted, env.principalAuthority, courtScope),
|
|
18946
19366
|
courtScope
|
|
18947
19367
|
);
|
|
19368
|
+
const noReceiptCancel = processCancelSignalName(env.signal);
|
|
19369
|
+
if (noReceiptCancel !== void 0) {
|
|
19370
|
+
return await finishAfterTurn(
|
|
19371
|
+
await settleProcessCancelAfterTurn({
|
|
19372
|
+
admitted,
|
|
19373
|
+
cancelName: noReceiptCancel,
|
|
19374
|
+
result,
|
|
19375
|
+
adapters,
|
|
19376
|
+
env,
|
|
19377
|
+
io,
|
|
19378
|
+
persistRunState,
|
|
19379
|
+
deferredPersist,
|
|
19380
|
+
invocationScopeId: request.invocationScopeId
|
|
19381
|
+
})
|
|
19382
|
+
);
|
|
19383
|
+
}
|
|
18948
19384
|
if (persistRunState) {
|
|
18949
19385
|
try {
|
|
18950
19386
|
await persistReturnedRunState(admitted, env.principalAuthority, { lawful: true });
|
|
@@ -18963,7 +19399,12 @@ async function dispatchPostAdmissionTurn(input) {
|
|
|
18963
19399
|
io,
|
|
18964
19400
|
persistRunState
|
|
18965
19401
|
);
|
|
18966
|
-
return await finishAfterTurn(
|
|
19402
|
+
return await finishAfterTurn(
|
|
19403
|
+
withProcessCancelSkipAutoResume(
|
|
19404
|
+
{ ...failed, turnDispatched: true, ...deferredPersist },
|
|
19405
|
+
env.signal
|
|
19406
|
+
)
|
|
19407
|
+
);
|
|
18967
19408
|
}
|
|
18968
19409
|
}
|
|
18969
19410
|
return await finishAfterTurn({
|
|
@@ -19159,6 +19600,7 @@ async function runPostAdmissionSeatResume(input) {
|
|
|
19159
19600
|
io: input.io,
|
|
19160
19601
|
sessionAppender: env.sessionAppender,
|
|
19161
19602
|
autoResumeLimit: env.autoResumeLimit,
|
|
19603
|
+
...env.signal === void 0 ? {} : { signal: env.signal },
|
|
19162
19604
|
buildInitialPayload: () => ({ resumeTurn: false }),
|
|
19163
19605
|
buildResumePayload: () => ({ resumeTurn: true }),
|
|
19164
19606
|
// Same as public manual resume: prior-court sealed acceptance is not a
|
|
@@ -19262,6 +19704,7 @@ async function runPostAdmissionResumable(input) {
|
|
|
19262
19704
|
io,
|
|
19263
19705
|
sessionAppender: env.sessionAppender,
|
|
19264
19706
|
autoResumeLimit: env.autoResumeLimit,
|
|
19707
|
+
...env.signal === void 0 ? {} : { signal: env.signal },
|
|
19265
19708
|
buildInitialPayload: buildScopedInitial,
|
|
19266
19709
|
buildResumePayload: buildScopedResume,
|
|
19267
19710
|
dispatch: async (request, lease, _isFirst, attemptIo) => {
|
|
@@ -19370,6 +19813,7 @@ var init_post_admission = __esm({
|
|
|
19370
19813
|
init_host_transition_prior_native();
|
|
19371
19814
|
init_public_run_credentials();
|
|
19372
19815
|
init_run_lifecycle();
|
|
19816
|
+
init_process_cancel();
|
|
19373
19817
|
init_activation_ledger_topology();
|
|
19374
19818
|
init_settlement();
|
|
19375
19819
|
init_terminal();
|
|
@@ -20630,7 +21074,9 @@ async function runPublicCountersign(argv, env, io, parseCountersignArgv2) {
|
|
|
20630
21074
|
{
|
|
20631
21075
|
instruction: parsed.instruction,
|
|
20632
21076
|
projectRoot: admitted.projectRoot,
|
|
20633
|
-
failureLabel: "unbound summons"
|
|
21077
|
+
failureLabel: "unbound summons",
|
|
21078
|
+
// #969: parent durable ticket is the resume/bind key (ADR 0079).
|
|
21079
|
+
...env.boundTicketNumber === void 0 ? {} : { boundTicketNumber: env.boundTicketNumber }
|
|
20634
21080
|
},
|
|
20635
21081
|
env,
|
|
20636
21082
|
io
|
|
@@ -20682,12 +21128,16 @@ async function runPublicCountersign(argv, env, io, parseCountersignArgv2) {
|
|
|
20682
21128
|
);
|
|
20683
21129
|
}
|
|
20684
21130
|
if (outcome.identity.kind === "ticket") {
|
|
20685
|
-
|
|
20686
|
-
typedTicket = assertedTicket;
|
|
21131
|
+
typedTicket = isSafePositiveTicketNumber(env.boundTicketNumber) ? env.boundTicketNumber : outcome.identity.ticketNumber;
|
|
20687
21132
|
typedCourtTicketNumbers = outcome.identity.courtTicketNumbers;
|
|
21133
|
+
} else if (isSafePositiveTicketNumber(env.boundTicketNumber)) {
|
|
21134
|
+
typedTicket = env.boundTicketNumber;
|
|
21135
|
+
}
|
|
21136
|
+
if (typedTicket !== void 0) {
|
|
21137
|
+
const resumeInstruction = env.reviewReask ?? env.gateReviewInstruction ?? parsed.instruction;
|
|
20688
21138
|
const summons = {
|
|
20689
|
-
instruction:
|
|
20690
|
-
instructionEmpty:
|
|
21139
|
+
instruction: resumeInstruction,
|
|
21140
|
+
instructionEmpty: resumeInstruction.trim() === ""
|
|
20691
21141
|
};
|
|
20692
21142
|
const resumed = await tryResumeSameTicketSeatRun({
|
|
20693
21143
|
home: env.home,
|
|
@@ -20769,7 +21219,9 @@ async function runPublicCountersign(argv, env, io, parseCountersignArgv2) {
|
|
|
20769
21219
|
...env.correlationId === void 0 || env.correlationId.trim() === "" ? {} : { correlationId: env.correlationId },
|
|
20770
21220
|
continuation: {
|
|
20771
21221
|
kind: "initial",
|
|
20772
|
-
|
|
21222
|
+
// #969/#879: gate path first mint carries parent payload as dialogue content;
|
|
21223
|
+
// ordinary public entry keeps package transport prompt.
|
|
21224
|
+
prompt: env.reviewReask ?? env.gateReviewInstruction ?? buildCountersignTransportPrompt(
|
|
20773
21225
|
admitted,
|
|
20774
21226
|
engineSessionMaterialFromOptions({
|
|
20775
21227
|
...pickEngineAxis(env),
|
|
@@ -21911,6 +22363,25 @@ async function summonGateOfficer(options) {
|
|
|
21911
22363
|
...common
|
|
21912
22364
|
});
|
|
21913
22365
|
}
|
|
22366
|
+
if (options.officer === "countersign") {
|
|
22367
|
+
const { runIdFromRunDirectory: runIdFromRunDirectory2 } = await Promise.resolve().then(() => (init_run_terminal_artifacts(), run_terminal_artifacts_exports));
|
|
22368
|
+
const correlationId = runIdFromRunDirectory2(options.sourceRunDirectory);
|
|
22369
|
+
if (correlationId === void 0 || correlationId.trim() === "") {
|
|
22370
|
+
throw new Error(
|
|
22371
|
+
`countersign gate summon requires parent runId from sourceRunDirectory: ${options.sourceRunDirectory}`
|
|
22372
|
+
);
|
|
22373
|
+
}
|
|
22374
|
+
const { readBoardTicketNumber: readBoardTicketNumber2 } = await Promise.resolve().then(() => (init_run_ticket_number(), run_ticket_number_exports));
|
|
22375
|
+
const parentTicket = await readBoardTicketNumber2(options.sourceRunDirectory);
|
|
22376
|
+
const instruction = options.reask ?? gateReviewInstruction ?? "";
|
|
22377
|
+
return summonPublicRole({
|
|
22378
|
+
role: "countersign",
|
|
22379
|
+
argv: ["--project", options.cwd, "--", instruction],
|
|
22380
|
+
...common,
|
|
22381
|
+
correlationId,
|
|
22382
|
+
...parentTicket === void 0 ? {} : { boundTicketNumber: parentTicket }
|
|
22383
|
+
});
|
|
22384
|
+
}
|
|
21914
22385
|
return summonPublicRole({
|
|
21915
22386
|
role: "inspector",
|
|
21916
22387
|
argv: [`\u5377\u5B97\u6307\u9488\uFF1A${options.sourceRunDirectory}`],
|
|
@@ -21935,7 +22406,7 @@ init_engine_detour();
|
|
|
21935
22406
|
import { randomUUID as randomUUID9 } from "node:crypto";
|
|
21936
22407
|
import { appendFile as appendFile3, mkdir as mkdir7, writeFile as writeFile12 } from "node:fs/promises";
|
|
21937
22408
|
import { createServer } from "node:net";
|
|
21938
|
-
import { dirname as
|
|
22409
|
+
import { dirname as dirname21, join as join41 } from "node:path";
|
|
21939
22410
|
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
21940
22411
|
|
|
21941
22412
|
// src/gatekeeper-pass-envelope.ts
|
|
@@ -21955,6 +22426,7 @@ function createDefaultGateOfficerSummon(options) {
|
|
|
21955
22426
|
...options.home === void 0 ? {} : { home: options.home },
|
|
21956
22427
|
...options.packageRoot === void 0 ? {} : { packageRoot: options.packageRoot },
|
|
21957
22428
|
...options.roleTurnHost === void 0 ? {} : { roleTurnHost: options.roleTurnHost },
|
|
22429
|
+
...options.hostAdapters === void 0 ? {} : { hostAdapters: options.hostAdapters },
|
|
21958
22430
|
...options.createRunId === void 0 ? {} : { createRunId: options.createRunId }
|
|
21959
22431
|
});
|
|
21960
22432
|
};
|
|
@@ -22003,9 +22475,15 @@ async function requireGatekeeperPass(options) {
|
|
|
22003
22475
|
options.hostActions.failInfrastructure(error, options.context, options.toolCallId);
|
|
22004
22476
|
}
|
|
22005
22477
|
}
|
|
22006
|
-
if (gatekeeper.status === "pass")
|
|
22478
|
+
if (gatekeeper.status === "pass") {
|
|
22479
|
+
return {
|
|
22480
|
+
officer: projected.officer,
|
|
22481
|
+
receipt: gatekeeper.receipt,
|
|
22482
|
+
...typeof gatekeeper.runId === "string" && gatekeeper.runId.trim() !== "" ? { runId: gatekeeper.runId } : {}
|
|
22483
|
+
};
|
|
22484
|
+
}
|
|
22007
22485
|
if (gatekeeper.status === "needs_reask") {
|
|
22008
|
-
reask =
|
|
22486
|
+
reask = officerConclusionReask(projected.officer);
|
|
22009
22487
|
continue;
|
|
22010
22488
|
}
|
|
22011
22489
|
if (gatekeeper.status === "transport_failure") {
|
|
@@ -22015,6 +22493,9 @@ async function requireGatekeeperPass(options) {
|
|
|
22015
22493
|
});
|
|
22016
22494
|
options.hostActions.failInfrastructure(failure2, options.context, options.toolCallId);
|
|
22017
22495
|
}
|
|
22496
|
+
if (gatekeeper.status === "escalate" && options.subject.kind === "secretariat_verdict") {
|
|
22497
|
+
throw new GatekeeperDecisionError(gatekeeper);
|
|
22498
|
+
}
|
|
22018
22499
|
options.hostActions.bindSubmissionNonPass(options.toolCallId, gatekeeper);
|
|
22019
22500
|
throw new GatekeeperDecisionError(gatekeeper);
|
|
22020
22501
|
}
|
|
@@ -22064,7 +22545,7 @@ init_sitian_facade();
|
|
|
22064
22545
|
init_submission_ledger();
|
|
22065
22546
|
init_collector_ledger();
|
|
22066
22547
|
import { randomUUID as randomUUID8 } from "node:crypto";
|
|
22067
|
-
import { readFileSync as readFileSync6, writeSync as
|
|
22548
|
+
import { readFileSync as readFileSync6, writeSync as writeSync3 } from "node:fs";
|
|
22068
22549
|
import { join as join40 } from "node:path";
|
|
22069
22550
|
import { Value as Value4 } from "typebox/value";
|
|
22070
22551
|
|
|
@@ -22106,16 +22587,7 @@ function namedActivationCause(error) {
|
|
|
22106
22587
|
init_activation_ledger_topology();
|
|
22107
22588
|
|
|
22108
22589
|
// src/activation-ledger.ts
|
|
22109
|
-
init_activation_ledger_topology();
|
|
22110
22590
|
init_activation_ledger_git();
|
|
22111
|
-
import {
|
|
22112
|
-
constants as constants2,
|
|
22113
|
-
closeSync as closeSync2,
|
|
22114
|
-
fstatSync,
|
|
22115
|
-
openSync as openSync2,
|
|
22116
|
-
writeSync
|
|
22117
|
-
} from "node:fs";
|
|
22118
|
-
import { dirname as dirname19, isAbsolute as isAbsolute10, resolve as resolve16 } from "node:path";
|
|
22119
22591
|
|
|
22120
22592
|
// src/activation-ledger-session.ts
|
|
22121
22593
|
init_activation_ledger_topology();
|
|
@@ -22219,129 +22691,11 @@ function durableSessionPointer(sessionManager) {
|
|
|
22219
22691
|
|
|
22220
22692
|
// src/activation-ledger.ts
|
|
22221
22693
|
init_activation_ledger_topology();
|
|
22222
|
-
var ACTIVATION_LEDGER_APPEND_OPEN_FLAGS = constants2.O_APPEND | constants2.O_CREAT | constants2.O_WRONLY | constants2.O_NOFOLLOW;
|
|
22223
|
-
var ACCEPTED_ACTIVATION_EVENT = "accepted-activation";
|
|
22224
|
-
var ACCEPTED_ACTIVATION_FACT_KEYS = Object.freeze([
|
|
22225
|
-
"event",
|
|
22226
|
-
"role",
|
|
22227
|
-
"observedAt",
|
|
22228
|
-
"bookKey",
|
|
22229
|
-
"session",
|
|
22230
|
-
"correlation"
|
|
22231
|
-
]);
|
|
22232
|
-
function correlationIdentityFromEnv(env = process.env) {
|
|
22233
|
-
const raw = env.AK_CORRELATION_ID;
|
|
22234
|
-
if (typeof raw === "string" && raw.trim().length > 0) {
|
|
22235
|
-
return { kind: "caller", id: raw };
|
|
22236
|
-
}
|
|
22237
|
-
return { kind: "absent" };
|
|
22238
|
-
}
|
|
22239
|
-
function projectAcceptedActivationFact(input) {
|
|
22240
|
-
const closed = {
|
|
22241
|
-
event: ACCEPTED_ACTIVATION_EVENT,
|
|
22242
|
-
role: input.role,
|
|
22243
|
-
observedAt: input.observedAt,
|
|
22244
|
-
bookKey: input.bookKey,
|
|
22245
|
-
session: { kind: "session-file", path: input.session.path },
|
|
22246
|
-
correlation: input.correlation.kind === "caller" ? { kind: "caller", id: input.correlation.id } : { kind: "absent" }
|
|
22247
|
-
};
|
|
22248
|
-
return Object.fromEntries(
|
|
22249
|
-
ACCEPTED_ACTIVATION_FACT_KEYS.map((key) => [key, closed[key]])
|
|
22250
|
-
);
|
|
22251
|
-
}
|
|
22252
|
-
function buildAcceptedActivationFact(input) {
|
|
22253
|
-
return projectAcceptedActivationFact(input);
|
|
22254
|
-
}
|
|
22255
|
-
function serializeAcceptedActivationFact(fact) {
|
|
22256
|
-
return `${JSON.stringify(projectAcceptedActivationFact(fact))}
|
|
22257
|
-
`;
|
|
22258
|
-
}
|
|
22259
|
-
function appendActivationLedgerLine(ledgerPath, line2, options) {
|
|
22260
|
-
if (!isAbsolute10(options.ledgerHome)) {
|
|
22261
|
-
throw new ActivationLedgerError(
|
|
22262
|
-
`activation ledger home must be absolute: ${options.ledgerHome}`
|
|
22263
|
-
);
|
|
22264
|
-
}
|
|
22265
|
-
const resolvedLedger = resolve16(ledgerPath);
|
|
22266
|
-
const resolvedHome = resolve16(options.ledgerHome);
|
|
22267
|
-
const parent = dirname19(resolvedLedger);
|
|
22268
|
-
ensureRealDirectoryTree(resolvedHome, parent);
|
|
22269
|
-
assertLedgerFileInsideHome(resolvedLedger, resolvedHome);
|
|
22270
|
-
if (typeof constants2.O_NOFOLLOW !== "number") {
|
|
22271
|
-
throw new ActivationLedgerError(
|
|
22272
|
-
"activation ledger append requires O_NOFOLLOW open-flag support (anti-symlink TOCTOU protection must not be silently dropped); refusing to append"
|
|
22273
|
-
);
|
|
22274
|
-
}
|
|
22275
|
-
const bytes = Buffer.isBuffer(line2) ? line2 : Buffer.from(line2);
|
|
22276
|
-
let ledgerFd;
|
|
22277
|
-
let primaryFailure;
|
|
22278
|
-
try {
|
|
22279
|
-
try {
|
|
22280
|
-
ledgerFd = openSync2(resolvedLedger, ACTIVATION_LEDGER_APPEND_OPEN_FLAGS, 420);
|
|
22281
|
-
} catch (error) {
|
|
22282
|
-
throw new ActivationLedgerError(
|
|
22283
|
-
`activation ledger failed to open ledger file (${resolvedLedger}): ${errorText(error)}`,
|
|
22284
|
-
{ cause: error }
|
|
22285
|
-
);
|
|
22286
|
-
}
|
|
22287
|
-
let opened;
|
|
22288
|
-
try {
|
|
22289
|
-
opened = fstatSync(ledgerFd);
|
|
22290
|
-
} catch (error) {
|
|
22291
|
-
throw new ActivationLedgerError(
|
|
22292
|
-
`activation ledger failed to fstat ledger file (${resolvedLedger}): ${errorText(error)}`,
|
|
22293
|
-
{ cause: error }
|
|
22294
|
-
);
|
|
22295
|
-
}
|
|
22296
|
-
if (!opened.isFile()) {
|
|
22297
|
-
throw new ActivationLedgerError(
|
|
22298
|
-
`activation ledger is not a regular file: ${resolvedLedger}`
|
|
22299
|
-
);
|
|
22300
|
-
}
|
|
22301
|
-
const written = writeSync(ledgerFd, bytes, 0, bytes.length, null);
|
|
22302
|
-
if (written !== bytes.length) {
|
|
22303
|
-
throw new ActivationLedgerError(
|
|
22304
|
-
`activation ledger short write: wrote ${written} of ${bytes.length} bytes to ${resolvedLedger}`
|
|
22305
|
-
);
|
|
22306
|
-
}
|
|
22307
|
-
} catch (error) {
|
|
22308
|
-
primaryFailure = error;
|
|
22309
|
-
}
|
|
22310
|
-
if (ledgerFd !== void 0) {
|
|
22311
|
-
try {
|
|
22312
|
-
closeSync2(ledgerFd);
|
|
22313
|
-
} catch (closeFailure) {
|
|
22314
|
-
if (primaryFailure !== void 0) {
|
|
22315
|
-
throw new AggregateError(
|
|
22316
|
-
[primaryFailure, closeFailure],
|
|
22317
|
-
"activation ledger operation and close failed",
|
|
22318
|
-
{ cause: primaryFailure }
|
|
22319
|
-
);
|
|
22320
|
-
}
|
|
22321
|
-
throw closeFailure;
|
|
22322
|
-
}
|
|
22323
|
-
}
|
|
22324
|
-
if (primaryFailure !== void 0) throw primaryFailure;
|
|
22325
|
-
}
|
|
22326
|
-
function appendAcceptedActivationFact(ledgerPath, fact, options) {
|
|
22327
|
-
appendActivationLedgerLine(
|
|
22328
|
-
ledgerPath,
|
|
22329
|
-
Buffer.from(serializeAcceptedActivationFact(fact), "utf8"),
|
|
22330
|
-
{ ledgerHome: options.ledgerHome }
|
|
22331
|
-
);
|
|
22332
|
-
}
|
|
22333
|
-
function appendAcceptedActivationToBook(options) {
|
|
22334
|
-
appendAcceptedActivationFact(
|
|
22335
|
-
activationWaitingLedgerPath(options.ledgerHome, options.fact.bookKey),
|
|
22336
|
-
options.fact,
|
|
22337
|
-
{ ledgerHome: options.ledgerHome }
|
|
22338
|
-
);
|
|
22339
|
-
}
|
|
22340
22694
|
|
|
22341
22695
|
// src/stderr-jsonl.ts
|
|
22342
|
-
import { writeSync
|
|
22696
|
+
import { writeSync } from "node:fs";
|
|
22343
22697
|
var STDERR_JSONL_WRITE_RETRY_LIMIT = 100;
|
|
22344
|
-
function writeStderrJsonlRecord(record4, write =
|
|
22698
|
+
function writeStderrJsonlRecord(record4, write = writeSync) {
|
|
22345
22699
|
const bytes = Buffer.from(`${JSON.stringify(record4)}
|
|
22346
22700
|
`);
|
|
22347
22701
|
let offset = 0;
|
|
@@ -22361,7 +22715,7 @@ function writeStderrJsonlRecord(record4, write = writeSync2) {
|
|
|
22361
22715
|
}
|
|
22362
22716
|
|
|
22363
22717
|
// src/tool-execution-observation.ts
|
|
22364
|
-
import { writeSync as
|
|
22718
|
+
import { writeSync as writeSync2 } from "node:fs";
|
|
22365
22719
|
import { Type as Type13 } from "typebox";
|
|
22366
22720
|
import { Value as Value2 } from "typebox/value";
|
|
22367
22721
|
var TOOL_EXECUTION_UPDATE_THROTTLE_MS = 3e4;
|
|
@@ -22392,7 +22746,7 @@ function validateToolExecutionObservationRecord(record4) {
|
|
|
22392
22746
|
}
|
|
22393
22747
|
return record4;
|
|
22394
22748
|
}
|
|
22395
|
-
function writeToolExecutionObservationRecord(record4, write =
|
|
22749
|
+
function writeToolExecutionObservationRecord(record4, write = writeSync2) {
|
|
22396
22750
|
writeStderrJsonlRecord(validateToolExecutionObservationRecord(record4), write);
|
|
22397
22751
|
}
|
|
22398
22752
|
function isProducingToolUpdate(partialResult) {
|
|
@@ -22623,15 +22977,15 @@ init_collector_evidence();
|
|
|
22623
22977
|
init_collector_github();
|
|
22624
22978
|
|
|
22625
22979
|
// src/collector-handbook.ts
|
|
22626
|
-
import { readFile as
|
|
22980
|
+
import { readFile as readFile20 } from "node:fs/promises";
|
|
22627
22981
|
import { join as join38, sep as sep6 } from "node:path";
|
|
22628
22982
|
|
|
22629
22983
|
// src/atomic-write.ts
|
|
22630
22984
|
import { randomUUID as randomUUID7 } from "node:crypto";
|
|
22631
22985
|
import { rename as rename3, rm as rm5, writeFile as writeFile11 } from "node:fs/promises";
|
|
22632
|
-
import { dirname as
|
|
22986
|
+
import { dirname as dirname19, join as join37 } from "node:path";
|
|
22633
22987
|
async function writeFileAtomically(destination, contents) {
|
|
22634
|
-
const parent =
|
|
22988
|
+
const parent = dirname19(destination);
|
|
22635
22989
|
const temporary = join37(parent, `.atomic-write-${randomUUID7()}.tmp`);
|
|
22636
22990
|
try {
|
|
22637
22991
|
await writeFile11(temporary, contents);
|
|
@@ -22786,7 +23140,7 @@ function createCollectorHandbookStore(input) {
|
|
|
22786
23140
|
ensureRealDirectoryTree(input.ledgerHome, parentDir2);
|
|
22787
23141
|
assertLedgerFileInsideHome(path, input.ledgerHome);
|
|
22788
23142
|
try {
|
|
22789
|
-
const body = await
|
|
23143
|
+
const body = await readFile20(path, "utf8");
|
|
22790
23144
|
assertHandbookBudget(body, "\u6B63\u6587");
|
|
22791
23145
|
return body;
|
|
22792
23146
|
} catch (error) {
|
|
@@ -23935,7 +24289,7 @@ import { createHash as createHash9 } from "node:crypto";
|
|
|
23935
24289
|
init_navigator_invocation_identity();
|
|
23936
24290
|
init_packaged_role_registry();
|
|
23937
24291
|
init_activation_ledger_topology();
|
|
23938
|
-
import { resolve as
|
|
24292
|
+
import { resolve as resolve16 } from "node:path";
|
|
23939
24293
|
import "@earendil-works/pi-coding-agent";
|
|
23940
24294
|
import { Type as Type22 } from "typebox";
|
|
23941
24295
|
|
|
@@ -24383,7 +24737,7 @@ function navigatorSubjectKey(subjectRoot, subject, provenance = "role_input") {
|
|
|
24383
24737
|
}
|
|
24384
24738
|
function navigatorSubjectKeyForInput(subjectRoot, reference, cwd = process.cwd()) {
|
|
24385
24739
|
if (issueRoot(subjectRoot) !== void 0 || !subjectRoot.includes("/.ak/work/")) return subjectRoot;
|
|
24386
|
-
const resolvedReference =
|
|
24740
|
+
const resolvedReference = resolve16(cwd, reference);
|
|
24387
24741
|
const marker = "/runs/";
|
|
24388
24742
|
if (resolvedReference.includes(marker)) {
|
|
24389
24743
|
return subjectRoot;
|
|
@@ -25085,7 +25439,7 @@ init_submission_errors();
|
|
|
25085
25439
|
init_submission_errors();
|
|
25086
25440
|
import { execFileSync as execFileSync4 } from "node:child_process";
|
|
25087
25441
|
import { existsSync as existsSync12, lstatSync as lstatSync3, readdirSync as readdirSync3, readFileSync as readFileSync5, rmdirSync, rmSync } from "node:fs";
|
|
25088
|
-
import { resolve as
|
|
25442
|
+
import { resolve as resolve17 } from "node:path";
|
|
25089
25443
|
var WORKER_SUBMISSION_GATE_RECORD_KIND = WORKER_SUBMISSION_GATE_KIND;
|
|
25090
25444
|
var WORKER_COMMIT_BASELINE_ENTRY_TYPE = "commit-baseline";
|
|
25091
25445
|
var WORKER_COMMIT_REMINDER_BOUNCE_ENTRY_TYPE = "commit-reminder-bounce";
|
|
@@ -25134,7 +25488,7 @@ function escapeGitConfigValueRegex(value) {
|
|
|
25134
25488
|
function unsetOwnedHooksPath(file) {
|
|
25135
25489
|
const owned = [];
|
|
25136
25490
|
for (const value of tryGetAll(file, "core.hooksPath")) {
|
|
25137
|
-
if (!ownedHook(
|
|
25491
|
+
if (!ownedHook(resolve17(value, HOOK_FILE))) continue;
|
|
25138
25492
|
try {
|
|
25139
25493
|
gitFile(file, [
|
|
25140
25494
|
"--unset-all",
|
|
@@ -25149,15 +25503,15 @@ function unsetOwnedHooksPath(file) {
|
|
|
25149
25503
|
return owned;
|
|
25150
25504
|
}
|
|
25151
25505
|
function rmOwnedDir(dir) {
|
|
25152
|
-
const hookPath =
|
|
25506
|
+
const hookPath = resolve17(dir, HOOK_FILE);
|
|
25153
25507
|
if (!ownedHook(hookPath)) return;
|
|
25154
25508
|
rmSync(hookPath, { force: true });
|
|
25155
25509
|
if (existsSync12(dir) && readdirSync3(dir).length === 0) rmdirSync(dir);
|
|
25156
25510
|
}
|
|
25157
25511
|
function linkedGitDirs(commonDir) {
|
|
25158
|
-
const root =
|
|
25512
|
+
const root = resolve17(commonDir, "worktrees");
|
|
25159
25513
|
if (!existsSync12(root)) return [];
|
|
25160
|
-
return readdirSync3(root).map((name) =>
|
|
25514
|
+
return readdirSync3(root).map((name) => resolve17(root, name)).filter((dir) => lstatSync3(dir).isDirectory());
|
|
25161
25515
|
}
|
|
25162
25516
|
function uninstallPackageWorkerHooks(cwd) {
|
|
25163
25517
|
let inside;
|
|
@@ -25171,17 +25525,17 @@ function uninstallPackageWorkerHooks(cwd) {
|
|
|
25171
25525
|
const clear = (configFile) => {
|
|
25172
25526
|
for (const hooks of unsetOwnedHooksPath(configFile)) rmOwnedDir(hooks);
|
|
25173
25527
|
};
|
|
25174
|
-
clear(
|
|
25175
|
-
clear(
|
|
25176
|
-
rmOwnedDir(
|
|
25177
|
-
const legacy =
|
|
25528
|
+
clear(resolve17(commonDir, "config"));
|
|
25529
|
+
clear(resolve17(commonDir, "config.worktree"));
|
|
25530
|
+
rmOwnedDir(resolve17(commonDir, HOOKS_DIR));
|
|
25531
|
+
const legacy = resolve17(commonDir, "hooks", HOOK_FILE);
|
|
25178
25532
|
if (ownedHook(legacy)) rmSync(legacy, { force: true });
|
|
25179
25533
|
for (const gitDir of linkedGitDirs(commonDir)) {
|
|
25180
|
-
clear(
|
|
25181
|
-
rmOwnedDir(
|
|
25534
|
+
clear(resolve17(gitDir, "config.worktree"));
|
|
25535
|
+
rmOwnedDir(resolve17(gitDir, HOOKS_DIR));
|
|
25182
25536
|
}
|
|
25183
25537
|
}
|
|
25184
|
-
function
|
|
25538
|
+
function isRecord14(value) {
|
|
25185
25539
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
25186
25540
|
}
|
|
25187
25541
|
function unfinishedReasonPresent(details) {
|
|
@@ -25197,7 +25551,7 @@ function readGateState(session) {
|
|
|
25197
25551
|
if (entry.type !== "custom") continue;
|
|
25198
25552
|
if (entry.customType === WORKER_COMMIT_BASELINE_ENTRY_TYPE) {
|
|
25199
25553
|
const data = entry.data;
|
|
25200
|
-
if (
|
|
25554
|
+
if (isRecord14(data) && (data.head === null || typeof data.head === "string")) {
|
|
25201
25555
|
baseline = data.head;
|
|
25202
25556
|
}
|
|
25203
25557
|
} else if (entry.customType === WORKER_COMMIT_REMINDER_BOUNCE_ENTRY_TYPE) {
|
|
@@ -25748,7 +26102,6 @@ ${JSON.stringify(admitted)}
|
|
|
25748
26102
|
// src/role-runtime.ts
|
|
25749
26103
|
init_navigator_invocation_identity();
|
|
25750
26104
|
init_gatekeeper_role();
|
|
25751
|
-
init_gatekeeper_role();
|
|
25752
26105
|
init_submission_errors();
|
|
25753
26106
|
init_doctor_contracts();
|
|
25754
26107
|
init_doctor_evidence();
|
|
@@ -25931,7 +26284,7 @@ async function executeActivationStage(role, stage, infrastructure) {
|
|
|
25931
26284
|
throw activationError;
|
|
25932
26285
|
}
|
|
25933
26286
|
}
|
|
25934
|
-
function writeActivationTraceRecord(record4, write =
|
|
26287
|
+
function writeActivationTraceRecord(record4, write = writeSync3) {
|
|
25935
26288
|
writeStderrJsonlRecord(record4, write);
|
|
25936
26289
|
}
|
|
25937
26290
|
var ActivationBarrierError = class extends Error {
|
|
@@ -26231,15 +26584,80 @@ ${error.message}`
|
|
|
26231
26584
|
}
|
|
26232
26585
|
var COUNTERSIGN_QUEUE_STATUSES = /* @__PURE__ */ new Set(["converged", "continue", "escalate"]);
|
|
26233
26586
|
var COUNTERSIGN_STATUS_REASK = "countersignStatus \u4E0D\u662F converged\u3001continue\u3001escalate \u4E09\u6001\u4E4B\u4E00\u3002\u8BF7\u91CD\u65B0\u4EA4\u5377\uFF0Cstatus \u5199\u660E\u5176\u4E00\u3002";
|
|
26234
|
-
|
|
26587
|
+
var SECRETARIAT_SUBMISSION_GATE_HOSTS = /* @__PURE__ */ new Set(["codex", "claude", "grok-build"]);
|
|
26588
|
+
var SECRETARIAT_QUEUE_STATUSES = /* @__PURE__ */ new Set(["converged", "escalate"]);
|
|
26589
|
+
var SECRETARIAT_STATUS_REASK = "secretariatStatus \u4E0D\u662F converged\u3001escalate \u4E4B\u4E00\u3002\u8BF7\u91CD\u65B0\u4EA4\u5377\uFF0Cstatus \u5199\u660E\u5176\u4E00\u3002";
|
|
26590
|
+
function createSecretariatRoleRuntime(roleHost, dependencies, hostActions) {
|
|
26235
26591
|
let parentInstruction = "";
|
|
26592
|
+
const beforeAccept = hostActions !== void 0 && roleHost.requireGatekeeperPass !== void 0 ? async ({ toolCallId, parameters, signal, ctx }) => {
|
|
26593
|
+
const host = typeof ctx.host === "string" && ctx.host.trim() !== "" ? ctx.host.trim() : void 0;
|
|
26594
|
+
if (host === void 0 || !SECRETARIAT_SUBMISSION_GATE_HOSTS.has(host)) {
|
|
26595
|
+
return void 0;
|
|
26596
|
+
}
|
|
26597
|
+
const record4 = parameters !== null && typeof parameters === "object" && !Array.isArray(parameters) ? parameters : void 0;
|
|
26598
|
+
const status = record4 !== void 0 && typeof record4.secretariatStatus === "string" ? record4.secretariatStatus : void 0;
|
|
26599
|
+
if (status === void 0 || !SECRETARIAT_QUEUE_STATUSES.has(status)) {
|
|
26600
|
+
throw new ParentQueueReaskError(SECRETARIAT_STATUS_REASK);
|
|
26601
|
+
}
|
|
26602
|
+
if (status === "escalate") {
|
|
26603
|
+
return void 0;
|
|
26604
|
+
}
|
|
26605
|
+
try {
|
|
26606
|
+
const pass = await roleHost.requireGatekeeperPass({
|
|
26607
|
+
context: ctx,
|
|
26608
|
+
subject: { kind: "secretariat_verdict" },
|
|
26609
|
+
...signal === void 0 ? {} : { signal },
|
|
26610
|
+
hostActions,
|
|
26611
|
+
toolCallId,
|
|
26612
|
+
// #879: this-turn typed payload — identity-bound at submit site.
|
|
26613
|
+
submission: parameters
|
|
26614
|
+
});
|
|
26615
|
+
if (pass !== void 0 && pass !== null && typeof pass === "object" && "receipt" in pass) {
|
|
26616
|
+
const {
|
|
26617
|
+
SECRETARIAT_GATE_OFFICER_ENTRY_TYPE: SECRETARIAT_GATE_OFFICER_ENTRY_TYPE2
|
|
26618
|
+
} = await Promise.resolve().then(() => (init_secretariat_contracts(), secretariat_contracts_exports));
|
|
26619
|
+
const runId = typeof pass.runId === "string" && pass.runId.trim() !== "" ? pass.runId : void 0;
|
|
26620
|
+
ctx.sessionManager.appendCustomEntry?.(SECRETARIAT_GATE_OFFICER_ENTRY_TYPE2, {
|
|
26621
|
+
officer: "countersign",
|
|
26622
|
+
receipt: pass.receipt,
|
|
26623
|
+
...runId === void 0 ? {} : { runId }
|
|
26624
|
+
});
|
|
26625
|
+
}
|
|
26626
|
+
return void 0;
|
|
26627
|
+
} catch (error) {
|
|
26628
|
+
if (error instanceof GatekeeperDecisionError && error.result.status === "escalate") {
|
|
26629
|
+
const receipt = error.result.receipt;
|
|
26630
|
+
const receiptRecord = receipt !== null && typeof receipt === "object" && !Array.isArray(receipt) ? receipt : void 0;
|
|
26631
|
+
const runId = typeof error.result.runId === "string" && error.result.runId.trim() !== "" ? error.result.runId : void 0;
|
|
26632
|
+
const {
|
|
26633
|
+
SECRETARIAT_GATE_OFFICER_ENTRY_TYPE: SECRETARIAT_GATE_OFFICER_ENTRY_TYPE2
|
|
26634
|
+
} = await Promise.resolve().then(() => (init_secretariat_contracts(), secretariat_contracts_exports));
|
|
26635
|
+
ctx.sessionManager.appendCustomEntry?.(SECRETARIAT_GATE_OFFICER_ENTRY_TYPE2, {
|
|
26636
|
+
officer: "countersign",
|
|
26637
|
+
receipt,
|
|
26638
|
+
...runId === void 0 ? {} : { runId }
|
|
26639
|
+
});
|
|
26640
|
+
const { buildAuditEscalationResult: buildAuditEscalationResult2 } = await Promise.resolve().then(() => (init_audit_escalation(), audit_escalation_exports));
|
|
26641
|
+
return buildAuditEscalationResult2(
|
|
26642
|
+
{
|
|
26643
|
+
status: "escalate",
|
|
26644
|
+
officer: "countersign",
|
|
26645
|
+
...receiptRecord !== void 0 && Object.prototype.hasOwnProperty.call(receiptRecord, "decisionGate") ? { decisionGate: receiptRecord.decisionGate } : {}
|
|
26646
|
+
},
|
|
26647
|
+
receipt
|
|
26648
|
+
);
|
|
26649
|
+
}
|
|
26650
|
+
throw error;
|
|
26651
|
+
}
|
|
26652
|
+
} : void 0;
|
|
26236
26653
|
const base = createFiledOfficerRuntime(
|
|
26237
26654
|
roleHost,
|
|
26238
26655
|
{
|
|
26239
26656
|
role: "secretariat",
|
|
26240
26657
|
tool: SECRETARIAT_OUTPUT_TOOL_SPEC,
|
|
26241
26658
|
acceptedText: SECRETARIAT_ACCEPTED_TEXT,
|
|
26242
|
-
soulTag: "secretariat"
|
|
26659
|
+
soulTag: "secretariat",
|
|
26660
|
+
...beforeAccept === void 0 ? {} : { beforeAccept }
|
|
26243
26661
|
},
|
|
26244
26662
|
dependencies
|
|
26245
26663
|
);
|
|
@@ -26921,8 +27339,9 @@ function createRoleRuntimeExtension(dependencies) {
|
|
|
26921
27339
|
if (!dependencies.loadSecretariatSoul) throw new Error("Secretariat runtime dependencies are not configured");
|
|
26922
27340
|
return dependencies.loadSecretariatSoul();
|
|
26923
27341
|
},
|
|
26924
|
-
...dependencies.packageRoot === void 0 ? {} : { packageRoot: dependencies.packageRoot }
|
|
26925
|
-
|
|
27342
|
+
...dependencies.packageRoot === void 0 ? {} : { packageRoot: dependencies.packageRoot },
|
|
27343
|
+
...dependencies.hostAdapters === void 0 ? {} : { hostAdapters: dependencies.hostAdapters }
|
|
27344
|
+
}, hostActions);
|
|
26926
27345
|
const merger = createMergerRoleRuntime(roleHost, {
|
|
26927
27346
|
async loadSoul() {
|
|
26928
27347
|
if (!dependencies.loadMergerSoul) throw new Error("Merger runtime dependencies are not configured");
|
|
@@ -27163,11 +27582,8 @@ function createRoleRuntimeExtension(dependencies) {
|
|
|
27163
27582
|
}
|
|
27164
27583
|
};
|
|
27165
27584
|
try {
|
|
27166
|
-
|
|
27167
|
-
|
|
27168
|
-
const sessionFile = ctx.sessionManager.getSessionFile?.() || ctx.sessionManager.getSessionDir?.();
|
|
27169
|
-
const ledgerHome = resolveActivationLedgerHomeForPath(sessionFile);
|
|
27170
|
-
const session = durableSessionPointer(ctx.sessionManager);
|
|
27585
|
+
resolveBookKeyFromGit(ctx.cwd);
|
|
27586
|
+
durableSessionPointer(ctx.sessionManager);
|
|
27171
27587
|
const isStationChild = roleHost.getFlag(STATION_CHILD_FLAG.name) === true;
|
|
27172
27588
|
if (dependencies.createNavigatorAttendance !== void 0 && entry.role !== "navigator" && !isStationChild) {
|
|
27173
27589
|
navigatorSessionParent = ctx.sessionManager.getSessionFile();
|
|
@@ -27254,16 +27670,6 @@ function createRoleRuntimeExtension(dependencies) {
|
|
|
27254
27670
|
if (entry.role === "coder") coder.armSubmissionGate(ctx.cwd, ctx.sessionManager);
|
|
27255
27671
|
else fixer.armSubmissionGate(ctx.cwd, ctx.sessionManager);
|
|
27256
27672
|
}
|
|
27257
|
-
appendAcceptedActivationToBook({
|
|
27258
|
-
ledgerHome,
|
|
27259
|
-
fact: buildAcceptedActivationFact({
|
|
27260
|
-
role: entry.role,
|
|
27261
|
-
observedAt: clock(),
|
|
27262
|
-
bookKey,
|
|
27263
|
-
session,
|
|
27264
|
-
correlation
|
|
27265
|
-
})
|
|
27266
|
-
});
|
|
27267
27673
|
admitted = true;
|
|
27268
27674
|
} catch (error) {
|
|
27269
27675
|
failInfrastructure(error, ctx);
|
|
@@ -27277,11 +27683,11 @@ init_role_activation_flags();
|
|
|
27277
27683
|
init_submission_correctable_error();
|
|
27278
27684
|
init_navigator_invocation_identity();
|
|
27279
27685
|
async function listen(server, path) {
|
|
27280
|
-
await new Promise((
|
|
27686
|
+
await new Promise((resolve21, reject) => {
|
|
27281
27687
|
server.once("error", reject);
|
|
27282
27688
|
server.listen(path, () => {
|
|
27283
27689
|
server.off("error", reject);
|
|
27284
|
-
|
|
27690
|
+
resolve21();
|
|
27285
27691
|
});
|
|
27286
27692
|
});
|
|
27287
27693
|
}
|
|
@@ -27317,7 +27723,7 @@ async function prepareRoleEnvelope(options) {
|
|
|
27317
27723
|
const runId = request.runDirectory.split("/").filter(Boolean).at(-1) ?? randomUUID9();
|
|
27318
27724
|
await mkdir7(request.runDirectory, { recursive: true });
|
|
27319
27725
|
let sessionFile = options.sessionFile ?? join41(request.runDirectory, "session", "session.jsonl");
|
|
27320
|
-
await mkdir7(
|
|
27726
|
+
await mkdir7(dirname21(sessionFile), { recursive: true });
|
|
27321
27727
|
if (request.continuation.kind !== "resume") {
|
|
27322
27728
|
try {
|
|
27323
27729
|
await writeFile12(
|
|
@@ -27367,7 +27773,7 @@ async function prepareRoleEnvelope(options) {
|
|
|
27367
27773
|
getLeafEntry: () => sessionEntries.at(-1),
|
|
27368
27774
|
getLeafId: () => runId,
|
|
27369
27775
|
getEntries: () => sessionEntries,
|
|
27370
|
-
getSessionDir: () =>
|
|
27776
|
+
getSessionDir: () => dirname21(sessionFile),
|
|
27371
27777
|
getSessionFile: () => sessionFile,
|
|
27372
27778
|
getHeader: () => ({ type: "session", id: runId }),
|
|
27373
27779
|
setSessionFile(path) {
|
|
@@ -27431,17 +27837,26 @@ async function prepareRoleEnvelope(options) {
|
|
|
27431
27837
|
getActiveTools() {
|
|
27432
27838
|
return [...preferredTools];
|
|
27433
27839
|
},
|
|
27434
|
-
async requireGatekeeperPass(
|
|
27435
|
-
|
|
27436
|
-
|
|
27437
|
-
|
|
27438
|
-
|
|
27840
|
+
async requireGatekeeperPass(gateOptions) {
|
|
27841
|
+
const packageRoot = typeof options.dependencies.packageRoot === "string" ? options.dependencies.packageRoot : void 0;
|
|
27842
|
+
return requireGatekeeperPass({
|
|
27843
|
+
context: gateOptions.context,
|
|
27844
|
+
subject: gateOptions.subject,
|
|
27845
|
+
...gateOptions.signal === void 0 ? {} : { signal: gateOptions.signal },
|
|
27439
27846
|
hostActions: {
|
|
27440
|
-
failInfrastructure: (error, _context, toolCallId) =>
|
|
27441
|
-
bindSubmissionNonPass:
|
|
27847
|
+
failInfrastructure: (error, _context, toolCallId) => gateOptions.hostActions.failInfrastructure(error, gateOptions.context, toolCallId),
|
|
27848
|
+
bindSubmissionNonPass: gateOptions.hostActions.bindSubmissionNonPass
|
|
27442
27849
|
},
|
|
27443
|
-
toolCallId:
|
|
27444
|
-
...
|
|
27850
|
+
toolCallId: gateOptions.toolCallId,
|
|
27851
|
+
...gateOptions.submission === void 0 ? {} : { submission: gateOptions.submission },
|
|
27852
|
+
// #969: package root + home reach nested 给事中/符宝郎 summons.
|
|
27853
|
+
// hostAdapters (when set on deps) forward nested seat selection — production unset.
|
|
27854
|
+
summonOfficer: createDefaultGateOfficerSummon({
|
|
27855
|
+
cwd: gateOptions.context.cwd ?? request.cwd,
|
|
27856
|
+
home: request.home,
|
|
27857
|
+
...packageRoot === void 0 ? {} : { packageRoot },
|
|
27858
|
+
...options.dependencies.hostAdapters === void 0 ? {} : { hostAdapters: options.dependencies.hostAdapters }
|
|
27859
|
+
})
|
|
27445
27860
|
});
|
|
27446
27861
|
},
|
|
27447
27862
|
on(...registration) {
|
|
@@ -27714,8 +28129,8 @@ async function prepareRoleEnvelope(options) {
|
|
|
27714
28129
|
try {
|
|
27715
28130
|
const closeAll = server.closeAllConnections;
|
|
27716
28131
|
if (typeof closeAll === "function") closeAll.call(server);
|
|
27717
|
-
await new Promise((
|
|
27718
|
-
server.close((error) => error ? reject(error) :
|
|
28132
|
+
await new Promise((resolve21, reject) => {
|
|
28133
|
+
server.close((error) => error ? reject(error) : resolve21());
|
|
27719
28134
|
});
|
|
27720
28135
|
} catch (error) {
|
|
27721
28136
|
cleanupFailures.push(error);
|
|
@@ -27851,18 +28266,18 @@ async function prepareRoleEnvelope(options) {
|
|
|
27851
28266
|
}
|
|
27852
28267
|
|
|
27853
28268
|
// src/role-runtime-dependencies.ts
|
|
27854
|
-
import { readFile as
|
|
28269
|
+
import { readFile as readFile23 } from "node:fs/promises";
|
|
27855
28270
|
import { join as join42 } from "node:path";
|
|
27856
28271
|
|
|
27857
28272
|
// src/canonical-skill-binding.ts
|
|
27858
|
-
import { readFile as
|
|
28273
|
+
import { readFile as readFile21, realpath as realpath8 } from "node:fs/promises";
|
|
27859
28274
|
import { homedir } from "node:os";
|
|
27860
|
-
import { dirname as
|
|
28275
|
+
import { dirname as dirname22, resolve as resolve18 } from "node:path";
|
|
27861
28276
|
import { stripFrontmatter } from "@earendil-works/pi-coding-agent";
|
|
27862
28277
|
function captureCanonicalSkillExpansion(name, snapshot, configuredPath, evidence, originalRequest) {
|
|
27863
28278
|
const matchedPath = evidence?.location === configuredPath ? configuredPath : evidence?.location === snapshot.path ? snapshot.path : void 0;
|
|
27864
28279
|
const expectedContent = matchedPath === void 0 ? void 0 : snapshot.body;
|
|
27865
|
-
const prefixedContent = matchedPath === void 0 ? void 0 : `References are relative to ${
|
|
28280
|
+
const prefixedContent = matchedPath === void 0 ? void 0 : `References are relative to ${dirname22(matchedPath)}.
|
|
27866
28281
|
|
|
27867
28282
|
${snapshot.body}`;
|
|
27868
28283
|
if (evidence?.name !== name || matchedPath === void 0 || evidence.content !== expectedContent && evidence.content !== prefixedContent || evidence.userMessage !== originalRequest) {
|
|
@@ -27880,7 +28295,7 @@ var CanonicalSkillUnavailableError = class extends Error {
|
|
|
27880
28295
|
code = "canonical-skill-unavailable";
|
|
27881
28296
|
};
|
|
27882
28297
|
async function loadCanonicalSkillBinding(name) {
|
|
27883
|
-
const configuredPath =
|
|
28298
|
+
const configuredPath = resolve18(
|
|
27884
28299
|
homedir(),
|
|
27885
28300
|
`.agents/skills/${name}/SKILL.md`
|
|
27886
28301
|
);
|
|
@@ -27888,7 +28303,7 @@ async function loadCanonicalSkillBinding(name) {
|
|
|
27888
28303
|
let raw;
|
|
27889
28304
|
try {
|
|
27890
28305
|
path = await realpath8(configuredPath);
|
|
27891
|
-
raw = await
|
|
28306
|
+
raw = await readFile21(path, "utf8");
|
|
27892
28307
|
} catch (error) {
|
|
27893
28308
|
throw new CanonicalSkillUnavailableError(name, configuredPath, error);
|
|
27894
28309
|
}
|
|
@@ -27899,7 +28314,7 @@ async function loadCanonicalSkillBinding(name) {
|
|
|
27899
28314
|
const snapshot = Object.freeze({
|
|
27900
28315
|
raw,
|
|
27901
28316
|
path,
|
|
27902
|
-
baseDir:
|
|
28317
|
+
baseDir: dirname22(path),
|
|
27903
28318
|
body,
|
|
27904
28319
|
snapshotIdentity: Object.freeze({ text: raw })
|
|
27905
28320
|
});
|
|
@@ -27927,8 +28342,8 @@ init_doctor_evidence();
|
|
|
27927
28342
|
// src/navigator-work-context.ts
|
|
27928
28343
|
init_doctor_evidence();
|
|
27929
28344
|
init_host_contracts();
|
|
27930
|
-
import { readFile as
|
|
27931
|
-
import { resolve as
|
|
28345
|
+
import { readFile as readFile22 } from "node:fs/promises";
|
|
28346
|
+
import { resolve as resolve19 } from "node:path";
|
|
27932
28347
|
init_notary_source_run();
|
|
27933
28348
|
init_packaged_role_registry();
|
|
27934
28349
|
init_invocation();
|
|
@@ -27936,11 +28351,11 @@ function navigatorInputReference(getFlag, role) {
|
|
|
27936
28351
|
if (getFlag === void 0) return void 0;
|
|
27937
28352
|
const name = packagedRoleInputFlag(role);
|
|
27938
28353
|
const value = name === void 0 ? void 0 : getFlag(name);
|
|
27939
|
-
return typeof value === "string" && value !== "" ?
|
|
28354
|
+
return typeof value === "string" && value !== "" ? resolve19(value) : void 0;
|
|
27940
28355
|
}
|
|
27941
28356
|
async function loadNavigatorWorkContext(options) {
|
|
27942
28357
|
const reference = navigatorInputReference(options.getFlag, options.role);
|
|
27943
|
-
const input = reference === void 0 || options.role === "doctor" || options.role === "notary" ? void 0 : await
|
|
28358
|
+
const input = reference === void 0 || options.role === "doctor" || options.role === "notary" ? void 0 : await readFile22(reference, "utf8");
|
|
27944
28359
|
const subjectRoot = subjectPath(reference ?? options.context.sessionManager.getSessionDir(), options.context.cwd);
|
|
27945
28360
|
let subjectKey = reference === void 0 ? subjectRoot : navigatorSubjectKeyForInput(subjectRoot, reference, options.context.cwd);
|
|
27946
28361
|
let subject = input ?? `work subject: ${subjectKey}`;
|
|
@@ -27957,7 +28372,7 @@ async function loadNavigatorWorkContext(options) {
|
|
|
27957
28372
|
}
|
|
27958
28373
|
const publicRunDir = runDirectoryFromHostContext(options.context);
|
|
27959
28374
|
const currentSessionDir = options.context.sessionManager.getSessionDir();
|
|
27960
|
-
const isBoundPublicRun = publicRunDir !== void 0 &&
|
|
28375
|
+
const isBoundPublicRun = publicRunDir !== void 0 && resolve19(currentSessionDir) === resolve19(publicRunDir, "session");
|
|
27961
28376
|
if (options.role === "judge" && isBoundPublicRun) {
|
|
27962
28377
|
let admitted;
|
|
27963
28378
|
try {
|
|
@@ -27990,14 +28405,14 @@ async function loadNavigatorWorkContext(options) {
|
|
|
27990
28405
|
}
|
|
27991
28406
|
const workRoot = subjectRoot.includes("/.ak/work/") ? subjectRoot : void 0;
|
|
27992
28407
|
const authorityFiles = workRoot === void 0 ? [] : [
|
|
27993
|
-
|
|
27994
|
-
|
|
27995
|
-
|
|
28408
|
+
resolve19(workRoot, "authority.md"),
|
|
28409
|
+
resolve19(workRoot, "authority.txt"),
|
|
28410
|
+
resolve19(workRoot, "design-v2/owner-direction.md")
|
|
27996
28411
|
];
|
|
27997
28412
|
let authorityMaterial;
|
|
27998
28413
|
for (const path of authorityFiles) {
|
|
27999
28414
|
try {
|
|
28000
|
-
const content = await
|
|
28415
|
+
const content = await readFile22(path, "utf8");
|
|
28001
28416
|
if (content.trim() !== "") {
|
|
28002
28417
|
authorityMaterial = content;
|
|
28003
28418
|
break;
|
|
@@ -28022,7 +28437,7 @@ async function loadNavigatorWorkContext(options) {
|
|
|
28022
28437
|
init_notary_source_run();
|
|
28023
28438
|
|
|
28024
28439
|
// src/package-resources/method-skill-binding.ts
|
|
28025
|
-
import { dirname as
|
|
28440
|
+
import { dirname as dirname23 } from "node:path";
|
|
28026
28441
|
init_method_skill();
|
|
28027
28442
|
async function loadPackagedCanonicalSkillBinding(packageRoot, name) {
|
|
28028
28443
|
const material = await loadPackagedMethodSkillMaterial(packageRoot, name);
|
|
@@ -28030,7 +28445,7 @@ async function loadPackagedCanonicalSkillBinding(packageRoot, name) {
|
|
|
28030
28445
|
const snapshot = Object.freeze({
|
|
28031
28446
|
raw: material.raw,
|
|
28032
28447
|
path: material.skillPath,
|
|
28033
|
-
baseDir:
|
|
28448
|
+
baseDir: dirname23(material.skillPath),
|
|
28034
28449
|
body: material.body,
|
|
28035
28450
|
snapshotIdentity: Object.freeze({ text: material.raw })
|
|
28036
28451
|
});
|
|
@@ -28066,12 +28481,12 @@ function createRoleRuntimeDependencies(packageRoot) {
|
|
|
28066
28481
|
loadRoleReferenceMaterials: loadPackagedRoleReferenceMaterials,
|
|
28067
28482
|
loadJudgeSoul: () => loadMainRoleSessionMaterials("judge"),
|
|
28068
28483
|
loadFixerSoul: () => loadMainRoleSessionMaterials("fixer"),
|
|
28069
|
-
loadFixPacket: (path) =>
|
|
28484
|
+
loadFixPacket: (path) => readFile23(path, "utf8"),
|
|
28070
28485
|
loadCoderSoul: () => loadMainRoleSessionMaterials("coder"),
|
|
28071
|
-
loadCoderTask: (path) =>
|
|
28486
|
+
loadCoderTask: (path) => readFile23(path, "utf8"),
|
|
28072
28487
|
loadReviewerSoul: () => loadMainRoleSessionMaterials("reviewer"),
|
|
28073
28488
|
loadCollectorSoul: () => loadMainRoleSessionMaterials("collector"),
|
|
28074
|
-
loadCollectorHandbookSeed: () =>
|
|
28489
|
+
loadCollectorHandbookSeed: () => readFile23(collectorHandbookSeedPath, "utf8"),
|
|
28075
28490
|
createCollectorTransport: () => createGhCollectorGitHubTransport(),
|
|
28076
28491
|
loadDoctorSoul: () => loadMainRoleSessionMaterials("doctor"),
|
|
28077
28492
|
loadDoctorCase,
|
|
@@ -28086,7 +28501,7 @@ function createRoleRuntimeDependencies(packageRoot) {
|
|
|
28086
28501
|
loadSecretariatSoul: () => loadMainRoleSessionMaterials("secretariat"),
|
|
28087
28502
|
loadNotarySourceRun: loadNotarySourceRunLocator,
|
|
28088
28503
|
loadMergerSoul: () => loadMainRoleSessionMaterials("merger"),
|
|
28089
|
-
loadMergerInput: async (path) => JSON.parse(await
|
|
28504
|
+
loadMergerInput: async (path) => JSON.parse(await readFile23(path, "utf8")),
|
|
28090
28505
|
async loadCanonicalSkillBinding(name) {
|
|
28091
28506
|
if (name === "tdd") {
|
|
28092
28507
|
return loadPackagedCanonicalSkillBinding(packageRoot, "tdd");
|
|
@@ -28112,7 +28527,7 @@ function createRoleRuntimeDependencies(packageRoot) {
|
|
|
28112
28527
|
authority: options.authority,
|
|
28113
28528
|
invocationId: options.invocationId,
|
|
28114
28529
|
loadSoul: () => loadMainRoleSessionMaterials("navigator"),
|
|
28115
|
-
loadRoutePlaybook: () =>
|
|
28530
|
+
loadRoutePlaybook: () => readFile23(navigatorRoutePlaybookPath, "utf8"),
|
|
28116
28531
|
loadRoleHelp: async (role) => formatNavigatorRoleHelp(role),
|
|
28117
28532
|
createSession: navigatorSessionFactory,
|
|
28118
28533
|
...options.contextError === void 0 ? {} : { contextError: options.contextError },
|
|
@@ -28176,7 +28591,7 @@ function hostAbortedError(message = "host aborted") {
|
|
|
28176
28591
|
function raceAgainstHostAbort(work, abortSignal, message = "host aborted") {
|
|
28177
28592
|
if (abortSignal?.aborted) return Promise.reject(hostAbortedError(message));
|
|
28178
28593
|
if (abortSignal === void 0) return work;
|
|
28179
|
-
return new Promise((
|
|
28594
|
+
return new Promise((resolve21, reject) => {
|
|
28180
28595
|
let settled = false;
|
|
28181
28596
|
const onAbort = () => {
|
|
28182
28597
|
if (settled) return;
|
|
@@ -28191,7 +28606,7 @@ function raceAgainstHostAbort(work, abortSignal, message = "host aborted") {
|
|
|
28191
28606
|
if (settled) return;
|
|
28192
28607
|
settled = true;
|
|
28193
28608
|
abortSignal.removeEventListener("abort", onAbort);
|
|
28194
|
-
|
|
28609
|
+
resolve21(value);
|
|
28195
28610
|
},
|
|
28196
28611
|
(error) => {
|
|
28197
28612
|
if (settled) return;
|
|
@@ -28431,8 +28846,8 @@ function connectAcpStdio(options) {
|
|
|
28431
28846
|
request(method, params) {
|
|
28432
28847
|
if (closed) return Promise.reject(terminalError ?? acpError("acp-connection-closed", "ACP connection is closed"));
|
|
28433
28848
|
const id = ++nextId;
|
|
28434
|
-
return new Promise((
|
|
28435
|
-
pending.set(id, { resolve:
|
|
28849
|
+
return new Promise((resolve21, reject) => {
|
|
28850
|
+
pending.set(id, { resolve: resolve21, reject });
|
|
28436
28851
|
child.stdin.write(`${JSON.stringify({ jsonrpc: "2.0", id, method, params })}
|
|
28437
28852
|
`, (error) => {
|
|
28438
28853
|
if (error === null || error === void 0) return;
|
|
@@ -28459,7 +28874,7 @@ function connectAcpStdio(options) {
|
|
|
28459
28874
|
settleClosed(acpError("acp-connection-closed", "ACP connection is closed"));
|
|
28460
28875
|
child.stdin.end();
|
|
28461
28876
|
child.kill("SIGTERM");
|
|
28462
|
-
await new Promise((
|
|
28877
|
+
await new Promise((resolve21) => child.once("close", () => resolve21()));
|
|
28463
28878
|
}
|
|
28464
28879
|
});
|
|
28465
28880
|
}
|
|
@@ -28657,9 +29072,9 @@ function createAcpRoleTurnHost(config) {
|
|
|
28657
29072
|
}
|
|
28658
29073
|
|
|
28659
29074
|
// src/acp-host/seat-profile-soul.ts
|
|
28660
|
-
import { constants as
|
|
29075
|
+
import { constants as constants2 } from "node:fs";
|
|
28661
29076
|
import { access as access4, copyFile, lstat as lstat8, mkdir as mkdir8, readlink as readlink2, symlink as symlink2, unlink as unlink3 } from "node:fs/promises";
|
|
28662
|
-
import { dirname as
|
|
29077
|
+
import { dirname as dirname24, join as join44, relative as relative4, resolve as resolve20 } from "node:path";
|
|
28663
29078
|
function seatProfileName(spec, role) {
|
|
28664
29079
|
return `${spec.namePrefix}${role}`;
|
|
28665
29080
|
}
|
|
@@ -28668,7 +29083,7 @@ function packageRoleSoulPath(packageRoot, role) {
|
|
|
28668
29083
|
}
|
|
28669
29084
|
async function pathExists2(path) {
|
|
28670
29085
|
try {
|
|
28671
|
-
await access4(path,
|
|
29086
|
+
await access4(path, constants2.F_OK);
|
|
28672
29087
|
return true;
|
|
28673
29088
|
} catch {
|
|
28674
29089
|
return false;
|
|
@@ -28677,13 +29092,13 @@ async function pathExists2(path) {
|
|
|
28677
29092
|
async function ensureSeatProfileSoul(options) {
|
|
28678
29093
|
const { spec, operatorHome, packageRoot, role } = options;
|
|
28679
29094
|
const profileName = seatProfileName(spec, role);
|
|
28680
|
-
const soulTarget =
|
|
29095
|
+
const soulTarget = resolve20(packageRoleSoulPath(packageRoot, role));
|
|
28681
29096
|
if (!await pathExists2(soulTarget)) {
|
|
28682
29097
|
throw new Error(`packaged role soul missing: ${soulTarget}`);
|
|
28683
29098
|
}
|
|
28684
29099
|
const profilesRoot = join44(operatorHome, ...spec.profilesRootFromHome);
|
|
28685
29100
|
const profileDir = join44(profilesRoot, profileName);
|
|
28686
|
-
const hostRoot =
|
|
29101
|
+
const hostRoot = dirname24(profilesRoot);
|
|
28687
29102
|
const soulPath = join44(profileDir, spec.soulFileName);
|
|
28688
29103
|
if (!await pathExists2(profileDir)) {
|
|
28689
29104
|
await mkdir8(profileDir, { recursive: true });
|