@imenam/mcp-dependabot-tracker 1.0.30 → 1.0.32
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 +41 -28
- package/dist/shared/schemas/model.schema.d.ts +64 -8
- package/dist/shared/schemas/model.schema.js +23 -8
- package/dist/src/core/commands.d.ts +5 -7
- package/dist/src/core/commands.js +7 -11
- 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 +20 -13
- package/dist/src/core/repair.js +110 -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/store.js +3 -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.js +2 -0
- 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
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import type { AuditScope, ManagerId, Vulnerability } from "../../../shared/schemas/model.schema.js";
|
|
2
|
+
import type { CommandResult } from "../commands.js";
|
|
3
|
+
import { type ContainerCommand, type ContainerRuntime, type Workspace } from "../containers.js";
|
|
4
|
+
/** Ce dont un gestionnaire a besoin pour lancer ses commandes dans les conteneurs d'une opération. */
|
|
5
|
+
export interface ManagerContext {
|
|
6
|
+
runtime: ContainerRuntime;
|
|
7
|
+
workspace: Workspace;
|
|
8
|
+
scope: AuditScope;
|
|
9
|
+
signal?: AbortSignal;
|
|
10
|
+
/** Journal de l'opération. */
|
|
11
|
+
log: (text: string) => void;
|
|
12
|
+
}
|
|
13
|
+
/** Image d'un conteneur : téléchargée telle quelle, ou construite à partir d'un Containerfile. */
|
|
14
|
+
export interface ImageSpec {
|
|
15
|
+
name: string;
|
|
16
|
+
containerfile?: string;
|
|
17
|
+
}
|
|
18
|
+
/** Résultat de l'audit d'un projet. */
|
|
19
|
+
export interface AuditResult {
|
|
20
|
+
vulnerabilities: Vulnerability[];
|
|
21
|
+
/** Vulnérabilités réduites à ce qui sert les corrections par Claude. */
|
|
22
|
+
facts: unknown[];
|
|
23
|
+
}
|
|
24
|
+
/** Paquets installés d'un projet d'après son lockfile : version par nom (ou chemin d'installation). */
|
|
25
|
+
export type Lockfile = Record<string, string>;
|
|
26
|
+
/** Outil d'un gestionnaire, servi à Claude par le serveur MCP `packages`. */
|
|
27
|
+
export interface ManagerTool {
|
|
28
|
+
name: string;
|
|
29
|
+
description: string;
|
|
30
|
+
/** Propriétés de l'outil, en plus de `project`. */
|
|
31
|
+
properties: Record<string, unknown>;
|
|
32
|
+
required: string[];
|
|
33
|
+
/** Arguments du gestionnaire pour un appel ; lève une erreur sur un argument refusé. */
|
|
34
|
+
args: (args: Record<string, unknown> | undefined, scope: AuditScope) => string[];
|
|
35
|
+
}
|
|
36
|
+
/** Gestionnaire de paquets : comment repérer ses projets, les auditer, les corriger et lire leurs lockfiles. */
|
|
37
|
+
export interface PackageManager {
|
|
38
|
+
id: ManagerId;
|
|
39
|
+
/** Lockfile suivi par git qui fait d'un dossier un projet de ce gestionnaire. */
|
|
40
|
+
lockfile: string;
|
|
41
|
+
/** Manifeste du projet, à côté du lockfile. */
|
|
42
|
+
manifest: string;
|
|
43
|
+
/** Image des conteneurs d'un projet. */
|
|
44
|
+
image: (ctx: ManagerContext, project: string) => ImageSpec;
|
|
45
|
+
/** Commande du conteneur qui lance le gestionnaire avec `args` dans un projet. */
|
|
46
|
+
command: (ctx: ManagerContext, project: string, args: string[]) => ContainerCommand;
|
|
47
|
+
audit: (ctx: ManagerContext, project: string) => Promise<AuditResult>;
|
|
48
|
+
/** Corrections automatiques d'un projet vulnérable, sans installation ni script. */
|
|
49
|
+
fix: (ctx: ManagerContext, project: string, vulnerabilities: Vulnerability[]) => Promise<void>;
|
|
50
|
+
/** Lit le contenu d'un lockfile ; lève une erreur sur un format non pris en charge. */
|
|
51
|
+
readLock: (text: string, project: string) => Lockfile;
|
|
52
|
+
/** Commande des corrections automatiques, telle que la pull request la cite. */
|
|
53
|
+
fixCommand: (scope: AuditScope) => string;
|
|
54
|
+
tools: ManagerTool[];
|
|
55
|
+
/** Consigne propre au gestionnaire, pour les corrections par Claude. */
|
|
56
|
+
guide: (scope: AuditScope, server: string) => string;
|
|
57
|
+
}
|
|
58
|
+
/** Préfixe d'affichage d'un projet : `""` pour la racine, `gui/` pour le dossier `gui`. */
|
|
59
|
+
export declare function projectLabel(project: string): string;
|
|
60
|
+
/** Lance le gestionnaire avec `args` dans un projet, dans un conteneur jetable, et note la commande au journal. */
|
|
61
|
+
export declare function runManager(manager: PackageManager, ctx: ManagerContext, project: string, args: string[]): Promise<CommandResult>;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { runInContainer } from "../containers.js";
|
|
2
|
+
/** Préfixe d'affichage d'un projet : `""` pour la racine, `gui/` pour le dossier `gui`. */
|
|
3
|
+
export function projectLabel(project) {
|
|
4
|
+
return project === "" ? "" : `${project}/`;
|
|
5
|
+
}
|
|
6
|
+
/** Lance le gestionnaire avec `args` dans un projet, dans un conteneur jetable, et note la commande au journal. */
|
|
7
|
+
export function runManager(manager, ctx, project, args) {
|
|
8
|
+
const spec = manager.command(ctx, project, args);
|
|
9
|
+
ctx.log(`$ ${spec.command.join(" ")}${project ? ` (in ${project})` : ""}`);
|
|
10
|
+
return runInContainer(ctx.runtime, ctx.workspace, spec, { signal: ctx.signal });
|
|
11
|
+
}
|
|
@@ -2,6 +2,7 @@ import { type AuditScope, type Operation, type Origin } from "../../shared/schem
|
|
|
2
2
|
import type { Settings } from "../../shared/schemas/settings.schema.js";
|
|
3
3
|
import { type ClaudeRuntime } from "./claude.js";
|
|
4
4
|
import type { GitHubConfig } from "./config.js";
|
|
5
|
+
import { type ContainerRuntime } from "./containers.js";
|
|
5
6
|
import { type Store } from "./store.js";
|
|
6
7
|
/** Accès aux données et à GitHub pour exécuter les opérations. */
|
|
7
8
|
export interface OperationContext {
|
|
@@ -16,22 +17,24 @@ export interface OperationContext {
|
|
|
16
17
|
settings: () => Settings;
|
|
17
18
|
/** Commande et dossier de configuration de Claude Code. */
|
|
18
19
|
claude: ClaudeRuntime;
|
|
20
|
+
/** Podman, qui exécute les commandes des gestionnaires de paquets. */
|
|
21
|
+
containers: ContainerRuntime;
|
|
19
22
|
}
|
|
20
23
|
/**
|
|
21
24
|
* Choix d'une correction : le périmètre, et les corrections par Claude quand
|
|
22
|
-
*
|
|
25
|
+
* les corrections automatiques laissent des vulnérabilités.
|
|
23
26
|
*/
|
|
24
27
|
export interface FixPlan {
|
|
25
28
|
scope: AuditScope;
|
|
26
29
|
claude: boolean;
|
|
27
30
|
}
|
|
28
|
-
/** `fix/
|
|
31
|
+
/** `fix/deps-audit-2026-10-28-143205`, à l'heure locale du serveur. */
|
|
29
32
|
export declare function branchName(date: Date): string;
|
|
30
|
-
/** Vrai pour une branche nommée par `branchName
|
|
33
|
+
/** Vrai pour une branche du tracker : `fix/deps-audit-…`, nommée par `branchName`, ou `fix/npm-audit-…`. */
|
|
31
34
|
export declare function isTrackerBranch(branch: string): boolean;
|
|
32
35
|
/**
|
|
33
36
|
* Lance une correction de la branche analysée, lancée par `origin`, menée en
|
|
34
|
-
* arrière-plan jusqu'au bout sans intervention : clone, audit,
|
|
37
|
+
* arrière-plan jusqu'au bout sans intervention : clone, audit, corrections automatiques,
|
|
35
38
|
* corrections par Claude s'il reste des vulnérabilités et que `plan` les
|
|
36
39
|
* demande, puis commit, push et pull request s'il y a quelque chose à pousser.
|
|
37
40
|
* Refusé si une opération est en cours sur le dépôt, ou s'il est déprécié.
|
|
@@ -39,7 +42,7 @@ export declare function isTrackerBranch(branch: string): boolean;
|
|
|
39
42
|
export declare function startFix(ctx: OperationContext, repoId: string, origin: Origin, plan: FixPlan): Operation;
|
|
40
43
|
/**
|
|
41
44
|
* Lance un audit de la branche analysée sur le périmètre `scope`, lancé par
|
|
42
|
-
* `origin` et mené en arrière-plan : clone et
|
|
45
|
+
* `origin` et mené en arrière-plan : clone et audit, sans rien modifier.
|
|
43
46
|
* Refusé si une opération est en cours sur le dépôt, ou s'il est déprécié.
|
|
44
47
|
*/
|
|
45
48
|
export declare function startAudit(ctx: OperationContext, repoId: string, origin: Origin, scope: AuditScope): Operation;
|
|
@@ -6,9 +6,10 @@ import { activityLine } from "./claude.js";
|
|
|
6
6
|
import { CommandAbortedError, runCommand, tail } from "./commands.js";
|
|
7
7
|
import { ConflictError, TrackerError } from "./errors.js";
|
|
8
8
|
import { GitHubClient } from "./github.js";
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
9
|
+
import { CACHE_DIR, assertContainersAvailable, buildImage, imageId, pullImage, removeImage } from "./containers.js";
|
|
10
|
+
import { PACKAGE_MANAGERS, detectProjects, diffLockfiles, installedDirs, lockfilePath, managerOf } from "./managers/index.js";
|
|
11
|
+
import { projectLabel } from "./managers/types.js";
|
|
12
|
+
import { repairVulnerabilities } from "./repair.js";
|
|
12
13
|
import { assertNotDeprecated, isActive } from "./store.js";
|
|
13
14
|
/** Signal d'annulation de chaque opération en cours, par identifiant. */
|
|
14
15
|
const runningOperations = new Map();
|
|
@@ -24,8 +25,14 @@ const MAX_PR_CHANGES = 60;
|
|
|
24
25
|
const CLAUDE_ACTIVITY = 3;
|
|
25
26
|
/** Éléments du déroulé de la session de Claude gardés, les plus récents. */
|
|
26
27
|
const SESSION_EVENTS = 500;
|
|
27
|
-
/**
|
|
28
|
-
|
|
28
|
+
/**
|
|
29
|
+
* Fichiers suivis par les commits du tracker : tout le clone, sauf les
|
|
30
|
+
* dépendances qu'installe Claude, `node_modules` et le `vendor` des projets
|
|
31
|
+
* Composer.
|
|
32
|
+
*/
|
|
33
|
+
function stagedPaths(projects) {
|
|
34
|
+
return ["--", ".", ":(exclude,glob)**/node_modules/**", ...projects.flatMap(installedDirs).map((dir) => `:(exclude,glob)${dir}/**`)];
|
|
35
|
+
}
|
|
29
36
|
/**
|
|
30
37
|
* Fichiers que le bac à sable de Claude Code garde en lecture seule. Absents
|
|
31
38
|
* du dépôt, il les crée vides dans le clone pour les monter : ces fichiers-là
|
|
@@ -37,15 +44,15 @@ const CLAUDE_TRAILER = "Co-Authored-By: Claude <noreply@anthropic.com>";
|
|
|
37
44
|
function now() {
|
|
38
45
|
return new Date().toISOString();
|
|
39
46
|
}
|
|
40
|
-
/** `fix/
|
|
47
|
+
/** `fix/deps-audit-2026-10-28-143205`, à l'heure locale du serveur. */
|
|
41
48
|
export function branchName(date) {
|
|
42
49
|
const pad = (value) => String(value).padStart(2, "0");
|
|
43
50
|
const day = `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())}`;
|
|
44
|
-
return `fix/
|
|
51
|
+
return `fix/deps-audit-${day}-${pad(date.getHours())}${pad(date.getMinutes())}${pad(date.getSeconds())}`;
|
|
45
52
|
}
|
|
46
|
-
/** Vrai pour une branche nommée par `branchName
|
|
53
|
+
/** Vrai pour une branche du tracker : `fix/deps-audit-…`, nommée par `branchName`, ou `fix/npm-audit-…`. */
|
|
47
54
|
export function isTrackerBranch(branch) {
|
|
48
|
-
return /^fix\/npm-audit-\d{4}-\d{2}-\d{2}-\d{6}$/.test(branch);
|
|
55
|
+
return /^fix\/(deps|npm)-audit-\d{4}-\d{2}-\d{2}-\d{6}$/.test(branch);
|
|
49
56
|
}
|
|
50
57
|
/** Réglages de toutes les commandes git : aucun hook, aucun moniteur de fichiers. */
|
|
51
58
|
const GIT_SETTINGS = [
|
|
@@ -66,16 +73,6 @@ function gitEnv(settings) {
|
|
|
66
73
|
});
|
|
67
74
|
return env;
|
|
68
75
|
}
|
|
69
|
-
/**
|
|
70
|
-
* Environnement des commandes npm. `allow_remote` autorise le téléchargement des
|
|
71
|
-
* archives de paquets à `bundleDependencies` (ex. `@tailwindcss/oxide-wasm32-wasi`),
|
|
72
|
-
* que npm 12 classe en dépendances distantes avec `--package-lock-only`.
|
|
73
|
-
*/
|
|
74
|
-
const NPM_ENV = { npm_config_fund: "false", npm_config_allow_remote: "all" };
|
|
75
|
-
/** Options npm qui limitent l'audit et ses corrections au périmètre `scope`. */
|
|
76
|
-
function scopeArgs(scope) {
|
|
77
|
-
return scope === "production" ? ["--omit=dev"] : [];
|
|
78
|
-
}
|
|
79
76
|
/** Sous-commande git d'une liste d'arguments, après les options `-c clé=valeur`. */
|
|
80
77
|
function subcommand(args) {
|
|
81
78
|
let index = 0;
|
|
@@ -118,13 +115,17 @@ class Runner {
|
|
|
118
115
|
signal;
|
|
119
116
|
config;
|
|
120
117
|
cloneDir;
|
|
121
|
-
|
|
118
|
+
containers;
|
|
119
|
+
constructor(ctx, id, signal, config, cloneDir, containers) {
|
|
122
120
|
this.ctx = ctx;
|
|
123
121
|
this.id = id;
|
|
124
122
|
this.signal = signal;
|
|
125
123
|
this.config = config;
|
|
126
124
|
this.cloneDir = cloneDir;
|
|
125
|
+
this.containers = containers;
|
|
127
126
|
}
|
|
127
|
+
/** Vulnérabilités du dernier audit, réduites à ce qui sert les corrections par Claude. */
|
|
128
|
+
facts = [];
|
|
128
129
|
get operation() {
|
|
129
130
|
return this.ctx.store.getOperation(this.id);
|
|
130
131
|
}
|
|
@@ -178,25 +179,22 @@ class Runner {
|
|
|
178
179
|
}
|
|
179
180
|
return result.stdout;
|
|
180
181
|
}
|
|
181
|
-
/**
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
this.log(
|
|
188
|
-
const sandbox = { root: this.repoDir, cache: path.join(this.operation.workDir, NPM_CACHE_DIR) };
|
|
189
|
-
const result = await runSandboxedNpm(sandbox, project, args, { env: NPM_ENV, signal: this.signal });
|
|
190
|
-
return parseNpmJson(result.stdout, result.stderr, `npm ${args.slice(0, args.indexOf("--json")).join(" ")} in ${projectLabel(project) || "./"}`);
|
|
182
|
+
/** Clone et cache de l'opération, montés dans les conteneurs. */
|
|
183
|
+
get workspace() {
|
|
184
|
+
return { root: this.repoDir, cache: path.join(this.operation.workDir, CACHE_DIR) };
|
|
185
|
+
}
|
|
186
|
+
/** Contexte des commandes des gestionnaires de paquets de l'opération. */
|
|
187
|
+
get managers() {
|
|
188
|
+
return { runtime: this.containers, workspace: this.workspace, scope: this.operation.scope, signal: this.signal, log: (text) => this.log(text) };
|
|
191
189
|
}
|
|
192
190
|
readLock(project) {
|
|
193
|
-
const file = path.join(this.repoDir, project
|
|
194
|
-
return
|
|
191
|
+
const file = path.join(this.repoDir, lockfilePath(project));
|
|
192
|
+
return managerOf(project.manager).readLock(fs.readFileSync(file, "utf-8"), project.path);
|
|
195
193
|
}
|
|
196
194
|
/**
|
|
197
195
|
* Commit cloné : HEAD tant que le tracker n'a rien commité ; après le commit
|
|
198
|
-
*
|
|
199
|
-
* par Claude.
|
|
196
|
+
* des corrections automatiques, son parent, et sans ce commit, la base des
|
|
197
|
+
* corrections par Claude.
|
|
200
198
|
*/
|
|
201
199
|
get clonedCommit() {
|
|
202
200
|
const repair = this.operation.repair;
|
|
@@ -206,14 +204,13 @@ class Runner {
|
|
|
206
204
|
}
|
|
207
205
|
/** Lockfile du projet tel qu'il est dans le commit cloné. */
|
|
208
206
|
async originalLock(project) {
|
|
209
|
-
|
|
210
|
-
return parseLockfile(await this.git(["show", `${this.clonedCommit}:${file}`]), project);
|
|
207
|
+
return managerOf(project.manager).readLock(await this.git(["show", `${this.clonedCommit}:${lockfilePath(project)}`]), project.path);
|
|
211
208
|
}
|
|
212
209
|
}
|
|
213
210
|
// --- Étapes -------------------------------------------------------------------
|
|
214
211
|
async function cloneStep(runner) {
|
|
215
212
|
runner.setStep("clone", "running");
|
|
216
|
-
await
|
|
213
|
+
await assertContainersAvailable(runner.containers, runner.cloneDir);
|
|
217
214
|
const operation = runner.operation;
|
|
218
215
|
const [owner, name] = operation.repoId.split("/");
|
|
219
216
|
const workDir = fs.mkdtempSync(path.join(runner.cloneDir, "mcp-dependabot-tracker-"));
|
|
@@ -222,25 +219,56 @@ async function cloneStep(runner) {
|
|
|
222
219
|
await runner.git(["-c", "core.autocrlf=false", "clone", "--depth", "1", "--branch", operation.baseBranch, "--single-branch", "--separate-git-dir", GIT_DIR, url, CLONE_DIR], { cwd: workDir, auth: true });
|
|
223
220
|
fs.rmSync(path.join(workDir, CLONE_DIR, ".git"));
|
|
224
221
|
const files = (await runner.git(["ls-files", "-z"])).split("\0");
|
|
225
|
-
const projects = files
|
|
226
|
-
.filter((file) => file === "package-lock.json" || file.endsWith("/package-lock.json"))
|
|
227
|
-
.map((file) => path.posix.dirname(file))
|
|
228
|
-
.map((dir) => (dir === "." ? "" : dir))
|
|
229
|
-
.sort();
|
|
222
|
+
const projects = detectProjects(files);
|
|
230
223
|
if (projects.length === 0) {
|
|
231
|
-
|
|
224
|
+
const lockfiles = PACKAGE_MANAGERS.map((manager) => manager.lockfile).join(", ");
|
|
225
|
+
throw new TrackerError(`No lockfile is tracked in ${operation.repoId}: the audit needs one of ${lockfiles}.`);
|
|
232
226
|
}
|
|
233
227
|
runner.update((current) => ({ ...current, projects }));
|
|
234
|
-
runner.log(`
|
|
228
|
+
runner.log(`Projects: ${projects.map((project) => `${projectLabel(project.path) || "./"} (${project.manager})`).join(", ")}`);
|
|
229
|
+
await prepareImages(runner, projects);
|
|
235
230
|
runner.setStep("clone", "done");
|
|
236
231
|
}
|
|
237
|
-
/**
|
|
232
|
+
/**
|
|
233
|
+
* Met à jour, ou construit, une fois chacune, les images des conteneurs des
|
|
234
|
+
* projets, puis supprime la version précédente d'une image qui a changé. Une
|
|
235
|
+
* version précédente que Podman refuse de supprimer (encore utilisée par un
|
|
236
|
+
* conteneur) est laissée, et le refus noté au journal.
|
|
237
|
+
*/
|
|
238
|
+
async function prepareImages(runner, projects) {
|
|
239
|
+
const ready = new Set();
|
|
240
|
+
for (const project of projects) {
|
|
241
|
+
const image = managerOf(project.manager).image(runner.managers, project.path);
|
|
242
|
+
if (ready.has(image.name))
|
|
243
|
+
continue;
|
|
244
|
+
ready.add(image.name);
|
|
245
|
+
const previous = await imageId(runner.containers, image.name, runner.cloneDir);
|
|
246
|
+
if (image.containerfile === undefined) {
|
|
247
|
+
runner.log(`$ podman pull ${image.name}`);
|
|
248
|
+
await pullImage(runner.containers, image.name, runner.cloneDir, runner.signal);
|
|
249
|
+
}
|
|
250
|
+
else {
|
|
251
|
+
runner.log(`$ podman build --tag ${image.name}`);
|
|
252
|
+
await buildImage(runner.containers, image.name, image.containerfile, runner.signal);
|
|
253
|
+
}
|
|
254
|
+
if (previous === null || previous === (await imageId(runner.containers, image.name, runner.cloneDir)))
|
|
255
|
+
continue;
|
|
256
|
+
runner.log(`$ podman rmi ${previous}`);
|
|
257
|
+
const refused = await removeImage(runner.containers, previous, runner.cloneDir);
|
|
258
|
+
if (refused)
|
|
259
|
+
runner.log(`The previous version of ${image.name} is kept: ${refused}`);
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
/** Audit de chaque projet ; enregistre le total sous `count` et les vulnérabilités restantes. */
|
|
238
263
|
async function auditAll(runner, count) {
|
|
239
264
|
const vulnerabilities = [];
|
|
265
|
+
const facts = [];
|
|
240
266
|
for (const project of runner.operation.projects) {
|
|
241
|
-
const
|
|
242
|
-
vulnerabilities.push(...
|
|
267
|
+
const result = await managerOf(project.manager).audit(runner.managers, project.path);
|
|
268
|
+
vulnerabilities.push(...result.vulnerabilities);
|
|
269
|
+
facts.push(...result.facts);
|
|
243
270
|
}
|
|
271
|
+
runner.facts = facts;
|
|
244
272
|
runner.log(`${vulnerabilities.length} vulnerabilit${vulnerabilities.length === 1 ? "y" : "ies"}`);
|
|
245
273
|
runner.update((operation) => ({
|
|
246
274
|
...operation,
|
|
@@ -249,14 +277,6 @@ async function auditAll(runner, count) {
|
|
|
249
277
|
}));
|
|
250
278
|
return vulnerabilities;
|
|
251
279
|
}
|
|
252
|
-
/** Vulnérabilités restantes de chaque projet, d'après un nouvel `npm audit`, sans toucher aux comptes de l'opération. */
|
|
253
|
-
async function currentAuditFacts(runner) {
|
|
254
|
-
const facts = [];
|
|
255
|
-
for (const project of runner.operation.projects) {
|
|
256
|
-
facts.push(...auditFacts(await runner.npm(project, ["audit", ...scopeArgs(runner.operation.scope), "--json"]), project));
|
|
257
|
-
}
|
|
258
|
-
return facts;
|
|
259
|
-
}
|
|
260
280
|
/** Paquets modifiés depuis le commit cloné, dans tous les projets. */
|
|
261
281
|
async function refreshChanges(runner) {
|
|
262
282
|
const changes = [];
|
|
@@ -272,12 +292,13 @@ async function auditStep(runner) {
|
|
|
272
292
|
runner.setStep("audit", "done");
|
|
273
293
|
return vulnerabilities;
|
|
274
294
|
}
|
|
275
|
-
/**
|
|
295
|
+
/** Corrections automatiques des projets vulnérables, sans installation ni script de paquet. */
|
|
276
296
|
async function fixStep(runner, vulnerabilities) {
|
|
277
297
|
runner.setStep("fix", "running");
|
|
278
|
-
const
|
|
279
|
-
|
|
280
|
-
|
|
298
|
+
for (const project of runner.operation.projects) {
|
|
299
|
+
const found = vulnerabilities.filter((vulnerability) => vulnerability.project === project.path && vulnerability.manager === project.manager);
|
|
300
|
+
if (found.length > 0)
|
|
301
|
+
await managerOf(project.manager).fix(runner.managers, project.path, found);
|
|
281
302
|
}
|
|
282
303
|
const remaining = await auditAll(runner, "afterFix");
|
|
283
304
|
await refreshChanges(runner);
|
|
@@ -294,15 +315,16 @@ async function hasStagedChanges(runner) {
|
|
|
294
315
|
return (await runner.git(["diff", "--cached", "--name-only"])).trim() !== "";
|
|
295
316
|
}
|
|
296
317
|
/**
|
|
297
|
-
* Crée la branche de la correction et y commite les
|
|
298
|
-
*
|
|
299
|
-
* corrections par Claude, et celui
|
|
318
|
+
* Crée la branche de la correction et y commite les fichiers modifiés par les
|
|
319
|
+
* corrections automatiques, s'ils ont changé ; rend le commit sur lequel
|
|
320
|
+
* reposeront les corrections par Claude, et celui des corrections
|
|
321
|
+
* automatiques, null sans changement.
|
|
300
322
|
*/
|
|
301
323
|
async function commitAuditFixes(runner) {
|
|
302
324
|
const branch = runner.operation.branch ?? branchName(new Date());
|
|
303
325
|
runner.update((operation) => ({ ...operation, branch }));
|
|
304
326
|
await runner.git(["checkout", "-b", branch]);
|
|
305
|
-
await runner.git(["add", "-A", ...
|
|
327
|
+
await runner.git(["add", "-A", ...stagedPaths(runner.operation.projects)]);
|
|
306
328
|
const committed = await hasStagedChanges(runner);
|
|
307
329
|
if (committed)
|
|
308
330
|
await runner.git([...(await commitIdentity(runner)), "commit", "-m", runner.operation.commitMessage]);
|
|
@@ -327,7 +349,7 @@ async function removeSandboxPlaceholders(runner) {
|
|
|
327
349
|
async function commitRepair(runner, base, message) {
|
|
328
350
|
await removeSandboxPlaceholders(runner);
|
|
329
351
|
await runner.git(["reset", "--soft", base]);
|
|
330
|
-
await runner.git(["add", "-A", ...
|
|
352
|
+
await runner.git(["add", "-A", ...stagedPaths(runner.operation.projects)]);
|
|
331
353
|
if (!(await hasStagedChanges(runner)))
|
|
332
354
|
return null;
|
|
333
355
|
await runner.git([...(await commitIdentity(runner)), "commit", "-m", message, "-m", CLAUDE_TRAILER]);
|
|
@@ -335,10 +357,11 @@ async function commitRepair(runner, base, message) {
|
|
|
335
357
|
}
|
|
336
358
|
/**
|
|
337
359
|
* Corrections par Claude des vulnérabilités restantes : la branche est créée et
|
|
338
|
-
*
|
|
339
|
-
* dont les changements font un seul commit. Un échec,
|
|
340
|
-
* comprise, remet le clone dans l'état du commit
|
|
341
|
-
* l'opération se poursuivre ; seule une
|
|
360
|
+
* les corrections automatiques y sont commitées, puis Claude analyse et corrige
|
|
361
|
+
* en une session, dont les changements font un seul commit. Un échec,
|
|
362
|
+
* configuration manquante comprise, remet le clone dans l'état du commit des
|
|
363
|
+
* corrections automatiques et laisse l'opération se poursuivre ; seule une
|
|
364
|
+
* annulation l'interrompt.
|
|
342
365
|
*/
|
|
343
366
|
async function repairStep(runner, ctx) {
|
|
344
367
|
runner.setStep("repair", "running");
|
|
@@ -354,7 +377,9 @@ async function repairStep(runner, ctx) {
|
|
|
354
377
|
scope: operation.scope,
|
|
355
378
|
cwd: runner.repoDir,
|
|
356
379
|
workDir: operation.workDir,
|
|
357
|
-
|
|
380
|
+
containers: ctx.containers,
|
|
381
|
+
managers: [...new Set(operation.projects.map((project) => project.manager))],
|
|
382
|
+
facts: runner.facts,
|
|
358
383
|
settings: ctx.settings(),
|
|
359
384
|
claude: ctx.claude,
|
|
360
385
|
signal: runner.signal,
|
|
@@ -370,7 +395,8 @@ async function repairStep(runner, ctx) {
|
|
|
370
395
|
},
|
|
371
396
|
});
|
|
372
397
|
const commit = await commitRepair(runner, base, report.commitMessage);
|
|
373
|
-
|
|
398
|
+
if (task)
|
|
399
|
+
runner.log(`Report of Claude ${task.key}: ${task.url}`);
|
|
374
400
|
await auditAll(runner, "afterRepair");
|
|
375
401
|
await refreshChanges(runner);
|
|
376
402
|
repaired((current) => ({ ...current, endedAt: now(), commit, report, task }));
|
|
@@ -391,7 +417,7 @@ async function repairStep(runner, ctx) {
|
|
|
391
417
|
function pullRequestWarnings(operation) {
|
|
392
418
|
const repair = operation.repair;
|
|
393
419
|
if (repair?.error) {
|
|
394
|
-
return [`> [!WARNING]`, `> Claude Code could not fix the remaining vulnerabilities: ${repair.error}`, `> This pull request only holds the fixes of
|
|
420
|
+
return [`> [!WARNING]`, `> Claude Code could not fix the remaining vulnerabilities: ${repair.error}`, `> This pull request only holds the automatic fixes of the package managers.`, ""];
|
|
395
421
|
}
|
|
396
422
|
if (repair?.report?.tests.outcome === "failed") {
|
|
397
423
|
return [`> [!WARNING]`, `> The tests failed after the fixes by Claude Code: ${repair.report.tests.detail}`, ""];
|
|
@@ -401,10 +427,11 @@ function pullRequestWarnings(operation) {
|
|
|
401
427
|
function pullRequestBody(operation) {
|
|
402
428
|
const after = operation.counts.afterRepair ?? operation.counts.afterFix;
|
|
403
429
|
const repair = operation.repair?.report ? operation.repair : null;
|
|
404
|
-
const
|
|
430
|
+
const managers = PACKAGE_MANAGERS.filter((manager) => operation.projects.some((project) => project.manager === manager.id));
|
|
431
|
+
const commands = managers.map((manager) => `\`${manager.fixCommand(operation.scope)}\``).join(", ");
|
|
405
432
|
const lines = [
|
|
406
433
|
...pullRequestWarnings(operation),
|
|
407
|
-
`Automated
|
|
434
|
+
`Automated dependency audit fixes, made by mcp-dependabot-tracker in a temporary clone (${commands}).`,
|
|
408
435
|
"",
|
|
409
436
|
operation.scope === "production"
|
|
410
437
|
? "- Scope: production dependencies only; the vulnerabilities of the devDependencies were neither audited nor fixed."
|
|
@@ -422,6 +449,8 @@ function pullRequestBody(operation) {
|
|
|
422
449
|
lines.push(`- … and ${operation.changes.length - MAX_PR_CHANGES} more`);
|
|
423
450
|
if (repair?.report) {
|
|
424
451
|
lines.push("", `Fixes by Claude Code${repair.task ? `, reported in organizer task ${repair.task.key}` : ""}:`, "", repair.report.summary, "");
|
|
452
|
+
if (repair.report.details)
|
|
453
|
+
lines.push("<details>", "<summary>Rapport de Claude</summary>", "", repair.report.details, "", "</details>", "");
|
|
425
454
|
for (const change of repair.report.changes)
|
|
426
455
|
lines.push(`- \`${change.file}\`: ${change.change}`);
|
|
427
456
|
lines.push(`- Tests: ${repair.report.tests.outcome.replace("_", " ")} — ${repair.report.tests.detail}`);
|
|
@@ -443,7 +472,7 @@ async function pushStep(runner) {
|
|
|
443
472
|
runner.update((current) => ({ ...current, branch }));
|
|
444
473
|
if (!operation.repair) {
|
|
445
474
|
await runner.git(["checkout", "-b", branch]);
|
|
446
|
-
await runner.git(["add", "-A", ...
|
|
475
|
+
await runner.git(["add", "-A", ...stagedPaths(runner.operation.projects)]);
|
|
447
476
|
if (!(await hasStagedChanges(runner)))
|
|
448
477
|
throw new TrackerError("Nothing to commit: the fixes left the files unchanged.");
|
|
449
478
|
await runner.git([...(await commitIdentity(runner)), "commit", "-m", operation.commitMessage]);
|
|
@@ -483,7 +512,7 @@ async function execute(ctx, id, body) {
|
|
|
483
512
|
const controller = new AbortController();
|
|
484
513
|
runningOperations.set(id, controller);
|
|
485
514
|
try {
|
|
486
|
-
const runner = new Runner(ctx, id, controller.signal, ctx.githubConfig(), ctx.cloneDir());
|
|
515
|
+
const runner = new Runner(ctx, id, controller.signal, ctx.githubConfig(), ctx.cloneDir(), ctx.containers);
|
|
487
516
|
await body(runner);
|
|
488
517
|
}
|
|
489
518
|
catch (err) {
|
|
@@ -518,7 +547,7 @@ function inBackground(ctx, id, run) {
|
|
|
518
547
|
// --- Entrées ---------------------------------------------------------------------
|
|
519
548
|
/**
|
|
520
549
|
* Lance une correction de la branche analysée, lancée par `origin`, menée en
|
|
521
|
-
* arrière-plan jusqu'au bout sans intervention : clone, audit,
|
|
550
|
+
* arrière-plan jusqu'au bout sans intervention : clone, audit, corrections automatiques,
|
|
522
551
|
* corrections par Claude s'il reste des vulnérabilités et que `plan` les
|
|
523
552
|
* demande, puis commit, push et pull request s'il y a quelque chose à pousser.
|
|
524
553
|
* Refusé si une opération est en cours sur le dépôt, ou s'il est déprécié.
|
|
@@ -548,7 +577,7 @@ export function startFix(ctx, repoId, origin, plan) {
|
|
|
548
577
|
}
|
|
549
578
|
/**
|
|
550
579
|
* Lance un audit de la branche analysée sur le périmètre `scope`, lancé par
|
|
551
|
-
* `origin` et mené en arrière-plan : clone et
|
|
580
|
+
* `origin` et mené en arrière-plan : clone et audit, sans rien modifier.
|
|
552
581
|
* Refusé si une opération est en cours sur le dépôt, ou s'il est déprécié.
|
|
553
582
|
*/
|
|
554
583
|
export function startAudit(ctx, repoId, origin, scope) {
|
|
@@ -1,15 +1,17 @@
|
|
|
1
|
-
import { type AuditScope, type Operation, type OrganizerTask, type RepairReport, type SessionEvent } from "../../shared/schemas/model.schema.js";
|
|
1
|
+
import { type AuditScope, type ManagerId, type Operation, type OrganizerTask, type RepairReport, type SessionEvent } from "../../shared/schemas/model.schema.js";
|
|
2
2
|
import type { Settings } from "../../shared/schemas/settings.schema.js";
|
|
3
3
|
import { type ClaudeRuntime } from "./claude.js";
|
|
4
|
+
import { type ContainerRuntime } from "./containers.js";
|
|
4
5
|
import { type OrganizerConnection } from "./organizer.js";
|
|
5
6
|
import type { Store } from "./store.js";
|
|
6
7
|
/**
|
|
7
|
-
* Corrections par Claude des vulnérabilités que
|
|
8
|
-
* clone, en une seule session. Claude analyse chaque
|
|
9
|
-
* code, la corrige quand il le peut en modifiant le clone
|
|
10
|
-
* Edit, Write), sans git ni écriture hors du clone, et lance
|
|
11
|
-
* (lockfile, audit, installation,
|
|
12
|
-
*
|
|
8
|
+
* Corrections par Claude des vulnérabilités que les corrections automatiques
|
|
9
|
+
* laissent dans un clone, en une seule session. Claude analyse chaque
|
|
10
|
+
* vulnérabilité dans le code, la corrige quand il le peut en modifiant le clone
|
|
11
|
+
* (Read, Grep, Glob, Edit, Write), sans git ni écriture hors du clone, et lance
|
|
12
|
+
* les commandes des gestionnaires de paquets (lockfile, audit, installation,
|
|
13
|
+
* tests) par les outils du serveur `package-tools`, que le tracker exécute
|
|
14
|
+
* dans des conteneurs jetables, sans aucun token. Il rend
|
|
13
15
|
* compte de son travail dans une seule tâche de l'organizer, assignée au
|
|
14
16
|
* propriétaire de l'espace et taguée du nom du dépôt, puis rend un rapport
|
|
15
17
|
* structuré. Le tracker relit la tâche sur l'organizer : absente, mal assignée
|
|
@@ -17,8 +19,8 @@ import type { Store } from "./store.js";
|
|
|
17
19
|
*/
|
|
18
20
|
/** Nom du serveur MCP organizer dans la configuration de la session. */
|
|
19
21
|
export declare const ORGANIZER_SERVER = "organizer";
|
|
20
|
-
/**
|
|
21
|
-
export declare
|
|
22
|
+
/** Serveur MCP des commandes des gestionnaires de paquets, dans la configuration de la session. */
|
|
23
|
+
export declare const PACKAGES_SERVER = "packages";
|
|
22
24
|
/** JSON des vulnérabilités dans la limite de taille ; au-delà, les dernières sont seulement comptées. */
|
|
23
25
|
export declare function factsJson(facts: unknown[]): string;
|
|
24
26
|
/** Serveur MCP organizer de la session, lancé par `npx` avec le token réglé dans la GUI. */
|
|
@@ -38,7 +40,11 @@ export interface RepairInput {
|
|
|
38
40
|
cwd: string;
|
|
39
41
|
/** Dossier de l'opération, hors du clone : configuration MCP de la session. */
|
|
40
42
|
workDir: string;
|
|
41
|
-
/**
|
|
43
|
+
/** Podman, qui exécute les commandes des gestionnaires de paquets de Claude. */
|
|
44
|
+
containers: ContainerRuntime;
|
|
45
|
+
/** Gestionnaires de paquets des projets du dépôt. */
|
|
46
|
+
managers: ManagerId[];
|
|
47
|
+
/** Vulnérabilités restantes, d'après le dernier audit. */
|
|
42
48
|
facts: unknown[];
|
|
43
49
|
settings: Settings;
|
|
44
50
|
claude: ClaudeRuntime;
|
|
@@ -46,12 +52,13 @@ export interface RepairInput {
|
|
|
46
52
|
onEvent: (event: SessionEvent, turns: number) => void;
|
|
47
53
|
}
|
|
48
54
|
/**
|
|
49
|
-
* Lance les corrections
|
|
50
|
-
*
|
|
55
|
+
* Lance les corrections. Avec l'organizer, Claude rend compte dans une tâche,
|
|
56
|
+
* que le tracker vérifie ensuite ; sans, son rapport détaillé rejoint la pull
|
|
57
|
+
* request. Lève une erreur sans le token Claude.
|
|
51
58
|
*/
|
|
52
59
|
export declare function repairVulnerabilities(input: RepairInput): Promise<{
|
|
53
60
|
report: RepairReport;
|
|
54
|
-
task: OrganizerTask;
|
|
61
|
+
task: OrganizerTask | null;
|
|
55
62
|
}>;
|
|
56
63
|
/** Dernière opération du dépôt dont les corrections ont créé une tâche ; `operations` va de la plus récente à la plus ancienne. */
|
|
57
64
|
export declare function latestReported(operations: Operation[]): Operation | null;
|