@mrclrchtr/supi-lsp 2.2.0 → 2.3.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.
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mrclrchtr/supi-core",
3
- "version": "2.2.0",
3
+ "version": "2.3.0",
4
4
  "description": "SuPi core — shared infrastructure for SuPi extensions (XML context tags, config system)",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -2,6 +2,48 @@
2
2
 
3
3
  import type { FileEntry, SessionEntry } from "@earendil-works/pi-coding-agent";
4
4
 
5
+ /**
6
+ * Minimal pi API surface needed to track the current session display name reactively.
7
+ * Accept `ExtensionAPI` or any object satisfying this shape.
8
+ */
9
+ export interface SessionNameTrackerHost {
10
+ on(event: string, handler: (...args: unknown[]) => unknown): void;
11
+ getSessionName(): string | undefined;
12
+ }
13
+
14
+ /**
15
+ * Create a reactive session-name tracker that stays consistent across
16
+ * session starts, renames, and shutdowns without polling.
17
+ *
18
+ * Subscribes to `session_start` (initial name), `session_info_changed`
19
+ * (renames via `/name`, `pi.setSessionName()`, or RPC), and
20
+ * `session_shutdown` (reset to `undefined`).
21
+ *
22
+ * @returns a zero-arg getter that always returns the current session name
23
+ *
24
+ * @example
25
+ * ```ts
26
+ * const getSessionName = createSessionNameTracker(pi);
27
+ * // …later, during tool execute or spinner rendering:
28
+ * const name = getSessionName();
29
+ * ```
30
+ */
31
+ export function createSessionNameTracker(pi: SessionNameTrackerHost): () => string | undefined {
32
+ let name: string | undefined;
33
+
34
+ pi.on("session_start", () => {
35
+ name = pi.getSessionName();
36
+ });
37
+ pi.on("session_info_changed", (event) => {
38
+ name = (event as { name?: string }).name;
39
+ });
40
+ pi.on("session_shutdown", () => {
41
+ name = undefined;
42
+ });
43
+
44
+ return () => name;
45
+ }
46
+
5
47
  /**
6
48
  * Resolve the active branch path using PI's append-only tree semantics.
7
49
  *
@@ -1,4 +1,8 @@
1
1
  // supi-core session domain — session utilities and registries.
2
2
 
3
3
  export { createRegistry, createSessionStateRegistry } from "./registry-utils.ts";
4
- export { getActiveBranchEntries } from "./session-utils.ts";
4
+ export type { SessionNameTrackerHost } from "./session-utils.ts";
5
+ export {
6
+ createSessionNameTracker,
7
+ getActiveBranchEntries,
8
+ } from "./session-utils.ts";
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mrclrchtr/supi-code-runtime",
3
- "version": "2.2.0",
3
+ "version": "2.3.0",
4
4
  "description": "SuPi code-runtime — shared workspace context, capability contracts, and canonical types for the code-understanding stack",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -29,7 +29,7 @@
29
29
  "!__tests__"
30
30
  ],
31
31
  "dependencies": {
32
- "@mrclrchtr/supi-core": "2.2.0"
32
+ "@mrclrchtr/supi-core": "2.3.0"
33
33
  },
34
34
  "bundledDependencies": [
35
35
  "@mrclrchtr/supi-core"
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mrclrchtr/supi-core",
3
- "version": "2.2.0",
3
+ "version": "2.3.0",
4
4
  "description": "SuPi core — shared infrastructure for SuPi extensions (XML context tags, config system)",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -2,6 +2,48 @@
2
2
 
3
3
  import type { FileEntry, SessionEntry } from "@earendil-works/pi-coding-agent";
4
4
 
5
+ /**
6
+ * Minimal pi API surface needed to track the current session display name reactively.
7
+ * Accept `ExtensionAPI` or any object satisfying this shape.
8
+ */
9
+ export interface SessionNameTrackerHost {
10
+ on(event: string, handler: (...args: unknown[]) => unknown): void;
11
+ getSessionName(): string | undefined;
12
+ }
13
+
14
+ /**
15
+ * Create a reactive session-name tracker that stays consistent across
16
+ * session starts, renames, and shutdowns without polling.
17
+ *
18
+ * Subscribes to `session_start` (initial name), `session_info_changed`
19
+ * (renames via `/name`, `pi.setSessionName()`, or RPC), and
20
+ * `session_shutdown` (reset to `undefined`).
21
+ *
22
+ * @returns a zero-arg getter that always returns the current session name
23
+ *
24
+ * @example
25
+ * ```ts
26
+ * const getSessionName = createSessionNameTracker(pi);
27
+ * // …later, during tool execute or spinner rendering:
28
+ * const name = getSessionName();
29
+ * ```
30
+ */
31
+ export function createSessionNameTracker(pi: SessionNameTrackerHost): () => string | undefined {
32
+ let name: string | undefined;
33
+
34
+ pi.on("session_start", () => {
35
+ name = pi.getSessionName();
36
+ });
37
+ pi.on("session_info_changed", (event) => {
38
+ name = (event as { name?: string }).name;
39
+ });
40
+ pi.on("session_shutdown", () => {
41
+ name = undefined;
42
+ });
43
+
44
+ return () => name;
45
+ }
46
+
5
47
  /**
6
48
  * Resolve the active branch path using PI's append-only tree semantics.
7
49
  *
@@ -1,4 +1,8 @@
1
1
  // supi-core session domain — session utilities and registries.
2
2
 
3
3
  export { createRegistry, createSessionStateRegistry } from "./registry-utils.ts";
4
- export { getActiveBranchEntries } from "./session-utils.ts";
4
+ export type { SessionNameTrackerHost } from "./session-utils.ts";
5
+ export {
6
+ createSessionNameTracker,
7
+ getActiveBranchEntries,
8
+ } from "./session-utils.ts";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mrclrchtr/supi-lsp",
3
- "version": "2.2.0",
3
+ "version": "2.3.0",
4
4
  "description": "SuPi LSP extension — Language Server Protocol integration for pi",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -38,8 +38,8 @@
38
38
  "vscode-jsonrpc": "^9.0.0",
39
39
  "vscode-languageserver-protocol": "^3.17.5",
40
40
  "vscode-languageserver-types": "^3.17.5",
41
- "@mrclrchtr/supi-code-runtime": "2.2.0",
42
- "@mrclrchtr/supi-core": "2.2.0"
41
+ "@mrclrchtr/supi-code-runtime": "2.3.0",
42
+ "@mrclrchtr/supi-core": "2.3.0"
43
43
  },
44
44
  "bundledDependencies": [
45
45
  "@mrclrchtr/supi-code-runtime",
@@ -2,7 +2,7 @@
2
2
  // Handles initialize handshake, document sync, shutdown, and crash recovery.
3
3
 
4
4
  // biome-ignore lint/style/noExcessiveLinesPerFile: LspClient remains a cohesive stateful wrapper; refresh logic is already split out.
5
- import { type ChildProcess, spawn } from "node:child_process";
5
+ import { type ChildProcess, execSync, spawn } from "node:child_process";
6
6
  import { existsSync } from "node:fs";
7
7
  import * as path from "node:path";
8
8
  import { recordDebugEvent } from "@mrclrchtr/supi-core/debug";
@@ -37,6 +37,31 @@ import { JsonRpcClient, JsonRpcRequestError } from "./transport.ts";
37
37
  const SHUTDOWN_TIMEOUT_MS = 5_000;
38
38
  const DIAGNOSTIC_WAIT_MS = 3_000;
39
39
 
40
+ // ── Process-tree cleanup ──────────────────────────────────────────────
41
+
42
+ /**
43
+ * Kill a process and all its descendants.
44
+ *
45
+ * On Unix, sends SIGTERM to the process group (negative PID).
46
+ * This requires the child to be spawned with `detached: true`.
47
+ * On Windows, uses `taskkill /T /F` to force-kill the entire tree.
48
+ */
49
+ function killProcessTree(pid: number): void {
50
+ if (process.platform === "win32") {
51
+ try {
52
+ execSync(`taskkill /PID ${pid} /T /F`, { stdio: "ignore" });
53
+ } catch {
54
+ // Process may have already exited — ignore.
55
+ }
56
+ return;
57
+ }
58
+ try {
59
+ process.kill(-pid, "SIGTERM");
60
+ } catch {
61
+ // Process group may already be dead — ignore.
62
+ }
63
+ }
64
+
40
65
  // ── Types ─────────────────────────────────────────────────────────────
41
66
  export type ClientStatus = "initializing" | "running" | "error" | "shutdown";
42
67
 
@@ -116,6 +141,10 @@ export class LspClient {
116
141
  cwd: this.root,
117
142
  stdio: ["pipe", "pipe", "pipe"],
118
143
  env: { ...process.env },
144
+ // Run the server in its own process group so we can atomically
145
+ // kill the entire tree (server + subprocesses like tsserver)
146
+ // with `process.kill(-pid, signal)` on Unix or `taskkill /T` on Windows.
147
+ detached: true,
119
148
  });
120
149
  } catch (err) {
121
150
  this._status = "error";
@@ -209,18 +238,26 @@ export class LspClient {
209
238
 
210
239
  this.rpc.dispose();
211
240
 
212
- // Wait briefly for clean exit, then force kill
213
- if (this.process.exitCode === null) {
214
- await new Promise<void>((resolve) => {
215
- const timer = setTimeout(() => {
216
- this.process?.kill("SIGTERM");
217
- resolve();
218
- }, 1_000);
219
- this.process?.on("exit", () => {
220
- clearTimeout(timer);
221
- resolve();
241
+ // Kill the entire process tree (server + subprocesses like tsserver).
242
+ // The LSP shutdown/exit protocol above should trigger a graceful exit,
243
+ // but the process-group kill ensures no orphans survive.
244
+ const pid = this.process.pid;
245
+ if (this.process.exitCode === null && pid) {
246
+ killProcessTree(pid);
247
+ if (process.platform !== "win32") {
248
+ // Escalate to SIGKILL after a brief grace period on Unix.
249
+ // Windows taskkill /F is already forceful.
250
+ await new Promise<void>((resolve) => {
251
+ setTimeout(() => {
252
+ try {
253
+ process.kill(-pid, "SIGKILL");
254
+ } catch {
255
+ // Already dead — ignore.
256
+ }
257
+ resolve();
258
+ }, 500);
222
259
  });
223
- });
260
+ }
224
261
  }
225
262
 
226
263
  this.openDocs.clear();