@akagilnc/pi-workflow-roles 0.1.5245 → 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.
Files changed (34) hide show
  1. package/dist/acp-host/production-host.js +125 -217
  2. package/dist/headless-host/production-host.js +381 -470
  3. package/dist/host-descriptions.js +0 -2
  4. package/dist/navigator-invocation-identity.js +0 -57
  5. package/dist/navigator-public-session.js +6 -1
  6. package/dist/pi/durable-principal.js +1 -12
  7. package/dist/public-cli/auto-resume.js +59 -87
  8. package/dist/public-cli/instruction-seat-run.js +3 -3
  9. package/dist/public-cli/main.js +86 -206
  10. package/dist/public-cli/post-admission.js +7 -15
  11. package/dist/public-cli/run-lifecycle.js +5 -15
  12. package/dist/public-cli/settlement.js +10 -59
  13. package/dist/public-cli/terminal.js +4 -2
  14. package/dist/session-identity.js +0 -18
  15. package/package.json +1 -1
  16. package/src/acp-host/description.ts +0 -2
  17. package/src/acp-host/production-host.ts +0 -1
  18. package/src/acp-host/role-turn-host.ts +12 -6
  19. package/src/headless-host/role-turn-host.ts +11 -3
  20. package/src/host-contracts.ts +0 -1
  21. package/src/host-descriptions.ts +0 -2
  22. package/src/navigator-invocation-identity.ts +4 -121
  23. package/src/navigator-public-session.ts +12 -1
  24. package/src/pi/durable-principal.ts +1 -11
  25. package/src/prepared-role-turn.ts +1 -1
  26. package/src/public-cli/auto-resume.ts +67 -109
  27. package/src/public-cli/instruction-seat-run.ts +3 -3
  28. package/src/public-cli/post-admission.ts +7 -21
  29. package/src/public-cli/run-lifecycle.ts +3 -21
  30. package/src/public-cli/settlement.ts +8 -75
  31. package/src/public-cli/terminal.ts +4 -2
  32. package/src/role-envelope.ts +3 -3
  33. package/src/role-runtime.ts +23 -5
  34. package/src/session-identity.ts +0 -22
@@ -3227,8 +3227,8 @@ function formatTerminalResult(result) {
3227
3227
  `diagnostic ${encodeTerminalField(result.roleOutcome.diagnostic)}`
3228
3228
  );
3229
3229
  }
3230
- if (result.roleOutcome.kind === "failure" || result.roleOutcome.kind === "no_receipt" || result.roleOutcome.kind === "audit_escalation") {
3231
- const facts = result.roleOutcome.decisiveFacts ?? {};
3230
+ if (result.roleOutcome.kind === "failure" || result.roleOutcome.kind === "no_receipt" || result.roleOutcome.kind === "audit_escalation" || result.roleOutcome.decisiveFacts?.failedAttempts !== void 0) {
3231
+ const facts = result.roleOutcome.kind === "accepted" ? { failedAttempts: result.roleOutcome.decisiveFacts?.failedAttempts } : result.roleOutcome.decisiveFacts ?? {};
3232
3232
  for (const [key, value] of Object.entries(facts)) {
3233
3233
  if (value === void 0) continue;
3234
3234
  const rendered = typeof value === "string" ? value : JSON.stringify(value);
@@ -3486,7 +3486,6 @@ __export(durable_principal_exports, {
3486
3486
  issuePiDurablePrincipalCoordinates: () => issuePiDurablePrincipalCoordinates,
3487
3487
  piDurablePrincipalAuthority: () => piDurablePrincipalAuthority
3488
3488
  });
3489
- import { lstat } from "node:fs/promises";
3490
3489
  import { join as join11 } from "node:path";
3491
3490
  function encode(coordinates) {
3492
3491
  return coordinates;
@@ -3539,15 +3538,6 @@ var init_durable_principal = __esm({
3539
3538
  sessionDirectory: record4.sessionDirectory,
3540
3539
  sessionFile: typeof record4.sessionFile === "string" && record4.sessionFile.trim() !== "" ? record4.sessionFile : join11(record4.sessionDirectory, "session.jsonl")
3541
3540
  };
3542
- },
3543
- async isAvailable(principal) {
3544
- const { sessionFile } = this.decode(principal);
3545
- try {
3546
- const stat2 = await lstat(sessionFile);
3547
- return stat2.isFile() && !stat2.isSymbolicLink();
3548
- } catch {
3549
- return false;
3550
- }
3551
3541
  }
3552
3542
  };
3553
3543
  }
@@ -3946,7 +3936,6 @@ var init_host_descriptions = __esm({
3946
3936
  modelFlag: "--model"
3947
3937
  }),
3948
3938
  modelPassing: "argv",
3949
- boundResume: "session/load",
3950
3939
  sessionBindingFile: "grok-acp-session.json"
3951
3940
  }),
3952
3941
  /**
@@ -3964,7 +3953,6 @@ var init_host_descriptions = __esm({
3964
3953
  thinkingFlag: "--reasoning"
3965
3954
  }),
3966
3955
  modelPassing: "set_model",
3967
- boundResume: "session/load",
3968
3956
  sessionBindingFile: "hermes-acp-session.json",
3969
3957
  seatProfileSoul: Object.freeze({
3970
3958
  flag: "-p",
@@ -4986,7 +4974,7 @@ var init_uuidv7 = __esm({
4986
4974
 
4987
4975
  // src/notary-source-run.ts
4988
4976
  import { dirname as dirname9, isAbsolute as isAbsolute5, join as join14, resolve as resolve8, basename as basename5 } from "node:path";
4989
- import { lstat as lstat2, realpath as realpath3 } from "node:fs/promises";
4977
+ import { lstat, realpath as realpath3 } from "node:fs/promises";
4990
4978
  async function readRetainedIdentity(runDirectory) {
4991
4979
  try {
4992
4980
  return await readRoleRunIdentity(runDirectory);
@@ -5014,7 +5002,7 @@ async function requireRunDirectory(candidate, display) {
5014
5002
  }
5015
5003
  let stat2;
5016
5004
  try {
5017
- stat2 = await lstat2(real);
5005
+ stat2 = await lstat(real);
5018
5006
  } catch (error) {
5019
5007
  throw new NotarySourceRunError(
5020
5008
  `notary --source-run is not a readable run directory: ${display}`,
@@ -6252,7 +6240,7 @@ var init_option_definitions = __esm({
6252
6240
  import { execFileSync as execFileSync2 } from "node:child_process";
6253
6241
  import { existsSync as existsSync3 } from "node:fs";
6254
6242
  import {
6255
- lstat as lstat3,
6243
+ lstat as lstat2,
6256
6244
  mkdtemp as mkdtemp2,
6257
6245
  readFile as readFile11,
6258
6246
  realpath as realpath4,
@@ -6814,7 +6802,7 @@ async function readRegularFileAttachment(sourcePath) {
6814
6802
  const absolute = isAbsolute6(sourcePath) ? sourcePath : resolve9(sourcePath);
6815
6803
  let st;
6816
6804
  try {
6817
- st = await lstat3(absolute);
6805
+ st = await lstat2(absolute);
6818
6806
  } catch (error) {
6819
6807
  throw new CliUsageError(
6820
6808
  `attachment is not a readable regular file: ${sourcePath}`,
@@ -10894,11 +10882,6 @@ async function appendRunAttemptHistory(source, outcome) {
10894
10882
  } catch {
10895
10883
  }
10896
10884
  }
10897
- function navigatorAttendanceCorrelatedWithBoundMarker(details, attendanceIndex, terminalIndex, marker) {
10898
- if (attendanceIndex <= terminalIndex) return false;
10899
- if (details.invocationId !== marker.invocationId) return false;
10900
- return true;
10901
- }
10902
10885
  function parseNavigatorAttendanceDetails(details) {
10903
10886
  const disposition = details.disposition;
10904
10887
  const advisoryDiagnostic = typeof details.routePlaybookReadFailure === "string" ? { advisoryDiagnostic: details.routePlaybookReadFailure } : {};
@@ -11049,54 +11032,12 @@ function extractNavigatorAttendanceFact(entries) {
11049
11032
  reason: "Navigator attendance has no durable packaged role terminal"
11050
11033
  };
11051
11034
  }
11052
- let markerIndex = -1;
11053
- for (let i = terminal.index - 1; i >= 0; i -= 1) {
11035
+ for (let i = terminal.index; i < entries.length; i += 1) {
11054
11036
  const entry = entries[i];
11055
- if (entry?.type === "custom" && entry.customType === NAVIGATOR_INVOCATION_ENTRY) {
11056
- markerIndex = i;
11057
- break;
11058
- }
11059
- }
11060
- if (markerIndex < 0) {
11061
- return {
11062
- disposition: "unavailable",
11063
- source: "unknown",
11064
- reason: "Navigator attendance is uncorrelated with session invocation facts"
11065
- };
11066
- }
11067
- const marker = parseInvocationMarkerIdentity(entries[markerIndex]?.data);
11068
- if (marker === void 0) {
11069
- return {
11070
- disposition: "unavailable",
11071
- source: "unknown",
11072
- reason: "Navigator attendance is uncorrelated with session invocation facts"
11073
- };
11074
- }
11075
- for (let i = entries.length - 1; i >= 0; i -= 1) {
11076
- const entry = entries[i];
11077
- if (entry?.type === "custom_message" && entry.customType === "ak-navigator-attendance") {
11078
- const details = entry.message?.details ?? entry.details;
11079
- if (!isRecord10(details)) {
11080
- return {
11081
- disposition: "unavailable",
11082
- source: "unknown",
11083
- reason: "Navigator attendance is unparseable"
11084
- };
11085
- }
11086
- if (!navigatorAttendanceCorrelatedWithBoundMarker(
11087
- details,
11088
- i,
11089
- terminal.index,
11090
- marker
11091
- )) {
11092
- return {
11093
- disposition: "unavailable",
11094
- source: "unknown",
11095
- reason: "Navigator attendance is uncorrelated with session invocation facts"
11096
- };
11097
- }
11098
- return parseNavigatorAttendanceDetails(details);
11099
- }
11037
+ if (entry?.type !== "custom" || entry.customType !== "ak-role-submission-closure") continue;
11038
+ const details = isRecord10(entry.data) ? entry.data.navigator : void 0;
11039
+ if (!isRecord10(details)) break;
11040
+ return parseNavigatorAttendanceDetails(details);
11100
11041
  }
11101
11042
  return {
11102
11043
  disposition: "unavailable",
@@ -12205,12 +12146,6 @@ function createSessionIdentityAuthority(authority, sessionBindingFile) {
12205
12146
  }
12206
12147
  };
12207
12148
  }
12208
- function resolveHostAwareSessionAvailability(host, principalAuthority) {
12209
- if (host === void 0 || host === DEFAULT_ROLE_TURN_HOST) {
12210
- return (principal) => principalAuthority.isAvailable(principal);
12211
- }
12212
- return async (principal) => await readStoredHostSessionId(host, principalAuthority, principal) !== void 0;
12213
- }
12214
12149
  async function readStoredHostSessionId(host, authority, principal) {
12215
12150
  if (host === void 0 || host === DEFAULT_ROLE_TURN_HOST) return void 0;
12216
12151
  const description = lookupHostDescription(host) ?? lookupHeadlessHostDescription(host);
@@ -12510,9 +12445,9 @@ var init_host_session_record = __esm({
12510
12445
  // src/public-cli/auto-resume.ts
12511
12446
  import { constants as fsConstants2 } from "node:fs";
12512
12447
  import { randomUUID as randomUUID5 } from "node:crypto";
12513
- import { lstat as lstat5, mkdir as mkdir3, open } from "node:fs/promises";
12448
+ import { lstat as lstat4, mkdir as mkdir3, open } from "node:fs/promises";
12514
12449
  import { join as join28 } from "node:path";
12515
- async function persistReturnedRunState(admitted, authority, options) {
12450
+ async function persistReturnedRunState(admitted, options) {
12516
12451
  if (options?.lawful === true) {
12517
12452
  await markRunTerminal(admitted.runDirectory);
12518
12453
  return;
@@ -12522,10 +12457,8 @@ async function persistReturnedRunState(admitted, authority, options) {
12522
12457
  });
12523
12458
  const typedHttp429 = resumeObservation.typedHttp429;
12524
12459
  if (admitted.principal !== void 0 && typedHttp429 !== void 0) {
12525
- if (await authority.isAvailable(admitted.principal)) {
12526
- await markRunResumable(admitted.runDirectory, typedHttp429);
12527
- return;
12528
- }
12460
+ await markRunResumable(admitted.runDirectory, typedHttp429);
12461
+ return;
12529
12462
  }
12530
12463
  await markRunTerminal(admitted.runDirectory);
12531
12464
  }
@@ -12547,20 +12480,20 @@ async function finalizeExceptionRunBestEffort(runDirectory, io) {
12547
12480
  }
12548
12481
  }
12549
12482
  async function ensureRealArtifactsDirectory(runDirectory) {
12550
- const runStat = await lstat5(runDirectory);
12483
+ const runStat = await lstat4(runDirectory);
12551
12484
  if (runStat.isSymbolicLink() || !runStat.isDirectory()) {
12552
12485
  throw new Error("run artifact retention: run directory is not a real directory");
12553
12486
  }
12554
12487
  const artifactsDir = roleRunArtifactsDirectory(runDirectory);
12555
12488
  try {
12556
- const existing = await lstat5(artifactsDir);
12489
+ const existing = await lstat4(artifactsDir);
12557
12490
  if (existing.isSymbolicLink() || !existing.isDirectory()) {
12558
12491
  throw new Error("run artifact retention: artifacts path is not a real directory");
12559
12492
  }
12560
12493
  } catch (error) {
12561
12494
  if (!isMissingPathError5(error)) throw error;
12562
12495
  await mkdir3(artifactsDir, { recursive: true });
12563
- const created = await lstat5(artifactsDir);
12496
+ const created = await lstat4(artifactsDir);
12564
12497
  if (created.isSymbolicLink() || !created.isDirectory()) {
12565
12498
  throw new Error("run artifact retention: artifacts directory is not a real directory");
12566
12499
  }
@@ -12691,7 +12624,6 @@ function dispatchExceptionFailureTerminal(input) {
12691
12624
  async function runWithAutoResumeLoop(options) {
12692
12625
  const limit = options.autoResumeLimit ?? AUTO_RESUME_LIMIT;
12693
12626
  parseAutoResumeLimit(limit);
12694
- const isPrincipalAvailable = options.isPrincipalAvailable ?? ((principal) => options.principalAuthority.isAvailable(principal));
12695
12627
  let autoResumeAttempts = 0;
12696
12628
  let isFirst = true;
12697
12629
  let currentPayload = options.buildInitialPayload();
@@ -12699,6 +12631,9 @@ async function runWithAutoResumeLoop(options) {
12699
12631
  let lastThrownError;
12700
12632
  let everyAttemptThrew = true;
12701
12633
  const retainedErrorFiles = [];
12634
+ const failedAttempts = [];
12635
+ let stoppedResult;
12636
+ let endReason;
12702
12637
  while (true) {
12703
12638
  let result;
12704
12639
  let turnStartedBeforeThrow = false;
@@ -12707,6 +12642,11 @@ async function runWithAutoResumeLoop(options) {
12707
12642
  result = await options.dispatch(currentPayload, lease, isFirst, dummyIo);
12708
12643
  } catch (error) {
12709
12644
  lastThrownError = error;
12645
+ const failedAttempt = {
12646
+ attempt: dispatchOrdinal,
12647
+ diagnostic: describeErrorIdentity(unwrapTurnDispatchedFailure(error))
12648
+ };
12649
+ failedAttempts.push(failedAttempt);
12710
12650
  turnStartedBeforeThrow = error instanceof TurnDispatchedFailure;
12711
12651
  const attempt = dispatchOrdinal;
12712
12652
  try {
@@ -12718,6 +12658,7 @@ async function runWithAutoResumeLoop(options) {
12718
12658
  error
12719
12659
  );
12720
12660
  retainedErrorFiles.push(file);
12661
+ failedAttempt.errorFile = file;
12721
12662
  options.io.stderr(
12722
12663
  `dispatch attempt ${attempt} threw (${describeErrorIdentity(error)}); full error retained at ${file}
12723
12664
  `
@@ -12738,100 +12679,30 @@ async function runWithAutoResumeLoop(options) {
12738
12679
  dispatchOrdinal += 1;
12739
12680
  if (result !== void 0) {
12740
12681
  everyAttemptThrew = false;
12741
- const terminal = result.terminal;
12742
- if (terminal !== void 0) {
12743
- terminal.autoResumeCount = autoResumeAttempts;
12744
- }
12745
- const lawful = terminal !== void 0 && isLawfulTypedTerminalOutcome(terminal.roleOutcome);
12746
- if (lawful) {
12747
- if (terminal !== void 0) {
12748
- options.io.stdout(formatTerminalResult(terminal));
12682
+ const terminal2 = result.terminal;
12683
+ if (terminal2 !== void 0) {
12684
+ terminal2.autoResumeCount = autoResumeAttempts;
12685
+ if (terminal2.roleOutcome.kind === "failure") {
12686
+ failedAttempts.push({
12687
+ attempt: dispatchOrdinal - 1,
12688
+ diagnostic: terminal2.roleOutcome.diagnostic,
12689
+ decisiveFacts: terminal2.roleOutcome.decisiveFacts
12690
+ });
12749
12691
  }
12750
- return result;
12751
12692
  }
12752
- if (result.skipAutoResume === true) {
12753
- if (terminal !== void 0) presentTerminal(terminal, options.io);
12754
- return result;
12755
- }
12756
- if (processCancelSignalName(options.signal) !== void 0) {
12757
- if (terminal !== void 0) presentTerminal(terminal, options.io);
12758
- return result;
12759
- }
12760
- }
12761
- if (result !== void 0) {
12762
- const terminal = result.terminal;
12763
- if (autoResumeAttempts >= limit) {
12764
- if (terminal !== void 0) presentTerminal(terminal, options.io);
12765
- return result;
12766
- }
12767
- if (result.turnDispatched === true && !await isPrincipalAvailable(options.admitted.principal)) {
12768
- if (terminal !== void 0) presentTerminal(terminal, options.io);
12769
- return result;
12693
+ if (terminal2 !== void 0 && isLawfulTypedTerminalOutcome(terminal2.roleOutcome) || result.skipAutoResume === true || autoResumeAttempts >= limit || processCancelSignalName(options.signal) !== void 0) {
12694
+ stoppedResult = result;
12695
+ break;
12770
12696
  }
12771
12697
  } else {
12772
12698
  if (autoResumeAttempts >= limit) {
12773
- const terminal = await attachDispatchExceptionTerminal(
12774
- options.admitted,
12775
- dispatchExceptionFailureTerminal({
12776
- role: options.admitted.role,
12777
- runId: options.admitted.runId,
12778
- causeError: lastThrownError,
12779
- errorFiles: retainedErrorFiles,
12780
- autoResumeAttempts,
12781
- endReason: "auto-resume budget exhausted",
12782
- everyAttemptThrew
12783
- }),
12784
- options.io
12785
- );
12786
- await finalizeExceptionRunBestEffort(options.admitted.runDirectory, options.io);
12787
- presentTerminal(terminal, options.io);
12788
- return {
12789
- exitCode: 1,
12790
- terminal
12791
- };
12699
+ endReason = "auto-resume budget exhausted";
12700
+ break;
12792
12701
  }
12793
12702
  const cancelName = processCancelSignalName(options.signal);
12794
12703
  if (cancelName !== void 0) {
12795
- const terminal = await attachDispatchExceptionTerminal(
12796
- options.admitted,
12797
- dispatchExceptionFailureTerminal({
12798
- role: options.admitted.role,
12799
- runId: options.admitted.runId,
12800
- causeError: lastThrownError,
12801
- errorFiles: retainedErrorFiles,
12802
- autoResumeAttempts,
12803
- endReason: `ak-role terminated by ${cancelName}`,
12804
- everyAttemptThrew
12805
- }),
12806
- options.io
12807
- );
12808
- await finalizeExceptionRunBestEffort(options.admitted.runDirectory, options.io);
12809
- presentTerminal(terminal, options.io);
12810
- return {
12811
- exitCode: 1,
12812
- terminal
12813
- };
12814
- }
12815
- if (!await isPrincipalAvailable(options.admitted.principal)) {
12816
- const terminal = await attachDispatchExceptionTerminal(
12817
- options.admitted,
12818
- dispatchExceptionFailureTerminal({
12819
- role: options.admitted.role,
12820
- runId: options.admitted.runId,
12821
- causeError: lastThrownError,
12822
- errorFiles: retainedErrorFiles,
12823
- autoResumeAttempts,
12824
- endReason: "session principal unavailable before further resume",
12825
- everyAttemptThrew
12826
- }),
12827
- options.io
12828
- );
12829
- await finalizeExceptionRunBestEffort(options.admitted.runDirectory, options.io);
12830
- presentTerminal(terminal, options.io);
12831
- return {
12832
- exitCode: 1,
12833
- terminal
12834
- };
12704
+ endReason = `ak-role terminated by ${cancelName}`;
12705
+ break;
12835
12706
  }
12836
12707
  }
12837
12708
  autoResumeAttempts++;
@@ -12840,6 +12711,34 @@ async function runWithAutoResumeLoop(options) {
12840
12711
  isFirst = false;
12841
12712
  }
12842
12713
  }
12714
+ const terminal = stoppedResult === void 0 ? await attachDispatchExceptionTerminal(
12715
+ options.admitted,
12716
+ dispatchExceptionFailureTerminal({
12717
+ role: options.admitted.role,
12718
+ runId: options.admitted.runId,
12719
+ causeError: lastThrownError,
12720
+ errorFiles: retainedErrorFiles,
12721
+ autoResumeAttempts,
12722
+ endReason,
12723
+ everyAttemptThrew
12724
+ }),
12725
+ options.io
12726
+ ) : stoppedResult.terminal;
12727
+ if (stoppedResult === void 0) {
12728
+ await finalizeExceptionRunBestEffort(options.admitted.runDirectory, options.io);
12729
+ }
12730
+ const complete = terminal !== void 0 && failedAttempts.length > 0 ? { ...terminal, roleOutcome: {
12731
+ ...terminal.roleOutcome,
12732
+ decisiveFacts: { ...terminal.roleOutcome.decisiveFacts, failedAttempts }
12733
+ } } : terminal;
12734
+ if (complete !== void 0) {
12735
+ if (isLawfulTypedTerminalOutcome(complete.roleOutcome)) {
12736
+ options.io.stdout(formatTerminalResult(complete));
12737
+ } else {
12738
+ presentTerminal(complete, options.io);
12739
+ }
12740
+ }
12741
+ return stoppedResult === void 0 ? { exitCode: 1, terminal: complete } : { ...stoppedResult, ...complete === void 0 ? {} : { terminal: complete } };
12843
12742
  }
12844
12743
  var dummyIo, TurnDispatchedFailure, DISPATCH_ERROR_RETENTION_ENTRY_TYPE;
12845
12744
  var init_auto_resume = __esm({
@@ -13008,14 +12907,9 @@ async function presentControlledFailure2(admitted, failureInput, adapters, autho
13008
12907
  ...failureInput.knownDiagnostic === void 0 ? {} : { knownDiagnostic: failureInput.knownDiagnostic },
13009
12908
  ...session === void 0 ? {} : { session }
13010
12909
  });
13011
- let resumable = false;
13012
- const typedHttp429 = resumeObservation.typedHttp429;
13013
- if (admitted.principal !== void 0) {
13014
- const sessionPrincipalAvailable = await authority.isAvailable(admitted.principal);
13015
- resumable = sessionPrincipalAvailable && typedHttp429 !== void 0;
13016
- }
12910
+ const resumable = admitted.principal !== void 0 && resumeObservation.typedHttp429 !== void 0;
13017
12911
  if (persistRunState && !failureInput.skipRunStateWrite) {
13018
- await persistReturnedRunState(admitted, authority);
12912
+ await persistReturnedRunState(admitted);
13019
12913
  }
13020
12914
  let publishedErrorPath;
13021
12915
  let terminal;
@@ -13060,7 +12954,7 @@ async function settleDeferredPersist(admitted, authority, adapters, io, result)
13060
12954
  const { needsPersist: _needsPersist, ...settledResult } = result;
13061
12955
  const lawful = isLawfulTypedTerminalOutcome(result.terminal.roleOutcome);
13062
12956
  try {
13063
- await persistReturnedRunState(admitted, authority, lawful ? { lawful: true } : void 0);
12957
+ await persistReturnedRunState(admitted, lawful ? { lawful: true } : void 0);
13064
12958
  return settledResult;
13065
12959
  } catch (error) {
13066
12960
  const failed = await settleAfterTurnStarted(
@@ -13338,7 +13232,7 @@ async function dispatchPostAdmissionTurn(input) {
13338
13232
  }
13339
13233
  if (persistRunState) {
13340
13234
  try {
13341
- await persistReturnedRunState(admitted, env.principalAuthority, { lawful: true });
13235
+ await persistReturnedRunState(admitted, { lawful: true });
13342
13236
  } catch (error) {
13343
13237
  await recordBestEffortPostDispatchDiagnostic(
13344
13238
  admitted,
@@ -13423,7 +13317,7 @@ async function dispatchPostAdmissionTurn(input) {
13423
13317
  }
13424
13318
  if (persistRunState) {
13425
13319
  try {
13426
- await persistReturnedRunState(admitted, env.principalAuthority, { lawful: true });
13320
+ await persistReturnedRunState(admitted, { lawful: true });
13427
13321
  } catch (error) {
13428
13322
  await recordBestEffortPostDispatchDiagnostic(
13429
13323
  admitted,
@@ -13640,10 +13534,6 @@ async function runPostAdmissionSeatResume(input) {
13640
13534
  return await runWithAutoResumeLoop({
13641
13535
  admitted: loaded.admitted,
13642
13536
  principalAuthority: env.principalAuthority,
13643
- isPrincipalAvailable: resolveHostAwareSessionAvailability(
13644
- env.host,
13645
- env.principalAuthority
13646
- ),
13647
13537
  io: input.io,
13648
13538
  sessionAppender: env.sessionAppender,
13649
13539
  autoResumeLimit: env.autoResumeLimit,
@@ -13831,7 +13721,6 @@ async function runPostAdmissionResumable(input) {
13831
13721
  return runWithAutoResumeLoop({
13832
13722
  admitted,
13833
13723
  principalAuthority: env.principalAuthority,
13834
- isPrincipalAvailable: resolveHostAwareSessionAvailability(env.host, env.principalAuthority),
13835
13724
  io,
13836
13725
  sessionAppender: env.sessionAppender,
13837
13726
  autoResumeLimit: env.autoResumeLimit,
@@ -13953,7 +13842,7 @@ var init_seat_ticket_binding = __esm({
13953
13842
 
13954
13843
  // src/public-cli/machine-method-skills.ts
13955
13844
  import { accessSync, constants as constants2, statSync as statSync4 } from "node:fs";
13956
- import { lstat as lstat6, mkdir as mkdir4, symlink } from "node:fs/promises";
13845
+ import { lstat as lstat5, mkdir as mkdir4, symlink } from "node:fs/promises";
13957
13846
  import { join as join30 } from "node:path";
13958
13847
  import { spawnSync as spawnSync2 } from "node:child_process";
13959
13848
  function skillRoot(home) {
@@ -13983,7 +13872,7 @@ function linkedSkillRoot(home, host) {
13983
13872
  }
13984
13873
  async function occupied(path) {
13985
13874
  try {
13986
- await lstat6(path);
13875
+ await lstat5(path);
13987
13876
  return true;
13988
13877
  } catch (error) {
13989
13878
  if (error.code !== "ENOENT") throw error;
@@ -15068,7 +14957,7 @@ async function runPublicInstructionSeatResume(request, env, io) {
15068
14957
  };
15069
14958
  let binding;
15070
14959
  try {
15071
- const loaded = await loadResumablePublicRole(env.home, request.runId, env.principalAuthority, true);
14960
+ const loaded = await loadResumablePublicRole(env.home, request.runId, env.principalAuthority);
15072
14961
  binding = loaded.admitted.role === "auditor" ? await readAuditorResumeBinding(loaded.admitted.runDirectory) : void 0;
15073
14962
  } catch (error) {
15074
14963
  if (!(error instanceof CliUsageError)) throw error;
@@ -15111,7 +15000,7 @@ async function queueConclusionFromChild(child, env, io) {
15111
15000
  }
15112
15001
  }
15113
15002
  async function continueParentAfterChild(parentRunId, child, env, io) {
15114
- const loaded = await loadResumablePublicRole(env.home, parentRunId, env.principalAuthority, true);
15003
+ const loaded = await loadResumablePublicRole(env.home, parentRunId, env.principalAuthority);
15115
15004
  if (loaded.run.state !== "admitted" && !AUDITED_ROLES.has(loaded.admitted.role)) {
15116
15005
  return runPublicInstructionSeatResume({ runId: parentRunId }, env, io);
15117
15006
  }
@@ -15306,7 +15195,7 @@ async function auditSubmittedRole(turn, env, io, passedOfficer, passedReceipt, p
15306
15195
  const escalation = chain.passes.at(-1);
15307
15196
  const escalatedRunId = escalation?.runId ?? (escalation?.runDirectory === void 0 ? void 0 : runIdFromRunDirectory(escalation.runDirectory));
15308
15197
  if (escalatedRunId === void 0) throw new Error("escalated audit has no resumable run identity");
15309
- const officer = await loadResumablePublicRole(env.home, escalatedRunId, env.principalAuthority, true);
15198
+ const officer = await loadResumablePublicRole(env.home, escalatedRunId, env.principalAuthority);
15310
15199
  const terminal2 = await trySettlePublicSeat(officer.admitted, env.principalAuthority, void 0);
15311
15200
  if (terminal2 === void 0) throw new Error("escalated audit has no terminal result");
15312
15201
  io.stdout(formatTerminalResult(terminal2));
@@ -19251,7 +19140,6 @@ __export(run_lifecycle_exports, {
19251
19140
  describeErrorIdentity: () => describeErrorIdentity,
19252
19141
  findLatestRunIdForSeatTicket: () => findLatestRunIdForSeatTicket,
19253
19142
  findRunDirectoryById: () => findRunDirectoryById,
19254
- isDurablePrincipalAvailable: () => isDurablePrincipalAvailable,
19255
19143
  isV1ResumableProvider: () => isV1ResumableProvider,
19256
19144
  loadResumablePublicRole: () => loadResumablePublicRole,
19257
19145
  markRunAdmitted: () => markRunAdmitted,
@@ -19271,7 +19159,7 @@ __export(run_lifecycle_exports, {
19271
19159
  renderResumeCommand: () => renderResumeCommand,
19272
19160
  writeRoleRunState: () => writeRoleRunState
19273
19161
  });
19274
- import { chmod, lstat as lstat7, open as open3, readdir as readdir7, readFile as readFile21, unlink as unlink5, writeFile as writeFile9 } from "node:fs/promises";
19162
+ import { chmod, lstat as lstat6, open as open3, readdir as readdir7, readFile as readFile21, unlink as unlink5, writeFile as writeFile9 } from "node:fs/promises";
19275
19163
  import { basename as basename9, join as join38 } from "node:path";
19276
19164
  function buildAutoResumeContinuationPrompt(options) {
19277
19165
  return appendEngineSessionMaterial(
@@ -19585,9 +19473,6 @@ async function clearCurrentCourt(runDirectory, expectedCourtAttemptId) {
19585
19473
  ...current.resumable === void 0 ? {} : { resumable: current.resumable }
19586
19474
  });
19587
19475
  }
19588
- async function isDurablePrincipalAvailable(principal, authority) {
19589
- return authority.isAvailable(principal);
19590
- }
19591
19476
  function describeErrorIdentity(error) {
19592
19477
  const candidate = error;
19593
19478
  const name = typeof candidate?.name === "string" && candidate.name !== "" ? candidate.name : typeof error;
@@ -19829,7 +19714,7 @@ async function runHasFormedSessionPrincipal(runDirectory) {
19829
19714
  if (disk === void 0) return false;
19830
19715
  const sessionFile = typeof disk.principalWire.sessionFile === "string" && disk.principalWire.sessionFile.trim() !== "" ? disk.principalWire.sessionFile : join38(disk.principalWire.sessionDirectory, "session.jsonl");
19831
19716
  try {
19832
- const stat2 = await lstat7(sessionFile);
19717
+ const stat2 = await lstat6(sessionFile);
19833
19718
  return stat2.isFile() && !stat2.isSymbolicLink();
19834
19719
  } catch (error) {
19835
19720
  if (errorCodeOf(error) === "ENOENT") return false;
@@ -19921,7 +19806,7 @@ function restoredTicketFields(fields) {
19921
19806
  ...fields.courtTicketNumbers === void 0 ? {} : { courtTicketNumbers: fields.courtTicketNumbers }
19922
19807
  };
19923
19808
  }
19924
- async function loadResumableRunRecord(home, runId, authority, allowUnformedAdmitted = false) {
19809
+ async function loadResumableRunRecord(home, runId, authority) {
19925
19810
  const runDirectory = await findRunDirectoryById(home, runId);
19926
19811
  if (runDirectory === void 0) {
19927
19812
  throw new CliUsageError(`unknown role run id: ${runId}`);
@@ -19935,11 +19820,6 @@ async function loadResumableRunRecord(home, runId, authority, allowUnformedAdmit
19935
19820
  throw new CliUsageError(`unknown role run id: ${runId}`);
19936
19821
  }
19937
19822
  const { run, principal } = materialized;
19938
- if (!(allowUnformedAdmitted && run.state === "admitted") && !await isDurablePrincipalAvailable(principal, authority)) {
19939
- throw new CliUsageError(
19940
- `role run Pi session principal is unavailable: ${runId}`
19941
- );
19942
- }
19943
19823
  let instruction = "";
19944
19824
  let instructionEmpty = true;
19945
19825
  let attachments = [];
@@ -20216,8 +20096,8 @@ async function peekRoleRunRole(home, runId) {
20216
20096
  const run = await readRoleRunIdentity(runDirectory);
20217
20097
  return run?.role;
20218
20098
  }
20219
- async function loadResumablePublicRole(home, runId, authority, allowUnformedAdmitted = false) {
20220
- const loaded = await loadResumableRunRecord(home, runId, authority, allowUnformedAdmitted);
20099
+ async function loadResumablePublicRole(home, runId, authority) {
20100
+ const loaded = await loadResumableRunRecord(home, runId, authority);
20221
20101
  return seatLoadedResult(loaded, admitResumedRole(loaded));
20222
20102
  }
20223
20103
  function admitResumedRole(loaded) {
@@ -22591,9 +22471,14 @@ function createNativeNavigatorSessionFactory(deps) {
22591
22471
  }
22592
22472
  if (outcome.kind === "failure") {
22593
22473
  providerFailure = navigatorProviderFailureFromPublicTerminal(outcome);
22474
+ const failedAttempts = outcome.decisiveFacts.failedAttempts;
22475
+ const attemptReasons = Array.isArray(failedAttempts) ? failedAttempts.map((entry, index) => {
22476
+ const fact = entry !== null && typeof entry === "object" ? entry : void 0;
22477
+ return `${typeof fact?.attempt === "number" ? fact.attempt + 1 : index + 1}: ${typeof fact?.diagnostic === "string" ? fact.diagnostic : outcome.diagnostic}`;
22478
+ }) : [];
22594
22479
  throw navigatorUnavailableError(
22595
22480
  providerFailure.source,
22596
- new Error(outcome.diagnostic),
22481
+ new Error(attemptReasons.length > 0 ? attemptReasons.join("\n") : outcome.diagnostic),
22597
22482
  providerFailure.cause
22598
22483
  );
22599
22484
  }
@@ -24028,8 +23913,15 @@ async function projectClosedSubmissionLifecycle(closed, context, phase, recordAc
24028
23913
  isError: false,
24029
23914
  details: closed.accepted
24030
23915
  };
24031
- context.sessionManager.appendCustomEntry?.("ak-role-submission-closure", closure);
24032
- await settle(publicNavigatorSettlement(closed.role, phase, closure));
23916
+ let navigator;
23917
+ try {
23918
+ navigator = await settle(publicNavigatorSettlement(closed.role, phase, closure));
23919
+ } finally {
23920
+ context.sessionManager.appendCustomEntry?.("ak-role-submission-closure", {
23921
+ ...closure,
23922
+ ...navigator === void 0 ? {} : { navigator }
23923
+ });
23924
+ }
24033
23925
  }
24034
23926
  function createFiledOfficerRuntime(roleHost, spec, dependencies) {
24035
23927
  let soul;
@@ -24388,6 +24280,8 @@ function createRoleRuntimeExtension(dependencies) {
24388
24280
  let activeReviewerParent;
24389
24281
  let navigatorAttendance;
24390
24282
  let pendingNavigatorPresentation;
24283
+ let navigatorActivation = 0;
24284
+ let navigatorDeliveryClosed = false;
24391
24285
  let pendingNavigatorSettlement;
24392
24286
  let navigatorWorkContext;
24393
24287
  let navigatorSessionParent;
@@ -24440,6 +24334,7 @@ function createRoleRuntimeExtension(dependencies) {
24440
24334
  void settlePromise.catch(() => void 0);
24441
24335
  const raced = await raceNavigatorGrace(settlePromise, NAVIGATOR_POST_ROLE_GRACE_MS);
24442
24336
  if (raced.status !== "timeout") return;
24337
+ navigatorDeliveryClosed = true;
24443
24338
  if (pendingNavigatorPresentation === void 0) {
24444
24339
  const report = {
24445
24340
  disposition: "unavailable",
@@ -24464,6 +24359,7 @@ function createRoleRuntimeExtension(dependencies) {
24464
24359
  })();
24465
24360
  pendingNavigatorSettlement = pending;
24466
24361
  await pending;
24362
+ return pendingNavigatorPresentation?.event;
24467
24363
  };
24468
24364
  projectClosedSubmission = async (closed, context) => projectClosedSubmissionLifecycle(
24469
24365
  closed,
@@ -24943,6 +24839,8 @@ function createRoleRuntimeExtension(dependencies) {
24943
24839
  receiptDelivery = createReceiptDeliveryPolicy();
24944
24840
  noReceiptRecorded = false;
24945
24841
  pendingNavigatorPresentation = void 0;
24842
+ navigatorActivation += 1;
24843
+ navigatorDeliveryClosed = false;
24946
24844
  pendingNavigatorSettlement = void 0;
24947
24845
  pendingInfrastructureFailures.clear();
24948
24846
  pendingSubmissionNonPassByToolCallId.clear();
@@ -25038,6 +24936,7 @@ function createRoleRuntimeExtension(dependencies) {
25038
24936
  } catch {
25039
24937
  }
25040
24938
  }
24939
+ const activation = navigatorActivation;
25041
24940
  navigatorAttendance = await dependencies.createNavigatorAttendance({
25042
24941
  context: ctx,
25043
24942
  role: entry.role,
@@ -25048,7 +24947,9 @@ function createRoleRuntimeExtension(dependencies) {
25048
24947
  invocationId,
25049
24948
  ...contextError === void 0 ? {} : { contextError },
25050
24949
  onEvent: (navigatorEvent, report) => {
25051
- pendingNavigatorPresentation = { event: navigatorEvent, report };
24950
+ if (activation === navigatorActivation && !navigatorDeliveryClosed) {
24951
+ pendingNavigatorPresentation = { event: navigatorEvent, report };
24952
+ }
25052
24953
  }
25053
24954
  });
25054
24955
  if (navigatorWorkContext.contextError === void 0 && navigatorWorkContext.subjectProvenance !== "placeholder") {
@@ -26150,17 +26051,25 @@ function createAcpRoleTurnHost(config) {
26150
26051
  });
26151
26052
  return loadedId;
26152
26053
  };
26153
- if (request.continuation.kind === "resume" && config.boundResume === "session/load") {
26054
+ let sessionReady = true;
26055
+ if (request.continuation.kind === "resume") {
26154
26056
  const explicitHostSessionId = request.continuation.hostSessionId;
26155
26057
  const boundSessionId = explicitHostSessionId !== void 0 && explicitHostSessionId !== "" ? explicitHostSessionId : await config.sessionIdentity.load(request.principal);
26156
26058
  if (boundSessionId !== void 0 && boundSessionId !== "") {
26157
26059
  sessionId = boundSessionId;
26158
26060
  sessionId = await loadSession(boundSessionId);
26159
26061
  sessionOpened = true;
26062
+ } else {
26063
+ outcome = failure(
26064
+ "session",
26065
+ "AcpSessionFailure",
26066
+ "session-id-missing",
26067
+ void 0,
26068
+ "resume requires a bound session id"
26069
+ );
26070
+ sessionReady = false;
26160
26071
  }
26161
- }
26162
- let sessionReady = true;
26163
- if (sessionId === void 0) {
26072
+ } else {
26164
26073
  const session = await rpc("session/new", sessionBindParams);
26165
26074
  sessionId = typeof session.sessionId === "string" ? session.sessionId : void 0;
26166
26075
  if (sessionId === void 0 || sessionId === "") {
@@ -26274,7 +26183,7 @@ function createAcpRoleTurnHost(config) {
26274
26183
 
26275
26184
  // src/acp-host/seat-profile-soul.ts
26276
26185
  import { constants as constants3 } from "node:fs";
26277
- import { access as access3, copyFile, lstat as lstat8, mkdir as mkdir6, readlink, symlink as symlink2, unlink as unlink6 } from "node:fs/promises";
26186
+ import { access as access3, copyFile, lstat as lstat7, mkdir as mkdir6, readlink, symlink as symlink2, unlink as unlink6 } from "node:fs/promises";
26278
26187
  import { dirname as dirname26, join as join48, relative as relative3, resolve as resolve21 } from "node:path";
26279
26188
  function seatProfileName(spec, role) {
26280
26189
  return `${spec.namePrefix}${role}`;
@@ -26314,7 +26223,7 @@ async function ensureSeatProfileSoul(options) {
26314
26223
  const desiredLink = relative3(profileDir, soulTarget);
26315
26224
  let current;
26316
26225
  try {
26317
- const st = await lstat8(soulPath);
26226
+ const st = await lstat7(soulPath);
26318
26227
  if (st.isSymbolicLink()) {
26319
26228
  current = await readlink(soulPath);
26320
26229
  }
@@ -26352,7 +26261,6 @@ function createProductionAcpRoleTurnHost(options) {
26352
26261
  return createComposedAcpRoleTurnHost({
26353
26262
  hostName,
26354
26263
  sessionIdentity: createSessionIdentityAuthority(principalAuthority, description.sessionBindingFile),
26355
- boundResume: description.boundResume,
26356
26264
  modelPassing: description.modelPassing,
26357
26265
  roleRuntimeDependencies: createRoleRuntimeDependencies(packageRoot),
26358
26266
  async connect(request) {