@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.
@@ -2823,85 +2823,6 @@ var init_sitian_reader = __esm({
2823
2823
  }
2824
2824
  });
2825
2825
 
2826
- // src/atomic-write.ts
2827
- import { randomUUID as randomUUID2 } from "node:crypto";
2828
- import { rename, rm as rm2, writeFile as writeFile2 } from "node:fs/promises";
2829
- import { dirname as dirname6, join as join11 } from "node:path";
2830
- async function writeFileAtomically(destination, contents) {
2831
- const parent = dirname6(destination);
2832
- const temporary = join11(parent, `.atomic-write-${randomUUID2()}.tmp`);
2833
- try {
2834
- await writeFile2(temporary, contents);
2835
- await rename(temporary, destination);
2836
- } catch (error) {
2837
- await rm2(temporary, { force: true }).catch(() => void 0);
2838
- throw error;
2839
- }
2840
- }
2841
- var init_atomic_write = __esm({
2842
- "src/atomic-write.ts"() {
2843
- "use strict";
2844
- }
2845
- });
2846
-
2847
- // src/sitian-volume.ts
2848
- import { appendFileSync as appendFileSync2 } from "node:fs";
2849
- import { readFile as readFile3 } from "node:fs/promises";
2850
- function resolveSitianVolume(input) {
2851
- const path = resolveSitianRecordPath(input);
2852
- return { recordFile: path.recordFile, volumeDir: path.sessionDir };
2853
- }
2854
- function ensureSitianVolume(input) {
2855
- try {
2856
- const { sessionDir, recordFile, ledgerHome } = resolveSitianRecordPath(input);
2857
- ensureRealDirectoryTree(ledgerHome, sessionDir);
2858
- appendFileSync2(recordFile, "", "utf8");
2859
- return { recordFile, volumeDir: sessionDir };
2860
- } catch (error) {
2861
- if (error instanceof SitianInfrastructureError) throw error;
2862
- throw new SitianInfrastructureError(
2863
- `Sitian volume ensure failure: ${errorText(error)}`,
2864
- { cause: error }
2865
- );
2866
- }
2867
- }
2868
- async function readSitianVolumeText(input) {
2869
- const { recordFile } = resolveSitianVolume(input);
2870
- try {
2871
- return { recordFile, text: await readFile3(recordFile, "utf8") };
2872
- } catch (error) {
2873
- if (error.code === "ENOENT") {
2874
- return { recordFile, text: void 0 };
2875
- }
2876
- throw new SitianInfrastructureError(
2877
- `Sitian volume read failure: ${errorText(error)}`,
2878
- { cause: error }
2879
- );
2880
- }
2881
- }
2882
- async function rewriteSitianVolume(input) {
2883
- try {
2884
- const volume = ensureSitianVolume(input);
2885
- await writeFileAtomically(volume.recordFile, input.body);
2886
- return volume;
2887
- } catch (error) {
2888
- if (error instanceof SitianInfrastructureError) throw error;
2889
- throw new SitianInfrastructureError(
2890
- `Sitian volume rewrite failure: ${errorText(error)}`,
2891
- { cause: error }
2892
- );
2893
- }
2894
- }
2895
- var init_sitian_volume = __esm({
2896
- "src/sitian-volume.ts"() {
2897
- "use strict";
2898
- init_activation_ledger_topology();
2899
- init_atomic_write();
2900
- init_sitian_appender();
2901
- init_sitian_contracts();
2902
- }
2903
- });
2904
-
2905
2826
  // src/sitian-facade.ts
2906
2827
  function sitianReport(input) {
2907
2828
  return appendSitianRecord(input);
@@ -2913,7 +2834,6 @@ var init_sitian_facade = __esm({
2913
2834
  init_sitian_contracts();
2914
2835
  init_sitian_appender();
2915
2836
  init_sitian_reader();
2916
- init_sitian_volume();
2917
2837
  }
2918
2838
  });
2919
2839
 
@@ -2931,13 +2851,13 @@ __export(role_turn_host_exports, {
2931
2851
  });
2932
2852
  import { execFile, spawn as spawn2 } from "node:child_process";
2933
2853
  import { constants } from "node:fs";
2934
- import { access, appendFile, readFile as readFile4, realpath } from "node:fs/promises";
2935
- import { basename as basename3, delimiter, dirname as dirname7, isAbsolute as isAbsolute3, join as join12, resolve as resolve5 } from "node:path";
2854
+ import { access, appendFile, readFile as readFile3, realpath } from "node:fs/promises";
2855
+ import { basename as basename3, delimiter, dirname as dirname6, isAbsolute as isAbsolute3, join as join11, resolve as resolve5 } from "node:path";
2936
2856
  import { platform } from "node:process";
2937
2857
  import { promisify } from "node:util";
2938
- import { randomUUID as randomUUID3 } from "node:crypto";
2858
+ import { randomUUID as randomUUID2 } from "node:crypto";
2939
2859
  function resolveInternalRoleEntrypoint(packageRoot) {
2940
- return join12(packageRoot, INTERNAL_ROLE_ENTRYPOINT_RELATIVE);
2860
+ return join11(packageRoot, INTERNAL_ROLE_ENTRYPOINT_RELATIVE);
2941
2861
  }
2942
2862
  function buildExplicitInternalActivationArgs(selectedRoleEntry, extraArgs = []) {
2943
2863
  return ["--no-extensions", "-e", selectedRoleEntry, ...extraArgs];
@@ -2973,7 +2893,7 @@ function buildMethodArgs(methods) {
2973
2893
  function applyPiNativeSkillInvocation(methods, prompt) {
2974
2894
  const skills = methods.filter((method) => method.kind === "skill");
2975
2895
  if (skills.length !== 1) return prompt;
2976
- const name = basename3(dirname7(skills[0].path));
2896
+ const name = basename3(dirname6(skills[0].path));
2977
2897
  if (name.length === 0) return prompt;
2978
2898
  const token = `/skill:${name}`;
2979
2899
  const trimmed = prompt.trimStart();
@@ -3214,7 +3134,7 @@ ${paths.join("\n")}`
3214
3134
  }
3215
3135
  async function appendPiSessionCustomEntry(authority, principal, customType, data) {
3216
3136
  const { sessionFile } = authority.decode(principal);
3217
- const text = await readFile4(sessionFile, "utf8");
3137
+ const text = await readFile3(sessionFile, "utf8");
3218
3138
  let parentId = null;
3219
3139
  for (const line2 of text.trim().split("\n").filter(Boolean)) {
3220
3140
  const entry = JSON.parse(line2);
@@ -3225,7 +3145,7 @@ async function appendPiSessionCustomEntry(authority, principal, customType, data
3225
3145
  type: "custom",
3226
3146
  customType,
3227
3147
  data,
3228
- id: randomUUID3(),
3148
+ id: randomUUID2(),
3229
3149
  parentId,
3230
3150
  timestamp: timestamp2
3231
3151
  })}
@@ -3386,7 +3306,7 @@ __export(session_assistant_usage_exports, {
3386
3306
  sessionFileFromPublicSummon: () => sessionFileFromPublicSummon,
3387
3307
  usageFromPublicSummon: () => usageFromPublicSummon
3388
3308
  });
3389
- import { join as join13 } from "node:path";
3309
+ import { join as join12 } from "node:path";
3390
3310
  async function readAssistantUsageFromSessionFile(sessionFile) {
3391
3311
  const { readFile: readFile25 } = await import("node:fs/promises");
3392
3312
  let text;
@@ -3456,7 +3376,7 @@ async function readAssistantUsageFromSessionFile(sessionFile) {
3456
3376
  }
3457
3377
  function sessionFileFromPublicSummon(summoned) {
3458
3378
  if (typeof summoned.runDirectory === "string" && summoned.runDirectory.trim() !== "") {
3459
- return join13(summoned.runDirectory, "session", "session.jsonl");
3379
+ return join12(summoned.runDirectory, "session", "session.jsonl");
3460
3380
  }
3461
3381
  const fromArtifacts = summoned.terminal?.artifacts?.map((a) => a.path).find((p) => typeof p === "string" && p.endsWith("session.jsonl"));
3462
3382
  if (fromArtifacts !== void 0) return fromArtifacts;
@@ -3465,7 +3385,7 @@ function sessionFileFromPublicSummon(summoned) {
3465
3385
  const facts = outcome.decisiveFacts;
3466
3386
  const pointer = facts?.runPointer;
3467
3387
  if (typeof pointer === "string" && pointer.trim() !== "") {
3468
- return join13(pointer, "session", "session.jsonl");
3388
+ return join12(pointer, "session", "session.jsonl");
3469
3389
  }
3470
3390
  return void 0;
3471
3391
  }
@@ -3620,8 +3540,8 @@ var init_compliance_transport = __esm({
3620
3540
 
3621
3541
  // src/role-run-relocation.ts
3622
3542
  import { existsSync as existsSync5 } from "node:fs";
3623
- import { readdir as readdir2, readFile as readFile5, writeFile as writeFile3 } from "node:fs/promises";
3624
- import { join as join14, sep as sep2 } from "node:path";
3543
+ import { readdir as readdir2, readFile as readFile4, writeFile as writeFile2 } from "node:fs/promises";
3544
+ import { join as join13, sep as sep2 } from "node:path";
3625
3545
  function isEnoent2(error) {
3626
3546
  return error instanceof Error && "code" in error && error.code === "ENOENT";
3627
3547
  }
@@ -3710,15 +3630,15 @@ function rewriteSummonsMaterials(value, rewrites) {
3710
3630
  }
3711
3631
  async function rewriteJsonObjectFile(path, fields, rewrites) {
3712
3632
  if (!existsSync5(path)) return;
3713
- const page = JSON.parse(await readFile5(path, "utf8"));
3633
+ const page = JSON.parse(await readFile4(path, "utf8"));
3714
3634
  if (!isPlainObject(page)) return;
3715
3635
  rewriteRunDirectoryPathFieldsAgainstRewrites(page, fields, rewrites);
3716
- await writeFile3(path, `${JSON.stringify(page, null, 2)}
3636
+ await writeFile2(path, `${JSON.stringify(page, null, 2)}
3717
3637
  `, "utf8");
3718
3638
  }
3719
3639
  async function rewriteOfficerPointerFile(path, rewrites) {
3720
3640
  if (!existsSync5(path)) return;
3721
- const page = JSON.parse(await readFile5(path, "utf8"));
3641
+ const page = JSON.parse(await readFile4(path, "utf8"));
3722
3642
  if (!isPlainObject(page)) return;
3723
3643
  if (page.kind !== "direct-officer-run-pointer") return;
3724
3644
  rewriteRunDirectoryPathFieldsAgainstRewrites(
@@ -3726,12 +3646,12 @@ async function rewriteOfficerPointerFile(path, rewrites) {
3726
3646
  OFFICER_POINTER_FIELDS,
3727
3647
  rewrites
3728
3648
  );
3729
- await writeFile3(path, `${JSON.stringify(page)}
3649
+ await writeFile2(path, `${JSON.stringify(page)}
3730
3650
  `, "utf8");
3731
3651
  }
3732
3652
  async function rewriteSitianRecordsJsonl(path, rewrites) {
3733
3653
  if (!existsSync5(path)) return;
3734
- const raw = await readFile5(path, "utf8");
3654
+ const raw = await readFile4(path, "utf8");
3735
3655
  if (raw.length === 0) return;
3736
3656
  const endsWithNewline = raw.endsWith("\n");
3737
3657
  const lines = raw.split("\n");
@@ -3773,7 +3693,7 @@ async function rewriteSitianRecordsJsonl(path, rewrites) {
3773
3693
  }
3774
3694
  if (!changed) return;
3775
3695
  const body = out.join("\n");
3776
- await writeFile3(
3696
+ await writeFile2(
3777
3697
  path,
3778
3698
  endsWithNewline && !body.endsWith("\n") ? `${body}
3779
3699
  ` : body,
@@ -3782,7 +3702,7 @@ async function rewriteSitianRecordsJsonl(path, rewrites) {
3782
3702
  }
3783
3703
  async function rewriteSessionTranscriptBindings(path, rewrites) {
3784
3704
  if (!existsSync5(path)) return;
3785
- const raw = await readFile5(path, "utf8");
3705
+ const raw = await readFile4(path, "utf8");
3786
3706
  if (raw.length === 0) return;
3787
3707
  const endsWithNewline = raw.endsWith("\n");
3788
3708
  const lines = raw.split("\n");
@@ -3833,7 +3753,7 @@ async function rewriteSessionTranscriptBindings(path, rewrites) {
3833
3753
  }
3834
3754
  if (!changed) return;
3835
3755
  const body = out.join("\n");
3836
- await writeFile3(
3756
+ await writeFile2(
3837
3757
  path,
3838
3758
  endsWithNewline && !body.endsWith("\n") ? `${body}
3839
3759
  ` : body,
@@ -3841,7 +3761,7 @@ async function rewriteSessionTranscriptBindings(path, rewrites) {
3841
3761
  );
3842
3762
  }
3843
3763
  async function rewriteNestedMachinePathPages(pagesDirectory, rewrites) {
3844
- const sessionRoot = join14(pagesDirectory, "session");
3764
+ const sessionRoot = join13(pagesDirectory, "session");
3845
3765
  async function walk(directory) {
3846
3766
  let entries;
3847
3767
  try {
@@ -3851,7 +3771,7 @@ async function rewriteNestedMachinePathPages(pagesDirectory, rewrites) {
3851
3771
  throw error;
3852
3772
  }
3853
3773
  for (const entry of entries) {
3854
- const path = join14(directory, entry.name);
3774
+ const path = join13(directory, entry.name);
3855
3775
  if (entry.isDirectory()) {
3856
3776
  await walk(path);
3857
3777
  continue;
@@ -3873,9 +3793,9 @@ async function rewriteNestedMachinePathPages(pagesDirectory, rewrites) {
3873
3793
  async function rewriteRoleRunDurablePages(input) {
3874
3794
  const { pagesDirectory } = input;
3875
3795
  const rewrites = collectRewrites(input);
3876
- const admittedPath = join14(pagesDirectory, "admitted-request.json");
3796
+ const admittedPath = join13(pagesDirectory, "admitted-request.json");
3877
3797
  if (existsSync5(admittedPath)) {
3878
- const page = JSON.parse(await readFile5(admittedPath, "utf8"));
3798
+ const page = JSON.parse(await readFile4(admittedPath, "utf8"));
3879
3799
  rewriteRunDirectoryPathFieldsAgainstRewrites(
3880
3800
  page,
3881
3801
  ADMITTED_PAGE_FIELDS,
@@ -3900,27 +3820,27 @@ async function rewriteRoleRunDurablePages(input) {
3900
3820
  rewrites
3901
3821
  );
3902
3822
  }
3903
- await writeFile3(admittedPath, `${JSON.stringify(page, null, 2)}
3823
+ await writeFile2(admittedPath, `${JSON.stringify(page, null, 2)}
3904
3824
  `, "utf8");
3905
3825
  }
3906
- const invocationPath = join14(pagesDirectory, "invocation.json");
3826
+ const invocationPath = join13(pagesDirectory, "invocation.json");
3907
3827
  if (existsSync5(invocationPath)) {
3908
- const page = JSON.parse(await readFile5(invocationPath, "utf8"));
3828
+ const page = JSON.parse(await readFile4(invocationPath, "utf8"));
3909
3829
  rewriteRunDirectoryPathFieldsAgainstRewrites(
3910
3830
  page,
3911
3831
  INVOCATION_PAGE_FIELDS,
3912
3832
  rewrites
3913
3833
  );
3914
- await writeFile3(
3834
+ await writeFile2(
3915
3835
  invocationPath,
3916
3836
  `${JSON.stringify(page, null, 2)}
3917
3837
  `,
3918
3838
  "utf8"
3919
3839
  );
3920
3840
  }
3921
- const statePath = join14(pagesDirectory, "run-state.json");
3841
+ const statePath = join13(pagesDirectory, "run-state.json");
3922
3842
  if (existsSync5(statePath)) {
3923
- const page = JSON.parse(await readFile5(statePath, "utf8"));
3843
+ const page = JSON.parse(await readFile4(statePath, "utf8"));
3924
3844
  rewriteRunDirectoryPathFieldsAgainstRewrites(
3925
3845
  page,
3926
3846
  RUN_STATE_PAGE_FIELDS,
@@ -3936,7 +3856,7 @@ async function rewriteRoleRunDurablePages(input) {
3936
3856
  if (isPlainObject(page.currentCourt)) {
3937
3857
  rewriteSummonsMaterials(page.currentCourt.summons, rewrites);
3938
3858
  }
3939
- await writeFile3(statePath, `${JSON.stringify(page, null, 2)}
3859
+ await writeFile2(statePath, `${JSON.stringify(page, null, 2)}
3940
3860
  `, "utf8");
3941
3861
  }
3942
3862
  await rewriteNestedMachinePathPages(pagesDirectory, rewrites);
@@ -4104,8 +4024,8 @@ var init_terminating_tools = __esm({
4104
4024
  });
4105
4025
 
4106
4026
  // src/doctor-evidence.ts
4107
- import { readdir as readdir3, readFile as readFile6, realpath as realpath2, stat } from "node:fs/promises";
4108
- import { dirname as dirname8, relative as relative2, resolve as resolve6, sep as sep3 } from "node:path";
4027
+ import { readdir as readdir3, readFile as readFile5, realpath as realpath2, stat } from "node:fs/promises";
4028
+ import { dirname as dirname7, relative as relative2, resolve as resolve6, sep as sep3 } from "node:path";
4109
4029
  function record2(value) {
4110
4030
  return typeof value === "object" && value !== null && !Array.isArray(value);
4111
4031
  }
@@ -4144,7 +4064,7 @@ async function stableRunsIdentity(root) {
4144
4064
  } catch (error) {
4145
4065
  if (!isMissingPathError2(error)) throw error;
4146
4066
  }
4147
- const parent = dirname8(cursor);
4067
+ const parent = dirname7(cursor);
4148
4068
  if (parent === cursor) return root;
4149
4069
  cursor = parent;
4150
4070
  }
@@ -4220,7 +4140,7 @@ async function loadDoctorCase(runsPath) {
4220
4140
  const turns = { count: 0, sources: [] }, calls = { count: 0, sources: [] }, tokens = { count: 0, sources: [] };
4221
4141
  for (const path of await discoverCaseFiles(root)) {
4222
4142
  const id = relative2(root, path).split(sep3).join("/");
4223
- const bytes = await readFile6(path);
4143
+ const bytes = await readFile5(path);
4224
4144
  const content = bytes.toString("utf8");
4225
4145
  const kind = id.endsWith(".jsonl") ? "session" : "stderr";
4226
4146
  evidence.push({ id, kind, byteLength: bytes.byteLength, contentLength: content.length, sha256: sha256Hex(bytes), content });
@@ -4250,7 +4170,7 @@ var init_doctor_evidence = __esm({
4250
4170
 
4251
4171
  // src/collector-config.ts
4252
4172
  import { createHash as createHash4 } from "node:crypto";
4253
- import { readFile as readFile7 } from "node:fs/promises";
4173
+ import { readFile as readFile6 } from "node:fs/promises";
4254
4174
  function fail3(message, cause) {
4255
4175
  throw new Error(message, cause === void 0 ? void 0 : { cause });
4256
4176
  }
@@ -4293,7 +4213,7 @@ function emptyCollectorManifest() {
4293
4213
  async function loadCollectorManifest(path) {
4294
4214
  let bytes;
4295
4215
  try {
4296
- bytes = await readFile7(path);
4216
+ bytes = await readFile6(path);
4297
4217
  } catch (error) {
4298
4218
  fail3(`Collector request manifest is unreadable at ${path}`, error);
4299
4219
  }
@@ -5133,7 +5053,7 @@ var init_git_object_id = __esm({
5133
5053
 
5134
5054
  // src/merger-git-state.ts
5135
5055
  import { execFile as execFile2 } from "node:child_process";
5136
- import { access as access2, readFile as readFile8 } from "node:fs/promises";
5056
+ import { access as access2, readFile as readFile7 } from "node:fs/promises";
5137
5057
  import { constants as fsConstants } from "node:fs";
5138
5058
  import { isAbsolute as isAbsolute4, resolve as resolve7 } from "node:path";
5139
5059
  import { promisify as promisify2 } from "node:util";
@@ -5203,7 +5123,7 @@ function createProductionMergerGitState(repositoryRoot = process.cwd()) {
5203
5123
  const mergeHeadPath = isAbsolute4(mergeHeadReported) ? mergeHeadReported : resolve7(repositoryRoot, mergeHeadReported);
5204
5124
  let sourceObjectId = "";
5205
5125
  if (await pathExists(mergeHeadPath)) {
5206
- const raw = exactUtf8(await readFile8(mergeHeadPath), "Git MERGE_HEAD");
5126
+ const raw = exactUtf8(await readFile7(mergeHeadPath), "Git MERGE_HEAD");
5207
5127
  const mergeHeads = raw.trim().split(/\r?\n/).map((row) => row.trim()).filter(Boolean);
5208
5128
  if (mergeHeads.length === 0) throw new Error("Git MERGE_HEAD is empty");
5209
5129
  if (mergeHeads.length !== 1) throw new Error("Assigned repository does not have one ordinary in-progress merge");
@@ -5255,10 +5175,10 @@ var init_uuidv7 = __esm({
5255
5175
  });
5256
5176
 
5257
5177
  // src/typed-provider-http.ts
5258
- import { readFile as readFile9, unlink, writeFile as writeFile4 } from "node:fs/promises";
5259
- import { join as join15 } from "node:path";
5178
+ import { readFile as readFile8, unlink, writeFile as writeFile3 } from "node:fs/promises";
5179
+ import { join as join14 } from "node:path";
5260
5180
  function typedProviderHttpPath(runDirectory) {
5261
- return join15(runDirectory, TYPED_HTTP_FILE);
5181
+ return join14(runDirectory, TYPED_HTTP_FILE);
5262
5182
  }
5263
5183
  async function clearTypedProviderHttpObservation(runDirectory) {
5264
5184
  try {
@@ -5279,7 +5199,7 @@ async function recordTypedProviderHttpStatus(runDirectory, observation) {
5279
5199
  httpStatus: observation.httpStatus,
5280
5200
  provider: observation.provider
5281
5201
  };
5282
- await writeFile4(
5202
+ await writeFile3(
5283
5203
  typedProviderHttpPath(runDirectory),
5284
5204
  `${JSON.stringify(body)}
5285
5205
  `,
@@ -5289,7 +5209,7 @@ async function recordTypedProviderHttpStatus(runDirectory, observation) {
5289
5209
  async function readLatestTypedProviderHttpObservation(runDirectory) {
5290
5210
  let text;
5291
5211
  try {
5292
- text = await readFile9(typedProviderHttpPath(runDirectory), "utf8");
5212
+ text = await readFile8(typedProviderHttpPath(runDirectory), "utf8");
5293
5213
  } catch (error) {
5294
5214
  if (error instanceof Error && "code" in error && error.code === "ENOENT") {
5295
5215
  return void 0;
@@ -5318,8 +5238,8 @@ var init_typed_provider_http = __esm({
5318
5238
  });
5319
5239
 
5320
5240
  // src/public-cli/run-lifecycle.ts
5321
- import { chmod, lstat as lstat2, open, readdir as readdir4, readFile as readFile10, unlink as unlink2, writeFile as writeFile5 } from "node:fs/promises";
5322
- import { basename as basename4, join as join16 } from "node:path";
5241
+ import { chmod, lstat as lstat2, open, readdir as readdir4, readFile as readFile9, unlink as unlink2, writeFile as writeFile4 } from "node:fs/promises";
5242
+ import { basename as basename4, join as join15 } from "node:path";
5323
5243
  function selectResumeContinuationPrompt(message, engineMaterial) {
5324
5244
  const lines = message !== void 0 ? [message] : [];
5325
5245
  return appendEngineSessionMaterial(lines, engineMaterial).join("\n");
@@ -5348,8 +5268,8 @@ function renderResumeCommand(runId) {
5348
5268
  }
5349
5269
  async function writeRoleRunState(runDirectory, record4) {
5350
5270
  const payload = { ...record4, runDirectory };
5351
- await writeFile5(
5352
- join16(runDirectory, RUN_STATE_FILE),
5271
+ await writeFile4(
5272
+ join15(runDirectory, RUN_STATE_FILE),
5353
5273
  `${JSON.stringify(payload, null, 2)}
5354
5274
  `,
5355
5275
  "utf8"
@@ -5399,7 +5319,7 @@ function parseCurrentCourtState(raw) {
5399
5319
  async function readRoleRunStateDisk(runDirectory) {
5400
5320
  let raw;
5401
5321
  try {
5402
- raw = JSON.parse(await readFile10(join16(runDirectory, RUN_STATE_FILE), "utf8"));
5322
+ raw = JSON.parse(await readFile9(join15(runDirectory, RUN_STATE_FILE), "utf8"));
5403
5323
  } catch (error) {
5404
5324
  if (errorCodeOf2(error) === "ENOENT") return void 0;
5405
5325
  throw error;
@@ -5466,8 +5386,8 @@ async function writeRoleRunStateDisk(runDirectory, disk) {
5466
5386
  ...disk.resumable === void 0 ? {} : { resumable: disk.resumable },
5467
5387
  ...disk.currentCourt === void 0 ? {} : { currentCourt: disk.currentCourt }
5468
5388
  };
5469
- await writeFile5(
5470
- join16(runDirectory, RUN_STATE_FILE),
5389
+ await writeFile4(
5390
+ join15(runDirectory, RUN_STATE_FILE),
5471
5391
  `${JSON.stringify(payload, null, 2)}
5472
5392
  `,
5473
5393
  "utf8"
@@ -5634,7 +5554,7 @@ function isProcessAlive(pid) {
5634
5554
  async function autopsyWriterLock(lockPath) {
5635
5555
  let content;
5636
5556
  try {
5637
- content = await readFile10(lockPath, "utf8");
5557
+ content = await readFile9(lockPath, "utf8");
5638
5558
  } catch (error) {
5639
5559
  if (errorCodeOf2(error) === "ENOENT") return { verdict: "absent" };
5640
5560
  return { verdict: "unknown", reason: "unreadable", readFailure: error };
@@ -5693,7 +5613,7 @@ async function createWriterLease(lockPath, runDirectory, reportCleanupFailure) {
5693
5613
  },
5694
5614
  relocate(nextRunDirectory) {
5695
5615
  currentRunDirectory = nextRunDirectory;
5696
- currentLockPath = join16(nextRunDirectory, WRITER_LOCK_FILE);
5616
+ currentLockPath = join15(nextRunDirectory, WRITER_LOCK_FILE);
5697
5617
  },
5698
5618
  async release() {
5699
5619
  if (released) return;
@@ -5732,10 +5652,10 @@ async function acquireRunWriterLease(runDirectory, onCleanupFailure) {
5732
5652
  };
5733
5653
  const reportReadFailure = (error) => {
5734
5654
  reportDiagnostic(
5735
- `writer lease lock read failed (holder liveness unverifiable; lock left in place) at ${join16(runDirectory, WRITER_LOCK_FILE)}: ${describeErrorIdentity(error)}`
5655
+ `writer lease lock read failed (holder liveness unverifiable; lock left in place) at ${join15(runDirectory, WRITER_LOCK_FILE)}: ${describeErrorIdentity(error)}`
5736
5656
  );
5737
5657
  };
5738
- const lockPath = join16(runDirectory, WRITER_LOCK_FILE);
5658
+ const lockPath = join15(runDirectory, WRITER_LOCK_FILE);
5739
5659
  let lastAutopsy = { verdict: "absent" };
5740
5660
  let lastReclaimFailure;
5741
5661
  for (let reclaimsLeft = WRITER_LEASE_RECLAIM_ROUNDS; ; reclaimsLeft -= 1) {
@@ -5790,7 +5710,7 @@ async function acquireRunWriterLease(runDirectory, onCleanupFailure) {
5790
5710
  async function findRunDirectoryById(home, runId, onlyBookKey, onlyRole) {
5791
5711
  if (runId.trim() === "") return void 0;
5792
5712
  const ledgerHome = resolveActivationLedgerHome(home);
5793
- const booksRoot = join16(ledgerHome, "books");
5713
+ const booksRoot = join15(ledgerHome, "books");
5794
5714
  let bookKeys;
5795
5715
  try {
5796
5716
  bookKeys = await readdir4(booksRoot);
@@ -5831,7 +5751,7 @@ async function readRunParentPath(runDirectory) {
5831
5751
  let raw;
5832
5752
  try {
5833
5753
  raw = JSON.parse(
5834
- await readFile10(join16(runDirectory, "admitted-request.json"), "utf8")
5754
+ await readFile9(join15(runDirectory, "admitted-request.json"), "utf8")
5835
5755
  );
5836
5756
  } catch (error) {
5837
5757
  if (errorCodeOf2(error) === "ENOENT") return void 0;
@@ -5852,7 +5772,7 @@ async function readRunParentPath(runDirectory) {
5852
5772
  async function runHasFormedSessionPrincipal(runDirectory) {
5853
5773
  const disk = await readRoleRunStateDisk(runDirectory);
5854
5774
  if (disk === void 0) return false;
5855
- const sessionFile = typeof disk.principalWire.sessionFile === "string" && disk.principalWire.sessionFile.trim() !== "" ? disk.principalWire.sessionFile : join16(disk.principalWire.sessionDirectory, "session.jsonl");
5775
+ const sessionFile = typeof disk.principalWire.sessionFile === "string" && disk.principalWire.sessionFile.trim() !== "" ? disk.principalWire.sessionFile : join15(disk.principalWire.sessionDirectory, "session.jsonl");
5856
5776
  try {
5857
5777
  const stat2 = await lstat2(sessionFile);
5858
5778
  return stat2.isFile() && !stat2.isSymbolicLink();
@@ -5999,7 +5919,7 @@ async function loadResumableRunRecord(home, runId, authority) {
5999
5919
  let sourceRun;
6000
5920
  try {
6001
5921
  const raw = JSON.parse(
6002
- await readFile10(run.admittedRequestPath, "utf8")
5922
+ await readFile9(run.admittedRequestPath, "utf8")
6003
5923
  );
6004
5924
  if (raw !== null && typeof raw === "object" && !Array.isArray(raw)) {
6005
5925
  const record4 = raw;
@@ -6114,7 +6034,7 @@ async function loadResumableRunRecord(home, runId, authority) {
6114
6034
  let model;
6115
6035
  try {
6116
6036
  const invocationRaw = JSON.parse(
6117
- await readFile10(join16(run.runDirectory, "invocation.json"), "utf8")
6037
+ await readFile9(join15(run.runDirectory, "invocation.json"), "utf8")
6118
6038
  );
6119
6039
  if (invocationRaw !== null && typeof invocationRaw === "object" && !Array.isArray(invocationRaw)) {
6120
6040
  const rec = invocationRaw;
@@ -6345,7 +6265,7 @@ __export(notary_source_run_exports, {
6345
6265
  loadNotarySourceRunLocator: () => loadNotarySourceRunLocator,
6346
6266
  resolveNotarySourceRunLocator: () => resolveNotarySourceRunLocator
6347
6267
  });
6348
- import { dirname as dirname9, isAbsolute as isAbsolute6, join as join17, resolve as resolve8, basename as basename5 } from "node:path";
6268
+ import { dirname as dirname8, isAbsolute as isAbsolute6, join as join16, resolve as resolve8, basename as basename5 } from "node:path";
6349
6269
  import { lstat as lstat3, realpath as realpath3 } from "node:fs/promises";
6350
6270
  function parseRunDirectoryName(name) {
6351
6271
  const match = RUN_DIR_NAME.exec(name);
@@ -6391,20 +6311,20 @@ async function resolveNotarySourceRunLocator(options) {
6391
6311
  }
6392
6312
  const ledgerHome = resolveActivationLedgerHome(options.home);
6393
6313
  const bookKey = resolveBookKeyFromGit(options.projectRoot);
6394
- const bookRunsRoot = join17(activationBookDirectory(ledgerHome, bookKey), "runs");
6314
+ const bookRunsRoot = join16(activationBookDirectory(ledgerHome, bookKey), "runs");
6395
6315
  let candidate;
6396
6316
  const bare = parseRunDirectoryName(raw);
6397
6317
  if (bare !== void 0 && !raw.includes("/") && !raw.includes("\\")) {
6398
- candidate = await findRunDirectoryById(options.home, bare.runId, bookKey, bare.role) ?? join17(bookRunsRoot, `${bare.runId}@${bare.role}`);
6318
+ candidate = await findRunDirectoryById(options.home, bare.runId, bookKey, bare.role) ?? join16(bookRunsRoot, `${bare.runId}@${bare.role}`);
6399
6319
  } else {
6400
6320
  candidate = isAbsolute6(raw) ? raw : resolve8(options.projectRoot, raw);
6401
6321
  }
6402
6322
  const real = await requireRunDirectory(candidate, raw);
6403
6323
  const identity = parseRunDirectoryName(basename5(real));
6404
6324
  const bookIdentity = physicalPathIdentity(activationBookDirectory(ledgerHome, bookKey));
6405
- const parentIdentity = physicalPathIdentity(dirname9(real));
6406
- const subjectBookIdentity = physicalPathIdentity(dirname9(dirname9(dirname9(real))));
6407
- if (parentIdentity !== physicalPathIdentity(bookRunsRoot) && !(basename5(dirname9(real)) === "runs" && subjectBookIdentity === bookIdentity)) {
6325
+ const parentIdentity = physicalPathIdentity(dirname8(real));
6326
+ const subjectBookIdentity = physicalPathIdentity(dirname8(dirname8(dirname8(real))));
6327
+ if (parentIdentity !== physicalPathIdentity(bookRunsRoot) && !(basename5(dirname8(real)) === "runs" && subjectBookIdentity === bookIdentity)) {
6408
6328
  throw new NotarySourceRunError(
6409
6329
  "notary --source-run must resolve to a retained run under the project machine-ledger book"
6410
6330
  );
@@ -7545,12 +7465,12 @@ import { execFileSync as execFileSync3 } from "node:child_process";
7545
7465
  import { existsSync as existsSync6 } from "node:fs";
7546
7466
  import {
7547
7467
  lstat as lstat4,
7548
- readFile as readFile11,
7468
+ readFile as readFile10,
7549
7469
  realpath as realpath4,
7550
- rename as rename2,
7551
- writeFile as writeFile6
7470
+ rename,
7471
+ writeFile as writeFile5
7552
7472
  } from "node:fs/promises";
7553
- import { basename as basename6, dirname as dirname10, isAbsolute as isAbsolute7, join as join18, resolve as resolve9, sep as sep4 } from "node:path";
7473
+ import { basename as basename6, dirname as dirname9, isAbsolute as isAbsolute7, join as join17, resolve as resolve9, sep as sep4 } from "node:path";
7554
7474
  function issueAdmissionPlacement(authority, request) {
7555
7475
  const ledgerHome = resolveActivationLedgerHome(request.home);
7556
7476
  const bookKey = resolveBookKeyFromGit(request.cwd);
@@ -7575,7 +7495,7 @@ async function writeAdmittedRequestPersistence(admittedRequestPath, body, coordi
7575
7495
  sessionDirectory: coordinates.sessionDirectory,
7576
7496
  sessionFile: coordinates.sessionFile
7577
7497
  };
7578
- await writeFile6(
7498
+ await writeFile5(
7579
7499
  admittedRequestPath,
7580
7500
  `${JSON.stringify(projection, null, 2)}
7581
7501
  `,
@@ -7603,16 +7523,16 @@ async function writeRoleInvocationLedger(source, role, effectiveModel) {
7603
7523
  ...source.ticketNumber === void 0 ? {} : { ticketNumber: source.ticketNumber },
7604
7524
  ...effectiveModelLedgerFields(effectiveModel)
7605
7525
  };
7606
- await writeFile6(
7607
- join18(source.runDirectory, "invocation.json"),
7526
+ await writeFile5(
7527
+ join17(source.runDirectory, "invocation.json"),
7608
7528
  `${JSON.stringify(identity, null, 2)}
7609
7529
  `,
7610
7530
  "utf8"
7611
7531
  );
7612
7532
  }
7613
7533
  async function recordEffectiveInvocationModel(runDirectory, model, engine, host, engineModel) {
7614
- const ledgerPath = join18(runDirectory, "invocation.json");
7615
- const current = JSON.parse(await readFile11(ledgerPath, "utf8"));
7534
+ const ledgerPath = join17(runDirectory, "invocation.json");
7535
+ const current = JSON.parse(await readFile10(ledgerPath, "utf8"));
7616
7536
  const next = { ...current };
7617
7537
  if (model !== void 0) {
7618
7538
  next.provider = model.provider;
@@ -7636,7 +7556,7 @@ async function recordEffectiveInvocationModel(runDirectory, model, engine, host,
7636
7556
  if (host !== void 0) {
7637
7557
  next.host = host;
7638
7558
  }
7639
- await writeFile6(
7559
+ await writeFile5(
7640
7560
  ledgerPath,
7641
7561
  `${JSON.stringify(next, null, 2)}
7642
7562
  `,
@@ -7644,9 +7564,9 @@ async function recordEffectiveInvocationModel(runDirectory, model, engine, host,
7644
7564
  );
7645
7565
  }
7646
7566
  async function mergeInvocationIdentityPage(runDirectory, fields) {
7647
- const ledgerPath = join18(runDirectory, "invocation.json");
7648
- const current = JSON.parse(await readFile11(ledgerPath, "utf8"));
7649
- await writeFile6(
7567
+ const ledgerPath = join17(runDirectory, "invocation.json");
7568
+ const current = JSON.parse(await readFile10(ledgerPath, "utf8"));
7569
+ await writeFile5(
7650
7570
  ledgerPath,
7651
7571
  `${JSON.stringify({
7652
7572
  ...current,
@@ -7661,14 +7581,14 @@ async function persistAdmittedSourceRunPath(admitted, sourceRunPath) {
7661
7581
  throw new Error("persistAdmittedSourceRunPath requires a non-empty sourceRunPath");
7662
7582
  }
7663
7583
  const admittedPath = admitted.admittedRequestPath;
7664
- const current = JSON.parse(await readFile11(admittedPath, "utf8"));
7584
+ const current = JSON.parse(await readFile10(admittedPath, "utf8"));
7665
7585
  if (typeof current.sourceRunPath === "string") {
7666
7586
  if (current.sourceRunPath === sourceRunPath) return;
7667
7587
  throw new Error(
7668
7588
  `persistAdmittedSourceRunPath refuses to replace ${current.sourceRunPath} with ${sourceRunPath}`
7669
7589
  );
7670
7590
  }
7671
- await writeFile6(
7591
+ await writeFile5(
7672
7592
  admittedPath,
7673
7593
  `${JSON.stringify({ ...current, sourceRunPath }, null, 2)}
7674
7594
  `,
@@ -7710,8 +7630,8 @@ async function bindCourtTicketNumbersOnAdmitted(admitted, courtTicketNumbers) {
7710
7630
  }
7711
7631
  const frozen = Object.freeze([...projected]);
7712
7632
  const admittedPath = admitted.admittedRequestPath;
7713
- const current = JSON.parse(await readFile11(admittedPath, "utf8"));
7714
- await writeFile6(
7633
+ const current = JSON.parse(await readFile10(admittedPath, "utf8"));
7634
+ await writeFile5(
7715
7635
  admittedPath,
7716
7636
  `${JSON.stringify({ ...current, courtTicketNumbers: frozen }, null, 2)}
7717
7637
  `,
@@ -7732,8 +7652,8 @@ async function relocateAdmittedRunToTicket(admitted, authority, heldLease) {
7732
7652
  runId: admitted.runId,
7733
7653
  role: admitted.role
7734
7654
  });
7735
- ensureRoleRunDirectory(ledgerHome, dirname10(target.runDirectory));
7736
- await rename2(oldRunDirectory, target.runDirectory);
7655
+ ensureRoleRunDirectory(ledgerHome, dirname9(target.runDirectory));
7656
+ await rename(oldRunDirectory, target.runDirectory);
7737
7657
  heldLease?.relocate(target.runDirectory);
7738
7658
  const admittedRecord = admitted;
7739
7659
  rewriteRunDirectoryPathFields(
@@ -7770,9 +7690,9 @@ async function bindTicketNumberOnRunDirectory(runDirectory, ticketNumber) {
7770
7690
  ticketNumber,
7771
7691
  "bindTicketNumberOnRunDirectory"
7772
7692
  );
7773
- const admittedPath = join18(runDirectory, "admitted-request.json");
7774
- const invocationPath = join18(runDirectory, "invocation.json");
7775
- const admitted = JSON.parse(await readFile11(admittedPath, "utf8"));
7693
+ const admittedPath = join17(runDirectory, "admitted-request.json");
7694
+ const invocationPath = join17(runDirectory, "invocation.json");
7695
+ const admitted = JSON.parse(await readFile10(admittedPath, "utf8"));
7776
7696
  const existing = admitted.ticketNumber;
7777
7697
  if (typeof existing === "number") {
7778
7698
  if (existing === ticketNumber) return;
@@ -7782,7 +7702,7 @@ async function bindTicketNumberOnRunDirectory(runDirectory, ticketNumber) {
7782
7702
  }
7783
7703
  if (existsSync6(invocationPath)) {
7784
7704
  const invocation = JSON.parse(
7785
- await readFile11(invocationPath, "utf8")
7705
+ await readFile10(invocationPath, "utf8")
7786
7706
  );
7787
7707
  if (typeof invocation.ticketNumber === "number" && invocation.ticketNumber !== ticketNumber) {
7788
7708
  throw new Error(
@@ -7790,7 +7710,7 @@ async function bindTicketNumberOnRunDirectory(runDirectory, ticketNumber) {
7790
7710
  );
7791
7711
  }
7792
7712
  }
7793
- await writeFile6(
7713
+ await writeFile5(
7794
7714
  admittedPath,
7795
7715
  `${JSON.stringify({ ...admitted, ticketNumber }, null, 2)}
7796
7716
  `,
@@ -7807,7 +7727,7 @@ async function recordLaunchedPiIdentity(runDirectory, identity) {
7807
7727
  async function observeLaunchedRolePackageIdentity(packageRoot, selectedRoleEntry) {
7808
7728
  const rolePackageRoot = packageRoot;
7809
7729
  const raw = JSON.parse(
7810
- await readFile11(join18(rolePackageRoot, "package.json"), "utf8")
7730
+ await readFile10(join17(rolePackageRoot, "package.json"), "utf8")
7811
7731
  );
7812
7732
  if (typeof raw.version !== "string" || raw.version.trim() === "") {
7813
7733
  throw new Error(
@@ -8063,10 +7983,10 @@ async function freezeRegularFileAttachment(sourcePath, destinationDir, index) {
8063
7983
  `attachment must be a regular file (not a directory or symlink): ${sourcePath}`
8064
7984
  );
8065
7985
  }
8066
- const bytes = await readFile11(absolute);
7986
+ const bytes = await readFile10(absolute);
8067
7987
  const name = `${String(index).padStart(2, "0")}-${basename6(absolute)}`;
8068
- const frozenPath = join18(destinationDir, name);
8069
- await writeFile6(frozenPath, bytes);
7988
+ const frozenPath = join17(destinationDir, name);
7989
+ await writeFile5(frozenPath, bytes);
8070
7990
  return {
8071
7991
  attachment: {
8072
7992
  provenancePath: absolute,
@@ -8093,7 +8013,7 @@ async function freezeAttachments(attachmentPaths, attachmentsDirectory) {
8093
8013
  async function freezeAttachmentsIntoRun(attachmentPaths, runDirectory, summonsKey = `s-${Date.now().toString(36)}`) {
8094
8014
  if (attachmentPaths.length === 0) return [];
8095
8015
  const ledgerHome = resolveActivationLedgerHome(homeFromRunDirectory(runDirectory));
8096
- const attachmentsDirectory = join18(runDirectory, "attachments", summonsKey);
8016
+ const attachmentsDirectory = join17(runDirectory, "attachments", summonsKey);
8097
8017
  ensureRealDirectoryTree(ledgerHome, attachmentsDirectory);
8098
8018
  return freezeAttachments(attachmentPaths, attachmentsDirectory);
8099
8019
  }
@@ -8151,7 +8071,7 @@ async function admitStandardMaterialInvocation(role, options) {
8151
8071
  })),
8152
8072
  ...ticketFields
8153
8073
  };
8154
- const admittedRequestPath = join18(runDirectory, "admitted-request.json");
8074
+ const admittedRequestPath = join17(runDirectory, "admitted-request.json");
8155
8075
  await writeAdmittedRequestPersistence(admittedRequestPath, admitted, {
8156
8076
  sessionDirectory,
8157
8077
  sessionFile
@@ -8253,7 +8173,7 @@ async function admitCountersignInvocation(options) {
8253
8173
  mediaKind: a.mediaKind
8254
8174
  }))
8255
8175
  };
8256
- const admittedRequestPath = join18(runDirectory, "admitted-request.json");
8176
+ const admittedRequestPath = join17(runDirectory, "admitted-request.json");
8257
8177
  await writeAdmittedRequestPersistence(admittedRequestPath, admitted, {
8258
8178
  sessionDirectory,
8259
8179
  sessionFile
@@ -8279,7 +8199,7 @@ function buildCountersignTransportPrompt(admitted, engineMaterial) {
8279
8199
  async function loadAdmittedJudgeRequest(runDirectory) {
8280
8200
  try {
8281
8201
  const raw = JSON.parse(
8282
- await readFile11(join18(runDirectory, "admitted-request.json"), "utf8")
8202
+ await readFile10(join17(runDirectory, "admitted-request.json"), "utf8")
8283
8203
  );
8284
8204
  if (raw === null || typeof raw !== "object" || Array.isArray(raw)) return void 0;
8285
8205
  const record4 = raw;
@@ -8334,8 +8254,8 @@ async function admitCoderInvocation(options) {
8334
8254
  home: options.home
8335
8255
  });
8336
8256
  const attachments = await freezeAttachments(options.attachmentPaths, attachmentsDirectory);
8337
- const taskPath = join18(runDirectory, "task.md");
8338
- await writeFile6(taskPath, instruction, "utf8");
8257
+ const taskPath = join17(runDirectory, "task.md");
8258
+ await writeFile5(taskPath, instruction, "utf8");
8339
8259
  const admitted = {
8340
8260
  role: "coder",
8341
8261
  phase: options.phase,
@@ -8355,7 +8275,7 @@ async function admitCoderInvocation(options) {
8355
8275
  mediaKind: a.mediaKind
8356
8276
  }))
8357
8277
  };
8358
- const admittedRequestPath = join18(runDirectory, "admitted-request.json");
8278
+ const admittedRequestPath = join17(runDirectory, "admitted-request.json");
8359
8279
  await writeAdmittedRequestPersistence(admittedRequestPath, admitted, {
8360
8280
  sessionDirectory,
8361
8281
  sessionFile
@@ -8405,7 +8325,7 @@ async function admitFixerInvocation(options) {
8405
8325
  if (options.prerequisitesPath !== void 0) {
8406
8326
  const absolutePrereq = isAbsolute7(options.prerequisitesPath) ? options.prerequisitesPath : resolve9(options.prerequisitesPath);
8407
8327
  try {
8408
- prerequisitesSource = await readFile11(absolutePrereq, "utf8");
8328
+ prerequisitesSource = await readFile10(absolutePrereq, "utf8");
8409
8329
  } catch (error) {
8410
8330
  throw new CliUsageError(
8411
8331
  `fixer prerequisites path is unreadable: ${options.prerequisitesPath}`,
@@ -8441,16 +8361,16 @@ async function admitFixerInvocation(options) {
8441
8361
  const attachments = await freezeAttachments(options.attachmentPaths, attachmentsDirectory);
8442
8362
  let prerequisitesPath;
8443
8363
  if (prerequisitesSource !== void 0) {
8444
- prerequisitesPath = join18(runDirectory, "prerequisites.json");
8445
- await writeFile6(
8364
+ prerequisitesPath = join17(runDirectory, "prerequisites.json");
8365
+ await writeFile5(
8446
8366
  prerequisitesPath,
8447
8367
  `${JSON.stringify(prerequisites, null, 2)}
8448
8368
  `,
8449
8369
  "utf8"
8450
8370
  );
8451
8371
  }
8452
- const packetPath = join18(runDirectory, "fix-packet.md");
8453
- await writeFile6(packetPath, instruction, "utf8");
8372
+ const packetPath = join17(runDirectory, "fix-packet.md");
8373
+ await writeFile5(packetPath, instruction, "utf8");
8454
8374
  const admitted = {
8455
8375
  role: "fixer",
8456
8376
  phase: options.phase,
@@ -8475,7 +8395,7 @@ async function admitFixerInvocation(options) {
8475
8395
  mediaKind: a.mediaKind
8476
8396
  }))
8477
8397
  };
8478
- const admittedRequestPath = join18(runDirectory, "admitted-request.json");
8398
+ const admittedRequestPath = join17(runDirectory, "admitted-request.json");
8479
8399
  await writeAdmittedRequestPersistence(admittedRequestPath, admitted, {
8480
8400
  sessionDirectory,
8481
8401
  sessionFile
@@ -8695,8 +8615,8 @@ async function admitCollectorInvocation(options) {
8695
8615
  const prNumber = target.kind === "bound" ? target.prNumber : void 0;
8696
8616
  let requestManifestPath;
8697
8617
  if (manifestCanonicalJson !== void 0) {
8698
- requestManifestPath = join18(runDirectory, "request-manifest.json");
8699
- await writeFile6(requestManifestPath, manifestCanonicalJson, "utf8");
8618
+ requestManifestPath = join17(runDirectory, "request-manifest.json");
8619
+ await writeFile5(requestManifestPath, manifestCanonicalJson, "utf8");
8700
8620
  }
8701
8621
  const admitted = {
8702
8622
  role: "collector",
@@ -8721,7 +8641,7 @@ async function admitCollectorInvocation(options) {
8721
8641
  mediaKind: a.mediaKind
8722
8642
  }))
8723
8643
  };
8724
- const admittedRequestPath = join18(runDirectory, "admitted-request.json");
8644
+ const admittedRequestPath = join17(runDirectory, "admitted-request.json");
8725
8645
  await writeAdmittedRequestPersistence(admittedRequestPath, admitted, {
8726
8646
  sessionDirectory,
8727
8647
  sessionFile
@@ -8819,7 +8739,7 @@ function parseDoctorArgv(args) {
8819
8739
  }
8820
8740
  async function resolveDoctorCaseRunsPath(options) {
8821
8741
  const ledgerHome = resolveActivationLedgerHome(options.home);
8822
- const defaultRuns = join18(
8742
+ const defaultRuns = join17(
8823
8743
  activationBookDirectory(ledgerHome, options.bookKey),
8824
8744
  String(options.issueNumber),
8825
8745
  "runs"
@@ -8950,7 +8870,7 @@ async function admitDoctorInvocation(options) {
8950
8870
  mediaKind: a.mediaKind
8951
8871
  }))
8952
8872
  };
8953
- const admittedRequestPath = join18(runDirectory, "admitted-request.json");
8873
+ const admittedRequestPath = join17(runDirectory, "admitted-request.json");
8954
8874
  await writeAdmittedRequestPersistence(admittedRequestPath, admitted, {
8955
8875
  sessionDirectory,
8956
8876
  sessionFile
@@ -9082,7 +9002,7 @@ async function admitNotaryInvocation(options) {
9082
9002
  ...ticketFields,
9083
9003
  ...options.correlationId === void 0 ? {} : { correlationId: options.correlationId }
9084
9004
  };
9085
- const admittedRequestPath = join18(runDirectory, "admitted-request.json");
9005
+ const admittedRequestPath = join17(runDirectory, "admitted-request.json");
9086
9006
  await writeAdmittedRequestPersistence(admittedRequestPath, admitted, {
9087
9007
  sessionDirectory,
9088
9008
  sessionFile
@@ -9185,7 +9105,7 @@ async function admitGleanerLeftInvocation(options) {
9185
9105
  attachments: [],
9186
9106
  ...options.correlationId === void 0 ? {} : { correlationId: options.correlationId }
9187
9107
  };
9188
- const admittedRequestPath = join18(runDirectory, "admitted-request.json");
9108
+ const admittedRequestPath = join17(runDirectory, "admitted-request.json");
9189
9109
  await writeAdmittedRequestPersistence(admittedRequestPath, admitted, {
9190
9110
  sessionDirectory,
9191
9111
  sessionFile
@@ -9314,7 +9234,7 @@ async function admitReviewerInvocation(options) {
9314
9234
  mediaKind: a.mediaKind
9315
9235
  }))
9316
9236
  };
9317
- const admittedRequestPath = join18(runDirectory, "admitted-request.json");
9237
+ const admittedRequestPath = join17(runDirectory, "admitted-request.json");
9318
9238
  await writeAdmittedRequestPersistence(admittedRequestPath, admitted, {
9319
9239
  sessionDirectory,
9320
9240
  sessionFile
@@ -9459,8 +9379,8 @@ async function admitMergerInvocation(options) {
9459
9379
  resolutionScope: [...derived.resolutionScope],
9460
9380
  authorizedChecks: []
9461
9381
  });
9462
- const mergerInputPath = join18(runDirectory, "merger-input.json");
9463
- await writeFile6(
9382
+ const mergerInputPath = join17(runDirectory, "merger-input.json");
9383
+ await writeFile5(
9464
9384
  mergerInputPath,
9465
9385
  `${JSON.stringify(mergerInput, null, 2)}
9466
9386
  `,
@@ -9490,7 +9410,7 @@ async function admitMergerInvocation(options) {
9490
9410
  mediaKind: a.mediaKind
9491
9411
  }))
9492
9412
  };
9493
- const admittedRequestPath = join18(runDirectory, "admitted-request.json");
9413
+ const admittedRequestPath = join17(runDirectory, "admitted-request.json");
9494
9414
  await writeAdmittedRequestPersistence(admittedRequestPath, admitted, {
9495
9415
  sessionDirectory,
9496
9416
  sessionFile
@@ -9774,15 +9694,15 @@ var init_invocation = __esm({
9774
9694
 
9775
9695
  // src/public-cli/load-production-acp-host.ts
9776
9696
  import { existsSync as existsSync7 } from "node:fs";
9777
- import { join as join19 } from "node:path";
9697
+ import { join as join18 } from "node:path";
9778
9698
  import { pathToFileURL } from "node:url";
9779
9699
  async function loadProductionAcpHostFactory(packageRoot, host) {
9780
9700
  const description = lookupHostDescription(host);
9781
9701
  if (description === void 0) {
9782
9702
  throw new Error(`unregistered host: ${host}`);
9783
9703
  }
9784
- const built = join19(packageRoot, "dist/acp-host/production-host.js");
9785
- const source = join19(packageRoot, "src/acp-host/production-host.ts");
9704
+ const built = join18(packageRoot, "dist/acp-host/production-host.js");
9705
+ const source = join18(packageRoot, "src/acp-host/production-host.ts");
9786
9706
  const target = existsSync7(built) ? built : source;
9787
9707
  const href = pathToFileURL(target).href;
9788
9708
  const mod = await import(href);
@@ -9798,15 +9718,15 @@ var init_load_production_acp_host = __esm({
9798
9718
 
9799
9719
  // src/public-cli/load-production-headless-host.ts
9800
9720
  import { existsSync as existsSync8 } from "node:fs";
9801
- import { join as join20 } from "node:path";
9721
+ import { join as join19 } from "node:path";
9802
9722
  import { pathToFileURL as pathToFileURL2 } from "node:url";
9803
9723
  async function loadProductionHeadlessHostFactory(packageRoot, host) {
9804
9724
  const description = lookupHeadlessHostDescription(host);
9805
9725
  if (description === void 0) {
9806
9726
  throw new Error(`unregistered headless host: ${host}`);
9807
9727
  }
9808
- const built = join20(packageRoot, "dist/headless-host/production-host.js");
9809
- const source = join20(packageRoot, "src/headless-host/production-host.ts");
9728
+ const built = join19(packageRoot, "dist/headless-host/production-host.js");
9729
+ const source = join19(packageRoot, "src/headless-host/production-host.ts");
9810
9730
  const target = existsSync8(built) ? built : source;
9811
9731
  const href = pathToFileURL2(target).href;
9812
9732
  const mod = await import(href);
@@ -10055,8 +9975,8 @@ __export(config_exports, {
10055
9975
  setPersistentSeatHost: () => setPersistentSeatHost,
10056
9976
  validatePublicCliConfigAxes: () => validatePublicCliConfigAxes
10057
9977
  });
10058
- import { mkdir, readFile as readFile12, writeFile as writeFile7 } from "node:fs/promises";
10059
- import { dirname as dirname11, join as join21 } from "node:path";
9978
+ import { mkdir, readFile as readFile11, writeFile as writeFile6 } from "node:fs/promises";
9979
+ import { dirname as dirname10, join as join20 } from "node:path";
10060
9980
  function isGateOfficerSeat(value) {
10061
9981
  return GATE_OFFICER_SEATS.includes(value);
10062
9982
  }
@@ -10064,12 +9984,12 @@ function publicCliConfigPath(home) {
10064
9984
  if (typeof home !== "string" || home.trim() === "") {
10065
9985
  throw new Error("home must be explicitly provided");
10066
9986
  }
10067
- return join21(home, ".ak-roles", "public-cli.json");
9987
+ return join20(home, ".ak-roles", "public-cli.json");
10068
9988
  }
10069
9989
  async function loadPublicCliConfig(home) {
10070
9990
  const path = publicCliConfigPath(home);
10071
9991
  try {
10072
- const raw = await readFile12(path, "utf8");
9992
+ const raw = await readFile11(path, "utf8");
10073
9993
  return parsePublicCliConfig(JSON.parse(raw));
10074
9994
  } catch (error) {
10075
9995
  if (error instanceof Error && "code" in error && error.code === "ENOENT") {
@@ -10080,9 +10000,9 @@ async function loadPublicCliConfig(home) {
10080
10000
  }
10081
10001
  async function savePublicCliConfig(config, home) {
10082
10002
  const path = publicCliConfigPath(home);
10083
- await mkdir(dirname11(path), { recursive: true });
10003
+ await mkdir(dirname10(path), { recursive: true });
10084
10004
  const normalized = parsePublicCliConfig(config);
10085
- await writeFile7(
10005
+ await writeFile6(
10086
10006
  path,
10087
10007
  `${JSON.stringify(serializePublicCliConfig(normalized), null, 2)}
10088
10008
  `,
@@ -10527,7 +10447,7 @@ function credentialProvidersFromAuthData(data) {
10527
10447
  }
10528
10448
  async function loadCredentialProviders(agentDir) {
10529
10449
  try {
10530
- const raw = await readFile12(join21(agentDir, "auth.json"), "utf8");
10450
+ const raw = await readFile11(join20(agentDir, "auth.json"), "utf8");
10531
10451
  return credentialProvidersFromAuthData(JSON.parse(raw));
10532
10452
  } catch (error) {
10533
10453
  if (error instanceof Error && "code" in error && error.code === "ENOENT") {
@@ -10566,15 +10486,15 @@ __export(host_providers_exports, {
10566
10486
  renderHostProvidersTable: () => renderHostProvidersTable
10567
10487
  });
10568
10488
  import { readFileSync as readFileSync3 } from "node:fs";
10569
- import { join as join22 } from "node:path";
10489
+ import { join as join21 } from "node:path";
10570
10490
  function hostProvidersPath(home) {
10571
10491
  if (typeof home !== "string" || home.trim() === "") {
10572
10492
  throw new Error("home must be explicitly provided");
10573
10493
  }
10574
- return join22(home, ".ak-roles", "host-providers.json");
10494
+ return join21(home, ".ak-roles", "host-providers.json");
10575
10495
  }
10576
10496
  function hermesProviderModelsCachePath(home) {
10577
- return join22(home, ".hermes", "provider_models_cache.json");
10497
+ return join21(home, ".hermes", "provider_models_cache.json");
10578
10498
  }
10579
10499
  function parseHostProvidersTable(value) {
10580
10500
  if (value === null || typeof value !== "object" || Array.isArray(value)) {
@@ -10729,12 +10649,12 @@ var init_host_providers = __esm({
10729
10649
  });
10730
10650
 
10731
10651
  // src/ledger-session-read.ts
10732
- import { readFile as readFile13 } from "node:fs/promises";
10652
+ import { readFile as readFile12 } from "node:fs/promises";
10733
10653
  function isRecord5(value) {
10734
10654
  return typeof value === "object" && value !== null && !Array.isArray(value);
10735
10655
  }
10736
10656
  async function readLedgerSessionJsonlLines(path) {
10737
- const text = await readFile13(path, "utf8");
10657
+ const text = await readFile12(path, "utf8");
10738
10658
  const lines = text.split("\n");
10739
10659
  const out = [];
10740
10660
  for (let index = 0; index < lines.length; index += 1) {
@@ -10833,7 +10753,7 @@ var init_ledger_session_read = __esm({
10833
10753
 
10834
10754
  // src/analyst-gate-cycles-read.ts
10835
10755
  import { readdir as readdir5 } from "node:fs/promises";
10836
- import { join as join23 } from "node:path";
10756
+ import { join as join22 } from "node:path";
10837
10757
  function isRecord6(value) {
10838
10758
  return typeof value === "object" && value !== null && !Array.isArray(value);
10839
10759
  }
@@ -11083,7 +11003,7 @@ async function readAnalystGateCyclesFromAuditorRoles(auditorRolesDirectory, opti
11083
11003
  throw error;
11084
11004
  }
11085
11005
  for (const name of names) {
11086
- const path = join23(directory, name);
11006
+ const path = join22(directory, name);
11087
11007
  const fromPointer = name.endsWith(".pointer.json");
11088
11008
  const sessionPath = fromPointer ? await resolveOfficerSessionFromPointerFile(path) : path;
11089
11009
  if (sessionPath === void 0) continue;
@@ -11222,7 +11142,7 @@ var init_audit_escalation = __esm({
11222
11142
  });
11223
11143
 
11224
11144
  // src/run-terminal-artifacts.ts
11225
- import { basename as basename7, dirname as dirname12, join as join24 } from "node:path";
11145
+ import { basename as basename7, dirname as dirname11, join as join23 } from "node:path";
11226
11146
  function runIdFromRunDirectory(runDirectory) {
11227
11147
  const name = basename7(runDirectory);
11228
11148
  const at = name.lastIndexOf("@");
@@ -11237,7 +11157,7 @@ var init_run_terminal_artifacts = __esm({
11237
11157
  });
11238
11158
 
11239
11159
  // src/submission-ledger.ts
11240
- import { join as join25 } from "node:path";
11160
+ import { join as join24 } from "node:path";
11241
11161
  function runIdentity(context) {
11242
11162
  const directory = runDirectoryFromHostContext(context);
11243
11163
  if (directory !== void 0) {
@@ -11259,7 +11179,7 @@ async function submissionRecordFile(cwd, runId, scope) {
11259
11179
  if (sessionParent === void 0) {
11260
11180
  const discoveredRun = await findRunDirectoryById(scope.home, runId);
11261
11181
  if (discoveredRun === void 0) return void 0;
11262
- sessionParent = join25(discoveredRun, "session", "session.jsonl");
11182
+ sessionParent = join24(discoveredRun, "session", "session.jsonl");
11263
11183
  }
11264
11184
  return resolveSitianRecordPathInLedger({
11265
11185
  level: "event",
@@ -11464,13 +11384,13 @@ function createSubmissionLedgerHost(host, outputTools, failInfrastructure2 = (er
11464
11384
  const sessionParentFromContext = (context) => {
11465
11385
  const runDirectory = runDirectoryFromHostContext(context);
11466
11386
  if (runDirectory !== void 0) {
11467
- return join25(runDirectory, "session", "session.jsonl");
11387
+ return join24(runDirectory, "session", "session.jsonl");
11468
11388
  }
11469
11389
  const sessionFile = context.sessionManager.getSessionFile?.();
11470
11390
  if (typeof sessionFile === "string" && sessionFile.length > 0) return sessionFile;
11471
11391
  const sessionDir = context.sessionManager.getSessionDir?.();
11472
11392
  if (typeof sessionDir === "string" && sessionDir.length > 0) {
11473
- return join25(sessionDir, "session.jsonl");
11393
+ return join24(sessionDir, "session.jsonl");
11474
11394
  }
11475
11395
  return void 0;
11476
11396
  };
@@ -11632,23 +11552,23 @@ var init_submission_ledger = __esm({
11632
11552
 
11633
11553
  // src/session-opening-materials.ts
11634
11554
  import { existsSync as existsSync9 } from "node:fs";
11635
- import { readFile as readFile14 } from "node:fs/promises";
11636
- import { dirname as dirname13, join as join26 } from "node:path";
11555
+ import { readFile as readFile13 } from "node:fs/promises";
11556
+ import { dirname as dirname12, join as join25 } from "node:path";
11637
11557
  import { fileURLToPath, pathToFileURL as pathToFileURL3 } from "node:url";
11638
11558
  function resolvePackageRootDir(moduleUrl = import.meta.url) {
11639
- let dir = dirname13(fileURLToPath(moduleUrl));
11559
+ let dir = dirname12(fileURLToPath(moduleUrl));
11640
11560
  for (let i = 0; i < 8; i += 1) {
11641
- if (existsSync9(join26(dir, "package.json")) && existsSync9(join26(dir, "souls"))) {
11561
+ if (existsSync9(join25(dir, "package.json")) && existsSync9(join25(dir, "souls"))) {
11642
11562
  return dir;
11643
11563
  }
11644
- const parent = dirname13(dir);
11564
+ const parent = dirname12(dir);
11645
11565
  if (parent === dir) break;
11646
11566
  dir = parent;
11647
11567
  }
11648
11568
  return fileURLToPath(new URL("..", moduleUrl));
11649
11569
  }
11650
11570
  async function readPackageMaterial(relativePath) {
11651
- return readFile14(fileURLToPath(new URL(relativePath, packageRootUrl)), "utf8");
11571
+ return readFile13(fileURLToPath(new URL(relativePath, packageRootUrl)), "utf8");
11652
11572
  }
11653
11573
  async function joinPackageMaterials(relativePaths) {
11654
11574
  const chunks = [];
@@ -12232,13 +12152,13 @@ var init_reviewer_dispatch = __esm({
12232
12152
  });
12233
12153
 
12234
12154
  // src/public-cli/reviewer-dispatch-rejection.ts
12235
- import { readFile as readFile15, unlink as unlink3 } from "node:fs/promises";
12236
- import { join as join27 } from "node:path";
12155
+ import { readFile as readFile14, unlink as unlink3 } from "node:fs/promises";
12156
+ import { join as join26 } from "node:path";
12237
12157
  function isReviewerPreflightViolation(value) {
12238
12158
  return typeof value === "string" && REVIEWER_PREFLIGHT_VIOLATIONS.includes(value);
12239
12159
  }
12240
12160
  function reviewerDispatchRejectionPath(runDirectory) {
12241
- return join27(runDirectory, REVIEWER_DISPATCH_REJECTION_FILE);
12161
+ return join26(runDirectory, REVIEWER_DISPATCH_REJECTION_FILE);
12242
12162
  }
12243
12163
  async function clearReviewerDispatchRejection(runDirectory) {
12244
12164
  try {
@@ -12253,7 +12173,7 @@ async function clearReviewerDispatchRejection(runDirectory) {
12253
12173
  async function readReviewerDispatchRejection(runDirectory) {
12254
12174
  let raw;
12255
12175
  try {
12256
- raw = await readFile15(reviewerDispatchRejectionPath(runDirectory), "utf8");
12176
+ raw = await readFile14(reviewerDispatchRejectionPath(runDirectory), "utf8");
12257
12177
  } catch (error) {
12258
12178
  if (error instanceof Error && "code" in error && error.code === "ENOENT") {
12259
12179
  return void 0;
@@ -13447,9 +13367,9 @@ var init_collector_ledger = __esm({
13447
13367
  });
13448
13368
 
13449
13369
  // src/engine-detour-usage.ts
13450
- import { randomUUID as randomUUID4 } from "node:crypto";
13370
+ import { randomUUID as randomUUID3 } from "node:crypto";
13451
13371
  import { readFileSync as readFileSync4 } from "node:fs";
13452
- import { dirname as dirname14, join as join28 } from "node:path";
13372
+ import { dirname as dirname13, join as join27 } from "node:path";
13453
13373
  function engineDetourStdoutByteLength(stdout) {
13454
13374
  return Buffer.byteLength(stdout, "utf8");
13455
13375
  }
@@ -13585,7 +13505,7 @@ function projectEngineDetourToolUsageForPublicTerminal(usage, options) {
13585
13505
  function readInvocationRecord(runDirectory) {
13586
13506
  try {
13587
13507
  const raw = JSON.parse(
13588
- readFileSync4(join28(runDirectory, "invocation.json"), "utf8")
13508
+ readFileSync4(join27(runDirectory, "invocation.json"), "utf8")
13589
13509
  );
13590
13510
  return isRecord8(raw) ? raw : void 0;
13591
13511
  } catch (error) {
@@ -13615,15 +13535,15 @@ function withEngineDetourToolUsageFact(outcome, usage) {
13615
13535
  };
13616
13536
  }
13617
13537
  function runDirectoryFromSessionDirectory(sessionDirectory) {
13618
- return dirname14(sessionDirectory);
13538
+ return dirname13(sessionDirectory);
13619
13539
  }
13620
13540
  function sessionFileFromSessionDirectory(sessionDirectory) {
13621
- return join28(sessionDirectory, "session.jsonl");
13541
+ return join27(sessionDirectory, "session.jsonl");
13622
13542
  }
13623
13543
  function mintEngineDetourInvocationScope(input) {
13624
13544
  const engine = input.effectiveEngine?.trim();
13625
13545
  if (engine === void 0 || engine.length === 0) return void 0;
13626
- return randomUUID4();
13546
+ return randomUUID3();
13627
13547
  }
13628
13548
  function withEngineDetourInvocationScope(request, invocationScopeId) {
13629
13549
  if (invocationScopeId === void 0 || invocationScopeId.length === 0) {
@@ -13648,8 +13568,8 @@ var init_engine_detour_usage = __esm({
13648
13568
 
13649
13569
  // src/package-resources/method-skill.ts
13650
13570
  import { createHash as createHash7 } from "node:crypto";
13651
- import { readFile as readFile16, realpath as realpath6 } from "node:fs/promises";
13652
- import { join as join29 } from "node:path";
13571
+ import { readFile as readFile15, realpath as realpath6 } from "node:fs/promises";
13572
+ import { join as join28 } from "node:path";
13653
13573
  function gitBlobOid(bytes) {
13654
13574
  const body = typeof bytes === "string" ? Buffer.from(bytes, "utf8") : Buffer.from(bytes);
13655
13575
  const header = Buffer.from(`blob ${body.byteLength}\0`, "utf8");
@@ -13666,10 +13586,10 @@ function packagedMethodSkillRelativeDirectory(name) {
13666
13586
  return `${METHOD_SKILL_RELATIVE_ROOT}/${name}`;
13667
13587
  }
13668
13588
  function resolvePackagedMethodSkillRoot(packageRoot, name) {
13669
- return join29(packageRoot, packagedMethodSkillRelativeDirectory(name));
13589
+ return join28(packageRoot, packagedMethodSkillRelativeDirectory(name));
13670
13590
  }
13671
13591
  function resolvePackagedMethodSkillPath(packageRoot, name) {
13672
- return join29(resolvePackagedMethodSkillRoot(packageRoot, name), "SKILL.md");
13592
+ return join28(resolvePackagedMethodSkillRoot(packageRoot, name), "SKILL.md");
13673
13593
  }
13674
13594
  function isRecord9(value) {
13675
13595
  return typeof value === "object" && value !== null && !Array.isArray(value);
@@ -13763,11 +13683,11 @@ function parseProvenance(raw, expectedName) {
13763
13683
  }
13764
13684
  async function loadPackagedMethodSkillMaterial(packageRoot, name) {
13765
13685
  const rootDirectory = resolvePackagedMethodSkillRoot(packageRoot, name);
13766
- const skillPathConfigured = join29(rootDirectory, "SKILL.md");
13767
- const provenancePath = join29(rootDirectory, "provenance.json");
13686
+ const skillPathConfigured = join28(rootDirectory, "SKILL.md");
13687
+ const provenancePath = join28(rootDirectory, "provenance.json");
13768
13688
  let provenanceRaw;
13769
13689
  try {
13770
- provenanceRaw = await readFile16(provenancePath, "utf8");
13690
+ provenanceRaw = await readFile15(provenancePath, "utf8");
13771
13691
  } catch (error) {
13772
13692
  throw new PackagedMethodSkillUnavailableError(name, provenancePath, error);
13773
13693
  }
@@ -13781,10 +13701,10 @@ async function loadPackagedMethodSkillMaterial(packageRoot, name) {
13781
13701
  }
13782
13702
  const provenance = parseProvenance(provenanceJson, name);
13783
13703
  for (const [rel, expected] of Object.entries(provenance.files)) {
13784
- const absolute = join29(rootDirectory, rel);
13704
+ const absolute = join28(rootDirectory, rel);
13785
13705
  let bytes;
13786
13706
  try {
13787
- bytes = await readFile16(absolute);
13707
+ bytes = await readFile15(absolute);
13788
13708
  } catch (error) {
13789
13709
  throw new PackagedMethodSkillUnavailableError(name, absolute, error);
13790
13710
  }
@@ -13800,7 +13720,7 @@ async function loadPackagedMethodSkillMaterial(packageRoot, name) {
13800
13720
  let raw;
13801
13721
  try {
13802
13722
  skillPath = await realpath6(skillPathConfigured);
13803
- raw = await readFile16(skillPath, "utf8");
13723
+ raw = await readFile15(skillPath, "utf8");
13804
13724
  } catch (error) {
13805
13725
  throw new PackagedMethodSkillUnavailableError(name, skillPathConfigured, error);
13806
13726
  }
@@ -14389,16 +14309,16 @@ __export(settlement_exports, {
14389
14309
  trySettleReviewerTerminalResult: () => trySettleReviewerTerminalResult,
14390
14310
  withSubmissions: () => withSubmissions
14391
14311
  });
14392
- import { randomUUID as randomUUID5 } from "node:crypto";
14393
- import { appendFile as appendFile2, readFile as readFile17, readdir as readdir6, writeFile as writeFile8 } from "node:fs/promises";
14394
- import { dirname as dirname15, join as join30 } from "node:path";
14312
+ import { randomUUID as randomUUID4 } from "node:crypto";
14313
+ import { appendFile as appendFile2, readFile as readFile16, readdir as readdir6, writeFile as writeFile7 } from "node:fs/promises";
14314
+ import { dirname as dirname14, join as join29 } from "node:path";
14395
14315
  function sealedLedgerHome(admitted) {
14396
14316
  return homeFromRunDirectory(admitted.runDirectory);
14397
14317
  }
14398
14318
  function ledgerReadScope(admitted, scope) {
14399
14319
  return {
14400
14320
  home: sealedLedgerHome(admitted),
14401
- sessionParent: join30(admitted.runDirectory, "session", "session.jsonl"),
14321
+ sessionParent: join29(admitted.runDirectory, "session", "session.jsonl"),
14402
14322
  ...scope?.courtAttemptId === void 0 || scope.courtAttemptId.length === 0 ? {} : { attemptId: scope.courtAttemptId }
14403
14323
  };
14404
14324
  }
@@ -14534,7 +14454,7 @@ function presentControlledFailure(failure2, io) {
14534
14454
  }
14535
14455
  async function inspectJudgeSession(sessionFile) {
14536
14456
  try {
14537
- await readFile17(sessionFile, "utf8");
14457
+ await readFile16(sessionFile, "utf8");
14538
14458
  return { state: "present" };
14539
14459
  } catch (error) {
14540
14460
  if (isMissingPathError3(error)) return { state: "missing" };
@@ -14766,7 +14686,7 @@ function sessionReadFailure(error, fallbackMessage) {
14766
14686
  return failed;
14767
14687
  }
14768
14688
  async function readBoundSessionEntries(sessionFile) {
14769
- const text = await readFile17(sessionFile, "utf8");
14689
+ const text = await readFile16(sessionFile, "utf8");
14770
14690
  const entries = [];
14771
14691
  for (const line2 of text.trim().split("\n").filter(Boolean)) {
14772
14692
  try {
@@ -14827,7 +14747,7 @@ async function readSitianRetainedAuditorProviderStop(sessionFile) {
14827
14747
  kind: "auditor",
14828
14748
  sessionParent: sessionFile,
14829
14749
  // Path is driven by sessionParent when under ledger home; cwd is a fallback only.
14830
- cwd: dirname15(sessionFile)
14750
+ cwd: dirname14(sessionFile)
14831
14751
  });
14832
14752
  const { records } = await readSitianRecords(recordFile);
14833
14753
  for (let i = records.length - 1; i >= 0; i -= 1) {
@@ -14853,7 +14773,7 @@ async function readSessionProviderStop(sessionFile) {
14853
14773
  }
14854
14774
  }
14855
14775
  async function readBoundEvidenceChildKnownFailure(sessionFile) {
14856
- const childDirectory = join30(dirname15(sessionFile), "evidence-children");
14776
+ const childDirectory = join29(dirname14(sessionFile), "evidence-children");
14857
14777
  let names;
14858
14778
  try {
14859
14779
  names = await readdir6(childDirectory);
@@ -14864,7 +14784,7 @@ async function readBoundEvidenceChildKnownFailure(sessionFile) {
14864
14784
  for (const file of names.filter((name) => name.endsWith(".jsonl")).sort().reverse()) {
14865
14785
  let entries;
14866
14786
  try {
14867
- entries = await readBoundSessionEntries(join30(childDirectory, file));
14787
+ entries = await readBoundSessionEntries(join29(childDirectory, file));
14868
14788
  } catch (error) {
14869
14789
  throw sessionReadFailure(error, "failed to read discovered evidence-child session");
14870
14790
  }
@@ -14919,7 +14839,7 @@ async function loadBoundAuditorVolumes(sessionFile) {
14919
14839
  latestParentUserIndex = i;
14920
14840
  break;
14921
14841
  }
14922
- const childDirectories = [join30(dirname15(sessionFile), "auditor-roles")];
14842
+ const childDirectories = [join29(dirname14(sessionFile), "auditor-roles")];
14923
14843
  const valid = [];
14924
14844
  let sawAnyDirectory = false;
14925
14845
  for (const childDirectory of childDirectories) {
@@ -14934,7 +14854,7 @@ async function loadBoundAuditorVolumes(sessionFile) {
14934
14854
  for (const file of names.filter((name) => name.endsWith(".jsonl")).sort().reverse()) {
14935
14855
  let entries;
14936
14856
  try {
14937
- entries = await readBoundSessionEntries(join30(childDirectory, file));
14857
+ entries = await readBoundSessionEntries(join29(childDirectory, file));
14938
14858
  } catch (error) {
14939
14859
  throw sessionReadFailure(error, "failed to read discovered auditor session");
14940
14860
  }
@@ -15353,7 +15273,7 @@ async function appendRunAttemptHistory(source, outcome) {
15353
15273
  type: "custom",
15354
15274
  customType: ATTEMPT_HISTORY_ENTRY_TYPE,
15355
15275
  data: attemptData,
15356
- id: randomUUID5(),
15276
+ id: randomUUID4(),
15357
15277
  parentId,
15358
15278
  timestamp: timestamp2
15359
15279
  })}
@@ -15459,8 +15379,8 @@ function projectTerminalGateFact(rounds) {
15459
15379
  };
15460
15380
  }
15461
15381
  async function extractGateFactFromSessionDirectory(sessionDirectory, options = {}) {
15462
- const directories = [join30(sessionDirectory, "auditor-roles")];
15463
- const parentSessionFile = options.parentSessionFile ?? join30(sessionDirectory, "session.jsonl");
15382
+ const directories = [join29(sessionDirectory, "auditor-roles")];
15383
+ const parentSessionFile = options.parentSessionFile ?? join29(sessionDirectory, "session.jsonl");
15464
15384
  const rounds = await readAnalystGateCyclesFromAuditorRoles(directories, {
15465
15385
  parentSessionFile
15466
15386
  });
@@ -15590,9 +15510,9 @@ async function extractNavigatorFactFromAdmittedSession(sessionFile) {
15590
15510
  async function publishJudgeArtifacts(admitted, roleOutcome, coordinates) {
15591
15511
  await appendRunAttemptHistory({ role: admitted.role, runId: admitted.runId, sessionFile: coordinates.sessionFile }, roleOutcome);
15592
15512
  const artifactsDir = await ensureRunArtifactsDir(admitted.runDirectory);
15593
- const reportPath = join30(artifactsDir, "report.json");
15594
- const evidencePath = join30(artifactsDir, "evidence.json");
15595
- await writeFile8(
15513
+ const reportPath = join29(artifactsDir, "report.json");
15514
+ const evidencePath = join29(artifactsDir, "evidence.json");
15515
+ await writeFile7(
15596
15516
  reportPath,
15597
15517
  `${JSON.stringify(
15598
15518
  {
@@ -15606,7 +15526,7 @@ async function publishJudgeArtifacts(admitted, roleOutcome, coordinates) {
15606
15526
  `,
15607
15527
  "utf8"
15608
15528
  );
15609
- await writeFile8(
15529
+ await writeFile7(
15610
15530
  evidencePath,
15611
15531
  `${JSON.stringify(
15612
15532
  {
@@ -15635,9 +15555,9 @@ async function publishJudgeArtifacts(admitted, roleOutcome, coordinates) {
15635
15555
  async function publishCoderArtifacts(admitted, roleOutcome, coordinates, options = {}) {
15636
15556
  await appendRunAttemptHistory({ role: admitted.role, runId: admitted.runId, sessionFile: coordinates.sessionFile }, roleOutcome);
15637
15557
  const artifactsDir = await ensureRunArtifactsDir(admitted.runDirectory);
15638
- const reportPath = join30(artifactsDir, "report.json");
15639
- const evidencePath = join30(artifactsDir, "evidence.json");
15640
- await writeFile8(
15558
+ const reportPath = join29(artifactsDir, "report.json");
15559
+ const evidencePath = join29(artifactsDir, "evidence.json");
15560
+ await writeFile7(
15641
15561
  reportPath,
15642
15562
  `${JSON.stringify(
15643
15563
  {
@@ -15652,7 +15572,7 @@ async function publishCoderArtifacts(admitted, roleOutcome, coordinates, options
15652
15572
  `,
15653
15573
  "utf8"
15654
15574
  );
15655
- await writeFile8(
15575
+ await writeFile7(
15656
15576
  evidencePath,
15657
15577
  `${JSON.stringify(
15658
15578
  {
@@ -15793,9 +15713,9 @@ function extractFixerMethodInvocations(entries, options) {
15793
15713
  async function publishFixerArtifacts(admitted, roleOutcome, coordinates, options) {
15794
15714
  await appendRunAttemptHistory({ role: admitted.role, runId: admitted.runId, sessionFile: coordinates.sessionFile }, roleOutcome);
15795
15715
  const artifactsDir = await ensureRunArtifactsDir(admitted.runDirectory);
15796
- const reportPath = join30(artifactsDir, "report.json");
15797
- const evidencePath = join30(artifactsDir, "evidence.json");
15798
- await writeFile8(
15716
+ const reportPath = join29(artifactsDir, "report.json");
15717
+ const evidencePath = join29(artifactsDir, "evidence.json");
15718
+ await writeFile7(
15799
15719
  reportPath,
15800
15720
  `${JSON.stringify(
15801
15721
  {
@@ -15810,7 +15730,7 @@ async function publishFixerArtifacts(admitted, roleOutcome, coordinates, options
15810
15730
  `,
15811
15731
  "utf8"
15812
15732
  );
15813
- await writeFile8(
15733
+ await writeFile7(
15814
15734
  evidencePath,
15815
15735
  `${JSON.stringify(
15816
15736
  {
@@ -15891,9 +15811,9 @@ async function settleFixerTerminalResult(admitted, authority, options, scope) {
15891
15811
  async function publishCollectorArtifacts(admitted, roleOutcome, coordinates) {
15892
15812
  await appendRunAttemptHistory({ role: admitted.role, runId: admitted.runId, sessionFile: coordinates.sessionFile }, roleOutcome);
15893
15813
  const artifactsDir = await ensureRunArtifactsDir(admitted.runDirectory);
15894
- const reportPath = join30(artifactsDir, "report.json");
15895
- const evidencePath = join30(artifactsDir, "evidence.json");
15896
- await writeFile8(
15814
+ const reportPath = join29(artifactsDir, "report.json");
15815
+ const evidencePath = join29(artifactsDir, "evidence.json");
15816
+ await writeFile7(
15897
15817
  reportPath,
15898
15818
  `${JSON.stringify(
15899
15819
  {
@@ -15907,7 +15827,7 @@ async function publishCollectorArtifacts(admitted, roleOutcome, coordinates) {
15907
15827
  `,
15908
15828
  "utf8"
15909
15829
  );
15910
- await writeFile8(
15830
+ await writeFile7(
15911
15831
  evidencePath,
15912
15832
  `${JSON.stringify(
15913
15833
  {
@@ -16024,9 +15944,9 @@ function extractDoctorCandidateAuditNoReceiptFact(entries) {
16024
15944
  async function publishDoctorArtifacts(admitted, roleOutcome, coordinates, options = {}) {
16025
15945
  await appendRunAttemptHistory({ role: admitted.role, runId: admitted.runId, sessionFile: coordinates.sessionFile }, roleOutcome);
16026
15946
  const artifactsDir = await ensureRunArtifactsDir(admitted.runDirectory);
16027
- const reportPath = join30(artifactsDir, "report.json");
16028
- const evidencePath = join30(artifactsDir, "evidence.json");
16029
- await writeFile8(
15947
+ const reportPath = join29(artifactsDir, "report.json");
15948
+ const evidencePath = join29(artifactsDir, "evidence.json");
15949
+ await writeFile7(
16030
15950
  reportPath,
16031
15951
  `${JSON.stringify(
16032
15952
  {
@@ -16042,7 +15962,7 @@ async function publishDoctorArtifacts(admitted, roleOutcome, coordinates, option
16042
15962
  `,
16043
15963
  "utf8"
16044
15964
  );
16045
- await writeFile8(
15965
+ await writeFile7(
16046
15966
  evidencePath,
16047
15967
  `${JSON.stringify(
16048
15968
  {
@@ -16320,9 +16240,9 @@ function extractReviewerMethodInvocations(entries, options) {
16320
16240
  async function publishReviewerArtifacts(admitted, roleOutcome, coordinates, options) {
16321
16241
  await appendRunAttemptHistory({ role: admitted.role, runId: admitted.runId, sessionFile: coordinates.sessionFile }, roleOutcome);
16322
16242
  const artifactsDir = await ensureRunArtifactsDir(admitted.runDirectory);
16323
- const reportPath = join30(artifactsDir, "report.json");
16324
- const evidencePath = join30(artifactsDir, "evidence.json");
16325
- await writeFile8(
16243
+ const reportPath = join29(artifactsDir, "report.json");
16244
+ const evidencePath = join29(artifactsDir, "evidence.json");
16245
+ await writeFile7(
16326
16246
  reportPath,
16327
16247
  `${JSON.stringify(
16328
16248
  {
@@ -16336,7 +16256,7 @@ async function publishReviewerArtifacts(admitted, roleOutcome, coordinates, opti
16336
16256
  `,
16337
16257
  "utf8"
16338
16258
  );
16339
- await writeFile8(
16259
+ await writeFile7(
16340
16260
  evidencePath,
16341
16261
  `${JSON.stringify(
16342
16262
  {
@@ -16435,9 +16355,9 @@ function extractMergerMethodInvocations(entries, options) {
16435
16355
  async function publishMergerArtifacts(admitted, roleOutcome, coordinates, options) {
16436
16356
  await appendRunAttemptHistory({ role: admitted.role, runId: admitted.runId, sessionFile: coordinates.sessionFile }, roleOutcome);
16437
16357
  const artifactsDir = await ensureRunArtifactsDir(admitted.runDirectory);
16438
- const reportPath = join30(artifactsDir, "report.json");
16439
- const evidencePath = join30(artifactsDir, "evidence.json");
16440
- await writeFile8(
16358
+ const reportPath = join29(artifactsDir, "report.json");
16359
+ const evidencePath = join29(artifactsDir, "evidence.json");
16360
+ await writeFile7(
16441
16361
  reportPath,
16442
16362
  `${JSON.stringify(
16443
16363
  {
@@ -16451,7 +16371,7 @@ async function publishMergerArtifacts(admitted, roleOutcome, coordinates, option
16451
16371
  `,
16452
16372
  "utf8"
16453
16373
  );
16454
- await writeFile8(
16374
+ await writeFile7(
16455
16375
  evidencePath,
16456
16376
  `${JSON.stringify(
16457
16377
  {
@@ -16570,7 +16490,7 @@ function publicationAttemptFromError(path, error) {
16570
16490
  }
16571
16491
  function uniqueFailureFallbackDirs(runDirectory, baseDir) {
16572
16492
  const dirs = [];
16573
- for (const dir of [baseDir, runDirectory, dirname15(runDirectory)]) {
16493
+ for (const dir of [baseDir, runDirectory, dirname14(runDirectory)]) {
16574
16494
  if (!dirs.includes(dir)) dirs.push(dir);
16575
16495
  }
16576
16496
  return dirs;
@@ -16592,13 +16512,13 @@ async function writeFailureJsonRetainingCause(preferredCandidates, uniqueFallbac
16592
16512
  const candidates = [
16593
16513
  ...preferredCandidates,
16594
16514
  // One unique name per fallback dir — collisions on fixed names cannot exhaust this.
16595
- ...uniqueFallbackDirs.map((dir) => join30(dir, `${stem}.${randomUUID5()}.json`))
16515
+ ...uniqueFallbackDirs.map((dir) => join29(dir, `${stem}.${randomUUID4()}.json`))
16596
16516
  ];
16597
16517
  for (let i = 0; i < candidates.length; i += 1) {
16598
16518
  const path = candidates[i];
16599
16519
  const payload = issues.length === 0 ? basePayload : { ...basePayload, publicationIssues: issues };
16600
16520
  try {
16601
- await writeFile8(
16521
+ await writeFile7(
16602
16522
  path,
16603
16523
  `${JSON.stringify(payload, null, 2)}
16604
16524
  `,
@@ -16643,20 +16563,20 @@ async function publishFailureArtifacts(admitted, failure2, authority) {
16643
16563
  baseDir
16644
16564
  );
16645
16565
  const errorCandidates = underArtifacts ? [
16646
- join30(baseDir, "error.json"),
16647
- join30(baseDir, "error.settlement.json"),
16648
- join30(admitted.runDirectory, "error.settlement.json")
16566
+ join29(baseDir, "error.json"),
16567
+ join29(baseDir, "error.settlement.json"),
16568
+ join29(admitted.runDirectory, "error.settlement.json")
16649
16569
  ] : [
16650
- join30(baseDir, "error.settlement.json"),
16651
- join30(baseDir, "error.json")
16570
+ join29(baseDir, "error.settlement.json"),
16571
+ join29(baseDir, "error.json")
16652
16572
  ];
16653
16573
  const evidenceCandidates = underArtifacts ? [
16654
- join30(baseDir, "evidence.json"),
16655
- join30(baseDir, "evidence.settlement.json"),
16656
- join30(admitted.runDirectory, "evidence.settlement.json")
16574
+ join29(baseDir, "evidence.json"),
16575
+ join29(baseDir, "evidence.settlement.json"),
16576
+ join29(admitted.runDirectory, "evidence.settlement.json")
16657
16577
  ] : [
16658
- join30(baseDir, "evidence.settlement.json"),
16659
- join30(baseDir, "evidence.json")
16578
+ join29(baseDir, "evidence.settlement.json"),
16579
+ join29(baseDir, "evidence.json")
16660
16580
  ];
16661
16581
  const errorPayloadBase = {
16662
16582
  kind: "error",
@@ -16944,17 +16864,17 @@ var init_seat_ticket_binding = __esm({
16944
16864
  });
16945
16865
 
16946
16866
  // src/session-identity.ts
16947
- import { mkdir as mkdir3, readFile as readFile18, rename as rename3, writeFile as writeFile9 } from "node:fs/promises";
16948
- import { dirname as dirname16, join as join31 } from "node:path";
16867
+ import { mkdir as mkdir3, readFile as readFile17, rename as rename2, writeFile as writeFile8 } from "node:fs/promises";
16868
+ import { dirname as dirname15, join as join30 } from "node:path";
16949
16869
  function createSessionIdentityAuthority(authority, sessionBindingFile) {
16950
- const bindingPath = (principal) => join31(authority.decode(principal).sessionDirectory, sessionBindingFile);
16870
+ const bindingPath = (principal) => join30(authority.decode(principal).sessionDirectory, sessionBindingFile);
16951
16871
  return {
16952
16872
  resolveSessionFile(principal) {
16953
16873
  return authority.decode(principal).sessionFile;
16954
16874
  },
16955
16875
  async load(principal) {
16956
16876
  try {
16957
- const value = JSON.parse(await readFile18(bindingPath(principal), "utf8"));
16877
+ const value = JSON.parse(await readFile17(bindingPath(principal), "utf8"));
16958
16878
  if (typeof value !== "object" || value === null || typeof value.sessionId !== "string") {
16959
16879
  throw new Error("durable session binding is invalid");
16960
16880
  }
@@ -16966,11 +16886,11 @@ function createSessionIdentityAuthority(authority, sessionBindingFile) {
16966
16886
  },
16967
16887
  async bind(principal, sessionId) {
16968
16888
  const target = bindingPath(principal);
16969
- await mkdir3(dirname16(target), { recursive: true });
16889
+ await mkdir3(dirname15(target), { recursive: true });
16970
16890
  const temporary = `${target}.${process.pid}.tmp`;
16971
- await writeFile9(temporary, `${JSON.stringify({ sessionId })}
16891
+ await writeFile8(temporary, `${JSON.stringify({ sessionId })}
16972
16892
  `, { encoding: "utf8", mode: 384 });
16973
- await rename3(temporary, target);
16893
+ await rename2(temporary, target);
16974
16894
  }
16975
16895
  };
16976
16896
  }
@@ -17058,6 +16978,23 @@ function fromQueueEvent(row) {
17058
16978
  const id = nativeEventId(row);
17059
16979
  return [{ speaker: "owner", text: content, ...id === void 0 ? {} : { id } }];
17060
16980
  }
16981
+ function hasFixedOpenTagPrefix(content, tag) {
16982
+ if (!content.startsWith(tag)) return false;
16983
+ const next = content.charAt(tag.length);
16984
+ return next === "" || next === ">" || next === " " || next === " " || next === "\n" || next === "\r";
16985
+ }
16986
+ function isFixedNonOwnerEnqueueShape(content) {
16987
+ return hasFixedOpenTagPrefix(content, TASK_NOTIFICATION_OPEN_TAG);
16988
+ }
16989
+ function materializationOriginKind(row) {
16990
+ if (!isRecord12(row.origin)) return void 0;
16991
+ const kind = row.origin.kind;
16992
+ return typeof kind === "string" && kind !== "" ? kind : void 0;
16993
+ }
16994
+ function isNonOwnerOriginKind(kind) {
16995
+ if (kind === void 0) return false;
16996
+ return kind !== "human";
16997
+ }
17061
16998
  function fromMessageEvent(row) {
17062
16999
  const message = messageBody(row);
17063
17000
  if (message === void 0) return [];
@@ -17074,78 +17011,45 @@ function fromMessageEvent(row) {
17074
17011
  const id = nativeEventId(row);
17075
17012
  return [{ speaker, text, ...id === void 0 ? {} : { id } }];
17076
17013
  }
17077
- function isOwnerDialogueMessage(row) {
17078
- if (row.type === "response_item" || row.type === "event_msg") return false;
17079
- return fromMessageEvent(row).some((event) => event.speaker === "owner");
17080
- }
17081
- function isRunnerMessage(row) {
17082
- const message = messageBody(row);
17083
- return message !== void 0 && message.role === "assistant";
17084
- }
17085
- function ownerMessagesMaterializingQueue(rows) {
17086
- const skip = /* @__PURE__ */ new Set();
17087
- const retainedByEnqueue = [];
17088
- let pendingSkips = 0;
17089
- for (let index = 0; index < rows.length; index += 1) {
17090
- const row = rows[index];
17091
- if (row === void 0) continue;
17092
- if (row.type === "queue-operation") {
17093
- if (row.operation === "enqueue") {
17094
- retainedByEnqueue.push(fromQueueEvent(row).length > 0);
17095
- continue;
17096
- }
17097
- if (row.operation === "dequeue" || row.operation === "remove") {
17098
- const retained = retainedByEnqueue.shift();
17099
- if (row.operation === "dequeue" && retained === true) {
17100
- pendingSkips += 1;
17101
- }
17102
- continue;
17103
- }
17104
- }
17105
- if (isRunnerMessage(row)) {
17106
- pendingSkips = 0;
17107
- continue;
17108
- }
17109
- if (pendingSkips > 0 && isOwnerDialogueMessage(row)) {
17110
- skip.add(index);
17111
- pendingSkips -= 1;
17112
- }
17113
- }
17114
- return skip;
17115
- }
17116
17014
  function adaptSessionDialogue(rows) {
17117
- const skipOwner = ownerMessagesMaterializingQueue(rows);
17118
- return rows.map((row, index) => {
17015
+ return rows.map((row) => {
17119
17016
  if (row === void 0) return [];
17017
+ const originKind = materializationOriginKind(row);
17018
+ if (isNonOwnerOriginKind(originKind)) return [];
17019
+ if (row.type === "queue-operation" && row.operation === "enqueue" && typeof row.content === "string" && isFixedNonOwnerEnqueueShape(row.content)) {
17020
+ return [];
17021
+ }
17120
17022
  const queued = fromQueueEvent(row);
17121
17023
  if (queued.length > 0) return queued;
17122
- if (skipOwner.has(index)) return [];
17123
17024
  return fromMessageEvent(row);
17124
17025
  });
17125
17026
  }
17126
- var SPEAKER_TEXT_PART_TYPES;
17027
+ var SPEAKER_TEXT_PART_TYPES, TASK_NOTIFICATION_OPEN_TAG;
17127
17028
  var init_session_dialogue = __esm({
17128
17029
  "src/session-dialogue.ts"() {
17129
17030
  "use strict";
17130
17031
  SPEAKER_TEXT_PART_TYPES = /* @__PURE__ */ new Set(["text", "input_text", "output_text"]);
17032
+ TASK_NOTIFICATION_OPEN_TAG = "<task-notification";
17131
17033
  }
17132
17034
  });
17133
17035
 
17134
17036
  // src/ticket-provenance.ts
17135
- import { basename as basename8, dirname as dirname17, join as join32, resolve as resolve12 } from "node:path";
17037
+ import { createHash as createHash8 } from "node:crypto";
17038
+ import { readFile as readFile18 } from "node:fs/promises";
17039
+ import { basename as basename8, dirname as dirname16, join as join31, resolve as resolve12 } from "node:path";
17136
17040
  function dialogueSessionSourceRoots(home) {
17137
17041
  const machineHome = typeof home === "string" && home.trim() !== "" ? home : packageMachineHome();
17138
17042
  return [
17139
- join32(machineHome, ".claude", "projects"),
17140
- join32(machineHome, ".codex", "sessions"),
17141
- join32(machineHome, ".pi", "agent", "sessions")
17043
+ join31(machineHome, ".claude", "projects"),
17044
+ join31(machineHome, ".codex", "sessions"),
17045
+ join31(machineHome, ".pi", "agent", "sessions")
17142
17046
  ];
17143
17047
  }
17144
17048
  function isLedgerRoleSessionFile(absolute, home) {
17145
17049
  const machineHome = typeof home === "string" && home.trim() !== "" ? home : packageMachineHome();
17146
17050
  const ledgerHome = resolveActivationLedgerHome(machineHome);
17147
17051
  if (!physicallyContainedIn(ledgerHome, absolute)) return false;
17148
- return basename8(absolute) === "session.jsonl" && basename8(dirname17(absolute)) === "session";
17052
+ return basename8(absolute) === "session.jsonl" && basename8(dirname16(absolute)) === "session";
17149
17053
  }
17150
17054
  function assertDialogueSessionSourcePath(path, home) {
17151
17055
  const absolute = resolve12(path);
@@ -17175,18 +17079,46 @@ function ticketProvenanceRecordInput(ticketNumber, cwd, home) {
17175
17079
  };
17176
17080
  }
17177
17081
  function resolveTicketProvenanceVolume(ticketNumber, cwd, home) {
17178
- return resolveSitianVolume(ticketProvenanceRecordInput(ticketNumber, cwd, home));
17179
- }
17180
- async function readTicketProvenance(ticketNumber, cwd, home) {
17181
- const { recordFile, text } = await readSitianVolumeText(
17082
+ const path = resolveSitianRecordPath(
17182
17083
  ticketProvenanceRecordInput(ticketNumber, cwd, home)
17183
17084
  );
17184
- if (text === void 0) {
17185
- return { header: void 0, lines: [], recordFile };
17085
+ return { recordFile: path.recordFile, volumeDir: path.sessionDir };
17086
+ }
17087
+ function projectTicketProvenanceCommit(value) {
17088
+ if (typeof value !== "object" || value === null || Array.isArray(value)) return void 0;
17089
+ const record4 = value;
17090
+ if (record4.kind !== TICKET_PROVENANCE_KIND || typeof record4.timestamp !== "string") {
17091
+ return void 0;
17092
+ }
17093
+ const payload = record4.payload;
17094
+ if (typeof payload !== "object" || payload === null || Array.isArray(payload)) return void 0;
17095
+ const body = payload;
17096
+ if (body.type !== "ticket-provenance-append") return void 0;
17097
+ const sessions = projectTicketProvenanceSessions(body.sessions);
17098
+ if (sessions === void 0 || !Array.isArray(body.lines)) return void 0;
17099
+ const lines = [];
17100
+ for (const raw of body.lines) {
17101
+ const line2 = projectTicketProvenanceLine(raw);
17102
+ if (line2 === void 0) return void 0;
17103
+ lines.push(line2);
17104
+ }
17105
+ return { timestamp: record4.timestamp, sessions, lines };
17106
+ }
17107
+ async function readTicketProvenance(ticketNumber, cwd, home) {
17108
+ const { recordFile } = resolveTicketProvenanceVolume(ticketNumber, cwd, home);
17109
+ let text;
17110
+ try {
17111
+ text = await readFile18(recordFile, "utf8");
17112
+ } catch (error) {
17113
+ if (error.code === "ENOENT") {
17114
+ return { header: void 0, lines: [], unprojectedRaw: [], recordFile };
17115
+ }
17116
+ throw error;
17186
17117
  }
17187
17118
  const physical = text.split("\n");
17188
17119
  let header;
17189
17120
  const lines = [];
17121
+ const unprojectedRaw = [];
17190
17122
  let sawFirst = false;
17191
17123
  for (let index = 0; index < physical.length; index += 1) {
17192
17124
  const raw = physical[index];
@@ -17195,6 +17127,7 @@ async function readTicketProvenance(ticketNumber, cwd, home) {
17195
17127
  try {
17196
17128
  parsed = JSON.parse(raw);
17197
17129
  } catch {
17130
+ unprojectedRaw.push(raw);
17198
17131
  continue;
17199
17132
  }
17200
17133
  if (!sawFirst) {
@@ -17203,9 +17136,35 @@ async function readTicketProvenance(ticketNumber, cwd, home) {
17203
17136
  if (header !== void 0) continue;
17204
17137
  }
17205
17138
  const line2 = projectTicketProvenanceLine(parsed);
17206
- if (line2 !== void 0) lines.push(line2);
17139
+ if (line2 !== void 0) {
17140
+ lines.push(line2);
17141
+ continue;
17142
+ }
17143
+ const commit = projectTicketProvenanceCommit(parsed);
17144
+ if (commit !== void 0) {
17145
+ const merged = mergeSessionBounds(header?.sessions, commit.sessions);
17146
+ const remapped = commit.lines.map((entry) => ({
17147
+ ...entry,
17148
+ s: merged.incomingIndexes[entry.s] ?? entry.s
17149
+ }));
17150
+ const now = commit.timestamp;
17151
+ header = {
17152
+ repo: header?.repo ?? resolveBookKeyFromGit(cwd),
17153
+ ticket: ticketNumber,
17154
+ createdAt: header?.createdAt ?? now,
17155
+ updatedAt: now,
17156
+ sessions: merged.sessions
17157
+ };
17158
+ const carried = lines.map((entry) => ({
17159
+ ...entry,
17160
+ s: merged.priorIndexes[entry.s] ?? entry.s
17161
+ }));
17162
+ lines.splice(0, lines.length, ...mergeFreshIntoCarried(carried, remapped));
17163
+ continue;
17164
+ }
17165
+ unprojectedRaw.push(raw);
17207
17166
  }
17208
- return { header, lines, recordFile };
17167
+ return { header, lines, unprojectedRaw, recordFile };
17209
17168
  }
17210
17169
  function resolveBoundIndex(bound, sessionLines) {
17211
17170
  if (typeof bound.id === "string" && bound.id !== "") {
@@ -17227,6 +17186,104 @@ function resolveBoundIndex(bound, sessionLines) {
17227
17186
  function amendmentKey(s, line2) {
17228
17187
  return `${s}:${line2}`;
17229
17188
  }
17189
+ function rangeDeclarationKey(range) {
17190
+ return JSON.stringify({
17191
+ from: range.from,
17192
+ to: range.to
17193
+ });
17194
+ }
17195
+ function mergeSessionBounds(prior, incoming) {
17196
+ const merged = [];
17197
+ const indexByIdentity = /* @__PURE__ */ new Map();
17198
+ const absorb = (sessions) => {
17199
+ const indexes = [];
17200
+ for (const session of sessions) {
17201
+ const identity = physicalPathIdentity(session.path);
17202
+ let targetIndex = indexByIdentity.get(identity);
17203
+ if (targetIndex === void 0) {
17204
+ targetIndex = merged.length;
17205
+ indexByIdentity.set(identity, targetIndex);
17206
+ merged.push({ path: session.path, ranges: [] });
17207
+ }
17208
+ indexes.push(targetIndex);
17209
+ const target = merged[targetIndex];
17210
+ const seen = new Set(target.ranges.map(rangeDeclarationKey));
17211
+ for (const range of session.ranges) {
17212
+ const key = rangeDeclarationKey(range);
17213
+ if (seen.has(key)) continue;
17214
+ seen.add(key);
17215
+ target.ranges.push({ from: { ...range.from }, to: { ...range.to } });
17216
+ }
17217
+ }
17218
+ return indexes;
17219
+ };
17220
+ const priorIndexes = absorb(prior ?? []);
17221
+ const incomingIndexes = absorb(incoming);
17222
+ return { sessions: merged, priorIndexes, incomingIndexes };
17223
+ }
17224
+ function undeclaredSessionRanges(prior, merged) {
17225
+ const priorKeys = /* @__PURE__ */ new Map();
17226
+ for (const session of prior ?? []) {
17227
+ const identity = physicalPathIdentity(session.path);
17228
+ let keys = priorKeys.get(identity);
17229
+ if (keys === void 0) {
17230
+ keys = /* @__PURE__ */ new Set();
17231
+ priorKeys.set(identity, keys);
17232
+ }
17233
+ for (const range of session.ranges) keys.add(rangeDeclarationKey(range));
17234
+ }
17235
+ const out = [];
17236
+ for (let s = 0; s < merged.length; s += 1) {
17237
+ const session = merged[s];
17238
+ const declared = priorKeys.get(physicalPathIdentity(session.path)) ?? /* @__PURE__ */ new Set();
17239
+ const fresh = session.ranges.filter(
17240
+ (range) => !declared.has(rangeDeclarationKey(range))
17241
+ );
17242
+ if (fresh.length === 0) continue;
17243
+ out.push({
17244
+ s,
17245
+ session: {
17246
+ path: session.path,
17247
+ ranges: fresh.map((range) => ({
17248
+ from: { ...range.from },
17249
+ to: { ...range.to }
17250
+ }))
17251
+ }
17252
+ });
17253
+ }
17254
+ return out;
17255
+ }
17256
+ function compareLinePosition(left, right) {
17257
+ if (left.s !== right.s) return left.s - right.s;
17258
+ const leftLine = left.line ?? Number.MAX_SAFE_INTEGER;
17259
+ const rightLine = right.line ?? Number.MAX_SAFE_INTEGER;
17260
+ return leftLine - rightLine;
17261
+ }
17262
+ function mergeFreshIntoCarried(carried, fresh) {
17263
+ const seenIds = /* @__PURE__ */ new Set();
17264
+ const seenPositions = /* @__PURE__ */ new Set();
17265
+ const out = [];
17266
+ for (const line2 of carried) {
17267
+ if (line2.id !== void 0) seenIds.add(line2.id);
17268
+ if (line2.line !== void 0)
17269
+ seenPositions.add(amendmentKey(line2.s, line2.line));
17270
+ out.push(line2);
17271
+ }
17272
+ for (const line2 of fresh) {
17273
+ if (line2.id !== void 0) {
17274
+ if (seenIds.has(line2.id)) continue;
17275
+ seenIds.add(line2.id);
17276
+ }
17277
+ if (line2.line !== void 0) {
17278
+ const position = amendmentKey(line2.s, line2.line);
17279
+ if (seenPositions.has(position)) continue;
17280
+ seenPositions.add(position);
17281
+ }
17282
+ out.push(line2);
17283
+ }
17284
+ out.sort(compareLinePosition);
17285
+ return out;
17286
+ }
17230
17287
  function normalizeResolvedRanges(ranges, sessionLines, sessionPath) {
17231
17288
  const resolved = [];
17232
17289
  for (const range of ranges) {
@@ -17321,84 +17378,101 @@ async function projectSessionRanges(input) {
17321
17378
  return { lines, unparsable };
17322
17379
  }
17323
17380
  async function reprojectTicketProvenance(input) {
17324
- const recordInput = ticketProvenanceRecordInput(
17325
- input.ticketNumber,
17326
- input.cwd,
17327
- input.home
17328
- );
17329
17381
  const prior = await readTicketProvenance(input.ticketNumber, input.cwd, input.home);
17330
- const priorRaw = await readSitianVolumeText(recordInput);
17331
- const priorNonEmpty = priorRaw.text !== void 0 && priorRaw.text.trim() !== "";
17332
- const amendments = input.amendments ?? [];
17333
- let sessions = input.sessions;
17334
- if (sessions.length === 0) {
17335
- if (amendments.length > 0) {
17336
- const priorSessions = prior.header?.sessions;
17337
- if (priorSessions === void 0 || priorSessions.length === 0) {
17338
- throw new TicketProvenanceInputError(
17339
- "amendments require sessions bounds (none submitted and no prior header sessions)"
17340
- );
17341
- }
17342
- sessions = priorSessions;
17343
- } else if (priorNonEmpty) {
17344
- const now2 = (/* @__PURE__ */ new Date()).toISOString();
17345
- const header2 = prior.header ?? {
17382
+ if (input.sessions.length === 0) {
17383
+ const now2 = (/* @__PURE__ */ new Date()).toISOString();
17384
+ return {
17385
+ recordFile: prior.recordFile,
17386
+ header: prior.header ?? {
17346
17387
  repo: resolveBookKeyFromGit(input.cwd),
17347
17388
  ticket: input.ticketNumber,
17348
17389
  createdAt: now2,
17349
17390
  updatedAt: now2,
17350
17391
  sessions: []
17351
- };
17352
- return {
17353
- recordFile: prior.recordFile,
17354
- header: header2,
17355
- lines: prior.lines,
17356
- unparsable: []
17357
- };
17358
- }
17392
+ },
17393
+ lines: prior.lines,
17394
+ unparsable: []
17395
+ };
17396
+ }
17397
+ const merged = mergeSessionBounds(prior.header?.sessions, input.sessions);
17398
+ const deltas = undeclaredSessionRanges(prior.header?.sessions, merged.sessions);
17399
+ if (deltas.length === 0) {
17400
+ const now2 = (/* @__PURE__ */ new Date()).toISOString();
17401
+ return {
17402
+ recordFile: prior.recordFile,
17403
+ header: prior.header ?? {
17404
+ repo: resolveBookKeyFromGit(input.cwd),
17405
+ ticket: input.ticketNumber,
17406
+ createdAt: now2,
17407
+ updatedAt: now2,
17408
+ sessions: merged.sessions
17409
+ },
17410
+ lines: prior.lines,
17411
+ unparsable: []
17412
+ };
17359
17413
  }
17360
17414
  const amendmentsByKey = /* @__PURE__ */ new Map();
17361
- for (const amendment of amendments) {
17362
- amendmentsByKey.set(amendmentKey(amendment.s, amendment.line), amendment);
17415
+ for (const amendment of input.amendments ?? []) {
17416
+ const cumulativeIndex = merged.incomingIndexes[amendment.s];
17417
+ if (cumulativeIndex === void 0) continue;
17418
+ amendmentsByKey.set(amendmentKey(cumulativeIndex, amendment.line), {
17419
+ ...amendment,
17420
+ s: cumulativeIndex
17421
+ });
17363
17422
  }
17364
- const lines = [];
17423
+ const seenIds = new Set(
17424
+ prior.lines.flatMap((line2) => line2.id === void 0 ? [] : [line2.id])
17425
+ );
17426
+ const fresh = [];
17365
17427
  const unparsable = [];
17366
- const seenIds = /* @__PURE__ */ new Set();
17367
- for (let s = 0; s < sessions.length; s += 1) {
17428
+ for (const delta of deltas) {
17368
17429
  const projected = await projectSessionRanges({
17369
- s,
17370
- session: sessions[s],
17430
+ s: delta.s,
17431
+ session: delta.session,
17371
17432
  amendmentsByKey,
17372
17433
  seenIds,
17373
17434
  ...input.home === void 0 ? {} : { home: input.home }
17374
17435
  });
17375
- lines.push(...projected.lines);
17436
+ fresh.push(...projected.lines);
17376
17437
  unparsable.push(...projected.unparsable);
17377
17438
  }
17439
+ const lines = mergeFreshIntoCarried(prior.lines, fresh);
17378
17440
  const now = (/* @__PURE__ */ new Date()).toISOString();
17379
17441
  const header = {
17380
- repo: resolveBookKeyFromGit(input.cwd),
17442
+ repo: prior.header?.repo ?? resolveBookKeyFromGit(input.cwd),
17381
17443
  ticket: input.ticketNumber,
17382
17444
  createdAt: prior.header?.createdAt ?? now,
17383
17445
  updatedAt: now,
17384
- sessions
17446
+ sessions: merged.sessions
17385
17447
  };
17386
17448
  if (unparsable.length > 0) {
17387
- return {
17388
- recordFile: prior.recordFile,
17389
- header,
17390
- lines,
17391
- unparsable
17392
- };
17449
+ return { recordFile: prior.recordFile, header, lines, unparsable };
17393
17450
  }
17394
- const body = `${[JSON.stringify(header), ...lines.map((line2) => JSON.stringify(line2))].join("\n")}
17395
- `;
17396
- const volume = await rewriteSitianVolume({ ...recordInput, body });
17451
+ const identityMaterial = JSON.stringify({
17452
+ ticket: input.ticketNumber,
17453
+ deltas: deltas.map(({ s, session }) => ({
17454
+ s,
17455
+ path: physicalPathIdentity(session.path),
17456
+ ranges: session.ranges
17457
+ })),
17458
+ lines: fresh
17459
+ });
17460
+ const identity = `ticket-provenance:${createHash8("sha256").update(identityMaterial).digest("hex")}`;
17461
+ const pointer = appendSitianRecord({
17462
+ ...ticketProvenanceRecordInput(input.ticketNumber, input.cwd, input.home),
17463
+ identity,
17464
+ payload: {
17465
+ type: "ticket-provenance-append",
17466
+ sessions: merged.sessions,
17467
+ lines: fresh
17468
+ }
17469
+ });
17470
+ const folded = await readTicketProvenance(input.ticketNumber, input.cwd, input.home);
17397
17471
  return {
17398
- recordFile: volume.recordFile,
17399
- header,
17400
- lines,
17401
- unparsable
17472
+ recordFile: pointer.recordFile,
17473
+ header: folded.header ?? header,
17474
+ lines: folded.lines,
17475
+ unparsable: []
17402
17476
  };
17403
17477
  }
17404
17478
  var TicketProvenanceInputError;
@@ -17432,9 +17506,9 @@ __export(case_dossier_delivery_exports, {
17432
17506
  loadCaseDossierReadingMaterial: () => loadCaseDossierReadingMaterial,
17433
17507
  projectCaseDossierPointerSection: () => projectCaseDossierPointerSection
17434
17508
  });
17435
- import { mkdtemp as mkdtemp2, readFile as readFile19, rm as rm3, writeFile as writeFile10 } from "node:fs/promises";
17509
+ import { mkdtemp as mkdtemp2, readFile as readFile19, rm as rm2, writeFile as writeFile9 } from "node:fs/promises";
17436
17510
  import { tmpdir as tmpdir2 } from "node:os";
17437
- import { join as join33 } from "node:path";
17511
+ import { join as join32 } from "node:path";
17438
17512
  function describeDossierFile(path) {
17439
17513
  return path;
17440
17514
  }
@@ -17459,10 +17533,10 @@ async function deliverCaseDossierAsAttachment(input) {
17459
17533
  home: input.home
17460
17534
  });
17461
17535
  if (section === void 0) return void 0;
17462
- const stagingDir = await mkdtemp2(join33(tmpdir2(), "ak-case-dossier-"));
17536
+ const stagingDir = await mkdtemp2(join32(tmpdir2(), "ak-case-dossier-"));
17463
17537
  try {
17464
- const stagingPath = join33(stagingDir, CASE_DOSSIER_ATTACH_FILE);
17465
- await writeFile10(stagingPath, `${section}
17538
+ const stagingPath = join32(stagingDir, CASE_DOSSIER_ATTACH_FILE);
17539
+ await writeFile9(stagingPath, `${section}
17466
17540
  `, "utf8");
17467
17541
  return await freezeAttachmentsIntoRun(
17468
17542
  [stagingPath],
@@ -17470,11 +17544,11 @@ async function deliverCaseDossierAsAttachment(input) {
17470
17544
  CASE_DOSSIER_ATTACH_KEY
17471
17545
  );
17472
17546
  } finally {
17473
- await rm3(stagingDir, { recursive: true, force: true });
17547
+ await rm2(stagingDir, { recursive: true, force: true });
17474
17548
  }
17475
17549
  }
17476
17550
  async function loadCaseDossierReadingMaterial(runDirectory) {
17477
- const frozenPath = join33(
17551
+ const frozenPath = join32(
17478
17552
  runDirectory,
17479
17553
  "attachments",
17480
17554
  CASE_DOSSIER_ATTACH_KEY,
@@ -17504,7 +17578,7 @@ var init_case_dossier_delivery = __esm({
17504
17578
 
17505
17579
  // src/host-transition-prior-native.ts
17506
17580
  import { access as access4, readdir as readdir7 } from "node:fs/promises";
17507
- import { dirname as dirname18, join as join34 } from "node:path";
17581
+ import { dirname as dirname17, join as join33 } from "node:path";
17508
17582
  function isEnoent3(error) {
17509
17583
  return typeof error === "object" && error !== null && error.code === "ENOENT";
17510
17584
  }
@@ -17518,7 +17592,7 @@ async function listPiNativeRecordPaths(sessionFile) {
17518
17592
  }
17519
17593
  }
17520
17594
  async function listSitianRecordPaths(sessionParent) {
17521
- const sessionRoot = dirname18(sessionParent);
17595
+ const sessionRoot = dirname17(sessionParent);
17522
17596
  let entries;
17523
17597
  try {
17524
17598
  entries = await readdir7(sessionRoot, { withFileTypes: true });
@@ -17529,7 +17603,7 @@ async function listSitianRecordPaths(sessionParent) {
17529
17603
  const recordPaths = [];
17530
17604
  for (const entry of entries) {
17531
17605
  if (!entry.isDirectory()) continue;
17532
- const recordFile = join34(sessionRoot, entry.name, "records.jsonl");
17606
+ const recordFile = join33(sessionRoot, entry.name, "records.jsonl");
17533
17607
  try {
17534
17608
  await access4(recordFile);
17535
17609
  recordPaths.push(recordFile);
@@ -17597,9 +17671,9 @@ var init_public_run_credentials = __esm({
17597
17671
 
17598
17672
  // src/public-cli/auto-resume.ts
17599
17673
  import { constants as fsConstants2 } from "node:fs";
17600
- import { randomUUID as randomUUID6 } from "node:crypto";
17674
+ import { randomUUID as randomUUID5 } from "node:crypto";
17601
17675
  import { lstat as lstat6, mkdir as mkdir4, open as open2 } from "node:fs/promises";
17602
- import { join as join35 } from "node:path";
17676
+ import { join as join34 } from "node:path";
17603
17677
  async function persistReturnedRunState(admitted, authority, options) {
17604
17678
  if (options?.lawful === true) {
17605
17679
  await markRunTerminal(admitted.runDirectory);
@@ -17714,7 +17788,7 @@ function jsonSafeReplacer() {
17714
17788
  };
17715
17789
  }
17716
17790
  async function writeHardenedArtifactFile(artifactsDir, namePrefix, payload) {
17717
- const filePath = join35(artifactsDir, `${namePrefix}-${randomUUID6()}.json`);
17791
+ const filePath = join34(artifactsDir, `${namePrefix}-${randomUUID5()}.json`);
17718
17792
  const body = `${JSON.stringify(payload, jsonSafeReplacer(), 2)}
17719
17793
  `;
17720
17794
  const noFollowFlag = typeof fsConstants2.O_NOFOLLOW === "number" ? fsConstants2.O_NOFOLLOW : 0;
@@ -17985,9 +18059,9 @@ var init_auto_resume = __esm({
17985
18059
  });
17986
18060
 
17987
18061
  // src/public-cli/post-admission.ts
17988
- import { randomUUID as randomUUID7 } from "node:crypto";
17989
- import { writeFile as writeFile11 } from "node:fs/promises";
17990
- import { isAbsolute as isAbsolute8, join as join36, resolve as resolve13 } from "node:path";
18062
+ import { randomUUID as randomUUID6 } from "node:crypto";
18063
+ import { writeFile as writeFile10 } from "node:fs/promises";
18064
+ import { isAbsolute as isAbsolute8, join as join35, resolve as resolve13 } from "node:path";
17991
18065
  function describeCaughtError(error) {
17992
18066
  if (error instanceof Error) {
17993
18067
  const code = error.code;
@@ -18031,8 +18105,8 @@ async function recordBestEffortPostDispatchDiagnostic(admitted, env, diagnostic,
18031
18105
  } catch (appendError) {
18032
18106
  try {
18033
18107
  const artifactsDir = await ensureRealArtifactsDirectory(admitted.runDirectory);
18034
- await writeFile11(
18035
- join36(artifactsDir, `post-admission-diagnostic-${randomUUID7()}.json`),
18108
+ await writeFile10(
18109
+ join35(artifactsDir, `post-admission-diagnostic-${randomUUID6()}.json`),
18036
18110
  `${JSON.stringify({ version: 1, ...payload }, null, 2)}
18037
18111
  `,
18038
18112
  { encoding: "utf8", flag: "wx" }
@@ -18307,8 +18381,8 @@ async function dispatchPostAdmissionTurn(input) {
18307
18381
  }
18308
18382
  let stderrLogWriteFailure;
18309
18383
  try {
18310
- await writeFile11(
18311
- join36(admitted.runDirectory, "stderr.log"),
18384
+ await writeFile10(
18385
+ join35(admitted.runDirectory, "stderr.log"),
18312
18386
  result.stderr,
18313
18387
  "utf8"
18314
18388
  );
@@ -18540,7 +18614,7 @@ function resumeTurnRequestProjectionOptions(admitted, request, env, summonsPrepa
18540
18614
  kind: "resume",
18541
18615
  prompt
18542
18616
  },
18543
- ...request.message === void 0 ? {} : { courtAttemptId: randomUUID7() },
18617
+ ...request.message === void 0 ? {} : { courtAttemptId: randomUUID6() },
18544
18618
  ...env.stationChild === void 0 ? {} : { stationChild: env.stationChild }
18545
18619
  };
18546
18620
  }
@@ -18558,7 +18632,7 @@ async function dispatchAfterWriterLease(input) {
18558
18632
  }
18559
18633
  function isAlreadyFrozenSummonsAttachment(runDirectory, attachmentPath) {
18560
18634
  const absolute = isAbsolute8(attachmentPath) ? attachmentPath : resolve13(attachmentPath);
18561
- return pathContainedIn(join36(runDirectory, "attachments"), absolute);
18635
+ return pathContainedIn(join35(runDirectory, "attachments"), absolute);
18562
18636
  }
18563
18637
  async function prepareSummonsResumeMaterials(runDirectory, summons) {
18564
18638
  if (summons === void 0) return void 0;
@@ -18637,7 +18711,7 @@ async function runPostAdmissionSeatResume(input) {
18637
18711
  }
18638
18712
  let turnRequest = await input.buildTurnRequest(admittedForBuild, request);
18639
18713
  if (openCourtAttemptId !== void 0 || request.summons !== void 0 || request.message !== void 0) {
18640
- const courtAttemptId = openCourtAttemptId ?? (turnRequest.courtAttemptId !== void 0 && turnRequest.courtAttemptId.length > 0 ? turnRequest.courtAttemptId : randomUUID7());
18714
+ const courtAttemptId = openCourtAttemptId ?? (turnRequest.courtAttemptId !== void 0 && turnRequest.courtAttemptId.length > 0 ? turnRequest.courtAttemptId : randomUUID6());
18641
18715
  turnRequest = { ...turnRequest, courtAttemptId };
18642
18716
  if (openCourtAttemptId === void 0) {
18643
18717
  const court = {
@@ -19925,7 +19999,7 @@ __export(public_role_summons_exports, {
19925
19999
  summonPublicRole: () => summonPublicRole
19926
20000
  });
19927
20001
  import { existsSync as existsSync11 } from "node:fs";
19928
- import { join as join37 } from "node:path";
20002
+ import { join as join36 } from "node:path";
19929
20003
  function createCapturingIo() {
19930
20004
  const chunks = [];
19931
20005
  return {
@@ -19948,7 +20022,7 @@ function parentDir(path) {
19948
20022
  function walkPackageRoot(start) {
19949
20023
  let dir = start;
19950
20024
  for (let i = 0; i < 12; i += 1) {
19951
- if (existsSync11(join37(dir, "package.json")) && existsSync11(join37(dir, "souls"))) {
20025
+ if (existsSync11(join36(dir, "package.json")) && existsSync11(join36(dir, "souls"))) {
19952
20026
  return dir;
19953
20027
  }
19954
20028
  const parent = parentDir(dir);
@@ -20059,7 +20133,7 @@ async function createSummonEnv(options, afterHost) {
20059
20133
  async function summonPublicRole(options) {
20060
20134
  const packageRoot = resolveSummonsPackageRoot(options.packageRoot);
20061
20135
  const home = await resolveSummonHome(options);
20062
- const agentDir = options.agentDir ?? process.env.PI_CODING_AGENT_DIR ?? join37(home, ".pi", "agent");
20136
+ const agentDir = options.agentDir ?? process.env.PI_CODING_AGENT_DIR ?? join36(home, ".pi", "agent");
20063
20137
  const {
20064
20138
  loadCredentialProviders: loadCredentialProviders2,
20065
20139
  loadPublicCliConfig: loadPublicCliConfig2,
@@ -20575,7 +20649,7 @@ import {
20575
20649
  openSync as openSync2,
20576
20650
  writeSync
20577
20651
  } from "node:fs";
20578
- import { dirname as dirname19, isAbsolute as isAbsolute10, resolve as resolve15 } from "node:path";
20652
+ import { dirname as dirname18, isAbsolute as isAbsolute10, resolve as resolve15 } from "node:path";
20579
20653
 
20580
20654
  // src/activation-ledger-session.ts
20581
20655
  init_activation_ledger_topology();
@@ -20724,7 +20798,7 @@ function appendActivationLedgerLine(ledgerPath, line2, options) {
20724
20798
  }
20725
20799
  const resolvedLedger = resolve15(ledgerPath);
20726
20800
  const resolvedHome = resolve15(options.ledgerHome);
20727
- const parent = dirname19(resolvedLedger);
20801
+ const parent = dirname18(resolvedLedger);
20728
20802
  ensureRealDirectoryTree(resolvedHome, parent);
20729
20803
  assertLedgerFileInsideHome(resolvedLedger, resolvedHome);
20730
20804
  if (typeof constants2.O_NOFOLLOW !== "number") {
@@ -21088,11 +21162,28 @@ init_collector_evidence();
21088
21162
  init_collector_github();
21089
21163
 
21090
21164
  // src/collector-handbook.ts
21091
- init_atomic_write();
21092
- init_activation_ledger_topology();
21093
21165
  import { readFile as readFile20 } from "node:fs/promises";
21094
21166
  import { join as join38, sep as sep5 } from "node:path";
21095
21167
 
21168
+ // src/atomic-write.ts
21169
+ import { randomUUID as randomUUID7 } from "node:crypto";
21170
+ import { rename as rename3, rm as rm3, writeFile as writeFile11 } from "node:fs/promises";
21171
+ import { dirname as dirname19, join as join37 } from "node:path";
21172
+ async function writeFileAtomically(destination, contents) {
21173
+ const parent = dirname19(destination);
21174
+ const temporary = join37(parent, `.atomic-write-${randomUUID7()}.tmp`);
21175
+ try {
21176
+ await writeFile11(temporary, contents);
21177
+ await rename3(temporary, destination);
21178
+ } catch (error) {
21179
+ await rm3(temporary, { force: true }).catch(() => void 0);
21180
+ throw error;
21181
+ }
21182
+ }
21183
+
21184
+ // src/collector-handbook.ts
21185
+ init_activation_ledger_topology();
21186
+
21096
21187
  // src/collector-tool-schemas.ts
21097
21188
  init_open_tool_schema();
21098
21189
  init_terminating_infrastructure();
@@ -22294,7 +22385,7 @@ init_gatekeeper_output();
22294
22385
  init_navigator_output();
22295
22386
 
22296
22387
  // src/navigator-attendance.ts
22297
- import { createHash as createHash8 } from "node:crypto";
22388
+ import { createHash as createHash9 } from "node:crypto";
22298
22389
  init_navigator_invocation_identity();
22299
22390
  init_packaged_role_registry();
22300
22391
  init_activation_ledger_topology();
@@ -22747,7 +22838,7 @@ function navigatorSubjectKey(subjectRoot, subject, provenance = "role_input") {
22747
22838
  if (provenance === "placeholder") return subjectRoot;
22748
22839
  const normalized = subject.trim().replace(/\s+/g, " ");
22749
22840
  if (normalized === "") return subjectRoot;
22750
- return `${subjectRoot}#${createHash8("sha256").update(normalized).digest("hex").slice(0, 32)}`;
22841
+ return `${subjectRoot}#${createHash9("sha256").update(normalized).digest("hex").slice(0, 32)}`;
22751
22842
  }
22752
22843
  function navigatorSubjectKeyForInput(subjectRoot, reference, cwd = process.cwd()) {
22753
22844
  if (issueRoot(subjectRoot) !== void 0 || !subjectRoot.includes("/.ak/work/")) return subjectRoot;