@neuralaxis/vibedoctor 0.1.3 → 0.2.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 (112) hide show
  1. package/README.md +298 -115
  2. package/dist/adapters/biome.js +135 -21
  3. package/dist/adapters/dpdp.d.ts +6 -0
  4. package/dist/adapters/dpdp.js +34 -0
  5. package/dist/adapters/index.d.ts +1 -0
  6. package/dist/adapters/index.js +3 -1
  7. package/dist/adapters/osvScanner.js +136 -17
  8. package/dist/adapters/presidio.js +6 -2
  9. package/dist/adapters/privacyDetector.d.ts +24 -1
  10. package/dist/adapters/privacyDetector.js +86 -2
  11. package/dist/adapters/shared.d.ts +6 -0
  12. package/dist/agentPack/templates/skills.js +159 -53
  13. package/dist/cli/commands/dpdp.d.ts +35 -0
  14. package/dist/cli/commands/dpdp.js +103 -0
  15. package/dist/cli/commands/init.js +105 -50
  16. package/dist/cli/commands/privacyReview.js +3 -4
  17. package/dist/cli/commands/scan.js +4 -1
  18. package/dist/cli/commands/setup.d.ts +13 -17
  19. package/dist/cli/commands/setup.js +138 -200
  20. package/dist/cli/index.js +84 -0
  21. package/dist/core/capability.d.ts +92 -0
  22. package/dist/core/capability.js +122 -0
  23. package/dist/core/config.d.ts +57 -0
  24. package/dist/core/config.js +194 -7
  25. package/dist/core/credentialHeuristics.d.ts +28 -0
  26. package/dist/core/credentialHeuristics.js +179 -0
  27. package/dist/core/engine.d.ts +21 -0
  28. package/dist/core/engine.js +484 -84
  29. package/dist/core/executable.d.ts +18 -0
  30. package/dist/core/executable.js +137 -0
  31. package/dist/core/fileRole.d.ts +24 -0
  32. package/dist/core/fileRole.js +125 -0
  33. package/dist/core/finding.d.ts +125 -1
  34. package/dist/core/finding.js +63 -5
  35. package/dist/core/findingNormalizer.d.ts +33 -0
  36. package/dist/core/findingNormalizer.js +171 -0
  37. package/dist/core/projectDetector.d.ts +13 -0
  38. package/dist/core/projectDetector.js +100 -15
  39. package/dist/core/relevance.d.ts +87 -0
  40. package/dist/core/relevance.js +367 -0
  41. package/dist/core/scanPlanner.d.ts +12 -0
  42. package/dist/core/scanPlanner.js +61 -29
  43. package/dist/core/semverLite.d.ts +27 -0
  44. package/dist/core/semverLite.js +163 -0
  45. package/dist/core/suppressions.d.ts +96 -0
  46. package/dist/core/suppressions.js +302 -0
  47. package/dist/core/toolRegistry.d.ts +58 -0
  48. package/dist/core/toolRegistry.js +247 -0
  49. package/dist/core/toolRunner.d.ts +23 -2
  50. package/dist/core/toolRunner.js +61 -93
  51. package/dist/core/toolVerification.d.ts +87 -0
  52. package/dist/core/toolVerification.js +370 -0
  53. package/dist/dpdp/artifacts.d.ts +11 -0
  54. package/dist/dpdp/artifacts.js +120 -0
  55. package/dist/dpdp/catalogue.d.ts +14 -0
  56. package/dist/dpdp/catalogue.js +661 -0
  57. package/dist/dpdp/collectors/confidence.d.ts +9 -0
  58. package/dist/dpdp/collectors/confidence.js +25 -0
  59. package/dist/dpdp/collectors/dependencies.d.ts +7 -0
  60. package/dist/dpdp/collectors/dependencies.js +63 -0
  61. package/dist/dpdp/collectors/index.d.ts +24 -0
  62. package/dist/dpdp/collectors/index.js +71 -0
  63. package/dist/dpdp/collectors/lifecycle.d.ts +2 -0
  64. package/dist/dpdp/collectors/lifecycle.js +202 -0
  65. package/dist/dpdp/collectors/optionalScanners.d.ts +14 -0
  66. package/dist/dpdp/collectors/optionalScanners.js +437 -0
  67. package/dist/dpdp/collectors/privacyBridge.d.ts +13 -0
  68. package/dist/dpdp/collectors/privacyBridge.js +152 -0
  69. package/dist/dpdp/collectors/safeguards.d.ts +5 -0
  70. package/dist/dpdp/collectors/safeguards.js +186 -0
  71. package/dist/dpdp/collectors/schema.d.ts +6 -0
  72. package/dist/dpdp/collectors/schema.js +122 -0
  73. package/dist/dpdp/collectors/shared.d.ts +10 -0
  74. package/dist/dpdp/collectors/shared.js +43 -0
  75. package/dist/dpdp/context.d.ts +28 -0
  76. package/dist/dpdp/context.js +195 -0
  77. package/dist/dpdp/dataMap.d.ts +7 -0
  78. package/dist/dpdp/dataMap.js +339 -0
  79. package/dist/dpdp/evaluators.d.ts +20 -0
  80. package/dist/dpdp/evaluators.js +522 -0
  81. package/dist/dpdp/evidence.d.ts +11 -0
  82. package/dist/dpdp/evidence.js +123 -0
  83. package/dist/dpdp/findings.d.ts +44 -0
  84. package/dist/dpdp/findings.js +286 -0
  85. package/dist/dpdp/gates.d.ts +14 -0
  86. package/dist/dpdp/gates.js +47 -0
  87. package/dist/dpdp/index.d.ts +16 -0
  88. package/dist/dpdp/index.js +32 -0
  89. package/dist/dpdp/legalSources.d.ts +10 -0
  90. package/dist/dpdp/legalSources.js +104 -0
  91. package/dist/dpdp/paths.d.ts +25 -0
  92. package/dist/dpdp/paths.js +85 -0
  93. package/dist/dpdp/report.d.ts +6 -0
  94. package/dist/dpdp/report.js +222 -0
  95. package/dist/dpdp/reviewQueue.d.ts +3 -0
  96. package/dist/dpdp/reviewQueue.js +88 -0
  97. package/dist/dpdp/scan.d.ts +26 -0
  98. package/dist/dpdp/scan.js +310 -0
  99. package/dist/dpdp/scoring.d.ts +41 -0
  100. package/dist/dpdp/scoring.js +237 -0
  101. package/dist/dpdp/types.d.ts +312 -0
  102. package/dist/dpdp/types.js +86 -0
  103. package/dist/index.d.ts +1 -0
  104. package/dist/index.js +1 -0
  105. package/dist/mcp/tools/dpdp.d.ts +11 -0
  106. package/dist/mcp/tools/dpdp.js +151 -0
  107. package/dist/mcp/tools/index.js +3 -1
  108. package/dist/reporters/html.js +57 -13
  109. package/dist/reporters/json.js +12 -1
  110. package/dist/reporters/markdown.js +46 -4
  111. package/dist/reporters/sarif.js +54 -5
  112. package/package.json +4 -1
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.withReportingDefaults = withReportingDefaults;
3
4
  exports.createAgentPlan = createAgentPlan;
4
5
  exports.runScan = runScan;
5
6
  exports.retryTool = retryTool;
@@ -11,6 +12,7 @@ exports.safeFix = safeFix;
11
12
  const adapters_1 = require("../adapters");
12
13
  const customLeftovers_1 = require("../adapters/customLeftovers");
13
14
  const privacyDetector_1 = require("../adapters/privacyDetector");
15
+ const dpdp_1 = require("../adapters/dpdp");
14
16
  const customRefactor_1 = require("../adapters/customRefactor");
15
17
  const customDeadChain_1 = require("../adapters/customDeadChain");
16
18
  const presidio_1 = require("../adapters/presidio");
@@ -23,6 +25,13 @@ const scanPlanner_1 = require("./scanPlanner");
23
25
  const scoring_1 = require("./scoring");
24
26
  const toolRunner_1 = require("./toolRunner");
25
27
  const severityMap_1 = require("../rules/severityMap");
28
+ const capability_1 = require("./capability");
29
+ const fileRole_1 = require("./fileRole");
30
+ const findingNormalizer_1 = require("./findingNormalizer");
31
+ const relevance_1 = require("./relevance");
32
+ const suppressions_1 = require("./suppressions");
33
+ const toolRegistry_1 = require("./toolRegistry");
34
+ const toolVerification_1 = require("./toolVerification");
26
35
  const privacyReview_1 = require("./privacyReview");
27
36
  const ALL_ADAPTERS = [
28
37
  adapters_1.gitleaksAdapter,
@@ -42,6 +51,7 @@ const ALL_ADAPTERS = [
42
51
  adapters_1.vitestAdapter,
43
52
  adapters_1.jestAdapter,
44
53
  privacyDetector_1.privacyDetectorAdapter,
54
+ dpdp_1.dpdpAdapter,
45
55
  presidio_1.presidioAdapter,
46
56
  adapters_1.telemetryDetectorAdapter,
47
57
  customLeftovers_1.customLeftoversAdapter,
@@ -59,6 +69,72 @@ const categoryPriority = {
59
69
  maintainability: 8,
60
70
  efficiency: 9
61
71
  };
72
+ const emptyRelevanceReport = {
73
+ enabled: false,
74
+ perTool: [],
75
+ totalReported: 0,
76
+ totalSurfaced: 0,
77
+ notes: []
78
+ };
79
+ const emptySuppressionReport = {
80
+ file: "",
81
+ active: [],
82
+ expired: [],
83
+ invalid: [],
84
+ permanent: [],
85
+ hits: {},
86
+ expiredHits: {},
87
+ unused: [],
88
+ resurfaced: 0
89
+ };
90
+ const emptyCapabilityMatrix = (0, capability_1.buildCapabilityMatrix)([], []);
91
+ /**
92
+ * Fills in the reporting fields a scan produces, for callers that reconstruct a
93
+ * `ScanOutput` from something other than a live scan — a cached report written by
94
+ * an older version, or a test fixture. The defaults describe an unknown scan
95
+ * rather than a clean one: an empty matrix claims no coverage.
96
+ */
97
+ function withReportingDefaults(partial) {
98
+ return {
99
+ root: partial.root ?? process.cwd(),
100
+ mode: partial.mode ?? "default",
101
+ score: partial.score ?? (0, scoring_1.buildScore)(partial.findings),
102
+ findings: partial.findings,
103
+ topFindings: partial.topFindings ?? [],
104
+ blockers: partial.blockers ?? [],
105
+ fixNext: partial.fixNext ?? [],
106
+ privacyFindings: partial.privacyFindings ?? [],
107
+ privacyReview: partial.privacyReview,
108
+ leftovers: partial.leftovers ?? [],
109
+ deadCodeCandidates: partial.deadCodeCandidates ?? [],
110
+ refactorCandidates: partial.refactorCandidates ?? [],
111
+ toolStatuses: partial.toolStatuses ?? [],
112
+ skippedTools: partial.skippedTools ?? [],
113
+ completeness: partial.completeness ?? {
114
+ status: "partial",
115
+ comparable: false,
116
+ planned: 0,
117
+ completed: 0,
118
+ incompleteTools: [],
119
+ requiredIncompleteTools: [],
120
+ reason: "This result was reconstructed without capability information, so coverage is unknown."
121
+ },
122
+ recoveryActions: partial.recoveryActions ?? [],
123
+ testCommands: partial.testCommands ?? [],
124
+ agentPlan: partial.agentPlan ??
125
+ createAgentPlan({
126
+ findings: partial.findings,
127
+ score: partial.score ?? (0, scoring_1.buildScore)(partial.findings),
128
+ skippedTools: partial.skippedTools ?? []
129
+ }),
130
+ configPath: partial.configPath,
131
+ capabilityMatrix: partial.capabilityMatrix ?? emptyCapabilityMatrix,
132
+ relevance: partial.relevance ?? emptyRelevanceReport,
133
+ suppressions: partial.suppressions ?? emptySuppressionReport,
134
+ suppressedFindings: partial.suppressedFindings ?? [],
135
+ verifications: partial.verifications ?? []
136
+ };
137
+ }
62
138
  function sortFindings(findings) {
63
139
  return [...findings].sort((left, right) => {
64
140
  const categoryDelta = categoryPriority[left.category] - categoryPriority[right.category];
@@ -252,7 +328,12 @@ function buildScanOutput(options) {
252
328
  recoveryActions,
253
329
  testCommands: options.testCommands
254
330
  }, { policy, target: options.target }),
255
- configPath: options.configPath
331
+ configPath: options.configPath,
332
+ capabilityMatrix: options.capabilityMatrix,
333
+ relevance: options.relevance,
334
+ suppressions: options.suppressions,
335
+ suppressedFindings: options.suppressedFindings,
336
+ verifications: options.verifications
256
337
  };
257
338
  }
258
339
  function firstUsefulLine(value) {
@@ -296,41 +377,191 @@ function forgiveKnownToolQuirks(toolId, result, findingsCount = 0) {
296
377
  }
297
378
  return undefined;
298
379
  }
299
- async function runAdapter(adapter, ctx) {
380
+ /**
381
+ * Narrows a context to a subset of files. A tool that cannot finish the whole
382
+ * repository within its budget can still cover the code being changed, and
383
+ * partial coverage that says so is worth more than no coverage at all.
384
+ */
385
+ function narrowContextToFiles(ctx, files) {
386
+ return {
387
+ ...ctx,
388
+ project: { ...ctx.project, projectFiles: files }
389
+ };
390
+ }
391
+ function commandText(command) {
392
+ return [command.cmd, ...command.args].join(" ");
393
+ }
394
+ async function runAdapter(adapter, ctx, deadline) {
300
395
  if (adapter.runStandalone) {
301
396
  return adapter.runStandalone(ctx);
302
397
  }
303
- if (adapter.buildScanCommand && adapter.parseResult) {
304
- const command = adapter.buildScanCommand(ctx);
305
- const timeoutSeconds = ctx.config.runtime.toolTimeouts[adapter.id] ?? ctx.config.runtime.defaultTimeoutSeconds;
306
- command.timeoutMs = timeoutSeconds * 1000;
307
- const status = await (0, toolRunner_1.runCommand)(command, adapter.installHint);
308
- if (status.status === "skipped") {
309
- return { findings: [], status };
310
- }
311
- // Guard against brittle parser (unvalidated JSON, format drift in tsc etc.).
312
- // Standalone adapters already have partial internal try/catch; this covers the command+parseResult path.
313
- let parsed = [];
314
- try {
315
- parsed = adapter.parseResult(status, ctx) ?? [];
316
- }
317
- catch {
318
- parsed = [];
319
- }
320
- return { findings: parsed, status };
398
+ if (!adapter.buildScanCommand || !adapter.parseResult) {
399
+ return {
400
+ findings: [],
401
+ status: {
402
+ command: adapter.id,
403
+ stdout: "",
404
+ stderr: "Adapter has no scan command",
405
+ exitCode: null,
406
+ durationMs: 0,
407
+ status: "skipped",
408
+ installHint: adapter.installHint
409
+ }
410
+ };
321
411
  }
322
- return {
323
- findings: [],
324
- status: {
325
- command: adapter.id,
326
- stdout: "",
327
- stderr: "Adapter has no scan command",
328
- exitCode: null,
329
- durationMs: 0,
330
- status: "skipped",
331
- installHint: adapter.installHint
412
+ const { runtime } = ctx.config;
413
+ const configuredSeconds = runtime.toolTimeouts[adapter.id] ?? runtime.defaultTimeoutSeconds;
414
+ // A wall-clock ceiling for the whole scan has to bound each tool too, or the
415
+ // slowest tool decides how long the scan takes regardless of the budget.
416
+ const budgetSeconds = deadline ? Math.max(1, Math.round((deadline - Date.now()) / 1000)) : configuredSeconds;
417
+ const timeoutSeconds = Math.min(configuredSeconds, budgetSeconds);
418
+ const command = adapter.buildScanCommand(ctx);
419
+ command.timeoutMs = timeoutSeconds * 1000;
420
+ let status = await (0, toolRunner_1.runCommand)(command, adapter.installHint);
421
+ if (status.status === "timeout" && runtime.onTimeout === "scoped_retry") {
422
+ const scoped = await retryWithNarrowedScope(adapter, ctx, timeoutSeconds);
423
+ if (scoped) {
424
+ status = scoped;
332
425
  }
426
+ }
427
+ if (status.status === "skipped") {
428
+ return { findings: [], status, timeoutSeconds };
429
+ }
430
+ // Guard against brittle parsers (unvalidated JSON, format drift in tsc etc.).
431
+ // A parse failure is reported rather than swallowed: a tool that ran but whose
432
+ // output could not be read has not actually checked anything.
433
+ try {
434
+ return { findings: adapter.parseResult(status, ctx) ?? [], status, timeoutSeconds };
435
+ }
436
+ catch (error) {
437
+ return {
438
+ findings: [],
439
+ status,
440
+ parseError: `Could not parse ${adapter.id} output: ${error instanceof Error ? error.message : String(error)}`,
441
+ timeoutSeconds
442
+ };
443
+ }
444
+ }
445
+ /**
446
+ * Reruns a timed-out tool over the changed files only. Skipped when narrowing
447
+ * produces the same command line, since a tool that ignores the target list
448
+ * would simply time out again.
449
+ */
450
+ async function retryWithNarrowedScope(adapter, ctx, originalTimeoutSeconds) {
451
+ const changed = ctx.project.changedFiles.filter((file) => ctx.project.projectFiles.includes(file));
452
+ if (changed.length === 0 || !adapter.buildScanCommand) {
453
+ return undefined;
454
+ }
455
+ const original = commandText(adapter.buildScanCommand(ctx));
456
+ const narrowedCtx = narrowContextToFiles(ctx, changed);
457
+ const narrowed = adapter.buildScanCommand(narrowedCtx);
458
+ if (commandText(narrowed) === original) {
459
+ return undefined;
460
+ }
461
+ narrowed.timeoutMs = Math.max(1, ctx.config.runtime.scopedRetryTimeoutSeconds) * 1000;
462
+ const result = await (0, toolRunner_1.runCommand)(narrowed, adapter.installHint);
463
+ const coverage = {
464
+ scope: "scoped",
465
+ detail: `Timed out after ${originalTimeoutSeconds}s over the full repository; rescanned ${changed.length} changed file(s) instead.`,
466
+ targetsRequested: ctx.project.projectFiles.length,
467
+ targetsScanned: changed.length
333
468
  };
469
+ return result.status === "timeout"
470
+ ? // Even the narrowed run did not finish. Report the original timeout rather
471
+ // than a second one, and say the fallback was attempted.
472
+ {
473
+ ...result,
474
+ coverage: {
475
+ scope: "none",
476
+ detail: `Timed out after ${originalTimeoutSeconds}s, and a scoped retry over ${changed.length} changed file(s) also timed out.`,
477
+ targetsRequested: ctx.project.projectFiles.length,
478
+ targetsScanned: 0
479
+ }
480
+ }
481
+ : { ...result, coverage };
482
+ }
483
+ /**
484
+ * Resolves each selected tool before the scan trusts it.
485
+ *
486
+ * Without this, a missing tool only revealed itself as an ENOENT mid-scan —
487
+ * indistinguishable from a tool that ran and found nothing, and with no record of
488
+ * which binary was even looked for. This runs at `resolve` depth: it locates the
489
+ * executable and checks runtime compatibility without spawning a probe per tool,
490
+ * because the scan is about to invoke each tool anyway. `vibedoctor setup` does
491
+ * the same work at `execute` depth, where there is no later run to rely on.
492
+ */
493
+ async function verifySelectedTools(root, adapterIds, config) {
494
+ const entries = adapterIds.map(toolRegistry_1.getToolEntry).filter((entry) => Boolean(entry));
495
+ if (!config.runtime.verifyToolsBeforeScan || entries.length === 0) {
496
+ return new Map();
497
+ }
498
+ const verifications = await (0, toolVerification_1.verifyTools)(entries, root, "resolve");
499
+ return new Map(verifications.map((verification) => [verification.id, verification]));
500
+ }
501
+ /** Derives the capability state for a tool that was selected and attempted. */
502
+ function stateForRun(id, run, verification, findingsCount) {
503
+ if (verification && (0, toolVerification_1.isVerificationBlocking)(verification)) {
504
+ return verification.state === "incompatible_runtime" ? "runtime_incompatible" : "not_installed";
505
+ }
506
+ const status = run.status;
507
+ if (!status) {
508
+ // Built-in checks report no process status; reaching here means they ran.
509
+ return "completed";
510
+ }
511
+ if (status.status === "skipped") {
512
+ return "not_installed";
513
+ }
514
+ if (status.status === "timeout") {
515
+ return status.coverage?.scope === "scoped" ? "partial" : "timed_out";
516
+ }
517
+ if (run.parseError) {
518
+ return "failed";
519
+ }
520
+ if (status.status === "error") {
521
+ return forgiveKnownToolQuirks(id, status, findingsCount) ? "completed" : "failed";
522
+ }
523
+ return status.coverage && status.coverage.scope !== "full" ? "partial" : "completed";
524
+ }
525
+ function reasonForCapability(id, state, run, verification, normalizationNote) {
526
+ if (verification && (0, toolVerification_1.isVerificationBlocking)(verification)) {
527
+ return { reason: verification.reason, remediation: verification.remediation };
528
+ }
529
+ switch (state) {
530
+ case "completed": {
531
+ const where = verification?.resolvedPath ?? run.status?.resolvedPath;
532
+ const version = verification?.version ? ` ${verification.version}` : "";
533
+ const base = where ? `Ran${version} at ${where}.` : `Completed${version}.`;
534
+ return { reason: normalizationNote ? `${base} ${normalizationNote}` : base };
535
+ }
536
+ case "partial":
537
+ return {
538
+ reason: run.status?.coverage?.detail ?? "Covered only part of the requested scope.",
539
+ remediation: `Raise runtime.tool_timeouts.${id} in vibedoctor.yml, or run \`vibedoctor tool retry ${id}\` with a longer budget.`
540
+ };
541
+ case "timed_out":
542
+ return {
543
+ reason: run.status?.coverage?.detail ??
544
+ `Exceeded its ${run.timeoutSeconds ?? "configured"}s budget and was stopped, so this check did not run.`,
545
+ remediation: `Raise runtime.tool_timeouts.${id} in vibedoctor.yml, scan fewer paths, or run \`vibedoctor scan --changed\` for a diff-scoped run.`
546
+ };
547
+ case "failed":
548
+ return {
549
+ reason: run.parseError ?? summarizeToolStatus(run.status).message ?? "Failed while running.",
550
+ remediation: `Run \`vibedoctor tool retry ${id}\` to see the full output.`
551
+ };
552
+ case "not_installed":
553
+ return {
554
+ reason: `${id} is not installed or could not be found on PATH, so this check did not run.`,
555
+ remediation: run.status?.installHint ?? ((0, toolRegistry_1.getToolEntry)(id) ? (0, toolRegistry_1.installHintFor)((0, toolRegistry_1.getToolEntry)(id)) : `Install ${id}.`)
556
+ };
557
+ case "runtime_incompatible":
558
+ return {
559
+ reason: `${id} cannot run under the active runtime.`,
560
+ remediation: `Upgrade the runtime or add ${id} to runtime.deferred_tools to defer it deliberately.`
561
+ };
562
+ default:
563
+ return { reason: "Did not run." };
564
+ }
334
565
  }
335
566
  async function runScan(root, mode = "default") {
336
567
  const [{ config, configPath }, { policy }] = await Promise.all([(0, config_1.loadConfig)(root), (0, policy_1.loadAgentPolicy)(root)]);
@@ -338,58 +569,109 @@ async function runScan(root, mode = "default") {
338
569
  const plan = await (0, scanPlanner_1.createScanPlan)(project, config, [...ALL_ADAPTERS], mode);
339
570
  const ctx = { root, project, config, scanMode: mode };
340
571
  const selectedAdapters = ALL_ADAPTERS.filter((adapter) => plan.adapterIds.includes(adapter.id));
341
- // Run adapters concurrently for performance (independent tools; dead-chain post-process depends on aggregated findings).
342
- // This addresses the previous sequential for-loop bottleneck in runScan.
343
- const adapterResults = await Promise.all(selectedAdapters.map(async (adapter) => ({ adapter, result: await runAdapter(adapter, ctx) })));
572
+ const verifications = await verifySelectedTools(root, plan.adapterIds, config);
573
+ // A tool that failed verification is not launched: doing so produces a
574
+ // confusing process error in place of the clear reason we already have.
575
+ const runnableAdapters = selectedAdapters.filter((adapter) => {
576
+ const verification = verifications.get(adapter.id);
577
+ return !verification || !(0, toolVerification_1.isVerificationBlocking)(verification);
578
+ });
579
+ const deadline = config.runtime.totalBudgetSeconds > 0 ? Date.now() + config.runtime.totalBudgetSeconds * 1000 : undefined;
580
+ const independentAdapters = runnableAdapters.filter((adapter) => adapter.id !== "dpdp");
581
+ // Run independent adapters once. DPDP follows so it can reuse optional scanner
582
+ // findings/status instead of launching duplicate Semgrep and Presidio processes.
583
+ const adapterResults = await Promise.all(independentAdapters.map(async (adapter) => ({ adapter, result: await runAdapter(adapter, ctx, deadline) })));
584
+ if (runnableAdapters.some((adapter) => adapter.id === "dpdp")) {
585
+ const sharedToolResults = Object.fromEntries(adapterResults.map(({ adapter, result }) => [adapter.id, result]));
586
+ const dpdpCtx = { ...ctx, sharedToolResults };
587
+ adapterResults.push({ adapter: dpdp_1.dpdpAdapter, result: await runAdapter(dpdp_1.dpdpAdapter, dpdpCtx, deadline) });
588
+ }
589
+ const classifyFile = (0, fileRole_1.createFileRoleClassifier)(config.relevance.fileRoles);
344
590
  const findings = [];
345
- const toolStatuses = [];
346
- const skippedTools = [];
591
+ const capabilities = [];
592
+ const normalizationIssues = [];
347
593
  for (const { adapter, result } of adapterResults) {
348
- findings.push(...result.findings);
349
- if (!result.status) {
350
- continue;
351
- }
352
- if (result.status.status === "skipped") {
353
- skippedTools.push({
354
- id: adapter.id,
355
- status: "skipped",
356
- installHint: result.status.installHint ?? adapter.installHint
357
- });
594
+ // Normalize per tool so location loss and enum drift are attributed to the
595
+ // tool that caused them rather than averaged across the whole scan.
596
+ const normalized = await (0, findingNormalizer_1.normalizeFindings)(result.findings, {
597
+ root,
598
+ tool: adapter.id,
599
+ classifyFile,
600
+ changedFiles: project.changedFiles
601
+ });
602
+ normalizationIssues.push(...normalized.issues);
603
+ findings.push(...normalized.findings);
604
+ const verification = verifications.get(adapter.id);
605
+ const state = stateForRun(adapter.id, result, verification, normalized.findings.length);
606
+ const { reason, remediation } = reasonForCapability(adapter.id, state, result, verification, (0, findingNormalizer_1.describeNormalizationIssues)(normalized.issues));
607
+ capabilities.push({
608
+ id: adapter.id,
609
+ category: adapter.category,
610
+ state,
611
+ planned: true,
612
+ applicable: true,
613
+ discovered: verification ? verification.state === "verified" : result.status?.status !== "skipped",
614
+ executed: Boolean(result.status) || state === "completed",
615
+ resolvedPath: verification?.resolvedPath ?? result.status?.resolvedPath ?? verification?.interpreterPath,
616
+ version: verification?.version,
617
+ command: result.status?.command,
618
+ durationMs: result.status?.durationMs,
619
+ timeoutSeconds: result.timeoutSeconds,
620
+ coverage: result.status?.coverage,
621
+ findingsReported: normalized.findings.length,
622
+ // Filled in once relevance and suppressions have run.
623
+ findingsSurfaced: normalized.findings.length,
624
+ reason,
625
+ remediation,
626
+ trust: "authoritative"
627
+ });
628
+ }
629
+ // Tools that failed verification never launched, so record them from the
630
+ // verification result alone.
631
+ for (const adapter of selectedAdapters) {
632
+ if (runnableAdapters.includes(adapter)) {
358
633
  continue;
359
634
  }
360
- const forgiven = forgiveKnownToolQuirks(adapter.id, result.status, result.findings.length);
361
- const summarized = summarizeToolStatus(result.status);
362
- toolStatuses.push({
635
+ const verification = verifications.get(adapter.id);
636
+ const state = verification.state === "incompatible_runtime" ? "runtime_incompatible" : "not_installed";
637
+ capabilities.push({
363
638
  id: adapter.id,
364
- status: forgiven?.status ?? result.status.status,
365
- ...summarized,
366
- ...(forgiven ? { message: forgiven.message } : {})
639
+ category: adapter.category,
640
+ state,
641
+ planned: true,
642
+ applicable: true,
643
+ discovered: verification.state !== "not_found",
644
+ executed: false,
645
+ resolvedPath: verification.resolvedPath ?? verification.interpreterPath,
646
+ version: verification.version,
647
+ findingsReported: 0,
648
+ findingsSurfaced: 0,
649
+ reason: verification.reason,
650
+ remediation: verification.remediation,
651
+ trust: "absent"
652
+ });
653
+ }
654
+ for (const excluded of plan.excluded) {
655
+ const adapter = ALL_ADAPTERS.find((candidate) => candidate.id === excluded.id);
656
+ capabilities.push({
657
+ id: excluded.id,
658
+ category: adapter?.category ?? "maintainability",
659
+ state: excluded.state,
660
+ planned: false,
661
+ applicable: excluded.state !== "not_applicable",
662
+ discovered: false,
663
+ executed: false,
664
+ findingsReported: 0,
665
+ findingsSurfaced: 0,
666
+ reason: excluded.reason,
667
+ remediation: excluded.state === "deferred"
668
+ ? `Remove ${excluded.id} from runtime.deferred_tools to run it again.`
669
+ : excluded.state === "not_selected"
670
+ ? "Run `vibedoctor scan --full` to include it."
671
+ : undefined,
672
+ trust: "authoritative"
367
673
  });
368
674
  }
369
- const incompleteTools = Array.from(new Set([
370
- ...skippedTools.map((tool) => tool.id),
371
- ...toolStatuses.filter((tool) => tool.status === "error" || tool.status === "timeout").map((tool) => tool.id)
372
- ])).sort();
373
- // Skipped tools can include checks that were never selected as adapters
374
- // (built-in checks, mode-filtered tools); count them in the denominator so
375
- // "completed" never underflows.
376
- const plannedIds = new Set([...selectedAdapters.map((adapter) => adapter.id), ...incompleteTools]);
377
- const requiredIncompleteTools = incompleteTools.filter((id) => config.runtime.requiredTools.includes(id));
378
- const completeness = {
379
- status: incompleteTools.length === 0
380
- ? "complete"
381
- : requiredIncompleteTools.length > 0 || config.runtime.failOnIncompleteScan
382
- ? "invalid"
383
- : "partial",
384
- comparable: incompleteTools.length === 0,
385
- planned: plannedIds.size,
386
- completed: plannedIds.size - incompleteTools.length,
387
- incompleteTools,
388
- requiredIncompleteTools,
389
- reason: incompleteTools.length > 0
390
- ? `${incompleteTools.length} of ${plannedIds.size} planned checks did not complete.`
391
- : undefined
392
- };
393
675
  let deadChainFindings = [];
394
676
  if (config.checks.deadCode.enabled) {
395
677
  const rawDead = await (0, customDeadChain_1.detectDeadChains)(project, findings, config);
@@ -399,13 +681,46 @@ async function runScan(root, mode = "default") {
399
681
  deadChainFindings = rawDead.filter((f) => rank[f.confidence] >= minRank);
400
682
  }
401
683
  let allFindings = (0, finding_1.dedupeFindings)([...findings, ...deadChainFindings]);
684
+ // Baseline first, so novelty is known before ranking; then acknowledgements,
685
+ // which may reclassify a finding as resurfaced; then relevance, which ranks and
686
+ // caps what is left.
402
687
  if (config.baseline.enabled) {
403
688
  const baseline = await (0, baseline_1.loadBaseline)(root, config.baseline.file);
404
689
  allFindings = (0, finding_1.applyBaseline)(allFindings, new Set(baseline.findings.map((entry) => entry.fingerprint)));
405
690
  }
691
+ const suppressionsResult = config.suppressions.enabled
692
+ ? (0, suppressions_1.applySuppressions)(allFindings, await (0, suppressions_1.loadSuppressions)(root, config.suppressions.file), {
693
+ requireExpiry: config.suppressions.requireExpiry
694
+ })
695
+ : { findings: allFindings, suppressed: [], report: { ...emptySuppressionReport, file: config.suppressions.file } };
696
+ const relevanceResult = await (0, relevance_1.applyRelevance)(suppressionsResult.findings, {
697
+ root,
698
+ config: config.relevance
699
+ });
700
+ allFindings = relevanceResult.findings;
406
701
  const privacyReview = await (0, privacyReview_1.loadPrivacyReview)(root, config.output.privacyReview);
407
702
  allFindings = (0, privacyReview_1.mergePrivacyReviewIntoFindings)(allFindings, privacyReview);
408
703
  allFindings = sortFindings(allFindings);
704
+ // Record what actually reached the report per tool, so "installed" and
705
+ // "completed" and "reported something you can read" stay separate facts.
706
+ const surfacedBySource = new Map();
707
+ for (const finding of allFindings) {
708
+ surfacedBySource.set(finding.source, (surfacedBySource.get(finding.source) ?? 0) + 1);
709
+ }
710
+ for (const capability of capabilities) {
711
+ capability.findingsSurfaced = surfacedBySource.get(capability.id) ?? 0;
712
+ capability.trust =
713
+ capability.state === "completed" ||
714
+ capability.state === "not_applicable" ||
715
+ capability.state === "disabled" ||
716
+ capability.state === "not_selected"
717
+ ? "authoritative"
718
+ : capability.state === "partial"
719
+ ? "partial"
720
+ : "absent";
721
+ }
722
+ const capabilityMatrix = (0, capability_1.buildCapabilityMatrix)(capabilities, config.runtime.requiredTools);
723
+ const { toolStatuses, skippedTools, completeness } = deriveLegacyStatuses(capabilityMatrix, config);
409
724
  const score = (0, scoring_1.buildScore)(allFindings);
410
725
  return buildScanOutput({
411
726
  root,
@@ -418,9 +733,57 @@ async function runScan(root, mode = "default") {
418
733
  testCommands: project.testCommands,
419
734
  policy,
420
735
  configPath,
421
- privacyReview: privacyReview?.summary
736
+ privacyReview: privacyReview?.summary,
737
+ capabilityMatrix,
738
+ relevance: relevanceResult.report,
739
+ suppressions: suppressionsResult.report,
740
+ suppressedFindings: suppressionsResult.suppressed,
741
+ verifications: Array.from(verifications.values())
422
742
  });
423
743
  }
744
+ /**
745
+ * Projects the capability matrix onto the older `toolStatuses` / `skippedTools` /
746
+ * `completeness` shapes, which the reporters, agent plan, and MCP tools consume.
747
+ * The matrix is the source of truth; these are views of it.
748
+ */
749
+ function deriveLegacyStatuses(matrix, config) {
750
+ const toolStatuses = [];
751
+ const skippedTools = [];
752
+ for (const tool of matrix.tools) {
753
+ if (tool.state === "not_installed" || tool.state === "runtime_incompatible" || tool.state === "deferred") {
754
+ skippedTools.push({ id: tool.id, status: "skipped", installHint: tool.remediation });
755
+ continue;
756
+ }
757
+ if (tool.state === "not_applicable" || tool.state === "disabled" || tool.state === "not_selected") {
758
+ continue;
759
+ }
760
+ toolStatuses.push({
761
+ id: tool.id,
762
+ status: tool.state === "timed_out" ? "timeout" : tool.state === "failed" ? "error" : "ok",
763
+ message: tool.state === "completed" ? undefined : tool.reason,
764
+ command: tool.command
765
+ });
766
+ }
767
+ const gaps = matrix.tools.filter(capability_1.isCoverageGap).map((tool) => tool.id);
768
+ const planned = matrix.tools.filter((tool) => tool.planned).length;
769
+ return {
770
+ toolStatuses,
771
+ skippedTools,
772
+ completeness: {
773
+ status: gaps.length === 0
774
+ ? "complete"
775
+ : matrix.requiredGaps.length > 0 || config.runtime.failOnIncompleteScan
776
+ ? "invalid"
777
+ : "partial",
778
+ comparable: gaps.length === 0,
779
+ planned,
780
+ completed: Math.max(0, planned - gaps.length),
781
+ incompleteTools: gaps,
782
+ requiredIncompleteTools: matrix.requiredGaps,
783
+ reason: gaps.length > 0 ? `${gaps.length} of ${planned} planned checks did not fully complete.` : undefined
784
+ }
785
+ };
786
+ }
424
787
  async function retryTool(root, toolId, timeoutSeconds) {
425
788
  const { config } = await (0, config_1.loadConfig)(root);
426
789
  const project = await (0, projectDetector_1.detectProject)(root, config.paths.exclude);
@@ -487,6 +850,9 @@ function buildRecoveryActions(toolStatuses, skippedTools = []) {
487
850
  }));
488
851
  return [...failed, ...skipped];
489
852
  }
853
+ function categoryScopeNote(categories) {
854
+ return `Counted across the whole scan, not only the ${categories.join(", ")} findings shown here.`;
855
+ }
490
856
  function filterScanByCategories(scan, categories, options = {}) {
491
857
  const findings = sortFindings(scan.findings.filter((finding) => categories.includes(finding.category)));
492
858
  const score = (0, scoring_1.buildScore)(findings);
@@ -502,7 +868,24 @@ function filterScanByCategories(scan, categories, options = {}) {
502
868
  policy: options.policy,
503
869
  target: options.target ?? scan.agentPlan.target,
504
870
  configPath: scan.configPath,
505
- privacyReview: scan.privacyReview
871
+ privacyReview: scan.privacyReview,
872
+ // The matrix describes the scan, not the filtered view, so it carries over
873
+ // unchanged apart from the surfaced counts, which now reflect the filter.
874
+ capabilityMatrix: {
875
+ ...scan.capabilityMatrix,
876
+ tools: scan.capabilityMatrix.tools.map((tool) => ({
877
+ ...tool,
878
+ findingsSurfaced: findings.filter((finding) => finding.source === tool.id).length
879
+ }))
880
+ },
881
+ // Filtering and acknowledgement counts were computed over the whole scan and
882
+ // cannot be re-attributed here (a withheld finding is no longer around to be
883
+ // categorised), so they are carried over and labelled as scan-wide rather
884
+ // than presented as totals for the categories on screen.
885
+ relevance: { ...scan.relevance, scopeNote: categoryScopeNote(categories) },
886
+ suppressions: { ...scan.suppressions, scopeNote: categoryScopeNote(categories) },
887
+ suppressedFindings: scan.suppressedFindings.filter((finding) => categories.includes(finding.category)),
888
+ verifications: scan.verifications
506
889
  });
507
890
  }
508
891
  function buildSummaryLines(scan) {
@@ -515,6 +898,10 @@ function buildSummaryLines(scan) {
515
898
  lines.push(`Blockers: ${scan.blockers.length}`);
516
899
  lines.push(`Fix next: ${scan.fixNext.length}`);
517
900
  lines.push(`Privacy Review findings: ${scan.privacyFindings.length}`);
901
+ const dpdpFindings = scan.privacyFindings.filter((finding) => finding.source === "dpdp");
902
+ if (dpdpFindings.length > 0) {
903
+ lines.push(`DPDP technical findings: ${dpdpFindings.length} (not legal compliance)`);
904
+ }
518
905
  lines.push(`Leftovers: ${scan.leftovers.length}`);
519
906
  lines.push(`Dead code candidates: ${scan.deadCodeCandidates.length}`);
520
907
  lines.push(`Refactor candidates: ${scan.refactorCandidates.length}`);
@@ -532,6 +919,13 @@ function buildSummaryLines(scan) {
532
919
  .slice(0, 5)
533
920
  .forEach((finding, index) => lines.push(`${index + 1}. ${finding.title}${finding.file ? ` (${finding.file}${finding.startLine ? `:${finding.startLine}` : ""})` : ""}`));
534
921
  }
922
+ if (dpdpFindings.length > 0) {
923
+ lines.push("", "DPDP TECHNICAL FINDINGS (not legal compliance)");
924
+ dpdpFindings
925
+ .slice(0, 5)
926
+ .forEach((finding, index) => lines.push(`${index + 1}. ${finding.title}${finding.file ? ` (${finding.file}${finding.startLine ? `:${finding.startLine}` : ""})` : ""}`));
927
+ lines.push("Artifacts: .vibedoctor/dpdp/ · Command: vibedoctor dpdp report --markdown");
928
+ }
535
929
  if (scan.leftovers.length > 0) {
536
930
  lines.push("", "LEFTOVERS");
537
931
  scan.leftovers.forEach((finding, index) => lines.push(`${index + 1}. ${finding.title}${finding.file ? ` (${finding.file})` : ""}`));
@@ -540,14 +934,20 @@ function buildSummaryLines(scan) {
540
934
  lines.push("", "DEAD CHAINS");
541
935
  scan.deadCodeCandidates.forEach((finding, index) => lines.push(`${index + 1}. ${finding.message}`));
542
936
  }
543
- if (scan.skippedTools.length > 0) {
544
- lines.push("", "SKIPPED TOOLS");
545
- scan.skippedTools.forEach((tool, index) => lines.push(`${index + 1}. ${tool.id}${tool.installHint ? ` — ${tool.installHint}` : ""}`));
937
+ // One table replaces the old "skipped tools" and "errored tools" lists. Those
938
+ // could not distinguish a tool that was never applicable from one that timed
939
+ // out mid-scan, and said nothing about how much of the repository was covered.
940
+ const matrixLines = (0, capability_1.renderCapabilityMatrixLines)(scan.capabilityMatrix);
941
+ if (matrixLines.length > 0) {
942
+ lines.push("", "TOOL COVERAGE", ...matrixLines);
943
+ }
944
+ const relevanceLines = (0, relevance_1.renderRelevanceLines)(scan.relevance);
945
+ if (relevanceLines.length > 0) {
946
+ lines.push("", "REPORT FILTERING", ...relevanceLines);
546
947
  }
547
- const erroredTools = scan.toolStatuses.filter((tool) => tool.status === "error" || tool.status === "timeout");
548
- if (erroredTools.length > 0) {
549
- lines.push("", "ERRORED TOOLS");
550
- erroredTools.forEach((tool, index) => lines.push(`${index + 1}. ${tool.id}${tool.message ? ` — ${tool.message}` : ` — ${tool.status}`}`));
948
+ const suppressionLines = (0, suppressions_1.renderSuppressionLines)(scan.suppressions);
949
+ if (suppressionLines.length > 0) {
950
+ lines.push("", "ACKNOWLEDGED", ...suppressionLines);
551
951
  }
552
952
  if (scan.recoveryActions.length > 0) {
553
953
  lines.push("", "RECOVER BEFORE EDITING");