@imenam/mcp-dependabot-tracker 1.0.10 → 1.0.12

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 (44) hide show
  1. package/README.md +33 -14
  2. package/dist/shared/alerts.d.ts +6 -1
  3. package/dist/shared/alerts.js +7 -0
  4. package/dist/shared/schemas/api.schema.d.ts +41 -9
  5. package/dist/shared/schemas/api.schema.js +5 -1
  6. package/dist/shared/schemas/ipc.schema.d.ts +1 -1
  7. package/dist/shared/schemas/ipc.schema.js +2 -0
  8. package/dist/shared/schemas/model.schema.d.ts +159 -7
  9. package/dist/shared/schemas/model.schema.js +63 -8
  10. package/dist/src/core/analysis.d.ts +26 -1
  11. package/dist/src/core/analysis.js +6 -3
  12. package/dist/src/core/audit-all.d.ts +6 -6
  13. package/dist/src/core/audit-all.js +6 -6
  14. package/dist/src/core/claude.d.ts +2 -0
  15. package/dist/src/core/claude.js +8 -4
  16. package/dist/src/core/commands.d.ts +2 -2
  17. package/dist/src/core/commands.js +1 -1
  18. package/dist/src/core/github.js +2 -1
  19. package/dist/src/core/npm-sandbox.d.ts +17 -0
  20. package/dist/src/core/npm-sandbox.js +89 -0
  21. package/dist/src/core/operations.d.ts +22 -12
  22. package/dist/src/core/operations.js +239 -44
  23. package/dist/src/core/organizer.d.ts +14 -0
  24. package/dist/src/core/organizer.js +17 -2
  25. package/dist/src/core/repair.d.ts +38 -0
  26. package/dist/src/core/repair.js +191 -0
  27. package/dist/src/core/repos.d.ts +11 -8
  28. package/dist/src/core/repos.js +38 -20
  29. package/dist/src/core/store.d.ts +2 -0
  30. package/dist/src/core/store.js +14 -5
  31. package/dist/src/gui-worker.js +20 -3
  32. package/dist/src/index.js +23 -8
  33. package/dist/src/npm-tools.d.ts +10 -0
  34. package/dist/src/npm-tools.js +136 -0
  35. package/dist/src/tools/format.js +20 -8
  36. package/dist/src/tools/tools.js +8 -6
  37. package/dist/src/tools/types.d.ts +2 -0
  38. package/dist/src/tools/types.js +9 -0
  39. package/gui/dist/assets/index-D98CR3xl.js +64 -0
  40. package/gui/dist/assets/index-DETLqB3f.css +1 -0
  41. package/gui/dist/index.html +2 -2
  42. package/package.json +1 -1
  43. package/gui/dist/assets/index-C1Ml-XiM.css +0 -1
  44. package/gui/dist/assets/index-DQPqW5Uq.js +0 -64
@@ -0,0 +1,136 @@
1
+ import fs from "fs";
2
+ import { fileURLToPath } from "url";
3
+ import { Server } from "@modelcontextprotocol/sdk/server/index.js";
4
+ import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
5
+ import { CallToolRequestSchema, ListToolsRequestSchema } from "@modelcontextprotocol/sdk/types.js";
6
+ import { AUDIT_SCOPES } from "../shared/schemas/model.schema.js";
7
+ import { runSandboxedNpm } from "./core/npm-sandbox.js";
8
+ import { tail } from "./core/commands.js";
9
+ import { APP_VERSION } from "./version.js";
10
+ import { errorResult, requireString, rejectUnknownFields } from "./tools/types.js";
11
+ /**
12
+ * Serveur MCP des commandes npm des corrections par Claude, lancé par Claude
13
+ * Code avec `node npm-tools.js --root <clone> --cache <cache> --scope <périmètre>` :
14
+ * chaque outil lance une commande npm fixe dans un projet du clone, à travers
15
+ * `runSandboxedNpm`, et rend son code de sortie et la fin de ses sorties.
16
+ */
17
+ /** Lignes de sortie rendues à Claude. */
18
+ const OUTPUT_LINES = 150;
19
+ /** Taille maximale de la sortie rendue à Claude. */
20
+ const OUTPUT_CHARS = 20_000;
21
+ /** Nom de paquet, spécification de version ou nom de script : pas d'option, pas d'espace. */
22
+ const NAME = /^[A-Za-z0-9@/._^~<>=*:+-]+$/;
23
+ const PROJECT_PROPERTY = {
24
+ type: "string",
25
+ description: 'Folder of the package.json, relative to the repository root; "" for the root.',
26
+ };
27
+ const TOOLS = [
28
+ {
29
+ name: "npm_install_lockfile",
30
+ description: "Run npm install --package-lock-only --ignore-scripts in a project: updates package-lock.json (and package.json for the packages given) without installing node_modules. Use it after changing package.json or its overrides.",
31
+ inputSchema: {
32
+ type: "object",
33
+ properties: {
34
+ project: PROJECT_PROPERTY,
35
+ packages: { type: "array", items: { type: "string" }, description: "Packages to add or upgrade, e.g. mermaid@12.0.1 (optional)." },
36
+ },
37
+ required: ["project"],
38
+ },
39
+ },
40
+ { name: "npm_audit", description: "Run npm audit in a project, with the scope of the operation.", inputSchema: { type: "object", properties: { project: PROJECT_PROPERTY }, required: ["project"] } },
41
+ { name: "npm_ci", description: "Run npm ci in a project: installs node_modules from package-lock.json, install scripts included.", inputSchema: { type: "object", properties: { project: PROJECT_PROPERTY }, required: ["project"] } },
42
+ { name: "npm_test", description: "Run npm test in a project.", inputSchema: { type: "object", properties: { project: PROJECT_PROPERTY }, required: ["project"] } },
43
+ {
44
+ name: "npm_run",
45
+ description: "Run a script of package.json in a project (npm run <script>).",
46
+ inputSchema: { type: "object", properties: { project: PROJECT_PROPERTY, script: { type: "string", description: "Name of the script." } }, required: ["project", "script"] },
47
+ },
48
+ {
49
+ name: "npm_ls",
50
+ description: "Show where a package is installed in the dependency tree of a project (npm ls <package> --all).",
51
+ inputSchema: { type: "object", properties: { project: PROJECT_PROPERTY, package: { type: "string", description: "Name of the package." } }, required: ["project", "package"] },
52
+ },
53
+ { name: "tsc", description: "Type-check a project with its own TypeScript (npm exec --no -- tsc --noEmit).", inputSchema: { type: "object", properties: { project: PROJECT_PROPERTY }, required: ["project"] } },
54
+ ];
55
+ /** Lit un nom de paquet ou de script ; lève une erreur s'il contient autre chose. */
56
+ function name(value, field) {
57
+ if (!NAME.test(value) || value.startsWith("-"))
58
+ throw new Error(`"${field}" must be a package or script name (got ${JSON.stringify(value)}).`);
59
+ return value;
60
+ }
61
+ /** Projet visé : `""` désigne la racine du clone. */
62
+ function project(args) {
63
+ const value = args?.project;
64
+ if (typeof value !== "string")
65
+ throw new Error('"project" is required: the folder of the package.json, "" for the root.');
66
+ return value.trim();
67
+ }
68
+ /** Arguments npm de l'outil appelé. */
69
+ export function npmArgs(tool, args, scope) {
70
+ switch (tool) {
71
+ case "npm_install_lockfile": {
72
+ rejectUnknownFields(args, ["project", "packages"]);
73
+ const packages = args?.packages ?? [];
74
+ if (!Array.isArray(packages) || packages.some((item) => typeof item !== "string"))
75
+ throw new Error('"packages" must be a list of package names.');
76
+ return ["install", "--package-lock-only", "--ignore-scripts", ...packages.map((item) => name(item.trim(), "packages"))];
77
+ }
78
+ case "npm_audit":
79
+ rejectUnknownFields(args, ["project"]);
80
+ return scope === "production" ? ["audit", "--omit=dev"] : ["audit"];
81
+ case "npm_ci":
82
+ rejectUnknownFields(args, ["project"]);
83
+ return ["ci"];
84
+ case "npm_test":
85
+ rejectUnknownFields(args, ["project"]);
86
+ return ["test"];
87
+ case "npm_run":
88
+ rejectUnknownFields(args, ["project", "script"]);
89
+ return ["run", name(requireString(args, "script"), "script")];
90
+ case "npm_ls":
91
+ rejectUnknownFields(args, ["project", "package"]);
92
+ return ["ls", name(requireString(args, "package"), "package"), "--all"];
93
+ case "tsc":
94
+ rejectUnknownFields(args, ["project"]);
95
+ return ["exec", "--no", "--", "tsc", "--noEmit"];
96
+ default:
97
+ throw new Error(`Unknown tool: ${tool}`);
98
+ }
99
+ }
100
+ /** Lance l'outil et décrit le résultat : commande, code de sortie, fin des sorties. */
101
+ export async function callNpmTool(sandbox, scope, tool, args) {
102
+ const npm = npmArgs(tool, args, scope);
103
+ const folder = project(args);
104
+ const result = await runSandboxedNpm(sandbox, folder, npm);
105
+ const output = tail(`${result.stdout}\n${result.stderr}`, OUTPUT_LINES);
106
+ const text = [`$ npm ${npm.join(" ")} (in ${folder || "."}, exit code ${result.code})`, output.length > OUTPUT_CHARS ? `…${output.slice(-OUTPUT_CHARS)}` : output].join("\n");
107
+ return { content: [{ type: "text", text }], isError: result.code !== 0 };
108
+ }
109
+ /** Lit `--root`, `--cache` et `--scope`, puis sert les outils sur stdio. */
110
+ export async function serveNpmTools(argv) {
111
+ const option = (flag) => {
112
+ const index = argv.indexOf(flag);
113
+ const value = index === -1 ? undefined : argv[index + 1];
114
+ if (!value)
115
+ throw new Error(`${flag} is required.`);
116
+ return value;
117
+ };
118
+ const sandbox = { root: option("--root"), cache: option("--cache") };
119
+ const scope = option("--scope");
120
+ if (!AUDIT_SCOPES.includes(scope))
121
+ throw new Error(`--scope must be one of ${AUDIT_SCOPES.join(", ")}.`);
122
+ const server = new Server({ name: "mcp-dependabot-tracker-npm", version: APP_VERSION }, { capabilities: { tools: {} } });
123
+ server.setRequestHandler(ListToolsRequestSchema, async () => ({ tools: TOOLS }));
124
+ server.setRequestHandler(CallToolRequestSchema, async (request) => {
125
+ try {
126
+ return await callNpmTool(sandbox, scope, request.params.name, request.params.arguments);
127
+ }
128
+ catch (err) {
129
+ return errorResult(err?.message ?? String(err));
130
+ }
131
+ });
132
+ await server.connect(new StdioServerTransport());
133
+ }
134
+ if (process.argv[1] && fs.realpathSync(process.argv[1]) === fs.realpathSync(fileURLToPath(import.meta.url))) {
135
+ await serveNpmTools(process.argv.slice(2));
136
+ }
@@ -8,7 +8,14 @@ export function rightsLabel(repo) {
8
8
  const allowed = RIGHTS.filter((right) => repo.rights[right]);
9
9
  return allowed.length === 0 ? "none" : allowed.join(", ");
10
10
  }
11
- /** Alertes restantes par gravité, et le nombre de celles que l'utilisateur a corrigées à la main. */
11
+ /** Périmètre d'un audit, en clair. */
12
+ function scopeLabel(scope) {
13
+ return scope === "production" ? "production dependencies" : "all dependencies";
14
+ }
15
+ /**
16
+ * Alertes restantes par gravité, dont celles qui portent sur une dépendance de
17
+ * développement, et le nombre de celles que l'utilisateur a corrigées à la main.
18
+ */
12
19
  function alertsLabel(repo) {
13
20
  const pending = pendingAlerts(repo);
14
21
  const handled = repo.alerts.length - pending.length;
@@ -17,7 +24,9 @@ function alertsLabel(repo) {
17
24
  return `none${handledNote}`;
18
25
  const counts = countBySeverity(pending);
19
26
  const detail = ALERT_SEVERITIES.filter((severity) => counts[severity] > 0).map((severity) => `${severity} ${counts[severity]}`);
20
- return `${pending.length} (${detail.join(", ")})${handledNote}`;
27
+ const development = pending.filter((alert) => alert.scope === "development").length;
28
+ const developmentNote = development > 0 ? `; ${development} on development dependencies` : "";
29
+ return `${pending.length} (${detail.join(", ")}${developmentNote})${handledNote}`;
21
30
  }
22
31
  /** Description d'un dépôt pour l'agent ; `category` est la catégorie où l'utilisateur l'a rangé. */
23
32
  export function describeRepo(view, category) {
@@ -34,12 +43,14 @@ export function describeRepo(view, category) {
34
43
  }
35
44
  if (view.unfixable.length > 0)
36
45
  lines.push(` Last npm audit found no published fix for: ${view.unfixable.join(", ")}`);
37
- if (view.cleanAuditAt) {
38
- lines.push(` npm audit of ${view.cleanAuditAt} found no vulnerability on the default branch: these Dependabot alerts are probably not refreshed yet.`);
46
+ if (view.cleanAudit) {
47
+ const { at, scope } = view.cleanAudit;
48
+ const alerts = scope === "production" ? "the Dependabot alerts on production dependencies" : "these Dependabot alerts";
49
+ lines.push(` npm audit of ${at} (${scopeLabel(scope)}) found no vulnerability on the default branch: ${alerts} are probably not refreshed yet.`);
39
50
  }
40
51
  if (view.auditFindings) {
41
- const { at, count, severity } = view.auditFindings;
42
- lines.push(` npm audit of ${at} found ${count} vulnerabilit${count === 1 ? "y" : "ies"} (worst: ${severity}) on the default branch although Dependabot reports none: Dependabot has probably not caught up yet.`);
52
+ const { at, scope, count, severity } = view.auditFindings;
53
+ lines.push(` npm audit of ${at} (${scopeLabel(scope)}) found ${count} vulnerabilit${count === 1 ? "y" : "ies"} (worst: ${severity}) on the default branch although Dependabot reports none there: Dependabot has probably not caught up yet.`);
43
54
  }
44
55
  lines.push(` Agent rights: ${rightsLabel(repo)}`);
45
56
  if (activeOperation)
@@ -52,7 +63,8 @@ export function describeAlerts(repo) {
52
63
  const patched = alert.patchedVersion ? ` — patched in ${alert.patchedVersion}` : " — no patched version";
53
64
  const mark = repo.handledAlerts.find((candidate) => candidate.number === alert.number);
54
65
  const handled = mark ? ` — fixed by hand by the user on ${mark.markedAt}` : "";
55
- return `- #${alert.number} ${alert.severity} ${alert.package} (${alert.ecosystem}, ${alert.manifestPath}): ${alert.summary}${patched}${handled} — ${alert.url}`;
66
+ const scope = alert.scope ? `, ${alert.scope} dependency` : "";
67
+ return `- #${alert.number} ${alert.severity} ${alert.package} (${alert.ecosystem}, ${alert.manifestPath}${scope}): ${alert.summary}${patched}${handled} — ${alert.url}`;
56
68
  });
57
69
  return [header, ...lines].join("\n");
58
70
  }
@@ -65,7 +77,7 @@ function list(items, render) {
65
77
  /** Compte rendu d'une opération pour l'agent : étapes, vulnérabilités, paquets modifiés, PR, erreur. */
66
78
  export function describeOperation(operation) {
67
79
  const title = operation.kind === "audit" ? "npm audit" : "npm audit fix";
68
- const lines = [`${title} on ${operation.repoId} (operation ${operation.id}): ${operation.status}.`];
80
+ const lines = [`${title} on ${operation.repoId}, ${scopeLabel(operation.scope)} (operation ${operation.id}): ${operation.status}.`];
69
81
  if (operation.projects.length > 0) {
70
82
  lines.push(`- npm projects: ${operation.projects.map((project) => projectLabel(project) || "./").join(", ")}`);
71
83
  }
@@ -1,9 +1,9 @@
1
- import { DEFAULT_COMMIT_MESSAGE } from "../../shared/schemas/model.schema.js";
1
+ import { AUDIT_SCOPES, DEFAULT_AUDIT_SCOPE, DEFAULT_COMMIT_MESSAGE } from "../../shared/schemas/model.schema.js";
2
2
  import { TrackerError } from "../core/errors.js";
3
3
  import { runAgentOperation } from "../core/operations.js";
4
4
  import { listRepoViews, repoView, syncRepository } from "../core/repos.js";
5
5
  import { describeAlerts, describeOperation, describeRepo } from "./format.js";
6
- import { errorResult, optionalBoolean, optionalString, rejectUnknownFields, requireString, textResult } from "./types.js";
6
+ import { errorResult, optionalBoolean, optionalEnum, optionalString, rejectUnknownFields, requireString, textResult } from "./types.js";
7
7
  const RIGHT_LABELS = {
8
8
  audit: "run npm audit",
9
9
  fix: "run npm audit fix",
@@ -51,14 +51,16 @@ function operationResult(operation) {
51
51
  return { result: operation.status === "done" ? textResult(text) : errorResult(text), operation };
52
52
  }
53
53
  export async function runAudit(ctx, args) {
54
- rejectUnknownFields(args, ["repository"]);
54
+ rejectUnknownFields(args, ["repository", "scope"]);
55
55
  const repo = ctx.store.getRepo(requireString(args, "repository"));
56
+ const scope = optionalEnum(args, "scope", AUDIT_SCOPES, DEFAULT_AUDIT_SCOPE);
56
57
  assertAllowed(repo, "audit");
57
- return operationResult(await runAgentOperation(ctx, repo.id, "audit", { force: false, push: false, commitMessage: DEFAULT_COMMIT_MESSAGE }));
58
+ return operationResult(await runAgentOperation(ctx, repo.id, "audit", { scope, force: false, push: false, commitMessage: DEFAULT_COMMIT_MESSAGE }));
58
59
  }
59
60
  export async function fixVulnerabilities(ctx, args) {
60
- rejectUnknownFields(args, ["repository", "force", "push", "commit_message"]);
61
+ rejectUnknownFields(args, ["repository", "scope", "force", "push", "commit_message"]);
61
62
  const repo = ctx.store.getRepo(requireString(args, "repository"));
63
+ const scope = optionalEnum(args, "scope", AUDIT_SCOPES, DEFAULT_AUDIT_SCOPE);
62
64
  const force = optionalBoolean(args, "force", false);
63
65
  const push = optionalBoolean(args, "push", false);
64
66
  const commitMessage = optionalString(args, "commit_message") ?? DEFAULT_COMMIT_MESSAGE;
@@ -67,5 +69,5 @@ export async function fixVulnerabilities(ctx, args) {
67
69
  assertAllowed(repo, "force");
68
70
  if (push)
69
71
  assertAllowed(repo, "push");
70
- return operationResult(await runAgentOperation(ctx, repo.id, "fix", { force, push, commitMessage }));
72
+ return operationResult(await runAgentOperation(ctx, repo.id, "fix", { scope, force, push, commitMessage }));
71
73
  }
@@ -17,5 +17,7 @@ export declare function requireString(args: Args, field: string): string;
17
17
  export declare function optionalString(args: Args, field: string): string | undefined;
18
18
  /** Lit un booléen facultatif ; `fallback` s'il est absent. */
19
19
  export declare function optionalBoolean(args: Args, field: string, fallback: boolean): boolean;
20
+ /** Lit un argument facultatif parmi `values` ; `fallback` s'il est absent. */
21
+ export declare function optionalEnum<T extends string>(args: Args, field: string, values: readonly T[], fallback: T): T;
20
22
  /** Lève une erreur si `args` contient des champs hors de `allowed` : une faute de frappe ne passe pas inaperçue. */
21
23
  export declare function rejectUnknownFields(args: Args, allowed: readonly string[]): void;
@@ -27,6 +27,15 @@ export function optionalBoolean(args, field, fallback) {
27
27
  throw new Error(`"${field}" must be a boolean (got ${JSON.stringify(value)}).`);
28
28
  return value;
29
29
  }
30
+ /** Lit un argument facultatif parmi `values` ; `fallback` s'il est absent. */
31
+ export function optionalEnum(args, field, values, fallback) {
32
+ const value = args?.[field];
33
+ if (value === undefined)
34
+ return fallback;
35
+ if (!values.includes(value))
36
+ throw new Error(`"${field}" must be one of ${values.join(", ")} (got ${JSON.stringify(value)}).`);
37
+ return value;
38
+ }
30
39
  /** Lève une erreur si `args` contient des champs hors de `allowed` : une faute de frappe ne passe pas inaperçue. */
31
40
  export function rejectUnknownFields(args, allowed) {
32
41
  if (!args)