@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
@@ -0,0 +1,367 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.defaultRelevanceConfig = void 0;
7
+ exports.computePriority = computePriority;
8
+ exports.applyRelevance = applyRelevance;
9
+ exports.renderRelevanceLines = renderRelevanceLines;
10
+ const node_fs_1 = require("node:fs");
11
+ const node_path_1 = __importDefault(require("node:path"));
12
+ const credentialHeuristics_1 = require("./credentialHeuristics");
13
+ const fileRole_1 = require("./fileRole");
14
+ exports.defaultRelevanceConfig = {
15
+ enabled: true,
16
+ minConfidence: "low",
17
+ maxFindingsPerTool: 200,
18
+ maxFindingsTotal: 1000,
19
+ syntheticFilePolicy: "downgrade",
20
+ validateSecrets: true,
21
+ perTool: {
22
+ // Whole-repository dead-code guessing produces far more candidates than
23
+ // anyone can triage, and its own confidence percentage is the best available
24
+ // ranking signal. Report the defensible subset and say how many were held.
25
+ vulture: { minConfidence: "medium", maxFindings: 50 },
26
+ // Type-checkers report accumulated debt in full. The ranking below puts new
27
+ // and changed-file findings first; the cap keeps the tail out of the report.
28
+ pyright: { maxFindings: 150 },
29
+ tsc: { maxFindings: 150 },
30
+ // Duplication and complexity are advisory, and the top offenders are the
31
+ // only actionable ones.
32
+ jscpd: { maxFindings: 50 },
33
+ lizard: { maxFindings: 50 },
34
+ radon: { maxFindings: 50 }
35
+ }
36
+ };
37
+ const confidenceRank = { low: 0, medium: 1, high: 2 };
38
+ const severityRank = { info: 0, low: 1, medium: 2, high: 3, critical: 4 };
39
+ const evidenceGradeRank = { unproven: 0, heuristic: 1, observed: 2, verified: 3 };
40
+ const severityOrder = ["info", "low", "medium", "high", "critical"];
41
+ function downgradeSeverity(severity, steps = 1) {
42
+ return severityOrder[Math.max(0, severityRank[severity] - steps)];
43
+ }
44
+ class ToolLedger {
45
+ reported = 0;
46
+ adjusted = 0;
47
+ withheld = new Map();
48
+ record({ reason, detail, remediation }) {
49
+ const key = `${reason}:${detail}`;
50
+ const existing = this.withheld.get(key);
51
+ if (existing) {
52
+ existing.count += 1;
53
+ return;
54
+ }
55
+ this.withheld.set(key, { reason, count: 1, detail, remediation });
56
+ }
57
+ toResult(tool, surfaced) {
58
+ return {
59
+ tool,
60
+ reported: this.reported,
61
+ surfaced,
62
+ adjusted: this.adjusted,
63
+ withheld: Array.from(this.withheld.values()).sort((left, right) => right.count - left.count)
64
+ };
65
+ }
66
+ }
67
+ /**
68
+ * Ranks a finding by how much it deserves a reader's attention. Severity leads,
69
+ * but a new finding in code the author just touched outranks an older, nominally
70
+ * more severe one they cannot act on right now.
71
+ */
72
+ function computePriority(finding) {
73
+ let priority = severityRank[finding.severity] * 10;
74
+ priority += confidenceRank[finding.confidence] * 3;
75
+ priority += evidenceGradeRank[finding.evidenceGrade ?? "observed"] * 3;
76
+ if (finding.isNew) {
77
+ priority += 8;
78
+ }
79
+ if (finding.inChangedFile) {
80
+ priority += 6;
81
+ }
82
+ if (finding.baselineState === "resurfaced") {
83
+ priority += 5;
84
+ }
85
+ priority += Math.min(3, finding.corroboratedBy?.length ?? 0) * 4;
86
+ if (finding.fileRole && (0, fileRole_1.isSyntheticRole)(finding.fileRole)) {
87
+ priority -= 8;
88
+ }
89
+ if (finding.evidence?.reviewState === "false_positive") {
90
+ priority -= 20;
91
+ }
92
+ if (finding.isAutofixable && finding.safeToAutofix) {
93
+ priority += 2;
94
+ }
95
+ return priority;
96
+ }
97
+ function createLineReader(root) {
98
+ const cache = new Map();
99
+ return async (file, line) => {
100
+ if (!cache.has(file)) {
101
+ try {
102
+ cache.set(file, (await node_fs_1.promises.readFile(node_path_1.default.join(root, file), "utf8")).split(/\r?\n/));
103
+ }
104
+ catch {
105
+ cache.set(file, undefined);
106
+ }
107
+ }
108
+ return cache.get(file)?.[line - 1];
109
+ };
110
+ }
111
+ function isSecretClaim(finding) {
112
+ return (finding.tags.includes("secret") ||
113
+ finding.source === "gitleaks" ||
114
+ /secret|credential|api[- _]?key|token|password/i.test(finding.title));
115
+ }
116
+ /**
117
+ * Re-examines findings that claim to have found a credential. Scanners redact
118
+ * their own output, so the source line the finding points at is the only place
119
+ * the matched value can still be evaluated.
120
+ */
121
+ async function validateSecretClaim(finding, readLine) {
122
+ if (!finding.file || finding.startLine === undefined) {
123
+ return finding;
124
+ }
125
+ const line = await readLine(finding.file, finding.startLine);
126
+ const candidate = (0, credentialHeuristics_1.extractAssignedValue)(line);
127
+ const assessment = (0, credentialHeuristics_1.assessCredential)(candidate);
128
+ if (assessment.verdict === "credential" || assessment.verdict === "unknown") {
129
+ return assessment.verdict === "credential"
130
+ ? {
131
+ ...finding,
132
+ evidenceGrade: "verified",
133
+ evidence: {
134
+ ...finding.evidence,
135
+ rationale: assessment.reason,
136
+ confidenceScore: Number(assessment.entropy.toFixed(2))
137
+ }
138
+ }
139
+ : finding;
140
+ }
141
+ const isPlaceholder = assessment.verdict === "placeholder";
142
+ return {
143
+ ...finding,
144
+ // Still reported, because a scanner match is a fact worth showing — but not
145
+ // at a severity that implies a live credential is in the repository.
146
+ severity: isPlaceholder ? "info" : downgradeSeverity(finding.severity, 2),
147
+ confidence: "low",
148
+ evidenceGrade: "heuristic",
149
+ title: isPlaceholder ? `${finding.title} (placeholder value)` : `${finding.title} (likely not a credential)`,
150
+ message: `${finding.message} Contextual check: ${assessment.reason}`,
151
+ tags: Array.from(new Set([...finding.tags, "likely-false-positive"])),
152
+ evidence: {
153
+ ...finding.evidence,
154
+ reviewState: "false_positive",
155
+ rationale: assessment.reason,
156
+ maskedValue: (0, credentialHeuristics_1.maskValue)(candidate),
157
+ confidenceScore: Number(assessment.entropy.toFixed(2))
158
+ },
159
+ remediation: {
160
+ kind: "human_review",
161
+ steps: [
162
+ "Confirm the matched value is not a credential.",
163
+ `Add an acknowledgement for rule "${finding.title}" in .vibedoctor/suppressions.yml to stop reporting it.`
164
+ ],
165
+ requiredEvidence: "Confirmation that the value is an identifier rather than a credential."
166
+ }
167
+ };
168
+ }
169
+ function syntheticNote(role) {
170
+ switch (role) {
171
+ case "fixture":
172
+ return "test fixture";
173
+ case "test":
174
+ return "test file";
175
+ case "generated":
176
+ return "generated file";
177
+ case "vendor":
178
+ return "vendored dependency";
179
+ default:
180
+ return role;
181
+ }
182
+ }
183
+ /**
184
+ * Applies relevance controls to the deduped finding set. Runs after dedupe so
185
+ * corroboration between tools is already recorded, and after the baseline so
186
+ * new-versus-existing can drive ranking.
187
+ */
188
+ async function applyRelevance(findings, options) {
189
+ const { config } = options;
190
+ const ledgers = new Map();
191
+ function ledgerFor(tool) {
192
+ const existing = ledgers.get(tool);
193
+ if (existing) {
194
+ return existing;
195
+ }
196
+ const created = new ToolLedger();
197
+ ledgers.set(tool, created);
198
+ return created;
199
+ }
200
+ for (const finding of findings) {
201
+ ledgerFor(finding.source).reported += 1;
202
+ }
203
+ if (!config.enabled) {
204
+ const ranked = findings.map((finding) => ({ ...finding, priority: computePriority(finding) }));
205
+ return {
206
+ findings: ranked,
207
+ report: {
208
+ enabled: false,
209
+ perTool: Array.from(ledgers.entries()).map(([tool, ledger]) => ledger.toResult(tool, ranked.filter((finding) => finding.source === tool).length)),
210
+ totalReported: findings.length,
211
+ totalSurfaced: ranked.length,
212
+ notes: ["Relevance filtering is disabled; every finding every tool reported is included."]
213
+ }
214
+ };
215
+ }
216
+ const readLine = createLineReader(options.root);
217
+ const kept = [];
218
+ for (const original of findings) {
219
+ const policy = config.perTool[original.source] ?? {};
220
+ const ledger = ledgerFor(original.source);
221
+ let finding = original;
222
+ if (config.validateSecrets && isSecretClaim(finding)) {
223
+ const validated = await validateSecretClaim(finding, readLine);
224
+ if (validated !== finding) {
225
+ ledger.adjusted += 1;
226
+ finding = validated;
227
+ }
228
+ }
229
+ const role = finding.fileRole ?? "unknown";
230
+ if ((0, fileRole_1.isSyntheticRole)(role)) {
231
+ if (config.syntheticFilePolicy === "drop") {
232
+ ledger.record({
233
+ reason: "synthetic_file",
234
+ detail: `in a ${syntheticNote(role)}`,
235
+ remediation: "Set relevance.synthetic_file_policy: downgrade in vibedoctor.yml to include these."
236
+ });
237
+ continue;
238
+ }
239
+ if (config.syntheticFilePolicy === "downgrade") {
240
+ finding = {
241
+ ...finding,
242
+ severity: downgradeSeverity(finding.severity),
243
+ tags: Array.from(new Set([...finding.tags, `role:${role}`]))
244
+ };
245
+ ledger.adjusted += 1;
246
+ }
247
+ }
248
+ const floor = policy.minConfidence ?? config.minConfidence;
249
+ if (confidenceRank[finding.confidence] < confidenceRank[floor]) {
250
+ ledger.record({
251
+ reason: "below_confidence_floor",
252
+ detail: `${finding.confidence} confidence, below the ${floor} floor for ${finding.source}`,
253
+ remediation: `Lower relevance.per_tool.${finding.source}.min_confidence in vibedoctor.yml to see these.`
254
+ });
255
+ continue;
256
+ }
257
+ if (policy.minEvidenceGrade) {
258
+ const grade = finding.evidenceGrade ?? "observed";
259
+ if (evidenceGradeRank[grade] < evidenceGradeRank[policy.minEvidenceGrade]) {
260
+ ledger.record({
261
+ reason: "below_evidence_floor",
262
+ detail: `${grade} evidence, below the ${policy.minEvidenceGrade} floor for ${finding.source}`,
263
+ remediation: `Lower relevance.per_tool.${finding.source}.min_evidence_grade in vibedoctor.yml to see these.`
264
+ });
265
+ continue;
266
+ }
267
+ }
268
+ if (policy.requireCorroboration && (finding.corroboratedBy?.length ?? 0) === 0) {
269
+ ledger.record({
270
+ reason: "not_corroborated",
271
+ detail: `only ${finding.source} reported it, and ${finding.source} findings require corroboration`,
272
+ remediation: `Set relevance.per_tool.${finding.source}.require_corroboration: false in vibedoctor.yml to see these.`
273
+ });
274
+ continue;
275
+ }
276
+ kept.push({ ...finding, priority: computePriority(finding) });
277
+ }
278
+ // Cap per tool, keeping the highest-ranked. A cap is a reading-order decision,
279
+ // so what falls outside it is reported as a count rather than dropped quietly.
280
+ const byTool = new Map();
281
+ for (const finding of kept) {
282
+ const bucket = byTool.get(finding.source) ?? [];
283
+ bucket.push(finding);
284
+ byTool.set(finding.source, bucket);
285
+ }
286
+ const capped = [];
287
+ for (const [tool, bucket] of byTool) {
288
+ const limit = config.perTool[tool]?.maxFindings ?? config.maxFindingsPerTool;
289
+ bucket.sort((left, right) => (right.priority ?? 0) - (left.priority ?? 0));
290
+ if (limit > 0 && bucket.length > limit) {
291
+ const ledger = ledgerFor(tool);
292
+ for (let index = limit; index < bucket.length; index += 1) {
293
+ ledger.record({
294
+ reason: "over_tool_cap",
295
+ detail: `beyond the ${limit}-finding cap for ${tool}, ranked by severity, novelty, and evidence`,
296
+ remediation: `Raise relevance.per_tool.${tool}.max_findings in vibedoctor.yml, or run \`vibedoctor scan --category <category>\` to see the full set.`
297
+ });
298
+ }
299
+ capped.push(...bucket.slice(0, limit));
300
+ continue;
301
+ }
302
+ capped.push(...bucket);
303
+ }
304
+ capped.sort((left, right) => (right.priority ?? 0) - (left.priority ?? 0));
305
+ let surfaced = capped;
306
+ if (config.maxFindingsTotal > 0 && capped.length > config.maxFindingsTotal) {
307
+ for (const finding of capped.slice(config.maxFindingsTotal)) {
308
+ ledgerFor(finding.source).record({
309
+ reason: "over_total_cap",
310
+ detail: `beyond the ${config.maxFindingsTotal}-finding report cap`,
311
+ remediation: "Raise relevance.max_findings_total in vibedoctor.yml, or filter with `vibedoctor scan --category`."
312
+ });
313
+ }
314
+ surfaced = capped.slice(0, config.maxFindingsTotal);
315
+ }
316
+ const perTool = Array.from(ledgers.entries())
317
+ .map(([tool, ledger]) => ledger.toResult(tool, surfaced.filter((finding) => finding.source === tool).length))
318
+ .sort((left, right) => left.tool.localeCompare(right.tool));
319
+ return {
320
+ findings: surfaced,
321
+ report: {
322
+ enabled: true,
323
+ perTool,
324
+ totalReported: findings.length,
325
+ totalSurfaced: surfaced.length,
326
+ notes: buildRelevanceNotes(perTool)
327
+ }
328
+ };
329
+ }
330
+ function buildRelevanceNotes(perTool) {
331
+ const notes = [];
332
+ for (const tool of perTool) {
333
+ const withheldTotal = tool.withheld.reduce((sum, group) => sum + group.count, 0);
334
+ if (withheldTotal === 0) {
335
+ continue;
336
+ }
337
+ const breakdown = tool.withheld.map((group) => `${group.count} ${group.detail}`).join("; ");
338
+ notes.push(`${tool.tool}: showing ${tool.surfaced} of ${tool.reported} — withheld ${breakdown}.`);
339
+ }
340
+ return notes;
341
+ }
342
+ function renderRelevanceLines(report) {
343
+ if (!report.enabled) {
344
+ return ["Relevance filtering: disabled (all findings shown)."];
345
+ }
346
+ const withheld = report.totalReported - report.totalSurfaced;
347
+ if (withheld === 0 && report.perTool.every((tool) => tool.adjusted === 0)) {
348
+ return [];
349
+ }
350
+ const lines = [`Relevance: showing ${report.totalSurfaced} of ${report.totalReported} findings.`];
351
+ if (report.scopeNote) {
352
+ lines.push(`- ${report.scopeNote}`);
353
+ }
354
+ lines.push(...report.notes.map((note) => `- ${note}`));
355
+ const adjusted = report.perTool.filter((tool) => tool.adjusted > 0);
356
+ if (adjusted.length > 0) {
357
+ lines.push(`- Adjusted (severity or confidence changed after contextual checks): ${adjusted
358
+ .map((tool) => `${tool.tool} ${tool.adjusted}`)
359
+ .join(", ")}.`);
360
+ }
361
+ const remediations = Array.from(new Set(report.perTool.flatMap((tool) => tool.withheld.map((group) => group.remediation))));
362
+ if (remediations.length > 0) {
363
+ lines.push("To see withheld findings:");
364
+ lines.push(...remediations.map((remediation) => `- ${remediation}`));
365
+ }
366
+ return lines;
367
+ }
@@ -1,10 +1,22 @@
1
1
  import type { ToolAdapter } from "../adapters/shared";
2
+ import type { CapabilityState } from "./capability";
2
3
  import type { VibeDoctorConfig } from "./config";
3
4
  import type { ProjectContext } from "./projectDetector";
4
5
  export type ScanMode = "default" | "changed" | "quick" | "full";
6
+ /** A tool that will not run, and the reason, so the report can say so explicitly. */
7
+ export type ExcludedTool = {
8
+ id: string;
9
+ state: Extract<CapabilityState, "disabled" | "not_applicable" | "not_selected" | "deferred">;
10
+ reason: string;
11
+ };
5
12
  export type ScanPlan = {
6
13
  mode: ScanMode;
7
14
  adapterIds: string[];
15
+ /**
16
+ * Tools deliberately left out. Previously these vanished from the plan, which
17
+ * meant a check that never ran was indistinguishable from one that passed.
18
+ */
19
+ excluded: ExcludedTool[];
8
20
  changedOnly: boolean;
9
21
  outputFull: boolean;
10
22
  };
@@ -1,50 +1,82 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createScanPlan = createScanPlan;
4
+ const QUICK_ADAPTER_IDS = new Set([
5
+ "ruff",
6
+ "biome",
7
+ "tsc",
8
+ "pyright",
9
+ "gitleaks",
10
+ "osv-scanner",
11
+ "privacy-detector",
12
+ "dpdp",
13
+ "custom-leftovers"
14
+ ]);
15
+ /** The config switch that governs each category, and the name to report. */
16
+ function disabledReason(adapter, config) {
17
+ const { checks } = config;
18
+ switch (adapter.category) {
19
+ case "security":
20
+ return checks.security.enabled ? undefined : "checks.security.enabled is false";
21
+ case "correctness":
22
+ return checks.correctness.enabled ? undefined : "checks.correctness.enabled is false";
23
+ case "dead_code":
24
+ return checks.deadCode.enabled ? undefined : "checks.deadCode.enabled is false";
25
+ case "leftovers":
26
+ return checks.leftovers.enabled ? undefined : "checks.leftovers.enabled is false";
27
+ case "refactor_readiness":
28
+ return checks.refactorReadiness.enabled ? undefined : "checks.refactorReadiness.enabled is false";
29
+ case "dependencies":
30
+ return checks.dependencies.enabled ? undefined : "checks.dependencies.enabled is false";
31
+ case "privacy":
32
+ if (adapter.id === "dpdp") {
33
+ return checks.dpdp.enabled ? undefined : "checks.dpdp.enabled is false";
34
+ }
35
+ return checks.privacy.enabled ? undefined : "checks.privacy.enabled is false";
36
+ default:
37
+ return undefined;
38
+ }
39
+ }
4
40
  async function createScanPlan(project, config, adapters, mode) {
5
41
  const selected = [];
6
- const quickAdapterIds = new Set([
7
- "ruff",
8
- "biome",
9
- "tsc",
10
- "pyright",
11
- "gitleaks",
12
- "osv-scanner",
13
- "privacy-detector",
14
- "custom-leftovers"
15
- ]);
42
+ const excluded = [];
43
+ const deferred = new Set(config.runtime.deferredTools);
16
44
  for (const adapter of adapters) {
17
- if (adapter.category === "security" && !config.checks.security.enabled) {
18
- continue;
19
- }
20
- if (adapter.category === "correctness" && !config.checks.correctness.enabled) {
21
- continue;
22
- }
23
- if (adapter.category === "dead_code" && !config.checks.deadCode.enabled) {
45
+ const disabled = disabledReason(adapter, config);
46
+ if (disabled) {
47
+ excluded.push({ id: adapter.id, state: "disabled", reason: `Turned off in config: ${disabled}.` });
24
48
  continue;
25
49
  }
26
- if (adapter.category === "leftovers" && !config.checks.leftovers.enabled) {
50
+ if (deferred.has(adapter.id)) {
51
+ excluded.push({
52
+ id: adapter.id,
53
+ state: "deferred",
54
+ reason: "Listed in runtime.deferred_tools, so it was deliberately not run."
55
+ });
27
56
  continue;
28
57
  }
29
- if (adapter.category === "refactor_readiness" && !config.checks.refactorReadiness.enabled) {
58
+ if (mode === "quick" && !QUICK_ADAPTER_IDS.has(adapter.id)) {
59
+ excluded.push({
60
+ id: adapter.id,
61
+ state: "not_selected",
62
+ reason: "Not part of the quick profile. Run `vibedoctor scan --full` to include it."
63
+ });
30
64
  continue;
31
65
  }
32
- if (adapter.category === "dependencies" && !config.checks.dependencies.enabled) {
66
+ if (!(await adapter.detect(project, config))) {
67
+ excluded.push({
68
+ id: adapter.id,
69
+ state: "not_applicable",
70
+ reason: `Nothing in this repository matches what ${adapter.id} analyses (language, lockfile, or config not present).`
71
+ });
33
72
  continue;
34
73
  }
35
- if (adapter.category === "privacy" && !config.checks.privacy.enabled) {
36
- continue;
37
- }
38
- if (mode === "quick" && !quickAdapterIds.has(adapter.id)) {
39
- continue;
40
- }
41
- if (await adapter.detect(project, config)) {
42
- selected.push(adapter.id);
43
- }
74
+ selected.push(adapter.id);
44
75
  }
45
76
  return {
46
77
  mode,
47
78
  adapterIds: selected,
79
+ excluded,
48
80
  changedOnly: mode === "changed",
49
81
  outputFull: mode === "full"
50
82
  };
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Minimal semver comparison and range satisfaction.
3
+ *
4
+ * VibeDoctor needs to answer one question in several places: "is the runtime we
5
+ * are about to hand a tool new enough for what that tool declares it needs?".
6
+ * The declared requirement comes from arbitrary package metadata
7
+ * (`engines.node`, `requires-python`), so it can use any of the common range
8
+ * shapes. Pulling in the full `semver` package for that would add a runtime
9
+ * dependency to a CLI that currently has three; this covers the shapes real
10
+ * engine fields use and reports "unknown" instead of guessing on anything else.
11
+ */
12
+ export type SemVersion = {
13
+ major: number;
14
+ minor: number;
15
+ patch: number;
16
+ prerelease?: string;
17
+ };
18
+ export declare function parseVersion(value: string | undefined): SemVersion | undefined;
19
+ export declare function formatVersion(version: SemVersion): string;
20
+ export declare function compareVersions(left: SemVersion, right: SemVersion): number;
21
+ /**
22
+ * Returns `undefined` when the range uses syntax this module does not model, so
23
+ * callers can report "could not verify" rather than a false pass or fail.
24
+ */
25
+ export declare function satisfiesRange(version: SemVersion, range: string | undefined): boolean | undefined;
26
+ /** The lowest version that could satisfy the range, for "you need at least X" messages. */
27
+ export declare function minimumSatisfying(range: string | undefined): string | undefined;
@@ -0,0 +1,163 @@
1
+ "use strict";
2
+ /**
3
+ * Minimal semver comparison and range satisfaction.
4
+ *
5
+ * VibeDoctor needs to answer one question in several places: "is the runtime we
6
+ * are about to hand a tool new enough for what that tool declares it needs?".
7
+ * The declared requirement comes from arbitrary package metadata
8
+ * (`engines.node`, `requires-python`), so it can use any of the common range
9
+ * shapes. Pulling in the full `semver` package for that would add a runtime
10
+ * dependency to a CLI that currently has three; this covers the shapes real
11
+ * engine fields use and reports "unknown" instead of guessing on anything else.
12
+ */
13
+ Object.defineProperty(exports, "__esModule", { value: true });
14
+ exports.parseVersion = parseVersion;
15
+ exports.formatVersion = formatVersion;
16
+ exports.compareVersions = compareVersions;
17
+ exports.satisfiesRange = satisfiesRange;
18
+ exports.minimumSatisfying = minimumSatisfying;
19
+ const VERSION_PATTERN = /(\d+)(?:\.(\d+))?(?:\.(\d+))?(?:[-+]([0-9A-Za-z.-]+))?/;
20
+ function parseVersion(value) {
21
+ if (!value) {
22
+ return undefined;
23
+ }
24
+ const match = VERSION_PATTERN.exec(value.trim());
25
+ if (!match) {
26
+ return undefined;
27
+ }
28
+ return {
29
+ major: Number(match[1]),
30
+ minor: Number(match[2] ?? 0),
31
+ patch: Number(match[3] ?? 0),
32
+ prerelease: match[4]
33
+ };
34
+ }
35
+ function formatVersion(version) {
36
+ const base = `${version.major}.${version.minor}.${version.patch}`;
37
+ return version.prerelease ? `${base}-${version.prerelease}` : base;
38
+ }
39
+ function compareVersions(left, right) {
40
+ if (left.major !== right.major) {
41
+ return left.major - right.major;
42
+ }
43
+ if (left.minor !== right.minor) {
44
+ return left.minor - right.minor;
45
+ }
46
+ if (left.patch !== right.patch) {
47
+ return left.patch - right.patch;
48
+ }
49
+ // A prerelease sorts below its own release (1.0.0-rc < 1.0.0).
50
+ if (left.prerelease && !right.prerelease) {
51
+ return -1;
52
+ }
53
+ if (!left.prerelease && right.prerelease) {
54
+ return 1;
55
+ }
56
+ return 0;
57
+ }
58
+ function comparatorsFor(token) {
59
+ const trimmed = token.trim().replace(/^v/, "");
60
+ if (!trimmed || trimmed === "*" || trimmed === "latest") {
61
+ return [];
62
+ }
63
+ const caret = /^\^\s*(.+)$/.exec(trimmed);
64
+ if (caret) {
65
+ const version = parseVersion(caret[1]);
66
+ if (!version) {
67
+ return undefined;
68
+ }
69
+ const upper = version.major > 0
70
+ ? { major: version.major + 1, minor: 0, patch: 0 }
71
+ : version.minor > 0
72
+ ? { major: 0, minor: version.minor + 1, patch: 0 }
73
+ : { major: 0, minor: version.minor, patch: version.patch + 1 };
74
+ return [
75
+ { operator: ">=", version },
76
+ { operator: "<", version: upper }
77
+ ];
78
+ }
79
+ const tilde = /^~\s*(.+)$/.exec(trimmed);
80
+ if (tilde) {
81
+ const version = parseVersion(tilde[1]);
82
+ if (!version) {
83
+ return undefined;
84
+ }
85
+ return [
86
+ { operator: ">=", version },
87
+ { operator: "<", version: { major: version.major, minor: version.minor + 1, patch: 0 } }
88
+ ];
89
+ }
90
+ const explicit = /^(>=|<=|>|<|=)\s*(.+)$/.exec(trimmed);
91
+ if (explicit) {
92
+ const version = parseVersion(explicit[2]);
93
+ if (!version) {
94
+ return undefined;
95
+ }
96
+ return [{ operator: explicit[1], version }];
97
+ }
98
+ const exact = parseVersion(trimmed);
99
+ return exact ? [{ operator: ">=", version: exact }] : undefined;
100
+ }
101
+ function satisfiesComparator(version, comparator) {
102
+ const delta = compareVersions(version, comparator.version);
103
+ switch (comparator.operator) {
104
+ case ">=":
105
+ return delta >= 0;
106
+ case ">":
107
+ return delta > 0;
108
+ case "<=":
109
+ return delta <= 0;
110
+ case "<":
111
+ return delta < 0;
112
+ case "=":
113
+ return delta === 0;
114
+ }
115
+ }
116
+ /**
117
+ * Returns `undefined` when the range uses syntax this module does not model, so
118
+ * callers can report "could not verify" rather than a false pass or fail.
119
+ */
120
+ function satisfiesRange(version, range) {
121
+ if (!range || !range.trim()) {
122
+ return true;
123
+ }
124
+ const alternatives = range.split("||");
125
+ let anyUnderstood = false;
126
+ for (const alternative of alternatives) {
127
+ const tokens = alternative.trim().split(/\s+/).filter(Boolean);
128
+ const comparators = [];
129
+ let understood = true;
130
+ for (const token of tokens) {
131
+ const parsed = comparatorsFor(token);
132
+ if (!parsed) {
133
+ understood = false;
134
+ break;
135
+ }
136
+ comparators.push(...parsed);
137
+ }
138
+ if (!understood) {
139
+ continue;
140
+ }
141
+ anyUnderstood = true;
142
+ if (comparators.every((comparator) => satisfiesComparator(version, comparator))) {
143
+ return true;
144
+ }
145
+ }
146
+ return anyUnderstood ? false : undefined;
147
+ }
148
+ /** The lowest version that could satisfy the range, for "you need at least X" messages. */
149
+ function minimumSatisfying(range) {
150
+ if (!range) {
151
+ return undefined;
152
+ }
153
+ const candidates = range
154
+ .split("||")
155
+ .flatMap((alternative) => alternative.trim().split(/\s+/).filter(Boolean))
156
+ .flatMap((token) => comparatorsFor(token) ?? [])
157
+ .filter((comparator) => comparator.operator === ">=" || comparator.operator === ">")
158
+ .map((comparator) => comparator.version);
159
+ if (candidates.length === 0) {
160
+ return undefined;
161
+ }
162
+ return formatVersion(candidates.sort(compareVersions)[0]);
163
+ }