@imenam/mcp-dependabot-tracker 1.0.31 → 1.0.33
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/README.md +63 -28
- package/dist/shared/schemas/model.schema.d.ts +64 -8
- package/dist/shared/schemas/model.schema.js +23 -8
- package/dist/src/cli/prompt.d.ts +4 -0
- package/dist/src/cli/prompt.js +28 -0
- package/dist/src/cli/setup.d.ts +55 -0
- package/dist/src/cli/setup.js +484 -0
- package/dist/src/cli/users.js +1 -28
- package/dist/src/core/auth.d.ts +2 -0
- package/dist/src/core/auth.js +4 -0
- package/dist/src/core/commands.d.ts +7 -7
- package/dist/src/core/commands.js +8 -12
- package/dist/src/core/containers.d.ts +82 -0
- package/dist/src/core/containers.js +144 -0
- package/dist/src/core/managers/composer.d.ts +15 -0
- package/dist/src/core/managers/composer.js +234 -0
- package/dist/src/core/managers/index.d.ts +14 -0
- package/dist/src/core/managers/index.js +46 -0
- package/dist/src/core/managers/npm.d.ts +25 -0
- package/dist/src/core/managers/npm.js +203 -0
- package/dist/src/core/managers/php-version.d.ts +18 -0
- package/dist/src/core/managers/php-version.js +113 -0
- package/dist/src/core/managers/pnpm.d.ts +28 -0
- package/dist/src/core/managers/pnpm.js +249 -0
- package/dist/src/core/managers/tool-args.d.ts +17 -0
- package/dist/src/core/managers/tool-args.js +26 -0
- package/dist/src/core/managers/types.d.ts +61 -0
- package/dist/src/core/managers/types.js +11 -0
- package/dist/src/core/operations.d.ts +8 -5
- package/dist/src/core/operations.js +106 -77
- package/dist/src/core/repair.d.ts +34 -13
- package/dist/src/core/repair.js +118 -84
- package/dist/src/core/repos.d.ts +1 -1
- package/dist/src/core/repos.js +1 -1
- package/dist/src/core/sandbox.d.ts +7 -0
- package/dist/src/core/sandbox.js +31 -0
- package/dist/src/core/settings.d.ts +1 -1
- package/dist/src/core/settings.js +2 -2
- package/dist/src/core/setup-files.d.ts +48 -0
- package/dist/src/core/setup-files.js +147 -0
- package/dist/src/core/store.js +3 -0
- package/dist/src/index.d.ts +1 -0
- package/dist/src/index.js +12 -0
- package/dist/src/mcp.js +6 -5
- package/dist/src/package-tools.d.ts +13 -0
- package/dist/src/package-tools.js +92 -0
- package/dist/src/server/serve.d.ts +2 -0
- package/dist/src/server/serve.js +3 -1
- package/dist/src/tools/format.js +11 -11
- package/dist/src/tools/tools.js +4 -4
- package/gui/dist/assets/index-DrVmedqf.js +71 -0
- package/gui/dist/index.html +1 -1
- package/package.json +2 -2
- package/dist/src/core/npm-audit.d.ts +0 -26
- package/dist/src/core/npm-audit.js +0 -76
- package/dist/src/core/npm-sandbox.d.ts +0 -33
- package/dist/src/core/npm-sandbox.js +0 -159
- package/dist/src/npm-tools.d.ts +0 -10
- package/dist/src/npm-tools.js +0 -136
- package/gui/dist/assets/index-CAOy2g1q.js +0 -71
package/gui/dist/index.html
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
<meta charset="UTF-8" />
|
|
5
5
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
6
6
|
<title>Dependabot Tracker</title>
|
|
7
|
-
<script type="module" crossorigin src="/assets/index-
|
|
7
|
+
<script type="module" crossorigin src="/assets/index-DrVmedqf.js"></script>
|
|
8
8
|
<link rel="stylesheet" crossorigin href="/assets/index-CYU7-6kP.css">
|
|
9
9
|
</head>
|
|
10
10
|
<body>
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@imenam/mcp-dependabot-tracker",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"description": "Server and web GUI that track the Dependabot alerts of GitHub repositories and fix their npm
|
|
3
|
+
"version": "1.0.33",
|
|
4
|
+
"description": "Server and web GUI that track the Dependabot alerts of GitHub repositories and fix their vulnerable dependencies (npm, pnpm, Composer) in a temporary clone: audit, automatic fixes in rootless Podman containers, fixes by Claude, then a branch and a pull request. An MCP mode lets agents drive the server.",
|
|
5
5
|
"main": "dist/src/index.js",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"test": "node --test \"dist/test/*.test.js\"",
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { type Change, type Vulnerability } from "../../shared/schemas/model.schema.js";
|
|
2
|
-
/** Contenu d'un `package-lock.json` utile ici : la version de chaque paquet installé, par chemin. */
|
|
3
|
-
export interface Lockfile {
|
|
4
|
-
packages: Record<string, {
|
|
5
|
-
version?: string;
|
|
6
|
-
}>;
|
|
7
|
-
}
|
|
8
|
-
/** Lit la sortie JSON d'un appel npm ; une sortie qui n'est pas du JSON, ou qui porte une erreur npm, lève une erreur. */
|
|
9
|
-
export declare function parseNpmJson(stdout: string, stderr: string, what: string): any;
|
|
10
|
-
/**
|
|
11
|
-
* Vulnérabilités d'un rapport `npm audit --json` (format `auditReportVersion` 2).
|
|
12
|
-
* `fixAvailable` vaut false (aucune correction), true (dans les plages déclarées)
|
|
13
|
-
* ou un objet `{ name, version, isSemVerMajor }` qui désigne le paquet à mettre à
|
|
14
|
-
* jour, éventuellement d'une version majeure.
|
|
15
|
-
*/
|
|
16
|
-
export declare function parseAuditReport(report: any, project: string): Vulnerability[];
|
|
17
|
-
/**
|
|
18
|
-
* Paquets dont la version diffère entre deux lockfiles d'un projet. Le nom est
|
|
19
|
-
* le chemin d'installation sans le premier `node_modules/` : `lodash`, ou
|
|
20
|
-
* `d3-sankey/node_modules/d3-array` pour une copie imbriquée.
|
|
21
|
-
*/
|
|
22
|
-
export declare function diffLockfiles(before: Lockfile, after: Lockfile, project: string): Change[];
|
|
23
|
-
/** Lit un `package-lock.json` ; un lockfile v1 (npm 6), sans `packages`, est refusé. */
|
|
24
|
-
export declare function parseLockfile(text: string, project: string): Lockfile;
|
|
25
|
-
/** Préfixe d'affichage d'un projet : `""` pour la racine, `gui/` pour le dossier `gui`. */
|
|
26
|
-
export declare function projectLabel(project: string): string;
|
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
import { NPM_SEVERITIES } from "../../shared/schemas/model.schema.js";
|
|
2
|
-
import { TrackerError } from "./errors.js";
|
|
3
|
-
/** Lit la sortie JSON d'un appel npm ; une sortie qui n'est pas du JSON, ou qui porte une erreur npm, lève une erreur. */
|
|
4
|
-
export function parseNpmJson(stdout, stderr, what) {
|
|
5
|
-
let json;
|
|
6
|
-
try {
|
|
7
|
-
json = JSON.parse(stdout);
|
|
8
|
-
}
|
|
9
|
-
catch {
|
|
10
|
-
const detail = stderr.trim() || stdout.trim() || "no output";
|
|
11
|
-
throw new TrackerError(`${what} did not return JSON: ${detail.slice(-1500)}`);
|
|
12
|
-
}
|
|
13
|
-
if (json && typeof json === "object" && json.error) {
|
|
14
|
-
const summary = json.error.summary ?? json.error.message ?? JSON.stringify(json.error);
|
|
15
|
-
const detail = json.error.detail ? ` ${json.error.detail}` : "";
|
|
16
|
-
throw new TrackerError(`${what} failed: ${summary}${detail}`.trim());
|
|
17
|
-
}
|
|
18
|
-
return json;
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* Vulnérabilités d'un rapport `npm audit --json` (format `auditReportVersion` 2).
|
|
22
|
-
* `fixAvailable` vaut false (aucune correction), true (dans les plages déclarées)
|
|
23
|
-
* ou un objet `{ name, version, isSemVerMajor }` qui désigne le paquet à mettre à
|
|
24
|
-
* jour, éventuellement d'une version majeure.
|
|
25
|
-
*/
|
|
26
|
-
export function parseAuditReport(report, project) {
|
|
27
|
-
if (report?.auditReportVersion !== 2 || typeof report.vulnerabilities !== "object" || report.vulnerabilities === null) {
|
|
28
|
-
throw new TrackerError(`Unsupported npm audit report for ${projectLabel(project)}package-lock.json: expected auditReportVersion 2 (npm 7 or later).`);
|
|
29
|
-
}
|
|
30
|
-
return Object.values(report.vulnerabilities).map((entry) => {
|
|
31
|
-
const severity = NPM_SEVERITIES.includes(entry.severity) ? entry.severity : "info";
|
|
32
|
-
const fixAvailable = entry.fixAvailable;
|
|
33
|
-
if (fixAvailable === true)
|
|
34
|
-
return { project, name: entry.name, severity, fix: "available" };
|
|
35
|
-
if (fixAvailable && typeof fixAvailable === "object")
|
|
36
|
-
return { project, name: entry.name, severity, fix: fixAvailable.isSemVerMajor ? "major" : "available" };
|
|
37
|
-
return { project, name: entry.name, severity, fix: "none" };
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
/**
|
|
41
|
-
* Paquets dont la version diffère entre deux lockfiles d'un projet. Le nom est
|
|
42
|
-
* le chemin d'installation sans le premier `node_modules/` : `lodash`, ou
|
|
43
|
-
* `d3-sankey/node_modules/d3-array` pour une copie imbriquée.
|
|
44
|
-
*/
|
|
45
|
-
export function diffLockfiles(before, after, project) {
|
|
46
|
-
const keys = new Set([...Object.keys(before.packages), ...Object.keys(after.packages)]);
|
|
47
|
-
const changes = [];
|
|
48
|
-
for (const key of keys) {
|
|
49
|
-
if (!key.startsWith("node_modules/"))
|
|
50
|
-
continue;
|
|
51
|
-
const from = before.packages[key]?.version ?? null;
|
|
52
|
-
const to = after.packages[key]?.version ?? null;
|
|
53
|
-
if (from === to)
|
|
54
|
-
continue;
|
|
55
|
-
changes.push({ project, name: key.slice("node_modules/".length), from, to });
|
|
56
|
-
}
|
|
57
|
-
return changes.sort((a, b) => a.name.localeCompare(b.name));
|
|
58
|
-
}
|
|
59
|
-
/** Lit un `package-lock.json` ; un lockfile v1 (npm 6), sans `packages`, est refusé. */
|
|
60
|
-
export function parseLockfile(text, project) {
|
|
61
|
-
let json;
|
|
62
|
-
try {
|
|
63
|
-
json = JSON.parse(text);
|
|
64
|
-
}
|
|
65
|
-
catch (err) {
|
|
66
|
-
throw new TrackerError(`${projectLabel(project)}package-lock.json is not valid JSON: ${err.message}`);
|
|
67
|
-
}
|
|
68
|
-
if (!json || typeof json.packages !== "object" || json.packages === null) {
|
|
69
|
-
throw new TrackerError(`${projectLabel(project)}package-lock.json has no "packages" section: lockfile version 2 or 3 (npm 7 or later) is required.`);
|
|
70
|
-
}
|
|
71
|
-
return { packages: json.packages };
|
|
72
|
-
}
|
|
73
|
-
/** Préfixe d'affichage d'un projet : `""` pour la racine, `gui/` pour le dossier `gui`. */
|
|
74
|
-
export function projectLabel(project) {
|
|
75
|
-
return project === "" ? "" : `${project}/`;
|
|
76
|
-
}
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { type CommandResult } from "./commands.js";
|
|
2
|
-
/**
|
|
3
|
-
* Vérifie, sous Linux, que bubblewrap crée un bac à sable pour le compte et
|
|
4
|
-
* avec les restrictions du serveur : le tracker y lance toutes les commandes
|
|
5
|
-
* npm d'une opération, et Claude Code refuse de démarrer sans lui. Lève une
|
|
6
|
-
* erreur qui dit quoi installer ou régler ; sans effet sur les autres systèmes.
|
|
7
|
-
*/
|
|
8
|
-
export declare function assertSandboxAvailable(platform?: NodeJS.Platform, command?: string): Promise<void>;
|
|
9
|
-
export interface NpmSandbox {
|
|
10
|
-
/** Clone du dépôt, seul dossier du projet en écriture. */
|
|
11
|
-
root: string;
|
|
12
|
-
/** Cache npm de l'opération, hors du clone. */
|
|
13
|
-
cache: string;
|
|
14
|
-
}
|
|
15
|
-
/** Cache npm d'une opération, dans son répertoire temporaire, à côté du clone. */
|
|
16
|
-
export declare const NPM_CACHE_DIR = "npm-cache";
|
|
17
|
-
export interface NpmRunOptions {
|
|
18
|
-
/** Variables propres à la commande, en plus de celles de `npmEnv`. */
|
|
19
|
-
env?: Record<string, string>;
|
|
20
|
-
/** Annulation de l'opération : arrête la commande. */
|
|
21
|
-
signal?: AbortSignal;
|
|
22
|
-
platform?: NodeJS.Platform;
|
|
23
|
-
}
|
|
24
|
-
/** Arguments de bubblewrap pour lancer `npm <args>` dans `cwd`, un dossier du clone, avec les variables `extraEnv` en plus. */
|
|
25
|
-
export declare function bwrapArgs(sandbox: NpmSandbox, cwd: string, args: string[], extraEnv?: Record<string, string>): string[];
|
|
26
|
-
/**
|
|
27
|
-
* Dossier d'un projet du clone, d'après son chemin relatif (`""` pour la
|
|
28
|
-
* racine) ; lève une erreur hors du clone, dans `node_modules` ou sans
|
|
29
|
-
* `package.json`.
|
|
30
|
-
*/
|
|
31
|
-
export declare function projectDir(sandbox: NpmSandbox, project: string): string;
|
|
32
|
-
/** Lance `npm <args>` dans un projet du clone et rend son code de sortie et ses sorties. */
|
|
33
|
-
export declare function runSandboxedNpm(sandbox: NpmSandbox, project: string, args: string[], options?: NpmRunOptions): Promise<CommandResult>;
|
|
@@ -1,159 +0,0 @@
|
|
|
1
|
-
import { spawn } from "child_process";
|
|
2
|
-
import fs from "fs";
|
|
3
|
-
import path from "path";
|
|
4
|
-
import { runCommand, tail } from "./commands.js";
|
|
5
|
-
import { TrackerError } from "./errors.js";
|
|
6
|
-
/**
|
|
7
|
-
* Commandes npm d'une opération : celles du tracker (`npm audit`, `npm audit
|
|
8
|
-
* fix`) et celles lancées pour Claude pendant ses corrections, hors du bac à
|
|
9
|
-
* sable de Claude Code, qui garde en lecture seule les manifestes, les lockfiles
|
|
10
|
-
* et `node_modules`. Sous Linux, chaque commande tourne dans un bac à sable
|
|
11
|
-
* bubblewrap du tracker : système en lecture seule (`/usr`, Node.js, et de
|
|
12
|
-
* `/etc` les seuls fichiers de `ETC_ENTRIES`), clone et cache npm de l'opération
|
|
13
|
-
* en écriture, `/tmp` vide, aucun autre dossier du serveur visible (ni `/opt`,
|
|
14
|
-
* ni `/home`, ni les données du tracker, ni les autres clones),
|
|
15
|
-
* environnement réduit à PATH, LANG, HOME et au cache npm. Ailleurs, la
|
|
16
|
-
* commande tourne directement dans le clone, avec le cache de l'opération.
|
|
17
|
-
*/
|
|
18
|
-
/** Dossiers système montés en lecture seule, ou recréés en lien symbolique quand ils en sont un. */
|
|
19
|
-
const SYSTEM_DIRS = ["/usr", "/bin", "/sbin", "/lib", "/lib32", "/lib64", "/run/systemd/resolve"];
|
|
20
|
-
/**
|
|
21
|
-
* Fichiers et dossiers de `/etc` montés en lecture seule : résolution de noms,
|
|
22
|
-
* comptes, certificats, éditeur de liens, alternatives de Debian, fuseau horaire
|
|
23
|
-
* et identité du système. Le reste de `/etc` est absent du bac à sable.
|
|
24
|
-
*/
|
|
25
|
-
const ETC_ENTRIES = [
|
|
26
|
-
"/etc/resolv.conf",
|
|
27
|
-
"/etc/hosts",
|
|
28
|
-
"/etc/host.conf",
|
|
29
|
-
"/etc/gai.conf",
|
|
30
|
-
"/etc/nsswitch.conf",
|
|
31
|
-
"/etc/passwd",
|
|
32
|
-
"/etc/group",
|
|
33
|
-
"/etc/ssl",
|
|
34
|
-
"/etc/ca-certificates",
|
|
35
|
-
"/etc/ca-certificates.conf",
|
|
36
|
-
"/etc/pki",
|
|
37
|
-
"/etc/crypto-policies",
|
|
38
|
-
"/etc/ld.so.cache",
|
|
39
|
-
"/etc/ld.so.conf",
|
|
40
|
-
"/etc/ld.so.conf.d",
|
|
41
|
-
"/etc/alternatives",
|
|
42
|
-
"/etc/localtime",
|
|
43
|
-
"/etc/os-release",
|
|
44
|
-
];
|
|
45
|
-
/** Bac à sable minimal, du type de ceux où le tracker lance les commandes npm sous Linux. */
|
|
46
|
-
const BWRAP_PROBE = ["--ro-bind", "/", "/", "--dev", "/dev", "--proc", "/proc", "--unshare-user", "--unshare-pid", "--unshare-net", "true"];
|
|
47
|
-
/** Durée maximale du test de bubblewrap. */
|
|
48
|
-
const BWRAP_PROBE_TIMEOUT_MS = 10_000;
|
|
49
|
-
/**
|
|
50
|
-
* Vérifie, sous Linux, que bubblewrap crée un bac à sable pour le compte et
|
|
51
|
-
* avec les restrictions du serveur : le tracker y lance toutes les commandes
|
|
52
|
-
* npm d'une opération, et Claude Code refuse de démarrer sans lui. Lève une
|
|
53
|
-
* erreur qui dit quoi installer ou régler ; sans effet sur les autres systèmes.
|
|
54
|
-
*/
|
|
55
|
-
export function assertSandboxAvailable(platform = process.platform, command = "bwrap") {
|
|
56
|
-
if (platform !== "linux")
|
|
57
|
-
return Promise.resolve();
|
|
58
|
-
return new Promise((resolve, reject) => {
|
|
59
|
-
const child = spawn(command, BWRAP_PROBE, { stdio: ["ignore", "ignore", "pipe"], timeout: BWRAP_PROBE_TIMEOUT_MS });
|
|
60
|
-
let stderr = "";
|
|
61
|
-
child.stderr.on("data", (chunk) => (stderr += String(chunk)));
|
|
62
|
-
child.on("error", (err) => reject(new TrackerError(err.code === "ENOENT"
|
|
63
|
-
? "The npm commands of an operation need bubblewrap (bwrap), which isolates them on Linux, and it is not in the PATH of the server. Install it on the server: sudo apt-get install -y bubblewrap socat"
|
|
64
|
-
: `The npm commands of an operation need bubblewrap (bwrap), which could not be started: ${err.message}`)));
|
|
65
|
-
child.on("close", (code) => {
|
|
66
|
-
if (code === 0)
|
|
67
|
-
return resolve();
|
|
68
|
-
reject(new TrackerError(`bubblewrap (bwrap) is installed but cannot create a sandbox for the account of the server${stderr.trim() ? `: ${tail(stderr, 3)}` : "."} ` +
|
|
69
|
-
"Check the AppArmor restriction on user namespaces (kernel.apparmor_restrict_unprivileged_userns on Ubuntu 24.04 and later) and the hardening of the service (RestrictNamespaces, PrivateUsers, SystemCallFilter)."));
|
|
70
|
-
});
|
|
71
|
-
});
|
|
72
|
-
}
|
|
73
|
-
/** Cache npm d'une opération, dans son répertoire temporaire, à côté du clone. */
|
|
74
|
-
export const NPM_CACHE_DIR = "npm-cache";
|
|
75
|
-
/** Variables transmises à npm : chemins, langue, HOME, cache de l'opération, mode CI pour que les tests ne restent pas en veille, puis `extra`. */
|
|
76
|
-
function npmEnv(sandbox, home, extra = {}) {
|
|
77
|
-
return {
|
|
78
|
-
PATH: process.env.PATH ?? "/usr/bin:/bin",
|
|
79
|
-
LANG: process.env.LANG ?? "C.UTF-8",
|
|
80
|
-
HOME: home,
|
|
81
|
-
npm_config_cache: sandbox.cache,
|
|
82
|
-
npm_config_update_notifier: "false",
|
|
83
|
-
CI: "true",
|
|
84
|
-
...extra,
|
|
85
|
-
};
|
|
86
|
-
}
|
|
87
|
-
/** Préfixe d'installation de Node.js (`<préfixe>/bin/node`), où se trouve aussi npm. */
|
|
88
|
-
function nodePrefix() {
|
|
89
|
-
return path.dirname(path.dirname(fs.realpathSync(process.execPath)));
|
|
90
|
-
}
|
|
91
|
-
/** Arguments de bubblewrap pour lancer `npm <args>` dans `cwd`, un dossier du clone, avec les variables `extraEnv` en plus. */
|
|
92
|
-
export function bwrapArgs(sandbox, cwd, args, extraEnv = {}) {
|
|
93
|
-
const mounts = [];
|
|
94
|
-
for (const dir of [...SYSTEM_DIRS, nodePrefix()]) {
|
|
95
|
-
let stat;
|
|
96
|
-
try {
|
|
97
|
-
stat = fs.lstatSync(dir);
|
|
98
|
-
}
|
|
99
|
-
catch {
|
|
100
|
-
continue;
|
|
101
|
-
}
|
|
102
|
-
if (stat.isSymbolicLink())
|
|
103
|
-
mounts.push("--symlink", fs.readlinkSync(dir), dir);
|
|
104
|
-
else
|
|
105
|
-
mounts.push("--ro-bind", dir, dir);
|
|
106
|
-
}
|
|
107
|
-
for (const entry of ETC_ENTRIES) {
|
|
108
|
-
let target;
|
|
109
|
-
try {
|
|
110
|
-
target = fs.realpathSync(entry);
|
|
111
|
-
}
|
|
112
|
-
catch {
|
|
113
|
-
continue;
|
|
114
|
-
}
|
|
115
|
-
mounts.push("--ro-bind", target, entry);
|
|
116
|
-
}
|
|
117
|
-
const env = Object.entries(npmEnv(sandbox, "/tmp", extraEnv)).flatMap(([name, value]) => ["--setenv", name, value]);
|
|
118
|
-
return [
|
|
119
|
-
"--die-with-parent",
|
|
120
|
-
"--new-session",
|
|
121
|
-
"--unshare-pid",
|
|
122
|
-
"--unshare-ipc",
|
|
123
|
-
...mounts,
|
|
124
|
-
"--dev", "/dev",
|
|
125
|
-
"--proc", "/proc",
|
|
126
|
-
"--tmpfs", "/tmp",
|
|
127
|
-
"--bind", sandbox.root, sandbox.root,
|
|
128
|
-
"--bind", sandbox.cache, sandbox.cache,
|
|
129
|
-
"--chdir", cwd,
|
|
130
|
-
"--clearenv",
|
|
131
|
-
...env,
|
|
132
|
-
"npm",
|
|
133
|
-
...args,
|
|
134
|
-
];
|
|
135
|
-
}
|
|
136
|
-
/**
|
|
137
|
-
* Dossier d'un projet du clone, d'après son chemin relatif (`""` pour la
|
|
138
|
-
* racine) ; lève une erreur hors du clone, dans `node_modules` ou sans
|
|
139
|
-
* `package.json`.
|
|
140
|
-
*/
|
|
141
|
-
export function projectDir(sandbox, project) {
|
|
142
|
-
const dir = path.resolve(sandbox.root, project);
|
|
143
|
-
const relative = path.relative(sandbox.root, dir);
|
|
144
|
-
if (relative.startsWith("..") || path.isAbsolute(relative) || relative.split(path.sep).includes("node_modules")) {
|
|
145
|
-
throw new TrackerError(`"${project}" is not a project folder of the repository.`);
|
|
146
|
-
}
|
|
147
|
-
if (!fs.existsSync(path.join(dir, "package.json")))
|
|
148
|
-
throw new TrackerError(`"${project || "."}" has no package.json.`);
|
|
149
|
-
return dir;
|
|
150
|
-
}
|
|
151
|
-
/** Lance `npm <args>` dans un projet du clone et rend son code de sortie et ses sorties. */
|
|
152
|
-
export function runSandboxedNpm(sandbox, project, args, options = {}) {
|
|
153
|
-
const cwd = projectDir(sandbox, project);
|
|
154
|
-
fs.mkdirSync(sandbox.cache, { recursive: true });
|
|
155
|
-
if ((options.platform ?? process.platform) === "linux") {
|
|
156
|
-
return runCommand("bwrap", bwrapArgs(sandbox, cwd, args, options.env), { cwd: sandbox.root, env: {}, signal: options.signal });
|
|
157
|
-
}
|
|
158
|
-
return runCommand("npm", args, { cwd, env: npmEnv(sandbox, sandbox.cache, options.env), signal: options.signal });
|
|
159
|
-
}
|
package/dist/src/npm-tools.d.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { type CallToolResult } from "@modelcontextprotocol/sdk/types.js";
|
|
2
|
-
import { type AuditScope } from "../shared/schemas/model.schema.js";
|
|
3
|
-
import { type NpmSandbox } from "./core/npm-sandbox.js";
|
|
4
|
-
import { type Args } from "./tools/types.js";
|
|
5
|
-
/** Arguments npm de l'outil appelé. */
|
|
6
|
-
export declare function npmArgs(tool: string, args: Args, scope: AuditScope): string[];
|
|
7
|
-
/** Lance l'outil et décrit le résultat : commande, code de sortie, fin des sorties. */
|
|
8
|
-
export declare function callNpmTool(sandbox: NpmSandbox, scope: AuditScope, tool: string, args: Args): Promise<CallToolResult>;
|
|
9
|
-
/** Lit `--root`, `--cache` et `--scope`, puis sert les outils sur stdio. */
|
|
10
|
-
export declare function serveNpmTools(argv: string[]): Promise<void>;
|
package/dist/src/npm-tools.js
DELETED
|
@@ -1,136 +0,0 @@
|
|
|
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
|
-
}
|