@akagilnc/pi-workflow-roles 0.1.4631 → 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/dist/acp-host/production-host.js +731 -329
- package/dist/gatekeeper-role.js +76 -6
- package/dist/headless-host/production-host.js +708 -306
- package/dist/migrate-book-topology.js +9 -0
- package/dist/public-cli/countersign-run.js +31 -10
- package/dist/public-cli/main.js +401 -287
- 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/src/archivist-record-entry.ts +2 -2
- 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/public-cli/countersign-run.ts +50 -13
- 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 +142 -4
- package/src/secretariat-contracts.ts +18 -0
|
@@ -964,6 +964,15 @@ var init_activation_ledger_topology = __esm({
|
|
|
964
964
|
});
|
|
965
965
|
|
|
966
966
|
// src/run-ticket-number.ts
|
|
967
|
+
var run_ticket_number_exports = {};
|
|
968
|
+
__export(run_ticket_number_exports, {
|
|
969
|
+
MIGRATION_TICKET_DERIVATION_PAGE: () => MIGRATION_TICKET_DERIVATION_PAGE,
|
|
970
|
+
isSafePositiveTicketNumber: () => isSafePositiveTicketNumber,
|
|
971
|
+
readBoardTicketNumber: () => readBoardTicketNumber,
|
|
972
|
+
readMigrationDerivedTicketNumber: () => readMigrationDerivedTicketNumber,
|
|
973
|
+
readRunTicketNumber: () => readRunTicketNumber,
|
|
974
|
+
requireSafePositiveTicketNumber: () => requireSafePositiveTicketNumber
|
|
975
|
+
});
|
|
967
976
|
import { readFile as readFile3 } from "node:fs/promises";
|
|
968
977
|
import { join as join2 } from "node:path";
|
|
969
978
|
function isEnoent(error) {
|
|
@@ -1003,9 +1012,22 @@ async function readBoardPageTicketNumber(runDirectory, page) {
|
|
|
1003
1012
|
async function readBoardTicketNumber(runDirectory) {
|
|
1004
1013
|
return await readBoardPageTicketNumber(runDirectory, "admitted-request.json") ?? await readBoardPageTicketNumber(runDirectory, "invocation.json");
|
|
1005
1014
|
}
|
|
1015
|
+
async function readMigrationDerivedTicketNumber(runDirectory) {
|
|
1016
|
+
const record4 = await readJsonObject(
|
|
1017
|
+
join2(runDirectory, MIGRATION_TICKET_DERIVATION_PAGE)
|
|
1018
|
+
);
|
|
1019
|
+
if (record4 === void 0) return void 0;
|
|
1020
|
+
if (record4.derivation !== "worktree-path-basename") return void 0;
|
|
1021
|
+
return ticketFromRecord(record4);
|
|
1022
|
+
}
|
|
1023
|
+
async function readRunTicketNumber(runDirectory) {
|
|
1024
|
+
return await readBoardTicketNumber(runDirectory) ?? await readMigrationDerivedTicketNumber(runDirectory);
|
|
1025
|
+
}
|
|
1026
|
+
var MIGRATION_TICKET_DERIVATION_PAGE;
|
|
1006
1027
|
var init_run_ticket_number = __esm({
|
|
1007
1028
|
"src/run-ticket-number.ts"() {
|
|
1008
1029
|
"use strict";
|
|
1030
|
+
MIGRATION_TICKET_DERIVATION_PAGE = "migration-ticket-derivation.json";
|
|
1009
1031
|
}
|
|
1010
1032
|
});
|
|
1011
1033
|
|
|
@@ -1388,15 +1410,165 @@ var init_gatekeeper_output = __esm({
|
|
|
1388
1410
|
}
|
|
1389
1411
|
});
|
|
1390
1412
|
|
|
1413
|
+
// src/run-terminal-artifacts.ts
|
|
1414
|
+
var run_terminal_artifacts_exports = {};
|
|
1415
|
+
__export(run_terminal_artifacts_exports, {
|
|
1416
|
+
RUN_TERMINAL_ARTIFACT_FILES: () => RUN_TERMINAL_ARTIFACT_FILES,
|
|
1417
|
+
RUN_TERMINAL_ERROR_FALLBACK_RELATIVE_PATHS: () => RUN_TERMINAL_ERROR_FALLBACK_RELATIVE_PATHS,
|
|
1418
|
+
isUniqueErrorFallbackName: () => isUniqueErrorFallbackName,
|
|
1419
|
+
readRunTerminalArtifact: () => readRunTerminalArtifact,
|
|
1420
|
+
runIdFromRunDirectory: () => runIdFromRunDirectory
|
|
1421
|
+
});
|
|
1422
|
+
import { readdir as readdir2, readFile as readFile4 } from "node:fs/promises";
|
|
1423
|
+
import { basename as basename2, dirname as dirname4, join as join5 } from "node:path";
|
|
1424
|
+
function isMissingPathError2(error) {
|
|
1425
|
+
return error instanceof Error && "code" in error && (error.code === "ENOENT" || error.code === "ENOTDIR");
|
|
1426
|
+
}
|
|
1427
|
+
function errorText2(error) {
|
|
1428
|
+
return error instanceof Error ? error.message : String(error);
|
|
1429
|
+
}
|
|
1430
|
+
function isRecord2(value) {
|
|
1431
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
1432
|
+
}
|
|
1433
|
+
function readUsableTerminalArtifactBody(body) {
|
|
1434
|
+
if (body === null) {
|
|
1435
|
+
return { ok: false, reason: "terminal artifact JSON value is null" };
|
|
1436
|
+
}
|
|
1437
|
+
if (!isRecord2(body)) {
|
|
1438
|
+
return {
|
|
1439
|
+
ok: false,
|
|
1440
|
+
reason: `terminal artifact JSON value is not a typed object (${Array.isArray(body) ? "array" : typeof body})`
|
|
1441
|
+
};
|
|
1442
|
+
}
|
|
1443
|
+
if (typeof body.role !== "string" || body.role.trim() === "") {
|
|
1444
|
+
return {
|
|
1445
|
+
ok: false,
|
|
1446
|
+
reason: "terminal artifact missing nonblank producer-owned role field"
|
|
1447
|
+
};
|
|
1448
|
+
}
|
|
1449
|
+
return { ok: true, body };
|
|
1450
|
+
}
|
|
1451
|
+
async function readTerminalArtifactAtPath(path, file) {
|
|
1452
|
+
let raw;
|
|
1453
|
+
try {
|
|
1454
|
+
raw = await readFile4(path, "utf8");
|
|
1455
|
+
} catch (error) {
|
|
1456
|
+
if (isMissingPathError2(error)) return void 0;
|
|
1457
|
+
return {
|
|
1458
|
+
status: "unreadable",
|
|
1459
|
+
file,
|
|
1460
|
+
path,
|
|
1461
|
+
reason: errorText2(error)
|
|
1462
|
+
};
|
|
1463
|
+
}
|
|
1464
|
+
let parsed;
|
|
1465
|
+
try {
|
|
1466
|
+
parsed = JSON.parse(raw);
|
|
1467
|
+
} catch (error) {
|
|
1468
|
+
return {
|
|
1469
|
+
status: "unreadable",
|
|
1470
|
+
file,
|
|
1471
|
+
path,
|
|
1472
|
+
reason: error instanceof Error ? error.message : `terminal artifact JSON parse failed: ${String(error)}`
|
|
1473
|
+
};
|
|
1474
|
+
}
|
|
1475
|
+
const usable = readUsableTerminalArtifactBody(parsed);
|
|
1476
|
+
if (!usable.ok) {
|
|
1477
|
+
return {
|
|
1478
|
+
status: "unreadable",
|
|
1479
|
+
file,
|
|
1480
|
+
path,
|
|
1481
|
+
reason: usable.reason
|
|
1482
|
+
};
|
|
1483
|
+
}
|
|
1484
|
+
return { status: "present", file, path, body: usable.body };
|
|
1485
|
+
}
|
|
1486
|
+
async function listUniqueErrorFallbackPaths(directories) {
|
|
1487
|
+
const found = [];
|
|
1488
|
+
for (const dir of directories) {
|
|
1489
|
+
let names;
|
|
1490
|
+
try {
|
|
1491
|
+
names = await readdir2(dir);
|
|
1492
|
+
} catch (error) {
|
|
1493
|
+
if (isMissingPathError2(error)) continue;
|
|
1494
|
+
throw error;
|
|
1495
|
+
}
|
|
1496
|
+
for (const name of names.sort((a, b) => a.localeCompare(b))) {
|
|
1497
|
+
if (!UNIQUE_ERROR_FALLBACK_NAME.test(name)) continue;
|
|
1498
|
+
found.push(join5(dir, name));
|
|
1499
|
+
}
|
|
1500
|
+
}
|
|
1501
|
+
return found;
|
|
1502
|
+
}
|
|
1503
|
+
function runIdFromRunDirectory(runDirectory) {
|
|
1504
|
+
const name = basename2(runDirectory);
|
|
1505
|
+
const at = name.lastIndexOf("@");
|
|
1506
|
+
if (at <= 0 || at === name.length - 1) return void 0;
|
|
1507
|
+
return name.slice(0, at);
|
|
1508
|
+
}
|
|
1509
|
+
function presentUniqueFallbackBoundToRun(body, expectedRunId) {
|
|
1510
|
+
if (expectedRunId === void 0) return false;
|
|
1511
|
+
return typeof body.runId === "string" && body.runId === expectedRunId;
|
|
1512
|
+
}
|
|
1513
|
+
async function readRunTerminalArtifact(runDirectory) {
|
|
1514
|
+
const artifactsDir = roleRunArtifactsDirectory(runDirectory);
|
|
1515
|
+
for (const file of RUN_TERMINAL_ARTIFACT_FILES) {
|
|
1516
|
+
const path = join5(artifactsDir, file);
|
|
1517
|
+
const read = await readTerminalArtifactAtPath(path, file);
|
|
1518
|
+
if (read !== void 0) return read;
|
|
1519
|
+
}
|
|
1520
|
+
for (const relative4 of RUN_TERMINAL_ERROR_FALLBACK_RELATIVE_PATHS) {
|
|
1521
|
+
const path = join5(runDirectory, relative4);
|
|
1522
|
+
const read = await readTerminalArtifactAtPath(path, "error.json");
|
|
1523
|
+
if (read !== void 0) return read;
|
|
1524
|
+
}
|
|
1525
|
+
for (const path of await listUniqueErrorFallbackPaths([artifactsDir, runDirectory])) {
|
|
1526
|
+
const read = await readTerminalArtifactAtPath(path, "error.json");
|
|
1527
|
+
if (read !== void 0) return read;
|
|
1528
|
+
}
|
|
1529
|
+
const expectedRunId = runIdFromRunDirectory(runDirectory);
|
|
1530
|
+
for (const path of await listUniqueErrorFallbackPaths([dirname4(runDirectory)])) {
|
|
1531
|
+
const read = await readTerminalArtifactAtPath(path, "error.json");
|
|
1532
|
+
if (read === void 0) continue;
|
|
1533
|
+
if (read.status === "present") {
|
|
1534
|
+
if (!presentUniqueFallbackBoundToRun(read.body, expectedRunId)) continue;
|
|
1535
|
+
return read;
|
|
1536
|
+
}
|
|
1537
|
+
}
|
|
1538
|
+
return { status: "absent" };
|
|
1539
|
+
}
|
|
1540
|
+
function isUniqueErrorFallbackName(name) {
|
|
1541
|
+
return UNIQUE_ERROR_FALLBACK_NAME.test(basename2(name));
|
|
1542
|
+
}
|
|
1543
|
+
var RUN_TERMINAL_ARTIFACT_FILES, RUN_TERMINAL_ERROR_FALLBACK_RELATIVE_PATHS, UNIQUE_ERROR_FALLBACK_NAME;
|
|
1544
|
+
var init_run_terminal_artifacts = __esm({
|
|
1545
|
+
"src/run-terminal-artifacts.ts"() {
|
|
1546
|
+
"use strict";
|
|
1547
|
+
init_role_run_placement();
|
|
1548
|
+
RUN_TERMINAL_ARTIFACT_FILES = [
|
|
1549
|
+
"report.json",
|
|
1550
|
+
"error.json",
|
|
1551
|
+
"audit-incomplete.json"
|
|
1552
|
+
];
|
|
1553
|
+
RUN_TERMINAL_ERROR_FALLBACK_RELATIVE_PATHS = [
|
|
1554
|
+
"artifacts/error.settlement.json",
|
|
1555
|
+
"error.settlement.json"
|
|
1556
|
+
];
|
|
1557
|
+
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;
|
|
1558
|
+
}
|
|
1559
|
+
});
|
|
1560
|
+
|
|
1391
1561
|
// src/gatekeeper-role.ts
|
|
1392
1562
|
function gateSeatLabel(stage) {
|
|
1393
1563
|
if (stage === "inspector") return "\u53F0\u9662";
|
|
1394
1564
|
if (stage === "auditor") return "\u5BA1\u5211\u9662";
|
|
1565
|
+
if (stage === "countersign") return "\u7ED9\u4E8B\u4E2D";
|
|
1395
1566
|
return "\u7B26\u5B9D\u90CE";
|
|
1396
1567
|
}
|
|
1397
1568
|
function gateOfficerForSubject(subject) {
|
|
1398
1569
|
if (subject.kind === "worker_completion") return "inspector";
|
|
1399
1570
|
if (subject.kind === "judge_compliance") return "auditor";
|
|
1571
|
+
if (subject.kind === "secretariat_verdict") return "countersign";
|
|
1400
1572
|
return "notary";
|
|
1401
1573
|
}
|
|
1402
1574
|
function failureReason(error) {
|
|
@@ -1410,9 +1582,26 @@ function readRecord(value) {
|
|
|
1410
1582
|
if (typeof value !== "object" || value === null || Array.isArray(value)) return void 0;
|
|
1411
1583
|
return value;
|
|
1412
1584
|
}
|
|
1585
|
+
function gateStatusFromCountersign(status) {
|
|
1586
|
+
if (status === "converged") return "pass";
|
|
1587
|
+
if (status === "continue") return "bounce";
|
|
1588
|
+
if (status === "escalate") return "escalate";
|
|
1589
|
+
return void 0;
|
|
1590
|
+
}
|
|
1413
1591
|
function projectOfficerDecision(officer, decision, fallbackStatus) {
|
|
1414
1592
|
const receipt = retainedReceipt(decision);
|
|
1415
1593
|
const record4 = readRecord(decision);
|
|
1594
|
+
if (officer === "countersign") {
|
|
1595
|
+
const countersignStatus = record4 !== void 0 && typeof record4.countersignStatus === "string" ? record4.countersignStatus : void 0;
|
|
1596
|
+
const status2 = typeof countersignStatus === "string" ? gateStatusFromCountersign(countersignStatus) : void 0;
|
|
1597
|
+
if (status2 === "pass") {
|
|
1598
|
+
return { status: "pass", officer, receipt };
|
|
1599
|
+
}
|
|
1600
|
+
if (status2 === "bounce" || status2 === "escalate") {
|
|
1601
|
+
return { status: status2, officer, receipt };
|
|
1602
|
+
}
|
|
1603
|
+
return { status: "needs_reask", officer, receipt };
|
|
1604
|
+
}
|
|
1416
1605
|
const status = (record4 !== void 0 && typeof record4.status === "string" ? record4.status : void 0) ?? fallbackStatus;
|
|
1417
1606
|
if (status === "pass") {
|
|
1418
1607
|
return { status: "pass", officer, receipt };
|
|
@@ -1443,6 +1632,26 @@ function projectOfficerPayloads(officer, payloads, fallbackStatus) {
|
|
|
1443
1632
|
}
|
|
1444
1633
|
return projectOfficerDecision(officer, payloads[payloads.length - 1], fallbackStatus);
|
|
1445
1634
|
}
|
|
1635
|
+
function officerRunIdFromSummoned(summoned) {
|
|
1636
|
+
if (typeof summoned.runDirectory === "string" && summoned.runDirectory.trim() !== "") {
|
|
1637
|
+
const fromDir = runIdFromRunDirectory(summoned.runDirectory);
|
|
1638
|
+
if (fromDir !== void 0) return fromDir;
|
|
1639
|
+
}
|
|
1640
|
+
const terminal = summoned.terminal;
|
|
1641
|
+
if (terminal !== void 0 && typeof terminal.runId === "string" && terminal.runId.trim() !== "") {
|
|
1642
|
+
return terminal.runId;
|
|
1643
|
+
}
|
|
1644
|
+
return void 0;
|
|
1645
|
+
}
|
|
1646
|
+
function withOfficerRunId(result, summoned) {
|
|
1647
|
+
if (result.status !== "pass" && result.status !== "bounce" && result.status !== "escalate" && result.status !== "needs_reask") {
|
|
1648
|
+
return result;
|
|
1649
|
+
}
|
|
1650
|
+
if (typeof result.runId === "string" && result.runId.trim() !== "") return result;
|
|
1651
|
+
const runId = officerRunIdFromSummoned(summoned);
|
|
1652
|
+
if (runId === void 0) return result;
|
|
1653
|
+
return { ...result, runId };
|
|
1654
|
+
}
|
|
1446
1655
|
function projectOfficerTerminal(officer, summoned) {
|
|
1447
1656
|
const terminal = summoned.terminal;
|
|
1448
1657
|
const outcome = terminal?.roleOutcome;
|
|
@@ -1475,22 +1684,34 @@ function projectOfficerTerminal(officer, summoned) {
|
|
|
1475
1684
|
};
|
|
1476
1685
|
}
|
|
1477
1686
|
if (outcome.kind === "audit_escalation") {
|
|
1478
|
-
return
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1687
|
+
return withOfficerRunId(
|
|
1688
|
+
{
|
|
1689
|
+
status: "escalate",
|
|
1690
|
+
officer,
|
|
1691
|
+
// This-court receipt only (#879) — historical rows remain on terminal.submissions.
|
|
1692
|
+
receipt: thisCourt.length > 0 ? thisCourt[thisCourt.length - 1] : retainedReceipt(outcome)
|
|
1693
|
+
},
|
|
1694
|
+
summoned
|
|
1695
|
+
);
|
|
1484
1696
|
}
|
|
1485
1697
|
if (outcome.kind === "accepted") {
|
|
1486
|
-
return
|
|
1698
|
+
return withOfficerRunId(
|
|
1699
|
+
projectOfficerPayloads(officer, thisCourt, outcome.status),
|
|
1700
|
+
summoned
|
|
1701
|
+
);
|
|
1487
1702
|
}
|
|
1488
|
-
return
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1703
|
+
return withOfficerRunId(
|
|
1704
|
+
{
|
|
1705
|
+
status: "needs_reask",
|
|
1706
|
+
officer,
|
|
1707
|
+
// This-court receipt only (#879).
|
|
1708
|
+
receipt: thisCourt.length > 0 ? thisCourt[thisCourt.length - 1] : retainedReceipt(outcome)
|
|
1709
|
+
},
|
|
1710
|
+
summoned
|
|
1711
|
+
);
|
|
1712
|
+
}
|
|
1713
|
+
function officerConclusionReask(officer) {
|
|
1714
|
+
return officer === "countersign" ? COUNTERSIGN_CONCLUSION_REASK : OFFICER_CONCLUSION_REASK;
|
|
1494
1715
|
}
|
|
1495
1716
|
async function projectGatekeeperRun(options) {
|
|
1496
1717
|
const officer = gateOfficerForSubject(options.subject);
|
|
@@ -1526,7 +1747,7 @@ async function projectGatekeeperRun(options) {
|
|
|
1526
1747
|
summoned
|
|
1527
1748
|
};
|
|
1528
1749
|
}
|
|
1529
|
-
var GATEKEEPER_TOOL_SPEC, OFFICER_CONCLUSION_REASK;
|
|
1750
|
+
var GATEKEEPER_TOOL_SPEC, OFFICER_CONCLUSION_REASK, COUNTERSIGN_CONCLUSION_REASK;
|
|
1530
1751
|
var init_gatekeeper_role = __esm({
|
|
1531
1752
|
"src/gatekeeper-role.ts"() {
|
|
1532
1753
|
"use strict";
|
|
@@ -1534,6 +1755,7 @@ var init_gatekeeper_role = __esm({
|
|
|
1534
1755
|
init_submission_errors();
|
|
1535
1756
|
init_inspector_contracts();
|
|
1536
1757
|
init_gatekeeper_output();
|
|
1758
|
+
init_run_terminal_artifacts();
|
|
1537
1759
|
init_submission_errors();
|
|
1538
1760
|
GATEKEEPER_TOOL_SPEC = {
|
|
1539
1761
|
name: GATEKEEPER_OUTPUT_TOOL_NAME,
|
|
@@ -1543,6 +1765,7 @@ var init_gatekeeper_role = __esm({
|
|
|
1543
1765
|
parameters: gatekeeperOutputSchema
|
|
1544
1766
|
};
|
|
1545
1767
|
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";
|
|
1768
|
+
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";
|
|
1546
1769
|
}
|
|
1547
1770
|
});
|
|
1548
1771
|
|
|
@@ -1553,12 +1776,12 @@ __export(session_assistant_usage_exports, {
|
|
|
1553
1776
|
sessionFileFromPublicSummon: () => sessionFileFromPublicSummon,
|
|
1554
1777
|
usageFromPublicSummon: () => usageFromPublicSummon
|
|
1555
1778
|
});
|
|
1556
|
-
import { join as
|
|
1779
|
+
import { join as join6 } from "node:path";
|
|
1557
1780
|
async function readAssistantUsageFromSessionFile(sessionFile) {
|
|
1558
|
-
const { readFile:
|
|
1781
|
+
const { readFile: readFile24 } = await import("node:fs/promises");
|
|
1559
1782
|
let text;
|
|
1560
1783
|
try {
|
|
1561
|
-
text = await
|
|
1784
|
+
text = await readFile24(sessionFile, "utf8");
|
|
1562
1785
|
} catch (error) {
|
|
1563
1786
|
if (error?.code === "ENOENT") return void 0;
|
|
1564
1787
|
throw error;
|
|
@@ -1623,7 +1846,7 @@ async function readAssistantUsageFromSessionFile(sessionFile) {
|
|
|
1623
1846
|
}
|
|
1624
1847
|
function sessionFileFromPublicSummon(summoned) {
|
|
1625
1848
|
if (typeof summoned.runDirectory === "string" && summoned.runDirectory.trim() !== "") {
|
|
1626
|
-
return
|
|
1849
|
+
return join6(summoned.runDirectory, "session", "session.jsonl");
|
|
1627
1850
|
}
|
|
1628
1851
|
const fromArtifacts = summoned.terminal?.artifacts?.map((a) => a.path).find((p) => typeof p === "string" && p.endsWith("session.jsonl"));
|
|
1629
1852
|
if (fromArtifacts !== void 0) return fromArtifacts;
|
|
@@ -1632,7 +1855,7 @@ function sessionFileFromPublicSummon(summoned) {
|
|
|
1632
1855
|
const facts = outcome.decisiveFacts;
|
|
1633
1856
|
const pointer = facts?.runPointer;
|
|
1634
1857
|
if (typeof pointer === "string" && pointer.trim() !== "") {
|
|
1635
|
-
return
|
|
1858
|
+
return join6(pointer, "session", "session.jsonl");
|
|
1636
1859
|
}
|
|
1637
1860
|
return void 0;
|
|
1638
1861
|
}
|
|
@@ -1649,7 +1872,7 @@ var init_session_assistant_usage = __esm({
|
|
|
1649
1872
|
|
|
1650
1873
|
// src/package-resources/engine-material.ts
|
|
1651
1874
|
import { existsSync, readdirSync } from "node:fs";
|
|
1652
|
-
import { join as
|
|
1875
|
+
import { join as join7 } from "node:path";
|
|
1653
1876
|
function pickEngineAxis(source) {
|
|
1654
1877
|
return {
|
|
1655
1878
|
...source.engine === void 0 ? {} : { engine: source.engine },
|
|
@@ -1670,11 +1893,11 @@ function isEngineNameSyntax(name) {
|
|
|
1670
1893
|
return true;
|
|
1671
1894
|
}
|
|
1672
1895
|
function resolveEngineMaterialDirectory(packageRoot) {
|
|
1673
|
-
return
|
|
1896
|
+
return join7(packageRoot, ENGINE_MATERIAL_RELATIVE_ROOT);
|
|
1674
1897
|
}
|
|
1675
1898
|
function resolveEngineMaterialPath(packageRoot, name) {
|
|
1676
1899
|
const legal = assertLegalEngineName(name);
|
|
1677
|
-
return
|
|
1900
|
+
return join7(resolveEngineMaterialDirectory(packageRoot), `${legal}.md`);
|
|
1678
1901
|
}
|
|
1679
1902
|
function assertLegalEngineName(name) {
|
|
1680
1903
|
if (!isEngineNameSyntax(name)) {
|
|
@@ -1727,7 +1950,7 @@ var init_engine_material = __esm({
|
|
|
1727
1950
|
|
|
1728
1951
|
// src/activation-ledger-git.ts
|
|
1729
1952
|
import { execFileSync } from "node:child_process";
|
|
1730
|
-
import { basename as
|
|
1953
|
+
import { basename as basename3, dirname as dirname5, isAbsolute as isAbsolute2, resolve as resolve4 } from "node:path";
|
|
1731
1954
|
function envWithoutGitDiscovery(base = process.env) {
|
|
1732
1955
|
const env = { ...base, LC_ALL: "C" };
|
|
1733
1956
|
for (const key of GIT_DISCOVERY_ENV_KEYS) {
|
|
@@ -1772,8 +1995,8 @@ function resolveBookKeyFromGit(cwd) {
|
|
|
1772
1995
|
throw new Error("git rev-parse --git-common-dir returned an empty path");
|
|
1773
1996
|
}
|
|
1774
1997
|
const absoluteCommon = isAbsolute2(commonDir) ? commonDir : resolve4(cwd, commonDir);
|
|
1775
|
-
const hostDirectory =
|
|
1776
|
-
const bookKey =
|
|
1998
|
+
const hostDirectory = basename3(absoluteCommon) === ".git" ? dirname5(absoluteCommon) : absoluteCommon;
|
|
1999
|
+
const bookKey = basename3(hostDirectory);
|
|
1777
2000
|
if (bookKey.length === 0 || bookKey === "." || bookKey === "/") {
|
|
1778
2001
|
throw new Error(`Unable to derive activation book key from git common dir: ${absoluteCommon}`);
|
|
1779
2002
|
}
|
|
@@ -1813,7 +2036,7 @@ __export(durable_principal_exports, {
|
|
|
1813
2036
|
piDurablePrincipalAuthority: () => piDurablePrincipalAuthority
|
|
1814
2037
|
});
|
|
1815
2038
|
import { lstat } from "node:fs/promises";
|
|
1816
|
-
import { join as
|
|
2039
|
+
import { join as join8 } from "node:path";
|
|
1817
2040
|
function encode(coordinates) {
|
|
1818
2041
|
return coordinates;
|
|
1819
2042
|
}
|
|
@@ -1863,7 +2086,7 @@ var init_durable_principal = __esm({
|
|
|
1863
2086
|
}
|
|
1864
2087
|
return {
|
|
1865
2088
|
sessionDirectory: record4.sessionDirectory,
|
|
1866
|
-
sessionFile: typeof record4.sessionFile === "string" && record4.sessionFile.trim() !== "" ? record4.sessionFile :
|
|
2089
|
+
sessionFile: typeof record4.sessionFile === "string" && record4.sessionFile.trim() !== "" ? record4.sessionFile : join8(record4.sessionDirectory, "session.jsonl")
|
|
1867
2090
|
};
|
|
1868
2091
|
},
|
|
1869
2092
|
async isAvailable(principal) {
|
|
@@ -1915,7 +2138,7 @@ var init_host_contracts = __esm({
|
|
|
1915
2138
|
import { spawn as spawn2 } from "node:child_process";
|
|
1916
2139
|
import { mkdtemp, rm, writeFile } from "node:fs/promises";
|
|
1917
2140
|
import { tmpdir } from "node:os";
|
|
1918
|
-
import { join as
|
|
2141
|
+
import { join as join9 } from "node:path";
|
|
1919
2142
|
function normalizeEngineName(engine) {
|
|
1920
2143
|
if (engine === void 0) return void 0;
|
|
1921
2144
|
const trimmed = engine.trim();
|
|
@@ -2016,8 +2239,8 @@ async function runEngineDetourOnce(input) {
|
|
|
2016
2239
|
if (input.stagedPrompt === void 0) {
|
|
2017
2240
|
return spawnEngineDetourOnce(input);
|
|
2018
2241
|
}
|
|
2019
|
-
const stagingDir = await mkdtemp(
|
|
2020
|
-
const stagedPath =
|
|
2242
|
+
const stagingDir = await mkdtemp(join9(tmpdir(), "ak-engine-detour-"));
|
|
2243
|
+
const stagedPath = join9(stagingDir, "prompt.txt");
|
|
2021
2244
|
let result;
|
|
2022
2245
|
let runError;
|
|
2023
2246
|
try {
|
|
@@ -2653,7 +2876,7 @@ var init_auditor_output = __esm({
|
|
|
2653
2876
|
});
|
|
2654
2877
|
|
|
2655
2878
|
// src/ticket-provenance-contracts.ts
|
|
2656
|
-
function
|
|
2879
|
+
function isRecord3(value) {
|
|
2657
2880
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
2658
2881
|
}
|
|
2659
2882
|
function positiveInteger(value) {
|
|
@@ -2676,7 +2899,7 @@ function projectSpeaker(value) {
|
|
|
2676
2899
|
return value === "owner" || value === "runner" ? value : void 0;
|
|
2677
2900
|
}
|
|
2678
2901
|
function projectBound(value) {
|
|
2679
|
-
if (!
|
|
2902
|
+
if (!isRecord3(value)) return void 0;
|
|
2680
2903
|
const id = typeof value.id === "string" && value.id !== "" ? value.id : void 0;
|
|
2681
2904
|
const line2 = positiveInteger(value.line);
|
|
2682
2905
|
if (id === void 0 && line2 === void 0) return void 0;
|
|
@@ -2687,13 +2910,13 @@ function projectTicketProvenanceSessions(value) {
|
|
|
2687
2910
|
if (value.length === 0) return [];
|
|
2688
2911
|
const sessions = [];
|
|
2689
2912
|
for (const raw of value) {
|
|
2690
|
-
if (!
|
|
2913
|
+
if (!isRecord3(raw)) return void 0;
|
|
2691
2914
|
const path = raw.path;
|
|
2692
2915
|
if (typeof path !== "string" || path.trim() === "") return void 0;
|
|
2693
2916
|
if (!Array.isArray(raw.ranges) || raw.ranges.length === 0) return void 0;
|
|
2694
2917
|
const ranges = [];
|
|
2695
2918
|
for (const rawRange of raw.ranges) {
|
|
2696
|
-
if (!
|
|
2919
|
+
if (!isRecord3(rawRange)) return void 0;
|
|
2697
2920
|
const from = projectBound(rawRange.from);
|
|
2698
2921
|
const to = projectBound(rawRange.to);
|
|
2699
2922
|
if (from === void 0 || to === void 0) return void 0;
|
|
@@ -2704,7 +2927,7 @@ function projectTicketProvenanceSessions(value) {
|
|
|
2704
2927
|
return sessions;
|
|
2705
2928
|
}
|
|
2706
2929
|
function projectTicketProvenanceHeader(value) {
|
|
2707
|
-
if (!
|
|
2930
|
+
if (!isRecord3(value)) return void 0;
|
|
2708
2931
|
const ticket = positiveInteger(value.ticket);
|
|
2709
2932
|
if (ticket === void 0) return void 0;
|
|
2710
2933
|
if (typeof value.repo !== "string") return void 0;
|
|
@@ -2722,7 +2945,7 @@ function projectTicketProvenanceHeader(value) {
|
|
|
2722
2945
|
};
|
|
2723
2946
|
}
|
|
2724
2947
|
function projectTicketProvenanceLine(value) {
|
|
2725
|
-
if (!
|
|
2948
|
+
if (!isRecord3(value)) return void 0;
|
|
2726
2949
|
const speaker = projectSpeaker(value.speaker);
|
|
2727
2950
|
const s = nonNegativeInteger(value.s);
|
|
2728
2951
|
if (speaker === void 0 || s === void 0) return void 0;
|
|
@@ -2838,13 +3061,23 @@ var init_diarist_contracts = __esm({
|
|
|
2838
3061
|
});
|
|
2839
3062
|
|
|
2840
3063
|
// src/secretariat-contracts.ts
|
|
2841
|
-
var
|
|
3064
|
+
var secretariat_contracts_exports = {};
|
|
3065
|
+
__export(secretariat_contracts_exports, {
|
|
3066
|
+
SECRETARIAT_ACCEPTED_TEXT: () => SECRETARIAT_ACCEPTED_TEXT,
|
|
3067
|
+
SECRETARIAT_COUNTERSIGN_TERMINAL_FACT_KEY: () => SECRETARIAT_COUNTERSIGN_TERMINAL_FACT_KEY,
|
|
3068
|
+
SECRETARIAT_GATE_OFFICER_ENTRY_TYPE: () => SECRETARIAT_GATE_OFFICER_ENTRY_TYPE,
|
|
3069
|
+
SECRETARIAT_OUTPUT_TOOL_NAME: () => SECRETARIAT_OUTPUT_TOOL_NAME,
|
|
3070
|
+
SECRETARIAT_SUMMON_COUNTERSIGN_TOOL_NAME: () => SECRETARIAT_SUMMON_COUNTERSIGN_TOOL_NAME
|
|
3071
|
+
});
|
|
3072
|
+
var SECRETARIAT_OUTPUT_TOOL_NAME, SECRETARIAT_SUMMON_COUNTERSIGN_TOOL_NAME, SECRETARIAT_ACCEPTED_TEXT, SECRETARIAT_GATE_OFFICER_ENTRY_TYPE, SECRETARIAT_COUNTERSIGN_TERMINAL_FACT_KEY;
|
|
2842
3073
|
var init_secretariat_contracts = __esm({
|
|
2843
3074
|
"src/secretariat-contracts.ts"() {
|
|
2844
3075
|
"use strict";
|
|
2845
3076
|
SECRETARIAT_OUTPUT_TOOL_NAME = "ak_secretariat_output";
|
|
2846
3077
|
SECRETARIAT_SUMMON_COUNTERSIGN_TOOL_NAME = "ak_secretariat_summon_countersign";
|
|
2847
3078
|
SECRETARIAT_ACCEPTED_TEXT = "\u4E2D\u4E66\u7701\u56DE\u6267\u5DF2\u63A5\u53D7";
|
|
3079
|
+
SECRETARIAT_GATE_OFFICER_ENTRY_TYPE = "ak-secretariat-gate-officer";
|
|
3080
|
+
SECRETARIAT_COUNTERSIGN_TERMINAL_FACT_KEY = "countersignTerminal";
|
|
2848
3081
|
}
|
|
2849
3082
|
});
|
|
2850
3083
|
|
|
@@ -3191,8 +3424,8 @@ import {
|
|
|
3191
3424
|
unlinkSync,
|
|
3192
3425
|
writeFileSync
|
|
3193
3426
|
} from "node:fs";
|
|
3194
|
-
import { dirname as
|
|
3195
|
-
function
|
|
3427
|
+
import { dirname as dirname6, join as join10 } from "node:path";
|
|
3428
|
+
function isRecord4(value) {
|
|
3196
3429
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
3197
3430
|
}
|
|
3198
3431
|
function errorCodeOf(error) {
|
|
@@ -3220,7 +3453,7 @@ function findIdentityPointer(recordFile, identity, kind, level) {
|
|
|
3220
3453
|
if (!trimmed) continue;
|
|
3221
3454
|
try {
|
|
3222
3455
|
const parsed = JSON.parse(trimmed);
|
|
3223
|
-
if (
|
|
3456
|
+
if (isRecord4(parsed) && parsed.identity === identity) {
|
|
3224
3457
|
return { identity, recordFile, kind, level };
|
|
3225
3458
|
}
|
|
3226
3459
|
} catch {
|
|
@@ -3319,8 +3552,8 @@ function resolveSitianVolumeCategory(kind) {
|
|
|
3319
3552
|
return kind;
|
|
3320
3553
|
}
|
|
3321
3554
|
function ticketProvenanceUnderBookPaths(ledgerHome, bookKey, ticketId) {
|
|
3322
|
-
const sessionDir =
|
|
3323
|
-
return { sessionDir, recordFile:
|
|
3555
|
+
const sessionDir = join10(activationBookDirectory(ledgerHome, bookKey), ticketId);
|
|
3556
|
+
return { sessionDir, recordFile: join10(sessionDir, SITIAN_RECORDS_LEAF) };
|
|
3324
3557
|
}
|
|
3325
3558
|
function resolveSitianRecordPathInLedger(input, ledgerHome) {
|
|
3326
3559
|
const category = resolveSitianVolumeCategory(input.kind);
|
|
@@ -3339,14 +3572,14 @@ function resolveSitianRecordPathInLedger(input, ledgerHome) {
|
|
|
3339
3572
|
if (input.sessionParent === void 0 || input.sessionParent.length === 0 || !physicallyContainedIn(ledgerHome, input.sessionParent)) {
|
|
3340
3573
|
throw new Error("Sitian record ownership requires a parent session inside the ledger home");
|
|
3341
3574
|
}
|
|
3342
|
-
sessionDir =
|
|
3343
|
-
recordFile =
|
|
3575
|
+
sessionDir = join10(dirname6(input.sessionParent), category);
|
|
3576
|
+
recordFile = join10(sessionDir, SITIAN_RECORDS_LEAF);
|
|
3344
3577
|
}
|
|
3345
3578
|
return { sessionDir, recordFile, ledgerHome };
|
|
3346
3579
|
}
|
|
3347
3580
|
function projectTicketRecordsPathShape() {
|
|
3348
3581
|
const { recordFile } = ticketProvenanceUnderBookPaths(
|
|
3349
|
-
|
|
3582
|
+
join10("~", ".ak-roles"),
|
|
3350
3583
|
"<\u7C3F>",
|
|
3351
3584
|
"<\u7968\u53F7>"
|
|
3352
3585
|
);
|
|
@@ -3408,15 +3641,15 @@ var init_sitian_appender = __esm({
|
|
|
3408
3641
|
|
|
3409
3642
|
// src/sitian-reader.ts
|
|
3410
3643
|
import { existsSync as existsSync3 } from "node:fs";
|
|
3411
|
-
import { readFile as
|
|
3412
|
-
function
|
|
3644
|
+
import { readFile as readFile5 } from "node:fs/promises";
|
|
3645
|
+
function isRecord5(value) {
|
|
3413
3646
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
3414
3647
|
}
|
|
3415
3648
|
async function readSitianRecords(recordFile) {
|
|
3416
3649
|
if (!existsSync3(recordFile)) {
|
|
3417
3650
|
return { records: [], diagnostics: [] };
|
|
3418
3651
|
}
|
|
3419
|
-
const text = await
|
|
3652
|
+
const text = await readFile5(recordFile, "utf8");
|
|
3420
3653
|
const lines = text.split("\n");
|
|
3421
3654
|
const records = [];
|
|
3422
3655
|
const diagnostics = [];
|
|
@@ -3425,7 +3658,7 @@ async function readSitianRecords(recordFile) {
|
|
|
3425
3658
|
if (!line2.trim()) continue;
|
|
3426
3659
|
try {
|
|
3427
3660
|
const parsed = JSON.parse(line2);
|
|
3428
|
-
if (
|
|
3661
|
+
if (isRecord5(parsed)) {
|
|
3429
3662
|
records.push(parsed);
|
|
3430
3663
|
} else {
|
|
3431
3664
|
const typeDesc = parsed === null ? "null" : Array.isArray(parsed) ? "array" : typeof parsed;
|
|
@@ -3481,13 +3714,13 @@ __export(role_turn_host_exports, {
|
|
|
3481
3714
|
});
|
|
3482
3715
|
import { execFile, spawn as spawn3 } from "node:child_process";
|
|
3483
3716
|
import { constants } from "node:fs";
|
|
3484
|
-
import { access, appendFile, readFile as
|
|
3485
|
-
import { basename as
|
|
3717
|
+
import { access, appendFile, readFile as readFile6, realpath as realpath2 } from "node:fs/promises";
|
|
3718
|
+
import { basename as basename4, delimiter, dirname as dirname7, isAbsolute as isAbsolute3, join as join11, resolve as resolve5 } from "node:path";
|
|
3486
3719
|
import { platform } from "node:process";
|
|
3487
3720
|
import { promisify } from "node:util";
|
|
3488
3721
|
import { randomUUID as randomUUID2 } from "node:crypto";
|
|
3489
3722
|
function resolveInternalRoleEntrypoint(packageRoot) {
|
|
3490
|
-
return
|
|
3723
|
+
return join11(packageRoot, INTERNAL_ROLE_ENTRYPOINT_RELATIVE);
|
|
3491
3724
|
}
|
|
3492
3725
|
function buildExplicitInternalActivationArgs(selectedRoleEntry, extraArgs = []) {
|
|
3493
3726
|
return ["--no-extensions", "-e", selectedRoleEntry, ...extraArgs];
|
|
@@ -3523,7 +3756,7 @@ function buildMethodArgs(methods) {
|
|
|
3523
3756
|
function applyPiNativeSkillInvocation(methods, prompt) {
|
|
3524
3757
|
const skills = methods.filter((method) => method.kind === "skill");
|
|
3525
3758
|
if (skills.length !== 1) return prompt;
|
|
3526
|
-
const name =
|
|
3759
|
+
const name = basename4(dirname7(skills[0].path));
|
|
3527
3760
|
if (name.length === 0) return prompt;
|
|
3528
3761
|
const token = `/skill:${name}`;
|
|
3529
3762
|
const trimmed = prompt.trimStart();
|
|
@@ -3761,7 +3994,7 @@ ${paths.join("\n")}`
|
|
|
3761
3994
|
}
|
|
3762
3995
|
async function appendPiSessionCustomEntry(authority, principal, customType, data) {
|
|
3763
3996
|
const { sessionFile } = authority.decode(principal);
|
|
3764
|
-
const text = await
|
|
3997
|
+
const text = await readFile6(sessionFile, "utf8");
|
|
3765
3998
|
let parentId = null;
|
|
3766
3999
|
for (const line2 of text.trim().split("\n").filter(Boolean)) {
|
|
3767
4000
|
const entry = JSON.parse(line2);
|
|
@@ -3914,8 +4147,8 @@ var init_host_descriptions = __esm({
|
|
|
3914
4147
|
|
|
3915
4148
|
// src/role-run-relocation.ts
|
|
3916
4149
|
import { existsSync as existsSync4 } from "node:fs";
|
|
3917
|
-
import { readdir as
|
|
3918
|
-
import { join as
|
|
4150
|
+
import { readdir as readdir3, readFile as readFile7, writeFile as writeFile2 } from "node:fs/promises";
|
|
4151
|
+
import { join as join12, sep as sep2 } from "node:path";
|
|
3919
4152
|
function isEnoent2(error) {
|
|
3920
4153
|
return error instanceof Error && "code" in error && error.code === "ENOENT";
|
|
3921
4154
|
}
|
|
@@ -4004,7 +4237,7 @@ function rewriteSummonsMaterials(value, rewrites) {
|
|
|
4004
4237
|
}
|
|
4005
4238
|
async function rewriteJsonObjectFile(path, fields, rewrites) {
|
|
4006
4239
|
if (!existsSync4(path)) return;
|
|
4007
|
-
const page = JSON.parse(await
|
|
4240
|
+
const page = JSON.parse(await readFile7(path, "utf8"));
|
|
4008
4241
|
if (!isPlainObject(page)) return;
|
|
4009
4242
|
rewriteRunDirectoryPathFieldsAgainstRewrites(page, fields, rewrites);
|
|
4010
4243
|
await writeFile2(path, `${JSON.stringify(page, null, 2)}
|
|
@@ -4012,7 +4245,7 @@ async function rewriteJsonObjectFile(path, fields, rewrites) {
|
|
|
4012
4245
|
}
|
|
4013
4246
|
async function rewriteOfficerPointerFile(path, rewrites) {
|
|
4014
4247
|
if (!existsSync4(path)) return;
|
|
4015
|
-
const page = JSON.parse(await
|
|
4248
|
+
const page = JSON.parse(await readFile7(path, "utf8"));
|
|
4016
4249
|
if (!isPlainObject(page)) return;
|
|
4017
4250
|
if (page.kind !== "direct-officer-run-pointer") return;
|
|
4018
4251
|
rewriteRunDirectoryPathFieldsAgainstRewrites(
|
|
@@ -4025,7 +4258,7 @@ async function rewriteOfficerPointerFile(path, rewrites) {
|
|
|
4025
4258
|
}
|
|
4026
4259
|
async function rewriteSitianRecordsJsonl(path, rewrites) {
|
|
4027
4260
|
if (!existsSync4(path)) return;
|
|
4028
|
-
const raw = await
|
|
4261
|
+
const raw = await readFile7(path, "utf8");
|
|
4029
4262
|
if (raw.length === 0) return;
|
|
4030
4263
|
const endsWithNewline = raw.endsWith("\n");
|
|
4031
4264
|
const lines = raw.split("\n");
|
|
@@ -4076,7 +4309,7 @@ async function rewriteSitianRecordsJsonl(path, rewrites) {
|
|
|
4076
4309
|
}
|
|
4077
4310
|
async function rewriteSessionTranscriptBindings(path, rewrites) {
|
|
4078
4311
|
if (!existsSync4(path)) return;
|
|
4079
|
-
const raw = await
|
|
4312
|
+
const raw = await readFile7(path, "utf8");
|
|
4080
4313
|
if (raw.length === 0) return;
|
|
4081
4314
|
const endsWithNewline = raw.endsWith("\n");
|
|
4082
4315
|
const lines = raw.split("\n");
|
|
@@ -4135,17 +4368,17 @@ async function rewriteSessionTranscriptBindings(path, rewrites) {
|
|
|
4135
4368
|
);
|
|
4136
4369
|
}
|
|
4137
4370
|
async function rewriteNestedMachinePathPages(pagesDirectory, rewrites) {
|
|
4138
|
-
const sessionRoot =
|
|
4371
|
+
const sessionRoot = join12(pagesDirectory, "session");
|
|
4139
4372
|
async function walk(directory) {
|
|
4140
4373
|
let entries;
|
|
4141
4374
|
try {
|
|
4142
|
-
entries = await
|
|
4375
|
+
entries = await readdir3(directory, { withFileTypes: true });
|
|
4143
4376
|
} catch (error) {
|
|
4144
4377
|
if (isEnoent2(error)) return;
|
|
4145
4378
|
throw error;
|
|
4146
4379
|
}
|
|
4147
4380
|
for (const entry of entries) {
|
|
4148
|
-
const path =
|
|
4381
|
+
const path = join12(directory, entry.name);
|
|
4149
4382
|
if (entry.isDirectory()) {
|
|
4150
4383
|
await walk(path);
|
|
4151
4384
|
continue;
|
|
@@ -4167,9 +4400,9 @@ async function rewriteNestedMachinePathPages(pagesDirectory, rewrites) {
|
|
|
4167
4400
|
async function rewriteRoleRunDurablePages(input) {
|
|
4168
4401
|
const { pagesDirectory } = input;
|
|
4169
4402
|
const rewrites = collectRewrites(input);
|
|
4170
|
-
const admittedPath =
|
|
4403
|
+
const admittedPath = join12(pagesDirectory, "admitted-request.json");
|
|
4171
4404
|
if (existsSync4(admittedPath)) {
|
|
4172
|
-
const page = JSON.parse(await
|
|
4405
|
+
const page = JSON.parse(await readFile7(admittedPath, "utf8"));
|
|
4173
4406
|
rewriteRunDirectoryPathFieldsAgainstRewrites(
|
|
4174
4407
|
page,
|
|
4175
4408
|
ADMITTED_PAGE_FIELDS,
|
|
@@ -4197,9 +4430,9 @@ async function rewriteRoleRunDurablePages(input) {
|
|
|
4197
4430
|
await writeFile2(admittedPath, `${JSON.stringify(page, null, 2)}
|
|
4198
4431
|
`, "utf8");
|
|
4199
4432
|
}
|
|
4200
|
-
const invocationPath =
|
|
4433
|
+
const invocationPath = join12(pagesDirectory, "invocation.json");
|
|
4201
4434
|
if (existsSync4(invocationPath)) {
|
|
4202
|
-
const page = JSON.parse(await
|
|
4435
|
+
const page = JSON.parse(await readFile7(invocationPath, "utf8"));
|
|
4203
4436
|
rewriteRunDirectoryPathFieldsAgainstRewrites(
|
|
4204
4437
|
page,
|
|
4205
4438
|
INVOCATION_PAGE_FIELDS,
|
|
@@ -4212,9 +4445,9 @@ async function rewriteRoleRunDurablePages(input) {
|
|
|
4212
4445
|
"utf8"
|
|
4213
4446
|
);
|
|
4214
4447
|
}
|
|
4215
|
-
const statePath =
|
|
4448
|
+
const statePath = join12(pagesDirectory, "run-state.json");
|
|
4216
4449
|
if (existsSync4(statePath)) {
|
|
4217
|
-
const page = JSON.parse(await
|
|
4450
|
+
const page = JSON.parse(await readFile7(statePath, "utf8"));
|
|
4218
4451
|
rewriteRunDirectoryPathFieldsAgainstRewrites(
|
|
4219
4452
|
page,
|
|
4220
4453
|
RUN_STATE_PAGE_FIELDS,
|
|
@@ -4402,15 +4635,15 @@ var init_terminating_tools = __esm({
|
|
|
4402
4635
|
});
|
|
4403
4636
|
|
|
4404
4637
|
// src/doctor-evidence.ts
|
|
4405
|
-
import { readdir as
|
|
4406
|
-
import { dirname as
|
|
4638
|
+
import { readdir as readdir4, readFile as readFile8, realpath as realpath3, stat } from "node:fs/promises";
|
|
4639
|
+
import { dirname as dirname8, relative as relative2, resolve as resolve6, sep as sep3 } from "node:path";
|
|
4407
4640
|
function record3(value) {
|
|
4408
4641
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
4409
4642
|
}
|
|
4410
4643
|
async function discoverCaseFiles(root) {
|
|
4411
4644
|
const found = [];
|
|
4412
4645
|
async function walk(dir, depth) {
|
|
4413
|
-
for (const item of await
|
|
4646
|
+
for (const item of await readdir4(dir, { withFileTypes: true })) {
|
|
4414
4647
|
const path = resolve6(dir, item.name);
|
|
4415
4648
|
if (item.isDirectory()) {
|
|
4416
4649
|
await walk(path, depth + 1);
|
|
@@ -4430,7 +4663,7 @@ function accumulate(metric, value, source) {
|
|
|
4430
4663
|
function timestamp(row) {
|
|
4431
4664
|
return typeof row.timestamp === "string" && Number.isFinite(Date.parse(row.timestamp)) ? row.timestamp : void 0;
|
|
4432
4665
|
}
|
|
4433
|
-
function
|
|
4666
|
+
function isMissingPathError3(error) {
|
|
4434
4667
|
return error instanceof Error && "code" in error && (error.code === "ENOENT" || error.code === "ENOTDIR");
|
|
4435
4668
|
}
|
|
4436
4669
|
async function stableRunsIdentity(root) {
|
|
@@ -4440,9 +4673,9 @@ async function stableRunsIdentity(root) {
|
|
|
4440
4673
|
const git3 = await stat(resolve6(cursor, ".git"));
|
|
4441
4674
|
if (git3.isDirectory() || git3.isFile()) return relative2(cursor, root).split(sep3).join("/");
|
|
4442
4675
|
} catch (error) {
|
|
4443
|
-
if (!
|
|
4676
|
+
if (!isMissingPathError3(error)) throw error;
|
|
4444
4677
|
}
|
|
4445
|
-
const parent =
|
|
4678
|
+
const parent = dirname8(cursor);
|
|
4446
4679
|
if (parent === cursor) return root;
|
|
4447
4680
|
cursor = parent;
|
|
4448
4681
|
}
|
|
@@ -4518,7 +4751,7 @@ async function loadDoctorCase(runsPath) {
|
|
|
4518
4751
|
const turns = { count: 0, sources: [] }, calls = { count: 0, sources: [] }, tokens = { count: 0, sources: [] };
|
|
4519
4752
|
for (const path of await discoverCaseFiles(root)) {
|
|
4520
4753
|
const id = relative2(root, path).split(sep3).join("/");
|
|
4521
|
-
const bytes = await
|
|
4754
|
+
const bytes = await readFile8(path);
|
|
4522
4755
|
const content = bytes.toString("utf8");
|
|
4523
4756
|
const kind = id.endsWith(".jsonl") ? "session" : "stderr";
|
|
4524
4757
|
evidence.push({ id, kind, byteLength: bytes.byteLength, contentLength: content.length, sha256: sha256Hex(bytes), content });
|
|
@@ -4531,7 +4764,7 @@ async function loadDoctorCase(runsPath) {
|
|
|
4531
4764
|
accumulate(calls, result.calls, id);
|
|
4532
4765
|
accumulate(tokens, result.tokens, id);
|
|
4533
4766
|
}
|
|
4534
|
-
const runDirs = (await
|
|
4767
|
+
const runDirs = (await readdir4(root, { withFileTypes: true })).filter((item) => item.isDirectory()).map((item) => item.name).sort();
|
|
4535
4768
|
const legs = evidence.filter((entry) => entry.kind === "session").map((entry) => entry.id);
|
|
4536
4769
|
const retryDirs = runDirs.filter((name) => /(?:^|[-_])retry(?:[-_]|$)/i.test(name));
|
|
4537
4770
|
const rawBytes = evidence.filter((entry) => entry.kind === "session").reduce((sum, entry) => sum + entry.byteLength, 0);
|
|
@@ -4758,7 +4991,7 @@ var init_git_object_id = __esm({
|
|
|
4758
4991
|
|
|
4759
4992
|
// src/merger-git-state.ts
|
|
4760
4993
|
import { execFile as execFile2 } from "node:child_process";
|
|
4761
|
-
import { access as access2, readFile as
|
|
4994
|
+
import { access as access2, readFile as readFile9 } from "node:fs/promises";
|
|
4762
4995
|
import { constants as fsConstants } from "node:fs";
|
|
4763
4996
|
import { isAbsolute as isAbsolute4, resolve as resolve7 } from "node:path";
|
|
4764
4997
|
import { promisify as promisify2 } from "node:util";
|
|
@@ -4828,7 +5061,7 @@ function createProductionMergerGitState(repositoryRoot = process.cwd()) {
|
|
|
4828
5061
|
const mergeHeadPath = isAbsolute4(mergeHeadReported) ? mergeHeadReported : resolve7(repositoryRoot, mergeHeadReported);
|
|
4829
5062
|
let sourceObjectId = "";
|
|
4830
5063
|
if (await pathExists(mergeHeadPath)) {
|
|
4831
|
-
const raw = exactUtf8(await
|
|
5064
|
+
const raw = exactUtf8(await readFile9(mergeHeadPath), "Git MERGE_HEAD");
|
|
4832
5065
|
const mergeHeads = raw.trim().split(/\r?\n/).map((row) => row.trim()).filter(Boolean);
|
|
4833
5066
|
if (mergeHeads.length === 0) throw new Error("Git MERGE_HEAD is empty");
|
|
4834
5067
|
if (mergeHeads.length !== 1) throw new Error("Assigned repository does not have one ordinary in-progress merge");
|
|
@@ -4880,10 +5113,10 @@ var init_uuidv7 = __esm({
|
|
|
4880
5113
|
});
|
|
4881
5114
|
|
|
4882
5115
|
// src/typed-provider-http.ts
|
|
4883
|
-
import { readFile as
|
|
4884
|
-
import { join as
|
|
5116
|
+
import { readFile as readFile10, unlink, writeFile as writeFile3 } from "node:fs/promises";
|
|
5117
|
+
import { join as join13 } from "node:path";
|
|
4885
5118
|
function typedProviderHttpPath(runDirectory) {
|
|
4886
|
-
return
|
|
5119
|
+
return join13(runDirectory, TYPED_HTTP_FILE);
|
|
4887
5120
|
}
|
|
4888
5121
|
async function clearTypedProviderHttpObservation(runDirectory) {
|
|
4889
5122
|
try {
|
|
@@ -4914,7 +5147,7 @@ async function recordTypedProviderHttpStatus(runDirectory, observation) {
|
|
|
4914
5147
|
async function readLatestTypedProviderHttpObservation(runDirectory) {
|
|
4915
5148
|
let text;
|
|
4916
5149
|
try {
|
|
4917
|
-
text = await
|
|
5150
|
+
text = await readFile10(typedProviderHttpPath(runDirectory), "utf8");
|
|
4918
5151
|
} catch (error) {
|
|
4919
5152
|
if (error instanceof Error && "code" in error && error.code === "ENOENT") {
|
|
4920
5153
|
return void 0;
|
|
@@ -4993,8 +5226,8 @@ __export(run_lifecycle_exports, {
|
|
|
4993
5226
|
selectResumeContinuationPrompt: () => selectResumeContinuationPrompt,
|
|
4994
5227
|
writeRoleRunState: () => writeRoleRunState
|
|
4995
5228
|
});
|
|
4996
|
-
import { chmod, lstat as lstat2, open, readdir as
|
|
4997
|
-
import { basename as
|
|
5229
|
+
import { chmod, lstat as lstat2, open, readdir as readdir5, readFile as readFile11, unlink as unlink2, writeFile as writeFile4 } from "node:fs/promises";
|
|
5230
|
+
import { basename as basename5, join as join14 } from "node:path";
|
|
4998
5231
|
function selectResumeContinuationPrompt(message, engineMaterial) {
|
|
4999
5232
|
const lines = message !== void 0 ? [message] : [];
|
|
5000
5233
|
return appendEngineSessionMaterial(lines, engineMaterial).join("\n");
|
|
@@ -5033,7 +5266,7 @@ function renderResumeCommand(runId) {
|
|
|
5033
5266
|
async function writeRoleRunState(runDirectory, record4) {
|
|
5034
5267
|
const payload = { ...record4, runDirectory };
|
|
5035
5268
|
await writeFile4(
|
|
5036
|
-
|
|
5269
|
+
join14(runDirectory, RUN_STATE_FILE),
|
|
5037
5270
|
`${JSON.stringify(payload, null, 2)}
|
|
5038
5271
|
`,
|
|
5039
5272
|
"utf8"
|
|
@@ -5083,7 +5316,7 @@ function parseCurrentCourtState(raw) {
|
|
|
5083
5316
|
async function readRoleRunStateDisk(runDirectory) {
|
|
5084
5317
|
let raw;
|
|
5085
5318
|
try {
|
|
5086
|
-
raw = JSON.parse(await
|
|
5319
|
+
raw = JSON.parse(await readFile11(join14(runDirectory, RUN_STATE_FILE), "utf8"));
|
|
5087
5320
|
} catch (error) {
|
|
5088
5321
|
if (errorCodeOf2(error) === "ENOENT") return void 0;
|
|
5089
5322
|
throw error;
|
|
@@ -5151,7 +5384,7 @@ async function writeRoleRunStateDisk(runDirectory, disk) {
|
|
|
5151
5384
|
...disk.currentCourt === void 0 ? {} : { currentCourt: disk.currentCourt }
|
|
5152
5385
|
};
|
|
5153
5386
|
await writeFile4(
|
|
5154
|
-
|
|
5387
|
+
join14(runDirectory, RUN_STATE_FILE),
|
|
5155
5388
|
`${JSON.stringify(payload, null, 2)}
|
|
5156
5389
|
`,
|
|
5157
5390
|
"utf8"
|
|
@@ -5323,7 +5556,7 @@ function isProcessAlive(pid) {
|
|
|
5323
5556
|
async function autopsyWriterLock(lockPath) {
|
|
5324
5557
|
let content;
|
|
5325
5558
|
try {
|
|
5326
|
-
content = await
|
|
5559
|
+
content = await readFile11(lockPath, "utf8");
|
|
5327
5560
|
} catch (error) {
|
|
5328
5561
|
if (errorCodeOf2(error) === "ENOENT") return { verdict: "absent" };
|
|
5329
5562
|
return { verdict: "unknown", reason: "unreadable", readFailure: error };
|
|
@@ -5382,7 +5615,7 @@ async function createWriterLease(lockPath, runDirectory, reportCleanupFailure) {
|
|
|
5382
5615
|
},
|
|
5383
5616
|
relocate(nextRunDirectory) {
|
|
5384
5617
|
currentRunDirectory = nextRunDirectory;
|
|
5385
|
-
currentLockPath =
|
|
5618
|
+
currentLockPath = join14(nextRunDirectory, WRITER_LOCK_FILE);
|
|
5386
5619
|
},
|
|
5387
5620
|
async release() {
|
|
5388
5621
|
if (released) return;
|
|
@@ -5421,10 +5654,10 @@ async function acquireRunWriterLease(runDirectory, onCleanupFailure) {
|
|
|
5421
5654
|
};
|
|
5422
5655
|
const reportReadFailure = (error) => {
|
|
5423
5656
|
reportDiagnostic(
|
|
5424
|
-
`writer lease lock read failed (holder liveness unverifiable; lock left in place) at ${
|
|
5657
|
+
`writer lease lock read failed (holder liveness unverifiable; lock left in place) at ${join14(runDirectory, WRITER_LOCK_FILE)}: ${describeErrorIdentity(error)}`
|
|
5425
5658
|
);
|
|
5426
5659
|
};
|
|
5427
|
-
const lockPath =
|
|
5660
|
+
const lockPath = join14(runDirectory, WRITER_LOCK_FILE);
|
|
5428
5661
|
let lastAutopsy = { verdict: "absent" };
|
|
5429
5662
|
let lastReclaimFailure;
|
|
5430
5663
|
for (let reclaimsLeft = WRITER_LEASE_RECLAIM_ROUNDS; ; reclaimsLeft -= 1) {
|
|
@@ -5479,10 +5712,10 @@ async function acquireRunWriterLease(runDirectory, onCleanupFailure) {
|
|
|
5479
5712
|
async function findRunDirectoryById(home, runId, onlyBookKey, onlyRole) {
|
|
5480
5713
|
if (runId.trim() === "") return void 0;
|
|
5481
5714
|
const ledgerHome = resolveActivationLedgerHome(home);
|
|
5482
|
-
const booksRoot =
|
|
5715
|
+
const booksRoot = join14(ledgerHome, "books");
|
|
5483
5716
|
let bookKeys;
|
|
5484
5717
|
try {
|
|
5485
|
-
bookKeys = await
|
|
5718
|
+
bookKeys = await readdir5(booksRoot);
|
|
5486
5719
|
} catch (error) {
|
|
5487
5720
|
if (errorCodeOf2(error) === "ENOENT") return void 0;
|
|
5488
5721
|
throw error;
|
|
@@ -5499,7 +5732,7 @@ async function findRunDirectoryById(home, runId, onlyBookKey, onlyRole) {
|
|
|
5499
5732
|
throw error;
|
|
5500
5733
|
}
|
|
5501
5734
|
for (const runDirectory of runDirectories) {
|
|
5502
|
-
const entry =
|
|
5735
|
+
const entry = basename5(runDirectory);
|
|
5503
5736
|
if (onlyRole === void 0 && (entry === `${runId}@judge` || entry.startsWith(`${runId}@`)) || entry === `${runId}@${onlyRole}`) {
|
|
5504
5737
|
matches.push(runDirectory);
|
|
5505
5738
|
}
|
|
@@ -5520,7 +5753,7 @@ async function readRunParentPath(runDirectory) {
|
|
|
5520
5753
|
let raw;
|
|
5521
5754
|
try {
|
|
5522
5755
|
raw = JSON.parse(
|
|
5523
|
-
await
|
|
5756
|
+
await readFile11(join14(runDirectory, "admitted-request.json"), "utf8")
|
|
5524
5757
|
);
|
|
5525
5758
|
} catch (error) {
|
|
5526
5759
|
if (errorCodeOf2(error) === "ENOENT") return void 0;
|
|
@@ -5541,7 +5774,7 @@ async function readRunParentPath(runDirectory) {
|
|
|
5541
5774
|
async function runHasFormedSessionPrincipal(runDirectory) {
|
|
5542
5775
|
const disk = await readRoleRunStateDisk(runDirectory);
|
|
5543
5776
|
if (disk === void 0) return false;
|
|
5544
|
-
const sessionFile = typeof disk.principalWire.sessionFile === "string" && disk.principalWire.sessionFile.trim() !== "" ? disk.principalWire.sessionFile :
|
|
5777
|
+
const sessionFile = typeof disk.principalWire.sessionFile === "string" && disk.principalWire.sessionFile.trim() !== "" ? disk.principalWire.sessionFile : join14(disk.principalWire.sessionDirectory, "session.jsonl");
|
|
5545
5778
|
try {
|
|
5546
5779
|
const stat2 = await lstat2(sessionFile);
|
|
5547
5780
|
return stat2.isFile() && !stat2.isSymbolicLink();
|
|
@@ -5566,7 +5799,7 @@ async function findLatestRunIdForSeatTicket(input) {
|
|
|
5566
5799
|
const suffix = `@${input.role}`;
|
|
5567
5800
|
let best;
|
|
5568
5801
|
for (const runDirectory of runDirectories) {
|
|
5569
|
-
const entry =
|
|
5802
|
+
const entry = basename5(runDirectory);
|
|
5570
5803
|
if (!entry.endsWith(suffix)) continue;
|
|
5571
5804
|
const runId = entry.slice(0, entry.length - suffix.length);
|
|
5572
5805
|
if (runId.length === 0) continue;
|
|
@@ -5689,7 +5922,7 @@ async function loadResumableRunRecord(home, runId, authority) {
|
|
|
5689
5922
|
let sourceRun;
|
|
5690
5923
|
try {
|
|
5691
5924
|
const raw = JSON.parse(
|
|
5692
|
-
await
|
|
5925
|
+
await readFile11(run.admittedRequestPath, "utf8")
|
|
5693
5926
|
);
|
|
5694
5927
|
if (raw !== null && typeof raw === "object" && !Array.isArray(raw)) {
|
|
5695
5928
|
const record4 = raw;
|
|
@@ -5807,7 +6040,7 @@ async function loadResumableRunRecord(home, runId, authority) {
|
|
|
5807
6040
|
let model;
|
|
5808
6041
|
try {
|
|
5809
6042
|
const invocationRaw = JSON.parse(
|
|
5810
|
-
await
|
|
6043
|
+
await readFile11(join14(run.runDirectory, "invocation.json"), "utf8")
|
|
5811
6044
|
);
|
|
5812
6045
|
if (invocationRaw !== null && typeof invocationRaw === "object" && !Array.isArray(invocationRaw)) {
|
|
5813
6046
|
const rec = invocationRaw;
|
|
@@ -6276,7 +6509,7 @@ __export(notary_source_run_exports, {
|
|
|
6276
6509
|
loadNotarySourceRunLocator: () => loadNotarySourceRunLocator,
|
|
6277
6510
|
resolveNotarySourceRunLocator: () => resolveNotarySourceRunLocator
|
|
6278
6511
|
});
|
|
6279
|
-
import { dirname as
|
|
6512
|
+
import { dirname as dirname9, isAbsolute as isAbsolute6, join as join15, resolve as resolve8, basename as basename6 } from "node:path";
|
|
6280
6513
|
import { lstat as lstat3, realpath as realpath4 } from "node:fs/promises";
|
|
6281
6514
|
function parseRunDirectoryName(name) {
|
|
6282
6515
|
const match = RUN_DIR_NAME.exec(name);
|
|
@@ -6307,10 +6540,10 @@ async function requireRunDirectory(candidate, display) {
|
|
|
6307
6540
|
`notary --source-run must be a run directory: ${display}`
|
|
6308
6541
|
);
|
|
6309
6542
|
}
|
|
6310
|
-
const identity = parseRunDirectoryName(
|
|
6543
|
+
const identity = parseRunDirectoryName(basename6(real));
|
|
6311
6544
|
if (identity === void 0) {
|
|
6312
6545
|
throw new NotarySourceRunError(
|
|
6313
|
-
`notary --source-run must be named <runId>@<role>: ${
|
|
6546
|
+
`notary --source-run must be named <runId>@<role>: ${basename6(real)}`
|
|
6314
6547
|
);
|
|
6315
6548
|
}
|
|
6316
6549
|
return real;
|
|
@@ -6322,20 +6555,20 @@ async function resolveNotarySourceRunLocator(options) {
|
|
|
6322
6555
|
}
|
|
6323
6556
|
const ledgerHome = resolveActivationLedgerHome(options.home);
|
|
6324
6557
|
const bookKey = resolveBookKeyFromGit(options.projectRoot);
|
|
6325
|
-
const bookRunsRoot =
|
|
6558
|
+
const bookRunsRoot = join15(activationBookDirectory(ledgerHome, bookKey), "runs");
|
|
6326
6559
|
let candidate;
|
|
6327
6560
|
const bare = parseRunDirectoryName(raw);
|
|
6328
6561
|
if (bare !== void 0 && !raw.includes("/") && !raw.includes("\\")) {
|
|
6329
|
-
candidate = await findRunDirectoryById(options.home, bare.runId, bookKey, bare.role) ??
|
|
6562
|
+
candidate = await findRunDirectoryById(options.home, bare.runId, bookKey, bare.role) ?? join15(bookRunsRoot, `${bare.runId}@${bare.role}`);
|
|
6330
6563
|
} else {
|
|
6331
6564
|
candidate = isAbsolute6(raw) ? raw : resolve8(options.projectRoot, raw);
|
|
6332
6565
|
}
|
|
6333
6566
|
const real = await requireRunDirectory(candidate, raw);
|
|
6334
|
-
const identity = parseRunDirectoryName(
|
|
6567
|
+
const identity = parseRunDirectoryName(basename6(real));
|
|
6335
6568
|
const bookIdentity = physicalPathIdentity(activationBookDirectory(ledgerHome, bookKey));
|
|
6336
|
-
const parentIdentity = physicalPathIdentity(
|
|
6337
|
-
const subjectBookIdentity = physicalPathIdentity(
|
|
6338
|
-
if (parentIdentity !== physicalPathIdentity(bookRunsRoot) && !(
|
|
6569
|
+
const parentIdentity = physicalPathIdentity(dirname9(real));
|
|
6570
|
+
const subjectBookIdentity = physicalPathIdentity(dirname9(dirname9(dirname9(real))));
|
|
6571
|
+
if (parentIdentity !== physicalPathIdentity(bookRunsRoot) && !(basename6(dirname9(real)) === "runs" && subjectBookIdentity === bookIdentity)) {
|
|
6339
6572
|
throw new NotarySourceRunError(
|
|
6340
6573
|
"notary --source-run must resolve to a retained run under the project machine-ledger book"
|
|
6341
6574
|
);
|
|
@@ -6369,7 +6602,7 @@ async function resolveNotarySourceRunLocator(options) {
|
|
|
6369
6602
|
}
|
|
6370
6603
|
async function loadNotarySourceRunLocator(path) {
|
|
6371
6604
|
const real = await requireRunDirectory(path, path);
|
|
6372
|
-
const identity = parseRunDirectoryName(
|
|
6605
|
+
const identity = parseRunDirectoryName(basename6(real));
|
|
6373
6606
|
const runState = await readRoleRunIdentity(real);
|
|
6374
6607
|
if (runState === void 0) {
|
|
6375
6608
|
throw new NotarySourceRunError(
|
|
@@ -7518,14 +7751,14 @@ import { existsSync as existsSync5 } from "node:fs";
|
|
|
7518
7751
|
import {
|
|
7519
7752
|
lstat as lstat4,
|
|
7520
7753
|
mkdtemp as mkdtemp2,
|
|
7521
|
-
readFile as
|
|
7754
|
+
readFile as readFile12,
|
|
7522
7755
|
realpath as realpath5,
|
|
7523
7756
|
rename,
|
|
7524
7757
|
rm as rm2,
|
|
7525
7758
|
writeFile as writeFile5
|
|
7526
7759
|
} from "node:fs/promises";
|
|
7527
7760
|
import { tmpdir as tmpdir2 } from "node:os";
|
|
7528
|
-
import { basename as
|
|
7761
|
+
import { basename as basename7, dirname as dirname10, isAbsolute as isAbsolute7, join as join16, resolve as resolve9, sep as sep4 } from "node:path";
|
|
7529
7762
|
function issueAdmissionPlacement(authority, request) {
|
|
7530
7763
|
const ledgerHome = resolveActivationLedgerHome(request.home);
|
|
7531
7764
|
const bookKey = resolveBookKeyFromGit(request.cwd);
|
|
@@ -7579,15 +7812,15 @@ async function writeRoleInvocationLedger(source, role, effectiveModel) {
|
|
|
7579
7812
|
...effectiveModelLedgerFields(effectiveModel)
|
|
7580
7813
|
};
|
|
7581
7814
|
await writeFile5(
|
|
7582
|
-
|
|
7815
|
+
join16(source.runDirectory, "invocation.json"),
|
|
7583
7816
|
`${JSON.stringify(identity, null, 2)}
|
|
7584
7817
|
`,
|
|
7585
7818
|
"utf8"
|
|
7586
7819
|
);
|
|
7587
7820
|
}
|
|
7588
7821
|
async function recordEffectiveInvocationModel(runDirectory, model, engine, host, engineModel) {
|
|
7589
|
-
const ledgerPath =
|
|
7590
|
-
const current = JSON.parse(await
|
|
7822
|
+
const ledgerPath = join16(runDirectory, "invocation.json");
|
|
7823
|
+
const current = JSON.parse(await readFile12(ledgerPath, "utf8"));
|
|
7591
7824
|
const next = { ...current };
|
|
7592
7825
|
if (model !== void 0) {
|
|
7593
7826
|
next.provider = model.provider;
|
|
@@ -7619,8 +7852,8 @@ async function recordEffectiveInvocationModel(runDirectory, model, engine, host,
|
|
|
7619
7852
|
);
|
|
7620
7853
|
}
|
|
7621
7854
|
async function mergeInvocationIdentityPage(runDirectory, fields) {
|
|
7622
|
-
const ledgerPath =
|
|
7623
|
-
const current = JSON.parse(await
|
|
7855
|
+
const ledgerPath = join16(runDirectory, "invocation.json");
|
|
7856
|
+
const current = JSON.parse(await readFile12(ledgerPath, "utf8"));
|
|
7624
7857
|
await writeFile5(
|
|
7625
7858
|
ledgerPath,
|
|
7626
7859
|
`${JSON.stringify({
|
|
@@ -7636,7 +7869,7 @@ async function persistAdmittedSourceRunPath(admitted, sourceRunPath) {
|
|
|
7636
7869
|
throw new Error("persistAdmittedSourceRunPath requires a non-empty sourceRunPath");
|
|
7637
7870
|
}
|
|
7638
7871
|
const admittedPath = admitted.admittedRequestPath;
|
|
7639
|
-
const current = JSON.parse(await
|
|
7872
|
+
const current = JSON.parse(await readFile12(admittedPath, "utf8"));
|
|
7640
7873
|
if (typeof current.sourceRunPath === "string") {
|
|
7641
7874
|
if (current.sourceRunPath === sourceRunPath) return;
|
|
7642
7875
|
throw new Error(
|
|
@@ -7662,7 +7895,7 @@ async function bindAdmittedTicketNumber(admitted, ticketNumber) {
|
|
|
7662
7895
|
}
|
|
7663
7896
|
async function recordAdmittedCorrelation(admitted, correlationId) {
|
|
7664
7897
|
const current = JSON.parse(
|
|
7665
|
-
await
|
|
7898
|
+
await readFile12(admitted.admittedRequestPath, "utf8")
|
|
7666
7899
|
);
|
|
7667
7900
|
const prior = [
|
|
7668
7901
|
...Array.isArray(current.correlationIds) ? current.correlationIds.filter(
|
|
@@ -7710,7 +7943,7 @@ async function bindCourtTicketNumbersOnAdmitted(admitted, courtTicketNumbers) {
|
|
|
7710
7943
|
}
|
|
7711
7944
|
const frozen = Object.freeze([...projected]);
|
|
7712
7945
|
const admittedPath = admitted.admittedRequestPath;
|
|
7713
|
-
const current = JSON.parse(await
|
|
7946
|
+
const current = JSON.parse(await readFile12(admittedPath, "utf8"));
|
|
7714
7947
|
await writeFile5(
|
|
7715
7948
|
admittedPath,
|
|
7716
7949
|
`${JSON.stringify({ ...current, courtTicketNumbers: frozen }, null, 2)}
|
|
@@ -7732,7 +7965,7 @@ async function relocateAdmittedRunToTicket(admitted, authority, heldLease) {
|
|
|
7732
7965
|
runId: admitted.runId,
|
|
7733
7966
|
role: admitted.role
|
|
7734
7967
|
});
|
|
7735
|
-
ensureRoleRunDirectory(ledgerHome,
|
|
7968
|
+
ensureRoleRunDirectory(ledgerHome, dirname10(target.runDirectory));
|
|
7736
7969
|
await rename(oldRunDirectory, target.runDirectory);
|
|
7737
7970
|
heldLease?.relocate(target.runDirectory);
|
|
7738
7971
|
const admittedRecord = admitted;
|
|
@@ -7770,9 +8003,9 @@ async function bindTicketNumberOnRunDirectory(runDirectory, ticketNumber) {
|
|
|
7770
8003
|
ticketNumber,
|
|
7771
8004
|
"bindTicketNumberOnRunDirectory"
|
|
7772
8005
|
);
|
|
7773
|
-
const admittedPath =
|
|
7774
|
-
const invocationPath =
|
|
7775
|
-
const admitted = JSON.parse(await
|
|
8006
|
+
const admittedPath = join16(runDirectory, "admitted-request.json");
|
|
8007
|
+
const invocationPath = join16(runDirectory, "invocation.json");
|
|
8008
|
+
const admitted = JSON.parse(await readFile12(admittedPath, "utf8"));
|
|
7776
8009
|
const existing = admitted.ticketNumber;
|
|
7777
8010
|
if (typeof existing === "number") {
|
|
7778
8011
|
if (existing === ticketNumber) return;
|
|
@@ -7782,7 +8015,7 @@ async function bindTicketNumberOnRunDirectory(runDirectory, ticketNumber) {
|
|
|
7782
8015
|
}
|
|
7783
8016
|
if (existsSync5(invocationPath)) {
|
|
7784
8017
|
const invocation = JSON.parse(
|
|
7785
|
-
await
|
|
8018
|
+
await readFile12(invocationPath, "utf8")
|
|
7786
8019
|
);
|
|
7787
8020
|
if (typeof invocation.ticketNumber === "number" && invocation.ticketNumber !== ticketNumber) {
|
|
7788
8021
|
throw new Error(
|
|
@@ -7807,7 +8040,7 @@ async function recordLaunchedPiIdentity(runDirectory, identity) {
|
|
|
7807
8040
|
async function observeLaunchedRolePackageIdentity(packageRoot, selectedRoleEntry) {
|
|
7808
8041
|
const rolePackageRoot = packageRoot;
|
|
7809
8042
|
const raw = JSON.parse(
|
|
7810
|
-
await
|
|
8043
|
+
await readFile12(join16(rolePackageRoot, "package.json"), "utf8")
|
|
7811
8044
|
);
|
|
7812
8045
|
if (typeof raw.version !== "string" || raw.version.trim() === "") {
|
|
7813
8046
|
throw new Error(
|
|
@@ -8092,7 +8325,7 @@ async function readRegularFileAttachment(sourcePath) {
|
|
|
8092
8325
|
);
|
|
8093
8326
|
}
|
|
8094
8327
|
try {
|
|
8095
|
-
return { absolute, bytes: await
|
|
8328
|
+
return { absolute, bytes: await readFile12(absolute) };
|
|
8096
8329
|
} catch (error) {
|
|
8097
8330
|
throw new CliUsageError(
|
|
8098
8331
|
`attachment is not a readable regular file: ${sourcePath}`,
|
|
@@ -8105,13 +8338,13 @@ async function removePreparedAttachmentDirectory(stagingDirectory) {
|
|
|
8105
8338
|
}
|
|
8106
8339
|
async function withPreparedAttachments(attachmentPaths, use) {
|
|
8107
8340
|
if (attachmentPaths.length === 0) return await use([]);
|
|
8108
|
-
const stagingDirectory = await mkdtemp2(
|
|
8341
|
+
const stagingDirectory = await mkdtemp2(join16(tmpdir2(), "ak-role-attachments-"));
|
|
8109
8342
|
const prepared = [];
|
|
8110
8343
|
let result;
|
|
8111
8344
|
try {
|
|
8112
8345
|
for (let index = 0; index < attachmentPaths.length; index += 1) {
|
|
8113
8346
|
const { absolute, bytes } = await readRegularFileAttachment(attachmentPaths[index]);
|
|
8114
|
-
const snapshotPath =
|
|
8347
|
+
const snapshotPath = join16(stagingDirectory, String(index).padStart(6, "0"));
|
|
8115
8348
|
await writeFile5(snapshotPath, bytes);
|
|
8116
8349
|
prepared.push({ absolute, snapshotPath });
|
|
8117
8350
|
}
|
|
@@ -8132,9 +8365,9 @@ async function withPreparedAttachments(attachmentPaths, use) {
|
|
|
8132
8365
|
return result;
|
|
8133
8366
|
}
|
|
8134
8367
|
async function freezeAttachmentBytes(provenancePath, bytes, destinationDir, index) {
|
|
8135
|
-
const frozenPath =
|
|
8368
|
+
const frozenPath = join16(
|
|
8136
8369
|
destinationDir,
|
|
8137
|
-
`${String(index).padStart(2, "0")}-${
|
|
8370
|
+
`${String(index).padStart(2, "0")}-${basename7(provenancePath)}`
|
|
8138
8371
|
);
|
|
8139
8372
|
await writeFile5(frozenPath, bytes);
|
|
8140
8373
|
return {
|
|
@@ -8148,7 +8381,7 @@ async function freezeAttachmentBytes(provenancePath, bytes, destinationDir, inde
|
|
|
8148
8381
|
async function freezePreparedAttachment(prepared, destinationDir, index) {
|
|
8149
8382
|
return freezeAttachmentBytes(
|
|
8150
8383
|
prepared.absolute,
|
|
8151
|
-
await
|
|
8384
|
+
await readFile12(prepared.snapshotPath),
|
|
8152
8385
|
destinationDir,
|
|
8153
8386
|
index
|
|
8154
8387
|
);
|
|
@@ -8175,14 +8408,14 @@ async function freezeAttachments(attachmentPaths, attachmentsDirectory) {
|
|
|
8175
8408
|
async function freezeAttachmentsIntoRun(attachmentPaths, runDirectory, summonsKey = `s-${Date.now().toString(36)}`) {
|
|
8176
8409
|
if (attachmentPaths.length === 0) return [];
|
|
8177
8410
|
const ledgerHome = resolveActivationLedgerHome(homeFromRunDirectory(runDirectory));
|
|
8178
|
-
const attachmentsDirectory =
|
|
8411
|
+
const attachmentsDirectory = join16(runDirectory, "attachments", summonsKey);
|
|
8179
8412
|
ensureRealDirectoryTree(ledgerHome, attachmentsDirectory);
|
|
8180
8413
|
return freezeAttachments(attachmentPaths, attachmentsDirectory);
|
|
8181
8414
|
}
|
|
8182
8415
|
async function freezePreparedAttachmentsIntoRun(prepared, runDirectory, summonsKey) {
|
|
8183
8416
|
if (prepared.length === 0) return [];
|
|
8184
8417
|
const ledgerHome = resolveActivationLedgerHome(homeFromRunDirectory(runDirectory));
|
|
8185
|
-
const attachmentsDirectory = summonsKey === void 0 ?
|
|
8418
|
+
const attachmentsDirectory = summonsKey === void 0 ? join16(runDirectory, "attachments") : join16(runDirectory, "attachments", summonsKey);
|
|
8186
8419
|
ensureRealDirectoryTree(ledgerHome, attachmentsDirectory);
|
|
8187
8420
|
const attachments = [];
|
|
8188
8421
|
for (let index = 0; index < prepared.length; index += 1) {
|
|
@@ -8244,7 +8477,7 @@ async function admitStandardMaterialInvocation(role, options) {
|
|
|
8244
8477
|
})),
|
|
8245
8478
|
...ticketFields
|
|
8246
8479
|
};
|
|
8247
|
-
const admittedRequestPath =
|
|
8480
|
+
const admittedRequestPath = join16(runDirectory, "admitted-request.json");
|
|
8248
8481
|
await writeAdmittedRequestPersistence(admittedRequestPath, admitted, {
|
|
8249
8482
|
sessionDirectory,
|
|
8250
8483
|
sessionFile
|
|
@@ -8353,7 +8586,7 @@ async function admitCountersignInvocation(options) {
|
|
|
8353
8586
|
mediaKind: a.mediaKind
|
|
8354
8587
|
}))
|
|
8355
8588
|
};
|
|
8356
|
-
const admittedRequestPath =
|
|
8589
|
+
const admittedRequestPath = join16(runDirectory, "admitted-request.json");
|
|
8357
8590
|
if (options.deferPersistence !== true) {
|
|
8358
8591
|
await writeAdmittedRequestPersistence(admittedRequestPath, admitted, {
|
|
8359
8592
|
sessionDirectory,
|
|
@@ -8404,7 +8637,7 @@ function buildCountersignTransportPrompt(admitted, engineMaterial) {
|
|
|
8404
8637
|
async function loadAdmittedJudgeRequest(runDirectory) {
|
|
8405
8638
|
try {
|
|
8406
8639
|
const raw = JSON.parse(
|
|
8407
|
-
await
|
|
8640
|
+
await readFile12(join16(runDirectory, "admitted-request.json"), "utf8")
|
|
8408
8641
|
);
|
|
8409
8642
|
if (raw === null || typeof raw !== "object" || Array.isArray(raw)) return void 0;
|
|
8410
8643
|
const record4 = raw;
|
|
@@ -8459,7 +8692,7 @@ async function admitCoderInvocation(options) {
|
|
|
8459
8692
|
home: options.home
|
|
8460
8693
|
});
|
|
8461
8694
|
const attachments = await freezeAttachments(options.attachmentPaths, attachmentsDirectory);
|
|
8462
|
-
const taskPath =
|
|
8695
|
+
const taskPath = join16(runDirectory, "task.md");
|
|
8463
8696
|
await writeFile5(taskPath, instruction, "utf8");
|
|
8464
8697
|
const admitted = {
|
|
8465
8698
|
role: "coder",
|
|
@@ -8480,7 +8713,7 @@ async function admitCoderInvocation(options) {
|
|
|
8480
8713
|
mediaKind: a.mediaKind
|
|
8481
8714
|
}))
|
|
8482
8715
|
};
|
|
8483
|
-
const admittedRequestPath =
|
|
8716
|
+
const admittedRequestPath = join16(runDirectory, "admitted-request.json");
|
|
8484
8717
|
await writeAdmittedRequestPersistence(admittedRequestPath, admitted, {
|
|
8485
8718
|
sessionDirectory,
|
|
8486
8719
|
sessionFile
|
|
@@ -8530,7 +8763,7 @@ async function admitFixerInvocation(options) {
|
|
|
8530
8763
|
if (options.prerequisitesPath !== void 0) {
|
|
8531
8764
|
const absolutePrereq = isAbsolute7(options.prerequisitesPath) ? options.prerequisitesPath : resolve9(options.prerequisitesPath);
|
|
8532
8765
|
try {
|
|
8533
|
-
prerequisitesSource = await
|
|
8766
|
+
prerequisitesSource = await readFile12(absolutePrereq, "utf8");
|
|
8534
8767
|
} catch (error) {
|
|
8535
8768
|
throw new CliUsageError(
|
|
8536
8769
|
`fixer prerequisites path is unreadable: ${options.prerequisitesPath}`,
|
|
@@ -8566,7 +8799,7 @@ async function admitFixerInvocation(options) {
|
|
|
8566
8799
|
const attachments = await freezeAttachments(options.attachmentPaths, attachmentsDirectory);
|
|
8567
8800
|
let prerequisitesPath;
|
|
8568
8801
|
if (prerequisitesSource !== void 0) {
|
|
8569
|
-
prerequisitesPath =
|
|
8802
|
+
prerequisitesPath = join16(runDirectory, "prerequisites.json");
|
|
8570
8803
|
await writeFile5(
|
|
8571
8804
|
prerequisitesPath,
|
|
8572
8805
|
`${JSON.stringify(prerequisites, null, 2)}
|
|
@@ -8574,7 +8807,7 @@ async function admitFixerInvocation(options) {
|
|
|
8574
8807
|
"utf8"
|
|
8575
8808
|
);
|
|
8576
8809
|
}
|
|
8577
|
-
const packetPath =
|
|
8810
|
+
const packetPath = join16(runDirectory, "fix-packet.md");
|
|
8578
8811
|
await writeFile5(packetPath, instruction, "utf8");
|
|
8579
8812
|
const admitted = {
|
|
8580
8813
|
role: "fixer",
|
|
@@ -8600,7 +8833,7 @@ async function admitFixerInvocation(options) {
|
|
|
8600
8833
|
mediaKind: a.mediaKind
|
|
8601
8834
|
}))
|
|
8602
8835
|
};
|
|
8603
|
-
const admittedRequestPath =
|
|
8836
|
+
const admittedRequestPath = join16(runDirectory, "admitted-request.json");
|
|
8604
8837
|
await writeAdmittedRequestPersistence(admittedRequestPath, admitted, {
|
|
8605
8838
|
sessionDirectory,
|
|
8606
8839
|
sessionFile
|
|
@@ -8820,7 +9053,7 @@ async function admitCollectorInvocation(options) {
|
|
|
8820
9053
|
const prNumber = target.kind === "bound" ? target.prNumber : void 0;
|
|
8821
9054
|
let requestManifestPath;
|
|
8822
9055
|
if (manifestCanonicalJson !== void 0) {
|
|
8823
|
-
requestManifestPath =
|
|
9056
|
+
requestManifestPath = join16(runDirectory, "request-manifest.json");
|
|
8824
9057
|
await writeFile5(requestManifestPath, manifestCanonicalJson, "utf8");
|
|
8825
9058
|
}
|
|
8826
9059
|
const admitted = {
|
|
@@ -8846,7 +9079,7 @@ async function admitCollectorInvocation(options) {
|
|
|
8846
9079
|
mediaKind: a.mediaKind
|
|
8847
9080
|
}))
|
|
8848
9081
|
};
|
|
8849
|
-
const admittedRequestPath =
|
|
9082
|
+
const admittedRequestPath = join16(runDirectory, "admitted-request.json");
|
|
8850
9083
|
await writeAdmittedRequestPersistence(admittedRequestPath, admitted, {
|
|
8851
9084
|
sessionDirectory,
|
|
8852
9085
|
sessionFile
|
|
@@ -8944,7 +9177,7 @@ function parseDoctorArgv(args) {
|
|
|
8944
9177
|
}
|
|
8945
9178
|
async function resolveDoctorCaseRunsPath(options) {
|
|
8946
9179
|
const ledgerHome = resolveActivationLedgerHome(options.home);
|
|
8947
|
-
const defaultRuns =
|
|
9180
|
+
const defaultRuns = join16(
|
|
8948
9181
|
activationBookDirectory(ledgerHome, options.bookKey),
|
|
8949
9182
|
String(options.issueNumber),
|
|
8950
9183
|
"runs"
|
|
@@ -9075,7 +9308,7 @@ async function admitDoctorInvocation(options) {
|
|
|
9075
9308
|
mediaKind: a.mediaKind
|
|
9076
9309
|
}))
|
|
9077
9310
|
};
|
|
9078
|
-
const admittedRequestPath =
|
|
9311
|
+
const admittedRequestPath = join16(runDirectory, "admitted-request.json");
|
|
9079
9312
|
await writeAdmittedRequestPersistence(admittedRequestPath, admitted, {
|
|
9080
9313
|
sessionDirectory,
|
|
9081
9314
|
sessionFile
|
|
@@ -9207,7 +9440,7 @@ async function admitNotaryInvocation(options) {
|
|
|
9207
9440
|
...ticketFields,
|
|
9208
9441
|
...options.correlationId === void 0 ? {} : { correlationId: options.correlationId }
|
|
9209
9442
|
};
|
|
9210
|
-
const admittedRequestPath =
|
|
9443
|
+
const admittedRequestPath = join16(runDirectory, "admitted-request.json");
|
|
9211
9444
|
await writeAdmittedRequestPersistence(admittedRequestPath, admitted, {
|
|
9212
9445
|
sessionDirectory,
|
|
9213
9446
|
sessionFile
|
|
@@ -9310,7 +9543,7 @@ async function admitGleanerLeftInvocation(options) {
|
|
|
9310
9543
|
attachments: [],
|
|
9311
9544
|
...options.correlationId === void 0 ? {} : { correlationId: options.correlationId }
|
|
9312
9545
|
};
|
|
9313
|
-
const admittedRequestPath =
|
|
9546
|
+
const admittedRequestPath = join16(runDirectory, "admitted-request.json");
|
|
9314
9547
|
await writeAdmittedRequestPersistence(admittedRequestPath, admitted, {
|
|
9315
9548
|
sessionDirectory,
|
|
9316
9549
|
sessionFile
|
|
@@ -9449,7 +9682,7 @@ async function admitReviewerInvocation(options) {
|
|
|
9449
9682
|
mediaKind: a.mediaKind
|
|
9450
9683
|
}))
|
|
9451
9684
|
};
|
|
9452
|
-
const admittedRequestPath =
|
|
9685
|
+
const admittedRequestPath = join16(runDirectory, "admitted-request.json");
|
|
9453
9686
|
await writeAdmittedRequestPersistence(admittedRequestPath, admitted, {
|
|
9454
9687
|
sessionDirectory,
|
|
9455
9688
|
sessionFile
|
|
@@ -9601,7 +9834,7 @@ async function admitMergerInvocation(options) {
|
|
|
9601
9834
|
resolutionScope: [...derived.resolutionScope],
|
|
9602
9835
|
authorizedChecks: []
|
|
9603
9836
|
});
|
|
9604
|
-
const mergerInputPath =
|
|
9837
|
+
const mergerInputPath = join16(runDirectory, "merger-input.json");
|
|
9605
9838
|
await writeFile5(
|
|
9606
9839
|
mergerInputPath,
|
|
9607
9840
|
`${JSON.stringify(mergerInput, null, 2)}
|
|
@@ -9632,7 +9865,7 @@ async function admitMergerInvocation(options) {
|
|
|
9632
9865
|
mediaKind: a.mediaKind
|
|
9633
9866
|
}))
|
|
9634
9867
|
};
|
|
9635
|
-
const admittedRequestPath =
|
|
9868
|
+
const admittedRequestPath = join16(runDirectory, "admitted-request.json");
|
|
9636
9869
|
await writeAdmittedRequestPersistence(admittedRequestPath, admitted, {
|
|
9637
9870
|
sessionDirectory,
|
|
9638
9871
|
sessionFile
|
|
@@ -9916,15 +10149,15 @@ var init_invocation = __esm({
|
|
|
9916
10149
|
|
|
9917
10150
|
// src/public-cli/load-production-acp-host.ts
|
|
9918
10151
|
import { existsSync as existsSync6 } from "node:fs";
|
|
9919
|
-
import { join as
|
|
10152
|
+
import { join as join17 } from "node:path";
|
|
9920
10153
|
import { pathToFileURL } from "node:url";
|
|
9921
10154
|
async function loadProductionAcpHostFactory(packageRoot, host) {
|
|
9922
10155
|
const description = lookupHostDescription(host);
|
|
9923
10156
|
if (description === void 0) {
|
|
9924
10157
|
throw new Error(`unregistered host: ${host}`);
|
|
9925
10158
|
}
|
|
9926
|
-
const built =
|
|
9927
|
-
const source =
|
|
10159
|
+
const built = join17(packageRoot, "dist/acp-host/production-host.js");
|
|
10160
|
+
const source = join17(packageRoot, "src/acp-host/production-host.ts");
|
|
9928
10161
|
const target = existsSync6(built) ? built : source;
|
|
9929
10162
|
const href = pathToFileURL(target).href;
|
|
9930
10163
|
const mod = await import(href);
|
|
@@ -9940,15 +10173,15 @@ var init_load_production_acp_host = __esm({
|
|
|
9940
10173
|
|
|
9941
10174
|
// src/public-cli/load-production-headless-host.ts
|
|
9942
10175
|
import { existsSync as existsSync7 } from "node:fs";
|
|
9943
|
-
import { join as
|
|
10176
|
+
import { join as join18 } from "node:path";
|
|
9944
10177
|
import { pathToFileURL as pathToFileURL2 } from "node:url";
|
|
9945
10178
|
async function loadProductionHeadlessHostFactory(packageRoot, host) {
|
|
9946
10179
|
const description = lookupHeadlessHostDescription(host);
|
|
9947
10180
|
if (description === void 0) {
|
|
9948
10181
|
throw new Error(`unregistered headless host: ${host}`);
|
|
9949
10182
|
}
|
|
9950
|
-
const built =
|
|
9951
|
-
const source =
|
|
10183
|
+
const built = join18(packageRoot, "dist/headless-host/production-host.js");
|
|
10184
|
+
const source = join18(packageRoot, "src/headless-host/production-host.ts");
|
|
9952
10185
|
const target = existsSync7(built) ? built : source;
|
|
9953
10186
|
const href = pathToFileURL2(target).href;
|
|
9954
10187
|
const mod = await import(href);
|
|
@@ -10197,8 +10430,8 @@ __export(config_exports, {
|
|
|
10197
10430
|
setPersistentSeatHost: () => setPersistentSeatHost,
|
|
10198
10431
|
validatePublicCliConfigAxes: () => validatePublicCliConfigAxes
|
|
10199
10432
|
});
|
|
10200
|
-
import { mkdir, readFile as
|
|
10201
|
-
import { dirname as
|
|
10433
|
+
import { mkdir, readFile as readFile13, writeFile as writeFile6 } from "node:fs/promises";
|
|
10434
|
+
import { dirname as dirname11, join as join19 } from "node:path";
|
|
10202
10435
|
function isGateOfficerSeat(value) {
|
|
10203
10436
|
return GATE_OFFICER_SEATS.includes(value);
|
|
10204
10437
|
}
|
|
@@ -10206,12 +10439,12 @@ function publicCliConfigPath(home) {
|
|
|
10206
10439
|
if (typeof home !== "string" || home.trim() === "") {
|
|
10207
10440
|
throw new Error("home must be explicitly provided");
|
|
10208
10441
|
}
|
|
10209
|
-
return
|
|
10442
|
+
return join19(home, ".ak-roles", "public-cli.json");
|
|
10210
10443
|
}
|
|
10211
10444
|
async function loadPublicCliConfig(home) {
|
|
10212
10445
|
const path = publicCliConfigPath(home);
|
|
10213
10446
|
try {
|
|
10214
|
-
const raw = await
|
|
10447
|
+
const raw = await readFile13(path, "utf8");
|
|
10215
10448
|
return parsePublicCliConfig(JSON.parse(raw));
|
|
10216
10449
|
} catch (error) {
|
|
10217
10450
|
if (error instanceof Error && "code" in error && error.code === "ENOENT") {
|
|
@@ -10222,7 +10455,7 @@ async function loadPublicCliConfig(home) {
|
|
|
10222
10455
|
}
|
|
10223
10456
|
async function savePublicCliConfig(config, home) {
|
|
10224
10457
|
const path = publicCliConfigPath(home);
|
|
10225
|
-
await mkdir(
|
|
10458
|
+
await mkdir(dirname11(path), { recursive: true });
|
|
10226
10459
|
const normalized = parsePublicCliConfig(config);
|
|
10227
10460
|
await writeFile6(
|
|
10228
10461
|
path,
|
|
@@ -10669,7 +10902,7 @@ function credentialProvidersFromAuthData(data) {
|
|
|
10669
10902
|
}
|
|
10670
10903
|
async function loadCredentialProviders(agentDir) {
|
|
10671
10904
|
try {
|
|
10672
|
-
const raw = await
|
|
10905
|
+
const raw = await readFile13(join19(agentDir, "auth.json"), "utf8");
|
|
10673
10906
|
return credentialProvidersFromAuthData(JSON.parse(raw));
|
|
10674
10907
|
} catch (error) {
|
|
10675
10908
|
if (error instanceof Error && "code" in error && error.code === "ENOENT") {
|
|
@@ -10708,15 +10941,15 @@ __export(host_providers_exports, {
|
|
|
10708
10941
|
renderHostProvidersTable: () => renderHostProvidersTable
|
|
10709
10942
|
});
|
|
10710
10943
|
import { readFileSync as readFileSync2 } from "node:fs";
|
|
10711
|
-
import { join as
|
|
10944
|
+
import { join as join20 } from "node:path";
|
|
10712
10945
|
function hostProvidersPath(home) {
|
|
10713
10946
|
if (typeof home !== "string" || home.trim() === "") {
|
|
10714
10947
|
throw new Error("home must be explicitly provided");
|
|
10715
10948
|
}
|
|
10716
|
-
return
|
|
10949
|
+
return join20(home, ".ak-roles", "host-providers.json");
|
|
10717
10950
|
}
|
|
10718
10951
|
function hermesProviderModelsCachePath(home) {
|
|
10719
|
-
return
|
|
10952
|
+
return join20(home, ".hermes", "provider_models_cache.json");
|
|
10720
10953
|
}
|
|
10721
10954
|
function parseHostProvidersTable(value) {
|
|
10722
10955
|
if (value === null || typeof value !== "object" || Array.isArray(value)) {
|
|
@@ -10871,12 +11104,12 @@ var init_host_providers = __esm({
|
|
|
10871
11104
|
});
|
|
10872
11105
|
|
|
10873
11106
|
// src/ledger-session-read.ts
|
|
10874
|
-
import { readFile as
|
|
10875
|
-
function
|
|
11107
|
+
import { readFile as readFile14 } from "node:fs/promises";
|
|
11108
|
+
function isRecord6(value) {
|
|
10876
11109
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
10877
11110
|
}
|
|
10878
11111
|
async function readLedgerSessionJsonlLines(path) {
|
|
10879
|
-
const text = await
|
|
11112
|
+
const text = await readFile14(path, "utf8");
|
|
10880
11113
|
const lines = text.split("\n");
|
|
10881
11114
|
const out = [];
|
|
10882
11115
|
for (let index = 0; index < lines.length; index += 1) {
|
|
@@ -10897,7 +11130,7 @@ async function readLedgerSessionJsonlLines(path) {
|
|
|
10897
11130
|
});
|
|
10898
11131
|
continue;
|
|
10899
11132
|
}
|
|
10900
|
-
if (!
|
|
11133
|
+
if (!isRecord6(row)) {
|
|
10901
11134
|
const kind = row === null ? "null" : Array.isArray(row) ? "array" : typeof row;
|
|
10902
11135
|
out.push({
|
|
10903
11136
|
line: lineNumber,
|
|
@@ -10974,9 +11207,9 @@ var init_ledger_session_read = __esm({
|
|
|
10974
11207
|
});
|
|
10975
11208
|
|
|
10976
11209
|
// src/analyst-gate-cycles-read.ts
|
|
10977
|
-
import { readdir as
|
|
10978
|
-
import { join as
|
|
10979
|
-
function
|
|
11210
|
+
import { readdir as readdir6 } from "node:fs/promises";
|
|
11211
|
+
import { join as join21 } from "node:path";
|
|
11212
|
+
function isRecord7(value) {
|
|
10980
11213
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
10981
11214
|
}
|
|
10982
11215
|
function isParentAttemptBindingRow(row) {
|
|
@@ -11006,7 +11239,7 @@ function isGateTerminatingToolName(toolName) {
|
|
|
11006
11239
|
function acceptedGateReceiptIds(rows) {
|
|
11007
11240
|
const accepted = /* @__PURE__ */ new Set();
|
|
11008
11241
|
for (const row of rows) {
|
|
11009
|
-
const message =
|
|
11242
|
+
const message = isRecord7(row.message) ? row.message : void 0;
|
|
11010
11243
|
if (message?.role !== "toolResult") continue;
|
|
11011
11244
|
if (typeof message.toolCallId !== "string" || message.toolCallId.length === 0) continue;
|
|
11012
11245
|
if (message.isError === false) accepted.add(message.toolCallId);
|
|
@@ -11041,7 +11274,7 @@ function nearestAttemptBindingBefore(rows, beforeIndex) {
|
|
|
11041
11274
|
for (let i = beforeIndex - 1; i >= 0; i -= 1) {
|
|
11042
11275
|
const row = rows[i];
|
|
11043
11276
|
if (!isParentAttemptBindingRow(row)) continue;
|
|
11044
|
-
if (!
|
|
11277
|
+
if (!isRecord7(row.data) || !isRecord7(row.data.parent)) continue;
|
|
11045
11278
|
const id = row.data.parent.attemptEntryId;
|
|
11046
11279
|
const sessionFile = row.data.parent.sessionFile;
|
|
11047
11280
|
return {
|
|
@@ -11056,10 +11289,10 @@ function extractAllAcceptedGateToolCalls(rows) {
|
|
|
11056
11289
|
const out = [];
|
|
11057
11290
|
for (let rowIndex = 0; rowIndex < rows.length; rowIndex += 1) {
|
|
11058
11291
|
const row = rows[rowIndex];
|
|
11059
|
-
const message =
|
|
11292
|
+
const message = isRecord7(row.message) ? row.message : void 0;
|
|
11060
11293
|
if (message?.role !== "assistant" || !Array.isArray(message.content)) continue;
|
|
11061
11294
|
for (const part of message.content) {
|
|
11062
|
-
if (!
|
|
11295
|
+
if (!isRecord7(part) || part.type !== "toolCall") continue;
|
|
11063
11296
|
if (typeof part.id !== "string" || part.id.length === 0) continue;
|
|
11064
11297
|
if (typeof part.name !== "string" || part.name.length === 0) continue;
|
|
11065
11298
|
if (!isGateTerminatingToolName(part.name)) continue;
|
|
@@ -11067,7 +11300,7 @@ function extractAllAcceptedGateToolCalls(rows) {
|
|
|
11067
11300
|
const binding = nearestAttemptBindingBefore(rows, rowIndex);
|
|
11068
11301
|
out.push({
|
|
11069
11302
|
toolName: part.name,
|
|
11070
|
-
args:
|
|
11303
|
+
args: isRecord7(part.arguments) ? part.arguments : void 0,
|
|
11071
11304
|
accepted: true,
|
|
11072
11305
|
rowIndex,
|
|
11073
11306
|
...binding
|
|
@@ -11190,17 +11423,17 @@ function pairGateRounds(volumes) {
|
|
|
11190
11423
|
return rounds.sort((a, b) => a.officerStartedAt.localeCompare(b.officerStartedAt)).map((round, index) => ({ ...round, roundIndex: index + 1 }));
|
|
11191
11424
|
}
|
|
11192
11425
|
async function resolveOfficerSessionFromPointerFile(pointerPath) {
|
|
11193
|
-
const { readFile:
|
|
11426
|
+
const { readFile: readFile24 } = await import("node:fs/promises");
|
|
11194
11427
|
let raw;
|
|
11195
11428
|
try {
|
|
11196
|
-
raw = JSON.parse(await
|
|
11429
|
+
raw = JSON.parse(await readFile24(pointerPath, "utf8"));
|
|
11197
11430
|
} catch (error) {
|
|
11198
11431
|
throw new Error(
|
|
11199
11432
|
`direct officer run pointer unreadable in ${pointerPath}: ${error instanceof Error ? error.message : String(error)}`,
|
|
11200
11433
|
{ cause: error }
|
|
11201
11434
|
);
|
|
11202
11435
|
}
|
|
11203
|
-
if (!
|
|
11436
|
+
if (!isRecord7(raw) || raw.kind !== "direct-officer-run-pointer" || raw.version !== 1) {
|
|
11204
11437
|
throw new Error(`direct officer run pointer has unknown shape in ${pointerPath}`);
|
|
11205
11438
|
}
|
|
11206
11439
|
const sessionFile = raw.sessionFile;
|
|
@@ -11216,7 +11449,7 @@ async function readAnalystGateCyclesFromAuditorRoles(auditorRolesDirectory, opti
|
|
|
11216
11449
|
for (const directory of directories) {
|
|
11217
11450
|
let names;
|
|
11218
11451
|
try {
|
|
11219
|
-
const entries = await
|
|
11452
|
+
const entries = await readdir6(directory, { withFileTypes: true });
|
|
11220
11453
|
names = entries.filter(
|
|
11221
11454
|
(e) => e.isFile() && (e.name.endsWith(".jsonl") || e.name.endsWith(".pointer.json"))
|
|
11222
11455
|
).map((e) => e.name).sort();
|
|
@@ -11225,7 +11458,7 @@ async function readAnalystGateCyclesFromAuditorRoles(auditorRolesDirectory, opti
|
|
|
11225
11458
|
throw error;
|
|
11226
11459
|
}
|
|
11227
11460
|
for (const name of names) {
|
|
11228
|
-
const path =
|
|
11461
|
+
const path = join21(directory, name);
|
|
11229
11462
|
const fromPointer = name.endsWith(".pointer.json");
|
|
11230
11463
|
const sessionPath = fromPointer ? await resolveOfficerSessionFromPointerFile(path) : path;
|
|
11231
11464
|
if (sessionPath === void 0) continue;
|
|
@@ -11267,6 +11500,15 @@ var init_analyst_gate_cycles_read = __esm({
|
|
|
11267
11500
|
});
|
|
11268
11501
|
|
|
11269
11502
|
// src/audit-escalation.ts
|
|
11503
|
+
var audit_escalation_exports = {};
|
|
11504
|
+
__export(audit_escalation_exports, {
|
|
11505
|
+
AUDIT_ESCALATION_KIND: () => AUDIT_ESCALATION_KIND,
|
|
11506
|
+
buildAuditEscalationResult: () => buildAuditEscalationResult,
|
|
11507
|
+
disposeComplianceDecision: () => disposeComplianceDecision,
|
|
11508
|
+
isAuditEscalationProjection: () => isAuditEscalationProjection,
|
|
11509
|
+
isAuditEscalationResult: () => isAuditEscalationResult,
|
|
11510
|
+
projectAuditEscalation: () => projectAuditEscalation
|
|
11511
|
+
});
|
|
11270
11512
|
function buildAuditEscalationResult(decision, deliveredOutput) {
|
|
11271
11513
|
const auditOwned = {
|
|
11272
11514
|
kind: AUDIT_ESCALATION_KIND
|
|
@@ -11363,21 +11605,6 @@ var init_audit_escalation = __esm({
|
|
|
11363
11605
|
}
|
|
11364
11606
|
});
|
|
11365
11607
|
|
|
11366
|
-
// src/run-terminal-artifacts.ts
|
|
11367
|
-
import { basename as basename7, dirname as dirname11, join as join21 } from "node:path";
|
|
11368
|
-
function runIdFromRunDirectory(runDirectory) {
|
|
11369
|
-
const name = basename7(runDirectory);
|
|
11370
|
-
const at = name.lastIndexOf("@");
|
|
11371
|
-
if (at <= 0 || at === name.length - 1) return void 0;
|
|
11372
|
-
return name.slice(0, at);
|
|
11373
|
-
}
|
|
11374
|
-
var init_run_terminal_artifacts = __esm({
|
|
11375
|
-
"src/run-terminal-artifacts.ts"() {
|
|
11376
|
-
"use strict";
|
|
11377
|
-
init_role_run_placement();
|
|
11378
|
-
}
|
|
11379
|
-
});
|
|
11380
|
-
|
|
11381
11608
|
// src/submission-ledger.ts
|
|
11382
11609
|
import { join as join22 } from "node:path";
|
|
11383
11610
|
function runIdentity(context) {
|
|
@@ -11801,7 +12028,7 @@ var init_submission_ledger = __esm({
|
|
|
11801
12028
|
|
|
11802
12029
|
// src/session-opening-materials.ts
|
|
11803
12030
|
import { existsSync as existsSync8 } from "node:fs";
|
|
11804
|
-
import { readFile as
|
|
12031
|
+
import { readFile as readFile15 } from "node:fs/promises";
|
|
11805
12032
|
import { dirname as dirname12, join as join23 } from "node:path";
|
|
11806
12033
|
import { fileURLToPath, pathToFileURL as pathToFileURL3 } from "node:url";
|
|
11807
12034
|
function resolvePackageRootDir(moduleUrl = import.meta.url) {
|
|
@@ -11817,7 +12044,7 @@ function resolvePackageRootDir(moduleUrl = import.meta.url) {
|
|
|
11817
12044
|
return fileURLToPath(new URL("..", moduleUrl));
|
|
11818
12045
|
}
|
|
11819
12046
|
async function readPackageMaterial(relativePath) {
|
|
11820
|
-
return
|
|
12047
|
+
return readFile15(fileURLToPath(new URL(relativePath, packageRootUrl)), "utf8");
|
|
11821
12048
|
}
|
|
11822
12049
|
async function joinPackageMaterials(relativePaths) {
|
|
11823
12050
|
const chunks = [];
|
|
@@ -13218,11 +13445,11 @@ function reportEngineDetourCall(input) {
|
|
|
13218
13445
|
recordPointer: pointer
|
|
13219
13446
|
};
|
|
13220
13447
|
}
|
|
13221
|
-
function
|
|
13448
|
+
function isRecord8(value) {
|
|
13222
13449
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
13223
13450
|
}
|
|
13224
13451
|
function callFactFromSitianPayload(payload, pointer) {
|
|
13225
|
-
if (!
|
|
13452
|
+
if (!isRecord8(payload)) return void 0;
|
|
13226
13453
|
if (payload.tool !== ENGINE_DETOUR_TOOL_NAME) return void 0;
|
|
13227
13454
|
if (typeof payload.toolCallId !== "string" || payload.toolCallId.length === 0) {
|
|
13228
13455
|
return void 0;
|
|
@@ -13239,11 +13466,11 @@ function callFactFromSitianPayload(payload, pointer) {
|
|
|
13239
13466
|
};
|
|
13240
13467
|
}
|
|
13241
13468
|
function invocationScopeIdOfRecord(record4) {
|
|
13242
|
-
if (
|
|
13469
|
+
if (isRecord8(record4.subject)) {
|
|
13243
13470
|
const fromSubject = record4.subject.invocationScopeId;
|
|
13244
13471
|
if (typeof fromSubject === "string" && fromSubject.length > 0) return fromSubject;
|
|
13245
13472
|
}
|
|
13246
|
-
if (
|
|
13473
|
+
if (isRecord8(record4.payload)) {
|
|
13247
13474
|
const fromPayload = record4.payload.invocationScopeId;
|
|
13248
13475
|
if (typeof fromPayload === "string" && fromPayload.length > 0) return fromPayload;
|
|
13249
13476
|
}
|
|
@@ -13303,7 +13530,7 @@ function readInvocationRecord(runDirectory) {
|
|
|
13303
13530
|
const raw = JSON.parse(
|
|
13304
13531
|
readFileSync3(join24(runDirectory, "invocation.json"), "utf8")
|
|
13305
13532
|
);
|
|
13306
|
-
return
|
|
13533
|
+
return isRecord8(raw) ? raw : void 0;
|
|
13307
13534
|
} catch (error) {
|
|
13308
13535
|
if (error?.code === "ENOENT") return void 0;
|
|
13309
13536
|
throw error;
|
|
@@ -13321,7 +13548,7 @@ function readInvocationSelectedHost(runDirectory) {
|
|
|
13321
13548
|
}
|
|
13322
13549
|
function withEngineDetourToolUsageFact(outcome, usage) {
|
|
13323
13550
|
if (usage === void 0) return outcome;
|
|
13324
|
-
const prior =
|
|
13551
|
+
const prior = isRecord8(outcome.decisiveFacts) ? outcome.decisiveFacts : {};
|
|
13325
13552
|
return {
|
|
13326
13553
|
...outcome,
|
|
13327
13554
|
decisiveFacts: {
|
|
@@ -13391,13 +13618,13 @@ function resolveAuditDossier(source) {
|
|
|
13391
13618
|
}
|
|
13392
13619
|
return { status: "ok", runDirectory };
|
|
13393
13620
|
}
|
|
13394
|
-
function
|
|
13621
|
+
function isRecord9(value) {
|
|
13395
13622
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
13396
13623
|
}
|
|
13397
13624
|
function readDoctorAuditSubjects(context) {
|
|
13398
13625
|
const entries = context.sessionManager.getEntries?.() ?? [];
|
|
13399
13626
|
for (const entry of entries) {
|
|
13400
|
-
if (
|
|
13627
|
+
if (isRecord9(entry) && entry.type === "custom" && entry.customType === DOCTOR_CANDIDATE_ENTRY_TYPE) {
|
|
13401
13628
|
return { status: "ok" };
|
|
13402
13629
|
}
|
|
13403
13630
|
}
|
|
@@ -13431,7 +13658,7 @@ var init_dossier_resolution = __esm({
|
|
|
13431
13658
|
|
|
13432
13659
|
// src/package-resources/method-skill.ts
|
|
13433
13660
|
import { createHash as createHash6 } from "node:crypto";
|
|
13434
|
-
import { readFile as
|
|
13661
|
+
import { readFile as readFile16, realpath as realpath6 } from "node:fs/promises";
|
|
13435
13662
|
import { join as join25 } from "node:path";
|
|
13436
13663
|
function gitBlobOid(bytes) {
|
|
13437
13664
|
const body = typeof bytes === "string" ? Buffer.from(bytes, "utf8") : Buffer.from(bytes);
|
|
@@ -13454,11 +13681,11 @@ function resolvePackagedMethodSkillRoot(packageRoot, name) {
|
|
|
13454
13681
|
function resolvePackagedMethodSkillPath(packageRoot, name) {
|
|
13455
13682
|
return join25(resolvePackagedMethodSkillRoot(packageRoot, name), "SKILL.md");
|
|
13456
13683
|
}
|
|
13457
|
-
function
|
|
13684
|
+
function isRecord10(value) {
|
|
13458
13685
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
13459
13686
|
}
|
|
13460
13687
|
function parseProvenance(raw, expectedName) {
|
|
13461
|
-
if (!
|
|
13688
|
+
if (!isRecord10(raw)) {
|
|
13462
13689
|
throw new Error(`Packaged method provenance must be an object for ${expectedName}`);
|
|
13463
13690
|
}
|
|
13464
13691
|
if (raw.name !== expectedName) {
|
|
@@ -13472,7 +13699,7 @@ function parseProvenance(raw, expectedName) {
|
|
|
13472
13699
|
if (typeof raw.packageAdaptation !== "string" || raw.packageAdaptation.trim() === "") {
|
|
13473
13700
|
throw new Error(`Packaged method provenance packageAdaptation must be nonblank`);
|
|
13474
13701
|
}
|
|
13475
|
-
if (!
|
|
13702
|
+
if (!isRecord10(raw.upstream)) {
|
|
13476
13703
|
throw new Error(`Packaged method provenance upstream must be an object`);
|
|
13477
13704
|
}
|
|
13478
13705
|
const upstream = raw.upstream;
|
|
@@ -13499,12 +13726,12 @@ function parseProvenance(raw, expectedName) {
|
|
|
13499
13726
|
`Packaged method provenance upstream must include nonblank tag or version`
|
|
13500
13727
|
);
|
|
13501
13728
|
}
|
|
13502
|
-
if (!
|
|
13729
|
+
if (!isRecord10(raw.files)) {
|
|
13503
13730
|
throw new Error(`Packaged method provenance files must be an object`);
|
|
13504
13731
|
}
|
|
13505
13732
|
const files = {};
|
|
13506
13733
|
for (const [rel, entry] of Object.entries(raw.files)) {
|
|
13507
|
-
if (!
|
|
13734
|
+
if (!isRecord10(entry)) {
|
|
13508
13735
|
throw new Error(`Packaged method provenance file entry must be an object: ${rel}`);
|
|
13509
13736
|
}
|
|
13510
13737
|
if (typeof entry.sha256 !== "string" || !SHA256_RE.test(entry.sha256)) {
|
|
@@ -13550,7 +13777,7 @@ async function loadPackagedMethodSkillMaterial(packageRoot, name) {
|
|
|
13550
13777
|
const provenancePath = join25(rootDirectory, "provenance.json");
|
|
13551
13778
|
let provenanceRaw;
|
|
13552
13779
|
try {
|
|
13553
|
-
provenanceRaw = await
|
|
13780
|
+
provenanceRaw = await readFile16(provenancePath, "utf8");
|
|
13554
13781
|
} catch (error) {
|
|
13555
13782
|
throw new PackagedMethodSkillUnavailableError(name, provenancePath, error);
|
|
13556
13783
|
}
|
|
@@ -13567,7 +13794,7 @@ async function loadPackagedMethodSkillMaterial(packageRoot, name) {
|
|
|
13567
13794
|
const absolute = join25(rootDirectory, rel);
|
|
13568
13795
|
let bytes;
|
|
13569
13796
|
try {
|
|
13570
|
-
bytes = await
|
|
13797
|
+
bytes = await readFile16(absolute);
|
|
13571
13798
|
} catch (error) {
|
|
13572
13799
|
throw new PackagedMethodSkillUnavailableError(name, absolute, error);
|
|
13573
13800
|
}
|
|
@@ -13583,7 +13810,7 @@ async function loadPackagedMethodSkillMaterial(packageRoot, name) {
|
|
|
13583
13810
|
let raw;
|
|
13584
13811
|
try {
|
|
13585
13812
|
skillPath = await realpath6(skillPathConfigured);
|
|
13586
|
-
raw = await
|
|
13813
|
+
raw = await readFile16(skillPath, "utf8");
|
|
13587
13814
|
} catch (error) {
|
|
13588
13815
|
throw new PackagedMethodSkillUnavailableError(name, skillPathConfigured, error);
|
|
13589
13816
|
}
|
|
@@ -13875,11 +14102,11 @@ var init_navigator_invocation_identity = __esm({
|
|
|
13875
14102
|
});
|
|
13876
14103
|
|
|
13877
14104
|
// src/receipt-delivery-policy.ts
|
|
13878
|
-
function
|
|
14105
|
+
function isRecord11(value) {
|
|
13879
14106
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
13880
14107
|
}
|
|
13881
14108
|
function parseNoReceiptLifecycleFacts(input) {
|
|
13882
|
-
if (!
|
|
14109
|
+
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")) {
|
|
13883
14110
|
throw new TypeError("malformed no-receipt lifecycle facts");
|
|
13884
14111
|
}
|
|
13885
14112
|
return {
|
|
@@ -14138,7 +14365,7 @@ __export(settlement_exports, {
|
|
|
14138
14365
|
withSubmissions: () => withSubmissions
|
|
14139
14366
|
});
|
|
14140
14367
|
import { randomUUID as randomUUID4 } from "node:crypto";
|
|
14141
|
-
import { appendFile as appendFile2, readFile as
|
|
14368
|
+
import { appendFile as appendFile2, readFile as readFile17, readdir as readdir7, writeFile as writeFile7 } from "node:fs/promises";
|
|
14142
14369
|
import { dirname as dirname14, join as join26 } from "node:path";
|
|
14143
14370
|
function sealedLedgerHome(admitted) {
|
|
14144
14371
|
return homeFromRunDirectory(admitted.runDirectory);
|
|
@@ -14282,10 +14509,10 @@ function presentControlledFailure(failure2, io) {
|
|
|
14282
14509
|
}
|
|
14283
14510
|
async function inspectJudgeSession(sessionFile) {
|
|
14284
14511
|
try {
|
|
14285
|
-
await
|
|
14512
|
+
await readFile17(sessionFile, "utf8");
|
|
14286
14513
|
return { state: "present" };
|
|
14287
14514
|
} catch (error) {
|
|
14288
|
-
if (
|
|
14515
|
+
if (isMissingPathError4(error)) return { state: "missing" };
|
|
14289
14516
|
return {
|
|
14290
14517
|
state: "unreadable",
|
|
14291
14518
|
diagnostic: error instanceof Error ? error.message || error.name : String(error)
|
|
@@ -14485,7 +14712,7 @@ function explicitInternalKnownFailureClassificationInput(failure2) {
|
|
|
14485
14712
|
...failure2.details === void 0 ? {} : { knownDetails: failure2.details }
|
|
14486
14713
|
};
|
|
14487
14714
|
}
|
|
14488
|
-
function
|
|
14715
|
+
function isMissingPathError4(error) {
|
|
14489
14716
|
return error instanceof Error && "code" in error && error.code === "ENOENT";
|
|
14490
14717
|
}
|
|
14491
14718
|
function sessionReadFailure(error, fallbackMessage) {
|
|
@@ -14514,7 +14741,7 @@ function sessionReadFailure(error, fallbackMessage) {
|
|
|
14514
14741
|
return failed;
|
|
14515
14742
|
}
|
|
14516
14743
|
async function readBoundSessionEntries(sessionFile) {
|
|
14517
|
-
const text = await
|
|
14744
|
+
const text = await readFile17(sessionFile, "utf8");
|
|
14518
14745
|
const entries = [];
|
|
14519
14746
|
for (const line2 of text.trim().split("\n").filter(Boolean)) {
|
|
14520
14747
|
try {
|
|
@@ -14580,7 +14807,7 @@ async function readSitianRetainedAuditorProviderStop(sessionFile) {
|
|
|
14580
14807
|
const { records } = await readSitianRecords(recordFile);
|
|
14581
14808
|
for (let i = records.length - 1; i >= 0; i -= 1) {
|
|
14582
14809
|
const payload = records[i]?.payload;
|
|
14583
|
-
if (!
|
|
14810
|
+
if (!isRecord12(payload) || !isRecord12(payload.response)) continue;
|
|
14584
14811
|
if (typeof payload.type === "string") continue;
|
|
14585
14812
|
const stop = sessionProviderStopFromAssistant(payload.response);
|
|
14586
14813
|
if (stop !== void 0) return stop;
|
|
@@ -14605,7 +14832,7 @@ async function loadBoundAuditorVolumes(sessionFile) {
|
|
|
14605
14832
|
try {
|
|
14606
14833
|
parentEntries = await readBoundSessionEntries(sessionFile);
|
|
14607
14834
|
} catch (error) {
|
|
14608
|
-
if (
|
|
14835
|
+
if (isMissingPathError4(error)) return void 0;
|
|
14609
14836
|
throw sessionReadFailure(error, "failed to read parent session for auditor binding");
|
|
14610
14837
|
}
|
|
14611
14838
|
const parentId = parentEntries.find((entry) => entry.type === "session")?.id;
|
|
@@ -14616,10 +14843,10 @@ async function loadBoundAuditorVolumes(sessionFile) {
|
|
|
14616
14843
|
for (const childDirectory of childDirectories) {
|
|
14617
14844
|
let names;
|
|
14618
14845
|
try {
|
|
14619
|
-
names = await
|
|
14846
|
+
names = await readdir7(childDirectory);
|
|
14620
14847
|
sawAnyDirectory = true;
|
|
14621
14848
|
} catch (error) {
|
|
14622
|
-
if (
|
|
14849
|
+
if (isMissingPathError4(error)) continue;
|
|
14623
14850
|
throw sessionReadFailure(error, "failed to read bound auditor session directory");
|
|
14624
14851
|
}
|
|
14625
14852
|
for (const file of names.filter((name) => name.endsWith(".jsonl")).sort().reverse()) {
|
|
@@ -14630,7 +14857,7 @@ async function loadBoundAuditorVolumes(sessionFile) {
|
|
|
14630
14857
|
throw sessionReadFailure(error, "failed to read discovered auditor session");
|
|
14631
14858
|
}
|
|
14632
14859
|
const header = entries.find((entry) => entry.type === "session");
|
|
14633
|
-
if (!
|
|
14860
|
+
if (!isRecord12(header)) continue;
|
|
14634
14861
|
const bindingIndexes = [];
|
|
14635
14862
|
for (let i = 0; i < entries.length; i += 1) {
|
|
14636
14863
|
const entry = entries[i];
|
|
@@ -14644,7 +14871,7 @@ async function loadBoundAuditorVolumes(sessionFile) {
|
|
|
14644
14871
|
end: idx + 1 < bindingIndexes.length ? bindingIndexes[idx + 1] : entries.length
|
|
14645
14872
|
})) : [{ entry: void 0, start: 0, end: entries.length }];
|
|
14646
14873
|
for (const { entry: bindingEntry, start, end } of bindingPasses) {
|
|
14647
|
-
const bindingParent = bindingEntry !== void 0 &&
|
|
14874
|
+
const bindingParent = bindingEntry !== void 0 && isRecord12(bindingEntry.data) && isRecord12(bindingEntry.data.parent) ? bindingEntry.data.parent : void 0;
|
|
14648
14875
|
const attemptEntryId = typeof bindingParent?.attemptEntryId === "string" ? bindingParent.attemptEntryId : void 0;
|
|
14649
14876
|
const boundSessionFile = typeof bindingParent?.sessionFile === "string" ? bindingParent.sessionFile : typeof header.parentSession === "string" ? header.parentSession : void 0;
|
|
14650
14877
|
if (boundSessionFile !== sessionFile) continue;
|
|
@@ -14668,12 +14895,12 @@ function complianceFailureFromAuditorVolumes(volumes) {
|
|
|
14668
14895
|
if (stop === void 0) continue;
|
|
14669
14896
|
for (let i = entries.length - 1; i >= 0; i -= 1) {
|
|
14670
14897
|
const entry = entries[i];
|
|
14671
|
-
if (entry?.type !== "custom" || entry.customType !== AUDITOR_COMPLIANCE_FAILURE_ENTRY_TYPE || !
|
|
14672
|
-
const parent =
|
|
14673
|
-
const failure2 =
|
|
14898
|
+
if (entry?.type !== "custom" || entry.customType !== AUDITOR_COMPLIANCE_FAILURE_ENTRY_TYPE || !isRecord12(entry.data)) continue;
|
|
14899
|
+
const parent = isRecord12(entry.data.parent) ? entry.data.parent : void 0;
|
|
14900
|
+
const failure2 = isRecord12(entry.data.failure) ? entry.data.failure : void 0;
|
|
14674
14901
|
if (parent?.sessionId !== parentId || parent.sessionFile !== sessionFile || parent.attemptEntryId !== attemptEntryId) continue;
|
|
14675
14902
|
if (failure2 === void 0) continue;
|
|
14676
|
-
const identity =
|
|
14903
|
+
const identity = isRecord12(failure2.identity) ? failure2.identity : void 0;
|
|
14677
14904
|
const typedCause = failure2.cause === "provider" || failure2.cause === "activation" || failure2.cause === "session" || failure2.cause === "output" || failure2.cause === "timeout" ? failure2.cause : void 0;
|
|
14678
14905
|
return {
|
|
14679
14906
|
...typedCause === void 0 ? {} : { cause: typedCause },
|
|
@@ -14682,7 +14909,7 @@ function complianceFailureFromAuditorVolumes(volumes) {
|
|
|
14682
14909
|
...typeof identity.code === "string" || typeof identity.code === "number" ? { code: identity.code } : {}
|
|
14683
14910
|
} },
|
|
14684
14911
|
...typeof failure2.diagnostic === "string" ? { diagnostic: failure2.diagnostic } : {},
|
|
14685
|
-
...
|
|
14912
|
+
...isRecord12(failure2.details) ? { details: failure2.details } : {}
|
|
14686
14913
|
};
|
|
14687
14914
|
}
|
|
14688
14915
|
}
|
|
@@ -14729,9 +14956,9 @@ function typedFailedTerminatingToolKnownFailure(entries) {
|
|
|
14729
14956
|
if (classification.kind !== "infrastructure") continue;
|
|
14730
14957
|
if (typeof message.toolCallId !== "string" || typeof message.toolName !== "string") continue;
|
|
14731
14958
|
if (boundRoleToolCallForResult(attemptEntries, i, message, message.toolName) === void 0) continue;
|
|
14732
|
-
const textPart = Array.isArray(message.content) ? message.content.find((part) =>
|
|
14733
|
-
const diagnostic =
|
|
14734
|
-
const details =
|
|
14959
|
+
const textPart = Array.isArray(message.content) ? message.content.find((part) => isRecord12(part) && part.type === "text" && typeof part.text === "string") : void 0;
|
|
14960
|
+
const diagnostic = isRecord12(textPart) ? textPart.text : void 0;
|
|
14961
|
+
const details = isRecord12(message.details) ? message.details : classification.fact;
|
|
14735
14962
|
return {
|
|
14736
14963
|
cause: "activation",
|
|
14737
14964
|
identity: { name: message.toolName, code: message.toolCallId },
|
|
@@ -14767,7 +14994,7 @@ async function resolveAuditedRunnerFailureResolution(input) {
|
|
|
14767
14994
|
);
|
|
14768
14995
|
if (terminatingFailure !== void 0) return resolutionOf(terminatingFailure);
|
|
14769
14996
|
} catch (error) {
|
|
14770
|
-
if (!
|
|
14997
|
+
if (!isMissingPathError4(error)) {
|
|
14771
14998
|
const failure2 = sessionReadFailure(error, "failed to recover typed terminating-tool failure");
|
|
14772
14999
|
return resolutionOf({
|
|
14773
15000
|
cause: "session",
|
|
@@ -14868,7 +15095,7 @@ function controlledFailureInputFromResolution(resolution) {
|
|
|
14868
15095
|
} : {}
|
|
14869
15096
|
};
|
|
14870
15097
|
}
|
|
14871
|
-
function
|
|
15098
|
+
function isRecord12(value) {
|
|
14872
15099
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
14873
15100
|
}
|
|
14874
15101
|
function toolResultText(message) {
|
|
@@ -14893,7 +15120,7 @@ function extractCollectorTargetBindRejection(entries) {
|
|
|
14893
15120
|
const diagnostic = toolResultText(message);
|
|
14894
15121
|
if (diagnostic.length === 0) return void 0;
|
|
14895
15122
|
const details = message.details;
|
|
14896
|
-
const code =
|
|
15123
|
+
const code = isRecord12(details) && typeof details.code === "string" && details.code.trim() !== "" ? details.code : void 0;
|
|
14897
15124
|
return code === void 0 ? { diagnostic } : { diagnostic, code };
|
|
14898
15125
|
}
|
|
14899
15126
|
return void 0;
|
|
@@ -14975,7 +15202,7 @@ function boundRoleToolCallForResult(entries, resultIndex, message, outputToolNam
|
|
|
14975
15202
|
const candidateMessage = entries[index]?.message;
|
|
14976
15203
|
if (candidateMessage?.role === "assistant" && Array.isArray(candidateMessage.content)) {
|
|
14977
15204
|
for (const part of candidateMessage.content) {
|
|
14978
|
-
if (!
|
|
15205
|
+
if (!isRecord12(part) || part.type !== "toolCall" || part.id !== callId) {
|
|
14979
15206
|
continue;
|
|
14980
15207
|
}
|
|
14981
15208
|
if (part.name !== outputToolName) return void 0;
|
|
@@ -15046,7 +15273,7 @@ function parseNavigatorAttendanceDetails(details) {
|
|
|
15046
15273
|
if (typeof details.prose === "string" && details.prose.trim() !== "") {
|
|
15047
15274
|
prose = details.prose;
|
|
15048
15275
|
} else {
|
|
15049
|
-
const next =
|
|
15276
|
+
const next = isRecord12(details.next) && typeof details.next.role === "string" ? details.next.role : void 0;
|
|
15050
15277
|
const reason = typeof details.reason === "string" && details.reason.trim() !== "" ? details.reason : void 0;
|
|
15051
15278
|
const command = typeof details.command === "string" && details.command.trim() !== "" ? details.command : void 0;
|
|
15052
15279
|
if (reason !== void 0 && next !== void 0) {
|
|
@@ -15155,7 +15382,7 @@ function detourGateContext(admitted, scope) {
|
|
|
15155
15382
|
}
|
|
15156
15383
|
async function withOptionalGateProjection(base, sessionDirectory, gateContext = {}) {
|
|
15157
15384
|
const secondaryEvidence = base.roleOutcome.kind === "failure" ? base.roleOutcome.decisiveFacts.secondaryEvidence : void 0;
|
|
15158
|
-
const skipGate =
|
|
15385
|
+
const skipGate = isRecord12(secondaryEvidence) && secondaryEvidence.kind === "role_infrastructure_failure" && (secondaryEvidence.stage === "gatekeeper" || secondaryEvidence.stage === "inspector" || secondaryEvidence.stage === "notary");
|
|
15159
15386
|
let next = base;
|
|
15160
15387
|
if (!skipGate) {
|
|
15161
15388
|
const gate = await extractGateFactFromSessionDirectory(sessionDirectory, gateContext);
|
|
@@ -15199,7 +15426,7 @@ function extractNavigatorFact(entries) {
|
|
|
15199
15426
|
const entry = entries[i];
|
|
15200
15427
|
if (entry?.type === "custom_message" && entry.customType === "ak-navigator-attendance") {
|
|
15201
15428
|
const details = entry.message?.details ?? entry.details;
|
|
15202
|
-
if (!
|
|
15429
|
+
if (!isRecord12(details)) {
|
|
15203
15430
|
return {
|
|
15204
15431
|
disposition: "unavailable",
|
|
15205
15432
|
source: "unknown",
|
|
@@ -15232,7 +15459,7 @@ async function extractNavigatorFactFromAdmittedSession(sessionFile) {
|
|
|
15232
15459
|
const entries = await readBoundSessionEntries(sessionFile);
|
|
15233
15460
|
return extractNavigatorFact(entries);
|
|
15234
15461
|
} catch (error) {
|
|
15235
|
-
if (
|
|
15462
|
+
if (isMissingPathError4(error)) {
|
|
15236
15463
|
return {
|
|
15237
15464
|
disposition: "unavailable",
|
|
15238
15465
|
source: "unknown",
|
|
@@ -15345,7 +15572,7 @@ async function readLawfulSettlementEntries(sessionFile) {
|
|
|
15345
15572
|
try {
|
|
15346
15573
|
return await readBoundSessionEntries(sessionFile);
|
|
15347
15574
|
} catch (error) {
|
|
15348
|
-
if (
|
|
15575
|
+
if (isMissingPathError4(error)) return void 0;
|
|
15349
15576
|
throw error instanceof Error && error.knownCause === "session" ? error : sessionReadFailure(error, "session unreadable");
|
|
15350
15577
|
}
|
|
15351
15578
|
}
|
|
@@ -15609,7 +15836,7 @@ async function settleLawfulCollectorTerminalResult(admitted, authority, scope) {
|
|
|
15609
15836
|
const residual = boundErroredToolCandidate(entries, index, message, COLLECTOR_WAIT_TOOL);
|
|
15610
15837
|
if (residual === void 0) continue;
|
|
15611
15838
|
const candidate = residual.candidate;
|
|
15612
|
-
const details =
|
|
15839
|
+
const details = isRecord12(candidate) ? candidate : { candidate };
|
|
15613
15840
|
const failed = await settleFailureTerminalResult(
|
|
15614
15841
|
admitted,
|
|
15615
15842
|
{
|
|
@@ -15664,7 +15891,7 @@ function extractDoctorCandidateCostFact(entries) {
|
|
|
15664
15891
|
const entry = entries[i];
|
|
15665
15892
|
if (entry?.type === "custom" && entry.customType === DOCTOR_CANDIDATE_ENTRY_TYPE) {
|
|
15666
15893
|
const data = entry.data;
|
|
15667
|
-
return
|
|
15894
|
+
return isRecord12(data) ? data.cost : void 0;
|
|
15668
15895
|
}
|
|
15669
15896
|
}
|
|
15670
15897
|
return void 0;
|
|
@@ -15675,7 +15902,7 @@ function extractDoctorCandidateAuditNoReceiptFact(entries) {
|
|
|
15675
15902
|
const entry = entries[i];
|
|
15676
15903
|
if (entry?.type === "custom" && entry.customType === DOCTOR_CANDIDATE_ENTRY_TYPE) {
|
|
15677
15904
|
const data = entry.data;
|
|
15678
|
-
return
|
|
15905
|
+
return isRecord12(data) ? data.auditNoReceipt : void 0;
|
|
15679
15906
|
}
|
|
15680
15907
|
}
|
|
15681
15908
|
return void 0;
|
|
@@ -15840,7 +16067,7 @@ async function settleLawfulSeatAcceptedTerminalResult(admitted, authority, spec,
|
|
|
15840
16067
|
);
|
|
15841
16068
|
}
|
|
15842
16069
|
if (residual !== void 0) {
|
|
15843
|
-
const details =
|
|
16070
|
+
const details = isRecord12(residual.candidate) ? residual.candidate : { candidate: residual.candidate };
|
|
15844
16071
|
const failed = await settleFailureTerminalResult(
|
|
15845
16072
|
admitted,
|
|
15846
16073
|
{
|
|
@@ -15918,11 +16145,75 @@ async function settleLawfulDiaristTerminalResult(admitted, authority, scope) {
|
|
|
15918
16145
|
async function trySettleDiaristTerminalResult(admitted, authority, scope) {
|
|
15919
16146
|
return settleLawfulDiaristTerminalResult(admitted, authority, scope);
|
|
15920
16147
|
}
|
|
16148
|
+
function countersignTerminalFromEntries(entries) {
|
|
16149
|
+
for (let index = entries.length - 1; index >= 0; index -= 1) {
|
|
16150
|
+
const entry = entries[index];
|
|
16151
|
+
if (entry?.type !== "custom") continue;
|
|
16152
|
+
if (entry.customType !== SECRETARIAT_GATE_OFFICER_ENTRY_TYPE) continue;
|
|
16153
|
+
const data = entry.data !== null && typeof entry.data === "object" && !Array.isArray(entry.data) ? entry.data : void 0;
|
|
16154
|
+
if (data?.officer !== "countersign") continue;
|
|
16155
|
+
if (data.receipt === void 0) continue;
|
|
16156
|
+
const runId = typeof data.runId === "string" && data.runId.trim() !== "" ? data.runId : void 0;
|
|
16157
|
+
return {
|
|
16158
|
+
receipt: data.receipt,
|
|
16159
|
+
...runId === void 0 ? {} : { runId }
|
|
16160
|
+
};
|
|
16161
|
+
}
|
|
16162
|
+
return void 0;
|
|
16163
|
+
}
|
|
16164
|
+
function withCountersignTerminalFact(roleOutcome, officer) {
|
|
16165
|
+
const prior = roleOutcome.decisiveFacts !== void 0 && isRecord12(roleOutcome.decisiveFacts) ? roleOutcome.decisiveFacts : {};
|
|
16166
|
+
return {
|
|
16167
|
+
...roleOutcome,
|
|
16168
|
+
decisiveFacts: {
|
|
16169
|
+
...prior,
|
|
16170
|
+
[SECRETARIAT_COUNTERSIGN_TERMINAL_FACT_KEY]: officer
|
|
16171
|
+
}
|
|
16172
|
+
};
|
|
16173
|
+
}
|
|
16174
|
+
function acceptedSecretariatDefinesOfficerProjection(roleOutcome) {
|
|
16175
|
+
const payloads = roleOutcome.payloads ?? [];
|
|
16176
|
+
for (let index = payloads.length - 1; index >= 0; index -= 1) {
|
|
16177
|
+
const payload = payloads[index];
|
|
16178
|
+
if (!isRecord12(payload)) continue;
|
|
16179
|
+
const status = payload.secretariatStatus;
|
|
16180
|
+
if (typeof status !== "string") continue;
|
|
16181
|
+
return status === "converged";
|
|
16182
|
+
}
|
|
16183
|
+
return false;
|
|
16184
|
+
}
|
|
15921
16185
|
async function settleLawfulSecretariatTerminalResult(admitted, authority, scope) {
|
|
15922
|
-
|
|
16186
|
+
const settled = await settleLawfulSeatAcceptedTerminalResult(admitted, authority, {
|
|
15923
16187
|
role: "secretariat",
|
|
15924
16188
|
toolName: SECRETARIAT_OUTPUT_TOOL_NAME
|
|
15925
16189
|
}, scope);
|
|
16190
|
+
if (settled === void 0) return void 0;
|
|
16191
|
+
const coordinates = coordinatesFromAdmitted(authority, admitted);
|
|
16192
|
+
const entries = await readLawfulSettlementEntries(coordinates.sessionFile) ?? [];
|
|
16193
|
+
const officer = countersignTerminalFromEntries(entries);
|
|
16194
|
+
if (officer === void 0) return settled;
|
|
16195
|
+
if (settled.roleOutcome.kind === "audit_escalation") {
|
|
16196
|
+
return {
|
|
16197
|
+
...settled,
|
|
16198
|
+
roleOutcome: withCountersignTerminalFact(
|
|
16199
|
+
{
|
|
16200
|
+
...settled.roleOutcome,
|
|
16201
|
+
payloads: [officer.receipt]
|
|
16202
|
+
},
|
|
16203
|
+
officer
|
|
16204
|
+
)
|
|
16205
|
+
};
|
|
16206
|
+
}
|
|
16207
|
+
if (settled.roleOutcome.kind === "accepted") {
|
|
16208
|
+
if (!acceptedSecretariatDefinesOfficerProjection(settled.roleOutcome)) {
|
|
16209
|
+
return settled;
|
|
16210
|
+
}
|
|
16211
|
+
return {
|
|
16212
|
+
...settled,
|
|
16213
|
+
roleOutcome: withCountersignTerminalFact(settled.roleOutcome, officer)
|
|
16214
|
+
};
|
|
16215
|
+
}
|
|
16216
|
+
return settled;
|
|
15926
16217
|
}
|
|
15927
16218
|
async function trySettleSecretariatTerminalResult(admitted, authority, scope) {
|
|
15928
16219
|
return settleLawfulSecretariatTerminalResult(admitted, authority, scope);
|
|
@@ -16164,7 +16455,7 @@ async function settleLawfulMergerTerminalResult(admitted, authority, options, sc
|
|
|
16164
16455
|
const residual = boundErroredToolCandidate(entries, index, message, MERGER_OUTPUT_TOOL_NAME);
|
|
16165
16456
|
if (residual === void 0) continue;
|
|
16166
16457
|
const candidate = residual.candidate;
|
|
16167
|
-
const details =
|
|
16458
|
+
const details = isRecord12(candidate) ? candidate : { candidate };
|
|
16168
16459
|
const failed = await settleFailureTerminalResult(
|
|
16169
16460
|
admitted,
|
|
16170
16461
|
{
|
|
@@ -16613,7 +16904,7 @@ var init_seat_ticket_binding = __esm({
|
|
|
16613
16904
|
});
|
|
16614
16905
|
|
|
16615
16906
|
// src/session-identity.ts
|
|
16616
|
-
import { mkdir as mkdir3, readFile as
|
|
16907
|
+
import { mkdir as mkdir3, readFile as readFile18, rename as rename2, writeFile as writeFile8 } from "node:fs/promises";
|
|
16617
16908
|
import { dirname as dirname15, join as join27 } from "node:path";
|
|
16618
16909
|
function createSessionIdentityAuthority(authority, sessionBindingFile) {
|
|
16619
16910
|
const bindingPath = (principal) => join27(authority.decode(principal).sessionDirectory, sessionBindingFile);
|
|
@@ -16623,7 +16914,7 @@ function createSessionIdentityAuthority(authority, sessionBindingFile) {
|
|
|
16623
16914
|
},
|
|
16624
16915
|
async load(principal) {
|
|
16625
16916
|
try {
|
|
16626
|
-
const value = JSON.parse(await
|
|
16917
|
+
const value = JSON.parse(await readFile18(bindingPath(principal), "utf8"));
|
|
16627
16918
|
if (typeof value !== "object" || value === null || typeof value.sessionId !== "string") {
|
|
16628
16919
|
throw new Error("durable session binding is invalid");
|
|
16629
16920
|
}
|
|
@@ -16662,7 +16953,7 @@ var init_session_identity = __esm({
|
|
|
16662
16953
|
});
|
|
16663
16954
|
|
|
16664
16955
|
// src/session-dialogue.ts
|
|
16665
|
-
function
|
|
16956
|
+
function isRecord13(value) {
|
|
16666
16957
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
16667
16958
|
}
|
|
16668
16959
|
function nativeEventId(row) {
|
|
@@ -16672,7 +16963,7 @@ function nativeEventId(row) {
|
|
|
16672
16963
|
}
|
|
16673
16964
|
for (const nestKey of ["message", "payload"]) {
|
|
16674
16965
|
const nested = row[nestKey];
|
|
16675
|
-
if (!
|
|
16966
|
+
if (!isRecord13(nested)) continue;
|
|
16676
16967
|
for (const key of ["uuid", "id"]) {
|
|
16677
16968
|
const value = nested[key];
|
|
16678
16969
|
if (typeof value === "string" && value !== "") return value;
|
|
@@ -16685,19 +16976,19 @@ function textParts(content) {
|
|
|
16685
16976
|
if (!Array.isArray(content)) return [];
|
|
16686
16977
|
const out = [];
|
|
16687
16978
|
for (const part of content) {
|
|
16688
|
-
if (!
|
|
16979
|
+
if (!isRecord13(part) || !SPEAKER_TEXT_PART_TYPES.has(String(part.type))) continue;
|
|
16689
16980
|
const text = part.text;
|
|
16690
16981
|
if (typeof text === "string" && text !== "") out.push(text);
|
|
16691
16982
|
}
|
|
16692
16983
|
return out;
|
|
16693
16984
|
}
|
|
16694
16985
|
function responseItemMessage(row) {
|
|
16695
|
-
if (row.type !== "response_item" || !
|
|
16986
|
+
if (row.type !== "response_item" || !isRecord13(row.payload)) return void 0;
|
|
16696
16987
|
if (row.payload.type !== "message") return void 0;
|
|
16697
16988
|
return row.payload;
|
|
16698
16989
|
}
|
|
16699
16990
|
function messageBody(row) {
|
|
16700
|
-
if (
|
|
16991
|
+
if (isRecord13(row.message)) return row.message;
|
|
16701
16992
|
return responseItemMessage(row);
|
|
16702
16993
|
}
|
|
16703
16994
|
function speakerOf(message) {
|
|
@@ -16707,7 +16998,7 @@ function speakerOf(message) {
|
|
|
16707
16998
|
}
|
|
16708
16999
|
function codexContentItemKinds(message) {
|
|
16709
17000
|
const pass = message.internal_chat_message_metadata_passthrough;
|
|
16710
|
-
if (!
|
|
17001
|
+
if (!isRecord13(pass) || !Array.isArray(pass.content_item_kinds)) return void 0;
|
|
16711
17002
|
const kinds = [];
|
|
16712
17003
|
for (const kind of pass.content_item_kinds) {
|
|
16713
17004
|
if (typeof kind === "string" && kind !== "") kinds.push(kind);
|
|
@@ -16736,7 +17027,7 @@ function isFixedNonOwnerEnqueueShape(content) {
|
|
|
16736
17027
|
return hasFixedOpenTagPrefix(content, TASK_NOTIFICATION_OPEN_TAG);
|
|
16737
17028
|
}
|
|
16738
17029
|
function materializationOriginKind(row) {
|
|
16739
|
-
if (!
|
|
17030
|
+
if (!isRecord13(row.origin)) return void 0;
|
|
16740
17031
|
const kind = row.origin.kind;
|
|
16741
17032
|
return typeof kind === "string" && kind !== "" ? kind : void 0;
|
|
16742
17033
|
}
|
|
@@ -16784,7 +17075,7 @@ var init_session_dialogue = __esm({
|
|
|
16784
17075
|
|
|
16785
17076
|
// src/ticket-provenance.ts
|
|
16786
17077
|
import { createHash as createHash7 } from "node:crypto";
|
|
16787
|
-
import { readFile as
|
|
17078
|
+
import { readFile as readFile19 } from "node:fs/promises";
|
|
16788
17079
|
import { basename as basename8, dirname as dirname16, join as join28, resolve as resolve12 } from "node:path";
|
|
16789
17080
|
function dialogueSessionSourceRoots(home) {
|
|
16790
17081
|
const machineHome = typeof home === "string" && home.trim() !== "" ? home : packageMachineHome();
|
|
@@ -16880,7 +17171,7 @@ async function readTicketProvenance(ticketNumber, cwd, home) {
|
|
|
16880
17171
|
const { recordFile } = resolveTicketProvenanceVolume(ticketNumber, cwd, home);
|
|
16881
17172
|
let text;
|
|
16882
17173
|
try {
|
|
16883
|
-
text = await
|
|
17174
|
+
text = await readFile19(recordFile, "utf8");
|
|
16884
17175
|
} catch (error) {
|
|
16885
17176
|
if (error.code === "ENOENT") {
|
|
16886
17177
|
return {
|
|
@@ -17360,7 +17651,7 @@ __export(case_dossier_delivery_exports, {
|
|
|
17360
17651
|
loadCaseDossierReadingMaterial: () => loadCaseDossierReadingMaterial,
|
|
17361
17652
|
projectCaseDossierPointerSection: () => projectCaseDossierPointerSection
|
|
17362
17653
|
});
|
|
17363
|
-
import { mkdtemp as mkdtemp3, readFile as
|
|
17654
|
+
import { mkdtemp as mkdtemp3, readFile as readFile20, rm as rm3, writeFile as writeFile9 } from "node:fs/promises";
|
|
17364
17655
|
import { tmpdir as tmpdir3 } from "node:os";
|
|
17365
17656
|
import { join as join29 } from "node:path";
|
|
17366
17657
|
async function projectCaseDossierPointerSection(input) {
|
|
@@ -17412,7 +17703,7 @@ async function loadCaseDossierReadingMaterial(runDirectory) {
|
|
|
17412
17703
|
);
|
|
17413
17704
|
let section;
|
|
17414
17705
|
try {
|
|
17415
|
-
section = await
|
|
17706
|
+
section = await readFile20(frozenPath, "utf8");
|
|
17416
17707
|
} catch (error) {
|
|
17417
17708
|
if (error.code === "ENOENT") return void 0;
|
|
17418
17709
|
throw error;
|
|
@@ -17435,7 +17726,7 @@ var init_case_dossier_delivery = __esm({
|
|
|
17435
17726
|
});
|
|
17436
17727
|
|
|
17437
17728
|
// src/host-transition-prior-native.ts
|
|
17438
|
-
import { access as access3, readdir as
|
|
17729
|
+
import { access as access3, readdir as readdir8 } from "node:fs/promises";
|
|
17439
17730
|
import { dirname as dirname17, join as join30 } from "node:path";
|
|
17440
17731
|
function isEnoent3(error) {
|
|
17441
17732
|
return typeof error === "object" && error !== null && error.code === "ENOENT";
|
|
@@ -17453,7 +17744,7 @@ async function listSitianRecordPaths(sessionParent) {
|
|
|
17453
17744
|
const sessionRoot = dirname17(sessionParent);
|
|
17454
17745
|
let entries;
|
|
17455
17746
|
try {
|
|
17456
|
-
entries = await
|
|
17747
|
+
entries = await readdir8(sessionRoot, { withFileTypes: true });
|
|
17457
17748
|
} catch (error) {
|
|
17458
17749
|
if (isEnoent3(error)) return [];
|
|
17459
17750
|
throw error;
|
|
@@ -17596,7 +17887,7 @@ async function ensureRealArtifactsDirectory(runDirectory) {
|
|
|
17596
17887
|
throw new Error("run artifact retention: artifacts path is not a real directory");
|
|
17597
17888
|
}
|
|
17598
17889
|
} catch (error) {
|
|
17599
|
-
if (!
|
|
17890
|
+
if (!isMissingPathError5(error)) throw error;
|
|
17600
17891
|
await mkdir4(artifactsDir, { recursive: true });
|
|
17601
17892
|
const created = await lstat6(artifactsDir);
|
|
17602
17893
|
if (created.isSymbolicLink() || !created.isDirectory()) {
|
|
@@ -17628,7 +17919,7 @@ function serializeThrownValue(value, depth = 0, seen = /* @__PURE__ */ new WeakS
|
|
|
17628
17919
|
}
|
|
17629
17920
|
return value;
|
|
17630
17921
|
}
|
|
17631
|
-
function
|
|
17922
|
+
function isMissingPathError5(error) {
|
|
17632
17923
|
return error instanceof Error && "code" in error && error.code === "ENOENT";
|
|
17633
17924
|
}
|
|
17634
17925
|
function transferNestedValue(value, depth, seen) {
|
|
@@ -20250,7 +20541,9 @@ async function runPublicCountersign(argv, env, io, parseCountersignArgv2) {
|
|
|
20250
20541
|
{
|
|
20251
20542
|
instruction: parsed.instruction,
|
|
20252
20543
|
projectRoot: admitted.projectRoot,
|
|
20253
|
-
failureLabel: "unbound summons"
|
|
20544
|
+
failureLabel: "unbound summons",
|
|
20545
|
+
// #969: parent durable ticket is the resume/bind key (ADR 0079).
|
|
20546
|
+
...env.boundTicketNumber === void 0 ? {} : { boundTicketNumber: env.boundTicketNumber }
|
|
20254
20547
|
},
|
|
20255
20548
|
env,
|
|
20256
20549
|
io
|
|
@@ -20302,12 +20595,16 @@ async function runPublicCountersign(argv, env, io, parseCountersignArgv2) {
|
|
|
20302
20595
|
);
|
|
20303
20596
|
}
|
|
20304
20597
|
if (outcome.identity.kind === "ticket") {
|
|
20305
|
-
|
|
20306
|
-
typedTicket = assertedTicket;
|
|
20598
|
+
typedTicket = isSafePositiveTicketNumber(env.boundTicketNumber) ? env.boundTicketNumber : outcome.identity.ticketNumber;
|
|
20307
20599
|
typedCourtTicketNumbers = outcome.identity.courtTicketNumbers;
|
|
20600
|
+
} else if (isSafePositiveTicketNumber(env.boundTicketNumber)) {
|
|
20601
|
+
typedTicket = env.boundTicketNumber;
|
|
20602
|
+
}
|
|
20603
|
+
if (typedTicket !== void 0) {
|
|
20604
|
+
const resumeInstruction = env.reviewReask ?? env.gateReviewInstruction ?? parsed.instruction;
|
|
20308
20605
|
const summons = {
|
|
20309
|
-
instruction:
|
|
20310
|
-
instructionEmpty:
|
|
20606
|
+
instruction: resumeInstruction,
|
|
20607
|
+
instructionEmpty: resumeInstruction.trim() === ""
|
|
20311
20608
|
};
|
|
20312
20609
|
const resumed = await tryResumeSameTicketSeatRun({
|
|
20313
20610
|
home: env.home,
|
|
@@ -20389,7 +20686,9 @@ async function runPublicCountersign(argv, env, io, parseCountersignArgv2) {
|
|
|
20389
20686
|
...env.correlationId === void 0 || env.correlationId.trim() === "" ? {} : { correlationId: env.correlationId },
|
|
20390
20687
|
continuation: {
|
|
20391
20688
|
kind: "initial",
|
|
20392
|
-
|
|
20689
|
+
// #969/#879: gate path first mint carries parent payload as dialogue content;
|
|
20690
|
+
// ordinary public entry keeps package transport prompt.
|
|
20691
|
+
prompt: env.reviewReask ?? env.gateReviewInstruction ?? buildCountersignTransportPrompt(
|
|
20393
20692
|
admitted,
|
|
20394
20693
|
engineSessionMaterialFromOptions({
|
|
20395
20694
|
...pickEngineAxis(env),
|
|
@@ -21531,6 +21830,25 @@ async function summonGateOfficer(options) {
|
|
|
21531
21830
|
...common
|
|
21532
21831
|
});
|
|
21533
21832
|
}
|
|
21833
|
+
if (options.officer === "countersign") {
|
|
21834
|
+
const { runIdFromRunDirectory: runIdFromRunDirectory2 } = await Promise.resolve().then(() => (init_run_terminal_artifacts(), run_terminal_artifacts_exports));
|
|
21835
|
+
const correlationId = runIdFromRunDirectory2(options.sourceRunDirectory);
|
|
21836
|
+
if (correlationId === void 0 || correlationId.trim() === "") {
|
|
21837
|
+
throw new Error(
|
|
21838
|
+
`countersign gate summon requires parent runId from sourceRunDirectory: ${options.sourceRunDirectory}`
|
|
21839
|
+
);
|
|
21840
|
+
}
|
|
21841
|
+
const { readBoardTicketNumber: readBoardTicketNumber2 } = await Promise.resolve().then(() => (init_run_ticket_number(), run_ticket_number_exports));
|
|
21842
|
+
const parentTicket = await readBoardTicketNumber2(options.sourceRunDirectory);
|
|
21843
|
+
const instruction = options.reask ?? gateReviewInstruction ?? "";
|
|
21844
|
+
return summonPublicRole({
|
|
21845
|
+
role: "countersign",
|
|
21846
|
+
argv: ["--project", options.cwd, "--", instruction],
|
|
21847
|
+
...common,
|
|
21848
|
+
correlationId,
|
|
21849
|
+
...parentTicket === void 0 ? {} : { boundTicketNumber: parentTicket }
|
|
21850
|
+
});
|
|
21851
|
+
}
|
|
21534
21852
|
return summonPublicRole({
|
|
21535
21853
|
role: "inspector",
|
|
21536
21854
|
argv: [`\u5377\u5B97\u6307\u9488\uFF1A${options.sourceRunDirectory}`],
|
|
@@ -22084,7 +22402,7 @@ var init_archivist_record_entry = __esm({
|
|
|
22084
22402
|
import { randomUUID as randomUUID11 } from "node:crypto";
|
|
22085
22403
|
|
|
22086
22404
|
// src/role-runtime-dependencies.ts
|
|
22087
|
-
import { readFile as
|
|
22405
|
+
import { readFile as readFile23 } from "node:fs/promises";
|
|
22088
22406
|
import { join as join40 } from "node:path";
|
|
22089
22407
|
|
|
22090
22408
|
// src/canonical-skill-binding.ts
|
|
@@ -23106,7 +23424,7 @@ ${helpContext}
|
|
|
23106
23424
|
// src/navigator-work-context.ts
|
|
23107
23425
|
init_doctor_evidence();
|
|
23108
23426
|
init_host_contracts();
|
|
23109
|
-
import { readFile as
|
|
23427
|
+
import { readFile as readFile21 } from "node:fs/promises";
|
|
23110
23428
|
import { resolve as resolve17 } from "node:path";
|
|
23111
23429
|
init_notary_source_run();
|
|
23112
23430
|
init_packaged_role_registry();
|
|
@@ -23119,7 +23437,7 @@ function navigatorInputReference(getFlag, role) {
|
|
|
23119
23437
|
}
|
|
23120
23438
|
async function loadNavigatorWorkContext(options) {
|
|
23121
23439
|
const reference = navigatorInputReference(options.getFlag, options.role);
|
|
23122
|
-
const input = reference === void 0 || options.role === "doctor" || options.role === "notary" ? void 0 : await
|
|
23440
|
+
const input = reference === void 0 || options.role === "doctor" || options.role === "notary" ? void 0 : await readFile21(reference, "utf8");
|
|
23123
23441
|
const subjectRoot = subjectPath(reference ?? options.context.sessionManager.getSessionDir(), options.context.cwd);
|
|
23124
23442
|
let subjectKey = reference === void 0 ? subjectRoot : navigatorSubjectKeyForInput(subjectRoot, reference, options.context.cwd);
|
|
23125
23443
|
let subject = input ?? `work subject: ${subjectKey}`;
|
|
@@ -23176,7 +23494,7 @@ async function loadNavigatorWorkContext(options) {
|
|
|
23176
23494
|
let authorityMaterial;
|
|
23177
23495
|
for (const path of authorityFiles) {
|
|
23178
23496
|
try {
|
|
23179
|
-
const content = await
|
|
23497
|
+
const content = await readFile21(path, "utf8");
|
|
23180
23498
|
if (content.trim() !== "") {
|
|
23181
23499
|
authorityMaterial = content;
|
|
23182
23500
|
break;
|
|
@@ -23667,7 +23985,7 @@ init_collector_evidence();
|
|
|
23667
23985
|
init_collector_github();
|
|
23668
23986
|
|
|
23669
23987
|
// src/collector-handbook.ts
|
|
23670
|
-
import { readFile as
|
|
23988
|
+
import { readFile as readFile22 } from "node:fs/promises";
|
|
23671
23989
|
import { join as join38, sep as sep6 } from "node:path";
|
|
23672
23990
|
|
|
23673
23991
|
// src/atomic-write.ts
|
|
@@ -23830,7 +24148,7 @@ function createCollectorHandbookStore(input) {
|
|
|
23830
24148
|
ensureRealDirectoryTree(input.ledgerHome, parentDir2);
|
|
23831
24149
|
assertLedgerFileInsideHome(path, input.ledgerHome);
|
|
23832
24150
|
try {
|
|
23833
|
-
const body = await
|
|
24151
|
+
const body = await readFile22(path, "utf8");
|
|
23834
24152
|
assertHandbookBudget(body, "\u6B63\u6587");
|
|
23835
24153
|
return body;
|
|
23836
24154
|
} catch (error) {
|
|
@@ -25277,7 +25595,7 @@ function uninstallPackageWorkerHooks(cwd) {
|
|
|
25277
25595
|
rmOwnedDir(resolve19(gitDir, HOOKS_DIR));
|
|
25278
25596
|
}
|
|
25279
25597
|
}
|
|
25280
|
-
function
|
|
25598
|
+
function isRecord14(value) {
|
|
25281
25599
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
25282
25600
|
}
|
|
25283
25601
|
function unfinishedReasonPresent(details) {
|
|
@@ -25293,7 +25611,7 @@ function readGateState(session) {
|
|
|
25293
25611
|
if (entry.type !== "custom") continue;
|
|
25294
25612
|
if (entry.customType === WORKER_COMMIT_BASELINE_ENTRY_TYPE) {
|
|
25295
25613
|
const data = entry.data;
|
|
25296
|
-
if (
|
|
25614
|
+
if (isRecord14(data) && (data.head === null || typeof data.head === "string")) {
|
|
25297
25615
|
baseline = data.head;
|
|
25298
25616
|
}
|
|
25299
25617
|
} else if (entry.customType === WORKER_COMMIT_REMINDER_BOUNCE_ENTRY_TYPE) {
|
|
@@ -25844,7 +26162,6 @@ ${JSON.stringify(admitted)}
|
|
|
25844
26162
|
// src/role-runtime.ts
|
|
25845
26163
|
init_navigator_invocation_identity();
|
|
25846
26164
|
init_gatekeeper_role();
|
|
25847
|
-
init_gatekeeper_role();
|
|
25848
26165
|
init_submission_errors();
|
|
25849
26166
|
init_doctor_contracts();
|
|
25850
26167
|
init_doctor_evidence();
|
|
@@ -26327,15 +26644,80 @@ ${error.message}`
|
|
|
26327
26644
|
}
|
|
26328
26645
|
var COUNTERSIGN_QUEUE_STATUSES = /* @__PURE__ */ new Set(["converged", "continue", "escalate"]);
|
|
26329
26646
|
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";
|
|
26330
|
-
|
|
26647
|
+
var SECRETARIAT_SUBMISSION_GATE_HOSTS = /* @__PURE__ */ new Set(["codex", "claude", "grok-build"]);
|
|
26648
|
+
var SECRETARIAT_QUEUE_STATUSES = /* @__PURE__ */ new Set(["converged", "escalate"]);
|
|
26649
|
+
var SECRETARIAT_STATUS_REASK = "secretariatStatus \u4E0D\u662F converged\u3001escalate \u4E4B\u4E00\u3002\u8BF7\u91CD\u65B0\u4EA4\u5377\uFF0Cstatus \u5199\u660E\u5176\u4E00\u3002";
|
|
26650
|
+
function createSecretariatRoleRuntime(roleHost, dependencies, hostActions) {
|
|
26331
26651
|
let parentInstruction = "";
|
|
26652
|
+
const beforeAccept = hostActions !== void 0 && roleHost.requireGatekeeperPass !== void 0 ? async ({ toolCallId, parameters, signal, ctx }) => {
|
|
26653
|
+
const host = typeof ctx.host === "string" && ctx.host.trim() !== "" ? ctx.host.trim() : void 0;
|
|
26654
|
+
if (host === void 0 || !SECRETARIAT_SUBMISSION_GATE_HOSTS.has(host)) {
|
|
26655
|
+
return void 0;
|
|
26656
|
+
}
|
|
26657
|
+
const record4 = parameters !== null && typeof parameters === "object" && !Array.isArray(parameters) ? parameters : void 0;
|
|
26658
|
+
const status = record4 !== void 0 && typeof record4.secretariatStatus === "string" ? record4.secretariatStatus : void 0;
|
|
26659
|
+
if (status === void 0 || !SECRETARIAT_QUEUE_STATUSES.has(status)) {
|
|
26660
|
+
throw new ParentQueueReaskError(SECRETARIAT_STATUS_REASK);
|
|
26661
|
+
}
|
|
26662
|
+
if (status === "escalate") {
|
|
26663
|
+
return void 0;
|
|
26664
|
+
}
|
|
26665
|
+
try {
|
|
26666
|
+
const pass = await roleHost.requireGatekeeperPass({
|
|
26667
|
+
context: ctx,
|
|
26668
|
+
subject: { kind: "secretariat_verdict" },
|
|
26669
|
+
...signal === void 0 ? {} : { signal },
|
|
26670
|
+
hostActions,
|
|
26671
|
+
toolCallId,
|
|
26672
|
+
// #879: this-turn typed payload — identity-bound at submit site.
|
|
26673
|
+
submission: parameters
|
|
26674
|
+
});
|
|
26675
|
+
if (pass !== void 0 && pass !== null && typeof pass === "object" && "receipt" in pass) {
|
|
26676
|
+
const {
|
|
26677
|
+
SECRETARIAT_GATE_OFFICER_ENTRY_TYPE: SECRETARIAT_GATE_OFFICER_ENTRY_TYPE2
|
|
26678
|
+
} = await Promise.resolve().then(() => (init_secretariat_contracts(), secretariat_contracts_exports));
|
|
26679
|
+
const runId = typeof pass.runId === "string" && pass.runId.trim() !== "" ? pass.runId : void 0;
|
|
26680
|
+
ctx.sessionManager.appendCustomEntry?.(SECRETARIAT_GATE_OFFICER_ENTRY_TYPE2, {
|
|
26681
|
+
officer: "countersign",
|
|
26682
|
+
receipt: pass.receipt,
|
|
26683
|
+
...runId === void 0 ? {} : { runId }
|
|
26684
|
+
});
|
|
26685
|
+
}
|
|
26686
|
+
return void 0;
|
|
26687
|
+
} catch (error) {
|
|
26688
|
+
if (error instanceof GatekeeperDecisionError && error.result.status === "escalate") {
|
|
26689
|
+
const receipt = error.result.receipt;
|
|
26690
|
+
const receiptRecord = receipt !== null && typeof receipt === "object" && !Array.isArray(receipt) ? receipt : void 0;
|
|
26691
|
+
const runId = typeof error.result.runId === "string" && error.result.runId.trim() !== "" ? error.result.runId : void 0;
|
|
26692
|
+
const {
|
|
26693
|
+
SECRETARIAT_GATE_OFFICER_ENTRY_TYPE: SECRETARIAT_GATE_OFFICER_ENTRY_TYPE2
|
|
26694
|
+
} = await Promise.resolve().then(() => (init_secretariat_contracts(), secretariat_contracts_exports));
|
|
26695
|
+
ctx.sessionManager.appendCustomEntry?.(SECRETARIAT_GATE_OFFICER_ENTRY_TYPE2, {
|
|
26696
|
+
officer: "countersign",
|
|
26697
|
+
receipt,
|
|
26698
|
+
...runId === void 0 ? {} : { runId }
|
|
26699
|
+
});
|
|
26700
|
+
const { buildAuditEscalationResult: buildAuditEscalationResult2 } = await Promise.resolve().then(() => (init_audit_escalation(), audit_escalation_exports));
|
|
26701
|
+
return buildAuditEscalationResult2(
|
|
26702
|
+
{
|
|
26703
|
+
status: "escalate",
|
|
26704
|
+
officer: "countersign",
|
|
26705
|
+
...receiptRecord !== void 0 && Object.prototype.hasOwnProperty.call(receiptRecord, "decisionGate") ? { decisionGate: receiptRecord.decisionGate } : {}
|
|
26706
|
+
},
|
|
26707
|
+
receipt
|
|
26708
|
+
);
|
|
26709
|
+
}
|
|
26710
|
+
throw error;
|
|
26711
|
+
}
|
|
26712
|
+
} : void 0;
|
|
26332
26713
|
const base = createFiledOfficerRuntime(
|
|
26333
26714
|
roleHost,
|
|
26334
26715
|
{
|
|
26335
26716
|
role: "secretariat",
|
|
26336
26717
|
tool: SECRETARIAT_OUTPUT_TOOL_SPEC,
|
|
26337
26718
|
acceptedText: SECRETARIAT_ACCEPTED_TEXT,
|
|
26338
|
-
soulTag: "secretariat"
|
|
26719
|
+
soulTag: "secretariat",
|
|
26720
|
+
...beforeAccept === void 0 ? {} : { beforeAccept }
|
|
26339
26721
|
},
|
|
26340
26722
|
dependencies
|
|
26341
26723
|
);
|
|
@@ -27017,8 +27399,9 @@ function createRoleRuntimeExtension(dependencies) {
|
|
|
27017
27399
|
if (!dependencies.loadSecretariatSoul) throw new Error("Secretariat runtime dependencies are not configured");
|
|
27018
27400
|
return dependencies.loadSecretariatSoul();
|
|
27019
27401
|
},
|
|
27020
|
-
...dependencies.packageRoot === void 0 ? {} : { packageRoot: dependencies.packageRoot }
|
|
27021
|
-
|
|
27402
|
+
...dependencies.packageRoot === void 0 ? {} : { packageRoot: dependencies.packageRoot },
|
|
27403
|
+
...dependencies.hostAdapters === void 0 ? {} : { hostAdapters: dependencies.hostAdapters }
|
|
27404
|
+
}, hostActions);
|
|
27022
27405
|
const merger = createMergerRoleRuntime(roleHost, {
|
|
27023
27406
|
async loadSoul() {
|
|
27024
27407
|
if (!dependencies.loadMergerSoul) throw new Error("Merger runtime dependencies are not configured");
|
|
@@ -27371,12 +27754,12 @@ function createRoleRuntimeDependencies(packageRoot) {
|
|
|
27371
27754
|
loadRoleReferenceMaterials: loadPackagedRoleReferenceMaterials,
|
|
27372
27755
|
loadJudgeSoul: () => loadMainRoleSessionMaterials("judge"),
|
|
27373
27756
|
loadFixerSoul: () => loadMainRoleSessionMaterials("fixer"),
|
|
27374
|
-
loadFixPacket: (path) =>
|
|
27757
|
+
loadFixPacket: (path) => readFile23(path, "utf8"),
|
|
27375
27758
|
loadCoderSoul: () => loadMainRoleSessionMaterials("coder"),
|
|
27376
|
-
loadCoderTask: (path) =>
|
|
27759
|
+
loadCoderTask: (path) => readFile23(path, "utf8"),
|
|
27377
27760
|
loadReviewerSoul: () => loadMainRoleSessionMaterials("reviewer"),
|
|
27378
27761
|
loadCollectorSoul: () => loadMainRoleSessionMaterials("collector"),
|
|
27379
|
-
loadCollectorHandbookSeed: () =>
|
|
27762
|
+
loadCollectorHandbookSeed: () => readFile23(collectorHandbookSeedPath, "utf8"),
|
|
27380
27763
|
createCollectorTransport: () => createGhCollectorGitHubTransport(),
|
|
27381
27764
|
loadDoctorSoul: () => loadMainRoleSessionMaterials("doctor"),
|
|
27382
27765
|
loadDoctorCase,
|
|
@@ -27391,7 +27774,7 @@ function createRoleRuntimeDependencies(packageRoot) {
|
|
|
27391
27774
|
loadSecretariatSoul: () => loadMainRoleSessionMaterials("secretariat"),
|
|
27392
27775
|
loadNotarySourceRun: loadNotarySourceRunLocator,
|
|
27393
27776
|
loadMergerSoul: () => loadMainRoleSessionMaterials("merger"),
|
|
27394
|
-
loadMergerInput: async (path) => JSON.parse(await
|
|
27777
|
+
loadMergerInput: async (path) => JSON.parse(await readFile23(path, "utf8")),
|
|
27395
27778
|
async loadCanonicalSkillBinding(name) {
|
|
27396
27779
|
if (name === "tdd") {
|
|
27397
27780
|
return loadPackagedCanonicalSkillBinding(packageRoot, "tdd");
|
|
@@ -27417,7 +27800,7 @@ function createRoleRuntimeDependencies(packageRoot) {
|
|
|
27417
27800
|
authority: options.authority,
|
|
27418
27801
|
invocationId: options.invocationId,
|
|
27419
27802
|
loadSoul: () => loadMainRoleSessionMaterials("navigator"),
|
|
27420
|
-
loadRoutePlaybook: () =>
|
|
27803
|
+
loadRoutePlaybook: () => readFile23(navigatorRoutePlaybookPath, "utf8"),
|
|
27421
27804
|
loadRoleHelp: async (role) => formatNavigatorRoleHelp(role),
|
|
27422
27805
|
createSession: navigatorSessionFactory,
|
|
27423
27806
|
...options.contextError === void 0 ? {} : { contextError: options.contextError },
|
|
@@ -27451,6 +27834,7 @@ function createDefaultGateOfficerSummon(options) {
|
|
|
27451
27834
|
...options.home === void 0 ? {} : { home: options.home },
|
|
27452
27835
|
...options.packageRoot === void 0 ? {} : { packageRoot: options.packageRoot },
|
|
27453
27836
|
...options.roleTurnHost === void 0 ? {} : { roleTurnHost: options.roleTurnHost },
|
|
27837
|
+
...options.hostAdapters === void 0 ? {} : { hostAdapters: options.hostAdapters },
|
|
27454
27838
|
...options.createRunId === void 0 ? {} : { createRunId: options.createRunId }
|
|
27455
27839
|
});
|
|
27456
27840
|
};
|
|
@@ -27499,9 +27883,15 @@ async function requireGatekeeperPass(options) {
|
|
|
27499
27883
|
options.hostActions.failInfrastructure(error, options.context, options.toolCallId);
|
|
27500
27884
|
}
|
|
27501
27885
|
}
|
|
27502
|
-
if (gatekeeper.status === "pass")
|
|
27886
|
+
if (gatekeeper.status === "pass") {
|
|
27887
|
+
return {
|
|
27888
|
+
officer: projected.officer,
|
|
27889
|
+
receipt: gatekeeper.receipt,
|
|
27890
|
+
...typeof gatekeeper.runId === "string" && gatekeeper.runId.trim() !== "" ? { runId: gatekeeper.runId } : {}
|
|
27891
|
+
};
|
|
27892
|
+
}
|
|
27503
27893
|
if (gatekeeper.status === "needs_reask") {
|
|
27504
|
-
reask =
|
|
27894
|
+
reask = officerConclusionReask(projected.officer);
|
|
27505
27895
|
continue;
|
|
27506
27896
|
}
|
|
27507
27897
|
if (gatekeeper.status === "transport_failure") {
|
|
@@ -27511,6 +27901,9 @@ async function requireGatekeeperPass(options) {
|
|
|
27511
27901
|
});
|
|
27512
27902
|
options.hostActions.failInfrastructure(failure2, options.context, options.toolCallId);
|
|
27513
27903
|
}
|
|
27904
|
+
if (gatekeeper.status === "escalate" && options.subject.kind === "secretariat_verdict") {
|
|
27905
|
+
throw new GatekeeperDecisionError(gatekeeper);
|
|
27906
|
+
}
|
|
27514
27907
|
options.hostActions.bindSubmissionNonPass(options.toolCallId, gatekeeper);
|
|
27515
27908
|
throw new GatekeeperDecisionError(gatekeeper);
|
|
27516
27909
|
}
|
|
@@ -27733,17 +28126,26 @@ async function prepareRoleEnvelope(options) {
|
|
|
27733
28126
|
getActiveTools() {
|
|
27734
28127
|
return [...preferredTools];
|
|
27735
28128
|
},
|
|
27736
|
-
async requireGatekeeperPass(
|
|
27737
|
-
|
|
27738
|
-
|
|
27739
|
-
|
|
27740
|
-
|
|
28129
|
+
async requireGatekeeperPass(gateOptions) {
|
|
28130
|
+
const packageRoot = typeof options.dependencies.packageRoot === "string" ? options.dependencies.packageRoot : void 0;
|
|
28131
|
+
return requireGatekeeperPass({
|
|
28132
|
+
context: gateOptions.context,
|
|
28133
|
+
subject: gateOptions.subject,
|
|
28134
|
+
...gateOptions.signal === void 0 ? {} : { signal: gateOptions.signal },
|
|
27741
28135
|
hostActions: {
|
|
27742
|
-
failInfrastructure: (error, _context, toolCallId) =>
|
|
27743
|
-
bindSubmissionNonPass:
|
|
28136
|
+
failInfrastructure: (error, _context, toolCallId) => gateOptions.hostActions.failInfrastructure(error, gateOptions.context, toolCallId),
|
|
28137
|
+
bindSubmissionNonPass: gateOptions.hostActions.bindSubmissionNonPass
|
|
27744
28138
|
},
|
|
27745
|
-
toolCallId:
|
|
27746
|
-
...
|
|
28139
|
+
toolCallId: gateOptions.toolCallId,
|
|
28140
|
+
...gateOptions.submission === void 0 ? {} : { submission: gateOptions.submission },
|
|
28141
|
+
// #969: package root + home reach nested 给事中/符宝郎 summons.
|
|
28142
|
+
// hostAdapters (when set on deps) forward nested seat selection — production unset.
|
|
28143
|
+
summonOfficer: createDefaultGateOfficerSummon({
|
|
28144
|
+
cwd: gateOptions.context.cwd ?? request.cwd,
|
|
28145
|
+
home: request.home,
|
|
28146
|
+
...packageRoot === void 0 ? {} : { packageRoot },
|
|
28147
|
+
...options.dependencies.hostAdapters === void 0 ? {} : { hostAdapters: options.dependencies.hostAdapters }
|
|
28148
|
+
})
|
|
27747
28149
|
});
|
|
27748
28150
|
},
|
|
27749
28151
|
on(...registration) {
|