@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.
- package/README.md +135 -23
- package/dist/adapters/biome.js +136 -21
- package/dist/adapters/flowDoctor.d.ts +7 -0
- package/dist/adapters/flowDoctor.js +195 -0
- package/dist/adapters/gitleaks.js +4 -2
- package/dist/adapters/index.d.ts +1 -0
- package/dist/adapters/index.js +3 -1
- package/dist/adapters/osvScanner.js +140 -19
- package/dist/adapters/presidio.js +3 -1
- package/dist/adapters/ruff.js +7 -3
- package/dist/adapters/shared.d.ts +4 -0
- package/dist/cli/commands/init.js +112 -50
- package/dist/cli/commands/privacyReview.js +3 -4
- package/dist/cli/commands/scan.d.ts +6 -0
- package/dist/cli/commands/scan.js +16 -2
- package/dist/cli/commands/setup.d.ts +13 -17
- package/dist/cli/commands/setup.js +138 -200
- package/dist/cli/index.js +4 -4
- package/dist/core/agentDiagnosis.d.ts +39 -0
- package/dist/core/agentDiagnosis.js +96 -0
- package/dist/core/capability.d.ts +92 -0
- package/dist/core/capability.js +122 -0
- package/dist/core/config.d.ts +47 -0
- package/dist/core/config.js +134 -3
- package/dist/core/credentialHeuristics.d.ts +28 -0
- package/dist/core/credentialHeuristics.js +179 -0
- package/dist/core/engine.d.ts +29 -1
- package/dist/core/engine.js +510 -126
- 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 +125 -1
- package/dist/core/finding.js +70 -8
- package/dist/core/findingCorrelator.d.ts +19 -0
- package/dist/core/findingCorrelator.js +112 -0
- package/dist/core/findingNormalizer.d.ts +33 -0
- package/dist/core/findingNormalizer.js +172 -0
- package/dist/core/managedTools.d.ts +25 -0
- package/dist/core/managedTools.js +186 -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/repoGraph.d.ts +62 -0
- package/dist/core/repoGraph.js +408 -0
- package/dist/core/riskRanker.d.ts +6 -0
- package/dist/core/riskRanker.js +127 -0
- package/dist/core/scanContext.d.ts +26 -0
- package/dist/core/scanContext.js +44 -0
- package/dist/core/scanPlanner.d.ts +13 -0
- package/dist/core/scanPlanner.js +66 -38
- 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 +254 -0
- package/dist/core/toolRunner.d.ts +27 -2
- package/dist/core/toolRunner.js +79 -93
- package/dist/core/toolRuntime.d.ts +40 -0
- package/dist/core/toolRuntime.js +417 -0
- package/dist/core/toolVerification.d.ts +89 -0
- package/dist/core/toolVerification.js +425 -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/index.d.ts +5 -0
- package/dist/index.js +5 -0
- package/dist/reporters/agent.d.ts +1 -1
- package/dist/reporters/agent.js +7 -0
- 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 +80 -80
|
@@ -0,0 +1,408 @@
|
|
|
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.normalizeRoutePath = normalizeRoutePath;
|
|
7
|
+
exports.pathsCompatible = pathsCompatible;
|
|
8
|
+
exports.linkRepoGraph = linkRepoGraph;
|
|
9
|
+
exports.buildRepoGraph = buildRepoGraph;
|
|
10
|
+
exports.routeMatchesCall = routeMatchesCall;
|
|
11
|
+
const node_fs_1 = require("node:fs");
|
|
12
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
13
|
+
const SOURCE_EXTS = new Set([".ts", ".tsx", ".js", ".jsx", ".py"]);
|
|
14
|
+
const MAX_FILE_BYTES = 512_000;
|
|
15
|
+
function normalizeMethod(method) {
|
|
16
|
+
return method.toUpperCase();
|
|
17
|
+
}
|
|
18
|
+
function normalizeRoutePath(raw) {
|
|
19
|
+
const withoutQuery = raw.split("?")[0].trim();
|
|
20
|
+
const withSlash = withoutQuery.startsWith("/") ? withoutQuery : `/${withoutQuery}`;
|
|
21
|
+
return withSlash
|
|
22
|
+
.replace(/\/+$/, "")
|
|
23
|
+
.replace(/\{[^}]+\}/g, ":param")
|
|
24
|
+
.replace(/:[A-Za-z_][\w]*/g, ":param")
|
|
25
|
+
.replace(/\[[^\]]+\]/g, ":param")
|
|
26
|
+
|| "/";
|
|
27
|
+
}
|
|
28
|
+
function stripCommonApiPrefix(normalized) {
|
|
29
|
+
return normalized.replace(/^\/api(?=\/|$)/, "") || "/";
|
|
30
|
+
}
|
|
31
|
+
function pathsCompatible(left, right) {
|
|
32
|
+
const a = normalizeRoutePath(left);
|
|
33
|
+
const b = normalizeRoutePath(right);
|
|
34
|
+
if (a === b) {
|
|
35
|
+
return true;
|
|
36
|
+
}
|
|
37
|
+
// SPA clients typically call /api/users while Express mounts /users.
|
|
38
|
+
return stripCommonApiPrefix(a) === stripCommonApiPrefix(b);
|
|
39
|
+
}
|
|
40
|
+
function isCommentLine(line, python) {
|
|
41
|
+
const trimmed = line.trim();
|
|
42
|
+
return python ? trimmed.startsWith("#") : trimmed.startsWith("//") || trimmed.startsWith("*") || trimmed.startsWith("/*");
|
|
43
|
+
}
|
|
44
|
+
function parseJsTs(file, content) {
|
|
45
|
+
const imports = [];
|
|
46
|
+
const symbols = [];
|
|
47
|
+
const calls = [];
|
|
48
|
+
const httpCalls = [];
|
|
49
|
+
const routes = [];
|
|
50
|
+
const errorPaths = [];
|
|
51
|
+
const lines = content.split(/\r?\n/);
|
|
52
|
+
for (let index = 0; index < lines.length; index += 1) {
|
|
53
|
+
const line = lines[index];
|
|
54
|
+
const lineNo = index + 1;
|
|
55
|
+
if (isCommentLine(line, false)) {
|
|
56
|
+
continue;
|
|
57
|
+
}
|
|
58
|
+
imports.push(...parseJsImports(file, line));
|
|
59
|
+
const fnMatch = /(?:export\s+)?(?:async\s+)?function\s+([A-Za-z_$][\w$]*)/.exec(line);
|
|
60
|
+
if (fnMatch) {
|
|
61
|
+
symbols.push({ file, name: fnMatch[1], kind: "function", line: lineNo, exported: /^\s*export\b/.test(line) });
|
|
62
|
+
}
|
|
63
|
+
const constFn = /(?:export\s+)?(?:const|let|var)\s+([A-Za-z_$][\w$]*)\s*=\s*(?:async\s+)?(?:function\b|\([^)]*\)\s*=>)/.exec(line);
|
|
64
|
+
if (constFn) {
|
|
65
|
+
symbols.push({ file, name: constFn[1], kind: "function", line: lineNo, exported: /^\s*export\b/.test(line) });
|
|
66
|
+
}
|
|
67
|
+
const exportList = /^\s*export\s*\{([^}]+)\}/.exec(line);
|
|
68
|
+
if (exportList) {
|
|
69
|
+
for (const raw of exportList[1].split(",")) {
|
|
70
|
+
const local = raw.trim().split(/\s+as\s+/)[0]?.trim();
|
|
71
|
+
const existing = symbols.find((symbol) => symbol.file === file && symbol.name === local);
|
|
72
|
+
if (existing) {
|
|
73
|
+
existing.exported = true;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
for (const callMatch of line.matchAll(/\b([A-Za-z_$][\w$]*)\s*\(/g)) {
|
|
78
|
+
if (!/^(if|for|while|switch|catch|function|return|async)$/.test(callMatch[1])) {
|
|
79
|
+
calls.push({ file, callee: callMatch[1], line: lineNo });
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
const fetchMatch = /\bfetch\s*\(\s*(['"`])([^'"`]+)\1/.exec(line) ??
|
|
83
|
+
/\baxios\.(get|post|put|patch|delete)\s*\(\s*(['"`])([^'"`]+)\2/i.exec(line);
|
|
84
|
+
if (fetchMatch) {
|
|
85
|
+
const method = fetchMatch.length === 4 ? fetchMatch[1] : methodFromFetchOptions(lines, index);
|
|
86
|
+
const rawPath = fetchMatch.length === 4 ? fetchMatch[3] : fetchMatch[2];
|
|
87
|
+
httpCalls.push(httpCallFrom(file, lineNo, method, rawPath, line));
|
|
88
|
+
}
|
|
89
|
+
const routeMatch = /\b(?:app|router|server)\.(get|post|put|patch|delete|all)\s*\(\s*(['"`])([^'"`]+)\2\s*(?:,\s*(?:async\s+)?([A-Za-z_$][\w$]*)(\.[A-Za-z_$][\w$]*)?)?/i.exec(line);
|
|
90
|
+
if (routeMatch && /get|post|put|patch|delete|all/i.test(routeMatch[1])) {
|
|
91
|
+
const handlerName = routeMatch[4];
|
|
92
|
+
const reserved = handlerName && /^(function|async|await|return|if)$/i.test(handlerName);
|
|
93
|
+
routes.push({
|
|
94
|
+
file,
|
|
95
|
+
line: lineNo,
|
|
96
|
+
method: normalizeMethod(routeMatch[1] === "all" ? "*" : routeMatch[1]),
|
|
97
|
+
path: routeMatch[3],
|
|
98
|
+
handler: reserved ? undefined : handlerName,
|
|
99
|
+
handlerMember: Boolean(routeMatch[5])
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
const exportedHandler = /export\s+async\s+function\s+(GET|POST|PUT|PATCH|DELETE)\b/.exec(line);
|
|
103
|
+
if (exportedHandler) {
|
|
104
|
+
const fromFile = fileBasedRoute(file);
|
|
105
|
+
if (fromFile) {
|
|
106
|
+
routes.push({
|
|
107
|
+
file,
|
|
108
|
+
line: lineNo,
|
|
109
|
+
method: exportedHandler[1],
|
|
110
|
+
path: fromFile,
|
|
111
|
+
handler: exportedHandler[1],
|
|
112
|
+
handlerFile: file,
|
|
113
|
+
handlerLine: lineNo
|
|
114
|
+
});
|
|
115
|
+
symbols.push({ file, name: exportedHandler[1], kind: "handler", line: lineNo, exported: true });
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
errorPaths.push(...detectJsErrorPaths(file, content));
|
|
120
|
+
return { imports, symbols, calls, httpCalls, routes, errorPaths };
|
|
121
|
+
}
|
|
122
|
+
function parsePython(file, content) {
|
|
123
|
+
const imports = [];
|
|
124
|
+
const symbols = [];
|
|
125
|
+
const calls = [];
|
|
126
|
+
const httpCalls = [];
|
|
127
|
+
const routes = [];
|
|
128
|
+
const errorPaths = [];
|
|
129
|
+
const pendingPythonRoute = new Map();
|
|
130
|
+
const lines = content.split(/\r?\n/);
|
|
131
|
+
for (let index = 0; index < lines.length; index += 1) {
|
|
132
|
+
const line = lines[index];
|
|
133
|
+
const lineNo = index + 1;
|
|
134
|
+
if (isCommentLine(line, true)) {
|
|
135
|
+
continue;
|
|
136
|
+
}
|
|
137
|
+
const fromImport = /^\s*from\s+([\w.]+)\s+import\s+(.+)$/.exec(line);
|
|
138
|
+
if (fromImport) {
|
|
139
|
+
const names = fromImport[2]
|
|
140
|
+
.split(",")
|
|
141
|
+
.map((part) => part.trim().split(/\s+as\s+/).pop()?.trim())
|
|
142
|
+
.filter((name) => Boolean(name) && name !== "*");
|
|
143
|
+
imports.push({ from: file, specifier: fromImport[1], names, external: !fromImport[1].startsWith(".") });
|
|
144
|
+
}
|
|
145
|
+
else {
|
|
146
|
+
const importMatch = /^\s*import\s+([\w.]+)/.exec(line);
|
|
147
|
+
if (importMatch) {
|
|
148
|
+
imports.push({ from: file, specifier: importMatch[1], names: [importMatch[1].split(".").pop() ?? importMatch[1]], external: !importMatch[1].startsWith(".") });
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
const fnMatch = /^\s*(?:async\s+)?def\s+([A-Za-z_][\w]*)/.exec(line);
|
|
152
|
+
if (fnMatch) {
|
|
153
|
+
symbols.push({ file, name: fnMatch[1], kind: "function", line: lineNo, exported: true });
|
|
154
|
+
const pending = pendingPythonRoute.get(file);
|
|
155
|
+
if (pending) {
|
|
156
|
+
pending.handler = fnMatch[1];
|
|
157
|
+
pending.handlerFile = file;
|
|
158
|
+
pending.handlerLine = lineNo;
|
|
159
|
+
pendingPythonRoute.delete(file);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
for (const callMatch of line.matchAll(/\b([A-Za-z_][\w]*)\s*\(/g)) {
|
|
163
|
+
if (!/^(if|for|while|except|def|return|print|len|range)$/.test(callMatch[1])) {
|
|
164
|
+
calls.push({ file, callee: callMatch[1], line: lineNo });
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
const client = /\b(?:requests|httpx)\.(get|post|put|patch|delete)\s*\(\s*(['"])([^'"]+)\2/i.exec(line);
|
|
168
|
+
if (client) {
|
|
169
|
+
httpCalls.push(httpCallFrom(file, lineNo, client[1], client[3], line));
|
|
170
|
+
}
|
|
171
|
+
const decorator = /@(?:app|router|api)\.(get|post|put|patch|delete)\s*\(\s*(['"])([^'"]+)\2/i.exec(line);
|
|
172
|
+
if (decorator) {
|
|
173
|
+
const route = { file, line: lineNo, method: normalizeMethod(decorator[1]), path: decorator[3] };
|
|
174
|
+
routes.push(route);
|
|
175
|
+
pendingPythonRoute.set(file, route);
|
|
176
|
+
}
|
|
177
|
+
const flask = /\b(?:app|blueprint)\.add_url_rule\s*\(\s*(['"])([^'"]+)\1[^)]*methods\s*=\s*\[[^\]]*['"](GET|POST|PUT|PATCH|DELETE)['"]/i.exec(line);
|
|
178
|
+
if (flask) {
|
|
179
|
+
routes.push({ file, line: lineNo, method: normalizeMethod(flask[3]), path: flask[2] });
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
errorPaths.push(...detectPyErrorPaths(file, content));
|
|
183
|
+
return { imports, symbols, calls, httpCalls, routes, errorPaths };
|
|
184
|
+
}
|
|
185
|
+
function parseJsImports(file, line) {
|
|
186
|
+
const edges = [];
|
|
187
|
+
const named = /import\s+(?:type\s+)?(?:[A-Za-z_$][\w$]*\s*,\s*)?\{([^}]+)\}\s+from\s+['"]([^'"]+)['"]/.exec(line);
|
|
188
|
+
if (named) {
|
|
189
|
+
const names = named[1]
|
|
190
|
+
.split(",")
|
|
191
|
+
.map((part) => {
|
|
192
|
+
const bits = part.trim().split(/\s+as\s+/);
|
|
193
|
+
return (bits[1] ?? bits[0])?.trim();
|
|
194
|
+
})
|
|
195
|
+
.filter((name) => Boolean(name));
|
|
196
|
+
edges.push({ from: file, specifier: named[2], names, external: !named[2].startsWith(".") });
|
|
197
|
+
}
|
|
198
|
+
const def = /import\s+(?:type\s+)?([A-Za-z_$][\w$]*)\s+from\s+['"]([^'"]+)['"]/.exec(line);
|
|
199
|
+
if (def) {
|
|
200
|
+
edges.push({ from: file, specifier: def[2], names: [def[1]], external: !def[2].startsWith(".") });
|
|
201
|
+
}
|
|
202
|
+
const req = /require\s*\(\s*['"]([^'"]+)['"]/.exec(line);
|
|
203
|
+
if (req && !named && !def) {
|
|
204
|
+
edges.push({ from: file, specifier: req[1], names: [], external: !req[1].startsWith(".") });
|
|
205
|
+
}
|
|
206
|
+
return edges;
|
|
207
|
+
}
|
|
208
|
+
const JS_RESOLVE_EXTS = [".ts", ".tsx", ".js", ".jsx", ""];
|
|
209
|
+
function resolveSpecifier(fromFile, specifier, files) {
|
|
210
|
+
if (!specifier.startsWith(".")) {
|
|
211
|
+
return undefined;
|
|
212
|
+
}
|
|
213
|
+
const fromDir = fromFile.includes("/") ? fromFile.slice(0, fromFile.lastIndexOf("/")) : "";
|
|
214
|
+
const joined = node_path_1.default.posix.normalize(`${fromDir}/${specifier}`).replace(/^\.\//, "");
|
|
215
|
+
const candidates = [
|
|
216
|
+
...JS_RESOLVE_EXTS.map((ext) => `${joined}${ext}`),
|
|
217
|
+
`${joined}/index.ts`,
|
|
218
|
+
`${joined}/index.js`,
|
|
219
|
+
`${joined}/index.tsx`,
|
|
220
|
+
`${joined}.py`
|
|
221
|
+
];
|
|
222
|
+
return candidates.find((candidate) => files.has(candidate));
|
|
223
|
+
}
|
|
224
|
+
function linkRepoGraph(graph) {
|
|
225
|
+
const files = new Set(graph.files);
|
|
226
|
+
for (const route of graph.routes) {
|
|
227
|
+
const handlerName = route.handler;
|
|
228
|
+
if (!handlerName || route.handlerMember || route.handlerFile) {
|
|
229
|
+
continue;
|
|
230
|
+
}
|
|
231
|
+
const local = graph.symbols.find((symbol) => symbol.file === route.file && symbol.name === handlerName);
|
|
232
|
+
if (local) {
|
|
233
|
+
route.handlerFile = local.file;
|
|
234
|
+
route.handlerLine = local.line;
|
|
235
|
+
continue;
|
|
236
|
+
}
|
|
237
|
+
const imported = graph.imports.find((edge) => edge.from === route.file && edge.names.includes(handlerName));
|
|
238
|
+
if (imported?.external) {
|
|
239
|
+
route.handlerExternal = true;
|
|
240
|
+
continue;
|
|
241
|
+
}
|
|
242
|
+
if (imported) {
|
|
243
|
+
const target = resolveSpecifier(route.file, imported.specifier, files);
|
|
244
|
+
if (target) {
|
|
245
|
+
const remote = graph.symbols.find((symbol) => symbol.file === target && symbol.name === handlerName);
|
|
246
|
+
if (remote) {
|
|
247
|
+
route.handlerFile = remote.file;
|
|
248
|
+
route.handlerLine = remote.line;
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
return graph;
|
|
254
|
+
}
|
|
255
|
+
function methodFromFetchOptions(lines, startIndex) {
|
|
256
|
+
for (let index = startIndex; index < lines.length && index < startIndex + 10; index += 1) {
|
|
257
|
+
const match = /method\s*:\s*['"](GET|POST|PUT|PATCH|DELETE)['"]/i.exec(lines[index]);
|
|
258
|
+
if (match) {
|
|
259
|
+
return match[1];
|
|
260
|
+
}
|
|
261
|
+
if (index > startIndex && /^\s*\)\s*;?\s*$/.test(lines[index])) {
|
|
262
|
+
break;
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
return undefined;
|
|
266
|
+
}
|
|
267
|
+
function httpCallFrom(file, line, method, rawPath, sourceLine) {
|
|
268
|
+
const dynamic = /\$\{|%[sdf]|f["']/.test(rawPath) || /\$\{/.test(sourceLine);
|
|
269
|
+
const absolute = /^https?:\/\//i.test(rawPath);
|
|
270
|
+
return {
|
|
271
|
+
file,
|
|
272
|
+
line,
|
|
273
|
+
method: normalizeMethod(method ?? "GET"),
|
|
274
|
+
methodExplicit: Boolean(method),
|
|
275
|
+
path: rawPath,
|
|
276
|
+
dynamic,
|
|
277
|
+
absolute
|
|
278
|
+
};
|
|
279
|
+
}
|
|
280
|
+
function fileBasedRoute(file) {
|
|
281
|
+
const posix = file.replaceAll("\\", "/");
|
|
282
|
+
const appApi = /(?:^|\/)app\/(api\/.+)\/route\.(t|j)sx?$/.exec(posix);
|
|
283
|
+
if (appApi) {
|
|
284
|
+
return `/${appApi[1]}`.replace(/\/route$/, "");
|
|
285
|
+
}
|
|
286
|
+
const pagesApi = /(?:^|\/)pages\/(api\/.+)\.(t|j)sx?$/.exec(posix);
|
|
287
|
+
if (pagesApi) {
|
|
288
|
+
return `/${pagesApi[1]}`;
|
|
289
|
+
}
|
|
290
|
+
return undefined;
|
|
291
|
+
}
|
|
292
|
+
function detectJsErrorPaths(file, content) {
|
|
293
|
+
const findings = [];
|
|
294
|
+
const emptyCatch = /catch\s*(?:\([^)]*\))?\s*\{\s*\}/g;
|
|
295
|
+
let match;
|
|
296
|
+
while ((match = emptyCatch.exec(content))) {
|
|
297
|
+
findings.push({
|
|
298
|
+
file,
|
|
299
|
+
line: lineNumberAt(content, match.index),
|
|
300
|
+
kind: "empty_handler",
|
|
301
|
+
detail: "Empty catch swallows the error."
|
|
302
|
+
});
|
|
303
|
+
}
|
|
304
|
+
const successAfter = /catch\s*(?:\([^)]*\))?\s*\{[^}]*(?:status\s*\(\s*20\d\s*\)|\bok\s*:\s*true|\bsuccess\s*:\s*true)[^}]*\}/gis;
|
|
305
|
+
while ((match = successAfter.exec(content))) {
|
|
306
|
+
findings.push({
|
|
307
|
+
file,
|
|
308
|
+
line: lineNumberAt(content, match.index),
|
|
309
|
+
kind: "success_after_failure",
|
|
310
|
+
detail: "Caught failure then emitted an HTTP 2xx or success payload."
|
|
311
|
+
});
|
|
312
|
+
}
|
|
313
|
+
return findings;
|
|
314
|
+
}
|
|
315
|
+
function detectPyErrorPaths(file, content) {
|
|
316
|
+
const findings = [];
|
|
317
|
+
const lines = content.split(/\r?\n/);
|
|
318
|
+
for (let index = 0; index < lines.length; index += 1) {
|
|
319
|
+
if (!/^\s*except\b/.test(lines[index])) {
|
|
320
|
+
continue;
|
|
321
|
+
}
|
|
322
|
+
const body = [];
|
|
323
|
+
let cursor = index + 1;
|
|
324
|
+
const indent = /^\s*/.exec(lines[index])?.[0].length ?? 0;
|
|
325
|
+
while (cursor < lines.length) {
|
|
326
|
+
const next = lines[cursor];
|
|
327
|
+
if (next.trim() === "") {
|
|
328
|
+
cursor += 1;
|
|
329
|
+
continue;
|
|
330
|
+
}
|
|
331
|
+
const nextIndent = /^\s*/.exec(next)?.[0].length ?? 0;
|
|
332
|
+
if (nextIndent <= indent) {
|
|
333
|
+
break;
|
|
334
|
+
}
|
|
335
|
+
body.push(next.trim());
|
|
336
|
+
cursor += 1;
|
|
337
|
+
}
|
|
338
|
+
const meaningful = body.filter((line) => line && !line.startsWith("#"));
|
|
339
|
+
if (meaningful.length === 0 || meaningful.every((line) => line === "pass" || line === "...")) {
|
|
340
|
+
findings.push({
|
|
341
|
+
file,
|
|
342
|
+
line: index + 1,
|
|
343
|
+
kind: "empty_handler",
|
|
344
|
+
detail: "except handler is empty or only pass."
|
|
345
|
+
});
|
|
346
|
+
}
|
|
347
|
+
else if (meaningful.some((line) => /return\s+.*\b(200|ok\s*=\s*True|success)/i.test(line))) {
|
|
348
|
+
findings.push({
|
|
349
|
+
file,
|
|
350
|
+
line: index + 1,
|
|
351
|
+
kind: "success_after_failure",
|
|
352
|
+
detail: "except handler returns a success response."
|
|
353
|
+
});
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
return findings;
|
|
357
|
+
}
|
|
358
|
+
function lineNumberAt(content, index) {
|
|
359
|
+
return content.slice(0, index).split(/\r?\n/).length;
|
|
360
|
+
}
|
|
361
|
+
async function buildRepoGraph(root, files) {
|
|
362
|
+
const list = "files" in files ? [...files.files] : [...files];
|
|
363
|
+
const graph = {
|
|
364
|
+
files: [],
|
|
365
|
+
imports: [],
|
|
366
|
+
symbols: [],
|
|
367
|
+
calls: [],
|
|
368
|
+
httpCalls: [],
|
|
369
|
+
routes: [],
|
|
370
|
+
errorPaths: []
|
|
371
|
+
};
|
|
372
|
+
for (const file of list) {
|
|
373
|
+
const ext = node_path_1.default.extname(file).toLowerCase();
|
|
374
|
+
if (!SOURCE_EXTS.has(ext)) {
|
|
375
|
+
continue;
|
|
376
|
+
}
|
|
377
|
+
const absolute = node_path_1.default.join(root, file);
|
|
378
|
+
let content;
|
|
379
|
+
try {
|
|
380
|
+
const stat = await node_fs_1.promises.stat(absolute);
|
|
381
|
+
if (stat.size > MAX_FILE_BYTES) {
|
|
382
|
+
continue;
|
|
383
|
+
}
|
|
384
|
+
content = await node_fs_1.promises.readFile(absolute, "utf8");
|
|
385
|
+
}
|
|
386
|
+
catch {
|
|
387
|
+
continue;
|
|
388
|
+
}
|
|
389
|
+
graph.files.push(file);
|
|
390
|
+
const parsed = ext === ".py" ? parsePython(file, content) : parseJsTs(file, content);
|
|
391
|
+
graph.imports.push(...parsed.imports);
|
|
392
|
+
graph.symbols.push(...parsed.symbols);
|
|
393
|
+
graph.calls.push(...parsed.calls);
|
|
394
|
+
graph.httpCalls.push(...parsed.httpCalls);
|
|
395
|
+
graph.routes.push(...parsed.routes);
|
|
396
|
+
graph.errorPaths.push(...parsed.errorPaths);
|
|
397
|
+
}
|
|
398
|
+
return linkRepoGraph(graph);
|
|
399
|
+
}
|
|
400
|
+
function routeMatchesCall(call, route) {
|
|
401
|
+
if (call.dynamic || !call.methodExplicit) {
|
|
402
|
+
return false;
|
|
403
|
+
}
|
|
404
|
+
if (route.method !== "*" && route.method !== call.method) {
|
|
405
|
+
return false;
|
|
406
|
+
}
|
|
407
|
+
return pathsCompatible(call.path, route.path);
|
|
408
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { Finding, FindingCategory } from "./finding";
|
|
2
|
+
export declare function isStyleOrHygieneFinding(finding: Finding): boolean;
|
|
3
|
+
export declare function isLikelyRealBug(finding: Finding): boolean;
|
|
4
|
+
export declare function riskScore(finding: Finding): number;
|
|
5
|
+
export declare function rankFindings(findings: Finding[]): Finding[];
|
|
6
|
+
export declare const RANKING_CATEGORY_HINT: FindingCategory[];
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RANKING_CATEGORY_HINT = void 0;
|
|
4
|
+
exports.isStyleOrHygieneFinding = isStyleOrHygieneFinding;
|
|
5
|
+
exports.isLikelyRealBug = isLikelyRealBug;
|
|
6
|
+
exports.riskScore = riskScore;
|
|
7
|
+
exports.rankFindings = rankFindings;
|
|
8
|
+
/**
|
|
9
|
+
* Holistic risk ranking. Category-first sort buried real bugs under unused-import
|
|
10
|
+
* warnings of the same scanner family. This scores likely runtime defects,
|
|
11
|
+
* secrets, and broken flows above lint and maintainability.
|
|
12
|
+
*/
|
|
13
|
+
const SEVERITY_SCORE = {
|
|
14
|
+
critical: 1000,
|
|
15
|
+
high: 700,
|
|
16
|
+
medium: 280,
|
|
17
|
+
low: 70,
|
|
18
|
+
info: 10
|
|
19
|
+
};
|
|
20
|
+
const CONFIDENCE_SCORE = {
|
|
21
|
+
high: 80,
|
|
22
|
+
medium: 30,
|
|
23
|
+
low: 0
|
|
24
|
+
};
|
|
25
|
+
const EVIDENCE_SCORE = {
|
|
26
|
+
verified: 60,
|
|
27
|
+
observed: 40,
|
|
28
|
+
heuristic: 10,
|
|
29
|
+
unproven: 0
|
|
30
|
+
};
|
|
31
|
+
const STYLE_LINT = /^(F401|F841|I00|I001|W29|E5\d|COM|Q0|T20|ISC|WPS|UP0|SIM\d)/i;
|
|
32
|
+
function isStyleOrHygieneFinding(finding) {
|
|
33
|
+
const code = finding.evidence?.toolRawId ?? finding.title;
|
|
34
|
+
if (STYLE_LINT.test(code)) {
|
|
35
|
+
return true;
|
|
36
|
+
}
|
|
37
|
+
return finding.category === "leftovers" || finding.category === "maintainability" || finding.category === "efficiency";
|
|
38
|
+
}
|
|
39
|
+
function isLikelyRealBug(finding) {
|
|
40
|
+
if (finding.source === "flow-doctor" && finding.evidenceGrade !== "heuristic") {
|
|
41
|
+
return true;
|
|
42
|
+
}
|
|
43
|
+
if (finding.source === "tsc" || finding.source === "pyright") {
|
|
44
|
+
return true;
|
|
45
|
+
}
|
|
46
|
+
if (finding.category === "tests" && (finding.severity === "high" || finding.severity === "critical")) {
|
|
47
|
+
return true;
|
|
48
|
+
}
|
|
49
|
+
const code = finding.evidence?.toolRawId ?? finding.title;
|
|
50
|
+
return /^(F8|F82|F821|E9|B0|S1|TS\d)/i.test(code);
|
|
51
|
+
}
|
|
52
|
+
function riskScore(finding) {
|
|
53
|
+
const evidence = finding.evidenceGrade ?? "observed";
|
|
54
|
+
let score = SEVERITY_SCORE[finding.severity] + CONFIDENCE_SCORE[finding.confidence] + EVIDENCE_SCORE[evidence];
|
|
55
|
+
if (finding.category === "security" || finding.source === "gitleaks" || finding.source === "osv-scanner") {
|
|
56
|
+
score += 520;
|
|
57
|
+
}
|
|
58
|
+
if (finding.source === "flow-doctor") {
|
|
59
|
+
score += evidence === "heuristic" ? 60 : 460;
|
|
60
|
+
}
|
|
61
|
+
if (isLikelyRealBug(finding)) {
|
|
62
|
+
score += 380;
|
|
63
|
+
}
|
|
64
|
+
if (finding.category === "correctness" && !isStyleOrHygieneFinding(finding)) {
|
|
65
|
+
score += 140;
|
|
66
|
+
}
|
|
67
|
+
if (finding.category === "dependencies" && (finding.severity === "high" || finding.severity === "critical")) {
|
|
68
|
+
score += 360;
|
|
69
|
+
}
|
|
70
|
+
if (finding.inChangedFile || finding.isNew) {
|
|
71
|
+
score += 70;
|
|
72
|
+
}
|
|
73
|
+
if (finding.fileRole === "source" || finding.fileRole === undefined) {
|
|
74
|
+
score += 35;
|
|
75
|
+
}
|
|
76
|
+
if (finding.fileRole === "test" || finding.fileRole === "fixture" || finding.fileRole === "generated") {
|
|
77
|
+
score -= 90;
|
|
78
|
+
}
|
|
79
|
+
if (isStyleOrHygieneFinding(finding)) {
|
|
80
|
+
score -= 220;
|
|
81
|
+
}
|
|
82
|
+
if (finding.category === "dead_code" && finding.confidence !== "high") {
|
|
83
|
+
score -= 80;
|
|
84
|
+
}
|
|
85
|
+
if (finding.corroboratedBy && finding.corroboratedBy.length > 0) {
|
|
86
|
+
score += 40 * finding.corroboratedBy.length;
|
|
87
|
+
}
|
|
88
|
+
return score;
|
|
89
|
+
}
|
|
90
|
+
function compareIds(left, right) {
|
|
91
|
+
const fileDelta = (left.file ?? "").localeCompare(right.file ?? "");
|
|
92
|
+
if (fileDelta !== 0) {
|
|
93
|
+
return fileDelta;
|
|
94
|
+
}
|
|
95
|
+
const lineDelta = (left.startLine ?? 0) - (right.startLine ?? 0);
|
|
96
|
+
if (lineDelta !== 0) {
|
|
97
|
+
return lineDelta;
|
|
98
|
+
}
|
|
99
|
+
const titleDelta = left.title.localeCompare(right.title);
|
|
100
|
+
if (titleDelta !== 0) {
|
|
101
|
+
return titleDelta;
|
|
102
|
+
}
|
|
103
|
+
return left.id.localeCompare(right.id);
|
|
104
|
+
}
|
|
105
|
+
function rankFindings(findings) {
|
|
106
|
+
return [...findings]
|
|
107
|
+
.map((finding) => ({ ...finding, priority: riskScore(finding) }))
|
|
108
|
+
.sort((left, right) => {
|
|
109
|
+
const scoreDelta = (right.priority ?? 0) - (left.priority ?? 0);
|
|
110
|
+
if (scoreDelta !== 0) {
|
|
111
|
+
return scoreDelta;
|
|
112
|
+
}
|
|
113
|
+
return compareIds(left, right);
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
exports.RANKING_CATEGORY_HINT = [
|
|
117
|
+
"security",
|
|
118
|
+
"correctness",
|
|
119
|
+
"tests",
|
|
120
|
+
"dependencies",
|
|
121
|
+
"privacy",
|
|
122
|
+
"dead_code",
|
|
123
|
+
"leftovers",
|
|
124
|
+
"refactor_readiness",
|
|
125
|
+
"maintainability",
|
|
126
|
+
"efficiency"
|
|
127
|
+
];
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { type FileRoleClassifier } from "./fileRole";
|
|
2
|
+
import type { VibeDoctorConfig } from "./config";
|
|
3
|
+
import { type ProjectContext } from "./projectDetector";
|
|
4
|
+
import type { ScanMode } from "./scanPlanner";
|
|
5
|
+
import { type ToolRuntime, type ToolRuntimeOptions } from "./toolRuntime";
|
|
6
|
+
export type FileIndex = {
|
|
7
|
+
files: readonly string[];
|
|
8
|
+
byExtension(extension: string): string[];
|
|
9
|
+
};
|
|
10
|
+
export type GitContext = {
|
|
11
|
+
hasGit: boolean;
|
|
12
|
+
changedFiles: readonly string[];
|
|
13
|
+
};
|
|
14
|
+
export type RepoContext = ProjectContext;
|
|
15
|
+
export type ScanContext = {
|
|
16
|
+
root: string;
|
|
17
|
+
mode: ScanMode;
|
|
18
|
+
config: VibeDoctorConfig;
|
|
19
|
+
repo: RepoContext;
|
|
20
|
+
files: FileIndex;
|
|
21
|
+
git: GitContext;
|
|
22
|
+
classifyFile: FileRoleClassifier;
|
|
23
|
+
toolRuntime: ToolRuntime;
|
|
24
|
+
};
|
|
25
|
+
export declare function buildFileIndex(files: string[]): FileIndex;
|
|
26
|
+
export declare function buildScanContext(root: string, config: VibeDoctorConfig, mode: ScanMode, runtimeOptions?: ToolRuntimeOptions): Promise<ScanContext>;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.buildFileIndex = buildFileIndex;
|
|
4
|
+
exports.buildScanContext = buildScanContext;
|
|
5
|
+
const fileRole_1 = require("./fileRole");
|
|
6
|
+
const projectDetector_1 = require("./projectDetector");
|
|
7
|
+
const toolRuntime_1 = require("./toolRuntime");
|
|
8
|
+
function buildFileIndex(files) {
|
|
9
|
+
const byExt = new Map();
|
|
10
|
+
for (const file of files) {
|
|
11
|
+
const dot = file.lastIndexOf(".");
|
|
12
|
+
const ext = dot >= 0 ? file.slice(dot).toLowerCase() : "";
|
|
13
|
+
const list = byExt.get(ext) ?? [];
|
|
14
|
+
list.push(file);
|
|
15
|
+
byExt.set(ext, list);
|
|
16
|
+
}
|
|
17
|
+
return {
|
|
18
|
+
files,
|
|
19
|
+
byExtension(extension) {
|
|
20
|
+
const key = extension.startsWith(".") ? extension.toLowerCase() : `.${extension.toLowerCase()}`;
|
|
21
|
+
return byExt.get(key) ?? [];
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
async function buildScanContext(root, config, mode, runtimeOptions) {
|
|
26
|
+
const repo = await (0, projectDetector_1.detectProject)(root, config.paths.exclude);
|
|
27
|
+
return {
|
|
28
|
+
root,
|
|
29
|
+
mode,
|
|
30
|
+
config,
|
|
31
|
+
repo,
|
|
32
|
+
files: buildFileIndex(repo.projectFiles),
|
|
33
|
+
git: { hasGit: repo.hasGit, changedFiles: repo.changedFiles },
|
|
34
|
+
classifyFile: (0, fileRole_1.createFileRoleClassifier)(config.relevance.fileRoles),
|
|
35
|
+
toolRuntime: (0, toolRuntime_1.createToolRuntime)({
|
|
36
|
+
projectRoot: root,
|
|
37
|
+
enabled: config.runtime.managedTools.enabled,
|
|
38
|
+
preferProjectLocal: config.runtime.managedTools.preferProjectLocal,
|
|
39
|
+
allowNetwork: config.runtime.managedTools.allowNetwork,
|
|
40
|
+
cacheDir: config.runtime.managedTools.cacheDir,
|
|
41
|
+
...runtimeOptions
|
|
42
|
+
})
|
|
43
|
+
};
|
|
44
|
+
}
|
|
@@ -1,11 +1,24 @@
|
|
|
1
1
|
import type { ToolAdapter } from "../adapters/shared";
|
|
2
|
+
import type { CapabilityState } from "./capability";
|
|
2
3
|
import type { VibeDoctorConfig } from "./config";
|
|
3
4
|
import type { ProjectContext } from "./projectDetector";
|
|
4
5
|
export type ScanMode = "default" | "changed" | "quick" | "full";
|
|
6
|
+
/** A tool that will not run, and the reason, so the report can say so explicitly. */
|
|
7
|
+
export type ExcludedTool = {
|
|
8
|
+
id: string;
|
|
9
|
+
state: Extract<CapabilityState, "disabled" | "not_applicable" | "not_selected" | "deferred">;
|
|
10
|
+
reason: string;
|
|
11
|
+
};
|
|
5
12
|
export type ScanPlan = {
|
|
6
13
|
mode: ScanMode;
|
|
7
14
|
adapterIds: string[];
|
|
15
|
+
/**
|
|
16
|
+
* Tools deliberately left out. Previously these vanished from the plan, which
|
|
17
|
+
* meant a check that never ran was indistinguishable from one that passed.
|
|
18
|
+
*/
|
|
19
|
+
excluded: ExcludedTool[];
|
|
8
20
|
changedOnly: boolean;
|
|
9
21
|
outputFull: boolean;
|
|
10
22
|
};
|
|
23
|
+
export declare const QUICK_ADAPTER_IDS: Set<string>;
|
|
11
24
|
export declare function createScanPlan(project: ProjectContext, config: VibeDoctorConfig, adapters: ToolAdapter[], mode: ScanMode): Promise<ScanPlan>;
|