@akagilnc/pi-workflow-roles 0.1.5252 → 0.1.5270

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.
@@ -538,7 +538,6 @@ __export(durable_principal_exports, {
538
538
  issuePiDurablePrincipalCoordinates: () => issuePiDurablePrincipalCoordinates,
539
539
  piDurablePrincipalAuthority: () => piDurablePrincipalAuthority
540
540
  });
541
- import { lstat } from "node:fs/promises";
542
541
  import { join as join5 } from "node:path";
543
542
  function encode(coordinates) {
544
543
  return coordinates;
@@ -591,15 +590,6 @@ var init_durable_principal = __esm({
591
590
  sessionDirectory: record4.sessionDirectory,
592
591
  sessionFile: typeof record4.sessionFile === "string" && record4.sessionFile.trim() !== "" ? record4.sessionFile : join5(record4.sessionDirectory, "session.jsonl")
593
592
  };
594
- },
595
- async isAvailable(principal) {
596
- const { sessionFile } = this.decode(principal);
597
- try {
598
- const stat2 = await lstat(sessionFile);
599
- return stat2.isFile() && !stat2.isSymbolicLink();
600
- } catch {
601
- return false;
602
- }
603
593
  }
604
594
  };
605
595
  }
@@ -15828,7 +15818,6 @@ var init_host_descriptions = __esm({
15828
15818
  modelFlag: "--model"
15829
15819
  }),
15830
15820
  modelPassing: "argv",
15831
- boundResume: "session/load",
15832
15821
  sessionBindingFile: "grok-acp-session.json"
15833
15822
  }),
15834
15823
  /**
@@ -15846,7 +15835,6 @@ var init_host_descriptions = __esm({
15846
15835
  thinkingFlag: "--reasoning"
15847
15836
  }),
15848
15837
  modelPassing: "set_model",
15849
- boundResume: "session/load",
15850
15838
  sessionBindingFile: "hermes-acp-session.json",
15851
15839
  seatProfileSoul: Object.freeze({
15852
15840
  flag: "-p",
@@ -16618,7 +16606,7 @@ var init_cli_errors = __esm({
16618
16606
 
16619
16607
  // src/public-cli/machine-method-skills.ts
16620
16608
  import { accessSync, constants, statSync as statSync2 } from "node:fs";
16621
- import { lstat as lstat2, mkdir as mkdir2, symlink } from "node:fs/promises";
16609
+ import { lstat, mkdir as mkdir2, symlink } from "node:fs/promises";
16622
16610
  import { join as join9 } from "node:path";
16623
16611
  import { spawnSync } from "node:child_process";
16624
16612
  function skillRoot(home) {
@@ -16648,7 +16636,7 @@ function linkedSkillRoot(home, host) {
16648
16636
  }
16649
16637
  async function occupied(path) {
16650
16638
  try {
16651
- await lstat2(path);
16639
+ await lstat(path);
16652
16640
  return true;
16653
16641
  } catch (error) {
16654
16642
  if (error.code !== "ENOENT") throw error;
@@ -17371,8 +17359,8 @@ function formatTerminalResult(result) {
17371
17359
  `diagnostic ${encodeTerminalField(result.roleOutcome.diagnostic)}`
17372
17360
  );
17373
17361
  }
17374
- if (result.roleOutcome.kind === "failure" || result.roleOutcome.kind === "no_receipt" || result.roleOutcome.kind === "audit_escalation") {
17375
- const facts = result.roleOutcome.decisiveFacts ?? {};
17362
+ if (result.roleOutcome.kind === "failure" || result.roleOutcome.kind === "no_receipt" || result.roleOutcome.kind === "audit_escalation" || result.roleOutcome.decisiveFacts?.failedAttempts !== void 0) {
17363
+ const facts = result.roleOutcome.kind === "accepted" ? { failedAttempts: result.roleOutcome.decisiveFacts?.failedAttempts } : result.roleOutcome.decisiveFacts ?? {};
17376
17364
  for (const [key, value] of Object.entries(facts)) {
17377
17365
  if (value === void 0) continue;
17378
17366
  const rendered = typeof value === "string" ? value : JSON.stringify(value);
@@ -18798,7 +18786,7 @@ var init_uuidv7 = __esm({
18798
18786
 
18799
18787
  // src/notary-source-run.ts
18800
18788
  import { dirname as dirname11, isAbsolute as isAbsolute5, join as join17, resolve as resolve8, basename as basename5 } from "node:path";
18801
- import { lstat as lstat3, realpath as realpath3 } from "node:fs/promises";
18789
+ import { lstat as lstat2, realpath as realpath3 } from "node:fs/promises";
18802
18790
  async function readRetainedIdentity(runDirectory) {
18803
18791
  try {
18804
18792
  return await readRoleRunIdentity(runDirectory);
@@ -18826,7 +18814,7 @@ async function requireRunDirectory(candidate, display) {
18826
18814
  }
18827
18815
  let stat2;
18828
18816
  try {
18829
- stat2 = await lstat3(real);
18817
+ stat2 = await lstat2(real);
18830
18818
  } catch (error) {
18831
18819
  throw new NotarySourceRunError(
18832
18820
  `notary --source-run is not a readable run directory: ${display}`,
@@ -19965,7 +19953,7 @@ var init_option_definitions = __esm({
19965
19953
  import { execFileSync as execFileSync2 } from "node:child_process";
19966
19954
  import { existsSync as existsSync4 } from "node:fs";
19967
19955
  import {
19968
- lstat as lstat4,
19956
+ lstat as lstat3,
19969
19957
  mkdtemp,
19970
19958
  readFile as readFile12,
19971
19959
  realpath as realpath4,
@@ -20527,7 +20515,7 @@ async function readRegularFileAttachment(sourcePath) {
20527
20515
  const absolute = isAbsolute6(sourcePath) ? sourcePath : resolve9(sourcePath);
20528
20516
  let st;
20529
20517
  try {
20530
- st = await lstat4(absolute);
20518
+ st = await lstat3(absolute);
20531
20519
  } catch (error) {
20532
20520
  throw new CliUsageError(
20533
20521
  `attachment is not a readable regular file: ${sourcePath}`,
@@ -26033,7 +26021,7 @@ async function runPublicInstructionSeatResume(request, env, io) {
26033
26021
  };
26034
26022
  let binding;
26035
26023
  try {
26036
- const loaded = await loadResumablePublicRole(env.home, request.runId, env.principalAuthority, true);
26024
+ const loaded = await loadResumablePublicRole(env.home, request.runId, env.principalAuthority);
26037
26025
  binding = loaded.admitted.role === "auditor" ? await readAuditorResumeBinding(loaded.admitted.runDirectory) : void 0;
26038
26026
  } catch (error) {
26039
26027
  if (!(error instanceof CliUsageError)) throw error;
@@ -26076,7 +26064,7 @@ async function queueConclusionFromChild(child, env, io) {
26076
26064
  }
26077
26065
  }
26078
26066
  async function continueParentAfterChild(parentRunId, child, env, io) {
26079
- const loaded = await loadResumablePublicRole(env.home, parentRunId, env.principalAuthority, true);
26067
+ const loaded = await loadResumablePublicRole(env.home, parentRunId, env.principalAuthority);
26080
26068
  if (loaded.run.state !== "admitted" && !AUDITED_ROLES.has(loaded.admitted.role)) {
26081
26069
  return runPublicInstructionSeatResume({ runId: parentRunId }, env, io);
26082
26070
  }
@@ -26271,7 +26259,7 @@ async function auditSubmittedRole(turn, env, io, passedOfficer, passedReceipt, p
26271
26259
  const escalation = chain.passes.at(-1);
26272
26260
  const escalatedRunId = escalation?.runId ?? (escalation?.runDirectory === void 0 ? void 0 : runIdFromRunDirectory(escalation.runDirectory));
26273
26261
  if (escalatedRunId === void 0) throw new Error("escalated audit has no resumable run identity");
26274
- const officer = await loadResumablePublicRole(env.home, escalatedRunId, env.principalAuthority, true);
26262
+ const officer = await loadResumablePublicRole(env.home, escalatedRunId, env.principalAuthority);
26275
26263
  const terminal2 = await trySettlePublicSeat(officer.admitted, env.principalAuthority, void 0);
26276
26264
  if (terminal2 === void 0) throw new Error("escalated audit has no terminal result");
26277
26265
  io.stdout(formatTerminalResult(terminal2));
@@ -27138,7 +27126,6 @@ __export(run_lifecycle_exports, {
27138
27126
  describeErrorIdentity: () => describeErrorIdentity,
27139
27127
  findLatestRunIdForSeatTicket: () => findLatestRunIdForSeatTicket,
27140
27128
  findRunDirectoryById: () => findRunDirectoryById,
27141
- isDurablePrincipalAvailable: () => isDurablePrincipalAvailable,
27142
27129
  isV1ResumableProvider: () => isV1ResumableProvider,
27143
27130
  loadResumablePublicRole: () => loadResumablePublicRole,
27144
27131
  markRunAdmitted: () => markRunAdmitted,
@@ -27158,7 +27145,7 @@ __export(run_lifecycle_exports, {
27158
27145
  renderResumeCommand: () => renderResumeCommand,
27159
27146
  writeRoleRunState: () => writeRoleRunState
27160
27147
  });
27161
- import { chmod, lstat as lstat6, open, readdir as readdir6, readFile as readFile16, unlink as unlink4, writeFile as writeFile5 } from "node:fs/promises";
27148
+ import { chmod, lstat as lstat5, open, readdir as readdir6, readFile as readFile16, unlink as unlink4, writeFile as writeFile5 } from "node:fs/promises";
27162
27149
  import { basename as basename8, join as join30 } from "node:path";
27163
27150
  function buildAutoResumeContinuationPrompt(options) {
27164
27151
  return appendEngineSessionMaterial(
@@ -27472,9 +27459,6 @@ async function clearCurrentCourt(runDirectory, expectedCourtAttemptId) {
27472
27459
  ...current.resumable === void 0 ? {} : { resumable: current.resumable }
27473
27460
  });
27474
27461
  }
27475
- async function isDurablePrincipalAvailable(principal, authority) {
27476
- return authority.isAvailable(principal);
27477
- }
27478
27462
  function describeErrorIdentity(error) {
27479
27463
  const candidate = error;
27480
27464
  const name = typeof candidate?.name === "string" && candidate.name !== "" ? candidate.name : typeof error;
@@ -27716,7 +27700,7 @@ async function runHasFormedSessionPrincipal(runDirectory) {
27716
27700
  if (disk === void 0) return false;
27717
27701
  const sessionFile = typeof disk.principalWire.sessionFile === "string" && disk.principalWire.sessionFile.trim() !== "" ? disk.principalWire.sessionFile : join30(disk.principalWire.sessionDirectory, "session.jsonl");
27718
27702
  try {
27719
- const stat2 = await lstat6(sessionFile);
27703
+ const stat2 = await lstat5(sessionFile);
27720
27704
  return stat2.isFile() && !stat2.isSymbolicLink();
27721
27705
  } catch (error) {
27722
27706
  if (errorCodeOf(error) === "ENOENT") return false;
@@ -27808,7 +27792,7 @@ function restoredTicketFields(fields) {
27808
27792
  ...fields.courtTicketNumbers === void 0 ? {} : { courtTicketNumbers: fields.courtTicketNumbers }
27809
27793
  };
27810
27794
  }
27811
- async function loadResumableRunRecord(home, runId, authority, allowUnformedAdmitted = false) {
27795
+ async function loadResumableRunRecord(home, runId, authority) {
27812
27796
  const runDirectory = await findRunDirectoryById(home, runId);
27813
27797
  if (runDirectory === void 0) {
27814
27798
  throw new CliUsageError(`unknown role run id: ${runId}`);
@@ -27822,11 +27806,6 @@ async function loadResumableRunRecord(home, runId, authority, allowUnformedAdmit
27822
27806
  throw new CliUsageError(`unknown role run id: ${runId}`);
27823
27807
  }
27824
27808
  const { run, principal } = materialized;
27825
- if (!(allowUnformedAdmitted && run.state === "admitted") && !await isDurablePrincipalAvailable(principal, authority)) {
27826
- throw new CliUsageError(
27827
- `role run Pi session principal is unavailable: ${runId}`
27828
- );
27829
- }
27830
27809
  let instruction = "";
27831
27810
  let instructionEmpty = true;
27832
27811
  let attachments = [];
@@ -28103,8 +28082,8 @@ async function peekRoleRunRole(home, runId) {
28103
28082
  const run = await readRoleRunIdentity(runDirectory);
28104
28083
  return run?.role;
28105
28084
  }
28106
- async function loadResumablePublicRole(home, runId, authority, allowUnformedAdmitted = false) {
28107
- const loaded = await loadResumableRunRecord(home, runId, authority, allowUnformedAdmitted);
28085
+ async function loadResumablePublicRole(home, runId, authority) {
28086
+ const loaded = await loadResumableRunRecord(home, runId, authority);
28108
28087
  return seatLoadedResult(loaded, admitResumedRole(loaded));
28109
28088
  }
28110
28089
  function admitResumedRole(loaded) {
@@ -28396,12 +28375,6 @@ function createSessionIdentityAuthority(authority, sessionBindingFile) {
28396
28375
  }
28397
28376
  };
28398
28377
  }
28399
- function resolveHostAwareSessionAvailability(host, principalAuthority) {
28400
- if (host === void 0 || host === DEFAULT_ROLE_TURN_HOST) {
28401
- return (principal) => principalAuthority.isAvailable(principal);
28402
- }
28403
- return async (principal) => await readStoredHostSessionId(host, principalAuthority, principal) !== void 0;
28404
- }
28405
28378
  async function readStoredHostSessionId(host, authority, principal) {
28406
28379
  if (host === void 0 || host === DEFAULT_ROLE_TURN_HOST) return void 0;
28407
28380
  const description = lookupHostDescription(host) ?? lookupHeadlessHostDescription(host);
@@ -28509,9 +28482,9 @@ var init_host_session_record = __esm({
28509
28482
  // src/public-cli/auto-resume.ts
28510
28483
  import { constants as fsConstants2 } from "node:fs";
28511
28484
  import { randomUUID as randomUUID5 } from "node:crypto";
28512
- import { lstat as lstat7, mkdir as mkdir4, open as open2 } from "node:fs/promises";
28485
+ import { lstat as lstat6, mkdir as mkdir4, open as open2 } from "node:fs/promises";
28513
28486
  import { join as join33 } from "node:path";
28514
- async function persistReturnedRunState(admitted, authority, options) {
28487
+ async function persistReturnedRunState(admitted, options) {
28515
28488
  if (options?.lawful === true) {
28516
28489
  await markRunTerminal(admitted.runDirectory);
28517
28490
  return;
@@ -28521,10 +28494,8 @@ async function persistReturnedRunState(admitted, authority, options) {
28521
28494
  });
28522
28495
  const typedHttp429 = resumeObservation.typedHttp429;
28523
28496
  if (admitted.principal !== void 0 && typedHttp429 !== void 0) {
28524
- if (await authority.isAvailable(admitted.principal)) {
28525
- await markRunResumable(admitted.runDirectory, typedHttp429);
28526
- return;
28527
- }
28497
+ await markRunResumable(admitted.runDirectory, typedHttp429);
28498
+ return;
28528
28499
  }
28529
28500
  await markRunTerminal(admitted.runDirectory);
28530
28501
  }
@@ -28546,20 +28517,20 @@ async function finalizeExceptionRunBestEffort(runDirectory, io) {
28546
28517
  }
28547
28518
  }
28548
28519
  async function ensureRealArtifactsDirectory(runDirectory) {
28549
- const runStat = await lstat7(runDirectory);
28520
+ const runStat = await lstat6(runDirectory);
28550
28521
  if (runStat.isSymbolicLink() || !runStat.isDirectory()) {
28551
28522
  throw new Error("run artifact retention: run directory is not a real directory");
28552
28523
  }
28553
28524
  const artifactsDir = roleRunArtifactsDirectory(runDirectory);
28554
28525
  try {
28555
- const existing = await lstat7(artifactsDir);
28526
+ const existing = await lstat6(artifactsDir);
28556
28527
  if (existing.isSymbolicLink() || !existing.isDirectory()) {
28557
28528
  throw new Error("run artifact retention: artifacts path is not a real directory");
28558
28529
  }
28559
28530
  } catch (error) {
28560
28531
  if (!isMissingPathError5(error)) throw error;
28561
28532
  await mkdir4(artifactsDir, { recursive: true });
28562
- const created = await lstat7(artifactsDir);
28533
+ const created = await lstat6(artifactsDir);
28563
28534
  if (created.isSymbolicLink() || !created.isDirectory()) {
28564
28535
  throw new Error("run artifact retention: artifacts directory is not a real directory");
28565
28536
  }
@@ -28690,7 +28661,6 @@ function dispatchExceptionFailureTerminal(input) {
28690
28661
  async function runWithAutoResumeLoop(options) {
28691
28662
  const limit = options.autoResumeLimit ?? AUTO_RESUME_LIMIT;
28692
28663
  parseAutoResumeLimit(limit);
28693
- const isPrincipalAvailable = options.isPrincipalAvailable ?? ((principal) => options.principalAuthority.isAvailable(principal));
28694
28664
  let autoResumeAttempts = 0;
28695
28665
  let isFirst = true;
28696
28666
  let currentPayload = options.buildInitialPayload();
@@ -28698,6 +28668,9 @@ async function runWithAutoResumeLoop(options) {
28698
28668
  let lastThrownError;
28699
28669
  let everyAttemptThrew = true;
28700
28670
  const retainedErrorFiles = [];
28671
+ const failedAttempts = [];
28672
+ let stoppedResult;
28673
+ let endReason;
28701
28674
  while (true) {
28702
28675
  let result;
28703
28676
  let turnStartedBeforeThrow = false;
@@ -28706,6 +28679,11 @@ async function runWithAutoResumeLoop(options) {
28706
28679
  result = await options.dispatch(currentPayload, lease, isFirst, dummyIo);
28707
28680
  } catch (error) {
28708
28681
  lastThrownError = error;
28682
+ const failedAttempt = {
28683
+ attempt: dispatchOrdinal,
28684
+ diagnostic: describeErrorIdentity(unwrapTurnDispatchedFailure(error))
28685
+ };
28686
+ failedAttempts.push(failedAttempt);
28709
28687
  turnStartedBeforeThrow = error instanceof TurnDispatchedFailure;
28710
28688
  const attempt = dispatchOrdinal;
28711
28689
  try {
@@ -28717,6 +28695,7 @@ async function runWithAutoResumeLoop(options) {
28717
28695
  error
28718
28696
  );
28719
28697
  retainedErrorFiles.push(file);
28698
+ failedAttempt.errorFile = file;
28720
28699
  options.io.stderr(
28721
28700
  `dispatch attempt ${attempt} threw (${describeErrorIdentity(error)}); full error retained at ${file}
28722
28701
  `
@@ -28737,100 +28716,30 @@ async function runWithAutoResumeLoop(options) {
28737
28716
  dispatchOrdinal += 1;
28738
28717
  if (result !== void 0) {
28739
28718
  everyAttemptThrew = false;
28740
- const terminal = result.terminal;
28741
- if (terminal !== void 0) {
28742
- terminal.autoResumeCount = autoResumeAttempts;
28743
- }
28744
- const lawful = terminal !== void 0 && isLawfulTypedTerminalOutcome(terminal.roleOutcome);
28745
- if (lawful) {
28746
- if (terminal !== void 0) {
28747
- options.io.stdout(formatTerminalResult(terminal));
28719
+ const terminal2 = result.terminal;
28720
+ if (terminal2 !== void 0) {
28721
+ terminal2.autoResumeCount = autoResumeAttempts;
28722
+ if (terminal2.roleOutcome.kind === "failure") {
28723
+ failedAttempts.push({
28724
+ attempt: dispatchOrdinal - 1,
28725
+ diagnostic: terminal2.roleOutcome.diagnostic,
28726
+ decisiveFacts: terminal2.roleOutcome.decisiveFacts
28727
+ });
28748
28728
  }
28749
- return result;
28750
- }
28751
- if (result.skipAutoResume === true) {
28752
- if (terminal !== void 0) presentTerminal(terminal, options.io);
28753
- return result;
28754
- }
28755
- if (processCancelSignalName(options.signal) !== void 0) {
28756
- if (terminal !== void 0) presentTerminal(terminal, options.io);
28757
- return result;
28758
- }
28759
- }
28760
- if (result !== void 0) {
28761
- const terminal = result.terminal;
28762
- if (autoResumeAttempts >= limit) {
28763
- if (terminal !== void 0) presentTerminal(terminal, options.io);
28764
- return result;
28765
28729
  }
28766
- if (result.turnDispatched === true && !await isPrincipalAvailable(options.admitted.principal)) {
28767
- if (terminal !== void 0) presentTerminal(terminal, options.io);
28768
- return result;
28730
+ if (terminal2 !== void 0 && isLawfulTypedTerminalOutcome(terminal2.roleOutcome) || result.skipAutoResume === true || autoResumeAttempts >= limit || processCancelSignalName(options.signal) !== void 0) {
28731
+ stoppedResult = result;
28732
+ break;
28769
28733
  }
28770
28734
  } else {
28771
28735
  if (autoResumeAttempts >= limit) {
28772
- const terminal = await attachDispatchExceptionTerminal(
28773
- options.admitted,
28774
- dispatchExceptionFailureTerminal({
28775
- role: options.admitted.role,
28776
- runId: options.admitted.runId,
28777
- causeError: lastThrownError,
28778
- errorFiles: retainedErrorFiles,
28779
- autoResumeAttempts,
28780
- endReason: "auto-resume budget exhausted",
28781
- everyAttemptThrew
28782
- }),
28783
- options.io
28784
- );
28785
- await finalizeExceptionRunBestEffort(options.admitted.runDirectory, options.io);
28786
- presentTerminal(terminal, options.io);
28787
- return {
28788
- exitCode: 1,
28789
- terminal
28790
- };
28736
+ endReason = "auto-resume budget exhausted";
28737
+ break;
28791
28738
  }
28792
28739
  const cancelName = processCancelSignalName(options.signal);
28793
28740
  if (cancelName !== void 0) {
28794
- const terminal = await attachDispatchExceptionTerminal(
28795
- options.admitted,
28796
- dispatchExceptionFailureTerminal({
28797
- role: options.admitted.role,
28798
- runId: options.admitted.runId,
28799
- causeError: lastThrownError,
28800
- errorFiles: retainedErrorFiles,
28801
- autoResumeAttempts,
28802
- endReason: `ak-role terminated by ${cancelName}`,
28803
- everyAttemptThrew
28804
- }),
28805
- options.io
28806
- );
28807
- await finalizeExceptionRunBestEffort(options.admitted.runDirectory, options.io);
28808
- presentTerminal(terminal, options.io);
28809
- return {
28810
- exitCode: 1,
28811
- terminal
28812
- };
28813
- }
28814
- if (!await isPrincipalAvailable(options.admitted.principal)) {
28815
- const terminal = await attachDispatchExceptionTerminal(
28816
- options.admitted,
28817
- dispatchExceptionFailureTerminal({
28818
- role: options.admitted.role,
28819
- runId: options.admitted.runId,
28820
- causeError: lastThrownError,
28821
- errorFiles: retainedErrorFiles,
28822
- autoResumeAttempts,
28823
- endReason: "session principal unavailable before further resume",
28824
- everyAttemptThrew
28825
- }),
28826
- options.io
28827
- );
28828
- await finalizeExceptionRunBestEffort(options.admitted.runDirectory, options.io);
28829
- presentTerminal(terminal, options.io);
28830
- return {
28831
- exitCode: 1,
28832
- terminal
28833
- };
28741
+ endReason = `ak-role terminated by ${cancelName}`;
28742
+ break;
28834
28743
  }
28835
28744
  }
28836
28745
  autoResumeAttempts++;
@@ -28839,6 +28748,34 @@ async function runWithAutoResumeLoop(options) {
28839
28748
  isFirst = false;
28840
28749
  }
28841
28750
  }
28751
+ const terminal = stoppedResult === void 0 ? await attachDispatchExceptionTerminal(
28752
+ options.admitted,
28753
+ dispatchExceptionFailureTerminal({
28754
+ role: options.admitted.role,
28755
+ runId: options.admitted.runId,
28756
+ causeError: lastThrownError,
28757
+ errorFiles: retainedErrorFiles,
28758
+ autoResumeAttempts,
28759
+ endReason,
28760
+ everyAttemptThrew
28761
+ }),
28762
+ options.io
28763
+ ) : stoppedResult.terminal;
28764
+ if (stoppedResult === void 0) {
28765
+ await finalizeExceptionRunBestEffort(options.admitted.runDirectory, options.io);
28766
+ }
28767
+ const complete = terminal !== void 0 && failedAttempts.length > 0 ? { ...terminal, roleOutcome: {
28768
+ ...terminal.roleOutcome,
28769
+ decisiveFacts: { ...terminal.roleOutcome.decisiveFacts, failedAttempts }
28770
+ } } : terminal;
28771
+ if (complete !== void 0) {
28772
+ if (isLawfulTypedTerminalOutcome(complete.roleOutcome)) {
28773
+ options.io.stdout(formatTerminalResult(complete));
28774
+ } else {
28775
+ presentTerminal(complete, options.io);
28776
+ }
28777
+ }
28778
+ return stoppedResult === void 0 ? { exitCode: 1, terminal: complete } : { ...stoppedResult, ...complete === void 0 ? {} : { terminal: complete } };
28842
28779
  }
28843
28780
  var dummyIo, TurnDispatchedFailure, DISPATCH_ERROR_RETENTION_ENTRY_TYPE;
28844
28781
  var init_auto_resume = __esm({
@@ -29007,14 +28944,9 @@ async function presentControlledFailure2(admitted, failureInput, adapters, autho
29007
28944
  ...failureInput.knownDiagnostic === void 0 ? {} : { knownDiagnostic: failureInput.knownDiagnostic },
29008
28945
  ...session === void 0 ? {} : { session }
29009
28946
  });
29010
- let resumable = false;
29011
- const typedHttp429 = resumeObservation.typedHttp429;
29012
- if (admitted.principal !== void 0) {
29013
- const sessionPrincipalAvailable = await authority.isAvailable(admitted.principal);
29014
- resumable = sessionPrincipalAvailable && typedHttp429 !== void 0;
29015
- }
28947
+ const resumable = admitted.principal !== void 0 && resumeObservation.typedHttp429 !== void 0;
29016
28948
  if (persistRunState && !failureInput.skipRunStateWrite) {
29017
- await persistReturnedRunState(admitted, authority);
28949
+ await persistReturnedRunState(admitted);
29018
28950
  }
29019
28951
  let publishedErrorPath;
29020
28952
  let terminal;
@@ -29059,7 +28991,7 @@ async function settleDeferredPersist(admitted, authority, adapters, io, result)
29059
28991
  const { needsPersist: _needsPersist, ...settledResult } = result;
29060
28992
  const lawful = isLawfulTypedTerminalOutcome(result.terminal.roleOutcome);
29061
28993
  try {
29062
- await persistReturnedRunState(admitted, authority, lawful ? { lawful: true } : void 0);
28994
+ await persistReturnedRunState(admitted, lawful ? { lawful: true } : void 0);
29063
28995
  return settledResult;
29064
28996
  } catch (error) {
29065
28997
  const failed = await settleAfterTurnStarted(
@@ -29337,7 +29269,7 @@ async function dispatchPostAdmissionTurn(input) {
29337
29269
  }
29338
29270
  if (persistRunState) {
29339
29271
  try {
29340
- await persistReturnedRunState(admitted, env.principalAuthority, { lawful: true });
29272
+ await persistReturnedRunState(admitted, { lawful: true });
29341
29273
  } catch (error) {
29342
29274
  await recordBestEffortPostDispatchDiagnostic(
29343
29275
  admitted,
@@ -29422,7 +29354,7 @@ async function dispatchPostAdmissionTurn(input) {
29422
29354
  }
29423
29355
  if (persistRunState) {
29424
29356
  try {
29425
- await persistReturnedRunState(admitted, env.principalAuthority, { lawful: true });
29357
+ await persistReturnedRunState(admitted, { lawful: true });
29426
29358
  } catch (error) {
29427
29359
  await recordBestEffortPostDispatchDiagnostic(
29428
29360
  admitted,
@@ -29639,10 +29571,6 @@ async function runPostAdmissionSeatResume(input) {
29639
29571
  return await runWithAutoResumeLoop({
29640
29572
  admitted: loaded.admitted,
29641
29573
  principalAuthority: env.principalAuthority,
29642
- isPrincipalAvailable: resolveHostAwareSessionAvailability(
29643
- env.host,
29644
- env.principalAuthority
29645
- ),
29646
29574
  io: input.io,
29647
29575
  sessionAppender: env.sessionAppender,
29648
29576
  autoResumeLimit: env.autoResumeLimit,
@@ -29830,7 +29758,6 @@ async function runPostAdmissionResumable(input) {
29830
29758
  return runWithAutoResumeLoop({
29831
29759
  admitted,
29832
29760
  principalAuthority: env.principalAuthority,
29833
- isPrincipalAvailable: resolveHostAwareSessionAvailability(env.host, env.principalAuthority),
29834
29761
  io,
29835
29762
  sessionAppender: env.sessionAppender,
29836
29763
  autoResumeLimit: env.autoResumeLimit,
@@ -15,7 +15,7 @@ import { readRecordedSubmissionRows } from "../submission-ledger.js";
15
15
  import { readDeclaredTicketNumber } from "../run-ticket-number.js";
16
16
  import { pathContainedIn } from "../activation-ledger-topology.js";
17
17
  import { pickEngineAxis } from "../package-resources/engine-material.js";
18
- import { readStoredHostSessionId, resolveHostAwareSessionAvailability, } from "../session-identity.js";
18
+ import { readStoredHostSessionId } from "../session-identity.js";
19
19
  import { rewriteRunDirectoryPathValue } from "../role-run-relocation.js";
20
20
  import { isOfficerReviewSeat } from "../packaged-role-registry.js";
21
21
  /** Original error bytes, never relabeled — a secondary fact riding beside a classified cause. */
@@ -223,16 +223,10 @@ export async function presentControlledFailure(admitted, failureInput, adapters,
223
223
  : { knownDiagnostic: failureInput.knownDiagnostic }),
224
224
  ...(session === undefined ? {} : { session }),
225
225
  });
226
- // #665 / #416: resume hint is seat-uniform — principal available && typed 429 → show.
227
- // Do not fork the public terminal face on per-seat hasLawful / isResumableRole (ADR 0040).
228
- let resumable = false;
229
- const typedHttp429 = resumeObservation.typedHttp429;
230
- if (admitted.principal !== undefined) {
231
- const sessionPrincipalAvailable = await authority.isAvailable(admitted.principal);
232
- resumable = sessionPrincipalAvailable && typedHttp429 !== undefined;
233
- }
226
+ // #665 / #416: typed 429 with a run principal offers resume; the host decides availability.
227
+ const resumable = admitted.principal !== undefined && resumeObservation.typedHttp429 !== undefined;
234
228
  if (persistRunState && !failureInput.skipRunStateWrite) {
235
- await persistReturnedRunState(admitted, authority);
229
+ await persistReturnedRunState(admitted);
236
230
  }
237
231
  let publishedErrorPath;
238
232
  let terminal;
@@ -302,7 +296,7 @@ async function settleDeferredPersist(admitted, authority, adapters, io, result)
302
296
  const { needsPersist: _needsPersist, ...settledResult } = result;
303
297
  const lawful = isLawfulTypedTerminalOutcome(result.terminal.roleOutcome);
304
298
  try {
305
- await persistReturnedRunState(admitted, authority, lawful ? { lawful: true } : undefined);
299
+ await persistReturnedRunState(admitted, lawful ? { lawful: true } : undefined);
306
300
  return settledResult;
307
301
  }
308
302
  catch (error) {
@@ -675,7 +669,7 @@ export async function dispatchPostAdmissionTurn(input) {
675
669
  }
676
670
  if (persistRunState) {
677
671
  try {
678
- await persistReturnedRunState(admitted, env.principalAuthority, { lawful: true });
672
+ await persistReturnedRunState(admitted, { lawful: true });
679
673
  }
680
674
  catch (error) {
681
675
  await recordBestEffortPostDispatchDiagnostic(admitted, env, `run-state persistence failed beside host terminal (best-effort continue): ${describeErrorIdentity(error)}`, io);
@@ -747,7 +741,7 @@ export async function dispatchPostAdmissionTurn(input) {
747
741
  }
748
742
  if (persistRunState) {
749
743
  try {
750
- await persistReturnedRunState(admitted, env.principalAuthority, { lawful: true });
744
+ await persistReturnedRunState(admitted, { lawful: true });
751
745
  }
752
746
  catch (error) {
753
747
  await recordBestEffortPostDispatchDiagnostic(admitted, env, `run-state persistence failed beside host terminal (best-effort continue): ${describeErrorIdentity(error)}`, io);
@@ -1046,7 +1040,6 @@ export async function runPostAdmissionSeatResume(input) {
1046
1040
  return await runWithAutoResumeLoop({
1047
1041
  admitted: loaded.admitted,
1048
1042
  principalAuthority: env.principalAuthority,
1049
- isPrincipalAvailable: resolveHostAwareSessionAvailability(env.host, env.principalAuthority),
1050
1043
  io: input.io,
1051
1044
  sessionAppender: env.sessionAppender,
1052
1045
  autoResumeLimit: env.autoResumeLimit,
@@ -1237,7 +1230,6 @@ export async function runPostAdmissionResumable(input) {
1237
1230
  return runWithAutoResumeLoop({
1238
1231
  admitted,
1239
1232
  principalAuthority: env.principalAuthority,
1240
- isPrincipalAvailable: resolveHostAwareSessionAvailability(env.host, env.principalAuthority),
1241
1233
  io,
1242
1234
  sessionAppender: env.sessionAppender,
1243
1235
  autoResumeLimit: env.autoResumeLimit,
@@ -429,13 +429,6 @@ export async function clearCurrentCourt(runDirectory, expectedCourtAttemptId) {
429
429
  ...(current.resumable === undefined ? {} : { resumable: current.resumable }),
430
430
  });
431
431
  }
432
- /**
433
- * True when the host authority reports the durable principal available.
434
- * Resume must reopen this exact principal; directory-latest is not identity.
435
- */
436
- export async function isDurablePrincipalAvailable(principal, authority) {
437
- return authority.isAvailable(principal);
438
- }
439
432
  export class RunWriterLeaseHeldError extends Error {
440
433
  code = "AK_RUN_WRITER_LEASE_HELD";
441
434
  constructor(message = "role run writer lease is already held") {
@@ -932,7 +925,7 @@ function restoredTicketFields(fields) {
932
925
  : { courtTicketNumbers: fields.courtTicketNumbers }),
933
926
  };
934
927
  }
935
- async function loadResumableRunRecord(home, runId, authority, allowUnformedAdmitted = false) {
928
+ async function loadResumableRunRecord(home, runId, authority) {
936
929
  const runDirectory = await findRunDirectoryById(home, runId);
937
930
  if (runDirectory === undefined) {
938
931
  throw new CliUsageError(`unknown role run id: ${runId}`);
@@ -941,17 +934,14 @@ async function loadResumableRunRecord(home, runId, authority, allowUnformedAdmit
941
934
  if (disk === undefined) {
942
935
  throw new CliUsageError(`unknown role run id: ${runId}`);
943
936
  }
944
- // #416: removed terminal/resumable gates per owner decision "根本不要有限制" (2026-08-22).
945
- // Only the exact Pi session principal check remains as honest failure.
937
+ // #416 / #1091: removed terminal/resumable and local session-file gates.
938
+ // The load seam locates the run and recovers identity; host CLI answers continuation.
946
939
  // One authority.decode of the uninterpreted wire yields both principal and record.
947
940
  const materialized = materializeRoleRunFromDisk(disk, authority);
948
941
  if (materialized === undefined) {
949
942
  throw new CliUsageError(`unknown role run id: ${runId}`);
950
943
  }
951
944
  const { run, principal } = materialized;
952
- if (!(allowUnformedAdmitted && run.state === "admitted") && !(await isDurablePrincipalAvailable(principal, authority))) {
953
- throw new CliUsageError(`role run Pi session principal is unavailable: ${runId}`);
954
- }
955
945
  // Reconstruct admitted identity from durable run record + admitted-request.json.
956
946
  let instruction = "";
957
947
  let instructionEmpty = true;
@@ -1268,8 +1258,8 @@ export async function peekRoleRunRole(home, runId) {
1268
1258
  * selects the existing restore checks. The stored native host session id is
1269
1259
  * read on the public explicit resume seam, not from this load.
1270
1260
  */
1271
- export async function loadResumablePublicRole(home, runId, authority, allowUnformedAdmitted = false) {
1272
- const loaded = await loadResumableRunRecord(home, runId, authority, allowUnformedAdmitted);
1261
+ export async function loadResumablePublicRole(home, runId, authority) {
1262
+ const loaded = await loadResumableRunRecord(home, runId, authority);
1273
1263
  return seatLoadedResult(loaded, admitResumedRole(loaded));
1274
1264
  }
1275
1265
  /**
@@ -69,8 +69,10 @@ export function formatTerminalResult(result) {
69
69
  if (result.roleOutcome.kind === "failure") {
70
70
  lines.push(`diagnostic\t${encodeTerminalField(result.roleOutcome.diagnostic)}`);
71
71
  }
72
- if (result.roleOutcome.kind === "failure" || result.roleOutcome.kind === "no_receipt" || result.roleOutcome.kind === "audit_escalation") {
73
- const facts = result.roleOutcome.decisiveFacts ?? {};
72
+ if (result.roleOutcome.kind === "failure" || result.roleOutcome.kind === "no_receipt" || result.roleOutcome.kind === "audit_escalation" || result.roleOutcome.decisiveFacts?.failedAttempts !== undefined) {
73
+ const facts = result.roleOutcome.kind === "accepted"
74
+ ? { failedAttempts: result.roleOutcome.decisiveFacts?.failedAttempts }
75
+ : result.roleOutcome.decisiveFacts ?? {};
74
76
  for (const [key, value] of Object.entries(facts)) {
75
77
  if (value === undefined)
76
78
  continue;
@@ -31,24 +31,6 @@ export function createSessionIdentityAuthority(authority, sessionBindingFile) {
31
31
  },
32
32
  };
33
33
  }
34
- /**
35
- * Host-aware resumable-session probe (#840 P1). The shared auto-resume loop
36
- * (public-cli/auto-resume.ts) asks one question — "can this principal's turn
37
- * still be resumed" — without itself knowing which concrete host executed it.
38
- * Pi's own session.jsonl transcript (DurablePrincipalAuthority#isAvailable)
39
- * answers that only for the pi host; ACP and headless hosts persist their
40
- * resumable native session id under their own session-identity binding file
41
- * instead (#729 / #731 / #645) and never write session.jsonl, so the plain
42
- * pi check always reports them unavailable after one attempt. One lookup per
43
- * registered host family — no per-host-name branch, no per-seat whitelist.
44
- */
45
- export function resolveHostAwareSessionAvailability(host, principalAuthority) {
46
- if (host === undefined || host === DEFAULT_ROLE_TURN_HOST) {
47
- return (principal) => principalAuthority.isAvailable(principal);
48
- }
49
- // Unregistered names have no binding file: absence, not a guess at pi.
50
- return async (principal) => (await readStoredHostSessionId(host, principalAuthority, principal)) !== undefined;
51
- }
52
34
  /**
53
35
  * Native session/thread id already stored for this principal on `host`.
54
36
  * Public explicit resume reads it once and hands it to the host adapter.