@bridge_gpt/mcp-server 0.2.76 → 0.2.77

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 (58) hide show
  1. package/README.md +8 -6
  2. package/build/agents.generated.js +3 -3
  3. package/build/cli-dispatch.js +333 -0
  4. package/build/commands.generated.js +5 -5
  5. package/build/conductor/bridge-api-client.js +52 -7
  6. package/build/conductor/declare-blocked.js +142 -7
  7. package/build/conductor/driver-register.js +8 -2
  8. package/build/conductor/epic-implementer-cli.js +11 -7
  9. package/build/conductor/epic-server-journal.js +39 -22
  10. package/build/conductor/launch-plan.js +28 -7
  11. package/build/conductor/local-merge.js +1 -1
  12. package/build/conductor/readiness-prerequisites.js +89 -2
  13. package/build/conductor/recovery-cli.js +2 -0
  14. package/build/docs.generated.js +67 -4
  15. package/build/doctor.js +97 -1
  16. package/build/drive-epic.js +223 -6
  17. package/build/engine-paths.js +10 -0
  18. package/build/epic-coherence-input-cli.js +105 -10
  19. package/build/epic-coherence-input.js +877 -4
  20. package/build/epic-coherence-input.test-fixtures.js +117 -0
  21. package/build/epic-implementer-bin.js +901 -94
  22. package/build/epic-implementer-env.js +2 -2
  23. package/build/executor/completion-contract.js +14 -1
  24. package/build/executor/guarded-fast-forward-push.js +25 -2
  25. package/build/executor/job-runner.js +83 -27
  26. package/build/executor/likely-tests.js +78 -6
  27. package/build/executor/provider-checks.js +73 -0
  28. package/build/executor/rebase-finalization.js +29 -27
  29. package/build/executor/rename-aside.js +265 -0
  30. package/build/executor/required-work-ledger.js +82 -4
  31. package/build/executor/types.js +121 -0
  32. package/build/executor/worktree.js +27 -1
  33. package/build/index.js +2449 -386
  34. package/build/install-bridge-conductor-assessment.js +13 -0
  35. package/build/install-bridge-conductor.js +60 -776
  36. package/build/install-bridge.js +4 -11
  37. package/build/language-catalog.generated.js +2649 -0
  38. package/build/pipelines.generated.js +45 -17
  39. package/build/plan-execution-ledger.js +8 -0
  40. package/build/plan-generation.js +34 -0
  41. package/build/plane/build-freshness.js +6 -0
  42. package/build/plane/cli.js +12 -5
  43. package/build/printed-remedy-commands.js +9 -0
  44. package/build/readiness-prerequisites.generated.js +28 -0
  45. package/build/readme.generated.js +1 -1
  46. package/build/run-unit-tests-launcher.js +3 -1
  47. package/build/server.js +7946 -0
  48. package/build/start-tickets-prereqs.js +3 -6
  49. package/build/test-support/console-guard.js +30 -0
  50. package/build/test-support/module-imports.js +155 -0
  51. package/build/test-support/server-client.js +96 -0
  52. package/build/test-support/stdio-server.js +146 -0
  53. package/build/v2-readiness-requirements.js +31 -2
  54. package/build/version.generated.js +3 -3
  55. package/docs/EPIC-IMPLEMENTER.md +71 -2
  56. package/docs/epic-implementer/getting-started.md +4 -0
  57. package/package.json +3 -3
  58. package/pipelines/learn-repository.json +19 -1
@@ -0,0 +1,333 @@
1
+ /**
2
+ * CLI subcommand dispatch for the `bridge-api-mcp-server` bin.
3
+ *
4
+ * `index.ts` calls `dispatchCliSubcommand(process.argv.slice(2))` before the MCP
5
+ * server module is loaded. A non-null result is the exit code; `null` means
6
+ * start the server. `resolveCliRoute` is the pure routing decision, so tests can
7
+ * check the order of the routes without running any of them.
8
+ */
9
+ import { runRepairAssetsCli } from "./repair-assets.js";
10
+ import { stat } from "fs/promises";
11
+ import { VERSION, BUILD_COMMIT } from "./version.generated.js";
12
+ import { getTopLevelCliUsage } from "./cli-help.js";
13
+ import { InitPreflightError, runInit } from "./init.js";
14
+ import { runStartTicketsCli } from "./start-tickets.js";
15
+ import { runReviewTicketsCli } from "./review-tickets.js";
16
+ import { runBridgePermissionsCliFromProcess } from "./bridge-permissions.js";
17
+ import { runDoctorCli } from "./doctor.js";
18
+ import { runMcpInvokeCli } from "./mcp-invoke.js";
19
+ import { runWithCredentialsCli } from "./with-credentials.js";
20
+ import { runAgentCapabilitiesCli } from "./agent-capabilities/cli.js";
21
+ import { runExecutorCli, runExecutorInstallServiceCli } from "./executor/index.js";
22
+ import { runExecutorWatchCli } from "./executor/watch-cli.js";
23
+ import { runSetupEpicCli } from "./setup-epic.js";
24
+ import { runDriveEpicCli } from "./drive-epic.js";
25
+ import { runPlaneCli } from "./plane/cli.js";
26
+ import { runEpicImplementerBundleCli } from "./epic-implementer-bundle-cli.js";
27
+ import { runEpicPlanCli } from "./authored-plan.js";
28
+ import { runEpicCoherenceInputCli } from "./epic-coherence-input-cli.js";
29
+ import { runRegressionCheckCli } from "./regression-check.js";
30
+ import { runNotificationsCli } from "./notifications.js";
31
+ import { buildInstallBridgeFailureLines, INSTALL_BRIDGE_DISPATCH_STEP_LABEL, INSTALL_BRIDGE_NO_GIT_PROMPT, INSTALL_BRIDGE_NO_GIT_ABORT, INSTALL_BRIDGE_NO_GIT_NONINTERACTIVE_WARNING, promptLineViaReadline, } from "./install-bridge.js";
32
+ import { hasProjectRootMarker } from "./project-root.js";
33
+ import { runInstallBridgeWithLatestCli } from "./install-reexec.js";
34
+ import { runConnectGithubCli } from "./connect-github.js";
35
+ import { runConnectBitbucketCli } from "./connect-bitbucket.js";
36
+ import { runUpgradeCli } from "./upgrade-cli.js";
37
+ import { runCredentialsCli } from "./credentials-cli.js";
38
+ import { runEpicImplementerCli } from "./conductor/epic-implementer-cli.js";
39
+ import { runCheckUpdateCli } from "./check-update-cli.js";
40
+ function createDefaultRunInitCliDeps() {
41
+ const isTTY = Boolean(process.stdin.isTTY);
42
+ return {
43
+ stat,
44
+ isTTY,
45
+ promptLine: isTTY ? promptLineViaReadline : undefined,
46
+ // BAPI-668/BAPI-818: index.ts writes NO diagnostic to stdout other than the
47
+ // `--version` exception — stdout carries the MCP stdio protocol once the
48
+ // server starts, and every dispatched CLI subcommand's own output goes to
49
+ // stderr uniformly regardless of success/failure. `log` follows that
50
+ // convention rather than `install`'s own `log` (which targets stdout).
51
+ log: (line) => console.error(line),
52
+ errorLog: (line) => console.error(line),
53
+ runInit,
54
+ };
55
+ }
56
+ /**
57
+ * Run the ``--init`` scaffolding flow. Returns a process exit code.
58
+ *
59
+ * BAPI-818 (R1): `--init` used to hard-require a `package.json` — a guard
60
+ * inherited from the old inline `--upgrade`, which genuinely ran
61
+ * `npm i @bridge_gpt/mcp-server@latest` and so genuinely needed one. `--upgrade`
62
+ * was rebuilt (BAPI-430/728) to stop needing a manifest at all, and `--init`'s
63
+ * own scaffolding (`runInit`) never read `package.json` in the first place — so
64
+ * the requirement was stale, not load-bearing, and blocked every non-Node
65
+ * repository (SFCC cartridges, Python, Go, Rust, polyglot monorepos) from the
66
+ * documented manual setup path. `--init` now shares ONE project-root definition
67
+ * with `install` (`project-root.ts`'s `.git` probe) and the SAME missing-marker
68
+ * confirmation policy — same prompt text, same default-No, same non-interactive
69
+ * warn-and-continue, same TTY/non-TTY exit semantics.
70
+ */
71
+ export async function runInitCli(cwd, overrides = {}) {
72
+ const deps = { ...createDefaultRunInitCliDeps(), ...overrides };
73
+ if (!(await hasProjectRootMarker(cwd, deps.stat))) {
74
+ if (deps.isTTY && deps.promptLine) {
75
+ let answer = "";
76
+ try {
77
+ answer = (await deps.promptLine(INSTALL_BRIDGE_NO_GIT_PROMPT)).trim().toLowerCase();
78
+ }
79
+ catch {
80
+ // A prompt that cannot be read is NOT confirmation. Never infer it — the
81
+ // default is No, so a malformed or failed read takes the abort path.
82
+ answer = "";
83
+ }
84
+ if (answer !== "y" && answer !== "yes") {
85
+ deps.log(INSTALL_BRIDGE_NO_GIT_ABORT);
86
+ // Exit 0: the user cancelled, and nothing was resolved, written, or spent.
87
+ return 0;
88
+ }
89
+ }
90
+ else {
91
+ // Automation compatibility: warn, never prompt, never abort.
92
+ deps.errorLog(INSTALL_BRIDGE_NO_GIT_NONINTERACTIVE_WARNING);
93
+ }
94
+ }
95
+ try {
96
+ // BAPI-728: a run that scaffolded successfully but produced a config that
97
+ // authenticates as nobody is NOT a success. `runInit` already printed the
98
+ // path-specific warning; exiting non-zero stops a caller (or a CI step) from
99
+ // treating "files were written" as "the MCP is configured".
100
+ const result = await deps.runInit(cwd);
101
+ return result.ok ? 0 : 1;
102
+ }
103
+ catch (err) {
104
+ // A deliberate preflight refusal is safe to show and the user needs it: each
105
+ // failure is a repo-relative path plus a reason from init's fixed table.
106
+ if (err instanceof InitPreflightError) {
107
+ deps.errorLog("Bridge API --init failed: these MCP launcher configs cannot be safely reconciled:");
108
+ for (const failure of err.failures)
109
+ deps.errorLog(` ${failure.relPath}: ${failure.reason}`);
110
+ return 1;
111
+ }
112
+ // Any other thrown message can carry a credential or a path, so it is never printed:
113
+ // only a fixed line plus the error's class name and, when it is a short
114
+ // identifier, its code.
115
+ deps.errorLog(`Bridge API --init failed: an unexpected error occurred (${describeInitError(err)}).`);
116
+ return 1;
117
+ }
118
+ }
119
+ /** The class name and a safe `code` of a thrown value, never its message. */
120
+ function describeInitError(err) {
121
+ const name = err instanceof Error && /^[A-Za-z][A-Za-z0-9_]{0,63}$/.test(err.name) ? err.name : "unknown error";
122
+ const code = err?.code;
123
+ return typeof code === "string" && /^[A-Z][A-Z0-9_]{0,31}$/.test(code) ? `${name}, ${code}` : name;
124
+ }
125
+ // Positional subcommands that take the rest of argv after their one token, in
126
+ // routing order. The executor sub-verbs and the renamed tokens are matched
127
+ // separately in `resolveCliRoute` at their place in this order.
128
+ const EXECUTOR_SUBVERBS = ["watch", "install-service", "uninstall-service"];
129
+ /**
130
+ * Decide which route `argv` takes, without running anything. `null` means
131
+ * start the MCP server (a bare run, or `serve`).
132
+ *
133
+ * The order is the contract:
134
+ * - `repair-assets` first, then `--help` / `-h` (only when it is the only token).
135
+ * - Every positional subcommand before the flag checks.
136
+ * - `executor watch|install-service|uninstall-service` before plain `executor`,
137
+ * which would otherwise reject the sub-verb as an unknown argument.
138
+ * - `emit-conductor-bundle` and bare `conductor` are renamed tokens: they fail
139
+ * with a pointer and never reach the renamed command.
140
+ * - `install` and its legacy spelling `install-bridge` share one route, the only
141
+ * one that reaches the npm registry.
142
+ * - `serve` drops its own token and keeps going, so `serve` alone starts the
143
+ * server and `serve --version` prints the version.
144
+ * - `--version`, then `--init` (wins over `--upgrade`), then `--upgrade`.
145
+ * - Any other positional token is rejected last.
146
+ */
147
+ export function resolveCliRoute(argv) {
148
+ const first = argv[0];
149
+ const rest = argv.slice(1);
150
+ if (first === "repair-assets")
151
+ return { id: "repair-assets", args: rest };
152
+ if (argv.length === 1 && (first === "--help" || first === "-h"))
153
+ return { id: "help", args: [] };
154
+ switch (first) {
155
+ case "start-tickets":
156
+ case "review-tickets":
157
+ case "mcp-invoke":
158
+ case "with-credentials":
159
+ case "check-update":
160
+ case "doctor":
161
+ case "bridge-permissions":
162
+ case "agent-capabilities":
163
+ case "notifications":
164
+ return { id: first, args: rest };
165
+ }
166
+ if (first === "executor" && EXECUTOR_SUBVERBS.includes(argv[1] ?? "")) {
167
+ return { id: `executor ${argv[1]}`, args: argv.slice(2) };
168
+ }
169
+ switch (first) {
170
+ case "worktrees":
171
+ case "executor":
172
+ case "setup-epic":
173
+ case "drive-epic":
174
+ case "plane":
175
+ return { id: first, args: rest };
176
+ case "emit-conductor-bundle":
177
+ return { id: "emit-conductor-bundle (renamed)", args: rest };
178
+ case "emit-epic-implementer-bundle":
179
+ case "epic-plan":
180
+ case "regression-check":
181
+ case "epic-coherence-input":
182
+ case "credentials":
183
+ return { id: first, args: rest };
184
+ case "conductor":
185
+ return { id: "conductor (renamed)", args: rest };
186
+ case "epic-implementer":
187
+ return { id: first, args: rest };
188
+ case "install-bridge":
189
+ case "install":
190
+ return { id: "install", args: rest };
191
+ case "connect-github":
192
+ case "connect-bitbucket":
193
+ case "upgrade":
194
+ return { id: first, args: rest };
195
+ }
196
+ const flags = first === "serve" ? rest : argv.slice();
197
+ if (flags.includes("--version"))
198
+ return { id: "--version", args: [] };
199
+ if (flags.includes("--init"))
200
+ return { id: "--init", args: [] };
201
+ // --upgrade passes every argument on, so flags like --dry-run are forwarded.
202
+ if (flags.includes("--upgrade"))
203
+ return { id: "--upgrade", args: flags };
204
+ if (flags.length > 0 && !flags[0].startsWith("-"))
205
+ return { id: "unknown-subcommand", args: [flags[0]] };
206
+ return null;
207
+ }
208
+ async function writeStdout(text) {
209
+ await new Promise((resolve, reject) => {
210
+ process.stdout.write(text, (error) => {
211
+ if (error) {
212
+ reject(error);
213
+ return;
214
+ }
215
+ resolve();
216
+ });
217
+ });
218
+ }
219
+ /**
220
+ * Run one resolved route and return its exit code. Every route writes its own
221
+ * diagnostics to stderr; only `--help`, `--version` and the subcommands that own
222
+ * their stdout write there.
223
+ */
224
+ export async function runCliRoute(route) {
225
+ const { args } = route;
226
+ switch (route.id) {
227
+ case "repair-assets":
228
+ return runRepairAssetsCli(args);
229
+ case "help":
230
+ await writeStdout(getTopLevelCliUsage());
231
+ return 0;
232
+ case "start-tickets":
233
+ return runStartTicketsCli(args);
234
+ case "review-tickets":
235
+ return runReviewTicketsCli(args);
236
+ case "mcp-invoke":
237
+ return runMcpInvokeCli(args);
238
+ case "with-credentials":
239
+ return runWithCredentialsCli(args);
240
+ case "check-update":
241
+ return runCheckUpdateCli(args);
242
+ case "doctor":
243
+ return runDoctorCli(args);
244
+ case "bridge-permissions":
245
+ return runBridgePermissionsCliFromProcess(args);
246
+ case "agent-capabilities":
247
+ return runAgentCapabilitiesCli(args);
248
+ case "notifications":
249
+ return runNotificationsCli(args);
250
+ case "executor watch":
251
+ return runExecutorWatchCli(args);
252
+ case "executor install-service":
253
+ return runExecutorInstallServiceCli(args);
254
+ case "executor uninstall-service": {
255
+ const { runExecutorUninstallServiceCli } = await import("./executor/service-uninstall.js");
256
+ return runExecutorUninstallServiceCli(args);
257
+ }
258
+ case "worktrees": {
259
+ const { runWorktreesCli } = await import("./worktrees.js");
260
+ return runWorktreesCli(args);
261
+ }
262
+ case "executor":
263
+ return runExecutorCli(args);
264
+ case "setup-epic":
265
+ return runSetupEpicCli(args);
266
+ case "drive-epic":
267
+ return runDriveEpicCli(args);
268
+ case "plane":
269
+ return runPlaneCli(args);
270
+ case "emit-conductor-bundle (renamed)":
271
+ process.stderr.write("'emit-conductor-bundle' was renamed to 'emit-epic-implementer-bundle'. Run 'emit-epic-implementer-bundle ...' instead.\n");
272
+ return 1;
273
+ case "emit-epic-implementer-bundle":
274
+ return runEpicImplementerBundleCli(args);
275
+ case "epic-plan":
276
+ return runEpicPlanCli(args);
277
+ case "regression-check":
278
+ return runRegressionCheckCli(args);
279
+ case "epic-coherence-input":
280
+ return runEpicCoherenceInputCli(args);
281
+ case "credentials":
282
+ return runCredentialsCli(args);
283
+ case "conductor (renamed)":
284
+ process.stderr.write("'conductor' was renamed to 'epic-implementer'. Run 'epic-implementer ...' instead.\n");
285
+ return 1;
286
+ case "epic-implementer":
287
+ return runEpicImplementerCli(args);
288
+ case "install":
289
+ // BAPI-668: a last-resort catch scoped to the installer only, so a
290
+ // first-time user never sees a raw Node stack. It uses the same
291
+ // secret-safe formatter as the installer; the raw message appears only
292
+ // under BAPI_INSTALL_DEBUG. Not a process-global handler: that would hide
293
+ // real server runtime failures.
294
+ try {
295
+ return await runInstallBridgeWithLatestCli(args);
296
+ }
297
+ catch (error) {
298
+ const lines = buildInstallBridgeFailureLines(error, {
299
+ step: INSTALL_BRIDGE_DISPATCH_STEP_LABEL,
300
+ debugEnabled: Boolean(process.env.BAPI_INSTALL_DEBUG),
301
+ });
302
+ for (const line of lines)
303
+ console.error(line);
304
+ return 1;
305
+ }
306
+ case "connect-github":
307
+ return runConnectGithubCli(args);
308
+ case "connect-bitbucket":
309
+ return runConnectBitbucketCli(args);
310
+ case "upgrade":
311
+ return runUpgradeCli(args);
312
+ case "--version":
313
+ // BAPI-873: the first line stays the bare semver (a parsed contract); the
314
+ // build commit is on a labelled second line.
315
+ console.log(`${VERSION}\ncommit: ${BUILD_COMMIT}`);
316
+ return 0;
317
+ case "--init":
318
+ return runInitCli(process.cwd());
319
+ case "--upgrade":
320
+ return runUpgradeCli(args);
321
+ case "unknown-subcommand":
322
+ console.error(`Error: Unknown subcommand '${args[0]}'. Run with --help for usage, or omit subcommands to start the MCP server.`);
323
+ return 1;
324
+ }
325
+ }
326
+ /**
327
+ * Route CLI subcommands before MCP server startup. Returns an exit code to exit
328
+ * the process with, or `null` to continue to normal MCP server startup.
329
+ */
330
+ export async function dispatchCliSubcommand(argv) {
331
+ const route = resolveCliRoute(argv);
332
+ return route === null ? null : runCliRoute(route);
333
+ }