@neuralaxis/vibedoctor 0.2.0 → 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 (52) hide show
  1. package/README.md +86 -0
  2. package/dist/adapters/biome.js +135 -21
  3. package/dist/adapters/osvScanner.js +136 -17
  4. package/dist/adapters/presidio.js +3 -1
  5. package/dist/cli/commands/init.js +105 -50
  6. package/dist/cli/commands/privacyReview.js +3 -4
  7. package/dist/cli/commands/setup.d.ts +13 -17
  8. package/dist/cli/commands/setup.js +138 -200
  9. package/dist/core/capability.d.ts +92 -0
  10. package/dist/core/capability.js +122 -0
  11. package/dist/core/config.d.ts +36 -0
  12. package/dist/core/config.js +105 -3
  13. package/dist/core/credentialHeuristics.d.ts +28 -0
  14. package/dist/core/credentialHeuristics.js +179 -0
  15. package/dist/core/engine.d.ts +21 -0
  16. package/dist/core/engine.js +466 -85
  17. package/dist/core/executable.d.ts +18 -0
  18. package/dist/core/executable.js +137 -0
  19. package/dist/core/fileRole.d.ts +24 -0
  20. package/dist/core/fileRole.js +125 -0
  21. package/dist/core/finding.d.ts +124 -0
  22. package/dist/core/finding.js +62 -5
  23. package/dist/core/findingNormalizer.d.ts +33 -0
  24. package/dist/core/findingNormalizer.js +171 -0
  25. package/dist/core/projectDetector.d.ts +13 -0
  26. package/dist/core/projectDetector.js +100 -15
  27. package/dist/core/relevance.d.ts +87 -0
  28. package/dist/core/relevance.js +367 -0
  29. package/dist/core/scanPlanner.d.ts +12 -0
  30. package/dist/core/scanPlanner.js +61 -37
  31. package/dist/core/semverLite.d.ts +27 -0
  32. package/dist/core/semverLite.js +163 -0
  33. package/dist/core/suppressions.d.ts +96 -0
  34. package/dist/core/suppressions.js +302 -0
  35. package/dist/core/toolRegistry.d.ts +58 -0
  36. package/dist/core/toolRegistry.js +247 -0
  37. package/dist/core/toolRunner.d.ts +23 -2
  38. package/dist/core/toolRunner.js +61 -93
  39. package/dist/core/toolVerification.d.ts +87 -0
  40. package/dist/core/toolVerification.js +370 -0
  41. package/dist/dpdp/collectors/optionalScanners.js +120 -30
  42. package/dist/dpdp/findings.d.ts +33 -3
  43. package/dist/dpdp/findings.js +191 -4
  44. package/dist/dpdp/scan.js +2 -2
  45. package/dist/dpdp/scoring.d.ts +14 -4
  46. package/dist/dpdp/scoring.js +34 -8
  47. package/dist/dpdp/types.d.ts +19 -1
  48. package/dist/reporters/html.js +57 -13
  49. package/dist/reporters/json.js +7 -1
  50. package/dist/reporters/markdown.js +46 -4
  51. package/dist/reporters/sarif.js +54 -5
  52. package/package.json +1 -1
@@ -0,0 +1,370 @@
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.isVerificationBlocking = isVerificationBlocking;
7
+ exports.probeRuntime = probeRuntime;
8
+ exports.probeRuntimes = probeRuntimes;
9
+ exports.probeRuntimesFor = probeRuntimesFor;
10
+ exports.verifyTool = verifyTool;
11
+ exports.verifyTools = verifyTools;
12
+ exports.summarizeVerification = summarizeVerification;
13
+ exports.formatVersionForDisplay = formatVersionForDisplay;
14
+ const node_fs_1 = require("node:fs");
15
+ const node_path_1 = __importDefault(require("node:path"));
16
+ const executable_1 = require("./executable");
17
+ const semverLite_1 = require("./semverLite");
18
+ const toolRegistry_1 = require("./toolRegistry");
19
+ const toolRunner_1 = require("./toolRunner");
20
+ function isVerificationBlocking(verification) {
21
+ return verification.state === "not_found" || verification.state === "broken" || verification.state === "incompatible_runtime";
22
+ }
23
+ const DEFAULT_VERSION_PATTERN = /\b(\d+\.\d+(?:\.\d+)?(?:[-+][0-9A-Za-z.-]+)?)\b/;
24
+ function extractVersion(output, pattern) {
25
+ const match = (pattern ?? DEFAULT_VERSION_PATTERN).exec(output);
26
+ return match?.[1] ?? match?.[0];
27
+ }
28
+ // Generous, because some tools are genuinely slow to start: reporting a working
29
+ // tool as broken because it took 31 seconds to print its version would be worse
30
+ // than waiting.
31
+ const PROBE_TIMEOUT_MS = 90_000;
32
+ /** Candidate interpreter command names, in the order the scanner would find them. */
33
+ const RUNTIME_COMMANDS = {
34
+ node: ["node"],
35
+ python: ["python", "python3", "py"]
36
+ };
37
+ /**
38
+ * Locates a language runtime once per process. `python` being absent is the
39
+ * reason a whole family of installs silently fails, so it is reported as a
40
+ * first-class fact rather than inferred from a tool-level error message.
41
+ */
42
+ async function probeRuntime(engine, cwd) {
43
+ if (engine === "node") {
44
+ // We are running on Node, so the version that matters is this process's.
45
+ const resolved = (0, executable_1.resolveExecutable)("node", cwd);
46
+ return {
47
+ engine,
48
+ available: true,
49
+ command: "node",
50
+ resolvedPath: resolved?.path ?? process.execPath,
51
+ version: process.versions.node,
52
+ detail: `Node ${process.versions.node} at ${resolved?.path ?? process.execPath}`
53
+ };
54
+ }
55
+ for (const command of RUNTIME_COMMANDS[engine]) {
56
+ const resolved = (0, executable_1.resolveExecutable)(command, cwd);
57
+ if (!resolved) {
58
+ continue;
59
+ }
60
+ const result = await (0, toolRunner_1.runCommand)({ cmd: command, args: ["--version"], cwd, timeoutMs: PROBE_TIMEOUT_MS });
61
+ if (result.status !== "ok") {
62
+ continue;
63
+ }
64
+ const version = extractVersion(`${result.stdout}\n${result.stderr}`, undefined);
65
+ return {
66
+ engine,
67
+ available: true,
68
+ command,
69
+ resolvedPath: resolved.path,
70
+ version,
71
+ detail: `${command} ${version ?? "(unknown version)"} at ${resolved.path}`
72
+ };
73
+ }
74
+ return {
75
+ engine,
76
+ available: false,
77
+ detail: `No ${engine} interpreter found on PATH (tried ${RUNTIME_COMMANDS[engine].join(", ")}).`
78
+ };
79
+ }
80
+ async function probeRuntimes(cwd, engines) {
81
+ const unique = Array.from(new Set(engines));
82
+ const probes = await Promise.all(unique.map(async (engine) => [engine, await probeRuntime(engine, cwd)]));
83
+ return Object.fromEntries(probes);
84
+ }
85
+ /**
86
+ * Probes only the runtimes that a tool present on this machine actually needs.
87
+ *
88
+ * Probing every runtime a registry entry mentions meant spawning a Python
89
+ * interpreter on repositories with no Python tooling installed, on every scan.
90
+ */
91
+ async function probeRuntimesFor(entries, cwd, depth = "execute") {
92
+ const engines = new Set();
93
+ for (const entry of entries) {
94
+ if (entry.moduleProbe && depth === "execute") {
95
+ engines.add(entry.moduleProbe.runtime);
96
+ continue;
97
+ }
98
+ if (!entry.runtime || !entry.executable) {
99
+ continue;
100
+ }
101
+ // Node compatibility is free — this process is the runtime — so it is always
102
+ // worth knowing. Other runtimes cost a spawn, so only ask when the tool that
103
+ // needs one is actually installed.
104
+ if (entry.runtime === "node" || (0, executable_1.resolveExecutable)(entry.executable, cwd)) {
105
+ engines.add(entry.runtime);
106
+ }
107
+ }
108
+ return probeRuntimes(cwd, Array.from(engines));
109
+ }
110
+ async function checkRuntimeCompatibility(root, entry, probes) {
111
+ if (!entry.runtime) {
112
+ return undefined;
113
+ }
114
+ const probe = probes[entry.runtime];
115
+ const { range, source } = entry.ecosystem === "npm" ? await (0, toolRegistry_1.readDeclaredNodeRequirement)(root, entry.packageName) : {};
116
+ if (!probe?.available) {
117
+ return {
118
+ engine: entry.runtime,
119
+ requirement: range,
120
+ requirementSource: source,
121
+ compatible: false
122
+ };
123
+ }
124
+ const version = (0, semverLite_1.parseVersion)(probe.version);
125
+ const satisfied = version ? (0, semverLite_1.satisfiesRange)(version, range) : undefined;
126
+ return {
127
+ engine: entry.runtime,
128
+ version: probe.version,
129
+ requirement: range,
130
+ requirementSource: source,
131
+ compatible: satisfied ?? "unknown"
132
+ };
133
+ }
134
+ function runtimeRemediation(entry, runtime) {
135
+ const needed = (0, semverLite_1.minimumSatisfying)(runtime.requirement);
136
+ const target = needed ? `${runtime.engine} >= ${needed}` : `a newer ${runtime.engine}`;
137
+ return [
138
+ `${entry.id} declares ${runtime.requirement ?? "a newer runtime"}${runtime.requirementSource ? ` (${runtime.requirementSource})` : ""}`,
139
+ `but the active runtime is ${runtime.engine} ${runtime.version ?? "unknown"}.`,
140
+ `Either upgrade to ${target}, run VibeDoctor under a compatible runtime, or set`,
141
+ `runtime.deferred_tools: [${entry.id}] in vibedoctor.yml to defer it deliberately.`
142
+ ].join(" ");
143
+ }
144
+ async function verifyTool(entry, options) {
145
+ const { root, runtimes } = options;
146
+ const depth = options.depth ?? "execute";
147
+ if (entry.ecosystem === "built-in") {
148
+ return {
149
+ id: entry.id,
150
+ state: "verified",
151
+ reason: "Built-in check; no external executable required.",
152
+ version: "built-in"
153
+ };
154
+ }
155
+ const runtime = await checkRuntimeCompatibility(root, entry, runtimes);
156
+ // A tool driven as a module of another runtime (Presidio) has no binary to
157
+ // find; import the module through the interpreter the scanner would use.
158
+ if (entry.moduleProbe) {
159
+ const probe = runtimes[entry.moduleProbe.runtime];
160
+ if (!probe?.available) {
161
+ return {
162
+ id: entry.id,
163
+ state: depth === "resolve" ? "unverifiable" : "not_found",
164
+ reason: depth === "resolve"
165
+ ? `${entry.id} runs as a ${entry.moduleProbe.runtime} module; whether it is importable is determined when it runs.`
166
+ : `${entry.moduleProbe.runtime} interpreter is not available, so ${entry.id} cannot run.`,
167
+ remediation: `Install ${entry.moduleProbe.runtime} and make it available on PATH, then rerun setup.`,
168
+ runtime
169
+ };
170
+ }
171
+ if (depth === "resolve") {
172
+ // Importing the module is expensive enough to matter on every scan, and
173
+ // the adapter reports the same fact when it actually runs.
174
+ return {
175
+ id: entry.id,
176
+ state: "unverifiable",
177
+ interpreterPath: probe.resolvedPath,
178
+ reason: `${entry.id} runs as a ${entry.moduleProbe.runtime} module; its availability is confirmed when the scan invokes it.`,
179
+ runtime
180
+ };
181
+ }
182
+ const args = ["-c", `import ${entry.moduleProbe.module} as m; print(getattr(m, "__version__", "installed"))`];
183
+ const result = await (0, toolRunner_1.runCommand)({ cmd: probe.command, args, cwd: root, timeoutMs: PROBE_TIMEOUT_MS });
184
+ const probeCommand = [probe.command, ...args].join(" ");
185
+ if (result.status !== "ok") {
186
+ return {
187
+ id: entry.id,
188
+ state: result.status === "skipped" ? "not_found" : "broken",
189
+ interpreterPath: probe.resolvedPath,
190
+ probeCommand,
191
+ reason: `${entry.moduleProbe.module} could not be imported by ${probe.resolvedPath ?? probe.command}.`,
192
+ remediation: (0, toolRegistry_1.installHintFor)(entry),
193
+ runtime
194
+ };
195
+ }
196
+ return {
197
+ id: entry.id,
198
+ state: "verified",
199
+ interpreterPath: probe.resolvedPath,
200
+ version: result.stdout.trim() || "installed",
201
+ probeCommand,
202
+ reason: `Imported ${entry.moduleProbe.module} using ${probe.resolvedPath ?? probe.command}.`,
203
+ runtime
204
+ };
205
+ }
206
+ if (!entry.executable) {
207
+ return {
208
+ id: entry.id,
209
+ state: "unverifiable",
210
+ reason: `${entry.id} declares no executable or module probe, so its availability cannot be confirmed.`,
211
+ remediation: "Add a probe to the tool registry so setup can verify this tool.",
212
+ runtime
213
+ };
214
+ }
215
+ const resolved = (0, executable_1.resolveExecutable)(entry.executable, root);
216
+ if (!resolved) {
217
+ const searched = (0, executable_1.describeSearchPaths)(root);
218
+ return {
219
+ id: entry.id,
220
+ state: "not_found",
221
+ reason: `${entry.executable} was not found in any of the ${searched.length} directories on the scanner's PATH.`,
222
+ remediation: (0, toolRegistry_1.installHintFor)(entry),
223
+ runtime
224
+ };
225
+ }
226
+ // Runtime incompatibility is reported before the probe, because a tool that
227
+ // cannot start under this runtime is not "broken" — it is mismatched, and the
228
+ // remediation is completely different.
229
+ if (runtime && runtime.compatible === false) {
230
+ return {
231
+ id: entry.id,
232
+ state: "incompatible_runtime",
233
+ resolvedPath: resolved.path,
234
+ reason: runtime.requirement
235
+ ? `${entry.id} requires ${runtime.engine} ${runtime.requirement} but ${runtime.engine} ${runtime.version ?? "unknown"} is active.`
236
+ : `${entry.id} needs a ${runtime.engine} runtime that is not available.`,
237
+ remediation: runtimeRemediation(entry, runtime),
238
+ runtime
239
+ };
240
+ }
241
+ if (depth === "resolve") {
242
+ return {
243
+ id: entry.id,
244
+ state: "verified",
245
+ resolvedPath: resolved.path,
246
+ reason: `Resolved to ${resolved.path}; the scan invokes this executable directly.`,
247
+ runtime
248
+ };
249
+ }
250
+ const probeArgs = entry.probeArgs ?? ["--version"];
251
+ const result = await (0, toolRunner_1.runCommand)({ cmd: entry.executable, args: probeArgs, cwd: root, timeoutMs: PROBE_TIMEOUT_MS });
252
+ const probeCommand = [entry.executable, ...probeArgs].join(" ");
253
+ const output = `${result.stdout}\n${result.stderr}`;
254
+ if (result.status !== "ok") {
255
+ // A tool present on PATH that cannot answer its own version probe is
256
+ // installed-but-unusable; saying "installed" here is what misled users.
257
+ const unsupportedRuntime = /requires node|unsupported engine|SyntaxError|Unexpected token/i.test(output);
258
+ return {
259
+ id: entry.id,
260
+ state: unsupportedRuntime ? "incompatible_runtime" : "broken",
261
+ resolvedPath: resolved.path,
262
+ probeCommand,
263
+ reason: unsupportedRuntime
264
+ ? `${entry.id} is installed at ${resolved.path} but failed to start under the active runtime.`
265
+ : `${entry.id} is installed at ${resolved.path} but \`${probeCommand}\` exited ${result.exitCode ?? "abnormally"}.`,
266
+ remediation: unsupportedRuntime && runtime ? runtimeRemediation(entry, runtime) : (0, toolRegistry_1.installHintFor)(entry),
267
+ runtime
268
+ };
269
+ }
270
+ return {
271
+ id: entry.id,
272
+ state: "verified",
273
+ resolvedPath: resolved.path,
274
+ version: extractVersion(output, entry.versionPattern),
275
+ probeCommand,
276
+ reason: `Ran \`${probeCommand}\` successfully at ${resolved.path}.`,
277
+ runtime
278
+ };
279
+ }
280
+ const VERIFICATION_CACHE_FILE = ".vibedoctor/tool-verification.json";
281
+ /**
282
+ * Identity of the file that answered the probe. A tool's version output cannot
283
+ * change unless the file does, so this is safe to cache against — and some tools
284
+ * are slow enough to matter: Semgrep takes the better part of a minute just to
285
+ * report its own version.
286
+ */
287
+ function fingerprintFile(filePath) {
288
+ if (!filePath) {
289
+ return undefined;
290
+ }
291
+ try {
292
+ const stats = (0, node_fs_1.statSync)(filePath);
293
+ return `${filePath}:${stats.size}:${Math.round(stats.mtimeMs)}`;
294
+ }
295
+ catch {
296
+ return undefined;
297
+ }
298
+ }
299
+ async function loadVerificationCache(root) {
300
+ try {
301
+ const parsed = JSON.parse(await node_fs_1.promises.readFile(node_path_1.default.join(root, VERIFICATION_CACHE_FILE), "utf8"));
302
+ if (parsed.version !== 1 || !Array.isArray(parsed.entries)) {
303
+ return new Map();
304
+ }
305
+ return new Map(parsed.entries.map((entry) => [entry.id, entry]));
306
+ }
307
+ catch {
308
+ return new Map();
309
+ }
310
+ }
311
+ async function saveVerificationCache(root, entries) {
312
+ try {
313
+ const target = node_path_1.default.join(root, VERIFICATION_CACHE_FILE);
314
+ await node_fs_1.promises.mkdir(node_path_1.default.dirname(target), { recursive: true });
315
+ await node_fs_1.promises.writeFile(target, `${JSON.stringify({ version: 1, entries }, null, 2)}\n`, "utf8");
316
+ }
317
+ catch {
318
+ // A cache that cannot be written only costs time on the next run.
319
+ }
320
+ }
321
+ async function verifyTools(entries, root, depth = "execute") {
322
+ const runtimes = await probeRuntimesFor(entries, root, depth);
323
+ if (depth === "resolve") {
324
+ // Resolution is a filesystem lookup; caching it would only add staleness.
325
+ return Promise.all(entries.map((entry) => verifyTool(entry, { root, runtimes, depth })));
326
+ }
327
+ const cache = await loadVerificationCache(root);
328
+ const results = await Promise.all(entries.map(async (entry) => {
329
+ const cached = cache.get(entry.id);
330
+ if (cached && entry.executable) {
331
+ const current = fingerprintFile((0, executable_1.resolveExecutable)(entry.executable, root)?.path);
332
+ if (current && current === cached.fingerprint) {
333
+ const { fingerprint: _fingerprint, checkedAt: _checkedAt, ...verification } = cached;
334
+ return { verification, cacheEntry: cached };
335
+ }
336
+ }
337
+ const verification = await verifyTool(entry, { root, runtimes, depth });
338
+ const fingerprint = fingerprintFile(verification.resolvedPath);
339
+ return {
340
+ verification,
341
+ // Only a result tied to a specific file can be invalidated reliably, so
342
+ // only those are cached.
343
+ cacheEntry: fingerprint && verification.state === "verified"
344
+ ? { ...verification, fingerprint, checkedAt: new Date().toISOString() }
345
+ : undefined
346
+ };
347
+ }));
348
+ await saveVerificationCache(root, results.map((result) => result.cacheEntry).filter((entry) => Boolean(entry)));
349
+ return results.map((result) => result.verification);
350
+ }
351
+ function summarizeVerification(verification) {
352
+ const where = verification.resolvedPath ?? verification.interpreterPath;
353
+ const version = verification.version ? ` ${verification.version}` : "";
354
+ switch (verification.state) {
355
+ case "verified":
356
+ return `${verification.id}${version} — verified${where ? ` at ${where}` : ""}`;
357
+ case "not_found":
358
+ return `${verification.id} — NOT FOUND: ${verification.reason}`;
359
+ case "broken":
360
+ return `${verification.id} — BROKEN: ${verification.reason}`;
361
+ case "incompatible_runtime":
362
+ return `${verification.id} — RUNTIME MISMATCH: ${verification.reason}`;
363
+ case "unverifiable":
364
+ return `${verification.id} — UNVERIFIED: ${verification.reason}`;
365
+ }
366
+ }
367
+ function formatVersionForDisplay(value) {
368
+ const parsed = (0, semverLite_1.parseVersion)(value);
369
+ return parsed ? (0, semverLite_1.formatVersion)(parsed) : (value ?? "unknown");
370
+ }
@@ -125,26 +125,49 @@ function scopedScannerContext(ctx, candidates) {
125
125
  }
126
126
  function capabilityFromExecution(id, execution, mapped) {
127
127
  const status = execution.status;
128
- if (status?.status === "skipped") {
129
- return {
130
- id,
131
- status: "skipped",
132
- message: status.installHint ?? (status.stderr.trim() || `${id} was unavailable (never counted as pass)`)
133
- };
134
- }
135
128
  if (status?.status === "error" || status?.status === "timeout") {
136
129
  return {
137
130
  id,
138
131
  status: "error",
139
- message: status.stderr.trim() || status.stdout.trim() || `${id} failed`
132
+ cause: status.status === "timeout" ? "timed_out" : "failed",
133
+ message: status.stderr.trim() || status.stdout.trim() || `${id} failed`,
134
+ remediation: `Run \`vibedoctor tool retry ${id}\` to see the full output.`
140
135
  };
141
136
  }
142
137
  return {
143
138
  id,
144
139
  status: "available",
145
- message: `Reused ${id} scan; ${mapped} scoped finding(s) contributed to DPDP evidence`
140
+ cause: "ran",
141
+ message: `Reused ${id} scan; ${mapped} scoped finding(s) contributed to DPDP evidence`,
142
+ resolvedVia: status?.resolvedPath,
143
+ signalsContributed: mapped
146
144
  };
147
145
  }
146
+ /**
147
+ * Whether a shared scan result can stand in for a DPDP-scoped run.
148
+ *
149
+ * DPDP runs these scanners under a context that forces privacy checks on, so a
150
+ * shared result that was skipped for a configuration reason says nothing about
151
+ * whether the scanner works — inheriting that skip is what reported an installed
152
+ * Presidio as unavailable for DPDP.
153
+ *
154
+ * A skip caused by the tool being absent is different: it is authoritative, and
155
+ * retrying under a different config would only spend time failing again.
156
+ */
157
+ function canReuseExecution(execution) {
158
+ if (!execution) {
159
+ return false;
160
+ }
161
+ // An entry with no process status came from an adapter that did its work
162
+ // in-process, so the results stand.
163
+ if (!execution.status) {
164
+ return true;
165
+ }
166
+ if (execution.status.status !== "skipped") {
167
+ return true;
168
+ }
169
+ return Boolean(execution.status.installHint);
170
+ }
148
171
  /**
149
172
  * Run opt-out optional scanners (Presidio, Semgrep) when enabled.
150
173
  * Missing tools are skipped — never counted as a pass.
@@ -160,8 +183,20 @@ async function collectOptionalScannerSignals(ctx, candidates, options = {}) {
160
183
  signals,
161
184
  findings,
162
185
  capabilities: [
163
- { id: "presidio", status: "skipped", message: "Skipped in quick mode" },
164
- { id: "semgrep", status: "skipped", message: "Skipped in quick mode" }
186
+ {
187
+ id: "presidio",
188
+ status: "skipped",
189
+ cause: "quick_mode",
190
+ message: "Skipped in quick mode",
191
+ remediation: "Run `vibedoctor dpdp scan --full` for evidence from the optional scanners."
192
+ },
193
+ {
194
+ id: "semgrep",
195
+ status: "skipped",
196
+ cause: "quick_mode",
197
+ message: "Skipped in quick mode",
198
+ remediation: "Run `vibedoctor dpdp scan --full` for evidence from the optional scanners."
199
+ }
165
200
  ]
166
201
  };
167
202
  }
@@ -171,15 +206,27 @@ async function collectOptionalScannerSignals(ctx, candidates, options = {}) {
171
206
  capabilities.push({
172
207
  id: "presidio",
173
208
  status: "skipped",
174
- message: "Opted out (set checks.dpdp.use_presidio: true to re-enable for DPDP evidence)"
209
+ cause: "opted_out",
210
+ message: "Opted out (set checks.dpdp.use_presidio: true to re-enable for DPDP evidence)",
211
+ remediation: "Set checks.dpdp.use_presidio: true in vibedoctor.yml."
175
212
  });
176
213
  }
177
214
  else if (candidates.length === 0) {
178
- capabilities.push({ id: "presidio", status: "skipped", message: "No DPDP candidate files in scope" });
215
+ capabilities.push({
216
+ id: "presidio",
217
+ status: "skipped",
218
+ cause: "nothing_in_scope",
219
+ message: "No DPDP candidate files in scope",
220
+ remediation: "Widen checks.dpdp.include or paths.include in vibedoctor.yml."
221
+ });
179
222
  }
180
223
  else {
181
224
  try {
182
- const reused = ctx.sharedToolResults?.presidio;
225
+ const shared = ctx.sharedToolResults?.presidio;
226
+ const reused = canReuseExecution(shared) ? shared : undefined;
227
+ // Note why the shared result could not be reused, so a fresh attempt that
228
+ // also fails can report both facts instead of only the second one.
229
+ const sharedSkipReason = shared && !reused ? shared.status?.installHint ?? shared.status?.stderr?.trim() : undefined;
183
230
  if (reused) {
184
231
  const scopedFindings = reused.findings.filter((finding) => inCandidateScope(finding, candidateSet));
185
232
  findings.push(...scopedFindings);
@@ -210,26 +257,33 @@ async function collectOptionalScannerSignals(ctx, candidates, options = {}) {
210
257
  capabilities.push({
211
258
  id: "presidio",
212
259
  status: "skipped",
213
- message: "Presidio not selected for this project"
260
+ cause: "not_applicable",
261
+ message: "Presidio not selected for this project",
262
+ remediation: "Set checks.privacy.enabled and checks.dpdp.use_presidio to true in vibedoctor.yml."
214
263
  });
215
264
  }
216
265
  else {
217
266
  const result = await presidio_1.presidioAdapter.runStandalone?.(presidioCtx);
218
267
  const status = result?.status;
219
268
  if (!result || status?.status === "skipped") {
269
+ const detail = status?.installHint ?? status?.stderr?.trim() ?? "Presidio could not be started in the project Python environment.";
220
270
  capabilities.push({
221
271
  id: "presidio",
222
272
  status: "skipped",
223
- message: status?.installHint ??
224
- status?.stderr?.trim() ??
225
- "Presidio not installed or unavailable (never counted as pass)"
273
+ cause: "not_installed",
274
+ message: sharedSkipReason
275
+ ? `${detail} (the privacy scan also skipped Presidio: ${sharedSkipReason})`
276
+ : detail,
277
+ remediation: "Install it in the interpreter the scanner uses: python -m pip install presidio-analyzer, then run `vibedoctor setup --apply` to confirm it resolves."
226
278
  });
227
279
  }
228
280
  else if (status?.status === "error" || status?.status === "timeout") {
229
281
  capabilities.push({
230
282
  id: "presidio",
231
283
  status: "error",
232
- message: status.stderr?.trim() || status.stdout?.trim() || "Presidio failed"
284
+ cause: status.status === "timeout" ? "timed_out" : "failed",
285
+ message: status.stderr?.trim() || status.stdout?.trim() || "Presidio failed",
286
+ remediation: "Run `vibedoctor tool retry presidio` to see the full output."
233
287
  });
234
288
  }
235
289
  else {
@@ -240,7 +294,10 @@ async function collectOptionalScannerSignals(ctx, candidates, options = {}) {
240
294
  capabilities.push({
241
295
  id: "presidio",
242
296
  status: "available",
243
- message: `Presidio contributed ${result.findings.length} finding(s) to DPDP evidence`
297
+ cause: "ran",
298
+ message: `Presidio contributed ${result.findings.length} finding(s) to DPDP evidence`,
299
+ resolvedVia: status?.resolvedPath,
300
+ signalsContributed: result.findings.length
244
301
  });
245
302
  }
246
303
  }
@@ -250,6 +307,7 @@ async function collectOptionalScannerSignals(ctx, candidates, options = {}) {
250
307
  capabilities.push({
251
308
  id: "presidio",
252
309
  status: "error",
310
+ cause: "failed",
253
311
  message: error instanceof Error ? error.message : String(error)
254
312
  });
255
313
  }
@@ -259,15 +317,25 @@ async function collectOptionalScannerSignals(ctx, candidates, options = {}) {
259
317
  capabilities.push({
260
318
  id: "semgrep",
261
319
  status: "skipped",
262
- message: "Opted out (set checks.dpdp.use_semgrep: true to re-enable for DPDP evidence)"
320
+ cause: "opted_out",
321
+ message: "Opted out (set checks.dpdp.use_semgrep: true to re-enable for DPDP evidence)",
322
+ remediation: "Set checks.dpdp.use_semgrep: true in vibedoctor.yml."
263
323
  });
264
324
  }
265
325
  else if (candidates.length === 0) {
266
- capabilities.push({ id: "semgrep", status: "skipped", message: "No DPDP candidate files in scope" });
326
+ capabilities.push({
327
+ id: "semgrep",
328
+ status: "skipped",
329
+ cause: "nothing_in_scope",
330
+ message: "No DPDP candidate files in scope",
331
+ remediation: "Widen checks.dpdp.include or paths.include in vibedoctor.yml."
332
+ });
267
333
  }
268
334
  else {
269
335
  try {
270
- const reused = ctx.sharedToolResults?.semgrep;
336
+ const sharedSemgrep = ctx.sharedToolResults?.semgrep;
337
+ const reused = canReuseExecution(sharedSemgrep) ? sharedSemgrep : undefined;
338
+ const sharedSkipReason = sharedSemgrep && !reused ? sharedSemgrep.status?.installHint ?? sharedSemgrep.status?.stderr?.trim() : undefined;
271
339
  if (reused) {
272
340
  const scopedFindings = reused.findings.filter((finding) => inCandidateScope(finding, candidateSet));
273
341
  findings.push(...scopedFindings);
@@ -286,33 +354,51 @@ async function collectOptionalScannerSignals(ctx, candidates, options = {}) {
286
354
  capabilities.push({
287
355
  id: "semgrep",
288
356
  status: "skipped",
289
- message: "Semgrep not applicable for this project"
357
+ cause: "not_applicable",
358
+ message: "Semgrep not applicable for this project",
359
+ remediation: "Semgrep needs source files in a language it supports; widen paths.include if that is wrong."
290
360
  });
291
361
  }
292
362
  else if (!semgrep_1.semgrepAdapter.buildScanCommand || !semgrep_1.semgrepAdapter.parseResult) {
293
363
  capabilities.push({
294
364
  id: "semgrep",
295
365
  status: "skipped",
296
- message: "Semgrep adapter cannot run in this build"
366
+ cause: "not_applicable",
367
+ message: "Semgrep adapter cannot run in this build",
368
+ remediation: "This is a packaging problem, not a configuration one; please report it."
297
369
  });
298
370
  }
299
371
  else {
300
372
  const command = semgrep_1.semgrepAdapter.buildScanCommand(semgrepCtx);
373
+ // Honour the configured budget here too. The adapter's own default is
374
+ // not the user's setting, and a DPDP scan that ignores
375
+ // runtime.tool_timeouts can outlast the whole scan it belongs to.
376
+ const timeoutSeconds = ctx.config.runtime.toolTimeouts.semgrep ?? ctx.config.runtime.defaultTimeoutSeconds;
377
+ command.timeoutMs = Math.max(1, timeoutSeconds) * 1000;
301
378
  const toolResult = await (0, toolRunner_1.runCommand)(command, semgrep_1.semgrepAdapter.installHint);
302
379
  if (toolResult.status === "skipped") {
303
380
  capabilities.push({
304
381
  id: "semgrep",
305
382
  status: "skipped",
306
- message: toolResult.installHint ??
307
- toolResult.stderr?.trim() ??
308
- "Semgrep not installed (never counted as pass)"
383
+ cause: "not_installed",
384
+ message: (() => {
385
+ const detail = toolResult.installHint ?? toolResult.stderr?.trim() ?? "Semgrep not installed (never counted as pass)";
386
+ return sharedSkipReason ? `${detail} (the main scan also skipped Semgrep: ${sharedSkipReason})` : detail;
387
+ })(),
388
+ remediation: "Install Semgrep (pipx install semgrep), then run `vibedoctor setup --apply` to confirm it resolves."
309
389
  });
310
390
  }
311
391
  else if (toolResult.status === "error" || toolResult.status === "timeout") {
312
392
  capabilities.push({
313
393
  id: "semgrep",
314
394
  status: "error",
315
- message: toolResult.stderr?.trim() || "Semgrep failed"
395
+ cause: toolResult.status === "timeout" ? "timed_out" : "failed",
396
+ message: toolResult.status === "timeout"
397
+ ? `Semgrep exceeded its ${Math.round(toolResult.durationMs / 1000)}s budget, so its rules did not run over DPDP candidates.`
398
+ : toolResult.stderr?.trim() || "Semgrep failed",
399
+ remediation: toolResult.status === "timeout"
400
+ ? "Raise runtime.tool_timeouts.semgrep in vibedoctor.yml, or narrow checks.dpdp.include."
401
+ : "Run `vibedoctor tool retry semgrep` to see the full output."
316
402
  });
317
403
  }
318
404
  else {
@@ -329,7 +415,10 @@ async function collectOptionalScannerSignals(ctx, candidates, options = {}) {
329
415
  capabilities.push({
330
416
  id: "semgrep",
331
417
  status: "available",
332
- message: `Semgrep ran (${semgrepFindings.length} finding(s); ${mapped} privacy-relevant mapped to DPDP evidence)`
418
+ cause: "ran",
419
+ message: `Semgrep ran (${semgrepFindings.length} finding(s); ${mapped} privacy-relevant mapped to DPDP evidence)`,
420
+ resolvedVia: toolResult.resolvedPath,
421
+ signalsContributed: mapped
333
422
  });
334
423
  }
335
424
  }
@@ -339,6 +428,7 @@ async function collectOptionalScannerSignals(ctx, candidates, options = {}) {
339
428
  capabilities.push({
340
429
  id: "semgrep",
341
430
  status: "error",
431
+ cause: "failed",
342
432
  message: error instanceof Error ? error.message : String(error)
343
433
  });
344
434
  }