@neuralaxis/vibedoctor 0.1.2 → 0.1.3

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 (43) hide show
  1. package/README.md +17 -1
  2. package/dist/adapters/biome.d.ts +1 -1
  3. package/dist/adapters/biome.js +7 -4
  4. package/dist/adapters/coveragePy.js +3 -0
  5. package/dist/adapters/deptry.js +21 -2
  6. package/dist/adapters/knip.js +29 -4
  7. package/dist/adapters/lizard.d.ts +1 -1
  8. package/dist/adapters/lizard.js +51 -2
  9. package/dist/adapters/osvScanner.js +14 -2
  10. package/dist/adapters/privacyDetector.js +5 -5
  11. package/dist/adapters/ruff.d.ts +1 -1
  12. package/dist/adapters/ruff.js +4 -1
  13. package/dist/adapters/semgrep.d.ts +1 -1
  14. package/dist/adapters/semgrep.js +17 -3
  15. package/dist/adapters/shared.d.ts +1 -0
  16. package/dist/adapters/shared.js +22 -0
  17. package/dist/adapters/tsc.js +43 -18
  18. package/dist/adapters/vulture.d.ts +1 -1
  19. package/dist/adapters/vulture.js +25 -6
  20. package/dist/agentPack/templates/index.js +7 -4
  21. package/dist/agentPack/templates/skills.js +10 -4
  22. package/dist/cli/commands/agentPlan.js +9 -1
  23. package/dist/cli/commands/init.js +12 -4
  24. package/dist/cli/commands/scan.d.ts +1 -1
  25. package/dist/cli/commands/scan.js +4 -0
  26. package/dist/cli/commands/setup.js +3 -1
  27. package/dist/cli/commands/tool.d.ts +4 -0
  28. package/dist/cli/commands/tool.js +11 -0
  29. package/dist/cli/index.js +12 -0
  30. package/dist/core/config.d.ts +6 -0
  31. package/dist/core/config.js +29 -1
  32. package/dist/core/engine.d.ts +32 -1
  33. package/dist/core/engine.js +173 -27
  34. package/dist/core/projectDetector.d.ts +1 -1
  35. package/dist/core/projectDetector.js +29 -12
  36. package/dist/core/toolRunner.d.ts +1 -0
  37. package/dist/core/toolRunner.js +73 -11
  38. package/dist/mcp/tools/shared.js +8 -1
  39. package/dist/reporters/agent.js +8 -0
  40. package/dist/reporters/html.js +4 -2
  41. package/dist/reporters/json.js +2 -0
  42. package/dist/reporters/markdown.js +8 -1
  43. package/package.json +6 -2
@@ -7,6 +7,14 @@ const agent_1 = require("../../reporters/agent");
7
7
  async function runAgentPlanCommand(root, format = "markdown", target = undefined) {
8
8
  const scan = await (0, engine_1.runScan)(root, "default");
9
9
  const { policy } = await (0, policy_1.loadAgentPolicy)(root);
10
- const plan = (0, engine_1.createAgentPlan)({ findings: scan.findings, score: scan.score, skippedTools: scan.skippedTools, testCommands: scan.testCommands }, { policy, target: target ?? "generic" });
10
+ const plan = (0, engine_1.createAgentPlan)({
11
+ findings: scan.findings,
12
+ score: scan.score,
13
+ skippedTools: scan.skippedTools,
14
+ toolStatuses: scan.toolStatuses,
15
+ completeness: scan.completeness,
16
+ recoveryActions: scan.recoveryActions,
17
+ testCommands: scan.testCommands
18
+ }, { policy, target: target ?? "generic" });
11
19
  return format === "json" ? `${(0, agent_1.renderAgentJson)(plan)}\n` : (0, agent_1.renderAgentMarkdown)(plan);
12
20
  }
@@ -49,10 +49,18 @@ baseline:
49
49
  file: .vibedoctor/baseline.json
50
50
  fail_only_on_new_issues: true
51
51
 
52
- score:
53
- minimum: ${config_1.defaultConfig.score.minimum}
54
-
55
- checks:
52
+ score:
53
+ minimum: ${config_1.defaultConfig.score.minimum}
54
+
55
+ runtime:
56
+ default_timeout_seconds: ${config_1.defaultConfig.runtime.defaultTimeoutSeconds}
57
+ tool_timeouts:
58
+ biome: ${config_1.defaultConfig.runtime.toolTimeouts.biome}
59
+ semgrep: ${config_1.defaultConfig.runtime.toolTimeouts.semgrep}
60
+ required_tools: []
61
+ fail_on_incomplete_scan: false
62
+
63
+ checks:
56
64
  security:
57
65
  enabled: true
58
66
  fail_on_secrets: true
@@ -4,7 +4,7 @@ export type ScanCommandResult = {
4
4
  output: string;
5
5
  exitCode: number;
6
6
  };
7
- export declare function determineExitCode(scan: Pick<ScanOutput, "score" | "findings">, config: VibeDoctorConfig): number;
7
+ export declare function determineExitCode(scan: Pick<ScanOutput, "score" | "findings"> & Partial<Pick<ScanOutput, "completeness">>, config: VibeDoctorConfig): number;
8
8
  export declare function runScanCommand(root: string, options: {
9
9
  changed?: boolean;
10
10
  quick?: boolean;
@@ -23,6 +23,10 @@ function isReviewedFalsePositive(finding) {
23
23
  return finding.evidence?.reviewState === "false_positive";
24
24
  }
25
25
  function determineExitCode(scan, config) {
26
+ if (scan.completeness &&
27
+ (scan.completeness.status === "invalid" || (config.runtime.failOnIncompleteScan && scan.completeness.status !== "complete"))) {
28
+ return 2;
29
+ }
26
30
  if (scan.score.overall < config.score.minimum) {
27
31
  return 1;
28
32
  }
@@ -8,6 +8,7 @@ exports.runSetupCommand = runSetupCommand;
8
8
  const node_path_1 = __importDefault(require("node:path"));
9
9
  const toolRunner_1 = require("../../core/toolRunner");
10
10
  const projectDetector_1 = require("../../core/projectDetector");
11
+ const config_1 = require("../../core/config");
11
12
  const paths_1 = require("../../core/paths");
12
13
  const VALID_SETUP_INCLUDES = new Set(["essential", "recommended", "all", "npm", "python", "manual", "built-in"]);
13
14
  const essentialTools = [
@@ -253,7 +254,8 @@ function resolveTools(include) {
253
254
  return combined.filter((tool) => tool.ecosystem === include);
254
255
  }
255
256
  async function createSetupPlan(root, include = "recommended") {
256
- const project = await (0, projectDetector_1.detectProject)(root);
257
+ const { config } = await (0, config_1.loadConfig)(root);
258
+ const project = await (0, projectDetector_1.detectProject)(root, config.paths.exclude);
257
259
  const tools = resolveTools(include);
258
260
  const relevantTools = tools.filter((tool) => appliesToProject(tool, project));
259
261
  const builtIn = relevantTools.filter((tool) => tool.ecosystem === "built-in");
@@ -0,0 +1,4 @@
1
+ export declare function runToolRetryCommand(root: string, toolId: string, timeoutSeconds?: number): Promise<{
2
+ output: string;
3
+ exitCode: number;
4
+ }>;
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.runToolRetryCommand = runToolRetryCommand;
4
+ const engine_1 = require("../../core/engine");
5
+ async function runToolRetryCommand(root, toolId, timeoutSeconds) {
6
+ const result = await (0, engine_1.retryTool)(root, toolId, timeoutSeconds);
7
+ return {
8
+ output: `${JSON.stringify(result, null, 2)}\n`,
9
+ exitCode: result.status === "ok" ? 0 : 2
10
+ };
11
+ }
package/dist/cli/index.js CHANGED
@@ -18,6 +18,7 @@ const privacyReview_1 = require("./commands/privacyReview");
18
18
  const report_1 = require("./commands/report");
19
19
  const scan_1 = require("./commands/scan");
20
20
  const setup_1 = require("./commands/setup");
21
+ const tool_1 = require("./commands/tool");
21
22
  function getVersion() {
22
23
  try {
23
24
  // After `npm version patch` + publish, package.json is shipped (see "files").
@@ -122,6 +123,17 @@ async function main() {
122
123
  process.stdout.write(await (0, agent_1.runAgentSyncCommand)(process.cwd(), options));
123
124
  process.exit(0);
124
125
  });
126
+ const tool = program.command("tool").description("Inspect and recover individual scanner tools");
127
+ tool
128
+ .command("retry")
129
+ .description("Retry one scanner with an extended deadline")
130
+ .argument("<tool-id>")
131
+ .option("--timeout <seconds>", "Override the retry deadline in seconds", (value) => Number(value))
132
+ .action(async (toolId, options) => {
133
+ const result = await (0, tool_1.runToolRetryCommand)(process.cwd(), toolId, options.timeout);
134
+ process.stdout.write(result.output);
135
+ process.exit(result.exitCode);
136
+ });
125
137
  agent
126
138
  .command("plugin")
127
139
  .description("Generate installable Codex and Claude plugin bundle files")
@@ -17,6 +17,12 @@ export type VibeDoctorConfig = {
17
17
  score: {
18
18
  minimum: number;
19
19
  };
20
+ runtime: {
21
+ defaultTimeoutSeconds: number;
22
+ toolTimeouts: Record<string, number>;
23
+ requiredTools: string[];
24
+ failOnIncompleteScan: boolean;
25
+ };
20
26
  checks: {
21
27
  security: {
22
28
  enabled: boolean;
@@ -48,6 +48,15 @@ exports.defaultConfig = {
48
48
  score: {
49
49
  minimum: 80
50
50
  },
51
+ runtime: {
52
+ defaultTimeoutSeconds: 120,
53
+ toolTimeouts: {
54
+ biome: 180,
55
+ semgrep: 300
56
+ },
57
+ requiredTools: [],
58
+ failOnIncompleteScan: false
59
+ },
51
60
  checks: {
52
61
  security: {
53
62
  enabled: true,
@@ -149,10 +158,11 @@ async function findConfigFile(root) {
149
158
  return undefined;
150
159
  }
151
160
  function normalizeRawConfig(raw) {
152
- const { baseline: _baseline, checks: _checks, output: _output, ...rest } = raw;
161
+ const { baseline: _baseline, checks: _checks, output: _output, runtime: _runtime, ...rest } = raw;
153
162
  const rawChecks = raw.checks;
154
163
  const rawBaseline = raw.baseline;
155
164
  const rawOutput = raw.output;
165
+ const rawRuntime = raw.runtime;
156
166
  const rawDeadCode = (rawChecks?.deadCode ?? rawChecks?.dead_code);
157
167
  const rawLeftovers = rawChecks?.leftovers;
158
168
  const rawRefactor = (rawChecks?.refactorReadiness ?? rawChecks?.refactor_readiness);
@@ -165,6 +175,24 @@ function normalizeRawConfig(raw) {
165
175
  const rawPresidio = (rawPrivacy?.presidio ?? {});
166
176
  return {
167
177
  ...rest,
178
+ ...(rawRuntime
179
+ ? {
180
+ runtime: {
181
+ defaultTimeoutSeconds: rawRuntime.defaultTimeoutSeconds ??
182
+ rawRuntime.default_timeout_seconds ??
183
+ exports.defaultConfig.runtime.defaultTimeoutSeconds,
184
+ toolTimeouts: rawRuntime.toolTimeouts ??
185
+ rawRuntime.tool_timeouts ??
186
+ exports.defaultConfig.runtime.toolTimeouts,
187
+ requiredTools: rawRuntime.requiredTools ??
188
+ rawRuntime.required_tools ??
189
+ exports.defaultConfig.runtime.requiredTools,
190
+ failOnIncompleteScan: rawRuntime.failOnIncompleteScan ??
191
+ rawRuntime.fail_on_incomplete_scan ??
192
+ exports.defaultConfig.runtime.failOnIncompleteScan
193
+ }
194
+ }
195
+ : {}),
168
196
  ...(rawOutput
169
197
  ? {
170
198
  output: {
@@ -17,14 +17,33 @@ export type AgentPlanTask = {
17
17
  };
18
18
  export type AgentPlan = {
19
19
  goal: string;
20
+ status: ScanExecutionStatus;
20
21
  target: AgentPlanTarget;
21
22
  workflow: string[];
22
23
  rules: string[];
23
24
  allowedActions: string[];
24
25
  forbiddenActions: string[];
25
26
  doNotTouch: string[];
27
+ recoveryActions: RecoveryAction[];
26
28
  tasks: AgentPlanTask[];
27
29
  };
30
+ export type ScanExecutionStatus = "complete" | "partial" | "invalid";
31
+ export type RecoveryAction = {
32
+ id: string;
33
+ tool: string;
34
+ command: string;
35
+ successCondition: string;
36
+ onFailure: string;
37
+ };
38
+ export type ScanCompleteness = {
39
+ status: ScanExecutionStatus;
40
+ comparable: boolean;
41
+ planned: number;
42
+ completed: number;
43
+ incompleteTools: string[];
44
+ requiredIncompleteTools: string[];
45
+ reason?: string;
46
+ };
28
47
  export type ToolStatusSummary = {
29
48
  id: string;
30
49
  status: ToolResult["status"];
@@ -51,6 +70,8 @@ export type ScanOutput = {
51
70
  refactorCandidates: Finding[];
52
71
  toolStatuses: ToolStatusSummary[];
53
72
  skippedTools: SkippedToolSummary[];
73
+ completeness: ScanCompleteness;
74
+ recoveryActions: RecoveryAction[];
54
75
  testCommands: string[];
55
76
  agentPlan: AgentPlan;
56
77
  configPath?: string;
@@ -68,17 +89,27 @@ export type ExplainPayload = {
68
89
  relatedFindings: Finding[];
69
90
  skippedTools: SkippedToolSummary[];
70
91
  };
92
+ export type ToolRetryOutput = {
93
+ tool: string;
94
+ status: ToolResult["status"];
95
+ timeoutSeconds: number;
96
+ findings: Finding[];
97
+ message?: string;
98
+ successCondition: string;
99
+ nextAction: string;
100
+ };
71
101
  type FilterScanOptions = {
72
102
  policy?: AgentPolicy;
73
103
  target?: AgentPlanTarget;
74
104
  };
75
- export declare function createAgentPlan(scan: Pick<ScanOutput, "findings" | "score" | "skippedTools"> & {
105
+ export declare function createAgentPlan(scan: Pick<ScanOutput, "findings" | "score" | "skippedTools"> & Partial<Pick<ScanOutput, "toolStatuses" | "completeness" | "recoveryActions">> & {
76
106
  testCommands?: string[];
77
107
  }, options?: {
78
108
  policy?: AgentPolicy;
79
109
  target?: AgentPlanTarget;
80
110
  }): AgentPlan;
81
111
  export declare function runScan(root: string, mode?: ScanMode): Promise<ScanOutput>;
112
+ export declare function retryTool(root: string, toolId: string, timeoutSeconds?: number): Promise<ToolRetryOutput>;
82
113
  export declare function filterScanByCategories(scan: ScanOutput, categories: FindingCategory[], options?: FilterScanOptions): ScanOutput;
83
114
  export declare function buildSummaryLines(scan: ScanOutput): string[];
84
115
  export declare function buildExplainPayload(scan: ScanOutput, findingId: string): ExplainPayload;
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createAgentPlan = createAgentPlan;
4
4
  exports.runScan = runScan;
5
+ exports.retryTool = retryTool;
5
6
  exports.filterScanByCategories = filterScanByCategories;
6
7
  exports.buildSummaryLines = buildSummaryLines;
7
8
  exports.buildExplainPayload = buildExplainPayload;
@@ -174,8 +175,18 @@ function targetScore(overall) {
174
175
  function createAgentPlan(scan, options = {}) {
175
176
  const policy = options.policy ?? policy_1.defaultAgentPolicy;
176
177
  const target = options.target ?? "generic";
178
+ const toolStatuses = scan.toolStatuses ?? [];
179
+ const completeness = scan.completeness ?? {
180
+ status: scan.skippedTools.length > 0 ? "partial" : "complete",
181
+ comparable: scan.skippedTools.length === 0,
182
+ planned: 0,
183
+ completed: 0,
184
+ incompleteTools: scan.skippedTools.map((tool) => tool.id),
185
+ requiredIncompleteTools: []
186
+ };
187
+ const recoveryActions = scan.recoveryActions ?? buildRecoveryActions(toolStatuses, scan.skippedTools);
177
188
  const ordered = sortFindings(scan.findings);
178
- const tasks = ordered.slice(0, 5).map((finding, index) => ({
189
+ const tasks = (completeness.status === "invalid" ? [] : ordered.slice(0, 5)).map((finding, index) => ({
179
190
  id: `task-${index + 1}`,
180
191
  title: finding.title,
181
192
  priority: index + 1,
@@ -186,9 +197,12 @@ function createAgentPlan(scan, options = {}) {
186
197
  commands: buildTaskCommands(finding, policy)
187
198
  }));
188
199
  return {
189
- goal: `Raise health score from ${scan.score.overall} to ${targetScore(scan.score.overall)}`,
200
+ goal: completeness.status === "complete"
201
+ ? `Raise health score from ${scan.score.overall} to ${targetScore(scan.score.overall)}`
202
+ : "Recover incomplete checks before changing code, then improve validated findings",
203
+ status: completeness.status,
190
204
  target,
191
- workflow: ["scan", "plan", "safe fix", "edit carefully", "verify", "scan again", "summarize"],
205
+ workflow: ["scan", "validate completeness", "recover tools", "plan", "safe fix", "edit carefully", "verify", "scan again", "summarize"],
192
206
  rules: [
193
207
  "Fix blockers before cleanup work.",
194
208
  "Do not delete low-confidence dead code.",
@@ -197,13 +211,20 @@ function createAgentPlan(scan, options = {}) {
197
211
  ],
198
212
  allowedActions: (0, policy_1.getAllowedActions)(policy),
199
213
  forbiddenActions: (0, policy_1.getForbiddenActions)(policy),
200
- doNotTouch: scan.skippedTools.map((tool) => `Do not assume ${tool.id} was fully checked because the tool was skipped.`),
214
+ doNotTouch: [
215
+ ...scan.skippedTools.map((tool) => `Do not assume ${tool.id} was fully checked because the tool was skipped.`),
216
+ ...toolStatuses
217
+ .filter((tool) => tool.status === "timeout" || tool.status === "error")
218
+ .map((tool) => `Do not treat the health score as complete because ${tool.id} ${tool.status === "timeout" ? "timed out" : "failed"}.`)
219
+ ],
220
+ recoveryActions,
201
221
  tasks
202
222
  };
203
223
  }
204
224
  function buildScanOutput(options) {
205
225
  const summary = summarizeFindings(options.findings);
206
226
  const policy = options.policy ?? policy_1.defaultAgentPolicy;
227
+ const recoveryActions = buildRecoveryActions(options.toolStatuses, options.skippedTools);
207
228
  return {
208
229
  root: options.root,
209
230
  mode: options.mode,
@@ -219,11 +240,16 @@ function buildScanOutput(options) {
219
240
  refactorCandidates: summary.refactorCandidates,
220
241
  toolStatuses: [...options.toolStatuses].sort((left, right) => left.id.localeCompare(right.id)),
221
242
  skippedTools: [...options.skippedTools].sort((left, right) => left.id.localeCompare(right.id)),
243
+ completeness: options.completeness,
244
+ recoveryActions,
222
245
  testCommands: options.testCommands,
223
246
  agentPlan: createAgentPlan({
224
247
  findings: summary.ordered,
225
248
  score: options.score,
249
+ toolStatuses: options.toolStatuses,
226
250
  skippedTools: options.skippedTools,
251
+ completeness: options.completeness,
252
+ recoveryActions,
227
253
  testCommands: options.testCommands
228
254
  }, { policy, target: options.target }),
229
255
  configPath: options.configPath
@@ -245,12 +271,40 @@ function summarizeToolStatus(status) {
245
271
  const message = rawMessage.length > 300 ? `${rawMessage.slice(0, 297)}...` : rawMessage;
246
272
  return { message, command: status.command };
247
273
  }
274
+ // Tools that intentionally use a non-zero exit for "findings reported" or emit
275
+ // experimental warnings on otherwise-successful runs. Shared by runScan and
276
+ // retryTool so a tool never "fails" in one path while "succeeding" in the other.
277
+ function forgiveKnownToolQuirks(toolId, result, findingsCount = 0) {
278
+ if (result.status !== "error") {
279
+ return undefined;
280
+ }
281
+ if (findingsCount > 0) {
282
+ return { status: "ok", message: "Reported issues (debt surfaced as findings)" };
283
+ }
284
+ const output = `${result.stderr}\n${result.stdout}`;
285
+ if (toolId === "biome" && /unstable|experimental/i.test(output)) {
286
+ return { status: "ok" };
287
+ }
288
+ if (toolId === "knip" && result.stdout.trim().startsWith("{")) {
289
+ return { status: "ok", message: "Reported issues (debt surfaced as findings)" };
290
+ }
291
+ if (toolId === "vitest" && /Loaded .*vitest@.*coverage-v8/i.test(output)) {
292
+ return { status: "ok" };
293
+ }
294
+ if (toolId === "osv-scanner" && result.stdout.trim().startsWith("{")) {
295
+ return { status: "ok", message: "Reported vulnerabilities as findings" };
296
+ }
297
+ return undefined;
298
+ }
248
299
  async function runAdapter(adapter, ctx) {
249
300
  if (adapter.runStandalone) {
250
301
  return adapter.runStandalone(ctx);
251
302
  }
252
303
  if (adapter.buildScanCommand && adapter.parseResult) {
253
- const status = await (0, toolRunner_1.runCommand)(adapter.buildScanCommand(ctx), adapter.installHint);
304
+ const command = adapter.buildScanCommand(ctx);
305
+ const timeoutSeconds = ctx.config.runtime.toolTimeouts[adapter.id] ?? ctx.config.runtime.defaultTimeoutSeconds;
306
+ command.timeoutMs = timeoutSeconds * 1000;
307
+ const status = await (0, toolRunner_1.runCommand)(command, adapter.installHint);
254
308
  if (status.status === "skipped") {
255
309
  return { findings: [], status };
256
310
  }
@@ -279,7 +333,8 @@ async function runAdapter(adapter, ctx) {
279
333
  };
280
334
  }
281
335
  async function runScan(root, mode = "default") {
282
- const [{ config, configPath }, { policy }, project] = await Promise.all([(0, config_1.loadConfig)(root), (0, policy_1.loadAgentPolicy)(root), (0, projectDetector_1.detectProject)(root)]);
336
+ const [{ config, configPath }, { policy }] = await Promise.all([(0, config_1.loadConfig)(root), (0, policy_1.loadAgentPolicy)(root)]);
337
+ const project = await (0, projectDetector_1.detectProject)(root, config.paths.exclude);
283
338
  const plan = await (0, scanPlanner_1.createScanPlan)(project, config, [...ALL_ADAPTERS], mode);
284
339
  const ctx = { root, project, config, scanMode: mode };
285
340
  const selectedAdapters = ALL_ADAPTERS.filter((adapter) => plan.adapterIds.includes(adapter.id));
@@ -302,26 +357,39 @@ async function runScan(root, mode = "default") {
302
357
  });
303
358
  continue;
304
359
  }
305
- toolStatuses.push({ id: adapter.id, status: result.status.status, ...summarizeToolStatus(result.status) });
306
- }
307
- // Ouroboros/self-scan improvement: normalize statuses for tools that intentionally use non-zero exit for "findings reported"
308
- // or emit experimental warnings on otherwise-successful report formats (biome --reporter=json, knip exit-on-issues).
309
- // This prevents noise in "ERRORED TOOLS" while still surfacing real parse/crash errors.
310
- for (const ts of toolStatuses) {
311
- if (ts.id === "biome" && /unstable|experimental/i.test(ts.message || "")) {
312
- ts.status = "ok";
313
- ts.message = undefined;
314
- }
315
- if (ts.id === "knip" && ts.status === "error" && (ts.message || "").trim().startsWith("{")) {
316
- ts.status = "ok";
317
- ts.message = "Reported issues (debt surfaced as findings)";
318
- }
319
- if (ts.id === "vitest" && /Loaded .*vitest@.*coverage-v8/i.test(ts.message || "")) {
320
- // Vitest coverage adapter produces startup "Loaded ..." logs; treat as success when the dependency is available and a report was produced.
321
- ts.status = "ok";
322
- ts.message = undefined;
323
- }
360
+ const forgiven = forgiveKnownToolQuirks(adapter.id, result.status, result.findings.length);
361
+ const summarized = summarizeToolStatus(result.status);
362
+ toolStatuses.push({
363
+ id: adapter.id,
364
+ status: forgiven?.status ?? result.status.status,
365
+ ...summarized,
366
+ ...(forgiven ? { message: forgiven.message } : {})
367
+ });
324
368
  }
369
+ const incompleteTools = Array.from(new Set([
370
+ ...skippedTools.map((tool) => tool.id),
371
+ ...toolStatuses.filter((tool) => tool.status === "error" || tool.status === "timeout").map((tool) => tool.id)
372
+ ])).sort();
373
+ // Skipped tools can include checks that were never selected as adapters
374
+ // (built-in checks, mode-filtered tools); count them in the denominator so
375
+ // "completed" never underflows.
376
+ const plannedIds = new Set([...selectedAdapters.map((adapter) => adapter.id), ...incompleteTools]);
377
+ const requiredIncompleteTools = incompleteTools.filter((id) => config.runtime.requiredTools.includes(id));
378
+ const completeness = {
379
+ status: incompleteTools.length === 0
380
+ ? "complete"
381
+ : requiredIncompleteTools.length > 0 || config.runtime.failOnIncompleteScan
382
+ ? "invalid"
383
+ : "partial",
384
+ comparable: incompleteTools.length === 0,
385
+ planned: plannedIds.size,
386
+ completed: plannedIds.size - incompleteTools.length,
387
+ incompleteTools,
388
+ requiredIncompleteTools,
389
+ reason: incompleteTools.length > 0
390
+ ? `${incompleteTools.length} of ${plannedIds.size} planned checks did not complete.`
391
+ : undefined
392
+ };
325
393
  let deadChainFindings = [];
326
394
  if (config.checks.deadCode.enabled) {
327
395
  const rawDead = await (0, customDeadChain_1.detectDeadChains)(project, findings, config);
@@ -346,12 +414,79 @@ async function runScan(root, mode = "default") {
346
414
  score,
347
415
  toolStatuses,
348
416
  skippedTools,
417
+ completeness,
349
418
  testCommands: project.testCommands,
350
419
  policy,
351
420
  configPath,
352
421
  privacyReview: privacyReview?.summary
353
422
  });
354
423
  }
424
+ async function retryTool(root, toolId, timeoutSeconds) {
425
+ const { config } = await (0, config_1.loadConfig)(root);
426
+ const project = await (0, projectDetector_1.detectProject)(root, config.paths.exclude);
427
+ const adapter = ALL_ADAPTERS.find((candidate) => candidate.id === toolId);
428
+ if (!adapter || !adapter.buildScanCommand || !adapter.parseResult) {
429
+ return {
430
+ tool: toolId,
431
+ status: "skipped",
432
+ timeoutSeconds: timeoutSeconds ?? config.runtime.defaultTimeoutSeconds,
433
+ findings: [],
434
+ message: `Tool ${toolId} is unknown or does not support isolated retry.`,
435
+ successCondition: `${toolId} completes with status ok`,
436
+ nextAction: "Run vibedoctor scan --full --report agent-json and request human review if the tool remains incomplete."
437
+ };
438
+ }
439
+ const ctx = { root, project, config, scanMode: "full" };
440
+ const seconds = timeoutSeconds ?? Math.max(config.runtime.defaultTimeoutSeconds, (config.runtime.toolTimeouts[toolId] ?? config.runtime.defaultTimeoutSeconds) * 2);
441
+ const command = adapter.buildScanCommand(ctx);
442
+ command.timeoutMs = seconds * 1000;
443
+ const result = await (0, toolRunner_1.runCommand)(command, adapter.installHint);
444
+ let parseError;
445
+ let findings = [];
446
+ if (result.status !== "skipped") {
447
+ try {
448
+ findings = adapter.parseResult(result, ctx) ?? [];
449
+ }
450
+ catch (error) {
451
+ // A run that produced unparseable output is not a success; report it so
452
+ // agents do not mistake "ok with zero findings" for a clean result.
453
+ parseError = `Could not parse ${toolId} output: ${error instanceof Error ? error.message : String(error)}`;
454
+ }
455
+ }
456
+ const forgiven = forgiveKnownToolQuirks(toolId, result, findings.length);
457
+ const status = parseError ? "error" : forgiven?.status ?? result.status;
458
+ const summary = summarizeToolStatus(result);
459
+ return {
460
+ tool: toolId,
461
+ status,
462
+ timeoutSeconds: seconds,
463
+ findings,
464
+ message: parseError ?? forgiven?.message ?? summary.message,
465
+ successCondition: `${toolId} completes with status ok`,
466
+ nextAction: status === "ok"
467
+ ? "Run vibedoctor scan --full --report agent-json to produce a comparable health result."
468
+ : `Keep the scan partial and disclose missing ${toolId} coverage before changing risky code.`
469
+ };
470
+ }
471
+ function buildRecoveryActions(toolStatuses, skippedTools = []) {
472
+ const failed = toolStatuses
473
+ .filter((tool) => tool.status === "timeout" || tool.status === "error")
474
+ .map((tool) => ({
475
+ id: `recover-${tool.id}`,
476
+ tool: tool.id,
477
+ command: `vibedoctor tool retry ${tool.id}`,
478
+ successCondition: `${tool.id} completes with status ok`,
479
+ onFailure: `Keep the scan partial, disclose missing ${tool.id} coverage, and request human review before risky changes.`
480
+ }));
481
+ const skipped = skippedTools.map((tool) => ({
482
+ id: `recover-${tool.id}`,
483
+ tool: tool.id,
484
+ command: "vibedoctor setup --include recommended",
485
+ successCondition: `${tool.id} is installed and completes on the next scan`,
486
+ onFailure: `${(tool.installHint ?? `Install ${tool.id}`).replace(/[.,;:]$/, "")}, then rerun the scan; otherwise disclose missing ${tool.id} coverage.`
487
+ }));
488
+ return [...failed, ...skipped];
489
+ }
355
490
  function filterScanByCategories(scan, categories, options = {}) {
356
491
  const findings = sortFindings(scan.findings.filter((finding) => categories.includes(finding.category)));
357
492
  const score = (0, scoring_1.buildScore)(findings);
@@ -362,6 +497,7 @@ function filterScanByCategories(scan, categories, options = {}) {
362
497
  score,
363
498
  toolStatuses: scan.toolStatuses,
364
499
  skippedTools: scan.skippedTools,
500
+ completeness: scan.completeness,
365
501
  testCommands: scan.testCommands,
366
502
  policy: options.policy,
367
503
  target: options.target ?? scan.agentPlan.target,
@@ -370,7 +506,12 @@ function filterScanByCategories(scan, categories, options = {}) {
370
506
  });
371
507
  }
372
508
  function buildSummaryLines(scan) {
373
- const lines = [`Health: ${scan.score.overall}/100 ${scan.score.overall >= 85 ? "✅" : "⚠️"}`, ""];
509
+ const lines = [
510
+ `Health: ${scan.score.overall}/100 — ${scan.completeness.status.toUpperCase()} ${scan.score.overall >= 85 ? "✅" : "⚠️"}`,
511
+ `Scan coverage: ${scan.completeness.completed}/${scan.completeness.planned} checks completed`,
512
+ ...(scan.completeness.comparable ? [] : ["This score is not comparable to a complete scan."]),
513
+ ""
514
+ ];
374
515
  lines.push(`Blockers: ${scan.blockers.length}`);
375
516
  lines.push(`Fix next: ${scan.fixNext.length}`);
376
517
  lines.push(`Privacy Review findings: ${scan.privacyFindings.length}`);
@@ -408,6 +549,10 @@ function buildSummaryLines(scan) {
408
549
  lines.push("", "ERRORED TOOLS");
409
550
  erroredTools.forEach((tool, index) => lines.push(`${index + 1}. ${tool.id}${tool.message ? ` — ${tool.message}` : ` — ${tool.status}`}`));
410
551
  }
552
+ if (scan.recoveryActions.length > 0) {
553
+ lines.push("", "RECOVER BEFORE EDITING");
554
+ scan.recoveryActions.forEach((action, index) => lines.push(`${index + 1}. ${action.command} — success: ${action.successCondition}`));
555
+ }
411
556
  lines.push("", "READY FOR AGENT", "Run:", "vibedoctor agent-plan");
412
557
  return lines;
413
558
  }
@@ -442,7 +587,8 @@ async function createBaseline(root) {
442
587
  }
443
588
  async function safeFix(root) {
444
589
  const before = await runScan(root, "default");
445
- const [{ config }, project] = await Promise.all([(0, config_1.loadConfig)(root), (0, projectDetector_1.detectProject)(root)]);
590
+ const { config } = await (0, config_1.loadConfig)(root);
591
+ const project = await (0, projectDetector_1.detectProject)(root, config.paths.exclude);
446
592
  const ctx = { root, project, config, scanMode: "default" };
447
593
  const fixableAdapters = ALL_ADAPTERS.filter((adapter) => adapter.buildFixCommand && adapter.detect);
448
594
  const results = [];
@@ -14,4 +14,4 @@ export type ProjectContext = {
14
14
  entryFiles: string[];
15
15
  projectFiles: string[];
16
16
  };
17
- export declare function detectProject(root: string): Promise<ProjectContext>;
17
+ export declare function detectProject(root: string, excludePatterns?: string[]): Promise<ProjectContext>;