@akagilnc/pi-workflow-roles 0.1.6108 → 0.1.6115

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 (65) hide show
  1. package/dist/acp-host/production-host.js +209 -177
  2. package/dist/compliance-transport.js +3 -3
  3. package/dist/diarist-contracts.js +0 -16
  4. package/dist/diarist-role.js +1 -2
  5. package/dist/doctor-contracts.js +1 -5
  6. package/dist/gatekeeper-role.js +6 -9
  7. package/dist/headless-host/production-host.js +162 -130
  8. package/dist/inspector-contracts.js +2 -22
  9. package/dist/inspector-role.js +1 -2
  10. package/dist/merger-contracts.js +1 -5
  11. package/dist/migrate-book-topology.js +32 -45
  12. package/dist/navigator-invocation-identity.js +8 -10
  13. package/dist/notary-contracts.js +1 -9
  14. package/dist/package-contracts/auditor-output.js +0 -10
  15. package/dist/package-contracts/fixer-output.js +3 -0
  16. package/dist/package-contracts/gatekeeper-output.js +1 -7
  17. package/dist/package-contracts/navigator-output.js +1 -25
  18. package/dist/package-contracts/reviewer-output.js +1 -5
  19. package/dist/package-contracts/terminating-tools.js +10 -24
  20. package/dist/packaged-role-registry.js +20 -4
  21. package/dist/public-cli/countersign-run.js +2 -4
  22. package/dist/public-cli/instruction-seat-run.js +55 -16
  23. package/dist/public-cli/invocation.js +22 -12
  24. package/dist/public-cli/main.js +192 -143
  25. package/dist/public-cli/post-admission.js +2 -2
  26. package/dist/review-submission.js +1 -1
  27. package/dist/role-runtime.js +15 -32
  28. package/dist/secretariat-contracts.js +1 -1
  29. package/dist/submission-errors.js +0 -9
  30. package/dist/submission-gate.js +3 -7
  31. package/dist/submission-ledger.js +4 -12
  32. package/dist/ticket-progress.js +64 -28
  33. package/dist/ticket-trajectory.js +6 -17
  34. package/dist/worker-role.js +3 -4
  35. package/package.json +1 -1
  36. package/src/compliance-transport.ts +3 -3
  37. package/src/diarist-contracts.ts +0 -16
  38. package/src/diarist-role.ts +0 -2
  39. package/src/doctor-contracts.ts +0 -4
  40. package/src/gatekeeper-role.ts +6 -9
  41. package/src/inspector-contracts.ts +1 -21
  42. package/src/inspector-role.ts +0 -2
  43. package/src/merger-contracts.ts +0 -4
  44. package/src/navigator-invocation-identity.ts +9 -16
  45. package/src/notary-contracts.ts +0 -13
  46. package/src/package-contracts/auditor-output.ts +0 -12
  47. package/src/package-contracts/fixer-output.ts +4 -0
  48. package/src/package-contracts/gatekeeper-output.ts +0 -9
  49. package/src/package-contracts/navigator-output.ts +0 -34
  50. package/src/package-contracts/reviewer-output.ts +0 -4
  51. package/src/package-contracts/terminating-tools.ts +21 -37
  52. package/src/packaged-role-registry.ts +33 -3
  53. package/src/public-cli/countersign-run.ts +2 -5
  54. package/src/public-cli/instruction-seat-run.ts +58 -13
  55. package/src/public-cli/invocation.ts +31 -16
  56. package/src/public-cli/post-admission.ts +2 -2
  57. package/src/review-submission.ts +1 -1
  58. package/src/role-runtime.ts +16 -29
  59. package/src/secretariat-contracts.ts +2 -3
  60. package/src/submission-errors.ts +0 -8
  61. package/src/submission-gate.ts +3 -7
  62. package/src/submission-ledger.ts +3 -11
  63. package/src/ticket-progress.ts +76 -33
  64. package/src/ticket-trajectory.ts +5 -18
  65. package/src/worker-role.ts +3 -4
@@ -7,7 +7,6 @@ import { dirname, resolve } from "node:path";
7
7
  import { isUnboundRunDirectory, sessionFileOf } from "../role-run-placement.js";
8
8
  import { createPiDoctorAuditor } from "../doctor-auditor.js";
9
9
  import { officerConclusionReask, gateOfficerForSubject } from "../gatekeeper-role.js";
10
- import { receivedDiscriminator } from "../submission-errors.js";
11
10
  import { REVIEW_QUEUE_STATUSES } from "../review-submission.js";
12
11
  import { JUDGE_GATES, runJudgeGates } from "../judge-role.js";
13
12
  import { WORKER_DONE_STATUSES } from "../worker-submission-contracts.js";
@@ -20,22 +19,23 @@ import { summonPublicRole } from "../public-role-summons.js";
20
19
  import { latestQueuePayload, latestQueueStatus, } from "../submission-gate.js";
21
20
  import { isSafePositiveTicketNumber, readBoardTicketNumber, } from "../run-ticket-number.js";
22
21
  import { NotarySourceRunError, resolveNotarySourceRunLocator } from "../notary-source-run.js";
23
- import { packagedAdmitsCountersign, isNavigatorSeat, packagedBindsBoardTicket, packagedRebindSourceOnResume, packagedRoleMetadata, } from "../packaged-role-registry.js";
22
+ import { packagedAdmitsCountersign, isNavigatorSeat, packagedBindsBoardTicket, packagedRebindSourceOnResume, packagedRoleMetadata, receiptStatus, } from "../packaged-role-registry.js";
24
23
  import { readAuditorResumeBinding } from "../auditor-soul.js";
25
24
  import { CliUsageError } from "./cli-errors.js";
26
- import { admitPublicRole, admittedSourceRunPath, bindAdmittedTicketNumber, appendCallerFileFlagPaths, buildInstructionTransportPrompt, materializeCountersignInvocation, persistAdmittedAuditedSubmissionToolCallId, persistAdmittedSourceRunPath, readAdmittedAuditedSubmissionToolCallId, recordAdmittedCorrelation, recordChildDiaristRun, relocateAdmittedRunToTicket, } from "./invocation.js";
25
+ import { admitPublicRole, admittedSourceRunPath, bindAdmittedTicketNumber, appendCallerFileFlagPaths, buildInstructionTransportPrompt, materializeCountersignInvocation, persistAdmittedAuditedLeg, persistAdmittedAuditedSubmissionToolCallId, readAdmittedAuditedSubmissionToolCallId, recordAdmittedCorrelation, recordChildDiaristRun, relocateAdmittedRunToTicket, } from "./invocation.js";
27
26
  import { bindDiaristAssertedTicketNumber, presentControlledFailure, packageFaultNoteFor, prepareSummonsResumeMaterials, roleTurnOptions, runPostAdmissionOneShot, runPostAdmissionResumable, runPostAdmissionSeatResume, showResumeErrorPointer, resumeTurnRequestProjectionOptions, } from "./post-admission.js";
28
27
  import { presentTerminal } from "./auto-resume.js";
29
28
  import { loadResumablePublicRole, markRunAdmitted, readCurrentCourt, } from "./run-lifecycle.js";
30
29
  import { tryResumeSameTicketSeatRun } from "./seat-ticket-binding.js";
31
- import { ledgerReadScope, presentStructuralRejection, readBoundSessionEntries, trySettlePublicSeat, } from "./settlement.js";
30
+ import { ledgerReadScope, presentStructuralRejection, readBoundSessionEntries, retainPackageFault, trySettlePublicSeat, } from "./settlement.js";
32
31
  import { warnMissingMethodSkills } from "./machine-method-skills.js";
33
32
  import { formatTerminalResult, isLawfulTypedTerminalOutcome, } from "./terminal.js";
34
33
  import { admittedSeatTurnDetails, projectRoleTurnRequest, requiredMethodSkills, } from "./turn-request.js";
35
34
  import { invokeCourtDiarist, latestPayloadEscalated, } from "./countersign-run.js";
36
- import { isRecord, errorText } from "../unknown-value.js";
35
+ import { readAuditedRound } from "../ticket-progress.js";
36
+ import { errorText } from "../unknown-value.js";
37
37
  const AUDITED_ROLES = new Set(["judge", "fixer", "coder", "secretariat", "countersign", "doctor"]);
38
- const SECRETARIAT_STATUS_REASK = "secretariatStatus 不是 converged、escalate 之一。请重新交卷,secretariatStatus 写明其一。";
38
+ const SECRETARIAT_STATUS_REASK = "status 不是 converged、escalate 之一。请重新交卷,status 写明其一。";
39
39
  const WORKER_ROUTING_STATUSES = new Set([
40
40
  "planned", "completed", "refused", "partially_completed", "unfinished",
41
41
  ]);
@@ -86,7 +86,7 @@ function unreadablePostSubmissionStatus(admitted, terminal) {
86
86
  if (route === undefined)
87
87
  return undefined;
88
88
  const payload = terminal.roleOutcome.payloads?.at(-1);
89
- const status = receivedDiscriminator(payload, "status");
89
+ const status = receiptStatus(payload);
90
90
  return typeof status === "string" && route.statuses.has(status)
91
91
  ? undefined
92
92
  : route.reask ?? officerConclusionReask(status);
@@ -569,6 +569,25 @@ async function runOmittedLensBatch(argv, parsed, env, io) {
569
569
  io.stdout(formatTerminalResult(terminal));
570
570
  return { exitCode: failed ? 1 : 0, terminal };
571
571
  }
572
+ /**
573
+ * #1200: every officer admission that names an audited leg — gate summons and
574
+ * a caller's own `--source-run`, first mint and re-summons alike — pins
575
+ *「审 谁#轮」before the officer runs, in the same page write as the source
576
+ * path when this admission is the one that records it. A row that cannot be
577
+ * read keeps its cause on the officer run; the officer still runs and its rows
578
+ * carry no `for`.
579
+ */
580
+ async function pinAuditedLegAtAdmission(officerRunDirectory, auditedRunDirectory, io, source) {
581
+ const { for: auditedRound, fault } = readAuditedRound(auditedRunDirectory);
582
+ persistAdmittedAuditedLeg(officerRunDirectory, { for: auditedRound, ...source });
583
+ if (fault === undefined)
584
+ return;
585
+ await retainPackageFault({
586
+ runDirectory: officerRunDirectory,
587
+ diagnostic: fault,
588
+ stderr: (text) => io.stderr(text),
589
+ });
590
+ }
572
591
  /**
573
592
  * One same-parent lookup. Seat branches still build their own summons.
574
593
  * A found child resumes that child. No prior run, explicit new, or a typed
@@ -593,7 +612,7 @@ function resumeSameParentInstructionSeat(input) {
593
612
  runDirectory,
594
613
  ...(reask === undefined ? {} : { message: reask }),
595
614
  ...(materials === undefined ? {} : { summons: materials }),
596
- }, input.env, input.io);
615
+ }, input.env, input.io, input.parentRunPath);
597
616
  },
598
617
  });
599
618
  }
@@ -678,7 +697,9 @@ async function runCountersignBody(parsed, env, io) {
678
697
  await materializeAdmission(isSafePositiveTicketNumber(env.boundTicketNumber) ? env.boundTicketNumber : undefined);
679
698
  await markRunAdmitted(admitted, env.principalAuthority);
680
699
  if (gateParentRunPath !== undefined) {
681
- await persistAdmittedSourceRunPath(admitted, gateParentRunPath);
700
+ await pinAuditedLegAtAdmission(admitted.runDirectory, gateParentRunPath, io, {
701
+ sourceRunPath: gateParentRunPath,
702
+ });
682
703
  admitted = { ...admitted, sourceRunPath: gateParentRunPath };
683
704
  }
684
705
  // #1208 C1 / #1166 J11: one shared initial-prompt seam (incl. file flags).
@@ -880,13 +901,25 @@ export async function runPublicInstructionSeat(argv, env, io, role, parseArgv) {
880
901
  throw error;
881
902
  }
882
903
  if (instructionSourceRunPath !== undefined) {
883
- await persistAdmittedSourceRunPath(admitted, instructionSourceRunPath);
904
+ await pinAuditedLegAtAdmission(admitted.runDirectory, instructionSourceRunPath, io, {
905
+ sourceRunPath: instructionSourceRunPath,
906
+ });
884
907
  admitted = { ...admitted, sourceRunPath: instructionSourceRunPath };
885
908
  }
886
- if (record.sameParent === "subject-source" && auditorSource !== undefined) {
887
- await persistAdmittedSourceRunPath(admitted, auditorSource, auditorSubject);
909
+ else if (record.sameParent === "subject-source" && auditorSource !== undefined) {
910
+ await pinAuditedLegAtAdmission(admitted.runDirectory, auditorSource, io, {
911
+ sourceRunPath: auditorSource,
912
+ auditorSubject,
913
+ });
888
914
  admitted = { ...admitted, sourceRunPath: auditorSource };
889
915
  }
916
+ else {
917
+ // The admission itself already recorded the source (source-locator seats).
918
+ const auditedRunDirectory = admittedSourceRunPath(admitted);
919
+ if (auditedRunDirectory !== undefined) {
920
+ await pinAuditedLegAtAdmission(admitted.runDirectory, auditedRunDirectory, io);
921
+ }
922
+ }
890
923
  // #1208 C2: same helper as resume — inherit the audited source's known ticket.
891
924
  admitted = await inheritKnownTicketFromSource(admitted, env.principalAuthority);
892
925
  const runAdmitted = async () => {
@@ -951,7 +984,9 @@ async function inheritKnownTicketFromSource(admitted, authority) {
951
984
  await relocateAdmittedRunToTicket(admitted, authority);
952
985
  return admitted;
953
986
  }
954
- export async function runPublicInstructionSeatResume(request, env, io) {
987
+ export async function runPublicInstructionSeatResume(request, env, io,
988
+ /** #1200: the audited leg a same-parent re-summons names; absent on every other resume. */
989
+ resummonedFor) {
955
990
  let selectedRequest = request;
956
991
  const resume = async () => {
957
992
  const held = [];
@@ -980,6 +1015,12 @@ export async function runPublicInstructionSeatResume(request, env, io) {
980
1015
  return { ...loaded, admitted };
981
1016
  },
982
1017
  buildTurnRequest: async (admitted, effective) => {
1018
+ // #1200: the turn is built once this leg has taken the summons — inside
1019
+ // its writer lease wherever the resume holds one — and before the host
1020
+ // turn. A summons the lease refuses never gets here and pins nothing.
1021
+ if (resummonedFor !== undefined) {
1022
+ await pinAuditedLegAtAdmission(admitted.runDirectory, resummonedFor, io);
1023
+ }
983
1024
  const summonsPrepared = await prepareSummonsResumeMaterials(admitted.runDirectory, effective.summons);
984
1025
  const projection = resumeTurnRequestProjectionOptions(admitted, effective, env, summonsPrepared);
985
1026
  // #1208: internal summons only — shared resolver owns review dialogue.
@@ -1194,9 +1235,7 @@ async function auditSubmittedRole(turn, env, io, resumedOfficer, passedReceipt)
1194
1235
  const accepted = turn.terminal.roleOutcome.payloads?.at(-1);
1195
1236
  if (accepted === undefined)
1196
1237
  throw new Error("accepted submission has no payload");
1197
- const record = isRecord(accepted)
1198
- ? accepted : undefined;
1199
- const status = admitted.role === "secretariat" ? record?.secretariatStatus : record?.status;
1238
+ const status = receiptStatus(accepted);
1200
1239
  // A gate summon already owns this conclusion's reasks. The seat must not
1201
1240
  // start another budget on the same run (parentRunPath is that summon).
1202
1241
  const gateOwnsStatusReask = typeof env.parentRunPath === "string" && env.parentRunPath.trim() !== "";
@@ -162,24 +162,34 @@ async function mergeInvocationIdentityPage(runDirectory, fields) {
162
162
  }));
163
163
  }
164
164
  /**
165
- * Persist parent --source-run path onto the admitted section for officer resume lookup (#747).
166
- * Reuses the existing notary sourceRunPath key; does not invent a new field name.
165
+ * What this officer audits, on its admitted section in one page write.
166
+ * `for` (#1200) is the audited leg's「席#轮」at this admission: a new value
167
+ * replaces the old one, none clears it. `sourceRunPath` (#747) is the parent
168
+ * --source-run path kept for officer resume lookup, given only by the admission
169
+ * that first records it; it reuses the existing notary key and is never replaced.
167
170
  */
168
- export async function persistAdmittedSourceRunPath(admitted, sourceRunPath, auditorSubject) {
169
- if (sourceRunPath.trim() === "") {
170
- throw new Error("persistAdmittedSourceRunPath requires a non-empty sourceRunPath");
171
+ export function persistAdmittedAuditedLeg(runDirectory, audited) {
172
+ const { sourceRunPath, auditorSubject } = audited;
173
+ if (sourceRunPath !== undefined && sourceRunPath.trim() === "") {
174
+ throw new Error("persistAdmittedAuditedLeg requires a non-empty sourceRunPath");
171
175
  }
172
- updateSectionSync(admitted.runDirectory, "admitted", (current) => {
173
- if (typeof current.sourceRunPath === "string" && current.sourceRunPath !== sourceRunPath) {
174
- throw new Error(`persistAdmittedSourceRunPath refuses to replace ${current.sourceRunPath} with ${sourceRunPath}`);
176
+ updateSectionSync(runDirectory, "admitted", (current) => {
177
+ if (sourceRunPath !== undefined
178
+ && typeof current.sourceRunPath === "string"
179
+ && current.sourceRunPath !== sourceRunPath) {
180
+ throw new Error(`persistAdmittedAuditedLeg refuses to replace ${current.sourceRunPath} with ${sourceRunPath}`);
175
181
  }
176
- const sameSubject = auditorSubject === undefined || current.auditorSubject === auditorSubject;
177
- if (current.sourceRunPath === sourceRunPath && sameSubject)
182
+ const unchanged = current.for === audited.for
183
+ && (sourceRunPath === undefined || current.sourceRunPath === sourceRunPath)
184
+ && (auditorSubject === undefined || current.auditorSubject === auditorSubject);
185
+ if (unchanged)
178
186
  return undefined;
187
+ const { for: _replaced, ...rest } = current;
179
188
  return {
180
- ...current,
181
- sourceRunPath,
189
+ ...rest,
190
+ ...(sourceRunPath === undefined ? {} : { sourceRunPath }),
182
191
  ...(auditorSubject === undefined ? {} : { auditorSubject }),
192
+ ...(audited.for === undefined ? {} : { for: audited.for }),
183
193
  };
184
194
  });
185
195
  }