@akagilnc/pi-workflow-roles 0.1.5797 → 0.1.5820

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 (80) hide show
  1. package/dist/acp-host/production-host.js +464 -355
  2. package/dist/acp-host/role-turn-host.js +484 -0
  3. package/dist/activation-ledger-session.js +105 -0
  4. package/dist/activation-ledger.js +8 -0
  5. package/dist/activation-trace.js +33 -0
  6. package/dist/audit-escalation.js +7 -0
  7. package/dist/audited-run-identity.js +21 -0
  8. package/dist/auditor-role.js +7 -0
  9. package/dist/book-topology-migration-placement.js +404 -0
  10. package/dist/book-topology-migration.js +125 -0
  11. package/dist/book-topology-migrators-t11.js +677 -0
  12. package/dist/book-topology-mixed-volume-migrators.js +322 -0
  13. package/dist/book-topology-partition-migrators.js +23 -0
  14. package/dist/book-topology-record-class-migrators.js +671 -0
  15. package/dist/book-topology-runs-migrator.js +272 -0
  16. package/dist/collector-role.js +109 -0
  17. package/dist/compliance-transport.js +5 -3
  18. package/dist/countersign-role.js +17 -0
  19. package/dist/diarist-role.js +8 -0
  20. package/dist/diarist.js +15 -0
  21. package/dist/doctor-role.js +80 -0
  22. package/dist/engine-detour-tool.js +51 -37
  23. package/dist/engine-detour.js +22 -11
  24. package/dist/factory-board.js +1478 -0
  25. package/dist/fixer-bash-seatbelt.js +13 -0
  26. package/dist/gatekeeper-role.js +1 -2
  27. package/dist/gh-api-runner.js +81 -0
  28. package/dist/gleaner-left-role.js +8 -0
  29. package/dist/headless-host/production-host.js +464 -355
  30. package/dist/headless-host/role-turn-host.js +691 -0
  31. package/dist/human-format.js +67 -0
  32. package/dist/inspector-role.js +12 -0
  33. package/dist/judge-recording-anti-forge.js +39 -0
  34. package/dist/judge-role.js +21 -3
  35. package/dist/merger-role.js +57 -0
  36. package/dist/migrate-book-topology.js +0 -2
  37. package/dist/navigator-role.js +6 -0
  38. package/dist/navigator-work-context.js +72 -0
  39. package/dist/notary-role.js +113 -0
  40. package/dist/oauth-keepalive.js +149 -0
  41. package/dist/package-contracts/terminating-infrastructure.js +0 -35
  42. package/dist/pi/adapter.js +272 -0
  43. package/dist/public-cli/cli.js +9 -3
  44. package/dist/public-cli/instruction-seat-run.js +163 -44
  45. package/dist/public-cli/main.js +241 -123
  46. package/dist/report-ticket-tool.js +24 -13
  47. package/dist/reviewer-role.js +33 -0
  48. package/dist/role-envelope.js +707 -0
  49. package/dist/role-runtime-dependencies.js +57 -0
  50. package/dist/role-runtime.js +1476 -0
  51. package/dist/secretariat-role.js +5 -0
  52. package/dist/stderr-jsonl.js +26 -0
  53. package/dist/submission-correctable-error.js +2 -6
  54. package/dist/submission-errors.js +0 -30
  55. package/dist/submission-gate.js +61 -54
  56. package/dist/submission-ledger.js +105 -98
  57. package/dist/ticket-snapshot.js +486 -0
  58. package/dist/ticket-trajectory.js +843 -0
  59. package/dist/worker-role.js +184 -0
  60. package/dist/worker-submission-gates.js +333 -0
  61. package/package.json +1 -1
  62. package/resources/engine-dispatch.md +6 -6
  63. package/resources/engines/agy.md +1 -1
  64. package/src/compliance-transport.ts +7 -3
  65. package/src/engine-detour-tool.ts +88 -57
  66. package/src/engine-detour.ts +31 -14
  67. package/src/gatekeeper-role.ts +1 -15
  68. package/src/host-contracts.ts +9 -12
  69. package/src/judge-role.ts +30 -7
  70. package/src/package-contracts/terminating-infrastructure.ts +8 -81
  71. package/src/pi/adapter.ts +0 -1
  72. package/src/public-cli/cli.ts +21 -14
  73. package/src/public-cli/instruction-seat-run.ts +227 -44
  74. package/src/report-ticket-tool.ts +27 -13
  75. package/src/role-envelope.ts +35 -35
  76. package/src/role-runtime.ts +63 -56
  77. package/src/submission-correctable-error.ts +1 -6
  78. package/src/submission-errors.ts +0 -34
  79. package/src/submission-gate.ts +71 -56
  80. package/src/submission-ledger.ts +109 -104
@@ -1425,18 +1425,29 @@ async function runEngineDetourOnce(input) {
1425
1425
  function isEngineDetourFailure(result) {
1426
1426
  return result.code !== 0 || result.stdout.trim() === "";
1427
1427
  }
1428
- function engineDetourFailureDiagnostic(result) {
1429
- if (result.stderr.trim().length > 0) return result.stderr;
1430
- if (result.stdout.trim() === "") return ENGINE_DETOUR_EMPTY_STDOUT_DIAGNOSTIC;
1431
- const rows = result.stdout.split("\n");
1432
- let lastRow = "";
1433
- for (let index = rows.length - 1; index >= 0; index -= 1) {
1434
- if (rows[index].trim() !== "") {
1435
- lastRow = rows[index];
1436
- break;
1437
- }
1428
+ function engineDetourFailureSeatText(result) {
1429
+ const parts = [];
1430
+ if (result.stdout.length > 0) parts.push(result.stdout);
1431
+ if (result.stderr.length > 0) parts.push(result.stderr);
1432
+ let text = "";
1433
+ if (parts.length > 0) {
1434
+ text = parts[0];
1435
+ for (let index = 1; index < parts.length; index += 1) {
1436
+ if (!text.endsWith("\n")) text += "\n";
1437
+ text += parts[index];
1438
+ }
1439
+ }
1440
+ const append = (line2) => {
1441
+ if (text.length > 0 && !text.endsWith("\n")) text += "\n";
1442
+ text += line2;
1443
+ };
1444
+ if (result.code !== 0) {
1445
+ append(`\u52B3\u52A1\u5F15\u64CE\u4EE5 code ${result.code} \u9000\u51FA`);
1446
+ }
1447
+ if (result.stdout.trim() === "") {
1448
+ append(ENGINE_DETOUR_EMPTY_STDOUT_DIAGNOSTIC);
1438
1449
  }
1439
- return `\u52B3\u52A1\u5F15\u64CE\u4EE5 code ${result.code} \u9000\u51FA\uFF1A${lastRow}`;
1450
+ return text.length > 0 ? text : ENGINE_DETOUR_EMPTY_STDOUT_DIAGNOSTIC;
1440
1451
  }
1441
1452
  function engineNameFromEnv() {
1442
1453
  return normalizeEngineName(
@@ -1524,43 +1535,10 @@ function withTerminatingOutputDeclarations(schema) {
1524
1535
  object.required = preserved;
1525
1536
  return object;
1526
1537
  }
1527
- function isInfrastructureFailureDeclaration(parameters) {
1528
- if (!isRecord(parameters)) return false;
1529
- if (!Object.hasOwn(parameters, INFRASTRUCTURE_FAILURE_DECLARATION_KEY)) return false;
1530
- const declaration = parameters[INFRASTRUCTURE_FAILURE_DECLARATION_KEY];
1531
- if (!isRecord(declaration)) return false;
1532
- const diagnostic = declaration[INFRASTRUCTURE_FAILURE_DIAGNOSTIC_KEY];
1533
- return typeof diagnostic === "string" && diagnostic.trim().length > 0;
1534
- }
1535
- function infrastructureFailureDiagnostic(parameters) {
1536
- if (!isInfrastructureFailureDeclaration(parameters)) return void 0;
1537
- const declaration = parameters[INFRASTRUCTURE_FAILURE_DECLARATION_KEY];
1538
- const diagnostic = declaration[INFRASTRUCTURE_FAILURE_DIAGNOSTIC_KEY];
1539
- return typeof diagnostic === "string" ? diagnostic.trim() : void 0;
1540
- }
1541
- function infrastructureFailureError(diagnostic) {
1542
- const error = new Error(diagnostic);
1543
- error.name = "InfrastructureFailure";
1544
- return error;
1545
- }
1546
- function failOnInfrastructureFailureDeclaration(parameters, hostActions, ctx, toolCallId, bounceInfrastructureDeclaration) {
1547
- const diagnostic = infrastructureFailureDiagnostic(parameters);
1548
- if (diagnostic === void 0) return;
1549
- if (bounceInfrastructureDeclaration !== void 0) {
1550
- const bounce = bounceInfrastructureDeclaration(parameters, toolCallId, ctx);
1551
- if (bounce !== void 0) throw bounce;
1552
- }
1553
- hostActions.failInfrastructure(
1554
- infrastructureFailureError(diagnostic),
1555
- ctx,
1556
- toolCallId
1557
- );
1558
- }
1559
1538
  var INFRASTRUCTURE_FAILURE_DECLARATION_KEY, INFRASTRUCTURE_FAILURE_DIAGNOSTIC_KEY, infrastructureFailureNested, infrastructureFailureDeclarationSchema;
1560
1539
  var init_terminating_infrastructure = __esm({
1561
1540
  "src/package-contracts/terminating-infrastructure.ts"() {
1562
1541
  "use strict";
1563
- init_unknown_value();
1564
1542
  INFRASTRUCTURE_FAILURE_DECLARATION_KEY = "infrastructureFailure";
1565
1543
  INFRASTRUCTURE_FAILURE_DIAGNOSTIC_KEY = "diagnostic";
1566
1544
  infrastructureFailureNested = Type2.Object(
@@ -3095,20 +3073,6 @@ var init_readable_gate_item = __esm({
3095
3073
  });
3096
3074
 
3097
3075
  // src/submission-errors.ts
3098
- function serializeReceipt(receipt) {
3099
- return readableGateItem(receipt);
3100
- }
3101
- function gatekeeperNonPassMessage(result) {
3102
- if (result.status === "continue") {
3103
- return serializeReceipt(result.receipt);
3104
- }
3105
- if (result.status === "transport_failure") {
3106
- const head = `\u95E8\u4E0B\u7701 ${result.status}\uFF08${result.stage}\uFF09\uFF1A${result.reason}`;
3107
- return result.submission === void 0 ? head : `${head}
3108
- ${serializeReceipt(result.submission)}`;
3109
- }
3110
- return `\u95E8\u4E0B\u7701 ${result.status}\uFF08${result.stage}\uFF09\uFF1A${result.reason}`;
3111
- }
3112
3076
  function isOneShotWorkerReminderCode(code) {
3113
3077
  return code === "worker_commit_reminder" || code === "worker_prefix_reminder";
3114
3078
  }
@@ -3121,20 +3085,12 @@ function receivedDiscriminator(receipt, field) {
3121
3085
  if (!Object.hasOwn(receipt, field)) return void 0;
3122
3086
  return receipt[field];
3123
3087
  }
3124
- var GatekeeperDecisionError, WorkerCommitReminderError, WorkerPrefixReminderError, WorkerUnfinishedReasonReminderError, ParentQueueReaskError;
3088
+ var WorkerCommitReminderError, WorkerPrefixReminderError, WorkerUnfinishedReasonReminderError, ParentQueueReaskError;
3125
3089
  var init_submission_errors = __esm({
3126
3090
  "src/submission-errors.ts"() {
3127
3091
  "use strict";
3128
3092
  init_readable_gate_item();
3129
3093
  init_unknown_value();
3130
- GatekeeperDecisionError = class extends Error {
3131
- result;
3132
- constructor(result, message) {
3133
- super(message ?? gatekeeperNonPassMessage(result));
3134
- this.name = "GatekeeperDecisionError";
3135
- this.result = result;
3136
- }
3137
- };
3138
3094
  WorkerCommitReminderError = class extends Error {
3139
3095
  code = "worker_commit_reminder";
3140
3096
  constructor() {
@@ -3692,7 +3648,6 @@ var init_gatekeeper_role = __esm({
3692
3648
  init_run_terminal_artifacts();
3693
3649
  init_unknown_value();
3694
3650
  init_serialize_thrown_value();
3695
- init_submission_errors();
3696
3651
  GATE_OFFICER_BY_SUBJECT = {
3697
3652
  worker_completion: "inspector",
3698
3653
  judge_compliance: "auditor",
@@ -4472,13 +4427,10 @@ function isCorrectableSubmissionError(error) {
4472
4427
  return error instanceof CorrectableSubmissionError;
4473
4428
  }
4474
4429
  function isCorrectableExecuteError(error) {
4475
- return isCorrectableSubmissionError(error) || error instanceof GatekeeperDecisionError || error instanceof ParentQueueReaskError || error instanceof WorkerCommitReminderError || error instanceof WorkerPrefixReminderError || error instanceof WorkerUnfinishedReasonReminderError;
4430
+ return isCorrectableSubmissionError(error) || error instanceof ParentQueueReaskError || error instanceof WorkerCommitReminderError || error instanceof WorkerPrefixReminderError || error instanceof WorkerUnfinishedReasonReminderError;
4476
4431
  }
4477
4432
  function projectCorrectableExecuteRejection(error) {
4478
4433
  const diagnostic = errorText(error);
4479
- if (error instanceof GatekeeperDecisionError) {
4480
- return { diagnostic, details: { ...error.result } };
4481
- }
4482
4434
  if (error instanceof WorkerCommitReminderError || error instanceof WorkerPrefixReminderError || error instanceof WorkerUnfinishedReasonReminderError) {
4483
4435
  return { diagnostic, details: { code: error.code } };
4484
4436
  }
@@ -8232,11 +8184,7 @@ function admittedForLiveTicketReport(runDirectory, authority) {
8232
8184
  ...ticketNumber === void 0 ? {} : { ticketNumber }
8233
8185
  };
8234
8186
  }
8235
- async function reportTicketFromHostContext(context, rawTicketNumber, authority = piDurablePrincipalAuthority) {
8236
- const ticketNumber = readDeclaredTicketNumber(rawTicketNumber);
8237
- if (ticketNumber === void 0) {
8238
- throw new Error("ak_report_ticket requires an identifiable ticketNumber");
8239
- }
8187
+ async function reportTicketFromHostContext(context, ticketNumber, authority = piDurablePrincipalAuthority) {
8240
8188
  const runDirectory = runDirectoryFromHostContext(context);
8241
8189
  if (runDirectory === void 0) {
8242
8190
  throw new Error("ak_report_ticket requires a per-turn run directory");
@@ -8272,7 +8220,7 @@ async function reportTicketFromHostContext(context, rawTicketNumber, authority =
8272
8220
  relocated: relocation !== void 0
8273
8221
  };
8274
8222
  }
8275
- function registerReportTicketTool(roleHost) {
8223
+ function registerReportTicketTool(roleHost, hostActions) {
8276
8224
  if (roleHost.getAllTools().some((tool) => tool.name === REPORT_TICKET_TOOL_NAME)) return;
8277
8225
  roleHost.registerTool({
8278
8226
  name: REPORT_TICKET_TOOL_NAME,
@@ -8280,13 +8228,21 @@ function registerReportTicketTool(roleHost) {
8280
8228
  description: REPORT_TICKET_TOOL_DESCRIPTION,
8281
8229
  promptSnippet: "\u5DF2\u77E5\u7968\u53F7\u65F6\u7ACB\u5373\u7533\u62A5\uFF0C\u5305\u5F53\u573A\u5F52\u4F4D",
8282
8230
  parameters: reportTicketArgsSchema,
8283
- async execute(_toolCallId, parameters, _signal, _onUpdate, ctx) {
8231
+ async execute(toolCallId, parameters, _signal, _onUpdate, ctx) {
8284
8232
  const raw = isRecord(parameters) ? parameters.ticketNumber : void 0;
8285
- const details = await reportTicketFromHostContext(ctx, raw);
8286
- return {
8287
- content: [],
8288
- details
8289
- };
8233
+ const ticketNumber = readDeclaredTicketNumber(raw);
8234
+ if (ticketNumber === void 0) {
8235
+ throw new Error("ak_report_ticket requires an identifiable ticketNumber");
8236
+ }
8237
+ try {
8238
+ const details = await reportTicketFromHostContext(ctx, ticketNumber);
8239
+ return {
8240
+ content: [],
8241
+ details
8242
+ };
8243
+ } catch (error) {
8244
+ hostActions.failInfrastructure(error, ctx, toolCallId);
8245
+ }
8290
8246
  }
8291
8247
  });
8292
8248
  }
@@ -8479,6 +8435,14 @@ async function readAttemptScopedSubmissionRows(cwd, runId, attemptId, homeOrScop
8479
8435
  const { owned } = await readOwnedSubmissionRecords(cwd, runId, scope);
8480
8436
  return mapOwnedToSubmissionRows(owned.filter((record) => recordAttemptId(record) === attemptId));
8481
8437
  }
8438
+ async function readSubmissionAttemptId(cwd, runId, toolCallId, homeOrScope) {
8439
+ const { owned } = await readOwnedSubmissionRecords(cwd, runId, resolveReadScope(homeOrScope));
8440
+ const record = owned.find((candidate) => {
8441
+ const payload = candidate.payload;
8442
+ return payload?.toolCallId === toolCallId;
8443
+ });
8444
+ return record === void 0 ? void 0 : recordAttemptId(record);
8445
+ }
8482
8446
  async function readRecordedSubmissions(cwd, runId, homeOrScope) {
8483
8447
  return (await readRecordedSubmissionRows(cwd, runId, homeOrScope)).map((row) => row.accepted);
8484
8448
  }
@@ -8602,89 +8566,82 @@ function createSubmissionLedgerHost(host, outputTools, failInfrastructure2 = (er
8602
8566
  host.registerTool({
8603
8567
  ...tool,
8604
8568
  async execute(toolCallId, params, signal, update, context) {
8605
- const typedTicket = isRecord(params) ? readDeclaredTicketNumber(params.ticketNumber) : void 0;
8606
- if (typedTicket !== void 0) {
8607
- await reportTicketFromHostContext(context, typedTicket);
8608
- }
8609
- const runId = runIdentity(context);
8610
- const attemptId = attemptIdentity(context, runId);
8611
- const state = await stateFor(context, runId);
8612
- const append = (event) => appendFor(context, runId, attemptId, event);
8613
- append({
8614
- type: "candidate",
8615
- attemptId,
8616
- toolCallId,
8617
- toolName: tool.name,
8618
- sequence: ++state.sequence,
8619
- role,
8620
- params
8621
- });
8569
+ let toolThrew = false;
8622
8570
  let result;
8571
+ let closed;
8623
8572
  try {
8624
- const reviewEscalate = tool.name === REVIEW_SUBMISSION_OUTPUT_TOOL_NAME && infrastructureFailureDiagnostic(params) !== void 0 && isRecord(params) && params.status === "escalate";
8625
- if (!reviewEscalate) {
8626
- failOnInfrastructureFailureDeclaration(
8627
- params,
8628
- {
8629
- failInfrastructure(error, ctx) {
8630
- failInfrastructure2(error, ctx);
8631
- }
8632
- },
8633
- context,
8634
- toolCallId,
8635
- tool.bounceInfrastructureDeclaration
8636
- );
8573
+ const typedTicket = isRecord(params) ? readDeclaredTicketNumber(params.ticketNumber) : void 0;
8574
+ if (typedTicket !== void 0) {
8575
+ await reportTicketFromHostContext(context, typedTicket);
8637
8576
  }
8638
- result = await tool.execute(toolCallId, params, signal, update, context);
8639
- } catch (error) {
8640
- if (isCorrectableExecuteError(error)) {
8641
- append({
8642
- type: "outcome",
8643
- attemptId,
8644
- toolCallId,
8645
- outcome: "correctable-rejection",
8646
- code: "typed-bounce",
8647
- diagnostic: errorText(error),
8648
- role,
8649
- accepted: params
8650
- });
8651
- throw error;
8652
- } else {
8653
- append({
8654
- type: "outcome",
8655
- attemptId,
8656
- toolCallId,
8657
- outcome: "infrastructure",
8658
- diagnostic: errorText(error),
8659
- role,
8660
- accepted: params
8661
- });
8577
+ const runId = runIdentity(context);
8578
+ const attemptId = attemptIdentity(context, runId);
8579
+ const state = await stateFor(context, runId);
8580
+ const append = (event) => appendFor(context, runId, attemptId, event);
8581
+ append({
8582
+ type: "candidate",
8583
+ attemptId,
8584
+ toolCallId,
8585
+ toolName: tool.name,
8586
+ sequence: ++state.sequence,
8587
+ role,
8588
+ params
8589
+ });
8590
+ try {
8591
+ result = await tool.execute(toolCallId, params, signal, update, context);
8592
+ } catch (error) {
8593
+ if (isCorrectableExecuteError(error)) {
8594
+ append({
8595
+ type: "outcome",
8596
+ attemptId,
8597
+ toolCallId,
8598
+ outcome: "correctable-rejection",
8599
+ code: "typed-bounce",
8600
+ diagnostic: errorText(error),
8601
+ role,
8602
+ accepted: params
8603
+ });
8604
+ } else {
8605
+ append({
8606
+ type: "outcome",
8607
+ attemptId,
8608
+ toolCallId,
8609
+ outcome: "infrastructure",
8610
+ diagnostic: errorText(error),
8611
+ role,
8612
+ accepted: params
8613
+ });
8614
+ }
8615
+ toolThrew = true;
8662
8616
  throw error;
8663
8617
  }
8618
+ if (result.terminate === false) return result;
8619
+ closed = {
8620
+ role,
8621
+ kind: "accepted",
8622
+ accepted: params
8623
+ };
8624
+ const sealHead = captureWorktreeHead(context.cwd);
8625
+ append({
8626
+ type: "sealed",
8627
+ attemptId,
8628
+ toolCallId,
8629
+ role,
8630
+ accepted: params
8631
+ });
8632
+ const rawLens = typeof host.getFlag === "function" ? host.getFlag("ak-review-lens") : void 0;
8633
+ landTicketProgressForSealedSubmission({
8634
+ context,
8635
+ role,
8636
+ accepted: params,
8637
+ sealHead,
8638
+ ...rawLens === "completeness" || rawLens === "correctness" ? { lens: rawLens } : {}
8639
+ });
8640
+ } catch (error) {
8641
+ if (toolThrew) throw error;
8642
+ return failInfrastructure2(error, context, toolCallId);
8664
8643
  }
8665
- if (result.terminate === false) return result;
8666
- const closed = {
8667
- role,
8668
- kind: "accepted",
8669
- accepted: params
8670
- };
8671
- const sealHead = captureWorktreeHead(context.cwd);
8672
- append({
8673
- type: "sealed",
8674
- attemptId,
8675
- toolCallId,
8676
- role,
8677
- accepted: params
8678
- });
8679
- const rawLens = typeof host.getFlag === "function" ? host.getFlag("ak-review-lens") : void 0;
8680
- landTicketProgressForSealedSubmission({
8681
- context,
8682
- role,
8683
- accepted: params,
8684
- sealHead,
8685
- ...rawLens === "completeness" || rawLens === "correctness" ? { lens: rawLens } : {}
8686
- });
8687
- await projectClosure(closed, context);
8644
+ await projectClosure(closed, context, toolCallId);
8688
8645
  return result;
8689
8646
  }
8690
8647
  });
@@ -8701,9 +8658,7 @@ var init_submission_ledger = __esm({
8701
8658
  init_sitian_facade();
8702
8659
  init_run_lifecycle();
8703
8660
  init_submission_correctable_error();
8704
- init_terminating_infrastructure();
8705
8661
  init_report_ticket_tool();
8706
- init_review_submission();
8707
8662
  init_run_ticket_number();
8708
8663
  init_ticket_progress();
8709
8664
  init_unknown_value();
@@ -12053,11 +12008,21 @@ async function runJudgeGates(input) {
12053
12008
  if (await input.gateAlreadyConverged(subject)) continue;
12054
12009
  const pass = await input.runGate(subject);
12055
12010
  const received = pass?.status;
12056
- if (pass === void 0 || (typeof received !== "string" || !REVIEW_QUEUE_STATUSES.has(received) && received !== "needs_reask")) {
12057
- throw new Error("judge gate returned no conclusion");
12011
+ if (pass === void 0 || (typeof received !== "string" || !REVIEW_QUEUE_STATUSES.has(received) && received !== "needs_reask" && received !== "transport_failure" && received !== "no_receipt")) {
12012
+ return {
12013
+ status: "needs_reask",
12014
+ passes: [{
12015
+ subject,
12016
+ status: "needs_reask",
12017
+ receipt: pass?.receipt ?? { reason: "judge gate returned no conclusion" },
12018
+ ...pass?.runId === void 0 ? {} : { runId: pass.runId },
12019
+ ...pass?.runDirectory === void 0 ? {} : { runDirectory: pass.runDirectory },
12020
+ ...pass?.terminal === void 0 ? {} : { terminal: pass.terminal }
12021
+ }]
12022
+ };
12058
12023
  }
12059
12024
  const status = received;
12060
- if (status === "needs_reask") {
12025
+ if (status === "needs_reask" || status === "transport_failure" || status === "no_receipt") {
12061
12026
  return {
12062
12027
  status,
12063
12028
  passes: [{
@@ -12066,7 +12031,8 @@ async function runJudgeGates(input) {
12066
12031
  receipt: pass.receipt,
12067
12032
  ...pass.runId === void 0 ? {} : { runId: pass.runId },
12068
12033
  ...pass.runDirectory === void 0 ? {} : { runDirectory: pass.runDirectory },
12069
- ...pass.terminal === void 0 ? {} : { terminal: pass.terminal }
12034
+ ...pass.terminal === void 0 ? {} : { terminal: pass.terminal },
12035
+ ...pass.reason === void 0 ? {} : { reason: pass.reason }
12070
12036
  }]
12071
12037
  };
12072
12038
  }
@@ -12075,7 +12041,8 @@ async function runJudgeGates(input) {
12075
12041
  status,
12076
12042
  receipt: pass.receipt,
12077
12043
  ...pass.runId === void 0 ? {} : { runId: pass.runId },
12078
- ...pass.runDirectory === void 0 ? {} : { runDirectory: pass.runDirectory }
12044
+ ...pass.runDirectory === void 0 ? {} : { runDirectory: pass.runDirectory },
12045
+ ...pass.terminal === void 0 ? {} : { terminal: pass.terminal }
12079
12046
  });
12080
12047
  if (status === "continue" || status === "escalate") return { status, passes };
12081
12048
  }
@@ -12188,6 +12155,17 @@ function createDefaultGateOfficerSummon(options) {
12188
12155
  });
12189
12156
  };
12190
12157
  }
12158
+ function presentGateOutcome(fields) {
12159
+ return {
12160
+ status: fields.status,
12161
+ officer: fields.officer,
12162
+ receipt: fields.receipt,
12163
+ ...typeof fields.runId === "string" && fields.runId.trim() !== "" ? { runId: fields.runId } : {},
12164
+ ...typeof fields.runDirectory === "string" && fields.runDirectory.trim() !== "" ? { runDirectory: fields.runDirectory } : {},
12165
+ ...fields.terminal === void 0 ? {} : { terminal: fields.terminal },
12166
+ ...fields.reason === void 0 ? {} : { reason: fields.reason }
12167
+ };
12168
+ }
12191
12169
  async function requireSubmissionGate(options) {
12192
12170
  let reask;
12193
12171
  let reasksSpent = 0;
@@ -12205,7 +12183,7 @@ async function requireSubmissionGate(options) {
12205
12183
  ...reask === void 0 ? {} : { reask }
12206
12184
  });
12207
12185
  const gatekeeper = projected.result;
12208
- if (projected.summoned !== void 0 && options.toolCallId.trim() !== "" && (gatekeeper.status === "converged" || gatekeeper.status === "continue" || gatekeeper.status === "escalate" || gatekeeper.status === "needs_reask" || gatekeeper.status === "transport_failure")) {
12186
+ if (projected.summoned !== void 0 && options.toolCallId.trim() !== "" && (gatekeeper.status === "converged" || gatekeeper.status === "continue" || gatekeeper.status === "escalate" || gatekeeper.status === "needs_reask" || gatekeeper.status === "transport_failure" || gatekeeper.status === "no_receipt")) {
12209
12187
  const officerRunDirectory = await directoryForSummonedOfficer(
12210
12188
  projected.officer,
12211
12189
  projected.summoned
@@ -12215,61 +12193,69 @@ async function requireSubmissionGate(options) {
12215
12193
  }
12216
12194
  }
12217
12195
  if (gatekeeper.status === "converged") {
12218
- return {
12196
+ return presentGateOutcome({
12219
12197
  status: "converged",
12220
12198
  officer: projected.officer,
12221
12199
  receipt: gatekeeper.receipt,
12222
- ...typeof gatekeeper.runId === "string" && gatekeeper.runId.trim() !== "" ? { runId: gatekeeper.runId } : {},
12223
- ...typeof projected.summoned?.runDirectory === "string" && projected.summoned.runDirectory.trim() !== "" ? { runDirectory: projected.summoned.runDirectory } : {},
12224
- // Keep the officer terminal for escalate / unsettled surfaces; parent
12225
- // finals do not project other-seat tables (#1195).
12226
- ...projected.summoned?.terminal === void 0 ? {} : { terminal: projected.summoned.terminal }
12227
- };
12200
+ runId: gatekeeper.runId,
12201
+ runDirectory: projected.summoned?.runDirectory,
12202
+ terminal: projected.summoned?.terminal
12203
+ });
12228
12204
  }
12229
12205
  if (gatekeeper.status === "continue") {
12230
- return {
12206
+ return presentGateOutcome({
12231
12207
  status: "continue",
12232
12208
  officer: projected.officer,
12233
12209
  receipt: gatekeeper.receipt,
12234
- ...typeof gatekeeper.runId === "string" && gatekeeper.runId.trim() !== "" ? { runId: gatekeeper.runId } : {}
12235
- };
12210
+ runId: gatekeeper.runId
12211
+ });
12236
12212
  }
12237
12213
  if (gatekeeper.status === "needs_reask") {
12238
12214
  const nestedIncomplete = projected.summoned?.terminal?.roleOutcome.kind === "accepted" && projected.summoned.terminal.roleOutcome.decisiveFacts?.directionUnsettled === true;
12239
12215
  if (nestedIncomplete || reasksSpent >= reaskLimit) {
12240
- return {
12216
+ return presentGateOutcome({
12241
12217
  status: "needs_reask",
12242
12218
  officer: projected.officer,
12243
12219
  receipt: gatekeeper.receipt,
12244
- ...typeof gatekeeper.runId === "string" && gatekeeper.runId.trim() !== "" ? { runId: gatekeeper.runId } : {},
12245
- ...typeof projected.summoned?.runDirectory === "string" && projected.summoned.runDirectory.trim() !== "" ? { runDirectory: projected.summoned.runDirectory } : {},
12246
- ...projected.summoned?.terminal === void 0 ? {} : { terminal: projected.summoned.terminal }
12247
- };
12220
+ runId: gatekeeper.runId,
12221
+ runDirectory: projected.summoned?.runDirectory,
12222
+ terminal: projected.summoned?.terminal
12223
+ });
12248
12224
  }
12249
12225
  reasksSpent += 1;
12250
12226
  reask = officerConclusionReask(gatekeeper.receivedStatus);
12251
12227
  continue;
12252
12228
  }
12253
12229
  if (gatekeeper.status === "transport_failure") {
12254
- const failure = Object.assign(new Error(gatekeeper.reason), {
12255
- name: "GatekeeperTransportFailure",
12256
- ...gatekeeper.submission === void 0 ? {} : { submission: gatekeeper.submission }
12230
+ return presentGateOutcome({
12231
+ status: "transport_failure",
12232
+ officer: projected.officer,
12233
+ receipt: gatekeeper.submission ?? { reason: gatekeeper.reason },
12234
+ reason: gatekeeper.reason,
12235
+ runId: projected.summoned?.terminal?.runId,
12236
+ runDirectory: projected.summoned?.runDirectory,
12237
+ terminal: projected.summoned?.terminal
12257
12238
  });
12258
- options.hostActions.failInfrastructure(failure, options.context, options.toolCallId);
12259
12239
  }
12260
12240
  if (gatekeeper.status === "escalate") {
12261
- return {
12241
+ return presentGateOutcome({
12262
12242
  status: "escalate",
12263
12243
  officer: projected.officer,
12264
12244
  receipt: gatekeeper.receipt,
12265
- ...typeof gatekeeper.runId === "string" && gatekeeper.runId.trim() !== "" ? { runId: gatekeeper.runId } : {},
12266
- ...typeof projected.summoned?.runDirectory === "string" && projected.summoned.runDirectory.trim() !== "" ? { runDirectory: projected.summoned.runDirectory } : {},
12267
- // Keep the actual officer terminal so callers resume that seat.
12268
- ...projected.summoned?.terminal === void 0 ? {} : { terminal: projected.summoned.terminal }
12269
- };
12245
+ runId: gatekeeper.runId,
12246
+ runDirectory: projected.summoned?.runDirectory,
12247
+ terminal: projected.summoned?.terminal
12248
+ });
12270
12249
  }
12271
- options.hostActions.bindSubmissionNonPass(options.toolCallId, gatekeeper);
12272
- throw new GatekeeperDecisionError(gatekeeper);
12250
+ return presentGateOutcome({
12251
+ status: "no_receipt",
12252
+ officer: projected.officer,
12253
+ receipt: gatekeeper.facts ?? { reason: gatekeeper.reason },
12254
+ reason: gatekeeper.reason,
12255
+ runId: projected.summoned?.terminal?.runId,
12256
+ runDirectory: projected.summoned?.runDirectory,
12257
+ terminal: projected.summoned?.terminal
12258
+ });
12273
12259
  }
12274
12260
  }
12275
12261
  var init_submission_gate = __esm({
@@ -14295,6 +14281,7 @@ __export(instruction_seat_run_exports, {
14295
14281
  NOTARY_FIXED_DISPATCH: () => NOTARY_FIXED_DISPATCH,
14296
14282
  buildInstructionSeatTurnRequest: () => buildInstructionSeatTurnRequest,
14297
14283
  continueParentAfterChild: () => continueParentAfterChild,
14284
+ presentAuditedOriginalOfUnsettledOfficer: () => presentAuditedOriginalOfUnsettledOfficer,
14298
14285
  resolveReviewSeatDialogueBody: () => resolveReviewSeatDialogueBody,
14299
14286
  runPublicInstructionSeat: () => runPublicInstructionSeat,
14300
14287
  runPublicInstructionSeatResume: () => runPublicInstructionSeatResume
@@ -14358,6 +14345,60 @@ async function presentUnsettledOfficer(officer, io, runDirectory) {
14358
14345
  await presentTerminal(terminal, { ...io, omitFailureStderrDiagnostic: true }, runDirectory);
14359
14346
  return terminal;
14360
14347
  }
14348
+ async function presentAuditedOriginalVolume(turn, io) {
14349
+ const admitted = turn.admitted;
14350
+ if (turn.terminal === void 0 || admitted === void 0) return;
14351
+ await presentTerminal(
14352
+ turn.terminal,
14353
+ { ...io, omitFailureStderrDiagnostic: true },
14354
+ admitted.runDirectory
14355
+ );
14356
+ }
14357
+ async function incompleteAuditWithoutOfficerVolume(turn, admitted, io, diagnostic) {
14358
+ await presentAuditedOriginalVolume(turn, io);
14359
+ io.stderr(diagnostic);
14360
+ return { exitCode: 1, admitted };
14361
+ }
14362
+ async function presentAuditedOriginalOfOfficer(officer, presentedRunId, env, io) {
14363
+ if (!GATE_CHILD_ROLES.has(officer.role)) return;
14364
+ const audited = officer.correlationId;
14365
+ if (audited === void 0 || audited === presentedRunId) return;
14366
+ const auditedSource = admittedSourceRunPath(officer);
14367
+ const parent = await loadResumablePublicRole(
14368
+ env.home,
14369
+ audited,
14370
+ env.principalAuthority,
14371
+ auditedSource === void 0 ? void 0 : { runDirectory: auditedSource }
14372
+ );
14373
+ if (!AUDITED_ROLES.has(parent.admitted.role)) return;
14374
+ const sealId = readAdmittedAuditedSubmissionToolCallId(officer.runDirectory);
14375
+ const courtAttemptId = sealId === void 0 ? (await readCurrentCourt(parent.admitted.runDirectory))?.courtAttemptId : await readSubmissionAttemptId(
14376
+ parent.admitted.projectRoot,
14377
+ parent.admitted.runId,
14378
+ sealId,
14379
+ ledgerReadScope(parent.admitted)
14380
+ );
14381
+ if (sealId !== void 0 && courtAttemptId === void 0) return;
14382
+ const terminal = await trySettlePublicSeat(
14383
+ parent.admitted,
14384
+ env.principalAuthority,
14385
+ {
14386
+ ...courtAttemptId === void 0 ? {} : { courtAttemptId },
14387
+ previewOnly: true,
14388
+ ...packageFaultScope(parent.admitted, env, io)
14389
+ }
14390
+ );
14391
+ if (terminal?.roleOutcome.kind !== "accepted") return;
14392
+ await presentTerminal(terminal, { ...io, omitFailureStderrDiagnostic: true }, parent.admitted.runDirectory);
14393
+ }
14394
+ function leavesAuditedVerdictUnsettled(result) {
14395
+ const outcome = result.terminal?.roleOutcome;
14396
+ return result.exitCode !== 0 || outcome?.kind === "no_receipt" || outcome?.decisiveFacts?.directionUnsettled === true;
14397
+ }
14398
+ async function presentAuditedOriginalOfUnsettledOfficer(result, env, io) {
14399
+ if (result.admitted === void 0 || !leavesAuditedVerdictUnsettled(result)) return;
14400
+ await presentAuditedOriginalOfOfficer(result.admitted, void 0, env, io);
14401
+ }
14361
14402
  async function reaskUnreadablePostSubmissionStatus(admitted, terminal, env, io, message = unreadablePostSubmissionStatus(admitted, terminal)) {
14362
14403
  if (message === void 0) return void 0;
14363
14404
  const next = withUnreadableReask(env);
@@ -15224,7 +15265,7 @@ async function queueConclusionFromChild(child, env, io) {
15224
15265
  if (terminal !== void 0 && typeof status === "string" && REVIEW_QUEUE_STATUSES.has(status)) {
15225
15266
  return { admitted: child, terminal, status };
15226
15267
  }
15227
- return { stop: { exitCode: 0, ...terminal === void 0 ? {} : { terminal } } };
15268
+ return { stop: { exitCode: 0, admitted: child, ...terminal === void 0 ? {} : { terminal } } };
15228
15269
  }
15229
15270
  let current = child;
15230
15271
  let budgetEnv = envForCourtContinue(env);
@@ -15246,7 +15287,7 @@ async function queueConclusionFromChild(child, env, io) {
15246
15287
  officerConclusionReask(status)
15247
15288
  );
15248
15289
  if (reasked === void 0 || isUnreadableReaskExhausted(reasked)) {
15249
- return { stop: { exitCode: 0, ...terminal === void 0 ? {} : { terminal } } };
15290
+ return { stop: { exitCode: 0, admitted: current, ...terminal === void 0 ? {} : { terminal } } };
15250
15291
  }
15251
15292
  budgetEnv = withUnreadableReask(budgetEnv);
15252
15293
  if (reasked.exitCode !== 0 || reasked.admitted === void 0 || reasked.terminal === void 0 || reasked.terminal.roleOutcome.kind === "no_receipt" || reasked.terminal.roleOutcome.decisiveFacts?.directionUnsettled === true) {
@@ -15282,6 +15323,9 @@ async function continueParentAfterChild(parentRunId, child, env, io) {
15282
15323
  const resolved = await queueConclusionFromChild(child, env, io);
15283
15324
  if (resolved !== void 0 && "stop" in resolved) {
15284
15325
  const stopped = resolved.stop;
15326
+ if (stopped.admitted !== void 0 && (leavesAuditedVerdictUnsettled(stopped) || heldUnreadableTerminal(stopped.terminal))) {
15327
+ await presentAuditedOriginalOfOfficer(stopped.admitted, void 0, env, io);
15328
+ }
15285
15329
  if (stopped.exitCode === 0 && heldUnreadableTerminal(stopped.terminal) && stopped.terminal !== void 0 && stopped.admitted !== void 0) {
15286
15330
  const terminal = await presentUnsettledOfficer(
15287
15331
  stopped.terminal,
@@ -15449,20 +15493,27 @@ async function auditSubmittedRole(turn, env, io, resumedOfficer, passedReceipt)
15449
15493
  }, envForCourtContinue(env), io);
15450
15494
  }
15451
15495
  if (decision.status === "received") {
15452
- if (lastSummon?.terminal === void 0) {
15453
- throw new Error("doctor audit kept an unreadable reply with no terminal");
15496
+ if (lastSummon?.terminal !== void 0) {
15497
+ await presentAuditedOriginalVolume(turn, io);
15498
+ const officerAdmitted = lastSummon.admitted;
15499
+ const officerDir = officerAdmitted?.runDirectory ?? lastSummon.runDirectory ?? admitted.runDirectory;
15500
+ const terminal = await presentUnsettledOfficer(lastSummon.terminal, io, officerDir);
15501
+ return {
15502
+ exitCode: 0,
15503
+ ...officerAdmitted === void 0 ? { admitted } : { admitted: officerAdmitted },
15504
+ terminal
15505
+ };
15454
15506
  }
15455
- const officerAdmitted = lastSummon.admitted;
15456
- const officerDir = officerAdmitted?.runDirectory ?? lastSummon.runDirectory ?? admitted.runDirectory;
15457
- const terminal = await presentUnsettledOfficer(lastSummon.terminal, io, officerDir);
15458
- return {
15459
- exitCode: 0,
15460
- ...officerAdmitted === void 0 ? { admitted } : { admitted: officerAdmitted },
15461
- terminal
15462
- };
15507
+ return incompleteAuditWithoutOfficerVolume(
15508
+ turn,
15509
+ admitted,
15510
+ io,
15511
+ "doctor audit kept an unreadable reply with no terminal"
15512
+ );
15463
15513
  }
15464
15514
  if (decision.status !== "converged") {
15465
15515
  if (lastSummon?.terminal !== void 0) {
15516
+ await presentAuditedOriginalVolume(turn, io);
15466
15517
  await presentTerminal(lastSummon.terminal, { ...io, omitFailureStderrDiagnostic: true }, lastSummon.admitted?.runDirectory ?? admitted.runDirectory);
15467
15518
  return {
15468
15519
  exitCode: lastSummon.exitCode,
@@ -15470,7 +15521,8 @@ async function auditSubmittedRole(turn, env, io, resumedOfficer, passedReceipt)
15470
15521
  terminal: lastSummon.terminal
15471
15522
  };
15472
15523
  }
15473
- throw new Error(`doctor audit did not converge: ${decision.status}`);
15524
+ const diagnostic = decision.status === "transport_failure" && "diagnostic" in decision && typeof decision.diagnostic === "string" ? decision.diagnostic : `doctor audit did not converge: ${decision.status}`;
15525
+ return incompleteAuditWithoutOfficerVolume(turn, admitted, io, diagnostic);
15474
15526
  }
15475
15527
  }
15476
15528
  } else {
@@ -15489,14 +15541,7 @@ async function auditSubmittedRole(turn, env, io, resumedOfficer, passedReceipt)
15489
15541
  submission: accepted,
15490
15542
  summonOfficer,
15491
15543
  ...env.autoResumeLimit === void 0 ? {} : { autoResumeLimit: env.autoResumeLimit },
15492
- ...env.signal === void 0 ? {} : { signal: env.signal },
15493
- hostActions: {
15494
- failInfrastructure(error) {
15495
- throw error;
15496
- },
15497
- bindSubmissionNonPass() {
15498
- }
15499
- }
15544
+ ...env.signal === void 0 ? {} : { signal: env.signal }
15500
15545
  });
15501
15546
  if (admitted.role === "judge") {
15502
15547
  const judgeGateOrder = JUDGE_GATES.map(gateOfficerForSubject);
@@ -15511,45 +15556,83 @@ async function auditSubmittedRole(turn, env, io, resumedOfficer, passedReceipt)
15511
15556
  chain = { status: "converged", passes: [] };
15512
15557
  } else {
15513
15558
  const pass = await runGate(subject);
15514
- if (pass === void 0) throw new Error("audit gate returned no conclusion");
15515
- chain = {
15516
- status: pass.status,
15517
- passes: [{
15518
- subject,
15559
+ if (pass === void 0) {
15560
+ chain = {
15561
+ status: "needs_reask",
15562
+ passes: [{
15563
+ subject,
15564
+ status: "needs_reask",
15565
+ receipt: { reason: "audit gate returned no conclusion" }
15566
+ }]
15567
+ };
15568
+ } else {
15569
+ chain = {
15519
15570
  status: pass.status,
15520
- receipt: pass.receipt,
15521
- ...pass.runId === void 0 ? {} : { runId: pass.runId },
15522
- ...pass.runDirectory === void 0 ? {} : { runDirectory: pass.runDirectory },
15523
- ...pass.terminal === void 0 ? {} : { terminal: pass.terminal }
15524
- }]
15525
- };
15571
+ passes: [{
15572
+ subject,
15573
+ status: pass.status,
15574
+ receipt: pass.receipt,
15575
+ ...pass.runId === void 0 ? {} : { runId: pass.runId },
15576
+ ...pass.runDirectory === void 0 ? {} : { runDirectory: pass.runDirectory },
15577
+ ...pass.terminal === void 0 ? {} : { terminal: pass.terminal },
15578
+ ...pass.reason === void 0 ? {} : { reason: pass.reason }
15579
+ }]
15580
+ };
15581
+ }
15526
15582
  }
15527
15583
  }
15528
- if (chain.status === "needs_reask") {
15584
+ if (chain.status === "needs_reask" || chain.status === "transport_failure" || chain.status === "no_receipt") {
15529
15585
  const pass = chain.passes.at(-1);
15530
15586
  const officerTerminal = pass?.terminal;
15531
- if (officerTerminal === void 0) throw new Error("unreadable audit has no terminal result");
15532
15587
  const officerRunDirectory = pass?.runDirectory;
15533
15588
  const officerRunId = pass?.runId ?? (officerRunDirectory === void 0 ? void 0 : runIdFromRunDirectory(officerRunDirectory));
15534
- if (officerRunId === void 0) throw new Error("unreadable audit has no resumable run identity");
15535
- const officer = await loadResumablePublicRole(
15536
- env.home,
15537
- officerRunId,
15538
- env.principalAuthority,
15539
- officerRunDirectory === void 0 ? void 0 : { runDirectory: officerRunDirectory }
15540
- );
15541
- const terminal = await presentUnsettledOfficer(
15542
- officerTerminal,
15589
+ if (officerTerminal !== void 0 && officerRunId !== void 0) {
15590
+ await presentAuditedOriginalVolume(turn, io);
15591
+ const officer = await loadResumablePublicRole(
15592
+ env.home,
15593
+ officerRunId,
15594
+ env.principalAuthority,
15595
+ officerRunDirectory === void 0 ? void 0 : { runDirectory: officerRunDirectory }
15596
+ );
15597
+ await presentAuditedOriginalOfOfficer(officer.admitted, admitted.runId, env, io);
15598
+ if (chain.status === "needs_reask" || chain.status === "no_receipt") {
15599
+ const terminal = await presentUnsettledOfficer(
15600
+ officerTerminal,
15601
+ io,
15602
+ officer.admitted.runDirectory
15603
+ );
15604
+ return { exitCode: 0, admitted: officer.admitted, terminal };
15605
+ }
15606
+ await presentTerminal(
15607
+ officerTerminal,
15608
+ { ...io, omitFailureStderrDiagnostic: true },
15609
+ officer.admitted.runDirectory
15610
+ );
15611
+ return {
15612
+ exitCode: officerTerminal.roleOutcome.kind === "failure" ? 1 : 0,
15613
+ admitted: officer.admitted,
15614
+ terminal: officerTerminal
15615
+ };
15616
+ }
15617
+ return incompleteAuditWithoutOfficerVolume(
15618
+ turn,
15619
+ admitted,
15543
15620
  io,
15544
- officer.admitted.runDirectory
15621
+ pass?.reason ?? (chain.status === "transport_failure" ? "audit officer transport failure with no presentable volume" : chain.status === "no_receipt" ? "audit officer no_receipt with no presentable volume" : "unreadable audit has no terminal result")
15545
15622
  );
15546
- return { exitCode: 0, admitted: officer.admitted, terminal };
15547
15623
  }
15548
15624
  if (chain.status === "escalate") {
15549
15625
  const escalation = chain.passes.at(-1);
15550
15626
  const escalatedRunDirectory = escalation?.runDirectory;
15551
15627
  const escalatedRunId = escalation?.runId ?? (escalatedRunDirectory === void 0 ? void 0 : runIdFromRunDirectory(escalatedRunDirectory));
15552
- if (escalatedRunId === void 0) throw new Error("escalated audit has no resumable run identity");
15628
+ if (escalatedRunId === void 0) {
15629
+ return incompleteAuditWithoutOfficerVolume(
15630
+ turn,
15631
+ admitted,
15632
+ io,
15633
+ "escalated audit has no resumable run identity"
15634
+ );
15635
+ }
15553
15636
  const officer = await loadResumablePublicRole(
15554
15637
  env.home,
15555
15638
  escalatedRunId,
@@ -15564,7 +15647,14 @@ async function auditSubmittedRole(turn, env, io, resumedOfficer, passedReceipt)
15564
15647
  { ...await readCurrentCourt(officer.admitted.runDirectory), ...packageFaultScope(officer.admitted, env, io) }
15565
15648
  );
15566
15649
  }
15567
- if (terminal === void 0) throw new Error("escalated audit has no terminal result");
15650
+ if (terminal === void 0) {
15651
+ return incompleteAuditWithoutOfficerVolume(
15652
+ turn,
15653
+ officer.admitted,
15654
+ io,
15655
+ "escalated audit has no terminal result"
15656
+ );
15657
+ }
15568
15658
  await presentTerminal(terminal, { ...io, omitFailureStderrDiagnostic: true }, officer.admitted.runDirectory);
15569
15659
  return { exitCode: 0, admitted: officer.admitted, terminal };
15570
15660
  }
@@ -18866,19 +18956,19 @@ async function runAkRole(argv, env) {
18866
18956
  parts.credentials,
18867
18957
  invocationFromParsed(parsed)
18868
18958
  );
18869
- const result = await runPublicInstructionSeatResume(
18870
- resumeRequest,
18871
- createRoleEnvironment(env, {
18872
- role: seatRole,
18873
- home,
18874
- agentDir: parts.agentDir,
18875
- cwd: parts.cwd,
18876
- credentials: parts.credentials,
18877
- seat,
18878
- config: parts.config
18879
- }),
18880
- io
18881
- );
18959
+ const resumeEnv = createRoleEnvironment(env, {
18960
+ role: seatRole,
18961
+ home,
18962
+ agentDir: parts.agentDir,
18963
+ cwd: parts.cwd,
18964
+ credentials: parts.credentials,
18965
+ seat,
18966
+ config: parts.config
18967
+ });
18968
+ const result = await runPublicInstructionSeatResume(resumeRequest, resumeEnv, io);
18969
+ if (result.admitted?.runId === resumeRequest.runId) {
18970
+ await presentAuditedOriginalOfUnsettledOfficer(result, resumeEnv, io);
18971
+ }
18882
18972
  let current = result;
18883
18973
  while (current.exitCode === 0 && current.admitted?.correlationId !== void 0 && current.terminal?.roleOutcome.kind === "accepted" && current.terminal.roleOutcome.decisiveFacts?.directionUnsettled !== true && !latestPayloadEscalated(current.terminal.roleOutcome)) {
18884
18974
  const parentRunId = current.admitted.correlationId;
@@ -19502,9 +19592,11 @@ async function projectAuditorTerminal(summoned) {
19502
19592
  const outcome = summoned.terminal?.roleOutcome;
19503
19593
  if (outcome === void 0) {
19504
19594
  const detail = summoned.stderr?.trim();
19505
- throw new Error(
19506
- detail && detail.length > 0 ? `Auditor public summon produced no terminal (exit ${summoned.exitCode}: ${detail})` : `Auditor public summon produced no terminal (exit ${summoned.exitCode})`
19507
- );
19595
+ return {
19596
+ status: "transport_failure",
19597
+ diagnostic: detail && detail.length > 0 ? `Auditor public summon produced no terminal (exit ${summoned.exitCode}: ${detail})` : `Auditor public summon produced no terminal (exit ${summoned.exitCode})`,
19598
+ ...summoned.terminal === void 0 ? {} : { terminal: summoned.terminal }
19599
+ };
19508
19600
  }
19509
19601
  const usage = await usageFromSummonedSession(summoned);
19510
19602
  if (outcome.kind === "no_receipt") {
@@ -21065,6 +21157,7 @@ init_engine_material();
21065
21157
  init_engine_detour();
21066
21158
  init_engine_detour_usage();
21067
21159
  init_run_terminal_artifacts();
21160
+ init_serialize_thrown_value();
21068
21161
  import { Type as Type18 } from "typebox";
21069
21162
  var engineDetourArgsSchema = Type18.Object(
21070
21163
  {
@@ -21085,6 +21178,27 @@ function isCallerCancellation(error, signal) {
21085
21178
  function asError(error, fallback) {
21086
21179
  return error instanceof Error ? error : new Error(String(error).trim() || fallback);
21087
21180
  }
21181
+ function engineFailureResult(input) {
21182
+ const details = {
21183
+ tool: ENGINE_DETOUR_TOOL_NAME,
21184
+ ...input.code === void 0 ? {} : { code: input.code },
21185
+ ...input.stdout === void 0 ? {} : { stdout: input.stdout },
21186
+ ...input.stderr === void 0 ? {} : { stderr: input.stderr },
21187
+ ...input.errorCode === void 0 ? {} : { errorCode: input.errorCode },
21188
+ ...input.ledgerError === void 0 ? {} : { ledgerError: input.ledgerError }
21189
+ };
21190
+ let text = input.text;
21191
+ if (input.ledgerError !== void 0 && input.ledgerError.length > 0) {
21192
+ if (text.length > 0 && !text.endsWith("\n")) text += "\n";
21193
+ text += input.ledgerError;
21194
+ }
21195
+ return {
21196
+ content: [{ type: "text", text }],
21197
+ details,
21198
+ // Identified detour failure is a tool error, not a seat-run death (#1213).
21199
+ isError: true
21200
+ };
21201
+ }
21088
21202
  function createEngineDetourToolDefinition(input) {
21089
21203
  const engineName = input.engineName;
21090
21204
  const engineModel = input.engineModel;
@@ -21098,13 +21212,6 @@ function createEngineDetourToolDefinition(input) {
21098
21212
  async execute(toolCallId, params, signal, _onUpdate, ctx) {
21099
21213
  const args = params;
21100
21214
  const argv = Array.isArray(args.argv) ? args.argv : [];
21101
- if (argv.length === 0 || argv.some((part) => typeof part !== "string" || part.length === 0)) {
21102
- input.fail(
21103
- new Error("\u52B3\u52A1\u5F15\u64CE argv \u987B\u4E3A\u975E\u7A7A\u5B57\u7B26\u4E32\u6570\u7EC4"),
21104
- toolCallId,
21105
- ctx
21106
- );
21107
- }
21108
21215
  const sessionParent = ctx.sessionManager?.getSessionFile?.();
21109
21216
  const startedAt = Date.now();
21110
21217
  const runDirectory = typeof ctx.runDirectory === "string" && ctx.runDirectory.length > 0 ? ctx.runDirectory : void 0;
@@ -21125,25 +21232,21 @@ function createEngineDetourToolDefinition(input) {
21125
21232
  ...observed2.stdoutByteLength === void 0 ? {} : { stdoutByteLength: observed2.stdoutByteLength }
21126
21233
  });
21127
21234
  };
21128
- const failAfterLedger = (engineCause, observed2, aggregateMessage) => {
21235
+ const recordCallOrLedgerError = (observed2) => {
21129
21236
  try {
21130
21237
  recordCall(observed2);
21238
+ return void 0;
21131
21239
  } catch (recordError) {
21132
- input.fail(
21133
- new AggregateError(
21134
- [
21135
- engineCause,
21136
- asError(recordError, "engine detour usage ledger write failed")
21137
- ],
21138
- aggregateMessage,
21139
- { cause: engineCause }
21140
- ),
21141
- toolCallId,
21142
- ctx
21143
- );
21240
+ return serializeThrownValue(recordError);
21144
21241
  }
21145
- input.fail(engineCause, toolCallId, ctx);
21146
21242
  };
21243
+ if (argv.length === 0 || argv.some((part) => typeof part !== "string" || part.length === 0)) {
21244
+ const ledgerError = recordCallOrLedgerError({});
21245
+ return engineFailureResult({
21246
+ text: "\u52B3\u52A1\u5F15\u64CE argv \u987B\u4E3A\u975E\u7A7A\u5B57\u7B26\u4E32\u6570\u7EC4",
21247
+ ...ledgerError === void 0 ? {} : { ledgerError }
21248
+ });
21249
+ }
21147
21250
  let result;
21148
21251
  try {
21149
21252
  result = await runEngineDetourOnce({
@@ -21153,20 +21256,26 @@ function createEngineDetourToolDefinition(input) {
21153
21256
  });
21154
21257
  } catch (error) {
21155
21258
  if (isCallerCancellation(error, signal)) throw error;
21156
- return failAfterLedger(
21157
- asError(error, "\u52B3\u52A1\u5F15\u64CE spawn \u5931\u8D25"),
21158
- {},
21159
- "engine detour spawn and usage ledger both failed"
21160
- );
21259
+ const engineError = asError(error, "\u52B3\u52A1\u5F15\u64CE spawn \u5931\u8D25");
21260
+ const ledgerError = recordCallOrLedgerError({});
21261
+ const errno = typeof engineError.code === "string" ? engineError.code : void 0;
21262
+ return engineFailureResult({
21263
+ text: engineError.message,
21264
+ ...errno === void 0 ? {} : { errorCode: errno },
21265
+ ...ledgerError === void 0 ? {} : { ledgerError }
21266
+ });
21161
21267
  }
21162
21268
  const stdoutByteLength = engineDetourStdoutByteLength(result.stdout);
21163
21269
  const observed = { code: result.code, stdoutByteLength };
21164
21270
  if (isEngineDetourFailure(result)) {
21165
- return failAfterLedger(
21166
- new Error(engineDetourFailureDiagnostic(result)),
21167
- observed,
21168
- "engine detour child-close and usage ledger both failed"
21169
- );
21271
+ const ledgerError = recordCallOrLedgerError(observed);
21272
+ return engineFailureResult({
21273
+ text: engineDetourFailureSeatText(result),
21274
+ code: result.code,
21275
+ stdout: result.stdout,
21276
+ stderr: result.stderr,
21277
+ ...ledgerError === void 0 ? {} : { ledgerError }
21278
+ });
21170
21279
  }
21171
21280
  recordCall(observed);
21172
21281
  return {
@@ -21180,7 +21289,7 @@ function createEngineDetourToolDefinition(input) {
21180
21289
  }
21181
21290
  };
21182
21291
  }
21183
- function registerEngineDetourTool(roleHost, hostActions) {
21292
+ function registerEngineDetourTool(roleHost) {
21184
21293
  const getFlag = (name) => roleHost.getFlag(name);
21185
21294
  const engineName = resolveEngineName(getFlag);
21186
21295
  if (engineName === void 0) {
@@ -21189,10 +21298,7 @@ function registerEngineDetourTool(roleHost, hostActions) {
21189
21298
  const engineModel = resolveEngineModel(getFlag);
21190
21299
  const definition = createEngineDetourToolDefinition({
21191
21300
  engineName,
21192
- ...engineModel === void 0 ? {} : { engineModel },
21193
- fail(error, toolCallId, ctx) {
21194
- hostActions.failInfrastructure(error, ctx, toolCallId);
21195
- }
21301
+ ...engineModel === void 0 ? {} : { engineModel }
21196
21302
  });
21197
21303
  roleHost.registerTool(definition);
21198
21304
  return true;
@@ -23137,7 +23243,7 @@ function publicNavigatorSettlement(role, phase, event) {
23137
23243
  }
23138
23244
  return { kind: "accepted", role, phase, ...status === void 0 ? {} : { status } };
23139
23245
  }
23140
- async function projectClosedSubmissionLifecycle(closed, context, phase, recordAccepted, settle) {
23246
+ async function projectClosedSubmissionLifecycle(closed, context, phase, recordAccepted, settle, failRecord) {
23141
23247
  recordAccepted();
23142
23248
  const closure = {
23143
23249
  toolName: navigatorOutputTool(closed.role),
@@ -23148,10 +23254,14 @@ async function projectClosedSubmissionLifecycle(closed, context, phase, recordAc
23148
23254
  try {
23149
23255
  navigator = await settle(publicNavigatorSettlement(closed.role, phase, closure));
23150
23256
  } finally {
23151
- context.sessionManager.appendCustomEntry?.("ak-role-submission-closure", {
23152
- ...closure,
23153
- ...navigator === void 0 ? {} : { navigator }
23154
- });
23257
+ try {
23258
+ context.sessionManager.appendCustomEntry?.("ak-role-submission-closure", {
23259
+ ...closure,
23260
+ ...navigator === void 0 ? {} : { navigator }
23261
+ });
23262
+ } catch (error) {
23263
+ failRecord(error);
23264
+ }
23155
23265
  }
23156
23266
  }
23157
23267
  function createFiledOfficerRuntime(roleHost, spec, dependencies) {
@@ -23339,30 +23449,28 @@ function readDiaristRunCoordinates(ctx) {
23339
23449
  };
23340
23450
  }
23341
23451
  var DIARIST_BOUNDS_REASK = "\u8FB9\u754C\u65E0\u6CD5\u4F7F\u7528\u3002\u591A\u7968\u8BF7\u9010\u7968\u91CD\u4EA4 ticketSessions\uFF0C\u5355\u7968\u91CD\u4EA4 sessions\uFF1B\u6BCF\u5377 path + ranges\uFF0C\u6BCF\u7AEF\u4EE5\u539F\u751F id \u6216\u672C\u8F6E\u884C\u53F7\u4E8C\u9009\u4E00\u6307\u540D\u3002";
23342
- function createDiaristRoleRuntime(roleHost, dependencies) {
23452
+ function createDiaristRoleRuntime(roleHost, dependencies, hostActions) {
23343
23453
  return createFiledOfficerRuntime(
23344
23454
  roleHost,
23345
23455
  {
23346
23456
  role: "diarist",
23347
23457
  tool: DIARIST_TOOL_SPEC,
23348
23458
  soulTag: "diarist",
23349
- beforeAccept: async ({ parameters, ctx }) => {
23459
+ beforeAccept: async ({ toolCallId, parameters, ctx }) => {
23350
23460
  const submitted = isRecord(parameters) ? parameters : void 0;
23351
23461
  const status = submitted?.status;
23352
23462
  if (status !== "completed") return parameters;
23353
23463
  const assertion = readDiaristTicketAssertion(submitted);
23354
23464
  const ticketNumber = assertion.kind === "ticket" ? assertion.ticketNumber : void 0;
23355
- if (ticketNumber !== void 0) {
23356
- await reportTicketFromHostContext(ctx, ticketNumber);
23357
- }
23358
- const coords = readDiaristRunCoordinates(ctx);
23359
- const multiTicket = submitted?.ticketSessions != null;
23360
- const singleSessions = submitted && !multiTicket ? projectDiaristSessions(parameters) : void 0;
23361
- const ticketSessions = submitted && multiTicket ? projectDiaristTicketSessions(submitted) : singleSessions === void 0 ? void 0 : [{ ticketNumber: ticketNumber ?? null, sessions: singleSessions }];
23362
- if (ticketSessions === void 0) {
23363
- throw new ParentQueueReaskError(DIARIST_BOUNDS_REASK);
23364
- }
23365
23465
  try {
23466
+ if (ticketNumber !== void 0) await reportTicketFromHostContext(ctx, ticketNumber);
23467
+ const coords = readDiaristRunCoordinates(ctx);
23468
+ const multiTicket = submitted?.ticketSessions != null;
23469
+ const singleSessions = submitted && !multiTicket ? projectDiaristSessions(parameters) : void 0;
23470
+ const ticketSessions = submitted && multiTicket ? projectDiaristTicketSessions(submitted) : singleSessions === void 0 ? void 0 : [{ ticketNumber: ticketNumber ?? null, sessions: singleSessions }];
23471
+ if (ticketSessions === void 0) {
23472
+ throw new ParentQueueReaskError(DIARIST_BOUNDS_REASK);
23473
+ }
23366
23474
  await commitDiaristProjection({
23367
23475
  cwd: coords.projectRoot,
23368
23476
  home: coords.home,
@@ -23377,7 +23485,7 @@ function createDiaristRoleRuntime(roleHost, dependencies) {
23377
23485
  ${error.message}`
23378
23486
  );
23379
23487
  }
23380
- throw error;
23488
+ hostActions.failInfrastructure(error, ctx, toolCallId);
23381
23489
  }
23382
23490
  return parameters;
23383
23491
  }
@@ -23464,8 +23572,8 @@ function createRoleRuntimeExtension(dependencies, deliveryRequestLimit) {
23464
23572
  }
23465
23573
  return entries;
23466
23574
  }, [])),
23467
- failInfrastructure,
23468
- async (closed, context) => projectClosedSubmission(closed, context)
23575
+ (error, ctx, toolCallId) => hostActions.failInfrastructure(error, ctx, toolCallId),
23576
+ async (closed, context, toolCallId) => projectClosedSubmission(closed, context, toolCallId)
23469
23577
  );
23470
23578
  roleHost.registerFlag(ROLE_FLAG.name, ROLE_FLAG.definition);
23471
23579
  for (const flag of REVIEWER_TRANSPORT_FLAGS) {
@@ -23503,7 +23611,6 @@ function createRoleRuntimeExtension(dependencies, deliveryRequestLimit) {
23503
23611
  let navigatorSessionParent;
23504
23612
  let navigatorCwd;
23505
23613
  const pendingInfrastructureFailures = /* @__PURE__ */ new Map();
23506
- const pendingSubmissionNonPassByToolCallId = /* @__PURE__ */ new Map();
23507
23614
  let engineDetourRegistered = false;
23508
23615
  let receiptDelivery = createReceiptDeliveryPolicy(deliveryLimit);
23509
23616
  let noReceiptRecorded = false;
@@ -23576,13 +23683,14 @@ function createRoleRuntimeExtension(dependencies, deliveryRequestLimit) {
23576
23683
  await pending;
23577
23684
  return pendingNavigatorPresentation?.event;
23578
23685
  };
23579
- projectClosedSubmission = async (closed, context) => {
23686
+ projectClosedSubmission = async (closed, context, toolCallId) => {
23580
23687
  await projectClosedSubmissionLifecycle(
23581
23688
  closed,
23582
23689
  context,
23583
23690
  navigatorPhase(roleHost, closed.role),
23584
23691
  () => receiptDelivery.recordAccepted(),
23585
- settleNavigatorProjection
23692
+ settleNavigatorProjection,
23693
+ (error) => hostActions.failInfrastructure(error, context, toolCallId)
23586
23694
  );
23587
23695
  };
23588
23696
  roleHost.on("input", (event, ctx) => {
@@ -23684,14 +23792,18 @@ function createRoleRuntimeExtension(dependencies, deliveryRequestLimit) {
23684
23792
  }
23685
23793
  }
23686
23794
  const settlement = isRoleInfrastructureFailure || outputClassification?.kind === "infrastructure" ? publicNavigatorSettlement(role, navigatorPhase(roleHost, role), classified) : void 0;
23687
- await settleNavigatorProjection(settlement);
23688
- if (infrastructureDetails !== void 0) {
23689
- return { isError: true };
23795
+ let projectionFailure;
23796
+ try {
23797
+ await settleNavigatorProjection(settlement);
23798
+ } catch (error) {
23799
+ if (infrastructureDetails === void 0) throw error;
23800
+ projectionFailure = errorText(error);
23690
23801
  }
23691
- const submissionNonPass = pendingSubmissionNonPassByToolCallId.get(event.toolCallId);
23692
- if (submissionNonPass !== void 0) {
23693
- pendingSubmissionNonPassByToolCallId.delete(event.toolCallId);
23694
- return { details: submissionNonPass, isError: true };
23802
+ if (infrastructureDetails !== void 0) {
23803
+ return {
23804
+ isError: true,
23805
+ details: projectionFailure === void 0 ? infrastructureDetails : { ...infrastructureDetails, projectionFailure }
23806
+ };
23695
23807
  }
23696
23808
  });
23697
23809
  roleHost.on("agent_end", async (event, ctx) => {
@@ -23707,15 +23819,17 @@ function createRoleRuntimeExtension(dependencies, deliveryRequestLimit) {
23707
23819
  const prose = lastAssistantProse(event.messages);
23708
23820
  if (prose !== void 0 && prose.trim() !== "") {
23709
23821
  const accepted = { prose };
23822
+ const toolCallId = `navigator-prose-exit:${randomUUID7()}`;
23710
23823
  await sealAcceptedSubmission({
23711
23824
  context: ctx,
23712
23825
  role: "navigator",
23713
23826
  accepted,
23714
- toolCallId: `navigator-prose-exit:${randomUUID7()}`
23827
+ toolCallId
23715
23828
  });
23716
23829
  await projectClosedSubmission(
23717
23830
  { role: "navigator", kind: "accepted", accepted },
23718
- ctx
23831
+ ctx,
23832
+ toolCallId
23719
23833
  );
23720
23834
  return;
23721
23835
  }
@@ -23817,7 +23931,6 @@ function createRoleRuntimeExtension(dependencies, deliveryRequestLimit) {
23817
23931
  pendingNavigatorSettlement = void 0;
23818
23932
  disposeNavigatorAttendanceNonBlocking(attendanceToDispose);
23819
23933
  pendingInfrastructureFailures.clear();
23820
- pendingSubmissionNonPassByToolCallId.clear();
23821
23934
  }
23822
23935
  });
23823
23936
  const hostActions = {
@@ -23826,9 +23939,6 @@ function createRoleRuntimeExtension(dependencies, deliveryRequestLimit) {
23826
23939
  pendingInfrastructureFailures.set(toolCallId, buildPendingInfrastructureFailure(error));
23827
23940
  }
23828
23941
  failInfrastructure(error, ctx);
23829
- },
23830
- bindSubmissionNonPass(toolCallId, result) {
23831
- pendingSubmissionNonPassByToolCallId.set(toolCallId, result);
23832
23942
  }
23833
23943
  };
23834
23944
  const requireRoleSoul = (role) => dependencies.loadRoleSoul(role);
@@ -23908,7 +24018,8 @@ function createRoleRuntimeExtension(dependencies, deliveryRequestLimit) {
23908
24018
  roleHost,
23909
24019
  {
23910
24020
  loadSoul: () => requireRoleSoul("diarist")
23911
- }
24021
+ },
24022
+ hostActions
23912
24023
  );
23913
24024
  const secretariat = createSecretariatRoleRuntime(roleHost, {
23914
24025
  loadSoul: () => requireRoleSoul("secretariat")
@@ -24006,7 +24117,6 @@ function createRoleRuntimeExtension(dependencies, deliveryRequestLimit) {
24006
24117
  navigatorDeliveryClosed = false;
24007
24118
  pendingNavigatorSettlement = void 0;
24008
24119
  pendingInfrastructureFailures.clear();
24009
- pendingSubmissionNonPassByToolCallId.clear();
24010
24120
  navigatorWorkContext = void 0;
24011
24121
  envelopeHost.startKeepalive(ctx);
24012
24122
  const rawRole = roleHost.getFlag(ROLE_FLAG.name);
@@ -24122,13 +24232,13 @@ function createRoleRuntimeExtension(dependencies, deliveryRequestLimit) {
24122
24232
  }
24123
24233
  }
24124
24234
  await executeActivationStage(entry.role, activationStage(entry.role, activateByRole), { clock, writeTrace });
24125
- registerReportTicketTool(roleHost);
24235
+ registerReportTicketTool(roleHost, hostActions);
24126
24236
  roleHost.setActiveTools([
24127
24237
  .../* @__PURE__ */ new Set([...roleHost.getActiveTools(), REPORT_TICKET_TOOL_NAME])
24128
24238
  ]);
24129
24239
  roleReferenceMaterials = await dependencies.loadRoleReferenceMaterials?.(entry.role) ?? "";
24130
24240
  if (!engineDetourRegistered) {
24131
- engineDetourRegistered = registerEngineDetourTool(roleHost, hostActions);
24241
+ engineDetourRegistered = registerEngineDetourTool(roleHost);
24132
24242
  }
24133
24243
  if (secretariat.claimsEngineDetour === true && engineDetourRegistered) {
24134
24244
  roleHost.setActiveTools([
@@ -24372,19 +24482,6 @@ async function prepareRoleEnvelope(options) {
24372
24482
  )(envelope);
24373
24483
  const token = randomUUID9();
24374
24484
  const server = createServer((socket) => serveSocket(socket));
24375
- function rememberProjectedRejection(details, toolCallId, content) {
24376
- if (typeof details !== "object" || details === null) return;
24377
- const record = details;
24378
- if (record.cause === "infrastructure") return;
24379
- if (record.kind === "role_infrastructure_failure") return;
24380
- const code = typeof record.code === "string" && record.code.length > 0 ? record.code : record.status === "continue" || record.status === "escalate" || record.status === "no_receipt" ? record.status : void 0;
24381
- if (code === void 0) return;
24382
- rejection = {
24383
- code,
24384
- toolCallIds: [toolCallId],
24385
- message: textDiagnostic(content) ?? code
24386
- };
24387
- }
24388
24485
  function textDiagnostic(content) {
24389
24486
  const text = content.filter((part) => part.type === "text").map((part) => part.text).join("\n\n");
24390
24487
  return text.trim().length > 0 ? text : void 0;
@@ -24455,7 +24552,6 @@ async function prepareRoleEnvelope(options) {
24455
24552
  sessionEntries.push(toolResultEntry);
24456
24553
  if (projected.isError) {
24457
24554
  rememberInfrastructureFailure(projected.details, projected.content);
24458
- rememberProjectedRejection(projected.details, toolCallId, projected.content);
24459
24555
  }
24460
24556
  await emit("tool_execution_end", { toolCallId, toolName, isError: projected.isError });
24461
24557
  return projected;
@@ -24501,7 +24597,7 @@ async function prepareRoleEnvelope(options) {
24501
24597
  const projected = await projectToolResult(toolCallId, name, {
24502
24598
  content: result.content,
24503
24599
  details: result.details,
24504
- isError: false
24600
+ isError: result.isError === true
24505
24601
  });
24506
24602
  if (result.terminate === false) {
24507
24603
  rejection = {
@@ -24514,18 +24610,31 @@ async function prepareRoleEnvelope(options) {
24514
24610
  } catch (error) {
24515
24611
  let content;
24516
24612
  let details;
24517
- if (isCorrectableExecuteError(error)) {
24518
- const projected2 = projectCorrectableExecuteRejection(error);
24519
- content = [{ type: "text", text: projected2.diagnostic }];
24520
- details = projected2.details;
24613
+ const correctable = isCorrectableExecuteError(error) ? projectCorrectableExecuteRejection(error) : void 0;
24614
+ if (correctable !== void 0) {
24615
+ content = [{ type: "text", text: correctable.diagnostic }];
24616
+ details = correctable.details;
24521
24617
  } else {
24522
- ({ content, details } = declareRoundInfrastructureFailure(error));
24618
+ const diagnostic = errorText(error);
24619
+ content = [{ type: "text", text: diagnostic }];
24620
+ details = {
24621
+ code: typeof error?.code === "string" ? error.code : "ak-tool-execution-failed",
24622
+ error: serializeThrownValue(error)
24623
+ };
24523
24624
  }
24524
24625
  const projected = await projectToolResult(toolCallId, name, {
24525
24626
  content,
24526
24627
  details,
24527
24628
  isError: true
24528
24629
  });
24630
+ if (correctable !== void 0) {
24631
+ const code = typeof correctable.details.code === "string" && correctable.details.code.length > 0 ? correctable.details.code : "correctable-submission-error";
24632
+ rejection = {
24633
+ code,
24634
+ toolCallIds: [toolCallId],
24635
+ message: textDiagnostic(projected.content) ?? correctable.diagnostic
24636
+ };
24637
+ }
24529
24638
  return { content: projected.content, isError: projected.isError };
24530
24639
  }
24531
24640
  }