@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,3 +1,4 @@
1
+ import { describeCheckEvidence } from "../check-evidence.js";
1
2
  /**
2
3
  * Deterministic, read-only CI gate discovery (BAPI-1391).
3
4
  *
@@ -56,6 +57,8 @@
56
57
  import fs from "node:fs/promises";
57
58
  import path from "node:path";
58
59
  import { LEGACY_EPIC_IMPLEMENTER_NODE_PATH_ENV } from "../epic-implementer-env.js";
60
+ import { MAX_MUST_ORDER_PATHS, canonicalMustOrderPaths, isValidMustOrderPath, } from "../dependency-install-declarations.js";
61
+ import { TOOLCHAIN_CONTENT_FILES, installArgvForJavaScript, installArgvForPython, resolveRepositoryToolchains, } from "../repository-toolchains.js";
59
62
  // ---------------------------------------------------------------------------
60
63
  // Bounds and fixed vocabularies
61
64
  // ---------------------------------------------------------------------------
@@ -75,7 +78,9 @@ export const JENKINS_LOOKUP_NAMES = [
75
78
  "continuous-integration/jenkins/pr-merge",
76
79
  ];
77
80
  /** The script body `npm init` writes; it is a placeholder, not a test command. */
78
- export const NPM_PLACEHOLDER_TEST_SCRIPT = 'echo "Error: no test specified" && exit 1';
81
+ export { NPM_PLACEHOLDER_TEST_SCRIPT } from "../package-script-semantics.js";
82
+ import { isUsablePackageScript } from "../package-script-semantics.js";
83
+ export { isUsablePackageScript };
79
84
  /** BAPI-1520 — at most this many worker-variable names are proposed. */
80
85
  export const MAX_WORKER_ENV_CANDIDATES = 32;
81
86
  /** BAPI-1520 — the longest value, in UTF-8 bytes, that may be proposed. */
@@ -159,6 +164,32 @@ const GIT_CLIENT_HOOK_NAMES = [
159
164
  "pre-rebase",
160
165
  "prepare-commit-msg",
161
166
  ];
167
+ /**
168
+ * BAPI-1580 — the fixed migration directories probed for must-order proposals.
169
+ * Each one top-level directory's `migrations/` (a Django app) is probed too.
170
+ * BAPI-1605 adds the Prisma, Flyway, Entity Framework, and Liquibase layouts.
171
+ * Each is one explicit path: no glob and no recursive walk.
172
+ */
173
+ export const MUST_ORDER_FIXED_DIRECTORIES = [
174
+ "alembic/versions/",
175
+ "db/alembic/versions/",
176
+ "migrations/versions/",
177
+ "db/migrate/",
178
+ "prisma/migrations/",
179
+ "db/migration/",
180
+ "src/main/resources/db/migration/",
181
+ "Migrations/",
182
+ "db/changelog/",
183
+ ];
184
+ /**
185
+ * BAPI-1605 — fixed entries whose spelling differs from another layout only by
186
+ * case. A case-insensitive filesystem answers a listing of `Migrations` for a
187
+ * lowercase `migrations` directory, so such an entry is proposed only when the
188
+ * single root listing holds this exact name.
189
+ */
190
+ const MUST_ORDER_ROOT_NAME_CHECKED = ["Migrations/"];
191
+ /** BAPI-1580 — top-level directories never probed for `<dir>/migrations/` (dot-directories are skipped too). */
192
+ export const MUST_ORDER_EXCLUDED_TOP_LEVEL = ["node_modules", "vendor", ".venv"];
162
193
  // ---------------------------------------------------------------------------
163
194
  // Node filesystem seam
164
195
  // ---------------------------------------------------------------------------
@@ -920,12 +951,6 @@ export function packageScriptArgv(pm, script) {
920
951
  return [pm, "run", script];
921
952
  }
922
953
  /** True when a package.json script value is a usable command (not empty, not the npm placeholder). */
923
- export function isUsablePackageScript(value) {
924
- if (typeof value !== "string")
925
- return false;
926
- const trimmed = value.trim();
927
- return trimmed !== "" && trimmed !== NPM_PLACEHOLDER_TEST_SCRIPT;
928
- }
929
954
  /** True when `name` is a valid local command name. */
930
955
  export function isGateCommandName(name) {
931
956
  return GATE_COMMAND_NAME_PATTERN.test(name);
@@ -959,6 +984,17 @@ export function deriveProposalKind(providerChecks, localCommandIds) {
959
984
  return "local";
960
985
  return "none";
961
986
  }
987
+ /**
988
+ * BAPI-1603 — the provider check names the repository's CI has actually reported,
989
+ * in the proposal's own order. A name counts only when it is in
990
+ * `proposal.proposed.providerChecks` AND its candidate's outcome is `reported`; an
991
+ * unseen, unavailable, or unknown name is never returned, so unknown history can
992
+ * never be mistaken for a reported check. The proposal is not modified.
993
+ */
994
+ export function reportedProviderChecks(proposal) {
995
+ const reported = new Set(proposal.providerCandidates.filter((c) => c.outcome === "reported").map((c) => c.name));
996
+ return proposal.proposed.providerChecks.filter((name) => reported.has(name));
997
+ }
962
998
  const PROVIDER_OUTCOMES = new Set(["reported", "unseen", "evidence_unavailable"]);
963
999
  /**
964
1000
  * Classify a lookup response into a history state. A successful answer with no
@@ -1029,6 +1065,197 @@ function jobDetail(job) {
1029
1065
  detail += ` (name may vary: ${VARIANCE_TEXT[job.variance]})`;
1030
1066
  return detail;
1031
1067
  }
1068
+ /** Environment names whose literal value shows that CI provides a database. */
1069
+ const CI_DATABASE_ENV_NAME = /^(?:DATABASE_URL|POSTGRES_[A-Z0-9_]+|PG[A-Z0-9_]+)$/;
1070
+ /** BAPI-1551 — classify one readable workflow file's database evidence. */
1071
+ function workflowDatabaseEvidence(text, jobsReadable) {
1072
+ const lines = significantLines(text);
1073
+ const hasServices = lines.some((l) => l.indent > 0 && splitKeyLine(l.text)?.key === "services");
1074
+ const env = scanEnvMaps(text, "github");
1075
+ const databaseNames = env.declarations.filter((d) => CI_DATABASE_ENV_NAME.test(d.name));
1076
+ if (hasServices || databaseNames.some((d) => d.value !== null))
1077
+ return "present";
1078
+ // A database name with a non-literal value (an expression, a number) cannot
1079
+ // prove absence, and neither can an env map or a jobs block that was unclear.
1080
+ if (!jobsReadable || env.unclear || databaseNames.length > 0)
1081
+ return "unclear";
1082
+ return "absent";
1083
+ }
1084
+ /**
1085
+ * BAPI-1551 — the `ci_database` proposal from the workflow files that hold a job
1086
+ * reporting one of `providerChecks`. `provided` wins when any such file has
1087
+ * definite evidence; `none` needs every reported check mapped to a workflow file
1088
+ * and every such file clearly without a database; anything else is `unknown`.
1089
+ */
1090
+ export function proposeCiDatabase(providerChecks, workflowFiles) {
1091
+ if (providerChecks.length === 0)
1092
+ return { value: "unknown", sources: [] };
1093
+ const relevant = workflowFiles.filter((f) => f.reportedNames.some((n) => providerChecks.includes(n)));
1094
+ const sources = relevant.map((f) => f.source);
1095
+ if (relevant.some((f) => f.database === "present")) {
1096
+ return { value: "provided", sources: relevant.filter((f) => f.database === "present").map((f) => f.source) };
1097
+ }
1098
+ const allMapped = providerChecks.every((check) => relevant.some((f) => f.reportedNames.includes(check)));
1099
+ // A workflow file whose jobs could not be named might report a check too.
1100
+ const unnamedFiles = workflowFiles.some((f) => !f.jobsReadable);
1101
+ if (relevant.length === 0 || !allMapped || unnamedFiles || relevant.some((f) => f.database !== "absent")) {
1102
+ return { value: "unknown", sources };
1103
+ }
1104
+ return { value: "none", sources };
1105
+ }
1106
+ /**
1107
+ * BAPI-1551 — read the toolchain resolver's files through the bounded discovery
1108
+ * seam. The seam answers `null` for an absent, unreadable, or over-size file, so
1109
+ * `exists` tells them apart: a file that exists but cannot be read throws a
1110
+ * non-missing error (the resolver then reports `unknown`), except a file the
1111
+ * resolver checks only for existence, which reads as present.
1112
+ */
1113
+ function toolchainReader(fsSeam) {
1114
+ return async (relPath) => {
1115
+ const text = await readBounded(fsSeam, relPath);
1116
+ if (text !== null)
1117
+ return text;
1118
+ if (!(await fsSeam.exists(relPath))) {
1119
+ throw Object.assign(new Error("absent"), { code: "ENOENT" });
1120
+ }
1121
+ if (!TOOLCHAIN_CONTENT_FILES.includes(relPath))
1122
+ return "";
1123
+ throw Object.assign(new Error("unreadable"), { code: "EIO" });
1124
+ };
1125
+ }
1126
+ /**
1127
+ * BAPI-1580 — the must-order proposals: the fixed migration directories, plus
1128
+ * `<top-level>/migrations/` for each entry of ONE root listing. `Migrations/`
1129
+ * (BAPI-1605) is proposed only when that listing holds the exact name. No recursive
1130
+ * walk. Dot-directories and {@link MUST_ORDER_EXCLUDED_TOP_LEVEL} are skipped.
1131
+ * A directory counts only when the seam lists it, so a path that is absent, not
1132
+ * a directory, or resolves outside the repository is never proposed. Past the
1133
+ * cap, the first {@link MAX_MUST_ORDER_PATHS} (sorted) are kept and the rest
1134
+ * are counted, never silently dropped.
1135
+ */
1136
+ export async function proposeMustOrderPaths(fsSeam) {
1137
+ // ONE root listing serves both the exact-name check and the `<dir>/migrations/` probes.
1138
+ const rootNames = (await fsSeam.listDir("")) ?? [];
1139
+ const probes = MUST_ORDER_FIXED_DIRECTORIES.filter((dir) => !MUST_ORDER_ROOT_NAME_CHECKED.includes(dir) || rootNames.includes(dir.slice(0, -1)));
1140
+ for (const name of rootNames) {
1141
+ if (name.startsWith(".") || MUST_ORDER_EXCLUDED_TOP_LEVEL.includes(name))
1142
+ continue;
1143
+ probes.push(`${name}/migrations/`);
1144
+ }
1145
+ const found = [];
1146
+ for (const probe of canonicalMustOrderPaths(probes)) {
1147
+ // A name the server would refuse is never probed or proposed.
1148
+ if (!isValidMustOrderPath(probe))
1149
+ continue;
1150
+ if ((await fsSeam.listDir(probe.slice(0, -1))) !== null)
1151
+ found.push(probe);
1152
+ }
1153
+ return { candidates: found.slice(0, MAX_MUST_ORDER_PATHS), overflow: Math.max(0, found.length - MAX_MUST_ORDER_PATHS) };
1154
+ }
1155
+ const COMPOSE_FILES = ["docker-compose.yml", "docker-compose.yaml", "compose.yml", "compose.yaml"];
1156
+ const WORKER_DATABASE_IDENTIFIER = /^[A-Za-z_][A-Za-z0-9_]{0,62}$/;
1157
+ const WORKER_DATABASE_RESERVED_PREFIXES = ["ANTHROPIC_", "BAPI_", "BRIDGE_", "CLAUDE_", "DYLD_", "GIT_CONFIG_"];
1158
+ const WORKER_DATABASE_SECRET_FRAGMENTS = ["TOKEN", "SECRET", "PASSWORD", "API_KEY"];
1159
+ const WORKER_DATABASE_MAX_ALIASES = 4;
1160
+ /** The default migration command timeout (seconds) proposed with an Alembic command. */
1161
+ const WORKER_DATABASE_PROPOSED_TIMEOUT_SECONDS = 120;
1162
+ function isProposableDatabaseUrlName(name) {
1163
+ if (!/^[A-Z][A-Z0-9_]{0,63}$/.test(name))
1164
+ return false;
1165
+ if (name !== "DATABASE_URL" && !name.endsWith("_URL"))
1166
+ return false;
1167
+ if (WORKER_DATABASE_RESERVED_PREFIXES.some((prefix) => name.startsWith(prefix)))
1168
+ return false;
1169
+ return !WORKER_DATABASE_SECRET_FRAGMENTS.some((fragment) => name.includes(fragment));
1170
+ }
1171
+ /**
1172
+ * BAPI-1598 — propose a worker-database declaration from local repository
1173
+ * evidence. Alembic evidence is `alembic.ini`; the database evidence is ONE
1174
+ * Compose Postgres service with a literal database name and a literal, non-
1175
+ * superuser-looking role. A Prisma schema alone proposes nothing.
1176
+ *
1177
+ * Reads names only. No password, connection string, or other Compose value is
1178
+ * kept, and a Compose file holding a connection string with user information
1179
+ * proposes nothing at all. Any missing part (role, protected database, URL alias,
1180
+ * migration command, timeout) proposes nothing: a partial declaration is never
1181
+ * built.
1182
+ */
1183
+ export async function proposeWorkerDatabase(fsSeam) {
1184
+ if (!(await fsSeam.exists("alembic.ini")))
1185
+ return undefined;
1186
+ for (const file of COMPOSE_FILES) {
1187
+ const text = await readBounded(fsSeam, file);
1188
+ if (text === null)
1189
+ continue;
1190
+ // A connection string with user information is a credential; do not guess around it.
1191
+ if (/[a-z][a-z0-9+.-]*:\/\/[^\s/?#'"]*@/i.test(text))
1192
+ return undefined;
1193
+ if (!/^\s*image:\s*['"]?(?:[\w.-]+\/)*postgres(?::[\w.-]+)?['"]?\s*(?:#.*)?$/m.test(text))
1194
+ continue;
1195
+ const literal = (key) => {
1196
+ const match = new RegExp(`^\\s*(?:-\\s*)?${key}\\s*[:=]\\s*['"]?([^\\s'"#$]+)['"]?\\s*(?:#.*)?$`, "m").exec(text);
1197
+ return match && WORKER_DATABASE_IDENTIFIER.test(match[1]) ? match[1] : null;
1198
+ };
1199
+ const database = literal("POSTGRES_DB");
1200
+ const role = literal("POSTGRES_USER");
1201
+ if (database === null || role === null || role === "postgres")
1202
+ return undefined;
1203
+ const aliases = [];
1204
+ for (const match of text.matchAll(/^\s*(?:-\s*)?([A-Z][A-Z0-9_]*_URL|DATABASE_URL)\s*[:=]/gm)) {
1205
+ if (isProposableDatabaseUrlName(match[1]) && !aliases.includes(match[1]))
1206
+ aliases.push(match[1]);
1207
+ }
1208
+ if (aliases.length === 0)
1209
+ return undefined;
1210
+ return {
1211
+ declaration: {
1212
+ mode: "disposable_postgres",
1213
+ worker_role: role,
1214
+ protected_databases: [database],
1215
+ env_names: aliases.slice(0, WORKER_DATABASE_MAX_ALIASES),
1216
+ migrate_command: {
1217
+ argv: [".venv/bin/alembic", "-c", "alembic.ini", "upgrade", "head"],
1218
+ timeout_seconds: WORKER_DATABASE_PROPOSED_TIMEOUT_SECONDS,
1219
+ head_check: "alembic",
1220
+ },
1221
+ },
1222
+ sources: ["alembic.ini", file],
1223
+ };
1224
+ }
1225
+ return undefined;
1226
+ }
1227
+ /** BAPI-1551 — the root dependency-refresh proposals and the notes on what was left out. */
1228
+ export async function proposeDependencyInstall(fsSeam) {
1229
+ let resolution;
1230
+ try {
1231
+ resolution = await resolveRepositoryToolchains(toolchainReader(fsSeam));
1232
+ }
1233
+ catch {
1234
+ return { candidates: [], notes: ["dependency_install_toolchain_unresolved"] };
1235
+ }
1236
+ if (resolution.status !== "resolved") {
1237
+ return { candidates: [], notes: ["dependency_install_toolchain_unresolved"] };
1238
+ }
1239
+ const candidates = [];
1240
+ const notes = [];
1241
+ const js = resolution.toolchains.javascript;
1242
+ if (js !== null) {
1243
+ candidates.push({
1244
+ cwd: ".",
1245
+ argv: installArgvForJavaScript(js),
1246
+ lockfiles: [js.dependencyFile],
1247
+ label: js.manager === "yarn" ? `yarn (${js.generation})` : js.manager,
1248
+ });
1249
+ }
1250
+ const py = resolution.toolchains.python;
1251
+ if (py !== null) {
1252
+ if (py.manager === "pip")
1253
+ notes.push("dependency_install_pip_not_proposed");
1254
+ else
1255
+ candidates.push({ cwd: ".", argv: installArgvForPython(py), lockfiles: [py.dependencyFile], label: py.manager });
1256
+ }
1257
+ return { candidates, notes };
1258
+ }
1032
1259
  async function collectWorkflows(fsSeam, evidence, lookups, extras) {
1033
1260
  const entries = await fsSeam.listDir(WORKFLOWS_DIR);
1034
1261
  if (entries === null)
@@ -1040,9 +1267,19 @@ async function collectWorkflows(fsSeam, evidence, lookups, extras) {
1040
1267
  for (const file of files) {
1041
1268
  const source = `${WORKFLOWS_DIR}/${file}`;
1042
1269
  const text = await readBounded(fsSeam, source);
1043
- if (text === null)
1270
+ if (text === null) {
1271
+ // BAPI-1551: an unreadable workflow file can neither prove nor rule out a database.
1272
+ extras.workflowFiles.push({ source, reportedNames: [], jobsReadable: false, database: "unclear" });
1044
1273
  continue;
1274
+ }
1045
1275
  const scan = scanWorkflowJobs(text, { structure: true });
1276
+ const facts = {
1277
+ source,
1278
+ reportedNames: [],
1279
+ jobsReadable: scan.jobs.length > 0,
1280
+ database: workflowDatabaseEvidence(text, scan.jobs.length > 0),
1281
+ };
1282
+ extras.workflowFiles.push(facts);
1046
1283
  for (const declaration of scanEnvMaps(text, "github").declarations) {
1047
1284
  extras.envObservations.push({ source, declaration });
1048
1285
  }
@@ -1067,6 +1304,7 @@ async function collectWorkflows(fsSeam, evidence, lookups, extras) {
1067
1304
  };
1068
1305
  evidence.push(e);
1069
1306
  if (reported !== null) {
1307
+ facts.reportedNames.push(reported);
1070
1308
  lookups.add(reported, e);
1071
1309
  if (job.structure) {
1072
1310
  const jobs = extras.hintJobs.get(reported) ?? [];
@@ -1288,7 +1526,7 @@ export async function discoverGate(input) {
1288
1526
  const evidence = [];
1289
1527
  const localCandidates = [];
1290
1528
  const lookups = new LookupNames();
1291
- const extras = { envObservations: [], hintJobs: new Map() };
1529
+ const extras = { envObservations: [], hintJobs: new Map(), workflowFiles: [] };
1292
1530
  await collectWorkflows(fsSeam, evidence, lookups, extras);
1293
1531
  await collectCircleCi(fsSeam, evidence, lookups, extras);
1294
1532
  await collectOtherProviders(fsSeam, evidence, lookups);
@@ -1306,7 +1544,8 @@ export async function discoverGate(input) {
1306
1544
  // When history is not `available`, no outcome is trusted, even one the response carried.
1307
1545
  const outcome = history.status === "available" ? outcomeFor(outcomes, entry.name) : null;
1308
1546
  if (outcome === "reported") {
1309
- providerCandidates.push({ name: entry.name, outcome, confidence: "high", evidence: entry.evidence });
1547
+ providerCandidates.push({ name: entry.name, outcome, confidence: "high", evidence: entry.evidence,
1548
+ checkEvidence: describeCheckEvidence(entry.name, "reported", "provider history") });
1310
1549
  }
1311
1550
  else {
1312
1551
  unreportedProviderNames.push({
@@ -1326,6 +1565,8 @@ export async function discoverGate(input) {
1326
1565
  const localCommandIds = providerChecks.length > 0 ? [] : validLocal.filter((c) => c.confidence === "high").map((c) => c.id);
1327
1566
  const workerEnv = resolveWorkerEnv(extras.envObservations);
1328
1567
  const hints = await proposeReproductionHints(fsSeam, providerChecks, extras.hintJobs);
1568
+ const dependencyInstall = await proposeDependencyInstall(fsSeam);
1569
+ const mustOrder = await proposeMustOrderPaths(fsSeam);
1329
1570
  return {
1330
1571
  providerCandidates,
1331
1572
  unreportedProviderNames,
@@ -1340,6 +1581,36 @@ export async function discoverGate(input) {
1340
1581
  workerEnvOverflow: workerEnv.overflow,
1341
1582
  reproductionHints: hints.proposed,
1342
1583
  reproductionHintsSkipped: hints.skipped,
1584
+ ...declarationFields(dependencyInstall, proposeCiDatabase(providerChecks, extras.workflowFiles), mustOrder, await proposeWorkerDatabase(fsSeam)),
1585
+ };
1586
+ }
1587
+ /**
1588
+ * BAPI-1551 — only the declaration proposals, for a repository whose gate is
1589
+ * already confirmed: the root dependency refreshes, the CI-database value
1590
+ * read from the workflow files that report one of the CONFIRMED provider checks,
1591
+ * and (BAPI-1580) the existing migration directories as must-order paths.
1592
+ * Makes no provider-history call.
1593
+ */
1594
+ export async function discoverDeclarations(input) {
1595
+ const extras = { envObservations: [], hintJobs: new Map(), workflowFiles: [] };
1596
+ await collectWorkflows(input.fs, [], new LookupNames(), extras);
1597
+ const dependencyInstall = await proposeDependencyInstall(input.fs);
1598
+ const mustOrder = await proposeMustOrderPaths(input.fs);
1599
+ return declarationFields(dependencyInstall, proposeCiDatabase(input.providerChecks, extras.workflowFiles), mustOrder, await proposeWorkerDatabase(input.fs));
1600
+ }
1601
+ /**
1602
+ * BAPI-1551 — the declaration fields of a proposal. Each is present only when it
1603
+ * says something (a candidate, a note, or a value other than `unknown`), so a
1604
+ * repository with nothing to propose yields exactly the pre-BAPI-1551 proposal.
1605
+ */
1606
+ function declarationFields(dependencyInstall, ciDatabase, mustOrder, workerDatabase) {
1607
+ return {
1608
+ ...(workerDatabase !== undefined ? { workerDatabaseProposal: workerDatabase } : {}),
1609
+ ...(dependencyInstall.candidates.length > 0 ? { dependencyInstallCandidates: dependencyInstall.candidates } : {}),
1610
+ ...(dependencyInstall.notes.length > 0 ? { dependencyInstallNotes: dependencyInstall.notes } : {}),
1611
+ ...(ciDatabase.value !== "unknown" ? { ciDatabaseProposal: ciDatabase } : {}),
1612
+ ...(mustOrder.candidates.length > 0 ? { mustOrderPathCandidates: mustOrder.candidates } : {}),
1613
+ ...(mustOrder.overflow > 0 ? { mustOrderPathOverflow: mustOrder.overflow } : {}),
1343
1614
  };
1344
1615
  }
1345
1616
  /**