@bridge_gpt/mcp-server 0.2.69 → 0.2.71

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 (164) hide show
  1. package/README.md +140 -292
  2. package/build/agent-launchers/claude-executor-adapter.js +27 -5
  3. package/build/agent-registry.js +5 -5
  4. package/build/agents.generated.js +15 -5
  5. package/build/artifact-diff.js +110 -0
  6. package/build/bin-entrypoint.js +36 -0
  7. package/build/bounded-wait.js +9 -1
  8. package/build/bridge-permissions.js +36 -9
  9. package/build/claude-review-workflow-drift.js +3 -3
  10. package/build/codex-bridge-profile.js +1 -1
  11. package/build/commands.generated.js +6 -6
  12. package/build/conductor/bridge-api-client.js +858 -21
  13. package/build/conductor/bring-up-facts.js +9 -9
  14. package/build/conductor/command-drift-production.js +7 -2
  15. package/build/conductor/doctor.js +472 -18
  16. package/build/conductor/epic-child-continuation.js +54 -3
  17. package/build/conductor/epic-implementer-cli.js +136 -34
  18. package/build/conductor/epic-runtime.js +2 -2
  19. package/build/conductor/epic-state.js +1 -1
  20. package/build/conductor/gate-discovery.js +524 -10
  21. package/build/conductor/gate-settings-review.js +451 -0
  22. package/build/conductor/hook-runtime-qualification.js +1 -1
  23. package/build/conductor/install-doctor.js +4 -2
  24. package/build/conductor/launch-need-probes.js +342 -0
  25. package/build/conductor/launch-plan.js +145 -0
  26. package/build/conductor/local-merge.js +241 -56
  27. package/build/conductor/merge-credential.js +172 -0
  28. package/build/conductor/merge-execution-eligibility.js +1 -1
  29. package/build/conductor/merged-child-check.js +95 -0
  30. package/build/conductor/plan-trim.js +30 -0
  31. package/build/conductor/pr-ci-producer.js +1 -1
  32. package/build/conductor/precheck-timings.js +14 -0
  33. package/build/conductor/preview-observations.js +10 -0
  34. package/build/conductor/readiness-cli.js +11 -6
  35. package/build/conductor/readiness-prerequisites.js +41 -0
  36. package/build/conductor/readiness-sections.js +348 -55
  37. package/build/conductor/readiness.js +99 -87
  38. package/build/conductor/recovery-cli.js +665 -23
  39. package/build/conductor/recovery-operations.js +350 -8
  40. package/build/conductor/repair-contract.js +47 -2
  41. package/build/conductor/repository-workflow-remedy.js +8 -6
  42. package/build/conductor/stored-merge-credential.js +76 -0
  43. package/build/conductor/stored-merge-token-probe.js +28 -0
  44. package/build/conductor/temporary-plan.js +50 -0
  45. package/build/conductor/wait-run-cli.js +759 -0
  46. package/build/conductor/worker-database-doctor-inspector.js +49 -0
  47. package/build/conductor-bin.js +2 -2
  48. package/build/conductor-claude-hook-bin.js +2 -2
  49. package/build/conductor-claude-hook-removed-stub-bin.js +2 -5
  50. package/build/conductor-removed-stub-bin.js +2 -5
  51. package/build/credential-store.js +356 -13
  52. package/build/docs.generated.js +26 -13
  53. package/build/doctor.js +94 -32
  54. package/build/drive-epic-help.js +212 -0
  55. package/build/drive-epic.js +1989 -379
  56. package/build/epic-ci-workflow-drift.js +125 -0
  57. package/build/epic-ci-workflow-install.js +240 -0
  58. package/build/epic-ci-workflow-v1.js +132 -0
  59. package/build/epic-ci-workflow.js +318 -0
  60. package/build/epic-contract-context.js +326 -0
  61. package/build/epic-implementer-bin.js +58 -42
  62. package/build/epic-implementer-claude-hook-bin.js +2 -2
  63. package/build/escalation-reachability.js +134 -0
  64. package/build/executor/ci-rerun-job.js +220 -14
  65. package/build/executor/cleanup-report.js +99 -0
  66. package/build/executor/cli.js +12 -1
  67. package/build/executor/completion-contract.js +66 -11
  68. package/build/executor/completion-supervision.js +99 -0
  69. package/build/executor/delivery-outcome.js +179 -0
  70. package/build/executor/deps.js +3 -0
  71. package/build/executor/env.js +276 -1
  72. package/build/executor/failure-reason-codes.js +126 -0
  73. package/build/executor/gate-qualification-job.js +20 -5
  74. package/build/executor/heartbeat.js +38 -0
  75. package/build/executor/http-client.js +72 -0
  76. package/build/executor/integration-job.js +298 -5
  77. package/build/executor/job-errors.js +36 -6
  78. package/build/executor/job-runner.js +830 -45
  79. package/build/executor/likely-tests.js +42 -3
  80. package/build/executor/merge-job.js +145 -2
  81. package/build/executor/observation.js +73 -4
  82. package/build/executor/permissions.js +193 -97
  83. package/build/executor/preflight.js +19 -3
  84. package/build/executor/process-containment.js +46 -2
  85. package/build/executor/prompt-spec.js +113 -9
  86. package/build/executor/rebase-finalization.js +38 -3
  87. package/build/executor/reconcile-overlap-job.js +41 -8
  88. package/build/executor/required-work-ledger.js +236 -81
  89. package/build/executor/resume-pre-spawn.js +38 -1
  90. package/build/executor/runner.js +91 -3
  91. package/build/executor/test-clock.js +8 -0
  92. package/build/executor/types.js +37 -2
  93. package/build/executor/worker-cli-launcher.js +259 -0
  94. package/build/executor/worker-command.js +177 -5
  95. package/build/executor/worker-database-target.js +91 -0
  96. package/build/executor/worker-database.js +927 -0
  97. package/build/executor/worker-finalization.js +106 -0
  98. package/build/executor/worker-guard-hook.js +203 -0
  99. package/build/executor/worker-resources.js +58 -0
  100. package/build/executor/worker-verification-guidance.js +44 -2
  101. package/build/executor/worktree.js +303 -15
  102. package/build/executor-launch.js +11 -1
  103. package/build/generated-assets-doctor.js +9 -1
  104. package/build/generated-assets-health.js +13 -4
  105. package/build/generated-assets-legacy.js +39 -0
  106. package/build/generated-assets-paths.js +12 -1
  107. package/build/generated-assets-repair.js +4 -1
  108. package/build/generated-assets-test-support.js +12 -0
  109. package/build/github-remote.js +33 -0
  110. package/build/github-sign-in.js +62 -0
  111. package/build/index.js +1133 -546
  112. package/build/init.js +39 -1
  113. package/build/install-bridge-conductor-gate.js +270 -11
  114. package/build/install-bridge-conductor-setup.js +427 -0
  115. package/build/install-bridge-conductor.js +1545 -268
  116. package/build/install-bridge.js +376 -60
  117. package/build/mcp-install-state.js +8 -2
  118. package/build/merge-pull-request.js +6 -0
  119. package/build/merge-workflow-install.js +782 -344
  120. package/build/phase-result-artifacts.js +75 -20
  121. package/build/pipeline-orchestrator.js +247 -4
  122. package/build/pipelines.generated.js +35 -35
  123. package/build/plan-discovery.js +15 -2
  124. package/build/plan-execution-ledger.js +321 -17
  125. package/build/plan-phase-routing.js +48 -13
  126. package/build/plane/cli.js +105 -51
  127. package/build/plane/defaults.js +3 -0
  128. package/build/plane/plane-freshness.js +298 -0
  129. package/build/plane/preflight.js +19 -0
  130. package/build/plane/schema-compatibility.js +137 -0
  131. package/build/plane/shutdown-deps.js +38 -0
  132. package/build/plane/shutdown.js +83 -8
  133. package/build/plane/terminal-run-cleanup.js +303 -0
  134. package/build/printed-remedy-commands.js +33 -4
  135. package/build/readiness-check.js +6 -2
  136. package/build/readiness-prerequisites.generated.js +532 -0
  137. package/build/readme.generated.js +1 -1
  138. package/build/repository-toolchains.js +581 -0
  139. package/build/setup-epic.js +421 -34
  140. package/build/shared-resources.generated.js +5 -0
  141. package/build/start-tickets.js +28 -15
  142. package/build/test-command-detection.js +284 -0
  143. package/build/test-command-validation.js +73 -0
  144. package/build/testing-config-client.js +150 -0
  145. package/build/ticket-delivery-artifacts.js +265 -0
  146. package/build/ticket-delivery-enrollment.js +369 -0
  147. package/build/ticket-delivery.js +205 -0
  148. package/build/ticket-review-summary.js +14 -0
  149. package/build/upgrade-cli.js +13 -0
  150. package/build/v2-readiness-requirements.js +552 -0
  151. package/build/version.generated.js +3 -3
  152. package/build/worker-guard-hook-bin.js +2 -2
  153. package/build/worktree-core.js +22 -7
  154. package/docs/BRIDGE-DIRECTORY-README.md +48 -0
  155. package/docs/EPIC-IMPLEMENTER-INSTALL.md +12 -867
  156. package/docs/EPIC-IMPLEMENTER.md +142 -63
  157. package/docs/epic-implementer/getting-started.md +187 -0
  158. package/docs/epic-implementer/self-hosting.md +133 -0
  159. package/package.json +4 -4
  160. package/pipelines/idea-to-ticket.json +1 -1
  161. package/pipelines/implement-ticket.json +8 -8
  162. package/pipelines/review-ticket.json +2 -2
  163. package/design-assets/favicon/favicon-32x32.png +0 -0
  164. package/design-assets/just-logo-rough-draft.png +0 -0
@@ -18,11 +18,12 @@
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, resumeRun, safeDiagnosticMessage, scopeCatchUp, scopeReparse, stopEpicRun, unparkEpicTicket, updateEpicRunStatus, fetchChildContinuationStatus, postContinueParkedChild, postGrantContinuation, resumeCiTicket, REVIEW_HEAD_REFUSAL_CODES, } from "./bridge-api-client.js";
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";
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
- import { canonicalSha256, clearContinuationReference, clearRecoveryReferenceFile, computeContinuationFingerprint, readRecoveryReferenceFile, writeRecoveryReferenceFile, isFullSha, newContinuationRequestId, readContinuationReference, writeContinuationReference, } from "./epic-child-continuation.js";
24
+ import { bindingsDriverContextSha256, CONTINUATION_CI_WAITING_REASONS, canonicalSha256, clearContinuationReference, clearRecoveryReferenceFile, computeContinuationFingerprint, driverContextSha256, readRecoveryReferenceFile, writeRecoveryReferenceFile, isFullSha, newContinuationRequestId, readContinuationReference, writeContinuationReference, } from "./epic-child-continuation.js";
25
25
  import { resolveLocalMergeCredential, resolveLocalMergeMethod, runApprovedLocalMerge, } from "./local-merge.js";
26
+ import { resolveMergeCredentialAtAction, } from "./stored-merge-credential.js";
26
27
  import { RERUN_CI_UNCONFIRMED_REASON, RESUME_RUN_UNCONFIRMED_MESSAGE } from "./repair-contract.js";
27
28
  /**
28
29
  * Bounded total attempts for a ticket-recovery CAS retry loop. Each attempt
@@ -180,10 +181,13 @@ async function ticketRecoveryWithRetry(access, options, mutate) {
180
181
  idempotencyKey,
181
182
  reason: options.reason,
182
183
  cleanupResolution: options.cleanupResolution,
184
+ ...(options.externalRepairOperationId !== undefined
185
+ ? { externalRepairOperationId: options.externalRepairOperationId }
186
+ : {}),
183
187
  });
184
188
  }
185
189
  catch (err) {
186
- const refusal = reviewHeadRefusal(err);
190
+ const refusal = reviewHeadRefusal(err) ?? externalRepairRefusal(err);
187
191
  if (refusal !== null) {
188
192
  return {
189
193
  ok: false,
@@ -192,6 +196,7 @@ async function ticketRecoveryWithRetry(access, options, mutate) {
192
196
  ticketKey: options.ticketKey,
193
197
  errorCode: refusal.errorCode,
194
198
  message: refusal.message,
199
+ ...(refusal.retryable !== undefined ? { retryable: refusal.retryable } : {}),
195
200
  };
196
201
  }
197
202
  return {
@@ -204,6 +209,7 @@ async function ticketRecoveryWithRetry(access, options, mutate) {
204
209
  }
205
210
  if (result.ok) {
206
211
  const recovery = result.ticket_status.review_head_recovery;
212
+ const external = result.ticket_status.external_repair;
207
213
  return {
208
214
  ok: true,
209
215
  kind: "unparked",
@@ -211,6 +217,7 @@ async function ticketRecoveryWithRetry(access, options, mutate) {
211
217
  ticketKey: options.ticketKey,
212
218
  status: result.ticket_status.status,
213
219
  ...(recovery ? { reviewHeadRecovery: recovery } : {}),
220
+ ...(external ? { externalRepair: external } : {}),
214
221
  };
215
222
  }
216
223
  // `result.kind === "cas-conflict"`: a concurrent write moved the ticket's
@@ -249,6 +256,43 @@ function reviewHeadRefusal(err) {
249
256
  return null;
250
257
  return { errorCode: code, message: REVIEW_HEAD_REFUSAL_MESSAGES[code] ?? "refused" };
251
258
  }
259
+ /**
260
+ * BAPI-1537: fixed operator sentences for the external-repair refusal codes,
261
+ * each naming the exit from the ticket's refusal table. Chosen by code so no
262
+ * server or provider text reaches the terminal.
263
+ */
264
+ const EXTERNAL_REPAIR_REFUSAL_MESSAGES = {
265
+ EXTERNAL_REPAIR_RUN_NOT_RECOVERABLE: "the run is paused, stopped, quarantined, or not active; resolve the run control " +
266
+ "(for example resume-run), then retry with the same operation id",
267
+ EXTERNAL_REPAIR_NOT_PARKED: "the ticket is not parked at exactly one gate, so the engine owns it; re-read explain-run",
268
+ EXTERNAL_REPAIR_LIVE_WORK: "an executor job for this ticket is queued or running; wait for it to end, re-read, " +
269
+ "and re-diagnose",
270
+ EXTERNAL_REPAIR_BRANCH_MISMATCH: "the repair is not on the ticket's own feature branch; push it to that branch",
271
+ EXTERNAL_REPAIR_ANCESTRY: "the branch head equals or does not descend from the ticket's recorded head; replay " +
272
+ "the commits fast-forward onto that head (never force), or end the intervention",
273
+ EXTERNAL_REPAIR_PR_MISMATCH: "the open pull request is cross-repository or has the wrong base or head; fix its " +
274
+ "base or head, or close the stray pull request, then retry",
275
+ EXTERNAL_REPAIR_PR_AMBIGUOUS: "more than one pull request is open from the ticket's branch; close the extras, then retry",
276
+ EXTERNAL_REPAIR_HEAD_CLAIMED: "another ticket or run already has this head bound; this is outside the sandbox, so " +
277
+ "apply the stop list",
278
+ EXTERNAL_REPAIR_OPERATION_CONFLICT: "this operation id already adopted a different head; use a new operation id",
279
+ EXTERNAL_REPAIR_UNAVAILABLE: "a provider or ancestry read was unreadable; retry with the same operation id",
280
+ EXTERNAL_REPAIR_ALREADY_INTEGRATED: "the repair head is already in the epic branch, so the parked-external-merge fold owns " +
281
+ "recovery; re-read explain-run",
282
+ };
283
+ /** Map a thrown client error to an external-repair refusal, or `null` for anything else. */
284
+ function externalRepairRefusal(err) {
285
+ if (!(err instanceof ConductorBridgeApiError) || err.status !== 409)
286
+ return null;
287
+ const code = err.errorCode;
288
+ if (typeof code !== "string" || !EXTERNAL_REPAIR_REFUSAL_CODES.includes(code))
289
+ return null;
290
+ return {
291
+ errorCode: code,
292
+ message: EXTERNAL_REPAIR_REFUSAL_MESSAGES[code] ?? "refused",
293
+ retryable: EXTERNAL_REPAIR_RETRYABLE_CODES.includes(code),
294
+ };
295
+ }
252
296
  /**
253
297
  * Unpark a parked `needs_human` ticket, with a bounded authoritative-reread
254
298
  * retry on a concurrent `row_version` bump.
@@ -296,6 +340,19 @@ export async function scopeReparseRepair(access, options, deps = {}) {
296
340
  return classifyRepairError(err, "scope-reparse request failed");
297
341
  }
298
342
  }
343
+ /**
344
+ * BAPI-1494 — record the owner's decision on a ticket's verification hand-offs.
345
+ * The server records the verified request actor and decides every refusal.
346
+ */
347
+ export async function resolveHandoffRepair(access, options, deps = {}) {
348
+ try {
349
+ const call = deps.resolveHandoff ?? resolveHandoff;
350
+ return { ok: true, result: await call(access, options) };
351
+ }
352
+ catch (err) {
353
+ return classifyRepairError(err, "resolve-handoff request failed");
354
+ }
355
+ }
299
356
  /**
300
357
  * Dispatch a remediation job with driver context. `context` must already be
301
358
  * validated against `DRIVER_CONTEXT_MAX_BYTES`; the server selects the job type.
@@ -341,6 +398,17 @@ export async function mergeChildRepair(access, options, deps = {}) {
341
398
  return { ok: true, result: serverResult };
342
399
  }
343
400
  const runLocal = deps.runLocalMerge ?? runApprovedLocalMerge;
401
+ const env = deps.env ?? process.env;
402
+ // BAPI-1461: the repository identity is resolved before any store lookup, and
403
+ // an unresolved or conflicting identity reads nothing.
404
+ const resolution = deps.storedMergeCredential
405
+ ? await resolveMergeCredentialAtAction(env, "local", deps.storedMergeCredential)
406
+ : null;
407
+ const credential = resolution === null
408
+ ? resolveLocalMergeCredential(env, "local")
409
+ : resolution.status === "resolved"
410
+ ? resolution.credential
411
+ : null;
344
412
  let succeeded = false;
345
413
  let alreadyMerged = false;
346
414
  let failureReason = "gh_merge_failed";
@@ -357,10 +425,7 @@ export async function mergeChildRepair(access, options, deps = {}) {
357
425
  }, { method: resolveLocalMergeMethod(local.merge_method) },
358
426
  // BAPI-1136: an explicitly configured local credential, never the ambient
359
427
  // login. `env` remains the source of the allowlisted operational base only.
360
- {
361
- env: deps.env ?? process.env,
362
- credential: resolveLocalMergeCredential(deps.env ?? process.env, "local"),
363
- });
428
+ { env, credential });
364
429
  succeeded = localResult.status === "succeeded";
365
430
  alreadyMerged = succeeded && localResult.reason === "already_merged";
366
431
  failureReason = boundedLocalMergeReason(localResult.reason);
@@ -632,6 +697,22 @@ export async function continueChildOnce(access, options, deps = {}) {
632
697
  reference = null;
633
698
  }
634
699
  const reusedReference = reference !== null;
700
+ // BAPI-1514 — a reused request is bound to the context it was first sent with
701
+ // (by hash). Re-sending it with a different context, or with/without one, would
702
+ // be a different request under the same id; refuse locally, sending nothing.
703
+ if (reference !== null) {
704
+ const storedSha = bindingsDriverContextSha256(reference.bindings);
705
+ const wantedSha = options.driverContext === undefined ? undefined : driverContextSha256(options.driverContext);
706
+ if (storedSha !== wantedSha) {
707
+ return {
708
+ kind: "unavailable",
709
+ message: `a pending continuation request (${reference.requestId}) was sent ` +
710
+ (storedSha === undefined ? "without --context-file" : "with a different --context-file") +
711
+ "; re-run with the same --context-file (or none, as before) to settle that same " +
712
+ "request, or look it up with continuation-receipt",
713
+ };
714
+ }
715
+ }
635
716
  if (reference === null) {
636
717
  let status;
637
718
  try {
@@ -662,6 +743,7 @@ export async function continueChildOnce(access, options, deps = {}) {
662
743
  expectedRowVersion: current.row_version,
663
744
  expectedHeadSha: head,
664
745
  sourceParkGeneration: current.park_generation,
746
+ ...(options.driverContext !== undefined ? { driverContext: options.driverContext } : {}),
665
747
  };
666
748
  reference = {
667
749
  version: 1,
@@ -699,9 +781,15 @@ export async function continueChildOnce(access, options, deps = {}) {
699
781
  requestFingerprint: ref.requestFingerprint,
700
782
  reason: options.reason,
701
783
  workerExitProof: options.workerExitProof,
784
+ ...(options.driverContext !== undefined ? { driverContext: options.driverContext } : {}),
702
785
  });
703
786
  if (outcome.kind === "result" && AUTHORITATIVE_OUTCOMES.has(outcome.result.outcome)) {
704
- await clear();
787
+ const keepForRetry = outcome.result.outcome === "refused" &&
788
+ outcome.result.retryable &&
789
+ outcome.result.reason_code !== null &&
790
+ CONTINUATION_CI_WAITING_REASONS.has(outcome.result.reason_code);
791
+ if (!keepForRetry)
792
+ await clear();
705
793
  return { kind: "decided", requestId: ref.requestId, reusedReference, result: outcome.result };
706
794
  }
707
795
  if (outcome.kind === "refused_http") {
@@ -711,6 +799,7 @@ export async function continueChildOnce(access, options, deps = {}) {
711
799
  requestId: ref.requestId,
712
800
  status: outcome.status,
713
801
  errorCode: outcome.errorCode,
802
+ ...(options.driverContext !== undefined ? { driverContextSent: true } : {}),
714
803
  };
715
804
  }
716
805
  // Uncertain (transport, malformed 2xx, 5xx, or the server's own unconfirmed).
@@ -1131,3 +1220,256 @@ export async function resumeCiOnce(access, options, deps = {}) {
1131
1220
  : "indeterminate";
1132
1221
  return { kind: "unconfirmed", transport, reusedReference, attempts: RESUME_CI_POST_LIMIT };
1133
1222
  }
1223
+ // ---------------------------------------------------------------------------
1224
+ // BAPI-1532 — `regenerate-plan`: a pinned, bounded answer to a named plan failure
1225
+ // ---------------------------------------------------------------------------
1226
+ /** The recovery-reference namespace of pinned `regenerate-plan` operations. */
1227
+ export const REGENERATE_PLAN_REFERENCE_NAMESPACE = "epic-plan-regenerations";
1228
+ /**
1229
+ * Bounded POSTs per invocation. Every POST of one invocation carries the SAME
1230
+ * operation key, route, reason, and park generation; only the row version may be
1231
+ * refreshed, and only while the park identity still matches.
1232
+ */
1233
+ export const REGENERATE_PLAN_POST_LIMIT = 3;
1234
+ const REGENERATE_PLAN_RETRY_DELAY_MS = 250;
1235
+ const REGENERATE_PLAN_OPERATION_KEY_PATTERN = /^[A-Za-z0-9][A-Za-z0-9._:-]{7,127}$/;
1236
+ const FINALIZATION_CAUSE = "worker_finalization_missing_branch_and_pr";
1237
+ /** The longest driver reason the request carries; the server bounds it again. */
1238
+ export const REGENERATE_PLAN_REASON_MAX_CHARS = 500;
1239
+ /**
1240
+ * Capture the park identity a `regenerate-plan` is pinned to, from authenticated
1241
+ * ticket state, mirroring the server's selection: the ticket is `needs_human`,
1242
+ * its single parked gate is `implement`, and either that gate holds a `parked`
1243
+ * `plan_failure` record for its own park generation, or its committed cause is the
1244
+ * BAPI-1487 finalization park (which the server admits through its own predicate
1245
+ * and which names no planner reason). Never derived from the park's reason text.
1246
+ */
1247
+ export function captureRegeneratePlanSubject(ticket) {
1248
+ if (ticket.status !== "needs_human")
1249
+ return { ok: false, reason: "not_parked" };
1250
+ const gates = isRecordValue(ticket.gates) ? ticket.gates : {};
1251
+ const parked = Object.entries(gates).filter(([, state]) => isRecordValue(state) && state.status === "needs_human");
1252
+ if (parked.length !== 1 || parked[0][0] !== "implement") {
1253
+ return { ok: false, reason: "not_implement_park" };
1254
+ }
1255
+ const gate = parked[0][1];
1256
+ const generation = isNonNegativeInteger(gate.park_generation) ? gate.park_generation : 0;
1257
+ const record = gate.plan_failure;
1258
+ if (isRecordValue(record)) {
1259
+ if (record.phase !== "parked")
1260
+ return { ok: false, reason: "park_superseded" };
1261
+ if (!isNonNegativeInteger(record.park_generation) || record.park_generation !== generation) {
1262
+ return { ok: false, reason: "park_superseded" };
1263
+ }
1264
+ return { ok: true, parkGeneration: generation };
1265
+ }
1266
+ if (gate.terminal_failure_cause === FINALIZATION_CAUSE) {
1267
+ return { ok: true, parkGeneration: generation };
1268
+ }
1269
+ return { ok: false, reason: "no_plan_failure" };
1270
+ }
1271
+ /** The fingerprint of a pinned operation's identity (the row version excluded). */
1272
+ export function computeRegeneratePlanFingerprint(ref) {
1273
+ return canonicalSha256({
1274
+ v: 1,
1275
+ operation: "regenerate_plan",
1276
+ target: { repo_name: ref.repoName, epic_run_id: ref.epicRunId, ticket_key: ref.ticketKey },
1277
+ route: ref.route,
1278
+ reason: ref.reason,
1279
+ park_generation: ref.parkGeneration,
1280
+ operation_key: ref.operationKey,
1281
+ });
1282
+ }
1283
+ function parseRegeneratePlanReference(raw) {
1284
+ if (!isRecordValue(raw) || raw.version !== 1 || raw.operation !== "regenerate_plan")
1285
+ return null;
1286
+ if (typeof raw.repoName !== "string" || !raw.repoName ||
1287
+ typeof raw.epicRunId !== "string" || !raw.epicRunId ||
1288
+ typeof raw.ticketKey !== "string" || !raw.ticketKey ||
1289
+ (raw.route !== "test" && raw.route !== "implementation") ||
1290
+ typeof raw.reason !== "string" || !raw.reason ||
1291
+ !isNonNegativeInteger(raw.parkGeneration) ||
1292
+ !isNonNegativeInteger(raw.expectedRowVersion) ||
1293
+ typeof raw.operationKey !== "string" ||
1294
+ !REGENERATE_PLAN_OPERATION_KEY_PATTERN.test(raw.operationKey) ||
1295
+ typeof raw.fingerprint !== "string") {
1296
+ return null;
1297
+ }
1298
+ const ref = {
1299
+ version: 1,
1300
+ operation: "regenerate_plan",
1301
+ repoName: raw.repoName,
1302
+ epicRunId: raw.epicRunId,
1303
+ ticketKey: raw.ticketKey,
1304
+ route: raw.route,
1305
+ reason: raw.reason,
1306
+ parkGeneration: raw.parkGeneration,
1307
+ expectedRowVersion: raw.expectedRowVersion,
1308
+ operationKey: raw.operationKey,
1309
+ fingerprint: raw.fingerprint,
1310
+ createdAt: typeof raw.createdAt === "string" ? raw.createdAt : "",
1311
+ };
1312
+ // A reference whose fingerprint no longer matches its own identity was
1313
+ // tampered with or truncated; it never authorizes a replay.
1314
+ return computeRegeneratePlanFingerprint(ref) === ref.fingerprint ? ref : null;
1315
+ }
1316
+ /**
1317
+ * Answer a named plan failure with one forced regeneration, its operation pinned.
1318
+ *
1319
+ * A pinned reference for this ticket is REUSED as-is — same operation key, same
1320
+ * route, same park generation — so a lost response or a restarted process is
1321
+ * answered from the server's durable record, and a later park is never silently
1322
+ * targeted. Only when no reference exists is the park identity read (once) from
1323
+ * authenticated ticket state, and the reference is stored BEFORE the first POST.
1324
+ *
1325
+ * At most {@link REGENERATE_PLAN_POST_LIMIT} POSTs, all with the same key, route
1326
+ * and park generation. A row-version conflict refreshes the row version ONLY while
1327
+ * the park identity still matches; otherwise the result is `stale_subject` and
1328
+ * nothing more is sent. There is no fallback to unpark or any other mutation.
1329
+ */
1330
+ export async function regeneratePlanOnce(access, options, deps = {}) {
1331
+ const fetchState = deps.fetchState ?? fetchEpicRunState;
1332
+ const post = deps.post ?? regeneratePlanTicket;
1333
+ const store = deps.store ?? {};
1334
+ const sleep = deps.sleep ?? ((ms) => new Promise((r) => setTimeout(r, ms)));
1335
+ const callerKey = { epicRunId: options.epicRunId, ticketKey: options.ticketKey };
1336
+ let reference = parseRegeneratePlanReference(await readRecoveryReferenceFile(REGENERATE_PLAN_REFERENCE_NAMESPACE, callerKey, store));
1337
+ if (reference !== null && reference.repoName !== access.repoName)
1338
+ reference = null;
1339
+ const reusedReference = reference !== null;
1340
+ if (reference !== null && reference.route !== options.route) {
1341
+ // An earlier operation is pinned on a different route and may be unconfirmed.
1342
+ // Sending a second route could answer the same park twice, so nothing is sent.
1343
+ return { kind: "pinned_mismatch", pinnedRoute: reference.route };
1344
+ }
1345
+ const persist = async (ref) => {
1346
+ await writeRecoveryReferenceFile(REGENERATE_PLAN_REFERENCE_NAMESPACE, callerKey, ref, store);
1347
+ if (ref.epicRunId !== callerKey.epicRunId || ref.ticketKey !== callerKey.ticketKey) {
1348
+ await writeRecoveryReferenceFile(REGENERATE_PLAN_REFERENCE_NAMESPACE, { epicRunId: ref.epicRunId, ticketKey: ref.ticketKey }, ref, store);
1349
+ }
1350
+ };
1351
+ const clear = async (ref) => {
1352
+ await clearRecoveryReferenceFile(REGENERATE_PLAN_REFERENCE_NAMESPACE, callerKey, store);
1353
+ await clearRecoveryReferenceFile(REGENERATE_PLAN_REFERENCE_NAMESPACE, { epicRunId: ref.epicRunId, ticketKey: ref.ticketKey }, store);
1354
+ };
1355
+ const readTicket = async () => {
1356
+ try {
1357
+ const state = await fetchState(access, options.epicRunId);
1358
+ return state.ticket_statuses.find((t) => t.ticket_key === options.ticketKey) ?? null;
1359
+ }
1360
+ catch {
1361
+ return "unavailable";
1362
+ }
1363
+ };
1364
+ if (reference === null) {
1365
+ const ticket = await readTicket();
1366
+ if (ticket === "unavailable") {
1367
+ return { kind: "unavailable", message: "could not read the ticket's state, so nothing was sent" };
1368
+ }
1369
+ if (ticket === null)
1370
+ return { kind: "not_eligible", reason: "ticket_not_found" };
1371
+ const captured = captureRegeneratePlanSubject(ticket);
1372
+ if (!captured.ok)
1373
+ return { kind: "not_eligible", reason: captured.reason };
1374
+ const identity = {
1375
+ repoName: access.repoName,
1376
+ epicRunId: ticket.epic_run_id,
1377
+ ticketKey: ticket.ticket_key,
1378
+ route: options.route,
1379
+ reason: options.reason.slice(0, REGENERATE_PLAN_REASON_MAX_CHARS),
1380
+ parkGeneration: captured.parkGeneration,
1381
+ operationKey: (deps.newOperationKey ?? randomUUID)(),
1382
+ };
1383
+ reference = {
1384
+ version: 1,
1385
+ operation: "regenerate_plan",
1386
+ ...identity,
1387
+ expectedRowVersion: ticket.row_version,
1388
+ fingerprint: computeRegeneratePlanFingerprint(identity),
1389
+ createdAt: (deps.now ?? (() => new Date()))().toISOString(),
1390
+ };
1391
+ try {
1392
+ await persist(reference);
1393
+ }
1394
+ catch {
1395
+ return {
1396
+ kind: "unavailable",
1397
+ message: "could not store the local recovery reference, so the request was not sent",
1398
+ };
1399
+ }
1400
+ }
1401
+ let ref = reference;
1402
+ let last = null;
1403
+ for (let attempt = 1; attempt <= REGENERATE_PLAN_POST_LIMIT; attempt += 1) {
1404
+ if (attempt > 1)
1405
+ await sleep(REGENERATE_PLAN_RETRY_DELAY_MS * (attempt - 1));
1406
+ const outcome = await post(access, {
1407
+ epicRunId: ref.epicRunId,
1408
+ ticketKey: ref.ticketKey,
1409
+ route: ref.route,
1410
+ reason: ref.reason,
1411
+ expectedRowVersion: ref.expectedRowVersion,
1412
+ parkGeneration: ref.parkGeneration,
1413
+ operationKey: ref.operationKey,
1414
+ });
1415
+ last = outcome;
1416
+ if (outcome.kind === "result") {
1417
+ await clear(ref);
1418
+ return { kind: outcome.result.outcome, result: outcome.result, reusedReference };
1419
+ }
1420
+ if (outcome.kind === "unsupported_server") {
1421
+ // Nothing was written, and no other mutation stands in for this one.
1422
+ await clear(ref);
1423
+ return { kind: "unsupported_server", status: outcome.status };
1424
+ }
1425
+ if (outcome.kind === "uncertain")
1426
+ continue;
1427
+ if (outcome.kind === "refused" && outcome.errorCode === "PLAN_REGEN_BUSY")
1428
+ continue;
1429
+ if (outcome.kind === "refused" && outcome.errorCode === "CONFLICT") {
1430
+ // Refresh the row version ONLY while the park identity is the same one.
1431
+ const ticket = await readTicket();
1432
+ if (ticket === "unavailable" || ticket === null) {
1433
+ return { kind: "refused", errorCode: outcome.errorCode, status: outcome.status, reusedReference };
1434
+ }
1435
+ const current = captureRegeneratePlanSubject(ticket);
1436
+ if (!current.ok || current.parkGeneration !== ref.parkGeneration) {
1437
+ return { kind: "stale_subject", reusedReference };
1438
+ }
1439
+ ref = { ...ref, expectedRowVersion: ticket.row_version };
1440
+ try {
1441
+ await persist(ref);
1442
+ }
1443
+ catch {
1444
+ return {
1445
+ kind: "unavailable",
1446
+ message: "could not update the local recovery reference, so the retry was not sent",
1447
+ };
1448
+ }
1449
+ continue;
1450
+ }
1451
+ // A stale park is the subject changing: back to explain_run, nothing written.
1452
+ if (outcome.kind === "refused" && outcome.errorCode === "PLAN_REGEN_STALE_PARK") {
1453
+ await clear(ref);
1454
+ return { kind: "stale_subject", reusedReference };
1455
+ }
1456
+ // Every other refusal or rejection is authoritative: nothing was written,
1457
+ // and this operation is finished.
1458
+ await clear(ref);
1459
+ return {
1460
+ kind: "refused",
1461
+ errorCode: outcome.kind === "refused" ? outcome.errorCode : outcome.errorCode ?? "REQUEST_REJECTED",
1462
+ status: outcome.status,
1463
+ reusedReference,
1464
+ };
1465
+ }
1466
+ if (last !== null && last.kind === "refused") {
1467
+ // Busy or row-version churn for the whole budget: nothing was written, and
1468
+ // the pinned reference is kept for the next invocation.
1469
+ return { kind: "refused", errorCode: last.errorCode, status: last.status, reusedReference };
1470
+ }
1471
+ const transport = last !== null && last.kind === "uncertain"
1472
+ ? last.status !== undefined ? `${last.reason} (status ${last.status})` : last.reason
1473
+ : "indeterminate";
1474
+ return { kind: "unconfirmed", transport, reusedReference, attempts: REGENERATE_PLAN_POST_LIMIT };
1475
+ }
@@ -1,8 +1,9 @@
1
1
  /**
2
- * The shared contract for the eight operator repair verbs: BAPI-1154's
2
+ * The shared contract for the nine operator repair verbs: BAPI-1154's
3
3
  * `scope-reparse`, `dispatch-remediation`, and `merge-child`, BAPI-1176's
4
4
  * `scope-catch-up`, `patch-policy`, and `resume-run`, BAPI-1326's
5
- * ticket-addressed `resume-ci`, and BAPI-1388's ticket-addressed `rerun-ci`.
5
+ * ticket-addressed `resume-ci`, BAPI-1388's ticket-addressed `rerun-ci`, and
6
+ * BAPI-1494's ticket-addressed `resolve-handoff`.
6
7
  *
7
8
  * CLI-only, exactly like the BAPI-872 recovery verbs: none of these names is ever
8
9
  * registered as an MCP tool (`index-static.test.ts` pins that). This module is the
@@ -23,6 +24,7 @@ export const VERB_PATCH_POLICY = "patch-policy";
23
24
  export const VERB_RESUME_RUN = "resume-run";
24
25
  export const VERB_RESUME_CI = "resume-ci";
25
26
  export const VERB_RERUN_CI = "rerun-ci";
27
+ export const VERB_RESOLVE_HANDOFF = "resolve-handoff";
26
28
  /** Every repair verb, in the order an operator meets them. */
27
29
  export const OPERATOR_REPAIR_VERBS = [
28
30
  VERB_SCOPE_REPARSE,
@@ -33,6 +35,7 @@ export const OPERATOR_REPAIR_VERBS = [
33
35
  VERB_RESUME_RUN,
34
36
  VERB_RESUME_CI,
35
37
  VERB_RERUN_CI,
38
+ VERB_RESOLVE_HANDOFF,
36
39
  ];
37
40
  /**
38
41
  * The ONE cap on driver context, in UTF-8 BYTES — the same number the server
@@ -113,6 +116,14 @@ export const OPERATOR_REPAIR_REFUSAL_CODES = [
113
116
  // BAPI-1333
114
117
  "GUIDED_REPAIR_DISABLED",
115
118
  "REPAIR_SUBJECT_STALE",
119
+ // BAPI-1494
120
+ "HANDOFF_NOT_PENDING",
121
+ "HANDOFF_ALREADY_RESOLVED",
122
+ "RESOLUTION_ACTOR_UNAVAILABLE",
123
+ "EPIC_HEAD_UNREADABLE",
124
+ "HANDOFF_LEDGER_UNREADABLE",
125
+ "HANDOFF_RESOLUTION_CAPACITY",
126
+ "HANDOFF_SELECTION_CHANGED",
116
127
  ];
117
128
  /** True when `code` is one of the closed repair refusal codes. */
118
129
  export function isOperatorRepairRefusalCode(code) {
@@ -207,3 +218,37 @@ export const RERUN_CI_NOT_RUNNABLE_REASONS = [
207
218
  ];
208
219
  /** The closed overall outcomes of an applied `rerun-ci`. */
209
220
  export const RERUN_CI_OUTCOMES = ["enqueued", "partial", "nothing_to_enqueue"];
221
+ // ---------------------------------------------------------------------------
222
+ // BAPI-1494 — `resolve-handoff`
223
+ // ---------------------------------------------------------------------------
224
+ /**
225
+ * The closed `resolve-handoff` refusal subset — mirrors
226
+ * `RESOLVE_HANDOFF_REFUSAL_CODES` in `operator_repair_contract.py`.
227
+ */
228
+ export const RESOLVE_HANDOFF_REFUSAL_CODES = [
229
+ "RESOLUTION_ACTOR_UNAVAILABLE",
230
+ "TICKET_NOT_IN_RUN",
231
+ "EPIC_HEAD_UNREADABLE",
232
+ "HANDOFF_LEDGER_UNREADABLE",
233
+ "HANDOFF_NOT_PENDING",
234
+ "HANDOFF_ALREADY_RESOLVED",
235
+ "HANDOFF_RESOLUTION_CAPACITY",
236
+ "HANDOFF_SELECTION_CHANGED",
237
+ "ROW_VERSION_CONFLICT",
238
+ ];
239
+ /** True when `code` is one of the closed `resolve-handoff` refusal codes. */
240
+ export function isResolveHandoffRefusalCode(code) {
241
+ return (typeof code === "string" &&
242
+ RESOLVE_HANDOFF_REFUSAL_CODES.includes(code));
243
+ }
244
+ /** The two decision kinds. `risk_accepted` is never shown as verified or passed. */
245
+ export const HANDOFF_RESOLUTION_KINDS = ["verified", "risk_accepted"];
246
+ /** The display label for each kind — the same labels the server uses. */
247
+ export const HANDOFF_RESOLUTION_KIND_LABELS = {
248
+ verified: "verified",
249
+ risk_accepted: "risk accepted",
250
+ };
251
+ /** Bounds shared with the server (`HANDOFF_RESOLUTION_*` in `api/models/epic_run.py`). */
252
+ export const HANDOFF_RESOLUTION_MAX_STEPS = 50;
253
+ export const HANDOFF_RESOLUTION_EVIDENCE_REF_MAX_CHARS = 500;
254
+ export const HANDOFF_RESOLUTION_REASON_MAX_CHARS = 2000;
@@ -1,3 +1,4 @@
1
+ import { CONSUMER_GUIDE_POINTER } from "../printed-remedy-commands.js";
1
2
  /** The two fixed workflow files unattended auto-merge reads. Named once here. */
2
3
  export const REVIEW_WORKFLOW_PATH = ".github/workflows/claude-review.yml";
3
4
  export const CI_WORKFLOW_PATH = ".github/workflows/epic-implementer-ci.yml";
@@ -5,8 +6,9 @@ export const CI_WORKFLOW_PATH = ".github/workflows/epic-implementer-ci.yml";
5
6
  export const MIGRATION_GUARD_JOB_ID = "migration-guard";
6
7
  export const MIGRATION_GUARD_CHECKER_PATH = "scripts/check_alembic_migration_graph.py";
7
8
  export const MIGRATION_GUARD_INVOCATION = `python ${MIGRATION_GUARD_CHECKER_PATH}`;
8
- const RETRY = "Run the readiness check again, or pass --attended. " +
9
- "If it keeps failing, contact Bridge operations.";
9
+ const RETRY = "Retry readiness, or use --attended.";
10
+ /** Every workflow remedy ends with the guide a consumer can actually install. */
11
+ const GUIDE_SENTENCE = `See ${CONSUMER_GUIDE_POINTER}.`;
10
12
  const TEMPLATES = {
11
13
  review_workflow_file: `${REVIEW_WORKFLOW_PATH} is missing from the default branch. Add it, or pass --attended.`,
12
14
  review_run_id_marker: `${REVIEW_WORKFLOW_PATH} does not emit the run-id: marker in its verdict comment. ` +
@@ -29,7 +31,7 @@ const TEMPLATES = {
29
31
  "Add that job, or pass --attended.",
30
32
  };
31
33
  /** Shown when the report is missing, incomplete, or not in a shape we can name. */
32
- const UNVERIFIABLE_FALLBACK = "Bridge could not verify the review and CI workflows on the default branch. " + RETRY;
34
+ const UNVERIFIABLE_FALLBACK = `Bridge could not verify the review and CI workflows on the default branch. ${RETRY} ${GUIDE_SENTENCE}`;
33
35
  function classifyReview(w) {
34
36
  if (w === null || w === undefined || typeof w !== "object")
35
37
  return "malformed";
@@ -86,7 +88,7 @@ function classifyCi(c) {
86
88
  * unreadable, and otherwise the empty result below.
87
89
  */
88
90
  export function describeRepositoryWorkflowRemedy(readiness) {
89
- const review = classifyReview(readiness?.review_workflow);
91
+ const review = readiness?.epic_branch_ci?.effective_review_mode === "verdict_protocol" ? classifyReview(readiness?.review_workflow) : [];
90
92
  if (review === "malformed") {
91
93
  return { section: null, missing: [], text: UNVERIFIABLE_FALLBACK };
92
94
  }
@@ -101,7 +103,7 @@ export function describeRepositoryWorkflowRemedy(readiness) {
101
103
  return { section: null, missing: [], text: "" };
102
104
  }
103
105
  function build(section, missing) {
104
- return { section, missing, text: missing.map((token) => TEMPLATES[token]).join(" ") };
106
+ return { section, missing, text: `${missing.map((token) => TEMPLATES[token]).join(" ")} ${GUIDE_SENTENCE}` };
105
107
  }
106
108
  /**
107
109
  * The remedy sentence for a repository whose workflows are not confirmed. Never
@@ -121,5 +123,5 @@ export function ciWorkflowRemedy(c) {
121
123
  const tokens = classifyCi(c);
122
124
  if (tokens === "malformed" || tokens.length === 0)
123
125
  return UNVERIFIABLE_FALLBACK;
124
- return tokens.map((token) => TEMPLATES[token]).join(" ");
126
+ return `${tokens.map((token) => TEMPLATES[token]).join(" ")} ${GUIDE_SENTENCE}`;
125
127
  }
@@ -0,0 +1,76 @@
1
+ /**
2
+ * Store-aware merge-credential resolution at privileged action boundaries
3
+ * (BAPI-1461).
4
+ *
5
+ * `merge-credential.ts` owns the precedence and stays free of filesystem and
6
+ * process dependencies. This module is the thin layer that binds it to one
7
+ * repository's stored entry, so every action boundary — a merge job, the
8
+ * `sync_base` integration action, the merge-child recovery verb, the
9
+ * `drive-epic` launch probe, and doctor — resolves the token the same way:
10
+ *
11
+ * `GITHUB_MERGE_TOKEN` → `BAPI_LOCAL_MERGE_TOKEN` → the stored
12
+ * `github-merge:github.com/<owner>/<repo>` entry.
13
+ *
14
+ * The store is read afresh at each call, never cached, so an executor that
15
+ * started before the token was stored still finds it when a merge runs.
16
+ *
17
+ * ELIGIBILITY is always an explicit input. A durable-host service executor
18
+ * (started with `--scrub-inherited-github-credentials`) passes `false` and so
19
+ * never reads a stored GitHub credential. Machine-user mode never reads it.
20
+ */
21
+ import { execFile } from "node:child_process";
22
+ import { readFile } from "node:fs/promises";
23
+ import os from "node:os";
24
+ import { readGithubMergeCredential, resolveGithubMergeRepositoryIdentity, } from "../credential-store.js";
25
+ import { parseGithubRemote } from "../github-remote.js";
26
+ import { resolveLocalMergeCredentialDetailedAsync, } from "./merge-credential.js";
27
+ /** Real host-local read deps for the user-scoped credential store. */
28
+ export function nodeGithubMergeCredentialReadDeps(env) {
29
+ return { env, homedir: os.homedir, readFile: (p) => readFile(p, "utf-8") };
30
+ }
31
+ /**
32
+ * Resolve one kind for a privileged action. The repository identity is settled
33
+ * BEFORE any store lookup: an unresolved or conflicting identity reads nothing,
34
+ * so a process can never pick up another repository's entry.
35
+ */
36
+ export async function resolveMergeCredentialAtAction(env, kind, context) {
37
+ const allowed = kind === "local" &&
38
+ context.allowStoredEntry === true &&
39
+ (context.storeDeps !== undefined || context.readStored !== undefined);
40
+ const identity = allowed
41
+ ? resolveGithubMergeRepositoryIdentity({
42
+ providerRepository: context.providerRepository,
43
+ localRemote: context.localRemote,
44
+ })
45
+ : null;
46
+ const { storeDeps, readStored } = context;
47
+ const reader = identity === null || !identity.ok
48
+ ? undefined
49
+ : readStored !== undefined
50
+ ? () => readStored(identity.identity)
51
+ : storeDeps !== undefined
52
+ ? () => readGithubMergeCredential(identity.identity, storeDeps)
53
+ : undefined;
54
+ return resolveLocalMergeCredentialDetailedAsync(env, kind, {
55
+ allowStoredEntry: allowed && reader !== undefined,
56
+ ...(reader !== undefined ? { readStoredEntry: reader } : {}),
57
+ });
58
+ }
59
+ /** Bound on the one `git remote get-url origin` read. */
60
+ const GIT_REMOTE_TIMEOUT_MS = 5_000;
61
+ const defaultGitRemoteReader = (cwd) => new Promise((resolve) => {
62
+ execFile("git", ["remote", "get-url", "origin"], { cwd, timeout: GIT_REMOTE_TIMEOUT_MS, env: { ...process.env, GIT_TERMINAL_PROMPT: "0" } }, (error, stdout) => resolve(error ? null : String(stdout)));
63
+ });
64
+ /**
65
+ * The working tree's github.com `origin` as `owner/repo`, or null. Read-only;
66
+ * any failure (no git, no remote, a non-GitHub host) is null, never an error.
67
+ */
68
+ export async function readLocalGithubRemote(cwd, readRemote = defaultGitRemoteReader) {
69
+ try {
70
+ const url = await readRemote(cwd);
71
+ return url === null ? null : parseGithubRemote(url);
72
+ }
73
+ catch {
74
+ return null;
75
+ }
76
+ }