@cruxy/cli 0.20.0 → 0.21.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.
- package/dist/approval/classify.js +24 -0
- package/dist/approval/policy.js +7 -0
- package/dist/approval/prompt.js +7 -0
- package/dist/approval/types.d.ts +6 -0
- package/dist/brand/voice.d.ts +1 -1
- package/dist/brand/voice.js +1 -1
- package/dist/cli/commands/mcp.d.ts +9 -0
- package/dist/cli/commands/mcp.js +87 -0
- package/dist/cli/commands/run.js +22 -5
- package/dist/cli/program.js +2 -0
- package/dist/cli/session-factory.d.ts +2 -2
- package/dist/cli/session-factory.js +9 -2
- package/dist/config/schema.d.ts +228 -30
- package/dist/config/schema.js +55 -4
- package/dist/constants.d.ts +8 -0
- package/dist/constants.js +8 -0
- package/dist/errors/constructors.d.ts +17 -0
- package/dist/errors/constructors.js +46 -0
- package/dist/errors/types.d.ts +9 -0
- package/dist/errors/types.js +15 -0
- package/dist/lsp/transport.d.ts +6 -15
- package/dist/lsp/transport.js +10 -66
- package/dist/mcp/adapter.d.ts +44 -0
- package/dist/mcp/adapter.js +70 -0
- package/dist/mcp/bounds.d.ts +35 -0
- package/dist/mcp/bounds.js +36 -0
- package/dist/mcp/client.d.ts +19 -0
- package/dist/mcp/client.js +93 -0
- package/dist/mcp/demarcate.d.ts +12 -0
- package/dist/mcp/demarcate.js +71 -0
- package/dist/mcp/index.d.ts +9 -0
- package/dist/mcp/index.js +8 -0
- package/dist/mcp/service.d.ts +54 -0
- package/dist/mcp/service.js +99 -0
- package/dist/mcp/transport.d.ts +30 -0
- package/dist/mcp/transport.js +188 -0
- package/dist/mcp/trust-gate.d.ts +35 -0
- package/dist/mcp/trust-gate.js +40 -0
- package/dist/mcp/trust.d.ts +52 -0
- package/dist/mcp/trust.js +111 -0
- package/dist/mcp/types.d.ts +52 -0
- package/dist/mcp/types.js +7 -0
- package/dist/tools/registry.js +3 -1
- package/dist/tools/types.d.ts +15 -1
- package/dist/utils/child-tree.d.ts +35 -0
- package/dist/utils/child-tree.js +76 -0
- package/package.json +1 -1
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared no-orphan machinery for long-lived child processes (C.12 LSP servers,
|
|
3
|
+
* C.27 MCP servers). A child is spawned `detached` so it leads its own process
|
|
4
|
+
* group; every kill here uses a **negative-PID** `SIGKILL` so the whole tree —
|
|
5
|
+
* the child AND any grandchildren it forked (gopls's `go`, an MCP server's
|
|
6
|
+
* helper) — dies together.
|
|
7
|
+
*
|
|
8
|
+
* A per-session graceful shutdown covers the normal path, but a hard exit
|
|
9
|
+
* (Ctrl-C, an uncaught throw) would otherwise orphan these trees. So every live
|
|
10
|
+
* child's pid is tracked in one process-wide set and force-killed on teardown.
|
|
11
|
+
* Handlers are installed ONCE, lazily, on the first registration — so unit tests
|
|
12
|
+
* that never spawn a real process never install them.
|
|
13
|
+
*
|
|
14
|
+
* This module is deliberately transport-agnostic: LSP (Content-Length framing)
|
|
15
|
+
* and MCP (newline-delimited JSON) share the SAME backstop, so `killTrackedTrees`
|
|
16
|
+
* on exit reaps both and there is a single source of truth for "no orphans".
|
|
17
|
+
*/
|
|
18
|
+
/**
|
|
19
|
+
* Kill a process's entire group (POSIX negative-PID `SIGKILL`), falling back to
|
|
20
|
+
* a direct kill when there is no group (or on win32). Swallows errors — the
|
|
21
|
+
* process may already be gone.
|
|
22
|
+
*/
|
|
23
|
+
export function killTree(pid) {
|
|
24
|
+
if (pid === undefined)
|
|
25
|
+
return;
|
|
26
|
+
try {
|
|
27
|
+
process.kill(-pid, "SIGKILL");
|
|
28
|
+
}
|
|
29
|
+
catch {
|
|
30
|
+
try {
|
|
31
|
+
process.kill(pid, "SIGKILL");
|
|
32
|
+
}
|
|
33
|
+
catch {
|
|
34
|
+
/* already exited */
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
const livePids = new Set();
|
|
39
|
+
let handlersInstalled = false;
|
|
40
|
+
/**
|
|
41
|
+
* Force-kill the process group of every tracked-but-not-yet-shut-down child,
|
|
42
|
+
* then forget them. This is exactly what the `exit`/`SIGINT`/`SIGTERM`/`SIGHUP`
|
|
43
|
+
* handlers run — the last line against orphaned server trees on a hard exit.
|
|
44
|
+
* Exported so it is directly testable without raising real process signals.
|
|
45
|
+
* Idempotent: a second call is a no-op.
|
|
46
|
+
*/
|
|
47
|
+
export function killTrackedTrees() {
|
|
48
|
+
for (const pid of livePids)
|
|
49
|
+
killTree(pid);
|
|
50
|
+
livePids.clear();
|
|
51
|
+
}
|
|
52
|
+
/** Number of child trees currently tracked by the exit backstop (for tests). */
|
|
53
|
+
export function trackedTreeCount() {
|
|
54
|
+
return livePids.size;
|
|
55
|
+
}
|
|
56
|
+
function installExitHandlers() {
|
|
57
|
+
if (handlersInstalled)
|
|
58
|
+
return;
|
|
59
|
+
handlersInstalled = true;
|
|
60
|
+
process.once("exit", killTrackedTrees);
|
|
61
|
+
for (const sig of ["SIGINT", "SIGTERM", "SIGHUP"]) {
|
|
62
|
+
process.once(sig, () => {
|
|
63
|
+
killTrackedTrees();
|
|
64
|
+
// Restore default behavior and re-raise so the exit code is correct.
|
|
65
|
+
process.exit(130);
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
/** Track a live child for the exit backstop; returns a deregister callback. */
|
|
70
|
+
export function registerForCleanup(pid) {
|
|
71
|
+
if (pid === undefined)
|
|
72
|
+
return () => { };
|
|
73
|
+
installExitHandlers();
|
|
74
|
+
livePids.add(pid);
|
|
75
|
+
return () => livePids.delete(pid);
|
|
76
|
+
}
|