@neuralaxis/vibedoctor 0.1.2 → 0.2.0

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 (109) hide show
  1. package/README.md +215 -102
  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/dpdp.d.ts +6 -0
  7. package/dist/adapters/dpdp.js +34 -0
  8. package/dist/adapters/index.d.ts +1 -0
  9. package/dist/adapters/index.js +3 -1
  10. package/dist/adapters/knip.js +29 -4
  11. package/dist/adapters/lizard.d.ts +1 -1
  12. package/dist/adapters/lizard.js +51 -2
  13. package/dist/adapters/osvScanner.js +14 -2
  14. package/dist/adapters/presidio.js +3 -1
  15. package/dist/adapters/privacyDetector.d.ts +24 -1
  16. package/dist/adapters/privacyDetector.js +91 -7
  17. package/dist/adapters/ruff.d.ts +1 -1
  18. package/dist/adapters/ruff.js +4 -1
  19. package/dist/adapters/semgrep.d.ts +1 -1
  20. package/dist/adapters/semgrep.js +17 -3
  21. package/dist/adapters/shared.d.ts +7 -0
  22. package/dist/adapters/shared.js +22 -0
  23. package/dist/adapters/tsc.js +43 -18
  24. package/dist/adapters/vulture.d.ts +1 -1
  25. package/dist/adapters/vulture.js +25 -6
  26. package/dist/agentPack/templates/index.js +7 -4
  27. package/dist/agentPack/templates/skills.js +156 -44
  28. package/dist/cli/commands/agentPlan.js +9 -1
  29. package/dist/cli/commands/dpdp.d.ts +35 -0
  30. package/dist/cli/commands/dpdp.js +103 -0
  31. package/dist/cli/commands/init.js +12 -4
  32. package/dist/cli/commands/scan.d.ts +1 -1
  33. package/dist/cli/commands/scan.js +8 -1
  34. package/dist/cli/commands/setup.js +4 -2
  35. package/dist/cli/commands/tool.d.ts +4 -0
  36. package/dist/cli/commands/tool.js +11 -0
  37. package/dist/cli/index.js +96 -0
  38. package/dist/core/config.d.ts +27 -0
  39. package/dist/core/config.js +118 -5
  40. package/dist/core/engine.d.ts +32 -1
  41. package/dist/core/engine.js +195 -30
  42. package/dist/core/finding.d.ts +1 -1
  43. package/dist/core/finding.js +1 -0
  44. package/dist/core/projectDetector.d.ts +1 -1
  45. package/dist/core/projectDetector.js +29 -12
  46. package/dist/core/scanPlanner.js +10 -2
  47. package/dist/core/toolRunner.d.ts +1 -0
  48. package/dist/core/toolRunner.js +73 -11
  49. package/dist/dpdp/artifacts.d.ts +11 -0
  50. package/dist/dpdp/artifacts.js +120 -0
  51. package/dist/dpdp/catalogue.d.ts +14 -0
  52. package/dist/dpdp/catalogue.js +661 -0
  53. package/dist/dpdp/collectors/confidence.d.ts +9 -0
  54. package/dist/dpdp/collectors/confidence.js +25 -0
  55. package/dist/dpdp/collectors/dependencies.d.ts +7 -0
  56. package/dist/dpdp/collectors/dependencies.js +63 -0
  57. package/dist/dpdp/collectors/index.d.ts +24 -0
  58. package/dist/dpdp/collectors/index.js +71 -0
  59. package/dist/dpdp/collectors/lifecycle.d.ts +2 -0
  60. package/dist/dpdp/collectors/lifecycle.js +202 -0
  61. package/dist/dpdp/collectors/optionalScanners.d.ts +14 -0
  62. package/dist/dpdp/collectors/optionalScanners.js +347 -0
  63. package/dist/dpdp/collectors/privacyBridge.d.ts +13 -0
  64. package/dist/dpdp/collectors/privacyBridge.js +152 -0
  65. package/dist/dpdp/collectors/safeguards.d.ts +5 -0
  66. package/dist/dpdp/collectors/safeguards.js +186 -0
  67. package/dist/dpdp/collectors/schema.d.ts +6 -0
  68. package/dist/dpdp/collectors/schema.js +122 -0
  69. package/dist/dpdp/collectors/shared.d.ts +10 -0
  70. package/dist/dpdp/collectors/shared.js +43 -0
  71. package/dist/dpdp/context.d.ts +28 -0
  72. package/dist/dpdp/context.js +195 -0
  73. package/dist/dpdp/dataMap.d.ts +7 -0
  74. package/dist/dpdp/dataMap.js +339 -0
  75. package/dist/dpdp/evaluators.d.ts +20 -0
  76. package/dist/dpdp/evaluators.js +522 -0
  77. package/dist/dpdp/evidence.d.ts +11 -0
  78. package/dist/dpdp/evidence.js +123 -0
  79. package/dist/dpdp/findings.d.ts +14 -0
  80. package/dist/dpdp/findings.js +99 -0
  81. package/dist/dpdp/gates.d.ts +14 -0
  82. package/dist/dpdp/gates.js +47 -0
  83. package/dist/dpdp/index.d.ts +16 -0
  84. package/dist/dpdp/index.js +32 -0
  85. package/dist/dpdp/legalSources.d.ts +10 -0
  86. package/dist/dpdp/legalSources.js +104 -0
  87. package/dist/dpdp/paths.d.ts +25 -0
  88. package/dist/dpdp/paths.js +85 -0
  89. package/dist/dpdp/report.d.ts +6 -0
  90. package/dist/dpdp/report.js +222 -0
  91. package/dist/dpdp/reviewQueue.d.ts +3 -0
  92. package/dist/dpdp/reviewQueue.js +88 -0
  93. package/dist/dpdp/scan.d.ts +26 -0
  94. package/dist/dpdp/scan.js +310 -0
  95. package/dist/dpdp/scoring.d.ts +31 -0
  96. package/dist/dpdp/scoring.js +211 -0
  97. package/dist/dpdp/types.d.ts +294 -0
  98. package/dist/dpdp/types.js +86 -0
  99. package/dist/index.d.ts +1 -0
  100. package/dist/index.js +1 -0
  101. package/dist/mcp/tools/dpdp.d.ts +11 -0
  102. package/dist/mcp/tools/dpdp.js +151 -0
  103. package/dist/mcp/tools/index.js +3 -1
  104. package/dist/mcp/tools/shared.js +8 -1
  105. package/dist/reporters/agent.js +8 -0
  106. package/dist/reporters/html.js +4 -2
  107. package/dist/reporters/json.js +8 -1
  108. package/dist/reporters/markdown.js +8 -1
  109. package/package.json +9 -2
@@ -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,
@@ -106,7 +115,30 @@ exports.defaultConfig = {
106
115
  includeRawValues: false
107
116
  },
108
117
  presidio: {
109
- enabled: false
118
+ // Opt-out: try Presidio on normal privacy scans; skip gracefully if not installed.
119
+ enabled: true
120
+ }
121
+ },
122
+ dpdp: {
123
+ enabled: true,
124
+ include: [],
125
+ exclude: [],
126
+ minConfidenceToReport: "medium",
127
+ maskExamples: true,
128
+ // Opt-out: DPDP tries these by default so agents get full coverage without extra flags.
129
+ usePresidio: true,
130
+ useSemgrep: true,
131
+ legalSourceVersion: "2025.2-final-corrigendum",
132
+ contextFile: ".vibedoctor/dpdp/context.yml",
133
+ evidenceFile: ".vibedoctor/dpdp/evidence.yml",
134
+ failOnSeverity: [],
135
+ failOnViolatedControls: [],
136
+ failOnlyOnNew: true,
137
+ organization: {
138
+ processesPersonalData: "unknown",
139
+ isSignificantDataFiduciary: "unknown",
140
+ processesChildrenData: "unknown",
141
+ hasCrossBorderTransfer: "unknown"
110
142
  }
111
143
  }
112
144
  },
@@ -122,6 +154,15 @@ const CONFIG_FILES = ["vibedoctor.yml", "vibedoctor.yaml", "vibedoctor.json"];
122
154
  function isRecord(value) {
123
155
  return typeof value === "object" && value !== null && !Array.isArray(value);
124
156
  }
157
+ function normalizeStringArray(value, fallback) {
158
+ return Array.isArray(value) ? value.filter((item) => typeof item === "string") : [...fallback];
159
+ }
160
+ function normalizeSeverityArray(value, fallback) {
161
+ const allowed = new Set(["info", "low", "medium", "high", "critical"]);
162
+ return Array.isArray(value)
163
+ ? value.filter((item) => typeof item === "string" && allowed.has(item))
164
+ : [...fallback];
165
+ }
125
166
  function deepMerge(base, override) {
126
167
  if (override === undefined) {
127
168
  return base;
@@ -149,10 +190,11 @@ async function findConfigFile(root) {
149
190
  return undefined;
150
191
  }
151
192
  function normalizeRawConfig(raw) {
152
- const { baseline: _baseline, checks: _checks, output: _output, ...rest } = raw;
193
+ const { baseline: _baseline, checks: _checks, output: _output, runtime: _runtime, ...rest } = raw;
153
194
  const rawChecks = raw.checks;
154
195
  const rawBaseline = raw.baseline;
155
196
  const rawOutput = raw.output;
197
+ const rawRuntime = raw.runtime;
156
198
  const rawDeadCode = (rawChecks?.deadCode ?? rawChecks?.dead_code);
157
199
  const rawLeftovers = rawChecks?.leftovers;
158
200
  const rawRefactor = (rawChecks?.refactorReadiness ?? rawChecks?.refactor_readiness);
@@ -163,8 +205,28 @@ function normalizeRawConfig(raw) {
163
205
  const rawPrivacy = rawChecks?.privacy;
164
206
  const rawPrivacyAi = (rawPrivacy?.ai ?? {});
165
207
  const rawPresidio = (rawPrivacy?.presidio ?? {});
208
+ const rawDpdp = rawChecks?.dpdp;
209
+ const rawDpdpOrg = (rawDpdp?.organization ?? rawDpdp?.organisation ?? {});
166
210
  return {
167
211
  ...rest,
212
+ ...(rawRuntime
213
+ ? {
214
+ runtime: {
215
+ defaultTimeoutSeconds: rawRuntime.defaultTimeoutSeconds ??
216
+ rawRuntime.default_timeout_seconds ??
217
+ exports.defaultConfig.runtime.defaultTimeoutSeconds,
218
+ toolTimeouts: rawRuntime.toolTimeouts ??
219
+ rawRuntime.tool_timeouts ??
220
+ exports.defaultConfig.runtime.toolTimeouts,
221
+ requiredTools: rawRuntime.requiredTools ??
222
+ rawRuntime.required_tools ??
223
+ exports.defaultConfig.runtime.requiredTools,
224
+ failOnIncompleteScan: rawRuntime.failOnIncompleteScan ??
225
+ rawRuntime.fail_on_incomplete_scan ??
226
+ exports.defaultConfig.runtime.failOnIncompleteScan
227
+ }
228
+ }
229
+ : {}),
168
230
  ...(rawOutput
169
231
  ? {
170
232
  output: {
@@ -327,19 +389,70 @@ function normalizeRawConfig(raw) {
327
389
  enabled: rawPresidio.enabled ?? exports.defaultConfig.checks.privacy.presidio.enabled
328
390
  }
329
391
  }
330
- : exports.defaultConfig.checks.privacy
392
+ : exports.defaultConfig.checks.privacy,
393
+ dpdp: rawDpdp
394
+ ? {
395
+ enabled: rawDpdp.enabled ?? exports.defaultConfig.checks.dpdp.enabled,
396
+ include: normalizeStringArray(rawDpdp.include, exports.defaultConfig.checks.dpdp.include),
397
+ exclude: normalizeStringArray(rawDpdp.exclude, exports.defaultConfig.checks.dpdp.exclude),
398
+ minConfidenceToReport: rawDpdp.minConfidenceToReport ??
399
+ rawDpdp.min_confidence_to_report ??
400
+ exports.defaultConfig.checks.dpdp.minConfidenceToReport,
401
+ maskExamples: rawDpdp.maskExamples ??
402
+ rawDpdp.mask_examples ??
403
+ exports.defaultConfig.checks.dpdp.maskExamples,
404
+ usePresidio: rawDpdp.usePresidio ??
405
+ rawDpdp.use_presidio ??
406
+ exports.defaultConfig.checks.dpdp.usePresidio,
407
+ useSemgrep: rawDpdp.useSemgrep ??
408
+ rawDpdp.use_semgrep ??
409
+ exports.defaultConfig.checks.dpdp.useSemgrep,
410
+ legalSourceVersion: rawDpdp.legalSourceVersion ??
411
+ rawDpdp.legal_source_version ??
412
+ exports.defaultConfig.checks.dpdp.legalSourceVersion,
413
+ contextFile: rawDpdp.contextFile ??
414
+ rawDpdp.context_file ??
415
+ exports.defaultConfig.checks.dpdp.contextFile,
416
+ evidenceFile: rawDpdp.evidenceFile ??
417
+ rawDpdp.evidence_file ??
418
+ exports.defaultConfig.checks.dpdp.evidenceFile,
419
+ failOnSeverity: normalizeSeverityArray(rawDpdp.failOnSeverity ?? rawDpdp.fail_on_severity, exports.defaultConfig.checks.dpdp.failOnSeverity),
420
+ failOnViolatedControls: normalizeStringArray(rawDpdp.failOnViolatedControls ?? rawDpdp.fail_on_violated_controls, exports.defaultConfig.checks.dpdp.failOnViolatedControls),
421
+ failOnlyOnNew: rawDpdp.failOnlyOnNew ??
422
+ rawDpdp.fail_only_on_new ??
423
+ exports.defaultConfig.checks.dpdp.failOnlyOnNew,
424
+ organization: {
425
+ processesPersonalData: normalizeTriState(rawDpdpOrg.processesPersonalData ?? rawDpdpOrg.processes_personal_data, exports.defaultConfig.checks.dpdp.organization.processesPersonalData),
426
+ isSignificantDataFiduciary: normalizeTriState(rawDpdpOrg.isSignificantDataFiduciary ?? rawDpdpOrg.is_significant_data_fiduciary, exports.defaultConfig.checks.dpdp.organization.isSignificantDataFiduciary),
427
+ processesChildrenData: normalizeTriState(rawDpdpOrg.processesChildrenData ?? rawDpdpOrg.processes_children_data, exports.defaultConfig.checks.dpdp.organization.processesChildrenData),
428
+ hasCrossBorderTransfer: normalizeTriState(rawDpdpOrg.hasCrossBorderTransfer ?? rawDpdpOrg.has_cross_border_transfer, exports.defaultConfig.checks.dpdp.organization.hasCrossBorderTransfer)
429
+ }
430
+ }
431
+ : exports.defaultConfig.checks.dpdp
331
432
  }
332
433
  }
333
434
  : {})
334
435
  };
335
436
  }
437
+ function normalizeTriState(value, fallback) {
438
+ if (value === true || value === "true" || value === "yes") {
439
+ return "true";
440
+ }
441
+ if (value === false || value === "false" || value === "no") {
442
+ return "false";
443
+ }
444
+ if (value === "unknown" || value === undefined || value === null) {
445
+ return value === "unknown" ? "unknown" : fallback;
446
+ }
447
+ return fallback;
448
+ }
336
449
  async function loadConfig(root) {
337
450
  const configPath = await findConfigFile(root);
338
451
  if (!configPath) {
339
- return { config: exports.defaultConfig };
452
+ return { config: structuredClone(exports.defaultConfig) };
340
453
  }
341
454
  const content = await node_fs_1.promises.readFile(configPath, "utf8");
342
455
  const parsed = configPath.endsWith(".json") ? JSON.parse(content) : yaml_1.default.parse(content);
343
- const config = deepMerge(exports.defaultConfig, normalizeRawConfig(parsed));
456
+ const config = deepMerge(structuredClone(exports.defaultConfig), normalizeRawConfig(parsed));
344
457
  return { config, configPath };
345
458
  }
@@ -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;
@@ -10,6 +11,7 @@ exports.safeFix = safeFix;
10
11
  const adapters_1 = require("../adapters");
11
12
  const customLeftovers_1 = require("../adapters/customLeftovers");
12
13
  const privacyDetector_1 = require("../adapters/privacyDetector");
14
+ const dpdp_1 = require("../adapters/dpdp");
13
15
  const customRefactor_1 = require("../adapters/customRefactor");
14
16
  const customDeadChain_1 = require("../adapters/customDeadChain");
15
17
  const presidio_1 = require("../adapters/presidio");
@@ -41,6 +43,7 @@ const ALL_ADAPTERS = [
41
43
  adapters_1.vitestAdapter,
42
44
  adapters_1.jestAdapter,
43
45
  privacyDetector_1.privacyDetectorAdapter,
46
+ dpdp_1.dpdpAdapter,
44
47
  presidio_1.presidioAdapter,
45
48
  adapters_1.telemetryDetectorAdapter,
46
49
  customLeftovers_1.customLeftoversAdapter,
@@ -174,8 +177,18 @@ function targetScore(overall) {
174
177
  function createAgentPlan(scan, options = {}) {
175
178
  const policy = options.policy ?? policy_1.defaultAgentPolicy;
176
179
  const target = options.target ?? "generic";
180
+ const toolStatuses = scan.toolStatuses ?? [];
181
+ const completeness = scan.completeness ?? {
182
+ status: scan.skippedTools.length > 0 ? "partial" : "complete",
183
+ comparable: scan.skippedTools.length === 0,
184
+ planned: 0,
185
+ completed: 0,
186
+ incompleteTools: scan.skippedTools.map((tool) => tool.id),
187
+ requiredIncompleteTools: []
188
+ };
189
+ const recoveryActions = scan.recoveryActions ?? buildRecoveryActions(toolStatuses, scan.skippedTools);
177
190
  const ordered = sortFindings(scan.findings);
178
- const tasks = ordered.slice(0, 5).map((finding, index) => ({
191
+ const tasks = (completeness.status === "invalid" ? [] : ordered.slice(0, 5)).map((finding, index) => ({
179
192
  id: `task-${index + 1}`,
180
193
  title: finding.title,
181
194
  priority: index + 1,
@@ -186,9 +199,12 @@ function createAgentPlan(scan, options = {}) {
186
199
  commands: buildTaskCommands(finding, policy)
187
200
  }));
188
201
  return {
189
- goal: `Raise health score from ${scan.score.overall} to ${targetScore(scan.score.overall)}`,
202
+ goal: completeness.status === "complete"
203
+ ? `Raise health score from ${scan.score.overall} to ${targetScore(scan.score.overall)}`
204
+ : "Recover incomplete checks before changing code, then improve validated findings",
205
+ status: completeness.status,
190
206
  target,
191
- workflow: ["scan", "plan", "safe fix", "edit carefully", "verify", "scan again", "summarize"],
207
+ workflow: ["scan", "validate completeness", "recover tools", "plan", "safe fix", "edit carefully", "verify", "scan again", "summarize"],
192
208
  rules: [
193
209
  "Fix blockers before cleanup work.",
194
210
  "Do not delete low-confidence dead code.",
@@ -197,13 +213,20 @@ function createAgentPlan(scan, options = {}) {
197
213
  ],
198
214
  allowedActions: (0, policy_1.getAllowedActions)(policy),
199
215
  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.`),
216
+ doNotTouch: [
217
+ ...scan.skippedTools.map((tool) => `Do not assume ${tool.id} was fully checked because the tool was skipped.`),
218
+ ...toolStatuses
219
+ .filter((tool) => tool.status === "timeout" || tool.status === "error")
220
+ .map((tool) => `Do not treat the health score as complete because ${tool.id} ${tool.status === "timeout" ? "timed out" : "failed"}.`)
221
+ ],
222
+ recoveryActions,
201
223
  tasks
202
224
  };
203
225
  }
204
226
  function buildScanOutput(options) {
205
227
  const summary = summarizeFindings(options.findings);
206
228
  const policy = options.policy ?? policy_1.defaultAgentPolicy;
229
+ const recoveryActions = buildRecoveryActions(options.toolStatuses, options.skippedTools);
207
230
  return {
208
231
  root: options.root,
209
232
  mode: options.mode,
@@ -219,11 +242,16 @@ function buildScanOutput(options) {
219
242
  refactorCandidates: summary.refactorCandidates,
220
243
  toolStatuses: [...options.toolStatuses].sort((left, right) => left.id.localeCompare(right.id)),
221
244
  skippedTools: [...options.skippedTools].sort((left, right) => left.id.localeCompare(right.id)),
245
+ completeness: options.completeness,
246
+ recoveryActions,
222
247
  testCommands: options.testCommands,
223
248
  agentPlan: createAgentPlan({
224
249
  findings: summary.ordered,
225
250
  score: options.score,
251
+ toolStatuses: options.toolStatuses,
226
252
  skippedTools: options.skippedTools,
253
+ completeness: options.completeness,
254
+ recoveryActions,
227
255
  testCommands: options.testCommands
228
256
  }, { policy, target: options.target }),
229
257
  configPath: options.configPath
@@ -245,12 +273,40 @@ function summarizeToolStatus(status) {
245
273
  const message = rawMessage.length > 300 ? `${rawMessage.slice(0, 297)}...` : rawMessage;
246
274
  return { message, command: status.command };
247
275
  }
276
+ // Tools that intentionally use a non-zero exit for "findings reported" or emit
277
+ // experimental warnings on otherwise-successful runs. Shared by runScan and
278
+ // retryTool so a tool never "fails" in one path while "succeeding" in the other.
279
+ function forgiveKnownToolQuirks(toolId, result, findingsCount = 0) {
280
+ if (result.status !== "error") {
281
+ return undefined;
282
+ }
283
+ if (findingsCount > 0) {
284
+ return { status: "ok", message: "Reported issues (debt surfaced as findings)" };
285
+ }
286
+ const output = `${result.stderr}\n${result.stdout}`;
287
+ if (toolId === "biome" && /unstable|experimental/i.test(output)) {
288
+ return { status: "ok" };
289
+ }
290
+ if (toolId === "knip" && result.stdout.trim().startsWith("{")) {
291
+ return { status: "ok", message: "Reported issues (debt surfaced as findings)" };
292
+ }
293
+ if (toolId === "vitest" && /Loaded .*vitest@.*coverage-v8/i.test(output)) {
294
+ return { status: "ok" };
295
+ }
296
+ if (toolId === "osv-scanner" && result.stdout.trim().startsWith("{")) {
297
+ return { status: "ok", message: "Reported vulnerabilities as findings" };
298
+ }
299
+ return undefined;
300
+ }
248
301
  async function runAdapter(adapter, ctx) {
249
302
  if (adapter.runStandalone) {
250
303
  return adapter.runStandalone(ctx);
251
304
  }
252
305
  if (adapter.buildScanCommand && adapter.parseResult) {
253
- const status = await (0, toolRunner_1.runCommand)(adapter.buildScanCommand(ctx), adapter.installHint);
306
+ const command = adapter.buildScanCommand(ctx);
307
+ const timeoutSeconds = ctx.config.runtime.toolTimeouts[adapter.id] ?? ctx.config.runtime.defaultTimeoutSeconds;
308
+ command.timeoutMs = timeoutSeconds * 1000;
309
+ const status = await (0, toolRunner_1.runCommand)(command, adapter.installHint);
254
310
  if (status.status === "skipped") {
255
311
  return { findings: [], status };
256
312
  }
@@ -279,13 +335,20 @@ async function runAdapter(adapter, ctx) {
279
335
  };
280
336
  }
281
337
  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)]);
338
+ const [{ config, configPath }, { policy }] = await Promise.all([(0, config_1.loadConfig)(root), (0, policy_1.loadAgentPolicy)(root)]);
339
+ const project = await (0, projectDetector_1.detectProject)(root, config.paths.exclude);
283
340
  const plan = await (0, scanPlanner_1.createScanPlan)(project, config, [...ALL_ADAPTERS], mode);
284
341
  const ctx = { root, project, config, scanMode: mode };
285
342
  const selectedAdapters = ALL_ADAPTERS.filter((adapter) => plan.adapterIds.includes(adapter.id));
286
- // Run adapters concurrently for performance (independent tools; dead-chain post-process depends on aggregated findings).
287
- // This addresses the previous sequential for-loop bottleneck in runScan.
288
- const adapterResults = await Promise.all(selectedAdapters.map(async (adapter) => ({ adapter, result: await runAdapter(adapter, ctx) })));
343
+ const independentAdapters = selectedAdapters.filter((adapter) => adapter.id !== "dpdp");
344
+ // Run independent adapters once. DPDP follows so it can reuse optional scanner
345
+ // findings/status instead of launching duplicate Semgrep and Presidio processes.
346
+ const adapterResults = await Promise.all(independentAdapters.map(async (adapter) => ({ adapter, result: await runAdapter(adapter, ctx) })));
347
+ if (selectedAdapters.some((adapter) => adapter.id === "dpdp")) {
348
+ const sharedToolResults = Object.fromEntries(adapterResults.map(({ adapter, result }) => [adapter.id, result]));
349
+ const dpdpCtx = { ...ctx, sharedToolResults };
350
+ adapterResults.push({ adapter: dpdp_1.dpdpAdapter, result: await runAdapter(dpdp_1.dpdpAdapter, dpdpCtx) });
351
+ }
289
352
  const findings = [];
290
353
  const toolStatuses = [];
291
354
  const skippedTools = [];
@@ -302,26 +365,39 @@ async function runScan(root, mode = "default") {
302
365
  });
303
366
  continue;
304
367
  }
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
- }
368
+ const forgiven = forgiveKnownToolQuirks(adapter.id, result.status, result.findings.length);
369
+ const summarized = summarizeToolStatus(result.status);
370
+ toolStatuses.push({
371
+ id: adapter.id,
372
+ status: forgiven?.status ?? result.status.status,
373
+ ...summarized,
374
+ ...(forgiven ? { message: forgiven.message } : {})
375
+ });
324
376
  }
377
+ const incompleteTools = Array.from(new Set([
378
+ ...skippedTools.map((tool) => tool.id),
379
+ ...toolStatuses.filter((tool) => tool.status === "error" || tool.status === "timeout").map((tool) => tool.id)
380
+ ])).sort();
381
+ // Skipped tools can include checks that were never selected as adapters
382
+ // (built-in checks, mode-filtered tools); count them in the denominator so
383
+ // "completed" never underflows.
384
+ const plannedIds = new Set([...selectedAdapters.map((adapter) => adapter.id), ...incompleteTools]);
385
+ const requiredIncompleteTools = incompleteTools.filter((id) => config.runtime.requiredTools.includes(id));
386
+ const completeness = {
387
+ status: incompleteTools.length === 0
388
+ ? "complete"
389
+ : requiredIncompleteTools.length > 0 || config.runtime.failOnIncompleteScan
390
+ ? "invalid"
391
+ : "partial",
392
+ comparable: incompleteTools.length === 0,
393
+ planned: plannedIds.size,
394
+ completed: plannedIds.size - incompleteTools.length,
395
+ incompleteTools,
396
+ requiredIncompleteTools,
397
+ reason: incompleteTools.length > 0
398
+ ? `${incompleteTools.length} of ${plannedIds.size} planned checks did not complete.`
399
+ : undefined
400
+ };
325
401
  let deadChainFindings = [];
326
402
  if (config.checks.deadCode.enabled) {
327
403
  const rawDead = await (0, customDeadChain_1.detectDeadChains)(project, findings, config);
@@ -346,12 +422,79 @@ async function runScan(root, mode = "default") {
346
422
  score,
347
423
  toolStatuses,
348
424
  skippedTools,
425
+ completeness,
349
426
  testCommands: project.testCommands,
350
427
  policy,
351
428
  configPath,
352
429
  privacyReview: privacyReview?.summary
353
430
  });
354
431
  }
432
+ async function retryTool(root, toolId, timeoutSeconds) {
433
+ const { config } = await (0, config_1.loadConfig)(root);
434
+ const project = await (0, projectDetector_1.detectProject)(root, config.paths.exclude);
435
+ const adapter = ALL_ADAPTERS.find((candidate) => candidate.id === toolId);
436
+ if (!adapter || !adapter.buildScanCommand || !adapter.parseResult) {
437
+ return {
438
+ tool: toolId,
439
+ status: "skipped",
440
+ timeoutSeconds: timeoutSeconds ?? config.runtime.defaultTimeoutSeconds,
441
+ findings: [],
442
+ message: `Tool ${toolId} is unknown or does not support isolated retry.`,
443
+ successCondition: `${toolId} completes with status ok`,
444
+ nextAction: "Run vibedoctor scan --full --report agent-json and request human review if the tool remains incomplete."
445
+ };
446
+ }
447
+ const ctx = { root, project, config, scanMode: "full" };
448
+ const seconds = timeoutSeconds ?? Math.max(config.runtime.defaultTimeoutSeconds, (config.runtime.toolTimeouts[toolId] ?? config.runtime.defaultTimeoutSeconds) * 2);
449
+ const command = adapter.buildScanCommand(ctx);
450
+ command.timeoutMs = seconds * 1000;
451
+ const result = await (0, toolRunner_1.runCommand)(command, adapter.installHint);
452
+ let parseError;
453
+ let findings = [];
454
+ if (result.status !== "skipped") {
455
+ try {
456
+ findings = adapter.parseResult(result, ctx) ?? [];
457
+ }
458
+ catch (error) {
459
+ // A run that produced unparseable output is not a success; report it so
460
+ // agents do not mistake "ok with zero findings" for a clean result.
461
+ parseError = `Could not parse ${toolId} output: ${error instanceof Error ? error.message : String(error)}`;
462
+ }
463
+ }
464
+ const forgiven = forgiveKnownToolQuirks(toolId, result, findings.length);
465
+ const status = parseError ? "error" : forgiven?.status ?? result.status;
466
+ const summary = summarizeToolStatus(result);
467
+ return {
468
+ tool: toolId,
469
+ status,
470
+ timeoutSeconds: seconds,
471
+ findings,
472
+ message: parseError ?? forgiven?.message ?? summary.message,
473
+ successCondition: `${toolId} completes with status ok`,
474
+ nextAction: status === "ok"
475
+ ? "Run vibedoctor scan --full --report agent-json to produce a comparable health result."
476
+ : `Keep the scan partial and disclose missing ${toolId} coverage before changing risky code.`
477
+ };
478
+ }
479
+ function buildRecoveryActions(toolStatuses, skippedTools = []) {
480
+ const failed = toolStatuses
481
+ .filter((tool) => tool.status === "timeout" || tool.status === "error")
482
+ .map((tool) => ({
483
+ id: `recover-${tool.id}`,
484
+ tool: tool.id,
485
+ command: `vibedoctor tool retry ${tool.id}`,
486
+ successCondition: `${tool.id} completes with status ok`,
487
+ onFailure: `Keep the scan partial, disclose missing ${tool.id} coverage, and request human review before risky changes.`
488
+ }));
489
+ const skipped = skippedTools.map((tool) => ({
490
+ id: `recover-${tool.id}`,
491
+ tool: tool.id,
492
+ command: "vibedoctor setup --include recommended",
493
+ successCondition: `${tool.id} is installed and completes on the next scan`,
494
+ onFailure: `${(tool.installHint ?? `Install ${tool.id}`).replace(/[.,;:]$/, "")}, then rerun the scan; otherwise disclose missing ${tool.id} coverage.`
495
+ }));
496
+ return [...failed, ...skipped];
497
+ }
355
498
  function filterScanByCategories(scan, categories, options = {}) {
356
499
  const findings = sortFindings(scan.findings.filter((finding) => categories.includes(finding.category)));
357
500
  const score = (0, scoring_1.buildScore)(findings);
@@ -362,6 +505,7 @@ function filterScanByCategories(scan, categories, options = {}) {
362
505
  score,
363
506
  toolStatuses: scan.toolStatuses,
364
507
  skippedTools: scan.skippedTools,
508
+ completeness: scan.completeness,
365
509
  testCommands: scan.testCommands,
366
510
  policy: options.policy,
367
511
  target: options.target ?? scan.agentPlan.target,
@@ -370,10 +514,19 @@ function filterScanByCategories(scan, categories, options = {}) {
370
514
  });
371
515
  }
372
516
  function buildSummaryLines(scan) {
373
- const lines = [`Health: ${scan.score.overall}/100 ${scan.score.overall >= 85 ? "✅" : "⚠️"}`, ""];
517
+ const lines = [
518
+ `Health: ${scan.score.overall}/100 — ${scan.completeness.status.toUpperCase()} ${scan.score.overall >= 85 ? "✅" : "⚠️"}`,
519
+ `Scan coverage: ${scan.completeness.completed}/${scan.completeness.planned} checks completed`,
520
+ ...(scan.completeness.comparable ? [] : ["This score is not comparable to a complete scan."]),
521
+ ""
522
+ ];
374
523
  lines.push(`Blockers: ${scan.blockers.length}`);
375
524
  lines.push(`Fix next: ${scan.fixNext.length}`);
376
525
  lines.push(`Privacy Review findings: ${scan.privacyFindings.length}`);
526
+ const dpdpFindings = scan.privacyFindings.filter((finding) => finding.source === "dpdp");
527
+ if (dpdpFindings.length > 0) {
528
+ lines.push(`DPDP technical findings: ${dpdpFindings.length} (not legal compliance)`);
529
+ }
377
530
  lines.push(`Leftovers: ${scan.leftovers.length}`);
378
531
  lines.push(`Dead code candidates: ${scan.deadCodeCandidates.length}`);
379
532
  lines.push(`Refactor candidates: ${scan.refactorCandidates.length}`);
@@ -391,6 +544,13 @@ function buildSummaryLines(scan) {
391
544
  .slice(0, 5)
392
545
  .forEach((finding, index) => lines.push(`${index + 1}. ${finding.title}${finding.file ? ` (${finding.file}${finding.startLine ? `:${finding.startLine}` : ""})` : ""}`));
393
546
  }
547
+ if (dpdpFindings.length > 0) {
548
+ lines.push("", "DPDP TECHNICAL FINDINGS (not legal compliance)");
549
+ dpdpFindings
550
+ .slice(0, 5)
551
+ .forEach((finding, index) => lines.push(`${index + 1}. ${finding.title}${finding.file ? ` (${finding.file}${finding.startLine ? `:${finding.startLine}` : ""})` : ""}`));
552
+ lines.push("Artifacts: .vibedoctor/dpdp/ · Command: vibedoctor dpdp report --markdown");
553
+ }
394
554
  if (scan.leftovers.length > 0) {
395
555
  lines.push("", "LEFTOVERS");
396
556
  scan.leftovers.forEach((finding, index) => lines.push(`${index + 1}. ${finding.title}${finding.file ? ` (${finding.file})` : ""}`));
@@ -408,6 +568,10 @@ function buildSummaryLines(scan) {
408
568
  lines.push("", "ERRORED TOOLS");
409
569
  erroredTools.forEach((tool, index) => lines.push(`${index + 1}. ${tool.id}${tool.message ? ` — ${tool.message}` : ` — ${tool.status}`}`));
410
570
  }
571
+ if (scan.recoveryActions.length > 0) {
572
+ lines.push("", "RECOVER BEFORE EDITING");
573
+ scan.recoveryActions.forEach((action, index) => lines.push(`${index + 1}. ${action.command} — success: ${action.successCondition}`));
574
+ }
411
575
  lines.push("", "READY FOR AGENT", "Run:", "vibedoctor agent-plan");
412
576
  return lines;
413
577
  }
@@ -442,7 +606,8 @@ async function createBaseline(root) {
442
606
  }
443
607
  async function safeFix(root) {
444
608
  const before = await runScan(root, "default");
445
- const [{ config }, project] = await Promise.all([(0, config_1.loadConfig)(root), (0, projectDetector_1.detectProject)(root)]);
609
+ const { config } = await (0, config_1.loadConfig)(root);
610
+ const project = await (0, projectDetector_1.detectProject)(root, config.paths.exclude);
446
611
  const ctx = { root, project, config, scanMode: "default" };
447
612
  const fixableAdapters = ALL_ADAPTERS.filter((adapter) => adapter.buildFixCommand && adapter.detect);
448
613
  const results = [];
@@ -1,4 +1,4 @@
1
- export declare const FINDING_SOURCES: readonly ["ruff", "biome", "tsc", "pyright", "semgrep", "gitleaks", "osv-scanner", "knip", "vulture", "deptry", "jscpd", "lizard", "radon", "coverage.py", "vitest", "jest", "privacy-detector", "presidio", "privacy-ai-review", "telemetry-detector", "custom-leftovers", "custom-refactor", "custom-dead-chain"];
1
+ export declare const FINDING_SOURCES: readonly ["ruff", "biome", "tsc", "pyright", "semgrep", "gitleaks", "osv-scanner", "knip", "vulture", "deptry", "jscpd", "lizard", "radon", "coverage.py", "vitest", "jest", "privacy-detector", "presidio", "privacy-ai-review", "telemetry-detector", "dpdp", "custom-leftovers", "custom-refactor", "custom-dead-chain"];
2
2
  export declare const FINDING_CATEGORIES: readonly ["security", "correctness", "dead_code", "leftovers", "maintainability", "dependencies", "tests", "privacy", "efficiency", "refactor_readiness"];
3
3
  export type FindingSource = (typeof FINDING_SOURCES)[number];
4
4
  export type FindingCategory = (typeof FINDING_CATEGORIES)[number];
@@ -34,6 +34,7 @@ exports.FINDING_SOURCES = [
34
34
  "presidio",
35
35
  "privacy-ai-review",
36
36
  "telemetry-detector",
37
+ "dpdp",
37
38
  "custom-leftovers",
38
39
  "custom-refactor",
39
40
  "custom-dead-chain"
@@ -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>;