@procedures/node 0.0.0-stage → 0.1.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/CHANGELOG.md +5 -0
- package/LICENSE +21 -0
- package/README.md +342 -2
- package/dist/.tsbuildinfo +1 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +15 -0
- package/dist/index.js.map +1 -0
- package/dist/module.d.ts +13 -0
- package/dist/module.d.ts.map +1 -0
- package/dist/module.js +80 -0
- package/dist/module.js.map +1 -0
- package/dist/procedures/node/index.d.ts +5 -0
- package/dist/procedures/node/index.d.ts.map +1 -0
- package/dist/procedures/node/index.js +5 -0
- package/dist/procedures/node/index.js.map +1 -0
- package/dist/procedures/node/kill.d.ts +11 -0
- package/dist/procedures/node/kill.d.ts.map +1 -0
- package/dist/procedures/node/kill.js +25 -0
- package/dist/procedures/node/kill.js.map +1 -0
- package/dist/procedures/node/run.d.ts +18 -0
- package/dist/procedures/node/run.d.ts.map +1 -0
- package/dist/procedures/node/run.js +48 -0
- package/dist/procedures/node/run.js.map +1 -0
- package/dist/procedures/node/spawn.d.ts +14 -0
- package/dist/procedures/node/spawn.d.ts.map +1 -0
- package/dist/procedures/node/spawn.js +35 -0
- package/dist/procedures/node/spawn.js.map +1 -0
- package/dist/procedures/node/status.d.ts +11 -0
- package/dist/procedures/node/status.d.ts.map +1 -0
- package/dist/procedures/node/status.js +17 -0
- package/dist/procedures/node/status.js.map +1 -0
- package/dist/process-manager.d.ts +50 -0
- package/dist/process-manager.d.ts.map +1 -0
- package/dist/process-manager.js +92 -0
- package/dist/process-manager.js.map +1 -0
- package/dist/register.d.ts +8 -0
- package/dist/register.d.ts.map +1 -0
- package/dist/register.js +14 -0
- package/dist/register.js.map +1 -0
- package/dist/types.d.ts +83 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +90 -0
- package/dist/types.js.map +1 -0
- package/package.json +78 -3
- package/src/index.ts +18 -0
- package/src/module.ts +103 -0
- package/src/procedures/node/index.ts +4 -0
- package/src/procedures/node/kill.ts +30 -0
- package/src/procedures/node/run.ts +56 -0
- package/src/procedures/node/spawn.ts +39 -0
- package/src/procedures/node/status.ts +23 -0
- package/src/process-manager.ts +102 -0
- package/src/register.ts +17 -0
- package/src/types.ts +184 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"run.d.ts","sourceRoot":"","sources":["../../../src/procedures/node/run.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAGH,OAAO,KAAK,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAKlE;;GAEG;AACH,wBAAsB,OAAO,CAC3B,KAAK,EAAE,YAAY,EACnB,GAAG,CAAC,EAAE;IAAE,MAAM,CAAC,EAAE,WAAW,GAAG,SAAS,CAAA;CAAE,GACzC,OAAO,CAAC,aAAa,CAAC,CAgCxB"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* node.run procedure
|
|
3
|
+
*
|
|
4
|
+
* Runs a Node.js script and waits for completion.
|
|
5
|
+
*
|
|
6
|
+
* The script runs with the Node.js of the host (`process.execPath`), through `runCommand` of
|
|
7
|
+
* client-shell: the output has a limit, and the timeout and the signal kill the script and the
|
|
8
|
+
* processes that it started (deep dive WRP-10). Before, the output had no limit, and the timeout
|
|
9
|
+
* killed only the direct child.
|
|
10
|
+
*/
|
|
11
|
+
import { runCommand } from "@procedures/shell/command";
|
|
12
|
+
/** The end of the output that a timeout error shows. */
|
|
13
|
+
const ERROR_OUTPUT_CHARS = 2000;
|
|
14
|
+
/**
|
|
15
|
+
* Run a Node.js script and wait for completion
|
|
16
|
+
*/
|
|
17
|
+
export async function nodeRun(input, ctx) {
|
|
18
|
+
const { script, args = [], cwd, env, timeout, maxOutputBytes } = input;
|
|
19
|
+
const result = await runCommand(process.execPath, {
|
|
20
|
+
args: [script, ...args],
|
|
21
|
+
cwd,
|
|
22
|
+
env,
|
|
23
|
+
timeout,
|
|
24
|
+
signal: ctx?.signal,
|
|
25
|
+
maxOutputBytes,
|
|
26
|
+
});
|
|
27
|
+
if (result.error) {
|
|
28
|
+
throw new Error(`node did not start: ${result.error}`);
|
|
29
|
+
}
|
|
30
|
+
if (result.timedOut) {
|
|
31
|
+
const output = `${result.stdout}${result.stderr}`.slice(-ERROR_OUTPUT_CHARS);
|
|
32
|
+
throw new Error(`Process timed out after ${timeout}ms${output ? `. Output:\n${output}` : ""}`);
|
|
33
|
+
}
|
|
34
|
+
if (result.aborted) {
|
|
35
|
+
const error = new Error("node.run was aborted");
|
|
36
|
+
error.name = "AbortError";
|
|
37
|
+
throw error;
|
|
38
|
+
}
|
|
39
|
+
const output = {
|
|
40
|
+
exitCode: result.exitCode,
|
|
41
|
+
stdout: result.stdout,
|
|
42
|
+
stderr: result.stderr,
|
|
43
|
+
};
|
|
44
|
+
if (result.truncated)
|
|
45
|
+
output.truncated = true;
|
|
46
|
+
return output;
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=run.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"run.js","sourceRoot":"","sources":["../../../src/procedures/node/run.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AAGvD,wDAAwD;AACxD,MAAM,kBAAkB,GAAG,IAAI,CAAC;AAEhC;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,OAAO,CAC3B,KAAmB,EACnB,GAA0C;IAE1C,MAAM,EAAE,MAAM,EAAE,IAAI,GAAG,EAAE,EAAE,GAAG,EAAE,GAAG,EAAE,OAAO,EAAE,cAAc,EAAE,GAAG,KAAK,CAAC;IAEvE,MAAM,MAAM,GAAG,MAAM,UAAU,CAAC,OAAO,CAAC,QAAQ,EAAE;QAChD,IAAI,EAAE,CAAC,MAAM,EAAE,GAAG,IAAI,CAAC;QACvB,GAAG;QACH,GAAG;QACH,OAAO;QACP,MAAM,EAAE,GAAG,EAAE,MAAM;QACnB,cAAc;KACf,CAAC,CAAC;IAEH,IAAI,MAAM,CAAC,KAAK,EAAE,CAAC;QACjB,MAAM,IAAI,KAAK,CAAC,uBAAuB,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC;IACzD,CAAC;IACD,IAAI,MAAM,CAAC,QAAQ,EAAE,CAAC;QACpB,MAAM,MAAM,GAAG,GAAG,MAAM,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC,CAAC,kBAAkB,CAAC,CAAC;QAC7E,MAAM,IAAI,KAAK,CAAC,2BAA2B,OAAO,KAAK,MAAM,CAAC,CAAC,CAAC,cAAc,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;IACjG,CAAC;IACD,IAAI,MAAM,CAAC,OAAO,EAAE,CAAC;QACnB,MAAM,KAAK,GAAG,IAAI,KAAK,CAAC,sBAAsB,CAAC,CAAC;QAChD,KAAK,CAAC,IAAI,GAAG,YAAY,CAAC;QAC1B,MAAM,KAAK,CAAC;IACd,CAAC;IAED,MAAM,MAAM,GAAkB;QAC5B,QAAQ,EAAE,MAAM,CAAC,QAAQ;QACzB,MAAM,EAAE,MAAM,CAAC,MAAM;QACrB,MAAM,EAAE,MAAM,CAAC,MAAM;KACtB,CAAC;IACF,IAAI,MAAM,CAAC,SAAS;QAAE,MAAM,CAAC,SAAS,GAAG,IAAI,CAAC;IAC9C,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* node.spawn procedure
|
|
3
|
+
*
|
|
4
|
+
* Spawns a long-running Node.js process.
|
|
5
|
+
*
|
|
6
|
+
* The process is a record of the process registry of client-shell: node.status shows it,
|
|
7
|
+
* node.kill ends its whole tree, and it ends with the host (deep dive WRP-4, WRP-10).
|
|
8
|
+
*/
|
|
9
|
+
import type { NodeSpawnInput, NodeSpawnOutput } from "../../types.js";
|
|
10
|
+
/**
|
|
11
|
+
* Spawn a long-running Node.js process
|
|
12
|
+
*/
|
|
13
|
+
export declare function nodeSpawn(input: NodeSpawnInput): Promise<NodeSpawnOutput>;
|
|
14
|
+
//# sourceMappingURL=spawn.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"spawn.d.ts","sourceRoot":"","sources":["../../../src/procedures/node/spawn.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAGtE;;GAEG;AACH,wBAAsB,SAAS,CAAC,KAAK,EAAE,cAAc,GAAG,OAAO,CAAC,eAAe,CAAC,CAuB/E"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* node.spawn procedure
|
|
3
|
+
*
|
|
4
|
+
* Spawns a long-running Node.js process.
|
|
5
|
+
*
|
|
6
|
+
* The process is a record of the process registry of client-shell: node.status shows it,
|
|
7
|
+
* node.kill ends its whole tree, and it ends with the host (deep dive WRP-4, WRP-10).
|
|
8
|
+
*/
|
|
9
|
+
import { processManager } from "../../process-manager.js";
|
|
10
|
+
/**
|
|
11
|
+
* Spawn a long-running Node.js process
|
|
12
|
+
*/
|
|
13
|
+
export async function nodeSpawn(input) {
|
|
14
|
+
const { script, args = [], cwd, env, ready } = input;
|
|
15
|
+
const started = processManager.start(script, { args, cwd, env });
|
|
16
|
+
if (started.status === "error") {
|
|
17
|
+
throw new Error(`node did not start for ${script}`);
|
|
18
|
+
}
|
|
19
|
+
// Wait for ready pattern if specified
|
|
20
|
+
if (ready) {
|
|
21
|
+
try {
|
|
22
|
+
await processManager.waitForReady(started.processId, ready.pattern, ready.timeout ?? 30000);
|
|
23
|
+
}
|
|
24
|
+
catch (error) {
|
|
25
|
+
// A process that is not ready is of no use to the caller: stop it
|
|
26
|
+
await processManager.kill(started.processId);
|
|
27
|
+
throw error;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return {
|
|
31
|
+
processId: started.processId,
|
|
32
|
+
pid: started.pid,
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=spawn.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"spawn.js","sourceRoot":"","sources":["../../../src/procedures/node/spawn.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAE1D;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,SAAS,CAAC,KAAqB;IACnD,MAAM,EAAE,MAAM,EAAE,IAAI,GAAG,EAAE,EAAE,GAAG,EAAE,GAAG,EAAE,KAAK,EAAE,GAAG,KAAK,CAAC;IAErD,MAAM,OAAO,GAAG,cAAc,CAAC,KAAK,CAAC,MAAM,EAAE,EAAE,IAAI,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC,CAAC;IACjE,IAAI,OAAO,CAAC,MAAM,KAAK,OAAO,EAAE,CAAC;QAC/B,MAAM,IAAI,KAAK,CAAC,0BAA0B,MAAM,EAAE,CAAC,CAAC;IACtD,CAAC;IAED,sCAAsC;IACtC,IAAI,KAAK,EAAE,CAAC;QACV,IAAI,CAAC;YACH,MAAM,cAAc,CAAC,YAAY,CAAC,OAAO,CAAC,SAAS,EAAE,KAAK,CAAC,OAAO,EAAE,KAAK,CAAC,OAAO,IAAI,KAAK,CAAC,CAAC;QAC9F,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,kEAAkE;YAClE,MAAM,cAAc,CAAC,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;YAC7C,MAAM,KAAK,CAAC;QACd,CAAC;IACH,CAAC;IAED,OAAO;QACL,SAAS,EAAE,OAAO,CAAC,SAAS;QAC5B,GAAG,EAAE,OAAO,CAAC,GAAG;KACjB,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* node.status procedure
|
|
3
|
+
*
|
|
4
|
+
* Gets status of spawned Node.js processes.
|
|
5
|
+
*/
|
|
6
|
+
import type { NodeStatusInput, NodeStatusOutput } from "../../types.js";
|
|
7
|
+
/**
|
|
8
|
+
* Get status of running processes (and the recent exits)
|
|
9
|
+
*/
|
|
10
|
+
export declare function nodeStatus(input: NodeStatusInput): Promise<NodeStatusOutput>;
|
|
11
|
+
//# sourceMappingURL=status.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"status.d.ts","sourceRoot":"","sources":["../../../src/procedures/node/status.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAGxE;;GAEG;AACH,wBAAsB,UAAU,CAAC,KAAK,EAAE,eAAe,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAUlF"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* node.status procedure
|
|
3
|
+
*
|
|
4
|
+
* Gets status of spawned Node.js processes.
|
|
5
|
+
*/
|
|
6
|
+
import { processManager } from "../../process-manager.js";
|
|
7
|
+
/**
|
|
8
|
+
* Get status of running processes (and the recent exits)
|
|
9
|
+
*/
|
|
10
|
+
export async function nodeStatus(input) {
|
|
11
|
+
const { processId } = input;
|
|
12
|
+
const processes = processManager.getStatus(processId).map((info) => input.output ? { ...info, output: processManager.output(info.processId) } : info);
|
|
13
|
+
return {
|
|
14
|
+
processes,
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=status.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"status.js","sourceRoot":"","sources":["../../../src/procedures/node/status.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAE1D;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,UAAU,CAAC,KAAsB;IACrD,MAAM,EAAE,SAAS,EAAE,GAAG,KAAK,CAAC;IAE5B,MAAM,SAAS,GAAG,cAAc,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CACjE,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,GAAG,IAAI,EAAE,MAAM,EAAE,cAAc,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CACjF,CAAC;IAEF,OAAO;QACL,SAAS;KACV,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Process Manager - Manages spawned Node.js processes
|
|
3
|
+
*
|
|
4
|
+
* The manager is a view of the process registry of client-shell, for the group "node"
|
|
5
|
+
* (deep dive WRP-4, WRP-10):
|
|
6
|
+
* - `kill` ends the whole process tree, not only the direct child;
|
|
7
|
+
* - the registry reads the output of each process, so a full pipe does not stop it;
|
|
8
|
+
* - the processes end when the host ends (before, they were detached and kept running);
|
|
9
|
+
* - the registry removes old exit records, and `cleanup` removes the rest.
|
|
10
|
+
*/
|
|
11
|
+
import type { ProcessInfo } from "./types.js";
|
|
12
|
+
/** The group of the node processes in the process registry. */
|
|
13
|
+
export declare const NODE_GROUP = "node";
|
|
14
|
+
declare class ProcessManager {
|
|
15
|
+
/**
|
|
16
|
+
* Start a Node.js script and record it
|
|
17
|
+
*/
|
|
18
|
+
start(script: string, options: {
|
|
19
|
+
args?: string[] | undefined;
|
|
20
|
+
cwd?: string | undefined;
|
|
21
|
+
env?: Record<string, string> | undefined;
|
|
22
|
+
}): ProcessInfo;
|
|
23
|
+
/**
|
|
24
|
+
* Get a managed process by ID
|
|
25
|
+
*/
|
|
26
|
+
get(processId: string): ProcessInfo | undefined;
|
|
27
|
+
/**
|
|
28
|
+
* Kill a process (and the processes that it started) by ID, and wait for its end
|
|
29
|
+
*/
|
|
30
|
+
kill(processId: string, signal?: NodeJS.Signals): Promise<boolean>;
|
|
31
|
+
/**
|
|
32
|
+
* Wait for a ready pattern in the output
|
|
33
|
+
*/
|
|
34
|
+
waitForReady(processId: string, pattern: string, timeout?: number): Promise<void>;
|
|
35
|
+
/**
|
|
36
|
+
* The end of the output of a process (the last 64 KiB)
|
|
37
|
+
*/
|
|
38
|
+
output(processId: string): string;
|
|
39
|
+
/**
|
|
40
|
+
* Get status of all or specific processes
|
|
41
|
+
*/
|
|
42
|
+
getStatus(processId?: string): ProcessInfo[];
|
|
43
|
+
/**
|
|
44
|
+
* Cleanup exited processes
|
|
45
|
+
*/
|
|
46
|
+
cleanup(): number;
|
|
47
|
+
}
|
|
48
|
+
export declare const processManager: ProcessManager;
|
|
49
|
+
export {};
|
|
50
|
+
//# sourceMappingURL=process-manager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"process-manager.d.ts","sourceRoot":"","sources":["../src/process-manager.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAGH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAE9C,+DAA+D;AAC/D,eAAO,MAAM,UAAU,SAAS,CAAC;AAejC,cAAM,cAAc;IAClB;;OAEG;IACH,KAAK,CACH,MAAM,EAAE,MAAM,EACd,OAAO,EAAE;QAAE,IAAI,CAAC,EAAE,MAAM,EAAE,GAAG,SAAS,CAAC;QAAC,GAAG,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;QAAC,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,SAAS,CAAA;KAAE,GAC3G,WAAW,CASb;IAED;;OAEG;IACH,GAAG,CAAC,SAAS,EAAE,MAAM,GAAG,WAAW,GAAG,SAAS,CAG9C;IAED;;OAEG;IACG,IAAI,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,GAAE,MAAM,CAAC,OAAmB,GAAG,OAAO,CAAC,OAAO,CAAC,CAGlF;IAED;;OAEG;IACG,YAAY,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,GAAE,MAAc,GAAG,OAAO,CAAC,IAAI,CAAC,CAE7F;IAED;;OAEG;IACH,MAAM,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAEhC;IAED;;OAEG;IACH,SAAS,CAAC,SAAS,CAAC,EAAE,MAAM,GAAG,WAAW,EAAE,CAK3C;IAED;;OAEG;IACH,OAAO,IAAI,MAAM,CAMhB;CACF;AAGD,eAAO,MAAM,cAAc,EAAE,cAAqC,CAAC"}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Process Manager - Manages spawned Node.js processes
|
|
3
|
+
*
|
|
4
|
+
* The manager is a view of the process registry of client-shell, for the group "node"
|
|
5
|
+
* (deep dive WRP-4, WRP-10):
|
|
6
|
+
* - `kill` ends the whole process tree, not only the direct child;
|
|
7
|
+
* - the registry reads the output of each process, so a full pipe does not stop it;
|
|
8
|
+
* - the processes end when the host ends (before, they were detached and kept running);
|
|
9
|
+
* - the registry removes old exit records, and `cleanup` removes the rest.
|
|
10
|
+
*/
|
|
11
|
+
import { processes } from "@procedures/shell/command";
|
|
12
|
+
/** The group of the node processes in the process registry. */
|
|
13
|
+
export const NODE_GROUP = "node";
|
|
14
|
+
function toProcessInfo(info) {
|
|
15
|
+
const result = {
|
|
16
|
+
processId: info.id,
|
|
17
|
+
pid: info.pid,
|
|
18
|
+
script: info.label ?? info.args[0] ?? "",
|
|
19
|
+
status: info.status,
|
|
20
|
+
startedAt: info.startedAt,
|
|
21
|
+
};
|
|
22
|
+
if (info.exitCode !== undefined)
|
|
23
|
+
result.exitCode = info.exitCode;
|
|
24
|
+
if (info.exitedAt !== undefined)
|
|
25
|
+
result.exitedAt = info.exitedAt;
|
|
26
|
+
return result;
|
|
27
|
+
}
|
|
28
|
+
class ProcessManager {
|
|
29
|
+
/**
|
|
30
|
+
* Start a Node.js script and record it
|
|
31
|
+
*/
|
|
32
|
+
start(script, options) {
|
|
33
|
+
const info = processes.start(process.execPath, {
|
|
34
|
+
args: [script, ...(options.args ?? [])],
|
|
35
|
+
cwd: options.cwd,
|
|
36
|
+
env: options.env,
|
|
37
|
+
group: NODE_GROUP,
|
|
38
|
+
label: script,
|
|
39
|
+
});
|
|
40
|
+
return toProcessInfo(info);
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Get a managed process by ID
|
|
44
|
+
*/
|
|
45
|
+
get(processId) {
|
|
46
|
+
const info = processes.get(processId);
|
|
47
|
+
return info && info.group === NODE_GROUP ? toProcessInfo(info) : undefined;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Kill a process (and the processes that it started) by ID, and wait for its end
|
|
51
|
+
*/
|
|
52
|
+
async kill(processId, signal = "SIGTERM") {
|
|
53
|
+
if (!this.get(processId))
|
|
54
|
+
return false;
|
|
55
|
+
return (await processes.stop(processId, signal)).stopped;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Wait for a ready pattern in the output
|
|
59
|
+
*/
|
|
60
|
+
async waitForReady(processId, pattern, timeout = 30000) {
|
|
61
|
+
await processes.waitFor(processId, new RegExp(pattern), timeout);
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* The end of the output of a process (the last 64 KiB)
|
|
65
|
+
*/
|
|
66
|
+
output(processId) {
|
|
67
|
+
return this.get(processId) ? processes.output(processId) : "";
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Get status of all or specific processes
|
|
71
|
+
*/
|
|
72
|
+
getStatus(processId) {
|
|
73
|
+
return processes
|
|
74
|
+
.list({ group: NODE_GROUP })
|
|
75
|
+
.filter((info) => processId === undefined || info.id === processId)
|
|
76
|
+
.map(toProcessInfo);
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Cleanup exited processes
|
|
80
|
+
*/
|
|
81
|
+
cleanup() {
|
|
82
|
+
let cleaned = 0;
|
|
83
|
+
for (const info of processes.list({ group: NODE_GROUP })) {
|
|
84
|
+
if (info.exitedAt && processes.forget(info.id))
|
|
85
|
+
cleaned++;
|
|
86
|
+
}
|
|
87
|
+
return cleaned;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
// Singleton instance
|
|
91
|
+
export const processManager = new ProcessManager();
|
|
92
|
+
//# sourceMappingURL=process-manager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"process-manager.js","sourceRoot":"","sources":["../src/process-manager.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,SAAS,EAA2B,MAAM,2BAA2B,CAAC;AAG/E,+DAA+D;AAC/D,MAAM,CAAC,MAAM,UAAU,GAAG,MAAM,CAAC;AAEjC,SAAS,aAAa,CAAC,IAAwB;IAC7C,MAAM,MAAM,GAAgB;QAC1B,SAAS,EAAE,IAAI,CAAC,EAAE;QAClB,GAAG,EAAE,IAAI,CAAC,GAAG;QACb,MAAM,EAAE,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,EAAE;QACxC,MAAM,EAAE,IAAI,CAAC,MAAM;QACnB,SAAS,EAAE,IAAI,CAAC,SAAS;KAC1B,CAAC;IACF,IAAI,IAAI,CAAC,QAAQ,KAAK,SAAS;QAAE,MAAM,CAAC,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC;IACjE,IAAI,IAAI,CAAC,QAAQ,KAAK,SAAS;QAAE,MAAM,CAAC,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC;IACjE,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,MAAM,cAAc;IAClB;;OAEG;IACH,KAAK,CACH,MAAc,EACd,OAA4G;QAE5G,MAAM,IAAI,GAAG,SAAS,CAAC,KAAK,CAAC,OAAO,CAAC,QAAQ,EAAE;YAC7C,IAAI,EAAE,CAAC,MA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AU,EAAE,CAAC;aAC3B,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,SAAS,KAAK,SAAS,IAAI,IAAI,CAAC,EAAE,KAAK,SAAS,CAAC;aAClE,GAAG,CAAC,aAAa,CAAC,CAAC;IACxB,CAAC;IAED;;OAEG;IACH,OAAO;QACL,IAAI,OAAO,GAAG,CAAC,CAAC;QAChB,KAAK,MAAM,IAAI,IAAI,SAAS,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,UAAU,EAAE,CAAC,EAAE,CAAC;YACzD,IAAI,IAAI,CAAC,QAAQ,IAAI,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC;gBAAE,OAAO,EAAE,CAAC;QAC5D,CAAC;QACD,OAAO,OAAO,CAAC;IACjB,CAAC;CACF;AAED,qBAAqB;AACrB,MAAM,CAAC,MAAM,cAAc,GAAmB,IAAI,cAAc,EAAE,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Importing this file registers the procedures of @procedures/node in the global registry
|
|
3
|
+
* (DECISIONS-2026-10, "Every package root registers its procedures"). The procedures as data
|
|
4
|
+
* are in `module.ts`, which registers nothing: a host with its own registry uses that one.
|
|
5
|
+
*/
|
|
6
|
+
export * from "./module.js";
|
|
7
|
+
export declare function registerNodeProcedures(): void;
|
|
8
|
+
//# sourceMappingURL=register.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"register.d.ts","sourceRoot":"","sources":["../src/register.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAKH,cAAc,aAAa,CAAC;AAE5B,wBAAgB,sBAAsB,IAAI,IAAI,CAE7C"}
|
package/dist/register.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Importing this file registers the procedures of @procedures/node in the global registry
|
|
3
|
+
* (DECISIONS-2026-10, "Every package root registers its procedures"). The procedures as data
|
|
4
|
+
* are in `module.ts`, which registers nothing: a host with its own registry uses that one.
|
|
5
|
+
*/
|
|
6
|
+
import { registerProcedures } from "@procedures/client";
|
|
7
|
+
import { nodeModule } from "./module.js";
|
|
8
|
+
export * from "./module.js";
|
|
9
|
+
export function registerNodeProcedures() {
|
|
10
|
+
registerProcedures(nodeModule.procedures);
|
|
11
|
+
}
|
|
12
|
+
// Auto-register when this module is loaded
|
|
13
|
+
registerNodeProcedures();
|
|
14
|
+
//# sourceMappingURL=register.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"register.js","sourceRoot":"","sources":["../src/register.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC,cAAc,aAAa,CAAC;AAE5B,MAAM,UAAU,sBAAsB;IACpC,kBAAkB,CAAC,UAAU,CAAC,UAAU,CAAC,CAAC;AAC5C,CAAC;AAED,2CAA2C;AAC3C,sBAAsB,EAAE,CAAC"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type definitions for client-node procedures
|
|
3
|
+
*/
|
|
4
|
+
import { z } from "zod";
|
|
5
|
+
export declare const NodeRunInputSchema: z.ZodObject<{
|
|
6
|
+
script: z.ZodString;
|
|
7
|
+
args: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
8
|
+
cwd: z.ZodOptional<z.ZodString>;
|
|
9
|
+
env: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
10
|
+
timeout: z.ZodOptional<z.ZodNumber>;
|
|
11
|
+
maxOutputBytes: z.ZodOptional<z.ZodNumber>;
|
|
12
|
+
}>;
|
|
13
|
+
export type NodeRunInput = z.infer<typeof NodeRunInputSchema>;
|
|
14
|
+
export interface NodeRunOutput {
|
|
15
|
+
/** Exit code of the process */
|
|
16
|
+
exitCode: number;
|
|
17
|
+
/** Standard output */
|
|
18
|
+
stdout: string;
|
|
19
|
+
/** Standard error */
|
|
20
|
+
stderr: string;
|
|
21
|
+
/** True when an output stream was longer than `maxOutputBytes` */
|
|
22
|
+
truncated?: boolean | undefined;
|
|
23
|
+
}
|
|
24
|
+
export declare const NodeSpawnInputSchema: z.ZodObject<{
|
|
25
|
+
script: z.ZodString;
|
|
26
|
+
args: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
27
|
+
cwd: z.ZodOptional<z.ZodString>;
|
|
28
|
+
env: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
29
|
+
ready: z.ZodOptional<z.ZodObject<{
|
|
30
|
+
pattern: z.ZodString;
|
|
31
|
+
timeout: z.ZodOptional<z.ZodNumber>;
|
|
32
|
+
}>>;
|
|
33
|
+
}>;
|
|
34
|
+
export type NodeSpawnInput = z.infer<typeof NodeSpawnInputSchema>;
|
|
35
|
+
export interface NodeSpawnOutput {
|
|
36
|
+
/** Unique process identifier for management */
|
|
37
|
+
processId: string;
|
|
38
|
+
/** OS process ID */
|
|
39
|
+
pid: number;
|
|
40
|
+
}
|
|
41
|
+
export declare const NodeKillInputSchema: z.ZodObject<{
|
|
42
|
+
processId: z.ZodString;
|
|
43
|
+
signal: z.ZodOptional<z.ZodString>;
|
|
44
|
+
}>;
|
|
45
|
+
export type NodeKillInput = z.infer<typeof NodeKillInputSchema>;
|
|
46
|
+
export interface NodeKillOutput {
|
|
47
|
+
/** Whether the kill was successful */
|
|
48
|
+
success: boolean;
|
|
49
|
+
/** Exit code if process exited */
|
|
50
|
+
exitCode?: number | undefined;
|
|
51
|
+
}
|
|
52
|
+
export declare const NodeStatusInputSchema: z.ZodObject<{
|
|
53
|
+
processId: z.ZodOptional<z.ZodString>;
|
|
54
|
+
output: z.ZodOptional<z.ZodBoolean>;
|
|
55
|
+
}>;
|
|
56
|
+
export type NodeStatusInput = z.infer<typeof NodeStatusInputSchema>;
|
|
57
|
+
export interface ProcessInfo {
|
|
58
|
+
/** Process identifier */
|
|
59
|
+
processId: string;
|
|
60
|
+
/** OS process ID */
|
|
61
|
+
pid: number;
|
|
62
|
+
/** Script path */
|
|
63
|
+
script: string;
|
|
64
|
+
/** Current status */
|
|
65
|
+
status: "running" | "exited" | "error";
|
|
66
|
+
/** Exit code if exited */
|
|
67
|
+
exitCode?: number | undefined;
|
|
68
|
+
/** Start time */
|
|
69
|
+
startedAt: string;
|
|
70
|
+
/** Exit time if exited */
|
|
71
|
+
exitedAt?: string | undefined;
|
|
72
|
+
/** With `output: true`, the end of the output */
|
|
73
|
+
output?: string | undefined;
|
|
74
|
+
}
|
|
75
|
+
export interface NodeStatusOutput {
|
|
76
|
+
/** List of processes */
|
|
77
|
+
processes: ProcessInfo[];
|
|
78
|
+
}
|
|
79
|
+
export declare const NodeRunOutputSchema: z.ZodType<NodeRunOutput>;
|
|
80
|
+
export declare const NodeSpawnOutputSchema: z.ZodType<NodeSpawnOutput>;
|
|
81
|
+
export declare const NodeKillOutputSchema: z.ZodType<NodeKillOutput>;
|
|
82
|
+
export declare const NodeStatusOutputSchema: z.ZodType<NodeStatusOutput>;
|
|
83
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAMxB,eAAO,MAAM,kBAAkB,EAAE,CAAC,CAAC,SAAS,CAAC;IAC3C,MAAM,EAAE,CAAC,CAAC,SAAS,CAAC;IACpB,IAAI,EAAE,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC;IAC7C,GAAG,EAAE,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC;IAChC,GAAG,EAAE,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,S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AE,MAAM,GAAG,SAAS,CAAC;IAC9B,iDAAiD;IACjD,MAAM,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CAC7B;AAED,MAAM,WAAW,gBAAgB;IAC/B,wBAAwB;IACxB,SAAS,EAAE,WAAW,EAAE,CAAC;CAC1B;AAKD,eAAO,MAAM,mBAAmB,EAAE,CAAC,CAAC,OAAO,CAAC,aAAa,CAKvD,CAAC;AAEH,eAAO,MAAM,qBAAqB,EAAE,CAAC,CAAC,OAAO,CAAC,eAAe,CAG3D,CAAC;AAEH,eAAO,MAAM,oBAAoB,EAAE,CAAC,CAAC,OAAO,CAAC,cAAc,CAGzD,CAAC;AAEH,eAAO,MAAM,sBAAsB,EAAE,CAAC,CAAC,OAAO,CAAC,gBAAgB,CAe7D,CAAC"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type definitions for client-node procedures
|
|
3
|
+
*/
|
|
4
|
+
import { z } from "zod";
|
|
5
|
+
// ============================================================================
|
|
6
|
+
// node.run - Run script and wait for completion
|
|
7
|
+
// ============================================================================
|
|
8
|
+
export const NodeRunInputSchema = z.object({
|
|
9
|
+
/** Script path to run */
|
|
10
|
+
script: z.string().describe("Script path to run"),
|
|
11
|
+
/** Arguments to pass to the script */
|
|
12
|
+
args: z.array(z.string()).optional().describe("Arguments to pass to the script"),
|
|
13
|
+
/** Working directory */
|
|
14
|
+
cwd: z.string().optional().describe("Working directory"),
|
|
15
|
+
/** Environment variables */
|
|
16
|
+
env: z.record(z.string(), z.string()).optional().describe("Environment variables"),
|
|
17
|
+
/** Timeout in milliseconds. At the timeout, the script and its child processes are killed. */
|
|
18
|
+
timeout: z.number().optional().describe("Timeout in milliseconds. At the timeout, the script and its child processes are killed."),
|
|
19
|
+
/** The most bytes kept of each output stream (default: 64 MiB). The procedure keeps the first bytes. */
|
|
20
|
+
maxOutputBytes: z.number().int().positive().optional().describe("The most bytes kept of each output stream (default: 64 MiB). The procedure keeps the first bytes."),
|
|
21
|
+
});
|
|
22
|
+
// ============================================================================
|
|
23
|
+
// node.spawn - Spawn long-running process
|
|
24
|
+
// ============================================================================
|
|
25
|
+
export const NodeSpawnInputSchema = z.object({
|
|
26
|
+
/** Script path to run */
|
|
27
|
+
script: z.string().describe("Script path to run"),
|
|
28
|
+
/** Arguments to pass to the script */
|
|
29
|
+
args: z.array(z.string()).optional().describe("Arguments to pass to the script"),
|
|
30
|
+
/** Working directory */
|
|
31
|
+
cwd: z.string().optional().describe("Working directory"),
|
|
32
|
+
/** Environment variables */
|
|
33
|
+
env: z.record(z.string(), z.string()).optional().describe("Environment variables"),
|
|
34
|
+
/** Ready pattern - wait for this in stdout before returning */
|
|
35
|
+
ready: z
|
|
36
|
+
.object({
|
|
37
|
+
pattern: z.string(),
|
|
38
|
+
timeout: z.number().optional(),
|
|
39
|
+
})
|
|
40
|
+
.optional().describe("Ready pattern - wait for this in stdout before returning"),
|
|
41
|
+
});
|
|
42
|
+
// ============================================================================
|
|
43
|
+
// node.kill - Kill a spawned process
|
|
44
|
+
// ============================================================================
|
|
45
|
+
export const NodeKillInputSchema = z.object({
|
|
46
|
+
/** Process ID returned from node.spawn */
|
|
47
|
+
processId: z.string().describe("Process ID returned from node.spawn"),
|
|
48
|
+
/** Signal to send (default: SIGTERM) */
|
|
49
|
+
signal: z.string().optional().describe("Signal to send (default: SIGTERM)"),
|
|
50
|
+
});
|
|
51
|
+
// ============================================================================
|
|
52
|
+
// node.status - Get status of running processes
|
|
53
|
+
// ============================================================================
|
|
54
|
+
export const NodeStatusInputSchema = z.object({
|
|
55
|
+
/** Optional process ID to filter by */
|
|
56
|
+
processId: z.string().optional().describe("Optional process ID to filter by"),
|
|
57
|
+
/** Also give the end of the output of each process (the last 64 KiB) */
|
|
58
|
+
output: z.boolean().optional().describe("Also give the end of the output of each process (the last 64 KiB)"),
|
|
59
|
+
});
|
|
60
|
+
// Output schemas (roadmap 2.1). Loose objects: a field that a schema does not name stays in the
|
|
61
|
+
// result (a strict schema would remove it when the output is validated).
|
|
62
|
+
export const NodeRunOutputSchema = z.looseObject({
|
|
63
|
+
exitCode: z.number().describe("The exit code of the script"),
|
|
64
|
+
stdout: z.string().describe("The standard output"),
|
|
65
|
+
stderr: z.string().describe("The standard error"),
|
|
66
|
+
truncated: z.boolean().optional().describe("True when an output stream was longer than maxOutputBytes"),
|
|
67
|
+
});
|
|
68
|
+
export const NodeSpawnOutputSchema = z.looseObject({
|
|
69
|
+
processId: z.string().describe("The id of the process: node.kill and node.status take it"),
|
|
70
|
+
pid: z.number().describe("The process id of the operating system"),
|
|
71
|
+
});
|
|
72
|
+
export const NodeKillOutputSchema = z.looseObject({
|
|
73
|
+
success: z.boolean().describe("True when the process ended"),
|
|
74
|
+
exitCode: z.number().optional().describe("The exit code, when the process exited"),
|
|
75
|
+
});
|
|
76
|
+
export const NodeStatusOutputSchema = z.looseObject({
|
|
77
|
+
processes: z
|
|
78
|
+
.array(z.looseObject({
|
|
79
|
+
processId: z.string().describe("The id of the process"),
|
|
80
|
+
pid: z.number().describe("The process id of the operating system"),
|
|
81
|
+
script: z.string().describe("The script"),
|
|
82
|
+
status: z.enum(["running", "exited", "error"]).describe("The state of the process"),
|
|
83
|
+
exitCode: z.number().optional().describe("The exit code, when the process exited"),
|
|
84
|
+
startedAt: z.string().describe("The start time (ISO 8601)"),
|
|
85
|
+
exitedAt: z.string().optional().describe("The end time (ISO 8601), when the process ended"),
|
|
86
|
+
output: z.string().optional().describe("With output: true, the end of the output"),
|
|
87
|
+
}))
|
|
88
|
+
.describe("The processes of this host"),
|
|
89
|
+
});
|
|
90
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,+EAA+E;AAC/E,gDAAgD;AAChD,+EAA+E;AAE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,CAAC,IAAI,CAAC,CAAC,SAAS,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAC,CAAC,QAAQ,CAAC,0BAA0B,CAAC;QACnF,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,wCAAwC,CAAC;QAClF,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,2BAA2B,CAAC;QAC3D,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,iDAAiD,CAAC;QAC3F,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,0CAA0C,CAAC;KACnF,CAAC,CACH;SACA,QAAQ,CAAC,4BAA4B,CAAC;CAC1C,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,81 @@
|
|
|
1
1
|
{
|
|
2
|
+
"$schema": "https://json.schemastore.org/package",
|
|
2
3
|
"name": "@procedures/node",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
4
|
+
"version": "0.1.0",
|
|
5
|
+
"description": "Node.js process procedures: run scripts, spawn and manage long-running processes, with output caps and process-tree cleanup.",
|
|
6
|
+
"keywords": [
|
|
7
|
+
"node",
|
|
8
|
+
"process",
|
|
9
|
+
"spawn",
|
|
10
|
+
"process-manager",
|
|
11
|
+
"procedures"
|
|
12
|
+
],
|
|
13
|
+
"homepage": "https://mark1russell7.github.io/client/",
|
|
14
|
+
"bugs": {
|
|
15
|
+
"url": "https://github.com/mark1russell7/client/issues"
|
|
16
|
+
},
|
|
17
|
+
"repository": {
|
|
18
|
+
"type": "git",
|
|
19
|
+
"url": "git+https://github.com/mark1russell7/client.git",
|
|
20
|
+
"directory": "packages/client-node"
|
|
21
|
+
},
|
|
22
|
+
"license": "MIT",
|
|
23
|
+
"author": "Mark Russell (https://github.com/mark1russell7)",
|
|
24
|
+
"type": "module",
|
|
25
|
+
"main": "./dist/index.js",
|
|
26
|
+
"types": "./dist/index.d.ts",
|
|
27
|
+
"exports": {
|
|
28
|
+
".": {
|
|
29
|
+
"types": "./dist/index.d.ts",
|
|
30
|
+
"import": "./dist/index.js"
|
|
31
|
+
},
|
|
32
|
+
"./module": {
|
|
33
|
+
"types": "./dist/module.d.ts",
|
|
34
|
+
"import": "./dist/module.js"
|
|
35
|
+
},
|
|
36
|
+
"./register": {
|
|
37
|
+
"types": "./dist/register.d.ts",
|
|
38
|
+
"import": "./dist/register.js"
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
"files": [
|
|
42
|
+
"dist",
|
|
43
|
+
"src",
|
|
44
|
+
"!src/**/*.test.ts",
|
|
45
|
+
"!src/**/*.test.tsx",
|
|
46
|
+
"!src/**/__tests__",
|
|
47
|
+
"CHANGELOG.md"
|
|
48
|
+
],
|
|
49
|
+
"sideEffects": [
|
|
50
|
+
"./dist/index.js",
|
|
51
|
+
"./dist/register.js"
|
|
52
|
+
],
|
|
53
|
+
"engines": {
|
|
54
|
+
"node": ">=22"
|
|
55
|
+
},
|
|
56
|
+
"publishConfig": {
|
|
57
|
+
"access": "public",
|
|
58
|
+
"provenance": true
|
|
59
|
+
},
|
|
60
|
+
"dependencies": {
|
|
61
|
+
"@procedures/client": "0.1.0",
|
|
62
|
+
"@procedures/shell": "0.1.0",
|
|
63
|
+
"zod": "^4.6.5"
|
|
64
|
+
},
|
|
65
|
+
"devDependencies": {
|
|
66
|
+
"typescript": "^7.0.2",
|
|
67
|
+
"@types/node": "^22.0.0",
|
|
68
|
+
"@mark1russell7/cue": "^1.0.0",
|
|
69
|
+
"vitest": "^5.0.3"
|
|
70
|
+
},
|
|
71
|
+
"client": {
|
|
72
|
+
"procedures": "./dist/register.js"
|
|
73
|
+
},
|
|
74
|
+
"scripts": {
|
|
75
|
+
"build": "tsc -b",
|
|
76
|
+
"typecheck": "tsc --noEmit",
|
|
77
|
+
"clean": "rm -rf dist .tsbuildinfo",
|
|
78
|
+
"test": "vitest run",
|
|
79
|
+
"test:watch": "vitest"
|
|
80
|
+
}
|
|
6
81
|
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* client-node - Node.js process management procedures
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
// Importing the package registers its procedures, as in the other client packages (BUGS-2026-07 H18)
|
|
6
|
+
import "./register.js";
|
|
7
|
+
|
|
8
|
+
// Export types
|
|
9
|
+
export * from "./types.js";
|
|
10
|
+
|
|
11
|
+
// Export procedures
|
|
12
|
+
export { nodeRun } from "./procedures/node/run.js";
|
|
13
|
+
export { nodeSpawn } from "./procedures/node/spawn.js";
|
|
14
|
+
export { nodeKill } from "./procedures/node/kill.js";
|
|
15
|
+
export { nodeStatus } from "./procedures/node/status.js";
|
|
16
|
+
|
|
17
|
+
// Export process manager
|
|
18
|
+
export { processManager } from "./process-manager.js";
|