@akagilnc/pi-workflow-roles 0.1.5216 → 0.1.5241

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.
@@ -17672,10 +17672,10 @@ __export(session_assistant_usage_exports, {
17672
17672
  });
17673
17673
  import { join as join13 } from "node:path";
17674
17674
  async function readAssistantUsageFromSessionFile(sessionFile) {
17675
- const { readFile: readFile23 } = await import("node:fs/promises");
17675
+ const { readFile: readFile22 } = await import("node:fs/promises");
17676
17676
  let text;
17677
17677
  try {
17678
- text = await readFile23(sessionFile, "utf8");
17678
+ text = await readFile22(sessionFile, "utf8");
17679
17679
  } catch (error) {
17680
17680
  if (error?.code === "ENOENT") return void 0;
17681
17681
  throw error;
@@ -17879,57 +17879,15 @@ var init_sitian_contracts = __esm({
17879
17879
  });
17880
17880
 
17881
17881
  // src/sitian-appender.ts
17882
- import { createHash as createHash2, randomUUID } from "node:crypto";
17883
- import {
17884
- appendFileSync,
17885
- existsSync as existsSync3,
17886
- readFileSync as readFileSync2,
17887
- unlinkSync,
17888
- writeFileSync
17889
- } from "node:fs";
17882
+ import { randomUUID } from "node:crypto";
17883
+ import { appendFileSync } from "node:fs";
17890
17884
  import { dirname as dirname7, join as join14 } from "node:path";
17891
- function isRecord3(value) {
17892
- return typeof value === "object" && value !== null && !Array.isArray(value);
17893
- }
17894
- function errorCodeOf(error) {
17895
- return error.code;
17896
- }
17897
- function identityClaimPath(recordFile, identity) {
17898
- const digest = createHash2("sha256").update(identity, "utf8").digest("hex");
17899
- return `${recordFile}.id-${digest}`;
17900
- }
17901
- function createExclusiveFile(path, contents) {
17902
- writeFileSync(path, contents, { encoding: "utf8", flag: "wx" });
17903
- }
17904
- function sealTornTail(recordFile) {
17905
- if (!existsSync3(recordFile)) return;
17906
- const buffer = readFileSync2(recordFile);
17907
- if (buffer.length > 0 && buffer[buffer.length - 1] !== 10) {
17908
- appendFileSync(recordFile, "\n", "utf8");
17909
- }
17910
- }
17911
17885
  function appendSitianRecordBlock(input, block) {
17912
17886
  if (block === "") return;
17913
17887
  try {
17914
17888
  const { sessionDir, recordFile, ledgerHome } = resolveSitianRecordPath(input);
17915
17889
  ensureRealDirectoryTree(ledgerHome, sessionDir);
17916
- appendFileSync(recordFile, "", "utf8");
17917
- sealTornTail(recordFile);
17918
- const identityOf = (line2) => {
17919
- try {
17920
- const row = JSON.parse(line2);
17921
- return isRecord3(row) && typeof row.identity === "string" ? row.identity : void 0;
17922
- } catch {
17923
- return void 0;
17924
- }
17925
- };
17926
- const identities = new Set(readFileSync2(recordFile, "utf8").split("\n").map(identityOf).filter((id) => id !== void 0));
17927
- for (const line2 of block.match(/[^\n]*\n|[^\n]+$/g) ?? []) {
17928
- const identity = identityOf(line2);
17929
- if (identity !== void 0 && identities.has(identity)) continue;
17930
- appendFileSync(recordFile, line2, "utf8");
17931
- if (identity !== void 0) identities.add(identity);
17932
- }
17890
+ appendFileSync(recordFile, block, "utf8");
17933
17891
  } catch (error) {
17934
17892
  if (error instanceof SitianInfrastructureError) throw error;
17935
17893
  throw new SitianInfrastructureError(
@@ -17938,106 +17896,6 @@ function appendSitianRecordBlock(input, block) {
17938
17896
  );
17939
17897
  }
17940
17898
  }
17941
- function findIdentityPointer(recordFile, identity, kind, level) {
17942
- if (!existsSync3(recordFile)) return void 0;
17943
- const text = readFileSync2(recordFile, "utf8");
17944
- for (const line2 of text.split("\n")) {
17945
- const trimmed = line2.trim();
17946
- if (!trimmed) continue;
17947
- try {
17948
- const parsed = JSON.parse(trimmed);
17949
- if (isRecord3(parsed) && parsed.identity === identity) {
17950
- return { identity, recordFile, kind, level };
17951
- }
17952
- } catch {
17953
- }
17954
- }
17955
- return void 0;
17956
- }
17957
- function unlinkAbsentOk(path) {
17958
- try {
17959
- unlinkSync(path);
17960
- return void 0;
17961
- } catch (error) {
17962
- if (errorCodeOf(error) === "ENOENT") return void 0;
17963
- return error instanceof Error ? error : new Error(errorText(error));
17964
- }
17965
- }
17966
- function appendWithIdentityClaim(recordFile, record4, row) {
17967
- sealTornTail(recordFile);
17968
- const claimPath = identityClaimPath(recordFile, record4.identity);
17969
- const existing = findIdentityPointer(
17970
- recordFile,
17971
- record4.identity,
17972
- record4.kind,
17973
- record4.level
17974
- );
17975
- if (existing !== void 0) {
17976
- unlinkAbsentOk(claimPath);
17977
- return existing;
17978
- }
17979
- try {
17980
- createExclusiveFile(claimPath, "");
17981
- } catch (error) {
17982
- if (errorCodeOf(error) !== "EEXIST") throw error;
17983
- sealTornTail(recordFile);
17984
- const published = findIdentityPointer(
17985
- recordFile,
17986
- record4.identity,
17987
- record4.kind,
17988
- record4.level
17989
- );
17990
- if (published !== void 0) {
17991
- unlinkAbsentOk(claimPath);
17992
- return published;
17993
- }
17994
- throw new SitianInfrastructureError(
17995
- `Sitian identity claim at ${claimPath} already exists for identity ${record4.identity}`,
17996
- { cause: error }
17997
- );
17998
- }
17999
- let primaryFailure;
18000
- let result;
18001
- let cleanupFailure;
18002
- try {
18003
- sealTornTail(recordFile);
18004
- const raced = findIdentityPointer(
18005
- recordFile,
18006
- record4.identity,
18007
- record4.kind,
18008
- record4.level
18009
- );
18010
- if (raced !== void 0) {
18011
- result = raced;
18012
- } else {
18013
- appendFileSync(recordFile, row, "utf8");
18014
- result = {
18015
- identity: record4.identity,
18016
- recordFile,
18017
- kind: record4.kind,
18018
- level: record4.level
18019
- };
18020
- }
18021
- } catch (error) {
18022
- primaryFailure = error;
18023
- } finally {
18024
- cleanupFailure = unlinkAbsentOk(claimPath);
18025
- }
18026
- if (primaryFailure !== void 0) {
18027
- if (primaryFailure instanceof SitianInfrastructureError) throw primaryFailure;
18028
- throw new SitianInfrastructureError(
18029
- `Sitian appender persistence failure: ${errorText(primaryFailure)}`,
18030
- { cause: primaryFailure }
18031
- );
18032
- }
18033
- if (cleanupFailure !== void 0) {
18034
- throw new SitianInfrastructureError(
18035
- `Sitian identity claim at ${claimPath} could not be released after append for identity ${record4.identity}: ${errorText(cleanupFailure)}`,
18036
- { cause: cleanupFailure }
18037
- );
18038
- }
18039
- return result;
18040
- }
18041
17899
  function resolveSitianVolumeCategory(kind) {
18042
17900
  if (S4_SUBMISSION_LEDGER_KINDS.has(kind)) {
18043
17901
  return "submission-ledger";
@@ -18076,14 +17934,6 @@ function resolveSitianRecordPathInLedger(input, ledgerHome) {
18076
17934
  }
18077
17935
  return { sessionDir, recordFile, ledgerHome };
18078
17936
  }
18079
- function projectTicketRecordsPathShape() {
18080
- const { recordFile } = ticketProvenanceUnderBookPaths(
18081
- join14("~", ".ak-roles"),
18082
- "<\u7C3F>",
18083
- "<\u7968\u53F7>"
18084
- );
18085
- return recordFile.replace(/\\/g, "/");
18086
- }
18087
17937
  function resolveSitianRecordPath(input) {
18088
17938
  const ledgerHome = input.home !== void 0 && input.home.length > 0 ? resolveActivationLedgerHome(input.home) : resolveActivationLedgerHomeForPath(input.runDirectory ?? input.sessionParent);
18089
17939
  return resolveSitianRecordPathInLedger(input, ledgerHome);
@@ -18110,7 +17960,13 @@ function appendSitianRecord(input) {
18110
17960
  };
18111
17961
  const row = `${JSON.stringify(record4)}
18112
17962
  `;
18113
- return appendWithIdentityClaim(recordFile, record4, row);
17963
+ appendFileSync(recordFile, row, "utf8");
17964
+ return {
17965
+ identity: record4.identity,
17966
+ recordFile,
17967
+ kind: record4.kind,
17968
+ level: record4.level
17969
+ };
18114
17970
  } catch (error) {
18115
17971
  if (error instanceof SitianInfrastructureError) throw error;
18116
17972
  throw new SitianInfrastructureError(
@@ -18138,13 +17994,13 @@ var init_sitian_appender = __esm({
18138
17994
  });
18139
17995
 
18140
17996
  // src/sitian-reader.ts
18141
- import { existsSync as existsSync4 } from "node:fs";
17997
+ import { existsSync as existsSync3 } from "node:fs";
18142
17998
  import { readFile as readFile6 } from "node:fs/promises";
18143
- function isRecord4(value) {
17999
+ function isRecord3(value) {
18144
18000
  return typeof value === "object" && value !== null && !Array.isArray(value);
18145
18001
  }
18146
18002
  async function readSitianRecords(recordFile) {
18147
- if (!existsSync4(recordFile)) {
18003
+ if (!existsSync3(recordFile)) {
18148
18004
  return { records: [], diagnostics: [] };
18149
18005
  }
18150
18006
  const text = await readFile6(recordFile, "utf8");
@@ -18156,7 +18012,7 @@ async function readSitianRecords(recordFile) {
18156
18012
  if (!line2.trim()) continue;
18157
18013
  try {
18158
18014
  const parsed = JSON.parse(line2);
18159
- if (isRecord4(parsed)) {
18015
+ if (isRecord3(parsed)) {
18160
18016
  records.push(parsed);
18161
18017
  } else {
18162
18018
  const typeDesc = parsed === null ? "null" : Array.isArray(parsed) ? "array" : typeof parsed;
@@ -18416,19 +18272,7 @@ function createPiRoleTurnHost(config) {
18416
18272
  });
18417
18273
  return {
18418
18274
  async executeTurn(request) {
18419
- let turnRequest = request;
18420
- const officerStationChild = request.stationChild === true && isOfficerReviewSeat(request.activation.role);
18421
- const paths = !officerStationChild && request.hostTransition?.priorNativeKind === "sitian" ? request.hostTransition.priorNativePaths : void 0;
18422
- if (request.continuation.kind === "resume" && paths !== void 0 && paths.length > 0) {
18423
- turnRequest = {
18424
- ...request,
18425
- continuation: {
18426
- ...request.continuation,
18427
- prompt: `${request.continuation.prompt}
18428
- ${paths.join("\n")}`
18429
- }
18430
- };
18431
- }
18275
+ const turnRequest = request;
18432
18276
  const roleEntry = await realpath(resolveInternalRoleEntrypoint(config.packageRoot));
18433
18277
  const extraArgs = buildPiTurnExtraArgs(
18434
18278
  turnRequest,
@@ -18508,7 +18352,6 @@ var init_role_turn_host = __esm({
18508
18352
  "src/pi/role-turn-host.ts"() {
18509
18353
  "use strict";
18510
18354
  init_host_contracts();
18511
- init_packaged_role_registry();
18512
18355
  init_engine_detour();
18513
18356
  init_role_activation_flags();
18514
18357
  init_user_dialogue_stdin();
@@ -18527,9 +18370,9 @@ var init_role_turn_host = __esm({
18527
18370
  });
18528
18371
 
18529
18372
  // src/sha256.ts
18530
- import { createHash as createHash3 } from "node:crypto";
18373
+ import { createHash as createHash2 } from "node:crypto";
18531
18374
  function sha256Hex(bytes) {
18532
- return createHash3("sha256").update(bytes).digest("hex");
18375
+ return createHash2("sha256").update(bytes).digest("hex");
18533
18376
  }
18534
18377
  var init_sha256 = __esm({
18535
18378
  "src/sha256.ts"() {
@@ -19029,7 +18872,7 @@ var init_merger_git_state = __esm({
19029
18872
 
19030
18873
  // src/ledger-session-read.ts
19031
18874
  import { readFile as readFile10 } from "node:fs/promises";
19032
- function isRecord5(value) {
18875
+ function isRecord4(value) {
19033
18876
  return typeof value === "object" && value !== null && !Array.isArray(value);
19034
18877
  }
19035
18878
  async function readLedgerSessionJsonlLines(path) {
@@ -19054,7 +18897,7 @@ async function readLedgerSessionJsonlLines(path) {
19054
18897
  });
19055
18898
  continue;
19056
18899
  }
19057
- if (!isRecord5(row)) {
18900
+ if (!isRecord4(row)) {
19058
18901
  const kind = row === null ? "null" : Array.isArray(row) ? "array" : typeof row;
19059
18902
  out.push({
19060
18903
  line: lineNumber,
@@ -19107,7 +18950,7 @@ function extractSessionModelSequence(rows) {
19107
18950
  if (row.type === "model_change" && typeof row.modelId === "string") {
19108
18951
  push(row.modelId);
19109
18952
  }
19110
- const message = isRecord5(row.message) ? row.message : void 0;
18953
+ const message = isRecord4(row.message) ? row.message : void 0;
19111
18954
  if (message?.role === "assistant" && typeof message.model === "string") {
19112
18955
  push(message.model);
19113
18956
  }
@@ -19123,11 +18966,11 @@ function extractSessionToolIntervals(rows) {
19123
18966
  const openById = /* @__PURE__ */ new Map();
19124
18967
  for (const row of rows) {
19125
18968
  const rowTimestamp = typeof row.timestamp === "string" ? row.timestamp : void 0;
19126
- const message = isRecord5(row.message) ? row.message : void 0;
18969
+ const message = isRecord4(row.message) ? row.message : void 0;
19127
18970
  if (message?.role === "assistant" && Array.isArray(message.content)) {
19128
18971
  const callTimestamp = typeof message.timestamp === "string" && message.timestamp ? message.timestamp : rowTimestamp;
19129
18972
  for (const part of message.content) {
19130
- if (!isRecord5(part) || part.type !== "toolCall") continue;
18973
+ if (!isRecord4(part) || part.type !== "toolCall") continue;
19131
18974
  if (typeof part.id !== "string" || part.id.length === 0) {
19132
18975
  throw new Error("toolCall frame missing string id");
19133
18976
  }
@@ -19140,7 +18983,7 @@ function extractSessionToolIntervals(rows) {
19140
18983
  if (openById.has(part.id)) {
19141
18984
  throw new Error(`duplicate toolCall id ${part.id}`);
19142
18985
  }
19143
- const args = isRecord5(part.arguments) ? part.arguments : void 0;
18986
+ const args = isRecord4(part.arguments) ? part.arguments : void 0;
19144
18987
  const command = part.name === "bash" && args !== void 0 && typeof args.command === "string" ? bashCommandFirstLine(args.command) : void 0;
19145
18988
  const interval = {
19146
18989
  toolCallId: part.id,
@@ -19251,12 +19094,6 @@ function ticketProvenanceRecordInput(ticketNumber, cwd, home, runDirectory) {
19251
19094
  ...home === void 0 ? {} : { home }
19252
19095
  };
19253
19096
  }
19254
- function resolveTicketProvenanceVolume(ticketNumber, cwd, home) {
19255
- const path = resolveSitianRecordPath(
19256
- ticketProvenanceRecordInput(ticketNumber, cwd, home)
19257
- );
19258
- return { recordFile: path.recordFile, volumeDir: path.sessionDir };
19259
- }
19260
19097
  async function rehomeUnboundTicketProvenance(runDirectory, ticketNumber, cwd, home) {
19261
19098
  const source = join16(runDirectory, "records.jsonl");
19262
19099
  let content;
@@ -20488,7 +20325,7 @@ var init_option_definitions = __esm({
20488
20325
 
20489
20326
  // src/public-cli/invocation.ts
20490
20327
  import { execFileSync as execFileSync3 } from "node:child_process";
20491
- import { existsSync as existsSync5 } from "node:fs";
20328
+ import { existsSync as existsSync4 } from "node:fs";
20492
20329
  import {
20493
20330
  lstat as lstat4,
20494
20331
  mkdtemp,
@@ -20714,7 +20551,7 @@ async function relocateAdmittedRunToTicket(admitted, authority, heldLease) {
20714
20551
  for (const childRunId of Array.isArray(childRunIds) ? childRunIds : []) {
20715
20552
  if (typeof childRunId !== "string") continue;
20716
20553
  const childDirectory = join18(dirname12(oldRunDirectory), `${childRunId}@diarist`);
20717
- if (!existsSync5(childDirectory)) continue;
20554
+ if (!existsSync4(childDirectory)) continue;
20718
20555
  const childTarget = roleRunPlacement(ledgerHome, {
20719
20556
  bookKey: admitted.bookKey,
20720
20557
  subject: { ticketNumber: admitted.ticketNumber },
@@ -22176,7 +22013,7 @@ var init_invocation = __esm({
22176
22013
  });
22177
22014
 
22178
22015
  // src/public-cli/load-production-acp-host.ts
22179
- import { existsSync as existsSync6 } from "node:fs";
22016
+ import { existsSync as existsSync5 } from "node:fs";
22180
22017
  import { join as join19 } from "node:path";
22181
22018
  import { pathToFileURL } from "node:url";
22182
22019
  async function loadProductionAcpHostFactory(packageRoot2, host) {
@@ -22186,7 +22023,7 @@ async function loadProductionAcpHostFactory(packageRoot2, host) {
22186
22023
  }
22187
22024
  const built = join19(packageRoot2, "dist/acp-host/production-host.js");
22188
22025
  const source = join19(packageRoot2, "src/acp-host/production-host.ts");
22189
- const target = existsSync6(built) ? built : source;
22026
+ const target = existsSync5(built) ? built : source;
22190
22027
  const href = pathToFileURL(target).href;
22191
22028
  const mod = await import(href);
22192
22029
  const create = mod.createProductionAcpRoleTurnHost;
@@ -22200,7 +22037,7 @@ var init_load_production_acp_host = __esm({
22200
22037
  });
22201
22038
 
22202
22039
  // src/public-cli/load-production-headless-host.ts
22203
- import { existsSync as existsSync7 } from "node:fs";
22040
+ import { existsSync as existsSync6 } from "node:fs";
22204
22041
  import { join as join20 } from "node:path";
22205
22042
  import { pathToFileURL as pathToFileURL2 } from "node:url";
22206
22043
  async function loadProductionHeadlessHostFactory(packageRoot2, host) {
@@ -22210,7 +22047,7 @@ async function loadProductionHeadlessHostFactory(packageRoot2, host) {
22210
22047
  }
22211
22048
  const built = join20(packageRoot2, "dist/headless-host/production-host.js");
22212
22049
  const source = join20(packageRoot2, "src/headless-host/production-host.ts");
22213
- const target = existsSync7(built) ? built : source;
22050
+ const target = existsSync6(built) ? built : source;
22214
22051
  const href = pathToFileURL2(target).href;
22215
22052
  const mod = await import(href);
22216
22053
  const create = mod.createProductionHeadlessRoleTurnHost;
@@ -22337,7 +22174,7 @@ var init_role_turn_host_resolution = __esm({
22337
22174
  // src/analyst-gate-cycles-read.ts
22338
22175
  import { readdir as readdir4 } from "node:fs/promises";
22339
22176
  import { join as join21 } from "node:path";
22340
- function isRecord6(value) {
22177
+ function isRecord5(value) {
22341
22178
  return typeof value === "object" && value !== null && !Array.isArray(value);
22342
22179
  }
22343
22180
  function isParentAttemptBindingRow(row) {
@@ -22367,7 +22204,7 @@ function isGateTerminatingToolName(toolName) {
22367
22204
  function acceptedGateReceiptIds(rows) {
22368
22205
  const accepted = /* @__PURE__ */ new Set();
22369
22206
  for (const row of rows) {
22370
- const message = isRecord6(row.message) ? row.message : void 0;
22207
+ const message = isRecord5(row.message) ? row.message : void 0;
22371
22208
  if (message?.role !== "toolResult") continue;
22372
22209
  if (typeof message.toolCallId !== "string" || message.toolCallId.length === 0) continue;
22373
22210
  if (message.isError === false) accepted.add(message.toolCallId);
@@ -22402,7 +22239,7 @@ function nearestAttemptBindingBefore(rows, beforeIndex) {
22402
22239
  for (let i = beforeIndex - 1; i >= 0; i -= 1) {
22403
22240
  const row = rows[i];
22404
22241
  if (!isParentAttemptBindingRow(row)) continue;
22405
- if (!isRecord6(row.data) || !isRecord6(row.data.parent)) continue;
22242
+ if (!isRecord5(row.data) || !isRecord5(row.data.parent)) continue;
22406
22243
  const id = row.data.parent.attemptEntryId;
22407
22244
  const sessionFile = row.data.parent.sessionFile;
22408
22245
  return {
@@ -22417,10 +22254,10 @@ function extractAllAcceptedGateToolCalls(rows) {
22417
22254
  const out = [];
22418
22255
  for (let rowIndex = 0; rowIndex < rows.length; rowIndex += 1) {
22419
22256
  const row = rows[rowIndex];
22420
- const message = isRecord6(row.message) ? row.message : void 0;
22257
+ const message = isRecord5(row.message) ? row.message : void 0;
22421
22258
  if (message?.role !== "assistant" || !Array.isArray(message.content)) continue;
22422
22259
  for (const part of message.content) {
22423
- if (!isRecord6(part) || part.type !== "toolCall") continue;
22260
+ if (!isRecord5(part) || part.type !== "toolCall") continue;
22424
22261
  if (typeof part.id !== "string" || part.id.length === 0) continue;
22425
22262
  if (typeof part.name !== "string" || part.name.length === 0) continue;
22426
22263
  if (!isGateTerminatingToolName(part.name)) continue;
@@ -22428,7 +22265,7 @@ function extractAllAcceptedGateToolCalls(rows) {
22428
22265
  const binding = nearestAttemptBindingBefore(rows, rowIndex);
22429
22266
  out.push({
22430
22267
  toolName: part.name,
22431
- args: isRecord6(part.arguments) ? part.arguments : void 0,
22268
+ args: isRecord5(part.arguments) ? part.arguments : void 0,
22432
22269
  accepted: true,
22433
22270
  rowIndex,
22434
22271
  ...binding
@@ -22551,17 +22388,17 @@ function pairGateRounds(volumes) {
22551
22388
  return rounds.sort((a, b) => a.officerStartedAt.localeCompare(b.officerStartedAt)).map((round, index) => ({ ...round, roundIndex: index + 1 }));
22552
22389
  }
22553
22390
  async function resolveOfficerSessionFromPointerFile(pointerPath) {
22554
- const { readFile: readFile23 } = await import("node:fs/promises");
22391
+ const { readFile: readFile22 } = await import("node:fs/promises");
22555
22392
  let raw;
22556
22393
  try {
22557
- raw = JSON.parse(await readFile23(pointerPath, "utf8"));
22394
+ raw = JSON.parse(await readFile22(pointerPath, "utf8"));
22558
22395
  } catch (error) {
22559
22396
  throw new Error(
22560
22397
  `direct officer run pointer unreadable in ${pointerPath}: ${error instanceof Error ? error.message : String(error)}`,
22561
22398
  { cause: error }
22562
22399
  );
22563
22400
  }
22564
- if (!isRecord6(raw) || raw.kind !== "direct-officer-run-pointer" || raw.version !== 1) {
22401
+ if (!isRecord5(raw) || raw.kind !== "direct-officer-run-pointer" || raw.version !== 1) {
22565
22402
  throw new Error(`direct officer run pointer has unknown shape in ${pointerPath}`);
22566
22403
  }
22567
22404
  const sessionFile = raw.sessionFile;
@@ -22831,14 +22668,14 @@ var init_audit_escalation = __esm({
22831
22668
  });
22832
22669
 
22833
22670
  // src/session-opening-materials.ts
22834
- import { existsSync as existsSync8 } from "node:fs";
22671
+ import { existsSync as existsSync7 } from "node:fs";
22835
22672
  import { readFile as readFile13 } from "node:fs/promises";
22836
22673
  import { dirname as dirname13, join as join23 } from "node:path";
22837
22674
  import { fileURLToPath, pathToFileURL as pathToFileURL3 } from "node:url";
22838
22675
  function resolvePackageRootDir(moduleUrl = import.meta.url) {
22839
22676
  let dir = dirname13(fileURLToPath(moduleUrl));
22840
22677
  for (let i = 0; i < 8; i += 1) {
22841
- if (existsSync8(join23(dir, "package.json")) && existsSync8(join23(dir, "souls"))) {
22678
+ if (existsSync7(join23(dir, "package.json")) && existsSync7(join23(dir, "souls"))) {
22842
22679
  return dir;
22843
22680
  }
22844
22681
  const parent = dirname13(dir);
@@ -23045,13 +22882,13 @@ var init_serialize_thrown_value = __esm({
23045
22882
 
23046
22883
  // src/engine-detour-usage.ts
23047
22884
  import { randomUUID as randomUUID3 } from "node:crypto";
23048
- import { readFileSync as readFileSync3 } from "node:fs";
22885
+ import { readFileSync as readFileSync2 } from "node:fs";
23049
22886
  import { dirname as dirname14, join as join25 } from "node:path";
23050
- function isRecord7(value) {
22887
+ function isRecord6(value) {
23051
22888
  return typeof value === "object" && value !== null && !Array.isArray(value);
23052
22889
  }
23053
22890
  function callFactFromSitianPayload(payload, pointer) {
23054
- if (!isRecord7(payload)) return void 0;
22891
+ if (!isRecord6(payload)) return void 0;
23055
22892
  if (payload.tool !== ENGINE_DETOUR_TOOL_NAME) return void 0;
23056
22893
  if (typeof payload.toolCallId !== "string" || payload.toolCallId.length === 0) {
23057
22894
  return void 0;
@@ -23068,11 +22905,11 @@ function callFactFromSitianPayload(payload, pointer) {
23068
22905
  };
23069
22906
  }
23070
22907
  function invocationScopeIdOfRecord(record4) {
23071
- if (isRecord7(record4.subject)) {
22908
+ if (isRecord6(record4.subject)) {
23072
22909
  const fromSubject = record4.subject.invocationScopeId;
23073
22910
  if (typeof fromSubject === "string" && fromSubject.length > 0) return fromSubject;
23074
22911
  }
23075
- if (isRecord7(record4.payload)) {
22912
+ if (isRecord6(record4.payload)) {
23076
22913
  const fromPayload = record4.payload.invocationScopeId;
23077
22914
  if (typeof fromPayload === "string" && fromPayload.length > 0) return fromPayload;
23078
22915
  }
@@ -23088,7 +22925,7 @@ async function readEngineDetourToolUsage(input) {
23088
22925
  ...input.cwd === void 0 ? {} : { cwd: input.cwd }
23089
22926
  });
23090
22927
  const { records } = await readSitianRecords(recordFile);
23091
- const calls = [];
22928
+ const callsByToolCallId = /* @__PURE__ */ new Map();
23092
22929
  for (const record4 of records) {
23093
22930
  if (record4.kind !== ENGINE_DETOUR_CALL_KIND) continue;
23094
22931
  const boundScope = invocationScopeIdOfRecord(record4);
@@ -23105,8 +22942,9 @@ async function readEngineDetourToolUsage(input) {
23105
22942
  };
23106
22943
  const fact = callFactFromSitianPayload(record4.payload, pointer);
23107
22944
  if (fact === void 0) continue;
23108
- calls.push(fact);
22945
+ callsByToolCallId.set(fact.toolCallId, fact);
23109
22946
  }
22947
+ const calls = Array.from(callsByToolCallId.values());
23110
22948
  return { callCount: calls.length, calls };
23111
22949
  }
23112
22950
  function projectEngineDetourToolUsageForPublicTerminal(usage, options) {
@@ -23130,9 +22968,9 @@ function projectEngineDetourToolUsageForPublicTerminal(usage, options) {
23130
22968
  function readInvocationRecord(runDirectory) {
23131
22969
  try {
23132
22970
  const raw = JSON.parse(
23133
- readFileSync3(join25(runDirectory, "invocation.json"), "utf8")
22971
+ readFileSync2(join25(runDirectory, "invocation.json"), "utf8")
23134
22972
  );
23135
- return isRecord7(raw) ? raw : void 0;
22973
+ return isRecord6(raw) ? raw : void 0;
23136
22974
  } catch (error) {
23137
22975
  if (error?.code === "ENOENT") return void 0;
23138
22976
  throw error;
@@ -23143,14 +22981,9 @@ async function readInvocationEngineMounted(runDirectory) {
23143
22981
  if (raw === void 0) return false;
23144
22982
  return typeof raw.engine === "string" && raw.engine.trim() !== "";
23145
22983
  }
23146
- function readInvocationSelectedHost(runDirectory) {
23147
- const raw = readInvocationRecord(runDirectory);
23148
- if (raw === void 0) return void 0;
23149
- return typeof raw.host === "string" && raw.host.trim() !== "" ? raw.host.trim() : void 0;
23150
- }
23151
22984
  function withEngineDetourToolUsageFact(outcome, usage) {
23152
22985
  if (usage === void 0) return outcome;
23153
- const prior = isRecord7(outcome.decisiveFacts) ? outcome.decisiveFacts : {};
22986
+ const prior = isRecord6(outcome.decisiveFacts) ? outcome.decisiveFacts : {};
23154
22987
  return {
23155
22988
  ...outcome,
23156
22989
  decisiveFacts: {
@@ -23192,7 +23025,7 @@ var init_engine_detour_usage = __esm({
23192
23025
  });
23193
23026
 
23194
23027
  // src/dossier-resolution.ts
23195
- import { existsSync as existsSync9, statSync as statSync3 } from "node:fs";
23028
+ import { existsSync as existsSync8, statSync as statSync3 } from "node:fs";
23196
23029
  import { resolve as resolve10 } from "node:path";
23197
23030
  function isHostContext(value) {
23198
23031
  return "sessionManager" in value;
@@ -23212,7 +23045,7 @@ function resolveAuditDossier(source) {
23212
23045
  }
23213
23046
  const runDirectory = resolve10(raw);
23214
23047
  try {
23215
- if (!existsSync9(runDirectory) || !statSync3(runDirectory).isDirectory()) {
23048
+ if (!existsSync8(runDirectory) || !statSync3(runDirectory).isDirectory()) {
23216
23049
  return { status: "incomplete", observation: { kind: "missing-dossier" } };
23217
23050
  }
23218
23051
  } catch {
@@ -23220,13 +23053,13 @@ function resolveAuditDossier(source) {
23220
23053
  }
23221
23054
  return { status: "ok", runDirectory };
23222
23055
  }
23223
- function isRecord8(value) {
23056
+ function isRecord7(value) {
23224
23057
  return typeof value === "object" && value !== null && !Array.isArray(value);
23225
23058
  }
23226
23059
  function readDoctorAuditSubjects(context) {
23227
23060
  const entries = context.sessionManager.getEntries?.() ?? [];
23228
23061
  for (const entry of entries) {
23229
- if (isRecord8(entry) && entry.type === "custom" && entry.customType === DOCTOR_CANDIDATE_ENTRY_TYPE) {
23062
+ if (isRecord7(entry) && entry.type === "custom" && entry.customType === DOCTOR_CANDIDATE_ENTRY_TYPE) {
23230
23063
  return { status: "ok" };
23231
23064
  }
23232
23065
  }
@@ -23371,11 +23204,11 @@ var init_navigator_invocation_identity = __esm({
23371
23204
  });
23372
23205
 
23373
23206
  // src/receipt-delivery-policy.ts
23374
- function isRecord9(value) {
23207
+ function isRecord8(value) {
23375
23208
  return typeof value === "object" && value !== null && !Array.isArray(value);
23376
23209
  }
23377
23210
  function parseNoReceiptLifecycleFacts(input) {
23378
- if (!isRecord9(input) || typeof input.terminalToolCalled !== "boolean" || input.deliveryTurns !== RECEIPT_DELIVERY_TURN_LIMIT || input.sessionCompletion !== "settled-without-accepted-receipt" || input.acceptedReceipt !== false || typeof input.runPointer !== "string" || input.runPointer.trim() === "" || typeof input.attemptPointer !== "string" || input.attemptPointer.trim() === "" || !Array.isArray(input.rejectedReceipts) || !input.rejectedReceipts.every((item) => isRecord9(item) && typeof item.reason === "string")) {
23211
+ if (!isRecord8(input) || typeof input.terminalToolCalled !== "boolean" || input.deliveryTurns !== RECEIPT_DELIVERY_TURN_LIMIT || input.sessionCompletion !== "settled-without-accepted-receipt" || input.acceptedReceipt !== false || typeof input.runPointer !== "string" || input.runPointer.trim() === "" || typeof input.attemptPointer !== "string" || input.attemptPointer.trim() === "" || !Array.isArray(input.rejectedReceipts) || !input.rejectedReceipts.every((item) => isRecord8(item) && typeof item.reason === "string")) {
23379
23212
  throw new TypeError("malformed no-receipt lifecycle facts");
23380
23213
  }
23381
23214
  return {
@@ -23950,7 +23783,7 @@ async function readSitianRetainedAuditorProviderStop(sessionFile) {
23950
23783
  const { records } = await readSitianRecords(recordFile);
23951
23784
  for (let i = records.length - 1; i >= 0; i -= 1) {
23952
23785
  const payload = records[i]?.payload;
23953
- if (!isRecord10(payload) || !isRecord10(payload.response)) continue;
23786
+ if (!isRecord9(payload) || !isRecord9(payload.response)) continue;
23954
23787
  if (typeof payload.type === "string") continue;
23955
23788
  const stop = sessionProviderStopFromAssistant(payload.response);
23956
23789
  if (stop !== void 0) return stop;
@@ -24000,7 +23833,7 @@ async function loadBoundAuditorVolumes(sessionFile) {
24000
23833
  throw sessionReadFailure(error, "failed to read discovered auditor session");
24001
23834
  }
24002
23835
  const header = entries.find((entry) => entry.type === "session");
24003
- if (!isRecord10(header)) continue;
23836
+ if (!isRecord9(header)) continue;
24004
23837
  const bindingIndexes = [];
24005
23838
  for (let i = 0; i < entries.length; i += 1) {
24006
23839
  const entry = entries[i];
@@ -24014,7 +23847,7 @@ async function loadBoundAuditorVolumes(sessionFile) {
24014
23847
  end: idx + 1 < bindingIndexes.length ? bindingIndexes[idx + 1] : entries.length
24015
23848
  })) : [{ entry: void 0, start: 0, end: entries.length }];
24016
23849
  for (const { entry: bindingEntry, start, end } of bindingPasses) {
24017
- const bindingParent = bindingEntry !== void 0 && isRecord10(bindingEntry.data) && isRecord10(bindingEntry.data.parent) ? bindingEntry.data.parent : void 0;
23850
+ const bindingParent = bindingEntry !== void 0 && isRecord9(bindingEntry.data) && isRecord9(bindingEntry.data.parent) ? bindingEntry.data.parent : void 0;
24018
23851
  const attemptEntryId = typeof bindingParent?.attemptEntryId === "string" ? bindingParent.attemptEntryId : void 0;
24019
23852
  const boundSessionFile = typeof bindingParent?.sessionFile === "string" ? bindingParent.sessionFile : typeof header.parentSession === "string" ? header.parentSession : void 0;
24020
23853
  if (boundSessionFile !== sessionFile) continue;
@@ -24038,12 +23871,12 @@ function complianceFailureFromAuditorVolumes(volumes) {
24038
23871
  if (stop === void 0) continue;
24039
23872
  for (let i = entries.length - 1; i >= 0; i -= 1) {
24040
23873
  const entry = entries[i];
24041
- if (entry?.type !== "custom" || entry.customType !== AUDITOR_COMPLIANCE_FAILURE_ENTRY_TYPE || !isRecord10(entry.data)) continue;
24042
- const parent = isRecord10(entry.data.parent) ? entry.data.parent : void 0;
24043
- const failure = isRecord10(entry.data.failure) ? entry.data.failure : void 0;
23874
+ if (entry?.type !== "custom" || entry.customType !== AUDITOR_COMPLIANCE_FAILURE_ENTRY_TYPE || !isRecord9(entry.data)) continue;
23875
+ const parent = isRecord9(entry.data.parent) ? entry.data.parent : void 0;
23876
+ const failure = isRecord9(entry.data.failure) ? entry.data.failure : void 0;
24044
23877
  if (parent?.sessionId !== parentId || parent.sessionFile !== sessionFile || parent.attemptEntryId !== attemptEntryId) continue;
24045
23878
  if (failure === void 0) continue;
24046
- const identity = isRecord10(failure.identity) ? failure.identity : void 0;
23879
+ const identity = isRecord9(failure.identity) ? failure.identity : void 0;
24047
23880
  const typedCause = failure.cause === "provider" || failure.cause === "activation" || failure.cause === "session" || failure.cause === "output" || failure.cause === "timeout" ? failure.cause : void 0;
24048
23881
  return {
24049
23882
  ...typedCause === void 0 ? {} : { cause: typedCause },
@@ -24052,7 +23885,7 @@ function complianceFailureFromAuditorVolumes(volumes) {
24052
23885
  ...typeof identity.code === "string" || typeof identity.code === "number" ? { code: identity.code } : {}
24053
23886
  } },
24054
23887
  ...typeof failure.diagnostic === "string" ? { diagnostic: failure.diagnostic } : {},
24055
- ...isRecord10(failure.details) ? { details: failure.details } : {}
23888
+ ...isRecord9(failure.details) ? { details: failure.details } : {}
24056
23889
  };
24057
23890
  }
24058
23891
  }
@@ -24099,9 +23932,9 @@ function typedFailedTerminatingToolKnownFailure(entries) {
24099
23932
  if (classification.kind !== "infrastructure") continue;
24100
23933
  if (typeof message.toolCallId !== "string" || typeof message.toolName !== "string") continue;
24101
23934
  if (boundRoleToolCallForResult(attemptEntries, i, message, message.toolName) === void 0) continue;
24102
- const textPart = Array.isArray(message.content) ? message.content.find((part) => isRecord10(part) && part.type === "text" && typeof part.text === "string") : void 0;
24103
- const diagnostic = isRecord10(textPart) ? textPart.text : void 0;
24104
- const details = isRecord10(message.details) ? message.details : classification.fact;
23935
+ const textPart = Array.isArray(message.content) ? message.content.find((part) => isRecord9(part) && part.type === "text" && typeof part.text === "string") : void 0;
23936
+ const diagnostic = isRecord9(textPart) ? textPart.text : void 0;
23937
+ const details = isRecord9(message.details) ? message.details : classification.fact;
24105
23938
  return {
24106
23939
  cause: "activation",
24107
23940
  identity: { name: message.toolName, code: message.toolCallId },
@@ -24238,7 +24071,7 @@ function controlledFailureInputFromResolution(resolution) {
24238
24071
  } : {}
24239
24072
  };
24240
24073
  }
24241
- function isRecord10(value) {
24074
+ function isRecord9(value) {
24242
24075
  return typeof value === "object" && value !== null && !Array.isArray(value);
24243
24076
  }
24244
24077
  function toolResultText(message) {
@@ -24263,7 +24096,7 @@ function extractCollectorTargetBindRejection(entries) {
24263
24096
  const diagnostic = toolResultText(message);
24264
24097
  if (diagnostic.length === 0) return void 0;
24265
24098
  const details = message.details;
24266
- const code = isRecord10(details) && typeof details.code === "string" && details.code.trim() !== "" ? details.code : void 0;
24099
+ const code = isRecord9(details) && typeof details.code === "string" && details.code.trim() !== "" ? details.code : void 0;
24267
24100
  return code === void 0 ? { diagnostic } : { diagnostic, code };
24268
24101
  }
24269
24102
  return void 0;
@@ -24364,7 +24197,7 @@ function boundRoleToolCallForResult(entries, resultIndex, message, outputToolNam
24364
24197
  const candidateMessage = entries[index]?.message;
24365
24198
  if (candidateMessage?.role === "assistant" && Array.isArray(candidateMessage.content)) {
24366
24199
  for (const part of candidateMessage.content) {
24367
- if (!isRecord10(part) || part.type !== "toolCall" || part.id !== callId) {
24200
+ if (!isRecord9(part) || part.type !== "toolCall" || part.id !== callId) {
24368
24201
  continue;
24369
24202
  }
24370
24203
  if (part.name !== outputToolName) return void 0;
@@ -24435,7 +24268,7 @@ function parseNavigatorAttendanceDetails(details) {
24435
24268
  if (typeof details.prose === "string" && details.prose.trim() !== "") {
24436
24269
  prose = details.prose;
24437
24270
  } else {
24438
- const next = isRecord10(details.next) && typeof details.next.role === "string" ? details.next.role : void 0;
24271
+ const next = isRecord9(details.next) && typeof details.next.role === "string" ? details.next.role : void 0;
24439
24272
  const reason = typeof details.reason === "string" && details.reason.trim() !== "" ? details.reason : void 0;
24440
24273
  const command = typeof details.command === "string" && details.command.trim() !== "" ? details.command : void 0;
24441
24274
  if (reason !== void 0 && next !== void 0) {
@@ -24544,7 +24377,7 @@ function detourGateContext(admitted, scope) {
24544
24377
  }
24545
24378
  async function withOptionalGateProjection(base, sessionDirectory, gateContext = {}) {
24546
24379
  const secondaryEvidence = base.roleOutcome.kind === "failure" ? base.roleOutcome.decisiveFacts.secondaryEvidence : void 0;
24547
- const skipGate = isRecord10(secondaryEvidence) && secondaryEvidence.kind === "role_infrastructure_failure" && packagedSkipsGateOnInfrastructureStage(secondaryEvidence.stage);
24380
+ const skipGate = isRecord9(secondaryEvidence) && secondaryEvidence.kind === "role_infrastructure_failure" && packagedSkipsGateOnInfrastructureStage(secondaryEvidence.stage);
24548
24381
  let next = base;
24549
24382
  if (!skipGate) {
24550
24383
  const gate = await extractGateFactFromSessionDirectory(sessionDirectory, gateContext);
@@ -24557,7 +24390,7 @@ function routePlaybookFailureMessage(entries) {
24557
24390
  const entry = entries[i];
24558
24391
  if (entry?.type !== "custom" || entry.customType !== NAVIGATOR_ROUTE_PLAYBOOK_FAILURE_ENTRY) continue;
24559
24392
  const data = entry.data;
24560
- if (!isRecord10(data) || typeof data.message !== "string" || data.message.trim() === "") return void 0;
24393
+ if (!isRecord9(data) || typeof data.message !== "string" || data.message.trim() === "") return void 0;
24561
24394
  return data.message;
24562
24395
  }
24563
24396
  return void 0;
@@ -24604,7 +24437,7 @@ function extractNavigatorAttendanceFact(entries) {
24604
24437
  const entry = entries[i];
24605
24438
  if (entry?.type === "custom_message" && entry.customType === "ak-navigator-attendance") {
24606
24439
  const details = entry.message?.details ?? entry.details;
24607
- if (!isRecord10(details)) {
24440
+ if (!isRecord9(details)) {
24608
24441
  return {
24609
24442
  disposition: "unavailable",
24610
24443
  source: "unknown",
@@ -24755,7 +24588,7 @@ async function settleSealedAcceptedOrToolResidual(admitted, authority, scope, ro
24755
24588
  const residual = boundErroredToolCandidate(entries, index, message, residualToolName);
24756
24589
  if (residual === void 0) continue;
24757
24590
  const candidate = residual.candidate;
24758
- const details = isRecord10(candidate) ? candidate : { candidate };
24591
+ const details = isRecord9(candidate) ? candidate : { candidate };
24759
24592
  const failed = await settleFailureTerminalResult(
24760
24593
  admitted,
24761
24594
  {
@@ -24830,7 +24663,7 @@ function extractDoctorCandidateFacts(entries) {
24830
24663
  continue;
24831
24664
  }
24832
24665
  const data = entry.data;
24833
- if (!isRecord10(data)) return {};
24666
+ if (!isRecord9(data)) return {};
24834
24667
  return {
24835
24668
  ...data.cost === void 0 ? {} : { cost: data.cost },
24836
24669
  ...data.auditNoReceipt === void 0 ? {} : { auditNoReceipt: data.auditNoReceipt }
@@ -24915,7 +24748,7 @@ async function settleLawfulSeatAcceptedTerminalResult(admitted, authority, spec,
24915
24748
  let residual;
24916
24749
  for (let index = entries.length - 1; index >= scanStart; index -= 1) {
24917
24750
  const entry = entries[index];
24918
- if (entry?.type === "custom" && entry.customType === "ak-role-submission-closure" && isRecord10(entry.data) && entry.data.toolName === spec.toolName && classifyPackagedRoleTerminalResult(entry.data).kind === "accepted") {
24751
+ if (entry?.type === "custom" && entry.customType === "ak-role-submission-closure" && isRecord9(entry.data) && entry.data.toolName === spec.toolName && classifyPackagedRoleTerminalResult(entry.data).kind === "accepted") {
24919
24752
  thisAttemptHasSeatSuccess = true;
24920
24753
  }
24921
24754
  const message = entries[index]?.message;
@@ -24955,7 +24788,7 @@ async function settleLawfulSeatAcceptedTerminalResult(admitted, authority, spec,
24955
24788
  );
24956
24789
  }
24957
24790
  if (residual !== void 0) {
24958
- const details = isRecord10(residual.candidate) ? residual.candidate : { candidate: residual.candidate };
24791
+ const details = isRecord9(residual.candidate) ? residual.candidate : { candidate: residual.candidate };
24959
24792
  const failed = await settleFailureTerminalResult(
24960
24793
  admitted,
24961
24794
  {
@@ -25005,7 +24838,7 @@ function countersignTerminalFromEntries(entries) {
25005
24838
  return void 0;
25006
24839
  }
25007
24840
  function withCountersignTerminalFact(roleOutcome, officer) {
25008
- const prior = roleOutcome.decisiveFacts !== void 0 && isRecord10(roleOutcome.decisiveFacts) ? roleOutcome.decisiveFacts : {};
24841
+ const prior = roleOutcome.decisiveFacts !== void 0 && isRecord9(roleOutcome.decisiveFacts) ? roleOutcome.decisiveFacts : {};
25009
24842
  return {
25010
24843
  ...roleOutcome,
25011
24844
  decisiveFacts: {
@@ -25018,7 +24851,7 @@ function acceptedSecretariatDefinesOfficerProjection(roleOutcome) {
25018
24851
  const payloads = roleOutcome.payloads ?? [];
25019
24852
  for (let index = payloads.length - 1; index >= 0; index -= 1) {
25020
24853
  const payload = payloads[index];
25021
- if (!isRecord10(payload)) continue;
24854
+ if (!isRecord9(payload)) continue;
25022
24855
  const status = payload.secretariatStatus;
25023
24856
  if (typeof status !== "string") continue;
25024
24857
  return status === "converged";
@@ -25463,7 +25296,7 @@ var init_settlement = __esm({
25463
25296
  });
25464
25297
 
25465
25298
  // src/archivist-record-pointer.ts
25466
- import { mkdirSync as mkdirSync3, writeFileSync as writeFileSync2 } from "node:fs";
25299
+ import { mkdirSync as mkdirSync3, writeFileSync } from "node:fs";
25467
25300
  import { dirname as dirname16, join as join27 } from "node:path";
25468
25301
  function bookDirectOfficerRunPointer(options) {
25469
25302
  const nest = join27(dirname16(options.parentSessionFile), "auditor-roles");
@@ -25475,7 +25308,7 @@ function bookDirectOfficerRunPointer(options) {
25475
25308
  sessionFile: options.sessionFile,
25476
25309
  ...options.runDirectory !== void 0 && options.runDirectory.trim() !== "" ? { runDirectory: options.runDirectory } : {}
25477
25310
  };
25478
- writeFileSync2(
25311
+ writeFileSync(
25479
25312
  join27(nest, `${options.officer}.pointer.json`),
25480
25313
  `${JSON.stringify(pointer)}
25481
25314
  `,
@@ -25818,11 +25651,11 @@ var init_turn_request = __esm({
25818
25651
  });
25819
25652
 
25820
25653
  // src/public-cli/countersign-run.ts
25821
- function isRecord11(value) {
25654
+ function isRecord10(value) {
25822
25655
  return typeof value === "object" && value !== null && !Array.isArray(value);
25823
25656
  }
25824
25657
  function isEscalatePayload(payload) {
25825
- if (!isRecord11(payload)) return false;
25658
+ if (!isRecord10(payload)) return false;
25826
25659
  return payload.status === "escalate";
25827
25660
  }
25828
25661
  function courtDiaristPayloadRows(roleOutcome, submissions) {
@@ -27046,7 +26879,7 @@ __export(public_role_summons_exports, {
27046
26879
  summonPublicRole: () => summonPublicRole
27047
26880
  });
27048
26881
  import { execFile as execFile3 } from "node:child_process";
27049
- import { existsSync as existsSync10 } from "node:fs";
26882
+ import { existsSync as existsSync9 } from "node:fs";
27050
26883
  import { realpath as realpath5 } from "node:fs/promises";
27051
26884
  import { join as join28 } from "node:path";
27052
26885
  import { promisify as promisify3 } from "node:util";
@@ -27072,7 +26905,7 @@ function parentDir(path) {
27072
26905
  function walkPackageRoot(start) {
27073
26906
  let dir = start;
27074
26907
  for (let i = 0; i < 12; i += 1) {
27075
- if (existsSync10(join28(dir, "package.json")) && existsSync10(join28(dir, "souls"))) {
26908
+ if (existsSync9(join28(dir, "package.json")) && existsSync9(join28(dir, "souls"))) {
27076
26909
  return dir;
27077
26910
  }
27078
26911
  const parent = parentDir(dir);
@@ -27897,7 +27730,7 @@ async function readRoleRunStateRaw(runDirectory) {
27897
27730
  try {
27898
27731
  raw = JSON.parse(await readFile16(join30(runDirectory, RUN_STATE_FILE), "utf8"));
27899
27732
  } catch (error) {
27900
- if (errorCodeOf2(error) === "ENOENT") return void 0;
27733
+ if (errorCodeOf(error) === "ENOENT") return void 0;
27901
27734
  throw error;
27902
27735
  }
27903
27736
  return raw;
@@ -28142,7 +27975,7 @@ function describeErrorIdentity(error) {
28142
27975
  const message = typeof candidate?.message === "string" && candidate.message !== "" ? `: ${candidate.message}` : "";
28143
27976
  return `${name}${code}${message}`;
28144
27977
  }
28145
- function errorCodeOf2(error) {
27978
+ function errorCodeOf(error) {
28146
27979
  return error.code;
28147
27980
  }
28148
27981
  function isProcessAlive(pid) {
@@ -28150,7 +27983,7 @@ function isProcessAlive(pid) {
28150
27983
  process.kill(pid, 0);
28151
27984
  return true;
28152
27985
  } catch (error) {
28153
- return errorCodeOf2(error) !== "ESRCH";
27986
+ return errorCodeOf(error) !== "ESRCH";
28154
27987
  }
28155
27988
  }
28156
27989
  async function autopsyWriterLock(lockPath) {
@@ -28158,7 +27991,7 @@ async function autopsyWriterLock(lockPath) {
28158
27991
  try {
28159
27992
  content = await readFile16(lockPath, "utf8");
28160
27993
  } catch (error) {
28161
- if (errorCodeOf2(error) === "ENOENT") return { verdict: "absent" };
27994
+ if (errorCodeOf(error) === "ENOENT") return { verdict: "absent" };
28162
27995
  return { verdict: "unknown", reason: "unreadable", readFailure: error };
28163
27996
  }
28164
27997
  const normalized = content.trim();
@@ -28190,8 +28023,8 @@ async function reclaimStaleWriterLock(lockPath, runDirectory) {
28190
28023
  await unlink4(lockPath);
28191
28024
  return { reclaimed: true };
28192
28025
  } catch (error) {
28193
- if (errorCodeOf2(error) === "ENOENT") return { reclaimed: false };
28194
- if (errorCodeOf2(error) !== "EACCES") throw error;
28026
+ if (errorCodeOf(error) === "ENOENT") return { reclaimed: false };
28027
+ if (errorCodeOf(error) !== "EACCES") throw error;
28195
28028
  await chmod(runDirectory, 493);
28196
28029
  return { reclaimed: false, eaccesFailure: error };
28197
28030
  }
@@ -28224,7 +28057,7 @@ async function createWriterLease(lockPath, runDirectory, reportCleanupFailure) {
28224
28057
  try {
28225
28058
  await unlink4(currentLockPath);
28226
28059
  } catch (error) {
28227
- if (errorCodeOf2(error) === "EACCES") {
28060
+ if (errorCodeOf(error) === "EACCES") {
28228
28061
  try {
28229
28062
  await chmod(currentRunDirectory, 493);
28230
28063
  await unlink4(currentLockPath);
@@ -28264,7 +28097,7 @@ async function acquireRunWriterLease(runDirectory, onCleanupFailure) {
28264
28097
  try {
28265
28098
  return await createWriterLease(lockPath, runDirectory, reportCleanupFailure);
28266
28099
  } catch (error) {
28267
- if (errorCodeOf2(error) !== "EEXIST") throw error;
28100
+ if (errorCodeOf(error) !== "EEXIST") throw error;
28268
28101
  }
28269
28102
  lastAutopsy = await autopsyWriterLock(lockPath);
28270
28103
  if (lastAutopsy.verdict === "unknown" && lastAutopsy.reason === "unreadable") {
@@ -28317,7 +28150,7 @@ async function findRunDirectoryById(home, runId, onlyBookKey, onlyRole) {
28317
28150
  try {
28318
28151
  bookKeys = await readdir6(booksRoot);
28319
28152
  } catch (error) {
28320
- if (errorCodeOf2(error) === "ENOENT") return void 0;
28153
+ if (errorCodeOf(error) === "ENOENT") return void 0;
28321
28154
  throw error;
28322
28155
  }
28323
28156
  const matches = [];
@@ -28328,7 +28161,7 @@ async function findRunDirectoryById(home, runId, onlyBookKey, onlyRole) {
28328
28161
  try {
28329
28162
  runDirectories = await listBookRunDirectories(bookDir);
28330
28163
  } catch (error) {
28331
- if (errorCodeOf2(error) === "ENOENT") continue;
28164
+ if (errorCodeOf(error) === "ENOENT") continue;
28332
28165
  throw error;
28333
28166
  }
28334
28167
  for (const runDirectory of runDirectories) {
@@ -28356,7 +28189,7 @@ async function readRunParentPath(runDirectory) {
28356
28189
  await readFile16(join30(runDirectory, "admitted-request.json"), "utf8")
28357
28190
  );
28358
28191
  } catch (error) {
28359
- if (errorCodeOf2(error) === "ENOENT") return void 0;
28192
+ if (errorCodeOf(error) === "ENOENT") return void 0;
28360
28193
  throw error;
28361
28194
  }
28362
28195
  if (raw === null || typeof raw !== "object" || Array.isArray(raw)) {
@@ -28379,7 +28212,7 @@ async function runHasFormedSessionPrincipal(runDirectory) {
28379
28212
  const stat2 = await lstat6(sessionFile);
28380
28213
  return stat2.isFile() && !stat2.isSymbolicLink();
28381
28214
  } catch (error) {
28382
- if (errorCodeOf2(error) === "ENOENT") return false;
28215
+ if (errorCodeOf(error) === "ENOENT") return false;
28383
28216
  throw error;
28384
28217
  }
28385
28218
  }
@@ -28395,7 +28228,7 @@ async function findLatestRunIdForSeatTicket(input) {
28395
28228
  input.ticketNumber === void 0 ? bookDir : join30(bookDir, String(input.ticketNumber))
28396
28229
  );
28397
28230
  } catch (error) {
28398
- if (errorCodeOf2(error) === "ENOENT") return void 0;
28231
+ if (errorCodeOf(error) === "ENOENT") return void 0;
28399
28232
  throw error;
28400
28233
  }
28401
28234
  const suffix = `@${input.role}`;
@@ -29080,121 +28913,6 @@ var init_session_identity = __esm({
29080
28913
  }
29081
28914
  });
29082
28915
 
29083
- // src/public-cli/case-dossier-delivery.ts
29084
- import { mkdtemp as mkdtemp2, readFile as readFile18, rm as rm3, writeFile as writeFile7 } from "node:fs/promises";
29085
- import { tmpdir as tmpdir2 } from "node:os";
29086
- import { join as join32 } from "node:path";
29087
- async function projectCaseDossierPointerSection(input) {
29088
- if (input.ticketNumber === void 0) {
29089
- return [
29090
- UNBOUND_DOSSIER_PATH_HEADING,
29091
- "",
29092
- `\u8BB0\u5F55\u5377\u5B97\uFF1A${projectTicketRecordsPathShape()}`
29093
- ].join("\n");
29094
- }
29095
- const volume = resolveTicketProvenanceVolume(
29096
- input.ticketNumber,
29097
- input.projectRoot,
29098
- input.home
29099
- );
29100
- return [
29101
- CASE_DOSSIER_SECTION_HEADING,
29102
- "",
29103
- `\u7968\u53F7\uFF1A#${input.ticketNumber}`,
29104
- `\u8BB0\u5F55\u5377\u5B97\uFF1A${volume.recordFile}`
29105
- ].join("\n");
29106
- }
29107
- async function deliverCaseDossierAsAttachment(input) {
29108
- const section = await projectCaseDossierPointerSection({
29109
- ticketNumber: input.ticketNumber,
29110
- projectRoot: input.projectRoot,
29111
- home: input.home
29112
- });
29113
- const stagingDir = await mkdtemp2(join32(tmpdir2(), "ak-case-dossier-"));
29114
- try {
29115
- const stagingPath = join32(stagingDir, CASE_DOSSIER_ATTACH_FILE);
29116
- await writeFile7(stagingPath, `${section}
29117
- `, "utf8");
29118
- return await freezeAttachmentsIntoRun(
29119
- [stagingPath],
29120
- input.runDirectory,
29121
- CASE_DOSSIER_ATTACH_KEY
29122
- );
29123
- } finally {
29124
- await rm3(stagingDir, { recursive: true, force: true });
29125
- }
29126
- }
29127
- var CASE_DOSSIER_SECTION_HEADING, UNBOUND_DOSSIER_PATH_HEADING, CASE_DOSSIER_ATTACH_KEY, CASE_DOSSIER_ATTACH_FILE;
29128
- var init_case_dossier_delivery = __esm({
29129
- "src/public-cli/case-dossier-delivery.ts"() {
29130
- "use strict";
29131
- init_sitian_facade();
29132
- init_ticket_provenance();
29133
- init_invocation();
29134
- CASE_DOSSIER_SECTION_HEADING = "## \u672C\u7968\u8D77\u5C45\u5F55\uFF08\u7CFB\u7EDF\u968F\u6848\u63D0\u4F9B\uFF09";
29135
- UNBOUND_DOSSIER_PATH_HEADING = "## \u8D77\u5C45\u5F55\u8DEF\u5F84\uFF08\u7CFB\u7EDF\u968F\u6848\u63D0\u4F9B\uFF09";
29136
- CASE_DOSSIER_ATTACH_KEY = "case-dossier";
29137
- CASE_DOSSIER_ATTACH_FILE = "case-dossier-pointer.md";
29138
- }
29139
- });
29140
-
29141
- // src/host-transition-prior-native.ts
29142
- import { access as access3, readdir as readdir7 } from "node:fs/promises";
29143
- import { dirname as dirname19, join as join33 } from "node:path";
29144
- function isEnoent2(error) {
29145
- return typeof error === "object" && error !== null && error.code === "ENOENT";
29146
- }
29147
- async function listPiNativeRecordPaths(sessionFile) {
29148
- try {
29149
- await access3(sessionFile);
29150
- return [sessionFile];
29151
- } catch (error) {
29152
- if (isEnoent2(error)) return [];
29153
- throw error;
29154
- }
29155
- }
29156
- async function listSitianRecordPaths(sessionParent) {
29157
- const sessionRoot = dirname19(sessionParent);
29158
- let entries;
29159
- try {
29160
- entries = await readdir7(sessionRoot, { withFileTypes: true });
29161
- } catch (error) {
29162
- if (isEnoent2(error)) return [];
29163
- throw error;
29164
- }
29165
- const recordPaths = [];
29166
- for (const entry of entries) {
29167
- if (!entry.isDirectory()) continue;
29168
- const recordFile = join33(sessionRoot, entry.name, "records.jsonl");
29169
- try {
29170
- await access3(recordFile);
29171
- recordPaths.push(recordFile);
29172
- } catch (error) {
29173
- if (!isEnoent2(error)) throw error;
29174
- }
29175
- }
29176
- recordPaths.sort();
29177
- return recordPaths;
29178
- }
29179
- async function projectHostTransitionPriorNative(input) {
29180
- if (input.previousHost === input.liveHost) return void 0;
29181
- if (input.previousHost === "pi") {
29182
- return {
29183
- priorNativeKind: "pi-native",
29184
- priorNativePaths: await listPiNativeRecordPaths(input.piSessionFile)
29185
- };
29186
- }
29187
- return {
29188
- priorNativeKind: "sitian",
29189
- priorNativePaths: await listSitianRecordPaths(input.piSessionFile)
29190
- };
29191
- }
29192
- var init_host_transition_prior_native = __esm({
29193
- "src/host-transition-prior-native.ts"() {
29194
- "use strict";
29195
- }
29196
- });
29197
-
29198
28916
  // src/public-cli/process-cancel.ts
29199
28917
  var process_cancel_exports = {};
29200
28918
  __export(process_cancel_exports, {
@@ -29248,11 +28966,44 @@ var init_process_cancel = __esm({
29248
28966
  }
29249
28967
  });
29250
28968
 
28969
+ // src/host-session-record.ts
28970
+ import {
28971
+ appendFileSync as appendFileSync2,
28972
+ copyFileSync,
28973
+ closeSync,
28974
+ existsSync as existsSync10,
28975
+ openSync,
28976
+ readFileSync as readFileSync3,
28977
+ mkdirSync as mkdirSync4,
28978
+ readdirSync as readdirSync2,
28979
+ rmSync as rmSync2,
28980
+ statSync as statSync4
28981
+ } from "node:fs";
28982
+ import { dirname as dirname19, join as join32 } from "node:path";
28983
+ function declareHostSessionFailure(error) {
28984
+ const message = error instanceof Error ? error.stack || error.message : String(error);
28985
+ process.stderr.write(`[host-session] Dossier record failure: ${message}
28986
+ `);
28987
+ }
28988
+ function recordRunStart(runDirectory) {
28989
+ try {
28990
+ appendFileSync2(join32(runDirectory, ".run-starts"), "\n");
28991
+ } catch (error) {
28992
+ declareHostSessionFailure(error);
28993
+ }
28994
+ }
28995
+ var init_host_session_record = __esm({
28996
+ "src/host-session-record.ts"() {
28997
+ "use strict";
28998
+ init_sitian_facade();
28999
+ }
29000
+ });
29001
+
29251
29002
  // src/public-cli/auto-resume.ts
29252
29003
  import { constants as fsConstants2 } from "node:fs";
29253
29004
  import { randomUUID as randomUUID5 } from "node:crypto";
29254
29005
  import { lstat as lstat7, mkdir as mkdir4, open as open2 } from "node:fs/promises";
29255
- import { join as join34 } from "node:path";
29006
+ import { join as join33 } from "node:path";
29256
29007
  async function persistReturnedRunState(admitted, authority, options) {
29257
29008
  if (options?.lawful === true) {
29258
29009
  await markRunTerminal(admitted.runDirectory);
@@ -29323,7 +29074,7 @@ function jsonSafeReplacer() {
29323
29074
  };
29324
29075
  }
29325
29076
  async function writeHardenedArtifactFile(artifactsDir, namePrefix, payload) {
29326
- const filePath = join34(artifactsDir, `${namePrefix}-${randomUUID5()}.json`);
29077
+ const filePath = join33(artifactsDir, `${namePrefix}-${randomUUID5()}.json`);
29327
29078
  const body = `${JSON.stringify(payload, jsonSafeReplacer(), 2)}
29328
29079
  `;
29329
29080
  const noFollowFlag = typeof fsConstants2.O_NOFOLLOW === "number" ? fsConstants2.O_NOFOLLOW : 0;
@@ -29611,8 +29362,8 @@ var init_auto_resume = __esm({
29611
29362
 
29612
29363
  // src/public-cli/post-admission.ts
29613
29364
  import { randomUUID as randomUUID6 } from "node:crypto";
29614
- import { writeFile as writeFile8 } from "node:fs/promises";
29615
- import { isAbsolute as isAbsolute8, join as join35, resolve as resolve12 } from "node:path";
29365
+ import { writeFile as writeFile7 } from "node:fs/promises";
29366
+ import { isAbsolute as isAbsolute8, join as join34, resolve as resolve12 } from "node:path";
29616
29367
  function describeCaughtError(error) {
29617
29368
  if (error instanceof Error) {
29618
29369
  const code = error.code;
@@ -29707,8 +29458,8 @@ async function recordBestEffortPostDispatchDiagnostic(admitted, env, diagnostic,
29707
29458
  } catch (appendError) {
29708
29459
  try {
29709
29460
  const artifactsDir = await ensureRealArtifactsDirectory(admitted.runDirectory);
29710
- await writeFile8(
29711
- join35(artifactsDir, `post-admission-diagnostic-${randomUUID6()}.json`),
29461
+ await writeFile7(
29462
+ join34(artifactsDir, `post-admission-diagnostic-${randomUUID6()}.json`),
29712
29463
  `${JSON.stringify({ version: 1, ...payload }, null, 2)}
29713
29464
  `,
29714
29465
  { encoding: "utf8", flag: "wx" }
@@ -29854,7 +29605,7 @@ async function dispatchPostAdmissionTurn(input) {
29854
29605
  const rows = await readRecordedSubmissionRows(
29855
29606
  admitted.projectRoot,
29856
29607
  admitted.runId,
29857
- { home: homeFromRunDirectory(admitted.runDirectory), sessionParent: join35(admitted.runDirectory, "session", "session.jsonl") }
29608
+ { home: homeFromRunDirectory(admitted.runDirectory), sessionParent: join34(admitted.runDirectory, "session", "session.jsonl") }
29858
29609
  );
29859
29610
  let ticketNumber;
29860
29611
  for (const row of rows) {
@@ -29910,35 +29661,6 @@ async function dispatchPostAdmissionTurn(input) {
29910
29661
  }
29911
29662
  };
29912
29663
  try {
29913
- let previousHost;
29914
- const liveHost = env.host;
29915
- const principalCoordinates = admitted.principal === void 0 ? void 0 : env.principalAuthority.decode(admitted.principal);
29916
- let hostTransition;
29917
- try {
29918
- previousHost = readInvocationSelectedHost(admitted.runDirectory);
29919
- hostTransition = previousHost !== void 0 && liveHost !== void 0 && principalCoordinates !== void 0 ? await projectHostTransitionPriorNative({
29920
- previousHost,
29921
- liveHost,
29922
- piSessionFile: principalCoordinates.sessionFile
29923
- }) : void 0;
29924
- } catch (error) {
29925
- return {
29926
- ...await presentControlledFailure2(
29927
- admitted,
29928
- withEngineDetourInvocationScope({
29929
- timedOut: false,
29930
- code: null,
29931
- stderr: "",
29932
- thrown: error
29933
- }, request.invocationScopeId),
29934
- adapters,
29935
- env.principalAuthority,
29936
- io,
29937
- persistRunState
29938
- ),
29939
- ...deferredPersist
29940
- };
29941
- }
29942
29664
  await clearTypedProviderHttpObservation(admitted.runDirectory);
29943
29665
  if (adapters.beforeDispatch !== void 0) {
29944
29666
  try {
@@ -29974,18 +29696,9 @@ async function dispatchPostAdmissionTurn(input) {
29974
29696
  if (env.stationChild !== void 0) {
29975
29697
  turnRequest = { ...turnRequest, stationChild: env.stationChild };
29976
29698
  }
29977
- if (hostTransition !== void 0) {
29978
- turnRequest = { ...turnRequest, hostTransition };
29699
+ if (typeof env.host === "string" && env.host.trim() !== "") {
29700
+ turnRequest = { ...turnRequest, host: env.host.trim() };
29979
29701
  }
29980
- if (typeof liveHost === "string" && liveHost.trim() !== "") {
29981
- turnRequest = { ...turnRequest, host: liveHost.trim() };
29982
- }
29983
- await deliverCaseDossierAsAttachment({
29984
- ticketNumber: admitted.ticketNumber,
29985
- projectRoot: admitted.projectRoot,
29986
- home: env.home,
29987
- runDirectory: admitted.runDirectory
29988
- });
29989
29702
  await markRunRunning(
29990
29703
  admitted.runDirectory,
29991
29704
  env.model,
@@ -29995,6 +29708,7 @@ async function dispatchPostAdmissionTurn(input) {
29995
29708
  );
29996
29709
  let result;
29997
29710
  try {
29711
+ recordRunStart(admitted.runDirectory);
29998
29712
  result = await env.roleTurnHost.executeTurn(turnRequest);
29999
29713
  } catch (error) {
30000
29714
  const processCancelName = processCancelSignalName(env.signal);
@@ -30020,8 +29734,8 @@ async function dispatchPostAdmissionTurn(input) {
30020
29734
  }
30021
29735
  let stderrLogWriteFailure;
30022
29736
  try {
30023
- await writeFile8(
30024
- join35(admitted.runDirectory, "stderr.log"),
29737
+ await writeFile7(
29738
+ join34(admitted.runDirectory, "stderr.log"),
30025
29739
  result.stderr,
30026
29740
  "utf8"
30027
29741
  );
@@ -30300,7 +30014,7 @@ async function dispatchAfterWriterLease(input) {
30300
30014
  }
30301
30015
  function isAlreadyFrozenSummonsAttachment(runDirectory, attachmentPath) {
30302
30016
  const absolute = isAbsolute8(attachmentPath) ? attachmentPath : resolve12(attachmentPath);
30303
- return pathContainedIn(join35(runDirectory, "attachments"), absolute);
30017
+ return pathContainedIn(join34(runDirectory, "attachments"), absolute);
30304
30018
  }
30305
30019
  async function prepareSummonsResumeMaterials(runDirectory, summons) {
30306
30020
  if (summons === void 0) return void 0;
@@ -30559,8 +30273,8 @@ async function presentResumeFailurePointer(io, thrown, publish) {
30559
30273
  }
30560
30274
  async function writeResumeDiagnosticFile(runDirectory, runId, failure, role) {
30561
30275
  const dir = await ensureRealArtifactsDirectory(runDirectory);
30562
- const path = join35(dir, `resume-diagnostic-${randomUUID6()}.json`);
30563
- await writeFile8(
30276
+ const path = join34(dir, `resume-diagnostic-${randomUUID6()}.json`);
30277
+ await writeFile7(
30564
30278
  path,
30565
30279
  `${JSON.stringify({
30566
30280
  runId,
@@ -30692,12 +30406,11 @@ var init_post_admission = __esm({
30692
30406
  init_session_identity();
30693
30407
  init_role_run_relocation();
30694
30408
  init_packaged_role_registry();
30695
- init_case_dossier_delivery();
30696
30409
  init_engine_detour_usage();
30697
- init_host_transition_prior_native();
30698
30410
  init_run_lifecycle();
30699
30411
  init_process_cancel();
30700
30412
  init_activation_ledger_topology();
30413
+ init_host_session_record();
30701
30414
  init_settlement();
30702
30415
  init_terminal();
30703
30416
  init_auto_resume();
@@ -30709,13 +30422,13 @@ var init_post_admission = __esm({
30709
30422
  });
30710
30423
 
30711
30424
  // src/analyst-book-key.ts
30712
- import { statSync as statSync4 } from "node:fs";
30425
+ import { statSync as statSync5 } from "node:fs";
30713
30426
  import { isAbsolute as isAbsolute9 } from "node:path";
30714
30427
  function resolveAnalystBookKey(projectRoot) {
30715
30428
  const identity = physicalPathIdentity(projectRoot);
30716
30429
  let stats;
30717
30430
  try {
30718
- stats = statSync4(identity);
30431
+ stats = statSync5(identity);
30719
30432
  } catch (error) {
30720
30433
  const code = errnoCode(error);
30721
30434
  if (code === "ENOENT" || code === "ENOTDIR") return `root:${identity}`;
@@ -30744,16 +30457,16 @@ var init_analyst_book_key = __esm({
30744
30457
 
30745
30458
  // src/atomic-write.ts
30746
30459
  import { randomUUID as randomUUID7 } from "node:crypto";
30747
- import { rename as rename3, rm as rm4, writeFile as writeFile9 } from "node:fs/promises";
30748
- import { dirname as dirname20, join as join36 } from "node:path";
30460
+ import { rename as rename3, rm as rm3, writeFile as writeFile8 } from "node:fs/promises";
30461
+ import { dirname as dirname20, join as join35 } from "node:path";
30749
30462
  async function writeFileAtomically(destination, contents) {
30750
30463
  const parent = dirname20(destination);
30751
- const temporary = join36(parent, `.atomic-write-${randomUUID7()}.tmp`);
30464
+ const temporary = join35(parent, `.atomic-write-${randomUUID7()}.tmp`);
30752
30465
  try {
30753
- await writeFile9(temporary, contents);
30466
+ await writeFile8(temporary, contents);
30754
30467
  await rename3(temporary, destination);
30755
30468
  } catch (error) {
30756
- await rm4(temporary, { force: true }).catch(() => void 0);
30469
+ await rm3(temporary, { force: true }).catch(() => void 0);
30757
30470
  throw error;
30758
30471
  }
30759
30472
  }
@@ -30764,8 +30477,8 @@ var init_atomic_write = __esm({
30764
30477
  });
30765
30478
 
30766
30479
  // src/analyst-index.ts
30767
- import { open as open3, readFile as readFile19, unlink as unlink5 } from "node:fs/promises";
30768
- import { dirname as dirname21, join as join37 } from "node:path";
30480
+ import { open as open3, readFile as readFile18, unlink as unlink5 } from "node:fs/promises";
30481
+ import { dirname as dirname21, join as join36 } from "node:path";
30769
30482
  function sleep(ms) {
30770
30483
  return new Promise((resolve14) => {
30771
30484
  setTimeout(resolve14, ms);
@@ -30774,7 +30487,7 @@ function sleep(ms) {
30774
30487
  async function withAnalystLibraryIndexLock(ledgerHome, fn) {
30775
30488
  const indexPath = analystLibraryIndexPath(ledgerHome);
30776
30489
  ensureRealDirectoryTree(ledgerHome, dirname21(indexPath));
30777
- const lockPath = join37(dirname21(indexPath), LIBRARY_INDEX_LOCK_NAME);
30490
+ const lockPath = join36(dirname21(indexPath), LIBRARY_INDEX_LOCK_NAME);
30778
30491
  assertLedgerFileInsideHome(lockPath, ledgerHome);
30779
30492
  const startedAt = Date.now();
30780
30493
  while (true) {
@@ -30801,7 +30514,7 @@ async function withAnalystLibraryIndexLock(ledgerHome, fn) {
30801
30514
  }
30802
30515
  }
30803
30516
  function analystLibraryIndexPath(ledgerHome) {
30804
- return join37(ledgerHome, "analyst", "library-index.json");
30517
+ return join36(ledgerHome, "analyst", "library-index.json");
30805
30518
  }
30806
30519
  function rowFromIssueMetricsPage(page) {
30807
30520
  return {
@@ -30892,7 +30605,7 @@ async function readAnalystLibraryIndexPage(ledgerHome) {
30892
30605
  const path = analystLibraryIndexPath(ledgerHome);
30893
30606
  let raw;
30894
30607
  try {
30895
- raw = await readFile19(path, "utf8");
30608
+ raw = await readFile18(path, "utf8");
30896
30609
  } catch (error) {
30897
30610
  if (error instanceof Error && "code" in error && (error.code === "ENOENT" || error.code === "ENOTDIR")) {
30898
30611
  return void 0;
@@ -31096,15 +30809,15 @@ var init_analyst_cohort = __esm({
31096
30809
  });
31097
30810
 
31098
30811
  // src/analyst-ledger.ts
31099
- import { readdir as readdir8, readFile as readFile20 } from "node:fs/promises";
31100
- import { basename as basename9, join as join38 } from "node:path";
30812
+ import { readdir as readdir7, readFile as readFile19 } from "node:fs/promises";
30813
+ import { basename as basename9, join as join37 } from "node:path";
31101
30814
  function isMissingPathError6(error) {
31102
30815
  return error instanceof Error && "code" in error && (error.code === "ENOENT" || error.code === "ENOTDIR");
31103
30816
  }
31104
30817
  function errorText3(error) {
31105
30818
  return error instanceof Error ? error.message : String(error);
31106
30819
  }
31107
- function isRecord12(value) {
30820
+ function isRecord11(value) {
31108
30821
  return typeof value === "object" && value !== null && !Array.isArray(value);
31109
30822
  }
31110
30823
  async function readExistingRunLifecycleState(runDirectory) {
@@ -31126,7 +30839,7 @@ function ghostLeaseCheckFromAutopsy(autopsy) {
31126
30839
  }
31127
30840
  }
31128
30841
  async function classifyGhostCandidate(input) {
31129
- const autopsy = await autopsyWriterLock(join38(input.runDirectory, "writer.lock"));
30842
+ const autopsy = await autopsyWriterLock(join37(input.runDirectory, "writer.lock"));
31130
30843
  const leaseCheck = ghostLeaseCheckFromAutopsy(autopsy);
31131
30844
  if (leaseCheck === void 0) return { kind: "live" };
31132
30845
  return {
@@ -31145,7 +30858,7 @@ function parseRunDirectoryName2(name) {
31145
30858
  }
31146
30859
  async function listLedgerBookNames(booksRoot) {
31147
30860
  try {
31148
- const entries = await readdir8(booksRoot, { withFileTypes: true });
30861
+ const entries = await readdir7(booksRoot, { withFileTypes: true });
31149
30862
  return entries.filter((e) => e.isDirectory()).map((e) => e.name).sort();
31150
30863
  } catch (error) {
31151
30864
  if (isMissingPathError6(error)) return [];
@@ -31155,13 +30868,13 @@ async function listLedgerBookNames(booksRoot) {
31155
30868
  async function readInvocationScopeFields(runDirectory) {
31156
30869
  let raw;
31157
30870
  try {
31158
- raw = await readFile20(join38(runDirectory, "invocation.json"), "utf8");
30871
+ raw = await readFile19(join37(runDirectory, "invocation.json"), "utf8");
31159
30872
  } catch (error) {
31160
30873
  if (isMissingPathError6(error)) return void 0;
31161
30874
  throw error;
31162
30875
  }
31163
30876
  const parsed = JSON.parse(raw);
31164
- if (!isRecord12(parsed)) return void 0;
30877
+ if (!isRecord11(parsed)) return void 0;
31165
30878
  if (typeof parsed.projectRoot !== "string" || parsed.projectRoot.trim() === "") {
31166
30879
  return void 0;
31167
30880
  }
@@ -31188,15 +30901,15 @@ function decideIssueScope(input) {
31188
30901
  }
31189
30902
  async function resolveSessionFile(runDirectory) {
31190
30903
  try {
31191
- const raw = await readFile20(join38(runDirectory, "invocation.json"), "utf8");
30904
+ const raw = await readFile19(join37(runDirectory, "invocation.json"), "utf8");
31192
30905
  const parsed = JSON.parse(raw);
31193
- if (isRecord12(parsed) && typeof parsed.sessionFile === "string" && parsed.sessionFile.trim() !== "") {
30906
+ if (isRecord11(parsed) && typeof parsed.sessionFile === "string" && parsed.sessionFile.trim() !== "") {
31194
30907
  return parsed.sessionFile;
31195
30908
  }
31196
30909
  } catch (error) {
31197
30910
  if (!isMissingPathError6(error)) throw error;
31198
30911
  }
31199
- return join38(runDirectory, "session", "session.jsonl");
30912
+ return join37(runDirectory, "session", "session.jsonl");
31200
30913
  }
31201
30914
  function attributeSessionRowsForRun(input) {
31202
30915
  if (pathContainedIn(input.runDirectory, input.sessionFile)) {
@@ -31388,9 +31101,9 @@ async function classifyScopedRun(input) {
31388
31101
  }
31389
31102
  let gateCycles;
31390
31103
  try {
31391
- const parentSessionFile = join38(input.runDirectory, "session", "session.jsonl");
31104
+ const parentSessionFile = join37(input.runDirectory, "session", "session.jsonl");
31392
31105
  gateCycles = await readAnalystGateCyclesFromAuditorRoles(
31393
- join38(input.runDirectory, "session", "auditor-roles"),
31106
+ join37(input.runDirectory, "session", "auditor-roles"),
31394
31107
  { parentSessionFile }
31395
31108
  );
31396
31109
  } catch (error) {
@@ -31425,7 +31138,7 @@ async function classifyScopedRun(input) {
31425
31138
  async function scanAnalystIssueRuns(input) {
31426
31139
  const ledgerHome = resolveActivationLedgerHome(input.home);
31427
31140
  const scopeTicketNumber = input.ticketNumber;
31428
- const booksRoot = join38(ledgerHome, "books");
31141
+ const booksRoot = join37(ledgerHome, "books");
31429
31142
  let wholeBook = false;
31430
31143
  let scopeRootIdentity;
31431
31144
  let bookNames;
@@ -31458,7 +31171,7 @@ async function scanAnalystIssueRuns(input) {
31458
31171
  const ghostLegs = [];
31459
31172
  const scopeConflicts = [];
31460
31173
  for (const book of bookNames) {
31461
- const bookDir = join38(booksRoot, book);
31174
+ const bookDir = join37(booksRoot, book);
31462
31175
  let runDirectories;
31463
31176
  try {
31464
31177
  runDirectories = await listBookRunDirectories(bookDir);
@@ -31528,7 +31241,7 @@ var init_analyst_ledger = __esm({
31528
31241
  });
31529
31242
 
31530
31243
  // src/analyst-metric-families/acceptance-success-rework.ts
31531
- function isRecord13(value) {
31244
+ function isRecord12(value) {
31532
31245
  return typeof value === "object" && value !== null && !Array.isArray(value);
31533
31246
  }
31534
31247
  function wallMsFromSpan(span) {
@@ -31537,21 +31250,21 @@ function wallMsFromSpan(span) {
31537
31250
  function findCollectorGroups(body) {
31538
31251
  if (Array.isArray(body.groups)) return body.groups;
31539
31252
  const receipt = body.receipt;
31540
- if (isRecord13(receipt) && Array.isArray(receipt.groups)) return receipt.groups;
31253
+ if (isRecord12(receipt) && Array.isArray(receipt.groups)) return receipt.groups;
31541
31254
  const outcome = body.outcome;
31542
- if (isRecord13(outcome)) {
31255
+ if (isRecord12(outcome)) {
31543
31256
  const facts = outcome.decisiveFacts;
31544
- if (isRecord13(facts) && Array.isArray(facts.groups)) return facts.groups;
31257
+ if (isRecord12(facts) && Array.isArray(facts.groups)) return facts.groups;
31545
31258
  }
31546
31259
  return void 0;
31547
31260
  }
31548
31261
  function extractStatus(body) {
31549
31262
  const outcome = body.outcome;
31550
- if (isRecord13(outcome) && typeof outcome.status === "string" && outcome.status.trim() !== "") {
31263
+ if (isRecord12(outcome) && typeof outcome.status === "string" && outcome.status.trim() !== "") {
31551
31264
  return outcome.status;
31552
31265
  }
31553
31266
  const receipt = body.receipt;
31554
- if (isRecord13(receipt) && typeof receipt.status === "string" && receipt.status.trim() !== "") {
31267
+ if (isRecord12(receipt) && typeof receipt.status === "string" && receipt.status.trim() !== "") {
31555
31268
  return receipt.status;
31556
31269
  }
31557
31270
  if (typeof body.status === "string" && body.status.trim() !== "") {
@@ -32177,15 +31890,15 @@ var init_leg_wall_clock = __esm({
32177
31890
  });
32178
31891
 
32179
31892
  // src/analyst-metric-families/round-timeline.ts
32180
- function isRecord14(value) {
31893
+ function isRecord13(value) {
32181
31894
  return typeof value === "object" && value !== null && !Array.isArray(value);
32182
31895
  }
32183
31896
  function wallMsFromSpan2(startedAt, endedAt) {
32184
31897
  return Date.parse(endedAt) - Date.parse(startedAt);
32185
31898
  }
32186
31899
  function readClassCount(body) {
32187
- if (!isRecord14(body.outcome)) return void 0;
32188
- if (!isRecord14(body.outcome.decisiveFacts)) return void 0;
31900
+ if (!isRecord13(body.outcome)) return void 0;
31901
+ if (!isRecord13(body.outcome.decisiveFacts)) return void 0;
32189
31902
  const classCount = body.outcome.decisiveFacts.classCount;
32190
31903
  if (typeof classCount !== "number" || !Number.isFinite(classCount)) {
32191
31904
  return void 0;
@@ -32329,8 +32042,8 @@ var init_analyst_metric_family = __esm({
32329
32042
  });
32330
32043
 
32331
32044
  // src/analyst-page.ts
32332
- import { createHash as createHash4 } from "node:crypto";
32333
- import { dirname as dirname22, join as join39 } from "node:path";
32045
+ import { createHash as createHash3 } from "node:crypto";
32046
+ import { dirname as dirname22, join as join38 } from "node:path";
32334
32047
  function analystIssuePageKey(address) {
32335
32048
  const parts = ["book", address.bookKey];
32336
32049
  if (address.issueNumber !== void 0) {
@@ -32338,10 +32051,10 @@ function analystIssuePageKey(address) {
32338
32051
  } else if (address.scopeRootIdentity !== void 0) {
32339
32052
  parts.push("root", physicalPathIdentity(address.scopeRootIdentity));
32340
32053
  }
32341
- return createHash4("sha256").update(parts.join("\0")).digest("hex").slice(0, 32);
32054
+ return createHash3("sha256").update(parts.join("\0")).digest("hex").slice(0, 32);
32342
32055
  }
32343
32056
  function analystIssuePagePath(ledgerHome, address) {
32344
- return join39(ledgerHome, "analyst", "issues", `${analystIssuePageKey(address)}.json`);
32057
+ return join38(ledgerHome, "analyst", "issues", `${analystIssuePageKey(address)}.json`);
32345
32058
  }
32346
32059
  function analystIssuePageAddressFromPage(page) {
32347
32060
  return {
@@ -32477,7 +32190,7 @@ var init_analyst_page = __esm({
32477
32190
  });
32478
32191
 
32479
32192
  // src/analyst-entry.ts
32480
- import { readFile as readFile21 } from "node:fs/promises";
32193
+ import { readFile as readFile20 } from "node:fs/promises";
32481
32194
  function isMissingPathError7(error) {
32482
32195
  return error instanceof Error && "code" in error && (error.code === "ENOENT" || error.code === "ENOTDIR");
32483
32196
  }
@@ -32507,7 +32220,7 @@ async function readOrComputeAnalystIssuePage(input, options) {
32507
32220
  ...issueNumber === void 0 && input.bookKey === void 0 ? { scopeRootIdentity: projectRoot } : {}
32508
32221
  });
32509
32222
  try {
32510
- const raw = await readFile21(pagePath, "utf8");
32223
+ const raw = await readFile20(pagePath, "utf8");
32511
32224
  const page = JSON.parse(raw);
32512
32225
  if (cachedPageMatchesRequestedScope(page, { bookKey, ...input })) {
32513
32226
  const ghostScan = await scanAnalystIssueRuns({
@@ -32608,7 +32321,7 @@ async function runAnalystModelGroupsMode(input, home) {
32608
32321
  scopeRootIdentity: projectRoot
32609
32322
  });
32610
32323
  try {
32611
- const raw = await readFile21(pagePath, "utf8");
32324
+ const raw = await readFile20(pagePath, "utf8");
32612
32325
  JSON.parse(raw);
32613
32326
  } catch (error) {
32614
32327
  if (!isMissingPathError7(error)) {
@@ -32707,7 +32420,7 @@ var init_analyst_entry = __esm({
32707
32420
  });
32708
32421
 
32709
32422
  // src/public-cli/analyst-run.ts
32710
- import { readFile as readFile22 } from "node:fs/promises";
32423
+ import { readFile as readFile21 } from "node:fs/promises";
32711
32424
  import { isAbsolute as isAbsolute10, resolve as resolve13 } from "node:path";
32712
32425
  function resolveAnalystIssueBookKeyFromCwd(cwd = process.cwd()) {
32713
32426
  try {
@@ -32760,7 +32473,7 @@ async function buildAnalystSweepModeInputFromAttachmentPaths(attachmentPaths) {
32760
32473
  const absolute = isAbsolute10(sourcePath) ? sourcePath : resolve13(sourcePath);
32761
32474
  let bytes;
32762
32475
  try {
32763
- bytes = await readFile22(absolute);
32476
+ bytes = await readFile21(absolute);
32764
32477
  } catch (error) {
32765
32478
  throw new CliUsageError(
32766
32479
  `analyst sweep attachment is not a readable regular file: ${sourcePath}`,
@@ -32881,7 +32594,7 @@ __export(cli_exports, {
32881
32594
  runAkRole: () => runAkRole
32882
32595
  });
32883
32596
  import { realpath as realpath6 } from "node:fs/promises";
32884
- import { join as join40 } from "node:path";
32597
+ import { join as join39 } from "node:path";
32885
32598
  function publicSeatArgv(owner) {
32886
32599
  return {
32887
32600
  parse: (args) => parsePublicSeatArgv(owner, args),
@@ -33020,7 +32733,7 @@ function resolveHome(env) {
33020
32733
  return env.home ?? packageMachineHome();
33021
32734
  }
33022
32735
  function resolveAgentDir(env, home) {
33023
- return env.agentDir ?? process.env.PI_CODING_AGENT_DIR ?? join40(home, ".pi", "agent");
32736
+ return env.agentDir ?? process.env.PI_CODING_AGENT_DIR ?? join39(home, ".pi", "agent");
33024
32737
  }
33025
32738
  function parseThinking(value) {
33026
32739
  return value;
@@ -33782,7 +33495,7 @@ var init_cli = __esm({
33782
33495
 
33783
33496
  // src/public-cli/main.ts
33784
33497
  import { existsSync as existsSync11 } from "node:fs";
33785
- import { dirname as dirname23, join as join41 } from "node:path";
33498
+ import { dirname as dirname23, join as join40 } from "node:path";
33786
33499
  import { fileURLToPath as fileURLToPath2 } from "node:url";
33787
33500
 
33788
33501
  // src/public-cli/host-pi-runtime.ts
@@ -33871,8 +33584,8 @@ function linkPackage(packageRoot2, name, targetDir) {
33871
33584
  // src/public-cli/main.ts
33872
33585
  var here = dirname23(fileURLToPath2(import.meta.url));
33873
33586
  function resolvePackageRoot(binDir) {
33874
- const canonical = join41(binDir, "..", "..");
33875
- if (existsSync11(join41(canonical, "package.json"))) {
33587
+ const canonical = join40(binDir, "..", "..");
33588
+ if (existsSync11(join40(canonical, "package.json"))) {
33876
33589
  return canonical;
33877
33590
  }
33878
33591
  return binDir;