@bridge_gpt/mcp-server 0.2.71 → 0.2.73

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 (198) hide show
  1. package/README.md +55 -17
  2. package/build/agent-launchers/claude-executor-adapter.js +22 -3
  3. package/build/agent-notes.js +171 -95
  4. package/build/agents.generated.js +7 -7
  5. package/build/bridge-permissions.js +31 -0
  6. package/build/bridge-worktree-inspection.js +237 -0
  7. package/build/check-evidence.js +6 -0
  8. package/build/ci-system-detection.js +50 -0
  9. package/build/ci-trigger-adapters.js +631 -0
  10. package/build/ci-trigger-install.js +106 -0
  11. package/build/claude-review-workflow.js +1 -1
  12. package/build/cli-help.js +6 -0
  13. package/build/codex-auto-recovery.js +126 -0
  14. package/build/codex-launcher-pin.js +33 -2
  15. package/build/codex-skill-adapter.js +5 -1
  16. package/build/command-host.js +33 -0
  17. package/build/commands.generated.js +7 -6
  18. package/build/conductor/bridge-api-client.js +1352 -50
  19. package/build/conductor/bring-up-facts.js +18 -5
  20. package/build/conductor/command-drift-production.js +42 -17
  21. package/build/conductor/command-drift.js +47 -0
  22. package/build/conductor/declare-blocked.js +554 -0
  23. package/build/conductor/doctor.js +187 -28
  24. package/build/conductor/driver-commands.js +141 -0
  25. package/build/conductor/driver-guard.js +277 -0
  26. package/build/conductor/driver-lapse.js +321 -0
  27. package/build/conductor/driver-register.js +176 -0
  28. package/build/conductor/driver-release.js +174 -0
  29. package/build/conductor/driver-session-state.js +315 -0
  30. package/build/conductor/epic-branch-ci-inspection.js +222 -29
  31. package/build/conductor/epic-implementer-cli.js +213 -13
  32. package/build/conductor/epic-server-database.js +162 -0
  33. package/build/conductor/epic-server-guidance.js +278 -0
  34. package/build/conductor/epic-server-journal.js +239 -0
  35. package/build/conductor/epic-server-processes.js +324 -0
  36. package/build/conductor/epic-server-recipe.js +397 -0
  37. package/build/conductor/epic-server-runtime.js +1207 -0
  38. package/build/conductor/epic-server-sfcc.js +107 -0
  39. package/build/conductor/epic-server-state.js +427 -0
  40. package/build/conductor/epic-server.js +594 -0
  41. package/build/conductor/gate-discovery.js +281 -10
  42. package/build/conductor/gate-settings-review.js +525 -5
  43. package/build/conductor/git-hooks-uninstall.js +112 -0
  44. package/build/conductor/git-hooks.js +81 -15
  45. package/build/conductor/guided-repair.js +10 -1
  46. package/build/conductor/install-doctor.js +2 -4
  47. package/build/conductor/launch-need-probes.js +6 -53
  48. package/build/conductor/launch-plan.js +318 -121
  49. package/build/conductor/local-merge.js +12 -1
  50. package/build/conductor/merge-execution-contract.js +1 -1
  51. package/build/conductor/merged-child-check.js +2 -1
  52. package/build/conductor/prerequisite-inputs.js +1213 -0
  53. package/build/conductor/readiness-assessment.js +93 -0
  54. package/build/conductor/readiness-cli.js +30 -9
  55. package/build/conductor/readiness-prerequisites.js +77 -5
  56. package/build/conductor/readiness-sections.js +146 -126
  57. package/build/conductor/readiness.js +21 -3
  58. package/build/conductor/recovery-cli.js +236 -15
  59. package/build/conductor/recovery-operations.js +34 -4
  60. package/build/conductor/repair-contract.js +33 -0
  61. package/build/conductor/tools.js +36 -4
  62. package/build/conductor/wait-run-attention.js +115 -0
  63. package/build/conductor/wait-run-cli.js +300 -21
  64. package/build/conductor/worker-database-doctor-inspector.js +34 -2
  65. package/build/conductor/worker-setup-tally.js +27 -0
  66. package/build/credential-store.js +96 -21
  67. package/build/dependency-install-declarations.js +212 -0
  68. package/build/docs.generated.js +4 -4
  69. package/build/doctor.js +91 -8
  70. package/build/drive-epic-help.js +23 -4
  71. package/build/drive-epic.js +1841 -340
  72. package/build/engine-paths.js +20 -0
  73. package/build/epic-branch-ci-summary.js +140 -0
  74. package/build/epic-capability-statement.js +107 -0
  75. package/build/epic-ci-workflow-drift.js +30 -15
  76. package/build/epic-ci-workflow-install.js +110 -42
  77. package/build/epic-ci-workflow-v2.js +274 -0
  78. package/build/epic-ci-workflow.js +38 -12
  79. package/build/epic-implementer-bin.js +2184 -52
  80. package/build/epic-launch-context.js +607 -0
  81. package/build/epic-launch-profile.js +1 -1
  82. package/build/epic-server-record.js +273 -0
  83. package/build/epic-shared/bridge-client.js +11 -3
  84. package/build/escalation-reachability.js +43 -0
  85. package/build/executor/ci-fix-test-runs.js +334 -0
  86. package/build/executor/cli.js +2 -0
  87. package/build/executor/completion-contract.js +24 -1
  88. package/build/executor/credentials.js +1 -1
  89. package/build/executor/delivery-observations.js +113 -0
  90. package/build/executor/delivery-outcome.js +30 -0
  91. package/build/executor/dependency-refresh-runner.js +132 -0
  92. package/build/executor/dependency-refresh.js +530 -0
  93. package/build/executor/deps.js +4 -0
  94. package/build/executor/env.js +119 -17
  95. package/build/executor/epic-server-context.js +141 -0
  96. package/build/executor/gate-qualification-job.js +127 -26
  97. package/build/executor/harness-coverage.js +19 -0
  98. package/build/executor/http-client.js +87 -6
  99. package/build/executor/index.js +2 -1
  100. package/build/executor/install-preflight.js +1 -1
  101. package/build/executor/job-runner.js +659 -87
  102. package/build/executor/likely-tests.js +94 -97
  103. package/build/executor/observation.js +8 -0
  104. package/build/executor/pre-pr-checks.js +363 -0
  105. package/build/executor/prompt-spec.js +127 -5
  106. package/build/executor/reconcile-overlap-job.js +5 -3
  107. package/build/executor/required-verification.js +28 -0
  108. package/build/executor/required-work-diagnostics.js +32 -0
  109. package/build/executor/required-work-ledger.js +955 -39
  110. package/build/executor/results.js +100 -0
  111. package/build/executor/service-discovery.js +42 -0
  112. package/build/executor/service-lifecycle.js +109 -2
  113. package/build/executor/service-uninstall.js +205 -0
  114. package/build/executor/service-unit.js +5 -3
  115. package/build/executor/terminal-mutation.js +8 -0
  116. package/build/executor/test-clock.js +3 -0
  117. package/build/executor/verification-hints.js +179 -0
  118. package/build/executor/worker-command.js +126 -5
  119. package/build/executor/worker-database-config.js +281 -0
  120. package/build/executor/worker-database-target.js +16 -12
  121. package/build/executor/worker-database.js +575 -116
  122. package/build/executor/worker-finalization.js +71 -10
  123. package/build/executor/worker-guard-hook.js +10 -2
  124. package/build/executor/worker-resources.js +25 -3
  125. package/build/executor/worker-verification-guidance.js +55 -5
  126. package/build/executor/worktree-inspection.js +42 -0
  127. package/build/executor/worktree.js +20 -1
  128. package/build/executor-launch.js +54 -2
  129. package/build/generated-assets-catalog.js +2 -2
  130. package/build/github-sign-in.js +1 -1
  131. package/build/index.js +1111 -381
  132. package/build/init.js +29 -14
  133. package/build/install-bridge-conductor-answers.js +465 -0
  134. package/build/install-bridge-conductor-apply.js +259 -0
  135. package/build/install-bridge-conductor-assessment.js +895 -0
  136. package/build/install-bridge-conductor-compact.js +161 -0
  137. package/build/install-bridge-conductor-contracts.js +63 -0
  138. package/build/install-bridge-conductor-gate.js +1383 -188
  139. package/build/install-bridge-conductor-setup.js +637 -92
  140. package/build/install-bridge-conductor.js +3163 -740
  141. package/build/install-bridge.js +601 -128
  142. package/build/install-maintenance.js +127 -0
  143. package/build/install-reexec.js +1 -1
  144. package/build/launcher-config-inspection.js +162 -1
  145. package/build/local-cleanup.js +59 -0
  146. package/build/mcp-grant-candidates.js +767 -0
  147. package/build/mcp-grant-doctor.js +63 -0
  148. package/build/mcp-grant.js +288 -0
  149. package/build/mcp-host-targets.js +8 -0
  150. package/build/mcp-identity.js +23 -0
  151. package/build/mcp-install-state.js +68 -2
  152. package/build/mcp-invoke.js +126 -13
  153. package/build/mcp-presets.js +107 -0
  154. package/build/mcp-provisioning.js +134 -2
  155. package/build/mcp-registration-doctor.js +31 -2
  156. package/build/mcp-server-invocation.js +6 -1
  157. package/build/merge-workflow-install.js +236 -111
  158. package/build/package-script-semantics.js +10 -0
  159. package/build/pipeline-utils.js +1 -1
  160. package/build/pipelines.generated.js +6 -6
  161. package/build/plan-discovery.js +97 -4
  162. package/build/plan-execution-ledger.js +248 -9
  163. package/build/plan-generation-io.js +262 -0
  164. package/build/plan-generation.js +424 -0
  165. package/build/plane/build-freshness.js +6 -1
  166. package/build/plane/cli.js +75 -9
  167. package/build/plane/plane-freshness.js +23 -7
  168. package/build/plane/preflight.js +50 -10
  169. package/build/plane/shutdown.js +19 -0
  170. package/build/plane/terminal-run-cleanup.js +23 -5
  171. package/build/plane/terminal-run-status.js +4 -0
  172. package/build/printed-remedy-commands.js +229 -15
  173. package/build/readiness-check.js +1 -1
  174. package/build/readiness-prerequisites.generated.js +311 -4
  175. package/build/readme.generated.js +1 -1
  176. package/build/repository-state-paths.js +38 -0
  177. package/build/repository-toolchains.js +50 -8
  178. package/build/run-unit-tests-launcher.js +8 -1
  179. package/build/setup-change-policy.js +32 -0
  180. package/build/setup-epic.js +1192 -198
  181. package/build/setup-progress.js +44 -0
  182. package/build/setup-question.js +180 -0
  183. package/build/start-tickets.js +4 -0
  184. package/build/test-command-detection.js +32 -88
  185. package/build/test-support/notes-fs.js +40 -0
  186. package/build/third-party-mcp-targets.js +30 -0
  187. package/build/ticket-delivery-enrollment.js +30 -8
  188. package/build/ticket-delivery-run-scope.js +128 -0
  189. package/build/upgrade-cli.js +85 -2
  190. package/build/v2-readiness-requirements.js +28 -1
  191. package/build/version.generated.js +3 -3
  192. package/build/worker-guard-hook-bin.js +2 -2
  193. package/build/worktrees.js +105 -0
  194. package/docs/EPIC-IMPLEMENTER-INSTALL.md +9 -1
  195. package/docs/EPIC-IMPLEMENTER.md +5 -0
  196. package/docs/epic-implementer/getting-started.md +42 -15
  197. package/docs/epic-implementer/self-hosting.md +14 -1
  198. package/package.json +2 -2
@@ -1,5 +1,5 @@
1
1
  /**
2
- * `conductor` operator recovery and repair verbs — sixteen CLI-only commands.
2
+ * `conductor` operator recovery and repair verbs — seventeen CLI-only commands.
3
3
  *
4
4
  * The four BAPI-872 recovery verbs: `stop-run`, `abandon-run`, `unpark`,
5
5
  * `adopt-current-head-and-unpark`. The six run-addressed repair verbs: BAPI-1154's
@@ -10,9 +10,11 @@
10
10
  * provider re-run of failed CI workflow runs: `rerun-ci`. BAPI-1494's owner
11
11
  * decision on verification hand-offs: `resolve-handoff`. BAPI-1532's answer to a
12
12
  * named plan failure, one forced regeneration on a chosen route: `regenerate-plan`.
13
+ * BAPI-1562's owner acknowledgement of the run's carried-gap list:
14
+ * `acknowledge-gaps`.
13
15
  *
14
16
  * CLI-only by design — this is an explicit ticket non-goal, not an oversight:
15
- * none of these sixteen command names is ever registered as an MCP tool, tool
17
+ * none of these seventeen command names is ever registered as an MCP tool, tool
16
18
  * description, or generated tool-schema input (`index-static.test.ts` guards
17
19
  * this). They exist so an operator (or `plane down`, via
18
20
  * `recovery-operations.ts`) can recover a stuck run or ticket WITHOUT
@@ -29,7 +31,7 @@
29
31
  import { readFile } from "node:fs/promises";
30
32
  import { ConductorValidationError, toConductorErrorEnvelope } from "./errors.js";
31
33
  import { nodeGithubMergeCredentialReadDeps, readLocalGithubRemote } from "./stored-merge-credential.js";
32
- import { DRIVER_CONTEXT_MAX_BYTES, HANDOFF_RESOLUTION_EVIDENCE_REF_MAX_CHARS, HANDOFF_RESOLUTION_KIND_LABELS, HANDOFF_RESOLUTION_KINDS, HANDOFF_RESOLUTION_MAX_STEPS, HANDOFF_RESOLUTION_REASON_MAX_CHARS, POLICY_PATCH_MAX_BYTES, RESUME_RUN_UNCONFIRMED_MESSAGE, } from "./repair-contract.js";
34
+ import { DRIVER_CONTEXT_MAX_BYTES, HANDOFF_RESOLUTION_EVIDENCE_REF_MAX_CHARS, HANDOFF_RESOLUTION_KIND_LABELS, HANDOFF_RESOLUTION_KINDS, HANDOFF_RESOLUTION_MAX_STEPS, HANDOFF_RESOLUTION_REASON_MAX_CHARS, GAP_ACKNOWLEDGEMENT_REASON_MAX_CHARS, POLICY_PATCH_MAX_BYTES, RESUME_RUN_UNCONFIRMED_MESSAGE, } from "./repair-contract.js";
33
35
  import { CONTINUATION_CI_WAITING_REASONS, continuationDispatchedJob, } from "./epic-child-continuation.js";
34
36
  import { decodeGuidedBinding, GuidedBindingError, } from "./guided-repair.js";
35
37
  // ---------------------------------------------------------------------------
@@ -146,7 +148,7 @@ function parseExternalRepairOperationId(values) {
146
148
  return id;
147
149
  }
148
150
  function parseTicketRecoveryArgs(argv) {
149
- const { values, bools } = tokenizeRecoveryFlags(argv, new Set([...TICKET_VALUE_FLAGS, "--reason", "--cleanup-resolution", "--external-repair"]), RECOVERY_BOOL_FLAGS);
151
+ const { values, bools } = tokenizeRecoveryFlags(argv, new Set([...TICKET_VALUE_FLAGS, "--reason", "--cleanup-resolution", "--external-repair", "--binding"]), RECOVERY_BOOL_FLAGS);
150
152
  if (bools.has("--help")) {
151
153
  return { epicRunId: "", ticketKey: "", json: bools.has("--json"), help: true };
152
154
  }
@@ -159,6 +161,15 @@ function parseTicketRecoveryArgs(argv) {
159
161
  throw new ConductorValidationError('Flag "--ticket-key" is required and must be non-empty.');
160
162
  }
161
163
  const externalRepairOperationId = parseExternalRepairOperationId(values);
164
+ let expectedRowVersion;
165
+ if (values.has("--binding")) {
166
+ const binding = decodeGuidedBinding(values.get("--binding") ?? "");
167
+ if (binding.verb !== "adopt-current-head-and-unpark" || binding.epicRunId !== epicRunId.trim()
168
+ || binding.ticketKey !== ticketKey.trim() || binding.externalRepairOperationId !== externalRepairOperationId) {
169
+ throw new ConductorValidationError("The external-repair binding does not match this command.");
170
+ }
171
+ expectedRowVersion = binding.expectedRowVersion;
172
+ }
162
173
  return {
163
174
  epicRunId: epicRunId.trim(),
164
175
  ticketKey: ticketKey.trim(),
@@ -167,6 +178,7 @@ function parseTicketRecoveryArgs(argv) {
167
178
  cleanupResolution: values.get("--cleanup-resolution"),
168
179
  } : {}),
169
180
  ...(externalRepairOperationId !== undefined ? { externalRepairOperationId } : {}),
181
+ ...(expectedRowVersion !== undefined ? { expectedRowVersion } : {}),
170
182
  json: bools.has("--json"),
171
183
  help: false,
172
184
  };
@@ -182,7 +194,7 @@ function parseTicketRecoveryArgs(argv) {
182
194
  */
183
195
  async function resolveRecoveryAccess(json) {
184
196
  const { resolveConductorBridgeApiAccess } = await import("./bridge-api-client.js");
185
- const result = await resolveConductorBridgeApiAccess();
197
+ const result = await resolveConductorBridgeApiAccess({ followEpicLaunchProfile: true });
186
198
  if (!result.ok) {
187
199
  if (json) {
188
200
  console.log(JSON.stringify({ ok: false, kind: "unauthorized", error: result.error }));
@@ -444,6 +456,7 @@ export async function runAdoptCurrentHeadAndUnparkCommand(argv) {
444
456
  const result = await adoptCurrentHeadAndUnparkWithRetry(access, {
445
457
  epicRunId: parsed.epicRunId,
446
458
  ticketKey: parsed.ticketKey,
459
+ ...(parsed.expectedRowVersion !== undefined ? { expectedRowVersion: parsed.expectedRowVersion } : {}),
447
460
  ...(parsed.externalRepairOperationId !== undefined
448
461
  ? { externalRepairOperationId: parsed.externalRepairOperationId }
449
462
  : {}),
@@ -469,6 +482,12 @@ const DISPATCH_REMEDIATION_VALUE_FLAGS = new Set([
469
482
  "--binding",
470
483
  ]);
471
484
  const MERGE_CHILD_VALUE_FLAGS = new Set(["--epic-run-id", "--pr"]);
485
+ /**
486
+ * BAPI-1564 — `--carry-gaps` is a `merge-child` switch only; no other verb
487
+ * accepts it. It selects the server's carried-gap admission MODE and carries no
488
+ * head, base, branch, or SHA.
489
+ */
490
+ const MERGE_CHILD_BOOL_FLAGS = new Set(["--json", "--help", "--carry-gaps"]);
472
491
  /**
473
492
  * BAPI-1333 — attach `binding` ONLY when `--binding` was given, so an unguided
474
493
  * parse result is exactly what it was before.
@@ -511,9 +530,21 @@ export function parseDispatchRemediationArgs(argv) {
511
530
  }, values);
512
531
  }
513
532
  export function parseMergeChildArgs(argv) {
514
- const { values, bools } = tokenizeRecoveryFlags(argv, MERGE_CHILD_VALUE_FLAGS, RECOVERY_BOOL_FLAGS);
533
+ // BAPI-1564 — the shared tokenizer reads `--flag=value` of a boolean flag as the
534
+ // bare flag, so `--carry-gaps=false` would SELECT the mode. Refused outright for
535
+ // this authority-bearing switch: it is given bare or not at all.
536
+ if (argv.some((token) => token.startsWith("--carry-gaps="))) {
537
+ throw new ConductorValidationError('Flag "--carry-gaps" takes no value; give it bare or omit it.');
538
+ }
539
+ const { values, bools } = tokenizeRecoveryFlags(argv, MERGE_CHILD_VALUE_FLAGS, MERGE_CHILD_BOOL_FLAGS);
515
540
  if (bools.has("--help")) {
516
- return { epicRunId: "", prNumber: 0, json: bools.has("--json"), help: true };
541
+ return {
542
+ epicRunId: "",
543
+ prNumber: 0,
544
+ json: bools.has("--json"),
545
+ help: true,
546
+ carryGaps: bools.has("--carry-gaps"),
547
+ };
517
548
  }
518
549
  const epicRunId = requireFlag(values, "--epic-run-id");
519
550
  const rawPr = requireFlag(values, "--pr");
@@ -521,7 +552,13 @@ export function parseMergeChildArgs(argv) {
521
552
  if (!Number.isSafeInteger(prNumber)) {
522
553
  throw new ConductorValidationError('Flag "--pr" must be a positive integer pull-request number.');
523
554
  }
524
- return { epicRunId, prNumber, json: bools.has("--json"), help: false };
555
+ return {
556
+ epicRunId,
557
+ prNumber,
558
+ json: bools.has("--json"),
559
+ help: false,
560
+ carryGaps: bools.has("--carry-gaps"),
561
+ };
525
562
  }
526
563
  /**
527
564
  * Validate and decode a driver-context file's BYTES.
@@ -687,13 +724,31 @@ function renderRepairResult(outcome, input, json, extraLines = () => []) {
687
724
  "and is not rolled back. You ran it, so you own reconciling the missing audit " +
688
725
  "record (the server also reported it to Sentry).");
689
726
  }
727
+ if (outcome.ok &&
728
+ input.verb === "dispatch-remediation" &&
729
+ outcome.result.driver_context_delivered === false) {
730
+ // BAPI-1550: only an EXPLICIT false warns. The dispatch itself still succeeded
731
+ // (a deduplicated dispatch exits 0), so this goes to stderr, never into the
732
+ // stdout the operator may be parsing (so it also shows in --json mode).
733
+ console.error("Warning: driver context was NOT delivered. A job for this ticket was already queued or " +
734
+ "running and continues WITHOUT it. Dispatch again with --context-file after that job " +
735
+ "finishes.");
736
+ }
690
737
  if (json) {
691
738
  if (outcome.ok) {
692
739
  console.log(JSON.stringify(outcome.result));
693
740
  return 0;
694
741
  }
695
742
  console.log(JSON.stringify(outcome.kind === "refused"
696
- ? { ok: false, kind: "refused", code: outcome.code, message: outcome.message }
743
+ ? {
744
+ ok: false,
745
+ kind: "refused",
746
+ code: outcome.code,
747
+ message: outcome.message,
748
+ ...(outcome.holder
749
+ ? { holder_job_id: outcome.holder.job_id, holder_job_type: outcome.holder.job_type }
750
+ : {}),
751
+ }
697
752
  : { ok: false, kind: "unavailable", message: input.unavailableMessage ?? outcome.message }));
698
753
  return 1;
699
754
  }
@@ -701,6 +756,10 @@ function renderRepairResult(outcome, input, json, extraLines = () => []) {
701
756
  if (outcome.kind === "refused") {
702
757
  console.error(`Error: ${input.verb} refused on run ${input.epicRunId} (${input.targetLabel}) — ` +
703
758
  `${outcome.code}: ${outcome.message}`);
759
+ if (outcome.holder) {
760
+ // BAPI-1550: one secondary detail line, only for a validated pair.
761
+ console.error(` lane holder: job ${outcome.holder.job_id} (${outcome.holder.job_type}), queued`);
762
+ }
704
763
  }
705
764
  else if (input.unavailableMessage) {
706
765
  console.error(`Error: ${input.verb} on run ${input.epicRunId} (${input.targetLabel}) — ` +
@@ -860,6 +919,10 @@ export async function runDispatchRemediationCommand(argv, deps = {}) {
860
919
  stateLabel: "selected gate",
861
920
  }, parsed.json, (result) => [
862
921
  ` job: ${result.job_type || "unknown"}${result.job_id !== null ? ` (job ${result.job_id})` : ""}`,
922
+ ...(result.driver_context_delivered === true ? [" context: delivered"] : []),
923
+ ...(typeof result.queued_behind === "number"
924
+ ? [` queued: queued behind job ${result.queued_behind}`]
925
+ : []),
863
926
  ]);
864
927
  }
865
928
  catch (error) {
@@ -1246,8 +1309,140 @@ export async function runResolveHandoffCommand(argv) {
1246
1309
  return RESOLVE_HANDOFF_EXIT_FAILED;
1247
1310
  }
1248
1311
  }
1312
+ // ---------------------------------------------------------------------------
1313
+ // BAPI-1562 — acknowledge-gaps
1314
+ // ---------------------------------------------------------------------------
1315
+ const ACKNOWLEDGE_GAPS_VALUE_FLAGS = new Set(["--epic-run-id", "--digest", "--reason"]);
1316
+ /** Exit codes: 0 acknowledged (or already acknowledged), 1 refused, stale, or failed. */
1317
+ export const ACKNOWLEDGE_GAPS_EXIT_OK = 0;
1318
+ export const ACKNOWLEDGE_GAPS_EXIT_FAILED = 1;
1319
+ /** What every success ends with: the second hold, and what acknowledging is not. */
1320
+ export const ACKNOWLEDGE_GAPS_NEXT_ACTION = "The integration PR leaves draft only when both holds are clear: this list hold and " +
1321
+ "the workaround-folder hold (remove any .bridge/epic-workarounds/ records in a new " +
1322
+ "epic-head commit). Acknowledging verified nothing, readied nothing and merged " +
1323
+ "nothing: review and merge the integration PR into base yourself.";
1324
+ const ACKNOWLEDGE_GAPS_USAGE = [
1325
+ "Usage: epic-implementer acknowledge-gaps --epic-run-id <RUN> --digest <CURRENT_DIGEST> --reason <TEXT> [--json]",
1326
+ "",
1327
+ "Acknowledge, once, the run's carried-gap list: every verification hand-off, carried",
1328
+ "gap, driver merge and out-of-engine merge the run carried forward. The integration PR",
1329
+ "stays in draft until the owner acknowledges the list's CURRENT digest; a new entry",
1330
+ "changes the digest and holds it again. Read the list on the integration PR report or",
1331
+ "with `epic-implementer explain-run` (carried_gap_list) and pass its digest exactly.",
1332
+ "",
1333
+ "This is the OWNER's step. The /drive-epic-run driver never runs it and workers",
1334
+ "cannot. The server records your verified API-key identity as the actor; you cannot",
1335
+ "supply one. It never marks a step verified, never readies the PR and never merges it.",
1336
+ "--digest is the 64-character lowercase hex list digest. --reason is at most 1000",
1337
+ "characters.",
1338
+ "",
1339
+ "Exit codes: 0 acknowledged (or this digest was already acknowledged); 1 refused,",
1340
+ "stale (the list changed), or failed.",
1341
+ ].join("\n");
1342
+ export function parseAcknowledgeGapsArgs(argv) {
1343
+ const { values, bools } = tokenizeRecoveryFlags(argv, ACKNOWLEDGE_GAPS_VALUE_FLAGS, RECOVERY_BOOL_FLAGS);
1344
+ if (bools.has("--help")) {
1345
+ return { epicRunId: "", digest: "", reason: "", json: bools.has("--json"), help: true };
1346
+ }
1347
+ const digest = requireFlag(values, "--digest");
1348
+ if (!/^[0-9a-f]{64}$/.test(digest)) {
1349
+ throw new ConductorValidationError("--digest must be the 64-character lowercase hex list digest from the report or explain-run.");
1350
+ }
1351
+ const reason = boundedText(values, "--reason", GAP_ACKNOWLEDGEMENT_REASON_MAX_CHARS);
1352
+ if (!reason.trim()) {
1353
+ throw new ConductorValidationError('Flag "--reason" must not be blank.');
1354
+ }
1355
+ return {
1356
+ epicRunId: requireFlag(values, "--epic-run-id"),
1357
+ digest,
1358
+ reason,
1359
+ json: bools.has("--json"),
1360
+ help: false,
1361
+ };
1362
+ }
1363
+ /**
1364
+ * Exported for tests: render one `acknowledge-gaps` outcome. Success goes to
1365
+ * stdout and every failure to stderr (`--json` included).
1366
+ */
1367
+ export function renderAcknowledgeGapsOutcome(outcome, parsed, json) {
1368
+ const label = `run ${parsed.epicRunId}`;
1369
+ if (outcome.ok) {
1370
+ const result = outcome.result;
1371
+ if (result.committed && !result.event_recorded) {
1372
+ console.error(`Warning: acknowledge-gaps for ${label} COMMITTED, but its operator_verb_applied ` +
1373
+ "audit event was not recorded. The acknowledgement stands; a replay will not write again.");
1374
+ }
1375
+ if (json) {
1376
+ console.log(JSON.stringify(result));
1377
+ return ACKNOWLEDGE_GAPS_EXIT_OK;
1378
+ }
1379
+ const lines = [
1380
+ result.committed
1381
+ ? `acknowledge-gaps — ${label}: list acknowledged (${result.entry_count} entries)`
1382
+ : `acknowledge-gaps — ${label}: this digest was already acknowledged; nothing was written`,
1383
+ ` digest: ${result.digest}`,
1384
+ ` event recorded: ${result.committed ? String(result.event_recorded) : "not applicable (replay)"}`,
1385
+ ` next action: ${ACKNOWLEDGE_GAPS_NEXT_ACTION}`,
1386
+ ];
1387
+ console.log(lines.join("\n"));
1388
+ return ACKNOWLEDGE_GAPS_EXIT_OK;
1389
+ }
1390
+ if (outcome.kind === "refused") {
1391
+ if (json) {
1392
+ console.error(JSON.stringify({
1393
+ ok: false,
1394
+ outcome: "refused",
1395
+ code: outcome.code,
1396
+ message: outcome.message,
1397
+ nothing_written: true,
1398
+ }));
1399
+ }
1400
+ else if (outcome.code === "GAP_DIGEST_STALE") {
1401
+ console.error(`Refused: acknowledge-gaps for ${label} — GAP_DIGEST_STALE: the list changed since ` +
1402
+ "you read it. Nothing was written. Re-read the integration PR report or " +
1403
+ "`epic-implementer explain-run` (carried_gap_list) and acknowledge the new digest.");
1404
+ }
1405
+ else {
1406
+ console.error(`Refused: acknowledge-gaps for ${label} — ${outcome.code}: ${outcome.message} ` +
1407
+ "Nothing was written.");
1408
+ }
1409
+ return ACKNOWLEDGE_GAPS_EXIT_FAILED;
1410
+ }
1411
+ if (json) {
1412
+ console.error(JSON.stringify({ ok: false, outcome: "unavailable", message: outcome.message }));
1413
+ }
1414
+ else {
1415
+ console.error(`Failed: acknowledge-gaps for ${label} — ${outcome.message}. The outcome is uncertain: ` +
1416
+ "it is safe to run the same command again with the same digest (a repeat writes " +
1417
+ "nothing if it was already recorded).");
1418
+ }
1419
+ return ACKNOWLEDGE_GAPS_EXIT_FAILED;
1420
+ }
1421
+ export async function runAcknowledgeGapsCommand(argv) {
1422
+ try {
1423
+ const parsed = parseAcknowledgeGapsArgs(argv);
1424
+ if (parsed.help) {
1425
+ console.log(ACKNOWLEDGE_GAPS_USAGE);
1426
+ return 0;
1427
+ }
1428
+ const access = await resolveRecoveryAccess(parsed.json);
1429
+ if (!access)
1430
+ return ACKNOWLEDGE_GAPS_EXIT_FAILED;
1431
+ const { acknowledgeGapsRepair } = await import("./recovery-operations.js");
1432
+ const outcome = await acknowledgeGapsRepair(access, {
1433
+ epicRunId: parsed.epicRunId,
1434
+ digest: parsed.digest,
1435
+ reason: parsed.reason,
1436
+ });
1437
+ return renderAcknowledgeGapsOutcome(outcome, parsed, parsed.json);
1438
+ }
1439
+ catch (error) {
1440
+ console.error(`Error: ${toConductorErrorEnvelope(error).message}`);
1441
+ return ACKNOWLEDGE_GAPS_EXIT_FAILED;
1442
+ }
1443
+ }
1249
1444
  const MERGE_CHILD_USAGE = [
1250
- "Usage: epic-implementer merge-child --epic-run-id <id> --pr <number> [--json]",
1445
+ "Usage: epic-implementer merge-child --epic-run-id <id> --pr <number> [--carry-gaps] [--json]",
1251
1446
  "",
1252
1447
  "Merge the run's child pull request through the shared merge service. You give",
1253
1448
  "ONLY the PR number: the server finds the one ticket in the run bound to it",
@@ -1259,6 +1454,15 @@ const MERGE_CHILD_USAGE = [
1259
1454
  "When the repository merges locally (the default), your own `gh` performs the",
1260
1455
  "merge — run this from inside the repository's checkout, with `gh auth status`",
1261
1456
  "passing.",
1457
+ "",
1458
+ "--carry-gaps Merge a PARKED, green child whose only readiness blockers are",
1459
+ " carried verification gaps. It merges only into this run's own",
1460
+ " epic/<KEY> branch, after server checks: gap authority, run",
1461
+ " membership, the epic-branch base, the exact run-produced head,",
1462
+ " green required CI, mergeability, and review. It never merges into",
1463
+ " the default branch or the integration PR. The server records a",
1464
+ " driver-merge admission first; the carried gaps are listed on the",
1465
+ " integration PR for the owner.",
1262
1466
  ].join("\n");
1263
1467
  export async function runMergeChildCommand(argv) {
1264
1468
  try {
@@ -1273,7 +1477,12 @@ export async function runMergeChildCommand(argv) {
1273
1477
  const { mergeChildRepair } = await import("./recovery-operations.js");
1274
1478
  // BAPI-1461: this verb runs in the person's own session, so a merge token
1275
1479
  // stored once for this repository is the last rung after the env keys.
1276
- const outcome = await mergeChildRepair(access, { epicRunId: parsed.epicRunId, prNumber: parsed.prNumber }, {
1480
+ const outcome = await mergeChildRepair(access, {
1481
+ epicRunId: parsed.epicRunId,
1482
+ prNumber: parsed.prNumber,
1483
+ // BAPI-1564 — the key is sent only when the operator gave the flag.
1484
+ ...(parsed.carryGaps ? { carryGaps: true } : {}),
1485
+ }, {
1277
1486
  storedMergeCredential: {
1278
1487
  allowStoredEntry: true,
1279
1488
  localRemote: await readLocalGithubRemote(process.cwd()),
@@ -1614,8 +1823,9 @@ const CONTINUE_CHILD_USAGE = [
1614
1823
  "approves a new head or episode); continuation-receipt looks the receipt up.",
1615
1824
  "Never accepts a version counter or a park generation.",
1616
1825
  "",
1617
- "--context-file (CI-repair continuations only): driver context for the repair",
1618
- "worker, sent beside --reason (never merged into it). It must be non-empty UTF-8",
1826
+ "--context-file: driver context for the continuation's worker, delivered as quoted,",
1827
+ "untrusted operational context appended to the worker prompt. For a CI-repair",
1828
+ "continuation it is sent beside --reason (never merged into it). It must be non-empty UTF-8",
1619
1829
  `text of at most DRIVER_CONTEXT_MAX_BYTES (${DRIVER_CONTEXT_MAX_BYTES} bytes); it is`,
1620
1830
  "rejected, never truncated, and is never printed, logged, or echoed. A re-run of",
1621
1831
  "a pending request must pass the same file. A server that does not support it",
@@ -1738,7 +1948,7 @@ const CI_ROUTE_GUIDANCE = {
1738
1948
  "(rerun-ci). No repair was dispatched.",
1739
1949
  ci_route_hold: "CI routing is holding; no widened repair was dispatched. Re-read the run state " +
1740
1950
  "(explain-run) before choosing another action.",
1741
- driver_context_not_supported: "--context-file applies only to a CI-repair (ci_fix) continuation. Drop --context-file " +
1951
+ driver_context_not_supported: "This continuation cannot carry --context-file into a worker prompt. Drop --context-file " +
1742
1952
  "and re-run with --reason only. Nothing was written.",
1743
1953
  };
1744
1954
  /** Exported for tests: render a `continue-child` result. Returns the exit code. */
@@ -2546,6 +2756,17 @@ export function formatEscalateError(error) {
2546
2756
  export async function runEscalateCommand(argv, deps = {}) {
2547
2757
  // Captured before parsing can throw, so a malformed command line still answers
2548
2758
  // in the format the caller asked for.
2759
+ // BAPI-1642: the driver guard's detached lapse FYI. Exactly
2760
+ // `--lapse-record <path>`; it composes its own fixed request from the
2761
+ // guard-owned record and never takes free text from argv.
2762
+ if (argv[0] === "--lapse-record") {
2763
+ if (argv.length !== 2) {
2764
+ console.error("Error: --lapse-record takes exactly one path and no other flag.");
2765
+ return 1;
2766
+ }
2767
+ const { runLapseRecord } = await import("./driver-lapse.js");
2768
+ return runLapseRecord(argv[1]);
2769
+ }
2549
2770
  const json = argv.includes("--json");
2550
2771
  const fail = (document) => {
2551
2772
  if (json)
@@ -2573,7 +2794,7 @@ export async function runEscalateCommand(argv, deps = {}) {
2573
2794
  }
2574
2795
  const resolveAccess = deps.resolveAccess ?? (async () => {
2575
2796
  const { resolveConductorBridgeApiAccess } = await import("./bridge-api-client.js");
2576
- const resolved = await resolveConductorBridgeApiAccess();
2797
+ const resolved = await resolveConductorBridgeApiAccess({ followEpicLaunchProfile: true });
2577
2798
  return resolved.ok ? resolved.access : null;
2578
2799
  });
2579
2800
  const access = await resolveAccess();
@@ -18,7 +18,7 @@
18
18
  * callers: `recovery-cli.ts` and `plane/shutdown.ts`.
19
19
  */
20
20
  import { randomUUID } from "crypto";
21
- import { adoptCurrentHeadAndUnparkTicket, completeMergeChild, ConductorBridgeApiError, dispatchRemediation, fetchEpicRunState, mergeChild, patchPolicy, RERUN_CI_ROUTE_UNAVAILABLE_CODE, RERUN_CI_ROUTE_UNAVAILABLE_MESSAGE, rerunCi, resolveHandoff, resumeRun, safeDiagnosticMessage, scopeCatchUp, scopeReparse, stopEpicRun, unparkEpicTicket, updateEpicRunStatus, fetchChildContinuationStatus, postContinueParkedChild, postGrantContinuation, resumeCiTicket, regeneratePlanTicket, REVIEW_HEAD_REFUSAL_CODES, EXTERNAL_REPAIR_REFUSAL_CODES, EXTERNAL_REPAIR_RETRYABLE_CODES, } from "./bridge-api-client.js";
21
+ import { acknowledgeGaps, adoptCurrentHeadAndUnparkTicket, completeMergeChild, ConductorBridgeApiError, dispatchRemediation, fetchEpicRunState, mergeChild, patchPolicy, RERUN_CI_ROUTE_UNAVAILABLE_CODE, RERUN_CI_ROUTE_UNAVAILABLE_MESSAGE, rerunCi, resolveHandoff, resumeRun, safeDiagnosticMessage, scopeCatchUp, scopeReparse, stopEpicRun, unparkEpicTicket, updateEpicRunStatus, fetchChildContinuationStatus, postContinueParkedChild, postGrantContinuation, resumeCiTicket, regeneratePlanTicket, REVIEW_HEAD_REFUSAL_CODES, EXTERNAL_REPAIR_REFUSAL_CODES, EXTERNAL_REPAIR_RETRYABLE_CODES, } from "./bridge-api-client.js";
22
22
  import { clearGuidedReference, guardForBinding, GUIDED_PAYLOAD_CONFLICT_MESSAGE, GUIDED_REFERENCE_STORE_FAILED_MESSAGE, guidedPayloadDigest, prepareGuidedRequest, } from "./guided-repair.js";
23
23
  import { DEFAULT_GATE_NAME } from "./git-ci-types.js";
24
24
  import { bindingsDriverContextSha256, CONTINUATION_CI_WAITING_REASONS, canonicalSha256, clearContinuationReference, clearRecoveryReferenceFile, computeContinuationFingerprint, driverContextSha256, readRecoveryReferenceFile, writeRecoveryReferenceFile, isFullSha, newContinuationRequestId, readContinuationReference, writeContinuationReference, } from "./epic-child-continuation.js";
@@ -177,7 +177,7 @@ async function ticketRecoveryWithRetry(access, options, mutate) {
177
177
  result = await mutate(access, {
178
178
  epicRunId: options.epicRunId,
179
179
  ticketKey: options.ticketKey,
180
- expectedRowVersion: ticket.row_version,
180
+ expectedRowVersion: options.expectedRowVersion ?? ticket.row_version,
181
181
  idempotencyKey,
182
182
  reason: options.reason,
183
183
  cleanupResolution: options.cleanupResolution,
@@ -199,6 +199,11 @@ async function ticketRecoveryWithRetry(access, options, mutate) {
199
199
  ...(refusal.retryable !== undefined ? { retryable: refusal.retryable } : {}),
200
200
  };
201
201
  }
202
+ // BAPI-1554: for an HTTP 400 `VALIDATION` refusal the client has already read
203
+ // the server's bounded `detail.error` into `bodyPreview` (stale-CAS handled
204
+ // first, inside the client), and `safeDiagnosticMessage` puts it after the
205
+ // `kind=/status=/code=` prefix. A missing, blank, or unusable explanation
206
+ // leaves only that prefix, so the generic diagnostic is the fallback.
202
207
  return {
203
208
  ok: false,
204
209
  kind: "unavailable",
@@ -220,6 +225,8 @@ async function ticketRecoveryWithRetry(access, options, mutate) {
220
225
  ...(external ? { externalRepair: external } : {}),
221
226
  };
222
227
  }
228
+ if (options.expectedRowVersion !== undefined)
229
+ break;
223
230
  // `result.kind === "cas-conflict"`: a concurrent write moved the ticket's
224
231
  // row_version between our read and our mutate. Loop back to a fresh read —
225
232
  // never reuse `result.current_row_version` here.
@@ -326,6 +333,9 @@ function classifyRepairError(err, fallback) {
326
333
  code: err.errorCode,
327
334
  status: err.status,
328
335
  message: err.bodyPreview ?? err.errorCode,
336
+ ...(typeof err.holderJobId === "number" && typeof err.holderJobType === "string"
337
+ ? { holder: { job_id: err.holderJobId, job_type: err.holderJobType } }
338
+ : {}),
329
339
  };
330
340
  }
331
341
  return { ok: false, kind: "unavailable", message: safeDiagnosticMessage(err, fallback) };
@@ -353,6 +363,19 @@ export async function resolveHandoffRepair(access, options, deps = {}) {
353
363
  return classifyRepairError(err, "resolve-handoff request failed");
354
364
  }
355
365
  }
366
+ /**
367
+ * BAPI-1562 — the owner's ONE acknowledgement of the run's carried-gap list. A
368
+ * thin wrapper so the CLI shares the closed refusal classification above.
369
+ */
370
+ export async function acknowledgeGapsRepair(access, options, deps = {}) {
371
+ try {
372
+ const call = deps.acknowledgeGaps ?? acknowledgeGaps;
373
+ return { ok: true, result: await call(access, options) };
374
+ }
375
+ catch (err) {
376
+ return classifyRepairError(err, "acknowledge-gaps request failed");
377
+ }
378
+ }
356
379
  /**
357
380
  * Dispatch a remediation job with driver context. `context` must already be
358
381
  * validated against `DRIVER_CONTEXT_MAX_BYTES`; the server selects the job type.
@@ -422,7 +445,14 @@ export async function mergeChildRepair(access, options, deps = {}) {
422
445
  // which is discarded — never the server's action key, which the server
423
446
  // recomposes itself at completion.
424
447
  action_key: `merge-child:${options.epicRunId}:${options.prNumber}`,
425
- }, { method: resolveLocalMergeMethod(local.merge_method) },
448
+ }, {
449
+ method: resolveLocalMergeMethod(local.merge_method),
450
+ // BAPI-1564 — a carry-gaps approval names its base; the local ref guard
451
+ // re-checks it before `gh pr merge`. A plain approval carries none.
452
+ ...(local.expected_base_branch !== undefined
453
+ ? { expectedBaseBranch: local.expected_base_branch }
454
+ : {}),
455
+ },
426
456
  // BAPI-1136: an explicitly configured local credential, never the ambient
427
457
  // login. `env` remains the source of the allowlisted operational base only.
428
458
  { env, credential });
@@ -960,7 +990,7 @@ export const RESUME_CI_POST_LIMIT = 3;
960
990
  const RESUME_CI_RETRY_DELAY_MS = 250;
961
991
  const FULL_SHA_PATTERN = /^[0-9a-f]{40}$/;
962
992
  const FINGERPRINT_PATTERN = /^[0-9a-f]{64}$/;
963
- const CI_STOP_REASON_VALUES = new Set(["wait_expired", "verdict_unavailable", "repair_exhausted"]);
993
+ const CI_STOP_REASON_VALUES = new Set(["wait_expired", "verdict_unavailable", "repair_exhausted", "required_check_not_reporting"]);
964
994
  function isRecordValue(value) {
965
995
  return value !== null && typeof value === "object" && !Array.isArray(value);
966
996
  }
@@ -25,6 +25,12 @@ export const VERB_RESUME_RUN = "resume-run";
25
25
  export const VERB_RESUME_CI = "resume-ci";
26
26
  export const VERB_RERUN_CI = "rerun-ci";
27
27
  export const VERB_RESOLVE_HANDOFF = "resolve-handoff";
28
+ /**
29
+ * BAPI-1562 — the owner's ONE acknowledgement of the run's carried-gap list by
30
+ * its digest. An owner step: the driver never runs it and the worker guard
31
+ * denies it.
32
+ */
33
+ export const VERB_ACKNOWLEDGE_GAPS = "acknowledge-gaps";
28
34
  /** Every repair verb, in the order an operator meets them. */
29
35
  export const OPERATOR_REPAIR_VERBS = [
30
36
  VERB_SCOPE_REPARSE,
@@ -36,6 +42,7 @@ export const OPERATOR_REPAIR_VERBS = [
36
42
  VERB_RESUME_CI,
37
43
  VERB_RERUN_CI,
38
44
  VERB_RESOLVE_HANDOFF,
45
+ VERB_ACKNOWLEDGE_GAPS,
39
46
  ];
40
47
  /**
41
48
  * The ONE cap on driver context, in UTF-8 BYTES — the same number the server
@@ -124,6 +131,12 @@ export const OPERATOR_REPAIR_REFUSAL_CODES = [
124
131
  "HANDOFF_LEDGER_UNREADABLE",
125
132
  "HANDOFF_RESOLUTION_CAPACITY",
126
133
  "HANDOFF_SELECTION_CHANGED",
134
+ // BAPI-1555
135
+ "MERGE_ALREADY_ADMITTED",
136
+ // BAPI-1562
137
+ "GAP_LIST_UNREADABLE",
138
+ "GAP_LIST_EMPTY",
139
+ "GAP_DIGEST_STALE",
127
140
  ];
128
141
  /** True when `code` is one of the closed repair refusal codes. */
129
142
  export function isOperatorRepairRefusalCode(code) {
@@ -252,3 +265,23 @@ export const HANDOFF_RESOLUTION_KIND_LABELS = {
252
265
  export const HANDOFF_RESOLUTION_MAX_STEPS = 50;
253
266
  export const HANDOFF_RESOLUTION_EVIDENCE_REF_MAX_CHARS = 500;
254
267
  export const HANDOFF_RESOLUTION_REASON_MAX_CHARS = 2000;
268
+ // ---------------------------------------------------------------------------
269
+ // BAPI-1562 — `acknowledge-gaps`
270
+ // ---------------------------------------------------------------------------
271
+ /**
272
+ * The closed `acknowledge-gaps` refusal subset, in check order — mirrors
273
+ * `ACKNOWLEDGE_GAPS_REFUSAL_CODES` in `operator_repair_contract.py`.
274
+ */
275
+ export const ACKNOWLEDGE_GAPS_REFUSAL_CODES = [
276
+ "RESOLUTION_ACTOR_UNAVAILABLE",
277
+ "GAP_LIST_UNREADABLE",
278
+ "GAP_LIST_EMPTY",
279
+ "GAP_DIGEST_STALE",
280
+ ];
281
+ /** True when `code` is one of the closed `acknowledge-gaps` refusal codes. */
282
+ export function isAcknowledgeGapsRefusalCode(code) {
283
+ return (typeof code === "string" &&
284
+ ACKNOWLEDGE_GAPS_REFUSAL_CODES.includes(code));
285
+ }
286
+ /** The acknowledgement reason bound (`GAP_ACKNOWLEDGEMENT_REASON_MAX_CHARS`). */
287
+ export const GAP_ACKNOWLEDGEMENT_REASON_MAX_CHARS = 1000;
@@ -18,6 +18,16 @@ import { resolveConductorBridgeApiAccess, fetchEpicRunState, fetchExplainRun, Co
18
18
  function jsonResult(value) {
19
19
  return { content: [{ type: "text", text: JSON.stringify(value, null, 2) }] };
20
20
  }
21
+ /**
22
+ * BAPI-1557: compact (unindented) JSON, used by `get_epic_snapshot`; BAPI-1649
23
+ * adds `explain_run`. Every other conductor tool keeps {@link jsonResult}'s
24
+ * pretty output.
25
+ */
26
+ function compactJsonResult(value) {
27
+ return { content: [{ type: "text", text: JSON.stringify(value) }] };
28
+ }
29
+ /** The snapshot tool's default executor-job row budget (soft; must-keep rows may exceed it). */
30
+ export const SNAPSHOT_DEFAULT_JOB_LIMIT = 50;
21
31
  /**
22
32
  * Wrap a tool handler so any thrown value becomes a sanitized structured JSON
23
33
  * error envelope (validation -> 400, store-busy -> 503, otherwise 500). Raw
@@ -51,16 +61,33 @@ function registerGetEpicSnapshotTool(registerTool) {
51
61
  "Read-only; never triggers a tick, transitions Jira, or mutates Epic state.",
52
62
  inputSchema: {
53
63
  epic_key: z.string().min(1).describe("The epic identifier to fetch the snapshot for (e.g. EPIC-123)."),
64
+ job_limit: z
65
+ .number()
66
+ .int()
67
+ .min(1)
68
+ .max(200)
69
+ .optional()
70
+ .describe("Soft job row budget, 1-200 (default 50)."),
71
+ ticket_key: z
72
+ .string()
73
+ .min(1)
74
+ .optional()
75
+ .describe("Scope to one ticket."),
54
76
  },
55
77
  }, withConductorToolErrorHandling(async (args) => {
56
78
  const epicKey = args.epic_key;
79
+ const jobLimit = args.job_limit ?? SNAPSHOT_DEFAULT_JOB_LIMIT;
80
+ const ticketKey = args.ticket_key;
57
81
  const accessResult = await resolveConductorBridgeApiAccess();
58
82
  if (!accessResult.ok) {
59
83
  throw new ConductorValidationError(accessResult.error);
60
84
  }
61
85
  try {
62
- const result = await fetchEpicRunState(accessResult.access, epicKey);
63
- return jsonResult(result);
86
+ const result = await fetchEpicRunState(accessResult.access, epicKey, undefined, {
87
+ job_limit: jobLimit,
88
+ ...(ticketKey !== undefined ? { ticket_key: ticketKey } : {}),
89
+ });
90
+ return compactJsonResult(result);
64
91
  }
65
92
  catch (error) {
66
93
  if (error instanceof ConductorBridgeApiError && error.status === 404) {
@@ -97,17 +124,22 @@ function registerExplainRunTool(registerTool) {
97
124
  .min(1)
98
125
  .optional()
99
126
  .describe("Narrow the answer to one ticket in the run."),
127
+ include_run: z
128
+ .boolean()
129
+ .optional()
130
+ .describe("With ticket_key: return full run summary, lists."),
100
131
  },
101
132
  }, withConductorToolErrorHandling(async (args) => {
102
133
  const epicRunId = args.epic_run_id;
103
134
  const ticketKey = args.ticket_key;
135
+ const includeRun = args.include_run;
104
136
  const scope = ticketKey === undefined ? "run" : "ticket";
105
137
  const accessResult = await resolveConductorBridgeApiAccess();
106
138
  if (!accessResult.ok) {
107
139
  throw new ConductorValidationError(accessResult.error);
108
140
  }
109
141
  try {
110
- return jsonResult(await fetchExplainRun(accessResult.access, epicRunId, ticketKey));
142
+ return compactJsonResult(await fetchExplainRun(accessResult.access, epicRunId, ticketKey, undefined, includeRun !== undefined ? { include_run: includeRun } : {}));
111
143
  }
112
144
  catch (error) {
113
145
  if (error instanceof ConductorBridgeApiError && error.status === 404) {
@@ -115,7 +147,7 @@ function registerExplainRunTool(registerTool) {
115
147
  // exists but has no such ticket" — the server distinguishes them and
116
148
  // collapsing both to one envelope would throw that away. No server
117
149
  // detail is echoed either way.
118
- return jsonResult({ status: "unknown", scope });
150
+ return compactJsonResult({ status: "unknown", scope });
119
151
  }
120
152
  throw error;
121
153
  }