@tryglen/pi 0.6.6 → 0.6.8

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tryglen/pi",
3
- "version": "0.6.6",
3
+ "version": "0.6.8",
4
4
  "description": "Shared team memory for coding agents: automatic recall and capture on every turn via the glen CLI.",
5
5
  "keywords": [
6
6
  "pi-package",
@@ -47,6 +47,6 @@
47
47
  "@earendil-works/pi-coding-agent": "1.1.0",
48
48
  "@types/node": "^20.0.0",
49
49
  "typescript": "^5.5.0",
50
- "vitest": "^3.0.0"
50
+ "vitest": "^4.1.12"
51
51
  }
52
52
  }
@@ -1,6 +1,25 @@
1
1
  import { spawn } from "node:child_process";
2
2
 
3
3
  const HOOK_TIMEOUT_MS = 60_000;
4
+ const STDIO: ["pipe", "pipe", "ignore"] = ["pipe", "pipe", "ignore"];
5
+
6
+ // npm's Windows shim is glen.cmd, which only cmd.exe can start, and cmd.exe
7
+ // reports a missing program as exit 9009. Hook commands are fixed strings.
8
+ const LAUNCH = {
9
+ posix: {
10
+ start: (command: string) => {
11
+ const [bin = "glen", ...args] = command.split(" ");
12
+ return spawn(bin, args, { stdio: STDIO });
13
+ },
14
+ notFoundExitCode: undefined,
15
+ },
16
+ win32: {
17
+ start: (command: string) =>
18
+ spawn(command, { stdio: STDIO, shell: true, windowsHide: true }),
19
+ notFoundExitCode: 9009,
20
+ },
21
+ };
22
+ const launch = LAUNCH[process.platform === "win32" ? "win32" : "posix"];
4
23
 
5
24
  // Spawned directly because pi.exec can't write to the child's stdin, and the
6
25
  // hooks read their JSON payload from stdin. Never rejects on a glen failure.
@@ -12,8 +31,7 @@ export const runGlenHook = (
12
31
  { kind: "ok"; stdout: string } | { kind: "missing" } | { kind: "failed" }
13
32
  > =>
14
33
  new Promise((resolve) => {
15
- const [bin = "glen", ...args] = command.split(" ");
16
- const child = spawn(bin, args, { stdio: ["pipe", "pipe", "ignore"] });
34
+ const child = launch.start(command);
17
35
  const chunks: Buffer[] = [];
18
36
  const timer = setTimeout(() => child.kill("SIGKILL"), timeoutMs);
19
37
  child.stdout.on("data", (chunk: Buffer) => chunks.push(chunk));
@@ -23,9 +41,13 @@ export const runGlenHook = (
23
41
  clearTimeout(timer);
24
42
  resolve({ kind: error.code === "ENOENT" ? "missing" : "failed" });
25
43
  });
26
- child.on("close", () => {
44
+ child.on("close", (code) => {
27
45
  clearTimeout(timer);
28
- resolve({ kind: "ok", stdout: Buffer.concat(chunks).toString("utf8") });
46
+ resolve(
47
+ code === launch.notFoundExitCode
48
+ ? { kind: "missing" }
49
+ : { kind: "ok", stdout: Buffer.concat(chunks).toString("utf8") },
50
+ );
29
51
  });
30
52
  child.stdin.end(JSON.stringify(payload));
31
53
  });