@floydous/pi-agent-kernel 0.3.31 → 0.4.1
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/AGENT_KERNEL_SYS_PROMPT.md +6 -4
- package/CHANGELOG.md +35 -4
- package/README.md +39 -74
- package/config.example.toml +36 -0
- package/docs/configuration.md +11 -3
- package/docs/retrieval.md +17 -1
- package/docs/testing.md +5 -3
- package/package.json +9 -7
- package/src/config/agent_kernel_command.ts +91 -91
- package/src/config/kernel_config.ts +179 -43
- package/src/config/toml.ts +15 -4
- package/src/context/session_repair.ts +179 -80
- package/src/editing/patch.ts +28 -16
- package/src/editing/smart_anchor.ts +29 -36
- package/src/editing/syntax-verify.ts +52 -18
- package/src/index.ts +257 -219
- package/src/lsp/lsp_client.ts +138 -23
- package/src/lsp/lsp_formatter.ts +61 -24
- package/src/lsp/lsp_installer.ts +277 -561
- package/src/lsp/lsp_manager.ts +1 -1
- package/src/lsp/lsp_registry.ts +110 -73
- package/src/retrieval/ast_search.ts +136 -172
- package/src/retrieval/repomap.ts +8 -47
- package/src/retrieval/search_bm25.ts +5 -2
- package/src/retrieval/search_cache.ts +69 -0
- package/src/retrieval/search_chunker.ts +21 -43
- package/src/retrieval/search_config.ts +75 -18
- package/src/retrieval/search_embedder.ts +8 -16
- package/src/retrieval/search_index.ts +923 -123
- package/src/retrieval/workspace_walker.ts +262 -0
- package/src/safety/atomic_write.ts +59 -20
- package/src/safety/epistemic_guard.ts +163 -43
- package/src/safety/output_clamper.ts +316 -74
- package/src/tools/code_search_output.ts +59 -23
- package/src/tools/code_search_tool.ts +42 -46
- package/src/tools/context.ts +15 -1
- package/src/tools/edit_tool.ts +124 -43
- package/src/tools/lsp_tool.ts +17 -4
- package/src/tools/read_tool.ts +48 -7
- package/config.toml +0 -31
package/src/lsp/lsp_installer.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
import crossSpawnSync from "cross-spawn";
|
|
1
2
|
import * as fs from "node:fs";
|
|
3
|
+
import * as os from "node:os";
|
|
2
4
|
import * as path from "node:path";
|
|
3
|
-
import
|
|
4
|
-
import { exec, execSync } from "node:child_process";
|
|
5
|
+
import { buildLspEnvironment } from "./lsp_client";
|
|
5
6
|
import {
|
|
6
7
|
PI_LSP_BIN_DIR,
|
|
7
8
|
LSP_SERVERS,
|
|
@@ -10,15 +11,7 @@ import {
|
|
|
10
11
|
} from "./lsp_registry";
|
|
11
12
|
import { kernelDebug } from "../safety/kernel_debug";
|
|
12
13
|
|
|
13
|
-
|
|
14
|
-
* Ensure ~/.pi/lsp/bin directory exists
|
|
15
|
-
*/
|
|
16
|
-
export function ensureLspBinDir(): string {
|
|
17
|
-
if (!fs.existsSync(PI_LSP_BIN_DIR)) {
|
|
18
|
-
fs.mkdirSync(PI_LSP_BIN_DIR, { recursive: true });
|
|
19
|
-
}
|
|
20
|
-
return PI_LSP_BIN_DIR;
|
|
21
|
-
}
|
|
14
|
+
const DEFAULT_INSTALL_TIMEOUT_MS = 120_000;
|
|
22
15
|
|
|
23
16
|
export interface InstallResult {
|
|
24
17
|
success: boolean;
|
|
@@ -26,579 +19,302 @@ export interface InstallResult {
|
|
|
26
19
|
binPath?: string;
|
|
27
20
|
}
|
|
28
21
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
const norm = languageOrKey.toLowerCase().trim();
|
|
37
|
-
ensureLspBinDir();
|
|
38
|
-
|
|
39
|
-
onProgress?.(`Resolving server installer for '${norm}'...`);
|
|
40
|
-
|
|
41
|
-
// TypeScript / JavaScript: Install @vtsls/language-server + typescript
|
|
42
|
-
if (
|
|
43
|
-
norm === "typescript" ||
|
|
44
|
-
norm === "ts" ||
|
|
45
|
-
norm === "javascript" ||
|
|
46
|
-
norm === "js"
|
|
47
|
-
) {
|
|
48
|
-
onProgress?.("Installing @vtsls/language-server & typescript via npm...");
|
|
49
|
-
try {
|
|
50
|
-
execSync(`npm install -g @vtsls/language-server typescript`, {
|
|
51
|
-
stdio: "pipe",
|
|
52
|
-
});
|
|
53
|
-
clearExecutableCache();
|
|
54
|
-
const bin = findExecutable("vtsls");
|
|
55
|
-
return {
|
|
56
|
-
success: true,
|
|
57
|
-
message: `Successfully installed vtsls (${bin || "vtsls"})`,
|
|
58
|
-
binPath: bin || undefined,
|
|
59
|
-
};
|
|
60
|
-
} catch (e: any) {
|
|
61
|
-
return {
|
|
62
|
-
success: false,
|
|
63
|
-
message: `Failed to install vtsls: ${e.message}`,
|
|
64
|
-
};
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
// Python: Install Astral ty or pyright
|
|
69
|
-
if (norm === "python" || norm === "py") {
|
|
70
|
-
// Try uv first if available
|
|
71
|
-
const uvBin = findExecutable("uv");
|
|
72
|
-
if (uvBin) {
|
|
73
|
-
onProgress?.("Installing Astral 'ty' via uv...");
|
|
74
|
-
try {
|
|
75
|
-
execSync(`uv tool install ty`, { stdio: "pipe" });
|
|
76
|
-
clearExecutableCache();
|
|
77
|
-
const bin = findExecutable("ty");
|
|
78
|
-
if (bin) {
|
|
79
|
-
return {
|
|
80
|
-
success: true,
|
|
81
|
-
message: `Successfully installed Astral ty (${bin})`,
|
|
82
|
-
binPath: bin,
|
|
83
|
-
};
|
|
84
|
-
}
|
|
85
|
-
} catch (e) {
|
|
86
|
-
kernelDebug(e);
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
// Fall back to pyright via npm
|
|
91
|
-
onProgress?.("Installing pyright via npm...");
|
|
92
|
-
try {
|
|
93
|
-
execSync(`npm install -g pyright`, { stdio: "pipe" });
|
|
94
|
-
clearExecutableCache();
|
|
95
|
-
const bin = findExecutable("pyright-langserver");
|
|
96
|
-
return {
|
|
97
|
-
success: true,
|
|
98
|
-
message: `Successfully installed pyright (${bin || "pyright-langserver"})`,
|
|
99
|
-
binPath: bin || undefined,
|
|
100
|
-
};
|
|
101
|
-
} catch (e: any) {
|
|
102
|
-
return {
|
|
103
|
-
success: false,
|
|
104
|
-
message: `Failed to install python LSP: ${e.message}`,
|
|
105
|
-
};
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
// Rust: rust-analyzer via rustup
|
|
110
|
-
if (norm === "rust" || norm === "rs") {
|
|
111
|
-
onProgress?.("Installing rust-analyzer via rustup...");
|
|
112
|
-
try {
|
|
113
|
-
execSync(`rustup component add rust-analyzer`, { stdio: "pipe" });
|
|
114
|
-
clearExecutableCache();
|
|
115
|
-
const bin = findExecutable("rust-analyzer");
|
|
116
|
-
return {
|
|
117
|
-
success: true,
|
|
118
|
-
message: `Successfully installed rust-analyzer (${bin || "rust-analyzer"})`,
|
|
119
|
-
binPath: bin || undefined,
|
|
120
|
-
};
|
|
121
|
-
} catch (e: any) {
|
|
122
|
-
return {
|
|
123
|
-
success: false,
|
|
124
|
-
message: `Failed to install rust-analyzer: ${e.message}`,
|
|
125
|
-
};
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
// Go: gopls
|
|
130
|
-
if (norm === "go" || norm === "golang") {
|
|
131
|
-
onProgress?.("Installing gopls via go install...");
|
|
132
|
-
try {
|
|
133
|
-
execSync(`go install golang.org/x/tools/gopls@latest`, { stdio: "pipe" });
|
|
134
|
-
clearExecutableCache();
|
|
135
|
-
const bin = findExecutable("gopls");
|
|
136
|
-
return {
|
|
137
|
-
success: true,
|
|
138
|
-
message: `Successfully installed gopls (${bin || "gopls"})`,
|
|
139
|
-
binPath: bin || undefined,
|
|
140
|
-
};
|
|
141
|
-
} catch (e: any) {
|
|
142
|
-
return {
|
|
143
|
-
success: false,
|
|
144
|
-
message: `Failed to install gopls: ${e.message}`,
|
|
145
|
-
};
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
// TOML: taplo
|
|
150
|
-
if (norm === "toml" || norm === "taplo") {
|
|
151
|
-
onProgress?.("Installing taplo-cli via cargo...");
|
|
152
|
-
try {
|
|
153
|
-
execSync(`cargo install taplo-cli --locked --features lsp`, {
|
|
154
|
-
stdio: "pipe",
|
|
155
|
-
});
|
|
156
|
-
clearExecutableCache();
|
|
157
|
-
const bin = findExecutable("taplo");
|
|
158
|
-
return {
|
|
159
|
-
success: true,
|
|
160
|
-
message: `Successfully installed taplo (${bin || "taplo"})`,
|
|
161
|
-
binPath: bin || undefined,
|
|
162
|
-
};
|
|
163
|
-
} catch (e: any) {
|
|
164
|
-
return {
|
|
165
|
-
success: false,
|
|
166
|
-
message: `Failed to install taplo: ${e.message}`,
|
|
167
|
-
};
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
// Shell / Bash: bash-language-server via npm
|
|
172
|
-
if (norm === "shell" || norm === "bash" || norm === "sh") {
|
|
173
|
-
onProgress?.("Installing bash-language-server via npm...");
|
|
174
|
-
try {
|
|
175
|
-
execSync(`npm install -g bash-language-server`, { stdio: "pipe" });
|
|
176
|
-
clearExecutableCache();
|
|
177
|
-
const bin = findExecutable("bash-language-server");
|
|
178
|
-
return {
|
|
179
|
-
success: true,
|
|
180
|
-
message: `Successfully installed bash-language-server (${bin || "bash-language-server"})`,
|
|
181
|
-
binPath: bin || undefined,
|
|
182
|
-
};
|
|
183
|
-
} catch (e: any) {
|
|
184
|
-
return {
|
|
185
|
-
success: false,
|
|
186
|
-
message: `Failed to install bash-language-server: ${e.message}`,
|
|
187
|
-
};
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
// HTML: superhtml or vscode-html-language-server
|
|
192
|
-
if (norm === "html" || norm === "htm") {
|
|
193
|
-
onProgress?.("Installing superhtml via package manager...");
|
|
194
|
-
const isWindows = process.platform === "win32";
|
|
195
|
-
try {
|
|
196
|
-
if (isWindows) {
|
|
197
|
-
execSync(
|
|
198
|
-
`winget install kristoff-it.superhtml --accept-source-agreements --accept-package-agreements --silent`,
|
|
199
|
-
{ stdio: "pipe" },
|
|
200
|
-
);
|
|
201
|
-
} else if (process.platform === "darwin") {
|
|
202
|
-
execSync(`brew install superhtml`, { stdio: "pipe" });
|
|
203
|
-
}
|
|
204
|
-
} catch (e) {
|
|
205
|
-
kernelDebug(e);
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
clearExecutableCache();
|
|
209
|
-
let bin = findExecutable("superhtml");
|
|
210
|
-
if (bin) {
|
|
211
|
-
return {
|
|
212
|
-
success: true,
|
|
213
|
-
message: `Successfully installed superhtml (${bin})`,
|
|
214
|
-
binPath: bin,
|
|
215
|
-
};
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
// Fallback to vscode-langservers-extracted via npm
|
|
219
|
-
onProgress?.("Installing vscode-langservers-extracted via npm...");
|
|
220
|
-
try {
|
|
221
|
-
execSync(`npm install -g vscode-langservers-extracted`, {
|
|
222
|
-
stdio: "pipe",
|
|
223
|
-
});
|
|
224
|
-
clearExecutableCache();
|
|
225
|
-
bin = findExecutable("vscode-html-language-server");
|
|
226
|
-
return {
|
|
227
|
-
success: true,
|
|
228
|
-
message: `Successfully installed vscode-html-language-server (${bin || "vscode-html-language-server"})`,
|
|
229
|
-
binPath: bin || undefined,
|
|
230
|
-
};
|
|
231
|
-
} catch (e: any) {
|
|
232
|
-
return {
|
|
233
|
-
success: false,
|
|
234
|
-
message: `Failed to install HTML LSP: ${e.message}`,
|
|
235
|
-
};
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
// JSON: Biome (Rust ultra-fast) or vscode-json-language-server
|
|
240
|
-
if (norm === "json" || norm === "jsonc") {
|
|
241
|
-
onProgress?.("Installing Biome (Rust) via npm...");
|
|
242
|
-
try {
|
|
243
|
-
execSync(`npm install -g @biomejs/biome`, { stdio: "pipe" });
|
|
244
|
-
clearExecutableCache();
|
|
245
|
-
const bin = findExecutable("biome");
|
|
246
|
-
if (bin) {
|
|
247
|
-
return {
|
|
248
|
-
success: true,
|
|
249
|
-
message: `Successfully installed Biome (${bin})`,
|
|
250
|
-
binPath: bin,
|
|
251
|
-
};
|
|
252
|
-
}
|
|
253
|
-
} catch (e) {
|
|
254
|
-
kernelDebug(e);
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
onProgress?.("Installing vscode-langservers-extracted via npm...");
|
|
258
|
-
try {
|
|
259
|
-
execSync(`npm install -g vscode-langservers-extracted`, {
|
|
260
|
-
stdio: "pipe",
|
|
261
|
-
});
|
|
262
|
-
clearExecutableCache();
|
|
263
|
-
const bin = findExecutable("vscode-json-language-server");
|
|
264
|
-
return {
|
|
265
|
-
success: true,
|
|
266
|
-
message: `Successfully installed vscode-json-language-server (${bin || "vscode-json-language-server"})`,
|
|
267
|
-
binPath: bin || undefined,
|
|
268
|
-
};
|
|
269
|
-
} catch (e: any) {
|
|
270
|
-
return {
|
|
271
|
-
success: false,
|
|
272
|
-
message: `Failed to install JSON LSP: ${e.message}`,
|
|
273
|
-
};
|
|
274
|
-
}
|
|
275
|
-
}
|
|
22
|
+
export interface InstallerSpec {
|
|
23
|
+
command: string;
|
|
24
|
+
args: string[];
|
|
25
|
+
verifyBin: string;
|
|
26
|
+
label: string;
|
|
27
|
+
timeoutMs?: number;
|
|
28
|
+
}
|
|
276
29
|
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
const bin = findExecutable("yaml-language-server");
|
|
284
|
-
return {
|
|
285
|
-
success: true,
|
|
286
|
-
message: `Successfully installed yaml-language-server (${bin || "yaml-language-server"})`,
|
|
287
|
-
binPath: bin || undefined,
|
|
288
|
-
};
|
|
289
|
-
} catch (e: any) {
|
|
290
|
-
return {
|
|
291
|
-
success: false,
|
|
292
|
-
message: `Failed to install yaml-language-server: ${e.message}`,
|
|
293
|
-
};
|
|
294
|
-
}
|
|
295
|
-
}
|
|
30
|
+
export interface InstallerCommandResult {
|
|
31
|
+
status: number | null;
|
|
32
|
+
stdout?: string;
|
|
33
|
+
stderr?: string;
|
|
34
|
+
error?: Error;
|
|
35
|
+
}
|
|
296
36
|
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
success: false,
|
|
314
|
-
message: `Failed to install dockerfile-language-server: ${e.message}`,
|
|
315
|
-
};
|
|
316
|
-
}
|
|
317
|
-
}
|
|
37
|
+
export type InstallerCommandResolver = (
|
|
38
|
+
command: string,
|
|
39
|
+
) => string | null;
|
|
40
|
+
export type InstallerCommandRunner = (
|
|
41
|
+
command: string,
|
|
42
|
+
args: string[],
|
|
43
|
+
options: {
|
|
44
|
+
cwd: string;
|
|
45
|
+
env: Record<string, string>;
|
|
46
|
+
shell: false;
|
|
47
|
+
windowsHide: true;
|
|
48
|
+
timeout: number;
|
|
49
|
+
encoding: "utf8";
|
|
50
|
+
stdio: "pipe";
|
|
51
|
+
},
|
|
52
|
+
) => InstallerCommandResult;
|
|
318
53
|
|
|
319
|
-
|
|
320
|
-
if (
|
|
321
|
-
|
|
322
|
-
try {
|
|
323
|
-
execSync(`npm install -g intelephense`, { stdio: "pipe" });
|
|
324
|
-
clearExecutableCache();
|
|
325
|
-
const bin = findExecutable("intelephense");
|
|
326
|
-
return {
|
|
327
|
-
success: true,
|
|
328
|
-
message: `Successfully installed intelephense (${bin || "intelephense"})`,
|
|
329
|
-
binPath: bin || undefined,
|
|
330
|
-
};
|
|
331
|
-
} catch (e: any) {
|
|
332
|
-
return {
|
|
333
|
-
success: false,
|
|
334
|
-
message: `Failed to install intelephense: ${e.message}`,
|
|
335
|
-
};
|
|
336
|
-
}
|
|
54
|
+
export function ensureLspBinDir(): string {
|
|
55
|
+
if (!fs.existsSync(PI_LSP_BIN_DIR)) {
|
|
56
|
+
fs.mkdirSync(PI_LSP_BIN_DIR, { recursive: true });
|
|
337
57
|
}
|
|
58
|
+
return PI_LSP_BIN_DIR;
|
|
59
|
+
}
|
|
338
60
|
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
61
|
+
const NPM_INSTALL = (
|
|
62
|
+
packages: string[],
|
|
63
|
+
verifyBin: string,
|
|
64
|
+
label: string,
|
|
65
|
+
): InstallerSpec => ({
|
|
66
|
+
command: "npm",
|
|
67
|
+
args: ["install", "-g", ...packages],
|
|
68
|
+
verifyBin,
|
|
69
|
+
label,
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
const CARGO_INSTALL = (
|
|
73
|
+
crate: string,
|
|
74
|
+
version: string,
|
|
75
|
+
verifyBin: string,
|
|
76
|
+
label: string,
|
|
77
|
+
extraArgs: string[] = [],
|
|
78
|
+
): InstallerSpec => ({
|
|
79
|
+
command: "cargo",
|
|
80
|
+
args: ["install", "--locked", crate, "--version", version, ...extraArgs],
|
|
81
|
+
verifyBin,
|
|
82
|
+
label,
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
export function getInstallerSpecs(): Record<string, InstallerSpec[]> {
|
|
86
|
+
return {
|
|
87
|
+
typescript: [
|
|
88
|
+
NPM_INSTALL(
|
|
89
|
+
["@vtsls/language-server@0.3.0", "typescript@7.0.2"],
|
|
90
|
+
"vtsls",
|
|
91
|
+
"vtsls 0.3.0 and TypeScript 7.0.2",
|
|
92
|
+
),
|
|
93
|
+
],
|
|
94
|
+
python: [
|
|
95
|
+
{
|
|
96
|
+
command: "uv",
|
|
97
|
+
args: ["tool", "install", "ty==0.0.83"],
|
|
98
|
+
verifyBin: "ty",
|
|
99
|
+
label: "Astral ty 0.0.83",
|
|
100
|
+
},
|
|
101
|
+
NPM_INSTALL(["pyright@1.1.414"], "pyright-langserver", "Pyright 1.1.414"),
|
|
102
|
+
],
|
|
103
|
+
go: [
|
|
104
|
+
{
|
|
105
|
+
command: "go",
|
|
106
|
+
args: ["install", "golang.org/x/tools/gopls@v0.23.0"],
|
|
107
|
+
verifyBin: "gopls",
|
|
108
|
+
label: "gopls v0.23.0",
|
|
109
|
+
},
|
|
110
|
+
],
|
|
111
|
+
toml: [
|
|
112
|
+
CARGO_INSTALL(
|
|
113
|
+
"taplo-cli",
|
|
114
|
+
"0.10.0",
|
|
115
|
+
"taplo",
|
|
116
|
+
"Taplo CLI 0.10.0",
|
|
117
|
+
["--features", "lsp"],
|
|
118
|
+
),
|
|
119
|
+
],
|
|
120
|
+
shell: [
|
|
121
|
+
NPM_INSTALL(
|
|
122
|
+
["bash-language-server@5.8.1"],
|
|
123
|
+
"bash-language-server",
|
|
124
|
+
"bash-language-server 5.8.1",
|
|
125
|
+
),
|
|
126
|
+
],
|
|
127
|
+
html: [
|
|
128
|
+
NPM_INSTALL(
|
|
129
|
+
["vscode-langservers-extracted@4.10.0"],
|
|
130
|
+
"vscode-html-language-server",
|
|
131
|
+
"vscode-langservers-extracted 4.10.0",
|
|
132
|
+
),
|
|
133
|
+
],
|
|
134
|
+
json: [
|
|
135
|
+
NPM_INSTALL(
|
|
136
|
+
["@biomejs/biome@2.5.14"],
|
|
137
|
+
"biome",
|
|
138
|
+
"Biome 2.5.14",
|
|
139
|
+
),
|
|
140
|
+
NPM_INSTALL(
|
|
141
|
+
["vscode-langservers-extracted@4.10.0"],
|
|
142
|
+
"vscode-json-language-server",
|
|
143
|
+
"vscode-langservers-extracted 4.10.0",
|
|
144
|
+
),
|
|
145
|
+
],
|
|
146
|
+
yaml: [
|
|
147
|
+
NPM_INSTALL(
|
|
148
|
+
["yaml-language-server@1.24.0"],
|
|
149
|
+
"yaml-language-server",
|
|
150
|
+
"yaml-language-server 1.24.0",
|
|
151
|
+
),
|
|
152
|
+
],
|
|
153
|
+
docker: [
|
|
154
|
+
NPM_INSTALL(
|
|
155
|
+
["dockerfile-language-server-nodejs@0.15.0"],
|
|
156
|
+
"docker-langserver",
|
|
157
|
+
"dockerfile-language-server-nodejs 0.15.0",
|
|
158
|
+
),
|
|
159
|
+
],
|
|
160
|
+
php: [
|
|
161
|
+
NPM_INSTALL(
|
|
162
|
+
["intelephense@1.18.5"],
|
|
163
|
+
"intelephense",
|
|
164
|
+
"Intelephense 1.18.5",
|
|
165
|
+
),
|
|
166
|
+
],
|
|
167
|
+
typst: [
|
|
168
|
+
CARGO_INSTALL("tinymist", "0.15.2", "tinymist", "Tinymist 0.15.2"),
|
|
169
|
+
],
|
|
170
|
+
csharp: [
|
|
171
|
+
{
|
|
172
|
+
command: "dotnet",
|
|
173
|
+
args: ["tool", "install", "-g", "csharp-ls", "--version", "0.28.0"],
|
|
174
|
+
verifyBin: "csharp-ls",
|
|
175
|
+
label: "csharp-ls 0.28.0",
|
|
176
|
+
},
|
|
177
|
+
],
|
|
178
|
+
ruby: [
|
|
179
|
+
{
|
|
180
|
+
command: "gem",
|
|
181
|
+
args: ["install", "ruby-lsp", "--version", "0.26.11", "--no-document"],
|
|
182
|
+
verifyBin: "ruby-lsp",
|
|
183
|
+
label: "ruby-lsp 0.26.11",
|
|
184
|
+
},
|
|
185
|
+
],
|
|
186
|
+
sql: [
|
|
187
|
+
{
|
|
188
|
+
command: "go",
|
|
189
|
+
args: ["install", "github.com/sqls-server/sqls@v0.2.48"],
|
|
190
|
+
verifyBin: "sqls",
|
|
191
|
+
label: "sqls v0.2.48",
|
|
192
|
+
},
|
|
193
|
+
],
|
|
194
|
+
latex: [
|
|
195
|
+
CARGO_INSTALL("texlab", "4.3.2", "texlab", "Texlab 4.3.2"),
|
|
196
|
+
],
|
|
197
|
+
protobuf: [
|
|
198
|
+
CARGO_INSTALL("protols", "0.14.1", "protols", "Protols 0.14.1"),
|
|
199
|
+
],
|
|
200
|
+
};
|
|
201
|
+
}
|
|
344
202
|
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
execSync(
|
|
349
|
-
`winget install Artempyanykh.Marksman --accept-source-agreements --accept-package-agreements --silent`,
|
|
350
|
-
{ stdio: "pipe" },
|
|
351
|
-
);
|
|
352
|
-
} else if (process.platform === "darwin") {
|
|
353
|
-
execSync(`brew install marksman`, { stdio: "pipe" });
|
|
354
|
-
}
|
|
355
|
-
} catch (e) {
|
|
356
|
-
kernelDebug(e);
|
|
357
|
-
}
|
|
203
|
+
function defaultResolver(command: string): string | null {
|
|
204
|
+
return findExecutable(command, [], [process.cwd()]);
|
|
205
|
+
}
|
|
358
206
|
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
};
|
|
367
|
-
}
|
|
207
|
+
function defaultRunner(
|
|
208
|
+
command: string,
|
|
209
|
+
args: string[],
|
|
210
|
+
options: Parameters<InstallerCommandRunner>[2],
|
|
211
|
+
): InstallerCommandResult {
|
|
212
|
+
return crossSpawnSync(command, args, options);
|
|
213
|
+
}
|
|
368
214
|
|
|
215
|
+
export function executeInstallerSpec(
|
|
216
|
+
spec: InstallerSpec,
|
|
217
|
+
dependencies: {
|
|
218
|
+
resolve?: InstallerCommandResolver;
|
|
219
|
+
run?: InstallerCommandRunner;
|
|
220
|
+
verify?: (binName: string) => InstallResult;
|
|
221
|
+
} = {},
|
|
222
|
+
): InstallResult {
|
|
223
|
+
const resolve = dependencies.resolve || defaultResolver;
|
|
224
|
+
const run = dependencies.run || defaultRunner;
|
|
225
|
+
const verify = dependencies.verify || ((binName: string) =>
|
|
226
|
+
verifyInstalledBinary(binName));
|
|
227
|
+
|
|
228
|
+
let executable: string | null;
|
|
229
|
+
try {
|
|
230
|
+
executable = resolve(spec.command);
|
|
231
|
+
} catch (error) {
|
|
369
232
|
return {
|
|
370
233
|
success: false,
|
|
371
|
-
message:
|
|
372
|
-
"Please install marksman using your system package manager (e.g. winget, brew, or cargo install marksman).",
|
|
234
|
+
message: `Unable to resolve trusted ${spec.command} executable: ${error instanceof Error ? error.message : String(error)}`,
|
|
373
235
|
};
|
|
374
236
|
}
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
try {
|
|
381
|
-
if (isWindows) {
|
|
382
|
-
execSync(
|
|
383
|
-
`winget install LLVM.clangd --accept-source-agreements --accept-package-agreements --silent`,
|
|
384
|
-
{ stdio: "pipe" },
|
|
385
|
-
);
|
|
386
|
-
} else if (process.platform === "darwin") {
|
|
387
|
-
execSync(`brew install llvm`, { stdio: "pipe" });
|
|
388
|
-
}
|
|
389
|
-
clearExecutableCache();
|
|
390
|
-
const bin = findExecutable("clangd");
|
|
391
|
-
if (bin) {
|
|
392
|
-
return {
|
|
393
|
-
success: true,
|
|
394
|
-
message: `Successfully installed clangd (${bin})`,
|
|
395
|
-
binPath: bin,
|
|
396
|
-
};
|
|
397
|
-
}
|
|
398
|
-
} catch (e: any) {
|
|
399
|
-
return {
|
|
400
|
-
success: false,
|
|
401
|
-
message: `Failed to install clangd: ${e.message}`,
|
|
402
|
-
};
|
|
403
|
-
}
|
|
404
|
-
}
|
|
405
|
-
|
|
406
|
-
// Zig: zls
|
|
407
|
-
if (norm === "zig" || norm === "zls") {
|
|
408
|
-
onProgress?.("Installing zls...");
|
|
409
|
-
const isWindows = process.platform === "win32";
|
|
410
|
-
try {
|
|
411
|
-
if (isWindows) {
|
|
412
|
-
execSync(
|
|
413
|
-
`winget install zigtools.zls --accept-source-agreements --accept-package-agreements --silent`,
|
|
414
|
-
{ stdio: "pipe" },
|
|
415
|
-
);
|
|
416
|
-
} else if (process.platform === "darwin") {
|
|
417
|
-
execSync(`brew install zls`, { stdio: "pipe" });
|
|
418
|
-
}
|
|
419
|
-
clearExecutableCache();
|
|
420
|
-
const bin = findExecutable("zls");
|
|
421
|
-
if (bin) {
|
|
422
|
-
return {
|
|
423
|
-
success: true,
|
|
424
|
-
message: `Successfully installed zls (${bin})`,
|
|
425
|
-
binPath: bin,
|
|
426
|
-
};
|
|
427
|
-
}
|
|
428
|
-
} catch (e: any) {
|
|
429
|
-
return { success: false, message: `Failed to install zls: ${e.message}` };
|
|
430
|
-
}
|
|
237
|
+
if (!executable) {
|
|
238
|
+
return {
|
|
239
|
+
success: false,
|
|
240
|
+
message: `Required package manager '${spec.command}' was not found in a trusted executable directory.`,
|
|
241
|
+
};
|
|
431
242
|
}
|
|
432
243
|
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
const bin = findExecutable("lua-language-server");
|
|
448
|
-
if (bin) {
|
|
449
|
-
return {
|
|
450
|
-
success: true,
|
|
451
|
-
message: `Successfully installed lua-language-server (${bin})`,
|
|
452
|
-
binPath: bin,
|
|
453
|
-
};
|
|
454
|
-
}
|
|
455
|
-
} catch (e: any) {
|
|
456
|
-
return {
|
|
457
|
-
success: false,
|
|
458
|
-
message: `Failed to install lua-language-server: ${e.message}`,
|
|
459
|
-
};
|
|
244
|
+
try {
|
|
245
|
+
const result = run(executable, spec.args, {
|
|
246
|
+
cwd: os.homedir(),
|
|
247
|
+
env: buildLspEnvironment(),
|
|
248
|
+
shell: false,
|
|
249
|
+
windowsHide: true,
|
|
250
|
+
timeout: spec.timeoutMs || DEFAULT_INSTALL_TIMEOUT_MS,
|
|
251
|
+
encoding: "utf8",
|
|
252
|
+
stdio: "pipe",
|
|
253
|
+
});
|
|
254
|
+
if (result.error) throw result.error;
|
|
255
|
+
if (result.status !== 0) {
|
|
256
|
+
const detail = String(result.stderr || result.stdout || "").trim();
|
|
257
|
+
throw new Error(detail || `${spec.command} exited with status ${result.status}`);
|
|
460
258
|
}
|
|
259
|
+
return verify(spec.verifyBin);
|
|
260
|
+
} catch (error) {
|
|
261
|
+
return {
|
|
262
|
+
success: false,
|
|
263
|
+
message: `Failed to install ${spec.label}: ${error instanceof Error ? error.message : String(error)}`,
|
|
264
|
+
};
|
|
461
265
|
}
|
|
266
|
+
}
|
|
462
267
|
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
);
|
|
473
|
-
} else if (process.platform === "darwin") {
|
|
474
|
-
execSync(`brew install tinymist`, { stdio: "pipe" });
|
|
475
|
-
} else {
|
|
476
|
-
execSync(`cargo install --locked tinymist`, { stdio: "pipe" });
|
|
477
|
-
}
|
|
478
|
-
clearExecutableCache();
|
|
479
|
-
const bin = findExecutable("tinymist");
|
|
480
|
-
if (bin) {
|
|
481
|
-
return {
|
|
482
|
-
success: true,
|
|
483
|
-
message: `Successfully installed tinymist (${bin})`,
|
|
484
|
-
binPath: bin,
|
|
485
|
-
};
|
|
486
|
-
}
|
|
487
|
-
} catch (e: any) {
|
|
488
|
-
return {
|
|
489
|
-
success: false,
|
|
490
|
-
message: `Failed to install tinymist: ${e.message}`,
|
|
491
|
-
};
|
|
492
|
-
}
|
|
268
|
+
function verifyInstalledBinary(binName: string): InstallResult {
|
|
269
|
+
clearExecutableCache();
|
|
270
|
+
const bin = findExecutable(binName, [], [process.cwd()]);
|
|
271
|
+
if (bin) {
|
|
272
|
+
return {
|
|
273
|
+
success: true,
|
|
274
|
+
message: `Successfully installed ${binName} (${bin})`,
|
|
275
|
+
binPath: bin,
|
|
276
|
+
};
|
|
493
277
|
}
|
|
278
|
+
return {
|
|
279
|
+
success: false,
|
|
280
|
+
message: `Installer completed, but trusted binary '${binName}' was not found.`,
|
|
281
|
+
};
|
|
282
|
+
}
|
|
494
283
|
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
return {
|
|
503
|
-
success: true,
|
|
504
|
-
message: `Successfully installed csharp-ls (${bin || "csharp-ls"})`,
|
|
505
|
-
binPath: bin || undefined,
|
|
506
|
-
};
|
|
507
|
-
} catch (e: any) {
|
|
508
|
-
return {
|
|
509
|
-
success: false,
|
|
510
|
-
message: `Failed to install csharp-ls: ${e.message}`,
|
|
511
|
-
};
|
|
512
|
-
}
|
|
513
|
-
}
|
|
284
|
+
const MANUAL_INSTALLS: Record<string, string> = {
|
|
285
|
+
rust: "Install rust-analyzer through a reviewed rustup toolchain, then rerun /lsp install rust.",
|
|
286
|
+
markdown: "Install Marksman 2026-02-08 with your system package manager, then rerun /lsp install markdown.",
|
|
287
|
+
cpp: "Install reviewed LLVM/clangd 23.1.2, then rerun /lsp install cpp.",
|
|
288
|
+
zig: "Install reviewed ZLS 0.16.0, then rerun /lsp install zig.",
|
|
289
|
+
lua: "Install reviewed Lua Language Server 3.19.1, then rerun /lsp install lua.",
|
|
290
|
+
};
|
|
514
291
|
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
const bin = findExecutable("ruby-lsp");
|
|
522
|
-
return {
|
|
523
|
-
success: true,
|
|
524
|
-
message: `Successfully installed ruby-lsp (${bin || "ruby-lsp"})`,
|
|
525
|
-
binPath: bin || undefined,
|
|
526
|
-
};
|
|
527
|
-
} catch (e: any) {
|
|
528
|
-
return {
|
|
529
|
-
success: false,
|
|
530
|
-
message: `Failed to install ruby-lsp: ${e.message}`,
|
|
531
|
-
};
|
|
532
|
-
}
|
|
533
|
-
}
|
|
292
|
+
export async function installLanguageServer(
|
|
293
|
+
languageOrKey: string,
|
|
294
|
+
onProgress?: (msg: string) => void,
|
|
295
|
+
): Promise<InstallResult> {
|
|
296
|
+
const norm = languageOrKey.toLowerCase().trim();
|
|
297
|
+
ensureLspBinDir();
|
|
534
298
|
|
|
535
|
-
|
|
536
|
-
if (
|
|
537
|
-
onProgress?.("Installing sqls via go install...");
|
|
538
|
-
try {
|
|
539
|
-
execSync(`go install github.com/sqls-server/sqls@latest`, {
|
|
540
|
-
stdio: "pipe",
|
|
541
|
-
});
|
|
542
|
-
clearExecutableCache();
|
|
543
|
-
const bin = findExecutable("sqls");
|
|
544
|
-
return {
|
|
545
|
-
success: true,
|
|
546
|
-
message: `Successfully installed sqls (${bin || "sqls"})`,
|
|
547
|
-
binPath: bin || undefined,
|
|
548
|
-
};
|
|
549
|
-
} catch (e: any) {
|
|
550
|
-
return {
|
|
551
|
-
success: false,
|
|
552
|
-
message: `Failed to install sqls: ${e.message}`,
|
|
553
|
-
};
|
|
554
|
-
}
|
|
555
|
-
}
|
|
299
|
+
const manual = MANUAL_INSTALLS[norm];
|
|
300
|
+
if (manual) return { success: false, message: manual };
|
|
556
301
|
|
|
557
|
-
|
|
558
|
-
if (
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
return {
|
|
565
|
-
success: true,
|
|
566
|
-
message: `Successfully installed texlab (${bin || "texlab"})`,
|
|
567
|
-
binPath: bin || undefined,
|
|
568
|
-
};
|
|
569
|
-
} catch (e: any) {
|
|
570
|
-
return {
|
|
571
|
-
success: false,
|
|
572
|
-
message: `Failed to install texlab: ${e.message}`,
|
|
573
|
-
};
|
|
574
|
-
}
|
|
302
|
+
const specs = getInstallerSpecs()[norm];
|
|
303
|
+
if (!specs || specs.length === 0) {
|
|
304
|
+
const hint = LSP_SERVERS[norm]?.installHint;
|
|
305
|
+
return {
|
|
306
|
+
success: false,
|
|
307
|
+
message: `No pinned automated installer is available${hint ? `. Manual option: ${hint}` : "."}`,
|
|
308
|
+
};
|
|
575
309
|
}
|
|
576
310
|
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
onProgress?.(
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
return {
|
|
585
|
-
success: true,
|
|
586
|
-
message: `Successfully installed protols (${bin || "protols"})`,
|
|
587
|
-
binPath: bin || undefined,
|
|
588
|
-
};
|
|
589
|
-
} catch (e: any) {
|
|
590
|
-
return {
|
|
591
|
-
success: false,
|
|
592
|
-
message: `Failed to install protols: ${e.message}`,
|
|
593
|
-
};
|
|
594
|
-
}
|
|
311
|
+
let lastFailure = "No installer attempted";
|
|
312
|
+
for (const spec of specs) {
|
|
313
|
+
onProgress?.(`Installing ${spec.label} with trusted ${spec.command}...`);
|
|
314
|
+
const result = executeInstallerSpec(spec);
|
|
315
|
+
if (result.success) return result;
|
|
316
|
+
lastFailure = result.message;
|
|
317
|
+
kernelDebug(result.message);
|
|
595
318
|
}
|
|
596
|
-
|
|
597
|
-
const hint =
|
|
598
|
-
LSP_SERVERS[norm]?.installHint ||
|
|
599
|
-
"No automated installer available for this language.";
|
|
600
|
-
return {
|
|
601
|
-
success: false,
|
|
602
|
-
message: `Manual installation required for '${norm}'. Recommended: ${hint}`,
|
|
603
|
-
};
|
|
319
|
+
return { success: false, message: lastFailure };
|
|
604
320
|
}
|