@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
@@ -0,0 +1,335 @@
1
+ /**
2
+ * BAPI-1677 — work out which optional extras an install command may add.
3
+ *
4
+ * An extra is kept only when the install target DECLARES it and the repository's
5
+ * learned instructions NAME it in a positive example. Only a declared key ever
6
+ * reaches an argument list: no other repository or instruction text does.
7
+ *
8
+ * Pure apart from one injected bounded file reader: no network, prompt, or write.
9
+ * Extras are read from text with a small lexical scanner rather than a TOML
10
+ * dependency. Anything the scanner cannot read with certainty is `unknown`, never
11
+ * a confirmed empty list, and never a stop.
12
+ */
13
+ import { MAX_DEPENDENCY_INSTALL_ARGV_ITEMS, isUnsafeDependencyInstallArg, } from "../dependency-install-declarations.js";
14
+ import { LEARNED_INSTRUCTION_FIELDS } from "../testing-config-client.js";
15
+ /** The largest `pyproject.toml` the scanner reads. */
16
+ export const MAX_DECLARED_EXTRAS_FILE_BYTES = 256 * 1024;
17
+ /** The most learned text read from one field. A longer field is a limitation. */
18
+ export const MAX_LEARNED_TEXT_BYTES = 256 * 1024;
19
+ /** The most matches kept from one field. More is a limitation, not a guess. */
20
+ export const MAX_EXTRA_MATCHES = 64;
21
+ /** The longest evidence span shown for one extra. */
22
+ export const MAX_EXTRA_EVIDENCE_CHARS = 80;
23
+ /** The most notes one derivation returns. */
24
+ export const MAX_EXTRA_NOTES = 8;
25
+ /** The repository-relative path of a target's own `pyproject.toml`. */
26
+ export function pyprojectPathFor(cwd) {
27
+ return cwd === "." ? "pyproject.toml" : `${cwd}/pyproject.toml`;
28
+ }
29
+ const BARE_KEY_RE = /^[A-Za-z0-9_-]+$/;
30
+ /** What may stand as an extra name. A key outside this set never reaches a command. */
31
+ const EXTRA_NAME_RE = /^[A-Za-z0-9][A-Za-z0-9._-]*$/;
32
+ /**
33
+ * Blank out comments and string bodies, keeping the line structure, so a header
34
+ * inside a multi-line string or a comment can never be read as a header. `null`
35
+ * means a string never closed: the file cannot be read with certainty.
36
+ *
37
+ * Each line reports its text with strings blanked to `S`, and its leading quoted
38
+ * key when it has one.
39
+ */
40
+ function lexicalLines(text) {
41
+ const lines = [];
42
+ let code = "";
43
+ let quotedKey = null;
44
+ let i = 0;
45
+ const flush = () => {
46
+ lines.push({ code, quotedKey });
47
+ code = "";
48
+ quotedKey = null;
49
+ };
50
+ while (i < text.length) {
51
+ const ch = text[i];
52
+ if (ch === "\n") {
53
+ flush();
54
+ i += 1;
55
+ continue;
56
+ }
57
+ if (ch === "#") {
58
+ while (i < text.length && text[i] !== "\n")
59
+ i += 1;
60
+ continue;
61
+ }
62
+ if (ch === '"' || ch === "'") {
63
+ const triple = ch.repeat(3);
64
+ if (text.startsWith(triple, i)) {
65
+ let end = i + 3;
66
+ for (;;) {
67
+ end = text.indexOf(triple, end);
68
+ if (end === -1)
69
+ return null;
70
+ // A basic string's `\"""` does not close it. A literal string has no escapes.
71
+ if (ch === '"' && isEscaped(text, end)) {
72
+ end += 1;
73
+ continue;
74
+ }
75
+ break;
76
+ }
77
+ // The string stands on its opening line. Its newlines stay lines, blank ones.
78
+ code += "S";
79
+ for (let at = i; at < end; at += 1)
80
+ if (text[at] === "\n")
81
+ flush();
82
+ i = end + 3;
83
+ // A closing delimiter may carry up to two more quotes that belong to the string.
84
+ while (text[i] === ch)
85
+ i += 1;
86
+ continue;
87
+ }
88
+ let end = i + 1;
89
+ while (end < text.length && text[end] !== "\n") {
90
+ if (text[end] === ch && !(ch === '"' && isEscaped(text, end)))
91
+ break;
92
+ end += 1;
93
+ }
94
+ if (text[end] !== ch)
95
+ return null;
96
+ if (code.trim().length === 0 && quotedKey === null) {
97
+ const inner = text.slice(i + 1, end);
98
+ // A quoted key with an escape is outside what this scanner can read exactly.
99
+ quotedKey = ch === '"' && inner.includes("\\") ? "\u0000" : inner;
100
+ }
101
+ code += "S";
102
+ i = end + 1;
103
+ continue;
104
+ }
105
+ code += ch;
106
+ i += 1;
107
+ }
108
+ flush();
109
+ return lines;
110
+ }
111
+ function isEscaped(text, at) {
112
+ let slashes = 0;
113
+ for (let j = at - 1; j >= 0 && text[j] === "\\"; j -= 1)
114
+ slashes += 1;
115
+ return slashes % 2 === 1;
116
+ }
117
+ const TABLE_FOR_MANAGER = Object.freeze({
118
+ uv: "[project.optional-dependencies]",
119
+ poetry: "[tool.poetry.extras]",
120
+ });
121
+ /**
122
+ * The manager's own table keys, in declaration order. A header counts only at the
123
+ * start of a line and outside any string or comment. Depth tracking skips a
124
+ * multi-line array's values, so a value never reads as a key.
125
+ */
126
+ export function scanDeclaredExtras(text, manager) {
127
+ if (Buffer.byteLength(text, "utf8") > MAX_DECLARED_EXTRAS_FILE_BYTES)
128
+ return { status: "unknown", reason: "too_large" };
129
+ const lines = lexicalLines(text.replace(/\r\n/g, "\n"));
130
+ if (lines === null)
131
+ return { status: "unknown", reason: "malformed" };
132
+ const wanted = TABLE_FOR_MANAGER[manager];
133
+ const extras = [];
134
+ let inTable = false;
135
+ let depth = 0;
136
+ for (const line of lines) {
137
+ const code = line.code;
138
+ const trimmed = code.trim();
139
+ if (depth > 0) {
140
+ depth += bracketDelta(code);
141
+ if (depth < 0)
142
+ return { status: "unknown", reason: "malformed" };
143
+ continue;
144
+ }
145
+ if (trimmed.length === 0)
146
+ continue;
147
+ if (trimmed.startsWith("[")) {
148
+ // A real table header starts at the first column.
149
+ if (code.startsWith("[") && /^\[\[?[^\]]*\]\]?$/.test(trimmed)) {
150
+ inTable = trimmed === wanted;
151
+ continue;
152
+ }
153
+ return { status: "unknown", reason: "malformed" };
154
+ }
155
+ const eq = code.indexOf("=");
156
+ if (eq === -1)
157
+ return { status: "unknown", reason: "malformed" };
158
+ depth = bracketDelta(code.slice(eq + 1));
159
+ if (depth < 0)
160
+ return { status: "unknown", reason: "malformed" };
161
+ if (!inTable)
162
+ continue;
163
+ const rawKey = code.slice(0, eq).trim();
164
+ const key = rawKey === "S" ? line.quotedKey : BARE_KEY_RE.test(rawKey) ? rawKey : null;
165
+ if (key === null || key === "\u0000")
166
+ return { status: "unknown", reason: "unsupported_key" };
167
+ if (!extras.includes(key))
168
+ extras.push(key);
169
+ }
170
+ if (depth !== 0)
171
+ return { status: "unknown", reason: "malformed" };
172
+ return { status: "known", extras };
173
+ }
174
+ function bracketDelta(code) {
175
+ let delta = 0;
176
+ for (const ch of code) {
177
+ if (ch === "[" || ch === "{")
178
+ delta += 1;
179
+ else if (ch === "]" || ch === "}")
180
+ delta -= 1;
181
+ }
182
+ return delta;
183
+ }
184
+ // A name ends in a letter or digit, so the full stop closing a sentence is never part of it.
185
+ const NAME = "[A-Za-z0-9](?:[A-Za-z0-9._-]*[A-Za-z0-9])?";
186
+ /** A sentence mentioning any of these is negated, even when another clause is positive. */
187
+ const NEGATION_RE = /\b(?:do not|don't|dont|never|avoid|without|must not|should not|shouldn't|cannot|can't|not)\b/i;
188
+ /** A word that makes a line refer to a command for something other than the install target. */
189
+ const OTHER_TARGET_RE = /\b(?:pip install|uv add|uv pip|poetry add|pipx)\b/i;
190
+ /** Sentence boundaries: a line break, or end punctuation before whitespace. */
191
+ function sentences(text) {
192
+ return text.split(/\n+|(?<=[.!?])\s+/).filter((s) => s.trim().length > 0);
193
+ }
194
+ function matchesInSentence(sentence, manager) {
195
+ const found = [];
196
+ if (/(?:^|[\s`'"])--all-extras(?=$|[\s`'".,;:)])/.test(sentence))
197
+ found.push({ names: "all", span: "--all-extras" });
198
+ if (manager === "uv") {
199
+ for (const m of sentence.matchAll(new RegExp(`(?:^|[\\s\`'"])--extra[ =](${NAME})`, "g"))) {
200
+ found.push({ names: [m[1]], span: `--extra ${m[1]}` });
201
+ }
202
+ }
203
+ else {
204
+ for (const m of sentence.matchAll(new RegExp(`(?:^|[\\s\`'"])-E[ =](${NAME})`, "g"))) {
205
+ found.push({ names: [m[1]], span: `-E ${m[1]}` });
206
+ }
207
+ for (const m of sentence.matchAll(/(?:^|[\s`'"])--extras[ =]"([^"]{1,200})"/g)) {
208
+ const names = m[1].trim().split(/\s+/).filter((n) => n.length > 0);
209
+ if (names.length > 0 && names.every((n) => EXTRA_NAME_RE.test(n))) {
210
+ found.push({ names, span: `--extras "${names.join(" ")}"` });
211
+ }
212
+ }
213
+ }
214
+ // `.[a,b]` is the resolved target itself. `other-pkg[seo]` has a name before the
215
+ // bracket, so it is another package's extra and never matches here.
216
+ for (const m of sentence.matchAll(/(?:^|[\s`'"])\.\[([A-Za-z0-9._,\s-]{1,200})\]/g)) {
217
+ const names = m[1].split(",").map((n) => n.trim()).filter((n) => n.length > 0);
218
+ if (names.length > 0 && names.every((n) => EXTRA_NAME_RE.test(n))) {
219
+ found.push({ names, span: `.[${names.join(",")}]` });
220
+ }
221
+ }
222
+ return found;
223
+ }
224
+ /** Whether a sentence holds an install-flag shape for extras at all. */
225
+ function mentionsExtraSyntax(sentence) {
226
+ return /(?:^|[\s`'"])(?:--extra|--extras|--all-extras|-E)(?=$|[\s=`'"])|(?:^|[\s`'"])\.\[/.test(sentence);
227
+ }
228
+ /** The learned fields in plain words, for what the owner reads. */
229
+ const LEARNED_FIELD_WORDS = Object.freeze({
230
+ architecture_instructions: "the architecture instructions Bridge learned",
231
+ unit_testing_instructions: "the unit testing instructions Bridge learned",
232
+ e2e_testing_instructions: "the end-to-end testing instructions Bridge learned",
233
+ });
234
+ function addNote(notes, note) {
235
+ if (notes.length < MAX_EXTRA_NOTES && !notes.includes(note))
236
+ notes.push(note);
237
+ }
238
+ /**
239
+ * Combine a target's declared keys with the learned text. Named ∩ declared, in
240
+ * declared order, within the argument bound. A failed field yields no extras from
241
+ * that field and marks the result incomplete; a blank field is only an absence.
242
+ */
243
+ export function deriveExtrasFromText(target, declared, learned) {
244
+ const notes = [];
245
+ let complete = true;
246
+ if (declared.status === "unknown") {
247
+ complete = false;
248
+ addNote(notes, `Bridge could not read the optional extras in ${pyprojectPathFor(target.cwd)}, so it adds none.`);
249
+ }
250
+ if (learned === null) {
251
+ complete = false;
252
+ addNote(notes, "Bridge could not read the repository's learned instructions, so it adds no extras from them.");
253
+ }
254
+ const declaredKeys = declared.status === "known" ? declared.extras : [];
255
+ const firstEvidence = new Map();
256
+ for (const field of LEARNED_INSTRUCTION_FIELDS) {
257
+ const read = learned?.[field];
258
+ if (read === undefined)
259
+ continue;
260
+ if (!read.ok) {
261
+ complete = false;
262
+ addNote(notes, `Bridge could not read ${LEARNED_FIELD_WORDS[field]} (${field}), so it adds no extras from them. Any extra your tests need can be added by correcting the commands.`);
263
+ continue;
264
+ }
265
+ const text = read.value;
266
+ if (text === null || text.trim().length === 0)
267
+ continue;
268
+ if (Buffer.byteLength(text, "utf8") > MAX_LEARNED_TEXT_BYTES) {
269
+ complete = false;
270
+ addNote(notes, `${LEARNED_FIELD_WORDS[field]} (${field}) are too long for Bridge to check for extras, so it adds none from them.`);
271
+ continue;
272
+ }
273
+ let matches = 0;
274
+ for (const sentence of sentences(text)) {
275
+ if (!mentionsExtraSyntax(sentence))
276
+ continue;
277
+ if (NEGATION_RE.test(sentence))
278
+ continue;
279
+ if (OTHER_TARGET_RE.test(sentence)) {
280
+ addNote(notes, `A line in ${LEARNED_FIELD_WORDS[field]} (${field}) names extras, but Bridge could not tell they belong to this project, so it left them out.`);
281
+ continue;
282
+ }
283
+ for (const match of matchesInSentence(sentence, target.manager)) {
284
+ matches += 1;
285
+ if (matches > MAX_EXTRA_MATCHES) {
286
+ complete = false;
287
+ addNote(notes, `${LEARNED_FIELD_WORDS[field]} (${field}) name too many extras for Bridge to read, so some may be left out.`);
288
+ break;
289
+ }
290
+ const names = match.names === "all" ? declaredKeys : match.names;
291
+ for (const name of names) {
292
+ if (declaredKeys.includes(name) && !firstEvidence.has(name)) {
293
+ firstEvidence.set(name, { extra: name, field, span: match.span.slice(0, MAX_EXTRA_EVIDENCE_CHARS) });
294
+ }
295
+ }
296
+ }
297
+ if (matches > MAX_EXTRA_MATCHES)
298
+ break;
299
+ }
300
+ }
301
+ const extras = [];
302
+ const evidence = [];
303
+ const room = Math.max(0, Math.floor((MAX_DEPENDENCY_INSTALL_ARGV_ITEMS - target.baseArgvLength) / 2));
304
+ let omittedForBound = false;
305
+ for (const key of declaredKeys) {
306
+ const kept = firstEvidence.get(key);
307
+ if (kept === undefined)
308
+ continue;
309
+ if (!EXTRA_NAME_RE.test(key) || isUnsafeDependencyInstallArg(key)) {
310
+ addNote(notes, "An extra was left out because its name is not safe to put in an install command.");
311
+ continue;
312
+ }
313
+ if (extras.length >= room) {
314
+ omittedForBound = true;
315
+ continue;
316
+ }
317
+ extras.push(key);
318
+ evidence.push(kept);
319
+ }
320
+ if (omittedForBound)
321
+ addNote(notes, "Some extras were left out because the install command would be too long.");
322
+ return { extras, evidence, notes, complete };
323
+ }
324
+ /** Read only the target's own `pyproject.toml`, then derive. Never throws. */
325
+ export async function deriveDeclaredExtras(target, learned, readFile) {
326
+ let text;
327
+ try {
328
+ text = await readFile(pyprojectPathFor(target.cwd));
329
+ }
330
+ catch {
331
+ text = null;
332
+ }
333
+ const declared = text === null ? { status: "unknown", reason: "unreadable" } : scanDeclaredExtras(text, target.manager);
334
+ return deriveExtrasFromText(target, declared, learned);
335
+ }
@@ -261,40 +261,92 @@ function makeRow(id, label, state, detail) {
261
261
  ...(state === "healthy" ? {} : { runbook: WORKER_DATABASE_DOCTOR_RUNBOOK_SECTION }),
262
262
  };
263
263
  }
264
- function roleRow(role) {
264
+ /** The configured role, for technical details; a generic phrase when doctor was not told one. */
265
+ function configuredRole(config) {
266
+ // No declaration passed at all (the launch advisory, which still inspects the
267
+ // Bridge seed): keep the wording it always had. The inspector uses the same seed.
268
+ if (config === undefined)
269
+ return "bridge_epic_worker";
270
+ return config.status === "configured" && config.workerRole ? config.workerRole : "the worker role";
271
+ }
272
+ /** An informational row for a check that does not apply. Nothing was probed. */
273
+ function notConfiguredRow(id, label) {
274
+ return {
275
+ ...makeRow(id, label, "healthy", "Not configured — no worker database is expected for this project"),
276
+ not_configured: true,
277
+ };
278
+ }
279
+ /** A row for a declaration that could not be read. Warning treatment; nothing was probed. */
280
+ function unreadableConfigRow(id, label) {
281
+ return makeRow(id, label, "unknown", "Couldn't check — the worker database setting could not be read");
282
+ }
283
+ const NOT_CONFIGURED_LABELS = [
284
+ ["worker-db-role", "worker role"],
285
+ ["worker-db-boundary", "protected-database boundary"],
286
+ ["worker-db-alembic", "operator-checkout Alembic"],
287
+ ["worker-db-leftovers", "worker databases"],
288
+ ["worker-db-unverifiable", "unverifiable worker databases"],
289
+ ["worker-db-harness", "conductor_harness databases"],
290
+ ];
291
+ /** True when the declaration says a disposable database is expected and was read. */
292
+ function isDisposableConfig(config) {
293
+ return config?.status === "configured" && config.mode === "disposable_postgres";
294
+ }
295
+ function roleRow(role, config) {
296
+ if (config?.status === "unreadable")
297
+ return unreadableConfigRow("worker-db-role", "worker role");
298
+ if (config !== undefined && !isDisposableConfig(config))
299
+ return notConfiguredRow("worker-db-role", "worker role");
300
+ const name = configuredRole(config);
265
301
  const r = (role ?? {});
266
302
  let state = safeState(r.state);
267
303
  const category = safeCategory(r.category);
268
304
  let detail;
269
305
  if (state === "healthy") {
270
- detail = "bridge_epic_worker exists with the expected attributes and no elevating memberships";
306
+ detail = `${name} exists with the expected attributes and no elevating memberships`;
271
307
  }
272
308
  else if (state === "unsafe") {
273
309
  detail =
274
310
  category === "role_missing"
275
- ? "bridge_epic_worker does not exist"
276
- : "bridge_epic_worker attributes or memberships differ from the expected least-privilege set";
311
+ ? `${name} does not exist`
312
+ : `${name} attributes or memberships differ from the expected least-privilege set`;
277
313
  }
278
314
  else if (category === "role_missing") {
279
315
  // A definitive "missing" answer is actionable, not unknown.
280
316
  state = "unsafe";
281
- detail = "bridge_epic_worker does not exist";
317
+ detail = `${name} does not exist`;
282
318
  }
283
319
  else {
284
320
  detail = `unknown — ${describeUnavailableCategory(category)}`;
285
321
  }
286
322
  return makeRow("worker-db-role", "worker role", state, detail);
287
323
  }
288
- function boundaryRow(boundary) {
324
+ function boundaryRow(boundary, config) {
325
+ const label = config === undefined ? "bridgeapi boundary" : "protected-database boundary";
326
+ if (config?.status === "unreadable")
327
+ return unreadableConfigRow("worker-db-boundary", label);
328
+ if (config !== undefined && !isDisposableConfig(config))
329
+ return notConfiguredRow("worker-db-boundary", label);
289
330
  const b = (boundary ?? {});
290
331
  const state = safeState(b.state);
291
332
  const category = safeCategory(b.category);
333
+ if (config === undefined) {
334
+ // No declaration passed (the launch advisory still inspects the Bridge seed): the wording it always had.
335
+ const legacy = state === "healthy"
336
+ ? "bridge_epic_worker is refused on bridgeapi"
337
+ : state === "unsafe"
338
+ ? "UNSAFE — bridge_epic_worker can connect to bridgeapi"
339
+ : `unknown — ${category === "boundary_unknown" ? "the bridgeapi refusal could not be confirmed" : describeUnavailableCategory(category)}`;
340
+ return makeRow("worker-db-boundary", label, state, legacy);
341
+ }
342
+ const name = configuredRole(config);
343
+ const protectedNames = config.protectedDatabases.length > 0 ? config.protectedDatabases.join(", ") : "the protected databases";
292
344
  const detail = state === "healthy"
293
- ? "bridge_epic_worker is refused on bridgeapi"
345
+ ? `${name} is refused on ${protectedNames}`
294
346
  : state === "unsafe"
295
- ? "UNSAFE — bridge_epic_worker can connect to bridgeapi"
296
- : `unknown — ${category === "boundary_unknown" ? "the bridgeapi refusal could not be confirmed" : describeUnavailableCategory(category)}`;
297
- return makeRow("worker-db-boundary", "bridgeapi boundary", state, detail);
347
+ ? `UNSAFE — ${name} can connect to a protected database (${protectedNames})`
348
+ : `unknown — ${category === "boundary_unknown" ? "the protected-database refusal could not be confirmed" : describeUnavailableCategory(category)}`;
349
+ return makeRow("worker-db-boundary", label, state, detail);
298
350
  }
299
351
  function alembicRow(alembic) {
300
352
  const a = (alembic ?? {});
@@ -307,8 +359,8 @@ function alembicRow(alembic) {
307
359
  : state === "unsafe"
308
360
  ? cause
309
361
  ? `the operator checkout's offline migration check failed: ${MIGRATION_CAUSE_LABELS[cause]} (cause: ${cause})`
310
- : "the operator checkout's .venv Alembic is missing"
311
- : "unknown — the operator checkout's offline migration check could not be completed";
362
+ : "the operator checkout's migration launcher is missing"
363
+ : "unknown — the operator checkout's offline migration check is not declared or could not be completed";
312
364
  return { ...makeRow("worker-db-alembic", "operator-checkout Alembic", state, detail), ...(cause ? { cause } : {}) };
313
365
  }
314
366
  function safeNameList(value, redacted) {
@@ -404,7 +456,22 @@ function inventoryRows(inventory) {
404
456
  ];
405
457
  }
406
458
  /** Project a (possibly hostile or malformed) inspection into the sanitized advisory section. */
407
- export function buildWorkerDatabaseDoctorSection(inspection) {
459
+ export function buildWorkerDatabaseDoctorSection(inspection, config) {
460
+ // BAPI-1598: a declaration that says no database is expected, or that could not
461
+ // be read, never reaches an inspection — every row says so and nothing is probed.
462
+ if (config !== undefined && !isDisposableConfig(config)) {
463
+ const unreadable = config.status === "unreadable";
464
+ return {
465
+ advisory: true,
466
+ owner: WORKER_DATABASE_DOCTOR_OWNER,
467
+ runbook: WORKER_DATABASE_DOCTOR_RUNBOOK_SECTION,
468
+ rows: NOT_CONFIGURED_LABELS.map(([id, label]) => ({
469
+ ...(unreadable ? unreadableConfigRow(id, label) : notConfiguredRow(id, label)),
470
+ duration_ms: 0,
471
+ })),
472
+ inventory: { state: "unknown" },
473
+ };
474
+ }
408
475
  const insp = (inspection ?? {});
409
476
  const inventory = inspection ? sanitizeInventory(insp.inventory) : { state: "unknown" };
410
477
  return {
@@ -412,8 +479,8 @@ export function buildWorkerDatabaseDoctorSection(inspection) {
412
479
  owner: WORKER_DATABASE_DOCTOR_OWNER,
413
480
  runbook: WORKER_DATABASE_DOCTOR_RUNBOOK_SECTION,
414
481
  rows: [
415
- roleRow(insp.role),
416
- boundaryRow(insp.boundary),
482
+ roleRow(insp.role, config),
483
+ boundaryRow(insp.boundary, config),
417
484
  alembicRow(insp.alembic),
418
485
  ...inventoryRows(inventory),
419
486
  ].map((row) => ({ ...row, duration_ms: inspection?.timings?.[row.id] ?? elapsedMs(monotonicNow()) })),
@@ -429,10 +496,14 @@ export function buildWorkerDatabaseDoctorSection(inspection) {
429
496
  * `timeout`/`error` classification — never the thrown value — so a caller can
430
497
  * say that the inspection failed without echoing exception text.
431
498
  */
432
- export async function collectWorkerDatabaseDoctorSection(inspect, timeoutMs = WORKER_DATABASE_DOCTOR_TIMEOUT_MS, onFailure) {
499
+ export async function collectWorkerDatabaseDoctorSection(inspect, timeoutMs = WORKER_DATABASE_DOCTOR_TIMEOUT_MS, onFailure, config) {
500
+ // BAPI-1598: nothing to inspect when no database is expected or the setting is unreadable.
501
+ if (config !== undefined && !isDisposableConfig(config)) {
502
+ return buildWorkerDatabaseDoctorSection(null, config);
503
+ }
433
504
  const started = monotonicNow();
434
505
  const failedSection = () => {
435
- const section = buildWorkerDatabaseDoctorSection(null);
506
+ const section = buildWorkerDatabaseDoctorSection(null, config);
436
507
  return { ...section, rows: section.rows.map((row) => ({ ...row, duration_ms: elapsedMs(started) })) };
437
508
  };
438
509
  let timer;
@@ -441,10 +512,10 @@ export async function collectWorkerDatabaseDoctorSection(inspect, timeoutMs = WO
441
512
  timer = setTimeout(() => resolve(null), timeoutMs);
442
513
  timer.unref?.();
443
514
  });
444
- const inspection = await Promise.race([Promise.resolve().then(inspect), timeout]);
515
+ const inspection = await Promise.race([Promise.resolve().then(() => inspect(config)), timeout]);
445
516
  if (inspection === null)
446
517
  onFailure?.("timeout");
447
- return inspection === null ? failedSection() : buildWorkerDatabaseDoctorSection(inspection);
518
+ return inspection === null ? failedSection() : buildWorkerDatabaseDoctorSection(inspection, config);
448
519
  }
449
520
  catch {
450
521
  onFailure?.("error");
@@ -477,6 +548,10 @@ export function formatWorkerDatabaseDoctorSection(section) {
477
548
  lines.push("──────────────────────────────────────");
478
549
  for (const row of section.rows) {
479
550
  const state = safeState(row.state);
551
+ if (row.not_configured === true) {
552
+ lines.push(`${row.label.padEnd(30)} [INFO] ${row.detail}`);
553
+ continue;
554
+ }
480
555
  lines.push(`${row.label.padEnd(30)} ${WORKER_DB_STATE_TAG[state]} ${state} — ${row.detail}`);
481
556
  if (state !== "healthy") {
482
557
  lines.push(` → ${WORKER_DATABASE_DOCTOR_OWNER}: see ${WORKER_DATABASE_DOCTOR_RUNBOOK_SECTION}`);
@@ -501,7 +576,8 @@ export function formatWorkerDatabaseDoctorSection(section) {
501
576
  * therefore resolve credentials themselves (CLAUDE.md "Shell-Spawned Credential
502
577
  * Resolution"): the four BAPI-872 recovery verbs, the six run-addressed repair
503
578
  * verbs (BAPI-1154's three and BAPI-1176's three), and BAPI-1300's parked-child
504
- * continuation pair, and BAPI-1557's `prerequisite-inputs`. `.mcp.json` env is invisible to
579
+ * continuation pair, BAPI-1557's `prerequisite-inputs`, and BAPI-1642's driver-supervision
580
+ * commands. `.mcp.json` env is invisible to
505
581
  * them — only `BAPI_API_KEY` in the parent env and the user-scoped credential
506
582
  * store count.
507
583
  */
@@ -523,6 +599,13 @@ export const CREDENTIALED_RECOVERY_COMMANDS = [
523
599
  "wait-run",
524
600
  // BAPI-1557: reads stored tickets and writes private local scanner inputs.
525
601
  "prerequisite-inputs",
602
+ // BAPI-1642: driver supervision. The Stop-hook guard itself resolves nothing;
603
+ // its detached lapse FYI goes through `escalate`.
604
+ "driver-register",
605
+ "driver-release",
606
+ "declare-blocked",
607
+ // BAPI-1682: read-only driver clock report; same shared resolver and launch-profile selection.
608
+ "driver-pass",
526
609
  ];
527
610
  /** Remediation for recovery/repair verbs that cannot resolve Bridge credentials. */
528
611
  export const REPAIR_CREDENTIAL_REMEDIATION = "export BAPI_API_KEY in the shell that runs `conductor`, or store a credential for this " +
@@ -1204,8 +1287,12 @@ export async function buildConductorDoctorReport(deps = {}) {
1204
1287
  const command_drift = deps.inspectCommandDrift
1205
1288
  ? await inspectCommandDriftSafe(deps.inspectCommandDrift)
1206
1289
  : undefined;
1290
+ let workerDatabaseConfig;
1291
+ if (deps.inspectWorkerDatabase && deps.readWorkerDatabaseConfig) {
1292
+ workerDatabaseConfig = await deps.readWorkerDatabaseConfig().catch(() => ({ status: "unreadable" }));
1293
+ }
1207
1294
  const worker_database = deps.inspectWorkerDatabase
1208
- ? await collectWorkerDatabaseDoctorSection(deps.inspectWorkerDatabase, deps.workerDatabaseTimeoutMs ?? WORKER_DATABASE_DOCTOR_TIMEOUT_MS)
1295
+ ? await collectWorkerDatabaseDoctorSection(deps.inspectWorkerDatabase, deps.workerDatabaseTimeoutMs ?? WORKER_DATABASE_DOCTOR_TIMEOUT_MS, undefined, workerDatabaseConfig)
1209
1296
  : undefined;
1210
1297
  return {
1211
1298
  ledger,