nulladrift 0.1.0 → 0.1.1

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.
package/dist/index.js CHANGED
@@ -270,6 +270,11 @@ async function readJsonIfPresent(path) {
270
270
  return { present: true, ok: false, reason: `not valid JSON: ${error.message}` };
271
271
  }
272
272
  }
273
+ function anchorCwd(server2, projectRoot) {
274
+ const { transport: transport2 } = server2;
275
+ if (transport2.type !== "stdio" || transport2.cwd === void 0 || isAbsolute(transport2.cwd)) return server2;
276
+ return { ...server2, transport: { ...transport2, cwd: resolve2(projectRoot, transport2.cwd) } };
277
+ }
273
278
  async function discoverServers(projectRoot, extraFiles = []) {
274
279
  const context = { workspaceFolder: projectRoot, env: process.env };
275
280
  const files = [
@@ -301,7 +306,7 @@ async function discoverServers(projectRoot, extraFiles = []) {
301
306
  }
302
307
  const parsed = file.client === "claude-code" && file.scope === "user" ? await parseClaudeJson(raw, projectRoot, source, context) : await parseServerMap(raw, mapKey, { ...source, scope: file.scope }, context);
303
308
  skipped.push(...parsed.skipped);
304
- for (const server2 of parsed.servers) {
309
+ for (const server2 of parsed.servers.map((entry) => anchorCwd(entry, projectRoot))) {
305
310
  const existing = byName2.get(server2.name);
306
311
  if (existing) {
307
312
  shadowed.push({ name: server2.name, keptFrom: existing.from, alsoIn: source.file });
@@ -649,7 +654,7 @@ import { dirname, join as join2 } from "path";
649
654
  import { ClientCredentialsProvider, UnauthorizedError } from "@modelcontextprotocol/client";
650
655
 
651
656
  // src/lib/version.ts
652
- var VERSION = "0.1.0";
657
+ var VERSION = "0.1.1";
653
658
  var USER_AGENT = `nulladrift/${VERSION}`;
654
659
 
655
660
  // src/mcp/oauth.ts
@@ -820,6 +825,17 @@ var UnreachableServerError = class extends Error {
820
825
  serverName;
821
826
  cause;
822
827
  };
828
+ function authFailureKind(error) {
829
+ if (!isAuthFailure(error)) return void 0;
830
+ const text = `${error instanceof Error ? error.message : String(error)}`.toLowerCase();
831
+ const cause = error instanceof UnreachableServerError && error.cause instanceof Error ? error.cause.message.toLowerCase() : "";
832
+ const both = `${text} ${cause}`;
833
+ const scoped = [error, error instanceof UnreachableServerError ? error.cause : void 0].some(
834
+ (candidate) => candidate instanceof Error && candidate.name === "InsufficientScopeError"
835
+ );
836
+ if (scoped || /\b403\b|forbidden|insufficient[_ ]scope/.test(both)) return "forbidden";
837
+ return "auth";
838
+ }
823
839
  function isAuthFailure(error) {
824
840
  if (error instanceof UnauthorizedError2) return true;
825
841
  if (error instanceof Error && error.name === "InteractiveAuthRequiredError") return true;
@@ -830,7 +846,9 @@ function isAuthFailure(error) {
830
846
  const name = candidate instanceof Error ? candidate.name : "";
831
847
  if (name === "RegistrationRejectedError" || name === "InsufficientScopeError" || name === "OAuthClientFlowError") return true;
832
848
  }
833
- const text = `${error instanceof Error ? error.message : String(error)}`.toLowerCase();
849
+ const outer = `${error instanceof Error ? error.message : String(error)}`;
850
+ const inner = error instanceof UnreachableServerError && error.cause instanceof Error ? error.cause.message : "";
851
+ const text = `${outer} ${inner}`.toLowerCase();
834
852
  return /\b(401|403)\b|unauthorized|forbidden|invalid or missing.*token|authentication required|invalid_client|dynamic client registration/.test(text);
835
853
  }
836
854
 
@@ -860,6 +878,12 @@ function buildTransport(server2, captureStderr = () => {
860
878
  if (transport2.type === "sse") return new SSEClientTransport(url, { requestInit: { headers }, authProvider });
861
879
  return new StreamableHTTPClientTransport(url, { requestInit: { headers }, authProvider });
862
880
  }
881
+ function diagnosticLines(stderr, limit = 3) {
882
+ const lines = stderr.split("\n").map((line) => line.trimEnd()).filter((line) => line.trim().length > 0).filter((line) => !/^\s*(at\s|\^+$|[}\])]+$|Node\.js v[\d.]+$)/.test(line));
883
+ const named = lines.filter((line) => /\b(error|exception|cannot|failed|refused|denied|not found|enoent|eacces)\b/i.test(line));
884
+ const chosen = named.length > 0 ? named : lines;
885
+ return chosen.slice(0, limit).map((line) => line.trim());
886
+ }
863
887
  async function connect(server2, timeoutMs = DEFAULT_TIMEOUT_MS, options = {}) {
864
888
  let stderrBuffer = "";
865
889
  const captureStderr = (chunk) => {
@@ -891,7 +915,7 @@ async function connect(server2, timeoutMs = DEFAULT_TIMEOUT_MS, options = {}) {
891
915
  throw new UnreachableServerError(
892
916
  server2.name,
893
917
  `${error.message}${detail ? `
894
- server stderr: ${detail.split("\n").slice(-3).join("\n ")}` : ""}`,
918
+ server stderr: ${diagnosticLines(detail).join("\n ")}` : ""}`,
895
919
  error
896
920
  );
897
921
  }
@@ -987,7 +1011,7 @@ async function captureAll(options) {
987
1011
  } catch (error) {
988
1012
  options.onServerDone?.(server2.name, "failed");
989
1013
  const reason = error instanceof UnreachableServerError ? error.message : error.message;
990
- const kind = isAuthFailure(error) ? "auth" : "unreachable";
1014
+ const kind = authFailureKind(error) ?? "unreachable";
991
1015
  return { name: server2.name, failure: { server: server2.name, reason, kind } };
992
1016
  }
993
1017
  });
@@ -1743,7 +1767,7 @@ function renderHumanReport(report) {
1743
1767
  if (report.unreachable.length > 0) {
1744
1768
  lines.push(bold(`Could not audit ${report.unreachable.length} server(s):`), "");
1745
1769
  for (const failure of report.unreachable) {
1746
- const label = failure.kind === "auth" ? yellow("needs creds") : red("unreachable");
1770
+ const label = failure.kind === "auth" ? yellow("needs creds") : failure.kind === "forbidden" ? yellow("not permitted") : red("unreachable");
1747
1771
  lines.push(` ${label} ${bold(failure.server)}`, ` ${failure.reason}`, "");
1748
1772
  }
1749
1773
  }
@@ -1762,9 +1786,17 @@ function renderHumanReport(report) {
1762
1786
  lines.push(dim("A server that cannot be checked fails the audit. Use --allow-unreachable to downgrade that to a warning."));
1763
1787
  if (report.unreachable.some((failure) => failure.kind === "auth")) {
1764
1788
  lines.push(
1765
- dim("`needs creds` means the server refused this client, not that it is down. The tool list a"),
1766
- dim("server shows may depend on who is asking, so auditing without them would pin the wrong"),
1767
- dim("surface. Run `nulladrift login <server>` once, or set oauth.clientId/clientSecret for CI.")
1789
+ dim("`needs creds` means the server would not accept this client, not that it is down. The tool"),
1790
+ dim("list a server shows may depend on who is asking, so auditing without credentials would pin"),
1791
+ dim("the wrong surface. Run `nulladrift login <server>` once, or set oauth.clientId/clientSecret"),
1792
+ dim("for CI.")
1793
+ );
1794
+ }
1795
+ if (report.unreachable.some((failure) => failure.kind === "forbidden")) {
1796
+ lines.push(
1797
+ dim("`not permitted` means your credentials were accepted and refused. Running `nulladrift login`"),
1798
+ dim("again will not change that. Check the server URL for an organization or project you do not"),
1799
+ dim("belong to, and whether the grant covers that resource.")
1768
1800
  );
1769
1801
  }
1770
1802
  }
@@ -1882,6 +1914,11 @@ function renderSarifReport(report) {
1882
1914
  }
1883
1915
 
1884
1916
  // src/report/markdown.ts
1917
+ var AUDIT_FAILURE_LABEL = {
1918
+ auth: "refused the audit",
1919
+ forbidden: "accepted the credentials and refused",
1920
+ unreachable: "unreachable"
1921
+ };
1885
1922
  var MARK2 = { high: "\u{1F534}", medium: "\u{1F7E0}", low: "\u26AA" };
1886
1923
  function cell(text) {
1887
1924
  return text.replace(/\|/g, "\\|").replace(/`/g, "\\`").replace(/\r?\n/g, " ").trim();
@@ -1918,7 +1955,7 @@ function renderMarkdownReport(report, options = {}) {
1918
1955
  `<details><summary>${report.unreachable.length} server${report.unreachable.length === 1 ? "" : "s"} could not be read</summary>`,
1919
1956
  "",
1920
1957
  ...report.unreachable.map(
1921
- (failure) => `- \`${cell(failure.server)}\` \xB7 ${failure.kind === "auth" ? "refused the audit" : "unreachable"}: ${cell(failure.reason)}`
1958
+ (failure) => `- \`${cell(failure.server)}\` \xB7 ${AUDIT_FAILURE_LABEL[failure.kind]}: ${cell(failure.reason)}`
1922
1959
  ),
1923
1960
  "",
1924
1961
  "</details>",
@@ -2262,8 +2299,9 @@ ${dim(`Looked in: ${result.discovery.filesRead.length > 0 ? result.discovery.fil
2262
2299
  );
2263
2300
  return EXIT_CLEAN;
2264
2301
  }
2265
- await writeLockfile(options.lockPath, result.lock);
2266
- const lines = ["", bold(`Pinned ${names.length} server(s) to ${options.lockPath}:`), ""];
2302
+ const pinnedSomething = names.length > 0;
2303
+ if (pinnedSomething) await writeLockfile(options.lockPath, result.lock);
2304
+ const lines = pinnedSomething ? ["", bold(`Pinned ${names.length} server(s) to ${options.lockPath}:`), ""] : ["", bold("Pinned nothing: no server answered."), ""];
2267
2305
  for (const name of names) {
2268
2306
  const entry = result.lock.subjects[name];
2269
2307
  const counts = [
@@ -2282,7 +2320,11 @@ ${dim(`Looked in: ${result.discovery.filesRead.length > 0 ? result.discovery.fil
2282
2320
  for (const shadow of result.discovery.shadowed) {
2283
2321
  lines.push(dim(` note: "${shadow.name}" is defined in both ${shadow.keptFrom} and ${shadow.alsoIn}; kept the first.`));
2284
2322
  }
2285
- lines.push("", dim("Commit mcp.lock. `nulladrift check` in CI will fail if any of this changes."), "");
2323
+ lines.push(
2324
+ "",
2325
+ pinnedSomething ? dim("Commit mcp.lock. `nulladrift check` in CI will fail if any of this changes.") : dim("No lockfile was written. Fix the server(s) above and run `nulladrift init` again."),
2326
+ ""
2327
+ );
2286
2328
  process.stdout.write(lines.join("\n"));
2287
2329
  await maybeOfferTelemetry();
2288
2330
  if (result.unreachable.length > 0 && !options.allowUnreachable) return EXIT_INCOMPLETE;
@@ -2487,6 +2529,13 @@ async function runPush(options) {
2487
2529
  configFiles: options.configFiles,
2488
2530
  timeoutMs: options.timeoutMs
2489
2531
  });
2532
+ if (Object.keys(result.lock.subjects).length === 0 && result.unreachable.length === 0) {
2533
+ const looked = result.discovery.filesRead.length > 0 ? result.discovery.filesRead.join(", ") : "no client config files exist for this project";
2534
+ process.stderr.write(`No MCP servers found, so there is nothing to push.
2535
+ ${dim(`Looked in: ${looked}`)}
2536
+ `);
2537
+ return EXIT_INCOMPLETE;
2538
+ }
2490
2539
  const servers = Object.entries(result.lock.subjects).map(([name, entry]) => ({
2491
2540
  name,
2492
2541
  transport: entry.transport.type,