@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
@@ -17,7 +17,8 @@
17
17
  * - retryable/missing/nonboolean/contradictory/malformed: nonterminal
18
18
  */
19
19
 
20
- import { LEGACY_REVIEW_OUTPUT_ROLES, PACKAGED_ROLE_REGISTRY } from "./packaged-role-registry.ts";
20
+ import { isTerminatingToolName } from "./package-contracts/terminating-tools.ts";
21
+ import { LEGACY_REVIEW_OUTPUT_ROLES, receiptSeat } from "./packaged-role-registry.ts";
21
22
  import { isUuidV7, uuidv7 } from "./uuidv7.ts";
22
23
  import { isRecord } from "./unknown-value.ts";
23
24
  import { workSubjectKeysEqual } from "./work-subject-identity.ts";
@@ -106,11 +107,6 @@ export function isNavigatorInfrastructureFailureFact(
106
107
  return Object.keys(value as object).length === NAVIGATOR_INFRASTRUCTURE_FAILURE_KEYS.length;
107
108
  }
108
109
 
109
- const PACKAGED_ROLE_OUTPUT_TOOLS: ReadonlyMap<string, string> = new Map(
110
- [...PACKAGED_ROLE_REGISTRY.filter((entry) => entry.outputTool !== "ak_submission_output")
111
- .map((entry) => [entry.outputTool, entry.role] as const), ...LEGACY_REVIEW_OUTPUT_ROLES],
112
- );
113
-
114
110
  export type NavigatorInvocationEntryLike = {
115
111
  readonly type?: string;
116
112
  readonly customType?: string;
@@ -224,9 +220,7 @@ export function packagedRoleOutputRejectionReason(message: {
224
220
  readonly content?: unknown;
225
221
  }): string | undefined {
226
222
  if (typeof message.toolName !== "string") return undefined;
227
- if (!PACKAGED_ROLE_OUTPUT_TOOLS.has(message.toolName) && message.toolName !== "ak_submission_output") {
228
- return undefined;
229
- }
223
+ if (!isTerminatingToolName(message.toolName)) return undefined;
230
224
  if (message.isError !== true) return undefined;
231
225
  if (classifyPackagedRoleTerminalResult(message).kind !== "nonterminal") return undefined;
232
226
  const content = message.content;
@@ -252,7 +246,7 @@ export function classifyPackagedRoleTerminalResult(
252
246
  message: PackagedRoleTerminalMessage,
253
247
  ): PackagedRoleTerminalClassification {
254
248
  if (typeof message.toolName !== "string") return { kind: "nonterminal" };
255
- if (!PACKAGED_ROLE_OUTPUT_TOOLS.has(message.toolName) && message.toolName !== "ak_submission_output") return { kind: "nonterminal" };
249
+ if (!isTerminatingToolName(message.toolName)) return { kind: "nonterminal" };
256
250
 
257
251
  // Base identity is enough; durable details may carry typed failure evidence (#475).
258
252
  const hasInfraBase = hasNavigatorInfrastructureFailureBase(message.details);
@@ -311,12 +305,11 @@ function durableTerminalAt(
311
305
  ? entry.message
312
306
  : undefined;
313
307
  if (typeof message?.toolName !== "string") return undefined;
314
- const marker = message.toolName === "ak_submission_output"
315
- ? entries.slice(0, index).reverse().find(isInvocationMarkerEntry)
316
- : undefined;
317
- const role = message.toolName === "ak_submission_output"
318
- ? parseInvocationMarkerIdentity(marker?.data)?.role ?? "unknown"
319
- : PACKAGED_ROLE_OUTPUT_TOOLS.get(message.toolName);
308
+ // The shared tool name takes its seat from the invocation marker before it.
309
+ const role = receiptSeat(message.toolName, () => {
310
+ const marker = entries.slice(0, index).reverse().find(isInvocationMarkerEntry);
311
+ return parseInvocationMarkerIdentity(marker?.data)?.role ?? "unknown";
312
+ })?.seat;
320
313
  if (role === undefined) return undefined;
321
314
  const classification = classifyPackagedRoleTerminalResult(message);
322
315
  if (classification.kind !== "accepted" && classification.kind !== "infrastructure") {
@@ -5,8 +5,6 @@
5
5
  */
6
6
  import { REVIEW_SUBMISSION_OUTPUT_TOOL_NAME } from "./review-submission.ts";
7
7
 
8
- import { isRecord } from "./unknown-value.ts";
9
-
10
8
  export const NOTARY_OUTPUT_TOOL_NAME: string = REVIEW_SUBMISSION_OUTPUT_TOOL_NAME;
11
9
  export const NOTARY_SOURCE_RUN_FLAG = {
12
10
  name: "ak-notary-source-run",
@@ -40,14 +38,3 @@ export type NotaryOutput =
40
38
  readonly reason?: unknown;
41
39
  readonly findings?: unknown;
42
40
  };
43
-
44
- /**
45
- * Settlement/recording path: only lawful recorded converged/continue/escalate.
46
- * Does not gate role admission — callers must not use this to reject a submission.
47
- */
48
- export function validateRecordedNotaryOutput(value: unknown): NotaryOutput {
49
- if (!isRecord(value)) {
50
- throw new Error("Notary output is not an object");
51
- }
52
- return value as NotaryOutput;
53
- }
@@ -4,8 +4,6 @@
4
4
  */
5
5
  import { REVIEW_SUBMISSION_OUTPUT_TOOL_NAME } from "../review-submission.ts";
6
6
 
7
- import { isRecord } from "../unknown-value.ts";
8
-
9
7
  export const AUDITOR_OUTPUT_TOOL_NAME: string = REVIEW_SUBMISSION_OUTPUT_TOOL_NAME;
10
8
 
11
9
  export type AuditorOutput =
@@ -16,13 +14,3 @@ export type AuditorOutput =
16
14
  readonly conflicts?: unknown;
17
15
  readonly decisionGate?: unknown;
18
16
  };
19
-
20
- /** #836: no field drop — original object is the receipt. */
21
- export function projectLawfulAuditorOutput(value: unknown): AuditorOutput | undefined {
22
- return isRecord(value) ? (value as AuditorOutput) : undefined;
23
- }
24
-
25
- export function validateRecordedAuditorOutput(value: unknown): AuditorOutput {
26
- if (!isRecord(value)) throw new Error("Auditor output is not an object");
27
- return value as AuditorOutput;
28
- }
@@ -31,6 +31,9 @@ const fixerOutputObject = Type.Object({
31
31
  description:
32
32
  "各类 class 结算,原样留存。每类写 name、shape(错误形状一句)。按代码形状认的类写 search(实际跑的搜索命令,原样)、hits(命令输出的每个命中一行 { where: path:line, outcome: 已修 | 不同类:理由 });按情形认的类写 cases(每种前序经历一行 { case: 对象先经历了什么, entry: 从真实入口怎么走到它, before: 修前结果, after: 修后结果 })。删并类写 files(本票起点到 HEAD 的 git diff --name-status 里每个文件一行 { file, hits: 该类在此文件的命中 path:line 列表,没有为空, outcome: 已修 | 无:比对了哪几处、为什么不算 | 未修:理由 })。完成项的 disposition 为 completed,可写 commitSha。拒绝项的 disposition 为 refused,可写 remainingScope、blocker。",
33
33
  }),
34
+ for: Type.Unknown({
35
+ description: "修的是哪份判词:<席>#<轮>,如 judge#5,原样落到进度行;没有就填 null。",
36
+ }),
34
37
  diffItems: diffItemsField,
35
38
  testEvidence: Type.Unknown({
36
39
  description:
@@ -58,6 +61,7 @@ export type FixerOutput = {
58
61
  readonly blocker?: unknown;
59
62
  readonly reason?: unknown;
60
63
  readonly classResults?: unknown;
64
+ readonly for?: unknown;
61
65
  readonly testEvidence?: unknown;
62
66
  readonly diffItems?: unknown;
63
67
  };
@@ -8,8 +8,6 @@ import { Type } from "typebox";
8
8
  import { openToolObject } from "../open-tool-schema.ts";
9
9
  import { withTerminatingOutputDeclarations } from "./terminating-infrastructure.ts";
10
10
 
11
- import { isRecord } from "../unknown-value.ts";
12
-
13
11
  export const GATEKEEPER_OUTPUT_TOOL_NAME = "ak_gatekeeper_output";
14
12
 
15
13
  /** Same open decision shape the province uses inside audit sessions. */
@@ -39,10 +37,3 @@ function asStringArray(value: unknown): readonly string[] {
39
37
  if (!Array.isArray(value)) return [];
40
38
  return value.filter((item): item is string => typeof item === "string");
41
39
  }
42
-
43
- /** #836: no status allowlist rejection — pass object through. */
44
- export function validateRecordedGatekeeperOutput(value: unknown): GatekeeperDirectOutput {
45
- if (!isRecord(value)) throw new Error("Gatekeeper output is not an object");
46
- return value as GatekeeperDirectOutput;
47
- }
48
-
@@ -77,40 +77,6 @@ function byStatusFromUnknown(value: unknown): Map<string, string> {
77
77
  return out;
78
78
  }
79
79
 
80
- /**
81
- * Project one Navigator advice receipt as prose (display / single-advice path).
82
- * Accepts { prose }, a bare string, or any object — objects stringify as the
83
- * prose body so historical / free-form submissions still present. Shape is not
84
- * an admission gate (ADR 0055 / 仓内 CLAUDE.md 开篇 / #959).
85
- */
86
- export function projectLawfulNavigatorOutput(value: unknown): NavigatorAdvice | undefined {
87
- if (value === undefined || value === null) return undefined;
88
- if (typeof value === "string") return { prose: value };
89
- if (isRecord(value)) {
90
- if (typeof value.prose === "string") return { prose: value.prose };
91
- if (value.prose !== undefined && value.prose !== null) {
92
- const serialized = nonEmptyProse(value.prose);
93
- if (serialized !== undefined) return { prose: serialized };
94
- }
95
- // Free-form object submission: present the whole body as prose when it has content.
96
- const keys = Object.keys(value);
97
- if (keys.length === 0) return { prose: "" };
98
- return { prose: JSON.stringify(value) };
99
- }
100
- return { prose: String(value) };
101
- }
102
-
103
- /**
104
- * Settlement/recording path: project prose. Does not gate role admission.
105
- */
106
- export function validateRecordedNavigatorOutput(value: unknown): NavigatorAdvice {
107
- const projected = projectLawfulNavigatorOutput(value);
108
- if (projected === undefined) {
109
- throw new Error("Navigator output is empty");
110
- }
111
- return projected;
112
- }
113
-
114
80
  /**
115
81
  * Extract parallel-prepare advice. Empty / missing → undefined.
116
82
  * Never a rejection — shape is not an admission gate.
@@ -34,7 +34,3 @@ export type ReviewerAmendments = Readonly<
34
34
  export type ReviewerIntent =
35
35
  | Readonly<{ status: "completed"; amendments?: ReviewerAmendments }>
36
36
  | Readonly<{ status: "refused"; diagnostic: string; amendments?: ReviewerAmendments }>;
37
-
38
- export function validateReviewerIntent(output: unknown): ReviewerIntent {
39
- return output as ReviewerIntent;
40
- }
@@ -13,22 +13,27 @@ import {
13
13
  } from "./judge-output.ts";
14
14
  import {
15
15
  REVIEWER_OUTPUT_TOOL_NAME,
16
- validateReviewerIntent,
17
16
  type ReviewerIntent,
18
17
  } from "./reviewer-output.ts";
19
- import { LEGACY_REVIEW_OUTPUT_ROLES, PACKAGED_ROLE_REGISTRY } from "../packaged-role-registry.ts";
18
+ import {
19
+ LEGACY_REVIEW_OUTPUT_ROLES,
20
+ PACKAGED_ROLE_REGISTRY,
21
+ packagedRoleMetadata,
22
+ receiptSeat,
23
+ receiptStatus,
24
+ } from "../packaged-role-registry.ts";
20
25
  import { CorrectableSubmissionError } from "../submission-correctable-error.ts";
21
- import { DOCTOR_OUTPUT_TOOL_NAME, validateDoctorSubmissionShape, validateRecordedDoctorOutput, type DoctorOutput, type DoctorSubmission } from "../doctor-contracts.ts";
22
- import { GATEKEEPER_OUTPUT_TOOL_NAME, validateRecordedGatekeeperOutput, type GatekeeperDirectOutput } from "./gatekeeper-output.ts";
23
- import { NAVIGATOR_OUTPUT_TOOL_NAME, validateRecordedNavigatorOutput, type NavigatorAdvice } from "./navigator-output.ts";
24
- import { AUDITOR_OUTPUT_TOOL_NAME, validateRecordedAuditorOutput, type AuditorOutput } from "./auditor-output.ts";
25
- import { MERGER_OUTPUT_TOOL_NAME, validateMergerOutput, type MergerOutput } from "../merger-contracts.ts";
26
- import { NOTARY_OUTPUT_TOOL_NAME, validateRecordedNotaryOutput, type NotaryOutput } from "../notary-contracts.ts";
26
+ import { validateDoctorSubmissionShape, type DoctorOutput, type DoctorSubmission } from "../doctor-contracts.ts";
27
+ import type { GatekeeperDirectOutput } from "./gatekeeper-output.ts";
28
+ import type { NavigatorAdvice } from "./navigator-output.ts";
29
+ import type { AuditorOutput } from "./auditor-output.ts";
30
+ import { MERGER_OUTPUT_TOOL_NAME, type MergerOutput } from "../merger-contracts.ts";
31
+ import type { NotaryOutput } from "../notary-contracts.ts";
27
32
  import type { CountersignVerdict } from "../countersign-contracts.ts";
28
33
  import type { GleanerLeftOutput } from "../gleaner-left-contracts.ts";
29
- import { INSPECTOR_OUTPUT_TOOL_NAME, validateRecordedInspectorOutput, type InspectorOutput } from "../inspector-contracts.ts";
30
- import { DIARIST_OUTPUT_TOOL_NAME, validateRecordedDiaristOutput, type DiaristOutput } from "../diarist-contracts.ts";
31
- import { SECRETARIAT_OUTPUT_TOOL_NAME, type SecretariatVerdict } from "../secretariat-contracts.ts";
34
+ import type { InspectorOutput } from "../inspector-contracts.ts";
35
+ import type { DiaristOutput } from "../diarist-contracts.ts";
36
+ import type { SecretariatVerdict } from "../secretariat-contracts.ts";
32
37
  import {
33
38
  CODER_OUTPUT_TOOL_NAME,
34
39
  FIXER_OUTPUT_TOOL_NAME,
@@ -45,17 +50,8 @@ export {
45
50
  JUDGE_OUTPUT_TOOL_NAME,
46
51
  REVIEWER_OUTPUT_TOOL_NAME,
47
52
  MERGER_OUTPUT_TOOL_NAME,
48
- validateReviewerIntent,
49
53
  validateAcceptedWorkerDetails,
50
54
  validateDoctorSubmissionShape,
51
- validateRecordedDoctorOutput,
52
- validateMergerOutput,
53
- validateRecordedNotaryOutput,
54
- validateRecordedInspectorOutput,
55
- validateRecordedGatekeeperOutput,
56
- validateRecordedNavigatorOutput,
57
- validateRecordedAuditorOutput,
58
- validateRecordedDiaristOutput,
59
55
  };
60
56
  export type {
61
57
  CollectorReceipt,
@@ -129,17 +125,6 @@ export function validateAcceptedDetails(
129
125
  return {} as AcceptedDetails;
130
126
  }
131
127
 
132
- /**
133
- * #836: args↔details equality rejection deleted. Details are recorded as submitted.
134
- */
135
- export function validateAcceptedLifecycle(
136
- toolName: TerminatingToolName,
137
- _argumentsValue: unknown,
138
- detailsValue: unknown,
139
- ): AcceptedDetails {
140
- return validateAcceptedDetails(toolName, detailsValue);
141
- }
142
-
143
128
  /** Machine-facing facts from an accepted terminating receipt. No presentation joins. */
144
129
  export type AcceptedFacts = {
145
130
  status?: string;
@@ -149,12 +134,11 @@ export type AcceptedFacts = {
149
134
  /** Read status/commit leaves the role wrote — never invent defaults (#836). */
150
135
  export function acceptedFacts(toolName: TerminatingToolName, details: AcceptedDetails): AcceptedFacts {
151
136
  const record = details as Record<string, unknown>;
152
- const entry = PACKAGED_ROLE_REGISTRY.find((candidate) => candidate.outputTool === toolName);
153
- const legacyRole = LEGACY_REVIEW_OUTPUT_ROLES.get(toolName);
154
- const statusKey = legacyRole === "judge" || legacyRole === "countersign"
155
- ? `${legacyRole}Status`
156
- : entry !== undefined && "receiptStatusKey" in entry ? entry.receiptStatusKey : "status";
157
- const status = typeof record[statusKey] === "string" ? record[statusKey] : undefined;
137
+ const received = receiptStatus(details);
138
+ const status = typeof received === "string" ? received : undefined;
139
+ // The commit leaf is one seat's own. The shared tool name carries none.
140
+ const seat = receiptSeat(toolName, () => undefined)?.seat;
141
+ const entry = seat === undefined ? undefined : packagedRoleMetadata(seat);
158
142
  const commitKey = entry !== undefined && "receiptCommitKey" in entry ? entry.receiptCommitKey : undefined;
159
143
  const commitWhen = entry !== undefined && "receiptCommitWhen" in entry ? entry.receiptCommitWhen : undefined;
160
144
  const commit = commitKey !== undefined
@@ -15,6 +15,7 @@ import { AUDITOR_OUTPUT_TOOL_NAME } from "./package-contracts/auditor-output.ts"
15
15
  import { DIARIST_OUTPUT_TOOL_NAME } from "./diarist-contracts.ts";
16
16
  import { SECRETARIAT_OUTPUT_TOOL_NAME } from "./secretariat-contracts.ts";
17
17
  import { JUDGE_AUDIT_TOOL_NAME } from "./judge-auditor.ts";
18
+ import { isRecord } from "./unknown-value.ts";
18
19
 
19
20
  /** Historical durable session names; these are read aliases, never registered tools. */
20
21
  export const LEGACY_REVIEW_OUTPUT_ROLES = new Map<string, string>([
@@ -25,6 +26,38 @@ export const LEGACY_REVIEW_OUTPUT_ROLES = new Map<string, string>([
25
26
  ["ak_auditor_output", "auditor"],
26
27
  ]);
27
28
 
29
+ /** Conclusion keys in reading order: `status`, then the keys older receipts used. */
30
+ const RECEIPT_STATUS_KEYS = ["status", "secretariatStatus", "judgeStatus", "countersignStatus"] as const;
31
+
32
+ /**
33
+ * The conclusion word a receipt carries, as written. Absent when no key holds one.
34
+ * The only reader of that word: a live submission and a ledger row read the same.
35
+ */
36
+ export function receiptStatus(receipt: unknown): unknown {
37
+ if (!isRecord(receipt)) return undefined;
38
+ for (const key of RECEIPT_STATUS_KEYS) {
39
+ if (Object.hasOwn(receipt, key)) return receipt[key];
40
+ }
41
+ return undefined;
42
+ }
43
+
44
+ /**
45
+ * The seat a receipt belongs to, from the tool that carried it. A historical
46
+ * name or a name one seat owns names that seat. The name several seats share
47
+ * names none, and the run's own seat is asked.
48
+ */
49
+ export function receiptSeat(
50
+ toolName: string,
51
+ runSeat: () => string | undefined,
52
+ ): { readonly seat: string; readonly source: "tool" | "invocation" } | undefined {
53
+ const legacy = LEGACY_REVIEW_OUTPUT_ROLES.get(toolName);
54
+ if (legacy !== undefined) return { seat: legacy, source: "tool" };
55
+ const owners = PACKAGED_ROLE_REGISTRY.filter((entry) => entry.outputTool === toolName);
56
+ if (owners.length === 1) return { seat: owners[0]!.role, source: "tool" };
57
+ const seat = owners.length === 0 ? undefined : runSeat();
58
+ return seat === undefined ? undefined : { seat, source: "invocation" };
59
+ }
60
+
28
61
  /** Success-terminal facts that still differ by seat. */
29
62
  export type PackagedArtifactFace = {
30
63
  readonly reportPhase?: true;
@@ -88,7 +121,6 @@ export const PUBLIC_ROLE_RECORDS = [
88
121
  /** Factory board: court until another station has started, then marshal. */
89
122
  boardPlacement: "judge-history",
90
123
  activationStage: "load-and-install",
91
- receiptStatusKey: "status",
92
124
  sessionMaterials: [
93
125
  "CLAUDE.md",
94
126
  "souls/judge.md",
@@ -319,7 +351,6 @@ export const PUBLIC_ROLE_RECORDS = [
319
351
  { field: "ticketNumber" },
320
352
  ],
321
353
  activationStage: "load-and-install",
322
- receiptStatusKey: "status",
323
354
  // #924: 公用《票面法》三席同装
324
355
  sessionMaterials: ["CLAUDE.md", "souls/countersign.md", "souls/ticket-law.md", "souls/design-law.md", "souls/audit-law.md", "souls/quality-law.md", "resources/countersign-ticket-issue.md", "docs/adr/0057-schema-narrowing-cuts-the-required-set-not-the-declared-set.md"],
325
356
  },
@@ -337,7 +368,6 @@ export const PUBLIC_ROLE_RECORDS = [
337
368
  { field: "ticketNumber" },
338
369
  ],
339
370
  activationStage: "load-and-install",
340
- receiptStatusKey: "secretariatStatus",
341
371
  // #924: owner-finalized Soul + 票面法 + 给事中/符宝郎行为指南
342
372
  sessionMaterials: [
343
373
  "CLAUDE.md",
@@ -9,7 +9,7 @@ import type { PostAdmissionEnv } from "./post-admission.ts";
9
9
  import type { CliIo } from "./cli-io.ts";
10
10
  import { currentReplyRows, type TerminalResult, type TerminalRoleOutcome } from "./terminal.ts";
11
11
 
12
- import { isRecord } from "../unknown-value.ts";
12
+ import { receiptStatus } from "../packaged-role-registry.ts";
13
13
 
14
14
  export type CountersignRunEnv = PostAdmissionEnv & {
15
15
  principalAuthority: DurablePrincipalAuthority;
@@ -54,10 +54,7 @@ export type CourtDiaristInvocationResult = {
54
54
  };
55
55
 
56
56
  function isEscalatePayload(payload: unknown): boolean {
57
- if (!isRecord(payload)) return false;
58
- return (
59
- payload.status === "escalate"
60
- );
57
+ return receiptStatus(payload) === "escalate";
61
58
  }
62
59
 
63
60
  /**
@@ -9,7 +9,6 @@ import { createPiDoctorAuditor } from "../doctor-auditor.ts";
9
9
 
10
10
  import type { DurablePrincipalAuthority, HostContext, RoleTurnRequest } from "../host-contracts.ts";
11
11
  import { officerConclusionReask, gateOfficerForSubject, type GateOfficer } from "../gatekeeper-role.ts";
12
- import { receivedDiscriminator } from "../submission-errors.ts";
13
12
  import { REVIEW_QUEUE_STATUSES } from "../review-submission.ts";
14
13
  import { JUDGE_GATES, runJudgeGates } from "../judge-role.ts";
15
14
  import { WORKER_DONE_STATUSES } from "../worker-submission-contracts.ts";
@@ -36,6 +35,7 @@ import {
36
35
  packagedBindsBoardTicket,
37
36
  packagedRebindSourceOnResume,
38
37
  packagedRoleMetadata,
38
+ receiptStatus,
39
39
  } from "../packaged-role-registry.ts";
40
40
  import { readAuditorResumeBinding } from "../auditor-soul.ts";
41
41
  import { CliUsageError } from "./cli-errors.ts";
@@ -46,8 +46,8 @@ import {
46
46
  appendCallerFileFlagPaths,
47
47
  buildInstructionTransportPrompt,
48
48
  materializeCountersignInvocation,
49
+ persistAdmittedAuditedLeg,
49
50
  persistAdmittedAuditedSubmissionToolCallId,
50
- persistAdmittedSourceRunPath,
51
51
  readAdmittedAuditedSubmissionToolCallId,
52
52
  recordAdmittedCorrelation,
53
53
  recordChildDiaristRun,
@@ -85,6 +85,7 @@ import {
85
85
  ledgerReadScope,
86
86
  presentStructuralRejection,
87
87
  readBoundSessionEntries,
88
+ retainPackageFault,
88
89
  trySettlePublicSeat,
89
90
  type SettlementCourtScope,
90
91
  } from "./settlement.ts";
@@ -106,7 +107,8 @@ import {
106
107
  latestPayloadEscalated,
107
108
  type CountersignRunEnv,
108
109
  } from "./countersign-run.ts";
109
- import { isRecord, errorText } from "../unknown-value.ts";
110
+ import { readAuditedRound } from "../ticket-progress.ts";
111
+ import { errorText } from "../unknown-value.ts";
110
112
 
111
113
  export type InstructionSeatRunEnv = PostAdmissionEnv & Pick<
112
114
  CountersignRunEnv,
@@ -120,7 +122,7 @@ type SeatRunResult = {
120
122
  };
121
123
 
122
124
  const AUDITED_ROLES = new Set<PackagedRole>(["judge", "fixer", "coder", "secretariat", "countersign", "doctor"]);
123
- const SECRETARIAT_STATUS_REASK = "secretariatStatus 不是 converged、escalate 之一。请重新交卷,secretariatStatus 写明其一。";
125
+ const SECRETARIAT_STATUS_REASK = "status 不是 converged、escalate 之一。请重新交卷,status 写明其一。";
124
126
  const WORKER_ROUTING_STATUSES: ReadonlySet<string> = new Set([
125
127
  "planned", "completed", "refused", "partially_completed", "unfinished",
126
128
  ]);
@@ -178,7 +180,7 @@ function unreadablePostSubmissionStatus(
178
180
  const route = POST_SUBMISSION_ROUTING[admitted.role];
179
181
  if (route === undefined) return undefined;
180
182
  const payload = terminal.roleOutcome.payloads?.at(-1);
181
- const status = receivedDiscriminator(payload, "status");
183
+ const status = receiptStatus(payload);
182
184
  return typeof status === "string" && route.statuses.has(status)
183
185
  ? undefined
184
186
  : route.reask ?? officerConclusionReask(status);
@@ -803,6 +805,30 @@ async function runOmittedLensBatch(
803
805
  return { exitCode: failed ? 1 : 0, terminal };
804
806
  }
805
807
 
808
+ /**
809
+ * #1200: every officer admission that names an audited leg — gate summons and
810
+ * a caller's own `--source-run`, first mint and re-summons alike — pins
811
+ *「审 谁#轮」before the officer runs, in the same page write as the source
812
+ * path when this admission is the one that records it. A row that cannot be
813
+ * read keeps its cause on the officer run; the officer still runs and its rows
814
+ * carry no `for`.
815
+ */
816
+ async function pinAuditedLegAtAdmission(
817
+ officerRunDirectory: string,
818
+ auditedRunDirectory: string,
819
+ io: CliIo,
820
+ source?: { readonly sourceRunPath: string; readonly auditorSubject?: "judge" | "doctor" | undefined },
821
+ ): Promise<void> {
822
+ const { for: auditedRound, fault } = readAuditedRound(auditedRunDirectory);
823
+ persistAdmittedAuditedLeg(officerRunDirectory, { for: auditedRound, ...source });
824
+ if (fault === undefined) return;
825
+ await retainPackageFault({
826
+ runDirectory: officerRunDirectory,
827
+ diagnostic: fault,
828
+ stderr: (text) => io.stderr(text),
829
+ });
830
+ }
831
+
806
832
  /**
807
833
  * One same-parent lookup. Seat branches still build their own summons.
808
834
  * A found child resumes that child. No prior run, explicit new, or a typed
@@ -839,6 +865,7 @@ function resumeSameParentInstructionSeat(input: {
839
865
  },
840
866
  input.env,
841
867
  input.io,
868
+ input.parentRunPath,
842
869
  );
843
870
  },
844
871
  });
@@ -945,7 +972,9 @@ async function runCountersignBody(
945
972
  );
946
973
  await markRunAdmitted(admitted, env.principalAuthority);
947
974
  if (gateParentRunPath !== undefined) {
948
- await persistAdmittedSourceRunPath(admitted, gateParentRunPath);
975
+ await pinAuditedLegAtAdmission(admitted.runDirectory, gateParentRunPath, io, {
976
+ sourceRunPath: gateParentRunPath,
977
+ });
949
978
  admitted = { ...admitted, sourceRunPath: gateParentRunPath };
950
979
  }
951
980
  // #1208 C1 / #1166 J11: one shared initial-prompt seam (incl. file flags).
@@ -1169,12 +1198,22 @@ export async function runPublicInstructionSeat(
1169
1198
  }
1170
1199
 
1171
1200
  if (instructionSourceRunPath !== undefined) {
1172
- await persistAdmittedSourceRunPath(admitted, instructionSourceRunPath);
1201
+ await pinAuditedLegAtAdmission(admitted.runDirectory, instructionSourceRunPath, io, {
1202
+ sourceRunPath: instructionSourceRunPath,
1203
+ });
1173
1204
  admitted = { ...admitted, sourceRunPath: instructionSourceRunPath } as AdmittedRoleInvocation;
1174
- }
1175
- if (record.sameParent === "subject-source" && auditorSource !== undefined) {
1176
- await persistAdmittedSourceRunPath(admitted, auditorSource, auditorSubject);
1205
+ } else if (record.sameParent === "subject-source" && auditorSource !== undefined) {
1206
+ await pinAuditedLegAtAdmission(admitted.runDirectory, auditorSource, io, {
1207
+ sourceRunPath: auditorSource,
1208
+ auditorSubject,
1209
+ });
1177
1210
  admitted = { ...admitted, sourceRunPath: auditorSource } as AdmittedRoleInvocation;
1211
+ } else {
1212
+ // The admission itself already recorded the source (source-locator seats).
1213
+ const auditedRunDirectory = admittedSourceRunPath(admitted);
1214
+ if (auditedRunDirectory !== undefined) {
1215
+ await pinAuditedLegAtAdmission(admitted.runDirectory, auditedRunDirectory, io);
1216
+ }
1178
1217
  }
1179
1218
  // #1208 C2: same helper as resume — inherit the audited source's known ticket.
1180
1219
  admitted = await inheritKnownTicketFromSource(admitted, env.principalAuthority);
@@ -1249,6 +1288,8 @@ export async function runPublicInstructionSeatResume(
1249
1288
  request: PublicResumeRequest,
1250
1289
  env: InstructionSeatRunEnv,
1251
1290
  io: CliIo,
1291
+ /** #1200: the audited leg a same-parent re-summons names; absent on every other resume. */
1292
+ resummonedFor?: string,
1252
1293
  ): Promise<SeatRunResult> {
1253
1294
  let selectedRequest = request;
1254
1295
  const resume = async () => {
@@ -1286,6 +1327,12 @@ export async function runPublicInstructionSeatResume(
1286
1327
  return { ...loaded, admitted };
1287
1328
  },
1288
1329
  buildTurnRequest: async (admitted, effective) => {
1330
+ // #1200: the turn is built once this leg has taken the summons — inside
1331
+ // its writer lease wherever the resume holds one — and before the host
1332
+ // turn. A summons the lease refuses never gets here and pins nothing.
1333
+ if (resummonedFor !== undefined) {
1334
+ await pinAuditedLegAtAdmission(admitted.runDirectory, resummonedFor, io);
1335
+ }
1289
1336
  const summonsPrepared = await prepareSummonsResumeMaterials(admitted.runDirectory, effective.summons);
1290
1337
  const projection = resumeTurnRequestProjectionOptions(
1291
1338
  admitted, effective, env, summonsPrepared,
@@ -1570,9 +1617,7 @@ async function auditSubmittedRole(
1570
1617
  || turn.terminal?.roleOutcome.kind !== "accepted") return turn;
1571
1618
  const accepted = turn.terminal.roleOutcome.payloads?.at(-1);
1572
1619
  if (accepted === undefined) throw new Error("accepted submission has no payload");
1573
- const record = isRecord(accepted)
1574
- ? accepted as Record<string, unknown> : undefined;
1575
- const status = admitted.role === "secretariat" ? record?.secretariatStatus : record?.status;
1620
+ const status = receiptStatus(accepted);
1576
1621
  // A gate summon already owns this conclusion's reasks. The seat must not
1577
1622
  // start another budget on the same run (parentRunPath is that summon).
1578
1623
  const gateOwnsStatusReask = typeof env.parentRunPath === "string" && env.parentRunPath.trim() !== "";
@@ -478,29 +478,44 @@ async function mergeInvocationIdentityPage(
478
478
  }
479
479
 
480
480
  /**
481
- * Persist parent --source-run path onto the admitted section for officer resume lookup (#747).
482
- * Reuses the existing notary sourceRunPath key; does not invent a new field name.
481
+ * What this officer audits, on its admitted section in one page write.
482
+ * `for` (#1200) is the audited leg's「席#轮」at this admission: a new value
483
+ * replaces the old one, none clears it. `sourceRunPath` (#747) is the parent
484
+ * --source-run path kept for officer resume lookup, given only by the admission
485
+ * that first records it; it reuses the existing notary key and is never replaced.
483
486
  */
484
- export async function persistAdmittedSourceRunPath(
485
- admitted: AdmittedRoleInvocation,
486
- sourceRunPath: string,
487
- auditorSubject?: "judge" | "doctor",
488
- ): Promise<void> {
489
- if (sourceRunPath.trim() === "") {
490
- throw new Error("persistAdmittedSourceRunPath requires a non-empty sourceRunPath");
487
+ export function persistAdmittedAuditedLeg(
488
+ runDirectory: string,
489
+ audited: {
490
+ readonly for: string | undefined;
491
+ readonly sourceRunPath?: string;
492
+ readonly auditorSubject?: "judge" | "doctor" | undefined;
493
+ },
494
+ ): void {
495
+ const { sourceRunPath, auditorSubject } = audited;
496
+ if (sourceRunPath !== undefined && sourceRunPath.trim() === "") {
497
+ throw new Error("persistAdmittedAuditedLeg requires a non-empty sourceRunPath");
491
498
  }
492
- updateSectionSync(admitted.runDirectory, "admitted", (current) => {
493
- if (typeof current.sourceRunPath === "string" && current.sourceRunPath !== sourceRunPath) {
499
+ updateSectionSync(runDirectory, "admitted", (current) => {
500
+ if (
501
+ sourceRunPath !== undefined
502
+ && typeof current.sourceRunPath === "string"
503
+ && current.sourceRunPath !== sourceRunPath
504
+ ) {
494
505
  throw new Error(
495
- `persistAdmittedSourceRunPath refuses to replace ${current.sourceRunPath} with ${sourceRunPath}`,
506
+ `persistAdmittedAuditedLeg refuses to replace ${current.sourceRunPath} with ${sourceRunPath}`,
496
507
  );
497
508
  }
498
- const sameSubject = auditorSubject === undefined || current.auditorSubject === auditorSubject;
499
- if (current.sourceRunPath === sourceRunPath && sameSubject) return undefined;
509
+ const unchanged = current.for === audited.for
510
+ && (sourceRunPath === undefined || current.sourceRunPath === sourceRunPath)
511
+ && (auditorSubject === undefined || current.auditorSubject === auditorSubject);
512
+ if (unchanged) return undefined;
513
+ const { for: _replaced, ...rest } = current;
500
514
  return {
501
- ...current,
502
- sourceRunPath,
515
+ ...rest,
516
+ ...(sourceRunPath === undefined ? {} : { sourceRunPath }),
503
517
  ...(auditorSubject === undefined ? {} : { auditorSubject }),
518
+ ...(audited.for === undefined ? {} : { for: audited.for }),
504
519
  };
505
520
  });
506
521
  }
@@ -42,7 +42,7 @@ import type {
42
42
  RoleTurnResult,
43
43
  SessionCustomEntryAppender,
44
44
  } from "../host-contracts.ts";
45
- import { isOfficerReviewSeat } from "../packaged-role-registry.ts";
45
+ import { isOfficerReviewSeat, receiptStatus } from "../packaged-role-registry.ts";
46
46
  /** Original error bytes, never relabeled — a secondary fact riding beside a classified cause. */
47
47
  function describeCaughtError(error: unknown): { name?: string; message: string; code?: string | number } {
48
48
  if (error instanceof Error) {
@@ -1088,7 +1088,7 @@ export async function bindDiaristAssertedTicketNumber(admitted: AdmittedRoleInvo
1088
1088
  );
1089
1089
  for (const row of rows) {
1090
1090
  if (row.role !== admitted.role || !isRecord(row.accepted)) continue;
1091
- if (row.accepted.status !== "completed" || !("ticketNumber" in row.accepted)) continue;
1091
+ if (receiptStatus(row.accepted) !== "completed" || !("ticketNumber" in row.accepted)) continue;
1092
1092
  const ticketNumber = parseTicketNumber(row.accepted.ticketNumber);
1093
1093
  if (ticketNumber !== undefined) {
1094
1094
  await bindAdmittedTicketNumber(admitted, ticketNumber);
@@ -322,7 +322,7 @@ export const architectureRowSchema = Type.Union(
322
322
  const ARCH_TABLE_COMMON =
323
323
  "架构归位表:先盘既有架构——docs/adr 与票面点名法源里的层表与规矩,再打开分层配置与代码看每层现在装着什么、有没有法源里没有的层。遵循行:稿里每样进代码的东西各一行,归到法源的层里;核架构行:既有架构每条条款各一行,联网找所选框架官方文档与公认资料里承担同一关切的做法,附链接与原句。法源里既没有层表也没有架构规矩时才为空数组,并在 note 写明;只有规矩没有层表的,遵循行的 layer 写被核的那条规矩原句,核架构行按规矩逐条列。";
324
324
  export const secretariatArchitectureField = Type.Array(architectureRowSchema, {
325
- description: `${ARCH_TABLE_COMMON}有「不合」或「可改进」行,secretariatStatus 只能是 escalate:不合行的原文与两边(改稿归位/改架构)、可改进的建议,都列进 decisionGate 由陛下拍,不出给宰相答。`,
325
+ description: `${ARCH_TABLE_COMMON}有「不合」或「可改进」行,status 只能是 escalate:不合行的原文与两边(改稿归位/改架构)、可改进的建议,都列进 decisionGate 由陛下拍,不出给宰相答。`,
326
326
  });
327
327
  export const countersignArchitectureField = Type.Array(architectureRowSchema, {
328
328
  description: `${ARCH_TABLE_COMMON}有「不合」行不得署:票面意在改架构的上呈,否则封驳退签发方归位;有「可改进」行上呈,建议附原文。`,