@akagilnc/pi-workflow-roles 0.1.5775 → 0.1.5797

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/dist/acp-host/production-host.js +556 -209
  2. package/dist/external-host-turn-loop.js +3 -0
  3. package/dist/headless-host/production-host.js +529 -182
  4. package/dist/migrate-book-topology.js +63 -23
  5. package/dist/pi/role-turn-host.js +6 -1
  6. package/dist/public-cli/instruction-seat-run.js +10 -7
  7. package/dist/public-cli/invocation.js +95 -39
  8. package/dist/public-cli/main.js +357 -147
  9. package/dist/public-cli/post-admission.js +2 -0
  10. package/dist/public-cli/run-lifecycle.js +10 -4
  11. package/dist/public-cli/turn-request.js +3 -0
  12. package/dist/report-ticket-tool.js +3 -3
  13. package/dist/role-run-placement.js +14 -2
  14. package/dist/role-run-relocation.js +2 -2
  15. package/dist/run-dossier.js +5 -4
  16. package/dist/session-identity.js +3 -2
  17. package/dist/sitian-appender.js +12 -3
  18. package/dist/submission-ledger.js +24 -0
  19. package/dist/ticket-progress.js +306 -0
  20. package/dist/user-dialogue-stdin.js +23 -17
  21. package/package.json +1 -1
  22. package/src/external-host-turn-loop.ts +7 -1
  23. package/src/host-contracts.ts +1 -1
  24. package/src/pi/adapter.ts +57 -45
  25. package/src/pi/role-turn-host.ts +6 -1
  26. package/src/prepared-role-turn.ts +6 -0
  27. package/src/public-cli/instruction-seat-run.ts +10 -7
  28. package/src/public-cli/invocation.ts +116 -38
  29. package/src/public-cli/post-admission.ts +3 -1
  30. package/src/public-cli/run-lifecycle.ts +10 -8
  31. package/src/public-cli/turn-request.ts +3 -0
  32. package/src/report-ticket-tool.ts +7 -3
  33. package/src/role-envelope.ts +5 -0
  34. package/src/role-run-placement.ts +19 -2
  35. package/src/role-run-relocation.ts +2 -2
  36. package/src/role-runtime.ts +14 -3
  37. package/src/run-dossier.ts +5 -3
  38. package/src/run-terminal-artifacts.ts +0 -1
  39. package/src/session-identity.ts +3 -2
  40. package/src/sitian-appender.ts +14 -3
  41. package/src/submission-ledger.ts +27 -0
  42. package/src/ticket-progress.ts +383 -0
  43. package/src/user-dialogue-stdin.ts +21 -14
@@ -711,6 +711,12 @@ function appendSitianRecordBlock(input, block) {
711
711
  function resolveSitianVolumeCategory(kind) {
712
712
  return kind;
713
713
  }
714
+ function runDirectoryOwningSessionParent(sessionParentDir) {
715
+ if (basename3(sessionParentDir) !== "session") return void 0;
716
+ const runDirectory = dirname3(sessionParentDir);
717
+ if (parseRunLeaf(basename3(runDirectory)) === void 0) return void 0;
718
+ return runDirectory;
719
+ }
714
720
  function sitianVolumeDirectory(sessionDirectory, category) {
715
721
  return join3(sessionDirectory, category);
716
722
  }
@@ -742,8 +748,8 @@ function resolveSitianRecordPathInLedger(input, ledgerHome) {
742
748
  throw new Error("Sitian record ownership requires a parent session inside the ledger home");
743
749
  }
744
750
  const sessionParentDir = dirname3(input.sessionParent);
745
- const runDirectory = dirname3(sessionParentDir);
746
- if (basename3(sessionParentDir) === "session" && parseRunLeaf(basename3(runDirectory)) !== void 0) {
751
+ const runDirectory = runDirectoryOwningSessionParent(sessionParentDir);
752
+ if (runDirectory !== void 0) {
747
753
  sessionDir = runDirectory;
748
754
  recordFile = join3(runDirectory, RUN_HISTORY_KINDS.has(input.kind) ? RUN_HISTORY_FILE : RUN_STATE_KINDS.has(input.kind) ? RUN_STATE_FILE : RUN_LOG_FILE);
749
755
  } else {
@@ -976,7 +982,9 @@ function render(runDirectory, history, state, log, unreadable) {
976
982
  original = payload.landingPath;
977
983
  }
978
984
  }
979
- if (typeof original === "string") original = join4(runDirectory, "session", basename4(original));
985
+ if (typeof original === "string") {
986
+ original = join4(sessionDirectoryOf(runDirectory), basename4(original));
987
+ }
980
988
  whole.host = { sessions, ...original === void 0 ? {} : { original } };
981
989
  whole.submission = latest === void 0 ? {} : { latest };
982
990
  if (Object.keys(unreadable).length > 0) whole.unreadable = unreadable;
@@ -1214,6 +1222,16 @@ function parseRunLeaf(name) {
1214
1222
  if (at <= 0 || at === name.length - 1) return void 0;
1215
1223
  return { runId: name.slice(0, at), role: name.slice(at + 1) };
1216
1224
  }
1225
+ function subjectDirectoryOfRun(runDirectory) {
1226
+ const runsParent = dirname4(runDirectory);
1227
+ if (basename5(runsParent) !== "runs") return void 0;
1228
+ const subjectDirectory = dirname4(runsParent);
1229
+ const subjectName = basename5(subjectDirectory);
1230
+ if (subjectName === "unbound" || /^[1-9]\d*$/.test(subjectName)) {
1231
+ return subjectDirectory;
1232
+ }
1233
+ return void 0;
1234
+ }
1217
1235
  function sessionDirectoryOf(runDirectory) {
1218
1236
  return join6(runDirectory, "session");
1219
1237
  }
@@ -1306,6 +1324,7 @@ function ensureRoleRunDirectory(ledgerHome, directory) {
1306
1324
  return ensureRealDirectoryTree(ledgerHome, directory);
1307
1325
  }
1308
1326
  function ensureRoleRunPlacement(ledgerHome, placement) {
1327
+ ensureRoleRunDirectory(ledgerHome, placement.runDirectory);
1309
1328
  ensureRoleRunDirectory(ledgerHome, placement.sessionDirectory);
1310
1329
  }
1311
1330
  var ROLE_RUN_SESSION_FILENAME;
@@ -4110,7 +4129,8 @@ var init_role_activation_flags = __esm({
4110
4129
 
4111
4130
  // src/user-dialogue-stdin.ts
4112
4131
  function encodeUserDialogueStdin(body) {
4113
- return JSON.stringify({ kind: USER_DIALOGUE_STDIN_KIND, body });
4132
+ const envelope = { kind: USER_DIALOGUE_STDIN_KIND, body };
4133
+ return JSON.stringify(envelope);
4114
4134
  }
4115
4135
  var USER_DIALOGUE_STDIN_KIND;
4116
4136
  var init_user_dialogue_stdin = __esm({
@@ -4485,17 +4505,6 @@ var init_submission_correctable_error = __esm({
4485
4505
  }
4486
4506
  });
4487
4507
 
4488
- // src/sha256.ts
4489
- import { createHash } from "node:crypto";
4490
- function sha256Hex(bytes) {
4491
- return createHash("sha256").update(bytes).digest("hex");
4492
- }
4493
- var init_sha256 = __esm({
4494
- "src/sha256.ts"() {
4495
- "use strict";
4496
- }
4497
- });
4498
-
4499
4508
  // src/package-contracts/terminating-tools.ts
4500
4509
  function isTerminatingToolName(name) {
4501
4510
  return TERMINATING_TOOL_NAMES.includes(name);
@@ -4556,9 +4565,256 @@ var init_terminating_tools = __esm({
4556
4565
  }
4557
4566
  });
4558
4567
 
4568
+ // src/ticket-progress.ts
4569
+ import { spawnSync as spawnSync2 } from "node:child_process";
4570
+ import {
4571
+ appendFileSync as appendFileSync2,
4572
+ existsSync as existsSync2,
4573
+ mkdirSync as mkdirSync3,
4574
+ readFileSync as readFileSync2,
4575
+ readdirSync as readdirSync2,
4576
+ rmSync as rmSync3,
4577
+ writeFileSync as writeFileSync2
4578
+ } from "node:fs";
4579
+ import { basename as basename7, dirname as dirname6, join as join8, relative as relative2, sep as sep3 } from "node:path";
4580
+ function parseProgressText(text, pathForDiagnostic) {
4581
+ if (text.trim() === "") return [];
4582
+ const { records, diagnostics } = parseSitianRecordText(text);
4583
+ for (const diagnostic of diagnostics) {
4584
+ process.stderr.write(
4585
+ `[ticket-progress] ${pathForDiagnostic} has malformed row(s); keeps reachable rows and retains the diagnostic: line ${diagnostic.line}: ${diagnostic.error}
4586
+ `
4587
+ );
4588
+ }
4589
+ const lines = [];
4590
+ for (const record of records) {
4591
+ const parsed = record;
4592
+ if (!isRecord(parsed)) continue;
4593
+ if (typeof parsed.seat !== "string" || typeof parsed.round !== "string") continue;
4594
+ lines.push(parsed);
4595
+ }
4596
+ return lines;
4597
+ }
4598
+ function readProgressFile(path) {
4599
+ if (!existsSync2(path)) return [];
4600
+ return parseProgressText(readFileSync2(path, "utf8"), path);
4601
+ }
4602
+ function readTicketProgressLines(subjectDirectory) {
4603
+ if (basename7(subjectDirectory) === "unbound") {
4604
+ const runsDir = join8(subjectDirectory, "runs");
4605
+ if (!existsSync2(runsDir)) return [];
4606
+ const out = [];
4607
+ for (const name of readdirSync2(runsDir).sort()) {
4608
+ out.push(...readProgressFile(join8(runsDir, name, LEG_PROGRESS_FILENAME)));
4609
+ }
4610
+ return out;
4611
+ }
4612
+ return readProgressFile(join8(subjectDirectory, CURRENT_FILENAME));
4613
+ }
4614
+ function roundBaseNumber(round) {
4615
+ if (round.trim() === "") return 0;
4616
+ const base = round.includes(".") ? round.slice(0, round.indexOf(".")) : round;
4617
+ const n = Number(base);
4618
+ return Number.isSafeInteger(n) && n > 0 ? n : 0;
4619
+ }
4620
+ function roundLens(round) {
4621
+ return round.includes(".") ? round.slice(round.indexOf(".") + 1) : void 0;
4622
+ }
4623
+ function nextRoundFromLines(lines, seat, lens) {
4624
+ const want = lens === void 0 || lens.trim() === "" ? void 0 : lens;
4625
+ let max = 0;
4626
+ for (const line2 of lines) {
4627
+ if (line2.seat !== seat) continue;
4628
+ if (roundLens(line2.round) !== want) continue;
4629
+ max = Math.max(max, roundBaseNumber(line2.round));
4630
+ }
4631
+ const base = max + 1;
4632
+ return want === void 0 ? String(base) : `${base}.${want}`;
4633
+ }
4634
+ function nextLegReceiptIndex(runDirectory) {
4635
+ const dir = join8(runDirectory, RECEIPTS_DIRNAME);
4636
+ if (!existsSync2(dir)) return 1;
4637
+ let max = 0;
4638
+ for (const name of readdirSync2(dir)) {
4639
+ const match = /^(\d+)\.json$/.exec(name);
4640
+ if (match === null) continue;
4641
+ const n = Number(match[1]);
4642
+ if (Number.isSafeInteger(n) && n > max) max = n;
4643
+ }
4644
+ return max + 1;
4645
+ }
4646
+ function statusAndSummaryFromPayload(seat, payload) {
4647
+ if (!isRecord(payload)) return {};
4648
+ const toolName = packagedRoleOutputTool(seat);
4649
+ const status = toolName !== void 0 && isTerminatingToolName(toolName) ? acceptedFacts(toolName, payload).status : void 0;
4650
+ const summary = typeof payload.summary === "string" ? payload.summary : void 0;
4651
+ return {
4652
+ ...status === void 0 ? {} : { status },
4653
+ ...summary === void 0 ? {} : { summary }
4654
+ };
4655
+ }
4656
+ function captureWorktreeHead(projectRoot) {
4657
+ try {
4658
+ const result = spawnSync2("git", ["rev-parse", "HEAD"], {
4659
+ cwd: projectRoot,
4660
+ encoding: "utf8",
4661
+ maxBuffer: 1024 * 1024
4662
+ });
4663
+ if (result.error != null) {
4664
+ const err = result.error;
4665
+ const detail = err instanceof Error ? err.stack ?? err.message : String(err);
4666
+ return { head: "", fault: `git rev-parse HEAD spawn failed cwd=${projectRoot}: ${detail}` };
4667
+ }
4668
+ if (result.status !== 0) {
4669
+ const detail = [result.stderr, result.stdout].map((part) => typeof part === "string" ? part.trim() : "").filter((part) => part !== "").join(" | ");
4670
+ const status = result.status === null ? "null" : String(result.status);
4671
+ const signal = result.signal == null ? "" : ` signal=${result.signal}`;
4672
+ return {
4673
+ head: "",
4674
+ fault: detail === "" ? `git rev-parse HEAD failed (status=${status}${signal}) cwd=${projectRoot}` : `git rev-parse HEAD failed (status=${status}${signal}) cwd=${projectRoot}: ${detail}`
4675
+ };
4676
+ }
4677
+ return { head: (result.stdout ?? "").trim() };
4678
+ } catch (error) {
4679
+ const message = error instanceof Error ? error.stack ?? error.message : String(error);
4680
+ return { head: "", fault: `git rev-parse HEAD threw cwd=${projectRoot}: ${message}` };
4681
+ }
4682
+ }
4683
+ function progressSessionAbsolute(runDirectory, context) {
4684
+ const host = typeof context.host === "string" ? context.host.trim() : "";
4685
+ const sessionDirectory = sessionDirectoryOf(runDirectory);
4686
+ if (host !== "" && host !== "pi" && host !== "hermes") {
4687
+ return resolveHostDossierLandingPath({ host, sessionDirectory });
4688
+ }
4689
+ const issued = context.sessionManager.getSessionFile?.();
4690
+ if (typeof issued === "string" && issued.trim() !== "") {
4691
+ return issued;
4692
+ }
4693
+ return sessionFileOf(runDirectory);
4694
+ }
4695
+ function lensFromRunDirectory(runDirectory, role) {
4696
+ if (role !== "reviewer") return void 0;
4697
+ const lens = readPageSync(runDirectory, "admitted")?.lens;
4698
+ return lens === "completeness" || lens === "correctness" ? lens : void 0;
4699
+ }
4700
+ function landTicketProgressForSealedSubmission(input) {
4701
+ const runDirectory = runDirectoryFromHostContext(input.context);
4702
+ if (runDirectory === void 0) return void 0;
4703
+ const subjectDirectory = subjectDirectoryOfRun(runDirectory);
4704
+ if (subjectDirectory === void 0) return void 0;
4705
+ const lens = input.lens === "completeness" || input.lens === "correctness" ? input.lens : lensFromRunDirectory(runDirectory, input.role);
4706
+ const leaf = basename7(runDirectory);
4707
+ const unbound = basename7(subjectDirectory) === "unbound";
4708
+ const progressPath = unbound ? join8(runDirectory, LEG_PROGRESS_FILENAME) : join8(subjectDirectory, CURRENT_FILENAME);
4709
+ const receiptIndex = nextLegReceiptIndex(runDirectory);
4710
+ const relativePath = `runs/${leaf}/${RECEIPTS_DIRNAME}/${receiptIndex}.json`;
4711
+ const absolutePath = join8(subjectDirectory, relativePath);
4712
+ mkdirSync3(dirname6(absolutePath), { recursive: true });
4713
+ writeFileSync2(absolutePath, `${JSON.stringify(input.accepted, null, 2)}
4714
+ `, "utf8");
4715
+ if (!unbound) {
4716
+ relocateTicketProgressForLeg({ runDirectory });
4717
+ }
4718
+ const existing = unbound ? readProgressFile(progressPath) : readTicketProgressLines(subjectDirectory);
4719
+ const round = unbound ? "" : nextRoundFromLines(existing, input.role, lens);
4720
+ const sessionFile = progressSessionAbsolute(runDirectory, input.context);
4721
+ const sessionRelative = relative2(subjectDirectory, sessionFile).split(sep3).join("/");
4722
+ const { status, summary } = statusAndSummaryFromPayload(input.role, input.accepted);
4723
+ const instruction = typeof input.context.summonsInstruction === "string" ? input.context.summonsInstruction : "";
4724
+ const line2 = {
4725
+ at: (/* @__PURE__ */ new Date()).toISOString(),
4726
+ seat: input.role,
4727
+ round,
4728
+ instruction,
4729
+ head: input.sealHead.head,
4730
+ ...status === void 0 ? {} : { status },
4731
+ ...summary === void 0 ? {} : { summary },
4732
+ receipt: relativePath,
4733
+ session: sessionRelative
4734
+ };
4735
+ mkdirSync3(dirname6(progressPath), { recursive: true });
4736
+ appendFileSync2(progressPath, `${JSON.stringify(line2)}
4737
+ `, "utf8");
4738
+ if (input.sealHead.fault !== void 0) {
4739
+ process.stderr.write(`${input.sealHead.fault}
4740
+ `);
4741
+ }
4742
+ return line2;
4743
+ }
4744
+ function relocateTicketProgressForLeg(input) {
4745
+ if (isUnboundRunDirectory(input.runDirectory)) return;
4746
+ const subjectDirectory = subjectDirectoryOfRun(input.runDirectory);
4747
+ if (subjectDirectory === void 0) return;
4748
+ const stagedPath = join8(input.runDirectory, LEG_PROGRESS_FILENAME);
4749
+ const mine = readProgressFile(stagedPath);
4750
+ if (mine.length === 0) {
4751
+ if (existsSync2(stagedPath)) {
4752
+ rmSync3(stagedPath, { force: true });
4753
+ }
4754
+ return;
4755
+ }
4756
+ const ticketLines = [...readTicketProgressLines(subjectDirectory)];
4757
+ const publishedReceipts = new Set(
4758
+ ticketLines.map((line2) => line2.receipt).filter((receipt) => typeof receipt === "string" && receipt !== "")
4759
+ );
4760
+ const pending = mine.filter((line2) => !publishedReceipts.has(line2.receipt));
4761
+ if (pending.length === 0) {
4762
+ rmSync3(stagedPath, { force: true });
4763
+ return;
4764
+ }
4765
+ const movedLines = [];
4766
+ for (const line2 of pending) {
4767
+ const lens = lensFromRunDirectory(input.runDirectory, line2.seat);
4768
+ const round = nextRoundFromLines(ticketLines, line2.seat, lens);
4769
+ const moved = {
4770
+ ...line2,
4771
+ round
4772
+ };
4773
+ movedLines.push(moved);
4774
+ ticketLines.push(moved);
4775
+ }
4776
+ const newCurrent = join8(subjectDirectory, CURRENT_FILENAME);
4777
+ mkdirSync3(dirname6(newCurrent), { recursive: true });
4778
+ appendFileSync2(
4779
+ newCurrent,
4780
+ `${movedLines.map((line2) => JSON.stringify(line2)).join("\n")}
4781
+ `,
4782
+ "utf8"
4783
+ );
4784
+ rmSync3(stagedPath, { force: true });
4785
+ }
4786
+ var CURRENT_FILENAME, RECEIPTS_DIRNAME, LEG_PROGRESS_FILENAME;
4787
+ var init_ticket_progress = __esm({
4788
+ "src/ticket-progress.ts"() {
4789
+ "use strict";
4790
+ init_host_session_record();
4791
+ init_host_contracts();
4792
+ init_terminating_tools();
4793
+ init_packaged_role_registry();
4794
+ init_role_run_placement();
4795
+ init_run_dossier();
4796
+ init_sitian_reader();
4797
+ init_unknown_value();
4798
+ CURRENT_FILENAME = "current.jsonl";
4799
+ RECEIPTS_DIRNAME = "receipts";
4800
+ LEG_PROGRESS_FILENAME = "progress.jsonl";
4801
+ }
4802
+ });
4803
+
4804
+ // src/sha256.ts
4805
+ import { createHash } from "node:crypto";
4806
+ function sha256Hex(bytes) {
4807
+ return createHash("sha256").update(bytes).digest("hex");
4808
+ }
4809
+ var init_sha256 = __esm({
4810
+ "src/sha256.ts"() {
4811
+ "use strict";
4812
+ }
4813
+ });
4814
+
4559
4815
  // src/doctor-evidence.ts
4560
4816
  import { readdir as readdir2, readFile as readFile4, realpath, stat } from "node:fs/promises";
4561
- import { dirname as dirname6, relative as relative2, resolve as resolve4, sep as sep3 } from "node:path";
4817
+ import { dirname as dirname7, relative as relative3, resolve as resolve4, sep as sep4 } from "node:path";
4562
4818
  async function discoverCaseFiles(root) {
4563
4819
  const found = [];
4564
4820
  async function walk(dir, depth) {
@@ -4587,11 +4843,11 @@ async function stableRunsIdentity(root) {
4587
4843
  while (true) {
4588
4844
  try {
4589
4845
  const git3 = await stat(resolve4(cursor, ".git"));
4590
- if (git3.isDirectory() || git3.isFile()) return relative2(cursor, root).split(sep3).join("/");
4846
+ if (git3.isDirectory() || git3.isFile()) return relative3(cursor, root).split(sep4).join("/");
4591
4847
  } catch (error) {
4592
4848
  if (!isMissingPathError(error)) throw error;
4593
4849
  }
4594
- const parent = dirname6(cursor);
4850
+ const parent = dirname7(cursor);
4595
4851
  if (parent === cursor) return root;
4596
4852
  cursor = parent;
4597
4853
  }
@@ -4664,12 +4920,12 @@ async function loadDoctorCase(runsPath, projectRoot) {
4664
4920
  if (projectRoot !== void 0 && !physicallyContainedIn(projectRoot, root)) {
4665
4921
  throw new Error("doctor --runs escapes the project root");
4666
4922
  }
4667
- const match = root.split(sep3).join("/").match(/\/\.ak-roles\/books\/[^/]+\/(?:issues\/)?([1-9]\d*)\/runs$/);
4923
+ const match = root.split(sep4).join("/").match(/\/\.ak-roles\/books\/[^/]+\/(?:issues\/)?([1-9]\d*)\/runs$/);
4668
4924
  if (!match) throw new Error("Doctor case must be an .ak-roles/books/<book>/<n>/runs directory");
4669
4925
  const evidence = [], sessions = [], statuses = [], commits = [];
4670
4926
  const turns = { count: 0, sources: [] }, calls = { count: 0, sources: [] }, tokens = { count: 0, sources: [] };
4671
4927
  for (const path of await discoverCaseFiles(root)) {
4672
- const id = relative2(root, path).split(sep3).join("/");
4928
+ const id = relative3(root, path).split(sep4).join("/");
4673
4929
  const bytes = await readFile4(path);
4674
4930
  const content = bytes.toString("utf8");
4675
4931
  const kind = id.split("/").length === 2 && id.endsWith("/log.jsonl") ? "log" : "session";
@@ -4965,13 +5221,13 @@ var init_session_dialogue = __esm({
4965
5221
 
4966
5222
  // src/ticket-provenance.ts
4967
5223
  import { readFile as readFile6 } from "node:fs/promises";
4968
- import { join as join8, resolve as resolve6 } from "node:path";
5224
+ import { join as join9, resolve as resolve6 } from "node:path";
4969
5225
  function dialogueSessionSourceRoots(home) {
4970
5226
  const machineHome = typeof home === "string" && home.trim() !== "" ? home : packageMachineHome();
4971
5227
  return [
4972
- join8(machineHome, ".claude", "projects"),
4973
- join8(machineHome, ".codex", "sessions"),
4974
- join8(machineHome, ".pi", "agent", "sessions")
5228
+ join9(machineHome, ".claude", "projects"),
5229
+ join9(machineHome, ".codex", "sessions"),
5230
+ join9(machineHome, ".pi", "agent", "sessions")
4975
5231
  ];
4976
5232
  }
4977
5233
  function isLedgerRoleSessionFile(absolute, home) {
@@ -5012,7 +5268,7 @@ async function rehomeUnboundTicketProvenance(runDirectory, ticketNumber, cwd, ho
5012
5268
  const ticketInput = ticketProvenanceRecordInput(ticketNumber, cwd, home);
5013
5269
  let history;
5014
5270
  try {
5015
- history = await readFile6(join8(runDirectory, RUN_HISTORY_FILE), "utf8");
5271
+ history = await readFile6(join9(runDirectory, RUN_HISTORY_FILE), "utf8");
5016
5272
  } catch (error) {
5017
5273
  if (errnoCode(error) === "ENOENT") return;
5018
5274
  throw error;
@@ -5229,7 +5485,7 @@ var init_uuidv7 = __esm({
5229
5485
  });
5230
5486
 
5231
5487
  // src/notary-source-run.ts
5232
- import { dirname as dirname7, isAbsolute as isAbsolute4, join as join9, resolve as resolve7, basename as basename7 } from "node:path";
5488
+ import { dirname as dirname8, isAbsolute as isAbsolute4, join as join10, resolve as resolve7, basename as basename8 } from "node:path";
5233
5489
  import { lstat, realpath as realpath2 } from "node:fs/promises";
5234
5490
  async function readRetainedIdentity(runDirectory) {
5235
5491
  try {
@@ -5265,10 +5521,10 @@ async function requireRunDirectory(candidate, display) {
5265
5521
  `notary --source-run must be a run directory: ${display}`
5266
5522
  );
5267
5523
  }
5268
- const identity = parseRunLeaf(basename7(real));
5524
+ const identity = parseRunLeaf(basename8(real));
5269
5525
  if (identity === void 0) {
5270
5526
  throw new NotarySourceRunError(
5271
- `notary --source-run must be named <runId>@<role>: ${basename7(real)}`
5527
+ `notary --source-run must be named <runId>@<role>: ${basename8(real)}`
5272
5528
  );
5273
5529
  }
5274
5530
  return real;
@@ -5281,26 +5537,26 @@ async function resolveNotarySourceRunLocator(options) {
5281
5537
  const ledgerHome = resolveActivationLedgerHome(options.home);
5282
5538
  const bookKey = resolveBookKeyFromGit(options.projectRoot);
5283
5539
  const bookDirectory = activationBookDirectory(ledgerHome, bookKey);
5284
- const bookRunsRoot = join9(bookDirectory, "runs");
5540
+ const bookRunsRoot = join10(bookDirectory, "runs");
5285
5541
  let candidate;
5286
5542
  const bare = parseRunLeaf(raw);
5287
5543
  if (bare !== void 0 && !raw.includes("/") && !raw.includes("\\")) {
5288
- candidate = await findRunDirectoryById(options.home, bare.runId, bookKey, bare.role) ?? join9(bookRunsRoot, formatRunLeaf(bare.runId, bare.role));
5544
+ candidate = await findRunDirectoryById(options.home, bare.runId, bookKey, bare.role) ?? join10(bookRunsRoot, formatRunLeaf(bare.runId, bare.role));
5289
5545
  } else {
5290
5546
  candidate = isAbsolute4(raw) ? raw : resolve7(options.projectRoot, raw);
5291
- const identity2 = parseRunLeaf(basename7(candidate));
5292
- const subjectDirectory = dirname7(dirname7(candidate));
5293
- const isLegacyUnboundLocator = identity2 !== void 0 && basename7(dirname7(candidate)) === "runs" && basename7(subjectDirectory) === "unbound" && resolve7(dirname7(subjectDirectory)) === resolve7(bookDirectory);
5547
+ const identity2 = parseRunLeaf(basename8(candidate));
5548
+ const subjectDirectory = dirname8(dirname8(candidate));
5549
+ const isLegacyUnboundLocator = identity2 !== void 0 && basename8(dirname8(candidate)) === "runs" && basename8(subjectDirectory) === "unbound" && resolve7(dirname8(subjectDirectory)) === resolve7(bookDirectory);
5294
5550
  if (isLegacyUnboundLocator) {
5295
5551
  candidate = await resolveLiveRunDirectoryPath(candidate, options.home ?? ledgerHome, bookKey) ?? candidate;
5296
5552
  }
5297
5553
  }
5298
5554
  const real = await requireRunDirectory(candidate, raw);
5299
- const identity = parseRunLeaf(basename7(real));
5555
+ const identity = parseRunLeaf(basename8(real));
5300
5556
  const bookIdentity = physicalPathIdentity(bookDirectory);
5301
- const parentIdentity = physicalPathIdentity(dirname7(real));
5302
- const subjectBookIdentity = physicalPathIdentity(dirname7(dirname7(dirname7(real))));
5303
- if (parentIdentity !== physicalPathIdentity(bookRunsRoot) && !(basename7(dirname7(real)) === "runs" && subjectBookIdentity === bookIdentity)) {
5557
+ const parentIdentity = physicalPathIdentity(dirname8(real));
5558
+ const subjectBookIdentity = physicalPathIdentity(dirname8(dirname8(dirname8(real))));
5559
+ if (parentIdentity !== physicalPathIdentity(bookRunsRoot) && !(basename8(dirname8(real)) === "runs" && subjectBookIdentity === bookIdentity)) {
5304
5560
  throw new NotarySourceRunError(
5305
5561
  "notary --source-run must resolve to a retained run under the project machine-ledger book"
5306
5562
  );
@@ -5334,7 +5590,7 @@ async function resolveNotarySourceRunLocator(options) {
5334
5590
  }
5335
5591
  async function loadNotarySourceRunLocator(path) {
5336
5592
  const real = await requireRunDirectory(path, path);
5337
- const identity = parseRunLeaf(basename7(real));
5593
+ const identity = parseRunLeaf(basename8(real));
5338
5594
  const runState = await readRetainedIdentity(real);
5339
5595
  if (runState === void 0) {
5340
5596
  throw new NotarySourceRunError(
@@ -6502,14 +6758,14 @@ var init_option_definitions = __esm({
6502
6758
 
6503
6759
  // src/public-cli/invocation.ts
6504
6760
  import { execFileSync as execFileSync2 } from "node:child_process";
6505
- import { existsSync as existsSync2 } from "node:fs";
6761
+ import { existsSync as existsSync3 } from "node:fs";
6506
6762
  import {
6507
6763
  readFile as readFile7,
6508
6764
  realpath as realpath3,
6509
6765
  rename,
6510
6766
  writeFile
6511
6767
  } from "node:fs/promises";
6512
- import { dirname as dirname8, isAbsolute as isAbsolute5, join as join10, resolve as resolve8 } from "node:path";
6768
+ import { dirname as dirname9, isAbsolute as isAbsolute5, join as join11, resolve as resolve8 } from "node:path";
6513
6769
  function admittedSourceRunPath(admitted) {
6514
6770
  if (!isRecord(admitted)) return void 0;
6515
6771
  const path = admitted.sourceRunPath;
@@ -6668,35 +6924,36 @@ async function recordAdmittedCorrelation(admitted, correlationId) {
6668
6924
  mutable.correlationId = correlationId;
6669
6925
  mutable.correlationIds = correlationIds;
6670
6926
  }
6671
- async function relocateAdmittedRunToTicket(admitted, authority, heldLease) {
6672
- if (admitted.ticketNumber === void 0 || !isUnboundRunDirectory(admitted.runDirectory)) return void 0;
6673
- const oldRunDirectory = admitted.runDirectory;
6674
- const ledgerHome = resolveActivationLedgerHome(homeFromRunDirectory(oldRunDirectory));
6675
- const target = roleRunPlacement(ledgerHome, {
6676
- bookKey: admitted.bookKey,
6677
- subject: { ticketNumber: admitted.ticketNumber },
6678
- runId: admitted.runId,
6679
- role: admitted.role
6680
- });
6681
- ensureRoleRunDirectory(ledgerHome, dirname8(target.runDirectory));
6682
- const principal = authority.seal(target);
6683
- if (admitted.role !== "diarist") {
6684
- const childRunIds = readPageSync(oldRunDirectory, "admitted")?.childDiaristRunIds;
6685
- for (const childRunId of Array.isArray(childRunIds) ? childRunIds : []) {
6686
- if (typeof childRunId !== "string") continue;
6687
- const childDirectory = join10(dirname8(oldRunDirectory), formatRunLeaf(childRunId, "diarist"));
6688
- if (!existsSync2(childDirectory)) continue;
6689
- const childTarget = roleRunPlacement(ledgerHome, {
6690
- bookKey: admitted.bookKey,
6691
- subject: { ticketNumber: admitted.ticketNumber },
6692
- runId: childRunId,
6693
- role: "diarist"
6927
+ async function relocateRegisteredChildDiarists(input) {
6928
+ const childRunIds = readPageSync(input.parentRunDirectory, "admitted")?.childDiaristRunIds;
6929
+ for (const childRunId of Array.isArray(childRunIds) ? childRunIds : []) {
6930
+ if (typeof childRunId !== "string") continue;
6931
+ const childTarget = roleRunPlacement(input.ledgerHome, {
6932
+ bookKey: input.bookKey,
6933
+ subject: { ticketNumber: input.ticketNumber },
6934
+ runId: childRunId,
6935
+ role: "diarist"
6936
+ });
6937
+ const unboundChildDirectory = roleRunPlacement(input.ledgerHome, {
6938
+ bookKey: input.bookKey,
6939
+ subject: { unbound: true },
6940
+ runId: childRunId,
6941
+ role: "diarist"
6942
+ }).runDirectory;
6943
+ if (existsSync3(unboundChildDirectory)) {
6944
+ input.authority.seal(childTarget);
6945
+ await bindTicketNumberOnRunDirectory(unboundChildDirectory, input.ticketNumber);
6946
+ await rehomeUnboundTicketProvenance(
6947
+ unboundChildDirectory,
6948
+ input.ticketNumber,
6949
+ input.projectRoot,
6950
+ homeFromRunDirectory(input.parentRunDirectory)
6951
+ );
6952
+ ensureRoleRunDirectory(input.ledgerHome, dirname9(childTarget.runDirectory));
6953
+ await rename(unboundChildDirectory, childTarget.runDirectory);
6954
+ relocateTicketProgressForLeg({
6955
+ runDirectory: childTarget.runDirectory
6694
6956
  });
6695
- authority.seal(childTarget);
6696
- await bindTicketNumberOnRunDirectory(childDirectory, admitted.ticketNumber);
6697
- await rehomeUnboundTicketProvenance(childDirectory, admitted.ticketNumber, admitted.projectRoot, homeFromRunDirectory(oldRunDirectory));
6698
- ensureRoleRunDirectory(ledgerHome, dirname8(childTarget.runDirectory));
6699
- await rename(childDirectory, childTarget.runDirectory);
6700
6957
  try {
6701
6958
  renderCurrentSync(childTarget.runDirectory);
6702
6959
  } catch (error) {
@@ -6705,18 +6962,71 @@ async function relocateAdmittedRunToTicket(admitted, authority, heldLease) {
6705
6962
  `
6706
6963
  );
6707
6964
  }
6965
+ continue;
6708
6966
  }
6967
+ if (existsSync3(childTarget.runDirectory)) {
6968
+ relocateTicketProgressForLeg({
6969
+ runDirectory: childTarget.runDirectory
6970
+ });
6971
+ }
6972
+ }
6973
+ }
6974
+ async function relocateAdmittedRunToTicket(admitted, authority, heldLease) {
6975
+ if (admitted.ticketNumber === void 0) return void 0;
6976
+ const ledgerHome = resolveActivationLedgerHome(homeFromRunDirectory(admitted.runDirectory));
6977
+ if (!isUnboundRunDirectory(admitted.runDirectory)) {
6978
+ relocateTicketProgressForLeg({
6979
+ runDirectory: admitted.runDirectory
6980
+ });
6981
+ if (admitted.role !== "diarist") {
6982
+ await relocateRegisteredChildDiarists({
6983
+ parentRunDirectory: admitted.runDirectory,
6984
+ bookKey: admitted.bookKey,
6985
+ ticketNumber: admitted.ticketNumber,
6986
+ projectRoot: admitted.projectRoot,
6987
+ ledgerHome,
6988
+ authority
6989
+ });
6990
+ }
6991
+ return void 0;
6992
+ }
6993
+ const oldRunDirectory = admitted.runDirectory;
6994
+ const target = roleRunPlacement(ledgerHome, {
6995
+ bookKey: admitted.bookKey,
6996
+ subject: { ticketNumber: admitted.ticketNumber },
6997
+ runId: admitted.runId,
6998
+ role: admitted.role
6999
+ });
7000
+ ensureRoleRunDirectory(ledgerHome, dirname9(target.runDirectory));
7001
+ authority.seal(target);
7002
+ if (admitted.role !== "diarist") {
7003
+ await relocateRegisteredChildDiarists({
7004
+ parentRunDirectory: oldRunDirectory,
7005
+ bookKey: admitted.bookKey,
7006
+ ticketNumber: admitted.ticketNumber,
7007
+ projectRoot: admitted.projectRoot,
7008
+ ledgerHome,
7009
+ authority
7010
+ });
6709
7011
  }
6710
7012
  if (admitted.role === "diarist") {
6711
7013
  await rehomeUnboundTicketProvenance(oldRunDirectory, admitted.ticketNumber, admitted.projectRoot, homeFromRunDirectory(oldRunDirectory));
6712
7014
  }
6713
7015
  await rename(oldRunDirectory, target.runDirectory);
6714
7016
  heldLease?.relocate(target.runDirectory);
7017
+ const actualSessionDirectory = sessionDirectoryOf(target.runDirectory);
7018
+ const principal = authority.seal({
7019
+ sessionDirectory: actualSessionDirectory,
7020
+ sessionFile: sessionFileIn(actualSessionDirectory)
7021
+ });
6715
7022
  rewriteAdmittedRoleRunPage(
6716
7023
  admitted,
6717
7024
  [{ oldRunDirectory, newRunDirectory: target.runDirectory }]
6718
7025
  );
6719
7026
  admitted.principal = principal;
7027
+ relocateTicketProgressForLeg({
7028
+ runDirectory: target.runDirectory
7029
+ });
6720
7030
  renderCurrentSync(target.runDirectory);
6721
7031
  return { oldRunDirectory, newRunDirectory: target.runDirectory };
6722
7032
  }
@@ -6752,7 +7062,7 @@ async function recordLaunchedPiIdentity(runDirectory, identity) {
6752
7062
  async function observeLaunchedRolePackageIdentity(packageRoot, selectedRoleEntry) {
6753
7063
  const rolePackageRoot = packageRoot;
6754
7064
  const raw = JSON.parse(
6755
- await readFile7(join10(rolePackageRoot, "package.json"), "utf8")
7065
+ await readFile7(join11(rolePackageRoot, "package.json"), "utf8")
6756
7066
  );
6757
7067
  if (typeof raw.version !== "string" || raw.version.trim() === "") {
6758
7068
  throw new Error(
@@ -7310,7 +7620,7 @@ async function admitPublicRole(role, parsed, env, override) {
7310
7620
  resolutionScope: [...derived.resolutionScope],
7311
7621
  authorizedChecks: []
7312
7622
  });
7313
- const mergerInputPath = join10(placed.runDirectory, "merger-input.json");
7623
+ const mergerInputPath = join11(placed.runDirectory, "merger-input.json");
7314
7624
  await writeFile(
7315
7625
  mergerInputPath,
7316
7626
  `${JSON.stringify(mergerInput, null, 2)}
@@ -7592,7 +7902,7 @@ function parseDoctorIssueNumber(raw) {
7592
7902
  }
7593
7903
  async function resolveDoctorCaseRunsPath(options) {
7594
7904
  const ledgerHome = resolveActivationLedgerHome(options.home);
7595
- const defaultRuns = join10(
7905
+ const defaultRuns = join11(
7596
7906
  activationBookDirectory(ledgerHome, options.bookKey),
7597
7907
  String(options.issueNumber),
7598
7908
  "runs"
@@ -7665,11 +7975,11 @@ function parseAnalystCohortIssueToken(raw, flag) {
7665
7975
  `${flag} requires a comma-separated list of N or book:N`
7666
7976
  );
7667
7977
  }
7668
- const sep5 = trimmed.lastIndexOf(":");
7669
- if (sep5 > 0) {
7670
- const rhs = trimmed.slice(sep5 + 1);
7978
+ const sep6 = trimmed.lastIndexOf(":");
7979
+ if (sep6 > 0) {
7980
+ const rhs = trimmed.slice(sep6 + 1);
7671
7981
  if (parseTicketNumber(rhs) !== void 0) {
7672
- const bookKey = trimmed.slice(0, sep5);
7982
+ const bookKey = trimmed.slice(0, sep6);
7673
7983
  if (bookKey.trim() === "") {
7674
7984
  throw new CliUsageError(
7675
7985
  `${flag} book:N requires a non-empty book key, got ${raw}`
@@ -7866,6 +8176,7 @@ var init_invocation = __esm({
7866
8176
  init_activation_ledger_topology();
7867
8177
  init_activation_ledger_git();
7868
8178
  init_role_run_placement();
8179
+ init_ticket_progress();
7869
8180
  init_packaged_role_registry();
7870
8181
  init_run_ticket_number();
7871
8182
  init_role_run_relocation();
@@ -7888,7 +8199,7 @@ var init_invocation = __esm({
7888
8199
 
7889
8200
  // src/report-ticket-tool.ts
7890
8201
  import { Type as Type15 } from "typebox";
7891
- import { existsSync as existsSync3 } from "node:fs";
8202
+ import { existsSync as existsSync4 } from "node:fs";
7892
8203
  function pageString(page, key) {
7893
8204
  const value = page?.[key];
7894
8205
  return typeof value === "string" && value.trim() !== "" ? value : void 0;
@@ -7930,7 +8241,7 @@ async function reportTicketFromHostContext(context, rawTicketNumber, authority =
7930
8241
  if (runDirectory === void 0) {
7931
8242
  throw new Error("ak_report_ticket requires a per-turn run directory");
7932
8243
  }
7933
- if (!existsSync3(runDirectory)) {
8244
+ if (!existsSync4(runDirectory)) {
7934
8245
  throw new Error(`ak_report_ticket run directory missing: ${runDirectory}`);
7935
8246
  }
7936
8247
  const admitted = admittedForLiveTicketReport(runDirectory, authority);
@@ -7949,7 +8260,11 @@ async function reportTicketFromHostContext(context, rawTicketNumber, authority =
7949
8260
  context.sessionManager.setSessionFile?.(projectedSessionFile);
7950
8261
  }
7951
8262
  };
7952
- const relocation = alreadyPlaced ? void 0 : await relocateAdmittedRunToTicket(admitted, authority, { relocate: applyLiveHandles });
8263
+ const relocation = await relocateAdmittedRunToTicket(
8264
+ admitted,
8265
+ authority,
8266
+ alreadyPlaced ? void 0 : { relocate: applyLiveHandles }
8267
+ );
7953
8268
  const nextDirectory = relocation?.newRunDirectory ?? admitted.runDirectory;
7954
8269
  if (relocation === void 0) applyLiveHandles(nextDirectory);
7955
8270
  return {
@@ -8206,6 +8521,7 @@ async function sealAcceptedSubmission(options) {
8206
8521
  const attemptId = attemptIdentity(options.context, runId);
8207
8522
  const sessionParent = sessionParentFromHostContext(options.context);
8208
8523
  const home = homeFromHostContext(options.context, options.home);
8524
+ const sealHead = captureWorktreeHead(options.context.cwd);
8209
8525
  sitianReport({
8210
8526
  level: "event",
8211
8527
  kind: "sealed",
@@ -8222,6 +8538,12 @@ async function sealAcceptedSubmission(options) {
8222
8538
  ...home !== void 0 ? { home } : {},
8223
8539
  ...sessionParent === void 0 ? {} : { sessionParent }
8224
8540
  });
8541
+ landTicketProgressForSealedSubmission({
8542
+ context: options.context,
8543
+ role: options.role,
8544
+ accepted: options.accepted,
8545
+ sealHead
8546
+ });
8225
8547
  }
8226
8548
  function createSubmissionLedgerHost(host, outputTools, failInfrastructure2 = (error) => {
8227
8549
  throw error;
@@ -8346,6 +8668,7 @@ function createSubmissionLedgerHost(host, outputTools, failInfrastructure2 = (er
8346
8668
  kind: "accepted",
8347
8669
  accepted: params
8348
8670
  };
8671
+ const sealHead = captureWorktreeHead(context.cwd);
8349
8672
  append({
8350
8673
  type: "sealed",
8351
8674
  attemptId,
@@ -8353,6 +8676,14 @@ function createSubmissionLedgerHost(host, outputTools, failInfrastructure2 = (er
8353
8676
  role,
8354
8677
  accepted: params
8355
8678
  });
8679
+ const rawLens = typeof host.getFlag === "function" ? host.getFlag("ak-review-lens") : void 0;
8680
+ landTicketProgressForSealedSubmission({
8681
+ context,
8682
+ role,
8683
+ accepted: params,
8684
+ sealHead,
8685
+ ...rawLens === "completeness" || rawLens === "correctness" ? { lens: rawLens } : {}
8686
+ });
8356
8687
  await projectClosure(closed, context);
8357
8688
  return result;
8358
8689
  }
@@ -8374,6 +8705,7 @@ var init_submission_ledger = __esm({
8374
8705
  init_report_ticket_tool();
8375
8706
  init_review_submission();
8376
8707
  init_run_ticket_number();
8708
+ init_ticket_progress();
8377
8709
  init_unknown_value();
8378
8710
  }
8379
8711
  });
@@ -8560,7 +8892,7 @@ var init_engine_detour_usage = __esm({
8560
8892
  });
8561
8893
 
8562
8894
  // src/dossier-resolution.ts
8563
- import { existsSync as existsSync4, statSync as statSync4 } from "node:fs";
8895
+ import { existsSync as existsSync5, statSync as statSync4 } from "node:fs";
8564
8896
  import { resolve as resolve9 } from "node:path";
8565
8897
  function isHostContext(value) {
8566
8898
  return "sessionManager" in value;
@@ -8580,7 +8912,7 @@ function resolveAuditDossier(source) {
8580
8912
  }
8581
8913
  const runDirectory = resolve9(raw);
8582
8914
  try {
8583
- if (!existsSync4(runDirectory) || !statSync4(runDirectory).isDirectory()) {
8915
+ if (!existsSync5(runDirectory) || !statSync4(runDirectory).isDirectory()) {
8584
8916
  return { status: "incomplete", observation: { kind: "missing-dossier" } };
8585
8917
  }
8586
8918
  } catch {
@@ -9898,12 +10230,12 @@ var init_settlement = __esm({
9898
10230
  });
9899
10231
 
9900
10232
  // src/external-host-turn-loop.ts
9901
- import { existsSync as existsSync5 } from "node:fs";
9902
- import { basename as basename8 } from "node:path";
10233
+ import { existsSync as existsSync6 } from "node:fs";
10234
+ import { basename as basename9 } from "node:path";
9903
10235
  async function syncTurnRequestLivePlacement(request, authority) {
9904
10236
  const live = await resolveLiveRunDirectoryPath(request.runDirectory, request.home);
9905
10237
  if (live === void 0) {
9906
- const parsed = parseRunLeaf(basename8(request.runDirectory));
10238
+ const parsed = parseRunLeaf(basename9(request.runDirectory));
9907
10239
  throw new Error(
9908
10240
  `admitted run ${parsed?.runId ?? "(unparseable)"} missing after host turn; not found under ${request.home}`
9909
10241
  );
@@ -9922,7 +10254,7 @@ async function trySyncTurnRequestLivePlacement(request, authority) {
9922
10254
  }
9923
10255
  async function retainPackageFaultBesideLivePlacement(request, input) {
9924
10256
  let runDirectory = request.runDirectory;
9925
- if (!existsSync5(runDirectory)) {
10257
+ if (!existsSync6(runDirectory)) {
9926
10258
  try {
9927
10259
  const found = await resolveLiveRunDirectoryPath(request.runDirectory, request.home);
9928
10260
  if (found === void 0) {
@@ -10093,6 +10425,7 @@ async function driveExternalRoleTurnRounds(prepared, request, driver) {
10093
10425
  }
10094
10426
  }
10095
10427
  prompt = closure.retry.message;
10428
+ prepared.recordSentInstruction?.(prompt);
10096
10429
  driver.afterRetry?.();
10097
10430
  }
10098
10431
  }
@@ -10135,9 +10468,9 @@ var init_external_host_turn_loop = __esm({
10135
10468
  });
10136
10469
 
10137
10470
  // src/session-identity.ts
10138
- import { dirname as dirname9, join as join11 } from "node:path";
10471
+ import { join as join12 } from "node:path";
10139
10472
  function createSessionIdentityAuthority(authority, hostName) {
10140
- const runDirectoryOf = (principal) => dirname9(authority.decode(principal).sessionDirectory);
10473
+ const runDirectoryOf = (principal) => runDirectoryFromSessionDirectory(authority.decode(principal).sessionDirectory);
10141
10474
  return {
10142
10475
  principalAuthority: authority,
10143
10476
  resolveSessionFile(principal) {
@@ -10145,7 +10478,7 @@ function createSessionIdentityAuthority(authority, hostName) {
10145
10478
  },
10146
10479
  async load(principal) {
10147
10480
  const runDirectory = runDirectoryOf(principal);
10148
- const { records, diagnostics } = await readSitianRecords(join11(runDirectory, RUN_STATE_FILE));
10481
+ const { records, diagnostics } = await readSitianRecords(join12(runDirectory, RUN_STATE_FILE));
10149
10482
  if (diagnostics.length > 0) {
10150
10483
  throw new Error(
10151
10484
  `${RUN_STATE_FILE} has ${diagnostics.length} malformed row(s); refusing stale session binding: ${runDirectory}`
@@ -10192,6 +10525,7 @@ var init_session_identity = __esm({
10192
10525
  "src/session-identity.ts"() {
10193
10526
  "use strict";
10194
10527
  init_host_descriptions();
10528
+ init_role_run_placement();
10195
10529
  init_run_dossier();
10196
10530
  init_sitian_facade();
10197
10531
  init_unknown_value();
@@ -10214,14 +10548,14 @@ __export(role_turn_host_exports, {
10214
10548
  });
10215
10549
  import { execFile as execFile2, spawn as spawn2 } from "node:child_process";
10216
10550
  import { constants } from "node:fs";
10217
- import { existsSync as existsSync6 } from "node:fs";
10551
+ import { existsSync as existsSync7 } from "node:fs";
10218
10552
  import { access as access2, appendFile, realpath as realpath4 } from "node:fs/promises";
10219
- import { delimiter, dirname as dirname10, isAbsolute as isAbsolute6, join as join12, resolve as resolve11 } from "node:path";
10553
+ import { delimiter, dirname as dirname10, isAbsolute as isAbsolute6, join as join13, resolve as resolve11 } from "node:path";
10220
10554
  import { platform } from "node:process";
10221
10555
  import { promisify as promisify2 } from "node:util";
10222
10556
  import { randomUUID as randomUUID4 } from "node:crypto";
10223
10557
  function resolveInternalRoleEntrypoint(packageRoot) {
10224
- return join12(packageRoot, INTERNAL_ROLE_ENTRYPOINT_RELATIVE2);
10558
+ return join13(packageRoot, INTERNAL_ROLE_ENTRYPOINT_RELATIVE2);
10225
10559
  }
10226
10560
  function buildExplicitInternalActivationArgs(selectedRoleEntry, extraArgs = []) {
10227
10561
  return ["--no-extensions", "-e", selectedRoleEntry, ...extraArgs];
@@ -10411,7 +10745,7 @@ function createDefaultPiSpawnRunner(options) {
10411
10745
  homeFromRunDirectory(spawnDir)
10412
10746
  );
10413
10747
  } catch (resolveError) {
10414
- runDirectory = existsSync6(spawnDir) ? spawnDir : void 0;
10748
+ runDirectory = existsSync7(spawnDir) ? spawnDir : void 0;
10415
10749
  const resolveDiagnostic = `live run path resolve failed beside Pi transport fault: ${describeErrorIdentity(resolveError)}`;
10416
10750
  if (runDirectory !== void 0) {
10417
10751
  await retainPackageFault({
@@ -10464,7 +10798,8 @@ function createPiRoleTurnHost(config) {
10464
10798
  config.extraPiArgs ?? []
10465
10799
  );
10466
10800
  const args = buildExplicitInternalActivationArgs(roleEntry, extraArgs);
10467
- const stdin = encodeUserDialogueStdin(piUserDialogueBody(turnRequest));
10801
+ const transportBody = piUserDialogueBody(turnRequest);
10802
+ const stdin = encodeUserDialogueStdin(transportBody);
10468
10803
  const env = {
10469
10804
  ...process.env,
10470
10805
  HOME: request.home,
@@ -10480,6 +10815,7 @@ function createPiRoleTurnHost(config) {
10480
10815
  else env.AK_ROLE_INVOCATION_SCOPE = request.invocationScopeId;
10481
10816
  if (request.host === void 0 || request.host.trim() === "") delete env.AK_ROLE_HOST;
10482
10817
  else env.AK_ROLE_HOST = request.host.trim();
10818
+ delete env.AK_ROLE_SUMMONS_INSTRUCTION;
10483
10819
  if (request.deliveryRequestLimit === void 0) delete env[RECEIPT_DELIVERY_LIMIT_ENV];
10484
10820
  else env[RECEIPT_DELIVERY_LIMIT_ENV] = String(request.deliveryRequestLimit);
10485
10821
  applyEngineChildEnv(env, request.engine);
@@ -10612,8 +10948,8 @@ var init_role_turn_host = __esm({
10612
10948
  });
10613
10949
 
10614
10950
  // src/package-resources/engine-material.ts
10615
- import { existsSync as existsSync7, readdirSync as readdirSync2, readFileSync as readFileSync2 } from "node:fs";
10616
- import { join as join13 } from "node:path";
10951
+ import { existsSync as existsSync8, readdirSync as readdirSync3, readFileSync as readFileSync3 } from "node:fs";
10952
+ import { join as join14 } from "node:path";
10617
10953
  function pickEngineAxis(source) {
10618
10954
  return {
10619
10955
  ...source.engine === void 0 ? {} : { engine: source.engine },
@@ -10634,14 +10970,14 @@ function isEngineNameSyntax(name) {
10634
10970
  return true;
10635
10971
  }
10636
10972
  function resolveEngineMaterialDirectory(packageRoot) {
10637
- return join13(packageRoot, ENGINE_MATERIAL_RELATIVE_ROOT);
10973
+ return join14(packageRoot, ENGINE_MATERIAL_RELATIVE_ROOT);
10638
10974
  }
10639
10975
  function resolveEngineDispatchMaterialPath(packageRoot) {
10640
- return join13(packageRoot, ENGINE_DISPATCH_RELATIVE_PATH);
10976
+ return join14(packageRoot, ENGINE_DISPATCH_RELATIVE_PATH);
10641
10977
  }
10642
10978
  function resolveEngineMaterialPath(packageRoot, name) {
10643
10979
  const legal = assertLegalEngineName(name);
10644
- return join13(resolveEngineMaterialDirectory(packageRoot), `${legal}.md`);
10980
+ return join14(resolveEngineMaterialDirectory(packageRoot), `${legal}.md`);
10645
10981
  }
10646
10982
  function assertLegalEngineName(name) {
10647
10983
  if (!isEngineNameSyntax(name)) {
@@ -10658,12 +10994,12 @@ function engineSessionMaterialFromOptions(options) {
10658
10994
  const model = options.engineModel === void 0 ? void 0 : assertLegalEngineModel(options.engineModel);
10659
10995
  const materialPath = resolveEngineMaterialPath(options.packageRoot, name);
10660
10996
  const modelField = model === void 0 ? {} : { model };
10661
- if (!existsSync7(materialPath)) {
10997
+ if (!existsSync8(materialPath)) {
10662
10998
  return Object.freeze({ name, ...modelField });
10663
10999
  }
10664
- const handbook = readFileSync2(materialPath, "utf8");
11000
+ const handbook = readFileSync3(materialPath, "utf8");
10665
11001
  const dispatchPath = resolveEngineDispatchMaterialPath(options.packageRoot);
10666
- const dispatchField = existsSync7(dispatchPath) ? { dispatchHandbook: readFileSync2(dispatchPath, "utf8") } : {};
11002
+ const dispatchField = existsSync8(dispatchPath) ? { dispatchHandbook: readFileSync3(dispatchPath, "utf8") } : {};
10667
11003
  return Object.freeze({ name, handbook, ...dispatchField, ...modelField });
10668
11004
  }
10669
11005
  function engineSessionReadingMaterial(engineMaterial) {
@@ -10740,7 +11076,7 @@ __export(config_exports, {
10740
11076
  validatePublicCliConfigAxes: () => validatePublicCliConfigAxes
10741
11077
  });
10742
11078
  import { mkdir, readFile as readFile8, writeFile as writeFile2 } from "node:fs/promises";
10743
- import { dirname as dirname11, join as join14 } from "node:path";
11079
+ import { dirname as dirname11, join as join15 } from "node:path";
10744
11080
  function isGateOfficerSeat(value) {
10745
11081
  return packagedProvinceConfig(value);
10746
11082
  }
@@ -10748,7 +11084,7 @@ function publicCliConfigPath(home) {
10748
11084
  if (typeof home !== "string" || home.trim() === "") {
10749
11085
  throw new Error("home must be explicitly provided");
10750
11086
  }
10751
- return join14(home, ".ak-roles", "public-cli.json");
11087
+ return join15(home, ".ak-roles", "public-cli.json");
10752
11088
  }
10753
11089
  async function loadPublicCliConfig(home) {
10754
11090
  const path = publicCliConfigPath(home);
@@ -11208,11 +11544,11 @@ function credentialProvidersFromAuthData(data) {
11208
11544
  };
11209
11545
  }
11210
11546
  function resolvePublicAgentDir(explicit, home) {
11211
- return explicit ?? process.env.PI_CODING_AGENT_DIR ?? join14(home, ".pi", "agent");
11547
+ return explicit ?? process.env.PI_CODING_AGENT_DIR ?? join15(home, ".pi", "agent");
11212
11548
  }
11213
11549
  async function loadCredentialProviders(agentDir) {
11214
11550
  try {
11215
- const raw = await readFile8(join14(agentDir, "auth.json"), "utf8");
11551
+ const raw = await readFile8(join15(agentDir, "auth.json"), "utf8");
11216
11552
  return credentialProvidersFromAuthData(JSON.parse(raw));
11217
11553
  } catch (error) {
11218
11554
  if (isEnoent(error)) return { "openai-codex": false, xai: false };
@@ -11236,16 +11572,16 @@ var init_config = __esm({
11236
11572
  });
11237
11573
 
11238
11574
  // src/public-cli/host-providers.ts
11239
- import { readFileSync as readFileSync3 } from "node:fs";
11240
- import { join as join15 } from "node:path";
11575
+ import { readFileSync as readFileSync4 } from "node:fs";
11576
+ import { join as join16 } from "node:path";
11241
11577
  function hostProvidersPath(home) {
11242
11578
  if (typeof home !== "string" || home.trim() === "") {
11243
11579
  throw new Error("home must be explicitly provided");
11244
11580
  }
11245
- return join15(home, ".ak-roles", "host-providers.json");
11581
+ return join16(home, ".ak-roles", "host-providers.json");
11246
11582
  }
11247
11583
  function hermesProviderModelsCachePath(home) {
11248
- return join15(home, ".hermes", "provider_models_cache.json");
11584
+ return join16(home, ".hermes", "provider_models_cache.json");
11249
11585
  }
11250
11586
  function parseHostProvidersTable(value) {
11251
11587
  if (!isRecord(value)) {
@@ -11282,7 +11618,7 @@ function parseHostProvidersTable(value) {
11282
11618
  function loadHostProvidersTable(home) {
11283
11619
  const path = hostProvidersPath(home);
11284
11620
  try {
11285
- const raw = readFileSync3(path, "utf8");
11621
+ const raw = readFileSync4(path, "utf8");
11286
11622
  return parseHostProvidersTable(JSON.parse(raw));
11287
11623
  } catch (error) {
11288
11624
  if (isEnoent(error)) return {};
@@ -11298,7 +11634,7 @@ function listHermesProvidersForModel(home, seatModel) {
11298
11634
  const path = hermesProviderModelsCachePath(home);
11299
11635
  let text;
11300
11636
  try {
11301
- text = readFileSync3(path, "utf8");
11637
+ text = readFileSync4(path, "utf8");
11302
11638
  } catch (error) {
11303
11639
  if (isEnoent(error)) return [];
11304
11640
  throw error;
@@ -11395,17 +11731,17 @@ var init_host_providers = __esm({
11395
11731
  });
11396
11732
 
11397
11733
  // src/public-cli/load-production-acp-host.ts
11398
- import { existsSync as existsSync8 } from "node:fs";
11399
- import { join as join16 } from "node:path";
11734
+ import { existsSync as existsSync9 } from "node:fs";
11735
+ import { join as join17 } from "node:path";
11400
11736
  import { pathToFileURL } from "node:url";
11401
11737
  async function loadProductionAcpHostFactory(packageRoot, host) {
11402
11738
  const description = lookupHostDescription(host);
11403
11739
  if (description === void 0) {
11404
11740
  throw new Error(`unregistered host: ${host}`);
11405
11741
  }
11406
- const built = join16(packageRoot, "dist/acp-host/production-host.js");
11407
- const source = join16(packageRoot, "src/acp-host/production-host.ts");
11408
- const target = existsSync8(built) ? built : source;
11742
+ const built = join17(packageRoot, "dist/acp-host/production-host.js");
11743
+ const source = join17(packageRoot, "src/acp-host/production-host.ts");
11744
+ const target = existsSync9(built) ? built : source;
11409
11745
  const href = pathToFileURL(target).href;
11410
11746
  const mod = await import(href);
11411
11747
  const create = mod.createProductionAcpRoleTurnHost;
@@ -11419,17 +11755,17 @@ var init_load_production_acp_host = __esm({
11419
11755
  });
11420
11756
 
11421
11757
  // src/public-cli/load-production-headless-host.ts
11422
- import { existsSync as existsSync9 } from "node:fs";
11423
- import { join as join17 } from "node:path";
11758
+ import { existsSync as existsSync10 } from "node:fs";
11759
+ import { join as join18 } from "node:path";
11424
11760
  import { pathToFileURL as pathToFileURL2 } from "node:url";
11425
11761
  async function loadProductionHeadlessHostFactory(packageRoot, host) {
11426
11762
  const description = lookupHeadlessHostDescription(host);
11427
11763
  if (description === void 0) {
11428
11764
  throw new Error(`unregistered headless host: ${host}`);
11429
11765
  }
11430
- const built = join17(packageRoot, "dist/headless-host/production-host.js");
11431
- const source = join17(packageRoot, "src/headless-host/production-host.ts");
11432
- const target = existsSync9(built) ? built : source;
11766
+ const built = join18(packageRoot, "dist/headless-host/production-host.js");
11767
+ const source = join18(packageRoot, "src/headless-host/production-host.ts");
11768
+ const target = existsSync10(built) ? built : source;
11433
11769
  const href = pathToFileURL2(target).href;
11434
11770
  const mod = await import(href);
11435
11771
  const create = mod.createProductionHeadlessRoleTurnHost;
@@ -11596,14 +11932,14 @@ var init_role_seat_runtime = __esm({
11596
11932
  });
11597
11933
 
11598
11934
  // src/session-opening-materials.ts
11599
- import { existsSync as existsSync10 } from "node:fs";
11935
+ import { existsSync as existsSync11 } from "node:fs";
11600
11936
  import { readFile as readFile9 } from "node:fs/promises";
11601
- import { dirname as dirname12, join as join18 } from "node:path";
11937
+ import { dirname as dirname12, join as join19 } from "node:path";
11602
11938
  import { fileURLToPath, pathToFileURL as pathToFileURL3 } from "node:url";
11603
11939
  function resolvePackageRootDir(moduleUrl = import.meta.url) {
11604
11940
  let dir = dirname12(fileURLToPath(moduleUrl));
11605
11941
  for (let i = 0; i < 8; i += 1) {
11606
- if (existsSync10(join18(dir, "package.json")) && existsSync10(join18(dir, "souls"))) {
11942
+ if (existsSync11(join19(dir, "package.json")) && existsSync11(join19(dir, "souls"))) {
11607
11943
  return dir;
11608
11944
  }
11609
11945
  const parent = dirname12(dir);
@@ -11963,7 +12299,7 @@ __export(auditor_soul_exports, {
11963
12299
  readAuditorResumeBinding: () => readAuditorResumeBinding,
11964
12300
  resolveAuditorSubject: () => resolveAuditorSubject
11965
12301
  });
11966
- import { basename as basename9 } from "node:path";
12302
+ import { basename as basename10 } from "node:path";
11967
12303
  function auditorSoulRelativePath(role) {
11968
12304
  return `souls/${role}-auditor.md`;
11969
12305
  }
@@ -11999,7 +12335,7 @@ function loadAuditorReferenceMaterialsFromSubjectInput(raw) {
11999
12335
  return loadAuditorReferenceMaterials(resolveAuditorSubject(raw));
12000
12336
  }
12001
12337
  function subjectFromSourceDirectory(sourceRunDirectory) {
12002
- const role = parseRunLeaf(basename9(sourceRunDirectory))?.role;
12338
+ const role = parseRunLeaf(basename10(sourceRunDirectory))?.role;
12003
12339
  return isAuditorSoulRole(role) ? role : void 0;
12004
12340
  }
12005
12341
  async function readAuditorResumeBinding(admitted) {
@@ -12042,16 +12378,16 @@ var init_auditor_soul = __esm({
12042
12378
  // src/public-cli/machine-method-skills.ts
12043
12379
  import { accessSync, constants as constants2, statSync as statSync5 } from "node:fs";
12044
12380
  import { lstat as lstat2, mkdir as mkdir2, symlink } from "node:fs/promises";
12045
- import { join as join20 } from "node:path";
12046
- import { spawnSync as spawnSync2 } from "node:child_process";
12381
+ import { join as join21 } from "node:path";
12382
+ import { spawnSync as spawnSync3 } from "node:child_process";
12047
12383
  function skillRoot(home) {
12048
- return join20(home, ".agents/skills");
12384
+ return join21(home, ".agents/skills");
12049
12385
  }
12050
12386
  function installedMethodSkillPath(home, name) {
12051
12387
  return installedSkillPath(skillRoot(home), name);
12052
12388
  }
12053
12389
  function installedSkillPath(root, name) {
12054
- const path = join20(root, name, "SKILL.md");
12390
+ const path = join21(root, name, "SKILL.md");
12055
12391
  try {
12056
12392
  if (!statSync5(path).isFile()) return void 0;
12057
12393
  accessSync(path, constants2.R_OK);
@@ -12064,9 +12400,9 @@ function installedSkillPath(root, name) {
12064
12400
  }
12065
12401
  function linkedSkillRoot(home, host) {
12066
12402
  if (host === "claude" || host === "claude-code") {
12067
- return join20(process.env.CLAUDE_CONFIG_DIR?.trim() || join20(home, ".claude"), "skills");
12403
+ return join21(process.env.CLAUDE_CONFIG_DIR?.trim() || join21(home, ".claude"), "skills");
12068
12404
  }
12069
- if (host === "hermes") return join20(home, ".hermes/skills");
12405
+ if (host === "hermes") return join21(home, ".hermes/skills");
12070
12406
  return void 0;
12071
12407
  }
12072
12408
  async function occupied(path) {
@@ -12094,7 +12430,7 @@ async function warnMissingMethodSkills(home, host, role, skills, stdout) {
12094
12430
  }
12095
12431
  }
12096
12432
  function runSkillsCli(args, home) {
12097
- const result = spawnSync2("npx", ["--yes", "skills", ...args], {
12433
+ const result = spawnSync3("npx", ["--yes", "skills", ...args], {
12098
12434
  stdio: "inherit",
12099
12435
  env: { ...process.env, HOME: home }
12100
12436
  });
@@ -12123,7 +12459,7 @@ async function runMachineSkillSetup(home, stdout) {
12123
12459
  const missingBySource = /* @__PURE__ */ new Map();
12124
12460
  let unsourced = false;
12125
12461
  for (const name of packagedMethodSkillNames()) {
12126
- const path = join20(canonical, name);
12462
+ const path = join21(canonical, name);
12127
12463
  if (await occupied(path)) {
12128
12464
  warnOccupied(path, stdout);
12129
12465
  continue;
@@ -12153,9 +12489,9 @@ async function runMachineSkillSetup(home, stdout) {
12153
12489
  throw error;
12154
12490
  }
12155
12491
  for (const name of packagedMethodSkillNames()) {
12156
- const target = join20(canonical, name);
12492
+ const target = join21(canonical, name);
12157
12493
  if (installedMethodSkillPath(home, name) === void 0) continue;
12158
- const link = join20(root, name);
12494
+ const link = join21(root, name);
12159
12495
  if (await occupied(link)) {
12160
12496
  warnOccupied(link, stdout);
12161
12497
  continue;
@@ -12215,7 +12551,8 @@ function projectRoleTurnRequest(admitted, roleDetails, options) {
12215
12551
  ...options.invocationScopeId === void 0 || options.invocationScopeId.length === 0 ? {} : { invocationScopeId: options.invocationScopeId },
12216
12552
  ...options.stationChild === void 0 ? {} : { stationChild: options.stationChild },
12217
12553
  ...options.navigatorByStatusPrepare === void 0 ? {} : { navigatorByStatusPrepare: options.navigatorByStatusPrepare },
12218
- ...options.deliveryRequestLimit === void 0 ? {} : { deliveryRequestLimit: options.deliveryRequestLimit }
12554
+ ...options.deliveryRequestLimit === void 0 ? {} : { deliveryRequestLimit: options.deliveryRequestLimit },
12555
+ ...options.host === void 0 || options.host.trim() === "" ? {} : { host: options.host.trim() }
12219
12556
  };
12220
12557
  }
12221
12558
  function packagedSettleSkill(admitted) {
@@ -14183,7 +14520,7 @@ async function resolveReviewSeatDialogueBody(input) {
14183
14520
  if (sourceRunPath === void 0) return void 0;
14184
14521
  return await loadLedgerPeerBody(sourceRunPath, input.projectRoot, input.home);
14185
14522
  }
14186
- async function resolveInitialPrompt(admitted, env) {
14523
+ async function resolveInitialTurnPrompt(admitted, env) {
14187
14524
  const record = roleRecord(admitted.role);
14188
14525
  if ("reaskPrompt" in record && record.reaskPrompt === true) {
14189
14526
  const sourceRunPath = admittedSourceRunPath(admitted);
@@ -14280,7 +14617,7 @@ async function dispatchAdmitted(admitted, env, io) {
14280
14617
  if (activeEnv.correlationId !== void 0 && activeEnv.correlationId.trim() !== "") {
14281
14618
  await recordAdmittedCorrelation(admitted, activeEnv.correlationId);
14282
14619
  }
14283
- const initialPromptText = await resolveInitialPrompt(admitted, activeEnv);
14620
+ const initialPrompt = await resolveInitialTurnPrompt(admitted, activeEnv);
14284
14621
  const auto = "inCallAutoResume" in record && record.inCallAutoResume === true;
14285
14622
  if (auto) {
14286
14623
  return await runPostAdmissionResumable({
@@ -14291,14 +14628,14 @@ async function dispatchAdmitted(admitted, env, io) {
14291
14628
  admitted,
14292
14629
  roleTurnOptions(activeEnv, admitted, {
14293
14630
  kind: "initial",
14294
- prompt: initialPromptText
14631
+ prompt: initialPrompt
14295
14632
  })
14296
14633
  ),
14297
14634
  buildResumeRequest: () => buildInstructionSeatTurnRequest(
14298
14635
  admitted,
14299
14636
  roleTurnOptions(activeEnv, admitted, {
14300
14637
  kind: "resume",
14301
- prompt: initialPromptText
14638
+ prompt: initialPrompt
14302
14639
  })
14303
14640
  ),
14304
14641
  adapters,
@@ -14313,7 +14650,7 @@ async function dispatchAdmitted(admitted, env, io) {
14313
14650
  admitted,
14314
14651
  roleTurnOptions(activeEnv, admitted, {
14315
14652
  kind: "initial",
14316
- prompt: initialPromptText
14653
+ prompt: initialPrompt
14317
14654
  })
14318
14655
  ),
14319
14656
  adapters,
@@ -14489,7 +14826,7 @@ async function runCountersignBody(parsed, env, io) {
14489
14826
  }
14490
14827
  const turnProjection = roleTurnOptions(env, admitted, {
14491
14828
  kind: "initial",
14492
- prompt: await resolveInitialPrompt(admitted, env)
14829
+ prompt: await resolveInitialTurnPrompt(admitted, env)
14493
14830
  });
14494
14831
  const turnRequest = buildInstructionSeatTurnRequest(admitted, turnProjection);
14495
14832
  const result = await runPostAdmissionOneShot({
@@ -15372,10 +15709,10 @@ var init_analyst_book_key = __esm({
15372
15709
  // src/atomic-write.ts
15373
15710
  import { randomUUID as randomUUID6 } from "node:crypto";
15374
15711
  import { rename as rename2, rm, writeFile as writeFile3 } from "node:fs/promises";
15375
- import { dirname as dirname14, join as join21 } from "node:path";
15712
+ import { dirname as dirname14, join as join22 } from "node:path";
15376
15713
  async function writeFileAtomically(destination, contents, options) {
15377
15714
  const parent = dirname14(destination);
15378
- const temporary = join21(parent, `.atomic-write-${randomUUID6()}.tmp`);
15715
+ const temporary = join22(parent, `.atomic-write-${randomUUID6()}.tmp`);
15379
15716
  try {
15380
15717
  await writeFile3(temporary, contents, options);
15381
15718
  await rename2(temporary, destination);
@@ -15392,12 +15729,12 @@ var init_atomic_write = __esm({
15392
15729
 
15393
15730
  // src/analyst-index.ts
15394
15731
  import { open, readFile as readFile10, unlink } from "node:fs/promises";
15395
- import { dirname as dirname15, join as join22 } from "node:path";
15732
+ import { dirname as dirname15, join as join23 } from "node:path";
15396
15733
  import { setTimeout as sleep } from "node:timers/promises";
15397
15734
  async function withAnalystLibraryIndexLock(ledgerHome, fn) {
15398
15735
  const indexPath = analystLibraryIndexPath(ledgerHome);
15399
15736
  ensureRealDirectoryTree(ledgerHome, dirname15(indexPath));
15400
- const lockPath = join22(dirname15(indexPath), LIBRARY_INDEX_LOCK_NAME);
15737
+ const lockPath = join23(dirname15(indexPath), LIBRARY_INDEX_LOCK_NAME);
15401
15738
  assertLedgerFileInsideHome(lockPath, ledgerHome);
15402
15739
  const startedAt = Date.now();
15403
15740
  while (true) {
@@ -15424,7 +15761,7 @@ async function withAnalystLibraryIndexLock(ledgerHome, fn) {
15424
15761
  }
15425
15762
  }
15426
15763
  function analystLibraryIndexPath(ledgerHome) {
15427
- return join22(ledgerHome, "analyst", "library-index.json");
15764
+ return join23(ledgerHome, "analyst", "library-index.json");
15428
15765
  }
15429
15766
  function rowFromIssueMetricsPage(page) {
15430
15767
  return {
@@ -15718,7 +16055,7 @@ var init_analyst_cohort = __esm({
15718
16055
  });
15719
16056
 
15720
16057
  // src/archivist-record-pointer.ts
15721
- import { basename as basename10, join as join23 } from "node:path";
16058
+ import { basename as basename11, join as join24 } from "node:path";
15722
16059
  async function resolveOfficerPointer(raw, parentRunDirectory) {
15723
16060
  const where = `${parentRunDirectory} officers`;
15724
16061
  if (!isRecord(raw) || raw.kind !== DIRECT_OFFICER_RUN_POINTER_KIND || raw.version !== 1) {
@@ -15731,7 +16068,7 @@ async function resolveOfficerPointer(raw, parentRunDirectory) {
15731
16068
  let runDirectory = typeof raw.runDirectory === "string" && raw.runDirectory.trim() !== "" ? raw.runDirectory : void 0;
15732
16069
  let sessionFile = raw.sessionFile;
15733
16070
  const recordedRunDirectory = runDirectory ?? runDirectoryOfSessionFile(sessionFile);
15734
- const leaf = parseRunLeaf(basename10(recordedRunDirectory));
16071
+ const leaf = parseRunLeaf(basename11(recordedRunDirectory));
15735
16072
  const parentIdentity = await readRoleRunIdentity(parentRunDirectory);
15736
16073
  if (leaf !== void 0 && parentIdentity !== void 0) {
15737
16074
  const currentRunDirectory = await resolveLiveRunDirectoryPath(
@@ -15751,7 +16088,7 @@ async function resolveOfficerPointer(raw, parentRunDirectory) {
15751
16088
  };
15752
16089
  }
15753
16090
  async function readBookedOfficerPointers(parentRunDirectory) {
15754
- const { records, diagnostics } = await readSitianRecords(join23(parentRunDirectory, RUN_HISTORY_FILE));
16091
+ const { records, diagnostics } = await readSitianRecords(join24(parentRunDirectory, RUN_HISTORY_FILE));
15755
16092
  if (diagnostics.length > 0) {
15756
16093
  throw new Error(
15757
16094
  `${RUN_HISTORY_FILE} has ${diagnostics.length} malformed row(s); officer pointers unreadable: ${parentRunDirectory}`
@@ -16034,7 +16371,7 @@ var init_analyst_gate_cycles_read = __esm({
16034
16371
 
16035
16372
  // src/analyst-ledger.ts
16036
16373
  import { readdir as readdir3 } from "node:fs/promises";
16037
- import { basename as basename11, join as join24 } from "node:path";
16374
+ import { basename as basename12, join as join25 } from "node:path";
16038
16375
  async function readExistingRunLifecycleState(runDirectory) {
16039
16376
  return (await readRoleRunIdentity(runDirectory))?.state;
16040
16377
  }
@@ -16054,7 +16391,7 @@ function ghostLeaseCheckFromAutopsy(autopsy) {
16054
16391
  }
16055
16392
  }
16056
16393
  async function classifyGhostCandidate(input) {
16057
- const autopsy = await autopsyWriterLock(join24(input.runDirectory, "writer.lock"));
16394
+ const autopsy = await autopsyWriterLock(join25(input.runDirectory, "writer.lock"));
16058
16395
  const leaseCheck = ghostLeaseCheckFromAutopsy(autopsy);
16059
16396
  if (leaseCheck === void 0) return { kind: "live" };
16060
16397
  return {
@@ -16344,7 +16681,7 @@ async function classifyScopedRun(input) {
16344
16681
  async function scanAnalystIssueRuns(input) {
16345
16682
  const ledgerHome = resolveActivationLedgerHome(input.home);
16346
16683
  const scopeTicketNumber = input.ticketNumber;
16347
- const booksRoot = join24(ledgerHome, "books");
16684
+ const booksRoot = join25(ledgerHome, "books");
16348
16685
  let wholeBook = false;
16349
16686
  let scopeRootIdentity;
16350
16687
  let bookNames;
@@ -16377,7 +16714,7 @@ async function scanAnalystIssueRuns(input) {
16377
16714
  const ghostLegs = [];
16378
16715
  const scopeConflicts = [];
16379
16716
  for (const book of bookNames) {
16380
- const bookDir = join24(booksRoot, book);
16717
+ const bookDir = join25(booksRoot, book);
16381
16718
  let runDirectories;
16382
16719
  try {
16383
16720
  runDirectories = await listBookRunDirectories(bookDir);
@@ -16386,7 +16723,7 @@ async function scanAnalystIssueRuns(input) {
16386
16723
  throw error;
16387
16724
  }
16388
16725
  for (const runDirectory of runDirectories) {
16389
- const runName = basename11(runDirectory);
16726
+ const runName = basename12(runDirectory);
16390
16727
  const parsed = parseRunLeaf(runName);
16391
16728
  if (parsed === void 0) continue;
16392
16729
  let scopeFields;
@@ -17123,7 +17460,7 @@ var init_analyst_metric_family = __esm({
17123
17460
  });
17124
17461
 
17125
17462
  // src/analyst-page.ts
17126
- import { dirname as dirname16, join as join25 } from "node:path";
17463
+ import { dirname as dirname16, join as join26 } from "node:path";
17127
17464
  function analystIssuePageKey(address) {
17128
17465
  const parts = ["book", address.bookKey];
17129
17466
  if (address.issueNumber !== void 0) {
@@ -17134,7 +17471,7 @@ function analystIssuePageKey(address) {
17134
17471
  return sha256Hex(parts.join("\0")).slice(0, 32);
17135
17472
  }
17136
17473
  function analystIssuePagePath(ledgerHome, address) {
17137
- return join25(ledgerHome, "analyst", "issues", `${analystIssuePageKey(address)}.json`);
17474
+ return join26(ledgerHome, "analyst", "issues", `${analystIssuePageKey(address)}.json`);
17138
17475
  }
17139
17476
  function analystIssuePageAddressFromPage(page) {
17140
17477
  return {
@@ -18690,9 +19027,9 @@ __export(public_role_summons_exports, {
18690
19027
  summonPublicRole: () => summonPublicRole
18691
19028
  });
18692
19029
  import { execFile as execFile3 } from "node:child_process";
18693
- import { existsSync as existsSync11 } from "node:fs";
19030
+ import { existsSync as existsSync12 } from "node:fs";
18694
19031
  import { realpath as realpath6 } from "node:fs/promises";
18695
- import { join as join26 } from "node:path";
19032
+ import { join as join27 } from "node:path";
18696
19033
  import { promisify as promisify3 } from "node:util";
18697
19034
  function createCapturingIo() {
18698
19035
  const chunks = [];
@@ -18716,7 +19053,7 @@ function parentDir(path) {
18716
19053
  function walkPackageRoot(start) {
18717
19054
  let dir = start;
18718
19055
  for (let i = 0; i < 12; i += 1) {
18719
- if (existsSync11(join26(dir, "package.json")) && existsSync11(join26(dir, "souls"))) {
19056
+ if (existsSync12(join27(dir, "package.json")) && existsSync12(join27(dir, "souls"))) {
18720
19057
  return dir;
18721
19058
  }
18722
19059
  const parent = parentDir(dir);
@@ -19264,7 +19601,7 @@ var init_compliance_transport = __esm({
19264
19601
  });
19265
19602
 
19266
19603
  // src/role-run-relocation.ts
19267
- import { dirname as dirname17, join as join27 } from "node:path";
19604
+ import { dirname as dirname17, join as join28 } from "node:path";
19268
19605
  async function retainedRunPathsMatch(recordedPath, currentPath, currentRunDirectory) {
19269
19606
  if (recordedPath === currentPath) return true;
19270
19607
  if (typeof recordedPath !== "string") return false;
@@ -19330,9 +19667,9 @@ __export(run_lifecycle_exports, {
19330
19667
  resolveLiveRunDirectoryPath: () => resolveLiveRunDirectoryPath,
19331
19668
  writeRoleRunState: () => writeRoleRunState
19332
19669
  });
19333
- import { existsSync as existsSync12 } from "node:fs";
19670
+ import { existsSync as existsSync13 } from "node:fs";
19334
19671
  import { chmod, lstat as lstat3, open as open2, readdir as readdir4, readFile as readFile14, unlink as unlink2 } from "node:fs/promises";
19335
- import { basename as basename12, join as join28 } from "node:path";
19672
+ import { basename as basename13, join as join29 } from "node:path";
19336
19673
  async function writeRoleRunState(runDirectory, record) {
19337
19674
  const payload = { ...record, runDirectory };
19338
19675
  writeSectionSync(runDirectory, "runState", { ...payload });
@@ -19414,13 +19751,14 @@ async function readRoleRunStateDisk(runDirectory) {
19414
19751
  if (typeof record.sessionDirectory !== "string") throw new TypeError("Invalid state.jsonl run-state");
19415
19752
  const storedRunDirectory = typeof record.runDirectory === "string" && record.runDirectory.trim() !== "" ? record.runDirectory : runDirectory;
19416
19753
  const runDir = runDirectory;
19754
+ const principalCoords = {
19755
+ sessionDirectory: record.sessionDirectory,
19756
+ ...typeof record.sessionFile === "string" ? { sessionFile: record.sessionFile } : {}
19757
+ };
19758
+ rewritePrincipalSessionPaths(principalCoords, storedRunDirectory, runDirectory);
19417
19759
  const principalWire = {
19418
- sessionDirectory: rewriteRunDirectoryPathValue(
19419
- record.sessionDirectory,
19420
- storedRunDirectory,
19421
- runDirectory
19422
- ),
19423
- ...typeof record.sessionFile === "string" ? { sessionFile: rewriteRunDirectoryPathValue(record.sessionFile, storedRunDirectory, runDirectory) } : {}
19760
+ sessionDirectory: principalCoords.sessionDirectory,
19761
+ ...typeof principalCoords.sessionFile === "string" ? { sessionFile: principalCoords.sessionFile } : {}
19424
19762
  };
19425
19763
  const phase = record.phase === "plan" || record.phase === "apply" ? record.phase : void 0;
19426
19764
  const currentCourt = parseCurrentCourtState(record.currentCourt);
@@ -19626,7 +19964,7 @@ async function createWriterLease(lockPath, runDirectory, reportCleanupFailure) {
19626
19964
  },
19627
19965
  relocate(nextRunDirectory) {
19628
19966
  currentRunDirectory = nextRunDirectory;
19629
- currentLockPath = join28(nextRunDirectory, WRITER_LOCK_FILE);
19967
+ currentLockPath = join29(nextRunDirectory, WRITER_LOCK_FILE);
19630
19968
  },
19631
19969
  async release() {
19632
19970
  if (released) return;
@@ -19665,10 +20003,10 @@ async function acquireRunWriterLease(runDirectory, onCleanupFailure) {
19665
20003
  };
19666
20004
  const reportReadFailure = (error) => {
19667
20005
  reportDiagnostic(
19668
- `writer lease lock read failed (holder liveness unverifiable; lock left in place) at ${join28(runDirectory, WRITER_LOCK_FILE)}: ${describeErrorIdentity(error)}`
20006
+ `writer lease lock read failed (holder liveness unverifiable; lock left in place) at ${join29(runDirectory, WRITER_LOCK_FILE)}: ${describeErrorIdentity(error)}`
19669
20007
  );
19670
20008
  };
19671
- const lockPath = join28(runDirectory, WRITER_LOCK_FILE);
20009
+ const lockPath = join29(runDirectory, WRITER_LOCK_FILE);
19672
20010
  let lastAutopsy = { verdict: "absent" };
19673
20011
  let lastReclaimFailure;
19674
20012
  for (let reclaimsLeft = WRITER_LEASE_RECLAIM_ROUNDS; ; reclaimsLeft -= 1) {
@@ -19724,7 +20062,7 @@ async function acquireRunWriterLease(runDirectory, onCleanupFailure) {
19724
20062
  }
19725
20063
  async function findRunDirectoryById(home, runId, onlyBookKey, onlyRole, knownRunDirectory) {
19726
20064
  if (typeof knownRunDirectory === "string" && knownRunDirectory.trim() !== "") {
19727
- const parsed = parseRunLeaf(basename12(knownRunDirectory));
20065
+ const parsed = parseRunLeaf(basename13(knownRunDirectory));
19728
20066
  if (parsed === void 0 || parsed.runId !== runId) {
19729
20067
  throw new CliUsageError(
19730
20068
  `run directory does not match run id ${runId}: ${knownRunDirectory}`
@@ -19734,7 +20072,7 @@ async function findRunDirectoryById(home, runId, onlyBookKey, onlyRole, knownRun
19734
20072
  }
19735
20073
  if (runId.trim() === "") return void 0;
19736
20074
  const ledgerHome = resolveActivationLedgerHome(home);
19737
- const booksRoot = join28(ledgerHome, "books");
20075
+ const booksRoot = join29(ledgerHome, "books");
19738
20076
  let bookKeys;
19739
20077
  try {
19740
20078
  bookKeys = await readdir4(booksRoot);
@@ -19749,8 +20087,8 @@ async function findRunDirectoryById(home, runId, onlyBookKey, onlyRole, knownRun
19749
20087
  );
19750
20088
  }
19751
20089
  async function resolveLiveRunDirectoryPath(recordedPath, home, onlyBookKey) {
19752
- if (existsSync12(recordedPath)) return recordedPath;
19753
- const parsed = parseRunLeaf(basename12(recordedPath));
20090
+ if (existsSync13(recordedPath)) return recordedPath;
20091
+ const parsed = parseRunLeaf(basename13(recordedPath));
19754
20092
  const bookKey = onlyBookKey ?? tryBookKeyFromAkRolesPath(recordedPath);
19755
20093
  if (parsed === void 0 || bookKey === void 0) return void 0;
19756
20094
  return findRunDirectoryById(home, parsed.runId, bookKey, parsed.role);
@@ -19784,7 +20122,7 @@ async function findLatestRunForSeatTicket(input) {
19784
20122
  let runDirectories;
19785
20123
  try {
19786
20124
  runDirectories = await listBookRunDirectories(
19787
- input.ticketNumber === void 0 ? bookDir : join28(bookDir, String(input.ticketNumber))
20125
+ input.ticketNumber === void 0 ? bookDir : join29(bookDir, String(input.ticketNumber))
19788
20126
  );
19789
20127
  } catch (error) {
19790
20128
  if (errorCodeOf(error) === "ENOENT") return void 0;
@@ -19792,7 +20130,7 @@ async function findLatestRunForSeatTicket(input) {
19792
20130
  }
19793
20131
  let best;
19794
20132
  for (const runDirectory of runDirectories) {
19795
- const parsed = parseRunLeaf(basename12(runDirectory));
20133
+ const parsed = parseRunLeaf(basename13(runDirectory));
19796
20134
  if (parsed === void 0 || parsed.role !== input.role) continue;
19797
20135
  const runId = parsed.runId;
19798
20136
  const parentPath = await readRunParentPath(runDirectory);
@@ -20547,7 +20885,7 @@ init_filed_submission();
20547
20885
  init_report_ticket_tool();
20548
20886
  import { randomUUID as randomUUID7 } from "node:crypto";
20549
20887
  import { writeSync as writeSync2 } from "node:fs";
20550
- import { join as join30 } from "node:path";
20888
+ import { join as join31 } from "node:path";
20551
20889
  import { Value as Value3 } from "typebox/value";
20552
20890
 
20553
20891
  // src/activation-trace.ts
@@ -20597,7 +20935,7 @@ import {
20597
20935
  lstatSync as lstatSync2,
20598
20936
  realpathSync as realpathSync2,
20599
20937
  statSync as statSync7,
20600
- writeFileSync as writeFileSync2
20938
+ writeFileSync as writeFileSync3
20601
20939
  } from "node:fs";
20602
20940
  import { isAbsolute as isAbsolute10, resolve as resolve14 } from "node:path";
20603
20941
  var ActivationSessionFileMissingError = class extends Error {
@@ -20618,7 +20956,7 @@ function materializeDeferredSessionFile(sessionManager, resolvedFile) {
20618
20956
  throw new ActivationSessionFileMissingError(resolvedFile);
20619
20957
  }
20620
20958
  try {
20621
- writeFileSync2(resolvedFile, `${JSON.stringify(header)}
20959
+ writeFileSync3(resolvedFile, `${JSON.stringify(header)}
20622
20960
  `, { flag: "wx" });
20623
20961
  } catch (error) {
20624
20962
  if (errnoCode(error) !== "EEXIST") {
@@ -21054,10 +21392,10 @@ init_run_ticket_number();
21054
21392
 
21055
21393
  // src/audited-run-identity.ts
21056
21394
  init_role_run_placement();
21057
- import { basename as basename13 } from "node:path";
21395
+ import { basename as basename14 } from "node:path";
21058
21396
  var AUDITED_RUN_IDENTITY_KIND = "audited-run-identity";
21059
21397
  function auditedRunIdentityFromDirectory(runDirectory) {
21060
- const parsed = parseRunLeaf(basename13(runDirectory));
21398
+ const parsed = parseRunLeaf(basename14(runDirectory));
21061
21399
  if (parsed === void 0) return void 0;
21062
21400
  return formatRunLeaf(parsed.runId, parsed.role);
21063
21401
  }
@@ -21236,7 +21574,7 @@ import "typebox";
21236
21574
 
21237
21575
  // src/navigator-public-session.ts
21238
21576
  init_host_session_record();
21239
- import { basename as basename14 } from "node:path";
21577
+ import { basename as basename15 } from "node:path";
21240
21578
 
21241
21579
  // src/navigator-session-contracts.ts
21242
21580
  init_unknown_value();
@@ -21440,7 +21778,7 @@ async function resolveNavigatorLedgerHome(context) {
21440
21778
  return void 0;
21441
21779
  }
21442
21780
  function runIdFromNavigatorDirectory(runDirectory) {
21443
- const parsed = parseRunLeaf(basename14(runDirectory));
21781
+ const parsed = parseRunLeaf(basename15(runDirectory));
21444
21782
  if (parsed === void 0 || parsed.role !== "navigator") return void 0;
21445
21783
  return parsed.runId;
21446
21784
  }
@@ -22071,7 +22409,7 @@ init_unknown_value();
22071
22409
  init_submission_errors();
22072
22410
  init_worker_submission_contracts();
22073
22411
  import { execFileSync as execFileSync3 } from "node:child_process";
22074
- import { existsSync as existsSync13, lstatSync as lstatSync3, readdirSync as readdirSync3, readFileSync as readFileSync4, rmdirSync, rmSync as rmSync3 } from "node:fs";
22412
+ import { existsSync as existsSync14, lstatSync as lstatSync3, readdirSync as readdirSync4, readFileSync as readFileSync5, rmdirSync, rmSync as rmSync4 } from "node:fs";
22075
22413
  import { resolve as resolve16 } from "node:path";
22076
22414
  var WORKER_COMMIT_BASELINE_ENTRY_TYPE = "commit-baseline";
22077
22415
  var WORKER_COMMIT_REMINDER_BOUNCE_ENTRY_TYPE = "commit-reminder-bounce";
@@ -22101,7 +22439,7 @@ function statusOf(error) {
22101
22439
  return typeof error === "object" && error !== null && "status" in error ? error.status : void 0;
22102
22440
  }
22103
22441
  function tryGetAll(file, key) {
22104
- if (!existsSync13(file)) return [];
22442
+ if (!existsSync14(file)) return [];
22105
22443
  try {
22106
22444
  const out = gitFile(file, ["--get-all", key]);
22107
22445
  return out.length === 0 ? [] : out.split("\n");
@@ -22111,8 +22449,8 @@ function tryGetAll(file, key) {
22111
22449
  }
22112
22450
  }
22113
22451
  function ownedHook(path) {
22114
- if (!existsSync13(path)) return false;
22115
- return readFileSync4(path, "utf8").includes(HOOK_MARKER);
22452
+ if (!existsSync14(path)) return false;
22453
+ return readFileSync5(path, "utf8").includes(HOOK_MARKER);
22116
22454
  }
22117
22455
  function escapeGitConfigValueRegex(value) {
22118
22456
  return value.replace(/[\\^$.*+?()[\]{}|]/g, "\\$&");
@@ -22137,13 +22475,13 @@ function unsetOwnedHooksPath(file) {
22137
22475
  function rmOwnedDir(dir) {
22138
22476
  const hookPath = resolve16(dir, HOOK_FILE);
22139
22477
  if (!ownedHook(hookPath)) return;
22140
- rmSync3(hookPath, { force: true });
22141
- if (existsSync13(dir) && readdirSync3(dir).length === 0) rmdirSync(dir);
22478
+ rmSync4(hookPath, { force: true });
22479
+ if (existsSync14(dir) && readdirSync4(dir).length === 0) rmdirSync(dir);
22142
22480
  }
22143
22481
  function linkedGitDirs(commonDir) {
22144
22482
  const root = resolve16(commonDir, "worktrees");
22145
- if (!existsSync13(root)) return [];
22146
- return readdirSync3(root).map((name) => resolve16(root, name)).filter((dir) => lstatSync3(dir).isDirectory());
22483
+ if (!existsSync14(root)) return [];
22484
+ return readdirSync4(root).map((name) => resolve16(root, name)).filter((dir) => lstatSync3(dir).isDirectory());
22147
22485
  }
22148
22486
  function uninstallPackageWorkerHooks(cwd) {
22149
22487
  let inside;
@@ -22161,7 +22499,7 @@ function uninstallPackageWorkerHooks(cwd) {
22161
22499
  clear(resolve16(commonDir, "config.worktree"));
22162
22500
  rmOwnedDir(resolve16(commonDir, HOOKS_DIR));
22163
22501
  const legacy = resolve16(commonDir, "hooks", HOOK_FILE);
22164
- if (ownedHook(legacy)) rmSync3(legacy, { force: true });
22502
+ if (ownedHook(legacy)) rmSync4(legacy, { force: true });
22165
22503
  for (const gitDir of linkedGitDirs(commonDir)) {
22166
22504
  clear(resolve16(gitDir, "config.worktree"));
22167
22505
  rmOwnedDir(resolve16(gitDir, HOOKS_DIR));
@@ -22239,11 +22577,11 @@ function reliableWindow(cwd, baseline, head) {
22239
22577
  const raw = git2(cwd, ["log", "--format=%P%x1e%s", range]);
22240
22578
  if (raw.length === 0) return [];
22241
22579
  return raw.split("\n").flatMap((line2) => {
22242
- const sep5 = line2.indexOf("");
22243
- if (sep5 < 0) return [];
22580
+ const sep6 = line2.indexOf("");
22581
+ if (sep6 < 0) return [];
22244
22582
  return [{
22245
- subject: line2.slice(sep5 + 1),
22246
- merge: line2.slice(0, sep5).trim().includes(" ")
22583
+ subject: line2.slice(sep6 + 1),
22584
+ merge: line2.slice(0, sep6).trim().includes(" ")
22247
22585
  }];
22248
22586
  });
22249
22587
  }
@@ -22981,7 +23319,7 @@ function readRoleRunCoordinates(ctx, label) {
22981
23319
  if (runDirectory === void 0) throw new Error(`${label} requires AK_ROLE_RUN_DIR`);
22982
23320
  const admitted = readPageSync(runDirectory, "admitted");
22983
23321
  if (typeof admitted?.projectRoot !== "string" || admitted.projectRoot.trim() === "") {
22984
- throw new Error(`${label} state.jsonl admitted-request row missing projectRoot (${join30(runDirectory, RUN_STATE_FILE)})`);
23322
+ throw new Error(`${label} state.jsonl admitted-request row missing projectRoot (${join31(runDirectory, RUN_STATE_FILE)})`);
22985
23323
  }
22986
23324
  return {
22987
23325
  runDirectory,
@@ -23247,7 +23585,10 @@ function createRoleRuntimeExtension(dependencies, deliveryRequestLimit) {
23247
23585
  settleNavigatorProjection
23248
23586
  );
23249
23587
  };
23250
- roleHost.on("input", (_event) => {
23588
+ roleHost.on("input", (event, ctx) => {
23589
+ if (typeof event.text === "string" && ctx.summonsInstruction === void 0) {
23590
+ ctx.summonsInstruction = event.text;
23591
+ }
23251
23592
  const role = roleHost.getFlag(ROLE_FLAG.name);
23252
23593
  if (role !== void 0 && !admitted) return { action: "handled" };
23253
23594
  return { action: "continue" };
@@ -23402,6 +23743,8 @@ function createRoleRuntimeExtension(dependencies, deliveryRequestLimit) {
23402
23743
  }
23403
23744
  if (receiptDelivery.nextAction() === "request-delivery") {
23404
23745
  receiptDelivery.recordDeliveryRequest();
23746
+ const deliveryContent = turnDialoguePrompt ?? "";
23747
+ ctx.summonsInstruction = deliveryContent;
23405
23748
  const scopeId = ctx.invocationScopeId?.trim() ?? "";
23406
23749
  envelopeHost.appendEntry(
23407
23750
  RECEIPT_DELIVERY_REQUEST_ENTRY,
@@ -23417,7 +23760,7 @@ function createRoleRuntimeExtension(dependencies, deliveryRequestLimit) {
23417
23760
  });
23418
23761
  envelopeHost.sendMessage({
23419
23762
  customType: "ak-receipt-delivery-prompt",
23420
- content: turnDialoguePrompt ?? "",
23763
+ content: deliveryContent,
23421
23764
  display: false
23422
23765
  }, { triggerTurn: true, deliverAs: "followUp" });
23423
23766
  } else if (receiptDelivery.nextAction() === "no-receipt" && !noReceiptRecorded) {
@@ -24349,6 +24692,7 @@ async function prepareRoleEnvelope(options) {
24349
24692
  const record = value;
24350
24693
  if (record.action === "transform" && typeof record.text === "string") prompt = record.text;
24351
24694
  }
24695
+ context.summonsInstruction = prompt;
24352
24696
  if (typeof prompt === "string" && prompt.trim() !== "") {
24353
24697
  sessionEntries.push({
24354
24698
  type: "message",
@@ -24390,6 +24734,9 @@ async function prepareRoleEnvelope(options) {
24390
24734
  }],
24391
24735
  systemPrompt: { body: systemPromptBody, materials: readingMaterials },
24392
24736
  prompt,
24737
+ recordSentInstruction(text) {
24738
+ context.summonsInstruction = text;
24739
+ },
24393
24740
  abortSignal: hostAbort.signal,
24394
24741
  closeRound,
24395
24742
  dispose,
@@ -24970,12 +25317,12 @@ function createAcpRoleTurnHost(config) {
24970
25317
  // src/acp-host/seat-profile-soul.ts
24971
25318
  import { constants as constants3 } from "node:fs";
24972
25319
  import { access as access3, copyFile, lstat as lstat4, mkdir as mkdir4, readlink, symlink as symlink2, unlink as unlink3 } from "node:fs/promises";
24973
- import { dirname as dirname20, join as join31, relative as relative3, resolve as resolve18 } from "node:path";
25320
+ import { dirname as dirname20, join as join32, relative as relative4, resolve as resolve18 } from "node:path";
24974
25321
  function seatProfileName(spec, role) {
24975
25322
  return `${spec.namePrefix}${role}`;
24976
25323
  }
24977
25324
  function packageRoleSoulPath(packageRoot, role) {
24978
- return join31(packageRoot, "souls", `${role}.md`);
25325
+ return join32(packageRoot, "souls", `${role}.md`);
24979
25326
  }
24980
25327
  async function pathExists2(path) {
24981
25328
  try {
@@ -24992,21 +25339,21 @@ async function ensureSeatProfileSoul(options) {
24992
25339
  if (!await pathExists2(soulTarget)) {
24993
25340
  throw new Error(`packaged role soul missing: ${soulTarget}`);
24994
25341
  }
24995
- const profilesRoot = join31(operatorHome, ...spec.profilesRootFromHome);
24996
- const profileDir = join31(profilesRoot, profileName);
25342
+ const profilesRoot = join32(operatorHome, ...spec.profilesRootFromHome);
25343
+ const profileDir = join32(profilesRoot, profileName);
24997
25344
  const hostRoot = dirname20(profilesRoot);
24998
- const soulPath = join31(profileDir, spec.soulFileName);
25345
+ const soulPath = join32(profileDir, spec.soulFileName);
24999
25346
  if (!await pathExists2(profileDir)) {
25000
25347
  await mkdir4(profileDir, { recursive: true });
25001
25348
  for (const name of ["auth.json", ".env", "config.yaml"]) {
25002
- const source = join31(hostRoot, name);
25349
+ const source = join32(hostRoot, name);
25003
25350
  if (!await pathExists2(source)) continue;
25004
- await copyFile(source, join31(profileDir, name));
25351
+ await copyFile(source, join32(profileDir, name));
25005
25352
  }
25006
25353
  } else {
25007
25354
  await mkdir4(profileDir, { recursive: true });
25008
25355
  }
25009
- const desiredLink = relative3(profileDir, soulTarget);
25356
+ const desiredLink = relative4(profileDir, soulTarget);
25010
25357
  let current;
25011
25358
  try {
25012
25359
  const st = await lstat4(soulPath);