@bridge_gpt/mcp-server 0.2.52 → 0.2.53

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.
@@ -20,6 +20,7 @@
20
20
  * required prerequisites only.
21
21
  */
22
22
  import path from "path";
23
+ import { createReadinessCheck, createReadinessCheckSafely, } from "./readiness-check.js";
23
24
  import { resolveBapiCredentials } from "./credential-store.js";
24
25
  import { detectClaudeLogin, formatClaudeLoginAdvisory } from "./claude-login.js";
25
26
  import { getProjectJsonTargets, hostAdapterForTarget } from "./mcp-host-targets.js";
@@ -105,7 +106,16 @@ export async function resolveInstallDoctorTarget(deps) {
105
106
  }
106
107
  return { repoName, repoSource, baseUrl: baseUrl ?? DEFAULT_BASE_URL };
107
108
  }
108
- /** Read-only GET with a bounded timeout. Never throws. */
109
+ /** Classify a thrown probe failure into the closed category vocabulary. */
110
+ function classifyProbeFailure(error) {
111
+ // `AbortSignal.timeout` rejects with a DOMException named `TimeoutError`;
112
+ // fall back to the name check so a polyfilled or wrapped abort still reads as
113
+ // a timeout rather than as a generic failure.
114
+ const name = error?.name;
115
+ return name === "TimeoutError" || name === "AbortError"
116
+ ? "request timed out"
117
+ : "request unavailable";
118
+ }
109
119
  async function probeGet(deps, url, apiKey) {
110
120
  try {
111
121
  const resp = await deps.fetch(url, {
@@ -122,7 +132,7 @@ async function probeGet(deps, url, apiKey) {
122
132
  return { ok: true, status: resp.status, body };
123
133
  }
124
134
  catch (e) {
125
- return { ok: false, error: e instanceof Error ? e.message : String(e) };
135
+ return { ok: false, error: classifyProbeFailure(e) };
126
136
  }
127
137
  }
128
138
  /** Count set/total bootstrap fields from an install-manifest response body. */
@@ -300,6 +310,8 @@ export async function collectInstallStatusChecks(deps) {
300
310
  label: "Server connectivity",
301
311
  status: "WARN",
302
312
  detail: `unexpected HTTP ${ping.status} from /jira/ping`,
313
+ remediation: "the server answered but not with a status this check understands — re-run doctor; " +
314
+ "if it persists the Bridge API is unhealthy and no install fact below can be trusted.",
303
315
  });
304
316
  }
305
317
  // --- bootstrap fields ---
@@ -310,6 +322,7 @@ export async function collectInstallStatusChecks(deps) {
310
322
  label: "Bootstrap config fields",
311
323
  status: "WARN",
312
324
  detail: `manifest unreachable (${manifest.error})`,
325
+ remediation: `check ${target.baseUrl} and your network, then re-run doctor.`,
313
326
  });
314
327
  }
315
328
  else if (manifest.status === 404) {
@@ -329,6 +342,8 @@ export async function collectInstallStatusChecks(deps) {
329
342
  label: "Bootstrap config fields",
330
343
  status: "WARN",
331
344
  detail: "manifest response had an unexpected shape",
345
+ remediation: "the manifest could not be read, so no bootstrap field state is known — re-run doctor, " +
346
+ "then run /install-bridge to re-derive the project configuration.",
332
347
  });
333
348
  }
334
349
  else if (summary.unset.length === 0) {
@@ -355,6 +370,8 @@ export async function collectInstallStatusChecks(deps) {
355
370
  label: "Bootstrap config fields",
356
371
  status: "WARN",
357
372
  detail: `unexpected HTTP ${manifest.status} from the install manifest`,
373
+ remediation: "the manifest endpoint answered with an unrecognized status — re-run doctor; " +
374
+ "if it persists, re-run /install-bridge for this repository.",
358
375
  });
359
376
  }
360
377
  // --- integrations (from the same manifest response; presence booleans only) ---
@@ -509,3 +526,138 @@ export function formatInstallStatusFallbackReport() {
509
526
  },
510
527
  ]);
511
528
  }
529
+ // ---------------------------------------------------------------------------
530
+ // Canonical readiness projection (BAPI-1055)
531
+ // ---------------------------------------------------------------------------
532
+ /**
533
+ * The complete install-side prerequisite set, in render order.
534
+ *
535
+ * A STABLE descriptor set, not a projection of whatever the collector happened
536
+ * to return. `collectInstallStatusChecks` returns early on an unresolved
537
+ * identity and again on an unresolved credential, so the checks it omits simply
538
+ * never appear — and a locus that vanished reads as "nothing to report" rather
539
+ * than "this could not be established". The adapter walks this list instead, so
540
+ * every prerequisite is always represented.
541
+ */
542
+ export const INSTALL_READINESS_DESCRIPTORS = [
543
+ { id: "claude-login", label: "Claude login" },
544
+ { id: "identity", label: "Repository identity" },
545
+ { id: "credential", label: "Bridge API credential" },
546
+ { id: "connectivity", label: "Server connectivity" },
547
+ { id: "bootstrap", label: "Bootstrap config fields" },
548
+ { id: "integrations", label: "Integration credentials" },
549
+ { id: "github", label: "GitHub connection" },
550
+ { id: "indexing", label: "Repository indexing" },
551
+ ];
552
+ /** Fixed remediation for an install prerequisite whose identity never resolved. */
553
+ export const INSTALL_IDENTITY_REMEDIATION = "run /install-bridge (or set BAPI_REPO_NAME) to configure this project; without a repository " +
554
+ "identity no server-side conductor fact can be resolved.";
555
+ /** Fixed remediation for the advisory Claude-login gap. */
556
+ export const INSTALL_CLAUDE_LOGIN_REMEDIATION = "run `claude login` on the host that will run conductor workers; Bridge stores no Anthropic " +
557
+ "credential and cannot confirm this for you.";
558
+ /** Fixed detail for a prerequisite the checklist stopped short of collecting. */
559
+ const INSTALL_NOT_COLLECTED_DETAIL = "not collected — an earlier install prerequisite stopped the checklist";
560
+ /** Fixed detail for a prerequisite whose whole collector could not be run. */
561
+ const INSTALL_UNAVAILABLE_DETAIL = "unknown — the install-status checklist could not be collected at all";
562
+ /** Fixed remediation for a prerequisite whose whole collector could not be run. */
563
+ const INSTALL_UNAVAILABLE_REMEDIATION = "run `doctor` to collect the advisory install-status checklist directly; this prerequisite's " +
564
+ "state is unknown, not healthy.";
565
+ /**
566
+ * How each install check's non-canonical statuses project (BAPI-1055).
567
+ *
568
+ * `INFO` never becomes a canonical status, and `SKIP` is not automatically
569
+ * `skip`: an unresolved repository identity is reported as `SKIP` by the
570
+ * collector because the checklist stops there, but it is a genuine unmet
571
+ * prerequisite, so it maps to `fail`. The mapping is therefore stated per check
572
+ * id rather than derived from the source status alone.
573
+ */
574
+ function projectInstallStatus(check) {
575
+ if (check.status === "PASS")
576
+ return { status: "pass" };
577
+ if (check.status === "WARN") {
578
+ return { status: "warn", ...(check.remediation ? { remediation: check.remediation } : {}) };
579
+ }
580
+ if (check.status === "INFO") {
581
+ // `claude-login` INFO means "no local login marker found". That is an
582
+ // actionable conductor gap — a worker cannot run without it — so it warns.
583
+ if (check.id === "claude-login") {
584
+ return { status: "warn", remediation: INSTALL_CLAUDE_LOGIN_REMEDIATION };
585
+ }
586
+ // `indexing` INFO is genuinely informational in both of its branches (a
587
+ // parse running, or none running). Neither is a prerequisite gap, so the
588
+ // information rides on `detail` and the check passes.
589
+ return { status: "pass" };
590
+ }
591
+ // SKIP.
592
+ if (check.id === "identity") {
593
+ // Unknown identity is never a successful or guessed repository context.
594
+ return { status: "fail", remediation: check.remediation ?? INSTALL_IDENTITY_REMEDIATION };
595
+ }
596
+ return { status: "skip", ...(check.remediation ? { remediation: check.remediation } : {}) };
597
+ }
598
+ /**
599
+ * Project the install-status checklist into canonical readiness checks.
600
+ *
601
+ * PURE: no probe, no I/O, no re-derivation. Ids are namespaced `install.<id>`
602
+ * so provenance survives into a consolidated report without being encoded in
603
+ * display prose, and only the collector's own fixed labels, bounded details, and
604
+ * authored remediations are carried across.
605
+ */
606
+ export function mapInstallStatusChecksToReadinessChecks(checks,
607
+ /**
608
+ * True when the COLLECTOR itself could not run, as opposed to running and
609
+ * stopping early.
610
+ *
611
+ * `null` alone cannot tell those apart, and they are not the same fact. A
612
+ * checklist that ran and returned early leaves its later prerequisites
613
+ * genuinely dependent — a `skip`. A checklist that never ran leaves them
614
+ * simply unknown, and unknown must never read as healthy, so they fail with a
615
+ * restoring remediation instead.
616
+ */
617
+ collectorUnavailable = false) {
618
+ const byId = new Map();
619
+ for (const check of checks ?? []) {
620
+ // First writer wins: the collector emits each id once, and a duplicate from
621
+ // an injected fake must not silently replace the real finding.
622
+ if (!byId.has(check.id))
623
+ byId.set(check.id, check);
624
+ }
625
+ return INSTALL_READINESS_DESCRIPTORS.map(({ id, label }) => {
626
+ const source = byId.get(id);
627
+ if (!source) {
628
+ return collectorUnavailable
629
+ ? createReadinessCheck({
630
+ id: `install.${id}`,
631
+ source: "install",
632
+ label,
633
+ status: "fail",
634
+ detail: INSTALL_UNAVAILABLE_DETAIL,
635
+ remediation: INSTALL_UNAVAILABLE_REMEDIATION,
636
+ })
637
+ : // Absent because the checklist never got this far. A dependency case,
638
+ // so `skip` — the prerequisite that stopped the chain carries the fix.
639
+ createReadinessCheck({
640
+ id: `install.${id}`,
641
+ source: "install",
642
+ label,
643
+ status: "skip",
644
+ detail: INSTALL_NOT_COLLECTED_DETAIL,
645
+ });
646
+ }
647
+ const projected = projectInstallStatus(source);
648
+ return createReadinessCheckSafely({
649
+ id: `install.${id}`,
650
+ source: "install",
651
+ label: source.label || label,
652
+ status: projected.status,
653
+ ...(source.detail ? { detail: source.detail } : {}),
654
+ ...(projected.status === "pass"
655
+ ? {}
656
+ : projected.remediation
657
+ ? { remediation: projected.remediation }
658
+ : projected.status === "fail"
659
+ ? { remediation: INSTALL_IDENTITY_REMEDIATION }
660
+ : {}),
661
+ });
662
+ });
663
+ }