pi-lens 3.6.2 → 3.6.4

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 (207) hide show
  1. package/CHANGELOG.md +10 -2
  2. package/package.json +4 -4
  3. package/tsconfig.json +1 -1
  4. package/clients/__tests__/file-time.test.js +0 -216
  5. package/clients/__tests__/file-time.test.ts +0 -276
  6. package/clients/__tests__/format-service.test.js +0 -245
  7. package/clients/__tests__/format-service.test.ts +0 -339
  8. package/clients/__tests__/formatters.test.js +0 -271
  9. package/clients/__tests__/formatters.test.ts +0 -401
  10. package/clients/agent-behavior-client.js +0 -110
  11. package/clients/agent-behavior-client.test.js +0 -94
  12. package/clients/agent-behavior-client.test.ts +0 -116
  13. package/clients/amain-types.js +0 -164
  14. package/clients/architect-client.js +0 -291
  15. package/clients/ast-grep-client.js +0 -253
  16. package/clients/ast-grep-parser.js +0 -84
  17. package/clients/ast-grep-rule-manager.js +0 -89
  18. package/clients/ast-grep-types.js +0 -9
  19. package/clients/auto-loop.js +0 -131
  20. package/clients/biome-client.js +0 -420
  21. package/clients/biome-client.test.js +0 -144
  22. package/clients/biome-client.test.ts +0 -163
  23. package/clients/cache/rule-cache.js +0 -72
  24. package/clients/cache-manager.js +0 -245
  25. package/clients/cache-manager.test.js +0 -197
  26. package/clients/cache-manager.test.ts +0 -299
  27. package/clients/complexity-client.js +0 -675
  28. package/clients/complexity-client.test.js +0 -234
  29. package/clients/complexity-client.test.ts +0 -255
  30. package/clients/config-validator.js +0 -465
  31. package/clients/dependency-checker.js +0 -325
  32. package/clients/dependency-checker.test.js +0 -60
  33. package/clients/dependency-checker.test.ts +0 -71
  34. package/clients/dispatch/__tests__/autofix-integration.test.js +0 -245
  35. package/clients/dispatch/__tests__/autofix-integration.test.ts +0 -300
  36. package/clients/dispatch/__tests__/runner-registration.test.js +0 -234
  37. package/clients/dispatch/__tests__/runner-registration.test.ts +0 -286
  38. package/clients/dispatch/debug.log +0 -1
  39. package/clients/dispatch/dispatcher.edge.test.js +0 -82
  40. package/clients/dispatch/dispatcher.edge.test.ts +0 -100
  41. package/clients/dispatch/dispatcher.format.test.js +0 -46
  42. package/clients/dispatch/dispatcher.format.test.ts +0 -58
  43. package/clients/dispatch/dispatcher.inline.test.js +0 -74
  44. package/clients/dispatch/dispatcher.inline.test.ts +0 -93
  45. package/clients/dispatch/dispatcher.js +0 -381
  46. package/clients/dispatch/dispatcher.test.js +0 -116
  47. package/clients/dispatch/dispatcher.test.ts +0 -149
  48. package/clients/dispatch/integration.js +0 -108
  49. package/clients/dispatch/plan.js +0 -183
  50. package/clients/dispatch/runners/architect.js +0 -83
  51. package/clients/dispatch/runners/architect.test.js +0 -138
  52. package/clients/dispatch/runners/architect.test.ts +0 -162
  53. package/clients/dispatch/runners/ast-grep-napi.js +0 -405
  54. package/clients/dispatch/runners/ast-grep-napi.test.js +0 -107
  55. package/clients/dispatch/runners/ast-grep-napi.test.ts +0 -129
  56. package/clients/dispatch/runners/ast-grep.js +0 -157
  57. package/clients/dispatch/runners/biome.js +0 -55
  58. package/clients/dispatch/runners/config-validation.js +0 -67
  59. package/clients/dispatch/runners/go-vet.js +0 -48
  60. package/clients/dispatch/runners/index.js +0 -47
  61. package/clients/dispatch/runners/lsp.js +0 -102
  62. package/clients/dispatch/runners/oxlint.js +0 -67
  63. package/clients/dispatch/runners/oxlint.test.js +0 -230
  64. package/clients/dispatch/runners/oxlint.test.ts +0 -303
  65. package/clients/dispatch/runners/pyright.js +0 -100
  66. package/clients/dispatch/runners/pyright.test.js +0 -98
  67. package/clients/dispatch/runners/pyright.test.ts +0 -121
  68. package/clients/dispatch/runners/python-slop.js +0 -97
  69. package/clients/dispatch/runners/python-slop.test.js +0 -203
  70. package/clients/dispatch/runners/python-slop.test.ts +0 -298
  71. package/clients/dispatch/runners/ruff.js +0 -48
  72. package/clients/dispatch/runners/rust-clippy.js +0 -102
  73. package/clients/dispatch/runners/scan_codebase.test.js +0 -89
  74. package/clients/dispatch/runners/scan_codebase.test.ts +0 -105
  75. package/clients/dispatch/runners/shellcheck.js +0 -147
  76. package/clients/dispatch/runners/shellcheck.test.js +0 -98
  77. package/clients/dispatch/runners/shellcheck.test.ts +0 -129
  78. package/clients/dispatch/runners/similarity.js +0 -230
  79. package/clients/dispatch/runners/spellcheck.js +0 -106
  80. package/clients/dispatch/runners/spellcheck.test.js +0 -158
  81. package/clients/dispatch/runners/spellcheck.test.ts +0 -214
  82. package/clients/dispatch/runners/tree-sitter.js +0 -246
  83. package/clients/dispatch/runners/ts-lsp.js +0 -125
  84. package/clients/dispatch/runners/ts-slop.js +0 -113
  85. package/clients/dispatch/runners/type-safety.js +0 -142
  86. package/clients/dispatch/runners/utils/diagnostic-parsers.js +0 -134
  87. package/clients/dispatch/runners/utils/runner-helpers.js +0 -115
  88. package/clients/dispatch/runners/utils.js +0 -51
  89. package/clients/dispatch/runners/yaml-rule-parser.js +0 -360
  90. package/clients/dispatch/types.js +0 -16
  91. package/clients/dispatch/utils/format-utils.js +0 -44
  92. package/clients/dogfood.test.js +0 -201
  93. package/clients/dogfood.test.ts +0 -269
  94. package/clients/file-kinds.js +0 -177
  95. package/clients/file-kinds.test.js +0 -169
  96. package/clients/file-kinds.test.ts +0 -210
  97. package/clients/file-time.js +0 -152
  98. package/clients/file-utils.js +0 -40
  99. package/clients/fix-scanners.js +0 -204
  100. package/clients/format-service.js +0 -184
  101. package/clients/formatters.js +0 -488
  102. package/clients/go-client.js +0 -203
  103. package/clients/go-client.test.js +0 -127
  104. package/clients/go-client.test.ts +0 -143
  105. package/clients/installer/index.js +0 -403
  106. package/clients/interviewer-templates.js +0 -75
  107. package/clients/interviewer.js +0 -173
  108. package/clients/jscpd-client.js +0 -196
  109. package/clients/jscpd-client.test.js +0 -127
  110. package/clients/jscpd-client.test.ts +0 -145
  111. package/clients/knip-client.js +0 -239
  112. package/clients/knip-client.test.js +0 -112
  113. package/clients/knip-client.test.ts +0 -128
  114. package/clients/latency-logger.js +0 -40
  115. package/clients/lsp/__tests__/client.test.js +0 -310
  116. package/clients/lsp/__tests__/client.test.ts +0 -412
  117. package/clients/lsp/__tests__/config.test.js +0 -167
  118. package/clients/lsp/__tests__/config.test.ts +0 -217
  119. package/clients/lsp/__tests__/error-recovery.test.js +0 -213
  120. package/clients/lsp/__tests__/error-recovery.test.ts +0 -279
  121. package/clients/lsp/__tests__/integration.test.js +0 -127
  122. package/clients/lsp/__tests__/integration.test.ts +0 -160
  123. package/clients/lsp/__tests__/launch.test.js +0 -313
  124. package/clients/lsp/__tests__/launch.test.ts +0 -394
  125. package/clients/lsp/__tests__/server.test.js +0 -259
  126. package/clients/lsp/__tests__/server.test.ts +0 -332
  127. package/clients/lsp/__tests__/service.test.js +0 -438
  128. package/clients/lsp/__tests__/service.test.ts +0 -530
  129. package/clients/lsp/client.js +0 -350
  130. package/clients/lsp/config.js +0 -112
  131. package/clients/lsp/index.js +0 -318
  132. package/clients/lsp/installer/index.js +0 -391
  133. package/clients/lsp/interactive-install.js +0 -221
  134. package/clients/lsp/language.js +0 -170
  135. package/clients/lsp/launch.js +0 -329
  136. package/clients/lsp/lsp/launch.js +0 -116
  137. package/clients/lsp/lsp/server.js +0 -532
  138. package/clients/lsp/lsp-index.js +0 -10
  139. package/clients/lsp/path-utils.js +0 -5
  140. package/clients/lsp/server.js +0 -725
  141. package/clients/lsp/test-py-spawn/requirements.txt +0 -1
  142. package/clients/lsp/test-py-spawn/test.py +0 -3
  143. package/clients/lsp/test-py-svc/requirements.txt +0 -1
  144. package/clients/lsp/test-py-svc/test.py +0 -3
  145. package/clients/lsp/test-python-project/requirements.txt +0 -1
  146. package/clients/lsp/test-python-project/test.py +0 -5
  147. package/clients/metrics-client.js +0 -107
  148. package/clients/metrics-client.test.js +0 -128
  149. package/clients/metrics-client.test.ts +0 -163
  150. package/clients/metrics-history.js +0 -367
  151. package/clients/path-utils.js +0 -142
  152. package/clients/pipeline.js +0 -272
  153. package/clients/production-readiness.js +0 -522
  154. package/clients/project-index.js +0 -255
  155. package/clients/project-metadata.js +0 -531
  156. package/clients/ruff-client.js +0 -325
  157. package/clients/ruff-client.test.js +0 -132
  158. package/clients/ruff-client.test.ts +0 -153
  159. package/clients/rules-scanner.js +0 -97
  160. package/clients/runner-tracker.js +0 -152
  161. package/clients/rust-client.js +0 -205
  162. package/clients/rust-client.test.js +0 -108
  163. package/clients/rust-client.test.ts +0 -130
  164. package/clients/safe-spawn-async.js +0 -163
  165. package/clients/safe-spawn.js +0 -241
  166. package/clients/sanitize.js +0 -291
  167. package/clients/sanitize.test.js +0 -177
  168. package/clients/sanitize.test.ts +0 -223
  169. package/clients/scan-architectural-debt.js +0 -167
  170. package/clients/scan-utils.js +0 -83
  171. package/clients/secrets-scanner.js +0 -119
  172. package/clients/secrets-scanner.test.js +0 -100
  173. package/clients/secrets-scanner.test.ts +0 -113
  174. package/clients/sg-runner.js +0 -292
  175. package/clients/state-matrix.js +0 -160
  176. package/clients/subprocess-client.js +0 -65
  177. package/clients/symbol-types.js +0 -5
  178. package/clients/test-runner-client.js +0 -523
  179. package/clients/test-runner-client.test.js +0 -192
  180. package/clients/test-runner-client.test.ts +0 -253
  181. package/clients/test-utils.js +0 -27
  182. package/clients/test-utils.ts +0 -36
  183. package/clients/todo-scanner.js +0 -200
  184. package/clients/todo-scanner.test.js +0 -301
  185. package/clients/todo-scanner.test.ts +0 -352
  186. package/clients/tool-availability.js +0 -207
  187. package/clients/tree-sitter-client.js +0 -601
  188. package/clients/tree-sitter-query-loader.js +0 -355
  189. package/clients/tree-sitter-symbol-extractor.js +0 -289
  190. package/clients/ts-service.js +0 -129
  191. package/clients/type-coverage-client.js +0 -127
  192. package/clients/type-coverage-client.test.js +0 -105
  193. package/clients/type-coverage-client.test.ts +0 -125
  194. package/clients/type-safety-client.js +0 -138
  195. package/clients/types.js +0 -11
  196. package/clients/typescript-client.codefix.test.js +0 -157
  197. package/clients/typescript-client.codefix.test.ts +0 -186
  198. package/clients/typescript-client.js +0 -509
  199. package/clients/typescript-client.test.js +0 -105
  200. package/clients/typescript-client.test.ts +0 -126
  201. package/commands/booboo.js +0 -1007
  202. package/commands/fix-from-booboo.js +0 -398
  203. package/commands/fix-simplified.js +0 -618
  204. package/commands/rate.js +0 -281
  205. package/commands/rate.test.js +0 -119
  206. package/commands/rate.test.ts +0 -131
  207. package/commands/refactor.js +0 -130
@@ -1,127 +0,0 @@
1
- import * as fs from "node:fs";
2
- import * as path from "node:path";
3
- import { afterEach, beforeEach, describe, expect, it } from "vitest";
4
- import { GoClient } from "./go-client.js";
5
- import { setupTestEnvironment } from "./test-utils.js";
6
- describe("GoClient", () => {
7
- let client;
8
- let tmpDir;
9
- let cleanup;
10
- beforeEach(() => {
11
- client = new GoClient();
12
- ({ tmpDir, cleanup } = setupTestEnvironment("pi-lens-go-test-"));
13
- });
14
- afterEach(() => {
15
- cleanup();
16
- });
17
- afterEach(() => {
18
- cleanup();
19
- });
20
- describe("isGoFile", () => {
21
- it("should recognize Go files", () => {
22
- expect(client.isGoFile("main.go")).toBe(true);
23
- expect(client.isGoFile("handler.go")).toBe(true);
24
- });
25
- it("should not recognize non-Go files", () => {
26
- expect(client.isGoFile("main.ts")).toBe(false);
27
- expect(client.isGoFile("main.py")).toBe(false);
28
- });
29
- });
30
- describe("isGoAvailable", () => {
31
- it("should check Go availability", () => {
32
- const available = client.isGoAvailable();
33
- expect(typeof available).toBe("boolean");
34
- });
35
- });
36
- describe("isGoplsAvailable", () => {
37
- it("should check gopls availability", () => {
38
- const available = client.isGoplsAvailable();
39
- expect(typeof available).toBe("boolean");
40
- });
41
- });
42
- describe("checkFile", () => {
43
- it("should return empty array for non-existent files", () => {
44
- if (!client.isGoAvailable())
45
- return;
46
- const result = client.checkFile("/nonexistent/file.go");
47
- expect(result).toEqual([]);
48
- });
49
- it("should return array for valid Go files", () => {
50
- if (!client.isGoAvailable())
51
- return;
52
- const content = `
53
- package main
54
-
55
- import "fmt"
56
-
57
- func main() {
58
- fmt.Println("Hello, World!")
59
- }
60
- `;
61
- const filePath = path.join(tmpDir, "main.go");
62
- fs.writeFileSync(filePath, content);
63
- const result = client.checkFile(filePath);
64
- expect(Array.isArray(result)).toBe(true);
65
- });
66
- it("should detect syntax errors", () => {
67
- if (!client.isGoAvailable())
68
- return;
69
- const content = `
70
- package main
71
-
72
- func main() {
73
- fmt.Println("missing import"
74
- }
75
- `;
76
- const filePath = path.join(tmpDir, "main.go");
77
- fs.writeFileSync(filePath, content);
78
- const result = client.checkFile(filePath);
79
- // go vet should catch syntax issues
80
- expect(Array.isArray(result)).toBe(true);
81
- });
82
- });
83
- describe("formatDiagnostics", () => {
84
- it("should format diagnostics for display", () => {
85
- const diags = [
86
- {
87
- line: 5,
88
- column: 2,
89
- endLine: 5,
90
- endColumn: 10,
91
- severity: "error",
92
- message: "undefined: fmt",
93
- file: "main.go",
94
- },
95
- ];
96
- const formatted = client.formatDiagnostics(diags);
97
- expect(formatted).toContain("Go");
98
- expect(formatted).toContain("1 issue");
99
- expect(formatted).toContain("undefined: fmt");
100
- });
101
- it("should show error and warning counts", () => {
102
- const diags = [
103
- {
104
- line: 1,
105
- column: 0,
106
- endLine: 1,
107
- endColumn: 10,
108
- severity: "error",
109
- message: "Error",
110
- file: "test.go",
111
- },
112
- {
113
- line: 2,
114
- column: 0,
115
- endLine: 2,
116
- endColumn: 10,
117
- severity: "warning",
118
- message: "Warning",
119
- file: "test.go",
120
- },
121
- ];
122
- const formatted = client.formatDiagnostics(diags);
123
- expect(formatted).toContain("1 error(s)");
124
- expect(formatted).toContain("1 warning(s)");
125
- });
126
- });
127
- });
@@ -1,143 +0,0 @@
1
- import * as fs from "node:fs";
2
- import * as path from "node:path";
3
- import { afterEach, beforeEach, describe, expect, it } from "vitest";
4
- import { GoClient } from "./go-client.js";
5
- import { setupTestEnvironment } from "./test-utils.js";
6
-
7
- describe("GoClient", () => {
8
- let client: GoClient;
9
- let tmpDir: string;
10
- let cleanup: () => void;
11
-
12
- beforeEach(() => {
13
- client = new GoClient();
14
- ({ tmpDir, cleanup } = setupTestEnvironment("pi-lens-go-test-"));
15
- });
16
-
17
- afterEach(() => {
18
- cleanup();
19
- });
20
-
21
- afterEach(() => {
22
- cleanup();
23
- });
24
-
25
- describe("isGoFile", () => {
26
- it("should recognize Go files", () => {
27
- expect(client.isGoFile("main.go")).toBe(true);
28
- expect(client.isGoFile("handler.go")).toBe(true);
29
- });
30
-
31
- it("should not recognize non-Go files", () => {
32
- expect(client.isGoFile("main.ts")).toBe(false);
33
- expect(client.isGoFile("main.py")).toBe(false);
34
- });
35
- });
36
-
37
- describe("isGoAvailable", () => {
38
- it("should check Go availability", () => {
39
- const available = client.isGoAvailable();
40
- expect(typeof available).toBe("boolean");
41
- });
42
- });
43
-
44
- describe("isGoplsAvailable", () => {
45
- it("should check gopls availability", () => {
46
- const available = client.isGoplsAvailable();
47
- expect(typeof available).toBe("boolean");
48
- });
49
- });
50
-
51
- describe("checkFile", () => {
52
- it("should return empty array for non-existent files", () => {
53
- if (!client.isGoAvailable()) return;
54
- const result = client.checkFile("/nonexistent/file.go");
55
- expect(result).toEqual([]);
56
- });
57
-
58
- it("should return array for valid Go files", () => {
59
- if (!client.isGoAvailable()) return;
60
-
61
- const content = `
62
- package main
63
-
64
- import "fmt"
65
-
66
- func main() {
67
- fmt.Println("Hello, World!")
68
- }
69
- `;
70
- const filePath = path.join(tmpDir, "main.go");
71
- fs.writeFileSync(filePath, content);
72
-
73
- const result = client.checkFile(filePath);
74
- expect(Array.isArray(result)).toBe(true);
75
- });
76
-
77
- it("should detect syntax errors", () => {
78
- if (!client.isGoAvailable()) return;
79
-
80
- const content = `
81
- package main
82
-
83
- func main() {
84
- fmt.Println("missing import"
85
- }
86
- `;
87
- const filePath = path.join(tmpDir, "main.go");
88
- fs.writeFileSync(filePath, content);
89
-
90
- const result = client.checkFile(filePath);
91
- // go vet should catch syntax issues
92
- expect(Array.isArray(result)).toBe(true);
93
- });
94
- });
95
-
96
- describe("formatDiagnostics", () => {
97
- it("should format diagnostics for display", () => {
98
- const diags = [
99
- {
100
- line: 5,
101
- column: 2,
102
- endLine: 5,
103
- endColumn: 10,
104
- severity: "error" as const,
105
- message: "undefined: fmt",
106
- file: "main.go",
107
- },
108
- ];
109
-
110
- const formatted = client.formatDiagnostics(diags);
111
- expect(formatted).toContain("Go");
112
- expect(formatted).toContain("1 issue");
113
- expect(formatted).toContain("undefined: fmt");
114
- });
115
-
116
- it("should show error and warning counts", () => {
117
- const diags = [
118
- {
119
- line: 1,
120
- column: 0,
121
- endLine: 1,
122
- endColumn: 10,
123
- severity: "error" as const,
124
- message: "Error",
125
- file: "test.go",
126
- },
127
- {
128
- line: 2,
129
- column: 0,
130
- endLine: 2,
131
- endColumn: 10,
132
- severity: "warning" as const,
133
- message: "Warning",
134
- file: "test.go",
135
- },
136
- ];
137
-
138
- const formatted = client.formatDiagnostics(diags);
139
- expect(formatted).toContain("1 error(s)");
140
- expect(formatted).toContain("1 warning(s)");
141
- });
142
- });
143
- });
@@ -1,403 +0,0 @@
1
- /**
2
- * Auto-Installation System for pi-lens
3
- *
4
- * Minimal auto-install: Core tools that run frequently.
5
- * Other tools require manual installation with clear instructions.
6
- *
7
- * Auto-install (8 tools):
8
- * - typescript-language-server (TypeScript LSP)
9
- * - pyright (Python LSP)
10
- * - ruff (Python linting)
11
- * - @biomejs/biome (JS/TS/JSON linting/formatting)
12
- * - madge (circular dependency detection)
13
- * - jscpd (duplicate code detection)
14
- * - @ast-grep/cli (structural code search)
15
- * - knip (dead code detection)
16
- *
17
- * Manual install required (25+ tools):
18
- * - yaml-language-server: npm install -g yaml-language-server
19
- * - vscode-json-languageserver: npm install -g vscode-langservers-extracted
20
- * - bash-language-server: npm install -g bash-language-server
21
- * - svelte-language-server: npm install -g svelte-language-server
22
- * - vscode-eslint-language-server: npm install -g vscode-langservers-extracted
23
- * - vscode-css-languageserver: npm install -g vscode-langservers-extracted
24
- * - @prisma/language-server: npm install -g @prisma/language-server
25
- * - dockerfile-language-server: npm install -g dockerfile-language-server-nodejs
26
- * - @vue/language-server: npm install -g @vue/language-server
27
- * - And all language-specific servers (gopls, rust-analyzer, etc.)
28
- *
29
- * Strategies:
30
- * - npm packages via npx/bun
31
- * - pip packages
32
- * - GitHub releases (for platform-specific binaries - not yet implemented)
33
- */
34
- import { spawn } from "node:child_process";
35
- import fs from "node:fs/promises";
36
- import path from "node:path";
37
- // Global installation directory for pi-lens tools
38
- const TOOLS_DIR = path.join(process.cwd(), ".pi-lens", "tools");
39
- const TOOLS = [
40
- // Core LSP servers
41
- {
42
- id: "typescript-language-server",
43
- name: "TypeScript Language Server",
44
- checkCommand: "typescript-language-server",
45
- checkArgs: ["--version"],
46
- installStrategy: "npm",
47
- packageName: "typescript-language-server",
48
- binaryName: "typescript-language-server",
49
- },
50
- {
51
- id: "pyright",
52
- name: "Pyright",
53
- checkCommand: "pyright",
54
- checkArgs: ["--version"],
55
- installStrategy: "npm",
56
- packageName: "pyright",
57
- binaryName: "pyright",
58
- },
59
- // Linting/formatting tools
60
- {
61
- id: "ruff",
62
- name: "Ruff",
63
- checkCommand: "ruff",
64
- checkArgs: ["--version"],
65
- installStrategy: "pip",
66
- packageName: "ruff",
67
- binaryName: "ruff",
68
- },
69
- {
70
- id: "biome",
71
- name: "Biome",
72
- checkCommand: "biome",
73
- checkArgs: ["--version"],
74
- installStrategy: "npm",
75
- packageName: "@biomejs/biome",
76
- binaryName: "biome",
77
- },
78
- // Analysis tools (run at session start / turn end)
79
- {
80
- id: "madge",
81
- name: "Madge",
82
- checkCommand: "madge",
83
- checkArgs: ["--version"],
84
- installStrategy: "npm",
85
- packageName: "madge",
86
- binaryName: "madge",
87
- },
88
- {
89
- id: "jscpd",
90
- name: "jscpd",
91
- checkCommand: "jscpd",
92
- checkArgs: ["--version"],
93
- installStrategy: "npm",
94
- packageName: "jscpd",
95
- binaryName: "jscpd",
96
- },
97
- // Structural search and dead code detection
98
- {
99
- id: "ast-grep",
100
- name: "ast-grep CLI",
101
- checkCommand: "sg",
102
- checkArgs: ["--version"],
103
- installStrategy: "npm",
104
- packageName: "@ast-grep/cli",
105
- binaryName: "sg",
106
- },
107
- {
108
- id: "knip",
109
- name: "Knip",
110
- checkCommand: "knip",
111
- checkArgs: ["--version"],
112
- installStrategy: "npm",
113
- packageName: "knip",
114
- binaryName: "knip",
115
- },
116
- ];
117
- // --- Check Functions ---
118
- /**
119
- * Check if a command is available in PATH
120
- */
121
- async function isCommandAvailable(command, args = ["--version"]) {
122
- return new Promise((resolve) => {
123
- // On Windows, use shell: true to handle .cmd files
124
- const isWindows = process.platform === "win32";
125
- const proc = isWindows
126
- ? spawn(`${command} ${args.join(" ")}`, [], {
127
- stdio: "ignore",
128
- shell: true,
129
- })
130
- : spawn(command, args, { stdio: "ignore" });
131
- proc.on("exit", (code) => resolve(code === 0));
132
- proc.on("error", () => resolve(false));
133
- });
134
- }
135
- /**
136
- * Check if a tool is installed (globally or locally)
137
- */
138
- export async function isToolInstalled(toolId) {
139
- const tool = TOOLS.find((t) => t.id === toolId);
140
- if (!tool)
141
- return false;
142
- // Check global PATH
143
- if (await isCommandAvailable(tool.checkCommand, tool.checkArgs)) {
144
- return true;
145
- }
146
- // Check local tools directory
147
- const localPath = path.join(TOOLS_DIR, "node_modules", ".bin", tool.binaryName || tool.id);
148
- try {
149
- await fs.access(localPath);
150
- return true;
151
- }
152
- catch {
153
- return false;
154
- }
155
- }
156
- /**
157
- * Get the path to a tool (global or local)
158
- */
159
- export async function getToolPath(toolId) {
160
- const tool = TOOLS.find((t) => t.id === toolId);
161
- if (!tool)
162
- return undefined;
163
- // Check if global
164
- if (await isCommandAvailable(tool.checkCommand, tool.checkArgs)) {
165
- return tool.checkCommand;
166
- }
167
- // Check local
168
- const localPath = path.join(TOOLS_DIR, "node_modules", ".bin", tool.binaryName || tool.id);
169
- try {
170
- await fs.access(localPath);
171
- return localPath;
172
- }
173
- catch {
174
- return undefined;
175
- }
176
- }
177
- // --- Verification Functions
178
- /**
179
- * Verify a tool binary actually works by running --version
180
- * This catches broken symlinks, partial installs, and corrupted binaries
181
- */
182
- async function verifyToolBinary(binPath) {
183
- return new Promise((resolve) => {
184
- // Add .cmd extension on Windows for the actual binary
185
- const isWindows = process.platform === "win32";
186
- const execPath = isWindows && !binPath.endsWith(".cmd") ? `${binPath}.cmd` : binPath;
187
- const proc = spawn(execPath, ["--version"], {
188
- timeout: 10000, // 10 second timeout for verification
189
- stdio: ["ignore", "pipe", "pipe"],
190
- shell: isWindows, // Required for .cmd wrappers on Windows
191
- });
192
- let stdout = "";
193
- let stderr = "";
194
- proc.stdout?.on("data", (data) => (stdout += data));
195
- proc.stderr?.on("data", (data) => (stderr += data));
196
- proc.on("exit", (code) => {
197
- if (code === 0) {
198
- console.error(`[auto-install] Verified: ${binPath} (version: ${stdout.trim()})`);
199
- resolve(true);
200
- }
201
- else {
202
- console.error(`[auto-install] Verification failed for ${binPath}: exit code ${code}, stderr: ${stderr}`);
203
- resolve(false);
204
- }
205
- });
206
- proc.on("error", (err) => {
207
- console.error(`[auto-install] Verification failed for ${binPath}: ${err.message}`);
208
- resolve(false);
209
- });
210
- });
211
- }
212
- // --- Installation Functions
213
- /**
214
- * Install an npm package tool
215
- */
216
- async function installNpmTool(packageName, binaryName) {
217
- try {
218
- // Ensure tools directory exists
219
- await fs.mkdir(TOOLS_DIR, { recursive: true });
220
- // Create a minimal package.json if it doesn't exist
221
- const packageJsonPath = path.join(TOOLS_DIR, "package.json");
222
- try {
223
- await fs.access(packageJsonPath);
224
- }
225
- catch {
226
- await fs.writeFile(packageJsonPath, JSON.stringify({ name: "pi-lens-tools", version: "1.0.0" }, null, 2));
227
- }
228
- console.error(`[auto-install] Installing ${packageName}...`);
229
- // Install via npm or bun (use .cmd on Windows)
230
- const isWindows = process.platform === "win32";
231
- const pm = process.env.BUN_INSTALL
232
- ? isWindows
233
- ? "bun.exe"
234
- : "bun"
235
- : isWindows
236
- ? "npm.cmd"
237
- : "npm";
238
- const proc = spawn(pm, ["install", packageName], {
239
- cwd: TOOLS_DIR,
240
- stdio: ["ignore", "pipe", "pipe"],
241
- shell: isWindows, // Required for .cmd files on Windows
242
- });
243
- return new Promise((resolve, reject) => {
244
- let stderr = "";
245
- proc.stderr?.on("data", (data) => (stderr += data));
246
- proc.on("exit", async (code) => {
247
- if (code === 0) {
248
- const binPath = path.join(TOOLS_DIR, "node_modules", ".bin", binaryName);
249
- // Make executable on Unix
250
- if (process.platform !== "win32") {
251
- try {
252
- await fs.chmod(binPath, 0o755);
253
- }
254
- catch {
255
- /* ignore */
256
- }
257
- }
258
- // NEW: Verify the binary actually works before returning
259
- console.error(`[auto-install] Verifying ${binaryName}...`);
260
- const isValid = await verifyToolBinary(binPath);
261
- if (!isValid) {
262
- console.error(`[auto-install] ${packageName} installed but verification failed. The binary may be corrupted.`);
263
- // Clean up the broken installation
264
- try {
265
- const packagePath = path.join(TOOLS_DIR, "node_modules", packageName);
266
- await fs.rm(packagePath, { recursive: true, force: true });
267
- await fs.rm(binPath, { force: true });
268
- if (isWindows) {
269
- await fs.rm(`${binPath}.cmd`, { force: true });
270
- await fs.rm(`${binPath}.ps1`, { force: true });
271
- }
272
- }
273
- catch {
274
- /* ignore cleanup errors */
275
- }
276
- resolve(undefined);
277
- return;
278
- }
279
- resolve(binPath);
280
- }
281
- else {
282
- reject(new Error(`Failed to install ${packageName}: ${stderr}`));
283
- }
284
- });
285
- proc.on("error", (err) => reject(err));
286
- });
287
- }
288
- catch (err) {
289
- console.error(`[auto-install] Failed to install npm tool ${packageName}:`, err);
290
- return undefined;
291
- }
292
- }
293
- /**
294
- * Install a pip package tool
295
- */
296
- async function installPipTool(packageName) {
297
- try {
298
- const pipCmd = process.platform === "win32" ? "pip" : "pip3";
299
- const isWindows = process.platform === "win32";
300
- const proc = spawn(pipCmd, ["install", "--user", packageName], {
301
- stdio: ["ignore", "pipe", "pipe"],
302
- shell: isWindows, // Required for .cmd files on Windows
303
- });
304
- return new Promise((resolve, reject) => {
305
- let stderr = "";
306
- proc.stderr?.on("data", (data) => (stderr += data));
307
- proc.on("exit", (code) => {
308
- if (code === 0) {
309
- resolve(packageName); // pip installs to PATH
310
- }
311
- else {
312
- reject(new Error(`Failed to install ${packageName}: ${stderr}`));
313
- }
314
- });
315
- proc.on("error", (err) => reject(err));
316
- });
317
- }
318
- catch (err) {
319
- console.error(`[auto-install] Failed to install pip tool ${packageName}:`, err);
320
- return undefined;
321
- }
322
- }
323
- /**
324
- * Install a tool by ID
325
- */
326
- export async function installTool(toolId) {
327
- const tool = TOOLS.find((t) => t.id === toolId);
328
- if (!tool) {
329
- console.error(`[auto-install] Unknown tool: ${toolId}`);
330
- return false;
331
- }
332
- console.error(`[auto-install] Installing ${tool.name}...`);
333
- try {
334
- switch (tool.installStrategy) {
335
- case "npm": {
336
- if (!tool.packageName || !tool.binaryName)
337
- return false;
338
- const npmPath = await installNpmTool(tool.packageName, tool.binaryName);
339
- return npmPath !== undefined;
340
- }
341
- case "pip": {
342
- if (!tool.packageName)
343
- return false;
344
- const pipPath = await installPipTool(tool.packageName);
345
- return pipPath !== undefined;
346
- }
347
- default:
348
- console.error(`[auto-install] Unsupported strategy: ${tool.installStrategy}`);
349
- return false;
350
- }
351
- }
352
- catch (err) {
353
- console.error(`[auto-install] Failed to install ${tool.name}:`, err);
354
- return false;
355
- }
356
- }
357
- /**
358
- * Ensure a tool is installed (check first, install if missing)
359
- */
360
- export async function ensureTool(toolId) {
361
- // Check if already installed
362
- const existingPath = await getToolPath(toolId);
363
- if (existingPath) {
364
- return existingPath;
365
- }
366
- // Try to install
367
- const installed = await installTool(toolId);
368
- if (!installed) {
369
- return undefined;
370
- }
371
- // Return the path after installation
372
- return getToolPath(toolId);
373
- }
374
- // --- Integration Helpers ---
375
- /**
376
- * Get environment with tool paths added
377
- */
378
- export async function getToolEnvironment() {
379
- const localBin = path.join(TOOLS_DIR, "node_modules", ".bin");
380
- const currentPath = process.env.PATH || "";
381
- const separator = process.platform === "win32" ? ";" : ":";
382
- return {
383
- ...process.env,
384
- PATH: `${localBin}${separator}${currentPath}`,
385
- };
386
- }
387
- // --- Status Check ---
388
- /**
389
- * Check status of all managed tools
390
- */
391
- export async function checkAllTools() {
392
- const results = [];
393
- for (const tool of TOOLS) {
394
- const path = await getToolPath(tool.id);
395
- results.push({
396
- id: tool.id,
397
- name: tool.name,
398
- installed: path !== undefined,
399
- path,
400
- });
401
- }
402
- return results;
403
- }