@neuralaxis/vibedoctor 0.2.0 → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (80) hide show
  1. package/README.md +135 -23
  2. package/dist/adapters/biome.js +136 -21
  3. package/dist/adapters/flowDoctor.d.ts +7 -0
  4. package/dist/adapters/flowDoctor.js +195 -0
  5. package/dist/adapters/gitleaks.js +4 -2
  6. package/dist/adapters/index.d.ts +1 -0
  7. package/dist/adapters/index.js +3 -1
  8. package/dist/adapters/osvScanner.js +140 -19
  9. package/dist/adapters/presidio.js +3 -1
  10. package/dist/adapters/ruff.js +7 -3
  11. package/dist/adapters/shared.d.ts +4 -0
  12. package/dist/cli/commands/init.js +112 -50
  13. package/dist/cli/commands/privacyReview.js +3 -4
  14. package/dist/cli/commands/scan.d.ts +6 -0
  15. package/dist/cli/commands/scan.js +16 -2
  16. package/dist/cli/commands/setup.d.ts +13 -17
  17. package/dist/cli/commands/setup.js +138 -200
  18. package/dist/cli/index.js +4 -4
  19. package/dist/core/agentDiagnosis.d.ts +39 -0
  20. package/dist/core/agentDiagnosis.js +96 -0
  21. package/dist/core/capability.d.ts +92 -0
  22. package/dist/core/capability.js +122 -0
  23. package/dist/core/config.d.ts +47 -0
  24. package/dist/core/config.js +134 -3
  25. package/dist/core/credentialHeuristics.d.ts +28 -0
  26. package/dist/core/credentialHeuristics.js +179 -0
  27. package/dist/core/engine.d.ts +29 -1
  28. package/dist/core/engine.js +510 -126
  29. package/dist/core/executable.d.ts +18 -0
  30. package/dist/core/executable.js +137 -0
  31. package/dist/core/fileRole.d.ts +24 -0
  32. package/dist/core/fileRole.js +125 -0
  33. package/dist/core/finding.d.ts +125 -1
  34. package/dist/core/finding.js +70 -8
  35. package/dist/core/findingCorrelator.d.ts +19 -0
  36. package/dist/core/findingCorrelator.js +112 -0
  37. package/dist/core/findingNormalizer.d.ts +33 -0
  38. package/dist/core/findingNormalizer.js +172 -0
  39. package/dist/core/managedTools.d.ts +25 -0
  40. package/dist/core/managedTools.js +186 -0
  41. package/dist/core/projectDetector.d.ts +13 -0
  42. package/dist/core/projectDetector.js +100 -15
  43. package/dist/core/relevance.d.ts +87 -0
  44. package/dist/core/relevance.js +367 -0
  45. package/dist/core/repoGraph.d.ts +62 -0
  46. package/dist/core/repoGraph.js +408 -0
  47. package/dist/core/riskRanker.d.ts +6 -0
  48. package/dist/core/riskRanker.js +127 -0
  49. package/dist/core/scanContext.d.ts +26 -0
  50. package/dist/core/scanContext.js +44 -0
  51. package/dist/core/scanPlanner.d.ts +13 -0
  52. package/dist/core/scanPlanner.js +66 -38
  53. package/dist/core/semverLite.d.ts +27 -0
  54. package/dist/core/semverLite.js +163 -0
  55. package/dist/core/suppressions.d.ts +96 -0
  56. package/dist/core/suppressions.js +302 -0
  57. package/dist/core/toolRegistry.d.ts +58 -0
  58. package/dist/core/toolRegistry.js +254 -0
  59. package/dist/core/toolRunner.d.ts +27 -2
  60. package/dist/core/toolRunner.js +79 -93
  61. package/dist/core/toolRuntime.d.ts +40 -0
  62. package/dist/core/toolRuntime.js +417 -0
  63. package/dist/core/toolVerification.d.ts +89 -0
  64. package/dist/core/toolVerification.js +425 -0
  65. package/dist/dpdp/collectors/optionalScanners.js +120 -30
  66. package/dist/dpdp/findings.d.ts +33 -3
  67. package/dist/dpdp/findings.js +191 -4
  68. package/dist/dpdp/scan.js +2 -2
  69. package/dist/dpdp/scoring.d.ts +14 -4
  70. package/dist/dpdp/scoring.js +34 -8
  71. package/dist/dpdp/types.d.ts +19 -1
  72. package/dist/index.d.ts +5 -0
  73. package/dist/index.js +5 -0
  74. package/dist/reporters/agent.d.ts +1 -1
  75. package/dist/reporters/agent.js +7 -0
  76. package/dist/reporters/html.js +57 -13
  77. package/dist/reporters/json.js +7 -1
  78. package/dist/reporters/markdown.js +46 -4
  79. package/dist/reporters/sarif.js +54 -5
  80. package/package.json +80 -80
@@ -1,59 +1,87 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.QUICK_ADAPTER_IDS = void 0;
3
4
  exports.createScanPlan = createScanPlan;
5
+ exports.QUICK_ADAPTER_IDS = new Set([
6
+ "ruff",
7
+ "biome",
8
+ "tsc",
9
+ "pyright",
10
+ "gitleaks",
11
+ "osv-scanner",
12
+ "privacy-detector",
13
+ "dpdp",
14
+ "custom-leftovers"
15
+ ]);
16
+ /** The config switch that governs each category, and the name to report. */
17
+ function disabledReason(adapter, config) {
18
+ const { checks } = config;
19
+ switch (adapter.category) {
20
+ case "security":
21
+ return checks.security.enabled ? undefined : "checks.security.enabled is false";
22
+ case "dead_code":
23
+ return checks.deadCode.enabled ? undefined : "checks.deadCode.enabled is false";
24
+ case "leftovers":
25
+ return checks.leftovers.enabled ? undefined : "checks.leftovers.enabled is false";
26
+ case "refactor_readiness":
27
+ return checks.refactorReadiness.enabled ? undefined : "checks.refactorReadiness.enabled is false";
28
+ case "dependencies":
29
+ return checks.dependencies.enabled ? undefined : "checks.dependencies.enabled is false";
30
+ case "privacy":
31
+ if (adapter.id === "dpdp") {
32
+ return checks.dpdp.enabled ? undefined : "checks.dpdp.enabled is false";
33
+ }
34
+ return checks.privacy.enabled ? undefined : "checks.privacy.enabled is false";
35
+ case "correctness":
36
+ if (adapter.id === "flow-doctor" && checks.flowAnalysis.enabled === false) {
37
+ return "checks.flowAnalysis.enabled is false";
38
+ }
39
+ return checks.correctness.enabled ? undefined : "checks.correctness.enabled is false";
40
+ default:
41
+ return undefined;
42
+ }
43
+ }
4
44
  async function createScanPlan(project, config, adapters, mode) {
5
45
  const selected = [];
6
- const quickAdapterIds = new Set([
7
- "ruff",
8
- "biome",
9
- "tsc",
10
- "pyright",
11
- "gitleaks",
12
- "osv-scanner",
13
- "privacy-detector",
14
- "dpdp",
15
- "custom-leftovers"
16
- ]);
46
+ const excluded = [];
47
+ const deferred = new Set(config.runtime.deferredTools);
17
48
  for (const adapter of adapters) {
18
- if (adapter.category === "security" && !config.checks.security.enabled) {
19
- continue;
20
- }
21
- if (adapter.category === "correctness" && !config.checks.correctness.enabled) {
22
- continue;
23
- }
24
- if (adapter.category === "dead_code" && !config.checks.deadCode.enabled) {
25
- continue;
26
- }
27
- if (adapter.category === "leftovers" && !config.checks.leftovers.enabled) {
49
+ const disabled = disabledReason(adapter, config);
50
+ if (disabled) {
51
+ excluded.push({ id: adapter.id, state: "disabled", reason: `Turned off in config: ${disabled}.` });
28
52
  continue;
29
53
  }
30
- if (adapter.category === "refactor_readiness" && !config.checks.refactorReadiness.enabled) {
54
+ if (deferred.has(adapter.id)) {
55
+ excluded.push({
56
+ id: adapter.id,
57
+ state: "deferred",
58
+ reason: "Listed in runtime.deferred_tools, so it was deliberately not run."
59
+ });
31
60
  continue;
32
61
  }
33
- if (adapter.category === "dependencies" && !config.checks.dependencies.enabled) {
62
+ if (mode === "quick" && !exports.QUICK_ADAPTER_IDS.has(adapter.id)) {
63
+ excluded.push({
64
+ id: adapter.id,
65
+ state: "not_selected",
66
+ reason: "Not part of the quick profile. Run `vibedoctor scan` for the full applicable diagnosis."
67
+ });
34
68
  continue;
35
69
  }
36
- if (adapter.category === "privacy") {
37
- if (adapter.id === "dpdp") {
38
- if (!config.checks.dpdp.enabled) {
39
- continue;
40
- }
41
- }
42
- else if (!config.checks.privacy.enabled) {
43
- continue;
44
- }
45
- }
46
- if (mode === "quick" && !quickAdapterIds.has(adapter.id)) {
70
+ if (!(await adapter.detect(project, config))) {
71
+ excluded.push({
72
+ id: adapter.id,
73
+ state: "not_applicable",
74
+ reason: `Nothing in this repository matches what ${adapter.id} analyses (language, lockfile, or config not present).`
75
+ });
47
76
  continue;
48
77
  }
49
- if (await adapter.detect(project, config)) {
50
- selected.push(adapter.id);
51
- }
78
+ selected.push(adapter.id);
52
79
  }
53
80
  return {
54
81
  mode,
55
82
  adapterIds: selected,
83
+ excluded,
56
84
  changedOnly: mode === "changed",
57
- outputFull: mode === "full"
85
+ outputFull: mode === "full" || mode === "default"
58
86
  };
59
87
  }
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Minimal semver comparison and range satisfaction.
3
+ *
4
+ * VibeDoctor needs to answer one question in several places: "is the runtime we
5
+ * are about to hand a tool new enough for what that tool declares it needs?".
6
+ * The declared requirement comes from arbitrary package metadata
7
+ * (`engines.node`, `requires-python`), so it can use any of the common range
8
+ * shapes. Pulling in the full `semver` package for that would add a runtime
9
+ * dependency to a CLI that currently has three; this covers the shapes real
10
+ * engine fields use and reports "unknown" instead of guessing on anything else.
11
+ */
12
+ export type SemVersion = {
13
+ major: number;
14
+ minor: number;
15
+ patch: number;
16
+ prerelease?: string;
17
+ };
18
+ export declare function parseVersion(value: string | undefined): SemVersion | undefined;
19
+ export declare function formatVersion(version: SemVersion): string;
20
+ export declare function compareVersions(left: SemVersion, right: SemVersion): number;
21
+ /**
22
+ * Returns `undefined` when the range uses syntax this module does not model, so
23
+ * callers can report "could not verify" rather than a false pass or fail.
24
+ */
25
+ export declare function satisfiesRange(version: SemVersion, range: string | undefined): boolean | undefined;
26
+ /** The lowest version that could satisfy the range, for "you need at least X" messages. */
27
+ export declare function minimumSatisfying(range: string | undefined): string | undefined;
@@ -0,0 +1,163 @@
1
+ "use strict";
2
+ /**
3
+ * Minimal semver comparison and range satisfaction.
4
+ *
5
+ * VibeDoctor needs to answer one question in several places: "is the runtime we
6
+ * are about to hand a tool new enough for what that tool declares it needs?".
7
+ * The declared requirement comes from arbitrary package metadata
8
+ * (`engines.node`, `requires-python`), so it can use any of the common range
9
+ * shapes. Pulling in the full `semver` package for that would add a runtime
10
+ * dependency to a CLI that currently has three; this covers the shapes real
11
+ * engine fields use and reports "unknown" instead of guessing on anything else.
12
+ */
13
+ Object.defineProperty(exports, "__esModule", { value: true });
14
+ exports.parseVersion = parseVersion;
15
+ exports.formatVersion = formatVersion;
16
+ exports.compareVersions = compareVersions;
17
+ exports.satisfiesRange = satisfiesRange;
18
+ exports.minimumSatisfying = minimumSatisfying;
19
+ const VERSION_PATTERN = /(\d+)(?:\.(\d+))?(?:\.(\d+))?(?:[-+]([0-9A-Za-z.-]+))?/;
20
+ function parseVersion(value) {
21
+ if (!value) {
22
+ return undefined;
23
+ }
24
+ const match = VERSION_PATTERN.exec(value.trim());
25
+ if (!match) {
26
+ return undefined;
27
+ }
28
+ return {
29
+ major: Number(match[1]),
30
+ minor: Number(match[2] ?? 0),
31
+ patch: Number(match[3] ?? 0),
32
+ prerelease: match[4]
33
+ };
34
+ }
35
+ function formatVersion(version) {
36
+ const base = `${version.major}.${version.minor}.${version.patch}`;
37
+ return version.prerelease ? `${base}-${version.prerelease}` : base;
38
+ }
39
+ function compareVersions(left, right) {
40
+ if (left.major !== right.major) {
41
+ return left.major - right.major;
42
+ }
43
+ if (left.minor !== right.minor) {
44
+ return left.minor - right.minor;
45
+ }
46
+ if (left.patch !== right.patch) {
47
+ return left.patch - right.patch;
48
+ }
49
+ // A prerelease sorts below its own release (1.0.0-rc < 1.0.0).
50
+ if (left.prerelease && !right.prerelease) {
51
+ return -1;
52
+ }
53
+ if (!left.prerelease && right.prerelease) {
54
+ return 1;
55
+ }
56
+ return 0;
57
+ }
58
+ function comparatorsFor(token) {
59
+ const trimmed = token.trim().replace(/^v/, "");
60
+ if (!trimmed || trimmed === "*" || trimmed === "latest") {
61
+ return [];
62
+ }
63
+ const caret = /^\^\s*(.+)$/.exec(trimmed);
64
+ if (caret) {
65
+ const version = parseVersion(caret[1]);
66
+ if (!version) {
67
+ return undefined;
68
+ }
69
+ const upper = version.major > 0
70
+ ? { major: version.major + 1, minor: 0, patch: 0 }
71
+ : version.minor > 0
72
+ ? { major: 0, minor: version.minor + 1, patch: 0 }
73
+ : { major: 0, minor: version.minor, patch: version.patch + 1 };
74
+ return [
75
+ { operator: ">=", version },
76
+ { operator: "<", version: upper }
77
+ ];
78
+ }
79
+ const tilde = /^~\s*(.+)$/.exec(trimmed);
80
+ if (tilde) {
81
+ const version = parseVersion(tilde[1]);
82
+ if (!version) {
83
+ return undefined;
84
+ }
85
+ return [
86
+ { operator: ">=", version },
87
+ { operator: "<", version: { major: version.major, minor: version.minor + 1, patch: 0 } }
88
+ ];
89
+ }
90
+ const explicit = /^(>=|<=|>|<|=)\s*(.+)$/.exec(trimmed);
91
+ if (explicit) {
92
+ const version = parseVersion(explicit[2]);
93
+ if (!version) {
94
+ return undefined;
95
+ }
96
+ return [{ operator: explicit[1], version }];
97
+ }
98
+ const exact = parseVersion(trimmed);
99
+ return exact ? [{ operator: ">=", version: exact }] : undefined;
100
+ }
101
+ function satisfiesComparator(version, comparator) {
102
+ const delta = compareVersions(version, comparator.version);
103
+ switch (comparator.operator) {
104
+ case ">=":
105
+ return delta >= 0;
106
+ case ">":
107
+ return delta > 0;
108
+ case "<=":
109
+ return delta <= 0;
110
+ case "<":
111
+ return delta < 0;
112
+ case "=":
113
+ return delta === 0;
114
+ }
115
+ }
116
+ /**
117
+ * Returns `undefined` when the range uses syntax this module does not model, so
118
+ * callers can report "could not verify" rather than a false pass or fail.
119
+ */
120
+ function satisfiesRange(version, range) {
121
+ if (!range || !range.trim()) {
122
+ return true;
123
+ }
124
+ const alternatives = range.split("||");
125
+ let anyUnderstood = false;
126
+ for (const alternative of alternatives) {
127
+ const tokens = alternative.trim().split(/\s+/).filter(Boolean);
128
+ const comparators = [];
129
+ let understood = true;
130
+ for (const token of tokens) {
131
+ const parsed = comparatorsFor(token);
132
+ if (!parsed) {
133
+ understood = false;
134
+ break;
135
+ }
136
+ comparators.push(...parsed);
137
+ }
138
+ if (!understood) {
139
+ continue;
140
+ }
141
+ anyUnderstood = true;
142
+ if (comparators.every((comparator) => satisfiesComparator(version, comparator))) {
143
+ return true;
144
+ }
145
+ }
146
+ return anyUnderstood ? false : undefined;
147
+ }
148
+ /** The lowest version that could satisfy the range, for "you need at least X" messages. */
149
+ function minimumSatisfying(range) {
150
+ if (!range) {
151
+ return undefined;
152
+ }
153
+ const candidates = range
154
+ .split("||")
155
+ .flatMap((alternative) => alternative.trim().split(/\s+/).filter(Boolean))
156
+ .flatMap((token) => comparatorsFor(token) ?? [])
157
+ .filter((comparator) => comparator.operator === ">=" || comparator.operator === ">")
158
+ .map((comparator) => comparator.version);
159
+ if (candidates.length === 0) {
160
+ return undefined;
161
+ }
162
+ return formatVersion(candidates.sort(compareVersions)[0]);
163
+ }
@@ -0,0 +1,96 @@
1
+ import { type Finding } from "./finding";
2
+ /**
3
+ * Acknowledgement of findings that are known and accepted, with a reason and an
4
+ * expiry date.
5
+ *
6
+ * The only existing lever was the baseline, which answers "was this here
7
+ * before?" and nothing else. There was no way to say "this is a synthetic
8
+ * fixture", "we accept this risk until the Q3 migration", or "this is a false
9
+ * positive because the identifier is a cache key, not a credential" — so the
10
+ * same rejected findings came back every scan and users learned to ignore whole
11
+ * categories. A suppression here must carry a rationale, and one with an expiry
12
+ * stops hiding its findings the day it lapses rather than quietly living forever.
13
+ */
14
+ export declare const SUPPRESSIONS_FILE = ".vibedoctor/suppressions.yml";
15
+ export type SuppressionClassification = "false_positive" | "accepted_risk" | "deferred" | "fixture";
16
+ export type SuppressionMatch = {
17
+ /** Finding sources this rule applies to. */
18
+ tools?: string[];
19
+ /** Glob patterns against repository-relative paths. */
20
+ paths?: string[];
21
+ /** Finding titles / rule ids, matched case-insensitively as substrings. */
22
+ rules?: string[];
23
+ categories?: string[];
24
+ /** Exact fingerprints, for pinning a single finding. */
25
+ fingerprints?: string[];
26
+ };
27
+ export type SuppressionRule = {
28
+ id: string;
29
+ reason: string;
30
+ classification: SuppressionClassification;
31
+ owner?: string;
32
+ /** ISO date. Absent means a permanent exemption, which reports call out. */
33
+ expiresAt?: string;
34
+ match: SuppressionMatch;
35
+ };
36
+ export type InvalidSuppression = {
37
+ id: string;
38
+ problem: string;
39
+ };
40
+ export type SuppressionReport = {
41
+ file: string;
42
+ /** Rules in force. */
43
+ active: SuppressionRule[];
44
+ /** Rules past their expiry date; their findings are shown again. */
45
+ expired: SuppressionRule[];
46
+ /** Rules that could not be loaded, with the reason. Never silently dropped. */
47
+ invalid: InvalidSuppression[];
48
+ /** Rules with no expiry date, which never lapse on their own. */
49
+ permanent: string[];
50
+ /** How many findings each active rule hid this scan. */
51
+ hits: Record<string, number>;
52
+ /**
53
+ * How many findings each lapsed rule would have hidden. Counted separately
54
+ * from `hits` because these findings are shown, not suppressed; folding them
55
+ * together let a report claim the same finding was both hidden and resurfaced.
56
+ */
57
+ expiredHits: Record<string, number>;
58
+ /** Rules that matched nothing, so they can be cleaned up. */
59
+ unused: string[];
60
+ /** Findings that reappeared because a suppression lapsed. */
61
+ resurfaced: number;
62
+ /**
63
+ * Set when these counts cover more findings than the report they appear in
64
+ * (a category-filtered view), so they are not mistaken for the filtered slice.
65
+ */
66
+ scopeNote?: string;
67
+ };
68
+ export type LoadedSuppressions = {
69
+ file: string;
70
+ rules: SuppressionRule[];
71
+ invalid: InvalidSuppression[];
72
+ };
73
+ export declare function loadSuppressions(root: string, file?: string): Promise<LoadedSuppressions>;
74
+ export type ApplySuppressionsResult = {
75
+ /** Findings that survived. Suppressed findings are removed, not hidden in place. */
76
+ findings: Finding[];
77
+ /** Suppressed findings, kept so reports can show what was acknowledged. */
78
+ suppressed: Finding[];
79
+ report: SuppressionReport;
80
+ };
81
+ export type ApplySuppressionsOptions = {
82
+ now?: Date;
83
+ /**
84
+ * Reject acknowledgements with no expiry date rather than letting them hide
85
+ * findings forever. Rejected rules appear in `invalid` with the reason.
86
+ */
87
+ requireExpiry?: boolean;
88
+ };
89
+ /**
90
+ * Applies suppressions to findings. Expired rules do not suppress; instead their
91
+ * findings are marked `resurfaced` so a lapsed acknowledgement is visible rather
92
+ * than being mistaken for a new regression.
93
+ */
94
+ export declare function applySuppressions(findings: Finding[], loaded: LoadedSuppressions, options?: ApplySuppressionsOptions): ApplySuppressionsResult;
95
+ export declare function renderSuppressionLines(report: SuppressionReport): string[];
96
+ export declare const SUPPRESSIONS_TEMPLATE = "# VibeDoctor acknowledgements.\n#\n# Each entry hides findings that are known and accepted. A reason is required,\n# and an expiry date is strongly recommended: when it passes, the findings come\n# back marked \"resurfaced\" instead of staying hidden indefinitely.\nversion: 1\nsuppressions:\n # - id: fixture-credentials\n # reason: Synthetic credentials in test fixtures, never used against real systems.\n # classification: fixture # false_positive | accepted_risk | deferred | fixture\n # owner: platform-team\n # expires: 2026-12-31\n # match:\n # tools: [gitleaks]\n # paths: [\"fixtures/**\"]\n";