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,318 +0,0 @@
1
- /**
2
- * LSP Service Layer for pi-lens
3
- *
4
- * Manages multiple LSP clients per workspace with:
5
- * - Auto-spawning based on file type
6
- * - Effect-TS service composition
7
- * - Bus event integration
8
- * - Resource cleanup
9
- */
10
- import { Effect } from "effect";
11
- import { createLSPClient } from "./client.js";
12
- import { getServersForFileWithConfig } from "./config.js";
13
- import { getLanguageId } from "./language.js";
14
- // --- Service ---
15
- export class LSPService {
16
- constructor() {
17
- this.state = {
18
- clients: new Map(),
19
- servers: new Map(),
20
- broken: new Set(),
21
- inFlight: new Map(),
22
- };
23
- }
24
- /**
25
- * Get or create LSP client for a file
26
- * Prevents duplicate client creation via in-flight promise tracking
27
- */
28
- async getClientForFile(filePath) {
29
- const servers = getServersForFileWithConfig(filePath);
30
- if (servers.length === 0)
31
- return undefined;
32
- // Try each matching server
33
- for (const server of servers) {
34
- const root = await server.root(filePath);
35
- if (!root)
36
- continue;
37
- // Normalize root path for consistent cache key on Windows
38
- const normalizedRoot = process.platform === "win32" ? root.toLowerCase() : root;
39
- const key = `${server.id}:${normalizedRoot}`;
40
- // Check cache first (fast path)
41
- const existing = this.state.clients.get(key);
42
- if (existing) {
43
- return { client: existing, info: server };
44
- }
45
- // Check if broken
46
- if (this.state.broken.has(key)) {
47
- continue;
48
- }
49
- // Check if there's already an in-flight spawn for this key
50
- const inFlight = this.state.inFlight.get(key);
51
- if (inFlight) {
52
- // Wait for the existing spawn to complete
53
- const result = await inFlight;
54
- if (result)
55
- return result;
56
- continue; // This server failed, try next
57
- }
58
- // Create the spawn promise and store it
59
- const spawnPromise = this.spawnClient(server, root, key);
60
- this.state.inFlight.set(key, spawnPromise);
61
- try {
62
- const result = await spawnPromise;
63
- if (result)
64
- return result;
65
- }
66
- finally {
67
- // Clean up in-flight tracking
68
- this.state.inFlight.delete(key);
69
- }
70
- }
71
- return undefined;
72
- }
73
- /**
74
- * Internal: spawn a client for a server/root combination
75
- */
76
- async spawnClient(server, root, key) {
77
- try {
78
- const spawned = await server.spawn(root);
79
- if (!spawned) {
80
- this.state.broken.add(key);
81
- return undefined;
82
- }
83
- const client = await createLSPClient({
84
- serverId: server.id,
85
- process: spawned.process,
86
- root,
87
- initialization: spawned.initialization,
88
- });
89
- this.state.clients.set(key, client);
90
- return { client, info: server };
91
- }
92
- catch (err) {
93
- const errorMsg = err instanceof Error ? err.message : String(err);
94
- if (errorMsg.includes("Timeout")) {
95
- console.error(`[lsp] ${server.id} timed out during initialization (${errorMsg}). The server may be downloading or the project is large. Skipping.`);
96
- }
97
- else if (errorMsg.includes("stream was destroyed")) {
98
- console.error(`[lsp] ${server.id} stream was destroyed. The server binary may be missing or crashed immediately. Try reinstalling: npm install -g ${server.id}-language-server`);
99
- }
100
- else if (errorMsg.includes("exited immediately")) {
101
- console.error(`[lsp] ${server.id} ${errorMsg}. Try reinstalling: npm install -g ${server.id}-language-server`);
102
- }
103
- else {
104
- console.error(`[lsp] Failed to spawn ${server.id}:`, err);
105
- }
106
- this.state.broken.add(key);
107
- return undefined;
108
- }
109
- }
110
- /**
111
- * Open a file in LSP (sends textDocument/didOpen)
112
- */
113
- async openFile(filePath, content) {
114
- const spawned = await this.getClientForFile(filePath);
115
- if (!spawned)
116
- return;
117
- const languageId = getLanguageId(filePath) ?? "plaintext";
118
- await spawned.client.notify.open(filePath, content, languageId);
119
- }
120
- /**
121
- * Update file content (sends textDocument/didChange)
122
- */
123
- async updateFile(filePath, content) {
124
- const spawned = await this.getClientForFile(filePath);
125
- if (!spawned)
126
- return;
127
- await spawned.client.notify.change(filePath, content);
128
- }
129
- /**
130
- * Get diagnostics for a file
131
- */
132
- async getDiagnostics(filePath) {
133
- const spawned = await this.getClientForFile(filePath);
134
- if (!spawned)
135
- return [];
136
- await spawned.client.waitForDiagnostics(filePath, 3000);
137
- return spawned.client.getDiagnostics(filePath);
138
- }
139
- /**
140
- * Navigation: go to definition
141
- */
142
- async definition(filePath, line, character) {
143
- const spawned = await this.getClientForFile(filePath);
144
- if (!spawned)
145
- return [];
146
- return spawned.client.definition(filePath, line, character);
147
- }
148
- /**
149
- * Navigation: find all references
150
- */
151
- async references(filePath, line, character, includeDeclaration = true) {
152
- const spawned = await this.getClientForFile(filePath);
153
- if (!spawned)
154
- return [];
155
- return spawned.client.references(filePath, line, character, includeDeclaration);
156
- }
157
- /**
158
- * Navigation: hover info
159
- */
160
- async hover(filePath, line, character) {
161
- const spawned = await this.getClientForFile(filePath);
162
- if (!spawned)
163
- return null;
164
- return spawned.client.hover(filePath, line, character);
165
- }
166
- /**
167
- * Navigation: symbols in document
168
- */
169
- async documentSymbol(filePath) {
170
- const spawned = await this.getClientForFile(filePath);
171
- if (!spawned)
172
- return [];
173
- return spawned.client.documentSymbol(filePath);
174
- }
175
- /**
176
- * Navigation: workspace-wide symbol search
177
- */
178
- async workspaceSymbol(query) {
179
- // Use the first active client for workspace-level queries
180
- const clients = Array.from(this.state.clients.values());
181
- if (clients.length === 0)
182
- return [];
183
- return clients[0].workspaceSymbol(query);
184
- }
185
- /**
186
- * Navigation: go to implementation
187
- */
188
- async implementation(filePath, line, character) {
189
- const spawned = await this.getClientForFile(filePath);
190
- if (!spawned)
191
- return [];
192
- return spawned.client.implementation(filePath, line, character);
193
- }
194
- /**
195
- * Navigation: prepare call hierarchy at position
196
- */
197
- async prepareCallHierarchy(filePath, line, character) {
198
- const spawned = await this.getClientForFile(filePath);
199
- if (!spawned)
200
- return [];
201
- return spawned.client.prepareCallHierarchy(filePath, line, character);
202
- }
203
- /**
204
- * Navigation: find incoming calls (callers)
205
- */
206
- async incomingCalls(item) {
207
- const spawned = await this.getClientForFile(item.uri.replace("file://", ""));
208
- if (!spawned)
209
- return [];
210
- return spawned.client.incomingCalls(item);
211
- }
212
- /**
213
- * Navigation: find outgoing calls (callees)
214
- */
215
- async outgoingCalls(item) {
216
- const spawned = await this.getClientForFile(item.uri.replace("file://", ""));
217
- if (!spawned)
218
- return [];
219
- return spawned.client.outgoingCalls(item);
220
- }
221
- /**
222
- * Get all diagnostics across all tracked files (for cascade checking)
223
- */
224
- async getAllDiagnostics() {
225
- const all = new Map();
226
- for (const [_key, client] of this.state.clients) {
227
- const clientDiags = client.getAllDiagnostics();
228
- for (const [filePath, diags] of clientDiags) {
229
- const existing = all.get(filePath) ?? [];
230
- all.set(filePath, [...existing, ...diags]);
231
- }
232
- }
233
- return all;
234
- }
235
- /**
236
- * Check if LSP is available for a file
237
- */
238
- async hasLSP(filePath) {
239
- const servers = getServersForFileWithConfig(filePath);
240
- if (servers.length === 0)
241
- return false;
242
- // Check if any server can provide a root
243
- for (const server of servers) {
244
- const root = await server.root(filePath);
245
- if (root)
246
- return true;
247
- }
248
- return false;
249
- }
250
- /**
251
- * Shutdown all LSP clients
252
- */
253
- async shutdown() {
254
- // Cancel any in-flight spawns
255
- this.state.inFlight.clear();
256
- for (const [key, client] of this.state.clients) {
257
- try {
258
- await client.shutdown();
259
- }
260
- catch (err) {
261
- console.error(`[lsp] Error shutting down ${key}:`, err);
262
- }
263
- }
264
- this.state.clients.clear();
265
- this.state.broken.clear();
266
- }
267
- /**
268
- * Get status of all active clients
269
- */
270
- getStatus() {
271
- return Array.from(this.state.clients.entries()).map(([key, _client]) => {
272
- const [serverId, root] = key.split(":");
273
- return { serverId, root, connected: true };
274
- });
275
- }
276
- }
277
- // --- Effect Integration ---
278
- /**
279
- * Effect wrapper for LSP operations
280
- */
281
- export function lspEffect(service) {
282
- return {
283
- openFile: (filePath, content) => Effect.tryPromise({
284
- try: () => service.openFile(filePath, content),
285
- catch: (err) => err,
286
- }),
287
- updateFile: (filePath, content) => Effect.tryPromise({
288
- try: () => service.updateFile(filePath, content),
289
- catch: (err) => err,
290
- }),
291
- getDiagnostics: (filePath) => Effect.tryPromise({
292
- try: () => service.getDiagnostics(filePath),
293
- catch: (err) => err,
294
- }),
295
- hasLSP: (filePath) => Effect.tryPromise({
296
- try: () => service.hasLSP(filePath),
297
- catch: (err) => err,
298
- }),
299
- shutdown: () => Effect.tryPromise({
300
- try: () => service.shutdown(),
301
- catch: (err) => err,
302
- }),
303
- };
304
- }
305
- // --- Singleton Instance ---
306
- let globalLSPService = null;
307
- export function getLSPService() {
308
- if (!globalLSPService) {
309
- globalLSPService = new LSPService();
310
- }
311
- return globalLSPService;
312
- }
313
- export function resetLSPService() {
314
- if (globalLSPService) {
315
- globalLSPService.shutdown().catch(() => { });
316
- }
317
- globalLSPService = null;
318
- }
@@ -1,391 +0,0 @@
1
- /**
2
- * Auto-Installation System for pi-lens
3
- *
4
- * Automatically installs required tools when they're not found.
5
- * Covers 14/31 LSP servers (npm/pip installable) plus linting tools.
6
- *
7
- * Core LSP (5):
8
- * - typescript-language-server (TypeScript)
9
- * - pyright (Python)
10
- * - yaml-language-server (YAML)
11
- * - vscode-json-languageserver (JSON)
12
- * - bash-language-server (Bash)
13
- *
14
- * Web Framework LSP (4):
15
- * - @vue/language-server (Vue)
16
- * - svelte-language-server (Svelte)
17
- * - vscode-eslint-language-server (ESLint)
18
- * - vscode-css-languageserver (CSS/SCSS/Sass/Less)
19
- *
20
- * DevOps/Config LSP (2):
21
- * - dockerfile-language-server-nodejs (Dockerfile)
22
- * - @prisma/language-server (Prisma)
23
- *
24
- * Linting/Structural (3):
25
- * - ruff (Python linting)
26
- * - @biomejs/biome (JS/TS/JSON linting)
27
- * - @ast-grep/cli (structural search)
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 "child_process";
35
- import fs from "fs/promises";
36
- import path from "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
- {
79
- id: "ast-grep",
80
- name: "ast-grep",
81
- checkCommand: "ast-grep",
82
- checkArgs: ["--version"],
83
- installStrategy: "npm",
84
- packageName: "@ast-grep/cli",
85
- binaryName: "sg",
86
- },
87
- // Config/Data LSP servers
88
- {
89
- id: "yaml-language-server",
90
- name: "YAML Language Server",
91
- checkCommand: "yaml-language-server",
92
- checkArgs: ["--version"],
93
- installStrategy: "npm",
94
- packageName: "yaml-language-server",
95
- binaryName: "yaml-language-server",
96
- },
97
- {
98
- id: "vscode-json-languageserver",
99
- name: "JSON Language Server",
100
- checkCommand: "vscode-json-languageserver",
101
- checkArgs: ["--version"],
102
- installStrategy: "npm",
103
- packageName: "vscode-langservers-extracted",
104
- binaryName: "vscode-json-languageserver",
105
- },
106
- // Shell/DevOps LSP servers
107
- {
108
- id: "bash-language-server",
109
- name: "Bash Language Server",
110
- checkCommand: "bash-language-server",
111
- checkArgs: ["--version"],
112
- installStrategy: "npm",
113
- packageName: "bash-language-server",
114
- binaryName: "bash-language-server",
115
- },
116
- {
117
- id: "dockerfile-language-server",
118
- name: "Dockerfile Language Server",
119
- checkCommand: "dockerfile-language-server-nodejs",
120
- checkArgs: ["--version"],
121
- installStrategy: "npm",
122
- packageName: "dockerfile-language-server-nodejs",
123
- binaryName: "dockerfile-language-server-nodejs",
124
- },
125
- // Web framework LSP servers
126
- {
127
- id: "vue-language-server",
128
- name: "Vue Language Server",
129
- checkCommand: "vue-language-server",
130
- checkArgs: ["--version"],
131
- installStrategy: "npm",
132
- packageName: "@vue/language-server",
133
- binaryName: "vue-language-server",
134
- },
135
- {
136
- id: "svelte-language-server",
137
- name: "Svelte Language Server",
138
- checkCommand: "svelteserver",
139
- checkArgs: ["--version"],
140
- installStrategy: "npm",
141
- packageName: "svelte-language-server",
142
- binaryName: "svelteserver",
143
- },
144
- {
145
- id: "eslint-server",
146
- name: "ESLint Language Server",
147
- checkCommand: "vscode-eslint-language-server",
148
- checkArgs: ["--version"],
149
- installStrategy: "npm",
150
- packageName: "vscode-langservers-extracted",
151
- binaryName: "vscode-eslint-language-server",
152
- },
153
- {
154
- id: "css-language-server",
155
- name: "CSS Language Server",
156
- checkCommand: "vscode-css-languageserver",
157
- checkArgs: ["--version"],
158
- installStrategy: "npm",
159
- packageName: "vscode-langservers-extracted",
160
- binaryName: "vscode-css-languageserver",
161
- },
162
- // Database/ORM LSP servers
163
- {
164
- id: "prisma-language-server",
165
- name: "Prisma Language Server",
166
- checkCommand: "prisma-language-server",
167
- checkArgs: ["--version"],
168
- installStrategy: "npm",
169
- packageName: "@prisma/language-server",
170
- binaryName: "prisma-language-server",
171
- },
172
- ];
173
- // --- Check Functions ---
174
- /**
175
- * Check if a command is available in PATH
176
- */
177
- async function isCommandAvailable(command, args = ["--version"]) {
178
- return new Promise((resolve) => {
179
- // On Windows, use shell: true to handle .cmd files
180
- const isWindows = process.platform === "win32";
181
- const proc = isWindows
182
- ? spawn(`${command} ${args.join(" ")}`, [], { stdio: "ignore", shell: true })
183
- : spawn(command, args, { stdio: "ignore" });
184
- proc.on("exit", (code) => resolve(code === 0));
185
- proc.on("error", () => resolve(false));
186
- });
187
- }
188
- /**
189
- * Check if a tool is installed (globally or locally)
190
- */
191
- export async function isToolInstalled(toolId) {
192
- const tool = TOOLS.find((t) => t.id === toolId);
193
- if (!tool)
194
- return false;
195
- // Check global PATH
196
- if (await isCommandAvailable(tool.checkCommand, tool.checkArgs)) {
197
- return true;
198
- }
199
- // Check local tools directory
200
- const localPath = path.join(TOOLS_DIR, "node_modules", ".bin", tool.binaryName || tool.id);
201
- try {
202
- await fs.access(localPath);
203
- return true;
204
- }
205
- catch {
206
- return false;
207
- }
208
- }
209
- /**
210
- * Get the path to a tool (global or local)
211
- */
212
- export async function getToolPath(toolId) {
213
- const tool = TOOLS.find((t) => t.id === toolId);
214
- if (!tool)
215
- return undefined;
216
- // Check if global
217
- if (await isCommandAvailable(tool.checkCommand, tool.checkArgs)) {
218
- return tool.checkCommand;
219
- }
220
- // Check local
221
- const localPath = path.join(TOOLS_DIR, "node_modules", ".bin", tool.binaryName || tool.id);
222
- try {
223
- await fs.access(localPath);
224
- return localPath;
225
- }
226
- catch {
227
- return undefined;
228
- }
229
- }
230
- // --- Installation Functions ---
231
- /**
232
- * Install an npm package tool
233
- */
234
- async function installNpmTool(packageName, binaryName) {
235
- try {
236
- // Ensure tools directory exists
237
- await fs.mkdir(TOOLS_DIR, { recursive: true });
238
- // Create a minimal package.json if it doesn't exist
239
- const packageJsonPath = path.join(TOOLS_DIR, "package.json");
240
- try {
241
- await fs.access(packageJsonPath);
242
- }
243
- catch {
244
- await fs.writeFile(packageJsonPath, JSON.stringify({ name: "pi-lens-tools", version: "1.0.0" }, null, 2));
245
- }
246
- // Install via npm or bun (use .cmd on Windows)
247
- const isWindows = process.platform === "win32";
248
- const pm = process.env.BUN_INSTALL
249
- ? isWindows ? "bun.exe" : "bun"
250
- : isWindows ? "npm.cmd" : "npm";
251
- const proc = spawn(pm, ["install", packageName], {
252
- cwd: TOOLS_DIR,
253
- stdio: ["ignore", "pipe", "pipe"],
254
- shell: isWindows, // Required for .cmd files on Windows
255
- });
256
- return new Promise((resolve, reject) => {
257
- let stderr = "";
258
- proc.stderr?.on("data", (data) => (stderr += data));
259
- proc.on("exit", async (code) => {
260
- if (code === 0) {
261
- const binPath = path.join(TOOLS_DIR, "node_modules", ".bin", binaryName);
262
- // Make executable on Unix
263
- if (process.platform !== "win32") {
264
- try {
265
- await fs.chmod(binPath, 0o755);
266
- }
267
- catch { /* ignore */ }
268
- }
269
- resolve(binPath);
270
- }
271
- else {
272
- reject(new Error(`Failed to install ${packageName}: ${stderr}`));
273
- }
274
- });
275
- proc.on("error", (err) => reject(err));
276
- });
277
- }
278
- catch (err) {
279
- console.error(`[auto-install] Failed to install npm tool ${packageName}:`, err);
280
- return undefined;
281
- }
282
- }
283
- /**
284
- * Install a pip package tool
285
- */
286
- async function installPipTool(packageName) {
287
- try {
288
- const pipCmd = process.platform === "win32" ? "pip" : "pip3";
289
- const isWindows = process.platform === "win32";
290
- const proc = spawn(pipCmd, ["install", "--user", packageName], {
291
- stdio: ["ignore", "pipe", "pipe"],
292
- shell: isWindows, // Required for .cmd files on Windows
293
- });
294
- return new Promise((resolve, reject) => {
295
- let stderr = "";
296
- proc.stderr?.on("data", (data) => (stderr += data));
297
- proc.on("exit", (code) => {
298
- if (code === 0) {
299
- resolve(packageName); // pip installs to PATH
300
- }
301
- else {
302
- reject(new Error(`Failed to install ${packageName}: ${stderr}`));
303
- }
304
- });
305
- proc.on("error", (err) => reject(err));
306
- });
307
- }
308
- catch (err) {
309
- console.error(`[auto-install] Failed to install pip tool ${packageName}:`, err);
310
- return undefined;
311
- }
312
- }
313
- /**
314
- * Install a tool by ID
315
- */
316
- export async function installTool(toolId) {
317
- const tool = TOOLS.find((t) => t.id === toolId);
318
- if (!tool) {
319
- console.error(`[auto-install] Unknown tool: ${toolId}`);
320
- return false;
321
- }
322
- console.error(`[auto-install] Installing ${tool.name}...`);
323
- try {
324
- switch (tool.installStrategy) {
325
- case "npm":
326
- if (!tool.packageName || !tool.binaryName)
327
- return false;
328
- const npmPath = await installNpmTool(tool.packageName, tool.binaryName);
329
- return npmPath !== undefined;
330
- case "pip":
331
- if (!tool.packageName)
332
- return false;
333
- const pipPath = await installPipTool(tool.packageName);
334
- return pipPath !== undefined;
335
- default:
336
- console.error(`[auto-install] Unsupported strategy: ${tool.installStrategy}`);
337
- return false;
338
- }
339
- }
340
- catch (err) {
341
- console.error(`[auto-install] Failed to install ${tool.name}:`, err);
342
- return false;
343
- }
344
- }
345
- /**
346
- * Ensure a tool is installed (check first, install if missing)
347
- */
348
- export async function ensureTool(toolId) {
349
- // Check if already installed
350
- const existingPath = await getToolPath(toolId);
351
- if (existingPath) {
352
- return existingPath;
353
- }
354
- // Try to install
355
- const installed = await installTool(toolId);
356
- if (!installed) {
357
- return undefined;
358
- }
359
- // Return the path after installation
360
- return getToolPath(toolId);
361
- }
362
- // --- Integration Helpers ---
363
- /**
364
- * Get environment with tool paths added
365
- */
366
- export async function getToolEnvironment() {
367
- const localBin = path.join(TOOLS_DIR, "node_modules", ".bin");
368
- const currentPath = process.env.PATH || "";
369
- const separator = process.platform === "win32" ? ";" : ":";
370
- return {
371
- ...process.env,
372
- PATH: `${localBin}${separator}${currentPath}`,
373
- };
374
- }
375
- // --- Status Check ---
376
- /**
377
- * Check status of all managed tools
378
- */
379
- export async function checkAllTools() {
380
- const results = [];
381
- for (const tool of TOOLS) {
382
- const path = await getToolPath(tool.id);
383
- results.push({
384
- id: tool.id,
385
- name: tool.name,
386
- installed: path !== undefined,
387
- path,
388
- });
389
- }
390
- return results;
391
- }