@akagilnc/pi-workflow-roles 0.1.4021 → 0.1.4062
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 +682 -355
- package/dist/doctor-auditor.js +1 -1
- package/dist/dossier-resolution.js +21 -8
- package/dist/gatekeeper-role.js +34 -27
- package/dist/headless-host/description.js +7 -8
- package/dist/headless-host/production-host.js +709 -369
- package/dist/host-contracts.js +16 -0
- package/dist/inspector-contracts.js +8 -0
- package/dist/navigator-attendance.js +2 -0
- package/dist/navigator-public-session.js +18 -34
- package/dist/navigator-session-contracts.js +19 -0
- package/dist/packaged-role-registry.js +1 -1
- package/dist/pi/known-failure.js +3 -4
- package/dist/pi/role-turn-host.js +43 -13
- package/dist/public-cli/auto-resume.js +20 -7
- package/dist/public-cli/case-dossier-delivery.js +60 -1
- package/dist/public-cli/diarist-run.js +9 -23
- package/dist/public-cli/inspector-run.js +17 -3
- package/dist/public-cli/instruction-seat-run.js +12 -7
- package/dist/public-cli/judge-run.js +3 -1
- package/dist/public-cli/main.js +440 -222
- package/dist/public-cli/notary-run.js +7 -4
- package/dist/public-cli/post-admission.js +66 -59
- package/dist/public-cli/run-lifecycle.js +3 -0
- package/dist/public-cli/settlement.js +78 -58
- package/dist/public-cli/terminal.js +1 -11
- package/dist/public-role-summons.js +8 -0
- package/dist/submission-ledger.js +139 -19
- package/dist/user-dialogue-stdin.js +33 -0
- package/extensions/role-runtime.ts +1 -0
- package/package.json +1 -1
- package/resources/836-deleted-machine-instruction-inventory.md +1 -1
- package/src/doctor-auditor.ts +1 -1
- package/src/dossier-resolution.ts +26 -8
- package/src/external-host-turn-loop.ts +9 -0
- package/src/gatekeeper-pass-envelope.ts +6 -0
- package/src/gatekeeper-role.ts +47 -28
- package/src/headless-host/description.ts +8 -11
- package/src/headless-host/role-turn-host.ts +20 -5
- package/src/host-contracts.ts +30 -7
- package/src/inspector-contracts.ts +7 -0
- package/src/judge-role.ts +4 -0
- package/src/navigator-attendance.ts +2 -0
- package/src/navigator-public-session.ts +19 -55
- package/src/navigator-session-contracts.ts +39 -0
- package/src/navigator-work-context.ts +3 -4
- package/src/notary-role.ts +1 -0
- package/src/packaged-role-registry.ts +1 -1
- package/src/pi/adapter.ts +19 -4
- package/src/pi/known-failure.ts +3 -4
- package/src/pi/role-turn-host.ts +48 -14
- package/src/public-cli/auto-resume.ts +57 -20
- package/src/public-cli/case-dossier-delivery.ts +86 -1
- package/src/public-cli/cli.ts +2 -2
- package/src/public-cli/collector-run.ts +3 -1
- package/src/public-cli/countersign-run.ts +34 -27
- package/src/public-cli/diarist-run.ts +10 -27
- package/src/public-cli/inspector-run.ts +26 -2
- package/src/public-cli/instruction-seat-run.ts +20 -10
- package/src/public-cli/invocation.ts +2 -0
- package/src/public-cli/judge-run.ts +3 -1
- package/src/public-cli/notary-run.ts +13 -4
- package/src/public-cli/post-admission.ts +74 -65
- package/src/public-cli/reviewer-run.ts +3 -1
- package/src/public-cli/run-lifecycle.ts +3 -0
- package/src/public-cli/settlement.ts +105 -80
- package/src/public-cli/terminal.ts +7 -16
- package/src/public-role-summons.ts +31 -7
- package/src/role-envelope.ts +9 -30
- package/src/role-runtime-dependencies.ts +1 -0
- package/src/role-runtime.ts +95 -19
- package/src/submission-ledger.ts +195 -26
- package/src/user-dialogue-stdin.ts +37 -0
- package/src/worker-role.ts +4 -0
|
@@ -790,9 +790,17 @@ var init_auditor_dossier_tool = __esm({
|
|
|
790
790
|
});
|
|
791
791
|
|
|
792
792
|
// src/readable-gate-item.ts
|
|
793
|
+
var readable_gate_item_exports = {};
|
|
794
|
+
__export(readable_gate_item_exports, {
|
|
795
|
+
joinReadableGateItems: () => joinReadableGateItems,
|
|
796
|
+
readableGateItem: () => readableGateItem
|
|
797
|
+
});
|
|
793
798
|
function readableGateItem(value) {
|
|
794
799
|
return typeof value === "string" ? value : JSON.stringify(value);
|
|
795
800
|
}
|
|
801
|
+
function joinReadableGateItems(items, separator = "; ") {
|
|
802
|
+
return items.map(readableGateItem).join(separator);
|
|
803
|
+
}
|
|
796
804
|
var init_readable_gate_item = __esm({
|
|
797
805
|
"src/readable-gate-item.ts"() {
|
|
798
806
|
"use strict";
|
|
@@ -859,12 +867,19 @@ var init_submission_errors = __esm({
|
|
|
859
867
|
});
|
|
860
868
|
|
|
861
869
|
// src/inspector-contracts.ts
|
|
862
|
-
var INSPECTOR_OUTPUT_TOOL_NAME, INSPECTOR_ACCEPTED_TEXT;
|
|
870
|
+
var INSPECTOR_OUTPUT_TOOL_NAME, INSPECTOR_ACCEPTED_TEXT, INSPECTOR_SOURCE_RUN_FLAG;
|
|
863
871
|
var init_inspector_contracts = __esm({
|
|
864
872
|
"src/inspector-contracts.ts"() {
|
|
865
873
|
"use strict";
|
|
866
874
|
INSPECTOR_OUTPUT_TOOL_NAME = "ak_inspector_output";
|
|
867
875
|
INSPECTOR_ACCEPTED_TEXT = "\u5BDF\u9662\u56DE\u6267\u5DF2\u63A5\u53D7";
|
|
876
|
+
INSPECTOR_SOURCE_RUN_FLAG = {
|
|
877
|
+
name: "ak-inspector-source-run",
|
|
878
|
+
definition: {
|
|
879
|
+
description: "\u5BDF\u9662\u521D\u94F8\u7ED1\u5B9A\u7684\u7236 run \u7EDD\u5BF9\u8DEF\u5F84",
|
|
880
|
+
type: "string"
|
|
881
|
+
}
|
|
882
|
+
};
|
|
868
883
|
}
|
|
869
884
|
});
|
|
870
885
|
|
|
@@ -1169,6 +1184,15 @@ var init_durable_principal = __esm({
|
|
|
1169
1184
|
});
|
|
1170
1185
|
|
|
1171
1186
|
// src/host-contracts.ts
|
|
1187
|
+
function isOfficerReviewSeat(role) {
|
|
1188
|
+
return role === "notary" || role === "inspector" || role === "auditor";
|
|
1189
|
+
}
|
|
1190
|
+
function runDirectoryFromHostContext(context) {
|
|
1191
|
+
return typeof context.runDirectory === "string" && context.runDirectory.trim() !== "" ? context.runDirectory : void 0;
|
|
1192
|
+
}
|
|
1193
|
+
function courtAttemptIdFromHostContext(context) {
|
|
1194
|
+
return typeof context.courtAttemptId === "string" && context.courtAttemptId.trim() !== "" ? context.courtAttemptId : void 0;
|
|
1195
|
+
}
|
|
1172
1196
|
var ExplicitInternalActivationError;
|
|
1173
1197
|
var init_host_contracts = __esm({
|
|
1174
1198
|
"src/host-contracts.ts"() {
|
|
@@ -1901,7 +1925,7 @@ var init_packaged_role_registry = __esm({
|
|
|
1901
1925
|
role: "inspector",
|
|
1902
1926
|
phases: [null],
|
|
1903
1927
|
outputTool: INSPECTOR_OUTPUT_TOOL_NAME,
|
|
1904
|
-
inputFlag:
|
|
1928
|
+
inputFlag: "ak-inspector-source-run",
|
|
1905
1929
|
phaseFlag: void 0,
|
|
1906
1930
|
activationStage: "load-and-install",
|
|
1907
1931
|
sessionMaterials: INSPECTOR_SESSION_MATERIALS
|
|
@@ -2005,6 +2029,18 @@ var init_role_activation_flags = __esm({
|
|
|
2005
2029
|
}
|
|
2006
2030
|
});
|
|
2007
2031
|
|
|
2032
|
+
// src/user-dialogue-stdin.ts
|
|
2033
|
+
function encodeUserDialogueStdin(body) {
|
|
2034
|
+
return JSON.stringify({ kind: USER_DIALOGUE_STDIN_KIND, body });
|
|
2035
|
+
}
|
|
2036
|
+
var USER_DIALOGUE_STDIN_KIND;
|
|
2037
|
+
var init_user_dialogue_stdin = __esm({
|
|
2038
|
+
"src/user-dialogue-stdin.ts"() {
|
|
2039
|
+
"use strict";
|
|
2040
|
+
USER_DIALOGUE_STDIN_KIND = "ak-user-dialogue";
|
|
2041
|
+
}
|
|
2042
|
+
});
|
|
2043
|
+
|
|
2008
2044
|
// src/sitian-contracts.ts
|
|
2009
2045
|
function attachDirectErrnoCode(error, cause) {
|
|
2010
2046
|
if (cause === null || typeof cause !== "object" || !("code" in cause)) return;
|
|
@@ -2378,11 +2414,6 @@ function applyPiNativeSkillInvocation(methods, prompt) {
|
|
|
2378
2414
|
}
|
|
2379
2415
|
function buildPiTurnExtraArgs(request, authority, extraPiArgs = []) {
|
|
2380
2416
|
const { sessionFile, sessionDirectory } = authority.decode(request.principal);
|
|
2381
|
-
const rawPrompt = request.continuation.kind === "initial" || request.continuation.kind === "resume" ? request.continuation.prompt : (() => {
|
|
2382
|
-
const _exhaustive = request.continuation;
|
|
2383
|
-
return _exhaustive;
|
|
2384
|
-
})();
|
|
2385
|
-
const prompt = applyPiNativeSkillInvocation(request.methods, rawPrompt);
|
|
2386
2417
|
return [
|
|
2387
2418
|
"--no-skills",
|
|
2388
2419
|
...buildMethodArgs(request.methods),
|
|
@@ -2396,12 +2427,24 @@ function buildPiTurnExtraArgs(request, authority, extraPiArgs = []) {
|
|
|
2396
2427
|
...extraPiArgs,
|
|
2397
2428
|
// Envelope assembly = projectActivationFlags; pi only renders argv pairs.
|
|
2398
2429
|
...activationFlagsToPiArgv(projectActivationFlags(request)),
|
|
2430
|
+
...piEngineModelArgs(request),
|
|
2399
2431
|
"--mode",
|
|
2400
2432
|
"json",
|
|
2401
|
-
...buildSeatModelCliArgs(request.model)
|
|
2402
|
-
prompt
|
|
2433
|
+
...buildSeatModelCliArgs(request.model)
|
|
2403
2434
|
];
|
|
2404
2435
|
}
|
|
2436
|
+
function piEngineModelArgs(request) {
|
|
2437
|
+
const model = normalizeEngineName(request.engineModel);
|
|
2438
|
+
if (model === void 0) return [];
|
|
2439
|
+
return [`--${ENGINE_MODEL_FLAG_NAME}`, model];
|
|
2440
|
+
}
|
|
2441
|
+
function piUserDialogueBody(request) {
|
|
2442
|
+
const rawPrompt = request.continuation.kind === "initial" || request.continuation.kind === "resume" ? request.continuation.prompt : (() => {
|
|
2443
|
+
const _exhaustive = request.continuation;
|
|
2444
|
+
return _exhaustive;
|
|
2445
|
+
})();
|
|
2446
|
+
return applyPiNativeSkillInvocation(request.methods, rawPrompt);
|
|
2447
|
+
}
|
|
2405
2448
|
async function resolveSelectedPi(command, cwd, env) {
|
|
2406
2449
|
const searchPath = env.PATH ?? (platform === "win32" ? process.env.PATH ?? "" : "/usr/bin:/bin");
|
|
2407
2450
|
const candidates = isAbsolute3(command) || command.includes("/") ? [resolve6(cwd, command)] : searchPath.split(delimiter).map((dir) => resolve6(cwd, dir, command));
|
|
@@ -2441,11 +2484,22 @@ function createDefaultPiSpawnRunner(options) {
|
|
|
2441
2484
|
const child = spawn2(piIdentity.executable, [...args], {
|
|
2442
2485
|
cwd: spawnOptions.cwd,
|
|
2443
2486
|
env: spawnOptions.env,
|
|
2444
|
-
stdio: ["
|
|
2487
|
+
stdio: ["pipe", "ignore", "pipe"]
|
|
2445
2488
|
});
|
|
2489
|
+
if (child.stdin === null) {
|
|
2490
|
+
throw new Error("Pi child stdin pipe was not created");
|
|
2491
|
+
}
|
|
2446
2492
|
if (child.stderr === null) {
|
|
2447
2493
|
throw new Error("Pi child stderr pipe was not created");
|
|
2448
2494
|
}
|
|
2495
|
+
let stdinDeliveryError;
|
|
2496
|
+
child.stdin.on("error", (error) => {
|
|
2497
|
+
stdinDeliveryError ??= error;
|
|
2498
|
+
});
|
|
2499
|
+
if (spawnOptions.stdin !== void 0) {
|
|
2500
|
+
child.stdin.write(spawnOptions.stdin);
|
|
2501
|
+
}
|
|
2502
|
+
child.stdin.end();
|
|
2449
2503
|
let stderr = "";
|
|
2450
2504
|
let timedOut = false;
|
|
2451
2505
|
let timer;
|
|
@@ -2498,6 +2552,10 @@ function createDefaultPiSpawnRunner(options) {
|
|
|
2498
2552
|
reject(executionError);
|
|
2499
2553
|
return;
|
|
2500
2554
|
}
|
|
2555
|
+
if (stdinDeliveryError !== void 0) {
|
|
2556
|
+
reject(stdinDeliveryError);
|
|
2557
|
+
return;
|
|
2558
|
+
}
|
|
2501
2559
|
resolveResult({
|
|
2502
2560
|
code,
|
|
2503
2561
|
stderr,
|
|
@@ -2521,7 +2579,8 @@ function createPiRoleTurnHost(config) {
|
|
|
2521
2579
|
return {
|
|
2522
2580
|
async executeTurn(request) {
|
|
2523
2581
|
let turnRequest = request;
|
|
2524
|
-
const
|
|
2582
|
+
const officerStationChild = request.stationChild === true && isOfficerReviewSeat(request.activation.role);
|
|
2583
|
+
const paths = !officerStationChild && request.hostTransition?.priorNativeKind === "sitian" ? request.hostTransition.priorNativePaths : void 0;
|
|
2525
2584
|
if (request.continuation.kind === "resume" && paths !== void 0 && paths.length > 0) {
|
|
2526
2585
|
turnRequest = {
|
|
2527
2586
|
...request,
|
|
@@ -2539,6 +2598,7 @@ ${paths.join("\n")}`
|
|
|
2539
2598
|
config.extraPiArgs ?? []
|
|
2540
2599
|
);
|
|
2541
2600
|
const args = buildExplicitInternalActivationArgs(roleEntry, extraArgs);
|
|
2601
|
+
const stdin = encodeUserDialogueStdin(piUserDialogueBody(turnRequest));
|
|
2542
2602
|
const env = {
|
|
2543
2603
|
...process.env,
|
|
2544
2604
|
HOME: request.home,
|
|
@@ -2570,6 +2630,7 @@ ${paths.join("\n")}`
|
|
|
2570
2630
|
return await spawnRunner(args, {
|
|
2571
2631
|
cwd: request.cwd,
|
|
2572
2632
|
env,
|
|
2633
|
+
stdin,
|
|
2573
2634
|
...timeoutMs === void 0 ? {} : { timeoutMs },
|
|
2574
2635
|
...request.signal === void 0 ? {} : { signal: request.signal }
|
|
2575
2636
|
});
|
|
@@ -2613,6 +2674,7 @@ var init_role_turn_host = __esm({
|
|
|
2613
2674
|
init_host_contracts();
|
|
2614
2675
|
init_engine_detour();
|
|
2615
2676
|
init_role_activation_flags();
|
|
2677
|
+
init_user_dialogue_stdin();
|
|
2616
2678
|
init_sitian_facade();
|
|
2617
2679
|
INTERNAL_ROLE_ENTRYPOINT_RELATIVE = "extensions/role-runtime.ts";
|
|
2618
2680
|
EXPLICIT_INTERNAL_LOAD_PROBE_ARGS = [
|
|
@@ -4993,7 +5055,8 @@ async function loadResumableInspectorRun(home, runId, authority) {
|
|
|
4993
5055
|
}
|
|
4994
5056
|
const admitted = {
|
|
4995
5057
|
role: "inspector",
|
|
4996
|
-
...resumedBaseAdmitted(loaded)
|
|
5058
|
+
...resumedBaseAdmitted(loaded),
|
|
5059
|
+
...loaded.admittedFields.sourceRunPath === void 0 ? {} : { sourceRunPath: loaded.admittedFields.sourceRunPath }
|
|
4997
5060
|
};
|
|
4998
5061
|
return seatLoadedResult(loaded, admitted);
|
|
4999
5062
|
}
|
|
@@ -9720,6 +9783,15 @@ var init_ticket_provenance = __esm({
|
|
|
9720
9783
|
});
|
|
9721
9784
|
|
|
9722
9785
|
// src/public-cli/case-dossier-delivery.ts
|
|
9786
|
+
var case_dossier_delivery_exports = {};
|
|
9787
|
+
__export(case_dossier_delivery_exports, {
|
|
9788
|
+
deliverCaseDossierAsAttachment: () => deliverCaseDossierAsAttachment,
|
|
9789
|
+
loadCaseDossierReadingMaterial: () => loadCaseDossierReadingMaterial,
|
|
9790
|
+
projectCaseDossierPointerSection: () => projectCaseDossierPointerSection
|
|
9791
|
+
});
|
|
9792
|
+
import { mkdtemp as mkdtemp2, readFile as readFile12, rm as rm2, writeFile as writeFile7 } from "node:fs/promises";
|
|
9793
|
+
import { tmpdir as tmpdir2 } from "node:os";
|
|
9794
|
+
import { join as join21 } from "node:path";
|
|
9723
9795
|
function describeDossierFile(path) {
|
|
9724
9796
|
return path;
|
|
9725
9797
|
}
|
|
@@ -9738,18 +9810,59 @@ async function projectCaseDossierPointerSection(input) {
|
|
|
9738
9810
|
`\u8BB0\u5F55\u5377\u5B97\uFF1A${describeDossierFile(volume.recordFile)}`
|
|
9739
9811
|
].join("\n");
|
|
9740
9812
|
}
|
|
9741
|
-
|
|
9813
|
+
async function deliverCaseDossierAsAttachment(input) {
|
|
9814
|
+
const section = await projectCaseDossierPointerSection({
|
|
9815
|
+
ticketNumber: input.ticketNumber,
|
|
9816
|
+
projectRoot: input.projectRoot,
|
|
9817
|
+
home: input.home
|
|
9818
|
+
});
|
|
9819
|
+
if (section === void 0) return void 0;
|
|
9820
|
+
const stagingDir = await mkdtemp2(join21(tmpdir2(), "ak-case-dossier-"));
|
|
9821
|
+
try {
|
|
9822
|
+
const stagingPath = join21(stagingDir, CASE_DOSSIER_ATTACH_FILE);
|
|
9823
|
+
await writeFile7(stagingPath, `${section}
|
|
9824
|
+
`, "utf8");
|
|
9825
|
+
return await freezeAttachmentsIntoRun(
|
|
9826
|
+
[stagingPath],
|
|
9827
|
+
input.runDirectory,
|
|
9828
|
+
CASE_DOSSIER_ATTACH_KEY
|
|
9829
|
+
);
|
|
9830
|
+
} finally {
|
|
9831
|
+
await rm2(stagingDir, { recursive: true, force: true });
|
|
9832
|
+
}
|
|
9833
|
+
}
|
|
9834
|
+
async function loadCaseDossierReadingMaterial(runDirectory) {
|
|
9835
|
+
const frozenPath = join21(
|
|
9836
|
+
runDirectory,
|
|
9837
|
+
"attachments",
|
|
9838
|
+
CASE_DOSSIER_ATTACH_KEY,
|
|
9839
|
+
`00-${CASE_DOSSIER_ATTACH_FILE}`
|
|
9840
|
+
);
|
|
9841
|
+
let section;
|
|
9842
|
+
try {
|
|
9843
|
+
section = await readFile12(frozenPath, "utf8");
|
|
9844
|
+
} catch (error) {
|
|
9845
|
+
if (error.code === "ENOENT") return void 0;
|
|
9846
|
+
throw error;
|
|
9847
|
+
}
|
|
9848
|
+
if (section.trim() === "") return void 0;
|
|
9849
|
+
return { kind: "case-dossier-pointer", frozenPath, section };
|
|
9850
|
+
}
|
|
9851
|
+
var CASE_DOSSIER_SECTION_HEADING, CASE_DOSSIER_ATTACH_KEY, CASE_DOSSIER_ATTACH_FILE;
|
|
9742
9852
|
var init_case_dossier_delivery = __esm({
|
|
9743
9853
|
"src/public-cli/case-dossier-delivery.ts"() {
|
|
9744
9854
|
"use strict";
|
|
9745
9855
|
init_ticket_provenance();
|
|
9856
|
+
init_invocation();
|
|
9746
9857
|
CASE_DOSSIER_SECTION_HEADING = "## \u672C\u7968\u8D77\u5C45\u5F55\uFF08\u7CFB\u7EDF\u968F\u6848\u63D0\u4F9B\uFF09";
|
|
9858
|
+
CASE_DOSSIER_ATTACH_KEY = "case-dossier";
|
|
9859
|
+
CASE_DOSSIER_ATTACH_FILE = "case-dossier-pointer.md";
|
|
9747
9860
|
}
|
|
9748
9861
|
});
|
|
9749
9862
|
|
|
9750
9863
|
// src/host-transition-prior-native.ts
|
|
9751
9864
|
import { access as access3, readdir as readdir3 } from "node:fs/promises";
|
|
9752
|
-
import { dirname as dirname11, join as
|
|
9865
|
+
import { dirname as dirname11, join as join22 } from "node:path";
|
|
9753
9866
|
function isEnoent2(error) {
|
|
9754
9867
|
return typeof error === "object" && error !== null && error.code === "ENOENT";
|
|
9755
9868
|
}
|
|
@@ -9774,7 +9887,7 @@ async function listSitianRecordPaths(sessionParent) {
|
|
|
9774
9887
|
const recordPaths = [];
|
|
9775
9888
|
for (const entry of entries) {
|
|
9776
9889
|
if (!entry.isDirectory()) continue;
|
|
9777
|
-
const recordFile =
|
|
9890
|
+
const recordFile = join22(sessionRoot, entry.name, "records.jsonl");
|
|
9778
9891
|
try {
|
|
9779
9892
|
await access3(recordFile);
|
|
9780
9893
|
recordPaths.push(recordFile);
|
|
@@ -10165,13 +10278,13 @@ var init_reviewer_dispatch = __esm({
|
|
|
10165
10278
|
});
|
|
10166
10279
|
|
|
10167
10280
|
// src/public-cli/reviewer-dispatch-rejection.ts
|
|
10168
|
-
import { readFile as
|
|
10169
|
-
import { join as
|
|
10281
|
+
import { readFile as readFile13, unlink as unlink3 } from "node:fs/promises";
|
|
10282
|
+
import { join as join23 } from "node:path";
|
|
10170
10283
|
function isReviewerPreflightViolation(value) {
|
|
10171
10284
|
return typeof value === "string" && REVIEWER_PREFLIGHT_VIOLATIONS.includes(value);
|
|
10172
10285
|
}
|
|
10173
10286
|
function reviewerDispatchRejectionPath(runDirectory) {
|
|
10174
|
-
return
|
|
10287
|
+
return join23(runDirectory, REVIEWER_DISPATCH_REJECTION_FILE);
|
|
10175
10288
|
}
|
|
10176
10289
|
async function clearReviewerDispatchRejection(runDirectory) {
|
|
10177
10290
|
try {
|
|
@@ -10186,7 +10299,7 @@ async function clearReviewerDispatchRejection(runDirectory) {
|
|
|
10186
10299
|
async function readReviewerDispatchRejection(runDirectory) {
|
|
10187
10300
|
let raw;
|
|
10188
10301
|
try {
|
|
10189
|
-
raw = await
|
|
10302
|
+
raw = await readFile13(reviewerDispatchRejectionPath(runDirectory), "utf8");
|
|
10190
10303
|
} catch (error) {
|
|
10191
10304
|
if (error instanceof Error && "code" in error && error.code === "ENOENT") {
|
|
10192
10305
|
return void 0;
|
|
@@ -10228,12 +10341,12 @@ __export(session_assistant_usage_exports, {
|
|
|
10228
10341
|
sessionFileFromPublicSummon: () => sessionFileFromPublicSummon,
|
|
10229
10342
|
usageFromPublicSummon: () => usageFromPublicSummon
|
|
10230
10343
|
});
|
|
10231
|
-
import { join as
|
|
10344
|
+
import { join as join24 } from "node:path";
|
|
10232
10345
|
async function readAssistantUsageFromSessionFile(sessionFile) {
|
|
10233
|
-
const { readFile:
|
|
10346
|
+
const { readFile: readFile24 } = await import("node:fs/promises");
|
|
10234
10347
|
let text;
|
|
10235
10348
|
try {
|
|
10236
|
-
text = await
|
|
10349
|
+
text = await readFile24(sessionFile, "utf8");
|
|
10237
10350
|
} catch (error) {
|
|
10238
10351
|
if (error?.code === "ENOENT") return void 0;
|
|
10239
10352
|
throw error;
|
|
@@ -10298,7 +10411,7 @@ async function readAssistantUsageFromSessionFile(sessionFile) {
|
|
|
10298
10411
|
}
|
|
10299
10412
|
function sessionFileFromPublicSummon(summoned) {
|
|
10300
10413
|
if (typeof summoned.runDirectory === "string" && summoned.runDirectory.trim() !== "") {
|
|
10301
|
-
return
|
|
10414
|
+
return join24(summoned.runDirectory, "session", "session.jsonl");
|
|
10302
10415
|
}
|
|
10303
10416
|
const fromArtifacts = summoned.terminal?.artifacts?.map((a) => a.path).find((p) => typeof p === "string" && p.endsWith("session.jsonl"));
|
|
10304
10417
|
if (fromArtifacts !== void 0) return fromArtifacts;
|
|
@@ -10307,7 +10420,7 @@ function sessionFileFromPublicSummon(summoned) {
|
|
|
10307
10420
|
const facts = outcome.decisiveFacts;
|
|
10308
10421
|
const pointer = facts?.runPointer;
|
|
10309
10422
|
if (typeof pointer === "string" && pointer.trim() !== "") {
|
|
10310
|
-
return
|
|
10423
|
+
return join24(pointer, "session", "session.jsonl");
|
|
10311
10424
|
}
|
|
10312
10425
|
return void 0;
|
|
10313
10426
|
}
|
|
@@ -10461,12 +10574,12 @@ var init_compliance_transport = __esm({
|
|
|
10461
10574
|
});
|
|
10462
10575
|
|
|
10463
10576
|
// src/ledger-session-read.ts
|
|
10464
|
-
import { readFile as
|
|
10577
|
+
import { readFile as readFile14 } from "node:fs/promises";
|
|
10465
10578
|
function isRecord5(value) {
|
|
10466
10579
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
10467
10580
|
}
|
|
10468
10581
|
async function readLedgerSessionJsonl(path) {
|
|
10469
|
-
const text = await
|
|
10582
|
+
const text = await readFile14(path, "utf8");
|
|
10470
10583
|
const lines = text.split("\n");
|
|
10471
10584
|
const rows = [];
|
|
10472
10585
|
for (let index = 0; index < lines.length; index += 1) {
|
|
@@ -10548,7 +10661,7 @@ var init_ledger_session_read = __esm({
|
|
|
10548
10661
|
|
|
10549
10662
|
// src/analyst-gate-cycles-read.ts
|
|
10550
10663
|
import { readdir as readdir4 } from "node:fs/promises";
|
|
10551
|
-
import { join as
|
|
10664
|
+
import { join as join25 } from "node:path";
|
|
10552
10665
|
function isRecord6(value) {
|
|
10553
10666
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
10554
10667
|
}
|
|
@@ -10763,10 +10876,10 @@ function pairGateRounds(volumes) {
|
|
|
10763
10876
|
return rounds.sort((a, b) => a.officerStartedAt.localeCompare(b.officerStartedAt)).map((round, index) => ({ ...round, roundIndex: index + 1 }));
|
|
10764
10877
|
}
|
|
10765
10878
|
async function resolveOfficerSessionFromPointerFile(pointerPath) {
|
|
10766
|
-
const { readFile:
|
|
10879
|
+
const { readFile: readFile24 } = await import("node:fs/promises");
|
|
10767
10880
|
let raw;
|
|
10768
10881
|
try {
|
|
10769
|
-
raw = JSON.parse(await
|
|
10882
|
+
raw = JSON.parse(await readFile24(pointerPath, "utf8"));
|
|
10770
10883
|
} catch (error) {
|
|
10771
10884
|
throw new Error(
|
|
10772
10885
|
`direct officer run pointer unreadable in ${pointerPath}: ${error instanceof Error ? error.message : String(error)}`,
|
|
@@ -10798,7 +10911,7 @@ async function readAnalystGateCyclesFromAuditorRoles(auditorRolesDirectory, opti
|
|
|
10798
10911
|
throw error;
|
|
10799
10912
|
}
|
|
10800
10913
|
for (const name of names) {
|
|
10801
|
-
const path =
|
|
10914
|
+
const path = join25(directory, name);
|
|
10802
10915
|
const fromPointer = name.endsWith(".pointer.json");
|
|
10803
10916
|
const sessionPath = fromPointer ? await resolveOfficerSessionFromPointerFile(path) : path;
|
|
10804
10917
|
if (sessionPath === void 0) continue;
|
|
@@ -10937,7 +11050,7 @@ var init_audit_escalation = __esm({
|
|
|
10937
11050
|
});
|
|
10938
11051
|
|
|
10939
11052
|
// src/run-terminal-artifacts.ts
|
|
10940
|
-
import { basename as basename7, dirname as dirname12, join as
|
|
11053
|
+
import { basename as basename7, dirname as dirname12, join as join26 } from "node:path";
|
|
10941
11054
|
function runIdFromRunDirectory(runDirectory) {
|
|
10942
11055
|
const name = basename7(runDirectory);
|
|
10943
11056
|
const at = name.lastIndexOf("@");
|
|
@@ -10952,8 +11065,8 @@ var init_run_terminal_artifacts = __esm({
|
|
|
10952
11065
|
|
|
10953
11066
|
// src/submission-ledger.ts
|
|
10954
11067
|
function runIdentity(context) {
|
|
10955
|
-
const directory =
|
|
10956
|
-
if (
|
|
11068
|
+
const directory = runDirectoryFromHostContext(context);
|
|
11069
|
+
if (directory !== void 0) {
|
|
10957
11070
|
const fromDir = runIdFromRunDirectory(directory);
|
|
10958
11071
|
if (fromDir !== void 0) return fromDir;
|
|
10959
11072
|
}
|
|
@@ -10962,8 +11075,8 @@ function runIdentity(context) {
|
|
|
10962
11075
|
throw new Error("\u63D0\u4EA4\u8D26\u9700\u8981\u5DF2\u53D7\u7406\u7684 run \u8EAB\u4EFD");
|
|
10963
11076
|
}
|
|
10964
11077
|
function attemptIdentity(context, runId) {
|
|
10965
|
-
const courtAttempt =
|
|
10966
|
-
if (
|
|
11078
|
+
const courtAttempt = courtAttemptIdFromHostContext(context);
|
|
11079
|
+
if (courtAttempt !== void 0) return courtAttempt;
|
|
10967
11080
|
return context.sessionManager.getHeader?.()?.id ?? context.sessionManager.getLeafId?.() ?? `${runId}:initial`;
|
|
10968
11081
|
}
|
|
10969
11082
|
function submissionRecordFile(cwd, runId, home) {
|
|
@@ -11023,31 +11136,107 @@ function recordedRole(payload) {
|
|
|
11023
11136
|
if (isTerminalRoleName(payload.projection?.role)) return payload.projection.role;
|
|
11024
11137
|
return void 0;
|
|
11025
11138
|
}
|
|
11026
|
-
|
|
11027
|
-
|
|
11028
|
-
|
|
11029
|
-
|
|
11139
|
+
function rowRank(kind) {
|
|
11140
|
+
switch (kind) {
|
|
11141
|
+
case "accepted":
|
|
11142
|
+
return 4;
|
|
11143
|
+
case "audit-escalation":
|
|
11144
|
+
return 3;
|
|
11145
|
+
case "correctable-rejection":
|
|
11146
|
+
case "infrastructure":
|
|
11147
|
+
return 2;
|
|
11148
|
+
case "candidate":
|
|
11149
|
+
return 1;
|
|
11150
|
+
}
|
|
11151
|
+
}
|
|
11152
|
+
function submissionCallKey(attemptId, toolCallId) {
|
|
11153
|
+
return `${attemptId ?? ""}\0${toolCallId}`;
|
|
11154
|
+
}
|
|
11155
|
+
function rowFromPayload(kind, payload, accepted, roleFallback) {
|
|
11156
|
+
const role = recordedRole(payload) ?? roleFallback;
|
|
11157
|
+
return {
|
|
11158
|
+
...role === void 0 ? {} : { role },
|
|
11159
|
+
kind,
|
|
11160
|
+
accepted,
|
|
11161
|
+
...typeof payload.toolCallId === "string" && payload.toolCallId.length > 0 ? { toolCallId: payload.toolCallId } : {}
|
|
11162
|
+
};
|
|
11163
|
+
}
|
|
11164
|
+
function mapOwnedToSubmissionRows(owned) {
|
|
11165
|
+
const scoped = owned;
|
|
11030
11166
|
const out = [];
|
|
11167
|
+
const indexByCall = /* @__PURE__ */ new Map();
|
|
11168
|
+
const roleByCall = /* @__PURE__ */ new Map();
|
|
11031
11169
|
for (const record4 of scoped) {
|
|
11170
|
+
const payload = record4.payload;
|
|
11171
|
+
if (typeof payload?.toolCallId !== "string" || payload.toolCallId.length === 0) continue;
|
|
11172
|
+
const role = recordedRole(payload);
|
|
11173
|
+
if (role !== void 0) {
|
|
11174
|
+
roleByCall.set(submissionCallKey(recordAttemptId(record4), payload.toolCallId), role);
|
|
11175
|
+
}
|
|
11176
|
+
}
|
|
11177
|
+
const take = (row, callKey) => {
|
|
11178
|
+
const toolCallId = row.toolCallId;
|
|
11179
|
+
if (toolCallId !== void 0 && callKey !== void 0) {
|
|
11180
|
+
const existingIndex = indexByCall.get(callKey);
|
|
11181
|
+
if (existingIndex !== void 0) {
|
|
11182
|
+
const existing = out[existingIndex];
|
|
11183
|
+
if (rowRank(row.kind) >= rowRank(existing.kind)) {
|
|
11184
|
+
out[existingIndex] = {
|
|
11185
|
+
...row,
|
|
11186
|
+
toolCallId,
|
|
11187
|
+
// Keep a previously recovered role when the upgraded row still omits it.
|
|
11188
|
+
...row.role === void 0 && existing.role !== void 0 ? { role: existing.role } : {}
|
|
11189
|
+
};
|
|
11190
|
+
} else if (existing.role === void 0 && row.role !== void 0) {
|
|
11191
|
+
out[existingIndex] = { ...existing, role: row.role };
|
|
11192
|
+
}
|
|
11193
|
+
return;
|
|
11194
|
+
}
|
|
11195
|
+
indexByCall.set(callKey, out.length);
|
|
11196
|
+
}
|
|
11197
|
+
out.push(row);
|
|
11198
|
+
};
|
|
11199
|
+
for (const record4 of scoped) {
|
|
11200
|
+
const attemptId = recordAttemptId(record4);
|
|
11201
|
+
if (record4.kind === "candidate") {
|
|
11202
|
+
const payload2 = record4.payload;
|
|
11203
|
+
if (payload2?.type !== "candidate" || payload2.params === void 0) continue;
|
|
11204
|
+
const callKey2 = typeof payload2.toolCallId === "string" ? submissionCallKey(attemptId, payload2.toolCallId) : void 0;
|
|
11205
|
+
const fallback2 = callKey2 !== void 0 ? roleByCall.get(callKey2) : void 0;
|
|
11206
|
+
take(rowFromPayload("candidate", payload2, payload2.params, fallback2), callKey2);
|
|
11207
|
+
continue;
|
|
11208
|
+
}
|
|
11032
11209
|
if (record4.kind === "sealed") {
|
|
11033
11210
|
const payload2 = record4.payload;
|
|
11034
11211
|
if (payload2?.type !== "sealed" || payload2.accepted === void 0) continue;
|
|
11035
|
-
const
|
|
11036
|
-
|
|
11037
|
-
|
|
11212
|
+
const callKey2 = typeof payload2.toolCallId === "string" ? submissionCallKey(attemptId, payload2.toolCallId) : void 0;
|
|
11213
|
+
const fallback2 = callKey2 !== void 0 ? roleByCall.get(callKey2) : void 0;
|
|
11214
|
+
take(rowFromPayload("accepted", payload2, payload2.accepted, fallback2), callKey2);
|
|
11038
11215
|
continue;
|
|
11039
11216
|
}
|
|
11040
11217
|
if (record4.kind !== "outcome") continue;
|
|
11041
11218
|
const payload = record4.payload;
|
|
11042
|
-
if (payload?.type !== "outcome" || payload.
|
|
11043
|
-
|
|
11044
|
-
|
|
11045
|
-
|
|
11046
|
-
|
|
11047
|
-
|
|
11219
|
+
if (payload?.type !== "outcome" || payload.accepted === void 0) continue;
|
|
11220
|
+
const outcome = payload.outcome;
|
|
11221
|
+
const kind = outcome === "audit-escalation" ? "audit-escalation" : outcome === "correctable-rejection" ? "correctable-rejection" : outcome === "infrastructure" ? "infrastructure" : void 0;
|
|
11222
|
+
if (kind === void 0) continue;
|
|
11223
|
+
const callKey = typeof payload.toolCallId === "string" ? submissionCallKey(attemptId, payload.toolCallId) : void 0;
|
|
11224
|
+
const fallback = callKey !== void 0 ? roleByCall.get(callKey) : void 0;
|
|
11225
|
+
take(rowFromPayload(kind, payload, payload.accepted, fallback), callKey);
|
|
11048
11226
|
}
|
|
11049
11227
|
return out;
|
|
11050
11228
|
}
|
|
11229
|
+
async function readRecordedSubmissionRows(cwd, runId, homeOrScope) {
|
|
11230
|
+
const scope = resolveReadScope(homeOrScope);
|
|
11231
|
+
const { owned } = await readOwnedSubmissionRecords(cwd, runId, scope.home);
|
|
11232
|
+
const scoped = recordsForAttempt(owned, scope.attemptId);
|
|
11233
|
+
return mapOwnedToSubmissionRows(scoped);
|
|
11234
|
+
}
|
|
11235
|
+
async function readAttemptScopedSubmissionRows(cwd, runId, attemptId, home) {
|
|
11236
|
+
if (attemptId.length === 0) return [];
|
|
11237
|
+
const { owned } = await readOwnedSubmissionRecords(cwd, runId, home);
|
|
11238
|
+
return mapOwnedToSubmissionRows(owned.filter((record4) => recordAttemptId(record4) === attemptId));
|
|
11239
|
+
}
|
|
11051
11240
|
async function readRecordedSubmissions(cwd, runId, homeOrScope) {
|
|
11052
11241
|
return (await readRecordedSubmissionRows(cwd, runId, homeOrScope)).map((row) => row.accepted);
|
|
11053
11242
|
}
|
|
@@ -11123,6 +11312,7 @@ function createSubmissionLedgerHost(host, outputTools, failInfrastructure2 = (er
|
|
|
11123
11312
|
toolCallId,
|
|
11124
11313
|
toolName: tool.name,
|
|
11125
11314
|
sequence: ++state.sequence,
|
|
11315
|
+
role,
|
|
11126
11316
|
params
|
|
11127
11317
|
});
|
|
11128
11318
|
let result;
|
|
@@ -11148,6 +11338,7 @@ function createSubmissionLedgerHost(host, outputTools, failInfrastructure2 = (er
|
|
|
11148
11338
|
outcome: "correctable-rejection",
|
|
11149
11339
|
code: "typed-bounce",
|
|
11150
11340
|
diagnostic: error instanceof Error ? error.message : String(error),
|
|
11341
|
+
role,
|
|
11151
11342
|
accepted: params
|
|
11152
11343
|
});
|
|
11153
11344
|
throw error;
|
|
@@ -11158,6 +11349,7 @@ function createSubmissionLedgerHost(host, outputTools, failInfrastructure2 = (er
|
|
|
11158
11349
|
toolCallId,
|
|
11159
11350
|
outcome: "infrastructure",
|
|
11160
11351
|
diagnostic: error instanceof Error ? error.message : String(error),
|
|
11352
|
+
role,
|
|
11161
11353
|
accepted: params
|
|
11162
11354
|
});
|
|
11163
11355
|
throw error;
|
|
@@ -11199,29 +11391,28 @@ function createSubmissionLedgerHost(host, outputTools, failInfrastructure2 = (er
|
|
|
11199
11391
|
}
|
|
11200
11392
|
};
|
|
11201
11393
|
}
|
|
11202
|
-
var COURT_ATTEMPT_ENV;
|
|
11203
11394
|
var init_submission_ledger = __esm({
|
|
11204
11395
|
"src/submission-ledger.ts"() {
|
|
11205
11396
|
"use strict";
|
|
11206
11397
|
init_activation_ledger_topology();
|
|
11398
|
+
init_host_contracts();
|
|
11207
11399
|
init_audit_escalation();
|
|
11208
11400
|
init_run_terminal_artifacts();
|
|
11209
11401
|
init_sitian_facade();
|
|
11210
11402
|
init_submission_correctable_error();
|
|
11211
11403
|
init_terminating_infrastructure();
|
|
11212
|
-
COURT_ATTEMPT_ENV = "AK_ROLE_COURT_ATTEMPT";
|
|
11213
11404
|
}
|
|
11214
11405
|
});
|
|
11215
11406
|
|
|
11216
11407
|
// src/session-opening-materials.ts
|
|
11217
11408
|
import { existsSync as existsSync8 } from "node:fs";
|
|
11218
|
-
import { readFile as
|
|
11219
|
-
import { dirname as dirname13, join as
|
|
11409
|
+
import { readFile as readFile15 } from "node:fs/promises";
|
|
11410
|
+
import { dirname as dirname13, join as join27 } from "node:path";
|
|
11220
11411
|
import { fileURLToPath, pathToFileURL as pathToFileURL3 } from "node:url";
|
|
11221
11412
|
function resolvePackageRootDir(moduleUrl = import.meta.url) {
|
|
11222
11413
|
let dir = dirname13(fileURLToPath(moduleUrl));
|
|
11223
11414
|
for (let i = 0; i < 8; i += 1) {
|
|
11224
|
-
if (existsSync8(
|
|
11415
|
+
if (existsSync8(join27(dir, "package.json")) && existsSync8(join27(dir, "souls"))) {
|
|
11225
11416
|
return dir;
|
|
11226
11417
|
}
|
|
11227
11418
|
const parent = dirname13(dir);
|
|
@@ -11231,7 +11422,7 @@ function resolvePackageRootDir(moduleUrl = import.meta.url) {
|
|
|
11231
11422
|
return fileURLToPath(new URL("..", moduleUrl));
|
|
11232
11423
|
}
|
|
11233
11424
|
async function readPackageMaterial(relativePath) {
|
|
11234
|
-
return
|
|
11425
|
+
return readFile15(fileURLToPath(new URL(relativePath, packageRootUrl)), "utf8");
|
|
11235
11426
|
}
|
|
11236
11427
|
async function joinPackageMaterials(relativePaths) {
|
|
11237
11428
|
const chunks = [];
|
|
@@ -11331,9 +11522,20 @@ var init_auditor_soul = __esm({
|
|
|
11331
11522
|
// src/dossier-resolution.ts
|
|
11332
11523
|
import { existsSync as existsSync9, statSync as statSync2 } from "node:fs";
|
|
11333
11524
|
import { resolve as resolve11 } from "node:path";
|
|
11334
|
-
function
|
|
11525
|
+
function isHostContext(value) {
|
|
11526
|
+
return "sessionManager" in value;
|
|
11527
|
+
}
|
|
11528
|
+
function dossierPointerFrom(source) {
|
|
11529
|
+
if (source !== void 0 && isHostContext(source)) {
|
|
11530
|
+
return runDirectoryFromHostContext(source);
|
|
11531
|
+
}
|
|
11532
|
+
const env = source ?? process.env;
|
|
11335
11533
|
const raw = env[AUDIT_RUN_DIR_ENV];
|
|
11336
|
-
|
|
11534
|
+
return typeof raw === "string" && raw.trim() !== "" ? raw : void 0;
|
|
11535
|
+
}
|
|
11536
|
+
function resolveAuditDossier(source) {
|
|
11537
|
+
const raw = dossierPointerFrom(source);
|
|
11538
|
+
if (raw === void 0) {
|
|
11337
11539
|
return { status: "ok" };
|
|
11338
11540
|
}
|
|
11339
11541
|
const runDirectory = resolve11(raw);
|
|
@@ -11367,6 +11569,7 @@ var AUDIT_RUN_DIR_ENV, DOCTOR_CANDIDATE_ENTRY_TYPE, AuditMaterialsUnavailableErr
|
|
|
11367
11569
|
var init_dossier_resolution = __esm({
|
|
11368
11570
|
"src/dossier-resolution.ts"() {
|
|
11369
11571
|
"use strict";
|
|
11572
|
+
init_host_contracts();
|
|
11370
11573
|
AUDIT_RUN_DIR_ENV = "AK_ROLE_RUN_DIR";
|
|
11371
11574
|
DOCTOR_CANDIDATE_ENTRY_TYPE = "ak_doctor_audit_candidate";
|
|
11372
11575
|
AuditMaterialsUnavailableError = class extends Error {
|
|
@@ -11386,7 +11589,7 @@ var init_dossier_resolution = __esm({
|
|
|
11386
11589
|
// src/doctor-auditor.ts
|
|
11387
11590
|
function createPiDoctorAuditor() {
|
|
11388
11591
|
return async (options) => {
|
|
11389
|
-
const dossier = resolveAuditDossier();
|
|
11592
|
+
const dossier = resolveAuditDossier(options.context);
|
|
11390
11593
|
requireAuditMaterials(dossier);
|
|
11391
11594
|
const subjects = readDoctorAuditSubjects(options.context);
|
|
11392
11595
|
requireAuditMaterials(subjects);
|
|
@@ -11465,7 +11668,7 @@ function knownFailureFromProviderStop(input) {
|
|
|
11465
11668
|
const diagnostic = nonEmptyString(input.errorMessage);
|
|
11466
11669
|
const details = sessionStopDetails(input);
|
|
11467
11670
|
return {
|
|
11468
|
-
|
|
11671
|
+
...hasUpstreamErrorTestimony(input) ? { cause: "provider" } : {},
|
|
11469
11672
|
...diagnostic === void 0 ? {} : { diagnostic },
|
|
11470
11673
|
...Object.keys(details).length === 0 ? {} : { details }
|
|
11471
11674
|
};
|
|
@@ -12638,8 +12841,8 @@ var init_collector_ledger = __esm({
|
|
|
12638
12841
|
|
|
12639
12842
|
// src/package-resources/method-skill.ts
|
|
12640
12843
|
import { createHash as createHash8 } from "node:crypto";
|
|
12641
|
-
import { readFile as
|
|
12642
|
-
import { join as
|
|
12844
|
+
import { readFile as readFile16, realpath as realpath6 } from "node:fs/promises";
|
|
12845
|
+
import { join as join28 } from "node:path";
|
|
12643
12846
|
function gitBlobOid(bytes) {
|
|
12644
12847
|
const body = typeof bytes === "string" ? Buffer.from(bytes, "utf8") : Buffer.from(bytes);
|
|
12645
12848
|
const header = Buffer.from(`blob ${body.byteLength}\0`, "utf8");
|
|
@@ -12656,10 +12859,10 @@ function packagedMethodSkillRelativeDirectory(name) {
|
|
|
12656
12859
|
return `${METHOD_SKILL_RELATIVE_ROOT}/${name}`;
|
|
12657
12860
|
}
|
|
12658
12861
|
function resolvePackagedMethodSkillRoot(packageRoot, name) {
|
|
12659
|
-
return
|
|
12862
|
+
return join28(packageRoot, packagedMethodSkillRelativeDirectory(name));
|
|
12660
12863
|
}
|
|
12661
12864
|
function resolvePackagedMethodSkillPath(packageRoot, name) {
|
|
12662
|
-
return
|
|
12865
|
+
return join28(resolvePackagedMethodSkillRoot(packageRoot, name), "SKILL.md");
|
|
12663
12866
|
}
|
|
12664
12867
|
function isRecord8(value) {
|
|
12665
12868
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
@@ -12753,11 +12956,11 @@ function parseProvenance(raw, expectedName) {
|
|
|
12753
12956
|
}
|
|
12754
12957
|
async function loadPackagedMethodSkillMaterial(packageRoot, name) {
|
|
12755
12958
|
const rootDirectory = resolvePackagedMethodSkillRoot(packageRoot, name);
|
|
12756
|
-
const skillPathConfigured =
|
|
12757
|
-
const provenancePath =
|
|
12959
|
+
const skillPathConfigured = join28(rootDirectory, "SKILL.md");
|
|
12960
|
+
const provenancePath = join28(rootDirectory, "provenance.json");
|
|
12758
12961
|
let provenanceRaw;
|
|
12759
12962
|
try {
|
|
12760
|
-
provenanceRaw = await
|
|
12963
|
+
provenanceRaw = await readFile16(provenancePath, "utf8");
|
|
12761
12964
|
} catch (error) {
|
|
12762
12965
|
throw new PackagedMethodSkillUnavailableError(name, provenancePath, error);
|
|
12763
12966
|
}
|
|
@@ -12771,10 +12974,10 @@ async function loadPackagedMethodSkillMaterial(packageRoot, name) {
|
|
|
12771
12974
|
}
|
|
12772
12975
|
const provenance = parseProvenance(provenanceJson, name);
|
|
12773
12976
|
for (const [rel, expected] of Object.entries(provenance.files)) {
|
|
12774
|
-
const absolute =
|
|
12977
|
+
const absolute = join28(rootDirectory, rel);
|
|
12775
12978
|
let bytes;
|
|
12776
12979
|
try {
|
|
12777
|
-
bytes = await
|
|
12980
|
+
bytes = await readFile16(absolute);
|
|
12778
12981
|
} catch (error) {
|
|
12779
12982
|
throw new PackagedMethodSkillUnavailableError(name, absolute, error);
|
|
12780
12983
|
}
|
|
@@ -12790,7 +12993,7 @@ async function loadPackagedMethodSkillMaterial(packageRoot, name) {
|
|
|
12790
12993
|
let raw;
|
|
12791
12994
|
try {
|
|
12792
12995
|
skillPath = await realpath6(skillPathConfigured);
|
|
12793
|
-
raw = await
|
|
12996
|
+
raw = await readFile16(skillPath, "utf8");
|
|
12794
12997
|
} catch (error) {
|
|
12795
12998
|
throw new PackagedMethodSkillUnavailableError(name, skillPathConfigured, error);
|
|
12796
12999
|
}
|
|
@@ -13190,15 +13393,6 @@ function isLawfulTypedTerminalOutcome(outcome) {
|
|
|
13190
13393
|
function exitCodeForTerminalOutcome(outcome) {
|
|
13191
13394
|
return isLawfulTypedTerminalOutcome(outcome) ? 0 : 1;
|
|
13192
13395
|
}
|
|
13193
|
-
function lastRolePayloadRecord(payloads) {
|
|
13194
|
-
for (let index = payloads.length - 1; index >= 0; index -= 1) {
|
|
13195
|
-
const payload = payloads[index];
|
|
13196
|
-
if (typeof payload === "object" && payload !== null && !Array.isArray(payload)) {
|
|
13197
|
-
return payload;
|
|
13198
|
-
}
|
|
13199
|
-
}
|
|
13200
|
-
return void 0;
|
|
13201
|
-
}
|
|
13202
13396
|
function recommendationNavigatorFact(input) {
|
|
13203
13397
|
const command = typeof input.modelCommand === "string" && input.modelCommand.trim() !== "" ? input.modelCommand : isPublicCallableRole2(input.next.role) ? renderPublicAkRoleCommand(input.next) : void 0;
|
|
13204
13398
|
return {
|
|
@@ -13213,7 +13407,7 @@ function recommendationNavigatorFact(input) {
|
|
|
13213
13407
|
function formatTerminalResult(result) {
|
|
13214
13408
|
const lines = [];
|
|
13215
13409
|
lines.push("role outcome status");
|
|
13216
|
-
const outcomeStatus = result.roleOutcome.kind === "failure" ? result.roleOutcome.cause : result.roleOutcome.kind === "accepted" ? "accepted" : result.roleOutcome.status;
|
|
13410
|
+
const outcomeStatus = result.roleOutcome.kind === "failure" ? result.roleOutcome.cause ?? "" : result.roleOutcome.kind === "accepted" ? "accepted" : result.roleOutcome.status;
|
|
13217
13411
|
lines.push(
|
|
13218
13412
|
`${result.roleOutcome.role} ${result.roleOutcome.kind} ${encodeTerminalField(outcomeStatus)}`
|
|
13219
13413
|
);
|
|
@@ -13286,8 +13480,8 @@ var init_terminal = __esm({
|
|
|
13286
13480
|
|
|
13287
13481
|
// src/public-cli/settlement.ts
|
|
13288
13482
|
import { randomUUID as randomUUID3 } from "node:crypto";
|
|
13289
|
-
import { appendFile as appendFile2, readFile as
|
|
13290
|
-
import { dirname as dirname14, join as
|
|
13483
|
+
import { appendFile as appendFile2, readFile as readFile17, readdir as readdir5, writeFile as writeFile8 } from "node:fs/promises";
|
|
13484
|
+
import { dirname as dirname14, join as join29 } from "node:path";
|
|
13291
13485
|
function sealedLedgerHome(admitted) {
|
|
13292
13486
|
return homeFromRunDirectory(admitted.runDirectory);
|
|
13293
13487
|
}
|
|
@@ -13299,14 +13493,27 @@ function ledgerReadScope(admitted, scope) {
|
|
|
13299
13493
|
}
|
|
13300
13494
|
function roleOutcomeFromRows(role, rows) {
|
|
13301
13495
|
const mine = rows.filter((row) => row.role === role);
|
|
13302
|
-
|
|
13496
|
+
const terminal = mine.filter(
|
|
13497
|
+
(row) => row.kind === "accepted" || row.kind === "audit-escalation"
|
|
13498
|
+
);
|
|
13499
|
+
if (terminal.length === 0) return void 0;
|
|
13303
13500
|
const payloads = mine.map((row) => row.accepted);
|
|
13304
|
-
if (
|
|
13501
|
+
if (terminal.some((row) => row.kind === "audit-escalation")) {
|
|
13305
13502
|
return { kind: "audit_escalation", role, status: "audit_escalation", payloads };
|
|
13306
13503
|
}
|
|
13307
13504
|
return { kind: "accepted", role, payloads };
|
|
13308
13505
|
}
|
|
13309
13506
|
async function sealedLedgerOutcome(admitted, role, scope) {
|
|
13507
|
+
const home = sealedLedgerHome(admitted);
|
|
13508
|
+
if (scope?.courtAttemptId !== void 0 && scope.courtAttemptId.length > 0) {
|
|
13509
|
+
const thisCourt = await readAttemptScopedSubmissionRows(
|
|
13510
|
+
admitted.projectRoot,
|
|
13511
|
+
admitted.runId,
|
|
13512
|
+
scope.courtAttemptId,
|
|
13513
|
+
home
|
|
13514
|
+
);
|
|
13515
|
+
return roleOutcomeFromRows(role, thisCourt);
|
|
13516
|
+
}
|
|
13310
13517
|
const rows = await readRecordedSubmissionRows(
|
|
13311
13518
|
admitted.projectRoot,
|
|
13312
13519
|
admitted.runId,
|
|
@@ -13337,7 +13544,11 @@ function withSubmissions(terminal, submissions) {
|
|
|
13337
13544
|
return { ...terminal, roleOutcome: withPayloads, submissions };
|
|
13338
13545
|
}
|
|
13339
13546
|
async function attachRecordedSubmissions(admitted, terminal, scope) {
|
|
13340
|
-
|
|
13547
|
+
void scope;
|
|
13548
|
+
return withSubmissions(
|
|
13549
|
+
terminal,
|
|
13550
|
+
await recordedSubmissionPayloads(admitted, void 0)
|
|
13551
|
+
);
|
|
13341
13552
|
}
|
|
13342
13553
|
async function settleHostEndedNoReceipt(admitted, authority) {
|
|
13343
13554
|
const facts = noReceiptLifecycleFacts({
|
|
@@ -13406,7 +13617,7 @@ function presentStructuralRejection(error, io) {
|
|
|
13406
13617
|
}
|
|
13407
13618
|
async function inspectJudgeSession(sessionFile) {
|
|
13408
13619
|
try {
|
|
13409
|
-
await
|
|
13620
|
+
await readFile17(sessionFile, "utf8");
|
|
13410
13621
|
return { state: "present" };
|
|
13411
13622
|
} catch (error) {
|
|
13412
13623
|
if (isMissingPathError2(error)) return { state: "missing" };
|
|
@@ -13429,7 +13640,7 @@ function thrownIdentity(error) {
|
|
|
13429
13640
|
function isTypedActivationError(error) {
|
|
13430
13641
|
if (!(error instanceof Error)) return false;
|
|
13431
13642
|
const cause = error.knownCause;
|
|
13432
|
-
return cause === "provider" || cause === "activation" || cause === "session" || cause === "output" || cause === "timeout"
|
|
13643
|
+
return cause === "provider" || cause === "activation" || cause === "session" || cause === "output" || cause === "timeout";
|
|
13433
13644
|
}
|
|
13434
13645
|
function flattenThrownFailureLeaves(error) {
|
|
13435
13646
|
if (!(error instanceof AggregateError)) {
|
|
@@ -13449,7 +13660,7 @@ function projectThrownFailureLeaf(error) {
|
|
|
13449
13660
|
}
|
|
13450
13661
|
return {
|
|
13451
13662
|
cause: error.knownCause,
|
|
13452
|
-
diagnostic: error.message || error.name || "
|
|
13663
|
+
diagnostic: error.message || error.name || "exception",
|
|
13453
13664
|
identity,
|
|
13454
13665
|
...error.details === void 0 ? {} : { details: error.details }
|
|
13455
13666
|
};
|
|
@@ -13457,13 +13668,11 @@ function projectThrownFailureLeaf(error) {
|
|
|
13457
13668
|
if (error instanceof Error) {
|
|
13458
13669
|
const identity = thrownIdentity(error);
|
|
13459
13670
|
return {
|
|
13460
|
-
|
|
13461
|
-
diagnostic: error.message || error.name || "unrecognized exception",
|
|
13671
|
+
diagnostic: error.message || error.name || "exception",
|
|
13462
13672
|
identity
|
|
13463
13673
|
};
|
|
13464
13674
|
}
|
|
13465
13675
|
return {
|
|
13466
|
-
cause: "unrecognized",
|
|
13467
13676
|
diagnostic: String(error)
|
|
13468
13677
|
};
|
|
13469
13678
|
}
|
|
@@ -13485,7 +13694,7 @@ function classifyThrownFailure(error) {
|
|
|
13485
13694
|
...leaves.slice(1).map((leaf) => {
|
|
13486
13695
|
const secondary = projectThrownFailureLeaf(leaf);
|
|
13487
13696
|
return {
|
|
13488
|
-
cause: secondary.cause,
|
|
13697
|
+
...secondary.cause === void 0 ? {} : { cause: secondary.cause },
|
|
13489
13698
|
diagnostic: secondary.diagnostic,
|
|
13490
13699
|
...secondary.identity === void 0 ? {} : { identity: secondary.identity },
|
|
13491
13700
|
...secondary.details === void 0 ? {} : { details: secondary.details }
|
|
@@ -13493,7 +13702,7 @@ function classifyThrownFailure(error) {
|
|
|
13493
13702
|
})
|
|
13494
13703
|
];
|
|
13495
13704
|
return {
|
|
13496
|
-
cause: primary.cause,
|
|
13705
|
+
...primary.cause === void 0 ? {} : { cause: primary.cause },
|
|
13497
13706
|
diagnostic: primary.diagnostic,
|
|
13498
13707
|
...primary.identity === void 0 ? {} : { identity: primary.identity },
|
|
13499
13708
|
details: {
|
|
@@ -13534,6 +13743,24 @@ function classifyPostAdmissionFailure(input) {
|
|
|
13534
13743
|
...input.knownIdentity === void 0 ? {} : { identity: input.knownIdentity }
|
|
13535
13744
|
};
|
|
13536
13745
|
}
|
|
13746
|
+
if (input.knownDiagnostic !== void 0 && input.knownDiagnostic.trim() !== "" || input.knownIdentity !== void 0) {
|
|
13747
|
+
const diagnostic = input.knownDiagnostic !== void 0 && input.knownDiagnostic.trim() !== "" ? input.knownDiagnostic : conciseChildDiagnostic(input.stderr, "role run failed");
|
|
13748
|
+
const { timedOut: _knownTimedOut, ...knownDetails } = input.knownDetails ?? {};
|
|
13749
|
+
const remoteCode = knownDetails.code;
|
|
13750
|
+
return withKnownDetails(
|
|
13751
|
+
{
|
|
13752
|
+
diagnostic,
|
|
13753
|
+
details: {
|
|
13754
|
+
...knownDetails,
|
|
13755
|
+
...remoteCode === void 0 ? {} : { code: remoteCode },
|
|
13756
|
+
exitCode: input.code,
|
|
13757
|
+
...input.timedOut ? { timedOut: true } : {}
|
|
13758
|
+
},
|
|
13759
|
+
...input.knownIdentity === void 0 ? {} : { identity: input.knownIdentity }
|
|
13760
|
+
},
|
|
13761
|
+
void 0
|
|
13762
|
+
);
|
|
13763
|
+
}
|
|
13537
13764
|
if (input.timedOut) {
|
|
13538
13765
|
return withKnownDetails(
|
|
13539
13766
|
{
|
|
@@ -13587,7 +13814,7 @@ function classifyPostAdmissionFailure(input) {
|
|
|
13587
13814
|
function explicitInternalKnownFailureClassificationInput(failure2) {
|
|
13588
13815
|
if (failure2 === void 0) return {};
|
|
13589
13816
|
return {
|
|
13590
|
-
knownCause: failure2.cause,
|
|
13817
|
+
...failure2.cause === void 0 ? {} : { knownCause: failure2.cause },
|
|
13591
13818
|
...failure2.identity === void 0 ? {} : { knownIdentity: failure2.identity },
|
|
13592
13819
|
...failure2.diagnostic === void 0 ? {} : { knownDiagnostic: failure2.diagnostic },
|
|
13593
13820
|
...failure2.details === void 0 ? {} : { knownDetails: failure2.details }
|
|
@@ -13622,7 +13849,7 @@ function sessionReadFailure(error, fallbackMessage) {
|
|
|
13622
13849
|
return failed;
|
|
13623
13850
|
}
|
|
13624
13851
|
async function readBoundSessionEntries(sessionFile) {
|
|
13625
|
-
const text = await
|
|
13852
|
+
const text = await readFile17(sessionFile, "utf8");
|
|
13626
13853
|
const entries = [];
|
|
13627
13854
|
for (const line2 of text.trim().split("\n").filter(Boolean)) {
|
|
13628
13855
|
try {
|
|
@@ -13709,7 +13936,7 @@ async function readSessionProviderStop(sessionFile) {
|
|
|
13709
13936
|
}
|
|
13710
13937
|
}
|
|
13711
13938
|
async function readBoundEvidenceChildKnownFailure(sessionFile) {
|
|
13712
|
-
const childDirectory =
|
|
13939
|
+
const childDirectory = join29(dirname14(sessionFile), "evidence-children");
|
|
13713
13940
|
let names;
|
|
13714
13941
|
try {
|
|
13715
13942
|
names = await readdir5(childDirectory);
|
|
@@ -13720,7 +13947,7 @@ async function readBoundEvidenceChildKnownFailure(sessionFile) {
|
|
|
13720
13947
|
for (const file of names.filter((name) => name.endsWith(".jsonl")).sort().reverse()) {
|
|
13721
13948
|
let entries;
|
|
13722
13949
|
try {
|
|
13723
|
-
entries = await readBoundSessionEntries(
|
|
13950
|
+
entries = await readBoundSessionEntries(join29(childDirectory, file));
|
|
13724
13951
|
} catch (error) {
|
|
13725
13952
|
throw sessionReadFailure(error, "failed to read discovered evidence-child session");
|
|
13726
13953
|
}
|
|
@@ -13775,7 +14002,7 @@ async function loadBoundAuditorVolumes(sessionFile) {
|
|
|
13775
14002
|
latestParentUserIndex = i;
|
|
13776
14003
|
break;
|
|
13777
14004
|
}
|
|
13778
|
-
const childDirectories = [
|
|
14005
|
+
const childDirectories = [join29(dirname14(sessionFile), "auditor-roles")];
|
|
13779
14006
|
const valid = [];
|
|
13780
14007
|
let sawAnyDirectory = false;
|
|
13781
14008
|
for (const childDirectory of childDirectories) {
|
|
@@ -13790,7 +14017,7 @@ async function loadBoundAuditorVolumes(sessionFile) {
|
|
|
13790
14017
|
for (const file of names.filter((name) => name.endsWith(".jsonl")).sort().reverse()) {
|
|
13791
14018
|
let entries;
|
|
13792
14019
|
try {
|
|
13793
|
-
entries = await readBoundSessionEntries(
|
|
14020
|
+
entries = await readBoundSessionEntries(join29(childDirectory, file));
|
|
13794
14021
|
} catch (error) {
|
|
13795
14022
|
throw sessionReadFailure(error, "failed to read discovered auditor session");
|
|
13796
14023
|
}
|
|
@@ -13839,10 +14066,12 @@ function complianceFailureFromAuditorVolumes(volumes) {
|
|
|
13839
14066
|
if (entry?.type !== "custom" || entry.customType !== AUDITOR_COMPLIANCE_FAILURE_ENTRY_TYPE || !isRecord10(entry.data)) continue;
|
|
13840
14067
|
const parent = isRecord10(entry.data.parent) ? entry.data.parent : void 0;
|
|
13841
14068
|
const failure2 = isRecord10(entry.data.failure) ? entry.data.failure : void 0;
|
|
13842
|
-
if (parent?.sessionId !== parentId || parent.sessionFile !== sessionFile || parent.attemptEntryId !== attemptEntryId
|
|
14069
|
+
if (parent?.sessionId !== parentId || parent.sessionFile !== sessionFile || parent.attemptEntryId !== attemptEntryId) continue;
|
|
14070
|
+
if (failure2 === void 0) continue;
|
|
13843
14071
|
const identity = isRecord10(failure2.identity) ? failure2.identity : void 0;
|
|
14072
|
+
const typedCause = failure2.cause === "provider" || failure2.cause === "activation" || failure2.cause === "session" || failure2.cause === "output" || failure2.cause === "timeout" ? failure2.cause : void 0;
|
|
13844
14073
|
return {
|
|
13845
|
-
|
|
14074
|
+
...typedCause === void 0 ? {} : { cause: typedCause },
|
|
13846
14075
|
...identity === void 0 ? {} : { identity: {
|
|
13847
14076
|
...typeof identity.name === "string" ? { name: identity.name } : {},
|
|
13848
14077
|
...typeof identity.code === "string" || typeof identity.code === "number" ? { code: identity.code } : {}
|
|
@@ -14284,8 +14513,8 @@ function projectTerminalGateFact(rounds) {
|
|
|
14284
14513
|
};
|
|
14285
14514
|
}
|
|
14286
14515
|
async function extractGateFactFromSessionDirectory(sessionDirectory, options = {}) {
|
|
14287
|
-
const directories = [
|
|
14288
|
-
const parentSessionFile = options.parentSessionFile ??
|
|
14516
|
+
const directories = [join29(sessionDirectory, "auditor-roles")];
|
|
14517
|
+
const parentSessionFile = options.parentSessionFile ?? join29(sessionDirectory, "session.jsonl");
|
|
14289
14518
|
const rounds = await readAnalystGateCyclesFromAuditorRoles(directories, {
|
|
14290
14519
|
parentSessionFile
|
|
14291
14520
|
});
|
|
@@ -14383,9 +14612,9 @@ async function extractNavigatorFactFromAdmittedSession(sessionFile) {
|
|
|
14383
14612
|
async function publishJudgeArtifacts(admitted, roleOutcome, coordinates) {
|
|
14384
14613
|
await appendRunAttemptHistory({ role: admitted.role, runId: admitted.runId, sessionFile: coordinates.sessionFile }, roleOutcome);
|
|
14385
14614
|
const artifactsDir = await ensureRunArtifactsDir(admitted.runDirectory);
|
|
14386
|
-
const reportPath =
|
|
14387
|
-
const evidencePath =
|
|
14388
|
-
await
|
|
14615
|
+
const reportPath = join29(artifactsDir, "report.json");
|
|
14616
|
+
const evidencePath = join29(artifactsDir, "evidence.json");
|
|
14617
|
+
await writeFile8(
|
|
14389
14618
|
reportPath,
|
|
14390
14619
|
`${JSON.stringify(
|
|
14391
14620
|
{
|
|
@@ -14399,7 +14628,7 @@ async function publishJudgeArtifacts(admitted, roleOutcome, coordinates) {
|
|
|
14399
14628
|
`,
|
|
14400
14629
|
"utf8"
|
|
14401
14630
|
);
|
|
14402
|
-
await
|
|
14631
|
+
await writeFile8(
|
|
14403
14632
|
evidencePath,
|
|
14404
14633
|
`${JSON.stringify(
|
|
14405
14634
|
{
|
|
@@ -14485,17 +14714,15 @@ function extractDoctorCandidateAuditNoReceiptFact(entries) {
|
|
|
14485
14714
|
async function publishDoctorArtifacts(admitted, roleOutcome, coordinates, options = {}) {
|
|
14486
14715
|
await appendRunAttemptHistory({ role: admitted.role, runId: admitted.runId, sessionFile: coordinates.sessionFile }, roleOutcome);
|
|
14487
14716
|
const artifactsDir = await ensureRunArtifactsDir(admitted.runDirectory);
|
|
14488
|
-
const reportPath =
|
|
14489
|
-
const evidencePath =
|
|
14490
|
-
await
|
|
14717
|
+
const reportPath = join29(artifactsDir, "report.json");
|
|
14718
|
+
const evidencePath = join29(artifactsDir, "evidence.json");
|
|
14719
|
+
await writeFile8(
|
|
14491
14720
|
reportPath,
|
|
14492
14721
|
`${JSON.stringify(
|
|
14493
14722
|
{
|
|
14494
14723
|
role: "doctor",
|
|
14495
14724
|
runId: admitted.runId,
|
|
14496
14725
|
outcome: roleOutcome,
|
|
14497
|
-
...options.doctorOutput === void 0 ? {} : { receipt: options.doctorOutput },
|
|
14498
|
-
// Independent machine fields beside the receipt — not merged into it.
|
|
14499
14726
|
...options.cost === void 0 ? {} : { cost: options.cost },
|
|
14500
14727
|
...options.auditNoReceipt === void 0 ? {} : { auditNoReceipt: options.auditNoReceipt }
|
|
14501
14728
|
},
|
|
@@ -14505,7 +14732,7 @@ async function publishDoctorArtifacts(admitted, roleOutcome, coordinates, option
|
|
|
14505
14732
|
`,
|
|
14506
14733
|
"utf8"
|
|
14507
14734
|
);
|
|
14508
|
-
await
|
|
14735
|
+
await writeFile8(
|
|
14509
14736
|
evidencePath,
|
|
14510
14737
|
`${JSON.stringify(
|
|
14511
14738
|
{
|
|
@@ -14553,7 +14780,6 @@ async function settleLawfulDoctorTerminalResult(admitted, authority, scope) {
|
|
|
14553
14780
|
sessionDirectory
|
|
14554
14781
|
);
|
|
14555
14782
|
}
|
|
14556
|
-
const output = lastRolePayloadRecord(sealed.payloads ?? []) ?? {};
|
|
14557
14783
|
const roleOutcome = sealed;
|
|
14558
14784
|
const navigator = extractNavigatorFact(entries);
|
|
14559
14785
|
const cost = extractDoctorCandidateCostFact(entries);
|
|
@@ -14563,7 +14789,6 @@ async function settleLawfulDoctorTerminalResult(admitted, authority, scope) {
|
|
|
14563
14789
|
roleOutcome,
|
|
14564
14790
|
coordinates,
|
|
14565
14791
|
{
|
|
14566
|
-
doctorOutput: output,
|
|
14567
14792
|
...cost === void 0 ? {} : { cost },
|
|
14568
14793
|
...auditNoReceipt === void 0 ? {} : { auditNoReceipt }
|
|
14569
14794
|
}
|
|
@@ -14727,7 +14952,7 @@ function uniqueFailureFallbackDirs(runDirectory, baseDir) {
|
|
|
14727
14952
|
return dirs;
|
|
14728
14953
|
}
|
|
14729
14954
|
async function resolveFailureArtifactsBase(runDirectory) {
|
|
14730
|
-
const artifactsDir =
|
|
14955
|
+
const artifactsDir = join29(runDirectory, "artifacts");
|
|
14731
14956
|
try {
|
|
14732
14957
|
await ensureRunArtifactsDir(runDirectory);
|
|
14733
14958
|
return { baseDir: artifactsDir };
|
|
@@ -14743,13 +14968,13 @@ async function writeFailureJsonRetainingCause(preferredCandidates, uniqueFallbac
|
|
|
14743
14968
|
const candidates = [
|
|
14744
14969
|
...preferredCandidates,
|
|
14745
14970
|
// One unique name per fallback dir — collisions on fixed names cannot exhaust this.
|
|
14746
|
-
...uniqueFallbackDirs.map((dir) =>
|
|
14971
|
+
...uniqueFallbackDirs.map((dir) => join29(dir, `${stem}.${randomUUID3()}.json`))
|
|
14747
14972
|
];
|
|
14748
14973
|
for (let i = 0; i < candidates.length; i += 1) {
|
|
14749
14974
|
const path = candidates[i];
|
|
14750
14975
|
const payload = issues.length === 0 ? basePayload : { ...basePayload, publicationIssues: issues };
|
|
14751
14976
|
try {
|
|
14752
|
-
await
|
|
14977
|
+
await writeFile8(
|
|
14753
14978
|
path,
|
|
14754
14979
|
`${JSON.stringify(payload, null, 2)}
|
|
14755
14980
|
`,
|
|
@@ -14788,32 +15013,32 @@ async function publishFailureArtifacts(admitted, failure2, authority) {
|
|
|
14788
15013
|
} catch (error) {
|
|
14789
15014
|
priorIssues.push(publicationAttemptFromError(sessionFile, error));
|
|
14790
15015
|
}
|
|
14791
|
-
const underArtifacts = baseDir ===
|
|
15016
|
+
const underArtifacts = baseDir === join29(admitted.runDirectory, "artifacts");
|
|
14792
15017
|
const uniqueFallbackDirs = uniqueFailureFallbackDirs(
|
|
14793
15018
|
admitted.runDirectory,
|
|
14794
15019
|
baseDir
|
|
14795
15020
|
);
|
|
14796
15021
|
const errorCandidates = underArtifacts ? [
|
|
14797
|
-
|
|
14798
|
-
|
|
14799
|
-
|
|
15022
|
+
join29(baseDir, "error.json"),
|
|
15023
|
+
join29(baseDir, "error.settlement.json"),
|
|
15024
|
+
join29(admitted.runDirectory, "error.settlement.json")
|
|
14800
15025
|
] : [
|
|
14801
|
-
|
|
14802
|
-
|
|
15026
|
+
join29(baseDir, "error.settlement.json"),
|
|
15027
|
+
join29(baseDir, "error.json")
|
|
14803
15028
|
];
|
|
14804
15029
|
const evidenceCandidates = underArtifacts ? [
|
|
14805
|
-
|
|
14806
|
-
|
|
14807
|
-
|
|
15030
|
+
join29(baseDir, "evidence.json"),
|
|
15031
|
+
join29(baseDir, "evidence.settlement.json"),
|
|
15032
|
+
join29(admitted.runDirectory, "evidence.settlement.json")
|
|
14808
15033
|
] : [
|
|
14809
|
-
|
|
14810
|
-
|
|
15034
|
+
join29(baseDir, "evidence.settlement.json"),
|
|
15035
|
+
join29(baseDir, "evidence.json")
|
|
14811
15036
|
];
|
|
14812
15037
|
const errorPayloadBase = {
|
|
14813
15038
|
kind: "error",
|
|
14814
15039
|
role: admitted.role,
|
|
14815
15040
|
runId: admitted.runId,
|
|
14816
|
-
cause: failure2.cause,
|
|
15041
|
+
...failure2.cause === void 0 ? {} : { cause: failure2.cause },
|
|
14817
15042
|
diagnostic: failure2.diagnostic,
|
|
14818
15043
|
...failure2.identity === void 0 ? {} : { identity: failure2.identity },
|
|
14819
15044
|
...failure2.details === void 0 ? {} : { details: failure2.details }
|
|
@@ -14836,7 +15061,7 @@ async function publishFailureArtifacts(admitted, failure2, authority) {
|
|
|
14836
15061
|
sha256: a.sha256,
|
|
14837
15062
|
byteLength: a.byteLength
|
|
14838
15063
|
})),
|
|
14839
|
-
failureCause: failure2.cause
|
|
15064
|
+
...failure2.cause === void 0 ? {} : { failureCause: failure2.cause }
|
|
14840
15065
|
};
|
|
14841
15066
|
const evidenceWrite = await writeFailureJsonRetainingCause(
|
|
14842
15067
|
evidenceCandidates,
|
|
@@ -14900,7 +15125,7 @@ async function settleFailureTerminalResult(admitted, failure2, authority, option
|
|
|
14900
15125
|
const navigator = await extractNavigatorFactFromAdmittedSession(sessionFile);
|
|
14901
15126
|
const artifacts = await publishFailureArtifacts(admitted, failure2, authority);
|
|
14902
15127
|
const decisiveFacts = {
|
|
14903
|
-
cause: failure2.cause,
|
|
15128
|
+
...failure2.cause === void 0 ? {} : { cause: failure2.cause },
|
|
14904
15129
|
diagnostic: failure2.diagnostic
|
|
14905
15130
|
};
|
|
14906
15131
|
if (failure2.identity?.name !== void 0) {
|
|
@@ -14916,7 +15141,7 @@ async function settleFailureTerminalResult(admitted, failure2, authority, option
|
|
|
14916
15141
|
const roleOutcome2 = {
|
|
14917
15142
|
kind: "failure",
|
|
14918
15143
|
role: admitted.role,
|
|
14919
|
-
cause: failure2.cause,
|
|
15144
|
+
...failure2.cause === void 0 ? {} : { cause: failure2.cause },
|
|
14920
15145
|
diagnostic: failure2.diagnostic,
|
|
14921
15146
|
decisiveFacts
|
|
14922
15147
|
};
|
|
@@ -14933,7 +15158,7 @@ async function settleFailureTerminalResult(admitted, failure2, authority, option
|
|
|
14933
15158
|
const roleOutcome = {
|
|
14934
15159
|
kind: "failure",
|
|
14935
15160
|
role: admitted.role,
|
|
14936
|
-
cause: failure2.cause,
|
|
15161
|
+
...failure2.cause === void 0 ? {} : { cause: failure2.cause },
|
|
14937
15162
|
diagnostic: failure2.diagnostic,
|
|
14938
15163
|
decisiveFacts
|
|
14939
15164
|
};
|
|
@@ -14954,7 +15179,7 @@ function presentFailureTerminal(terminal, io) {
|
|
|
14954
15179
|
io.stdout(formatTerminalResult(terminal));
|
|
14955
15180
|
if (terminal.roleOutcome.kind === "failure") {
|
|
14956
15181
|
io.stderr(formatFailureStderrDiagnostic({
|
|
14957
|
-
cause: terminal.roleOutcome.cause,
|
|
15182
|
+
...terminal.roleOutcome.cause === void 0 ? {} : { cause: terminal.roleOutcome.cause },
|
|
14958
15183
|
diagnostic: terminal.roleOutcome.diagnostic
|
|
14959
15184
|
}));
|
|
14960
15185
|
return;
|
|
@@ -15052,7 +15277,7 @@ var init_settlement = __esm({
|
|
|
15052
15277
|
import { constants as fsConstants2 } from "node:fs";
|
|
15053
15278
|
import { randomUUID as randomUUID4 } from "node:crypto";
|
|
15054
15279
|
import { lstat as lstat5, mkdir as mkdir5, open as open2 } from "node:fs/promises";
|
|
15055
|
-
import { join as
|
|
15280
|
+
import { join as join30 } from "node:path";
|
|
15056
15281
|
async function persistReturnedRunState(admitted, authority, options) {
|
|
15057
15282
|
if (options?.lawful === true) {
|
|
15058
15283
|
await markRunTerminal(admitted.runDirectory);
|
|
@@ -15088,7 +15313,7 @@ async function finalizeExceptionRunBestEffort(runDirectory, io) {
|
|
|
15088
15313
|
}
|
|
15089
15314
|
}
|
|
15090
15315
|
function runArtifactsDirectory(runDirectory) {
|
|
15091
|
-
return
|
|
15316
|
+
return join30(runDirectory, "artifacts");
|
|
15092
15317
|
}
|
|
15093
15318
|
async function ensureRealArtifactsDirectory(runDirectory) {
|
|
15094
15319
|
const runStat = await lstat5(runDirectory);
|
|
@@ -15170,7 +15395,7 @@ function jsonSafeReplacer() {
|
|
|
15170
15395
|
};
|
|
15171
15396
|
}
|
|
15172
15397
|
async function writeHardenedArtifactFile(artifactsDir, namePrefix, payload) {
|
|
15173
|
-
const filePath =
|
|
15398
|
+
const filePath = join30(artifactsDir, `${namePrefix}-${randomUUID4()}.json`);
|
|
15174
15399
|
const body = `${JSON.stringify(payload, jsonSafeReplacer(), 2)}
|
|
15175
15400
|
`;
|
|
15176
15401
|
const noFollowFlag = typeof fsConstants2.O_NOFOLLOW === "number" ? fsConstants2.O_NOFOLLOW : 0;
|
|
@@ -15224,12 +15449,29 @@ function unwrapTurnDispatchedFailure(error) {
|
|
|
15224
15449
|
}
|
|
15225
15450
|
return current;
|
|
15226
15451
|
}
|
|
15452
|
+
async function attachDispatchExceptionTerminal(admitted, terminal, io) {
|
|
15453
|
+
try {
|
|
15454
|
+
return await attachRecordedSubmissions(
|
|
15455
|
+
{
|
|
15456
|
+
projectRoot: admitted.projectRoot,
|
|
15457
|
+
runId: admitted.runId,
|
|
15458
|
+
runDirectory: admitted.runDirectory
|
|
15459
|
+
},
|
|
15460
|
+
terminal
|
|
15461
|
+
);
|
|
15462
|
+
} catch (error) {
|
|
15463
|
+
io.stderr(
|
|
15464
|
+
`dispatch exception ledger attach failed (best-effort continue): ${describeErrorIdentity(error)}
|
|
15465
|
+
`
|
|
15466
|
+
);
|
|
15467
|
+
return terminal;
|
|
15468
|
+
}
|
|
15469
|
+
}
|
|
15227
15470
|
function dispatchExceptionFailureTerminal(input) {
|
|
15228
15471
|
const causeError = unwrapTurnDispatchedFailure(input.causeError);
|
|
15229
15472
|
const history = input.everyAttemptThrew ? "dispatch threw an exception on every attempt" : "the final dispatch threw an exception";
|
|
15230
15473
|
const diagnostic = `${history} (${input.endReason}; resumes used ${input.autoResumeAttempts}); last cause: ${describeErrorIdentity(causeError)}`;
|
|
15231
15474
|
const decisiveFacts = {
|
|
15232
|
-
cause: "unrecognized",
|
|
15233
15475
|
diagnostic,
|
|
15234
15476
|
resumesUsed: input.autoResumeAttempts,
|
|
15235
15477
|
dispatchErrorFiles: [...input.errorFiles]
|
|
@@ -15250,7 +15492,6 @@ function dispatchExceptionFailureTerminal(input) {
|
|
|
15250
15492
|
roleOutcome: {
|
|
15251
15493
|
kind: "failure",
|
|
15252
15494
|
role: input.role,
|
|
15253
|
-
cause: "unrecognized",
|
|
15254
15495
|
diagnostic,
|
|
15255
15496
|
decisiveFacts
|
|
15256
15497
|
},
|
|
@@ -15350,15 +15591,19 @@ async function runWithAutoResumeLoop(options) {
|
|
|
15350
15591
|
}
|
|
15351
15592
|
} else {
|
|
15352
15593
|
if (autoResumeAttempts >= limit) {
|
|
15353
|
-
const terminal =
|
|
15354
|
-
|
|
15355
|
-
|
|
15356
|
-
|
|
15357
|
-
|
|
15358
|
-
|
|
15359
|
-
|
|
15360
|
-
|
|
15361
|
-
|
|
15594
|
+
const terminal = await attachDispatchExceptionTerminal(
|
|
15595
|
+
options.admitted,
|
|
15596
|
+
dispatchExceptionFailureTerminal({
|
|
15597
|
+
role: options.admitted.role,
|
|
15598
|
+
runId: options.admitted.runId,
|
|
15599
|
+
causeError: lastThrownError,
|
|
15600
|
+
errorFiles: retainedErrorFiles,
|
|
15601
|
+
autoResumeAttempts,
|
|
15602
|
+
endReason: "auto-resume budget exhausted",
|
|
15603
|
+
everyAttemptThrew
|
|
15604
|
+
}),
|
|
15605
|
+
options.io
|
|
15606
|
+
);
|
|
15362
15607
|
await finalizeExceptionRunBestEffort(options.admitted.runDirectory, options.io);
|
|
15363
15608
|
presentTerminal(terminal, options.io);
|
|
15364
15609
|
return {
|
|
@@ -15367,15 +15612,19 @@ async function runWithAutoResumeLoop(options) {
|
|
|
15367
15612
|
};
|
|
15368
15613
|
}
|
|
15369
15614
|
if (!await isPrincipalAvailable(options.admitted.principal)) {
|
|
15370
|
-
const terminal =
|
|
15371
|
-
|
|
15372
|
-
|
|
15373
|
-
|
|
15374
|
-
|
|
15375
|
-
|
|
15376
|
-
|
|
15377
|
-
|
|
15378
|
-
|
|
15615
|
+
const terminal = await attachDispatchExceptionTerminal(
|
|
15616
|
+
options.admitted,
|
|
15617
|
+
dispatchExceptionFailureTerminal({
|
|
15618
|
+
role: options.admitted.role,
|
|
15619
|
+
runId: options.admitted.runId,
|
|
15620
|
+
causeError: lastThrownError,
|
|
15621
|
+
errorFiles: retainedErrorFiles,
|
|
15622
|
+
autoResumeAttempts,
|
|
15623
|
+
endReason: "session principal unavailable before further resume",
|
|
15624
|
+
everyAttemptThrew
|
|
15625
|
+
}),
|
|
15626
|
+
options.io
|
|
15627
|
+
);
|
|
15379
15628
|
await finalizeExceptionRunBestEffort(options.admitted.runDirectory, options.io);
|
|
15380
15629
|
presentTerminal(terminal, options.io);
|
|
15381
15630
|
return {
|
|
@@ -15417,8 +15666,8 @@ var init_auto_resume = __esm({
|
|
|
15417
15666
|
|
|
15418
15667
|
// src/public-cli/post-admission.ts
|
|
15419
15668
|
import { randomUUID as randomUUID5 } from "node:crypto";
|
|
15420
|
-
import { readFile as
|
|
15421
|
-
import { isAbsolute as isAbsolute8, join as
|
|
15669
|
+
import { readFile as readFile18, writeFile as writeFile9 } from "node:fs/promises";
|
|
15670
|
+
import { isAbsolute as isAbsolute8, join as join31, resolve as resolve13 } from "node:path";
|
|
15422
15671
|
function describeCaughtError(error) {
|
|
15423
15672
|
if (error instanceof Error) {
|
|
15424
15673
|
const code = error.code;
|
|
@@ -15432,6 +15681,9 @@ function appendContinuationSection(continuation, section) {
|
|
|
15432
15681
|
${section}`;
|
|
15433
15682
|
return continuation.kind === "initial" ? { kind: "initial", prompt } : { kind: "resume", prompt };
|
|
15434
15683
|
}
|
|
15684
|
+
function isStationChildOfficerDialogue(role, env) {
|
|
15685
|
+
return env.stationChild === true && isOfficerReviewSeat(role);
|
|
15686
|
+
}
|
|
15435
15687
|
function withOnceSuccessfulBeforeDispatch(adapters) {
|
|
15436
15688
|
const hook = adapters.beforeDispatch;
|
|
15437
15689
|
if (hook === void 0) return adapters;
|
|
@@ -15459,8 +15711,8 @@ async function recordBestEffortPostDispatchDiagnostic(admitted, env, diagnostic,
|
|
|
15459
15711
|
} catch (appendError) {
|
|
15460
15712
|
try {
|
|
15461
15713
|
const artifactsDir = await ensureRealArtifactsDirectory(admitted.runDirectory);
|
|
15462
|
-
await
|
|
15463
|
-
|
|
15714
|
+
await writeFile9(
|
|
15715
|
+
join31(artifactsDir, `post-admission-diagnostic-${randomUUID5()}.json`),
|
|
15464
15716
|
`${JSON.stringify({ version: 1, ...payload }, null, 2)}
|
|
15465
15717
|
`,
|
|
15466
15718
|
{ encoding: "utf8", flag: "wx" }
|
|
@@ -15476,7 +15728,7 @@ async function recordBestEffortPostDispatchDiagnostic(admitted, env, diagnostic,
|
|
|
15476
15728
|
}
|
|
15477
15729
|
async function readInvocationHost(runDirectory) {
|
|
15478
15730
|
try {
|
|
15479
|
-
const raw = JSON.parse(await
|
|
15731
|
+
const raw = JSON.parse(await readFile18(join31(runDirectory, "invocation.json"), "utf8"));
|
|
15480
15732
|
return typeof raw.host === "string" && raw.host.trim() !== "" ? raw.host : void 0;
|
|
15481
15733
|
} catch (error) {
|
|
15482
15734
|
if (error.code === "ENOENT") return void 0;
|
|
@@ -15649,19 +15901,28 @@ async function dispatchPostAdmissionTurn(input) {
|
|
|
15649
15901
|
if (hostTransition !== void 0) {
|
|
15650
15902
|
turnRequest = { ...turnRequest, hostTransition };
|
|
15651
15903
|
}
|
|
15652
|
-
|
|
15653
|
-
|
|
15654
|
-
|
|
15655
|
-
|
|
15656
|
-
|
|
15657
|
-
|
|
15658
|
-
|
|
15659
|
-
|
|
15660
|
-
|
|
15661
|
-
|
|
15662
|
-
|
|
15663
|
-
|
|
15664
|
-
};
|
|
15904
|
+
if (isStationChildOfficerDialogue(admitted.role, env)) {
|
|
15905
|
+
await deliverCaseDossierAsAttachment({
|
|
15906
|
+
ticketNumber: admitted.ticketNumber,
|
|
15907
|
+
projectRoot: admitted.projectRoot,
|
|
15908
|
+
home: env.home,
|
|
15909
|
+
runDirectory: admitted.runDirectory
|
|
15910
|
+
});
|
|
15911
|
+
} else {
|
|
15912
|
+
const dossierSection = await projectCaseDossierPointerSection({
|
|
15913
|
+
ticketNumber: admitted.ticketNumber,
|
|
15914
|
+
projectRoot: admitted.projectRoot,
|
|
15915
|
+
home: env.home
|
|
15916
|
+
});
|
|
15917
|
+
if (dossierSection !== void 0) {
|
|
15918
|
+
turnRequest = {
|
|
15919
|
+
...turnRequest,
|
|
15920
|
+
continuation: appendContinuationSection(
|
|
15921
|
+
turnRequest.continuation,
|
|
15922
|
+
dossierSection
|
|
15923
|
+
)
|
|
15924
|
+
};
|
|
15925
|
+
}
|
|
15665
15926
|
}
|
|
15666
15927
|
await markRunRunning(
|
|
15667
15928
|
admitted.runDirectory,
|
|
@@ -15691,8 +15952,8 @@ async function dispatchPostAdmissionTurn(input) {
|
|
|
15691
15952
|
}
|
|
15692
15953
|
let stderrLogWriteFailure;
|
|
15693
15954
|
try {
|
|
15694
|
-
await
|
|
15695
|
-
|
|
15955
|
+
await writeFile9(
|
|
15956
|
+
join31(admitted.runDirectory, "stderr.log"),
|
|
15696
15957
|
result.stderr,
|
|
15697
15958
|
"utf8"
|
|
15698
15959
|
);
|
|
@@ -15881,25 +16142,17 @@ async function dispatchPostAdmissionTurn(input) {
|
|
|
15881
16142
|
}
|
|
15882
16143
|
}
|
|
15883
16144
|
function resumeTurnRequestProjectionOptions(admitted, request, env, summonsPrepared) {
|
|
15884
|
-
const
|
|
15885
|
-
const withReread = (body) => {
|
|
15886
|
-
if (officerSourcePath === void 0 || admitted.role !== "notary" && admitted.role !== "inspector" && admitted.role !== "auditor") {
|
|
15887
|
-
return body;
|
|
15888
|
-
}
|
|
15889
|
-
if (body.startsWith("\u8BF7\u91CD\u8BFB")) return body;
|
|
15890
|
-
return `\u8BF7\u91CD\u8BFB
|
|
15891
|
-
${body}`;
|
|
15892
|
-
};
|
|
16145
|
+
const officerDialogue = isStationChildOfficerDialogue(admitted.role, env);
|
|
15893
16146
|
let prompt;
|
|
15894
16147
|
if (request.message !== void 0) {
|
|
15895
16148
|
if (summonsPrepared !== void 0) {
|
|
15896
|
-
prompt =
|
|
16149
|
+
prompt = officerDialogue ? request.message : buildInstructionTransportPrompt({
|
|
15897
16150
|
instruction: request.message,
|
|
15898
16151
|
instructionEmpty: false,
|
|
15899
16152
|
attachments: summonsPrepared.attachments
|
|
15900
|
-
})
|
|
16153
|
+
});
|
|
15901
16154
|
} else if (request.summons !== void 0) {
|
|
15902
|
-
prompt =
|
|
16155
|
+
prompt = request.message;
|
|
15903
16156
|
} else {
|
|
15904
16157
|
prompt = buildResumeContinuationPrompt({
|
|
15905
16158
|
packageRoot: env.packageRoot,
|
|
@@ -15908,17 +16161,9 @@ ${body}`;
|
|
|
15908
16161
|
});
|
|
15909
16162
|
}
|
|
15910
16163
|
} else if (summonsPrepared !== void 0) {
|
|
15911
|
-
prompt =
|
|
16164
|
+
prompt = officerDialogue ? summonsPrepared.instructionEmpty ? "" : summonsPrepared.instruction : buildInstructionTransportPrompt(summonsPrepared);
|
|
15912
16165
|
} else if (request.summons !== void 0) {
|
|
15913
|
-
|
|
15914
|
-
if (path !== void 0 && (admitted.role === "notary" || admitted.role === "inspector" || admitted.role === "auditor")) {
|
|
15915
|
-
prompt = `\u8BF7\u91CD\u8BFB
|
|
15916
|
-
${GATE_DOSSIER_POINTER_PREFIX}${path}`;
|
|
15917
|
-
} else if (admitted.role === "notary" || admitted.role === "inspector" || admitted.role === "auditor") {
|
|
15918
|
-
prompt = "\u8BF7\u91CD\u8BFB";
|
|
15919
|
-
} else {
|
|
15920
|
-
prompt = "";
|
|
15921
|
-
}
|
|
16166
|
+
prompt = "";
|
|
15922
16167
|
} else {
|
|
15923
16168
|
prompt = buildResumeContinuationPrompt({
|
|
15924
16169
|
packageRoot: env.packageRoot,
|
|
@@ -15955,7 +16200,7 @@ async function dispatchAfterWriterLease(input) {
|
|
|
15955
16200
|
}
|
|
15956
16201
|
function isAlreadyFrozenSummonsAttachment(runDirectory, attachmentPath) {
|
|
15957
16202
|
const absolute = isAbsolute8(attachmentPath) ? attachmentPath : resolve13(attachmentPath);
|
|
15958
|
-
return pathContainedIn(
|
|
16203
|
+
return pathContainedIn(join31(runDirectory, "attachments"), absolute);
|
|
15959
16204
|
}
|
|
15960
16205
|
async function prepareSummonsResumeMaterials(runDirectory, summons) {
|
|
15961
16206
|
if (summons === void 0) return void 0;
|
|
@@ -16251,6 +16496,7 @@ var init_post_admission = __esm({
|
|
|
16251
16496
|
init_activation_ledger_topology();
|
|
16252
16497
|
init_engine_material();
|
|
16253
16498
|
init_session_identity();
|
|
16499
|
+
init_host_contracts();
|
|
16254
16500
|
init_case_dossier_delivery();
|
|
16255
16501
|
init_host_transition_prior_native();
|
|
16256
16502
|
init_public_run_credentials();
|
|
@@ -16344,7 +16590,7 @@ async function runPublicNotary(argv, env, io, parseNotaryArgv2) {
|
|
|
16344
16590
|
throw error;
|
|
16345
16591
|
}
|
|
16346
16592
|
{
|
|
16347
|
-
const resumeInstruction = env.reviewReask;
|
|
16593
|
+
const resumeInstruction = env.reviewReask ?? env.gateReviewInstruction;
|
|
16348
16594
|
const summons = {
|
|
16349
16595
|
sourceRunPath: source.runDirectory,
|
|
16350
16596
|
sourceRun: source,
|
|
@@ -16399,7 +16645,9 @@ async function runPublicNotary(argv, env, io, parseNotaryArgv2) {
|
|
|
16399
16645
|
...env.correlationId === void 0 || env.correlationId.trim() === "" ? {} : { correlationId: env.correlationId },
|
|
16400
16646
|
continuation: {
|
|
16401
16647
|
kind: "initial",
|
|
16402
|
-
|
|
16648
|
+
// #879: gate path first mint carries parent payload as dialogue content;
|
|
16649
|
+
// external zero-prompt kickoff unchanged when no body/reask.
|
|
16650
|
+
prompt: env.reviewReask ?? env.gateReviewInstruction ?? buildNotaryTransportPrompt(admitted, engineMaterial)
|
|
16403
16651
|
}
|
|
16404
16652
|
});
|
|
16405
16653
|
return await runPostAdmissionOneShot({
|
|
@@ -16487,12 +16735,20 @@ __export(inspector_run_exports, {
|
|
|
16487
16735
|
runPublicInspector: () => runPublicInspector,
|
|
16488
16736
|
runPublicInspectorResume: () => runPublicInspectorResume
|
|
16489
16737
|
});
|
|
16738
|
+
function inspectorParentRunPath(admitted) {
|
|
16739
|
+
if (typeof admitted.sourceRunPath === "string" && admitted.sourceRunPath.trim() !== "") {
|
|
16740
|
+
return admitted.sourceRunPath;
|
|
16741
|
+
}
|
|
16742
|
+
return parentRunPathFromGatePointerInstruction(admitted.instruction);
|
|
16743
|
+
}
|
|
16490
16744
|
function buildInspectorTurnRequest(admitted, options) {
|
|
16745
|
+
const sourceRun = inspectorParentRunPath(admitted);
|
|
16491
16746
|
return projectRoleTurnRequest(
|
|
16492
16747
|
admitted,
|
|
16493
16748
|
{
|
|
16494
16749
|
activation: {
|
|
16495
|
-
role: "inspector"
|
|
16750
|
+
role: "inspector",
|
|
16751
|
+
...sourceRun === void 0 ? {} : { sourceRun }
|
|
16496
16752
|
}
|
|
16497
16753
|
},
|
|
16498
16754
|
options
|
|
@@ -16512,7 +16768,7 @@ async function runPublicInspector(argv, env, io, parseInspectorArgv2) {
|
|
|
16512
16768
|
const projectRoot = parsed.project ?? env.cwd;
|
|
16513
16769
|
const parentRunPath = parentRunPathFromGatePointerInstruction(parsed.instruction);
|
|
16514
16770
|
if (parentRunPath !== void 0) {
|
|
16515
|
-
const resumeInstruction = env.reviewReask;
|
|
16771
|
+
const resumeInstruction = env.reviewReask ?? env.gateReviewInstruction;
|
|
16516
16772
|
const summons = {
|
|
16517
16773
|
sourceRunPath: parentRunPath,
|
|
16518
16774
|
...resumeInstruction === void 0 ? {
|
|
@@ -16557,6 +16813,10 @@ async function runPublicInspector(argv, env, io, parseInspectorArgv2) {
|
|
|
16557
16813
|
throw error;
|
|
16558
16814
|
}
|
|
16559
16815
|
await markRunAdmitted(admitted, env.principalAuthority);
|
|
16816
|
+
if (parentRunPath !== void 0) {
|
|
16817
|
+
await persistAdmittedSourceRunPath(admitted, parentRunPath);
|
|
16818
|
+
admitted = { ...admitted, sourceRunPath: parentRunPath };
|
|
16819
|
+
}
|
|
16560
16820
|
const engineMaterial = engineSessionMaterialFromOptions({
|
|
16561
16821
|
...pickEngineAxis(env),
|
|
16562
16822
|
packageRoot: env.packageRoot
|
|
@@ -16571,7 +16831,8 @@ async function runPublicInspector(argv, env, io, parseInspectorArgv2) {
|
|
|
16571
16831
|
...env.correlationId === void 0 || env.correlationId.trim() === "" ? {} : { correlationId: env.correlationId },
|
|
16572
16832
|
continuation: {
|
|
16573
16833
|
kind: "initial",
|
|
16574
|
-
|
|
16834
|
+
// #879: gate first mint uses parent payload as content; binding stays typed activation.
|
|
16835
|
+
prompt: env.reviewReask ?? env.gateReviewInstruction ?? buildInspectorTransportPrompt(admitted, engineMaterial)
|
|
16575
16836
|
}
|
|
16576
16837
|
});
|
|
16577
16838
|
return await runPostAdmissionOneShot({
|
|
@@ -16673,7 +16934,7 @@ function instructionSeatAdapters(options) {
|
|
|
16673
16934
|
}) => {
|
|
16674
16935
|
const infrastructureFailure = await readEngineDetourInfrastructureFailure(sessionFile);
|
|
16675
16936
|
return infrastructureFailure === void 0 ? result.knownFailure : {
|
|
16676
|
-
cause: infrastructureFailure.cause,
|
|
16937
|
+
...infrastructureFailure.cause === void 0 ? {} : { cause: infrastructureFailure.cause },
|
|
16677
16938
|
diagnostic: infrastructureFailure.diagnostic,
|
|
16678
16939
|
...infrastructureFailure.identity === void 0 ? {} : { identity: infrastructureFailure.identity }
|
|
16679
16940
|
};
|
|
@@ -16795,7 +17056,7 @@ async function runPublicInstructionSeat(argv, env, io, role, parseArgv) {
|
|
|
16795
17056
|
return { exitCode: 2 };
|
|
16796
17057
|
}
|
|
16797
17058
|
}
|
|
16798
|
-
const resumeInstruction = env.reviewReask;
|
|
17059
|
+
const resumeInstruction = env.reviewReask ?? env.gateReviewInstruction;
|
|
16799
17060
|
const summons = {
|
|
16800
17061
|
...resumeInstruction === void 0 ? {
|
|
16801
17062
|
instruction: parsed.instruction,
|
|
@@ -16861,7 +17122,8 @@ async function runPublicInstructionSeat(argv, env, io, role, parseArgv) {
|
|
|
16861
17122
|
...env.correlationId === void 0 || env.correlationId.trim() === "" ? {} : { correlationId: env.correlationId },
|
|
16862
17123
|
continuation: {
|
|
16863
17124
|
kind: "initial",
|
|
16864
|
-
|
|
17125
|
+
// #879: gate first mint uses parent payload as content when present.
|
|
17126
|
+
prompt: env.reviewReask ?? env.gateReviewInstruction ?? buildInstructionTransportPrompt(
|
|
16865
17127
|
admitted,
|
|
16866
17128
|
engineSessionMaterialFromOptions({
|
|
16867
17129
|
...pickEngineAxis(env),
|
|
@@ -16918,7 +17180,7 @@ function judgeAdapters() {
|
|
|
16918
17180
|
resolveRunnerKnownFailure: async ({ result, sessionFile }) => {
|
|
16919
17181
|
const infrastructureFailure = await readEngineDetourInfrastructureFailure(sessionFile);
|
|
16920
17182
|
return result.knownFailure ?? (infrastructureFailure === void 0 ? void 0 : {
|
|
16921
|
-
cause: infrastructureFailure.cause,
|
|
17183
|
+
...infrastructureFailure.cause === void 0 ? {} : { cause: infrastructureFailure.cause },
|
|
16922
17184
|
diagnostic: infrastructureFailure.diagnostic,
|
|
16923
17185
|
...infrastructureFailure.identity === void 0 ? {} : { identity: infrastructureFailure.identity }
|
|
16924
17186
|
});
|
|
@@ -17230,15 +17492,11 @@ async function runPublicDiarist(argv, env, io, parseDiaristArgv2) {
|
|
|
17230
17492
|
...env.engine === void 0 ? {} : { effectiveEngine: env.engine }
|
|
17231
17493
|
}).then(async (result) => {
|
|
17232
17494
|
if (admitted.ticketNumber === void 0 && result.admitted !== void 0) {
|
|
17233
|
-
const
|
|
17234
|
-
|
|
17235
|
-
|
|
17236
|
-
|
|
17237
|
-
|
|
17238
|
-
admitted.ticketNumber = raw;
|
|
17239
|
-
if (result.admitted.ticketNumber === void 0) {
|
|
17240
|
-
result.admitted.ticketNumber = raw;
|
|
17241
|
-
}
|
|
17495
|
+
const fromPages = await readRunTicketNumber(admitted.runDirectory);
|
|
17496
|
+
if (fromPages !== void 0) {
|
|
17497
|
+
await bindAdmittedTicketNumber(admitted, fromPages);
|
|
17498
|
+
if (result.admitted.ticketNumber === void 0) {
|
|
17499
|
+
result.admitted.ticketNumber = fromPages;
|
|
17242
17500
|
}
|
|
17243
17501
|
}
|
|
17244
17502
|
}
|
|
@@ -17280,8 +17538,8 @@ var init_diarist_run = __esm({
|
|
|
17280
17538
|
init_run_lifecycle();
|
|
17281
17539
|
init_seat_ticket_binding();
|
|
17282
17540
|
init_settlement();
|
|
17283
|
-
init_terminal();
|
|
17284
17541
|
init_turn_request();
|
|
17542
|
+
init_run_ticket_number();
|
|
17285
17543
|
}
|
|
17286
17544
|
});
|
|
17287
17545
|
|
|
@@ -17294,7 +17552,7 @@ __export(public_role_summons_exports, {
|
|
|
17294
17552
|
summonPublicRole: () => summonPublicRole
|
|
17295
17553
|
});
|
|
17296
17554
|
import { existsSync as existsSync10 } from "node:fs";
|
|
17297
|
-
import { join as
|
|
17555
|
+
import { join as join32 } from "node:path";
|
|
17298
17556
|
function createCapturingIo() {
|
|
17299
17557
|
const chunks = [];
|
|
17300
17558
|
return {
|
|
@@ -17317,7 +17575,7 @@ function parentDir(path) {
|
|
|
17317
17575
|
function walkPackageRoot(start) {
|
|
17318
17576
|
let dir = start;
|
|
17319
17577
|
for (let i = 0; i < 12; i += 1) {
|
|
17320
|
-
if (existsSync10(
|
|
17578
|
+
if (existsSync10(join32(dir, "package.json")) && existsSync10(join32(dir, "souls"))) {
|
|
17321
17579
|
return dir;
|
|
17322
17580
|
}
|
|
17323
17581
|
const parent = parentDir(dir);
|
|
@@ -17411,7 +17669,7 @@ async function createSummonEnv(options) {
|
|
|
17411
17669
|
async function summonPublicRole(options) {
|
|
17412
17670
|
const packageRoot = resolveSummonsPackageRoot(options.packageRoot);
|
|
17413
17671
|
const home = await resolveSummonHome(options);
|
|
17414
|
-
const agentDir = options.agentDir ?? process.env.PI_CODING_AGENT_DIR ??
|
|
17672
|
+
const agentDir = options.agentDir ?? process.env.PI_CODING_AGENT_DIR ?? join32(home, ".pi", "agent");
|
|
17415
17673
|
const {
|
|
17416
17674
|
loadCredentialProviders: loadCredentialProviders2,
|
|
17417
17675
|
loadPublicCliConfig: loadPublicCliConfig2,
|
|
@@ -17452,6 +17710,8 @@ async function summonPublicRole(options) {
|
|
|
17452
17710
|
...options.signal === void 0 ? {} : { signal: options.signal },
|
|
17453
17711
|
// #753: reask rides the existing notary same-ticket resume summons.instruction.
|
|
17454
17712
|
...options.reviewReask === void 0 ? {} : { reviewReask: options.reviewReask },
|
|
17713
|
+
// #879: verbatim submission body on officer dialogue content channel.
|
|
17714
|
+
...options.gateReviewInstruction === void 0 ? {} : { gateReviewInstruction: options.gateReviewInstruction },
|
|
17455
17715
|
...options.boundTicketNumber === void 0 ? {} : { boundTicketNumber: options.boundTicketNumber },
|
|
17456
17716
|
// createRunId is the only remaining env overlay — host is seat-selected above.
|
|
17457
17717
|
...options.createRunId === void 0 ? {} : { createRunId: options.createRunId }
|
|
@@ -17559,6 +17819,11 @@ async function summonGateOfficer(options) {
|
|
|
17559
17819
|
const { homeFromRunDirectory: homeFromRunDirectory3 } = await Promise.resolve().then(() => (init_activation_ledger_topology(), activation_ledger_topology_exports));
|
|
17560
17820
|
home = homeFromRunDirectory3(options.sourceRunDirectory);
|
|
17561
17821
|
}
|
|
17822
|
+
let gateReviewInstruction;
|
|
17823
|
+
if (options.reask === void 0 && options.submission !== void 0) {
|
|
17824
|
+
const { readableGateItem: readableGateItem2 } = await Promise.resolve().then(() => (init_readable_gate_item(), readable_gate_item_exports));
|
|
17825
|
+
gateReviewInstruction = readableGateItem2(options.submission);
|
|
17826
|
+
}
|
|
17562
17827
|
const common = {
|
|
17563
17828
|
cwd: options.cwd,
|
|
17564
17829
|
...home === void 0 ? {} : { home },
|
|
@@ -17566,6 +17831,7 @@ async function summonGateOfficer(options) {
|
|
|
17566
17831
|
...options.io === void 0 ? {} : { io: options.io },
|
|
17567
17832
|
...options.signal === void 0 ? {} : { signal: options.signal },
|
|
17568
17833
|
...options.reask === void 0 ? {} : { reviewReask: options.reask },
|
|
17834
|
+
...gateReviewInstruction === void 0 ? {} : { gateReviewInstruction },
|
|
17569
17835
|
...options.roleTurnHost === void 0 ? {} : { roleTurnHost: options.roleTurnHost },
|
|
17570
17836
|
...options.hostAdapters === void 0 ? {} : { hostAdapters: options.hostAdapters },
|
|
17571
17837
|
...options.createRunId === void 0 ? {} : { createRunId: options.createRunId }
|
|
@@ -17639,11 +17905,18 @@ function projectOfficerDecision(officer, decision, fallbackStatus) {
|
|
|
17639
17905
|
}
|
|
17640
17906
|
return { status: "needs_reask", officer, receipt };
|
|
17641
17907
|
}
|
|
17642
|
-
function
|
|
17908
|
+
function thisCourtOfficerPayloads(terminal) {
|
|
17643
17909
|
const outcome = terminal?.roleOutcome;
|
|
17644
17910
|
if (outcome !== void 0 && (outcome.kind === "accepted" || outcome.kind === "audit_escalation")) {
|
|
17645
|
-
|
|
17911
|
+
if (outcome.payloads !== void 0 && outcome.payloads.length > 0) return outcome.payloads;
|
|
17912
|
+
}
|
|
17913
|
+
if (outcome?.kind === "failure" && outcome.payloads !== void 0 && outcome.payloads.length > 0) {
|
|
17914
|
+
return outcome.payloads;
|
|
17646
17915
|
}
|
|
17916
|
+
return [];
|
|
17917
|
+
}
|
|
17918
|
+
function officerFailurePayloads(terminal) {
|
|
17919
|
+
const outcome = terminal?.roleOutcome;
|
|
17647
17920
|
if (outcome?.kind === "failure") return outcome.payloads ?? terminal?.submissions ?? [];
|
|
17648
17921
|
return terminal?.submissions ?? [];
|
|
17649
17922
|
}
|
|
@@ -17651,24 +17924,20 @@ function projectOfficerPayloads(officer, payloads, fallbackStatus) {
|
|
|
17651
17924
|
if (payloads.length === 0) {
|
|
17652
17925
|
return projectOfficerDecision(officer, void 0, fallbackStatus);
|
|
17653
17926
|
}
|
|
17654
|
-
|
|
17655
|
-
if (payloads.length === 1) return queued;
|
|
17656
|
-
if (queued.status === "pass" || queued.status === "bounce" || queued.status === "escalate" || queued.status === "needs_reask") {
|
|
17657
|
-
return { ...queued, receipt: payloads };
|
|
17658
|
-
}
|
|
17659
|
-
return queued;
|
|
17927
|
+
return projectOfficerDecision(officer, payloads[payloads.length - 1], fallbackStatus);
|
|
17660
17928
|
}
|
|
17661
17929
|
function projectOfficerTerminal(officer, summoned) {
|
|
17662
17930
|
const terminal = summoned.terminal;
|
|
17663
17931
|
const outcome = terminal?.roleOutcome;
|
|
17664
|
-
const
|
|
17932
|
+
const thisCourt = thisCourtOfficerPayloads(terminal);
|
|
17665
17933
|
if (outcome === void 0) {
|
|
17666
17934
|
const detail = summoned.stderr ?? "";
|
|
17935
|
+
const failurePayloads = officerFailurePayloads(terminal);
|
|
17667
17936
|
return {
|
|
17668
17937
|
status: "transport_failure",
|
|
17669
17938
|
stage: officer,
|
|
17670
17939
|
reason: detail.length > 0 ? `${gateSeatLabel(officer)} public summon exit ${summoned.exitCode}: ${detail}` : `${gateSeatLabel(officer)} public summon produced no terminal (exit ${summoned.exitCode})`,
|
|
17671
|
-
submission:
|
|
17940
|
+
submission: failurePayloads.length > 0 ? failurePayloads : summoned
|
|
17672
17941
|
};
|
|
17673
17942
|
}
|
|
17674
17943
|
if (outcome.kind === "no_receipt") {
|
|
@@ -17680,27 +17949,30 @@ function projectOfficerTerminal(officer, summoned) {
|
|
|
17680
17949
|
};
|
|
17681
17950
|
}
|
|
17682
17951
|
if (outcome.kind === "failure") {
|
|
17952
|
+
const failurePayloads = officerFailurePayloads(terminal);
|
|
17683
17953
|
return {
|
|
17684
17954
|
status: "transport_failure",
|
|
17685
17955
|
stage: officer,
|
|
17686
17956
|
reason: outcome.diagnostic,
|
|
17687
|
-
submission:
|
|
17957
|
+
submission: failurePayloads.length > 0 ? failurePayloads : outcome.decisiveFacts
|
|
17688
17958
|
};
|
|
17689
17959
|
}
|
|
17690
17960
|
if (outcome.kind === "audit_escalation") {
|
|
17691
17961
|
return {
|
|
17692
17962
|
status: "escalate",
|
|
17693
17963
|
officer,
|
|
17694
|
-
receipt
|
|
17964
|
+
// This-court receipt only (#879) — historical rows remain on terminal.submissions.
|
|
17965
|
+
receipt: thisCourt.length > 0 ? thisCourt[thisCourt.length - 1] : retainedReceipt(outcome)
|
|
17695
17966
|
};
|
|
17696
17967
|
}
|
|
17697
17968
|
if (outcome.kind === "accepted") {
|
|
17698
|
-
return projectOfficerPayloads(officer,
|
|
17969
|
+
return projectOfficerPayloads(officer, thisCourt, outcome.status);
|
|
17699
17970
|
}
|
|
17700
17971
|
return {
|
|
17701
17972
|
status: "needs_reask",
|
|
17702
17973
|
officer,
|
|
17703
|
-
|
|
17974
|
+
// This-court receipt only (#879).
|
|
17975
|
+
receipt: thisCourt.length > 0 ? thisCourt[thisCourt.length - 1] : retainedReceipt(outcome)
|
|
17704
17976
|
};
|
|
17705
17977
|
}
|
|
17706
17978
|
async function projectGatekeeperRun(options) {
|
|
@@ -17718,7 +17990,7 @@ async function projectGatekeeperRun(options) {
|
|
|
17718
17990
|
}
|
|
17719
17991
|
let summoned;
|
|
17720
17992
|
try {
|
|
17721
|
-
const summon = options.summonOfficer ?? (async (nextOfficer, sourceRunDirectory, officerSignal, reask) => {
|
|
17993
|
+
const summon = options.summonOfficer ?? (async (nextOfficer, sourceRunDirectory, officerSignal, reask, nextSubmission) => {
|
|
17722
17994
|
const { summonGateOfficer: summonGateOfficer2 } = await Promise.resolve().then(() => (init_public_role_summons(), public_role_summons_exports));
|
|
17723
17995
|
return summonGateOfficer2({
|
|
17724
17996
|
officer: nextOfficer,
|
|
@@ -17726,6 +17998,7 @@ async function projectGatekeeperRun(options) {
|
|
|
17726
17998
|
cwd: options.context.cwd ?? process.cwd(),
|
|
17727
17999
|
...officerSignal === void 0 ? {} : { signal: officerSignal },
|
|
17728
18000
|
...reask === void 0 ? {} : { reask },
|
|
18001
|
+
...nextSubmission === void 0 ? {} : { submission: nextSubmission },
|
|
17729
18002
|
...options.home === void 0 ? {} : { home: options.home },
|
|
17730
18003
|
...options.packageRoot === void 0 ? {} : { packageRoot: options.packageRoot },
|
|
17731
18004
|
...options.roleTurnHost === void 0 ? {} : { roleTurnHost: options.roleTurnHost },
|
|
@@ -17736,7 +18009,8 @@ async function projectGatekeeperRun(options) {
|
|
|
17736
18009
|
officer,
|
|
17737
18010
|
runDirectory,
|
|
17738
18011
|
options.signal,
|
|
17739
|
-
options.reask
|
|
18012
|
+
options.reask,
|
|
18013
|
+
options.submission
|
|
17740
18014
|
);
|
|
17741
18015
|
} catch (error) {
|
|
17742
18016
|
return {
|
|
@@ -17776,9 +18050,9 @@ import { randomUUID as randomUUID8 } from "node:crypto";
|
|
|
17776
18050
|
// src/role-envelope.ts
|
|
17777
18051
|
init_engine_detour();
|
|
17778
18052
|
import { randomUUID as randomUUID7 } from "node:crypto";
|
|
17779
|
-
import { mkdir as mkdir6, readFile as
|
|
18053
|
+
import { mkdir as mkdir6, readFile as readFile20, writeFile as writeFile11 } from "node:fs/promises";
|
|
17780
18054
|
import { createServer } from "node:net";
|
|
17781
|
-
import { basename as basename8, dirname as dirname18, join as
|
|
18055
|
+
import { basename as basename8, dirname as dirname18, join as join37 } from "node:path";
|
|
17782
18056
|
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
17783
18057
|
|
|
17784
18058
|
// src/gatekeeper-pass-envelope.ts
|
|
@@ -17810,6 +18084,7 @@ async function requireGatekeeperPass(options) {
|
|
|
17810
18084
|
subject: options.subject,
|
|
17811
18085
|
...options.signal === void 0 ? {} : { signal: options.signal },
|
|
17812
18086
|
...options.summonOfficer === void 0 ? {} : { summonOfficer: options.summonOfficer },
|
|
18087
|
+
...options.submission === void 0 ? {} : { submission: options.submission },
|
|
17813
18088
|
...reask === void 0 ? {} : { reask }
|
|
17814
18089
|
});
|
|
17815
18090
|
const gatekeeper = projected.result;
|
|
@@ -17852,7 +18127,7 @@ init_sitian_facade();
|
|
|
17852
18127
|
init_submission_ledger();
|
|
17853
18128
|
init_collector_ledger();
|
|
17854
18129
|
import { readFileSync as readFileSync5, writeSync as writeSync4 } from "node:fs";
|
|
17855
|
-
import { join as
|
|
18130
|
+
import { join as join36 } from "node:path";
|
|
17856
18131
|
import { Value as Value4 } from "typebox/value";
|
|
17857
18132
|
|
|
17858
18133
|
// src/activation-trace.ts
|
|
@@ -18261,6 +18536,7 @@ function createToolExecutionObservationFace(options) {
|
|
|
18261
18536
|
|
|
18262
18537
|
// src/role-runtime.ts
|
|
18263
18538
|
init_engine_detour();
|
|
18539
|
+
init_engine_material();
|
|
18264
18540
|
|
|
18265
18541
|
// src/engine-detour-tool.ts
|
|
18266
18542
|
init_engine_detour();
|
|
@@ -18358,21 +18634,21 @@ init_collector_evidence();
|
|
|
18358
18634
|
init_collector_github();
|
|
18359
18635
|
|
|
18360
18636
|
// src/collector-handbook.ts
|
|
18361
|
-
import { readFile as
|
|
18362
|
-
import { join as
|
|
18637
|
+
import { readFile as readFile19 } from "node:fs/promises";
|
|
18638
|
+
import { join as join34, sep as sep4 } from "node:path";
|
|
18363
18639
|
|
|
18364
18640
|
// src/atomic-write.ts
|
|
18365
18641
|
import { randomUUID as randomUUID6 } from "node:crypto";
|
|
18366
|
-
import { rename as rename2, rm as
|
|
18367
|
-
import { dirname as dirname16, join as
|
|
18642
|
+
import { rename as rename2, rm as rm3, writeFile as writeFile10 } from "node:fs/promises";
|
|
18643
|
+
import { dirname as dirname16, join as join33 } from "node:path";
|
|
18368
18644
|
async function writeFileAtomically(destination, contents) {
|
|
18369
18645
|
const parent = dirname16(destination);
|
|
18370
|
-
const temporary =
|
|
18646
|
+
const temporary = join33(parent, `.atomic-write-${randomUUID6()}.tmp`);
|
|
18371
18647
|
try {
|
|
18372
|
-
await
|
|
18648
|
+
await writeFile10(temporary, contents);
|
|
18373
18649
|
await rename2(temporary, destination);
|
|
18374
18650
|
} catch (error) {
|
|
18375
|
-
await
|
|
18651
|
+
await rm3(temporary, { force: true }).catch(() => void 0);
|
|
18376
18652
|
throw error;
|
|
18377
18653
|
}
|
|
18378
18654
|
}
|
|
@@ -18493,7 +18769,7 @@ function resolveCollectorHandbookRoot(sessionPath) {
|
|
|
18493
18769
|
throw new Error(`\u901A\u8FDB\u53F8\u624B\u518C\u62D2\u7EDD\u4E0D\u5B89\u5168 bookKey ${JSON.stringify(bookKey)}`);
|
|
18494
18770
|
}
|
|
18495
18771
|
const ledgerHome = resolveActivationLedgerHomeForPath(sessionPath);
|
|
18496
|
-
const root =
|
|
18772
|
+
const root = join34(activationBookDirectory(ledgerHome, bookKey), "collector-handbook");
|
|
18497
18773
|
return { ledgerHome, bookKey, root };
|
|
18498
18774
|
}
|
|
18499
18775
|
function collectorHandbookRepoFileName(repositoryCanonical) {
|
|
@@ -18505,9 +18781,9 @@ function collectorHandbookRepoFileName(repositoryCanonical) {
|
|
|
18505
18781
|
return `${repositoryCanonical.replaceAll("/", "__")}.md`;
|
|
18506
18782
|
}
|
|
18507
18783
|
function createCollectorHandbookStore(input) {
|
|
18508
|
-
const generalPath =
|
|
18509
|
-
const repoDir =
|
|
18510
|
-
const repoPath =
|
|
18784
|
+
const generalPath = join34(input.handbookRoot, "general.md");
|
|
18785
|
+
const repoDir = join34(input.handbookRoot, "repos");
|
|
18786
|
+
const repoPath = join34(repoDir, collectorHandbookRepoFileName(input.repositoryCanonical));
|
|
18511
18787
|
const assertHandbookBudget = (body, label) => {
|
|
18512
18788
|
const byteLength = Buffer.byteLength(body, "utf8");
|
|
18513
18789
|
if (byteLength > COLLECTOR_HANDBOOK_MAX_BYTES) {
|
|
@@ -18521,7 +18797,7 @@ function createCollectorHandbookStore(input) {
|
|
|
18521
18797
|
ensureRealDirectoryTree(input.ledgerHome, parentDir2);
|
|
18522
18798
|
assertLedgerFileInsideHome(path, input.ledgerHome);
|
|
18523
18799
|
try {
|
|
18524
|
-
const body = await
|
|
18800
|
+
const body = await readFile19(path, "utf8");
|
|
18525
18801
|
assertHandbookBudget(body, "\u6B63\u6587");
|
|
18526
18802
|
return body;
|
|
18527
18803
|
} catch (error) {
|
|
@@ -19653,6 +19929,24 @@ function navigatorProviderFailureFromDiagnostics(diagnostics) {
|
|
|
19653
19929
|
}
|
|
19654
19930
|
return void 0;
|
|
19655
19931
|
}
|
|
19932
|
+
function navigatorProviderFailureFromPublicTerminal(outcome) {
|
|
19933
|
+
const facts = outcome.decisiveFacts;
|
|
19934
|
+
const secondary = typeof facts.secondaryEvidence === "object" && facts.secondaryEvidence !== null ? facts.secondaryEvidence : void 0;
|
|
19935
|
+
const httpStatus = typeof secondary?.httpStatus === "number" ? secondary.httpStatus : typeof facts.httpStatus === "number" ? facts.httpStatus : typeof facts.errorCode === "number" ? facts.errorCode : void 0;
|
|
19936
|
+
const fromStatus = navigatorProviderFailureFromStatus(httpStatus);
|
|
19937
|
+
if (fromStatus !== void 0) return fromStatus;
|
|
19938
|
+
const diagnostics = secondary?.diagnostics ?? facts.diagnostics;
|
|
19939
|
+
const fromDiagnostics = navigatorProviderFailureFromDiagnostics(diagnostics);
|
|
19940
|
+
if (fromDiagnostics !== void 0) return fromDiagnostics;
|
|
19941
|
+
const fromCode = navigatorProviderFailureFromError({
|
|
19942
|
+
code: secondary?.code ?? facts.errorCode
|
|
19943
|
+
});
|
|
19944
|
+
if (fromCode !== void 0) return fromCode;
|
|
19945
|
+
if (outcome.cause === "provider") return { source: "transport", cause: "unknown" };
|
|
19946
|
+
const typed = navigatorUnavailableKey(outcome.cause);
|
|
19947
|
+
if (typed !== void 0) return { source: typed, cause: typed };
|
|
19948
|
+
return { source: "unknown", cause: "unknown" };
|
|
19949
|
+
}
|
|
19656
19950
|
var navigatorProviderFailureSchema = Type20.Object({
|
|
19657
19951
|
source: Type20.Union([
|
|
19658
19952
|
Type20.Literal("context"),
|
|
@@ -19734,23 +20028,6 @@ async function resolveNavigatorSeatSelection(context) {
|
|
|
19734
20028
|
}
|
|
19735
20029
|
|
|
19736
20030
|
// src/navigator-public-session.ts
|
|
19737
|
-
init_terminal();
|
|
19738
|
-
function providerFailureFromPublicTerminal(outcome) {
|
|
19739
|
-
const facts = outcome.decisiveFacts;
|
|
19740
|
-
const secondary = typeof facts.secondaryEvidence === "object" && facts.secondaryEvidence !== null ? facts.secondaryEvidence : void 0;
|
|
19741
|
-
const httpStatus = typeof secondary?.httpStatus === "number" ? secondary.httpStatus : typeof facts.httpStatus === "number" ? facts.httpStatus : typeof facts.errorCode === "number" ? facts.errorCode : void 0;
|
|
19742
|
-
const fromStatus = navigatorProviderFailureFromStatus(httpStatus);
|
|
19743
|
-
if (fromStatus !== void 0) return fromStatus;
|
|
19744
|
-
const diagnostics = secondary?.diagnostics ?? facts.diagnostics;
|
|
19745
|
-
const fromDiagnostics = navigatorProviderFailureFromDiagnostics(diagnostics);
|
|
19746
|
-
if (fromDiagnostics !== void 0) return fromDiagnostics;
|
|
19747
|
-
const fromCode = navigatorProviderFailureFromError({
|
|
19748
|
-
code: secondary?.code ?? facts.errorCode
|
|
19749
|
-
});
|
|
19750
|
-
if (fromCode !== void 0) return fromCode;
|
|
19751
|
-
if (outcome.cause === "provider") return { source: "transport", cause: "transport" };
|
|
19752
|
-
return { source: "session", cause: "session" };
|
|
19753
|
-
}
|
|
19754
20031
|
function createNativeNavigatorSessionFactory() {
|
|
19755
20032
|
return async ({ context, subject, tool }) => {
|
|
19756
20033
|
const resolved = await resolveNavigatorSeatSelection(context);
|
|
@@ -19806,14 +20083,15 @@ function createNativeNavigatorSessionFactory() {
|
|
|
19806
20083
|
const outcome = summoned.terminal?.roleOutcome;
|
|
19807
20084
|
if (outcome === void 0) {
|
|
19808
20085
|
const detail = summoned.stderr?.trim() || `exit ${summoned.exitCode}`;
|
|
19809
|
-
providerFailure = { source: "transport", cause: "
|
|
20086
|
+
providerFailure = { source: "transport", cause: "unknown" };
|
|
19810
20087
|
throw navigatorUnavailableError(
|
|
19811
|
-
|
|
19812
|
-
new Error(`Navigator public summon produced no terminal (${detail})`)
|
|
20088
|
+
providerFailure.source,
|
|
20089
|
+
new Error(`Navigator public summon produced no terminal (${detail})`),
|
|
20090
|
+
providerFailure.cause
|
|
19813
20091
|
);
|
|
19814
20092
|
}
|
|
19815
20093
|
if (outcome.kind === "failure") {
|
|
19816
|
-
providerFailure =
|
|
20094
|
+
providerFailure = navigatorProviderFailureFromPublicTerminal(outcome);
|
|
19817
20095
|
throw navigatorUnavailableError(
|
|
19818
20096
|
providerFailure.source,
|
|
19819
20097
|
new Error(outcome.diagnostic),
|
|
@@ -19827,21 +20105,22 @@ function createNativeNavigatorSessionFactory() {
|
|
|
19827
20105
|
if (outcome.kind !== "accepted") {
|
|
19828
20106
|
return;
|
|
19829
20107
|
}
|
|
19830
|
-
const
|
|
19831
|
-
|
|
19832
|
-
|
|
20108
|
+
for (const payload of outcome.payloads ?? []) {
|
|
20109
|
+
if (typeof payload !== "object" || payload === null || Array.isArray(payload)) continue;
|
|
20110
|
+
const candidates = payload.candidates;
|
|
20111
|
+
if (!Array.isArray(candidates)) continue;
|
|
20112
|
+
await tool.execute(
|
|
20113
|
+
"navigator-public-prepare",
|
|
20114
|
+
{ candidates },
|
|
20115
|
+
void 0,
|
|
20116
|
+
void 0,
|
|
20117
|
+
context
|
|
20118
|
+
);
|
|
19833
20119
|
}
|
|
19834
|
-
await tool.execute(
|
|
19835
|
-
"navigator-public-prepare",
|
|
19836
|
-
{ candidates },
|
|
19837
|
-
void 0,
|
|
19838
|
-
void 0,
|
|
19839
|
-
context
|
|
19840
|
-
);
|
|
19841
20120
|
} catch (error) {
|
|
19842
20121
|
if (error instanceof NavigatorUnavailableError) throw error;
|
|
19843
20122
|
const fact = navigatorProviderFailureFromError(error);
|
|
19844
|
-
providerFailure = fact ?? { source: "transport", cause: "
|
|
20123
|
+
providerFailure = fact ?? { source: "transport", cause: "unknown" };
|
|
19845
20124
|
throw navigatorUnavailableError(providerFailure.source, error, providerFailure.cause);
|
|
19846
20125
|
}
|
|
19847
20126
|
})();
|
|
@@ -20606,14 +20885,18 @@ function createJudgeRoleRuntime(pi, dependencies, hostActions) {
|
|
|
20606
20885
|
subject: { kind: "judge_draft" },
|
|
20607
20886
|
...signal === void 0 ? {} : { signal },
|
|
20608
20887
|
hostActions,
|
|
20609
|
-
toolCallId
|
|
20888
|
+
toolCallId,
|
|
20889
|
+
// #879: this-turn typed payload — identity-bound at submit site.
|
|
20890
|
+
submission: parameters
|
|
20610
20891
|
});
|
|
20611
20892
|
await pi.requireGatekeeperPass({
|
|
20612
20893
|
context: ctx,
|
|
20613
20894
|
subject: { kind: "judge_compliance" },
|
|
20614
20895
|
...signal === void 0 ? {} : { signal },
|
|
20615
20896
|
hostActions,
|
|
20616
|
-
toolCallId
|
|
20897
|
+
toolCallId,
|
|
20898
|
+
// #879: same parent payload for 审刑院; not recovered from session latest.
|
|
20899
|
+
submission: parameters
|
|
20617
20900
|
});
|
|
20618
20901
|
return {
|
|
20619
20902
|
content: [{ type: "text", text: JUDGE_ACCEPTED_TEXT }],
|
|
@@ -21124,7 +21407,9 @@ function createFixerRoleRuntime(pi, dependencies, hostActions) {
|
|
|
21124
21407
|
subject: { kind: "worker_completion" },
|
|
21125
21408
|
..._signal === void 0 ? {} : { signal: _signal },
|
|
21126
21409
|
hostActions,
|
|
21127
|
-
toolCallId
|
|
21410
|
+
toolCallId,
|
|
21411
|
+
// #879: this-turn typed payload — identity-bound at submit site.
|
|
21412
|
+
submission: output
|
|
21128
21413
|
});
|
|
21129
21414
|
}
|
|
21130
21415
|
const acceptedDetails = output;
|
|
@@ -21260,7 +21545,9 @@ function createCoderRoleRuntime(pi, dependencies, hostActions) {
|
|
|
21260
21545
|
subject: { kind: "worker_completion" },
|
|
21261
21546
|
..._signal === void 0 ? {} : { signal: _signal },
|
|
21262
21547
|
hostActions,
|
|
21263
|
-
toolCallId
|
|
21548
|
+
toolCallId,
|
|
21549
|
+
// #879: this-turn typed payload — identity-bound at submit site.
|
|
21550
|
+
submission: output
|
|
21264
21551
|
});
|
|
21265
21552
|
}
|
|
21266
21553
|
const acceptedDetails = output;
|
|
@@ -21795,12 +22082,12 @@ function readDiaristTicketAssertion(submitted) {
|
|
|
21795
22082
|
}
|
|
21796
22083
|
return { kind: "invalid" };
|
|
21797
22084
|
}
|
|
21798
|
-
function readDiaristRunCoordinates() {
|
|
21799
|
-
const runDirectory =
|
|
21800
|
-
if (
|
|
22085
|
+
function readDiaristRunCoordinates(ctx) {
|
|
22086
|
+
const runDirectory = runDirectoryFromHostContext(ctx);
|
|
22087
|
+
if (runDirectory === void 0) {
|
|
21801
22088
|
throw new Error("diarist accept requires AK_ROLE_RUN_DIR");
|
|
21802
22089
|
}
|
|
21803
|
-
const admittedPath =
|
|
22090
|
+
const admittedPath = join36(runDirectory, "admitted-request.json");
|
|
21804
22091
|
const admitted = JSON.parse(readFileSync5(admittedPath, "utf8"));
|
|
21805
22092
|
if (typeof admitted.projectRoot !== "string" || admitted.projectRoot.trim() === "") {
|
|
21806
22093
|
throw new Error(`diarist admitted-request missing projectRoot (${admittedPath})`);
|
|
@@ -21821,10 +22108,10 @@ function createDiaristRoleRuntime(roleHost, dependencies) {
|
|
|
21821
22108
|
tool: DIARIST_TOOL_SPEC,
|
|
21822
22109
|
acceptedText: DIARIST_ACCEPTED_TEXT,
|
|
21823
22110
|
soulTag: "diarist",
|
|
21824
|
-
beforeAccept: async ({ parameters }) => {
|
|
22111
|
+
beforeAccept: async ({ parameters, ctx }) => {
|
|
21825
22112
|
const submitted = parameters !== null && typeof parameters === "object" && !Array.isArray(parameters) ? parameters : void 0;
|
|
21826
22113
|
const assertion = readDiaristTicketAssertion(submitted);
|
|
21827
|
-
const coords = readDiaristRunCoordinates();
|
|
22114
|
+
const coords = readDiaristRunCoordinates(ctx);
|
|
21828
22115
|
const ticketNumber = assertion.kind === "ticket" ? assertion.ticketNumber : void 0;
|
|
21829
22116
|
if (ticketNumber !== void 0) {
|
|
21830
22117
|
if (coords.boundTicketNumber === void 0) {
|
|
@@ -21860,7 +22147,9 @@ function createCountersignRoleRuntime(roleHost, dependencies, hostActions) {
|
|
|
21860
22147
|
subject: { kind: "countersign_verdict" },
|
|
21861
22148
|
...signal === void 0 ? {} : { signal },
|
|
21862
22149
|
hostActions,
|
|
21863
|
-
toolCallId
|
|
22150
|
+
toolCallId,
|
|
22151
|
+
// #879: this-turn typed payload — identity-bound at submit site.
|
|
22152
|
+
submission: parameters
|
|
21864
22153
|
});
|
|
21865
22154
|
} : void 0;
|
|
21866
22155
|
return createFiledOfficerRuntime(
|
|
@@ -21893,6 +22182,10 @@ function createRoleRuntimeExtension(dependencies) {
|
|
|
21893
22182
|
for (const flag of NOTARY_TRANSPORT_FLAGS) {
|
|
21894
22183
|
roleHost.registerFlag(flag.name, flag.definition);
|
|
21895
22184
|
}
|
|
22185
|
+
roleHost.registerFlag(
|
|
22186
|
+
INSPECTOR_SOURCE_RUN_FLAG.name,
|
|
22187
|
+
INSPECTOR_SOURCE_RUN_FLAG.definition
|
|
22188
|
+
);
|
|
21896
22189
|
for (const flag of GLEANER_LEFT_TRANSPORT_FLAGS) {
|
|
21897
22190
|
roleHost.registerFlag(flag.name, flag.definition);
|
|
21898
22191
|
}
|
|
@@ -21900,6 +22193,11 @@ function createRoleRuntimeExtension(dependencies) {
|
|
|
21900
22193
|
roleHost.registerFlag(flag.name, flag.definition);
|
|
21901
22194
|
}
|
|
21902
22195
|
roleHost.registerFlag(STATION_CHILD_FLAG.name, STATION_CHILD_FLAG.definition);
|
|
22196
|
+
roleHost.registerFlag(ENGINE_MODEL_FLAG_NAME, {
|
|
22197
|
+
description: "\u672C\u6B21\u52B3\u52A1\u5F15\u64CE\u6A21\u578B",
|
|
22198
|
+
type: "string",
|
|
22199
|
+
default: ""
|
|
22200
|
+
});
|
|
21903
22201
|
let admitted = false;
|
|
21904
22202
|
let selectedRole;
|
|
21905
22203
|
let activeReviewerParent;
|
|
@@ -21984,19 +22282,21 @@ function createRoleRuntimeExtension(dependencies) {
|
|
|
21984
22282
|
settleNavigatorProjection
|
|
21985
22283
|
);
|
|
21986
22284
|
roleHost.on("input", (event) => {
|
|
22285
|
+
const text = event.text;
|
|
21987
22286
|
const role = roleHost.getFlag(ROLE_FLAG.name);
|
|
21988
22287
|
if (role !== void 0 && !admitted) return { action: "handled" };
|
|
21989
22288
|
if (role === "reviewer" && admitted && activeReviewerParent !== void 0 && reviewerOriginalRequest === void 0) {
|
|
21990
22289
|
reviewerOriginalRequest = roleHost.capabilities?.skillOriginalRequest?.(
|
|
21991
22290
|
activeReviewerParent.skillBinding.name,
|
|
21992
|
-
|
|
21993
|
-
) ??
|
|
21994
|
-
return { action: "continue" };
|
|
22291
|
+
text
|
|
22292
|
+
) ?? text;
|
|
22293
|
+
return text === event.text ? { action: "continue" } : { action: "transform", text };
|
|
21995
22294
|
}
|
|
21996
|
-
return { action: "continue" };
|
|
22295
|
+
return text === event.text ? { action: "continue" } : { action: "transform", text };
|
|
21997
22296
|
});
|
|
21998
22297
|
roleHost.on("before_agent_start", async (event, ctx) => {
|
|
21999
22298
|
const role = roleHost.getFlag(ROLE_FLAG.name);
|
|
22299
|
+
const prompt = event.prompt;
|
|
22000
22300
|
if (role === void 0) return;
|
|
22001
22301
|
if (!admitted || selectedRole !== role) {
|
|
22002
22302
|
failInfrastructure(new ActivationBarrierError(role), ctx);
|
|
@@ -22009,7 +22309,7 @@ function createRoleRuntimeExtension(dependencies) {
|
|
|
22009
22309
|
}
|
|
22010
22310
|
if (navigatorAttendance !== void 0 && navigatorWorkContext !== void 0 && navigatorWorkContext.contextError === void 0) {
|
|
22011
22311
|
if (navigatorWorkContext.subjectProvenance === "placeholder") {
|
|
22012
|
-
const subject =
|
|
22312
|
+
const subject = prompt.trim();
|
|
22013
22313
|
if (subject !== "") {
|
|
22014
22314
|
const root = subjectPath(ctx.sessionManager.getSessionDir(), ctx.cwd);
|
|
22015
22315
|
const subjectProvenance = "user_prompt";
|
|
@@ -22030,7 +22330,7 @@ function createRoleRuntimeExtension(dependencies) {
|
|
|
22030
22330
|
if (!reviewerExpansionCaptured) {
|
|
22031
22331
|
if (reviewerOriginalRequest !== void 0) {
|
|
22032
22332
|
activeReviewerParent.skillBinding.captureExpansion(
|
|
22033
|
-
roleHost.capabilities?.skillExpansion(
|
|
22333
|
+
roleHost.capabilities?.skillExpansion(prompt),
|
|
22034
22334
|
reviewerOriginalRequest
|
|
22035
22335
|
);
|
|
22036
22336
|
}
|
|
@@ -22053,6 +22353,46 @@ function createRoleRuntimeExtension(dependencies) {
|
|
|
22053
22353
|
};
|
|
22054
22354
|
}
|
|
22055
22355
|
});
|
|
22356
|
+
roleHost.on("before_agent_start", () => {
|
|
22357
|
+
const role = selectedRole ?? roleHost.getFlag(ROLE_FLAG.name);
|
|
22358
|
+
if (typeof role !== "string" || !isOfficerReviewSeat(role)) return;
|
|
22359
|
+
if (roleHost.getFlag(STATION_CHILD_FLAG.name) !== true) return;
|
|
22360
|
+
const engine = resolveEngineName((name) => roleHost.getFlag(name));
|
|
22361
|
+
if (engine === void 0 || dependencies.packageRoot === void 0) return;
|
|
22362
|
+
const engineModel = resolveEngineModel((name) => roleHost.getFlag(name));
|
|
22363
|
+
const material = engineSessionMaterialFromOptions({
|
|
22364
|
+
engine,
|
|
22365
|
+
...engineModel === void 0 ? {} : { engineModel },
|
|
22366
|
+
packageRoot: dependencies.packageRoot
|
|
22367
|
+
});
|
|
22368
|
+
if (material === void 0) return;
|
|
22369
|
+
return {
|
|
22370
|
+
readingMaterial: {
|
|
22371
|
+
kind: "engine-session-material",
|
|
22372
|
+
name: material.name,
|
|
22373
|
+
...material.model === void 0 ? {} : { model: material.model },
|
|
22374
|
+
...material.materialPath === void 0 ? {} : { materialPath: material.materialPath }
|
|
22375
|
+
}
|
|
22376
|
+
};
|
|
22377
|
+
});
|
|
22378
|
+
roleHost.on("before_agent_start", () => {
|
|
22379
|
+
const path = roleHost.getFlag(INSPECTOR_SOURCE_RUN_FLAG.name);
|
|
22380
|
+
if (typeof path !== "string" || path.trim() === "") return;
|
|
22381
|
+
return {
|
|
22382
|
+
readingMaterial: {
|
|
22383
|
+
kind: "inspector-parent-binding",
|
|
22384
|
+
sourceRunPath: path
|
|
22385
|
+
}
|
|
22386
|
+
};
|
|
22387
|
+
});
|
|
22388
|
+
roleHost.on("before_agent_start", async (_event, ctx) => {
|
|
22389
|
+
const runDir = runDirectoryFromHostContext(ctx);
|
|
22390
|
+
if (runDir === void 0) return;
|
|
22391
|
+
const { loadCaseDossierReadingMaterial: loadCaseDossierReadingMaterial2 } = await Promise.resolve().then(() => (init_case_dossier_delivery(), case_dossier_delivery_exports));
|
|
22392
|
+
const caseDossier = await loadCaseDossierReadingMaterial2(runDir);
|
|
22393
|
+
if (caseDossier === void 0) return;
|
|
22394
|
+
return { readingMaterial: caseDossier };
|
|
22395
|
+
});
|
|
22056
22396
|
roleHost.on("tool_result", async (event) => {
|
|
22057
22397
|
const role = selectedRole;
|
|
22058
22398
|
if (role === void 0) return;
|
|
@@ -22113,7 +22453,7 @@ function createRoleRuntimeExtension(dependencies) {
|
|
|
22113
22453
|
display: false
|
|
22114
22454
|
}, { triggerTurn: true, deliverAs: "followUp" });
|
|
22115
22455
|
} else if (receiptDelivery.nextAction() === "no-receipt" && !noReceiptRecorded) {
|
|
22116
|
-
const runPointer =
|
|
22456
|
+
const runPointer = runDirectoryFromHostContext(ctx);
|
|
22117
22457
|
if (runPointer !== void 0) {
|
|
22118
22458
|
noReceiptRecorded = true;
|
|
22119
22459
|
const facts = receiptDelivery.facts({ runPointer, attemptPointer: `current:${runPointer}` });
|
|
@@ -22475,8 +22815,8 @@ function createRoleRuntimeExtension(dependencies) {
|
|
|
22475
22815
|
await observe(() => observationFace.onEnd(event), ctx);
|
|
22476
22816
|
});
|
|
22477
22817
|
const recordHttpObservation = async (status, provider, ctx) => {
|
|
22478
|
-
const runDir =
|
|
22479
|
-
if (
|
|
22818
|
+
const runDir = runDirectoryFromHostContext(ctx);
|
|
22819
|
+
if (runDir === void 0) return;
|
|
22480
22820
|
try {
|
|
22481
22821
|
await recordTypedProviderHttpStatus(runDir, { httpStatus: status, provider });
|
|
22482
22822
|
} catch (error) {
|
|
@@ -22499,8 +22839,8 @@ function createRoleRuntimeExtension(dependencies) {
|
|
|
22499
22839
|
const underlying = priorFetch;
|
|
22500
22840
|
globalThis.fetch = (async (input, init) => {
|
|
22501
22841
|
const response = await underlying(input, init);
|
|
22502
|
-
const runDir =
|
|
22503
|
-
if (
|
|
22842
|
+
const runDir = runDirectoryFromHostContext(ctx);
|
|
22843
|
+
if (runDir !== void 0 && typeof response?.status === "number" && (response.status < 200 || response.status >= 300)) {
|
|
22504
22844
|
const provider = typeof ctx.model?.provider === "string" && ctx.model.provider.trim() !== "" ? ctx.model.provider : "unknown";
|
|
22505
22845
|
try {
|
|
22506
22846
|
await recordTypedProviderHttpStatus(runDir, {
|
|
@@ -22733,14 +23073,14 @@ async function prepareRoleEnvelope(options) {
|
|
|
22733
23073
|
for (const method of request.methods) {
|
|
22734
23074
|
if (method.kind !== "skill") continue;
|
|
22735
23075
|
const name = basename8(dirname18(method.path));
|
|
22736
|
-
const raw = await
|
|
23076
|
+
const raw = await readFile20(method.path, "utf8");
|
|
22737
23077
|
methodSkills.set(name, { path: method.path, body: stripSkillFrontmatter(raw).trim() });
|
|
22738
23078
|
}
|
|
22739
|
-
let sessionFile = options.sessionFile ??
|
|
23079
|
+
let sessionFile = options.sessionFile ?? join37(request.runDirectory, "session", "session.jsonl");
|
|
22740
23080
|
await mkdir6(dirname18(sessionFile), { recursive: true });
|
|
22741
23081
|
if (request.continuation.kind !== "resume") {
|
|
22742
23082
|
try {
|
|
22743
|
-
await
|
|
23083
|
+
await writeFile11(
|
|
22744
23084
|
sessionFile,
|
|
22745
23085
|
`${JSON.stringify({
|
|
22746
23086
|
type: "session",
|
|
@@ -22760,6 +23100,8 @@ async function prepareRoleEnvelope(options) {
|
|
|
22760
23100
|
cwd: request.cwd,
|
|
22761
23101
|
mode: "print",
|
|
22762
23102
|
model: request.model === void 0 ? void 0 : { provider: request.model.provider },
|
|
23103
|
+
runDirectory: request.runDirectory,
|
|
23104
|
+
...request.courtAttemptId === void 0 ? {} : { courtAttemptId: request.courtAttemptId },
|
|
22763
23105
|
sessionManager: {
|
|
22764
23106
|
getLeafEntry: () => sessionEntries.at(-1),
|
|
22765
23107
|
getLeafId: () => runId,
|
|
@@ -22834,7 +23176,8 @@ async function prepareRoleEnvelope(options) {
|
|
|
22834
23176
|
failInfrastructure: (error, _context, toolCallId) => options2.hostActions.failInfrastructure(error, options2.context, toolCallId),
|
|
22835
23177
|
bindSubmissionNonPass: options2.hostActions.bindSubmissionNonPass
|
|
22836
23178
|
},
|
|
22837
|
-
toolCallId: options2.toolCallId
|
|
23179
|
+
toolCallId: options2.toolCallId,
|
|
23180
|
+
...options2.submission === void 0 ? {} : { submission: options2.submission }
|
|
22838
23181
|
});
|
|
22839
23182
|
},
|
|
22840
23183
|
on(...registration) {
|
|
@@ -23061,17 +23404,6 @@ async function prepareRoleEnvelope(options) {
|
|
|
23061
23404
|
const relay = fileURLToPath2(new URL("./mcp-relay.mjs", import.meta.url));
|
|
23062
23405
|
await listen(server, options.socketPath);
|
|
23063
23406
|
let disposed = false;
|
|
23064
|
-
let priorAkRoleRunDir;
|
|
23065
|
-
let priorAkRoleCourtAttempt;
|
|
23066
|
-
let runDirInjected = false;
|
|
23067
|
-
const restoreAkRoleRunEnv = () => {
|
|
23068
|
-
if (!runDirInjected) return;
|
|
23069
|
-
runDirInjected = false;
|
|
23070
|
-
if (priorAkRoleRunDir === void 0) delete process.env.AK_ROLE_RUN_DIR;
|
|
23071
|
-
else process.env.AK_ROLE_RUN_DIR = priorAkRoleRunDir;
|
|
23072
|
-
if (priorAkRoleCourtAttempt === void 0) delete process.env.AK_ROLE_COURT_ATTEMPT;
|
|
23073
|
-
else process.env.AK_ROLE_COURT_ATTEMPT = priorAkRoleCourtAttempt;
|
|
23074
|
-
};
|
|
23075
23407
|
const dispose = async () => {
|
|
23076
23408
|
if (disposed) return;
|
|
23077
23409
|
disposed = true;
|
|
@@ -23081,11 +23413,6 @@ async function prepareRoleEnvelope(options) {
|
|
|
23081
23413
|
} catch (error) {
|
|
23082
23414
|
cleanupFailures.push(error);
|
|
23083
23415
|
}
|
|
23084
|
-
try {
|
|
23085
|
-
restoreAkRoleRunEnv();
|
|
23086
|
-
} catch (error) {
|
|
23087
|
-
cleanupFailures.push(error);
|
|
23088
|
-
}
|
|
23089
23416
|
try {
|
|
23090
23417
|
const closeAll = server.closeAllConnections;
|
|
23091
23418
|
if (typeof closeAll === "function") closeAll.call(server);
|
|
@@ -23154,7 +23481,7 @@ async function prepareRoleEnvelope(options) {
|
|
|
23154
23481
|
message: { role: "user", content: prompt }
|
|
23155
23482
|
});
|
|
23156
23483
|
}
|
|
23157
|
-
const methodPrompt = (await Promise.all(request.methods.map(({ path }) =>
|
|
23484
|
+
const methodPrompt = (await Promise.all(request.methods.map(({ path }) => readFile20(path, "utf8")))).join("\n\n");
|
|
23158
23485
|
const promptResults = await emit("before_agent_start", {
|
|
23159
23486
|
prompt,
|
|
23160
23487
|
systemPrompt: methodPrompt,
|
|
@@ -23173,12 +23500,6 @@ async function prepareRoleEnvelope(options) {
|
|
|
23173
23500
|
const material = value.readingMaterial;
|
|
23174
23501
|
if (material !== void 0) readingMaterials.push(material);
|
|
23175
23502
|
}
|
|
23176
|
-
priorAkRoleRunDir = process.env.AK_ROLE_RUN_DIR;
|
|
23177
|
-
priorAkRoleCourtAttempt = process.env.AK_ROLE_COURT_ATTEMPT;
|
|
23178
|
-
process.env.AK_ROLE_RUN_DIR = request.runDirectory;
|
|
23179
|
-
if (request.courtAttemptId === void 0) delete process.env.AK_ROLE_COURT_ATTEMPT;
|
|
23180
|
-
else process.env.AK_ROLE_COURT_ATTEMPT = request.courtAttemptId;
|
|
23181
|
-
runDirInjected = true;
|
|
23182
23503
|
const terminating = tools.get(terminatingToolName);
|
|
23183
23504
|
if (terminating === void 0) {
|
|
23184
23505
|
throw new Error(`terminating tool not registered after activation: ${terminatingToolName}`);
|
|
@@ -23218,11 +23539,11 @@ async function prepareRoleEnvelope(options) {
|
|
|
23218
23539
|
}
|
|
23219
23540
|
|
|
23220
23541
|
// src/role-runtime-dependencies.ts
|
|
23221
|
-
import { readFile as
|
|
23542
|
+
import { readFile as readFile23 } from "node:fs/promises";
|
|
23222
23543
|
import { fileURLToPath as fileURLToPath3 } from "node:url";
|
|
23223
23544
|
|
|
23224
23545
|
// src/canonical-skill-binding.ts
|
|
23225
|
-
import { readFile as
|
|
23546
|
+
import { readFile as readFile21, realpath as realpath7 } from "node:fs/promises";
|
|
23226
23547
|
import { homedir } from "node:os";
|
|
23227
23548
|
import { dirname as dirname19, resolve as resolve18 } from "node:path";
|
|
23228
23549
|
import { stripFrontmatter } from "@earendil-works/pi-coding-agent";
|
|
@@ -23255,7 +23576,7 @@ async function loadCanonicalSkillBinding(name) {
|
|
|
23255
23576
|
let raw;
|
|
23256
23577
|
try {
|
|
23257
23578
|
path = await realpath7(configuredPath);
|
|
23258
|
-
raw = await
|
|
23579
|
+
raw = await readFile21(path, "utf8");
|
|
23259
23580
|
} catch (error) {
|
|
23260
23581
|
throw new CanonicalSkillUnavailableError(name, configuredPath, error);
|
|
23261
23582
|
}
|
|
@@ -23293,7 +23614,8 @@ init_doctor_evidence();
|
|
|
23293
23614
|
|
|
23294
23615
|
// src/navigator-work-context.ts
|
|
23295
23616
|
init_doctor_evidence();
|
|
23296
|
-
|
|
23617
|
+
init_host_contracts();
|
|
23618
|
+
import { readFile as readFile22 } from "node:fs/promises";
|
|
23297
23619
|
import { resolve as resolve19 } from "node:path";
|
|
23298
23620
|
init_notary_source_run();
|
|
23299
23621
|
init_packaged_role_registry();
|
|
@@ -23306,7 +23628,7 @@ function navigatorInputReference(getFlag, role) {
|
|
|
23306
23628
|
}
|
|
23307
23629
|
async function loadNavigatorWorkContext(options) {
|
|
23308
23630
|
const reference = navigatorInputReference(options.getFlag, options.role);
|
|
23309
|
-
const input = reference === void 0 || options.role === "doctor" || options.role === "notary" ? void 0 : await
|
|
23631
|
+
const input = reference === void 0 || options.role === "doctor" || options.role === "notary" ? void 0 : await readFile22(reference, "utf8");
|
|
23310
23632
|
const subjectRoot = subjectPath(reference ?? options.context.sessionManager.getSessionDir(), options.context.cwd);
|
|
23311
23633
|
let subjectKey = reference === void 0 ? subjectRoot : navigatorSubjectKeyForInput(subjectRoot, reference, options.context.cwd);
|
|
23312
23634
|
let subject = input ?? `work subject: ${subjectKey}`;
|
|
@@ -23321,9 +23643,9 @@ async function loadNavigatorWorkContext(options) {
|
|
|
23321
23643
|
subject = JSON.stringify({ sourceRun: locator });
|
|
23322
23644
|
subjectProvenance = "role_input";
|
|
23323
23645
|
}
|
|
23324
|
-
const publicRunDir =
|
|
23646
|
+
const publicRunDir = runDirectoryFromHostContext(options.context);
|
|
23325
23647
|
const currentSessionDir = options.context.sessionManager.getSessionDir();
|
|
23326
|
-
const isBoundPublicRun =
|
|
23648
|
+
const isBoundPublicRun = publicRunDir !== void 0 && resolve19(currentSessionDir) === resolve19(publicRunDir, "session");
|
|
23327
23649
|
if (options.role === "judge" && isBoundPublicRun) {
|
|
23328
23650
|
let admitted;
|
|
23329
23651
|
try {
|
|
@@ -23363,7 +23685,7 @@ async function loadNavigatorWorkContext(options) {
|
|
|
23363
23685
|
let authorityMaterial;
|
|
23364
23686
|
for (const path of authorityFiles) {
|
|
23365
23687
|
try {
|
|
23366
|
-
const content = await
|
|
23688
|
+
const content = await readFile22(path, "utf8");
|
|
23367
23689
|
if (content.trim() !== "") {
|
|
23368
23690
|
authorityMaterial = content;
|
|
23369
23691
|
break;
|
|
@@ -23430,15 +23752,16 @@ function createRoleRuntimeDependencies(packageRoot) {
|
|
|
23430
23752
|
const doctorAuditor = createPiDoctorAuditor();
|
|
23431
23753
|
const navigatorSessionFactory = createNativeNavigatorSessionFactory();
|
|
23432
23754
|
return {
|
|
23755
|
+
packageRoot,
|
|
23433
23756
|
loadJudgeSoul: () => loadMainRoleSessionMaterials("judge"),
|
|
23434
23757
|
loadFixerSoul: () => loadMainRoleSessionMaterials("fixer"),
|
|
23435
|
-
loadFixPacket: (path) =>
|
|
23758
|
+
loadFixPacket: (path) => readFile23(path, "utf8"),
|
|
23436
23759
|
loadCoderSoul: () => loadMainRoleSessionMaterials("coder"),
|
|
23437
|
-
loadCoderTask: (path) =>
|
|
23760
|
+
loadCoderTask: (path) => readFile23(path, "utf8"),
|
|
23438
23761
|
loadReviewerSoul: () => loadMainRoleSessionMaterials("reviewer"),
|
|
23439
23762
|
createReviewerPinnedGitReader: () => createReviewerPinnedGitReader(),
|
|
23440
23763
|
loadCollectorSoul: () => loadMainRoleSessionMaterials("collector"),
|
|
23441
|
-
loadCollectorHandbookSeed: () =>
|
|
23764
|
+
loadCollectorHandbookSeed: () => readFile23(collectorHandbookSeedPath, "utf8"),
|
|
23442
23765
|
createCollectorTransport: () => createGhCollectorGitHubTransport(),
|
|
23443
23766
|
loadDoctorSoul: () => loadMainRoleSessionMaterials("doctor"),
|
|
23444
23767
|
loadDoctorCase,
|
|
@@ -23452,7 +23775,7 @@ function createRoleRuntimeDependencies(packageRoot) {
|
|
|
23452
23775
|
loadDiaristSoul: () => loadMainRoleSessionMaterials("diarist"),
|
|
23453
23776
|
loadNotarySourceRun: loadNotarySourceRunLocator,
|
|
23454
23777
|
loadMergerSoul: () => loadMainRoleSessionMaterials("merger"),
|
|
23455
|
-
loadMergerInput: async (path) => JSON.parse(await
|
|
23778
|
+
loadMergerInput: async (path) => JSON.parse(await readFile23(path, "utf8")),
|
|
23456
23779
|
async loadCanonicalSkillBinding(name) {
|
|
23457
23780
|
if (name === "tdd") {
|
|
23458
23781
|
return loadPackagedCanonicalSkillBinding(packageRoot, "tdd");
|
|
@@ -23478,7 +23801,7 @@ function createRoleRuntimeDependencies(packageRoot) {
|
|
|
23478
23801
|
authority: options.authority,
|
|
23479
23802
|
invocationId: options.invocationId,
|
|
23480
23803
|
loadSoul: () => loadMainRoleSessionMaterials("navigator"),
|
|
23481
|
-
loadRoutePlaybook: () =>
|
|
23804
|
+
loadRoutePlaybook: () => readFile23(navigatorRoutePlaybookPath, "utf8"),
|
|
23482
23805
|
loadRoleHelp: async (role) => formatNavigatorRoleHelp(role),
|
|
23483
23806
|
createSession: navigatorSessionFactory,
|
|
23484
23807
|
...options.contextError === void 0 ? {} : { contextError: options.contextError },
|
|
@@ -23491,9 +23814,9 @@ function createRoleRuntimeDependencies(packageRoot) {
|
|
|
23491
23814
|
init_session_identity();
|
|
23492
23815
|
|
|
23493
23816
|
// src/acp-host/description.ts
|
|
23494
|
-
import { join as
|
|
23817
|
+
import { join as join38 } from "node:path";
|
|
23495
23818
|
function resolveAcpBinary(description, operatorHome) {
|
|
23496
|
-
return
|
|
23819
|
+
return join38(operatorHome, ...description.binaryFromHome);
|
|
23497
23820
|
}
|
|
23498
23821
|
function acpStdioArgs(description, model, seat) {
|
|
23499
23822
|
const { prefix, suffix, modelFlag, thinkingFlag } = description.argv;
|
|
@@ -23516,6 +23839,7 @@ import { spawn as spawn4 } from "node:child_process";
|
|
|
23516
23839
|
import { createInterface } from "node:readline";
|
|
23517
23840
|
|
|
23518
23841
|
// src/external-host-turn-loop.ts
|
|
23842
|
+
init_host_contracts();
|
|
23519
23843
|
var EXTERNAL_ROLE_TURN_ROUND_LIMIT = 8;
|
|
23520
23844
|
function mergeRoleTurnAbortSignals(prepared, request) {
|
|
23521
23845
|
if (request === void 0) return prepared;
|
|
@@ -23524,6 +23848,9 @@ function mergeRoleTurnAbortSignals(prepared, request) {
|
|
|
23524
23848
|
}
|
|
23525
23849
|
function promptWithPriorNativePaths(basePrompt, request) {
|
|
23526
23850
|
if (request.continuation.kind !== "resume") return basePrompt;
|
|
23851
|
+
if (request.stationChild === true && isOfficerReviewSeat(request.activation.role)) {
|
|
23852
|
+
return basePrompt;
|
|
23853
|
+
}
|
|
23527
23854
|
const paths = request.hostTransition?.priorNativePaths;
|
|
23528
23855
|
if (paths === void 0 || paths.length === 0) return basePrompt;
|
|
23529
23856
|
return `${basePrompt}
|
|
@@ -23936,12 +24263,12 @@ function createAcpRoleTurnHost(config) {
|
|
|
23936
24263
|
// src/acp-host/seat-profile-soul.ts
|
|
23937
24264
|
import { constants as constants3 } from "node:fs";
|
|
23938
24265
|
import { access as access5, copyFile, lstat as lstat6, mkdir as mkdir7, readlink, symlink, unlink as unlink4 } from "node:fs/promises";
|
|
23939
|
-
import { dirname as dirname21, join as
|
|
24266
|
+
import { dirname as dirname21, join as join39, relative as relative3, resolve as resolve20 } from "node:path";
|
|
23940
24267
|
function seatProfileName(spec, role) {
|
|
23941
24268
|
return `${spec.namePrefix}${role}`;
|
|
23942
24269
|
}
|
|
23943
24270
|
function packageRoleSoulPath(packageRoot, role) {
|
|
23944
|
-
return
|
|
24271
|
+
return join39(packageRoot, "souls", `${role}.md`);
|
|
23945
24272
|
}
|
|
23946
24273
|
async function pathExists2(path) {
|
|
23947
24274
|
try {
|
|
@@ -23958,16 +24285,16 @@ async function ensureSeatProfileSoul(options) {
|
|
|
23958
24285
|
if (!await pathExists2(soulTarget)) {
|
|
23959
24286
|
throw new Error(`packaged role soul missing: ${soulTarget}`);
|
|
23960
24287
|
}
|
|
23961
|
-
const profilesRoot =
|
|
23962
|
-
const profileDir =
|
|
24288
|
+
const profilesRoot = join39(operatorHome, ...spec.profilesRootFromHome);
|
|
24289
|
+
const profileDir = join39(profilesRoot, profileName);
|
|
23963
24290
|
const hostRoot = dirname21(profilesRoot);
|
|
23964
|
-
const soulPath =
|
|
24291
|
+
const soulPath = join39(profileDir, spec.soulFileName);
|
|
23965
24292
|
if (!await pathExists2(profileDir)) {
|
|
23966
24293
|
await mkdir7(profileDir, { recursive: true });
|
|
23967
24294
|
for (const name of ["auth.json", ".env", "config.yaml"]) {
|
|
23968
|
-
const source =
|
|
24295
|
+
const source = join39(hostRoot, name);
|
|
23969
24296
|
if (!await pathExists2(source)) continue;
|
|
23970
|
-
await copyFile(source,
|
|
24297
|
+
await copyFile(source, join39(profileDir, name));
|
|
23971
24298
|
}
|
|
23972
24299
|
} else {
|
|
23973
24300
|
await mkdir7(profileDir, { recursive: true });
|