@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
@@ -1,9 +1,20 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.knipAdapter = void 0;
7
+ const node_path_1 = __importDefault(require("node:path"));
4
8
  const finding_1 = require("../core/finding");
5
9
  function parseKnip(stdout) {
6
- return stdout.trim() ? JSON.parse(stdout) : {};
10
+ const trimmed = stdout.trim();
11
+ return trimmed && trimmed.startsWith("{") ? JSON.parse(trimmed) : {};
12
+ }
13
+ function findPackageJsonPath(projectFiles) {
14
+ if (projectFiles.includes("package.json")) {
15
+ return "package.json";
16
+ }
17
+ return projectFiles.find((f) => f.endsWith("/package.json"));
7
18
  }
8
19
  exports.knipAdapter = {
9
20
  id: "knip",
@@ -12,14 +23,28 @@ exports.knipAdapter = {
12
23
  return project.languages.includes("javascript") || project.languages.includes("typescript");
13
24
  },
14
25
  buildScanCommand(ctx) {
26
+ const packageJsonPath = findPackageJsonPath(ctx.project.projectFiles);
27
+ const cwd = packageJsonPath && node_path_1.default.dirname(packageJsonPath) !== "." ? node_path_1.default.join(ctx.root, node_path_1.default.dirname(packageJsonPath)) : ctx.root;
15
28
  return {
16
29
  cmd: "knip",
17
30
  args: ["--reporter", "json"],
18
- cwd: ctx.root,
31
+ cwd,
19
32
  timeoutMs: 60_000
20
33
  };
21
34
  },
22
35
  parseResult(result, ctx) {
36
+ const output = `${result.stdout}\n${result.stderr}`;
37
+ if (/styleText|ERR_UNKNOWN_BUILTIN_MODULE|SyntaxError.*styleText/i.test(output)) {
38
+ result.status = "skipped";
39
+ result.installHint = "Knip 5+ requires Node >= 20.19. Please upgrade Node.js to run Knip.";
40
+ return [];
41
+ }
42
+ if (result.exitCode !== 0 && /Could not find package\.json|ENOENT.*package\.json/i.test(output)) {
43
+ result.status = "skipped";
44
+ return [];
45
+ }
46
+ const packageJsonPath = findPackageJsonPath(ctx.project.projectFiles);
47
+ const prefix = packageJsonPath && node_path_1.default.dirname(packageJsonPath) !== "." ? node_path_1.default.dirname(packageJsonPath) : "";
23
48
  const parsed = parseKnip(result.stdout);
24
49
  const fileFindings = (parsed.unusedFiles ?? []).map((file) => ({
25
50
  id: `knip:file:${file}`,
@@ -29,7 +54,7 @@ exports.knipAdapter = {
29
54
  confidence: "high",
30
55
  title: "Unused file",
31
56
  message: `${file} is not reachable from detected entrypoints.`,
32
- file: (0, finding_1.normalizeFilePath)(file, ctx.root),
57
+ file: (0, finding_1.normalizeFilePath)(prefix ? node_path_1.default.join(prefix, file) : file, ctx.root),
33
58
  isNew: true,
34
59
  isAutofixable: false,
35
60
  safeToAutofix: false,
@@ -45,7 +70,7 @@ exports.knipAdapter = {
45
70
  confidence: "high",
46
71
  title: "Unused export",
47
72
  message: `${item.symbol ?? "Export"} appears unused.`,
48
- file: (0, finding_1.normalizeFilePath)(item.file, ctx.root),
73
+ file: (0, finding_1.normalizeFilePath)(item.file ? (prefix ? node_path_1.default.join(prefix, item.file) : item.file) : undefined, ctx.root),
49
74
  startLine: item.line,
50
75
  isNew: true,
51
76
  isAutofixable: false,
@@ -1,2 +1,2 @@
1
- import type { ToolAdapter } from "./shared";
1
+ import { type ToolAdapter } from "./shared";
2
2
  export declare const lizardAdapter: ToolAdapter;
@@ -2,8 +2,51 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.lizardAdapter = void 0;
4
4
  const finding_1 = require("../core/finding");
5
+ const shared_1 = require("./shared");
6
+ function parseCsvLine(line) {
7
+ const values = [];
8
+ let value = "";
9
+ let quoted = false;
10
+ for (let index = 0; index < line.length; index += 1) {
11
+ const character = line[index];
12
+ if (character === '"') {
13
+ if (quoted && line[index + 1] === '"') {
14
+ value += '"';
15
+ index += 1;
16
+ }
17
+ else {
18
+ quoted = !quoted;
19
+ }
20
+ }
21
+ else if (character === "," && !quoted) {
22
+ values.push(value);
23
+ value = "";
24
+ }
25
+ else {
26
+ value += character;
27
+ }
28
+ }
29
+ values.push(value);
30
+ return values;
31
+ }
5
32
  function parseLizard(stdout) {
6
- return stdout.trim() ? JSON.parse(stdout) : [];
33
+ const files = new Map();
34
+ for (const line of stdout.split(/\r?\n/).filter(Boolean)) {
35
+ const columns = parseCsvLine(line);
36
+ if (columns.length < 11) {
37
+ continue;
38
+ }
39
+ const filename = columns[6];
40
+ const functions = files.get(filename) ?? [];
41
+ functions.push({
42
+ name: columns[7],
43
+ start_line: Number(columns[9]),
44
+ end_line: Number(columns[10]),
45
+ cyclomatic_complexity: Number(columns[1])
46
+ });
47
+ files.set(filename, functions);
48
+ }
49
+ return Array.from(files, ([filename, function_list]) => ({ filename, function_list }));
7
50
  }
8
51
  exports.lizardAdapter = {
9
52
  id: "lizard",
@@ -12,9 +55,15 @@ exports.lizardAdapter = {
12
55
  return project.languages.length > 0;
13
56
  },
14
57
  buildScanCommand(ctx) {
58
+ const targets = (0, shared_1.adapterTargets)(ctx, /\.(?:js|jsx|ts|tsx|py)$/i);
15
59
  return {
16
60
  cmd: "lizard",
17
- args: ["-j", "."],
61
+ args: [
62
+ "--csv",
63
+ "--ignore_warnings",
64
+ "-1",
65
+ ...targets
66
+ ],
18
67
  cwd: ctx.root,
19
68
  timeoutMs: 120_000
20
69
  };
@@ -21,6 +21,10 @@ function parseOsv(stdout) {
21
21
  return findings;
22
22
  }
23
23
  function severityFromCvss(item) {
24
+ const namedSeverity = item.database_specific?.severity?.toLowerCase();
25
+ if (namedSeverity === "critical" || namedSeverity === "high" || namedSeverity === "medium" || namedSeverity === "low") {
26
+ return namedSeverity;
27
+ }
24
28
  const score = Number(item.severity?.[0]?.score ?? 0);
25
29
  if (score >= 9) {
26
30
  return "critical";
@@ -42,14 +46,22 @@ exports.osvScannerAdapter = {
42
46
  buildScanCommand(ctx) {
43
47
  return {
44
48
  cmd: "osv-scanner",
45
- args: ["scan", "--lockfile=auto", "--format=json", "."],
49
+ args: [
50
+ "scan",
51
+ "source",
52
+ ...ctx.project.lockfiles.flatMap((lockfile) => ["--lockfile", lockfile]),
53
+ "--format",
54
+ "json",
55
+ "--verbosity",
56
+ "error"
57
+ ],
46
58
  cwd: ctx.root,
47
59
  timeoutMs: 60_000
48
60
  };
49
61
  },
50
62
  parseResult(result) {
51
63
  return parseOsv(result.stdout).map((item, index) => ({
52
- id: `osv:${item.package?.name}:${item.id ?? index}`,
64
+ id: `osv:${item.package?.name}:${item.package?.version ?? "unknown"}:${item.id ?? index}`,
53
65
  source: "osv-scanner",
54
66
  category: "dependencies",
55
67
  severity: severityFromCvss(item),
@@ -114,6 +114,8 @@ exports.presidioAdapter = {
114
114
  id: "presidio",
115
115
  category: "privacy",
116
116
  async detect(_project, config) {
117
+ // This adapter belongs to the normal privacy scan. DPDP has an independent
118
+ // opt-out switch and invokes/reuses this adapter through its collector.
117
119
  return config.checks.privacy.enabled && config.checks.privacy.presidio.enabled;
118
120
  },
119
121
  async runStandalone(ctx) {
@@ -154,5 +156,5 @@ exports.presidioAdapter = {
154
156
  status
155
157
  };
156
158
  },
157
- installHint: "Optional privacy scanner. Enable checks.privacy.presidio.enabled and install presidio-analyzer."
159
+ installHint: "Optional privacy scanner (on by default). Install: python -m pip install presidio-analyzer. Opt out of normal privacy scans with checks.privacy.presidio.enabled: false."
158
160
  };
@@ -5,6 +5,29 @@ export declare function confidenceFromScore(score: number): Confidence;
5
5
  export declare function passesLuhn(value: string): boolean;
6
6
  export declare function isValidAadhaar(value: string): boolean;
7
7
  export declare function maskPiiValue(value: string, entityType: string, maskExamples?: boolean): string;
8
- export declare function detectPiiFindings(ctx: ToolAdapterContext): Promise<Finding[]>;
8
+ export type DetectPiiFindingsOptions = {
9
+ /**
10
+ * When set, only these files are scanned (already path-normalized preferred).
11
+ * Used by DPDP changed-scope collection so privacy reuse the same allowlist.
12
+ */
13
+ fileAllowlist?: string[];
14
+ /** Override include patterns (defaults to config.paths.include). Ignored when fileAllowlist is set. */
15
+ include?: string[];
16
+ /** Override exclude patterns (defaults to config.paths.exclude). Ignored when fileAllowlist is set. */
17
+ exclude?: string[];
18
+ /** Bypass process-lifetime cache (tests / forced refresh). */
19
+ skipCache?: boolean;
20
+ };
21
+ export declare function clearPrivacyFindingsCache(): void;
22
+ export declare function getPrivacyFindingsCacheStats(): {
23
+ size: number;
24
+ hits: number;
25
+ misses: number;
26
+ };
27
+ /**
28
+ * Deterministic privacy scan with process-lifetime cache.
29
+ * Concurrent callers with the same key share one in-flight computation (dedupes privacy + DPDP double walks).
30
+ */
31
+ export declare function detectPiiFindings(ctx: ToolAdapterContext, options?: DetectPiiFindingsOptions): Promise<Finding[]>;
9
32
  export declare const privacyDetectorAdapter: ToolAdapter;
10
33
  export declare function normalizeExternalFile(file: string | undefined, root: string): string | undefined;
@@ -8,6 +8,8 @@ exports.confidenceFromScore = confidenceFromScore;
8
8
  exports.passesLuhn = passesLuhn;
9
9
  exports.isValidAadhaar = isValidAadhaar;
10
10
  exports.maskPiiValue = maskPiiValue;
11
+ exports.clearPrivacyFindingsCache = clearPrivacyFindingsCache;
12
+ exports.getPrivacyFindingsCacheStats = getPrivacyFindingsCacheStats;
11
13
  exports.detectPiiFindings = detectPiiFindings;
12
14
  exports.normalizeExternalFile = normalizeExternalFile;
13
15
  const node_fs_1 = require("node:fs");
@@ -200,7 +202,7 @@ function fieldEntity(field) {
200
202
  if (/aadhaar|aadhar|uidai/.test(normalized)) {
201
203
  return { entityType: "aadhaar", sensitivity: "regulated_identifier", confidenceScore: 0.82, matchedPattern: "aadhaar-field", reasons: [reason] };
202
204
  }
203
- if (/permanentaccountnumber|pan(number|no|card)?$/.test(normalized)) {
205
+ if (/^(?:permanentaccountnumber|pan(?:number|no|card)?)$/.test(normalized)) {
204
206
  return { entityType: "pan", sensitivity: "regulated_identifier", confidenceScore: 0.82, matchedPattern: "pan-field", reasons: [reason] };
205
207
  }
206
208
  if (/passport/.test(normalized)) {
@@ -378,16 +380,16 @@ function combinationRisk(file, fields) {
378
380
  const groups = new Map();
379
381
  for (const field of fields) {
380
382
  const normalized = field.normalized;
381
- if (/age|dob|dateofbirth|birthdate/.test(normalized)) {
383
+ if (/^(?:age|dob|dateofbirth|birthdate|userage|customerage|employeeage|patientage)$/.test(normalized)) {
382
384
  groups.set("age_or_dob", [...(groups.get("age_or_dob") ?? []), field.field]);
383
385
  }
384
- if (/gender|sex/.test(normalized)) {
386
+ if (/^(?:gender|sex|usergender|customergender|employeegender|patientgender)$/.test(normalized)) {
385
387
  groups.set("gender", [...(groups.get("gender") ?? []), field.field]);
386
388
  }
387
- if (/location|site|city|branch|address|latitude|longitude|gps/.test(normalized)) {
389
+ if (/^(?:location|site|city|branch|address|latitude|longitude|gps|userlocation|customerlocation|employeelocation|patientlocation)$/.test(normalized)) {
388
390
  groups.set("location", [...(groups.get("location") ?? []), field.field]);
389
391
  }
390
- if (/designation|role|title|department|team|job/.test(normalized)) {
392
+ if (/^(?:designation|role|title|department|team|job|jobtitle|employeerole|employeedepartment)$/.test(normalized)) {
391
393
  groups.set("role_or_department", [...(groups.get("role_or_department") ?? []), field.field]);
392
394
  }
393
395
  }
@@ -459,9 +461,64 @@ async function readCandidate(root, file, maxFileBytes) {
459
461
  function passesConfidenceThreshold(finding, minimum) {
460
462
  return CONFIDENCE_RANK[finding.confidence] >= CONFIDENCE_RANK[minimum];
461
463
  }
462
- async function detectPiiFindings(ctx) {
464
+ /** Process-lifetime cache: privacy adapter + DPDP collectors often scan the same tree once per run. */
465
+ const privacyFindingsCache = new Map();
466
+ let privacyCacheHits = 0;
467
+ let privacyCacheMisses = 0;
468
+ function clearPrivacyFindingsCache() {
469
+ privacyFindingsCache.clear();
470
+ privacyCacheHits = 0;
471
+ privacyCacheMisses = 0;
472
+ }
473
+ function getPrivacyFindingsCacheStats() {
474
+ return {
475
+ size: privacyFindingsCache.size,
476
+ hits: privacyCacheHits,
477
+ misses: privacyCacheMisses
478
+ };
479
+ }
480
+ function privacyConfigFingerprint(ctx) {
481
+ const privacy = ctx.config.checks.privacy;
482
+ return JSON.stringify({
483
+ minConfidenceToReport: privacy.minConfidenceToReport,
484
+ maskExamples: privacy.maskExamples,
485
+ maxFileBytes: privacy.maxFileBytes,
486
+ detectUnsanitizedLogs: privacy.detectUnsanitizedLogs,
487
+ detectApiOverfetching: privacy.detectApiOverfetching,
488
+ detectMissingRetention: privacy.detectMissingRetention
489
+ });
490
+ }
491
+ function resolvePrivacyCandidates(ctx, options) {
492
+ if (options.fileAllowlist !== undefined) {
493
+ return options.fileAllowlist.filter(isTextCandidate).map((file) => file.replaceAll("\\", "/")).sort();
494
+ }
495
+ return (0, paths_1.filterPaths)(ctx.project.projectFiles, options.include ?? ctx.config.paths.include, options.exclude ?? ctx.config.paths.exclude)
496
+ .filter(isTextCandidate)
497
+ .map((file) => file.replaceAll("\\", "/"))
498
+ .sort();
499
+ }
500
+ async function buildPrivacyFindingsCacheKey(ctx, options, candidates) {
501
+ const fileVersions = [];
502
+ for (const candidate of candidates) {
503
+ const stat = await node_fs_1.promises.stat(node_path_1.default.join(ctx.root, candidate)).catch(() => undefined);
504
+ fileVersions.push(`${candidate}:${stat?.size ?? -1}:${stat?.mtimeMs ?? -1}`);
505
+ }
506
+ return [
507
+ ctx.root,
508
+ privacyConfigFingerprint(ctx),
509
+ fileVersions.join("\n"),
510
+ JSON.stringify({
511
+ include: options.include ?? null,
512
+ exclude: options.exclude ?? null,
513
+ allowlist: options.fileAllowlist !== undefined
514
+ })
515
+ ].join("::");
516
+ }
517
+ function cloneFindings(findings) {
518
+ return structuredClone(findings);
519
+ }
520
+ async function detectPiiFindingsUncached(ctx, candidates) {
463
521
  const privacyCfg = ctx.config.checks.privacy;
464
- const candidates = (0, paths_1.filterPaths)(ctx.project.projectFiles, ctx.config.paths.include, ctx.config.paths.exclude).filter(isTextCandidate);
465
522
  const findings = [];
466
523
  for (const file of candidates) {
467
524
  const content = await readCandidate(ctx.root, file, privacyCfg.maxFileBytes);
@@ -583,6 +640,33 @@ async function detectPiiFindings(ctx) {
583
640
  }
584
641
  return findings.filter((finding) => passesConfidenceThreshold(finding, privacyCfg.minConfidenceToReport));
585
642
  }
643
+ /**
644
+ * Deterministic privacy scan with process-lifetime cache.
645
+ * Concurrent callers with the same key share one in-flight computation (dedupes privacy + DPDP double walks).
646
+ */
647
+ async function detectPiiFindings(ctx, options = {}) {
648
+ const candidates = resolvePrivacyCandidates(ctx, options);
649
+ if (options.skipCache) {
650
+ return detectPiiFindingsUncached(ctx, candidates);
651
+ }
652
+ const key = await buildPrivacyFindingsCacheKey(ctx, options, candidates);
653
+ const existing = privacyFindingsCache.get(key);
654
+ if (existing) {
655
+ privacyCacheHits += 1;
656
+ return cloneFindings(await existing);
657
+ }
658
+ privacyCacheMisses += 1;
659
+ const pending = detectPiiFindingsUncached(ctx, candidates);
660
+ privacyFindingsCache.set(key, pending);
661
+ try {
662
+ const findings = await pending;
663
+ return cloneFindings(findings);
664
+ }
665
+ catch (error) {
666
+ privacyFindingsCache.delete(key);
667
+ throw error;
668
+ }
669
+ }
586
670
  exports.privacyDetectorAdapter = {
587
671
  id: "privacy-detector",
588
672
  category: "privacy",
@@ -1,2 +1,2 @@
1
- import type { ToolAdapter } from "./shared";
1
+ import { type ToolAdapter } from "./shared";
2
2
  export declare const ruffAdapter: ToolAdapter;
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ruffAdapter = void 0;
4
4
  const finding_1 = require("../core/finding");
5
+ const shared_1 = require("./shared");
5
6
  function parseRuffOutput(stdout) {
6
7
  const trimmed = stdout.trim();
7
8
  if (!trimmed) {
@@ -25,9 +26,11 @@ exports.ruffAdapter = {
25
26
  return project.languages.includes("python");
26
27
  },
27
28
  buildScanCommand(ctx) {
29
+ const targets = (0, shared_1.adapterTargets)(ctx, /\.py$/i);
30
+ const excludePatterns = ctx.config.paths.exclude.length > 0 ? ["--exclude", ctx.config.paths.exclude.join(",")] : [];
28
31
  return {
29
32
  cmd: "ruff",
30
- args: ["check", ".", "--output-format", "json"],
33
+ args: ["check", ...targets, "--output-format", "json", ...excludePatterns],
31
34
  cwd: ctx.root,
32
35
  timeoutMs: 60_000
33
36
  };
@@ -1,2 +1,2 @@
1
- import type { ToolAdapter } from "./shared";
1
+ import { type ToolAdapter } from "./shared";
2
2
  export declare const semgrepAdapter: ToolAdapter;
@@ -2,6 +2,8 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.semgrepAdapter = void 0;
4
4
  const finding_1 = require("../core/finding");
5
+ const toolRunner_1 = require("../core/toolRunner");
6
+ const shared_1 = require("./shared");
5
7
  function parseSemgrep(stdout) {
6
8
  return stdout.trim() ? JSON.parse(stdout) : {};
7
9
  }
@@ -30,11 +32,23 @@ exports.semgrepAdapter = {
30
32
  return project.languages.length > 0;
31
33
  },
32
34
  buildScanCommand(ctx) {
35
+ const targets = (0, shared_1.adapterTargets)(ctx, /\.(?:js|jsx|ts|tsx|py)$/i);
36
+ // The Semgrep Windows launcher expands wildcard arguments before handing
37
+ // them to pysemgrep. Calling pysemgrep directly preserves exclude globs,
38
+ // but fall back to the regular launcher when only "semgrep" is installed.
39
+ const useDirectEntryPoint = process.platform === "win32" && (0, toolRunner_1.commandExistsOnWindowsPath)("pysemgrep", ctx.root);
33
40
  return {
34
- cmd: "semgrep",
35
- args: ["scan", "--json", "--quiet", "--config", "auto", "."],
41
+ cmd: useDirectEntryPoint ? "pysemgrep" : "semgrep",
42
+ args: [
43
+ "scan",
44
+ "--json",
45
+ "--no-git-ignore",
46
+ "--config",
47
+ "auto",
48
+ ...targets
49
+ ],
36
50
  cwd: ctx.root,
37
- timeoutMs: 120_000
51
+ timeoutMs: 300_000
38
52
  };
39
53
  },
40
54
  parseResult(result, ctx) {
@@ -7,6 +7,12 @@ export type ToolAdapterContext = {
7
7
  project: ProjectContext;
8
8
  config: VibeDoctorConfig;
9
9
  scanMode: "default" | "changed" | "quick" | "full";
10
+ /** Results already produced by the scan engine, available to dependent adapters for reuse. */
11
+ sharedToolResults?: Record<string, SharedToolExecution>;
12
+ };
13
+ export type SharedToolExecution = {
14
+ findings: Finding[];
15
+ status?: ToolResult;
10
16
  };
11
17
  export type ToolAdapter = {
12
18
  id: string;
@@ -21,3 +27,4 @@ export type ToolAdapter = {
21
27
  }>;
22
28
  installHint: string;
23
29
  };
30
+ export declare function adapterTargets(ctx: ToolAdapterContext, extensionPattern: RegExp): string[];
@@ -1,2 +1,24 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.adapterTargets = adapterTargets;
4
+ const paths_1 = require("../core/paths");
5
+ const MAX_TARGET_ARGS_LENGTH = 6_000;
6
+ function getTopLevelTargets(targets) {
7
+ const topLevels = new Set();
8
+ for (const target of targets) {
9
+ const parts = target.split("/");
10
+ if (parts.length > 0 && parts[0]) {
11
+ topLevels.add(parts[0]);
12
+ }
13
+ }
14
+ const result = Array.from(topLevels).sort();
15
+ return result.length > 0 ? result : ["."];
16
+ }
17
+ function adapterTargets(ctx, extensionPattern) {
18
+ const targets = (0, paths_1.filterPaths)(ctx.project.projectFiles, ctx.config.paths.include, ctx.config.paths.exclude).filter((file) => extensionPattern.test(file));
19
+ if (targets.length === 0) {
20
+ return ["."];
21
+ }
22
+ const totalLength = targets.reduce((sum, target) => sum + target.length + 1, 0);
23
+ return totalLength > MAX_TARGET_ARGS_LENGTH ? getTopLevelTargets(targets) : targets;
24
+ }
@@ -1,6 +1,10 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.tscAdapter = void 0;
7
+ const node_path_1 = __importDefault(require("node:path"));
4
8
  const finding_1 = require("../core/finding");
5
9
  const TSC_PATTERN = /^(?<file>.+?)\((?<line>\d+),(?<column>\d+)\): error (?<code>TS\d+): (?<message>.+)$/gm;
6
10
  function parseTsc(stdout, stderr) {
@@ -20,6 +24,12 @@ function mapSeverity(code) {
20
24
  }
21
25
  return "medium";
22
26
  }
27
+ function findTsconfigPath(projectFiles) {
28
+ if (projectFiles.includes("tsconfig.json")) {
29
+ return "tsconfig.json";
30
+ }
31
+ return projectFiles.find((f) => f.endsWith("/tsconfig.json"));
32
+ }
23
33
  exports.tscAdapter = {
24
34
  id: "tsc",
25
35
  category: "correctness",
@@ -27,31 +37,46 @@ exports.tscAdapter = {
27
37
  return project.languages.includes("typescript");
28
38
  },
29
39
  buildScanCommand(ctx) {
40
+ const tsconfig = findTsconfigPath(ctx.project.projectFiles);
41
+ const cwd = tsconfig && node_path_1.default.dirname(tsconfig) !== "." ? node_path_1.default.join(ctx.root, node_path_1.default.dirname(tsconfig)) : ctx.root;
30
42
  return {
31
43
  cmd: "tsc",
32
44
  args: ["--noEmit", "--pretty", "false"],
33
- cwd: ctx.root,
45
+ cwd,
34
46
  timeoutMs: 90_000
35
47
  };
36
48
  },
37
49
  parseResult(result, ctx) {
38
- return parseTsc(result.stdout, result.stderr).map((item) => ({
39
- id: `tsc:${item.file}:${item.line}:${item.code}`,
40
- source: "tsc",
41
- category: "correctness",
42
- severity: mapSeverity(item.code),
43
- confidence: "high",
44
- title: item.code,
45
- message: item.message,
46
- file: (0, finding_1.normalizeFilePath)(item.file, ctx.root),
47
- startLine: Number(item.line),
48
- isNew: true,
49
- isAutofixable: false,
50
- safeToAutofix: false,
51
- agentInstruction: "Fix the type error without changing public behavior unless required.",
52
- tags: ["typescript", "types"],
53
- scoreImpact: 0
54
- }));
50
+ const output = `${result.stdout}\n${result.stderr}`;
51
+ const parsed = parseTsc(result.stdout, result.stderr);
52
+ // With no tsconfig, tsc prints CLI help and can exit successfully. That
53
+ // does not represent a completed type check.
54
+ if (/Syntax:\s*tsc|TS2304.*--help|Version \d+/i.test(output) && parsed.length === 0) {
55
+ result.status = "skipped";
56
+ return [];
57
+ }
58
+ const tsconfig = findTsconfigPath(ctx.project.projectFiles);
59
+ const prefix = tsconfig && node_path_1.default.dirname(tsconfig) !== "." ? node_path_1.default.dirname(tsconfig) : "";
60
+ return parsed.map((item) => {
61
+ const fullPath = prefix ? node_path_1.default.join(prefix, item.file) : item.file;
62
+ return {
63
+ id: `tsc:${fullPath}:${item.line}:${item.code}`,
64
+ source: "tsc",
65
+ category: "correctness",
66
+ severity: mapSeverity(item.code),
67
+ confidence: "high",
68
+ title: item.code,
69
+ message: item.message,
70
+ file: (0, finding_1.normalizeFilePath)(fullPath, ctx.root),
71
+ startLine: Number(item.line),
72
+ isNew: true,
73
+ isAutofixable: false,
74
+ safeToAutofix: false,
75
+ agentInstruction: "Fix the type error without changing public behavior unless required.",
76
+ tags: ["typescript", "types"],
77
+ scoreImpact: 0
78
+ };
79
+ });
55
80
  },
56
81
  installHint: "Install TypeScript with: npm install -D typescript"
57
82
  };
@@ -1,2 +1,2 @@
1
- import type { ToolAdapter } from "./shared";
1
+ import { type ToolAdapter } from "./shared";
2
2
  export declare const vultureAdapter: ToolAdapter;
@@ -2,9 +2,24 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.vultureAdapter = void 0;
4
4
  const finding_1 = require("../core/finding");
5
+ const shared_1 = require("./shared");
6
+ const VULTURE_PATTERN = /^(?<file>.+?):(?<line>\d+):\s*unused\s+(?<type>[\w\s]+)\s+'(?<name>[^']+)'(?:\s*\((?<confidence>\d+)%\s*confidence\))?/gm;
5
7
  function parseVulture(stdout) {
6
- const trimmed = stdout.trim();
7
- return trimmed ? JSON.parse(trimmed) : [];
8
+ const items = [];
9
+ const matches = stdout.matchAll(VULTURE_PATTERN);
10
+ for (const match of matches) {
11
+ if (!match.groups) {
12
+ continue;
13
+ }
14
+ items.push({
15
+ filename: match.groups.file,
16
+ first_lineno: Number(match.groups.line),
17
+ name: match.groups.name,
18
+ type: match.groups.type.trim(),
19
+ confidence: match.groups.confidence ? Number(match.groups.confidence) : 60
20
+ });
21
+ }
22
+ return items;
8
23
  }
9
24
  function isPackageInitializer(file) {
10
25
  return file.replaceAll("\\", "/").endsWith("/__init__.py") || file === "__init__.py";
@@ -16,15 +31,19 @@ exports.vultureAdapter = {
16
31
  return project.languages.includes("python");
17
32
  },
18
33
  buildScanCommand(ctx) {
34
+ const targets = (0, shared_1.adapterTargets)(ctx, /\.py$/i);
35
+ const excludePatterns = ctx.config.paths.exclude.length > 0 ? ctx.config.paths.exclude.join(",") : undefined;
36
+ const excludeArgs = excludePatterns ? ["--exclude", excludePatterns] : [];
19
37
  return {
20
38
  cmd: "vulture",
21
- args: [".", "--json"],
39
+ args: [...targets, ...excludeArgs],
22
40
  cwd: ctx.root,
23
41
  timeoutMs: 60_000
24
42
  };
25
43
  },
26
44
  parseResult(result, ctx) {
27
- return parseVulture(result.stdout).map((item) => {
45
+ const text = `${result.stdout}\n${result.stderr}`;
46
+ return parseVulture(text).map((item) => {
28
47
  const packageInitializer = isPackageInitializer(item.filename);
29
48
  return {
30
49
  id: `vulture:${item.filename}:${item.first_lineno}:${item.name}`,
@@ -33,9 +52,9 @@ exports.vultureAdapter = {
33
52
  severity: "low",
34
53
  confidence: packageInitializer
35
54
  ? "low"
36
- : (item.confidence ?? 60) >= 90
55
+ : item.confidence >= 90
37
56
  ? "high"
38
- : (item.confidence ?? 60) >= 70
57
+ : item.confidence >= 70
39
58
  ? "medium"
40
59
  : "low",
41
60
  title: packageInitializer ? `Review package initializer ${item.type}` : `Unused ${item.type}`,
@@ -18,8 +18,10 @@ Use VibeDoctor as the source of truth for code-health checks.
18
18
 
19
19
  Before major edits:
20
20
  \`\`\`bash
21
- vibedoctor scan --changed --report json
22
- \`\`\`
21
+ vibedoctor scan --changed --report json
22
+ \`\`\`
23
+
24
+ Read \`completeness.status\` before editing. If it is \`partial\` or \`invalid\`, run the report's \`recoveryActions\` first. Never compare a partial score with a complete score or assume a timed-out tool passed.
23
25
 
24
26
  After edits:
25
27
  \`\`\`bash
@@ -63,8 +65,9 @@ After each meaningful change, run the smallest relevant verification command.
63
65
  At the end, report:
64
66
 
65
67
  \`\`\`text
66
- Health score:
67
- Commands run:
68
+ Health score:
69
+ Scan completeness:
70
+ Commands run:
68
71
  Files changed:
69
72
  Remaining blockers:
70
73
  Suggested next step: