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