@akagilnc/pi-workflow-roles 0.1.6014 → 0.1.6021

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.
@@ -4282,6 +4282,67 @@ var init_run_terminal_artifacts = __esm({
4282
4282
  }
4283
4283
  });
4284
4284
 
4285
+ // src/session-opening-materials.ts
4286
+ import { existsSync as existsSync2 } from "node:fs";
4287
+ import { readFile as readFile5 } from "node:fs/promises";
4288
+ import { dirname as dirname7, join as join8 } from "node:path";
4289
+ import { fileURLToPath, pathToFileURL } from "node:url";
4290
+ function resolvePackageRootDir(moduleUrl = import.meta.url) {
4291
+ let dir = dirname7(fileURLToPath(moduleUrl));
4292
+ for (let i = 0; i < 8; i += 1) {
4293
+ if (existsSync2(join8(dir, "package.json")) && existsSync2(join8(dir, "souls"))) {
4294
+ return dir;
4295
+ }
4296
+ const parent = dirname7(dir);
4297
+ if (parent === dir) break;
4298
+ dir = parent;
4299
+ }
4300
+ return fileURLToPath(new URL("..", moduleUrl));
4301
+ }
4302
+ async function readPackageMaterial(relativePath) {
4303
+ return readFile5(fileURLToPath(new URL(relativePath, packageRootUrl)), "utf8");
4304
+ }
4305
+ async function joinPackageMaterials(relativePaths) {
4306
+ const chunks = [];
4307
+ for (const relativePath of relativePaths) chunks.push(await readPackageMaterial(relativePath));
4308
+ return chunks.join("\n\n");
4309
+ }
4310
+ function roleSoulPath(role, materials) {
4311
+ const suffix = `/souls/${role}.md`;
4312
+ const path = materials.find((candidate) => `/${candidate}`.endsWith(suffix));
4313
+ if (path === void 0) throw new Error(`session materials omit the ${role} Soul`);
4314
+ return path;
4315
+ }
4316
+ async function loadSeparatedSessionPart(role, materials, part) {
4317
+ const soul = roleSoulPath(role, materials);
4318
+ return part === "soul" ? readPackageMaterial(soul) : joinPackageMaterials(materials.filter((path) => path !== soul));
4319
+ }
4320
+ function loadMainRoleSessionMaterials(role) {
4321
+ return loadSeparatedSessionPart(role, MAIN_ROLE_SESSION_MATERIALS[role], "soul");
4322
+ }
4323
+ function loadMainRoleReferenceMaterials(role) {
4324
+ return loadSeparatedSessionPart(role, MAIN_ROLE_SESSION_MATERIALS[role], "references");
4325
+ }
4326
+ var packageRootUrl, MAIN_ROLE_SESSION_MATERIALS, GATEKEEPER_SESSION_MATERIALS;
4327
+ var init_session_opening_materials = __esm({
4328
+ "src/session-opening-materials.ts"() {
4329
+ "use strict";
4330
+ init_packaged_role_registry();
4331
+ packageRootUrl = pathToFileURL(resolvePackageRootDir() + "/").href;
4332
+ MAIN_ROLE_SESSION_MATERIALS = {
4333
+ ...Object.fromEntries(
4334
+ PUBLIC_ROLE_RECORDS.map((record) => [record.role, record.sessionMaterials])
4335
+ )
4336
+ };
4337
+ GATEKEEPER_SESSION_MATERIALS = {
4338
+ // #639: single authority — the public gatekeeper record owns the province list.
4339
+ gatekeeper: packagedRoleSessionMaterials("gatekeeper"),
4340
+ inspector: INSPECTOR_SESSION_MATERIALS,
4341
+ notary: NOTARY_SESSION_MATERIALS
4342
+ };
4343
+ }
4344
+ });
4345
+
4285
4346
  // src/public-cli/cli-errors.ts
4286
4347
  var cli_errors_exports = {};
4287
4348
  __export(cli_errors_exports, {
@@ -4779,8 +4840,8 @@ var init_gatekeeper_role = __esm({
4779
4840
  });
4780
4841
 
4781
4842
  // src/package-resources/engine-material.ts
4782
- import { existsSync as existsSync2, readFileSync as readFileSync2 } from "node:fs";
4783
- import { join as join8 } from "node:path";
4843
+ import { existsSync as existsSync3, readFileSync as readFileSync2 } from "node:fs";
4844
+ import { join as join9 } from "node:path";
4784
4845
  function pickEngineAxis(source) {
4785
4846
  return {
4786
4847
  ...source.engine === void 0 ? {} : { engine: source.engine },
@@ -4801,14 +4862,14 @@ function isEngineNameSyntax(name) {
4801
4862
  return true;
4802
4863
  }
4803
4864
  function resolveEngineMaterialDirectory(packageRoot) {
4804
- return join8(packageRoot, ENGINE_MATERIAL_RELATIVE_ROOT);
4865
+ return join9(packageRoot, ENGINE_MATERIAL_RELATIVE_ROOT);
4805
4866
  }
4806
4867
  function resolveEngineDispatchMaterialPath(packageRoot) {
4807
- return join8(packageRoot, ENGINE_DISPATCH_RELATIVE_PATH);
4868
+ return join9(packageRoot, ENGINE_DISPATCH_RELATIVE_PATH);
4808
4869
  }
4809
4870
  function resolveEngineMaterialPath(packageRoot, name) {
4810
4871
  const legal = assertLegalEngineName(name);
4811
- return join8(resolveEngineMaterialDirectory(packageRoot), `${legal}.md`);
4872
+ return join9(resolveEngineMaterialDirectory(packageRoot), `${legal}.md`);
4812
4873
  }
4813
4874
  function assertLegalEngineName(name) {
4814
4875
  if (!isEngineNameSyntax(name)) {
@@ -4825,12 +4886,12 @@ function engineSessionMaterialFromOptions(options) {
4825
4886
  const model = options.engineModel === void 0 ? void 0 : assertLegalEngineModel(options.engineModel);
4826
4887
  const materialPath = resolveEngineMaterialPath(options.packageRoot, name);
4827
4888
  const modelField = model === void 0 ? {} : { model };
4828
- if (!existsSync2(materialPath)) {
4889
+ if (!existsSync3(materialPath)) {
4829
4890
  return Object.freeze({ name, ...modelField });
4830
4891
  }
4831
4892
  const handbook = readFileSync2(materialPath, "utf8");
4832
4893
  const dispatchPath = resolveEngineDispatchMaterialPath(options.packageRoot);
4833
- const dispatchField = existsSync2(dispatchPath) ? { dispatchHandbook: readFileSync2(dispatchPath, "utf8") } : {};
4894
+ const dispatchField = existsSync3(dispatchPath) ? { dispatchHandbook: readFileSync2(dispatchPath, "utf8") } : {};
4834
4895
  return Object.freeze({ name, handbook, ...dispatchField, ...modelField });
4835
4896
  }
4836
4897
  function engineSessionReadingMaterial(engineMaterial) {
@@ -4967,8 +5028,8 @@ __export(config_exports, {
4967
5028
  setPersistentSeatHost: () => setPersistentSeatHost,
4968
5029
  validatePublicCliConfigAxes: () => validatePublicCliConfigAxes
4969
5030
  });
4970
- import { mkdir, readFile as readFile5, writeFile } from "node:fs/promises";
4971
- import { dirname as dirname7, join as join9 } from "node:path";
5031
+ import { mkdir, readFile as readFile6, writeFile } from "node:fs/promises";
5032
+ import { dirname as dirname8, join as join10 } from "node:path";
4972
5033
  function isGateOfficerSeat(value) {
4973
5034
  return packagedProvinceConfig(value);
4974
5035
  }
@@ -4976,12 +5037,12 @@ function publicCliConfigPath(home) {
4976
5037
  if (typeof home !== "string" || home.trim() === "") {
4977
5038
  throw new Error("home must be explicitly provided");
4978
5039
  }
4979
- return join9(home, ".ak-roles", "public-cli.json");
5040
+ return join10(home, ".ak-roles", "public-cli.json");
4980
5041
  }
4981
5042
  async function loadPublicCliConfig(home) {
4982
5043
  const path = publicCliConfigPath(home);
4983
5044
  try {
4984
- const raw = await readFile5(path, "utf8");
5045
+ const raw = await readFile6(path, "utf8");
4985
5046
  return parsePublicCliConfig(JSON.parse(raw));
4986
5047
  } catch (error) {
4987
5048
  if (isEnoent(error)) return { seats: {} };
@@ -4990,7 +5051,7 @@ async function loadPublicCliConfig(home) {
4990
5051
  }
4991
5052
  async function savePublicCliConfig(config, home) {
4992
5053
  const path = publicCliConfigPath(home);
4993
- await mkdir(dirname7(path), { recursive: true });
5054
+ await mkdir(dirname8(path), { recursive: true });
4994
5055
  const normalized = parsePublicCliConfig(config);
4995
5056
  await writeFile(
4996
5057
  path,
@@ -5436,11 +5497,11 @@ function credentialProvidersFromAuthData(data) {
5436
5497
  };
5437
5498
  }
5438
5499
  function resolvePublicAgentDir(explicit, home) {
5439
- return explicit ?? process.env.PI_CODING_AGENT_DIR ?? join9(home, ".pi", "agent");
5500
+ return explicit ?? process.env.PI_CODING_AGENT_DIR ?? join10(home, ".pi", "agent");
5440
5501
  }
5441
5502
  async function loadCredentialProviders(agentDir) {
5442
5503
  try {
5443
- const raw = await readFile5(join9(agentDir, "auth.json"), "utf8");
5504
+ const raw = await readFile6(join10(agentDir, "auth.json"), "utf8");
5444
5505
  return credentialProvidersFromAuthData(JSON.parse(raw));
5445
5506
  } catch (error) {
5446
5507
  if (isEnoent(error)) return { "openai-codex": false, xai: false };
@@ -5897,7 +5958,7 @@ var init_compliance_transport = __esm({
5897
5958
  });
5898
5959
 
5899
5960
  // src/role-run-relocation.ts
5900
- import { dirname as dirname8, join as join10 } from "node:path";
5961
+ import { dirname as dirname9, join as join11 } from "node:path";
5901
5962
  async function retainedRunPathsMatch(recordedPath, currentPath, currentRunDirectory) {
5902
5963
  if (recordedPath === currentPath) return true;
5903
5964
  if (typeof recordedPath !== "string") return false;
@@ -5908,8 +5969,8 @@ async function retainedRunPathsMatch(recordedPath, currentPath, currentRunDirect
5908
5969
  const runDirectory = physicalPathIdentity(currentRunDirectory);
5909
5970
  const identity = await readRoleRunIdentity(runDirectory);
5910
5971
  if (identity === void 0) return false;
5911
- for (let directory = runDirectory; dirname8(directory) !== directory; directory = dirname8(directory)) {
5912
- const ledgerHome = dirname8(dirname8(directory));
5972
+ for (let directory = runDirectory; dirname9(directory) !== directory; directory = dirname9(directory)) {
5973
+ const ledgerHome = dirname9(dirname9(directory));
5913
5974
  if (directory !== activationBookDirectory(ledgerHome, identity.bookKey)) continue;
5914
5975
  const unbound = roleRunPlacement(ledgerHome, {
5915
5976
  bookKey: identity.bookKey,
@@ -5942,14 +6003,14 @@ var init_role_run_relocation = __esm({
5942
6003
  import { spawnSync as spawnSync2 } from "node:child_process";
5943
6004
  import {
5944
6005
  appendFileSync as appendFileSync2,
5945
- existsSync as existsSync3,
6006
+ existsSync as existsSync4,
5946
6007
  mkdirSync as mkdirSync3,
5947
6008
  readFileSync as readFileSync3,
5948
6009
  readdirSync as readdirSync2,
5949
6010
  rmSync as rmSync3,
5950
6011
  writeFileSync as writeFileSync2
5951
6012
  } from "node:fs";
5952
- import { basename as basename7, dirname as dirname9, join as join11, relative as relative3, sep as sep4 } from "node:path";
6013
+ import { basename as basename7, dirname as dirname10, join as join12, relative as relative3, sep as sep4 } from "node:path";
5953
6014
  function parseProgressText(text, pathForDiagnostic) {
5954
6015
  if (text.trim() === "") return [];
5955
6016
  const { records, diagnostics } = parseSitianRecordText(text);
@@ -5969,20 +6030,20 @@ function parseProgressText(text, pathForDiagnostic) {
5969
6030
  return lines;
5970
6031
  }
5971
6032
  function readProgressFile(path) {
5972
- if (!existsSync3(path)) return [];
6033
+ if (!existsSync4(path)) return [];
5973
6034
  return parseProgressText(readFileSync3(path, "utf8"), path);
5974
6035
  }
5975
6036
  function readTicketProgressLines(subjectDirectory) {
5976
6037
  if (basename7(subjectDirectory) === "unbound") {
5977
- const runsDir = join11(subjectDirectory, "runs");
5978
- if (!existsSync3(runsDir)) return [];
6038
+ const runsDir = join12(subjectDirectory, "runs");
6039
+ if (!existsSync4(runsDir)) return [];
5979
6040
  const out = [];
5980
6041
  for (const name of readdirSync2(runsDir).sort()) {
5981
- out.push(...readProgressFile(join11(runsDir, name, LEG_PROGRESS_FILENAME)));
6042
+ out.push(...readProgressFile(join12(runsDir, name, LEG_PROGRESS_FILENAME)));
5982
6043
  }
5983
6044
  return out;
5984
6045
  }
5985
- return readProgressFile(join11(subjectDirectory, CURRENT_FILENAME));
6046
+ return readProgressFile(join12(subjectDirectory, CURRENT_FILENAME));
5986
6047
  }
5987
6048
  function roundBaseNumber(round) {
5988
6049
  if (round.trim() === "") return 0;
@@ -6005,8 +6066,8 @@ function nextRoundFromLines(lines, seat, lens) {
6005
6066
  return want === void 0 ? String(base) : `${base}.${want}`;
6006
6067
  }
6007
6068
  function nextLegReceiptIndex(runDirectory) {
6008
- const dir = join11(runDirectory, RECEIPTS_DIRNAME);
6009
- if (!existsSync3(dir)) return 1;
6069
+ const dir = join12(runDirectory, RECEIPTS_DIRNAME);
6070
+ if (!existsSync4(dir)) return 1;
6010
6071
  let max = 0;
6011
6072
  for (const name of readdirSync2(dir)) {
6012
6073
  const match = /^(\d+)\.json$/.exec(name);
@@ -6090,11 +6151,11 @@ function landTicketProgress(input) {
6090
6151
  const lens = input.lens === "completeness" || input.lens === "correctness" ? input.lens : lensFromRunDirectory(runDirectory, input.role);
6091
6152
  const leaf = basename7(runDirectory);
6092
6153
  const unbound = basename7(subjectDirectory) === "unbound";
6093
- const progressPath = unbound ? join11(runDirectory, LEG_PROGRESS_FILENAME) : join11(subjectDirectory, CURRENT_FILENAME);
6154
+ const progressPath = unbound ? join12(runDirectory, LEG_PROGRESS_FILENAME) : join12(subjectDirectory, CURRENT_FILENAME);
6094
6155
  const receiptIndex = nextLegReceiptIndex(runDirectory);
6095
6156
  const relativePath = `runs/${leaf}/${RECEIPTS_DIRNAME}/${receiptIndex}.json`;
6096
- const absolutePath = join11(subjectDirectory, relativePath);
6097
- mkdirSync3(dirname9(absolutePath), { recursive: true });
6157
+ const absolutePath = join12(subjectDirectory, relativePath);
6158
+ mkdirSync3(dirname10(absolutePath), { recursive: true });
6098
6159
  writeFileSync2(absolutePath, `${JSON.stringify(input.accepted, null, 2)}
6099
6160
  `, "utf8");
6100
6161
  if (!unbound) {
@@ -6116,7 +6177,7 @@ function landTicketProgress(input) {
6116
6177
  receipt: relativePath,
6117
6178
  session: sessionRelative
6118
6179
  };
6119
- mkdirSync3(dirname9(progressPath), { recursive: true });
6180
+ mkdirSync3(dirname10(progressPath), { recursive: true });
6120
6181
  appendFileSync2(progressPath, `${JSON.stringify(line2)}
6121
6182
  `, "utf8");
6122
6183
  if (input.sealHead.fault !== void 0) {
@@ -6129,10 +6190,10 @@ function relocateTicketProgressForLeg(input) {
6129
6190
  if (isUnboundRunDirectory(input.runDirectory)) return;
6130
6191
  const subjectDirectory = subjectDirectoryOfRun(input.runDirectory);
6131
6192
  if (subjectDirectory === void 0) return;
6132
- const stagedPath = join11(input.runDirectory, LEG_PROGRESS_FILENAME);
6193
+ const stagedPath = join12(input.runDirectory, LEG_PROGRESS_FILENAME);
6133
6194
  const mine = readProgressFile(stagedPath);
6134
6195
  if (mine.length === 0) {
6135
- if (existsSync3(stagedPath)) {
6196
+ if (existsSync4(stagedPath)) {
6136
6197
  rmSync3(stagedPath, { force: true });
6137
6198
  }
6138
6199
  return;
@@ -6157,8 +6218,8 @@ function relocateTicketProgressForLeg(input) {
6157
6218
  movedLines.push(moved);
6158
6219
  ticketLines.push(moved);
6159
6220
  }
6160
- const newCurrent = join11(subjectDirectory, CURRENT_FILENAME);
6161
- mkdirSync3(dirname9(newCurrent), { recursive: true });
6221
+ const newCurrent = join12(subjectDirectory, CURRENT_FILENAME);
6222
+ mkdirSync3(dirname10(newCurrent), { recursive: true });
6162
6223
  appendFileSync2(
6163
6224
  newCurrent,
6164
6225
  `${movedLines.map((line2) => JSON.stringify(line2)).join("\n")}
@@ -6233,7 +6294,7 @@ var init_git_object_id = __esm({
6233
6294
 
6234
6295
  // src/merger-git-state.ts
6235
6296
  import { execFile } from "node:child_process";
6236
- import { access, readFile as readFile6 } from "node:fs/promises";
6297
+ import { access, readFile as readFile7 } from "node:fs/promises";
6237
6298
  import { constants as fsConstants } from "node:fs";
6238
6299
  import { isAbsolute as isAbsolute3, resolve as resolve6 } from "node:path";
6239
6300
  import { promisify } from "node:util";
@@ -6303,7 +6364,7 @@ function createProductionMergerGitState(repositoryRoot = process.cwd()) {
6303
6364
  const mergeHeadPath = isAbsolute3(mergeHeadReported) ? mergeHeadReported : resolve6(repositoryRoot, mergeHeadReported);
6304
6365
  let sourceObjectId = "";
6305
6366
  if (await pathExists(mergeHeadPath)) {
6306
- const raw = exactUtf8(await readFile6(mergeHeadPath), "Git MERGE_HEAD");
6367
+ const raw = exactUtf8(await readFile7(mergeHeadPath), "Git MERGE_HEAD");
6307
6368
  const mergeHeads = raw.trim().split(/\r?\n/).map((row) => row.trim()).filter(Boolean);
6308
6369
  if (mergeHeads.length === 0) throw new Error("Git MERGE_HEAD is empty");
6309
6370
  if (mergeHeads.length !== 1) throw new Error("Assigned repository does not have one ordinary in-progress merge");
@@ -6446,14 +6507,14 @@ var init_session_dialogue = __esm({
6446
6507
  });
6447
6508
 
6448
6509
  // src/ticket-provenance.ts
6449
- import { readFile as readFile7 } from "node:fs/promises";
6450
- import { join as join12, resolve as resolve7 } from "node:path";
6510
+ import { readFile as readFile8 } from "node:fs/promises";
6511
+ import { join as join13, resolve as resolve7 } from "node:path";
6451
6512
  function dialogueSessionSourceRoots(home) {
6452
6513
  const machineHome = typeof home === "string" && home.trim() !== "" ? home : packageMachineHome();
6453
6514
  return [
6454
- join12(machineHome, ".claude", "projects"),
6455
- join12(machineHome, ".codex", "sessions"),
6456
- join12(machineHome, ".pi", "agent", "sessions")
6515
+ join13(machineHome, ".claude", "projects"),
6516
+ join13(machineHome, ".codex", "sessions"),
6517
+ join13(machineHome, ".pi", "agent", "sessions")
6457
6518
  ];
6458
6519
  }
6459
6520
  function isLedgerRoleSessionFile(absolute, home) {
@@ -6494,7 +6555,7 @@ async function rehomeUnboundTicketProvenance(runDirectory, ticketNumber, cwd, ho
6494
6555
  const ticketInput = ticketProvenanceRecordInput(ticketNumber, cwd, home);
6495
6556
  let history;
6496
6557
  try {
6497
- history = await readFile7(join12(runDirectory, RUN_HISTORY_FILE), "utf8");
6558
+ history = await readFile8(join13(runDirectory, RUN_HISTORY_FILE), "utf8");
6498
6559
  } catch (error) {
6499
6560
  if (errnoCode(error) === "ENOENT") return;
6500
6561
  throw error;
@@ -6686,7 +6747,7 @@ var init_ticket_provenance = __esm({
6686
6747
  });
6687
6748
 
6688
6749
  // src/notary-source-run.ts
6689
- import { dirname as dirname10, isAbsolute as isAbsolute4, join as join13, resolve as resolve8, basename as basename8 } from "node:path";
6750
+ import { dirname as dirname11, isAbsolute as isAbsolute4, join as join14, resolve as resolve8, basename as basename8 } from "node:path";
6690
6751
  import { lstat, realpath as realpath2 } from "node:fs/promises";
6691
6752
  async function readRetainedIdentity(runDirectory) {
6692
6753
  try {
@@ -6738,16 +6799,16 @@ async function resolveNotarySourceRunLocator(options) {
6738
6799
  const ledgerHome = resolveActivationLedgerHome(options.home);
6739
6800
  const bookKey = resolveBookKeyFromGit(options.projectRoot);
6740
6801
  const bookDirectory = activationBookDirectory(ledgerHome, bookKey);
6741
- const bookRunsRoot = join13(bookDirectory, "runs");
6802
+ const bookRunsRoot = join14(bookDirectory, "runs");
6742
6803
  let candidate;
6743
6804
  const bare = parseRunLeaf(raw);
6744
6805
  if (bare !== void 0 && !raw.includes("/") && !raw.includes("\\")) {
6745
- candidate = await findRunDirectoryById(options.home, bare.runId, bookKey, bare.role) ?? join13(bookRunsRoot, formatRunLeaf(bare.runId, bare.role));
6806
+ candidate = await findRunDirectoryById(options.home, bare.runId, bookKey, bare.role) ?? join14(bookRunsRoot, formatRunLeaf(bare.runId, bare.role));
6746
6807
  } else {
6747
6808
  candidate = isAbsolute4(raw) ? raw : resolve8(options.projectRoot, raw);
6748
6809
  const identity2 = parseRunLeaf(basename8(candidate));
6749
- const subjectDirectory = dirname10(dirname10(candidate));
6750
- const isLegacyUnboundLocator = identity2 !== void 0 && basename8(dirname10(candidate)) === "runs" && basename8(subjectDirectory) === "unbound" && resolve8(dirname10(subjectDirectory)) === resolve8(bookDirectory);
6810
+ const subjectDirectory = dirname11(dirname11(candidate));
6811
+ const isLegacyUnboundLocator = identity2 !== void 0 && basename8(dirname11(candidate)) === "runs" && basename8(subjectDirectory) === "unbound" && resolve8(dirname11(subjectDirectory)) === resolve8(bookDirectory);
6751
6812
  if (isLegacyUnboundLocator) {
6752
6813
  candidate = await resolveLiveRunDirectoryPath(candidate, options.home ?? ledgerHome, bookKey) ?? candidate;
6753
6814
  }
@@ -6755,9 +6816,9 @@ async function resolveNotarySourceRunLocator(options) {
6755
6816
  const real = await requireRunDirectory(candidate, raw);
6756
6817
  const identity = parseRunLeaf(basename8(real));
6757
6818
  const bookIdentity = physicalPathIdentity(bookDirectory);
6758
- const parentIdentity = physicalPathIdentity(dirname10(real));
6759
- const subjectBookIdentity = physicalPathIdentity(dirname10(dirname10(dirname10(real))));
6760
- if (parentIdentity !== physicalPathIdentity(bookRunsRoot) && !(basename8(dirname10(real)) === "runs" && subjectBookIdentity === bookIdentity)) {
6819
+ const parentIdentity = physicalPathIdentity(dirname11(real));
6820
+ const subjectBookIdentity = physicalPathIdentity(dirname11(dirname11(dirname11(real))));
6821
+ if (parentIdentity !== physicalPathIdentity(bookRunsRoot) && !(basename8(dirname11(real)) === "runs" && subjectBookIdentity === bookIdentity)) {
6761
6822
  throw new NotarySourceRunError(
6762
6823
  "notary --source-run must resolve to a retained run under the project machine-ledger book"
6763
6824
  );
@@ -7912,14 +7973,14 @@ var init_option_definitions = __esm({
7912
7973
 
7913
7974
  // src/public-cli/invocation.ts
7914
7975
  import { execFileSync as execFileSync2 } from "node:child_process";
7915
- import { existsSync as existsSync4 } from "node:fs";
7976
+ import { existsSync as existsSync5 } from "node:fs";
7916
7977
  import {
7917
- readFile as readFile8,
7978
+ readFile as readFile9,
7918
7979
  realpath as realpath3,
7919
7980
  rename,
7920
7981
  writeFile as writeFile2
7921
7982
  } from "node:fs/promises";
7922
- import { dirname as dirname11, isAbsolute as isAbsolute5, join as join14, resolve as resolve9 } from "node:path";
7983
+ import { dirname as dirname12, isAbsolute as isAbsolute5, join as join15, resolve as resolve9 } from "node:path";
7923
7984
  function admittedSourceRunPath(admitted) {
7924
7985
  if (!isRecord(admitted)) return void 0;
7925
7986
  const path = admitted.sourceRunPath;
@@ -8094,7 +8155,7 @@ async function relocateRegisteredChildDiarists(input) {
8094
8155
  runId: childRunId,
8095
8156
  role: "diarist"
8096
8157
  }).runDirectory;
8097
- if (existsSync4(unboundChildDirectory)) {
8158
+ if (existsSync5(unboundChildDirectory)) {
8098
8159
  input.authority.seal(childTarget);
8099
8160
  await bindTicketNumberOnRunDirectory(unboundChildDirectory, input.ticketNumber);
8100
8161
  await rehomeUnboundTicketProvenance(
@@ -8103,7 +8164,7 @@ async function relocateRegisteredChildDiarists(input) {
8103
8164
  input.projectRoot,
8104
8165
  homeFromRunDirectory(input.parentRunDirectory)
8105
8166
  );
8106
- ensureRoleRunDirectory(input.ledgerHome, dirname11(childTarget.runDirectory));
8167
+ ensureRoleRunDirectory(input.ledgerHome, dirname12(childTarget.runDirectory));
8107
8168
  await rename(unboundChildDirectory, childTarget.runDirectory);
8108
8169
  relocateTicketProgressForLeg({
8109
8170
  runDirectory: childTarget.runDirectory
@@ -8118,7 +8179,7 @@ async function relocateRegisteredChildDiarists(input) {
8118
8179
  }
8119
8180
  continue;
8120
8181
  }
8121
- if (existsSync4(childTarget.runDirectory)) {
8182
+ if (existsSync5(childTarget.runDirectory)) {
8122
8183
  relocateTicketProgressForLeg({
8123
8184
  runDirectory: childTarget.runDirectory
8124
8185
  });
@@ -8151,7 +8212,7 @@ async function relocateAdmittedRunToTicket(admitted, authority, heldLease) {
8151
8212
  runId: admitted.runId,
8152
8213
  role: admitted.role
8153
8214
  });
8154
- ensureRoleRunDirectory(ledgerHome, dirname11(target.runDirectory));
8215
+ ensureRoleRunDirectory(ledgerHome, dirname12(target.runDirectory));
8155
8216
  authority.seal(target);
8156
8217
  if (admitted.role !== "diarist") {
8157
8218
  await relocateRegisteredChildDiarists({
@@ -8216,7 +8277,7 @@ async function recordLaunchedPiIdentity(runDirectory, identity) {
8216
8277
  async function observeLaunchedRolePackageIdentity(packageRoot, selectedRoleEntry) {
8217
8278
  const rolePackageRoot = packageRoot;
8218
8279
  const raw = JSON.parse(
8219
- await readFile8(join14(rolePackageRoot, "package.json"), "utf8")
8280
+ await readFile9(join15(rolePackageRoot, "package.json"), "utf8")
8220
8281
  );
8221
8282
  if (typeof raw.version !== "string" || raw.version.trim() === "") {
8222
8283
  throw new Error(
@@ -8787,7 +8848,7 @@ async function admitPublicRole(role, parsed, env, override) {
8787
8848
  resolutionScope: [...derived.resolutionScope],
8788
8849
  authorizedChecks: []
8789
8850
  });
8790
- const mergerInputPath = join14(placed.runDirectory, "merger-input.json");
8851
+ const mergerInputPath = join15(placed.runDirectory, "merger-input.json");
8791
8852
  await writeFile2(
8792
8853
  mergerInputPath,
8793
8854
  `${JSON.stringify(mergerInput, null, 2)}
@@ -9055,7 +9116,7 @@ function parseDoctorIssueNumber(raw) {
9055
9116
  }
9056
9117
  async function resolveDoctorCaseRunsPath(options) {
9057
9118
  const ledgerHome = resolveActivationLedgerHome(options.home);
9058
- const defaultRuns = join14(
9119
+ const defaultRuns = join15(
9059
9120
  activationBookDirectory(ledgerHome, options.bookKey),
9060
9121
  String(options.issueNumber),
9061
9122
  "runs"
@@ -9377,9 +9438,9 @@ __export(run_lifecycle_exports, {
9377
9438
  resolveLiveRunDirectoryPath: () => resolveLiveRunDirectoryPath,
9378
9439
  writeRoleRunState: () => writeRoleRunState
9379
9440
  });
9380
- import { existsSync as existsSync5 } from "node:fs";
9381
- import { chmod, lstat as lstat2, open, readdir as readdir3, readFile as readFile9, unlink } from "node:fs/promises";
9382
- import { basename as basename9, join as join15 } from "node:path";
9441
+ import { existsSync as existsSync6 } from "node:fs";
9442
+ import { chmod, lstat as lstat2, open, readdir as readdir3, readFile as readFile10, unlink } from "node:fs/promises";
9443
+ import { basename as basename9, join as join16 } from "node:path";
9383
9444
  async function writeRoleRunState(runDirectory, record) {
9384
9445
  const payload = { ...record, runDirectory };
9385
9446
  writeSectionSync(runDirectory, "runState", { ...payload });
@@ -9615,7 +9676,7 @@ function isProcessAlive(pid) {
9615
9676
  async function autopsyWriterLock(lockPath) {
9616
9677
  let content;
9617
9678
  try {
9618
- content = await readFile9(lockPath, "utf8");
9679
+ content = await readFile10(lockPath, "utf8");
9619
9680
  } catch (error) {
9620
9681
  if (errorCodeOf(error) === "ENOENT") return { verdict: "absent" };
9621
9682
  return { verdict: "unknown", reason: "unreadable", readFailure: error };
@@ -9674,7 +9735,7 @@ async function createWriterLease(lockPath, runDirectory, reportCleanupFailure) {
9674
9735
  },
9675
9736
  relocate(nextRunDirectory) {
9676
9737
  currentRunDirectory = nextRunDirectory;
9677
- currentLockPath = join15(nextRunDirectory, WRITER_LOCK_FILE);
9738
+ currentLockPath = join16(nextRunDirectory, WRITER_LOCK_FILE);
9678
9739
  },
9679
9740
  async release() {
9680
9741
  if (released) return;
@@ -9713,10 +9774,10 @@ async function acquireRunWriterLease(runDirectory, onCleanupFailure) {
9713
9774
  };
9714
9775
  const reportReadFailure = (error) => {
9715
9776
  reportDiagnostic(
9716
- `writer lease lock read failed (holder liveness unverifiable; lock left in place) at ${join15(runDirectory, WRITER_LOCK_FILE)}: ${describeErrorIdentity(error)}`
9777
+ `writer lease lock read failed (holder liveness unverifiable; lock left in place) at ${join16(runDirectory, WRITER_LOCK_FILE)}: ${describeErrorIdentity(error)}`
9717
9778
  );
9718
9779
  };
9719
- const lockPath = join15(runDirectory, WRITER_LOCK_FILE);
9780
+ const lockPath = join16(runDirectory, WRITER_LOCK_FILE);
9720
9781
  let lastAutopsy = { verdict: "absent" };
9721
9782
  let lastReclaimFailure;
9722
9783
  for (let reclaimsLeft = WRITER_LEASE_RECLAIM_ROUNDS; ; reclaimsLeft -= 1) {
@@ -9782,7 +9843,7 @@ async function findRunDirectoryById(home, runId, onlyBookKey, onlyRole, knownRun
9782
9843
  }
9783
9844
  if (runId.trim() === "") return void 0;
9784
9845
  const ledgerHome = resolveActivationLedgerHome(home);
9785
- const booksRoot = join15(ledgerHome, "books");
9846
+ const booksRoot = join16(ledgerHome, "books");
9786
9847
  let bookKeys;
9787
9848
  try {
9788
9849
  bookKeys = await readdir3(booksRoot);
@@ -9797,7 +9858,7 @@ async function findRunDirectoryById(home, runId, onlyBookKey, onlyRole, knownRun
9797
9858
  );
9798
9859
  }
9799
9860
  async function resolveLiveRunDirectoryPath(recordedPath, home, onlyBookKey) {
9800
- if (existsSync5(recordedPath)) return recordedPath;
9861
+ if (existsSync6(recordedPath)) return recordedPath;
9801
9862
  const parsed = parseRunLeaf(basename9(recordedPath));
9802
9863
  const bookKey = onlyBookKey ?? tryBookKeyFromAkRolesPath(recordedPath);
9803
9864
  if (parsed === void 0 || bookKey === void 0) return void 0;
@@ -9832,7 +9893,7 @@ async function findLatestRunForSeatTicket(input) {
9832
9893
  let runDirectories;
9833
9894
  try {
9834
9895
  runDirectories = await listBookRunDirectories(
9835
- input.ticketNumber === void 0 ? bookDir : join15(bookDir, String(input.ticketNumber))
9896
+ input.ticketNumber === void 0 ? bookDir : join16(bookDir, String(input.ticketNumber))
9836
9897
  );
9837
9898
  } catch (error) {
9838
9899
  if (errorCodeOf(error) === "ENOENT") return void 0;
@@ -10348,7 +10409,7 @@ var init_run_lifecycle = __esm({
10348
10409
 
10349
10410
  // src/report-ticket-tool.ts
10350
10411
  import { Type as Type16 } from "typebox";
10351
- import { existsSync as existsSync6 } from "node:fs";
10412
+ import { existsSync as existsSync7 } from "node:fs";
10352
10413
  function pageString(page, key) {
10353
10414
  const value = page?.[key];
10354
10415
  return typeof value === "string" && value.trim() !== "" ? value : void 0;
@@ -10386,7 +10447,7 @@ async function reportTicketFromHostContext(context, ticketNumber, authority = pi
10386
10447
  if (runDirectory === void 0) {
10387
10448
  throw new Error("ak_report_ticket requires a per-turn run directory");
10388
10449
  }
10389
- if (!existsSync6(runDirectory)) {
10450
+ if (!existsSync7(runDirectory)) {
10390
10451
  throw new Error(`ak_report_ticket run directory missing: ${runDirectory}`);
10391
10452
  }
10392
10453
  const admitted = admittedForLiveTicketReport(runDirectory, authority);
@@ -10443,7 +10504,7 @@ function registerReportTicketTool(roleHost, hostActions) {
10443
10504
  }
10444
10505
  });
10445
10506
  }
10446
- var REPORT_TICKET_TOOL_NAME, reportTicketArgsSchema, REPORT_TICKET_TOOL_DESCRIPTION, MISSING_TICKET_REASK_MATERIAL;
10507
+ var REPORT_TICKET_TOOL_NAME, reportTicketArgsSchema, REPORT_TICKET_TOOL_DESCRIPTION;
10447
10508
  var init_report_ticket_tool = __esm({
10448
10509
  "src/report-ticket-tool.ts"() {
10449
10510
  "use strict";
@@ -10464,8 +10525,7 @@ var init_report_ticket_tool = __esm({
10464
10525
  },
10465
10526
  { additionalProperties: true }
10466
10527
  );
10467
- REPORT_TICKET_TOOL_DESCRIPTION = "\u5411\u5305\u7533\u62A5\u672C\u7968\u53F7\u3002\u5DF2\u77E5\u7968\u53F7\u65F6\u5F00\u5DE5\u7B2C\u4E00\u4EF6\u4E8B\u8C03\u7528\uFF1B\u5305\u5F53\u573A\u628A\u672C\u817F\u5F52\u5230\u7968\u53F7\u76EE\u5F55\u3002\u5C1A\u65E0\u7968\u53F7\uFF08\u4F8B\u5982\u4E2D\u4E66\u7701\u5EFA\u7968\u524D\uFF09\u4E0D\u8981\u8C03\u7528\uFF0C\u53D6\u5F97\u540E\u518D\u62A5\u3002\u4EA4\u5377\u65F6\u82E5\u4ECD\u672A\u62A5\u8FC7\u4E14\u4EA4\u5377\u4EA6\u672A\u5E26\u7968\u53F7\uFF0C\u5305\u4F1A\u7ECF\u65E2\u6709\u91CD\u4EA4\u901A\u9053\u518D\u95EE\u4E00\u6B21\u3002";
10468
- MISSING_TICKET_REASK_MATERIAL = "resources/missing-ticket-reask.md";
10528
+ REPORT_TICKET_TOOL_DESCRIPTION = "\u5411\u5305\u7533\u62A5\u672C\u7968\u53F7\u3002\u5DF2\u77E5\u7968\u53F7\u65F6\u5F00\u5DE5\u7B2C\u4E00\u4EF6\u4E8B\u8C03\u7528\uFF1B\u5305\u5F53\u573A\u628A\u672C\u817F\u5F52\u5230\u7968\u53F7\u76EE\u5F55\u3002\u5C1A\u65E0\u7968\u53F7\uFF08\u4F8B\u5982\u4E2D\u4E66\u7701\u5EFA\u7968\u524D\uFF09\u4E0D\u8981\u8C03\u7528\uFF0C\u53D6\u5F97\u540E\u518D\u62A5\u3002";
10469
10529
  }
10470
10530
  });
10471
10531
 
@@ -10837,6 +10897,17 @@ function createSubmissionLedgerHost(host, outputTools, failInfrastructure2 = (er
10837
10897
  sealHead,
10838
10898
  ...rawLens === "completeness" || rawLens === "correctness" ? { lens: rawLens } : {}
10839
10899
  });
10900
+ const runDirectory = runDirectoryFromHostContext(context);
10901
+ if (context.host !== "claude" && context.host !== "codex" && runDirectory !== void 0 && isUnboundRunDirectory(runDirectory)) {
10902
+ result = {
10903
+ ...result,
10904
+ terminate: false,
10905
+ content: [...result.content, {
10906
+ type: "text",
10907
+ text: (await readPackageMaterial("resources/ticket-at-receipt.md")).trim()
10908
+ }]
10909
+ };
10910
+ }
10840
10911
  } catch (error) {
10841
10912
  if (toolThrew) throw error;
10842
10913
  return failInfrastructure2(error, context, toolCallId);
@@ -10852,6 +10923,7 @@ var init_submission_ledger = __esm({
10852
10923
  "src/submission-ledger.ts"() {
10853
10924
  "use strict";
10854
10925
  init_role_run_placement();
10926
+ init_session_opening_materials();
10855
10927
  init_activation_ledger_topology();
10856
10928
  init_host_contracts();
10857
10929
  init_run_terminal_artifacts();
@@ -11047,7 +11119,7 @@ var init_engine_detour_usage = __esm({
11047
11119
  });
11048
11120
 
11049
11121
  // src/dossier-resolution.ts
11050
- import { existsSync as existsSync7, statSync as statSync4 } from "node:fs";
11122
+ import { existsSync as existsSync8, statSync as statSync4 } from "node:fs";
11051
11123
  import { resolve as resolve10 } from "node:path";
11052
11124
  function isHostContext(value) {
11053
11125
  return "sessionManager" in value;
@@ -11067,7 +11139,7 @@ function resolveAuditDossier(source) {
11067
11139
  }
11068
11140
  const runDirectory = resolve10(raw);
11069
11141
  try {
11070
- if (!existsSync7(runDirectory) || !statSync4(runDirectory).isDirectory()) {
11142
+ if (!existsSync8(runDirectory) || !statSync4(runDirectory).isDirectory()) {
11071
11143
  return { status: "incomplete", observation: { kind: "missing-dossier" } };
11072
11144
  }
11073
11145
  } catch {
@@ -12130,7 +12202,7 @@ var init_settlement = __esm({
12130
12202
  });
12131
12203
 
12132
12204
  // src/external-host-turn-loop.ts
12133
- import { existsSync as existsSync8 } from "node:fs";
12205
+ import { existsSync as existsSync9 } from "node:fs";
12134
12206
  import { basename as basename10 } from "node:path";
12135
12207
  async function syncTurnRequestLivePlacement(request, authority) {
12136
12208
  const live = await resolveLiveRunDirectoryPath(request.runDirectory, request.home);
@@ -12154,7 +12226,7 @@ async function trySyncTurnRequestLivePlacement(request, authority) {
12154
12226
  }
12155
12227
  async function retainPackageFaultBesideLivePlacement(request, input) {
12156
12228
  let runDirectory = request.runDirectory;
12157
- if (!existsSync8(runDirectory)) {
12229
+ if (!existsSync9(runDirectory)) {
12158
12230
  try {
12159
12231
  const found = await resolveLiveRunDirectoryPath(request.runDirectory, request.home);
12160
12232
  if (found === void 0) {
@@ -12339,7 +12411,7 @@ var init_external_host_turn_loop = __esm({
12339
12411
  });
12340
12412
 
12341
12413
  // src/session-identity.ts
12342
- import { join as join16 } from "node:path";
12414
+ import { join as join17 } from "node:path";
12343
12415
  function createSessionIdentityAuthority(authority, hostName) {
12344
12416
  const runDirectoryOf = (principal) => runDirectoryFromSessionDirectory(authority.decode(principal).sessionDirectory);
12345
12417
  return {
@@ -12349,7 +12421,7 @@ function createSessionIdentityAuthority(authority, hostName) {
12349
12421
  },
12350
12422
  async load(principal) {
12351
12423
  const runDirectory = runDirectoryOf(principal);
12352
- const { records, diagnostics } = await readSitianRecords(join16(runDirectory, RUN_STATE_FILE));
12424
+ const { records, diagnostics } = await readSitianRecords(join17(runDirectory, RUN_STATE_FILE));
12353
12425
  if (diagnostics.length > 0) {
12354
12426
  throw new Error(
12355
12427
  `${RUN_STATE_FILE} has ${diagnostics.length} malformed row(s); refusing stale session binding: ${runDirectory}`
@@ -12419,14 +12491,14 @@ __export(role_turn_host_exports, {
12419
12491
  });
12420
12492
  import { execFile as execFile2, spawn as spawn2 } from "node:child_process";
12421
12493
  import { constants } from "node:fs";
12422
- import { existsSync as existsSync9 } from "node:fs";
12494
+ import { existsSync as existsSync10 } from "node:fs";
12423
12495
  import { access as access2, appendFile, realpath as realpath4 } from "node:fs/promises";
12424
- import { delimiter, dirname as dirname12, isAbsolute as isAbsolute7, join as join17, resolve as resolve11 } from "node:path";
12496
+ import { delimiter, dirname as dirname13, isAbsolute as isAbsolute7, join as join18, resolve as resolve11 } from "node:path";
12425
12497
  import { platform } from "node:process";
12426
12498
  import { promisify as promisify2 } from "node:util";
12427
12499
  import { randomUUID as randomUUID4 } from "node:crypto";
12428
12500
  function resolveInternalRoleEntrypoint(packageRoot) {
12429
- return join17(packageRoot, INTERNAL_ROLE_ENTRYPOINT_RELATIVE2);
12501
+ return join18(packageRoot, INTERNAL_ROLE_ENTRYPOINT_RELATIVE2);
12430
12502
  }
12431
12503
  function buildExplicitInternalActivationArgs(selectedRoleEntry, extraArgs = []) {
12432
12504
  return ["--no-extensions", "-e", selectedRoleEntry, ...extraArgs];
@@ -12454,7 +12526,7 @@ function buildMethodArgs(methods) {
12454
12526
  const skillArgs = [];
12455
12527
  for (const method of methods) {
12456
12528
  if (method.kind === "skill") {
12457
- skillArgs.push("--skill", dirname12(method.path));
12529
+ skillArgs.push("--skill", dirname13(method.path));
12458
12530
  }
12459
12531
  }
12460
12532
  return skillArgs;
@@ -12616,7 +12688,7 @@ function createDefaultPiSpawnRunner(options) {
12616
12688
  homeFromRunDirectory(spawnDir)
12617
12689
  );
12618
12690
  } catch (resolveError) {
12619
- runDirectory = existsSync9(spawnDir) ? spawnDir : void 0;
12691
+ runDirectory = existsSync10(spawnDir) ? spawnDir : void 0;
12620
12692
  const resolveDiagnostic = `live run path resolve failed beside Pi transport fault: ${describeErrorIdentity(resolveError)}`;
12621
12693
  if (runDirectory !== void 0) {
12622
12694
  await retainPackageFault({
@@ -12906,15 +12978,15 @@ var init_navigator_lookup_host = __esm({
12906
12978
 
12907
12979
  // src/public-cli/host-providers.ts
12908
12980
  import { readFileSync as readFileSync4 } from "node:fs";
12909
- import { join as join18 } from "node:path";
12981
+ import { join as join19 } from "node:path";
12910
12982
  function hostProvidersPath(home) {
12911
12983
  if (typeof home !== "string" || home.trim() === "") {
12912
12984
  throw new Error("home must be explicitly provided");
12913
12985
  }
12914
- return join18(home, ".ak-roles", "host-providers.json");
12986
+ return join19(home, ".ak-roles", "host-providers.json");
12915
12987
  }
12916
12988
  function hermesProviderModelsCachePath(home) {
12917
- return join18(home, ".hermes", "provider_models_cache.json");
12989
+ return join19(home, ".hermes", "provider_models_cache.json");
12918
12990
  }
12919
12991
  function parseHostProvidersTable(value) {
12920
12992
  if (!isRecord(value)) {
@@ -13064,18 +13136,18 @@ var init_host_providers = __esm({
13064
13136
  });
13065
13137
 
13066
13138
  // src/public-cli/load-production-acp-host.ts
13067
- import { existsSync as existsSync10 } from "node:fs";
13068
- import { join as join19 } from "node:path";
13069
- import { pathToFileURL } from "node:url";
13139
+ import { existsSync as existsSync11 } from "node:fs";
13140
+ import { join as join20 } from "node:path";
13141
+ import { pathToFileURL as pathToFileURL2 } from "node:url";
13070
13142
  async function loadProductionAcpHostFactory(packageRoot, host) {
13071
13143
  const description = lookupHostDescription(host);
13072
13144
  if (description === void 0) {
13073
13145
  throw new Error(`unregistered host: ${host}`);
13074
13146
  }
13075
- const built = join19(packageRoot, "dist/acp-host/production-host.js");
13076
- const source = join19(packageRoot, "src/acp-host/production-host.ts");
13077
- const target = existsSync10(built) ? built : source;
13078
- const href = pathToFileURL(target).href;
13147
+ const built = join20(packageRoot, "dist/acp-host/production-host.js");
13148
+ const source = join20(packageRoot, "src/acp-host/production-host.ts");
13149
+ const target = existsSync11(built) ? built : source;
13150
+ const href = pathToFileURL2(target).href;
13079
13151
  const mod = await import(href);
13080
13152
  const create = mod.createProductionAcpRoleTurnHost;
13081
13153
  return (options) => create({ ...options, description, hostName: host });
@@ -13088,18 +13160,18 @@ var init_load_production_acp_host = __esm({
13088
13160
  });
13089
13161
 
13090
13162
  // src/public-cli/load-production-headless-host.ts
13091
- import { existsSync as existsSync11 } from "node:fs";
13092
- import { join as join20 } from "node:path";
13093
- import { pathToFileURL as pathToFileURL2 } from "node:url";
13163
+ import { existsSync as existsSync12 } from "node:fs";
13164
+ import { join as join21 } from "node:path";
13165
+ import { pathToFileURL as pathToFileURL3 } from "node:url";
13094
13166
  async function loadProductionHeadlessHostFactory(packageRoot, host) {
13095
13167
  const description = lookupHeadlessHostDescription(host);
13096
13168
  if (description === void 0) {
13097
13169
  throw new Error(`unregistered headless host: ${host}`);
13098
13170
  }
13099
- const built = join20(packageRoot, "dist/headless-host/production-host.js");
13100
- const source = join20(packageRoot, "src/headless-host/production-host.ts");
13101
- const target = existsSync11(built) ? built : source;
13102
- const href = pathToFileURL2(target).href;
13171
+ const built = join21(packageRoot, "dist/headless-host/production-host.js");
13172
+ const source = join21(packageRoot, "src/headless-host/production-host.ts");
13173
+ const target = existsSync12(built) ? built : source;
13174
+ const href = pathToFileURL3(target).href;
13103
13175
  const mod = await import(href);
13104
13176
  const create = mod.createProductionHeadlessRoleTurnHost;
13105
13177
  return (options) => create({ ...options, description, hostName: host });
@@ -13275,67 +13347,6 @@ var init_role_seat_runtime = __esm({
13275
13347
  }
13276
13348
  });
13277
13349
 
13278
- // src/session-opening-materials.ts
13279
- import { existsSync as existsSync12 } from "node:fs";
13280
- import { readFile as readFile10 } from "node:fs/promises";
13281
- import { dirname as dirname13, join as join21 } from "node:path";
13282
- import { fileURLToPath, pathToFileURL as pathToFileURL3 } from "node:url";
13283
- function resolvePackageRootDir(moduleUrl = import.meta.url) {
13284
- let dir = dirname13(fileURLToPath(moduleUrl));
13285
- for (let i = 0; i < 8; i += 1) {
13286
- if (existsSync12(join21(dir, "package.json")) && existsSync12(join21(dir, "souls"))) {
13287
- return dir;
13288
- }
13289
- const parent = dirname13(dir);
13290
- if (parent === dir) break;
13291
- dir = parent;
13292
- }
13293
- return fileURLToPath(new URL("..", moduleUrl));
13294
- }
13295
- async function readPackageMaterial(relativePath) {
13296
- return readFile10(fileURLToPath(new URL(relativePath, packageRootUrl)), "utf8");
13297
- }
13298
- async function joinPackageMaterials(relativePaths) {
13299
- const chunks = [];
13300
- for (const relativePath of relativePaths) chunks.push(await readPackageMaterial(relativePath));
13301
- return chunks.join("\n\n");
13302
- }
13303
- function roleSoulPath(role, materials) {
13304
- const suffix = `/souls/${role}.md`;
13305
- const path = materials.find((candidate) => `/${candidate}`.endsWith(suffix));
13306
- if (path === void 0) throw new Error(`session materials omit the ${role} Soul`);
13307
- return path;
13308
- }
13309
- async function loadSeparatedSessionPart(role, materials, part) {
13310
- const soul = roleSoulPath(role, materials);
13311
- return part === "soul" ? readPackageMaterial(soul) : joinPackageMaterials(materials.filter((path) => path !== soul));
13312
- }
13313
- function loadMainRoleSessionMaterials(role) {
13314
- return loadSeparatedSessionPart(role, MAIN_ROLE_SESSION_MATERIALS[role], "soul");
13315
- }
13316
- function loadMainRoleReferenceMaterials(role) {
13317
- return loadSeparatedSessionPart(role, MAIN_ROLE_SESSION_MATERIALS[role], "references");
13318
- }
13319
- var packageRootUrl, MAIN_ROLE_SESSION_MATERIALS, GATEKEEPER_SESSION_MATERIALS;
13320
- var init_session_opening_materials = __esm({
13321
- "src/session-opening-materials.ts"() {
13322
- "use strict";
13323
- init_packaged_role_registry();
13324
- packageRootUrl = pathToFileURL3(resolvePackageRootDir() + "/").href;
13325
- MAIN_ROLE_SESSION_MATERIALS = {
13326
- ...Object.fromEntries(
13327
- PUBLIC_ROLE_RECORDS.map((record) => [record.role, record.sessionMaterials])
13328
- )
13329
- };
13330
- GATEKEEPER_SESSION_MATERIALS = {
13331
- // #639: single authority — the public gatekeeper record owns the province list.
13332
- gatekeeper: packagedRoleSessionMaterials("gatekeeper"),
13333
- inspector: INSPECTOR_SESSION_MATERIALS,
13334
- notary: NOTARY_SESSION_MATERIALS
13335
- };
13336
- }
13337
- });
13338
-
13339
13350
  // src/doctor-auditor.ts
13340
13351
  function createPiDoctorAuditor() {
13341
13352
  return async (options) => {
@@ -14775,12 +14786,7 @@ async function dispatchPostAdmissionTurn(input) {
14775
14786
  }
14776
14787
  if (pendingSettlement !== void 0 && pendingTerminal !== void 0 && result.terminal === pendingTerminal) {
14777
14788
  try {
14778
- const softTicketReaskNoSeal = pendingSettlement !== "sealed" && env.softTicketReaskTurn === true;
14779
- const noSealScope = softTicketReaskNoSeal ? {
14780
- ...courtScope,
14781
- previewOnly: true,
14782
- recordAttemptHistory: true
14783
- } : { ...courtScope, recordAttemptHistory: true };
14789
+ const noSealScope = { ...courtScope, recordAttemptHistory: true };
14784
14790
  const terminal = pendingSettlement === "sealed" ? await adapters.trySettle(
14785
14791
  admitted,
14786
14792
  env.principalAuthority,
@@ -14797,9 +14803,6 @@ async function dispatchPostAdmissionTurn(input) {
14797
14803
  );
14798
14804
  if (terminal === void 0) throw new Error("settled host attempt vanished before publication");
14799
14805
  result = { ...result, terminal, exitCode: exitCodeForTerminalOutcome(terminal.roleOutcome) };
14800
- if (pendingSettlement === "sealed" && env.softTicketReaskTurn === true && env.softTicketReaskOwnership !== void 0) {
14801
- env.softTicketReaskOwnership.sealedSubstitute = true;
14802
- }
14803
14806
  if (pendingSettlement === "sealed" && terminal.roleOutcome.kind === "accepted" && request.courtAttemptId !== void 0 && request.courtAttemptId.length > 0) {
14804
14807
  try {
14805
14808
  await clearCurrentCourt(admitted.runDirectory, request.courtAttemptId);
@@ -15703,14 +15706,10 @@ function unreadablePostSubmissionStatus(admitted, terminal) {
15703
15706
  const status = receivedDiscriminator(payload, "status");
15704
15707
  return typeof status === "string" && route.statuses.has(status) ? void 0 : route.reask ?? officerConclusionReask(status);
15705
15708
  }
15706
- function withoutSoftTicketReaskTurn(env) {
15707
- const { softTicketReaskTurn: _softTicketReaskTurn, ...rest } = env;
15708
- return rest;
15709
- }
15710
15709
  function withUnreadableReask(env) {
15711
15710
  const spent = env.unreadableReasksSpent ?? 0;
15712
15711
  if (spent >= deliveryLimitFromConfig(env.autoResumeLimit)) return void 0;
15713
- return { ...withoutSoftTicketReaskTurn(env), unreadableReasksSpent: spent + 1 };
15712
+ return { ...env, unreadableReasksSpent: spent + 1 };
15714
15713
  }
15715
15714
  function isUnreadableReaskExhausted(value) {
15716
15715
  return value === UNREADABLE_REASK_EXHAUSTED;
@@ -15822,68 +15821,8 @@ async function reaskUnreadablePostSubmissionStatus(admitted, terminal, env, io,
15822
15821
  io
15823
15822
  );
15824
15823
  }
15825
- async function reaskMissingTicketOnce(admitted, terminal, env, io) {
15826
- if ((env.ticketReasksSpent ?? 0) >= 1) return { kind: "none" };
15827
- if (isNavigatorSeat(admitted.role)) return { kind: "none" };
15828
- if (admitted.ticketNumber !== void 0) return { kind: "none" };
15829
- if (!isUnboundRunDirectory(admitted.runDirectory)) return { kind: "none" };
15830
- if (terminal?.roleOutcome.kind !== "accepted" && terminal?.roleOutcome.kind !== "audit_escalation") {
15831
- return { kind: "none" };
15832
- }
15833
- const payloads = terminal.roleOutcome.payloads ?? [];
15834
- if (payloads.length === 0) return { kind: "none" };
15835
- const instruction = (await readPackageMaterial(MISSING_TICKET_REASK_MATERIAL)).trim();
15836
- const softTicketReaskOwnership = { sealedSubstitute: false };
15837
- const softReaskEnv = {
15838
- ...env,
15839
- ticketReasksSpent: 1,
15840
- softTicketReaskTurn: true,
15841
- softTicketReaskOwnership
15842
- };
15843
- const result = await runPublicInstructionSeatResume(
15844
- {
15845
- runId: admitted.runId,
15846
- runDirectory: admitted.runDirectory,
15847
- message: instruction,
15848
- summons: { instructionEmpty: true }
15849
- },
15850
- softReaskEnv,
15851
- io
15852
- );
15853
- if (softTicketReaskOwnership.sealedSubstitute || terminalCarriesSealedSubmission(result.terminal)) {
15854
- return { kind: "nested_owns", result };
15855
- }
15856
- return { kind: "no_substitute", result };
15857
- }
15858
15824
  function envForCourtContinue(env) {
15859
- return { ...withoutSoftTicketReaskTurn(env), unreadableReasksSpent: 0 };
15860
- }
15861
- function terminalCarriesSealedSubmission(terminal) {
15862
- const kind = terminal?.roleOutcome.kind;
15863
- if (kind !== "accepted" && kind !== "audit_escalation") return false;
15864
- return (terminal?.roleOutcome.payloads ?? []).length > 0;
15865
- }
15866
- function projectKeptOriginalArtifactsOntoLiveAdmitted(original, kept) {
15867
- const oldRunDirectory = original.admitted?.runDirectory;
15868
- const newRunDirectory = kept.admitted?.runDirectory;
15869
- if (oldRunDirectory === void 0 || newRunDirectory === void 0 || oldRunDirectory === newRunDirectory || kept.terminal === void 0) {
15870
- return;
15871
- }
15872
- for (const artifact of kept.terminal.artifacts) {
15873
- artifact.path = rewriteRunDirectoryPathValue(
15874
- artifact.path,
15875
- oldRunDirectory,
15876
- newRunDirectory
15877
- );
15878
- }
15879
- }
15880
- function mergeMissingTicketReaskKeepOriginal(original, ticketReask) {
15881
- if (ticketReask.exitCode !== 0) return ticketReask;
15882
- const admitted = ticketReask.admitted ?? original.admitted;
15883
- if (admitted === void 0) return { ...original };
15884
- const kept = { ...original, admitted };
15885
- projectKeptOriginalArtifactsOntoLiveAdmitted(original, kept);
15886
- return kept;
15825
+ return { ...env, unreadableReasksSpent: 0 };
15887
15826
  }
15888
15827
  async function continueAfterPostSubmissionGuards(result, admittedRole, env, io, held) {
15889
15828
  const live = result.admitted;
@@ -15897,30 +15836,18 @@ async function continueAfterPostSubmissionGuards(result, admittedRole, env, io,
15897
15836
  env,
15898
15837
  io
15899
15838
  );
15900
- let afterStatus = result;
15839
+ let continued = result;
15901
15840
  if (isUnreadableReaskExhausted(unreadableReask)) {
15902
15841
  const terminal = result.terminal === void 0 ? void 0 : withUnsettledDirection(result.terminal);
15903
- afterStatus = terminal === void 0 ? { ...result, admitted: live } : { ...result, admitted: live, terminal };
15842
+ continued = terminal === void 0 ? { ...result, admitted: live } : { ...result, admitted: live, terminal };
15904
15843
  } else if (unreadableReask !== void 0) {
15905
15844
  return unreadableReask;
15906
15845
  }
15907
- const forTicket = afterStatus.admitted ?? live;
15908
- const softReask = await reaskMissingTicketOnce(
15909
- forTicket,
15910
- afterStatus.terminal ?? result.terminal,
15911
- env,
15912
- io
15913
- );
15914
- if (softReask.kind === "nested_owns") {
15915
- return softReask.result;
15916
- }
15917
- const continued = softReask.kind === "none" ? afterStatus : mergeMissingTicketReaskKeepOriginal(afterStatus, softReask.result);
15918
15846
  const continuedAdmitted = continued.admitted ?? live;
15919
- const continuedEnv = softReask.kind !== "none" ? { ...env, ticketReasksSpent: 1 } : env;
15920
15847
  if (AUDITED_ROLES.has(admittedRole) && continued.terminal?.roleOutcome.kind === "accepted") {
15921
15848
  return auditSubmittedRole(
15922
15849
  { ...continued, admitted: continuedAdmitted },
15923
- continuedEnv,
15850
+ env,
15924
15851
  io
15925
15852
  );
15926
15853
  }
@@ -16796,7 +16723,6 @@ function officerSatisfiedByLiveChild(officer, resumedOfficer, passedReceipt, cha
16796
16723
  return childIndex >= 0 && officerIndex >= 0 && officerIndex < childIndex;
16797
16724
  }
16798
16725
  async function auditSubmittedRole(turn, env, io, resumedOfficer, passedReceipt) {
16799
- env = withoutSoftTicketReaskTurn(env);
16800
16726
  const admitted = turn.admitted;
16801
16727
  if (admitted === void 0 || !AUDITED_ROLES.has(admitted.role) || turn.terminal?.roleOutcome.kind !== "accepted") return turn;
16802
16728
  const accepted = turn.terminal.roleOutcome.payloads?.at(-1);
@@ -17083,10 +17009,7 @@ var AUDITED_ROLES, SECRETARIAT_STATUS_REASK, WORKER_ROUTING_STATUSES, WORKER_STA
17083
17009
  var init_instruction_seat_run = __esm({
17084
17010
  "src/public-cli/instruction-seat-run.ts"() {
17085
17011
  "use strict";
17086
- init_report_ticket_tool();
17087
17012
  init_role_run_placement();
17088
- init_role_run_relocation();
17089
- init_session_opening_materials();
17090
17013
  init_doctor_auditor();
17091
17014
  init_gatekeeper_role();
17092
17015
  init_submission_errors();