@neuralaxis/vibedoctor 0.2.0 → 0.2.1
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.
- package/README.md +86 -0
- package/dist/adapters/biome.js +135 -21
- package/dist/adapters/osvScanner.js +136 -17
- package/dist/adapters/presidio.js +3 -1
- package/dist/cli/commands/init.js +105 -50
- package/dist/cli/commands/privacyReview.js +3 -4
- package/dist/cli/commands/setup.d.ts +13 -17
- package/dist/cli/commands/setup.js +138 -200
- package/dist/core/capability.d.ts +92 -0
- package/dist/core/capability.js +122 -0
- package/dist/core/config.d.ts +36 -0
- package/dist/core/config.js +105 -3
- package/dist/core/credentialHeuristics.d.ts +28 -0
- package/dist/core/credentialHeuristics.js +179 -0
- package/dist/core/engine.d.ts +21 -0
- package/dist/core/engine.js +466 -85
- package/dist/core/executable.d.ts +18 -0
- package/dist/core/executable.js +137 -0
- package/dist/core/fileRole.d.ts +24 -0
- package/dist/core/fileRole.js +125 -0
- package/dist/core/finding.d.ts +124 -0
- package/dist/core/finding.js +62 -5
- package/dist/core/findingNormalizer.d.ts +33 -0
- package/dist/core/findingNormalizer.js +171 -0
- package/dist/core/projectDetector.d.ts +13 -0
- package/dist/core/projectDetector.js +100 -15
- package/dist/core/relevance.d.ts +87 -0
- package/dist/core/relevance.js +367 -0
- package/dist/core/scanPlanner.d.ts +12 -0
- package/dist/core/scanPlanner.js +61 -37
- package/dist/core/semverLite.d.ts +27 -0
- package/dist/core/semverLite.js +163 -0
- package/dist/core/suppressions.d.ts +96 -0
- package/dist/core/suppressions.js +302 -0
- package/dist/core/toolRegistry.d.ts +58 -0
- package/dist/core/toolRegistry.js +247 -0
- package/dist/core/toolRunner.d.ts +23 -2
- package/dist/core/toolRunner.js +61 -93
- package/dist/core/toolVerification.d.ts +87 -0
- package/dist/core/toolVerification.js +370 -0
- package/dist/dpdp/collectors/optionalScanners.js +120 -30
- package/dist/dpdp/findings.d.ts +33 -3
- package/dist/dpdp/findings.js +191 -4
- package/dist/dpdp/scan.js +2 -2
- package/dist/dpdp/scoring.d.ts +14 -4
- package/dist/dpdp/scoring.js +34 -8
- package/dist/dpdp/types.d.ts +19 -1
- package/dist/reporters/html.js +57 -13
- package/dist/reporters/json.js +7 -1
- package/dist/reporters/markdown.js +46 -4
- package/dist/reporters/sarif.js +54 -5
- package/package.json +1 -1
|
@@ -0,0 +1,171 @@
|
|
|
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.normalizeFindings = normalizeFindings;
|
|
7
|
+
exports.describeNormalizationIssues = describeNormalizationIssues;
|
|
8
|
+
const node_fs_1 = require("node:fs");
|
|
9
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
10
|
+
const finding_1 = require("./finding");
|
|
11
|
+
/**
|
|
12
|
+
* Default evidence grade per source. A tool that reports what the compiler
|
|
13
|
+
* proved is not making the same kind of claim as one matching a regex against
|
|
14
|
+
* identifiers, and the report should not present them identically.
|
|
15
|
+
*/
|
|
16
|
+
const DEFAULT_EVIDENCE_GRADE = {
|
|
17
|
+
tsc: "verified",
|
|
18
|
+
pyright: "verified",
|
|
19
|
+
biome: "verified",
|
|
20
|
+
ruff: "verified",
|
|
21
|
+
vitest: "verified",
|
|
22
|
+
jest: "verified",
|
|
23
|
+
"coverage.py": "verified",
|
|
24
|
+
"osv-scanner": "verified",
|
|
25
|
+
deptry: "verified",
|
|
26
|
+
radon: "verified",
|
|
27
|
+
lizard: "verified",
|
|
28
|
+
jscpd: "verified",
|
|
29
|
+
semgrep: "observed",
|
|
30
|
+
gitleaks: "observed",
|
|
31
|
+
presidio: "observed",
|
|
32
|
+
knip: "observed",
|
|
33
|
+
vulture: "heuristic",
|
|
34
|
+
"privacy-detector": "heuristic",
|
|
35
|
+
"telemetry-detector": "heuristic",
|
|
36
|
+
"privacy-ai-review": "heuristic",
|
|
37
|
+
"custom-leftovers": "observed",
|
|
38
|
+
"custom-refactor": "verified",
|
|
39
|
+
"custom-dead-chain": "heuristic",
|
|
40
|
+
dpdp: "heuristic"
|
|
41
|
+
};
|
|
42
|
+
const VALID_CATEGORIES = new Set(finding_1.FINDING_CATEGORIES);
|
|
43
|
+
const VALID_SEVERITIES = new Set(["info", "low", "medium", "high", "critical"]);
|
|
44
|
+
const VALID_CONFIDENCE = new Set(["low", "medium", "high"]);
|
|
45
|
+
function locationQualityFor(finding) {
|
|
46
|
+
if (!finding.file) {
|
|
47
|
+
return "repository";
|
|
48
|
+
}
|
|
49
|
+
if (finding.startLine === undefined) {
|
|
50
|
+
return "file_only";
|
|
51
|
+
}
|
|
52
|
+
return finding.startColumn === undefined ? "line_only" : "exact";
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Converts a byte offset into a 1-based line and column. Tools that report
|
|
56
|
+
* offsets (Biome among them) otherwise arrive with no position at all, because
|
|
57
|
+
* the report only understands lines.
|
|
58
|
+
*/
|
|
59
|
+
function offsetToPosition(content, offset) {
|
|
60
|
+
if (offset < 0 || offset > Buffer.byteLength(content, "utf8")) {
|
|
61
|
+
return undefined;
|
|
62
|
+
}
|
|
63
|
+
// Walk by byte length so multi-byte characters do not shift the result.
|
|
64
|
+
let bytes = 0;
|
|
65
|
+
let line = 1;
|
|
66
|
+
let column = 1;
|
|
67
|
+
for (const character of content) {
|
|
68
|
+
if (bytes >= offset) {
|
|
69
|
+
break;
|
|
70
|
+
}
|
|
71
|
+
bytes += Buffer.byteLength(character, "utf8");
|
|
72
|
+
if (character === "\n") {
|
|
73
|
+
line += 1;
|
|
74
|
+
column = 1;
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
column += 1;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return { line, column };
|
|
81
|
+
}
|
|
82
|
+
function createFileReader(root) {
|
|
83
|
+
const cache = new Map();
|
|
84
|
+
return async (file) => {
|
|
85
|
+
if (cache.has(file)) {
|
|
86
|
+
return cache.get(file);
|
|
87
|
+
}
|
|
88
|
+
let content;
|
|
89
|
+
try {
|
|
90
|
+
content = await node_fs_1.promises.readFile(node_path_1.default.join(root, file), "utf8");
|
|
91
|
+
}
|
|
92
|
+
catch {
|
|
93
|
+
content = undefined;
|
|
94
|
+
}
|
|
95
|
+
cache.set(file, content);
|
|
96
|
+
return content;
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
async function normalizeFindings(raw, options) {
|
|
100
|
+
const issues = new Map();
|
|
101
|
+
const readFile = createFileReader(options.root);
|
|
102
|
+
const changed = new Set(options.changedFiles ?? []);
|
|
103
|
+
const findings = [];
|
|
104
|
+
let withoutLocation = 0;
|
|
105
|
+
function note(kind, detail) {
|
|
106
|
+
const existing = issues.get(kind);
|
|
107
|
+
if (existing) {
|
|
108
|
+
existing.count += 1;
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
issues.set(kind, { tool: options.tool, kind, count: 1, detail });
|
|
112
|
+
}
|
|
113
|
+
for (const item of raw) {
|
|
114
|
+
const finding = { ...item };
|
|
115
|
+
if (!VALID_CATEGORIES.has(finding.category)) {
|
|
116
|
+
note("invalid_enum", `Unknown category "${finding.category}" was reported as maintainability.`);
|
|
117
|
+
finding.category = "maintainability";
|
|
118
|
+
}
|
|
119
|
+
if (!VALID_SEVERITIES.has(finding.severity)) {
|
|
120
|
+
note("invalid_enum", `Unknown severity "${finding.severity}" was reported as medium.`);
|
|
121
|
+
finding.severity = "medium";
|
|
122
|
+
}
|
|
123
|
+
if (!VALID_CONFIDENCE.has(finding.confidence)) {
|
|
124
|
+
note("invalid_enum", `Unknown confidence "${finding.confidence}" was reported as low.`);
|
|
125
|
+
finding.confidence = "low";
|
|
126
|
+
}
|
|
127
|
+
if (!finding.message?.trim()) {
|
|
128
|
+
note("missing_message", "A finding arrived with no message; its title was used instead.");
|
|
129
|
+
finding.message = finding.title || `${options.tool} reported an issue.`;
|
|
130
|
+
}
|
|
131
|
+
// Recover a position from a byte offset when the tool reports offsets only.
|
|
132
|
+
if (finding.file && finding.startLine === undefined && finding.evidence?.startOffset !== undefined) {
|
|
133
|
+
const content = await readFile(finding.file);
|
|
134
|
+
const position = content ? offsetToPosition(content, finding.evidence.startOffset) : undefined;
|
|
135
|
+
if (position) {
|
|
136
|
+
finding.startLine = position.line;
|
|
137
|
+
finding.startColumn = position.column;
|
|
138
|
+
if (finding.evidence.endOffset !== undefined && content) {
|
|
139
|
+
finding.endLine = offsetToPosition(content, finding.evidence.endOffset)?.line ?? position.line;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
else {
|
|
143
|
+
note("unresolved_offset", `${options.tool} reported byte offsets that could not be mapped to lines (file unreadable or offset out of range).`);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
finding.locationQuality = locationQualityFor(finding);
|
|
147
|
+
if (finding.locationQuality === "file_only" || finding.locationQuality === "repository") {
|
|
148
|
+
withoutLocation += 1;
|
|
149
|
+
if (finding.locationQuality === "file_only") {
|
|
150
|
+
note("missing_location", `${options.tool} reported findings without a line number.`);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
finding.evidenceGrade ??= DEFAULT_EVIDENCE_GRADE[finding.source] ?? "observed";
|
|
154
|
+
finding.fileRole ??= options.classifyFile(finding.file);
|
|
155
|
+
finding.inChangedFile ??= finding.file ? changed.has(finding.file) : false;
|
|
156
|
+
finding.tags = Array.from(new Set(finding.tags ?? []));
|
|
157
|
+
findings.push(finding);
|
|
158
|
+
}
|
|
159
|
+
return {
|
|
160
|
+
findings,
|
|
161
|
+
issues: Array.from(issues.values()),
|
|
162
|
+
locationLossRate: raw.length === 0 ? 0 : withoutLocation / raw.length
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
/** Human-readable summary of what a tool's output lost, for the capability matrix. */
|
|
166
|
+
function describeNormalizationIssues(issues) {
|
|
167
|
+
if (issues.length === 0) {
|
|
168
|
+
return undefined;
|
|
169
|
+
}
|
|
170
|
+
return issues.map((issue) => `${issue.detail} (${issue.count})`).join(" ");
|
|
171
|
+
}
|
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
export type ProjectLanguage = "python" | "javascript" | "typescript";
|
|
2
2
|
export type PackageManager = "npm" | "pnpm" | "yarn" | "bun" | "pip" | "uv" | "poetry" | "pdm";
|
|
3
|
+
/**
|
|
4
|
+
* Dependencies the project declares, split by how they reach production.
|
|
5
|
+
*
|
|
6
|
+
* Vulnerability findings arrive from lockfiles, which flatten that distinction
|
|
7
|
+
* away. Without it, an advisory in a build-time dev server is presented as
|
|
8
|
+
* equivalent to one in a library that handles user input.
|
|
9
|
+
*/
|
|
10
|
+
export type DeclaredDependencies = {
|
|
11
|
+
runtime: string[];
|
|
12
|
+
dev: string[];
|
|
13
|
+
optional: string[];
|
|
14
|
+
};
|
|
3
15
|
export type ProjectContext = {
|
|
4
16
|
root: string;
|
|
5
17
|
languages: ProjectLanguage[];
|
|
@@ -13,5 +25,6 @@ export type ProjectContext = {
|
|
|
13
25
|
frameworkHints: string[];
|
|
14
26
|
entryFiles: string[];
|
|
15
27
|
projectFiles: string[];
|
|
28
|
+
declaredDependencies?: DeclaredDependencies;
|
|
16
29
|
};
|
|
17
30
|
export declare function detectProject(root: string, excludePatterns?: string[]): Promise<ProjectContext>;
|
|
@@ -6,12 +6,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.detectProject = detectProject;
|
|
7
7
|
const node_fs_1 = require("node:fs");
|
|
8
8
|
const node_path_1 = __importDefault(require("node:path"));
|
|
9
|
-
const node_child_process_1 = require("node:child_process");
|
|
10
|
-
const node_util_1 = require("node:util");
|
|
11
9
|
const git_1 = require("./git");
|
|
12
10
|
const paths_1 = require("./paths");
|
|
13
|
-
const
|
|
14
|
-
const
|
|
11
|
+
const executable_1 = require("./executable");
|
|
12
|
+
const toolRegistry_1 = require("./toolRegistry");
|
|
15
13
|
const KNOWN_CONFIG_FILES = [
|
|
16
14
|
"package.json",
|
|
17
15
|
"tsconfig.json",
|
|
@@ -37,15 +35,14 @@ const KNOWN_CONFIG_FILES = [
|
|
|
37
35
|
];
|
|
38
36
|
const KNOWN_LOCKFILES = ["pnpm-lock.yaml", "package-lock.json", "yarn.lock", "bun.lockb", "uv.lock", "poetry.lock", "pdm.lock"];
|
|
39
37
|
const KNOWN_TOOLS = ["ruff", "biome", "knip", "vulture", "gitleaks", "osv-scanner", "semgrep", "tsc", "pyright", "eslint", "jest", "vitest", "coverage"];
|
|
38
|
+
/**
|
|
39
|
+
* Availability uses the same resolution the scanner uses to launch tools.
|
|
40
|
+
* Shelling out to `where`/`which` answered a subtly different question — it
|
|
41
|
+
* ignored the local `node_modules/.bin` and virtualenv directories the scanner
|
|
42
|
+
* adds to PATH — so a tool could be "unavailable" here and run fine in a scan.
|
|
43
|
+
*/
|
|
40
44
|
async function commandExists(command, root) {
|
|
41
|
-
|
|
42
|
-
try {
|
|
43
|
-
await execFileAsync(locator, [command], { cwd: root, env: (0, toolRunner_1.buildCommandEnv)(root, undefined), windowsHide: true });
|
|
44
|
-
return true;
|
|
45
|
-
}
|
|
46
|
-
catch {
|
|
47
|
-
return false;
|
|
48
|
-
}
|
|
45
|
+
return (0, executable_1.commandExists)(command, root);
|
|
49
46
|
}
|
|
50
47
|
function packageScriptCommand(packageManager, name) {
|
|
51
48
|
if (packageManager === "pnpm") {
|
|
@@ -103,7 +100,89 @@ async function readPackageMetadata(root, packageManager) {
|
|
|
103
100
|
if (pkg.workspaces) {
|
|
104
101
|
frameworkHints.push("monorepo");
|
|
105
102
|
}
|
|
106
|
-
return {
|
|
103
|
+
return {
|
|
104
|
+
testCommands,
|
|
105
|
+
frameworkHints,
|
|
106
|
+
declaredDependencies: {
|
|
107
|
+
runtime: Object.keys(pkg.dependencies ?? {}),
|
|
108
|
+
dev: Object.keys(pkg.devDependencies ?? {}),
|
|
109
|
+
optional: Object.keys({ ...(pkg.optionalDependencies ?? {}), ...(pkg.peerDependencies ?? {}) })
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Reads Python dependency declarations. Covers the shapes projects actually use:
|
|
115
|
+
* PEP 621 `project.dependencies`, PEP 735 `dependency-groups`, Poetry's groups,
|
|
116
|
+
* and plain requirements files.
|
|
117
|
+
*/
|
|
118
|
+
async function readPythonDependencies(root, projectFiles) {
|
|
119
|
+
const runtime = new Set();
|
|
120
|
+
const dev = new Set();
|
|
121
|
+
function addSpec(target, spec) {
|
|
122
|
+
// Strip version constraints, extras, and markers to leave the package name.
|
|
123
|
+
const name = spec
|
|
124
|
+
.trim()
|
|
125
|
+
.replace(/^-[er]\s+/, "")
|
|
126
|
+
.split(/[\s;]/)[0]
|
|
127
|
+
.split(/[<>=!~[]/)[0]
|
|
128
|
+
.trim();
|
|
129
|
+
if (name && !name.startsWith("#") && !name.startsWith("-")) {
|
|
130
|
+
target.add(name.toLowerCase());
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
const pyproject = node_path_1.default.join(root, "pyproject.toml");
|
|
134
|
+
if (await (0, paths_1.pathExists)(pyproject)) {
|
|
135
|
+
const content = await node_fs_1.promises.readFile(pyproject, "utf8");
|
|
136
|
+
// A dependency-aware TOML parse is more than this needs: dependency arrays
|
|
137
|
+
// are flat lists of strings, and misreading one only costs scope precision.
|
|
138
|
+
for (const match of content.matchAll(/^\s*(dependencies|optional-dependencies|dev-dependencies)\s*=\s*\[([^\]]*)\]/gms)) {
|
|
139
|
+
const target = match[1] === "dependencies" ? runtime : dev;
|
|
140
|
+
for (const spec of match[2].split(",")) {
|
|
141
|
+
const quoted = /["']([^"']+)["']/.exec(spec);
|
|
142
|
+
if (quoted) {
|
|
143
|
+
addSpec(target, quoted[1]);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
for (const match of content.matchAll(/^\s*\[(?:tool\.poetry\.group\.[\w-]+\.dependencies|dependency-groups)\]/gm)) {
|
|
148
|
+
// Group tables list one package per line after the header.
|
|
149
|
+
const start = match.index + match[0].length;
|
|
150
|
+
const block = content.slice(start).split(/^\s*\[/m)[0];
|
|
151
|
+
for (const line of block.split(/\r?\n/)) {
|
|
152
|
+
const entry = /^\s*([A-Za-z0-9_.-]+)\s*=/.exec(line);
|
|
153
|
+
if (entry) {
|
|
154
|
+
addSpec(dev, entry[1]);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
for (const file of projectFiles.filter((candidate) => /(^|\/)requirements[\w.-]*\.txt$/i.test(candidate))) {
|
|
160
|
+
const target = /dev|test|lint|ci/i.test(file) ? dev : runtime;
|
|
161
|
+
try {
|
|
162
|
+
const content = await node_fs_1.promises.readFile(node_path_1.default.join(root, file), "utf8");
|
|
163
|
+
for (const line of content.split(/\r?\n/)) {
|
|
164
|
+
addSpec(target, line);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
catch {
|
|
168
|
+
// Unreadable requirements file: scope stays unknown for its packages.
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
if (runtime.size === 0 && dev.size === 0) {
|
|
172
|
+
return undefined;
|
|
173
|
+
}
|
|
174
|
+
return { runtime: Array.from(runtime), dev: Array.from(dev), optional: [] };
|
|
175
|
+
}
|
|
176
|
+
function mergeDeclaredDependencies(...sources) {
|
|
177
|
+
const present = sources.filter((source) => Boolean(source));
|
|
178
|
+
if (present.length === 0) {
|
|
179
|
+
return undefined;
|
|
180
|
+
}
|
|
181
|
+
return {
|
|
182
|
+
runtime: Array.from(new Set(present.flatMap((source) => source.runtime))),
|
|
183
|
+
dev: Array.from(new Set(present.flatMap((source) => source.dev))),
|
|
184
|
+
optional: Array.from(new Set(present.flatMap((source) => source.optional)))
|
|
185
|
+
};
|
|
107
186
|
}
|
|
108
187
|
function isFrameworkEntryFile(file) {
|
|
109
188
|
return (/^(?:src\/)?app\/(?:.+\/)?(?:page|layout|route|loading|error|global-error|not-found|default|template)\.(ts|tsx|js|jsx)$/.test(file) ||
|
|
@@ -161,7 +240,12 @@ async function detectProject(root, excludePatterns) {
|
|
|
161
240
|
detectionFiles.some((file) => /(^|\/)tests?\//.test(file) && file.endsWith(".py"))) {
|
|
162
241
|
packageMetadata.testCommands.push(pythonTestCommand(packageManagers));
|
|
163
242
|
}
|
|
164
|
-
|
|
243
|
+
// Probe every executable the registry knows about, not a hand-maintained
|
|
244
|
+
// subset. Tools missing from that subset always looked unavailable, so setup
|
|
245
|
+
// reinstalled them on every run and the scan could never confirm them.
|
|
246
|
+
const probeTargets = Array.from(new Set([...KNOWN_TOOLS, ...(0, toolRegistry_1.registryExecutables)()]));
|
|
247
|
+
const toolPairs = await Promise.all(probeTargets.map(async (tool) => [tool, await commandExists(tool, root)]));
|
|
248
|
+
const pythonDependencies = await readPythonDependencies(root, detectionFiles);
|
|
165
249
|
const entryFiles = detectionFiles.filter((file) => /(^|\/)(main|index|app|server|cli)\.(ts|tsx|js|jsx|py)$/.test(file) || isFrameworkEntryFile(file) || file.endsWith("package.json"));
|
|
166
250
|
return {
|
|
167
251
|
root,
|
|
@@ -177,6 +261,7 @@ async function detectProject(root, excludePatterns) {
|
|
|
177
261
|
toolsAvailable: Object.fromEntries(toolPairs),
|
|
178
262
|
frameworkHints: Array.from(frameworkHints).sort(),
|
|
179
263
|
entryFiles,
|
|
180
|
-
projectFiles
|
|
264
|
+
projectFiles,
|
|
265
|
+
declaredDependencies: mergeDeclaredDependencies(packageMetadata.declaredDependencies, pythonDependencies)
|
|
181
266
|
};
|
|
182
267
|
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import type { Confidence, EvidenceGrade, Finding } from "./finding";
|
|
2
|
+
/**
|
|
3
|
+
* Turns raw tool output into a report worth reading.
|
|
4
|
+
*
|
|
5
|
+
* Every scanner ships its own idea of what to report, and none of them know what
|
|
6
|
+
* else ran. The result was a report where a type-checker's 857 pre-existing
|
|
7
|
+
* findings, a dead-code detector's 12,060 low-confidence guesses, and three real
|
|
8
|
+
* secrets all arrived as one flat list — so the real items were unreachable.
|
|
9
|
+
*
|
|
10
|
+
* The controls here are uniform across tools rather than patched into each
|
|
11
|
+
* adapter: a confidence floor, awareness of what kind of file a finding sits in,
|
|
12
|
+
* validation of claims that a value is a credential, ranking that puts new and
|
|
13
|
+
* changed-code findings first, and a cap. Nothing is dropped silently: every
|
|
14
|
+
* filter records what it withheld and why, and that reaches the report.
|
|
15
|
+
*/
|
|
16
|
+
export type RelevanceToolPolicy = {
|
|
17
|
+
minConfidence?: Confidence;
|
|
18
|
+
minEvidenceGrade?: EvidenceGrade;
|
|
19
|
+
/** 0 means no cap. */
|
|
20
|
+
maxFindings?: number;
|
|
21
|
+
/** Only surface findings another tool also reported. */
|
|
22
|
+
requireCorroboration?: boolean;
|
|
23
|
+
};
|
|
24
|
+
export type RelevanceConfig = {
|
|
25
|
+
enabled: boolean;
|
|
26
|
+
minConfidence: Confidence;
|
|
27
|
+
maxFindingsPerTool: number;
|
|
28
|
+
maxFindingsTotal: number;
|
|
29
|
+
/** What to do with findings in tests, fixtures, generated, and vendored files. */
|
|
30
|
+
syntheticFilePolicy: "keep" | "downgrade" | "drop";
|
|
31
|
+
/** Check that findings claiming to be credentials look like credentials. */
|
|
32
|
+
validateSecrets: boolean;
|
|
33
|
+
perTool: Record<string, RelevanceToolPolicy>;
|
|
34
|
+
};
|
|
35
|
+
export declare const defaultRelevanceConfig: RelevanceConfig;
|
|
36
|
+
/** Reasons a finding did not reach the report. Each one is disclosed, never silent. */
|
|
37
|
+
export type WithholdReason = "below_confidence_floor" | "below_evidence_floor" | "synthetic_file" | "not_corroborated" | "over_tool_cap" | "over_total_cap";
|
|
38
|
+
export type WithheldGroup = {
|
|
39
|
+
reason: WithholdReason;
|
|
40
|
+
count: number;
|
|
41
|
+
detail: string;
|
|
42
|
+
/** How to see the withheld findings if they are wanted. */
|
|
43
|
+
remediation: string;
|
|
44
|
+
};
|
|
45
|
+
export type ToolRelevance = {
|
|
46
|
+
tool: string;
|
|
47
|
+
reported: number;
|
|
48
|
+
surfaced: number;
|
|
49
|
+
withheld: WithheldGroup[];
|
|
50
|
+
/** Findings whose severity or confidence was adjusted rather than removed. */
|
|
51
|
+
adjusted: number;
|
|
52
|
+
};
|
|
53
|
+
export type RelevanceReport = {
|
|
54
|
+
enabled: boolean;
|
|
55
|
+
perTool: ToolRelevance[];
|
|
56
|
+
totalReported: number;
|
|
57
|
+
totalSurfaced: number;
|
|
58
|
+
/** Human-readable notes for the report footer. */
|
|
59
|
+
notes: string[];
|
|
60
|
+
/**
|
|
61
|
+
* Set when these totals describe a wider set of findings than the report they
|
|
62
|
+
* appear in (a category-filtered view), so the counts are not read as if they
|
|
63
|
+
* applied to the filtered slice.
|
|
64
|
+
*/
|
|
65
|
+
scopeNote?: string;
|
|
66
|
+
};
|
|
67
|
+
/**
|
|
68
|
+
* Ranks a finding by how much it deserves a reader's attention. Severity leads,
|
|
69
|
+
* but a new finding in code the author just touched outranks an older, nominally
|
|
70
|
+
* more severe one they cannot act on right now.
|
|
71
|
+
*/
|
|
72
|
+
export declare function computePriority(finding: Finding): number;
|
|
73
|
+
export type ApplyRelevanceOptions = {
|
|
74
|
+
root: string;
|
|
75
|
+
config: RelevanceConfig;
|
|
76
|
+
};
|
|
77
|
+
export type ApplyRelevanceResult = {
|
|
78
|
+
findings: Finding[];
|
|
79
|
+
report: RelevanceReport;
|
|
80
|
+
};
|
|
81
|
+
/**
|
|
82
|
+
* Applies relevance controls to the deduped finding set. Runs after dedupe so
|
|
83
|
+
* corroboration between tools is already recorded, and after the baseline so
|
|
84
|
+
* new-versus-existing can drive ranking.
|
|
85
|
+
*/
|
|
86
|
+
export declare function applyRelevance(findings: Finding[], options: ApplyRelevanceOptions): Promise<ApplyRelevanceResult>;
|
|
87
|
+
export declare function renderRelevanceLines(report: RelevanceReport): string[];
|