pi-lens 2.2.9 โ 3.0.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/CHANGELOG.md +198 -0
- package/README.md +709 -519
- package/clients/__tests__/file-time.test.js +216 -0
- package/clients/__tests__/file-time.test.ts +276 -0
- package/clients/__tests__/format-service.test.js +245 -0
- package/clients/__tests__/format-service.test.ts +339 -0
- package/clients/__tests__/formatters.test.js +271 -0
- package/clients/__tests__/formatters.test.ts +401 -0
- package/clients/amain-types.js +164 -0
- package/clients/amain-types.ts +165 -0
- package/clients/architect-client.js +56 -12
- package/clients/architect-client.ts +81 -16
- package/clients/ast-grep-client.js +2 -2
- package/clients/ast-grep-client.ts +14 -39
- package/clients/ast-grep-parser.ts +1 -1
- package/clients/ast-grep-rule-manager.js +8 -0
- package/clients/ast-grep-rule-manager.ts +10 -1
- package/clients/ast-grep-types.js +9 -0
- package/clients/ast-grep-types.ts +106 -0
- package/clients/auto-loop.js +10 -0
- package/clients/auto-loop.ts +14 -1
- package/clients/biome-client.js +81 -19
- package/clients/biome-client.ts +103 -22
- package/clients/bus/bus.js +191 -0
- package/clients/bus/bus.ts +251 -0
- package/clients/bus/events.js +214 -0
- package/clients/bus/events.ts +279 -0
- package/clients/bus/index.js +8 -0
- package/clients/bus/index.ts +9 -0
- package/clients/bus/integration.js +158 -0
- package/clients/bus/integration.ts +214 -0
- package/clients/complexity-client.js +13 -7
- package/clients/complexity-client.ts +13 -7
- package/clients/config-validator.js +465 -0
- package/clients/config-validator.ts +558 -0
- package/clients/dependency-checker.js +4 -10
- package/clients/dependency-checker.ts +4 -10
- package/clients/dispatch/__tests__/autofix-integration.test.js +245 -0
- package/clients/dispatch/__tests__/autofix-integration.test.ts +300 -0
- package/clients/dispatch/__tests__/runner-registration.test.js +236 -0
- package/clients/dispatch/__tests__/runner-registration.test.ts +282 -0
- package/clients/dispatch/bus-dispatcher.js +177 -0
- package/clients/dispatch/bus-dispatcher.ts +251 -0
- package/clients/dispatch/dispatcher.edge.test.js +82 -0
- package/clients/dispatch/dispatcher.edge.test.ts +100 -0
- package/clients/dispatch/dispatcher.format.test.js +46 -0
- package/clients/dispatch/dispatcher.format.test.ts +58 -0
- package/clients/dispatch/dispatcher.inline.test.js +74 -0
- package/clients/dispatch/dispatcher.inline.test.ts +93 -0
- package/clients/dispatch/dispatcher.js +19 -53
- package/clients/dispatch/dispatcher.ts +20 -67
- package/clients/dispatch/plan.js +9 -4
- package/clients/dispatch/plan.ts +9 -4
- package/clients/dispatch/runners/architect.js +21 -7
- package/clients/dispatch/runners/architect.test.js +138 -0
- package/clients/dispatch/runners/architect.test.ts +162 -0
- package/clients/dispatch/runners/architect.ts +22 -7
- package/clients/dispatch/runners/ast-grep-napi.js +462 -0
- package/clients/dispatch/runners/ast-grep-napi.test.js +111 -0
- package/clients/dispatch/runners/ast-grep-napi.test.ts +133 -0
- package/clients/dispatch/runners/ast-grep-napi.ts +506 -0
- package/clients/dispatch/runners/ast-grep.js +62 -19
- package/clients/dispatch/runners/ast-grep.ts +70 -18
- package/clients/dispatch/runners/biome.js +29 -53
- package/clients/dispatch/runners/biome.ts +29 -63
- package/clients/dispatch/runners/config-validation.js +67 -0
- package/clients/dispatch/runners/config-validation.ts +82 -0
- package/clients/dispatch/runners/go-vet.js +4 -28
- package/clients/dispatch/runners/go-vet.ts +4 -32
- package/clients/dispatch/runners/index.js +30 -10
- package/clients/dispatch/runners/index.ts +30 -10
- package/clients/dispatch/runners/oxlint.js +141 -0
- package/clients/dispatch/runners/oxlint.test.js +230 -0
- package/clients/dispatch/runners/oxlint.test.ts +303 -0
- package/clients/dispatch/runners/oxlint.ts +175 -0
- package/clients/dispatch/runners/pyright.js +40 -70
- package/clients/dispatch/runners/pyright.test.js +16 -2
- package/clients/dispatch/runners/pyright.test.ts +14 -2
- package/clients/dispatch/runners/pyright.ts +48 -91
- package/clients/dispatch/runners/python-slop.js +97 -0
- package/clients/dispatch/runners/python-slop.test.js +203 -0
- package/clients/dispatch/runners/python-slop.test.ts +298 -0
- package/clients/dispatch/runners/python-slop.ts +124 -0
- package/clients/dispatch/runners/ruff.js +18 -71
- package/clients/dispatch/runners/ruff.ts +19 -79
- package/clients/dispatch/runners/rust-clippy.js +28 -32
- package/clients/dispatch/runners/rust-clippy.ts +29 -31
- package/clients/dispatch/runners/scan_codebase.test.js +89 -0
- package/clients/dispatch/runners/scan_codebase.test.ts +105 -0
- package/clients/dispatch/runners/shellcheck.js +147 -0
- package/clients/dispatch/runners/shellcheck.test.js +98 -0
- package/clients/dispatch/runners/shellcheck.test.ts +129 -0
- package/clients/dispatch/runners/shellcheck.ts +188 -0
- package/clients/dispatch/runners/similarity.js +230 -0
- package/clients/dispatch/runners/similarity.ts +339 -0
- package/clients/dispatch/runners/spellcheck.js +106 -0
- package/clients/dispatch/runners/spellcheck.test.js +158 -0
- package/clients/dispatch/runners/spellcheck.test.ts +214 -0
- package/clients/dispatch/runners/spellcheck.ts +136 -0
- package/clients/dispatch/runners/tree-sitter.js +107 -0
- package/clients/dispatch/runners/tree-sitter.ts +135 -0
- package/clients/dispatch/runners/ts-lsp.js +104 -33
- package/clients/dispatch/runners/ts-lsp.ts +120 -38
- package/clients/dispatch/runners/ts-slop.js +113 -0
- package/clients/dispatch/runners/ts-slop.test.js +180 -0
- package/clients/dispatch/runners/ts-slop.test.ts +230 -0
- package/clients/dispatch/runners/ts-slop.ts +142 -0
- package/clients/dispatch/runners/utils/diagnostic-parsers.js +134 -0
- package/clients/dispatch/runners/utils/diagnostic-parsers.ts +186 -0
- package/clients/dispatch/runners/utils/runner-helpers.js +115 -0
- package/clients/dispatch/runners/utils/runner-helpers.ts +167 -0
- package/clients/dispatch/runners/utils.js +2 -4
- package/clients/dispatch/runners/utils.ts +2 -4
- package/clients/dispatch/types.ts +1 -1
- package/clients/dispatch/utils/format-utils.js +49 -0
- package/clients/dispatch/utils/format-utils.ts +60 -0
- package/clients/dogfood.test.js +201 -0
- package/clients/dogfood.test.ts +269 -0
- package/clients/file-time.js +152 -0
- package/clients/file-time.ts +208 -0
- package/clients/file-utils.js +40 -0
- package/clients/file-utils.ts +44 -0
- package/clients/fix-scanners.js +10 -20
- package/clients/fix-scanners.ts +10 -22
- package/clients/format-service.js +172 -0
- package/clients/format-service.ts +254 -0
- package/clients/formatters.js +435 -0
- package/clients/formatters.ts +508 -0
- package/clients/go-client.js +5 -14
- package/clients/go-client.ts +5 -13
- package/clients/installer/index.js +356 -0
- package/clients/installer/index.ts +426 -0
- package/clients/jscpd-client.js +11 -9
- package/clients/jscpd-client.ts +12 -8
- package/clients/knip-client.js +3 -7
- package/clients/knip-client.ts +3 -6
- package/clients/lsp/__tests__/client.test.js +325 -0
- package/clients/lsp/__tests__/client.test.ts +434 -0
- package/clients/lsp/__tests__/config.test.js +166 -0
- package/clients/lsp/__tests__/config.test.ts +209 -0
- package/clients/lsp/__tests__/error-recovery.test.js +213 -0
- package/clients/lsp/__tests__/error-recovery.test.ts +279 -0
- package/clients/lsp/__tests__/integration.test.js +127 -0
- package/clients/lsp/__tests__/integration.test.ts +160 -0
- package/clients/lsp/__tests__/launch.test.js +260 -0
- package/clients/lsp/__tests__/launch.test.ts +329 -0
- package/clients/lsp/__tests__/server.test.js +259 -0
- package/clients/lsp/__tests__/server.test.ts +332 -0
- package/clients/lsp/__tests__/service.test.js +417 -0
- package/clients/lsp/__tests__/service.test.ts +499 -0
- package/clients/lsp/client.js +235 -0
- package/clients/lsp/client.ts +328 -0
- package/clients/lsp/config.js +115 -0
- package/clients/lsp/config.ts +149 -0
- package/clients/lsp/index.js +222 -0
- package/clients/lsp/index.ts +280 -0
- package/clients/lsp/installer/index.js +391 -0
- package/clients/lsp/interactive-install.js +210 -0
- package/clients/lsp/interactive-install.ts +251 -0
- package/clients/lsp/language.js +170 -0
- package/clients/lsp/language.ts +216 -0
- package/clients/lsp/launch.js +174 -0
- package/clients/lsp/launch.ts +240 -0
- package/clients/lsp/lsp/launch.js +116 -0
- package/clients/lsp/lsp/server.js +532 -0
- package/clients/lsp/lsp-index.js +10 -0
- package/clients/lsp/lsp-index.ts +11 -0
- package/clients/lsp/path-utils.js +48 -0
- package/clients/lsp/path-utils.ts +52 -0
- package/clients/lsp/server.js +615 -0
- package/clients/lsp/server.ts +800 -0
- package/clients/lsp/test-py-spawn/requirements.txt +1 -0
- package/clients/lsp/test-py-spawn/test.py +3 -0
- package/clients/lsp/test-py-svc/requirements.txt +1 -0
- package/clients/lsp/test-py-svc/test.py +3 -0
- package/clients/lsp/test-python-project/requirements.txt +1 -0
- package/clients/lsp/test-python-project/test.py +5 -0
- package/clients/metrics-history.js +2 -2
- package/clients/metrics-history.ts +2 -2
- package/clients/production-readiness.js +522 -0
- package/clients/production-readiness.ts +556 -0
- package/clients/project-index.js +255 -0
- package/clients/project-index.ts +383 -0
- package/clients/project-metadata.js +531 -0
- package/clients/project-metadata.ts +624 -0
- package/clients/ruff-client.js +56 -16
- package/clients/ruff-client.ts +72 -15
- package/clients/runner-tracker.js +152 -0
- package/clients/runner-tracker.ts +213 -0
- package/clients/rust-client.js +4 -11
- package/clients/rust-client.ts +5 -11
- package/clients/safe-spawn.js +96 -0
- package/clients/safe-spawn.ts +128 -0
- package/clients/scan-architectural-debt.js +3 -6
- package/clients/scan-architectural-debt.ts +3 -6
- package/clients/scan-utils.js +5 -20
- package/clients/scan-utils.ts +5 -29
- package/clients/secrets-scanner.js +3 -17
- package/clients/secrets-scanner.ts +4 -20
- package/clients/services/__tests__/effect-integration.test.js +86 -0
- package/clients/services/__tests__/effect-integration.test.ts +111 -0
- package/clients/services/effect-integration.js +194 -0
- package/clients/services/effect-integration.ts +268 -0
- package/clients/services/index.js +7 -0
- package/clients/services/index.ts +8 -0
- package/clients/services/runner-service.js +105 -0
- package/clients/services/runner-service.ts +179 -0
- package/clients/sg-runner.js +87 -13
- package/clients/sg-runner.ts +97 -13
- package/clients/state-matrix.js +160 -0
- package/clients/state-matrix.ts +202 -0
- package/clients/subprocess-client.js +10 -9
- package/clients/subprocess-client.ts +10 -8
- package/clients/test-runner-client.js +3 -7
- package/clients/test-runner-client.ts +3 -6
- package/clients/tool-availability.js +4 -10
- package/clients/tool-availability.ts +4 -9
- package/clients/tree-sitter-client.js +564 -0
- package/clients/tree-sitter-client.ts +797 -0
- package/clients/tree-sitter-query-loader.js +355 -0
- package/clients/tree-sitter-query-loader.ts +425 -0
- package/clients/type-coverage-client.js +3 -7
- package/clients/type-coverage-client.ts +3 -6
- package/clients/typescript-client.codefix.test.js +157 -0
- package/clients/typescript-client.codefix.test.ts +186 -0
- package/clients/typescript-client.js +43 -0
- package/clients/typescript-client.ts +98 -0
- package/commands/booboo.js +799 -219
- package/commands/booboo.ts +1004 -225
- package/commands/clients/ast-grep-client.js +250 -0
- package/commands/clients/ast-grep-parser.js +86 -0
- package/commands/clients/ast-grep-rule-manager.js +91 -0
- package/commands/clients/ast-grep-types.js +9 -0
- package/commands/clients/biome-client.js +380 -0
- package/commands/clients/complexity-client.js +667 -0
- package/commands/clients/file-kinds.js +177 -0
- package/commands/clients/file-utils.js +40 -0
- package/commands/clients/jscpd-client.js +169 -0
- package/commands/clients/knip-client.js +211 -0
- package/commands/clients/ruff-client.js +297 -0
- package/commands/clients/safe-spawn.js +88 -0
- package/commands/clients/scan-utils.js +83 -0
- package/commands/clients/sg-runner.js +190 -0
- package/commands/clients/types.js +11 -0
- package/commands/clients/typescript-client.js +505 -0
- package/commands/fix-from-booboo.js +398 -0
- package/commands/fix-from-booboo.ts +485 -0
- package/commands/fix-simplified.js +618 -0
- package/commands/fix-simplified.ts +768 -0
- package/commands/rate.js +10 -14
- package/commands/rate.ts +9 -16
- package/default-architect.yaml +59 -15
- package/index.ts +342 -429
- package/package.json +16 -3
- package/rules/ast-grep-rules/rules/empty-catch.yml +38 -13
- package/rules/ast-grep-rules/rules/no-array-constructor.yml +1 -0
- package/rules/ast-grep-rules/rules/no-debugger.yml +2 -0
- package/rules/python-slop-rules/.sgconfig.yml +4 -0
- package/rules/python-slop-rules/rules/slop-rules.yml +647 -0
- package/rules/tree-sitter-queries/python/bare-except.yml +54 -0
- package/rules/tree-sitter-queries/python/eval-exec.yml +50 -0
- package/rules/tree-sitter-queries/python/is-vs-equals.yml +60 -0
- package/rules/tree-sitter-queries/python/mutable-default-arg.yml +57 -0
- package/rules/tree-sitter-queries/python/unreachable-except.yml +60 -0
- package/rules/tree-sitter-queries/python/wildcard-import.yml +46 -0
- package/rules/tree-sitter-queries/tsx/dangerously-set-inner-html.yml +63 -0
- package/rules/tree-sitter-queries/typescript/await-in-loop.yml +56 -0
- package/rules/tree-sitter-queries/typescript/console-statement.yml +47 -0
- package/rules/tree-sitter-queries/typescript/debugger.yml +47 -0
- package/rules/tree-sitter-queries/typescript/deep-nesting.yml +117 -0
- package/rules/tree-sitter-queries/typescript/deep-promise-chain.yml +73 -0
- package/rules/tree-sitter-queries/typescript/empty-catch.yml +64 -0
- package/rules/tree-sitter-queries/typescript/eval.yml +48 -0
- package/rules/tree-sitter-queries/typescript/hardcoded-secrets.yml +78 -0
- package/rules/tree-sitter-queries/typescript/long-parameter-list.yml +62 -0
- package/rules/tree-sitter-queries/typescript/mixed-async-styles.yml +49 -0
- package/rules/tree-sitter-queries/typescript/nested-ternary.yml +45 -0
- package/rules/ts-slop-rules/.sgconfig.yml +4 -0
- package/rules/ts-slop-rules/rules/in-correct-optional-input-type.yml +10 -0
- package/rules/ts-slop-rules/rules/jwt-no-verify.yml +13 -0
- package/rules/ts-slop-rules/rules/no-architecture-violation.yml +10 -0
- package/rules/ts-slop-rules/rules/no-case-declarations.yml +10 -0
- package/rules/ts-slop-rules/rules/no-dangerously-set-inner-html.yml +10 -0
- package/rules/ts-slop-rules/rules/no-debugger.yml +10 -0
- package/rules/ts-slop-rules/rules/no-dupe-args.yml +10 -0
- package/rules/ts-slop-rules/rules/no-dupe-class-members.yml +10 -0
- package/rules/ts-slop-rules/rules/no-dupe-keys.yml +10 -0
- package/rules/ts-slop-rules/rules/no-eval.yml +13 -0
- package/rules/ts-slop-rules/rules/no-hardcoded-secrets.yml +12 -0
- package/rules/ts-slop-rules/rules/no-implied-eval.yml +12 -0
- package/rules/ts-slop-rules/rules/no-inner-html.yml +13 -0
- package/rules/ts-slop-rules/rules/no-javascript-url.yml +10 -0
- package/rules/ts-slop-rules/rules/no-mutable-default.yml +10 -0
- package/rules/ts-slop-rules/rules/no-nested-links.yml +12 -0
- package/rules/ts-slop-rules/rules/no-new-symbol.yml +10 -0
- package/rules/ts-slop-rules/rules/no-new-wrappers.yml +13 -0
- package/rules/ts-slop-rules/rules/no-open-redirect.yml +16 -0
- package/rules/ts-slop-rules/rules/slop-rules.yml +455 -0
- package/rules/ts-slop-rules/rules/weak-rsa-key.yml +12 -0
- package/skills/ast-grep/SKILL.md +182 -0
- package/clients/dispatch/runners/secrets.js +0 -109
- package/commands/fix.js +0 -244
- package/commands/fix.ts +0 -373
- package/rules/ast-grep-rules/rules/no-lonely-if.yml +0 -13
|
@@ -0,0 +1,531 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Project Metadata Detection for pi-lens
|
|
3
|
+
*
|
|
4
|
+
* Extracts project configuration from common config files:
|
|
5
|
+
* - package.json (Node.js/npm/pnpm/yarn/bun)
|
|
6
|
+
* - pyproject.toml (Python)
|
|
7
|
+
* - Cargo.toml (Rust)
|
|
8
|
+
* - go.mod (Go)
|
|
9
|
+
* - composer.json (PHP)
|
|
10
|
+
* - Gemfile (Ruby)
|
|
11
|
+
*/
|
|
12
|
+
import * as fs from "node:fs";
|
|
13
|
+
import * as path from "node:path";
|
|
14
|
+
// --- Detection Functions ---
|
|
15
|
+
/**
|
|
16
|
+
* Detect project metadata from a target directory.
|
|
17
|
+
* Reads common config files and extracts structured information.
|
|
18
|
+
*/
|
|
19
|
+
export function detectProjectMetadata(targetPath) {
|
|
20
|
+
const metadata = {
|
|
21
|
+
type: "unknown",
|
|
22
|
+
scripts: {},
|
|
23
|
+
languages: [],
|
|
24
|
+
hasTests: false,
|
|
25
|
+
hasLinting: false,
|
|
26
|
+
hasFormatting: false,
|
|
27
|
+
hasTypeScript: false,
|
|
28
|
+
configFiles: [],
|
|
29
|
+
};
|
|
30
|
+
// Check for Node.js project
|
|
31
|
+
const nodeMeta = detectNodeProject(targetPath);
|
|
32
|
+
if (nodeMeta) {
|
|
33
|
+
Object.assign(metadata, nodeMeta);
|
|
34
|
+
}
|
|
35
|
+
// Check for Python project
|
|
36
|
+
const pythonMeta = detectPythonProject(targetPath);
|
|
37
|
+
if (pythonMeta && metadata.type === "unknown") {
|
|
38
|
+
Object.assign(metadata, pythonMeta);
|
|
39
|
+
}
|
|
40
|
+
// Check for Rust project
|
|
41
|
+
const rustMeta = detectRustProject(targetPath);
|
|
42
|
+
if (rustMeta && metadata.type === "unknown") {
|
|
43
|
+
Object.assign(metadata, rustMeta);
|
|
44
|
+
}
|
|
45
|
+
// Check for Go project
|
|
46
|
+
const goMeta = detectGoProject(targetPath);
|
|
47
|
+
if (goMeta && metadata.type === "unknown") {
|
|
48
|
+
Object.assign(metadata, goMeta);
|
|
49
|
+
}
|
|
50
|
+
// Check for PHP project
|
|
51
|
+
const phpMeta = detectPhpProject(targetPath);
|
|
52
|
+
if (phpMeta && metadata.type === "unknown") {
|
|
53
|
+
Object.assign(metadata, phpMeta);
|
|
54
|
+
}
|
|
55
|
+
// Check for Ruby project
|
|
56
|
+
const rubyMeta = detectRubyProject(targetPath);
|
|
57
|
+
if (rubyMeta && metadata.type === "unknown") {
|
|
58
|
+
Object.assign(metadata, rubyMeta);
|
|
59
|
+
}
|
|
60
|
+
// Multi-project detection: if multiple types found
|
|
61
|
+
const types = [nodeMeta, pythonMeta, rustMeta, goMeta, phpMeta, rubyMeta]
|
|
62
|
+
.filter(Boolean)
|
|
63
|
+
.map(m => m.type);
|
|
64
|
+
if (types.length > 1) {
|
|
65
|
+
metadata.type = "multi";
|
|
66
|
+
metadata.languages = [...new Set(types)];
|
|
67
|
+
}
|
|
68
|
+
return metadata;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Detect Node.js project from package.json and lockfiles
|
|
72
|
+
*/
|
|
73
|
+
function detectNodeProject(targetPath) {
|
|
74
|
+
const packageJsonPath = path.join(targetPath, "package.json");
|
|
75
|
+
if (!fs.existsSync(packageJsonPath)) {
|
|
76
|
+
return null;
|
|
77
|
+
}
|
|
78
|
+
let packageJson;
|
|
79
|
+
try {
|
|
80
|
+
packageJson = JSON.parse(fs.readFileSync(packageJsonPath, "utf-8"));
|
|
81
|
+
}
|
|
82
|
+
catch {
|
|
83
|
+
return null;
|
|
84
|
+
}
|
|
85
|
+
const metadata = {
|
|
86
|
+
type: "node",
|
|
87
|
+
name: typeof packageJson.name === "string" ? packageJson.name : undefined,
|
|
88
|
+
version: typeof packageJson.version === "string" ? packageJson.version : undefined,
|
|
89
|
+
packageManager: detectNodePackageManager(targetPath),
|
|
90
|
+
scripts: typeof packageJson.scripts === "object" && packageJson.scripts !== null
|
|
91
|
+
? packageJson.scripts
|
|
92
|
+
: {},
|
|
93
|
+
languages: ["javascript"],
|
|
94
|
+
hasTests: false,
|
|
95
|
+
hasLinting: false,
|
|
96
|
+
hasFormatting: false,
|
|
97
|
+
hasTypeScript: fs.existsSync(path.join(targetPath, "tsconfig.json")),
|
|
98
|
+
configFiles: ["package.json"],
|
|
99
|
+
};
|
|
100
|
+
// Detect TypeScript
|
|
101
|
+
if (metadata.hasTypeScript) {
|
|
102
|
+
metadata.languages.push("typescript");
|
|
103
|
+
metadata.configFiles.push("tsconfig.json");
|
|
104
|
+
}
|
|
105
|
+
// Detect tests from scripts or config files
|
|
106
|
+
const scripts = Object.keys(metadata.scripts).join(" ").toLowerCase();
|
|
107
|
+
if (scripts.includes("test") || scripts.includes("spec")) {
|
|
108
|
+
metadata.hasTests = true;
|
|
109
|
+
}
|
|
110
|
+
// Detect test frameworks from dependencies
|
|
111
|
+
const allDeps = {
|
|
112
|
+
...(packageJson.dependencies || {}),
|
|
113
|
+
...(packageJson.devDependencies || {}),
|
|
114
|
+
};
|
|
115
|
+
if (allDeps["vitest"]) {
|
|
116
|
+
metadata.hasTests = true;
|
|
117
|
+
metadata.testFramework = "vitest";
|
|
118
|
+
}
|
|
119
|
+
else if (allDeps["jest"]) {
|
|
120
|
+
metadata.hasTests = true;
|
|
121
|
+
metadata.testFramework = "jest";
|
|
122
|
+
}
|
|
123
|
+
else if (allDeps["mocha"]) {
|
|
124
|
+
metadata.hasTests = true;
|
|
125
|
+
metadata.testFramework = "mocha";
|
|
126
|
+
}
|
|
127
|
+
else if (allDeps["ava"]) {
|
|
128
|
+
metadata.hasTests = true;
|
|
129
|
+
metadata.testFramework = "ava";
|
|
130
|
+
}
|
|
131
|
+
else if (allDeps["tap"]) {
|
|
132
|
+
metadata.hasTests = true;
|
|
133
|
+
metadata.testFramework = "tap";
|
|
134
|
+
}
|
|
135
|
+
else if (allDeps["node:test"]) {
|
|
136
|
+
metadata.hasTests = true;
|
|
137
|
+
metadata.testFramework = "node:test";
|
|
138
|
+
}
|
|
139
|
+
// Detect linting
|
|
140
|
+
if (allDeps["eslint"] || fs.existsSync(path.join(targetPath, ".eslintrc")) ||
|
|
141
|
+
fs.existsSync(path.join(targetPath, ".eslintrc.js")) ||
|
|
142
|
+
fs.existsSync(path.join(targetPath, "eslint.config.js")) ||
|
|
143
|
+
fs.existsSync(path.join(targetPath, "eslint.config.mjs"))) {
|
|
144
|
+
metadata.hasLinting = true;
|
|
145
|
+
metadata.linter = "eslint";
|
|
146
|
+
metadata.configFiles.push("eslint config");
|
|
147
|
+
}
|
|
148
|
+
if (allDeps["@biomejs/biome"] || fs.existsSync(path.join(targetPath, "biome.json"))) {
|
|
149
|
+
metadata.hasLinting = true;
|
|
150
|
+
metadata.linter = metadata.linter ? `${metadata.linter}, biome` : "biome";
|
|
151
|
+
metadata.configFiles.push("biome.json");
|
|
152
|
+
}
|
|
153
|
+
// Detect formatting
|
|
154
|
+
if (allDeps["prettier"] || fs.existsSync(path.join(targetPath, ".prettierrc")) ||
|
|
155
|
+
fs.existsSync(path.join(targetPath, ".prettierrc.json"))) {
|
|
156
|
+
metadata.hasFormatting = true;
|
|
157
|
+
metadata.formatter = metadata.formatter ? `${metadata.formatter}, prettier` : "prettier";
|
|
158
|
+
metadata.configFiles.push("prettier config");
|
|
159
|
+
}
|
|
160
|
+
if (allDeps["@biomejs/biome"]) {
|
|
161
|
+
metadata.hasFormatting = true;
|
|
162
|
+
metadata.formatter = metadata.formatter ? `${metadata.formatter}, biome` : "biome";
|
|
163
|
+
}
|
|
164
|
+
return metadata;
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Detect Node.js package manager from lockfiles
|
|
168
|
+
*/
|
|
169
|
+
function detectNodePackageManager(targetPath) {
|
|
170
|
+
if (fs.existsSync(path.join(targetPath, "bun.lockb")) || fs.existsSync(path.join(targetPath, "bun.lock"))) {
|
|
171
|
+
return "bun";
|
|
172
|
+
}
|
|
173
|
+
if (fs.existsSync(path.join(targetPath, "pnpm-lock.yaml"))) {
|
|
174
|
+
return "pnpm";
|
|
175
|
+
}
|
|
176
|
+
if (fs.existsSync(path.join(targetPath, "yarn.lock"))) {
|
|
177
|
+
return "yarn";
|
|
178
|
+
}
|
|
179
|
+
if (fs.existsSync(path.join(targetPath, "package-lock.json"))) {
|
|
180
|
+
return "npm";
|
|
181
|
+
}
|
|
182
|
+
return undefined;
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Detect Python project from pyproject.toml, setup.py, requirements.txt
|
|
186
|
+
*/
|
|
187
|
+
function detectPythonProject(targetPath) {
|
|
188
|
+
const pyprojectPath = path.join(targetPath, "pyproject.toml");
|
|
189
|
+
const setupPyPath = path.join(targetPath, "setup.py");
|
|
190
|
+
const requirementsPath = path.join(targetPath, "requirements.txt");
|
|
191
|
+
if (!fs.existsSync(pyprojectPath) && !fs.existsSync(setupPyPath) && !fs.existsSync(requirementsPath)) {
|
|
192
|
+
return null;
|
|
193
|
+
}
|
|
194
|
+
const metadata = {
|
|
195
|
+
type: "python",
|
|
196
|
+
packageManager: detectPythonPackageManager(targetPath),
|
|
197
|
+
scripts: {},
|
|
198
|
+
languages: ["python"],
|
|
199
|
+
hasTests: false,
|
|
200
|
+
hasLinting: false,
|
|
201
|
+
hasFormatting: false,
|
|
202
|
+
hasTypeScript: false,
|
|
203
|
+
configFiles: [],
|
|
204
|
+
};
|
|
205
|
+
// Read pyproject.toml if available
|
|
206
|
+
if (fs.existsSync(pyprojectPath)) {
|
|
207
|
+
metadata.configFiles.push("pyproject.toml");
|
|
208
|
+
try {
|
|
209
|
+
const content = fs.readFileSync(pyprojectPath, "utf-8");
|
|
210
|
+
// Extract project name
|
|
211
|
+
const nameMatch = content.match(/\[project\][\s\S]*?name\s*=\s*["']([^"']+)["']/);
|
|
212
|
+
if (nameMatch)
|
|
213
|
+
metadata.name = nameMatch[1];
|
|
214
|
+
// Extract version
|
|
215
|
+
const versionMatch = content.match(/\[project\][\s\S]*?version\s*=\s*["']([^"']+)["']/);
|
|
216
|
+
if (versionMatch)
|
|
217
|
+
metadata.version = versionMatch[1];
|
|
218
|
+
// Detect test framework
|
|
219
|
+
if (content.includes("pytest") || fs.existsSync(path.join(targetPath, "pytest.ini"))) {
|
|
220
|
+
metadata.hasTests = true;
|
|
221
|
+
metadata.testFramework = "pytest";
|
|
222
|
+
}
|
|
223
|
+
// Detect linting
|
|
224
|
+
if (content.includes("ruff") || fs.existsSync(path.join(targetPath, "ruff.toml"))) {
|
|
225
|
+
metadata.hasLinting = true;
|
|
226
|
+
metadata.linter = "ruff";
|
|
227
|
+
metadata.hasFormatting = true;
|
|
228
|
+
metadata.formatter = "ruff";
|
|
229
|
+
}
|
|
230
|
+
else if (content.includes("pylint") || content.includes("flake8")) {
|
|
231
|
+
metadata.hasLinting = true;
|
|
232
|
+
metadata.linter = content.includes("pylint") ? "pylint" : "flake8";
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
catch {
|
|
236
|
+
// Ignore parse errors
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
if (fs.existsSync(setupPyPath))
|
|
240
|
+
metadata.configFiles.push("setup.py");
|
|
241
|
+
if (fs.existsSync(requirementsPath))
|
|
242
|
+
metadata.configFiles.push("requirements.txt");
|
|
243
|
+
return metadata;
|
|
244
|
+
}
|
|
245
|
+
/**
|
|
246
|
+
* Detect Python package manager
|
|
247
|
+
*/
|
|
248
|
+
function detectPythonPackageManager(targetPath) {
|
|
249
|
+
if (fs.existsSync(path.join(targetPath, "uv.lock"))) {
|
|
250
|
+
return "uv";
|
|
251
|
+
}
|
|
252
|
+
if (fs.existsSync(path.join(targetPath, "poetry.lock"))) {
|
|
253
|
+
return "poetry";
|
|
254
|
+
}
|
|
255
|
+
if (fs.existsSync(path.join(targetPath, "Pipfile.lock")) || fs.existsSync(path.join(targetPath, "Pipfile"))) {
|
|
256
|
+
return "pip"; // pipenv uses Pipfile
|
|
257
|
+
}
|
|
258
|
+
if (fs.existsSync(path.join(targetPath, "requirements.txt"))) {
|
|
259
|
+
return "pip";
|
|
260
|
+
}
|
|
261
|
+
return undefined;
|
|
262
|
+
}
|
|
263
|
+
/**
|
|
264
|
+
* Detect Rust project from Cargo.toml
|
|
265
|
+
*/
|
|
266
|
+
function detectRustProject(targetPath) {
|
|
267
|
+
const cargoPath = path.join(targetPath, "Cargo.toml");
|
|
268
|
+
if (!fs.existsSync(cargoPath)) {
|
|
269
|
+
return null;
|
|
270
|
+
}
|
|
271
|
+
const metadata = {
|
|
272
|
+
type: "rust",
|
|
273
|
+
packageManager: "cargo",
|
|
274
|
+
scripts: {},
|
|
275
|
+
languages: ["rust"],
|
|
276
|
+
hasTests: true, // Cargo has built-in test support
|
|
277
|
+
hasLinting: false,
|
|
278
|
+
hasFormatting: false,
|
|
279
|
+
hasTypeScript: false,
|
|
280
|
+
configFiles: ["Cargo.toml"],
|
|
281
|
+
};
|
|
282
|
+
// Read Cargo.toml
|
|
283
|
+
try {
|
|
284
|
+
const content = fs.readFileSync(cargoPath, "utf-8");
|
|
285
|
+
// Extract package name
|
|
286
|
+
const nameMatch = content.match(/\[package\][\s\S]*?name\s*=\s*["']([^"']+)["']/);
|
|
287
|
+
if (nameMatch)
|
|
288
|
+
metadata.name = nameMatch[1];
|
|
289
|
+
// Extract version
|
|
290
|
+
const versionMatch = content.match(/\[package\][\s\S]*?version\s*=\s*["']([^"']+)["']/);
|
|
291
|
+
if (versionMatch)
|
|
292
|
+
metadata.version = versionMatch[1];
|
|
293
|
+
}
|
|
294
|
+
catch {
|
|
295
|
+
// Ignore parse errors
|
|
296
|
+
}
|
|
297
|
+
// Check for clippy (linter)
|
|
298
|
+
if (fs.existsSync(path.join(targetPath, ".clippy.toml")) ||
|
|
299
|
+
fs.existsSync(path.join(targetPath, "clippy.toml"))) {
|
|
300
|
+
metadata.hasLinting = true;
|
|
301
|
+
metadata.linter = "clippy";
|
|
302
|
+
}
|
|
303
|
+
// Check for rustfmt
|
|
304
|
+
if (fs.existsSync(path.join(targetPath, ".rustfmt.toml")) ||
|
|
305
|
+
fs.existsSync(path.join(targetPath, "rustfmt.toml"))) {
|
|
306
|
+
metadata.hasFormatting = true;
|
|
307
|
+
metadata.formatter = "rustfmt";
|
|
308
|
+
}
|
|
309
|
+
return metadata;
|
|
310
|
+
}
|
|
311
|
+
/**
|
|
312
|
+
* Detect Go project from go.mod
|
|
313
|
+
*/
|
|
314
|
+
function detectGoProject(targetPath) {
|
|
315
|
+
const goModPath = path.join(targetPath, "go.mod");
|
|
316
|
+
if (!fs.existsSync(goModPath)) {
|
|
317
|
+
return null;
|
|
318
|
+
}
|
|
319
|
+
const metadata = {
|
|
320
|
+
type: "go",
|
|
321
|
+
packageManager: "gomod",
|
|
322
|
+
scripts: {},
|
|
323
|
+
languages: ["go"],
|
|
324
|
+
hasTests: true, // Go has built-in test support
|
|
325
|
+
hasLinting: false,
|
|
326
|
+
hasFormatting: false,
|
|
327
|
+
hasTypeScript: false,
|
|
328
|
+
configFiles: ["go.mod"],
|
|
329
|
+
};
|
|
330
|
+
// Read go.mod
|
|
331
|
+
try {
|
|
332
|
+
const content = fs.readFileSync(goModPath, "utf-8");
|
|
333
|
+
// Extract module name (first line: module example.com/module)
|
|
334
|
+
const moduleMatch = content.match(/^module\s+(\S+)/m);
|
|
335
|
+
if (moduleMatch)
|
|
336
|
+
metadata.name = moduleMatch[1];
|
|
337
|
+
// Extract go version
|
|
338
|
+
const versionMatch = content.match(/^go\s+(\S+)/m);
|
|
339
|
+
if (versionMatch)
|
|
340
|
+
metadata.version = versionMatch[1];
|
|
341
|
+
}
|
|
342
|
+
catch {
|
|
343
|
+
// Ignore parse errors
|
|
344
|
+
}
|
|
345
|
+
// Check for golangci-lint
|
|
346
|
+
if (fs.existsSync(path.join(targetPath, ".golangci.yml")) ||
|
|
347
|
+
fs.existsSync(path.join(targetPath, ".golangci.yaml"))) {
|
|
348
|
+
metadata.hasLinting = true;
|
|
349
|
+
metadata.linter = "golangci-lint";
|
|
350
|
+
}
|
|
351
|
+
return metadata;
|
|
352
|
+
}
|
|
353
|
+
/**
|
|
354
|
+
* Detect PHP project from composer.json
|
|
355
|
+
*/
|
|
356
|
+
function detectPhpProject(targetPath) {
|
|
357
|
+
const composerPath = path.join(targetPath, "composer.json");
|
|
358
|
+
if (!fs.existsSync(composerPath)) {
|
|
359
|
+
return null;
|
|
360
|
+
}
|
|
361
|
+
let composerJson;
|
|
362
|
+
try {
|
|
363
|
+
composerJson = JSON.parse(fs.readFileSync(composerPath, "utf-8"));
|
|
364
|
+
}
|
|
365
|
+
catch {
|
|
366
|
+
return null;
|
|
367
|
+
}
|
|
368
|
+
const metadata = {
|
|
369
|
+
type: "php",
|
|
370
|
+
packageManager: "composer",
|
|
371
|
+
name: typeof composerJson.name === "string" ? composerJson.name : undefined,
|
|
372
|
+
scripts: typeof composerJson.scripts === "object" && composerJson.scripts !== null
|
|
373
|
+
? composerJson.scripts
|
|
374
|
+
: {},
|
|
375
|
+
languages: ["php"],
|
|
376
|
+
hasTests: false,
|
|
377
|
+
hasLinting: false,
|
|
378
|
+
hasFormatting: false,
|
|
379
|
+
hasTypeScript: false,
|
|
380
|
+
configFiles: ["composer.json"],
|
|
381
|
+
};
|
|
382
|
+
// Detect tests from scripts
|
|
383
|
+
const scripts = Object.keys(metadata.scripts).join(" ").toLowerCase();
|
|
384
|
+
if (scripts.includes("test") || scripts.includes("phpunit")) {
|
|
385
|
+
metadata.hasTests = true;
|
|
386
|
+
metadata.testFramework = "phpunit";
|
|
387
|
+
}
|
|
388
|
+
return metadata;
|
|
389
|
+
}
|
|
390
|
+
/**
|
|
391
|
+
* Detect Ruby project from Gemfile
|
|
392
|
+
*/
|
|
393
|
+
function detectRubyProject(targetPath) {
|
|
394
|
+
const gemfilePath = path.join(targetPath, "Gemfile");
|
|
395
|
+
const gemspecPath = fs.readdirSync(targetPath).find(f => f.endsWith(".gemspec"));
|
|
396
|
+
if (!fs.existsSync(gemfilePath) && !gemspecPath) {
|
|
397
|
+
return null;
|
|
398
|
+
}
|
|
399
|
+
const metadata = {
|
|
400
|
+
type: "ruby",
|
|
401
|
+
packageManager: "bundler",
|
|
402
|
+
scripts: {},
|
|
403
|
+
languages: ["ruby"],
|
|
404
|
+
hasTests: false,
|
|
405
|
+
hasLinting: false,
|
|
406
|
+
hasFormatting: false,
|
|
407
|
+
hasTypeScript: false,
|
|
408
|
+
configFiles: [],
|
|
409
|
+
};
|
|
410
|
+
if (fs.existsSync(gemfilePath))
|
|
411
|
+
metadata.configFiles.push("Gemfile");
|
|
412
|
+
if (gemspecPath)
|
|
413
|
+
metadata.configFiles.push(gemspecPath);
|
|
414
|
+
// Check for Rakefile to get tasks
|
|
415
|
+
const rakefilePath = path.join(targetPath, "Rakefile");
|
|
416
|
+
if (fs.existsSync(rakefilePath)) {
|
|
417
|
+
metadata.configFiles.push("Rakefile");
|
|
418
|
+
}
|
|
419
|
+
// Check for test framework
|
|
420
|
+
if (fs.existsSync(path.join(targetPath, "spec"))) {
|
|
421
|
+
metadata.hasTests = true;
|
|
422
|
+
metadata.testFramework = "rspec";
|
|
423
|
+
}
|
|
424
|
+
else if (fs.existsSync(path.join(targetPath, "test"))) {
|
|
425
|
+
metadata.hasTests = true;
|
|
426
|
+
metadata.testFramework = "minitest";
|
|
427
|
+
}
|
|
428
|
+
// Check for rubocop
|
|
429
|
+
if (fs.existsSync(path.join(targetPath, ".rubocop.yml"))) {
|
|
430
|
+
metadata.hasLinting = true;
|
|
431
|
+
metadata.linter = "rubocop";
|
|
432
|
+
metadata.configFiles.push(".rubocop.yml");
|
|
433
|
+
}
|
|
434
|
+
return metadata;
|
|
435
|
+
}
|
|
436
|
+
// --- Formatting Utilities ---
|
|
437
|
+
/**
|
|
438
|
+
* Format project metadata for display in reports
|
|
439
|
+
*/
|
|
440
|
+
export function formatProjectMetadata(metadata) {
|
|
441
|
+
const lines = [];
|
|
442
|
+
// Header
|
|
443
|
+
const name = metadata.name ? `**${metadata.name}**` : "Project";
|
|
444
|
+
const type = metadata.type !== "unknown" ? `(${capitalize(metadata.type)})` : "";
|
|
445
|
+
lines.push(`๐ ${name} ${type}`.trim());
|
|
446
|
+
// Package manager
|
|
447
|
+
if (metadata.packageManager) {
|
|
448
|
+
lines.push(`๐ฆ Package Manager: ${capitalize(metadata.packageManager)}`);
|
|
449
|
+
}
|
|
450
|
+
// Languages
|
|
451
|
+
if (metadata.languages.length > 0) {
|
|
452
|
+
lines.push(`๐ Languages: ${metadata.languages.map(capitalize).join(", ")}`);
|
|
453
|
+
}
|
|
454
|
+
// Tools
|
|
455
|
+
const tools = [];
|
|
456
|
+
if (metadata.hasTests) {
|
|
457
|
+
tools.push(metadata.testFramework ? `๐งช ${metadata.testFramework}` : "๐งช tests");
|
|
458
|
+
}
|
|
459
|
+
if (metadata.hasLinting) {
|
|
460
|
+
tools.push(metadata.linter ? `๐ ${metadata.linter}` : "๐ linting");
|
|
461
|
+
}
|
|
462
|
+
if (metadata.hasFormatting) {
|
|
463
|
+
tools.push(metadata.formatter ? `โจ ${metadata.formatter}` : "โจ formatting");
|
|
464
|
+
}
|
|
465
|
+
if (tools.length > 0) {
|
|
466
|
+
lines.push(tools.join(" | "));
|
|
467
|
+
}
|
|
468
|
+
// Config files (limited)
|
|
469
|
+
if (metadata.configFiles.length > 0) {
|
|
470
|
+
const limited = metadata.configFiles.slice(0, 5);
|
|
471
|
+
const more = metadata.configFiles.length > 5 ? ` (+${metadata.configFiles.length - 5} more)` : "";
|
|
472
|
+
lines.push(`โ๏ธ Config: ${limited.join(", ")}${more}`);
|
|
473
|
+
}
|
|
474
|
+
return lines.join("\n");
|
|
475
|
+
}
|
|
476
|
+
/**
|
|
477
|
+
* Get available commands for a project (build, test, lint, etc.)
|
|
478
|
+
*/
|
|
479
|
+
export function getAvailableCommands(metadata) {
|
|
480
|
+
const commands = [];
|
|
481
|
+
// Node.js projects - use npm scripts
|
|
482
|
+
if (metadata.type === "node" && Object.keys(metadata.scripts).length > 0) {
|
|
483
|
+
const scriptPriority = ["test", "build", "lint", "format", "dev", "start", "typecheck"];
|
|
484
|
+
for (const priority of scriptPriority) {
|
|
485
|
+
const matching = Object.entries(metadata.scripts).find(([name]) => name.toLowerCase().includes(priority));
|
|
486
|
+
if (matching) {
|
|
487
|
+
const runCmd = metadata.packageManager === "bun" ? "bun run" :
|
|
488
|
+
metadata.packageManager === "pnpm" ? "pnpm" :
|
|
489
|
+
metadata.packageManager === "yarn" ? "yarn" :
|
|
490
|
+
"npm run";
|
|
491
|
+
commands.push({
|
|
492
|
+
action: priority,
|
|
493
|
+
command: `${runCmd} ${matching[0]}`,
|
|
494
|
+
});
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
// Python projects
|
|
499
|
+
if (metadata.type === "python") {
|
|
500
|
+
if (metadata.hasTests) {
|
|
501
|
+
const testCmd = metadata.packageManager === "poetry" ? "poetry run pytest" :
|
|
502
|
+
metadata.packageManager === "uv" ? "uv run pytest" :
|
|
503
|
+
"pytest";
|
|
504
|
+
commands.push({ action: "test", command: testCmd });
|
|
505
|
+
}
|
|
506
|
+
if (metadata.linter?.includes("ruff")) {
|
|
507
|
+
commands.push({ action: "lint", command: "ruff check ." });
|
|
508
|
+
commands.push({ action: "format", command: "ruff format ." });
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
// Rust projects
|
|
512
|
+
if (metadata.type === "rust") {
|
|
513
|
+
commands.push({ action: "build", command: "cargo build" });
|
|
514
|
+
commands.push({ action: "test", command: "cargo test" });
|
|
515
|
+
if (metadata.hasLinting) {
|
|
516
|
+
commands.push({ action: "lint", command: "cargo clippy" });
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
// Go projects
|
|
520
|
+
if (metadata.type === "go") {
|
|
521
|
+
commands.push({ action: "build", command: "go build" });
|
|
522
|
+
commands.push({ action: "test", command: "go test ./..." });
|
|
523
|
+
if (metadata.hasLinting) {
|
|
524
|
+
commands.push({ action: "lint", command: "golangci-lint run" });
|
|
525
|
+
}
|
|
526
|
+
}
|
|
527
|
+
return commands;
|
|
528
|
+
}
|
|
529
|
+
function capitalize(str) {
|
|
530
|
+
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
531
|
+
}
|