@akagilnc/pi-workflow-roles 0.1.3682 → 0.1.3700

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.
Files changed (60) hide show
  1. package/dist/acp-host/production-host.js +519 -561
  2. package/dist/analyst-gate-cycles-read.js +11 -1
  3. package/dist/archivist-record-entry.js +1 -1
  4. package/dist/audit-escalation.js +4 -3
  5. package/dist/auditor-dossier-tool.js +12 -0
  6. package/dist/doctor-role.js +2 -1
  7. package/dist/dossier-resolution.js +0 -35
  8. package/dist/gatekeeper-pass-envelope.js +39 -34
  9. package/dist/gatekeeper-role.js +70 -76
  10. package/dist/judge-auditor.js +5 -24
  11. package/dist/judge-role.js +39 -41
  12. package/dist/notary-contracts.js +2 -17
  13. package/dist/notary-role.js +3 -6
  14. package/dist/package-contracts/judge-output.js +0 -2
  15. package/dist/package-contracts/terminating-tools.js +2 -2
  16. package/dist/public-cli/inspector-run.js +16 -2
  17. package/dist/public-cli/instruction-seat-run.js +14 -2
  18. package/dist/public-cli/main.js +198 -213
  19. package/dist/public-cli/notary-run.js +23 -20
  20. package/dist/public-cli/post-admission.js +30 -23
  21. package/dist/public-cli/run-lifecycle.js +6 -14
  22. package/dist/public-role-summons.js +38 -11
  23. package/dist/readable-gate-item.js +16 -0
  24. package/dist/role-runtime.js +28 -3
  25. package/dist/submission-correctable-error.js +2 -1
  26. package/dist/submission-errors.js +26 -8
  27. package/dist/submission-ledger.js +7 -23
  28. package/extensions/role-runtime.ts +0 -2
  29. package/package.json +1 -1
  30. package/souls/countersign.md +3 -1
  31. package/souls/notary.md +5 -0
  32. package/src/acp-host/production-host.ts +1 -4
  33. package/src/acp-host/role-envelope.ts +1 -1
  34. package/src/analyst-gate-cycles-read.ts +10 -1
  35. package/src/archivist-record-entry.ts +7 -3
  36. package/src/audit-escalation.ts +4 -3
  37. package/src/auditor-dossier-tool.ts +21 -0
  38. package/src/doctor-role.ts +2 -1
  39. package/src/dossier-resolution.ts +0 -39
  40. package/src/gatekeeper-pass-envelope.ts +59 -43
  41. package/src/gatekeeper-role.ts +114 -112
  42. package/src/host-contracts.ts +3 -3
  43. package/src/judge-auditor.ts +5 -43
  44. package/src/judge-role.ts +41 -53
  45. package/src/notary-contracts.ts +8 -27
  46. package/src/notary-role.ts +2 -7
  47. package/src/package-contracts/judge-output.ts +0 -1
  48. package/src/package-contracts/terminating-tools.ts +2 -2
  49. package/src/public-cli/inspector-run.ts +32 -2
  50. package/src/public-cli/instruction-seat-run.ts +30 -2
  51. package/src/public-cli/notary-run.ts +48 -16
  52. package/src/public-cli/post-admission.ts +31 -37
  53. package/src/public-cli/run-lifecycle.ts +6 -17
  54. package/src/public-role-summons.ts +76 -12
  55. package/src/readable-gate-item.ts +20 -0
  56. package/src/role-runtime.ts +34 -9
  57. package/src/submission-correctable-error.ts +2 -0
  58. package/src/submission-errors.ts +28 -8
  59. package/src/submission-ledger.ts +8 -32
  60. package/dist/shape-unreadable-failure.js +0 -34
@@ -508,6 +508,7 @@ __export(auditor_dossier_tool_exports, {
508
508
  AUDITOR_DOSSIER_TOOL_NAME: () => AUDITOR_DOSSIER_TOOL_NAME,
509
509
  GATE_SUBMISSION_CANDIDATE_FILE: () => GATE_SUBMISSION_CANDIDATE_FILE,
510
510
  auditorRunDirectory: () => auditorRunDirectory,
511
+ buildGateOfficerReviewInstruction: () => buildGateOfficerReviewInstruction,
511
512
  createAuditorDossierTool: () => createAuditorDossierTool,
512
513
  gateSubmissionCandidatePath: () => gateSubmissionCandidatePath,
513
514
  persistGateSubmissionCandidate: () => persistGateSubmissionCandidate,
@@ -542,6 +543,17 @@ function readLatestToolCallLeaf(context) {
542
543
  function gateSubmissionCandidatePath(runDirectory) {
543
544
  return join(runDirectory, "artifacts", GATE_SUBMISSION_CANDIDATE_FILE);
544
545
  }
546
+ function buildGateOfficerReviewInstruction(input) {
547
+ const lines = [
548
+ "\u672C\u8F6E\u7236\u5E2D\u4EA4\u5377\u5F85\u5BA1\u3002",
549
+ `\u6765\u6E90 run\uFF1A${input.sourceRunDirectory}`
550
+ ];
551
+ const candidate = input.submissionCandidatePath?.trim();
552
+ if (candidate !== void 0 && candidate.length > 0) {
553
+ lines.push(`\u4EA4\u5377\u5019\u9009\uFF08\u51BB\u7ED3\u5FEB\u7167\uFF09\uFF1A${candidate}`);
554
+ }
555
+ return lines.join("\n");
556
+ }
545
557
  function persistGateSubmissionCandidate(runDirectory, context) {
546
558
  const leaf = readLatestToolCallLeaf(context);
547
559
  if (leaf === void 0) return void 0;
@@ -2122,13 +2134,12 @@ function validateAcceptedJudgeDetails(verdict) {
2122
2134
  }
2123
2135
  throw new Error("Judge verdict has no execution discriminator");
2124
2136
  }
2125
- var JUDGE_OUTPUT_TOOL_NAME, JUDGE_ACCEPTED_TEXT, JUDGE_ACCEPTED_AUDIT_NO_RECEIPT_TEXT;
2137
+ var JUDGE_OUTPUT_TOOL_NAME, JUDGE_ACCEPTED_TEXT;
2126
2138
  var init_judge_output = __esm({
2127
2139
  "src/package-contracts/judge-output.ts"() {
2128
2140
  "use strict";
2129
2141
  JUDGE_OUTPUT_TOOL_NAME = "ak_judge_output";
2130
2142
  JUDGE_ACCEPTED_TEXT = "\u5927\u7406\u5BFA\u56DE\u6267\u5DF2\u63A5\u53D7";
2131
- JUDGE_ACCEPTED_AUDIT_NO_RECEIPT_TEXT = "\u5927\u7406\u5BFA\u56DE\u6267\u5DF2\u63A5\u53D7\uFF1B\u5BA1\u8BA1\u65E0\u56DE\u6267";
2132
2143
  }
2133
2144
  });
2134
2145
 
@@ -2228,6 +2239,19 @@ var init_reviewer_output = __esm({
2228
2239
  }
2229
2240
  });
2230
2241
 
2242
+ // src/readable-gate-item.ts
2243
+ function readableGateItem(value) {
2244
+ return typeof value === "string" ? value : JSON.stringify(value);
2245
+ }
2246
+ function joinReadableGateItems(items, separator = "; ") {
2247
+ return items.map(readableGateItem).join(separator);
2248
+ }
2249
+ var init_readable_gate_item = __esm({
2250
+ "src/readable-gate-item.ts"() {
2251
+ "use strict";
2252
+ }
2253
+ });
2254
+
2231
2255
  // src/audit-escalation.ts
2232
2256
  function buildAuditEscalationResult(decision, deliveredOutput) {
2233
2257
  const auditOwned = {
@@ -2276,17 +2300,17 @@ function humanDecisionText(decision, result) {
2276
2300
  lines.push(`Reason: ${result.reason}`);
2277
2301
  }
2278
2302
  if (Array.isArray(result.conflicts)) {
2279
- lines.push("Conflicts:", ...result.conflicts.map((conflict) => `- ${conflict}`));
2303
+ lines.push("Conflicts:", ...result.conflicts.map((conflict) => `- ${readableGateItem(conflict)}`));
2280
2304
  }
2281
2305
  if (officer !== void 0 && Array.isArray(result.findings) && result.findings.length > 0) {
2282
- lines.push("Findings:", ...result.findings.map((finding2) => `- ${finding2}`));
2306
+ lines.push("Findings:", ...result.findings.map((finding2) => `- ${readableGateItem(finding2)}`));
2283
2307
  }
2284
2308
  const gate = result.auditDecisionGate;
2285
2309
  if (gate !== null && typeof gate === "object" && !Array.isArray(gate)) {
2286
2310
  const record4 = gate;
2287
2311
  if (typeof record4.question === "string") lines.push(`Question: ${record4.question}`);
2288
2312
  if (Array.isArray(record4.options)) {
2289
- lines.push("Options:", ...record4.options.map((option) => `- ${option}`));
2313
+ lines.push("Options:", ...record4.options.map((option) => `- ${readableGateItem(option)}`));
2290
2314
  }
2291
2315
  }
2292
2316
  return lines.join("\n");
@@ -2338,30 +2362,31 @@ var AUDIT_ESCALATION_KIND, AUDIT_ESCALATION_LIVE_REGISTRY;
2338
2362
  var init_audit_escalation = __esm({
2339
2363
  "src/audit-escalation.ts"() {
2340
2364
  "use strict";
2365
+ init_readable_gate_item();
2341
2366
  AUDIT_ESCALATION_KIND = "audit_escalation";
2342
2367
  AUDIT_ESCALATION_LIVE_REGISTRY = /* @__PURE__ */ new WeakSet();
2343
2368
  }
2344
2369
  });
2345
2370
 
2346
2371
  // src/submission-errors.ts
2372
+ function serializeReceipt(receipt) {
2373
+ return readableGateItem(receipt);
2374
+ }
2347
2375
  function gatekeeperNonPassMessage(result) {
2348
- if (result.status === "bounce") {
2349
- const findings = result.findings.length === 0 ? "\uFF08\u65E0 findings\uFF09" : result.findings.join("; ");
2350
- return `\u95E8\u4E0B\u7701\u6253\u56DE\u91CD\u5199\uFF0Cfindings\uFF1A${findings}`;
2351
- }
2352
- if (result.status === "unreadable") {
2353
- return `\u95E8\u4E0B\u7701\u5B98\u56DE\u6267\u5F62\u72B6\u4E0D\u53EF\u8BFB\uFF08${result.officer}\uFF09\uFF1A${result.reason}`;
2376
+ if (result.status === "bounce" || result.status === "escalate") {
2377
+ return serializeReceipt(result.receipt);
2354
2378
  }
2355
2379
  return `\u95E8\u4E0B\u7701 ${result.status}\uFF08${result.stage}\uFF09\uFF1A${result.reason}`;
2356
2380
  }
2357
- var GatekeeperDecisionError, WorkerCommitReminderError, WorkerPrefixReminderError, WorkerUnfinishedReasonReminderError;
2381
+ var GatekeeperDecisionError, WorkerCommitReminderError, WorkerPrefixReminderError, WorkerUnfinishedReasonReminderError, ParentQueueReaskError;
2358
2382
  var init_submission_errors = __esm({
2359
2383
  "src/submission-errors.ts"() {
2360
2384
  "use strict";
2385
+ init_readable_gate_item();
2361
2386
  GatekeeperDecisionError = class extends Error {
2362
2387
  result;
2363
- constructor(result) {
2364
- super(gatekeeperNonPassMessage(result));
2388
+ constructor(result, message) {
2389
+ super(message ?? gatekeeperNonPassMessage(result));
2365
2390
  this.name = "GatekeeperDecisionError";
2366
2391
  this.result = result;
2367
2392
  }
@@ -2387,6 +2412,13 @@ var init_submission_errors = __esm({
2387
2412
  this.name = "WorkerUnfinishedReasonReminderError";
2388
2413
  }
2389
2414
  };
2415
+ ParentQueueReaskError = class extends Error {
2416
+ code = "parent_queue_reask";
2417
+ constructor(message) {
2418
+ super(message);
2419
+ this.name = "ParentQueueReaskError";
2420
+ }
2421
+ };
2390
2422
  }
2391
2423
  });
2392
2424
 
@@ -2395,7 +2427,7 @@ function isCorrectableSubmissionError(error) {
2395
2427
  return error instanceof CorrectableSubmissionError;
2396
2428
  }
2397
2429
  function isCorrectableExecuteError(error) {
2398
- return isCorrectableSubmissionError(error) || error instanceof GatekeeperDecisionError || error instanceof WorkerCommitReminderError || error instanceof WorkerPrefixReminderError || error instanceof WorkerUnfinishedReasonReminderError;
2430
+ return isCorrectableSubmissionError(error) || error instanceof GatekeeperDecisionError || error instanceof ParentQueueReaskError || error instanceof WorkerCommitReminderError || error instanceof WorkerPrefixReminderError || error instanceof WorkerUnfinishedReasonReminderError;
2399
2431
  }
2400
2432
  var correctableSubmissionErrorBrand, CorrectableSubmissionError;
2401
2433
  var init_submission_correctable_error = __esm({
@@ -3067,36 +3099,13 @@ import { Type as Type10 } from "typebox";
3067
3099
  function isRecord10(value) {
3068
3100
  return typeof value === "object" && value !== null && !Array.isArray(value);
3069
3101
  }
3070
- function asStringArray2(value) {
3071
- if (!Array.isArray(value)) return [];
3072
- return value.filter((item) => typeof item === "string");
3073
- }
3074
3102
  function projectLawfulNotaryOutput(value) {
3075
3103
  if (!isRecord10(value)) return void 0;
3076
3104
  const status = typeof value.status === "string" ? value.status : void 0;
3077
- if (status === "bounce") {
3078
- const clone = structuredClone(value);
3079
- if (clone.disposition === void 0) clone.disposition = "rewrite";
3080
- if (!Array.isArray(clone.findings)) clone.findings = asStringArray2(clone.findings);
3081
- return clone;
3082
- }
3083
- if (status === "pass") {
3084
- const clone = structuredClone(value);
3085
- if (!Array.isArray(clone.findings)) clone.findings = asStringArray2(clone.findings);
3086
- return clone;
3087
- }
3088
- if (status === "escalate") {
3089
- return structuredClone(value);
3090
- }
3091
- return void 0;
3092
- }
3093
- function retainNotarySubmission(value) {
3094
- if (value === void 0) return { missing: "arguments" };
3095
- try {
3096
- return structuredClone(value);
3097
- } catch {
3105
+ if (status === "bounce" || status === "pass" || status === "escalate") {
3098
3106
  return value;
3099
3107
  }
3108
+ return void 0;
3100
3109
  }
3101
3110
  function validateRecordedNotaryOutput(value) {
3102
3111
  const projected = projectLawfulNotaryOutput(value);
@@ -3489,10 +3498,10 @@ function validateAcceptedDetails(toolName, details) {
3489
3498
  [COLLECTOR_OUTPUT_TOOL]: [],
3490
3499
  [DOCTOR_OUTPUT_TOOL_NAME]: ["completed", "refused"],
3491
3500
  [MERGER_OUTPUT_TOOL_NAME]: ["completed", "escalate"],
3492
- [NOTARY_OUTPUT_TOOL_NAME]: ["pass", "bounce"],
3501
+ [NOTARY_OUTPUT_TOOL_NAME]: ["pass", "bounce", "escalate"],
3493
3502
  [COUNTERSIGN_OUTPUT_TOOL_NAME]: ["converged", "continue", "escalate"],
3494
3503
  [GLEANER_LEFT_OUTPUT_TOOL_NAME]: ["completed"],
3495
- [INSPECTOR_OUTPUT_TOOL_NAME]: ["pass", "bounce"],
3504
+ [INSPECTOR_OUTPUT_TOOL_NAME]: ["pass", "bounce", "escalate"],
3496
3505
  [GATEKEEPER_OUTPUT_TOOL_NAME]: ["dispatch", "pass"],
3497
3506
  [NAVIGATOR_OUTPUT_TOOL_NAME]: ["advice"],
3498
3507
  [AUDITOR_OUTPUT_TOOL_NAME]: ["pass", "bounce", "escalate"],
@@ -4102,13 +4111,6 @@ function instructResumeHandbookRead(prompt, engineMaterial) {
4102
4111
  return line2;
4103
4112
  }).join("\n");
4104
4113
  }
4105
- function appendResumeMaterialReread(prompt, materialPath) {
4106
- const instruction = resumeRereadInstruction(materialPath, false);
4107
- const lines = prompt.split("\n");
4108
- if (lines.includes(instruction)) return prompt;
4109
- return prompt.length === 0 ? instruction : `${prompt}
4110
- ${instruction}`;
4111
- }
4112
4114
  function selectResumeContinuationPrompt(message, engineMaterial) {
4113
4115
  const base = message !== void 0 ? message : RESUME_TRANSPORT_ENVELOPE;
4114
4116
  return instructResumeHandbookRead(
@@ -9801,201 +9803,6 @@ var init_public_run_credentials = __esm({
9801
9803
  }
9802
9804
  });
9803
9805
 
9804
- // src/shape-unreadable-failure.ts
9805
- function isRecord12(value) {
9806
- return typeof value === "object" && value !== null && !Array.isArray(value);
9807
- }
9808
- function retainedShapeUnreadable(decisiveFacts) {
9809
- if (!isRecord12(decisiveFacts)) return void 0;
9810
- if (decisiveFacts[SHAPE_UNREADABLE_KEY] === true) {
9811
- return { candidate: decisiveFacts.candidate };
9812
- }
9813
- const secondary = isRecord12(decisiveFacts.secondaryEvidence) ? decisiveFacts.secondaryEvidence : void 0;
9814
- if (secondary !== void 0 && secondary[SHAPE_UNREADABLE_KEY] === true) {
9815
- return { candidate: secondary.candidate };
9816
- }
9817
- return void 0;
9818
- }
9819
- var SHAPE_UNREADABLE_KEY;
9820
- var init_shape_unreadable_failure = __esm({
9821
- "src/shape-unreadable-failure.ts"() {
9822
- "use strict";
9823
- SHAPE_UNREADABLE_KEY = "shapeUnreadable";
9824
- }
9825
- });
9826
-
9827
- // src/gatekeeper-role.ts
9828
- function gateSeatLabel(stage) {
9829
- return stage === "inspector" ? "\u5BDF\u9662" : "\u7B26\u5B9D\u90CE";
9830
- }
9831
- function failureReason(error) {
9832
- if (error instanceof AggregateError) return error.errors.map(failureReason).join("; ");
9833
- return error instanceof Error ? `${error.name}: ${error.message}` : String(error);
9834
- }
9835
- function asStringArray3(value) {
9836
- if (!Array.isArray(value)) return [];
9837
- return value.map((item) => typeof item === "string" ? item : JSON.stringify(item));
9838
- }
9839
- function isRecord13(value) {
9840
- return typeof value === "object" && value !== null && !Array.isArray(value);
9841
- }
9842
- function retainedSubmission(decision) {
9843
- return decision === void 0 || isRecord13(decision) && Object.keys(decision).length === 0 ? MISSING_ARGUMENTS_SUBMISSION : decision;
9844
- }
9845
- function shapeUnreadable(officer, decision, reason = "decision \u65E0\u663E\u5F0F pass/bounce/escalate") {
9846
- return {
9847
- status: "unreadable",
9848
- officer,
9849
- reason,
9850
- submission: retainedSubmission(decision)
9851
- };
9852
- }
9853
- function readRecord(value) {
9854
- if (typeof value !== "object" || value === null || Array.isArray(value)) return void 0;
9855
- return value;
9856
- }
9857
- function projectOfficerDecision(officer, decision) {
9858
- const record4 = readRecord(decision);
9859
- if (record4 === void 0) return shapeUnreadable(officer, decision);
9860
- if (record4.status === "bounce") {
9861
- return {
9862
- status: "bounce",
9863
- officer,
9864
- disposition: "rewrite",
9865
- findings: asStringArray3(record4.findings),
9866
- submission: retainedSubmission(decision)
9867
- };
9868
- }
9869
- if (record4.status === "pass") {
9870
- return {
9871
- status: "pass",
9872
- officer,
9873
- findings: asStringArray3(record4.findings)
9874
- };
9875
- }
9876
- if (record4.status === "escalate") {
9877
- return {
9878
- status: "escalate",
9879
- officer,
9880
- ...Object.hasOwn(record4, "reason") ? { reason: record4.reason } : {},
9881
- findings: record4.findings,
9882
- submission: retainedSubmission(decision)
9883
- };
9884
- }
9885
- return shapeUnreadable(officer, decision);
9886
- }
9887
- function projectOfficerTerminal(officer, summoned) {
9888
- const terminal = summoned.terminal;
9889
- const outcome = terminal?.roleOutcome;
9890
- if (outcome === void 0) {
9891
- const detail = summoned.stderr?.trim();
9892
- return {
9893
- status: "transport_failure",
9894
- stage: officer,
9895
- reason: detail && detail.length > 0 ? `${gateSeatLabel(officer)} public summon exit ${summoned.exitCode}: ${detail}` : `${gateSeatLabel(officer)} public summon produced no terminal (exit ${summoned.exitCode})`,
9896
- submission: summoned
9897
- };
9898
- }
9899
- if (outcome.kind === "no_receipt") {
9900
- return {
9901
- status: "no_receipt",
9902
- stage: officer,
9903
- reason: `${gateSeatLabel(officer)}\u672A\u4EA7\u751F\u5DF2\u63A5\u53D7\u56DE\u6267\u5373\u6563\u5C40`,
9904
- facts: outcome
9905
- };
9906
- }
9907
- if (outcome.kind === "failure") {
9908
- const shape = retainedShapeUnreadable(outcome.decisiveFacts);
9909
- if (shape !== void 0) {
9910
- return shapeUnreadable(officer, shape.candidate, outcome.diagnostic);
9911
- }
9912
- return {
9913
- status: "transport_failure",
9914
- stage: officer,
9915
- reason: outcome.diagnostic,
9916
- submission: outcome.decisiveFacts
9917
- };
9918
- }
9919
- if (outcome.kind === "accepted") {
9920
- return projectOfficerDecision(officer, {
9921
- status: outcome.status,
9922
- ...outcome.decisiveFacts
9923
- });
9924
- }
9925
- return {
9926
- status: "transport_failure",
9927
- stage: officer,
9928
- reason: `${gateSeatLabel(officer)} public summon returned unusable terminal kind`,
9929
- submission: outcome
9930
- };
9931
- }
9932
- async function projectGatekeeperRun(options) {
9933
- const officer = options.subject.kind === "worker_completion" ? "inspector" : "notary";
9934
- const runDirectory = options.runDirectory ?? auditorRunDirectory(options.context);
9935
- if (runDirectory === void 0) {
9936
- return {
9937
- officer,
9938
- result: {
9939
- status: "transport_failure",
9940
- stage: officer,
9941
- reason: `${gateSeatLabel(officer)} requires a parent run directory pointer`
9942
- }
9943
- };
9944
- }
9945
- persistGateSubmissionCandidate(runDirectory, options.context);
9946
- let summoned;
9947
- try {
9948
- const summon = options.summonOfficer ?? (async (nextOfficer, sourceRunDirectory, officerSignal) => {
9949
- const { summonGateOfficer: summonGateOfficer2 } = await Promise.resolve().then(() => (init_public_role_summons(), public_role_summons_exports));
9950
- return summonGateOfficer2({
9951
- officer: nextOfficer,
9952
- sourceRunDirectory,
9953
- cwd: options.context.cwd ?? process.cwd(),
9954
- ...officerSignal === void 0 ? {} : { signal: officerSignal }
9955
- });
9956
- });
9957
- summoned = await summon(officer, runDirectory, options.signal);
9958
- } catch (error) {
9959
- return {
9960
- officer,
9961
- result: { status: "transport_failure", stage: officer, reason: failureReason(error) }
9962
- };
9963
- }
9964
- return {
9965
- officer,
9966
- result: projectOfficerTerminal(officer, summoned),
9967
- summoned
9968
- };
9969
- }
9970
- var GatekeeperEscalationError, GATEKEEPER_TOOL_SPEC, MISSING_ARGUMENTS_SUBMISSION;
9971
- var init_gatekeeper_role = __esm({
9972
- "src/gatekeeper-role.ts"() {
9973
- "use strict";
9974
- init_auditor_dossier_tool();
9975
- init_submission_errors();
9976
- init_inspector_contracts();
9977
- init_gatekeeper_output();
9978
- init_shape_unreadable_failure();
9979
- init_submission_errors();
9980
- GatekeeperEscalationError = class extends Error {
9981
- gatekeeper;
9982
- constructor(gatekeeper) {
9983
- super(`\u95E8\u4E0B\u7701${gateSeatLabel(gatekeeper.officer)}\u4E0A\u5448`);
9984
- this.name = "GatekeeperEscalationError";
9985
- this.gatekeeper = gatekeeper;
9986
- }
9987
- };
9988
- GATEKEEPER_TOOL_SPEC = {
9989
- name: GATEKEEPER_OUTPUT_TOOL_NAME,
9990
- label: "\u95E8\u4E0B\u7701\u51B3\u8BAE",
9991
- description: "\u95E8\u4E0B\u7701\u7EC8\u5C40\u51B3\u8BAE\uFF0C\u72B6\u6001\u4E3A dispatch \u6216 pass\u3002",
9992
- promptSnippet: "\u95E8\u4E0B\u7701\u51B3\u8BAE",
9993
- parameters: gatekeeperOutputSchema
9994
- };
9995
- MISSING_ARGUMENTS_SUBMISSION = Object.freeze({ missing: "arguments" });
9996
- }
9997
- });
9998
-
9999
9806
  // src/run-terminal-artifacts.ts
10000
9807
  import { basename as basename6, dirname as dirname10, join as join18 } from "node:path";
10001
9808
  function runIdFromRunDirectory(runDirectory) {
@@ -10221,12 +10028,6 @@ function createSubmissionLedgerHost(host, outputTools, failInfrastructure2 = (er
10221
10028
  const append = (event) => appendFor(state, context, runId, attemptId, event);
10222
10029
  if (state.sealedAttemptIds.has(attemptId)) throw new Error("\u63D0\u4EA4\u8D26\u5DF2\u5C01\u8D26");
10223
10030
  append({ type: "candidate", attemptId, toolCallId, toolName: tool.name, sequence: ++state.sequence });
10224
- const projectOfficerEscalation = (officer, original, deliveredOutput = original) => projectAuditEscalation({
10225
- ...original,
10226
- status: "escalate",
10227
- officer,
10228
- reason: original.reason === void 0 ? `\u95E8\u4E0B\u7701${officer}\u4E0A\u5448\uFF08\u539F\u5377\u672A\u9644 reason\uFF09` : original.reason
10229
- }, deliveredOutput);
10230
10031
  let result;
10231
10032
  try {
10232
10033
  failOnInfrastructureFailureDeclaration(
@@ -10242,14 +10043,7 @@ function createSubmissionLedgerHost(host, outputTools, failInfrastructure2 = (er
10242
10043
  );
10243
10044
  result = await tool.execute(toolCallId, params, signal, update, context);
10244
10045
  } catch (error) {
10245
- if (error instanceof GatekeeperEscalationError) {
10246
- const decision = error.gatekeeper;
10247
- result = projectOfficerEscalation(
10248
- error.gatekeeper.officer,
10249
- decision,
10250
- params
10251
- );
10252
- } else if (isCorrectableExecuteError(error)) {
10046
+ if (isCorrectableExecuteError(error)) {
10253
10047
  append({
10254
10048
  type: "outcome",
10255
10049
  attemptId,
@@ -10270,10 +10064,6 @@ function createSubmissionLedgerHost(host, outputTools, failInfrastructure2 = (er
10270
10064
  throw error;
10271
10065
  }
10272
10066
  }
10273
- if ((role === "inspector" || role === "notary") && typeof result.details === "object" && result.details !== null && !Array.isArray(result.details) && result.details.status === "escalate") {
10274
- const details = result.details;
10275
- result = projectOfficerEscalation(role, details);
10276
- }
10277
10067
  if (isAuditEscalationProjection(result.details)) {
10278
10068
  const candidates2 = rounds.get(attemptId) ?? [];
10279
10069
  candidates2.push({
@@ -10321,7 +10111,6 @@ var init_submission_ledger = __esm({
10321
10111
  "use strict";
10322
10112
  init_activation_ledger_topology();
10323
10113
  init_audit_escalation();
10324
- init_gatekeeper_role();
10325
10114
  init_terminating_tools();
10326
10115
  init_run_terminal_artifacts();
10327
10116
  init_sitian_facade();
@@ -10333,7 +10122,7 @@ var init_submission_ledger = __esm({
10333
10122
 
10334
10123
  // src/ledger-session-read.ts
10335
10124
  import { readFile as readFile11 } from "node:fs/promises";
10336
- function isRecord14(value) {
10125
+ function isRecord12(value) {
10337
10126
  return typeof value === "object" && value !== null && !Array.isArray(value);
10338
10127
  }
10339
10128
  async function readLedgerSessionJsonl(path) {
@@ -10357,7 +10146,7 @@ async function readLedgerSessionJsonl(path) {
10357
10146
  }
10358
10147
  break;
10359
10148
  }
10360
- if (!isRecord14(row)) {
10149
+ if (!isRecord12(row)) {
10361
10150
  const kind = row === null ? "null" : Array.isArray(row) ? "array" : typeof row;
10362
10151
  throw new LedgerSessionJsonlError(
10363
10152
  `complete non-object JSONL record in ${path} at line ${index + 1}: expected object, got ${kind}`,
@@ -10420,7 +10209,7 @@ var init_ledger_session_read = __esm({
10420
10209
  // src/analyst-gate-cycles-read.ts
10421
10210
  import { readdir as readdir4 } from "node:fs/promises";
10422
10211
  import { join as join19 } from "node:path";
10423
- function isRecord15(value) {
10212
+ function isRecord13(value) {
10424
10213
  return typeof value === "object" && value !== null && !Array.isArray(value);
10425
10214
  }
10426
10215
  function isParentAttemptBindingRow(row) {
@@ -10451,7 +10240,7 @@ function isGateTerminatingToolName(toolName) {
10451
10240
  function acceptedGateReceiptIds(rows) {
10452
10241
  const accepted = /* @__PURE__ */ new Set();
10453
10242
  for (const row of rows) {
10454
- const message = isRecord15(row.message) ? row.message : void 0;
10243
+ const message = isRecord13(row.message) ? row.message : void 0;
10455
10244
  if (message?.role !== "toolResult") continue;
10456
10245
  if (typeof message.toolCallId !== "string" || message.toolCallId.length === 0) continue;
10457
10246
  if (message.isError === false) accepted.add(message.toolCallId);
@@ -10490,7 +10279,7 @@ function nearestAttemptBindingBefore(rows, beforeIndex) {
10490
10279
  for (let i = beforeIndex - 1; i >= 0; i -= 1) {
10491
10280
  const row = rows[i];
10492
10281
  if (!isParentAttemptBindingRow(row)) continue;
10493
- if (!isRecord15(row.data) || !isRecord15(row.data.parent)) continue;
10282
+ if (!isRecord13(row.data) || !isRecord13(row.data.parent)) continue;
10494
10283
  const id = row.data.parent.attemptEntryId;
10495
10284
  const sessionFile = row.data.parent.sessionFile;
10496
10285
  return {
@@ -10505,10 +10294,10 @@ function extractAllAcceptedGateToolCalls(rows) {
10505
10294
  const out = [];
10506
10295
  for (let rowIndex = 0; rowIndex < rows.length; rowIndex += 1) {
10507
10296
  const row = rows[rowIndex];
10508
- const message = isRecord15(row.message) ? row.message : void 0;
10297
+ const message = isRecord13(row.message) ? row.message : void 0;
10509
10298
  if (message?.role !== "assistant" || !Array.isArray(message.content)) continue;
10510
10299
  for (const part of message.content) {
10511
- if (!isRecord15(part) || part.type !== "toolCall") continue;
10300
+ if (!isRecord13(part) || part.type !== "toolCall") continue;
10512
10301
  if (typeof part.id !== "string" || part.id.length === 0) continue;
10513
10302
  if (typeof part.name !== "string" || part.name.length === 0) continue;
10514
10303
  if (!isGateTerminatingToolName(part.name)) continue;
@@ -10516,7 +10305,7 @@ function extractAllAcceptedGateToolCalls(rows) {
10516
10305
  const binding = nearestAttemptBindingBefore(rows, rowIndex);
10517
10306
  out.push({
10518
10307
  toolName: part.name,
10519
- args: isRecord15(part.arguments) ? part.arguments : void 0,
10308
+ args: isRecord13(part.arguments) ? part.arguments : void 0,
10520
10309
  accepted: true,
10521
10310
  rowIndex,
10522
10311
  ...binding
@@ -10656,7 +10445,7 @@ async function resolveOfficerSessionFromPointerFile(pointerPath) {
10656
10445
  { cause: error }
10657
10446
  );
10658
10447
  }
10659
- if (!isRecord15(raw) || raw.kind !== "direct-officer-run-pointer" || raw.version !== 1) {
10448
+ if (!isRecord13(raw) || raw.kind !== "direct-officer-run-pointer" || raw.version !== 1) {
10660
10449
  throw new Error(`direct officer run pointer has unknown shape in ${pointerPath}`);
10661
10450
  }
10662
10451
  const sessionFile = raw.sessionFile;
@@ -10668,6 +10457,7 @@ async function resolveOfficerSessionFromPointerFile(pointerPath) {
10668
10457
  async function readAnalystGateCyclesFromAuditorRoles(auditorRolesDirectory, options = {}) {
10669
10458
  const directories = typeof auditorRolesDirectory === "string" ? [auditorRolesDirectory] : auditorRolesDirectory;
10670
10459
  const volumes = [];
10460
+ const classifiedOfficerSessions = /* @__PURE__ */ new Set();
10671
10461
  for (const directory of directories) {
10672
10462
  let names;
10673
10463
  try {
@@ -10681,8 +10471,13 @@ async function readAnalystGateCyclesFromAuditorRoles(auditorRolesDirectory, opti
10681
10471
  }
10682
10472
  for (const name of names) {
10683
10473
  const path = join19(directory, name);
10684
- const sessionPath = name.endsWith(".pointer.json") ? await resolveOfficerSessionFromPointerFile(path) : path;
10474
+ const fromPointer = name.endsWith(".pointer.json");
10475
+ const sessionPath = fromPointer ? await resolveOfficerSessionFromPointerFile(path) : path;
10685
10476
  if (sessionPath === void 0) continue;
10477
+ if (fromPointer) {
10478
+ if (classifiedOfficerSessions.has(sessionPath)) continue;
10479
+ classifiedOfficerSessions.add(sessionPath);
10480
+ }
10686
10481
  const classified = await classifyAuditorVolume(sessionPath);
10687
10482
  for (const volume of classified) {
10688
10483
  if (options.parentSessionFile !== void 0 && volume.parentSessionFile !== void 0 && volume.parentSessionFile !== options.parentSessionFile) {
@@ -10831,112 +10626,10 @@ var init_auditor_soul = __esm({
10831
10626
  }
10832
10627
  });
10833
10628
 
10834
- // src/dossier-resolution.ts
10835
- import { existsSync as existsSync8, statSync as statSync2 } from "node:fs";
10836
- import { resolve as resolve10 } from "node:path";
10837
- function resolveAuditDossier(env = process.env) {
10838
- const raw = env[AUDIT_RUN_DIR_ENV];
10839
- if (typeof raw !== "string" || raw.trim() === "") {
10840
- return { status: "ok" };
10841
- }
10842
- const runDirectory = resolve10(raw);
10843
- try {
10844
- if (!existsSync8(runDirectory) || !statSync2(runDirectory).isDirectory()) {
10845
- return { status: "incomplete", observation: { kind: "missing-dossier" } };
10846
- }
10847
- } catch {
10848
- return { status: "incomplete", observation: { kind: "missing-dossier" } };
10849
- }
10850
- return { status: "ok", runDirectory };
10851
- }
10852
- function isRecord16(value) {
10853
- return typeof value === "object" && value !== null && !Array.isArray(value);
10854
- }
10855
- function readJudgeAuditSubjects(context) {
10856
- const entries = context.sessionManager.getEntries?.() ?? [];
10857
- let hasAssignment = false;
10858
- let hasCandidate = false;
10859
- for (const entry of entries) {
10860
- if (!isRecord16(entry) || entry.type !== "message" || !isRecord16(entry.message)) continue;
10861
- const message = entry.message;
10862
- if (message.role === "user") {
10863
- const text = typeof message.content === "string" ? message.content : Array.isArray(message.content) ? message.content.map((part) => isRecord16(part) && part.type === "text" && typeof part.text === "string" ? part.text : "").join("") : "";
10864
- if (text.trim().length > 0) hasAssignment = true;
10865
- }
10866
- if (message.role === "assistant" && Array.isArray(message.content)) {
10867
- for (const part of message.content) {
10868
- if (isRecord16(part) && part.type === "toolCall" && part.name === JUDGE_OUTPUT_TOOL_NAME2 && isRecord16(part.arguments)) {
10869
- hasCandidate = true;
10870
- }
10871
- }
10872
- }
10873
- }
10874
- if (!hasAssignment) {
10875
- return { status: "incomplete", observation: { kind: "missing-subject", subject: "assignment" } };
10876
- }
10877
- if (!hasCandidate) {
10878
- return { status: "incomplete", observation: { kind: "missing-subject", subject: "candidate-verdict" } };
10879
- }
10880
- return { status: "ok" };
10881
- }
10882
- function readDoctorAuditSubjects(context) {
10883
- const entries = context.sessionManager.getEntries?.() ?? [];
10884
- for (const entry of entries) {
10885
- if (isRecord16(entry) && entry.type === "custom" && entry.customType === DOCTOR_CANDIDATE_ENTRY_TYPE) {
10886
- return { status: "ok" };
10887
- }
10888
- }
10889
- return { status: "incomplete", observation: { kind: "missing-subject", subject: "candidate-testimony" } };
10890
- }
10891
- function requireAuditMaterials(resolution) {
10892
- if (resolution.status === "incomplete") {
10893
- throw new AuditMaterialsUnavailableError(resolution.observation);
10894
- }
10895
- }
10896
- var JUDGE_OUTPUT_TOOL_NAME2, AUDIT_RUN_DIR_ENV, DOCTOR_CANDIDATE_ENTRY_TYPE, AuditMaterialsUnavailableError;
10897
- var init_dossier_resolution = __esm({
10898
- "src/dossier-resolution.ts"() {
10899
- "use strict";
10900
- init_judge_output();
10901
- JUDGE_OUTPUT_TOOL_NAME2 = JUDGE_OUTPUT_TOOL_NAME;
10902
- AUDIT_RUN_DIR_ENV = "AK_ROLE_RUN_DIR";
10903
- DOCTOR_CANDIDATE_ENTRY_TYPE = "ak_doctor_audit_candidate";
10904
- AuditMaterialsUnavailableError = class extends Error {
10905
- observation;
10906
- candidate;
10907
- constructor(observation) {
10908
- const detail = observation.kind === "missing-subject" ? `${observation.kind}:${observation.subject}` : observation.kind;
10909
- super(`Audit materials unavailable: ${detail}`);
10910
- this.name = "AuditMaterialsUnavailableError";
10911
- this.observation = observation;
10912
- this.candidate = void 0;
10913
- }
10914
- };
10915
- }
10916
- });
10917
-
10918
10629
  // src/judge-auditor.ts
10919
- function createPiJudgeAuditor() {
10920
- return async (options) => {
10921
- const dossier = resolveAuditDossier();
10922
- requireAuditMaterials(dossier);
10923
- const subjects = readJudgeAuditSubjects(options.context);
10924
- requireAuditMaterials(subjects);
10925
- return runComplianceAudit({
10926
- subject: "judge",
10927
- context: options.context,
10928
- ...auditorRunDirectory(options.context) === void 0 ? {} : { runDirectory: auditorRunDirectory(options.context) },
10929
- ...options.signal === void 0 ? {} : { signal: options.signal },
10930
- ...options.summonAuditor === void 0 ? {} : { summonAuditor: options.summonAuditor }
10931
- });
10932
- };
10933
- }
10934
10630
  var init_judge_auditor = __esm({
10935
10631
  "src/judge-auditor.ts"() {
10936
10632
  "use strict";
10937
- init_compliance_transport();
10938
- init_auditor_dossier_tool();
10939
- init_dossier_resolution();
10940
10633
  }
10941
10634
  });
10942
10635
 
@@ -12891,11 +12584,11 @@ function resolvePackagedMethodSkillRoot(packageRoot, name) {
12891
12584
  function resolvePackagedMethodSkillPath(packageRoot, name) {
12892
12585
  return join22(resolvePackagedMethodSkillRoot(packageRoot, name), "SKILL.md");
12893
12586
  }
12894
- function isRecord17(value) {
12587
+ function isRecord14(value) {
12895
12588
  return typeof value === "object" && value !== null && !Array.isArray(value);
12896
12589
  }
12897
12590
  function parseProvenance(raw, expectedName) {
12898
- if (!isRecord17(raw)) {
12591
+ if (!isRecord14(raw)) {
12899
12592
  throw new Error(`Packaged method provenance must be an object for ${expectedName}`);
12900
12593
  }
12901
12594
  if (raw.name !== expectedName) {
@@ -12909,7 +12602,7 @@ function parseProvenance(raw, expectedName) {
12909
12602
  if (typeof raw.packageAdaptation !== "string" || raw.packageAdaptation.trim() === "") {
12910
12603
  throw new Error(`Packaged method provenance packageAdaptation must be nonblank`);
12911
12604
  }
12912
- if (!isRecord17(raw.upstream)) {
12605
+ if (!isRecord14(raw.upstream)) {
12913
12606
  throw new Error(`Packaged method provenance upstream must be an object`);
12914
12607
  }
12915
12608
  const upstream = raw.upstream;
@@ -12936,12 +12629,12 @@ function parseProvenance(raw, expectedName) {
12936
12629
  `Packaged method provenance upstream must include nonblank tag or version`
12937
12630
  );
12938
12631
  }
12939
- if (!isRecord17(raw.files)) {
12632
+ if (!isRecord14(raw.files)) {
12940
12633
  throw new Error(`Packaged method provenance files must be an object`);
12941
12634
  }
12942
12635
  const files = {};
12943
12636
  for (const [rel, entry] of Object.entries(raw.files)) {
12944
- if (!isRecord17(entry)) {
12637
+ if (!isRecord14(entry)) {
12945
12638
  throw new Error(`Packaged method provenance file entry must be an object: ${rel}`);
12946
12639
  }
12947
12640
  if (typeof entry.sha256 !== "string" || !SHA256_RE.test(entry.sha256)) {
@@ -13076,7 +12769,7 @@ var init_method_skill = __esm({
13076
12769
  });
13077
12770
 
13078
12771
  // src/work-subject-identity.ts
13079
- import { resolve as resolve11 } from "node:path";
12772
+ import { resolve as resolve10 } from "node:path";
13080
12773
  function issueRoot(value) {
13081
12774
  const normalized = value.replaceAll("\\", "/");
13082
12775
  const marker = ".ak/work/issues/";
@@ -13086,7 +12779,7 @@ function issueRoot(value) {
13086
12779
  return issue === void 0 || issue === "" ? void 0 : normalized.slice(0, index + marker.length) + issue;
13087
12780
  }
13088
12781
  function workIdentityFromCwd(cwd) {
13089
- const resolvedCwd = resolve11(cwd, ".");
12782
+ const resolvedCwd = resolve10(cwd, ".");
13090
12783
  const cwdIssue = issueRoot(resolvedCwd);
13091
12784
  if (cwdIssue !== void 0) return cwdIssue;
13092
12785
  if (resolvedCwd.includes("/.ak/work/")) return resolvedCwd;
@@ -13097,11 +12790,11 @@ function isMachineLedgerSessionPath(sessionPath) {
13097
12790
  }
13098
12791
  function subjectPath(sessionDir, cwd = process.cwd()) {
13099
12792
  if (sessionDir === "") {
13100
- return workIdentityFromCwd(cwd) ?? resolve11(cwd, ".ak/work");
12793
+ return workIdentityFromCwd(cwd) ?? resolve10(cwd, ".ak/work");
13101
12794
  }
13102
- const resolvedSession = resolve11(cwd, sessionDir || ".ak/work");
12795
+ const resolvedSession = resolve10(cwd, sessionDir || ".ak/work");
13103
12796
  if (isMachineLedgerSessionPath(resolvedSession)) {
13104
- return workIdentityFromCwd(cwd) ?? resolve11(cwd, ".ak/work");
12797
+ return workIdentityFromCwd(cwd) ?? resolve10(cwd, ".ak/work");
13105
12798
  }
13106
12799
  const issue = issueRoot(resolvedSession);
13107
12800
  if (issue !== void 0) return issue;
@@ -13285,11 +12978,11 @@ var init_navigator_invocation_identity = __esm({
13285
12978
  });
13286
12979
 
13287
12980
  // src/receipt-delivery-policy.ts
13288
- function isRecord18(value) {
12981
+ function isRecord15(value) {
13289
12982
  return typeof value === "object" && value !== null && !Array.isArray(value);
13290
12983
  }
13291
12984
  function parseNoReceiptLifecycleFacts(input) {
13292
- if (!isRecord18(input) || typeof input.terminalToolCalled !== "boolean" || input.deliveryTurns !== RECEIPT_DELIVERY_TURN_LIMIT || input.sessionCompletion !== "settled-without-accepted-receipt" || input.acceptedReceipt !== false || typeof input.runPointer !== "string" || input.runPointer.trim() === "" || typeof input.attemptPointer !== "string" || input.attemptPointer.trim() === "" || !Array.isArray(input.rejectedReceipts) || !input.rejectedReceipts.every((item) => isRecord18(item) && typeof item.reason === "string")) {
12985
+ if (!isRecord15(input) || typeof input.terminalToolCalled !== "boolean" || input.deliveryTurns !== RECEIPT_DELIVERY_TURN_LIMIT || input.sessionCompletion !== "settled-without-accepted-receipt" || input.acceptedReceipt !== false || typeof input.runPointer !== "string" || input.runPointer.trim() === "" || typeof input.attemptPointer !== "string" || input.attemptPointer.trim() === "" || !Array.isArray(input.rejectedReceipts) || !input.rejectedReceipts.every((item) => isRecord15(item) && typeof item.reason === "string")) {
13293
12986
  throw new TypeError("malformed no-receipt lifecycle facts");
13294
12987
  }
13295
12988
  return {
@@ -13892,7 +13585,7 @@ async function readSitianRetainedAuditorProviderStop(sessionFile) {
13892
13585
  const { records: records2 } = await readSitianRecords(recordFile);
13893
13586
  for (let i = records2.length - 1; i >= 0; i -= 1) {
13894
13587
  const payload = records2[i]?.payload;
13895
- if (!isRecord19(payload) || !isRecord19(payload.response)) continue;
13588
+ if (!isRecord16(payload) || !isRecord16(payload.response)) continue;
13896
13589
  if (typeof payload.type === "string") continue;
13897
13590
  const stop = sessionProviderStopFromAssistant(payload.response);
13898
13591
  if (stop !== void 0) return stop;
@@ -13929,7 +13622,7 @@ async function readBoundEvidenceChildKnownFailure(sessionFile) {
13929
13622
  throw sessionReadFailure(error, "failed to read discovered evidence-child session");
13930
13623
  }
13931
13624
  const header = entries.find((entry) => entry.type === "session");
13932
- if (!isRecord19(header) || header.parentSession !== sessionFile) continue;
13625
+ if (!isRecord16(header) || header.parentSession !== sessionFile) continue;
13933
13626
  const stop = extractSessionProviderStop(entries);
13934
13627
  if (stop === void 0) continue;
13935
13628
  const primary = knownFailureFromProviderStop(stop);
@@ -13961,12 +13654,12 @@ async function loadBoundAuditorVolumes(sessionFile) {
13961
13654
  return firstLine === RESUME_ENVELOPE;
13962
13655
  };
13963
13656
  const isResumeEnvelope = (msg) => {
13964
- if (!isRecord19(msg) || msg.role !== "user") return false;
13657
+ if (!isRecord16(msg) || msg.role !== "user") return false;
13965
13658
  const text = typeof msg.text === "string" ? msg.text : typeof msg.content === "string" ? msg.content : void 0;
13966
13659
  if (isResumeEnvelopeBytes(text)) return true;
13967
13660
  const content = msg.content;
13968
13661
  if (Array.isArray(content)) {
13969
- return content.some((p) => isRecord19(p) && (isResumeEnvelopeBytes(p.text) || isResumeEnvelopeBytes(p.content)));
13662
+ return content.some((p) => isRecord16(p) && (isResumeEnvelopeBytes(p.text) || isResumeEnvelopeBytes(p.content)));
13970
13663
  }
13971
13664
  return false;
13972
13665
  };
@@ -13998,7 +13691,7 @@ async function loadBoundAuditorVolumes(sessionFile) {
13998
13691
  throw sessionReadFailure(error, "failed to read discovered auditor session");
13999
13692
  }
14000
13693
  const header = entries.find((entry) => entry.type === "session");
14001
- if (!isRecord19(header)) continue;
13694
+ if (!isRecord16(header)) continue;
14002
13695
  const bindingIndexes = [];
14003
13696
  for (let i = 0; i < entries.length; i += 1) {
14004
13697
  const entry = entries[i];
@@ -14012,7 +13705,7 @@ async function loadBoundAuditorVolumes(sessionFile) {
14012
13705
  end: idx + 1 < bindingIndexes.length ? bindingIndexes[idx + 1] : entries.length
14013
13706
  })) : [{ entry: void 0, start: 0, end: entries.length }];
14014
13707
  for (const { entry: bindingEntry, start, end } of bindingPasses) {
14015
- const bindingParent = bindingEntry !== void 0 && isRecord19(bindingEntry.data) && isRecord19(bindingEntry.data.parent) ? bindingEntry.data.parent : void 0;
13708
+ const bindingParent = bindingEntry !== void 0 && isRecord16(bindingEntry.data) && isRecord16(bindingEntry.data.parent) ? bindingEntry.data.parent : void 0;
14016
13709
  const attemptEntryId = typeof bindingParent?.attemptEntryId === "string" ? bindingParent.attemptEntryId : void 0;
14017
13710
  const attemptEntryIndex = attemptEntryId === void 0 ? -1 : parentEntries.findIndex((entry) => entry.id === attemptEntryId);
14018
13711
  const boundSessionFile = typeof bindingParent?.sessionFile === "string" ? bindingParent.sessionFile : typeof header.parentSession === "string" ? header.parentSession : void 0;
@@ -14039,11 +13732,11 @@ function complianceFailureFromAuditorVolumes(volumes) {
14039
13732
  if (stop === void 0) continue;
14040
13733
  for (let i = entries.length - 1; i >= 0; i -= 1) {
14041
13734
  const entry = entries[i];
14042
- if (entry?.type !== "custom" || entry.customType !== AUDITOR_COMPLIANCE_FAILURE_ENTRY_TYPE || !isRecord19(entry.data)) continue;
14043
- const parent = isRecord19(entry.data.parent) ? entry.data.parent : void 0;
14044
- const failure2 = isRecord19(entry.data.failure) ? entry.data.failure : void 0;
13735
+ if (entry?.type !== "custom" || entry.customType !== AUDITOR_COMPLIANCE_FAILURE_ENTRY_TYPE || !isRecord16(entry.data)) continue;
13736
+ const parent = isRecord16(entry.data.parent) ? entry.data.parent : void 0;
13737
+ const failure2 = isRecord16(entry.data.failure) ? entry.data.failure : void 0;
14045
13738
  if (parent?.sessionId !== parentId || parent.sessionFile !== sessionFile || parent.attemptEntryId !== attemptEntryId || failure2?.cause !== "provider" && failure2?.cause !== "unrecognized") continue;
14046
- const identity = isRecord19(failure2.identity) ? failure2.identity : void 0;
13739
+ const identity = isRecord16(failure2.identity) ? failure2.identity : void 0;
14047
13740
  return {
14048
13741
  cause: failure2.cause === "provider" ? "provider" : "unrecognized",
14049
13742
  ...identity === void 0 ? {} : { identity: {
@@ -14051,7 +13744,7 @@ function complianceFailureFromAuditorVolumes(volumes) {
14051
13744
  ...typeof identity.code === "string" || typeof identity.code === "number" ? { code: identity.code } : {}
14052
13745
  } },
14053
13746
  ...typeof failure2.diagnostic === "string" ? { diagnostic: failure2.diagnostic } : {},
14054
- ...isRecord19(failure2.details) ? { details: failure2.details } : {}
13747
+ ...isRecord16(failure2.details) ? { details: failure2.details } : {}
14055
13748
  };
14056
13749
  }
14057
13750
  }
@@ -14098,9 +13791,9 @@ function typedFailedTerminatingToolKnownFailure(entries) {
14098
13791
  if (classification.kind !== "infrastructure") continue;
14099
13792
  if (typeof message.toolCallId !== "string" || typeof message.toolName !== "string") continue;
14100
13793
  if (boundRoleToolCallForResult(attemptEntries, i, message, message.toolName) === void 0) continue;
14101
- const textPart = Array.isArray(message.content) ? message.content.find((part) => isRecord19(part) && part.type === "text" && typeof part.text === "string") : void 0;
14102
- const diagnostic = isRecord19(textPart) ? textPart.text : void 0;
14103
- const details = isRecord19(message.details) ? message.details : classification.fact;
13794
+ const textPart = Array.isArray(message.content) ? message.content.find((part) => isRecord16(part) && part.type === "text" && typeof part.text === "string") : void 0;
13795
+ const diagnostic = isRecord16(textPart) ? textPart.text : void 0;
13796
+ const details = isRecord16(message.details) ? message.details : classification.fact;
14104
13797
  return {
14105
13798
  cause: "activation",
14106
13799
  identity: { name: message.toolName, code: message.toolCallId },
@@ -14258,7 +13951,7 @@ function controlledFailureInputFromResolution(resolution) {
14258
13951
  } : {}
14259
13952
  };
14260
13953
  }
14261
- function isRecord19(value) {
13954
+ function isRecord16(value) {
14262
13955
  return typeof value === "object" && value !== null && !Array.isArray(value);
14263
13956
  }
14264
13957
  function safelyRead(object, key) {
@@ -14350,7 +14043,7 @@ function boundRoleToolCallForResult(entries, resultIndex, message, outputToolNam
14350
14043
  const candidateMessage = entries[index]?.message;
14351
14044
  if (candidateMessage?.role === "assistant" && Array.isArray(candidateMessage.content)) {
14352
14045
  for (const part of candidateMessage.content) {
14353
- if (!isRecord19(part) || part.type !== "toolCall" || part.id !== callId) {
14046
+ if (!isRecord16(part) || part.type !== "toolCall" || part.id !== callId) {
14354
14047
  continue;
14355
14048
  }
14356
14049
  if (part.name !== outputToolName) return void 0;
@@ -14422,7 +14115,7 @@ function parseNavigatorAttendanceDetails(details) {
14422
14115
  const advisoryDiagnostic = typeof details.routePlaybookReadFailure === "string" ? { advisoryDiagnostic: details.routePlaybookReadFailure } : {};
14423
14116
  if (disposition === "recommendation") {
14424
14117
  const next = details.next;
14425
- if (!isRecord19(next) || typeof next.role !== "string") {
14118
+ if (!isRecord16(next) || typeof next.role !== "string") {
14426
14119
  return {
14427
14120
  disposition: "unavailable",
14428
14121
  source: "unknown",
@@ -14430,7 +14123,7 @@ function parseNavigatorAttendanceDetails(details) {
14430
14123
  };
14431
14124
  }
14432
14125
  const reason = typeof details.reason === "string" ? details.reason : "";
14433
- const route = Array.isArray(details.route) ? details.route.filter(isRecord19).map((target) => ({
14126
+ const route = Array.isArray(details.route) ? details.route.filter(isRecord16).map((target) => ({
14434
14127
  role: String(target.role),
14435
14128
  phase: navigatorPhaseValue(target.phase)
14436
14129
  })) : void 0;
@@ -14502,7 +14195,7 @@ async function extractGateFactFromSessionDirectory(sessionDirectory, options = {
14502
14195
  }
14503
14196
  async function withOptionalGateProjection(base, sessionDirectory, gateContext = {}) {
14504
14197
  const secondaryEvidence = base.roleOutcome.kind === "failure" ? base.roleOutcome.decisiveFacts.secondaryEvidence : void 0;
14505
- if (isRecord19(secondaryEvidence) && secondaryEvidence.kind === "role_infrastructure_failure" && (secondaryEvidence.stage === "gatekeeper" || secondaryEvidence.stage === "inspector" || secondaryEvidence.stage === "notary")) return base;
14198
+ if (isRecord16(secondaryEvidence) && secondaryEvidence.kind === "role_infrastructure_failure" && (secondaryEvidence.stage === "gatekeeper" || secondaryEvidence.stage === "inspector" || secondaryEvidence.stage === "notary")) return base;
14506
14199
  const gate = await extractGateFactFromSessionDirectory(sessionDirectory, gateContext);
14507
14200
  return gate === void 0 ? base : { ...base, gate };
14508
14201
  }
@@ -14542,7 +14235,7 @@ function extractNavigatorFact(entries) {
14542
14235
  const entry = entries[i];
14543
14236
  if (entry?.type === "custom_message" && entry.customType === "ak-navigator-attendance") {
14544
14237
  const details = entry.message?.details ?? entry.details;
14545
- if (!isRecord19(details)) {
14238
+ if (!isRecord16(details)) {
14546
14239
  return {
14547
14240
  disposition: "unavailable",
14548
14241
  source: "unknown",
@@ -14825,7 +14518,7 @@ async function settleLawfulSeatAcceptedTerminalResult(admitted, authority, spec,
14825
14518
  spec.toolName
14826
14519
  );
14827
14520
  if (residual !== void 0) {
14828
- const details = isRecord19(residual.candidate) ? residual.candidate : { candidate: residual.candidate };
14521
+ const details = isRecord16(residual.candidate) ? residual.candidate : { candidate: residual.candidate };
14829
14522
  return settleFailureTerminalResult(admitted, {
14830
14523
  cause: "output",
14831
14524
  diagnostic: residual.diagnostic,
@@ -15619,7 +15312,7 @@ var init_auto_resume = __esm({
15619
15312
  // src/public-cli/post-admission.ts
15620
15313
  import { randomUUID as randomUUID5 } from "node:crypto";
15621
15314
  import { readFile as readFile16, writeFile as writeFile7 } from "node:fs/promises";
15622
- import { isAbsolute as isAbsolute7, join as join25, resolve as resolve12 } from "node:path";
15315
+ import { isAbsolute as isAbsolute7, join as join25, resolve as resolve11 } from "node:path";
15623
15316
  function appendContinuationSection(continuation, section) {
15624
15317
  const prompt = `${continuation.prompt}
15625
15318
 
@@ -15848,24 +15541,16 @@ async function dispatchPostAdmissionTurn(input) {
15848
15541
  }
15849
15542
  }
15850
15543
  function resumeTurnRequestProjectionOptions(admitted, request, env, summonsPrepared) {
15851
- const engineMaterial = engineSessionMaterialFromOptions({
15852
- ...env.engine === void 0 ? {} : { engine: env.engine },
15853
- packageRoot: env.packageRoot
15854
- });
15855
15544
  let prompt;
15856
15545
  if (request.message !== void 0) {
15857
- if (summonsPrepared !== void 0 && summonsPrepared.attachments.length > 0) {
15858
- prompt = instructResumeHandbookRead(
15859
- buildInstructionTransportPrompt(
15860
- {
15861
- instruction: request.message,
15862
- instructionEmpty: false,
15863
- attachments: summonsPrepared.attachments
15864
- },
15865
- engineMaterial
15866
- ),
15867
- engineMaterial
15868
- );
15546
+ if (summonsPrepared !== void 0) {
15547
+ prompt = buildInstructionTransportPrompt({
15548
+ instruction: request.message,
15549
+ instructionEmpty: false,
15550
+ attachments: summonsPrepared.attachments
15551
+ });
15552
+ } else if (request.summons !== void 0) {
15553
+ prompt = request.message;
15869
15554
  } else {
15870
15555
  prompt = buildResumeContinuationPrompt({
15871
15556
  packageRoot: env.packageRoot,
@@ -15874,10 +15559,9 @@ function resumeTurnRequestProjectionOptions(admitted, request, env, summonsPrepa
15874
15559
  });
15875
15560
  }
15876
15561
  } else if (summonsPrepared !== void 0) {
15877
- prompt = instructResumeHandbookRead(
15878
- buildInstructionTransportPrompt(summonsPrepared, engineMaterial),
15879
- engineMaterial
15880
- );
15562
+ prompt = buildInstructionTransportPrompt(summonsPrepared);
15563
+ } else if (request.summons !== void 0) {
15564
+ prompt = RESUME_TRANSPORT_ENVELOPE;
15881
15565
  } else {
15882
15566
  prompt = buildResumeContinuationPrompt({
15883
15567
  packageRoot: env.packageRoot,
@@ -15899,7 +15583,7 @@ function resumeTurnRequestProjectionOptions(admitted, request, env, summonsPrepa
15899
15583
  };
15900
15584
  }
15901
15585
  function isAlreadyFrozenSummonsAttachment(runDirectory, attachmentPath) {
15902
- const absolute = isAbsolute7(attachmentPath) ? attachmentPath : resolve12(attachmentPath);
15586
+ const absolute = isAbsolute7(attachmentPath) ? attachmentPath : resolve11(attachmentPath);
15903
15587
  return pathContainedIn(join25(runDirectory, "attachments"), absolute);
15904
15588
  }
15905
15589
  async function prepareSummonsResumeMaterials(runDirectory, summons) {
@@ -16192,7 +15876,6 @@ var init_post_admission = __esm({
16192
15876
  init_cli_errors();
16193
15877
  init_invocation();
16194
15878
  init_activation_ledger_topology();
16195
- init_engine_material();
16196
15879
  init_case_dossier_delivery();
16197
15880
  init_host_transition_prior_native();
16198
15881
  init_public_run_credentials();
@@ -16238,7 +15921,6 @@ __export(notary_run_exports, {
16238
15921
  runPublicNotary: () => runPublicNotary,
16239
15922
  runPublicNotaryResume: () => runPublicNotaryResume
16240
15923
  });
16241
- import { existsSync as existsSync9 } from "node:fs";
16242
15924
  function buildNotaryTurnRequest(admitted, options) {
16243
15925
  return projectRoleTurnRequest(
16244
15926
  admitted,
@@ -16280,9 +15962,11 @@ async function runPublicNotary(argv, env, io, parseNotaryArgv2) {
16280
15962
  throw error;
16281
15963
  }
16282
15964
  {
15965
+ const resumeInstruction = env.reviewReask ?? env.gateReviewInstruction;
16283
15966
  const summons = {
16284
15967
  sourceRunPath: source.runDirectory,
16285
- sourceRun: source
15968
+ sourceRun: source,
15969
+ ...resumeInstruction === void 0 ? {} : { instruction: resumeInstruction, instructionEmpty: false }
16286
15970
  };
16287
15971
  const resumed = await tryResumeSameTicketSeatRun({
16288
15972
  home: env.home,
@@ -16298,6 +15982,15 @@ async function runPublicNotary(argv, env, io, parseNotaryArgv2) {
16298
15982
  )
16299
15983
  });
16300
15984
  if (resumed !== void 0) return resumed;
15985
+ if (env.reviewReask !== void 0) {
15986
+ presentStructuralRejection(
15987
+ new CliUsageError(
15988
+ "notary review reask requires a prior same-parent run to resume"
15989
+ ),
15990
+ io
15991
+ );
15992
+ return { exitCode: 2 };
15993
+ }
16301
15994
  }
16302
15995
  let admitted;
16303
15996
  try {
@@ -16380,18 +16073,20 @@ async function runPublicNotaryResume(request, env, io) {
16380
16073
  }
16381
16074
  return loaded;
16382
16075
  },
16383
- buildTurnRequest: (admitted, effective) => {
16384
- const projection = resumeTurnRequestProjectionOptions(
16076
+ buildTurnRequest: async (admitted, effective) => {
16077
+ const summonsPrepared = effective.summons === void 0 ? void 0 : await prepareSummonsResumeMaterials(
16078
+ admitted.runDirectory,
16079
+ effective.summons
16080
+ );
16081
+ return buildNotaryTurnRequest(
16385
16082
  admitted,
16386
- effective,
16387
- env
16083
+ resumeTurnRequestProjectionOptions(
16084
+ admitted,
16085
+ effective,
16086
+ env,
16087
+ summonsPrepared
16088
+ )
16388
16089
  );
16389
- const candidatePath = gateSubmissionCandidatePath(admitted.sourceRunPath);
16390
- const prompt = existsSync9(candidatePath) ? appendResumeMaterialReread(projection.continuation.prompt, candidatePath) : projection.continuation.prompt;
16391
- return buildNotaryTurnRequest(admitted, {
16392
- ...projection,
16393
- continuation: { kind: "resume", prompt }
16394
- });
16395
16090
  },
16396
16091
  adapters: notaryAdapters(),
16397
16092
  ...env.engine === void 0 ? {} : { effectiveEngine: env.engine }
@@ -16400,7 +16095,6 @@ async function runPublicNotaryResume(request, env, io) {
16400
16095
  var init_notary_run = __esm({
16401
16096
  "src/public-cli/notary-run.ts"() {
16402
16097
  "use strict";
16403
- init_auditor_dossier_tool();
16404
16098
  init_notary_source_run();
16405
16099
  init_engine_material();
16406
16100
  init_cli_errors();
@@ -16445,9 +16139,12 @@ async function runPublicInspector(argv, env, io, parseInspectorArgv2) {
16445
16139
  const projectRoot = parsed.project ?? env.cwd;
16446
16140
  const parentRunPath = parentRunPathFromGatePointerInstruction(parsed.instruction);
16447
16141
  if (parentRunPath !== void 0) {
16142
+ const resumeInstruction = env.reviewReask ?? env.gateReviewInstruction;
16448
16143
  const summons = {
16449
- instruction: parsed.instruction,
16450
- instructionEmpty: parsed.instruction.trim() === "",
16144
+ ...resumeInstruction === void 0 ? {
16145
+ instruction: parsed.instruction,
16146
+ instructionEmpty: parsed.instruction.trim() === ""
16147
+ } : { instruction: resumeInstruction, instructionEmpty: false },
16451
16148
  attachmentPaths: parsed.attachmentPaths
16452
16149
  };
16453
16150
  const resumed = await tryResumeSameTicketSeatRun({
@@ -16464,6 +16161,15 @@ async function runPublicInspector(argv, env, io, parseInspectorArgv2) {
16464
16161
  )
16465
16162
  });
16466
16163
  if (resumed !== void 0) return resumed;
16164
+ if (env.reviewReask !== void 0) {
16165
+ presentStructuralRejection(
16166
+ new CliUsageError(
16167
+ "inspector review reask requires a prior same-parent run to resume"
16168
+ ),
16169
+ io
16170
+ );
16171
+ return { exitCode: 2 };
16172
+ }
16467
16173
  }
16468
16174
  let admitted;
16469
16175
  try {
@@ -16724,9 +16430,12 @@ async function runPublicInstructionSeat(argv, env, io, role, parseArgv) {
16724
16430
  return { exitCode: 2 };
16725
16431
  }
16726
16432
  }
16433
+ const resumeInstruction = env.reviewReask ?? env.gateReviewInstruction;
16727
16434
  const summons = {
16728
- instruction: parsed.instruction,
16729
- instructionEmpty: parsed.instruction.trim() === "",
16435
+ ...resumeInstruction === void 0 ? {
16436
+ instruction: parsed.instruction,
16437
+ instructionEmpty: parsed.instruction.trim() === ""
16438
+ } : { instruction: resumeInstruction, instructionEmpty: false },
16730
16439
  attachmentPaths: parsed.attachmentPaths
16731
16440
  };
16732
16441
  if (role === "auditor" && auditorSourceRun !== void 0) {
@@ -16748,6 +16457,15 @@ async function runPublicInstructionSeat(argv, env, io, role, parseArgv) {
16748
16457
  })
16749
16458
  });
16750
16459
  if (resumed !== void 0) return resumed;
16460
+ if (env.reviewReask !== void 0) {
16461
+ presentStructuralRejection(
16462
+ new CliUsageError(
16463
+ "auditor review reask requires a prior same-parent run to resume"
16464
+ ),
16465
+ io
16466
+ );
16467
+ return { exitCode: 2 };
16468
+ }
16751
16469
  }
16752
16470
  let admitted;
16753
16471
  try {
@@ -17051,7 +16769,7 @@ __export(public_role_summons_exports, {
17051
16769
  summonGateOfficer: () => summonGateOfficer,
17052
16770
  summonPublicRole: () => summonPublicRole
17053
16771
  });
17054
- import { existsSync as existsSync10 } from "node:fs";
16772
+ import { existsSync as existsSync8 } from "node:fs";
17055
16773
  import { join as join26 } from "node:path";
17056
16774
  function createCapturingIo() {
17057
16775
  const chunks = [];
@@ -17075,7 +16793,7 @@ function parentDir(path) {
17075
16793
  function walkPackageRoot(start) {
17076
16794
  let dir = start;
17077
16795
  for (let i = 0; i < 12; i += 1) {
17078
- if (existsSync10(join26(dir, "package.json")) && existsSync10(join26(dir, "souls"))) {
16796
+ if (existsSync8(join26(dir, "package.json")) && existsSync8(join26(dir, "souls"))) {
17079
16797
  return dir;
17080
16798
  }
17081
16799
  const parent = parentDir(dir);
@@ -17214,7 +16932,11 @@ async function summonPublicRole(options) {
17214
16932
  // Host config passthrough only — same face as public CLI (#422 / #675).
17215
16933
  ...config.autoResumeLimit === void 0 ? {} : { autoResumeLimit: config.autoResumeLimit },
17216
16934
  // Parent cancellation reaches the nested activation's own turn dispatch.
17217
- ...options.signal === void 0 ? {} : { signal: options.signal }
16935
+ ...options.signal === void 0 ? {} : { signal: options.signal },
16936
+ // #753: reask rides the existing notary same-ticket resume summons.instruction.
16937
+ ...options.reviewReask === void 0 ? {} : { reviewReask: options.reviewReask },
16938
+ // #753/#750: new-submission pointers on same-parent resume (not conclusion re-ask).
16939
+ ...options.gateReviewInstruction === void 0 ? {} : { gateReviewInstruction: options.gateReviewInstruction }
17218
16940
  };
17219
16941
  const captured = options.io === void 0 ? createCapturingIo() : void 0;
17220
16942
  const io = options.io ?? captured.io;
@@ -17310,25 +17032,48 @@ async function summonGateOfficer(options) {
17310
17032
  const { homeFromRunDirectory: homeFromRunDirectory2 } = await Promise.resolve().then(() => (init_activation_ledger_topology(), activation_ledger_topology_exports));
17311
17033
  home = homeFromRunDirectory2(options.sourceRunDirectory);
17312
17034
  }
17035
+ let gateReviewInstruction;
17036
+ if (options.reask === void 0) {
17037
+ const { buildGateOfficerReviewInstruction: buildGateOfficerReviewInstruction2 } = await Promise.resolve().then(() => (init_auditor_dossier_tool(), auditor_dossier_tool_exports));
17038
+ gateReviewInstruction = buildGateOfficerReviewInstruction2({
17039
+ sourceRunDirectory: options.sourceRunDirectory,
17040
+ ...options.submissionCandidatePath === void 0 ? {} : { submissionCandidatePath: options.submissionCandidatePath }
17041
+ });
17042
+ }
17043
+ const common = {
17044
+ cwd: options.cwd,
17045
+ ...home === void 0 ? {} : { home },
17046
+ ...options.packageRoot === void 0 ? {} : { packageRoot: options.packageRoot },
17047
+ ...options.io === void 0 ? {} : { io: options.io },
17048
+ ...options.signal === void 0 ? {} : { signal: options.signal },
17049
+ ...options.reask === void 0 ? {} : { reviewReask: options.reask },
17050
+ ...gateReviewInstruction === void 0 ? {} : { gateReviewInstruction }
17051
+ };
17313
17052
  if (options.officer === "notary") {
17314
17053
  return summonPublicRole({
17315
17054
  role: "notary",
17316
17055
  argv: ["--source-run", options.sourceRunDirectory, "--project", options.cwd],
17317
- cwd: options.cwd,
17318
- ...home === void 0 ? {} : { home },
17319
- ...options.packageRoot === void 0 ? {} : { packageRoot: options.packageRoot },
17320
- ...options.io === void 0 ? {} : { io: options.io },
17321
- ...options.signal === void 0 ? {} : { signal: options.signal }
17056
+ ...common
17057
+ });
17058
+ }
17059
+ if (options.officer === "auditor") {
17060
+ const { AUDITOR_DOSSIER_PROMPT: AUDITOR_DOSSIER_PROMPT2 } = await Promise.resolve().then(() => (init_compliance_transport(), compliance_transport_exports));
17061
+ return summonPublicRole({
17062
+ role: "auditor",
17063
+ argv: [
17064
+ "--subject",
17065
+ "judge",
17066
+ "--source-run",
17067
+ options.sourceRunDirectory,
17068
+ AUDITOR_DOSSIER_PROMPT2
17069
+ ],
17070
+ ...common
17322
17071
  });
17323
17072
  }
17324
17073
  return summonPublicRole({
17325
17074
  role: "inspector",
17326
17075
  argv: [`\u5377\u5B97\u6307\u9488\uFF1A${options.sourceRunDirectory}`],
17327
- cwd: options.cwd,
17328
- ...home === void 0 ? {} : { home },
17329
- ...options.packageRoot === void 0 ? {} : { packageRoot: options.packageRoot },
17330
- ...options.io === void 0 ? {} : { io: options.io },
17331
- ...options.signal === void 0 ? {} : { signal: options.signal }
17076
+ ...common
17332
17077
  });
17333
17078
  }
17334
17079
  var AK_ROLE_PACKAGE_ROOT_ENV;
@@ -17340,6 +17085,18 @@ var init_public_role_summons = __esm({
17340
17085
  });
17341
17086
 
17342
17087
  // src/compliance-transport.ts
17088
+ var compliance_transport_exports = {};
17089
+ __export(compliance_transport_exports, {
17090
+ AUDITOR_COMPLIANCE_FAILURE_ENTRY_TYPE: () => AUDITOR_COMPLIANCE_FAILURE_ENTRY_TYPE,
17091
+ AUDITOR_DOSSIER_PROMPT: () => AUDITOR_DOSSIER_PROMPT,
17092
+ AUDITOR_PARENT_ATTEMPT_BINDING_ENTRY_TYPE: () => AUDITOR_PARENT_ATTEMPT_BINDING_ENTRY_TYPE,
17093
+ COMPLIANCE_RESPONSE_ENTRY_TYPE: () => COMPLIANCE_RESPONSE_ENTRY_TYPE,
17094
+ ComplianceResponseRetentionError: () => ComplianceResponseRetentionError,
17095
+ complianceDecisionSchema: () => complianceDecisionSchema,
17096
+ readComplianceCandidate: () => readComplianceCandidate,
17097
+ runComplianceAudit: () => runComplianceAudit,
17098
+ tryReadComplianceCandidate: () => tryReadComplianceCandidate
17099
+ });
17343
17100
  import { Type as Type14 } from "typebox";
17344
17101
  function readListField(value) {
17345
17102
  return Array.isArray(value) ? value : value === void 0 ? [] : [value];
@@ -17432,7 +17189,7 @@ async function runComplianceAudit(options) {
17432
17189
  const summoned = await summon(subject, runDirectory, options.signal);
17433
17190
  return await projectAuditorTerminal(summoned);
17434
17191
  }
17435
- var AUDITOR_DOSSIER_PROMPT, nonblank2, decisionGateSchema, complianceDecisionSchema, AUDITOR_PARENT_ATTEMPT_BINDING_ENTRY_TYPE, AUDITOR_COMPLIANCE_FAILURE_ENTRY_TYPE, ComplianceResponseRetentionError;
17192
+ var AUDITOR_DOSSIER_PROMPT, nonblank2, decisionGateSchema, complianceDecisionSchema, COMPLIANCE_RESPONSE_ENTRY_TYPE, AUDITOR_PARENT_ATTEMPT_BINDING_ENTRY_TYPE, AUDITOR_COMPLIANCE_FAILURE_ENTRY_TYPE, ComplianceResponseRetentionError;
17436
17193
  var init_compliance_transport = __esm({
17437
17194
  "src/compliance-transport.ts"() {
17438
17195
  "use strict";
@@ -17441,6 +17198,7 @@ var init_compliance_transport = __esm({
17441
17198
  nonblank2 = Type14.String({ minLength: 1, pattern: "\\S" });
17442
17199
  decisionGateSchema = Type14.Object({ question: nonblank2, options: Type14.Array(nonblank2, { minItems: 1 }) }, { additionalProperties: false });
17443
17200
  complianceDecisionSchema = Type14.Object({ status: Type14.Unknown({ description: "pass | bounce | escalate \u2014 \u5F62\u72B6\u6307\u5F15\uFF0C\u975E schema \u95F8" }), violations: Type14.Array(nonblank2, { description: "\u89C2\u5BDF\u5230\u7684\u5408\u89C4\u8FDD\u89C4" }), conflicts: Type14.Array(nonblank2, { description: "\u672A\u51B3\u6743\u5A01\u6216\u6267\u884C\u51B2\u7A81" }), decisionGate: Type14.Union([decisionGateSchema, Type14.Null()], { description: "\u5347\u7EA7\u95EE\u9898\u4E0E\u53EF\u9009\u9009\u9879" }) }, { additionalProperties: true, required: [] });
17201
+ COMPLIANCE_RESPONSE_ENTRY_TYPE = "ak_compliance_response";
17444
17202
  AUDITOR_PARENT_ATTEMPT_BINDING_ENTRY_TYPE = "ak_auditor_parent_attempt_binding";
17445
17203
  AUDITOR_COMPLIANCE_FAILURE_ENTRY_TYPE = "ak_auditor_compliance_failure";
17446
17204
  ComplianceResponseRetentionError = class extends Error {
@@ -17452,6 +17210,61 @@ var init_compliance_transport = __esm({
17452
17210
  }
17453
17211
  });
17454
17212
 
17213
+ // src/dossier-resolution.ts
17214
+ import { existsSync as existsSync9, statSync as statSync2 } from "node:fs";
17215
+ import { resolve as resolve12 } from "node:path";
17216
+ function resolveAuditDossier(env = process.env) {
17217
+ const raw = env[AUDIT_RUN_DIR_ENV];
17218
+ if (typeof raw !== "string" || raw.trim() === "") {
17219
+ return { status: "ok" };
17220
+ }
17221
+ const runDirectory = resolve12(raw);
17222
+ try {
17223
+ if (!existsSync9(runDirectory) || !statSync2(runDirectory).isDirectory()) {
17224
+ return { status: "incomplete", observation: { kind: "missing-dossier" } };
17225
+ }
17226
+ } catch {
17227
+ return { status: "incomplete", observation: { kind: "missing-dossier" } };
17228
+ }
17229
+ return { status: "ok", runDirectory };
17230
+ }
17231
+ function isRecord17(value) {
17232
+ return typeof value === "object" && value !== null && !Array.isArray(value);
17233
+ }
17234
+ function readDoctorAuditSubjects(context) {
17235
+ const entries = context.sessionManager.getEntries?.() ?? [];
17236
+ for (const entry of entries) {
17237
+ if (isRecord17(entry) && entry.type === "custom" && entry.customType === DOCTOR_CANDIDATE_ENTRY_TYPE) {
17238
+ return { status: "ok" };
17239
+ }
17240
+ }
17241
+ return { status: "incomplete", observation: { kind: "missing-subject", subject: "candidate-testimony" } };
17242
+ }
17243
+ function requireAuditMaterials(resolution) {
17244
+ if (resolution.status === "incomplete") {
17245
+ throw new AuditMaterialsUnavailableError(resolution.observation);
17246
+ }
17247
+ }
17248
+ var AUDIT_RUN_DIR_ENV, DOCTOR_CANDIDATE_ENTRY_TYPE, AuditMaterialsUnavailableError;
17249
+ var init_dossier_resolution = __esm({
17250
+ "src/dossier-resolution.ts"() {
17251
+ "use strict";
17252
+ AUDIT_RUN_DIR_ENV = "AK_ROLE_RUN_DIR";
17253
+ DOCTOR_CANDIDATE_ENTRY_TYPE = "ak_doctor_audit_candidate";
17254
+ AuditMaterialsUnavailableError = class extends Error {
17255
+ observation;
17256
+ candidate;
17257
+ constructor(observation) {
17258
+ const detail = observation.kind === "missing-subject" ? `${observation.kind}:${observation.subject}` : observation.kind;
17259
+ super(`Audit materials unavailable: ${detail}`);
17260
+ this.name = "AuditMaterialsUnavailableError";
17261
+ this.observation = observation;
17262
+ this.candidate = void 0;
17263
+ }
17264
+ };
17265
+ }
17266
+ });
17267
+
17455
17268
  // src/doctor-auditor.ts
17456
17269
  function createPiDoctorAuditor() {
17457
17270
  return async (options) => {
@@ -17685,7 +17498,7 @@ __export(archivist_record_entry_exports, {
17685
17498
  createRecordSessionOpen: () => createRecordSessionOpen,
17686
17499
  subjectKeyedRecordDirectory: () => subjectKeyedRecordDirectory
17687
17500
  });
17688
- import { existsSync as existsSync11, mkdirSync as mkdirSync4, readFileSync as readFileSync3, realpathSync as realpathSync2, writeFileSync as writeFileSync5 } from "node:fs";
17501
+ import { existsSync as existsSync10, mkdirSync as mkdirSync4, readFileSync as readFileSync3, realpathSync as realpathSync2, writeFileSync as writeFileSync5 } from "node:fs";
17689
17502
  import { dirname as dirname13, resolve as resolve13, join as join28 } from "node:path";
17690
17503
  import { SessionManager } from "@earendil-works/pi-coding-agent";
17691
17504
  function readCurrentSession(sessionDir) {
@@ -17768,7 +17581,7 @@ function createRecordSessionOpen(options) {
17768
17581
  sessionDir = physicallyContainedIn(ledgerHome, parentResolved) ? join28(dirname13(parentResolved), options.kind) : join28(activationBookDirectory(ledgerHome, resolveBookKeyFromGit(cwd)), options.kind);
17769
17582
  parentSession = parentFile;
17770
17583
  }
17771
- const nestAlreadyExists = existsSync11(sessionDir);
17584
+ const nestAlreadyExists = existsSync10(sessionDir);
17772
17585
  ensureRealDirectoryTree(ledgerHome, sessionDir);
17773
17586
  const mayResumeSameNest = options.subject !== void 0 || options.kind === WORKER_SUBMISSION_GATE_KIND;
17774
17587
  if (mayResumeSameNest && nestAlreadyExists) {
@@ -17786,7 +17599,7 @@ function createRecordSessionOpen(options) {
17786
17599
  );
17787
17600
  if (session.isPersisted()) {
17788
17601
  const file = session.getSessionFile();
17789
- if (file !== void 0 && !existsSync11(file)) {
17602
+ if (file !== void 0 && !existsSync10(file)) {
17790
17603
  const header = session.getHeader();
17791
17604
  if (header !== null && header.type === "session") {
17792
17605
  writeFileSync5(file, `${JSON.stringify(header)}
@@ -17814,7 +17627,7 @@ function bookDirectOfficerRunPointer(options) {
17814
17627
  ...options.runDirectory !== void 0 && options.runDirectory.trim() !== "" ? { runDirectory: options.runDirectory } : {}
17815
17628
  };
17816
17629
  writeFileSync5(
17817
- join28(nest, `${options.officer}-${Date.now().toString(36)}.pointer.json`),
17630
+ join28(nest, `${options.officer}.pointer.json`),
17818
17631
  `${JSON.stringify(pointer)}
17819
17632
  `,
17820
17633
  "utf8"
@@ -18765,9 +18578,158 @@ var init_engine_detour_tool = __esm({
18765
18578
  }
18766
18579
  });
18767
18580
 
18581
+ // src/gatekeeper-role.ts
18582
+ function gateSeatLabel(stage) {
18583
+ if (stage === "inspector") return "\u5BDF\u9662";
18584
+ if (stage === "auditor") return "\u5BA1\u5211\u9662";
18585
+ return "\u7B26\u5B9D\u90CE";
18586
+ }
18587
+ function gateOfficerForSubject(subject) {
18588
+ if (subject.kind === "worker_completion") return "inspector";
18589
+ if (subject.kind === "judge_compliance") return "auditor";
18590
+ return "notary";
18591
+ }
18592
+ function failureReason(error) {
18593
+ if (error instanceof AggregateError) return error.errors.map(failureReason).join("; ");
18594
+ return error instanceof Error ? `${error.name}: ${error.message}` : String(error);
18595
+ }
18596
+ function isRecord18(value) {
18597
+ return typeof value === "object" && value !== null && !Array.isArray(value);
18598
+ }
18599
+ function retainedReceipt(decision) {
18600
+ return decision === void 0 || isRecord18(decision) && Object.keys(decision).length === 0 ? MISSING_ARGUMENTS_SUBMISSION : decision;
18601
+ }
18602
+ function readRecord(value) {
18603
+ if (typeof value !== "object" || value === null || Array.isArray(value)) return void 0;
18604
+ return value;
18605
+ }
18606
+ function projectOfficerDecision(officer, decision, fallbackStatus) {
18607
+ const receipt = retainedReceipt(decision);
18608
+ const record4 = readRecord(decision);
18609
+ const status = (record4 !== void 0 && typeof record4.status === "string" ? record4.status : void 0) ?? fallbackStatus;
18610
+ if (status === "pass") {
18611
+ return { status: "pass", officer, receipt };
18612
+ }
18613
+ if (status === "bounce" || status === "escalate") {
18614
+ return { status, officer, receipt };
18615
+ }
18616
+ return { status: "needs_reask", officer, receipt };
18617
+ }
18618
+ function projectOfficerTerminal(officer, summoned) {
18619
+ const terminal = summoned.terminal;
18620
+ const outcome = terminal?.roleOutcome;
18621
+ if (outcome === void 0) {
18622
+ const detail = summoned.stderr?.trim();
18623
+ return {
18624
+ status: "transport_failure",
18625
+ stage: officer,
18626
+ reason: detail && detail.length > 0 ? `${gateSeatLabel(officer)} public summon exit ${summoned.exitCode}: ${detail}` : `${gateSeatLabel(officer)} public summon produced no terminal (exit ${summoned.exitCode})`,
18627
+ submission: summoned
18628
+ };
18629
+ }
18630
+ if (outcome.kind === "no_receipt") {
18631
+ return {
18632
+ status: "no_receipt",
18633
+ stage: officer,
18634
+ reason: `${gateSeatLabel(officer)}\u672A\u4EA7\u751F\u5DF2\u63A5\u53D7\u56DE\u6267\u5373\u6563\u5C40`,
18635
+ facts: outcome
18636
+ };
18637
+ }
18638
+ if (outcome.kind === "failure") {
18639
+ return {
18640
+ status: "transport_failure",
18641
+ stage: officer,
18642
+ reason: outcome.diagnostic,
18643
+ submission: outcome.decisiveFacts
18644
+ };
18645
+ }
18646
+ if (outcome.kind === "audit_escalation") {
18647
+ return {
18648
+ status: "escalate",
18649
+ officer,
18650
+ receipt: retainedReceipt(outcome.decisiveFacts)
18651
+ };
18652
+ }
18653
+ if (outcome.kind === "accepted") {
18654
+ const facts = outcome.decisiveFacts;
18655
+ if (isRecord18(facts) && Object.keys(facts).length > 0) {
18656
+ return projectOfficerDecision(officer, facts, outcome.status);
18657
+ }
18658
+ return projectOfficerDecision(officer, { status: outcome.status });
18659
+ }
18660
+ return {
18661
+ status: "needs_reask",
18662
+ officer,
18663
+ receipt: retainedReceipt(outcome)
18664
+ };
18665
+ }
18666
+ async function projectGatekeeperRun(options) {
18667
+ const officer = gateOfficerForSubject(options.subject);
18668
+ const runDirectory = options.runDirectory ?? auditorRunDirectory(options.context);
18669
+ if (runDirectory === void 0) {
18670
+ return {
18671
+ officer,
18672
+ result: {
18673
+ status: "transport_failure",
18674
+ stage: officer,
18675
+ reason: `${gateSeatLabel(officer)} requires a parent run directory pointer`
18676
+ }
18677
+ };
18678
+ }
18679
+ const submissionCandidatePath = persistGateSubmissionCandidate(
18680
+ runDirectory,
18681
+ options.context
18682
+ );
18683
+ let summoned;
18684
+ try {
18685
+ const summon = options.summonOfficer ?? (async (nextOfficer, sourceRunDirectory, officerSignal, reask) => {
18686
+ const { summonGateOfficer: summonGateOfficer2 } = await Promise.resolve().then(() => (init_public_role_summons(), public_role_summons_exports));
18687
+ return summonGateOfficer2({
18688
+ officer: nextOfficer,
18689
+ sourceRunDirectory,
18690
+ cwd: options.context.cwd ?? process.cwd(),
18691
+ ...officerSignal === void 0 ? {} : { signal: officerSignal },
18692
+ ...reask === void 0 ? {} : { reask },
18693
+ ...submissionCandidatePath === void 0 ? {} : { submissionCandidatePath }
18694
+ });
18695
+ });
18696
+ summoned = await summon(officer, runDirectory, options.signal, options.reask);
18697
+ } catch (error) {
18698
+ return {
18699
+ officer,
18700
+ result: { status: "transport_failure", stage: officer, reason: failureReason(error) }
18701
+ };
18702
+ }
18703
+ return {
18704
+ officer,
18705
+ result: projectOfficerTerminal(officer, summoned),
18706
+ summoned
18707
+ };
18708
+ }
18709
+ var GATEKEEPER_TOOL_SPEC, MISSING_ARGUMENTS_SUBMISSION, OFFICER_CONCLUSION_REASK;
18710
+ var init_gatekeeper_role = __esm({
18711
+ "src/gatekeeper-role.ts"() {
18712
+ "use strict";
18713
+ init_auditor_dossier_tool();
18714
+ init_submission_errors();
18715
+ init_inspector_contracts();
18716
+ init_gatekeeper_output();
18717
+ init_submission_errors();
18718
+ GATEKEEPER_TOOL_SPEC = {
18719
+ name: GATEKEEPER_OUTPUT_TOOL_NAME,
18720
+ label: "\u95E8\u4E0B\u7701\u51B3\u8BAE",
18721
+ description: "\u95E8\u4E0B\u7701\u7EC8\u5C40\u51B3\u8BAE\uFF0C\u72B6\u6001\u4E3A dispatch \u6216 pass\u3002",
18722
+ promptSnippet: "\u95E8\u4E0B\u7701\u51B3\u8BAE",
18723
+ parameters: gatekeeperOutputSchema
18724
+ };
18725
+ MISSING_ARGUMENTS_SUBMISSION = Object.freeze({ missing: "arguments" });
18726
+ OFFICER_CONCLUSION_REASK = "\u4E0A\u6B21\u4EA4\u5377\u7684\u7ED3\u8BBA\u4E0D\u662F pass\u3001bounce\u3001escalate \u4E09\u6001\u4E4B\u4E00\u3002\u8BF7\u91CD\u65B0\u8F93\u51FA\uFF0C\u7ED3\u8BBA\u5B57\u6BB5\u5199\u660E\u5176\u4E00\uFF1B\u6253\u56DE\u6216\u4E0A\u5448\u7684\u8BDD\u5C31\u662F\u7ED9\u5BF9\u65B9\u770B\u7684\u539F\u6587\u3002";
18727
+ }
18728
+ });
18729
+
18768
18730
  // src/gatekeeper-pass-envelope.ts
18769
18731
  function bookDirectOfficerPointer(context, officer, result, summoned) {
18770
- if (result.status !== "pass" && result.status !== "bounce" && result.status !== "escalate" && result.status !== "unreadable") {
18732
+ if (result.status !== "pass" && result.status !== "bounce" && result.status !== "escalate" && result.status !== "needs_reask") {
18771
18733
  return;
18772
18734
  }
18773
18735
  const parentFile = context.sessionManager?.getSessionFile?.();
@@ -18784,39 +18746,43 @@ function bookDirectOfficerPointer(context, officer, result, summoned) {
18784
18746
  });
18785
18747
  }
18786
18748
  async function requireGatekeeperPass(options) {
18787
- const projected = await projectGatekeeperRun({
18788
- context: options.context,
18789
- subject: options.subject,
18790
- ...options.signal === void 0 ? {} : { signal: options.signal },
18791
- ...options.summonOfficer === void 0 ? {} : { summonOfficer: options.summonOfficer }
18792
- });
18793
- const gatekeeper = projected.result;
18794
- if (projected.summoned !== void 0) {
18795
- try {
18796
- bookDirectOfficerPointer(
18797
- options.context,
18798
- projected.officer,
18799
- gatekeeper,
18800
- projected.summoned
18801
- );
18802
- } catch (error) {
18749
+ let reask;
18750
+ for (; ; ) {
18751
+ const projected = await projectGatekeeperRun({
18752
+ context: options.context,
18753
+ subject: options.subject,
18754
+ ...options.signal === void 0 ? {} : { signal: options.signal },
18755
+ ...options.summonOfficer === void 0 ? {} : { summonOfficer: options.summonOfficer },
18756
+ ...reask === void 0 ? {} : { reask }
18757
+ });
18758
+ const gatekeeper = projected.result;
18759
+ if (projected.summoned !== void 0) {
18760
+ try {
18761
+ bookDirectOfficerPointer(
18762
+ options.context,
18763
+ projected.officer,
18764
+ gatekeeper,
18765
+ projected.summoned
18766
+ );
18767
+ } catch (error) {
18768
+ options.hostActions.failInfrastructure(error, options.context, options.toolCallId);
18769
+ }
18770
+ }
18771
+ if (gatekeeper.status === "pass") return;
18772
+ if (gatekeeper.status === "needs_reask") {
18773
+ reask = OFFICER_CONCLUSION_REASK;
18774
+ continue;
18775
+ }
18776
+ if (gatekeeper.status === "transport_failure") {
18777
+ const error = new Error(`\u4EA4\u5377\u95F8 transport_failure\uFF08${gatekeeper.stage}\uFF09\uFF1A${gatekeeper.reason}`);
18778
+ error.stage = gatekeeper.stage;
18779
+ error.reason = gatekeeper.reason;
18780
+ if (gatekeeper.submission !== void 0) error.submission = gatekeeper.submission;
18803
18781
  options.hostActions.failInfrastructure(error, options.context, options.toolCallId);
18804
18782
  }
18783
+ options.hostActions.bindSubmissionNonPass(options.toolCallId, gatekeeper);
18784
+ throw new GatekeeperDecisionError(gatekeeper);
18805
18785
  }
18806
- if (gatekeeper.status === "pass") return;
18807
- if (gatekeeper.status === "unreadable") return;
18808
- if (gatekeeper.status === "transport_failure") {
18809
- const error = new Error(`\u4EA4\u5377\u95F8 transport_failure\uFF08${gatekeeper.stage}\uFF09\uFF1A${gatekeeper.reason}`);
18810
- error.stage = gatekeeper.stage;
18811
- error.reason = gatekeeper.reason;
18812
- if (gatekeeper.submission !== void 0) error.submission = gatekeeper.submission;
18813
- options.hostActions.failInfrastructure(error, options.context, options.toolCallId);
18814
- }
18815
- if (gatekeeper.status === "escalate") {
18816
- throw new GatekeeperEscalationError(gatekeeper);
18817
- }
18818
- options.hostActions.bindSubmissionNonPass(options.toolCallId, gatekeeper);
18819
- throw new GatekeeperDecisionError(gatekeeper);
18820
18786
  }
18821
18787
  var init_gatekeeper_pass_envelope = __esm({
18822
18788
  "src/gatekeeper-pass-envelope.ts"() {
@@ -20071,7 +20037,7 @@ function createDoctorRoleRuntime(pi, dependencies, host) {
20071
20037
  const details = testimony.status === "completed" ? { ...testimony, cost: activation.patient.cost } : testimony;
20072
20038
  const acceptedDetails = details;
20073
20039
  return disposeComplianceDecision(audit, { pass: (usage) => ({ content: [{ type: "text", text: DOCTOR_ACCEPTED_TEXT }], details: acceptedDetails, terminate: true, ...usage === void 0 ? {} : { usage } }), noReceipt: (auditNoReceipt, usageProjection) => ({ content: [{ type: "text", text: DOCTOR_ACCEPTED_AUDIT_NO_RECEIPT_TEXT }], details: { ...acceptedDetails, auditNoReceipt }, terminate: true, ...usageProjection }), received: (auditReceived, usageProjection) => ({ content: [{ type: "text", text: DOCTOR_ACCEPTED_TEXT }], details: { ...acceptedDetails, audit: auditReceived.reply }, terminate: true, ...usageProjection }), bounce: (violations) => {
20074
- throw new Error(`\u592A\u533B\u7F72\u56DE\u6267\u8FDD soul\uFF1A${violations.join("; ")}`);
20040
+ throw new Error(`\u592A\u533B\u7F72\u56DE\u6267\u8FDD soul\uFF1A${joinReadableGateItems(violations)}`);
20075
20041
  }, escalate: (result) => result }, acceptedDetails);
20076
20042
  } });
20077
20043
  pi.on("before_agent_start", (event) => {
@@ -20102,6 +20068,7 @@ var init_doctor_role = __esm({
20102
20068
  "use strict";
20103
20069
  init_audit_escalation();
20104
20070
  init_compliance_transport();
20071
+ init_readable_gate_item();
20105
20072
  init_dossier_resolution();
20106
20073
  init_doctor_contracts();
20107
20074
  init_sitian_facade();
@@ -20185,11 +20152,9 @@ function createNotaryRoleRuntime(pi, dependencies, host) {
20185
20152
  if (activation === void 0) {
20186
20153
  throw new Error("\u7B26\u5B9D\u90CE\u672A\u6FC0\u6D3B");
20187
20154
  }
20188
- const lawful = projectLawfulNotaryOutput(parameters);
20189
- const details = lawful ?? retainNotarySubmission(parameters);
20190
20155
  return {
20191
20156
  content: [{ type: "text", text: NOTARY_ACCEPTED_TEXT }],
20192
- details,
20157
+ details: parameters,
20193
20158
  terminate: true
20194
20159
  };
20195
20160
  }
@@ -20734,11 +20699,23 @@ function createJudgeRoleRuntime(pi, dependencies, hostActions) {
20734
20699
  pi.registerTool({
20735
20700
  name: JUDGE_OUTPUT_TOOL_NAME,
20736
20701
  label: "\u5927\u7406\u5BFA\u8F93\u51FA",
20737
- description: "\u63D0\u4EA4\u5927\u7406\u5BFA\u7EC8\u5C40\u5224\u8BCD\uFF1B\u53D7\u7406\u524D\u7ECF\u5BA1\u5211\u9662\u5BA1\u8BA1\u3002",
20702
+ description: "\u63D0\u4EA4\u5927\u7406\u5BFA\u7EC8\u5C40\u5224\u8BCD\uFF1B\u53D7\u7406\u524D\u7ECF\u7B26\u5B9D\u90CE\u5185\u95F8\u4E0E\u5BA1\u5211\u9662\u5408\u89C4\u5BA1\u6838\u3002",
20738
20703
  promptSnippet: "\u63D0\u4EA4\u5927\u7406\u5BFA\u7EC8\u5C40\u5224\u8BCD",
20739
20704
  parameters: judgeVerdictSchema,
20740
20705
  async execute(toolCallId, parameters, signal, _onUpdate, ctx) {
20741
20706
  if (soul === void 0) throw new Error("\u5927\u7406\u5BFA\u804C\u5206\u672A\u88C5\u8F7D");
20707
+ const rawStatus = parameters !== null && typeof parameters === "object" && !Array.isArray(parameters) && typeof parameters.judgeStatus === "string" ? parameters.judgeStatus : void 0;
20708
+ if (rawStatus === void 0 || !JUDGE_QUEUE_STATUSES.has(rawStatus)) {
20709
+ throw new ParentQueueReaskError(JUDGE_STATUS_REASK);
20710
+ }
20711
+ if (rawStatus === "escalate") {
20712
+ const verdict2 = validateVerdict(parameters);
20713
+ return {
20714
+ content: [{ type: "text", text: JUDGE_ACCEPTED_TEXT }],
20715
+ details: verdict2,
20716
+ terminate: true
20717
+ };
20718
+ }
20742
20719
  const verdict = validateVerdict(parameters);
20743
20720
  await pi.requireGatekeeperPass({
20744
20721
  context: ctx,
@@ -20747,47 +20724,18 @@ function createJudgeRoleRuntime(pi, dependencies, hostActions) {
20747
20724
  hostActions,
20748
20725
  toolCallId
20749
20726
  });
20750
- let audit;
20751
- try {
20752
- audit = await dependencies.auditSoulCompliance(
20753
- signal === void 0 ? { context: ctx } : { context: ctx, signal }
20754
- );
20755
- } catch (error) {
20756
- hostActions.failInfrastructure(error, ctx, toolCallId);
20757
- }
20758
- const acceptedDetails = verdict;
20759
- return disposeComplianceDecision(
20760
- audit,
20761
- {
20762
- pass: (usage) => ({
20763
- content: [{ type: "text", text: JUDGE_ACCEPTED_TEXT }],
20764
- details: acceptedDetails,
20765
- terminate: true,
20766
- ...usage === void 0 ? {} : { usage }
20767
- }),
20768
- noReceipt: (auditNoReceipt, usageProjection) => ({
20769
- content: [{ type: "text", text: JUDGE_ACCEPTED_AUDIT_NO_RECEIPT_TEXT }],
20770
- details: { ...acceptedDetails, auditNoReceipt },
20771
- terminate: true,
20772
- ...usageProjection
20773
- }),
20774
- // #757: parent stands with auditor raw reply — no unreadable judgment.
20775
- received: (auditReceived, usageProjection) => ({
20776
- content: [{ type: "text", text: JUDGE_ACCEPTED_TEXT }],
20777
- details: { ...acceptedDetails, audit: auditReceived.reply },
20778
- terminate: true,
20779
- ...usageProjection
20780
- }),
20781
- bounce: (violations) => {
20782
- throw new Error(
20783
- `\u5927\u7406\u5BFA\u56DE\u6267\u8FDD soul\uFF1A${violations.join("; ")}`
20784
- );
20785
- },
20786
- escalate: (result) => result
20787
- },
20788
- // #380: escalate deliveredOutput must carry the same mechanical projection.
20789
- acceptedDetails
20790
- );
20727
+ await pi.requireGatekeeperPass({
20728
+ context: ctx,
20729
+ subject: { kind: "judge_compliance" },
20730
+ ...signal === void 0 ? {} : { signal },
20731
+ hostActions,
20732
+ toolCallId
20733
+ });
20734
+ return {
20735
+ content: [{ type: "text", text: JUDGE_ACCEPTED_TEXT }],
20736
+ details: verdict,
20737
+ terminate: true
20738
+ };
20791
20739
  }
20792
20740
  });
20793
20741
  pi.on("before_agent_start", (event) => {
@@ -20804,14 +20752,16 @@ ${soul}
20804
20752
  }
20805
20753
  };
20806
20754
  }
20807
- var judgeVerdictSchema;
20755
+ var JUDGE_QUEUE_STATUSES, JUDGE_STATUS_REASK, judgeVerdictSchema;
20808
20756
  var init_judge_role = __esm({
20809
20757
  "src/judge-role.ts"() {
20810
20758
  "use strict";
20811
20759
  init_host_contracts();
20812
- init_audit_escalation();
20813
20760
  init_terminating_infrastructure();
20761
+ init_submission_errors();
20814
20762
  init_judge_output();
20763
+ JUDGE_QUEUE_STATUSES = /* @__PURE__ */ new Set(["converged", "continue", "escalate"]);
20764
+ JUDGE_STATUS_REASK = "judgeStatus \u4E0D\u662F converged\u3001continue\u3001escalate \u4E09\u6001\u4E4B\u4E00\u3002\u8BF7\u91CD\u65B0\u4EA4\u5377\uFF0Cstatus \u5199\u660E\u5176\u4E00\u3002";
20815
20765
  judgeVerdictSchema = withInfrastructureFailureDeclaration(
20816
20766
  Type24.Object(
20817
20767
  {
@@ -21220,7 +21170,7 @@ var init_reviewer_role = __esm({
21220
21170
 
21221
21171
  // src/worker-submission-gates.ts
21222
21172
  import { execFileSync as execFileSync4 } from "node:child_process";
21223
- import { existsSync as existsSync12, lstatSync as lstatSync3, readdirSync as readdirSync2, readFileSync as readFileSync5, rmdirSync, rmSync } from "node:fs";
21173
+ import { existsSync as existsSync11, lstatSync as lstatSync3, readdirSync as readdirSync2, readFileSync as readFileSync5, rmdirSync, rmSync } from "node:fs";
21224
21174
  import { resolve as resolve18 } from "node:path";
21225
21175
  function git2(cwd, args) {
21226
21176
  return execFileSync4("git", args, {
@@ -21241,7 +21191,7 @@ function statusOf(error) {
21241
21191
  return typeof error === "object" && error !== null && "status" in error ? error.status : void 0;
21242
21192
  }
21243
21193
  function tryGetAll(file, key) {
21244
- if (!existsSync12(file)) return [];
21194
+ if (!existsSync11(file)) return [];
21245
21195
  try {
21246
21196
  const out = gitFile(file, ["--get-all", key]);
21247
21197
  return out.length === 0 ? [] : out.split("\n");
@@ -21251,7 +21201,7 @@ function tryGetAll(file, key) {
21251
21201
  }
21252
21202
  }
21253
21203
  function ownedHook(path) {
21254
- if (!existsSync12(path)) return false;
21204
+ if (!existsSync11(path)) return false;
21255
21205
  return readFileSync5(path, "utf8").includes(HOOK_MARKER);
21256
21206
  }
21257
21207
  function escapeGitConfigValueRegex(value) {
@@ -21278,11 +21228,11 @@ function rmOwnedDir(dir) {
21278
21228
  const hookPath = resolve18(dir, HOOK_FILE);
21279
21229
  if (!ownedHook(hookPath)) return;
21280
21230
  rmSync(hookPath, { force: true });
21281
- if (existsSync12(dir) && readdirSync2(dir).length === 0) rmdirSync(dir);
21231
+ if (existsSync11(dir) && readdirSync2(dir).length === 0) rmdirSync(dir);
21282
21232
  }
21283
21233
  function linkedGitDirs(commonDir) {
21284
21234
  const root = resolve18(commonDir, "worktrees");
21285
- if (!existsSync12(root)) return [];
21235
+ if (!existsSync11(root)) return [];
21286
21236
  return readdirSync2(root).map((name) => resolve18(root, name)).filter((dir) => lstatSync3(dir).isDirectory());
21287
21237
  }
21288
21238
  function uninstallPackageWorkerHooks(cwd) {
@@ -21307,7 +21257,7 @@ function uninstallPackageWorkerHooks(cwd) {
21307
21257
  rmOwnedDir(resolve18(gitDir, HOOKS_DIR));
21308
21258
  }
21309
21259
  }
21310
- function isRecord20(value) {
21260
+ function isRecord19(value) {
21311
21261
  return typeof value === "object" && value !== null && !Array.isArray(value);
21312
21262
  }
21313
21263
  function unfinishedReasonPresent(details) {
@@ -21323,7 +21273,7 @@ function readGateState(session) {
21323
21273
  if (entry.type !== "custom") continue;
21324
21274
  if (entry.customType === WORKER_COMMIT_BASELINE_ENTRY_TYPE) {
21325
21275
  const data = entry.data;
21326
- if (isRecord20(data) && (data.head === null || typeof data.head === "string")) {
21276
+ if (isRecord19(data) && (data.head === null || typeof data.head === "string")) {
21327
21277
  baseline = data.head;
21328
21278
  }
21329
21279
  } else if (entry.customType === WORKER_COMMIT_REMINDER_BOUNCE_ENTRY_TYPE) {
@@ -22435,7 +22385,15 @@ function loadFrozenDiaristCatalog(getFlag) {
22435
22385
  return loadDiaristSourceCatalog(raw);
22436
22386
  }
22437
22387
  function createCountersignRoleRuntime(roleHost, dependencies, hostActions) {
22438
- const beforeAccept = hostActions !== void 0 && roleHost.requireGatekeeperPass !== void 0 ? async ({ toolCallId, signal, ctx }) => {
22388
+ const beforeAccept = hostActions !== void 0 && roleHost.requireGatekeeperPass !== void 0 ? async ({ toolCallId, parameters, signal, ctx }) => {
22389
+ const record4 = parameters !== null && typeof parameters === "object" && !Array.isArray(parameters) ? parameters : void 0;
22390
+ const status = record4 !== void 0 && typeof record4.countersignStatus === "string" ? record4.countersignStatus : void 0;
22391
+ if (status === void 0 || !COUNTERSIGN_QUEUE_STATUSES.has(status)) {
22392
+ throw new ParentQueueReaskError(COUNTERSIGN_STATUS_REASK);
22393
+ }
22394
+ if (status === "escalate") {
22395
+ return void 0;
22396
+ }
22439
22397
  await roleHost.requireGatekeeperPass({
22440
22398
  context: ctx,
22441
22399
  subject: { kind: "countersign_verdict" },
@@ -22745,8 +22703,7 @@ function createRoleRuntimeExtension(dependencies) {
22745
22703
  const judge = createJudgeRoleRuntime(
22746
22704
  roleHost,
22747
22705
  {
22748
- loadSoul: dependencies.loadJudgeSoul,
22749
- auditSoulCompliance: dependencies.auditSoulCompliance
22706
+ loadSoul: dependencies.loadJudgeSoul
22750
22707
  },
22751
22708
  hostActions
22752
22709
  );
@@ -23175,7 +23132,7 @@ function createRoleRuntimeExtension(dependencies) {
23175
23132
  });
23176
23133
  };
23177
23134
  }
23178
- var REVIEWER_TRANSPORT_FLAGS, NOTARY_TRANSPORT_FLAGS, GLEANER_LEFT_TRANSPORT_FLAGS, DIARIST_TRANSPORT_FLAGS, ActivationBarrierError, WORKFLOW_ROLES, ROLE_FLAG;
23135
+ var REVIEWER_TRANSPORT_FLAGS, NOTARY_TRANSPORT_FLAGS, GLEANER_LEFT_TRANSPORT_FLAGS, DIARIST_TRANSPORT_FLAGS, ActivationBarrierError, WORKFLOW_ROLES, ROLE_FLAG, COUNTERSIGN_QUEUE_STATUSES, COUNTERSIGN_STATUS_REASK;
23179
23136
  var init_role_runtime = __esm({
23180
23137
  "src/role-runtime.ts"() {
23181
23138
  "use strict";
@@ -23233,6 +23190,8 @@ var init_role_runtime = __esm({
23233
23190
  init_activation_reconciliation();
23234
23191
  init_tool_execution_observation();
23235
23192
  init_gatekeeper_role();
23193
+ init_gatekeeper_role();
23194
+ init_submission_errors();
23236
23195
  init_doctor_role();
23237
23196
  init_doctor_contracts();
23238
23197
  init_doctor_evidence();
@@ -23314,6 +23273,8 @@ var init_role_runtime = __esm({
23314
23273
  type: "string"
23315
23274
  }
23316
23275
  };
23276
+ COUNTERSIGN_QUEUE_STATUSES = /* @__PURE__ */ new Set(["converged", "continue", "escalate"]);
23277
+ COUNTERSIGN_STATUS_REASK = "countersignStatus \u4E0D\u662F converged\u3001continue\u3001escalate \u4E09\u6001\u4E4B\u4E00\u3002\u8BF7\u91CD\u65B0\u4EA4\u5377\uFF0Cstatus \u5199\u660E\u5176\u4E00\u3002";
23317
23278
  }
23318
23279
  });
23319
23280
 
@@ -24772,7 +24733,6 @@ async function loadCanonicalSkillBinding(name) {
24772
24733
  init_collector_github();
24773
24734
  init_doctor_auditor();
24774
24735
  init_doctor_evidence();
24775
- init_judge_auditor();
24776
24736
  init_merger_git_state();
24777
24737
  init_navigator_attendance();
24778
24738
 
@@ -25439,7 +25399,7 @@ async function prepareAcpRoleEnvelope(options) {
25439
25399
  const record4 = details;
25440
25400
  if (record4.cause === "infrastructure") return;
25441
25401
  if (record4.kind === "role_infrastructure_failure") return;
25442
- const code = typeof record4.code === "string" && record4.code.length > 0 ? record4.code : record4.status === "bounce" || record4.status === "no_receipt" || record4.status === "unreadable" ? record4.status : void 0;
25402
+ const code = typeof record4.code === "string" && record4.code.length > 0 ? record4.code : record4.status === "bounce" || record4.status === "escalate" || record4.status === "no_receipt" ? record4.status : void 0;
25443
25403
  if (code === void 0) return;
25444
25404
  rejection = { code, toolCallIds: [toolCallId] };
25445
25405
  }
@@ -25803,7 +25763,6 @@ var navigatorRoutePlaybookPath = fileURLToPath3(
25803
25763
  new URL("../../resources/navigator-route-playbook.md", import.meta.url)
25804
25764
  );
25805
25765
  function createAcpRoleRuntimeDependencies(packageRoot) {
25806
- const judgeAuditor = createPiJudgeAuditor();
25807
25766
  const doctorAuditor = createPiDoctorAuditor();
25808
25767
  const reviewerAgent = createPerDispatchReviewerAgent({ packageRoot });
25809
25768
  const navigatorSessionFactory = createNativeNavigatorSessionFactory();
@@ -25841,8 +25800,7 @@ function createAcpRoleRuntimeDependencies(packageRoot) {
25841
25800
  }
25842
25801
  return loadCanonicalSkillBinding(name);
25843
25802
  },
25844
- // #590: four sub-legs on the shared institutional child seam (host-neutral).
25845
- auditSoulCompliance: (options) => judgeAuditor(options),
25803
+ // #590: doctor compliance still on disposeCompliance path; judge→auditor is gate queue (#756).
25846
25804
  auditDoctorCompliance: (options) => doctorAuditor(options),
25847
25805
  runReviewerDispatch: (dispatch, options) => reviewerAgent.run(dispatch, options),
25848
25806
  shutdownReviewerAgent: () => reviewerAgent.shutdown(),