@akagilnc/pi-workflow-roles 0.1.5805 → 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 (74) hide show
  1. package/dist/acp-host/production-host.js +390 -306
  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/factory-board.js +1478 -0
  23. package/dist/fixer-bash-seatbelt.js +13 -0
  24. package/dist/gatekeeper-role.js +1 -2
  25. package/dist/gh-api-runner.js +81 -0
  26. package/dist/gleaner-left-role.js +8 -0
  27. package/dist/headless-host/production-host.js +390 -306
  28. package/dist/headless-host/role-turn-host.js +691 -0
  29. package/dist/human-format.js +67 -0
  30. package/dist/inspector-role.js +12 -0
  31. package/dist/judge-recording-anti-forge.js +39 -0
  32. package/dist/judge-role.js +21 -3
  33. package/dist/merger-role.js +57 -0
  34. package/dist/migrate-book-topology.js +0 -2
  35. package/dist/navigator-role.js +6 -0
  36. package/dist/navigator-work-context.js +72 -0
  37. package/dist/notary-role.js +113 -0
  38. package/dist/oauth-keepalive.js +149 -0
  39. package/dist/package-contracts/terminating-infrastructure.js +0 -35
  40. package/dist/pi/adapter.js +272 -0
  41. package/dist/public-cli/cli.js +9 -3
  42. package/dist/public-cli/instruction-seat-run.js +163 -44
  43. package/dist/public-cli/main.js +241 -123
  44. package/dist/report-ticket-tool.js +24 -13
  45. package/dist/reviewer-role.js +33 -0
  46. package/dist/role-envelope.js +707 -0
  47. package/dist/role-runtime-dependencies.js +57 -0
  48. package/dist/role-runtime.js +1476 -0
  49. package/dist/secretariat-role.js +5 -0
  50. package/dist/stderr-jsonl.js +26 -0
  51. package/dist/submission-correctable-error.js +2 -6
  52. package/dist/submission-errors.js +0 -30
  53. package/dist/submission-gate.js +61 -54
  54. package/dist/submission-ledger.js +105 -98
  55. package/dist/ticket-snapshot.js +486 -0
  56. package/dist/ticket-trajectory.js +843 -0
  57. package/dist/worker-role.js +184 -0
  58. package/dist/worker-submission-gates.js +333 -0
  59. package/package.json +1 -1
  60. package/src/compliance-transport.ts +7 -3
  61. package/src/gatekeeper-role.ts +1 -15
  62. package/src/host-contracts.ts +2 -12
  63. package/src/judge-role.ts +30 -7
  64. package/src/package-contracts/terminating-infrastructure.ts +8 -81
  65. package/src/pi/adapter.ts +0 -1
  66. package/src/public-cli/cli.ts +21 -14
  67. package/src/public-cli/instruction-seat-run.ts +227 -44
  68. package/src/report-ticket-tool.ts +27 -13
  69. package/src/role-envelope.ts +32 -34
  70. package/src/role-runtime.ts +62 -55
  71. package/src/submission-correctable-error.ts +1 -6
  72. package/src/submission-errors.ts +0 -34
  73. package/src/submission-gate.ts +71 -56
  74. package/src/submission-ledger.ts +109 -104
@@ -1535,43 +1535,10 @@ function withTerminatingOutputDeclarations(schema) {
1535
1535
  object.required = preserved;
1536
1536
  return object;
1537
1537
  }
1538
- function isInfrastructureFailureDeclaration(parameters) {
1539
- if (!isRecord(parameters)) return false;
1540
- if (!Object.hasOwn(parameters, INFRASTRUCTURE_FAILURE_DECLARATION_KEY)) return false;
1541
- const declaration = parameters[INFRASTRUCTURE_FAILURE_DECLARATION_KEY];
1542
- if (!isRecord(declaration)) return false;
1543
- const diagnostic = declaration[INFRASTRUCTURE_FAILURE_DIAGNOSTIC_KEY];
1544
- return typeof diagnostic === "string" && diagnostic.trim().length > 0;
1545
- }
1546
- function infrastructureFailureDiagnostic(parameters) {
1547
- if (!isInfrastructureFailureDeclaration(parameters)) return void 0;
1548
- const declaration = parameters[INFRASTRUCTURE_FAILURE_DECLARATION_KEY];
1549
- const diagnostic = declaration[INFRASTRUCTURE_FAILURE_DIAGNOSTIC_KEY];
1550
- return typeof diagnostic === "string" ? diagnostic.trim() : void 0;
1551
- }
1552
- function infrastructureFailureError(diagnostic) {
1553
- const error = new Error(diagnostic);
1554
- error.name = "InfrastructureFailure";
1555
- return error;
1556
- }
1557
- function failOnInfrastructureFailureDeclaration(parameters, hostActions, ctx, toolCallId, bounceInfrastructureDeclaration) {
1558
- const diagnostic = infrastructureFailureDiagnostic(parameters);
1559
- if (diagnostic === void 0) return;
1560
- if (bounceInfrastructureDeclaration !== void 0) {
1561
- const bounce = bounceInfrastructureDeclaration(parameters, toolCallId, ctx);
1562
- if (bounce !== void 0) throw bounce;
1563
- }
1564
- hostActions.failInfrastructure(
1565
- infrastructureFailureError(diagnostic),
1566
- ctx,
1567
- toolCallId
1568
- );
1569
- }
1570
1538
  var INFRASTRUCTURE_FAILURE_DECLARATION_KEY, INFRASTRUCTURE_FAILURE_DIAGNOSTIC_KEY, infrastructureFailureNested, infrastructureFailureDeclarationSchema;
1571
1539
  var init_terminating_infrastructure = __esm({
1572
1540
  "src/package-contracts/terminating-infrastructure.ts"() {
1573
1541
  "use strict";
1574
- init_unknown_value();
1575
1542
  INFRASTRUCTURE_FAILURE_DECLARATION_KEY = "infrastructureFailure";
1576
1543
  INFRASTRUCTURE_FAILURE_DIAGNOSTIC_KEY = "diagnostic";
1577
1544
  infrastructureFailureNested = Type2.Object(
@@ -3106,20 +3073,6 @@ var init_readable_gate_item = __esm({
3106
3073
  });
3107
3074
 
3108
3075
  // src/submission-errors.ts
3109
- function serializeReceipt(receipt) {
3110
- return readableGateItem(receipt);
3111
- }
3112
- function gatekeeperNonPassMessage(result) {
3113
- if (result.status === "continue") {
3114
- return serializeReceipt(result.receipt);
3115
- }
3116
- if (result.status === "transport_failure") {
3117
- const head = `\u95E8\u4E0B\u7701 ${result.status}\uFF08${result.stage}\uFF09\uFF1A${result.reason}`;
3118
- return result.submission === void 0 ? head : `${head}
3119
- ${serializeReceipt(result.submission)}`;
3120
- }
3121
- return `\u95E8\u4E0B\u7701 ${result.status}\uFF08${result.stage}\uFF09\uFF1A${result.reason}`;
3122
- }
3123
3076
  function isOneShotWorkerReminderCode(code) {
3124
3077
  return code === "worker_commit_reminder" || code === "worker_prefix_reminder";
3125
3078
  }
@@ -3132,20 +3085,12 @@ function receivedDiscriminator(receipt, field) {
3132
3085
  if (!Object.hasOwn(receipt, field)) return void 0;
3133
3086
  return receipt[field];
3134
3087
  }
3135
- var GatekeeperDecisionError, WorkerCommitReminderError, WorkerPrefixReminderError, WorkerUnfinishedReasonReminderError, ParentQueueReaskError;
3088
+ var WorkerCommitReminderError, WorkerPrefixReminderError, WorkerUnfinishedReasonReminderError, ParentQueueReaskError;
3136
3089
  var init_submission_errors = __esm({
3137
3090
  "src/submission-errors.ts"() {
3138
3091
  "use strict";
3139
3092
  init_readable_gate_item();
3140
3093
  init_unknown_value();
3141
- GatekeeperDecisionError = class extends Error {
3142
- result;
3143
- constructor(result, message) {
3144
- super(message ?? gatekeeperNonPassMessage(result));
3145
- this.name = "GatekeeperDecisionError";
3146
- this.result = result;
3147
- }
3148
- };
3149
3094
  WorkerCommitReminderError = class extends Error {
3150
3095
  code = "worker_commit_reminder";
3151
3096
  constructor() {
@@ -3703,7 +3648,6 @@ var init_gatekeeper_role = __esm({
3703
3648
  init_run_terminal_artifacts();
3704
3649
  init_unknown_value();
3705
3650
  init_serialize_thrown_value();
3706
- init_submission_errors();
3707
3651
  GATE_OFFICER_BY_SUBJECT = {
3708
3652
  worker_completion: "inspector",
3709
3653
  judge_compliance: "auditor",
@@ -4483,13 +4427,10 @@ function isCorrectableSubmissionError(error) {
4483
4427
  return error instanceof CorrectableSubmissionError;
4484
4428
  }
4485
4429
  function isCorrectableExecuteError(error) {
4486
- 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;
4487
4431
  }
4488
4432
  function projectCorrectableExecuteRejection(error) {
4489
4433
  const diagnostic = errorText(error);
4490
- if (error instanceof GatekeeperDecisionError) {
4491
- return { diagnostic, details: { ...error.result } };
4492
- }
4493
4434
  if (error instanceof WorkerCommitReminderError || error instanceof WorkerPrefixReminderError || error instanceof WorkerUnfinishedReasonReminderError) {
4494
4435
  return { diagnostic, details: { code: error.code } };
4495
4436
  }
@@ -8243,11 +8184,7 @@ function admittedForLiveTicketReport(runDirectory, authority) {
8243
8184
  ...ticketNumber === void 0 ? {} : { ticketNumber }
8244
8185
  };
8245
8186
  }
8246
- async function reportTicketFromHostContext(context, rawTicketNumber, authority = piDurablePrincipalAuthority) {
8247
- const ticketNumber = readDeclaredTicketNumber(rawTicketNumber);
8248
- if (ticketNumber === void 0) {
8249
- throw new Error("ak_report_ticket requires an identifiable ticketNumber");
8250
- }
8187
+ async function reportTicketFromHostContext(context, ticketNumber, authority = piDurablePrincipalAuthority) {
8251
8188
  const runDirectory = runDirectoryFromHostContext(context);
8252
8189
  if (runDirectory === void 0) {
8253
8190
  throw new Error("ak_report_ticket requires a per-turn run directory");
@@ -8283,7 +8220,7 @@ async function reportTicketFromHostContext(context, rawTicketNumber, authority =
8283
8220
  relocated: relocation !== void 0
8284
8221
  };
8285
8222
  }
8286
- function registerReportTicketTool(roleHost) {
8223
+ function registerReportTicketTool(roleHost, hostActions) {
8287
8224
  if (roleHost.getAllTools().some((tool) => tool.name === REPORT_TICKET_TOOL_NAME)) return;
8288
8225
  roleHost.registerTool({
8289
8226
  name: REPORT_TICKET_TOOL_NAME,
@@ -8291,13 +8228,21 @@ function registerReportTicketTool(roleHost) {
8291
8228
  description: REPORT_TICKET_TOOL_DESCRIPTION,
8292
8229
  promptSnippet: "\u5DF2\u77E5\u7968\u53F7\u65F6\u7ACB\u5373\u7533\u62A5\uFF0C\u5305\u5F53\u573A\u5F52\u4F4D",
8293
8230
  parameters: reportTicketArgsSchema,
8294
- async execute(_toolCallId, parameters, _signal, _onUpdate, ctx) {
8231
+ async execute(toolCallId, parameters, _signal, _onUpdate, ctx) {
8295
8232
  const raw = isRecord(parameters) ? parameters.ticketNumber : void 0;
8296
- const details = await reportTicketFromHostContext(ctx, raw);
8297
- return {
8298
- content: [],
8299
- details
8300
- };
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
+ }
8301
8246
  }
8302
8247
  });
8303
8248
  }
@@ -8490,6 +8435,14 @@ async function readAttemptScopedSubmissionRows(cwd, runId, attemptId, homeOrScop
8490
8435
  const { owned } = await readOwnedSubmissionRecords(cwd, runId, scope);
8491
8436
  return mapOwnedToSubmissionRows(owned.filter((record) => recordAttemptId(record) === attemptId));
8492
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
+ }
8493
8446
  async function readRecordedSubmissions(cwd, runId, homeOrScope) {
8494
8447
  return (await readRecordedSubmissionRows(cwd, runId, homeOrScope)).map((row) => row.accepted);
8495
8448
  }
@@ -8613,89 +8566,82 @@ function createSubmissionLedgerHost(host, outputTools, failInfrastructure2 = (er
8613
8566
  host.registerTool({
8614
8567
  ...tool,
8615
8568
  async execute(toolCallId, params, signal, update, context) {
8616
- const typedTicket = isRecord(params) ? readDeclaredTicketNumber(params.ticketNumber) : void 0;
8617
- if (typedTicket !== void 0) {
8618
- await reportTicketFromHostContext(context, typedTicket);
8619
- }
8620
- const runId = runIdentity(context);
8621
- const attemptId = attemptIdentity(context, runId);
8622
- const state = await stateFor(context, runId);
8623
- const append = (event) => appendFor(context, runId, attemptId, event);
8624
- append({
8625
- type: "candidate",
8626
- attemptId,
8627
- toolCallId,
8628
- toolName: tool.name,
8629
- sequence: ++state.sequence,
8630
- role,
8631
- params
8632
- });
8569
+ let toolThrew = false;
8633
8570
  let result;
8571
+ let closed;
8634
8572
  try {
8635
- const reviewEscalate = tool.name === REVIEW_SUBMISSION_OUTPUT_TOOL_NAME && infrastructureFailureDiagnostic(params) !== void 0 && isRecord(params) && params.status === "escalate";
8636
- if (!reviewEscalate) {
8637
- failOnInfrastructureFailureDeclaration(
8638
- params,
8639
- {
8640
- failInfrastructure(error, ctx) {
8641
- failInfrastructure2(error, ctx);
8642
- }
8643
- },
8644
- context,
8645
- toolCallId,
8646
- tool.bounceInfrastructureDeclaration
8647
- );
8573
+ const typedTicket = isRecord(params) ? readDeclaredTicketNumber(params.ticketNumber) : void 0;
8574
+ if (typedTicket !== void 0) {
8575
+ await reportTicketFromHostContext(context, typedTicket);
8648
8576
  }
8649
- result = await tool.execute(toolCallId, params, signal, update, context);
8650
- } catch (error) {
8651
- if (isCorrectableExecuteError(error)) {
8652
- append({
8653
- type: "outcome",
8654
- attemptId,
8655
- toolCallId,
8656
- outcome: "correctable-rejection",
8657
- code: "typed-bounce",
8658
- diagnostic: errorText(error),
8659
- role,
8660
- accepted: params
8661
- });
8662
- throw error;
8663
- } else {
8664
- append({
8665
- type: "outcome",
8666
- attemptId,
8667
- toolCallId,
8668
- outcome: "infrastructure",
8669
- diagnostic: errorText(error),
8670
- role,
8671
- accepted: params
8672
- });
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;
8673
8616
  throw error;
8674
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);
8675
8643
  }
8676
- if (result.terminate === false) return result;
8677
- const closed = {
8678
- role,
8679
- kind: "accepted",
8680
- accepted: params
8681
- };
8682
- const sealHead = captureWorktreeHead(context.cwd);
8683
- append({
8684
- type: "sealed",
8685
- attemptId,
8686
- toolCallId,
8687
- role,
8688
- accepted: params
8689
- });
8690
- const rawLens = typeof host.getFlag === "function" ? host.getFlag("ak-review-lens") : void 0;
8691
- landTicketProgressForSealedSubmission({
8692
- context,
8693
- role,
8694
- accepted: params,
8695
- sealHead,
8696
- ...rawLens === "completeness" || rawLens === "correctness" ? { lens: rawLens } : {}
8697
- });
8698
- await projectClosure(closed, context);
8644
+ await projectClosure(closed, context, toolCallId);
8699
8645
  return result;
8700
8646
  }
8701
8647
  });
@@ -8712,9 +8658,7 @@ var init_submission_ledger = __esm({
8712
8658
  init_sitian_facade();
8713
8659
  init_run_lifecycle();
8714
8660
  init_submission_correctable_error();
8715
- init_terminating_infrastructure();
8716
8661
  init_report_ticket_tool();
8717
- init_review_submission();
8718
8662
  init_run_ticket_number();
8719
8663
  init_ticket_progress();
8720
8664
  init_unknown_value();
@@ -12064,11 +12008,21 @@ async function runJudgeGates(input) {
12064
12008
  if (await input.gateAlreadyConverged(subject)) continue;
12065
12009
  const pass = await input.runGate(subject);
12066
12010
  const received = pass?.status;
12067
- if (pass === void 0 || (typeof received !== "string" || !REVIEW_QUEUE_STATUSES.has(received) && received !== "needs_reask")) {
12068
- 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
+ };
12069
12023
  }
12070
12024
  const status = received;
12071
- if (status === "needs_reask") {
12025
+ if (status === "needs_reask" || status === "transport_failure" || status === "no_receipt") {
12072
12026
  return {
12073
12027
  status,
12074
12028
  passes: [{
@@ -12077,7 +12031,8 @@ async function runJudgeGates(input) {
12077
12031
  receipt: pass.receipt,
12078
12032
  ...pass.runId === void 0 ? {} : { runId: pass.runId },
12079
12033
  ...pass.runDirectory === void 0 ? {} : { runDirectory: pass.runDirectory },
12080
- ...pass.terminal === void 0 ? {} : { terminal: pass.terminal }
12034
+ ...pass.terminal === void 0 ? {} : { terminal: pass.terminal },
12035
+ ...pass.reason === void 0 ? {} : { reason: pass.reason }
12081
12036
  }]
12082
12037
  };
12083
12038
  }
@@ -12086,7 +12041,8 @@ async function runJudgeGates(input) {
12086
12041
  status,
12087
12042
  receipt: pass.receipt,
12088
12043
  ...pass.runId === void 0 ? {} : { runId: pass.runId },
12089
- ...pass.runDirectory === void 0 ? {} : { runDirectory: pass.runDirectory }
12044
+ ...pass.runDirectory === void 0 ? {} : { runDirectory: pass.runDirectory },
12045
+ ...pass.terminal === void 0 ? {} : { terminal: pass.terminal }
12090
12046
  });
12091
12047
  if (status === "continue" || status === "escalate") return { status, passes };
12092
12048
  }
@@ -12199,6 +12155,17 @@ function createDefaultGateOfficerSummon(options) {
12199
12155
  });
12200
12156
  };
12201
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
+ }
12202
12169
  async function requireSubmissionGate(options) {
12203
12170
  let reask;
12204
12171
  let reasksSpent = 0;
@@ -12216,7 +12183,7 @@ async function requireSubmissionGate(options) {
12216
12183
  ...reask === void 0 ? {} : { reask }
12217
12184
  });
12218
12185
  const gatekeeper = projected.result;
12219
- 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")) {
12220
12187
  const officerRunDirectory = await directoryForSummonedOfficer(
12221
12188
  projected.officer,
12222
12189
  projected.summoned
@@ -12226,61 +12193,69 @@ async function requireSubmissionGate(options) {
12226
12193
  }
12227
12194
  }
12228
12195
  if (gatekeeper.status === "converged") {
12229
- return {
12196
+ return presentGateOutcome({
12230
12197
  status: "converged",
12231
12198
  officer: projected.officer,
12232
12199
  receipt: gatekeeper.receipt,
12233
- ...typeof gatekeeper.runId === "string" && gatekeeper.runId.trim() !== "" ? { runId: gatekeeper.runId } : {},
12234
- ...typeof projected.summoned?.runDirectory === "string" && projected.summoned.runDirectory.trim() !== "" ? { runDirectory: projected.summoned.runDirectory } : {},
12235
- // Keep the officer terminal for escalate / unsettled surfaces; parent
12236
- // finals do not project other-seat tables (#1195).
12237
- ...projected.summoned?.terminal === void 0 ? {} : { terminal: projected.summoned.terminal }
12238
- };
12200
+ runId: gatekeeper.runId,
12201
+ runDirectory: projected.summoned?.runDirectory,
12202
+ terminal: projected.summoned?.terminal
12203
+ });
12239
12204
  }
12240
12205
  if (gatekeeper.status === "continue") {
12241
- return {
12206
+ return presentGateOutcome({
12242
12207
  status: "continue",
12243
12208
  officer: projected.officer,
12244
12209
  receipt: gatekeeper.receipt,
12245
- ...typeof gatekeeper.runId === "string" && gatekeeper.runId.trim() !== "" ? { runId: gatekeeper.runId } : {}
12246
- };
12210
+ runId: gatekeeper.runId
12211
+ });
12247
12212
  }
12248
12213
  if (gatekeeper.status === "needs_reask") {
12249
12214
  const nestedIncomplete = projected.summoned?.terminal?.roleOutcome.kind === "accepted" && projected.summoned.terminal.roleOutcome.decisiveFacts?.directionUnsettled === true;
12250
12215
  if (nestedIncomplete || reasksSpent >= reaskLimit) {
12251
- return {
12216
+ return presentGateOutcome({
12252
12217
  status: "needs_reask",
12253
12218
  officer: projected.officer,
12254
12219
  receipt: gatekeeper.receipt,
12255
- ...typeof gatekeeper.runId === "string" && gatekeeper.runId.trim() !== "" ? { runId: gatekeeper.runId } : {},
12256
- ...typeof projected.summoned?.runDirectory === "string" && projected.summoned.runDirectory.trim() !== "" ? { runDirectory: projected.summoned.runDirectory } : {},
12257
- ...projected.summoned?.terminal === void 0 ? {} : { terminal: projected.summoned.terminal }
12258
- };
12220
+ runId: gatekeeper.runId,
12221
+ runDirectory: projected.summoned?.runDirectory,
12222
+ terminal: projected.summoned?.terminal
12223
+ });
12259
12224
  }
12260
12225
  reasksSpent += 1;
12261
12226
  reask = officerConclusionReask(gatekeeper.receivedStatus);
12262
12227
  continue;
12263
12228
  }
12264
12229
  if (gatekeeper.status === "transport_failure") {
12265
- const failure = Object.assign(new Error(gatekeeper.reason), {
12266
- name: "GatekeeperTransportFailure",
12267
- ...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
12268
12238
  });
12269
- options.hostActions.failInfrastructure(failure, options.context, options.toolCallId);
12270
12239
  }
12271
12240
  if (gatekeeper.status === "escalate") {
12272
- return {
12241
+ return presentGateOutcome({
12273
12242
  status: "escalate",
12274
12243
  officer: projected.officer,
12275
12244
  receipt: gatekeeper.receipt,
12276
- ...typeof gatekeeper.runId === "string" && gatekeeper.runId.trim() !== "" ? { runId: gatekeeper.runId } : {},
12277
- ...typeof projected.summoned?.runDirectory === "string" && projected.summoned.runDirectory.trim() !== "" ? { runDirectory: projected.summoned.runDirectory } : {},
12278
- // Keep the actual officer terminal so callers resume that seat.
12279
- ...projected.summoned?.terminal === void 0 ? {} : { terminal: projected.summoned.terminal }
12280
- };
12245
+ runId: gatekeeper.runId,
12246
+ runDirectory: projected.summoned?.runDirectory,
12247
+ terminal: projected.summoned?.terminal
12248
+ });
12281
12249
  }
12282
- options.hostActions.bindSubmissionNonPass(options.toolCallId, gatekeeper);
12283
- 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
+ });
12284
12259
  }
12285
12260
  }
12286
12261
  var init_submission_gate = __esm({
@@ -14306,6 +14281,7 @@ __export(instruction_seat_run_exports, {
14306
14281
  NOTARY_FIXED_DISPATCH: () => NOTARY_FIXED_DISPATCH,
14307
14282
  buildInstructionSeatTurnRequest: () => buildInstructionSeatTurnRequest,
14308
14283
  continueParentAfterChild: () => continueParentAfterChild,
14284
+ presentAuditedOriginalOfUnsettledOfficer: () => presentAuditedOriginalOfUnsettledOfficer,
14309
14285
  resolveReviewSeatDialogueBody: () => resolveReviewSeatDialogueBody,
14310
14286
  runPublicInstructionSeat: () => runPublicInstructionSeat,
14311
14287
  runPublicInstructionSeatResume: () => runPublicInstructionSeatResume
@@ -14369,6 +14345,60 @@ async function presentUnsettledOfficer(officer, io, runDirectory) {
14369
14345
  await presentTerminal(terminal, { ...io, omitFailureStderrDiagnostic: true }, runDirectory);
14370
14346
  return terminal;
14371
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
+ }
14372
14402
  async function reaskUnreadablePostSubmissionStatus(admitted, terminal, env, io, message = unreadablePostSubmissionStatus(admitted, terminal)) {
14373
14403
  if (message === void 0) return void 0;
14374
14404
  const next = withUnreadableReask(env);
@@ -15235,7 +15265,7 @@ async function queueConclusionFromChild(child, env, io) {
15235
15265
  if (terminal !== void 0 && typeof status === "string" && REVIEW_QUEUE_STATUSES.has(status)) {
15236
15266
  return { admitted: child, terminal, status };
15237
15267
  }
15238
- return { stop: { exitCode: 0, ...terminal === void 0 ? {} : { terminal } } };
15268
+ return { stop: { exitCode: 0, admitted: child, ...terminal === void 0 ? {} : { terminal } } };
15239
15269
  }
15240
15270
  let current = child;
15241
15271
  let budgetEnv = envForCourtContinue(env);
@@ -15257,7 +15287,7 @@ async function queueConclusionFromChild(child, env, io) {
15257
15287
  officerConclusionReask(status)
15258
15288
  );
15259
15289
  if (reasked === void 0 || isUnreadableReaskExhausted(reasked)) {
15260
- return { stop: { exitCode: 0, ...terminal === void 0 ? {} : { terminal } } };
15290
+ return { stop: { exitCode: 0, admitted: current, ...terminal === void 0 ? {} : { terminal } } };
15261
15291
  }
15262
15292
  budgetEnv = withUnreadableReask(budgetEnv);
15263
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) {
@@ -15293,6 +15323,9 @@ async function continueParentAfterChild(parentRunId, child, env, io) {
15293
15323
  const resolved = await queueConclusionFromChild(child, env, io);
15294
15324
  if (resolved !== void 0 && "stop" in resolved) {
15295
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
+ }
15296
15329
  if (stopped.exitCode === 0 && heldUnreadableTerminal(stopped.terminal) && stopped.terminal !== void 0 && stopped.admitted !== void 0) {
15297
15330
  const terminal = await presentUnsettledOfficer(
15298
15331
  stopped.terminal,
@@ -15460,20 +15493,27 @@ async function auditSubmittedRole(turn, env, io, resumedOfficer, passedReceipt)
15460
15493
  }, envForCourtContinue(env), io);
15461
15494
  }
15462
15495
  if (decision.status === "received") {
15463
- if (lastSummon?.terminal === void 0) {
15464
- 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
+ };
15465
15506
  }
15466
- const officerAdmitted = lastSummon.admitted;
15467
- const officerDir = officerAdmitted?.runDirectory ?? lastSummon.runDirectory ?? admitted.runDirectory;
15468
- const terminal = await presentUnsettledOfficer(lastSummon.terminal, io, officerDir);
15469
- return {
15470
- exitCode: 0,
15471
- ...officerAdmitted === void 0 ? { admitted } : { admitted: officerAdmitted },
15472
- terminal
15473
- };
15507
+ return incompleteAuditWithoutOfficerVolume(
15508
+ turn,
15509
+ admitted,
15510
+ io,
15511
+ "doctor audit kept an unreadable reply with no terminal"
15512
+ );
15474
15513
  }
15475
15514
  if (decision.status !== "converged") {
15476
15515
  if (lastSummon?.terminal !== void 0) {
15516
+ await presentAuditedOriginalVolume(turn, io);
15477
15517
  await presentTerminal(lastSummon.terminal, { ...io, omitFailureStderrDiagnostic: true }, lastSummon.admitted?.runDirectory ?? admitted.runDirectory);
15478
15518
  return {
15479
15519
  exitCode: lastSummon.exitCode,
@@ -15481,7 +15521,8 @@ async function auditSubmittedRole(turn, env, io, resumedOfficer, passedReceipt)
15481
15521
  terminal: lastSummon.terminal
15482
15522
  };
15483
15523
  }
15484
- 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);
15485
15526
  }
15486
15527
  }
15487
15528
  } else {
@@ -15500,14 +15541,7 @@ async function auditSubmittedRole(turn, env, io, resumedOfficer, passedReceipt)
15500
15541
  submission: accepted,
15501
15542
  summonOfficer,
15502
15543
  ...env.autoResumeLimit === void 0 ? {} : { autoResumeLimit: env.autoResumeLimit },
15503
- ...env.signal === void 0 ? {} : { signal: env.signal },
15504
- hostActions: {
15505
- failInfrastructure(error) {
15506
- throw error;
15507
- },
15508
- bindSubmissionNonPass() {
15509
- }
15510
- }
15544
+ ...env.signal === void 0 ? {} : { signal: env.signal }
15511
15545
  });
15512
15546
  if (admitted.role === "judge") {
15513
15547
  const judgeGateOrder = JUDGE_GATES.map(gateOfficerForSubject);
@@ -15522,45 +15556,83 @@ async function auditSubmittedRole(turn, env, io, resumedOfficer, passedReceipt)
15522
15556
  chain = { status: "converged", passes: [] };
15523
15557
  } else {
15524
15558
  const pass = await runGate(subject);
15525
- if (pass === void 0) throw new Error("audit gate returned no conclusion");
15526
- chain = {
15527
- status: pass.status,
15528
- passes: [{
15529
- 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 = {
15530
15570
  status: pass.status,
15531
- receipt: pass.receipt,
15532
- ...pass.runId === void 0 ? {} : { runId: pass.runId },
15533
- ...pass.runDirectory === void 0 ? {} : { runDirectory: pass.runDirectory },
15534
- ...pass.terminal === void 0 ? {} : { terminal: pass.terminal }
15535
- }]
15536
- };
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
+ }
15537
15582
  }
15538
15583
  }
15539
- if (chain.status === "needs_reask") {
15584
+ if (chain.status === "needs_reask" || chain.status === "transport_failure" || chain.status === "no_receipt") {
15540
15585
  const pass = chain.passes.at(-1);
15541
15586
  const officerTerminal = pass?.terminal;
15542
- if (officerTerminal === void 0) throw new Error("unreadable audit has no terminal result");
15543
15587
  const officerRunDirectory = pass?.runDirectory;
15544
15588
  const officerRunId = pass?.runId ?? (officerRunDirectory === void 0 ? void 0 : runIdFromRunDirectory(officerRunDirectory));
15545
- if (officerRunId === void 0) throw new Error("unreadable audit has no resumable run identity");
15546
- const officer = await loadResumablePublicRole(
15547
- env.home,
15548
- officerRunId,
15549
- env.principalAuthority,
15550
- officerRunDirectory === void 0 ? void 0 : { runDirectory: officerRunDirectory }
15551
- );
15552
- const terminal = await presentUnsettledOfficer(
15553
- 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,
15554
15620
  io,
15555
- 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")
15556
15622
  );
15557
- return { exitCode: 0, admitted: officer.admitted, terminal };
15558
15623
  }
15559
15624
  if (chain.status === "escalate") {
15560
15625
  const escalation = chain.passes.at(-1);
15561
15626
  const escalatedRunDirectory = escalation?.runDirectory;
15562
15627
  const escalatedRunId = escalation?.runId ?? (escalatedRunDirectory === void 0 ? void 0 : runIdFromRunDirectory(escalatedRunDirectory));
15563
- 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
+ }
15564
15636
  const officer = await loadResumablePublicRole(
15565
15637
  env.home,
15566
15638
  escalatedRunId,
@@ -15575,7 +15647,14 @@ async function auditSubmittedRole(turn, env, io, resumedOfficer, passedReceipt)
15575
15647
  { ...await readCurrentCourt(officer.admitted.runDirectory), ...packageFaultScope(officer.admitted, env, io) }
15576
15648
  );
15577
15649
  }
15578
- 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
+ }
15579
15658
  await presentTerminal(terminal, { ...io, omitFailureStderrDiagnostic: true }, officer.admitted.runDirectory);
15580
15659
  return { exitCode: 0, admitted: officer.admitted, terminal };
15581
15660
  }
@@ -18877,19 +18956,19 @@ async function runAkRole(argv, env) {
18877
18956
  parts.credentials,
18878
18957
  invocationFromParsed(parsed)
18879
18958
  );
18880
- const result = await runPublicInstructionSeatResume(
18881
- resumeRequest,
18882
- createRoleEnvironment(env, {
18883
- role: seatRole,
18884
- home,
18885
- agentDir: parts.agentDir,
18886
- cwd: parts.cwd,
18887
- credentials: parts.credentials,
18888
- seat,
18889
- config: parts.config
18890
- }),
18891
- io
18892
- );
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
+ }
18893
18972
  let current = result;
18894
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)) {
18895
18974
  const parentRunId = current.admitted.correlationId;
@@ -19513,9 +19592,11 @@ async function projectAuditorTerminal(summoned) {
19513
19592
  const outcome = summoned.terminal?.roleOutcome;
19514
19593
  if (outcome === void 0) {
19515
19594
  const detail = summoned.stderr?.trim();
19516
- throw new Error(
19517
- detail && detail.length > 0 ? `Auditor public summon produced no terminal (exit ${summoned.exitCode}: ${detail})` : `Auditor public summon produced no terminal (exit ${summoned.exitCode})`
19518
- );
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
+ };
19519
19600
  }
19520
19601
  const usage = await usageFromSummonedSession(summoned);
19521
19602
  if (outcome.kind === "no_receipt") {
@@ -23162,7 +23243,7 @@ function publicNavigatorSettlement(role, phase, event) {
23162
23243
  }
23163
23244
  return { kind: "accepted", role, phase, ...status === void 0 ? {} : { status } };
23164
23245
  }
23165
- async function projectClosedSubmissionLifecycle(closed, context, phase, recordAccepted, settle) {
23246
+ async function projectClosedSubmissionLifecycle(closed, context, phase, recordAccepted, settle, failRecord) {
23166
23247
  recordAccepted();
23167
23248
  const closure = {
23168
23249
  toolName: navigatorOutputTool(closed.role),
@@ -23173,10 +23254,14 @@ async function projectClosedSubmissionLifecycle(closed, context, phase, recordAc
23173
23254
  try {
23174
23255
  navigator = await settle(publicNavigatorSettlement(closed.role, phase, closure));
23175
23256
  } finally {
23176
- context.sessionManager.appendCustomEntry?.("ak-role-submission-closure", {
23177
- ...closure,
23178
- ...navigator === void 0 ? {} : { navigator }
23179
- });
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
+ }
23180
23265
  }
23181
23266
  }
23182
23267
  function createFiledOfficerRuntime(roleHost, spec, dependencies) {
@@ -23364,30 +23449,28 @@ function readDiaristRunCoordinates(ctx) {
23364
23449
  };
23365
23450
  }
23366
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";
23367
- function createDiaristRoleRuntime(roleHost, dependencies) {
23452
+ function createDiaristRoleRuntime(roleHost, dependencies, hostActions) {
23368
23453
  return createFiledOfficerRuntime(
23369
23454
  roleHost,
23370
23455
  {
23371
23456
  role: "diarist",
23372
23457
  tool: DIARIST_TOOL_SPEC,
23373
23458
  soulTag: "diarist",
23374
- beforeAccept: async ({ parameters, ctx }) => {
23459
+ beforeAccept: async ({ toolCallId, parameters, ctx }) => {
23375
23460
  const submitted = isRecord(parameters) ? parameters : void 0;
23376
23461
  const status = submitted?.status;
23377
23462
  if (status !== "completed") return parameters;
23378
23463
  const assertion = readDiaristTicketAssertion(submitted);
23379
23464
  const ticketNumber = assertion.kind === "ticket" ? assertion.ticketNumber : void 0;
23380
- if (ticketNumber !== void 0) {
23381
- await reportTicketFromHostContext(ctx, ticketNumber);
23382
- }
23383
- const coords = readDiaristRunCoordinates(ctx);
23384
- const multiTicket = submitted?.ticketSessions != null;
23385
- const singleSessions = submitted && !multiTicket ? projectDiaristSessions(parameters) : void 0;
23386
- const ticketSessions = submitted && multiTicket ? projectDiaristTicketSessions(submitted) : singleSessions === void 0 ? void 0 : [{ ticketNumber: ticketNumber ?? null, sessions: singleSessions }];
23387
- if (ticketSessions === void 0) {
23388
- throw new ParentQueueReaskError(DIARIST_BOUNDS_REASK);
23389
- }
23390
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
+ }
23391
23474
  await commitDiaristProjection({
23392
23475
  cwd: coords.projectRoot,
23393
23476
  home: coords.home,
@@ -23402,7 +23485,7 @@ function createDiaristRoleRuntime(roleHost, dependencies) {
23402
23485
  ${error.message}`
23403
23486
  );
23404
23487
  }
23405
- throw error;
23488
+ hostActions.failInfrastructure(error, ctx, toolCallId);
23406
23489
  }
23407
23490
  return parameters;
23408
23491
  }
@@ -23489,8 +23572,8 @@ function createRoleRuntimeExtension(dependencies, deliveryRequestLimit) {
23489
23572
  }
23490
23573
  return entries;
23491
23574
  }, [])),
23492
- failInfrastructure,
23493
- async (closed, context) => projectClosedSubmission(closed, context)
23575
+ (error, ctx, toolCallId) => hostActions.failInfrastructure(error, ctx, toolCallId),
23576
+ async (closed, context, toolCallId) => projectClosedSubmission(closed, context, toolCallId)
23494
23577
  );
23495
23578
  roleHost.registerFlag(ROLE_FLAG.name, ROLE_FLAG.definition);
23496
23579
  for (const flag of REVIEWER_TRANSPORT_FLAGS) {
@@ -23528,7 +23611,6 @@ function createRoleRuntimeExtension(dependencies, deliveryRequestLimit) {
23528
23611
  let navigatorSessionParent;
23529
23612
  let navigatorCwd;
23530
23613
  const pendingInfrastructureFailures = /* @__PURE__ */ new Map();
23531
- const pendingSubmissionNonPassByToolCallId = /* @__PURE__ */ new Map();
23532
23614
  let engineDetourRegistered = false;
23533
23615
  let receiptDelivery = createReceiptDeliveryPolicy(deliveryLimit);
23534
23616
  let noReceiptRecorded = false;
@@ -23601,13 +23683,14 @@ function createRoleRuntimeExtension(dependencies, deliveryRequestLimit) {
23601
23683
  await pending;
23602
23684
  return pendingNavigatorPresentation?.event;
23603
23685
  };
23604
- projectClosedSubmission = async (closed, context) => {
23686
+ projectClosedSubmission = async (closed, context, toolCallId) => {
23605
23687
  await projectClosedSubmissionLifecycle(
23606
23688
  closed,
23607
23689
  context,
23608
23690
  navigatorPhase(roleHost, closed.role),
23609
23691
  () => receiptDelivery.recordAccepted(),
23610
- settleNavigatorProjection
23692
+ settleNavigatorProjection,
23693
+ (error) => hostActions.failInfrastructure(error, context, toolCallId)
23611
23694
  );
23612
23695
  };
23613
23696
  roleHost.on("input", (event, ctx) => {
@@ -23709,14 +23792,18 @@ function createRoleRuntimeExtension(dependencies, deliveryRequestLimit) {
23709
23792
  }
23710
23793
  }
23711
23794
  const settlement = isRoleInfrastructureFailure || outputClassification?.kind === "infrastructure" ? publicNavigatorSettlement(role, navigatorPhase(roleHost, role), classified) : void 0;
23712
- await settleNavigatorProjection(settlement);
23713
- if (infrastructureDetails !== void 0) {
23714
- 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);
23715
23801
  }
23716
- const submissionNonPass = pendingSubmissionNonPassByToolCallId.get(event.toolCallId);
23717
- if (submissionNonPass !== void 0) {
23718
- pendingSubmissionNonPassByToolCallId.delete(event.toolCallId);
23719
- return { details: submissionNonPass, isError: true };
23802
+ if (infrastructureDetails !== void 0) {
23803
+ return {
23804
+ isError: true,
23805
+ details: projectionFailure === void 0 ? infrastructureDetails : { ...infrastructureDetails, projectionFailure }
23806
+ };
23720
23807
  }
23721
23808
  });
23722
23809
  roleHost.on("agent_end", async (event, ctx) => {
@@ -23732,15 +23819,17 @@ function createRoleRuntimeExtension(dependencies, deliveryRequestLimit) {
23732
23819
  const prose = lastAssistantProse(event.messages);
23733
23820
  if (prose !== void 0 && prose.trim() !== "") {
23734
23821
  const accepted = { prose };
23822
+ const toolCallId = `navigator-prose-exit:${randomUUID7()}`;
23735
23823
  await sealAcceptedSubmission({
23736
23824
  context: ctx,
23737
23825
  role: "navigator",
23738
23826
  accepted,
23739
- toolCallId: `navigator-prose-exit:${randomUUID7()}`
23827
+ toolCallId
23740
23828
  });
23741
23829
  await projectClosedSubmission(
23742
23830
  { role: "navigator", kind: "accepted", accepted },
23743
- ctx
23831
+ ctx,
23832
+ toolCallId
23744
23833
  );
23745
23834
  return;
23746
23835
  }
@@ -23842,7 +23931,6 @@ function createRoleRuntimeExtension(dependencies, deliveryRequestLimit) {
23842
23931
  pendingNavigatorSettlement = void 0;
23843
23932
  disposeNavigatorAttendanceNonBlocking(attendanceToDispose);
23844
23933
  pendingInfrastructureFailures.clear();
23845
- pendingSubmissionNonPassByToolCallId.clear();
23846
23934
  }
23847
23935
  });
23848
23936
  const hostActions = {
@@ -23851,9 +23939,6 @@ function createRoleRuntimeExtension(dependencies, deliveryRequestLimit) {
23851
23939
  pendingInfrastructureFailures.set(toolCallId, buildPendingInfrastructureFailure(error));
23852
23940
  }
23853
23941
  failInfrastructure(error, ctx);
23854
- },
23855
- bindSubmissionNonPass(toolCallId, result) {
23856
- pendingSubmissionNonPassByToolCallId.set(toolCallId, result);
23857
23942
  }
23858
23943
  };
23859
23944
  const requireRoleSoul = (role) => dependencies.loadRoleSoul(role);
@@ -23933,7 +24018,8 @@ function createRoleRuntimeExtension(dependencies, deliveryRequestLimit) {
23933
24018
  roleHost,
23934
24019
  {
23935
24020
  loadSoul: () => requireRoleSoul("diarist")
23936
- }
24021
+ },
24022
+ hostActions
23937
24023
  );
23938
24024
  const secretariat = createSecretariatRoleRuntime(roleHost, {
23939
24025
  loadSoul: () => requireRoleSoul("secretariat")
@@ -24031,7 +24117,6 @@ function createRoleRuntimeExtension(dependencies, deliveryRequestLimit) {
24031
24117
  navigatorDeliveryClosed = false;
24032
24118
  pendingNavigatorSettlement = void 0;
24033
24119
  pendingInfrastructureFailures.clear();
24034
- pendingSubmissionNonPassByToolCallId.clear();
24035
24120
  navigatorWorkContext = void 0;
24036
24121
  envelopeHost.startKeepalive(ctx);
24037
24122
  const rawRole = roleHost.getFlag(ROLE_FLAG.name);
@@ -24147,7 +24232,7 @@ function createRoleRuntimeExtension(dependencies, deliveryRequestLimit) {
24147
24232
  }
24148
24233
  }
24149
24234
  await executeActivationStage(entry.role, activationStage(entry.role, activateByRole), { clock, writeTrace });
24150
- registerReportTicketTool(roleHost);
24235
+ registerReportTicketTool(roleHost, hostActions);
24151
24236
  roleHost.setActiveTools([
24152
24237
  .../* @__PURE__ */ new Set([...roleHost.getActiveTools(), REPORT_TICKET_TOOL_NAME])
24153
24238
  ]);
@@ -24397,19 +24482,6 @@ async function prepareRoleEnvelope(options) {
24397
24482
  )(envelope);
24398
24483
  const token = randomUUID9();
24399
24484
  const server = createServer((socket) => serveSocket(socket));
24400
- function rememberProjectedRejection(details, toolCallId, content) {
24401
- if (typeof details !== "object" || details === null) return;
24402
- const record = details;
24403
- if (record.cause === "infrastructure") return;
24404
- if (record.kind === "role_infrastructure_failure") return;
24405
- 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;
24406
- if (code === void 0) return;
24407
- rejection = {
24408
- code,
24409
- toolCallIds: [toolCallId],
24410
- message: textDiagnostic(content) ?? code
24411
- };
24412
- }
24413
24485
  function textDiagnostic(content) {
24414
24486
  const text = content.filter((part) => part.type === "text").map((part) => part.text).join("\n\n");
24415
24487
  return text.trim().length > 0 ? text : void 0;
@@ -24480,7 +24552,6 @@ async function prepareRoleEnvelope(options) {
24480
24552
  sessionEntries.push(toolResultEntry);
24481
24553
  if (projected.isError) {
24482
24554
  rememberInfrastructureFailure(projected.details, projected.content);
24483
- rememberProjectedRejection(projected.details, toolCallId, projected.content);
24484
24555
  }
24485
24556
  await emit("tool_execution_end", { toolCallId, toolName, isError: projected.isError });
24486
24557
  return projected;
@@ -24539,18 +24610,31 @@ async function prepareRoleEnvelope(options) {
24539
24610
  } catch (error) {
24540
24611
  let content;
24541
24612
  let details;
24542
- if (isCorrectableExecuteError(error)) {
24543
- const projected2 = projectCorrectableExecuteRejection(error);
24544
- content = [{ type: "text", text: projected2.diagnostic }];
24545
- 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;
24546
24617
  } else {
24547
- ({ 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
+ };
24548
24624
  }
24549
24625
  const projected = await projectToolResult(toolCallId, name, {
24550
24626
  content,
24551
24627
  details,
24552
24628
  isError: true
24553
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
+ }
24554
24638
  return { content: projected.content, isError: projected.isError };
24555
24639
  }
24556
24640
  }