@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
@@ -10,165 +10,17 @@ const toolRunner_1 = require("../../core/toolRunner");
10
10
  const projectDetector_1 = require("../../core/projectDetector");
11
11
  const config_1 = require("../../core/config");
12
12
  const paths_1 = require("../../core/paths");
13
- const VALID_SETUP_INCLUDES = new Set(["essential", "recommended", "all", "npm", "python", "manual", "built-in"]);
14
- const essentialTools = [
15
- {
16
- id: "custom-leftovers",
17
- ecosystem: "built-in",
18
- priority: "essential",
19
- reason: "Finds stale TODOs, commented-out code, legacy fallback paths, and AI leftovers without any external install."
20
- },
21
- {
22
- id: "custom-dead-chain",
23
- ecosystem: "built-in",
24
- priority: "essential",
25
- reason: "Finds isolated file clusters after external dead-code tools report candidates."
26
- },
27
- {
28
- id: "custom-refactor",
29
- ecosystem: "built-in",
30
- priority: "essential",
31
- reason: "Finds large or complex files that need tests before refactor work."
32
- },
33
- {
34
- id: "privacy-detector",
35
- ecosystem: "built-in",
36
- priority: "essential",
37
- reason: "Finds personal-data and Privacy Review signals without sending data to an external service."
38
- },
39
- {
40
- id: "tsc",
41
- packageName: "typescript",
42
- executable: "tsc",
43
- ecosystem: "npm",
44
- priority: "essential",
45
- languages: ["typescript"],
46
- reason: "TypeScript correctness signal."
47
- },
48
- {
49
- id: "biome",
50
- packageName: "@biomejs/biome",
51
- executable: "biome",
52
- ecosystem: "npm",
53
- priority: "essential",
54
- languages: ["javascript", "typescript"],
55
- reason: "Fast JS/TS lint and safe formatting signal."
56
- },
57
- {
58
- id: "knip",
59
- packageName: "knip",
60
- executable: "knip",
61
- ecosystem: "npm",
62
- priority: "essential",
63
- languages: ["javascript", "typescript"],
64
- reason: "Unused files, exports, and dependency signal for JS/TS."
65
- },
66
- {
67
- id: "ruff",
68
- packageName: "ruff",
69
- executable: "ruff",
70
- ecosystem: "python",
71
- priority: "essential",
72
- languages: ["python"],
73
- reason: "Python lint and safe-fix signal."
74
- },
75
- {
76
- id: "pyright",
77
- packageName: "pyright",
78
- executable: "pyright",
79
- ecosystem: "python",
80
- priority: "essential",
81
- languages: ["python"],
82
- reason: "Python type correctness signal."
83
- },
84
- {
85
- id: "vulture",
86
- packageName: "vulture",
87
- executable: "vulture",
88
- ecosystem: "python",
89
- priority: "essential",
90
- languages: ["python"],
91
- reason: "Python dead-code signal."
92
- },
93
- {
94
- id: "gitleaks",
95
- executable: "gitleaks",
96
- ecosystem: "manual",
97
- priority: "essential",
98
- reason: "Secret detection across every repository.",
99
- installHint: "Install Gitleaks from https://gitleaks.io/ or your OS package manager."
100
- },
101
- {
102
- id: "osv-scanner",
103
- executable: "osv-scanner",
104
- ecosystem: "manual",
105
- priority: "essential",
106
- requiresLockfile: true,
107
- reason: "Known-vulnerability detection for dependency lockfiles.",
108
- installHint: "Install OSV-Scanner from https://google.github.io/osv-scanner/ or your OS package manager."
109
- }
110
- ];
111
- const recommendedTools = [
112
- {
113
- id: "jscpd",
114
- packageName: "jscpd",
115
- executable: "jscpd",
116
- ecosystem: "npm",
117
- priority: "recommended",
118
- languages: ["javascript", "typescript"],
119
- reason: "Duplication signal for refactor planning."
120
- },
121
- {
122
- id: "coverage.py",
123
- packageName: "coverage",
124
- executable: "coverage",
125
- ecosystem: "python",
126
- priority: "recommended",
127
- languages: ["python"],
128
- reason: "Python coverage signal."
129
- },
130
- {
131
- id: "radon",
132
- packageName: "radon",
133
- executable: "radon",
134
- ecosystem: "python",
135
- priority: "recommended",
136
- languages: ["python"],
137
- reason: "Python complexity signal."
138
- },
139
- {
140
- id: "deptry",
141
- packageName: "deptry",
142
- executable: "deptry",
143
- ecosystem: "python",
144
- priority: "recommended",
145
- languages: ["python"],
146
- reason: "Python dependency hygiene signal."
147
- },
148
- {
149
- id: "lizard",
150
- executable: "lizard",
151
- ecosystem: "manual",
152
- priority: "recommended",
153
- reason: "Function-level complexity and code size hotspots (great for spotting refactor candidates).",
154
- installHint: "Install Lizard with: pipx install lizard, uv tool install lizard, or your OS package manager."
155
- },
156
- {
157
- id: "semgrep",
158
- executable: "semgrep",
159
- ecosystem: "manual",
160
- priority: "recommended",
161
- reason: "Additional security and correctness rules.",
162
- installHint: "Install Semgrep with: pipx install semgrep, uv tool install semgrep, or your OS package manager."
163
- },
164
- {
165
- id: "presidio",
166
- ecosystem: "manual",
167
- priority: "recommended",
168
- reason: "External PII analyzer used by privacy + DPDP scans by default (skipped gracefully if missing). The normal privacy and DPDP opt-outs are independent.",
169
- installHint: "Install in the project Python environment with: python -m pip install presidio-analyzer"
170
- }
171
- ];
13
+ const toolRegistry_1 = require("../../core/toolRegistry");
14
+ const toolVerification_1 = require("../../core/toolVerification");
15
+ const VALID_SETUP_INCLUDES = new Set([
16
+ "essential",
17
+ "recommended",
18
+ "all",
19
+ "npm",
20
+ "python",
21
+ "manual",
22
+ "built-in"
23
+ ]);
172
24
  function hasActiveLanguage(project, language) {
173
25
  if (!project.languages.includes(language)) {
174
26
  return false;
@@ -176,7 +28,8 @@ function hasActiveLanguage(project, language) {
176
28
  if (language === "python" && project.packageManagers.some((manager) => ["pip", "uv", "poetry", "pdm"].includes(manager))) {
177
29
  return true;
178
30
  }
179
- if ((language === "javascript" || language === "typescript") && project.packageManagers.some((manager) => ["npm", "pnpm", "yarn", "bun"].includes(manager))) {
31
+ if ((language === "javascript" || language === "typescript") &&
32
+ project.packageManagers.some((manager) => ["npm", "pnpm", "yarn", "bun"].includes(manager))) {
180
33
  return true;
181
34
  }
182
35
  const sourcePattern = language === "python"
@@ -201,12 +54,6 @@ function appliesToProject(tool, project) {
201
54
  }
202
55
  return true;
203
56
  }
204
- function isToolAvailable(tool, project) {
205
- if (!tool.executable) {
206
- return false;
207
- }
208
- return Boolean(project.toolsAvailable[tool.executable] ?? project.toolsAvailable[tool.id]);
209
- }
210
57
  function jsPackageManager(project) {
211
58
  return ["pnpm", "yarn", "bun", "npm"].find((manager) => project.packageManagers.includes(manager));
212
59
  }
@@ -222,7 +69,13 @@ function jsInstallCommand(root, manager, packages) {
222
69
  }
223
70
  return { cmd: "npm", args: ["install", "-D", ...packages], cwd: root, timeoutMs: 180_000 };
224
71
  }
225
- async function pythonInstallCommand(root, project, packages) {
72
+ /**
73
+ * Chooses how to install Python packages. Returns undefined when there is no
74
+ * interpreter or environment to install into — previously this produced an
75
+ * install command that failed at spawn time and was reported as a skip, which
76
+ * read like success.
77
+ */
78
+ async function pythonInstallCommand(root, project, packages, runtimes) {
226
79
  if (project.packageManagers.includes("uv")) {
227
80
  return { cmd: "uv", args: ["add", "--dev", ...packages], cwd: root, timeoutMs: 180_000 };
228
81
  }
@@ -232,42 +85,49 @@ async function pythonInstallCommand(root, project, packages) {
232
85
  if (project.packageManagers.includes("pdm")) {
233
86
  return { cmd: "pdm", args: ["add", "-dG", "dev", ...packages], cwd: root, timeoutMs: 180_000 };
234
87
  }
235
- const hasLocalVenv = Boolean(process.env.VIRTUAL_ENV) || (await (0, paths_1.pathExists)(node_path_1.default.join(root, ".venv"))) || (await (0, paths_1.pathExists)(node_path_1.default.join(root, "venv")));
88
+ const python = runtimes.python;
89
+ if (!python?.available || !python.command) {
90
+ return undefined;
91
+ }
92
+ const hasLocalVenv = Boolean(process.env.VIRTUAL_ENV) ||
93
+ (await (0, paths_1.pathExists)(node_path_1.default.join(root, ".venv"))) ||
94
+ (await (0, paths_1.pathExists)(node_path_1.default.join(root, "venv")));
236
95
  if (!hasLocalVenv) {
237
96
  return undefined;
238
97
  }
239
- return { cmd: "python", args: ["-m", "pip", "install", "-U", ...packages], cwd: root, timeoutMs: 180_000 };
98
+ return { cmd: python.command, args: ["-m", "pip", "install", "-U", ...packages], cwd: root, timeoutMs: 180_000 };
240
99
  }
241
100
  function commandText(command) {
242
101
  return [command.cmd, ...command.args].join(" ");
243
102
  }
244
103
  function resolveTools(include) {
245
104
  if (include === "essential") {
246
- return essentialTools;
105
+ return toolRegistry_1.TOOL_REGISTRY.filter((tool) => tool.priority === "essential");
247
106
  }
248
- const combined = [...essentialTools, ...recommendedTools];
249
107
  if (include === "recommended" || include === "all") {
250
108
  // "recommended" is the sensible default experience (essential + high-value extras).
251
109
  // "all" currently resolves to the same set (add future extended tools here if needed).
252
- return combined;
110
+ return toolRegistry_1.TOOL_REGISTRY;
253
111
  }
254
- return combined.filter((tool) => tool.ecosystem === include);
112
+ return toolRegistry_1.TOOL_REGISTRY.filter((tool) => tool.ecosystem === include);
255
113
  }
256
114
  async function createSetupPlan(root, include = "recommended") {
257
115
  const { config } = await (0, config_1.loadConfig)(root);
258
116
  const project = await (0, projectDetector_1.detectProject)(root, config.paths.exclude);
259
- const tools = resolveTools(include);
260
- const relevantTools = tools.filter((tool) => appliesToProject(tool, project));
117
+ const relevantTools = resolveTools(include).filter((tool) => appliesToProject(tool, project));
118
+ const runtimes = await (0, toolVerification_1.probeRuntimesFor)(relevantTools, root);
119
+ // Verification, not a name lookup, decides what counts as installed. This runs
120
+ // each tool the way the scanner will, so the two cannot disagree.
121
+ const verifications = await (0, toolVerification_1.verifyTools)(relevantTools, root);
122
+ const verificationById = new Map(verifications.map((verification) => [verification.id, verification]));
261
123
  const builtIn = relevantTools.filter((tool) => tool.ecosystem === "built-in");
262
124
  const externalTools = relevantTools.filter((tool) => tool.ecosystem !== "built-in");
263
- const available = externalTools.filter((tool) => isToolAvailable(tool, project));
264
- const missing = externalTools.filter((tool) => !isToolAvailable(tool, project));
265
- const npmPackages = missing
266
- .filter((tool) => tool.ecosystem === "npm" && tool.packageName)
267
- .map((tool) => tool.packageName);
268
- const pythonPackages = missing
269
- .filter((tool) => tool.ecosystem === "python" && tool.packageName)
270
- .map((tool) => tool.packageName);
125
+ const available = externalTools.filter((tool) => verificationById.get(tool.id)?.state === "verified");
126
+ const missing = externalTools.filter((tool) => verificationById.get(tool.id)?.state !== "verified");
127
+ const npmMissing = missing.filter((tool) => tool.ecosystem === "npm" && tool.packageName);
128
+ const pythonMissing = missing.filter((tool) => tool.ecosystem === "python" && tool.packageName);
129
+ const npmPackages = npmMissing.map((tool) => tool.packageName);
130
+ const pythonPackages = pythonMissing.map((tool) => tool.packageName);
271
131
  const manual = missing.filter((tool) => tool.ecosystem === "manual");
272
132
  const skipped = [];
273
133
  const commands = [];
@@ -277,35 +137,84 @@ async function createSetupPlan(root, include = "recommended") {
277
137
  commands.push(jsInstallCommand(root, manager, npmPackages));
278
138
  }
279
139
  else {
280
- skipped.push(...missing.filter((tool) => tool.ecosystem === "npm").map((tool) => ({
140
+ skipped.push(...npmMissing.map((tool) => ({
281
141
  ...tool,
282
142
  installHint: "Add a package.json first, then install this as a dev dependency."
283
143
  })));
284
144
  }
285
145
  }
286
146
  if (pythonPackages.length > 0) {
287
- const command = await pythonInstallCommand(root, project, pythonPackages);
147
+ const command = await pythonInstallCommand(root, project, pythonPackages, runtimes);
288
148
  if (command) {
289
149
  commands.push(command);
290
150
  }
291
151
  else {
292
- skipped.push(...missing.filter((tool) => tool.ecosystem === "python").map((tool) => ({
152
+ // Naming the actual obstacle matters: "no interpreter" and "no virtualenv"
153
+ // have different fixes, and reporting the wrong one wastes the user's time.
154
+ const obstacle = runtimes.python?.available
155
+ ? "Create or activate a Python virtualenv (.venv), then run"
156
+ : `No Python interpreter was found on PATH. Install Python, then run`;
157
+ skipped.push(...pythonMissing.map((tool) => ({
293
158
  ...tool,
294
- installHint: "Create or activate a Python virtualenv, then run: python -m pip install -U " + pythonPackages.join(" ")
159
+ installHint: `${obstacle}: python -m pip install -U ${pythonPackages.join(" ")}`
295
160
  })));
296
161
  }
297
162
  }
298
- return { project, builtIn, available, npmPackages, pythonPackages, manual, skipped, commands };
163
+ return { project, builtIn, available, npmPackages, pythonPackages, manual, skipped, commands, runtimes, verifications };
299
164
  }
300
165
  function renderToolList(prefix, tools) {
301
166
  if (tools.length === 0) {
302
167
  return [];
303
168
  }
304
- return [prefix, ...tools.map((tool) => `- ${tool.id}: ${tool.reason}${tool.installHint ? ` ${tool.installHint}` : ""}`), ""];
169
+ return [
170
+ prefix,
171
+ ...tools.map((tool) => `- ${tool.id}: ${tool.reason}${tool.installHint ? ` ${tool.installHint}` : ""}`),
172
+ ""
173
+ ];
174
+ }
175
+ function renderRuntimeLines(runtimes) {
176
+ const entries = Object.values(runtimes).filter(Boolean);
177
+ if (entries.length === 0) {
178
+ return [];
179
+ }
180
+ return [
181
+ "Runtimes",
182
+ ...entries.map((probe) => `- ${probe.engine}: ${probe.available ? probe.detail : `NOT AVAILABLE — ${probe.detail}`}`),
183
+ ""
184
+ ];
185
+ }
186
+ /**
187
+ * Renders verification results. Each line names the resolved path, because
188
+ * "installed" without a path is the claim that turned out to be unreliable.
189
+ */
190
+ function renderVerificationLines(verifications) {
191
+ if (verifications.length === 0) {
192
+ return [];
193
+ }
194
+ const lines = ["Verification (each tool resolved and run the way the scanner will run it)"];
195
+ for (const verification of [...verifications].sort((left, right) => left.id.localeCompare(right.id))) {
196
+ lines.push(`- ${(0, toolVerification_1.summarizeVerification)(verification)}`);
197
+ if (verification.probeCommand && verification.state === "verified") {
198
+ lines.push(` probe: ${verification.probeCommand}`);
199
+ }
200
+ if (verification.remediation && (0, toolVerification_1.isVerificationBlocking)(verification)) {
201
+ lines.push(` fix: ${verification.remediation}`);
202
+ }
203
+ }
204
+ lines.push("");
205
+ return lines;
305
206
  }
306
- function renderPlan(plan, include, results = []) {
207
+ function renderPlan({ plan, include, installResults = [], postInstall }) {
307
208
  const languages = activeLanguages(plan.project);
308
- const lines = ["VibeDoctor setup", "", `Detected languages: ${languages.length > 0 ? languages.join(", ") : "none"}`, `Package managers: ${plan.project.packageManagers.length > 0 ? plan.project.packageManagers.join(", ") : "none"}`, `Install set: ${include}`, ""];
209
+ const lines = [
210
+ "VibeDoctor setup",
211
+ "",
212
+ `Detected languages: ${languages.length > 0 ? languages.join(", ") : "none"}`,
213
+ `Package managers: ${plan.project.packageManagers.length > 0 ? plan.project.packageManagers.join(", ") : "none"}`,
214
+ `Install set: ${include}`,
215
+ ""
216
+ ];
217
+ lines.push(...renderRuntimeLines(plan.runtimes));
309
218
  lines.push(...renderToolList("Already built in", plan.builtIn));
310
219
  lines.push(...renderToolList("Already available", plan.available));
311
220
  if (plan.commands.length > 0) {
@@ -313,9 +222,9 @@ function renderPlan(plan, include, results = []) {
313
222
  }
314
223
  lines.push(...renderToolList("Manual installs", plan.manual));
315
224
  lines.push(...renderToolList("Skipped until project setup exists", plan.skipped));
316
- if (results.length > 0) {
225
+ if (installResults.length > 0) {
317
226
  lines.push("Install results");
318
- for (const result of results) {
227
+ for (const result of installResults) {
319
228
  lines.push(`- ${result.command}: ${result.status}${result.exitCode === null ? "" : ` (${result.exitCode})`}`);
320
229
  if (result.stderr.trim()) {
321
230
  lines.push(` ${result.stderr.trim().split(/\r?\n/)[0]}`);
@@ -323,8 +232,28 @@ function renderPlan(plan, include, results = []) {
323
232
  }
324
233
  lines.push("");
325
234
  }
326
- if (plan.commands.length > 0 && results.length === 0) {
327
- lines.push("Run `vibedoctor setup --apply` to install the automatable tools.");
235
+ // After applying, the verification pass is the authoritative result: an install
236
+ // command exiting zero is not evidence the scanner can run the tool.
237
+ const verifications = postInstall ?? plan.verifications;
238
+ lines.push(...renderVerificationLines(verifications));
239
+ const blocking = verifications.filter(toolVerification_1.isVerificationBlocking);
240
+ const runtimeMismatches = blocking.filter((verification) => verification.state === "incompatible_runtime");
241
+ if (postInstall) {
242
+ if (blocking.length === 0) {
243
+ lines.push("All selected tools verified. The next scan will use exactly these executables.");
244
+ }
245
+ else {
246
+ lines.push(`Setup did not complete: ${blocking.length} tool(s) could not be verified — ${blocking
247
+ .map((verification) => verification.id)
248
+ .join(", ")}.`, "The scan will report these as missing coverage rather than treating their silence as a pass.");
249
+ if (runtimeMismatches.length > 0) {
250
+ lines.push("", "Runtime mismatches are installed but unusable here. To keep them out of the way deliberately, add to vibedoctor.yml:", " runtime:", " deferred_tools:", ...runtimeMismatches.map((verification) => ` - ${verification.id}`));
251
+ }
252
+ }
253
+ lines.push("");
254
+ }
255
+ else if (plan.commands.length > 0) {
256
+ lines.push("Run `vibedoctor setup --apply` to install the automatable tools and verify each one.");
328
257
  }
329
258
  else if (plan.commands.length === 0 && plan.manual.length === 0 && plan.skipped.length === 0) {
330
259
  lines.push(`All relevant ${include} tools are already available.`);
@@ -355,14 +284,23 @@ async function runSetupCommand(root, options = {}) {
355
284
  const include = VALID_SETUP_INCLUDES.has(options.include ?? "recommended") ? (options.include ?? "recommended") : "recommended";
356
285
  const plan = await createSetupPlan(root, include);
357
286
  if (!options.apply) {
358
- return { output: renderPlan(plan, include), exitCode: 0 };
287
+ return { output: renderPlan({ plan, include }), exitCode: 0 };
359
288
  }
360
- const results = [];
289
+ const installResults = [];
361
290
  for (const command of plan.commands) {
362
- results.push(await (0, toolRunner_1.runCommand)(command));
291
+ installResults.push(await (0, toolRunner_1.runCommand)(command));
363
292
  }
293
+ // Re-probe runtimes as well: an install can add the interpreter or venv that
294
+ // was missing when the plan was built.
295
+ const relevantTools = resolveTools(include).filter((tool) => appliesToProject(tool, plan.project));
296
+ const postInstall = await (0, toolVerification_1.verifyTools)(relevantTools, root);
297
+ const installFailed = installResults.some((result) => result.status === "error" || result.status === "timeout" || result.status === "skipped");
298
+ const verificationFailed = postInstall.some(toolVerification_1.isVerificationBlocking);
364
299
  return {
365
- output: renderPlan(plan, include, results),
366
- exitCode: results.some((result) => result.status === "error" || result.status === "timeout" || result.status === "skipped") ? 1 : 0
300
+ output: renderPlan({ plan, include, installResults, postInstall }),
301
+ // Setup fails when a tool cannot be verified, even if every install command
302
+ // succeeded. Reporting success for an unusable tool is the failure mode this
303
+ // exit code exists to prevent.
304
+ exitCode: installFailed || verificationFailed ? 1 : 0
367
305
  };
368
306
  }
package/dist/cli/index.js CHANGED
@@ -47,10 +47,10 @@ async function main() {
47
47
  });
48
48
  program
49
49
  .command("scan")
50
- .description("Run relevant checks and print a short health report")
51
- .option("--changed", "Only report changed-file issues")
52
- .option("--quick", "Quick mode")
53
- .option("--full", "Full mode")
50
+ .description("Run the full applicable diagnosis and print a ranked health report")
51
+ .option("--changed", "Optimize for git-changed files")
52
+ .option("--quick", "Narrower opt-in profile")
53
+ .option("--full", "Alias for the default full applicable diagnosis")
54
54
  .option("--category <categories>", "Comma-separated finding categories")
55
55
  .option("--report <format>", "terminal|json|html|agent|agent-json", "terminal")
56
56
  .action(async (options) => {
@@ -0,0 +1,39 @@
1
+ import type { AgentPlan, RecoveryAction, ScanCompleteness, ScanOutput, ToolStatusSummary } from "./engine";
2
+ import type { EvidenceGrade, Finding, FindingCategory, Severity, Confidence } from "./finding";
3
+ import { type FindingLocation, type RootCauseGroup } from "./findingCorrelator";
4
+ export type AgentIssue = {
5
+ id: string;
6
+ ruleId: string;
7
+ title: string;
8
+ severity: Severity;
9
+ confidence: Confidence;
10
+ evidenceGrade: EvidenceGrade;
11
+ category: FindingCategory;
12
+ locations: FindingLocation[];
13
+ impact: string;
14
+ likelyRootCause: string;
15
+ supportingEngines: string[];
16
+ recommendedRepair: string;
17
+ verificationGuidance: string;
18
+ };
19
+ export type AgentDiagnosisSummary = {
20
+ score: number;
21
+ mode: ScanOutput["mode"];
22
+ planned: number;
23
+ completed: number;
24
+ findingCount: number;
25
+ blockerCount: number;
26
+ topIssueCount: number;
27
+ };
28
+ export type AgentDiagnosis = {
29
+ completeness: ScanCompleteness;
30
+ summary: AgentDiagnosisSummary;
31
+ topIssues: AgentIssue[];
32
+ rootCauseGroups: RootCauseGroup[];
33
+ toolStatuses: ToolStatusSummary[];
34
+ recoveryActions: RecoveryAction[];
35
+ recommendedOrder: string[];
36
+ agentPlan: AgentPlan;
37
+ };
38
+ export declare function findingToAgentIssue(finding: Finding, testCommands?: string[]): AgentIssue;
39
+ export declare function buildAgentDiagnosis(scan: ScanOutput): AgentDiagnosis;
@@ -0,0 +1,96 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.findingToAgentIssue = findingToAgentIssue;
4
+ exports.buildAgentDiagnosis = buildAgentDiagnosis;
5
+ const findingCorrelator_1 = require("./findingCorrelator");
6
+ const riskRanker_1 = require("./riskRanker");
7
+ function describeImpact(finding) {
8
+ if (finding.category === "security") {
9
+ return "Credentials or vulnerable dependencies can be exploited if this reaches a shared or deployed tree.";
10
+ }
11
+ if (finding.source === "flow-doctor") {
12
+ return "A request or error path does not match the implemented contract, so the feature can fail at runtime.";
13
+ }
14
+ if (finding.category === "correctness" || finding.category === "tests") {
15
+ return "Type, lint, or test evidence indicates the code may not behave as written.";
16
+ }
17
+ if (finding.category === "privacy") {
18
+ return "Personal data may be handled without a visible control.";
19
+ }
20
+ if (finding.category === "dead_code" || finding.category === "leftovers") {
21
+ return "Unused or leftover code increases review cost and hides real defects.";
22
+ }
23
+ return finding.message;
24
+ }
25
+ function recommendedRepair(finding) {
26
+ if (finding.remediation?.steps.length) {
27
+ return finding.remediation.steps.join(" ");
28
+ }
29
+ if (finding.agentInstruction) {
30
+ return finding.agentInstruction;
31
+ }
32
+ if (finding.fixCommand) {
33
+ return `Apply: ${finding.fixCommand}`;
34
+ }
35
+ return finding.message;
36
+ }
37
+ function verificationGuidance(finding, testCommands) {
38
+ const test = testCommands[0];
39
+ const parts = [
40
+ finding.file ? `Re-read ${finding.file}${finding.startLine ? `:${finding.startLine}` : ""} after the edit.` : undefined,
41
+ test ? `Run \`${test}\`.` : undefined,
42
+ "Run `vibedoctor scan --changed --report agent-json` and confirm this finding id is gone."
43
+ ];
44
+ return parts.filter(Boolean).join(" ");
45
+ }
46
+ function findingToAgentIssue(finding, testCommands = []) {
47
+ return {
48
+ id: finding.id,
49
+ ruleId: finding.evidence?.toolRawId ?? finding.title,
50
+ title: finding.title,
51
+ severity: finding.severity,
52
+ confidence: finding.confidence,
53
+ evidenceGrade: finding.evidenceGrade ?? "observed",
54
+ category: finding.category,
55
+ locations: [{ file: finding.file, startLine: finding.startLine, endLine: finding.endLine }],
56
+ impact: describeImpact(finding),
57
+ likelyRootCause: (0, findingCorrelator_1.inferRootCause)(finding),
58
+ supportingEngines: Array.from(new Set([finding.source, ...(finding.corroboratedBy ?? [])])),
59
+ recommendedRepair: recommendedRepair(finding),
60
+ verificationGuidance: verificationGuidance(finding, testCommands)
61
+ };
62
+ }
63
+ function buildAgentDiagnosis(scan) {
64
+ const ranked = (0, riskRanker_1.rankFindings)(scan.findings);
65
+ const groups = (0, findingCorrelator_1.correlateFindings)(ranked);
66
+ const topFindings = ranked.slice(0, 8);
67
+ const topIssues = topFindings.map((finding) => {
68
+ const group = groups.find((candidate) => candidate.findingIds.includes(finding.id));
69
+ const issue = findingToAgentIssue(finding, scan.testCommands);
70
+ if (group) {
71
+ issue.supportingEngines = group.supportingEngines;
72
+ issue.likelyRootCause = group.likelyRootCause;
73
+ issue.locations = group.locations;
74
+ }
75
+ return issue;
76
+ });
77
+ const recommendedOrder = topIssues.map((issue) => issue.id);
78
+ return {
79
+ completeness: scan.completeness,
80
+ summary: {
81
+ score: scan.score.overall,
82
+ mode: scan.mode,
83
+ planned: scan.completeness.planned,
84
+ completed: scan.completeness.completed,
85
+ findingCount: scan.findings.length,
86
+ blockerCount: scan.blockers.length,
87
+ topIssueCount: topIssues.length
88
+ },
89
+ topIssues,
90
+ rootCauseGroups: groups,
91
+ toolStatuses: scan.toolStatuses,
92
+ recoveryActions: scan.recoveryActions,
93
+ recommendedOrder,
94
+ agentPlan: scan.agentPlan
95
+ };
96
+ }