@akagilnc/pi-workflow-roles 0.1.6111 → 0.1.6123

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 (47) hide show
  1. package/README.md +3 -3
  2. package/README.zh-CN.md +3 -3
  3. package/dist/acp-host/production-host.js +442 -279
  4. package/dist/engine-detour-usage.js +2 -1
  5. package/dist/gatekeeper-role.js +3 -15
  6. package/dist/headless-host/production-host.js +427 -264
  7. package/dist/migrate-book-topology.js +42 -22
  8. package/dist/notary-source-run.js +8 -8
  9. package/dist/package-contracts/fixer-output.js +3 -0
  10. package/dist/public-cli/auto-resume.js +3 -3
  11. package/dist/public-cli/cli.js +38 -32
  12. package/dist/public-cli/instruction-seat-run.js +52 -13
  13. package/dist/public-cli/invocation.js +22 -12
  14. package/dist/public-cli/main.js +398 -237
  15. package/dist/public-cli/option-definitions.js +22 -21
  16. package/dist/public-cli/run-lifecycle.js +27 -26
  17. package/dist/public-cli/seat-ticket-binding.js +2 -1
  18. package/dist/public-cli/settlement.js +33 -8
  19. package/dist/public-cli/terminal.js +13 -3
  20. package/dist/public-role-summons.js +1 -7
  21. package/dist/role-run-placement.js +1 -1
  22. package/dist/run-dossier-files.js +4 -2
  23. package/dist/submission-gate.js +3 -3
  24. package/dist/submission-ledger.js +29 -3
  25. package/dist/ticket-address.js +77 -0
  26. package/dist/ticket-progress.js +90 -14
  27. package/package.json +1 -1
  28. package/src/engine-detour-usage.ts +2 -1
  29. package/src/gatekeeper-role.ts +5 -18
  30. package/src/notary-source-run.ts +8 -8
  31. package/src/package-contracts/fixer-output.ts +4 -0
  32. package/src/public-cli/auto-resume.ts +4 -3
  33. package/src/public-cli/cli.ts +53 -32
  34. package/src/public-cli/instruction-seat-run.ts +55 -11
  35. package/src/public-cli/invocation.ts +31 -16
  36. package/src/public-cli/option-definitions.ts +22 -21
  37. package/src/public-cli/run-lifecycle.ts +31 -31
  38. package/src/public-cli/seat-ticket-binding.ts +2 -1
  39. package/src/public-cli/settlement.ts +43 -7
  40. package/src/public-cli/terminal.ts +33 -14
  41. package/src/public-role-summons.ts +3 -15
  42. package/src/role-run-placement.ts +1 -1
  43. package/src/run-dossier-files.ts +5 -2
  44. package/src/submission-gate.ts +3 -2
  45. package/src/submission-ledger.ts +32 -2
  46. package/src/ticket-address.ts +91 -0
  47. package/src/ticket-progress.ts +113 -15
@@ -343,7 +343,7 @@ const AUDITOR_OPTIONS = [
343
343
  owner: "auditor",
344
344
  canonical: "--source-run",
345
345
  aliases: [],
346
- valueMetavar: "runId@role|path",
346
+ valueMetavar: "ticket:seat#round|path",
347
347
  required: true,
348
348
  repeatable: false,
349
349
  form: "option",
@@ -522,13 +522,13 @@ const NOTARY_OPTIONS = [
522
522
  owner: "notary",
523
523
  canonical: "--source-run",
524
524
  aliases: [],
525
- valueMetavar: "runId@role|path",
525
+ valueMetavar: "ticket:seat#round|path",
526
526
  required: true,
527
527
  repeatable: false,
528
528
  form: "option",
529
529
  description: {
530
- en: "Required source run locator (runId@role under the book home, or path to that run directory). Binds the audited identity; review dialogue is the fixed Notary dispatch (verdict stays in the ledger). Missing-ticket and unreadable-status reasks keep their existing diagnostic text.",
531
- zh: "必填源 run 定位符(簿内 runId@role,或该 run 目录路径)。绑定受审身份;审稿对话为符宝郎固定派单文(判词留在卷宗自行读取)。缺票号与读不出 status 的重交仍递既有诊断原文。",
530
+ en: "Required source run locator (<ticket>:<seat>#<round> as written on the ticket's progress row, or path to that run directory). Binds the audited identity; review dialogue is the fixed Notary dispatch (verdict stays in the ledger). Missing-ticket and unreadable-status reasks keep their existing diagnostic text.",
531
+ zh: "必填源 run 定位符(<票号>:<席>#<轮>,轮照进度行上的写法;或该 run 目录路径)。绑定受审身份;审稿对话为符宝郎固定派单文(判词留在卷宗自行读取)。缺票号与读不出 status 的重交仍递既有诊断原文。",
532
532
  },
533
533
  },
534
534
  ];
@@ -540,13 +540,13 @@ const INSPECTOR_OPTIONS = [
540
540
  owner: "inspector",
541
541
  canonical: "--source-run",
542
542
  aliases: [],
543
- valueMetavar: "runId@role|path",
543
+ valueMetavar: "ticket:seat#round|path",
544
544
  required: false,
545
545
  repeatable: false,
546
546
  form: "option",
547
547
  description: {
548
- en: "Optional audited source-run locator (runId@role or path). Gate summons always supply it; identity rides startup materials.",
549
- zh: "可选被审腿定位符(runId@role 或路径)。闸传召必带;身份在启动材料里。",
548
+ en: "Optional audited source-run locator (<ticket>:<seat>#<round> or path). Gate summons always supply it; identity rides startup materials.",
549
+ zh: "可选被审腿定位符(<票号>:<席>#<轮> 或路径)。闸传召必带;身份在启动材料里。",
550
550
  },
551
551
  },
552
552
  ];
@@ -1027,10 +1027,10 @@ const ROLE_COMMAND_HELP = {
1027
1027
  auditor: {
1028
1028
  command: "auditor",
1029
1029
  summary: "Direct Auditor (审刑院) compliance audit: converged, continue, or escalate.",
1030
- usage: ["ak-role auditor --subject <judge|doctor> --source-run <runId@role|path> [options] [instruction]"],
1030
+ usage: ["ak-role auditor --subject <judge|doctor> --source-run <ticket:seat#round|path> [options] [instruction]"],
1031
1031
  examples: [
1032
- 'ak-role auditor --subject judge --source-run 01abc…@judge --attach ./dossier "审:本 run 是否合规。"',
1033
- 'ak-role auditor --subject doctor --source-run 01abc…@doctor "审:太医候选是否合规。"',
1032
+ 'ak-role auditor --subject judge --source-run 1201:judge#2 --attach ./dossier "审:本 run 是否合规。"',
1033
+ 'ak-role auditor --subject doctor --source-run 1201:doctor#1 "审:太医候选是否合规。"',
1034
1034
  ],
1035
1035
  },
1036
1036
  diarist: {
@@ -1053,10 +1053,10 @@ const ROLE_COMMAND_HELP = {
1053
1053
  notary: {
1054
1054
  command: "notary",
1055
1055
  summary: "Direct Notary summons; duties: souls/notary.md. Review uses fixed dispatch — binds --source-run identity; does not accept caller review prompt; verdict stays in the ledger. Missing-ticket (#1171) and unreadable-status reasks deliver their existing diagnostic text on the same seat, not the review sentence.",
1056
- usage: ["ak-role notary --source-run <runId@role|path> [options]"],
1056
+ usage: ["ak-role notary --source-run <ticket:seat#round|path> [options]"],
1057
1057
  examples: [
1058
- "ak-role notary --source-run 01a034f1-75bf-71a6-bcf5-d1299145b1a5@judge",
1059
- "ak-role notary --source-run 01a034f1-75bf-71a6-bcf5-d1299145b1a5@countersign",
1058
+ "ak-role notary --source-run 1201:judge#2",
1059
+ "ak-role notary --source-run 1201:countersign#1",
1060
1060
  ],
1061
1061
  },
1062
1062
  analyst: {
@@ -1113,14 +1113,15 @@ const SUPPORT_COMMAND_HELP = {
1113
1113
  },
1114
1114
  resume: {
1115
1115
  command: "resume",
1116
- summary: "Resume a role run under the live seat table (model/host/engine); session principal must still exist. Every callable seat accepts the optional caller message and passes it through unchanged as the continuation prompt. Notary new/direct review calls use only --source-run plus the fixed review dispatch (no caller review prompt); public manual resume still passes the caller message. Global --model/--thinking/--host/--engine must be placed before <runId> (either before `resume` or between `resume` and <runId>); the one argv after <runId> is the opaque message, not a flag position (#471).",
1117
- usage: ["ak-role resume <runId> [message]"],
1116
+ summary: "Resume one leg of a ticket under the live seat table (model/host/engine); session principal must still exist. The address is the ticket number and the seat: by default the seat's most recently active leg under that ticket; <seat>#<round> (round as written on the ticket's progress row, reviewer rounds carry the lens suffix) names the leg that filed that round. A leg that has reported no ticket is not in this address. Every callable seat accepts the optional caller message and passes it through unchanged as the continuation prompt. Notary new/direct review calls use only --source-run plus the fixed review dispatch (no caller review prompt); public manual resume still passes the caller message. Global --model/--thinking/--host/--engine must be placed before <ticket> (either before `resume` or between `resume` and <ticket>); the one argv after <seat> is the opaque message, not a flag position (#471).",
1117
+ usage: ["ak-role resume <ticket> <seat>[#<round>] [message]"],
1118
1118
  examples: [
1119
- "ak-role resume 01abc…",
1120
- "ak-role resume 01abc… \"owner ruling\"",
1121
- "ak-role --host grok-build resume 01abc…",
1122
- "ak-role --engine agy resume 01abc…",
1123
- "ak-role resume --model xai/grok-4.5 01abc… \"owner ruling\"",
1119
+ "ak-role resume 1201 judge",
1120
+ "ak-role resume 1201 judge \"owner ruling\"",
1121
+ "ak-role resume 1201 'reviewer#2.correctness'",
1122
+ "ak-role --host grok-build resume 1201 fixer",
1123
+ "ak-role --engine agy resume 1201 fixer",
1124
+ "ak-role resume --model xai/grok-4.5 1201 notary \"owner ruling\"",
1124
1125
  ],
1125
1126
  },
1126
1127
  new: {
@@ -1129,7 +1130,7 @@ const SUPPORT_COMMAND_HELP = {
1129
1130
  usage: ["ak-role new <role> [options] …"],
1130
1131
  examples: [
1131
1132
  'ak-role new countersign --attach ./ticket.md "裁:本票 #708 是否足以开工。"',
1132
- "ak-role new notary --source-run 01abc…@countersign",
1133
+ "ak-role new notary --source-run 1201:countersign#1",
1133
1134
  "ak-role --host grok-build new inspector --attach ./change.patch",
1134
1135
  ],
1135
1136
  },
@@ -605,7 +605,7 @@ export async function findRunDirectoryById(home, runId, onlyBookKey, onlyRole, k
605
605
  if (typeof knownRunDirectory === "string" && knownRunDirectory.trim() !== "") {
606
606
  const parsed = parseRunLeaf(basename(knownRunDirectory));
607
607
  if (parsed === undefined || parsed.runId !== runId) {
608
- throw new CliUsageError(`run directory does not match run id ${runId}: ${knownRunDirectory}`);
608
+ throw new CliUsageError(`run directory is not the expected role run: ${knownRunDirectory}`);
609
609
  }
610
610
  return knownRunDirectory;
611
611
  }
@@ -678,7 +678,7 @@ async function runHasFormedSessionPrincipal(runDirectory) {
678
678
  * parent run path (officer / gate seats, #747 / #987), narrowed to a supplied
679
679
  * typed ticket for same-ticket gate re-summons. runId is UUIDv7 — lexicographic
680
680
  * max is latest among runs that formed a session principal. No parallel index;
681
- * callers can use explicit `ak-role resume <runId>`.
681
+ * callers address a leg explicitly with `ak-role resume <ticket> <seat>`.
682
682
  * Only a truly missing book directory means no history; damage/permission errors propagate.
683
683
  */
684
684
  export async function findLatestRunIdForSeatTicket(input) {
@@ -744,19 +744,20 @@ function restoredTicketFields(fields) {
744
744
  }
745
745
  async function loadResumableRunRecord(home, runId, authority, knownRunDirectory) {
746
746
  const runDirectory = await findRunDirectoryById(home, runId, undefined, undefined, knownRunDirectory);
747
+ // Diagnostics name the leg by its directory; the run id is not a caller-facing identity (#1201).
747
748
  if (runDirectory === undefined) {
748
- throw new CliUsageError(`unknown role run id: ${runId}`);
749
+ throw new CliUsageError(`unknown role run: no run directory found under ${home}`);
749
750
  }
750
751
  const disk = await readRoleRunStateDisk(runDirectory);
751
752
  if (disk === undefined) {
752
- throw new CliUsageError(`unknown role run id: ${runId}`);
753
+ throw new CliUsageError(`role run has no readable state: ${runDirectory}`);
753
754
  }
754
755
  // #416 / #1091: removed terminal/resumable and local session-file gates.
755
756
  // The load seam locates the run and recovers identity; host CLI answers continuation.
756
757
  // One authority.decode of the uninterpreted wire yields both principal and record.
757
758
  const materialized = materializeRoleRunFromDisk(disk, authority);
758
759
  if (materialized === undefined) {
759
- throw new CliUsageError(`unknown role run id: ${runId}`);
760
+ throw new CliUsageError(`role run has no readable state: ${runDirectory}`);
760
761
  }
761
762
  const { run, principal } = materialized;
762
763
  // Reconstruct admitted identity from durable run record + the admitted section.
@@ -906,7 +907,7 @@ async function loadResumableRunRecord(home, runId, authority, knownRunDirectory)
906
907
  // Preserve unique --authority-ref grammar failures; do not collapse to unreadable.
907
908
  if (error instanceof CliUsageError)
908
909
  throw error;
909
- throw new CliUsageError(`role run admitted request is unreadable: ${runId}`, { cause: error });
910
+ throw new CliUsageError(`role run admitted request is unreadable: ${run.runDirectory}`, { cause: error });
910
911
  }
911
912
  let model;
912
913
  try {
@@ -935,7 +936,7 @@ async function loadResumableRunRecord(home, runId, authority, knownRunDirectory)
935
936
  throw error;
936
937
  }
937
938
  if (!isEnoent(error)) {
938
- throw new CliUsageError(`role run invocation identity is unreadable: ${runId}`, { cause: error });
939
+ throw new CliUsageError(`role run invocation identity is unreadable: ${run.runDirectory}`, { cause: error });
939
940
  }
940
941
  }
941
942
  const recordedSourceDirectory = sourceRunPath ?? sourceRun?.runDirectory;
@@ -1025,7 +1026,7 @@ export async function loadResumablePublicRole(home, runId, authority, options) {
1025
1026
  */
1026
1027
  function admitResumedRole(loaded) {
1027
1028
  const role = loaded.run.role;
1028
- const runId = loaded.run.runId;
1029
+ const leg = loaded.run.runDirectory;
1029
1030
  const record = packagedRoleMetadata(role);
1030
1031
  if (record === undefined) {
1031
1032
  throw new CliUsageError(`unknown role: ${role}`);
@@ -1062,9 +1063,9 @@ function admitResumedRole(loaded) {
1062
1063
  return admitted;
1063
1064
  }
1064
1065
  case "worker-task": {
1065
- const phase = resumedWorkerPhase(fields.phase ?? loaded.run.phase, record.phases, role, runId);
1066
+ const phase = resumedWorkerPhase(fields.phase ?? loaded.run.phase, record.phases, role, leg);
1066
1067
  if (fields.instruction.trim() === "") {
1067
- throw new CliUsageError(`role run admitted coder task is blank: ${runId}`);
1068
+ throw new CliUsageError(`role run admitted coder task is blank: ${leg}`);
1068
1069
  }
1069
1070
  const admitted = {
1070
1071
  role: "coder",
@@ -1075,9 +1076,9 @@ function admitResumedRole(loaded) {
1075
1076
  return admitted;
1076
1077
  }
1077
1078
  case "worker-packet": {
1078
- const phase = resumedWorkerPhase(fields.phase ?? loaded.run.phase, record.phases, role, runId);
1079
+ const phase = resumedWorkerPhase(fields.phase ?? loaded.run.phase, record.phases, role, leg);
1079
1080
  if (fields.instruction.trim() === "") {
1080
- throw new CliUsageError(`role run admitted fixer instruction is blank: ${runId}`);
1081
+ throw new CliUsageError(`role run admitted fixer instruction is blank: ${leg}`);
1081
1082
  }
1082
1083
  const admitted = {
1083
1084
  role: "fixer",
@@ -1095,16 +1096,16 @@ function admitResumedRole(loaded) {
1095
1096
  const baseFault = admittedReviewerBaseFault(rawBase);
1096
1097
  if (baseFault !== undefined || rawBase === undefined) {
1097
1098
  throw new CliUsageError(baseFault === "damaged"
1098
- ? `role run admitted reviewer base revision is damaged: ${runId}`
1099
- : `role run admitted reviewer base revision is missing: ${runId}`);
1099
+ ? `role run admitted reviewer base revision is damaged: ${leg}`
1100
+ : `role run admitted reviewer base revision is missing: ${leg}`);
1100
1101
  }
1101
1102
  const lens = fields.lens;
1102
1103
  if (!isReviewerLens(lens)) {
1103
- throw new CliUsageError(`role run admitted reviewer lens is missing: ${runId}`);
1104
+ throw new CliUsageError(`role run admitted reviewer lens is missing: ${leg}`);
1104
1105
  }
1105
1106
  const authorityRefs = Object.freeze([...(fields.authorityRefs ?? [])]);
1106
1107
  if (authorityRefs.length === 0) {
1107
- throw new CliUsageError(`role run admitted reviewer authority refs are missing: ${runId}`);
1108
+ throw new CliUsageError(`role run admitted reviewer authority refs are missing: ${leg}`);
1108
1109
  }
1109
1110
  const admitted = {
1110
1111
  role: "reviewer",
@@ -1118,7 +1119,7 @@ function admitResumedRole(loaded) {
1118
1119
  case "gleaner": {
1119
1120
  const baseRevision = fields.baseRevision;
1120
1121
  if (baseRevision === undefined || baseRevision.trim() === "") {
1121
- throw new CliUsageError(`role run admitted gleaner-left base revision is missing: ${runId}`);
1122
+ throw new CliUsageError(`role run admitted gleaner-left base revision is missing: ${leg}`);
1122
1123
  }
1123
1124
  const admitted = {
1124
1125
  role: "gleaner-left",
@@ -1130,14 +1131,14 @@ function admitResumedRole(loaded) {
1130
1131
  case "merge-envelope": {
1131
1132
  const mergerInputPath = fields.mergerInputPath;
1132
1133
  if (mergerInputPath === undefined) {
1133
- throw new CliUsageError(`role run admitted merger input path is missing: ${runId}`);
1134
+ throw new CliUsageError(`role run admitted merger input path is missing: ${leg}`);
1134
1135
  }
1135
1136
  const derived = fields.derived;
1136
1137
  if (derived === undefined) {
1137
- throw new CliUsageError(`role run admitted merger envelope is missing: ${runId}`);
1138
+ throw new CliUsageError(`role run admitted merger envelope is missing: ${leg}`);
1138
1139
  }
1139
1140
  if (fields.instruction.trim() === "") {
1140
- throw new CliUsageError(`role run admitted merger task is blank: ${runId}`);
1141
+ throw new CliUsageError(`role run admitted merger task is blank: ${leg}`);
1141
1142
  }
1142
1143
  const admitted = {
1143
1144
  role: "merger",
@@ -1151,7 +1152,7 @@ function admitResumedRole(loaded) {
1151
1152
  case "collect-target": {
1152
1153
  const { prNumber, repository, repositoryDisplay } = fields;
1153
1154
  if (repository === undefined || repositoryDisplay === undefined) {
1154
- throw new CliUsageError(`role run admitted collector repository identity is missing: ${runId}`);
1155
+ throw new CliUsageError(`role run admitted collector repository identity is missing: ${leg}`);
1155
1156
  }
1156
1157
  let parsedRepository;
1157
1158
  try {
@@ -1162,7 +1163,7 @@ function admitResumedRole(loaded) {
1162
1163
  throw new CliUsageError(detail, { cause: error });
1163
1164
  }
1164
1165
  if (parsedRepository.canonical !== repository) {
1165
- throw new CliUsageError(`role run admitted collector repository does not match its canonical form: ${runId}`);
1166
+ throw new CliUsageError(`role run admitted collector repository does not match its canonical form: ${leg}`);
1166
1167
  }
1167
1168
  const admitted = {
1168
1169
  role: "collector",
@@ -1181,7 +1182,7 @@ function admitResumedRole(loaded) {
1181
1182
  if (issueNumber === undefined ||
1182
1183
  caseRunsPath === undefined ||
1183
1184
  caseIdentity === undefined) {
1184
- throw new CliUsageError(`role run admitted doctor case identity is missing: ${runId}`);
1185
+ throw new CliUsageError(`role run admitted doctor case identity is missing: ${leg}`);
1185
1186
  }
1186
1187
  const admitted = {
1187
1188
  role: "doctor",
@@ -1195,7 +1196,7 @@ function admitResumedRole(loaded) {
1195
1196
  case "source-locator": {
1196
1197
  const { sourceRunPath, sourceRun } = fields;
1197
1198
  if (sourceRunPath === undefined || sourceRun === undefined) {
1198
- throw new CliUsageError(`role run admitted notary source-run locator is missing: ${runId}`);
1199
+ throw new CliUsageError(`role run admitted notary source-run locator is missing: ${leg}`);
1199
1200
  }
1200
1201
  const admitted = {
1201
1202
  role: "notary",
@@ -1208,11 +1209,11 @@ function admitResumedRole(loaded) {
1208
1209
  }
1209
1210
  }
1210
1211
  /** Worker phase on resume: value must belong to the registry phase set. */
1211
- function resumedWorkerPhase(phase, phases, role, runId) {
1212
+ function resumedWorkerPhase(phase, phases, role, leg) {
1212
1213
  if (phase === "plan" || phase === "apply") {
1213
1214
  if (phases.some((item) => item === phase)) {
1214
1215
  return phase;
1215
1216
  }
1216
1217
  }
1217
- throw new CliUsageError(`role run admitted ${role} phase is missing: ${runId}`);
1218
+ throw new CliUsageError(`role run admitted ${role} phase is missing: ${leg}`);
1218
1219
  }
@@ -12,7 +12,8 @@ function resumedSessionIdMissing(result, runId) {
12
12
  const terminal = result.terminal;
13
13
  if (typeof terminal !== "object" || terminal === null)
14
14
  return false;
15
- if (terminal.runId !== runId)
15
+ // The failure belongs to the resumed leg, not to another seat presented in its place.
16
+ if (result.admitted?.runId !== runId)
16
17
  return false;
17
18
  const outcome = terminal.roleOutcome;
18
19
  if (typeof outcome !== "object" || outcome === null)
@@ -4,9 +4,10 @@
4
4
  * Controlled failures and audit human decisions settle here without washing causes.
5
5
  */
6
6
  import { randomUUID } from "node:crypto";
7
- import { dirname, join } from "node:path";
7
+ import { basename, join } from "node:path";
8
8
  import { lstat, mkdir, readFile, rm, writeFile } from "node:fs/promises";
9
- import { sessionFileOf } from "../role-run-placement.js";
9
+ import { sessionFileOf, subjectDirectoryOfRun } from "../role-run-placement.js";
10
+ import { parseTicketNumber } from "../run-ticket-number.js";
10
11
  import { sitianReport } from "../sitian-facade.js";
11
12
  import { ATTEMPT_HISTORY_IDENTITY_FIELD, TERMINAL_COURT_ATTEMPT_FIELD, writeRunTerminal, } from "../run-terminal-artifacts.js";
12
13
  import { readAttemptScopedSubmissionRows, readRecordedSubmissionRows, readRecordedSubmissions, } from "../submission-ledger.js";
@@ -103,6 +104,24 @@ export function ledgerReadScope(admitted, scope) {
103
104
  : { attemptId: scope.courtAttemptId }),
104
105
  };
105
106
  }
107
+ /**
108
+ * #1201 public identity of a leg's terminal: the ticket it is filed under and
109
+ * the receipts this settle accepted. Row references resolve under the leg's
110
+ * subject directory as it stands now; a leg that has reported no ticket names
111
+ * no ticket and no round.
112
+ */
113
+ export function filedIdentity(runDirectory, filed = []) {
114
+ const subjectDirectory = subjectDirectoryOfRun(runDirectory);
115
+ if (subjectDirectory === undefined)
116
+ return {};
117
+ const ticket = parseTicketNumber(basename(subjectDirectory));
118
+ return {
119
+ ...(ticket === undefined ? {} : { ticket }),
120
+ ...(filed.length === 0 ? {} : {
121
+ receipts: filed.map((row) => ({ ...row, receipt: join(subjectDirectory, row.receipt) })),
122
+ }),
123
+ };
124
+ }
106
125
  function roleOutcomeFromRows(role, rows) {
107
126
  const mine = rows.filter((row) => row.role === role);
108
127
  // Terminal acceptance kind still only follows sealed / audit-escalation (#881):
@@ -118,7 +137,13 @@ function roleOutcomeFromRows(role, rows) {
118
137
  const submissionToolCallId = typeof latest.toolCallId === "string" && latest.toolCallId.length > 0
119
138
  ? latest.toolCallId
120
139
  : undefined;
121
- const belonging = submissionToolCallId === undefined ? {} : { submissionToolCallId };
140
+ const filed = mine.flatMap((row) => row.receipt === undefined
141
+ ? []
142
+ : [{ receipt: row.receipt, ...(row.round === undefined ? {} : { round: row.round }) }]);
143
+ const belonging = {
144
+ ...(submissionToolCallId === undefined ? {} : { submissionToolCallId }),
145
+ filed,
146
+ };
122
147
  if (latest.kind === "audit-escalation") {
123
148
  return {
124
149
  outcome: {
@@ -296,7 +321,7 @@ async function settleNoReceiptTerminal(admitted, authority, scope, facts) {
296
321
  ? NAVIGATOR_SEAT_OWN_FACT
297
322
  : await extractNavigatorFactFromAdmittedSession(coordinates.sessionFile, admitted.runDirectory, scope),
298
323
  artifacts: [],
299
- runId: admitted.runId,
324
+ ...filedIdentity(admitted.runDirectory),
300
325
  }, coordinates.sessionDirectory, detourUsageContext(admitted, scope));
301
326
  }
302
327
  /** Transitional host-session reads remain only for non-sealed failure and audit evidence. */
@@ -955,9 +980,9 @@ async function settleSealedSeat(admitted, authority, scope, options) {
955
980
  if (read.kind === "fault") {
956
981
  await noteSettlementFault(admitted.runDirectory, scope, `session read failed beside lawful terminal: ${describeErrorIdentity(read.error)}`);
957
982
  }
958
- return finishLawfulSeat(admitted, coordinates, entriesOf(read), settled.outcome, scope, settled.submissionToolCallId);
983
+ return finishLawfulSeat(admitted, coordinates, entriesOf(read), settled.outcome, scope, settled.submissionToolCallId, settled.filed);
959
984
  }
960
- async function finishLawfulSeat(admitted, coordinates, entries, roleOutcome, scope, submissionToolCallId) {
985
+ async function finishLawfulSeat(admitted, coordinates, entries, roleOutcome, scope, submissionToolCallId, filed) {
961
986
  const artifacts = scope?.previewOnly === true
962
987
  ? []
963
988
  : await publishDeclaredSeatTerminal(admitted, roleOutcome, coordinates, entries, scope);
@@ -965,7 +990,7 @@ async function finishLawfulSeat(admitted, coordinates, entries, roleOutcome, sco
965
990
  roleOutcome,
966
991
  navigator: isNavigatorSeat(admitted.role) ? NAVIGATOR_SEAT_OWN_FACT : extractNavigatorFact(entries),
967
992
  artifacts,
968
- runId: admitted.runId,
993
+ ...filedIdentity(admitted.runDirectory, filed),
969
994
  ...(submissionToolCallId === undefined || submissionToolCallId.length === 0
970
995
  ? {}
971
996
  : { submissionToolCallId }),
@@ -1155,7 +1180,7 @@ export async function settleFailureTerminalResult(admitted, failure, authority,
1155
1180
  diagnostic: failure.diagnostic,
1156
1181
  decisiveFacts,
1157
1182
  };
1158
- return attachEngineDetourToolUsage({ roleOutcome, navigator, artifacts, runId: admitted.runId }, sessionDirectory, detourUsageContext(admitted, options));
1183
+ return attachEngineDetourToolUsage({ roleOutcome, navigator, artifacts, ...filedIdentity(admitted.runDirectory) }, sessionDirectory, detourUsageContext(admitted, options));
1159
1184
  }
1160
1185
  /**
1161
1186
  * Emit one complete failure Terminal on stdout and one concise stderr diagnostic.
@@ -28,6 +28,14 @@ export function currentReplyRows(terminal) {
28
28
  export function adviceNavigatorFact(input) {
29
29
  return { disposition: "advice", prose: input.prose };
30
30
  }
31
+ /** One leg's public identity rows (#1201): its ticket, then its receipts newest first. */
32
+ function identityRows(leg) {
33
+ const seat = leg.roleOutcome.role;
34
+ return [
35
+ ...(leg.ticket === undefined ? [] : [`ticket\t${leg.ticket}`]),
36
+ ...[...(leg.receipts ?? [])].reverse().map((filed) => `receipt\t${encodeTerminalField(filed.round === undefined ? seat : `${seat}#${filed.round}`)}\t${encodeTerminalField(filed.receipt)}`),
37
+ ];
38
+ }
31
39
  /**
32
40
  * Present one Terminal result for humans. Labels, row order, wording, and layout
33
41
  * are unfrozen (ADR 0052). Machine consumers and tests must read typed
@@ -85,11 +93,13 @@ export function formatTerminalResult(result) {
85
93
  if (child.stderr !== undefined && child.stderr !== "") {
86
94
  lines.push(`reviewer-child-diagnostic\t${axis}\t${encodeTerminalField(child.stderr)}`);
87
95
  }
96
+ // Each lens reports under its own ticket: the two may have reported different ones.
97
+ const lens = result.reviewerChildren?.[axis];
98
+ if (lens !== undefined)
99
+ lines.push(...identityRows(lens));
88
100
  }
89
101
  }
90
- if (result.runId !== undefined) {
91
- lines.push(`run\t${encodeTerminalField(result.runId)}`);
92
- }
102
+ lines.push(...identityRows(result));
93
103
  if (result.autoResumeCount !== undefined) {
94
104
  lines.push(`autoResumeCount\t${encodeTerminalField(String(result.autoResumeCount))}`);
95
105
  }
@@ -264,13 +264,7 @@ async function summonPublicRole(options) {
264
264
  result = stepped.ok;
265
265
  }
266
266
  const stderr = captured?.stderrText();
267
- let runDirectory = result.admitted?.runDirectory;
268
- if (result.terminal !== void 0 && result.terminal.roleOutcome.role !== options.role && typeof result.terminal.runId === "string" && result.admitted?.runId !== result.terminal.runId) {
269
- runDirectory = await (await import("./public-cli/run-lifecycle.js")).findRunDirectoryById(
270
- home,
271
- result.terminal.runId
272
- ) ?? runDirectory;
273
- }
267
+ const runDirectory = result.admitted?.runDirectory;
274
268
  return {
275
269
  exitCode: result.exitCode,
276
270
  ...result.terminal === void 0 ? {} : { terminal: result.terminal },
@@ -90,7 +90,7 @@ async function findRoleRunDirectory(bookDirectories, runId, onlyRole) {
90
90
  }
91
91
  if (matches.length === 0) return void 0;
92
92
  if (matches.length === 1) return matches[0];
93
- throw new Error(`ambiguous role run id ${runId}: ${matches.join(", ")}`);
93
+ throw new Error(`ambiguous role run: ${matches.join(", ")}`);
94
94
  }
95
95
  function roleRunPlacement(ledgerHome, input) {
96
96
  const subjectDirectory = "ticketNumber" in input.subject ? String(requireSafePositiveTicketNumber(
@@ -9,12 +9,14 @@ export const RUN_STATE_FILE = "state.jsonl";
9
9
  /**
10
10
  * Record kinds that make a leg's history: they land in `history.jsonl`. The
11
11
  * original submission ledger and attempt history, the prompt/schema each turn was
12
- * started with, and officer pointers.
12
+ * started with, officer pointers, and the ticket progress rows a leg wrote.
13
13
  */
14
14
  export const RUN_HISTORY_KINDS = new Set([
15
15
  "candidate", "roundContext", "outcome", "sealed", "post-seal-anomaly",
16
- "attempt-history", "turn-delivery", "officer-pointer",
16
+ "attempt-history", "turn-delivery", "officer-pointer", "progress",
17
17
  ]);
18
+ /** History record kind of a ticket progress row carried to settlement (#1201). */
19
+ export const PROGRESS_RECORD_KIND = "progress";
18
20
  /** History record kind of a booked officer pointer (appender routes it to history.jsonl). */
19
21
  export const OFFICER_POINTER_RECORD_KIND = "officer-pointer";
20
22
  /**
@@ -1,6 +1,6 @@
1
1
  import { persistAdmittedAuditedSubmissionToolCallId } from "./public-cli/invocation.js";
2
2
  import { readRunParentPath, readRoleRunIdentity } from "./public-cli/run-lifecycle.js";
3
- import { officerConclusionReask, projectGatekeeperRun, } from "./gatekeeper-role.js";
3
+ import { officerConclusionReask, officerRunIdFromSummoned, projectGatekeeperRun, } from "./gatekeeper-role.js";
4
4
  import { receiptStatus } from "./packaged-role-registry.js";
5
5
  import { deliveryLimitFromConfig } from "./receipt-delivery-policy.js";
6
6
  /**
@@ -174,7 +174,7 @@ export async function requireSubmissionGate(options) {
174
174
  officer: projected.officer,
175
175
  receipt: gatekeeper.submission ?? { reason: gatekeeper.reason },
176
176
  reason: gatekeeper.reason,
177
- runId: projected.summoned?.terminal?.runId,
177
+ runId: projected.summoned === undefined ? undefined : officerRunIdFromSummoned(projected.summoned),
178
178
  runDirectory: projected.summoned?.runDirectory,
179
179
  terminal: projected.summoned?.terminal,
180
180
  });
@@ -197,7 +197,7 @@ export async function requireSubmissionGate(options) {
197
197
  officer: projected.officer,
198
198
  receipt: gatekeeper.facts ?? { reason: gatekeeper.reason },
199
199
  reason: gatekeeper.reason,
200
- runId: projected.summoned?.terminal?.runId,
200
+ runId: projected.summoned === undefined ? undefined : officerRunIdFromSummoned(projected.summoned),
201
201
  runDirectory: projected.summoned?.runDirectory,
202
202
  terminal: projected.summoned?.terminal,
203
203
  });
@@ -4,6 +4,7 @@ import { resolveActivationLedgerHome, tryHomeFromAkRolesPath, } from "./activati
4
4
  import { courtAttemptIdFromHostContext, runDirectoryFromHostContext, } from "./host-contracts.js";
5
5
  import { runIdFromRunDirectory } from "./run-terminal-artifacts.js";
6
6
  import { readSitianRecords, resolveSitianRecordPathInLedger, sitianReport } from "./sitian-facade.js";
7
+ import { PROGRESS_RECORD_KIND } from "./run-dossier-files.js";
7
8
  import { findRunDirectoryById } from "./public-cli/run-lifecycle.js";
8
9
  import { isCorrectableExecuteError } from "./submission-correctable-error.js";
9
10
  import { reportTicketFromHostContext } from "./report-ticket-tool.js";
@@ -149,8 +150,25 @@ function rowFromPayload(kind, payload, accepted, roleFallback) {
149
150
  * recorded attemptId + toolCallId so distinct court attempts stay distinct (#881).
150
151
  * `accepted` is the original payload; never rebuilt from a status/facts envelope.
151
152
  */
152
- function mapOwnedToSubmissionRows(owned) {
153
+ function mapOwnedToSubmissionRows(owned,
154
+ /** Whole-leg records: a round filled at bind carries no court attempt (#1201). */
155
+ leg = owned) {
153
156
  const scoped = owned;
157
+ const receiptByCall = new Map();
158
+ const roundByReceipt = new Map();
159
+ for (const record of leg) {
160
+ if (record.kind !== PROGRESS_RECORD_KIND)
161
+ continue;
162
+ const payload = record.payload;
163
+ if (typeof payload?.receipt !== "string")
164
+ continue;
165
+ if (typeof payload.toolCallId === "string") {
166
+ receiptByCall.set(submissionCallKey(recordAttemptId(record), payload.toolCallId), payload.receipt);
167
+ }
168
+ if (typeof payload.round === "string" && payload.round !== "") {
169
+ roundByReceipt.set(payload.receipt, payload.round);
170
+ }
171
+ }
154
172
  const out = [];
155
173
  const indexByCall = new Map();
156
174
  // Recover seat identity for historical non-sealed rows that omitted role (#881).
@@ -212,7 +230,13 @@ function mapOwnedToSubmissionRows(owned) {
212
230
  ? submissionCallKey(recordAttemptId(record), payload.toolCallId)
213
231
  : undefined;
214
232
  const fallback = callKey === undefined ? undefined : roleByCall.get(callKey);
215
- take(rowFromPayload(kind, payload, original, fallback), callKey);
233
+ const receipt = kind === "accepted" && callKey !== undefined ? receiptByCall.get(callKey) : undefined;
234
+ const round = receipt === undefined ? undefined : roundByReceipt.get(receipt);
235
+ take({
236
+ ...rowFromPayload(kind, payload, original, fallback),
237
+ ...(receipt === undefined ? {} : { receipt }),
238
+ ...(round === undefined ? {} : { round }),
239
+ }, callKey);
216
240
  }
217
241
  return out;
218
242
  }
@@ -237,7 +261,7 @@ export async function readAttemptScopedSubmissionRows(cwd, runId, attemptId, hom
237
261
  return [];
238
262
  const scope = resolveReadScope(homeOrScope);
239
263
  const { owned } = await readOwnedSubmissionRecords(cwd, runId, scope);
240
- return mapOwnedToSubmissionRows(owned.filter((record) => recordAttemptId(record) === attemptId));
264
+ return mapOwnedToSubmissionRows(owned.filter((record) => recordAttemptId(record) === attemptId), owned);
241
265
  }
242
266
  /** #1214 R2c: the court-turn attempt that recorded this tool call's submission, if any. */
243
267
  export async function readSubmissionAttemptId(cwd, runId, toolCallId, homeOrScope) {
@@ -330,6 +354,7 @@ export function sealAcceptedSubmission(options) {
330
354
  sealHead,
331
355
  sessionFile: undefined,
332
356
  instruction: options.instruction ?? "",
357
+ call: { attemptId, toolCallId: options.toolCallId },
333
358
  });
334
359
  }
335
360
  /**
@@ -483,6 +508,7 @@ outputTools, failInfrastructure = (error) => { throw error; }, projectClosure =
483
508
  ...(rawLens === "completeness" || rawLens === "correctness"
484
509
  ? { lens: rawLens }
485
510
  : {}),
511
+ call: { attemptId, toolCallId },
486
512
  });
487
513
  // Native structured-output hosts have no tool-result reply to the model.
488
514
  // Keep the conversation open only after the receipt is durably sealed.