@neuralaxis/vibedoctor 0.2.0 → 0.2.2

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 (80) hide show
  1. package/README.md +135 -23
  2. package/dist/adapters/biome.js +136 -21
  3. package/dist/adapters/flowDoctor.d.ts +7 -0
  4. package/dist/adapters/flowDoctor.js +195 -0
  5. package/dist/adapters/gitleaks.js +4 -2
  6. package/dist/adapters/index.d.ts +1 -0
  7. package/dist/adapters/index.js +3 -1
  8. package/dist/adapters/osvScanner.js +140 -19
  9. package/dist/adapters/presidio.js +3 -1
  10. package/dist/adapters/ruff.js +7 -3
  11. package/dist/adapters/shared.d.ts +4 -0
  12. package/dist/cli/commands/init.js +112 -50
  13. package/dist/cli/commands/privacyReview.js +3 -4
  14. package/dist/cli/commands/scan.d.ts +6 -0
  15. package/dist/cli/commands/scan.js +16 -2
  16. package/dist/cli/commands/setup.d.ts +13 -17
  17. package/dist/cli/commands/setup.js +138 -200
  18. package/dist/cli/index.js +4 -4
  19. package/dist/core/agentDiagnosis.d.ts +39 -0
  20. package/dist/core/agentDiagnosis.js +96 -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 +47 -0
  24. package/dist/core/config.js +134 -3
  25. package/dist/core/credentialHeuristics.d.ts +28 -0
  26. package/dist/core/credentialHeuristics.js +179 -0
  27. package/dist/core/engine.d.ts +29 -1
  28. package/dist/core/engine.js +510 -126
  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 +70 -8
  35. package/dist/core/findingCorrelator.d.ts +19 -0
  36. package/dist/core/findingCorrelator.js +112 -0
  37. package/dist/core/findingNormalizer.d.ts +33 -0
  38. package/dist/core/findingNormalizer.js +172 -0
  39. package/dist/core/managedTools.d.ts +25 -0
  40. package/dist/core/managedTools.js +186 -0
  41. package/dist/core/projectDetector.d.ts +13 -0
  42. package/dist/core/projectDetector.js +100 -15
  43. package/dist/core/relevance.d.ts +87 -0
  44. package/dist/core/relevance.js +367 -0
  45. package/dist/core/repoGraph.d.ts +62 -0
  46. package/dist/core/repoGraph.js +408 -0
  47. package/dist/core/riskRanker.d.ts +6 -0
  48. package/dist/core/riskRanker.js +127 -0
  49. package/dist/core/scanContext.d.ts +26 -0
  50. package/dist/core/scanContext.js +44 -0
  51. package/dist/core/scanPlanner.d.ts +13 -0
  52. package/dist/core/scanPlanner.js +66 -38
  53. package/dist/core/semverLite.d.ts +27 -0
  54. package/dist/core/semverLite.js +163 -0
  55. package/dist/core/suppressions.d.ts +96 -0
  56. package/dist/core/suppressions.js +302 -0
  57. package/dist/core/toolRegistry.d.ts +58 -0
  58. package/dist/core/toolRegistry.js +254 -0
  59. package/dist/core/toolRunner.d.ts +27 -2
  60. package/dist/core/toolRunner.js +79 -93
  61. package/dist/core/toolRuntime.d.ts +40 -0
  62. package/dist/core/toolRuntime.js +417 -0
  63. package/dist/core/toolVerification.d.ts +89 -0
  64. package/dist/core/toolVerification.js +425 -0
  65. package/dist/dpdp/collectors/optionalScanners.js +120 -30
  66. package/dist/dpdp/findings.d.ts +33 -3
  67. package/dist/dpdp/findings.js +191 -4
  68. package/dist/dpdp/scan.js +2 -2
  69. package/dist/dpdp/scoring.d.ts +14 -4
  70. package/dist/dpdp/scoring.js +34 -8
  71. package/dist/dpdp/types.d.ts +19 -1
  72. package/dist/index.d.ts +5 -0
  73. package/dist/index.js +5 -0
  74. package/dist/reporters/agent.d.ts +1 -1
  75. package/dist/reporters/agent.js +7 -0
  76. package/dist/reporters/html.js +57 -13
  77. package/dist/reporters/json.js +7 -1
  78. package/dist/reporters/markdown.js +46 -4
  79. package/dist/reporters/sarif.js +54 -5
  80. package/package.json +80 -80
@@ -0,0 +1,89 @@
1
+ import { type RuntimeEngine, type ToolRegistryEntry } from "./toolRegistry";
2
+ import { type ToolRuntime } from "./toolRuntime";
3
+ /**
4
+ * Proves a tool is usable rather than merely present.
5
+ *
6
+ * `setup --apply` used to report success when an install command exited zero.
7
+ * That is not the same claim as "the scanner can run this", and the two came
8
+ * apart in practice: a package installed into an interpreter that was not on
9
+ * PATH, or under a Node version too old to run it. Verification here resolves
10
+ * the executable through the scanner's own lookup, runs it, and records the
11
+ * concrete path and version — so a passing verification means the next scan
12
+ * will find the same binary.
13
+ */
14
+ export type VerificationState =
15
+ /** Resolved, ran, and reported a version. */
16
+ "verified"
17
+ /** Nothing on PATH matches the executable. */
18
+ | "not_found"
19
+ /** Found on PATH but the probe failed, so the install is broken. */
20
+ | "broken"
21
+ /** Found, but the runtime it needs cannot run it. */
22
+ | "incompatible_runtime"
23
+ /** Cannot be verified from here (no probe declared); reported honestly, never as a pass. */
24
+ | "unverifiable";
25
+ export type ToolVerification = {
26
+ id: string;
27
+ state: VerificationState;
28
+ /** Absolute path of the executable that answered the probe. */
29
+ resolvedPath?: string;
30
+ /** Interpreter path, for tools driven as a module of another runtime. */
31
+ interpreterPath?: string;
32
+ version?: string;
33
+ /** The exact command line used to verify, so a user can rerun it by hand. */
34
+ probeCommand?: string;
35
+ runtime?: {
36
+ engine: RuntimeEngine;
37
+ version?: string;
38
+ requirement?: string;
39
+ requirementSource?: string;
40
+ compatible: boolean | "unknown";
41
+ };
42
+ reason: string;
43
+ remediation?: string;
44
+ };
45
+ export declare function isVerificationBlocking(verification: ToolVerification): boolean;
46
+ export type RuntimeProbe = {
47
+ engine: RuntimeEngine;
48
+ available: boolean;
49
+ command?: string;
50
+ resolvedPath?: string;
51
+ version?: string;
52
+ detail: string;
53
+ };
54
+ /**
55
+ * Locates a language runtime once per process. `python` being absent is the
56
+ * reason a whole family of installs silently fails, so it is reported as a
57
+ * first-class fact rather than inferred from a tool-level error message.
58
+ */
59
+ export declare function probeRuntime(engine: RuntimeEngine, cwd: string): Promise<RuntimeProbe>;
60
+ export type RuntimeProbes = Partial<Record<RuntimeEngine, RuntimeProbe>>;
61
+ export declare function probeRuntimes(cwd: string, engines: RuntimeEngine[]): Promise<RuntimeProbes>;
62
+ /**
63
+ * Probes only the runtimes that a tool present on this machine actually needs.
64
+ *
65
+ * Probing every runtime a registry entry mentions meant spawning a Python
66
+ * interpreter on repositories with no Python tooling installed, on every scan.
67
+ */
68
+ export declare function probeRuntimesFor(entries: ToolRegistryEntry[], cwd: string, depth?: VerificationDepth): Promise<RuntimeProbes>;
69
+ /**
70
+ * How hard to look.
71
+ *
72
+ * `execute` runs each tool's probe, which is what `setup` needs: there is no
73
+ * later scan to fall back on, so an unproven tool must not be reported as
74
+ * installed. `resolve` stops at locating the executable and checking runtime
75
+ * compatibility, which is what a scan needs — the scan is about to invoke the
76
+ * tool anyway, and paying for a second process per tool would add tens of
77
+ * seconds to every run to learn something the run itself reveals.
78
+ */
79
+ export type VerificationDepth = "resolve" | "execute";
80
+ export type VerifyToolOptions = {
81
+ root: string;
82
+ runtimes: RuntimeProbes;
83
+ depth?: VerificationDepth;
84
+ toolRuntime?: ToolRuntime;
85
+ };
86
+ export declare function verifyTool(entry: ToolRegistryEntry, options: VerifyToolOptions): Promise<ToolVerification>;
87
+ export declare function verifyTools(entries: ToolRegistryEntry[], root: string, depth?: VerificationDepth, toolRuntime?: ToolRuntime): Promise<ToolVerification[]>;
88
+ export declare function summarizeVerification(verification: ToolVerification): string;
89
+ export declare function formatVersionForDisplay(value: string | undefined): string;
@@ -0,0 +1,425 @@
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
+ const toolRuntime_1 = require("./toolRuntime");
21
+ function isVerificationBlocking(verification) {
22
+ return verification.state === "not_found" || verification.state === "broken" || verification.state === "incompatible_runtime";
23
+ }
24
+ const DEFAULT_VERSION_PATTERN = /\b(\d+\.\d+(?:\.\d+)?(?:[-+][0-9A-Za-z.-]+)?)\b/;
25
+ function extractVersion(output, pattern) {
26
+ const match = (pattern ?? DEFAULT_VERSION_PATTERN).exec(output);
27
+ return match?.[1] ?? match?.[0];
28
+ }
29
+ // Generous, because some tools are genuinely slow to start: reporting a working
30
+ // tool as broken because it took 31 seconds to print its version would be worse
31
+ // than waiting.
32
+ const PROBE_TIMEOUT_MS = 90_000;
33
+ /** Candidate interpreter command names, in the order the scanner would find them. */
34
+ const RUNTIME_COMMANDS = {
35
+ node: ["node"],
36
+ python: ["python", "python3", "py"]
37
+ };
38
+ /**
39
+ * Locates a language runtime once per process. `python` being absent is the
40
+ * reason a whole family of installs silently fails, so it is reported as a
41
+ * first-class fact rather than inferred from a tool-level error message.
42
+ */
43
+ async function probeRuntime(engine, cwd) {
44
+ if (engine === "node") {
45
+ // We are running on Node, so the version that matters is this process's.
46
+ const resolved = (0, executable_1.resolveExecutable)("node", cwd);
47
+ return {
48
+ engine,
49
+ available: true,
50
+ command: "node",
51
+ resolvedPath: resolved?.path ?? process.execPath,
52
+ version: process.versions.node,
53
+ detail: `Node ${process.versions.node} at ${resolved?.path ?? process.execPath}`
54
+ };
55
+ }
56
+ for (const command of RUNTIME_COMMANDS[engine]) {
57
+ const resolved = (0, executable_1.resolveExecutable)(command, cwd);
58
+ if (!resolved) {
59
+ continue;
60
+ }
61
+ const result = await (0, toolRunner_1.runCommand)({ cmd: command, args: ["--version"], cwd, timeoutMs: PROBE_TIMEOUT_MS });
62
+ if (result.status !== "ok") {
63
+ continue;
64
+ }
65
+ const version = extractVersion(`${result.stdout}\n${result.stderr}`, undefined);
66
+ return {
67
+ engine,
68
+ available: true,
69
+ command,
70
+ resolvedPath: resolved.path,
71
+ version,
72
+ detail: `${command} ${version ?? "(unknown version)"} at ${resolved.path}`
73
+ };
74
+ }
75
+ return {
76
+ engine,
77
+ available: false,
78
+ detail: `No ${engine} interpreter found on PATH (tried ${RUNTIME_COMMANDS[engine].join(", ")}).`
79
+ };
80
+ }
81
+ async function probeRuntimes(cwd, engines) {
82
+ const unique = Array.from(new Set(engines));
83
+ const probes = await Promise.all(unique.map(async (engine) => [engine, await probeRuntime(engine, cwd)]));
84
+ return Object.fromEntries(probes);
85
+ }
86
+ /**
87
+ * Probes only the runtimes that a tool present on this machine actually needs.
88
+ *
89
+ * Probing every runtime a registry entry mentions meant spawning a Python
90
+ * interpreter on repositories with no Python tooling installed, on every scan.
91
+ */
92
+ async function probeRuntimesFor(entries, cwd, depth = "execute") {
93
+ const engines = new Set();
94
+ for (const entry of entries) {
95
+ if (entry.moduleProbe && depth === "execute") {
96
+ engines.add(entry.moduleProbe.runtime);
97
+ continue;
98
+ }
99
+ if (!entry.runtime || !entry.executable) {
100
+ continue;
101
+ }
102
+ // Node compatibility is free — this process is the runtime — so it is always
103
+ // worth knowing. Other runtimes cost a spawn, so only ask when the tool that
104
+ // needs one is actually installed.
105
+ if (entry.runtime === "node" || (0, executable_1.resolveExecutable)(entry.executable, cwd)) {
106
+ engines.add(entry.runtime);
107
+ }
108
+ }
109
+ return probeRuntimes(cwd, Array.from(engines));
110
+ }
111
+ async function checkRuntimeCompatibility(root, entry, probes) {
112
+ if (!entry.runtime) {
113
+ return undefined;
114
+ }
115
+ const probe = probes[entry.runtime];
116
+ const { range, source } = entry.ecosystem === "npm" ? await (0, toolRegistry_1.readDeclaredNodeRequirement)(root, entry.packageName) : {};
117
+ if (!probe?.available) {
118
+ return {
119
+ engine: entry.runtime,
120
+ requirement: range,
121
+ requirementSource: source,
122
+ compatible: false
123
+ };
124
+ }
125
+ const version = (0, semverLite_1.parseVersion)(probe.version);
126
+ const satisfied = version ? (0, semverLite_1.satisfiesRange)(version, range) : undefined;
127
+ return {
128
+ engine: entry.runtime,
129
+ version: probe.version,
130
+ requirement: range,
131
+ requirementSource: source,
132
+ compatible: satisfied ?? "unknown"
133
+ };
134
+ }
135
+ function runtimeRemediation(entry, runtime) {
136
+ const needed = (0, semverLite_1.minimumSatisfying)(runtime.requirement);
137
+ const target = needed ? `${runtime.engine} >= ${needed}` : `a newer ${runtime.engine}`;
138
+ return [
139
+ `${entry.id} declares ${runtime.requirement ?? "a newer runtime"}${runtime.requirementSource ? ` (${runtime.requirementSource})` : ""}`,
140
+ `but the active runtime is ${runtime.engine} ${runtime.version ?? "unknown"}.`,
141
+ `Either upgrade to ${target}, run VibeDoctor under a compatible runtime, or set`,
142
+ `runtime.deferred_tools: [${entry.id}] in vibedoctor.yml to defer it deliberately.`
143
+ ].join(" ");
144
+ }
145
+ async function verifyTool(entry, options) {
146
+ const { root, runtimes } = options;
147
+ const depth = options.depth ?? "execute";
148
+ if (entry.ecosystem === "built-in") {
149
+ return {
150
+ id: entry.id,
151
+ state: "verified",
152
+ reason: "Built-in check; no external executable required.",
153
+ version: "built-in"
154
+ };
155
+ }
156
+ const runtime = await checkRuntimeCompatibility(root, entry, runtimes);
157
+ // A tool driven as a module of another runtime (Presidio) has no binary to
158
+ // find; import the module through the interpreter the scanner would use.
159
+ if (entry.moduleProbe) {
160
+ const probe = runtimes[entry.moduleProbe.runtime];
161
+ if (!probe?.available) {
162
+ return {
163
+ id: entry.id,
164
+ state: depth === "resolve" ? "unverifiable" : "not_found",
165
+ reason: depth === "resolve"
166
+ ? `${entry.id} runs as a ${entry.moduleProbe.runtime} module; whether it is importable is determined when it runs.`
167
+ : `${entry.moduleProbe.runtime} interpreter is not available, so ${entry.id} cannot run.`,
168
+ remediation: `Install ${entry.moduleProbe.runtime} and make it available on PATH, then rerun setup.`,
169
+ runtime
170
+ };
171
+ }
172
+ if (depth === "resolve") {
173
+ // Importing the module is expensive enough to matter on every scan, and
174
+ // the adapter reports the same fact when it actually runs.
175
+ return {
176
+ id: entry.id,
177
+ state: "unverifiable",
178
+ interpreterPath: probe.resolvedPath,
179
+ reason: `${entry.id} runs as a ${entry.moduleProbe.runtime} module; its availability is confirmed when the scan invokes it.`,
180
+ runtime
181
+ };
182
+ }
183
+ const args = ["-c", `import ${entry.moduleProbe.module} as m; print(getattr(m, "__version__", "installed"))`];
184
+ const result = await (0, toolRunner_1.runCommand)({ cmd: probe.command, args, cwd: root, timeoutMs: PROBE_TIMEOUT_MS });
185
+ const probeCommand = [probe.command, ...args].join(" ");
186
+ if (result.status !== "ok") {
187
+ return {
188
+ id: entry.id,
189
+ state: result.status === "skipped" ? "not_found" : "broken",
190
+ interpreterPath: probe.resolvedPath,
191
+ probeCommand,
192
+ reason: `${entry.moduleProbe.module} could not be imported by ${probe.resolvedPath ?? probe.command}.`,
193
+ remediation: (0, toolRegistry_1.installHintFor)(entry),
194
+ runtime
195
+ };
196
+ }
197
+ return {
198
+ id: entry.id,
199
+ state: "verified",
200
+ interpreterPath: probe.resolvedPath,
201
+ version: result.stdout.trim() || "installed",
202
+ probeCommand,
203
+ reason: `Imported ${entry.moduleProbe.module} using ${probe.resolvedPath ?? probe.command}.`,
204
+ runtime
205
+ };
206
+ }
207
+ if (!entry.executable) {
208
+ return {
209
+ id: entry.id,
210
+ state: "unverifiable",
211
+ reason: `${entry.id} declares no executable or module probe, so its availability cannot be confirmed.`,
212
+ remediation: "Add a probe to the tool registry so setup can verify this tool.",
213
+ runtime
214
+ };
215
+ }
216
+ if (options.toolRuntime && (0, toolRuntime_1.isManagedTool)(entry.id)) {
217
+ const managed = await options.toolRuntime.resolve(entry.id, { projectRoot: root });
218
+ if (managed.executablePath) {
219
+ if (depth === "resolve") {
220
+ return {
221
+ id: entry.id,
222
+ state: "verified",
223
+ resolvedPath: managed.executablePath,
224
+ version: managed.version,
225
+ reason: managed.reason,
226
+ runtime
227
+ };
228
+ }
229
+ const probeArgs = entry.probeArgs ?? ["--version"];
230
+ const result = await (0, toolRunner_1.runCommand)({
231
+ cmd: managed.executablePath,
232
+ args: probeArgs,
233
+ cwd: root,
234
+ timeoutMs: PROBE_TIMEOUT_MS
235
+ });
236
+ const probeCommand = [managed.executablePath, ...probeArgs].join(" ");
237
+ if (result.status !== "ok") {
238
+ return {
239
+ id: entry.id,
240
+ state: "broken",
241
+ resolvedPath: managed.executablePath,
242
+ version: managed.version,
243
+ probeCommand,
244
+ reason: `Managed ${entry.id} at ${managed.executablePath} failed its version probe.`,
245
+ remediation: managed.remediation ?? (0, toolRegistry_1.installHintFor)(entry),
246
+ runtime
247
+ };
248
+ }
249
+ return {
250
+ id: entry.id,
251
+ state: "verified",
252
+ resolvedPath: managed.executablePath,
253
+ version: extractVersion(`${result.stdout}\n${result.stderr}`, entry.versionPattern) ?? managed.version,
254
+ probeCommand,
255
+ reason: `Ran managed ${entry.id} at ${managed.executablePath}.`,
256
+ runtime
257
+ };
258
+ }
259
+ if (managed.status === "checksum_mismatch" || managed.status === "failed") {
260
+ return {
261
+ id: entry.id,
262
+ state: "broken",
263
+ version: managed.version,
264
+ reason: managed.reason,
265
+ remediation: managed.remediation,
266
+ runtime
267
+ };
268
+ }
269
+ }
270
+ const resolved = (0, executable_1.resolveExecutable)(entry.executable, root);
271
+ if (!resolved) {
272
+ const searched = (0, executable_1.describeSearchPaths)(root);
273
+ return {
274
+ id: entry.id,
275
+ state: "not_found",
276
+ reason: `${entry.executable} was not found in any of the ${searched.length} directories on the scanner's PATH.`,
277
+ remediation: (0, toolRegistry_1.installHintFor)(entry),
278
+ runtime
279
+ };
280
+ }
281
+ // Runtime incompatibility is reported before the probe, because a tool that
282
+ // cannot start under this runtime is not "broken" — it is mismatched, and the
283
+ // remediation is completely different.
284
+ if (runtime && runtime.compatible === false) {
285
+ return {
286
+ id: entry.id,
287
+ state: "incompatible_runtime",
288
+ resolvedPath: resolved.path,
289
+ reason: runtime.requirement
290
+ ? `${entry.id} requires ${runtime.engine} ${runtime.requirement} but ${runtime.engine} ${runtime.version ?? "unknown"} is active.`
291
+ : `${entry.id} needs a ${runtime.engine} runtime that is not available.`,
292
+ remediation: runtimeRemediation(entry, runtime),
293
+ runtime
294
+ };
295
+ }
296
+ if (depth === "resolve") {
297
+ return {
298
+ id: entry.id,
299
+ state: "verified",
300
+ resolvedPath: resolved.path,
301
+ reason: `Resolved to ${resolved.path}; the scan invokes this executable directly.`,
302
+ runtime
303
+ };
304
+ }
305
+ const probeArgs = entry.probeArgs ?? ["--version"];
306
+ const result = await (0, toolRunner_1.runCommand)({ cmd: entry.executable, args: probeArgs, cwd: root, timeoutMs: PROBE_TIMEOUT_MS });
307
+ const probeCommand = [entry.executable, ...probeArgs].join(" ");
308
+ const output = `${result.stdout}\n${result.stderr}`;
309
+ if (result.status !== "ok") {
310
+ // A tool present on PATH that cannot answer its own version probe is
311
+ // installed-but-unusable; saying "installed" here is what misled users.
312
+ const unsupportedRuntime = /requires node|unsupported engine|SyntaxError|Unexpected token/i.test(output);
313
+ return {
314
+ id: entry.id,
315
+ state: unsupportedRuntime ? "incompatible_runtime" : "broken",
316
+ resolvedPath: resolved.path,
317
+ probeCommand,
318
+ reason: unsupportedRuntime
319
+ ? `${entry.id} is installed at ${resolved.path} but failed to start under the active runtime.`
320
+ : `${entry.id} is installed at ${resolved.path} but \`${probeCommand}\` exited ${result.exitCode ?? "abnormally"}.`,
321
+ remediation: unsupportedRuntime && runtime ? runtimeRemediation(entry, runtime) : (0, toolRegistry_1.installHintFor)(entry),
322
+ runtime
323
+ };
324
+ }
325
+ return {
326
+ id: entry.id,
327
+ state: "verified",
328
+ resolvedPath: resolved.path,
329
+ version: extractVersion(output, entry.versionPattern),
330
+ probeCommand,
331
+ reason: `Ran \`${probeCommand}\` successfully at ${resolved.path}.`,
332
+ runtime
333
+ };
334
+ }
335
+ const VERIFICATION_CACHE_FILE = ".vibedoctor/tool-verification.json";
336
+ /**
337
+ * Identity of the file that answered the probe. A tool's version output cannot
338
+ * change unless the file does, so this is safe to cache against — and some tools
339
+ * are slow enough to matter: Semgrep takes the better part of a minute just to
340
+ * report its own version.
341
+ */
342
+ function fingerprintFile(filePath) {
343
+ if (!filePath) {
344
+ return undefined;
345
+ }
346
+ try {
347
+ const stats = (0, node_fs_1.statSync)(filePath);
348
+ return `${filePath}:${stats.size}:${Math.round(stats.mtimeMs)}`;
349
+ }
350
+ catch {
351
+ return undefined;
352
+ }
353
+ }
354
+ async function loadVerificationCache(root) {
355
+ try {
356
+ const parsed = JSON.parse(await node_fs_1.promises.readFile(node_path_1.default.join(root, VERIFICATION_CACHE_FILE), "utf8"));
357
+ if (parsed.version !== 1 || !Array.isArray(parsed.entries)) {
358
+ return new Map();
359
+ }
360
+ return new Map(parsed.entries.map((entry) => [entry.id, entry]));
361
+ }
362
+ catch {
363
+ return new Map();
364
+ }
365
+ }
366
+ async function saveVerificationCache(root, entries) {
367
+ try {
368
+ const target = node_path_1.default.join(root, VERIFICATION_CACHE_FILE);
369
+ await node_fs_1.promises.mkdir(node_path_1.default.dirname(target), { recursive: true });
370
+ await node_fs_1.promises.writeFile(target, `${JSON.stringify({ version: 1, entries }, null, 2)}\n`, "utf8");
371
+ }
372
+ catch {
373
+ // A cache that cannot be written only costs time on the next run.
374
+ }
375
+ }
376
+ async function verifyTools(entries, root, depth = "execute", toolRuntime) {
377
+ const runtimes = await probeRuntimesFor(entries, root, depth);
378
+ if (depth === "resolve") {
379
+ // Resolution is a filesystem lookup; caching it would only add staleness.
380
+ return Promise.all(entries.map((entry) => verifyTool(entry, { root, runtimes, depth, toolRuntime })));
381
+ }
382
+ const cache = await loadVerificationCache(root);
383
+ const results = await Promise.all(entries.map(async (entry) => {
384
+ const cached = cache.get(entry.id);
385
+ if (cached && entry.executable) {
386
+ const current = fingerprintFile((0, executable_1.resolveExecutable)(entry.executable, root)?.path);
387
+ if (current && current === cached.fingerprint) {
388
+ const { fingerprint: _fingerprint, checkedAt: _checkedAt, ...verification } = cached;
389
+ return { verification, cacheEntry: cached };
390
+ }
391
+ }
392
+ const verification = await verifyTool(entry, { root, runtimes, depth, toolRuntime });
393
+ const fingerprint = fingerprintFile(verification.resolvedPath);
394
+ return {
395
+ verification,
396
+ // Only a result tied to a specific file can be invalidated reliably, so
397
+ // only those are cached.
398
+ cacheEntry: fingerprint && verification.state === "verified"
399
+ ? { ...verification, fingerprint, checkedAt: new Date().toISOString() }
400
+ : undefined
401
+ };
402
+ }));
403
+ await saveVerificationCache(root, results.map((result) => result.cacheEntry).filter((entry) => Boolean(entry)));
404
+ return results.map((result) => result.verification);
405
+ }
406
+ function summarizeVerification(verification) {
407
+ const where = verification.resolvedPath ?? verification.interpreterPath;
408
+ const version = verification.version ? ` ${verification.version}` : "";
409
+ switch (verification.state) {
410
+ case "verified":
411
+ return `${verification.id}${version} — verified${where ? ` at ${where}` : ""}`;
412
+ case "not_found":
413
+ return `${verification.id} — NOT FOUND: ${verification.reason}`;
414
+ case "broken":
415
+ return `${verification.id} — BROKEN: ${verification.reason}`;
416
+ case "incompatible_runtime":
417
+ return `${verification.id} — RUNTIME MISMATCH: ${verification.reason}`;
418
+ case "unverifiable":
419
+ return `${verification.id} — UNVERIFIED: ${verification.reason}`;
420
+ }
421
+ }
422
+ function formatVersionForDisplay(value) {
423
+ const parsed = (0, semverLite_1.parseVersion)(value);
424
+ return parsed ? (0, semverLite_1.formatVersion)(parsed) : (value ?? "unknown");
425
+ }