@akagilnc/pi-workflow-roles 0.1.3412 → 0.1.3439

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 (67) hide show
  1. package/dist/archivist-record-entry.js +21 -12
  2. package/dist/archivist-record-topology.js +20 -0
  3. package/dist/auditor-dossier-tool.js +67 -76
  4. package/dist/canonical-json.js +66 -69
  5. package/dist/compliance-transport.js +99 -86
  6. package/dist/countersign-contracts.js +23 -25
  7. package/dist/doctor-contracts.js +169 -145
  8. package/dist/engine-detour-tool.js +83 -87
  9. package/dist/engine-detour.js +148 -183
  10. package/dist/evidence-child-executor.js +10 -1
  11. package/dist/exact-utf8.js +11 -10
  12. package/dist/git-object-id.js +10 -5
  13. package/dist/gleaner-left-contracts.js +33 -35
  14. package/dist/grok/production-host.js +229 -118
  15. package/dist/inspector-contracts.js +28 -31
  16. package/dist/institutional-resolution.js +101 -104
  17. package/dist/ledger-session-read.js +241 -0
  18. package/dist/merger-contracts.js +66 -56
  19. package/dist/notary-contracts.js +91 -100
  20. package/dist/open-tool-schema.js +32 -31
  21. package/dist/package-contracts/collector-output.js +56 -43
  22. package/dist/package-contracts/fixer-output.js +52 -50
  23. package/dist/package-contracts/fixer-packet.js +67 -64
  24. package/dist/package-contracts/gatekeeper-output.js +48 -56
  25. package/dist/package-contracts/judge-output.js +23 -20
  26. package/dist/package-contracts/navigator-output.js +35 -40
  27. package/dist/package-contracts/reviewer-output.js +94 -110
  28. package/dist/package-contracts/terminating-infrastructure.js +62 -90
  29. package/dist/package-contracts/worker-output.js +30 -11
  30. package/dist/package-resources/engine-material.js +58 -94
  31. package/dist/public-cli/config.js +420 -484
  32. package/dist/public-cli/main.js +1219 -524
  33. package/dist/public-cli/registry.js +107 -114
  34. package/dist/receipt-delivery-policy.js +74 -76
  35. package/dist/session-opening-materials.js +44 -47
  36. package/dist/sha256.js +5 -3
  37. package/dist/sitian-appender.js +204 -210
  38. package/dist/sitian-contracts.js +15 -19
  39. package/dist/sitian-facade.js +5 -10
  40. package/dist/sitian-reader.js +37 -46
  41. package/dist/stream-idle-guard.js +63 -71
  42. package/dist/ticket-seat-memory.js +244 -0
  43. package/package.json +1 -1
  44. package/scripts/build-package.mjs +41 -0
  45. package/souls/audit-law.md +4 -0
  46. package/souls/countersign.md +1 -1
  47. package/souls/gleaner-left.md +1 -1
  48. package/souls/inspector.md +1 -1
  49. package/souls/notary.md +1 -1
  50. package/souls/reviewer.md +1 -1
  51. package/src/analyst-gate-cycles-read.ts +152 -83
  52. package/src/analyst-ledger.ts +170 -43
  53. package/src/archivist-record-entry.ts +32 -11
  54. package/src/archivist-record-topology.ts +39 -0
  55. package/src/evidence-child-executor.ts +14 -1
  56. package/src/grok/production-host.ts +44 -9
  57. package/src/host-contracts.ts +18 -0
  58. package/src/host-transition-prior-native.ts +8 -1
  59. package/src/ledger-session-read.ts +56 -0
  60. package/src/pi/durable-principal.ts +6 -0
  61. package/src/public-cli/inspector-run.ts +21 -10
  62. package/src/public-cli/invocation.ts +4 -20
  63. package/src/public-cli/notary-run.ts +21 -4
  64. package/src/public-cli/post-admission.ts +333 -42
  65. package/src/public-cli/settlement.ts +266 -81
  66. package/src/session-opening-materials.ts +4 -2
  67. package/src/ticket-seat-memory.ts +454 -0
@@ -393,6 +393,12 @@ var init_durable_principal = __esm({
393
393
  sessionFile: coordinates.sessionFile
394
394
  });
395
395
  },
396
+ seal(coordinates) {
397
+ return encode({
398
+ sessionDirectory: coordinates.sessionDirectory,
399
+ sessionFile: coordinates.sessionFile
400
+ });
401
+ },
396
402
  decode(value) {
397
403
  const record4 = value;
398
404
  if (record4 === null || typeof record4 !== "object") {
@@ -16648,6 +16654,297 @@ var init_role_turn_host = __esm({
16648
16654
  }
16649
16655
  });
16650
16656
 
16657
+ // src/archivist-record-topology.ts
16658
+ import { createHash as createHash3 } from "node:crypto";
16659
+ import { join as join11 } from "node:path";
16660
+ function subjectKeyedRecordDirectory(input) {
16661
+ const ledgerHome = input.parentSessionFile !== void 0 && input.parentSessionFile.length > 0 ? resolveActivationLedgerHomeForPath(input.parentSessionFile) : resolveActivationLedgerHome(input.home);
16662
+ const digest = createHash3("sha256").update(input.subject).digest("hex").slice(0, 32);
16663
+ return join11(
16664
+ activationBookDirectory(ledgerHome, resolveBookKeyFromGit(input.cwd)),
16665
+ input.kind,
16666
+ digest
16667
+ );
16668
+ }
16669
+ var init_archivist_record_topology = __esm({
16670
+ "src/archivist-record-topology.ts"() {
16671
+ "use strict";
16672
+ init_activation_ledger_git();
16673
+ init_activation_ledger_topology();
16674
+ }
16675
+ });
16676
+
16677
+ // src/session-opening-materials.ts
16678
+ import { existsSync as existsSync6 } from "node:fs";
16679
+ import { dirname as dirname6, join as join12 } from "node:path";
16680
+ import { fileURLToPath, pathToFileURL as pathToFileURL2 } from "node:url";
16681
+ function resolvePackageRootDir(moduleUrl = import.meta.url) {
16682
+ let dir = dirname6(fileURLToPath(moduleUrl));
16683
+ for (let i = 0; i < 8; i += 1) {
16684
+ if (existsSync6(join12(dir, "package.json")) && existsSync6(join12(dir, "souls"))) {
16685
+ return dir;
16686
+ }
16687
+ const parent = dirname6(dir);
16688
+ if (parent === dir) break;
16689
+ dir = parent;
16690
+ }
16691
+ return fileURLToPath(new URL("..", moduleUrl));
16692
+ }
16693
+ var packageRootUrl, MAIN_ROLE_SESSION_MATERIALS, GATEKEEPER_SESSION_MATERIALS;
16694
+ var init_session_opening_materials = __esm({
16695
+ "src/session-opening-materials.ts"() {
16696
+ "use strict";
16697
+ init_packaged_role_registry();
16698
+ packageRootUrl = pathToFileURL2(resolvePackageRootDir() + "/").href;
16699
+ MAIN_ROLE_SESSION_MATERIALS = {
16700
+ ...Object.fromEntries(
16701
+ PUBLIC_ROLE_RECORDS.map((record4) => [record4.role, record4.sessionMaterials])
16702
+ )
16703
+ };
16704
+ GATEKEEPER_SESSION_MATERIALS = {
16705
+ // #639: single authority — the public gatekeeper record owns the province list.
16706
+ gatekeeper: PUBLIC_ROLE_RECORDS.find((entry) => entry.role === "gatekeeper").sessionMaterials,
16707
+ inspector: INSPECTOR_SESSION_MATERIALS,
16708
+ notary: NOTARY_SESSION_MATERIALS
16709
+ };
16710
+ }
16711
+ });
16712
+
16713
+ // src/ticket-seat-memory.ts
16714
+ import { existsSync as existsSync7 } from "node:fs";
16715
+ import { readFile as readFile5, writeFile as writeFile4 } from "node:fs/promises";
16716
+ import { join as join13 } from "node:path";
16717
+ import { pathToFileURL as pathToFileURL3 } from "node:url";
16718
+ function isTicketSeatRunBindingRow(row) {
16719
+ return row.type === "custom" && row.customType === TICKET_SEAT_RUN_BINDING_ENTRY_TYPE;
16720
+ }
16721
+ function ticketSeatRunBindingRunId(row) {
16722
+ if (!isTicketSeatRunBindingRow(row)) return void 0;
16723
+ if (row.data === null || typeof row.data !== "object" || Array.isArray(row.data)) {
16724
+ return void 0;
16725
+ }
16726
+ const runId = row.data.runId;
16727
+ return typeof runId === "string" && runId.length > 0 ? runId : void 0;
16728
+ }
16729
+ async function loadCreateRecordSessionOpen() {
16730
+ const packageRoot2 = resolvePackageRootDir(import.meta.url);
16731
+ const built = join13(packageRoot2, "dist/archivist-record-entry.js");
16732
+ const source = join13(packageRoot2, "src/archivist-record-entry.ts");
16733
+ const target = existsSync7(built) ? built : source;
16734
+ const mod = await import(pathToFileURL3(target).href);
16735
+ return mod.createRecordSessionOpen;
16736
+ }
16737
+ function isTicketSeatMemorySeat(value) {
16738
+ return TICKET_SEAT_MEMORY_SEATS.includes(value);
16739
+ }
16740
+ function isTicketSeatMemoryBound(input) {
16741
+ return isTicketSeatMemorySeat(input.role) && typeof input.ticketNumber === "number" && Number.isSafeInteger(input.ticketNumber) && input.ticketNumber >= 1;
16742
+ }
16743
+ function isEnoent(error) {
16744
+ return error instanceof Error && "code" in error && error.code === "ENOENT";
16745
+ }
16746
+ function ticketSeatMemorySubject(ticketNumber, seat) {
16747
+ if (!Number.isSafeInteger(ticketNumber) || ticketNumber < 1) {
16748
+ throw new Error(
16749
+ `ticket-seat memory subject requires a positive ticket number, got ${String(ticketNumber)}`
16750
+ );
16751
+ }
16752
+ return `${ticketNumber}:${seat}`;
16753
+ }
16754
+ function ticketSeatMemorySessionDirectory(input) {
16755
+ return subjectKeyedRecordDirectory({
16756
+ cwd: input.cwd,
16757
+ kind: TICKET_SEAT_MEMORY_KIND,
16758
+ subject: ticketSeatMemorySubject(input.ticketNumber, input.seat),
16759
+ ...input.parentSessionFile === void 0 ? {} : { parentSessionFile: input.parentSessionFile },
16760
+ ...input.home === void 0 ? {} : { home: input.home }
16761
+ });
16762
+ }
16763
+ async function readRunAdmittedPageFacts(runDirectory) {
16764
+ try {
16765
+ const raw = JSON.parse(
16766
+ await readFile5(join13(runDirectory, "admitted-request.json"), "utf8")
16767
+ );
16768
+ if (raw === null || typeof raw !== "object" || Array.isArray(raw)) {
16769
+ return {};
16770
+ }
16771
+ const record4 = raw;
16772
+ const ticketNumber = record4.ticketNumber;
16773
+ const projectRoot = record4.projectRoot;
16774
+ return {
16775
+ ...typeof ticketNumber === "number" && Number.isSafeInteger(ticketNumber) && ticketNumber >= 1 ? { ticketNumber } : {},
16776
+ ...typeof projectRoot === "string" ? { projectRoot } : {}
16777
+ };
16778
+ } catch (error) {
16779
+ if (isEnoent(error)) return {};
16780
+ throw error;
16781
+ }
16782
+ }
16783
+ async function readInvocationTicketNumber(runDirectory) {
16784
+ try {
16785
+ const raw = JSON.parse(
16786
+ await readFile5(join13(runDirectory, "invocation.json"), "utf8")
16787
+ );
16788
+ if (raw === null || typeof raw !== "object" || Array.isArray(raw)) {
16789
+ return void 0;
16790
+ }
16791
+ const ticketNumber = raw.ticketNumber;
16792
+ if (typeof ticketNumber === "number" && Number.isSafeInteger(ticketNumber) && ticketNumber >= 1) {
16793
+ return ticketNumber;
16794
+ }
16795
+ } catch (error) {
16796
+ if (isEnoent(error)) return void 0;
16797
+ throw error;
16798
+ }
16799
+ return void 0;
16800
+ }
16801
+ async function readRunTicketNumber(runDirectory) {
16802
+ const admitted = await readRunAdmittedPageFacts(runDirectory);
16803
+ if (admitted.ticketNumber !== void 0) return admitted.ticketNumber;
16804
+ return readInvocationTicketNumber(runDirectory);
16805
+ }
16806
+ async function resolveTicketSeatMemoryNestDirectories(input) {
16807
+ if (input.seats.length === 0) return [];
16808
+ const admitted = await readRunAdmittedPageFacts(input.runDirectory);
16809
+ const ticketNumber = admitted.ticketNumber ?? await readInvocationTicketNumber(input.runDirectory);
16810
+ if (ticketNumber === void 0) return [];
16811
+ let home;
16812
+ try {
16813
+ home = homeFromRunDirectory(input.runDirectory);
16814
+ } catch {
16815
+ return [];
16816
+ }
16817
+ const projectRoot = admitted.projectRoot;
16818
+ if (projectRoot === void 0) return [];
16819
+ return input.seats.map(
16820
+ (seat) => ticketSeatMemorySessionDirectory({
16821
+ ticketNumber,
16822
+ seat,
16823
+ cwd: projectRoot,
16824
+ home
16825
+ })
16826
+ );
16827
+ }
16828
+ async function openTicketSeatMemoryCoordinates(input) {
16829
+ const createRecordSessionOpen = await loadCreateRecordSessionOpen();
16830
+ const opened = createRecordSessionOpen({
16831
+ cwd: input.cwd,
16832
+ kind: TICKET_SEAT_MEMORY_KIND,
16833
+ subject: ticketSeatMemorySubject(input.ticketNumber, input.seat),
16834
+ parent: {
16835
+ getSessionFile: () => input.ledgerAnchorSessionFile
16836
+ }
16837
+ });
16838
+ if (input.runId !== void 0) {
16839
+ const data = { version: 1, runId: input.runId };
16840
+ opened.session.appendCustomEntry(TICKET_SEAT_RUN_BINDING_ENTRY_TYPE, data);
16841
+ }
16842
+ const sessionFile = opened.session.getSessionFile();
16843
+ const sessionDirectory = opened.session.getSessionDir();
16844
+ if (typeof sessionFile !== "string" || sessionFile.length === 0) {
16845
+ throw new Error(
16846
+ `ticket-seat memory principal missing session file for ticket #${input.ticketNumber} seat ${input.seat}`
16847
+ );
16848
+ }
16849
+ if (typeof sessionDirectory !== "string" || sessionDirectory.length === 0) {
16850
+ throw new Error(
16851
+ `ticket-seat memory principal missing session directory for ticket #${input.ticketNumber} seat ${input.seat}`
16852
+ );
16853
+ }
16854
+ return { sessionDirectory, sessionFile, resumed: opened.resumed };
16855
+ }
16856
+ async function rebindAdmittedToTicketSeatMemory(input) {
16857
+ const ticketNumber = input.admitted.ticketNumber;
16858
+ if (ticketNumber === void 0) return void 0;
16859
+ const anchor = input.principalAuthority.decode(input.admitted.principal);
16860
+ const opened = await openTicketSeatMemoryCoordinates({
16861
+ ticketNumber,
16862
+ seat: input.seat,
16863
+ cwd: input.admitted.projectRoot,
16864
+ ledgerAnchorSessionFile: anchor.sessionFile,
16865
+ // Analyst attributes frame/model/tool to this binding interval only (#636 D).
16866
+ runId: input.admitted.runId
16867
+ });
16868
+ const coordinates = {
16869
+ sessionDirectory: opened.sessionDirectory,
16870
+ sessionFile: opened.sessionFile
16871
+ };
16872
+ const principal = input.principalAuthority.seal(coordinates);
16873
+ input.principalAuthority.decode(principal);
16874
+ input.admitted.principal = principal;
16875
+ for (const page of ["admitted-request.json", "invocation.json"]) {
16876
+ const path = join13(input.admitted.runDirectory, page);
16877
+ try {
16878
+ const raw = JSON.parse(await readFile5(path, "utf8"));
16879
+ if (raw === null || typeof raw !== "object" || Array.isArray(raw)) continue;
16880
+ const next = {
16881
+ ...raw,
16882
+ sessionDirectory: coordinates.sessionDirectory,
16883
+ sessionFile: coordinates.sessionFile
16884
+ };
16885
+ await writeFile4(path, `${JSON.stringify(next, null, 2)}
16886
+ `, "utf8");
16887
+ } catch (error) {
16888
+ if (error instanceof Error && "code" in error && error.code === "ENOENT") {
16889
+ continue;
16890
+ }
16891
+ throw error;
16892
+ }
16893
+ }
16894
+ return { coordinates, resumed: opened.resumed };
16895
+ }
16896
+ async function readTicketSeatMemoryLastHost(sessionDirectory) {
16897
+ try {
16898
+ const raw = JSON.parse(
16899
+ await readFile5(join13(sessionDirectory, TICKET_SEAT_LAST_HOST_FILE), "utf8")
16900
+ );
16901
+ if (raw === null || typeof raw !== "object" || Array.isArray(raw) || typeof raw.host !== "string" || raw.host.length === 0) {
16902
+ throw new Error(
16903
+ `ticket-seat memory last-host page is damaged under ${sessionDirectory}`
16904
+ );
16905
+ }
16906
+ const host = raw.host;
16907
+ const runDirectory = raw.runDirectory;
16908
+ return {
16909
+ host,
16910
+ ...typeof runDirectory === "string" && runDirectory.length > 0 ? { runDirectory } : {}
16911
+ };
16912
+ } catch (error) {
16913
+ if (error instanceof Error && "code" in error && error.code === "ENOENT") {
16914
+ return void 0;
16915
+ }
16916
+ throw error;
16917
+ }
16918
+ }
16919
+ async function writeTicketSeatMemoryLastHost(sessionDirectory, host, runDirectory) {
16920
+ if (host.trim() === "") {
16921
+ throw new Error("ticket-seat memory last-host requires a non-empty host");
16922
+ }
16923
+ const body = {
16924
+ host,
16925
+ ...runDirectory !== void 0 && runDirectory.length > 0 ? { runDirectory } : {}
16926
+ };
16927
+ await writeFile4(
16928
+ join13(sessionDirectory, TICKET_SEAT_LAST_HOST_FILE),
16929
+ `${JSON.stringify(body, null, 2)}
16930
+ `,
16931
+ "utf8"
16932
+ );
16933
+ }
16934
+ var TICKET_SEAT_RUN_BINDING_ENTRY_TYPE, TICKET_SEAT_MEMORY_KIND, TICKET_SEAT_MEMORY_SEATS, TICKET_SEAT_LAST_HOST_FILE;
16935
+ var init_ticket_seat_memory = __esm({
16936
+ "src/ticket-seat-memory.ts"() {
16937
+ "use strict";
16938
+ init_activation_ledger_topology();
16939
+ init_archivist_record_topology();
16940
+ init_session_opening_materials();
16941
+ TICKET_SEAT_RUN_BINDING_ENTRY_TYPE = "ak_ticket_seat_run_binding";
16942
+ TICKET_SEAT_MEMORY_KIND = "auditor-roles";
16943
+ TICKET_SEAT_MEMORY_SEATS = ["inspector", "notary", "auditor"];
16944
+ TICKET_SEAT_LAST_HOST_FILE = "last-host.json";
16945
+ }
16946
+ });
16947
+
16651
16948
  // src/audit-escalation.ts
16652
16949
  function isAuditEscalationResult(value) {
16653
16950
  if (typeof value !== "object" || value === null || Array.isArray(value)) {
@@ -16832,8 +17129,8 @@ var init_terminating_tools = __esm({
16832
17129
  });
16833
17130
 
16834
17131
  // src/doctor-evidence.ts
16835
- import { readdir, readFile as readFile5, realpath as realpath2, stat } from "node:fs/promises";
16836
- import { dirname as dirname6, relative as relative2, resolve as resolve5, sep as sep2 } from "node:path";
17132
+ import { readdir, readFile as readFile6, realpath as realpath2, stat } from "node:fs/promises";
17133
+ import { dirname as dirname7, relative as relative2, resolve as resolve5, sep as sep2 } from "node:path";
16837
17134
  function record2(value) {
16838
17135
  return typeof value === "object" && value !== null && !Array.isArray(value);
16839
17136
  }
@@ -16873,7 +17170,7 @@ async function stableRunsIdentity(root) {
16873
17170
  } catch (error) {
16874
17171
  if (!isMissingPathError(error)) throw error;
16875
17172
  }
16876
- const parent = dirname6(cursor);
17173
+ const parent = dirname7(cursor);
16877
17174
  if (parent === cursor) return root;
16878
17175
  cursor = parent;
16879
17176
  }
@@ -16952,7 +17249,7 @@ async function loadDoctorCase(runsPath) {
16952
17249
  const turns = { count: 0, sources: [] }, calls = { count: 0, sources: [] }, tokens = { count: 0, sources: [] };
16953
17250
  for (const path of await discoverCaseFiles(root)) {
16954
17251
  const id = relative2(root, path).split(sep2).join("/");
16955
- const bytes = await readFile5(path);
17252
+ const bytes = await readFile6(path);
16956
17253
  const content = bytes.toString("utf8");
16957
17254
  const kind = id.endsWith(".jsonl") ? "session" : "stderr";
16958
17255
  evidence.push({ id, kind, byteLength: bytes.byteLength, contentLength: content.length, sha256: sha256Hex(bytes), content });
@@ -16983,8 +17280,8 @@ var init_doctor_evidence = __esm({
16983
17280
  });
16984
17281
 
16985
17282
  // src/collector-config.ts
16986
- import { createHash as createHash3 } from "node:crypto";
16987
- import { readFile as readFile6 } from "node:fs/promises";
17283
+ import { createHash as createHash4 } from "node:crypto";
17284
+ import { readFile as readFile7 } from "node:fs/promises";
16988
17285
  function fail3(message, cause) {
16989
17286
  throw new Error(message, cause === void 0 ? void 0 : { cause });
16990
17287
  }
@@ -17022,12 +17319,12 @@ function canonicalManifest(requests) {
17022
17319
  }
17023
17320
  function emptyCollectorManifest() {
17024
17321
  const canonicalJson2 = canonicalManifest([]);
17025
- return { requests: [], canonicalJson: canonicalJson2, digest: createHash3("sha256").update(canonicalJson2).digest("hex") };
17322
+ return { requests: [], canonicalJson: canonicalJson2, digest: createHash4("sha256").update(canonicalJson2).digest("hex") };
17026
17323
  }
17027
17324
  async function loadCollectorManifest(path) {
17028
17325
  let bytes;
17029
17326
  try {
17030
- bytes = await readFile6(path);
17327
+ bytes = await readFile7(path);
17031
17328
  } catch (error) {
17032
17329
  fail3(`Collector request manifest is unreadable at ${path}`, error);
17033
17330
  }
@@ -17049,7 +17346,7 @@ async function loadCollectorManifest(path) {
17049
17346
  requests.push({ id: item.id, requestBody: item.body });
17050
17347
  }
17051
17348
  const canonicalJson2 = canonicalManifest(requests);
17052
- return { requests, canonicalJson: canonicalJson2, digest: createHash3("sha256").update(canonicalJson2).digest("hex"), sourcePath: path };
17349
+ return { requests, canonicalJson: canonicalJson2, digest: createHash4("sha256").update(canonicalJson2).digest("hex"), sourcePath: path };
17053
17350
  }
17054
17351
  var COLLECTOR_OWNER_PATTERN, COLLECTOR_REPO_PATTERN, COLLECTOR_FIXED_KICKOFF;
17055
17352
  var init_collector_config = __esm({
@@ -17162,10 +17459,10 @@ var init_uuidv7 = __esm({
17162
17459
  });
17163
17460
 
17164
17461
  // src/typed-provider-http.ts
17165
- import { readFile as readFile7, unlink, writeFile as writeFile4 } from "node:fs/promises";
17166
- import { join as join11 } from "node:path";
17462
+ import { readFile as readFile8, unlink, writeFile as writeFile5 } from "node:fs/promises";
17463
+ import { join as join14 } from "node:path";
17167
17464
  function typedProviderHttpPath(runDirectory) {
17168
- return join11(runDirectory, TYPED_HTTP_FILE);
17465
+ return join14(runDirectory, TYPED_HTTP_FILE);
17169
17466
  }
17170
17467
  async function clearTypedProviderHttpObservation(runDirectory) {
17171
17468
  try {
@@ -17180,7 +17477,7 @@ async function clearTypedProviderHttpObservation(runDirectory) {
17180
17477
  async function readLatestTypedProviderHttpObservation(runDirectory) {
17181
17478
  let text;
17182
17479
  try {
17183
- text = await readFile7(typedProviderHttpPath(runDirectory), "utf8");
17480
+ text = await readFile8(typedProviderHttpPath(runDirectory), "utf8");
17184
17481
  } catch (error) {
17185
17482
  if (error instanceof Error && "code" in error && error.code === "ENOENT") {
17186
17483
  return void 0;
@@ -17209,8 +17506,8 @@ var init_typed_provider_http = __esm({
17209
17506
  });
17210
17507
 
17211
17508
  // src/public-cli/run-lifecycle.ts
17212
- import { chmod, open, readdir as readdir2, readFile as readFile8, unlink as unlink2, writeFile as writeFile5 } from "node:fs/promises";
17213
- import { join as join12 } from "node:path";
17509
+ import { chmod, open, readdir as readdir2, readFile as readFile9, unlink as unlink2, writeFile as writeFile6 } from "node:fs/promises";
17510
+ import { join as join15 } from "node:path";
17214
17511
  function selectResumeContinuationPrompt(message, engineMaterial) {
17215
17512
  const base = message !== void 0 ? message : RESUME_TRANSPORT_ENVELOPE;
17216
17513
  return appendEngineSessionMaterial([base], engineMaterial).join("\n");
@@ -17239,8 +17536,8 @@ function renderResumeCommand(runId) {
17239
17536
  }
17240
17537
  async function writeRoleRunState(runDirectory, record4) {
17241
17538
  const payload = { ...record4, runDirectory };
17242
- await writeFile5(
17243
- join12(runDirectory, RUN_STATE_FILE),
17539
+ await writeFile6(
17540
+ join15(runDirectory, RUN_STATE_FILE),
17244
17541
  `${JSON.stringify(payload, null, 2)}
17245
17542
  `,
17246
17543
  "utf8"
@@ -17249,7 +17546,7 @@ async function writeRoleRunState(runDirectory, record4) {
17249
17546
  async function readRoleRunStateDisk(runDirectory) {
17250
17547
  let raw;
17251
17548
  try {
17252
- raw = JSON.parse(await readFile8(join12(runDirectory, RUN_STATE_FILE), "utf8"));
17549
+ raw = JSON.parse(await readFile9(join15(runDirectory, RUN_STATE_FILE), "utf8"));
17253
17550
  } catch {
17254
17551
  return void 0;
17255
17552
  }
@@ -17312,8 +17609,8 @@ async function writeRoleRunStateDisk(runDirectory, disk) {
17312
17609
  ...disk.phase === void 0 ? {} : { phase: disk.phase },
17313
17610
  ...disk.resumable === void 0 ? {} : { resumable: disk.resumable }
17314
17611
  };
17315
- await writeFile5(
17316
- join12(runDirectory, RUN_STATE_FILE),
17612
+ await writeFile6(
17613
+ join15(runDirectory, RUN_STATE_FILE),
17317
17614
  `${JSON.stringify(payload, null, 2)}
17318
17615
  `,
17319
17616
  "utf8"
@@ -17443,7 +17740,7 @@ function isProcessAlive(pid) {
17443
17740
  async function autopsyWriterLock(lockPath) {
17444
17741
  let content;
17445
17742
  try {
17446
- content = await readFile8(lockPath, "utf8");
17743
+ content = await readFile9(lockPath, "utf8");
17447
17744
  } catch (error) {
17448
17745
  if (errorCodeOf2(error) === "ENOENT") return { verdict: "absent" };
17449
17746
  return { verdict: "absent", readFailure: error };
@@ -17522,15 +17819,15 @@ async function acquireRunWriterLease(runDirectory, onCleanupFailure) {
17522
17819
  };
17523
17820
  const reportCleanupFailure = (error) => {
17524
17821
  reportDiagnostic(
17525
- `writer lease lock cleanup failed (release is best-effort; residual lock left in place) at ${join12(runDirectory, WRITER_LOCK_FILE)}: ${describeErrorIdentity(error)}`
17822
+ `writer lease lock cleanup failed (release is best-effort; residual lock left in place) at ${join15(runDirectory, WRITER_LOCK_FILE)}: ${describeErrorIdentity(error)}`
17526
17823
  );
17527
17824
  };
17528
17825
  const reportReadFailure = (error) => {
17529
17826
  reportDiagnostic(
17530
- `writer lease lock read failed (holder liveness unverifiable; lock left in place) at ${join12(runDirectory, WRITER_LOCK_FILE)}: ${describeErrorIdentity(error)}`
17827
+ `writer lease lock read failed (holder liveness unverifiable; lock left in place) at ${join15(runDirectory, WRITER_LOCK_FILE)}: ${describeErrorIdentity(error)}`
17531
17828
  );
17532
17829
  };
17533
- const lockPath = join12(runDirectory, WRITER_LOCK_FILE);
17830
+ const lockPath = join15(runDirectory, WRITER_LOCK_FILE);
17534
17831
  let lastAutopsy = { verdict: "absent" };
17535
17832
  let lastReclaimFailure;
17536
17833
  for (let reclaimsLeft = WRITER_LEASE_RECLAIM_ROUNDS; ; reclaimsLeft -= 1) {
@@ -17580,7 +17877,7 @@ async function acquireRunWriterLease(runDirectory, onCleanupFailure) {
17580
17877
  async function findRunDirectoryById(home, runId) {
17581
17878
  if (runId.trim() === "") return void 0;
17582
17879
  const ledgerHome = resolveActivationLedgerHome(home);
17583
- const booksRoot = join12(ledgerHome, "books");
17880
+ const booksRoot = join15(ledgerHome, "books");
17584
17881
  let bookKeys;
17585
17882
  try {
17586
17883
  bookKeys = await readdir2(booksRoot);
@@ -17588,7 +17885,7 @@ async function findRunDirectoryById(home, runId) {
17588
17885
  return void 0;
17589
17886
  }
17590
17887
  for (const bookKey of bookKeys) {
17591
- const runsDir = join12(activationBookDirectory(ledgerHome, bookKey), "runs");
17888
+ const runsDir = join15(activationBookDirectory(ledgerHome, bookKey), "runs");
17592
17889
  let entries;
17593
17890
  try {
17594
17891
  entries = await readdir2(runsDir);
@@ -17597,7 +17894,7 @@ async function findRunDirectoryById(home, runId) {
17597
17894
  }
17598
17895
  for (const entry of entries) {
17599
17896
  if (entry === `${runId}@judge` || entry.startsWith(`${runId}@`)) {
17600
- return join12(runsDir, entry);
17897
+ return join15(runsDir, entry);
17601
17898
  }
17602
17899
  }
17603
17900
  }
@@ -17666,7 +17963,7 @@ async function loadResumableRunRecord(home, runId, authority) {
17666
17963
  let sourceRun;
17667
17964
  try {
17668
17965
  const raw = JSON.parse(
17669
- await readFile8(run.admittedRequestPath, "utf8")
17966
+ await readFile9(run.admittedRequestPath, "utf8")
17670
17967
  );
17671
17968
  if (raw !== null && typeof raw === "object" && !Array.isArray(raw)) {
17672
17969
  const record4 = raw;
@@ -17779,7 +18076,7 @@ async function loadResumableRunRecord(home, runId, authority) {
17779
18076
  let model;
17780
18077
  try {
17781
18078
  const invocationRaw = JSON.parse(
17782
- await readFile8(join12(run.runDirectory, "invocation.json"), "utf8")
18079
+ await readFile9(join15(run.runDirectory, "invocation.json"), "utf8")
17783
18080
  );
17784
18081
  if (invocationRaw !== null && typeof invocationRaw === "object" && !Array.isArray(invocationRaw)) {
17785
18082
  const rec = invocationRaw;
@@ -18171,7 +18468,7 @@ var init_run_lifecycle = __esm({
18171
18468
  });
18172
18469
 
18173
18470
  // src/notary-source-run.ts
18174
- import { dirname as dirname7, isAbsolute as isAbsolute4, join as join13, resolve as resolve6, basename as basename4 } from "node:path";
18471
+ import { dirname as dirname8, isAbsolute as isAbsolute4, join as join16, resolve as resolve6, basename as basename4 } from "node:path";
18175
18472
  import { lstat as lstat2, realpath as realpath3 } from "node:fs/promises";
18176
18473
  function parseRunDirectoryName(name) {
18177
18474
  const match = RUN_DIR_NAME.exec(name);
@@ -18217,18 +18514,18 @@ async function resolveNotarySourceRunLocator(options) {
18217
18514
  }
18218
18515
  const ledgerHome = resolveActivationLedgerHome(options.home);
18219
18516
  const bookKey = resolveBookKeyFromGit(options.projectRoot);
18220
- const bookRunsRoot = join13(activationBookDirectory(ledgerHome, bookKey), "runs");
18517
+ const bookRunsRoot = join16(activationBookDirectory(ledgerHome, bookKey), "runs");
18221
18518
  let candidate;
18222
18519
  const bare = parseRunDirectoryName(raw);
18223
18520
  if (bare !== void 0 && !raw.includes("/") && !raw.includes("\\")) {
18224
- candidate = join13(bookRunsRoot, `${bare.runId}@${bare.role}`);
18521
+ candidate = join16(bookRunsRoot, `${bare.runId}@${bare.role}`);
18225
18522
  } else {
18226
18523
  candidate = isAbsolute4(raw) ? raw : resolve6(options.projectRoot, raw);
18227
18524
  }
18228
18525
  const real = await requireRunDirectory(candidate, raw);
18229
18526
  const identity = parseRunDirectoryName(basename4(real));
18230
18527
  const runsRootIdentity = physicalPathIdentity(bookRunsRoot);
18231
- const parentIdentity = physicalPathIdentity(dirname7(real));
18528
+ const parentIdentity = physicalPathIdentity(dirname8(real));
18232
18529
  if (parentIdentity !== runsRootIdentity) {
18233
18530
  throw new NotarySourceRunError(
18234
18531
  "notary --source-run must resolve to a retained run under the project machine-ledger book"
@@ -19250,15 +19547,15 @@ import { execFileSync as execFileSync2 } from "node:child_process";
19250
19547
  import {
19251
19548
  lstat as lstat3,
19252
19549
  mkdir as mkdir2,
19253
- readFile as readFile9,
19550
+ readFile as readFile10,
19254
19551
  realpath as realpath4,
19255
- writeFile as writeFile6
19552
+ writeFile as writeFile7
19256
19553
  } from "node:fs/promises";
19257
- import { basename as basename5, isAbsolute as isAbsolute5, join as join14, resolve as resolve7, sep as sep3 } from "node:path";
19554
+ import { basename as basename5, isAbsolute as isAbsolute5, join as join17, resolve as resolve7, sep as sep3 } from "node:path";
19258
19555
  function issueAdmissionPlacement(authority, request) {
19259
19556
  const principal = authority.issue(request);
19260
19557
  const { sessionDirectory, sessionFile } = authority.decode(principal);
19261
- const runDirectory = join14(sessionDirectory, "..");
19558
+ const runDirectory = join17(sessionDirectory, "..");
19262
19559
  const ledgerHome = resolveActivationLedgerHome(request.home);
19263
19560
  const bookKey = resolveBookKeyFromGit(request.cwd);
19264
19561
  return {
@@ -19277,7 +19574,7 @@ async function writeAdmittedRequestPersistence(admittedRequestPath, body, coordi
19277
19574
  sessionDirectory: coordinates.sessionDirectory,
19278
19575
  sessionFile: coordinates.sessionFile
19279
19576
  };
19280
- await writeFile6(
19577
+ await writeFile7(
19281
19578
  admittedRequestPath,
19282
19579
  `${JSON.stringify(projection, null, 2)}
19283
19580
  `,
@@ -19305,8 +19602,8 @@ async function writeRoleInvocationLedger(source, role, effectiveModel) {
19305
19602
  ...source.ticketNumber === void 0 ? {} : { ticketNumber: source.ticketNumber },
19306
19603
  ...effectiveModelLedgerFields(effectiveModel)
19307
19604
  };
19308
- await writeFile6(
19309
- join14(source.runDirectory, "invocation.json"),
19605
+ await writeFile7(
19606
+ join17(source.runDirectory, "invocation.json"),
19310
19607
  `${JSON.stringify(identity, null, 2)}
19311
19608
  `,
19312
19609
  "utf8"
@@ -19317,8 +19614,8 @@ async function writeRoleInvocationLedger(source, role, effectiveModel) {
19317
19614
  await writeInstitutionalResolutionPage(source.runDirectory, institutionalPage);
19318
19615
  }
19319
19616
  async function recordEffectiveInvocationModel(runDirectory, model, engine, host) {
19320
- const ledgerPath = join14(runDirectory, "invocation.json");
19321
- const current = JSON.parse(await readFile9(ledgerPath, "utf8"));
19617
+ const ledgerPath = join17(runDirectory, "invocation.json");
19618
+ const current = JSON.parse(await readFile10(ledgerPath, "utf8"));
19322
19619
  const next = { ...current };
19323
19620
  if (model !== void 0) {
19324
19621
  next.provider = model.provider;
@@ -19337,7 +19634,7 @@ async function recordEffectiveInvocationModel(runDirectory, model, engine, host)
19337
19634
  if (host !== void 0) {
19338
19635
  next.host = host;
19339
19636
  }
19340
- await writeFile6(
19637
+ await writeFile7(
19341
19638
  ledgerPath,
19342
19639
  `${JSON.stringify(next, null, 2)}
19343
19640
  `,
@@ -19354,9 +19651,9 @@ async function recordEffectiveInvocationModel(runDirectory, model, engine, host)
19354
19651
  await writeInstitutionalResolutionPage(runDirectory, institutionalPage);
19355
19652
  }
19356
19653
  async function mergeInvocationIdentityPage(runDirectory, fields) {
19357
- const ledgerPath = join14(runDirectory, "invocation.json");
19358
- const current = JSON.parse(await readFile9(ledgerPath, "utf8"));
19359
- await writeFile6(
19654
+ const ledgerPath = join17(runDirectory, "invocation.json");
19655
+ const current = JSON.parse(await readFile10(ledgerPath, "utf8"));
19656
+ await writeFile7(
19360
19657
  ledgerPath,
19361
19658
  `${JSON.stringify({
19362
19659
  ...current,
@@ -19384,8 +19681,8 @@ async function bindAdmittedTicketNumber(admitted, ticketNumber) {
19384
19681
  admitted.ticketNumber = ticketNumber;
19385
19682
  await mergeInvocationIdentityPage(admitted.runDirectory, { ticketNumber });
19386
19683
  const admittedPath = admitted.admittedRequestPath;
19387
- const current = JSON.parse(await readFile9(admittedPath, "utf8"));
19388
- await writeFile6(
19684
+ const current = JSON.parse(await readFile10(admittedPath, "utf8"));
19685
+ await writeFile7(
19389
19686
  admittedPath,
19390
19687
  `${JSON.stringify({ ...current, ticketNumber }, null, 2)}
19391
19688
  `,
@@ -19404,8 +19701,8 @@ async function recordTrueUnboundTicketResolution(admitted) {
19404
19701
  ticketResolution: "true-unbound"
19405
19702
  });
19406
19703
  const admittedPath = admitted.admittedRequestPath;
19407
- const current = JSON.parse(await readFile9(admittedPath, "utf8"));
19408
- await writeFile6(
19704
+ const current = JSON.parse(await readFile10(admittedPath, "utf8"));
19705
+ await writeFile7(
19409
19706
  admittedPath,
19410
19707
  `${JSON.stringify({ ...current, ticketResolution: "true-unbound" }, null, 2)}
19411
19708
  `,
@@ -19421,7 +19718,7 @@ async function recordLaunchedPiIdentity(runDirectory, identity) {
19421
19718
  async function observeLaunchedRolePackageIdentity(packageRoot2, selectedRoleEntry) {
19422
19719
  const rolePackageRoot = packageRoot2;
19423
19720
  const raw = JSON.parse(
19424
- await readFile9(join14(rolePackageRoot, "package.json"), "utf8")
19721
+ await readFile10(join17(rolePackageRoot, "package.json"), "utf8")
19425
19722
  );
19426
19723
  if (typeof raw.version !== "string" || raw.version.trim() === "") {
19427
19724
  throw new Error(
@@ -19638,10 +19935,10 @@ async function freezeRegularFileAttachment(sourcePath, destinationDir, index) {
19638
19935
  `attachment must be a regular file (not a directory or symlink): ${sourcePath}`
19639
19936
  );
19640
19937
  }
19641
- const bytes = await readFile9(absolute);
19938
+ const bytes = await readFile10(absolute);
19642
19939
  const name = `${String(index).padStart(2, "0")}-${basename5(absolute)}`;
19643
- const frozenPath = join14(destinationDir, name);
19644
- await writeFile6(frozenPath, bytes);
19940
+ const frozenPath = join17(destinationDir, name);
19941
+ await writeFile7(frozenPath, bytes);
19645
19942
  return {
19646
19943
  attachment: {
19647
19944
  provenancePath: absolute,
@@ -19666,20 +19963,7 @@ async function freezeAttachments(attachmentPaths, attachmentsDirectory) {
19666
19963
  return attachments;
19667
19964
  }
19668
19965
  async function readTicketNumberFromSourceRun(runDirectory) {
19669
- for (const page of ["admitted-request.json", "invocation.json"]) {
19670
- try {
19671
- const raw = JSON.parse(
19672
- await readFile9(join14(runDirectory, page), "utf8")
19673
- );
19674
- if (raw === null || typeof raw !== "object" || Array.isArray(raw)) continue;
19675
- const ticketNumber = raw.ticketNumber;
19676
- if (typeof ticketNumber === "number" && Number.isSafeInteger(ticketNumber) && ticketNumber >= 1) {
19677
- return ticketNumber;
19678
- }
19679
- } catch {
19680
- }
19681
- }
19682
- return void 0;
19966
+ return readRunTicketNumber(runDirectory);
19683
19967
  }
19684
19968
  function ticketAdmissionFields(ticketNumber) {
19685
19969
  return ticketNumber === void 0 ? {} : { ticketNumber };
@@ -19703,7 +19987,7 @@ async function admitStandardMaterialInvocation(role, options) {
19703
19987
  role,
19704
19988
  home: options.home
19705
19989
  });
19706
- const attachmentsDirectory = join14(runDirectory, "attachments");
19990
+ const attachmentsDirectory = join17(runDirectory, "attachments");
19707
19991
  ensureRealDirectoryTree(ledgerHome, sessionDirectory);
19708
19992
  ensureRealDirectoryTree(ledgerHome, attachmentsDirectory);
19709
19993
  const attachments = await freezeAttachments(options.attachmentPaths, attachmentsDirectory);
@@ -19728,7 +20012,7 @@ async function admitStandardMaterialInvocation(role, options) {
19728
20012
  mediaKind: a.mediaKind
19729
20013
  }))
19730
20014
  };
19731
- const admittedRequestPath = join14(runDirectory, "admitted-request.json");
20015
+ const admittedRequestPath = join17(runDirectory, "admitted-request.json");
19732
20016
  await writeAdmittedRequestPersistence(admittedRequestPath, admitted, {
19733
20017
  sessionDirectory,
19734
20018
  sessionFile
@@ -19800,7 +20084,7 @@ async function admitCountersignInvocation(options) {
19800
20084
  role: "countersign",
19801
20085
  home: options.home
19802
20086
  });
19803
- const attachmentsDirectory = join14(runDirectory, "attachments");
20087
+ const attachmentsDirectory = join17(runDirectory, "attachments");
19804
20088
  ensureRealDirectoryTree(ledgerHome, sessionDirectory);
19805
20089
  ensureRealDirectoryTree(ledgerHome, attachmentsDirectory);
19806
20090
  const attachments = await freezeAttachments(options.attachmentPaths, attachmentsDirectory);
@@ -19824,7 +20108,7 @@ async function admitCountersignInvocation(options) {
19824
20108
  mediaKind: a.mediaKind
19825
20109
  }))
19826
20110
  };
19827
- const admittedRequestPath = join14(runDirectory, "admitted-request.json");
20111
+ const admittedRequestPath = join17(runDirectory, "admitted-request.json");
19828
20112
  await writeAdmittedRequestPersistence(admittedRequestPath, admitted, {
19829
20113
  sessionDirectory,
19830
20114
  sessionFile
@@ -19848,7 +20132,7 @@ function buildCountersignTransportPrompt(admitted, engineMaterial) {
19848
20132
  return buildInstructionTransportPrompt(admitted, engineMaterial);
19849
20133
  }
19850
20134
  async function ensureRunArtifactsDir(runDirectory) {
19851
- const dir = join14(runDirectory, "artifacts");
20135
+ const dir = join17(runDirectory, "artifacts");
19852
20136
  await mkdir2(dir, { recursive: true });
19853
20137
  return dir;
19854
20138
  }
@@ -19880,12 +20164,12 @@ async function admitCoderInvocation(options) {
19880
20164
  role: "coder",
19881
20165
  home: options.home
19882
20166
  });
19883
- const attachmentsDirectory = join14(runDirectory, "attachments");
20167
+ const attachmentsDirectory = join17(runDirectory, "attachments");
19884
20168
  ensureRealDirectoryTree(ledgerHome, sessionDirectory);
19885
20169
  ensureRealDirectoryTree(ledgerHome, attachmentsDirectory);
19886
20170
  const attachments = await freezeAttachments(options.attachmentPaths, attachmentsDirectory);
19887
- const taskPath = join14(runDirectory, "task.md");
19888
- await writeFile6(taskPath, instruction, "utf8");
20171
+ const taskPath = join17(runDirectory, "task.md");
20172
+ await writeFile7(taskPath, instruction, "utf8");
19889
20173
  const admitted = {
19890
20174
  role: "coder",
19891
20175
  phase: options.phase,
@@ -19905,7 +20189,7 @@ async function admitCoderInvocation(options) {
19905
20189
  mediaKind: a.mediaKind
19906
20190
  }))
19907
20191
  };
19908
- const admittedRequestPath = join14(runDirectory, "admitted-request.json");
20192
+ const admittedRequestPath = join17(runDirectory, "admitted-request.json");
19909
20193
  await writeAdmittedRequestPersistence(admittedRequestPath, admitted, {
19910
20194
  sessionDirectory,
19911
20195
  sessionFile
@@ -19955,7 +20239,7 @@ async function admitFixerInvocation(options) {
19955
20239
  if (options.prerequisitesPath !== void 0) {
19956
20240
  const absolutePrereq = isAbsolute5(options.prerequisitesPath) ? options.prerequisitesPath : resolve7(options.prerequisitesPath);
19957
20241
  try {
19958
- prerequisitesSource = await readFile9(absolutePrereq, "utf8");
20242
+ prerequisitesSource = await readFile10(absolutePrereq, "utf8");
19959
20243
  } catch (error) {
19960
20244
  throw new CliUsageError(
19961
20245
  `fixer prerequisites path is unreadable: ${options.prerequisitesPath}`,
@@ -19986,22 +20270,22 @@ async function admitFixerInvocation(options) {
19986
20270
  role: "fixer",
19987
20271
  home: options.home
19988
20272
  });
19989
- const attachmentsDirectory = join14(runDirectory, "attachments");
20273
+ const attachmentsDirectory = join17(runDirectory, "attachments");
19990
20274
  ensureRealDirectoryTree(ledgerHome, sessionDirectory);
19991
20275
  ensureRealDirectoryTree(ledgerHome, attachmentsDirectory);
19992
20276
  const attachments = await freezeAttachments(options.attachmentPaths, attachmentsDirectory);
19993
20277
  let prerequisitesPath;
19994
20278
  if (prerequisitesSource !== void 0) {
19995
- prerequisitesPath = join14(runDirectory, "prerequisites.json");
19996
- await writeFile6(
20279
+ prerequisitesPath = join17(runDirectory, "prerequisites.json");
20280
+ await writeFile7(
19997
20281
  prerequisitesPath,
19998
20282
  `${JSON.stringify(prerequisites, null, 2)}
19999
20283
  `,
20000
20284
  "utf8"
20001
20285
  );
20002
20286
  }
20003
- const packetPath = join14(runDirectory, "fix-packet.md");
20004
- await writeFile6(packetPath, instruction, "utf8");
20287
+ const packetPath = join17(runDirectory, "fix-packet.md");
20288
+ await writeFile7(packetPath, instruction, "utf8");
20005
20289
  const admitted = {
20006
20290
  role: "fixer",
20007
20291
  phase: options.phase,
@@ -20026,7 +20310,7 @@ async function admitFixerInvocation(options) {
20026
20310
  mediaKind: a.mediaKind
20027
20311
  }))
20028
20312
  };
20029
- const admittedRequestPath = join14(runDirectory, "admitted-request.json");
20313
+ const admittedRequestPath = join17(runDirectory, "admitted-request.json");
20030
20314
  await writeAdmittedRequestPersistence(admittedRequestPath, admitted, {
20031
20315
  sessionDirectory,
20032
20316
  sessionFile
@@ -20235,14 +20519,14 @@ async function admitCollectorInvocation(options) {
20235
20519
  role: "collector",
20236
20520
  home: options.home
20237
20521
  });
20238
- const attachmentsDirectory = join14(runDirectory, "attachments");
20522
+ const attachmentsDirectory = join17(runDirectory, "attachments");
20239
20523
  ensureRealDirectoryTree(ledgerHome, sessionDirectory);
20240
20524
  ensureRealDirectoryTree(ledgerHome, attachmentsDirectory);
20241
20525
  const attachments = await freezeAttachments(options.attachmentPaths ?? [], attachmentsDirectory);
20242
20526
  let requestManifestPath;
20243
20527
  if (manifestCanonicalJson !== void 0) {
20244
- requestManifestPath = join14(runDirectory, "request-manifest.json");
20245
- await writeFile6(requestManifestPath, manifestCanonicalJson, "utf8");
20528
+ requestManifestPath = join17(runDirectory, "request-manifest.json");
20529
+ await writeFile7(requestManifestPath, manifestCanonicalJson, "utf8");
20246
20530
  }
20247
20531
  const instruction = options.instruction ?? "";
20248
20532
  const instructionEmpty = instruction.trim() === "";
@@ -20268,7 +20552,7 @@ async function admitCollectorInvocation(options) {
20268
20552
  mediaKind: a.mediaKind
20269
20553
  }))
20270
20554
  };
20271
- const admittedRequestPath = join14(runDirectory, "admitted-request.json");
20555
+ const admittedRequestPath = join17(runDirectory, "admitted-request.json");
20272
20556
  await writeAdmittedRequestPersistence(admittedRequestPath, admitted, {
20273
20557
  sessionDirectory,
20274
20558
  sessionFile
@@ -20365,7 +20649,7 @@ function parseDoctorArgv(args) {
20365
20649
  }
20366
20650
  async function resolveDoctorCaseRunsPath(options) {
20367
20651
  const ledgerHome = resolveActivationLedgerHome(options.home);
20368
- const defaultRuns = join14(
20652
+ const defaultRuns = join17(
20369
20653
  activationBookDirectory(ledgerHome, options.bookKey),
20370
20654
  "issues",
20371
20655
  String(options.issueNumber),
@@ -20472,7 +20756,7 @@ async function admitDoctorInvocation(options) {
20472
20756
  { cause: error }
20473
20757
  );
20474
20758
  }
20475
- const attachmentsDirectory = join14(runDirectory, "attachments");
20759
+ const attachmentsDirectory = join17(runDirectory, "attachments");
20476
20760
  ensureRealDirectoryTree(ledgerHome, sessionDirectory);
20477
20761
  ensureRealDirectoryTree(ledgerHome, attachmentsDirectory);
20478
20762
  const attachments = await freezeAttachments(options.attachmentPaths ?? [], attachmentsDirectory);
@@ -20498,7 +20782,7 @@ async function admitDoctorInvocation(options) {
20498
20782
  mediaKind: a.mediaKind
20499
20783
  }))
20500
20784
  };
20501
- const admittedRequestPath = join14(runDirectory, "admitted-request.json");
20785
+ const admittedRequestPath = join17(runDirectory, "admitted-request.json");
20502
20786
  await writeAdmittedRequestPersistence(admittedRequestPath, admitted, {
20503
20787
  sessionDirectory,
20504
20788
  sessionFile
@@ -20630,7 +20914,7 @@ async function admitNotaryInvocation(options) {
20630
20914
  ...ticketFields,
20631
20915
  ...options.correlationId === void 0 ? {} : { correlationId: options.correlationId }
20632
20916
  };
20633
- const admittedRequestPath = join14(runDirectory, "admitted-request.json");
20917
+ const admittedRequestPath = join17(runDirectory, "admitted-request.json");
20634
20918
  await writeAdmittedRequestPersistence(admittedRequestPath, admitted, {
20635
20919
  sessionDirectory,
20636
20920
  sessionFile
@@ -20732,7 +21016,7 @@ async function admitGleanerLeftInvocation(options) {
20732
21016
  attachments: [],
20733
21017
  ...options.correlationId === void 0 ? {} : { correlationId: options.correlationId }
20734
21018
  };
20735
- const admittedRequestPath = join14(runDirectory, "admitted-request.json");
21019
+ const admittedRequestPath = join17(runDirectory, "admitted-request.json");
20736
21020
  await writeAdmittedRequestPersistence(admittedRequestPath, admitted, {
20737
21021
  sessionDirectory,
20738
21022
  sessionFile
@@ -20837,7 +21121,7 @@ async function admitReviewerInvocation(options) {
20837
21121
  role: "reviewer",
20838
21122
  home: options.home
20839
21123
  });
20840
- const attachmentsDirectory = join14(runDirectory, "attachments");
21124
+ const attachmentsDirectory = join17(runDirectory, "attachments");
20841
21125
  ensureRealDirectoryTree(ledgerHome, sessionDirectory);
20842
21126
  ensureRealDirectoryTree(ledgerHome, attachmentsDirectory);
20843
21127
  const attachments = await freezeAttachments(options.attachmentPaths, attachmentsDirectory);
@@ -20862,7 +21146,7 @@ async function admitReviewerInvocation(options) {
20862
21146
  mediaKind: a.mediaKind
20863
21147
  }))
20864
21148
  };
20865
- const admittedRequestPath = join14(runDirectory, "admitted-request.json");
21149
+ const admittedRequestPath = join17(runDirectory, "admitted-request.json");
20866
21150
  await writeAdmittedRequestPersistence(admittedRequestPath, admitted, {
20867
21151
  sessionDirectory,
20868
21152
  sessionFile
@@ -20989,7 +21273,7 @@ async function admitMergerInvocation(options) {
20989
21273
  role: "merger",
20990
21274
  home: options.home
20991
21275
  });
20992
- const attachmentsDirectory = join14(runDirectory, "attachments");
21276
+ const attachmentsDirectory = join17(runDirectory, "attachments");
20993
21277
  ensureRealDirectoryTree(ledgerHome, sessionDirectory);
20994
21278
  ensureRealDirectoryTree(ledgerHome, attachmentsDirectory);
20995
21279
  const attachments = await freezeAttachments(options.attachmentPaths, attachmentsDirectory);
@@ -21017,8 +21301,8 @@ async function admitMergerInvocation(options) {
21017
21301
  // Authorized checks remain available on the assignment; default none.
21018
21302
  authorizedChecks: []
21019
21303
  });
21020
- const mergerInputPath = join14(runDirectory, "merger-input.json");
21021
- await writeFile6(
21304
+ const mergerInputPath = join17(runDirectory, "merger-input.json");
21305
+ await writeFile7(
21022
21306
  mergerInputPath,
21023
21307
  `${JSON.stringify(mergerInput, null, 2)}
21024
21308
  `,
@@ -21049,7 +21333,7 @@ async function admitMergerInvocation(options) {
21049
21333
  mediaKind: a.mediaKind
21050
21334
  }))
21051
21335
  };
21052
- const admittedRequestPath = join14(runDirectory, "admitted-request.json");
21336
+ const admittedRequestPath = join17(runDirectory, "admitted-request.json");
21053
21337
  await writeAdmittedRequestPersistence(admittedRequestPath, admitted, {
21054
21338
  sessionDirectory,
21055
21339
  sessionFile
@@ -21309,6 +21593,7 @@ var init_invocation = __esm({
21309
21593
  "use strict";
21310
21594
  init_activation_ledger_topology();
21311
21595
  init_activation_ledger_git();
21596
+ init_ticket_seat_memory();
21312
21597
  init_doctor_evidence();
21313
21598
  init_collector_config();
21314
21599
  init_fixer_packet();
@@ -21339,13 +21624,13 @@ var init_invocation = __esm({
21339
21624
  });
21340
21625
 
21341
21626
  // src/package-resources/method-skill.ts
21342
- import { createHash as createHash4 } from "node:crypto";
21343
- import { readFile as readFile10, realpath as realpath5 } from "node:fs/promises";
21344
- import { join as join15 } from "node:path";
21627
+ import { createHash as createHash5 } from "node:crypto";
21628
+ import { readFile as readFile11, realpath as realpath5 } from "node:fs/promises";
21629
+ import { join as join18 } from "node:path";
21345
21630
  function gitBlobOid(bytes) {
21346
21631
  const body = typeof bytes === "string" ? Buffer.from(bytes, "utf8") : Buffer.from(bytes);
21347
21632
  const header = Buffer.from(`blob ${body.byteLength}\0`, "utf8");
21348
- return createHash4("sha1").update(header).update(body).digest("hex");
21633
+ return createHash5("sha1").update(header).update(body).digest("hex");
21349
21634
  }
21350
21635
  function stripSkillFrontmatter(content) {
21351
21636
  if (!content.startsWith("---")) return content;
@@ -21358,10 +21643,10 @@ function packagedMethodSkillRelativeDirectory(name) {
21358
21643
  return `${METHOD_SKILL_RELATIVE_ROOT}/${name}`;
21359
21644
  }
21360
21645
  function resolvePackagedMethodSkillRoot(packageRoot2, name) {
21361
- return join15(packageRoot2, packagedMethodSkillRelativeDirectory(name));
21646
+ return join18(packageRoot2, packagedMethodSkillRelativeDirectory(name));
21362
21647
  }
21363
21648
  function resolvePackagedMethodSkillPath(packageRoot2, name) {
21364
- return join15(resolvePackagedMethodSkillRoot(packageRoot2, name), "SKILL.md");
21649
+ return join18(resolvePackagedMethodSkillRoot(packageRoot2, name), "SKILL.md");
21365
21650
  }
21366
21651
  function isRecord8(value) {
21367
21652
  return typeof value === "object" && value !== null && !Array.isArray(value);
@@ -21455,11 +21740,11 @@ function parseProvenance(raw, expectedName) {
21455
21740
  }
21456
21741
  async function loadPackagedMethodSkillMaterial(packageRoot2, name) {
21457
21742
  const rootDirectory = resolvePackagedMethodSkillRoot(packageRoot2, name);
21458
- const skillPathConfigured = join15(rootDirectory, "SKILL.md");
21459
- const provenancePath = join15(rootDirectory, "provenance.json");
21743
+ const skillPathConfigured = join18(rootDirectory, "SKILL.md");
21744
+ const provenancePath = join18(rootDirectory, "provenance.json");
21460
21745
  let provenanceRaw;
21461
21746
  try {
21462
- provenanceRaw = await readFile10(provenancePath, "utf8");
21747
+ provenanceRaw = await readFile11(provenancePath, "utf8");
21463
21748
  } catch (error) {
21464
21749
  throw new PackagedMethodSkillUnavailableError(name, provenancePath, error);
21465
21750
  }
@@ -21473,10 +21758,10 @@ async function loadPackagedMethodSkillMaterial(packageRoot2, name) {
21473
21758
  }
21474
21759
  const provenance = parseProvenance(provenanceJson, name);
21475
21760
  for (const [rel, expected] of Object.entries(provenance.files)) {
21476
- const absolute = join15(rootDirectory, rel);
21761
+ const absolute = join18(rootDirectory, rel);
21477
21762
  let bytes;
21478
21763
  try {
21479
- bytes = await readFile10(absolute);
21764
+ bytes = await readFile11(absolute);
21480
21765
  } catch (error) {
21481
21766
  throw new PackagedMethodSkillUnavailableError(name, absolute, error);
21482
21767
  }
@@ -21492,7 +21777,7 @@ async function loadPackagedMethodSkillMaterial(packageRoot2, name) {
21492
21777
  let raw;
21493
21778
  try {
21494
21779
  skillPath = await realpath5(skillPathConfigured);
21495
- raw = await readFile10(skillPath, "utf8");
21780
+ raw = await readFile11(skillPath, "utf8");
21496
21781
  } catch (error) {
21497
21782
  throw new PackagedMethodSkillUnavailableError(name, skillPathConfigured, error);
21498
21783
  }
@@ -22026,11 +22311,11 @@ var init_collector_github = __esm({
22026
22311
  });
22027
22312
 
22028
22313
  // src/diarist-ticket-resolution.ts
22029
- import { existsSync as existsSync6, readFileSync as readFileSync2 } from "node:fs";
22030
- import { join as join16 } from "node:path";
22031
- import { fileURLToPath } from "node:url";
22032
- function resolveDiaristResolveTicketMethodPath(packageRoot2 = fileURLToPath(new URL("..", import.meta.url))) {
22033
- return join16(packageRoot2, DIARIST_RESOLVE_TICKET_METHOD_RELATIVE);
22314
+ import { existsSync as existsSync8, readFileSync as readFileSync2 } from "node:fs";
22315
+ import { join as join19 } from "node:path";
22316
+ import { fileURLToPath as fileURLToPath2 } from "node:url";
22317
+ function resolveDiaristResolveTicketMethodPath(packageRoot2 = fileURLToPath2(new URL("..", import.meta.url))) {
22318
+ return join19(packageRoot2, DIARIST_RESOLVE_TICKET_METHOD_RELATIVE);
22034
22319
  }
22035
22320
  function instructionContainsTicketNumber(instruction, ticketNumber) {
22036
22321
  if (!Number.isSafeInteger(ticketNumber) || ticketNumber < 1) return false;
@@ -22079,7 +22364,7 @@ function parseDiaristTicketResolverStdout(stdout) {
22079
22364
  }
22080
22365
  function createHermesDiaristTicketResolver(options = {}) {
22081
22366
  const methodPath = resolveDiaristResolveTicketMethodPath(options.packageRoot);
22082
- if (!existsSync6(methodPath)) {
22367
+ if (!existsSync8(methodPath)) {
22083
22368
  throw new Error(`diarist resolve-ticket method material missing (${methodPath})`);
22084
22369
  }
22085
22370
  const method = readFileSync2(methodPath, "utf8");
@@ -22251,9 +22536,9 @@ var init_adr_path_refs = __esm({
22251
22536
  });
22252
22537
 
22253
22538
  // src/diarist-mechanical.ts
22254
- import { createHash as createHash5 } from "node:crypto";
22255
- import { existsSync as existsSync7, readdirSync as readdirSync2, readFileSync as readFileSync3, realpathSync as realpathSync3, statSync as statSync2 } from "node:fs";
22256
- import { basename as basename6, join as join17, resolve as resolve8 } from "node:path";
22539
+ import { createHash as createHash6 } from "node:crypto";
22540
+ import { existsSync as existsSync9, readdirSync as readdirSync2, readFileSync as readFileSync3, realpathSync as realpathSync3, statSync as statSync2 } from "node:fs";
22541
+ import { basename as basename6, join as join20, resolve as resolve8 } from "node:path";
22257
22542
  import { homedir } from "node:os";
22258
22543
  function extractCornerQuotes(text, minLength = DEFAULT_QUOTE_MIN) {
22259
22544
  const out = [];
@@ -22291,7 +22576,7 @@ function blockKey(block) {
22291
22576
  r.entryId === void 0 ? "" : String(r.entryId),
22292
22577
  r.path ?? "",
22293
22578
  r.url ?? "",
22294
- createHash5("sha256").update(block.transcript, "utf8").digest("hex").slice(0, 16)
22579
+ createHash6("sha256").update(block.transcript, "utf8").digest("hex").slice(0, 16)
22295
22580
  ].join("|");
22296
22581
  }
22297
22582
  function dedupeSourceBlocks(blocks) {
@@ -22357,20 +22642,20 @@ function isNotificationRow(type, text) {
22357
22642
  return false;
22358
22643
  }
22359
22644
  function readCcSessionBlocks(options) {
22360
- const root = options.projectsRoot ?? join17(homedir(), ".claude", "projects");
22361
- if (!existsSync7(root)) return [];
22645
+ const root = options.projectsRoot ?? join20(homedir(), ".claude", "projects");
22646
+ if (!existsSync9(root)) return [];
22362
22647
  const blocks = [];
22363
22648
  const dirs = /* @__PURE__ */ new Set();
22364
22649
  for (const cwd of options.cwds) {
22365
- dirs.add(join17(root, encodeClaudeProjectDir(cwd)));
22650
+ dirs.add(join20(root, encodeClaudeProjectDir(cwd)));
22366
22651
  }
22367
22652
  for (const cwd of options.cwds) {
22368
22653
  if (cwd.includes("projects")) continue;
22369
- const direct = join17(root, cwd);
22370
- if (existsSync7(direct)) dirs.add(direct);
22654
+ const direct = join20(root, cwd);
22655
+ if (existsSync9(direct)) dirs.add(direct);
22371
22656
  }
22372
22657
  for (const dir of dirs) {
22373
- if (!existsSync7(dir)) continue;
22658
+ if (!existsSync9(dir)) continue;
22374
22659
  let dirStat;
22375
22660
  try {
22376
22661
  dirStat = statSync2(dir);
@@ -22395,7 +22680,7 @@ function readCcSessionBlocks(options) {
22395
22680
  );
22396
22681
  }
22397
22682
  for (const name of files) {
22398
- const sessionFile = join17(dir, name);
22683
+ const sessionFile = join20(dir, name);
22399
22684
  let text;
22400
22685
  try {
22401
22686
  text = readFileSync3(sessionFile, "utf8");
@@ -22495,7 +22780,7 @@ function readAdrDecisionKeyBlocks(input) {
22495
22780
  const adrRootAbs = resolve8(cwdAbs, DIARIST_ADR_ROOT_REL);
22496
22781
  let adrRootReal;
22497
22782
  try {
22498
- adrRootReal = existsSync7(adrRootAbs) ? realpathSync3(adrRootAbs) : resolve8(realpathSync3(cwdAbs), DIARIST_ADR_ROOT_REL);
22783
+ adrRootReal = existsSync9(adrRootAbs) ? realpathSync3(adrRootAbs) : resolve8(realpathSync3(cwdAbs), DIARIST_ADR_ROOT_REL);
22499
22784
  } catch (error) {
22500
22785
  throw new DiaristSourceReadError(
22501
22786
  "adr-unreadable",
@@ -22521,7 +22806,7 @@ function readAdrDecisionKeyBlocks(input) {
22521
22806
  `diarist referenced ADR escapes docs/adr (${rel})`
22522
22807
  );
22523
22808
  }
22524
- if (!existsSync7(abs)) {
22809
+ if (!existsSync9(abs)) {
22525
22810
  throw new DiaristSourceReadError(
22526
22811
  "adr-missing",
22527
22812
  abs,
@@ -22623,11 +22908,11 @@ var init_diarist_mechanical = __esm({
22623
22908
  });
22624
22909
 
22625
22910
  // src/diarist-llm-collector.ts
22626
- import { existsSync as existsSync8, readFileSync as readFileSync4 } from "node:fs";
22627
- import { join as join18 } from "node:path";
22628
- import { fileURLToPath as fileURLToPath2 } from "node:url";
22629
- function resolveDiaristCollectMethodPath(packageRoot2 = fileURLToPath2(packageRootUrl)) {
22630
- return join18(packageRoot2, DIARIST_COLLECT_METHOD_RELATIVE);
22911
+ import { existsSync as existsSync10, readFileSync as readFileSync4 } from "node:fs";
22912
+ import { join as join21 } from "node:path";
22913
+ import { fileURLToPath as fileURLToPath3 } from "node:url";
22914
+ function resolveDiaristCollectMethodPath(packageRoot2 = fileURLToPath3(packageRootUrl2)) {
22915
+ return join21(packageRoot2, DIARIST_COLLECT_METHOD_RELATIVE);
22631
22916
  }
22632
22917
  function isRecord11(value) {
22633
22918
  return typeof value === "object" && value !== null && !Array.isArray(value);
@@ -22739,7 +23024,7 @@ function serializeDiaristCollectorEnginePayload(payload) {
22739
23024
  function createHermesDiaristCollector(options = {}) {
22740
23025
  const executable = options.executable ?? "hermes";
22741
23026
  const methodPath = resolveDiaristCollectMethodPath(options.packageRoot);
22742
- if (!existsSync8(methodPath)) {
23027
+ if (!existsSync10(methodPath)) {
22743
23028
  throw new Error(`diarist collect method material missing (${methodPath})`);
22744
23029
  }
22745
23030
  const method = readFileSync4(methodPath, "utf8");
@@ -22789,13 +23074,13 @@ function createHermesDiaristCollector(options = {}) {
22789
23074
  };
22790
23075
  };
22791
23076
  }
22792
- var DIARIST_COLLECT_METHOD_RELATIVE, packageRootUrl, DiaristLlmStdoutError, HERMES_DIARIST_COLLECTOR_TOOLSET;
23077
+ var DIARIST_COLLECT_METHOD_RELATIVE, packageRootUrl2, DiaristLlmStdoutError, HERMES_DIARIST_COLLECTOR_TOOLSET;
22793
23078
  var init_diarist_llm_collector = __esm({
22794
23079
  "src/diarist-llm-collector.ts"() {
22795
23080
  "use strict";
22796
23081
  init_engine_detour();
22797
23082
  DIARIST_COLLECT_METHOD_RELATIVE = "resources/diarist-collect.md";
22798
- packageRootUrl = new URL("..", import.meta.url);
23083
+ packageRootUrl2 = new URL("..", import.meta.url);
22799
23084
  DiaristLlmStdoutError = class extends Error {
22800
23085
  code = "diarist-llm-stdout";
22801
23086
  reason;
@@ -22958,9 +23243,9 @@ var init_ticket_provenance_contracts = __esm({
22958
23243
  });
22959
23244
 
22960
23245
  // src/ticket-provenance.ts
22961
- import { createHash as createHash6 } from "node:crypto";
22962
- import { appendFileSync as appendFileSync2, existsSync as existsSync9, mkdirSync as mkdirSync3, readFileSync as readFileSync5, writeFileSync as writeFileSync2 } from "node:fs";
22963
- import { join as join19 } from "node:path";
23246
+ import { createHash as createHash7 } from "node:crypto";
23247
+ import { appendFileSync as appendFileSync2, existsSync as existsSync11, mkdirSync as mkdirSync3, readFileSync as readFileSync5, writeFileSync as writeFileSync2 } from "node:fs";
23248
+ import { join as join22 } from "node:path";
22964
23249
  function ticketProvenanceSubject(ticketNumber) {
22965
23250
  if (!Number.isSafeInteger(ticketNumber) || ticketNumber < 1) {
22966
23251
  throw new Error(`ticket-provenance subject requires a positive ticket number, got ${String(ticketNumber)}`);
@@ -22981,7 +23266,7 @@ function ticketProvenanceEntryIdentity(input) {
22981
23266
  refKey,
22982
23267
  input.transcript
22983
23268
  ].join("\0");
22984
- return createHash6("sha256").update(material, "utf8").digest("hex");
23269
+ return createHash7("sha256").update(material, "utf8").digest("hex");
22985
23270
  }
22986
23271
  function appendTicketProvenanceEntry(input) {
22987
23272
  const subject = ticketProvenanceSubject(input.ticketNumber);
@@ -23018,13 +23303,13 @@ function resolveTicketProvenanceVolume(ticketNumber, cwd, home) {
23018
23303
  return {
23019
23304
  recordFile: path.recordFile,
23020
23305
  volumeDir: path.sessionDir,
23021
- humanViewFile: join19(path.sessionDir, TICKET_PROVENANCE_HUMAN_VIEW),
23022
- offeredWatermarkFile: join19(path.sessionDir, TICKET_PROVENANCE_OFFERED_WATERMARK)
23306
+ humanViewFile: join22(path.sessionDir, TICKET_PROVENANCE_HUMAN_VIEW),
23307
+ offeredWatermarkFile: join22(path.sessionDir, TICKET_PROVENANCE_OFFERED_WATERMARK)
23023
23308
  };
23024
23309
  }
23025
23310
  function readOfferedIdentities(ticketNumber, cwd, home) {
23026
23311
  const { offeredWatermarkFile } = resolveTicketProvenanceVolume(ticketNumber, cwd, home);
23027
- if (!existsSync9(offeredWatermarkFile)) return /* @__PURE__ */ new Set();
23312
+ if (!existsSync11(offeredWatermarkFile)) return /* @__PURE__ */ new Set();
23028
23313
  let text;
23029
23314
  try {
23030
23315
  text = readFileSync5(offeredWatermarkFile, "utf8");
@@ -23180,7 +23465,7 @@ function appendTicketProvenanceDiagnostic(input) {
23180
23465
  input.diagnostic.cause,
23181
23466
  input.diagnostic.reason ?? ""
23182
23467
  ];
23183
- const identity = createHash6("sha256").update(identityParts.join("\0"), "utf8").digest("hex");
23468
+ const identity = createHash7("sha256").update(identityParts.join("\0"), "utf8").digest("hex");
23184
23469
  return sitianReport({
23185
23470
  level: "event",
23186
23471
  kind: TICKET_PROVENANCE_KIND,
@@ -23593,42 +23878,6 @@ var init_engine_detour_tool = __esm({
23593
23878
  }
23594
23879
  });
23595
23880
 
23596
- // src/session-opening-materials.ts
23597
- import { existsSync as existsSync10 } from "node:fs";
23598
- import { dirname as dirname8, join as join20 } from "node:path";
23599
- import { fileURLToPath as fileURLToPath3, pathToFileURL as pathToFileURL2 } from "node:url";
23600
- function resolvePackageRootDir(moduleUrl = import.meta.url) {
23601
- let dir = dirname8(fileURLToPath3(moduleUrl));
23602
- for (let i = 0; i < 8; i += 1) {
23603
- if (existsSync10(join20(dir, "package.json")) && existsSync10(join20(dir, "souls"))) {
23604
- return dir;
23605
- }
23606
- const parent = dirname8(dir);
23607
- if (parent === dir) break;
23608
- dir = parent;
23609
- }
23610
- return fileURLToPath3(new URL("..", moduleUrl));
23611
- }
23612
- var packageRootUrl2, MAIN_ROLE_SESSION_MATERIALS, GATEKEEPER_SESSION_MATERIALS;
23613
- var init_session_opening_materials = __esm({
23614
- "src/session-opening-materials.ts"() {
23615
- "use strict";
23616
- init_packaged_role_registry();
23617
- packageRootUrl2 = pathToFileURL2(resolvePackageRootDir() + "/").href;
23618
- MAIN_ROLE_SESSION_MATERIALS = {
23619
- ...Object.fromEntries(
23620
- PUBLIC_ROLE_RECORDS.map((record4) => [record4.role, record4.sessionMaterials])
23621
- )
23622
- };
23623
- GATEKEEPER_SESSION_MATERIALS = {
23624
- // #639: single authority — the public gatekeeper record owns the province list.
23625
- gatekeeper: PUBLIC_ROLE_RECORDS.find((entry) => entry.role === "gatekeeper").sessionMaterials,
23626
- inspector: INSPECTOR_SESSION_MATERIALS,
23627
- notary: NOTARY_SESSION_MATERIALS
23628
- };
23629
- }
23630
- });
23631
-
23632
23881
  // src/navigator-session-contracts.ts
23633
23882
  var navigatorProviderFailureSchema;
23634
23883
  var init_navigator_session_contracts = __esm({
@@ -23721,6 +23970,7 @@ var init_evidence_child_executor = __esm({
23721
23970
  init_compliance_transport();
23722
23971
  init_auditor_dossier_tool();
23723
23972
  init_sitian_facade();
23973
+ init_ticket_seat_memory();
23724
23974
  init_engine_detour_tool();
23725
23975
  init_engine_detour();
23726
23976
  init_engine_material();
@@ -23757,12 +24007,12 @@ var init_compliance_transport = __esm({
23757
24007
  });
23758
24008
 
23759
24009
  // src/ledger-session-read.ts
23760
- import { readFile as readFile11 } from "node:fs/promises";
24010
+ import { readFile as readFile12 } from "node:fs/promises";
23761
24011
  function isRecord14(value) {
23762
24012
  return typeof value === "object" && value !== null && !Array.isArray(value);
23763
24013
  }
23764
24014
  async function readLedgerSessionJsonl(path) {
23765
- const text = await readFile11(path, "utf8");
24015
+ const text = await readFile12(path, "utf8");
23766
24016
  const lines = text.split("\n");
23767
24017
  const rows = [];
23768
24018
  for (let index = 0; index < lines.length; index += 1) {
@@ -23899,6 +24149,31 @@ function extractSessionToolIntervals(rows) {
23899
24149
  return interval.endedAt === void 0 ? base : { ...base, endedAt: interval.endedAt };
23900
24150
  });
23901
24151
  }
24152
+ function intervalRowsAroundAnchor(rows, anchorIndex, isBindingRow) {
24153
+ let start = 0;
24154
+ for (let i = anchorIndex; i >= 0; i -= 1) {
24155
+ if (isBindingRow(rows[i])) {
24156
+ start = i;
24157
+ break;
24158
+ }
24159
+ }
24160
+ let end = rows.length;
24161
+ for (let i = Math.max(anchorIndex, start) + 1; i < rows.length; i += 1) {
24162
+ if (isBindingRow(rows[i])) {
24163
+ end = i;
24164
+ break;
24165
+ }
24166
+ }
24167
+ return { rows: rows.slice(start, end), closed: end < rows.length };
24168
+ }
24169
+ function intervalRowsForMatchingBinding(rows, isBindingRow, matches) {
24170
+ for (let i = 0; i < rows.length; i += 1) {
24171
+ const row = rows[i];
24172
+ if (!isBindingRow(row) || !matches(row)) continue;
24173
+ return intervalRowsAroundAnchor(rows, i, isBindingRow);
24174
+ }
24175
+ return void 0;
24176
+ }
23902
24177
  var LedgerSessionJsonlError;
23903
24178
  var init_ledger_session_read = __esm({
23904
24179
  "src/ledger-session-read.ts"() {
@@ -23920,18 +24195,15 @@ var init_ledger_session_read = __esm({
23920
24195
 
23921
24196
  // src/analyst-gate-cycles-read.ts
23922
24197
  import { readdir as readdir3 } from "node:fs/promises";
23923
- import { join as join21 } from "node:path";
24198
+ import { join as join23 } from "node:path";
23924
24199
  function isRecord15(value) {
23925
24200
  return typeof value === "object" && value !== null && !Array.isArray(value);
23926
24201
  }
23927
- function extractAttemptEntryId(rows) {
23928
- for (const row of rows) {
23929
- if (row.type !== "custom" || row.customType !== AUDITOR_PARENT_ATTEMPT_BINDING_ENTRY_TYPE) continue;
23930
- if (!isRecord15(row.data) || !isRecord15(row.data.parent)) continue;
23931
- const id = row.data.parent.attemptEntryId;
23932
- if (typeof id === "string" && id.length > 0) return id;
23933
- }
23934
- return void 0;
24202
+ function isParentAttemptBindingRow(row) {
24203
+ return row.type === "custom" && row.customType === AUDITOR_PARENT_ATTEMPT_BINDING_ENTRY_TYPE;
24204
+ }
24205
+ function intervalRowsForGateCall(rows, callRowIndex) {
24206
+ return intervalRowsAroundAnchor(rows, callRowIndex, isParentAttemptBindingRow).rows;
23935
24207
  }
23936
24208
  function isMissingDirectoryError(error) {
23937
24209
  return error instanceof Error && "code" in error && error.code === "ENOENT";
@@ -23962,32 +24234,6 @@ function acceptedGateReceiptIds(rows) {
23962
24234
  }
23963
24235
  return accepted;
23964
24236
  }
23965
- function extractLastGateToolCall(rows) {
23966
- const acceptedIds = acceptedGateReceiptIds(rows);
23967
- let lastAccepted;
23968
- let lastRejected;
23969
- for (const row of rows) {
23970
- const message = isRecord15(row.message) ? row.message : void 0;
23971
- if (message?.role !== "assistant" || !Array.isArray(message.content)) continue;
23972
- for (const part of message.content) {
23973
- if (!isRecord15(part) || part.type !== "toolCall") continue;
23974
- if (typeof part.id !== "string" || part.id.length === 0) continue;
23975
- if (typeof part.name !== "string" || part.name.length === 0) continue;
23976
- if (!isGateTerminatingToolName(part.name)) continue;
23977
- const call = {
23978
- toolName: part.name,
23979
- args: isRecord15(part.arguments) ? part.arguments : void 0,
23980
- accepted: acceptedIds.has(part.id)
23981
- };
23982
- if (call.accepted) {
23983
- lastAccepted = call;
23984
- } else if (lastAccepted === void 0) {
23985
- lastRejected = call;
23986
- }
23987
- }
23988
- }
23989
- return lastAccepted ?? lastRejected;
23990
- }
23991
24237
  function requireAcceptedGateStatus(args, filePath) {
23992
24238
  if (args === void 0 || typeof args.status !== "string" || args.status.trim() === "") {
23993
24239
  throw new Error(
@@ -24016,18 +24262,54 @@ function requireAcceptedGateSpan(rows, filePath) {
24016
24262
  wallMs: endedMs - startedMs
24017
24263
  };
24018
24264
  }
24019
- async function classifyAuditorVolume(filePath) {
24020
- const rows = await readLedgerSessionJsonl(filePath);
24021
- const call = extractLastGateToolCall(rows);
24022
- if (call === void 0) return void 0;
24023
- const attemptEntryId = extractAttemptEntryId(rows);
24024
- if (!call.accepted) {
24025
- return void 0;
24026
- }
24027
- const span = requireAcceptedGateSpan(rows, filePath);
24028
- const status = requireAcceptedGateStatus(call.args, filePath);
24265
+ function nearestAttemptBindingBefore(rows, beforeIndex) {
24266
+ for (let i = beforeIndex - 1; i >= 0; i -= 1) {
24267
+ const row = rows[i];
24268
+ if (!isParentAttemptBindingRow(row)) continue;
24269
+ if (!isRecord15(row.data) || !isRecord15(row.data.parent)) continue;
24270
+ const id = row.data.parent.attemptEntryId;
24271
+ const sessionFile = row.data.parent.sessionFile;
24272
+ return {
24273
+ ...typeof id === "string" && id.length > 0 ? { attemptEntryId: id } : {},
24274
+ ...typeof sessionFile === "string" && sessionFile.length > 0 ? { parentSessionFile: sessionFile } : {}
24275
+ };
24276
+ }
24277
+ return {};
24278
+ }
24279
+ function extractAllAcceptedGateToolCalls(rows) {
24280
+ const acceptedIds = acceptedGateReceiptIds(rows);
24281
+ const out = [];
24282
+ for (let rowIndex = 0; rowIndex < rows.length; rowIndex += 1) {
24283
+ const row = rows[rowIndex];
24284
+ const message = isRecord15(row.message) ? row.message : void 0;
24285
+ if (message?.role !== "assistant" || !Array.isArray(message.content)) continue;
24286
+ for (const part of message.content) {
24287
+ if (!isRecord15(part) || part.type !== "toolCall") continue;
24288
+ if (typeof part.id !== "string" || part.id.length === 0) continue;
24289
+ if (typeof part.name !== "string" || part.name.length === 0) continue;
24290
+ if (!isGateTerminatingToolName(part.name)) continue;
24291
+ if (!acceptedIds.has(part.id)) continue;
24292
+ const binding = nearestAttemptBindingBefore(rows, rowIndex);
24293
+ out.push({
24294
+ toolName: part.name,
24295
+ args: isRecord15(part.arguments) ? part.arguments : void 0,
24296
+ accepted: true,
24297
+ rowIndex,
24298
+ ...binding
24299
+ });
24300
+ }
24301
+ }
24302
+ return out;
24303
+ }
24304
+ function projectAcceptedGateCall(filePath, rows, call) {
24305
+ const span = requireAcceptedGateSpan(intervalRowsForGateCall(rows, call.rowIndex), filePath);
24306
+ const status = requireAcceptedGateStatus(call.args, filePath);
24029
24307
  const findings = asStringFindings(call.args?.findings);
24030
24308
  const findingsCount = findings.length;
24309
+ const bindingFields = {
24310
+ ...call.attemptEntryId === void 0 ? {} : { attemptEntryId: call.attemptEntryId },
24311
+ ...call.parentSessionFile === void 0 ? {} : { parentSessionFile: call.parentSessionFile }
24312
+ };
24031
24313
  if (DISPATCH_TOOLS.has(call.toolName)) {
24032
24314
  if (status === "pass") {
24033
24315
  return void 0;
@@ -24050,7 +24332,7 @@ async function classifyAuditorVolume(filePath) {
24050
24332
  officer: officer2,
24051
24333
  status,
24052
24334
  ...reason === void 0 ? {} : { reason },
24053
- ...attemptEntryId === void 0 ? {} : { attemptEntryId }
24335
+ ...bindingFields
24054
24336
  };
24055
24337
  }
24056
24338
  const officer = OFFICER_TOOL_TO_FACE[call.toolName];
@@ -24068,9 +24350,29 @@ async function classifyAuditorVolume(filePath) {
24068
24350
  findings,
24069
24351
  findingsCount,
24070
24352
  officerWallMs: span.wallMs,
24071
- ...attemptEntryId === void 0 ? {} : { attemptEntryId }
24353
+ ...bindingFields
24072
24354
  };
24073
24355
  }
24356
+ async function classifyAuditorVolume(filePath) {
24357
+ let rows;
24358
+ try {
24359
+ rows = await readLedgerSessionJsonl(filePath);
24360
+ } catch (error) {
24361
+ if (error instanceof LedgerSessionJsonlError && error.prefixRows.some((row) => isTicketSeatRunBindingRow(row))) {
24362
+ rows = error.prefixRows;
24363
+ } else {
24364
+ throw error;
24365
+ }
24366
+ }
24367
+ const accepted = extractAllAcceptedGateToolCalls(rows);
24368
+ if (accepted.length === 0) return [];
24369
+ const volumes = [];
24370
+ for (const call of accepted) {
24371
+ const projected = projectAcceptedGateCall(filePath, rows, call);
24372
+ if (projected !== void 0) volumes.push(projected);
24373
+ }
24374
+ return volumes;
24375
+ }
24074
24376
  function pairGateRounds(volumes) {
24075
24377
  const ordered = [...volumes].sort((a, b) => {
24076
24378
  if (a.startedAt !== b.startedAt) return a.startedAt.localeCompare(b.startedAt);
@@ -24128,19 +24430,27 @@ function pairGateRounds(volumes) {
24128
24430
  }
24129
24431
  return rounds.sort((a, b) => a.officerStartedAt.localeCompare(b.officerStartedAt)).map((round, index) => ({ ...round, roundIndex: index + 1 }));
24130
24432
  }
24131
- async function readAnalystGateCyclesFromAuditorRoles(auditorRolesDirectory) {
24132
- let names;
24133
- try {
24134
- const entries = await readdir3(auditorRolesDirectory, { withFileTypes: true });
24135
- names = entries.filter((e) => e.isFile() && e.name.endsWith(".jsonl")).map((e) => e.name).sort();
24136
- } catch (error) {
24137
- if (isMissingDirectoryError(error)) return [];
24138
- throw error;
24139
- }
24433
+ async function readAnalystGateCyclesFromAuditorRoles(auditorRolesDirectory, options = {}) {
24434
+ const directories = typeof auditorRolesDirectory === "string" ? [auditorRolesDirectory] : auditorRolesDirectory;
24140
24435
  const volumes = [];
24141
- for (const name of names) {
24142
- const classified = await classifyAuditorVolume(join21(auditorRolesDirectory, name));
24143
- if (classified !== void 0) volumes.push(classified);
24436
+ for (const directory of directories) {
24437
+ let names;
24438
+ try {
24439
+ const entries = await readdir3(directory, { withFileTypes: true });
24440
+ names = entries.filter((e) => e.isFile() && e.name.endsWith(".jsonl")).map((e) => e.name).sort();
24441
+ } catch (error) {
24442
+ if (isMissingDirectoryError(error)) continue;
24443
+ throw error;
24444
+ }
24445
+ for (const name of names) {
24446
+ const classified = await classifyAuditorVolume(join23(directory, name));
24447
+ for (const volume of classified) {
24448
+ if (options.parentSessionFile !== void 0 && volume.parentSessionFile !== void 0 && volume.parentSessionFile !== options.parentSessionFile) {
24449
+ continue;
24450
+ }
24451
+ volumes.push(volume);
24452
+ }
24453
+ }
24144
24454
  }
24145
24455
  return pairGateRounds(volumes);
24146
24456
  }
@@ -24150,6 +24460,7 @@ var init_analyst_gate_cycles_read = __esm({
24150
24460
  "use strict";
24151
24461
  init_compliance_transport();
24152
24462
  init_ledger_session_read();
24463
+ init_ticket_seat_memory();
24153
24464
  DISPATCH_TOOLS = /* @__PURE__ */ new Set(["ak_menxia_output", "ak_gatekeeper_output"]);
24154
24465
  OFFICER_TOOL_TO_FACE = {
24155
24466
  ak_jishizhong_output: "inspector",
@@ -24190,8 +24501,8 @@ var init_gatekeeper_role = __esm({
24190
24501
  });
24191
24502
 
24192
24503
  // src/run-terminal-artifacts.ts
24193
- import { readdir as readdir4, readFile as readFile12 } from "node:fs/promises";
24194
- import { basename as basename7, dirname as dirname9, join as join22 } from "node:path";
24504
+ import { readdir as readdir4, readFile as readFile13 } from "node:fs/promises";
24505
+ import { basename as basename7, dirname as dirname9, join as join24 } from "node:path";
24195
24506
  function isMissingPathError2(error) {
24196
24507
  return error instanceof Error && "code" in error && (error.code === "ENOENT" || error.code === "ENOTDIR");
24197
24508
  }
@@ -24222,7 +24533,7 @@ function readUsableTerminalArtifactBody(body) {
24222
24533
  async function readTerminalArtifactAtPath(path, file) {
24223
24534
  let raw;
24224
24535
  try {
24225
- raw = await readFile12(path, "utf8");
24536
+ raw = await readFile13(path, "utf8");
24226
24537
  } catch (error) {
24227
24538
  if (isMissingPathError2(error)) return void 0;
24228
24539
  return {
@@ -24266,7 +24577,7 @@ async function listUniqueErrorFallbackPaths(directories) {
24266
24577
  }
24267
24578
  for (const name of names.sort((a, b) => a.localeCompare(b))) {
24268
24579
  if (!UNIQUE_ERROR_FALLBACK_NAME.test(name)) continue;
24269
- found.push(join22(dir, name));
24580
+ found.push(join24(dir, name));
24270
24581
  }
24271
24582
  }
24272
24583
  return found;
@@ -24282,14 +24593,14 @@ function presentUniqueFallbackBoundToRun(body, expectedRunId) {
24282
24593
  return typeof body.runId === "string" && body.runId === expectedRunId;
24283
24594
  }
24284
24595
  async function readRunTerminalArtifact(runDirectory) {
24285
- const artifactsDir = join22(runDirectory, "artifacts");
24596
+ const artifactsDir = join24(runDirectory, "artifacts");
24286
24597
  for (const file of RUN_TERMINAL_ARTIFACT_FILES) {
24287
- const path = join22(artifactsDir, file);
24598
+ const path = join24(artifactsDir, file);
24288
24599
  const read3 = await readTerminalArtifactAtPath(path, file);
24289
24600
  if (read3 !== void 0) return read3;
24290
24601
  }
24291
24602
  for (const relative3 of RUN_TERMINAL_ERROR_FALLBACK_RELATIVE_PATHS) {
24292
- const path = join22(runDirectory, relative3);
24603
+ const path = join24(runDirectory, relative3);
24293
24604
  const read3 = await readTerminalArtifactAtPath(path, "error.json");
24294
24605
  if (read3 !== void 0) return read3;
24295
24606
  }
@@ -24549,13 +24860,13 @@ var init_reviewer_dispatch = __esm({
24549
24860
  });
24550
24861
 
24551
24862
  // src/public-cli/reviewer-dispatch-rejection.ts
24552
- import { readFile as readFile13, unlink as unlink3 } from "node:fs/promises";
24553
- import { join as join23 } from "node:path";
24863
+ import { readFile as readFile14, unlink as unlink3 } from "node:fs/promises";
24864
+ import { join as join25 } from "node:path";
24554
24865
  function isReviewerPreflightViolation(value) {
24555
24866
  return typeof value === "string" && REVIEWER_PREFLIGHT_VIOLATIONS.includes(value);
24556
24867
  }
24557
24868
  function reviewerDispatchRejectionPath(runDirectory) {
24558
- return join23(runDirectory, REVIEWER_DISPATCH_REJECTION_FILE);
24869
+ return join25(runDirectory, REVIEWER_DISPATCH_REJECTION_FILE);
24559
24870
  }
24560
24871
  async function clearReviewerDispatchRejection(runDirectory) {
24561
24872
  try {
@@ -24570,7 +24881,7 @@ async function clearReviewerDispatchRejection(runDirectory) {
24570
24881
  async function readReviewerDispatchRejection(runDirectory) {
24571
24882
  let raw;
24572
24883
  try {
24573
- raw = await readFile13(reviewerDispatchRejectionPath(runDirectory), "utf8");
24884
+ raw = await readFile14(reviewerDispatchRejectionPath(runDirectory), "utf8");
24574
24885
  } catch (error) {
24575
24886
  if (error instanceof Error && "code" in error && error.code === "ENOENT") {
24576
24887
  return void 0;
@@ -24936,8 +25247,8 @@ var init_terminal = __esm({
24936
25247
 
24937
25248
  // src/public-cli/settlement.ts
24938
25249
  import { randomUUID as randomUUID3 } from "node:crypto";
24939
- import { appendFile as appendFile2, readFile as readFile14, readdir as readdir5, writeFile as writeFile7 } from "node:fs/promises";
24940
- import { dirname as dirname10, join as join24 } from "node:path";
25250
+ import { appendFile as appendFile2, readFile as readFile15, readdir as readdir5, writeFile as writeFile8 } from "node:fs/promises";
25251
+ import { dirname as dirname10, join as join26 } from "node:path";
24941
25252
  function sealedLedgerHome(admitted) {
24942
25253
  return homeFromRunDirectory(admitted.runDirectory);
24943
25254
  }
@@ -25029,7 +25340,7 @@ function presentControlledFailure(failure, io) {
25029
25340
  }
25030
25341
  async function inspectJudgeSession(sessionFile) {
25031
25342
  try {
25032
- await readFile14(sessionFile, "utf8");
25343
+ await readFile15(sessionFile, "utf8");
25033
25344
  return { state: "present" };
25034
25345
  } catch (error) {
25035
25346
  if (isMissingPathError3(error)) return { state: "missing" };
@@ -25054,33 +25365,92 @@ function isTypedActivationError(error) {
25054
25365
  const cause = error.knownCause;
25055
25366
  return cause === "provider" || cause === "activation" || cause === "session" || cause === "output" || cause === "timeout" || cause === "unrecognized";
25056
25367
  }
25057
- function classifyPostAdmissionFailure(input) {
25058
- if (Object.hasOwn(input, "thrown")) {
25059
- const error = input.thrown;
25060
- if (isTypedActivationError(error)) {
25061
- const identity = thrownIdentity(error);
25062
- if (error.failureCode !== void 0 && identity.code === void 0) {
25063
- identity.code = error.failureCode;
25064
- }
25065
- return {
25066
- cause: error.knownCause,
25067
- diagnostic: error.message || error.name || "unrecognized exception",
25068
- identity
25069
- };
25070
- }
25071
- if (error instanceof Error) {
25072
- const identity = thrownIdentity(error);
25073
- return {
25074
- cause: "unrecognized",
25075
- diagnostic: error.message || error.name || "unrecognized exception",
25076
- identity
25077
- };
25368
+ function flattenThrownFailureLeaves(error) {
25369
+ if (!(error instanceof AggregateError)) {
25370
+ return [error];
25371
+ }
25372
+ const leaves = [];
25373
+ for (const item of error.errors) {
25374
+ leaves.push(...flattenThrownFailureLeaves(item));
25375
+ }
25376
+ return leaves;
25377
+ }
25378
+ function projectThrownFailureLeaf(error) {
25379
+ if (isTypedActivationError(error)) {
25380
+ const identity = thrownIdentity(error);
25381
+ if (error.failureCode !== void 0 && identity.code === void 0) {
25382
+ identity.code = error.failureCode;
25078
25383
  }
25384
+ return {
25385
+ cause: error.knownCause,
25386
+ diagnostic: error.message || error.name || "unrecognized exception",
25387
+ identity,
25388
+ ...error.details === void 0 ? {} : { details: error.details }
25389
+ };
25390
+ }
25391
+ if (error instanceof Error) {
25392
+ const identity = thrownIdentity(error);
25079
25393
  return {
25080
25394
  cause: "unrecognized",
25081
- diagnostic: String(error)
25395
+ diagnostic: error.message || error.name || "unrecognized exception",
25396
+ identity
25082
25397
  };
25083
25398
  }
25399
+ return {
25400
+ cause: "unrecognized",
25401
+ diagnostic: String(error)
25402
+ };
25403
+ }
25404
+ function classifyThrownFailure(error) {
25405
+ if (!(error instanceof AggregateError)) {
25406
+ return projectThrownFailureLeaf(error);
25407
+ }
25408
+ const leaves = flattenThrownFailureLeaves(error);
25409
+ if (leaves.length === 0) {
25410
+ return projectThrownFailureLeaf(error);
25411
+ }
25412
+ const primary = projectThrownFailureLeaf(leaves[0]);
25413
+ if (leaves.length === 1) {
25414
+ return primary;
25415
+ }
25416
+ const priorConcurrent = Array.isArray(primary.details?.concurrentFailures) ? primary.details.concurrentFailures : [];
25417
+ const concurrentFailures = [
25418
+ ...priorConcurrent,
25419
+ ...leaves.slice(1).map((leaf) => {
25420
+ const secondary = projectThrownFailureLeaf(leaf);
25421
+ return {
25422
+ cause: secondary.cause,
25423
+ diagnostic: secondary.diagnostic,
25424
+ ...secondary.identity === void 0 ? {} : { identity: secondary.identity },
25425
+ ...secondary.details === void 0 ? {} : { details: secondary.details }
25426
+ };
25427
+ })
25428
+ ];
25429
+ return {
25430
+ cause: primary.cause,
25431
+ diagnostic: primary.diagnostic,
25432
+ ...primary.identity === void 0 ? {} : { identity: primary.identity },
25433
+ details: {
25434
+ ...primary.details ?? {},
25435
+ concurrentFailures
25436
+ }
25437
+ };
25438
+ }
25439
+ function withKnownDetails(failure, knownDetails) {
25440
+ if (knownDetails === void 0) return failure;
25441
+ const { timedOut: _knownTimedOut, ...rest } = knownDetails;
25442
+ return {
25443
+ ...failure,
25444
+ details: {
25445
+ ...rest,
25446
+ ...failure.details ?? {}
25447
+ }
25448
+ };
25449
+ }
25450
+ function classifyPostAdmissionFailure(input) {
25451
+ if (Object.hasOwn(input, "thrown")) {
25452
+ return classifyThrownFailure(input.thrown);
25453
+ }
25084
25454
  if (input.knownCause !== void 0) {
25085
25455
  const fallback = input.knownCause === "provider" ? "provider failure" : input.knownCause === "session" ? "session unreadable" : input.knownCause === "output" ? "role run completed without a lawful typed terminal result" : `role run failed (${input.knownCause})`;
25086
25456
  const diagnostic = input.knownDiagnostic !== void 0 && input.knownDiagnostic.trim() !== "" ? input.knownDiagnostic : conciseChildDiagnostic(input.stderr, fallback);
@@ -25099,39 +25469,54 @@ function classifyPostAdmissionFailure(input) {
25099
25469
  };
25100
25470
  }
25101
25471
  if (input.timedOut) {
25102
- return {
25103
- cause: "timeout",
25104
- diagnostic: "role run timed out",
25105
- details: { timedOut: true, exitCode: input.code }
25106
- };
25472
+ return withKnownDetails(
25473
+ {
25474
+ cause: "timeout",
25475
+ diagnostic: "role run timed out",
25476
+ details: { timedOut: true, exitCode: input.code }
25477
+ },
25478
+ input.knownDetails
25479
+ );
25107
25480
  }
25108
25481
  if (input.code !== 0) {
25109
25482
  const fallback = `role run failed with exit ${input.code ?? "null"}`;
25110
- return {
25111
- cause: "activation",
25112
- diagnostic: conciseChildDiagnostic(input.stderr, fallback),
25113
- details: { exitCode: input.code }
25114
- };
25483
+ return withKnownDetails(
25484
+ {
25485
+ cause: "activation",
25486
+ diagnostic: conciseChildDiagnostic(input.stderr, fallback),
25487
+ details: { exitCode: input.code }
25488
+ },
25489
+ input.knownDetails
25490
+ );
25115
25491
  }
25116
25492
  if (input.session?.state === "missing") {
25117
- return {
25118
- cause: "session",
25119
- diagnostic: "role run left no readable session transcript",
25120
- details: { exitCode: input.code, session: "missing" }
25121
- };
25493
+ return withKnownDetails(
25494
+ {
25495
+ cause: "session",
25496
+ diagnostic: "role run left no readable session transcript",
25497
+ details: { exitCode: input.code, session: "missing" }
25498
+ },
25499
+ input.knownDetails
25500
+ );
25122
25501
  }
25123
25502
  if (input.session?.state === "unreadable") {
25124
- return {
25125
- cause: "session",
25126
- diagnostic: input.session.diagnostic,
25127
- details: { exitCode: input.code, session: "unreadable" }
25128
- };
25503
+ return withKnownDetails(
25504
+ {
25505
+ cause: "session",
25506
+ diagnostic: input.session.diagnostic,
25507
+ details: { exitCode: input.code, session: "unreadable" }
25508
+ },
25509
+ input.knownDetails
25510
+ );
25129
25511
  }
25130
- return {
25131
- cause: "output",
25132
- diagnostic: "role run completed without a lawful typed terminal result",
25133
- details: { exitCode: input.code }
25134
- };
25512
+ return withKnownDetails(
25513
+ {
25514
+ cause: "output",
25515
+ diagnostic: "role run completed without a lawful typed terminal result",
25516
+ details: { exitCode: input.code }
25517
+ },
25518
+ input.knownDetails
25519
+ );
25135
25520
  }
25136
25521
  function explicitInternalKnownFailureClassificationInput(failure) {
25137
25522
  if (failure === void 0) return {};
@@ -25171,7 +25556,7 @@ function sessionReadFailure(error, fallbackMessage) {
25171
25556
  return failed;
25172
25557
  }
25173
25558
  async function readBoundSessionEntries(sessionFile) {
25174
- const text = await readFile14(sessionFile, "utf8");
25559
+ const text = await readFile15(sessionFile, "utf8");
25175
25560
  const entries = [];
25176
25561
  for (const line2 of text.trim().split("\n").filter(Boolean)) {
25177
25562
  try {
@@ -25258,7 +25643,7 @@ async function readSessionProviderStop(sessionFile) {
25258
25643
  }
25259
25644
  }
25260
25645
  async function readBoundEvidenceChildKnownFailure(sessionFile) {
25261
- const childDirectory = join24(dirname10(sessionFile), "evidence-children");
25646
+ const childDirectory = join26(dirname10(sessionFile), "evidence-children");
25262
25647
  let names;
25263
25648
  try {
25264
25649
  names = await readdir5(childDirectory);
@@ -25269,7 +25654,7 @@ async function readBoundEvidenceChildKnownFailure(sessionFile) {
25269
25654
  for (const file of names.filter((name) => name.endsWith(".jsonl")).sort().reverse()) {
25270
25655
  let entries;
25271
25656
  try {
25272
- entries = await readBoundSessionEntries(join24(childDirectory, file));
25657
+ entries = await readBoundSessionEntries(join26(childDirectory, file));
25273
25658
  } catch (error) {
25274
25659
  throw sessionReadFailure(error, "failed to read discovered evidence-child session");
25275
25660
  }
@@ -25323,36 +25708,67 @@ async function loadBoundAuditorVolumes(sessionFile) {
25323
25708
  latestParentUserIndex = i;
25324
25709
  break;
25325
25710
  }
25326
- const childDirectory = join24(dirname10(sessionFile), "auditor-roles");
25327
- let names;
25328
- try {
25329
- names = await readdir5(childDirectory);
25330
- } catch (error) {
25331
- if (isMissingPathError3(error)) return void 0;
25332
- throw sessionReadFailure(error, "failed to read bound auditor session directory");
25333
- }
25711
+ const runDirectory = join26(dirname10(sessionFile), "..");
25712
+ const memoryNests = await resolveTicketSeatMemoryNestDirectories({
25713
+ runDirectory,
25714
+ seats: ["auditor"]
25715
+ });
25716
+ const childDirectories = [
25717
+ join26(dirname10(sessionFile), "auditor-roles"),
25718
+ ...memoryNests
25719
+ ];
25334
25720
  const valid = [];
25335
- for (const file of names.filter((name) => name.endsWith(".jsonl")).sort().reverse()) {
25336
- let entries;
25721
+ let sawAnyDirectory = false;
25722
+ for (const childDirectory of childDirectories) {
25723
+ let names;
25337
25724
  try {
25338
- entries = await readBoundSessionEntries(join24(childDirectory, file));
25725
+ names = await readdir5(childDirectory);
25726
+ sawAnyDirectory = true;
25339
25727
  } catch (error) {
25340
- throw sessionReadFailure(error, "failed to read discovered auditor session");
25728
+ if (isMissingPathError3(error)) continue;
25729
+ throw sessionReadFailure(error, "failed to read bound auditor session directory");
25730
+ }
25731
+ for (const file of names.filter((name) => name.endsWith(".jsonl")).sort().reverse()) {
25732
+ let entries;
25733
+ try {
25734
+ entries = await readBoundSessionEntries(join26(childDirectory, file));
25735
+ } catch (error) {
25736
+ throw sessionReadFailure(error, "failed to read discovered auditor session");
25737
+ }
25738
+ const header = entries.find((entry) => entry.type === "session");
25739
+ if (!isRecord17(header)) continue;
25740
+ const bindingIndexes = [];
25741
+ for (let i = 0; i < entries.length; i += 1) {
25742
+ const entry = entries[i];
25743
+ if (entry?.type === "custom" && entry.customType === AUDITOR_PARENT_ATTEMPT_BINDING_ENTRY_TYPE) {
25744
+ bindingIndexes.push(i);
25745
+ }
25746
+ }
25747
+ const bindingPasses = bindingIndexes.length > 0 ? bindingIndexes.map((start, idx) => ({
25748
+ entry: entries[start],
25749
+ start,
25750
+ end: idx + 1 < bindingIndexes.length ? bindingIndexes[idx + 1] : entries.length
25751
+ })) : [{ entry: void 0, start: 0, end: entries.length }];
25752
+ for (const { entry: bindingEntry, start, end } of bindingPasses) {
25753
+ const bindingParent = bindingEntry !== void 0 && isRecord17(bindingEntry.data) && isRecord17(bindingEntry.data.parent) ? bindingEntry.data.parent : void 0;
25754
+ const attemptEntryId = typeof bindingParent?.attemptEntryId === "string" ? bindingParent.attemptEntryId : void 0;
25755
+ const attemptEntryIndex = attemptEntryId === void 0 ? -1 : parentEntries.findIndex((entry) => entry.id === attemptEntryId);
25756
+ const boundSessionFile = typeof bindingParent?.sessionFile === "string" ? bindingParent.sessionFile : typeof header.parentSession === "string" ? header.parentSession : void 0;
25757
+ if (boundSessionFile !== sessionFile) continue;
25758
+ if (bindingParent !== void 0 && (bindingParent.sessionId !== parentId || attemptEntryIndex < latestParentUserIndex)) {
25759
+ continue;
25760
+ }
25761
+ if (bindingParent === void 0 && header.parentSession !== sessionFile) continue;
25762
+ valid.push({
25763
+ entries: entries.slice(start, end),
25764
+ parentId,
25765
+ sessionFile,
25766
+ ...attemptEntryId === void 0 ? {} : { attemptEntryId }
25767
+ });
25768
+ }
25341
25769
  }
25342
- const header = entries.find((entry) => entry.type === "session");
25343
- if (!isRecord17(header) || header.parentSession !== sessionFile) continue;
25344
- const bindingEntry = entries.find((entry) => entry.type === "custom" && entry.customType === AUDITOR_PARENT_ATTEMPT_BINDING_ENTRY_TYPE);
25345
- const bindingParent = isRecord17(bindingEntry?.data) && isRecord17(bindingEntry.data.parent) ? bindingEntry.data.parent : void 0;
25346
- const attemptEntryId = typeof bindingParent?.attemptEntryId === "string" ? bindingParent.attemptEntryId : void 0;
25347
- const attemptEntryIndex = attemptEntryId === void 0 ? -1 : parentEntries.findIndex((entry) => entry.id === attemptEntryId);
25348
- if (bindingParent?.sessionId !== parentId || bindingParent.sessionFile !== sessionFile || attemptEntryIndex < latestParentUserIndex) continue;
25349
- valid.push({
25350
- entries,
25351
- parentId,
25352
- sessionFile,
25353
- ...attemptEntryId === void 0 ? {} : { attemptEntryId }
25354
- });
25355
25770
  }
25771
+ if (!sawAnyDirectory && valid.length === 0) return void 0;
25356
25772
  return valid;
25357
25773
  }
25358
25774
  function complianceFailureFromAuditorVolumes(volumes) {
@@ -26080,16 +26496,26 @@ function projectTerminalGateFact(rounds) {
26080
26496
  }))
26081
26497
  };
26082
26498
  }
26083
- async function extractGateFactFromSessionDirectory(sessionDirectory) {
26084
- const rounds = await readAnalystGateCyclesFromAuditorRoles(
26085
- join24(sessionDirectory, "auditor-roles")
26086
- );
26499
+ async function extractGateFactFromSessionDirectory(sessionDirectory, options = {}) {
26500
+ const runDirectory = options.runDirectory ?? join26(sessionDirectory, "..");
26501
+ const memoryNests = await resolveTicketSeatMemoryNestDirectories({
26502
+ runDirectory,
26503
+ seats: ["inspector", "notary"]
26504
+ });
26505
+ const directories = [
26506
+ join26(sessionDirectory, "auditor-roles"),
26507
+ ...memoryNests
26508
+ ];
26509
+ const parentSessionFile = options.parentSessionFile ?? join26(sessionDirectory, "session.jsonl");
26510
+ const rounds = await readAnalystGateCyclesFromAuditorRoles(directories, {
26511
+ parentSessionFile
26512
+ });
26087
26513
  return projectTerminalGateFact(rounds);
26088
26514
  }
26089
- async function withOptionalGateProjection(base, sessionDirectory) {
26515
+ async function withOptionalGateProjection(base, sessionDirectory, gateContext = {}) {
26090
26516
  const secondaryEvidence = base.roleOutcome.kind === "failure" ? base.roleOutcome.decisiveFacts.secondaryEvidence : void 0;
26091
26517
  if (isRecord17(secondaryEvidence) && secondaryEvidence.kind === "role_infrastructure_failure" && (secondaryEvidence.stage === "gatekeeper" || secondaryEvidence.stage === "inspector" || secondaryEvidence.stage === "notary")) return base;
26092
- const gate = await extractGateFactFromSessionDirectory(sessionDirectory);
26518
+ const gate = await extractGateFactFromSessionDirectory(sessionDirectory, gateContext);
26093
26519
  return gate === void 0 ? base : { ...base, gate };
26094
26520
  }
26095
26521
  function extractNavigatorFact(entries) {
@@ -26178,9 +26604,9 @@ async function extractNavigatorFactFromAdmittedSession(sessionFile) {
26178
26604
  async function publishJudgeArtifacts(admitted, roleOutcome, coordinates) {
26179
26605
  await appendRunAttemptHistory({ role: admitted.role, runId: admitted.runId, sessionFile: coordinates.sessionFile }, roleOutcome);
26180
26606
  const artifactsDir = await ensureRunArtifactsDir(admitted.runDirectory);
26181
- const reportPath = join24(artifactsDir, "report.json");
26182
- const evidencePath = join24(artifactsDir, "evidence.json");
26183
- await writeFile7(
26607
+ const reportPath = join26(artifactsDir, "report.json");
26608
+ const evidencePath = join26(artifactsDir, "evidence.json");
26609
+ await writeFile8(
26184
26610
  reportPath,
26185
26611
  `${JSON.stringify(
26186
26612
  {
@@ -26194,7 +26620,7 @@ async function publishJudgeArtifacts(admitted, roleOutcome, coordinates) {
26194
26620
  `,
26195
26621
  "utf8"
26196
26622
  );
26197
- await writeFile7(
26623
+ await writeFile8(
26198
26624
  evidencePath,
26199
26625
  `${JSON.stringify(
26200
26626
  {
@@ -26223,9 +26649,9 @@ async function publishJudgeArtifacts(admitted, roleOutcome, coordinates) {
26223
26649
  async function publishCoderArtifacts(admitted, roleOutcome, coordinates, options = {}) {
26224
26650
  await appendRunAttemptHistory({ role: admitted.role, runId: admitted.runId, sessionFile: coordinates.sessionFile }, roleOutcome);
26225
26651
  const artifactsDir = await ensureRunArtifactsDir(admitted.runDirectory);
26226
- const reportPath = join24(artifactsDir, "report.json");
26227
- const evidencePath = join24(artifactsDir, "evidence.json");
26228
- await writeFile7(
26652
+ const reportPath = join26(artifactsDir, "report.json");
26653
+ const evidencePath = join26(artifactsDir, "evidence.json");
26654
+ await writeFile8(
26229
26655
  reportPath,
26230
26656
  `${JSON.stringify(
26231
26657
  {
@@ -26241,7 +26667,7 @@ async function publishCoderArtifacts(admitted, roleOutcome, coordinates, options
26241
26667
  `,
26242
26668
  "utf8"
26243
26669
  );
26244
- await writeFile7(
26670
+ await writeFile8(
26245
26671
  evidencePath,
26246
26672
  `${JSON.stringify(
26247
26673
  {
@@ -26383,9 +26809,9 @@ function extractFixerMethodInvocations(entries, options) {
26383
26809
  async function publishFixerArtifacts(admitted, roleOutcome, coordinates, options) {
26384
26810
  await appendRunAttemptHistory({ role: admitted.role, runId: admitted.runId, sessionFile: coordinates.sessionFile }, roleOutcome);
26385
26811
  const artifactsDir = await ensureRunArtifactsDir(admitted.runDirectory);
26386
- const reportPath = join24(artifactsDir, "report.json");
26387
- const evidencePath = join24(artifactsDir, "evidence.json");
26388
- await writeFile7(
26812
+ const reportPath = join26(artifactsDir, "report.json");
26813
+ const evidencePath = join26(artifactsDir, "evidence.json");
26814
+ await writeFile8(
26389
26815
  reportPath,
26390
26816
  `${JSON.stringify(
26391
26817
  {
@@ -26401,7 +26827,7 @@ async function publishFixerArtifacts(admitted, roleOutcome, coordinates, options
26401
26827
  `,
26402
26828
  "utf8"
26403
26829
  );
26404
- await writeFile7(
26830
+ await writeFile8(
26405
26831
  evidencePath,
26406
26832
  `${JSON.stringify(
26407
26833
  {
@@ -26483,9 +26909,9 @@ async function settleLawfulFixerTerminalResult(admitted, authority, options) {
26483
26909
  async function publishCollectorArtifacts(admitted, roleOutcome, coordinates, options = {}) {
26484
26910
  await appendRunAttemptHistory({ role: admitted.role, runId: admitted.runId, sessionFile: coordinates.sessionFile }, roleOutcome);
26485
26911
  const artifactsDir = await ensureRunArtifactsDir(admitted.runDirectory);
26486
- const reportPath = join24(artifactsDir, "report.json");
26487
- const evidencePath = join24(artifactsDir, "evidence.json");
26488
- await writeFile7(
26912
+ const reportPath = join26(artifactsDir, "report.json");
26913
+ const evidencePath = join26(artifactsDir, "evidence.json");
26914
+ await writeFile8(
26489
26915
  reportPath,
26490
26916
  `${JSON.stringify(
26491
26917
  {
@@ -26500,7 +26926,7 @@ async function publishCollectorArtifacts(admitted, roleOutcome, coordinates, opt
26500
26926
  `,
26501
26927
  "utf8"
26502
26928
  );
26503
- await writeFile7(
26929
+ await writeFile8(
26504
26930
  evidencePath,
26505
26931
  `${JSON.stringify(
26506
26932
  {
@@ -26591,9 +27017,9 @@ async function trySettleCollectorTerminalResult(admitted, authority) {
26591
27017
  async function publishDoctorArtifacts(admitted, roleOutcome, coordinates, options = {}) {
26592
27018
  await appendRunAttemptHistory({ role: admitted.role, runId: admitted.runId, sessionFile: coordinates.sessionFile }, roleOutcome);
26593
27019
  const artifactsDir = await ensureRunArtifactsDir(admitted.runDirectory);
26594
- const reportPath = join24(artifactsDir, "report.json");
26595
- const evidencePath = join24(artifactsDir, "evidence.json");
26596
- await writeFile7(
27020
+ const reportPath = join26(artifactsDir, "report.json");
27021
+ const evidencePath = join26(artifactsDir, "evidence.json");
27022
+ await writeFile8(
26597
27023
  reportPath,
26598
27024
  `${JSON.stringify(
26599
27025
  {
@@ -26608,7 +27034,7 @@ async function publishDoctorArtifacts(admitted, roleOutcome, coordinates, option
26608
27034
  `,
26609
27035
  "utf8"
26610
27036
  );
26611
- await writeFile7(
27037
+ await writeFile8(
26612
27038
  evidencePath,
26613
27039
  `${JSON.stringify(
26614
27040
  {
@@ -26939,9 +27365,9 @@ function extractReviewerMethodInvocations(entries, options) {
26939
27365
  async function publishReviewerArtifacts(admitted, roleOutcome, coordinates, options) {
26940
27366
  await appendRunAttemptHistory({ role: admitted.role, runId: admitted.runId, sessionFile: coordinates.sessionFile }, roleOutcome);
26941
27367
  const artifactsDir = await ensureRunArtifactsDir(admitted.runDirectory);
26942
- const reportPath = join24(artifactsDir, "report.json");
26943
- const evidencePath = join24(artifactsDir, "evidence.json");
26944
- await writeFile7(
27368
+ const reportPath = join26(artifactsDir, "report.json");
27369
+ const evidencePath = join26(artifactsDir, "evidence.json");
27370
+ await writeFile8(
26945
27371
  reportPath,
26946
27372
  `${JSON.stringify(
26947
27373
  {
@@ -26956,7 +27382,7 @@ async function publishReviewerArtifacts(admitted, roleOutcome, coordinates, opti
26956
27382
  `,
26957
27383
  "utf8"
26958
27384
  );
26959
- await writeFile7(
27385
+ await writeFile8(
26960
27386
  evidencePath,
26961
27387
  `${JSON.stringify(
26962
27388
  {
@@ -27067,9 +27493,9 @@ function extractMergerMethodInvocations(entries, options) {
27067
27493
  async function publishMergerArtifacts(admitted, roleOutcome, coordinates, options) {
27068
27494
  await appendRunAttemptHistory({ role: admitted.role, runId: admitted.runId, sessionFile: coordinates.sessionFile }, roleOutcome);
27069
27495
  const artifactsDir = await ensureRunArtifactsDir(admitted.runDirectory);
27070
- const reportPath = join24(artifactsDir, "report.json");
27071
- const evidencePath = join24(artifactsDir, "evidence.json");
27072
- await writeFile7(
27496
+ const reportPath = join26(artifactsDir, "report.json");
27497
+ const evidencePath = join26(artifactsDir, "evidence.json");
27498
+ await writeFile8(
27073
27499
  reportPath,
27074
27500
  `${JSON.stringify(
27075
27501
  {
@@ -27084,7 +27510,7 @@ async function publishMergerArtifacts(admitted, roleOutcome, coordinates, option
27084
27510
  `,
27085
27511
  "utf8"
27086
27512
  );
27087
- await writeFile7(
27513
+ await writeFile8(
27088
27514
  evidencePath,
27089
27515
  `${JSON.stringify(
27090
27516
  {
@@ -27217,7 +27643,7 @@ function uniqueFailureFallbackDirs(runDirectory, baseDir) {
27217
27643
  return dirs;
27218
27644
  }
27219
27645
  async function resolveFailureArtifactsBase(runDirectory) {
27220
- const artifactsDir = join24(runDirectory, "artifacts");
27646
+ const artifactsDir = join26(runDirectory, "artifacts");
27221
27647
  try {
27222
27648
  await ensureRunArtifactsDir(runDirectory);
27223
27649
  return { baseDir: artifactsDir };
@@ -27233,13 +27659,13 @@ async function writeFailureJsonRetainingCause(preferredCandidates, uniqueFallbac
27233
27659
  const candidates = [
27234
27660
  ...preferredCandidates,
27235
27661
  // One unique name per fallback dir — collisions on fixed names cannot exhaust this.
27236
- ...uniqueFallbackDirs.map((dir) => join24(dir, `${stem}.${randomUUID3()}.json`))
27662
+ ...uniqueFallbackDirs.map((dir) => join26(dir, `${stem}.${randomUUID3()}.json`))
27237
27663
  ];
27238
27664
  for (let i = 0; i < candidates.length; i += 1) {
27239
27665
  const path = candidates[i];
27240
27666
  const payload = issues.length === 0 ? basePayload : { ...basePayload, publicationIssues: issues };
27241
27667
  try {
27242
- await writeFile7(
27668
+ await writeFile8(
27243
27669
  path,
27244
27670
  `${JSON.stringify(payload, null, 2)}
27245
27671
  `,
@@ -27278,26 +27704,26 @@ async function publishFailureArtifacts(admitted, failure, authority) {
27278
27704
  } catch (error) {
27279
27705
  priorIssues.push(publicationAttemptFromError(sessionFile, error));
27280
27706
  }
27281
- const underArtifacts = baseDir === join24(admitted.runDirectory, "artifacts");
27707
+ const underArtifacts = baseDir === join26(admitted.runDirectory, "artifacts");
27282
27708
  const uniqueFallbackDirs = uniqueFailureFallbackDirs(
27283
27709
  admitted.runDirectory,
27284
27710
  baseDir
27285
27711
  );
27286
27712
  const errorCandidates = underArtifacts ? [
27287
- join24(baseDir, "error.json"),
27288
- join24(baseDir, "error.settlement.json"),
27289
- join24(admitted.runDirectory, "error.settlement.json")
27713
+ join26(baseDir, "error.json"),
27714
+ join26(baseDir, "error.settlement.json"),
27715
+ join26(admitted.runDirectory, "error.settlement.json")
27290
27716
  ] : [
27291
- join24(baseDir, "error.settlement.json"),
27292
- join24(baseDir, "error.json")
27717
+ join26(baseDir, "error.settlement.json"),
27718
+ join26(baseDir, "error.json")
27293
27719
  ];
27294
27720
  const evidenceCandidates = underArtifacts ? [
27295
- join24(baseDir, "evidence.json"),
27296
- join24(baseDir, "evidence.settlement.json"),
27297
- join24(admitted.runDirectory, "evidence.settlement.json")
27721
+ join26(baseDir, "evidence.json"),
27722
+ join26(baseDir, "evidence.settlement.json"),
27723
+ join26(admitted.runDirectory, "evidence.settlement.json")
27298
27724
  ] : [
27299
- join24(baseDir, "evidence.settlement.json"),
27300
- join24(baseDir, "evidence.json")
27725
+ join26(baseDir, "evidence.settlement.json"),
27726
+ join26(baseDir, "evidence.json")
27301
27727
  ];
27302
27728
  const errorPayloadBase = {
27303
27729
  kind: "error",
@@ -27488,6 +27914,7 @@ var init_settlement = __esm({
27488
27914
  "use strict";
27489
27915
  init_analyst_gate_cycles_read();
27490
27916
  init_sitian_facade();
27917
+ init_ticket_seat_memory();
27491
27918
  init_submission_ledger();
27492
27919
  init_audit_escalation();
27493
27920
  init_auditor_soul();
@@ -27569,11 +27996,11 @@ var init_turn_request = __esm({
27569
27996
 
27570
27997
  // src/host-transition-prior-native.ts
27571
27998
  import { access as access2, readdir as readdir6 } from "node:fs/promises";
27572
- import { join as join25 } from "node:path";
27999
+ import { join as join27 } from "node:path";
27573
28000
  function isKnownRoleTurnHost(value) {
27574
28001
  return KNOWN_ROLE_TURN_HOSTS.includes(value);
27575
28002
  }
27576
- function isEnoent(error) {
28003
+ function isEnoent2(error) {
27577
28004
  return typeof error === "object" && error !== null && error.code === "ENOENT";
27578
28005
  }
27579
28006
  async function listPiNativeRecordPaths(sessionFile) {
@@ -27581,17 +28008,17 @@ async function listPiNativeRecordPaths(sessionFile) {
27581
28008
  await access2(sessionFile);
27582
28009
  return [sessionFile];
27583
28010
  } catch (error) {
27584
- if (isEnoent(error)) return [];
28011
+ if (isEnoent2(error)) return [];
27585
28012
  throw error;
27586
28013
  }
27587
28014
  }
27588
28015
  async function listGrokNativeRecordPaths(runDirectory) {
27589
- const grokSessionsDir = join25(runDirectory, "grok-home", "sessions");
28016
+ const grokSessionsDir = join27(runDirectory, "grok-home", "sessions");
27590
28017
  let encodedCwds;
27591
28018
  try {
27592
28019
  encodedCwds = await readdir6(grokSessionsDir, { withFileTypes: true });
27593
28020
  } catch (error) {
27594
- if (isEnoent(error)) return [];
28021
+ if (isEnoent2(error)) return [];
27595
28022
  throw error;
27596
28023
  }
27597
28024
  const updatesPaths = [];
@@ -27599,14 +28026,14 @@ async function listGrokNativeRecordPaths(runDirectory) {
27599
28026
  if (!cwdEntry.isDirectory()) continue;
27600
28027
  let sessionDirs;
27601
28028
  try {
27602
- sessionDirs = await readdir6(join25(grokSessionsDir, cwdEntry.name), { withFileTypes: true });
28029
+ sessionDirs = await readdir6(join27(grokSessionsDir, cwdEntry.name), { withFileTypes: true });
27603
28030
  } catch (error) {
27604
- if (isEnoent(error)) continue;
28031
+ if (isEnoent2(error)) continue;
27605
28032
  throw error;
27606
28033
  }
27607
28034
  for (const sessEntry of sessionDirs) {
27608
28035
  if (!sessEntry.isDirectory()) continue;
27609
- updatesPaths.push(join25(grokSessionsDir, cwdEntry.name, sessEntry.name, "updates.jsonl"));
28036
+ updatesPaths.push(join27(grokSessionsDir, cwdEntry.name, sessEntry.name, "updates.jsonl"));
27610
28037
  }
27611
28038
  }
27612
28039
  updatesPaths.sort();
@@ -27616,7 +28043,7 @@ async function listGrokNativeRecordPaths(runDirectory) {
27616
28043
  await access2(updatesFile);
27617
28044
  present.push(updatesFile);
27618
28045
  } catch (error) {
27619
- if (!isEnoent(error)) throw error;
28046
+ if (!isEnoent2(error)) throw error;
27620
28047
  }
27621
28048
  }
27622
28049
  return present;
@@ -27633,7 +28060,8 @@ async function projectHostTransitionPriorNative(input) {
27633
28060
  priorNativePaths: paths2
27634
28061
  };
27635
28062
  }
27636
- const paths = await listGrokNativeRecordPaths(input.runDirectory);
28063
+ const grokRoot = input.previousRunDirectory ?? input.runDirectory;
28064
+ const paths = await listGrokNativeRecordPaths(grokRoot);
27637
28065
  return {
27638
28066
  previousHost: "grok-build",
27639
28067
  priorNativePaths: paths
@@ -27687,7 +28115,7 @@ var init_public_run_credentials = __esm({
27687
28115
  import { constants as fsConstants } from "node:fs";
27688
28116
  import { randomUUID as randomUUID4 } from "node:crypto";
27689
28117
  import { lstat as lstat5, mkdir as mkdir4, open as open2 } from "node:fs/promises";
27690
- import { join as join26 } from "node:path";
28118
+ import { join as join28 } from "node:path";
27691
28119
  function presentTerminal(terminal, io) {
27692
28120
  if (terminal.roleOutcome.kind === "failure" || terminal.roleOutcome.kind === "no_receipt") {
27693
28121
  presentFailureTerminal(terminal, io);
@@ -27706,7 +28134,7 @@ async function finalizeExceptionRunBestEffort(runDirectory, io) {
27706
28134
  }
27707
28135
  }
27708
28136
  function runArtifactsDirectory(runDirectory) {
27709
- return join26(runDirectory, "artifacts");
28137
+ return join28(runDirectory, "artifacts");
27710
28138
  }
27711
28139
  async function ensureRealArtifactsDirectory(runDirectory) {
27712
28140
  const runStat = await lstat5(runDirectory);
@@ -27789,7 +28217,7 @@ function jsonSafeReplacer() {
27789
28217
  }
27790
28218
  async function retainDispatchError(admitted, principalAuthority, sessionAppender, attempt, error) {
27791
28219
  const artifactsDir = await ensureRealArtifactsDirectory(admitted.runDirectory);
27792
- const filePath = join26(
28220
+ const filePath = join28(
27793
28221
  artifactsDir,
27794
28222
  `dispatch-error-attempt-${attempt}-${randomUUID4()}.json`
27795
28223
  );
@@ -28036,11 +28464,11 @@ var init_auto_resume = __esm({
28036
28464
  });
28037
28465
 
28038
28466
  // src/public-cli/post-admission.ts
28039
- import { readFile as readFile15, writeFile as writeFile8 } from "node:fs/promises";
28040
- import { join as join27 } from "node:path";
28467
+ import { readFile as readFile16, writeFile as writeFile9 } from "node:fs/promises";
28468
+ import { join as join29 } from "node:path";
28041
28469
  async function readInvocationHost(runDirectory) {
28042
28470
  try {
28043
- const raw = JSON.parse(await readFile15(join27(runDirectory, "invocation.json"), "utf8"));
28471
+ const raw = JSON.parse(await readFile16(join29(runDirectory, "invocation.json"), "utf8"));
28044
28472
  return typeof raw.host === "string" && raw.host.trim() !== "" ? raw.host : void 0;
28045
28473
  } catch (error) {
28046
28474
  if (error.code === "ENOENT") return void 0;
@@ -28058,12 +28486,14 @@ async function presentControlledFailure2(admitted, failureInput, adapters, autho
28058
28486
  });
28059
28487
  const knownFailure = failureInput.knownFailure ?? resumeObservation.observationReadFailure;
28060
28488
  const session = !hasThrown && !failureInput.timedOut && knownFailure === void 0 && failureInput.knownCause === void 0 && admitted.principal !== void 0 ? await inspectJudgeSession(authority.decode(admitted.principal).sessionFile) : void 0;
28489
+ const fromKnownFailure = explicitInternalKnownFailureClassificationInput(knownFailure);
28061
28490
  const failure = classifyPostAdmissionFailure({
28062
28491
  timedOut: failureInput.timedOut,
28063
28492
  code: failureInput.code,
28064
28493
  stderr: failureInput.stderr,
28065
28494
  ...hasThrown ? { thrown: failureInput.thrown } : {},
28066
- ...explicitInternalKnownFailureClassificationInput(knownFailure),
28495
+ ...failureInput.knownDetails === void 0 ? {} : { knownDetails: failureInput.knownDetails },
28496
+ ...fromKnownFailure,
28067
28497
  ...failureInput.knownCause === void 0 ? {} : { knownCause: failureInput.knownCause },
28068
28498
  ...failureInput.knownIdentity === void 0 ? {} : { knownIdentity: failureInput.knownIdentity },
28069
28499
  ...failureInput.knownDiagnostic === void 0 ? {} : { knownDiagnostic: failureInput.knownDiagnostic },
@@ -28093,12 +28523,70 @@ async function presentControlledFailure2(admitted, failureInput, adapters, autho
28093
28523
  terminal
28094
28524
  };
28095
28525
  }
28096
- function presentSecondaryTerminal(terminal, io) {
28097
- if (terminal.roleOutcome.kind === "failure" || terminal.roleOutcome.kind === "no_receipt") {
28098
- presentFailureTerminal(terminal, io);
28099
- } else {
28100
- io.stdout(formatTerminalResult(terminal));
28526
+ function concurrentFailureLeafRecord(leaf) {
28527
+ return {
28528
+ cause: leaf.cause,
28529
+ diagnostic: leaf.diagnostic,
28530
+ ...leaf.identity === void 0 ? {} : { identity: leaf.identity },
28531
+ ...leaf.details === void 0 ? {} : { details: leaf.details }
28532
+ };
28533
+ }
28534
+ function existingConcurrentFailureLeaves(details) {
28535
+ const value = details?.concurrentFailures;
28536
+ return Array.isArray(value) ? [...value] : [];
28537
+ }
28538
+ function withLastHostWriteConcurrentFailure(input, writeError) {
28539
+ const writeLeaf = concurrentFailureLeafRecord(projectThrownFailureLeaf(writeError));
28540
+ if (input.knownFailure !== void 0) {
28541
+ const failure = input.knownFailure;
28542
+ return {
28543
+ ...input,
28544
+ knownFailure: {
28545
+ cause: failure.cause,
28546
+ ...failure.identity === void 0 ? {} : { identity: failure.identity },
28547
+ ...failure.diagnostic === void 0 ? {} : { diagnostic: failure.diagnostic },
28548
+ details: {
28549
+ ...failure.details ?? {},
28550
+ concurrentFailures: [
28551
+ ...existingConcurrentFailureLeaves(failure.details),
28552
+ writeLeaf
28553
+ ]
28554
+ }
28555
+ }
28556
+ };
28101
28557
  }
28558
+ return {
28559
+ ...input,
28560
+ knownDetails: {
28561
+ ...input.knownDetails ?? {},
28562
+ concurrentFailures: [
28563
+ ...existingConcurrentFailureLeaves(input.knownDetails),
28564
+ writeLeaf
28565
+ ]
28566
+ }
28567
+ };
28568
+ }
28569
+ function knownFailureFromSettledFailureOutcome(outcome) {
28570
+ const facts = outcome.decisiveFacts;
28571
+ const secondary = facts.secondaryEvidence;
28572
+ const details = secondary !== void 0 && typeof secondary === "object" && secondary !== null && !Array.isArray(secondary) ? secondary : void 0;
28573
+ const identity = {};
28574
+ if (typeof facts.errorName === "string") identity.name = facts.errorName;
28575
+ if (typeof facts.errorCode === "string" || typeof facts.errorCode === "number") {
28576
+ identity.code = facts.errorCode;
28577
+ }
28578
+ return {
28579
+ cause: outcome.cause,
28580
+ diagnostic: outcome.diagnostic,
28581
+ ...Object.keys(identity).length > 0 ? { identity } : {},
28582
+ ...details === void 0 ? {} : { details }
28583
+ };
28584
+ }
28585
+ function withOptionalLastHostWriteThrow(primary, writeFailure, message) {
28586
+ if (writeFailure === void 0) return primary;
28587
+ return new AggregateError([primary, writeFailure.error], message, {
28588
+ cause: primary
28589
+ });
28102
28590
  }
28103
28591
  async function dispatchPostAdmissionTurn(input) {
28104
28592
  const { admitted, env, io, request, lease, adapters, effectiveEngine } = input;
@@ -28117,15 +28605,70 @@ async function dispatchPostAdmissionTurn(input) {
28117
28605
  io
28118
28606
  );
28119
28607
  }
28120
- const previousHost = await readInvocationHost(admitted.runDirectory);
28608
+ let previousHost;
28609
+ let previousRunDirectory;
28610
+ let nativeHomeRunDirectory;
28611
+ let openedNativeHomeRunDirectory;
28121
28612
  const liveHost = env.host;
28122
- const hostTransition = previousHost !== void 0 && liveHost !== void 0 && admitted.principal !== void 0 ? await projectHostTransitionPriorNative({
28123
- previousHost,
28124
- liveHost,
28125
- runDirectory: admitted.runDirectory,
28126
- piSessionFile: env.principalAuthority.decode(admitted.principal).sessionFile
28127
- }) : void 0;
28128
- const turnRequest = hostTransition === void 0 ? request : { ...request, hostTransition };
28613
+ const principalCoordinates = admitted.principal === void 0 ? void 0 : env.principalAuthority.decode(admitted.principal);
28614
+ const ticketSeatMemoryBound = isTicketSeatMemoryBound({
28615
+ role: admitted.role,
28616
+ ...admitted.ticketNumber === void 0 ? {} : { ticketNumber: admitted.ticketNumber }
28617
+ });
28618
+ let turnRequest;
28619
+ try {
28620
+ if (ticketSeatMemoryBound && principalCoordinates !== void 0) {
28621
+ const lastHost = await readTicketSeatMemoryLastHost(
28622
+ principalCoordinates.sessionDirectory
28623
+ );
28624
+ if (lastHost !== void 0) {
28625
+ previousHost = lastHost.host;
28626
+ if (typeof lastHost.runDirectory === "string" && lastHost.runDirectory.length > 0) {
28627
+ previousRunDirectory = lastHost.runDirectory;
28628
+ if (liveHost === "grok-build" && request.continuation.kind === "resume") {
28629
+ nativeHomeRunDirectory = lastHost.runDirectory;
28630
+ }
28631
+ }
28632
+ }
28633
+ } else {
28634
+ previousHost = await readInvocationHost(admitted.runDirectory);
28635
+ }
28636
+ const hostTransition = previousHost !== void 0 && liveHost !== void 0 && principalCoordinates !== void 0 ? await projectHostTransitionPriorNative({
28637
+ previousHost,
28638
+ liveHost,
28639
+ runDirectory: admitted.runDirectory,
28640
+ piSessionFile: principalCoordinates.sessionFile,
28641
+ ...previousRunDirectory === void 0 ? {} : { previousRunDirectory }
28642
+ }) : void 0;
28643
+ turnRequest = request;
28644
+ if (hostTransition !== void 0) {
28645
+ turnRequest = { ...turnRequest, hostTransition };
28646
+ }
28647
+ if (nativeHomeRunDirectory !== void 0) {
28648
+ turnRequest = { ...turnRequest, nativeHomeRunDirectory };
28649
+ }
28650
+ if (ticketSeatMemoryBound) {
28651
+ turnRequest = {
28652
+ ...turnRequest,
28653
+ noteNativeHomeOpened: (runDirectory) => {
28654
+ openedNativeHomeRunDirectory = runDirectory;
28655
+ }
28656
+ };
28657
+ }
28658
+ } catch (error) {
28659
+ return await presentControlledFailure2(
28660
+ admitted,
28661
+ {
28662
+ timedOut: false,
28663
+ code: null,
28664
+ stderr: "",
28665
+ thrown: error
28666
+ },
28667
+ adapters,
28668
+ env.principalAuthority,
28669
+ io
28670
+ );
28671
+ }
28129
28672
  await markRunRunning(admitted.runDirectory, env.model, effectiveEngine, env.host);
28130
28673
  await clearTypedProviderHttpObservation(admitted.runDirectory);
28131
28674
  if (adapters.beforeDispatch !== void 0) {
@@ -28146,26 +28689,50 @@ async function dispatchPostAdmissionTurn(input) {
28146
28689
  );
28147
28690
  }
28148
28691
  }
28149
- let result2;
28692
+ let turnOutcome;
28150
28693
  try {
28151
- result2 = await env.roleTurnHost.executeTurn(turnRequest);
28694
+ turnOutcome = {
28695
+ kind: "returned",
28696
+ result: await env.roleTurnHost.executeTurn(turnRequest)
28697
+ };
28152
28698
  } catch (error) {
28699
+ turnOutcome = { kind: "thrown", error };
28700
+ }
28701
+ let lastHostWriteFailure;
28702
+ const hostEngaged = turnOutcome.kind === "returned" || openedNativeHomeRunDirectory !== void 0;
28703
+ if (hostEngaged && liveHost !== void 0 && principalCoordinates !== void 0 && ticketSeatMemoryBound) {
28704
+ try {
28705
+ await writeTicketSeatMemoryLastHost(
28706
+ principalCoordinates.sessionDirectory,
28707
+ liveHost,
28708
+ liveHost === "grok-build" ? openedNativeHomeRunDirectory ?? nativeHomeRunDirectory ?? admitted.runDirectory : previousRunDirectory
28709
+ );
28710
+ } catch (error) {
28711
+ lastHostWriteFailure = { error };
28712
+ }
28713
+ }
28714
+ if (turnOutcome.kind === "thrown") {
28153
28715
  return await presentControlledFailure2(
28154
28716
  admitted,
28155
28717
  {
28156
28718
  timedOut: false,
28157
28719
  code: null,
28158
28720
  stderr: "",
28159
- thrown: error
28721
+ thrown: withOptionalLastHostWriteThrow(
28722
+ turnOutcome.error,
28723
+ lastHostWriteFailure,
28724
+ "host turn and ticket-seat last-host write failed"
28725
+ )
28160
28726
  },
28161
28727
  adapters,
28162
28728
  env.principalAuthority,
28163
28729
  io
28164
28730
  );
28165
28731
  }
28732
+ const result2 = turnOutcome.result;
28166
28733
  try {
28167
- await writeFile8(
28168
- join27(admitted.runDirectory, "stderr.log"),
28734
+ await writeFile9(
28735
+ join29(admitted.runDirectory, "stderr.log"),
28169
28736
  result2.stderr,
28170
28737
  "utf8"
28171
28738
  );
@@ -28181,7 +28748,11 @@ async function dispatchPostAdmissionTurn(input) {
28181
28748
  timedOut: false,
28182
28749
  code: result2.code,
28183
28750
  stderr: result2.stderr,
28184
- thrown: error
28751
+ thrown: withOptionalLastHostWriteThrow(
28752
+ error,
28753
+ lastHostWriteFailure,
28754
+ "settlement and ticket-seat last-host write failed"
28755
+ )
28185
28756
  },
28186
28757
  adapters,
28187
28758
  env.principalAuthority,
@@ -28189,6 +28760,39 @@ async function dispatchPostAdmissionTurn(input) {
28189
28760
  );
28190
28761
  }
28191
28762
  if (settled !== void 0 && shouldPresent(settled)) {
28763
+ if (lastHostWriteFailure !== void 0) {
28764
+ if (settled.roleOutcome.kind === "failure") {
28765
+ return await presentControlledFailure2(
28766
+ admitted,
28767
+ withLastHostWriteConcurrentFailure(
28768
+ {
28769
+ timedOut: result2.timedOut,
28770
+ code: result2.code,
28771
+ stderr: result2.stderr,
28772
+ knownFailure: knownFailureFromSettledFailureOutcome(
28773
+ settled.roleOutcome
28774
+ )
28775
+ },
28776
+ lastHostWriteFailure.error
28777
+ ),
28778
+ adapters,
28779
+ env.principalAuthority,
28780
+ io
28781
+ );
28782
+ }
28783
+ return await presentControlledFailure2(
28784
+ admitted,
28785
+ {
28786
+ timedOut: result2.timedOut,
28787
+ code: result2.code,
28788
+ stderr: result2.stderr,
28789
+ thrown: lastHostWriteFailure.error
28790
+ },
28791
+ adapters,
28792
+ env.principalAuthority,
28793
+ io
28794
+ );
28795
+ }
28192
28796
  await markRunTerminal(admitted.runDirectory);
28193
28797
  io.stdout(formatTerminalResult(settled));
28194
28798
  return {
@@ -28197,18 +28801,6 @@ async function dispatchPostAdmissionTurn(input) {
28197
28801
  terminal: settled
28198
28802
  };
28199
28803
  }
28200
- if (adapters.trySettleSecondary !== void 0) {
28201
- const secondary = await adapters.trySettleSecondary(admitted, env.principalAuthority);
28202
- if (secondary !== void 0) {
28203
- await markRunTerminal(admitted.runDirectory);
28204
- presentSecondaryTerminal(secondary, io);
28205
- return {
28206
- exitCode: exitCodeForTerminalOutcome(secondary.roleOutcome),
28207
- admitted,
28208
- terminal: secondary
28209
- };
28210
- }
28211
- }
28212
28804
  const sessionFile = admitted.principal !== void 0 ? env.principalAuthority.decode(admitted.principal).sessionFile : "";
28213
28805
  const runnerKnownFailure = adapters.resolveRunnerKnownFailure !== void 0 && sessionFile !== "" ? await adapters.resolveRunnerKnownFailure({ result: result2, sessionFile }) : result2.knownFailure;
28214
28806
  const credentialFailure = postRunMissingCredentialFailure(
@@ -28222,14 +28814,18 @@ async function dispatchPostAdmissionTurn(input) {
28222
28814
  credential: credentialFailure,
28223
28815
  runDirectory: admitted.runDirectory
28224
28816
  });
28817
+ const hostFailureInput = {
28818
+ timedOut: result2.timedOut,
28819
+ code: result2.code,
28820
+ stderr: result2.stderr,
28821
+ ...controlledFailureInputFromResolution(resolution)
28822
+ };
28225
28823
  return await presentControlledFailure2(
28226
28824
  admitted,
28227
- {
28228
- timedOut: result2.timedOut,
28229
- code: result2.code,
28230
- stderr: result2.stderr,
28231
- ...controlledFailureInputFromResolution(resolution)
28232
- },
28825
+ lastHostWriteFailure === void 0 ? hostFailureInput : withLastHostWriteConcurrentFailure(
28826
+ hostFailureInput,
28827
+ lastHostWriteFailure.error
28828
+ ),
28233
28829
  adapters,
28234
28830
  env.principalAuthority,
28235
28831
  io
@@ -28404,6 +29000,7 @@ var init_post_admission = __esm({
28404
29000
  init_run_lifecycle();
28405
29001
  init_cli_errors();
28406
29002
  init_host_transition_prior_native();
29003
+ init_ticket_seat_memory();
28407
29004
  init_public_run_credentials();
28408
29005
  init_run_lifecycle();
28409
29006
  init_settlement();
@@ -29406,7 +30003,20 @@ async function runPublicNotary(argv, env, io, parseNotaryArgv2) {
29406
30003
  }
29407
30004
  throw error;
29408
30005
  }
30006
+ const memory = await rebindAdmittedToTicketSeatMemory({
30007
+ admitted,
30008
+ seat: "notary",
30009
+ principalAuthority: env.principalAuthority
30010
+ });
29409
30011
  await markRunAdmitted(admitted, env.principalAuthority);
30012
+ const engineMaterial = engineSessionMaterialFromOptions({
30013
+ ...env.engine === void 0 ? {} : { engine: env.engine },
30014
+ packageRoot: env.packageRoot
30015
+ });
30016
+ const continuation = {
30017
+ kind: memory?.resumed === true ? "resume" : "initial",
30018
+ prompt: buildNotaryTransportPrompt(admitted, engineMaterial)
30019
+ };
29410
30020
  const turnRequest = buildNotaryTurnRequest(admitted, {
29411
30021
  packageRoot: env.packageRoot,
29412
30022
  home: env.home,
@@ -29415,10 +30025,7 @@ async function runPublicNotary(argv, env, io, parseNotaryArgv2) {
29415
30025
  ...env.engine === void 0 ? {} : { engine: env.engine },
29416
30026
  ...env.timeoutMs === void 0 ? {} : { timeoutMs: env.timeoutMs },
29417
30027
  ...env.correlationId === void 0 || env.correlationId.trim() === "" ? {} : { correlationId: env.correlationId },
29418
- continuation: {
29419
- kind: "initial",
29420
- prompt: buildNotaryTransportPrompt(admitted, engineSessionMaterialFromOptions({ ...env.engine === void 0 ? {} : { engine: env.engine }, packageRoot: env.packageRoot }))
29421
- }
30028
+ continuation
29422
30029
  });
29423
30030
  return await runPostAdmissionOneShot({
29424
30031
  admitted,
@@ -29465,6 +30072,7 @@ var init_notary_run = __esm({
29465
30072
  "src/public-cli/notary-run.ts"() {
29466
30073
  "use strict";
29467
30074
  init_engine_material();
30075
+ init_ticket_seat_memory();
29468
30076
  init_cli_errors();
29469
30077
  init_invocation();
29470
30078
  init_post_admission();
@@ -29508,7 +30116,21 @@ async function runPublicInspector(argv, env, io, parseInspectorArgv2) {
29508
30116
  }
29509
30117
  throw error;
29510
30118
  }
30119
+ await resolveSeatTicketBinding(admitted, env);
30120
+ const memory = await rebindAdmittedToTicketSeatMemory({
30121
+ admitted,
30122
+ seat: "inspector",
30123
+ principalAuthority: env.principalAuthority
30124
+ });
29511
30125
  await markRunAdmitted(admitted, env.principalAuthority);
30126
+ const engineMaterial = engineSessionMaterialFromOptions({
30127
+ ...env.engine === void 0 ? {} : { engine: env.engine },
30128
+ packageRoot: env.packageRoot
30129
+ });
30130
+ const continuation = {
30131
+ kind: memory?.resumed === true ? "resume" : "initial",
30132
+ prompt: buildInspectorTransportPrompt(admitted, engineMaterial)
30133
+ };
29512
30134
  const turnRequest = buildInspectorTurnRequest(admitted, {
29513
30135
  packageRoot: env.packageRoot,
29514
30136
  home: env.home,
@@ -29517,16 +30139,7 @@ async function runPublicInspector(argv, env, io, parseInspectorArgv2) {
29517
30139
  ...env.engine === void 0 ? {} : { engine: env.engine },
29518
30140
  ...env.timeoutMs === void 0 ? {} : { timeoutMs: env.timeoutMs },
29519
30141
  ...env.correlationId === void 0 || env.correlationId.trim() === "" ? {} : { correlationId: env.correlationId },
29520
- continuation: {
29521
- kind: "initial",
29522
- prompt: buildInspectorTransportPrompt(
29523
- admitted,
29524
- engineSessionMaterialFromOptions({
29525
- ...env.engine === void 0 ? {} : { engine: env.engine },
29526
- packageRoot: env.packageRoot
29527
- })
29528
- )
29529
- }
30142
+ continuation
29530
30143
  });
29531
30144
  return await runPostAdmissionOneShot({
29532
30145
  admitted,
@@ -29565,7 +30178,9 @@ var init_inspector_run = __esm({
29565
30178
  "src/public-cli/inspector-run.ts"() {
29566
30179
  "use strict";
29567
30180
  init_engine_material();
30181
+ init_ticket_seat_memory();
29568
30182
  init_cli_errors();
30183
+ init_seat_ticket_binding();
29569
30184
  init_invocation();
29570
30185
  init_post_admission();
29571
30186
  init_run_lifecycle();
@@ -29690,8 +30305,8 @@ var init_judge_run = __esm({
29690
30305
  });
29691
30306
 
29692
30307
  // src/public-cli/merger-run.ts
29693
- import { mkdir as mkdir5, writeFile as writeFile9 } from "node:fs/promises";
29694
- import { join as join28, resolve as resolve9 } from "node:path";
30308
+ import { mkdir as mkdir5, writeFile as writeFile10 } from "node:fs/promises";
30309
+ import { join as join30, resolve as resolve9 } from "node:path";
29695
30310
  function mergerMethods(packageRoot2) {
29696
30311
  return [
29697
30312
  {
@@ -29757,9 +30372,9 @@ async function admitMergerShellForActivationFailure(options) {
29757
30372
  expectedConflictPaths: [],
29758
30373
  resolutionScope: []
29759
30374
  };
29760
- const admittedRequestPath = join28(runDirectory, "admitted-request.json");
29761
- const mergerInputPath = join28(runDirectory, "merger-input.json");
29762
- await writeFile9(
30375
+ const admittedRequestPath = join30(runDirectory, "admitted-request.json");
30376
+ const mergerInputPath = join30(runDirectory, "merger-input.json");
30377
+ await writeFile10(
29763
30378
  admittedRequestPath,
29764
30379
  `${JSON.stringify(
29765
30380
  {
@@ -30197,13 +30812,13 @@ var init_analyst_book_key = __esm({
30197
30812
 
30198
30813
  // src/atomic-write.ts
30199
30814
  import { randomUUID as randomUUID5 } from "node:crypto";
30200
- import { rename, rm as rm2, writeFile as writeFile10 } from "node:fs/promises";
30201
- import { dirname as dirname11, join as join29 } from "node:path";
30815
+ import { rename, rm as rm2, writeFile as writeFile11 } from "node:fs/promises";
30816
+ import { dirname as dirname11, join as join31 } from "node:path";
30202
30817
  async function writeFileAtomically(destination, contents) {
30203
30818
  const parent = dirname11(destination);
30204
- const temporary = join29(parent, `.atomic-write-${randomUUID5()}.tmp`);
30819
+ const temporary = join31(parent, `.atomic-write-${randomUUID5()}.tmp`);
30205
30820
  try {
30206
- await writeFile10(temporary, contents);
30821
+ await writeFile11(temporary, contents);
30207
30822
  await rename(temporary, destination);
30208
30823
  } catch (error) {
30209
30824
  await rm2(temporary, { force: true }).catch(() => void 0);
@@ -30217,8 +30832,8 @@ var init_atomic_write = __esm({
30217
30832
  });
30218
30833
 
30219
30834
  // src/analyst-index.ts
30220
- import { open as open3, readFile as readFile16, unlink as unlink4 } from "node:fs/promises";
30221
- import { dirname as dirname12, join as join30 } from "node:path";
30835
+ import { open as open3, readFile as readFile17, unlink as unlink4 } from "node:fs/promises";
30836
+ import { dirname as dirname12, join as join32 } from "node:path";
30222
30837
  function sleep(ms) {
30223
30838
  return new Promise((resolve11) => {
30224
30839
  setTimeout(resolve11, ms);
@@ -30227,7 +30842,7 @@ function sleep(ms) {
30227
30842
  async function withAnalystLibraryIndexLock(ledgerHome, fn) {
30228
30843
  const indexPath = analystLibraryIndexPath(ledgerHome);
30229
30844
  ensureRealDirectoryTree(ledgerHome, dirname12(indexPath));
30230
- const lockPath = join30(dirname12(indexPath), LIBRARY_INDEX_LOCK_NAME);
30845
+ const lockPath = join32(dirname12(indexPath), LIBRARY_INDEX_LOCK_NAME);
30231
30846
  assertLedgerFileInsideHome(lockPath, ledgerHome);
30232
30847
  const startedAt = Date.now();
30233
30848
  while (true) {
@@ -30254,7 +30869,7 @@ async function withAnalystLibraryIndexLock(ledgerHome, fn) {
30254
30869
  }
30255
30870
  }
30256
30871
  function analystLibraryIndexPath(ledgerHome) {
30257
- return join30(ledgerHome, "analyst", "library-index.json");
30872
+ return join32(ledgerHome, "analyst", "library-index.json");
30258
30873
  }
30259
30874
  function rowFromIssueMetricsPage(page) {
30260
30875
  return {
@@ -30345,7 +30960,7 @@ async function readAnalystLibraryIndexPage(ledgerHome) {
30345
30960
  const path = analystLibraryIndexPath(ledgerHome);
30346
30961
  let raw;
30347
30962
  try {
30348
- raw = await readFile16(path, "utf8");
30963
+ raw = await readFile17(path, "utf8");
30349
30964
  } catch (error) {
30350
30965
  if (error instanceof Error && "code" in error && (error.code === "ENOENT" || error.code === "ENOTDIR")) {
30351
30966
  return void 0;
@@ -30549,8 +31164,8 @@ var init_analyst_cohort = __esm({
30549
31164
  });
30550
31165
 
30551
31166
  // src/analyst-ledger.ts
30552
- import { readdir as readdir7, readFile as readFile17 } from "node:fs/promises";
30553
- import { join as join31 } from "node:path";
31167
+ import { readdir as readdir7, readFile as readFile18 } from "node:fs/promises";
31168
+ import { join as join33 } from "node:path";
30554
31169
  function isMissingPathError5(error) {
30555
31170
  return error instanceof Error && "code" in error && (error.code === "ENOENT" || error.code === "ENOTDIR");
30556
31171
  }
@@ -30563,7 +31178,7 @@ function isRecord18(value) {
30563
31178
  async function readExistingRunLifecycleState(runDirectory) {
30564
31179
  try {
30565
31180
  const raw = JSON.parse(
30566
- await readFile17(join31(runDirectory, "run-state.json"), "utf8")
31181
+ await readFile18(join33(runDirectory, "run-state.json"), "utf8")
30567
31182
  );
30568
31183
  if (!isRecord18(raw) || typeof raw.state !== "string") return void 0;
30569
31184
  return raw.state;
@@ -30595,7 +31210,7 @@ async function listLedgerBookNames(booksRoot) {
30595
31210
  async function readInvocationScopeFields(runDirectory) {
30596
31211
  let raw;
30597
31212
  try {
30598
- raw = await readFile17(join31(runDirectory, "invocation.json"), "utf8");
31213
+ raw = await readFile18(join33(runDirectory, "invocation.json"), "utf8");
30599
31214
  } catch (error) {
30600
31215
  if (isMissingPathError5(error)) return void 0;
30601
31216
  throw error;
@@ -30627,7 +31242,7 @@ function decideIssueScope(input) {
30627
31242
  }
30628
31243
  async function resolveSessionFile(runDirectory) {
30629
31244
  try {
30630
- const raw = await readFile17(join31(runDirectory, "invocation.json"), "utf8");
31245
+ const raw = await readFile18(join33(runDirectory, "invocation.json"), "utf8");
30631
31246
  const parsed = JSON.parse(raw);
30632
31247
  if (isRecord18(parsed) && typeof parsed.sessionFile === "string" && parsed.sessionFile.trim() !== "") {
30633
31248
  return parsed.sessionFile;
@@ -30635,7 +31250,68 @@ async function resolveSessionFile(runDirectory) {
30635
31250
  } catch (error) {
30636
31251
  if (!isMissingPathError5(error)) throw error;
30637
31252
  }
30638
- return join31(runDirectory, "session", "session.jsonl");
31253
+ return join33(runDirectory, "session", "session.jsonl");
31254
+ }
31255
+ function attributeSessionRowsForRun(input) {
31256
+ if (pathContainedIn(input.runDirectory, input.sessionFile)) {
31257
+ return { kind: "attributed", rows: input.rows, closed: false };
31258
+ }
31259
+ const interval = intervalRowsForMatchingBinding(
31260
+ input.rows,
31261
+ isTicketSeatRunBindingRow,
31262
+ (row) => ticketSeatRunBindingRunId(row) === input.runId
31263
+ );
31264
+ if (interval === void 0) {
31265
+ return {
31266
+ kind: "missing-boundary",
31267
+ reason: "shared session volume has no ticket-seat run binding for this run"
31268
+ };
31269
+ }
31270
+ return { kind: "attributed", rows: interval.rows, closed: interval.closed };
31271
+ }
31272
+ function admitFrameSpanFromRows(rows) {
31273
+ const models = extractSessionModelSequence(rows);
31274
+ const span = extractSessionTimestampSpan(rows);
31275
+ let partialFirstFrameAt = { status: "absent" };
31276
+ let partialLastFrameAt = { status: "absent" };
31277
+ if (span.startedAt === void 0 || span.endedAt === void 0) {
31278
+ if (span.startedAt !== void 0) {
31279
+ partialFirstFrameAt = { status: "present", at: span.startedAt };
31280
+ }
31281
+ if (span.endedAt !== void 0) {
31282
+ partialLastFrameAt = { status: "present", at: span.endedAt };
31283
+ }
31284
+ return {
31285
+ models,
31286
+ partialFirstFrameAt,
31287
+ partialLastFrameAt,
31288
+ missingReason: "session timeline has no usable timestamps"
31289
+ };
31290
+ }
31291
+ const startedMs = Date.parse(span.startedAt);
31292
+ const endedMs = Date.parse(span.endedAt);
31293
+ if (!Number.isFinite(startedMs) || !Number.isFinite(endedMs)) {
31294
+ return {
31295
+ models,
31296
+ partialFirstFrameAt: { status: "present", at: span.startedAt },
31297
+ partialLastFrameAt: { status: "present", at: span.endedAt },
31298
+ missingReason: "session timeline timestamps are not parseable instants"
31299
+ };
31300
+ }
31301
+ if (endedMs < startedMs) {
31302
+ return {
31303
+ models,
31304
+ partialFirstFrameAt: { status: "present", at: span.startedAt },
31305
+ partialLastFrameAt: { status: "present", at: span.endedAt },
31306
+ missingReason: "session timeline end is earlier than start"
31307
+ };
31308
+ }
31309
+ return {
31310
+ models,
31311
+ frameSpan: { startedAt: span.startedAt, endedAt: span.endedAt },
31312
+ partialFirstFrameAt: { status: "present", at: span.startedAt },
31313
+ partialLastFrameAt: { status: "present", at: span.endedAt }
31314
+ };
30639
31315
  }
30640
31316
  async function classifyScopedRun(input) {
30641
31317
  const missingSources = [];
@@ -30648,48 +31324,57 @@ async function classifyScopedRun(input) {
30648
31324
  let partialLastFrameAt = { status: "absent" };
30649
31325
  const sessionFile = await resolveSessionFile(input.runDirectory);
30650
31326
  let rows;
31327
+ const admitAttributed = (attributedRows) => {
31328
+ rows = attributedRows;
31329
+ const admitted = admitFrameSpanFromRows(attributedRows);
31330
+ models = admitted.models;
31331
+ partialFirstFrameAt = admitted.partialFirstFrameAt;
31332
+ partialLastFrameAt = admitted.partialLastFrameAt;
31333
+ if (admitted.frameSpan !== void 0) {
31334
+ frameSpan = admitted.frameSpan;
31335
+ } else if (admitted.missingReason !== void 0) {
31336
+ missingSources.push("session-timeline");
31337
+ reasons.push(admitted.missingReason);
31338
+ }
31339
+ };
30651
31340
  try {
30652
- rows = await readLedgerSessionJsonl(sessionFile);
30653
- models = extractSessionModelSequence(rows);
30654
- const span = extractSessionTimestampSpan(rows);
30655
- if (span.startedAt === void 0 || span.endedAt === void 0) {
31341
+ const rawRows = await readLedgerSessionJsonl(sessionFile);
31342
+ const attributed = attributeSessionRowsForRun({
31343
+ rows: rawRows,
31344
+ sessionFile,
31345
+ runDirectory: input.runDirectory,
31346
+ runId: input.runId
31347
+ });
31348
+ if (attributed.kind === "missing-boundary") {
30656
31349
  missingSources.push("session-timeline");
30657
- reasons.push("session timeline has no usable timestamps");
30658
- if (span.startedAt !== void 0) {
30659
- partialFirstFrameAt = { status: "present", at: span.startedAt };
30660
- }
30661
- if (span.endedAt !== void 0) {
30662
- partialLastFrameAt = { status: "present", at: span.endedAt };
30663
- }
31350
+ reasons.push(attributed.reason);
30664
31351
  } else {
30665
- const startedMs = Date.parse(span.startedAt);
30666
- const endedMs = Date.parse(span.endedAt);
30667
- if (!Number.isFinite(startedMs) || !Number.isFinite(endedMs)) {
30668
- missingSources.push("session-timeline");
30669
- reasons.push("session timeline timestamps are not parseable instants");
30670
- partialFirstFrameAt = { status: "present", at: span.startedAt };
30671
- partialLastFrameAt = { status: "present", at: span.endedAt };
30672
- } else if (endedMs < startedMs) {
30673
- missingSources.push("session-timeline");
30674
- reasons.push("session timeline end is earlier than start");
30675
- partialFirstFrameAt = { status: "present", at: span.startedAt };
30676
- partialLastFrameAt = { status: "present", at: span.endedAt };
30677
- } else {
30678
- frameSpan = { startedAt: span.startedAt, endedAt: span.endedAt };
30679
- }
31352
+ admitAttributed(attributed.rows);
30680
31353
  }
30681
31354
  } catch (error) {
30682
- missingSources.push("session-timeline");
30683
- reasons.push(errorText3(error));
30684
31355
  if (error instanceof LedgerSessionJsonlError) {
30685
- const span = extractSessionTimestampSpan(error.prefixRows);
30686
- if (span.startedAt !== void 0) {
30687
- partialFirstFrameAt = { status: "present", at: span.startedAt };
30688
- }
30689
- if (span.endedAt !== void 0) {
30690
- partialLastFrameAt = { status: "present", at: span.endedAt };
31356
+ const attributed = attributeSessionRowsForRun({
31357
+ rows: error.prefixRows,
31358
+ sessionFile,
31359
+ runDirectory: input.runDirectory,
31360
+ runId: input.runId
31361
+ });
31362
+ if (attributed.kind === "attributed" && attributed.closed) {
31363
+ admitAttributed(attributed.rows);
31364
+ } else if (attributed.kind === "attributed") {
31365
+ missingSources.push("session-timeline");
31366
+ reasons.push(errorText3(error));
31367
+ const admitted = admitFrameSpanFromRows(attributed.rows);
31368
+ models = admitted.models;
31369
+ partialFirstFrameAt = admitted.partialFirstFrameAt;
31370
+ partialLastFrameAt = admitted.partialLastFrameAt;
31371
+ } else {
31372
+ missingSources.push("session-timeline");
31373
+ reasons.push(errorText3(error));
30691
31374
  }
30692
- models = extractSessionModelSequence(error.prefixRows);
31375
+ } else {
31376
+ missingSources.push("session-timeline");
31377
+ reasons.push(errorText3(error));
30693
31378
  }
30694
31379
  }
30695
31380
  if (rows !== void 0 && !missingSources.includes("session-timeline")) {
@@ -30745,9 +31430,18 @@ async function classifyScopedRun(input) {
30745
31430
  }
30746
31431
  let gateCycles;
30747
31432
  try {
30748
- gateCycles = await readAnalystGateCyclesFromAuditorRoles(
30749
- join31(input.runDirectory, "session", "auditor-roles")
30750
- );
31433
+ const memoryNests = await resolveTicketSeatMemoryNestDirectories({
31434
+ runDirectory: input.runDirectory,
31435
+ seats: ["inspector", "notary"]
31436
+ });
31437
+ const directories = [
31438
+ join33(input.runDirectory, "session", "auditor-roles"),
31439
+ ...memoryNests
31440
+ ];
31441
+ const parentSessionFile = join33(input.runDirectory, "session", "session.jsonl");
31442
+ gateCycles = await readAnalystGateCyclesFromAuditorRoles(directories, {
31443
+ parentSessionFile
31444
+ });
30751
31445
  } catch (error) {
30752
31446
  return {
30753
31447
  kind: "unreadable",
@@ -30778,7 +31472,7 @@ async function classifyScopedRun(input) {
30778
31472
  async function scanAnalystIssueRuns(input) {
30779
31473
  const ledgerHome = resolveActivationLedgerHome(input.home);
30780
31474
  const scopeTicketNumber = input.ticketNumber;
30781
- const booksRoot = join31(ledgerHome, "books");
31475
+ const booksRoot = join33(ledgerHome, "books");
30782
31476
  let wholeBook = false;
30783
31477
  let scopeRootIdentity;
30784
31478
  let bookNames;
@@ -30810,7 +31504,7 @@ async function scanAnalystIssueRuns(input) {
30810
31504
  const unreadable = [];
30811
31505
  const scopeConflicts = [];
30812
31506
  for (const book of bookNames) {
30813
- const runsDir = join31(booksRoot, book, "runs");
31507
+ const runsDir = join33(booksRoot, book, "runs");
30814
31508
  let runNames;
30815
31509
  try {
30816
31510
  const entries = await readdir7(runsDir, { withFileTypes: true });
@@ -30822,7 +31516,7 @@ async function scanAnalystIssueRuns(input) {
30822
31516
  for (const runName of runNames) {
30823
31517
  const parsed = parseRunDirectoryName2(runName);
30824
31518
  if (parsed === void 0) continue;
30825
- const runDirectory = join31(runsDir, runName);
31519
+ const runDirectory = join33(runsDir, runName);
30826
31520
  let scopeFields;
30827
31521
  try {
30828
31522
  scopeFields = await readInvocationScopeFields(runDirectory);
@@ -30865,6 +31559,7 @@ var init_analyst_ledger = __esm({
30865
31559
  init_ledger_session_read();
30866
31560
  init_run_terminal_artifacts();
30867
31561
  init_analyst_gate_cycles_read();
31562
+ init_ticket_seat_memory();
30868
31563
  LIVE_RUN_STATES = /* @__PURE__ */ new Set(["admitted", "running", "resumable"]);
30869
31564
  }
30870
31565
  });
@@ -31675,8 +32370,8 @@ var init_analyst_metric_family = __esm({
31675
32370
  });
31676
32371
 
31677
32372
  // src/analyst-page.ts
31678
- import { createHash as createHash7 } from "node:crypto";
31679
- import { dirname as dirname13, join as join32 } from "node:path";
32373
+ import { createHash as createHash8 } from "node:crypto";
32374
+ import { dirname as dirname13, join as join34 } from "node:path";
31680
32375
  function analystIssuePageKey(address) {
31681
32376
  const parts = ["book", address.bookKey];
31682
32377
  if (address.issueNumber !== void 0) {
@@ -31684,10 +32379,10 @@ function analystIssuePageKey(address) {
31684
32379
  } else if (address.scopeRootIdentity !== void 0) {
31685
32380
  parts.push("root", physicalPathIdentity(address.scopeRootIdentity));
31686
32381
  }
31687
- return createHash7("sha256").update(parts.join("\0")).digest("hex").slice(0, 32);
32382
+ return createHash8("sha256").update(parts.join("\0")).digest("hex").slice(0, 32);
31688
32383
  }
31689
32384
  function analystIssuePagePath(ledgerHome, address) {
31690
- return join32(ledgerHome, "analyst", "issues", `${analystIssuePageKey(address)}.json`);
32385
+ return join34(ledgerHome, "analyst", "issues", `${analystIssuePageKey(address)}.json`);
31691
32386
  }
31692
32387
  function analystIssuePageAddressFromPage(page) {
31693
32388
  return {
@@ -31823,7 +32518,7 @@ var init_analyst_page = __esm({
31823
32518
  });
31824
32519
 
31825
32520
  // src/analyst-entry.ts
31826
- import { readFile as readFile18 } from "node:fs/promises";
32521
+ import { readFile as readFile19 } from "node:fs/promises";
31827
32522
  function isMissingPathError6(error) {
31828
32523
  return error instanceof Error && "code" in error && (error.code === "ENOENT" || error.code === "ENOTDIR");
31829
32524
  }
@@ -31853,7 +32548,7 @@ async function readOrComputeAnalystIssuePage(input, options) {
31853
32548
  ...issueNumber === void 0 && input.bookKey === void 0 ? { scopeRootIdentity: projectRoot } : {}
31854
32549
  });
31855
32550
  try {
31856
- const raw = await readFile18(pagePath, "utf8");
32551
+ const raw = await readFile19(pagePath, "utf8");
31857
32552
  const page = JSON.parse(raw);
31858
32553
  if (cachedPageMatchesRequestedScope(page, { bookKey, ...input })) {
31859
32554
  return { mode: "issue", page, pagePath };
@@ -31948,7 +32643,7 @@ async function runAnalystModelGroupsMode(input, home) {
31948
32643
  scopeRootIdentity: projectRoot
31949
32644
  });
31950
32645
  try {
31951
- const raw = await readFile18(pagePath, "utf8");
32646
+ const raw = await readFile19(pagePath, "utf8");
31952
32647
  JSON.parse(raw);
31953
32648
  } catch (error) {
31954
32649
  if (!isMissingPathError6(error)) {
@@ -32047,7 +32742,7 @@ var init_analyst_entry = __esm({
32047
32742
  });
32048
32743
 
32049
32744
  // src/public-cli/analyst-run.ts
32050
- import { readFile as readFile19 } from "node:fs/promises";
32745
+ import { readFile as readFile20 } from "node:fs/promises";
32051
32746
  import { isAbsolute as isAbsolute7, resolve as resolve10 } from "node:path";
32052
32747
  function resolveAnalystIssueBookKeyFromCwd(cwd = process.cwd()) {
32053
32748
  try {
@@ -32100,7 +32795,7 @@ async function buildAnalystSweepModeInputFromAttachmentPaths(attachmentPaths) {
32100
32795
  const absolute = isAbsolute7(sourcePath) ? sourcePath : resolve10(sourcePath);
32101
32796
  let bytes;
32102
32797
  try {
32103
- bytes = await readFile19(absolute);
32798
+ bytes = await readFile20(absolute);
32104
32799
  } catch (error) {
32105
32800
  throw new CliUsageError(
32106
32801
  `analyst sweep attachment is not a readable regular file: ${sourcePath}`,
@@ -32220,7 +32915,7 @@ __export(cli_exports, {
32220
32915
  runAkRole: () => runAkRole
32221
32916
  });
32222
32917
  import { realpath as realpath6 } from "node:fs/promises";
32223
- import { join as join33 } from "node:path";
32918
+ import { join as join35 } from "node:path";
32224
32919
  function takePublicGlobalFlag(argv, index, options) {
32225
32920
  const tokens = argv.slice(index);
32226
32921
  const taken = options.takeDashed(tokens);
@@ -32351,7 +33046,7 @@ function resolveHome(env) {
32351
33046
  return env.home ?? packageMachineHome();
32352
33047
  }
32353
33048
  function resolveAgentDir(env, home) {
32354
- return env.agentDir ?? process.env.PI_CODING_AGENT_DIR ?? join33(home, ".pi", "agent");
33049
+ return env.agentDir ?? process.env.PI_CODING_AGENT_DIR ?? join35(home, ".pi", "agent");
32355
33050
  }
32356
33051
  function parseThinking(value) {
32357
33052
  if (!THINKING_LEVELS2.has(value)) {
@@ -33275,8 +33970,8 @@ var init_cli = __esm({
33275
33970
  });
33276
33971
 
33277
33972
  // src/public-cli/main.ts
33278
- import { existsSync as existsSync11 } from "node:fs";
33279
- import { dirname as dirname14, join as join34 } from "node:path";
33973
+ import { existsSync as existsSync12 } from "node:fs";
33974
+ import { dirname as dirname14, join as join36 } from "node:path";
33280
33975
  import { fileURLToPath as fileURLToPath4 } from "node:url";
33281
33976
 
33282
33977
  // src/public-cli/host-pi-runtime.ts
@@ -33365,8 +34060,8 @@ function linkPackage(packageRoot2, name, targetDir) {
33365
34060
  // src/public-cli/main.ts
33366
34061
  var here = dirname14(fileURLToPath4(import.meta.url));
33367
34062
  function resolvePackageRoot(binDir) {
33368
- const canonical = join34(binDir, "..", "..");
33369
- if (existsSync11(join34(canonical, "package.json"))) {
34063
+ const canonical = join36(binDir, "..", "..");
34064
+ if (existsSync12(join36(canonical, "package.json"))) {
33370
34065
  return canonical;
33371
34066
  }
33372
34067
  return binDir;