@neuralaxis/vibedoctor 0.1.1 → 0.1.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 +203 -290
- package/dist/adapters/customDeadChain.d.ts +2 -1
- package/dist/adapters/customDeadChain.js +100 -8
- package/dist/adapters/customLeftovers.js +33 -10
- package/dist/adapters/index.d.ts +3 -0
- package/dist/adapters/index.js +7 -1
- package/dist/adapters/jscpd.d.ts +1 -0
- package/dist/adapters/jscpd.js +10 -1
- package/dist/adapters/presidio.d.ts +2 -0
- package/dist/adapters/presidio.js +158 -0
- package/dist/adapters/privacyDetector.d.ts +10 -0
- package/dist/adapters/privacyDetector.js +600 -0
- package/dist/adapters/telemetryDetector.d.ts +2 -0
- package/dist/adapters/telemetryDetector.js +118 -0
- package/dist/agentPack/generateAgentPack.d.ts +7 -0
- package/dist/agentPack/generateAgentPack.js +89 -1
- package/dist/agentPack/templates/index.js +14 -11
- package/dist/agentPack/templates/skills.js +47 -0
- package/dist/cli/commands/agent.d.ts +5 -0
- package/dist/cli/commands/agent.js +10 -0
- package/dist/cli/commands/init.js +38 -13
- package/dist/cli/commands/privacyReview.d.ts +9 -0
- package/dist/cli/commands/privacyReview.js +304 -0
- package/dist/cli/commands/scan.js +27 -1
- package/dist/cli/commands/setup.js +13 -0
- package/dist/cli/index.js +24 -0
- package/dist/core/config.d.ts +23 -0
- package/dist/core/config.js +114 -5
- package/dist/core/engine.d.ts +3 -0
- package/dist/core/engine.js +31 -9
- package/dist/core/finding.d.ts +16 -2
- package/dist/core/finding.js +5 -0
- package/dist/core/paths.js +5 -0
- package/dist/core/privacyReview.d.ts +51 -0
- package/dist/core/privacyReview.js +94 -0
- package/dist/core/projectDetector.js +6 -1
- package/dist/core/scanPlanner.js +4 -0
- package/dist/core/scoring.js +6 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +5 -0
- package/dist/mcp/tools/shared.d.ts +1 -1
- package/dist/reporters/html.js +8 -6
- package/dist/reporters/json.js +3 -5
- package/dist/reporters/markdown.js +7 -0
- package/dist/reporters/sarif.js +6 -0
- package/dist/reporters/terminal.js +1 -5
- package/dist/rules/severityMap.d.ts +1 -0
- package/dist/rules/severityMap.js +1 -0
- package/package.json +1 -1
|
@@ -9,6 +9,7 @@ const paths_1 = require("../core/paths");
|
|
|
9
9
|
const SOURCE_FILE_PATTERN = /\.(ts|tsx|js|jsx|py)$/;
|
|
10
10
|
const JS_EXTENSIONS = [".ts", ".tsx", ".js", ".jsx"];
|
|
11
11
|
const PY_EXTENSIONS = [".py"];
|
|
12
|
+
const JS_CONFIG_FILES = ["tsconfig.json", "jsconfig.json"];
|
|
12
13
|
function isTestFile(file) {
|
|
13
14
|
return /(^|\/)tests?\//.test(file) || /\.test\./.test(file) || /\.spec\./.test(file);
|
|
14
15
|
}
|
|
@@ -32,7 +33,12 @@ function parseImports(file, content) {
|
|
|
32
33
|
}
|
|
33
34
|
return Array.from(imports);
|
|
34
35
|
}
|
|
35
|
-
for (const match of content.matchAll(/(?:import|export)\s+(?:[^"'`]+?\s+from\s+)?["'`]([^"'`]+)["'`]/g)) {
|
|
36
|
+
for (const match of content.matchAll(/(?:import|export)\s+(?:type\s+)?(?:[^"'`]+?\s+from\s+)?["'`]([^"'`]+)["'`]/g)) {
|
|
37
|
+
if (match[1]) {
|
|
38
|
+
imports.add(match[1]);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
for (const match of content.matchAll(/\bimport\s*\(\s*["'`]([^"'`]+)["'`]\s*\)/g)) {
|
|
36
42
|
if (match[1]) {
|
|
37
43
|
imports.add(match[1]);
|
|
38
44
|
}
|
|
@@ -44,9 +50,39 @@ function parseImports(file, content) {
|
|
|
44
50
|
}
|
|
45
51
|
return Array.from(imports);
|
|
46
52
|
}
|
|
47
|
-
function
|
|
48
|
-
|
|
49
|
-
|
|
53
|
+
function stripJsonComments(content) {
|
|
54
|
+
return content
|
|
55
|
+
.replace(/\/\*[\s\S]*?\*\//g, "")
|
|
56
|
+
.replace(/(^|[^:])\/\/.*$/gm, "$1")
|
|
57
|
+
.replace(/,\s*([}\]])/g, "$1");
|
|
58
|
+
}
|
|
59
|
+
async function loadJsResolverConfig(project) {
|
|
60
|
+
const configFile = JS_CONFIG_FILES.find((file) => project.projectFiles.includes(file));
|
|
61
|
+
if (!configFile) {
|
|
62
|
+
return { configDir: "", paths: [] };
|
|
63
|
+
}
|
|
64
|
+
const content = await (0, paths_1.readTextIfExists)(node_path_1.default.join(project.root, configFile));
|
|
65
|
+
if (!content) {
|
|
66
|
+
return { configDir: "", paths: [] };
|
|
67
|
+
}
|
|
68
|
+
try {
|
|
69
|
+
const parsed = JSON.parse(stripJsonComments(content));
|
|
70
|
+
const configDir = node_path_1.default.posix.dirname(configFile) === "." ? "" : node_path_1.default.posix.dirname(configFile);
|
|
71
|
+
const baseUrl = parsed.compilerOptions?.baseUrl
|
|
72
|
+
? node_path_1.default.posix.normalize(node_path_1.default.posix.join(configDir, parsed.compilerOptions.baseUrl))
|
|
73
|
+
: undefined;
|
|
74
|
+
const paths = Object.entries(parsed.compilerOptions?.paths ?? {}).map(([pattern, targets]) => ({
|
|
75
|
+
pattern,
|
|
76
|
+
targets: Array.isArray(targets) ? targets : []
|
|
77
|
+
}));
|
|
78
|
+
return { configDir, baseUrl, paths };
|
|
79
|
+
}
|
|
80
|
+
catch {
|
|
81
|
+
return { configDir: "", paths: [] };
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
function resolveCandidate(rawSpecifierPath, projectFiles, extensions) {
|
|
85
|
+
const raw = node_path_1.default.posix.normalize(rawSpecifierPath).replace(/^\.\//, "");
|
|
50
86
|
const candidates = [
|
|
51
87
|
raw,
|
|
52
88
|
...extensions.map((extension) => `${raw}${extension}`),
|
|
@@ -54,6 +90,50 @@ function resolveRelativeImport(fromFile, specifier, projectFiles, extensions) {
|
|
|
54
90
|
];
|
|
55
91
|
return candidates.find((candidate) => projectFiles.has(candidate));
|
|
56
92
|
}
|
|
93
|
+
function resolveRelativeImport(fromFile, specifier, projectFiles, extensions) {
|
|
94
|
+
const baseDir = node_path_1.default.posix.dirname(fromFile);
|
|
95
|
+
const raw = node_path_1.default.posix.normalize(node_path_1.default.posix.join(baseDir, specifier));
|
|
96
|
+
return resolveCandidate(raw, projectFiles, extensions);
|
|
97
|
+
}
|
|
98
|
+
function matchPathPattern(specifier, pattern) {
|
|
99
|
+
const starIndex = pattern.indexOf("*");
|
|
100
|
+
if (starIndex === -1) {
|
|
101
|
+
return specifier === pattern ? "" : undefined;
|
|
102
|
+
}
|
|
103
|
+
const prefix = pattern.slice(0, starIndex);
|
|
104
|
+
const suffix = pattern.slice(starIndex + 1);
|
|
105
|
+
if (!specifier.startsWith(prefix) || !specifier.endsWith(suffix)) {
|
|
106
|
+
return undefined;
|
|
107
|
+
}
|
|
108
|
+
return specifier.slice(prefix.length, specifier.length - suffix.length);
|
|
109
|
+
}
|
|
110
|
+
function resolveTsConfigImport(specifier, projectFiles, extensions, resolverConfig) {
|
|
111
|
+
for (const mapping of resolverConfig.paths) {
|
|
112
|
+
const wildcard = matchPathPattern(specifier, mapping.pattern);
|
|
113
|
+
if (wildcard === undefined) {
|
|
114
|
+
continue;
|
|
115
|
+
}
|
|
116
|
+
for (const target of mapping.targets) {
|
|
117
|
+
const replaced = target.replace("*", wildcard);
|
|
118
|
+
const base = resolverConfig.baseUrl ?? resolverConfig.configDir;
|
|
119
|
+
const resolved = resolveCandidate(node_path_1.default.posix.join(base, replaced), projectFiles, extensions);
|
|
120
|
+
if (resolved) {
|
|
121
|
+
return resolved;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
if (resolverConfig.baseUrl) {
|
|
126
|
+
const resolved = resolveCandidate(node_path_1.default.posix.join(resolverConfig.baseUrl, specifier), projectFiles, extensions);
|
|
127
|
+
if (resolved) {
|
|
128
|
+
return resolved;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
if (specifier.startsWith("@/")) {
|
|
132
|
+
return (resolveCandidate(node_path_1.default.posix.join("src", specifier.slice(2)), projectFiles, extensions) ??
|
|
133
|
+
resolveCandidate(specifier.slice(2), projectFiles, extensions));
|
|
134
|
+
}
|
|
135
|
+
return undefined;
|
|
136
|
+
}
|
|
57
137
|
function resolvePythonImport(fromFile, specifier, projectFiles) {
|
|
58
138
|
if (specifier.startsWith(".")) {
|
|
59
139
|
const depth = specifier.match(/^\.+/)?.[0].length ?? 1;
|
|
@@ -73,10 +153,11 @@ function resolvePythonImport(fromFile, specifier, projectFiles) {
|
|
|
73
153
|
const dottedPath = specifier.replaceAll(".", "/");
|
|
74
154
|
return [`${dottedPath}.py`, `${dottedPath}/__init__.py`].find((candidate) => projectFiles.has(candidate));
|
|
75
155
|
}
|
|
76
|
-
async function buildGraph(project) {
|
|
77
|
-
const sourceFiles = (0, paths_1.filterPaths)(project.projectFiles,
|
|
156
|
+
async function buildGraph(project, includePatterns, excludePatterns) {
|
|
157
|
+
const sourceFiles = (0, paths_1.filterPaths)(project.projectFiles, includePatterns, excludePatterns).filter((file) => SOURCE_FILE_PATTERN.test(file));
|
|
78
158
|
const projectFileSet = new Set(sourceFiles);
|
|
79
159
|
const graph = new Map();
|
|
160
|
+
const jsResolverConfig = await loadJsResolverConfig(project);
|
|
80
161
|
for (const file of sourceFiles) {
|
|
81
162
|
graph.set(file, {
|
|
82
163
|
id: file,
|
|
@@ -104,6 +185,9 @@ async function buildGraph(project) {
|
|
|
104
185
|
else if (specifier.startsWith(".")) {
|
|
105
186
|
resolved = resolveRelativeImport(file, specifier, projectFileSet, extensions);
|
|
106
187
|
}
|
|
188
|
+
else {
|
|
189
|
+
resolved = resolveTsConfigImport(specifier, projectFileSet, extensions, jsResolverConfig);
|
|
190
|
+
}
|
|
107
191
|
if (!resolved) {
|
|
108
192
|
continue;
|
|
109
193
|
}
|
|
@@ -118,12 +202,20 @@ async function buildGraph(project) {
|
|
|
118
202
|
}
|
|
119
203
|
return graph;
|
|
120
204
|
}
|
|
205
|
+
function isFrameworkEntrypoint(file) {
|
|
206
|
+
return (/^(?:src\/)?app\/(?:.+\/)?(?:page|layout|route|loading|error|global-error|not-found|default|template)\.(ts|tsx|js|jsx)$/.test(file) ||
|
|
207
|
+
/^(?:src\/)?pages\/(?:.+)\.(ts|tsx|js|jsx)$/.test(file) ||
|
|
208
|
+
/^(?:src\/)?(?:middleware|instrumentation)\.(ts|js)$/.test(file));
|
|
209
|
+
}
|
|
121
210
|
function collectEntrypoints(project, graph) {
|
|
122
211
|
const explicit = new Set(project.entryFiles.filter((file) => graph.has(file) && !isTestFile(file)));
|
|
123
212
|
for (const file of graph.keys()) {
|
|
124
213
|
if (/^src\/(index|main|app|server)\.(ts|tsx|js|jsx|py)$/.test(file)) {
|
|
125
214
|
explicit.add(file);
|
|
126
215
|
}
|
|
216
|
+
if (isFrameworkEntrypoint(file)) {
|
|
217
|
+
explicit.add(file);
|
|
218
|
+
}
|
|
127
219
|
}
|
|
128
220
|
return Array.from(explicit);
|
|
129
221
|
}
|
|
@@ -186,8 +278,8 @@ function hasDynamicPattern(file) {
|
|
|
186
278
|
function isPackageInitializer(file) {
|
|
187
279
|
return file.endsWith("/__init__.py") || file === "__init__.py";
|
|
188
280
|
}
|
|
189
|
-
async function detectDeadChains(project, findings) {
|
|
190
|
-
const graph = await buildGraph(project);
|
|
281
|
+
async function detectDeadChains(project, findings, config) {
|
|
282
|
+
const graph = await buildGraph(project, config?.paths.include ?? ["**/*"], config?.paths.exclude ?? []);
|
|
191
283
|
const entrypoints = collectEntrypoints(project, graph);
|
|
192
284
|
const reachable = markReachable(graph, entrypoints);
|
|
193
285
|
const deadCodeFiles = new Set(findings.filter((finding) => finding.category === "dead_code" && finding.file).map((finding) => finding.file));
|
|
@@ -15,7 +15,14 @@ const COMMENT_PREFIX = {
|
|
|
15
15
|
".py": "#"
|
|
16
16
|
};
|
|
17
17
|
function looksLikeCommentedCode(text) {
|
|
18
|
-
|
|
18
|
+
const trimmed = text.trim();
|
|
19
|
+
return (/^(?:export\s+)?(?:const|let|var)\s+[A-Za-z_$][\w$]*\s*=/.test(trimmed) ||
|
|
20
|
+
/^(?:export\s+)?(?:async\s+)?function\s+[A-Za-z_$][\w$]*\s*\(/.test(trimmed) ||
|
|
21
|
+
/^class\s+[A-Za-z_$][\w$]*/.test(trimmed) ||
|
|
22
|
+
/^def\s+[A-Za-z_][\w]*\s*\(/.test(trimmed) ||
|
|
23
|
+
/^return\b.+/.test(trimmed) ||
|
|
24
|
+
/^import\s+.+(?:from\s+)?["'`][^"'`]+["'`]/.test(trimmed) ||
|
|
25
|
+
/^from\s+[\w.]+\s+import\s+/.test(trimmed));
|
|
19
26
|
}
|
|
20
27
|
function shouldIgnoreComment(commentText) {
|
|
21
28
|
return /^changelog\b|^release notes?\b|^copyright\b|^migration\b|^history\b|^example\b/i.test(commentText.trim());
|
|
@@ -43,6 +50,12 @@ function shouldIgnoreLine(lineText) {
|
|
|
43
50
|
}
|
|
44
51
|
return false;
|
|
45
52
|
}
|
|
53
|
+
function isActionableCommentMatch(group, pattern, lowerComment) {
|
|
54
|
+
if (group === "fallback" && pattern === "fallback") {
|
|
55
|
+
return /\b(todo|fixme|remove later|temporary|legacy|deprecated|old implementation|previous implementation)\b/.test(lowerComment);
|
|
56
|
+
}
|
|
57
|
+
return true;
|
|
58
|
+
}
|
|
46
59
|
function findCommentMatches(file, content, scanComments, scanCommentedCode) {
|
|
47
60
|
const extension = node_path_1.default.extname(file);
|
|
48
61
|
const commentPrefix = COMMENT_PREFIX[extension];
|
|
@@ -57,6 +70,9 @@ function findCommentMatches(file, content, scanComments, scanCommentedCode) {
|
|
|
57
70
|
if (!isComment) {
|
|
58
71
|
continue;
|
|
59
72
|
}
|
|
73
|
+
if (trimmed.startsWith("/**") || trimmed.startsWith("*")) {
|
|
74
|
+
continue;
|
|
75
|
+
}
|
|
60
76
|
const commentText = trimmed.replace(/^\/\//, "").replace(/^#/, "").replace(/^\/\*/, "").replace(/^\*/, "").trim();
|
|
61
77
|
if (shouldIgnoreComment(commentText) || shouldIgnoreLine(commentText)) {
|
|
62
78
|
continue;
|
|
@@ -65,7 +81,7 @@ function findCommentMatches(file, content, scanComments, scanCommentedCode) {
|
|
|
65
81
|
if (scanComments) {
|
|
66
82
|
for (const [group, patterns] of Object.entries(leftoverPatterns_1.LEFTOVER_PATTERNS)) {
|
|
67
83
|
for (const pattern of patterns) {
|
|
68
|
-
if (lower.includes(pattern)) {
|
|
84
|
+
if (lower.includes(pattern) && isActionableCommentMatch(group, pattern, lower)) {
|
|
69
85
|
matches.push({
|
|
70
86
|
group,
|
|
71
87
|
pattern,
|
|
@@ -97,15 +113,19 @@ function findNameMatches(file, content) {
|
|
|
97
113
|
const lines = content.split(/\r?\n/);
|
|
98
114
|
const matches = [];
|
|
99
115
|
for (const [index, line] of lines.entries()) {
|
|
100
|
-
const
|
|
101
|
-
|
|
116
|
+
const declaration = line.match(/^\s*(?:export\s+)?(?:async\s+)?(?:function|class|const|let|var|def)\s+([A-Za-z_$][\w$]*)/);
|
|
117
|
+
const name = declaration?.[1];
|
|
118
|
+
if (!name) {
|
|
102
119
|
continue;
|
|
103
120
|
}
|
|
104
121
|
if (shouldIgnoreLine(line)) {
|
|
105
122
|
continue;
|
|
106
123
|
}
|
|
107
124
|
for (const pattern of leftoverPatterns_1.LEFTOVER_NAME_PATTERNS) {
|
|
108
|
-
if (
|
|
125
|
+
if (pattern !== "deprecated") {
|
|
126
|
+
continue;
|
|
127
|
+
}
|
|
128
|
+
if (new RegExp(`^(?:${pattern})[A-Z_]`, "i").test(name)) {
|
|
109
129
|
matches.push({
|
|
110
130
|
group: "name-signal",
|
|
111
131
|
pattern,
|
|
@@ -128,14 +148,14 @@ function findFallbackMatches(file, content) {
|
|
|
128
148
|
if (shouldIgnoreLine(line)) {
|
|
129
149
|
continue;
|
|
130
150
|
}
|
|
131
|
-
const
|
|
151
|
+
const hasLegacySignal = /\b(legacy|compat|oldflow|deprecated|previous implementation|old implementation)\b/.test(lower);
|
|
132
152
|
// Further tightened for real code (post-ouroboros scan):
|
|
133
153
|
// - Removed "return" (noisy on normal "return foo(fallback)" utils).
|
|
134
154
|
// - Stricter hasBranchControl: only true branch keywords (if/else etc) or actual ternary ( ? ... : ).
|
|
135
155
|
// This avoids matching ":" in TS param types like "fallback: AgentTarget[]" on declaration lines.
|
|
136
156
|
const hasBranchControl = /\b(if|else|catch|except|try|switch)\b/.test(lower) || (/\?/.test(lower) && /:/.test(lower));
|
|
137
|
-
if (
|
|
138
|
-
const envGuardMatch = line.match(/\b([A-
|
|
157
|
+
if (hasLegacySignal && hasBranchControl) {
|
|
158
|
+
const envGuardMatch = line.match(/\b(?=[A-Z0-9_]*(?:LEGACY|OLD|FALLBACK|COMPAT|V1))([A-Z][A-Z0-9_]*)\b/);
|
|
139
159
|
matches.push({
|
|
140
160
|
group: "fallback-branch",
|
|
141
161
|
pattern: lower.includes("legacy") ? "legacy branch" : "fallback branch",
|
|
@@ -160,12 +180,15 @@ function findFlagMatches(file, content) {
|
|
|
160
180
|
if (shouldIgnoreLine(line)) {
|
|
161
181
|
continue;
|
|
162
182
|
}
|
|
163
|
-
const envMatch = trimmed.match(/\b([A-
|
|
164
|
-
const featureFlagMatch = trimmed.match(/\b(?:legacy|old|
|
|
183
|
+
const envMatch = trimmed.match(/\b(?=[A-Z0-9_]*(?:LEGACY|OLD|FALLBACK|COMPAT|DEPRECATED|PREVIOUS|V1))([A-Z][A-Z0-9_]*)\b/);
|
|
184
|
+
const featureFlagMatch = trimmed.match(/\b(?:legacy|old|compat|deprecated|previous)[A-Z][A-Za-z0-9]*(?:Flag|Enabled|Toggle|Mode)\b/);
|
|
165
185
|
const signal = envMatch?.[1] ?? featureFlagMatch?.[0];
|
|
166
186
|
if (!signal) {
|
|
167
187
|
continue;
|
|
168
188
|
}
|
|
189
|
+
if (!/(?:process\.env|env|config|flag|enabled|toggle|mode|if\s*\(|const|let|var|=)/i.test(trimmed)) {
|
|
190
|
+
continue;
|
|
191
|
+
}
|
|
169
192
|
matches.push({
|
|
170
193
|
group: "flag-signal",
|
|
171
194
|
pattern: signal,
|
package/dist/adapters/index.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ export { jscpdAdapter } from "./jscpd";
|
|
|
7
7
|
export { knipAdapter } from "./knip";
|
|
8
8
|
export { lizardAdapter } from "./lizard";
|
|
9
9
|
export { osvScannerAdapter } from "./osvScanner";
|
|
10
|
+
export { presidioAdapter } from "./presidio";
|
|
10
11
|
export { pyrightAdapter } from "./pyright";
|
|
11
12
|
export { radonAdapter } from "./radon";
|
|
12
13
|
export { ruffAdapter } from "./ruff";
|
|
@@ -14,3 +15,5 @@ export { semgrepAdapter } from "./semgrep";
|
|
|
14
15
|
export { tscAdapter } from "./tsc";
|
|
15
16
|
export { vitestAdapter } from "./vitest";
|
|
16
17
|
export { vultureAdapter } from "./vulture";
|
|
18
|
+
export { privacyDetectorAdapter } from "./privacyDetector";
|
|
19
|
+
export { telemetryDetectorAdapter } from "./telemetryDetector";
|
package/dist/adapters/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.vultureAdapter = exports.vitestAdapter = exports.tscAdapter = exports.semgrepAdapter = exports.ruffAdapter = exports.radonAdapter = exports.pyrightAdapter = exports.osvScannerAdapter = exports.lizardAdapter = exports.knipAdapter = exports.jscpdAdapter = exports.jestAdapter = exports.gitleaksAdapter = exports.deptryAdapter = exports.coveragePyAdapter = exports.biomeAdapter = void 0;
|
|
3
|
+
exports.telemetryDetectorAdapter = exports.privacyDetectorAdapter = exports.vultureAdapter = exports.vitestAdapter = exports.tscAdapter = exports.semgrepAdapter = exports.ruffAdapter = exports.radonAdapter = exports.pyrightAdapter = exports.presidioAdapter = exports.osvScannerAdapter = exports.lizardAdapter = exports.knipAdapter = exports.jscpdAdapter = exports.jestAdapter = exports.gitleaksAdapter = exports.deptryAdapter = exports.coveragePyAdapter = exports.biomeAdapter = void 0;
|
|
4
4
|
var biome_1 = require("./biome");
|
|
5
5
|
Object.defineProperty(exports, "biomeAdapter", { enumerable: true, get: function () { return biome_1.biomeAdapter; } });
|
|
6
6
|
var coveragePy_1 = require("./coveragePy");
|
|
@@ -19,6 +19,8 @@ var lizard_1 = require("./lizard");
|
|
|
19
19
|
Object.defineProperty(exports, "lizardAdapter", { enumerable: true, get: function () { return lizard_1.lizardAdapter; } });
|
|
20
20
|
var osvScanner_1 = require("./osvScanner");
|
|
21
21
|
Object.defineProperty(exports, "osvScannerAdapter", { enumerable: true, get: function () { return osvScanner_1.osvScannerAdapter; } });
|
|
22
|
+
var presidio_1 = require("./presidio");
|
|
23
|
+
Object.defineProperty(exports, "presidioAdapter", { enumerable: true, get: function () { return presidio_1.presidioAdapter; } });
|
|
22
24
|
var pyright_1 = require("./pyright");
|
|
23
25
|
Object.defineProperty(exports, "pyrightAdapter", { enumerable: true, get: function () { return pyright_1.pyrightAdapter; } });
|
|
24
26
|
var radon_1 = require("./radon");
|
|
@@ -33,3 +35,7 @@ var vitest_1 = require("./vitest");
|
|
|
33
35
|
Object.defineProperty(exports, "vitestAdapter", { enumerable: true, get: function () { return vitest_1.vitestAdapter; } });
|
|
34
36
|
var vulture_1 = require("./vulture");
|
|
35
37
|
Object.defineProperty(exports, "vultureAdapter", { enumerable: true, get: function () { return vulture_1.vultureAdapter; } });
|
|
38
|
+
var privacyDetector_1 = require("./privacyDetector");
|
|
39
|
+
Object.defineProperty(exports, "privacyDetectorAdapter", { enumerable: true, get: function () { return privacyDetector_1.privacyDetectorAdapter; } });
|
|
40
|
+
var telemetryDetector_1 = require("./telemetryDetector");
|
|
41
|
+
Object.defineProperty(exports, "telemetryDetectorAdapter", { enumerable: true, get: function () { return telemetryDetector_1.telemetryDetectorAdapter; } });
|
package/dist/adapters/jscpd.d.ts
CHANGED
package/dist/adapters/jscpd.js
CHANGED
|
@@ -4,11 +4,20 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.jscpdAdapter = void 0;
|
|
7
|
+
exports.buildJscpdArgs = buildJscpdArgs;
|
|
7
8
|
const node_fs_1 = require("node:fs");
|
|
8
9
|
const node_os_1 = __importDefault(require("node:os"));
|
|
9
10
|
const node_path_1 = __importDefault(require("node:path"));
|
|
10
11
|
const finding_1 = require("../core/finding");
|
|
11
12
|
const toolRunner_1 = require("../core/toolRunner");
|
|
13
|
+
function buildJscpdArgs(outputDir, excludePatterns) {
|
|
14
|
+
const args = [".", "--reporters", "json", "--output", outputDir, "--silent", "--min-lines", "30"];
|
|
15
|
+
const ignored = excludePatterns.map((pattern) => pattern.trim()).filter(Boolean);
|
|
16
|
+
if (ignored.length > 0) {
|
|
17
|
+
args.push("--ignore", ignored.join(","));
|
|
18
|
+
}
|
|
19
|
+
return args;
|
|
20
|
+
}
|
|
12
21
|
exports.jscpdAdapter = {
|
|
13
22
|
id: "jscpd",
|
|
14
23
|
category: "maintainability",
|
|
@@ -20,7 +29,7 @@ exports.jscpdAdapter = {
|
|
|
20
29
|
const reportPath = node_path_1.default.join(outputDir, "jscpd-report.json");
|
|
21
30
|
const status = await (0, toolRunner_1.runCommand)({
|
|
22
31
|
cmd: "jscpd",
|
|
23
|
-
args:
|
|
32
|
+
args: buildJscpdArgs(outputDir, ctx.config.paths.exclude),
|
|
24
33
|
cwd: ctx.root,
|
|
25
34
|
timeoutMs: 120_000
|
|
26
35
|
}, "Install jscpd with: npm install -D jscpd");
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.presidioAdapter = void 0;
|
|
4
|
+
const privacyDetector_1 = require("./privacyDetector");
|
|
5
|
+
const paths_1 = require("../core/paths");
|
|
6
|
+
const toolRunner_1 = require("../core/toolRunner");
|
|
7
|
+
const CONFIDENCE_RANK = {
|
|
8
|
+
low: 0,
|
|
9
|
+
medium: 1,
|
|
10
|
+
high: 2
|
|
11
|
+
};
|
|
12
|
+
const PRESIDIO_EXTENSIONS = /\.(ts|tsx|js|jsx|py|json|jsonl|ya?ml|toml|md|txt|log|csv|tsv|sql|graphql|gql)$/i;
|
|
13
|
+
const PRESIDIO_SCRIPT = String.raw `
|
|
14
|
+
import json
|
|
15
|
+
import os
|
|
16
|
+
import pathlib
|
|
17
|
+
import sys
|
|
18
|
+
|
|
19
|
+
try:
|
|
20
|
+
from presidio_analyzer import AnalyzerEngine
|
|
21
|
+
except Exception as exc:
|
|
22
|
+
sys.stderr.write(f"presidio_analyzer is not installed: {exc}\n")
|
|
23
|
+
sys.exit(2)
|
|
24
|
+
|
|
25
|
+
root = pathlib.Path(sys.argv[1])
|
|
26
|
+
files = json.loads(os.environ.get("VIBEDOCTOR_PRESIDIO_FILES", "[]"))
|
|
27
|
+
max_file_bytes = int(os.environ.get("VIBEDOCTOR_PRESIDIO_MAX_FILE_BYTES", "1048576"))
|
|
28
|
+
analyzer = AnalyzerEngine()
|
|
29
|
+
out = []
|
|
30
|
+
|
|
31
|
+
for rel in files:
|
|
32
|
+
candidate = root / rel
|
|
33
|
+
try:
|
|
34
|
+
if candidate.stat().st_size > max_file_bytes:
|
|
35
|
+
continue
|
|
36
|
+
text = candidate.read_text(encoding="utf-8", errors="ignore")
|
|
37
|
+
except Exception:
|
|
38
|
+
continue
|
|
39
|
+
|
|
40
|
+
for item in analyzer.analyze(text=text, language="en"):
|
|
41
|
+
value = text[item.start:item.end]
|
|
42
|
+
out.append({
|
|
43
|
+
"file": rel,
|
|
44
|
+
"line": text.count("\n", 0, item.start) + 1,
|
|
45
|
+
"entityType": item.entity_type.lower(),
|
|
46
|
+
"score": float(item.score),
|
|
47
|
+
"value": value,
|
|
48
|
+
})
|
|
49
|
+
|
|
50
|
+
print(json.dumps(out))
|
|
51
|
+
`;
|
|
52
|
+
function passesConfidenceThreshold(score, minimum) {
|
|
53
|
+
return CONFIDENCE_RANK[(0, privacyDetector_1.confidenceFromScore)(score)] >= CONFIDENCE_RANK[minimum];
|
|
54
|
+
}
|
|
55
|
+
function normalizeStatus(status) {
|
|
56
|
+
if (status.status === "error" && /presidio_analyzer is not installed|No module named ['"]presidio_analyzer/i.test(status.stderr)) {
|
|
57
|
+
return {
|
|
58
|
+
...status,
|
|
59
|
+
status: "skipped",
|
|
60
|
+
installHint: "Install Presidio in the project environment: python -m pip install presidio-analyzer"
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
return status;
|
|
64
|
+
}
|
|
65
|
+
function sensitivityForPresidio(entityType) {
|
|
66
|
+
if (/credit_card|iban|crypto|passport|aadhaar|pan|bank/.test(entityType)) {
|
|
67
|
+
return "regulated_identifier";
|
|
68
|
+
}
|
|
69
|
+
if (/medical|patient|health|location/.test(entityType)) {
|
|
70
|
+
return "high";
|
|
71
|
+
}
|
|
72
|
+
if (/phone|ip|date_time|id/.test(entityType)) {
|
|
73
|
+
return "moderate";
|
|
74
|
+
}
|
|
75
|
+
return "low";
|
|
76
|
+
}
|
|
77
|
+
function toFinding(item, ctx) {
|
|
78
|
+
const entityType = item.entityType.toLowerCase();
|
|
79
|
+
const sensitivity = sensitivityForPresidio(entityType);
|
|
80
|
+
const confidence = (0, privacyDetector_1.confidenceFromScore)(item.score);
|
|
81
|
+
const maskedValue = (0, privacyDetector_1.maskPiiValue)(item.value, entityType, ctx.config.checks.privacy.maskExamples);
|
|
82
|
+
return {
|
|
83
|
+
id: `privacy-presidio:${item.file}:${item.line ?? 0}:${entityType}:${maskedValue}`,
|
|
84
|
+
source: "presidio",
|
|
85
|
+
category: "privacy",
|
|
86
|
+
severity: sensitivity === "low" ? "low" : "medium",
|
|
87
|
+
confidence,
|
|
88
|
+
title: `PII detected: ${entityType}`,
|
|
89
|
+
message: `${entityType} detected by Presidio with ${confidence} confidence.`,
|
|
90
|
+
file: item.file,
|
|
91
|
+
startLine: item.line,
|
|
92
|
+
isNew: true,
|
|
93
|
+
isAutofixable: false,
|
|
94
|
+
safeToAutofix: false,
|
|
95
|
+
agentInstruction: "Review this Presidio privacy finding before treating it as confirmed PII.",
|
|
96
|
+
tags: ["privacy", entityType, sensitivity],
|
|
97
|
+
evidence: {
|
|
98
|
+
detector: "presidio",
|
|
99
|
+
entityType,
|
|
100
|
+
sensitivity,
|
|
101
|
+
maskedValue,
|
|
102
|
+
fieldPath: item.line ? `${item.file}:${item.line}` : item.file,
|
|
103
|
+
matchedPattern: entityType,
|
|
104
|
+
detectionPath: "presidio",
|
|
105
|
+
confidenceScore: Number(item.score.toFixed(2)),
|
|
106
|
+
coverageConfidence: 0.75,
|
|
107
|
+
reviewState: item.score >= 0.85 ? "confirmed" : "needs_human_review",
|
|
108
|
+
reasons: ["Presidio analyzer returned this entity span"]
|
|
109
|
+
},
|
|
110
|
+
scoreImpact: 0
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
exports.presidioAdapter = {
|
|
114
|
+
id: "presidio",
|
|
115
|
+
category: "privacy",
|
|
116
|
+
async detect(_project, config) {
|
|
117
|
+
return config.checks.privacy.enabled && config.checks.privacy.presidio.enabled;
|
|
118
|
+
},
|
|
119
|
+
async runStandalone(ctx) {
|
|
120
|
+
const files = (0, paths_1.filterPaths)(ctx.project.projectFiles, ctx.config.paths.include, ctx.config.paths.exclude)
|
|
121
|
+
.filter((file) => PRESIDIO_EXTENSIONS.test(file))
|
|
122
|
+
.slice(0, 500);
|
|
123
|
+
const status = normalizeStatus(await (0, toolRunner_1.runCommand)({
|
|
124
|
+
cmd: "python",
|
|
125
|
+
args: ["-c", PRESIDIO_SCRIPT, ctx.root],
|
|
126
|
+
cwd: ctx.root,
|
|
127
|
+
timeoutMs: 120_000,
|
|
128
|
+
env: {
|
|
129
|
+
VIBEDOCTOR_PRESIDIO_FILES: JSON.stringify(files),
|
|
130
|
+
VIBEDOCTOR_PRESIDIO_MAX_FILE_BYTES: String(ctx.config.checks.privacy.maxFileBytes)
|
|
131
|
+
}
|
|
132
|
+
}, "Install Presidio in the project environment: python -m pip install presidio-analyzer"));
|
|
133
|
+
if (status.status !== "ok") {
|
|
134
|
+
return { findings: [], status };
|
|
135
|
+
}
|
|
136
|
+
let raw = [];
|
|
137
|
+
try {
|
|
138
|
+
raw = JSON.parse(status.stdout.trim() || "[]");
|
|
139
|
+
}
|
|
140
|
+
catch {
|
|
141
|
+
return {
|
|
142
|
+
findings: [],
|
|
143
|
+
status: {
|
|
144
|
+
...status,
|
|
145
|
+
status: "error",
|
|
146
|
+
stderr: "Presidio output was not valid JSON."
|
|
147
|
+
}
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
return {
|
|
151
|
+
findings: raw
|
|
152
|
+
.filter((item) => passesConfidenceThreshold(item.score, ctx.config.checks.privacy.minConfidenceToReport))
|
|
153
|
+
.map((item) => toFinding(item, ctx)),
|
|
154
|
+
status
|
|
155
|
+
};
|
|
156
|
+
},
|
|
157
|
+
installHint: "Optional privacy scanner. Enable checks.privacy.presidio.enabled and install presidio-analyzer."
|
|
158
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type Confidence, type Finding } from "../core/finding";
|
|
2
|
+
import type { ToolAdapter, ToolAdapterContext } from "./shared";
|
|
3
|
+
export type PrivacySensitivity = "low" | "moderate" | "high" | "regulated_identifier" | "combination_risk";
|
|
4
|
+
export declare function confidenceFromScore(score: number): Confidence;
|
|
5
|
+
export declare function passesLuhn(value: string): boolean;
|
|
6
|
+
export declare function isValidAadhaar(value: string): boolean;
|
|
7
|
+
export declare function maskPiiValue(value: string, entityType: string, maskExamples?: boolean): string;
|
|
8
|
+
export declare function detectPiiFindings(ctx: ToolAdapterContext): Promise<Finding[]>;
|
|
9
|
+
export declare const privacyDetectorAdapter: ToolAdapter;
|
|
10
|
+
export declare function normalizeExternalFile(file: string | undefined, root: string): string | undefined;
|