@akagilnc/pi-workflow-roles 0.1.4295 → 0.1.4321

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.
@@ -3126,85 +3126,6 @@ var init_sitian_reader = __esm({
3126
3126
  }
3127
3127
  });
3128
3128
 
3129
- // src/atomic-write.ts
3130
- import { randomUUID as randomUUID2 } from "node:crypto";
3131
- import { rename, rm as rm2, writeFile as writeFile2 } from "node:fs/promises";
3132
- import { dirname as dirname6, join as join9 } from "node:path";
3133
- async function writeFileAtomically(destination, contents) {
3134
- const parent = dirname6(destination);
3135
- const temporary = join9(parent, `.atomic-write-${randomUUID2()}.tmp`);
3136
- try {
3137
- await writeFile2(temporary, contents);
3138
- await rename(temporary, destination);
3139
- } catch (error) {
3140
- await rm2(temporary, { force: true }).catch(() => void 0);
3141
- throw error;
3142
- }
3143
- }
3144
- var init_atomic_write = __esm({
3145
- "src/atomic-write.ts"() {
3146
- "use strict";
3147
- }
3148
- });
3149
-
3150
- // src/sitian-volume.ts
3151
- import { appendFileSync as appendFileSync2 } from "node:fs";
3152
- import { readFile as readFile5 } from "node:fs/promises";
3153
- function resolveSitianVolume(input) {
3154
- const path = resolveSitianRecordPath(input);
3155
- return { recordFile: path.recordFile, volumeDir: path.sessionDir };
3156
- }
3157
- function ensureSitianVolume(input) {
3158
- try {
3159
- const { sessionDir, recordFile, ledgerHome } = resolveSitianRecordPath(input);
3160
- ensureRealDirectoryTree(ledgerHome, sessionDir);
3161
- appendFileSync2(recordFile, "", "utf8");
3162
- return { recordFile, volumeDir: sessionDir };
3163
- } catch (error) {
3164
- if (error instanceof SitianInfrastructureError) throw error;
3165
- throw new SitianInfrastructureError(
3166
- `Sitian volume ensure failure: ${errorText(error)}`,
3167
- { cause: error }
3168
- );
3169
- }
3170
- }
3171
- async function readSitianVolumeText(input) {
3172
- const { recordFile } = resolveSitianVolume(input);
3173
- try {
3174
- return { recordFile, text: await readFile5(recordFile, "utf8") };
3175
- } catch (error) {
3176
- if (error.code === "ENOENT") {
3177
- return { recordFile, text: void 0 };
3178
- }
3179
- throw new SitianInfrastructureError(
3180
- `Sitian volume read failure: ${errorText(error)}`,
3181
- { cause: error }
3182
- );
3183
- }
3184
- }
3185
- async function rewriteSitianVolume(input) {
3186
- try {
3187
- const volume = ensureSitianVolume(input);
3188
- await writeFileAtomically(volume.recordFile, input.body);
3189
- return volume;
3190
- } catch (error) {
3191
- if (error instanceof SitianInfrastructureError) throw error;
3192
- throw new SitianInfrastructureError(
3193
- `Sitian volume rewrite failure: ${errorText(error)}`,
3194
- { cause: error }
3195
- );
3196
- }
3197
- }
3198
- var init_sitian_volume = __esm({
3199
- "src/sitian-volume.ts"() {
3200
- "use strict";
3201
- init_activation_ledger_topology();
3202
- init_atomic_write();
3203
- init_sitian_appender();
3204
- init_sitian_contracts();
3205
- }
3206
- });
3207
-
3208
3129
  // src/sitian-facade.ts
3209
3130
  function sitianReport(input) {
3210
3131
  return appendSitianRecord(input);
@@ -3216,7 +3137,6 @@ var init_sitian_facade = __esm({
3216
3137
  init_sitian_contracts();
3217
3138
  init_sitian_appender();
3218
3139
  init_sitian_reader();
3219
- init_sitian_volume();
3220
3140
  }
3221
3141
  });
3222
3142
 
@@ -3234,13 +3154,13 @@ __export(role_turn_host_exports, {
3234
3154
  });
3235
3155
  import { execFile, spawn as spawn3 } from "node:child_process";
3236
3156
  import { constants } from "node:fs";
3237
- import { access, appendFile, readFile as readFile6, realpath as realpath2 } from "node:fs/promises";
3238
- import { basename as basename3, delimiter, dirname as dirname7, isAbsolute as isAbsolute3, join as join10, resolve as resolve5 } from "node:path";
3157
+ import { access, appendFile, readFile as readFile5, realpath as realpath2 } from "node:fs/promises";
3158
+ import { basename as basename3, delimiter, dirname as dirname6, isAbsolute as isAbsolute3, join as join9, resolve as resolve5 } from "node:path";
3239
3159
  import { platform } from "node:process";
3240
3160
  import { promisify } from "node:util";
3241
- import { randomUUID as randomUUID3 } from "node:crypto";
3161
+ import { randomUUID as randomUUID2 } from "node:crypto";
3242
3162
  function resolveInternalRoleEntrypoint(packageRoot) {
3243
- return join10(packageRoot, INTERNAL_ROLE_ENTRYPOINT_RELATIVE);
3163
+ return join9(packageRoot, INTERNAL_ROLE_ENTRYPOINT_RELATIVE);
3244
3164
  }
3245
3165
  function buildExplicitInternalActivationArgs(selectedRoleEntry, extraArgs = []) {
3246
3166
  return ["--no-extensions", "-e", selectedRoleEntry, ...extraArgs];
@@ -3276,7 +3196,7 @@ function buildMethodArgs(methods) {
3276
3196
  function applyPiNativeSkillInvocation(methods, prompt) {
3277
3197
  const skills = methods.filter((method) => method.kind === "skill");
3278
3198
  if (skills.length !== 1) return prompt;
3279
- const name = basename3(dirname7(skills[0].path));
3199
+ const name = basename3(dirname6(skills[0].path));
3280
3200
  if (name.length === 0) return prompt;
3281
3201
  const token = `/skill:${name}`;
3282
3202
  const trimmed = prompt.trimStart();
@@ -3517,7 +3437,7 @@ ${paths.join("\n")}`
3517
3437
  }
3518
3438
  async function appendPiSessionCustomEntry(authority, principal, customType, data) {
3519
3439
  const { sessionFile } = authority.decode(principal);
3520
- const text = await readFile6(sessionFile, "utf8");
3440
+ const text = await readFile5(sessionFile, "utf8");
3521
3441
  let parentId = null;
3522
3442
  for (const line2 of text.trim().split("\n").filter(Boolean)) {
3523
3443
  const entry = JSON.parse(line2);
@@ -3528,7 +3448,7 @@ async function appendPiSessionCustomEntry(authority, principal, customType, data
3528
3448
  type: "custom",
3529
3449
  customType,
3530
3450
  data,
3531
- id: randomUUID3(),
3451
+ id: randomUUID2(),
3532
3452
  parentId,
3533
3453
  timestamp: timestamp2
3534
3454
  })}
@@ -3684,8 +3604,8 @@ var init_host_descriptions = __esm({
3684
3604
 
3685
3605
  // src/role-run-relocation.ts
3686
3606
  import { existsSync as existsSync4 } from "node:fs";
3687
- import { readdir as readdir2, readFile as readFile7, writeFile as writeFile3 } from "node:fs/promises";
3688
- import { join as join11, sep as sep2 } from "node:path";
3607
+ import { readdir as readdir2, readFile as readFile6, writeFile as writeFile2 } from "node:fs/promises";
3608
+ import { join as join10, sep as sep2 } from "node:path";
3689
3609
  function isEnoent2(error) {
3690
3610
  return error instanceof Error && "code" in error && error.code === "ENOENT";
3691
3611
  }
@@ -3774,15 +3694,15 @@ function rewriteSummonsMaterials(value, rewrites) {
3774
3694
  }
3775
3695
  async function rewriteJsonObjectFile(path, fields, rewrites) {
3776
3696
  if (!existsSync4(path)) return;
3777
- const page = JSON.parse(await readFile7(path, "utf8"));
3697
+ const page = JSON.parse(await readFile6(path, "utf8"));
3778
3698
  if (!isPlainObject(page)) return;
3779
3699
  rewriteRunDirectoryPathFieldsAgainstRewrites(page, fields, rewrites);
3780
- await writeFile3(path, `${JSON.stringify(page, null, 2)}
3700
+ await writeFile2(path, `${JSON.stringify(page, null, 2)}
3781
3701
  `, "utf8");
3782
3702
  }
3783
3703
  async function rewriteOfficerPointerFile(path, rewrites) {
3784
3704
  if (!existsSync4(path)) return;
3785
- const page = JSON.parse(await readFile7(path, "utf8"));
3705
+ const page = JSON.parse(await readFile6(path, "utf8"));
3786
3706
  if (!isPlainObject(page)) return;
3787
3707
  if (page.kind !== "direct-officer-run-pointer") return;
3788
3708
  rewriteRunDirectoryPathFieldsAgainstRewrites(
@@ -3790,12 +3710,12 @@ async function rewriteOfficerPointerFile(path, rewrites) {
3790
3710
  OFFICER_POINTER_FIELDS,
3791
3711
  rewrites
3792
3712
  );
3793
- await writeFile3(path, `${JSON.stringify(page)}
3713
+ await writeFile2(path, `${JSON.stringify(page)}
3794
3714
  `, "utf8");
3795
3715
  }
3796
3716
  async function rewriteSitianRecordsJsonl(path, rewrites) {
3797
3717
  if (!existsSync4(path)) return;
3798
- const raw = await readFile7(path, "utf8");
3718
+ const raw = await readFile6(path, "utf8");
3799
3719
  if (raw.length === 0) return;
3800
3720
  const endsWithNewline = raw.endsWith("\n");
3801
3721
  const lines = raw.split("\n");
@@ -3837,7 +3757,7 @@ async function rewriteSitianRecordsJsonl(path, rewrites) {
3837
3757
  }
3838
3758
  if (!changed) return;
3839
3759
  const body = out.join("\n");
3840
- await writeFile3(
3760
+ await writeFile2(
3841
3761
  path,
3842
3762
  endsWithNewline && !body.endsWith("\n") ? `${body}
3843
3763
  ` : body,
@@ -3846,7 +3766,7 @@ async function rewriteSitianRecordsJsonl(path, rewrites) {
3846
3766
  }
3847
3767
  async function rewriteSessionTranscriptBindings(path, rewrites) {
3848
3768
  if (!existsSync4(path)) return;
3849
- const raw = await readFile7(path, "utf8");
3769
+ const raw = await readFile6(path, "utf8");
3850
3770
  if (raw.length === 0) return;
3851
3771
  const endsWithNewline = raw.endsWith("\n");
3852
3772
  const lines = raw.split("\n");
@@ -3897,7 +3817,7 @@ async function rewriteSessionTranscriptBindings(path, rewrites) {
3897
3817
  }
3898
3818
  if (!changed) return;
3899
3819
  const body = out.join("\n");
3900
- await writeFile3(
3820
+ await writeFile2(
3901
3821
  path,
3902
3822
  endsWithNewline && !body.endsWith("\n") ? `${body}
3903
3823
  ` : body,
@@ -3905,7 +3825,7 @@ async function rewriteSessionTranscriptBindings(path, rewrites) {
3905
3825
  );
3906
3826
  }
3907
3827
  async function rewriteNestedMachinePathPages(pagesDirectory, rewrites) {
3908
- const sessionRoot = join11(pagesDirectory, "session");
3828
+ const sessionRoot = join10(pagesDirectory, "session");
3909
3829
  async function walk(directory) {
3910
3830
  let entries;
3911
3831
  try {
@@ -3915,7 +3835,7 @@ async function rewriteNestedMachinePathPages(pagesDirectory, rewrites) {
3915
3835
  throw error;
3916
3836
  }
3917
3837
  for (const entry of entries) {
3918
- const path = join11(directory, entry.name);
3838
+ const path = join10(directory, entry.name);
3919
3839
  if (entry.isDirectory()) {
3920
3840
  await walk(path);
3921
3841
  continue;
@@ -3937,9 +3857,9 @@ async function rewriteNestedMachinePathPages(pagesDirectory, rewrites) {
3937
3857
  async function rewriteRoleRunDurablePages(input) {
3938
3858
  const { pagesDirectory } = input;
3939
3859
  const rewrites = collectRewrites(input);
3940
- const admittedPath = join11(pagesDirectory, "admitted-request.json");
3860
+ const admittedPath = join10(pagesDirectory, "admitted-request.json");
3941
3861
  if (existsSync4(admittedPath)) {
3942
- const page = JSON.parse(await readFile7(admittedPath, "utf8"));
3862
+ const page = JSON.parse(await readFile6(admittedPath, "utf8"));
3943
3863
  rewriteRunDirectoryPathFieldsAgainstRewrites(
3944
3864
  page,
3945
3865
  ADMITTED_PAGE_FIELDS,
@@ -3964,27 +3884,27 @@ async function rewriteRoleRunDurablePages(input) {
3964
3884
  rewrites
3965
3885
  );
3966
3886
  }
3967
- await writeFile3(admittedPath, `${JSON.stringify(page, null, 2)}
3887
+ await writeFile2(admittedPath, `${JSON.stringify(page, null, 2)}
3968
3888
  `, "utf8");
3969
3889
  }
3970
- const invocationPath = join11(pagesDirectory, "invocation.json");
3890
+ const invocationPath = join10(pagesDirectory, "invocation.json");
3971
3891
  if (existsSync4(invocationPath)) {
3972
- const page = JSON.parse(await readFile7(invocationPath, "utf8"));
3892
+ const page = JSON.parse(await readFile6(invocationPath, "utf8"));
3973
3893
  rewriteRunDirectoryPathFieldsAgainstRewrites(
3974
3894
  page,
3975
3895
  INVOCATION_PAGE_FIELDS,
3976
3896
  rewrites
3977
3897
  );
3978
- await writeFile3(
3898
+ await writeFile2(
3979
3899
  invocationPath,
3980
3900
  `${JSON.stringify(page, null, 2)}
3981
3901
  `,
3982
3902
  "utf8"
3983
3903
  );
3984
3904
  }
3985
- const statePath = join11(pagesDirectory, "run-state.json");
3905
+ const statePath = join10(pagesDirectory, "run-state.json");
3986
3906
  if (existsSync4(statePath)) {
3987
- const page = JSON.parse(await readFile7(statePath, "utf8"));
3907
+ const page = JSON.parse(await readFile6(statePath, "utf8"));
3988
3908
  rewriteRunDirectoryPathFieldsAgainstRewrites(
3989
3909
  page,
3990
3910
  RUN_STATE_PAGE_FIELDS,
@@ -4000,7 +3920,7 @@ async function rewriteRoleRunDurablePages(input) {
4000
3920
  if (isPlainObject(page.currentCourt)) {
4001
3921
  rewriteSummonsMaterials(page.currentCourt.summons, rewrites);
4002
3922
  }
4003
- await writeFile3(statePath, `${JSON.stringify(page, null, 2)}
3923
+ await writeFile2(statePath, `${JSON.stringify(page, null, 2)}
4004
3924
  `, "utf8");
4005
3925
  }
4006
3926
  await rewriteNestedMachinePathPages(pagesDirectory, rewrites);
@@ -4168,8 +4088,8 @@ var init_terminating_tools = __esm({
4168
4088
  });
4169
4089
 
4170
4090
  // src/doctor-evidence.ts
4171
- import { readdir as readdir3, readFile as readFile8, realpath as realpath3, stat } from "node:fs/promises";
4172
- import { dirname as dirname8, relative as relative2, resolve as resolve6, sep as sep3 } from "node:path";
4091
+ import { readdir as readdir3, readFile as readFile7, realpath as realpath3, stat } from "node:fs/promises";
4092
+ import { dirname as dirname7, relative as relative2, resolve as resolve6, sep as sep3 } from "node:path";
4173
4093
  function record3(value) {
4174
4094
  return typeof value === "object" && value !== null && !Array.isArray(value);
4175
4095
  }
@@ -4208,7 +4128,7 @@ async function stableRunsIdentity(root) {
4208
4128
  } catch (error) {
4209
4129
  if (!isMissingPathError2(error)) throw error;
4210
4130
  }
4211
- const parent = dirname8(cursor);
4131
+ const parent = dirname7(cursor);
4212
4132
  if (parent === cursor) return root;
4213
4133
  cursor = parent;
4214
4134
  }
@@ -4284,7 +4204,7 @@ async function loadDoctorCase(runsPath) {
4284
4204
  const turns = { count: 0, sources: [] }, calls = { count: 0, sources: [] }, tokens = { count: 0, sources: [] };
4285
4205
  for (const path of await discoverCaseFiles(root)) {
4286
4206
  const id = relative2(root, path).split(sep3).join("/");
4287
- const bytes = await readFile8(path);
4207
+ const bytes = await readFile7(path);
4288
4208
  const content = bytes.toString("utf8");
4289
4209
  const kind = id.endsWith(".jsonl") ? "session" : "stderr";
4290
4210
  evidence.push({ id, kind, byteLength: bytes.byteLength, contentLength: content.length, sha256: sha256Hex(bytes), content });
@@ -4524,7 +4444,7 @@ var init_git_object_id = __esm({
4524
4444
 
4525
4445
  // src/merger-git-state.ts
4526
4446
  import { execFile as execFile2 } from "node:child_process";
4527
- import { access as access2, readFile as readFile9 } from "node:fs/promises";
4447
+ import { access as access2, readFile as readFile8 } from "node:fs/promises";
4528
4448
  import { constants as fsConstants } from "node:fs";
4529
4449
  import { isAbsolute as isAbsolute4, resolve as resolve7 } from "node:path";
4530
4450
  import { promisify as promisify2 } from "node:util";
@@ -4594,7 +4514,7 @@ function createProductionMergerGitState(repositoryRoot = process.cwd()) {
4594
4514
  const mergeHeadPath = isAbsolute4(mergeHeadReported) ? mergeHeadReported : resolve7(repositoryRoot, mergeHeadReported);
4595
4515
  let sourceObjectId = "";
4596
4516
  if (await pathExists(mergeHeadPath)) {
4597
- const raw = exactUtf8(await readFile9(mergeHeadPath), "Git MERGE_HEAD");
4517
+ const raw = exactUtf8(await readFile8(mergeHeadPath), "Git MERGE_HEAD");
4598
4518
  const mergeHeads = raw.trim().split(/\r?\n/).map((row) => row.trim()).filter(Boolean);
4599
4519
  if (mergeHeads.length === 0) throw new Error("Git MERGE_HEAD is empty");
4600
4520
  if (mergeHeads.length !== 1) throw new Error("Assigned repository does not have one ordinary in-progress merge");
@@ -4646,10 +4566,10 @@ var init_uuidv7 = __esm({
4646
4566
  });
4647
4567
 
4648
4568
  // src/typed-provider-http.ts
4649
- import { readFile as readFile10, unlink, writeFile as writeFile4 } from "node:fs/promises";
4650
- import { join as join12 } from "node:path";
4569
+ import { readFile as readFile9, unlink, writeFile as writeFile3 } from "node:fs/promises";
4570
+ import { join as join11 } from "node:path";
4651
4571
  function typedProviderHttpPath(runDirectory) {
4652
- return join12(runDirectory, TYPED_HTTP_FILE);
4572
+ return join11(runDirectory, TYPED_HTTP_FILE);
4653
4573
  }
4654
4574
  async function clearTypedProviderHttpObservation(runDirectory) {
4655
4575
  try {
@@ -4670,7 +4590,7 @@ async function recordTypedProviderHttpStatus(runDirectory, observation) {
4670
4590
  httpStatus: observation.httpStatus,
4671
4591
  provider: observation.provider
4672
4592
  };
4673
- await writeFile4(
4593
+ await writeFile3(
4674
4594
  typedProviderHttpPath(runDirectory),
4675
4595
  `${JSON.stringify(body)}
4676
4596
  `,
@@ -4680,7 +4600,7 @@ async function recordTypedProviderHttpStatus(runDirectory, observation) {
4680
4600
  async function readLatestTypedProviderHttpObservation(runDirectory) {
4681
4601
  let text;
4682
4602
  try {
4683
- text = await readFile10(typedProviderHttpPath(runDirectory), "utf8");
4603
+ text = await readFile9(typedProviderHttpPath(runDirectory), "utf8");
4684
4604
  } catch (error) {
4685
4605
  if (error instanceof Error && "code" in error && error.code === "ENOENT") {
4686
4606
  return void 0;
@@ -4709,8 +4629,8 @@ var init_typed_provider_http = __esm({
4709
4629
  });
4710
4630
 
4711
4631
  // src/public-cli/run-lifecycle.ts
4712
- import { chmod, lstat as lstat2, open, readdir as readdir4, readFile as readFile11, unlink as unlink2, writeFile as writeFile5 } from "node:fs/promises";
4713
- import { basename as basename4, join as join13 } from "node:path";
4632
+ import { chmod, lstat as lstat2, open, readdir as readdir4, readFile as readFile10, unlink as unlink2, writeFile as writeFile4 } from "node:fs/promises";
4633
+ import { basename as basename4, join as join12 } from "node:path";
4714
4634
  function selectResumeContinuationPrompt(message, engineMaterial) {
4715
4635
  const lines = message !== void 0 ? [message] : [];
4716
4636
  return appendEngineSessionMaterial(lines, engineMaterial).join("\n");
@@ -4739,8 +4659,8 @@ function renderResumeCommand(runId) {
4739
4659
  }
4740
4660
  async function writeRoleRunState(runDirectory, record4) {
4741
4661
  const payload = { ...record4, runDirectory };
4742
- await writeFile5(
4743
- join13(runDirectory, RUN_STATE_FILE),
4662
+ await writeFile4(
4663
+ join12(runDirectory, RUN_STATE_FILE),
4744
4664
  `${JSON.stringify(payload, null, 2)}
4745
4665
  `,
4746
4666
  "utf8"
@@ -4790,7 +4710,7 @@ function parseCurrentCourtState(raw) {
4790
4710
  async function readRoleRunStateDisk(runDirectory) {
4791
4711
  let raw;
4792
4712
  try {
4793
- raw = JSON.parse(await readFile11(join13(runDirectory, RUN_STATE_FILE), "utf8"));
4713
+ raw = JSON.parse(await readFile10(join12(runDirectory, RUN_STATE_FILE), "utf8"));
4794
4714
  } catch (error) {
4795
4715
  if (errorCodeOf2(error) === "ENOENT") return void 0;
4796
4716
  throw error;
@@ -4857,8 +4777,8 @@ async function writeRoleRunStateDisk(runDirectory, disk) {
4857
4777
  ...disk.resumable === void 0 ? {} : { resumable: disk.resumable },
4858
4778
  ...disk.currentCourt === void 0 ? {} : { currentCourt: disk.currentCourt }
4859
4779
  };
4860
- await writeFile5(
4861
- join13(runDirectory, RUN_STATE_FILE),
4780
+ await writeFile4(
4781
+ join12(runDirectory, RUN_STATE_FILE),
4862
4782
  `${JSON.stringify(payload, null, 2)}
4863
4783
  `,
4864
4784
  "utf8"
@@ -5025,7 +4945,7 @@ function isProcessAlive(pid) {
5025
4945
  async function autopsyWriterLock(lockPath) {
5026
4946
  let content;
5027
4947
  try {
5028
- content = await readFile11(lockPath, "utf8");
4948
+ content = await readFile10(lockPath, "utf8");
5029
4949
  } catch (error) {
5030
4950
  if (errorCodeOf2(error) === "ENOENT") return { verdict: "absent" };
5031
4951
  return { verdict: "unknown", reason: "unreadable", readFailure: error };
@@ -5084,7 +5004,7 @@ async function createWriterLease(lockPath, runDirectory, reportCleanupFailure) {
5084
5004
  },
5085
5005
  relocate(nextRunDirectory) {
5086
5006
  currentRunDirectory = nextRunDirectory;
5087
- currentLockPath = join13(nextRunDirectory, WRITER_LOCK_FILE);
5007
+ currentLockPath = join12(nextRunDirectory, WRITER_LOCK_FILE);
5088
5008
  },
5089
5009
  async release() {
5090
5010
  if (released) return;
@@ -5123,10 +5043,10 @@ async function acquireRunWriterLease(runDirectory, onCleanupFailure) {
5123
5043
  };
5124
5044
  const reportReadFailure = (error) => {
5125
5045
  reportDiagnostic(
5126
- `writer lease lock read failed (holder liveness unverifiable; lock left in place) at ${join13(runDirectory, WRITER_LOCK_FILE)}: ${describeErrorIdentity(error)}`
5046
+ `writer lease lock read failed (holder liveness unverifiable; lock left in place) at ${join12(runDirectory, WRITER_LOCK_FILE)}: ${describeErrorIdentity(error)}`
5127
5047
  );
5128
5048
  };
5129
- const lockPath = join13(runDirectory, WRITER_LOCK_FILE);
5049
+ const lockPath = join12(runDirectory, WRITER_LOCK_FILE);
5130
5050
  let lastAutopsy = { verdict: "absent" };
5131
5051
  let lastReclaimFailure;
5132
5052
  for (let reclaimsLeft = WRITER_LEASE_RECLAIM_ROUNDS; ; reclaimsLeft -= 1) {
@@ -5181,7 +5101,7 @@ async function acquireRunWriterLease(runDirectory, onCleanupFailure) {
5181
5101
  async function findRunDirectoryById(home, runId, onlyBookKey, onlyRole) {
5182
5102
  if (runId.trim() === "") return void 0;
5183
5103
  const ledgerHome = resolveActivationLedgerHome(home);
5184
- const booksRoot = join13(ledgerHome, "books");
5104
+ const booksRoot = join12(ledgerHome, "books");
5185
5105
  let bookKeys;
5186
5106
  try {
5187
5107
  bookKeys = await readdir4(booksRoot);
@@ -5222,7 +5142,7 @@ async function readRunParentPath(runDirectory) {
5222
5142
  let raw;
5223
5143
  try {
5224
5144
  raw = JSON.parse(
5225
- await readFile11(join13(runDirectory, "admitted-request.json"), "utf8")
5145
+ await readFile10(join12(runDirectory, "admitted-request.json"), "utf8")
5226
5146
  );
5227
5147
  } catch (error) {
5228
5148
  if (errorCodeOf2(error) === "ENOENT") return void 0;
@@ -5243,7 +5163,7 @@ async function readRunParentPath(runDirectory) {
5243
5163
  async function runHasFormedSessionPrincipal(runDirectory) {
5244
5164
  const disk = await readRoleRunStateDisk(runDirectory);
5245
5165
  if (disk === void 0) return false;
5246
- const sessionFile = typeof disk.principalWire.sessionFile === "string" && disk.principalWire.sessionFile.trim() !== "" ? disk.principalWire.sessionFile : join13(disk.principalWire.sessionDirectory, "session.jsonl");
5166
+ const sessionFile = typeof disk.principalWire.sessionFile === "string" && disk.principalWire.sessionFile.trim() !== "" ? disk.principalWire.sessionFile : join12(disk.principalWire.sessionDirectory, "session.jsonl");
5247
5167
  try {
5248
5168
  const stat2 = await lstat2(sessionFile);
5249
5169
  return stat2.isFile() && !stat2.isSymbolicLink();
@@ -5390,7 +5310,7 @@ async function loadResumableRunRecord(home, runId, authority) {
5390
5310
  let sourceRun;
5391
5311
  try {
5392
5312
  const raw = JSON.parse(
5393
- await readFile11(run.admittedRequestPath, "utf8")
5313
+ await readFile10(run.admittedRequestPath, "utf8")
5394
5314
  );
5395
5315
  if (raw !== null && typeof raw === "object" && !Array.isArray(raw)) {
5396
5316
  const record4 = raw;
@@ -5505,7 +5425,7 @@ async function loadResumableRunRecord(home, runId, authority) {
5505
5425
  let model;
5506
5426
  try {
5507
5427
  const invocationRaw = JSON.parse(
5508
- await readFile11(join13(run.runDirectory, "invocation.json"), "utf8")
5428
+ await readFile10(join12(run.runDirectory, "invocation.json"), "utf8")
5509
5429
  );
5510
5430
  if (invocationRaw !== null && typeof invocationRaw === "object" && !Array.isArray(invocationRaw)) {
5511
5431
  const rec = invocationRaw;
@@ -5736,7 +5656,7 @@ __export(notary_source_run_exports, {
5736
5656
  loadNotarySourceRunLocator: () => loadNotarySourceRunLocator,
5737
5657
  resolveNotarySourceRunLocator: () => resolveNotarySourceRunLocator
5738
5658
  });
5739
- import { dirname as dirname9, isAbsolute as isAbsolute6, join as join14, resolve as resolve8, basename as basename5 } from "node:path";
5659
+ import { dirname as dirname8, isAbsolute as isAbsolute6, join as join13, resolve as resolve8, basename as basename5 } from "node:path";
5740
5660
  import { lstat as lstat3, realpath as realpath4 } from "node:fs/promises";
5741
5661
  function parseRunDirectoryName(name) {
5742
5662
  const match = RUN_DIR_NAME.exec(name);
@@ -5782,20 +5702,20 @@ async function resolveNotarySourceRunLocator(options) {
5782
5702
  }
5783
5703
  const ledgerHome = resolveActivationLedgerHome(options.home);
5784
5704
  const bookKey = resolveBookKeyFromGit(options.projectRoot);
5785
- const bookRunsRoot = join14(activationBookDirectory(ledgerHome, bookKey), "runs");
5705
+ const bookRunsRoot = join13(activationBookDirectory(ledgerHome, bookKey), "runs");
5786
5706
  let candidate;
5787
5707
  const bare = parseRunDirectoryName(raw);
5788
5708
  if (bare !== void 0 && !raw.includes("/") && !raw.includes("\\")) {
5789
- candidate = await findRunDirectoryById(options.home, bare.runId, bookKey, bare.role) ?? join14(bookRunsRoot, `${bare.runId}@${bare.role}`);
5709
+ candidate = await findRunDirectoryById(options.home, bare.runId, bookKey, bare.role) ?? join13(bookRunsRoot, `${bare.runId}@${bare.role}`);
5790
5710
  } else {
5791
5711
  candidate = isAbsolute6(raw) ? raw : resolve8(options.projectRoot, raw);
5792
5712
  }
5793
5713
  const real = await requireRunDirectory(candidate, raw);
5794
5714
  const identity = parseRunDirectoryName(basename5(real));
5795
5715
  const bookIdentity = physicalPathIdentity(activationBookDirectory(ledgerHome, bookKey));
5796
- const parentIdentity = physicalPathIdentity(dirname9(real));
5797
- const subjectBookIdentity = physicalPathIdentity(dirname9(dirname9(dirname9(real))));
5798
- if (parentIdentity !== physicalPathIdentity(bookRunsRoot) && !(basename5(dirname9(real)) === "runs" && subjectBookIdentity === bookIdentity)) {
5716
+ const parentIdentity = physicalPathIdentity(dirname8(real));
5717
+ const subjectBookIdentity = physicalPathIdentity(dirname8(dirname8(dirname8(real))));
5718
+ if (parentIdentity !== physicalPathIdentity(bookRunsRoot) && !(basename5(dirname8(real)) === "runs" && subjectBookIdentity === bookIdentity)) {
5799
5719
  throw new NotarySourceRunError(
5800
5720
  "notary --source-run must resolve to a retained run under the project machine-ledger book"
5801
5721
  );
@@ -6936,12 +6856,12 @@ import { execFileSync as execFileSync3 } from "node:child_process";
6936
6856
  import { existsSync as existsSync5 } from "node:fs";
6937
6857
  import {
6938
6858
  lstat as lstat4,
6939
- readFile as readFile12,
6859
+ readFile as readFile11,
6940
6860
  realpath as realpath5,
6941
- rename as rename2,
6942
- writeFile as writeFile6
6861
+ rename,
6862
+ writeFile as writeFile5
6943
6863
  } from "node:fs/promises";
6944
- import { basename as basename6, dirname as dirname10, isAbsolute as isAbsolute7, join as join15, resolve as resolve9, sep as sep4 } from "node:path";
6864
+ import { basename as basename6, dirname as dirname9, isAbsolute as isAbsolute7, join as join14, resolve as resolve9, sep as sep4 } from "node:path";
6945
6865
  function issueAdmissionPlacement(authority, request) {
6946
6866
  const ledgerHome = resolveActivationLedgerHome(request.home);
6947
6867
  const bookKey = resolveBookKeyFromGit(request.cwd);
@@ -6966,7 +6886,7 @@ async function writeAdmittedRequestPersistence(admittedRequestPath, body, coordi
6966
6886
  sessionDirectory: coordinates.sessionDirectory,
6967
6887
  sessionFile: coordinates.sessionFile
6968
6888
  };
6969
- await writeFile6(
6889
+ await writeFile5(
6970
6890
  admittedRequestPath,
6971
6891
  `${JSON.stringify(projection, null, 2)}
6972
6892
  `,
@@ -6994,16 +6914,16 @@ async function writeRoleInvocationLedger(source, role, effectiveModel) {
6994
6914
  ...source.ticketNumber === void 0 ? {} : { ticketNumber: source.ticketNumber },
6995
6915
  ...effectiveModelLedgerFields(effectiveModel)
6996
6916
  };
6997
- await writeFile6(
6998
- join15(source.runDirectory, "invocation.json"),
6917
+ await writeFile5(
6918
+ join14(source.runDirectory, "invocation.json"),
6999
6919
  `${JSON.stringify(identity, null, 2)}
7000
6920
  `,
7001
6921
  "utf8"
7002
6922
  );
7003
6923
  }
7004
6924
  async function recordEffectiveInvocationModel(runDirectory, model, engine, host, engineModel) {
7005
- const ledgerPath = join15(runDirectory, "invocation.json");
7006
- const current = JSON.parse(await readFile12(ledgerPath, "utf8"));
6925
+ const ledgerPath = join14(runDirectory, "invocation.json");
6926
+ const current = JSON.parse(await readFile11(ledgerPath, "utf8"));
7007
6927
  const next = { ...current };
7008
6928
  if (model !== void 0) {
7009
6929
  next.provider = model.provider;
@@ -7027,7 +6947,7 @@ async function recordEffectiveInvocationModel(runDirectory, model, engine, host,
7027
6947
  if (host !== void 0) {
7028
6948
  next.host = host;
7029
6949
  }
7030
- await writeFile6(
6950
+ await writeFile5(
7031
6951
  ledgerPath,
7032
6952
  `${JSON.stringify(next, null, 2)}
7033
6953
  `,
@@ -7035,9 +6955,9 @@ async function recordEffectiveInvocationModel(runDirectory, model, engine, host,
7035
6955
  );
7036
6956
  }
7037
6957
  async function mergeInvocationIdentityPage(runDirectory, fields) {
7038
- const ledgerPath = join15(runDirectory, "invocation.json");
7039
- const current = JSON.parse(await readFile12(ledgerPath, "utf8"));
7040
- await writeFile6(
6958
+ const ledgerPath = join14(runDirectory, "invocation.json");
6959
+ const current = JSON.parse(await readFile11(ledgerPath, "utf8"));
6960
+ await writeFile5(
7041
6961
  ledgerPath,
7042
6962
  `${JSON.stringify({
7043
6963
  ...current,
@@ -7052,14 +6972,14 @@ async function persistAdmittedSourceRunPath(admitted, sourceRunPath) {
7052
6972
  throw new Error("persistAdmittedSourceRunPath requires a non-empty sourceRunPath");
7053
6973
  }
7054
6974
  const admittedPath = admitted.admittedRequestPath;
7055
- const current = JSON.parse(await readFile12(admittedPath, "utf8"));
6975
+ const current = JSON.parse(await readFile11(admittedPath, "utf8"));
7056
6976
  if (typeof current.sourceRunPath === "string") {
7057
6977
  if (current.sourceRunPath === sourceRunPath) return;
7058
6978
  throw new Error(
7059
6979
  `persistAdmittedSourceRunPath refuses to replace ${current.sourceRunPath} with ${sourceRunPath}`
7060
6980
  );
7061
6981
  }
7062
- await writeFile6(
6982
+ await writeFile5(
7063
6983
  admittedPath,
7064
6984
  `${JSON.stringify({ ...current, sourceRunPath }, null, 2)}
7065
6985
  `,
@@ -7101,8 +7021,8 @@ async function bindCourtTicketNumbersOnAdmitted(admitted, courtTicketNumbers) {
7101
7021
  }
7102
7022
  const frozen = Object.freeze([...projected]);
7103
7023
  const admittedPath = admitted.admittedRequestPath;
7104
- const current = JSON.parse(await readFile12(admittedPath, "utf8"));
7105
- await writeFile6(
7024
+ const current = JSON.parse(await readFile11(admittedPath, "utf8"));
7025
+ await writeFile5(
7106
7026
  admittedPath,
7107
7027
  `${JSON.stringify({ ...current, courtTicketNumbers: frozen }, null, 2)}
7108
7028
  `,
@@ -7123,8 +7043,8 @@ async function relocateAdmittedRunToTicket(admitted, authority, heldLease) {
7123
7043
  runId: admitted.runId,
7124
7044
  role: admitted.role
7125
7045
  });
7126
- ensureRoleRunDirectory(ledgerHome, dirname10(target.runDirectory));
7127
- await rename2(oldRunDirectory, target.runDirectory);
7046
+ ensureRoleRunDirectory(ledgerHome, dirname9(target.runDirectory));
7047
+ await rename(oldRunDirectory, target.runDirectory);
7128
7048
  heldLease?.relocate(target.runDirectory);
7129
7049
  const admittedRecord = admitted;
7130
7050
  rewriteRunDirectoryPathFields(
@@ -7161,9 +7081,9 @@ async function bindTicketNumberOnRunDirectory(runDirectory, ticketNumber) {
7161
7081
  ticketNumber,
7162
7082
  "bindTicketNumberOnRunDirectory"
7163
7083
  );
7164
- const admittedPath = join15(runDirectory, "admitted-request.json");
7165
- const invocationPath = join15(runDirectory, "invocation.json");
7166
- const admitted = JSON.parse(await readFile12(admittedPath, "utf8"));
7084
+ const admittedPath = join14(runDirectory, "admitted-request.json");
7085
+ const invocationPath = join14(runDirectory, "invocation.json");
7086
+ const admitted = JSON.parse(await readFile11(admittedPath, "utf8"));
7167
7087
  const existing = admitted.ticketNumber;
7168
7088
  if (typeof existing === "number") {
7169
7089
  if (existing === ticketNumber) return;
@@ -7173,7 +7093,7 @@ async function bindTicketNumberOnRunDirectory(runDirectory, ticketNumber) {
7173
7093
  }
7174
7094
  if (existsSync5(invocationPath)) {
7175
7095
  const invocation = JSON.parse(
7176
- await readFile12(invocationPath, "utf8")
7096
+ await readFile11(invocationPath, "utf8")
7177
7097
  );
7178
7098
  if (typeof invocation.ticketNumber === "number" && invocation.ticketNumber !== ticketNumber) {
7179
7099
  throw new Error(
@@ -7181,7 +7101,7 @@ async function bindTicketNumberOnRunDirectory(runDirectory, ticketNumber) {
7181
7101
  );
7182
7102
  }
7183
7103
  }
7184
- await writeFile6(
7104
+ await writeFile5(
7185
7105
  admittedPath,
7186
7106
  `${JSON.stringify({ ...admitted, ticketNumber }, null, 2)}
7187
7107
  `,
@@ -7198,7 +7118,7 @@ async function recordLaunchedPiIdentity(runDirectory, identity) {
7198
7118
  async function observeLaunchedRolePackageIdentity(packageRoot, selectedRoleEntry) {
7199
7119
  const rolePackageRoot = packageRoot;
7200
7120
  const raw = JSON.parse(
7201
- await readFile12(join15(rolePackageRoot, "package.json"), "utf8")
7121
+ await readFile11(join14(rolePackageRoot, "package.json"), "utf8")
7202
7122
  );
7203
7123
  if (typeof raw.version !== "string" || raw.version.trim() === "") {
7204
7124
  throw new Error(
@@ -7454,10 +7374,10 @@ async function freezeRegularFileAttachment(sourcePath, destinationDir, index) {
7454
7374
  `attachment must be a regular file (not a directory or symlink): ${sourcePath}`
7455
7375
  );
7456
7376
  }
7457
- const bytes = await readFile12(absolute);
7377
+ const bytes = await readFile11(absolute);
7458
7378
  const name = `${String(index).padStart(2, "0")}-${basename6(absolute)}`;
7459
- const frozenPath = join15(destinationDir, name);
7460
- await writeFile6(frozenPath, bytes);
7379
+ const frozenPath = join14(destinationDir, name);
7380
+ await writeFile5(frozenPath, bytes);
7461
7381
  return {
7462
7382
  attachment: {
7463
7383
  provenancePath: absolute,
@@ -7484,7 +7404,7 @@ async function freezeAttachments(attachmentPaths, attachmentsDirectory) {
7484
7404
  async function freezeAttachmentsIntoRun(attachmentPaths, runDirectory, summonsKey = `s-${Date.now().toString(36)}`) {
7485
7405
  if (attachmentPaths.length === 0) return [];
7486
7406
  const ledgerHome = resolveActivationLedgerHome(homeFromRunDirectory(runDirectory));
7487
- const attachmentsDirectory = join15(runDirectory, "attachments", summonsKey);
7407
+ const attachmentsDirectory = join14(runDirectory, "attachments", summonsKey);
7488
7408
  ensureRealDirectoryTree(ledgerHome, attachmentsDirectory);
7489
7409
  return freezeAttachments(attachmentPaths, attachmentsDirectory);
7490
7410
  }
@@ -7542,7 +7462,7 @@ async function admitStandardMaterialInvocation(role, options) {
7542
7462
  })),
7543
7463
  ...ticketFields
7544
7464
  };
7545
- const admittedRequestPath = join15(runDirectory, "admitted-request.json");
7465
+ const admittedRequestPath = join14(runDirectory, "admitted-request.json");
7546
7466
  await writeAdmittedRequestPersistence(admittedRequestPath, admitted, {
7547
7467
  sessionDirectory,
7548
7468
  sessionFile
@@ -7644,7 +7564,7 @@ async function admitCountersignInvocation(options) {
7644
7564
  mediaKind: a.mediaKind
7645
7565
  }))
7646
7566
  };
7647
- const admittedRequestPath = join15(runDirectory, "admitted-request.json");
7567
+ const admittedRequestPath = join14(runDirectory, "admitted-request.json");
7648
7568
  await writeAdmittedRequestPersistence(admittedRequestPath, admitted, {
7649
7569
  sessionDirectory,
7650
7570
  sessionFile
@@ -7670,7 +7590,7 @@ function buildCountersignTransportPrompt(admitted, engineMaterial) {
7670
7590
  async function loadAdmittedJudgeRequest(runDirectory) {
7671
7591
  try {
7672
7592
  const raw = JSON.parse(
7673
- await readFile12(join15(runDirectory, "admitted-request.json"), "utf8")
7593
+ await readFile11(join14(runDirectory, "admitted-request.json"), "utf8")
7674
7594
  );
7675
7595
  if (raw === null || typeof raw !== "object" || Array.isArray(raw)) return void 0;
7676
7596
  const record4 = raw;
@@ -7725,8 +7645,8 @@ async function admitCoderInvocation(options) {
7725
7645
  home: options.home
7726
7646
  });
7727
7647
  const attachments = await freezeAttachments(options.attachmentPaths, attachmentsDirectory);
7728
- const taskPath = join15(runDirectory, "task.md");
7729
- await writeFile6(taskPath, instruction, "utf8");
7648
+ const taskPath = join14(runDirectory, "task.md");
7649
+ await writeFile5(taskPath, instruction, "utf8");
7730
7650
  const admitted = {
7731
7651
  role: "coder",
7732
7652
  phase: options.phase,
@@ -7746,7 +7666,7 @@ async function admitCoderInvocation(options) {
7746
7666
  mediaKind: a.mediaKind
7747
7667
  }))
7748
7668
  };
7749
- const admittedRequestPath = join15(runDirectory, "admitted-request.json");
7669
+ const admittedRequestPath = join14(runDirectory, "admitted-request.json");
7750
7670
  await writeAdmittedRequestPersistence(admittedRequestPath, admitted, {
7751
7671
  sessionDirectory,
7752
7672
  sessionFile
@@ -7796,7 +7716,7 @@ async function admitFixerInvocation(options) {
7796
7716
  if (options.prerequisitesPath !== void 0) {
7797
7717
  const absolutePrereq = isAbsolute7(options.prerequisitesPath) ? options.prerequisitesPath : resolve9(options.prerequisitesPath);
7798
7718
  try {
7799
- prerequisitesSource = await readFile12(absolutePrereq, "utf8");
7719
+ prerequisitesSource = await readFile11(absolutePrereq, "utf8");
7800
7720
  } catch (error) {
7801
7721
  throw new CliUsageError(
7802
7722
  `fixer prerequisites path is unreadable: ${options.prerequisitesPath}`,
@@ -7832,16 +7752,16 @@ async function admitFixerInvocation(options) {
7832
7752
  const attachments = await freezeAttachments(options.attachmentPaths, attachmentsDirectory);
7833
7753
  let prerequisitesPath;
7834
7754
  if (prerequisitesSource !== void 0) {
7835
- prerequisitesPath = join15(runDirectory, "prerequisites.json");
7836
- await writeFile6(
7755
+ prerequisitesPath = join14(runDirectory, "prerequisites.json");
7756
+ await writeFile5(
7837
7757
  prerequisitesPath,
7838
7758
  `${JSON.stringify(prerequisites, null, 2)}
7839
7759
  `,
7840
7760
  "utf8"
7841
7761
  );
7842
7762
  }
7843
- const packetPath = join15(runDirectory, "fix-packet.md");
7844
- await writeFile6(packetPath, instruction, "utf8");
7763
+ const packetPath = join14(runDirectory, "fix-packet.md");
7764
+ await writeFile5(packetPath, instruction, "utf8");
7845
7765
  const admitted = {
7846
7766
  role: "fixer",
7847
7767
  phase: options.phase,
@@ -7866,7 +7786,7 @@ async function admitFixerInvocation(options) {
7866
7786
  mediaKind: a.mediaKind
7867
7787
  }))
7868
7788
  };
7869
- const admittedRequestPath = join15(runDirectory, "admitted-request.json");
7789
+ const admittedRequestPath = join14(runDirectory, "admitted-request.json");
7870
7790
  await writeAdmittedRequestPersistence(admittedRequestPath, admitted, {
7871
7791
  sessionDirectory,
7872
7792
  sessionFile
@@ -8086,8 +8006,8 @@ async function admitCollectorInvocation(options) {
8086
8006
  const prNumber = target.kind === "bound" ? target.prNumber : void 0;
8087
8007
  let requestManifestPath;
8088
8008
  if (manifestCanonicalJson !== void 0) {
8089
- requestManifestPath = join15(runDirectory, "request-manifest.json");
8090
- await writeFile6(requestManifestPath, manifestCanonicalJson, "utf8");
8009
+ requestManifestPath = join14(runDirectory, "request-manifest.json");
8010
+ await writeFile5(requestManifestPath, manifestCanonicalJson, "utf8");
8091
8011
  }
8092
8012
  const admitted = {
8093
8013
  role: "collector",
@@ -8112,7 +8032,7 @@ async function admitCollectorInvocation(options) {
8112
8032
  mediaKind: a.mediaKind
8113
8033
  }))
8114
8034
  };
8115
- const admittedRequestPath = join15(runDirectory, "admitted-request.json");
8035
+ const admittedRequestPath = join14(runDirectory, "admitted-request.json");
8116
8036
  await writeAdmittedRequestPersistence(admittedRequestPath, admitted, {
8117
8037
  sessionDirectory,
8118
8038
  sessionFile
@@ -8210,7 +8130,7 @@ function parseDoctorArgv(args) {
8210
8130
  }
8211
8131
  async function resolveDoctorCaseRunsPath(options) {
8212
8132
  const ledgerHome = resolveActivationLedgerHome(options.home);
8213
- const defaultRuns = join15(
8133
+ const defaultRuns = join14(
8214
8134
  activationBookDirectory(ledgerHome, options.bookKey),
8215
8135
  String(options.issueNumber),
8216
8136
  "runs"
@@ -8341,7 +8261,7 @@ async function admitDoctorInvocation(options) {
8341
8261
  mediaKind: a.mediaKind
8342
8262
  }))
8343
8263
  };
8344
- const admittedRequestPath = join15(runDirectory, "admitted-request.json");
8264
+ const admittedRequestPath = join14(runDirectory, "admitted-request.json");
8345
8265
  await writeAdmittedRequestPersistence(admittedRequestPath, admitted, {
8346
8266
  sessionDirectory,
8347
8267
  sessionFile
@@ -8473,7 +8393,7 @@ async function admitNotaryInvocation(options) {
8473
8393
  ...ticketFields,
8474
8394
  ...options.correlationId === void 0 ? {} : { correlationId: options.correlationId }
8475
8395
  };
8476
- const admittedRequestPath = join15(runDirectory, "admitted-request.json");
8396
+ const admittedRequestPath = join14(runDirectory, "admitted-request.json");
8477
8397
  await writeAdmittedRequestPersistence(admittedRequestPath, admitted, {
8478
8398
  sessionDirectory,
8479
8399
  sessionFile
@@ -8576,7 +8496,7 @@ async function admitGleanerLeftInvocation(options) {
8576
8496
  attachments: [],
8577
8497
  ...options.correlationId === void 0 ? {} : { correlationId: options.correlationId }
8578
8498
  };
8579
- const admittedRequestPath = join15(runDirectory, "admitted-request.json");
8499
+ const admittedRequestPath = join14(runDirectory, "admitted-request.json");
8580
8500
  await writeAdmittedRequestPersistence(admittedRequestPath, admitted, {
8581
8501
  sessionDirectory,
8582
8502
  sessionFile
@@ -8705,7 +8625,7 @@ async function admitReviewerInvocation(options) {
8705
8625
  mediaKind: a.mediaKind
8706
8626
  }))
8707
8627
  };
8708
- const admittedRequestPath = join15(runDirectory, "admitted-request.json");
8628
+ const admittedRequestPath = join14(runDirectory, "admitted-request.json");
8709
8629
  await writeAdmittedRequestPersistence(admittedRequestPath, admitted, {
8710
8630
  sessionDirectory,
8711
8631
  sessionFile
@@ -8850,8 +8770,8 @@ async function admitMergerInvocation(options) {
8850
8770
  resolutionScope: [...derived.resolutionScope],
8851
8771
  authorizedChecks: []
8852
8772
  });
8853
- const mergerInputPath = join15(runDirectory, "merger-input.json");
8854
- await writeFile6(
8773
+ const mergerInputPath = join14(runDirectory, "merger-input.json");
8774
+ await writeFile5(
8855
8775
  mergerInputPath,
8856
8776
  `${JSON.stringify(mergerInput, null, 2)}
8857
8777
  `,
@@ -8881,7 +8801,7 @@ async function admitMergerInvocation(options) {
8881
8801
  mediaKind: a.mediaKind
8882
8802
  }))
8883
8803
  };
8884
- const admittedRequestPath = join15(runDirectory, "admitted-request.json");
8804
+ const admittedRequestPath = join14(runDirectory, "admitted-request.json");
8885
8805
  await writeAdmittedRequestPersistence(admittedRequestPath, admitted, {
8886
8806
  sessionDirectory,
8887
8807
  sessionFile
@@ -9165,15 +9085,15 @@ var init_invocation = __esm({
9165
9085
 
9166
9086
  // src/public-cli/load-production-acp-host.ts
9167
9087
  import { existsSync as existsSync6 } from "node:fs";
9168
- import { join as join16 } from "node:path";
9088
+ import { join as join15 } from "node:path";
9169
9089
  import { pathToFileURL } from "node:url";
9170
9090
  async function loadProductionAcpHostFactory(packageRoot, host) {
9171
9091
  const description = lookupHostDescription(host);
9172
9092
  if (description === void 0) {
9173
9093
  throw new Error(`unregistered host: ${host}`);
9174
9094
  }
9175
- const built = join16(packageRoot, "dist/acp-host/production-host.js");
9176
- const source = join16(packageRoot, "src/acp-host/production-host.ts");
9095
+ const built = join15(packageRoot, "dist/acp-host/production-host.js");
9096
+ const source = join15(packageRoot, "src/acp-host/production-host.ts");
9177
9097
  const target = existsSync6(built) ? built : source;
9178
9098
  const href = pathToFileURL(target).href;
9179
9099
  const mod = await import(href);
@@ -9189,15 +9109,15 @@ var init_load_production_acp_host = __esm({
9189
9109
 
9190
9110
  // src/public-cli/load-production-headless-host.ts
9191
9111
  import { existsSync as existsSync7 } from "node:fs";
9192
- import { join as join17 } from "node:path";
9112
+ import { join as join16 } from "node:path";
9193
9113
  import { pathToFileURL as pathToFileURL2 } from "node:url";
9194
9114
  async function loadProductionHeadlessHostFactory(packageRoot, host) {
9195
9115
  const description = lookupHeadlessHostDescription(host);
9196
9116
  if (description === void 0) {
9197
9117
  throw new Error(`unregistered headless host: ${host}`);
9198
9118
  }
9199
- const built = join17(packageRoot, "dist/headless-host/production-host.js");
9200
- const source = join17(packageRoot, "src/headless-host/production-host.ts");
9119
+ const built = join16(packageRoot, "dist/headless-host/production-host.js");
9120
+ const source = join16(packageRoot, "src/headless-host/production-host.ts");
9201
9121
  const target = existsSync7(built) ? built : source;
9202
9122
  const href = pathToFileURL2(target).href;
9203
9123
  const mod = await import(href);
@@ -9446,8 +9366,8 @@ __export(config_exports, {
9446
9366
  setPersistentSeatHost: () => setPersistentSeatHost,
9447
9367
  validatePublicCliConfigAxes: () => validatePublicCliConfigAxes
9448
9368
  });
9449
- import { mkdir, readFile as readFile13, writeFile as writeFile7 } from "node:fs/promises";
9450
- import { dirname as dirname11, join as join18 } from "node:path";
9369
+ import { mkdir, readFile as readFile12, writeFile as writeFile6 } from "node:fs/promises";
9370
+ import { dirname as dirname10, join as join17 } from "node:path";
9451
9371
  function isGateOfficerSeat(value) {
9452
9372
  return GATE_OFFICER_SEATS.includes(value);
9453
9373
  }
@@ -9455,12 +9375,12 @@ function publicCliConfigPath(home) {
9455
9375
  if (typeof home !== "string" || home.trim() === "") {
9456
9376
  throw new Error("home must be explicitly provided");
9457
9377
  }
9458
- return join18(home, ".ak-roles", "public-cli.json");
9378
+ return join17(home, ".ak-roles", "public-cli.json");
9459
9379
  }
9460
9380
  async function loadPublicCliConfig(home) {
9461
9381
  const path = publicCliConfigPath(home);
9462
9382
  try {
9463
- const raw = await readFile13(path, "utf8");
9383
+ const raw = await readFile12(path, "utf8");
9464
9384
  return parsePublicCliConfig(JSON.parse(raw));
9465
9385
  } catch (error) {
9466
9386
  if (error instanceof Error && "code" in error && error.code === "ENOENT") {
@@ -9471,9 +9391,9 @@ async function loadPublicCliConfig(home) {
9471
9391
  }
9472
9392
  async function savePublicCliConfig(config, home) {
9473
9393
  const path = publicCliConfigPath(home);
9474
- await mkdir(dirname11(path), { recursive: true });
9394
+ await mkdir(dirname10(path), { recursive: true });
9475
9395
  const normalized = parsePublicCliConfig(config);
9476
- await writeFile7(
9396
+ await writeFile6(
9477
9397
  path,
9478
9398
  `${JSON.stringify(serializePublicCliConfig(normalized), null, 2)}
9479
9399
  `,
@@ -9918,7 +9838,7 @@ function credentialProvidersFromAuthData(data) {
9918
9838
  }
9919
9839
  async function loadCredentialProviders(agentDir) {
9920
9840
  try {
9921
- const raw = await readFile13(join18(agentDir, "auth.json"), "utf8");
9841
+ const raw = await readFile12(join17(agentDir, "auth.json"), "utf8");
9922
9842
  return credentialProvidersFromAuthData(JSON.parse(raw));
9923
9843
  } catch (error) {
9924
9844
  if (error instanceof Error && "code" in error && error.code === "ENOENT") {
@@ -9957,15 +9877,15 @@ __export(host_providers_exports, {
9957
9877
  renderHostProvidersTable: () => renderHostProvidersTable
9958
9878
  });
9959
9879
  import { readFileSync as readFileSync2 } from "node:fs";
9960
- import { join as join19 } from "node:path";
9880
+ import { join as join18 } from "node:path";
9961
9881
  function hostProvidersPath(home) {
9962
9882
  if (typeof home !== "string" || home.trim() === "") {
9963
9883
  throw new Error("home must be explicitly provided");
9964
9884
  }
9965
- return join19(home, ".ak-roles", "host-providers.json");
9885
+ return join18(home, ".ak-roles", "host-providers.json");
9966
9886
  }
9967
9887
  function hermesProviderModelsCachePath(home) {
9968
- return join19(home, ".hermes", "provider_models_cache.json");
9888
+ return join18(home, ".hermes", "provider_models_cache.json");
9969
9889
  }
9970
9890
  function parseHostProvidersTable(value) {
9971
9891
  if (value === null || typeof value !== "object" || Array.isArray(value)) {
@@ -10120,12 +10040,12 @@ var init_host_providers = __esm({
10120
10040
  });
10121
10041
 
10122
10042
  // src/ledger-session-read.ts
10123
- import { readFile as readFile14 } from "node:fs/promises";
10043
+ import { readFile as readFile13 } from "node:fs/promises";
10124
10044
  function isRecord5(value) {
10125
10045
  return typeof value === "object" && value !== null && !Array.isArray(value);
10126
10046
  }
10127
10047
  async function readLedgerSessionJsonlLines(path) {
10128
- const text = await readFile14(path, "utf8");
10048
+ const text = await readFile13(path, "utf8");
10129
10049
  const lines = text.split("\n");
10130
10050
  const out = [];
10131
10051
  for (let index = 0; index < lines.length; index += 1) {
@@ -10224,7 +10144,7 @@ var init_ledger_session_read = __esm({
10224
10144
 
10225
10145
  // src/analyst-gate-cycles-read.ts
10226
10146
  import { readdir as readdir5 } from "node:fs/promises";
10227
- import { join as join20 } from "node:path";
10147
+ import { join as join19 } from "node:path";
10228
10148
  function isRecord6(value) {
10229
10149
  return typeof value === "object" && value !== null && !Array.isArray(value);
10230
10150
  }
@@ -10474,7 +10394,7 @@ async function readAnalystGateCyclesFromAuditorRoles(auditorRolesDirectory, opti
10474
10394
  throw error;
10475
10395
  }
10476
10396
  for (const name of names) {
10477
- const path = join20(directory, name);
10397
+ const path = join19(directory, name);
10478
10398
  const fromPointer = name.endsWith(".pointer.json");
10479
10399
  const sessionPath = fromPointer ? await resolveOfficerSessionFromPointerFile(path) : path;
10480
10400
  if (sessionPath === void 0) continue;
@@ -10613,7 +10533,7 @@ var init_audit_escalation = __esm({
10613
10533
  });
10614
10534
 
10615
10535
  // src/run-terminal-artifacts.ts
10616
- import { basename as basename7, dirname as dirname12, join as join21 } from "node:path";
10536
+ import { basename as basename7, dirname as dirname11, join as join20 } from "node:path";
10617
10537
  function runIdFromRunDirectory(runDirectory) {
10618
10538
  const name = basename7(runDirectory);
10619
10539
  const at = name.lastIndexOf("@");
@@ -10628,7 +10548,7 @@ var init_run_terminal_artifacts = __esm({
10628
10548
  });
10629
10549
 
10630
10550
  // src/submission-ledger.ts
10631
- import { join as join22 } from "node:path";
10551
+ import { join as join21 } from "node:path";
10632
10552
  function runIdentity(context) {
10633
10553
  const directory = runDirectoryFromHostContext(context);
10634
10554
  if (directory !== void 0) {
@@ -10650,7 +10570,7 @@ async function submissionRecordFile(cwd, runId, scope) {
10650
10570
  if (sessionParent === void 0) {
10651
10571
  const discoveredRun = await findRunDirectoryById(scope.home, runId);
10652
10572
  if (discoveredRun === void 0) return void 0;
10653
- sessionParent = join22(discoveredRun, "session", "session.jsonl");
10573
+ sessionParent = join21(discoveredRun, "session", "session.jsonl");
10654
10574
  }
10655
10575
  return resolveSitianRecordPathInLedger({
10656
10576
  level: "event",
@@ -10855,13 +10775,13 @@ function createSubmissionLedgerHost(host, outputTools, failInfrastructure2 = (er
10855
10775
  const sessionParentFromContext = (context) => {
10856
10776
  const runDirectory = runDirectoryFromHostContext(context);
10857
10777
  if (runDirectory !== void 0) {
10858
- return join22(runDirectory, "session", "session.jsonl");
10778
+ return join21(runDirectory, "session", "session.jsonl");
10859
10779
  }
10860
10780
  const sessionFile = context.sessionManager.getSessionFile?.();
10861
10781
  if (typeof sessionFile === "string" && sessionFile.length > 0) return sessionFile;
10862
10782
  const sessionDir = context.sessionManager.getSessionDir?.();
10863
10783
  if (typeof sessionDir === "string" && sessionDir.length > 0) {
10864
- return join22(sessionDir, "session.jsonl");
10784
+ return join21(sessionDir, "session.jsonl");
10865
10785
  }
10866
10786
  return void 0;
10867
10787
  };
@@ -11023,23 +10943,23 @@ var init_submission_ledger = __esm({
11023
10943
 
11024
10944
  // src/session-opening-materials.ts
11025
10945
  import { existsSync as existsSync8 } from "node:fs";
11026
- import { readFile as readFile15 } from "node:fs/promises";
11027
- import { dirname as dirname13, join as join23 } from "node:path";
10946
+ import { readFile as readFile14 } from "node:fs/promises";
10947
+ import { dirname as dirname12, join as join22 } from "node:path";
11028
10948
  import { fileURLToPath, pathToFileURL as pathToFileURL3 } from "node:url";
11029
10949
  function resolvePackageRootDir(moduleUrl = import.meta.url) {
11030
- let dir = dirname13(fileURLToPath(moduleUrl));
10950
+ let dir = dirname12(fileURLToPath(moduleUrl));
11031
10951
  for (let i = 0; i < 8; i += 1) {
11032
- if (existsSync8(join23(dir, "package.json")) && existsSync8(join23(dir, "souls"))) {
10952
+ if (existsSync8(join22(dir, "package.json")) && existsSync8(join22(dir, "souls"))) {
11033
10953
  return dir;
11034
10954
  }
11035
- const parent = dirname13(dir);
10955
+ const parent = dirname12(dir);
11036
10956
  if (parent === dir) break;
11037
10957
  dir = parent;
11038
10958
  }
11039
10959
  return fileURLToPath(new URL("..", moduleUrl));
11040
10960
  }
11041
10961
  async function readPackageMaterial(relativePath) {
11042
- return readFile15(fileURLToPath(new URL(relativePath, packageRootUrl)), "utf8");
10962
+ return readFile14(fileURLToPath(new URL(relativePath, packageRootUrl)), "utf8");
11043
10963
  }
11044
10964
  async function joinPackageMaterials(relativePaths) {
11045
10965
  const chunks = [];
@@ -11531,13 +11451,13 @@ var init_reviewer_dispatch = __esm({
11531
11451
  });
11532
11452
 
11533
11453
  // src/public-cli/reviewer-dispatch-rejection.ts
11534
- import { readFile as readFile16, unlink as unlink3 } from "node:fs/promises";
11535
- import { join as join24 } from "node:path";
11454
+ import { readFile as readFile15, unlink as unlink3 } from "node:fs/promises";
11455
+ import { join as join23 } from "node:path";
11536
11456
  function isReviewerPreflightViolation(value) {
11537
11457
  return typeof value === "string" && REVIEWER_PREFLIGHT_VIOLATIONS.includes(value);
11538
11458
  }
11539
11459
  function reviewerDispatchRejectionPath(runDirectory) {
11540
- return join24(runDirectory, REVIEWER_DISPATCH_REJECTION_FILE);
11460
+ return join23(runDirectory, REVIEWER_DISPATCH_REJECTION_FILE);
11541
11461
  }
11542
11462
  async function clearReviewerDispatchRejection(runDirectory) {
11543
11463
  try {
@@ -11552,7 +11472,7 @@ async function clearReviewerDispatchRejection(runDirectory) {
11552
11472
  async function readReviewerDispatchRejection(runDirectory) {
11553
11473
  let raw;
11554
11474
  try {
11555
- raw = await readFile16(reviewerDispatchRejectionPath(runDirectory), "utf8");
11475
+ raw = await readFile15(reviewerDispatchRejectionPath(runDirectory), "utf8");
11556
11476
  } catch (error) {
11557
11477
  if (error instanceof Error && "code" in error && error.code === "ENOENT") {
11558
11478
  return void 0;
@@ -12746,9 +12666,9 @@ var init_collector_ledger = __esm({
12746
12666
  });
12747
12667
 
12748
12668
  // src/engine-detour-usage.ts
12749
- import { randomUUID as randomUUID4 } from "node:crypto";
12669
+ import { randomUUID as randomUUID3 } from "node:crypto";
12750
12670
  import { readFileSync as readFileSync3 } from "node:fs";
12751
- import { dirname as dirname14, join as join25 } from "node:path";
12671
+ import { dirname as dirname13, join as join24 } from "node:path";
12752
12672
  function engineDetourStdoutByteLength(stdout) {
12753
12673
  return Buffer.byteLength(stdout, "utf8");
12754
12674
  }
@@ -12884,7 +12804,7 @@ function projectEngineDetourToolUsageForPublicTerminal(usage, options) {
12884
12804
  function readInvocationRecord(runDirectory) {
12885
12805
  try {
12886
12806
  const raw = JSON.parse(
12887
- readFileSync3(join25(runDirectory, "invocation.json"), "utf8")
12807
+ readFileSync3(join24(runDirectory, "invocation.json"), "utf8")
12888
12808
  );
12889
12809
  return isRecord7(raw) ? raw : void 0;
12890
12810
  } catch (error) {
@@ -12914,15 +12834,15 @@ function withEngineDetourToolUsageFact(outcome, usage) {
12914
12834
  };
12915
12835
  }
12916
12836
  function runDirectoryFromSessionDirectory(sessionDirectory) {
12917
- return dirname14(sessionDirectory);
12837
+ return dirname13(sessionDirectory);
12918
12838
  }
12919
12839
  function sessionFileFromSessionDirectory(sessionDirectory) {
12920
- return join25(sessionDirectory, "session.jsonl");
12840
+ return join24(sessionDirectory, "session.jsonl");
12921
12841
  }
12922
12842
  function mintEngineDetourInvocationScope(input) {
12923
12843
  const engine = input.effectiveEngine?.trim();
12924
12844
  if (engine === void 0 || engine.length === 0) return void 0;
12925
- return randomUUID4();
12845
+ return randomUUID3();
12926
12846
  }
12927
12847
  function withEngineDetourInvocationScope(request, invocationScopeId) {
12928
12848
  if (invocationScopeId === void 0 || invocationScopeId.length === 0) {
@@ -13014,8 +12934,8 @@ var init_dossier_resolution = __esm({
13014
12934
 
13015
12935
  // src/package-resources/method-skill.ts
13016
12936
  import { createHash as createHash6 } from "node:crypto";
13017
- import { readFile as readFile17, realpath as realpath7 } from "node:fs/promises";
13018
- import { join as join26 } from "node:path";
12937
+ import { readFile as readFile16, realpath as realpath7 } from "node:fs/promises";
12938
+ import { join as join25 } from "node:path";
13019
12939
  function gitBlobOid(bytes) {
13020
12940
  const body = typeof bytes === "string" ? Buffer.from(bytes, "utf8") : Buffer.from(bytes);
13021
12941
  const header = Buffer.from(`blob ${body.byteLength}\0`, "utf8");
@@ -13032,10 +12952,10 @@ function packagedMethodSkillRelativeDirectory(name) {
13032
12952
  return `${METHOD_SKILL_RELATIVE_ROOT}/${name}`;
13033
12953
  }
13034
12954
  function resolvePackagedMethodSkillRoot(packageRoot, name) {
13035
- return join26(packageRoot, packagedMethodSkillRelativeDirectory(name));
12955
+ return join25(packageRoot, packagedMethodSkillRelativeDirectory(name));
13036
12956
  }
13037
12957
  function resolvePackagedMethodSkillPath(packageRoot, name) {
13038
- return join26(resolvePackagedMethodSkillRoot(packageRoot, name), "SKILL.md");
12958
+ return join25(resolvePackagedMethodSkillRoot(packageRoot, name), "SKILL.md");
13039
12959
  }
13040
12960
  function isRecord9(value) {
13041
12961
  return typeof value === "object" && value !== null && !Array.isArray(value);
@@ -13129,11 +13049,11 @@ function parseProvenance(raw, expectedName) {
13129
13049
  }
13130
13050
  async function loadPackagedMethodSkillMaterial(packageRoot, name) {
13131
13051
  const rootDirectory = resolvePackagedMethodSkillRoot(packageRoot, name);
13132
- const skillPathConfigured = join26(rootDirectory, "SKILL.md");
13133
- const provenancePath = join26(rootDirectory, "provenance.json");
13052
+ const skillPathConfigured = join25(rootDirectory, "SKILL.md");
13053
+ const provenancePath = join25(rootDirectory, "provenance.json");
13134
13054
  let provenanceRaw;
13135
13055
  try {
13136
- provenanceRaw = await readFile17(provenancePath, "utf8");
13056
+ provenanceRaw = await readFile16(provenancePath, "utf8");
13137
13057
  } catch (error) {
13138
13058
  throw new PackagedMethodSkillUnavailableError(name, provenancePath, error);
13139
13059
  }
@@ -13147,10 +13067,10 @@ async function loadPackagedMethodSkillMaterial(packageRoot, name) {
13147
13067
  }
13148
13068
  const provenance = parseProvenance(provenanceJson, name);
13149
13069
  for (const [rel, expected] of Object.entries(provenance.files)) {
13150
- const absolute = join26(rootDirectory, rel);
13070
+ const absolute = join25(rootDirectory, rel);
13151
13071
  let bytes;
13152
13072
  try {
13153
- bytes = await readFile17(absolute);
13073
+ bytes = await readFile16(absolute);
13154
13074
  } catch (error) {
13155
13075
  throw new PackagedMethodSkillUnavailableError(name, absolute, error);
13156
13076
  }
@@ -13166,7 +13086,7 @@ async function loadPackagedMethodSkillMaterial(packageRoot, name) {
13166
13086
  let raw;
13167
13087
  try {
13168
13088
  skillPath = await realpath7(skillPathConfigured);
13169
- raw = await readFile17(skillPath, "utf8");
13089
+ raw = await readFile16(skillPath, "utf8");
13170
13090
  } catch (error) {
13171
13091
  throw new PackagedMethodSkillUnavailableError(name, skillPathConfigured, error);
13172
13092
  }
@@ -13755,16 +13675,16 @@ __export(settlement_exports, {
13755
13675
  trySettleReviewerTerminalResult: () => trySettleReviewerTerminalResult,
13756
13676
  withSubmissions: () => withSubmissions
13757
13677
  });
13758
- import { randomUUID as randomUUID5 } from "node:crypto";
13759
- import { appendFile as appendFile2, readFile as readFile18, readdir as readdir6, writeFile as writeFile8 } from "node:fs/promises";
13760
- import { dirname as dirname15, join as join27 } from "node:path";
13678
+ import { randomUUID as randomUUID4 } from "node:crypto";
13679
+ import { appendFile as appendFile2, readFile as readFile17, readdir as readdir6, writeFile as writeFile7 } from "node:fs/promises";
13680
+ import { dirname as dirname14, join as join26 } from "node:path";
13761
13681
  function sealedLedgerHome(admitted) {
13762
13682
  return homeFromRunDirectory(admitted.runDirectory);
13763
13683
  }
13764
13684
  function ledgerReadScope(admitted, scope) {
13765
13685
  return {
13766
13686
  home: sealedLedgerHome(admitted),
13767
- sessionParent: join27(admitted.runDirectory, "session", "session.jsonl"),
13687
+ sessionParent: join26(admitted.runDirectory, "session", "session.jsonl"),
13768
13688
  ...scope?.courtAttemptId === void 0 || scope.courtAttemptId.length === 0 ? {} : { attemptId: scope.courtAttemptId }
13769
13689
  };
13770
13690
  }
@@ -13900,7 +13820,7 @@ function presentControlledFailure(failure2, io) {
13900
13820
  }
13901
13821
  async function inspectJudgeSession(sessionFile) {
13902
13822
  try {
13903
- await readFile18(sessionFile, "utf8");
13823
+ await readFile17(sessionFile, "utf8");
13904
13824
  return { state: "present" };
13905
13825
  } catch (error) {
13906
13826
  if (isMissingPathError3(error)) return { state: "missing" };
@@ -14132,7 +14052,7 @@ function sessionReadFailure(error, fallbackMessage) {
14132
14052
  return failed;
14133
14053
  }
14134
14054
  async function readBoundSessionEntries(sessionFile) {
14135
- const text = await readFile18(sessionFile, "utf8");
14055
+ const text = await readFile17(sessionFile, "utf8");
14136
14056
  const entries = [];
14137
14057
  for (const line2 of text.trim().split("\n").filter(Boolean)) {
14138
14058
  try {
@@ -14193,7 +14113,7 @@ async function readSitianRetainedAuditorProviderStop(sessionFile) {
14193
14113
  kind: "auditor",
14194
14114
  sessionParent: sessionFile,
14195
14115
  // Path is driven by sessionParent when under ledger home; cwd is a fallback only.
14196
- cwd: dirname15(sessionFile)
14116
+ cwd: dirname14(sessionFile)
14197
14117
  });
14198
14118
  const { records } = await readSitianRecords(recordFile);
14199
14119
  for (let i = records.length - 1; i >= 0; i -= 1) {
@@ -14219,7 +14139,7 @@ async function readSessionProviderStop(sessionFile) {
14219
14139
  }
14220
14140
  }
14221
14141
  async function readBoundEvidenceChildKnownFailure(sessionFile) {
14222
- const childDirectory = join27(dirname15(sessionFile), "evidence-children");
14142
+ const childDirectory = join26(dirname14(sessionFile), "evidence-children");
14223
14143
  let names;
14224
14144
  try {
14225
14145
  names = await readdir6(childDirectory);
@@ -14230,7 +14150,7 @@ async function readBoundEvidenceChildKnownFailure(sessionFile) {
14230
14150
  for (const file of names.filter((name) => name.endsWith(".jsonl")).sort().reverse()) {
14231
14151
  let entries;
14232
14152
  try {
14233
- entries = await readBoundSessionEntries(join27(childDirectory, file));
14153
+ entries = await readBoundSessionEntries(join26(childDirectory, file));
14234
14154
  } catch (error) {
14235
14155
  throw sessionReadFailure(error, "failed to read discovered evidence-child session");
14236
14156
  }
@@ -14285,7 +14205,7 @@ async function loadBoundAuditorVolumes(sessionFile) {
14285
14205
  latestParentUserIndex = i;
14286
14206
  break;
14287
14207
  }
14288
- const childDirectories = [join27(dirname15(sessionFile), "auditor-roles")];
14208
+ const childDirectories = [join26(dirname14(sessionFile), "auditor-roles")];
14289
14209
  const valid = [];
14290
14210
  let sawAnyDirectory = false;
14291
14211
  for (const childDirectory of childDirectories) {
@@ -14300,7 +14220,7 @@ async function loadBoundAuditorVolumes(sessionFile) {
14300
14220
  for (const file of names.filter((name) => name.endsWith(".jsonl")).sort().reverse()) {
14301
14221
  let entries;
14302
14222
  try {
14303
- entries = await readBoundSessionEntries(join27(childDirectory, file));
14223
+ entries = await readBoundSessionEntries(join26(childDirectory, file));
14304
14224
  } catch (error) {
14305
14225
  throw sessionReadFailure(error, "failed to read discovered auditor session");
14306
14226
  }
@@ -14719,7 +14639,7 @@ async function appendRunAttemptHistory(source, outcome) {
14719
14639
  type: "custom",
14720
14640
  customType: ATTEMPT_HISTORY_ENTRY_TYPE,
14721
14641
  data: attemptData,
14722
- id: randomUUID5(),
14642
+ id: randomUUID4(),
14723
14643
  parentId,
14724
14644
  timestamp: timestamp2
14725
14645
  })}
@@ -14825,8 +14745,8 @@ function projectTerminalGateFact(rounds) {
14825
14745
  };
14826
14746
  }
14827
14747
  async function extractGateFactFromSessionDirectory(sessionDirectory, options = {}) {
14828
- const directories = [join27(sessionDirectory, "auditor-roles")];
14829
- const parentSessionFile = options.parentSessionFile ?? join27(sessionDirectory, "session.jsonl");
14748
+ const directories = [join26(sessionDirectory, "auditor-roles")];
14749
+ const parentSessionFile = options.parentSessionFile ?? join26(sessionDirectory, "session.jsonl");
14830
14750
  const rounds = await readAnalystGateCyclesFromAuditorRoles(directories, {
14831
14751
  parentSessionFile
14832
14752
  });
@@ -14956,9 +14876,9 @@ async function extractNavigatorFactFromAdmittedSession(sessionFile) {
14956
14876
  async function publishJudgeArtifacts(admitted, roleOutcome, coordinates) {
14957
14877
  await appendRunAttemptHistory({ role: admitted.role, runId: admitted.runId, sessionFile: coordinates.sessionFile }, roleOutcome);
14958
14878
  const artifactsDir = await ensureRunArtifactsDir(admitted.runDirectory);
14959
- const reportPath = join27(artifactsDir, "report.json");
14960
- const evidencePath = join27(artifactsDir, "evidence.json");
14961
- await writeFile8(
14879
+ const reportPath = join26(artifactsDir, "report.json");
14880
+ const evidencePath = join26(artifactsDir, "evidence.json");
14881
+ await writeFile7(
14962
14882
  reportPath,
14963
14883
  `${JSON.stringify(
14964
14884
  {
@@ -14972,7 +14892,7 @@ async function publishJudgeArtifacts(admitted, roleOutcome, coordinates) {
14972
14892
  `,
14973
14893
  "utf8"
14974
14894
  );
14975
- await writeFile8(
14895
+ await writeFile7(
14976
14896
  evidencePath,
14977
14897
  `${JSON.stringify(
14978
14898
  {
@@ -15001,9 +14921,9 @@ async function publishJudgeArtifacts(admitted, roleOutcome, coordinates) {
15001
14921
  async function publishCoderArtifacts(admitted, roleOutcome, coordinates, options = {}) {
15002
14922
  await appendRunAttemptHistory({ role: admitted.role, runId: admitted.runId, sessionFile: coordinates.sessionFile }, roleOutcome);
15003
14923
  const artifactsDir = await ensureRunArtifactsDir(admitted.runDirectory);
15004
- const reportPath = join27(artifactsDir, "report.json");
15005
- const evidencePath = join27(artifactsDir, "evidence.json");
15006
- await writeFile8(
14924
+ const reportPath = join26(artifactsDir, "report.json");
14925
+ const evidencePath = join26(artifactsDir, "evidence.json");
14926
+ await writeFile7(
15007
14927
  reportPath,
15008
14928
  `${JSON.stringify(
15009
14929
  {
@@ -15018,7 +14938,7 @@ async function publishCoderArtifacts(admitted, roleOutcome, coordinates, options
15018
14938
  `,
15019
14939
  "utf8"
15020
14940
  );
15021
- await writeFile8(
14941
+ await writeFile7(
15022
14942
  evidencePath,
15023
14943
  `${JSON.stringify(
15024
14944
  {
@@ -15159,9 +15079,9 @@ function extractFixerMethodInvocations(entries, options) {
15159
15079
  async function publishFixerArtifacts(admitted, roleOutcome, coordinates, options) {
15160
15080
  await appendRunAttemptHistory({ role: admitted.role, runId: admitted.runId, sessionFile: coordinates.sessionFile }, roleOutcome);
15161
15081
  const artifactsDir = await ensureRunArtifactsDir(admitted.runDirectory);
15162
- const reportPath = join27(artifactsDir, "report.json");
15163
- const evidencePath = join27(artifactsDir, "evidence.json");
15164
- await writeFile8(
15082
+ const reportPath = join26(artifactsDir, "report.json");
15083
+ const evidencePath = join26(artifactsDir, "evidence.json");
15084
+ await writeFile7(
15165
15085
  reportPath,
15166
15086
  `${JSON.stringify(
15167
15087
  {
@@ -15176,7 +15096,7 @@ async function publishFixerArtifacts(admitted, roleOutcome, coordinates, options
15176
15096
  `,
15177
15097
  "utf8"
15178
15098
  );
15179
- await writeFile8(
15099
+ await writeFile7(
15180
15100
  evidencePath,
15181
15101
  `${JSON.stringify(
15182
15102
  {
@@ -15257,9 +15177,9 @@ async function settleFixerTerminalResult(admitted, authority, options, scope) {
15257
15177
  async function publishCollectorArtifacts(admitted, roleOutcome, coordinates) {
15258
15178
  await appendRunAttemptHistory({ role: admitted.role, runId: admitted.runId, sessionFile: coordinates.sessionFile }, roleOutcome);
15259
15179
  const artifactsDir = await ensureRunArtifactsDir(admitted.runDirectory);
15260
- const reportPath = join27(artifactsDir, "report.json");
15261
- const evidencePath = join27(artifactsDir, "evidence.json");
15262
- await writeFile8(
15180
+ const reportPath = join26(artifactsDir, "report.json");
15181
+ const evidencePath = join26(artifactsDir, "evidence.json");
15182
+ await writeFile7(
15263
15183
  reportPath,
15264
15184
  `${JSON.stringify(
15265
15185
  {
@@ -15273,7 +15193,7 @@ async function publishCollectorArtifacts(admitted, roleOutcome, coordinates) {
15273
15193
  `,
15274
15194
  "utf8"
15275
15195
  );
15276
- await writeFile8(
15196
+ await writeFile7(
15277
15197
  evidencePath,
15278
15198
  `${JSON.stringify(
15279
15199
  {
@@ -15390,9 +15310,9 @@ function extractDoctorCandidateAuditNoReceiptFact(entries) {
15390
15310
  async function publishDoctorArtifacts(admitted, roleOutcome, coordinates, options = {}) {
15391
15311
  await appendRunAttemptHistory({ role: admitted.role, runId: admitted.runId, sessionFile: coordinates.sessionFile }, roleOutcome);
15392
15312
  const artifactsDir = await ensureRunArtifactsDir(admitted.runDirectory);
15393
- const reportPath = join27(artifactsDir, "report.json");
15394
- const evidencePath = join27(artifactsDir, "evidence.json");
15395
- await writeFile8(
15313
+ const reportPath = join26(artifactsDir, "report.json");
15314
+ const evidencePath = join26(artifactsDir, "evidence.json");
15315
+ await writeFile7(
15396
15316
  reportPath,
15397
15317
  `${JSON.stringify(
15398
15318
  {
@@ -15408,7 +15328,7 @@ async function publishDoctorArtifacts(admitted, roleOutcome, coordinates, option
15408
15328
  `,
15409
15329
  "utf8"
15410
15330
  );
15411
- await writeFile8(
15331
+ await writeFile7(
15412
15332
  evidencePath,
15413
15333
  `${JSON.stringify(
15414
15334
  {
@@ -15686,9 +15606,9 @@ function extractReviewerMethodInvocations(entries, options) {
15686
15606
  async function publishReviewerArtifacts(admitted, roleOutcome, coordinates, options) {
15687
15607
  await appendRunAttemptHistory({ role: admitted.role, runId: admitted.runId, sessionFile: coordinates.sessionFile }, roleOutcome);
15688
15608
  const artifactsDir = await ensureRunArtifactsDir(admitted.runDirectory);
15689
- const reportPath = join27(artifactsDir, "report.json");
15690
- const evidencePath = join27(artifactsDir, "evidence.json");
15691
- await writeFile8(
15609
+ const reportPath = join26(artifactsDir, "report.json");
15610
+ const evidencePath = join26(artifactsDir, "evidence.json");
15611
+ await writeFile7(
15692
15612
  reportPath,
15693
15613
  `${JSON.stringify(
15694
15614
  {
@@ -15702,7 +15622,7 @@ async function publishReviewerArtifacts(admitted, roleOutcome, coordinates, opti
15702
15622
  `,
15703
15623
  "utf8"
15704
15624
  );
15705
- await writeFile8(
15625
+ await writeFile7(
15706
15626
  evidencePath,
15707
15627
  `${JSON.stringify(
15708
15628
  {
@@ -15801,9 +15721,9 @@ function extractMergerMethodInvocations(entries, options) {
15801
15721
  async function publishMergerArtifacts(admitted, roleOutcome, coordinates, options) {
15802
15722
  await appendRunAttemptHistory({ role: admitted.role, runId: admitted.runId, sessionFile: coordinates.sessionFile }, roleOutcome);
15803
15723
  const artifactsDir = await ensureRunArtifactsDir(admitted.runDirectory);
15804
- const reportPath = join27(artifactsDir, "report.json");
15805
- const evidencePath = join27(artifactsDir, "evidence.json");
15806
- await writeFile8(
15724
+ const reportPath = join26(artifactsDir, "report.json");
15725
+ const evidencePath = join26(artifactsDir, "evidence.json");
15726
+ await writeFile7(
15807
15727
  reportPath,
15808
15728
  `${JSON.stringify(
15809
15729
  {
@@ -15817,7 +15737,7 @@ async function publishMergerArtifacts(admitted, roleOutcome, coordinates, option
15817
15737
  `,
15818
15738
  "utf8"
15819
15739
  );
15820
- await writeFile8(
15740
+ await writeFile7(
15821
15741
  evidencePath,
15822
15742
  `${JSON.stringify(
15823
15743
  {
@@ -15936,7 +15856,7 @@ function publicationAttemptFromError(path, error) {
15936
15856
  }
15937
15857
  function uniqueFailureFallbackDirs(runDirectory, baseDir) {
15938
15858
  const dirs = [];
15939
- for (const dir of [baseDir, runDirectory, dirname15(runDirectory)]) {
15859
+ for (const dir of [baseDir, runDirectory, dirname14(runDirectory)]) {
15940
15860
  if (!dirs.includes(dir)) dirs.push(dir);
15941
15861
  }
15942
15862
  return dirs;
@@ -15958,13 +15878,13 @@ async function writeFailureJsonRetainingCause(preferredCandidates, uniqueFallbac
15958
15878
  const candidates = [
15959
15879
  ...preferredCandidates,
15960
15880
  // One unique name per fallback dir — collisions on fixed names cannot exhaust this.
15961
- ...uniqueFallbackDirs.map((dir) => join27(dir, `${stem}.${randomUUID5()}.json`))
15881
+ ...uniqueFallbackDirs.map((dir) => join26(dir, `${stem}.${randomUUID4()}.json`))
15962
15882
  ];
15963
15883
  for (let i = 0; i < candidates.length; i += 1) {
15964
15884
  const path = candidates[i];
15965
15885
  const payload = issues.length === 0 ? basePayload : { ...basePayload, publicationIssues: issues };
15966
15886
  try {
15967
- await writeFile8(
15887
+ await writeFile7(
15968
15888
  path,
15969
15889
  `${JSON.stringify(payload, null, 2)}
15970
15890
  `,
@@ -16009,20 +15929,20 @@ async function publishFailureArtifacts(admitted, failure2, authority) {
16009
15929
  baseDir
16010
15930
  );
16011
15931
  const errorCandidates = underArtifacts ? [
16012
- join27(baseDir, "error.json"),
16013
- join27(baseDir, "error.settlement.json"),
16014
- join27(admitted.runDirectory, "error.settlement.json")
15932
+ join26(baseDir, "error.json"),
15933
+ join26(baseDir, "error.settlement.json"),
15934
+ join26(admitted.runDirectory, "error.settlement.json")
16015
15935
  ] : [
16016
- join27(baseDir, "error.settlement.json"),
16017
- join27(baseDir, "error.json")
15936
+ join26(baseDir, "error.settlement.json"),
15937
+ join26(baseDir, "error.json")
16018
15938
  ];
16019
15939
  const evidenceCandidates = underArtifacts ? [
16020
- join27(baseDir, "evidence.json"),
16021
- join27(baseDir, "evidence.settlement.json"),
16022
- join27(admitted.runDirectory, "evidence.settlement.json")
15940
+ join26(baseDir, "evidence.json"),
15941
+ join26(baseDir, "evidence.settlement.json"),
15942
+ join26(admitted.runDirectory, "evidence.settlement.json")
16023
15943
  ] : [
16024
- join27(baseDir, "evidence.settlement.json"),
16025
- join27(baseDir, "evidence.json")
15944
+ join26(baseDir, "evidence.settlement.json"),
15945
+ join26(baseDir, "evidence.json")
16026
15946
  ];
16027
15947
  const errorPayloadBase = {
16028
15948
  kind: "error",
@@ -16310,17 +16230,17 @@ var init_seat_ticket_binding = __esm({
16310
16230
  });
16311
16231
 
16312
16232
  // src/session-identity.ts
16313
- import { mkdir as mkdir3, readFile as readFile19, rename as rename3, writeFile as writeFile9 } from "node:fs/promises";
16314
- import { dirname as dirname16, join as join28 } from "node:path";
16233
+ import { mkdir as mkdir3, readFile as readFile18, rename as rename2, writeFile as writeFile8 } from "node:fs/promises";
16234
+ import { dirname as dirname15, join as join27 } from "node:path";
16315
16235
  function createSessionIdentityAuthority(authority, sessionBindingFile) {
16316
- const bindingPath = (principal) => join28(authority.decode(principal).sessionDirectory, sessionBindingFile);
16236
+ const bindingPath = (principal) => join27(authority.decode(principal).sessionDirectory, sessionBindingFile);
16317
16237
  return {
16318
16238
  resolveSessionFile(principal) {
16319
16239
  return authority.decode(principal).sessionFile;
16320
16240
  },
16321
16241
  async load(principal) {
16322
16242
  try {
16323
- const value = JSON.parse(await readFile19(bindingPath(principal), "utf8"));
16243
+ const value = JSON.parse(await readFile18(bindingPath(principal), "utf8"));
16324
16244
  if (typeof value !== "object" || value === null || typeof value.sessionId !== "string") {
16325
16245
  throw new Error("durable session binding is invalid");
16326
16246
  }
@@ -16332,11 +16252,11 @@ function createSessionIdentityAuthority(authority, sessionBindingFile) {
16332
16252
  },
16333
16253
  async bind(principal, sessionId) {
16334
16254
  const target = bindingPath(principal);
16335
- await mkdir3(dirname16(target), { recursive: true });
16255
+ await mkdir3(dirname15(target), { recursive: true });
16336
16256
  const temporary = `${target}.${process.pid}.tmp`;
16337
- await writeFile9(temporary, `${JSON.stringify({ sessionId })}
16257
+ await writeFile8(temporary, `${JSON.stringify({ sessionId })}
16338
16258
  `, { encoding: "utf8", mode: 384 });
16339
- await rename3(temporary, target);
16259
+ await rename2(temporary, target);
16340
16260
  }
16341
16261
  };
16342
16262
  }
@@ -16424,6 +16344,23 @@ function fromQueueEvent(row) {
16424
16344
  const id = nativeEventId(row);
16425
16345
  return [{ speaker: "owner", text: content, ...id === void 0 ? {} : { id } }];
16426
16346
  }
16347
+ function hasFixedOpenTagPrefix(content, tag) {
16348
+ if (!content.startsWith(tag)) return false;
16349
+ const next = content.charAt(tag.length);
16350
+ return next === "" || next === ">" || next === " " || next === " " || next === "\n" || next === "\r";
16351
+ }
16352
+ function isFixedNonOwnerEnqueueShape(content) {
16353
+ return hasFixedOpenTagPrefix(content, TASK_NOTIFICATION_OPEN_TAG);
16354
+ }
16355
+ function materializationOriginKind(row) {
16356
+ if (!isRecord12(row.origin)) return void 0;
16357
+ const kind = row.origin.kind;
16358
+ return typeof kind === "string" && kind !== "" ? kind : void 0;
16359
+ }
16360
+ function isNonOwnerOriginKind(kind) {
16361
+ if (kind === void 0) return false;
16362
+ return kind !== "human";
16363
+ }
16427
16364
  function fromMessageEvent(row) {
16428
16365
  const message = messageBody(row);
16429
16366
  if (message === void 0) return [];
@@ -16440,78 +16377,45 @@ function fromMessageEvent(row) {
16440
16377
  const id = nativeEventId(row);
16441
16378
  return [{ speaker, text, ...id === void 0 ? {} : { id } }];
16442
16379
  }
16443
- function isOwnerDialogueMessage(row) {
16444
- if (row.type === "response_item" || row.type === "event_msg") return false;
16445
- return fromMessageEvent(row).some((event) => event.speaker === "owner");
16446
- }
16447
- function isRunnerMessage(row) {
16448
- const message = messageBody(row);
16449
- return message !== void 0 && message.role === "assistant";
16450
- }
16451
- function ownerMessagesMaterializingQueue(rows) {
16452
- const skip = /* @__PURE__ */ new Set();
16453
- const retainedByEnqueue = [];
16454
- let pendingSkips = 0;
16455
- for (let index = 0; index < rows.length; index += 1) {
16456
- const row = rows[index];
16457
- if (row === void 0) continue;
16458
- if (row.type === "queue-operation") {
16459
- if (row.operation === "enqueue") {
16460
- retainedByEnqueue.push(fromQueueEvent(row).length > 0);
16461
- continue;
16462
- }
16463
- if (row.operation === "dequeue" || row.operation === "remove") {
16464
- const retained = retainedByEnqueue.shift();
16465
- if (row.operation === "dequeue" && retained === true) {
16466
- pendingSkips += 1;
16467
- }
16468
- continue;
16469
- }
16470
- }
16471
- if (isRunnerMessage(row)) {
16472
- pendingSkips = 0;
16473
- continue;
16474
- }
16475
- if (pendingSkips > 0 && isOwnerDialogueMessage(row)) {
16476
- skip.add(index);
16477
- pendingSkips -= 1;
16478
- }
16479
- }
16480
- return skip;
16481
- }
16482
16380
  function adaptSessionDialogue(rows) {
16483
- const skipOwner = ownerMessagesMaterializingQueue(rows);
16484
- return rows.map((row, index) => {
16381
+ return rows.map((row) => {
16485
16382
  if (row === void 0) return [];
16383
+ const originKind = materializationOriginKind(row);
16384
+ if (isNonOwnerOriginKind(originKind)) return [];
16385
+ if (row.type === "queue-operation" && row.operation === "enqueue" && typeof row.content === "string" && isFixedNonOwnerEnqueueShape(row.content)) {
16386
+ return [];
16387
+ }
16486
16388
  const queued = fromQueueEvent(row);
16487
16389
  if (queued.length > 0) return queued;
16488
- if (skipOwner.has(index)) return [];
16489
16390
  return fromMessageEvent(row);
16490
16391
  });
16491
16392
  }
16492
- var SPEAKER_TEXT_PART_TYPES;
16393
+ var SPEAKER_TEXT_PART_TYPES, TASK_NOTIFICATION_OPEN_TAG;
16493
16394
  var init_session_dialogue = __esm({
16494
16395
  "src/session-dialogue.ts"() {
16495
16396
  "use strict";
16496
16397
  SPEAKER_TEXT_PART_TYPES = /* @__PURE__ */ new Set(["text", "input_text", "output_text"]);
16398
+ TASK_NOTIFICATION_OPEN_TAG = "<task-notification";
16497
16399
  }
16498
16400
  });
16499
16401
 
16500
16402
  // src/ticket-provenance.ts
16501
- import { basename as basename8, dirname as dirname17, join as join29, resolve as resolve12 } from "node:path";
16403
+ import { createHash as createHash7 } from "node:crypto";
16404
+ import { readFile as readFile19 } from "node:fs/promises";
16405
+ import { basename as basename8, dirname as dirname16, join as join28, resolve as resolve12 } from "node:path";
16502
16406
  function dialogueSessionSourceRoots(home) {
16503
16407
  const machineHome = typeof home === "string" && home.trim() !== "" ? home : packageMachineHome();
16504
16408
  return [
16505
- join29(machineHome, ".claude", "projects"),
16506
- join29(machineHome, ".codex", "sessions"),
16507
- join29(machineHome, ".pi", "agent", "sessions")
16409
+ join28(machineHome, ".claude", "projects"),
16410
+ join28(machineHome, ".codex", "sessions"),
16411
+ join28(machineHome, ".pi", "agent", "sessions")
16508
16412
  ];
16509
16413
  }
16510
16414
  function isLedgerRoleSessionFile(absolute, home) {
16511
16415
  const machineHome = typeof home === "string" && home.trim() !== "" ? home : packageMachineHome();
16512
16416
  const ledgerHome = resolveActivationLedgerHome(machineHome);
16513
16417
  if (!physicallyContainedIn(ledgerHome, absolute)) return false;
16514
- return basename8(absolute) === "session.jsonl" && basename8(dirname17(absolute)) === "session";
16418
+ return basename8(absolute) === "session.jsonl" && basename8(dirname16(absolute)) === "session";
16515
16419
  }
16516
16420
  function assertDialogueSessionSourcePath(path, home) {
16517
16421
  const absolute = resolve12(path);
@@ -16541,18 +16445,46 @@ function ticketProvenanceRecordInput(ticketNumber, cwd, home) {
16541
16445
  };
16542
16446
  }
16543
16447
  function resolveTicketProvenanceVolume(ticketNumber, cwd, home) {
16544
- return resolveSitianVolume(ticketProvenanceRecordInput(ticketNumber, cwd, home));
16545
- }
16546
- async function readTicketProvenance(ticketNumber, cwd, home) {
16547
- const { recordFile, text } = await readSitianVolumeText(
16448
+ const path = resolveSitianRecordPath(
16548
16449
  ticketProvenanceRecordInput(ticketNumber, cwd, home)
16549
16450
  );
16550
- if (text === void 0) {
16551
- return { header: void 0, lines: [], recordFile };
16451
+ return { recordFile: path.recordFile, volumeDir: path.sessionDir };
16452
+ }
16453
+ function projectTicketProvenanceCommit(value) {
16454
+ if (typeof value !== "object" || value === null || Array.isArray(value)) return void 0;
16455
+ const record4 = value;
16456
+ if (record4.kind !== TICKET_PROVENANCE_KIND || typeof record4.timestamp !== "string") {
16457
+ return void 0;
16458
+ }
16459
+ const payload = record4.payload;
16460
+ if (typeof payload !== "object" || payload === null || Array.isArray(payload)) return void 0;
16461
+ const body = payload;
16462
+ if (body.type !== "ticket-provenance-append") return void 0;
16463
+ const sessions = projectTicketProvenanceSessions(body.sessions);
16464
+ if (sessions === void 0 || !Array.isArray(body.lines)) return void 0;
16465
+ const lines = [];
16466
+ for (const raw of body.lines) {
16467
+ const line2 = projectTicketProvenanceLine(raw);
16468
+ if (line2 === void 0) return void 0;
16469
+ lines.push(line2);
16470
+ }
16471
+ return { timestamp: record4.timestamp, sessions, lines };
16472
+ }
16473
+ async function readTicketProvenance(ticketNumber, cwd, home) {
16474
+ const { recordFile } = resolveTicketProvenanceVolume(ticketNumber, cwd, home);
16475
+ let text;
16476
+ try {
16477
+ text = await readFile19(recordFile, "utf8");
16478
+ } catch (error) {
16479
+ if (error.code === "ENOENT") {
16480
+ return { header: void 0, lines: [], unprojectedRaw: [], recordFile };
16481
+ }
16482
+ throw error;
16552
16483
  }
16553
16484
  const physical = text.split("\n");
16554
16485
  let header;
16555
16486
  const lines = [];
16487
+ const unprojectedRaw = [];
16556
16488
  let sawFirst = false;
16557
16489
  for (let index = 0; index < physical.length; index += 1) {
16558
16490
  const raw = physical[index];
@@ -16561,6 +16493,7 @@ async function readTicketProvenance(ticketNumber, cwd, home) {
16561
16493
  try {
16562
16494
  parsed = JSON.parse(raw);
16563
16495
  } catch {
16496
+ unprojectedRaw.push(raw);
16564
16497
  continue;
16565
16498
  }
16566
16499
  if (!sawFirst) {
@@ -16569,9 +16502,35 @@ async function readTicketProvenance(ticketNumber, cwd, home) {
16569
16502
  if (header !== void 0) continue;
16570
16503
  }
16571
16504
  const line2 = projectTicketProvenanceLine(parsed);
16572
- if (line2 !== void 0) lines.push(line2);
16505
+ if (line2 !== void 0) {
16506
+ lines.push(line2);
16507
+ continue;
16508
+ }
16509
+ const commit = projectTicketProvenanceCommit(parsed);
16510
+ if (commit !== void 0) {
16511
+ const merged = mergeSessionBounds(header?.sessions, commit.sessions);
16512
+ const remapped = commit.lines.map((entry) => ({
16513
+ ...entry,
16514
+ s: merged.incomingIndexes[entry.s] ?? entry.s
16515
+ }));
16516
+ const now = commit.timestamp;
16517
+ header = {
16518
+ repo: header?.repo ?? resolveBookKeyFromGit(cwd),
16519
+ ticket: ticketNumber,
16520
+ createdAt: header?.createdAt ?? now,
16521
+ updatedAt: now,
16522
+ sessions: merged.sessions
16523
+ };
16524
+ const carried = lines.map((entry) => ({
16525
+ ...entry,
16526
+ s: merged.priorIndexes[entry.s] ?? entry.s
16527
+ }));
16528
+ lines.splice(0, lines.length, ...mergeFreshIntoCarried(carried, remapped));
16529
+ continue;
16530
+ }
16531
+ unprojectedRaw.push(raw);
16573
16532
  }
16574
- return { header, lines, recordFile };
16533
+ return { header, lines, unprojectedRaw, recordFile };
16575
16534
  }
16576
16535
  function resolveBoundIndex(bound, sessionLines) {
16577
16536
  if (typeof bound.id === "string" && bound.id !== "") {
@@ -16593,6 +16552,104 @@ function resolveBoundIndex(bound, sessionLines) {
16593
16552
  function amendmentKey(s, line2) {
16594
16553
  return `${s}:${line2}`;
16595
16554
  }
16555
+ function rangeDeclarationKey(range) {
16556
+ return JSON.stringify({
16557
+ from: range.from,
16558
+ to: range.to
16559
+ });
16560
+ }
16561
+ function mergeSessionBounds(prior, incoming) {
16562
+ const merged = [];
16563
+ const indexByIdentity = /* @__PURE__ */ new Map();
16564
+ const absorb = (sessions) => {
16565
+ const indexes = [];
16566
+ for (const session of sessions) {
16567
+ const identity = physicalPathIdentity(session.path);
16568
+ let targetIndex = indexByIdentity.get(identity);
16569
+ if (targetIndex === void 0) {
16570
+ targetIndex = merged.length;
16571
+ indexByIdentity.set(identity, targetIndex);
16572
+ merged.push({ path: session.path, ranges: [] });
16573
+ }
16574
+ indexes.push(targetIndex);
16575
+ const target = merged[targetIndex];
16576
+ const seen = new Set(target.ranges.map(rangeDeclarationKey));
16577
+ for (const range of session.ranges) {
16578
+ const key = rangeDeclarationKey(range);
16579
+ if (seen.has(key)) continue;
16580
+ seen.add(key);
16581
+ target.ranges.push({ from: { ...range.from }, to: { ...range.to } });
16582
+ }
16583
+ }
16584
+ return indexes;
16585
+ };
16586
+ const priorIndexes = absorb(prior ?? []);
16587
+ const incomingIndexes = absorb(incoming);
16588
+ return { sessions: merged, priorIndexes, incomingIndexes };
16589
+ }
16590
+ function undeclaredSessionRanges(prior, merged) {
16591
+ const priorKeys = /* @__PURE__ */ new Map();
16592
+ for (const session of prior ?? []) {
16593
+ const identity = physicalPathIdentity(session.path);
16594
+ let keys = priorKeys.get(identity);
16595
+ if (keys === void 0) {
16596
+ keys = /* @__PURE__ */ new Set();
16597
+ priorKeys.set(identity, keys);
16598
+ }
16599
+ for (const range of session.ranges) keys.add(rangeDeclarationKey(range));
16600
+ }
16601
+ const out = [];
16602
+ for (let s = 0; s < merged.length; s += 1) {
16603
+ const session = merged[s];
16604
+ const declared = priorKeys.get(physicalPathIdentity(session.path)) ?? /* @__PURE__ */ new Set();
16605
+ const fresh = session.ranges.filter(
16606
+ (range) => !declared.has(rangeDeclarationKey(range))
16607
+ );
16608
+ if (fresh.length === 0) continue;
16609
+ out.push({
16610
+ s,
16611
+ session: {
16612
+ path: session.path,
16613
+ ranges: fresh.map((range) => ({
16614
+ from: { ...range.from },
16615
+ to: { ...range.to }
16616
+ }))
16617
+ }
16618
+ });
16619
+ }
16620
+ return out;
16621
+ }
16622
+ function compareLinePosition(left, right) {
16623
+ if (left.s !== right.s) return left.s - right.s;
16624
+ const leftLine = left.line ?? Number.MAX_SAFE_INTEGER;
16625
+ const rightLine = right.line ?? Number.MAX_SAFE_INTEGER;
16626
+ return leftLine - rightLine;
16627
+ }
16628
+ function mergeFreshIntoCarried(carried, fresh) {
16629
+ const seenIds = /* @__PURE__ */ new Set();
16630
+ const seenPositions = /* @__PURE__ */ new Set();
16631
+ const out = [];
16632
+ for (const line2 of carried) {
16633
+ if (line2.id !== void 0) seenIds.add(line2.id);
16634
+ if (line2.line !== void 0)
16635
+ seenPositions.add(amendmentKey(line2.s, line2.line));
16636
+ out.push(line2);
16637
+ }
16638
+ for (const line2 of fresh) {
16639
+ if (line2.id !== void 0) {
16640
+ if (seenIds.has(line2.id)) continue;
16641
+ seenIds.add(line2.id);
16642
+ }
16643
+ if (line2.line !== void 0) {
16644
+ const position = amendmentKey(line2.s, line2.line);
16645
+ if (seenPositions.has(position)) continue;
16646
+ seenPositions.add(position);
16647
+ }
16648
+ out.push(line2);
16649
+ }
16650
+ out.sort(compareLinePosition);
16651
+ return out;
16652
+ }
16596
16653
  function normalizeResolvedRanges(ranges, sessionLines, sessionPath) {
16597
16654
  const resolved = [];
16598
16655
  for (const range of ranges) {
@@ -16687,84 +16744,101 @@ async function projectSessionRanges(input) {
16687
16744
  return { lines, unparsable };
16688
16745
  }
16689
16746
  async function reprojectTicketProvenance(input) {
16690
- const recordInput = ticketProvenanceRecordInput(
16691
- input.ticketNumber,
16692
- input.cwd,
16693
- input.home
16694
- );
16695
16747
  const prior = await readTicketProvenance(input.ticketNumber, input.cwd, input.home);
16696
- const priorRaw = await readSitianVolumeText(recordInput);
16697
- const priorNonEmpty = priorRaw.text !== void 0 && priorRaw.text.trim() !== "";
16698
- const amendments = input.amendments ?? [];
16699
- let sessions = input.sessions;
16700
- if (sessions.length === 0) {
16701
- if (amendments.length > 0) {
16702
- const priorSessions = prior.header?.sessions;
16703
- if (priorSessions === void 0 || priorSessions.length === 0) {
16704
- throw new TicketProvenanceInputError(
16705
- "amendments require sessions bounds (none submitted and no prior header sessions)"
16706
- );
16707
- }
16708
- sessions = priorSessions;
16709
- } else if (priorNonEmpty) {
16710
- const now2 = (/* @__PURE__ */ new Date()).toISOString();
16711
- const header2 = prior.header ?? {
16748
+ if (input.sessions.length === 0) {
16749
+ const now2 = (/* @__PURE__ */ new Date()).toISOString();
16750
+ return {
16751
+ recordFile: prior.recordFile,
16752
+ header: prior.header ?? {
16712
16753
  repo: resolveBookKeyFromGit(input.cwd),
16713
16754
  ticket: input.ticketNumber,
16714
16755
  createdAt: now2,
16715
16756
  updatedAt: now2,
16716
16757
  sessions: []
16717
- };
16718
- return {
16719
- recordFile: prior.recordFile,
16720
- header: header2,
16721
- lines: prior.lines,
16722
- unparsable: []
16723
- };
16724
- }
16758
+ },
16759
+ lines: prior.lines,
16760
+ unparsable: []
16761
+ };
16762
+ }
16763
+ const merged = mergeSessionBounds(prior.header?.sessions, input.sessions);
16764
+ const deltas = undeclaredSessionRanges(prior.header?.sessions, merged.sessions);
16765
+ if (deltas.length === 0) {
16766
+ const now2 = (/* @__PURE__ */ new Date()).toISOString();
16767
+ return {
16768
+ recordFile: prior.recordFile,
16769
+ header: prior.header ?? {
16770
+ repo: resolveBookKeyFromGit(input.cwd),
16771
+ ticket: input.ticketNumber,
16772
+ createdAt: now2,
16773
+ updatedAt: now2,
16774
+ sessions: merged.sessions
16775
+ },
16776
+ lines: prior.lines,
16777
+ unparsable: []
16778
+ };
16725
16779
  }
16726
16780
  const amendmentsByKey = /* @__PURE__ */ new Map();
16727
- for (const amendment of amendments) {
16728
- amendmentsByKey.set(amendmentKey(amendment.s, amendment.line), amendment);
16781
+ for (const amendment of input.amendments ?? []) {
16782
+ const cumulativeIndex = merged.incomingIndexes[amendment.s];
16783
+ if (cumulativeIndex === void 0) continue;
16784
+ amendmentsByKey.set(amendmentKey(cumulativeIndex, amendment.line), {
16785
+ ...amendment,
16786
+ s: cumulativeIndex
16787
+ });
16729
16788
  }
16730
- const lines = [];
16789
+ const seenIds = new Set(
16790
+ prior.lines.flatMap((line2) => line2.id === void 0 ? [] : [line2.id])
16791
+ );
16792
+ const fresh = [];
16731
16793
  const unparsable = [];
16732
- const seenIds = /* @__PURE__ */ new Set();
16733
- for (let s = 0; s < sessions.length; s += 1) {
16794
+ for (const delta of deltas) {
16734
16795
  const projected = await projectSessionRanges({
16735
- s,
16736
- session: sessions[s],
16796
+ s: delta.s,
16797
+ session: delta.session,
16737
16798
  amendmentsByKey,
16738
16799
  seenIds,
16739
16800
  ...input.home === void 0 ? {} : { home: input.home }
16740
16801
  });
16741
- lines.push(...projected.lines);
16802
+ fresh.push(...projected.lines);
16742
16803
  unparsable.push(...projected.unparsable);
16743
16804
  }
16805
+ const lines = mergeFreshIntoCarried(prior.lines, fresh);
16744
16806
  const now = (/* @__PURE__ */ new Date()).toISOString();
16745
16807
  const header = {
16746
- repo: resolveBookKeyFromGit(input.cwd),
16808
+ repo: prior.header?.repo ?? resolveBookKeyFromGit(input.cwd),
16747
16809
  ticket: input.ticketNumber,
16748
16810
  createdAt: prior.header?.createdAt ?? now,
16749
16811
  updatedAt: now,
16750
- sessions
16812
+ sessions: merged.sessions
16751
16813
  };
16752
16814
  if (unparsable.length > 0) {
16753
- return {
16754
- recordFile: prior.recordFile,
16755
- header,
16756
- lines,
16757
- unparsable
16758
- };
16815
+ return { recordFile: prior.recordFile, header, lines, unparsable };
16759
16816
  }
16760
- const body = `${[JSON.stringify(header), ...lines.map((line2) => JSON.stringify(line2))].join("\n")}
16761
- `;
16762
- const volume = await rewriteSitianVolume({ ...recordInput, body });
16817
+ const identityMaterial = JSON.stringify({
16818
+ ticket: input.ticketNumber,
16819
+ deltas: deltas.map(({ s, session }) => ({
16820
+ s,
16821
+ path: physicalPathIdentity(session.path),
16822
+ ranges: session.ranges
16823
+ })),
16824
+ lines: fresh
16825
+ });
16826
+ const identity = `ticket-provenance:${createHash7("sha256").update(identityMaterial).digest("hex")}`;
16827
+ const pointer = appendSitianRecord({
16828
+ ...ticketProvenanceRecordInput(input.ticketNumber, input.cwd, input.home),
16829
+ identity,
16830
+ payload: {
16831
+ type: "ticket-provenance-append",
16832
+ sessions: merged.sessions,
16833
+ lines: fresh
16834
+ }
16835
+ });
16836
+ const folded = await readTicketProvenance(input.ticketNumber, input.cwd, input.home);
16763
16837
  return {
16764
- recordFile: volume.recordFile,
16765
- header,
16766
- lines,
16767
- unparsable
16838
+ recordFile: pointer.recordFile,
16839
+ header: folded.header ?? header,
16840
+ lines: folded.lines,
16841
+ unparsable: []
16768
16842
  };
16769
16843
  }
16770
16844
  var TicketProvenanceInputError;
@@ -16798,9 +16872,9 @@ __export(case_dossier_delivery_exports, {
16798
16872
  loadCaseDossierReadingMaterial: () => loadCaseDossierReadingMaterial,
16799
16873
  projectCaseDossierPointerSection: () => projectCaseDossierPointerSection
16800
16874
  });
16801
- import { mkdtemp as mkdtemp2, readFile as readFile20, rm as rm3, writeFile as writeFile10 } from "node:fs/promises";
16875
+ import { mkdtemp as mkdtemp2, readFile as readFile20, rm as rm2, writeFile as writeFile9 } from "node:fs/promises";
16802
16876
  import { tmpdir as tmpdir2 } from "node:os";
16803
- import { join as join30 } from "node:path";
16877
+ import { join as join29 } from "node:path";
16804
16878
  function describeDossierFile(path) {
16805
16879
  return path;
16806
16880
  }
@@ -16825,10 +16899,10 @@ async function deliverCaseDossierAsAttachment(input) {
16825
16899
  home: input.home
16826
16900
  });
16827
16901
  if (section === void 0) return void 0;
16828
- const stagingDir = await mkdtemp2(join30(tmpdir2(), "ak-case-dossier-"));
16902
+ const stagingDir = await mkdtemp2(join29(tmpdir2(), "ak-case-dossier-"));
16829
16903
  try {
16830
- const stagingPath = join30(stagingDir, CASE_DOSSIER_ATTACH_FILE);
16831
- await writeFile10(stagingPath, `${section}
16904
+ const stagingPath = join29(stagingDir, CASE_DOSSIER_ATTACH_FILE);
16905
+ await writeFile9(stagingPath, `${section}
16832
16906
  `, "utf8");
16833
16907
  return await freezeAttachmentsIntoRun(
16834
16908
  [stagingPath],
@@ -16836,11 +16910,11 @@ async function deliverCaseDossierAsAttachment(input) {
16836
16910
  CASE_DOSSIER_ATTACH_KEY
16837
16911
  );
16838
16912
  } finally {
16839
- await rm3(stagingDir, { recursive: true, force: true });
16913
+ await rm2(stagingDir, { recursive: true, force: true });
16840
16914
  }
16841
16915
  }
16842
16916
  async function loadCaseDossierReadingMaterial(runDirectory) {
16843
- const frozenPath = join30(
16917
+ const frozenPath = join29(
16844
16918
  runDirectory,
16845
16919
  "attachments",
16846
16920
  CASE_DOSSIER_ATTACH_KEY,
@@ -16870,7 +16944,7 @@ var init_case_dossier_delivery = __esm({
16870
16944
 
16871
16945
  // src/host-transition-prior-native.ts
16872
16946
  import { access as access4, readdir as readdir7 } from "node:fs/promises";
16873
- import { dirname as dirname18, join as join31 } from "node:path";
16947
+ import { dirname as dirname17, join as join30 } from "node:path";
16874
16948
  function isEnoent3(error) {
16875
16949
  return typeof error === "object" && error !== null && error.code === "ENOENT";
16876
16950
  }
@@ -16884,7 +16958,7 @@ async function listPiNativeRecordPaths(sessionFile) {
16884
16958
  }
16885
16959
  }
16886
16960
  async function listSitianRecordPaths(sessionParent) {
16887
- const sessionRoot = dirname18(sessionParent);
16961
+ const sessionRoot = dirname17(sessionParent);
16888
16962
  let entries;
16889
16963
  try {
16890
16964
  entries = await readdir7(sessionRoot, { withFileTypes: true });
@@ -16895,7 +16969,7 @@ async function listSitianRecordPaths(sessionParent) {
16895
16969
  const recordPaths = [];
16896
16970
  for (const entry of entries) {
16897
16971
  if (!entry.isDirectory()) continue;
16898
- const recordFile = join31(sessionRoot, entry.name, "records.jsonl");
16972
+ const recordFile = join30(sessionRoot, entry.name, "records.jsonl");
16899
16973
  try {
16900
16974
  await access4(recordFile);
16901
16975
  recordPaths.push(recordFile);
@@ -16963,9 +17037,9 @@ var init_public_run_credentials = __esm({
16963
17037
 
16964
17038
  // src/public-cli/auto-resume.ts
16965
17039
  import { constants as fsConstants2 } from "node:fs";
16966
- import { randomUUID as randomUUID6 } from "node:crypto";
17040
+ import { randomUUID as randomUUID5 } from "node:crypto";
16967
17041
  import { lstat as lstat6, mkdir as mkdir4, open as open2 } from "node:fs/promises";
16968
- import { join as join32 } from "node:path";
17042
+ import { join as join31 } from "node:path";
16969
17043
  async function persistReturnedRunState(admitted, authority, options) {
16970
17044
  if (options?.lawful === true) {
16971
17045
  await markRunTerminal(admitted.runDirectory);
@@ -17080,7 +17154,7 @@ function jsonSafeReplacer() {
17080
17154
  };
17081
17155
  }
17082
17156
  async function writeHardenedArtifactFile(artifactsDir, namePrefix, payload) {
17083
- const filePath = join32(artifactsDir, `${namePrefix}-${randomUUID6()}.json`);
17157
+ const filePath = join31(artifactsDir, `${namePrefix}-${randomUUID5()}.json`);
17084
17158
  const body = `${JSON.stringify(payload, jsonSafeReplacer(), 2)}
17085
17159
  `;
17086
17160
  const noFollowFlag = typeof fsConstants2.O_NOFOLLOW === "number" ? fsConstants2.O_NOFOLLOW : 0;
@@ -17351,9 +17425,9 @@ var init_auto_resume = __esm({
17351
17425
  });
17352
17426
 
17353
17427
  // src/public-cli/post-admission.ts
17354
- import { randomUUID as randomUUID7 } from "node:crypto";
17355
- import { writeFile as writeFile11 } from "node:fs/promises";
17356
- import { isAbsolute as isAbsolute8, join as join33, resolve as resolve13 } from "node:path";
17428
+ import { randomUUID as randomUUID6 } from "node:crypto";
17429
+ import { writeFile as writeFile10 } from "node:fs/promises";
17430
+ import { isAbsolute as isAbsolute8, join as join32, resolve as resolve13 } from "node:path";
17357
17431
  function describeCaughtError(error) {
17358
17432
  if (error instanceof Error) {
17359
17433
  const code = error.code;
@@ -17397,8 +17471,8 @@ async function recordBestEffortPostDispatchDiagnostic(admitted, env, diagnostic,
17397
17471
  } catch (appendError) {
17398
17472
  try {
17399
17473
  const artifactsDir = await ensureRealArtifactsDirectory(admitted.runDirectory);
17400
- await writeFile11(
17401
- join33(artifactsDir, `post-admission-diagnostic-${randomUUID7()}.json`),
17474
+ await writeFile10(
17475
+ join32(artifactsDir, `post-admission-diagnostic-${randomUUID6()}.json`),
17402
17476
  `${JSON.stringify({ version: 1, ...payload }, null, 2)}
17403
17477
  `,
17404
17478
  { encoding: "utf8", flag: "wx" }
@@ -17673,8 +17747,8 @@ async function dispatchPostAdmissionTurn(input) {
17673
17747
  }
17674
17748
  let stderrLogWriteFailure;
17675
17749
  try {
17676
- await writeFile11(
17677
- join33(admitted.runDirectory, "stderr.log"),
17750
+ await writeFile10(
17751
+ join32(admitted.runDirectory, "stderr.log"),
17678
17752
  result.stderr,
17679
17753
  "utf8"
17680
17754
  );
@@ -17906,7 +17980,7 @@ function resumeTurnRequestProjectionOptions(admitted, request, env, summonsPrepa
17906
17980
  kind: "resume",
17907
17981
  prompt
17908
17982
  },
17909
- ...request.message === void 0 ? {} : { courtAttemptId: randomUUID7() },
17983
+ ...request.message === void 0 ? {} : { courtAttemptId: randomUUID6() },
17910
17984
  ...env.stationChild === void 0 ? {} : { stationChild: env.stationChild }
17911
17985
  };
17912
17986
  }
@@ -17924,7 +17998,7 @@ async function dispatchAfterWriterLease(input) {
17924
17998
  }
17925
17999
  function isAlreadyFrozenSummonsAttachment(runDirectory, attachmentPath) {
17926
18000
  const absolute = isAbsolute8(attachmentPath) ? attachmentPath : resolve13(attachmentPath);
17927
- return pathContainedIn(join33(runDirectory, "attachments"), absolute);
18001
+ return pathContainedIn(join32(runDirectory, "attachments"), absolute);
17928
18002
  }
17929
18003
  async function prepareSummonsResumeMaterials(runDirectory, summons) {
17930
18004
  if (summons === void 0) return void 0;
@@ -18003,7 +18077,7 @@ async function runPostAdmissionSeatResume(input) {
18003
18077
  }
18004
18078
  let turnRequest = await input.buildTurnRequest(admittedForBuild, request);
18005
18079
  if (openCourtAttemptId !== void 0 || request.summons !== void 0 || request.message !== void 0) {
18006
- const courtAttemptId = openCourtAttemptId ?? (turnRequest.courtAttemptId !== void 0 && turnRequest.courtAttemptId.length > 0 ? turnRequest.courtAttemptId : randomUUID7());
18080
+ const courtAttemptId = openCourtAttemptId ?? (turnRequest.courtAttemptId !== void 0 && turnRequest.courtAttemptId.length > 0 ? turnRequest.courtAttemptId : randomUUID6());
18007
18081
  turnRequest = { ...turnRequest, courtAttemptId };
18008
18082
  if (openCourtAttemptId === void 0) {
18009
18083
  const court = {
@@ -19291,7 +19365,7 @@ __export(public_role_summons_exports, {
19291
19365
  summonPublicRole: () => summonPublicRole
19292
19366
  });
19293
19367
  import { existsSync as existsSync10 } from "node:fs";
19294
- import { join as join34 } from "node:path";
19368
+ import { join as join33 } from "node:path";
19295
19369
  function createCapturingIo() {
19296
19370
  const chunks = [];
19297
19371
  return {
@@ -19314,7 +19388,7 @@ function parentDir(path) {
19314
19388
  function walkPackageRoot(start) {
19315
19389
  let dir = start;
19316
19390
  for (let i = 0; i < 12; i += 1) {
19317
- if (existsSync10(join34(dir, "package.json")) && existsSync10(join34(dir, "souls"))) {
19391
+ if (existsSync10(join33(dir, "package.json")) && existsSync10(join33(dir, "souls"))) {
19318
19392
  return dir;
19319
19393
  }
19320
19394
  const parent = parentDir(dir);
@@ -19425,7 +19499,7 @@ async function createSummonEnv(options, afterHost) {
19425
19499
  async function summonPublicRole(options) {
19426
19500
  const packageRoot = resolveSummonsPackageRoot(options.packageRoot);
19427
19501
  const home = await resolveSummonHome(options);
19428
- const agentDir = options.agentDir ?? process.env.PI_CODING_AGENT_DIR ?? join34(home, ".pi", "agent");
19502
+ const agentDir = options.agentDir ?? process.env.PI_CODING_AGENT_DIR ?? join33(home, ".pi", "agent");
19429
19503
  const {
19430
19504
  loadCredentialProviders: loadCredentialProviders2,
19431
19505
  loadPublicCliConfig: loadPublicCliConfig2,
@@ -19815,7 +19889,7 @@ __export(session_assistant_usage_exports, {
19815
19889
  sessionFileFromPublicSummon: () => sessionFileFromPublicSummon,
19816
19890
  usageFromPublicSummon: () => usageFromPublicSummon
19817
19891
  });
19818
- import { join as join35 } from "node:path";
19892
+ import { join as join34 } from "node:path";
19819
19893
  async function readAssistantUsageFromSessionFile(sessionFile) {
19820
19894
  const { readFile: readFile25 } = await import("node:fs/promises");
19821
19895
  let text;
@@ -19885,7 +19959,7 @@ async function readAssistantUsageFromSessionFile(sessionFile) {
19885
19959
  }
19886
19960
  function sessionFileFromPublicSummon(summoned) {
19887
19961
  if (typeof summoned.runDirectory === "string" && summoned.runDirectory.trim() !== "") {
19888
- return join35(summoned.runDirectory, "session", "session.jsonl");
19962
+ return join34(summoned.runDirectory, "session", "session.jsonl");
19889
19963
  }
19890
19964
  const fromArtifacts = summoned.terminal?.artifacts?.map((a) => a.path).find((p) => typeof p === "string" && p.endsWith("session.jsonl"));
19891
19965
  if (fromArtifacts !== void 0) return fromArtifacts;
@@ -19894,7 +19968,7 @@ function sessionFileFromPublicSummon(summoned) {
19894
19968
  const facts = outcome.decisiveFacts;
19895
19969
  const pointer = facts?.runPointer;
19896
19970
  if (typeof pointer === "string" && pointer.trim() !== "") {
19897
- return join35(pointer, "session", "session.jsonl");
19971
+ return join34(pointer, "session", "session.jsonl");
19898
19972
  }
19899
19973
  return void 0;
19900
19974
  }
@@ -20073,8 +20147,8 @@ var init_doctor_auditor = __esm({
20073
20147
  });
20074
20148
 
20075
20149
  // src/archivist-record-topology.ts
20076
- import { createHash as createHash7 } from "node:crypto";
20077
- import { join as join36 } from "node:path";
20150
+ import { createHash as createHash8 } from "node:crypto";
20151
+ import { join as join35 } from "node:path";
20078
20152
  function resolveNavigatorWorkSubjectPlacement(input) {
20079
20153
  let ledgerHome;
20080
20154
  if (input.parentSessionFile !== void 0 && input.parentSessionFile.length > 0) {
@@ -20084,10 +20158,10 @@ function resolveNavigatorWorkSubjectPlacement(input) {
20084
20158
  }
20085
20159
  }
20086
20160
  ledgerHome ??= resolveActivationLedgerHome(input.home);
20087
- const digest = createHash7("sha256").update(input.subject).digest("hex").slice(0, 32);
20161
+ const digest = createHash8("sha256").update(input.subject).digest("hex").slice(0, 32);
20088
20162
  return {
20089
20163
  ledgerHome,
20090
- sessionDir: join36(
20164
+ sessionDir: join35(
20091
20165
  activationBookDirectory(ledgerHome, resolveBookKeyFromGit(input.cwd)),
20092
20166
  NAVIGATOR_RECORD_KIND,
20093
20167
  digest
@@ -20127,11 +20201,11 @@ import {
20127
20201
  statSync as statSync3,
20128
20202
  writeFileSync as writeFileSync2
20129
20203
  } from "node:fs";
20130
- import { dirname as dirname19, resolve as resolve14, join as join37 } from "node:path";
20204
+ import { dirname as dirname18, resolve as resolve14, join as join36 } from "node:path";
20131
20205
  import { StringDecoder } from "node:string_decoder";
20132
20206
  import { SessionManager } from "@earendil-works/pi-coding-agent";
20133
20207
  function readCurrentSession(sessionDir) {
20134
- const ledger = join37(sessionDir, CURRENT_SESSION_LEDGER);
20208
+ const ledger = join36(sessionDir, CURRENT_SESSION_LEDGER);
20135
20209
  try {
20136
20210
  const value = JSON.parse(readFileSync4(ledger, "utf8"));
20137
20211
  if (typeof value !== "object" || value === null || typeof value.sessionFile !== "string" || value.sessionFile.length === 0) {
@@ -20146,7 +20220,7 @@ function readCurrentSession(sessionDir) {
20146
20220
  }
20147
20221
  }
20148
20222
  function writeCurrentSession(sessionDir, sessionFile) {
20149
- const ledger = join37(sessionDir, CURRENT_SESSION_LEDGER);
20223
+ const ledger = join36(sessionDir, CURRENT_SESSION_LEDGER);
20150
20224
  try {
20151
20225
  writeFileSync2(ledger, `${JSON.stringify({ sessionFile })}
20152
20226
  `, { flag: "wx" });
@@ -20162,7 +20236,7 @@ function isCurrentSessionClaimRace(error) {
20162
20236
  return errnoCode(error.cause) === "EEXIST";
20163
20237
  }
20164
20238
  function currentSessionLedgerPath(sessionDir) {
20165
- return join37(sessionDir, CURRENT_SESSION_LEDGER);
20239
+ return join36(sessionDir, CURRENT_SESSION_LEDGER);
20166
20240
  }
20167
20241
  function readBoundedSessionHeader(filePath) {
20168
20242
  const fd = openSync(filePath, "r");
@@ -20249,7 +20323,7 @@ function mostRecentNavigatorSessionFile(sessionDir, cwd) {
20249
20323
  const matched = [];
20250
20324
  for (const name of names) {
20251
20325
  if (!name.endsWith(".jsonl")) continue;
20252
- const filePath = join37(absoluteSessionDir, name);
20326
+ const filePath = join36(absoluteSessionDir, name);
20253
20327
  let st;
20254
20328
  try {
20255
20329
  st = statSync3(filePath);
@@ -20361,7 +20435,7 @@ function createRecordSessionOpen(options) {
20361
20435
  if (!physicallyContainedIn(ledgerHome, parentResolved)) {
20362
20436
  throw new Error("Durable record ownership requires a parent session inside the ledger home");
20363
20437
  }
20364
- sessionDir = join37(dirname19(parentResolved), options.kind);
20438
+ sessionDir = join36(dirname18(parentResolved), options.kind);
20365
20439
  parentSession = parentFile;
20366
20440
  mayResumeSameNest = options.kind === WORKER_SUBMISSION_GATE_KIND;
20367
20441
  }
@@ -20410,7 +20484,7 @@ function createRecordSession(options) {
20410
20484
  return createRecordSessionOpen(options).session;
20411
20485
  }
20412
20486
  function bookDirectOfficerRunPointer(options) {
20413
- const nest = join37(dirname19(options.parentSessionFile), "auditor-roles");
20487
+ const nest = join36(dirname18(options.parentSessionFile), "auditor-roles");
20414
20488
  mkdirSync2(nest, { recursive: true });
20415
20489
  const pointer = {
20416
20490
  version: 1,
@@ -20420,7 +20494,7 @@ function bookDirectOfficerRunPointer(options) {
20420
20494
  ...options.runDirectory !== void 0 && options.runDirectory.trim() !== "" ? { runDirectory: options.runDirectory } : {}
20421
20495
  };
20422
20496
  writeFileSync2(
20423
- join37(nest, `${options.officer}.pointer.json`),
20497
+ join36(nest, `${options.officer}.pointer.json`),
20424
20498
  `${JSON.stringify(pointer)}
20425
20499
  `,
20426
20500
  "utf8"
@@ -20520,7 +20594,7 @@ init_doctor_auditor();
20520
20594
  init_doctor_evidence();
20521
20595
 
20522
20596
  // src/navigator-attendance.ts
20523
- import { createHash as createHash8 } from "node:crypto";
20597
+ import { createHash as createHash9 } from "node:crypto";
20524
20598
  init_navigator_invocation_identity();
20525
20599
  init_packaged_role_registry();
20526
20600
  init_activation_ledger_topology();
@@ -20973,7 +21047,7 @@ function navigatorSubjectKey(subjectRoot, subject, provenance = "role_input") {
20973
21047
  if (provenance === "placeholder") return subjectRoot;
20974
21048
  const normalized = subject.trim().replace(/\s+/g, " ");
20975
21049
  if (normalized === "") return subjectRoot;
20976
- return `${subjectRoot}#${createHash8("sha256").update(normalized).digest("hex").slice(0, 32)}`;
21050
+ return `${subjectRoot}#${createHash9("sha256").update(normalized).digest("hex").slice(0, 32)}`;
20977
21051
  }
20978
21052
  function navigatorSubjectKeyForInput(subjectRoot, reference, cwd = process.cwd()) {
20979
21053
  if (issueRoot(subjectRoot) !== void 0 || !subjectRoot.includes("/.ak/work/")) return subjectRoot;
@@ -21583,7 +21657,7 @@ async function loadNavigatorWorkContext(options) {
21583
21657
  init_notary_source_run();
21584
21658
 
21585
21659
  // src/package-resources/method-skill-binding.ts
21586
- import { dirname as dirname21 } from "node:path";
21660
+ import { dirname as dirname20 } from "node:path";
21587
21661
  init_method_skill();
21588
21662
  async function loadPackagedCanonicalSkillBinding(packageRoot, name) {
21589
21663
  const material = await loadPackagedMethodSkillMaterial(packageRoot, name);
@@ -21591,7 +21665,7 @@ async function loadPackagedCanonicalSkillBinding(packageRoot, name) {
21591
21665
  const snapshot = Object.freeze({
21592
21666
  raw: material.raw,
21593
21667
  path: material.skillPath,
21594
- baseDir: dirname21(material.skillPath),
21668
+ baseDir: dirname20(material.skillPath),
21595
21669
  body: material.body,
21596
21670
  snapshotIdentity: Object.freeze({ text: material.raw })
21597
21671
  });
@@ -21667,7 +21741,7 @@ import {
21667
21741
  openSync as openSync2,
21668
21742
  writeSync
21669
21743
  } from "node:fs";
21670
- import { dirname as dirname22, isAbsolute as isAbsolute10, resolve as resolve18 } from "node:path";
21744
+ import { dirname as dirname21, isAbsolute as isAbsolute10, resolve as resolve18 } from "node:path";
21671
21745
 
21672
21746
  // src/activation-ledger-session.ts
21673
21747
  init_activation_ledger_topology();
@@ -21816,7 +21890,7 @@ function appendActivationLedgerLine(ledgerPath, line2, options) {
21816
21890
  }
21817
21891
  const resolvedLedger = resolve18(ledgerPath);
21818
21892
  const resolvedHome = resolve18(options.ledgerHome);
21819
- const parent = dirname22(resolvedLedger);
21893
+ const parent = dirname21(resolvedLedger);
21820
21894
  ensureRealDirectoryTree(resolvedHome, parent);
21821
21895
  assertLedgerFileInsideHome(resolvedLedger, resolvedHome);
21822
21896
  if (typeof constants2.O_NOFOLLOW !== "number") {
@@ -22180,11 +22254,28 @@ init_collector_evidence();
22180
22254
  init_collector_github();
22181
22255
 
22182
22256
  // src/collector-handbook.ts
22183
- init_atomic_write();
22184
- init_activation_ledger_topology();
22185
22257
  import { readFile as readFile22 } from "node:fs/promises";
22186
22258
  import { join as join39, sep as sep5 } from "node:path";
22187
22259
 
22260
+ // src/atomic-write.ts
22261
+ import { randomUUID as randomUUID7 } from "node:crypto";
22262
+ import { rename as rename3, rm as rm3, writeFile as writeFile11 } from "node:fs/promises";
22263
+ import { dirname as dirname22, join as join38 } from "node:path";
22264
+ async function writeFileAtomically(destination, contents) {
22265
+ const parent = dirname22(destination);
22266
+ const temporary = join38(parent, `.atomic-write-${randomUUID7()}.tmp`);
22267
+ try {
22268
+ await writeFile11(temporary, contents);
22269
+ await rename3(temporary, destination);
22270
+ } catch (error) {
22271
+ await rm3(temporary, { force: true }).catch(() => void 0);
22272
+ throw error;
22273
+ }
22274
+ }
22275
+
22276
+ // src/collector-handbook.ts
22277
+ init_activation_ledger_topology();
22278
+
22188
22279
  // src/collector-tool-schemas.ts
22189
22280
  init_open_tool_schema();
22190
22281
  init_terminating_infrastructure();