@bridge_gpt/mcp-server 0.2.72 → 0.2.74

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 (181) hide show
  1. package/README.md +5 -5
  2. package/build/agent-launchers/claude-executor-adapter.js +15 -0
  3. package/build/agents.generated.js +6 -6
  4. package/build/bridge-config.js +7 -1
  5. package/build/bridge-permissions.js +30 -0
  6. package/build/ci-system-detection.js +50 -0
  7. package/build/ci-trigger-adapters.js +631 -0
  8. package/build/ci-trigger-install.js +106 -0
  9. package/build/codex-launcher-pin.js +33 -2
  10. package/build/codex-skill-adapter.js +3 -1
  11. package/build/command-host.js +33 -0
  12. package/build/command-provisioning.js +4 -3
  13. package/build/commands.generated.js +7 -6
  14. package/build/conductor/bridge-api-client.js +867 -35
  15. package/build/conductor/bring-up-facts.js +18 -5
  16. package/build/conductor/command-drift-production.js +42 -17
  17. package/build/conductor/command-drift.js +48 -1
  18. package/build/conductor/declare-blocked.js +554 -0
  19. package/build/conductor/declared-extras.js +335 -0
  20. package/build/conductor/doctor.js +108 -21
  21. package/build/conductor/driver-commands.js +141 -0
  22. package/build/conductor/driver-guard.js +277 -0
  23. package/build/conductor/driver-lapse.js +321 -0
  24. package/build/conductor/driver-pass-output.js +104 -0
  25. package/build/conductor/driver-pass.js +571 -0
  26. package/build/conductor/driver-register.js +176 -0
  27. package/build/conductor/driver-release.js +174 -0
  28. package/build/conductor/driver-session-state.js +315 -0
  29. package/build/conductor/epic-branch-ci-inspection.js +281 -43
  30. package/build/conductor/epic-implementer-cli.js +199 -15
  31. package/build/conductor/epic-server-database.js +162 -0
  32. package/build/conductor/epic-server-guidance.js +278 -0
  33. package/build/conductor/epic-server-journal.js +239 -0
  34. package/build/conductor/epic-server-processes.js +324 -0
  35. package/build/conductor/epic-server-recipe.js +397 -0
  36. package/build/conductor/epic-server-runtime.js +1207 -0
  37. package/build/conductor/epic-server-sfcc-upload.js +1567 -0
  38. package/build/conductor/epic-server-sfcc.js +85 -0
  39. package/build/conductor/epic-server-state.js +427 -0
  40. package/build/conductor/epic-server.js +647 -0
  41. package/build/conductor/gate-discovery.js +196 -11
  42. package/build/conductor/gate-settings-review.js +261 -4
  43. package/build/conductor/launch-need-probes.js +6 -53
  44. package/build/conductor/launch-plan.js +313 -156
  45. package/build/conductor/prerequisite-inputs.js +879 -45
  46. package/build/conductor/readiness-assessment.js +16 -1
  47. package/build/conductor/readiness-cli.js +20 -9
  48. package/build/conductor/readiness-prerequisites.js +28 -9
  49. package/build/conductor/readiness-sections.js +133 -126
  50. package/build/conductor/readiness.js +1 -1
  51. package/build/conductor/recovery-cli.js +13 -2
  52. package/build/conductor/tools.js +6 -5
  53. package/build/conductor/wait-run-attention.js +2 -2
  54. package/build/conductor/wait-run-cli.js +208 -22
  55. package/build/conductor/worker-database-doctor-inspector.js +33 -2
  56. package/build/conductor/worker-setup-tally.js +27 -0
  57. package/build/credential-delivery.js +280 -0
  58. package/build/credential-launch-safety.js +142 -0
  59. package/build/credential-materialization.js +91 -16
  60. package/build/credential-references-node-deps.js +29 -0
  61. package/build/credential-references.js +1394 -0
  62. package/build/credential-references.test-fixtures.js +211 -0
  63. package/build/credential-scan-conventions.js +145 -0
  64. package/build/credential-scan.js +517 -0
  65. package/build/credential-store.js +121 -1
  66. package/build/credentials-cli.js +252 -3
  67. package/build/dependency-install-declarations.js +102 -1
  68. package/build/docs.generated.js +10 -3
  69. package/build/doctor.js +95 -3
  70. package/build/drive-epic-help.js +21 -2
  71. package/build/drive-epic.js +2095 -375
  72. package/build/engine-paths.js +20 -0
  73. package/build/epic-branch-ci-summary.js +157 -0
  74. package/build/epic-capability-statement.js +175 -0
  75. package/build/epic-ci-workflow-drift.js +77 -23
  76. package/build/epic-ci-workflow-install.js +137 -44
  77. package/build/epic-ci-workflow-v2.js +274 -0
  78. package/build/epic-ci-workflow-v3.js +273 -0
  79. package/build/epic-ci-workflow.js +165 -18
  80. package/build/epic-implementer-bin.js +2204 -56
  81. package/build/epic-launch-context.js +702 -0
  82. package/build/epic-server-record.js +288 -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/completion-contract.js +8 -1
  87. package/build/executor/credential-delivery-step.js +168 -0
  88. package/build/executor/deps.js +3 -1
  89. package/build/executor/env.js +98 -23
  90. package/build/executor/epic-server-context.js +157 -0
  91. package/build/executor/gate-qualification-job.js +127 -26
  92. package/build/executor/guarded-fast-forward-push.js +13 -8
  93. package/build/executor/http-client.js +52 -5
  94. package/build/executor/job-runner.js +577 -81
  95. package/build/executor/observation.js +8 -0
  96. package/build/executor/permissions.js +85 -3
  97. package/build/executor/pre-pr-checks.js +363 -0
  98. package/build/executor/prompt-spec.js +149 -3
  99. package/build/executor/reconcile-overlap-job.js +5 -3
  100. package/build/executor/required-work-diagnostics.js +4 -2
  101. package/build/executor/required-work-ledger.js +936 -38
  102. package/build/executor/results.js +58 -0
  103. package/build/executor/terminal-mutation.js +8 -0
  104. package/build/executor/worker-command.js +72 -3
  105. package/build/executor/worker-database-config.js +281 -0
  106. package/build/executor/worker-database-target.js +16 -12
  107. package/build/executor/worker-database.js +320 -101
  108. package/build/executor/worker-finalization.js +7 -1
  109. package/build/executor/worker-resources.js +25 -3
  110. package/build/executor/worker-verification-guidance.js +18 -3
  111. package/build/executor/worktree.js +20 -1
  112. package/build/executor-launch.js +58 -4
  113. package/build/generated-assets-catalog.js +2 -2
  114. package/build/git-exclude-lock.js +187 -0
  115. package/build/index.js +824 -366
  116. package/build/init.js +26 -11
  117. package/build/install-bridge-conductor-answers.js +528 -0
  118. package/build/install-bridge-conductor-apply.js +288 -0
  119. package/build/install-bridge-conductor-assessment.js +1222 -0
  120. package/build/install-bridge-conductor-compact.js +186 -0
  121. package/build/install-bridge-conductor-contracts.js +72 -0
  122. package/build/install-bridge-conductor-gate.js +1312 -198
  123. package/build/install-bridge-conductor-setup.js +577 -83
  124. package/build/install-bridge-conductor.js +3381 -544
  125. package/build/install-bridge.js +280 -25
  126. package/build/install-doctor.js +38 -8
  127. package/build/install-maintenance.js +26 -3
  128. package/build/install-sfcc-detection.js +120 -0
  129. package/build/install-sfcc-setup.js +185 -0
  130. package/build/launcher-config-inspection.js +162 -1
  131. package/build/mcp-grant-candidates.js +779 -0
  132. package/build/mcp-grant-doctor.js +63 -0
  133. package/build/mcp-grant.js +288 -0
  134. package/build/mcp-host-targets.js +8 -0
  135. package/build/mcp-identity.js +23 -0
  136. package/build/mcp-invoke.js +292 -15
  137. package/build/mcp-presets.js +107 -0
  138. package/build/mcp-provisioning.js +155 -6
  139. package/build/mcp-registration-doctor.js +31 -2
  140. package/build/mcp-server-invocation.js +19 -1
  141. package/build/merge-workflow-install.js +243 -110
  142. package/build/pipelines.generated.js +7 -6
  143. package/build/plan-discovery.js +97 -4
  144. package/build/plan-execution-ledger.js +100 -7
  145. package/build/plan-generation-io.js +262 -0
  146. package/build/plan-generation.js +424 -0
  147. package/build/plane/build-freshness.js +6 -1
  148. package/build/plane/cli.js +75 -9
  149. package/build/plane/plane-freshness.js +17 -0
  150. package/build/plane/preflight.js +50 -10
  151. package/build/plane/shutdown.js +19 -0
  152. package/build/plane/status.js +8 -2
  153. package/build/plane/terminal-run-cleanup.js +18 -4
  154. package/build/printed-remedy-commands.js +211 -12
  155. package/build/project-root.js +40 -0
  156. package/build/readiness-check.js +77 -0
  157. package/build/readiness-prerequisites.generated.js +122 -14
  158. package/build/readme.generated.js +1 -1
  159. package/build/repository-state-paths.js +41 -0
  160. package/build/repository-toolchains.js +6 -3
  161. package/build/run-unit-tests-launcher.js +8 -1
  162. package/build/setup-epic.js +1305 -210
  163. package/build/setup-progress.js +44 -0
  164. package/build/setup-question.js +122 -4
  165. package/build/sfcc/credentials.js +3 -2
  166. package/build/sfcc/hostname.js +98 -2
  167. package/build/sfcc/tool-wrapper.js +6 -95
  168. package/build/start-tickets.js +193 -29
  169. package/build/test-support/executor-source-files.js +200 -0
  170. package/build/testing-config-client.js +25 -2
  171. package/build/third-party-mcp-targets.js +63 -2
  172. package/build/ticket-delivery-enrollment.js +9 -0
  173. package/build/upgrade-cli.js +85 -2
  174. package/build/v2-readiness-requirements.js +28 -1
  175. package/build/version.generated.js +3 -3
  176. package/build/with-credentials.js +208 -0
  177. package/build/worktree-credential-delivery.js +340 -0
  178. package/docs/EPIC-IMPLEMENTER-INSTALL.md +9 -1
  179. package/docs/epic-implementer/getting-started.md +3 -1
  180. package/docs/epic-implementer/self-hosting.md +14 -1
  181. package/package.json +2 -2
@@ -57,6 +57,8 @@ import { describeCheckEvidence } from "../check-evidence.js";
57
57
  import fs from "node:fs/promises";
58
58
  import path from "node:path";
59
59
  import { LEGACY_EPIC_IMPLEMENTER_NODE_PATH_ENV } from "../epic-implementer-env.js";
60
+ import { deriveDeclaredExtras } from "./declared-extras.js";
61
+ import { MAX_MUST_ORDER_PATHS, canonicalMustOrderPaths, isValidMustOrderPath, } from "../dependency-install-declarations.js";
60
62
  import { TOOLCHAIN_CONTENT_FILES, installArgvForJavaScript, installArgvForPython, resolveRepositoryToolchains, } from "../repository-toolchains.js";
61
63
  // ---------------------------------------------------------------------------
62
64
  // Bounds and fixed vocabularies
@@ -163,6 +165,32 @@ const GIT_CLIENT_HOOK_NAMES = [
163
165
  "pre-rebase",
164
166
  "prepare-commit-msg",
165
167
  ];
168
+ /**
169
+ * BAPI-1580 — the fixed migration directories probed for must-order proposals.
170
+ * Each one top-level directory's `migrations/` (a Django app) is probed too.
171
+ * BAPI-1605 adds the Prisma, Flyway, Entity Framework, and Liquibase layouts.
172
+ * Each is one explicit path: no glob and no recursive walk.
173
+ */
174
+ export const MUST_ORDER_FIXED_DIRECTORIES = [
175
+ "alembic/versions/",
176
+ "db/alembic/versions/",
177
+ "migrations/versions/",
178
+ "db/migrate/",
179
+ "prisma/migrations/",
180
+ "db/migration/",
181
+ "src/main/resources/db/migration/",
182
+ "Migrations/",
183
+ "db/changelog/",
184
+ ];
185
+ /**
186
+ * BAPI-1605 — fixed entries whose spelling differs from another layout only by
187
+ * case. A case-insensitive filesystem answers a listing of `Migrations` for a
188
+ * lowercase `migrations` directory, so such an entry is proposed only when the
189
+ * single root listing holds this exact name.
190
+ */
191
+ const MUST_ORDER_ROOT_NAME_CHECKED = ["Migrations/"];
192
+ /** BAPI-1580 — top-level directories never probed for `<dir>/migrations/` (dot-directories are skipped too). */
193
+ export const MUST_ORDER_EXCLUDED_TOP_LEVEL = ["node_modules", "vendor", ".venv"];
166
194
  // ---------------------------------------------------------------------------
167
195
  // Node filesystem seam
168
196
  // ---------------------------------------------------------------------------
@@ -957,6 +985,17 @@ export function deriveProposalKind(providerChecks, localCommandIds) {
957
985
  return "local";
958
986
  return "none";
959
987
  }
988
+ /**
989
+ * BAPI-1603 — the provider check names the repository's CI has actually reported,
990
+ * in the proposal's own order. A name counts only when it is in
991
+ * `proposal.proposed.providerChecks` AND its candidate's outcome is `reported`; an
992
+ * unseen, unavailable, or unknown name is never returned, so unknown history can
993
+ * never be mistaken for a reported check. The proposal is not modified.
994
+ */
995
+ export function reportedProviderChecks(proposal) {
996
+ const reported = new Set(proposal.providerCandidates.filter((c) => c.outcome === "reported").map((c) => c.name));
997
+ return proposal.proposed.providerChecks.filter((name) => reported.has(name));
998
+ }
960
999
  const PROVIDER_OUTCOMES = new Set(["reported", "unseen", "evidence_unavailable"]);
961
1000
  /**
962
1001
  * Classify a lookup response into a history state. A successful answer with no
@@ -1085,8 +1124,114 @@ function toolchainReader(fsSeam) {
1085
1124
  throw Object.assign(new Error("unreadable"), { code: "EIO" });
1086
1125
  };
1087
1126
  }
1127
+ /**
1128
+ * BAPI-1580 — the must-order proposals: the fixed migration directories, plus
1129
+ * `<top-level>/migrations/` for each entry of ONE root listing. `Migrations/`
1130
+ * (BAPI-1605) is proposed only when that listing holds the exact name. No recursive
1131
+ * walk. Dot-directories and {@link MUST_ORDER_EXCLUDED_TOP_LEVEL} are skipped.
1132
+ * A directory counts only when the seam lists it, so a path that is absent, not
1133
+ * a directory, or resolves outside the repository is never proposed. Past the
1134
+ * cap, the first {@link MAX_MUST_ORDER_PATHS} (sorted) are kept and the rest
1135
+ * are counted, never silently dropped.
1136
+ */
1137
+ export async function proposeMustOrderPaths(fsSeam) {
1138
+ // ONE root listing serves both the exact-name check and the `<dir>/migrations/` probes.
1139
+ const rootNames = (await fsSeam.listDir("")) ?? [];
1140
+ const probes = MUST_ORDER_FIXED_DIRECTORIES.filter((dir) => !MUST_ORDER_ROOT_NAME_CHECKED.includes(dir) || rootNames.includes(dir.slice(0, -1)));
1141
+ for (const name of rootNames) {
1142
+ if (name.startsWith(".") || MUST_ORDER_EXCLUDED_TOP_LEVEL.includes(name))
1143
+ continue;
1144
+ probes.push(`${name}/migrations/`);
1145
+ }
1146
+ const found = [];
1147
+ for (const probe of canonicalMustOrderPaths(probes)) {
1148
+ // A name the server would refuse is never probed or proposed.
1149
+ if (!isValidMustOrderPath(probe))
1150
+ continue;
1151
+ if ((await fsSeam.listDir(probe.slice(0, -1))) !== null)
1152
+ found.push(probe);
1153
+ }
1154
+ return { candidates: found.slice(0, MAX_MUST_ORDER_PATHS), overflow: Math.max(0, found.length - MAX_MUST_ORDER_PATHS) };
1155
+ }
1156
+ const COMPOSE_FILES = ["docker-compose.yml", "docker-compose.yaml", "compose.yml", "compose.yaml"];
1157
+ const WORKER_DATABASE_IDENTIFIER = /^[A-Za-z_][A-Za-z0-9_]{0,62}$/;
1158
+ const WORKER_DATABASE_RESERVED_PREFIXES = ["ANTHROPIC_", "BAPI_", "BRIDGE_", "CLAUDE_", "DYLD_", "GIT_CONFIG_"];
1159
+ const WORKER_DATABASE_SECRET_FRAGMENTS = ["TOKEN", "SECRET", "PASSWORD", "API_KEY"];
1160
+ const WORKER_DATABASE_MAX_ALIASES = 4;
1161
+ /** The default migration command timeout (seconds) proposed with an Alembic command. */
1162
+ const WORKER_DATABASE_PROPOSED_TIMEOUT_SECONDS = 120;
1163
+ function isProposableDatabaseUrlName(name) {
1164
+ if (!/^[A-Z][A-Z0-9_]{0,63}$/.test(name))
1165
+ return false;
1166
+ if (name !== "DATABASE_URL" && !name.endsWith("_URL"))
1167
+ return false;
1168
+ if (WORKER_DATABASE_RESERVED_PREFIXES.some((prefix) => name.startsWith(prefix)))
1169
+ return false;
1170
+ return !WORKER_DATABASE_SECRET_FRAGMENTS.some((fragment) => name.includes(fragment));
1171
+ }
1172
+ /**
1173
+ * BAPI-1598 — propose a worker-database declaration from local repository
1174
+ * evidence. Alembic evidence is `alembic.ini`; the database evidence is ONE
1175
+ * Compose Postgres service with a literal database name and a literal, non-
1176
+ * superuser-looking role. A Prisma schema alone proposes nothing.
1177
+ *
1178
+ * Reads names only. No password, connection string, or other Compose value is
1179
+ * kept, and a Compose file holding a connection string with user information
1180
+ * proposes nothing at all. Any missing part (role, protected database, URL alias,
1181
+ * migration command, timeout) proposes nothing: a partial declaration is never
1182
+ * built.
1183
+ */
1184
+ export async function proposeWorkerDatabase(fsSeam) {
1185
+ if (!(await fsSeam.exists("alembic.ini")))
1186
+ return undefined;
1187
+ for (const file of COMPOSE_FILES) {
1188
+ const text = await readBounded(fsSeam, file);
1189
+ if (text === null)
1190
+ continue;
1191
+ // A connection string with user information is a credential; do not guess around it.
1192
+ if (/[a-z][a-z0-9+.-]*:\/\/[^\s/?#'"]*@/i.test(text))
1193
+ return undefined;
1194
+ if (!/^\s*image:\s*['"]?(?:[\w.-]+\/)*postgres(?::[\w.-]+)?['"]?\s*(?:#.*)?$/m.test(text))
1195
+ continue;
1196
+ const literal = (key) => {
1197
+ const match = new RegExp(`^\\s*(?:-\\s*)?${key}\\s*[:=]\\s*['"]?([^\\s'"#$]+)['"]?\\s*(?:#.*)?$`, "m").exec(text);
1198
+ return match && WORKER_DATABASE_IDENTIFIER.test(match[1]) ? match[1] : null;
1199
+ };
1200
+ const database = literal("POSTGRES_DB");
1201
+ const role = literal("POSTGRES_USER");
1202
+ if (database === null || role === null || role === "postgres")
1203
+ return undefined;
1204
+ const aliases = [];
1205
+ for (const match of text.matchAll(/^\s*(?:-\s*)?([A-Z][A-Z0-9_]*_URL|DATABASE_URL)\s*[:=]/gm)) {
1206
+ if (isProposableDatabaseUrlName(match[1]) && !aliases.includes(match[1]))
1207
+ aliases.push(match[1]);
1208
+ }
1209
+ if (aliases.length === 0)
1210
+ return undefined;
1211
+ return {
1212
+ declaration: {
1213
+ mode: "disposable_postgres",
1214
+ worker_role: role,
1215
+ protected_databases: [database],
1216
+ env_names: aliases.slice(0, WORKER_DATABASE_MAX_ALIASES),
1217
+ migrate_command: {
1218
+ argv: [".venv/bin/alembic", "-c", "alembic.ini", "upgrade", "head"],
1219
+ timeout_seconds: WORKER_DATABASE_PROPOSED_TIMEOUT_SECONDS,
1220
+ head_check: "alembic",
1221
+ },
1222
+ },
1223
+ sources: ["alembic.ini", file],
1224
+ };
1225
+ }
1226
+ return undefined;
1227
+ }
1088
1228
  /** BAPI-1551 — the root dependency-refresh proposals and the notes on what was left out. */
1089
- export async function proposeDependencyInstall(fsSeam) {
1229
+ export async function proposeDependencyInstall(fsSeam,
1230
+ /**
1231
+ * BAPI-1677 — the learned-text snapshot extras are worked out from. Absent means no
1232
+ * derivation was asked for. `null` means the text could not be read: a limitation.
1233
+ */
1234
+ options = {}) {
1090
1235
  let resolution;
1091
1236
  try {
1092
1237
  resolution = await resolveRepositoryToolchains(toolchainReader(fsSeam));
@@ -1109,13 +1254,33 @@ export async function proposeDependencyInstall(fsSeam) {
1109
1254
  });
1110
1255
  }
1111
1256
  const py = resolution.toolchains.python;
1257
+ let limitations = [];
1258
+ let unknown = false;
1112
1259
  if (py !== null) {
1113
1260
  if (py.manager === "pip")
1114
1261
  notes.push("dependency_install_pip_not_proposed");
1115
- else
1116
- candidates.push({ cwd: ".", argv: installArgvForPython(py), lockfiles: [py.dependencyFile], label: py.manager });
1262
+ else {
1263
+ // The install target is resolved first: its own file, never a union across projects.
1264
+ const derived = options.learned === undefined
1265
+ ? null
1266
+ : await deriveDeclaredExtras({ manager: py.manager, cwd: ".", baseArgvLength: installArgvForPython(py).length }, options.learned, (relPath) => readBounded(fsSeam, relPath));
1267
+ limitations = derived?.notes ?? [];
1268
+ unknown = derived !== null && !derived.complete;
1269
+ candidates.push({
1270
+ cwd: ".",
1271
+ argv: installArgvForPython(py, derived?.extras ?? []),
1272
+ lockfiles: [py.dependencyFile],
1273
+ label: py.manager,
1274
+ ...(derived !== null && derived.evidence.length > 0 ? { extraEvidence: derived.evidence } : {}),
1275
+ });
1276
+ }
1117
1277
  }
1118
- return { candidates, notes };
1278
+ return {
1279
+ candidates,
1280
+ notes,
1281
+ ...(limitations.length > 0 ? { limitations } : {}),
1282
+ ...(unknown ? { unknown: true } : {}),
1283
+ };
1119
1284
  }
1120
1285
  async function collectWorkflows(fsSeam, evidence, lookups, extras) {
1121
1286
  const entries = await fsSeam.listDir(WORKFLOWS_DIR);
@@ -1426,7 +1591,8 @@ export async function discoverGate(input) {
1426
1591
  const localCommandIds = providerChecks.length > 0 ? [] : validLocal.filter((c) => c.confidence === "high").map((c) => c.id);
1427
1592
  const workerEnv = resolveWorkerEnv(extras.envObservations);
1428
1593
  const hints = await proposeReproductionHints(fsSeam, providerChecks, extras.hintJobs);
1429
- const dependencyInstall = await proposeDependencyInstall(fsSeam);
1594
+ const dependencyInstall = await proposeDependencyInstall(fsSeam, input.learned !== undefined ? { learned: input.learned } : {});
1595
+ const mustOrder = await proposeMustOrderPaths(fsSeam);
1430
1596
  return {
1431
1597
  providerCandidates,
1432
1598
  unreportedProviderNames,
@@ -1441,31 +1607,38 @@ export async function discoverGate(input) {
1441
1607
  workerEnvOverflow: workerEnv.overflow,
1442
1608
  reproductionHints: hints.proposed,
1443
1609
  reproductionHintsSkipped: hints.skipped,
1444
- ...declarationFields(dependencyInstall, proposeCiDatabase(providerChecks, extras.workflowFiles)),
1610
+ ...declarationFields(dependencyInstall, proposeCiDatabase(providerChecks, extras.workflowFiles), mustOrder, await proposeWorkerDatabase(fsSeam)),
1445
1611
  };
1446
1612
  }
1447
1613
  /**
1448
1614
  * BAPI-1551 — only the declaration proposals, for a repository whose gate is
1449
- * already confirmed: the root dependency refreshes, and the CI-database value
1450
- * read from the workflow files that report one of the CONFIRMED provider checks.
1615
+ * already confirmed: the root dependency refreshes, the CI-database value
1616
+ * read from the workflow files that report one of the CONFIRMED provider checks,
1617
+ * and (BAPI-1580) the existing migration directories as must-order paths.
1451
1618
  * Makes no provider-history call.
1452
1619
  */
1453
1620
  export async function discoverDeclarations(input) {
1454
1621
  const extras = { envObservations: [], hintJobs: new Map(), workflowFiles: [] };
1455
1622
  await collectWorkflows(input.fs, [], new LookupNames(), extras);
1456
- const dependencyInstall = await proposeDependencyInstall(input.fs);
1457
- return declarationFields(dependencyInstall, proposeCiDatabase(input.providerChecks, extras.workflowFiles));
1623
+ const dependencyInstall = await proposeDependencyInstall(input.fs, input.learned !== undefined ? { learned: input.learned } : {});
1624
+ const mustOrder = await proposeMustOrderPaths(input.fs);
1625
+ return declarationFields(dependencyInstall, proposeCiDatabase(input.providerChecks, extras.workflowFiles), mustOrder, await proposeWorkerDatabase(input.fs));
1458
1626
  }
1459
1627
  /**
1460
1628
  * BAPI-1551 — the declaration fields of a proposal. Each is present only when it
1461
1629
  * says something (a candidate, a note, or a value other than `unknown`), so a
1462
1630
  * repository with nothing to propose yields exactly the pre-BAPI-1551 proposal.
1463
1631
  */
1464
- function declarationFields(dependencyInstall, ciDatabase) {
1632
+ function declarationFields(dependencyInstall, ciDatabase, mustOrder, workerDatabase) {
1465
1633
  return {
1634
+ ...(workerDatabase !== undefined ? { workerDatabaseProposal: workerDatabase } : {}),
1466
1635
  ...(dependencyInstall.candidates.length > 0 ? { dependencyInstallCandidates: dependencyInstall.candidates } : {}),
1467
1636
  ...(dependencyInstall.notes.length > 0 ? { dependencyInstallNotes: dependencyInstall.notes } : {}),
1637
+ ...(dependencyInstall.limitations !== undefined ? { dependencyInstallLimitations: dependencyInstall.limitations } : {}),
1638
+ ...(dependencyInstall.unknown === true ? { dependencyInstallUnknown: true } : {}),
1468
1639
  ...(ciDatabase.value !== "unknown" ? { ciDatabaseProposal: ciDatabase } : {}),
1640
+ ...(mustOrder.candidates.length > 0 ? { mustOrderPathCandidates: mustOrder.candidates } : {}),
1641
+ ...(mustOrder.overflow > 0 ? { mustOrderPathOverflow: mustOrder.overflow } : {}),
1469
1642
  };
1470
1643
  }
1471
1644
  /**
@@ -1528,3 +1701,15 @@ async function proposeReproductionHints(fsSeam, reportedChecks, hintJobs) {
1528
1701
  }
1529
1702
  return { proposed, skipped };
1530
1703
  }
1704
+ /**
1705
+ * BAPI-1677 — the test commands the repository's own files name, without any provider
1706
+ * lookup. The same collectors, in the same order, as {@link discoverGate}.
1707
+ */
1708
+ export async function discoverLocalTestCandidates(fsSeam) {
1709
+ const evidence = [];
1710
+ const localCandidates = [];
1711
+ await collectPackageJson(fsSeam, evidence, localCandidates);
1712
+ await collectMakefile(fsSeam, evidence, localCandidates);
1713
+ await collectPython(fsSeam, evidence, localCandidates);
1714
+ return localCandidates.filter((c) => isGateCommandName(c.name));
1715
+ }
@@ -14,6 +14,11 @@
14
14
  * - **CI database behavior** — whether the repository's CI runs with a database
15
15
  * (`none`, `provided`, or `unknown`).
16
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
+ *
17
22
  * All are high-trust: a value is confirmed by the repository owner, one decision
18
23
  * at a time, and only in an interactive terminal. An install argv is shown and
19
24
  * edited only here, as an argument array, never as a shell string.
@@ -32,8 +37,9 @@
32
37
  * untouched setting is omitted from the write, so the server keeps what it has;
33
38
  * an empty `workerEnv` list is a deliberate removal of every stored variable.
34
39
  */
40
+ import { redactSecretString } from "./redaction.js";
35
41
  import { LOCAL_COMMAND_TIMEOUT_SECONDS, } from "./gate-discovery.js";
36
- import { CI_DATABASE_DEFAULT, MAX_DEPENDENCY_INSTALL_ENTRIES, MAX_DEPENDENCY_INSTALL_LOCKFILES, admitDependencyInstallDeclarations, dependencyInstallEntryIdentity, isCiDatabase, isSafeRepoRelativePath, sameDependencyInstall, } from "../dependency-install-declarations.js";
42
+ 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";
37
43
  /** Limits that mirror `gate_profile.py` for hand-typed hints. */
38
44
  const MAX_HINT_WORDS = 32;
39
45
  const MAX_HINT_WORD_CHARS = 1024;
@@ -48,6 +54,14 @@ const MAX_REVIEW_ATTEMPTS = 3;
48
54
  * formatting characters are written as `\u{hex}`. Nothing is truncated; callers
49
55
  * pass values already bounded by the validated input limits.
50
56
  */
57
+ /**
58
+ * BAPI-1677 — text a person reads as it is, unquoted: credential shapes redacted and
59
+ * every control or bidirectional character removed. For values already known not to
60
+ * need the visible quoting of {@link terminalSafe}.
61
+ */
62
+ export function plainDisplayText(text) {
63
+ return redactSecretString(text).replace(/[\u0000-\u001f\u007f-\u009f\u200b-\u200f\u2028-\u202e\u2066-\u2069\ufeff]/g, "");
64
+ }
51
65
  export function terminalSafe(text) {
52
66
  let out = "";
53
67
  for (const ch of text) {
@@ -104,6 +118,25 @@ export function dependencyInstallEqual(a, b) {
104
118
  export function storedCiDatabase(stored) {
105
119
  return stored?.ci_database ?? CI_DATABASE_DEFAULT;
106
120
  }
121
+ /** BAPI-1598 — order-insensitive canonical text of a declaration, for equality only. */
122
+ function canonicalDeclaration(value) {
123
+ if (Array.isArray(value))
124
+ return `[${value.map(canonicalDeclaration).join(",")}]`;
125
+ if (typeof value === "object" && value !== null) {
126
+ return `{${Object.entries(value)
127
+ .filter(([, v]) => v !== undefined)
128
+ .sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0))
129
+ .map(([k, v]) => `${JSON.stringify(k)}:${canonicalDeclaration(v)}`)
130
+ .join(",")}}`;
131
+ }
132
+ return JSON.stringify(value);
133
+ }
134
+ /** BAPI-1598 — whether two worker-database declarations are the same (a declaration and `undefined` differ). */
135
+ export function workerDatabaseEqual(a, b) {
136
+ if (a === undefined || b === undefined)
137
+ return a === b;
138
+ return canonicalDeclaration(a) === canonicalDeclaration(b);
139
+ }
107
140
  /**
108
141
  * Whether `edit` leaves the stored settings exactly as they are. Omitted
109
142
  * settings and per-check hints resolve against `stored` first, so a request
@@ -117,6 +150,12 @@ export function settingsMatchStored(edit, stored) {
117
150
  }
118
151
  if (edit.ciDatabase !== undefined && edit.ciDatabase !== storedCiDatabase(stored))
119
152
  return false;
153
+ if (edit.workerDatabase !== undefined && !workerDatabaseEqual(edit.workerDatabase, stored?.worker_database)) {
154
+ return false;
155
+ }
156
+ if (edit.mustOrderPaths !== undefined && !sameMustOrderPaths(edit.mustOrderPaths, stored?.must_order_paths ?? [])) {
157
+ return false;
158
+ }
120
159
  for (const [check, hint] of edit.reproduce ?? []) {
121
160
  const current = stored?.reproduction_hints?.get(check) ?? null;
122
161
  if (hint === null) {
@@ -214,8 +253,40 @@ export function hasDeclarationsToReview(proposal, stored) {
214
253
  return ((stored?.dependency_install?.length ?? 0) > 0 ||
215
254
  newDependencyProposals(proposal, stored).length > 0 ||
216
255
  storedCiDatabase(stored) !== CI_DATABASE_DEFAULT ||
256
+ proposedCiDatabase(proposal) !== CI_DATABASE_DEFAULT ||
257
+ // BAPI-1598: a lone worker-database proposal must still reach the review, or it
258
+ // would be printed as "proposed" and never selected.
259
+ newWorkerDatabaseProposal(proposal, stored) !== undefined ||
260
+ mustOrderOffer(proposal, stored).offered.length > 0);
261
+ }
262
+ /** Whether the BAPI-1551 dependency-refresh or CI-database groups have anything to show. */
263
+ function hasDependencyOrCiToReview(proposal, stored) {
264
+ return ((stored?.dependency_install?.length ?? 0) > 0 ||
265
+ newDependencyProposals(proposal, stored).length > 0 ||
266
+ (proposal.dependencyInstallNotes?.length ?? 0) > 0 ||
267
+ storedCiDatabase(stored) !== CI_DATABASE_DEFAULT ||
217
268
  proposedCiDatabase(proposal) !== CI_DATABASE_DEFAULT);
218
269
  }
270
+ /**
271
+ * BAPI-1580 — the must-order discoveries to offer: those not already stored,
272
+ * limited to what still fits in the {@link MAX_MUST_ORDER_PATHS}-entry total.
273
+ */
274
+ export function mustOrderOffer(proposal, stored) {
275
+ const storedList = stored?.must_order_paths ?? [];
276
+ const fresh = canonicalMustOrderPaths(proposal.mustOrderPathCandidates ?? []).filter((p) => !storedList.includes(p));
277
+ const capacity = Math.max(0, MAX_MUST_ORDER_PATHS - storedList.length);
278
+ const offered = fresh.slice(0, capacity);
279
+ return { offered, notOffered: fresh.length - offered.length + (proposal.mustOrderPathOverflow ?? 0) };
280
+ }
281
+ /** BAPI-1580 — the explicit warning when some discoveries cannot be offered, or null. */
282
+ export function mustOrderShortfallWarning(proposal, stored) {
283
+ const { notOffered } = mustOrderOffer(proposal, stored);
284
+ if (notOffered === 0)
285
+ return null;
286
+ return (` ⚠ ${notOffered} discovered must-order path${notOffered === 1 ? " was" : "s were"} not offered: the gate holds ` +
287
+ `at most ${MAX_MUST_ORDER_PATHS} must-order paths, counting the ${(stored?.must_order_paths ?? []).length} ` +
288
+ "already stored. Add the rest manually.");
289
+ }
219
290
  /**
220
291
  * BAPI-1551 — whether discovery proposes a declaration the stored profile does
221
292
  * not already hold. This is the advisory gate change setup offers; it is never a
@@ -223,16 +294,59 @@ export function hasDeclarationsToReview(proposal, stored) {
223
294
  */
224
295
  export function hasUnstoredDeclarationProposal(proposal, stored) {
225
296
  const ci = proposedCiDatabase(proposal);
226
- return newDependencyProposals(proposal, stored).length > 0 || (ci !== CI_DATABASE_DEFAULT && ci !== storedCiDatabase(stored));
297
+ return (newDependencyProposals(proposal, stored).length > 0 ||
298
+ (ci !== CI_DATABASE_DEFAULT && ci !== storedCiDatabase(stored)) ||
299
+ newWorkerDatabaseProposal(proposal, stored) !== undefined ||
300
+ mustOrderOffer(proposal, stored).offered.length > 0);
227
301
  }
228
302
  /** Proposed entries whose identity (cwd and lockfiles) is not stored with the same argv. */
229
303
  function newDependencyProposals(proposal, stored) {
230
304
  const storedList = stored?.dependency_install ?? [];
231
305
  return (proposal.dependencyInstallCandidates ?? []).filter((c) => !storedList.some((e) => dependencyInstallEqual([entryOf(c)], [e])));
232
306
  }
307
+ /**
308
+ * BAPI-1677 — the one rule for a proposal against a stored list. A proposed entry
309
+ * with a stored identity replaces it in place, a new identity is added at the end,
310
+ * and a stored entry the proposal does not name stays. Nothing is sorted.
311
+ *
312
+ * `additive` means every stored entry survives in its place, with the same trigger
313
+ * files and with its command only extended. Anything else is `replacing`.
314
+ */
315
+ export function mergeDependencyProposal(stored, proposed) {
316
+ const merged = stored.map(entryOf);
317
+ for (const candidate of proposed) {
318
+ const entry = entryOf(candidate);
319
+ const identity = dependencyInstallEntryIdentity(entry);
320
+ const at = merged.findIndex((e) => dependencyInstallEntryIdentity(e) === identity);
321
+ if (at === -1)
322
+ merged.push(entry);
323
+ else
324
+ merged[at] = entry;
325
+ }
326
+ const withinBounds = merged.length <= MAX_DEPENDENCY_INSTALL_ENTRIES;
327
+ if (dependencyInstallEqual(merged, [...stored]))
328
+ return { merged, drift: "same", withinBounds };
329
+ const additive = stored.every((before, index) => {
330
+ const after = merged[index];
331
+ return (JSON.stringify(after.lockfiles) === JSON.stringify(before.lockfiles) &&
332
+ after.cwd === before.cwd &&
333
+ before.argv.every((arg, at) => after.argv[at] === arg));
334
+ });
335
+ return { merged, drift: additive ? "additive" : "replacing", withinBounds };
336
+ }
233
337
  function entryOf(candidate) {
234
338
  return { cwd: candidate.cwd, argv: [...candidate.argv], lockfiles: [...candidate.lockfiles] };
235
339
  }
340
+ /**
341
+ * BAPI-1598 — the proposed worker-database declaration, only when none is stored.
342
+ * An existing confirmed declaration is preserved over discovery output, whatever
343
+ * the repository now looks like.
344
+ */
345
+ function newWorkerDatabaseProposal(proposal, stored) {
346
+ if (stored?.worker_database !== undefined)
347
+ return undefined;
348
+ return proposal.workerDatabaseProposal?.declaration;
349
+ }
236
350
  function proposedCiDatabase(proposal) {
237
351
  return proposal.ciDatabaseProposal?.value ?? CI_DATABASE_DEFAULT;
238
352
  }
@@ -306,10 +420,32 @@ export function renderSettingsReview(io, proposal, stored, providerChecks, showV
306
420
  }
307
421
  // Shown only when there is something to say, so a review without either
308
422
  // declaration renders exactly as it did before BAPI-1551.
309
- if (hasDeclarationsToReview(proposal, stored) || (proposal.dependencyInstallNotes?.length ?? 0) > 0) {
423
+ if (hasDeclarationsToReview(proposal, stored) ||
424
+ (proposal.dependencyInstallNotes?.length ?? 0) > 0 ||
425
+ mustOrderOffer(proposal, stored).notOffered > 0) {
310
426
  renderDeclarationsReview(io, proposal, stored, showValues);
311
427
  }
428
+ renderWorkerDatabaseReview(io, proposal, stored);
429
+ io.log("");
430
+ }
431
+ /**
432
+ * BAPI-1598 — the "Worker database setup" and "Verification when no database
433
+ * checks can run" lines of the existing summary. Plain language only: the mode
434
+ * token, identifiers, and migration argv stay in the admin and details output.
435
+ */
436
+ export function renderWorkerDatabaseReview(io, proposal, stored) {
437
+ const storedDeclaration = stored?.worker_database;
438
+ const state = storedDeclaration !== undefined && storedDeclaration.mode !== "none"
439
+ ? "already confirmed"
440
+ : newWorkerDatabaseProposal(proposal, stored) !== undefined
441
+ ? "proposed"
442
+ : "not configured";
312
443
  io.log("");
444
+ io.log(` Worker database setup: ${state}.`);
445
+ if (state === "not configured")
446
+ io.log(" No database will be created for workers.");
447
+ const handoff = stored?.verification_handoff_default ?? "proceed";
448
+ io.log(` Verification when no database checks can run: ${handoff === "block" ? "stop and ask" : "continue and say so"}.`);
313
449
  }
314
450
  const CI_DATABASE_TEXT = Object.freeze({
315
451
  none: "none — CI runs without a database",
@@ -328,10 +464,36 @@ function describeDependencyEntry(entry, label, showValues) {
328
464
  lines.push(showValues
329
465
  ? ` runs: ${entry.argv.map(terminalSafe).join(" ")}`
330
466
  : " (the install command is shown only in a terminal)");
467
+ // BAPI-1677: why each extra is there, as the smallest matched text and its field.
468
+ for (const evidence of entry.extraEvidence ?? []) {
469
+ lines.push(` because ${evidence.field} says: ${plainDisplayText(evidence.span)}`);
470
+ }
331
471
  return lines;
332
472
  }
333
- /** BAPI-1551 — the Dependency refresh and CI database behavior groups. */
473
+ /** BAPI-1551 (extended by BAPI-1580) — every declaration group with something to show. */
334
474
  function renderDeclarationsReview(io, proposal, stored, showValues) {
475
+ // BAPI-1580: a review with only must-order paths to show skips the BAPI-1551
476
+ // groups; any other review renders them exactly as before.
477
+ if (hasDependencyOrCiToReview(proposal, stored))
478
+ renderDependencyAndCiReview(io, proposal, stored, showValues);
479
+ renderMustOrderReview(io, proposal, stored);
480
+ }
481
+ /** BAPI-1580 — the Must-order paths group, shown only when something is new or left out. */
482
+ function renderMustOrderReview(io, proposal, stored) {
483
+ const { offered } = mustOrderOffer(proposal, stored);
484
+ const warning = mustOrderShortfallWarning(proposal, stored);
485
+ if (offered.length === 0 && warning === null)
486
+ return;
487
+ io.log("");
488
+ io.log(" Must-order paths — children that change these paths merge one at a time, in plan order.");
489
+ for (const entry of stored?.must_order_paths ?? [])
490
+ io.log(` ${terminalSafe(entry)} — Stored`);
491
+ offered.forEach((entry, index) => io.log(` [${index + 1}] ${terminalSafe(entry)} — Proposed`));
492
+ if (warning !== null)
493
+ io.log(warning);
494
+ }
495
+ /** BAPI-1551 — the Dependency refresh and CI database behavior groups. */
496
+ function renderDependencyAndCiReview(io, proposal, stored, showValues) {
335
497
  io.log("");
336
498
  io.log(" Dependency refresh — before a worker starts, reinstall dependencies when a lockfile changed.");
337
499
  const storedList = stored?.dependency_install ?? [];
@@ -352,6 +514,9 @@ function renderDeclarationsReview(io, proposal, stored, showValues) {
352
514
  });
353
515
  for (const note of proposal.dependencyInstallNotes ?? [])
354
516
  io.log(` ${DEPENDENCY_NOTE_TEXT[note] ?? note}`);
517
+ for (const line of proposal.dependencyInstallLimitations ?? [])
518
+ io.log(` Could not check: ${plainDisplayText(line)}`);
519
+ io.log(" Each command runs in every fresh worker worktree, and again only when a file it names changes.");
355
520
  io.log(" Discovery looks at the repository root only, so it can miss a subdirectory project. Stored entries stay " +
356
521
  "as they are unless you change them; you can add a subdirectory entry by hand below.");
357
522
  io.log("");
@@ -676,6 +841,24 @@ async function reviewCiDatabase(io, proposal, stored) {
676
841
  }
677
842
  return chosen === current ? undefined : chosen;
678
843
  }
844
+ /**
845
+ * BAPI-1580 — offer each new must-order path on its own. Returns the complete
846
+ * canonical list (stored entries kept, accepted ones added), or `undefined`
847
+ * when the owner accepts none. Enter, or anything but yes, declines.
848
+ */
849
+ async function reviewMustOrderPaths(io, proposal, stored) {
850
+ const { offered } = mustOrderOffer(proposal, stored);
851
+ const accepted = [];
852
+ for (const entry of offered) {
853
+ if (await yes(io.promptLine, `Add must-order path ${terminalSafe(entry)}? [y/N]: `))
854
+ accepted.push(entry);
855
+ else
856
+ io.log(" Not added. Stored must-order paths are untouched.");
857
+ }
858
+ if (accepted.length === 0)
859
+ return undefined;
860
+ return canonicalMustOrderPaths([...(stored?.must_order_paths ?? []), ...accepted]);
861
+ }
679
862
  /**
680
863
  * Show the review surface and collect the owner's decisions. Requires a
681
864
  * terminal. Returns what changed; nothing is stored here.
@@ -701,19 +884,84 @@ export async function reviewDeclarations(io, proposal, stored) {
701
884
  const edit = {};
702
885
  if (!hasDeclarationsToReview(proposal, stored))
703
886
  return edit;
887
+ // BAPI-1598: printed in the summary above and covered by the same single
888
+ // confirmation; it adds no question of its own.
889
+ const workerDatabase = newWorkerDatabaseProposal(proposal, stored);
890
+ if (workerDatabase !== undefined)
891
+ edit.workerDatabase = workerDatabase;
704
892
  const dependencyInstall = await reviewDependencyInstall(io, proposal, stored);
705
893
  if (dependencyInstall !== undefined)
706
894
  edit.dependencyInstall = dependencyInstall;
707
895
  const ciDatabase = await reviewCiDatabase(io, proposal, stored);
708
896
  if (ciDatabase !== undefined)
709
897
  edit.ciDatabase = ciDatabase;
898
+ const mustOrderPaths = await reviewMustOrderPaths(io, proposal, stored);
899
+ if (mustOrderPaths !== undefined)
900
+ edit.mustOrderPaths = mustOrderPaths;
710
901
  return edit;
711
902
  }
712
903
  /** BAPI-1551 — print only the declaration groups (setup's advisory offer). */
713
904
  export function renderDeclarationsOnly(io, proposal, stored, showValues) {
714
905
  renderDeclarationsReview(io, proposal, stored, showValues);
906
+ if (newWorkerDatabaseProposal(proposal, stored) !== undefined)
907
+ renderWorkerDatabaseReview(io, proposal, stored);
715
908
  io.log("");
716
909
  }
910
+ /**
911
+ * BAPI-1604 — select the settings that need no individual confirmation, without
912
+ * asking: proposed worker variables (never a committed literal, which needs its
913
+ * own typed `yes`), proposed reproduction hints, dependency refresh entries, the
914
+ * CI-database proposal, and new must-order paths. Stored settings are never
915
+ * removed. The skipped receipts name the variable and never its value. Pure: no
916
+ * prompt, no write, and it uses the same committed-literal marker the interactive
917
+ * review uses rather than a second secret-name heuristic.
918
+ */
919
+ export function recommendedSettingsSelection(proposal, stored, providerChecks) {
920
+ const edit = {};
921
+ const skipped = [];
922
+ const storedEnv = stored?.worker_env ?? [];
923
+ let env = storedEnv.map((e) => ({ ...e }));
924
+ for (const row of envRows(proposal, stored)) {
925
+ const entry = row.proposed;
926
+ if (row.status === "Stored" || entry === undefined)
927
+ continue;
928
+ if (entry.committed_literal === true) {
929
+ skipped.push(`Skipped for safety: ${row.name} needs your review. Use --review-ci-settings.`);
930
+ continue;
931
+ }
932
+ env = [...env.filter((e) => e.name !== row.name), { ...entry }];
933
+ }
934
+ env.sort((a, b) => (a.name < b.name ? -1 : a.name > b.name ? 1 : 0));
935
+ if (!workerEnvEqual(env, storedEnv))
936
+ edit.workerEnv = env;
937
+ const reproduce = new Map();
938
+ for (const row of hintRows(proposal, stored, providerChecks)) {
939
+ if (row.proposed === null)
940
+ continue;
941
+ const proposed = hintFrom(row.proposed);
942
+ if (row.stored === null || !hintEqual(row.stored, proposed))
943
+ reproduce.set(row.check, proposed);
944
+ }
945
+ if (reproduce.size > 0)
946
+ edit.reproduce = reproduce;
947
+ // BAPI-1677: a safe default takes only additive drift. A change that drops or
948
+ // rewrites what is stored is the owner's decision, so it stays as stored here.
949
+ const deps = mergeDependencyProposal(stored?.dependency_install ?? [], proposal.dependencyInstallCandidates ?? []);
950
+ if (deps.withinBounds && deps.drift === "additive")
951
+ edit.dependencyInstall = deps.merged;
952
+ const current = storedCiDatabase(stored);
953
+ const proposedDb = proposedCiDatabase(proposal);
954
+ if (proposedDb !== CI_DATABASE_DEFAULT && proposedDb !== current)
955
+ edit.ciDatabase = proposedDb;
956
+ const workerDatabase = newWorkerDatabaseProposal(proposal, stored);
957
+ if (workerDatabase !== undefined)
958
+ edit.workerDatabase = workerDatabase;
959
+ const { offered } = mustOrderOffer(proposal, stored);
960
+ if (offered.length > 0) {
961
+ edit.mustOrderPaths = canonicalMustOrderPaths([...(stored?.must_order_paths ?? []), ...offered]);
962
+ }
963
+ return { edit, skipped };
964
+ }
717
965
  /** Name-only lines describing what an edit changes, for the gate comparison. */
718
966
  export function describeSettingsEdit(edit, stored) {
719
967
  const lines = [];
@@ -747,5 +995,14 @@ export function describeSettingsEdit(edit, stored) {
747
995
  ? " CI database behavior: reset to unknown"
748
996
  : ` CI database behavior: ${edit.ciDatabase}`);
749
997
  }
998
+ if (edit.workerDatabase !== undefined) {
999
+ lines.push(" worker database setup: set (replaces any stored declaration)");
1000
+ }
1001
+ if (edit.mustOrderPaths !== undefined) {
1002
+ const before = stored?.must_order_paths ?? [];
1003
+ const added = edit.mustOrderPaths.filter((p) => !before.includes(p));
1004
+ lines.push(` must-order paths: ${edit.mustOrderPaths.length} after this change` +
1005
+ (added.length > 0 ? ` (added ${safeList(added)})` : ""));
1006
+ }
750
1007
  return lines;
751
1008
  }