@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,15 +1,27 @@
1
1
  /**
2
2
  * The interactive review of discovered CI settings (BAPI-1520).
3
3
  *
4
- * `install-bridge conductor` can propose two optional settings beside the gate:
4
+ * `install epic-implementer` can propose two optional settings beside the gate:
5
5
  *
6
6
  * - **worker variables** — literal environment values found in CI config; and
7
7
  * - **local reproduction hints** — a structured command for a reported provider
8
8
  * check, so a worker can reproduce a failing check locally.
9
9
  *
10
- * Both are stored now and delivered to workers later (a follow-up ticket). Both
11
- * are high-trust: a value is confirmed by the repository owner, one decision at
12
- * a time, and only in an interactive terminal.
10
+ * BAPI-1551 adds two more, reviewed in the same step:
11
+ *
12
+ * - **dependency refresh** — `{cwd, argv, lockfiles}` entries the executor runs
13
+ * before a worker starts, only when a declared lockfile changed; and
14
+ * - **CI database behavior** — whether the repository's CI runs with a database
15
+ * (`none`, `provided`, or `unknown`).
16
+ *
17
+ * BAPI-1580 adds **must-order paths** — migration directories whose children
18
+ * merge one at a time. Discovery only proposes existing directories; each new
19
+ * one is offered on its own, stored entries are never removed here, and the
20
+ * 32-entry bound is respected (anything left out is named as a warning).
21
+ *
22
+ * All are high-trust: a value is confirmed by the repository owner, one decision
23
+ * at a time, and only in an interactive terminal. An install argv is shown and
24
+ * edited only here, as an argument array, never as a shell string.
13
25
  *
14
26
  * ## Why values stay in this module
15
27
  *
@@ -26,6 +38,7 @@
26
38
  * an empty `workerEnv` list is a deliberate removal of every stored variable.
27
39
  */
28
40
  import { LOCAL_COMMAND_TIMEOUT_SECONDS, } from "./gate-discovery.js";
41
+ import { CI_DATABASE_DEFAULT, MAX_DEPENDENCY_INSTALL_ENTRIES, MAX_DEPENDENCY_INSTALL_LOCKFILES, MAX_MUST_ORDER_PATHS, admitDependencyInstallDeclarations, canonicalMustOrderPaths, dependencyInstallEntryIdentity, isCiDatabase, isSafeRepoRelativePath, sameDependencyInstall, sameMustOrderPaths, } from "../dependency-install-declarations.js";
29
42
  /** Limits that mirror `gate_profile.py` for hand-typed hints. */
30
43
  const MAX_HINT_WORDS = 32;
31
44
  const MAX_HINT_WORD_CHARS = 1024;
@@ -88,6 +101,33 @@ export function workerEnvEqual(a, b) {
88
101
  export function hintEqual(a, b) {
89
102
  return (a.timeout_seconds === b.timeout_seconds && a.argv.length === b.argv.length && a.argv.every((w, i) => w === b.argv[i]));
90
103
  }
104
+ /** BAPI-1551 — whether two dependency-refresh lists are the same (absent is empty; order matters). */
105
+ export function dependencyInstallEqual(a, b) {
106
+ return sameDependencyInstall(a ?? [], b ?? []);
107
+ }
108
+ /** BAPI-1551 — the stored `ci_database`; absent is `unknown`. */
109
+ export function storedCiDatabase(stored) {
110
+ return stored?.ci_database ?? CI_DATABASE_DEFAULT;
111
+ }
112
+ /** BAPI-1598 — order-insensitive canonical text of a declaration, for equality only. */
113
+ function canonicalDeclaration(value) {
114
+ if (Array.isArray(value))
115
+ return `[${value.map(canonicalDeclaration).join(",")}]`;
116
+ if (typeof value === "object" && value !== null) {
117
+ return `{${Object.entries(value)
118
+ .filter(([, v]) => v !== undefined)
119
+ .sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0))
120
+ .map(([k, v]) => `${JSON.stringify(k)}:${canonicalDeclaration(v)}`)
121
+ .join(",")}}`;
122
+ }
123
+ return JSON.stringify(value);
124
+ }
125
+ /** BAPI-1598 — whether two worker-database declarations are the same (a declaration and `undefined` differ). */
126
+ export function workerDatabaseEqual(a, b) {
127
+ if (a === undefined || b === undefined)
128
+ return a === b;
129
+ return canonicalDeclaration(a) === canonicalDeclaration(b);
130
+ }
91
131
  /**
92
132
  * Whether `edit` leaves the stored settings exactly as they are. Omitted
93
133
  * settings and per-check hints resolve against `stored` first, so a request
@@ -96,6 +136,17 @@ export function hintEqual(a, b) {
96
136
  export function settingsMatchStored(edit, stored) {
97
137
  if (edit.workerEnv !== undefined && !workerEnvEqual(edit.workerEnv, stored?.worker_env))
98
138
  return false;
139
+ if (edit.dependencyInstall !== undefined && !dependencyInstallEqual(edit.dependencyInstall, stored?.dependency_install)) {
140
+ return false;
141
+ }
142
+ if (edit.ciDatabase !== undefined && edit.ciDatabase !== storedCiDatabase(stored))
143
+ return false;
144
+ if (edit.workerDatabase !== undefined && !workerDatabaseEqual(edit.workerDatabase, stored?.worker_database)) {
145
+ return false;
146
+ }
147
+ if (edit.mustOrderPaths !== undefined && !sameMustOrderPaths(edit.mustOrderPaths, stored?.must_order_paths ?? [])) {
148
+ return false;
149
+ }
99
150
  for (const [check, hint] of edit.reproduce ?? []) {
100
151
  const current = stored?.reproduction_hints?.get(check) ?? null;
101
152
  if (hint === null) {
@@ -182,7 +233,83 @@ export function hasSettingsToReview(proposal, stored, providerChecks) {
182
233
  return (proposal.workerEnvCandidates.length > 0 ||
183
234
  (stored?.worker_env?.length ?? 0) > 0 ||
184
235
  proposal.workerEnvConflicts.length > 0 ||
185
- hintRows(proposal, stored, providerChecks).some((r) => r.stored !== null || r.proposed !== null));
236
+ hintRows(proposal, stored, providerChecks).some((r) => r.stored !== null || r.proposed !== null) ||
237
+ hasDeclarationsToReview(proposal, stored));
238
+ }
239
+ /**
240
+ * BAPI-1551 — whether the dependency-refresh or CI-database declarations have
241
+ * anything stored or newly proposed.
242
+ */
243
+ export function hasDeclarationsToReview(proposal, stored) {
244
+ return ((stored?.dependency_install?.length ?? 0) > 0 ||
245
+ newDependencyProposals(proposal, stored).length > 0 ||
246
+ storedCiDatabase(stored) !== CI_DATABASE_DEFAULT ||
247
+ proposedCiDatabase(proposal) !== CI_DATABASE_DEFAULT ||
248
+ // BAPI-1598: a lone worker-database proposal must still reach the review, or it
249
+ // would be printed as "proposed" and never selected.
250
+ newWorkerDatabaseProposal(proposal, stored) !== undefined ||
251
+ mustOrderOffer(proposal, stored).offered.length > 0);
252
+ }
253
+ /** Whether the BAPI-1551 dependency-refresh or CI-database groups have anything to show. */
254
+ function hasDependencyOrCiToReview(proposal, stored) {
255
+ return ((stored?.dependency_install?.length ?? 0) > 0 ||
256
+ newDependencyProposals(proposal, stored).length > 0 ||
257
+ (proposal.dependencyInstallNotes?.length ?? 0) > 0 ||
258
+ storedCiDatabase(stored) !== CI_DATABASE_DEFAULT ||
259
+ proposedCiDatabase(proposal) !== CI_DATABASE_DEFAULT);
260
+ }
261
+ /**
262
+ * BAPI-1580 — the must-order discoveries to offer: those not already stored,
263
+ * limited to what still fits in the {@link MAX_MUST_ORDER_PATHS}-entry total.
264
+ */
265
+ export function mustOrderOffer(proposal, stored) {
266
+ const storedList = stored?.must_order_paths ?? [];
267
+ const fresh = canonicalMustOrderPaths(proposal.mustOrderPathCandidates ?? []).filter((p) => !storedList.includes(p));
268
+ const capacity = Math.max(0, MAX_MUST_ORDER_PATHS - storedList.length);
269
+ const offered = fresh.slice(0, capacity);
270
+ return { offered, notOffered: fresh.length - offered.length + (proposal.mustOrderPathOverflow ?? 0) };
271
+ }
272
+ /** BAPI-1580 — the explicit warning when some discoveries cannot be offered, or null. */
273
+ export function mustOrderShortfallWarning(proposal, stored) {
274
+ const { notOffered } = mustOrderOffer(proposal, stored);
275
+ if (notOffered === 0)
276
+ return null;
277
+ return (` ⚠ ${notOffered} discovered must-order path${notOffered === 1 ? " was" : "s were"} not offered: the gate holds ` +
278
+ `at most ${MAX_MUST_ORDER_PATHS} must-order paths, counting the ${(stored?.must_order_paths ?? []).length} ` +
279
+ "already stored. Add the rest manually.");
280
+ }
281
+ /**
282
+ * BAPI-1551 — whether discovery proposes a declaration the stored profile does
283
+ * not already hold. This is the advisory gate change setup offers; it is never a
284
+ * blocking item.
285
+ */
286
+ export function hasUnstoredDeclarationProposal(proposal, stored) {
287
+ const ci = proposedCiDatabase(proposal);
288
+ return (newDependencyProposals(proposal, stored).length > 0 ||
289
+ (ci !== CI_DATABASE_DEFAULT && ci !== storedCiDatabase(stored)) ||
290
+ newWorkerDatabaseProposal(proposal, stored) !== undefined ||
291
+ mustOrderOffer(proposal, stored).offered.length > 0);
292
+ }
293
+ /** Proposed entries whose identity (cwd and lockfiles) is not stored with the same argv. */
294
+ function newDependencyProposals(proposal, stored) {
295
+ const storedList = stored?.dependency_install ?? [];
296
+ return (proposal.dependencyInstallCandidates ?? []).filter((c) => !storedList.some((e) => dependencyInstallEqual([entryOf(c)], [e])));
297
+ }
298
+ function entryOf(candidate) {
299
+ return { cwd: candidate.cwd, argv: [...candidate.argv], lockfiles: [...candidate.lockfiles] };
300
+ }
301
+ /**
302
+ * BAPI-1598 — the proposed worker-database declaration, only when none is stored.
303
+ * An existing confirmed declaration is preserved over discovery output, whatever
304
+ * the repository now looks like.
305
+ */
306
+ function newWorkerDatabaseProposal(proposal, stored) {
307
+ if (stored?.worker_database !== undefined)
308
+ return undefined;
309
+ return proposal.workerDatabaseProposal?.declaration;
310
+ }
311
+ function proposedCiDatabase(proposal) {
312
+ return proposal.ciDatabaseProposal?.value ?? CI_DATABASE_DEFAULT;
186
313
  }
187
314
  /**
188
315
  * Print the review surface. Values appear only when `showValues` is true (an
@@ -252,8 +379,108 @@ export function renderSettingsReview(io, proposal, stored, providerChecks, showV
252
379
  if (proposal.reproductionHintsSkipped.length > 0) {
253
380
  io.log(` Not proposed (no single plain command could be read for): ${safeList(proposal.reproductionHintsSkipped)}`);
254
381
  }
382
+ // Shown only when there is something to say, so a review without either
383
+ // declaration renders exactly as it did before BAPI-1551.
384
+ if (hasDeclarationsToReview(proposal, stored) ||
385
+ (proposal.dependencyInstallNotes?.length ?? 0) > 0 ||
386
+ mustOrderOffer(proposal, stored).notOffered > 0) {
387
+ renderDeclarationsReview(io, proposal, stored, showValues);
388
+ }
389
+ renderWorkerDatabaseReview(io, proposal, stored);
255
390
  io.log("");
256
391
  }
392
+ /**
393
+ * BAPI-1598 — the "Worker database setup" and "Verification when no database
394
+ * checks can run" lines of the existing summary. Plain language only: the mode
395
+ * token, identifiers, and migration argv stay in the admin and details output.
396
+ */
397
+ export function renderWorkerDatabaseReview(io, proposal, stored) {
398
+ const storedDeclaration = stored?.worker_database;
399
+ const state = storedDeclaration !== undefined && storedDeclaration.mode !== "none"
400
+ ? "already confirmed"
401
+ : newWorkerDatabaseProposal(proposal, stored) !== undefined
402
+ ? "proposed"
403
+ : "not configured";
404
+ io.log("");
405
+ io.log(` Worker database setup: ${state}.`);
406
+ if (state === "not configured")
407
+ io.log(" No database will be created for workers.");
408
+ const handoff = stored?.verification_handoff_default ?? "proceed";
409
+ io.log(` Verification when no database checks can run: ${handoff === "block" ? "stop and ask" : "continue and say so"}.`);
410
+ }
411
+ const CI_DATABASE_TEXT = Object.freeze({
412
+ none: "none — CI runs without a database",
413
+ provided: "provided — CI provides a database",
414
+ unknown: "unknown — not declared",
415
+ });
416
+ const DEPENDENCY_NOTE_TEXT = Object.freeze({
417
+ dependency_install_pip_not_proposed: "A pip requirements file was found. It is not proposed: a bare pip install would use whatever " +
418
+ "Python is first on the executor's PATH, not this worktree's environment. Add an entry by hand if you need one.",
419
+ dependency_install_toolchain_unresolved: "The repository's toolchains could not be read with certainty, so nothing is proposed.",
420
+ });
421
+ /** One entry as a person reads it: where it runs and what it watches first, then the command. */
422
+ function describeDependencyEntry(entry, label, showValues) {
423
+ const where = entry.cwd === "." ? "repository root" : terminalSafe(entry.cwd);
424
+ const lines = [`${where}, when ${safeList(entry.lockfiles)} change${entry.lockfiles.length === 1 ? "s" : ""}${label ? ` (${label})` : ""}`];
425
+ lines.push(showValues
426
+ ? ` runs: ${entry.argv.map(terminalSafe).join(" ")}`
427
+ : " (the install command is shown only in a terminal)");
428
+ return lines;
429
+ }
430
+ /** BAPI-1551 (extended by BAPI-1580) — every declaration group with something to show. */
431
+ function renderDeclarationsReview(io, proposal, stored, showValues) {
432
+ // BAPI-1580: a review with only must-order paths to show skips the BAPI-1551
433
+ // groups; any other review renders them exactly as before.
434
+ if (hasDependencyOrCiToReview(proposal, stored))
435
+ renderDependencyAndCiReview(io, proposal, stored, showValues);
436
+ renderMustOrderReview(io, proposal, stored);
437
+ }
438
+ /** BAPI-1580 — the Must-order paths group, shown only when something is new or left out. */
439
+ function renderMustOrderReview(io, proposal, stored) {
440
+ const { offered } = mustOrderOffer(proposal, stored);
441
+ const warning = mustOrderShortfallWarning(proposal, stored);
442
+ if (offered.length === 0 && warning === null)
443
+ return;
444
+ io.log("");
445
+ io.log(" Must-order paths — children that change these paths merge one at a time, in plan order.");
446
+ for (const entry of stored?.must_order_paths ?? [])
447
+ io.log(` ${terminalSafe(entry)} — Stored`);
448
+ offered.forEach((entry, index) => io.log(` [${index + 1}] ${terminalSafe(entry)} — Proposed`));
449
+ if (warning !== null)
450
+ io.log(warning);
451
+ }
452
+ /** BAPI-1551 — the Dependency refresh and CI database behavior groups. */
453
+ function renderDependencyAndCiReview(io, proposal, stored, showValues) {
454
+ io.log("");
455
+ io.log(" Dependency refresh — before a worker starts, reinstall dependencies when a lockfile changed.");
456
+ const storedList = stored?.dependency_install ?? [];
457
+ const proposals = newDependencyProposals(proposal, stored);
458
+ if (storedList.length === 0 && proposals.length === 0)
459
+ io.log(" None stored and none proposed.");
460
+ storedList.forEach((entry) => {
461
+ const [first, ...rest] = describeDependencyEntry(entry, null, showValues);
462
+ io.log(` ${first} — Stored`);
463
+ for (const line of rest)
464
+ io.log(line);
465
+ });
466
+ proposals.forEach((candidate, index) => {
467
+ const [first, ...rest] = describeDependencyEntry(candidate, candidate.label, showValues);
468
+ io.log(` [${index + 1}] ${first} — Proposed`);
469
+ for (const line of rest)
470
+ io.log(line);
471
+ });
472
+ for (const note of proposal.dependencyInstallNotes ?? [])
473
+ io.log(` ${DEPENDENCY_NOTE_TEXT[note] ?? note}`);
474
+ io.log(" Discovery looks at the repository root only, so it can miss a subdirectory project. Stored entries stay " +
475
+ "as they are unless you change them; you can add a subdirectory entry by hand below.");
476
+ io.log("");
477
+ io.log(" CI database behavior — tells workers whether CI runs with a database.");
478
+ io.log(` Stored: ${CI_DATABASE_TEXT[storedCiDatabase(stored)]}`);
479
+ const ci = proposal.ciDatabaseProposal;
480
+ if (ci !== undefined && ci.value !== CI_DATABASE_DEFAULT && ci.value !== storedCiDatabase(stored)) {
481
+ io.log(` Proposed: ${CI_DATABASE_TEXT[ci.value]}${ci.sources.length > 0 ? ` (from ${safeList(ci.sources)})` : ""}`);
482
+ }
483
+ }
257
484
  function hintFrom(candidate) {
258
485
  return { argv: [...candidate.argv], timeout_seconds: candidate.timeoutSeconds };
259
486
  }
@@ -410,6 +637,182 @@ async function reviewHints(io, proposal, stored, providerChecks) {
410
637
  }
411
638
  return edits.size > 0 ? edits : undefined;
412
639
  }
640
+ /** Read hand-typed relative paths (comma separated); `null` when any is unsafe. */
641
+ function parsePathList(line) {
642
+ const items = line.split(",").map((p) => p.trim()).filter((p) => p !== "");
643
+ if (items.length === 0 || items.length > MAX_DEPENDENCY_INSTALL_LOCKFILES)
644
+ return null;
645
+ if (items.some((p) => !isSafeRepoRelativePath(p)) || new Set(items).size !== items.length)
646
+ return null;
647
+ return items;
648
+ }
649
+ /** Ask for one entry by hand: directory, lockfiles, then the command as words. `null` cancels. */
650
+ async function typedDependencyEntry(prompt, io, initial) {
651
+ const cwdAnswer = (await prompt(`Directory to run in, relative to the repository root ("." is the root)${initial ? ` (Enter keeps ${terminalSafe(initial.cwd)})` : ""}: `)).trim();
652
+ const cwd = cwdAnswer === "" && initial ? initial.cwd : cwdAnswer;
653
+ if (!isSafeRepoRelativePath(cwd, { allowRoot: true })) {
654
+ io.log(" A directory must be repository-relative, with no .., backslash, colon, or leading /.");
655
+ return null;
656
+ }
657
+ const lockAnswer = (await prompt(`Lockfiles, relative to the repository root, comma separated${initial ? ` (Enter keeps ${safeList(initial.lockfiles)})` : ""}: `)).trim();
658
+ const lockfiles = lockAnswer === "" && initial ? [...initial.lockfiles] : parsePathList(lockAnswer);
659
+ if (lockfiles === null) {
660
+ io.log(` Give 1 to ${MAX_DEPENDENCY_INSTALL_LOCKFILES} distinct repository-relative file paths.`);
661
+ return null;
662
+ }
663
+ const argvAnswer = await prompt(`Install command words, space separated, no shell syntax${initial ? " (Enter keeps the current command)" : ""}: `);
664
+ const argv = argvAnswer.trim() === "" && initial ? [...initial.argv] : parseHintWords(argvAnswer);
665
+ if (argv === null) {
666
+ io.log(` A command needs 1 to ${MAX_HINT_WORDS} words of at most ${MAX_HINT_WORD_CHARS} characters.`);
667
+ return null;
668
+ }
669
+ const admitted = admitDependencyInstallDeclarations([{ cwd, argv, lockfiles }]);
670
+ if (admitted.entries.length !== 1) {
671
+ io.log(" That entry cannot be stored. Nothing was changed.");
672
+ return null;
673
+ }
674
+ return admitted.entries[0];
675
+ }
676
+ /**
677
+ * BAPI-1551 — ask about dependency refresh. Returns the complete new list, or
678
+ * `undefined` when the owner leaves the stored list untouched. Declining a
679
+ * proposal never clears a stored entry.
680
+ */
681
+ async function reviewDependencyInstall(io, proposal, stored) {
682
+ const prompt = io.promptLine;
683
+ const storedList = (stored?.dependency_install ?? []).map(entryOf);
684
+ const proposals = newDependencyProposals(proposal, stored);
685
+ if (storedList.length === 0 && proposals.length === 0 && (proposal.dependencyInstallNotes?.length ?? 0) === 0) {
686
+ return undefined;
687
+ }
688
+ const letters = [
689
+ ...(storedList.length > 0 ? ["[k]eep stored entries as they are"] : []),
690
+ ...(proposals.length > 0 ? ["[a]pply every proposal", "[i]gnore the proposals (stored entries stay untouched)"] : []),
691
+ "[e]dit — decide each entry one at a time, or add one by hand",
692
+ ...(storedList.length > 0 ? ["[r]emove every stored entry"] : []),
693
+ ];
694
+ let choice = null;
695
+ for (let attempt = 0; attempt < MAX_REVIEW_ATTEMPTS && choice === null; attempt++) {
696
+ const a = (await prompt(`Dependency refresh — ${letters.join(", ")} (Enter leaves it untouched): `)).trim().toLowerCase();
697
+ if (a === "")
698
+ choice = "keep";
699
+ else if ((a === "k" || a === "keep") && storedList.length > 0)
700
+ choice = "keep";
701
+ else if ((a === "a" || a === "apply") && proposals.length > 0)
702
+ choice = "apply";
703
+ else if ((a === "i" || a === "ignore") && proposals.length > 0)
704
+ choice = "ignore";
705
+ else if (a === "e" || a === "edit")
706
+ choice = "edit";
707
+ else if ((a === "r" || a === "remove") && storedList.length > 0)
708
+ choice = "remove";
709
+ else
710
+ io.log(" Choose one of the listed letters, or press Enter.");
711
+ }
712
+ if (choice === "ignore") {
713
+ io.log(` Ignored ${proposals.length} proposal(s). Stored entries are untouched; nothing was removed.`);
714
+ }
715
+ if (choice === null || choice === "keep" || choice === "ignore")
716
+ return undefined;
717
+ if (choice === "remove") {
718
+ io.log(` Removal requested for ${storedList.length} stored dependency refresh entr${storedList.length === 1 ? "y" : "ies"}.`);
719
+ return (await yes(prompt, "Remove every stored dependency refresh entry? [y/N]: ")) ? [] : undefined;
720
+ }
721
+ let result = storedList.map(entryOf);
722
+ const place = (entry) => {
723
+ const identity = dependencyInstallEntryIdentity(entry);
724
+ const at = result.findIndex((e) => dependencyInstallEntryIdentity(e) === identity);
725
+ if (at === -1)
726
+ result.push(entry);
727
+ else
728
+ result[at] = entry;
729
+ };
730
+ if (choice === "apply") {
731
+ for (const candidate of proposals)
732
+ place(entryOf(candidate));
733
+ }
734
+ else {
735
+ for (const candidate of proposals) {
736
+ const where = candidate.cwd === "." ? "the repository root" : terminalSafe(candidate.cwd);
737
+ const a = (await prompt(`Proposed for ${where} (${safeList(candidate.lockfiles)}): ${candidate.argv.map(terminalSafe).join(" ")} — ` +
738
+ "[a]pply, [e]dit, or Enter to ignore: ")).trim().toLowerCase();
739
+ if (a === "a" || a === "apply")
740
+ place(entryOf(candidate));
741
+ else if (a === "e" || a === "edit") {
742
+ const typed = await typedDependencyEntry(prompt, io, entryOf(candidate));
743
+ if (typed !== null)
744
+ place(typed);
745
+ }
746
+ else
747
+ io.log(" Ignored that proposal. Stored entries are untouched.");
748
+ }
749
+ for (const entry of storedList) {
750
+ const where = entry.cwd === "." ? "the repository root" : terminalSafe(entry.cwd);
751
+ const a = (await prompt(`Stored entry for ${where} — [e]dit, [r]emove, or Enter to keep: `)).trim().toLowerCase();
752
+ const identity = dependencyInstallEntryIdentity(entry);
753
+ if (a === "r" || a === "remove") {
754
+ io.log(` Removal requested: the stored entry for ${where}.`);
755
+ result = result.filter((e) => dependencyInstallEntryIdentity(e) !== identity);
756
+ }
757
+ else if (a === "e" || a === "edit") {
758
+ const typed = await typedDependencyEntry(prompt, io, entry);
759
+ if (typed !== null) {
760
+ result = result.filter((e) => dependencyInstallEntryIdentity(e) !== identity);
761
+ place(typed);
762
+ }
763
+ }
764
+ }
765
+ while (result.length < MAX_DEPENDENCY_INSTALL_ENTRIES && (await yes(prompt, "Add a dependency refresh entry by hand? [y/N]: "))) {
766
+ const typed = await typedDependencyEntry(prompt, io);
767
+ if (typed !== null)
768
+ place(typed);
769
+ }
770
+ }
771
+ if (result.length > MAX_DEPENDENCY_INSTALL_ENTRIES) {
772
+ io.log(` At most ${MAX_DEPENDENCY_INSTALL_ENTRIES} entries can be stored. Nothing was changed.`);
773
+ return undefined;
774
+ }
775
+ return dependencyInstallEqual(result, storedList) ? undefined : result;
776
+ }
777
+ /** BAPI-1551 — ask about CI database behavior. `undefined` leaves the stored value untouched. */
778
+ async function reviewCiDatabase(io, proposal, stored) {
779
+ const current = storedCiDatabase(stored);
780
+ const proposed = proposedCiDatabase(proposal);
781
+ const offer = proposed !== CI_DATABASE_DEFAULT && proposed !== current ? proposed : null;
782
+ if (current === CI_DATABASE_DEFAULT && offer === null)
783
+ return undefined;
784
+ const answer = (await io.promptLine(`CI database behavior — ${offer ? `[a]pply proposed (${offer}), ` : ""}or type none, provided, or unknown ` +
785
+ "(unknown clears it) (Enter leaves it untouched): ")).trim().toLowerCase();
786
+ if (answer === "") {
787
+ if (offer)
788
+ io.log(" Ignored the proposal. The stored value is untouched.");
789
+ return undefined;
790
+ }
791
+ const chosen = (answer === "a" || answer === "apply") && offer ? offer : answer;
792
+ if (!isCiDatabase(chosen)) {
793
+ io.log(" Not recognized; the CI database behavior is left untouched.");
794
+ return undefined;
795
+ }
796
+ return chosen === current ? undefined : chosen;
797
+ }
798
+ /**
799
+ * BAPI-1580 — offer each new must-order path on its own. Returns the complete
800
+ * canonical list (stored entries kept, accepted ones added), or `undefined`
801
+ * when the owner accepts none. Enter, or anything but yes, declines.
802
+ */
803
+ async function reviewMustOrderPaths(io, proposal, stored) {
804
+ const { offered } = mustOrderOffer(proposal, stored);
805
+ const accepted = [];
806
+ for (const entry of offered) {
807
+ if (await yes(io.promptLine, `Add must-order path ${terminalSafe(entry)}? [y/N]: `))
808
+ accepted.push(entry);
809
+ else
810
+ io.log(" Not added. Stored must-order paths are untouched.");
811
+ }
812
+ if (accepted.length === 0)
813
+ return undefined;
814
+ return canonicalMustOrderPaths([...(stored?.must_order_paths ?? []), ...accepted]);
815
+ }
413
816
  /**
414
817
  * Show the review surface and collect the owner's decisions. Requires a
415
818
  * terminal. Returns what changed; nothing is stored here.
@@ -423,8 +826,105 @@ export async function reviewDiscoveredSettings(io, proposal, stored, providerChe
423
826
  const reproduce = await reviewHints(io, proposal, stored, providerChecks);
424
827
  if (reproduce !== undefined)
425
828
  edit.reproduce = reproduce;
829
+ Object.assign(edit, await reviewDeclarations(io, proposal, stored));
426
830
  return edit;
427
831
  }
832
+ /**
833
+ * BAPI-1551 — collect only the dependency-refresh and CI-database decisions.
834
+ * Used beside the full review, and by setup when a confirmed gate is kept and
835
+ * discovery proposes a declaration that is not stored yet.
836
+ */
837
+ export async function reviewDeclarations(io, proposal, stored) {
838
+ const edit = {};
839
+ if (!hasDeclarationsToReview(proposal, stored))
840
+ return edit;
841
+ // BAPI-1598: printed in the summary above and covered by the same single
842
+ // confirmation; it adds no question of its own.
843
+ const workerDatabase = newWorkerDatabaseProposal(proposal, stored);
844
+ if (workerDatabase !== undefined)
845
+ edit.workerDatabase = workerDatabase;
846
+ const dependencyInstall = await reviewDependencyInstall(io, proposal, stored);
847
+ if (dependencyInstall !== undefined)
848
+ edit.dependencyInstall = dependencyInstall;
849
+ const ciDatabase = await reviewCiDatabase(io, proposal, stored);
850
+ if (ciDatabase !== undefined)
851
+ edit.ciDatabase = ciDatabase;
852
+ const mustOrderPaths = await reviewMustOrderPaths(io, proposal, stored);
853
+ if (mustOrderPaths !== undefined)
854
+ edit.mustOrderPaths = mustOrderPaths;
855
+ return edit;
856
+ }
857
+ /** BAPI-1551 — print only the declaration groups (setup's advisory offer). */
858
+ export function renderDeclarationsOnly(io, proposal, stored, showValues) {
859
+ renderDeclarationsReview(io, proposal, stored, showValues);
860
+ if (newWorkerDatabaseProposal(proposal, stored) !== undefined)
861
+ renderWorkerDatabaseReview(io, proposal, stored);
862
+ io.log("");
863
+ }
864
+ /**
865
+ * BAPI-1604 — select the settings that need no individual confirmation, without
866
+ * asking: proposed worker variables (never a committed literal, which needs its
867
+ * own typed `yes`), proposed reproduction hints, dependency refresh entries, the
868
+ * CI-database proposal, and new must-order paths. Stored settings are never
869
+ * removed. The skipped receipts name the variable and never its value. Pure: no
870
+ * prompt, no write, and it uses the same committed-literal marker the interactive
871
+ * review uses rather than a second secret-name heuristic.
872
+ */
873
+ export function recommendedSettingsSelection(proposal, stored, providerChecks) {
874
+ const edit = {};
875
+ const skipped = [];
876
+ const storedEnv = stored?.worker_env ?? [];
877
+ let env = storedEnv.map((e) => ({ ...e }));
878
+ for (const row of envRows(proposal, stored)) {
879
+ const entry = row.proposed;
880
+ if (row.status === "Stored" || entry === undefined)
881
+ continue;
882
+ if (entry.committed_literal === true) {
883
+ skipped.push(`Skipped for safety: ${row.name} needs your review. Use --review-ci-settings.`);
884
+ continue;
885
+ }
886
+ env = [...env.filter((e) => e.name !== row.name), { ...entry }];
887
+ }
888
+ env.sort((a, b) => (a.name < b.name ? -1 : a.name > b.name ? 1 : 0));
889
+ if (!workerEnvEqual(env, storedEnv))
890
+ edit.workerEnv = env;
891
+ const reproduce = new Map();
892
+ for (const row of hintRows(proposal, stored, providerChecks)) {
893
+ if (row.proposed === null)
894
+ continue;
895
+ const proposed = hintFrom(row.proposed);
896
+ if (row.stored === null || !hintEqual(row.stored, proposed))
897
+ reproduce.set(row.check, proposed);
898
+ }
899
+ if (reproduce.size > 0)
900
+ edit.reproduce = reproduce;
901
+ const storedDeps = (stored?.dependency_install ?? []).map(entryOf);
902
+ const deps = storedDeps.map(entryOf);
903
+ for (const candidate of newDependencyProposals(proposal, stored)) {
904
+ const entry = entryOf(candidate);
905
+ const identity = dependencyInstallEntryIdentity(entry);
906
+ const at = deps.findIndex((e) => dependencyInstallEntryIdentity(e) === identity);
907
+ if (at === -1)
908
+ deps.push(entry);
909
+ else
910
+ deps[at] = entry;
911
+ }
912
+ if (deps.length <= MAX_DEPENDENCY_INSTALL_ENTRIES && !dependencyInstallEqual(deps, storedDeps)) {
913
+ edit.dependencyInstall = deps;
914
+ }
915
+ const current = storedCiDatabase(stored);
916
+ const proposedDb = proposedCiDatabase(proposal);
917
+ if (proposedDb !== CI_DATABASE_DEFAULT && proposedDb !== current)
918
+ edit.ciDatabase = proposedDb;
919
+ const workerDatabase = newWorkerDatabaseProposal(proposal, stored);
920
+ if (workerDatabase !== undefined)
921
+ edit.workerDatabase = workerDatabase;
922
+ const { offered } = mustOrderOffer(proposal, stored);
923
+ if (offered.length > 0) {
924
+ edit.mustOrderPaths = canonicalMustOrderPaths([...(stored?.must_order_paths ?? []), ...offered]);
925
+ }
926
+ return { edit, skipped };
927
+ }
428
928
  /** Name-only lines describing what an edit changes, for the gate comparison. */
429
929
  export function describeSettingsEdit(edit, stored) {
430
930
  const lines = [];
@@ -447,5 +947,25 @@ export function describeSettingsEdit(edit, stored) {
447
947
  ? ` reproduction hint for ${terminalSafe(check)}: removal requested`
448
948
  : ` reproduction hint for ${terminalSafe(check)}: set (hint only — never changes gating)`);
449
949
  }
950
+ if (edit.dependencyInstall !== undefined) {
951
+ const where = edit.dependencyInstall.map((e) => (e.cwd === "." ? "repository root" : e.cwd));
952
+ lines.push(edit.dependencyInstall.length === 0
953
+ ? " dependency refresh: removal requested for every stored entry"
954
+ : ` dependency refresh: ${edit.dependencyInstall.length} entr${edit.dependencyInstall.length === 1 ? "y" : "ies"} (${safeList(where)})`);
955
+ }
956
+ if (edit.ciDatabase !== undefined) {
957
+ lines.push(edit.ciDatabase === CI_DATABASE_DEFAULT
958
+ ? " CI database behavior: reset to unknown"
959
+ : ` CI database behavior: ${edit.ciDatabase}`);
960
+ }
961
+ if (edit.workerDatabase !== undefined) {
962
+ lines.push(" worker database setup: set (replaces any stored declaration)");
963
+ }
964
+ if (edit.mustOrderPaths !== undefined) {
965
+ const before = stored?.must_order_paths ?? [];
966
+ const added = edit.mustOrderPaths.filter((p) => !before.includes(p));
967
+ lines.push(` must-order paths: ${edit.mustOrderPaths.length} after this change` +
968
+ (added.length > 0 ? ` (added ${safeList(added)})` : ""));
969
+ }
450
970
  return lines;
451
971
  }