@procedures/node 0.0.0-stage → 0.2.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.
Files changed (55) hide show
  1. package/CHANGELOG.md +26 -0
  2. package/LICENSE +21 -0
  3. package/README.md +342 -2
  4. package/dist/.tsbuildinfo +1 -0
  5. package/dist/index.d.ts +11 -0
  6. package/dist/index.d.ts.map +1 -0
  7. package/dist/index.js +14 -0
  8. package/dist/index.js.map +1 -0
  9. package/dist/module.d.ts +19 -0
  10. package/dist/module.d.ts.map +1 -0
  11. package/dist/module.js +97 -0
  12. package/dist/module.js.map +1 -0
  13. package/dist/procedures/node/index.d.ts +5 -0
  14. package/dist/procedures/node/index.d.ts.map +1 -0
  15. package/dist/procedures/node/index.js +5 -0
  16. package/dist/procedures/node/index.js.map +1 -0
  17. package/dist/procedures/node/kill.d.ts +11 -0
  18. package/dist/procedures/node/kill.d.ts.map +1 -0
  19. package/dist/procedures/node/kill.js +25 -0
  20. package/dist/procedures/node/kill.js.map +1 -0
  21. package/dist/procedures/node/run.d.ts +18 -0
  22. package/dist/procedures/node/run.d.ts.map +1 -0
  23. package/dist/procedures/node/run.js +48 -0
  24. package/dist/procedures/node/run.js.map +1 -0
  25. package/dist/procedures/node/spawn.d.ts +14 -0
  26. package/dist/procedures/node/spawn.d.ts.map +1 -0
  27. package/dist/procedures/node/spawn.js +35 -0
  28. package/dist/procedures/node/spawn.js.map +1 -0
  29. package/dist/procedures/node/status.d.ts +11 -0
  30. package/dist/procedures/node/status.d.ts.map +1 -0
  31. package/dist/procedures/node/status.js +17 -0
  32. package/dist/procedures/node/status.js.map +1 -0
  33. package/dist/process-manager.d.ts +50 -0
  34. package/dist/process-manager.d.ts.map +1 -0
  35. package/dist/process-manager.js +92 -0
  36. package/dist/process-manager.js.map +1 -0
  37. package/dist/register.d.ts +7 -0
  38. package/dist/register.d.ts.map +1 -0
  39. package/dist/register.js +9 -0
  40. package/dist/register.js.map +1 -0
  41. package/dist/types.d.ts +83 -0
  42. package/dist/types.d.ts.map +1 -0
  43. package/dist/types.js +90 -0
  44. package/dist/types.js.map +1 -0
  45. package/package.json +77 -3
  46. package/src/index.ts +17 -0
  47. package/src/module.ts +121 -0
  48. package/src/procedures/node/index.ts +4 -0
  49. package/src/procedures/node/kill.ts +30 -0
  50. package/src/procedures/node/run.ts +56 -0
  51. package/src/procedures/node/spawn.ts +39 -0
  52. package/src/procedures/node/status.ts +23 -0
  53. package/src/process-manager.ts +102 -0
  54. package/src/register.ts +11 -0
  55. package/src/types.ts +184 -0
package/CHANGELOG.md ADDED
@@ -0,0 +1,26 @@
1
+ # @procedures/node
2
+
3
+ ## 0.2.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 76d0d64: **Breaking:** an import of a package registers nothing. The `./register` entry of a package registers its procedures, and the procedures of the modules that they need, in the global registry (ARCHITECTURE-PROPOSALS-2026-10, P9).
8
+
9
+ - `import "@procedures/git"` gives the exports and registers nothing. Use `import "@procedures/git/register"`, or give `gitModule` (`@procedures/git/module`) to `createRegistry()`.
10
+ - `import "@procedures/client/register"` registers the control flow (`client.chain` and the others) and `procedure.define`/`get`/`list`/`delete`. `createRegistry()` adds them to each new registry, as before. The new `registerClientProcedures(registry?)` does the same for any registry.
11
+ - Each `register<Name>Procedures(registry?)` function is in the module of its package, takes a registry (the global one by default) and registers the modules that the package requires. `registerBridge` (splay) and `register` (store) are now `registerSplayProcedures` and `registerStoreProcedures`. The old names stay for one version.
12
+ - `sideEffects` names only `./dist/register.js`, so a bundler can drop the rest of a package.
13
+ - The bundles require `clientModule`, so `@procedures/bundle-mcp/register` gives the whole tool surface.
14
+ - `lib new` makes `src/module.ts` and a root without side effects, and `procedure new` adds procedures to the module.
15
+
16
+ ### Patch Changes
17
+
18
+ - Updated dependencies [0cf4bea]
19
+ - Updated dependencies [44d3e30]
20
+ - Updated dependencies [76d0d64]
21
+ - @procedures/client@0.2.0
22
+ - @procedures/shell@0.2.0
23
+
24
+ ## 0.1.0
25
+
26
+ The first release on npm. The packages of the client monorepo have one version together.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025-2026 Mark Russell
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,343 @@
1
- # Temporary Holding Version
1
+ # @procedures/node
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ [![npm](https://img.shields.io/npm/v/@procedures/node?color=2346c4&label=npm)](https://www.npmjs.com/package/@procedures/node)
4
+
5
+ Node.js process management procedures for the client ecosystem. Provides procedures for running scripts, spawning long-running processes, and managing process lifecycles.
6
+
7
+ ## Architecture Overview
8
+
9
+ ```
10
+ ┌─────────────────────────────────────────────────────────────────────────────┐
11
+ │ Client Application │
12
+ │ │
13
+ │ await client.exec(["node", "run"], { script: "build.js" }) │
14
+ │ await client.exec(["node", "spawn"], { script: "server.js" }) │
15
+ │ await client.exec(["node", "kill"], { processId: "abc123" }) │
16
+ │ await client.exec(["node", "status"], {}) │
17
+ │ │
18
+ └─────────────────────────────────┬───────────────────────────────────────────┘
19
+ │
20
+ ▼
21
+ ┌─────────────────────────────────────────────────────────────────────────────┐
22
+ │ Procedure Registry │
23
+ │ │
24
+ │ ┌───────────────┐ ┌───────────────┐ ┌───────────────┐ ┌─────────────┐ │
25
+ │ │ node.run │ │ node.spawn │ │ node.kill │ │ node.status │ │
26
+ │ │ │ │ │ │ │ │ │ │
27
+ │ │ Run to │ │ Start │ │ Kill by │ │ List all │ │
28
+ │ │ completion │ │ detached │ │ process ID │ │ processes │ │
29
+ │ └───────┬───────┘ └───────┬───────┘ └───────┬───────┘ └──────┬──────┘ │
30
+ │ │ │ │ │ │
31
+ └───────────┼──────────────────┼──────────────────┼─────────────────┼────────┘
32
+ │ │ │ │
33
+ ▼ ▼ ▼ ▼
34
+ ┌─────────────────────────────────────────────────────────────────────────────┐
35
+ │ ProcessManager (Singleton) │
36
+ │ │
37
+ │ ┌─────────────────────────────────────────────────────────────────────┐ │
38
+ │ │ Active Processes Map │ │
39
+ │ │ │ │
40
+ │ │ processId: "abc123" ──► { script, pid, startedAt, status } │ │
41
+ │ │ processId: "def456" ──► { script, pid, startedAt, status } │ │
42
+ │ │ processId: "ghi789" ──► { script, pid, startedAt, status } │ │
43
+ │ │ │ │
44
+ │ └─────────────────────────────────────────────────────────────────────┘ │
45
+ │ │
46
+ └─────────────────────────────────────────────────────────────────────────────┘
47
+ │
48
+ ▼
49
+ ┌─────────────────────────────────────────────────────────────────────────────┐
50
+ │ Node.js child_process │
51
+ │ │
52
+ │ spawn("node", ["script.js"], { detached: true, stdio: "pipe" }) │
53
+ │ │
54
+ └─────────────────────────────────────────────────────────────────────────────┘
55
+ ```
56
+
57
+ ## Installation
58
+
59
+ ```bash
60
+ pnpm add @procedures/node
61
+ ```
62
+
63
+ ## Procedures
64
+
65
+ ### node.run
66
+
67
+ Run a Node.js script to completion and return the output.
68
+
69
+ ```typescript
70
+ import { Client } from "@procedures/client";
71
+
72
+ const result = await client.exec<{
73
+ stdout: string;
74
+ stderr: string;
75
+ exitCode: number;
76
+ }>(["node", "run"], {
77
+ script: "./scripts/build.js",
78
+ args: ["--production"],
79
+ cwd: "/path/to/project",
80
+ env: { NODE_ENV: "production" },
81
+ timeout: 60000 // 1 minute timeout
82
+ });
83
+
84
+ console.log("Exit code:", result.exitCode);
85
+ console.log("Output:", result.stdout);
86
+ ```
87
+
88
+ **Input Schema:**
89
+
90
+ | Field | Type | Required | Description |
91
+ |-------|------|----------|-------------|
92
+ | `script` | `string` | Yes | Path to script file |
93
+ | `args` | `string[]` | No | Command line arguments |
94
+ | `cwd` | `string` | No | Working directory |
95
+ | `env` | `Record<string, string>` | No | Environment variables |
96
+ | `timeout` | `number` | No | Timeout in milliseconds. At the timeout, the script and its child processes are killed, and the call throws. |
97
+ | `maxOutputBytes` | `number` | No | The most bytes kept of each output stream (default: 64 MiB) |
98
+
99
+ The script runs with the Node.js of the host (`process.execPath`). The signal of the call also kills the script and its child processes.
100
+
101
+ **Output Schema:**
102
+
103
+ | Field | Type | Description |
104
+ |-------|------|-------------|
105
+ | `stdout` | `string` | Standard output |
106
+ | `stderr` | `string` | Standard error |
107
+ | `exitCode` | `number` | Process exit code |
108
+ | `truncated` | `boolean` | Present when an output stream was longer than `maxOutputBytes` |
109
+
110
+ ### node.spawn
111
+
112
+ Start a long-running Node.js process. The process is a record of the process registry of `client-shell`: `node.status` shows it, `node.kill` ends it, and it ends with the host.
113
+
114
+ ```typescript
115
+ const result = await client.exec<{
116
+ processId: string;
117
+ pid: number;
118
+ }>(["node", "spawn"], {
119
+ script: "./server.js",
120
+ args: ["--port", "3000"],
121
+ cwd: "/path/to/project",
122
+ env: { NODE_ENV: "production" },
123
+ ready: { pattern: "Server listening on", timeout: 30000 } // Wait for this output
124
+ });
125
+
126
+ console.log("Process ID:", result.processId);
127
+ console.log("PID:", result.pid);
128
+ ```
129
+
130
+ **Input Schema:**
131
+
132
+ | Field | Type | Required | Description |
133
+ |-------|------|----------|-------------|
134
+ | `script` | `string` | Yes | Path to script file |
135
+ | `args` | `string[]` | No | Command line arguments |
136
+ | `cwd` | `string` | No | Working directory |
137
+ | `env` | `Record<string, string>` | No | Environment variables |
138
+ | `ready` | `{ pattern: string; timeout?: number }` | No | Wait until the output matches `pattern` (a regular expression). When the process does not get ready, the procedure stops it and throws. |
139
+
140
+ **Output Schema:**
141
+
142
+ | Field | Type | Description |
143
+ |-------|------|-------------|
144
+ | `processId` | `string` | Internal process identifier |
145
+ | `pid` | `number` | System process ID |
146
+
147
+ ### node.kill
148
+
149
+ Kill a spawned process by its process ID, with the processes that it started, and wait for its end.
150
+
151
+ ```typescript
152
+ const result = await client.exec<{
153
+ success: boolean;
154
+ }>(["node", "kill"], {
155
+ processId: "abc123"
156
+ });
157
+
158
+ if (result.success) {
159
+ console.log("Process killed successfully");
160
+ }
161
+ ```
162
+
163
+ **Input Schema:**
164
+
165
+ | Field | Type | Required | Description |
166
+ |-------|------|----------|-------------|
167
+ | `processId` | `string` | Yes | Process ID from spawn |
168
+
169
+ **Output Schema:**
170
+
171
+ | Field | Type | Description |
172
+ |-------|------|-------------|
173
+ | `success` | `boolean` | Whether kill succeeded |
174
+
175
+ ### node.status
176
+
177
+ Get status of all running processes or a specific one.
178
+
179
+ ```typescript
180
+ // Get all processes
181
+ const result = await client.exec<{
182
+ processes: ProcessInfo[];
183
+ }>(["node", "status"], {});
184
+
185
+ // Get specific process
186
+ const result = await client.exec<{
187
+ processes: ProcessInfo[];
188
+ }>(["node", "status"], {
189
+ processId: "abc123"
190
+ });
191
+
192
+ for (const proc of result.processes) {
193
+ console.log(`${proc.processId}: ${proc.status} (PID: ${proc.pid})`);
194
+ }
195
+ ```
196
+
197
+ **Input Schema:**
198
+
199
+ | Field | Type | Required | Description |
200
+ |-------|------|----------|-------------|
201
+ | `processId` | `string` | No | Specific process ID to query |
202
+ | `output` | `boolean` | No | Also give the end of the output of each process (the last 64 KiB) |
203
+
204
+ **Output Schema:**
205
+
206
+ | Field | Type | Description |
207
+ |-------|------|-------------|
208
+ | `processes` | `ProcessInfo[]` | Array of process information |
209
+
210
+ **ProcessInfo:**
211
+
212
+ | Field | Type | Description |
213
+ |-------|------|-------------|
214
+ | `processId` | `string` | Internal process identifier |
215
+ | `script` | `string` | Script path |
216
+ | `pid` | `number` | System process ID |
217
+ | `status` | `"running" \| "stopped"` | Process status |
218
+ | `startedAt` | `string` | ISO timestamp when started |
219
+
220
+ ## Process Lifecycle
221
+
222
+ ```
223
+ ┌─────────────┐ spawn() ┌─────────────┐
224
+ │ │ ───────────────► │ │
225
+ │ (none) │ │ running │
226
+ │ │ │ │
227
+ └─────────────┘ └──────┬──────┘
228
+ │
229
+ ┌───────────────────┼───────────────────┐
230
+ │ │ │
231
+ ▼ ▼ ▼
232
+ kill() called process exits crash/error
233
+ │ │ │
234
+ ▼ ▼ ▼
235
+ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐
236
+ │ stopped │ │ stopped │ │ stopped │
237
+ │ (killed) │ │ (exited) │ │ (crashed) │
238
+ └─────────────┘ └─────────────┘ └─────────────┘
239
+ ```
240
+
241
+ ## Ready Pattern Detection
242
+
243
+ To wait until a server is ready, give `ready.pattern` (and optionally `ready.timeout` in milliseconds):
244
+
245
+ ```typescript
246
+ // The spawn resolves when "Server listening on port" appears in stdout
247
+ const result = await client.exec(["node", "spawn"], {
248
+ script: "./server.js",
249
+ ready: { pattern: "Server listening on port", timeout: 30000 },
250
+ });
251
+ ```
252
+
253
+ ```
254
+ Timeline:
255
+
256
+ spawn() called
257
+ │
258
+ ▼
259
+ ┌─────────────────────────────────────────────┐
260
+ │ Process Starting │
261
+ │ │
262
+ │ stdout: "Loading configuration..." │
263
+ │ stdout: "Connecting to database..." │
264
+ │ stdout: "Server listening on port 3000" ◄──┼── Pattern matched!
265
+ │ │
266
+ └─────────────────────────────────────────────┘
267
+ │
268
+ ▼
269
+ Promise resolves with { processId, pid }
270
+ ```
271
+
272
+ ## Integration Example
273
+
274
+ ```typescript
275
+ import { Client, LocalTransport, PROCEDURE_REGISTRY } from "@procedures/client";
276
+ import "@procedures/node/register"; // registers its procedures
277
+
278
+ const client = new Client(new LocalTransport({ registry: PROCEDURE_REGISTRY }));
279
+
280
+ // Start a dev server
281
+ const server = await client.exec(["node", "spawn"], {
282
+ script: "./server.js",
283
+ args: ["--port", "3000"],
284
+ ready: { pattern: "listening on" },
285
+ env: { NODE_ENV: "development" }
286
+ });
287
+
288
+ console.log(`Server started with PID ${server.pid}`);
289
+
290
+ // Check status
291
+ const status = await client.exec(["node", "status"], {
292
+ processId: server.processId
293
+ });
294
+
295
+ console.log(`Status: ${status.processes[0].status}`);
296
+
297
+ // Cleanup
298
+ await client.exec(["node", "kill"], {
299
+ processId: server.processId
300
+ });
301
+ ```
302
+
303
+ ## Error Handling
304
+
305
+ ```typescript
306
+ try {
307
+ const result = await client.exec(["node", "run"], {
308
+ script: "./nonexistent.js"
309
+ });
310
+ } catch (error) {
311
+ if (error.code === "ENOENT") {
312
+ console.error("Script not found");
313
+ } else if (error.code === "TIMEOUT") {
314
+ console.error("Script timed out");
315
+ }
316
+ }
317
+ ```
318
+
319
+ ## Registration
320
+
321
+ Import the register entry to register all procedures:
322
+
323
+ ```typescript
324
+ import "@procedures/node/register"; // registers its procedures
325
+ ```
326
+
327
+ Or register manually:
328
+
329
+ ```typescript
330
+ import { registerNodeProcedures } from "@procedures/node";
331
+
332
+ registerNodeProcedures();
333
+ ```
334
+
335
+ ## Related Packages
336
+
337
+ - `@procedures/client` - Core client framework
338
+ - `@procedures/shell` - Shell command execution
339
+ - `@procedures/vite` - Vite dev server management
340
+
341
+ ## License
342
+
343
+ MIT