@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.
Files changed (135) hide show
  1. package/LICENSE +232 -0
  2. package/README.md +280 -0
  3. package/dist/adapters/biome.d.ts +2 -0
  4. package/dist/adapters/biome.js +66 -0
  5. package/dist/adapters/coveragePy.d.ts +2 -0
  6. package/dist/adapters/coveragePy.js +56 -0
  7. package/dist/adapters/customDeadChain.d.ts +20 -0
  8. package/dist/adapters/customDeadChain.js +243 -0
  9. package/dist/adapters/customLeftovers.d.ts +2 -0
  10. package/dist/adapters/customLeftovers.js +244 -0
  11. package/dist/adapters/customRefactor.d.ts +2 -0
  12. package/dist/adapters/customRefactor.js +176 -0
  13. package/dist/adapters/deptry.d.ts +2 -0
  14. package/dist/adapters/deptry.js +59 -0
  15. package/dist/adapters/gitleaks.d.ts +2 -0
  16. package/dist/adapters/gitleaks.js +47 -0
  17. package/dist/adapters/index.d.ts +16 -0
  18. package/dist/adapters/index.js +35 -0
  19. package/dist/adapters/jest.d.ts +2 -0
  20. package/dist/adapters/jest.js +62 -0
  21. package/dist/adapters/jscpd.d.ts +2 -0
  22. package/dist/adapters/jscpd.js +59 -0
  23. package/dist/adapters/knip.d.ts +2 -0
  24. package/dist/adapters/knip.js +75 -0
  25. package/dist/adapters/lizard.d.ts +2 -0
  26. package/dist/adapters/lizard.js +45 -0
  27. package/dist/adapters/osvScanner.d.ts +2 -0
  28. package/dist/adapters/osvScanner.js +68 -0
  29. package/dist/adapters/pyright.d.ts +2 -0
  30. package/dist/adapters/pyright.js +52 -0
  31. package/dist/adapters/radon.d.ts +2 -0
  32. package/dist/adapters/radon.js +45 -0
  33. package/dist/adapters/ruff.d.ts +2 -0
  34. package/dist/adapters/ruff.js +71 -0
  35. package/dist/adapters/semgrep.d.ts +2 -0
  36. package/dist/adapters/semgrep.js +64 -0
  37. package/dist/adapters/shared.d.ts +23 -0
  38. package/dist/adapters/shared.js +2 -0
  39. package/dist/adapters/tsc.d.ts +2 -0
  40. package/dist/adapters/tsc.js +57 -0
  41. package/dist/adapters/vitest.d.ts +2 -0
  42. package/dist/adapters/vitest.js +62 -0
  43. package/dist/adapters/vulture.d.ts +2 -0
  44. package/dist/adapters/vulture.js +59 -0
  45. package/dist/agentPack/generateAgentPack.d.ts +48 -0
  46. package/dist/agentPack/generateAgentPack.js +219 -0
  47. package/dist/agentPack/policy.d.ts +19 -0
  48. package/dist/agentPack/policy.js +117 -0
  49. package/dist/agentPack/templates/index.d.ts +7 -0
  50. package/dist/agentPack/templates/index.js +134 -0
  51. package/dist/agentPack/templates/skills.d.ts +7 -0
  52. package/dist/agentPack/templates/skills.js +337 -0
  53. package/dist/cli/commands/agent.d.ts +22 -0
  54. package/dist/cli/commands/agent.js +57 -0
  55. package/dist/cli/commands/agentPlan.d.ts +1 -0
  56. package/dist/cli/commands/agentPlan.js +12 -0
  57. package/dist/cli/commands/baseline.d.ts +1 -0
  58. package/dist/cli/commands/baseline.js +8 -0
  59. package/dist/cli/commands/explain.d.ts +1 -0
  60. package/dist/cli/commands/explain.js +35 -0
  61. package/dist/cli/commands/fix.d.ts +1 -0
  62. package/dist/cli/commands/fix.js +19 -0
  63. package/dist/cli/commands/init.d.ts +1 -0
  64. package/dist/cli/commands/init.js +101 -0
  65. package/dist/cli/commands/report.d.ts +1 -0
  66. package/dist/cli/commands/report.js +25 -0
  67. package/dist/cli/commands/scan.d.ts +14 -0
  68. package/dist/cli/commands/scan.js +61 -0
  69. package/dist/cli/commands/setup.d.ts +35 -0
  70. package/dist/cli/commands/setup.js +326 -0
  71. package/dist/cli/commands/shared.d.ts +8 -0
  72. package/dist/cli/commands/shared.js +29 -0
  73. package/dist/cli/index.d.ts +2 -0
  74. package/dist/cli/index.js +148 -0
  75. package/dist/core/baseline.d.ts +7 -0
  76. package/dist/core/baseline.js +33 -0
  77. package/dist/core/config.d.ts +72 -0
  78. package/dist/core/config.js +236 -0
  79. package/dist/core/engine.d.ts +87 -0
  80. package/dist/core/engine.js +437 -0
  81. package/dist/core/finding.d.ts +40 -0
  82. package/dist/core/finding.js +141 -0
  83. package/dist/core/git.d.ts +3 -0
  84. package/dist/core/git.js +67 -0
  85. package/dist/core/paths.d.ts +7 -0
  86. package/dist/core/paths.js +104 -0
  87. package/dist/core/projectDetector.d.ts +17 -0
  88. package/dist/core/projectDetector.js +160 -0
  89. package/dist/core/scanPlanner.d.ts +11 -0
  90. package/dist/core/scanPlanner.js +47 -0
  91. package/dist/core/scoring.d.ts +8 -0
  92. package/dist/core/scoring.js +57 -0
  93. package/dist/core/toolRunner.d.ts +24 -0
  94. package/dist/core/toolRunner.js +130 -0
  95. package/dist/index.d.ts +7 -0
  96. package/dist/index.js +23 -0
  97. package/dist/mcp/server.d.ts +1 -0
  98. package/dist/mcp/server.js +141 -0
  99. package/dist/mcp/tools/explainFinding.d.ts +2 -0
  100. package/dist/mcp/tools/explainFinding.js +23 -0
  101. package/dist/mcp/tools/fixSafe.d.ts +2 -0
  102. package/dist/mcp/tools/fixSafe.js +15 -0
  103. package/dist/mcp/tools/getAgentPlan.d.ts +2 -0
  104. package/dist/mcp/tools/getAgentPlan.js +31 -0
  105. package/dist/mcp/tools/getReport.d.ts +2 -0
  106. package/dist/mcp/tools/getReport.js +26 -0
  107. package/dist/mcp/tools/index.d.ts +1 -0
  108. package/dist/mcp/tools/index.js +19 -0
  109. package/dist/mcp/tools/scanChanged.d.ts +2 -0
  110. package/dist/mcp/tools/scanChanged.js +23 -0
  111. package/dist/mcp/tools/scanFull.d.ts +2 -0
  112. package/dist/mcp/tools/scanFull.js +23 -0
  113. package/dist/mcp/tools/shared.d.ts +51 -0
  114. package/dist/mcp/tools/shared.js +126 -0
  115. package/dist/mcp/tools/verify.d.ts +2 -0
  116. package/dist/mcp/tools/verify.js +21 -0
  117. package/dist/reporters/agent.d.ts +3 -0
  118. package/dist/reporters/agent.js +48 -0
  119. package/dist/reporters/html.d.ts +2 -0
  120. package/dist/reporters/html.js +81 -0
  121. package/dist/reporters/json.d.ts +2 -0
  122. package/dist/reporters/json.js +18 -0
  123. package/dist/reporters/markdown.d.ts +2 -0
  124. package/dist/reporters/markdown.js +33 -0
  125. package/dist/reporters/sarif.d.ts +2 -0
  126. package/dist/reporters/sarif.js +38 -0
  127. package/dist/reporters/terminal.d.ts +2 -0
  128. package/dist/reporters/terminal.js +11 -0
  129. package/dist/rules/leftoverPatterns.d.ts +7 -0
  130. package/dist/rules/leftoverPatterns.js +10 -0
  131. package/dist/rules/refactorRules.d.ts +13 -0
  132. package/dist/rules/refactorRules.js +16 -0
  133. package/dist/rules/severityMap.d.ts +15 -0
  134. package/dist/rules/severityMap.js +33 -0
  135. package/package.json +72 -0
@@ -0,0 +1,7 @@
1
+ export declare const DEFAULT_EXCLUDES: string[];
2
+ export declare function pathExists(targetPath: string): Promise<boolean>;
3
+ export declare function ensureDir(targetPath: string): Promise<void>;
4
+ export declare function listProjectFiles(root: string, excludePatterns?: string[]): Promise<string[]>;
5
+ export declare function filterPaths(items: string[], includePatterns?: string[], excludePatterns?: string[]): string[];
6
+ export declare function readTextIfExists(filePath: string): Promise<string | undefined>;
7
+ export declare function normalizeToPosix(value: string): string;
@@ -0,0 +1,104 @@
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.DEFAULT_EXCLUDES = void 0;
7
+ exports.pathExists = pathExists;
8
+ exports.ensureDir = ensureDir;
9
+ exports.listProjectFiles = listProjectFiles;
10
+ exports.filterPaths = filterPaths;
11
+ exports.readTextIfExists = readTextIfExists;
12
+ exports.normalizeToPosix = normalizeToPosix;
13
+ const node_fs_1 = require("node:fs");
14
+ const node_path_1 = __importDefault(require("node:path"));
15
+ const minimatch_1 = require("minimatch");
16
+ exports.DEFAULT_EXCLUDES = [
17
+ "node_modules/**",
18
+ "**/node_modules/**",
19
+ "dist/**",
20
+ "**/dist/**",
21
+ "build/**",
22
+ ".venv/**",
23
+ "**/.venv/**",
24
+ "coverage/**",
25
+ ".next/**",
26
+ "vendor/**",
27
+ ".git/**",
28
+ "**/__pycache__/**",
29
+ "**/*.egg-info/**"
30
+ ];
31
+ async function pathExists(targetPath) {
32
+ try {
33
+ await node_fs_1.promises.access(targetPath);
34
+ return true;
35
+ }
36
+ catch {
37
+ return false;
38
+ }
39
+ }
40
+ async function ensureDir(targetPath) {
41
+ await node_fs_1.promises.mkdir(targetPath, { recursive: true });
42
+ }
43
+ function matchesAnyPath(patterns, relativePath) {
44
+ return patterns.some((matcher) => matcher.match(relativePath));
45
+ }
46
+ function shouldSkipDirectory(excludePatterns, relativePath) {
47
+ return matchesAnyPath(excludePatterns, relativePath) || matchesAnyPath(excludePatterns, `${relativePath}/__vibedoctor_probe__`);
48
+ }
49
+ async function walkDirectory(root, currentDir, files, excludePatterns) {
50
+ const entries = await node_fs_1.promises.readdir(currentDir, { withFileTypes: true });
51
+ for (const entry of entries) {
52
+ const absolutePath = node_path_1.default.join(currentDir, entry.name);
53
+ const relativePath = node_path_1.default.relative(root, absolutePath).split(node_path_1.default.sep).join("/");
54
+ if (entry.isDirectory()) {
55
+ if (!shouldSkipDirectory(excludePatterns, relativePath)) {
56
+ await walkDirectory(root, absolutePath, files, excludePatterns);
57
+ }
58
+ continue;
59
+ }
60
+ files.push(relativePath);
61
+ }
62
+ }
63
+ async function readGitignoreExcludes(root) {
64
+ const gitignorePath = node_path_1.default.join(root, '.gitignore');
65
+ if (!(await pathExists(gitignorePath)))
66
+ return [];
67
+ try {
68
+ const content = await node_fs_1.promises.readFile(gitignorePath, 'utf8');
69
+ return content
70
+ .split(/\r?\n/)
71
+ .map((line) => line.trim())
72
+ .filter((line) => line && !line.startsWith('#') && !line.startsWith('!'))
73
+ .map((line) => {
74
+ let p = line.replace(/^\//, '');
75
+ if (p.endsWith('/'))
76
+ p += '**';
77
+ return p;
78
+ });
79
+ }
80
+ catch {
81
+ return [];
82
+ }
83
+ }
84
+ async function listProjectFiles(root, excludePatterns = exports.DEFAULT_EXCLUDES) {
85
+ const gitExcludes = await readGitignoreExcludes(root);
86
+ const combined = [...excludePatterns, ...gitExcludes];
87
+ const items = [];
88
+ await walkDirectory(root, root, items, combined.map((pattern) => new minimatch_1.Minimatch(pattern, { dot: true })));
89
+ return items;
90
+ }
91
+ function filterPaths(items, includePatterns = ["**/*"], excludePatterns = exports.DEFAULT_EXCLUDES) {
92
+ const includes = includePatterns.map((pattern) => new minimatch_1.Minimatch(pattern, { dot: true }));
93
+ const excludes = excludePatterns.map((pattern) => new minimatch_1.Minimatch(pattern, { dot: true }));
94
+ return items.filter((item) => matchesAnyPath(includes, item) && !matchesAnyPath(excludes, item));
95
+ }
96
+ async function readTextIfExists(filePath) {
97
+ if (!(await pathExists(filePath))) {
98
+ return undefined;
99
+ }
100
+ return node_fs_1.promises.readFile(filePath, "utf8");
101
+ }
102
+ function normalizeToPosix(value) {
103
+ return value.split(node_path_1.default.sep).join("/");
104
+ }
@@ -0,0 +1,17 @@
1
+ export type ProjectLanguage = "python" | "javascript" | "typescript";
2
+ export type PackageManager = "npm" | "pnpm" | "yarn" | "bun" | "pip" | "uv" | "poetry" | "pdm";
3
+ export type ProjectContext = {
4
+ root: string;
5
+ languages: ProjectLanguage[];
6
+ packageManagers: PackageManager[];
7
+ hasGit: boolean;
8
+ changedFiles: string[];
9
+ configFiles: string[];
10
+ lockfiles: string[];
11
+ testCommands: string[];
12
+ toolsAvailable: Record<string, boolean>;
13
+ frameworkHints: string[];
14
+ entryFiles: string[];
15
+ projectFiles: string[];
16
+ };
17
+ export declare function detectProject(root: string): Promise<ProjectContext>;
@@ -0,0 +1,160 @@
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.detectProject = detectProject;
7
+ const node_fs_1 = require("node:fs");
8
+ const node_path_1 = __importDefault(require("node:path"));
9
+ const node_child_process_1 = require("node:child_process");
10
+ const node_util_1 = require("node:util");
11
+ const git_1 = require("./git");
12
+ const paths_1 = require("./paths");
13
+ const toolRunner_1 = require("./toolRunner");
14
+ const execFileAsync = (0, node_util_1.promisify)(node_child_process_1.execFile);
15
+ const KNOWN_CONFIG_FILES = [
16
+ "package.json",
17
+ "tsconfig.json",
18
+ "biome.json",
19
+ ".eslintrc",
20
+ ".eslintrc.js",
21
+ ".eslintrc.cjs",
22
+ ".eslintrc.json",
23
+ "jest.config.js",
24
+ "jest.config.cjs",
25
+ "jest.config.ts",
26
+ "vitest.config.ts",
27
+ "vitest.config.js",
28
+ "pyproject.toml",
29
+ "requirements.txt",
30
+ "uv.lock",
31
+ "poetry.lock",
32
+ "pdm.lock",
33
+ "pytest.ini",
34
+ "ruff.toml",
35
+ "mypy.ini",
36
+ "pyrightconfig.json"
37
+ ];
38
+ const KNOWN_LOCKFILES = ["pnpm-lock.yaml", "package-lock.json", "yarn.lock", "bun.lockb", "uv.lock", "poetry.lock", "pdm.lock"];
39
+ const KNOWN_TOOLS = ["ruff", "biome", "knip", "vulture", "gitleaks", "osv-scanner", "semgrep", "tsc", "pyright", "eslint", "jest", "vitest", "coverage"];
40
+ async function commandExists(command, root) {
41
+ const locator = process.platform === "win32" ? "where" : "which";
42
+ try {
43
+ await execFileAsync(locator, [command], { cwd: root, env: (0, toolRunner_1.buildCommandEnv)(root, undefined), windowsHide: true });
44
+ return true;
45
+ }
46
+ catch {
47
+ return false;
48
+ }
49
+ }
50
+ function packageScriptCommand(packageManager, name) {
51
+ if (packageManager === "pnpm") {
52
+ return name === "test" ? "pnpm test" : `pnpm run ${name}`;
53
+ }
54
+ if (packageManager === "yarn") {
55
+ return name === "test" ? "yarn test" : `yarn run ${name}`;
56
+ }
57
+ if (packageManager === "bun") {
58
+ return `bun run ${name}`;
59
+ }
60
+ return name === "test" ? "npm test" : `npm run ${name}`;
61
+ }
62
+ function pythonTestCommand(packageManagers) {
63
+ if (packageManagers.has("uv")) {
64
+ return "uv run pytest";
65
+ }
66
+ if (packageManagers.has("poetry")) {
67
+ return "poetry run pytest";
68
+ }
69
+ if (packageManagers.has("pdm")) {
70
+ return "pdm run pytest";
71
+ }
72
+ return "pytest";
73
+ }
74
+ async function readPackageMetadata(root, packageManager) {
75
+ const packagePath = node_path_1.default.join(root, "package.json");
76
+ if (!(await (0, paths_1.pathExists)(packagePath))) {
77
+ return { testCommands: [], frameworkHints: [] };
78
+ }
79
+ const pkg = JSON.parse(await node_fs_1.promises.readFile(packagePath, "utf8"));
80
+ const testCommands = [];
81
+ for (const [name, value] of Object.entries(pkg.scripts ?? {})) {
82
+ if (/test|vitest|jest|pytest/i.test(name) || /vitest|jest|pytest/i.test(value)) {
83
+ testCommands.push(packageScriptCommand(packageManager, name));
84
+ }
85
+ }
86
+ const frameworkHints = [];
87
+ const deps = { ...(pkg.dependencies ?? {}), ...(pkg.devDependencies ?? {}) };
88
+ if (deps.next) {
89
+ frameworkHints.push("nextjs");
90
+ }
91
+ if (deps.react) {
92
+ frameworkHints.push("react");
93
+ }
94
+ if (deps.express) {
95
+ frameworkHints.push("express");
96
+ }
97
+ if (deps.vitest) {
98
+ frameworkHints.push("vitest");
99
+ }
100
+ if (deps.jest) {
101
+ frameworkHints.push("jest");
102
+ }
103
+ if (pkg.workspaces) {
104
+ frameworkHints.push("monorepo");
105
+ }
106
+ return { testCommands, frameworkHints };
107
+ }
108
+ async function detectProject(root) {
109
+ const projectFiles = await (0, paths_1.listProjectFiles)(root);
110
+ const fileSet = new Set(projectFiles);
111
+ const languages = new Set();
112
+ const frameworkHints = new Set();
113
+ for (const file of projectFiles) {
114
+ if (file.endsWith(".py")) {
115
+ languages.add("python");
116
+ }
117
+ if (file.endsWith(".ts") || file.endsWith(".tsx")) {
118
+ languages.add("typescript");
119
+ }
120
+ if (file.endsWith(".js") || file.endsWith(".jsx")) {
121
+ languages.add("javascript");
122
+ }
123
+ if (/manage\.py|django/i.test(file)) {
124
+ frameworkHints.add("django");
125
+ }
126
+ if (/fastapi|flask/i.test(file)) {
127
+ frameworkHints.add("python-web");
128
+ }
129
+ }
130
+ const packageManagers = new Set();
131
+ if (fileSet.has("package.json")) {
132
+ packageManagers.add(fileSet.has("pnpm-lock.yaml") ? "pnpm" : fileSet.has("yarn.lock") ? "yarn" : fileSet.has("bun.lockb") ? "bun" : "npm");
133
+ }
134
+ if (fileSet.has("requirements.txt") || fileSet.has("pyproject.toml")) {
135
+ packageManagers.add(fileSet.has("uv.lock") ? "uv" : fileSet.has("poetry.lock") ? "poetry" : fileSet.has("pdm.lock") ? "pdm" : "pip");
136
+ }
137
+ const packageMetadata = await readPackageMetadata(root, ["npm", "pnpm", "yarn", "bun"].find((manager) => packageManagers.has(manager)));
138
+ for (const hint of packageMetadata.frameworkHints) {
139
+ frameworkHints.add(hint);
140
+ }
141
+ if (fileSet.has("pytest.ini") || projectFiles.some((file) => /(^|\/)tests?\//.test(file) && file.endsWith(".py"))) {
142
+ packageMetadata.testCommands.push(pythonTestCommand(packageManagers));
143
+ }
144
+ const toolPairs = await Promise.all(KNOWN_TOOLS.map(async (tool) => [tool, await commandExists(tool, root)]));
145
+ const entryFiles = projectFiles.filter((file) => /(^|\/)(main|index|app|server|cli)\.(ts|tsx|js|jsx|py)$/.test(file) || file === "package.json");
146
+ return {
147
+ root,
148
+ languages: Array.from(languages).sort(),
149
+ packageManagers: Array.from(packageManagers).sort(),
150
+ hasGit: await (0, git_1.isGitRepo)(root),
151
+ changedFiles: await (0, git_1.getChangedFiles)(root),
152
+ configFiles: KNOWN_CONFIG_FILES.filter((fileName) => fileSet.has(fileName)),
153
+ lockfiles: KNOWN_LOCKFILES.filter((fileName) => fileSet.has(fileName)),
154
+ testCommands: Array.from(new Set(packageMetadata.testCommands)),
155
+ toolsAvailable: Object.fromEntries(toolPairs),
156
+ frameworkHints: Array.from(frameworkHints).sort(),
157
+ entryFiles,
158
+ projectFiles
159
+ };
160
+ }
@@ -0,0 +1,11 @@
1
+ import type { ToolAdapter } from "../adapters/shared";
2
+ import type { VibeDoctorConfig } from "./config";
3
+ import type { ProjectContext } from "./projectDetector";
4
+ export type ScanMode = "default" | "changed" | "quick" | "full";
5
+ export type ScanPlan = {
6
+ mode: ScanMode;
7
+ adapterIds: string[];
8
+ changedOnly: boolean;
9
+ outputFull: boolean;
10
+ };
11
+ export declare function createScanPlan(project: ProjectContext, config: VibeDoctorConfig, adapters: ToolAdapter[], mode: ScanMode): Promise<ScanPlan>;
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createScanPlan = createScanPlan;
4
+ async function createScanPlan(project, config, adapters, mode) {
5
+ const selected = [];
6
+ const quickAdapterIds = new Set([
7
+ "ruff",
8
+ "biome",
9
+ "tsc",
10
+ "pyright",
11
+ "gitleaks",
12
+ "osv-scanner",
13
+ "custom-leftovers"
14
+ ]);
15
+ for (const adapter of adapters) {
16
+ if (adapter.category === "security" && !config.checks.security.enabled) {
17
+ continue;
18
+ }
19
+ if (adapter.category === "correctness" && !config.checks.correctness.enabled) {
20
+ continue;
21
+ }
22
+ if (adapter.category === "dead_code" && !config.checks.deadCode.enabled) {
23
+ continue;
24
+ }
25
+ if (adapter.category === "leftovers" && !config.checks.leftovers.enabled) {
26
+ continue;
27
+ }
28
+ if (adapter.category === "refactor_readiness" && !config.checks.refactorReadiness.enabled) {
29
+ continue;
30
+ }
31
+ if (adapter.category === "dependencies" && !config.checks.dependencies.enabled) {
32
+ continue;
33
+ }
34
+ if (mode === "quick" && !quickAdapterIds.has(adapter.id)) {
35
+ continue;
36
+ }
37
+ if (await adapter.detect(project, config)) {
38
+ selected.push(adapter.id);
39
+ }
40
+ }
41
+ return {
42
+ mode,
43
+ adapterIds: selected,
44
+ changedOnly: mode === "changed",
45
+ outputFull: mode === "full"
46
+ };
47
+ }
@@ -0,0 +1,8 @@
1
+ import type { Finding, FindingCategory } from "./finding";
2
+ export type ScoreBreakdown = {
3
+ overall: number;
4
+ categories: Record<FindingCategory, number>;
5
+ penalties: Record<FindingCategory, number>;
6
+ };
7
+ export declare function scoreFinding(finding: Finding): number;
8
+ export declare function buildScore(findings: Finding[]): ScoreBreakdown;
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.scoreFinding = scoreFinding;
4
+ exports.buildScore = buildScore;
5
+ const severityMap_1 = require("../rules/severityMap");
6
+ const defaultCategoryScore = {
7
+ security: 100,
8
+ correctness: 100,
9
+ dead_code: 100,
10
+ leftovers: 100,
11
+ maintainability: 100,
12
+ dependencies: 100,
13
+ tests: 100,
14
+ efficiency: 100,
15
+ refactor_readiness: 100
16
+ };
17
+ const defaultPenalties = {
18
+ security: 0,
19
+ correctness: 0,
20
+ dead_code: 0,
21
+ leftovers: 0,
22
+ maintainability: 0,
23
+ dependencies: 0,
24
+ tests: 0,
25
+ efficiency: 0,
26
+ refactor_readiness: 0
27
+ };
28
+ function scoreFinding(finding) {
29
+ const issueMultiplier = finding.isNew ? 1.5 : 0.3;
30
+ const confidence = severityMap_1.confidenceMultiplier[finding.confidence];
31
+ const autofix = finding.safeToAutofix ? 0.5 : 1;
32
+ const fileWeight = finding.file && (/\.test\./.test(finding.file) || /(^|\/)tests?\//.test(finding.file)) ? 0.6 : 1.2;
33
+ return Number((severityMap_1.severityPenalty[finding.severity] * issueMultiplier * confidence * autofix * fileWeight).toFixed(2));
34
+ }
35
+ function buildScore(findings) {
36
+ const penalties = { ...defaultPenalties };
37
+ for (const finding of findings) {
38
+ // scoreImpact was historically always set to 0 by every adapter/custom (see 20+ sites).
39
+ // It only affected dedupe max() in practice. Use the computed scoreFinding for penalties
40
+ // (severity, confidence, newness, autofix, test-file weight). This removes the legacy scoreImpact handling.
41
+ penalties[finding.category] += scoreFinding(finding);
42
+ }
43
+ const categories = { ...defaultCategoryScore };
44
+ for (const key of Object.keys(categories)) {
45
+ categories[key] = Math.max(0, Number((100 - penalties[key]).toFixed(2)));
46
+ }
47
+ const overall = Math.round(categories.security * severityMap_1.categoryWeights.security +
48
+ categories.correctness * severityMap_1.categoryWeights.correctness +
49
+ categories.tests * severityMap_1.categoryWeights.tests +
50
+ categories.dependencies * severityMap_1.categoryWeights.dependencies +
51
+ categories.maintainability * severityMap_1.categoryWeights.maintainability +
52
+ categories.dead_code * severityMap_1.categoryWeights.dead_code +
53
+ categories.leftovers * severityMap_1.categoryWeights.leftovers +
54
+ categories.refactor_readiness * severityMap_1.categoryWeights.refactor_readiness +
55
+ categories.efficiency * severityMap_1.categoryWeights.efficiency);
56
+ return { overall, categories, penalties };
57
+ }
@@ -0,0 +1,24 @@
1
+ export type CommandSpec = {
2
+ cmd: string;
3
+ args: string[];
4
+ cwd?: string;
5
+ timeoutMs?: number;
6
+ env?: NodeJS.ProcessEnv;
7
+ };
8
+ export type ToolResult = {
9
+ command: string;
10
+ stdout: string;
11
+ stderr: string;
12
+ exitCode: number | null;
13
+ durationMs: number;
14
+ status: "ok" | "error" | "skipped" | "timeout";
15
+ installHint?: string;
16
+ };
17
+ export declare function getLocalToolSearchPaths(cwd: string | undefined): string[];
18
+ export declare function buildCommandEnv(cwd: string | undefined, overrides: NodeJS.ProcessEnv | undefined): NodeJS.ProcessEnv;
19
+ export declare function runCommand(spec: CommandSpec, installHint?: string): Promise<ToolResult>;
20
+ export declare function runCommands(commands: Array<{
21
+ id: string;
22
+ command: CommandSpec;
23
+ installHint?: string;
24
+ }>): Promise<Record<string, ToolResult>>;
@@ -0,0 +1,130 @@
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.getLocalToolSearchPaths = getLocalToolSearchPaths;
7
+ exports.buildCommandEnv = buildCommandEnv;
8
+ exports.runCommand = runCommand;
9
+ exports.runCommands = runCommands;
10
+ const node_path_1 = __importDefault(require("node:path"));
11
+ const node_child_process_1 = require("node:child_process");
12
+ const LOCAL_TOOL_PATHS = [
13
+ ["node_modules", ".bin"],
14
+ [".venv", "Scripts"],
15
+ [".venv", "bin"],
16
+ ["venv", "Scripts"],
17
+ ["venv", "bin"]
18
+ ];
19
+ function ancestorDirs(startDir) {
20
+ if (!startDir) {
21
+ return [];
22
+ }
23
+ const dirs = [];
24
+ let current = node_path_1.default.resolve(startDir);
25
+ while (true) {
26
+ dirs.push(current);
27
+ const parent = node_path_1.default.dirname(current);
28
+ if (parent === current) {
29
+ return dirs;
30
+ }
31
+ current = parent;
32
+ }
33
+ }
34
+ function getPathKey(env) {
35
+ return Object.keys(env).find((key) => key.toLowerCase() === "path") ?? "PATH";
36
+ }
37
+ function getLocalToolSearchPaths(cwd) {
38
+ const paths = ancestorDirs(cwd).flatMap((dir) => LOCAL_TOOL_PATHS.map((segments) => node_path_1.default.join(dir, ...segments)));
39
+ return Array.from(new Set(paths));
40
+ }
41
+ function buildCommandEnv(cwd, overrides) {
42
+ const env = { ...process.env, ...overrides };
43
+ const pathKey = getPathKey(env);
44
+ const existingPath = env[pathKey];
45
+ env[pathKey] = [...getLocalToolSearchPaths(cwd), existingPath].filter(Boolean).join(node_path_1.default.delimiter);
46
+ return env;
47
+ }
48
+ async function runCommand(spec, installHint) {
49
+ const startedAt = Date.now();
50
+ const useShell = process.platform === "win32" &&
51
+ !node_path_1.default.isAbsolute(spec.cmd) &&
52
+ node_path_1.default.extname(spec.cmd).length === 0;
53
+ return new Promise((resolve) => {
54
+ const child = (0, node_child_process_1.spawn)(spec.cmd, spec.args, {
55
+ cwd: spec.cwd,
56
+ env: buildCommandEnv(spec.cwd, spec.env),
57
+ shell: useShell,
58
+ windowsHide: true
59
+ });
60
+ let stdout = "";
61
+ let stderr = "";
62
+ let settled = false;
63
+ let timeoutHandle;
64
+ child.stdout.on("data", (chunk) => {
65
+ stdout += chunk.toString();
66
+ });
67
+ child.stderr.on("data", (chunk) => {
68
+ stderr += chunk.toString();
69
+ });
70
+ child.on("error", (error) => {
71
+ if (settled) {
72
+ return;
73
+ }
74
+ settled = true;
75
+ resolve({
76
+ command: [spec.cmd, ...spec.args].join(" "),
77
+ stdout,
78
+ stderr: error.message,
79
+ exitCode: null,
80
+ durationMs: Date.now() - startedAt,
81
+ status: /ENOENT|not recognized/i.test(error.message) ? "skipped" : "error",
82
+ installHint
83
+ });
84
+ });
85
+ child.on("close", (exitCode) => {
86
+ if (settled) {
87
+ return;
88
+ }
89
+ settled = true;
90
+ if (timeoutHandle) {
91
+ clearTimeout(timeoutHandle);
92
+ }
93
+ resolve({
94
+ command: [spec.cmd, ...spec.args].join(" "),
95
+ stdout,
96
+ stderr,
97
+ exitCode,
98
+ durationMs: Date.now() - startedAt,
99
+ status: exitCode === 0
100
+ ? "ok"
101
+ : /not recognized|not found|is not installed|no such file/i.test(stderr)
102
+ ? "skipped"
103
+ : "error",
104
+ installHint
105
+ });
106
+ });
107
+ if (spec.timeoutMs) {
108
+ timeoutHandle = setTimeout(() => {
109
+ if (settled) {
110
+ return;
111
+ }
112
+ settled = true;
113
+ child.kill("SIGTERM");
114
+ resolve({
115
+ command: [spec.cmd, ...spec.args].join(" "),
116
+ stdout,
117
+ stderr,
118
+ exitCode: null,
119
+ durationMs: Date.now() - startedAt,
120
+ status: "timeout",
121
+ installHint
122
+ });
123
+ }, spec.timeoutMs);
124
+ }
125
+ });
126
+ }
127
+ async function runCommands(commands) {
128
+ const pairs = await Promise.all(commands.map(async ({ id, command, installHint }) => [id, await runCommand(command, installHint)]));
129
+ return Object.fromEntries(pairs);
130
+ }
@@ -0,0 +1,7 @@
1
+ export * from "./agentPack/generateAgentPack";
2
+ export * from "./agentPack/policy";
3
+ export * from "./core/config";
4
+ export * from "./core/engine";
5
+ export * from "./core/finding";
6
+ export * from "./core/projectDetector";
7
+ export * from "./mcp/server";
package/dist/index.js ADDED
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./agentPack/generateAgentPack"), exports);
18
+ __exportStar(require("./agentPack/policy"), exports);
19
+ __exportStar(require("./core/config"), exports);
20
+ __exportStar(require("./core/engine"), exports);
21
+ __exportStar(require("./core/finding"), exports);
22
+ __exportStar(require("./core/projectDetector"), exports);
23
+ __exportStar(require("./mcp/server"), exports);
@@ -0,0 +1 @@
1
+ export declare function runMcpServer(root: string): Promise<void>;