@akagilnc/pi-workflow-roles 0.1.4035 → 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 +476 -250
- 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 +503 -264
- package/dist/host-contracts.js +16 -0
- package/dist/inspector-contracts.js +8 -0
- package/dist/packaged-role-registry.js +1 -1
- package/dist/pi/role-turn-host.js +43 -13
- package/dist/public-cli/case-dossier-delivery.js +60 -1
- package/dist/public-cli/inspector-run.js +17 -3
- package/dist/public-cli/instruction-seat-run.js +9 -6
- package/dist/public-cli/main.js +239 -112
- 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 +24 -7
- package/dist/public-role-summons.js +8 -0
- package/dist/submission-ledger.js +30 -8
- 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 +22 -3
- package/src/inspector-contracts.ts +7 -0
- package/src/judge-role.ts +4 -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/role-turn-host.ts +48 -14
- package/src/public-cli/case-dossier-delivery.ts +86 -1
- package/src/public-cli/inspector-run.ts +26 -2
- package/src/public-cli/instruction-seat-run.ts +17 -9
- package/src/public-cli/invocation.ts +2 -0
- package/src/public-cli/notary-run.ts +13 -4
- package/src/public-cli/post-admission.ts +74 -65
- package/src/public-cli/run-lifecycle.ts +3 -0
- package/src/public-cli/settlement.ts +32 -6
- 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 +48 -13
- package/src/user-dialogue-stdin.ts +37 -0
- package/src/worker-role.ts +4 -0
|
@@ -737,9 +737,17 @@ var init_auditor_dossier_tool = __esm({
|
|
|
737
737
|
});
|
|
738
738
|
|
|
739
739
|
// src/readable-gate-item.ts
|
|
740
|
+
var readable_gate_item_exports = {};
|
|
741
|
+
__export(readable_gate_item_exports, {
|
|
742
|
+
joinReadableGateItems: () => joinReadableGateItems,
|
|
743
|
+
readableGateItem: () => readableGateItem
|
|
744
|
+
});
|
|
740
745
|
function readableGateItem(value) {
|
|
741
746
|
return typeof value === "string" ? value : JSON.stringify(value);
|
|
742
747
|
}
|
|
748
|
+
function joinReadableGateItems(items, separator = "; ") {
|
|
749
|
+
return items.map(readableGateItem).join(separator);
|
|
750
|
+
}
|
|
743
751
|
var init_readable_gate_item = __esm({
|
|
744
752
|
"src/readable-gate-item.ts"() {
|
|
745
753
|
"use strict";
|
|
@@ -806,12 +814,19 @@ var init_submission_errors = __esm({
|
|
|
806
814
|
});
|
|
807
815
|
|
|
808
816
|
// src/inspector-contracts.ts
|
|
809
|
-
var INSPECTOR_OUTPUT_TOOL_NAME, INSPECTOR_ACCEPTED_TEXT;
|
|
817
|
+
var INSPECTOR_OUTPUT_TOOL_NAME, INSPECTOR_ACCEPTED_TEXT, INSPECTOR_SOURCE_RUN_FLAG;
|
|
810
818
|
var init_inspector_contracts = __esm({
|
|
811
819
|
"src/inspector-contracts.ts"() {
|
|
812
820
|
"use strict";
|
|
813
821
|
INSPECTOR_OUTPUT_TOOL_NAME = "ak_inspector_output";
|
|
814
822
|
INSPECTOR_ACCEPTED_TEXT = "\u5BDF\u9662\u56DE\u6267\u5DF2\u63A5\u53D7";
|
|
823
|
+
INSPECTOR_SOURCE_RUN_FLAG = {
|
|
824
|
+
name: "ak-inspector-source-run",
|
|
825
|
+
definition: {
|
|
826
|
+
description: "\u5BDF\u9662\u521D\u94F8\u7ED1\u5B9A\u7684\u7236 run \u7EDD\u5BF9\u8DEF\u5F84",
|
|
827
|
+
type: "string"
|
|
828
|
+
}
|
|
829
|
+
};
|
|
815
830
|
}
|
|
816
831
|
});
|
|
817
832
|
|
|
@@ -1478,6 +1493,15 @@ var init_durable_principal = __esm({
|
|
|
1478
1493
|
});
|
|
1479
1494
|
|
|
1480
1495
|
// src/host-contracts.ts
|
|
1496
|
+
function isOfficerReviewSeat(role) {
|
|
1497
|
+
return role === "notary" || role === "inspector" || role === "auditor";
|
|
1498
|
+
}
|
|
1499
|
+
function runDirectoryFromHostContext(context) {
|
|
1500
|
+
return typeof context.runDirectory === "string" && context.runDirectory.trim() !== "" ? context.runDirectory : void 0;
|
|
1501
|
+
}
|
|
1502
|
+
function courtAttemptIdFromHostContext(context) {
|
|
1503
|
+
return typeof context.courtAttemptId === "string" && context.courtAttemptId.trim() !== "" ? context.courtAttemptId : void 0;
|
|
1504
|
+
}
|
|
1481
1505
|
var ExplicitInternalActivationError;
|
|
1482
1506
|
var init_host_contracts = __esm({
|
|
1483
1507
|
"src/host-contracts.ts"() {
|
|
@@ -2394,7 +2418,7 @@ var init_packaged_role_registry = __esm({
|
|
|
2394
2418
|
role: "inspector",
|
|
2395
2419
|
phases: [null],
|
|
2396
2420
|
outputTool: INSPECTOR_OUTPUT_TOOL_NAME,
|
|
2397
|
-
inputFlag:
|
|
2421
|
+
inputFlag: "ak-inspector-source-run",
|
|
2398
2422
|
phaseFlag: void 0,
|
|
2399
2423
|
activationStage: "load-and-install",
|
|
2400
2424
|
sessionMaterials: INSPECTOR_SESSION_MATERIALS
|
|
@@ -2498,6 +2522,18 @@ var init_role_activation_flags = __esm({
|
|
|
2498
2522
|
}
|
|
2499
2523
|
});
|
|
2500
2524
|
|
|
2525
|
+
// src/user-dialogue-stdin.ts
|
|
2526
|
+
function encodeUserDialogueStdin(body) {
|
|
2527
|
+
return JSON.stringify({ kind: USER_DIALOGUE_STDIN_KIND, body });
|
|
2528
|
+
}
|
|
2529
|
+
var USER_DIALOGUE_STDIN_KIND;
|
|
2530
|
+
var init_user_dialogue_stdin = __esm({
|
|
2531
|
+
"src/user-dialogue-stdin.ts"() {
|
|
2532
|
+
"use strict";
|
|
2533
|
+
USER_DIALOGUE_STDIN_KIND = "ak-user-dialogue";
|
|
2534
|
+
}
|
|
2535
|
+
});
|
|
2536
|
+
|
|
2501
2537
|
// src/sitian-contracts.ts
|
|
2502
2538
|
function attachDirectErrnoCode(error, cause) {
|
|
2503
2539
|
if (cause === null || typeof cause !== "object" || !("code" in cause)) return;
|
|
@@ -2871,11 +2907,6 @@ function applyPiNativeSkillInvocation(methods, prompt) {
|
|
|
2871
2907
|
}
|
|
2872
2908
|
function buildPiTurnExtraArgs(request, authority, extraPiArgs = []) {
|
|
2873
2909
|
const { sessionFile, sessionDirectory } = authority.decode(request.principal);
|
|
2874
|
-
const rawPrompt = request.continuation.kind === "initial" || request.continuation.kind === "resume" ? request.continuation.prompt : (() => {
|
|
2875
|
-
const _exhaustive = request.continuation;
|
|
2876
|
-
return _exhaustive;
|
|
2877
|
-
})();
|
|
2878
|
-
const prompt = applyPiNativeSkillInvocation(request.methods, rawPrompt);
|
|
2879
2910
|
return [
|
|
2880
2911
|
"--no-skills",
|
|
2881
2912
|
...buildMethodArgs(request.methods),
|
|
@@ -2889,12 +2920,24 @@ function buildPiTurnExtraArgs(request, authority, extraPiArgs = []) {
|
|
|
2889
2920
|
...extraPiArgs,
|
|
2890
2921
|
// Envelope assembly = projectActivationFlags; pi only renders argv pairs.
|
|
2891
2922
|
...activationFlagsToPiArgv(projectActivationFlags(request)),
|
|
2923
|
+
...piEngineModelArgs(request),
|
|
2892
2924
|
"--mode",
|
|
2893
2925
|
"json",
|
|
2894
|
-
...buildSeatModelCliArgs(request.model)
|
|
2895
|
-
prompt
|
|
2926
|
+
...buildSeatModelCliArgs(request.model)
|
|
2896
2927
|
];
|
|
2897
2928
|
}
|
|
2929
|
+
function piEngineModelArgs(request) {
|
|
2930
|
+
const model = normalizeEngineName(request.engineModel);
|
|
2931
|
+
if (model === void 0) return [];
|
|
2932
|
+
return [`--${ENGINE_MODEL_FLAG_NAME}`, model];
|
|
2933
|
+
}
|
|
2934
|
+
function piUserDialogueBody(request) {
|
|
2935
|
+
const rawPrompt = request.continuation.kind === "initial" || request.continuation.kind === "resume" ? request.continuation.prompt : (() => {
|
|
2936
|
+
const _exhaustive = request.continuation;
|
|
2937
|
+
return _exhaustive;
|
|
2938
|
+
})();
|
|
2939
|
+
return applyPiNativeSkillInvocation(request.methods, rawPrompt);
|
|
2940
|
+
}
|
|
2898
2941
|
async function resolveSelectedPi(command, cwd, env) {
|
|
2899
2942
|
const searchPath = env.PATH ?? (platform === "win32" ? process.env.PATH ?? "" : "/usr/bin:/bin");
|
|
2900
2943
|
const candidates = isAbsolute3(command) || command.includes("/") ? [resolve6(cwd, command)] : searchPath.split(delimiter).map((dir) => resolve6(cwd, dir, command));
|
|
@@ -2934,11 +2977,22 @@ function createDefaultPiSpawnRunner(options) {
|
|
|
2934
2977
|
const child = spawn3(piIdentity.executable, [...args], {
|
|
2935
2978
|
cwd: spawnOptions.cwd,
|
|
2936
2979
|
env: spawnOptions.env,
|
|
2937
|
-
stdio: ["
|
|
2980
|
+
stdio: ["pipe", "ignore", "pipe"]
|
|
2938
2981
|
});
|
|
2982
|
+
if (child.stdin === null) {
|
|
2983
|
+
throw new Error("Pi child stdin pipe was not created");
|
|
2984
|
+
}
|
|
2939
2985
|
if (child.stderr === null) {
|
|
2940
2986
|
throw new Error("Pi child stderr pipe was not created");
|
|
2941
2987
|
}
|
|
2988
|
+
let stdinDeliveryError;
|
|
2989
|
+
child.stdin.on("error", (error) => {
|
|
2990
|
+
stdinDeliveryError ??= error;
|
|
2991
|
+
});
|
|
2992
|
+
if (spawnOptions.stdin !== void 0) {
|
|
2993
|
+
child.stdin.write(spawnOptions.stdin);
|
|
2994
|
+
}
|
|
2995
|
+
child.stdin.end();
|
|
2942
2996
|
let stderr = "";
|
|
2943
2997
|
let timedOut = false;
|
|
2944
2998
|
let timer;
|
|
@@ -2991,6 +3045,10 @@ function createDefaultPiSpawnRunner(options) {
|
|
|
2991
3045
|
reject(executionError);
|
|
2992
3046
|
return;
|
|
2993
3047
|
}
|
|
3048
|
+
if (stdinDeliveryError !== void 0) {
|
|
3049
|
+
reject(stdinDeliveryError);
|
|
3050
|
+
return;
|
|
3051
|
+
}
|
|
2994
3052
|
resolveResult({
|
|
2995
3053
|
code,
|
|
2996
3054
|
stderr,
|
|
@@ -3014,7 +3072,8 @@ function createPiRoleTurnHost(config) {
|
|
|
3014
3072
|
return {
|
|
3015
3073
|
async executeTurn(request) {
|
|
3016
3074
|
let turnRequest = request;
|
|
3017
|
-
const
|
|
3075
|
+
const officerStationChild = request.stationChild === true && isOfficerReviewSeat(request.activation.role);
|
|
3076
|
+
const paths = !officerStationChild && request.hostTransition?.priorNativeKind === "sitian" ? request.hostTransition.priorNativePaths : void 0;
|
|
3018
3077
|
if (request.continuation.kind === "resume" && paths !== void 0 && paths.length > 0) {
|
|
3019
3078
|
turnRequest = {
|
|
3020
3079
|
...request,
|
|
@@ -3032,6 +3091,7 @@ ${paths.join("\n")}`
|
|
|
3032
3091
|
config.extraPiArgs ?? []
|
|
3033
3092
|
);
|
|
3034
3093
|
const args = buildExplicitInternalActivationArgs(roleEntry, extraArgs);
|
|
3094
|
+
const stdin = encodeUserDialogueStdin(piUserDialogueBody(turnRequest));
|
|
3035
3095
|
const env = {
|
|
3036
3096
|
...process.env,
|
|
3037
3097
|
HOME: request.home,
|
|
@@ -3063,6 +3123,7 @@ ${paths.join("\n")}`
|
|
|
3063
3123
|
return await spawnRunner(args, {
|
|
3064
3124
|
cwd: request.cwd,
|
|
3065
3125
|
env,
|
|
3126
|
+
stdin,
|
|
3066
3127
|
...timeoutMs === void 0 ? {} : { timeoutMs },
|
|
3067
3128
|
...request.signal === void 0 ? {} : { signal: request.signal }
|
|
3068
3129
|
});
|
|
@@ -3106,6 +3167,7 @@ var init_role_turn_host = __esm({
|
|
|
3106
3167
|
init_host_contracts();
|
|
3107
3168
|
init_engine_detour();
|
|
3108
3169
|
init_role_activation_flags();
|
|
3170
|
+
init_user_dialogue_stdin();
|
|
3109
3171
|
init_sitian_facade();
|
|
3110
3172
|
INTERNAL_ROLE_ENTRYPOINT_RELATIVE = "extensions/role-runtime.ts";
|
|
3111
3173
|
EXPLICIT_INTERNAL_LOAD_PROBE_ARGS = [
|
|
@@ -4813,7 +4875,8 @@ async function loadResumableInspectorRun(home, runId, authority) {
|
|
|
4813
4875
|
}
|
|
4814
4876
|
const admitted = {
|
|
4815
4877
|
role: "inspector",
|
|
4816
|
-
...resumedBaseAdmitted(loaded)
|
|
4878
|
+
...resumedBaseAdmitted(loaded),
|
|
4879
|
+
...loaded.admittedFields.sourceRunPath === void 0 ? {} : { sourceRunPath: loaded.admittedFields.sourceRunPath }
|
|
4817
4880
|
};
|
|
4818
4881
|
return seatLoadedResult(loaded, admitted);
|
|
4819
4882
|
}
|
|
@@ -9540,6 +9603,15 @@ var init_ticket_provenance = __esm({
|
|
|
9540
9603
|
});
|
|
9541
9604
|
|
|
9542
9605
|
// src/public-cli/case-dossier-delivery.ts
|
|
9606
|
+
var case_dossier_delivery_exports = {};
|
|
9607
|
+
__export(case_dossier_delivery_exports, {
|
|
9608
|
+
deliverCaseDossierAsAttachment: () => deliverCaseDossierAsAttachment,
|
|
9609
|
+
loadCaseDossierReadingMaterial: () => loadCaseDossierReadingMaterial,
|
|
9610
|
+
projectCaseDossierPointerSection: () => projectCaseDossierPointerSection
|
|
9611
|
+
});
|
|
9612
|
+
import { mkdtemp as mkdtemp2, readFile as readFile13, rm as rm2, writeFile as writeFile7 } from "node:fs/promises";
|
|
9613
|
+
import { tmpdir as tmpdir2 } from "node:os";
|
|
9614
|
+
import { join as join19 } from "node:path";
|
|
9543
9615
|
function describeDossierFile(path) {
|
|
9544
9616
|
return path;
|
|
9545
9617
|
}
|
|
@@ -9558,18 +9630,59 @@ async function projectCaseDossierPointerSection(input) {
|
|
|
9558
9630
|
`\u8BB0\u5F55\u5377\u5B97\uFF1A${describeDossierFile(volume.recordFile)}`
|
|
9559
9631
|
].join("\n");
|
|
9560
9632
|
}
|
|
9561
|
-
|
|
9633
|
+
async function deliverCaseDossierAsAttachment(input) {
|
|
9634
|
+
const section = await projectCaseDossierPointerSection({
|
|
9635
|
+
ticketNumber: input.ticketNumber,
|
|
9636
|
+
projectRoot: input.projectRoot,
|
|
9637
|
+
home: input.home
|
|
9638
|
+
});
|
|
9639
|
+
if (section === void 0) return void 0;
|
|
9640
|
+
const stagingDir = await mkdtemp2(join19(tmpdir2(), "ak-case-dossier-"));
|
|
9641
|
+
try {
|
|
9642
|
+
const stagingPath = join19(stagingDir, CASE_DOSSIER_ATTACH_FILE);
|
|
9643
|
+
await writeFile7(stagingPath, `${section}
|
|
9644
|
+
`, "utf8");
|
|
9645
|
+
return await freezeAttachmentsIntoRun(
|
|
9646
|
+
[stagingPath],
|
|
9647
|
+
input.runDirectory,
|
|
9648
|
+
CASE_DOSSIER_ATTACH_KEY
|
|
9649
|
+
);
|
|
9650
|
+
} finally {
|
|
9651
|
+
await rm2(stagingDir, { recursive: true, force: true });
|
|
9652
|
+
}
|
|
9653
|
+
}
|
|
9654
|
+
async function loadCaseDossierReadingMaterial(runDirectory) {
|
|
9655
|
+
const frozenPath = join19(
|
|
9656
|
+
runDirectory,
|
|
9657
|
+
"attachments",
|
|
9658
|
+
CASE_DOSSIER_ATTACH_KEY,
|
|
9659
|
+
`00-${CASE_DOSSIER_ATTACH_FILE}`
|
|
9660
|
+
);
|
|
9661
|
+
let section;
|
|
9662
|
+
try {
|
|
9663
|
+
section = await readFile13(frozenPath, "utf8");
|
|
9664
|
+
} catch (error) {
|
|
9665
|
+
if (error.code === "ENOENT") return void 0;
|
|
9666
|
+
throw error;
|
|
9667
|
+
}
|
|
9668
|
+
if (section.trim() === "") return void 0;
|
|
9669
|
+
return { kind: "case-dossier-pointer", frozenPath, section };
|
|
9670
|
+
}
|
|
9671
|
+
var CASE_DOSSIER_SECTION_HEADING, CASE_DOSSIER_ATTACH_KEY, CASE_DOSSIER_ATTACH_FILE;
|
|
9562
9672
|
var init_case_dossier_delivery = __esm({
|
|
9563
9673
|
"src/public-cli/case-dossier-delivery.ts"() {
|
|
9564
9674
|
"use strict";
|
|
9565
9675
|
init_ticket_provenance();
|
|
9676
|
+
init_invocation();
|
|
9566
9677
|
CASE_DOSSIER_SECTION_HEADING = "## \u672C\u7968\u8D77\u5C45\u5F55\uFF08\u7CFB\u7EDF\u968F\u6848\u63D0\u4F9B\uFF09";
|
|
9678
|
+
CASE_DOSSIER_ATTACH_KEY = "case-dossier";
|
|
9679
|
+
CASE_DOSSIER_ATTACH_FILE = "case-dossier-pointer.md";
|
|
9567
9680
|
}
|
|
9568
9681
|
});
|
|
9569
9682
|
|
|
9570
9683
|
// src/host-transition-prior-native.ts
|
|
9571
9684
|
import { access as access3, readdir as readdir3 } from "node:fs/promises";
|
|
9572
|
-
import { dirname as dirname11, join as
|
|
9685
|
+
import { dirname as dirname11, join as join20 } from "node:path";
|
|
9573
9686
|
function isEnoent2(error) {
|
|
9574
9687
|
return typeof error === "object" && error !== null && error.code === "ENOENT";
|
|
9575
9688
|
}
|
|
@@ -9594,7 +9707,7 @@ async function listSitianRecordPaths(sessionParent) {
|
|
|
9594
9707
|
const recordPaths = [];
|
|
9595
9708
|
for (const entry of entries) {
|
|
9596
9709
|
if (!entry.isDirectory()) continue;
|
|
9597
|
-
const recordFile =
|
|
9710
|
+
const recordFile = join20(sessionRoot, entry.name, "records.jsonl");
|
|
9598
9711
|
try {
|
|
9599
9712
|
await access3(recordFile);
|
|
9600
9713
|
recordPaths.push(recordFile);
|
|
@@ -9985,13 +10098,13 @@ var init_reviewer_dispatch = __esm({
|
|
|
9985
10098
|
});
|
|
9986
10099
|
|
|
9987
10100
|
// src/public-cli/reviewer-dispatch-rejection.ts
|
|
9988
|
-
import { readFile as
|
|
9989
|
-
import { join as
|
|
10101
|
+
import { readFile as readFile14, unlink as unlink3 } from "node:fs/promises";
|
|
10102
|
+
import { join as join21 } from "node:path";
|
|
9990
10103
|
function isReviewerPreflightViolation(value) {
|
|
9991
10104
|
return typeof value === "string" && REVIEWER_PREFLIGHT_VIOLATIONS.includes(value);
|
|
9992
10105
|
}
|
|
9993
10106
|
function reviewerDispatchRejectionPath(runDirectory) {
|
|
9994
|
-
return
|
|
10107
|
+
return join21(runDirectory, REVIEWER_DISPATCH_REJECTION_FILE);
|
|
9995
10108
|
}
|
|
9996
10109
|
async function clearReviewerDispatchRejection(runDirectory) {
|
|
9997
10110
|
try {
|
|
@@ -10006,7 +10119,7 @@ async function clearReviewerDispatchRejection(runDirectory) {
|
|
|
10006
10119
|
async function readReviewerDispatchRejection(runDirectory) {
|
|
10007
10120
|
let raw;
|
|
10008
10121
|
try {
|
|
10009
|
-
raw = await
|
|
10122
|
+
raw = await readFile14(reviewerDispatchRejectionPath(runDirectory), "utf8");
|
|
10010
10123
|
} catch (error) {
|
|
10011
10124
|
if (error instanceof Error && "code" in error && error.code === "ENOENT") {
|
|
10012
10125
|
return void 0;
|
|
@@ -10042,12 +10155,12 @@ var init_reviewer_dispatch_rejection = __esm({
|
|
|
10042
10155
|
});
|
|
10043
10156
|
|
|
10044
10157
|
// src/ledger-session-read.ts
|
|
10045
|
-
import { readFile as
|
|
10158
|
+
import { readFile as readFile15 } from "node:fs/promises";
|
|
10046
10159
|
function isRecord5(value) {
|
|
10047
10160
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
10048
10161
|
}
|
|
10049
10162
|
async function readLedgerSessionJsonl(path) {
|
|
10050
|
-
const text = await
|
|
10163
|
+
const text = await readFile15(path, "utf8");
|
|
10051
10164
|
const lines = text.split("\n");
|
|
10052
10165
|
const rows = [];
|
|
10053
10166
|
for (let index = 0; index < lines.length; index += 1) {
|
|
@@ -10129,7 +10242,7 @@ var init_ledger_session_read = __esm({
|
|
|
10129
10242
|
|
|
10130
10243
|
// src/analyst-gate-cycles-read.ts
|
|
10131
10244
|
import { readdir as readdir4 } from "node:fs/promises";
|
|
10132
|
-
import { join as
|
|
10245
|
+
import { join as join22 } from "node:path";
|
|
10133
10246
|
function isRecord6(value) {
|
|
10134
10247
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
10135
10248
|
}
|
|
@@ -10344,10 +10457,10 @@ function pairGateRounds(volumes) {
|
|
|
10344
10457
|
return rounds.sort((a, b) => a.officerStartedAt.localeCompare(b.officerStartedAt)).map((round, index) => ({ ...round, roundIndex: index + 1 }));
|
|
10345
10458
|
}
|
|
10346
10459
|
async function resolveOfficerSessionFromPointerFile(pointerPath) {
|
|
10347
|
-
const { readFile:
|
|
10460
|
+
const { readFile: readFile24 } = await import("node:fs/promises");
|
|
10348
10461
|
let raw;
|
|
10349
10462
|
try {
|
|
10350
|
-
raw = JSON.parse(await
|
|
10463
|
+
raw = JSON.parse(await readFile24(pointerPath, "utf8"));
|
|
10351
10464
|
} catch (error) {
|
|
10352
10465
|
throw new Error(
|
|
10353
10466
|
`direct officer run pointer unreadable in ${pointerPath}: ${error instanceof Error ? error.message : String(error)}`,
|
|
@@ -10379,7 +10492,7 @@ async function readAnalystGateCyclesFromAuditorRoles(auditorRolesDirectory, opti
|
|
|
10379
10492
|
throw error;
|
|
10380
10493
|
}
|
|
10381
10494
|
for (const name of names) {
|
|
10382
|
-
const path =
|
|
10495
|
+
const path = join22(directory, name);
|
|
10383
10496
|
const fromPointer = name.endsWith(".pointer.json");
|
|
10384
10497
|
const sessionPath = fromPointer ? await resolveOfficerSessionFromPointerFile(path) : path;
|
|
10385
10498
|
if (sessionPath === void 0) continue;
|
|
@@ -10518,7 +10631,7 @@ var init_audit_escalation = __esm({
|
|
|
10518
10631
|
});
|
|
10519
10632
|
|
|
10520
10633
|
// src/run-terminal-artifacts.ts
|
|
10521
|
-
import { basename as basename7, dirname as dirname12, join as
|
|
10634
|
+
import { basename as basename7, dirname as dirname12, join as join23 } from "node:path";
|
|
10522
10635
|
function runIdFromRunDirectory(runDirectory) {
|
|
10523
10636
|
const name = basename7(runDirectory);
|
|
10524
10637
|
const at = name.lastIndexOf("@");
|
|
@@ -10533,8 +10646,8 @@ var init_run_terminal_artifacts = __esm({
|
|
|
10533
10646
|
|
|
10534
10647
|
// src/submission-ledger.ts
|
|
10535
10648
|
function runIdentity(context) {
|
|
10536
|
-
const directory =
|
|
10537
|
-
if (
|
|
10649
|
+
const directory = runDirectoryFromHostContext(context);
|
|
10650
|
+
if (directory !== void 0) {
|
|
10538
10651
|
const fromDir = runIdFromRunDirectory(directory);
|
|
10539
10652
|
if (fromDir !== void 0) return fromDir;
|
|
10540
10653
|
}
|
|
@@ -10543,8 +10656,8 @@ function runIdentity(context) {
|
|
|
10543
10656
|
throw new Error("\u63D0\u4EA4\u8D26\u9700\u8981\u5DF2\u53D7\u7406\u7684 run \u8EAB\u4EFD");
|
|
10544
10657
|
}
|
|
10545
10658
|
function attemptIdentity(context, runId) {
|
|
10546
|
-
const courtAttempt =
|
|
10547
|
-
if (
|
|
10659
|
+
const courtAttempt = courtAttemptIdFromHostContext(context);
|
|
10660
|
+
if (courtAttempt !== void 0) return courtAttempt;
|
|
10548
10661
|
return context.sessionManager.getHeader?.()?.id ?? context.sessionManager.getLeafId?.() ?? `${runId}:initial`;
|
|
10549
10662
|
}
|
|
10550
10663
|
function submissionRecordFile(cwd, runId, home) {
|
|
@@ -10629,10 +10742,8 @@ function rowFromPayload(kind, payload, accepted, roleFallback) {
|
|
|
10629
10742
|
...typeof payload.toolCallId === "string" && payload.toolCallId.length > 0 ? { toolCallId: payload.toolCallId } : {}
|
|
10630
10743
|
};
|
|
10631
10744
|
}
|
|
10632
|
-
|
|
10633
|
-
const
|
|
10634
|
-
const { owned } = await readOwnedSubmissionRecords(cwd, runId, scope.home);
|
|
10635
|
-
const scoped = recordsForAttempt(owned, scope.attemptId);
|
|
10745
|
+
function mapOwnedToSubmissionRows(owned) {
|
|
10746
|
+
const scoped = owned;
|
|
10636
10747
|
const out = [];
|
|
10637
10748
|
const indexByCall = /* @__PURE__ */ new Map();
|
|
10638
10749
|
const roleByCall = /* @__PURE__ */ new Map();
|
|
@@ -10696,6 +10807,17 @@ async function readRecordedSubmissionRows(cwd, runId, homeOrScope) {
|
|
|
10696
10807
|
}
|
|
10697
10808
|
return out;
|
|
10698
10809
|
}
|
|
10810
|
+
async function readRecordedSubmissionRows(cwd, runId, homeOrScope) {
|
|
10811
|
+
const scope = resolveReadScope(homeOrScope);
|
|
10812
|
+
const { owned } = await readOwnedSubmissionRecords(cwd, runId, scope.home);
|
|
10813
|
+
const scoped = recordsForAttempt(owned, scope.attemptId);
|
|
10814
|
+
return mapOwnedToSubmissionRows(scoped);
|
|
10815
|
+
}
|
|
10816
|
+
async function readAttemptScopedSubmissionRows(cwd, runId, attemptId, home) {
|
|
10817
|
+
if (attemptId.length === 0) return [];
|
|
10818
|
+
const { owned } = await readOwnedSubmissionRecords(cwd, runId, home);
|
|
10819
|
+
return mapOwnedToSubmissionRows(owned.filter((record4) => recordAttemptId(record4) === attemptId));
|
|
10820
|
+
}
|
|
10699
10821
|
async function readRecordedSubmissions(cwd, runId, homeOrScope) {
|
|
10700
10822
|
return (await readRecordedSubmissionRows(cwd, runId, homeOrScope)).map((row) => row.accepted);
|
|
10701
10823
|
}
|
|
@@ -10850,29 +10972,28 @@ function createSubmissionLedgerHost(host, outputTools, failInfrastructure2 = (er
|
|
|
10850
10972
|
}
|
|
10851
10973
|
};
|
|
10852
10974
|
}
|
|
10853
|
-
var COURT_ATTEMPT_ENV;
|
|
10854
10975
|
var init_submission_ledger = __esm({
|
|
10855
10976
|
"src/submission-ledger.ts"() {
|
|
10856
10977
|
"use strict";
|
|
10857
10978
|
init_activation_ledger_topology();
|
|
10979
|
+
init_host_contracts();
|
|
10858
10980
|
init_audit_escalation();
|
|
10859
10981
|
init_run_terminal_artifacts();
|
|
10860
10982
|
init_sitian_facade();
|
|
10861
10983
|
init_submission_correctable_error();
|
|
10862
10984
|
init_terminating_infrastructure();
|
|
10863
|
-
COURT_ATTEMPT_ENV = "AK_ROLE_COURT_ATTEMPT";
|
|
10864
10985
|
}
|
|
10865
10986
|
});
|
|
10866
10987
|
|
|
10867
10988
|
// src/session-opening-materials.ts
|
|
10868
10989
|
import { existsSync as existsSync7 } from "node:fs";
|
|
10869
|
-
import { readFile as
|
|
10870
|
-
import { dirname as dirname13, join as
|
|
10990
|
+
import { readFile as readFile16 } from "node:fs/promises";
|
|
10991
|
+
import { dirname as dirname13, join as join24 } from "node:path";
|
|
10871
10992
|
import { fileURLToPath, pathToFileURL as pathToFileURL3 } from "node:url";
|
|
10872
10993
|
function resolvePackageRootDir(moduleUrl = import.meta.url) {
|
|
10873
10994
|
let dir = dirname13(fileURLToPath(moduleUrl));
|
|
10874
10995
|
for (let i = 0; i < 8; i += 1) {
|
|
10875
|
-
if (existsSync7(
|
|
10996
|
+
if (existsSync7(join24(dir, "package.json")) && existsSync7(join24(dir, "souls"))) {
|
|
10876
10997
|
return dir;
|
|
10877
10998
|
}
|
|
10878
10999
|
const parent = dirname13(dir);
|
|
@@ -10882,7 +11003,7 @@ function resolvePackageRootDir(moduleUrl = import.meta.url) {
|
|
|
10882
11003
|
return fileURLToPath(new URL("..", moduleUrl));
|
|
10883
11004
|
}
|
|
10884
11005
|
async function readPackageMaterial(relativePath) {
|
|
10885
|
-
return
|
|
11006
|
+
return readFile16(fileURLToPath(new URL(relativePath, packageRootUrl)), "utf8");
|
|
10886
11007
|
}
|
|
10887
11008
|
async function joinPackageMaterials(relativePaths) {
|
|
10888
11009
|
const chunks = [];
|
|
@@ -12210,9 +12331,20 @@ var init_collector_ledger = __esm({
|
|
|
12210
12331
|
// src/dossier-resolution.ts
|
|
12211
12332
|
import { existsSync as existsSync8, statSync as statSync2 } from "node:fs";
|
|
12212
12333
|
import { resolve as resolve11 } from "node:path";
|
|
12213
|
-
function
|
|
12334
|
+
function isHostContext(value) {
|
|
12335
|
+
return "sessionManager" in value;
|
|
12336
|
+
}
|
|
12337
|
+
function dossierPointerFrom(source) {
|
|
12338
|
+
if (source !== void 0 && isHostContext(source)) {
|
|
12339
|
+
return runDirectoryFromHostContext(source);
|
|
12340
|
+
}
|
|
12341
|
+
const env = source ?? process.env;
|
|
12214
12342
|
const raw = env[AUDIT_RUN_DIR_ENV];
|
|
12215
|
-
|
|
12343
|
+
return typeof raw === "string" && raw.trim() !== "" ? raw : void 0;
|
|
12344
|
+
}
|
|
12345
|
+
function resolveAuditDossier(source) {
|
|
12346
|
+
const raw = dossierPointerFrom(source);
|
|
12347
|
+
if (raw === void 0) {
|
|
12216
12348
|
return { status: "ok" };
|
|
12217
12349
|
}
|
|
12218
12350
|
const runDirectory = resolve11(raw);
|
|
@@ -12246,6 +12378,7 @@ var AUDIT_RUN_DIR_ENV, DOCTOR_CANDIDATE_ENTRY_TYPE, AuditMaterialsUnavailableErr
|
|
|
12246
12378
|
var init_dossier_resolution = __esm({
|
|
12247
12379
|
"src/dossier-resolution.ts"() {
|
|
12248
12380
|
"use strict";
|
|
12381
|
+
init_host_contracts();
|
|
12249
12382
|
AUDIT_RUN_DIR_ENV = "AK_ROLE_RUN_DIR";
|
|
12250
12383
|
DOCTOR_CANDIDATE_ENTRY_TYPE = "ak_doctor_audit_candidate";
|
|
12251
12384
|
AuditMaterialsUnavailableError = class extends Error {
|
|
@@ -12264,8 +12397,8 @@ var init_dossier_resolution = __esm({
|
|
|
12264
12397
|
|
|
12265
12398
|
// src/package-resources/method-skill.ts
|
|
12266
12399
|
import { createHash as createHash7 } from "node:crypto";
|
|
12267
|
-
import { readFile as
|
|
12268
|
-
import { join as
|
|
12400
|
+
import { readFile as readFile17, realpath as realpath7 } from "node:fs/promises";
|
|
12401
|
+
import { join as join25 } from "node:path";
|
|
12269
12402
|
function gitBlobOid(bytes) {
|
|
12270
12403
|
const body = typeof bytes === "string" ? Buffer.from(bytes, "utf8") : Buffer.from(bytes);
|
|
12271
12404
|
const header = Buffer.from(`blob ${body.byteLength}\0`, "utf8");
|
|
@@ -12282,10 +12415,10 @@ function packagedMethodSkillRelativeDirectory(name) {
|
|
|
12282
12415
|
return `${METHOD_SKILL_RELATIVE_ROOT}/${name}`;
|
|
12283
12416
|
}
|
|
12284
12417
|
function resolvePackagedMethodSkillRoot(packageRoot, name) {
|
|
12285
|
-
return
|
|
12418
|
+
return join25(packageRoot, packagedMethodSkillRelativeDirectory(name));
|
|
12286
12419
|
}
|
|
12287
12420
|
function resolvePackagedMethodSkillPath(packageRoot, name) {
|
|
12288
|
-
return
|
|
12421
|
+
return join25(resolvePackagedMethodSkillRoot(packageRoot, name), "SKILL.md");
|
|
12289
12422
|
}
|
|
12290
12423
|
function isRecord8(value) {
|
|
12291
12424
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
@@ -12379,11 +12512,11 @@ function parseProvenance(raw, expectedName) {
|
|
|
12379
12512
|
}
|
|
12380
12513
|
async function loadPackagedMethodSkillMaterial(packageRoot, name) {
|
|
12381
12514
|
const rootDirectory = resolvePackagedMethodSkillRoot(packageRoot, name);
|
|
12382
|
-
const skillPathConfigured =
|
|
12383
|
-
const provenancePath =
|
|
12515
|
+
const skillPathConfigured = join25(rootDirectory, "SKILL.md");
|
|
12516
|
+
const provenancePath = join25(rootDirectory, "provenance.json");
|
|
12384
12517
|
let provenanceRaw;
|
|
12385
12518
|
try {
|
|
12386
|
-
provenanceRaw = await
|
|
12519
|
+
provenanceRaw = await readFile17(provenancePath, "utf8");
|
|
12387
12520
|
} catch (error) {
|
|
12388
12521
|
throw new PackagedMethodSkillUnavailableError(name, provenancePath, error);
|
|
12389
12522
|
}
|
|
@@ -12397,10 +12530,10 @@ async function loadPackagedMethodSkillMaterial(packageRoot, name) {
|
|
|
12397
12530
|
}
|
|
12398
12531
|
const provenance = parseProvenance(provenanceJson, name);
|
|
12399
12532
|
for (const [rel, expected] of Object.entries(provenance.files)) {
|
|
12400
|
-
const absolute =
|
|
12533
|
+
const absolute = join25(rootDirectory, rel);
|
|
12401
12534
|
let bytes;
|
|
12402
12535
|
try {
|
|
12403
|
-
bytes = await
|
|
12536
|
+
bytes = await readFile17(absolute);
|
|
12404
12537
|
} catch (error) {
|
|
12405
12538
|
throw new PackagedMethodSkillUnavailableError(name, absolute, error);
|
|
12406
12539
|
}
|
|
@@ -12416,7 +12549,7 @@ async function loadPackagedMethodSkillMaterial(packageRoot, name) {
|
|
|
12416
12549
|
let raw;
|
|
12417
12550
|
try {
|
|
12418
12551
|
skillPath = await realpath7(skillPathConfigured);
|
|
12419
|
-
raw = await
|
|
12552
|
+
raw = await readFile17(skillPath, "utf8");
|
|
12420
12553
|
} catch (error) {
|
|
12421
12554
|
throw new PackagedMethodSkillUnavailableError(name, skillPathConfigured, error);
|
|
12422
12555
|
}
|
|
@@ -12903,8 +13036,8 @@ var init_terminal = __esm({
|
|
|
12903
13036
|
|
|
12904
13037
|
// src/public-cli/settlement.ts
|
|
12905
13038
|
import { randomUUID as randomUUID3 } from "node:crypto";
|
|
12906
|
-
import { appendFile as appendFile2, readFile as
|
|
12907
|
-
import { dirname as dirname14, join as
|
|
13039
|
+
import { appendFile as appendFile2, readFile as readFile18, readdir as readdir5, writeFile as writeFile8 } from "node:fs/promises";
|
|
13040
|
+
import { dirname as dirname14, join as join26 } from "node:path";
|
|
12908
13041
|
function sealedLedgerHome(admitted) {
|
|
12909
13042
|
return homeFromRunDirectory(admitted.runDirectory);
|
|
12910
13043
|
}
|
|
@@ -12927,6 +13060,16 @@ function roleOutcomeFromRows(role, rows) {
|
|
|
12927
13060
|
return { kind: "accepted", role, payloads };
|
|
12928
13061
|
}
|
|
12929
13062
|
async function sealedLedgerOutcome(admitted, role, scope) {
|
|
13063
|
+
const home = sealedLedgerHome(admitted);
|
|
13064
|
+
if (scope?.courtAttemptId !== void 0 && scope.courtAttemptId.length > 0) {
|
|
13065
|
+
const thisCourt = await readAttemptScopedSubmissionRows(
|
|
13066
|
+
admitted.projectRoot,
|
|
13067
|
+
admitted.runId,
|
|
13068
|
+
scope.courtAttemptId,
|
|
13069
|
+
home
|
|
13070
|
+
);
|
|
13071
|
+
return roleOutcomeFromRows(role, thisCourt);
|
|
13072
|
+
}
|
|
12930
13073
|
const rows = await readRecordedSubmissionRows(
|
|
12931
13074
|
admitted.projectRoot,
|
|
12932
13075
|
admitted.runId,
|
|
@@ -12953,11 +13096,15 @@ async function recordedSubmissionPayloads(admitted, scope) {
|
|
|
12953
13096
|
function withSubmissions(terminal, submissions) {
|
|
12954
13097
|
if (submissions.length === 0) return terminal;
|
|
12955
13098
|
const roleOutcome = terminal.roleOutcome;
|
|
12956
|
-
const withPayloads = roleOutcome.kind === "accepted" || roleOutcome.kind === "audit_escalation"
|
|
13099
|
+
const withPayloads = roleOutcome.kind === "accepted" || roleOutcome.kind === "audit_escalation" ? { ...roleOutcome, payloads: (roleOutcome.payloads ?? []).length > 0 ? roleOutcome.payloads : submissions } : roleOutcome.kind === "failure" ? { ...roleOutcome, payloads: roleOutcome.payloads ?? submissions } : roleOutcome;
|
|
12957
13100
|
return { ...terminal, roleOutcome: withPayloads, submissions };
|
|
12958
13101
|
}
|
|
12959
13102
|
async function attachRecordedSubmissions(admitted, terminal, scope) {
|
|
12960
|
-
|
|
13103
|
+
void scope;
|
|
13104
|
+
return withSubmissions(
|
|
13105
|
+
terminal,
|
|
13106
|
+
await recordedSubmissionPayloads(admitted, void 0)
|
|
13107
|
+
);
|
|
12961
13108
|
}
|
|
12962
13109
|
async function settleHostEndedNoReceipt(admitted, authority) {
|
|
12963
13110
|
const facts = noReceiptLifecycleFacts({
|
|
@@ -13026,7 +13173,7 @@ function presentStructuralRejection(error, io) {
|
|
|
13026
13173
|
}
|
|
13027
13174
|
async function inspectJudgeSession(sessionFile) {
|
|
13028
13175
|
try {
|
|
13029
|
-
await
|
|
13176
|
+
await readFile18(sessionFile, "utf8");
|
|
13030
13177
|
return { state: "present" };
|
|
13031
13178
|
} catch (error) {
|
|
13032
13179
|
if (isMissingPathError2(error)) return { state: "missing" };
|
|
@@ -13258,7 +13405,7 @@ function sessionReadFailure(error, fallbackMessage) {
|
|
|
13258
13405
|
return failed;
|
|
13259
13406
|
}
|
|
13260
13407
|
async function readBoundSessionEntries(sessionFile) {
|
|
13261
|
-
const text = await
|
|
13408
|
+
const text = await readFile18(sessionFile, "utf8");
|
|
13262
13409
|
const entries = [];
|
|
13263
13410
|
for (const line2 of text.trim().split("\n").filter(Boolean)) {
|
|
13264
13411
|
try {
|
|
@@ -13345,7 +13492,7 @@ async function readSessionProviderStop(sessionFile) {
|
|
|
13345
13492
|
}
|
|
13346
13493
|
}
|
|
13347
13494
|
async function readBoundEvidenceChildKnownFailure(sessionFile) {
|
|
13348
|
-
const childDirectory =
|
|
13495
|
+
const childDirectory = join26(dirname14(sessionFile), "evidence-children");
|
|
13349
13496
|
let names;
|
|
13350
13497
|
try {
|
|
13351
13498
|
names = await readdir5(childDirectory);
|
|
@@ -13356,7 +13503,7 @@ async function readBoundEvidenceChildKnownFailure(sessionFile) {
|
|
|
13356
13503
|
for (const file of names.filter((name) => name.endsWith(".jsonl")).sort().reverse()) {
|
|
13357
13504
|
let entries;
|
|
13358
13505
|
try {
|
|
13359
|
-
entries = await readBoundSessionEntries(
|
|
13506
|
+
entries = await readBoundSessionEntries(join26(childDirectory, file));
|
|
13360
13507
|
} catch (error) {
|
|
13361
13508
|
throw sessionReadFailure(error, "failed to read discovered evidence-child session");
|
|
13362
13509
|
}
|
|
@@ -13411,7 +13558,7 @@ async function loadBoundAuditorVolumes(sessionFile) {
|
|
|
13411
13558
|
latestParentUserIndex = i;
|
|
13412
13559
|
break;
|
|
13413
13560
|
}
|
|
13414
|
-
const childDirectories = [
|
|
13561
|
+
const childDirectories = [join26(dirname14(sessionFile), "auditor-roles")];
|
|
13415
13562
|
const valid = [];
|
|
13416
13563
|
let sawAnyDirectory = false;
|
|
13417
13564
|
for (const childDirectory of childDirectories) {
|
|
@@ -13426,7 +13573,7 @@ async function loadBoundAuditorVolumes(sessionFile) {
|
|
|
13426
13573
|
for (const file of names.filter((name) => name.endsWith(".jsonl")).sort().reverse()) {
|
|
13427
13574
|
let entries;
|
|
13428
13575
|
try {
|
|
13429
|
-
entries = await readBoundSessionEntries(
|
|
13576
|
+
entries = await readBoundSessionEntries(join26(childDirectory, file));
|
|
13430
13577
|
} catch (error) {
|
|
13431
13578
|
throw sessionReadFailure(error, "failed to read discovered auditor session");
|
|
13432
13579
|
}
|
|
@@ -13922,8 +14069,8 @@ function projectTerminalGateFact(rounds) {
|
|
|
13922
14069
|
};
|
|
13923
14070
|
}
|
|
13924
14071
|
async function extractGateFactFromSessionDirectory(sessionDirectory, options = {}) {
|
|
13925
|
-
const directories = [
|
|
13926
|
-
const parentSessionFile = options.parentSessionFile ??
|
|
14072
|
+
const directories = [join26(sessionDirectory, "auditor-roles")];
|
|
14073
|
+
const parentSessionFile = options.parentSessionFile ?? join26(sessionDirectory, "session.jsonl");
|
|
13927
14074
|
const rounds = await readAnalystGateCyclesFromAuditorRoles(directories, {
|
|
13928
14075
|
parentSessionFile
|
|
13929
14076
|
});
|
|
@@ -14021,9 +14168,9 @@ async function extractNavigatorFactFromAdmittedSession(sessionFile) {
|
|
|
14021
14168
|
async function publishJudgeArtifacts(admitted, roleOutcome, coordinates) {
|
|
14022
14169
|
await appendRunAttemptHistory({ role: admitted.role, runId: admitted.runId, sessionFile: coordinates.sessionFile }, roleOutcome);
|
|
14023
14170
|
const artifactsDir = await ensureRunArtifactsDir(admitted.runDirectory);
|
|
14024
|
-
const reportPath =
|
|
14025
|
-
const evidencePath =
|
|
14026
|
-
await
|
|
14171
|
+
const reportPath = join26(artifactsDir, "report.json");
|
|
14172
|
+
const evidencePath = join26(artifactsDir, "evidence.json");
|
|
14173
|
+
await writeFile8(
|
|
14027
14174
|
reportPath,
|
|
14028
14175
|
`${JSON.stringify(
|
|
14029
14176
|
{
|
|
@@ -14037,7 +14184,7 @@ async function publishJudgeArtifacts(admitted, roleOutcome, coordinates) {
|
|
|
14037
14184
|
`,
|
|
14038
14185
|
"utf8"
|
|
14039
14186
|
);
|
|
14040
|
-
await
|
|
14187
|
+
await writeFile8(
|
|
14041
14188
|
evidencePath,
|
|
14042
14189
|
`${JSON.stringify(
|
|
14043
14190
|
{
|
|
@@ -14123,9 +14270,9 @@ function extractDoctorCandidateAuditNoReceiptFact(entries) {
|
|
|
14123
14270
|
async function publishDoctorArtifacts(admitted, roleOutcome, coordinates, options = {}) {
|
|
14124
14271
|
await appendRunAttemptHistory({ role: admitted.role, runId: admitted.runId, sessionFile: coordinates.sessionFile }, roleOutcome);
|
|
14125
14272
|
const artifactsDir = await ensureRunArtifactsDir(admitted.runDirectory);
|
|
14126
|
-
const reportPath =
|
|
14127
|
-
const evidencePath =
|
|
14128
|
-
await
|
|
14273
|
+
const reportPath = join26(artifactsDir, "report.json");
|
|
14274
|
+
const evidencePath = join26(artifactsDir, "evidence.json");
|
|
14275
|
+
await writeFile8(
|
|
14129
14276
|
reportPath,
|
|
14130
14277
|
`${JSON.stringify(
|
|
14131
14278
|
{
|
|
@@ -14141,7 +14288,7 @@ async function publishDoctorArtifacts(admitted, roleOutcome, coordinates, option
|
|
|
14141
14288
|
`,
|
|
14142
14289
|
"utf8"
|
|
14143
14290
|
);
|
|
14144
|
-
await
|
|
14291
|
+
await writeFile8(
|
|
14145
14292
|
evidencePath,
|
|
14146
14293
|
`${JSON.stringify(
|
|
14147
14294
|
{
|
|
@@ -14361,7 +14508,7 @@ function uniqueFailureFallbackDirs(runDirectory, baseDir) {
|
|
|
14361
14508
|
return dirs;
|
|
14362
14509
|
}
|
|
14363
14510
|
async function resolveFailureArtifactsBase(runDirectory) {
|
|
14364
|
-
const artifactsDir =
|
|
14511
|
+
const artifactsDir = join26(runDirectory, "artifacts");
|
|
14365
14512
|
try {
|
|
14366
14513
|
await ensureRunArtifactsDir(runDirectory);
|
|
14367
14514
|
return { baseDir: artifactsDir };
|
|
@@ -14377,13 +14524,13 @@ async function writeFailureJsonRetainingCause(preferredCandidates, uniqueFallbac
|
|
|
14377
14524
|
const candidates = [
|
|
14378
14525
|
...preferredCandidates,
|
|
14379
14526
|
// One unique name per fallback dir — collisions on fixed names cannot exhaust this.
|
|
14380
|
-
...uniqueFallbackDirs.map((dir) =>
|
|
14527
|
+
...uniqueFallbackDirs.map((dir) => join26(dir, `${stem}.${randomUUID3()}.json`))
|
|
14381
14528
|
];
|
|
14382
14529
|
for (let i = 0; i < candidates.length; i += 1) {
|
|
14383
14530
|
const path = candidates[i];
|
|
14384
14531
|
const payload = issues.length === 0 ? basePayload : { ...basePayload, publicationIssues: issues };
|
|
14385
14532
|
try {
|
|
14386
|
-
await
|
|
14533
|
+
await writeFile8(
|
|
14387
14534
|
path,
|
|
14388
14535
|
`${JSON.stringify(payload, null, 2)}
|
|
14389
14536
|
`,
|
|
@@ -14422,26 +14569,26 @@ async function publishFailureArtifacts(admitted, failure2, authority) {
|
|
|
14422
14569
|
} catch (error) {
|
|
14423
14570
|
priorIssues.push(publicationAttemptFromError(sessionFile, error));
|
|
14424
14571
|
}
|
|
14425
|
-
const underArtifacts = baseDir ===
|
|
14572
|
+
const underArtifacts = baseDir === join26(admitted.runDirectory, "artifacts");
|
|
14426
14573
|
const uniqueFallbackDirs = uniqueFailureFallbackDirs(
|
|
14427
14574
|
admitted.runDirectory,
|
|
14428
14575
|
baseDir
|
|
14429
14576
|
);
|
|
14430
14577
|
const errorCandidates = underArtifacts ? [
|
|
14431
|
-
|
|
14432
|
-
|
|
14433
|
-
|
|
14578
|
+
join26(baseDir, "error.json"),
|
|
14579
|
+
join26(baseDir, "error.settlement.json"),
|
|
14580
|
+
join26(admitted.runDirectory, "error.settlement.json")
|
|
14434
14581
|
] : [
|
|
14435
|
-
|
|
14436
|
-
|
|
14582
|
+
join26(baseDir, "error.settlement.json"),
|
|
14583
|
+
join26(baseDir, "error.json")
|
|
14437
14584
|
];
|
|
14438
14585
|
const evidenceCandidates = underArtifacts ? [
|
|
14439
|
-
|
|
14440
|
-
|
|
14441
|
-
|
|
14586
|
+
join26(baseDir, "evidence.json"),
|
|
14587
|
+
join26(baseDir, "evidence.settlement.json"),
|
|
14588
|
+
join26(admitted.runDirectory, "evidence.settlement.json")
|
|
14442
14589
|
] : [
|
|
14443
|
-
|
|
14444
|
-
|
|
14590
|
+
join26(baseDir, "evidence.settlement.json"),
|
|
14591
|
+
join26(baseDir, "evidence.json")
|
|
14445
14592
|
];
|
|
14446
14593
|
const errorPayloadBase = {
|
|
14447
14594
|
kind: "error",
|
|
@@ -14686,7 +14833,7 @@ var init_settlement = __esm({
|
|
|
14686
14833
|
import { constants as fsConstants2 } from "node:fs";
|
|
14687
14834
|
import { randomUUID as randomUUID4 } from "node:crypto";
|
|
14688
14835
|
import { lstat as lstat5, mkdir as mkdir5, open as open2 } from "node:fs/promises";
|
|
14689
|
-
import { join as
|
|
14836
|
+
import { join as join27 } from "node:path";
|
|
14690
14837
|
async function persistReturnedRunState(admitted, authority, options) {
|
|
14691
14838
|
if (options?.lawful === true) {
|
|
14692
14839
|
await markRunTerminal(admitted.runDirectory);
|
|
@@ -14722,7 +14869,7 @@ async function finalizeExceptionRunBestEffort(runDirectory, io) {
|
|
|
14722
14869
|
}
|
|
14723
14870
|
}
|
|
14724
14871
|
function runArtifactsDirectory(runDirectory) {
|
|
14725
|
-
return
|
|
14872
|
+
return join27(runDirectory, "artifacts");
|
|
14726
14873
|
}
|
|
14727
14874
|
async function ensureRealArtifactsDirectory(runDirectory) {
|
|
14728
14875
|
const runStat = await lstat5(runDirectory);
|
|
@@ -14804,7 +14951,7 @@ function jsonSafeReplacer() {
|
|
|
14804
14951
|
};
|
|
14805
14952
|
}
|
|
14806
14953
|
async function writeHardenedArtifactFile(artifactsDir, namePrefix, payload) {
|
|
14807
|
-
const filePath =
|
|
14954
|
+
const filePath = join27(artifactsDir, `${namePrefix}-${randomUUID4()}.json`);
|
|
14808
14955
|
const body = `${JSON.stringify(payload, jsonSafeReplacer(), 2)}
|
|
14809
14956
|
`;
|
|
14810
14957
|
const noFollowFlag = typeof fsConstants2.O_NOFOLLOW === "number" ? fsConstants2.O_NOFOLLOW : 0;
|
|
@@ -15075,8 +15222,8 @@ var init_auto_resume = __esm({
|
|
|
15075
15222
|
|
|
15076
15223
|
// src/public-cli/post-admission.ts
|
|
15077
15224
|
import { randomUUID as randomUUID5 } from "node:crypto";
|
|
15078
|
-
import { readFile as
|
|
15079
|
-
import { isAbsolute as isAbsolute8, join as
|
|
15225
|
+
import { readFile as readFile19, writeFile as writeFile9 } from "node:fs/promises";
|
|
15226
|
+
import { isAbsolute as isAbsolute8, join as join28, resolve as resolve13 } from "node:path";
|
|
15080
15227
|
function describeCaughtError(error) {
|
|
15081
15228
|
if (error instanceof Error) {
|
|
15082
15229
|
const code = error.code;
|
|
@@ -15090,6 +15237,9 @@ function appendContinuationSection(continuation, section) {
|
|
|
15090
15237
|
${section}`;
|
|
15091
15238
|
return continuation.kind === "initial" ? { kind: "initial", prompt } : { kind: "resume", prompt };
|
|
15092
15239
|
}
|
|
15240
|
+
function isStationChildOfficerDialogue(role, env) {
|
|
15241
|
+
return env.stationChild === true && isOfficerReviewSeat(role);
|
|
15242
|
+
}
|
|
15093
15243
|
function withOnceSuccessfulBeforeDispatch(adapters) {
|
|
15094
15244
|
const hook = adapters.beforeDispatch;
|
|
15095
15245
|
if (hook === void 0) return adapters;
|
|
@@ -15117,8 +15267,8 @@ async function recordBestEffortPostDispatchDiagnostic(admitted, env, diagnostic,
|
|
|
15117
15267
|
} catch (appendError) {
|
|
15118
15268
|
try {
|
|
15119
15269
|
const artifactsDir = await ensureRealArtifactsDirectory(admitted.runDirectory);
|
|
15120
|
-
await
|
|
15121
|
-
|
|
15270
|
+
await writeFile9(
|
|
15271
|
+
join28(artifactsDir, `post-admission-diagnostic-${randomUUID5()}.json`),
|
|
15122
15272
|
`${JSON.stringify({ version: 1, ...payload }, null, 2)}
|
|
15123
15273
|
`,
|
|
15124
15274
|
{ encoding: "utf8", flag: "wx" }
|
|
@@ -15134,7 +15284,7 @@ async function recordBestEffortPostDispatchDiagnostic(admitted, env, diagnostic,
|
|
|
15134
15284
|
}
|
|
15135
15285
|
async function readInvocationHost(runDirectory) {
|
|
15136
15286
|
try {
|
|
15137
|
-
const raw = JSON.parse(await
|
|
15287
|
+
const raw = JSON.parse(await readFile19(join28(runDirectory, "invocation.json"), "utf8"));
|
|
15138
15288
|
return typeof raw.host === "string" && raw.host.trim() !== "" ? raw.host : void 0;
|
|
15139
15289
|
} catch (error) {
|
|
15140
15290
|
if (error.code === "ENOENT") return void 0;
|
|
@@ -15307,19 +15457,28 @@ async function dispatchPostAdmissionTurn(input) {
|
|
|
15307
15457
|
if (hostTransition !== void 0) {
|
|
15308
15458
|
turnRequest = { ...turnRequest, hostTransition };
|
|
15309
15459
|
}
|
|
15310
|
-
|
|
15311
|
-
|
|
15312
|
-
|
|
15313
|
-
|
|
15314
|
-
|
|
15315
|
-
|
|
15316
|
-
|
|
15317
|
-
|
|
15318
|
-
|
|
15319
|
-
|
|
15320
|
-
|
|
15321
|
-
|
|
15322
|
-
};
|
|
15460
|
+
if (isStationChildOfficerDialogue(admitted.role, env)) {
|
|
15461
|
+
await deliverCaseDossierAsAttachment({
|
|
15462
|
+
ticketNumber: admitted.ticketNumber,
|
|
15463
|
+
projectRoot: admitted.projectRoot,
|
|
15464
|
+
home: env.home,
|
|
15465
|
+
runDirectory: admitted.runDirectory
|
|
15466
|
+
});
|
|
15467
|
+
} else {
|
|
15468
|
+
const dossierSection = await projectCaseDossierPointerSection({
|
|
15469
|
+
ticketNumber: admitted.ticketNumber,
|
|
15470
|
+
projectRoot: admitted.projectRoot,
|
|
15471
|
+
home: env.home
|
|
15472
|
+
});
|
|
15473
|
+
if (dossierSection !== void 0) {
|
|
15474
|
+
turnRequest = {
|
|
15475
|
+
...turnRequest,
|
|
15476
|
+
continuation: appendContinuationSection(
|
|
15477
|
+
turnRequest.continuation,
|
|
15478
|
+
dossierSection
|
|
15479
|
+
)
|
|
15480
|
+
};
|
|
15481
|
+
}
|
|
15323
15482
|
}
|
|
15324
15483
|
await markRunRunning(
|
|
15325
15484
|
admitted.runDirectory,
|
|
@@ -15349,8 +15508,8 @@ async function dispatchPostAdmissionTurn(input) {
|
|
|
15349
15508
|
}
|
|
15350
15509
|
let stderrLogWriteFailure;
|
|
15351
15510
|
try {
|
|
15352
|
-
await
|
|
15353
|
-
|
|
15511
|
+
await writeFile9(
|
|
15512
|
+
join28(admitted.runDirectory, "stderr.log"),
|
|
15354
15513
|
result.stderr,
|
|
15355
15514
|
"utf8"
|
|
15356
15515
|
);
|
|
@@ -15539,25 +15698,17 @@ async function dispatchPostAdmissionTurn(input) {
|
|
|
15539
15698
|
}
|
|
15540
15699
|
}
|
|
15541
15700
|
function resumeTurnRequestProjectionOptions(admitted, request, env, summonsPrepared) {
|
|
15542
|
-
const
|
|
15543
|
-
const withReread = (body) => {
|
|
15544
|
-
if (officerSourcePath === void 0 || admitted.role !== "notary" && admitted.role !== "inspector" && admitted.role !== "auditor") {
|
|
15545
|
-
return body;
|
|
15546
|
-
}
|
|
15547
|
-
if (body.startsWith("\u8BF7\u91CD\u8BFB")) return body;
|
|
15548
|
-
return `\u8BF7\u91CD\u8BFB
|
|
15549
|
-
${body}`;
|
|
15550
|
-
};
|
|
15701
|
+
const officerDialogue = isStationChildOfficerDialogue(admitted.role, env);
|
|
15551
15702
|
let prompt;
|
|
15552
15703
|
if (request.message !== void 0) {
|
|
15553
15704
|
if (summonsPrepared !== void 0) {
|
|
15554
|
-
prompt =
|
|
15705
|
+
prompt = officerDialogue ? request.message : buildInstructionTransportPrompt({
|
|
15555
15706
|
instruction: request.message,
|
|
15556
15707
|
instructionEmpty: false,
|
|
15557
15708
|
attachments: summonsPrepared.attachments
|
|
15558
|
-
})
|
|
15709
|
+
});
|
|
15559
15710
|
} else if (request.summons !== void 0) {
|
|
15560
|
-
prompt =
|
|
15711
|
+
prompt = request.message;
|
|
15561
15712
|
} else {
|
|
15562
15713
|
prompt = buildResumeContinuationPrompt({
|
|
15563
15714
|
packageRoot: env.packageRoot,
|
|
@@ -15566,17 +15717,9 @@ ${body}`;
|
|
|
15566
15717
|
});
|
|
15567
15718
|
}
|
|
15568
15719
|
} else if (summonsPrepared !== void 0) {
|
|
15569
|
-
prompt =
|
|
15720
|
+
prompt = officerDialogue ? summonsPrepared.instructionEmpty ? "" : summonsPrepared.instruction : buildInstructionTransportPrompt(summonsPrepared);
|
|
15570
15721
|
} else if (request.summons !== void 0) {
|
|
15571
|
-
|
|
15572
|
-
if (path !== void 0 && (admitted.role === "notary" || admitted.role === "inspector" || admitted.role === "auditor")) {
|
|
15573
|
-
prompt = `\u8BF7\u91CD\u8BFB
|
|
15574
|
-
${GATE_DOSSIER_POINTER_PREFIX}${path}`;
|
|
15575
|
-
} else if (admitted.role === "notary" || admitted.role === "inspector" || admitted.role === "auditor") {
|
|
15576
|
-
prompt = "\u8BF7\u91CD\u8BFB";
|
|
15577
|
-
} else {
|
|
15578
|
-
prompt = "";
|
|
15579
|
-
}
|
|
15722
|
+
prompt = "";
|
|
15580
15723
|
} else {
|
|
15581
15724
|
prompt = buildResumeContinuationPrompt({
|
|
15582
15725
|
packageRoot: env.packageRoot,
|
|
@@ -15613,7 +15756,7 @@ async function dispatchAfterWriterLease(input) {
|
|
|
15613
15756
|
}
|
|
15614
15757
|
function isAlreadyFrozenSummonsAttachment(runDirectory, attachmentPath) {
|
|
15615
15758
|
const absolute = isAbsolute8(attachmentPath) ? attachmentPath : resolve13(attachmentPath);
|
|
15616
|
-
return pathContainedIn(
|
|
15759
|
+
return pathContainedIn(join28(runDirectory, "attachments"), absolute);
|
|
15617
15760
|
}
|
|
15618
15761
|
async function prepareSummonsResumeMaterials(runDirectory, summons) {
|
|
15619
15762
|
if (summons === void 0) return void 0;
|
|
@@ -15909,6 +16052,7 @@ var init_post_admission = __esm({
|
|
|
15909
16052
|
init_activation_ledger_topology();
|
|
15910
16053
|
init_engine_material();
|
|
15911
16054
|
init_session_identity();
|
|
16055
|
+
init_host_contracts();
|
|
15912
16056
|
init_case_dossier_delivery();
|
|
15913
16057
|
init_host_transition_prior_native();
|
|
15914
16058
|
init_public_run_credentials();
|
|
@@ -16002,7 +16146,7 @@ async function runPublicNotary(argv, env, io, parseNotaryArgv2) {
|
|
|
16002
16146
|
throw error;
|
|
16003
16147
|
}
|
|
16004
16148
|
{
|
|
16005
|
-
const resumeInstruction = env.reviewReask;
|
|
16149
|
+
const resumeInstruction = env.reviewReask ?? env.gateReviewInstruction;
|
|
16006
16150
|
const summons = {
|
|
16007
16151
|
sourceRunPath: source.runDirectory,
|
|
16008
16152
|
sourceRun: source,
|
|
@@ -16057,7 +16201,9 @@ async function runPublicNotary(argv, env, io, parseNotaryArgv2) {
|
|
|
16057
16201
|
...env.correlationId === void 0 || env.correlationId.trim() === "" ? {} : { correlationId: env.correlationId },
|
|
16058
16202
|
continuation: {
|
|
16059
16203
|
kind: "initial",
|
|
16060
|
-
|
|
16204
|
+
// #879: gate path first mint carries parent payload as dialogue content;
|
|
16205
|
+
// external zero-prompt kickoff unchanged when no body/reask.
|
|
16206
|
+
prompt: env.reviewReask ?? env.gateReviewInstruction ?? buildNotaryTransportPrompt(admitted, engineMaterial)
|
|
16061
16207
|
}
|
|
16062
16208
|
});
|
|
16063
16209
|
return await runPostAdmissionOneShot({
|
|
@@ -16145,12 +16291,20 @@ __export(inspector_run_exports, {
|
|
|
16145
16291
|
runPublicInspector: () => runPublicInspector,
|
|
16146
16292
|
runPublicInspectorResume: () => runPublicInspectorResume
|
|
16147
16293
|
});
|
|
16294
|
+
function inspectorParentRunPath(admitted) {
|
|
16295
|
+
if (typeof admitted.sourceRunPath === "string" && admitted.sourceRunPath.trim() !== "") {
|
|
16296
|
+
return admitted.sourceRunPath;
|
|
16297
|
+
}
|
|
16298
|
+
return parentRunPathFromGatePointerInstruction(admitted.instruction);
|
|
16299
|
+
}
|
|
16148
16300
|
function buildInspectorTurnRequest(admitted, options) {
|
|
16301
|
+
const sourceRun = inspectorParentRunPath(admitted);
|
|
16149
16302
|
return projectRoleTurnRequest(
|
|
16150
16303
|
admitted,
|
|
16151
16304
|
{
|
|
16152
16305
|
activation: {
|
|
16153
|
-
role: "inspector"
|
|
16306
|
+
role: "inspector",
|
|
16307
|
+
...sourceRun === void 0 ? {} : { sourceRun }
|
|
16154
16308
|
}
|
|
16155
16309
|
},
|
|
16156
16310
|
options
|
|
@@ -16170,7 +16324,7 @@ async function runPublicInspector(argv, env, io, parseInspectorArgv2) {
|
|
|
16170
16324
|
const projectRoot = parsed.project ?? env.cwd;
|
|
16171
16325
|
const parentRunPath = parentRunPathFromGatePointerInstruction(parsed.instruction);
|
|
16172
16326
|
if (parentRunPath !== void 0) {
|
|
16173
|
-
const resumeInstruction = env.reviewReask;
|
|
16327
|
+
const resumeInstruction = env.reviewReask ?? env.gateReviewInstruction;
|
|
16174
16328
|
const summons = {
|
|
16175
16329
|
sourceRunPath: parentRunPath,
|
|
16176
16330
|
...resumeInstruction === void 0 ? {
|
|
@@ -16215,6 +16369,10 @@ async function runPublicInspector(argv, env, io, parseInspectorArgv2) {
|
|
|
16215
16369
|
throw error;
|
|
16216
16370
|
}
|
|
16217
16371
|
await markRunAdmitted(admitted, env.principalAuthority);
|
|
16372
|
+
if (parentRunPath !== void 0) {
|
|
16373
|
+
await persistAdmittedSourceRunPath(admitted, parentRunPath);
|
|
16374
|
+
admitted = { ...admitted, sourceRunPath: parentRunPath };
|
|
16375
|
+
}
|
|
16218
16376
|
const engineMaterial = engineSessionMaterialFromOptions({
|
|
16219
16377
|
...pickEngineAxis(env),
|
|
16220
16378
|
packageRoot: env.packageRoot
|
|
@@ -16229,7 +16387,8 @@ async function runPublicInspector(argv, env, io, parseInspectorArgv2) {
|
|
|
16229
16387
|
...env.correlationId === void 0 || env.correlationId.trim() === "" ? {} : { correlationId: env.correlationId },
|
|
16230
16388
|
continuation: {
|
|
16231
16389
|
kind: "initial",
|
|
16232
|
-
|
|
16390
|
+
// #879: gate first mint uses parent payload as content; binding stays typed activation.
|
|
16391
|
+
prompt: env.reviewReask ?? env.gateReviewInstruction ?? buildInspectorTransportPrompt(admitted, engineMaterial)
|
|
16233
16392
|
}
|
|
16234
16393
|
});
|
|
16235
16394
|
return await runPostAdmissionOneShot({
|
|
@@ -16453,7 +16612,7 @@ async function runPublicInstructionSeat(argv, env, io, role, parseArgv) {
|
|
|
16453
16612
|
return { exitCode: 2 };
|
|
16454
16613
|
}
|
|
16455
16614
|
}
|
|
16456
|
-
const resumeInstruction = env.reviewReask;
|
|
16615
|
+
const resumeInstruction = env.reviewReask ?? env.gateReviewInstruction;
|
|
16457
16616
|
const summons = {
|
|
16458
16617
|
...resumeInstruction === void 0 ? {
|
|
16459
16618
|
instruction: parsed.instruction,
|
|
@@ -16519,7 +16678,8 @@ async function runPublicInstructionSeat(argv, env, io, role, parseArgv) {
|
|
|
16519
16678
|
...env.correlationId === void 0 || env.correlationId.trim() === "" ? {} : { correlationId: env.correlationId },
|
|
16520
16679
|
continuation: {
|
|
16521
16680
|
kind: "initial",
|
|
16522
|
-
|
|
16681
|
+
// #879: gate first mint uses parent payload as content when present.
|
|
16682
|
+
prompt: env.reviewReask ?? env.gateReviewInstruction ?? buildInstructionTransportPrompt(
|
|
16523
16683
|
admitted,
|
|
16524
16684
|
engineSessionMaterialFromOptions({
|
|
16525
16685
|
...pickEngineAxis(env),
|
|
@@ -16948,7 +17108,7 @@ __export(public_role_summons_exports, {
|
|
|
16948
17108
|
summonPublicRole: () => summonPublicRole
|
|
16949
17109
|
});
|
|
16950
17110
|
import { existsSync as existsSync9 } from "node:fs";
|
|
16951
|
-
import { join as
|
|
17111
|
+
import { join as join29 } from "node:path";
|
|
16952
17112
|
function createCapturingIo() {
|
|
16953
17113
|
const chunks = [];
|
|
16954
17114
|
return {
|
|
@@ -16971,7 +17131,7 @@ function parentDir(path) {
|
|
|
16971
17131
|
function walkPackageRoot(start) {
|
|
16972
17132
|
let dir = start;
|
|
16973
17133
|
for (let i = 0; i < 12; i += 1) {
|
|
16974
|
-
if (existsSync9(
|
|
17134
|
+
if (existsSync9(join29(dir, "package.json")) && existsSync9(join29(dir, "souls"))) {
|
|
16975
17135
|
return dir;
|
|
16976
17136
|
}
|
|
16977
17137
|
const parent = parentDir(dir);
|
|
@@ -17065,7 +17225,7 @@ async function createSummonEnv(options) {
|
|
|
17065
17225
|
async function summonPublicRole(options) {
|
|
17066
17226
|
const packageRoot = resolveSummonsPackageRoot(options.packageRoot);
|
|
17067
17227
|
const home = await resolveSummonHome(options);
|
|
17068
|
-
const agentDir = options.agentDir ?? process.env.PI_CODING_AGENT_DIR ??
|
|
17228
|
+
const agentDir = options.agentDir ?? process.env.PI_CODING_AGENT_DIR ?? join29(home, ".pi", "agent");
|
|
17069
17229
|
const {
|
|
17070
17230
|
loadCredentialProviders: loadCredentialProviders2,
|
|
17071
17231
|
loadPublicCliConfig: loadPublicCliConfig2,
|
|
@@ -17106,6 +17266,8 @@ async function summonPublicRole(options) {
|
|
|
17106
17266
|
...options.signal === void 0 ? {} : { signal: options.signal },
|
|
17107
17267
|
// #753: reask rides the existing notary same-ticket resume summons.instruction.
|
|
17108
17268
|
...options.reviewReask === void 0 ? {} : { reviewReask: options.reviewReask },
|
|
17269
|
+
// #879: verbatim submission body on officer dialogue content channel.
|
|
17270
|
+
...options.gateReviewInstruction === void 0 ? {} : { gateReviewInstruction: options.gateReviewInstruction },
|
|
17109
17271
|
...options.boundTicketNumber === void 0 ? {} : { boundTicketNumber: options.boundTicketNumber },
|
|
17110
17272
|
// createRunId is the only remaining env overlay — host is seat-selected above.
|
|
17111
17273
|
...options.createRunId === void 0 ? {} : { createRunId: options.createRunId }
|
|
@@ -17213,6 +17375,11 @@ async function summonGateOfficer(options) {
|
|
|
17213
17375
|
const { homeFromRunDirectory: homeFromRunDirectory3 } = await Promise.resolve().then(() => (init_activation_ledger_topology(), activation_ledger_topology_exports));
|
|
17214
17376
|
home = homeFromRunDirectory3(options.sourceRunDirectory);
|
|
17215
17377
|
}
|
|
17378
|
+
let gateReviewInstruction;
|
|
17379
|
+
if (options.reask === void 0 && options.submission !== void 0) {
|
|
17380
|
+
const { readableGateItem: readableGateItem2 } = await Promise.resolve().then(() => (init_readable_gate_item(), readable_gate_item_exports));
|
|
17381
|
+
gateReviewInstruction = readableGateItem2(options.submission);
|
|
17382
|
+
}
|
|
17216
17383
|
const common = {
|
|
17217
17384
|
cwd: options.cwd,
|
|
17218
17385
|
...home === void 0 ? {} : { home },
|
|
@@ -17220,6 +17387,7 @@ async function summonGateOfficer(options) {
|
|
|
17220
17387
|
...options.io === void 0 ? {} : { io: options.io },
|
|
17221
17388
|
...options.signal === void 0 ? {} : { signal: options.signal },
|
|
17222
17389
|
...options.reask === void 0 ? {} : { reviewReask: options.reask },
|
|
17390
|
+
...gateReviewInstruction === void 0 ? {} : { gateReviewInstruction },
|
|
17223
17391
|
...options.roleTurnHost === void 0 ? {} : { roleTurnHost: options.roleTurnHost },
|
|
17224
17392
|
...options.hostAdapters === void 0 ? {} : { hostAdapters: options.hostAdapters },
|
|
17225
17393
|
...options.createRunId === void 0 ? {} : { createRunId: options.createRunId }
|
|
@@ -17293,11 +17461,18 @@ function projectOfficerDecision(officer, decision, fallbackStatus) {
|
|
|
17293
17461
|
}
|
|
17294
17462
|
return { status: "needs_reask", officer, receipt };
|
|
17295
17463
|
}
|
|
17296
|
-
function
|
|
17464
|
+
function thisCourtOfficerPayloads(terminal) {
|
|
17297
17465
|
const outcome = terminal?.roleOutcome;
|
|
17298
17466
|
if (outcome !== void 0 && (outcome.kind === "accepted" || outcome.kind === "audit_escalation")) {
|
|
17299
|
-
|
|
17467
|
+
if (outcome.payloads !== void 0 && outcome.payloads.length > 0) return outcome.payloads;
|
|
17468
|
+
}
|
|
17469
|
+
if (outcome?.kind === "failure" && outcome.payloads !== void 0 && outcome.payloads.length > 0) {
|
|
17470
|
+
return outcome.payloads;
|
|
17300
17471
|
}
|
|
17472
|
+
return [];
|
|
17473
|
+
}
|
|
17474
|
+
function officerFailurePayloads(terminal) {
|
|
17475
|
+
const outcome = terminal?.roleOutcome;
|
|
17301
17476
|
if (outcome?.kind === "failure") return outcome.payloads ?? terminal?.submissions ?? [];
|
|
17302
17477
|
return terminal?.submissions ?? [];
|
|
17303
17478
|
}
|
|
@@ -17305,24 +17480,20 @@ function projectOfficerPayloads(officer, payloads, fallbackStatus) {
|
|
|
17305
17480
|
if (payloads.length === 0) {
|
|
17306
17481
|
return projectOfficerDecision(officer, void 0, fallbackStatus);
|
|
17307
17482
|
}
|
|
17308
|
-
|
|
17309
|
-
if (payloads.length === 1) return queued;
|
|
17310
|
-
if (queued.status === "pass" || queued.status === "bounce" || queued.status === "escalate" || queued.status === "needs_reask") {
|
|
17311
|
-
return { ...queued, receipt: payloads };
|
|
17312
|
-
}
|
|
17313
|
-
return queued;
|
|
17483
|
+
return projectOfficerDecision(officer, payloads[payloads.length - 1], fallbackStatus);
|
|
17314
17484
|
}
|
|
17315
17485
|
function projectOfficerTerminal(officer, summoned) {
|
|
17316
17486
|
const terminal = summoned.terminal;
|
|
17317
17487
|
const outcome = terminal?.roleOutcome;
|
|
17318
|
-
const
|
|
17488
|
+
const thisCourt = thisCourtOfficerPayloads(terminal);
|
|
17319
17489
|
if (outcome === void 0) {
|
|
17320
17490
|
const detail = summoned.stderr ?? "";
|
|
17491
|
+
const failurePayloads = officerFailurePayloads(terminal);
|
|
17321
17492
|
return {
|
|
17322
17493
|
status: "transport_failure",
|
|
17323
17494
|
stage: officer,
|
|
17324
17495
|
reason: detail.length > 0 ? `${gateSeatLabel(officer)} public summon exit ${summoned.exitCode}: ${detail}` : `${gateSeatLabel(officer)} public summon produced no terminal (exit ${summoned.exitCode})`,
|
|
17325
|
-
submission:
|
|
17496
|
+
submission: failurePayloads.length > 0 ? failurePayloads : summoned
|
|
17326
17497
|
};
|
|
17327
17498
|
}
|
|
17328
17499
|
if (outcome.kind === "no_receipt") {
|
|
@@ -17334,27 +17505,30 @@ function projectOfficerTerminal(officer, summoned) {
|
|
|
17334
17505
|
};
|
|
17335
17506
|
}
|
|
17336
17507
|
if (outcome.kind === "failure") {
|
|
17508
|
+
const failurePayloads = officerFailurePayloads(terminal);
|
|
17337
17509
|
return {
|
|
17338
17510
|
status: "transport_failure",
|
|
17339
17511
|
stage: officer,
|
|
17340
17512
|
reason: outcome.diagnostic,
|
|
17341
|
-
submission:
|
|
17513
|
+
submission: failurePayloads.length > 0 ? failurePayloads : outcome.decisiveFacts
|
|
17342
17514
|
};
|
|
17343
17515
|
}
|
|
17344
17516
|
if (outcome.kind === "audit_escalation") {
|
|
17345
17517
|
return {
|
|
17346
17518
|
status: "escalate",
|
|
17347
17519
|
officer,
|
|
17348
|
-
receipt
|
|
17520
|
+
// This-court receipt only (#879) — historical rows remain on terminal.submissions.
|
|
17521
|
+
receipt: thisCourt.length > 0 ? thisCourt[thisCourt.length - 1] : retainedReceipt(outcome)
|
|
17349
17522
|
};
|
|
17350
17523
|
}
|
|
17351
17524
|
if (outcome.kind === "accepted") {
|
|
17352
|
-
return projectOfficerPayloads(officer,
|
|
17525
|
+
return projectOfficerPayloads(officer, thisCourt, outcome.status);
|
|
17353
17526
|
}
|
|
17354
17527
|
return {
|
|
17355
17528
|
status: "needs_reask",
|
|
17356
17529
|
officer,
|
|
17357
|
-
|
|
17530
|
+
// This-court receipt only (#879).
|
|
17531
|
+
receipt: thisCourt.length > 0 ? thisCourt[thisCourt.length - 1] : retainedReceipt(outcome)
|
|
17358
17532
|
};
|
|
17359
17533
|
}
|
|
17360
17534
|
async function projectGatekeeperRun(options) {
|
|
@@ -17372,7 +17546,7 @@ async function projectGatekeeperRun(options) {
|
|
|
17372
17546
|
}
|
|
17373
17547
|
let summoned;
|
|
17374
17548
|
try {
|
|
17375
|
-
const summon = options.summonOfficer ?? (async (nextOfficer, sourceRunDirectory, officerSignal, reask) => {
|
|
17549
|
+
const summon = options.summonOfficer ?? (async (nextOfficer, sourceRunDirectory, officerSignal, reask, nextSubmission) => {
|
|
17376
17550
|
const { summonGateOfficer: summonGateOfficer2 } = await Promise.resolve().then(() => (init_public_role_summons(), public_role_summons_exports));
|
|
17377
17551
|
return summonGateOfficer2({
|
|
17378
17552
|
officer: nextOfficer,
|
|
@@ -17380,6 +17554,7 @@ async function projectGatekeeperRun(options) {
|
|
|
17380
17554
|
cwd: options.context.cwd ?? process.cwd(),
|
|
17381
17555
|
...officerSignal === void 0 ? {} : { signal: officerSignal },
|
|
17382
17556
|
...reask === void 0 ? {} : { reask },
|
|
17557
|
+
...nextSubmission === void 0 ? {} : { submission: nextSubmission },
|
|
17383
17558
|
...options.home === void 0 ? {} : { home: options.home },
|
|
17384
17559
|
...options.packageRoot === void 0 ? {} : { packageRoot: options.packageRoot },
|
|
17385
17560
|
...options.roleTurnHost === void 0 ? {} : { roleTurnHost: options.roleTurnHost },
|
|
@@ -17390,7 +17565,8 @@ async function projectGatekeeperRun(options) {
|
|
|
17390
17565
|
officer,
|
|
17391
17566
|
runDirectory,
|
|
17392
17567
|
options.signal,
|
|
17393
|
-
options.reask
|
|
17568
|
+
options.reask,
|
|
17569
|
+
options.submission
|
|
17394
17570
|
);
|
|
17395
17571
|
} catch (error) {
|
|
17396
17572
|
return {
|
|
@@ -17431,12 +17607,12 @@ __export(session_assistant_usage_exports, {
|
|
|
17431
17607
|
sessionFileFromPublicSummon: () => sessionFileFromPublicSummon,
|
|
17432
17608
|
usageFromPublicSummon: () => usageFromPublicSummon
|
|
17433
17609
|
});
|
|
17434
|
-
import { join as
|
|
17610
|
+
import { join as join30 } from "node:path";
|
|
17435
17611
|
async function readAssistantUsageFromSessionFile(sessionFile) {
|
|
17436
|
-
const { readFile:
|
|
17612
|
+
const { readFile: readFile24 } = await import("node:fs/promises");
|
|
17437
17613
|
let text;
|
|
17438
17614
|
try {
|
|
17439
|
-
text = await
|
|
17615
|
+
text = await readFile24(sessionFile, "utf8");
|
|
17440
17616
|
} catch (error) {
|
|
17441
17617
|
if (error?.code === "ENOENT") return void 0;
|
|
17442
17618
|
throw error;
|
|
@@ -17501,7 +17677,7 @@ async function readAssistantUsageFromSessionFile(sessionFile) {
|
|
|
17501
17677
|
}
|
|
17502
17678
|
function sessionFileFromPublicSummon(summoned) {
|
|
17503
17679
|
if (typeof summoned.runDirectory === "string" && summoned.runDirectory.trim() !== "") {
|
|
17504
|
-
return
|
|
17680
|
+
return join30(summoned.runDirectory, "session", "session.jsonl");
|
|
17505
17681
|
}
|
|
17506
17682
|
const fromArtifacts = summoned.terminal?.artifacts?.map((a) => a.path).find((p) => typeof p === "string" && p.endsWith("session.jsonl"));
|
|
17507
17683
|
if (fromArtifacts !== void 0) return fromArtifacts;
|
|
@@ -17510,7 +17686,7 @@ function sessionFileFromPublicSummon(summoned) {
|
|
|
17510
17686
|
const facts = outcome.decisiveFacts;
|
|
17511
17687
|
const pointer = facts?.runPointer;
|
|
17512
17688
|
if (typeof pointer === "string" && pointer.trim() !== "") {
|
|
17513
|
-
return
|
|
17689
|
+
return join30(pointer, "session", "session.jsonl");
|
|
17514
17690
|
}
|
|
17515
17691
|
return void 0;
|
|
17516
17692
|
}
|
|
@@ -17666,7 +17842,7 @@ var init_compliance_transport = __esm({
|
|
|
17666
17842
|
// src/doctor-auditor.ts
|
|
17667
17843
|
function createPiDoctorAuditor() {
|
|
17668
17844
|
return async (options) => {
|
|
17669
|
-
const dossier = resolveAuditDossier();
|
|
17845
|
+
const dossier = resolveAuditDossier(options.context);
|
|
17670
17846
|
requireAuditMaterials(dossier);
|
|
17671
17847
|
const subjects = readDoctorAuditSubjects(options.context);
|
|
17672
17848
|
requireAuditMaterials(subjects);
|
|
@@ -17690,11 +17866,11 @@ var init_doctor_auditor = __esm({
|
|
|
17690
17866
|
|
|
17691
17867
|
// src/archivist-record-topology.ts
|
|
17692
17868
|
import { createHash as createHash8 } from "node:crypto";
|
|
17693
|
-
import { join as
|
|
17869
|
+
import { join as join31 } from "node:path";
|
|
17694
17870
|
function subjectKeyedRecordDirectory(input) {
|
|
17695
17871
|
const ledgerHome = input.parentSessionFile !== void 0 && input.parentSessionFile.length > 0 ? resolveActivationLedgerHomeForPath(input.parentSessionFile) : resolveActivationLedgerHome(input.home);
|
|
17696
17872
|
const digest = createHash8("sha256").update(input.subject).digest("hex").slice(0, 32);
|
|
17697
|
-
return
|
|
17873
|
+
return join31(
|
|
17698
17874
|
activationBookDirectory(ledgerHome, resolveBookKeyFromGit(input.cwd)),
|
|
17699
17875
|
input.kind,
|
|
17700
17876
|
digest
|
|
@@ -17719,10 +17895,10 @@ __export(archivist_record_entry_exports, {
|
|
|
17719
17895
|
subjectKeyedRecordDirectory: () => subjectKeyedRecordDirectory
|
|
17720
17896
|
});
|
|
17721
17897
|
import { existsSync as existsSync10, mkdirSync as mkdirSync3, readFileSync as readFileSync3, realpathSync as realpathSync2, writeFileSync as writeFileSync3 } from "node:fs";
|
|
17722
|
-
import { dirname as dirname15, resolve as resolve14, join as
|
|
17898
|
+
import { dirname as dirname15, resolve as resolve14, join as join32 } from "node:path";
|
|
17723
17899
|
import { SessionManager } from "@earendil-works/pi-coding-agent";
|
|
17724
17900
|
function readCurrentSession(sessionDir) {
|
|
17725
|
-
const ledger =
|
|
17901
|
+
const ledger = join32(sessionDir, CURRENT_SESSION_LEDGER);
|
|
17726
17902
|
try {
|
|
17727
17903
|
const value = JSON.parse(readFileSync3(ledger, "utf8"));
|
|
17728
17904
|
if (typeof value !== "object" || value === null || typeof value.sessionFile !== "string" || value.sessionFile.length === 0) {
|
|
@@ -17737,7 +17913,7 @@ function readCurrentSession(sessionDir) {
|
|
|
17737
17913
|
}
|
|
17738
17914
|
}
|
|
17739
17915
|
function writeCurrentSession(sessionDir, sessionFile) {
|
|
17740
|
-
const ledger =
|
|
17916
|
+
const ledger = join32(sessionDir, CURRENT_SESSION_LEDGER);
|
|
17741
17917
|
try {
|
|
17742
17918
|
writeFileSync3(ledger, `${JSON.stringify({ sessionFile })}
|
|
17743
17919
|
`, { flag: "wx" });
|
|
@@ -17798,7 +17974,7 @@ function createRecordSessionOpen(options) {
|
|
|
17798
17974
|
return { session: SessionManager.inMemory(cwd), resumed: false };
|
|
17799
17975
|
} else {
|
|
17800
17976
|
const parentResolved = resolve14(parentFile);
|
|
17801
|
-
sessionDir = physicallyContainedIn(ledgerHome, parentResolved) ?
|
|
17977
|
+
sessionDir = physicallyContainedIn(ledgerHome, parentResolved) ? join32(dirname15(parentResolved), options.kind) : join32(activationBookDirectory(ledgerHome, resolveBookKeyFromGit(cwd)), options.kind);
|
|
17802
17978
|
parentSession = parentFile;
|
|
17803
17979
|
}
|
|
17804
17980
|
const nestAlreadyExists = existsSync10(sessionDir);
|
|
@@ -17837,7 +18013,7 @@ function createRecordSession(options) {
|
|
|
17837
18013
|
return createRecordSessionOpen(options).session;
|
|
17838
18014
|
}
|
|
17839
18015
|
function bookDirectOfficerRunPointer(options) {
|
|
17840
|
-
const nest =
|
|
18016
|
+
const nest = join32(dirname15(options.parentSessionFile), "auditor-roles");
|
|
17841
18017
|
mkdirSync3(nest, { recursive: true });
|
|
17842
18018
|
const pointer = {
|
|
17843
18019
|
version: 1,
|
|
@@ -17847,7 +18023,7 @@ function bookDirectOfficerRunPointer(options) {
|
|
|
17847
18023
|
...options.runDirectory !== void 0 && options.runDirectory.trim() !== "" ? { runDirectory: options.runDirectory } : {}
|
|
17848
18024
|
};
|
|
17849
18025
|
writeFileSync3(
|
|
17850
|
-
|
|
18026
|
+
join32(nest, `${options.officer}.pointer.json`),
|
|
17851
18027
|
`${JSON.stringify(pointer)}
|
|
17852
18028
|
`,
|
|
17853
18029
|
"utf8"
|
|
@@ -17872,7 +18048,7 @@ var init_archivist_record_entry = __esm({
|
|
|
17872
18048
|
import { randomUUID as randomUUID9 } from "node:crypto";
|
|
17873
18049
|
|
|
17874
18050
|
// src/role-runtime-dependencies.ts
|
|
17875
|
-
import { readFile as
|
|
18051
|
+
import { readFile as readFile22 } from "node:fs/promises";
|
|
17876
18052
|
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
17877
18053
|
|
|
17878
18054
|
// src/canonical-skill-binding.ts
|
|
@@ -18923,7 +19099,8 @@ ${helpContext}
|
|
|
18923
19099
|
|
|
18924
19100
|
// src/navigator-work-context.ts
|
|
18925
19101
|
init_doctor_evidence();
|
|
18926
|
-
|
|
19102
|
+
init_host_contracts();
|
|
19103
|
+
import { readFile as readFile20 } from "node:fs/promises";
|
|
18927
19104
|
import { resolve as resolve16 } from "node:path";
|
|
18928
19105
|
init_notary_source_run();
|
|
18929
19106
|
init_packaged_role_registry();
|
|
@@ -18936,7 +19113,7 @@ function navigatorInputReference(getFlag, role) {
|
|
|
18936
19113
|
}
|
|
18937
19114
|
async function loadNavigatorWorkContext(options) {
|
|
18938
19115
|
const reference = navigatorInputReference(options.getFlag, options.role);
|
|
18939
|
-
const input = reference === void 0 || options.role === "doctor" || options.role === "notary" ? void 0 : await
|
|
19116
|
+
const input = reference === void 0 || options.role === "doctor" || options.role === "notary" ? void 0 : await readFile20(reference, "utf8");
|
|
18940
19117
|
const subjectRoot = subjectPath(reference ?? options.context.sessionManager.getSessionDir(), options.context.cwd);
|
|
18941
19118
|
let subjectKey = reference === void 0 ? subjectRoot : navigatorSubjectKeyForInput(subjectRoot, reference, options.context.cwd);
|
|
18942
19119
|
let subject = input ?? `work subject: ${subjectKey}`;
|
|
@@ -18951,9 +19128,9 @@ async function loadNavigatorWorkContext(options) {
|
|
|
18951
19128
|
subject = JSON.stringify({ sourceRun: locator });
|
|
18952
19129
|
subjectProvenance = "role_input";
|
|
18953
19130
|
}
|
|
18954
|
-
const publicRunDir =
|
|
19131
|
+
const publicRunDir = runDirectoryFromHostContext(options.context);
|
|
18955
19132
|
const currentSessionDir = options.context.sessionManager.getSessionDir();
|
|
18956
|
-
const isBoundPublicRun =
|
|
19133
|
+
const isBoundPublicRun = publicRunDir !== void 0 && resolve16(currentSessionDir) === resolve16(publicRunDir, "session");
|
|
18957
19134
|
if (options.role === "judge" && isBoundPublicRun) {
|
|
18958
19135
|
let admitted;
|
|
18959
19136
|
try {
|
|
@@ -18993,7 +19170,7 @@ async function loadNavigatorWorkContext(options) {
|
|
|
18993
19170
|
let authorityMaterial;
|
|
18994
19171
|
for (const path of authorityFiles) {
|
|
18995
19172
|
try {
|
|
18996
|
-
const content = await
|
|
19173
|
+
const content = await readFile20(path, "utf8");
|
|
18997
19174
|
if (content.trim() !== "") {
|
|
18998
19175
|
authorityMaterial = content;
|
|
18999
19176
|
break;
|
|
@@ -19052,7 +19229,7 @@ init_sitian_facade();
|
|
|
19052
19229
|
init_submission_ledger();
|
|
19053
19230
|
init_collector_ledger();
|
|
19054
19231
|
import { readFileSync as readFileSync5, writeSync as writeSync4 } from "node:fs";
|
|
19055
|
-
import { join as
|
|
19232
|
+
import { join as join36 } from "node:path";
|
|
19056
19233
|
import { Value as Value4 } from "typebox/value";
|
|
19057
19234
|
|
|
19058
19235
|
// src/activation-trace.ts
|
|
@@ -19461,6 +19638,7 @@ function createToolExecutionObservationFace(options) {
|
|
|
19461
19638
|
|
|
19462
19639
|
// src/role-runtime.ts
|
|
19463
19640
|
init_engine_detour();
|
|
19641
|
+
init_engine_material();
|
|
19464
19642
|
|
|
19465
19643
|
// src/engine-detour-tool.ts
|
|
19466
19644
|
init_engine_detour();
|
|
@@ -19558,21 +19736,21 @@ init_collector_evidence();
|
|
|
19558
19736
|
init_collector_github();
|
|
19559
19737
|
|
|
19560
19738
|
// src/collector-handbook.ts
|
|
19561
|
-
import { readFile as
|
|
19562
|
-
import { join as
|
|
19739
|
+
import { readFile as readFile21 } from "node:fs/promises";
|
|
19740
|
+
import { join as join35, sep as sep4 } from "node:path";
|
|
19563
19741
|
|
|
19564
19742
|
// src/atomic-write.ts
|
|
19565
19743
|
import { randomUUID as randomUUID6 } from "node:crypto";
|
|
19566
|
-
import { rename as rename2, rm as
|
|
19567
|
-
import { dirname as dirname19, join as
|
|
19744
|
+
import { rename as rename2, rm as rm3, writeFile as writeFile10 } from "node:fs/promises";
|
|
19745
|
+
import { dirname as dirname19, join as join34 } from "node:path";
|
|
19568
19746
|
async function writeFileAtomically(destination, contents) {
|
|
19569
19747
|
const parent = dirname19(destination);
|
|
19570
|
-
const temporary =
|
|
19748
|
+
const temporary = join34(parent, `.atomic-write-${randomUUID6()}.tmp`);
|
|
19571
19749
|
try {
|
|
19572
|
-
await
|
|
19750
|
+
await writeFile10(temporary, contents);
|
|
19573
19751
|
await rename2(temporary, destination);
|
|
19574
19752
|
} catch (error) {
|
|
19575
|
-
await
|
|
19753
|
+
await rm3(temporary, { force: true }).catch(() => void 0);
|
|
19576
19754
|
throw error;
|
|
19577
19755
|
}
|
|
19578
19756
|
}
|
|
@@ -19693,7 +19871,7 @@ function resolveCollectorHandbookRoot(sessionPath) {
|
|
|
19693
19871
|
throw new Error(`\u901A\u8FDB\u53F8\u624B\u518C\u62D2\u7EDD\u4E0D\u5B89\u5168 bookKey ${JSON.stringify(bookKey)}`);
|
|
19694
19872
|
}
|
|
19695
19873
|
const ledgerHome = resolveActivationLedgerHomeForPath(sessionPath);
|
|
19696
|
-
const root =
|
|
19874
|
+
const root = join35(activationBookDirectory(ledgerHome, bookKey), "collector-handbook");
|
|
19697
19875
|
return { ledgerHome, bookKey, root };
|
|
19698
19876
|
}
|
|
19699
19877
|
function collectorHandbookRepoFileName(repositoryCanonical) {
|
|
@@ -19705,9 +19883,9 @@ function collectorHandbookRepoFileName(repositoryCanonical) {
|
|
|
19705
19883
|
return `${repositoryCanonical.replaceAll("/", "__")}.md`;
|
|
19706
19884
|
}
|
|
19707
19885
|
function createCollectorHandbookStore(input) {
|
|
19708
|
-
const generalPath =
|
|
19709
|
-
const repoDir =
|
|
19710
|
-
const repoPath =
|
|
19886
|
+
const generalPath = join35(input.handbookRoot, "general.md");
|
|
19887
|
+
const repoDir = join35(input.handbookRoot, "repos");
|
|
19888
|
+
const repoPath = join35(repoDir, collectorHandbookRepoFileName(input.repositoryCanonical));
|
|
19711
19889
|
const assertHandbookBudget = (body, label) => {
|
|
19712
19890
|
const byteLength = Buffer.byteLength(body, "utf8");
|
|
19713
19891
|
if (byteLength > COLLECTOR_HANDBOOK_MAX_BYTES) {
|
|
@@ -19721,7 +19899,7 @@ function createCollectorHandbookStore(input) {
|
|
|
19721
19899
|
ensureRealDirectoryTree(input.ledgerHome, parentDir2);
|
|
19722
19900
|
assertLedgerFileInsideHome(path, input.ledgerHome);
|
|
19723
19901
|
try {
|
|
19724
|
-
const body = await
|
|
19902
|
+
const body = await readFile21(path, "utf8");
|
|
19725
19903
|
assertHandbookBudget(body, "\u6B63\u6587");
|
|
19726
19904
|
return body;
|
|
19727
19905
|
} catch (error) {
|
|
@@ -20831,14 +21009,18 @@ function createJudgeRoleRuntime(pi, dependencies, hostActions) {
|
|
|
20831
21009
|
subject: { kind: "judge_draft" },
|
|
20832
21010
|
...signal === void 0 ? {} : { signal },
|
|
20833
21011
|
hostActions,
|
|
20834
|
-
toolCallId
|
|
21012
|
+
toolCallId,
|
|
21013
|
+
// #879: this-turn typed payload — identity-bound at submit site.
|
|
21014
|
+
submission: parameters
|
|
20835
21015
|
});
|
|
20836
21016
|
await pi.requireGatekeeperPass({
|
|
20837
21017
|
context: ctx,
|
|
20838
21018
|
subject: { kind: "judge_compliance" },
|
|
20839
21019
|
...signal === void 0 ? {} : { signal },
|
|
20840
21020
|
hostActions,
|
|
20841
|
-
toolCallId
|
|
21021
|
+
toolCallId,
|
|
21022
|
+
// #879: same parent payload for 审刑院; not recovered from session latest.
|
|
21023
|
+
submission: parameters
|
|
20842
21024
|
});
|
|
20843
21025
|
return {
|
|
20844
21026
|
content: [{ type: "text", text: JUDGE_ACCEPTED_TEXT }],
|
|
@@ -21349,7 +21531,9 @@ function createFixerRoleRuntime(pi, dependencies, hostActions) {
|
|
|
21349
21531
|
subject: { kind: "worker_completion" },
|
|
21350
21532
|
..._signal === void 0 ? {} : { signal: _signal },
|
|
21351
21533
|
hostActions,
|
|
21352
|
-
toolCallId
|
|
21534
|
+
toolCallId,
|
|
21535
|
+
// #879: this-turn typed payload — identity-bound at submit site.
|
|
21536
|
+
submission: output
|
|
21353
21537
|
});
|
|
21354
21538
|
}
|
|
21355
21539
|
const acceptedDetails = output;
|
|
@@ -21485,7 +21669,9 @@ function createCoderRoleRuntime(pi, dependencies, hostActions) {
|
|
|
21485
21669
|
subject: { kind: "worker_completion" },
|
|
21486
21670
|
..._signal === void 0 ? {} : { signal: _signal },
|
|
21487
21671
|
hostActions,
|
|
21488
|
-
toolCallId
|
|
21672
|
+
toolCallId,
|
|
21673
|
+
// #879: this-turn typed payload — identity-bound at submit site.
|
|
21674
|
+
submission: output
|
|
21489
21675
|
});
|
|
21490
21676
|
}
|
|
21491
21677
|
const acceptedDetails = output;
|
|
@@ -22020,12 +22206,12 @@ function readDiaristTicketAssertion(submitted) {
|
|
|
22020
22206
|
}
|
|
22021
22207
|
return { kind: "invalid" };
|
|
22022
22208
|
}
|
|
22023
|
-
function readDiaristRunCoordinates() {
|
|
22024
|
-
const runDirectory =
|
|
22025
|
-
if (
|
|
22209
|
+
function readDiaristRunCoordinates(ctx) {
|
|
22210
|
+
const runDirectory = runDirectoryFromHostContext(ctx);
|
|
22211
|
+
if (runDirectory === void 0) {
|
|
22026
22212
|
throw new Error("diarist accept requires AK_ROLE_RUN_DIR");
|
|
22027
22213
|
}
|
|
22028
|
-
const admittedPath =
|
|
22214
|
+
const admittedPath = join36(runDirectory, "admitted-request.json");
|
|
22029
22215
|
const admitted = JSON.parse(readFileSync5(admittedPath, "utf8"));
|
|
22030
22216
|
if (typeof admitted.projectRoot !== "string" || admitted.projectRoot.trim() === "") {
|
|
22031
22217
|
throw new Error(`diarist admitted-request missing projectRoot (${admittedPath})`);
|
|
@@ -22046,10 +22232,10 @@ function createDiaristRoleRuntime(roleHost, dependencies) {
|
|
|
22046
22232
|
tool: DIARIST_TOOL_SPEC,
|
|
22047
22233
|
acceptedText: DIARIST_ACCEPTED_TEXT,
|
|
22048
22234
|
soulTag: "diarist",
|
|
22049
|
-
beforeAccept: async ({ parameters }) => {
|
|
22235
|
+
beforeAccept: async ({ parameters, ctx }) => {
|
|
22050
22236
|
const submitted = parameters !== null && typeof parameters === "object" && !Array.isArray(parameters) ? parameters : void 0;
|
|
22051
22237
|
const assertion = readDiaristTicketAssertion(submitted);
|
|
22052
|
-
const coords = readDiaristRunCoordinates();
|
|
22238
|
+
const coords = readDiaristRunCoordinates(ctx);
|
|
22053
22239
|
const ticketNumber = assertion.kind === "ticket" ? assertion.ticketNumber : void 0;
|
|
22054
22240
|
if (ticketNumber !== void 0) {
|
|
22055
22241
|
if (coords.boundTicketNumber === void 0) {
|
|
@@ -22085,7 +22271,9 @@ function createCountersignRoleRuntime(roleHost, dependencies, hostActions) {
|
|
|
22085
22271
|
subject: { kind: "countersign_verdict" },
|
|
22086
22272
|
...signal === void 0 ? {} : { signal },
|
|
22087
22273
|
hostActions,
|
|
22088
|
-
toolCallId
|
|
22274
|
+
toolCallId,
|
|
22275
|
+
// #879: this-turn typed payload — identity-bound at submit site.
|
|
22276
|
+
submission: parameters
|
|
22089
22277
|
});
|
|
22090
22278
|
} : void 0;
|
|
22091
22279
|
return createFiledOfficerRuntime(
|
|
@@ -22118,6 +22306,10 @@ function createRoleRuntimeExtension(dependencies) {
|
|
|
22118
22306
|
for (const flag of NOTARY_TRANSPORT_FLAGS) {
|
|
22119
22307
|
roleHost.registerFlag(flag.name, flag.definition);
|
|
22120
22308
|
}
|
|
22309
|
+
roleHost.registerFlag(
|
|
22310
|
+
INSPECTOR_SOURCE_RUN_FLAG.name,
|
|
22311
|
+
INSPECTOR_SOURCE_RUN_FLAG.definition
|
|
22312
|
+
);
|
|
22121
22313
|
for (const flag of GLEANER_LEFT_TRANSPORT_FLAGS) {
|
|
22122
22314
|
roleHost.registerFlag(flag.name, flag.definition);
|
|
22123
22315
|
}
|
|
@@ -22125,6 +22317,11 @@ function createRoleRuntimeExtension(dependencies) {
|
|
|
22125
22317
|
roleHost.registerFlag(flag.name, flag.definition);
|
|
22126
22318
|
}
|
|
22127
22319
|
roleHost.registerFlag(STATION_CHILD_FLAG.name, STATION_CHILD_FLAG.definition);
|
|
22320
|
+
roleHost.registerFlag(ENGINE_MODEL_FLAG_NAME, {
|
|
22321
|
+
description: "\u672C\u6B21\u52B3\u52A1\u5F15\u64CE\u6A21\u578B",
|
|
22322
|
+
type: "string",
|
|
22323
|
+
default: ""
|
|
22324
|
+
});
|
|
22128
22325
|
let admitted = false;
|
|
22129
22326
|
let selectedRole;
|
|
22130
22327
|
let activeReviewerParent;
|
|
@@ -22209,19 +22406,21 @@ function createRoleRuntimeExtension(dependencies) {
|
|
|
22209
22406
|
settleNavigatorProjection
|
|
22210
22407
|
);
|
|
22211
22408
|
roleHost.on("input", (event) => {
|
|
22409
|
+
const text = event.text;
|
|
22212
22410
|
const role = roleHost.getFlag(ROLE_FLAG.name);
|
|
22213
22411
|
if (role !== void 0 && !admitted) return { action: "handled" };
|
|
22214
22412
|
if (role === "reviewer" && admitted && activeReviewerParent !== void 0 && reviewerOriginalRequest === void 0) {
|
|
22215
22413
|
reviewerOriginalRequest = roleHost.capabilities?.skillOriginalRequest?.(
|
|
22216
22414
|
activeReviewerParent.skillBinding.name,
|
|
22217
|
-
|
|
22218
|
-
) ??
|
|
22219
|
-
return { action: "continue" };
|
|
22415
|
+
text
|
|
22416
|
+
) ?? text;
|
|
22417
|
+
return text === event.text ? { action: "continue" } : { action: "transform", text };
|
|
22220
22418
|
}
|
|
22221
|
-
return { action: "continue" };
|
|
22419
|
+
return text === event.text ? { action: "continue" } : { action: "transform", text };
|
|
22222
22420
|
});
|
|
22223
22421
|
roleHost.on("before_agent_start", async (event, ctx) => {
|
|
22224
22422
|
const role = roleHost.getFlag(ROLE_FLAG.name);
|
|
22423
|
+
const prompt = event.prompt;
|
|
22225
22424
|
if (role === void 0) return;
|
|
22226
22425
|
if (!admitted || selectedRole !== role) {
|
|
22227
22426
|
failInfrastructure(new ActivationBarrierError(role), ctx);
|
|
@@ -22234,7 +22433,7 @@ function createRoleRuntimeExtension(dependencies) {
|
|
|
22234
22433
|
}
|
|
22235
22434
|
if (navigatorAttendance !== void 0 && navigatorWorkContext !== void 0 && navigatorWorkContext.contextError === void 0) {
|
|
22236
22435
|
if (navigatorWorkContext.subjectProvenance === "placeholder") {
|
|
22237
|
-
const subject =
|
|
22436
|
+
const subject = prompt.trim();
|
|
22238
22437
|
if (subject !== "") {
|
|
22239
22438
|
const root = subjectPath(ctx.sessionManager.getSessionDir(), ctx.cwd);
|
|
22240
22439
|
const subjectProvenance = "user_prompt";
|
|
@@ -22255,7 +22454,7 @@ function createRoleRuntimeExtension(dependencies) {
|
|
|
22255
22454
|
if (!reviewerExpansionCaptured) {
|
|
22256
22455
|
if (reviewerOriginalRequest !== void 0) {
|
|
22257
22456
|
activeReviewerParent.skillBinding.captureExpansion(
|
|
22258
|
-
roleHost.capabilities?.skillExpansion(
|
|
22457
|
+
roleHost.capabilities?.skillExpansion(prompt),
|
|
22259
22458
|
reviewerOriginalRequest
|
|
22260
22459
|
);
|
|
22261
22460
|
}
|
|
@@ -22278,6 +22477,46 @@ function createRoleRuntimeExtension(dependencies) {
|
|
|
22278
22477
|
};
|
|
22279
22478
|
}
|
|
22280
22479
|
});
|
|
22480
|
+
roleHost.on("before_agent_start", () => {
|
|
22481
|
+
const role = selectedRole ?? roleHost.getFlag(ROLE_FLAG.name);
|
|
22482
|
+
if (typeof role !== "string" || !isOfficerReviewSeat(role)) return;
|
|
22483
|
+
if (roleHost.getFlag(STATION_CHILD_FLAG.name) !== true) return;
|
|
22484
|
+
const engine = resolveEngineName((name) => roleHost.getFlag(name));
|
|
22485
|
+
if (engine === void 0 || dependencies.packageRoot === void 0) return;
|
|
22486
|
+
const engineModel = resolveEngineModel((name) => roleHost.getFlag(name));
|
|
22487
|
+
const material = engineSessionMaterialFromOptions({
|
|
22488
|
+
engine,
|
|
22489
|
+
...engineModel === void 0 ? {} : { engineModel },
|
|
22490
|
+
packageRoot: dependencies.packageRoot
|
|
22491
|
+
});
|
|
22492
|
+
if (material === void 0) return;
|
|
22493
|
+
return {
|
|
22494
|
+
readingMaterial: {
|
|
22495
|
+
kind: "engine-session-material",
|
|
22496
|
+
name: material.name,
|
|
22497
|
+
...material.model === void 0 ? {} : { model: material.model },
|
|
22498
|
+
...material.materialPath === void 0 ? {} : { materialPath: material.materialPath }
|
|
22499
|
+
}
|
|
22500
|
+
};
|
|
22501
|
+
});
|
|
22502
|
+
roleHost.on("before_agent_start", () => {
|
|
22503
|
+
const path = roleHost.getFlag(INSPECTOR_SOURCE_RUN_FLAG.name);
|
|
22504
|
+
if (typeof path !== "string" || path.trim() === "") return;
|
|
22505
|
+
return {
|
|
22506
|
+
readingMaterial: {
|
|
22507
|
+
kind: "inspector-parent-binding",
|
|
22508
|
+
sourceRunPath: path
|
|
22509
|
+
}
|
|
22510
|
+
};
|
|
22511
|
+
});
|
|
22512
|
+
roleHost.on("before_agent_start", async (_event, ctx) => {
|
|
22513
|
+
const runDir = runDirectoryFromHostContext(ctx);
|
|
22514
|
+
if (runDir === void 0) return;
|
|
22515
|
+
const { loadCaseDossierReadingMaterial: loadCaseDossierReadingMaterial2 } = await Promise.resolve().then(() => (init_case_dossier_delivery(), case_dossier_delivery_exports));
|
|
22516
|
+
const caseDossier = await loadCaseDossierReadingMaterial2(runDir);
|
|
22517
|
+
if (caseDossier === void 0) return;
|
|
22518
|
+
return { readingMaterial: caseDossier };
|
|
22519
|
+
});
|
|
22281
22520
|
roleHost.on("tool_result", async (event) => {
|
|
22282
22521
|
const role = selectedRole;
|
|
22283
22522
|
if (role === void 0) return;
|
|
@@ -22338,7 +22577,7 @@ function createRoleRuntimeExtension(dependencies) {
|
|
|
22338
22577
|
display: false
|
|
22339
22578
|
}, { triggerTurn: true, deliverAs: "followUp" });
|
|
22340
22579
|
} else if (receiptDelivery.nextAction() === "no-receipt" && !noReceiptRecorded) {
|
|
22341
|
-
const runPointer =
|
|
22580
|
+
const runPointer = runDirectoryFromHostContext(ctx);
|
|
22342
22581
|
if (runPointer !== void 0) {
|
|
22343
22582
|
noReceiptRecorded = true;
|
|
22344
22583
|
const facts = receiptDelivery.facts({ runPointer, attemptPointer: `current:${runPointer}` });
|
|
@@ -22700,8 +22939,8 @@ function createRoleRuntimeExtension(dependencies) {
|
|
|
22700
22939
|
await observe(() => observationFace.onEnd(event), ctx);
|
|
22701
22940
|
});
|
|
22702
22941
|
const recordHttpObservation = async (status, provider, ctx) => {
|
|
22703
|
-
const runDir =
|
|
22704
|
-
if (
|
|
22942
|
+
const runDir = runDirectoryFromHostContext(ctx);
|
|
22943
|
+
if (runDir === void 0) return;
|
|
22705
22944
|
try {
|
|
22706
22945
|
await recordTypedProviderHttpStatus(runDir, { httpStatus: status, provider });
|
|
22707
22946
|
} catch (error) {
|
|
@@ -22724,8 +22963,8 @@ function createRoleRuntimeExtension(dependencies) {
|
|
|
22724
22963
|
const underlying = priorFetch;
|
|
22725
22964
|
globalThis.fetch = (async (input, init) => {
|
|
22726
22965
|
const response = await underlying(input, init);
|
|
22727
|
-
const runDir =
|
|
22728
|
-
if (
|
|
22966
|
+
const runDir = runDirectoryFromHostContext(ctx);
|
|
22967
|
+
if (runDir !== void 0 && typeof response?.status === "number" && (response.status < 200 || response.status >= 300)) {
|
|
22729
22968
|
const provider = typeof ctx.model?.provider === "string" && ctx.model.provider.trim() !== "" ? ctx.model.provider : "unknown";
|
|
22730
22969
|
try {
|
|
22731
22970
|
await recordTypedProviderHttpStatus(runDir, {
|
|
@@ -22911,15 +23150,16 @@ function createRoleRuntimeDependencies(packageRoot) {
|
|
|
22911
23150
|
const doctorAuditor = createPiDoctorAuditor();
|
|
22912
23151
|
const navigatorSessionFactory = createNativeNavigatorSessionFactory();
|
|
22913
23152
|
return {
|
|
23153
|
+
packageRoot,
|
|
22914
23154
|
loadJudgeSoul: () => loadMainRoleSessionMaterials("judge"),
|
|
22915
23155
|
loadFixerSoul: () => loadMainRoleSessionMaterials("fixer"),
|
|
22916
|
-
loadFixPacket: (path) =>
|
|
23156
|
+
loadFixPacket: (path) => readFile22(path, "utf8"),
|
|
22917
23157
|
loadCoderSoul: () => loadMainRoleSessionMaterials("coder"),
|
|
22918
|
-
loadCoderTask: (path) =>
|
|
23158
|
+
loadCoderTask: (path) => readFile22(path, "utf8"),
|
|
22919
23159
|
loadReviewerSoul: () => loadMainRoleSessionMaterials("reviewer"),
|
|
22920
23160
|
createReviewerPinnedGitReader: () => createReviewerPinnedGitReader(),
|
|
22921
23161
|
loadCollectorSoul: () => loadMainRoleSessionMaterials("collector"),
|
|
22922
|
-
loadCollectorHandbookSeed: () =>
|
|
23162
|
+
loadCollectorHandbookSeed: () => readFile22(collectorHandbookSeedPath, "utf8"),
|
|
22923
23163
|
createCollectorTransport: () => createGhCollectorGitHubTransport(),
|
|
22924
23164
|
loadDoctorSoul: () => loadMainRoleSessionMaterials("doctor"),
|
|
22925
23165
|
loadDoctorCase,
|
|
@@ -22933,7 +23173,7 @@ function createRoleRuntimeDependencies(packageRoot) {
|
|
|
22933
23173
|
loadDiaristSoul: () => loadMainRoleSessionMaterials("diarist"),
|
|
22934
23174
|
loadNotarySourceRun: loadNotarySourceRunLocator,
|
|
22935
23175
|
loadMergerSoul: () => loadMainRoleSessionMaterials("merger"),
|
|
22936
|
-
loadMergerInput: async (path) => JSON.parse(await
|
|
23176
|
+
loadMergerInput: async (path) => JSON.parse(await readFile22(path, "utf8")),
|
|
22937
23177
|
async loadCanonicalSkillBinding(name) {
|
|
22938
23178
|
if (name === "tdd") {
|
|
22939
23179
|
return loadPackagedCanonicalSkillBinding(packageRoot, "tdd");
|
|
@@ -22959,7 +23199,7 @@ function createRoleRuntimeDependencies(packageRoot) {
|
|
|
22959
23199
|
authority: options.authority,
|
|
22960
23200
|
invocationId: options.invocationId,
|
|
22961
23201
|
loadSoul: () => loadMainRoleSessionMaterials("navigator"),
|
|
22962
|
-
loadRoutePlaybook: () =>
|
|
23202
|
+
loadRoutePlaybook: () => readFile22(navigatorRoutePlaybookPath, "utf8"),
|
|
22963
23203
|
loadRoleHelp: async (role) => formatNavigatorRoleHelp(role),
|
|
22964
23204
|
createSession: navigatorSessionFactory,
|
|
22965
23205
|
...options.contextError === void 0 ? {} : { contextError: options.contextError },
|
|
@@ -22971,9 +23211,9 @@ function createRoleRuntimeDependencies(packageRoot) {
|
|
|
22971
23211
|
// src/role-envelope.ts
|
|
22972
23212
|
init_engine_detour();
|
|
22973
23213
|
import { randomUUID as randomUUID7 } from "node:crypto";
|
|
22974
|
-
import { mkdir as mkdir6, readFile as
|
|
23214
|
+
import { mkdir as mkdir6, readFile as readFile23, writeFile as writeFile11 } from "node:fs/promises";
|
|
22975
23215
|
import { createServer } from "node:net";
|
|
22976
|
-
import { basename as basename8, dirname as dirname20, join as
|
|
23216
|
+
import { basename as basename8, dirname as dirname20, join as join37 } from "node:path";
|
|
22977
23217
|
import { fileURLToPath as fileURLToPath3 } from "node:url";
|
|
22978
23218
|
|
|
22979
23219
|
// src/gatekeeper-pass-envelope.ts
|
|
@@ -23005,6 +23245,7 @@ async function requireGatekeeperPass(options) {
|
|
|
23005
23245
|
subject: options.subject,
|
|
23006
23246
|
...options.signal === void 0 ? {} : { signal: options.signal },
|
|
23007
23247
|
...options.summonOfficer === void 0 ? {} : { summonOfficer: options.summonOfficer },
|
|
23248
|
+
...options.submission === void 0 ? {} : { submission: options.submission },
|
|
23008
23249
|
...reask === void 0 ? {} : { reask }
|
|
23009
23250
|
});
|
|
23010
23251
|
const gatekeeper = projected.result;
|
|
@@ -23100,14 +23341,14 @@ async function prepareRoleEnvelope(options) {
|
|
|
23100
23341
|
for (const method of request.methods) {
|
|
23101
23342
|
if (method.kind !== "skill") continue;
|
|
23102
23343
|
const name = basename8(dirname20(method.path));
|
|
23103
|
-
const raw = await
|
|
23344
|
+
const raw = await readFile23(method.path, "utf8");
|
|
23104
23345
|
methodSkills.set(name, { path: method.path, body: stripSkillFrontmatter(raw).trim() });
|
|
23105
23346
|
}
|
|
23106
|
-
let sessionFile = options.sessionFile ??
|
|
23347
|
+
let sessionFile = options.sessionFile ?? join37(request.runDirectory, "session", "session.jsonl");
|
|
23107
23348
|
await mkdir6(dirname20(sessionFile), { recursive: true });
|
|
23108
23349
|
if (request.continuation.kind !== "resume") {
|
|
23109
23350
|
try {
|
|
23110
|
-
await
|
|
23351
|
+
await writeFile11(
|
|
23111
23352
|
sessionFile,
|
|
23112
23353
|
`${JSON.stringify({
|
|
23113
23354
|
type: "session",
|
|
@@ -23127,6 +23368,8 @@ async function prepareRoleEnvelope(options) {
|
|
|
23127
23368
|
cwd: request.cwd,
|
|
23128
23369
|
mode: "print",
|
|
23129
23370
|
model: request.model === void 0 ? void 0 : { provider: request.model.provider },
|
|
23371
|
+
runDirectory: request.runDirectory,
|
|
23372
|
+
...request.courtAttemptId === void 0 ? {} : { courtAttemptId: request.courtAttemptId },
|
|
23130
23373
|
sessionManager: {
|
|
23131
23374
|
getLeafEntry: () => sessionEntries.at(-1),
|
|
23132
23375
|
getLeafId: () => runId,
|
|
@@ -23201,7 +23444,8 @@ async function prepareRoleEnvelope(options) {
|
|
|
23201
23444
|
failInfrastructure: (error, _context, toolCallId) => options2.hostActions.failInfrastructure(error, options2.context, toolCallId),
|
|
23202
23445
|
bindSubmissionNonPass: options2.hostActions.bindSubmissionNonPass
|
|
23203
23446
|
},
|
|
23204
|
-
toolCallId: options2.toolCallId
|
|
23447
|
+
toolCallId: options2.toolCallId,
|
|
23448
|
+
...options2.submission === void 0 ? {} : { submission: options2.submission }
|
|
23205
23449
|
});
|
|
23206
23450
|
},
|
|
23207
23451
|
on(...registration) {
|
|
@@ -23428,17 +23672,6 @@ async function prepareRoleEnvelope(options) {
|
|
|
23428
23672
|
const relay = fileURLToPath3(new URL("./mcp-relay.mjs", import.meta.url));
|
|
23429
23673
|
await listen(server, options.socketPath);
|
|
23430
23674
|
let disposed = false;
|
|
23431
|
-
let priorAkRoleRunDir;
|
|
23432
|
-
let priorAkRoleCourtAttempt;
|
|
23433
|
-
let runDirInjected = false;
|
|
23434
|
-
const restoreAkRoleRunEnv = () => {
|
|
23435
|
-
if (!runDirInjected) return;
|
|
23436
|
-
runDirInjected = false;
|
|
23437
|
-
if (priorAkRoleRunDir === void 0) delete process.env.AK_ROLE_RUN_DIR;
|
|
23438
|
-
else process.env.AK_ROLE_RUN_DIR = priorAkRoleRunDir;
|
|
23439
|
-
if (priorAkRoleCourtAttempt === void 0) delete process.env.AK_ROLE_COURT_ATTEMPT;
|
|
23440
|
-
else process.env.AK_ROLE_COURT_ATTEMPT = priorAkRoleCourtAttempt;
|
|
23441
|
-
};
|
|
23442
23675
|
const dispose = async () => {
|
|
23443
23676
|
if (disposed) return;
|
|
23444
23677
|
disposed = true;
|
|
@@ -23448,11 +23681,6 @@ async function prepareRoleEnvelope(options) {
|
|
|
23448
23681
|
} catch (error) {
|
|
23449
23682
|
cleanupFailures.push(error);
|
|
23450
23683
|
}
|
|
23451
|
-
try {
|
|
23452
|
-
restoreAkRoleRunEnv();
|
|
23453
|
-
} catch (error) {
|
|
23454
|
-
cleanupFailures.push(error);
|
|
23455
|
-
}
|
|
23456
23684
|
try {
|
|
23457
23685
|
const closeAll = server.closeAllConnections;
|
|
23458
23686
|
if (typeof closeAll === "function") closeAll.call(server);
|
|
@@ -23521,7 +23749,7 @@ async function prepareRoleEnvelope(options) {
|
|
|
23521
23749
|
message: { role: "user", content: prompt }
|
|
23522
23750
|
});
|
|
23523
23751
|
}
|
|
23524
|
-
const methodPrompt = (await Promise.all(request.methods.map(({ path }) =>
|
|
23752
|
+
const methodPrompt = (await Promise.all(request.methods.map(({ path }) => readFile23(path, "utf8")))).join("\n\n");
|
|
23525
23753
|
const promptResults = await emit("before_agent_start", {
|
|
23526
23754
|
prompt,
|
|
23527
23755
|
systemPrompt: methodPrompt,
|
|
@@ -23540,12 +23768,6 @@ async function prepareRoleEnvelope(options) {
|
|
|
23540
23768
|
const material = value.readingMaterial;
|
|
23541
23769
|
if (material !== void 0) readingMaterials.push(material);
|
|
23542
23770
|
}
|
|
23543
|
-
priorAkRoleRunDir = process.env.AK_ROLE_RUN_DIR;
|
|
23544
|
-
priorAkRoleCourtAttempt = process.env.AK_ROLE_COURT_ATTEMPT;
|
|
23545
|
-
process.env.AK_ROLE_RUN_DIR = request.runDirectory;
|
|
23546
|
-
if (request.courtAttemptId === void 0) delete process.env.AK_ROLE_COURT_ATTEMPT;
|
|
23547
|
-
else process.env.AK_ROLE_COURT_ATTEMPT = request.courtAttemptId;
|
|
23548
|
-
runDirInjected = true;
|
|
23549
23771
|
const terminating = tools.get(terminatingToolName);
|
|
23550
23772
|
if (terminating === void 0) {
|
|
23551
23773
|
throw new Error(`terminating tool not registered after activation: ${terminatingToolName}`);
|
|
@@ -23588,7 +23810,7 @@ async function prepareRoleEnvelope(options) {
|
|
|
23588
23810
|
init_session_identity();
|
|
23589
23811
|
|
|
23590
23812
|
// src/headless-host/description.ts
|
|
23591
|
-
import { join as
|
|
23813
|
+
import { join as join38 } from "node:path";
|
|
23592
23814
|
function isClaudePrintDescription(description) {
|
|
23593
23815
|
return description.protocol === "claude-print";
|
|
23594
23816
|
}
|
|
@@ -23596,13 +23818,12 @@ function isCodexExecDescription(description) {
|
|
|
23596
23818
|
return description.protocol === "codex-exec";
|
|
23597
23819
|
}
|
|
23598
23820
|
function resolveHeadlessBinary(description, operatorHome) {
|
|
23599
|
-
return
|
|
23821
|
+
return join38(operatorHome, ...description.binaryFromHome);
|
|
23600
23822
|
}
|
|
23601
23823
|
function headlessTurnArgs(options) {
|
|
23602
23824
|
const { description } = options;
|
|
23603
23825
|
const args = [
|
|
23604
23826
|
description.promptFlag,
|
|
23605
|
-
options.prompt,
|
|
23606
23827
|
...description.fixedArgs,
|
|
23607
23828
|
description.systemPromptFlag,
|
|
23608
23829
|
options.systemPromptPath,
|
|
@@ -23830,7 +24051,7 @@ function codexTurnArgs(options) {
|
|
|
23830
24051
|
if (options.skipGitRepoCheck === true) {
|
|
23831
24052
|
args.push("--skip-git-repo-check");
|
|
23832
24053
|
}
|
|
23833
|
-
args.push("--",
|
|
24054
|
+
args.push("--", "-");
|
|
23834
24055
|
return args;
|
|
23835
24056
|
}
|
|
23836
24057
|
function headlessMcpConfigDocument(mcpServers) {
|
|
@@ -23852,10 +24073,11 @@ function headlessMcpConfigDocument(mcpServers) {
|
|
|
23852
24073
|
import { spawn as spawn4, spawnSync } from "node:child_process";
|
|
23853
24074
|
import { randomUUID as randomUUID8 } from "node:crypto";
|
|
23854
24075
|
import { existsSync as existsSync12 } from "node:fs";
|
|
23855
|
-
import { writeFile as
|
|
23856
|
-
import { dirname as dirname21, isAbsolute as isAbsolute11, join as
|
|
24076
|
+
import { writeFile as writeFile12 } from "node:fs/promises";
|
|
24077
|
+
import { dirname as dirname21, isAbsolute as isAbsolute11, join as join39, resolve as resolve20 } from "node:path";
|
|
23857
24078
|
|
|
23858
24079
|
// src/external-host-turn-loop.ts
|
|
24080
|
+
init_host_contracts();
|
|
23859
24081
|
var EXTERNAL_ROLE_TURN_ROUND_LIMIT = 8;
|
|
23860
24082
|
function mergeRoleTurnAbortSignals(prepared, request) {
|
|
23861
24083
|
if (request === void 0) return prepared;
|
|
@@ -23864,6 +24086,9 @@ function mergeRoleTurnAbortSignals(prepared, request) {
|
|
|
23864
24086
|
}
|
|
23865
24087
|
function promptWithPriorNativePaths(basePrompt, request) {
|
|
23866
24088
|
if (request.continuation.kind !== "resume") return basePrompt;
|
|
24089
|
+
if (request.stationChild === true && isOfficerReviewSeat(request.activation.role)) {
|
|
24090
|
+
return basePrompt;
|
|
24091
|
+
}
|
|
23867
24092
|
const paths = request.hostTransition?.priorNativePaths;
|
|
23868
24093
|
if (paths === void 0 || paths.length === 0) return basePrompt;
|
|
23869
24094
|
return `${basePrompt}
|
|
@@ -24068,7 +24293,7 @@ function formatCodexFailurePayload(payload) {
|
|
|
24068
24293
|
function cwdIsGitWorkTree(cwd) {
|
|
24069
24294
|
let dir = cwd;
|
|
24070
24295
|
for (; ; ) {
|
|
24071
|
-
if (existsSync12(
|
|
24296
|
+
if (existsSync12(join39(dir, ".git"))) return true;
|
|
24072
24297
|
const parent = dirname21(dir);
|
|
24073
24298
|
if (parent === dir) return false;
|
|
24074
24299
|
dir = parent;
|
|
@@ -24108,8 +24333,20 @@ function spawnHeadlessTurn(options) {
|
|
|
24108
24333
|
const child = spawn4(options.binary, [...options.args], {
|
|
24109
24334
|
cwd: options.cwd,
|
|
24110
24335
|
env: options.env,
|
|
24111
|
-
stdio: ["
|
|
24336
|
+
stdio: ["pipe", "pipe", "pipe"]
|
|
24112
24337
|
});
|
|
24338
|
+
if (child.stdin === null) {
|
|
24339
|
+
reject(new Error("headless child stdin pipe was not created"));
|
|
24340
|
+
return;
|
|
24341
|
+
}
|
|
24342
|
+
let stdinDeliveryError;
|
|
24343
|
+
child.stdin.on("error", (error) => {
|
|
24344
|
+
stdinDeliveryError ??= error;
|
|
24345
|
+
});
|
|
24346
|
+
if (options.stdin !== void 0) {
|
|
24347
|
+
child.stdin.write(options.stdin);
|
|
24348
|
+
}
|
|
24349
|
+
child.stdin.end();
|
|
24113
24350
|
let resultStdout = "";
|
|
24114
24351
|
let stderr = "";
|
|
24115
24352
|
let lineBuffer = "";
|
|
@@ -24159,6 +24396,10 @@ function spawnHeadlessTurn(options) {
|
|
|
24159
24396
|
settled = true;
|
|
24160
24397
|
if (timer !== void 0) clearTimeout(timer);
|
|
24161
24398
|
options.signal?.removeEventListener("abort", onAbort);
|
|
24399
|
+
if (stdinDeliveryError !== void 0) {
|
|
24400
|
+
reject(stdinDeliveryError);
|
|
24401
|
+
return;
|
|
24402
|
+
}
|
|
24162
24403
|
resolve21({ code, stdout: resultStdout, stderr, timedOut });
|
|
24163
24404
|
};
|
|
24164
24405
|
const onAbort = () => {
|
|
@@ -24222,7 +24463,6 @@ function buildTurnArgs(options) {
|
|
|
24222
24463
|
}
|
|
24223
24464
|
if (options.outputSchemaPath === void 0) throw new Error("codex requires an output schema path");
|
|
24224
24465
|
return codexTurnArgs({
|
|
24225
|
-
prompt: options.prompt,
|
|
24226
24466
|
systemPromptPath: options.systemPromptPath,
|
|
24227
24467
|
outputSchemaPath: options.outputSchemaPath,
|
|
24228
24468
|
mcpServers: options.mcpServers,
|
|
@@ -24238,7 +24478,6 @@ function buildTurnArgs(options) {
|
|
|
24238
24478
|
if (options.mcpConfigPath === void 0) throw new Error("claude print-mode requires an MCP config path");
|
|
24239
24479
|
return headlessTurnArgs({
|
|
24240
24480
|
description: options.description,
|
|
24241
|
-
prompt: options.prompt,
|
|
24242
24481
|
systemPromptPath: options.systemPromptPath,
|
|
24243
24482
|
jsonSchema: options.jsonSchema,
|
|
24244
24483
|
mcpConfigPath: options.mcpConfigPath,
|
|
@@ -24261,18 +24500,18 @@ function createHeadlessRoleTurnHost(config) {
|
|
|
24261
24500
|
await config.sessionIdentity.bind(request.principal, sessionId);
|
|
24262
24501
|
}
|
|
24263
24502
|
const env = { ...process.env, ...config.env ?? {} };
|
|
24264
|
-
const systemPromptPath =
|
|
24265
|
-
await
|
|
24503
|
+
const systemPromptPath = join39(request.runDirectory, "headless-system-prompt.txt");
|
|
24504
|
+
await writeFile12(systemPromptPath, systemPrompt, "utf8");
|
|
24266
24505
|
let mcpConfigPath;
|
|
24267
24506
|
let outputSchemaPath;
|
|
24268
24507
|
if (codex) {
|
|
24269
|
-
outputSchemaPath =
|
|
24508
|
+
outputSchemaPath = join39(request.runDirectory, "headless-output-schema.json");
|
|
24270
24509
|
const closed = closeJsonSchemaForCodex(prepared.jsonSchema);
|
|
24271
|
-
await
|
|
24510
|
+
await writeFile12(outputSchemaPath, `${JSON.stringify(closed, null, 2)}
|
|
24272
24511
|
`, "utf8");
|
|
24273
24512
|
} else {
|
|
24274
|
-
mcpConfigPath =
|
|
24275
|
-
await
|
|
24513
|
+
mcpConfigPath = join39(request.runDirectory, "headless-mcp-config.json");
|
|
24514
|
+
await writeFile12(
|
|
24276
24515
|
mcpConfigPath,
|
|
24277
24516
|
`${JSON.stringify(headlessMcpConfigDocument(prepared.mcpServers), null, 2)}
|
|
24278
24517
|
`,
|
|
@@ -24292,7 +24531,6 @@ function createHeadlessRoleTurnHost(config) {
|
|
|
24292
24531
|
const gitCommonDir = codex ? resolveGitCommonDir(request.cwd) : void 0;
|
|
24293
24532
|
args = buildTurnArgs({
|
|
24294
24533
|
description: config.description,
|
|
24295
|
-
prompt,
|
|
24296
24534
|
systemPromptPath,
|
|
24297
24535
|
jsonSchema: prepared.jsonSchema,
|
|
24298
24536
|
mcpServers: prepared.mcpServers,
|
|
@@ -24320,6 +24558,7 @@ function createHeadlessRoleTurnHost(config) {
|
|
|
24320
24558
|
args,
|
|
24321
24559
|
cwd: request.cwd,
|
|
24322
24560
|
env,
|
|
24561
|
+
stdin: prompt,
|
|
24323
24562
|
...abortSignal === void 0 ? {} : { signal: abortSignal },
|
|
24324
24563
|
...request.timeoutMs === void 0 ? {} : { timeoutMs: request.timeoutMs },
|
|
24325
24564
|
onStdoutLine(line2) {
|