@akagilnc/pi-workflow-roles 0.1.5406 → 0.1.5475

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 (93) hide show
  1. package/CLAUDE.md +1 -1
  2. package/README.md +42 -55
  3. package/README.zh-CN.md +59 -73
  4. package/THIRD_PARTY_NOTICES.md +4 -7
  5. package/dist/acp-host/production-host.js +8261 -9073
  6. package/dist/collector-tool-schemas.js +1 -1
  7. package/dist/compliance-transport.js +2 -5
  8. package/dist/engine-detour-usage.js +3 -30
  9. package/dist/gatekeeper-role.js +4 -18
  10. package/dist/headless-host/description.js +0 -209
  11. package/dist/headless-host/production-host.js +6973 -8035
  12. package/dist/host-contracts.js +8 -0
  13. package/dist/migrate-book-topology.js +30 -27
  14. package/dist/packaged-role-registry.js +1 -9
  15. package/dist/pi/role-turn-host.js +37 -19
  16. package/dist/public-cli/auto-resume.js +29 -66
  17. package/dist/public-cli/countersign-run.js +4 -18
  18. package/dist/public-cli/instruction-seat-run.js +59 -76
  19. package/dist/public-cli/main.js +9844 -10720
  20. package/dist/public-cli/option-definitions.js +1 -1
  21. package/dist/public-cli/post-admission.js +204 -285
  22. package/dist/public-cli/process-cancel.js +8 -0
  23. package/dist/public-cli/run-lifecycle.js +24 -94
  24. package/dist/public-cli/settlement.js +614 -1524
  25. package/dist/public-cli/terminal.js +23 -53
  26. package/dist/public-role-summons.js +3 -8
  27. package/dist/receipt-delivery-policy.js +11 -12
  28. package/dist/run-terminal-artifacts.js +19 -14
  29. package/dist/serialize-thrown-value.js +7 -1
  30. package/dist/submission-ledger.js +21 -89
  31. package/package.json +1 -1
  32. package/packets/fixer-repair.md +3 -1
  33. package/packets/judge-apply.md +7 -16
  34. package/packets/judge-authority.md +7 -17
  35. package/packets/judge-plan.md +7 -18
  36. package/packets/judge-review.md +8 -22
  37. package/packets/judge-submission.md +4 -7
  38. package/resources/collector-bot-handbook.md +2 -2
  39. package/resources/diarist-collect.md +2 -2
  40. package/resources/engine-dispatch.md +2 -2
  41. package/resources/navigator-route-playbook.md +1 -1
  42. package/resources/secretariat-ticket-identity.md +1 -1
  43. package/scripts/build-package.mjs +0 -2
  44. package/souls/coder-output-guide.md +3 -3
  45. package/souls/coder.md +2 -3
  46. package/souls/doctor-auditor.md +0 -3
  47. package/souls/fixer-auditor.md +0 -2
  48. package/souls/fixer-output-guide.md +3 -3
  49. package/souls/fixer.md +2 -2
  50. package/souls/gate-output-guide.md +1 -1
  51. package/souls/quality-law.md +2 -0
  52. package/src/acp-host/role-turn-host.ts +168 -75
  53. package/src/collector-tool-schemas.ts +1 -1
  54. package/src/compliance-transport.ts +3 -6
  55. package/src/engine-detour-usage.ts +3 -33
  56. package/src/external-host-turn-loop.ts +81 -36
  57. package/src/gatekeeper-role.ts +5 -20
  58. package/src/headless-host/description.ts +4 -214
  59. package/src/headless-host/production-host.ts +2 -1
  60. package/src/headless-host/role-turn-host.ts +153 -186
  61. package/src/host-contracts.ts +13 -10
  62. package/src/navigator-public-session.ts +1 -1
  63. package/src/navigator-session-contracts.ts +1 -1
  64. package/src/package-contracts/gatekeeper-output.ts +1 -1
  65. package/src/package-contracts/navigator-output.ts +1 -1
  66. package/src/package-contracts/terminating-infrastructure.ts +1 -1
  67. package/src/packaged-role-registry.ts +2 -10
  68. package/src/pi/adapter.ts +0 -3
  69. package/src/pi/role-turn-host.ts +42 -28
  70. package/src/prepared-role-turn.ts +2 -0
  71. package/src/public-cli/auto-resume.ts +27 -66
  72. package/src/public-cli/countersign-run.ts +4 -22
  73. package/src/public-cli/instruction-seat-run.ts +79 -80
  74. package/src/public-cli/option-definitions.ts +1 -1
  75. package/src/public-cli/post-admission.ts +264 -340
  76. package/src/public-cli/process-cancel.ts +9 -0
  77. package/src/public-cli/run-lifecycle.ts +25 -126
  78. package/src/public-cli/settlement.ts +792 -1912
  79. package/src/public-cli/terminal.ts +29 -69
  80. package/src/public-role-summons.ts +3 -8
  81. package/src/receipt-delivery-policy.ts +11 -12
  82. package/src/role-envelope.ts +16 -9
  83. package/src/role-runtime.ts +14 -81
  84. package/src/run-terminal-artifacts.ts +21 -17
  85. package/src/serialize-thrown-value.ts +7 -1
  86. package/src/submission-ledger.ts +30 -116
  87. package/dist/audit-escalation.js +0 -7
  88. package/dist/pi/known-failure.js +0 -51
  89. package/dist/typed-provider-http.js +0 -57
  90. package/dist/upstream-error-testimony.js +0 -19
  91. package/src/pi/known-failure.ts +0 -76
  92. package/src/typed-provider-http.ts +0 -89
  93. package/src/upstream-error-testimony.ts +0 -45
@@ -29,12 +29,13 @@ import { packagedAdmitsCountersign, packagedBindsBoardTicket, packagedRebindSour
29
29
  import { readAuditorResumeBinding } from "../auditor-soul.js";
30
30
  import { CliUsageError } from "./cli-errors.js";
31
31
  import { admitPublicRole, bindAdmittedTicketNumber, buildInstructionTransportPrompt, materializeCountersignInvocation, persistAdmittedSourceRunPath, recordAdmittedCorrelation, recordChildDiaristRun, relocateAdmittedRunToTicket, withPreparedAttachments, } from "./invocation.js";
32
- import { presentControlledFailure, prepareSummonsResumeMaterials, roleTurnOptions, runPostAdmissionOneShot, runPostAdmissionResumable, runPostAdmissionSeatResume, showResumeErrorPointer, resumeTurnRequestProjectionOptions, } from "./post-admission.js";
32
+ import { presentControlledFailure, packageFaultNoteFor, prepareSummonsResumeMaterials, roleTurnOptions, runPostAdmissionOneShot, runPostAdmissionResumable, runPostAdmissionSeatResume, showResumeErrorPointer, resumeTurnRequestProjectionOptions, } from "./post-admission.js";
33
+ import { presentTerminal } from "./auto-resume.js";
33
34
  import { buildAutoResumeContinuationPrompt, loadResumablePublicRole, markRunAdmitted, parentRunPathFromGatePointerInstruction, readCurrentCourt, } from "./run-lifecycle.js";
34
35
  import { tryResumeSameTicketSeatRun } from "./seat-ticket-binding.js";
35
- import { presentStructuralRejection, readBoundSessionEntries, seatKnownFailureResolver, attachPostAuditProjection, trySettlePublicSeat, } from "./settlement.js";
36
+ import { presentStructuralRejection, readBoundSessionEntries, attachPostAuditProjection, trySettlePublicSeat, } from "./settlement.js";
36
37
  import { warnMissingMethodSkills } from "./machine-method-skills.js";
37
- import { coalesceSubmissionRows, formatTerminalResult, isLawfulTypedTerminalOutcome, } from "./terminal.js";
38
+ import { formatTerminalResult, isLawfulTypedTerminalOutcome, } from "./terminal.js";
38
39
  import { admittedSeatTurnDetails, projectRoleTurnRequest, requiredMethodSkills, } from "./turn-request.js";
39
40
  import { invokeCourtDiarist, latestPayloadEscalated, } from "./countersign-run.js";
40
41
  import { isRecord, errorText } from "../unknown-value.js";
@@ -98,19 +99,15 @@ const UNREADABLE_REASK_EXHAUSTED = { unreadableReaskExhausted: true };
98
99
  function isUnreadableReaskExhausted(value) {
99
100
  return value === UNREADABLE_REASK_EXHAUSTED;
100
101
  }
101
- function presentOriginalVolume(held, terminal, io) {
102
- // The held buffer was formatted before direction facts were attached.
103
- if (terminal?.roleOutcome.decisiveFacts?.directionUnsettled === true) {
104
- io.stdout(formatTerminalResult(terminal));
105
- return;
106
- }
107
- if (held.length > 0) {
108
- for (const value of held)
109
- io.stdout(value);
102
+ async function presentOriginalVolume(held, terminal, io, runDirectory) {
103
+ if (terminal !== undefined && runDirectory !== undefined) {
104
+ // Direction facts were attached after the held volume was formatted.
105
+ await presentTerminal(terminal, { ...io, omitFailureStderrDiagnostic: true }, runDirectory, terminal.roleOutcome.decisiveFacts?.directionUnsettled === true ? undefined : held);
110
106
  return;
111
107
  }
112
- if (terminal !== undefined)
113
- io.stdout(formatTerminalResult(terminal));
108
+ // No settled host report exists to preserve at this pre-result boundary.
109
+ for (const value of held)
110
+ io.stdout(value);
114
111
  }
115
112
  /** Runtime fact beside the original volume. Payloads stay as submitted. */
116
113
  function withUnsettledDirection(parent, officer) {
@@ -118,9 +115,11 @@ function withUnsettledDirection(parent, officer) {
118
115
  if (outcome.kind !== "accepted" && outcome.kind !== "audit_escalation")
119
116
  return parent;
120
117
  const officerOutcome = officer?.roleOutcome;
121
- const officerPayloads = coalesceSubmissionRows(officer?.submissions, officerOutcome !== undefined && officerOutcome.kind !== "no_receipt"
122
- ? officerOutcome.payloads
123
- : undefined);
118
+ const officerPayloads = officer?.submissions !== undefined && officer.submissions.length > 0
119
+ ? officer.submissions
120
+ : officerOutcome !== undefined && officerOutcome.kind !== "no_receipt"
121
+ ? officerOutcome.payloads ?? []
122
+ : [];
124
123
  return {
125
124
  ...parent,
126
125
  roleOutcome: {
@@ -144,11 +143,11 @@ function heldUnreadableTerminal(terminal) {
144
143
  const status = latestQueueStatus(terminal);
145
144
  return typeof status !== "string" || !REVIEW_QUEUE_STATUSES.has(status);
146
145
  }
147
- function presentUnsettledAudit(parent, officer, io) {
146
+ async function presentUnsettledAudit(parent, officer, io, runDirectory) {
148
147
  const terminal = withUnsettledDirection(parent, officer);
149
- io.stdout(formatTerminalResult(terminal));
148
+ await presentTerminal(terminal, { ...io, omitFailureStderrDiagnostic: true }, runDirectory);
150
149
  if (officer !== undefined)
151
- io.stdout(formatTerminalResult(officer));
150
+ await presentTerminal(officer, { ...io, omitFailureStderrDiagnostic: true }, runDirectory);
152
151
  return terminal;
153
152
  }
154
153
  async function reaskUnreadablePostSubmissionStatus(admitted, terminal, env, io, message = unreadablePostSubmissionStatus(admitted, terminal)) {
@@ -157,7 +156,7 @@ async function reaskUnreadablePostSubmissionStatus(admitted, terminal, env, io,
157
156
  const next = withUnreadableReask(env);
158
157
  if (next === undefined)
159
158
  return UNREADABLE_REASK_EXHAUSTED;
160
- return runPublicInstructionSeatResume({ runId: admitted.runId, message }, next, io);
159
+ return runPublicInstructionSeatResume({ runId: admitted.runId, summons: { instruction: message } }, next, io);
161
160
  }
162
161
  function roleRecord(role) {
163
162
  const record = packagedRoleMetadata(role);
@@ -181,10 +180,6 @@ function initialPrompt(admitted, env) {
181
180
  packageRoot: env.packageRoot,
182
181
  }));
183
182
  }
184
- function infraFailure(role) {
185
- const resolveRunnerKnownFailure = seatKnownFailureResolver(role);
186
- return resolveRunnerKnownFailure === undefined ? {} : { resolveRunnerKnownFailure };
187
- }
188
183
  function isBoardTicketSeat(seat) {
189
184
  return packagedBindsBoardTicket(seat.role);
190
185
  }
@@ -197,6 +192,9 @@ async function bindAndRelocateDiarist(admitted, authority, lease) {
197
192
  }
198
193
  return await relocateAdmittedRunToTicket(admitted, authority, lease);
199
194
  }
195
+ function packageFaultScope(admitted, env, io) {
196
+ return { notePackageFault: packageFaultNoteFor(admitted, env, io) };
197
+ }
200
198
  function seatAdapters(admitted, env) {
201
199
  const record = roleRecord(admitted.role);
202
200
  const present = "presentSettled" in record ? record.presentSettled : "default";
@@ -206,7 +204,6 @@ function seatAdapters(admitted, env) {
206
204
  ...(present === "typed"
207
205
  ? { shouldPresentSettled: (terminal) => isLawfulTypedTerminalOutcome(terminal.roleOutcome) }
208
206
  : {}),
209
- ...infraFailure(admitted.role),
210
207
  ...(packagedBindsBoardTicket(admitted.role)
211
208
  ? {
212
209
  beforeDispatch: async (seat, lease) => {
@@ -309,7 +306,7 @@ async function dispatchAdmitted(admitted, env, io) {
309
306
  const terminal = result.terminal === undefined
310
307
  ? undefined
311
308
  : withUnsettledDirection(result.terminal);
312
- presentOriginalVolume(held, terminal, io);
309
+ await presentOriginalVolume(held, terminal, io, admitted.runDirectory);
313
310
  return terminal === undefined ? result : { ...result, terminal };
314
311
  }
315
312
  if (unreadableReask !== undefined)
@@ -317,8 +314,7 @@ async function dispatchAdmitted(admitted, env, io) {
317
314
  if (AUDITED_ROLES.has(admitted.role) && result.terminal?.roleOutcome.kind === "accepted") {
318
315
  return auditSubmittedRole(result, env, io);
319
316
  }
320
- for (const value of held)
321
- io.stdout(value);
317
+ await presentOriginalVolume(held, result.terminal, io, admitted.runDirectory);
322
318
  return result;
323
319
  }
324
320
  /**
@@ -386,7 +382,11 @@ async function runOmittedLensBatch(argv, parsed, env, io) {
386
382
  },
387
383
  artifacts: terminals.flatMap((item) => item.artifacts),
388
384
  };
389
- io.stdout(formatTerminalResult(terminal));
385
+ const childRunDirectory = children.completeness.admitted?.runDirectory ?? children.correctness.admitted?.runDirectory;
386
+ if (childRunDirectory !== undefined)
387
+ await presentTerminal(terminal, { ...io, omitFailureStderrDiagnostic: true }, childRunDirectory);
388
+ else
389
+ io.stdout(formatTerminalResult(terminal));
390
390
  return { exitCode: failed ? 1 : 0, terminal };
391
391
  }
392
392
  /**
@@ -522,8 +522,7 @@ export async function runPublicInstructionSeat(argv, env, io, role, parseArgv) {
522
522
  });
523
523
  if (result.terminal?.roleOutcome.kind === "accepted")
524
524
  return auditSubmittedRole(result, env, io);
525
- for (const value of held)
526
- io.stdout(value);
525
+ await presentOriginalVolume(held, result.terminal, io, result.admitted?.runDirectory);
527
526
  return result;
528
527
  }
529
528
  if ("parallelLenses" in record && record.parallelLenses === true) {
@@ -685,7 +684,7 @@ export async function runPublicInstructionSeat(argv, env, io, role, parseArgv) {
685
684
  catch (error) {
686
685
  return await presentControlledFailure(admitted, {
687
686
  timedOut: false, code: null, stderr: "", thrown: error,
688
- }, seatAdapters(admitted, env), env.principalAuthority, io);
687
+ }, seatAdapters(admitted, env), env.principalAuthority, io, true, packageFaultNoteFor(admitted, env, io));
689
688
  }
690
689
  if (outcome.admitted !== undefined && isUnboundRunDirectory(outcome.admitted.runDirectory)) {
691
690
  await recordChildDiaristRun(admitted, outcome.admitted.runId);
@@ -694,12 +693,12 @@ export async function runPublicInstructionSeat(argv, env, io, role, parseArgv) {
694
693
  return await presentControlledFailure(admitted, {
695
694
  timedOut: false, code: null, stderr: "",
696
695
  thrown: new Error(outcome.failedWithoutEscalate.diagnostic),
697
- }, seatAdapters(admitted, env), env.principalAuthority, io);
696
+ }, seatAdapters(admitted, env), env.principalAuthority, io, true, packageFaultNoteFor(admitted, env, io));
698
697
  }
699
698
  // The diarist's escalation pauses only the diarist's own run; call order
700
699
  // belongs to the caller, so the Secretariat still takes its own turn.
701
700
  if (outcome.identity.kind === "escalate" && outcome.terminal !== undefined) {
702
- io.stdout(formatTerminalResult(outcome.terminal));
701
+ await presentTerminal(outcome.terminal, { ...io, omitFailureStderrDiagnostic: true }, outcome.admitted?.runDirectory ?? admitted.runDirectory);
703
702
  }
704
703
  }
705
704
  return dispatchAdmitted(admitted, env, io);
@@ -751,24 +750,7 @@ export async function runPublicInstructionSeatResume(request, env, io) {
751
750
  },
752
751
  afterAdmittedLoad: async (admitted) => {
753
752
  await warnMissingMethodSkills(env.home, env.host, admitted.role, requiredMethodSkills(admitted), io.stdout);
754
- const adapters = seatAdapters(admitted, env);
755
- if ((env.unreadableReasksSpent ?? 0) === 0 && env.reviewReask === undefined) {
756
- return { kind: "continue", adapters };
757
- }
758
- const original = await adapters.trySettle(admitted, env.principalAuthority, await readCurrentCourt(admitted.runDirectory));
759
- const unsettled = POST_SUBMISSION_ROUTING[admitted.role] === undefined
760
- ? heldUnreadableTerminal(original)
761
- : unreadablePostSubmissionStatus(admitted, original) !== undefined;
762
- // Select this reask's existing subject before dispatch. The common
763
- // settlement then keeps it only when no fresh receipt supersedes it;
764
- // actual failures still take their normal failure path.
765
- return {
766
- kind: "continue",
767
- adapters: original === undefined || !unsettled ? adapters : {
768
- ...adapters,
769
- trySettle: async (seat, authority, scope) => await adapters.trySettle(seat, authority, scope) ?? original,
770
- },
771
- };
753
+ return { kind: "continue", adapters: seatAdapters(admitted, env) };
772
754
  },
773
755
  ...(env.engine === undefined ? {} : { effectiveEngine: env.engine }),
774
756
  });
@@ -779,7 +761,7 @@ export async function runPublicInstructionSeatResume(request, env, io) {
779
761
  const terminal = result.terminal === undefined
780
762
  ? undefined
781
763
  : withUnsettledDirection(result.terminal);
782
- presentOriginalVolume(held, terminal, io);
764
+ await presentOriginalVolume(held, terminal, io, result.admitted?.runDirectory);
783
765
  return terminal === undefined ? result : { ...result, terminal };
784
766
  }
785
767
  if (unreadableReask !== undefined)
@@ -788,8 +770,7 @@ export async function runPublicInstructionSeatResume(request, env, io) {
788
770
  && result.terminal?.roleOutcome.kind === "accepted") {
789
771
  return auditSubmittedRole(result, env, io);
790
772
  }
791
- for (const value of held)
792
- io.stdout(value);
773
+ await presentOriginalVolume(held, result.terminal, io, result.admitted?.runDirectory);
793
774
  return result;
794
775
  };
795
776
  let binding;
@@ -825,7 +806,7 @@ async function queueConclusionFromChild(child, env, io) {
825
806
  if (!GATE_CHILD_ROLES.has(child.role))
826
807
  return undefined;
827
808
  if (child.role === "countersign") {
828
- const terminal = await trySettlePublicSeat(child, env.principalAuthority, await readCurrentCourt(child.runDirectory));
809
+ const terminal = await trySettlePublicSeat(child, env.principalAuthority, { ...await readCurrentCourt(child.runDirectory), ...packageFaultScope(child, env, io) });
829
810
  const status = latestQueueStatus(terminal);
830
811
  if (terminal !== undefined && typeof status === "string" && REVIEW_QUEUE_STATUSES.has(status)) {
831
812
  return { admitted: child, terminal, status };
@@ -838,7 +819,7 @@ async function queueConclusionFromChild(child, env, io) {
838
819
  // failure recovery, and other reask loops stay separate.
839
820
  let budgetEnv = { ...env, unreadableReasksSpent: 0 };
840
821
  for (;;) {
841
- const terminal = await trySettlePublicSeat(current, env.principalAuthority, await readCurrentCourt(current.runDirectory));
822
+ const terminal = await trySettlePublicSeat(current, env.principalAuthority, { ...await readCurrentCourt(current.runDirectory), ...packageFaultScope(current, env, io) });
842
823
  const status = latestQueueStatus(terminal);
843
824
  if (terminal !== undefined && typeof status === "string" && REVIEW_QUEUE_STATUSES.has(status)) {
844
825
  return { admitted: current, terminal, status };
@@ -878,7 +859,7 @@ export async function continueParentAfterChild(parentRunId, child, env, io) {
878
859
  const parentTerminal = await trySettlePublicSeat(admitted, env.principalAuthority, undefined);
879
860
  if (parentTerminal?.roleOutcome.kind === "accepted"
880
861
  || parentTerminal?.roleOutcome.kind === "audit_escalation") {
881
- const terminal = presentUnsettledAudit(parentTerminal, stopped.terminal, io);
862
+ const terminal = await presentUnsettledAudit(parentTerminal, stopped.terminal, io, admitted.runDirectory);
882
863
  return { exitCode: 0, admitted, terminal };
883
864
  }
884
865
  }
@@ -889,14 +870,14 @@ export async function continueParentAfterChild(parentRunId, child, env, io) {
889
870
  }
890
871
  if (resolved !== undefined && (resolved.status === "continue" || resolved.status === "converged")) {
891
872
  if (AUDITED_ROLES.has(admitted.role) && resolved.status === "converged") {
892
- const terminal = await trySettlePublicSeat(admitted, env.principalAuthority, undefined);
873
+ const terminal = await trySettlePublicSeat(admitted, env.principalAuthority, packageFaultScope(admitted, env, io));
893
874
  if (terminal?.roleOutcome.kind !== "accepted")
894
875
  throw new Error("pending submission is not recorded");
895
876
  return auditSubmittedRole({ exitCode: 0, admitted, terminal }, env, io, resolved.admitted, latestQueuePayload(resolved.terminal));
896
877
  }
897
878
  return runPublicInstructionSeatResume({
898
879
  runId: parentRunId,
899
- message: readableGateItem(latestQueuePayload(resolved.terminal)),
880
+ summons: { instruction: readableGateItem(latestQueuePayload(resolved.terminal)) },
900
881
  }, { ...env, unreadableReasksSpent: 0 }, io);
901
882
  }
902
883
  const result = await dispatchAdmitted(admitted, env, { ...io, omitFailureStderrDiagnostic: true });
@@ -955,10 +936,10 @@ async function auditSubmittedRole(turn, env, io, resumedOfficer, passedReceipt)
955
936
  const next = withUnreadableReask(env);
956
937
  if (next === undefined) {
957
938
  const terminal = withUnsettledDirection(turn.terminal);
958
- io.stdout(formatTerminalResult(terminal));
939
+ await presentTerminal(terminal, { ...io, omitFailureStderrDiagnostic: true }, admitted.runDirectory);
959
940
  return { ...turn, terminal };
960
941
  }
961
- return runPublicInstructionSeatResume({ runId: admitted.runId, message: SECRETARIAT_STATUS_REASK }, next, io);
942
+ return runPublicInstructionSeatResume({ runId: admitted.runId, summons: { instruction: SECRETARIAT_STATUS_REASK } }, next, io);
962
943
  }
963
944
  if (admitted.role === "countersign" && (typeof status !== "string" || !REVIEW_QUEUE_STATUSES.has(status))) {
964
945
  if (gateOwnsStatusReask)
@@ -966,10 +947,10 @@ async function auditSubmittedRole(turn, env, io, resumedOfficer, passedReceipt)
966
947
  const next = withUnreadableReask(env);
967
948
  if (next === undefined) {
968
949
  const terminal = withUnsettledDirection(turn.terminal);
969
- io.stdout(formatTerminalResult(terminal));
950
+ await presentTerminal(terminal, { ...io, omitFailureStderrDiagnostic: true }, admitted.runDirectory);
970
951
  return { ...turn, terminal };
971
952
  }
972
- return runPublicInstructionSeatResume({ runId: admitted.runId, message: officerConclusionReask(status) }, next, io);
953
+ return runPublicInstructionSeatResume({ runId: admitted.runId, summons: { instruction: officerConclusionReask(status) } }, next, io);
973
954
  }
974
955
  // Self-escalation is a valid open routing state for these seats only.
975
956
  // Doctor's declared domain is completed|refused — an open "escalate" must
@@ -981,7 +962,7 @@ async function auditSubmittedRole(turn, env, io, resumedOfficer, passedReceipt)
981
962
  || ((admitted.role === "fixer" || admitted.role === "coder")
982
963
  && (typeof status !== "string" || !WORKER_DONE_STATUSES.has(status)));
983
964
  if (skipAudit) {
984
- io.stdout(formatTerminalResult(turn.terminal));
965
+ await presentTerminal(turn.terminal, { ...io, omitFailureStderrDiagnostic: true }, admitted.runDirectory);
985
966
  return turn;
986
967
  }
987
968
  const rows = await readRecordedSubmissionRows(admitted.projectRoot, admitted.runId, env.home);
@@ -990,7 +971,9 @@ async function auditSubmittedRole(turn, env, io, resumedOfficer, passedReceipt)
990
971
  if (toolCallId === undefined)
991
972
  throw new Error("accepted submission has no tool call identity");
992
973
  const sessionFile = env.principalAuthority.decode(admitted.principal).sessionFile;
993
- const entries = admitted.role === "doctor" ? await readBoundSessionEntries(sessionFile) : [];
974
+ const entries = admitted.role === "doctor"
975
+ ? await readBoundSessionEntries(sessionFile)
976
+ : [];
994
977
  const context = {
995
978
  cwd: admitted.projectRoot,
996
979
  mode: "print",
@@ -1047,7 +1030,7 @@ async function auditSubmittedRole(turn, env, io, resumedOfficer, passedReceipt)
1047
1030
  });
1048
1031
  if (decision.status === "continue") {
1049
1032
  return runPublicInstructionSeatResume({
1050
- runId: admitted.runId, message: readableGateItem(decision.receipt ?? decision.violations),
1033
+ runId: admitted.runId, summons: { instruction: readableGateItem(decision.receipt ?? decision.violations) },
1051
1034
  }, { ...env, unreadableReasksSpent: 0 }, io);
1052
1035
  }
1053
1036
  if (decision.status === "received") {
@@ -1056,12 +1039,12 @@ async function auditSubmittedRole(turn, env, io, resumedOfficer, passedReceipt)
1056
1039
  }
1057
1040
  if (turn.terminal === undefined)
1058
1041
  throw new Error("doctor submission has no terminal");
1059
- const terminal = presentUnsettledAudit(turn.terminal, lastSummon.terminal, io);
1042
+ const terminal = await presentUnsettledAudit(turn.terminal, lastSummon.terminal, io, admitted.runDirectory);
1060
1043
  return { exitCode: 0, admitted, terminal };
1061
1044
  }
1062
1045
  if (decision.status !== "converged") {
1063
1046
  if (lastSummon?.terminal !== undefined) {
1064
- io.stdout(formatTerminalResult(lastSummon.terminal));
1047
+ await presentTerminal(lastSummon.terminal, { ...io, omitFailureStderrDiagnostic: true }, lastSummon.admitted?.runDirectory ?? admitted.runDirectory);
1065
1048
  return { exitCode: lastSummon.exitCode,
1066
1049
  ...(lastSummon.admitted === undefined ? {} : { admitted: lastSummon.admitted }),
1067
1050
  terminal: lastSummon.terminal };
@@ -1133,7 +1116,7 @@ async function auditSubmittedRole(turn, env, io, resumedOfficer, passedReceipt)
1133
1116
  throw new Error("unreadable audit has no terminal result");
1134
1117
  if (turn.terminal === undefined)
1135
1118
  throw new Error("audited submission has no terminal");
1136
- const terminal = presentUnsettledAudit(turn.terminal, officerTerminal, io);
1119
+ const terminal = await presentUnsettledAudit(turn.terminal, officerTerminal, io, admitted.runDirectory);
1137
1120
  return { exitCode: 0, admitted, terminal };
1138
1121
  }
1139
1122
  if (chain.status === "escalate") {
@@ -1144,16 +1127,16 @@ async function auditSubmittedRole(turn, env, io, resumedOfficer, passedReceipt)
1144
1127
  if (escalatedRunId === undefined)
1145
1128
  throw new Error("escalated audit has no resumable run identity");
1146
1129
  const officer = await loadResumablePublicRole(env.home, escalatedRunId, env.principalAuthority);
1147
- const terminal = await trySettlePublicSeat(officer.admitted, env.principalAuthority, await readCurrentCourt(officer.admitted.runDirectory));
1130
+ const terminal = await trySettlePublicSeat(officer.admitted, env.principalAuthority, { ...await readCurrentCourt(officer.admitted.runDirectory), ...packageFaultScope(officer.admitted, env, io) });
1148
1131
  if (terminal === undefined)
1149
1132
  throw new Error("escalated audit has no terminal result");
1150
- io.stdout(formatTerminalResult(terminal));
1133
+ await presentTerminal(terminal, { ...io, omitFailureStderrDiagnostic: true }, officer.admitted.runDirectory);
1151
1134
  return { exitCode: 0, admitted: officer.admitted, terminal };
1152
1135
  }
1153
1136
  if (chain.status === "continue") {
1154
1137
  return runPublicInstructionSeatResume({
1155
1138
  runId: admitted.runId,
1156
- message: readableGateItem(chain.passes.at(-1)?.receipt),
1139
+ summons: { instruction: readableGateItem(chain.passes.at(-1)?.receipt) },
1157
1140
  }, { ...env, unreadableReasksSpent: 0 }, io);
1158
1141
  }
1159
1142
  if (admitted.role === "secretariat") {
@@ -1172,8 +1155,8 @@ async function auditSubmittedRole(turn, env, io, resumedOfficer, passedReceipt)
1172
1155
  // settle would republish the same attempt.
1173
1156
  if (turn.terminal === undefined)
1174
1157
  throw new Error(`audited ${admitted.role} submission did not settle`);
1175
- const terminal = await attachPostAuditProjection(admitted, env.principalAuthority, turn.terminal);
1158
+ const terminal = await attachPostAuditProjection(admitted, env.principalAuthority, turn.terminal, packageFaultScope(admitted, env, io));
1176
1159
  turn = { ...turn, terminal };
1177
- io.stdout(formatTerminalResult(terminal));
1160
+ await presentTerminal(terminal, { ...io, omitFailureStderrDiagnostic: true }, admitted.runDirectory);
1178
1161
  return turn;
1179
1162
  }