@akagilnc/pi-workflow-roles 0.1.4021 → 0.1.4062

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (74) hide show
  1. package/dist/acp-host/production-host.js +682 -355
  2. package/dist/doctor-auditor.js +1 -1
  3. package/dist/dossier-resolution.js +21 -8
  4. package/dist/gatekeeper-role.js +34 -27
  5. package/dist/headless-host/description.js +7 -8
  6. package/dist/headless-host/production-host.js +709 -369
  7. package/dist/host-contracts.js +16 -0
  8. package/dist/inspector-contracts.js +8 -0
  9. package/dist/navigator-attendance.js +2 -0
  10. package/dist/navigator-public-session.js +18 -34
  11. package/dist/navigator-session-contracts.js +19 -0
  12. package/dist/packaged-role-registry.js +1 -1
  13. package/dist/pi/known-failure.js +3 -4
  14. package/dist/pi/role-turn-host.js +43 -13
  15. package/dist/public-cli/auto-resume.js +20 -7
  16. package/dist/public-cli/case-dossier-delivery.js +60 -1
  17. package/dist/public-cli/diarist-run.js +9 -23
  18. package/dist/public-cli/inspector-run.js +17 -3
  19. package/dist/public-cli/instruction-seat-run.js +12 -7
  20. package/dist/public-cli/judge-run.js +3 -1
  21. package/dist/public-cli/main.js +440 -222
  22. package/dist/public-cli/notary-run.js +7 -4
  23. package/dist/public-cli/post-admission.js +66 -59
  24. package/dist/public-cli/run-lifecycle.js +3 -0
  25. package/dist/public-cli/settlement.js +78 -58
  26. package/dist/public-cli/terminal.js +1 -11
  27. package/dist/public-role-summons.js +8 -0
  28. package/dist/submission-ledger.js +139 -19
  29. package/dist/user-dialogue-stdin.js +33 -0
  30. package/extensions/role-runtime.ts +1 -0
  31. package/package.json +1 -1
  32. package/resources/836-deleted-machine-instruction-inventory.md +1 -1
  33. package/src/doctor-auditor.ts +1 -1
  34. package/src/dossier-resolution.ts +26 -8
  35. package/src/external-host-turn-loop.ts +9 -0
  36. package/src/gatekeeper-pass-envelope.ts +6 -0
  37. package/src/gatekeeper-role.ts +47 -28
  38. package/src/headless-host/description.ts +8 -11
  39. package/src/headless-host/role-turn-host.ts +20 -5
  40. package/src/host-contracts.ts +30 -7
  41. package/src/inspector-contracts.ts +7 -0
  42. package/src/judge-role.ts +4 -0
  43. package/src/navigator-attendance.ts +2 -0
  44. package/src/navigator-public-session.ts +19 -55
  45. package/src/navigator-session-contracts.ts +39 -0
  46. package/src/navigator-work-context.ts +3 -4
  47. package/src/notary-role.ts +1 -0
  48. package/src/packaged-role-registry.ts +1 -1
  49. package/src/pi/adapter.ts +19 -4
  50. package/src/pi/known-failure.ts +3 -4
  51. package/src/pi/role-turn-host.ts +48 -14
  52. package/src/public-cli/auto-resume.ts +57 -20
  53. package/src/public-cli/case-dossier-delivery.ts +86 -1
  54. package/src/public-cli/cli.ts +2 -2
  55. package/src/public-cli/collector-run.ts +3 -1
  56. package/src/public-cli/countersign-run.ts +34 -27
  57. package/src/public-cli/diarist-run.ts +10 -27
  58. package/src/public-cli/inspector-run.ts +26 -2
  59. package/src/public-cli/instruction-seat-run.ts +20 -10
  60. package/src/public-cli/invocation.ts +2 -0
  61. package/src/public-cli/judge-run.ts +3 -1
  62. package/src/public-cli/notary-run.ts +13 -4
  63. package/src/public-cli/post-admission.ts +74 -65
  64. package/src/public-cli/reviewer-run.ts +3 -1
  65. package/src/public-cli/run-lifecycle.ts +3 -0
  66. package/src/public-cli/settlement.ts +105 -80
  67. package/src/public-cli/terminal.ts +7 -16
  68. package/src/public-role-summons.ts +31 -7
  69. package/src/role-envelope.ts +9 -30
  70. package/src/role-runtime-dependencies.ts +1 -0
  71. package/src/role-runtime.ts +95 -19
  72. package/src/submission-ledger.ts +195 -26
  73. package/src/user-dialogue-stdin.ts +37 -0
  74. package/src/worker-role.ts +4 -0
@@ -69,6 +69,11 @@ export type InstructionSeatRunEnv = PostAdmissionEnv & {
69
69
  * Never a public CLI argv — must not pollute the --source-run parent lookup key (#747).
70
70
  */
71
71
  reviewReask?: string;
72
+ /**
73
+ * #879 gate summons: verbatim parent-submission body for officer dialogue content.
74
+ * Rides summons.instruction / first-mint prompt when reviewReask is absent.
75
+ */
76
+ gateReviewInstruction?: string;
72
77
  };
73
78
 
74
79
  /** Project an admitted instruction-seat invocation onto the host-neutral turn request. */
@@ -122,7 +127,9 @@ function instructionSeatAdapters(options?: {
122
127
  return infrastructureFailure === undefined
123
128
  ? result.knownFailure
124
129
  : {
125
- cause: infrastructureFailure.cause,
130
+ ...(infrastructureFailure.cause === undefined
131
+ ? {}
132
+ : { cause: infrastructureFailure.cause }),
126
133
  diagnostic: infrastructureFailure.diagnostic,
127
134
  ...(infrastructureFailure.identity === undefined
128
135
  ? {}
@@ -289,8 +296,9 @@ export async function runPublicInstructionSeat(
289
296
  }
290
297
  }
291
298
 
292
- // #756/#786: auditor reask / verbatim submission body ride summons.instruction on resume.
293
- const resumeInstruction = env.reviewReask;
299
+ // #756/#879: auditor reask / verbatim submission body ride summons.instruction.
300
+ // Binding pointer stays --source-run / argv 卷宗指针; content is body or reask.
301
+ const resumeInstruction = env.reviewReask ?? env.gateReviewInstruction;
294
302
  const summons: SameTicketSummonsMaterials = {
295
303
  ...(resumeInstruction === undefined
296
304
  ? {
@@ -370,13 +378,15 @@ export async function runPublicInstructionSeat(
370
378
  : { correlationId: env.correlationId }),
371
379
  continuation: {
372
380
  kind: "initial",
373
- prompt: buildInstructionTransportPrompt(
374
- admitted,
375
- engineSessionMaterialFromOptions({
376
- ...pickEngineAxis(env),
377
- packageRoot: env.packageRoot,
378
- }),
379
- ),
381
+ // #879: gate first mint uses parent payload as content when present.
382
+ prompt: (env.reviewReask ?? env.gateReviewInstruction)
383
+ ?? buildInstructionTransportPrompt(
384
+ admitted,
385
+ engineSessionMaterialFromOptions({
386
+ ...pickEngineAxis(env),
387
+ packageRoot: env.packageRoot,
388
+ }),
389
+ ),
380
390
  },
381
391
  });
382
392
 
@@ -131,6 +131,8 @@ export type AdmittedGleanerLeftInvocation = AdmittedRoleInvocationBase & {
131
131
 
132
132
  export type AdmittedInspectorInvocation = AdmittedRoleInvocationBase & {
133
133
  readonly role: "inspector";
134
+ /** Parent run directory (#747 / #879); independent of dialogue instruction. */
135
+ readonly sourceRunPath?: string;
134
136
  };
135
137
 
136
138
  export type AdmittedGatekeeperInvocation = AdmittedRoleInvocationBase & {
@@ -63,7 +63,9 @@ function judgeAdapters(): PostAdmissionAdapters<AdmittedJudgeInvocation> {
63
63
  (infrastructureFailure === undefined
64
64
  ? undefined
65
65
  : {
66
- cause: infrastructureFailure.cause,
66
+ ...(infrastructureFailure.cause === undefined
67
+ ? {}
68
+ : { cause: infrastructureFailure.cause }),
67
69
  diagnostic: infrastructureFailure.diagnostic,
68
70
  ...(infrastructureFailure.identity === undefined
69
71
  ? {}
@@ -52,6 +52,12 @@ export type NotaryRunEnv = PostAdmissionEnv & {
52
52
  * Never a public CLI argv — external callers still have zero prompt.
53
53
  */
54
54
  reviewReask?: string;
55
+ /**
56
+ * #879 gate summons: verbatim parent-submission body for officer dialogue content.
57
+ * Rides summons.instruction / first-mint prompt when reviewReask is absent.
58
+ * Binding pointer stays --source-run (independent machine material).
59
+ */
60
+ gateReviewInstruction?: string;
55
61
  };
56
62
 
57
63
  /** Project admitted invocation onto the host-neutral turn request. */
@@ -115,10 +121,10 @@ export async function runPublicNotary(
115
121
  throw error;
116
122
  }
117
123
  // #747: officer resume key is this parent source-run path (not ticket number).
118
- // #753/#786: gate re-ask and verbatim submission body share summons.instruction
119
- // (reask wins when both present; no parallel stack).
124
+ // #753/#879: gate re-ask and verbatim submission body share summons.instruction
125
+ // (reask wins when both present; no parallel stack). Binding stays sourceRunPath.
120
126
  {
121
- const resumeInstruction = env.reviewReask;
127
+ const resumeInstruction = env.reviewReask ?? env.gateReviewInstruction;
122
128
  const summons: SameTicketSummonsMaterials = {
123
129
  sourceRunPath: source.runDirectory,
124
130
  sourceRun: source,
@@ -181,7 +187,10 @@ export async function runPublicNotary(
181
187
  : { correlationId: env.correlationId }),
182
188
  continuation: {
183
189
  kind: "initial",
184
- prompt: buildNotaryTransportPrompt(admitted, engineMaterial),
190
+ // #879: gate path first mint carries parent payload as dialogue content;
191
+ // external zero-prompt kickoff unchanged when no body/reask.
192
+ prompt: (env.reviewReask ?? env.gateReviewInstruction)
193
+ ?? buildNotaryTransportPrompt(admitted, engineMaterial),
185
194
  },
186
195
  });
187
196
 
@@ -11,7 +11,6 @@ import { isAbsolute, join, resolve } from "node:path";
11
11
 
12
12
  import {
13
13
  buildResumeContinuationPrompt,
14
- GATE_DOSSIER_POINTER_PREFIX,
15
14
  RESUME_TRANSPORT_ENVELOPE,
16
15
  type PublicResumeRequest,
17
16
  type SameTicketSummonsMaterials,
@@ -37,7 +36,11 @@ import type {
37
36
  RoleTurnResult,
38
37
  SessionCustomEntryAppender,
39
38
  } from "../host-contracts.ts";
40
- import { projectCaseDossierPointerSection } from "./case-dossier-delivery.ts";
39
+ import { isOfficerReviewSeat } from "../host-contracts.ts";
40
+ import {
41
+ deliverCaseDossierAsAttachment,
42
+ projectCaseDossierPointerSection,
43
+ } from "./case-dossier-delivery.ts";
41
44
 
42
45
  /** Original error bytes, never relabeled — a secondary fact riding beside a classified cause. */
43
46
  function describeCaughtError(error: unknown): { name?: string; message: string; code?: string | number } {
@@ -58,6 +61,18 @@ function appendContinuationSection(
58
61
  ? { kind: "initial", prompt }
59
62
  : { kind: "resume", prompt };
60
63
  }
64
+
65
+ /**
66
+ * Nested gate summons (station child) on an officer seat: dialogue content is
67
+ * peer words only (#879). ADR 0081 case dossier still hangs via the existing
68
+ * attachments freeze seam — never into the peer body, never RoleTurnRequest.materials.
69
+ */
70
+ function isStationChildOfficerDialogue(
71
+ role: string,
72
+ env: { readonly stationChild?: boolean },
73
+ ): boolean {
74
+ return env.stationChild === true && isOfficerReviewSeat(role);
75
+ }
61
76
  import { projectHostTransitionPriorNative } from "../host-transition-prior-native.ts";
62
77
  import type { CredentialProviders, SeatModelConfig } from "./config.ts";
63
78
  import {
@@ -654,9 +669,9 @@ export async function dispatchPostAdmissionTurn<
654
669
  // Turn request is assembled after beforeDispatch so this turn sees whatever it
655
670
  // settled — the seat's ticket bind re-projection and any court diarist station
656
671
  // writes (#742). Case dossier delivery (ADR 0081 / #709) rides here once for
657
- // every public entry: first call, same-ticket re-summons and manual resume
658
- // alike. System refs append their own neutral section; caller frozen
659
- // attachments and the seat's own prompt bytes are never rewritten.
672
+ // every public entry. #879: station-child officer dialogue keeps peer body
673
+ // intact — 起居录 hangs via existing attachments freeze (not prompt wrap,
674
+ // not RoleTurnRequest.materials). Other entries keep the neutral prompt section.
660
675
  let turnRequest: RoleTurnRequest =
661
676
  env.signal === undefined ? request : { ...request, signal: env.signal };
662
677
  if (env.stationChild !== undefined) {
@@ -665,19 +680,33 @@ export async function dispatchPostAdmissionTurn<
665
680
  if (hostTransition !== undefined) {
666
681
  turnRequest = { ...turnRequest, hostTransition };
667
682
  }
668
- const dossierSection = await projectCaseDossierPointerSection({
669
- ticketNumber: admitted.ticketNumber,
670
- projectRoot: admitted.projectRoot,
671
- home: env.home,
672
- });
673
- if (dossierSection !== undefined) {
674
- turnRequest = {
675
- ...turnRequest,
676
- continuation: appendContinuationSection(
677
- turnRequest.continuation,
678
- dossierSection,
679
- ),
680
- };
683
+ if (isStationChildOfficerDialogue(admitted.role, env)) {
684
+ // 0081 non-body face: freeze pointer section under run/attachments/.
685
+ // Peer dialogue continuation.prompt stays parent payload only — the seat
686
+ // consumes the freeze via loadCaseDossierReadingMaterial → existing
687
+ // agent-start readingMaterial / systemPrompt.materials fold (not prompt splice,
688
+ // not RoleTurnRequest.materials).
689
+ await deliverCaseDossierAsAttachment({
690
+ ticketNumber: admitted.ticketNumber,
691
+ projectRoot: admitted.projectRoot,
692
+ home: env.home,
693
+ runDirectory: admitted.runDirectory,
694
+ });
695
+ } else {
696
+ const dossierSection = await projectCaseDossierPointerSection({
697
+ ticketNumber: admitted.ticketNumber,
698
+ projectRoot: admitted.projectRoot,
699
+ home: env.home,
700
+ });
701
+ if (dossierSection !== undefined) {
702
+ turnRequest = {
703
+ ...turnRequest,
704
+ continuation: appendContinuationSection(
705
+ turnRequest.continuation,
706
+ dossierSection,
707
+ ),
708
+ };
709
+ }
681
710
  }
682
711
 
683
712
  // Authoritative host write happens here, at the real dispatch boundary —
@@ -1065,16 +1094,16 @@ export async function dispatchPostAdmissionTurn<
1065
1094
  }
1066
1095
 
1067
1096
  /**
1068
- * Shared resume continuation projection (#471 / #600 / #633 / #637 / #755):
1097
+ * Shared resume continuation projection (#471 / #600 / #633 / #637 / #755 / #879):
1069
1098
  * seat-table model/engine/timeout axes, restored correlation, and either
1070
1099
  * - manual resume (no same-ticket summons): package envelope / optional caller
1071
1100
  * message, with engine-axis handbook via buildResumeContinuationPrompt, or
1072
1101
  * - same-ticket summons (审核循环续话): caller/peer words + optional frozen
1073
- * attachment paths only — no「重新读」、no engine handbook packaging
1074
- * (#750/#755), whether or not attachments are present.
1102
+ * attachment paths only — no「请重读」、no code-authored content substitute,
1103
+ * no engine handbook packaging (#750/#755/#879).
1075
1104
  * Caller message wins as prompt base when supplied (bytes unchanged, including
1076
- * blank/whitespace); else summons instruction. Attachment projection must not
1077
- * re-interpret the caller message as instructionEmpty.
1105
+ * blank/whitespace); else summons instruction (parent payload or reask).
1106
+ * Binding pointer stays on summons.sourceRunPath / activation — not dialogue content.
1078
1107
  * Seats add only their activation projection. Call prepareSummonsResumeMaterials
1079
1108
  * first when request.summons carries instruction or attachment paths.
1080
1109
  */
@@ -1088,32 +1117,25 @@ export function resumeTurnRequestProjectionOptions(
1088
1117
  readonly attachments: readonly { frozenPath: string }[];
1089
1118
  },
1090
1119
  ): RoleTurnRequestProjectionOptions {
1091
- const officerSourcePath = request.summons?.sourceRunPath;
1092
- const withReread = (body: string): string => {
1093
- if (
1094
- officerSourcePath === undefined
1095
- || (admitted.role !== "notary"
1096
- && admitted.role !== "inspector"
1097
- && admitted.role !== "auditor")
1098
- ) {
1099
- return body;
1100
- }
1101
- if (body.startsWith("请重读")) return body;
1102
- return `请重读\n${body}`;
1103
- };
1120
+ // #879: officer dialogue content is caller/peer words only — no「请重读」,
1121
+ // no code-authored constant substitute, no attachment-list wrap of peer body.
1122
+ // Binding pointer stays on summons sourceRunPath / activation / attachments.
1123
+ const officerDialogue = isStationChildOfficerDialogue(admitted.role, env);
1104
1124
  let prompt: string;
1105
1125
  if (request.message !== undefined) {
1106
1126
  if (summonsPrepared !== undefined) {
1107
- // #755: same-ticket review / open-court — caller words + optional paths.
1108
- // Attachments are not a gate: message-only summons must stay plain too.
1109
- prompt = withReread(buildInstructionTransportPrompt({
1110
- instruction: request.message,
1111
- instructionEmpty: false,
1112
- attachments: summonsPrepared.attachments,
1113
- }));
1127
+ // #755: same-ticket review / open-court — caller words.
1128
+ // #879 station-child officer: words only (attachments are independent freeze).
1129
+ prompt = officerDialogue
1130
+ ? request.message
1131
+ : buildInstructionTransportPrompt({
1132
+ instruction: request.message,
1133
+ instructionEmpty: false,
1134
+ attachments: summonsPrepared.attachments,
1135
+ });
1114
1136
  } else if (request.summons !== undefined) {
1115
1137
  // #755: same-ticket summons without prepared materials — caller words only.
1116
- prompt = withReread(request.message);
1138
+ prompt = request.message;
1117
1139
  } else {
1118
1140
  // Bare manual resume — outsourcing engine axis keeps handbook (#600/#736).
1119
1141
  prompt = buildResumeContinuationPrompt({
@@ -1123,28 +1145,15 @@ export function resumeTurnRequestProjectionOptions(
1123
1145
  });
1124
1146
  }
1125
1147
  } else if (summonsPrepared !== undefined) {
1126
- // #755: same-ticket review summons — instruction/attachments only.
1127
- prompt = withReread(buildInstructionTransportPrompt(summonsPrepared));
1148
+ // #879 station-child officer: instruction bytes === peer body/reask (no wrap).
1149
+ // Other seats keep #755 instruction + optional attachment path listing.
1150
+ prompt = officerDialogue
1151
+ ? (summonsPrepared.instructionEmpty ? "" : summonsPrepared.instruction)
1152
+ : buildInstructionTransportPrompt(summonsPrepared);
1128
1153
  } else if (request.summons !== undefined) {
1129
- // #755: same-ticket summons with no instruction/attachments (e.g. notary
1130
- // source-run pointer). #836: officer resume opening adds「请重读」+ path pointer.
1131
- const path = request.summons.sourceRunPath;
1132
- if (
1133
- path !== undefined &&
1134
- (admitted.role === "notary" ||
1135
- admitted.role === "inspector" ||
1136
- admitted.role === "auditor")
1137
- ) {
1138
- prompt = `请重读\n${GATE_DOSSIER_POINTER_PREFIX}${path}`;
1139
- } else if (
1140
- admitted.role === "notary" ||
1141
- admitted.role === "inspector" ||
1142
- admitted.role === "auditor"
1143
- ) {
1144
- prompt = "请重读";
1145
- } else {
1146
- prompt = "";
1147
- }
1154
+ // #879: same-ticket summons with no instruction (e.g. notary source-run binding
1155
+ // only). Pointer is activation/sourceRun material — not dialogue content.
1156
+ prompt = "";
1148
1157
  } else {
1149
1158
  // Bare manual resume — outsourcing engine axis keeps handbook (#600/#736).
1150
1159
  prompt = buildResumeContinuationPrompt({
@@ -104,7 +104,9 @@ function reviewerAdapters(
104
104
  return infrastructureFailure === undefined
105
105
  ? result.knownFailure
106
106
  : {
107
- cause: infrastructureFailure.cause,
107
+ ...(infrastructureFailure.cause === undefined
108
+ ? {}
109
+ : { cause: infrastructureFailure.cause }),
108
110
  diagnostic: infrastructureFailure.diagnostic,
109
111
  ...(infrastructureFailure.identity === undefined
110
112
  ? {}
@@ -2007,6 +2007,9 @@ export async function loadResumableInspectorRun(
2007
2007
  const admitted: AdmittedInspectorInvocation = {
2008
2008
  role: "inspector",
2009
2009
  ...resumedBaseAdmitted(loaded),
2010
+ ...(loaded.admittedFields.sourceRunPath === undefined
2011
+ ? {}
2012
+ : { sourceRunPath: loaded.admittedFields.sourceRunPath }),
2010
2013
  };
2011
2014
  return seatLoadedResult(loaded, admitted);
2012
2015
  }