cve-lite-cli 1.0.2 → 1.0.4

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.
@@ -0,0 +1,26 @@
1
+ export async function osvQueryBatch(packages) {
2
+ const response = await fetch("https://api.osv.dev/v1/querybatch", {
3
+ method: "POST",
4
+ headers: { "content-type": "application/json" },
5
+ body: JSON.stringify({
6
+ queries: packages.map(pkg => ({
7
+ package: {
8
+ ecosystem: pkg.ecosystem,
9
+ name: pkg.name
10
+ },
11
+ version: pkg.version
12
+ }))
13
+ })
14
+ });
15
+ if (!response.ok) {
16
+ throw new Error(`OSV batch query failed: ${response.status} ${response.statusText}`);
17
+ }
18
+ return response.json();
19
+ }
20
+ export async function osvGetVuln(id) {
21
+ const response = await fetch(`https://api.osv.dev/v1/vulns/${encodeURIComponent(id)}`);
22
+ if (!response.ok) {
23
+ throw new Error(`OSV vuln fetch failed for ${id}`);
24
+ }
25
+ return response.json();
26
+ }
@@ -0,0 +1,31 @@
1
+ import fs from "node:fs";
2
+ import path from "node:path";
3
+ import os from "node:os";
4
+ export function getCacheFilePath(cacheDirOverride) {
5
+ const baseDir = cacheDirOverride
6
+ ? path.resolve(cacheDirOverride)
7
+ : path.join(os.homedir(), ".cache", "cve-lite");
8
+ fs.mkdirSync(baseDir, { recursive: true });
9
+ return path.join(baseDir, "osv-vulns.json");
10
+ }
11
+ export function loadCache(cacheDirOverride) {
12
+ const filePath = getCacheFilePath(cacheDirOverride);
13
+ if (!fs.existsSync(filePath)) {
14
+ return { version: 1, createdAt: new Date().toISOString(), entries: {} };
15
+ }
16
+ try {
17
+ const parsed = JSON.parse(fs.readFileSync(filePath, "utf8"));
18
+ if (parsed.version === 1 && parsed.entries) {
19
+ return parsed;
20
+ }
21
+ }
22
+ catch (_error) {
23
+ // ignore corrupt cache
24
+ }
25
+ return { version: 1, createdAt: new Date().toISOString(), entries: {} };
26
+ }
27
+ export function saveCache(cache, cacheDirOverride) {
28
+ const filePath = getCacheFilePath(cacheDirOverride);
29
+ cache.createdAt = new Date().toISOString();
30
+ fs.writeFileSync(filePath, JSON.stringify(cache, null, 2), "utf8");
31
+ }
@@ -0,0 +1,50 @@
1
+ import { severityOrder } from "../constants.js";
2
+ export function maxSeverity(vulns) {
3
+ let current = "none";
4
+ for (const vuln of vulns) {
5
+ const sev = inferSeverity(vuln);
6
+ if (severityOrder[sev] > severityOrder[current]) {
7
+ current = sev;
8
+ }
9
+ }
10
+ return current;
11
+ }
12
+ export function inferSeverity(vuln) {
13
+ const rawScores = vuln.severity ?? [];
14
+ for (const item of rawScores) {
15
+ const score = item?.score ?? "";
16
+ const label = severityFromScore(score);
17
+ if (label !== "unknown")
18
+ return label;
19
+ }
20
+ const db = vuln.database_specific;
21
+ const dbSeverity = String(db?.severity ?? "").toLowerCase();
22
+ if (["critical", "high", "medium", "low"].includes(dbSeverity)) {
23
+ return dbSeverity;
24
+ }
25
+ return "unknown";
26
+ }
27
+ function severityFromScore(score) {
28
+ const match = String(score).match(/([0-9]+(?:\.[0-9]+)?)/);
29
+ if (!match)
30
+ return "unknown";
31
+ const value = Number(match[1]);
32
+ if (Number.isNaN(value))
33
+ return "unknown";
34
+ if (value >= 9.0)
35
+ return "critical";
36
+ if (value >= 7.0)
37
+ return "high";
38
+ if (value >= 4.0)
39
+ return "medium";
40
+ if (value > 0)
41
+ return "low";
42
+ return "none";
43
+ }
44
+ export function normalizeSeverity(input) {
45
+ const normalized = String(input || "").toLowerCase();
46
+ if (["none", "low", "medium", "high", "critical", "unknown"].includes(normalized)) {
47
+ return normalized;
48
+ }
49
+ return "critical";
50
+ }
@@ -0,0 +1,113 @@
1
+ import { chalk } from "../utils/chalk.js";
2
+ import { loadCache } from "../osv/cache.js";
3
+ import { inferSeverity } from "../osv/severity.js";
4
+ export function formatSeverityLabel(severity) {
5
+ if (severity === "critical")
6
+ return chalk.redBright(severity);
7
+ if (severity === "high")
8
+ return chalk.red(severity);
9
+ if (severity === "medium")
10
+ return chalk.yellow(severity);
11
+ if (severity === "low")
12
+ return chalk.blueBright(severity);
13
+ if (severity === "unknown")
14
+ return chalk.magenta(severity);
15
+ return severity;
16
+ }
17
+ export function formatRelationshipLabel(value) {
18
+ if (value === "direct")
19
+ return chalk.green(value);
20
+ if (value === "transitive")
21
+ return chalk.yellow(value);
22
+ return chalk.gray(value);
23
+ }
24
+ export function getPrimaryParent(finding) {
25
+ const firstPath = finding.dependencyPaths?.[0];
26
+ if (!firstPath || firstPath.length < 3)
27
+ return null;
28
+ return firstPath[1] ?? null;
29
+ }
30
+ export function getRecommendedAction(finding) {
31
+ if (finding.relationship === "direct" && finding.firstFixedVersion) {
32
+ return `Upgrade ${finding.pkg.name} to ${finding.firstFixedVersion}+ in this project.`;
33
+ }
34
+ if (finding.relationship === "direct") {
35
+ return `Review and upgrade ${finding.pkg.name} directly in this project.`;
36
+ }
37
+ const parent = getPrimaryParent(finding);
38
+ if (parent && finding.firstFixedVersion) {
39
+ return `Review ${parent}; aim for a version that resolves ${finding.pkg.name} to ${finding.firstFixedVersion}+`;
40
+ }
41
+ if (parent) {
42
+ return `Review ${parent}; it currently pulls in vulnerable ${finding.pkg.name}.`;
43
+ }
44
+ if (finding.firstFixedVersion) {
45
+ return `Upgrade the parent dependency chain so ${finding.pkg.name} resolves to ${finding.firstFixedVersion}+`;
46
+ }
47
+ return `Inspect the dependency path for ${finding.pkg.name} and choose the safest upgrade path.`;
48
+ }
49
+ export function summarizeRisk(finding) {
50
+ if (finding.severity === "critical" && finding.relationship === "direct") {
51
+ return "Critical direct dependency. Prioritize this first because the project controls it directly.";
52
+ }
53
+ if (finding.severity === "high" && finding.relationship === "direct") {
54
+ return "High-severity direct dependency. A direct upgrade is likely the fastest path.";
55
+ }
56
+ if (finding.relationship === "transitive" && finding.firstFixedVersion) {
57
+ return `Transitive issue. Look for a parent dependency upgrade that pulls in ${finding.firstFixedVersion}+`;
58
+ }
59
+ if (finding.relationship === "transitive") {
60
+ return "Transitive issue. Review the parent path and check whether an upstream package can be upgraded.";
61
+ }
62
+ if (finding.firstFixedVersion) {
63
+ return `A fixed-version hint exists. Aim for at least ${finding.firstFixedVersion}.`;
64
+ }
65
+ return "Review this finding and inspect the dependency path for the safest upgrade path.";
66
+ }
67
+ export function summarizeNextAction(finding) {
68
+ if (finding.relationship === "direct" && finding.firstFixedVersion) {
69
+ return `Upgrade ${finding.pkg.name} toward ${finding.firstFixedVersion}.`;
70
+ }
71
+ if (finding.relationship === "direct") {
72
+ return `Review and upgrade ${finding.pkg.name} directly in this project.`;
73
+ }
74
+ if (finding.firstFixedVersion) {
75
+ return `Upgrade the parent dependency chain so it resolves ${finding.pkg.name} to ${finding.firstFixedVersion}+`;
76
+ }
77
+ return `Inspect the parent dependency chain for ${finding.pkg.name} and choose the safest available upgrade.`;
78
+ }
79
+ export function serializeFinding(finding) {
80
+ return {
81
+ package: finding.pkg.name,
82
+ version: finding.pkg.version,
83
+ severity: finding.severity,
84
+ relationship: finding.relationship,
85
+ firstFixedVersion: finding.firstFixedVersion,
86
+ recommendedAction: getRecommendedAction(finding),
87
+ primaryParent: getPrimaryParent(finding),
88
+ cves: finding.cveAliases,
89
+ dependencyPaths: finding.dependencyPaths,
90
+ vulnerabilities: finding.vulnerabilities.map(v => ({
91
+ id: v.id,
92
+ aliases: v.aliases ?? [],
93
+ summary: v.summary ?? "",
94
+ severity: inferSeverity(v)
95
+ }))
96
+ };
97
+ }
98
+ export function printCacheSummary(cacheDirOverride, options) {
99
+ if (options?.json)
100
+ return;
101
+ const cache = loadCache(cacheDirOverride);
102
+ const advisoryCount = Object.entries(cache.entries).filter(([, value]) => Boolean(value)).length;
103
+ const negativeCount = Object.entries(cache.entries).filter(([, value]) => value === null).length;
104
+ logInfo(`Cache summary: ${advisoryCount} advisory record${advisoryCount === 1 ? "" : "s"} cached, ${negativeCount} negative entr${negativeCount === 1 ? "y" : "ies"}`, options);
105
+ }
106
+ export function logInfo(message, options) {
107
+ if (!options?.json)
108
+ console.log(chalk.cyan(`• ${message}`));
109
+ }
110
+ export function logWarn(message, options) {
111
+ if (!options?.json)
112
+ console.log(chalk.yellow(`! ${message}`));
113
+ }
@@ -0,0 +1,319 @@
1
+ import { chalk, stripAnsi } from "../utils/chalk.js";
2
+ import { severityOrder } from "../constants.js";
3
+ import { formatSeverityLabel, formatRelationshipLabel, getPrimaryParent, getRecommendedAction, summarizeRisk, summarizeNextAction } from "./formatters.js";
4
+ export function printSummary(findings, packageCount, scanInput) {
5
+ if (findings.length === 0) {
6
+ if (scanInput.mode === "manifest-fallback") {
7
+ console.log(chalk.greenBright(`✓ No known OSV matches found for manifest fallback packages (${packageCount} exact direct dependencies checked)`));
8
+ }
9
+ else {
10
+ console.log(chalk.greenBright(`✓ No known OSV vulnerability matches found in parsed lockfile packages (${packageCount} checked)`));
11
+ }
12
+ return;
13
+ }
14
+ const counts = {
15
+ critical: findings.filter(f => f.severity === "critical").length,
16
+ high: findings.filter(f => f.severity === "high").length,
17
+ medium: findings.filter(f => f.severity === "medium").length,
18
+ low: findings.filter(f => f.severity === "low").length,
19
+ unknown: findings.filter(f => f.severity === "unknown").length
20
+ };
21
+ console.log(chalk.redBright(`✗ Found ${findings.length} package(s) with known OSV matches from ${scanInput.source}`));
22
+ console.log(` ${formatSeverityLabel("critical")}: ${counts.critical} ${formatSeverityLabel("high")}: ${counts.high} ${formatSeverityLabel("medium")}: ${counts.medium} ${formatSeverityLabel("low")}: ${counts.low} ${formatSeverityLabel("unknown")}: ${counts.unknown}`);
23
+ }
24
+ export function printActionSummary(findings) {
25
+ if (findings.length === 0)
26
+ return;
27
+ const direct = findings.filter(f => f.relationship === "direct").length;
28
+ const transitive = findings.filter(f => f.relationship === "transitive").length;
29
+ const unknown = findings.filter(f => f.relationship === "unknown").length;
30
+ const uniqueAdvisories = new Set(findings.flatMap(f => f.vulnerabilities.map(v => v.id))).size;
31
+ const fixable = findings.filter(f => Boolean(f.firstFixedVersion)).length;
32
+ console.log("");
33
+ console.log(chalk.bold.cyan("Quick take"));
34
+ console.log(`- ${chalk.green(String(direct))} vulnerable package${direct === 1 ? "" : "s"} look directly fixable in this project.`);
35
+ console.log(`- ${chalk.yellow(String(transitive))} issue${transitive === 1 ? "" : "s"} come through other dependencies.`);
36
+ if (unknown > 0) {
37
+ console.log(`- ${chalk.magenta(String(unknown))} package${unknown === 1 ? "" : "s"} could not be clearly classified as direct or transitive.`);
38
+ }
39
+ console.log(`- ${chalk.blueBright(String(uniqueAdvisories))} unique advisories matched overall.`);
40
+ console.log(`- ${chalk.blue(String(fixable))} package${fixable === 1 ? "" : "s"} include a fixed-version hint from OSV.`);
41
+ }
42
+ export function printPriorityFixes(findings) {
43
+ if (findings.length === 0)
44
+ return;
45
+ const scored = [...findings].sort((a, b) => {
46
+ const sevDelta = severityOrder[b.severity] - severityOrder[a.severity];
47
+ if (sevDelta !== 0)
48
+ return sevDelta;
49
+ const relScore = (f) => f.relationship === "direct" ? 2 : f.relationship === "transitive" ? 1 : 0;
50
+ const relDelta = relScore(b) - relScore(a);
51
+ if (relDelta !== 0)
52
+ return relDelta;
53
+ const fixedDelta = Number(Boolean(b.firstFixedVersion)) - Number(Boolean(a.firstFixedVersion));
54
+ if (fixedDelta !== 0)
55
+ return fixedDelta;
56
+ return a.pkg.name.localeCompare(b.pkg.name);
57
+ });
58
+ const top = scored.slice(0, 5);
59
+ console.log("");
60
+ console.log(chalk.bold.magenta("Top priority fixes"));
61
+ for (const finding of top) {
62
+ console.log(`- ${chalk.whiteBright(finding.pkg.name)}@${chalk.white(finding.pkg.version)} (${formatSeverityLabel(finding.severity)}, ${formatRelationshipLabel(finding.relationship)})`);
63
+ console.log(` Risk: ${summarizeRisk(finding)}`);
64
+ const parent = getPrimaryParent(finding);
65
+ if (parent)
66
+ console.log(` Parent: ${parent}`);
67
+ console.log(` Next: ${summarizeNextAction(finding)}`);
68
+ }
69
+ }
70
+ export function printFixPlan(findings) {
71
+ if (findings.length === 0)
72
+ return;
73
+ const directUrgent = findings.filter(f => f.relationship === "direct" && (f.severity === "critical" || f.severity === "high"));
74
+ const transitiveUrgent = findings.filter(f => f.relationship === "transitive" && (f.severity === "critical" || f.severity === "high"));
75
+ const directMedium = findings.filter(f => f.relationship === "direct" && f.severity === "medium");
76
+ console.log("");
77
+ console.log(chalk.bold.green("Suggested fix plan"));
78
+ if (directUrgent.length > 0) {
79
+ console.log(chalk.green("1) Upgrade these direct critical/high dependencies first:"));
80
+ for (const finding of directUrgent.slice(0, 5)) {
81
+ console.log(` - ${finding.pkg.name}@${finding.pkg.version}: ${getRecommendedAction(finding)}`);
82
+ }
83
+ }
84
+ if (transitiveUrgent.length > 0) {
85
+ console.log(chalk.yellow("2) Review these urgent transitive issues next:"));
86
+ for (const finding of transitiveUrgent.slice(0, 5)) {
87
+ console.log(` - ${finding.pkg.name}@${finding.pkg.version}: ${getRecommendedAction(finding)}`);
88
+ }
89
+ }
90
+ if (directMedium.length > 0) {
91
+ console.log(chalk.blue("3) Clean up these medium direct dependencies after the urgent fixes:"));
92
+ for (const finding of directMedium.slice(0, 5)) {
93
+ console.log(` - ${finding.pkg.name}@${finding.pkg.version}: ${getRecommendedAction(finding)}`);
94
+ }
95
+ }
96
+ const grouped = new Map();
97
+ for (const finding of findings) {
98
+ const existing = grouped.get(finding.pkg.name) ?? [];
99
+ existing.push(finding);
100
+ grouped.set(finding.pkg.name, existing);
101
+ }
102
+ const dupes = [...grouped.entries()]
103
+ .filter(([, items]) => items.length > 1)
104
+ .sort((a, b) => b[1].length - a[1].length || a[0].localeCompare(b[0]))
105
+ .slice(0, 5);
106
+ if (dupes.length > 0) {
107
+ console.log(chalk.magenta("4) Consolidate duplicated vulnerable packages where possible:"));
108
+ for (const [name, items] of dupes) {
109
+ const versions = [...new Set(items.map(item => item.pkg.version))].sort().join(", ");
110
+ console.log(` - ${name}: vulnerable versions present -> ${versions}`);
111
+ }
112
+ }
113
+ }
114
+ export function printCoverage(notes) {
115
+ if (notes.length === 0)
116
+ return;
117
+ console.log("");
118
+ console.log(chalk.bold.blue("Coverage notes"));
119
+ for (const note of notes) {
120
+ console.log(`${chalk.blue("•")} ${note}`);
121
+ }
122
+ }
123
+ export function printSkippedDependencies(skipped) {
124
+ console.log("");
125
+ console.log(chalk.bold.yellow("Skipped manifest dependencies"));
126
+ for (const item of skipped.slice(0, 10)) {
127
+ console.log(`${chalk.yellow("•")} ${item}`);
128
+ }
129
+ if (skipped.length > 10) {
130
+ console.log(`${chalk.yellow("•")} ...and ${skipped.length - 10} more`);
131
+ }
132
+ }
133
+ export function printGroupSummary(findings) {
134
+ const direct = findings.filter(f => f.relationship === "direct");
135
+ const transitive = findings.filter(f => f.relationship === "transitive");
136
+ const unknown = findings.filter(f => f.relationship === "unknown");
137
+ console.log("");
138
+ console.log(chalk.bold.green("Where the issues are"));
139
+ console.log(`- Direct dependencies: ${chalk.green(String(direct.length))}`);
140
+ console.log(`- Transitive dependencies: ${chalk.yellow(String(transitive.length))}`);
141
+ if (unknown.length > 0) {
142
+ console.log(`- Unclear relationship: ${chalk.magenta(String(unknown.length))}`);
143
+ }
144
+ }
145
+ export function printTable(findings, threshold) {
146
+ const headers = ["Package", "Version", "Severity", "Type", "Fixed", "IDs"];
147
+ const rawRows = findings.map(f => [
148
+ f.pkg.name,
149
+ f.pkg.version,
150
+ f.severity,
151
+ f.relationship,
152
+ f.firstFixedVersion ?? "-",
153
+ f.vulnerabilities.map(v => v.id).join(", ")
154
+ ]);
155
+ const widths = headers.map((header, index) => Math.min(40, Math.max(header.length, ...rawRows.map(r => String(r[index]).length))));
156
+ console.log("");
157
+ if (threshold) {
158
+ console.log(chalk.bold(`Showing ${threshold}+ findings in the main table. Use --all to show everything.`));
159
+ }
160
+ const line = (left, mid, right) => left + widths.map(w => "─".repeat(w + 2)).join(mid) + right;
161
+ console.log(line("┌", "┬", "┐"));
162
+ console.log(renderRow(headers, widths));
163
+ console.log(line("├", "┼", "┤"));
164
+ for (const row of rawRows) {
165
+ const decorated = [
166
+ row[0],
167
+ row[1],
168
+ formatSeverityLabel(String(row[2])),
169
+ formatRelationshipLabel(String(row[3])),
170
+ row[4],
171
+ row[5]
172
+ ];
173
+ console.log(renderRow(decorated, widths));
174
+ }
175
+ console.log(line("└", "┴", "┘"));
176
+ console.log(chalk.gray("Tip: use --all to include low/unknown findings, or --min-severity high to focus only on urgent issues."));
177
+ }
178
+ export function printPathHints(findings) {
179
+ const withPaths = findings.filter(f => (f.dependencyPaths ?? []).length > 0);
180
+ if (withPaths.length === 0)
181
+ return;
182
+ console.log("");
183
+ console.log(chalk.bold.cyan("Dependency paths to inspect"));
184
+ for (const finding of withPaths.slice(0, 10)) {
185
+ const examples = finding.dependencyPaths.slice(0, 3).map(p => p.join(" -> "));
186
+ console.log(`- ${finding.pkg.name}@${finding.pkg.version}`);
187
+ for (const example of examples) {
188
+ console.log(` ${chalk.gray(example)}`);
189
+ }
190
+ }
191
+ }
192
+ export function printFinalStatus(findings) {
193
+ console.log("");
194
+ console.log(chalk.gray("────────────────────────────────"));
195
+ if (findings.length === 0) {
196
+ console.log(chalk.greenBright("✔ Scan complete. No known vulnerabilities found."));
197
+ return;
198
+ }
199
+ const criticalCount = findings.filter(f => f.severity === "critical").length;
200
+ const highCount = findings.filter(f => f.severity === "high").length;
201
+ if (criticalCount > 0 || highCount > 0) {
202
+ console.log(chalk.redBright(`✖ Scan complete. ${findings.length} issue${findings.length === 1 ? "" : "s"} found (${criticalCount} critical, ${highCount} high). Start with the priority fixes above.`));
203
+ return;
204
+ }
205
+ console.log(chalk.yellow(`▲ Scan complete. ${findings.length} issue${findings.length === 1 ? "" : "s"} found. Review the suggested fix plan above.`));
206
+ }
207
+ function renderRow(cells, widths) {
208
+ const formatted = cells.map((cell, i) => {
209
+ const truncated = truncate(cell, widths[i]);
210
+ const visible = stripAnsi(truncated);
211
+ return ` ${truncated}${" ".repeat(Math.max(0, widths[i] - visible.length))} `;
212
+ });
213
+ return "│" + formatted.join("│") + "│";
214
+ }
215
+ function truncate(value, width) {
216
+ const plain = stripAnsi(value);
217
+ if (plain.length <= width)
218
+ return value;
219
+ return plain.slice(0, Math.max(0, width - 1)) + "…";
220
+ }
221
+ export function printCompactOutput(findings) {
222
+ console.log("");
223
+ if (findings.length === 0) {
224
+ console.log(chalk.greenBright("✔ Scan complete. No known vulnerabilities found."));
225
+ console.log("");
226
+ return;
227
+ }
228
+ // Vulnerabilities found section
229
+ console.log("────────────────────────────────");
230
+ console.log(chalk.bold("📦 Vulnerabilities found"));
231
+ console.log("────────────────────────────────\n");
232
+ // Get top 3 critical/high issues
233
+ const urgentFindings = findings
234
+ .filter(f => f.severity === "critical" || f.severity === "high")
235
+ .slice(0, 3);
236
+ for (const finding of urgentFindings) {
237
+ const sevLabel = finding.severity.toUpperCase().padEnd(8);
238
+ const typeLabel = finding.relationship === "direct" ? "Direct dependency" :
239
+ finding.relationship === "transitive" ? "Transitive dependency" : "Unknown dependency";
240
+ console.log(`${formatSeverityLabel(sevLabel)} ${chalk.whiteBright(finding.pkg.name)}@${finding.pkg.version}`);
241
+ console.log(` ${typeLabel}`);
242
+ if (finding.firstFixedVersion) {
243
+ const action = finding.relationship === "direct"
244
+ ? `upgrade to ${finding.firstFixedVersion}`
245
+ : `upgrade parent chain to resolve ${finding.firstFixedVersion}+`;
246
+ console.log(` ${chalk.gray(`Fix: ${action}`)}`);
247
+ }
248
+ else {
249
+ const action = finding.relationship === "direct"
250
+ ? "review and upgrade directly"
251
+ : "upgrade parent chain to resolve";
252
+ console.log(` ${chalk.gray(`Fix: ${action}`)}`);
253
+ }
254
+ console.log("");
255
+ }
256
+ // Top Priority Fix section
257
+ if (urgentFindings.length > 0) {
258
+ const topFinding = urgentFindings[0];
259
+ console.log("────────────────────────────────");
260
+ console.log(chalk.bold("🚀 Top Priority Fix"));
261
+ console.log("────────────────────────────────\n");
262
+ if (topFinding.relationship === "direct" && topFinding.firstFixedVersion) {
263
+ console.log(`Upgrade ${chalk.whiteBright(topFinding.pkg.name)} → ${topFinding.firstFixedVersion}`);
264
+ }
265
+ else if (topFinding.relationship === "direct") {
266
+ console.log(`Upgrade ${chalk.whiteBright(topFinding.pkg.name)} to latest safe version`);
267
+ }
268
+ else {
269
+ const parent = getPrimaryParent(topFinding);
270
+ if (parent) {
271
+ console.log(`Upgrade ${chalk.whiteBright(parent)} to resolve ${topFinding.pkg.name}`);
272
+ }
273
+ else {
274
+ console.log(`Upgrade parent chain to resolve ${chalk.whiteBright(topFinding.pkg.name)}`);
275
+ }
276
+ }
277
+ console.log("");
278
+ }
279
+ // Summary
280
+ console.log("────────────────────────────────");
281
+ console.log("Summary");
282
+ console.log("────────────────────────────────\n");
283
+ const counts = {
284
+ critical: findings.filter(f => f.severity === "critical").length,
285
+ high: findings.filter(f => f.severity === "high").length,
286
+ medium: findings.filter(f => f.severity === "medium").length,
287
+ low: findings.filter(f => f.severity === "low").length,
288
+ unknown: findings.filter(f => f.severity === "unknown").length
289
+ };
290
+ const direct = findings.filter(f => f.relationship === "direct").length;
291
+ const transitive = findings.filter(f => f.relationship === "transitive").length;
292
+ const parts = [];
293
+ if (counts.critical > 0)
294
+ parts.push(chalk.redBright(`${counts.critical} critical`));
295
+ if (counts.high > 0)
296
+ parts.push(chalk.magenta(`${counts.high} high`));
297
+ if (counts.medium > 0)
298
+ parts.push(chalk.yellow(`${counts.medium} medium`));
299
+ if (counts.low > 0)
300
+ parts.push(chalk.green(`${counts.low} low`));
301
+ if (counts.unknown > 0)
302
+ parts.push(chalk.gray(`${counts.unknown} unknown`));
303
+ console.log(`${chalk.whiteBright(String(findings.length))} vulnerable packages`);
304
+ console.log(parts.join(chalk.gray(" · ")));
305
+ console.log(`${chalk.cyan(String(direct))} ${chalk.white("direct")}` +
306
+ `${chalk.gray(" · ")}` +
307
+ `${chalk.cyan(String(transitive))} ${chalk.white("transitive")}`);
308
+ console.log("");
309
+ // Footer
310
+ const urgentCount = counts.critical + counts.high;
311
+ if (urgentCount > 0) {
312
+ console.log(chalk.redBright(`✖ Scan complete. ${urgentCount} urgent issue${urgentCount === 1 ? "" : "s"} found.`));
313
+ }
314
+ else {
315
+ console.log(chalk.yellow(`▲ Scan complete. ${findings.length} issue${findings.length === 1 ? "" : "s"} found.`));
316
+ }
317
+ console.log(chalk.gray(`Run with ${chalk.whiteBright("--verbose")} for fix plan, paths, and full table.`));
318
+ console.log("");
319
+ }
@@ -0,0 +1,42 @@
1
+ import process from "node:process";
2
+ import { chalk } from "../utils/chalk.js";
3
+ export function createSpinner(initialMessage, options) {
4
+ const enabled = !options?.json && Boolean(process.stdout.isTTY);
5
+ if (!enabled) {
6
+ return {
7
+ update: () => { },
8
+ succeed: () => { },
9
+ fail: () => { },
10
+ stop: () => { }
11
+ };
12
+ }
13
+ const frames = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"];
14
+ let frameIndex = 0;
15
+ let currentMessage = initialMessage;
16
+ const render = () => {
17
+ process.stdout.write(`\r\x1b[2K${chalk.cyan(frames[frameIndex])} ${currentMessage}`);
18
+ frameIndex = (frameIndex + 1) % frames.length;
19
+ };
20
+ render();
21
+ const timer = setInterval(render, 80);
22
+ const clearLine = () => {
23
+ clearInterval(timer);
24
+ process.stdout.write("\r\x1b[2K");
25
+ };
26
+ return {
27
+ update(message) {
28
+ currentMessage = message;
29
+ },
30
+ succeed(message) {
31
+ clearLine();
32
+ console.log(chalk.green(`✓ ${message}`));
33
+ },
34
+ fail(message) {
35
+ clearLine();
36
+ console.log(chalk.red(`✗ ${message}`));
37
+ },
38
+ stop() {
39
+ clearLine();
40
+ }
41
+ };
42
+ }