@imenam/mcp-dependabot-tracker 1.0.10 → 1.0.11
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 +33 -14
- package/dist/shared/alerts.d.ts +6 -1
- package/dist/shared/alerts.js +7 -0
- package/dist/shared/schemas/api.schema.d.ts +41 -9
- package/dist/shared/schemas/api.schema.js +5 -1
- package/dist/shared/schemas/ipc.schema.d.ts +1 -1
- package/dist/shared/schemas/ipc.schema.js +2 -0
- package/dist/shared/schemas/model.schema.d.ts +159 -7
- package/dist/shared/schemas/model.schema.js +63 -8
- package/dist/src/core/analysis.d.ts +26 -1
- package/dist/src/core/analysis.js +6 -3
- package/dist/src/core/audit-all.d.ts +6 -6
- package/dist/src/core/audit-all.js +6 -6
- package/dist/src/core/claude.d.ts +2 -0
- package/dist/src/core/claude.js +8 -4
- package/dist/src/core/github.js +2 -1
- package/dist/src/core/operations.d.ts +21 -12
- package/dist/src/core/operations.js +224 -43
- package/dist/src/core/organizer.d.ts +14 -0
- package/dist/src/core/organizer.js +17 -2
- package/dist/src/core/repair.d.ts +31 -0
- package/dist/src/core/repair.js +150 -0
- package/dist/src/core/repos.d.ts +11 -8
- package/dist/src/core/repos.js +38 -20
- package/dist/src/core/store.d.ts +2 -0
- package/dist/src/core/store.js +14 -5
- package/dist/src/gui-worker.js +20 -3
- package/dist/src/index.js +23 -8
- package/dist/src/tools/format.js +20 -8
- package/dist/src/tools/tools.js +8 -6
- package/dist/src/tools/types.d.ts +2 -0
- package/dist/src/tools/types.js +9 -0
- package/gui/dist/assets/index-CPYr3dz7.css +1 -0
- package/gui/dist/assets/index-CSbeloLm.js +64 -0
- package/gui/dist/index.html +2 -2
- package/package.json +1 -1
- package/gui/dist/assets/index-C1Ml-XiM.css +0 -1
- package/gui/dist/assets/index-DQPqW5Uq.js +0 -64
|
@@ -7,6 +7,7 @@ import { CommandAbortedError, runCommand, tail } from "./commands.js";
|
|
|
7
7
|
import { ConflictError, TrackerError } from "./errors.js";
|
|
8
8
|
import { GitHubClient } from "./github.js";
|
|
9
9
|
import { diffLockfiles, forceCandidates, parseAuditReport, parseLockfile, parseNpmJson, projectLabel, } from "./npm-audit.js";
|
|
10
|
+
import { repairVulnerabilities } from "./repair.js";
|
|
10
11
|
import { assertNotDeprecated, isActive } from "./store.js";
|
|
11
12
|
/** Intervalle de lecture de la demande d'annulation pendant une étape. */
|
|
12
13
|
const CANCEL_POLL_MS = 500;
|
|
@@ -16,8 +17,12 @@ const MAX_LOG_TEXT = 4000;
|
|
|
16
17
|
const CLONE_DIR = "repo";
|
|
17
18
|
/** Paquets listés dans le corps de la pull request. */
|
|
18
19
|
const MAX_PR_CHANGES = 60;
|
|
19
|
-
/** Dernières actions de Claude gardées dans l'opération pendant l'analyse. */
|
|
20
|
+
/** Dernières actions de Claude gardées dans l'opération pendant l'analyse et les corrections. */
|
|
20
21
|
const ANALYSIS_ACTIVITY = 3;
|
|
22
|
+
/** Fichiers suivis par les commits du tracker : tout le clone, sauf les node_modules qu'installe Claude. */
|
|
23
|
+
const STAGED_PATHS = ["--", ".", ":(exclude,glob)**/node_modules/**"];
|
|
24
|
+
/** Co-auteur du commit des corrections par Claude. */
|
|
25
|
+
const CLAUDE_TRAILER = "Co-Authored-By: Claude <noreply@anthropic.com>";
|
|
21
26
|
function now() {
|
|
22
27
|
return new Date().toISOString();
|
|
23
28
|
}
|
|
@@ -48,6 +53,10 @@ function gitAuthEnv(config) {
|
|
|
48
53
|
* que npm 12 classe en dépendances distantes avec `--package-lock-only`.
|
|
49
54
|
*/
|
|
50
55
|
const NPM_ENV = { npm_config_update_notifier: "false", npm_config_fund: "false", npm_config_allow_remote: "all" };
|
|
56
|
+
/** Options npm qui limitent l'audit et ses corrections au périmètre `scope`. */
|
|
57
|
+
function scopeArgs(scope) {
|
|
58
|
+
return scope === "production" ? ["--omit=dev"] : [];
|
|
59
|
+
}
|
|
51
60
|
/** Sous-commande git d'une liste d'arguments, après les options `-c clé=valeur`. */
|
|
52
61
|
function subcommand(args) {
|
|
53
62
|
let index = 0;
|
|
@@ -55,13 +64,14 @@ function subcommand(args) {
|
|
|
55
64
|
index += 2;
|
|
56
65
|
return args[index] ?? "";
|
|
57
66
|
}
|
|
58
|
-
function newOperation(repo, kind, origin) {
|
|
67
|
+
function newOperation(repo, kind, origin, scope) {
|
|
59
68
|
const createdAt = now();
|
|
60
69
|
return {
|
|
61
70
|
id: `op-${Date.now().toString(36)}-${crypto.randomBytes(3).toString("hex")}`,
|
|
62
71
|
repoId: repo.id,
|
|
63
72
|
kind,
|
|
64
73
|
origin,
|
|
74
|
+
scope,
|
|
65
75
|
status: "running",
|
|
66
76
|
createdAt,
|
|
67
77
|
updatedAt: createdAt,
|
|
@@ -69,9 +79,9 @@ function newOperation(repo, kind, origin) {
|
|
|
69
79
|
workDir: null,
|
|
70
80
|
baseBranch: repo.branch,
|
|
71
81
|
cancelRequested: false,
|
|
72
|
-
steps: { clone: "pending", audit: "pending", fix: "pending", analysis: "pending", force: "pending", push: "pending" },
|
|
82
|
+
steps: { clone: "pending", audit: "pending", fix: "pending", analysis: "pending", force: "pending", repair: "pending", push: "pending" },
|
|
73
83
|
projects: [],
|
|
74
|
-
counts: { initial: null, afterFix: null, afterForce: null },
|
|
84
|
+
counts: { initial: null, afterFix: null, afterForce: null, afterRepair: null },
|
|
75
85
|
found: [],
|
|
76
86
|
remaining: [],
|
|
77
87
|
forceCandidates: [],
|
|
@@ -80,6 +90,7 @@ function newOperation(repo, kind, origin) {
|
|
|
80
90
|
branch: null,
|
|
81
91
|
pullRequest: null,
|
|
82
92
|
analysis: null,
|
|
93
|
+
repair: null,
|
|
83
94
|
error: null,
|
|
84
95
|
log: [],
|
|
85
96
|
};
|
|
@@ -184,7 +195,7 @@ async function cloneStep(runner) {
|
|
|
184
195
|
async function auditAll(runner, count) {
|
|
185
196
|
const vulnerabilities = [];
|
|
186
197
|
for (const project of runner.operation.projects) {
|
|
187
|
-
const report = await runner.npm(project, ["audit", "--json"]);
|
|
198
|
+
const report = await runner.npm(project, ["audit", ...scopeArgs(runner.operation.scope), "--json"]);
|
|
188
199
|
runner.auditReports.set(project, report);
|
|
189
200
|
vulnerabilities.push(...parseAuditReport(report, project));
|
|
190
201
|
}
|
|
@@ -196,6 +207,14 @@ async function auditAll(runner, count) {
|
|
|
196
207
|
}));
|
|
197
208
|
return vulnerabilities;
|
|
198
209
|
}
|
|
210
|
+
/** Vulnérabilités restantes de chaque projet, d'après un nouvel `npm audit`, sans toucher aux comptes de l'opération. */
|
|
211
|
+
async function currentAuditFacts(runner) {
|
|
212
|
+
const facts = [];
|
|
213
|
+
for (const project of runner.operation.projects) {
|
|
214
|
+
facts.push(...auditFacts(await runner.npm(project, ["audit", ...scopeArgs(runner.operation.scope), "--json"]), project));
|
|
215
|
+
}
|
|
216
|
+
return facts;
|
|
217
|
+
}
|
|
199
218
|
/** Paquets modifiés depuis le commit cloné, dans tous les projets. */
|
|
200
219
|
async function refreshChanges(runner) {
|
|
201
220
|
const changes = [];
|
|
@@ -216,7 +235,7 @@ async function fixStep(runner, vulnerabilities) {
|
|
|
216
235
|
runner.setStep("fix", "running");
|
|
217
236
|
const projects = new Set(vulnerabilities.map((vulnerability) => vulnerability.project));
|
|
218
237
|
for (const project of runner.operation.projects.filter((candidate) => projects.has(candidate))) {
|
|
219
|
-
await runner.npm(project, ["audit", "fix", "--package-lock-only", "--ignore-scripts", "--json"]);
|
|
238
|
+
await runner.npm(project, ["audit", "fix", ...scopeArgs(runner.operation.scope), "--package-lock-only", "--ignore-scripts", "--json"]);
|
|
220
239
|
}
|
|
221
240
|
const remaining = await auditAll(runner, "afterFix");
|
|
222
241
|
await refreshChanges(runner);
|
|
@@ -248,6 +267,7 @@ async function analysisStep(runner, ctx) {
|
|
|
248
267
|
const { report, task } = await analyseVulnerabilities({
|
|
249
268
|
repoId: operation.repoId,
|
|
250
269
|
branch: operation.baseBranch,
|
|
270
|
+
scope: operation.scope,
|
|
251
271
|
cwd: runner.repoDir,
|
|
252
272
|
workDir: operation.workDir,
|
|
253
273
|
facts: operation.projects.flatMap((project) => auditFacts(runner.auditReports.get(project), project)),
|
|
@@ -273,22 +293,132 @@ async function analysisStep(runner, ctx) {
|
|
|
273
293
|
runner.setStep("analysis", "failed");
|
|
274
294
|
}
|
|
275
295
|
}
|
|
296
|
+
/** Options git qui signent un commit au nom de l'utilisateur du token GitHub. */
|
|
297
|
+
async function commitIdentity(runner) {
|
|
298
|
+
const user = await new GitHubClient(runner.config).getAuthenticatedUser();
|
|
299
|
+
return ["-c", `user.name=${user.name ?? user.login}`, "-c", `user.email=${user.id}+${user.login}@users.noreply.github.com`];
|
|
300
|
+
}
|
|
301
|
+
/** Vrai si l'index contient des changements à commiter. */
|
|
302
|
+
async function hasStagedChanges(runner) {
|
|
303
|
+
return (await runner.git(["diff", "--cached", "--name-only"])).trim() !== "";
|
|
304
|
+
}
|
|
305
|
+
/**
|
|
306
|
+
* Crée la branche de la correction et y commite les lockfiles modifiés par
|
|
307
|
+
* `npm audit fix`, s'ils ont changé ; rend le commit sur lequel reposeront les
|
|
308
|
+
* corrections par Claude, et celui de `npm audit fix`, null sans changement.
|
|
309
|
+
*/
|
|
310
|
+
async function commitAuditFixes(runner) {
|
|
311
|
+
const branch = runner.operation.branch ?? branchName(new Date());
|
|
312
|
+
runner.update((operation) => ({ ...operation, branch }));
|
|
313
|
+
await runner.git(["checkout", "-b", branch]);
|
|
314
|
+
await runner.git(["add", "-A", ...STAGED_PATHS]);
|
|
315
|
+
const committed = await hasStagedChanges(runner);
|
|
316
|
+
if (committed)
|
|
317
|
+
await runner.git([...(await commitIdentity(runner)), "commit", "-m", runner.operation.commitMessage]);
|
|
318
|
+
const base = (await runner.git(["rev-parse", "HEAD"])).trim();
|
|
319
|
+
return { base, auditCommit: committed ? base : null };
|
|
320
|
+
}
|
|
321
|
+
/**
|
|
322
|
+
* Remplace le commit des corrections par Claude par un seul commit de tout ce
|
|
323
|
+
* qui a changé depuis `base` ; rend ce commit, ou null quand rien n'a changé.
|
|
324
|
+
*/
|
|
325
|
+
async function commitRepair(runner, base, message) {
|
|
326
|
+
await runner.git(["reset", "--soft", base]);
|
|
327
|
+
await runner.git(["add", "-A", ...STAGED_PATHS]);
|
|
328
|
+
if (!(await hasStagedChanges(runner)))
|
|
329
|
+
return null;
|
|
330
|
+
await runner.git([...(await commitIdentity(runner)), "commit", "-m", message, "-m", CLAUDE_TRAILER]);
|
|
331
|
+
return (await runner.git(["rev-parse", "HEAD"])).trim();
|
|
332
|
+
}
|
|
276
333
|
/** `npm audit fix --force` dans les projets qui ont une montée majeure à appliquer. */
|
|
277
334
|
async function forceStep(runner) {
|
|
278
335
|
runner.setStep("force", "running");
|
|
279
336
|
const projects = new Set(runner.operation.forceCandidates.map((candidate) => candidate.project));
|
|
280
337
|
for (const project of runner.operation.projects.filter((candidate) => projects.has(candidate))) {
|
|
281
|
-
await runner.npm(project, ["audit", "fix", "--force", "--package-lock-only", "--ignore-scripts", "--json"]);
|
|
338
|
+
await runner.npm(project, ["audit", "fix", "--force", ...scopeArgs(runner.operation.scope), "--package-lock-only", "--ignore-scripts", "--json"]);
|
|
282
339
|
}
|
|
283
340
|
await auditAll(runner, "afterForce");
|
|
284
341
|
await refreshChanges(runner);
|
|
285
342
|
runner.setStep("force", "done");
|
|
286
343
|
}
|
|
344
|
+
/**
|
|
345
|
+
* Corrections par Claude, d'après la tâche de l'analyse et les remarques de
|
|
346
|
+
* l'utilisateur : la première fois, la branche est créée et `npm audit fix`
|
|
347
|
+
* y est commité ; les corrections de Claude font ensuite un seul commit, qui
|
|
348
|
+
* remplace celui d'un passage précédent. Un échec remet le clone dans l'état
|
|
349
|
+
* du passage précédent et garde ses résultats ; seule une annulation
|
|
350
|
+
* interrompt l'opération.
|
|
351
|
+
*/
|
|
352
|
+
async function repairStep(runner, ctx) {
|
|
353
|
+
runner.setStep("repair", "running");
|
|
354
|
+
const previous = runner.operation.repair;
|
|
355
|
+
const { base, auditCommit } = previous ?? (await commitAuditFixes(runner));
|
|
356
|
+
const repair = {
|
|
357
|
+
runs: (previous?.runs ?? 0) + 1,
|
|
358
|
+
startedAt: now(),
|
|
359
|
+
endedAt: null,
|
|
360
|
+
turns: 0,
|
|
361
|
+
activity: [],
|
|
362
|
+
base,
|
|
363
|
+
auditCommit,
|
|
364
|
+
commit: previous?.commit ?? null,
|
|
365
|
+
report: previous?.report ?? null,
|
|
366
|
+
task: previous?.task ?? null,
|
|
367
|
+
error: null,
|
|
368
|
+
};
|
|
369
|
+
runner.update((operation) => ({ ...operation, repair }));
|
|
370
|
+
const repaired = (fn) => runner.update((operation) => ({ ...operation, repair: operation.repair && fn(operation.repair) }));
|
|
371
|
+
try {
|
|
372
|
+
const operation = runner.operation;
|
|
373
|
+
const analysisTask = operation.analysis?.task;
|
|
374
|
+
if (!analysisTask)
|
|
375
|
+
throw new TrackerError("The fixes by Claude need the organizer task of the analysis.");
|
|
376
|
+
const { report, task } = await repairVulnerabilities({
|
|
377
|
+
repoId: operation.repoId,
|
|
378
|
+
branch: operation.baseBranch,
|
|
379
|
+
scope: operation.scope,
|
|
380
|
+
cwd: runner.repoDir,
|
|
381
|
+
workDir: operation.workDir,
|
|
382
|
+
facts: await currentAuditFacts(runner),
|
|
383
|
+
forceApplied: operation.steps.force === "done",
|
|
384
|
+
analysisTask: analysisTask.key,
|
|
385
|
+
reportTask: previous?.task?.key ?? null,
|
|
386
|
+
settings: ctx.settings(),
|
|
387
|
+
claude: ctx.claude,
|
|
388
|
+
signal: runner.signal,
|
|
389
|
+
onLine: (line, turns) => {
|
|
390
|
+
runner.log(`claude: ${line}`);
|
|
391
|
+
repaired((current) => ({ ...current, turns, activity: [...current.activity, line].slice(-ANALYSIS_ACTIVITY) }));
|
|
392
|
+
},
|
|
393
|
+
});
|
|
394
|
+
const commit = await commitRepair(runner, base, report.commitMessage);
|
|
395
|
+
runner.log(`Development report ${task.key}: ${task.url}`);
|
|
396
|
+
await auditAll(runner, "afterRepair");
|
|
397
|
+
await refreshChanges(runner);
|
|
398
|
+
repaired((current) => ({ ...current, endedAt: now(), commit, report, task }));
|
|
399
|
+
runner.setStep("repair", "done");
|
|
400
|
+
}
|
|
401
|
+
catch (err) {
|
|
402
|
+
if (err instanceof CommandAbortedError || runner.signal.aborted)
|
|
403
|
+
throw err;
|
|
404
|
+
const message = err?.message ?? String(err);
|
|
405
|
+
runner.log(`Fixes by Claude failed: ${message}`);
|
|
406
|
+
await runner.git(["reset", "--hard", "HEAD"]);
|
|
407
|
+
await runner.git(["clean", "-fd", "-e", "node_modules"]);
|
|
408
|
+
repaired((current) => ({ ...current, endedAt: now(), error: message }));
|
|
409
|
+
runner.setStep("repair", previous?.report ? "done" : "failed");
|
|
410
|
+
}
|
|
411
|
+
}
|
|
287
412
|
function pullRequestBody(operation) {
|
|
288
|
-
const after = operation.counts.afterForce ?? operation.counts.afterFix;
|
|
413
|
+
const after = operation.counts.afterRepair ?? operation.counts.afterForce ?? operation.counts.afterFix;
|
|
414
|
+
const repair = operation.repair?.report ? operation.repair : null;
|
|
415
|
+
const command = ["npm audit fix", ...scopeArgs(operation.scope), "--package-lock-only --ignore-scripts"].join(" ");
|
|
289
416
|
const lines = [
|
|
290
|
-
|
|
417
|
+
`Automated \`npm audit\` fixes, made by mcp-dependabot-tracker in a temporary clone (\`${command}\`).`,
|
|
291
418
|
"",
|
|
419
|
+
operation.scope === "production"
|
|
420
|
+
? "- Scope: production dependencies only; the vulnerabilities of the devDependencies were neither audited nor fixed."
|
|
421
|
+
: "- Scope: all dependencies, devDependencies included.",
|
|
292
422
|
`- Vulnerabilities before: ${operation.counts.initial}`,
|
|
293
423
|
`- Vulnerabilities after: ${after}`,
|
|
294
424
|
`- \`npm audit fix --force\`: ${operation.steps.force === "done" ? "applied" : "not applied"}`,
|
|
@@ -302,31 +432,34 @@ function pullRequestBody(operation) {
|
|
|
302
432
|
}
|
|
303
433
|
if (operation.changes.length > MAX_PR_CHANGES)
|
|
304
434
|
lines.push(`- … and ${operation.changes.length - MAX_PR_CHANGES} more`);
|
|
435
|
+
if (repair?.report) {
|
|
436
|
+
lines.push("", `Fixes by Claude Code${repair.task ? `, detailed in organizer task ${repair.task.key}` : ""}:`, "", repair.report.summary, "");
|
|
437
|
+
for (const change of repair.report.changes)
|
|
438
|
+
lines.push(`- \`${change.file}\`: ${change.change}`);
|
|
439
|
+
lines.push(`- Tests: ${repair.report.tests.outcome.replace("_", " ")} — ${repair.report.tests.detail}`);
|
|
440
|
+
}
|
|
305
441
|
return lines.join("\n");
|
|
306
442
|
}
|
|
307
|
-
/**
|
|
443
|
+
/**
|
|
444
|
+
* Commit des lockfiles modifiés sur une nouvelle branche, push, puis pull
|
|
445
|
+
* request vers la branche analysée. Après des corrections par Claude, la
|
|
446
|
+
* branche et ses commits existent déjà : seuls le push et la pull request
|
|
447
|
+
* restent à faire.
|
|
448
|
+
*/
|
|
308
449
|
async function pushStep(runner) {
|
|
309
450
|
runner.setStep("push", "running");
|
|
310
451
|
const operation = runner.operation;
|
|
311
452
|
const [owner, name] = operation.repoId.split("/");
|
|
312
453
|
const github = new GitHubClient(runner.config);
|
|
313
|
-
const user = await github.getAuthenticatedUser();
|
|
314
454
|
const branch = operation.branch ?? branchName(new Date());
|
|
315
455
|
runner.update((current) => ({ ...current, branch }));
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
`user.name=${user.name ?? user.login}`,
|
|
324
|
-
"-c",
|
|
325
|
-
`user.email=${user.id}+${user.login}@users.noreply.github.com`,
|
|
326
|
-
"commit",
|
|
327
|
-
"-m",
|
|
328
|
-
operation.commitMessage,
|
|
329
|
-
]);
|
|
456
|
+
if (!operation.repair) {
|
|
457
|
+
await runner.git(["checkout", "-b", branch]);
|
|
458
|
+
await runner.git(["add", "-A", ...STAGED_PATHS]);
|
|
459
|
+
if (!(await hasStagedChanges(runner)))
|
|
460
|
+
throw new TrackerError("Nothing to commit: the fixes left the files unchanged.");
|
|
461
|
+
await runner.git([...(await commitIdentity(runner)), "commit", "-m", operation.commitMessage]);
|
|
462
|
+
}
|
|
330
463
|
await runner.git(["push", "origin", `HEAD:refs/heads/${branch}`], { auth: true });
|
|
331
464
|
const title = operation.commitMessage.split(/\r?\n/)[0];
|
|
332
465
|
let pullRequest;
|
|
@@ -354,13 +487,36 @@ function finish(runner) {
|
|
|
354
487
|
* branche qui sera poussée, ou l'opération se termine s'il n'y a rien à pousser.
|
|
355
488
|
*/
|
|
356
489
|
function settleForPush(runner) {
|
|
357
|
-
|
|
358
|
-
|
|
490
|
+
const operation = runner.operation;
|
|
491
|
+
if (operation.changes.length > 0 || operation.repair?.commit) {
|
|
492
|
+
runner.update((current) => ({ ...current, status: "waiting_push", branch: current.branch ?? branchName(new Date()) }));
|
|
359
493
|
}
|
|
360
494
|
else {
|
|
361
495
|
finish(runner);
|
|
362
496
|
}
|
|
363
497
|
}
|
|
498
|
+
/** Vrai quand Claude peut corriger : son analyse a créé une tâche et des vulnérabilités restent. */
|
|
499
|
+
function canRepair(operation) {
|
|
500
|
+
return operation.analysis?.task != null && operation.remaining.length > 0;
|
|
501
|
+
}
|
|
502
|
+
/** Après `npm audit fix` et la décision sur `--force` : les corrections par Claude attendent l'utilisateur quand elles sont possibles, sinon le push. */
|
|
503
|
+
function settleAfterFixes(runner) {
|
|
504
|
+
if (canRepair(runner.operation)) {
|
|
505
|
+
runner.update((operation) => ({ ...operation, status: "waiting_repair" }));
|
|
506
|
+
return;
|
|
507
|
+
}
|
|
508
|
+
runner.setStep("repair", "skipped");
|
|
509
|
+
settleForPush(runner);
|
|
510
|
+
}
|
|
511
|
+
/** Après un passage de Claude : le push attend quand un passage a abouti, sinon les corrections attendent de nouveau. */
|
|
512
|
+
function settleAfterRepair(runner) {
|
|
513
|
+
if (runner.operation.repair?.report) {
|
|
514
|
+
settleForPush(runner);
|
|
515
|
+
}
|
|
516
|
+
else {
|
|
517
|
+
runner.update((operation) => ({ ...operation, status: "waiting_repair" }));
|
|
518
|
+
}
|
|
519
|
+
}
|
|
364
520
|
/**
|
|
365
521
|
* Exécute `body` pour l'opération `id`, avec un signal déclenché par une demande
|
|
366
522
|
* d'annulation enregistrée par n'importe quel processus. Une erreur fait échouer
|
|
@@ -421,15 +577,16 @@ function inBackground(ctx, id, run) {
|
|
|
421
577
|
}
|
|
422
578
|
// --- Entrées ---------------------------------------------------------------------
|
|
423
579
|
/**
|
|
424
|
-
* Lance une correction depuis la GUI : clone, audit,
|
|
425
|
-
* l'analyse par Claude s'exécutent en arrière-plan, puis
|
|
426
|
-
* décision sur `--force
|
|
580
|
+
* Lance une correction depuis la GUI, sur le périmètre `scope` : clone, audit,
|
|
581
|
+
* `npm audit fix` et l'analyse par Claude s'exécutent en arrière-plan, puis
|
|
582
|
+
* l'opération attend la décision sur `--force`, les corrections par Claude ou
|
|
583
|
+
* le push. Refusé sur un dépôt déprécié.
|
|
427
584
|
*/
|
|
428
|
-
export function startUserFix(ctx, repoId) {
|
|
585
|
+
export function startUserFix(ctx, repoId, scope) {
|
|
429
586
|
ctx.githubConfig();
|
|
430
587
|
const repo = ctx.store.getRepo(repoId);
|
|
431
588
|
assertNotDeprecated(repo);
|
|
432
|
-
const operation = ctx.store.createOperation(newOperation(repo, "fix", "user"));
|
|
589
|
+
const operation = ctx.store.createOperation(newOperation(repo, "fix", "user", scope));
|
|
433
590
|
inBackground(ctx, operation.id, execute(ctx, operation.id, async (runner) => {
|
|
434
591
|
await cloneStep(runner);
|
|
435
592
|
const vulnerabilities = await auditStep(runner);
|
|
@@ -442,20 +599,20 @@ export function startUserFix(ctx, repoId) {
|
|
|
442
599
|
return;
|
|
443
600
|
}
|
|
444
601
|
runner.setStep("force", "skipped");
|
|
445
|
-
|
|
602
|
+
settleAfterFixes(runner);
|
|
446
603
|
}));
|
|
447
604
|
return operation;
|
|
448
605
|
}
|
|
449
606
|
/**
|
|
450
|
-
* Audit de la branche par défaut, celle que Dependabot analyse,
|
|
451
|
-
* l'utilisateur et attendu jusqu'à sa fin. Refusé
|
|
452
|
-
* cours sur le dépôt, ou s'il est déprécié.
|
|
607
|
+
* Audit de la branche par défaut, celle que Dependabot analyse, sur le
|
|
608
|
+
* périmètre `scope`, lancé par l'utilisateur et attendu jusqu'à sa fin. Refusé
|
|
609
|
+
* si une opération est en cours sur le dépôt, ou s'il est déprécié.
|
|
453
610
|
*/
|
|
454
|
-
export async function runDefaultBranchAudit(ctx, repoId) {
|
|
611
|
+
export async function runDefaultBranchAudit(ctx, repoId, scope) {
|
|
455
612
|
ctx.githubConfig();
|
|
456
613
|
const repo = ctx.store.getRepo(repoId);
|
|
457
614
|
assertNotDeprecated(repo);
|
|
458
|
-
const operation = ctx.store.createOperation({ ...newOperation(repo, "audit", "user"), baseBranch: repo.defaultBranch });
|
|
615
|
+
const operation = ctx.store.createOperation({ ...newOperation(repo, "audit", "user", scope), baseBranch: repo.defaultBranch });
|
|
459
616
|
return execute(ctx, operation.id, async (runner) => {
|
|
460
617
|
await cloneStep(runner);
|
|
461
618
|
await auditStep(runner);
|
|
@@ -472,7 +629,30 @@ export function decideForce(ctx, id, apply) {
|
|
|
472
629
|
else {
|
|
473
630
|
runner.setStep("force", "skipped");
|
|
474
631
|
}
|
|
475
|
-
|
|
632
|
+
settleAfterFixes(runner);
|
|
633
|
+
}));
|
|
634
|
+
return operation;
|
|
635
|
+
}
|
|
636
|
+
/**
|
|
637
|
+
* Lance ou passe les corrections par Claude d'une opération qui les attend ;
|
|
638
|
+
* `run` sur une opération qui attend le push après un passage relance Claude
|
|
639
|
+
* avec les remarques de l'utilisateur.
|
|
640
|
+
*/
|
|
641
|
+
export function decideRepair(ctx, id, run) {
|
|
642
|
+
const relaunch = run && ctx.store.getOperation(id).status === "waiting_push";
|
|
643
|
+
const operation = resume(ctx, id, relaunch ? "waiting_push" : "waiting_repair", (current) => {
|
|
644
|
+
if (relaunch && !current.repair?.report)
|
|
645
|
+
throw new ConflictError(`Operation ${id} has no fixes by Claude to run again.`);
|
|
646
|
+
return current;
|
|
647
|
+
});
|
|
648
|
+
inBackground(ctx, id, execute(ctx, id, async (runner) => {
|
|
649
|
+
if (!run) {
|
|
650
|
+
runner.setStep("repair", "skipped");
|
|
651
|
+
settleForPush(runner);
|
|
652
|
+
return;
|
|
653
|
+
}
|
|
654
|
+
await repairStep(runner, ctx);
|
|
655
|
+
settleAfterRepair(runner);
|
|
476
656
|
}));
|
|
477
657
|
return operation;
|
|
478
658
|
}
|
|
@@ -506,15 +686,16 @@ export function cancelOperation(ctx, id) {
|
|
|
506
686
|
return cleanUp(ctx, operation.id);
|
|
507
687
|
}
|
|
508
688
|
/**
|
|
509
|
-
* Opération menée par l'agent d'un bout à l'autre,
|
|
510
|
-
* `audit` s'arrête après `npm audit` ; `fix` enchaîne
|
|
511
|
-
* `--force` et le push selon `plan`. Refusé sur un dépôt
|
|
689
|
+
* Opération menée par l'agent d'un bout à l'autre, sur le périmètre de `plan`,
|
|
690
|
+
* attendue jusqu'à sa fin : `audit` s'arrête après `npm audit` ; `fix` enchaîne
|
|
691
|
+
* `npm audit fix`, puis `--force` et le push selon `plan`. Refusé sur un dépôt
|
|
692
|
+
* déprécié.
|
|
512
693
|
*/
|
|
513
694
|
export async function runAgentOperation(ctx, repoId, kind, plan) {
|
|
514
695
|
ctx.githubConfig();
|
|
515
696
|
const repo = ctx.store.getRepo(repoId);
|
|
516
697
|
assertNotDeprecated(repo);
|
|
517
|
-
const operation = ctx.store.createOperation({ ...newOperation(repo, kind, "agent"), commitMessage: plan.commitMessage });
|
|
698
|
+
const operation = ctx.store.createOperation({ ...newOperation(repo, kind, "agent", plan.scope), commitMessage: plan.commitMessage });
|
|
518
699
|
return execute(ctx, operation.id, async (runner) => {
|
|
519
700
|
await cloneStep(runner);
|
|
520
701
|
const vulnerabilities = await auditStep(runner);
|
|
@@ -16,14 +16,22 @@ export interface OrganizerSpace {
|
|
|
16
16
|
email: string;
|
|
17
17
|
};
|
|
18
18
|
}
|
|
19
|
+
/** Tâche de l'espace ; `parentKey` est la clé de sa tâche parente, null pour une tâche de premier niveau. */
|
|
19
20
|
export interface OrganizerTask {
|
|
20
21
|
id: string;
|
|
21
22
|
key: string;
|
|
22
23
|
title: string;
|
|
23
24
|
status: (typeof TASK_STATUSES)[number];
|
|
25
|
+
parentKey: string | null;
|
|
24
26
|
assigneeIds: string[];
|
|
25
27
|
tags: string[];
|
|
26
28
|
}
|
|
29
|
+
/** Commentaire d'une tâche ; `author` est le nom de son auteur. */
|
|
30
|
+
export interface OrganizerComment {
|
|
31
|
+
author: string;
|
|
32
|
+
body: string;
|
|
33
|
+
createdAt: string;
|
|
34
|
+
}
|
|
27
35
|
/**
|
|
28
36
|
* Adresse du site, validée : absolue, en https sauf pour un site de cette
|
|
29
37
|
* machine (le token passerait en clair), sans identifiants, requête ni fragment.
|
|
@@ -38,6 +46,12 @@ export declare class OrganizerClient {
|
|
|
38
46
|
space(): Promise<OrganizerSpace>;
|
|
39
47
|
/** Tâche de l'espace, par sa clé (ex. `ORG-42`) ou son identifiant. */
|
|
40
48
|
task(ref: string): Promise<OrganizerTask>;
|
|
49
|
+
/** Tâche de l'espace et ses commentaires récents, du plus ancien au plus récent. */
|
|
50
|
+
taskWithComments(ref: string): Promise<{
|
|
51
|
+
task: OrganizerTask;
|
|
52
|
+
comments: OrganizerComment[];
|
|
53
|
+
}>;
|
|
54
|
+
private parseTask;
|
|
41
55
|
/** Données d'une lecture de l'API agent. Une redirection n'est jamais suivie : le token ne part que vers l'adresse réglée. */
|
|
42
56
|
private get;
|
|
43
57
|
}
|
|
@@ -49,16 +49,31 @@ export class OrganizerClient {
|
|
|
49
49
|
}
|
|
50
50
|
/** Tâche de l'espace, par sa clé (ex. `ORG-42`) ou son identifiant. */
|
|
51
51
|
async task(ref) {
|
|
52
|
-
|
|
52
|
+
return this.parseTask((await this.get(`tasks/${encodeURIComponent(ref)}`))?.task, ref);
|
|
53
|
+
}
|
|
54
|
+
/** Tâche de l'espace et ses commentaires récents, du plus ancien au plus récent. */
|
|
55
|
+
async taskWithComments(ref) {
|
|
56
|
+
const data = await this.get(`tasks/${encodeURIComponent(ref)}`);
|
|
57
|
+
const comments = data?.comments;
|
|
58
|
+
if (!Array.isArray(comments) || !comments.every((comment) => typeof comment?.authorName === "string" && typeof comment.body === "string" && typeof comment.createdAt === "string")) {
|
|
59
|
+
throw new TrackerError(`The organizer at ${this.connection.url} sent an unexpected answer for the comments of task ${ref}: check that it is up to date.`);
|
|
60
|
+
}
|
|
61
|
+
return {
|
|
62
|
+
task: this.parseTask(data.task, ref),
|
|
63
|
+
comments: comments.map((comment) => ({ author: comment.authorName, body: comment.body, createdAt: comment.createdAt })),
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
parseTask(task, ref) {
|
|
53
67
|
if (typeof task?.id !== "string" ||
|
|
54
68
|
typeof task.key !== "string" ||
|
|
55
69
|
typeof task.title !== "string" ||
|
|
56
70
|
!TASK_STATUSES.includes(task.status) ||
|
|
71
|
+
(task.parentKey !== null && typeof task.parentKey !== "string") ||
|
|
57
72
|
!Array.isArray(task.assigneeIds) ||
|
|
58
73
|
!Array.isArray(task.tags)) {
|
|
59
74
|
throw new TrackerError(`The organizer at ${this.connection.url} sent an unexpected answer for task ${ref}: check that it is up to date.`);
|
|
60
75
|
}
|
|
61
|
-
return { id: task.id, key: task.key, title: task.title, status: task.status, assigneeIds: task.assigneeIds, tags: task.tags };
|
|
76
|
+
return { id: task.id, key: task.key, title: task.title, status: task.status, parentKey: task.parentKey, assigneeIds: task.assigneeIds, tags: task.tags };
|
|
62
77
|
}
|
|
63
78
|
/** Données d'une lecture de l'API agent. Une redirection n'est jamais suivie : le token ne part que vers l'adresse réglée. */
|
|
64
79
|
async get(path) {
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { RemarksResponse } from "../../shared/schemas/api.schema.js";
|
|
2
|
+
import { type AnalysisTask, type AuditScope, type Operation, type RepairReport } from "../../shared/schemas/model.schema.js";
|
|
3
|
+
import type { Settings } from "../../shared/schemas/settings.schema.js";
|
|
4
|
+
import { type ClaudeRuntime } from "./claude.js";
|
|
5
|
+
export interface RepairInput {
|
|
6
|
+
repoId: string;
|
|
7
|
+
branch: string;
|
|
8
|
+
scope: AuditScope;
|
|
9
|
+
/** Clone du dépôt : dossier de travail de Claude. */
|
|
10
|
+
cwd: string;
|
|
11
|
+
/** Dossier de l'opération, hors du clone : configuration MCP de la session. */
|
|
12
|
+
workDir: string;
|
|
13
|
+
/** Vulnérabilités restantes, d'après `npm audit --json`. */
|
|
14
|
+
facts: unknown[];
|
|
15
|
+
forceApplied: boolean;
|
|
16
|
+
/** Clé de la tâche de l'analyse, dont les commentaires portent les remarques de l'utilisateur. */
|
|
17
|
+
analysisTask: string;
|
|
18
|
+
/** Clé de la sous-tâche d'un passage précédent, dont le clone contient encore les corrections. */
|
|
19
|
+
reportTask: string | null;
|
|
20
|
+
settings: Settings;
|
|
21
|
+
claude: ClaudeRuntime;
|
|
22
|
+
signal: AbortSignal;
|
|
23
|
+
onLine: (line: string, turns: number) => void;
|
|
24
|
+
}
|
|
25
|
+
/** Tâche de l'analyse d'une opération et ses commentaires : les remarques que Claude prendra en compte. */
|
|
26
|
+
export declare function analysisRemarks(settings: Settings, operation: Operation): Promise<RemarksResponse>;
|
|
27
|
+
/** Lance les corrections, puis vérifie sur l'organizer la sous-tâche que Claude dit avoir créée ou mise à jour. */
|
|
28
|
+
export declare function repairVulnerabilities(input: RepairInput): Promise<{
|
|
29
|
+
report: RepairReport;
|
|
30
|
+
task: AnalysisTask;
|
|
31
|
+
}>;
|