@akagilnc/pi-workflow-roles 0.1.1893 → 0.1.1918

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.
@@ -14873,6 +14873,69 @@ var init_sitian_role_run_coordinates = __esm({
14873
14873
  }
14874
14874
  });
14875
14875
 
14876
+ // src/ticket-frontmatter.ts
14877
+ function parseTicketNumberFrontmatter(bytes) {
14878
+ let text;
14879
+ if (typeof bytes === "string") {
14880
+ text = bytes;
14881
+ } else {
14882
+ try {
14883
+ text = exactUtf8(bytes, "ticket face");
14884
+ } catch {
14885
+ return void 0;
14886
+ }
14887
+ }
14888
+ let cursor;
14889
+ if (text.startsWith("---\n")) {
14890
+ cursor = 4;
14891
+ } else if (text.startsWith("---\r\n")) {
14892
+ cursor = 5;
14893
+ } else {
14894
+ return void 0;
14895
+ }
14896
+ const fmLines = [];
14897
+ let closed = false;
14898
+ while (cursor < text.length) {
14899
+ const nl = text.indexOf("\n", cursor);
14900
+ const lineEnd = nl === -1 ? text.length : nl;
14901
+ let line2 = text.slice(cursor, lineEnd);
14902
+ if (line2.endsWith("\r")) line2 = line2.slice(0, -1);
14903
+ if (line2 === "---") {
14904
+ closed = true;
14905
+ break;
14906
+ }
14907
+ fmLines.push(line2);
14908
+ if (nl === -1) break;
14909
+ cursor = nl + 1;
14910
+ }
14911
+ if (!closed) return void 0;
14912
+ let found;
14913
+ for (const line2 of fmLines) {
14914
+ const match = /^[ \t]*ticketNumber[ \t]*:[ \t]*(\d+)[ \t]*$/.exec(line2);
14915
+ if (match === null) continue;
14916
+ const value = Number(match[1]);
14917
+ if (!Number.isInteger(value) || value < 1) return void 0;
14918
+ if (found !== void 0 && found !== value) return void 0;
14919
+ found = value;
14920
+ }
14921
+ return found;
14922
+ }
14923
+ function resolveTicketNumberFromAttachmentBodies(bodies) {
14924
+ const found = /* @__PURE__ */ new Set();
14925
+ for (const body of bodies) {
14926
+ const value = parseTicketNumberFrontmatter(body);
14927
+ if (value !== void 0) found.add(value);
14928
+ }
14929
+ if (found.size !== 1) return void 0;
14930
+ return found.values().next().value;
14931
+ }
14932
+ var init_ticket_frontmatter = __esm({
14933
+ "src/ticket-frontmatter.ts"() {
14934
+ "use strict";
14935
+ init_exact_utf8();
14936
+ }
14937
+ });
14938
+
14876
14939
  // src/audit-escalation.ts
14877
14940
  function isAuditEscalationResult(value) {
14878
14941
  if (typeof value !== "object" || value === null || Array.isArray(value)) {
@@ -15338,7 +15401,9 @@ async function writeRoleInvocationLedger(source, role) {
15338
15401
  projectRoot: source.projectRoot,
15339
15402
  runDirectory: source.runDirectory,
15340
15403
  sessionDirectory: source.sessionDirectory,
15341
- sessionFile: source.sessionFile
15404
+ sessionFile: source.sessionFile,
15405
+ ...source.correlationId === void 0 ? {} : { correlationId: source.correlationId },
15406
+ ...source.ticketNumber === void 0 ? {} : { ticketNumber: source.ticketNumber }
15342
15407
  };
15343
15408
  await writeFile2(
15344
15409
  join5(source.runDirectory, "invocation.json"),
@@ -15568,13 +15633,37 @@ async function freezeRegularFileAttachment(sourcePath, destinationDir, index) {
15568
15633
  const frozenPath = join5(destinationDir, name);
15569
15634
  await writeFile2(frozenPath, bytes);
15570
15635
  return {
15571
- provenancePath: absolute,
15572
- frozenPath,
15573
- byteLength: bytes.byteLength,
15574
- sha256: sha256Hex(bytes),
15575
- mediaKind: "regular-file"
15636
+ attachment: {
15637
+ provenancePath: absolute,
15638
+ frozenPath,
15639
+ byteLength: bytes.byteLength,
15640
+ sha256: sha256Hex(bytes),
15641
+ mediaKind: "regular-file"
15642
+ },
15643
+ body: bytes
15576
15644
  };
15577
15645
  }
15646
+ async function freezeAttachmentsWithTicketNumber(attachmentPaths, attachmentsDirectory) {
15647
+ const attachments = [];
15648
+ const bodies = [];
15649
+ for (let i = 0; i < attachmentPaths.length; i += 1) {
15650
+ const frozen = await freezeRegularFileAttachment(
15651
+ attachmentPaths[i],
15652
+ attachmentsDirectory,
15653
+ i
15654
+ );
15655
+ attachments.push(frozen.attachment);
15656
+ bodies.push(frozen.body);
15657
+ }
15658
+ const ticketNumber = resolveTicketNumberFromAttachmentBodies(bodies);
15659
+ return {
15660
+ attachments,
15661
+ ...ticketNumber === void 0 ? {} : { ticketNumber }
15662
+ };
15663
+ }
15664
+ function ticketAdmissionFields(ticketNumber) {
15665
+ return ticketNumber === void 0 ? {} : { ticketNumber };
15666
+ }
15578
15667
  async function admitJudgeInvocation(options) {
15579
15668
  if (options.project !== void 0) {
15580
15669
  requireOptionPath("--project", options.project);
@@ -15585,16 +15674,11 @@ async function admitJudgeInvocation(options) {
15585
15674
  const attachmentsDirectory = join5(runDirectory, "attachments");
15586
15675
  ensureRealDirectoryTree(ledgerHome, sessionDirectory);
15587
15676
  ensureRealDirectoryTree(ledgerHome, attachmentsDirectory);
15588
- const attachments = [];
15589
- for (let i = 0; i < options.attachmentPaths.length; i += 1) {
15590
- attachments.push(
15591
- await freezeRegularFileAttachment(
15592
- options.attachmentPaths[i],
15593
- attachmentsDirectory,
15594
- i
15595
- )
15596
- );
15597
- }
15677
+ const { attachments, ticketNumber } = await freezeAttachmentsWithTicketNumber(
15678
+ options.attachmentPaths,
15679
+ attachmentsDirectory
15680
+ );
15681
+ const ticketFields = ticketAdmissionFields(ticketNumber);
15598
15682
  const instruction = options.instruction;
15599
15683
  const instructionEmpty = instruction.trim() === "";
15600
15684
  const admitted = {
@@ -15605,6 +15689,7 @@ async function admitJudgeInvocation(options) {
15605
15689
  runDirectory,
15606
15690
  sessionDirectory,
15607
15691
  sessionFile,
15692
+ ...ticketFields,
15608
15693
  instruction,
15609
15694
  instructionEmpty,
15610
15695
  attachments: attachments.map((a) => ({
@@ -15630,7 +15715,8 @@ async function admitJudgeInvocation(options) {
15630
15715
  runDirectory,
15631
15716
  sessionDirectory,
15632
15717
  sessionFile,
15633
- admittedRequestPath
15718
+ admittedRequestPath,
15719
+ ...ticketFields
15634
15720
  };
15635
15721
  }
15636
15722
  function buildJudgeTransportPrompt(admitted) {
@@ -15668,16 +15754,11 @@ async function admitCoderInvocation(options) {
15668
15754
  const attachmentsDirectory = join5(runDirectory, "attachments");
15669
15755
  ensureRealDirectoryTree(ledgerHome, sessionDirectory);
15670
15756
  ensureRealDirectoryTree(ledgerHome, attachmentsDirectory);
15671
- const attachments = [];
15672
- for (let i = 0; i < options.attachmentPaths.length; i += 1) {
15673
- attachments.push(
15674
- await freezeRegularFileAttachment(
15675
- options.attachmentPaths[i],
15676
- attachmentsDirectory,
15677
- i
15678
- )
15679
- );
15680
- }
15757
+ const { attachments, ticketNumber } = await freezeAttachmentsWithTicketNumber(
15758
+ options.attachmentPaths,
15759
+ attachmentsDirectory
15760
+ );
15761
+ const ticketFields = ticketAdmissionFields(ticketNumber);
15681
15762
  const taskPath = join5(runDirectory, "task.md");
15682
15763
  await writeFile2(taskPath, instruction, "utf8");
15683
15764
  const admitted = {
@@ -15689,6 +15770,7 @@ async function admitCoderInvocation(options) {
15689
15770
  runDirectory,
15690
15771
  sessionDirectory,
15691
15772
  sessionFile,
15773
+ ...ticketFields,
15692
15774
  instruction,
15693
15775
  instructionEmpty: false,
15694
15776
  taskPath,
@@ -15717,7 +15799,8 @@ async function admitCoderInvocation(options) {
15717
15799
  sessionDirectory,
15718
15800
  sessionFile,
15719
15801
  admittedRequestPath,
15720
- taskPath
15802
+ taskPath,
15803
+ ...ticketFields
15721
15804
  };
15722
15805
  }
15723
15806
  function buildCoderTransportPrompt(admitted) {
@@ -15744,29 +15827,12 @@ async function admitFixerInvocation(options) {
15744
15827
  if (options.phase !== "plan" && options.phase !== "apply") {
15745
15828
  throw new CliUsageError("fixer phase must be plan or apply");
15746
15829
  }
15747
- const projectRoot = resolve4(options.project ?? options.cwd);
15748
- const runId = (options.createRunId ?? uuidv7)();
15749
- const { ledgerHome, bookKey, runDirectory, sessionDirectory, sessionFile } = roleRunSessionCoordinates({ cwd: projectRoot, runId, role: "fixer", home: options.home });
15750
- const attachmentsDirectory = join5(runDirectory, "attachments");
15751
- ensureRealDirectoryTree(ledgerHome, sessionDirectory);
15752
- ensureRealDirectoryTree(ledgerHome, attachmentsDirectory);
15753
- const attachments = [];
15754
- for (let i = 0; i < options.attachmentPaths.length; i += 1) {
15755
- attachments.push(
15756
- await freezeRegularFileAttachment(
15757
- options.attachmentPaths[i],
15758
- attachmentsDirectory,
15759
- i
15760
- )
15761
- );
15762
- }
15763
15830
  let prerequisites = Object.freeze([]);
15764
- let prerequisitesPath;
15831
+ let prerequisitesSource;
15765
15832
  if (options.prerequisitesPath !== void 0) {
15766
15833
  const absolutePrereq = isAbsolute3(options.prerequisitesPath) ? options.prerequisitesPath : resolve4(options.prerequisitesPath);
15767
- let source;
15768
15834
  try {
15769
- source = await readFile4(absolutePrereq, "utf8");
15835
+ prerequisitesSource = await readFile4(absolutePrereq, "utf8");
15770
15836
  } catch (error) {
15771
15837
  throw new CliUsageError(
15772
15838
  `fixer prerequisites path is unreadable: ${options.prerequisitesPath}`,
@@ -15774,13 +15840,27 @@ async function admitFixerInvocation(options) {
15774
15840
  );
15775
15841
  }
15776
15842
  try {
15777
- prerequisites = parseFixerPrerequisites(source);
15843
+ prerequisites = parseFixerPrerequisites(prerequisitesSource);
15778
15844
  } catch (error) {
15779
15845
  if (error instanceof FixerPacketValidationError) {
15780
15846
  throw new CliUsageError(error.message, { cause: error });
15781
15847
  }
15782
15848
  throw error;
15783
15849
  }
15850
+ }
15851
+ const projectRoot = resolve4(options.project ?? options.cwd);
15852
+ const runId = (options.createRunId ?? uuidv7)();
15853
+ const { ledgerHome, bookKey, runDirectory, sessionDirectory, sessionFile } = roleRunSessionCoordinates({ cwd: projectRoot, runId, role: "fixer", home: options.home });
15854
+ const attachmentsDirectory = join5(runDirectory, "attachments");
15855
+ ensureRealDirectoryTree(ledgerHome, sessionDirectory);
15856
+ ensureRealDirectoryTree(ledgerHome, attachmentsDirectory);
15857
+ const { attachments, ticketNumber } = await freezeAttachmentsWithTicketNumber(
15858
+ options.attachmentPaths,
15859
+ attachmentsDirectory
15860
+ );
15861
+ const ticketFields = ticketAdmissionFields(ticketNumber);
15862
+ let prerequisitesPath;
15863
+ if (prerequisitesSource !== void 0) {
15784
15864
  prerequisitesPath = join5(runDirectory, "prerequisites.json");
15785
15865
  await writeFile2(
15786
15866
  prerequisitesPath,
@@ -15800,6 +15880,7 @@ async function admitFixerInvocation(options) {
15800
15880
  runDirectory,
15801
15881
  sessionDirectory,
15802
15882
  sessionFile,
15883
+ ...ticketFields,
15803
15884
  instruction,
15804
15885
  instructionEmpty: false,
15805
15886
  packetPath,
@@ -15835,7 +15916,8 @@ async function admitFixerInvocation(options) {
15835
15916
  admittedRequestPath,
15836
15917
  packetPath,
15837
15918
  ...prerequisitesPath === void 0 ? {} : { prerequisitesPath },
15838
- prerequisites
15919
+ prerequisites,
15920
+ ...ticketFields
15839
15921
  };
15840
15922
  }
15841
15923
  function buildFixerTransportPrompt(admitted) {
@@ -16003,34 +16085,32 @@ async function admitCollectorInvocation(options) {
16003
16085
  } else {
16004
16086
  repository = resolveGitHubRemoteRepository(projectRoot);
16005
16087
  }
16006
- const runId = (options.createRunId ?? uuidv7)();
16007
- const { ledgerHome, bookKey, runDirectory, sessionDirectory, sessionFile } = roleRunSessionCoordinates({ cwd: projectRoot, runId, role: "collector", home: options.home });
16008
- const attachmentsDirectory = join5(runDirectory, "attachments");
16009
- ensureRealDirectoryTree(ledgerHome, sessionDirectory);
16010
- ensureRealDirectoryTree(ledgerHome, attachmentsDirectory);
16011
- const attachments = [];
16012
- const attachmentPaths = options.attachmentPaths ?? [];
16013
- for (let i = 0; i < attachmentPaths.length; i += 1) {
16014
- attachments.push(
16015
- await freezeRegularFileAttachment(
16016
- attachmentPaths[i],
16017
- attachmentsDirectory,
16018
- i
16019
- )
16020
- );
16021
- }
16022
16088
  let manifest = emptyCollectorManifest();
16023
- let requestManifestPath;
16089
+ let manifestCanonicalJson;
16024
16090
  if (options.requestManifestPath !== void 0) {
16025
16091
  try {
16026
16092
  manifest = await loadCollectorManifest(options.requestManifestPath);
16093
+ manifestCanonicalJson = manifest.canonicalJson;
16027
16094
  } catch (error) {
16028
16095
  throw new CliUsageError(error instanceof Error ? error.message : String(error), { cause: error });
16029
16096
  }
16030
- requestManifestPath = join5(runDirectory, "request-manifest.json");
16031
- await writeFile2(requestManifestPath, manifest.canonicalJson, "utf8");
16032
16097
  }
16033
16098
  const manifestDigest = manifest.digest;
16099
+ const runId = (options.createRunId ?? uuidv7)();
16100
+ const { ledgerHome, bookKey, runDirectory, sessionDirectory, sessionFile } = roleRunSessionCoordinates({ cwd: projectRoot, runId, role: "collector", home: options.home });
16101
+ const attachmentsDirectory = join5(runDirectory, "attachments");
16102
+ ensureRealDirectoryTree(ledgerHome, sessionDirectory);
16103
+ ensureRealDirectoryTree(ledgerHome, attachmentsDirectory);
16104
+ const { attachments, ticketNumber } = await freezeAttachmentsWithTicketNumber(
16105
+ options.attachmentPaths ?? [],
16106
+ attachmentsDirectory
16107
+ );
16108
+ const ticketFields = ticketAdmissionFields(ticketNumber);
16109
+ let requestManifestPath;
16110
+ if (manifestCanonicalJson !== void 0) {
16111
+ requestManifestPath = join5(runDirectory, "request-manifest.json");
16112
+ await writeFile2(requestManifestPath, manifestCanonicalJson, "utf8");
16113
+ }
16034
16114
  const instruction = options.instruction ?? "";
16035
16115
  const instructionEmpty = instruction.trim() === "";
16036
16116
  const admitted = {
@@ -16041,6 +16121,7 @@ async function admitCollectorInvocation(options) {
16041
16121
  runDirectory,
16042
16122
  sessionDirectory,
16043
16123
  sessionFile,
16124
+ ...ticketFields,
16044
16125
  instruction,
16045
16126
  instructionEmpty,
16046
16127
  prNumber,
@@ -16079,7 +16160,8 @@ async function admitCollectorInvocation(options) {
16079
16160
  prNumber,
16080
16161
  repository,
16081
16162
  ...requestManifestPath === void 0 ? {} : { requestManifestPath },
16082
- manifestDigest
16163
+ manifestDigest,
16164
+ ...ticketFields
16083
16165
  };
16084
16166
  }
16085
16167
  function buildCollectorTransportPrompt(_admitted) {
@@ -16276,17 +16358,11 @@ async function admitDoctorInvocation(options) {
16276
16358
  const attachmentsDirectory = join5(runDirectory, "attachments");
16277
16359
  ensureRealDirectoryTree(ledgerHome, sessionDirectory);
16278
16360
  ensureRealDirectoryTree(ledgerHome, attachmentsDirectory);
16279
- const attachments = [];
16280
- const attachmentPaths = options.attachmentPaths ?? [];
16281
- for (let i = 0; i < attachmentPaths.length; i += 1) {
16282
- attachments.push(
16283
- await freezeRegularFileAttachment(
16284
- attachmentPaths[i],
16285
- attachmentsDirectory,
16286
- i
16287
- )
16288
- );
16289
- }
16361
+ const { attachments, ticketNumber } = await freezeAttachmentsWithTicketNumber(
16362
+ options.attachmentPaths ?? [],
16363
+ attachmentsDirectory
16364
+ );
16365
+ const ticketFields = ticketAdmissionFields(ticketNumber);
16290
16366
  const instruction = options.instruction ?? "";
16291
16367
  const instructionEmpty = instruction.trim() === "";
16292
16368
  const admitted = {
@@ -16297,6 +16373,7 @@ async function admitDoctorInvocation(options) {
16297
16373
  runDirectory,
16298
16374
  sessionDirectory,
16299
16375
  sessionFile,
16376
+ ...ticketFields,
16300
16377
  instruction,
16301
16378
  instructionEmpty,
16302
16379
  issueNumber: options.issueNumber,
@@ -16332,7 +16409,8 @@ async function admitDoctorInvocation(options) {
16332
16409
  admittedRequestPath,
16333
16410
  issueNumber: options.issueNumber,
16334
16411
  caseRunsPath,
16335
- caseIdentity: caseIdentity2
16412
+ caseIdentity: caseIdentity2,
16413
+ ...ticketFields
16336
16414
  };
16337
16415
  }
16338
16416
  function buildDoctorTransportPrompt(admitted) {
@@ -16402,16 +16480,11 @@ async function admitReviewerInvocation(options) {
16402
16480
  const attachmentsDirectory = join5(runDirectory, "attachments");
16403
16481
  ensureRealDirectoryTree(ledgerHome, sessionDirectory);
16404
16482
  ensureRealDirectoryTree(ledgerHome, attachmentsDirectory);
16405
- const attachments = [];
16406
- for (let i = 0; i < options.attachmentPaths.length; i += 1) {
16407
- attachments.push(
16408
- await freezeRegularFileAttachment(
16409
- options.attachmentPaths[i],
16410
- attachmentsDirectory,
16411
- i
16412
- )
16413
- );
16414
- }
16483
+ const { attachments, ticketNumber } = await freezeAttachmentsWithTicketNumber(
16484
+ options.attachmentPaths,
16485
+ attachmentsDirectory
16486
+ );
16487
+ const ticketFields = ticketAdmissionFields(ticketNumber);
16415
16488
  const instruction = options.instruction;
16416
16489
  const instructionEmpty = instruction.trim() === "";
16417
16490
  const admitted = {
@@ -16422,6 +16495,7 @@ async function admitReviewerInvocation(options) {
16422
16495
  runDirectory,
16423
16496
  sessionDirectory,
16424
16497
  sessionFile,
16498
+ ...ticketFields,
16425
16499
  instruction,
16426
16500
  instructionEmpty,
16427
16501
  baseRevision: options.baseRevision,
@@ -16453,7 +16527,8 @@ async function admitReviewerInvocation(options) {
16453
16527
  sessionDirectory,
16454
16528
  sessionFile,
16455
16529
  admittedRequestPath,
16456
- baseRevision: options.baseRevision
16530
+ baseRevision: options.baseRevision,
16531
+ ...ticketFields
16457
16532
  };
16458
16533
  }
16459
16534
  function buildReviewerTransportPrompt(admitted) {
@@ -16555,16 +16630,11 @@ async function admitMergerInvocation(options) {
16555
16630
  const attachmentsDirectory = join5(runDirectory, "attachments");
16556
16631
  ensureRealDirectoryTree(ledgerHome, sessionDirectory);
16557
16632
  ensureRealDirectoryTree(ledgerHome, attachmentsDirectory);
16558
- const attachments = [];
16559
- for (let i = 0; i < options.attachmentPaths.length; i += 1) {
16560
- attachments.push(
16561
- await freezeRegularFileAttachment(
16562
- options.attachmentPaths[i],
16563
- attachmentsDirectory,
16564
- i
16565
- )
16566
- );
16567
- }
16633
+ const { attachments, ticketNumber } = await freezeAttachmentsWithTicketNumber(
16634
+ options.attachmentPaths,
16635
+ attachmentsDirectory
16636
+ );
16637
+ const ticketFields = ticketAdmissionFields(ticketNumber);
16568
16638
  const targetIntent = mergerMaterialFromUtf8(
16569
16639
  `Investigate primary sources for target parent ${derived.targetObjectId}. Do not invent intent.`
16570
16640
  );
@@ -16604,6 +16674,7 @@ async function admitMergerInvocation(options) {
16604
16674
  runDirectory,
16605
16675
  sessionDirectory,
16606
16676
  sessionFile,
16677
+ ...ticketFields,
16607
16678
  instruction,
16608
16679
  instructionEmpty: false,
16609
16680
  mergerInputPath,
@@ -16643,7 +16714,8 @@ async function admitMergerInvocation(options) {
16643
16714
  sessionFile,
16644
16715
  admittedRequestPath,
16645
16716
  mergerInputPath,
16646
- derived: admitted.derived
16717
+ derived: admitted.derived,
16718
+ ...ticketFields
16647
16719
  };
16648
16720
  }
16649
16721
  function buildMergerTransportPrompt(admitted) {
@@ -16666,6 +16738,7 @@ var init_invocation = __esm({
16666
16738
  init_activation_ledger_topology();
16667
16739
  init_activation_ledger_git();
16668
16740
  init_sitian_role_run_coordinates();
16741
+ init_ticket_frontmatter();
16669
16742
  init_doctor_evidence();
16670
16743
  init_collector_config();
16671
16744
  init_fixer_packet();
@@ -17524,6 +17597,20 @@ async function findRunDirectoryById(home, runId) {
17524
17597
  }
17525
17598
  return void 0;
17526
17599
  }
17600
+ function parsePersistedTicketIdentity(record4) {
17601
+ const correlationId = typeof record4.correlationId === "string" && record4.correlationId.trim() !== "" ? record4.correlationId : void 0;
17602
+ const ticketNumber = typeof record4.ticketNumber === "number" && Number.isInteger(record4.ticketNumber) && record4.ticketNumber >= 1 ? record4.ticketNumber : void 0;
17603
+ return {
17604
+ ...correlationId === void 0 ? {} : { correlationId },
17605
+ ...ticketNumber === void 0 ? {} : { ticketNumber }
17606
+ };
17607
+ }
17608
+ function restoredTicketFields(fields) {
17609
+ return {
17610
+ ...fields.correlationId === void 0 ? {} : { correlationId: fields.correlationId },
17611
+ ...fields.ticketNumber === void 0 ? {} : { ticketNumber: fields.ticketNumber }
17612
+ };
17613
+ }
17527
17614
  async function loadResumableRunRecord(home, runId) {
17528
17615
  const runDirectory = await findRunDirectoryById(home, runId);
17529
17616
  if (runDirectory === void 0) {
@@ -17555,6 +17642,8 @@ async function loadResumableRunRecord(home, runId) {
17555
17642
  let baseRevision;
17556
17643
  let mergerInputPath;
17557
17644
  let derived;
17645
+ let correlationId;
17646
+ let ticketNumber;
17558
17647
  try {
17559
17648
  const raw = JSON.parse(
17560
17649
  await readFile8(run.admittedRequestPath, "utf8")
@@ -17603,12 +17692,36 @@ async function loadResumableRunRecord(home, runId) {
17603
17692
  };
17604
17693
  }
17605
17694
  }
17695
+ const fromAdmitted = parsePersistedTicketIdentity(record4);
17696
+ correlationId = fromAdmitted.correlationId;
17697
+ ticketNumber = fromAdmitted.ticketNumber;
17606
17698
  }
17607
17699
  } catch {
17608
17700
  throw new CliUsageError(
17609
17701
  `role run admitted request is unreadable: ${runId}`
17610
17702
  );
17611
17703
  }
17704
+ if (correlationId === void 0 || ticketNumber === void 0) {
17705
+ try {
17706
+ const invocationRaw = JSON.parse(
17707
+ await readFile8(join9(run.runDirectory, "invocation.json"), "utf8")
17708
+ );
17709
+ if (invocationRaw !== null && typeof invocationRaw === "object" && !Array.isArray(invocationRaw)) {
17710
+ const fromInvocation = parsePersistedTicketIdentity(
17711
+ invocationRaw
17712
+ );
17713
+ if (correlationId === void 0) correlationId = fromInvocation.correlationId;
17714
+ if (ticketNumber === void 0) ticketNumber = fromInvocation.ticketNumber;
17715
+ }
17716
+ } catch (error) {
17717
+ if (!(error instanceof Error && "code" in error && error.code === "ENOENT")) {
17718
+ throw new CliUsageError(
17719
+ `role run invocation identity is unreadable: ${runId}`,
17720
+ { cause: error }
17721
+ );
17722
+ }
17723
+ }
17724
+ }
17612
17725
  return {
17613
17726
  run,
17614
17727
  observation: run.resumable,
@@ -17623,7 +17736,9 @@ async function loadResumableRunRecord(home, runId) {
17623
17736
  ...prerequisites === void 0 ? {} : { prerequisites },
17624
17737
  ...baseRevision === void 0 ? {} : { baseRevision },
17625
17738
  ...mergerInputPath === void 0 ? {} : { mergerInputPath },
17626
- ...derived === void 0 ? {} : { derived }
17739
+ ...derived === void 0 ? {} : { derived },
17740
+ ...correlationId === void 0 ? {} : { correlationId },
17741
+ ...ticketNumber === void 0 ? {} : { ticketNumber }
17627
17742
  }
17628
17743
  };
17629
17744
  }
@@ -17645,7 +17760,8 @@ async function loadResumableJudgeRun(home, runId) {
17645
17760
  runDirectory: loaded.run.runDirectory,
17646
17761
  sessionDirectory: loaded.run.sessionDirectory,
17647
17762
  sessionFile: loaded.run.sessionFile,
17648
- admittedRequestPath: loaded.run.admittedRequestPath
17763
+ admittedRequestPath: loaded.run.admittedRequestPath,
17764
+ ...restoredTicketFields(loaded.admittedFields)
17649
17765
  };
17650
17766
  return {
17651
17767
  admitted,
@@ -17690,7 +17806,8 @@ async function loadResumableCoderRun(home, runId) {
17690
17806
  sessionDirectory: loaded.run.sessionDirectory,
17691
17807
  sessionFile: loaded.run.sessionFile,
17692
17808
  admittedRequestPath: loaded.run.admittedRequestPath,
17693
- taskPath
17809
+ taskPath,
17810
+ ...restoredTicketFields(loaded.admittedFields)
17694
17811
  };
17695
17812
  return {
17696
17813
  admitted,
@@ -17738,7 +17855,8 @@ async function loadResumableFixerRun(home, runId) {
17738
17855
  admittedRequestPath: loaded.run.admittedRequestPath,
17739
17856
  packetPath,
17740
17857
  ...loaded.admittedFields.prerequisitesPath === void 0 ? {} : { prerequisitesPath: loaded.admittedFields.prerequisitesPath },
17741
- prerequisites
17858
+ prerequisites,
17859
+ ...restoredTicketFields(loaded.admittedFields)
17742
17860
  };
17743
17861
  return {
17744
17862
  admitted,
@@ -17771,7 +17889,8 @@ async function loadResumableReviewerRun(home, runId) {
17771
17889
  sessionDirectory: loaded.run.sessionDirectory,
17772
17890
  sessionFile: loaded.run.sessionFile,
17773
17891
  admittedRequestPath: loaded.run.admittedRequestPath,
17774
- baseRevision
17892
+ baseRevision,
17893
+ ...restoredTicketFields(loaded.admittedFields)
17775
17894
  };
17776
17895
  return {
17777
17896
  admitted,
@@ -17816,7 +17935,8 @@ async function loadResumableMergerRun(home, runId) {
17816
17935
  sessionFile: loaded.run.sessionFile,
17817
17936
  admittedRequestPath: loaded.run.admittedRequestPath,
17818
17937
  mergerInputPath,
17819
- derived
17938
+ derived,
17939
+ ...restoredTicketFields(loaded.admittedFields)
17820
17940
  };
17821
17941
  return {
17822
17942
  admitted,
@@ -21265,8 +21385,9 @@ async function dispatchAdmittedCoder(input) {
21265
21385
  PI_CODING_AGENT_DIR: env.agentDir,
21266
21386
  AK_ROLE_RUN_DIR: admitted.runDirectory
21267
21387
  };
21268
- if (env.correlationId !== void 0 && env.correlationId.trim() !== "") {
21269
- childEnv.AK_CORRELATION_ID = env.correlationId;
21388
+ const correlationId = admitted.correlationId ?? env.correlationId;
21389
+ if (correlationId !== void 0 && correlationId.trim() !== "") {
21390
+ childEnv.AK_CORRELATION_ID = correlationId;
21270
21391
  }
21271
21392
  let result2;
21272
21393
  try {
@@ -21412,7 +21533,10 @@ async function runPublicCoder(argv, env, io, parseCoderArgv2) {
21412
21533
  });
21413
21534
  return await dispatchAdmittedCoder({
21414
21535
  admitted,
21415
- env,
21536
+ env: {
21537
+ ...env,
21538
+ ...admitted.correlationId === void 0 ? {} : { correlationId: admitted.correlationId }
21539
+ },
21416
21540
  io,
21417
21541
  extraArgs,
21418
21542
  lease,
@@ -21486,7 +21610,10 @@ async function runPublicCoderResume(argv, env, io) {
21486
21610
  });
21487
21611
  return await dispatchAdmittedCoder({
21488
21612
  admitted,
21489
- env,
21613
+ env: {
21614
+ ...env,
21615
+ ...admitted.correlationId === void 0 ? {} : { correlationId: admitted.correlationId }
21616
+ },
21490
21617
  io,
21491
21618
  extraArgs,
21492
21619
  lease,
@@ -21591,8 +21718,9 @@ async function dispatchAdmittedCollector(input) {
21591
21718
  PI_CODING_AGENT_DIR: env.agentDir,
21592
21719
  AK_ROLE_RUN_DIR: admitted.runDirectory
21593
21720
  };
21594
- if (env.correlationId !== void 0 && env.correlationId.trim() !== "") {
21595
- childEnv.AK_CORRELATION_ID = env.correlationId;
21721
+ const correlationId = admitted.correlationId ?? env.correlationId;
21722
+ if (correlationId !== void 0 && correlationId.trim() !== "") {
21723
+ childEnv.AK_CORRELATION_ID = correlationId;
21596
21724
  }
21597
21725
  let result2;
21598
21726
  try {
@@ -21721,7 +21849,10 @@ async function runPublicCollector(argv, env, io, parseCollectorArgv2) {
21721
21849
  });
21722
21850
  return await dispatchAdmittedCollector({
21723
21851
  admitted,
21724
- env,
21852
+ env: {
21853
+ ...env,
21854
+ ...admitted.correlationId === void 0 ? {} : { correlationId: admitted.correlationId }
21855
+ },
21725
21856
  io,
21726
21857
  extraArgs,
21727
21858
  lease
@@ -22123,8 +22254,9 @@ async function dispatchAdmittedFixer(input) {
22123
22254
  PI_CODING_AGENT_DIR: env.agentDir,
22124
22255
  AK_ROLE_RUN_DIR: admitted.runDirectory
22125
22256
  };
22126
- if (env.correlationId !== void 0 && env.correlationId.trim() !== "") {
22127
- childEnv.AK_CORRELATION_ID = env.correlationId;
22257
+ const correlationId = admitted.correlationId ?? env.correlationId;
22258
+ if (correlationId !== void 0 && correlationId.trim() !== "") {
22259
+ childEnv.AK_CORRELATION_ID = correlationId;
22128
22260
  }
22129
22261
  let result2;
22130
22262
  try {
@@ -22286,7 +22418,10 @@ async function runPublicFixer(argv, env, io, parseFixerArgv2) {
22286
22418
  });
22287
22419
  return await dispatchAdmittedFixer({
22288
22420
  admitted,
22289
- env,
22421
+ env: {
22422
+ ...env,
22423
+ ...admitted.correlationId === void 0 ? {} : { correlationId: admitted.correlationId }
22424
+ },
22290
22425
  io,
22291
22426
  extraArgs,
22292
22427
  lease,
@@ -22353,7 +22488,10 @@ async function runPublicFixerResume(argv, env, io) {
22353
22488
  });
22354
22489
  return await dispatchAdmittedFixer({
22355
22490
  admitted,
22356
- env,
22491
+ env: {
22492
+ ...env,
22493
+ ...admitted.correlationId === void 0 ? {} : { correlationId: admitted.correlationId }
22494
+ },
22357
22495
  io,
22358
22496
  extraArgs,
22359
22497
  lease,
@@ -22497,8 +22635,9 @@ async function dispatchAdmittedJudge(input) {
22497
22635
  // and role-runtime can record typed provider HTTP observations.
22498
22636
  AK_ROLE_RUN_DIR: admitted.runDirectory
22499
22637
  };
22500
- if (env.correlationId !== void 0 && env.correlationId.trim() !== "") {
22501
- childEnv.AK_CORRELATION_ID = env.correlationId;
22638
+ const correlationId = admitted.correlationId ?? env.correlationId;
22639
+ if (correlationId !== void 0 && correlationId.trim() !== "") {
22640
+ childEnv.AK_CORRELATION_ID = correlationId;
22502
22641
  }
22503
22642
  let result2;
22504
22643
  try {
@@ -22631,7 +22770,10 @@ async function runPublicJudge(argv, env, io, parseJudgeArgv2) {
22631
22770
  });
22632
22771
  return await dispatchAdmittedJudge({
22633
22772
  admitted,
22634
- env,
22773
+ env: {
22774
+ ...env,
22775
+ ...admitted.correlationId === void 0 ? {} : { correlationId: admitted.correlationId }
22776
+ },
22635
22777
  io,
22636
22778
  extraArgs,
22637
22779
  lease
@@ -22680,7 +22822,10 @@ async function runPublicResume(argv, env, io) {
22680
22822
  });
22681
22823
  return await dispatchAdmittedJudge({
22682
22824
  admitted,
22683
- env,
22825
+ env: {
22826
+ ...env,
22827
+ ...admitted.correlationId === void 0 ? {} : { correlationId: admitted.correlationId }
22828
+ },
22684
22829
  io,
22685
22830
  extraArgs,
22686
22831
  lease
@@ -22838,8 +22983,9 @@ async function dispatchAdmittedMerger(input) {
22838
22983
  PI_CODING_AGENT_DIR: env.agentDir,
22839
22984
  AK_ROLE_RUN_DIR: admitted.runDirectory
22840
22985
  };
22841
- if (env.correlationId !== void 0 && env.correlationId.trim() !== "") {
22842
- childEnv.AK_CORRELATION_ID = env.correlationId;
22986
+ const correlationId = admitted.correlationId ?? env.correlationId;
22987
+ if (correlationId !== void 0 && correlationId.trim() !== "") {
22988
+ childEnv.AK_CORRELATION_ID = correlationId;
22843
22989
  }
22844
22990
  let result2;
22845
22991
  try {
@@ -23071,7 +23217,10 @@ async function runPublicMerger(argv, env, io, parseMergerArgv2) {
23071
23217
  });
23072
23218
  return await dispatchAdmittedMerger({
23073
23219
  admitted,
23074
- env,
23220
+ env: {
23221
+ ...env,
23222
+ ...admitted.correlationId === void 0 ? {} : { correlationId: admitted.correlationId }
23223
+ },
23075
23224
  io,
23076
23225
  extraArgs,
23077
23226
  lease,
@@ -23139,7 +23288,10 @@ async function runPublicMergerResume(argv, env, io) {
23139
23288
  });
23140
23289
  return await dispatchAdmittedMerger({
23141
23290
  admitted,
23142
- env,
23291
+ env: {
23292
+ ...env,
23293
+ ...admitted.correlationId === void 0 ? {} : { correlationId: admitted.correlationId }
23294
+ },
23143
23295
  io,
23144
23296
  extraArgs,
23145
23297
  lease,
@@ -23300,8 +23452,9 @@ async function dispatchAdmittedReviewer(input) {
23300
23452
  PI_CODING_AGENT_DIR: env.agentDir,
23301
23453
  AK_ROLE_RUN_DIR: admitted.runDirectory
23302
23454
  };
23303
- if (env.correlationId !== void 0 && env.correlationId.trim() !== "") {
23304
- childEnv.AK_CORRELATION_ID = env.correlationId;
23455
+ const correlationId = admitted.correlationId ?? env.correlationId;
23456
+ if (correlationId !== void 0 && correlationId.trim() !== "") {
23457
+ childEnv.AK_CORRELATION_ID = correlationId;
23305
23458
  }
23306
23459
  let result2;
23307
23460
  try {
@@ -23462,7 +23615,10 @@ async function runPublicReviewer(argv, env, io, parseReviewerArgv2) {
23462
23615
  });
23463
23616
  return await dispatchAdmittedReviewer({
23464
23617
  admitted,
23465
- env,
23618
+ env: {
23619
+ ...env,
23620
+ ...admitted.correlationId === void 0 ? {} : { correlationId: admitted.correlationId }
23621
+ },
23466
23622
  io,
23467
23623
  extraArgs,
23468
23624
  lease,
@@ -23529,7 +23685,10 @@ async function runPublicReviewerResume(argv, env, io) {
23529
23685
  });
23530
23686
  return await dispatchAdmittedReviewer({
23531
23687
  admitted,
23532
- env,
23688
+ env: {
23689
+ ...env,
23690
+ ...admitted.correlationId === void 0 ? {} : { correlationId: admitted.correlationId }
23691
+ },
23533
23692
  io,
23534
23693
  extraArgs,
23535
23694
  lease,
@@ -23554,6 +23713,7 @@ var init_reviewer_run = __esm({
23554
23713
  var cli_exports = {};
23555
23714
  __export(cli_exports, {
23556
23715
  CliUsageError: () => CliUsageError,
23716
+ PUBLIC_ROLE_ARGV: () => PUBLIC_ROLE_ARGV,
23557
23717
  buildExplicitInternalActivationArgs: () => buildExplicitInternalActivationArgs,
23558
23718
  helpDocument: () => helpDocument,
23559
23719
  resolveInternalRoleEntrypoint: () => resolveInternalRoleEntrypoint,
@@ -23562,6 +23722,42 @@ __export(cli_exports, {
23562
23722
  import { realpath as realpath5 } from "node:fs/promises";
23563
23723
  import { homedir as homedir3 } from "node:os";
23564
23724
  import { join as join18 } from "node:path";
23725
+ function takePublicGlobalFlag(argv, index) {
23726
+ const token = argv[index];
23727
+ if (token === void 0) return void 0;
23728
+ if (token === "--help" || token === "-h") {
23729
+ return { flag: "help", consume: 1 };
23730
+ }
23731
+ if (token === "--model") {
23732
+ const value = argv[index + 1];
23733
+ if (value === void 0) {
23734
+ return { flag: "model", consume: 1, value: void 0 };
23735
+ }
23736
+ return { flag: "model", consume: 2, value };
23737
+ }
23738
+ if (token.startsWith("--model=")) {
23739
+ return {
23740
+ flag: "model",
23741
+ consume: 1,
23742
+ value: token.slice("--model=".length)
23743
+ };
23744
+ }
23745
+ if (token === "--thinking") {
23746
+ const raw = argv[index + 1];
23747
+ if (raw === void 0) {
23748
+ return { flag: "thinking", consume: 1, raw: void 0 };
23749
+ }
23750
+ return { flag: "thinking", consume: 2, raw };
23751
+ }
23752
+ if (token.startsWith("--thinking=")) {
23753
+ return {
23754
+ flag: "thinking",
23755
+ consume: 1,
23756
+ raw: token.slice("--thinking=".length)
23757
+ };
23758
+ }
23759
+ return void 0;
23760
+ }
23565
23761
  function defaultIo() {
23566
23762
  return {
23567
23763
  stdout: (text) => {
@@ -23591,40 +23787,34 @@ function parseArgv(argv) {
23591
23787
  let help = false;
23592
23788
  const positional = [];
23593
23789
  while (args.length > 0) {
23594
- const token = args.shift();
23595
- if (token === "--") {
23790
+ if (args[0] === "--") {
23791
+ args.shift();
23596
23792
  positional.push(...args);
23597
23793
  break;
23598
23794
  }
23599
- if (token === "--help" || token === "-h") {
23600
- help = true;
23601
- continue;
23602
- }
23603
- if (token === "--model") {
23604
- const value = args.shift();
23605
- if (value === void 0) throw new CliUsageError("--model requires a value");
23606
- model = value;
23607
- continue;
23608
- }
23609
- if (token.startsWith("--model=")) {
23610
- model = token.slice("--model=".length);
23611
- continue;
23612
- }
23613
- if (token === "--thinking") {
23614
- const value = args.shift();
23615
- if (value === void 0) throw new CliUsageError("--thinking requires a value");
23616
- thinking = parseThinking(value);
23617
- continue;
23618
- }
23619
- if (token.startsWith("--thinking=")) {
23620
- thinking = parseThinking(token.slice("--thinking=".length));
23621
- continue;
23622
- }
23623
- if (token.startsWith("-") && token !== "-") {
23624
- positional.push(token);
23795
+ const taken = takePublicGlobalFlag(args, 0);
23796
+ if (taken !== void 0) {
23797
+ if (taken.flag === "help") {
23798
+ help = true;
23799
+ args.splice(0, taken.consume);
23800
+ continue;
23801
+ }
23802
+ if (taken.flag === "model") {
23803
+ if (taken.value === void 0) {
23804
+ throw new CliUsageError("--model requires a value");
23805
+ }
23806
+ model = taken.value;
23807
+ args.splice(0, taken.consume);
23808
+ continue;
23809
+ }
23810
+ if (taken.raw === void 0) {
23811
+ throw new CliUsageError("--thinking requires a value");
23812
+ }
23813
+ thinking = parseThinking(taken.raw);
23814
+ args.splice(0, taken.consume);
23625
23815
  continue;
23626
23816
  }
23627
- positional.push(token);
23817
+ positional.push(args.shift());
23628
23818
  }
23629
23819
  const [command, ...rest] = positional;
23630
23820
  return {
@@ -23957,7 +24147,7 @@ async function runAkRole(argv, env) {
23957
24147
  ...env.createRunId === void 0 ? {} : { createRunId: env.createRunId }
23958
24148
  },
23959
24149
  io,
23960
- parseJudgeArgv
24150
+ PUBLIC_ROLE_ARGV.judge.parse
23961
24151
  );
23962
24152
  return {
23963
24153
  exitCode: result2.exitCode,
@@ -23991,7 +24181,7 @@ async function runAkRole(argv, env) {
23991
24181
  ...env.createRunId === void 0 ? {} : { createRunId: env.createRunId }
23992
24182
  },
23993
24183
  io,
23994
- parseCoderArgv
24184
+ PUBLIC_ROLE_ARGV.coder.parse
23995
24185
  );
23996
24186
  return {
23997
24187
  exitCode: result2.exitCode,
@@ -24025,7 +24215,7 @@ async function runAkRole(argv, env) {
24025
24215
  ...env.createRunId === void 0 ? {} : { createRunId: env.createRunId }
24026
24216
  },
24027
24217
  io,
24028
- parseFixerArgv
24218
+ PUBLIC_ROLE_ARGV.fixer.parse
24029
24219
  );
24030
24220
  return {
24031
24221
  exitCode: result2.exitCode,
@@ -24059,7 +24249,7 @@ async function runAkRole(argv, env) {
24059
24249
  ...env.createRunId === void 0 ? {} : { createRunId: env.createRunId }
24060
24250
  },
24061
24251
  io,
24062
- parseCollectorArgv
24252
+ PUBLIC_ROLE_ARGV.collector.parse
24063
24253
  );
24064
24254
  return {
24065
24255
  exitCode: result2.exitCode,
@@ -24093,7 +24283,7 @@ async function runAkRole(argv, env) {
24093
24283
  ...env.createRunId === void 0 ? {} : { createRunId: env.createRunId }
24094
24284
  },
24095
24285
  io,
24096
- parseReviewerArgv
24286
+ PUBLIC_ROLE_ARGV.reviewer.parse
24097
24287
  );
24098
24288
  return {
24099
24289
  exitCode: result2.exitCode,
@@ -24127,7 +24317,7 @@ async function runAkRole(argv, env) {
24127
24317
  ...env.createRunId === void 0 ? {} : { createRunId: env.createRunId }
24128
24318
  },
24129
24319
  io,
24130
- parseDoctorArgv
24320
+ PUBLIC_ROLE_ARGV.doctor.parse
24131
24321
  );
24132
24322
  return {
24133
24323
  exitCode: result2.exitCode,
@@ -24161,7 +24351,7 @@ async function runAkRole(argv, env) {
24161
24351
  ...env.createRunId === void 0 ? {} : { createRunId: env.createRunId }
24162
24352
  },
24163
24353
  io,
24164
- parseMergerArgv
24354
+ PUBLIC_ROLE_ARGV.merger.parse
24165
24355
  );
24166
24356
  return {
24167
24357
  exitCode: result2.exitCode,
@@ -24183,7 +24373,7 @@ async function runAkRole(argv, env) {
24183
24373
  return { exitCode: 1 };
24184
24374
  }
24185
24375
  }
24186
- var THINKING_LEVELS2;
24376
+ var PUBLIC_ROLE_ARGV, THINKING_LEVELS2;
24187
24377
  var init_cli = __esm({
24188
24378
  "src/public-cli/cli.ts"() {
24189
24379
  "use strict";
@@ -24203,6 +24393,15 @@ var init_cli = __esm({
24203
24393
  init_settlement();
24204
24394
  init_explicit_internal();
24205
24395
  init_cli_errors();
24396
+ PUBLIC_ROLE_ARGV = {
24397
+ judge: { parse: parseJudgeArgv },
24398
+ coder: { parse: parseCoderArgv },
24399
+ fixer: { parse: parseFixerArgv },
24400
+ collector: { parse: parseCollectorArgv },
24401
+ doctor: { parse: parseDoctorArgv },
24402
+ merger: { parse: parseMergerArgv },
24403
+ reviewer: { parse: parseReviewerArgv }
24404
+ };
24206
24405
  THINKING_LEVELS2 = /* @__PURE__ */ new Set([
24207
24406
  "off",
24208
24407
  "minimal",