@neuralaxis/vibedoctor 0.1.0
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/LICENSE +232 -0
- package/README.md +280 -0
- package/dist/adapters/biome.d.ts +2 -0
- package/dist/adapters/biome.js +66 -0
- package/dist/adapters/coveragePy.d.ts +2 -0
- package/dist/adapters/coveragePy.js +56 -0
- package/dist/adapters/customDeadChain.d.ts +20 -0
- package/dist/adapters/customDeadChain.js +243 -0
- package/dist/adapters/customLeftovers.d.ts +2 -0
- package/dist/adapters/customLeftovers.js +244 -0
- package/dist/adapters/customRefactor.d.ts +2 -0
- package/dist/adapters/customRefactor.js +176 -0
- package/dist/adapters/deptry.d.ts +2 -0
- package/dist/adapters/deptry.js +59 -0
- package/dist/adapters/gitleaks.d.ts +2 -0
- package/dist/adapters/gitleaks.js +47 -0
- package/dist/adapters/index.d.ts +16 -0
- package/dist/adapters/index.js +35 -0
- package/dist/adapters/jest.d.ts +2 -0
- package/dist/adapters/jest.js +62 -0
- package/dist/adapters/jscpd.d.ts +2 -0
- package/dist/adapters/jscpd.js +59 -0
- package/dist/adapters/knip.d.ts +2 -0
- package/dist/adapters/knip.js +75 -0
- package/dist/adapters/lizard.d.ts +2 -0
- package/dist/adapters/lizard.js +45 -0
- package/dist/adapters/osvScanner.d.ts +2 -0
- package/dist/adapters/osvScanner.js +68 -0
- package/dist/adapters/pyright.d.ts +2 -0
- package/dist/adapters/pyright.js +52 -0
- package/dist/adapters/radon.d.ts +2 -0
- package/dist/adapters/radon.js +45 -0
- package/dist/adapters/ruff.d.ts +2 -0
- package/dist/adapters/ruff.js +71 -0
- package/dist/adapters/semgrep.d.ts +2 -0
- package/dist/adapters/semgrep.js +64 -0
- package/dist/adapters/shared.d.ts +23 -0
- package/dist/adapters/shared.js +2 -0
- package/dist/adapters/tsc.d.ts +2 -0
- package/dist/adapters/tsc.js +57 -0
- package/dist/adapters/vitest.d.ts +2 -0
- package/dist/adapters/vitest.js +62 -0
- package/dist/adapters/vulture.d.ts +2 -0
- package/dist/adapters/vulture.js +59 -0
- package/dist/agentPack/generateAgentPack.d.ts +48 -0
- package/dist/agentPack/generateAgentPack.js +219 -0
- package/dist/agentPack/policy.d.ts +19 -0
- package/dist/agentPack/policy.js +117 -0
- package/dist/agentPack/templates/index.d.ts +7 -0
- package/dist/agentPack/templates/index.js +134 -0
- package/dist/agentPack/templates/skills.d.ts +7 -0
- package/dist/agentPack/templates/skills.js +337 -0
- package/dist/cli/commands/agent.d.ts +22 -0
- package/dist/cli/commands/agent.js +57 -0
- package/dist/cli/commands/agentPlan.d.ts +1 -0
- package/dist/cli/commands/agentPlan.js +12 -0
- package/dist/cli/commands/baseline.d.ts +1 -0
- package/dist/cli/commands/baseline.js +8 -0
- package/dist/cli/commands/explain.d.ts +1 -0
- package/dist/cli/commands/explain.js +35 -0
- package/dist/cli/commands/fix.d.ts +1 -0
- package/dist/cli/commands/fix.js +19 -0
- package/dist/cli/commands/init.d.ts +1 -0
- package/dist/cli/commands/init.js +101 -0
- package/dist/cli/commands/report.d.ts +1 -0
- package/dist/cli/commands/report.js +25 -0
- package/dist/cli/commands/scan.d.ts +14 -0
- package/dist/cli/commands/scan.js +61 -0
- package/dist/cli/commands/setup.d.ts +35 -0
- package/dist/cli/commands/setup.js +326 -0
- package/dist/cli/commands/shared.d.ts +8 -0
- package/dist/cli/commands/shared.js +29 -0
- package/dist/cli/index.d.ts +2 -0
- package/dist/cli/index.js +148 -0
- package/dist/core/baseline.d.ts +7 -0
- package/dist/core/baseline.js +33 -0
- package/dist/core/config.d.ts +72 -0
- package/dist/core/config.js +236 -0
- package/dist/core/engine.d.ts +87 -0
- package/dist/core/engine.js +437 -0
- package/dist/core/finding.d.ts +40 -0
- package/dist/core/finding.js +141 -0
- package/dist/core/git.d.ts +3 -0
- package/dist/core/git.js +67 -0
- package/dist/core/paths.d.ts +7 -0
- package/dist/core/paths.js +104 -0
- package/dist/core/projectDetector.d.ts +17 -0
- package/dist/core/projectDetector.js +160 -0
- package/dist/core/scanPlanner.d.ts +11 -0
- package/dist/core/scanPlanner.js +47 -0
- package/dist/core/scoring.d.ts +8 -0
- package/dist/core/scoring.js +57 -0
- package/dist/core/toolRunner.d.ts +24 -0
- package/dist/core/toolRunner.js +130 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +23 -0
- package/dist/mcp/server.d.ts +1 -0
- package/dist/mcp/server.js +141 -0
- package/dist/mcp/tools/explainFinding.d.ts +2 -0
- package/dist/mcp/tools/explainFinding.js +23 -0
- package/dist/mcp/tools/fixSafe.d.ts +2 -0
- package/dist/mcp/tools/fixSafe.js +15 -0
- package/dist/mcp/tools/getAgentPlan.d.ts +2 -0
- package/dist/mcp/tools/getAgentPlan.js +31 -0
- package/dist/mcp/tools/getReport.d.ts +2 -0
- package/dist/mcp/tools/getReport.js +26 -0
- package/dist/mcp/tools/index.d.ts +1 -0
- package/dist/mcp/tools/index.js +19 -0
- package/dist/mcp/tools/scanChanged.d.ts +2 -0
- package/dist/mcp/tools/scanChanged.js +23 -0
- package/dist/mcp/tools/scanFull.d.ts +2 -0
- package/dist/mcp/tools/scanFull.js +23 -0
- package/dist/mcp/tools/shared.d.ts +51 -0
- package/dist/mcp/tools/shared.js +126 -0
- package/dist/mcp/tools/verify.d.ts +2 -0
- package/dist/mcp/tools/verify.js +21 -0
- package/dist/reporters/agent.d.ts +3 -0
- package/dist/reporters/agent.js +48 -0
- package/dist/reporters/html.d.ts +2 -0
- package/dist/reporters/html.js +81 -0
- package/dist/reporters/json.d.ts +2 -0
- package/dist/reporters/json.js +18 -0
- package/dist/reporters/markdown.d.ts +2 -0
- package/dist/reporters/markdown.js +33 -0
- package/dist/reporters/sarif.d.ts +2 -0
- package/dist/reporters/sarif.js +38 -0
- package/dist/reporters/terminal.d.ts +2 -0
- package/dist/reporters/terminal.js +11 -0
- package/dist/rules/leftoverPatterns.d.ts +7 -0
- package/dist/rules/leftoverPatterns.js +10 -0
- package/dist/rules/refactorRules.d.ts +13 -0
- package/dist/rules/refactorRules.js +16 -0
- package/dist/rules/severityMap.d.ts +15 -0
- package/dist/rules/severityMap.js +33 -0
- package/package.json +72 -0
|
@@ -0,0 +1,176 @@
|
|
|
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.customRefactorAdapter = void 0;
|
|
7
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
8
|
+
const paths_1 = require("../core/paths");
|
|
9
|
+
const refactorRules_1 = require("../rules/refactorRules");
|
|
10
|
+
function countOccurrences(content, expression) {
|
|
11
|
+
return (content.match(expression) ?? []).length;
|
|
12
|
+
}
|
|
13
|
+
function scoreLines(lineCount, minFileLines) {
|
|
14
|
+
if (lineCount < minFileLines) {
|
|
15
|
+
return 0;
|
|
16
|
+
}
|
|
17
|
+
if (lineCount > minFileLines * 2) {
|
|
18
|
+
return 35;
|
|
19
|
+
}
|
|
20
|
+
return 20;
|
|
21
|
+
}
|
|
22
|
+
function scoreComplexity(content, minComplexity) {
|
|
23
|
+
const branching = countOccurrences(content, /\b(if|else if|switch|case|catch|for|while|except)\b/g);
|
|
24
|
+
if (branching < minComplexity) {
|
|
25
|
+
return 0;
|
|
26
|
+
}
|
|
27
|
+
if (branching >= minComplexity * 2) {
|
|
28
|
+
return 30;
|
|
29
|
+
}
|
|
30
|
+
return 18;
|
|
31
|
+
}
|
|
32
|
+
function scoreDuplication(lines) {
|
|
33
|
+
const fingerprints = new Map();
|
|
34
|
+
for (const line of lines.map((item) => item.trim()).filter((item) => item.length > 20)) {
|
|
35
|
+
fingerprints.set(line, (fingerprints.get(line) ?? 0) + 1);
|
|
36
|
+
}
|
|
37
|
+
const duplicates = Array.from(fingerprints.values()).filter((count) => count > 1).length;
|
|
38
|
+
return Math.min(20, duplicates * 2);
|
|
39
|
+
}
|
|
40
|
+
function collectFunctionSignals(lines) {
|
|
41
|
+
const signals = [];
|
|
42
|
+
const pattern = /^\s*(?:export\s+)?(?:async\s+)?function\s+([A-Za-z0-9_]+)|^\s*def\s+([A-Za-z0-9_]+)|^\s*(?:export\s+)?const\s+([A-Za-z0-9_]+)\s*=\s*(?:async\s*)?\(/;
|
|
43
|
+
const functionStarts = lines
|
|
44
|
+
.map((line, index) => {
|
|
45
|
+
const match = line.match(pattern);
|
|
46
|
+
return match ? { index, name: match[1] ?? match[2] ?? match[3] ?? "anonymous" } : undefined;
|
|
47
|
+
})
|
|
48
|
+
.filter((item) => Boolean(item));
|
|
49
|
+
for (let i = 0; i < functionStarts.length; i += 1) {
|
|
50
|
+
const current = functionStarts[i];
|
|
51
|
+
const next = functionStarts[i + 1];
|
|
52
|
+
const startLine = current.index + 1;
|
|
53
|
+
const endLine = next ? next.index : lines.length;
|
|
54
|
+
const block = lines.slice(current.index, endLine);
|
|
55
|
+
const complexity = block.reduce((total, line) => total + (line.match(/\b(if|else if|switch|case|catch|for|while|except)\b/g)?.length ?? 0), 0);
|
|
56
|
+
signals.push({
|
|
57
|
+
name: current.name,
|
|
58
|
+
startLine,
|
|
59
|
+
endLine,
|
|
60
|
+
length: endLine - current.index,
|
|
61
|
+
complexity
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
return signals;
|
|
65
|
+
}
|
|
66
|
+
function isSecuritySensitive(file, content) {
|
|
67
|
+
return /payment|webhook|token|secret|signature|auth|session/i.test(file) || /\b(payment|webhook|secret|token|signature|auth|session)\b/i.test(content);
|
|
68
|
+
}
|
|
69
|
+
exports.customRefactorAdapter = {
|
|
70
|
+
id: "custom-refactor",
|
|
71
|
+
category: "refactor_readiness",
|
|
72
|
+
async detect(_project, config) {
|
|
73
|
+
return config.checks.refactorReadiness.enabled;
|
|
74
|
+
},
|
|
75
|
+
async runStandalone(ctx) {
|
|
76
|
+
const candidates = (0, paths_1.filterPaths)(ctx.project.projectFiles, ctx.config.paths.include, ctx.config.paths.exclude).filter((file) => /\.(ts|tsx|js|jsx|py)$/.test(file));
|
|
77
|
+
const findings = [];
|
|
78
|
+
const hasTests = ctx.project.projectFiles.some((file) => /(^|\/)tests?\//.test(file) || /\.test\./.test(file));
|
|
79
|
+
for (const file of candidates) {
|
|
80
|
+
const content = await (0, paths_1.readTextIfExists)(node_path_1.default.join(ctx.root, file));
|
|
81
|
+
if (!content) {
|
|
82
|
+
continue;
|
|
83
|
+
}
|
|
84
|
+
if (/generated/i.test(content.slice(0, 200))) {
|
|
85
|
+
continue;
|
|
86
|
+
}
|
|
87
|
+
const lines = content.split(/\r?\n/);
|
|
88
|
+
const lineCount = lines.length;
|
|
89
|
+
const importCount = countOccurrences(content, /\b(import|from)\b/g);
|
|
90
|
+
const exportCount = countOccurrences(content, /\bexport\b/g) + countOccurrences(content, /\bdef\b/g);
|
|
91
|
+
const functionSignals = collectFunctionSignals(lines);
|
|
92
|
+
const largestFunction = functionSignals.reduce((largest, signal) => {
|
|
93
|
+
if (!largest || signal.length > largest.length) {
|
|
94
|
+
return signal;
|
|
95
|
+
}
|
|
96
|
+
return largest;
|
|
97
|
+
}, undefined);
|
|
98
|
+
const highComplexFunctions = functionSignals.filter((signal) => signal.complexity >= ctx.config.checks.refactorReadiness.minComplexity);
|
|
99
|
+
const securitySensitive = isSecuritySensitive(file, content);
|
|
100
|
+
const pain = scoreLines(lineCount, ctx.config.checks.refactorReadiness.minFileLines) +
|
|
101
|
+
scoreComplexity(content, ctx.config.checks.refactorReadiness.minComplexity) +
|
|
102
|
+
scoreDuplication(lines) +
|
|
103
|
+
Math.min(10, Math.floor(importCount / 6)) +
|
|
104
|
+
Math.min(10, Math.floor(exportCount / 6)) +
|
|
105
|
+
Math.min(12, highComplexFunctions.length * 3) +
|
|
106
|
+
(largestFunction && largestFunction.length > 80 ? 12 : 0);
|
|
107
|
+
const testSafety = !ctx.config.checks.refactorReadiness.requireTestsBeforeRefactor ? 25 : hasTests ? 35 : 5;
|
|
108
|
+
const safety = testSafety +
|
|
109
|
+
Math.max(0, 25 - Math.floor(exportCount / 2)) +
|
|
110
|
+
Math.max(0, 20 - Math.floor(importCount / 2)) -
|
|
111
|
+
(securitySensitive ? 20 : 0);
|
|
112
|
+
const ready = safety >= refactorRules_1.safetyThresholds.ready;
|
|
113
|
+
const nearThresholdReady = ready &&
|
|
114
|
+
lineCount >= Math.ceil(ctx.config.checks.refactorReadiness.minFileLines * 1.75) &&
|
|
115
|
+
highComplexFunctions.length > 0;
|
|
116
|
+
if (pain < refactorRules_1.safetyThresholds.pain && !nearThresholdReady) {
|
|
117
|
+
if (!largestFunction || largestFunction.length < 80 || largestFunction.complexity < ctx.config.checks.refactorReadiness.minComplexity) {
|
|
118
|
+
continue;
|
|
119
|
+
}
|
|
120
|
+
findings.push({
|
|
121
|
+
id: `refactor:function:${file}:${largestFunction.startLine}`,
|
|
122
|
+
source: "custom-refactor",
|
|
123
|
+
category: "refactor_readiness",
|
|
124
|
+
severity: ready ? "low" : "medium",
|
|
125
|
+
confidence: "medium",
|
|
126
|
+
title: ready ? "Function ready for refactor" : "Add tests before function refactor",
|
|
127
|
+
message: ready
|
|
128
|
+
? `${largestFunction.name} in ${file} is a focused extraction candidate.`
|
|
129
|
+
: `${largestFunction.name} in ${file} is complex, but needs better test safety before refactoring.`,
|
|
130
|
+
file,
|
|
131
|
+
startLine: largestFunction.startLine,
|
|
132
|
+
endLine: largestFunction.endLine,
|
|
133
|
+
isNew: true,
|
|
134
|
+
isAutofixable: false,
|
|
135
|
+
safeToAutofix: false,
|
|
136
|
+
agentInstruction: ready
|
|
137
|
+
? `Extract ${largestFunction.name} into a smaller helper while keeping the public API unchanged.`
|
|
138
|
+
: `Add tests covering ${largestFunction.name} before attempting a refactor.`,
|
|
139
|
+
tags: ["refactor", "function-level", ready ? "ready" : "tests-first"],
|
|
140
|
+
evidence: {
|
|
141
|
+
snippet: `function=${largestFunction.name}; lines=${largestFunction.length}; complexity=${largestFunction.complexity}; safety=${safety}`
|
|
142
|
+
},
|
|
143
|
+
scoreImpact: 0
|
|
144
|
+
});
|
|
145
|
+
continue;
|
|
146
|
+
}
|
|
147
|
+
findings.push({
|
|
148
|
+
id: `refactor:${file}`,
|
|
149
|
+
source: "custom-refactor",
|
|
150
|
+
category: "refactor_readiness",
|
|
151
|
+
severity: ready ? "low" : "medium",
|
|
152
|
+
confidence: "medium",
|
|
153
|
+
title: ready ? "Ready for refactor" : "Add tests before refactor",
|
|
154
|
+
message: ready
|
|
155
|
+
? `${file} is large and tangled enough to split with moderate safety.`
|
|
156
|
+
: `${file} looks painful, but test safety is too weak for a confident refactor.`,
|
|
157
|
+
file,
|
|
158
|
+
isNew: true,
|
|
159
|
+
isAutofixable: false,
|
|
160
|
+
safeToAutofix: false,
|
|
161
|
+
agentInstruction: ready
|
|
162
|
+
? `Keep the public entrypoint stable and extract smaller modules in small patches.${largestFunction ? ` Start with ${largestFunction.name}.` : ""}`
|
|
163
|
+
: securitySensitive
|
|
164
|
+
? "Add focused tests around current behavior before changing structure, especially around the security-sensitive paths."
|
|
165
|
+
: "Add focused tests around current behavior before changing structure.",
|
|
166
|
+
tags: ["refactor", ready ? "ready" : "tests-first"],
|
|
167
|
+
evidence: {
|
|
168
|
+
snippet: `lines=${lineCount}; pain=${pain}; safety=${safety}; imports=${importCount}; exports=${exportCount}; largestFunction=${largestFunction?.name ?? "n/a"}:${largestFunction?.length ?? 0}; securitySensitive=${securitySensitive}`
|
|
169
|
+
},
|
|
170
|
+
scoreImpact: 0
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
return { findings };
|
|
174
|
+
},
|
|
175
|
+
installHint: "Built-in detector. No external install needed."
|
|
176
|
+
};
|
|
@@ -0,0 +1,59 @@
|
|
|
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.deptryAdapter = void 0;
|
|
7
|
+
const node_fs_1 = require("node:fs");
|
|
8
|
+
const node_os_1 = __importDefault(require("node:os"));
|
|
9
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
10
|
+
const finding_1 = require("../core/finding");
|
|
11
|
+
const toolRunner_1 = require("../core/toolRunner");
|
|
12
|
+
function parseDeptry(text) {
|
|
13
|
+
return text.trim() ? JSON.parse(text) : [];
|
|
14
|
+
}
|
|
15
|
+
exports.deptryAdapter = {
|
|
16
|
+
id: "deptry",
|
|
17
|
+
category: "dependencies",
|
|
18
|
+
async detect(project) {
|
|
19
|
+
return project.languages.includes("python");
|
|
20
|
+
},
|
|
21
|
+
async runStandalone(ctx) {
|
|
22
|
+
const tempPath = node_path_1.default.join(node_os_1.default.tmpdir(), `vibedoctor-deptry-${Date.now()}.json`);
|
|
23
|
+
const status = await (0, toolRunner_1.runCommand)({
|
|
24
|
+
cmd: "deptry",
|
|
25
|
+
args: [".", "--json-output", tempPath],
|
|
26
|
+
cwd: ctx.root,
|
|
27
|
+
timeoutMs: 90_000
|
|
28
|
+
}, "Install deptry with: pipx install deptry or uv tool install deptry");
|
|
29
|
+
let findings = [];
|
|
30
|
+
try {
|
|
31
|
+
const content = await node_fs_1.promises.readFile(tempPath, "utf8");
|
|
32
|
+
findings = parseDeptry(content).map((item, index) => ({
|
|
33
|
+
id: `deptry:${item.location?.file}:${item.location?.line ?? 0}:${item.error.code}:${index}`,
|
|
34
|
+
source: "deptry",
|
|
35
|
+
category: "dependencies",
|
|
36
|
+
severity: item.error.code === "DEP002" ? "medium" : "low",
|
|
37
|
+
confidence: "high",
|
|
38
|
+
title: item.error.code,
|
|
39
|
+
message: item.error.message,
|
|
40
|
+
file: (0, finding_1.normalizeFilePath)(item.location?.file, ctx.root),
|
|
41
|
+
startLine: item.location?.line,
|
|
42
|
+
isNew: true,
|
|
43
|
+
isAutofixable: false,
|
|
44
|
+
safeToAutofix: false,
|
|
45
|
+
agentInstruction: "Fix the Python dependency declaration without removing packages that may be imported dynamically.",
|
|
46
|
+
tags: ["python", "dependencies"],
|
|
47
|
+
scoreImpact: 0
|
|
48
|
+
}));
|
|
49
|
+
}
|
|
50
|
+
catch {
|
|
51
|
+
findings = [];
|
|
52
|
+
}
|
|
53
|
+
finally {
|
|
54
|
+
await node_fs_1.promises.rm(tempPath, { force: true }).catch(() => undefined);
|
|
55
|
+
}
|
|
56
|
+
return { findings, status };
|
|
57
|
+
},
|
|
58
|
+
installHint: "Install deptry with: pipx install deptry or uv tool install deptry"
|
|
59
|
+
};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.gitleaksAdapter = void 0;
|
|
4
|
+
const finding_1 = require("../core/finding");
|
|
5
|
+
function parseGitleaks(stdout) {
|
|
6
|
+
const trimmed = stdout.trim();
|
|
7
|
+
return trimmed ? JSON.parse(trimmed) : [];
|
|
8
|
+
}
|
|
9
|
+
exports.gitleaksAdapter = {
|
|
10
|
+
id: "gitleaks",
|
|
11
|
+
category: "security",
|
|
12
|
+
async detect() {
|
|
13
|
+
return true;
|
|
14
|
+
},
|
|
15
|
+
buildScanCommand(ctx) {
|
|
16
|
+
return {
|
|
17
|
+
cmd: "gitleaks",
|
|
18
|
+
args: ["detect", "--no-banner", "--redact", "--report-format", "json", "--report-path", "-"],
|
|
19
|
+
cwd: ctx.root,
|
|
20
|
+
timeoutMs: 60_000
|
|
21
|
+
};
|
|
22
|
+
},
|
|
23
|
+
parseResult(result, ctx) {
|
|
24
|
+
return parseGitleaks(result.stdout).map((item, index) => ({
|
|
25
|
+
id: `gitleaks:${item.File}:${item.StartLine}:${item.RuleID ?? index}`,
|
|
26
|
+
source: "gitleaks",
|
|
27
|
+
category: "security",
|
|
28
|
+
severity: "critical",
|
|
29
|
+
confidence: "high",
|
|
30
|
+
title: item.RuleID ?? "Secret-like token",
|
|
31
|
+
message: item.Description ?? "Potential secret detected.",
|
|
32
|
+
file: (0, finding_1.normalizeFilePath)(item.File, ctx.root),
|
|
33
|
+
startLine: item.StartLine,
|
|
34
|
+
endLine: item.EndLine,
|
|
35
|
+
isNew: true,
|
|
36
|
+
isAutofixable: false,
|
|
37
|
+
safeToAutofix: false,
|
|
38
|
+
agentInstruction: "Remove the secret from source, rotate the credential, and replace it with environment-based configuration.",
|
|
39
|
+
tags: ["security", "secret"],
|
|
40
|
+
evidence: {
|
|
41
|
+
snippet: item.Match ?? item.Secret
|
|
42
|
+
},
|
|
43
|
+
scoreImpact: 0
|
|
44
|
+
}));
|
|
45
|
+
},
|
|
46
|
+
installHint: "Install Gitleaks from https://gitleaks.io/ or your package manager."
|
|
47
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export { biomeAdapter } from "./biome";
|
|
2
|
+
export { coveragePyAdapter } from "./coveragePy";
|
|
3
|
+
export { deptryAdapter } from "./deptry";
|
|
4
|
+
export { gitleaksAdapter } from "./gitleaks";
|
|
5
|
+
export { jestAdapter } from "./jest";
|
|
6
|
+
export { jscpdAdapter } from "./jscpd";
|
|
7
|
+
export { knipAdapter } from "./knip";
|
|
8
|
+
export { lizardAdapter } from "./lizard";
|
|
9
|
+
export { osvScannerAdapter } from "./osvScanner";
|
|
10
|
+
export { pyrightAdapter } from "./pyright";
|
|
11
|
+
export { radonAdapter } from "./radon";
|
|
12
|
+
export { ruffAdapter } from "./ruff";
|
|
13
|
+
export { semgrepAdapter } from "./semgrep";
|
|
14
|
+
export { tscAdapter } from "./tsc";
|
|
15
|
+
export { vitestAdapter } from "./vitest";
|
|
16
|
+
export { vultureAdapter } from "./vulture";
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
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;
|
|
4
|
+
var biome_1 = require("./biome");
|
|
5
|
+
Object.defineProperty(exports, "biomeAdapter", { enumerable: true, get: function () { return biome_1.biomeAdapter; } });
|
|
6
|
+
var coveragePy_1 = require("./coveragePy");
|
|
7
|
+
Object.defineProperty(exports, "coveragePyAdapter", { enumerable: true, get: function () { return coveragePy_1.coveragePyAdapter; } });
|
|
8
|
+
var deptry_1 = require("./deptry");
|
|
9
|
+
Object.defineProperty(exports, "deptryAdapter", { enumerable: true, get: function () { return deptry_1.deptryAdapter; } });
|
|
10
|
+
var gitleaks_1 = require("./gitleaks");
|
|
11
|
+
Object.defineProperty(exports, "gitleaksAdapter", { enumerable: true, get: function () { return gitleaks_1.gitleaksAdapter; } });
|
|
12
|
+
var jest_1 = require("./jest");
|
|
13
|
+
Object.defineProperty(exports, "jestAdapter", { enumerable: true, get: function () { return jest_1.jestAdapter; } });
|
|
14
|
+
var jscpd_1 = require("./jscpd");
|
|
15
|
+
Object.defineProperty(exports, "jscpdAdapter", { enumerable: true, get: function () { return jscpd_1.jscpdAdapter; } });
|
|
16
|
+
var knip_1 = require("./knip");
|
|
17
|
+
Object.defineProperty(exports, "knipAdapter", { enumerable: true, get: function () { return knip_1.knipAdapter; } });
|
|
18
|
+
var lizard_1 = require("./lizard");
|
|
19
|
+
Object.defineProperty(exports, "lizardAdapter", { enumerable: true, get: function () { return lizard_1.lizardAdapter; } });
|
|
20
|
+
var osvScanner_1 = require("./osvScanner");
|
|
21
|
+
Object.defineProperty(exports, "osvScannerAdapter", { enumerable: true, get: function () { return osvScanner_1.osvScannerAdapter; } });
|
|
22
|
+
var pyright_1 = require("./pyright");
|
|
23
|
+
Object.defineProperty(exports, "pyrightAdapter", { enumerable: true, get: function () { return pyright_1.pyrightAdapter; } });
|
|
24
|
+
var radon_1 = require("./radon");
|
|
25
|
+
Object.defineProperty(exports, "radonAdapter", { enumerable: true, get: function () { return radon_1.radonAdapter; } });
|
|
26
|
+
var ruff_1 = require("./ruff");
|
|
27
|
+
Object.defineProperty(exports, "ruffAdapter", { enumerable: true, get: function () { return ruff_1.ruffAdapter; } });
|
|
28
|
+
var semgrep_1 = require("./semgrep");
|
|
29
|
+
Object.defineProperty(exports, "semgrepAdapter", { enumerable: true, get: function () { return semgrep_1.semgrepAdapter; } });
|
|
30
|
+
var tsc_1 = require("./tsc");
|
|
31
|
+
Object.defineProperty(exports, "tscAdapter", { enumerable: true, get: function () { return tsc_1.tscAdapter; } });
|
|
32
|
+
var vitest_1 = require("./vitest");
|
|
33
|
+
Object.defineProperty(exports, "vitestAdapter", { enumerable: true, get: function () { return vitest_1.vitestAdapter; } });
|
|
34
|
+
var vulture_1 = require("./vulture");
|
|
35
|
+
Object.defineProperty(exports, "vultureAdapter", { enumerable: true, get: function () { return vulture_1.vultureAdapter; } });
|
|
@@ -0,0 +1,62 @@
|
|
|
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.jestAdapter = void 0;
|
|
7
|
+
const node_fs_1 = require("node:fs");
|
|
8
|
+
const node_os_1 = __importDefault(require("node:os"));
|
|
9
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
10
|
+
const paths_1 = require("../core/paths");
|
|
11
|
+
const toolRunner_1 = require("../core/toolRunner");
|
|
12
|
+
async function readCoverageSummary(filePath) {
|
|
13
|
+
if (!(await (0, paths_1.pathExists)(filePath))) {
|
|
14
|
+
return undefined;
|
|
15
|
+
}
|
|
16
|
+
const parsed = JSON.parse(await node_fs_1.promises.readFile(filePath, "utf8"));
|
|
17
|
+
return parsed.total?.lines?.pct;
|
|
18
|
+
}
|
|
19
|
+
exports.jestAdapter = {
|
|
20
|
+
id: "jest",
|
|
21
|
+
category: "tests",
|
|
22
|
+
async detect(project) {
|
|
23
|
+
return project.frameworkHints.includes("jest") || project.testCommands.some((command) => /jest/i.test(command));
|
|
24
|
+
},
|
|
25
|
+
async runStandalone(ctx) {
|
|
26
|
+
const existingSummary = node_path_1.default.join(ctx.root, "coverage", "coverage-summary.json");
|
|
27
|
+
let percent = await readCoverageSummary(existingSummary);
|
|
28
|
+
let status;
|
|
29
|
+
if (percent === undefined) {
|
|
30
|
+
const outputDir = node_path_1.default.join(node_os_1.default.tmpdir(), `vibedoctor-jest-${Date.now()}`);
|
|
31
|
+
status = await (0, toolRunner_1.runCommand)({
|
|
32
|
+
cmd: "jest",
|
|
33
|
+
args: ["--coverage", "--coverageReporters=json-summary", `--coverageDirectory=${outputDir}`],
|
|
34
|
+
cwd: ctx.root,
|
|
35
|
+
timeoutMs: 180_000
|
|
36
|
+
}, "Install Jest with: npm install -D jest");
|
|
37
|
+
percent = await readCoverageSummary(node_path_1.default.join(outputDir, "coverage-summary.json"));
|
|
38
|
+
await node_fs_1.promises.rm(outputDir, { recursive: true, force: true }).catch(() => undefined);
|
|
39
|
+
}
|
|
40
|
+
const findings = typeof percent === "number" && percent < ctx.config.checks.tests.minCoverage
|
|
41
|
+
? [
|
|
42
|
+
{
|
|
43
|
+
id: "jest:coverage",
|
|
44
|
+
source: "jest",
|
|
45
|
+
category: "tests",
|
|
46
|
+
severity: percent < ctx.config.checks.tests.minCoverage / 2 ? "high" : "medium",
|
|
47
|
+
confidence: "high",
|
|
48
|
+
title: "JS coverage below target",
|
|
49
|
+
message: `Coverage is ${percent}% which is below the configured minimum of ${ctx.config.checks.tests.minCoverage}%.`,
|
|
50
|
+
isNew: true,
|
|
51
|
+
isAutofixable: false,
|
|
52
|
+
safeToAutofix: false,
|
|
53
|
+
agentInstruction: "Add or expand Jest coverage before larger refactors.",
|
|
54
|
+
tags: ["javascript", "coverage"],
|
|
55
|
+
scoreImpact: 0
|
|
56
|
+
}
|
|
57
|
+
]
|
|
58
|
+
: [];
|
|
59
|
+
return { findings, status };
|
|
60
|
+
},
|
|
61
|
+
installHint: "Install Jest with: npm install -D jest"
|
|
62
|
+
};
|
|
@@ -0,0 +1,59 @@
|
|
|
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.jscpdAdapter = void 0;
|
|
7
|
+
const node_fs_1 = require("node:fs");
|
|
8
|
+
const node_os_1 = __importDefault(require("node:os"));
|
|
9
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
10
|
+
const finding_1 = require("../core/finding");
|
|
11
|
+
const toolRunner_1 = require("../core/toolRunner");
|
|
12
|
+
exports.jscpdAdapter = {
|
|
13
|
+
id: "jscpd",
|
|
14
|
+
category: "maintainability",
|
|
15
|
+
async detect(project) {
|
|
16
|
+
return project.languages.length > 0;
|
|
17
|
+
},
|
|
18
|
+
async runStandalone(ctx) {
|
|
19
|
+
const outputDir = node_path_1.default.join(node_os_1.default.tmpdir(), `vibedoctor-jscpd-${Date.now()}`);
|
|
20
|
+
const reportPath = node_path_1.default.join(outputDir, "jscpd-report.json");
|
|
21
|
+
const status = await (0, toolRunner_1.runCommand)({
|
|
22
|
+
cmd: "jscpd",
|
|
23
|
+
args: [".", "--reporters", "json", "--output", outputDir],
|
|
24
|
+
cwd: ctx.root,
|
|
25
|
+
timeoutMs: 120_000
|
|
26
|
+
}, "Install jscpd with: npm install -D jscpd");
|
|
27
|
+
let findings = [];
|
|
28
|
+
try {
|
|
29
|
+
const content = await node_fs_1.promises.readFile(reportPath, "utf8");
|
|
30
|
+
const parsed = JSON.parse(content);
|
|
31
|
+
findings = (parsed.duplicates ?? []).map((clone, index) => ({
|
|
32
|
+
id: `jscpd:${clone.firstFile?.name}:${clone.firstFile?.start ?? 0}:${index}`,
|
|
33
|
+
source: "jscpd",
|
|
34
|
+
category: "maintainability",
|
|
35
|
+
severity: (clone.lines ?? 0) > 20 ? "medium" : "low",
|
|
36
|
+
confidence: "high",
|
|
37
|
+
title: "Duplicated code block",
|
|
38
|
+
message: `${clone.lines ?? clone.tokens ?? 0} duplicated lines between ${clone.firstFile?.name} and ${clone.secondFile?.name}.`,
|
|
39
|
+
file: (0, finding_1.normalizeFilePath)(clone.firstFile?.name, ctx.root),
|
|
40
|
+
startLine: clone.firstFile?.start,
|
|
41
|
+
endLine: clone.firstFile?.end,
|
|
42
|
+
isNew: true,
|
|
43
|
+
isAutofixable: false,
|
|
44
|
+
safeToAutofix: false,
|
|
45
|
+
agentInstruction: "Extract or consolidate the duplicated logic only if behavior can stay identical.",
|
|
46
|
+
tags: ["duplication", clone.format ?? "unknown"],
|
|
47
|
+
scoreImpact: 0
|
|
48
|
+
}));
|
|
49
|
+
}
|
|
50
|
+
catch {
|
|
51
|
+
findings = [];
|
|
52
|
+
}
|
|
53
|
+
finally {
|
|
54
|
+
await node_fs_1.promises.rm(outputDir, { recursive: true, force: true }).catch(() => undefined);
|
|
55
|
+
}
|
|
56
|
+
return { findings, status };
|
|
57
|
+
},
|
|
58
|
+
installHint: "Install jscpd with: npm install -D jscpd"
|
|
59
|
+
};
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.knipAdapter = void 0;
|
|
4
|
+
const finding_1 = require("../core/finding");
|
|
5
|
+
function parseKnip(stdout) {
|
|
6
|
+
return stdout.trim() ? JSON.parse(stdout) : {};
|
|
7
|
+
}
|
|
8
|
+
exports.knipAdapter = {
|
|
9
|
+
id: "knip",
|
|
10
|
+
category: "dead_code",
|
|
11
|
+
async detect(project) {
|
|
12
|
+
return project.languages.includes("javascript") || project.languages.includes("typescript");
|
|
13
|
+
},
|
|
14
|
+
buildScanCommand(ctx) {
|
|
15
|
+
return {
|
|
16
|
+
cmd: "knip",
|
|
17
|
+
args: ["--reporter", "json"],
|
|
18
|
+
cwd: ctx.root,
|
|
19
|
+
timeoutMs: 60_000
|
|
20
|
+
};
|
|
21
|
+
},
|
|
22
|
+
parseResult(result, ctx) {
|
|
23
|
+
const parsed = parseKnip(result.stdout);
|
|
24
|
+
const fileFindings = (parsed.unusedFiles ?? []).map((file) => ({
|
|
25
|
+
id: `knip:file:${file}`,
|
|
26
|
+
source: "knip",
|
|
27
|
+
category: "dead_code",
|
|
28
|
+
severity: "medium",
|
|
29
|
+
confidence: "high",
|
|
30
|
+
title: "Unused file",
|
|
31
|
+
message: `${file} is not reachable from detected entrypoints.`,
|
|
32
|
+
file: (0, finding_1.normalizeFilePath)(file, ctx.root),
|
|
33
|
+
isNew: true,
|
|
34
|
+
isAutofixable: false,
|
|
35
|
+
safeToAutofix: false,
|
|
36
|
+
agentInstruction: "Verify no runtime entrypoint or framework convention depends on this file before deletion.",
|
|
37
|
+
tags: ["javascript", "typescript", "dead-code"],
|
|
38
|
+
scoreImpact: 0
|
|
39
|
+
}));
|
|
40
|
+
const exportFindings = (parsed.unusedExports ?? []).map((item) => ({
|
|
41
|
+
id: `knip:export:${item.file}:${item.line}:${item.symbol}`,
|
|
42
|
+
source: "knip",
|
|
43
|
+
category: "dead_code",
|
|
44
|
+
severity: "low",
|
|
45
|
+
confidence: "high",
|
|
46
|
+
title: "Unused export",
|
|
47
|
+
message: `${item.symbol ?? "Export"} appears unused.`,
|
|
48
|
+
file: (0, finding_1.normalizeFilePath)(item.file, ctx.root),
|
|
49
|
+
startLine: item.line,
|
|
50
|
+
isNew: true,
|
|
51
|
+
isAutofixable: false,
|
|
52
|
+
safeToAutofix: false,
|
|
53
|
+
agentInstruction: "Remove the export only if external consumers and dynamic imports are ruled out.",
|
|
54
|
+
tags: ["javascript", "typescript", "dead-code"],
|
|
55
|
+
scoreImpact: 0
|
|
56
|
+
}));
|
|
57
|
+
const dependencyFindings = (parsed.unusedDependencies ?? []).map((dependency) => ({
|
|
58
|
+
id: `knip:dependency:${dependency}`,
|
|
59
|
+
source: "knip",
|
|
60
|
+
category: "dependencies",
|
|
61
|
+
severity: "low",
|
|
62
|
+
confidence: "medium",
|
|
63
|
+
title: "Unused dependency",
|
|
64
|
+
message: `${dependency} appears unused in the current JS/TS graph.`,
|
|
65
|
+
isNew: true,
|
|
66
|
+
isAutofixable: false,
|
|
67
|
+
safeToAutofix: false,
|
|
68
|
+
agentInstruction: "Remove the dependency only after checking scripts, config, and transitive runtime loading.",
|
|
69
|
+
tags: ["javascript", "typescript", "dependencies"],
|
|
70
|
+
scoreImpact: 0
|
|
71
|
+
}));
|
|
72
|
+
return [...fileFindings, ...exportFindings, ...dependencyFindings];
|
|
73
|
+
},
|
|
74
|
+
installHint: "Install Knip with: npm install -D knip"
|
|
75
|
+
};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.lizardAdapter = void 0;
|
|
4
|
+
const finding_1 = require("../core/finding");
|
|
5
|
+
function parseLizard(stdout) {
|
|
6
|
+
return stdout.trim() ? JSON.parse(stdout) : [];
|
|
7
|
+
}
|
|
8
|
+
exports.lizardAdapter = {
|
|
9
|
+
id: "lizard",
|
|
10
|
+
category: "maintainability",
|
|
11
|
+
async detect(project) {
|
|
12
|
+
return project.languages.length > 0;
|
|
13
|
+
},
|
|
14
|
+
buildScanCommand(ctx) {
|
|
15
|
+
return {
|
|
16
|
+
cmd: "lizard",
|
|
17
|
+
args: ["-j", "."],
|
|
18
|
+
cwd: ctx.root,
|
|
19
|
+
timeoutMs: 120_000
|
|
20
|
+
};
|
|
21
|
+
},
|
|
22
|
+
parseResult(result, ctx) {
|
|
23
|
+
return parseLizard(result.stdout).flatMap((file) => (file.function_list ?? [])
|
|
24
|
+
.filter((item) => (item.cyclomatic_complexity ?? 0) >= ctx.config.checks.refactorReadiness.minComplexity)
|
|
25
|
+
.map((item) => ({
|
|
26
|
+
id: `lizard:${file.filename}:${item.start_line ?? 0}:${item.name}`,
|
|
27
|
+
source: "lizard",
|
|
28
|
+
category: "maintainability",
|
|
29
|
+
severity: (item.cyclomatic_complexity ?? 0) >= ctx.config.checks.refactorReadiness.minComplexity * 2 ? "high" : "medium",
|
|
30
|
+
confidence: "high",
|
|
31
|
+
title: "High cyclomatic complexity",
|
|
32
|
+
message: `${item.name ?? "Function"} complexity is ${item.cyclomatic_complexity}.`,
|
|
33
|
+
file: (0, finding_1.normalizeFilePath)(file.filename, ctx.root),
|
|
34
|
+
startLine: item.start_line,
|
|
35
|
+
endLine: item.end_line,
|
|
36
|
+
isNew: true,
|
|
37
|
+
isAutofixable: false,
|
|
38
|
+
safeToAutofix: false,
|
|
39
|
+
agentInstruction: "Reduce branching with extraction or guard clauses while keeping current behavior stable.",
|
|
40
|
+
tags: ["complexity"],
|
|
41
|
+
scoreImpact: 0
|
|
42
|
+
})));
|
|
43
|
+
},
|
|
44
|
+
installHint: "Install lizard with: pipx install lizard or uv tool install lizard"
|
|
45
|
+
};
|