@akagilnc/pi-workflow-roles 0.1.4745 → 0.1.4772

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.
@@ -17221,12 +17221,7 @@ var init_compliance_transport = __esm({
17221
17221
  });
17222
17222
 
17223
17223
  // src/role-run-relocation.ts
17224
- import { existsSync as existsSync5 } from "node:fs";
17225
- import { readdir as readdir3, readFile as readFile6, writeFile as writeFile2 } from "node:fs/promises";
17226
17224
  import { join as join12, sep as sep2 } from "node:path";
17227
- function isEnoent2(error) {
17228
- return error instanceof Error && "code" in error && error.code === "ENOENT";
17229
- }
17230
17225
  function rewriteRunDirectoryPathValue(value, oldRunDirectory, newRunDirectory) {
17231
17226
  if (typeof value !== "string") return value;
17232
17227
  if (value === oldRunDirectory) return newRunDirectory;
@@ -17268,23 +17263,6 @@ function rewriteRunDirectoryPathFieldsAgainstRewrites(record4, fields, rewrites)
17268
17263
  }
17269
17264
  }
17270
17265
  }
17271
- function collectRewrites(input) {
17272
- const own = {
17273
- oldRunDirectory: input.oldRunDirectory,
17274
- newRunDirectory: input.newRunDirectory
17275
- };
17276
- if (input.crossRunRewrites === void 0 || input.crossRunRewrites.length === 0) {
17277
- return [own];
17278
- }
17279
- const seen = /* @__PURE__ */ new Set([own.oldRunDirectory]);
17280
- const out = [own];
17281
- for (const rewrite of input.crossRunRewrites) {
17282
- if (seen.has(rewrite.oldRunDirectory)) continue;
17283
- seen.add(rewrite.oldRunDirectory);
17284
- out.push(rewrite);
17285
- }
17286
- return out;
17287
- }
17288
17266
  function isPlainObject(value) {
17289
17267
  return value !== null && typeof value === "object" && !Array.isArray(value);
17290
17268
  }
@@ -17296,254 +17274,25 @@ function rewriteSourceRunLocator(value, rewrites) {
17296
17274
  rewrites
17297
17275
  );
17298
17276
  }
17299
- function rewriteSummonsMaterials(value, rewrites) {
17300
- if (!isPlainObject(value)) return;
17301
- rewriteRunDirectoryPathFieldsAgainstRewrites(
17302
- value,
17303
- SUMMONS_PATH_FIELDS,
17304
- rewrites
17305
- );
17306
- rewriteSourceRunLocator(value.sourceRun, rewrites);
17307
- if (Array.isArray(value.attachmentPaths)) {
17308
- value.attachmentPaths = value.attachmentPaths.map(
17309
- (path) => rewriteRunDirectoryPathValueAgainstRewrites(path, rewrites)
17310
- );
17311
- }
17312
- }
17313
- async function rewriteJsonObjectFile(path, fields, rewrites) {
17314
- if (!existsSync5(path)) return;
17315
- const page = JSON.parse(await readFile6(path, "utf8"));
17316
- if (!isPlainObject(page)) return;
17317
- rewriteRunDirectoryPathFieldsAgainstRewrites(page, fields, rewrites);
17318
- await writeFile2(path, `${JSON.stringify(page, null, 2)}
17319
- `, "utf8");
17320
- }
17321
- async function rewriteOfficerPointerFile(path, rewrites) {
17322
- if (!existsSync5(path)) return;
17323
- const page = JSON.parse(await readFile6(path, "utf8"));
17324
- if (!isPlainObject(page)) return;
17325
- if (page.kind !== "direct-officer-run-pointer") return;
17326
- rewriteRunDirectoryPathFieldsAgainstRewrites(
17327
- page,
17328
- OFFICER_POINTER_FIELDS,
17329
- rewrites
17330
- );
17331
- await writeFile2(path, `${JSON.stringify(page)}
17332
- `, "utf8");
17333
- }
17334
- async function rewriteSitianRecordsJsonl(path, rewrites) {
17335
- if (!existsSync5(path)) return;
17336
- const raw = await readFile6(path, "utf8");
17337
- if (raw.length === 0) return;
17338
- const endsWithNewline = raw.endsWith("\n");
17339
- const lines = raw.split("\n");
17340
- let changed = false;
17341
- const out = [];
17342
- for (let i = 0; i < lines.length; i += 1) {
17343
- const line2 = lines[i];
17344
- if (line2 === "" && i === lines.length - 1 && endsWithNewline) {
17345
- out.push("");
17346
- continue;
17347
- }
17348
- if (line2.trim() === "") {
17349
- out.push(line2);
17350
- continue;
17351
- }
17352
- let parsed;
17353
- try {
17354
- parsed = JSON.parse(line2);
17355
- } catch {
17356
- out.push(line2);
17357
- continue;
17358
- }
17359
- if (!isPlainObject(parsed)) {
17360
- out.push(line2);
17361
- continue;
17362
- }
17363
- if (!("sessionParent" in parsed)) {
17364
- out.push(line2);
17365
- continue;
17366
- }
17367
- const before = parsed.sessionParent;
17368
- rewriteRunDirectoryPathFieldsAgainstRewrites(
17369
- parsed,
17370
- SITIAN_RECORD_FIELDS,
17371
- rewrites
17372
- );
17373
- if (parsed.sessionParent !== before) changed = true;
17374
- out.push(JSON.stringify(parsed));
17375
- }
17376
- if (!changed) return;
17377
- const body = out.join("\n");
17378
- await writeFile2(
17379
- path,
17380
- endsWithNewline && !body.endsWith("\n") ? `${body}
17381
- ` : body,
17382
- "utf8"
17383
- );
17384
- }
17385
- async function rewriteSessionTranscriptBindings(path, rewrites) {
17386
- if (!existsSync5(path)) return;
17387
- const raw = await readFile6(path, "utf8");
17388
- if (raw.length === 0) return;
17389
- const endsWithNewline = raw.endsWith("\n");
17390
- const lines = raw.split("\n");
17391
- let changed = false;
17392
- const out = [];
17393
- for (let i = 0; i < lines.length; i += 1) {
17394
- const line2 = lines[i];
17395
- if (line2 === "" && i === lines.length - 1 && endsWithNewline) {
17396
- out.push("");
17397
- continue;
17398
- }
17399
- if (line2.trim() === "") {
17400
- out.push(line2);
17401
- continue;
17402
- }
17403
- let parsed;
17404
- try {
17405
- parsed = JSON.parse(line2);
17406
- } catch {
17407
- out.push(line2);
17408
- continue;
17409
- }
17410
- if (!isPlainObject(parsed)) {
17411
- out.push(line2);
17412
- continue;
17413
- }
17414
- let lineChanged = false;
17415
- if (parsed.type === "session" && "parentSession" in parsed) {
17416
- const before = parsed.parentSession;
17417
- rewriteRunDirectoryPathFieldsAgainstRewrites(
17418
- parsed,
17419
- SESSION_HEADER_FIELDS,
17420
- rewrites
17421
- );
17422
- if (parsed.parentSession !== before) lineChanged = true;
17423
- } else if (parsed.type === "custom" && parsed.customType === AUDITOR_PARENT_ATTEMPT_BINDING_ENTRY_TYPE && isPlainObject(parsed.data) && isPlainObject(parsed.data.parent)) {
17424
- const parent = parsed.data.parent;
17425
- const before = parent.sessionFile;
17426
- rewriteRunDirectoryPathFieldsAgainstRewrites(
17427
- parent,
17428
- BINDING_PARENT_FIELDS,
17429
- rewrites
17430
- );
17431
- if (parent.sessionFile !== before) lineChanged = true;
17432
- }
17433
- if (lineChanged) changed = true;
17434
- out.push(lineChanged ? JSON.stringify(parsed) : line2);
17435
- }
17436
- if (!changed) return;
17437
- const body = out.join("\n");
17438
- await writeFile2(
17439
- path,
17440
- endsWithNewline && !body.endsWith("\n") ? `${body}
17441
- ` : body,
17442
- "utf8"
17443
- );
17444
- }
17445
- async function rewriteNestedMachinePathPages(pagesDirectory, rewrites) {
17446
- const sessionRoot = join12(pagesDirectory, "session");
17447
- async function walk(directory) {
17448
- let entries;
17449
- try {
17450
- entries = await readdir3(directory, { withFileTypes: true });
17451
- } catch (error) {
17452
- if (isEnoent2(error)) return;
17453
- throw error;
17454
- }
17455
- for (const entry of entries) {
17456
- const path = join12(directory, entry.name);
17457
- if (entry.isDirectory()) {
17458
- await walk(path);
17459
- continue;
17277
+ function rewriteAdmittedRoleRunPage(page, rewrites) {
17278
+ rewriteRunDirectoryPathFieldsAgainstRewrites(page, ADMITTED_PAGE_FIELDS, rewrites);
17279
+ rewriteSourceRunLocator(page.sourceRun, rewrites);
17280
+ if (Array.isArray(page.attachments)) {
17281
+ for (const attachment of page.attachments) {
17282
+ if (isPlainObject(attachment)) {
17283
+ rewriteRunDirectoryPathFieldsAgainstRewrites(attachment, ["frozenPath"], rewrites);
17460
17284
  }
17461
- if (!entry.isFile()) continue;
17462
- if (entry.name === "current-session.json") {
17463
- await rewriteJsonObjectFile(path, CURRENT_SESSION_FIELDS, rewrites);
17464
- } else if (entry.name.endsWith(".pointer.json")) {
17465
- await rewriteOfficerPointerFile(path, rewrites);
17466
- } else if (entry.name === "records.jsonl") {
17467
- await rewriteSitianRecordsJsonl(path, rewrites);
17468
- } else if (entry.name.endsWith(".jsonl")) {
17469
- await rewriteSessionTranscriptBindings(path, rewrites);
17470
- }
17471
- }
17472
- }
17473
- await walk(sessionRoot);
17474
- }
17475
- async function rewriteRoleRunDurablePages(input) {
17476
- const { pagesDirectory } = input;
17477
- const rewrites = collectRewrites(input);
17478
- const admittedPath = join12(pagesDirectory, "admitted-request.json");
17479
- if (existsSync5(admittedPath)) {
17480
- const page = JSON.parse(await readFile6(admittedPath, "utf8"));
17481
- rewriteRunDirectoryPathFieldsAgainstRewrites(
17482
- page,
17483
- ADMITTED_PAGE_FIELDS,
17484
- rewrites
17485
- );
17486
- rewriteSourceRunLocator(page.sourceRun, rewrites);
17487
- if (Array.isArray(page.attachments)) {
17488
- for (const attachment of page.attachments) {
17489
- if (isPlainObject(attachment)) {
17490
- rewriteRunDirectoryPathFieldsAgainstRewrites(
17491
- attachment,
17492
- ["frozenPath"],
17493
- rewrites
17494
- );
17495
- }
17496
- }
17497
- }
17498
- if (isPlainObject(page.principal)) {
17499
- rewriteRunDirectoryPathFieldsAgainstRewrites(
17500
- page.principal,
17501
- ["sessionDirectory", "sessionFile"],
17502
- rewrites
17503
- );
17504
17285
  }
17505
- await writeFile2(admittedPath, `${JSON.stringify(page, null, 2)}
17506
- `, "utf8");
17507
17286
  }
17508
- const invocationPath = join12(pagesDirectory, "invocation.json");
17509
- if (existsSync5(invocationPath)) {
17510
- const page = JSON.parse(await readFile6(invocationPath, "utf8"));
17287
+ if (isPlainObject(page.principal)) {
17511
17288
  rewriteRunDirectoryPathFieldsAgainstRewrites(
17512
- page,
17513
- INVOCATION_PAGE_FIELDS,
17289
+ page.principal,
17290
+ ["sessionDirectory", "sessionFile"],
17514
17291
  rewrites
17515
17292
  );
17516
- await writeFile2(
17517
- invocationPath,
17518
- `${JSON.stringify(page, null, 2)}
17519
- `,
17520
- "utf8"
17521
- );
17522
17293
  }
17523
- const statePath = join12(pagesDirectory, "run-state.json");
17524
- if (existsSync5(statePath)) {
17525
- const page = JSON.parse(await readFile6(statePath, "utf8"));
17526
- rewriteRunDirectoryPathFieldsAgainstRewrites(
17527
- page,
17528
- RUN_STATE_PAGE_FIELDS,
17529
- rewrites
17530
- );
17531
- if (isPlainObject(page.principal)) {
17532
- rewriteRunDirectoryPathFieldsAgainstRewrites(
17533
- page.principal,
17534
- ["sessionDirectory", "sessionFile"],
17535
- rewrites
17536
- );
17537
- }
17538
- if (isPlainObject(page.currentCourt)) {
17539
- rewriteSummonsMaterials(page.currentCourt.summons, rewrites);
17540
- }
17541
- await writeFile2(statePath, `${JSON.stringify(page, null, 2)}
17542
- `, "utf8");
17543
- }
17544
- await rewriteNestedMachinePathPages(pagesDirectory, rewrites);
17545
17294
  }
17546
- var ADMITTED_PAGE_FIELDS, INVOCATION_PAGE_FIELDS, RUN_STATE_PAGE_FIELDS, SOURCE_RUN_LOCATOR_FIELDS, SUMMONS_PATH_FIELDS, CURRENT_SESSION_FIELDS, OFFICER_POINTER_FIELDS, SITIAN_RECORD_FIELDS, SESSION_HEADER_FIELDS, BINDING_PARENT_FIELDS;
17295
+ var ADMITTED_PAGE_FIELDS, SOURCE_RUN_LOCATOR_FIELDS;
17547
17296
  var init_role_run_relocation = __esm({
17548
17297
  "src/role-run-relocation.ts"() {
17549
17298
  "use strict";
@@ -17560,24 +17309,7 @@ var init_role_run_relocation = __esm({
17560
17309
  "mergerInputPath",
17561
17310
  "sourceRunPath"
17562
17311
  ];
17563
- INVOCATION_PAGE_FIELDS = [
17564
- "runDirectory",
17565
- "sessionDirectory",
17566
- "sessionFile"
17567
- ];
17568
- RUN_STATE_PAGE_FIELDS = [
17569
- "runDirectory",
17570
- "admittedRequestPath",
17571
- "sessionDirectory",
17572
- "sessionFile"
17573
- ];
17574
17312
  SOURCE_RUN_LOCATOR_FIELDS = ["runDirectory"];
17575
- SUMMONS_PATH_FIELDS = ["sourceRunPath"];
17576
- CURRENT_SESSION_FIELDS = ["sessionFile"];
17577
- OFFICER_POINTER_FIELDS = ["sessionFile", "runDirectory"];
17578
- SITIAN_RECORD_FIELDS = ["sessionParent"];
17579
- SESSION_HEADER_FIELDS = ["parentSession"];
17580
- BINDING_PARENT_FIELDS = ["sessionFile"];
17581
17313
  }
17582
17314
  });
17583
17315
 
@@ -17686,7 +17418,7 @@ var init_terminating_tools = __esm({
17686
17418
  });
17687
17419
 
17688
17420
  // src/doctor-evidence.ts
17689
- import { readdir as readdir4, readFile as readFile7, realpath as realpath2, stat } from "node:fs/promises";
17421
+ import { readdir as readdir3, readFile as readFile6, realpath as realpath2, stat } from "node:fs/promises";
17690
17422
  import { dirname as dirname8, relative as relative2, resolve as resolve4, sep as sep3 } from "node:path";
17691
17423
  function record2(value) {
17692
17424
  return typeof value === "object" && value !== null && !Array.isArray(value);
@@ -17694,7 +17426,7 @@ function record2(value) {
17694
17426
  async function discoverCaseFiles(root) {
17695
17427
  const found = [];
17696
17428
  async function walk(dir, depth) {
17697
- for (const item of await readdir4(dir, { withFileTypes: true })) {
17429
+ for (const item of await readdir3(dir, { withFileTypes: true })) {
17698
17430
  const path = resolve4(dir, item.name);
17699
17431
  if (item.isDirectory()) {
17700
17432
  await walk(path, depth + 1);
@@ -17802,7 +17534,7 @@ async function loadDoctorCase(runsPath) {
17802
17534
  const turns = { count: 0, sources: [] }, calls = { count: 0, sources: [] }, tokens = { count: 0, sources: [] };
17803
17535
  for (const path of await discoverCaseFiles(root)) {
17804
17536
  const id = relative2(root, path).split(sep3).join("/");
17805
- const bytes = await readFile7(path);
17537
+ const bytes = await readFile6(path);
17806
17538
  const content = bytes.toString("utf8");
17807
17539
  const kind = id.endsWith(".jsonl") ? "session" : "stderr";
17808
17540
  evidence.push({ id, kind, byteLength: bytes.byteLength, contentLength: content.length, sha256: sha256Hex(bytes), content });
@@ -17815,7 +17547,7 @@ async function loadDoctorCase(runsPath) {
17815
17547
  accumulate(calls, result.calls, id);
17816
17548
  accumulate(tokens, result.tokens, id);
17817
17549
  }
17818
- const runDirs = (await readdir4(root, { withFileTypes: true })).filter((item) => item.isDirectory()).map((item) => item.name).sort();
17550
+ const runDirs = (await readdir3(root, { withFileTypes: true })).filter((item) => item.isDirectory()).map((item) => item.name).sort();
17819
17551
  const legs = evidence.filter((entry) => entry.kind === "session").map((entry) => entry.id);
17820
17552
  const retryDirs = runDirs.filter((name) => /(?:^|[-_])retry(?:[-_]|$)/i.test(name));
17821
17553
  const rawBytes = evidence.filter((entry) => entry.kind === "session").reduce((sum, entry) => sum + entry.byteLength, 0);
@@ -17832,7 +17564,7 @@ var init_doctor_evidence = __esm({
17832
17564
 
17833
17565
  // src/collector-config.ts
17834
17566
  import { createHash as createHash3 } from "node:crypto";
17835
- import { readFile as readFile8 } from "node:fs/promises";
17567
+ import { readFile as readFile7 } from "node:fs/promises";
17836
17568
  function fail3(message, cause) {
17837
17569
  throw new Error(message, cause === void 0 ? void 0 : { cause });
17838
17570
  }
@@ -17875,7 +17607,7 @@ function emptyCollectorManifest() {
17875
17607
  async function loadCollectorManifest(path) {
17876
17608
  let bytes;
17877
17609
  try {
17878
- bytes = await readFile8(path);
17610
+ bytes = await readFile7(path);
17879
17611
  } catch (error) {
17880
17612
  fail3(`Collector request manifest is unreadable at ${path}`, error);
17881
17613
  }
@@ -18266,7 +17998,7 @@ var init_git_object_id = __esm({
18266
17998
 
18267
17999
  // src/merger-git-state.ts
18268
18000
  import { execFile as execFile2 } from "node:child_process";
18269
- import { access as access2, readFile as readFile9 } from "node:fs/promises";
18001
+ import { access as access2, readFile as readFile8 } from "node:fs/promises";
18270
18002
  import { constants as fsConstants } from "node:fs";
18271
18003
  import { isAbsolute as isAbsolute4, resolve as resolve5 } from "node:path";
18272
18004
  import { promisify as promisify2 } from "node:util";
@@ -18336,7 +18068,7 @@ function createProductionMergerGitState(repositoryRoot = process.cwd()) {
18336
18068
  const mergeHeadPath = isAbsolute4(mergeHeadReported) ? mergeHeadReported : resolve5(repositoryRoot, mergeHeadReported);
18337
18069
  let sourceObjectId = "";
18338
18070
  if (await pathExists(mergeHeadPath)) {
18339
- const raw = exactUtf8(await readFile9(mergeHeadPath), "Git MERGE_HEAD");
18071
+ const raw = exactUtf8(await readFile8(mergeHeadPath), "Git MERGE_HEAD");
18340
18072
  const mergeHeads = raw.trim().split(/\r?\n/).map((row) => row.trim()).filter(Boolean);
18341
18073
  if (mergeHeads.length === 0) throw new Error("Git MERGE_HEAD is empty");
18342
18074
  if (mergeHeads.length !== 1) throw new Error("Assigned repository does not have one ordinary in-progress merge");
@@ -18388,7 +18120,7 @@ var init_uuidv7 = __esm({
18388
18120
  });
18389
18121
 
18390
18122
  // src/typed-provider-http.ts
18391
- import { readFile as readFile10, unlink, writeFile as writeFile3 } from "node:fs/promises";
18123
+ import { readFile as readFile9, unlink, writeFile as writeFile2 } from "node:fs/promises";
18392
18124
  import { join as join13 } from "node:path";
18393
18125
  function typedProviderHttpPath(runDirectory) {
18394
18126
  return join13(runDirectory, TYPED_HTTP_FILE);
@@ -18406,7 +18138,7 @@ async function clearTypedProviderHttpObservation(runDirectory) {
18406
18138
  async function readLatestTypedProviderHttpObservation(runDirectory) {
18407
18139
  let text;
18408
18140
  try {
18409
- text = await readFile10(typedProviderHttpPath(runDirectory), "utf8");
18141
+ text = await readFile9(typedProviderHttpPath(runDirectory), "utf8");
18410
18142
  } catch (error) {
18411
18143
  if (error instanceof Error && "code" in error && error.code === "ENOENT") {
18412
18144
  return void 0;
@@ -18435,7 +18167,7 @@ var init_typed_provider_http = __esm({
18435
18167
  });
18436
18168
 
18437
18169
  // src/public-cli/run-lifecycle.ts
18438
- import { chmod, lstat as lstat2, open, readdir as readdir5, readFile as readFile11, unlink as unlink2, writeFile as writeFile4 } from "node:fs/promises";
18170
+ import { chmod, lstat as lstat2, open, readdir as readdir4, readFile as readFile10, unlink as unlink2, writeFile as writeFile3 } from "node:fs/promises";
18439
18171
  import { basename as basename5, join as join14 } from "node:path";
18440
18172
  function selectResumeContinuationPrompt(message, engineMaterial) {
18441
18173
  const lines = message !== void 0 ? [message] : [];
@@ -18474,7 +18206,7 @@ function renderResumeCommand(runId) {
18474
18206
  }
18475
18207
  async function writeRoleRunState(runDirectory, record4) {
18476
18208
  const payload = { ...record4, runDirectory };
18477
- await writeFile4(
18209
+ await writeFile3(
18478
18210
  join14(runDirectory, RUN_STATE_FILE),
18479
18211
  `${JSON.stringify(payload, null, 2)}
18480
18212
  `,
@@ -18525,7 +18257,7 @@ function parseCurrentCourtState(raw) {
18525
18257
  async function readRoleRunStateDisk(runDirectory) {
18526
18258
  let raw;
18527
18259
  try {
18528
- raw = JSON.parse(await readFile11(join14(runDirectory, RUN_STATE_FILE), "utf8"));
18260
+ raw = JSON.parse(await readFile10(join14(runDirectory, RUN_STATE_FILE), "utf8"));
18529
18261
  } catch (error) {
18530
18262
  if (errorCodeOf2(error) === "ENOENT") return void 0;
18531
18263
  throw error;
@@ -18547,10 +18279,15 @@ async function readRoleRunStateDisk(runDirectory) {
18547
18279
  if (typeof record4.projectRoot !== "string") return void 0;
18548
18280
  if (typeof record4.sessionDirectory !== "string") return void 0;
18549
18281
  if (typeof record4.admittedRequestPath !== "string") return void 0;
18550
- const runDir = typeof record4.runDirectory === "string" && record4.runDirectory.trim() !== "" ? record4.runDirectory : runDirectory;
18282
+ const storedRunDirectory = typeof record4.runDirectory === "string" && record4.runDirectory.trim() !== "" ? record4.runDirectory : runDirectory;
18283
+ const runDir = runDirectory;
18551
18284
  const principalWire = {
18552
- sessionDirectory: record4.sessionDirectory,
18553
- ...typeof record4.sessionFile === "string" ? { sessionFile: record4.sessionFile } : {}
18285
+ sessionDirectory: rewriteRunDirectoryPathValue(
18286
+ record4.sessionDirectory,
18287
+ storedRunDirectory,
18288
+ runDirectory
18289
+ ),
18290
+ ...typeof record4.sessionFile === "string" ? { sessionFile: rewriteRunDirectoryPathValue(record4.sessionFile, storedRunDirectory, runDirectory) } : {}
18554
18291
  };
18555
18292
  let resumable;
18556
18293
  if (record4.resumable !== void 0 && record4.resumable !== null) {
@@ -18570,7 +18307,11 @@ async function readRoleRunStateDisk(runDirectory) {
18570
18307
  bookKey: record4.bookKey,
18571
18308
  projectRoot: record4.projectRoot,
18572
18309
  runDirectory: runDir,
18573
- admittedRequestPath: record4.admittedRequestPath,
18310
+ admittedRequestPath: rewriteRunDirectoryPathValue(
18311
+ record4.admittedRequestPath,
18312
+ storedRunDirectory,
18313
+ runDirectory
18314
+ ),
18574
18315
  principalWire,
18575
18316
  ...phase === void 0 ? {} : { phase },
18576
18317
  ...resumable === void 0 ? {} : { resumable },
@@ -18592,7 +18333,7 @@ async function writeRoleRunStateDisk(runDirectory, disk) {
18592
18333
  ...disk.resumable === void 0 ? {} : { resumable: disk.resumable },
18593
18334
  ...disk.currentCourt === void 0 ? {} : { currentCourt: disk.currentCourt }
18594
18335
  };
18595
- await writeFile4(
18336
+ await writeFile3(
18596
18337
  join14(runDirectory, RUN_STATE_FILE),
18597
18338
  `${JSON.stringify(payload, null, 2)}
18598
18339
  `,
@@ -18760,7 +18501,7 @@ function isProcessAlive(pid) {
18760
18501
  async function autopsyWriterLock(lockPath) {
18761
18502
  let content;
18762
18503
  try {
18763
- content = await readFile11(lockPath, "utf8");
18504
+ content = await readFile10(lockPath, "utf8");
18764
18505
  } catch (error) {
18765
18506
  if (errorCodeOf2(error) === "ENOENT") return { verdict: "absent" };
18766
18507
  return { verdict: "unknown", reason: "unreadable", readFailure: error };
@@ -18919,7 +18660,7 @@ async function findRunDirectoryById(home, runId, onlyBookKey, onlyRole) {
18919
18660
  const booksRoot = join14(ledgerHome, "books");
18920
18661
  let bookKeys;
18921
18662
  try {
18922
- bookKeys = await readdir5(booksRoot);
18663
+ bookKeys = await readdir4(booksRoot);
18923
18664
  } catch (error) {
18924
18665
  if (errorCodeOf2(error) === "ENOENT") return void 0;
18925
18666
  throw error;
@@ -18957,7 +18698,7 @@ async function readRunParentPath(runDirectory) {
18957
18698
  let raw;
18958
18699
  try {
18959
18700
  raw = JSON.parse(
18960
- await readFile11(join14(runDirectory, "admitted-request.json"), "utf8")
18701
+ await readFile10(join14(runDirectory, "admitted-request.json"), "utf8")
18961
18702
  );
18962
18703
  } catch (error) {
18963
18704
  if (errorCodeOf2(error) === "ENOENT") return void 0;
@@ -19126,10 +18867,15 @@ async function loadResumableRunRecord(home, runId, authority) {
19126
18867
  let sourceRun;
19127
18868
  try {
19128
18869
  const raw = JSON.parse(
19129
- await readFile11(run.admittedRequestPath, "utf8")
18870
+ await readFile10(run.admittedRequestPath, "utf8")
19130
18871
  );
19131
18872
  if (raw !== null && typeof raw === "object" && !Array.isArray(raw)) {
19132
18873
  const record4 = raw;
18874
+ const storedRunDirectory = typeof record4.runDirectory === "string" && record4.runDirectory.trim() !== "" ? record4.runDirectory : run.runDirectory;
18875
+ rewriteAdmittedRoleRunPage(record4, [{
18876
+ oldRunDirectory: storedRunDirectory,
18877
+ newRunDirectory: run.runDirectory
18878
+ }]);
19133
18879
  if (typeof record4.instruction === "string") {
19134
18880
  instruction = record4.instruction;
19135
18881
  }
@@ -19244,7 +18990,7 @@ async function loadResumableRunRecord(home, runId, authority) {
19244
18990
  let model;
19245
18991
  try {
19246
18992
  const invocationRaw = JSON.parse(
19247
- await readFile11(join14(run.runDirectory, "invocation.json"), "utf8")
18993
+ await readFile10(join14(run.runDirectory, "invocation.json"), "utf8")
19248
18994
  );
19249
18995
  if (invocationRaw !== null && typeof invocationRaw === "object" && !Array.isArray(invocationRaw)) {
19250
18996
  const rec = invocationRaw;
@@ -19283,6 +19029,23 @@ async function loadResumableRunRecord(home, runId, authority) {
19283
19029
  } else if (mergedSet.tickets !== void 0) {
19284
19030
  courtTicketNumbers = mergedSet.tickets;
19285
19031
  }
19032
+ const sourceRunLeaf = basename5(sourceRunPath ?? "").split("@");
19033
+ const referencedRunId = sourceRun?.runId ?? sourceRunLeaf[0];
19034
+ const referencedRole = sourceRun?.role ?? sourceRunLeaf[1];
19035
+ if (referencedRunId !== void 0 && referencedRunId !== "") {
19036
+ const currentSourceRunDirectory = await findRunDirectoryById(
19037
+ home,
19038
+ referencedRunId,
19039
+ run.bookKey,
19040
+ referencedRole
19041
+ );
19042
+ if (currentSourceRunDirectory !== void 0) {
19043
+ sourceRunPath = currentSourceRunDirectory;
19044
+ if (sourceRun !== void 0) {
19045
+ sourceRun = { ...sourceRun, runDirectory: currentSourceRunDirectory };
19046
+ }
19047
+ }
19048
+ }
19286
19049
  return {
19287
19050
  run,
19288
19051
  principal,
@@ -19687,6 +19450,7 @@ var init_run_lifecycle = __esm({
19687
19450
  init_typed_provider_http();
19688
19451
  init_collector_config();
19689
19452
  init_diarist_contracts();
19453
+ init_role_run_relocation();
19690
19454
  init_engine_material();
19691
19455
  init_invocation();
19692
19456
  V1_RESUMABLE_PROVIDERS = ["openai-codex", "xai"];
@@ -19759,17 +19523,29 @@ async function resolveNotarySourceRunLocator(options) {
19759
19523
  }
19760
19524
  const ledgerHome = resolveActivationLedgerHome(options.home);
19761
19525
  const bookKey = resolveBookKeyFromGit(options.projectRoot);
19762
- const bookRunsRoot = join15(activationBookDirectory(ledgerHome, bookKey), "runs");
19526
+ const bookDirectory = activationBookDirectory(ledgerHome, bookKey);
19527
+ const bookRunsRoot = join15(bookDirectory, "runs");
19763
19528
  let candidate;
19764
19529
  const bare = parseRunDirectoryName(raw);
19765
19530
  if (bare !== void 0 && !raw.includes("/") && !raw.includes("\\")) {
19766
19531
  candidate = await findRunDirectoryById(options.home, bare.runId, bookKey, bare.role) ?? join15(bookRunsRoot, `${bare.runId}@${bare.role}`);
19767
19532
  } else {
19768
19533
  candidate = isAbsolute6(raw) ? raw : resolve6(options.projectRoot, raw);
19534
+ const identity2 = parseRunDirectoryName(basename6(candidate));
19535
+ const subjectDirectory = dirname9(dirname9(candidate));
19536
+ const isLegacyUnboundLocator = identity2 !== void 0 && basename6(dirname9(candidate)) === "runs" && basename6(subjectDirectory) === "unbound" && resolve6(dirname9(subjectDirectory)) === resolve6(bookDirectory);
19537
+ if (isLegacyUnboundLocator) {
19538
+ candidate = await findRunDirectoryById(
19539
+ options.home,
19540
+ identity2.runId,
19541
+ bookKey,
19542
+ identity2.role
19543
+ ) ?? candidate;
19544
+ }
19769
19545
  }
19770
19546
  const real = await requireRunDirectory(candidate, raw);
19771
19547
  const identity = parseRunDirectoryName(basename6(real));
19772
- const bookIdentity = physicalPathIdentity(activationBookDirectory(ledgerHome, bookKey));
19548
+ const bookIdentity = physicalPathIdentity(bookDirectory);
19773
19549
  const parentIdentity = physicalPathIdentity(dirname9(real));
19774
19550
  const subjectBookIdentity = physicalPathIdentity(dirname9(dirname9(dirname9(real))));
19775
19551
  if (parentIdentity !== physicalPathIdentity(bookRunsRoot) && !(basename6(dirname9(real)) === "runs" && subjectBookIdentity === bookIdentity)) {
@@ -21011,15 +20787,15 @@ __export(invocation_exports, {
21011
20787
  withPreparedAttachments: () => withPreparedAttachments
21012
20788
  });
21013
20789
  import { execFileSync as execFileSync3 } from "node:child_process";
21014
- import { existsSync as existsSync6 } from "node:fs";
20790
+ import { existsSync as existsSync5 } from "node:fs";
21015
20791
  import {
21016
20792
  lstat as lstat4,
21017
20793
  mkdtemp,
21018
- readFile as readFile12,
20794
+ readFile as readFile11,
21019
20795
  realpath as realpath4,
21020
20796
  rename,
21021
20797
  rm,
21022
- writeFile as writeFile5
20798
+ writeFile as writeFile4
21023
20799
  } from "node:fs/promises";
21024
20800
  import { tmpdir } from "node:os";
21025
20801
  import { basename as basename7, dirname as dirname10, isAbsolute as isAbsolute7, join as join16, resolve as resolve7, sep as sep4 } from "node:path";
@@ -21047,7 +20823,7 @@ async function writeAdmittedRequestPersistence(admittedRequestPath, body, coordi
21047
20823
  sessionDirectory: coordinates.sessionDirectory,
21048
20824
  sessionFile: coordinates.sessionFile
21049
20825
  };
21050
- await writeFile5(
20826
+ await writeFile4(
21051
20827
  admittedRequestPath,
21052
20828
  `${JSON.stringify(projection, null, 2)}
21053
20829
  `,
@@ -21075,7 +20851,7 @@ async function writeRoleInvocationLedger(source, role, effectiveModel) {
21075
20851
  ...source.ticketNumber === void 0 ? {} : { ticketNumber: source.ticketNumber },
21076
20852
  ...effectiveModelLedgerFields(effectiveModel)
21077
20853
  };
21078
- await writeFile5(
20854
+ await writeFile4(
21079
20855
  join16(source.runDirectory, "invocation.json"),
21080
20856
  `${JSON.stringify(identity, null, 2)}
21081
20857
  `,
@@ -21084,7 +20860,7 @@ async function writeRoleInvocationLedger(source, role, effectiveModel) {
21084
20860
  }
21085
20861
  async function recordEffectiveInvocationModel(runDirectory, model, engine, host, engineModel) {
21086
20862
  const ledgerPath = join16(runDirectory, "invocation.json");
21087
- const current = JSON.parse(await readFile12(ledgerPath, "utf8"));
20863
+ const current = JSON.parse(await readFile11(ledgerPath, "utf8"));
21088
20864
  const next = { ...current };
21089
20865
  if (model !== void 0) {
21090
20866
  next.provider = model.provider;
@@ -21108,7 +20884,7 @@ async function recordEffectiveInvocationModel(runDirectory, model, engine, host,
21108
20884
  if (host !== void 0) {
21109
20885
  next.host = host;
21110
20886
  }
21111
- await writeFile5(
20887
+ await writeFile4(
21112
20888
  ledgerPath,
21113
20889
  `${JSON.stringify(next, null, 2)}
21114
20890
  `,
@@ -21117,8 +20893,8 @@ async function recordEffectiveInvocationModel(runDirectory, model, engine, host,
21117
20893
  }
21118
20894
  async function mergeInvocationIdentityPage(runDirectory, fields) {
21119
20895
  const ledgerPath = join16(runDirectory, "invocation.json");
21120
- const current = JSON.parse(await readFile12(ledgerPath, "utf8"));
21121
- await writeFile5(
20896
+ const current = JSON.parse(await readFile11(ledgerPath, "utf8"));
20897
+ await writeFile4(
21122
20898
  ledgerPath,
21123
20899
  `${JSON.stringify({
21124
20900
  ...current,
@@ -21133,14 +20909,14 @@ async function persistAdmittedSourceRunPath(admitted, sourceRunPath) {
21133
20909
  throw new Error("persistAdmittedSourceRunPath requires a non-empty sourceRunPath");
21134
20910
  }
21135
20911
  const admittedPath = admitted.admittedRequestPath;
21136
- const current = JSON.parse(await readFile12(admittedPath, "utf8"));
20912
+ const current = JSON.parse(await readFile11(admittedPath, "utf8"));
21137
20913
  if (typeof current.sourceRunPath === "string") {
21138
20914
  if (current.sourceRunPath === sourceRunPath) return;
21139
20915
  throw new Error(
21140
20916
  `persistAdmittedSourceRunPath refuses to replace ${current.sourceRunPath} with ${sourceRunPath}`
21141
20917
  );
21142
20918
  }
21143
- await writeFile5(
20919
+ await writeFile4(
21144
20920
  admittedPath,
21145
20921
  `${JSON.stringify({ ...current, sourceRunPath }, null, 2)}
21146
20922
  `,
@@ -21159,7 +20935,7 @@ async function bindAdmittedTicketNumber(admitted, ticketNumber) {
21159
20935
  }
21160
20936
  async function recordAdmittedCorrelation(admitted, correlationId) {
21161
20937
  const current = JSON.parse(
21162
- await readFile12(admitted.admittedRequestPath, "utf8")
20938
+ await readFile11(admitted.admittedRequestPath, "utf8")
21163
20939
  );
21164
20940
  const prior = [
21165
20941
  ...Array.isArray(current.correlationIds) ? current.correlationIds.filter(
@@ -21168,7 +20944,7 @@ async function recordAdmittedCorrelation(admitted, correlationId) {
21168
20944
  ...typeof current.correlationId === "string" && current.correlationId.trim() !== "" ? [current.correlationId] : []
21169
20945
  ];
21170
20946
  const correlationIds = [.../* @__PURE__ */ new Set([...prior, correlationId])];
21171
- await writeFile5(
20947
+ await writeFile4(
21172
20948
  admitted.admittedRequestPath,
21173
20949
  `${JSON.stringify({ ...current, correlationId, correlationIds }, null, 2)}
21174
20950
  `,
@@ -21207,8 +20983,8 @@ async function bindCourtTicketNumbersOnAdmitted(admitted, courtTicketNumbers) {
21207
20983
  }
21208
20984
  const frozen = Object.freeze([...projected]);
21209
20985
  const admittedPath = admitted.admittedRequestPath;
21210
- const current = JSON.parse(await readFile12(admittedPath, "utf8"));
21211
- await writeFile5(
20986
+ const current = JSON.parse(await readFile11(admittedPath, "utf8"));
20987
+ await writeFile4(
21212
20988
  admittedPath,
21213
20989
  `${JSON.stringify({ ...current, courtTicketNumbers: frozen }, null, 2)}
21214
20990
  `,
@@ -21220,7 +20996,7 @@ async function bindCourtTicketNumbersOnAdmitted(admitted, courtTicketNumbers) {
21220
20996
  admitted.courtTicketNumbers = frozen;
21221
20997
  }
21222
20998
  async function relocateAdmittedRunToTicket(admitted, authority, heldLease) {
21223
- if (admitted.ticketNumber === void 0 || !admitted.runDirectory.includes(`${sep4}unbound${sep4}runs${sep4}`)) return;
20999
+ if (admitted.ticketNumber === void 0 || !admitted.runDirectory.includes(`${sep4}unbound${sep4}runs${sep4}`)) return void 0;
21224
21000
  const oldRunDirectory = admitted.runDirectory;
21225
21001
  const ledgerHome = resolveActivationLedgerHome(homeFromRunDirectory(oldRunDirectory));
21226
21002
  const target = roleRunPlacement(ledgerHome, {
@@ -21230,6 +21006,7 @@ async function relocateAdmittedRunToTicket(admitted, authority, heldLease) {
21230
21006
  role: admitted.role
21231
21007
  });
21232
21008
  ensureRoleRunDirectory(ledgerHome, dirname10(target.runDirectory));
21009
+ const principal = authority.seal(target);
21233
21010
  await rename(oldRunDirectory, target.runDirectory);
21234
21011
  heldLease?.relocate(target.runDirectory);
21235
21012
  const admittedRecord = admitted;
@@ -21254,13 +21031,8 @@ async function relocateAdmittedRunToTicket(admitted, authority, heldLease) {
21254
21031
  target.runDirectory
21255
21032
  );
21256
21033
  }
21257
- const principal = authority.seal(target);
21258
21034
  admitted.principal = principal;
21259
- await rewriteRoleRunDurablePages({
21260
- pagesDirectory: target.runDirectory,
21261
- oldRunDirectory,
21262
- newRunDirectory: target.runDirectory
21263
- });
21035
+ return { oldRunDirectory, newRunDirectory: target.runDirectory };
21264
21036
  }
21265
21037
  async function bindTicketNumberOnRunDirectory(runDirectory, ticketNumber) {
21266
21038
  requireSafePositiveTicketNumber(
@@ -21269,7 +21041,7 @@ async function bindTicketNumberOnRunDirectory(runDirectory, ticketNumber) {
21269
21041
  );
21270
21042
  const admittedPath = join16(runDirectory, "admitted-request.json");
21271
21043
  const invocationPath = join16(runDirectory, "invocation.json");
21272
- const admitted = JSON.parse(await readFile12(admittedPath, "utf8"));
21044
+ const admitted = JSON.parse(await readFile11(admittedPath, "utf8"));
21273
21045
  const existing = admitted.ticketNumber;
21274
21046
  if (typeof existing === "number") {
21275
21047
  if (existing === ticketNumber) return;
@@ -21277,9 +21049,9 @@ async function bindTicketNumberOnRunDirectory(runDirectory, ticketNumber) {
21277
21049
  `bindTicketNumberOnRunDirectory refuses to replace existing ticket #${existing} with #${ticketNumber}`
21278
21050
  );
21279
21051
  }
21280
- if (existsSync6(invocationPath)) {
21052
+ if (existsSync5(invocationPath)) {
21281
21053
  const invocation = JSON.parse(
21282
- await readFile12(invocationPath, "utf8")
21054
+ await readFile11(invocationPath, "utf8")
21283
21055
  );
21284
21056
  if (typeof invocation.ticketNumber === "number" && invocation.ticketNumber !== ticketNumber) {
21285
21057
  throw new Error(
@@ -21287,7 +21059,7 @@ async function bindTicketNumberOnRunDirectory(runDirectory, ticketNumber) {
21287
21059
  );
21288
21060
  }
21289
21061
  }
21290
- await writeFile5(
21062
+ await writeFile4(
21291
21063
  admittedPath,
21292
21064
  `${JSON.stringify({ ...admitted, ticketNumber }, null, 2)}
21293
21065
  `,
@@ -21304,7 +21076,7 @@ async function recordLaunchedPiIdentity(runDirectory, identity) {
21304
21076
  async function observeLaunchedRolePackageIdentity(packageRoot2, selectedRoleEntry) {
21305
21077
  const rolePackageRoot = packageRoot2;
21306
21078
  const raw = JSON.parse(
21307
- await readFile12(join16(rolePackageRoot, "package.json"), "utf8")
21079
+ await readFile11(join16(rolePackageRoot, "package.json"), "utf8")
21308
21080
  );
21309
21081
  if (typeof raw.version !== "string" || raw.version.trim() === "") {
21310
21082
  throw new Error(
@@ -21589,7 +21361,7 @@ async function readRegularFileAttachment(sourcePath) {
21589
21361
  );
21590
21362
  }
21591
21363
  try {
21592
- return { absolute, bytes: await readFile12(absolute) };
21364
+ return { absolute, bytes: await readFile11(absolute) };
21593
21365
  } catch (error) {
21594
21366
  throw new CliUsageError(
21595
21367
  `attachment is not a readable regular file: ${sourcePath}`,
@@ -21609,7 +21381,7 @@ async function withPreparedAttachments(attachmentPaths, use) {
21609
21381
  for (let index = 0; index < attachmentPaths.length; index += 1) {
21610
21382
  const { absolute, bytes } = await readRegularFileAttachment(attachmentPaths[index]);
21611
21383
  const snapshotPath = join16(stagingDirectory, String(index).padStart(6, "0"));
21612
- await writeFile5(snapshotPath, bytes);
21384
+ await writeFile4(snapshotPath, bytes);
21613
21385
  prepared.push({ absolute, snapshotPath });
21614
21386
  }
21615
21387
  result = await use(prepared);
@@ -21633,7 +21405,7 @@ async function freezeAttachmentBytes(provenancePath, bytes, destinationDir, inde
21633
21405
  destinationDir,
21634
21406
  `${String(index).padStart(2, "0")}-${basename7(provenancePath)}`
21635
21407
  );
21636
- await writeFile5(frozenPath, bytes);
21408
+ await writeFile4(frozenPath, bytes);
21637
21409
  return {
21638
21410
  provenancePath,
21639
21411
  frozenPath,
@@ -21645,7 +21417,7 @@ async function freezeAttachmentBytes(provenancePath, bytes, destinationDir, inde
21645
21417
  async function freezePreparedAttachment(prepared, destinationDir, index) {
21646
21418
  return freezeAttachmentBytes(
21647
21419
  prepared.absolute,
21648
- await readFile12(prepared.snapshotPath),
21420
+ await readFile11(prepared.snapshotPath),
21649
21421
  destinationDir,
21650
21422
  index
21651
21423
  );
@@ -21901,7 +21673,7 @@ function buildCountersignTransportPrompt(admitted, engineMaterial) {
21901
21673
  async function loadAdmittedJudgeRequest(runDirectory) {
21902
21674
  try {
21903
21675
  const raw = JSON.parse(
21904
- await readFile12(join16(runDirectory, "admitted-request.json"), "utf8")
21676
+ await readFile11(join16(runDirectory, "admitted-request.json"), "utf8")
21905
21677
  );
21906
21678
  if (raw === null || typeof raw !== "object" || Array.isArray(raw)) return void 0;
21907
21679
  const record4 = raw;
@@ -21957,7 +21729,7 @@ async function admitCoderInvocation(options) {
21957
21729
  });
21958
21730
  const attachments = await freezeAttachments(options.attachmentPaths, attachmentsDirectory);
21959
21731
  const taskPath = join16(runDirectory, "task.md");
21960
- await writeFile5(taskPath, instruction, "utf8");
21732
+ await writeFile4(taskPath, instruction, "utf8");
21961
21733
  const admitted = {
21962
21734
  role: "coder",
21963
21735
  phase: options.phase,
@@ -22027,7 +21799,7 @@ async function admitFixerInvocation(options) {
22027
21799
  if (options.prerequisitesPath !== void 0) {
22028
21800
  const absolutePrereq = isAbsolute7(options.prerequisitesPath) ? options.prerequisitesPath : resolve7(options.prerequisitesPath);
22029
21801
  try {
22030
- prerequisitesSource = await readFile12(absolutePrereq, "utf8");
21802
+ prerequisitesSource = await readFile11(absolutePrereq, "utf8");
22031
21803
  } catch (error) {
22032
21804
  throw new CliUsageError(
22033
21805
  `fixer prerequisites path is unreadable: ${options.prerequisitesPath}`,
@@ -22064,7 +21836,7 @@ async function admitFixerInvocation(options) {
22064
21836
  let prerequisitesPath;
22065
21837
  if (prerequisitesSource !== void 0) {
22066
21838
  prerequisitesPath = join16(runDirectory, "prerequisites.json");
22067
- await writeFile5(
21839
+ await writeFile4(
22068
21840
  prerequisitesPath,
22069
21841
  `${JSON.stringify(prerequisites, null, 2)}
22070
21842
  `,
@@ -22072,7 +21844,7 @@ async function admitFixerInvocation(options) {
22072
21844
  );
22073
21845
  }
22074
21846
  const packetPath = join16(runDirectory, "fix-packet.md");
22075
- await writeFile5(packetPath, instruction, "utf8");
21847
+ await writeFile4(packetPath, instruction, "utf8");
22076
21848
  const admitted = {
22077
21849
  role: "fixer",
22078
21850
  phase: options.phase,
@@ -22318,7 +22090,7 @@ async function admitCollectorInvocation(options) {
22318
22090
  let requestManifestPath;
22319
22091
  if (manifestCanonicalJson !== void 0) {
22320
22092
  requestManifestPath = join16(runDirectory, "request-manifest.json");
22321
- await writeFile5(requestManifestPath, manifestCanonicalJson, "utf8");
22093
+ await writeFile4(requestManifestPath, manifestCanonicalJson, "utf8");
22322
22094
  }
22323
22095
  const admitted = {
22324
22096
  role: "collector",
@@ -23099,7 +22871,7 @@ async function admitMergerInvocation(options) {
23099
22871
  authorizedChecks: []
23100
22872
  });
23101
22873
  const mergerInputPath = join16(runDirectory, "merger-input.json");
23102
- await writeFile5(
22874
+ await writeFile4(
23103
22875
  mergerInputPath,
23104
22876
  `${JSON.stringify(mergerInput, null, 2)}
23105
22877
  `,
@@ -23412,7 +23184,7 @@ var init_invocation = __esm({
23412
23184
  });
23413
23185
 
23414
23186
  // src/public-cli/load-production-acp-host.ts
23415
- import { existsSync as existsSync7 } from "node:fs";
23187
+ import { existsSync as existsSync6 } from "node:fs";
23416
23188
  import { join as join17 } from "node:path";
23417
23189
  import { pathToFileURL } from "node:url";
23418
23190
  async function loadProductionAcpHostFactory(packageRoot2, host) {
@@ -23422,7 +23194,7 @@ async function loadProductionAcpHostFactory(packageRoot2, host) {
23422
23194
  }
23423
23195
  const built = join17(packageRoot2, "dist/acp-host/production-host.js");
23424
23196
  const source = join17(packageRoot2, "src/acp-host/production-host.ts");
23425
- const target = existsSync7(built) ? built : source;
23197
+ const target = existsSync6(built) ? built : source;
23426
23198
  const href = pathToFileURL(target).href;
23427
23199
  const mod = await import(href);
23428
23200
  const create = mod.createProductionAcpRoleTurnHost;
@@ -23436,7 +23208,7 @@ var init_load_production_acp_host = __esm({
23436
23208
  });
23437
23209
 
23438
23210
  // src/public-cli/load-production-headless-host.ts
23439
- import { existsSync as existsSync8 } from "node:fs";
23211
+ import { existsSync as existsSync7 } from "node:fs";
23440
23212
  import { join as join18 } from "node:path";
23441
23213
  import { pathToFileURL as pathToFileURL2 } from "node:url";
23442
23214
  async function loadProductionHeadlessHostFactory(packageRoot2, host) {
@@ -23446,7 +23218,7 @@ async function loadProductionHeadlessHostFactory(packageRoot2, host) {
23446
23218
  }
23447
23219
  const built = join18(packageRoot2, "dist/headless-host/production-host.js");
23448
23220
  const source = join18(packageRoot2, "src/headless-host/production-host.ts");
23449
- const target = existsSync8(built) ? built : source;
23221
+ const target = existsSync7(built) ? built : source;
23450
23222
  const href = pathToFileURL2(target).href;
23451
23223
  const mod = await import(href);
23452
23224
  const create = mod.createProductionHeadlessRoleTurnHost;
@@ -23572,7 +23344,7 @@ var init_role_turn_host_resolution = __esm({
23572
23344
 
23573
23345
  // src/package-resources/method-skill.ts
23574
23346
  import { createHash as createHash4 } from "node:crypto";
23575
- import { readFile as readFile13, realpath as realpath5 } from "node:fs/promises";
23347
+ import { readFile as readFile12, realpath as realpath5 } from "node:fs/promises";
23576
23348
  import { join as join19 } from "node:path";
23577
23349
  function gitBlobOid(bytes) {
23578
23350
  const body = typeof bytes === "string" ? Buffer.from(bytes, "utf8") : Buffer.from(bytes);
@@ -23691,7 +23463,7 @@ async function loadPackagedMethodSkillMaterial(packageRoot2, name) {
23691
23463
  const provenancePath = join19(rootDirectory, "provenance.json");
23692
23464
  let provenanceRaw;
23693
23465
  try {
23694
- provenanceRaw = await readFile13(provenancePath, "utf8");
23466
+ provenanceRaw = await readFile12(provenancePath, "utf8");
23695
23467
  } catch (error) {
23696
23468
  throw new PackagedMethodSkillUnavailableError(name, provenancePath, error);
23697
23469
  }
@@ -23708,7 +23480,7 @@ async function loadPackagedMethodSkillMaterial(packageRoot2, name) {
23708
23480
  const absolute = join19(rootDirectory, rel);
23709
23481
  let bytes;
23710
23482
  try {
23711
- bytes = await readFile13(absolute);
23483
+ bytes = await readFile12(absolute);
23712
23484
  } catch (error) {
23713
23485
  throw new PackagedMethodSkillUnavailableError(name, absolute, error);
23714
23486
  }
@@ -23724,7 +23496,7 @@ async function loadPackagedMethodSkillMaterial(packageRoot2, name) {
23724
23496
  let raw;
23725
23497
  try {
23726
23498
  skillPath = await realpath5(skillPathConfigured);
23727
- raw = await readFile13(skillPath, "utf8");
23499
+ raw = await readFile12(skillPath, "utf8");
23728
23500
  } catch (error) {
23729
23501
  throw new PackagedMethodSkillUnavailableError(name, skillPathConfigured, error);
23730
23502
  }
@@ -23808,12 +23580,12 @@ var init_method_skill = __esm({
23808
23580
  });
23809
23581
 
23810
23582
  // src/ledger-session-read.ts
23811
- import { readFile as readFile14 } from "node:fs/promises";
23583
+ import { readFile as readFile13 } from "node:fs/promises";
23812
23584
  function isRecord6(value) {
23813
23585
  return typeof value === "object" && value !== null && !Array.isArray(value);
23814
23586
  }
23815
23587
  async function readLedgerSessionJsonlLines(path) {
23816
- const text = await readFile14(path, "utf8");
23588
+ const text = await readFile13(path, "utf8");
23817
23589
  const lines = text.split("\n");
23818
23590
  const out = [];
23819
23591
  for (let index = 0; index < lines.length; index += 1) {
@@ -24004,7 +23776,7 @@ var init_ledger_session_read = __esm({
24004
23776
  });
24005
23777
 
24006
23778
  // src/analyst-gate-cycles-read.ts
24007
- import { readdir as readdir6 } from "node:fs/promises";
23779
+ import { readdir as readdir5 } from "node:fs/promises";
24008
23780
  import { join as join20 } from "node:path";
24009
23781
  function isRecord7(value) {
24010
23782
  return typeof value === "object" && value !== null && !Array.isArray(value);
@@ -24220,10 +23992,10 @@ function pairGateRounds(volumes) {
24220
23992
  return rounds.sort((a, b) => a.officerStartedAt.localeCompare(b.officerStartedAt)).map((round, index) => ({ ...round, roundIndex: index + 1 }));
24221
23993
  }
24222
23994
  async function resolveOfficerSessionFromPointerFile(pointerPath) {
24223
- const { readFile: readFile23 } = await import("node:fs/promises");
23995
+ const { readFile: readFile22 } = await import("node:fs/promises");
24224
23996
  let raw;
24225
23997
  try {
24226
- raw = JSON.parse(await readFile23(pointerPath, "utf8"));
23998
+ raw = JSON.parse(await readFile22(pointerPath, "utf8"));
24227
23999
  } catch (error) {
24228
24000
  throw new Error(
24229
24001
  `direct officer run pointer unreadable in ${pointerPath}: ${error instanceof Error ? error.message : String(error)}`,
@@ -24246,7 +24018,7 @@ async function readAnalystGateCyclesFromAuditorRoles(auditorRolesDirectory, opti
24246
24018
  for (const directory of directories) {
24247
24019
  let names;
24248
24020
  try {
24249
- const entries = await readdir6(directory, { withFileTypes: true });
24021
+ const entries = await readdir5(directory, { withFileTypes: true });
24250
24022
  names = entries.filter(
24251
24023
  (e) => e.isFile() && (e.name.endsWith(".jsonl") || e.name.endsWith(".pointer.json"))
24252
24024
  ).map((e) => e.name).sort();
@@ -24499,14 +24271,14 @@ var init_submission_ledger = __esm({
24499
24271
  });
24500
24272
 
24501
24273
  // src/session-opening-materials.ts
24502
- import { existsSync as existsSync9 } from "node:fs";
24503
- import { readFile as readFile15 } from "node:fs/promises";
24274
+ import { existsSync as existsSync8 } from "node:fs";
24275
+ import { readFile as readFile14 } from "node:fs/promises";
24504
24276
  import { dirname as dirname11, join as join22 } from "node:path";
24505
24277
  import { fileURLToPath, pathToFileURL as pathToFileURL3 } from "node:url";
24506
24278
  function resolvePackageRootDir(moduleUrl = import.meta.url) {
24507
24279
  let dir = dirname11(fileURLToPath(moduleUrl));
24508
24280
  for (let i = 0; i < 8; i += 1) {
24509
- if (existsSync9(join22(dir, "package.json")) && existsSync9(join22(dir, "souls"))) {
24281
+ if (existsSync8(join22(dir, "package.json")) && existsSync8(join22(dir, "souls"))) {
24510
24282
  return dir;
24511
24283
  }
24512
24284
  const parent = dirname11(dir);
@@ -24516,7 +24288,7 @@ function resolvePackageRootDir(moduleUrl = import.meta.url) {
24516
24288
  return fileURLToPath(new URL("..", moduleUrl));
24517
24289
  }
24518
24290
  async function readPackageMaterial(relativePath) {
24519
- return readFile15(fileURLToPath(new URL(relativePath, packageRootUrl)), "utf8");
24291
+ return readFile14(fileURLToPath(new URL(relativePath, packageRootUrl)), "utf8");
24520
24292
  }
24521
24293
  async function joinPackageMaterials(relativePaths) {
24522
24294
  const chunks = [];
@@ -25120,7 +24892,7 @@ __export(settlement_exports, {
25120
24892
  withSubmissions: () => withSubmissions
25121
24893
  });
25122
24894
  import { randomUUID as randomUUID4 } from "node:crypto";
25123
- import { appendFile as appendFile2, readFile as readFile16, readdir as readdir7, rm as rm2, writeFile as writeFile6 } from "node:fs/promises";
24895
+ import { appendFile as appendFile2, readFile as readFile15, readdir as readdir6, rm as rm2, writeFile as writeFile5 } from "node:fs/promises";
25124
24896
  import { dirname as dirname13, join as join24 } from "node:path";
25125
24897
  function sealedLedgerHome(admitted) {
25126
24898
  return homeFromRunDirectory(admitted.runDirectory);
@@ -25271,7 +25043,7 @@ function presentControlledFailure(failure, io) {
25271
25043
  }
25272
25044
  async function inspectJudgeSession(sessionFile) {
25273
25045
  try {
25274
- await readFile16(sessionFile, "utf8");
25046
+ await readFile15(sessionFile, "utf8");
25275
25047
  return { state: "present" };
25276
25048
  } catch (error) {
25277
25049
  if (isMissingPathError4(error)) return { state: "missing" };
@@ -25506,7 +25278,7 @@ function sessionReadFailure(error, fallbackMessage) {
25506
25278
  return failed;
25507
25279
  }
25508
25280
  async function readBoundSessionEntries(sessionFile) {
25509
- const text = await readFile16(sessionFile, "utf8");
25281
+ const text = await readFile15(sessionFile, "utf8");
25510
25282
  const entries = [];
25511
25283
  for (const line2 of text.trim().split("\n").filter(Boolean)) {
25512
25284
  try {
@@ -25608,7 +25380,7 @@ async function loadBoundAuditorVolumes(sessionFile) {
25608
25380
  for (const childDirectory of childDirectories) {
25609
25381
  let names;
25610
25382
  try {
25611
- names = await readdir7(childDirectory);
25383
+ names = await readdir6(childDirectory);
25612
25384
  sawAnyDirectory = true;
25613
25385
  } catch (error) {
25614
25386
  if (isMissingPathError4(error)) continue;
@@ -26283,13 +26055,13 @@ async function publishAcceptedTerminalArtifacts(admitted, roleOutcome, coordinat
26283
26055
  const artifactsDir = await ensureTerminalArtifactFace(admitted.runDirectory);
26284
26056
  const reportPath = join24(artifactsDir, "report.json");
26285
26057
  const evidencePath = join24(artifactsDir, "evidence.json");
26286
- await writeFile6(
26058
+ await writeFile5(
26287
26059
  reportPath,
26288
26060
  `${JSON.stringify(bodies.report, null, 2)}
26289
26061
  `,
26290
26062
  "utf8"
26291
26063
  );
26292
- await writeFile6(
26064
+ await writeFile5(
26293
26065
  evidencePath,
26294
26066
  `${JSON.stringify(bodies.evidence, null, 2)}
26295
26067
  `,
@@ -27203,7 +26975,7 @@ async function writeFailureJsonRetainingCause(preferredCandidates, uniqueFallbac
27203
26975
  const path = candidates[i];
27204
26976
  const payload = issues.length === 0 ? basePayload : { ...basePayload, publicationIssues: issues };
27205
26977
  try {
27206
- await writeFile6(
26978
+ await writeFile5(
27207
26979
  path,
27208
26980
  `${JSON.stringify(payload, null, 2)}
27209
26981
  `,
@@ -27574,7 +27346,7 @@ var init_turn_request = __esm({
27574
27346
  });
27575
27347
 
27576
27348
  // src/session-identity.ts
27577
- import { mkdir as mkdir2, readFile as readFile17, rename as rename2, writeFile as writeFile7 } from "node:fs/promises";
27349
+ import { mkdir as mkdir2, readFile as readFile16, rename as rename2, writeFile as writeFile6 } from "node:fs/promises";
27578
27350
  import { dirname as dirname14, join as join25 } from "node:path";
27579
27351
  function createSessionIdentityAuthority(authority, sessionBindingFile) {
27580
27352
  const bindingPath = (principal) => join25(authority.decode(principal).sessionDirectory, sessionBindingFile);
@@ -27584,7 +27356,7 @@ function createSessionIdentityAuthority(authority, sessionBindingFile) {
27584
27356
  },
27585
27357
  async load(principal) {
27586
27358
  try {
27587
- const value = JSON.parse(await readFile17(bindingPath(principal), "utf8"));
27359
+ const value = JSON.parse(await readFile16(bindingPath(principal), "utf8"));
27588
27360
  if (typeof value !== "object" || value === null || typeof value.sessionId !== "string") {
27589
27361
  throw new Error("durable session binding is invalid");
27590
27362
  }
@@ -27598,7 +27370,7 @@ function createSessionIdentityAuthority(authority, sessionBindingFile) {
27598
27370
  const target = bindingPath(principal);
27599
27371
  await mkdir2(dirname14(target), { recursive: true });
27600
27372
  const temporary = `${target}.${process.pid}.tmp`;
27601
- await writeFile7(temporary, `${JSON.stringify({ sessionId })}
27373
+ await writeFile6(temporary, `${JSON.stringify({ sessionId })}
27602
27374
  `, { encoding: "utf8", mode: 384 });
27603
27375
  await rename2(temporary, target);
27604
27376
  }
@@ -27667,7 +27439,7 @@ var init_ticket_provenance = __esm({
27667
27439
  });
27668
27440
 
27669
27441
  // src/public-cli/case-dossier-delivery.ts
27670
- import { mkdtemp as mkdtemp2, readFile as readFile18, rm as rm3, writeFile as writeFile8 } from "node:fs/promises";
27442
+ import { mkdtemp as mkdtemp2, readFile as readFile17, rm as rm3, writeFile as writeFile7 } from "node:fs/promises";
27671
27443
  import { tmpdir as tmpdir2 } from "node:os";
27672
27444
  import { join as join26 } from "node:path";
27673
27445
  async function projectCaseDossierPointerSection(input) {
@@ -27699,7 +27471,7 @@ async function deliverCaseDossierAsAttachment(input) {
27699
27471
  const stagingDir = await mkdtemp2(join26(tmpdir2(), "ak-case-dossier-"));
27700
27472
  try {
27701
27473
  const stagingPath = join26(stagingDir, CASE_DOSSIER_ATTACH_FILE);
27702
- await writeFile8(stagingPath, `${section}
27474
+ await writeFile7(stagingPath, `${section}
27703
27475
  `, "utf8");
27704
27476
  return await freezeAttachmentsIntoRun(
27705
27477
  [stagingPath],
@@ -27725,9 +27497,9 @@ var init_case_dossier_delivery = __esm({
27725
27497
  });
27726
27498
 
27727
27499
  // src/host-transition-prior-native.ts
27728
- import { access as access3, readdir as readdir8 } from "node:fs/promises";
27500
+ import { access as access3, readdir as readdir7 } from "node:fs/promises";
27729
27501
  import { dirname as dirname15, join as join27 } from "node:path";
27730
- function isEnoent3(error) {
27502
+ function isEnoent2(error) {
27731
27503
  return typeof error === "object" && error !== null && error.code === "ENOENT";
27732
27504
  }
27733
27505
  async function listPiNativeRecordPaths(sessionFile) {
@@ -27735,7 +27507,7 @@ async function listPiNativeRecordPaths(sessionFile) {
27735
27507
  await access3(sessionFile);
27736
27508
  return [sessionFile];
27737
27509
  } catch (error) {
27738
- if (isEnoent3(error)) return [];
27510
+ if (isEnoent2(error)) return [];
27739
27511
  throw error;
27740
27512
  }
27741
27513
  }
@@ -27743,9 +27515,9 @@ async function listSitianRecordPaths(sessionParent) {
27743
27515
  const sessionRoot = dirname15(sessionParent);
27744
27516
  let entries;
27745
27517
  try {
27746
- entries = await readdir8(sessionRoot, { withFileTypes: true });
27518
+ entries = await readdir7(sessionRoot, { withFileTypes: true });
27747
27519
  } catch (error) {
27748
- if (isEnoent3(error)) return [];
27520
+ if (isEnoent2(error)) return [];
27749
27521
  throw error;
27750
27522
  }
27751
27523
  const recordPaths = [];
@@ -27756,7 +27528,7 @@ async function listSitianRecordPaths(sessionParent) {
27756
27528
  await access3(recordFile);
27757
27529
  recordPaths.push(recordFile);
27758
27530
  } catch (error) {
27759
- if (!isEnoent3(error)) throw error;
27531
+ if (!isEnoent2(error)) throw error;
27760
27532
  }
27761
27533
  }
27762
27534
  recordPaths.sort();
@@ -27781,42 +27553,6 @@ var init_host_transition_prior_native = __esm({
27781
27553
  }
27782
27554
  });
27783
27555
 
27784
- // src/public-cli/public-run-credentials.ts
27785
- function knownFailureForMissingProviderCredential(model, credentials) {
27786
- if (model === void 0 || credentials === void 0) return void 0;
27787
- if (model.provider !== "openai-codex" && model.provider !== "xai") return void 0;
27788
- if (!missingPublicProviderCredential(model.provider, credentials)) {
27789
- return void 0;
27790
- }
27791
- return {
27792
- cause: "provider",
27793
- identity: {
27794
- name: "MissingProviderCredential",
27795
- code: model.provider
27796
- }
27797
- };
27798
- }
27799
- function missingCredentialPreDispatchFailure(model, credentials) {
27800
- const knownFailure = knownFailureForMissingProviderCredential(model, credentials);
27801
- if (knownFailure === void 0) return void 0;
27802
- return {
27803
- timedOut: false,
27804
- code: 1,
27805
- stderr: `Missing credential for provider ${String(knownFailure.identity?.code ?? "unknown")}`,
27806
- knownFailure
27807
- };
27808
- }
27809
- function postRunMissingCredentialFailure(result, model, credentials) {
27810
- if (!(result.timedOut || result.code !== 0)) return void 0;
27811
- return knownFailureForMissingProviderCredential(model, credentials);
27812
- }
27813
- var init_public_run_credentials = __esm({
27814
- "src/public-cli/public-run-credentials.ts"() {
27815
- "use strict";
27816
- init_config2();
27817
- }
27818
- });
27819
-
27820
27556
  // src/public-cli/process-cancel.ts
27821
27557
  var process_cancel_exports = {};
27822
27558
  __export(process_cancel_exports, {
@@ -28288,7 +28024,7 @@ var init_auto_resume = __esm({
28288
28024
 
28289
28025
  // src/public-cli/post-admission.ts
28290
28026
  import { randomUUID as randomUUID6 } from "node:crypto";
28291
- import { writeFile as writeFile9 } from "node:fs/promises";
28027
+ import { writeFile as writeFile8 } from "node:fs/promises";
28292
28028
  import { isAbsolute as isAbsolute8, join as join29, resolve as resolve8 } from "node:path";
28293
28029
  function describeCaughtError(error) {
28294
28030
  if (error instanceof Error) {
@@ -28300,6 +28036,28 @@ function describeCaughtError(error) {
28300
28036
  function isStationChildOfficerDialogue(role, env) {
28301
28037
  return env.stationChild === true && isOfficerReviewSeat(role);
28302
28038
  }
28039
+ function projectRelocatedTurnIdentity(request, result, admitted, relocation) {
28040
+ const rewrite = (value) => rewriteRunDirectoryPathValue(
28041
+ value,
28042
+ relocation.oldRunDirectory,
28043
+ relocation.newRunDirectory
28044
+ );
28045
+ const mutableRequest = request;
28046
+ mutableRequest.runDirectory = admitted.runDirectory;
28047
+ mutableRequest.principal = admitted.principal;
28048
+ const activation = mutableRequest.activation;
28049
+ if (activation !== null && typeof activation === "object" && !Array.isArray(activation)) {
28050
+ for (const field of ["taskPath", "packetPath", "prerequisitesPath", "inputPath", "requestManifestPath"]) {
28051
+ const record4 = activation;
28052
+ if (field in record4) record4[field] = rewrite(record4[field]);
28053
+ }
28054
+ }
28055
+ if (result.terminal !== void 0) {
28056
+ for (const artifact of result.terminal.artifacts) {
28057
+ artifact.path = rewrite(artifact.path);
28058
+ }
28059
+ }
28060
+ }
28303
28061
  function withProcessCancelSkipAutoResume(result, signal) {
28304
28062
  if (processCancelSignalName(signal) === void 0) {
28305
28063
  return result;
@@ -28344,8 +28102,8 @@ function withOnceSuccessfulBeforeDispatch(adapters) {
28344
28102
  };
28345
28103
  }
28346
28104
  async function recordBestEffortPostDispatchDiagnostic(admitted, env, diagnostic, io) {
28347
- io.stderr(formatCliDiagnostic(diagnostic));
28348
28105
  const payload = { diagnostic, recordedAt: (/* @__PURE__ */ new Date()).toISOString() };
28106
+ let retentionFailure;
28349
28107
  try {
28350
28108
  await env.sessionAppender(
28351
28109
  env.principalAuthority,
@@ -28353,23 +28111,25 @@ async function recordBestEffortPostDispatchDiagnostic(admitted, env, diagnostic,
28353
28111
  POST_ADMISSION_CLEANUP_DIAGNOSTIC_ENTRY_TYPE,
28354
28112
  payload
28355
28113
  );
28356
- return;
28357
28114
  } catch (appendError) {
28358
28115
  try {
28359
28116
  const artifactsDir = await ensureRealArtifactsDirectory(admitted.runDirectory);
28360
- await writeFile9(
28117
+ await writeFile8(
28361
28118
  join29(artifactsDir, `post-admission-diagnostic-${randomUUID6()}.json`),
28362
28119
  `${JSON.stringify({ version: 1, ...payload }, null, 2)}
28363
28120
  `,
28364
28121
  { encoding: "utf8", flag: "wx" }
28365
28122
  );
28366
28123
  } catch (artifactError) {
28367
- io.stderr(
28368
- formatCliDiagnostic(
28369
- `post-dispatch diagnostic durable retention failed on both channels (best-effort continue): dossier=${describeErrorIdentity(appendError)}; artifact=${describeErrorIdentity(artifactError)}`
28370
- )
28371
- );
28124
+ retentionFailure = `post-dispatch diagnostic durable retention failed on both channels (best-effort continue): dossier=${describeErrorIdentity(appendError)}; artifact=${describeErrorIdentity(artifactError)}`;
28125
+ }
28126
+ }
28127
+ try {
28128
+ io.stderr(formatCliDiagnostic(diagnostic));
28129
+ if (retentionFailure !== void 0) {
28130
+ io.stderr(formatCliDiagnostic(retentionFailure));
28372
28131
  }
28132
+ } catch {
28373
28133
  }
28374
28134
  }
28375
28135
  async function resolveResumeMethodMaterialAdapters(input) {
@@ -28530,15 +28290,18 @@ async function dispatchPostAdmissionTurn(input) {
28530
28290
  const ticketNumber = asserted === void 0 ? void 0 : asserted.ticketNumber;
28531
28291
  if (ticketNumber !== void 0) await bindAdmittedTicketNumber(admitted, ticketNumber);
28532
28292
  }
28293
+ const relocation = await relocateAdmittedRunToTicket(admitted, env.principalAuthority, lease);
28294
+ if (relocation !== void 0) {
28295
+ projectRelocatedTurnIdentity(request, result, admitted, relocation);
28296
+ }
28533
28297
  if (adapters.afterDispatch !== void 0) await adapters.afterDispatch(admitted, lease);
28534
28298
  return result;
28535
28299
  } catch (error) {
28536
- const primaryFailure = result.terminal !== void 0 && !isLawfulTypedTerminalOutcome(result.terminal.roleOutcome);
28537
- if (primaryFailure) {
28300
+ if (result.terminal !== void 0) {
28538
28301
  await recordBestEffortPostDispatchDiagnostic(
28539
28302
  admitted,
28540
28303
  env,
28541
- `afterDispatch failed beside primary terminal (best-effort continue): ${describeErrorIdentity(error)}`,
28304
+ `afterDispatch failed beside host terminal (best-effort continue): ${describeErrorIdentity(error)}`,
28542
28305
  io
28543
28306
  );
28544
28307
  return result;
@@ -28564,23 +28327,6 @@ async function dispatchPostAdmissionTurn(input) {
28564
28327
  }
28565
28328
  };
28566
28329
  try {
28567
- const missingCredential = missingCredentialPreDispatchFailure(
28568
- env.model,
28569
- env.credentials
28570
- );
28571
- if (missingCredential !== void 0) {
28572
- return {
28573
- ...await presentControlledFailure2(
28574
- admitted,
28575
- withEngineDetourInvocationScope(missingCredential, request.invocationScopeId),
28576
- adapters,
28577
- env.principalAuthority,
28578
- io,
28579
- persistRunState
28580
- ),
28581
- ...deferredPersist
28582
- };
28583
- }
28584
28330
  let previousHost;
28585
28331
  const liveHost = env.host;
28586
28332
  const principalCoordinates = admitted.principal === void 0 ? void 0 : env.principalAuthority.decode(admitted.principal);
@@ -28688,7 +28434,7 @@ async function dispatchPostAdmissionTurn(input) {
28688
28434
  }
28689
28435
  let stderrLogWriteFailure;
28690
28436
  try {
28691
- await writeFile9(
28437
+ await writeFile8(
28692
28438
  join29(admitted.runDirectory, "stderr.log"),
28693
28439
  result.stderr,
28694
28440
  "utf8"
@@ -28713,19 +28459,14 @@ async function dispatchPostAdmissionTurn(input) {
28713
28459
  try {
28714
28460
  const sessionFile = admitted.principal !== void 0 ? env.principalAuthority.decode(admitted.principal).sessionFile : "";
28715
28461
  const runnerKnownFailure = adapters.resolveRunnerKnownFailure !== void 0 && sessionFile !== "" ? await adapters.resolveRunnerKnownFailure({ result, sessionFile }) : result.knownFailure;
28716
- const credentialFailure = postRunMissingCredentialFailure(
28717
- result,
28718
- env.model,
28719
- env.credentials
28720
- );
28721
28462
  resolution = await resolveAuditedRunnerFailureResolution({
28722
28463
  runner: runnerKnownFailure,
28723
28464
  sessionFile,
28724
- credential: credentialFailure,
28465
+ credential: void 0,
28725
28466
  runDirectory: admitted.runDirectory
28726
28467
  });
28727
28468
  const processCancelName = processCancelSignalName(env.signal);
28728
- const directHostFailureSignal = result.timedOut || result.knownFailure !== void 0 || runnerKnownFailure !== void 0 || credentialFailure !== void 0 || processCancelName !== void 0;
28469
+ const directHostFailureSignal = result.timedOut || result.knownFailure !== void 0 || runnerKnownFailure !== void 0 || processCancelName !== void 0;
28729
28470
  hostSignalFailed = directHostFailureSignal || result.code !== null && result.code !== 0 || resolution.knownFailure !== void 0;
28730
28471
  settled = await adapters.trySettle(admitted, env.principalAuthority, courtScope);
28731
28472
  if (settled !== void 0) {
@@ -28791,25 +28532,11 @@ async function dispatchPostAdmissionTurn(input) {
28791
28532
  try {
28792
28533
  await persistReturnedRunState(admitted, env.principalAuthority, { lawful: true });
28793
28534
  } catch (error) {
28794
- const failed = await settleAfterTurnStarted(
28535
+ await recordBestEffortPostDispatchDiagnostic(
28795
28536
  admitted,
28796
- withEngineDetourInvocationScope({
28797
- timedOut: false,
28798
- code: null,
28799
- stderr: "",
28800
- thrown: error,
28801
- skipRunStateWrite: true
28802
- }, request.invocationScopeId),
28803
- adapters,
28804
- env.principalAuthority,
28805
- io,
28806
- persistRunState
28807
- );
28808
- return await finishAfterTurn(
28809
- withProcessCancelSkipAutoResume(
28810
- { ...failed, turnDispatched: true, ...deferredPersist },
28811
- env.signal
28812
- )
28537
+ env,
28538
+ `run-state persistence failed beside host terminal (best-effort continue): ${describeErrorIdentity(error)}`,
28539
+ io
28813
28540
  );
28814
28541
  }
28815
28542
  }
@@ -28890,25 +28617,11 @@ async function dispatchPostAdmissionTurn(input) {
28890
28617
  try {
28891
28618
  await persistReturnedRunState(admitted, env.principalAuthority, { lawful: true });
28892
28619
  } catch (error) {
28893
- const failed = await settleAfterTurnStarted(
28620
+ await recordBestEffortPostDispatchDiagnostic(
28894
28621
  admitted,
28895
- withEngineDetourInvocationScope({
28896
- timedOut: false,
28897
- code: null,
28898
- stderr: "",
28899
- thrown: error,
28900
- skipRunStateWrite: true
28901
- }, request.invocationScopeId),
28902
- adapters,
28903
- env.principalAuthority,
28904
- io,
28905
- persistRunState
28906
- );
28907
- return await finishAfterTurn(
28908
- withProcessCancelSkipAutoResume(
28909
- { ...failed, turnDispatched: true, ...deferredPersist },
28910
- env.signal
28911
- )
28622
+ env,
28623
+ `run-state persistence failed beside host terminal (best-effort continue): ${describeErrorIdentity(error)}`,
28624
+ io
28912
28625
  );
28913
28626
  }
28914
28627
  }
@@ -28920,14 +28633,16 @@ async function dispatchPostAdmissionTurn(input) {
28920
28633
  ...deferredPersist
28921
28634
  });
28922
28635
  } finally {
28923
- try {
28924
- await lease.release();
28925
- } catch (error) {
28926
- io.stderr(
28927
- formatCliDiagnostic(
28928
- `writer lease release failed unexpectedly (best-effort continue): ${describeErrorIdentity(error)}`
28929
- )
28930
- );
28636
+ if (lease !== void 0) {
28637
+ try {
28638
+ await lease.release();
28639
+ } catch (error) {
28640
+ io.stderr(
28641
+ formatCliDiagnostic(
28642
+ `writer lease release failed unexpectedly (best-effort continue): ${describeErrorIdentity(error)}`
28643
+ )
28644
+ );
28645
+ }
28931
28646
  }
28932
28647
  }
28933
28648
  }
@@ -29242,53 +28957,29 @@ async function runPostAdmissionManualResume(input) {
29242
28957
  } = input;
29243
28958
  let request = input.request;
29244
28959
  const effectiveModel = env.model;
29245
- let lease;
29246
- let staleWriterLeaseReclaimed;
29247
- try {
29248
- lease = await acquireRunWriterLease(admitted.runDirectory, (diagnostic, kind) => {
29249
- if (kind === "stale-reclaimed") staleWriterLeaseReclaimed = true;
29250
- io.stderr(diagnostic);
29251
- });
29252
- } catch (error) {
29253
- if (error instanceof RunWriterLeaseHeldError) {
29254
- io.stderr(formatCliDiagnostic(error.message));
29255
- return {
29256
- exitCode: 1,
29257
- ...staleWriterLeaseReclaimed === true ? { staleWriterLeaseReclaimed: true } : {}
29258
- };
29259
- }
29260
- throw error;
29261
- }
29262
28960
  const invocationScopeId = mintEngineDetourInvocationScope({
29263
28961
  ...effectiveEngine === void 0 ? {} : { effectiveEngine }
29264
28962
  });
29265
- const result = await dispatchAfterWriterLease({
29266
- lease,
29267
- build: async () => {
29268
- if (request === void 0) {
29269
- if (buildRequestAfterLease === void 0) {
29270
- throw new Error(
29271
- "runPostAdmissionManualResume requires request or buildRequestAfterLease"
29272
- );
29273
- }
29274
- request = await buildRequestAfterLease();
29275
- }
29276
- request = withEngineDetourInvocationScope(request, invocationScopeId);
29277
- return request;
28963
+ if (request === void 0) {
28964
+ if (buildRequestAfterLease === void 0) {
28965
+ throw new Error(
28966
+ "runPostAdmissionManualResume requires request or buildRequestAfterLease"
28967
+ );
28968
+ }
28969
+ request = await buildRequestAfterLease();
28970
+ }
28971
+ request = withEngineDetourInvocationScope(request, invocationScopeId);
28972
+ const result = await dispatchPostAdmissionTurn({
28973
+ admitted,
28974
+ env: {
28975
+ ...env,
28976
+ ...effectiveModel === void 0 ? {} : { model: effectiveModel },
28977
+ ...admitted.correlationId === void 0 ? {} : { correlationId: admitted.correlationId }
29278
28978
  },
29279
- dispatch: (turnRequest) => dispatchPostAdmissionTurn({
29280
- admitted,
29281
- env: {
29282
- ...env,
29283
- ...effectiveModel === void 0 ? {} : { model: effectiveModel },
29284
- ...admitted.correlationId === void 0 ? {} : { correlationId: admitted.correlationId }
29285
- },
29286
- io,
29287
- request: turnRequest,
29288
- lease,
29289
- adapters,
29290
- ...effectiveEngine === void 0 ? {} : { effectiveEngine }
29291
- })
28979
+ io,
28980
+ request,
28981
+ adapters,
28982
+ ...effectiveEngine === void 0 ? {} : { effectiveEngine }
29292
28983
  });
29293
28984
  if (result.terminal !== void 0 && isLawfulTypedTerminalOutcome(result.terminal.roleOutcome)) {
29294
28985
  io.stdout(formatTerminalResult(result.terminal));
@@ -29296,10 +28987,7 @@ async function runPostAdmissionManualResume(input) {
29296
28987
  if (result.terminal !== void 0) {
29297
28988
  result.terminal.autoResumeCount = 0;
29298
28989
  }
29299
- return {
29300
- ...result,
29301
- ...staleWriterLeaseReclaimed === true ? { staleWriterLeaseReclaimed: true } : {}
29302
- };
28990
+ return result;
29303
28991
  }
29304
28992
  var StationChildExhaustedError, POST_ADMISSION_CLEANUP_DIAGNOSTIC_ENTRY_TYPE;
29305
28993
  var init_post_admission = __esm({
@@ -29312,11 +29000,11 @@ var init_post_admission = __esm({
29312
29000
  init_activation_ledger_topology();
29313
29001
  init_engine_material();
29314
29002
  init_session_identity();
29003
+ init_role_run_relocation();
29315
29004
  init_host_contracts();
29316
29005
  init_case_dossier_delivery();
29317
29006
  init_engine_detour_usage();
29318
29007
  init_host_transition_prior_native();
29319
- init_public_run_credentials();
29320
29008
  init_run_lifecycle();
29321
29009
  init_process_cancel();
29322
29010
  init_activation_ledger_topology();
@@ -30966,7 +30654,7 @@ __export(public_role_summons_exports, {
30966
30654
  withEphemeralReviewerWorktree: () => withEphemeralReviewerWorktree
30967
30655
  });
30968
30656
  import { execFile as execFile3 } from "node:child_process";
30969
- import { existsSync as existsSync10 } from "node:fs";
30657
+ import { existsSync as existsSync9 } from "node:fs";
30970
30658
  import { mkdir as mkdir4, mkdtemp as mkdtemp3, realpath as realpath6, rm as rm4 } from "node:fs/promises";
30971
30659
  import { tmpdir as tmpdir3 } from "node:os";
30972
30660
  import { join as join30, relative as relative3, sep as sep5 } from "node:path";
@@ -30993,7 +30681,7 @@ function parentDir(path) {
30993
30681
  function walkPackageRoot(start) {
30994
30682
  let dir = start;
30995
30683
  for (let i = 0; i < 12; i += 1) {
30996
- if (existsSync10(join30(dir, "package.json")) && existsSync10(join30(dir, "souls"))) {
30684
+ if (existsSync9(join30(dir, "package.json")) && existsSync9(join30(dir, "souls"))) {
30997
30685
  return dir;
30998
30686
  }
30999
30687
  const parent = parentDir(dir);
@@ -32858,13 +32546,13 @@ var init_analyst_book_key = __esm({
32858
32546
 
32859
32547
  // src/atomic-write.ts
32860
32548
  import { randomUUID as randomUUID7 } from "node:crypto";
32861
- import { rename as rename3, rm as rm5, writeFile as writeFile10 } from "node:fs/promises";
32549
+ import { rename as rename3, rm as rm5, writeFile as writeFile9 } from "node:fs/promises";
32862
32550
  import { dirname as dirname16, join as join31 } from "node:path";
32863
32551
  async function writeFileAtomically(destination, contents) {
32864
32552
  const parent = dirname16(destination);
32865
32553
  const temporary = join31(parent, `.atomic-write-${randomUUID7()}.tmp`);
32866
32554
  try {
32867
- await writeFile10(temporary, contents);
32555
+ await writeFile9(temporary, contents);
32868
32556
  await rename3(temporary, destination);
32869
32557
  } catch (error) {
32870
32558
  await rm5(temporary, { force: true }).catch(() => void 0);
@@ -32878,7 +32566,7 @@ var init_atomic_write = __esm({
32878
32566
  });
32879
32567
 
32880
32568
  // src/analyst-index.ts
32881
- import { open as open3, readFile as readFile19, unlink as unlink4 } from "node:fs/promises";
32569
+ import { open as open3, readFile as readFile18, unlink as unlink4 } from "node:fs/promises";
32882
32570
  import { dirname as dirname17, join as join32 } from "node:path";
32883
32571
  function sleep(ms) {
32884
32572
  return new Promise((resolve11) => {
@@ -33006,7 +32694,7 @@ async function readAnalystLibraryIndexPage(ledgerHome) {
33006
32694
  const path = analystLibraryIndexPath(ledgerHome);
33007
32695
  let raw;
33008
32696
  try {
33009
- raw = await readFile19(path, "utf8");
32697
+ raw = await readFile18(path, "utf8");
33010
32698
  } catch (error) {
33011
32699
  if (error instanceof Error && "code" in error && (error.code === "ENOENT" || error.code === "ENOTDIR")) {
33012
32700
  return void 0;
@@ -33210,7 +32898,7 @@ var init_analyst_cohort = __esm({
33210
32898
  });
33211
32899
 
33212
32900
  // src/analyst-ledger.ts
33213
- import { readdir as readdir9, readFile as readFile20 } from "node:fs/promises";
32901
+ import { readdir as readdir8, readFile as readFile19 } from "node:fs/promises";
33214
32902
  import { basename as basename8, join as join33 } from "node:path";
33215
32903
  function isMissingPathError6(error) {
33216
32904
  return error instanceof Error && "code" in error && (error.code === "ENOENT" || error.code === "ENOTDIR");
@@ -33224,7 +32912,7 @@ function isRecord12(value) {
33224
32912
  async function readExistingRunLifecycleState(runDirectory) {
33225
32913
  try {
33226
32914
  const raw = JSON.parse(
33227
- await readFile20(join33(runDirectory, "run-state.json"), "utf8")
32915
+ await readFile19(join33(runDirectory, "run-state.json"), "utf8")
33228
32916
  );
33229
32917
  if (!isRecord12(raw) || typeof raw.state !== "string") return void 0;
33230
32918
  return raw.state;
@@ -33274,7 +32962,7 @@ function tryResolveBookKeyFromProjectRoot(projectRoot) {
33274
32962
  }
33275
32963
  async function listLedgerBookNames(booksRoot) {
33276
32964
  try {
33277
- const entries = await readdir9(booksRoot, { withFileTypes: true });
32965
+ const entries = await readdir8(booksRoot, { withFileTypes: true });
33278
32966
  return entries.filter((e) => e.isDirectory()).map((e) => e.name).sort();
33279
32967
  } catch (error) {
33280
32968
  if (isMissingPathError6(error)) return [];
@@ -33284,7 +32972,7 @@ async function listLedgerBookNames(booksRoot) {
33284
32972
  async function readInvocationScopeFields(runDirectory) {
33285
32973
  let raw;
33286
32974
  try {
33287
- raw = await readFile20(join33(runDirectory, "invocation.json"), "utf8");
32975
+ raw = await readFile19(join33(runDirectory, "invocation.json"), "utf8");
33288
32976
  } catch (error) {
33289
32977
  if (isMissingPathError6(error)) return void 0;
33290
32978
  throw error;
@@ -33317,7 +33005,7 @@ function decideIssueScope(input) {
33317
33005
  }
33318
33006
  async function resolveSessionFile(runDirectory) {
33319
33007
  try {
33320
- const raw = await readFile20(join33(runDirectory, "invocation.json"), "utf8");
33008
+ const raw = await readFile19(join33(runDirectory, "invocation.json"), "utf8");
33321
33009
  const parsed = JSON.parse(raw);
33322
33010
  if (isRecord12(parsed) && typeof parsed.sessionFile === "string" && parsed.sessionFile.trim() !== "") {
33323
33011
  return parsed.sessionFile;
@@ -34604,7 +34292,7 @@ var init_analyst_page = __esm({
34604
34292
  });
34605
34293
 
34606
34294
  // src/analyst-entry.ts
34607
- import { readFile as readFile21 } from "node:fs/promises";
34295
+ import { readFile as readFile20 } from "node:fs/promises";
34608
34296
  function isMissingPathError7(error) {
34609
34297
  return error instanceof Error && "code" in error && (error.code === "ENOENT" || error.code === "ENOTDIR");
34610
34298
  }
@@ -34634,7 +34322,7 @@ async function readOrComputeAnalystIssuePage(input, options) {
34634
34322
  ...issueNumber === void 0 && input.bookKey === void 0 ? { scopeRootIdentity: projectRoot } : {}
34635
34323
  });
34636
34324
  try {
34637
- const raw = await readFile21(pagePath, "utf8");
34325
+ const raw = await readFile20(pagePath, "utf8");
34638
34326
  const page = JSON.parse(raw);
34639
34327
  if (cachedPageMatchesRequestedScope(page, { bookKey, ...input })) {
34640
34328
  const ghostScan = await scanAnalystIssueRuns({
@@ -34735,7 +34423,7 @@ async function runAnalystModelGroupsMode(input, home) {
34735
34423
  scopeRootIdentity: projectRoot
34736
34424
  });
34737
34425
  try {
34738
- const raw = await readFile21(pagePath, "utf8");
34426
+ const raw = await readFile20(pagePath, "utf8");
34739
34427
  JSON.parse(raw);
34740
34428
  } catch (error) {
34741
34429
  if (!isMissingPathError7(error)) {
@@ -34834,7 +34522,7 @@ var init_analyst_entry = __esm({
34834
34522
  });
34835
34523
 
34836
34524
  // src/public-cli/analyst-run.ts
34837
- import { readFile as readFile22 } from "node:fs/promises";
34525
+ import { readFile as readFile21 } from "node:fs/promises";
34838
34526
  import { isAbsolute as isAbsolute10, resolve as resolve10 } from "node:path";
34839
34527
  function resolveAnalystIssueBookKeyFromCwd(cwd = process.cwd()) {
34840
34528
  try {
@@ -34887,7 +34575,7 @@ async function buildAnalystSweepModeInputFromAttachmentPaths(attachmentPaths) {
34887
34575
  const absolute = isAbsolute10(sourcePath) ? sourcePath : resolve10(sourcePath);
34888
34576
  let bytes;
34889
34577
  try {
34890
- bytes = await readFile22(absolute);
34578
+ bytes = await readFile21(absolute);
34891
34579
  } catch (error) {
34892
34580
  throw new CliUsageError(
34893
34581
  `analyst sweep attachment is not a readable regular file: ${sourcePath}`,
@@ -35123,8 +34811,7 @@ async function dispatchPublicRoleCommand(env, home, io, parsed, role, parse, run
35123
34811
  function cliResultFromRoleRun(result) {
35124
34812
  return {
35125
34813
  exitCode: result.exitCode,
35126
- ...result.terminal === void 0 ? {} : { terminal: result.terminal },
35127
- ...result.staleWriterLeaseReclaimed === true ? { staleWriterLeaseReclaimed: true } : {}
34814
+ ...result.terminal === void 0 ? {} : { terminal: result.terminal }
35128
34815
  };
35129
34816
  }
35130
34817
  function defaultIo() {
@@ -36041,7 +35728,7 @@ var init_cli = __esm({
36041
35728
  });
36042
35729
 
36043
35730
  // src/public-cli/main.ts
36044
- import { existsSync as existsSync11 } from "node:fs";
35731
+ import { existsSync as existsSync10 } from "node:fs";
36045
35732
  import { dirname as dirname19, join as join36 } from "node:path";
36046
35733
  import { fileURLToPath as fileURLToPath2 } from "node:url";
36047
35734
 
@@ -36132,7 +35819,7 @@ function linkPackage(packageRoot2, name, targetDir) {
36132
35819
  var here = dirname19(fileURLToPath2(import.meta.url));
36133
35820
  function resolvePackageRoot(binDir) {
36134
35821
  const canonical = join36(binDir, "..", "..");
36135
- if (existsSync11(join36(canonical, "package.json"))) {
35822
+ if (existsSync10(join36(canonical, "package.json"))) {
36136
35823
  return canonical;
36137
35824
  }
36138
35825
  return binDir;