@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
@@ -134,6 +134,8 @@ import {
134
134
  packagedRoleMetadata,
135
135
  packagedRoleOutputTool,
136
136
  packagedRolePhaseFlag,
137
+ receiptSeat,
138
+ receiptStatus,
137
139
  type PackagedRole,
138
140
  } from "./packaged-role-registry.ts";
139
141
  import {
@@ -368,7 +370,7 @@ export { COLLECTOR_OUTPUT_TOOL } from "./collector-role.ts";
368
370
  export type { CollectorReceipt } from "./package-contracts/collector-output.ts";
369
371
  export * from "./navigator-attendance.ts";
370
372
  export { MERGER_INPUT_FLAG, createMergerRoleRuntime } from "./merger-role.ts";
371
- export { MERGER_OUTPUT_TOOL_NAME, mergerInputSchema, mergerOutputSchema, validateMergerInput, validateMergerOutput } from "./merger-contracts.ts";
373
+ export { MERGER_OUTPUT_TOOL_NAME, mergerInputSchema, mergerOutputSchema, validateMergerInput } from "./merger-contracts.ts";
372
374
  export type { MergerInput, MergerMaterial, MergerOutput } from "./merger-contracts.ts";
373
375
  export { createProductionMergerGitState } from "./merger-git-state.ts";
374
376
  export type { MergerGitState, ActiveMergerGitState } from "./merger-git-state.ts";
@@ -511,16 +513,6 @@ function navigatorOutputTool(role: string): string | undefined {
511
513
  return packagedRoleOutputTool(role);
512
514
  }
513
515
 
514
- /** Status leaves that are not the shared `status` key, in registry order. */
515
- function receiptStatusFromRegistry(details: Record<string, unknown>): string | undefined {
516
- for (const entry of PACKAGED_ROLE_REGISTRY) {
517
- if (!("receiptStatusKey" in entry)) continue;
518
- const value = details[entry.receiptStatusKey];
519
- if (typeof value === "string") return value;
520
- }
521
- return undefined;
522
- }
523
-
524
516
  export function publicNavigatorSettlement(role: string, phase: NavigatorPhase, event: { toolName: string; isError?: unknown; details: unknown }): NavigatorSettlement | undefined {
525
517
  // One shared classifier owns terminal discriminant (lifecycle + settlement + extractors).
526
518
  if (event.toolName !== navigatorOutputTool(role)) return undefined;
@@ -530,13 +522,9 @@ export function publicNavigatorSettlement(role: string, phase: NavigatorPhase, e
530
522
  return { kind: "role_infrastructure_failure", role, phase };
531
523
  }
532
524
  // accepted/human — project role/phase status; classifier already rejected infra/contradiction.
533
- const details = isRecord(event.details)
534
- ? event.details as Record<string, unknown>
535
- : {};
536
- const status = typeof details.status === "string"
537
- ? details.status
538
- : receiptStatusFromRegistry(details);
539
- if (status !== undefined && status === "escalate") {
525
+ const received = receiptStatus(event.details);
526
+ const status = typeof received === "string" ? received : undefined;
527
+ if (status === "escalate") {
540
528
  return { kind: "human_decision", role, phase, status };
541
529
  }
542
530
  return { kind: "accepted", role, phase, ...(status === undefined ? {} : { status }) };
@@ -811,8 +799,7 @@ export function createDiaristRoleRuntime(
811
799
  // Routing belongs to the public seam after this tool call has returned.
812
800
  // Only completed receipts need local diary projection; other statuses
813
801
  // pass through verbatim for that seam to route.
814
- const status = submitted?.status;
815
- if (status !== "completed") return parameters;
802
+ if (receiptStatus(parameters) !== "completed") return parameters;
816
803
  const assertion = readDiaristTicketAssertion(submitted);
817
804
  // #836 7.3: pre-bound ticket is material for the LLM, not an override.
818
805
  const ticketNumber = assertion.kind === "ticket" ? assertion.ticketNumber : undefined;
@@ -938,15 +925,15 @@ export function createRoleRuntimeExtension(
938
925
  };
939
926
  const roleHost = createSubmissionLedgerHost(
940
927
  envelopeHost.host,
941
- new Map(PACKAGED_ROLE_REGISTRY.reduce<(readonly [string, import("./public-cli/terminal.ts").TerminalRoleName | readonly import("./public-cli/terminal.ts").TerminalRoleName[]])[]>((entries, { role, outputTool }) => {
942
- const existingIndex = entries.findIndex(([name]) => name === outputTool);
943
- if (existingIndex < 0) entries.push([outputTool, role]);
944
- else {
945
- const previous = entries[existingIndex]![1];
946
- entries[existingIndex] = [outputTool, [...(Array.isArray(previous) ? previous : [previous]), role]];
947
- }
948
- return entries;
949
- }, [])),
928
+ {
929
+ get(toolName) {
930
+ const seat = receiptSeat(toolName, () => {
931
+ const active = envelopeHost.host.getFlag(ROLE_FLAG.name);
932
+ return typeof active === "string" ? active : undefined;
933
+ })?.seat;
934
+ return seat === undefined ? undefined : packagedRoleMetadata(seat)?.role;
935
+ },
936
+ },
950
937
  (error, ctx, toolCallId) => hostActions.failInfrastructure(error, ctx, toolCallId),
951
938
  async (closed, context, toolCallId) => projectClosedSubmission(closed, context, toolCallId),
952
939
  );
@@ -14,8 +14,7 @@ export const SECRETARIAT_OUTPUT_TOOL_NAME = "ak_secretariat_output";
14
14
 
15
15
  /**
16
16
  * 中书省终局回执形状。
17
- * #1134: `secretariatStatus` alone is the trajectory field
18
- * (src/packaged-role-registry.ts receiptStatusKey; the public settlement reads
17
+ * #1134: `status` alone is the trajectory field (the public settlement reads
19
18
  * converged | escalate to route); its words ride the description. note/evidence/
20
19
  * decisionGate are declared name + semantic description only — the string type, the
21
20
  * number type, the nested question/options object shape and the required constraint
@@ -26,7 +25,7 @@ export const SECRETARIAT_OUTPUT_TOOL_NAME = "ak_secretariat_output";
26
25
  export const secretariatVerdictSchema = withTerminatingOutputDeclarations(
27
26
  Type.Object(
28
27
  {
29
- secretariatStatus: Type.Unknown({
28
+ status: Type.Unknown({
30
29
  description: "converged | escalate",
31
30
  }),
32
31
  ticketNumber: Type.Optional(
@@ -1,5 +1,4 @@
1
1
  import { readableGateItem } from "./readable-gate-item.ts";
2
- import { isRecord } from "./unknown-value.ts";
3
2
 
4
3
  export class WorkerCommitReminderError extends Error {
5
4
  readonly code = "worker_commit_reminder" as const;
@@ -45,13 +44,6 @@ export function unreadableDiscriminatorNotice(field: string, received: unknown):
45
44
  return `读不出 ${field}:${readableGateItem(received)}`;
46
45
  }
47
46
 
48
- /** The received discriminator only — never the rest of the receipt. */
49
- export function receivedDiscriminator(receipt: unknown, field: string): unknown {
50
- if (!isRecord(receipt)) return undefined;
51
- if (!Object.hasOwn(receipt, field)) return undefined;
52
- return (receipt as Record<string, unknown>)[field];
53
- }
54
-
55
47
  /**
56
48
  * Parent seat status unreadable for queueing (#753).
57
49
  * Correctable back to the parent itself — not a gate officer bounce, no officer field.
@@ -28,7 +28,7 @@ import {
28
28
  } from "./gatekeeper-role.ts";
29
29
  import type { PublicSummonResult } from "./public-role-summons.ts";
30
30
  import type { TerminalResult } from "./public-cli/terminal.ts";
31
- import { receivedDiscriminator } from "./submission-errors.ts";
31
+ import { receiptStatus } from "./packaged-role-registry.ts";
32
32
  import type { ReviewQueueWord } from "./review-submission.ts";
33
33
  import { deliveryLimitFromConfig } from "./receipt-delivery-policy.ts";
34
34
 
@@ -64,11 +64,8 @@ export function latestQueueStatus(terminal: TerminalResult | undefined): unknown
64
64
  if (outcome === undefined) return undefined;
65
65
  if (outcome.kind === "audit_escalation") return "escalate";
66
66
  if (outcome.kind !== "accepted") return undefined;
67
- const latest = outcome.payloads?.[outcome.payloads.length - 1];
68
- if (isRecord(latest) && Object.hasOwn(latest, "status")) {
69
- return receivedDiscriminator(latest, "status");
70
- }
71
- return outcome.status;
67
+ const received = receiptStatus(outcome.payloads?.[outcome.payloads.length - 1]);
68
+ return received === undefined ? outcome.status : received;
72
69
  }
73
70
 
74
71
  export function latestQueuePayload(terminal: TerminalResult | undefined): unknown {
@@ -78,7 +75,6 @@ export function latestQueuePayload(terminal: TerminalResult | undefined): unknow
78
75
  const payloads = outcome.payloads ?? [];
79
76
  return payloads.length === 0 ? undefined : payloads[payloads.length - 1];
80
77
  }
81
- import { isRecord } from "./unknown-value.ts";
82
78
 
83
79
  /**
84
80
  * Shared-envelope default officer summon (ADR 0018).
@@ -522,7 +522,8 @@ export function sealAcceptedSubmission(options: {
522
522
  */
523
523
  export function createSubmissionLedgerHost(
524
524
  host: RoleHost,
525
- outputTools: ReadonlyMap<string, TerminalRoleName | readonly TerminalRoleName[]>,
525
+ /** The seat an output tool's submissions belong to. Absent for any other tool. */
526
+ outputTools: { get(toolName: string): TerminalRoleName | undefined },
526
527
  failInfrastructure: (error: unknown, context: HostContext, toolCallId?: string) => never = (error) => { throw error; },
527
528
  projectClosure: (closed: ClosedSubmission, context: HostContext, toolCallId: string) => void | Promise<void> = () => undefined,
528
529
  options?: { home?: string },
@@ -572,16 +573,7 @@ export function createSubmissionLedgerHost(
572
573
  return {
573
574
  ...host,
574
575
  registerTool(tool) {
575
- const registeredRole = outputTools.get(tool.name);
576
- let role: TerminalRoleName | undefined;
577
- if (typeof registeredRole === "string") {
578
- role = registeredRole;
579
- } else if (registeredRole !== undefined) {
580
- const activeRole = host.getFlag("ak-role");
581
- role = typeof activeRole === "string" && registeredRole.includes(activeRole as TerminalRoleName)
582
- ? activeRole as TerminalRoleName
583
- : undefined;
584
- }
576
+ const role = outputTools.get(tool.name);
585
577
  if (role === undefined) return host.registerTool(tool);
586
578
  host.registerTool({
587
579
  ...tool,
@@ -26,12 +26,7 @@ import { basename, dirname, join, relative, sep } from "node:path";
26
26
  import { resolveHostDossierLandingPath } from "./host-session-record.ts";
27
27
  import type { HostContext } from "./host-contracts.ts";
28
28
  import { runDirectoryFromHostContext } from "./host-contracts.ts";
29
- import {
30
- acceptedFacts,
31
- isTerminatingToolName,
32
- type AcceptedDetails,
33
- } from "./package-contracts/terminating-tools.ts";
34
- import { packagedRoleOutputTool } from "./packaged-role-registry.ts";
29
+ import { packagedGateStageLabel, receiptStatus } from "./packaged-role-registry.ts";
35
30
  import {
36
31
  isUnboundRunDirectory,
37
32
  sessionDirectoryOf,
@@ -40,7 +35,7 @@ import {
40
35
  } from "./role-run-placement.ts";
41
36
  import { readPageSync } from "./run-dossier.ts";
42
37
  import { parseSitianRecordText } from "./sitian-reader.ts";
43
- import { isRecord } from "./unknown-value.ts";
38
+ import { errorText, isRecord } from "./unknown-value.ts";
44
39
 
45
40
  const CURRENT_FILENAME = "current.jsonl" as const;
46
41
  const RECEIPTS_DIRNAME = "receipts" as const;
@@ -52,6 +47,11 @@ export type TicketProgressLine = {
52
47
  readonly seat: string;
53
48
  /** Seat-local round; reviewer dual-lens uses `<n>.<lens>`. Empty while unbound. */
54
49
  readonly round: string;
50
+ /**
51
+ * #1200 `<seat>#<round>` this row reviews or fixes. Officer rows copy the value
52
+ * pinned at admission; fixer rows copy the receipt's own `for`. Absent otherwise.
53
+ */
54
+ readonly for?: string;
55
55
  /** This-round summons instruction bytes; empty string when none. */
56
56
  readonly instruction: string;
57
57
  /** `git rev-parse HEAD` at seal from the seat worktree; empty on failure. */
@@ -67,18 +67,17 @@ export type TicketProgressLine = {
67
67
  };
68
68
 
69
69
  /**
70
- * Append-only progress JSONL — same posture as run-dossier row files:
71
- * sole Sitian decoder keeps reachable rows; malformed lines leave diagnostics
72
- * on stderr and do not abort seal/relocate.
70
+ * Append-only progress JSONL through the sole Sitian decoder: reachable rows
71
+ * plus one diagnostic per malformed line.
73
72
  */
74
- function parseProgressText(text: string, pathForDiagnostic: string): TicketProgressLine[] {
75
- if (text.trim() === "") return [];
73
+ function decodeProgressFile(path: string): {
74
+ readonly lines: TicketProgressLine[];
75
+ readonly malformed: readonly string[];
76
+ } {
77
+ if (!existsSync(path)) return { lines: [], malformed: [] };
78
+ const text = readFileSync(path, "utf8");
79
+ if (text.trim() === "") return { lines: [], malformed: [] };
76
80
  const { records, diagnostics } = parseSitianRecordText(text);
77
- for (const diagnostic of diagnostics) {
78
- process.stderr.write(
79
- `[ticket-progress] ${pathForDiagnostic} has malformed row(s); keeps reachable rows and retains the diagnostic: line ${diagnostic.line}: ${diagnostic.error}\n`,
80
- );
81
- }
82
81
  const lines: TicketProgressLine[] = [];
83
82
  for (const record of records) {
84
83
  const parsed: unknown = record;
@@ -86,12 +85,24 @@ function parseProgressText(text: string, pathForDiagnostic: string): TicketProgr
86
85
  if (typeof parsed.seat !== "string" || typeof parsed.round !== "string") continue;
87
86
  lines.push(parsed as unknown as TicketProgressLine);
88
87
  }
89
- return lines;
88
+ return {
89
+ lines,
90
+ malformed: diagnostics.map((diagnostic) => `line ${diagnostic.line}: ${diagnostic.error}`),
91
+ };
90
92
  }
91
93
 
94
+ /**
95
+ * Same posture as run-dossier row files: malformed lines leave diagnostics on
96
+ * stderr and do not abort seal/relocate.
97
+ */
92
98
  function readProgressFile(path: string): TicketProgressLine[] {
93
- if (!existsSync(path)) return [];
94
- return parseProgressText(readFileSync(path, "utf8"), path);
99
+ const { lines, malformed } = decodeProgressFile(path);
100
+ for (const diagnostic of malformed) {
101
+ process.stderr.write(
102
+ `[ticket-progress] ${path} has malformed row(s); keeps reachable rows and retains the diagnostic: ${diagnostic}\n`,
103
+ );
104
+ }
105
+ return lines;
95
106
  }
96
107
 
97
108
  /**
@@ -155,24 +166,16 @@ function nextLegReceiptIndex(runDirectory: string): number {
155
166
 
156
167
  /**
157
168
  * Copy structured status/summary from the seat receipt.
158
- * Status leaves reuse acceptedFacts (terminating-tools authority) via the seat's
159
- * current output tool — legacy judgeStatus/countersignStatus keys are unreachable
160
- * at this seal seam (tool is the live registry name, not ak_judge_output).
161
- * summary is seat-authored prose on the receipt and is not part of AcceptedFacts.
169
+ * summary is seat-authored prose on the receipt.
162
170
  * Missing fields stay absent — never invent "" or "accepted".
163
- *
164
- * Not receiptStatusFromRegistry: that scans every registry key for navigator
165
- * projection when the seat is unknown; here the seal already knows the seat.
166
171
  */
167
- function statusAndSummaryFromPayload(seat: string, payload: unknown): {
172
+ function statusAndSummaryFromPayload(payload: unknown): {
168
173
  readonly status?: string;
169
174
  readonly summary?: string;
170
175
  } {
171
176
  if (!isRecord(payload)) return {};
172
- const toolName = packagedRoleOutputTool(seat);
173
- const status = toolName !== undefined && isTerminatingToolName(toolName)
174
- ? acceptedFacts(toolName, payload as AcceptedDetails).status
175
- : undefined;
177
+ const received = receiptStatus(payload);
178
+ const status = typeof received === "string" ? received : undefined;
176
179
  const summary = typeof payload.summary === "string" ? payload.summary : undefined;
177
180
  return {
178
181
  ...(status === undefined ? {} : { status }),
@@ -180,6 +183,44 @@ function statusAndSummaryFromPayload(seat: string, payload: unknown): {
180
183
  };
181
184
  }
182
185
 
186
+ /**
187
+ * #1200「审 谁#轮」as the ticket has it now: the audited leg's latest row. Read
188
+ * at the officer's admission, before the officer runs. An audited leg with no
189
+ * round yet (unbound, or no accepted receipt) has none. A progress file that
190
+ * cannot be read or has malformed rows has none either and returns the cause
191
+ * for the caller to retain — the officer still runs.
192
+ */
193
+ export function readAuditedRound(auditedRunDirectory: string): {
194
+ readonly for?: string;
195
+ readonly fault?: string;
196
+ } {
197
+ try {
198
+ const subjectDirectory = subjectDirectoryOfRun(auditedRunDirectory);
199
+ if (subjectDirectory === undefined) return {};
200
+ const path = join(subjectDirectory, CURRENT_FILENAME);
201
+ const { lines, malformed } = decodeProgressFile(path);
202
+ if (malformed.length > 0) {
203
+ throw new Error(`${path} has malformed row(s): ${malformed.join("; ")}`);
204
+ }
205
+ const receipts = `runs/${basename(auditedRunDirectory)}/`;
206
+ const latest = lines.filter((line) => line.receipt.startsWith(receipts)).at(-1);
207
+ return latest === undefined ? {} : { for: `${latest.seat}#${latest.round}` };
208
+ } catch (error) {
209
+ return { fault: `audited round unavailable for ${auditedRunDirectory}: ${errorText(error)}` };
210
+ }
211
+ }
212
+
213
+ /**
214
+ * The row's `for`: gate officers copy the admission pin; the fixer's receipt
215
+ * reports its own (copied when it is a string, never checked). No other seat has one.
216
+ */
217
+ function forOfSealedRow(runDirectory: string, seat: string, payload: unknown): string | undefined {
218
+ const reported = packagedGateStageLabel(seat) !== undefined
219
+ ? readPageSync(runDirectory, "admitted")?.for
220
+ : seat === "fixer" && isRecord(payload) ? payload.for : undefined;
221
+ return typeof reported === "string" ? reported : undefined;
222
+ }
223
+
183
224
  export type WorktreeHeadCapture = {
184
225
  readonly head: string;
185
226
  readonly fault?: string;
@@ -320,12 +361,14 @@ export function landTicketProgress(input: {
320
361
  const sessionRelative = input.sessionFile === undefined
321
362
  ? ""
322
363
  : relative(subjectDirectory, input.sessionFile).split(sep).join("/");
323
- const { status, summary } = statusAndSummaryFromPayload(input.role, input.accepted);
364
+ const { status, summary } = statusAndSummaryFromPayload(input.accepted);
365
+ const reviewed = forOfSealedRow(runDirectory, input.role, input.accepted);
324
366
  const instruction = input.instruction;
325
367
  const line: TicketProgressLine = {
326
368
  at: new Date().toISOString(),
327
369
  seat: input.role,
328
370
  round,
371
+ ...(reviewed === undefined ? {} : { for: reviewed }),
329
372
  instruction,
330
373
  head: input.sealHead.head,
331
374
  ...(status === undefined ? {} : { status }),
@@ -52,7 +52,7 @@ import {
52
52
  validateAcceptedDetails,
53
53
  type TerminatingToolName,
54
54
  } from "./package-contracts/terminating-tools.ts";
55
- import { LEGACY_REVIEW_OUTPUT_ROLES, PACKAGED_ROLE_REGISTRY } from "./packaged-role-registry.ts";
55
+ import { PACKAGED_ROLE_REGISTRY, receiptSeat } from "./packaged-role-registry.ts";
56
56
 
57
57
  import { isRecord, isMissingPathError } from "./unknown-value.ts";
58
58
 
@@ -134,18 +134,8 @@ async function realpathOrLexicalIfMissing(path: string): Promise<string> {
134
134
  }
135
135
  }
136
136
 
137
- const TOOL_TO_ROLE: ReadonlyMap<string, string> = new Map([
138
- ...PACKAGED_ROLE_REGISTRY.filter((entry) => entry.outputTool !== "ak_submission_output")
139
- .map((entry) => [entry.outputTool, entry.role] as const),
140
- ...LEGACY_REVIEW_OUTPUT_ROLES,
141
- ]);
142
-
143
137
  const NAME_PREFIX_ROLES: readonly string[] = PACKAGED_ROLE_REGISTRY.map((entry) => entry.role);
144
138
 
145
- function roleFromToolName(toolName: string): string | undefined {
146
- return TOOL_TO_ROLE.get(toolName);
147
- }
148
-
149
139
  function roleFromRunName(runId: string): string | undefined {
150
140
  const base = runId.split("@")[0] ?? runId;
151
141
  const lower = base.toLowerCase();
@@ -319,13 +309,10 @@ function resolveStation(input: {
319
309
  invocationRole?: string;
320
310
  runId: string;
321
311
  }): { station: string; stationSource: StationSource } {
322
- if (input.invocationRole && input.toolNames.includes("ak_submission_output")) {
323
- return { station: input.invocationRole, stationSource: "invocation" };
324
- }
325
- for (const toolName of input.toolNames) {
326
- const role = roleFromToolName(toolName);
327
- if (role) return { station: role, stationSource: "tool" };
328
- }
312
+ const seats = input.toolNames.flatMap((toolName) => receiptSeat(toolName, () => input.invocationRole) ?? []);
313
+ // A receipt on the shared tool name places the run before any seat-owned name does.
314
+ const placed = seats.find((seat) => seat.source === "invocation") ?? seats[0];
315
+ if (placed !== undefined) return { station: placed.seat, stationSource: placed.source };
329
316
  // Also accept tool names observed only via accepted results order
330
317
  if (input.invocationRole) {
331
318
  return { station: input.invocationRole, stationSource: "invocation" };
@@ -23,7 +23,7 @@ import {
23
23
  matchFixerBashForbiddenLiteral,
24
24
  } from "./fixer-bash-seatbelt.ts";
25
25
 
26
- import { isRecord } from "./unknown-value.ts";
26
+ import { receiptStatus } from "./packaged-role-registry.ts";
27
27
 
28
28
  export {
29
29
  CODER_OUTPUT_TOOL_NAME,
@@ -69,9 +69,8 @@ export type WorkerRoleRuntime = {
69
69
 
70
70
  /** Read only the field that selects the worker's next package-owned path. */
71
71
  function workerStatusOf(output: WorkerOutput): string | undefined {
72
- return isRecord(output) && typeof output.status === "string"
73
- ? output.status
74
- : undefined;
72
+ const status = receiptStatus(output);
73
+ return typeof status === "string" ? status : undefined;
75
74
  }
76
75
 
77
76
  function deepFreeze<T>(value: T): T {