@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
@@ -1045,6 +1045,12 @@ function appendSitianRecordBlock(input, block) {
1045
1045
  function resolveSitianVolumeCategory(kind) {
1046
1046
  return kind;
1047
1047
  }
1048
+ function runDirectoryOwningSessionParent(sessionParentDir) {
1049
+ if (basename3(sessionParentDir) !== "session") return void 0;
1050
+ const runDirectory = dirname3(sessionParentDir);
1051
+ if (parseRunLeaf(basename3(runDirectory)) === void 0) return void 0;
1052
+ return runDirectory;
1053
+ }
1048
1054
  function sitianVolumeDirectory(sessionDirectory, category) {
1049
1055
  return join2(sessionDirectory, category);
1050
1056
  }
@@ -1076,8 +1082,8 @@ function resolveSitianRecordPathInLedger(input, ledgerHome) {
1076
1082
  throw new Error("Sitian record ownership requires a parent session inside the ledger home");
1077
1083
  }
1078
1084
  const sessionParentDir = dirname3(input.sessionParent);
1079
- const runDirectory = dirname3(sessionParentDir);
1080
- if (basename3(sessionParentDir) === "session" && parseRunLeaf(basename3(runDirectory)) !== void 0) {
1085
+ const runDirectory = runDirectoryOwningSessionParent(sessionParentDir);
1086
+ if (runDirectory !== void 0) {
1081
1087
  sessionDir = runDirectory;
1082
1088
  recordFile = join2(runDirectory, RUN_HISTORY_KINDS.has(input.kind) ? RUN_HISTORY_FILE : RUN_STATE_KINDS.has(input.kind) ? RUN_STATE_FILE : RUN_LOG_FILE);
1083
1089
  } else {
@@ -1310,7 +1316,9 @@ function render(runDirectory, history, state, log, unreadable) {
1310
1316
  original = payload.landingPath;
1311
1317
  }
1312
1318
  }
1313
- if (typeof original === "string") original = join3(runDirectory, "session", basename4(original));
1319
+ if (typeof original === "string") {
1320
+ original = join3(sessionDirectoryOf(runDirectory), basename4(original));
1321
+ }
1314
1322
  whole.host = { sessions, ...original === void 0 ? {} : { original } };
1315
1323
  whole.submission = latest === void 0 ? {} : { latest };
1316
1324
  if (Object.keys(unreadable).length > 0) whole.unreadable = unreadable;
@@ -1548,6 +1556,16 @@ function parseRunLeaf(name) {
1548
1556
  if (at <= 0 || at === name.length - 1) return void 0;
1549
1557
  return { runId: name.slice(0, at), role: name.slice(at + 1) };
1550
1558
  }
1559
+ function subjectDirectoryOfRun(runDirectory) {
1560
+ const runsParent = dirname4(runDirectory);
1561
+ if (basename5(runsParent) !== "runs") return void 0;
1562
+ const subjectDirectory = dirname4(runsParent);
1563
+ const subjectName = basename5(subjectDirectory);
1564
+ if (subjectName === "unbound" || /^[1-9]\d*$/.test(subjectName)) {
1565
+ return subjectDirectory;
1566
+ }
1567
+ return void 0;
1568
+ }
1551
1569
  function sessionDirectoryOf(runDirectory) {
1552
1570
  return join5(runDirectory, "session");
1553
1571
  }
@@ -1640,6 +1658,7 @@ function ensureRoleRunDirectory(ledgerHome, directory) {
1640
1658
  return ensureRealDirectoryTree(ledgerHome, directory);
1641
1659
  }
1642
1660
  function ensureRoleRunPlacement(ledgerHome, placement) {
1661
+ ensureRoleRunDirectory(ledgerHome, placement.runDirectory);
1643
1662
  ensureRoleRunDirectory(ledgerHome, placement.sessionDirectory);
1644
1663
  }
1645
1664
  var ROLE_RUN_SESSION_FILENAME;
@@ -12583,7 +12602,8 @@ var init_role_activation_flags = __esm({
12583
12602
 
12584
12603
  // src/user-dialogue-stdin.ts
12585
12604
  function encodeUserDialogueStdin(body) {
12586
- return JSON.stringify({ kind: USER_DIALOGUE_STDIN_KIND, body });
12605
+ const envelope = { kind: USER_DIALOGUE_STDIN_KIND, body };
12606
+ return JSON.stringify(envelope);
12587
12607
  }
12588
12608
  var USER_DIALOGUE_STDIN_KIND;
12589
12609
  var init_user_dialogue_stdin = __esm({
@@ -12913,17 +12933,6 @@ var init_submission_correctable_error = __esm({
12913
12933
  }
12914
12934
  });
12915
12935
 
12916
- // src/sha256.ts
12917
- import { createHash } from "node:crypto";
12918
- function sha256Hex(bytes) {
12919
- return createHash("sha256").update(bytes).digest("hex");
12920
- }
12921
- var init_sha256 = __esm({
12922
- "src/sha256.ts"() {
12923
- "use strict";
12924
- }
12925
- });
12926
-
12927
12936
  // src/package-contracts/terminating-tools.ts
12928
12937
  function isTerminatingToolName(name) {
12929
12938
  return TERMINATING_TOOL_NAMES.includes(name);
@@ -12984,9 +12993,149 @@ var init_terminating_tools = __esm({
12984
12993
  }
12985
12994
  });
12986
12995
 
12996
+ // src/ticket-progress.ts
12997
+ import {
12998
+ appendFileSync as appendFileSync2,
12999
+ existsSync as existsSync2,
13000
+ mkdirSync as mkdirSync3,
13001
+ readFileSync as readFileSync3,
13002
+ readdirSync as readdirSync2,
13003
+ rmSync as rmSync3,
13004
+ writeFileSync as writeFileSync2
13005
+ } from "node:fs";
13006
+ import { basename as basename7, dirname as dirname7, join as join11, relative as relative2, sep as sep3 } from "node:path";
13007
+ function parseProgressText(text, pathForDiagnostic) {
13008
+ if (text.trim() === "") return [];
13009
+ const { records, diagnostics } = parseSitianRecordText(text);
13010
+ for (const diagnostic of diagnostics) {
13011
+ process.stderr.write(
13012
+ `[ticket-progress] ${pathForDiagnostic} has malformed row(s); keeps reachable rows and retains the diagnostic: line ${diagnostic.line}: ${diagnostic.error}
13013
+ `
13014
+ );
13015
+ }
13016
+ const lines = [];
13017
+ for (const record of records) {
13018
+ const parsed = record;
13019
+ if (!isRecord(parsed)) continue;
13020
+ if (typeof parsed.seat !== "string" || typeof parsed.round !== "string") continue;
13021
+ lines.push(parsed);
13022
+ }
13023
+ return lines;
13024
+ }
13025
+ function readProgressFile(path) {
13026
+ if (!existsSync2(path)) return [];
13027
+ return parseProgressText(readFileSync3(path, "utf8"), path);
13028
+ }
13029
+ function readTicketProgressLines(subjectDirectory) {
13030
+ if (basename7(subjectDirectory) === "unbound") {
13031
+ const runsDir = join11(subjectDirectory, "runs");
13032
+ if (!existsSync2(runsDir)) return [];
13033
+ const out = [];
13034
+ for (const name of readdirSync2(runsDir).sort()) {
13035
+ out.push(...readProgressFile(join11(runsDir, name, LEG_PROGRESS_FILENAME)));
13036
+ }
13037
+ return out;
13038
+ }
13039
+ return readProgressFile(join11(subjectDirectory, CURRENT_FILENAME));
13040
+ }
13041
+ function roundBaseNumber(round) {
13042
+ if (round.trim() === "") return 0;
13043
+ const base = round.includes(".") ? round.slice(0, round.indexOf(".")) : round;
13044
+ const n = Number(base);
13045
+ return Number.isSafeInteger(n) && n > 0 ? n : 0;
13046
+ }
13047
+ function roundLens(round) {
13048
+ return round.includes(".") ? round.slice(round.indexOf(".") + 1) : void 0;
13049
+ }
13050
+ function nextRoundFromLines(lines, seat, lens) {
13051
+ const want = lens === void 0 || lens.trim() === "" ? void 0 : lens;
13052
+ let max = 0;
13053
+ for (const line2 of lines) {
13054
+ if (line2.seat !== seat) continue;
13055
+ if (roundLens(line2.round) !== want) continue;
13056
+ max = Math.max(max, roundBaseNumber(line2.round));
13057
+ }
13058
+ const base = max + 1;
13059
+ return want === void 0 ? String(base) : `${base}.${want}`;
13060
+ }
13061
+ function lensFromRunDirectory(runDirectory, role) {
13062
+ if (role !== "reviewer") return void 0;
13063
+ const lens = readPageSync(runDirectory, "admitted")?.lens;
13064
+ return lens === "completeness" || lens === "correctness" ? lens : void 0;
13065
+ }
13066
+ function relocateTicketProgressForLeg(input) {
13067
+ if (isUnboundRunDirectory(input.runDirectory)) return;
13068
+ const subjectDirectory = subjectDirectoryOfRun(input.runDirectory);
13069
+ if (subjectDirectory === void 0) return;
13070
+ const stagedPath = join11(input.runDirectory, LEG_PROGRESS_FILENAME);
13071
+ const mine = readProgressFile(stagedPath);
13072
+ if (mine.length === 0) {
13073
+ if (existsSync2(stagedPath)) {
13074
+ rmSync3(stagedPath, { force: true });
13075
+ }
13076
+ return;
13077
+ }
13078
+ const ticketLines = [...readTicketProgressLines(subjectDirectory)];
13079
+ const publishedReceipts = new Set(
13080
+ ticketLines.map((line2) => line2.receipt).filter((receipt) => typeof receipt === "string" && receipt !== "")
13081
+ );
13082
+ const pending = mine.filter((line2) => !publishedReceipts.has(line2.receipt));
13083
+ if (pending.length === 0) {
13084
+ rmSync3(stagedPath, { force: true });
13085
+ return;
13086
+ }
13087
+ const movedLines = [];
13088
+ for (const line2 of pending) {
13089
+ const lens = lensFromRunDirectory(input.runDirectory, line2.seat);
13090
+ const round = nextRoundFromLines(ticketLines, line2.seat, lens);
13091
+ const moved = {
13092
+ ...line2,
13093
+ round
13094
+ };
13095
+ movedLines.push(moved);
13096
+ ticketLines.push(moved);
13097
+ }
13098
+ const newCurrent = join11(subjectDirectory, CURRENT_FILENAME);
13099
+ mkdirSync3(dirname7(newCurrent), { recursive: true });
13100
+ appendFileSync2(
13101
+ newCurrent,
13102
+ `${movedLines.map((line2) => JSON.stringify(line2)).join("\n")}
13103
+ `,
13104
+ "utf8"
13105
+ );
13106
+ rmSync3(stagedPath, { force: true });
13107
+ }
13108
+ var CURRENT_FILENAME, LEG_PROGRESS_FILENAME;
13109
+ var init_ticket_progress = __esm({
13110
+ "src/ticket-progress.ts"() {
13111
+ "use strict";
13112
+ init_host_session_record();
13113
+ init_host_contracts();
13114
+ init_terminating_tools();
13115
+ init_packaged_role_registry();
13116
+ init_role_run_placement();
13117
+ init_run_dossier();
13118
+ init_sitian_reader();
13119
+ init_unknown_value();
13120
+ CURRENT_FILENAME = "current.jsonl";
13121
+ LEG_PROGRESS_FILENAME = "progress.jsonl";
13122
+ }
13123
+ });
13124
+
13125
+ // src/sha256.ts
13126
+ import { createHash } from "node:crypto";
13127
+ function sha256Hex(bytes) {
13128
+ return createHash("sha256").update(bytes).digest("hex");
13129
+ }
13130
+ var init_sha256 = __esm({
13131
+ "src/sha256.ts"() {
13132
+ "use strict";
13133
+ }
13134
+ });
13135
+
12987
13136
  // src/doctor-evidence.ts
12988
13137
  import { readdir as readdir2, readFile as readFile5, realpath, stat } from "node:fs/promises";
12989
- import { dirname as dirname7, relative as relative2, resolve as resolve4, sep as sep3 } from "node:path";
13138
+ import { dirname as dirname8, relative as relative3, resolve as resolve4, sep as sep4 } from "node:path";
12990
13139
  async function discoverCaseFiles(root) {
12991
13140
  const found = [];
12992
13141
  async function walk(dir, depth) {
@@ -13015,11 +13164,11 @@ async function stableRunsIdentity(root) {
13015
13164
  while (true) {
13016
13165
  try {
13017
13166
  const git2 = await stat(resolve4(cursor, ".git"));
13018
- if (git2.isDirectory() || git2.isFile()) return relative2(cursor, root).split(sep3).join("/");
13167
+ if (git2.isDirectory() || git2.isFile()) return relative3(cursor, root).split(sep4).join("/");
13019
13168
  } catch (error) {
13020
13169
  if (!isMissingPathError(error)) throw error;
13021
13170
  }
13022
- const parent = dirname7(cursor);
13171
+ const parent = dirname8(cursor);
13023
13172
  if (parent === cursor) return root;
13024
13173
  cursor = parent;
13025
13174
  }
@@ -13092,12 +13241,12 @@ async function loadDoctorCase(runsPath, projectRoot) {
13092
13241
  if (projectRoot !== void 0 && !physicallyContainedIn(projectRoot, root)) {
13093
13242
  throw new Error("doctor --runs escapes the project root");
13094
13243
  }
13095
- const match = root.split(sep3).join("/").match(/\/\.ak-roles\/books\/[^/]+\/(?:issues\/)?([1-9]\d*)\/runs$/);
13244
+ const match = root.split(sep4).join("/").match(/\/\.ak-roles\/books\/[^/]+\/(?:issues\/)?([1-9]\d*)\/runs$/);
13096
13245
  if (!match) throw new Error("Doctor case must be an .ak-roles/books/<book>/<n>/runs directory");
13097
13246
  const evidence = [], sessions = [], statuses = [], commits = [];
13098
13247
  const turns = { count: 0, sources: [] }, calls = { count: 0, sources: [] }, tokens = { count: 0, sources: [] };
13099
13248
  for (const path of await discoverCaseFiles(root)) {
13100
- const id = relative2(root, path).split(sep3).join("/");
13249
+ const id = relative3(root, path).split(sep4).join("/");
13101
13250
  const bytes = await readFile5(path);
13102
13251
  const content = bytes.toString("utf8");
13103
13252
  const kind = id.split("/").length === 2 && id.endsWith("/log.jsonl") ? "log" : "session";
@@ -13282,7 +13431,7 @@ var init_session_dialogue = __esm({
13282
13431
 
13283
13432
  // src/ticket-provenance.ts
13284
13433
  import { readFile as readFile7 } from "node:fs/promises";
13285
- import { join as join11, resolve as resolve6 } from "node:path";
13434
+ import { join as join12, resolve as resolve6 } from "node:path";
13286
13435
  function ticketProvenanceSubject(ticketNumber) {
13287
13436
  if (!isSafePositiveTicketNumber(ticketNumber)) {
13288
13437
  throw new Error(
@@ -13305,7 +13454,7 @@ async function rehomeUnboundTicketProvenance(runDirectory, ticketNumber, cwd, ho
13305
13454
  const ticketInput = ticketProvenanceRecordInput(ticketNumber, cwd, home);
13306
13455
  let history;
13307
13456
  try {
13308
- history = await readFile7(join11(runDirectory, RUN_HISTORY_FILE), "utf8");
13457
+ history = await readFile7(join12(runDirectory, RUN_HISTORY_FILE), "utf8");
13309
13458
  } catch (error) {
13310
13459
  if (errnoCode(error) === "ENOENT") return;
13311
13460
  throw error;
@@ -13361,7 +13510,7 @@ var init_uuidv7 = __esm({
13361
13510
  });
13362
13511
 
13363
13512
  // src/notary-source-run.ts
13364
- import { dirname as dirname8, isAbsolute as isAbsolute4, join as join12, resolve as resolve7, basename as basename7 } from "node:path";
13513
+ import { dirname as dirname9, isAbsolute as isAbsolute4, join as join13, resolve as resolve7, basename as basename8 } from "node:path";
13365
13514
  import { lstat as lstat2, realpath as realpath2 } from "node:fs/promises";
13366
13515
  async function readRetainedIdentity(runDirectory) {
13367
13516
  try {
@@ -13397,10 +13546,10 @@ async function requireRunDirectory(candidate, display) {
13397
13546
  `notary --source-run must be a run directory: ${display}`
13398
13547
  );
13399
13548
  }
13400
- const identity = parseRunLeaf(basename7(real));
13549
+ const identity = parseRunLeaf(basename8(real));
13401
13550
  if (identity === void 0) {
13402
13551
  throw new NotarySourceRunError(
13403
- `notary --source-run must be named <runId>@<role>: ${basename7(real)}`
13552
+ `notary --source-run must be named <runId>@<role>: ${basename8(real)}`
13404
13553
  );
13405
13554
  }
13406
13555
  return real;
@@ -13413,26 +13562,26 @@ async function resolveNotarySourceRunLocator(options) {
13413
13562
  const ledgerHome = resolveActivationLedgerHome(options.home);
13414
13563
  const bookKey = resolveBookKeyFromGit(options.projectRoot);
13415
13564
  const bookDirectory = activationBookDirectory(ledgerHome, bookKey);
13416
- const bookRunsRoot = join12(bookDirectory, "runs");
13565
+ const bookRunsRoot = join13(bookDirectory, "runs");
13417
13566
  let candidate;
13418
13567
  const bare = parseRunLeaf(raw);
13419
13568
  if (bare !== void 0 && !raw.includes("/") && !raw.includes("\\")) {
13420
- candidate = await findRunDirectoryById(options.home, bare.runId, bookKey, bare.role) ?? join12(bookRunsRoot, formatRunLeaf(bare.runId, bare.role));
13569
+ candidate = await findRunDirectoryById(options.home, bare.runId, bookKey, bare.role) ?? join13(bookRunsRoot, formatRunLeaf(bare.runId, bare.role));
13421
13570
  } else {
13422
13571
  candidate = isAbsolute4(raw) ? raw : resolve7(options.projectRoot, raw);
13423
- const identity2 = parseRunLeaf(basename7(candidate));
13424
- const subjectDirectory = dirname8(dirname8(candidate));
13425
- const isLegacyUnboundLocator = identity2 !== void 0 && basename7(dirname8(candidate)) === "runs" && basename7(subjectDirectory) === "unbound" && resolve7(dirname8(subjectDirectory)) === resolve7(bookDirectory);
13572
+ const identity2 = parseRunLeaf(basename8(candidate));
13573
+ const subjectDirectory = dirname9(dirname9(candidate));
13574
+ const isLegacyUnboundLocator = identity2 !== void 0 && basename8(dirname9(candidate)) === "runs" && basename8(subjectDirectory) === "unbound" && resolve7(dirname9(subjectDirectory)) === resolve7(bookDirectory);
13426
13575
  if (isLegacyUnboundLocator) {
13427
13576
  candidate = await resolveLiveRunDirectoryPath(candidate, options.home ?? ledgerHome, bookKey) ?? candidate;
13428
13577
  }
13429
13578
  }
13430
13579
  const real = await requireRunDirectory(candidate, raw);
13431
- const identity = parseRunLeaf(basename7(real));
13580
+ const identity = parseRunLeaf(basename8(real));
13432
13581
  const bookIdentity = physicalPathIdentity(bookDirectory);
13433
- const parentIdentity = physicalPathIdentity(dirname8(real));
13434
- const subjectBookIdentity = physicalPathIdentity(dirname8(dirname8(dirname8(real))));
13435
- if (parentIdentity !== physicalPathIdentity(bookRunsRoot) && !(basename7(dirname8(real)) === "runs" && subjectBookIdentity === bookIdentity)) {
13582
+ const parentIdentity = physicalPathIdentity(dirname9(real));
13583
+ const subjectBookIdentity = physicalPathIdentity(dirname9(dirname9(dirname9(real))));
13584
+ if (parentIdentity !== physicalPathIdentity(bookRunsRoot) && !(basename8(dirname9(real)) === "runs" && subjectBookIdentity === bookIdentity)) {
13436
13585
  throw new NotarySourceRunError(
13437
13586
  "notary --source-run must resolve to a retained run under the project machine-ledger book"
13438
13587
  );
@@ -14535,14 +14684,14 @@ var init_option_definitions = __esm({
14535
14684
 
14536
14685
  // src/public-cli/invocation.ts
14537
14686
  import { execFileSync as execFileSync2 } from "node:child_process";
14538
- import { existsSync as existsSync2 } from "node:fs";
14687
+ import { existsSync as existsSync3 } from "node:fs";
14539
14688
  import {
14540
14689
  readFile as readFile8,
14541
14690
  realpath as realpath3,
14542
14691
  rename,
14543
14692
  writeFile as writeFile2
14544
14693
  } from "node:fs/promises";
14545
- import { dirname as dirname9, isAbsolute as isAbsolute5, join as join13, resolve as resolve8 } from "node:path";
14694
+ import { dirname as dirname10, isAbsolute as isAbsolute5, join as join14, resolve as resolve8 } from "node:path";
14546
14695
  function admittedSourceRunPath(admitted) {
14547
14696
  if (!isRecord(admitted)) return void 0;
14548
14697
  const path = admitted.sourceRunPath;
@@ -14701,35 +14850,36 @@ async function recordAdmittedCorrelation(admitted, correlationId) {
14701
14850
  mutable.correlationId = correlationId;
14702
14851
  mutable.correlationIds = correlationIds;
14703
14852
  }
14704
- async function relocateAdmittedRunToTicket(admitted, authority, heldLease) {
14705
- if (admitted.ticketNumber === void 0 || !isUnboundRunDirectory(admitted.runDirectory)) return void 0;
14706
- const oldRunDirectory = admitted.runDirectory;
14707
- const ledgerHome = resolveActivationLedgerHome(homeFromRunDirectory(oldRunDirectory));
14708
- const target = roleRunPlacement(ledgerHome, {
14709
- bookKey: admitted.bookKey,
14710
- subject: { ticketNumber: admitted.ticketNumber },
14711
- runId: admitted.runId,
14712
- role: admitted.role
14713
- });
14714
- ensureRoleRunDirectory(ledgerHome, dirname9(target.runDirectory));
14715
- const principal = authority.seal(target);
14716
- if (admitted.role !== "diarist") {
14717
- const childRunIds = readPageSync(oldRunDirectory, "admitted")?.childDiaristRunIds;
14718
- for (const childRunId of Array.isArray(childRunIds) ? childRunIds : []) {
14719
- if (typeof childRunId !== "string") continue;
14720
- const childDirectory = join13(dirname9(oldRunDirectory), formatRunLeaf(childRunId, "diarist"));
14721
- if (!existsSync2(childDirectory)) continue;
14722
- const childTarget = roleRunPlacement(ledgerHome, {
14723
- bookKey: admitted.bookKey,
14724
- subject: { ticketNumber: admitted.ticketNumber },
14725
- runId: childRunId,
14726
- role: "diarist"
14853
+ async function relocateRegisteredChildDiarists(input) {
14854
+ const childRunIds = readPageSync(input.parentRunDirectory, "admitted")?.childDiaristRunIds;
14855
+ for (const childRunId of Array.isArray(childRunIds) ? childRunIds : []) {
14856
+ if (typeof childRunId !== "string") continue;
14857
+ const childTarget = roleRunPlacement(input.ledgerHome, {
14858
+ bookKey: input.bookKey,
14859
+ subject: { ticketNumber: input.ticketNumber },
14860
+ runId: childRunId,
14861
+ role: "diarist"
14862
+ });
14863
+ const unboundChildDirectory = roleRunPlacement(input.ledgerHome, {
14864
+ bookKey: input.bookKey,
14865
+ subject: { unbound: true },
14866
+ runId: childRunId,
14867
+ role: "diarist"
14868
+ }).runDirectory;
14869
+ if (existsSync3(unboundChildDirectory)) {
14870
+ input.authority.seal(childTarget);
14871
+ await bindTicketNumberOnRunDirectory(unboundChildDirectory, input.ticketNumber);
14872
+ await rehomeUnboundTicketProvenance(
14873
+ unboundChildDirectory,
14874
+ input.ticketNumber,
14875
+ input.projectRoot,
14876
+ homeFromRunDirectory(input.parentRunDirectory)
14877
+ );
14878
+ ensureRoleRunDirectory(input.ledgerHome, dirname10(childTarget.runDirectory));
14879
+ await rename(unboundChildDirectory, childTarget.runDirectory);
14880
+ relocateTicketProgressForLeg({
14881
+ runDirectory: childTarget.runDirectory
14727
14882
  });
14728
- authority.seal(childTarget);
14729
- await bindTicketNumberOnRunDirectory(childDirectory, admitted.ticketNumber);
14730
- await rehomeUnboundTicketProvenance(childDirectory, admitted.ticketNumber, admitted.projectRoot, homeFromRunDirectory(oldRunDirectory));
14731
- ensureRoleRunDirectory(ledgerHome, dirname9(childTarget.runDirectory));
14732
- await rename(childDirectory, childTarget.runDirectory);
14733
14883
  try {
14734
14884
  renderCurrentSync(childTarget.runDirectory);
14735
14885
  } catch (error) {
@@ -14738,18 +14888,71 @@ async function relocateAdmittedRunToTicket(admitted, authority, heldLease) {
14738
14888
  `
14739
14889
  );
14740
14890
  }
14891
+ continue;
14892
+ }
14893
+ if (existsSync3(childTarget.runDirectory)) {
14894
+ relocateTicketProgressForLeg({
14895
+ runDirectory: childTarget.runDirectory
14896
+ });
14741
14897
  }
14742
14898
  }
14899
+ }
14900
+ async function relocateAdmittedRunToTicket(admitted, authority, heldLease) {
14901
+ if (admitted.ticketNumber === void 0) return void 0;
14902
+ const ledgerHome = resolveActivationLedgerHome(homeFromRunDirectory(admitted.runDirectory));
14903
+ if (!isUnboundRunDirectory(admitted.runDirectory)) {
14904
+ relocateTicketProgressForLeg({
14905
+ runDirectory: admitted.runDirectory
14906
+ });
14907
+ if (admitted.role !== "diarist") {
14908
+ await relocateRegisteredChildDiarists({
14909
+ parentRunDirectory: admitted.runDirectory,
14910
+ bookKey: admitted.bookKey,
14911
+ ticketNumber: admitted.ticketNumber,
14912
+ projectRoot: admitted.projectRoot,
14913
+ ledgerHome,
14914
+ authority
14915
+ });
14916
+ }
14917
+ return void 0;
14918
+ }
14919
+ const oldRunDirectory = admitted.runDirectory;
14920
+ const target = roleRunPlacement(ledgerHome, {
14921
+ bookKey: admitted.bookKey,
14922
+ subject: { ticketNumber: admitted.ticketNumber },
14923
+ runId: admitted.runId,
14924
+ role: admitted.role
14925
+ });
14926
+ ensureRoleRunDirectory(ledgerHome, dirname10(target.runDirectory));
14927
+ authority.seal(target);
14928
+ if (admitted.role !== "diarist") {
14929
+ await relocateRegisteredChildDiarists({
14930
+ parentRunDirectory: oldRunDirectory,
14931
+ bookKey: admitted.bookKey,
14932
+ ticketNumber: admitted.ticketNumber,
14933
+ projectRoot: admitted.projectRoot,
14934
+ ledgerHome,
14935
+ authority
14936
+ });
14937
+ }
14743
14938
  if (admitted.role === "diarist") {
14744
14939
  await rehomeUnboundTicketProvenance(oldRunDirectory, admitted.ticketNumber, admitted.projectRoot, homeFromRunDirectory(oldRunDirectory));
14745
14940
  }
14746
14941
  await rename(oldRunDirectory, target.runDirectory);
14747
14942
  heldLease?.relocate(target.runDirectory);
14943
+ const actualSessionDirectory = sessionDirectoryOf(target.runDirectory);
14944
+ const principal = authority.seal({
14945
+ sessionDirectory: actualSessionDirectory,
14946
+ sessionFile: sessionFileIn(actualSessionDirectory)
14947
+ });
14748
14948
  rewriteAdmittedRoleRunPage(
14749
14949
  admitted,
14750
14950
  [{ oldRunDirectory, newRunDirectory: target.runDirectory }]
14751
14951
  );
14752
14952
  admitted.principal = principal;
14953
+ relocateTicketProgressForLeg({
14954
+ runDirectory: target.runDirectory
14955
+ });
14753
14956
  renderCurrentSync(target.runDirectory);
14754
14957
  return { oldRunDirectory, newRunDirectory: target.runDirectory };
14755
14958
  }
@@ -14785,7 +14988,7 @@ async function recordLaunchedPiIdentity(runDirectory, identity) {
14785
14988
  async function observeLaunchedRolePackageIdentity(packageRoot2, selectedRoleEntry) {
14786
14989
  const rolePackageRoot = packageRoot2;
14787
14990
  const raw = JSON.parse(
14788
- await readFile8(join13(rolePackageRoot, "package.json"), "utf8")
14991
+ await readFile8(join14(rolePackageRoot, "package.json"), "utf8")
14789
14992
  );
14790
14993
  if (typeof raw.version !== "string" || raw.version.trim() === "") {
14791
14994
  throw new Error(
@@ -15343,7 +15546,7 @@ async function admitPublicRole(role, parsed, env, override) {
15343
15546
  resolutionScope: [...derived.resolutionScope],
15344
15547
  authorizedChecks: []
15345
15548
  });
15346
- const mergerInputPath = join13(placed.runDirectory, "merger-input.json");
15549
+ const mergerInputPath = join14(placed.runDirectory, "merger-input.json");
15347
15550
  await writeFile2(
15348
15551
  mergerInputPath,
15349
15552
  `${JSON.stringify(mergerInput, null, 2)}
@@ -15611,7 +15814,7 @@ function parseDoctorIssueNumber(raw) {
15611
15814
  }
15612
15815
  async function resolveDoctorCaseRunsPath(options) {
15613
15816
  const ledgerHome = resolveActivationLedgerHome(options.home);
15614
- const defaultRuns = join13(
15817
+ const defaultRuns = join14(
15615
15818
  activationBookDirectory(ledgerHome, options.bookKey),
15616
15819
  String(options.issueNumber),
15617
15820
  "runs"
@@ -15684,11 +15887,11 @@ function parseAnalystCohortIssueToken(raw, flag) {
15684
15887
  `${flag} requires a comma-separated list of N or book:N`
15685
15888
  );
15686
15889
  }
15687
- const sep5 = trimmed.lastIndexOf(":");
15688
- if (sep5 > 0) {
15689
- const rhs = trimmed.slice(sep5 + 1);
15890
+ const sep6 = trimmed.lastIndexOf(":");
15891
+ if (sep6 > 0) {
15892
+ const rhs = trimmed.slice(sep6 + 1);
15690
15893
  if (parseTicketNumber(rhs) !== void 0) {
15691
- const bookKey = trimmed.slice(0, sep5);
15894
+ const bookKey = trimmed.slice(0, sep6);
15692
15895
  if (bookKey.trim() === "") {
15693
15896
  throw new CliUsageError(
15694
15897
  `${flag} book:N requires a non-empty book key, got ${raw}`
@@ -15885,6 +16088,7 @@ var init_invocation = __esm({
15885
16088
  init_activation_ledger_topology();
15886
16089
  init_activation_ledger_git();
15887
16090
  init_role_run_placement();
16091
+ init_ticket_progress();
15888
16092
  init_packaged_role_registry();
15889
16093
  init_run_ticket_number();
15890
16094
  init_role_run_relocation();
@@ -16096,6 +16300,7 @@ var init_submission_ledger = __esm({
16096
16300
  init_report_ticket_tool();
16097
16301
  init_review_submission();
16098
16302
  init_run_ticket_number();
16303
+ init_ticket_progress();
16099
16304
  init_unknown_value();
16100
16305
  }
16101
16306
  });
@@ -16266,7 +16471,7 @@ var init_engine_detour_usage = __esm({
16266
16471
  });
16267
16472
 
16268
16473
  // src/dossier-resolution.ts
16269
- import { existsSync as existsSync3, statSync as statSync5 } from "node:fs";
16474
+ import { existsSync as existsSync4, statSync as statSync5 } from "node:fs";
16270
16475
  import { resolve as resolve9 } from "node:path";
16271
16476
  function isHostContext(value) {
16272
16477
  return "sessionManager" in value;
@@ -16286,7 +16491,7 @@ function resolveAuditDossier(source) {
16286
16491
  }
16287
16492
  const runDirectory = resolve9(raw);
16288
16493
  try {
16289
- if (!existsSync3(runDirectory) || !statSync5(runDirectory).isDirectory()) {
16494
+ if (!existsSync4(runDirectory) || !statSync5(runDirectory).isDirectory()) {
16290
16495
  return { status: "incomplete", observation: { kind: "missing-dossier" } };
16291
16496
  }
16292
16497
  } catch {
@@ -17488,12 +17693,12 @@ var init_settlement = __esm({
17488
17693
  });
17489
17694
 
17490
17695
  // src/external-host-turn-loop.ts
17491
- import { existsSync as existsSync4 } from "node:fs";
17492
- import { basename as basename8 } from "node:path";
17696
+ import { existsSync as existsSync5 } from "node:fs";
17697
+ import { basename as basename9 } from "node:path";
17493
17698
  async function syncTurnRequestLivePlacement(request, authority) {
17494
17699
  const live = await resolveLiveRunDirectoryPath(request.runDirectory, request.home);
17495
17700
  if (live === void 0) {
17496
- const parsed = parseRunLeaf(basename8(request.runDirectory));
17701
+ const parsed = parseRunLeaf(basename9(request.runDirectory));
17497
17702
  throw new Error(
17498
17703
  `admitted run ${parsed?.runId ?? "(unparseable)"} missing after host turn; not found under ${request.home}`
17499
17704
  );
@@ -17505,7 +17710,7 @@ async function syncTurnRequestLivePlacement(request, authority) {
17505
17710
  }
17506
17711
  async function retainPackageFaultBesideLivePlacement(request, input) {
17507
17712
  let runDirectory = request.runDirectory;
17508
- if (!existsSync4(runDirectory)) {
17713
+ if (!existsSync5(runDirectory)) {
17509
17714
  try {
17510
17715
  const found = await resolveLiveRunDirectoryPath(request.runDirectory, request.home);
17511
17716
  if (found === void 0) {
@@ -17553,9 +17758,9 @@ var init_external_host_turn_loop = __esm({
17553
17758
  });
17554
17759
 
17555
17760
  // src/session-identity.ts
17556
- import { dirname as dirname10, join as join14 } from "node:path";
17761
+ import { join as join15 } from "node:path";
17557
17762
  function createSessionIdentityAuthority(authority, hostName) {
17558
- const runDirectoryOf = (principal) => dirname10(authority.decode(principal).sessionDirectory);
17763
+ const runDirectoryOf = (principal) => runDirectoryFromSessionDirectory(authority.decode(principal).sessionDirectory);
17559
17764
  return {
17560
17765
  principalAuthority: authority,
17561
17766
  resolveSessionFile(principal) {
@@ -17563,7 +17768,7 @@ function createSessionIdentityAuthority(authority, hostName) {
17563
17768
  },
17564
17769
  async load(principal) {
17565
17770
  const runDirectory = runDirectoryOf(principal);
17566
- const { records, diagnostics } = await readSitianRecords(join14(runDirectory, RUN_STATE_FILE));
17771
+ const { records, diagnostics } = await readSitianRecords(join15(runDirectory, RUN_STATE_FILE));
17567
17772
  if (diagnostics.length > 0) {
17568
17773
  throw new Error(
17569
17774
  `${RUN_STATE_FILE} has ${diagnostics.length} malformed row(s); refusing stale session binding: ${runDirectory}`
@@ -17610,6 +17815,7 @@ var init_session_identity = __esm({
17610
17815
  "src/session-identity.ts"() {
17611
17816
  "use strict";
17612
17817
  init_host_descriptions();
17818
+ init_role_run_placement();
17613
17819
  init_run_dossier();
17614
17820
  init_sitian_facade();
17615
17821
  init_unknown_value();
@@ -17632,14 +17838,14 @@ __export(role_turn_host_exports, {
17632
17838
  });
17633
17839
  import { execFile as execFile2, spawn } from "node:child_process";
17634
17840
  import { constants as constants2 } from "node:fs";
17635
- import { existsSync as existsSync5 } from "node:fs";
17841
+ import { existsSync as existsSync6 } from "node:fs";
17636
17842
  import { access as access2, appendFile, realpath as realpath4 } from "node:fs/promises";
17637
- import { delimiter, dirname as dirname11, isAbsolute as isAbsolute6, join as join15, resolve as resolve10 } from "node:path";
17843
+ import { delimiter, dirname as dirname11, isAbsolute as isAbsolute6, join as join16, resolve as resolve10 } from "node:path";
17638
17844
  import { platform } from "node:process";
17639
17845
  import { promisify as promisify2 } from "node:util";
17640
17846
  import { randomUUID as randomUUID4 } from "node:crypto";
17641
17847
  function resolveInternalRoleEntrypoint(packageRoot2) {
17642
- return join15(packageRoot2, INTERNAL_ROLE_ENTRYPOINT_RELATIVE2);
17848
+ return join16(packageRoot2, INTERNAL_ROLE_ENTRYPOINT_RELATIVE2);
17643
17849
  }
17644
17850
  function buildExplicitInternalActivationArgs(selectedRoleEntry, extraArgs = []) {
17645
17851
  return ["--no-extensions", "-e", selectedRoleEntry, ...extraArgs];
@@ -17829,7 +18035,7 @@ function createDefaultPiSpawnRunner(options) {
17829
18035
  homeFromRunDirectory(spawnDir)
17830
18036
  );
17831
18037
  } catch (resolveError) {
17832
- runDirectory = existsSync5(spawnDir) ? spawnDir : void 0;
18038
+ runDirectory = existsSync6(spawnDir) ? spawnDir : void 0;
17833
18039
  const resolveDiagnostic = `live run path resolve failed beside Pi transport fault: ${describeErrorIdentity(resolveError)}`;
17834
18040
  if (runDirectory !== void 0) {
17835
18041
  await retainPackageFault({
@@ -17882,7 +18088,8 @@ function createPiRoleTurnHost(config) {
17882
18088
  config.extraPiArgs ?? []
17883
18089
  );
17884
18090
  const args = buildExplicitInternalActivationArgs(roleEntry, extraArgs);
17885
- const stdin = encodeUserDialogueStdin(piUserDialogueBody(turnRequest));
18091
+ const transportBody = piUserDialogueBody(turnRequest);
18092
+ const stdin = encodeUserDialogueStdin(transportBody);
17886
18093
  const env = {
17887
18094
  ...process.env,
17888
18095
  HOME: request.home,
@@ -17898,6 +18105,7 @@ function createPiRoleTurnHost(config) {
17898
18105
  else env.AK_ROLE_INVOCATION_SCOPE = request.invocationScopeId;
17899
18106
  if (request.host === void 0 || request.host.trim() === "") delete env.AK_ROLE_HOST;
17900
18107
  else env.AK_ROLE_HOST = request.host.trim();
18108
+ delete env.AK_ROLE_SUMMONS_INSTRUCTION;
17901
18109
  if (request.deliveryRequestLimit === void 0) delete env[RECEIPT_DELIVERY_LIMIT_ENV];
17902
18110
  else env[RECEIPT_DELIVERY_LIMIT_ENV] = String(request.deliveryRequestLimit);
17903
18111
  applyEngineChildEnv(env, request.engine);
@@ -18030,17 +18238,17 @@ var init_role_turn_host = __esm({
18030
18238
  });
18031
18239
 
18032
18240
  // src/public-cli/load-production-acp-host.ts
18033
- import { existsSync as existsSync6 } from "node:fs";
18034
- import { join as join16 } from "node:path";
18241
+ import { existsSync as existsSync7 } from "node:fs";
18242
+ import { join as join17 } from "node:path";
18035
18243
  import { pathToFileURL } from "node:url";
18036
18244
  async function loadProductionAcpHostFactory(packageRoot2, host) {
18037
18245
  const description = lookupHostDescription(host);
18038
18246
  if (description === void 0) {
18039
18247
  throw new Error(`unregistered host: ${host}`);
18040
18248
  }
18041
- const built = join16(packageRoot2, "dist/acp-host/production-host.js");
18042
- const source = join16(packageRoot2, "src/acp-host/production-host.ts");
18043
- const target = existsSync6(built) ? built : source;
18249
+ const built = join17(packageRoot2, "dist/acp-host/production-host.js");
18250
+ const source = join17(packageRoot2, "src/acp-host/production-host.ts");
18251
+ const target = existsSync7(built) ? built : source;
18044
18252
  const href = pathToFileURL(target).href;
18045
18253
  const mod = await import(href);
18046
18254
  const create = mod.createProductionAcpRoleTurnHost;
@@ -18054,17 +18262,17 @@ var init_load_production_acp_host = __esm({
18054
18262
  });
18055
18263
 
18056
18264
  // src/public-cli/load-production-headless-host.ts
18057
- import { existsSync as existsSync7 } from "node:fs";
18058
- import { join as join17 } from "node:path";
18265
+ import { existsSync as existsSync8 } from "node:fs";
18266
+ import { join as join18 } from "node:path";
18059
18267
  import { pathToFileURL as pathToFileURL2 } from "node:url";
18060
18268
  async function loadProductionHeadlessHostFactory(packageRoot2, host) {
18061
18269
  const description = lookupHeadlessHostDescription(host);
18062
18270
  if (description === void 0) {
18063
18271
  throw new Error(`unregistered headless host: ${host}`);
18064
18272
  }
18065
- const built = join17(packageRoot2, "dist/headless-host/production-host.js");
18066
- const source = join17(packageRoot2, "src/headless-host/production-host.ts");
18067
- const target = existsSync7(built) ? built : source;
18273
+ const built = join18(packageRoot2, "dist/headless-host/production-host.js");
18274
+ const source = join18(packageRoot2, "src/headless-host/production-host.ts");
18275
+ const target = existsSync8(built) ? built : source;
18068
18276
  const href = pathToFileURL2(target).href;
18069
18277
  const mod = await import(href);
18070
18278
  const create = mod.createProductionHeadlessRoleTurnHost;
@@ -18231,14 +18439,14 @@ var init_role_seat_runtime = __esm({
18231
18439
  });
18232
18440
 
18233
18441
  // src/session-opening-materials.ts
18234
- import { existsSync as existsSync8 } from "node:fs";
18442
+ import { existsSync as existsSync9 } from "node:fs";
18235
18443
  import { readFile as readFile9 } from "node:fs/promises";
18236
- import { dirname as dirname12, join as join18 } from "node:path";
18444
+ import { dirname as dirname12, join as join19 } from "node:path";
18237
18445
  import { fileURLToPath, pathToFileURL as pathToFileURL3 } from "node:url";
18238
18446
  function resolvePackageRootDir(moduleUrl = import.meta.url) {
18239
18447
  let dir = dirname12(fileURLToPath(moduleUrl));
18240
18448
  for (let i = 0; i < 8; i += 1) {
18241
- if (existsSync8(join18(dir, "package.json")) && existsSync8(join18(dir, "souls"))) {
18449
+ if (existsSync9(join19(dir, "package.json")) && existsSync9(join19(dir, "souls"))) {
18242
18450
  return dir;
18243
18451
  }
18244
18452
  const parent = dirname12(dir);
@@ -18537,7 +18745,7 @@ __export(auditor_soul_exports, {
18537
18745
  readAuditorResumeBinding: () => readAuditorResumeBinding,
18538
18746
  resolveAuditorSubject: () => resolveAuditorSubject
18539
18747
  });
18540
- import { basename as basename9 } from "node:path";
18748
+ import { basename as basename10 } from "node:path";
18541
18749
  function auditorSoulRelativePath(role) {
18542
18750
  return `souls/${role}-auditor.md`;
18543
18751
  }
@@ -18573,7 +18781,7 @@ function loadAuditorReferenceMaterialsFromSubjectInput(raw) {
18573
18781
  return loadAuditorReferenceMaterials(resolveAuditorSubject(raw));
18574
18782
  }
18575
18783
  function subjectFromSourceDirectory(sourceRunDirectory) {
18576
- const role = parseRunLeaf(basename9(sourceRunDirectory))?.role;
18784
+ const role = parseRunLeaf(basename10(sourceRunDirectory))?.role;
18577
18785
  return isAuditorSoulRole(role) ? role : void 0;
18578
18786
  }
18579
18787
  async function readAuditorResumeBinding(admitted) {
@@ -18942,7 +19150,8 @@ function projectRoleTurnRequest(admitted, roleDetails, options) {
18942
19150
  ...options.invocationScopeId === void 0 || options.invocationScopeId.length === 0 ? {} : { invocationScopeId: options.invocationScopeId },
18943
19151
  ...options.stationChild === void 0 ? {} : { stationChild: options.stationChild },
18944
19152
  ...options.navigatorByStatusPrepare === void 0 ? {} : { navigatorByStatusPrepare: options.navigatorByStatusPrepare },
18945
- ...options.deliveryRequestLimit === void 0 ? {} : { deliveryRequestLimit: options.deliveryRequestLimit }
19153
+ ...options.deliveryRequestLimit === void 0 ? {} : { deliveryRequestLimit: options.deliveryRequestLimit },
19154
+ ...options.host === void 0 || options.host.trim() === "" ? {} : { host: options.host.trim() }
18946
19155
  };
18947
19156
  }
18948
19157
  function packagedSettleSkill(admitted) {
@@ -19336,7 +19545,7 @@ async function resolveReviewSeatDialogueBody(input) {
19336
19545
  if (sourceRunPath === void 0) return void 0;
19337
19546
  return await loadLedgerPeerBody(sourceRunPath, input.projectRoot, input.home);
19338
19547
  }
19339
- async function resolveInitialPrompt(admitted, env) {
19548
+ async function resolveInitialTurnPrompt(admitted, env) {
19340
19549
  const record = roleRecord(admitted.role);
19341
19550
  if ("reaskPrompt" in record && record.reaskPrompt === true) {
19342
19551
  const sourceRunPath = admittedSourceRunPath(admitted);
@@ -19433,7 +19642,7 @@ async function dispatchAdmitted(admitted, env, io) {
19433
19642
  if (activeEnv.correlationId !== void 0 && activeEnv.correlationId.trim() !== "") {
19434
19643
  await recordAdmittedCorrelation(admitted, activeEnv.correlationId);
19435
19644
  }
19436
- const initialPromptText = await resolveInitialPrompt(admitted, activeEnv);
19645
+ const initialPrompt = await resolveInitialTurnPrompt(admitted, activeEnv);
19437
19646
  const auto = "inCallAutoResume" in record && record.inCallAutoResume === true;
19438
19647
  if (auto) {
19439
19648
  return await runPostAdmissionResumable({
@@ -19444,14 +19653,14 @@ async function dispatchAdmitted(admitted, env, io) {
19444
19653
  admitted,
19445
19654
  roleTurnOptions(activeEnv, admitted, {
19446
19655
  kind: "initial",
19447
- prompt: initialPromptText
19656
+ prompt: initialPrompt
19448
19657
  })
19449
19658
  ),
19450
19659
  buildResumeRequest: () => buildInstructionSeatTurnRequest(
19451
19660
  admitted,
19452
19661
  roleTurnOptions(activeEnv, admitted, {
19453
19662
  kind: "resume",
19454
- prompt: initialPromptText
19663
+ prompt: initialPrompt
19455
19664
  })
19456
19665
  ),
19457
19666
  adapters,
@@ -19466,7 +19675,7 @@ async function dispatchAdmitted(admitted, env, io) {
19466
19675
  admitted,
19467
19676
  roleTurnOptions(activeEnv, admitted, {
19468
19677
  kind: "initial",
19469
- prompt: initialPromptText
19678
+ prompt: initialPrompt
19470
19679
  })
19471
19680
  ),
19472
19681
  adapters,
@@ -19642,7 +19851,7 @@ async function runCountersignBody(parsed, env, io) {
19642
19851
  }
19643
19852
  const turnProjection = roleTurnOptions(env, admitted, {
19644
19853
  kind: "initial",
19645
- prompt: await resolveInitialPrompt(admitted, env)
19854
+ prompt: await resolveInitialTurnPrompt(admitted, env)
19646
19855
  });
19647
19856
  const turnRequest = buildInstructionSeatTurnRequest(admitted, turnProjection);
19648
19857
  const result = await runPostAdmissionOneShot({
@@ -20498,9 +20707,9 @@ __export(public_role_summons_exports, {
20498
20707
  summonPublicRole: () => summonPublicRole
20499
20708
  });
20500
20709
  import { execFile as execFile3 } from "node:child_process";
20501
- import { existsSync as existsSync9 } from "node:fs";
20710
+ import { existsSync as existsSync10 } from "node:fs";
20502
20711
  import { realpath as realpath5 } from "node:fs/promises";
20503
- import { join as join20 } from "node:path";
20712
+ import { join as join21 } from "node:path";
20504
20713
  import { promisify as promisify3 } from "node:util";
20505
20714
  function createCapturingIo() {
20506
20715
  const chunks = [];
@@ -20524,7 +20733,7 @@ function parentDir(path) {
20524
20733
  function walkPackageRoot(start) {
20525
20734
  let dir = start;
20526
20735
  for (let i = 0; i < 12; i += 1) {
20527
- if (existsSync9(join20(dir, "package.json")) && existsSync9(join20(dir, "souls"))) {
20736
+ if (existsSync10(join21(dir, "package.json")) && existsSync10(join21(dir, "souls"))) {
20528
20737
  return dir;
20529
20738
  }
20530
20739
  const parent = parentDir(dir);
@@ -21066,7 +21275,7 @@ var init_compliance_transport = __esm({
21066
21275
  });
21067
21276
 
21068
21277
  // src/role-run-relocation.ts
21069
- import { dirname as dirname14, join as join21 } from "node:path";
21278
+ import { dirname as dirname14, join as join22 } from "node:path";
21070
21279
  async function retainedRunPathsMatch(recordedPath, currentPath, currentRunDirectory) {
21071
21280
  if (recordedPath === currentPath) return true;
21072
21281
  if (typeof recordedPath !== "string") return false;
@@ -21132,9 +21341,9 @@ __export(run_lifecycle_exports, {
21132
21341
  resolveLiveRunDirectoryPath: () => resolveLiveRunDirectoryPath,
21133
21342
  writeRoleRunState: () => writeRoleRunState
21134
21343
  });
21135
- import { existsSync as existsSync10 } from "node:fs";
21344
+ import { existsSync as existsSync11 } from "node:fs";
21136
21345
  import { chmod, lstat as lstat3, open, readdir as readdir3, readFile as readFile10, unlink } from "node:fs/promises";
21137
- import { basename as basename10, join as join22 } from "node:path";
21346
+ import { basename as basename11, join as join23 } from "node:path";
21138
21347
  async function writeRoleRunState(runDirectory, record) {
21139
21348
  const payload = { ...record, runDirectory };
21140
21349
  writeSectionSync(runDirectory, "runState", { ...payload });
@@ -21216,13 +21425,14 @@ async function readRoleRunStateDisk(runDirectory) {
21216
21425
  if (typeof record.sessionDirectory !== "string") throw new TypeError("Invalid state.jsonl run-state");
21217
21426
  const storedRunDirectory = typeof record.runDirectory === "string" && record.runDirectory.trim() !== "" ? record.runDirectory : runDirectory;
21218
21427
  const runDir = runDirectory;
21428
+ const principalCoords = {
21429
+ sessionDirectory: record.sessionDirectory,
21430
+ ...typeof record.sessionFile === "string" ? { sessionFile: record.sessionFile } : {}
21431
+ };
21432
+ rewritePrincipalSessionPaths(principalCoords, storedRunDirectory, runDirectory);
21219
21433
  const principalWire = {
21220
- sessionDirectory: rewriteRunDirectoryPathValue(
21221
- record.sessionDirectory,
21222
- storedRunDirectory,
21223
- runDirectory
21224
- ),
21225
- ...typeof record.sessionFile === "string" ? { sessionFile: rewriteRunDirectoryPathValue(record.sessionFile, storedRunDirectory, runDirectory) } : {}
21434
+ sessionDirectory: principalCoords.sessionDirectory,
21435
+ ...typeof principalCoords.sessionFile === "string" ? { sessionFile: principalCoords.sessionFile } : {}
21226
21436
  };
21227
21437
  const phase = record.phase === "plan" || record.phase === "apply" ? record.phase : void 0;
21228
21438
  const currentCourt = parseCurrentCourtState(record.currentCourt);
@@ -21428,7 +21638,7 @@ async function createWriterLease(lockPath, runDirectory, reportCleanupFailure) {
21428
21638
  },
21429
21639
  relocate(nextRunDirectory) {
21430
21640
  currentRunDirectory = nextRunDirectory;
21431
- currentLockPath = join22(nextRunDirectory, WRITER_LOCK_FILE);
21641
+ currentLockPath = join23(nextRunDirectory, WRITER_LOCK_FILE);
21432
21642
  },
21433
21643
  async release() {
21434
21644
  if (released) return;
@@ -21467,10 +21677,10 @@ async function acquireRunWriterLease(runDirectory, onCleanupFailure) {
21467
21677
  };
21468
21678
  const reportReadFailure = (error) => {
21469
21679
  reportDiagnostic(
21470
- `writer lease lock read failed (holder liveness unverifiable; lock left in place) at ${join22(runDirectory, WRITER_LOCK_FILE)}: ${describeErrorIdentity(error)}`
21680
+ `writer lease lock read failed (holder liveness unverifiable; lock left in place) at ${join23(runDirectory, WRITER_LOCK_FILE)}: ${describeErrorIdentity(error)}`
21471
21681
  );
21472
21682
  };
21473
- const lockPath = join22(runDirectory, WRITER_LOCK_FILE);
21683
+ const lockPath = join23(runDirectory, WRITER_LOCK_FILE);
21474
21684
  let lastAutopsy = { verdict: "absent" };
21475
21685
  let lastReclaimFailure;
21476
21686
  for (let reclaimsLeft = WRITER_LEASE_RECLAIM_ROUNDS; ; reclaimsLeft -= 1) {
@@ -21526,7 +21736,7 @@ async function acquireRunWriterLease(runDirectory, onCleanupFailure) {
21526
21736
  }
21527
21737
  async function findRunDirectoryById(home, runId, onlyBookKey, onlyRole, knownRunDirectory) {
21528
21738
  if (typeof knownRunDirectory === "string" && knownRunDirectory.trim() !== "") {
21529
- const parsed = parseRunLeaf(basename10(knownRunDirectory));
21739
+ const parsed = parseRunLeaf(basename11(knownRunDirectory));
21530
21740
  if (parsed === void 0 || parsed.runId !== runId) {
21531
21741
  throw new CliUsageError(
21532
21742
  `run directory does not match run id ${runId}: ${knownRunDirectory}`
@@ -21536,7 +21746,7 @@ async function findRunDirectoryById(home, runId, onlyBookKey, onlyRole, knownRun
21536
21746
  }
21537
21747
  if (runId.trim() === "") return void 0;
21538
21748
  const ledgerHome = resolveActivationLedgerHome(home);
21539
- const booksRoot = join22(ledgerHome, "books");
21749
+ const booksRoot = join23(ledgerHome, "books");
21540
21750
  let bookKeys;
21541
21751
  try {
21542
21752
  bookKeys = await readdir3(booksRoot);
@@ -21551,8 +21761,8 @@ async function findRunDirectoryById(home, runId, onlyBookKey, onlyRole, knownRun
21551
21761
  );
21552
21762
  }
21553
21763
  async function resolveLiveRunDirectoryPath(recordedPath, home, onlyBookKey) {
21554
- if (existsSync10(recordedPath)) return recordedPath;
21555
- const parsed = parseRunLeaf(basename10(recordedPath));
21764
+ if (existsSync11(recordedPath)) return recordedPath;
21765
+ const parsed = parseRunLeaf(basename11(recordedPath));
21556
21766
  const bookKey = onlyBookKey ?? tryBookKeyFromAkRolesPath(recordedPath);
21557
21767
  if (parsed === void 0 || bookKey === void 0) return void 0;
21558
21768
  return findRunDirectoryById(home, parsed.runId, bookKey, parsed.role);
@@ -21586,7 +21796,7 @@ async function findLatestRunForSeatTicket(input) {
21586
21796
  let runDirectories;
21587
21797
  try {
21588
21798
  runDirectories = await listBookRunDirectories(
21589
- input.ticketNumber === void 0 ? bookDir : join22(bookDir, String(input.ticketNumber))
21799
+ input.ticketNumber === void 0 ? bookDir : join23(bookDir, String(input.ticketNumber))
21590
21800
  );
21591
21801
  } catch (error) {
21592
21802
  if (errorCodeOf(error) === "ENOENT") return void 0;
@@ -21594,7 +21804,7 @@ async function findLatestRunForSeatTicket(input) {
21594
21804
  }
21595
21805
  let best;
21596
21806
  for (const runDirectory of runDirectories) {
21597
- const parsed = parseRunLeaf(basename10(runDirectory));
21807
+ const parsed = parseRunLeaf(basename11(runDirectory));
21598
21808
  if (parsed === void 0 || parsed.role !== input.role) continue;
21599
21809
  const runId = parsed.runId;
21600
21810
  const parentPath = await readRunParentPath(runDirectory);
@@ -29325,10 +29535,10 @@ var init_analyst_book_key = __esm({
29325
29535
  // src/atomic-write.ts
29326
29536
  import { randomUUID as randomUUID6 } from "node:crypto";
29327
29537
  import { rename as rename2, rm, writeFile as writeFile4 } from "node:fs/promises";
29328
- import { dirname as dirname15, join as join23 } from "node:path";
29538
+ import { dirname as dirname15, join as join24 } from "node:path";
29329
29539
  async function writeFileAtomically(destination, contents, options) {
29330
29540
  const parent = dirname15(destination);
29331
- const temporary = join23(parent, `.atomic-write-${randomUUID6()}.tmp`);
29541
+ const temporary = join24(parent, `.atomic-write-${randomUUID6()}.tmp`);
29332
29542
  try {
29333
29543
  await writeFile4(temporary, contents, options);
29334
29544
  await rename2(temporary, destination);
@@ -29345,12 +29555,12 @@ var init_atomic_write = __esm({
29345
29555
 
29346
29556
  // src/analyst-index.ts
29347
29557
  import { open as open2, readFile as readFile11, unlink as unlink2 } from "node:fs/promises";
29348
- import { dirname as dirname16, join as join24 } from "node:path";
29558
+ import { dirname as dirname16, join as join25 } from "node:path";
29349
29559
  import { setTimeout as sleep } from "node:timers/promises";
29350
29560
  async function withAnalystLibraryIndexLock(ledgerHome, fn) {
29351
29561
  const indexPath = analystLibraryIndexPath(ledgerHome);
29352
29562
  ensureRealDirectoryTree(ledgerHome, dirname16(indexPath));
29353
- const lockPath = join24(dirname16(indexPath), LIBRARY_INDEX_LOCK_NAME);
29563
+ const lockPath = join25(dirname16(indexPath), LIBRARY_INDEX_LOCK_NAME);
29354
29564
  assertLedgerFileInsideHome(lockPath, ledgerHome);
29355
29565
  const startedAt = Date.now();
29356
29566
  while (true) {
@@ -29377,7 +29587,7 @@ async function withAnalystLibraryIndexLock(ledgerHome, fn) {
29377
29587
  }
29378
29588
  }
29379
29589
  function analystLibraryIndexPath(ledgerHome) {
29380
- return join24(ledgerHome, "analyst", "library-index.json");
29590
+ return join25(ledgerHome, "analyst", "library-index.json");
29381
29591
  }
29382
29592
  function rowFromIssueMetricsPage(page) {
29383
29593
  return {
@@ -29671,7 +29881,7 @@ var init_analyst_cohort = __esm({
29671
29881
  });
29672
29882
 
29673
29883
  // src/archivist-record-pointer.ts
29674
- import { basename as basename11, join as join25 } from "node:path";
29884
+ import { basename as basename12, join as join26 } from "node:path";
29675
29885
  async function resolveOfficerPointer(raw, parentRunDirectory) {
29676
29886
  const where = `${parentRunDirectory} officers`;
29677
29887
  if (!isRecord(raw) || raw.kind !== DIRECT_OFFICER_RUN_POINTER_KIND || raw.version !== 1) {
@@ -29684,7 +29894,7 @@ async function resolveOfficerPointer(raw, parentRunDirectory) {
29684
29894
  let runDirectory = typeof raw.runDirectory === "string" && raw.runDirectory.trim() !== "" ? raw.runDirectory : void 0;
29685
29895
  let sessionFile = raw.sessionFile;
29686
29896
  const recordedRunDirectory = runDirectory ?? runDirectoryOfSessionFile(sessionFile);
29687
- const leaf = parseRunLeaf(basename11(recordedRunDirectory));
29897
+ const leaf = parseRunLeaf(basename12(recordedRunDirectory));
29688
29898
  const parentIdentity = await readRoleRunIdentity(parentRunDirectory);
29689
29899
  if (leaf !== void 0 && parentIdentity !== void 0) {
29690
29900
  const currentRunDirectory = await resolveLiveRunDirectoryPath(
@@ -29704,7 +29914,7 @@ async function resolveOfficerPointer(raw, parentRunDirectory) {
29704
29914
  };
29705
29915
  }
29706
29916
  async function readBookedOfficerPointers(parentRunDirectory) {
29707
- const { records, diagnostics } = await readSitianRecords(join25(parentRunDirectory, RUN_HISTORY_FILE));
29917
+ const { records, diagnostics } = await readSitianRecords(join26(parentRunDirectory, RUN_HISTORY_FILE));
29708
29918
  if (diagnostics.length > 0) {
29709
29919
  throw new Error(
29710
29920
  `${RUN_HISTORY_FILE} has ${diagnostics.length} malformed row(s); officer pointers unreadable: ${parentRunDirectory}`
@@ -29987,7 +30197,7 @@ var init_analyst_gate_cycles_read = __esm({
29987
30197
 
29988
30198
  // src/analyst-ledger.ts
29989
30199
  import { readdir as readdir4 } from "node:fs/promises";
29990
- import { basename as basename12, join as join26 } from "node:path";
30200
+ import { basename as basename13, join as join27 } from "node:path";
29991
30201
  async function readExistingRunLifecycleState(runDirectory) {
29992
30202
  return (await readRoleRunIdentity(runDirectory))?.state;
29993
30203
  }
@@ -30007,7 +30217,7 @@ function ghostLeaseCheckFromAutopsy(autopsy) {
30007
30217
  }
30008
30218
  }
30009
30219
  async function classifyGhostCandidate(input) {
30010
- const autopsy = await autopsyWriterLock(join26(input.runDirectory, "writer.lock"));
30220
+ const autopsy = await autopsyWriterLock(join27(input.runDirectory, "writer.lock"));
30011
30221
  const leaseCheck = ghostLeaseCheckFromAutopsy(autopsy);
30012
30222
  if (leaseCheck === void 0) return { kind: "live" };
30013
30223
  return {
@@ -30297,7 +30507,7 @@ async function classifyScopedRun(input) {
30297
30507
  async function scanAnalystIssueRuns(input) {
30298
30508
  const ledgerHome = resolveActivationLedgerHome(input.home);
30299
30509
  const scopeTicketNumber = input.ticketNumber;
30300
- const booksRoot = join26(ledgerHome, "books");
30510
+ const booksRoot = join27(ledgerHome, "books");
30301
30511
  let wholeBook = false;
30302
30512
  let scopeRootIdentity;
30303
30513
  let bookNames;
@@ -30330,7 +30540,7 @@ async function scanAnalystIssueRuns(input) {
30330
30540
  const ghostLegs = [];
30331
30541
  const scopeConflicts = [];
30332
30542
  for (const book of bookNames) {
30333
- const bookDir = join26(booksRoot, book);
30543
+ const bookDir = join27(booksRoot, book);
30334
30544
  let runDirectories;
30335
30545
  try {
30336
30546
  runDirectories = await listBookRunDirectories(bookDir);
@@ -30339,7 +30549,7 @@ async function scanAnalystIssueRuns(input) {
30339
30549
  throw error;
30340
30550
  }
30341
30551
  for (const runDirectory of runDirectories) {
30342
- const runName = basename12(runDirectory);
30552
+ const runName = basename13(runDirectory);
30343
30553
  const parsed = parseRunLeaf(runName);
30344
30554
  if (parsed === void 0) continue;
30345
30555
  let scopeFields;
@@ -31076,7 +31286,7 @@ var init_analyst_metric_family = __esm({
31076
31286
  });
31077
31287
 
31078
31288
  // src/analyst-page.ts
31079
- import { dirname as dirname17, join as join27 } from "node:path";
31289
+ import { dirname as dirname17, join as join28 } from "node:path";
31080
31290
  function analystIssuePageKey(address) {
31081
31291
  const parts = ["book", address.bookKey];
31082
31292
  if (address.issueNumber !== void 0) {
@@ -31087,7 +31297,7 @@ function analystIssuePageKey(address) {
31087
31297
  return sha256Hex(parts.join("\0")).slice(0, 32);
31088
31298
  }
31089
31299
  function analystIssuePagePath(ledgerHome, address) {
31090
- return join27(ledgerHome, "analyst", "issues", `${analystIssuePageKey(address)}.json`);
31300
+ return join28(ledgerHome, "analyst", "issues", `${analystIssuePageKey(address)}.json`);
31091
31301
  }
31092
31302
  function analystIssuePageAddressFromPage(page) {
31093
31303
  return {
@@ -32634,13 +32844,13 @@ var init_cli = __esm({
32634
32844
  });
32635
32845
 
32636
32846
  // src/public-cli/main.ts
32637
- import { existsSync as existsSync11 } from "node:fs";
32638
- import { dirname as dirname18, join as join28 } from "node:path";
32847
+ import { existsSync as existsSync12 } from "node:fs";
32848
+ import { dirname as dirname18, join as join29 } from "node:path";
32639
32849
  import { fileURLToPath as fileURLToPath2 } from "node:url";
32640
32850
  var here = dirname18(fileURLToPath2(import.meta.url));
32641
32851
  function resolvePackageRoot(binDir) {
32642
- const canonical = join28(binDir, "..", "..");
32643
- if (existsSync11(join28(canonical, "package.json"))) {
32852
+ const canonical = join29(binDir, "..", "..");
32853
+ if (existsSync12(join29(canonical, "package.json"))) {
32644
32854
  return canonical;
32645
32855
  }
32646
32856
  return binDir;