@imenam/mcp-dependabot-tracker 0.0.0-stage → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. package/README.md +208 -2
  2. package/dist/shared/schemas/api.schema.d.ts +49 -0
  3. package/dist/shared/schemas/api.schema.js +11 -0
  4. package/dist/shared/schemas/ipc.schema.d.ts +26 -0
  5. package/dist/shared/schemas/ipc.schema.js +30 -0
  6. package/dist/shared/schemas/model.schema.d.ts +276 -0
  7. package/dist/shared/schemas/model.schema.js +116 -0
  8. package/dist/src/cli/setup-mcp.d.ts +24 -0
  9. package/dist/src/cli/setup-mcp.js +137 -0
  10. package/dist/src/core/commands.d.ts +26 -0
  11. package/dist/src/core/commands.js +101 -0
  12. package/dist/src/core/config.d.ts +12 -0
  13. package/dist/src/core/config.js +18 -0
  14. package/dist/src/core/data-dir.d.ts +11 -0
  15. package/dist/src/core/data-dir.js +27 -0
  16. package/dist/src/core/errors.d.ts +12 -0
  17. package/dist/src/core/errors.js +21 -0
  18. package/dist/src/core/github.d.ts +43 -0
  19. package/dist/src/core/github.js +122 -0
  20. package/dist/src/core/log-dir.d.ts +6 -0
  21. package/dist/src/core/log-dir.js +13 -0
  22. package/dist/src/core/npm-audit.d.ts +36 -0
  23. package/dist/src/core/npm-audit.js +115 -0
  24. package/dist/src/core/operations.d.ts +42 -0
  25. package/dist/src/core/operations.js +438 -0
  26. package/dist/src/core/repo-ref.d.ts +9 -0
  27. package/dist/src/core/repo-ref.js +33 -0
  28. package/dist/src/core/repos.d.ts +23 -0
  29. package/dist/src/core/repos.js +84 -0
  30. package/dist/src/core/store.d.ts +49 -0
  31. package/dist/src/core/store.js +266 -0
  32. package/dist/src/gui-worker.d.ts +1 -0
  33. package/dist/src/gui-worker.js +325 -0
  34. package/dist/src/index.d.ts +2 -0
  35. package/dist/src/index.js +363 -0
  36. package/dist/src/tools/format.d.ts +7 -0
  37. package/dist/src/tools/format.js +81 -0
  38. package/dist/src/tools/tools.d.ts +15 -0
  39. package/dist/src/tools/tools.js +56 -0
  40. package/dist/src/tools/types.d.ts +21 -0
  41. package/dist/src/tools/types.js +38 -0
  42. package/dist/src/version.d.ts +1 -0
  43. package/dist/src/version.js +16 -0
  44. package/gui/dist/assets/index-BBJkUr54.css +1 -0
  45. package/gui/dist/assets/index-DbT51E3H.js +63 -0
  46. package/gui/dist/assets/inter-cyrillic-ext-wght-normal-BOeWTOD4.woff2 +0 -0
  47. package/gui/dist/assets/inter-cyrillic-wght-normal-DqGufNeO.woff2 +0 -0
  48. package/gui/dist/assets/inter-greek-ext-wght-normal-DlzME5K_.woff2 +0 -0
  49. package/gui/dist/assets/inter-greek-wght-normal-CkhJZR-_.woff2 +0 -0
  50. package/gui/dist/assets/inter-latin-ext-wght-normal-DO1Apj_S.woff2 +0 -0
  51. package/gui/dist/assets/inter-latin-wght-normal-Dx4kXJAl.woff2 +0 -0
  52. package/gui/dist/assets/inter-vietnamese-wght-normal-CBcvBZtf.woff2 +0 -0
  53. package/gui/dist/assets/jetbrains-mono-cyrillic-wght-normal-D73BlboJ.woff2 +0 -0
  54. package/gui/dist/assets/jetbrains-mono-greek-wght-normal-Bw9x6K1M.woff2 +0 -0
  55. package/gui/dist/assets/jetbrains-mono-latin-ext-wght-normal-DBQx-q_a.woff2 +0 -0
  56. package/gui/dist/assets/jetbrains-mono-latin-wght-normal-B9CIFXIH.woff2 +0 -0
  57. package/gui/dist/assets/jetbrains-mono-vietnamese-wght-normal-Bt-aOZkq.woff2 +0 -0
  58. package/gui/dist/index.html +13 -0
  59. package/package.json +57 -4
@@ -0,0 +1,122 @@
1
+ import { ALERT_SEVERITIES } from "../../shared/schemas/model.schema.js";
2
+ import { NotFoundError, TrackerError } from "./errors.js";
3
+ const REQUEST_TIMEOUT_MS = 30_000;
4
+ /** Nombre maximal de pages d'alertes lues (100 alertes par page). */
5
+ const MAX_ALERT_PAGES = 20;
6
+ /** URL de la page suivante dans un en-tête `Link` de pagination, ou null. */
7
+ export function nextPageUrl(link) {
8
+ if (!link)
9
+ return null;
10
+ for (const part of link.split(",")) {
11
+ const match = /<([^>]+)>\s*;\s*rel="next"/.exec(part);
12
+ if (match)
13
+ return match[1];
14
+ }
15
+ return null;
16
+ }
17
+ /** Client REST minimal de l'API GitHub, authentifié par le token de la configuration. */
18
+ export class GitHubClient {
19
+ config;
20
+ constructor(config) {
21
+ this.config = config;
22
+ }
23
+ async request(method, url, body) {
24
+ let response;
25
+ try {
26
+ response = await fetch(url.startsWith("http") ? url : `${this.config.apiUrl}${url}`, {
27
+ method,
28
+ headers: {
29
+ Accept: "application/vnd.github+json",
30
+ Authorization: `Bearer ${this.config.token}`,
31
+ "X-GitHub-Api-Version": "2022-11-28",
32
+ "User-Agent": "mcp-dependabot-tracker",
33
+ ...(body === undefined ? {} : { "Content-Type": "application/json" }),
34
+ },
35
+ body: body === undefined ? undefined : JSON.stringify(body),
36
+ signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS),
37
+ });
38
+ }
39
+ catch (err) {
40
+ throw new TrackerError(`GitHub API unreachable (${method} ${url}): ${err?.message ?? err}`);
41
+ }
42
+ const text = await response.text();
43
+ let json = null;
44
+ if (text !== "") {
45
+ try {
46
+ json = JSON.parse(text);
47
+ }
48
+ catch {
49
+ throw new TrackerError(`GitHub API returned a non-JSON response (${method} ${url}, HTTP ${response.status}).`);
50
+ }
51
+ }
52
+ if (!response.ok) {
53
+ const message = typeof json?.message === "string" ? json.message : `HTTP ${response.status}`;
54
+ if (response.status === 401)
55
+ throw new TrackerError(`GitHub rejected GITHUB_TOKEN (401: ${message}).`);
56
+ throw new GitHubApiError(response.status, `GitHub API ${method} ${url} failed (${response.status}): ${message}`);
57
+ }
58
+ return { json, link: response.headers.get("link") };
59
+ }
60
+ async getRepository(owner, name) {
61
+ try {
62
+ const { json } = await this.request("GET", `/repos/${owner}/${name}`);
63
+ return { owner: json.owner.login, name: json.name, fullName: json.full_name, defaultBranch: json.default_branch };
64
+ }
65
+ catch (err) {
66
+ if (err instanceof GitHubApiError && err.status === 404) {
67
+ throw new NotFoundError(`Repository ${owner}/${name} not found on GitHub, or GITHUB_TOKEN cannot access it.`);
68
+ }
69
+ throw err;
70
+ }
71
+ }
72
+ /** Alertes Dependabot ouvertes du dépôt, toutes pages comprises. */
73
+ async listOpenAlerts(owner, name) {
74
+ const alerts = [];
75
+ let url = `/repos/${owner}/${name}/dependabot/alerts?state=open&per_page=100`;
76
+ for (let page = 0; url !== null; page += 1) {
77
+ if (page === MAX_ALERT_PAGES) {
78
+ throw new TrackerError(`${owner}/${name} has more than ${MAX_ALERT_PAGES * 100} open Dependabot alerts; the tracker reads at most that many.`);
79
+ }
80
+ const { json, link } = await this.request("GET", url);
81
+ if (!Array.isArray(json))
82
+ throw new TrackerError(`GitHub API returned an unexpected list of alerts for ${owner}/${name}.`);
83
+ for (const raw of json)
84
+ alerts.push(toAlert(raw));
85
+ url = nextPageUrl(link);
86
+ }
87
+ return alerts;
88
+ }
89
+ async getAuthenticatedUser() {
90
+ const { json } = await this.request("GET", "/user");
91
+ return { login: json.login, id: json.id, name: json.name ?? null };
92
+ }
93
+ async createPullRequest(owner, name, pr) {
94
+ const { json } = await this.request("POST", `/repos/${owner}/${name}/pulls`, pr);
95
+ return { number: json.number, url: json.html_url };
96
+ }
97
+ }
98
+ /** Échec HTTP de l'API GitHub, avec son code. */
99
+ export class GitHubApiError extends TrackerError {
100
+ status;
101
+ constructor(status, message) {
102
+ super(message);
103
+ this.status = status;
104
+ this.name = "GitHubApiError";
105
+ }
106
+ }
107
+ function toAlert(raw) {
108
+ const severity = raw?.security_advisory?.severity ?? raw?.security_vulnerability?.severity;
109
+ if (!ALERT_SEVERITIES.includes(severity)) {
110
+ throw new TrackerError(`Dependabot alert #${raw?.number} has an unknown severity: ${JSON.stringify(severity)}.`);
111
+ }
112
+ return {
113
+ number: raw.number,
114
+ severity: severity,
115
+ ecosystem: raw.dependency?.package?.ecosystem ?? "",
116
+ package: raw.dependency?.package?.name ?? "",
117
+ manifestPath: raw.dependency?.manifest_path ?? "",
118
+ summary: raw.security_advisory?.summary ?? "",
119
+ url: raw.html_url ?? "",
120
+ patchedVersion: raw.security_vulnerability?.first_patched_version?.identifier ?? null,
121
+ };
122
+ }
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Répertoire des logs : MCP_LOG_DIR s'il est renseigné, sinon <dataDir>/logs.
3
+ * Lu depuis process.env au démarrage, avant le chargement du .env du package :
4
+ * la variable vient donc de la déclaration du serveur dans le client MCP.
5
+ */
6
+ export declare function resolveLogDir(): string;
@@ -0,0 +1,13 @@
1
+ import path from "path";
2
+ import { resolveDataDir } from "./data-dir.js";
3
+ /**
4
+ * Répertoire des logs : MCP_LOG_DIR s'il est renseigné, sinon <dataDir>/logs.
5
+ * Lu depuis process.env au démarrage, avant le chargement du .env du package :
6
+ * la variable vient donc de la déclaration du serveur dans le client MCP.
7
+ */
8
+ export function resolveLogDir() {
9
+ const configured = process.env.MCP_LOG_DIR?.trim();
10
+ if (configured)
11
+ return path.resolve(configured);
12
+ return path.join(resolveDataDir(), "logs");
13
+ }
@@ -0,0 +1,36 @@
1
+ import { type Change, type ForceCandidate, type Vulnerability } from "../../shared/schemas/model.schema.js";
2
+ /** Contenu d'un `package-lock.json` utile ici : la version de chaque paquet installé, par chemin. */
3
+ export interface Lockfile {
4
+ packages: Record<string, {
5
+ version?: string;
6
+ }>;
7
+ }
8
+ /** Vulnérabilité lue dans un rapport, avec la correction que propose npm. */
9
+ export interface AuditedVulnerability extends Vulnerability {
10
+ fixPackage: string | null;
11
+ fixVersion: string | null;
12
+ }
13
+ /** Lit la sortie JSON d'un appel npm ; une sortie qui n'est pas du JSON, ou qui porte une erreur npm, lève une erreur. */
14
+ export declare function parseNpmJson(stdout: string, stderr: string, what: string): any;
15
+ /**
16
+ * Vulnérabilités d'un rapport `npm audit --json` (format `auditReportVersion` 2).
17
+ * `fixAvailable` vaut false (aucune correction), true (dans les plages déclarées)
18
+ * ou un objet `{ name, version, isSemVerMajor }` qui désigne le paquet à mettre à
19
+ * jour ; une montée majeure demande `--force`.
20
+ */
21
+ export declare function parseAuditReport(report: any, project: string): AuditedVulnerability[];
22
+ /**
23
+ * Paquets que `npm audit fix --force` monterait d'une version majeure, un par
24
+ * paquet et par projet, avec le nombre de vulnérabilités que cette montée corrige.
25
+ */
26
+ export declare function forceCandidates(vulnerabilities: AuditedVulnerability[], locks: Record<string, Lockfile>): ForceCandidate[];
27
+ /**
28
+ * Paquets dont la version diffère entre deux lockfiles d'un projet. Le nom est
29
+ * le chemin d'installation sans le premier `node_modules/` : `lodash`, ou
30
+ * `d3-sankey/node_modules/d3-array` pour une copie imbriquée.
31
+ */
32
+ export declare function diffLockfiles(before: Lockfile, after: Lockfile, project: string): Change[];
33
+ /** Lit un `package-lock.json` ; un lockfile v1 (npm 6), sans `packages`, est refusé. */
34
+ export declare function parseLockfile(text: string, project: string): Lockfile;
35
+ /** Préfixe d'affichage d'un projet : `""` pour la racine, `gui/` pour le dossier `gui`. */
36
+ export declare function projectLabel(project: string): string;
@@ -0,0 +1,115 @@
1
+ import { NPM_SEVERITIES } from "../../shared/schemas/model.schema.js";
2
+ import { TrackerError } from "./errors.js";
3
+ /** Lit la sortie JSON d'un appel npm ; une sortie qui n'est pas du JSON, ou qui porte une erreur npm, lève une erreur. */
4
+ export function parseNpmJson(stdout, stderr, what) {
5
+ let json;
6
+ try {
7
+ json = JSON.parse(stdout);
8
+ }
9
+ catch {
10
+ const detail = stderr.trim() || stdout.trim() || "no output";
11
+ throw new TrackerError(`${what} did not return JSON: ${detail.slice(-1500)}`);
12
+ }
13
+ if (json && typeof json === "object" && json.error) {
14
+ const summary = json.error.summary ?? json.error.message ?? JSON.stringify(json.error);
15
+ const detail = json.error.detail ? ` ${json.error.detail}` : "";
16
+ throw new TrackerError(`${what} failed: ${summary}${detail}`.trim());
17
+ }
18
+ return json;
19
+ }
20
+ /**
21
+ * Vulnérabilités d'un rapport `npm audit --json` (format `auditReportVersion` 2).
22
+ * `fixAvailable` vaut false (aucune correction), true (dans les plages déclarées)
23
+ * ou un objet `{ name, version, isSemVerMajor }` qui désigne le paquet à mettre à
24
+ * jour ; une montée majeure demande `--force`.
25
+ */
26
+ export function parseAuditReport(report, project) {
27
+ if (report?.auditReportVersion !== 2 || typeof report.vulnerabilities !== "object" || report.vulnerabilities === null) {
28
+ throw new TrackerError(`Unsupported npm audit report for ${projectLabel(project)}package-lock.json: expected auditReportVersion 2 (npm 7 or later).`);
29
+ }
30
+ return Object.values(report.vulnerabilities).map((entry) => {
31
+ const severity = NPM_SEVERITIES.includes(entry.severity) ? entry.severity : "info";
32
+ const fixAvailable = entry.fixAvailable;
33
+ if (fixAvailable === true) {
34
+ return { project, name: entry.name, severity, fix: "available", fixPackage: null, fixVersion: null };
35
+ }
36
+ if (fixAvailable && typeof fixAvailable === "object") {
37
+ return {
38
+ project,
39
+ name: entry.name,
40
+ severity,
41
+ fix: fixAvailable.isSemVerMajor ? "major" : "available",
42
+ fixPackage: fixAvailable.name,
43
+ fixVersion: fixAvailable.version,
44
+ };
45
+ }
46
+ return { project, name: entry.name, severity, fix: "none", fixPackage: null, fixVersion: null };
47
+ });
48
+ }
49
+ /** Version installée d'un paquet de premier niveau dans le lockfile, ou null. */
50
+ function installedVersion(lock, name) {
51
+ return lock.packages[`node_modules/${name}`]?.version ?? null;
52
+ }
53
+ /**
54
+ * Paquets que `npm audit fix --force` monterait d'une version majeure, un par
55
+ * paquet et par projet, avec le nombre de vulnérabilités que cette montée corrige.
56
+ */
57
+ export function forceCandidates(vulnerabilities, locks) {
58
+ const byKey = new Map();
59
+ for (const vulnerability of vulnerabilities) {
60
+ if (vulnerability.fix !== "major" || !vulnerability.fixPackage || !vulnerability.fixVersion)
61
+ continue;
62
+ const key = `${vulnerability.project}\0${vulnerability.fixPackage}`;
63
+ const existing = byKey.get(key);
64
+ if (existing) {
65
+ existing.vulnerabilities += 1;
66
+ continue;
67
+ }
68
+ const lock = locks[vulnerability.project];
69
+ byKey.set(key, {
70
+ project: vulnerability.project,
71
+ name: vulnerability.fixPackage,
72
+ from: lock ? installedVersion(lock, vulnerability.fixPackage) : null,
73
+ to: vulnerability.fixVersion,
74
+ vulnerabilities: 1,
75
+ });
76
+ }
77
+ return [...byKey.values()].sort((a, b) => a.project.localeCompare(b.project) || a.name.localeCompare(b.name));
78
+ }
79
+ /**
80
+ * Paquets dont la version diffère entre deux lockfiles d'un projet. Le nom est
81
+ * le chemin d'installation sans le premier `node_modules/` : `lodash`, ou
82
+ * `d3-sankey/node_modules/d3-array` pour une copie imbriquée.
83
+ */
84
+ export function diffLockfiles(before, after, project) {
85
+ const keys = new Set([...Object.keys(before.packages), ...Object.keys(after.packages)]);
86
+ const changes = [];
87
+ for (const key of keys) {
88
+ if (!key.startsWith("node_modules/"))
89
+ continue;
90
+ const from = before.packages[key]?.version ?? null;
91
+ const to = after.packages[key]?.version ?? null;
92
+ if (from === to)
93
+ continue;
94
+ changes.push({ project, name: key.slice("node_modules/".length), from, to });
95
+ }
96
+ return changes.sort((a, b) => a.name.localeCompare(b.name));
97
+ }
98
+ /** Lit un `package-lock.json` ; un lockfile v1 (npm 6), sans `packages`, est refusé. */
99
+ export function parseLockfile(text, project) {
100
+ let json;
101
+ try {
102
+ json = JSON.parse(text);
103
+ }
104
+ catch (err) {
105
+ throw new TrackerError(`${projectLabel(project)}package-lock.json is not valid JSON: ${err.message}`);
106
+ }
107
+ if (!json || typeof json.packages !== "object" || json.packages === null) {
108
+ throw new TrackerError(`${projectLabel(project)}package-lock.json has no "packages" section: lockfile version 2 or 3 (npm 7 or later) is required.`);
109
+ }
110
+ return { packages: json.packages };
111
+ }
112
+ /** Préfixe d'affichage d'un projet : `""` pour la racine, `gui/` pour le dossier `gui`. */
113
+ export function projectLabel(project) {
114
+ return project === "" ? "" : `${project}/`;
115
+ }
@@ -0,0 +1,42 @@
1
+ import { type Operation, type OperationKind } from "../../shared/schemas/model.schema.js";
2
+ import type { GitHubConfig } from "./config.js";
3
+ import { type Store } from "./store.js";
4
+ /** Accès aux données et à GitHub pour exécuter les opérations. */
5
+ export interface OperationContext {
6
+ store: Store;
7
+ /** Configuration GitHub, lue à chaque opération ; lève une erreur si GITHUB_TOKEN manque. */
8
+ githubConfig: () => GitHubConfig;
9
+ /** Dossier où créer le clone d'une opération, qui existe au retour. */
10
+ cloneDir: () => string;
11
+ /** Journalise une erreur d'une exécution en arrière-plan qui n'a pas pu être enregistrée dans l'opération. */
12
+ logError: (message: string) => void;
13
+ }
14
+ /** Choix de l'agent pour une opération qu'il mène d'un bout à l'autre. */
15
+ export interface AgentPlan {
16
+ force: boolean;
17
+ push: boolean;
18
+ commitMessage: string;
19
+ }
20
+ /** `fix/npm-audit-2026-10-28-143205`, à l'heure locale du serveur. */
21
+ export declare function branchName(date: Date): string;
22
+ /**
23
+ * Lance une correction depuis la GUI : clone, audit et `npm audit fix` s'exécutent
24
+ * en arrière-plan, puis l'opération attend la décision sur `--force` ou le push.
25
+ */
26
+ export declare function startUserFix(ctx: OperationContext, repoId: string): Operation;
27
+ /** Applique ou passe `npm audit fix --force` sur une opération qui attend cette décision. */
28
+ export declare function decideForce(ctx: OperationContext, id: string, apply: boolean): Operation;
29
+ /** Commit, push et pull request d'une opération qui attend le push. */
30
+ export declare function pushOperation(ctx: OperationContext, id: string, commitMessage: string): Operation;
31
+ /**
32
+ * Annule une opération : une opération en attente se termine aussitôt ; une
33
+ * opération en cours reçoit une demande d'annulation, lue par le processus qui
34
+ * l'exécute, qui arrête sa commande.
35
+ */
36
+ export declare function cancelOperation(ctx: OperationContext, id: string): Operation;
37
+ /**
38
+ * Opération menée par l'agent d'un bout à l'autre, attendue jusqu'à sa fin :
39
+ * `audit` s'arrête après `npm audit` ; `fix` enchaîne `npm audit fix`, puis
40
+ * `--force` et le push selon `plan`.
41
+ */
42
+ export declare function runAgentOperation(ctx: OperationContext, repoId: string, kind: OperationKind, plan: AgentPlan): Promise<Operation>;