@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
@@ -0,0 +1,18 @@
1
+ export declare function getPathKey(env: NodeJS.ProcessEnv): string;
2
+ export declare function getLocalToolSearchPaths(cwd: string | undefined): string[];
3
+ export declare function buildCommandEnv(cwd: string | undefined, overrides: NodeJS.ProcessEnv | undefined): NodeJS.ProcessEnv;
4
+ export type ResolvedExecutable = {
5
+ /** Absolute path to the file that will actually be launched. */
6
+ path: string;
7
+ /** True when the resolved file must be launched through a shell (.cmd/.bat). */
8
+ requiresShell: boolean;
9
+ };
10
+ /**
11
+ * Resolves a command name to a concrete file, searching the same augmented PATH
12
+ * the scanner uses. Returns undefined when nothing on PATH matches — callers
13
+ * should treat that as "not installed" and report the searched locations.
14
+ */
15
+ export declare function resolveExecutable(command: string, cwd?: string, env?: NodeJS.ProcessEnv): ResolvedExecutable | undefined;
16
+ export declare function commandExists(command: string, cwd?: string): boolean;
17
+ /** The directories searched, so a "not found" report can say where we looked. */
18
+ export declare function describeSearchPaths(cwd?: string): string[];
@@ -0,0 +1,137 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.getPathKey = getPathKey;
7
+ exports.getLocalToolSearchPaths = getLocalToolSearchPaths;
8
+ exports.buildCommandEnv = buildCommandEnv;
9
+ exports.resolveExecutable = resolveExecutable;
10
+ exports.commandExists = commandExists;
11
+ exports.describeSearchPaths = describeSearchPaths;
12
+ const node_path_1 = __importDefault(require("node:path"));
13
+ const node_fs_1 = require("node:fs");
14
+ /**
15
+ * Executable discovery, shared by every code path that needs to know whether a
16
+ * tool is usable.
17
+ *
18
+ * Setup used to answer "is this installed?" with one mechanism (`where`/`which`
19
+ * against a bare name) while the scanner answered it with another (PATH probing
20
+ * plus a shell fallback). When the two disagreed, setup reported success for a
21
+ * tool the scanner could not run. Everything now resolves through
22
+ * `resolveExecutable` against the same augmented environment, so "setup found
23
+ * it" and "the scanner can run it" are the same claim.
24
+ */
25
+ const LOCAL_TOOL_PATHS = [
26
+ ["node_modules", ".bin"],
27
+ [".venv", "Scripts"],
28
+ [".venv", "bin"],
29
+ ["venv", "Scripts"],
30
+ ["venv", "bin"]
31
+ ];
32
+ function ancestorDirs(startDir) {
33
+ if (!startDir) {
34
+ return [];
35
+ }
36
+ const dirs = [];
37
+ let current = node_path_1.default.resolve(startDir);
38
+ while (true) {
39
+ dirs.push(current);
40
+ const parent = node_path_1.default.dirname(current);
41
+ if (parent === current) {
42
+ return dirs;
43
+ }
44
+ current = parent;
45
+ }
46
+ }
47
+ function getPathKey(env) {
48
+ return Object.keys(env).find((key) => key.toLowerCase() === "path") ?? "PATH";
49
+ }
50
+ function getLocalToolSearchPaths(cwd) {
51
+ const paths = ancestorDirs(cwd).flatMap((dir) => LOCAL_TOOL_PATHS.map((segments) => node_path_1.default.join(dir, ...segments)));
52
+ return Array.from(new Set(paths));
53
+ }
54
+ function getUserToolSearchPaths(env) {
55
+ const paths = [];
56
+ if (process.platform === "win32" && env.APPDATA) {
57
+ const pythonRoot = node_path_1.default.join(env.APPDATA, "Python");
58
+ try {
59
+ for (const entry of (0, node_fs_1.readdirSync)(pythonRoot, { withFileTypes: true })) {
60
+ if (entry.isDirectory() && /^Python\d+$/i.test(entry.name)) {
61
+ paths.push(node_path_1.default.join(pythonRoot, entry.name, "Scripts"));
62
+ }
63
+ }
64
+ }
65
+ catch {
66
+ // Python user packages have not been installed for this account.
67
+ }
68
+ }
69
+ else if (env.HOME) {
70
+ paths.push(node_path_1.default.join(env.HOME, ".local", "bin"));
71
+ }
72
+ return paths;
73
+ }
74
+ function buildCommandEnv(cwd, overrides) {
75
+ const env = { ...process.env, ...overrides };
76
+ const pathKey = getPathKey(env);
77
+ const existingPath = env[pathKey];
78
+ env[pathKey] = [...getLocalToolSearchPaths(cwd), ...getUserToolSearchPaths(env), existingPath]
79
+ .filter(Boolean)
80
+ .join(node_path_1.default.delimiter);
81
+ return env;
82
+ }
83
+ function isExecutableFile(candidate) {
84
+ try {
85
+ if (!(0, node_fs_1.statSync)(candidate).isFile()) {
86
+ return false;
87
+ }
88
+ }
89
+ catch {
90
+ return false;
91
+ }
92
+ if (process.platform === "win32") {
93
+ return true;
94
+ }
95
+ try {
96
+ (0, node_fs_1.accessSync)(candidate, node_fs_1.constants.X_OK);
97
+ return true;
98
+ }
99
+ catch {
100
+ return false;
101
+ }
102
+ }
103
+ /**
104
+ * Resolves a command name to a concrete file, searching the same augmented PATH
105
+ * the scanner uses. Returns undefined when nothing on PATH matches — callers
106
+ * should treat that as "not installed" and report the searched locations.
107
+ */
108
+ function resolveExecutable(command, cwd, env = buildCommandEnv(cwd, undefined)) {
109
+ if (node_path_1.default.isAbsolute(command)) {
110
+ return isExecutableFile(command) ? { path: command, requiresShell: /\.(?:cmd|bat)$/i.test(command) } : undefined;
111
+ }
112
+ const pathValue = env[getPathKey(env)] ?? "";
113
+ const directories = pathValue.split(node_path_1.default.delimiter).filter(Boolean);
114
+ const extensions = process.platform === "win32"
115
+ ? // An explicit extension on the command wins; otherwise try each PATHEXT entry.
116
+ node_path_1.default.extname(command)
117
+ ? [""]
118
+ : (env.PATHEXT ?? ".COM;.EXE;.BAT;.CMD").split(";").map((extension) => extension.toLowerCase())
119
+ : [""];
120
+ for (const directory of directories) {
121
+ for (const extension of extensions) {
122
+ const candidate = node_path_1.default.join(directory, `${command}${extension}`);
123
+ if ((0, node_fs_1.existsSync)(candidate) && isExecutableFile(candidate)) {
124
+ return { path: candidate, requiresShell: /\.(?:cmd|bat)$/i.test(candidate) };
125
+ }
126
+ }
127
+ }
128
+ return undefined;
129
+ }
130
+ function commandExists(command, cwd) {
131
+ return resolveExecutable(command, cwd) !== undefined;
132
+ }
133
+ /** The directories searched, so a "not found" report can say where we looked. */
134
+ function describeSearchPaths(cwd) {
135
+ const env = buildCommandEnv(cwd, undefined);
136
+ return (env[getPathKey(env)] ?? "").split(node_path_1.default.delimiter).filter(Boolean);
137
+ }
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Classifies what a file is for.
3
+ *
4
+ * Relevance decisions kept being made per tool: one detector learned to ignore
5
+ * fixtures, another flagged them as critical. A secret in a test fixture, a dead
6
+ * function in a generated client, and a type error in production code are not
7
+ * the same finding, and every tool needs the same answer to that question.
8
+ */
9
+ export type FileRole = "source" | "test" | "fixture" | "generated" | "vendor" | "config" | "docs" | "unknown";
10
+ export type FileRoleClassifier = (file: string | undefined) => FileRole;
11
+ export type FileRoleOverrides = Partial<Record<FileRole, string[]>>;
12
+ /**
13
+ * Builds a classifier. Repository-specific globs are checked before the defaults
14
+ * so a project can correct a misclassification without disabling the rest.
15
+ */
16
+ export declare function createFileRoleClassifier(overrides?: FileRoleOverrides): FileRoleClassifier;
17
+ /** Roles where a finding is usually about the repository's real behaviour. */
18
+ export declare function isProductionRole(role: FileRole): boolean;
19
+ /**
20
+ * Roles where a "secret", a dead function, or a hardcoded personal identifier is
21
+ * expected by design. Findings here are still reported, at reduced severity, so
22
+ * a real leak in a fixture is not hidden outright.
23
+ */
24
+ export declare function isSyntheticRole(role: FileRole): boolean;
@@ -0,0 +1,125 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createFileRoleClassifier = createFileRoleClassifier;
4
+ exports.isProductionRole = isProductionRole;
5
+ exports.isSyntheticRole = isSyntheticRole;
6
+ const minimatch_1 = require("minimatch");
7
+ const DEFAULT_ROLE_PATTERNS = [
8
+ {
9
+ role: "fixture",
10
+ patterns: [
11
+ "**/fixtures/**",
12
+ "**/fixture/**",
13
+ "**/__fixtures__/**",
14
+ "**/testdata/**",
15
+ "**/test-data/**",
16
+ "**/mocks/**",
17
+ "**/__mocks__/**",
18
+ "**/samples/**",
19
+ "**/examples/**",
20
+ "**/seeds/**",
21
+ "**/*.fixture.*",
22
+ "**/*.mock.*"
23
+ ]
24
+ },
25
+ {
26
+ role: "test",
27
+ patterns: [
28
+ "**/test/**",
29
+ "**/tests/**",
30
+ "**/__tests__/**",
31
+ "**/spec/**",
32
+ "**/*.test.*",
33
+ "**/*.spec.*",
34
+ "**/*_test.py",
35
+ "**/test_*.py",
36
+ "**/conftest.py",
37
+ "**/e2e/**"
38
+ ]
39
+ },
40
+ {
41
+ role: "generated",
42
+ patterns: [
43
+ "**/*.generated.*",
44
+ "**/*.gen.*",
45
+ "**/generated/**",
46
+ "**/__generated__/**",
47
+ "**/*_pb2.py",
48
+ "**/*_pb2_grpc.py",
49
+ "**/*.pb.go",
50
+ "**/migrations/**",
51
+ "**/.next/**",
52
+ "**/dist/**",
53
+ "**/build/**",
54
+ "**/*.min.js",
55
+ "**/*.d.ts",
56
+ "**/*.snap"
57
+ ]
58
+ },
59
+ {
60
+ role: "vendor",
61
+ patterns: ["**/vendor/**", "**/node_modules/**", "**/third_party/**", "**/site-packages/**", "**/.venv/**"]
62
+ },
63
+ {
64
+ role: "config",
65
+ patterns: [
66
+ "*.json",
67
+ "*.yml",
68
+ "*.yaml",
69
+ "*.toml",
70
+ "*.ini",
71
+ "*.cfg",
72
+ "**/.*rc",
73
+ "**/.*rc.*",
74
+ "**/*.config.*",
75
+ "**/Dockerfile*",
76
+ "**/*.env.example",
77
+ "**/.github/**"
78
+ ]
79
+ },
80
+ {
81
+ role: "docs",
82
+ patterns: ["**/*.md", "**/*.mdx", "**/*.rst", "**/*.txt", "**/docs/**", "**/LICENSE*", "**/CHANGELOG*"]
83
+ }
84
+ ];
85
+ /**
86
+ * Builds a classifier. Repository-specific globs are checked before the defaults
87
+ * so a project can correct a misclassification without disabling the rest.
88
+ */
89
+ function createFileRoleClassifier(overrides = {}) {
90
+ const compiled = [];
91
+ for (const [role, patterns] of Object.entries(overrides)) {
92
+ if (patterns && patterns.length > 0) {
93
+ compiled.push({ role, matchers: patterns.map((pattern) => new minimatch_1.Minimatch(pattern, { dot: true })) });
94
+ }
95
+ }
96
+ for (const { role, patterns } of DEFAULT_ROLE_PATTERNS) {
97
+ compiled.push({ role, matchers: patterns.map((pattern) => new minimatch_1.Minimatch(pattern, { dot: true })) });
98
+ }
99
+ const cache = new Map();
100
+ return (file) => {
101
+ if (!file) {
102
+ return "unknown";
103
+ }
104
+ const cached = cache.get(file);
105
+ if (cached) {
106
+ return cached;
107
+ }
108
+ const normalized = file.split("\\").join("/");
109
+ const role = compiled.find(({ matchers }) => matchers.some((matcher) => matcher.match(normalized)))?.role ?? "source";
110
+ cache.set(file, role);
111
+ return role;
112
+ };
113
+ }
114
+ /** Roles where a finding is usually about the repository's real behaviour. */
115
+ function isProductionRole(role) {
116
+ return role === "source" || role === "config";
117
+ }
118
+ /**
119
+ * Roles where a "secret", a dead function, or a hardcoded personal identifier is
120
+ * expected by design. Findings here are still reported, at reduced severity, so
121
+ * a real leak in a fixture is not hidden outright.
122
+ */
123
+ function isSyntheticRole(role) {
124
+ return role === "fixture" || role === "test" || role === "generated" || role === "vendor";
125
+ }
@@ -1,9 +1,98 @@
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"];
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", "flow-doctor"];
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];
5
5
  export type Severity = "info" | "low" | "medium" | "high" | "critical";
6
6
  export type Confidence = "low" | "medium" | "high";
7
+ /**
8
+ * How strongly the evidence supports the claim, independent of how bad the claim
9
+ * would be if true.
10
+ *
11
+ * Severity and confidence together could not express the difference between "we
12
+ * traced this data into a log call" and "a variable name looked like an email
13
+ * field", so both were presented the same way. Reports that mix the two read as
14
+ * stronger than the evidence supports.
15
+ */
16
+ export type EvidenceGrade =
17
+ /** A code path was followed and the claim holds. */
18
+ "verified"
19
+ /** A concrete match exists at a real location; its meaning is inferred. */
20
+ | "observed"
21
+ /** Inferred from names, patterns, or shape rather than behaviour. */
22
+ | "heuristic"
23
+ /** Neither presence nor absence could be established from the code. */
24
+ | "unproven";
25
+ /**
26
+ * For findings that assert something is missing, whether the absence is a fact
27
+ * or a limit of static analysis. A missing control and an unprovable control
28
+ * need different responses, and conflating them inflates readiness scores.
29
+ */
30
+ export type AbsenceClaim = "control_absent" | "not_statically_provable" | "not_applicable";
31
+ /** How precisely the finding is anchored in the source. */
32
+ export type LocationQuality =
33
+ /** File, line, and column. */
34
+ "exact"
35
+ /** File and line. */
36
+ | "line_only"
37
+ /** File only; the tool reported no position. */
38
+ | "file_only"
39
+ /** No file; the claim is about the repository as a whole. */
40
+ | "repository";
41
+ /** Where a finding stands relative to the recorded baseline. */
42
+ export type BaselineState =
43
+ /** Not in the baseline. */
44
+ "new"
45
+ /** In the baseline; pre-existing debt. */
46
+ | "existing"
47
+ /** In the baseline but previously suppressed, and the suppression has lapsed. */
48
+ | "resurfaced";
49
+ /** One hop in a traced data path, for findings that follow data rather than match text. */
50
+ export type DataFlowStep = {
51
+ kind: "source" | "store" | "transform" | "processor" | "sink";
52
+ /** What this step is, in the repository's own terms ("sessionStorage", "OpenAI chat completion"). */
53
+ label: string;
54
+ file?: string;
55
+ startLine?: number;
56
+ /** How this specific hop was established. */
57
+ evidenceGrade: EvidenceGrade;
58
+ detail?: string;
59
+ };
60
+ /** What kind of work a fix actually is, so it reaches the right person. */
61
+ export type RemediationKind = "code" | "config" | "dependency" | "policy" | "human_review";
62
+ export type FindingRemediation = {
63
+ kind: RemediationKind;
64
+ /** The component or module that owns the fix. */
65
+ component?: string;
66
+ steps: string[];
67
+ /** What would have to be shown for this finding to be considered resolved. */
68
+ requiredEvidence?: string;
69
+ /** Set when the fix is not something an automated agent should attempt. */
70
+ requiresHumanDecision?: boolean;
71
+ };
72
+ /** Dependency identity, so advisories can be triaged rather than just counted. */
73
+ export type PackageReference = {
74
+ name: string;
75
+ version?: string;
76
+ ecosystem?: string;
77
+ /** Runtime exposure. A dev-only advisory is not equivalent to a shipped one. */
78
+ scope: "runtime" | "dev" | "optional" | "transitive" | "unknown";
79
+ /** Path from a direct dependency to this package. */
80
+ dependencyPath?: string[];
81
+ /** First version that resolves the advisory. */
82
+ fixedIn?: string;
83
+ /** Manifest or lockfile the dependency was read from. */
84
+ manifest?: string;
85
+ };
86
+ export type FindingSuppression = {
87
+ /** Suppression rule that matched. */
88
+ ruleId: string;
89
+ classification: "false_positive" | "accepted_risk" | "deferred" | "fixture";
90
+ reason: string;
91
+ owner?: string;
92
+ /** ISO date. A suppression without an expiry is a permanent exemption. */
93
+ expiresAt?: string;
94
+ expired: boolean;
95
+ };
7
96
  export type Finding = {
8
97
  id: string;
9
98
  source: FindingSource;
@@ -15,12 +104,40 @@ export type Finding = {
15
104
  file?: string;
16
105
  startLine?: number;
17
106
  endLine?: number;
107
+ startColumn?: number;
108
+ endColumn?: number;
18
109
  isNew: boolean;
19
110
  isAutofixable: boolean;
20
111
  safeToAutofix: boolean;
21
112
  fixCommand?: string;
22
113
  agentInstruction?: string;
23
114
  tags: string[];
115
+ /** How well the evidence supports the claim. Defaults per source at normalization. */
116
+ evidenceGrade?: EvidenceGrade;
117
+ /** Only meaningful for findings asserting something is missing. */
118
+ absenceClaim?: AbsenceClaim;
119
+ /** Set by the normalizer from whichever position fields the tool supplied. */
120
+ locationQuality?: LocationQuality;
121
+ /** Traced path from data source to sink, when the finding follows data. */
122
+ dataFlow?: DataFlowStep[];
123
+ remediation?: FindingRemediation;
124
+ package?: PackageReference;
125
+ /** Position relative to the baseline. `isNew` stays as the boolean shorthand. */
126
+ baselineState?: BaselineState;
127
+ /** True when the finding sits in a file changed on this branch. */
128
+ inChangedFile?: boolean;
129
+ /** Role of the containing file, used for relevance decisions. */
130
+ fileRole?: "source" | "test" | "fixture" | "generated" | "vendor" | "config" | "docs" | "unknown";
131
+ /** Ranking score used to order and cap output. Higher is more worth reading. */
132
+ priority?: number;
133
+ /**
134
+ * Other tools that independently reported the same problem. Agreement between
135
+ * tools is the cheapest available corroboration, and it lets noisy detectors
136
+ * be filtered down to their cross-validated subset.
137
+ */
138
+ corroboratedBy?: string[];
139
+ /** Present when a suppression rule matched this finding. */
140
+ suppression?: FindingSuppression;
24
141
  evidence?: {
25
142
  snippet?: string;
26
143
  toolRawId?: string;
@@ -39,6 +156,13 @@ export type Finding = {
39
156
  rationale?: string;
40
157
  recommendedAction?: string;
41
158
  reasons?: string[];
159
+ /**
160
+ * Byte offset into the file, when a tool reports positions that way. The
161
+ * normalizer converts it to a line number so no tool's locations are lost
162
+ * just because it uses a different position model.
163
+ */
164
+ startOffset?: number;
165
+ endOffset?: number;
42
166
  };
43
167
  scoreImpact: number;
44
168
  };
@@ -37,7 +37,8 @@ exports.FINDING_SOURCES = [
37
37
  "dpdp",
38
38
  "custom-leftovers",
39
39
  "custom-refactor",
40
- "custom-dead-chain"
40
+ "custom-dead-chain",
41
+ "flow-doctor"
41
42
  ];
42
43
  exports.FINDING_CATEGORIES = [
43
44
  "security",
@@ -72,8 +73,12 @@ function normalizeFilePath(file, root) {
72
73
  if (!file) {
73
74
  return undefined;
74
75
  }
75
- const normalized = file.replaceAll("/", node_path_1.default.sep);
76
- const relative = node_path_1.default.isAbsolute(normalized) ? node_path_1.default.relative(root, normalized) : normalized;
76
+ // Scanners emit both separators (Biome on Windows even writes unescaped `\`
77
+ // into JSON). Reports always use POSIX-style relative paths, so treat `\` as
78
+ // a separator first rather than hoping `path.sep` matches the input.
79
+ const withPosix = file.replaceAll("\\", "/");
80
+ const asNative = withPosix.replaceAll("/", node_path_1.default.sep);
81
+ const relative = node_path_1.default.isAbsolute(asNative) ? node_path_1.default.relative(root, asNative) : asNative;
77
82
  return relative.split(node_path_1.default.sep).join("/");
78
83
  }
79
84
  function stableSnippetHash(value) {
@@ -91,11 +96,17 @@ function fingerprintFinding(finding) {
91
96
  return (0, node_crypto_1.createHash)("sha1").update(payload).digest("hex");
92
97
  }
93
98
  function applyBaseline(findings, baselineFingerprints) {
94
- return findings.map((finding) => ({
95
- ...finding,
96
- id: finding.id || fingerprintFinding(finding),
97
- isNew: !baselineFingerprints.has(fingerprintFinding(finding))
98
- }));
99
+ return findings.map((finding) => {
100
+ const isNew = !baselineFingerprints.has(fingerprintFinding(finding));
101
+ return {
102
+ ...finding,
103
+ id: finding.id || fingerprintFinding(finding),
104
+ isNew,
105
+ // A finding whose suppression has lapsed is neither new nor quietly
106
+ // pre-existing: it was deliberately hidden and that decision has expired.
107
+ baselineState: finding.suppression?.expired ? "resurfaced" : isNew ? "new" : "existing"
108
+ };
109
+ });
99
110
  }
100
111
  function dedupeKey(finding) {
101
112
  return [
@@ -118,6 +129,46 @@ const confidenceOrder = {
118
129
  medium: 1,
119
130
  high: 2
120
131
  };
132
+ const evidenceGradeOrder = {
133
+ unproven: 0,
134
+ heuristic: 1,
135
+ observed: 2,
136
+ verified: 3
137
+ };
138
+ const locationQualityOrder = {
139
+ repository: 0,
140
+ file_only: 1,
141
+ line_only: 2,
142
+ exact: 3
143
+ };
144
+ /**
145
+ * When two tools report the same problem, keep the better-supported version of
146
+ * each fact rather than whichever arrived first: the stronger evidence grade,
147
+ * the more precise location, and any structured detail the other tool lacked.
148
+ */
149
+ function mergeEvidenceGrade(left, right) {
150
+ if (!left.evidenceGrade) {
151
+ return right.evidenceGrade;
152
+ }
153
+ if (!right.evidenceGrade) {
154
+ return left.evidenceGrade;
155
+ }
156
+ return evidenceGradeOrder[right.evidenceGrade] > evidenceGradeOrder[left.evidenceGrade]
157
+ ? right.evidenceGrade
158
+ : left.evidenceGrade;
159
+ }
160
+ function preferPreciseLocation(left, right) {
161
+ const leftRank = locationQualityOrder[left.locationQuality ?? "file_only"];
162
+ const rightRank = locationQualityOrder[right.locationQuality ?? "file_only"];
163
+ const winner = rightRank > leftRank ? right : left;
164
+ return {
165
+ startLine: winner.startLine,
166
+ endLine: winner.endLine,
167
+ startColumn: winner.startColumn,
168
+ endColumn: winner.endColumn,
169
+ locationQuality: winner.locationQuality
170
+ };
171
+ }
121
172
  function dedupeFindings(findings) {
122
173
  const byKey = new Map();
123
174
  for (const finding of findings) {
@@ -140,6 +191,17 @@ function dedupeFindings(findings) {
140
191
  evidence: existing.evidence ?? finding.evidence,
141
192
  fixCommand: existing.fixCommand ?? finding.fixCommand,
142
193
  agentInstruction: existing.agentInstruction ?? finding.agentInstruction,
194
+ ...preferPreciseLocation(existing, finding),
195
+ evidenceGrade: mergeEvidenceGrade(existing, finding),
196
+ absenceClaim: existing.absenceClaim ?? finding.absenceClaim,
197
+ dataFlow: existing.dataFlow ?? finding.dataFlow,
198
+ remediation: existing.remediation ?? finding.remediation,
199
+ package: existing.package ?? finding.package,
200
+ fileRole: existing.fileRole ?? finding.fileRole,
201
+ suppression: existing.suppression ?? finding.suppression,
202
+ inChangedFile: existing.inChangedFile ?? finding.inChangedFile,
203
+ // Two tools agreeing is itself corroboration, so record who else saw it.
204
+ corroboratedBy: Array.from(new Set([...(existing.corroboratedBy ?? []), ...(finding.corroboratedBy ?? []), finding.source, existing.source])).filter((source) => source !== existing.source),
143
205
  scoreImpact: Math.max(existing.scoreImpact, finding.scoreImpact)
144
206
  });
145
207
  }
@@ -0,0 +1,19 @@
1
+ import type { Finding, FindingCategory, Severity } from "./finding";
2
+ export type FindingLocation = {
3
+ file?: string;
4
+ startLine?: number;
5
+ endLine?: number;
6
+ };
7
+ export type RootCauseGroup = {
8
+ id: string;
9
+ title: string;
10
+ severity: Severity;
11
+ category: FindingCategory;
12
+ findingIds: string[];
13
+ supportingEngines: string[];
14
+ likelyRootCause: string;
15
+ locations: FindingLocation[];
16
+ };
17
+ export declare function inferRootCause(finding: Finding): string;
18
+ export declare function correlateFindings(findings: Finding[]): RootCauseGroup[];
19
+ export declare function locationKeyForTests(finding: Finding): string | undefined;