@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
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
import path from "path";
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
import { RepairReportSchema, TEST_OUTCOMES } from "../../shared/schemas/model.schema.js";
|
|
5
|
+
import { ORGANIZER_SERVER, factsJson, organizerServer } from "./analysis.js";
|
|
6
|
+
import { runClaudeSession } from "./claude.js";
|
|
7
|
+
import { TrackerError } from "./errors.js";
|
|
8
|
+
import { OrganizerClient } from "./organizer.js";
|
|
9
|
+
import { organizerConnection } from "./settings.js";
|
|
10
|
+
/**
|
|
11
|
+
* Corrections par Claude des vulnérabilités que `npm audit fix` laisse dans un
|
|
12
|
+
* clone, d'après la tâche de l'analyse et les commentaires que l'utilisateur y
|
|
13
|
+
* a laissés. Claude modifie le clone (Read, Grep, Glob, Edit, Write et
|
|
14
|
+
* quelques commandes npm : installation, audit, tests), sans git ni écriture
|
|
15
|
+
* hors du clone ; les commandes qu'il lance ne reçoivent pas son token. Il crée
|
|
16
|
+
* une sous-tâche « rapport de développement » de la tâche de l'analyse, ou met
|
|
17
|
+
* à jour celle d'un passage précédent, puis rend un rapport structuré. Le
|
|
18
|
+
* tracker relit la sous-tâche sur l'organizer : absente, rattachée à une autre
|
|
19
|
+
* tâche, mal assignée ou mal taguée, elle fait échouer les corrections.
|
|
20
|
+
*/
|
|
21
|
+
/** Outils organizer autorisés ; tout autre appel est refusé par `dontAsk`. */
|
|
22
|
+
const ORGANIZER_TOOLS = ["get_task", "create_task", "update_task", "set_assignees", "set_tags"];
|
|
23
|
+
/** Commandes que Claude peut lancer dans le clone, chacune avec ou sans arguments. */
|
|
24
|
+
const ALLOWED_COMMANDS = ["npm install", "npm ci", "npm audit", "npm test", "npm run", "npm ls", "npx tsc"];
|
|
25
|
+
/** Réglages de la session : Edit et Write refusent tout chemin hors du clone. */
|
|
26
|
+
const SESSION_SETTINGS = { permissions: { blockWritesOutsideWorkingDirectories: true } };
|
|
27
|
+
/** Résultat demandé à Claude : le rapport et la clé de la sous-tâche. */
|
|
28
|
+
const OutputSchema = RepairReportSchema.extend({ task: z.string().min(1), commitMessage: z.string().trim().min(1) });
|
|
29
|
+
const OUTPUT_JSON_SCHEMA = {
|
|
30
|
+
type: "object",
|
|
31
|
+
additionalProperties: false,
|
|
32
|
+
required: ["task", "summary", "changes", "commitMessage", "tests"],
|
|
33
|
+
properties: {
|
|
34
|
+
task: { type: "string", description: "Key of the development report sub-task, e.g. ORG-43." },
|
|
35
|
+
summary: { type: "string", description: "One or two sentences, in French." },
|
|
36
|
+
changes: {
|
|
37
|
+
type: "array",
|
|
38
|
+
description: "Every file you changed; empty when none.",
|
|
39
|
+
items: {
|
|
40
|
+
type: "object",
|
|
41
|
+
additionalProperties: false,
|
|
42
|
+
required: ["file", "change"],
|
|
43
|
+
properties: { file: { type: "string", description: "Path relative to the repository root." }, change: { type: "string", description: "A few words, in French." } },
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
commitMessage: { type: "string", description: "Conventional commit message in English, first line under 72 characters." },
|
|
47
|
+
tests: {
|
|
48
|
+
type: "object",
|
|
49
|
+
additionalProperties: false,
|
|
50
|
+
required: ["outcome", "detail"],
|
|
51
|
+
properties: { outcome: { type: "string", enum: [...TEST_OUTCOMES] }, detail: { type: "string", description: "One sentence, in French." } },
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
};
|
|
55
|
+
function prompt(input, space, owner, tag) {
|
|
56
|
+
const fixes = input.forceApplied ? "`npm audit fix` and `npm audit fix --force`" : "`npm audit fix`";
|
|
57
|
+
const omit = input.scope === "production" ? " --omit=dev" : "";
|
|
58
|
+
const report = input.reportTask
|
|
59
|
+
? `update the description of your previous report, task ${input.reportTask}, with update_task (keep it a sub-task of ${input.analysisTask}); do not create a new one.`
|
|
60
|
+
: `create one sub-task of ${input.analysisTask} with create_task (parent "${input.analysisTask}"), without request_id, titled in French "Rapport de développement — " followed by what you changed.`;
|
|
61
|
+
return [
|
|
62
|
+
`You fix the npm vulnerabilities that ${fixes} left in the GitHub repository ${input.repoId} (branch ${input.branch}).`,
|
|
63
|
+
input.scope === "production"
|
|
64
|
+
? "The audit covers the production dependencies only (`--omit=dev`): the vulnerabilities of the devDependencies are out of scope."
|
|
65
|
+
: "The audit covers all the dependencies, devDependencies included.",
|
|
66
|
+
`The current directory is a clone of that branch where ${fixes} already updated the lockfiles.`,
|
|
67
|
+
...(input.reportTask ? [`It also holds the changes of your previous pass, described in task ${input.reportTask}: build on them, and change or revert them where the remarks of the user ask for it.`] : []),
|
|
68
|
+
"",
|
|
69
|
+
"Remaining vulnerabilities, from `npm audit --json` (`project` is the folder of the package-lock.json):",
|
|
70
|
+
"```json",
|
|
71
|
+
factsJson(input.facts),
|
|
72
|
+
"```",
|
|
73
|
+
"",
|
|
74
|
+
"Your job:",
|
|
75
|
+
`1. Read the organizer task ${input.analysisTask} with get_task: its description is the analysis of these vulnerabilities, and its comments are the remarks of the user. Follow the remarks: they take precedence over the analysis.`,
|
|
76
|
+
"2. Fix what can be fixed, with minimal changes: upgrade a dependency in package.json, or pin a transitive one with an `overrides` entry, then run `npm install --package-lock-only --ignore-scripts` in the folder of its package-lock.json; adapt the code to the new versions.",
|
|
77
|
+
`3. Check your work: run \`npm audit${omit}\` in each project; install the dependencies with \`npm ci\` and run the tests (\`npm test\`, or the test script of package.json) when the project has some.`,
|
|
78
|
+
" You can only run npm install, npm ci, npm audit, npm test, npm run, npm ls and npx tsc. Never run git, and never write outside the current directory: the tracker commits your changes, node_modules aside.",
|
|
79
|
+
`4. Report in the organizer space "${space}": ${report} Its description, in French markdown, details every change file by file and why, how each remark of the user was taken into account, the result of the audit and of the tests, and what is left to check by hand.`,
|
|
80
|
+
` Assign it to ${owner.name} with set_assignees (member id ${owner.id}), and set its tags to exactly ["${tag}"] with set_tags.`,
|
|
81
|
+
"5. Finish with the structured report: the key of the sub-task, a summary in French, every changed file with its change in a few words in French, a conventional commit message in English for your changes, and the outcome of the tests with a one-sentence detail in French.",
|
|
82
|
+
].join("\n");
|
|
83
|
+
}
|
|
84
|
+
/** Tâche de l'analyse d'une opération et ses commentaires : les remarques que Claude prendra en compte. */
|
|
85
|
+
export async function analysisRemarks(settings, operation) {
|
|
86
|
+
const connection = organizerConnection(settings);
|
|
87
|
+
const task = operation.analysis?.task;
|
|
88
|
+
if (!connection)
|
|
89
|
+
throw new TrackerError("The organizer connection is not set: set it in the settings.");
|
|
90
|
+
if (!task)
|
|
91
|
+
throw new TrackerError(`Operation ${operation.id} has no organizer task from an analysis.`);
|
|
92
|
+
const { comments } = await new OrganizerClient(connection).taskWithComments(task.key);
|
|
93
|
+
return { task, remarks: comments };
|
|
94
|
+
}
|
|
95
|
+
/** Lance les corrections, puis vérifie sur l'organizer la sous-tâche que Claude dit avoir créée ou mise à jour. */
|
|
96
|
+
export async function repairVulnerabilities(input) {
|
|
97
|
+
const connection = organizerConnection(input.settings);
|
|
98
|
+
const token = input.settings.claude.token;
|
|
99
|
+
if (!connection || !token)
|
|
100
|
+
throw new TrackerError("The fixes by Claude need the organizer connection and the Claude token: set them in the settings.");
|
|
101
|
+
const organizer = new OrganizerClient(connection);
|
|
102
|
+
const { space, owner } = await organizer.space();
|
|
103
|
+
const tag = input.repoId.split("/")[1];
|
|
104
|
+
const configFile = path.join(input.workDir, "repair-mcp.json");
|
|
105
|
+
fs.writeFileSync(configFile, JSON.stringify({ mcpServers: { [ORGANIZER_SERVER]: organizerServer(connection) } }), { encoding: "utf-8", mode: 0o600 });
|
|
106
|
+
let structured;
|
|
107
|
+
try {
|
|
108
|
+
({ structured } = await runClaudeSession(input.claude, {
|
|
109
|
+
cwd: input.cwd,
|
|
110
|
+
prompt: prompt(input, space.name, owner, tag),
|
|
111
|
+
args: [
|
|
112
|
+
"--tools",
|
|
113
|
+
"Read,Grep,Glob,Edit,Write,Bash",
|
|
114
|
+
"--allowedTools",
|
|
115
|
+
["Edit", "Write", ...ALLOWED_COMMANDS.map((command) => `Bash(${command} *)`), ...ORGANIZER_TOOLS.map((tool) => `mcp__${ORGANIZER_SERVER}__${tool}`)].join(","),
|
|
116
|
+
"--settings",
|
|
117
|
+
JSON.stringify(SESSION_SETTINGS),
|
|
118
|
+
"--mcp-config",
|
|
119
|
+
configFile,
|
|
120
|
+
"--strict-mcp-config",
|
|
121
|
+
"--json-schema",
|
|
122
|
+
JSON.stringify(OUTPUT_JSON_SCHEMA),
|
|
123
|
+
],
|
|
124
|
+
env: { CLAUDE_CODE_SUBPROCESS_ENV_SCRUB: "1" },
|
|
125
|
+
token,
|
|
126
|
+
maxTurns: input.settings.analysis.maxTurns,
|
|
127
|
+
maxMinutes: input.settings.analysis.maxMinutes,
|
|
128
|
+
signal: input.signal,
|
|
129
|
+
onLine: input.onLine,
|
|
130
|
+
}));
|
|
131
|
+
}
|
|
132
|
+
finally {
|
|
133
|
+
fs.rmSync(configFile, { force: true });
|
|
134
|
+
}
|
|
135
|
+
const output = OutputSchema.safeParse(structured);
|
|
136
|
+
if (!output.success)
|
|
137
|
+
throw new TrackerError("Claude Code ended without the structured report of its fixes.");
|
|
138
|
+
const task = await organizer.task(output.data.task);
|
|
139
|
+
if (task.parentKey?.toLowerCase() !== input.analysisTask.toLowerCase()) {
|
|
140
|
+
throw new TrackerError(`Task ${task.key} is not a sub-task of ${input.analysisTask}.`);
|
|
141
|
+
}
|
|
142
|
+
if (!task.tags.some((candidate) => candidate.toLowerCase() === tag.toLowerCase())) {
|
|
143
|
+
throw new TrackerError(`Task ${task.key} was created without the tag "${tag}".`);
|
|
144
|
+
}
|
|
145
|
+
if (!task.assigneeIds.includes(owner.id)) {
|
|
146
|
+
throw new TrackerError(`Task ${task.key} was created without being assigned to ${owner.name}.`);
|
|
147
|
+
}
|
|
148
|
+
const { task: _key, ...report } = output.data;
|
|
149
|
+
return { report, task: { key: task.key, title: task.title, url: organizer.taskUrl(task.id), status: task.status } };
|
|
150
|
+
}
|
package/dist/src/core/repos.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type Alert, type AlertSeverity, type AnalysisTask, type HandledAlert, type Operation, type PullRequest, type Repo, type Rights } from "../../shared/schemas/model.schema.js";
|
|
2
|
-
import type { AuditFindings, RepoView } from "../../shared/schemas/api.schema.js";
|
|
2
|
+
import type { AuditFindings, CleanAudit, RepoView } from "../../shared/schemas/api.schema.js";
|
|
3
3
|
import type { GitHubConfig } from "./config.js";
|
|
4
4
|
import { type OpenPullRequest } from "./github.js";
|
|
5
5
|
import { type Store } from "./store.js";
|
|
@@ -20,16 +20,18 @@ export declare function sortRepos<T extends {
|
|
|
20
20
|
auditFindings?: AuditFindings | null;
|
|
21
21
|
}>(views: T[]): T[];
|
|
22
22
|
/**
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
* par défaut, la seule que Dependabot analyse, et dater d'après
|
|
26
|
-
* alertes. Null sinon. `operations` va de la plus récente à la
|
|
23
|
+
* Dernier audit, quand il n'a trouvé aucune vulnérabilité alors que Dependabot
|
|
24
|
+
* signale encore des alertes dans son périmètre : l'audit doit porter sur la
|
|
25
|
+
* branche par défaut, la seule que Dependabot analyse, et dater d'après
|
|
26
|
+
* chacune de ces alertes. Null sinon. `operations` va de la plus récente à la
|
|
27
|
+
* plus ancienne.
|
|
27
28
|
*/
|
|
28
|
-
export declare function
|
|
29
|
+
export declare function cleanAudit(repo: Repo, operations: Operation[]): CleanAudit | null;
|
|
29
30
|
/**
|
|
30
31
|
* Vulnérabilités trouvées par le dernier audit de la branche par défaut, la
|
|
31
|
-
* seule que Dependabot analyse, quand Dependabot ne signale aucune alerte
|
|
32
|
-
* Null sinon. `operations` va de la plus récente à
|
|
32
|
+
* seule que Dependabot analyse, quand Dependabot ne signale aucune alerte dans
|
|
33
|
+
* le périmètre de cet audit. Null sinon. `operations` va de la plus récente à
|
|
34
|
+
* la plus ancienne.
|
|
33
35
|
*/
|
|
34
36
|
export declare function auditFindings(repo: Repo, operations: Operation[]): AuditFindings | null;
|
|
35
37
|
/**
|
|
@@ -53,6 +55,7 @@ export declare function trackerPullRequests(repoId: string, pulls: OpenPullReque
|
|
|
53
55
|
export declare function repoView(store: Store, repo: Repo): RepoView;
|
|
54
56
|
/** Tâche organizer de la dernière analyse, tant qu'elle n'est pas terminée. `operations` va de la plus récente à la plus ancienne. */
|
|
55
57
|
export declare function openAnalysisTask(operations: Operation[]): AnalysisTask | null;
|
|
58
|
+
/** Vues de tous les dépôts suivis ; les dépôts, les catégories et les opérations sont lus une seule fois. */
|
|
56
59
|
export declare function listRepoViews(store: Store): RepoView[];
|
|
57
60
|
/**
|
|
58
61
|
* Relit les alertes Dependabot ouvertes du dépôt et ses pull requests ouvertes
|
package/dist/src/core/repos.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { fromNpmSeverity, pendingAlerts, worstOf } from "../../shared/alerts.js";
|
|
1
|
+
import { alertsInScope, fromNpmSeverity, pendingAlerts, worstOf } from "../../shared/alerts.js";
|
|
2
2
|
import { ALERT_SEVERITIES, DEFAULT_RIGHTS } from "../../shared/schemas/model.schema.js";
|
|
3
3
|
import { latestAnalysed } from "./analysis.js";
|
|
4
4
|
import { ConflictError, NotFoundError } from "./errors.js";
|
|
@@ -44,33 +44,36 @@ export function sortRepos(views) {
|
|
|
44
44
|
});
|
|
45
45
|
}
|
|
46
46
|
/**
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
* par défaut, la seule que Dependabot analyse, et dater d'après
|
|
50
|
-
* alertes. Null sinon. `operations` va de la plus récente à la
|
|
47
|
+
* Dernier audit, quand il n'a trouvé aucune vulnérabilité alors que Dependabot
|
|
48
|
+
* signale encore des alertes dans son périmètre : l'audit doit porter sur la
|
|
49
|
+
* branche par défaut, la seule que Dependabot analyse, et dater d'après
|
|
50
|
+
* chacune de ces alertes. Null sinon. `operations` va de la plus récente à la
|
|
51
|
+
* plus ancienne.
|
|
51
52
|
*/
|
|
52
|
-
export function
|
|
53
|
-
if (repo.alerts.length === 0)
|
|
54
|
-
return null;
|
|
53
|
+
export function cleanAudit(repo, operations) {
|
|
55
54
|
const audited = operations.find((operation) => operation.steps.audit === "done");
|
|
56
55
|
if (!audited || audited.counts.initial !== 0 || audited.baseBranch !== repo.defaultBranch)
|
|
57
56
|
return null;
|
|
57
|
+
const alerts = alertsInScope(repo.alerts, audited.scope);
|
|
58
|
+
if (alerts.length === 0)
|
|
59
|
+
return null;
|
|
58
60
|
const auditedAt = Date.parse(audited.createdAt);
|
|
59
|
-
return
|
|
61
|
+
return alerts.every((alert) => Date.parse(alert.createdAt) <= auditedAt) ? { at: audited.createdAt, scope: audited.scope } : null;
|
|
60
62
|
}
|
|
61
63
|
/**
|
|
62
64
|
* Vulnérabilités trouvées par le dernier audit de la branche par défaut, la
|
|
63
|
-
* seule que Dependabot analyse, quand Dependabot ne signale aucune alerte
|
|
64
|
-
* Null sinon. `operations` va de la plus récente à
|
|
65
|
+
* seule que Dependabot analyse, quand Dependabot ne signale aucune alerte dans
|
|
66
|
+
* le périmètre de cet audit. Null sinon. `operations` va de la plus récente à
|
|
67
|
+
* la plus ancienne.
|
|
65
68
|
*/
|
|
66
69
|
export function auditFindings(repo, operations) {
|
|
67
|
-
if (repo.alerts.length > 0)
|
|
68
|
-
return null;
|
|
69
70
|
const audited = operations.find((operation) => operation.steps.audit === "done" && operation.baseBranch === repo.defaultBranch);
|
|
70
|
-
|
|
71
|
-
if (!audited || severity === null)
|
|
71
|
+
if (!audited || alertsInScope(repo.alerts, audited.scope).length > 0)
|
|
72
72
|
return null;
|
|
73
|
-
|
|
73
|
+
const severity = worstOf(audited.found.map((vulnerability) => fromNpmSeverity(vulnerability.severity)));
|
|
74
|
+
if (severity === null)
|
|
75
|
+
return null;
|
|
76
|
+
return { at: audited.createdAt, scope: audited.scope, count: audited.found.length, severity };
|
|
74
77
|
}
|
|
75
78
|
/**
|
|
76
79
|
* Paquets pour lesquels le dernier audit n'a trouvé aucune version corrigée,
|
|
@@ -106,13 +109,16 @@ export function trackerPullRequests(repoId, pulls) {
|
|
|
106
109
|
.map(({ number, url, branch, createdAt }) => ({ number, url, branch, createdAt }));
|
|
107
110
|
}
|
|
108
111
|
export function repoView(store, repo) {
|
|
109
|
-
|
|
112
|
+
return buildRepoView(repo, store.listOperations(repo.id), repo.categoryId === null ? null : store.getCategory(repo.categoryId));
|
|
113
|
+
}
|
|
114
|
+
/** Vue d'un dépôt à partir de ses opérations, de la plus récente à la plus ancienne, et de sa catégorie. */
|
|
115
|
+
function buildRepoView(repo, operations, category) {
|
|
110
116
|
return {
|
|
111
117
|
repo: { ...repo, alerts: sortAlerts(repo.alerts) },
|
|
112
|
-
category
|
|
118
|
+
category,
|
|
113
119
|
activeOperation: operations.find(isActive) ?? null,
|
|
114
120
|
latestOperation: operations[0] ?? null,
|
|
115
|
-
|
|
121
|
+
cleanAudit: cleanAudit(repo, operations),
|
|
116
122
|
auditFindings: auditFindings(repo, operations),
|
|
117
123
|
unfixable: unfixablePackages(repo, operations),
|
|
118
124
|
analysisTask: openAnalysisTask(operations),
|
|
@@ -123,9 +129,21 @@ export function openAnalysisTask(operations) {
|
|
|
123
129
|
const task = latestAnalysed(operations)?.analysis?.task ?? null;
|
|
124
130
|
return task && task.status !== "done" ? task : null;
|
|
125
131
|
}
|
|
132
|
+
/** Vues de tous les dépôts suivis ; les dépôts, les catégories et les opérations sont lus une seule fois. */
|
|
126
133
|
export function listRepoViews(store) {
|
|
127
134
|
store.failOrphanedOperations();
|
|
128
|
-
|
|
135
|
+
const categories = new Map(store.listCategories().map((category) => [category.id, category]));
|
|
136
|
+
const operationsByRepo = new Map();
|
|
137
|
+
for (const operation of store.listAllOperations()) {
|
|
138
|
+
const key = operation.repoId.toLowerCase();
|
|
139
|
+
operationsByRepo.set(key, [...(operationsByRepo.get(key) ?? []), operation]);
|
|
140
|
+
}
|
|
141
|
+
return sortRepos(store.listRepos().map((repo) => {
|
|
142
|
+
const category = repo.categoryId === null ? null : categories.get(repo.categoryId);
|
|
143
|
+
if (category === undefined)
|
|
144
|
+
throw new NotFoundError(`Category "${repo.categoryId}" does not exist.`);
|
|
145
|
+
return buildRepoView(repo, operationsByRepo.get(repo.id.toLowerCase()) ?? [], category);
|
|
146
|
+
}));
|
|
129
147
|
}
|
|
130
148
|
/**
|
|
131
149
|
* Relit les alertes Dependabot ouvertes du dépôt et ses pull requests ouvertes
|
package/dist/src/core/store.d.ts
CHANGED
|
@@ -40,6 +40,8 @@ export declare class Store {
|
|
|
40
40
|
deleteCategory(categoryId: string): void;
|
|
41
41
|
private operationPath;
|
|
42
42
|
private readOperationFile;
|
|
43
|
+
/** Opérations de tous les dépôts, de la plus récente à la plus ancienne. */
|
|
44
|
+
listAllOperations(): Operation[];
|
|
43
45
|
private readAllOperations;
|
|
44
46
|
private readOperationsOf;
|
|
45
47
|
getOperation(id: string): Operation;
|
package/dist/src/core/store.js
CHANGED
|
@@ -42,8 +42,8 @@ export function processAlive(pid) {
|
|
|
42
42
|
* corrigée à la main n'en a aucune, un dépôt sans pull request en attente n'en
|
|
43
43
|
* a aucune jusqu'à sa lecture suivante, un dépôt sans date de dépréciation
|
|
44
44
|
* n'est pas déprécié. Une alerte sans date
|
|
45
|
-
* d'émission prend celle de la lecture qui l'a rapportée
|
|
46
|
-
* la remplace par
|
|
45
|
+
* d'émission prend celle de la lecture qui l'a rapportée, une alerte sans
|
|
46
|
+
* portée n'en a aucune ; la lecture suivante les remplace par les vraies.
|
|
47
47
|
*/
|
|
48
48
|
function normalizeReposFile(file) {
|
|
49
49
|
if (!Array.isArray(file?.repos))
|
|
@@ -59,7 +59,7 @@ function normalizeReposFile(file) {
|
|
|
59
59
|
pullRequests: repo?.pullRequests ?? [],
|
|
60
60
|
deprecatedAt: repo?.deprecatedAt ?? null,
|
|
61
61
|
alerts: Array.isArray(repo?.alerts)
|
|
62
|
-
? repo.alerts.map((alert) => ({ ...alert, createdAt: alert?.createdAt ?? repo.syncedAt ?? repo.addedAt }))
|
|
62
|
+
? repo.alerts.map((alert) => ({ ...alert, createdAt: alert?.createdAt ?? repo.syncedAt ?? repo.addedAt, scope: alert?.scope ?? null }))
|
|
63
63
|
: repo?.alerts,
|
|
64
64
|
})),
|
|
65
65
|
};
|
|
@@ -67,7 +67,9 @@ function normalizeReposFile(file) {
|
|
|
67
67
|
/**
|
|
68
68
|
* Complète une opération écrite par une version antérieure : sans `found`, les
|
|
69
69
|
* vulnérabilités du premier audit sont `remaining` tant qu'aucune correction
|
|
70
|
-
* n'a suivi, et inconnues sinon ; sans étape d'analyse
|
|
70
|
+
* n'a suivi, et inconnues sinon ; sans étape d'analyse ou de corrections par
|
|
71
|
+
* Claude, l'étape est passée ; sans périmètre, l'audit a couvert toutes les
|
|
72
|
+
* dépendances.
|
|
71
73
|
*/
|
|
72
74
|
function normalizeOperation(operation) {
|
|
73
75
|
if (operation === null || typeof operation !== "object")
|
|
@@ -75,8 +77,11 @@ function normalizeOperation(operation) {
|
|
|
75
77
|
return {
|
|
76
78
|
...operation,
|
|
77
79
|
found: operation.found ?? (operation.counts?.afterFix === null ? operation.remaining : []),
|
|
78
|
-
steps: operation.steps && typeof operation.steps === "object" ? { analysis: "skipped", ...operation.steps } : operation.steps,
|
|
80
|
+
steps: operation.steps && typeof operation.steps === "object" ? { analysis: "skipped", repair: "skipped", ...operation.steps } : operation.steps,
|
|
81
|
+
counts: operation.counts && typeof operation.counts === "object" ? { afterRepair: null, ...operation.counts } : operation.counts,
|
|
79
82
|
analysis: operation.analysis ?? null,
|
|
83
|
+
repair: operation.repair ?? null,
|
|
84
|
+
scope: operation.scope ?? "all",
|
|
80
85
|
};
|
|
81
86
|
}
|
|
82
87
|
function sameName(a, b) {
|
|
@@ -295,6 +300,10 @@ export class Store {
|
|
|
295
300
|
throw new TrackerError(`${file} is invalid: ${parsed.error.message}`);
|
|
296
301
|
return parsed.data;
|
|
297
302
|
}
|
|
303
|
+
/** Opérations de tous les dépôts, de la plus récente à la plus ancienne. */
|
|
304
|
+
listAllOperations() {
|
|
305
|
+
return this.readAllOperations();
|
|
306
|
+
}
|
|
298
307
|
readAllOperations() {
|
|
299
308
|
const operations = [];
|
|
300
309
|
for (const entry of fs.readdirSync(this.operationsDir)) {
|
package/dist/src/gui-worker.js
CHANGED
|
@@ -6,7 +6,7 @@ import path from "path";
|
|
|
6
6
|
import fs from "fs";
|
|
7
7
|
import { fileURLToPath } from "url";
|
|
8
8
|
import { IPCMessageSchema } from "../shared/schemas/ipc.schema.js";
|
|
9
|
-
import { AddRepoBodySchema, CategoryBodySchema, ForceBodySchema, PushBodySchema, SetBranchBodySchema, SetCategoryBodySchema, SetRightsBodySchema } from "../shared/schemas/api.schema.js";
|
|
9
|
+
import { AddRepoBodySchema, CategoryBodySchema, ForceBodySchema, PushBodySchema, RepairBodySchema, ScopeBodySchema, SetBranchBodySchema, SetCategoryBodySchema, SetRightsBodySchema } from "../shared/schemas/api.schema.js";
|
|
10
10
|
import { SaveSettingsBodySchema } from "../shared/schemas/settings.schema.js";
|
|
11
11
|
import { resolveLogDir } from "./core/log-dir.js";
|
|
12
12
|
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
@@ -198,7 +198,12 @@ app.post("/api/repos", async (c) => {
|
|
|
198
198
|
});
|
|
199
199
|
app.post("/api/sync", (c) => forward(c, "SYNC_REPOS"));
|
|
200
200
|
app.get("/api/audit-all", (c) => forward(c, "GET_AUDIT_ALL"));
|
|
201
|
-
app.post("/api/audit-all", (c) =>
|
|
201
|
+
app.post("/api/audit-all", async (c) => {
|
|
202
|
+
const read = await readBody(c, ScopeBodySchema);
|
|
203
|
+
if ("response" in read)
|
|
204
|
+
return read.response;
|
|
205
|
+
return forward(c, "START_AUDIT_ALL", { body: read.body });
|
|
206
|
+
});
|
|
202
207
|
app.get("/api/github/repos", (c) => forward(c, "LIST_ADDABLE_REPOS"));
|
|
203
208
|
app.get("/api/repos/:owner/:name", (c) => forward(c, "GET_REPO", { repoId: repoId(c) }));
|
|
204
209
|
app.delete("/api/repos/:owner/:name", (c) => forward(c, "REMOVE_REPO", { repoId: repoId(c) }));
|
|
@@ -239,7 +244,12 @@ app.put("/api/categories/:id", async (c) => {
|
|
|
239
244
|
return forward(c, "RENAME_CATEGORY", { categoryId: c.req.param("id"), body: read.body });
|
|
240
245
|
});
|
|
241
246
|
app.delete("/api/categories/:id", (c) => forward(c, "DELETE_CATEGORY", { categoryId: c.req.param("id") }));
|
|
242
|
-
app.post("/api/repos/:owner/:name/operations", (c) =>
|
|
247
|
+
app.post("/api/repos/:owner/:name/operations", async (c) => {
|
|
248
|
+
const read = await readBody(c, ScopeBodySchema);
|
|
249
|
+
if ("response" in read)
|
|
250
|
+
return read.response;
|
|
251
|
+
return forward(c, "START_FIX", { repoId: repoId(c), body: read.body });
|
|
252
|
+
});
|
|
243
253
|
app.get("/api/operations/:id", (c) => forward(c, "GET_OPERATION", { operationId: c.req.param("id") }));
|
|
244
254
|
app.post("/api/operations/:id/force", async (c) => {
|
|
245
255
|
const read = await readBody(c, ForceBodySchema);
|
|
@@ -247,6 +257,13 @@ app.post("/api/operations/:id/force", async (c) => {
|
|
|
247
257
|
return read.response;
|
|
248
258
|
return forward(c, "DECIDE_FORCE", { operationId: c.req.param("id"), body: read.body });
|
|
249
259
|
});
|
|
260
|
+
app.post("/api/operations/:id/repair", async (c) => {
|
|
261
|
+
const read = await readBody(c, RepairBodySchema);
|
|
262
|
+
if ("response" in read)
|
|
263
|
+
return read.response;
|
|
264
|
+
return forward(c, "DECIDE_REPAIR", { operationId: c.req.param("id"), body: read.body });
|
|
265
|
+
});
|
|
266
|
+
app.get("/api/operations/:id/remarks", (c) => forward(c, "GET_REMARKS", { operationId: c.req.param("id") }));
|
|
250
267
|
app.post("/api/operations/:id/push", async (c) => {
|
|
251
268
|
const read = await readBody(c, PushBodySchema);
|
|
252
269
|
if ("response" in read)
|
package/dist/src/index.js
CHANGED
|
@@ -13,16 +13,18 @@ import { resolveLogDir } from "./core/log-dir.js";
|
|
|
13
13
|
import { githubConfigured, readGitHubConfig } from "./core/config.js";
|
|
14
14
|
import { ConflictError, NotFoundError, TrackerError } from "./core/errors.js";
|
|
15
15
|
import { Store } from "./core/store.js";
|
|
16
|
-
import { cancelOperation, decideForce, pushOperation, runDefaultBranchAudit, startUserFix } from "./core/operations.js";
|
|
16
|
+
import { cancelOperation, decideForce, decideRepair, pushOperation, runDefaultBranchAudit, startUserFix } from "./core/operations.js";
|
|
17
17
|
import { AuditAll } from "./core/audit-all.js";
|
|
18
18
|
import { refreshAnalysisTask } from "./core/analysis.js";
|
|
19
|
+
import { analysisRemarks } from "./core/repair.js";
|
|
19
20
|
import { checkClaudeToken, packagedClaudeCommand } from "./core/claude.js";
|
|
20
21
|
import { OrganizerClient } from "./core/organizer.js";
|
|
21
22
|
import { readSettings, saveSettings, settingsView, testOrganizer } from "./core/settings.js";
|
|
22
23
|
import { SaveSettingsBodySchema } from "../shared/schemas/settings.schema.js";
|
|
24
|
+
import { AUDIT_SCOPES } from "../shared/schemas/model.schema.js";
|
|
23
25
|
import { SYNC_INTERVAL_MS, activeRepos, addRepository, deprecateRepository, listAddableRepositories, restoreRepository, listRepoBranches, listRepoViews, markAlertHandled, setBranch, setCategory, repoView, setRights, staleRepos, syncAllRepositories, syncRepository, unmarkAlertHandled } from "./core/repos.js";
|
|
24
26
|
import { GUI_REQUEST_TYPES, IPCMessageSchema } from "../shared/schemas/ipc.schema.js";
|
|
25
|
-
import { AddRepoBodySchema, AlertRequestSchema, CategoryBodySchema, CategoryRequestSchema, ForceBodySchema, OperationRequestSchema, PushBodySchema, RepoRequestSchema, SetBranchBodySchema, SetCategoryBodySchema, SetRightsBodySchema, } from "../shared/schemas/api.schema.js";
|
|
27
|
+
import { AddRepoBodySchema, AlertRequestSchema, CategoryBodySchema, CategoryRequestSchema, ForceBodySchema, OperationRequestSchema, PushBodySchema, RepairBodySchema, RepoRequestSchema, ScopeBodySchema, SetBranchBodySchema, SetCategoryBodySchema, SetRightsBodySchema, } from "../shared/schemas/api.schema.js";
|
|
26
28
|
import { errorResult, textResult } from "./tools/types.js";
|
|
27
29
|
import { fixVulnerabilities, getAlerts, listRepositories, runAudit } from "./tools/tools.js";
|
|
28
30
|
const __filename = fileURLToPath(import.meta.url);
|
|
@@ -86,7 +88,7 @@ const operations = {
|
|
|
86
88
|
claude,
|
|
87
89
|
};
|
|
88
90
|
/** Série « Auditer tout » de la GUI servie par ce processus. */
|
|
89
|
-
const auditAll = new AuditAll((repoId) => runDefaultBranchAudit(operations, repoId), (message) => logger.error(message));
|
|
91
|
+
const auditAll = new AuditAll((repoId, scope) => runDefaultBranchAudit(operations, repoId, scope), (message) => logger.error(message));
|
|
90
92
|
/** Présentation du serveur transmise au client MCP : concepts, déroulé et règles. */
|
|
91
93
|
const INSTRUCTIONS = `mcp-dependabot-tracker follows the Dependabot alerts of GitHub repositories and fixes their npm vulnerabilities. The user tracks repositories and decides what you may do on each of them in a web GUI; you act only through these tools, never with git or npm yourself.
|
|
92
94
|
|
|
@@ -94,13 +96,14 @@ Concepts:
|
|
|
94
96
|
- A **tracked repository** is a GitHub repository the user added in the GUI. Its open Dependabot alerts, and the pull requests the tracker opened that are not merged or closed yet, are read from GitHub and refreshed every 10 minutes.
|
|
95
97
|
- A **deprecated repository** is one the user set aside in the GUI: it is neither synced nor audited, list_repositories leaves it out, and every tool refuses it until the user restores it.
|
|
96
98
|
- **Rights**: for each repository, the user allows you to run npm audit (audit), npm audit fix (fix), npm audit fix --force (force) and to push the fixes (push). A tool refuses an action you are not allowed to do; only the user can change the rights.
|
|
99
|
+
- The **scope** of an audit is chosen at each launch: production (the default) runs npm audit and npm audit fix with --omit=dev, so the devDependencies are left out; all covers every dependency. Each Dependabot alert says whether its dependency is a runtime or a development one.
|
|
97
100
|
- The **analysed branch** of a repository is chosen by the user in the GUI (the default branch unless changed). Dependabot alerts always describe the default branch; npm audit describes the analysed branch.
|
|
98
101
|
- An **operation** runs in a temporary clone of the analysed branch, deleted at the end: npm audit in every directory that holds a package-lock.json, then npm audit fix with --package-lock-only and --ignore-scripts (lockfiles only, no install, no scripts), optionally --force, then a commit on a new branch fix/npm-audit-<date>-<time> and a pull request to the analysed branch.
|
|
99
102
|
|
|
100
103
|
Workflow:
|
|
101
104
|
1. list_repositories to see the tracked repositories, their open alerts and your rights.
|
|
102
105
|
2. get_alerts for the detail of the alerts of one repository.
|
|
103
|
-
3. run_audit to see what npm audit reports, or fix_vulnerabilities to fix: without push, nothing leaves the temporary clone and the result shows what the fixes would change; with push, the fixes are pushed and the pull request is opened.
|
|
106
|
+
3. run_audit to see what npm audit reports, or fix_vulnerabilities to fix, on the production dependencies unless the user asks for all of them: without push, nothing leaves the temporary clone and the result shows what the fixes would change; with push, the fixes are pushed and the pull request is opened.
|
|
104
107
|
|
|
105
108
|
Rules:
|
|
106
109
|
- An operation runs until it ends; one operation at a time per repository.
|
|
@@ -157,7 +160,7 @@ async function handleGuiRequest(msg) {
|
|
|
157
160
|
case "START_AUDIT_ALL":
|
|
158
161
|
readGitHubConfig();
|
|
159
162
|
store.failOrphanedOperations();
|
|
160
|
-
return { auditAll: auditAll.start(activeRepos(store).map((repo) => repo.id)) };
|
|
163
|
+
return { auditAll: auditAll.start(activeRepos(store).map((repo) => repo.id), parseRequest(ScopeBodySchema, msg.data?.body).scope) };
|
|
161
164
|
case "LIST_ADDABLE_REPOS":
|
|
162
165
|
return { repositories: await listAddableRepositories(store, readGitHubConfig()) };
|
|
163
166
|
case "GET_REPO": {
|
|
@@ -214,7 +217,7 @@ async function handleGuiRequest(msg) {
|
|
|
214
217
|
store.deleteCategory(parseRequest(CategoryRequestSchema, msg.data).categoryId);
|
|
215
218
|
return { deleted: true };
|
|
216
219
|
case "START_FIX":
|
|
217
|
-
return { operation: startUserFix(operations, parseRequest(RepoRequestSchema, msg.data).repoId) };
|
|
220
|
+
return { operation: startUserFix(operations, parseRequest(RepoRequestSchema, msg.data).repoId, parseRequest(ScopeBodySchema, msg.data?.body).scope) };
|
|
218
221
|
case "GET_OPERATION": {
|
|
219
222
|
store.failOrphanedOperations();
|
|
220
223
|
return { operation: store.getOperation(parseRequest(OperationRequestSchema, msg.data).operationId) };
|
|
@@ -223,6 +226,12 @@ async function handleGuiRequest(msg) {
|
|
|
223
226
|
const { operationId } = parseRequest(OperationRequestSchema, msg.data);
|
|
224
227
|
return { operation: decideForce(operations, operationId, parseRequest(ForceBodySchema, msg.data?.body).apply) };
|
|
225
228
|
}
|
|
229
|
+
case "DECIDE_REPAIR": {
|
|
230
|
+
const { operationId } = parseRequest(OperationRequestSchema, msg.data);
|
|
231
|
+
return { operation: decideRepair(operations, operationId, parseRequest(RepairBodySchema, msg.data?.body).run) };
|
|
232
|
+
}
|
|
233
|
+
case "GET_REMARKS":
|
|
234
|
+
return await analysisRemarks(readSettings(dataDir), store.getOperation(parseRequest(OperationRequestSchema, msg.data).operationId));
|
|
226
235
|
case "PUSH_OPERATION": {
|
|
227
236
|
const { operationId } = parseRequest(OperationRequestSchema, msg.data);
|
|
228
237
|
return { operation: pushOperation(operations, operationId, parseRequest(PushBodySchema, msg.data?.body).commitMessage) };
|
|
@@ -337,6 +346,11 @@ async function syncStaleRepos() {
|
|
|
337
346
|
}
|
|
338
347
|
// --- Outils -------------------------------------------------------------------
|
|
339
348
|
const REPOSITORY_DOC = "Tracked repository, as owner/name (see list_repositories).";
|
|
349
|
+
const SCOPE_PROPERTY = {
|
|
350
|
+
type: "string",
|
|
351
|
+
enum: [...AUDIT_SCOPES],
|
|
352
|
+
description: "production (default): npm audit and its fixes run with --omit=dev and leave the devDependencies out. all: every dependency, devDependencies included.",
|
|
353
|
+
};
|
|
340
354
|
const TOOLS = [
|
|
341
355
|
{
|
|
342
356
|
name: "list_repositories",
|
|
@@ -348,7 +362,7 @@ const TOOLS = [
|
|
|
348
362
|
},
|
|
349
363
|
{
|
|
350
364
|
name: "get_alerts",
|
|
351
|
-
description: "Read the open Dependabot alerts of a tracked repository from GitHub now, and list them from the most to the least severe: number, severity, package, ecosystem, manifest, summary, patched version and link.",
|
|
365
|
+
description: "Read the open Dependabot alerts of a tracked repository from GitHub now, and list them from the most to the least severe: number, severity, package, ecosystem, manifest, whether the dependency is a runtime or a development one, summary, patched version and link.",
|
|
352
366
|
inputSchema: {
|
|
353
367
|
type: "object",
|
|
354
368
|
properties: { repository: { type: "string", description: REPOSITORY_DOC } },
|
|
@@ -360,7 +374,7 @@ const TOOLS = [
|
|
|
360
374
|
description: "Run npm audit on a temporary clone of the analysed branch, in every directory that holds a package-lock.json, and report the vulnerabilities with the fix npm proposes (none, within the declared ranges, or a major upgrade that needs --force). Needs the audit right. Nothing is changed; the clone is deleted.",
|
|
361
375
|
inputSchema: {
|
|
362
376
|
type: "object",
|
|
363
|
-
properties: { repository: { type: "string", description: REPOSITORY_DOC } },
|
|
377
|
+
properties: { repository: { type: "string", description: REPOSITORY_DOC }, scope: SCOPE_PROPERTY },
|
|
364
378
|
required: ["repository"],
|
|
365
379
|
},
|
|
366
380
|
},
|
|
@@ -372,6 +386,7 @@ const TOOLS = [
|
|
|
372
386
|
type: "object",
|
|
373
387
|
properties: {
|
|
374
388
|
repository: { type: "string", description: REPOSITORY_DOC },
|
|
389
|
+
scope: SCOPE_PROPERTY,
|
|
375
390
|
force: {
|
|
376
391
|
type: "boolean",
|
|
377
392
|
description: "Also run npm audit fix --force when vulnerabilities remain that only a major upgrade fixes (default false). Breaking changes possible: only when the user asked for it.",
|
package/dist/src/tools/format.js
CHANGED
|
@@ -8,7 +8,14 @@ export function rightsLabel(repo) {
|
|
|
8
8
|
const allowed = RIGHTS.filter((right) => repo.rights[right]);
|
|
9
9
|
return allowed.length === 0 ? "none" : allowed.join(", ");
|
|
10
10
|
}
|
|
11
|
-
/**
|
|
11
|
+
/** Périmètre d'un audit, en clair. */
|
|
12
|
+
function scopeLabel(scope) {
|
|
13
|
+
return scope === "production" ? "production dependencies" : "all dependencies";
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Alertes restantes par gravité, dont celles qui portent sur une dépendance de
|
|
17
|
+
* développement, et le nombre de celles que l'utilisateur a corrigées à la main.
|
|
18
|
+
*/
|
|
12
19
|
function alertsLabel(repo) {
|
|
13
20
|
const pending = pendingAlerts(repo);
|
|
14
21
|
const handled = repo.alerts.length - pending.length;
|
|
@@ -17,7 +24,9 @@ function alertsLabel(repo) {
|
|
|
17
24
|
return `none${handledNote}`;
|
|
18
25
|
const counts = countBySeverity(pending);
|
|
19
26
|
const detail = ALERT_SEVERITIES.filter((severity) => counts[severity] > 0).map((severity) => `${severity} ${counts[severity]}`);
|
|
20
|
-
|
|
27
|
+
const development = pending.filter((alert) => alert.scope === "development").length;
|
|
28
|
+
const developmentNote = development > 0 ? `; ${development} on development dependencies` : "";
|
|
29
|
+
return `${pending.length} (${detail.join(", ")}${developmentNote})${handledNote}`;
|
|
21
30
|
}
|
|
22
31
|
/** Description d'un dépôt pour l'agent ; `category` est la catégorie où l'utilisateur l'a rangé. */
|
|
23
32
|
export function describeRepo(view, category) {
|
|
@@ -34,12 +43,14 @@ export function describeRepo(view, category) {
|
|
|
34
43
|
}
|
|
35
44
|
if (view.unfixable.length > 0)
|
|
36
45
|
lines.push(` Last npm audit found no published fix for: ${view.unfixable.join(", ")}`);
|
|
37
|
-
if (view.
|
|
38
|
-
|
|
46
|
+
if (view.cleanAudit) {
|
|
47
|
+
const { at, scope } = view.cleanAudit;
|
|
48
|
+
const alerts = scope === "production" ? "the Dependabot alerts on production dependencies" : "these Dependabot alerts";
|
|
49
|
+
lines.push(` npm audit of ${at} (${scopeLabel(scope)}) found no vulnerability on the default branch: ${alerts} are probably not refreshed yet.`);
|
|
39
50
|
}
|
|
40
51
|
if (view.auditFindings) {
|
|
41
|
-
const { at, count, severity } = view.auditFindings;
|
|
42
|
-
lines.push(` npm audit of ${at} found ${count} vulnerabilit${count === 1 ? "y" : "ies"} (worst: ${severity}) on the default branch although Dependabot reports none: Dependabot has probably not caught up yet.`);
|
|
52
|
+
const { at, scope, count, severity } = view.auditFindings;
|
|
53
|
+
lines.push(` npm audit of ${at} (${scopeLabel(scope)}) found ${count} vulnerabilit${count === 1 ? "y" : "ies"} (worst: ${severity}) on the default branch although Dependabot reports none there: Dependabot has probably not caught up yet.`);
|
|
43
54
|
}
|
|
44
55
|
lines.push(` Agent rights: ${rightsLabel(repo)}`);
|
|
45
56
|
if (activeOperation)
|
|
@@ -52,7 +63,8 @@ export function describeAlerts(repo) {
|
|
|
52
63
|
const patched = alert.patchedVersion ? ` — patched in ${alert.patchedVersion}` : " — no patched version";
|
|
53
64
|
const mark = repo.handledAlerts.find((candidate) => candidate.number === alert.number);
|
|
54
65
|
const handled = mark ? ` — fixed by hand by the user on ${mark.markedAt}` : "";
|
|
55
|
-
|
|
66
|
+
const scope = alert.scope ? `, ${alert.scope} dependency` : "";
|
|
67
|
+
return `- #${alert.number} ${alert.severity} ${alert.package} (${alert.ecosystem}, ${alert.manifestPath}${scope}): ${alert.summary}${patched}${handled} — ${alert.url}`;
|
|
56
68
|
});
|
|
57
69
|
return [header, ...lines].join("\n");
|
|
58
70
|
}
|
|
@@ -65,7 +77,7 @@ function list(items, render) {
|
|
|
65
77
|
/** Compte rendu d'une opération pour l'agent : étapes, vulnérabilités, paquets modifiés, PR, erreur. */
|
|
66
78
|
export function describeOperation(operation) {
|
|
67
79
|
const title = operation.kind === "audit" ? "npm audit" : "npm audit fix";
|
|
68
|
-
const lines = [`${title} on ${operation.repoId} (operation ${operation.id}): ${operation.status}.`];
|
|
80
|
+
const lines = [`${title} on ${operation.repoId}, ${scopeLabel(operation.scope)} (operation ${operation.id}): ${operation.status}.`];
|
|
69
81
|
if (operation.projects.length > 0) {
|
|
70
82
|
lines.push(`- npm projects: ${operation.projects.map((project) => projectLabel(project) || "./").join(", ")}`);
|
|
71
83
|
}
|
package/dist/src/tools/tools.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { DEFAULT_COMMIT_MESSAGE } from "../../shared/schemas/model.schema.js";
|
|
1
|
+
import { AUDIT_SCOPES, DEFAULT_AUDIT_SCOPE, DEFAULT_COMMIT_MESSAGE } from "../../shared/schemas/model.schema.js";
|
|
2
2
|
import { TrackerError } from "../core/errors.js";
|
|
3
3
|
import { runAgentOperation } from "../core/operations.js";
|
|
4
4
|
import { listRepoViews, repoView, syncRepository } from "../core/repos.js";
|
|
5
5
|
import { describeAlerts, describeOperation, describeRepo } from "./format.js";
|
|
6
|
-
import { errorResult, optionalBoolean, optionalString, rejectUnknownFields, requireString, textResult } from "./types.js";
|
|
6
|
+
import { errorResult, optionalBoolean, optionalEnum, optionalString, rejectUnknownFields, requireString, textResult } from "./types.js";
|
|
7
7
|
const RIGHT_LABELS = {
|
|
8
8
|
audit: "run npm audit",
|
|
9
9
|
fix: "run npm audit fix",
|
|
@@ -51,14 +51,16 @@ function operationResult(operation) {
|
|
|
51
51
|
return { result: operation.status === "done" ? textResult(text) : errorResult(text), operation };
|
|
52
52
|
}
|
|
53
53
|
export async function runAudit(ctx, args) {
|
|
54
|
-
rejectUnknownFields(args, ["repository"]);
|
|
54
|
+
rejectUnknownFields(args, ["repository", "scope"]);
|
|
55
55
|
const repo = ctx.store.getRepo(requireString(args, "repository"));
|
|
56
|
+
const scope = optionalEnum(args, "scope", AUDIT_SCOPES, DEFAULT_AUDIT_SCOPE);
|
|
56
57
|
assertAllowed(repo, "audit");
|
|
57
|
-
return operationResult(await runAgentOperation(ctx, repo.id, "audit", { force: false, push: false, commitMessage: DEFAULT_COMMIT_MESSAGE }));
|
|
58
|
+
return operationResult(await runAgentOperation(ctx, repo.id, "audit", { scope, force: false, push: false, commitMessage: DEFAULT_COMMIT_MESSAGE }));
|
|
58
59
|
}
|
|
59
60
|
export async function fixVulnerabilities(ctx, args) {
|
|
60
|
-
rejectUnknownFields(args, ["repository", "force", "push", "commit_message"]);
|
|
61
|
+
rejectUnknownFields(args, ["repository", "scope", "force", "push", "commit_message"]);
|
|
61
62
|
const repo = ctx.store.getRepo(requireString(args, "repository"));
|
|
63
|
+
const scope = optionalEnum(args, "scope", AUDIT_SCOPES, DEFAULT_AUDIT_SCOPE);
|
|
62
64
|
const force = optionalBoolean(args, "force", false);
|
|
63
65
|
const push = optionalBoolean(args, "push", false);
|
|
64
66
|
const commitMessage = optionalString(args, "commit_message") ?? DEFAULT_COMMIT_MESSAGE;
|
|
@@ -67,5 +69,5 @@ export async function fixVulnerabilities(ctx, args) {
|
|
|
67
69
|
assertAllowed(repo, "force");
|
|
68
70
|
if (push)
|
|
69
71
|
assertAllowed(repo, "push");
|
|
70
|
-
return operationResult(await runAgentOperation(ctx, repo.id, "fix", { force, push, commitMessage }));
|
|
72
|
+
return operationResult(await runAgentOperation(ctx, repo.id, "fix", { scope, force, push, commitMessage }));
|
|
71
73
|
}
|