@akagilnc/pi-workflow-roles 0.1.5096 → 0.1.5124

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.
@@ -14298,6 +14298,7 @@ __export(settlement_exports, {
14298
14298
  projectThrownFailureLeaf: () => projectThrownFailureLeaf,
14299
14299
  publishFailureArtifacts: () => publishFailureArtifacts,
14300
14300
  publishSeatAcceptedArtifacts: () => publishSeatAcceptedArtifacts,
14301
+ publishedFailureErrorPath: () => publishedFailureErrorPath,
14301
14302
  raceNavigatorGrace: () => raceNavigatorGrace,
14302
14303
  readCollectorInfrastructureFailure: () => readCollectorInfrastructureFailure,
14303
14304
  readEngineDetourInfrastructureFailure: () => readEngineDetourInfrastructureFailure,
@@ -14306,6 +14307,7 @@ __export(settlement_exports, {
14306
14307
  resolveAuditedRunnerFailureResolution: () => resolveAuditedRunnerFailureResolution,
14307
14308
  resolveAuditedRunnerKnownFailure: () => resolveAuditedRunnerKnownFailure,
14308
14309
  resolveControlledFailureResumeObservation: () => resolveControlledFailureResumeObservation,
14310
+ rewritePublishedFailureErrorPath: () => rewritePublishedFailureErrorPath,
14309
14311
  seatKnownFailureResolver: () => seatKnownFailureResolver,
14310
14312
  settleFailureTerminalResult: () => settleFailureTerminalResult,
14311
14313
  settleHostEndedNoReceipt: () => settleHostEndedNoReceipt,
@@ -14399,10 +14401,13 @@ function withSubmissions(terminal, submissions) {
14399
14401
  }
14400
14402
  async function attachRecordedSubmissions(admitted, terminal, scope) {
14401
14403
  void scope;
14402
- return withSubmissions(
14404
+ const result = withSubmissions(
14403
14405
  terminal,
14404
14406
  await recordedSubmissionPayloads(admitted, void 0)
14405
14407
  );
14408
+ const errorPath = privateFailureErrorPaths.get(terminal);
14409
+ if (errorPath !== void 0) privateFailureErrorPaths.set(result, errorPath);
14410
+ return result;
14406
14411
  }
14407
14412
  async function settleHostEndedNoReceipt(admitted, authority, scope) {
14408
14413
  const facts = noReceiptLifecycleFacts({
@@ -14434,6 +14439,18 @@ async function settleHostEndedNoReceipt(admitted, authority, scope) {
14434
14439
  function coordinatesFromAdmitted(authority, admitted) {
14435
14440
  return authority.decode(admitted.principal);
14436
14441
  }
14442
+ function publishedFailureErrorPath(terminal) {
14443
+ return privateFailureErrorPaths.get(terminal);
14444
+ }
14445
+ function rewritePublishedFailureErrorPath(terminal, oldRunDirectory, newRunDirectory) {
14446
+ const errorPath = privateFailureErrorPaths.get(terminal);
14447
+ if (errorPath !== void 0) {
14448
+ privateFailureErrorPaths.set(
14449
+ terminal,
14450
+ rewriteRunDirectoryPathValue(errorPath, oldRunDirectory, newRunDirectory)
14451
+ );
14452
+ }
14453
+ }
14437
14454
  function conciseChildDiagnostic(stderr, fallback) {
14438
14455
  const trimmed = stderr.trim();
14439
14456
  return trimmed.length > 0 ? stderr : fallback;
@@ -15955,7 +15972,7 @@ async function writeFailureJsonRetainingCause(preferredCandidates, uniqueFallbac
15955
15972
  error.publicationAttempts = issues;
15956
15973
  throw error;
15957
15974
  }
15958
- async function publishFailureArtifacts(admitted, failure2, authority) {
15975
+ async function publishFailureArtifacts(admitted, failure2, authority, onErrorPublished) {
15959
15976
  const { sessionDirectory, sessionFile } = coordinatesFromAdmitted(authority, admitted);
15960
15977
  const { baseDir, attempt: baseAttempt } = await resolveFailureArtifactsBase(
15961
15978
  admitted.runDirectory
@@ -16017,6 +16034,7 @@ async function publishFailureArtifacts(admitted, failure2, authority) {
16017
16034
  errorPayloadBase,
16018
16035
  priorIssues
16019
16036
  );
16037
+ onErrorPublished?.(errorWrite.path);
16020
16038
  const evidencePayload = {
16021
16039
  runId: admitted.runId,
16022
16040
  sessionDirectory,
@@ -16099,7 +16117,8 @@ async function settleFailureTerminalResult(admitted, failure2, authority, option
16099
16117
  }
16100
16118
  }
16101
16119
  const navigator = await extractNavigatorFactFromAdmittedSession(sessionFile);
16102
- const artifacts = await publishFailureArtifacts(admitted, failure2, authority);
16120
+ const artifacts = await publishFailureArtifacts(admitted, failure2, authority, options.onErrorPublished);
16121
+ const errorPath = artifacts.find((artifact) => artifact.kind === "error")?.path;
16103
16122
  const decisiveFacts = {
16104
16123
  ...failure2.cause === void 0 ? {} : { cause: failure2.cause },
16105
16124
  diagnostic: failure2.diagnostic
@@ -16121,7 +16140,7 @@ async function settleFailureTerminalResult(admitted, failure2, authority, option
16121
16140
  diagnostic: failure2.diagnostic,
16122
16141
  decisiveFacts
16123
16142
  };
16124
- return withOptionalGateProjection(
16143
+ const terminal = await withOptionalGateProjection(
16125
16144
  {
16126
16145
  roleOutcome: roleOutcome2,
16127
16146
  navigator,
@@ -16131,6 +16150,8 @@ async function settleFailureTerminalResult(admitted, failure2, authority, option
16131
16150
  sessionDirectory,
16132
16151
  detourGateContext(admitted, options)
16133
16152
  );
16153
+ if (errorPath !== void 0) privateFailureErrorPaths.set(terminal, errorPath);
16154
+ return terminal;
16134
16155
  }
16135
16156
  const roleOutcome = {
16136
16157
  kind: "failure",
@@ -16159,6 +16180,7 @@ function presentFailureTerminal(terminal, io) {
16159
16180
  }
16160
16181
  io.stdout(formatTerminalResult(terminal));
16161
16182
  if (terminal.roleOutcome.kind === "failure") {
16183
+ if (io.omitFailureStderrDiagnostic) return;
16162
16184
  io.stderr(formatFailureStderrDiagnostic({
16163
16185
  ...terminal.roleOutcome.cause === void 0 ? {} : { cause: terminal.roleOutcome.cause },
16164
16186
  diagnostic: terminal.roleOutcome.diagnostic
@@ -16207,7 +16229,7 @@ function raceNavigatorGrace(work, graceMs = NAVIGATOR_POST_ROLE_GRACE_MS, sleep2
16207
16229
  });
16208
16230
  });
16209
16231
  }
16210
- var NAVIGATOR_POST_ROLE_GRACE_MS, COLLECTOR_INFRASTRUCTURE_TOOLS, COLLECTOR_INFRASTRUCTURE_FAILURE_SPEC, ENGINE_DETOUR_INFRASTRUCTURE_FAILURE_SPEC, RUNNER_FAILURE_POLICY, ATTEMPT_HISTORY_ENTRY_TYPE, EMPTY_ARTIFACT_FACE;
16232
+ var privateFailureErrorPaths, NAVIGATOR_POST_ROLE_GRACE_MS, COLLECTOR_INFRASTRUCTURE_TOOLS, COLLECTOR_INFRASTRUCTURE_FAILURE_SPEC, ENGINE_DETOUR_INFRASTRUCTURE_FAILURE_SPEC, RUNNER_FAILURE_POLICY, ATTEMPT_HISTORY_ENTRY_TYPE, EMPTY_ARTIFACT_FACE;
16211
16233
  var init_settlement = __esm({
16212
16234
  "src/public-cli/settlement.ts"() {
16213
16235
  "use strict";
@@ -16234,9 +16256,11 @@ var init_settlement = __esm({
16234
16256
  init_navigator_invocation_identity();
16235
16257
  init_receipt_delivery_policy();
16236
16258
  init_role_run_placement();
16259
+ init_role_run_relocation();
16237
16260
  init_run_terminal_artifacts();
16238
16261
  init_invocation();
16239
16262
  init_terminal();
16263
+ privateFailureErrorPaths = /* @__PURE__ */ new WeakMap();
16240
16264
  NAVIGATOR_POST_ROLE_GRACE_MS = 1e4;
16241
16265
  COLLECTOR_INFRASTRUCTURE_TOOLS = /* @__PURE__ */ new Set([
16242
16266
  COLLECTOR_OBSERVE_TOOL,
@@ -16879,6 +16903,11 @@ function projectRelocatedTurnIdentity(request, result, admitted, relocation) {
16879
16903
  }
16880
16904
  }
16881
16905
  if (result.terminal !== void 0) {
16906
+ rewritePublishedFailureErrorPath(
16907
+ result.terminal,
16908
+ relocation.oldRunDirectory,
16909
+ relocation.newRunDirectory
16910
+ );
16882
16911
  for (const artifact of result.terminal.artifacts) {
16883
16912
  artifact.path = rewrite(artifact.path);
16884
16913
  }
@@ -16992,18 +17021,23 @@ async function presentControlledFailure2(admitted, failureInput, adapters, autho
16992
17021
  if (persistRunState && !failureInput.skipRunStateWrite) {
16993
17022
  await persistReturnedRunState(admitted, authority);
16994
17023
  }
16995
- const terminal = await attachRecordedSubmissions(
16996
- admitted,
16997
- await settleFailureTerminalResult(
16998
- admitted,
16999
- failure2,
17000
- authority,
17001
- {
17002
- ...resumable ? { resume: { command: renderResumeCommand(admitted.runId) } } : {},
17003
- ...failureInput.invocationScopeId === void 0 || failureInput.invocationScopeId.length === 0 ? {} : { invocationScopeId: failureInput.invocationScopeId }
17024
+ let publishedErrorPath;
17025
+ let terminal;
17026
+ try {
17027
+ const settled = await settleFailureTerminalResult(admitted, failure2, authority, {
17028
+ ...resumable ? { resume: { command: renderResumeCommand(admitted.runId) } } : {},
17029
+ ...failureInput.invocationScopeId === void 0 || failureInput.invocationScopeId.length === 0 ? {} : { invocationScopeId: failureInput.invocationScopeId },
17030
+ onErrorPublished: (path) => {
17031
+ publishedErrorPath = path;
17004
17032
  }
17005
- )
17006
- );
17033
+ });
17034
+ terminal = await attachRecordedSubmissions(admitted, settled);
17035
+ } catch (error) {
17036
+ if (io.omitFailureStderrDiagnostic && publishedErrorPath !== void 0) {
17037
+ writeResumeFailurePointer(io, publishedErrorPath);
17038
+ }
17039
+ throw error;
17040
+ }
17007
17041
  presentFailureTerminal(terminal, io);
17008
17042
  return {
17009
17043
  exitCode: exitCodeForTerminalOutcome(terminal.roleOutcome),
@@ -17097,7 +17131,10 @@ async function dispatchPostAdmissionTurn(input) {
17097
17131
  if (relocation !== void 0) {
17098
17132
  projectRelocatedTurnIdentity(request, result, admitted, relocation);
17099
17133
  }
17100
- if (adapters.afterDispatch !== void 0) await adapters.afterDispatch(admitted, lease);
17134
+ const afterDispatchRelocation = adapters.afterDispatch === void 0 ? void 0 : await adapters.afterDispatch(admitted, lease);
17135
+ if (afterDispatchRelocation !== void 0) {
17136
+ projectRelocatedTurnIdentity(request, result, admitted, afterDispatchRelocation);
17137
+ }
17101
17138
  return result;
17102
17139
  } catch (error) {
17103
17140
  if (result.terminal !== void 0) {
@@ -17544,16 +17581,28 @@ async function runPostAdmissionSeatResume(input) {
17544
17581
  try {
17545
17582
  loaded = await input.load(request);
17546
17583
  } catch (error) {
17547
- if (error instanceof CliUsageError) {
17548
- presentStructuralRejection(error, input.io);
17549
- return { exitCode: 2 };
17584
+ const usageError = error instanceof CliUsageError;
17585
+ const recorded = await pointExistingRunFailure(
17586
+ input.env.home,
17587
+ request.runId,
17588
+ input.env.principalAuthority,
17589
+ input.io,
17590
+ error
17591
+ );
17592
+ if (!recorded) {
17593
+ if (usageError) {
17594
+ presentStructuralRejection(error, input.io);
17595
+ return { exitCode: 2 };
17596
+ }
17597
+ throw error;
17550
17598
  }
17551
- throw error;
17599
+ return { exitCode: usageError ? 2 : 1 };
17552
17600
  }
17553
17601
  let adapters = input.adapters;
17554
17602
  if (input.afterAdmittedLoad !== void 0) {
17555
17603
  const prepared = await input.afterAdmittedLoad(loaded.admitted);
17556
17604
  if (prepared.kind === "terminal") {
17605
+ showResumeErrorPointer(input.io, prepared.exitCode, prepared.terminal);
17557
17606
  return {
17558
17607
  exitCode: prepared.exitCode,
17559
17608
  admitted: prepared.admitted,
@@ -17679,22 +17728,110 @@ async function runPostAdmissionSeatResume(input) {
17679
17728
  })
17680
17729
  });
17681
17730
  }
17682
- return await runPostAdmissionManualResume({
17731
+ const resumed = await runPostAdmissionManualResume({
17683
17732
  admitted: loaded.admitted,
17684
17733
  env,
17685
- io: input.io,
17734
+ io: { ...input.io, omitFailureStderrDiagnostic: true },
17686
17735
  adapters,
17687
17736
  ...input.effectiveEngine === void 0 ? {} : { effectiveEngine: input.effectiveEngine },
17688
17737
  buildRequestAfterLease
17689
17738
  });
17739
+ showResumeErrorPointer(input.io, resumed.exitCode, resumed.terminal);
17740
+ return resumed;
17690
17741
  } catch (error) {
17691
- if (error instanceof CliUsageError) {
17692
- presentStructuralRejection(error, input.io);
17693
- return { exitCode: 2 };
17742
+ if (error instanceof TurnDispatchedFailure) throw error;
17743
+ await presentResumeFailurePointer(
17744
+ input.io,
17745
+ error,
17746
+ (failure2) => writeResumeDiagnosticFile(
17747
+ loaded.admitted.runDirectory,
17748
+ loaded.admitted.runId,
17749
+ failure2,
17750
+ loaded.admitted.role
17751
+ )
17752
+ );
17753
+ return { exitCode: error instanceof CliUsageError ? 2 : 1 };
17754
+ }
17755
+ }
17756
+ async function pointExistingRunFailure(home, runId, authority, io, thrown) {
17757
+ let foundRunDirectory;
17758
+ try {
17759
+ foundRunDirectory = await findRunDirectoryById(home, runId);
17760
+ } catch {
17761
+ return false;
17762
+ }
17763
+ if (foundRunDirectory === void 0) return false;
17764
+ const runDirectory = foundRunDirectory;
17765
+ let record4;
17766
+ try {
17767
+ record4 = await readRoleRunState(runDirectory, authority);
17768
+ } catch {
17769
+ await presentResumeFailurePointer(
17770
+ io,
17771
+ thrown,
17772
+ (failure2) => writeResumeDiagnosticFile(runDirectory, runId, failure2)
17773
+ );
17774
+ return true;
17775
+ }
17776
+ if (record4 === void 0) return false;
17777
+ await presentResumeFailurePointer(
17778
+ io,
17779
+ thrown,
17780
+ (failure2) => writeResumeDiagnosticFile(runDirectory, runId, failure2, record4.role)
17781
+ );
17782
+ return true;
17783
+ }
17784
+ async function presentLocatedResumeFailure(home, runId, authority, io, thrown) {
17785
+ return await pointExistingRunFailure(home, runId, authority, io, thrown);
17786
+ }
17787
+ function writeResumeFailurePointer(io, errorPath) {
17788
+ io.stderr(formatCliDiagnostic(`\u7EED\u8DD1\u5931\u8D25\uFF0C\u5F53\u6B21\u9519\u8BEF\u8BB0\u5F55\uFF1A${errorPath}`));
17789
+ }
17790
+ function showResumeErrorPointer(io, exitCode, terminal) {
17791
+ if (exitCode === 0 || terminal === void 0) return;
17792
+ const publishedError = terminal.artifacts.find((artifact) => artifact.kind === "error")?.path ?? publishedFailureErrorPath(terminal);
17793
+ if (publishedError !== void 0) writeResumeFailurePointer(io, publishedError);
17794
+ }
17795
+ async function presentResumeFailurePointer(io, thrown, publish) {
17796
+ const failure2 = classifyPostAdmissionFailure({
17797
+ timedOut: false,
17798
+ code: null,
17799
+ stderr: "",
17800
+ thrown
17801
+ });
17802
+ try {
17803
+ writeResumeFailurePointer(io, await publish(failure2));
17804
+ } catch (publishError) {
17805
+ const cause = {
17806
+ publishError: formatErrorCauseDetail(publishError)
17807
+ };
17808
+ if (thrown instanceof Error && thrown.cause !== void 0) {
17809
+ cause.thrownCause = formatErrorCauseDetail(thrown.cause);
17694
17810
  }
17695
- throw error;
17811
+ presentStructuralRejection({
17812
+ message: thrown instanceof Error ? thrown.message : String(thrown),
17813
+ cause
17814
+ }, io);
17696
17815
  }
17697
17816
  }
17817
+ async function writeResumeDiagnosticFile(runDirectory, runId, failure2, role) {
17818
+ const dir = await ensureRealArtifactsDirectory(runDirectory);
17819
+ const path = join31(dir, `resume-diagnostic-${randomUUID6()}.json`);
17820
+ await writeFile9(
17821
+ path,
17822
+ `${JSON.stringify({
17823
+ runId,
17824
+ ...role === void 0 ? {} : { role },
17825
+ diagnostic: failure2.diagnostic,
17826
+ ...failure2.cause === void 0 ? {} : { cause: failure2.cause },
17827
+ ...failure2.identity === void 0 ? {} : { identity: failure2.identity },
17828
+ ...failure2.details === void 0 ? {} : { details: failure2.details }
17829
+ }, null, 2)}
17830
+ `,
17831
+ { encoding: "utf8", flag: "wx" }
17832
+ );
17833
+ return path;
17834
+ }
17698
17835
  async function runPostAdmissionOneShot(input) {
17699
17836
  return await runPostAdmissionResumable({
17700
17837
  admitted: input.admitted,
@@ -18325,11 +18462,11 @@ function isBoardTicketSeat(seat) {
18325
18462
  }
18326
18463
  async function bindAndRelocateDiarist(admitted, authority, lease) {
18327
18464
  const boardTicket = await readBoardTicketNumber(admitted.runDirectory);
18328
- if (boardTicket === void 0) return;
18465
+ if (boardTicket === void 0) return void 0;
18329
18466
  if (admitted.ticketNumber === void 0) {
18330
18467
  await bindAdmittedTicketNumber(admitted, boardTicket);
18331
18468
  }
18332
- await relocateAdmittedRunToTicket(admitted, authority, lease);
18469
+ return await relocateAdmittedRunToTicket(admitted, authority, lease);
18333
18470
  }
18334
18471
  function seatAdapters(admitted, env) {
18335
18472
  const record4 = roleRecord(admitted.role);
@@ -18348,8 +18485,8 @@ function seatAdapters(admitted, env) {
18348
18485
  await bindAndRelocateDiarist(seat, env.principalAuthority, lease);
18349
18486
  },
18350
18487
  afterDispatch: async (seat, lease) => {
18351
- if (!isBoardTicketSeat(seat)) return;
18352
- await bindAndRelocateDiarist(seat, env.principalAuthority, lease);
18488
+ if (!isBoardTicketSeat(seat)) return void 0;
18489
+ return await bindAndRelocateDiarist(seat, env.principalAuthority, lease);
18353
18490
  }
18354
18491
  } : {}
18355
18492
  };
@@ -18911,7 +19048,9 @@ async function continueParentAfterChild(parentRunId, child, env, io) {
18911
19048
  return { exitCode: 0, admitted, terminal: refresh.terminal };
18912
19049
  }
18913
19050
  }
18914
- return dispatchAdmitted(admitted, env, io);
19051
+ const result = await dispatchAdmitted(admitted, env, { ...io, omitFailureStderrDiagnostic: true });
19052
+ showResumeErrorPointer(io, result.exitCode, result.terminal);
19053
+ return result;
18915
19054
  }
18916
19055
  var init_instruction_seat_run = __esm({
18917
19056
  "src/public-cli/instruction-seat-run.ts"() {
@@ -21778,6 +21917,7 @@ function commandNeedsProcessCancel(argv) {
21778
21917
  }
21779
21918
  async function runAkRole(argv, env) {
21780
21919
  const io = env.io ?? defaultIo();
21920
+ let resumeFailureContext;
21781
21921
  try {
21782
21922
  env = {
21783
21923
  ...env,
@@ -21850,11 +21990,16 @@ async function runAkRole(argv, env) {
21850
21990
  env = { ...env, freshSummons: true };
21851
21991
  }
21852
21992
  if (parsed.command === "resume") {
21993
+ const resumeRequest = parseResumeRequest(parsed.args);
21994
+ resumeFailureContext = {
21995
+ home,
21996
+ runId: resumeRequest.runId,
21997
+ authority: env.principalAuthority ?? piDurablePrincipalAuthority
21998
+ };
21853
21999
  const agentDir = resolveAgentDir(env, home);
21854
22000
  const cwd = env.cwd ?? process.cwd();
21855
22001
  const config = await loadAndValidateConfig(home, env.packageRoot);
21856
22002
  const credentials = env.credentials ?? await loadCredentialProviders(agentDir);
21857
- const resumeRequest = parseResumeRequest(parsed.args);
21858
22003
  const resumeRole = await peekRoleRunRole(home, resumeRequest.runId);
21859
22004
  const seatRole = resumeRole ?? "judge";
21860
22005
  const seat = resolveEffectiveSeat(
@@ -21879,6 +22024,11 @@ async function runAkRole(argv, env) {
21879
22024
  let current = result;
21880
22025
  while (current.exitCode === 0 && current.admitted?.correlationId !== void 0 && current.terminal?.roleOutcome.kind === "accepted" && !courtDiaristEscalated(current.terminal.roleOutcome)) {
21881
22026
  const parentRunId = current.admitted.correlationId;
22027
+ resumeFailureContext = {
22028
+ home,
22029
+ runId: parentRunId,
22030
+ authority: env.principalAuthority ?? piDurablePrincipalAuthority
22031
+ };
21882
22032
  const parentRole = await peekRoleRunRole(home, parentRunId);
21883
22033
  if (parentRole === void 0) break;
21884
22034
  const parentSeat = resolveEffectiveSeat(config, parentRole, credentials, invocationFromParsed(parsed));
@@ -21921,6 +22071,18 @@ async function runAkRole(argv, env) {
21921
22071
  }
21922
22072
  throw new CliUsageError(`unknown command: ${parsed.command}`);
21923
22073
  } catch (error) {
22074
+ if (resumeFailureContext !== void 0 && !(error instanceof TurnDispatchedFailure) && await presentLocatedResumeFailure(
22075
+ resumeFailureContext.home,
22076
+ resumeFailureContext.runId,
22077
+ resumeFailureContext.authority,
22078
+ io,
22079
+ error
22080
+ )) {
22081
+ return {
22082
+ exitCode: error instanceof CliUsageError ? 2 : 1,
22083
+ ...error instanceof HostSelectionError ? { hostFailure: error.failure } : {}
22084
+ };
22085
+ }
21924
22086
  if (error instanceof HostSelectionError) {
21925
22087
  io.stderr(formatCliDiagnostic(formatHostSelectionFailure(error.failure)));
21926
22088
  return { exitCode: 1, hostFailure: error.failure };
@@ -21958,10 +22120,12 @@ var init_cli = __esm({
21958
22120
  init_registry();
21959
22121
  init_cli_errors();
21960
22122
  init_machine_method_skills();
22123
+ init_post_admission();
21961
22124
  init_role_turn_host();
21962
22125
  init_role_turn_host_resolution();
21963
22126
  init_invocation();
21964
22127
  init_option_definitions();
22128
+ init_auto_resume();
21965
22129
  init_instruction_seat_run();
21966
22130
  init_countersign_run();
21967
22131
  init_analyst_run();
@@ -13,10 +13,12 @@ import { packagedModelParent } from "../packaged-role-registry.js";
13
13
  import { seatModelOnly } from "./registry.js";
14
14
  import { CliUsageError } from "./cli-errors.js";
15
15
  import { runMachineSkillSetup } from "./machine-method-skills.js";
16
+ import { presentLocatedResumeFailure, } from "./post-admission.js";
16
17
  import { appendPiSessionCustomEntry } from "../pi/role-turn-host.js";
17
18
  import { composeRoleTurnHostAdapters, formatHostSelectionFailure, HostSelectionError, selectRoleTurnHost, } from "./role-turn-host-resolution.js";
18
19
  import { parseAnalystArgv, parsePublicSeatArgv, } from "./invocation.js";
19
20
  import { createTypedOptionConsumer, optionsForOwner, projectCommandHelp, projectOwnerOptions, PUBLIC_NAVIGATOR_HELP_NOTE, PUBLIC_ROLE_OPTION_OWNERS, renderHumanOwnerOptionLines, } from "./option-definitions.js";
21
+ import { TurnDispatchedFailure } from "./auto-resume.js";
20
22
  import { continueParentAfterChild, runPublicInstructionSeat, runPublicInstructionSeatResume } from "./instruction-seat-run.js";
21
23
  import { courtDiaristEscalated } from "./countersign-run.js";
22
24
  import { runPublicAnalyst } from "./analyst-run.js";
@@ -727,6 +729,7 @@ export function commandNeedsProcessCancel(argv) {
727
729
  }
728
730
  export async function runAkRole(argv, env) {
729
731
  const io = env.io ?? defaultIo();
732
+ let resumeFailureContext;
730
733
  try {
731
734
  // Select the installed package identity once, before any role-owned Skill,
732
735
  // runtime entry, activation argv, or invocation provenance is derived.
@@ -820,11 +823,16 @@ export async function runAkRole(argv, env) {
820
823
  // must still exist. Seat and dispatch follow the durable admitted role.
821
824
  // #471: unique parser owns {runId, message?}; five role paths only consume it.
822
825
  if (parsed.command === "resume") {
826
+ const resumeRequest = parseResumeRequest(parsed.args);
827
+ resumeFailureContext = {
828
+ home,
829
+ runId: resumeRequest.runId,
830
+ authority: env.principalAuthority ?? piDurablePrincipalAuthority,
831
+ };
823
832
  const agentDir = resolveAgentDir(env, home);
824
833
  const cwd = env.cwd ?? process.cwd();
825
834
  const config = await loadAndValidateConfig(home, env.packageRoot);
826
835
  const credentials = env.credentials ?? (await loadCredentialProviders(agentDir));
827
- const resumeRequest = parseResumeRequest(parsed.args);
828
836
  const resumeRole = await peekRoleRunRole(home, resumeRequest.runId);
829
837
  // Missing durable role keeps the judge seat table. The resume entry
830
838
  // itself is one function; it reads the stored run.
@@ -844,6 +852,11 @@ export async function runAkRole(argv, env) {
844
852
  && current.terminal?.roleOutcome.kind === "accepted"
845
853
  && !courtDiaristEscalated(current.terminal.roleOutcome)) {
846
854
  const parentRunId = current.admitted.correlationId;
855
+ resumeFailureContext = {
856
+ home,
857
+ runId: parentRunId,
858
+ authority: env.principalAuthority ?? piDurablePrincipalAuthority,
859
+ };
847
860
  const parentRole = await peekRoleRunRole(home, parentRunId);
848
861
  if (parentRole === undefined)
849
862
  break;
@@ -875,6 +888,16 @@ export async function runAkRole(argv, env) {
875
888
  throw new CliUsageError(`unknown command: ${parsed.command}`);
876
889
  }
877
890
  catch (error) {
891
+ // A dispatched turn owns its settlement; only pre-dispatch resume failures
892
+ // fall through to the located-run diagnostic presenter here.
893
+ if (resumeFailureContext !== undefined
894
+ && !(error instanceof TurnDispatchedFailure)
895
+ && await presentLocatedResumeFailure(resumeFailureContext.home, resumeFailureContext.runId, resumeFailureContext.authority, io, error)) {
896
+ return {
897
+ exitCode: error instanceof CliUsageError ? 2 : 1,
898
+ ...(error instanceof HostSelectionError ? { hostFailure: error.failure } : {}),
899
+ };
900
+ }
878
901
  if (error instanceof HostSelectionError) {
879
902
  io.stderr(formatCliDiagnostic(formatHostSelectionFailure(error.failure)));
880
903
  return { exitCode: 1, hostFailure: error.failure };
@@ -12,7 +12,7 @@ import { packagedAdmitsCountersign, packagedBindsBoardTicket, packagedRebindSour
12
12
  import { isAuditorSoulRole } from "../auditor-soul.js";
13
13
  import { CliUsageError } from "./cli-errors.js";
14
14
  import { admitPublicRole, bindAdmittedTicketNumber, bindCourtTicketNumbersOnAdmitted, buildInstructionTransportPrompt, materializeCountersignInvocation, persistAdmittedSourceRunPath, recordAdmittedCorrelation, recordChildDiaristRun, relocateAdmittedRunToTicket, withPreparedAttachments, } from "./invocation.js";
15
- import { presentControlledFailure, prepareSummonsResumeMaterials, roleTurnOptions, runPostAdmissionOneShot, runPostAdmissionResumable, runPostAdmissionSeatResume, resumeTurnRequestProjectionOptions, } from "./post-admission.js";
15
+ import { presentControlledFailure, prepareSummonsResumeMaterials, roleTurnOptions, runPostAdmissionOneShot, runPostAdmissionResumable, runPostAdmissionSeatResume, showResumeErrorPointer, resumeTurnRequestProjectionOptions, } from "./post-admission.js";
16
16
  import { buildAutoResumeContinuationPrompt, loadResumablePublicRole, markRunAdmitted, parentRunPathFromGatePointerInstruction, } from "./run-lifecycle.js";
17
17
  import { tryResumeSameTicketSeatRun } from "./seat-ticket-binding.js";
18
18
  import { presentStructuralRejection, seatKnownFailureResolver, trySettlePublicSeat, } from "./settlement.js";
@@ -52,11 +52,11 @@ function isBoardTicketSeat(seat) {
52
52
  async function bindAndRelocateDiarist(admitted, authority, lease) {
53
53
  const boardTicket = await readBoardTicketNumber(admitted.runDirectory);
54
54
  if (boardTicket === undefined)
55
- return;
55
+ return undefined;
56
56
  if (admitted.ticketNumber === undefined) {
57
57
  await bindAdmittedTicketNumber(admitted, boardTicket);
58
58
  }
59
- await relocateAdmittedRunToTicket(admitted, authority, lease);
59
+ return await relocateAdmittedRunToTicket(admitted, authority, lease);
60
60
  }
61
61
  function seatAdapters(admitted, env) {
62
62
  const record = roleRecord(admitted.role);
@@ -80,8 +80,8 @@ function seatAdapters(admitted, env) {
80
80
  },
81
81
  afterDispatch: async (seat, lease) => {
82
82
  if (!isBoardTicketSeat(seat))
83
- return;
84
- await bindAndRelocateDiarist(seat, env.principalAuthority, lease);
83
+ return undefined;
84
+ return await bindAndRelocateDiarist(seat, env.principalAuthority, lease);
85
85
  },
86
86
  }
87
87
  : {}),
@@ -655,5 +655,7 @@ export async function continueParentAfterChild(parentRunId, child, env, io) {
655
655
  return { exitCode: 0, admitted, terminal: refresh.terminal };
656
656
  }
657
657
  }
658
- return dispatchAdmitted(admitted, env, io);
658
+ const result = await dispatchAdmitted(admitted, env, { ...io, omitFailureStderrDiagnostic: true });
659
+ showResumeErrorPointer(io, result.exitCode, result.terminal);
660
+ return result;
659
661
  }