@floydous/pi-agent-kernel 0.3.31 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -26,6 +26,22 @@ export interface InstallResult {
26
26
  binPath?: string;
27
27
  }
28
28
 
29
+ function verifyInstalledBinary(binName: string): InstallResult {
30
+ clearExecutableCache();
31
+ const bin = findExecutable(binName);
32
+ if (bin) {
33
+ return {
34
+ success: true,
35
+ message: `Successfully installed ${binName} (${bin})`,
36
+ binPath: bin,
37
+ };
38
+ }
39
+ return {
40
+ success: false,
41
+ message: `Installer completed, but binary '${binName}' was not found in PATH or LSP bin directory.`,
42
+ };
43
+ }
44
+
29
45
  /**
30
46
  * Install language server via npm, uv, cargo, or binary release
31
47
  */
@@ -49,14 +65,9 @@ export async function installLanguageServer(
49
65
  try {
50
66
  execSync(`npm install -g @vtsls/language-server typescript`, {
51
67
  stdio: "pipe",
68
+ timeout: 120_000,
52
69
  });
53
- clearExecutableCache();
54
- const bin = findExecutable("vtsls");
55
- return {
56
- success: true,
57
- message: `Successfully installed vtsls (${bin || "vtsls"})`,
58
- binPath: bin || undefined,
59
- };
70
+ return verifyInstalledBinary("vtsls");
60
71
  } catch (e: any) {
61
72
  return {
62
73
  success: false,
@@ -90,14 +101,8 @@ export async function installLanguageServer(
90
101
  // Fall back to pyright via npm
91
102
  onProgress?.("Installing pyright via npm...");
92
103
  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
- };
104
+ execSync(`npm install -g pyright`, { stdio: "pipe", timeout: 120_000 });
105
+ return verifyInstalledBinary("pyright-langserver");
101
106
  } catch (e: any) {
102
107
  return {
103
108
  success: false,
@@ -110,14 +115,8 @@ export async function installLanguageServer(
110
115
  if (norm === "rust" || norm === "rs") {
111
116
  onProgress?.("Installing rust-analyzer via rustup...");
112
117
  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
- };
118
+ execSync(`rustup component add rust-analyzer`, { stdio: "pipe", timeout: 120_000 });
119
+ return verifyInstalledBinary("rust-analyzer");
121
120
  } catch (e: any) {
122
121
  return {
123
122
  success: false,
@@ -130,14 +129,8 @@ export async function installLanguageServer(
130
129
  if (norm === "go" || norm === "golang") {
131
130
  onProgress?.("Installing gopls via go install...");
132
131
  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
- };
132
+ execSync(`go install golang.org/x/tools/gopls@latest`, { stdio: "pipe", timeout: 120_000 });
133
+ return verifyInstalledBinary("gopls");
141
134
  } catch (e: any) {
142
135
  return {
143
136
  success: false,
@@ -152,14 +145,9 @@ export async function installLanguageServer(
152
145
  try {
153
146
  execSync(`cargo install taplo-cli --locked --features lsp`, {
154
147
  stdio: "pipe",
148
+ timeout: 120_000,
155
149
  });
156
- clearExecutableCache();
157
- const bin = findExecutable("taplo");
158
- return {
159
- success: true,
160
- message: `Successfully installed taplo (${bin || "taplo"})`,
161
- binPath: bin || undefined,
162
- };
150
+ return verifyInstalledBinary("taplo");
163
151
  } catch (e: any) {
164
152
  return {
165
153
  success: false,
@@ -172,14 +160,8 @@ export async function installLanguageServer(
172
160
  if (norm === "shell" || norm === "bash" || norm === "sh") {
173
161
  onProgress?.("Installing bash-language-server via npm...");
174
162
  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
- };
163
+ execSync(`npm install -g bash-language-server`, { stdio: "pipe", timeout: 120_000 });
164
+ return verifyInstalledBinary("bash-language-server");
183
165
  } catch (e: any) {
184
166
  return {
185
167
  success: false,
@@ -258,14 +240,9 @@ export async function installLanguageServer(
258
240
  try {
259
241
  execSync(`npm install -g vscode-langservers-extracted`, {
260
242
  stdio: "pipe",
243
+ timeout: 120_000,
261
244
  });
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
- };
245
+ return verifyInstalledBinary("vscode-json-language-server");
269
246
  } catch (e: any) {
270
247
  return {
271
248
  success: false,
@@ -278,14 +255,8 @@ export async function installLanguageServer(
278
255
  if (norm === "yaml" || norm === "yml") {
279
256
  onProgress?.("Installing yaml-language-server via npm...");
280
257
  try {
281
- execSync(`npm install -g yaml-language-server`, { stdio: "pipe" });
282
- clearExecutableCache();
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
- };
258
+ execSync(`npm install -g yaml-language-server`, { stdio: "pipe", timeout: 120_000 });
259
+ return verifyInstalledBinary("yaml-language-server");
289
260
  } catch (e: any) {
290
261
  return {
291
262
  success: false,
@@ -300,14 +271,9 @@ export async function installLanguageServer(
300
271
  try {
301
272
  execSync(`npm install -g dockerfile-language-server-nodejs`, {
302
273
  stdio: "pipe",
274
+ timeout: 120_000,
303
275
  });
304
- clearExecutableCache();
305
- const bin = findExecutable("docker-langserver");
306
- return {
307
- success: true,
308
- message: `Successfully installed docker-langserver (${bin || "docker-langserver"})`,
309
- binPath: bin || undefined,
310
- };
276
+ return verifyInstalledBinary("docker-langserver");
311
277
  } catch (e: any) {
312
278
  return {
313
279
  success: false,
@@ -320,14 +286,8 @@ export async function installLanguageServer(
320
286
  if (norm === "php") {
321
287
  onProgress?.("Installing intelephense via npm...");
322
288
  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
- };
289
+ execSync(`npm install -g intelephense`, { stdio: "pipe", timeout: 120_000 });
290
+ return verifyInstalledBinary("intelephense");
331
291
  } catch (e: any) {
332
292
  return {
333
293
  success: false,
@@ -496,14 +456,8 @@ export async function installLanguageServer(
496
456
  if (norm === "csharp" || norm === "cs") {
497
457
  onProgress?.("Installing csharp-ls via dotnet tool...");
498
458
  try {
499
- execSync(`dotnet tool install -g csharp-ls`, { stdio: "pipe" });
500
- clearExecutableCache();
501
- const bin = findExecutable("csharp-ls");
502
- return {
503
- success: true,
504
- message: `Successfully installed csharp-ls (${bin || "csharp-ls"})`,
505
- binPath: bin || undefined,
506
- };
459
+ execSync(`dotnet tool install -g csharp-ls`, { stdio: "pipe", timeout: 120_000 });
460
+ return verifyInstalledBinary("csharp-ls");
507
461
  } catch (e: any) {
508
462
  return {
509
463
  success: false,
@@ -516,14 +470,8 @@ export async function installLanguageServer(
516
470
  if (norm === "ruby" || norm === "rb") {
517
471
  onProgress?.("Installing ruby-lsp via gem...");
518
472
  try {
519
- execSync(`gem install ruby-lsp`, { stdio: "pipe" });
520
- clearExecutableCache();
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
- };
473
+ execSync(`gem install ruby-lsp`, { stdio: "pipe", timeout: 120_000 });
474
+ return verifyInstalledBinary("ruby-lsp");
527
475
  } catch (e: any) {
528
476
  return {
529
477
  success: false,
@@ -538,14 +486,9 @@ export async function installLanguageServer(
538
486
  try {
539
487
  execSync(`go install github.com/sqls-server/sqls@latest`, {
540
488
  stdio: "pipe",
489
+ timeout: 120_000,
541
490
  });
542
- clearExecutableCache();
543
- const bin = findExecutable("sqls");
544
- return {
545
- success: true,
546
- message: `Successfully installed sqls (${bin || "sqls"})`,
547
- binPath: bin || undefined,
548
- };
491
+ return verifyInstalledBinary("sqls");
549
492
  } catch (e: any) {
550
493
  return {
551
494
  success: false,
@@ -558,14 +501,8 @@ export async function installLanguageServer(
558
501
  if (norm === "latex" || norm === "tex" || norm === "texlab") {
559
502
  onProgress?.("Installing texlab via cargo...");
560
503
  try {
561
- execSync(`cargo install --locked texlab`, { stdio: "pipe" });
562
- clearExecutableCache();
563
- const bin = findExecutable("texlab");
564
- return {
565
- success: true,
566
- message: `Successfully installed texlab (${bin || "texlab"})`,
567
- binPath: bin || undefined,
568
- };
504
+ execSync(`cargo install --locked texlab`, { stdio: "pipe", timeout: 120_000 });
505
+ return verifyInstalledBinary("texlab");
569
506
  } catch (e: any) {
570
507
  return {
571
508
  success: false,
@@ -578,14 +515,8 @@ export async function installLanguageServer(
578
515
  if (norm === "protobuf" || norm === "proto" || norm === "protols") {
579
516
  onProgress?.("Installing protols via cargo...");
580
517
  try {
581
- execSync(`cargo install --locked protols`, { stdio: "pipe" });
582
- clearExecutableCache();
583
- const bin = findExecutable("protols");
584
- return {
585
- success: true,
586
- message: `Successfully installed protols (${bin || "protols"})`,
587
- binPath: bin || undefined,
588
- };
518
+ execSync(`cargo install --locked protols`, { stdio: "pipe", timeout: 120_000 });
519
+ return verifyInstalledBinary("protols");
589
520
  } catch (e: any) {
590
521
  return {
591
522
  success: false,
@@ -1,7 +1,7 @@
1
1
  import * as fs from "node:fs";
2
2
  import * as path from "node:path";
3
3
  import * as os from "node:os";
4
- import { execSync } from "node:child_process";
4
+ import { execFileSync } from "node:child_process";
5
5
  import type { LspServerConfig } from "./lsp_types";
6
6
  import { getPiHomeDir, loadKernelConfig, saveGlobalKernelConfig } from "../config";
7
7
  import { kernelDebug } from "../safety/kernel_debug";
@@ -363,7 +363,7 @@ function isBinaryUsable(fullPath: string, binName: string): boolean {
363
363
  // but fail to execute if the component was never installed in the active toolchain.
364
364
  if (binName === "rust-analyzer") {
365
365
  try {
366
- execSync(`"${fullPath}" --version`, {
366
+ execFileSync(fullPath, ["--version"], {
367
367
  stdio: ["ignore", "ignore", "ignore"],
368
368
  timeout: 1500,
369
369
  });
@@ -457,36 +457,44 @@ export function findExecutable(
457
457
  }
458
458
  }
459
459
 
460
- // 2. System PATH lookup via which/where
461
- try {
462
- const cmd = isWindows ? `where "${binName}"` : `which "${binName}"`;
463
- const stdout = execSync(cmd, {
464
- stdio: ["pipe", "pipe", "ignore"],
465
- encoding: "utf8",
466
- timeout: 800,
467
- });
468
- const matches = stdout
469
- .split(/\r?\n/)
470
- .map((l) => l.trim())
471
- .filter((l) => l.length > 0 && fs.existsSync(l));
460
+ // 2. System PATH lookup without shell execution
461
+ const pathEnv = process.env.PATH || process.env.Path || "";
462
+ const pathDirs = pathEnv.split(path.delimiter).map((d) => d.trim()).filter(Boolean);
472
463
 
473
- if (matches.length > 0) {
474
- let selected = matches[0];
475
- if (isWindows) {
476
- // On Windows, prefer .cmd / .exe / .bat over extensionless bash scripts
477
- const preferred = matches.find((m) =>
478
- [".cmd", ".exe", ".bat"].some((ext) => m.toLowerCase().endsWith(ext)),
479
- );
480
- if (preferred) selected = preferred;
481
- }
464
+ const pathext = (isWindows ? (process.env.PATHEXT || ".COM;.EXE;.BAT;.CMD") : "")
465
+ .split(";")
466
+ .map((e) => e.trim().toLowerCase())
467
+ .filter(Boolean);
482
468
 
483
- if (isBinaryUsable(selected, binName)) {
484
- executableCache.set(binName, selected);
485
- return selected;
469
+ for (const dir of pathDirs) {
470
+ if (!dir || !fs.existsSync(dir)) continue;
471
+ const candidates = isWindows
472
+ ? [
473
+ ...pathext.map((ext) => `${binName}${ext}`),
474
+ `${binName}.cmd`,
475
+ `${binName}.exe`,
476
+ `${binName}.bat`,
477
+ binName,
478
+ ]
479
+ : [binName];
480
+
481
+ for (const cand of candidates) {
482
+ const fullPath = path.join(dir, cand);
483
+ try {
484
+ if (fs.existsSync(fullPath)) {
485
+ const stat = fs.statSync(fullPath);
486
+ if (stat.isFile()) {
487
+ if (!isBinaryUsable(fullPath, binName)) {
488
+ continue;
489
+ }
490
+ executableCache.set(binName, fullPath);
491
+ return fullPath;
492
+ }
493
+ }
494
+ } catch (e) {
495
+ kernelDebug(e);
486
496
  }
487
497
  }
488
- } catch (e) {
489
- kernelDebug(e);
490
498
  }
491
499
 
492
500
  executableCache.set(binName, null);