cve-lite-cli 1.24.0 → 1.26.0-beta.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 (77) hide show
  1. package/README.md +83 -2
  2. package/assets/OWASP_Logo_Black_TM.png +0 -0
  3. package/assets/logo-with-title-removebg-preview.png +0 -0
  4. package/dist/advisory/local-db.js +7 -1
  5. package/dist/advisory/osv-advisory-source.js +2 -1
  6. package/dist/audit-log/events.js +3 -0
  7. package/dist/audit-log/handle.js +20 -0
  8. package/dist/audit-log/index.js +16 -0
  9. package/dist/audit-log/ndjson-writer.js +28 -0
  10. package/dist/cli/args.js +75 -0
  11. package/dist/cli/fix-overrides-hook.js +64 -0
  12. package/dist/cli/help.js +24 -1
  13. package/dist/cli/overrides.js +67 -0
  14. package/dist/cli/validate.js +9 -1
  15. package/dist/index.js +310 -21
  16. package/dist/osv/cache.js +28 -4
  17. package/dist/output/formatters.js +22 -18
  18. package/dist/output/html-reporter.js +37 -8
  19. package/dist/output/logos.js +18 -0
  20. package/dist/output/multi-folder-html-reporter.js +3 -4
  21. package/dist/output/override-findings-html.js +63 -0
  22. package/dist/output/override-findings-json.js +3 -0
  23. package/dist/output/override-findings-sarif.js +52 -0
  24. package/dist/output/override-findings-terminal.js +106 -0
  25. package/dist/output/printers.js +66 -23
  26. package/dist/output/sarif.js +77 -8
  27. package/dist/output/write-outputs.js +7 -3
  28. package/dist/overrides/api.js +79 -0
  29. package/dist/overrides/composite.js +23 -0
  30. package/dist/overrides/context-builder.js +150 -0
  31. package/dist/overrides/context.js +3 -0
  32. package/dist/overrides/detectors/index.js +23 -0
  33. package/dist/overrides/detectors/oa001-orphaned-target.js +36 -0
  34. package/dist/overrides/detectors/oa002-floating-tag.js +40 -0
  35. package/dist/overrides/detectors/oa003-wrong-section.js +48 -0
  36. package/dist/overrides/detectors/oa004-surpassed-pin.js +49 -0
  37. package/dist/overrides/detectors/oa005-nested-ineffective.js +128 -0
  38. package/dist/overrides/detectors/oa006-coupled-platform-binary.js +170 -0
  39. package/dist/overrides/detectors/oa007-frozen-latest.js +69 -0
  40. package/dist/overrides/detectors/oa008-materialized.js +75 -0
  41. package/dist/overrides/detectors/platform-binary.js +37 -0
  42. package/dist/overrides/fixer.js +199 -0
  43. package/dist/overrides/index.js +5 -0
  44. package/dist/overrides/parsing/installed-tree.js +164 -0
  45. package/dist/overrides/parsing/json-pointer.js +8 -0
  46. package/dist/overrides/parsing/node-modules.js +19 -0
  47. package/dist/overrides/parsing/package-json.js +139 -0
  48. package/dist/overrides/parsing/registry.js +66 -0
  49. package/dist/overrides/types.js +2 -0
  50. package/dist/parsers/pnpm-lock.js +46 -3
  51. package/dist/parsers/yarn-lock.js +2 -2
  52. package/dist/remediation/fix-commands.js +59 -5
  53. package/dist/remediation/npm-registry.js +55 -43
  54. package/dist/remediation/npm-transitive-resolution.js +2 -2
  55. package/dist/remediation/transitive-chain-resolver.js +100 -0
  56. package/dist/scan/multi-folder-scan.js +37 -1
  57. package/dist/scanner.js +122 -46
  58. package/dist/types.js +13 -1
  59. package/dist/utils/baseline.js +16 -0
  60. package/dist/utils/create-pr.js +19 -4
  61. package/dist/utils/fix-runner.js +6 -0
  62. package/dist/utils/package-json.js +21 -0
  63. package/dist/utils/severity.js +16 -0
  64. package/dist/utils/string.js +34 -0
  65. package/dist/utils/validate-url.js +223 -0
  66. package/dist/utils/version.js +135 -2
  67. package/package.json +8 -2
  68. package/dist/learn/keypress.js +0 -50
  69. package/dist/learn/runner.js +0 -96
  70. package/dist/learn/scenario.js +0 -47
  71. package/dist/learn/session.js +0 -36
  72. package/dist/learn/types.js +0 -1
  73. package/dist/llm/client.js +0 -40
  74. package/dist/llm/config.js +0 -48
  75. package/dist/llm/explainer.js +0 -31
  76. package/dist/output/logo-base64.js +0 -1
  77. package/dist/output/owasp-logo-base64.js +0 -1
package/dist/scanner.js CHANGED
@@ -12,6 +12,7 @@ import { resolveRecommendedParentUpgrade } from "./remediation/parent-upgrade.js
12
12
  import { configureNpmRegistryDebug, fetchPackument, resolveLowestKnownNonVulnerableVersion, resolvePublishedFixVersion, } from "./remediation/npm-registry.js";
13
13
  import { countBySeverity } from "./utils/severity.js";
14
14
  import { resolveNpmTransitiveRemediation, resolveTransitiveRemediationViaRegistry } from "./remediation/npm-transitive-resolution.js";
15
+ import { resolveChainFix } from "./remediation/transitive-chain-resolver.js";
15
16
  import { loadNpmLockGraph } from "./parsers/npm-lock-graph.js";
16
17
  import { buildPnpmWorkspaceMap } from "./parsers/pnpm-lock.js";
17
18
  import { buildNpmWorkspaceMap } from "./parsers/package-lock.js";
@@ -45,6 +46,17 @@ export function createAdvisorySource(options) {
45
46
  function getPackageCacheKey(pkg) {
46
47
  return `${pkg.ecosystem}:${pkg.name}@${pkg.version}`;
47
48
  }
49
+ function inferPackageManagerForChain(source) {
50
+ if (source === "package-lock" || source === "npm-shrinkwrap")
51
+ return "npm";
52
+ if (source === "pnpm-lock")
53
+ return "pnpm";
54
+ if (source === "yarn-lock")
55
+ return "yarn";
56
+ if (source === "bun-lock")
57
+ return "bun";
58
+ return null;
59
+ }
48
60
  export async function scanPackages(packages, batchSize, options, context, debugLog) {
49
61
  const log = debugLog ?? (() => { });
50
62
  const sourceContext = createAdvisorySource({
@@ -96,6 +108,7 @@ export async function scanPackages(packages, batchSize, options, context, debugL
96
108
  const batchId = `b-${String(batchCounter).padStart(2, "0")}`;
97
109
  return advisorySource.queryBatch(c, { batchId });
98
110
  });
111
+ const cachedAt = new Date().toISOString();
99
112
  for (let i = 0; i < chunks.length; i++) {
100
113
  const chunkItems = chunks[i];
101
114
  const rows = allAdvisoryResults[i] ?? [];
@@ -103,7 +116,7 @@ export async function scanPackages(packages, batchSize, options, context, debugL
103
116
  const pkg = chunkItems[j];
104
117
  const row = rows[j];
105
118
  const vulnIds = (row?.vulnerabilities ?? []).map(v => v.id).filter(Boolean);
106
- cache.queryEntries[getPackageCacheKey(pkg)] = { vulnIds, cachedAt: new Date().toISOString() };
119
+ cache.queryEntries[getPackageCacheKey(pkg)] = { vulnIds, cachedAt };
107
120
  if (vulnIds.length > 0) {
108
121
  results.push({ pkg, vulnIds });
109
122
  }
@@ -222,6 +235,7 @@ export async function scanPackages(packages, batchSize, options, context, debugL
222
235
  firstFixedVersion,
223
236
  validatedFirstFixedVersion: null,
224
237
  fixVersionValidationNote: null,
238
+ fixVersionPublishedAt: null,
225
239
  validatedTargetScannedVersions: null,
226
240
  validatedTargetKnownVulnerableVersions: null,
227
241
  recommendedParentUpgrade: undefined,
@@ -297,7 +311,15 @@ export async function scanPackages(packages, batchSize, options, context, debugL
297
311
  const npmRemediationCache = new Map();
298
312
  const parentUpgradeCache = new Map();
299
313
  const directValidationCount = offline ? 0 : findings.length;
300
- const transitiveRemediationCount = findings.filter(finding => finding.relationship === "transitive").length;
314
+ let directCount = 0;
315
+ let transitiveCount = 0;
316
+ for (const finding of findings) {
317
+ if (finding.relationship === "direct")
318
+ directCount++;
319
+ else if (finding.relationship === "transitive")
320
+ transitiveCount++;
321
+ }
322
+ const transitiveRemediationCount = transitiveCount;
301
323
  const analysisStepCount = directValidationCount + transitiveRemediationCount;
302
324
  if (analysisStepCount > 0) {
303
325
  const analysisSpinner = createSpinner("Analyzing vulnerability findings...", options);
@@ -308,9 +330,12 @@ export async function scanPackages(packages, batchSize, options, context, debugL
308
330
  };
309
331
  try {
310
332
  if (!offline) {
311
- await validateDirectFixTargets(findings, (finding) => {
333
+ const npmVersionCacheUpdated = await validateDirectFixTargets(findings, (finding) => {
312
334
  updateAnalysisProgress("validating fix target for", `${finding.pkg.name}@${finding.pkg.version}`);
313
- }, log);
335
+ }, { cache, noCache: options.noCache, debugLog: log });
336
+ if (npmVersionCacheUpdated) {
337
+ saveCache(cache, cacheDirOverride, options.debug ? log : undefined);
338
+ }
314
339
  }
315
340
  // Pre-warm packument cache for all packages needed in the remediation loop.
316
341
  // This converts N sequential registry round-trips into one concurrent burst,
@@ -413,6 +438,21 @@ export async function scanPackages(packages, batchSize, options, context, debugL
413
438
  }
414
439
  }
415
440
  analysisSpinner.succeed("Analyzed vulnerability findings");
441
+ // Chain fix resolution: pre-compute validated chain for transitive findings
442
+ const chainPm = inferPackageManagerForChain(context?.scanSource);
443
+ if (chainPm) {
444
+ const installedVersions = new Map(packages.map(p => [p.name, p.version]));
445
+ await Promise.all(findings
446
+ .filter(f => f.relationship === "transitive" && f.dependencyPaths?.length)
447
+ .map(async (finding) => {
448
+ try {
449
+ finding.chainResolution = await resolveChainFix(finding, installedVersions, chainPm, { offline });
450
+ }
451
+ catch {
452
+ finding.chainResolution = null;
453
+ }
454
+ }));
455
+ }
416
456
  }
417
457
  catch (error) {
418
458
  analysisSpinner.fail("Failed while analyzing vulnerability findings");
@@ -420,13 +460,20 @@ export async function scanPackages(packages, batchSize, options, context, debugL
420
460
  }
421
461
  }
422
462
  else if (!offline) {
423
- await validateDirectFixTargets(findings, undefined, log);
463
+ const npmVersionCacheUpdated = await validateDirectFixTargets(findings, undefined, {
464
+ cache,
465
+ noCache: options.noCache,
466
+ debugLog: log,
467
+ });
468
+ if (npmVersionCacheUpdated) {
469
+ saveCache(cache, cacheDirOverride, options.debug ? log : undefined);
470
+ }
424
471
  }
425
472
  const severityCounts = countBySeverity(findings);
426
473
  log("Findings classified", {
427
474
  total: findings.length,
428
- direct: findings.filter(finding => finding.relationship === "direct").length,
429
- transitive: findings.filter(finding => finding.relationship === "transitive").length,
475
+ direct: directCount,
476
+ transitive: transitiveCount,
430
477
  critical: severityCounts.critical,
431
478
  high: severityCounts.high,
432
479
  medium: severityCounts.medium,
@@ -473,56 +520,85 @@ function createNpmTransitiveGraphFromLockfile(filePath, log, packageCount) {
473
520
  return null;
474
521
  }
475
522
  }
476
- async function validateDirectFixTargets(findings, onFinding, debugLog) {
523
+ async function validateDirectFixTargets(findings, onFinding, options) {
477
524
  const directCandidates = findings.filter(finding => finding.vulnerabilities.length > 0);
478
- for (const finding of directCandidates) {
525
+ const results = await runWithConcurrency(directCandidates, 8, async (finding) => {
479
526
  onFinding?.(finding);
480
- const logFixValidation = () => {
481
- debugLog?.("Fix validation", {
482
- package: finding.pkg.name,
483
- installed: finding.pkg.version,
484
- resolvedFixVersion: finding.validatedFirstFixedVersion,
485
- verified: Boolean(finding.validatedFirstFixedVersion),
486
- });
527
+ return validateOneDirectFixTarget(finding, options);
528
+ });
529
+ return results.some(Boolean);
530
+ }
531
+ async function validateOneDirectFixTarget(finding, options) {
532
+ let npmVersionCacheUpdated = false;
533
+ const debugLog = options?.debugLog;
534
+ const logFixValidation = () => {
535
+ debugLog?.("Fix validation", {
536
+ package: finding.pkg.name,
537
+ installed: finding.pkg.version,
538
+ resolvedFixVersion: finding.validatedFirstFixedVersion,
539
+ verified: Boolean(finding.validatedFirstFixedVersion),
540
+ });
541
+ };
542
+ const lowestKnownResolution = await resolveLowestKnownNonVulnerableVersion(finding.pkg.name, finding.pkg.version, finding.vulnerabilities);
543
+ const fixedVersionHint = finding.firstFixedVersion;
544
+ const setPublishedDate = (resolution) => {
545
+ const date = resolution.publishedAt;
546
+ finding.fixVersionPublishedAt = date;
547
+ if (!date || !options?.cache)
548
+ return;
549
+ const cacheKey = `${finding.pkg.name}@${finding.validatedFirstFixedVersion}`;
550
+ const existing = options.cache.npmVersionEntries?.[cacheKey];
551
+ if (!options.noCache && existing?.publishedAt === date)
552
+ return;
553
+ options.cache.npmVersionEntries ??= {};
554
+ options.cache.npmVersionEntries[cacheKey] = {
555
+ publishedAt: date,
556
+ cachedAt: new Date().toISOString(),
487
557
  };
488
- const lowestKnownResolution = await resolveLowestKnownNonVulnerableVersion(finding.pkg.name, finding.pkg.version, finding.vulnerabilities);
489
- const fixedVersionHint = finding.firstFixedVersion;
490
- if (lowestKnownResolution.resolvedVersion) {
491
- finding.validatedFirstFixedVersion = lowestKnownResolution.resolvedVersion;
492
- finding.validatedTargetScannedVersions = lowestKnownResolution.candidatesChecked;
493
- finding.validatedTargetKnownVulnerableVersions = lowestKnownResolution.candidatesKnownVulnerable;
494
- if (!fixedVersionHint || fixedVersionHint === lowestKnownResolution.resolvedVersion) {
495
- finding.fixVersionValidationNote = null;
496
- logFixValidation();
497
- continue;
498
- }
499
- const hintResolution = await resolvePublishedFixVersion(finding.pkg.name, fixedVersionHint);
500
- if (hintResolution.resolvedVersion === lowestKnownResolution.resolvedVersion &&
501
- hintResolution.note) {
502
- finding.fixVersionValidationNote = hintResolution.note;
503
- logFixValidation();
504
- continue;
505
- }
506
- finding.fixVersionValidationNote =
507
- `Advisory fixed-version hint ${fixedVersionHint} is still known vulnerable for ${finding.pkg.name}; scanned ${lowestKnownResolution.candidatesChecked} package ${pluralize(lowestKnownResolution.candidatesChecked, "version")} above current version (${lowestKnownResolution.candidatesKnownVulnerable} still known vulnerable); using lowest known non-vulnerable version ${lowestKnownResolution.resolvedVersion}.`;
558
+ npmVersionCacheUpdated = true;
559
+ };
560
+ if (lowestKnownResolution.resolvedVersion) {
561
+ finding.validatedFirstFixedVersion = lowestKnownResolution.resolvedVersion;
562
+ finding.validatedTargetScannedVersions = lowestKnownResolution.candidatesChecked;
563
+ finding.validatedTargetKnownVulnerableVersions = lowestKnownResolution.candidatesKnownVulnerable;
564
+ if (!fixedVersionHint || fixedVersionHint === lowestKnownResolution.resolvedVersion) {
565
+ finding.fixVersionValidationNote = null;
566
+ setPublishedDate(lowestKnownResolution);
508
567
  logFixValidation();
509
- continue;
568
+ return npmVersionCacheUpdated;
510
569
  }
511
- if (!fixedVersionHint) {
512
- finding.validatedFirstFixedVersion = null;
513
- finding.fixVersionValidationNote = lowestKnownResolution.note;
514
- finding.validatedTargetScannedVersions = null;
515
- finding.validatedTargetKnownVulnerableVersions = null;
570
+ const hintResolution = await resolvePublishedFixVersion(finding.pkg.name, fixedVersionHint);
571
+ if (hintResolution.resolvedVersion === lowestKnownResolution.resolvedVersion &&
572
+ hintResolution.note) {
573
+ finding.fixVersionValidationNote = hintResolution.note;
574
+ // date is for the validated version, not the hint
575
+ setPublishedDate(lowestKnownResolution);
516
576
  logFixValidation();
517
- continue;
577
+ return npmVersionCacheUpdated;
518
578
  }
519
- const resolution = await resolvePublishedFixVersion(finding.pkg.name, fixedVersionHint);
520
- finding.validatedFirstFixedVersion = resolution.resolvedVersion;
521
- finding.fixVersionValidationNote = resolution.note ?? lowestKnownResolution.note;
579
+ finding.fixVersionValidationNote =
580
+ `Advisory fixed-version hint ${fixedVersionHint} is still known vulnerable for ${finding.pkg.name}; scanned ${lowestKnownResolution.candidatesChecked} package ${pluralize(lowestKnownResolution.candidatesChecked, "version")} above current version (${lowestKnownResolution.candidatesKnownVulnerable} still known vulnerable); using lowest known non-vulnerable version ${lowestKnownResolution.resolvedVersion}.`;
581
+ setPublishedDate(lowestKnownResolution);
582
+ logFixValidation();
583
+ return npmVersionCacheUpdated;
584
+ }
585
+ if (!fixedVersionHint) {
586
+ finding.validatedFirstFixedVersion = null;
587
+ finding.fixVersionValidationNote = lowestKnownResolution.note;
522
588
  finding.validatedTargetScannedVersions = null;
523
589
  finding.validatedTargetKnownVulnerableVersions = null;
590
+ finding.fixVersionPublishedAt = null;
524
591
  logFixValidation();
592
+ return npmVersionCacheUpdated;
525
593
  }
594
+ const resolution = await resolvePublishedFixVersion(finding.pkg.name, fixedVersionHint);
595
+ finding.validatedFirstFixedVersion = resolution.resolvedVersion;
596
+ finding.fixVersionValidationNote = resolution.note ?? lowestKnownResolution.note;
597
+ finding.validatedTargetScannedVersions = null;
598
+ finding.validatedTargetKnownVulnerableVersions = null;
599
+ setPublishedDate(resolution);
600
+ logFixValidation();
601
+ return npmVersionCacheUpdated;
526
602
  }
527
603
  function isAdvisoryDbStale(metadata) {
528
604
  if (!metadata.lastSyncAt) {
package/dist/types.js CHANGED
@@ -1 +1,13 @@
1
- export {};
1
+ /**
2
+ * Exit codes used by the CLI.
3
+ *
4
+ * 0 - no findings above --fail-on threshold
5
+ * 1 - findings present (CVE or override) above threshold
6
+ * 2 - --fix applied but verify() detected the fix did not take
7
+ * (operationally distinct from 1: "fix ran but did not work")
8
+ * 3 - tool error (unhandled exception, unreadable lockfile, etc.)
9
+ */
10
+ export const EXIT_OK = 0;
11
+ export const EXIT_FINDINGS = 1;
12
+ export const EXIT_VERIFY_FAILED = 2;
13
+ export const EXIT_ERROR = 3;
@@ -32,6 +32,22 @@ export function writeBaseline(projectRoot, findings) {
32
32
  };
33
33
  fs.writeFileSync(baselinePath(projectRoot), JSON.stringify(baseline, null, 2) + "\n", "utf8");
34
34
  }
35
+ /**
36
+ * Decide what `--ratchet` should do for this scan.
37
+ *
38
+ * - No baseline yet -> "save": record the current findings as the baseline.
39
+ * - Baseline exists -> "gate": never overwrite; report findings not already in
40
+ * the baseline so the caller can fail on them. This is the "if baseline exists,
41
+ * only fail on new findings" half of --ratchet. Re-saving here would let a newly
42
+ * introduced vulnerability be silently absorbed into a fresh baseline, so a
43
+ * ratcheted CI job could never fail on a regression.
44
+ */
45
+ export function ratchetOutcome(baseline, findings) {
46
+ if (!baseline)
47
+ return { action: "save" };
48
+ const { newFindings, suppressedCount } = filterNewFindings(findings, baseline);
49
+ return { action: "gate", newFindings, suppressedCount };
50
+ }
35
51
  export function filterNewFindings(findings, baseline) {
36
52
  const baselineMap = new Map();
37
53
  for (const entry of baseline.findings) {
@@ -22,11 +22,17 @@ export function defaultFixBranchName(date = new Date()) {
22
22
  const day = String(date.getUTCDate()).padStart(2, "0");
23
23
  return `cve-lite/fix-${year}-${month}-${day}`;
24
24
  }
25
- export function buildPullRequestTitle(appliedCount, packageNames) {
25
+ export function buildPullRequestTitle(appliedCount, packageNames, overrideFixCount = 0) {
26
+ if (appliedCount === 0 && overrideFixCount > 0) {
27
+ return `[CVE-Lite-CLI] chore: ${overrideFixCount} override hygiene ${pluralize(overrideFixCount, "fix", "fixes")}`;
28
+ }
26
29
  const pkgList = packageNames.length <= 3
27
30
  ? packageNames.join(", ")
28
31
  : `${packageNames.slice(0, 2).join(", ")} +${packageNames.length - 2} more`;
29
- return `[CVE-Lite-CLI] fix: upgrade ${pkgList} (${appliedCount} ${pluralize(appliedCount, "vulnerability", "vulnerabilities")} resolved)`;
32
+ const base = `[CVE-Lite-CLI] fix: upgrade ${pkgList} (${appliedCount} ${pluralize(appliedCount, "vulnerability", "vulnerabilities")} resolved)`;
33
+ return overrideFixCount > 0
34
+ ? `${base} + ${overrideFixCount} override hygiene ${pluralize(overrideFixCount, "fix", "fixes")}`
35
+ : base;
30
36
  }
31
37
  export function collectAdvisoryIdsForPackage(findings, packageName) {
32
38
  const ids = new Set();
@@ -45,6 +51,7 @@ export function collectAdvisoryIdsForPackage(findings, packageName) {
45
51
  return [...ids].sort();
46
52
  }
47
53
  export function buildPullRequestBody(params) {
54
+ const overrideFixCount = params.overrideFixCount ?? 0;
48
55
  const lines = [
49
56
  "## Summary",
50
57
  "",
@@ -53,12 +60,18 @@ export function buildPullRequestBody(params) {
53
60
  "## Fixed packages",
54
61
  "",
55
62
  ];
63
+ if (params.fixResult.applied.length === 0) {
64
+ lines.push("- _No direct CVE fixes in this PR._");
65
+ }
56
66
  for (const item of params.fixResult.applied) {
57
67
  const advisoryIds = collectAdvisoryIdsForPackage(params.findingsBeforeFix, item.package);
58
68
  const advisoryText = advisoryIds.length > 0 ? advisoryIds.join(", ") : "n/a";
59
69
  lines.push(`- **${item.package}**: \`${item.from}\` → \`${item.to}\``);
60
70
  lines.push(` - Advisories: ${advisoryText}`);
61
71
  }
72
+ if (overrideFixCount > 0) {
73
+ lines.push("", "## Override hygiene", "", `- Applied **${overrideFixCount}** override hygiene ${pluralize(overrideFixCount, "fix", "fixes")} to \`package.json\` (e.g. removing orphaned or ineffective overrides). Each change is constrained to existing overrides; no new override key is ever introduced.`);
74
+ }
62
75
  lines.push("", "## Scan results", "", `- Findings before fix: **${params.findingsBeforeFix.length}**`, `- Findings after fix: **${params.findingsAfterFix.length}**`, "", "## Notes", "", "- Only validated **direct** dependency upgrades are included in this PR.", "- Transitive vulnerabilities may still require parent package upgrades or upstream releases.");
63
76
  return lines.join("\n");
64
77
  }
@@ -151,7 +164,8 @@ function extractPullRequestUrl(output) {
151
164
  }
152
165
  export async function createPullRequestForFixes(params) {
153
166
  const baseBranchName = defaultFixBranchName();
154
- if (params.fixResult.appliedFixCount === 0) {
167
+ const overrideFixCount = params.overrideFixCount ?? 0;
168
+ if (params.fixResult.appliedFixCount === 0 && overrideFixCount === 0) {
155
169
  return {
156
170
  branchName: baseBranchName,
157
171
  prUrl: null,
@@ -170,11 +184,12 @@ export async function createPullRequestForFixes(params) {
170
184
  };
171
185
  }
172
186
  const packageNames = params.fixResult.applied.map(a => a.package);
173
- const title = buildPullRequestTitle(params.fixResult.appliedFixCount, packageNames);
187
+ const title = buildPullRequestTitle(params.fixResult.appliedFixCount, packageNames, overrideFixCount);
174
188
  const body = buildPullRequestBody({
175
189
  fixResult: params.fixResult,
176
190
  findingsBeforeFix: params.findingsBeforeFix,
177
191
  findingsAfterFix: params.findingsAfterFix,
192
+ overrideFixCount,
178
193
  });
179
194
  await stageDependencyFilesOnly(params.projectPath);
180
195
  if (!(await hasStagedDependencyChanges(params.projectPath))) {
@@ -1,4 +1,6 @@
1
1
  import { spawn } from "node:child_process";
2
+ import fs from "node:fs";
3
+ import path from "node:path";
2
4
  import { createSpinner } from "../output/spinner.js";
3
5
  import { chalk } from "./chalk.js";
4
6
  import { pluralize } from "./string.js";
@@ -43,6 +45,10 @@ export function commandLabelForPackageManager(packageManager) {
43
45
  return "bun add";
44
46
  return "yarn add";
45
47
  }
48
+ export function writeFixResultJson(json, projectPath) {
49
+ const outPath = path.join(projectPath, "cve-lite-fix-result.json");
50
+ fs.writeFileSync(outPath, JSON.stringify(json, null, 2), "utf8");
51
+ }
46
52
  export async function applyFixesIfRequested(params) {
47
53
  console.log("");
48
54
  console.log(chalk.bold.cyan("Applying fixes (--fix)"));
@@ -122,3 +122,24 @@ function expandWorkspacePattern(projectPath, segments, currentRelativePath) {
122
122
  export function isRecord(value) {
123
123
  return !!value && typeof value === "object" && !Array.isArray(value);
124
124
  }
125
+ export function hasOverrideEntries(dir) {
126
+ const pkgPath = path.join(dir, "package.json");
127
+ if (!fs.existsSync(pkgPath))
128
+ return false;
129
+ try {
130
+ const raw = JSON.parse(fs.readFileSync(pkgPath, "utf8"));
131
+ if (!raw || typeof raw !== "object")
132
+ return false;
133
+ if (isRecord(raw.overrides) && Object.keys(raw.overrides).length > 0)
134
+ return true;
135
+ const pnpm = raw.pnpm;
136
+ if (isRecord(pnpm) && isRecord(pnpm.overrides) && Object.keys(pnpm.overrides).length > 0)
137
+ return true;
138
+ if (isRecord(raw.resolutions) && Object.keys(raw.resolutions).length > 0)
139
+ return true;
140
+ return false;
141
+ }
142
+ catch {
143
+ return false;
144
+ }
145
+ }
@@ -1,3 +1,19 @@
1
+ import { chalk } from "./chalk.js";
2
+ export const SEVERITY_ORDER = ["critical", "high", "medium", "low", "unknown", "none"];
3
+ export function formatSeverityLabel(severity) {
4
+ const lower = severity.toLowerCase();
5
+ if (lower === "critical")
6
+ return chalk.redBright(severity);
7
+ if (lower === "high")
8
+ return chalk.red(severity);
9
+ if (lower === "medium")
10
+ return chalk.yellow(severity);
11
+ if (lower === "low")
12
+ return chalk.blueBright(severity);
13
+ if (lower === "unknown")
14
+ return chalk.magenta(severity);
15
+ return severity;
16
+ }
1
17
  export function countBySeverity(findings) {
2
18
  const counts = {
3
19
  none: 0,
@@ -1,3 +1,37 @@
1
1
  export function pluralize(count, singular, plural = `${singular}s`) {
2
2
  return count === 1 ? singular : plural;
3
3
  }
4
+ /** Known top-level cve-lite commands, for typo suggestions on a mistyped first argument. */
5
+ const KNOWN_COMMANDS = ["advisories", "install-skill", "config", "overrides"];
6
+ /**
7
+ * Suggest the nearest known command for a mistyped first argument. Returns
8
+ * undefined when nothing is within edit distance 2 (e.g. a real typo'd path
9
+ * rather than a typo'd command).
10
+ */
11
+ export function nearestCommand(arg) {
12
+ let best;
13
+ let bestDist = 3;
14
+ for (const c of KNOWN_COMMANDS) {
15
+ const d = levenshtein(arg.toLowerCase(), c);
16
+ if (d < bestDist) {
17
+ bestDist = d;
18
+ best = c;
19
+ }
20
+ }
21
+ return best;
22
+ }
23
+ export function levenshtein(a, b) {
24
+ const m = a.length;
25
+ const n = b.length;
26
+ const dp = Array.from({ length: m + 1 }, () => new Array(n + 1).fill(0));
27
+ for (let i = 0; i <= m; i++)
28
+ dp[i][0] = i;
29
+ for (let j = 0; j <= n; j++)
30
+ dp[0][j] = j;
31
+ for (let i = 1; i <= m; i++) {
32
+ for (let j = 1; j <= n; j++) {
33
+ dp[i][j] = Math.min(dp[i - 1][j] + 1, dp[i][j - 1] + 1, dp[i - 1][j - 1] + (a[i - 1] === b[j - 1] ? 0 : 1));
34
+ }
35
+ }
36
+ return dp[m][n];
37
+ }