@orkestrel/process 0.0.9 → 0.0.11
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/README.md +18 -23
- package/dist/src/core/index.cjs +33 -17
- package/dist/src/core/index.cjs.map +1 -1
- package/dist/src/core/index.d.cts +171 -148
- package/dist/src/core/index.d.ts +171 -148
- package/dist/src/core/index.js +33 -17
- package/dist/src/core/index.js.map +1 -1
- package/dist/src/server/index.cjs +157 -97
- package/dist/src/server/index.cjs.map +1 -1
- package/dist/src/server/index.d.cts +316 -93
- package/dist/src/server/index.d.ts +316 -93
- package/dist/src/server/index.js +157 -98
- package/dist/src/server/index.js.map +1 -1
- package/package.json +11 -12
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { EmitterErrorHandler } from '@orkestrel/emitter';
|
|
2
|
-
import { EmitterHooks } from '@orkestrel/emitter';
|
|
3
|
-
import { EmitterInterface } from '@orkestrel/emitter';
|
|
1
|
+
import type { EmitterErrorHandler } from '@orkestrel/emitter';
|
|
2
|
+
import type { EmitterHooks } from '@orkestrel/emitter';
|
|
3
|
+
import type { EmitterInterface } from '@orkestrel/emitter';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
|
-
* Creates the failure raised when a manager launch reuses a live id.
|
|
6
|
+
* Creates the `duplicate`-coded failure raised when a manager launch reuses a live id.
|
|
7
7
|
*
|
|
8
8
|
* @param id - The id already occupied by a live child
|
|
9
9
|
* @returns A typed duplicate-id failure
|
|
@@ -25,7 +25,8 @@ export declare function createDuplicateError(id: string): ProcessError;
|
|
|
25
25
|
export declare function createExecuteError(result: ExecuteResult, cause?: unknown): ProcessError;
|
|
26
26
|
|
|
27
27
|
/**
|
|
28
|
-
* Creates the failure raised when a public input is refused before anything is
|
|
28
|
+
* Creates the `invalid`-coded failure raised when a public input is refused before anything is
|
|
29
|
+
* spawned.
|
|
29
30
|
*
|
|
30
31
|
* @param subject - The rejected input named as the caller wrote it, such as `option 'grace'`
|
|
31
32
|
* @param value - The rejected value, carried as `context.value`
|
|
@@ -39,7 +40,8 @@ export declare function createExecuteError(result: ExecuteResult, cause?: unknow
|
|
|
39
40
|
export declare function createInvalidError(subject: string, value: unknown): ProcessError;
|
|
40
41
|
|
|
41
42
|
/**
|
|
42
|
-
* Creates the failure raised when a launch is attempted on a registry that is
|
|
43
|
+
* Creates the `protocol`-coded failure raised when a launch is attempted on a registry that is
|
|
44
|
+
* being destroyed.
|
|
43
45
|
*
|
|
44
46
|
* @param id - The id the refused launch asked for
|
|
45
47
|
* @returns A typed protocol failure
|
|
@@ -47,33 +49,33 @@ export declare function createInvalidError(subject: string, value: unknown): Pro
|
|
|
47
49
|
export declare function createProtocolError(id: string): ProcessError;
|
|
48
50
|
|
|
49
51
|
/**
|
|
50
|
-
*
|
|
52
|
+
* Configures a detached fire-and-forget spawn.
|
|
51
53
|
*
|
|
52
54
|
* @remarks
|
|
53
55
|
* A detached child owns no stdio and is never awaited, so the contract carries only the directory it
|
|
54
56
|
* starts in. Its environment comes from the command's own `environment` and `isolated`.
|
|
55
57
|
*/
|
|
56
58
|
export declare interface DetachOptions {
|
|
57
|
-
/**
|
|
59
|
+
/** Names the working directory. Default: the current working directory. */
|
|
58
60
|
readonly workspace?: string;
|
|
59
61
|
}
|
|
60
62
|
|
|
61
63
|
/**
|
|
62
|
-
*
|
|
64
|
+
* Supplies the lookup inputs for resolving a command file to an executable path.
|
|
63
65
|
*
|
|
64
66
|
* @remarks
|
|
65
67
|
* `workspace` is searched before `PATH`, matching Windows command semantics. `environment` is the
|
|
66
68
|
* child's effective environment, so the lookup reads the same `PATH` and `PATHEXT` the child will.
|
|
67
69
|
*/
|
|
68
70
|
export declare interface ExecutableOptions {
|
|
69
|
-
/**
|
|
71
|
+
/** Names the directory searched first. Default: the current working directory. */
|
|
70
72
|
readonly workspace?: string;
|
|
71
|
-
/**
|
|
73
|
+
/** Holds the child's effective environment. Default: the parent process environment. */
|
|
72
74
|
readonly environment?: Readonly<Record<string, string | undefined>>;
|
|
73
75
|
}
|
|
74
76
|
|
|
75
77
|
/**
|
|
76
|
-
*
|
|
78
|
+
* Represents the captured bytes and terminal facts one settled {@link ExecuteResult} is built from.
|
|
77
79
|
*
|
|
78
80
|
* @remarks
|
|
79
81
|
* Each byte field is trimmed to `limit` on a code-point boundary when the result is built, so a
|
|
@@ -81,13 +83,15 @@ export declare interface ExecutableOptions {
|
|
|
81
83
|
* that ended the run, when one did; its presence alone marks the run failed.
|
|
82
84
|
*/
|
|
83
85
|
export declare interface ExecuteInput {
|
|
84
|
-
/**
|
|
86
|
+
/** Holds the diagnostic command line. */
|
|
85
87
|
readonly command: string;
|
|
86
|
-
/**
|
|
88
|
+
/** Holds the retained standard-output bytes. */
|
|
87
89
|
readonly stdout: Uint8Array;
|
|
88
|
-
/**
|
|
90
|
+
/** Holds the retained standard-error bytes. */
|
|
89
91
|
readonly stderr: Uint8Array;
|
|
92
|
+
/** Holds the exit code. A spawn fault reports the host's negative errno for `execute` and `null` for `executeSync`. */
|
|
90
93
|
readonly code: number | null;
|
|
94
|
+
/** Holds the terminating signal name, or `null` when the process exited on its own. */
|
|
91
95
|
readonly signal: string | null;
|
|
92
96
|
/** If `true`, the run's own timeout elapsed; if `false`, it did not. */
|
|
93
97
|
readonly expired: boolean;
|
|
@@ -95,14 +99,14 @@ export declare interface ExecuteInput {
|
|
|
95
99
|
readonly aborted: boolean;
|
|
96
100
|
/** If `true`, a stream exceeded `limit`; if `false`, neither did. */
|
|
97
101
|
readonly truncated: boolean;
|
|
98
|
-
/**
|
|
102
|
+
/** Sets the maximum retained bytes for each stream. */
|
|
99
103
|
readonly limit: number;
|
|
100
|
-
/**
|
|
104
|
+
/** Carries the host fault that ended the run, when one did. */
|
|
101
105
|
readonly cause?: unknown;
|
|
102
106
|
}
|
|
103
107
|
|
|
104
108
|
/**
|
|
105
|
-
*
|
|
109
|
+
* Configures a one-shot run.
|
|
106
110
|
*
|
|
107
111
|
* @remarks
|
|
108
112
|
* A run is a fire-and-collect function, not a lifecycle entity, so it carries no emitter. `strict`
|
|
@@ -117,26 +121,26 @@ export declare interface ExecuteInput {
|
|
|
117
121
|
* that throws strands no process.
|
|
118
122
|
*/
|
|
119
123
|
export declare interface ExecuteOptions {
|
|
120
|
-
/**
|
|
124
|
+
/** Names the working directory. Default: the current working directory. */
|
|
121
125
|
readonly workspace?: string;
|
|
122
|
-
/**
|
|
126
|
+
/** Holds environment overrides merged over the parent environment; an `undefined` value unsets a key. */
|
|
123
127
|
readonly environment?: Readonly<Record<string, string | undefined>>;
|
|
124
|
-
/**
|
|
128
|
+
/** Holds the standard-input payload written to the child, including any NUL characters. */
|
|
125
129
|
readonly input?: string;
|
|
126
|
-
/**
|
|
130
|
+
/** Sets the milliseconds before the child is terminated. `0` or omitted disables the timeout. */
|
|
127
131
|
readonly timeout?: number;
|
|
128
|
-
/**
|
|
132
|
+
/** Sets the cooperative POSIX window between `SIGTERM` and `SIGKILL` when terminating. Default: {@link PROCESS_GRACE}. */
|
|
129
133
|
readonly grace?: number;
|
|
130
|
-
/**
|
|
134
|
+
/** Terminates the run and reports `aborted` when this signal aborts. */
|
|
131
135
|
readonly signal?: AbortSignal;
|
|
132
|
-
/** If `false`, resolve with the result
|
|
136
|
+
/** If `true`, reject on failure; if `false`, resolve with the result instead. Default: `true`. */
|
|
133
137
|
readonly strict?: boolean;
|
|
134
|
-
/**
|
|
138
|
+
/** Sets the maximum captured bytes for stdout and for stderr, each. Default: {@link PROCESS_OUTPUT}. */
|
|
135
139
|
readonly limit?: number;
|
|
136
140
|
}
|
|
137
141
|
|
|
138
142
|
/**
|
|
139
|
-
*
|
|
143
|
+
* Represents the settled outcome of a one-shot run: the buffered output and the terminal state.
|
|
140
144
|
*
|
|
141
145
|
* @remarks
|
|
142
146
|
* `failed` is `true` when the run timed out, was aborted, ended on a host fault, was ended by a
|
|
@@ -150,27 +154,28 @@ export declare interface ExecuteOptions {
|
|
|
150
154
|
* the host's negative errno for `execute`. A spawn fault reports `null` for `executeSync`.
|
|
151
155
|
*/
|
|
152
156
|
export declare interface ExecuteResult {
|
|
153
|
-
/**
|
|
157
|
+
/** Holds the command line that was run, for diagnostics. */
|
|
154
158
|
readonly command: string;
|
|
155
|
-
/**
|
|
159
|
+
/** Holds the captured standard output, byte-bounded by `limit`. */
|
|
156
160
|
readonly stdout: string;
|
|
157
|
-
/**
|
|
161
|
+
/** Holds the captured standard error, byte-bounded by `limit`. */
|
|
158
162
|
readonly stderr: string;
|
|
159
|
-
/**
|
|
163
|
+
/** Holds the exit code. A spawn fault reports the host's negative errno for `execute` and `null` for `executeSync`. */
|
|
160
164
|
readonly code: number | null;
|
|
165
|
+
/** Holds the terminating signal name, or `null` when the process exited on its own. */
|
|
161
166
|
readonly signal: string | null;
|
|
162
|
-
/**
|
|
167
|
+
/** Reports whether the run failed to complete successfully. */
|
|
163
168
|
readonly failed: boolean;
|
|
164
|
-
/**
|
|
169
|
+
/** Reports whether the run's `timeout` elapsed before completion. */
|
|
165
170
|
readonly expired: boolean;
|
|
166
|
-
/**
|
|
171
|
+
/** Reports whether the caller's `signal` aborted the run before completion. */
|
|
167
172
|
readonly aborted: boolean;
|
|
168
|
-
/**
|
|
173
|
+
/** Reports whether either captured stream omitted output because it exceeded `limit`. */
|
|
169
174
|
readonly truncated: boolean;
|
|
170
175
|
}
|
|
171
176
|
|
|
172
177
|
/**
|
|
173
|
-
*
|
|
178
|
+
* Configures a synchronous one-shot run.
|
|
174
179
|
*
|
|
175
180
|
* @remarks
|
|
176
181
|
* The synchronous host offers neither a cooperative termination window nor in-flight cancellation,
|
|
@@ -181,17 +186,17 @@ export declare interface ExecuteResult {
|
|
|
181
186
|
* `input` is standard-input payload and carries no NUL restriction.
|
|
182
187
|
*/
|
|
183
188
|
export declare interface ExecuteSyncOptions {
|
|
184
|
-
/**
|
|
189
|
+
/** Names the working directory. Default: the current working directory. */
|
|
185
190
|
readonly workspace?: string;
|
|
186
|
-
/**
|
|
191
|
+
/** Holds environment overrides merged over the parent environment; an `undefined` value unsets a key. */
|
|
187
192
|
readonly environment?: Readonly<Record<string, string | undefined>>;
|
|
188
|
-
/**
|
|
193
|
+
/** Holds the standard-input payload written to the child, including any NUL characters. */
|
|
189
194
|
readonly input?: string;
|
|
190
|
-
/**
|
|
195
|
+
/** Sets the milliseconds before the host kills the root process alone. `0` or omitted disables the timeout. */
|
|
191
196
|
readonly timeout?: number;
|
|
192
|
-
/** If `false`, return the result
|
|
197
|
+
/** If `true`, throw on failure; if `false`, return the result instead. Default: `true`. */
|
|
193
198
|
readonly strict?: boolean;
|
|
194
|
-
/**
|
|
199
|
+
/** Sets the maximum captured bytes for stdout and for stderr, each. Default: {@link PROCESS_OUTPUT}. */
|
|
195
200
|
readonly limit?: number;
|
|
196
201
|
}
|
|
197
202
|
|
|
@@ -206,7 +211,7 @@ export declare interface ExecuteSyncOptions {
|
|
|
206
211
|
* plain or property-only lookalike.
|
|
207
212
|
*
|
|
208
213
|
* @param value - The value to inspect
|
|
209
|
-
* @returns True
|
|
214
|
+
* @returns True if the value is a `ProcessError` instance; false otherwise
|
|
210
215
|
*
|
|
211
216
|
* @example
|
|
212
217
|
* ```ts
|
|
@@ -216,15 +221,15 @@ export declare interface ExecuteSyncOptions {
|
|
|
216
221
|
*/
|
|
217
222
|
export declare function isProcessError(value: unknown): value is ProcessError;
|
|
218
223
|
|
|
219
|
-
/**
|
|
224
|
+
/** Names the default soft high-water mark, 10485760 bytes, for a supervised {@link ProcessInterface} line backlog. */
|
|
220
225
|
export declare const PROCESS_BACKLOG = 10485760;
|
|
221
226
|
|
|
222
|
-
/**
|
|
227
|
+
/** Names the window, 5000 ms, a termination waits for the child's native exit after the final kill. */
|
|
223
228
|
export declare const PROCESS_CONFIRMATION = 5000;
|
|
224
229
|
|
|
225
230
|
/**
|
|
226
|
-
*
|
|
227
|
-
*
|
|
231
|
+
* Names the default window, 1000 ms, the package waits for the child's read ends to close after the
|
|
232
|
+
* child's native exit or after a termination this package initiated, before cutting them off.
|
|
228
233
|
*
|
|
229
234
|
* @remarks
|
|
230
235
|
* Measured on Windows 11 with Node v24.18.1 on 2026-08-21, spawning the `tests/src/server/fixtures`
|
|
@@ -239,26 +244,29 @@ export declare const PROCESS_CONFIRMATION = 5000;
|
|
|
239
244
|
*/
|
|
240
245
|
export declare const PROCESS_DRAIN = 1000;
|
|
241
246
|
|
|
242
|
-
/**
|
|
247
|
+
/**
|
|
248
|
+
* Lists the machine-readable failure categories a {@link ProcessError} carries, in declaration order:
|
|
249
|
+
* `spawn`, `timeout`, `input`, `duplicate`, `protocol`, and `invalid`.
|
|
250
|
+
*/
|
|
243
251
|
export declare const PROCESS_ERROR_CODES: readonly ["spawn", "timeout", "input", "duplicate", "protocol", "invalid"];
|
|
244
252
|
|
|
245
|
-
/**
|
|
253
|
+
/** Names the default maximum retained stderr tail, 2048 bytes, for a supervised {@link ProcessInterface}. */
|
|
246
254
|
export declare const PROCESS_EVIDENCE = 2048;
|
|
247
255
|
|
|
248
|
-
/**
|
|
256
|
+
/** Names the default cooperative POSIX window, 5000 ms, between `SIGTERM` and `SIGKILL` during termination. */
|
|
249
257
|
export declare const PROCESS_GRACE = 5000;
|
|
250
258
|
|
|
251
|
-
/**
|
|
259
|
+
/** Names the default maximum captured bytes, 10485760 each, for a one-shot run's stdout and stderr. */
|
|
252
260
|
export declare const PROCESS_OUTPUT = 10485760;
|
|
253
261
|
|
|
254
|
-
/**
|
|
262
|
+
/** Lists the executable extensions a Windows lookup applies when the environment declares no `PATHEXT`, `.COM;.EXE;.BAT;.CMD`. */
|
|
255
263
|
export declare const PROCESS_PATHEXT = ".COM;.EXE;.BAT;.CMD";
|
|
256
264
|
|
|
257
|
-
/**
|
|
265
|
+
/** Names the largest timer delay, 2147483647 ms, the host schedules without truncating it to one. */
|
|
258
266
|
export declare const PROCESS_TIMER = 2147483647;
|
|
259
267
|
|
|
260
268
|
/**
|
|
261
|
-
*
|
|
269
|
+
* Declares the public contracts for `@orkestrel/process`: a typed child-process toolkit.
|
|
262
270
|
*
|
|
263
271
|
* @remarks
|
|
264
272
|
* The tiers divide by lifetime:
|
|
@@ -280,7 +288,7 @@ export declare const PROCESS_TIMER = 2147483647;
|
|
|
280
288
|
* and plain `string` signal names). The Node implementations live in `@orkestrel/process/server`.
|
|
281
289
|
*/
|
|
282
290
|
/**
|
|
283
|
-
*
|
|
291
|
+
* Represents one spawnable command: the executable, its argument vector, and optional environment overrides
|
|
284
292
|
* and initial standard input.
|
|
285
293
|
*
|
|
286
294
|
* @remarks
|
|
@@ -298,19 +306,30 @@ export declare interface ProcessCommand {
|
|
|
298
306
|
readonly arguments: readonly string[];
|
|
299
307
|
readonly environment?: Readonly<Record<string, string | undefined>>;
|
|
300
308
|
readonly input?: string;
|
|
301
|
-
/** If `true`, exclude the parent environment;
|
|
309
|
+
/** If `true`, exclude the parent environment; if `false` or omitted, the overrides layer over it. On POSIX `true` leaves no `PATH`, while Windows libuv still injects a host set. */
|
|
302
310
|
readonly isolated?: boolean;
|
|
303
311
|
}
|
|
304
312
|
|
|
305
|
-
/**
|
|
313
|
+
/**
|
|
314
|
+
* Represents a child-process failure with a stable machine-readable category.
|
|
315
|
+
*
|
|
316
|
+
* @example
|
|
317
|
+
* ```ts
|
|
318
|
+
* const error = new ProcessError('git status refused', {
|
|
319
|
+
* code: 'invalid',
|
|
320
|
+
* context: { command: 'git status' },
|
|
321
|
+
* })
|
|
322
|
+
* error.code // 'invalid'
|
|
323
|
+
* ```
|
|
324
|
+
*/
|
|
306
325
|
export declare class ProcessError extends Error {
|
|
307
326
|
readonly name = "ProcessError";
|
|
308
327
|
readonly code: ProcessErrorCode;
|
|
309
328
|
readonly context?: ProcessErrorContext;
|
|
310
|
-
/**
|
|
329
|
+
/** Carries the buffered run outcome, present when a one-shot run produced the failure. */
|
|
311
330
|
readonly result?: ExecuteResult;
|
|
312
331
|
/**
|
|
313
|
-
*
|
|
332
|
+
* Creates a process error.
|
|
314
333
|
*
|
|
315
334
|
* @param message - Human-readable failure description
|
|
316
335
|
* @param options - Machine-readable category, optional context, optional cause, and optional run result
|
|
@@ -318,37 +337,40 @@ export declare class ProcessError extends Error {
|
|
|
318
337
|
constructor(message: string, options: ProcessErrorOptions);
|
|
319
338
|
}
|
|
320
339
|
|
|
321
|
-
/**
|
|
340
|
+
/**
|
|
341
|
+
* Names the machine-readable {@link ProcessError} categories, derived from {@link PROCESS_ERROR_CODES}:
|
|
342
|
+
* `spawn`, `timeout`, `input`, `duplicate`, `protocol`, and `invalid`.
|
|
343
|
+
*/
|
|
322
344
|
export declare type ProcessErrorCode = (typeof PROCESS_ERROR_CODES)[number];
|
|
323
345
|
|
|
324
|
-
/**
|
|
346
|
+
/** Represents structured context carried by a {@link ProcessError}. */
|
|
325
347
|
export declare interface ProcessErrorContext {
|
|
326
|
-
/**
|
|
348
|
+
/** Names the registry id involved, for a manager failure. */
|
|
327
349
|
readonly id?: string;
|
|
328
|
-
/**
|
|
350
|
+
/** Names the command line involved, for a run or spawn failure. */
|
|
329
351
|
readonly command?: string;
|
|
330
|
-
/**
|
|
352
|
+
/** Holds the child's exit code, when one was observed. */
|
|
331
353
|
readonly code?: number | null;
|
|
332
|
-
/**
|
|
354
|
+
/** Names the terminating signal, when one ended the child. */
|
|
333
355
|
readonly signal?: string | null;
|
|
334
|
-
/**
|
|
356
|
+
/** Carries the rejected public input, for an input-validation failure. */
|
|
335
357
|
readonly value?: unknown;
|
|
336
358
|
}
|
|
337
359
|
|
|
338
|
-
/**
|
|
360
|
+
/** Configures a {@link ProcessError}. */
|
|
339
361
|
export declare interface ProcessErrorOptions {
|
|
340
|
-
/**
|
|
362
|
+
/** Names the stable machine-readable category. */
|
|
341
363
|
readonly code: ProcessErrorCode;
|
|
342
|
-
/**
|
|
364
|
+
/** Carries structured detail about the failure. */
|
|
343
365
|
readonly context?: ProcessErrorContext;
|
|
344
|
-
/**
|
|
366
|
+
/** Carries the underlying cause, when one exists. */
|
|
345
367
|
readonly cause?: unknown;
|
|
346
|
-
/**
|
|
368
|
+
/** Carries the buffered run outcome, present when an {@link ExecuteResult} produced the failure. */
|
|
347
369
|
readonly result?: ExecuteResult;
|
|
348
370
|
}
|
|
349
371
|
|
|
350
372
|
/**
|
|
351
|
-
*
|
|
373
|
+
* Represents the push observation surface of a {@link ProcessInterface} — the moments a fire-and-forget
|
|
352
374
|
* observer subscribes to, alongside the `lines` stream and the `exit` promise.
|
|
353
375
|
*
|
|
354
376
|
* @remarks
|
|
@@ -362,16 +384,16 @@ export declare interface ProcessErrorOptions {
|
|
|
362
384
|
* routed to that handler, never emitted as this `error` event.
|
|
363
385
|
*/
|
|
364
386
|
export declare type ProcessEventMap = {
|
|
365
|
-
/**
|
|
387
|
+
/** Reports a decoded standard-error chunk arrived. */
|
|
366
388
|
readonly stderr: readonly [chunk: string];
|
|
367
|
-
/**
|
|
389
|
+
/** Reports a fault from the child or its open standard-input channel, carrying the host cause directly or through a `protocol` {@link ProcessError}. */
|
|
368
390
|
readonly error: readonly [error: unknown];
|
|
369
|
-
/**
|
|
391
|
+
/** Reports the child settled — its terminal state, delivered once. */
|
|
370
392
|
readonly exit: readonly [exit: ProcessExit];
|
|
371
393
|
};
|
|
372
394
|
|
|
373
395
|
/**
|
|
374
|
-
*
|
|
396
|
+
* Represents the observed terminal state of a child process: its exit code or the signal that ended it, and
|
|
375
397
|
* how its observation ended.
|
|
376
398
|
*
|
|
377
399
|
* @remarks
|
|
@@ -382,16 +404,16 @@ export declare type ProcessEventMap = {
|
|
|
382
404
|
* dropped lines and the drain bound cut stderr off.
|
|
383
405
|
*/
|
|
384
406
|
export declare interface ProcessExit {
|
|
385
|
-
/**
|
|
407
|
+
/** Holds the exit code, or `null` when a signal ended the process. A spawn fault reports the host's negative errno for `Process` and `execute`. */
|
|
386
408
|
readonly code: number | null;
|
|
387
|
-
/**
|
|
409
|
+
/** Holds the terminating signal name, or `null` when the process exited on its own. */
|
|
388
410
|
readonly signal: string | null;
|
|
389
|
-
/**
|
|
411
|
+
/** Reports how the terminal moment arrived: true when the child's streams closed; false when the `drain` bound elapsed first and later diagnostics may have existed. */
|
|
390
412
|
readonly drained: boolean;
|
|
391
413
|
}
|
|
392
414
|
|
|
393
415
|
/**
|
|
394
|
-
*
|
|
416
|
+
* Represents one supervised child process with framed output, a bounded backlog, and bounded termination.
|
|
395
417
|
*
|
|
396
418
|
* @remarks
|
|
397
419
|
* `lines` is pumped as soon as the child writes, and it is a single-consumer stream: each line goes
|
|
@@ -426,16 +448,16 @@ export declare interface ProcessExit {
|
|
|
426
448
|
* supervisor inside that window reads the terminal state here.
|
|
427
449
|
*/
|
|
428
450
|
export declare interface ProcessInterface {
|
|
429
|
-
/**
|
|
451
|
+
/** Holds the host process id, fixed when construction returns, or `undefined` when the spawn produced none. */
|
|
430
452
|
readonly pid: number | undefined;
|
|
431
|
-
/**
|
|
453
|
+
/** Holds the exit code the host recorded, or `null` while the child has not exited and when a signal ended it. A spawn fault reports the host's negative errno. */
|
|
432
454
|
readonly code: number | null;
|
|
433
|
-
/**
|
|
455
|
+
/** Holds the terminating signal name the host recorded, or `null` while the child has not exited and when it exited on its own. */
|
|
434
456
|
readonly signal: string | null;
|
|
435
|
-
/**
|
|
457
|
+
/** Holds the typed lifecycle observation surface. */
|
|
436
458
|
readonly emitter: EmitterInterface<ProcessEventMap>;
|
|
437
459
|
/**
|
|
438
|
-
*
|
|
460
|
+
* Yields the captured stdout lines, in arrival order, for one consumer, ending at the terminal moment.
|
|
439
461
|
*
|
|
440
462
|
* @remarks
|
|
441
463
|
* A line feed, a CRLF pair, and a bare carriage return each terminate a line, and a CRLF split
|
|
@@ -455,7 +477,7 @@ export declare interface ProcessInterface {
|
|
|
455
477
|
*/
|
|
456
478
|
readonly lines: AsyncIterable<string>;
|
|
457
479
|
/**
|
|
458
|
-
*
|
|
480
|
+
* Holds the decoded byte-bounded stderr tail.
|
|
459
481
|
*
|
|
460
482
|
* @remarks
|
|
461
483
|
* The live tail before the terminal moment and the frozen value after it, on every path — a
|
|
@@ -465,10 +487,10 @@ export declare interface ProcessInterface {
|
|
|
465
487
|
* the tail as of the cutoff, and later diagnostics may have existed.
|
|
466
488
|
*/
|
|
467
489
|
readonly evidence: string;
|
|
468
|
-
/**
|
|
490
|
+
/** Reports whether the `lines` stream omitted output because a retention bound was reached. */
|
|
469
491
|
readonly truncated: boolean;
|
|
470
492
|
/**
|
|
471
|
-
*
|
|
493
|
+
* Reports whether the `exit` promise settled.
|
|
472
494
|
*
|
|
473
495
|
* @remarks
|
|
474
496
|
* The terminal moment has arrived: `evidence` is frozen, `lines` has ended, and the
|
|
@@ -477,7 +499,7 @@ export declare interface ProcessInterface {
|
|
|
477
499
|
*/
|
|
478
500
|
readonly settled: boolean;
|
|
479
501
|
/**
|
|
480
|
-
*
|
|
502
|
+
* Reports whether a termination began.
|
|
481
503
|
*
|
|
482
504
|
* @remarks
|
|
483
505
|
* Monotonic. It turns true when `stop`, `destroy`, or an abort of the `signal` option begins a
|
|
@@ -488,7 +510,7 @@ export declare interface ProcessInterface {
|
|
|
488
510
|
*/
|
|
489
511
|
readonly stopping: boolean;
|
|
490
512
|
/**
|
|
491
|
-
*
|
|
513
|
+
* Settles with the terminal child state, delivered once.
|
|
492
514
|
*
|
|
493
515
|
* @remarks
|
|
494
516
|
* Never rejects. It settles at the terminal moment: when the child's streams close, or when the
|
|
@@ -497,7 +519,7 @@ export declare interface ProcessInterface {
|
|
|
497
519
|
*/
|
|
498
520
|
readonly exit: Promise<ProcessExit>;
|
|
499
521
|
/**
|
|
500
|
-
*
|
|
522
|
+
* Writes one line to the open standard-input channel.
|
|
501
523
|
*
|
|
502
524
|
* @remarks
|
|
503
525
|
* Never rejects. `true` means the host accepted the bytes without reporting a fault; it does not
|
|
@@ -511,11 +533,11 @@ export declare interface ProcessInterface {
|
|
|
511
533
|
* for bytes the package is about to discard.
|
|
512
534
|
*
|
|
513
535
|
* @param text - The line text without its trailing newline
|
|
514
|
-
* @returns True
|
|
536
|
+
* @returns True if the host accepted the bytes without reporting a fault; false otherwise (the channel was closed, destroyed, ended, failed, or the write remained unconfirmed through `delivery`)
|
|
515
537
|
*/
|
|
516
538
|
send(text: string): Promise<boolean>;
|
|
517
539
|
/**
|
|
518
|
-
*
|
|
540
|
+
* Terminates the child process tree, awaits its observed exit, and reaches the terminal moment.
|
|
519
541
|
*
|
|
520
542
|
* @remarks
|
|
521
543
|
* Never rejects. On Windows the whole tree is killed immediately through `taskkill`, with a
|
|
@@ -528,11 +550,11 @@ export declare interface ProcessInterface {
|
|
|
528
550
|
* reaches the end of the stream instead of waiting on a child it already ended, and needs no
|
|
529
551
|
* second call to release it.
|
|
530
552
|
*
|
|
531
|
-
* @returns True
|
|
553
|
+
* @returns True if the child's native exit was observed; false otherwise (the confirmation deadline elapsed without it)
|
|
532
554
|
*/
|
|
533
555
|
stop(): Promise<boolean>;
|
|
534
556
|
/**
|
|
535
|
-
*
|
|
557
|
+
* Stops the child, closes its standard-input channel, reaches the terminal moment, and destroys the
|
|
536
558
|
* observation emitter.
|
|
537
559
|
*
|
|
538
560
|
* @remarks
|
|
@@ -549,21 +571,21 @@ export declare interface ProcessInterface {
|
|
|
549
571
|
}
|
|
550
572
|
|
|
551
573
|
/**
|
|
552
|
-
*
|
|
574
|
+
* Represents the push observation surface of a {@link ProcessManagerInterface} — the fleet-level moments a
|
|
553
575
|
* fire-and-forget observer subscribes to.
|
|
554
576
|
*
|
|
555
577
|
* @remarks
|
|
556
578
|
* Declared as a `type` alias so it satisfies the emitter's `EventMap` constraint structurally.
|
|
557
579
|
*/
|
|
558
580
|
export declare type ProcessManagerEventMap = {
|
|
559
|
-
/**
|
|
581
|
+
/** Reports a child launched under its id. */
|
|
560
582
|
readonly launch: readonly [id: string];
|
|
561
|
-
/**
|
|
583
|
+
/** Reports a child settled and left the registry — its id and terminal state. */
|
|
562
584
|
readonly exit: readonly [id: string, exit: ProcessExit];
|
|
563
585
|
};
|
|
564
586
|
|
|
565
587
|
/**
|
|
566
|
-
*
|
|
588
|
+
* Represents a keyed registry of live supervised child processes.
|
|
567
589
|
*
|
|
568
590
|
* @remarks
|
|
569
591
|
* A child that settles removes itself from the registry, so `count` and `processes` reflect only
|
|
@@ -575,25 +597,25 @@ export declare type ProcessManagerEventMap = {
|
|
|
575
597
|
* the `launch` and `exit` moments across every child.
|
|
576
598
|
*/
|
|
577
599
|
export declare interface ProcessManagerInterface {
|
|
578
|
-
/**
|
|
600
|
+
/** Holds the typed fleet-level observation surface. */
|
|
579
601
|
readonly emitter: EmitterInterface<ProcessManagerEventMap>;
|
|
580
|
-
/**
|
|
602
|
+
/** Counts the live children. */
|
|
581
603
|
readonly count: number;
|
|
582
604
|
/**
|
|
583
|
-
*
|
|
605
|
+
* Returns the live child under `id`, or `undefined` when none is.
|
|
584
606
|
*
|
|
585
607
|
* @param id - The registry key
|
|
586
608
|
* @returns The child, or `undefined`
|
|
587
609
|
*/
|
|
588
610
|
process(id: string): ProcessInterface | undefined;
|
|
589
611
|
/**
|
|
590
|
-
*
|
|
612
|
+
* Returns a snapshot of every live child.
|
|
591
613
|
*
|
|
592
614
|
* @returns The live children in launch order
|
|
593
615
|
*/
|
|
594
616
|
processes(): readonly ProcessInterface[];
|
|
595
617
|
/**
|
|
596
|
-
*
|
|
618
|
+
* Spawns and registers one child under `id`.
|
|
597
619
|
*
|
|
598
620
|
* @remarks
|
|
599
621
|
* Every option is read before the child is spawned, so a caller's own option getter runs while
|
|
@@ -611,27 +633,28 @@ export declare interface ProcessManagerInterface {
|
|
|
611
633
|
*/
|
|
612
634
|
launch(id: string, options: ProcessOptions): ProcessInterface;
|
|
613
635
|
/**
|
|
614
|
-
*
|
|
636
|
+
* Terminates the named children, or every live child when a call names none, and awaits their
|
|
637
|
+
* exit.
|
|
615
638
|
*
|
|
616
639
|
* @param ids - The registry keys to stop
|
|
617
|
-
* @returns True
|
|
640
|
+
* @returns True if every named child was live and its exit was confirmed; false otherwise
|
|
618
641
|
*/
|
|
619
642
|
stop(ids: readonly string[]): Promise<boolean>;
|
|
620
643
|
/**
|
|
621
|
-
*
|
|
644
|
+
* Terminates one child and awaits its exit.
|
|
622
645
|
*
|
|
623
646
|
* @param id - The registry key to stop
|
|
624
|
-
* @returns True
|
|
647
|
+
* @returns True if the child was live and its exit was confirmed; false otherwise (the id was not live, or the confirmation deadline elapsed)
|
|
625
648
|
*/
|
|
626
649
|
stop(id: string): Promise<boolean>;
|
|
627
650
|
/**
|
|
628
|
-
*
|
|
651
|
+
* Terminates every live child and awaits their exit.
|
|
629
652
|
*
|
|
630
653
|
* @returns A promise that resolves after every child stops
|
|
631
654
|
*/
|
|
632
655
|
stop(): Promise<void>;
|
|
633
656
|
/**
|
|
634
|
-
*
|
|
657
|
+
* Stops every child, then destroys the registry emitter last.
|
|
635
658
|
*
|
|
636
659
|
* @remarks
|
|
637
660
|
* Always resolves, and refuses a later `launch` with a {@link ProcessError} coded `protocol`.
|
|
@@ -645,7 +668,7 @@ export declare interface ProcessManagerInterface {
|
|
|
645
668
|
}
|
|
646
669
|
|
|
647
670
|
/**
|
|
648
|
-
*
|
|
671
|
+
* Configures a {@link ProcessManagerInterface}.
|
|
649
672
|
*
|
|
650
673
|
* @remarks
|
|
651
674
|
* `on` installs initial {@link ProcessManagerEventMap} listeners and `error` receives isolated
|
|
@@ -657,7 +680,7 @@ export declare interface ProcessManagerOptions {
|
|
|
657
680
|
}
|
|
658
681
|
|
|
659
682
|
/**
|
|
660
|
-
*
|
|
683
|
+
* Configures one supervised child process.
|
|
661
684
|
*
|
|
662
685
|
* @remarks
|
|
663
686
|
* `grace` is the cooperative window between `SIGTERM` and `SIGKILL` on a POSIX host; Windows has no
|
|
@@ -685,26 +708,26 @@ export declare interface ProcessOptions {
|
|
|
685
708
|
readonly on?: EmitterHooks<ProcessEventMap>;
|
|
686
709
|
readonly error?: EmitterErrorHandler;
|
|
687
710
|
readonly command: ProcessCommand;
|
|
688
|
-
/**
|
|
711
|
+
/** Names the working directory the child runs in. */
|
|
689
712
|
readonly workspace: string;
|
|
690
|
-
/**
|
|
713
|
+
/** Sets the cooperative POSIX window in milliseconds between `SIGTERM` and `SIGKILL`. Default: {@link PROCESS_GRACE}. */
|
|
691
714
|
readonly grace?: number;
|
|
692
|
-
/**
|
|
715
|
+
/** Sets the milliseconds the package waits for the child's read ends to close after the native exit or an initiated termination, before cutting them off; `0` cuts them off as soon as the bound is armed. Default: {@link PROCESS_DRAIN}. */
|
|
693
716
|
readonly drain?: number;
|
|
694
|
-
/**
|
|
717
|
+
/** Sets the maximum retained stderr tail in bytes. Default: {@link PROCESS_EVIDENCE}. */
|
|
695
718
|
readonly evidence?: number;
|
|
696
|
-
/**
|
|
719
|
+
/** Sets the soft high-water mark in bytes for the unconsumed `lines` backlog; termination retains at most twice this value. Default: {@link PROCESS_BACKLOG}. */
|
|
697
720
|
readonly backlog?: number;
|
|
698
|
-
/**
|
|
721
|
+
/** Sets the milliseconds an unconfirmed {@link ProcessInterface.send} waits before resolving `false`. `0` or omitted disables the bound. */
|
|
699
722
|
readonly delivery?: number;
|
|
700
723
|
/** If `true`, stdin stays open for {@link ProcessInterface.send}; if `false` or omitted, stdin closes after any initial `input`. */
|
|
701
724
|
readonly writable?: boolean;
|
|
702
|
-
/**
|
|
725
|
+
/** Terminates the child through the same bounded `stop` when this signal aborts. */
|
|
703
726
|
readonly signal?: AbortSignal;
|
|
704
727
|
}
|
|
705
728
|
|
|
706
729
|
/**
|
|
707
|
-
*
|
|
730
|
+
* Represents the push observation surface of a {@link SessionInterface} — the moments a byte-oriented observer
|
|
708
731
|
* subscribes to, alongside the `ending` and `exit` promises.
|
|
709
732
|
*
|
|
710
733
|
* @remarks
|
|
@@ -727,18 +750,18 @@ export declare interface ProcessOptions {
|
|
|
727
750
|
* `error` event.
|
|
728
751
|
*/
|
|
729
752
|
export declare type SessionEventMap = {
|
|
730
|
-
/**
|
|
753
|
+
/** Reports a standard-output chunk arrived, as an owned `Uint8Array` the consumer may keep and mutate. */
|
|
731
754
|
readonly stdout: readonly [chunk: Uint8Array];
|
|
732
|
-
/**
|
|
755
|
+
/** Reports a decoded standard-error chunk arrived. */
|
|
733
756
|
readonly stderr: readonly [chunk: string];
|
|
734
|
-
/**
|
|
757
|
+
/** Reports a fault from the child or its open standard-input channel, carrying the host cause directly or through a `protocol` {@link ProcessError}. */
|
|
735
758
|
readonly error: readonly [error: unknown];
|
|
736
|
-
/**
|
|
759
|
+
/** Reports the child settled — its terminal state, delivered once. */
|
|
737
760
|
readonly exit: readonly [exit: ProcessExit];
|
|
738
761
|
};
|
|
739
762
|
|
|
740
763
|
/**
|
|
741
|
-
*
|
|
764
|
+
* Represents one supervised child process read as raw bytes, with an open standard-input channel and bounded
|
|
742
765
|
* termination.
|
|
743
766
|
*
|
|
744
767
|
* @remarks
|
|
@@ -770,16 +793,16 @@ export declare type SessionEventMap = {
|
|
|
770
793
|
* the id.
|
|
771
794
|
*/
|
|
772
795
|
export declare interface SessionInterface {
|
|
773
|
-
/**
|
|
796
|
+
/** Holds the host process id, fixed when construction returns, or `undefined` when the spawn produced none. */
|
|
774
797
|
readonly pid: number | undefined;
|
|
775
|
-
/**
|
|
798
|
+
/** Holds the exit code the host recorded, or `null` while the child has not exited and when a signal ended it. A spawn fault reports the host's negative errno. */
|
|
776
799
|
readonly code: number | null;
|
|
777
|
-
/**
|
|
800
|
+
/** Holds the terminating signal name the host recorded, or `null` while the child has not exited and when it exited on its own. */
|
|
778
801
|
readonly signal: string | null;
|
|
779
|
-
/**
|
|
802
|
+
/** Holds the typed lifecycle observation surface. */
|
|
780
803
|
readonly emitter: EmitterInterface<SessionEventMap>;
|
|
781
804
|
/**
|
|
782
|
-
*
|
|
805
|
+
* Holds the decoded byte-bounded stderr tail.
|
|
783
806
|
*
|
|
784
807
|
* @remarks
|
|
785
808
|
* The live tail before the terminal moment and the frozen value after it, on every path — a
|
|
@@ -789,7 +812,7 @@ export declare interface SessionInterface {
|
|
|
789
812
|
*/
|
|
790
813
|
readonly evidence: string;
|
|
791
814
|
/**
|
|
792
|
-
*
|
|
815
|
+
* Reports whether the `exit` promise settled.
|
|
793
816
|
*
|
|
794
817
|
* @remarks
|
|
795
818
|
* The terminal moment has arrived: `evidence` is frozen, no further `stdout` or `stderr` event
|
|
@@ -798,7 +821,7 @@ export declare interface SessionInterface {
|
|
|
798
821
|
*/
|
|
799
822
|
readonly settled: boolean;
|
|
800
823
|
/**
|
|
801
|
-
*
|
|
824
|
+
* Reports whether a termination began.
|
|
802
825
|
*
|
|
803
826
|
* @remarks
|
|
804
827
|
* Monotonic. It turns true when `stop`, `destroy`, or an abort of the `signal` option begins a
|
|
@@ -808,7 +831,7 @@ export declare interface SessionInterface {
|
|
|
808
831
|
*/
|
|
809
832
|
readonly stopping: boolean;
|
|
810
833
|
/**
|
|
811
|
-
*
|
|
834
|
+
* Settles at the child's own ending, awaited without the terminal moment's drain window.
|
|
812
835
|
*
|
|
813
836
|
* @remarks
|
|
814
837
|
* Never rejects, and resolves no value: `code` and `signal` carry the terminal facts as soon as
|
|
@@ -821,7 +844,7 @@ export declare interface SessionInterface {
|
|
|
821
844
|
*/
|
|
822
845
|
readonly ending: Promise<void>;
|
|
823
846
|
/**
|
|
824
|
-
*
|
|
847
|
+
* Settles with the terminal child state, delivered once.
|
|
825
848
|
*
|
|
826
849
|
* @remarks
|
|
827
850
|
* Never rejects. It settles at the terminal moment: when the child's streams close, or when the
|
|
@@ -830,7 +853,7 @@ export declare interface SessionInterface {
|
|
|
830
853
|
*/
|
|
831
854
|
readonly exit: Promise<ProcessExit>;
|
|
832
855
|
/**
|
|
833
|
-
*
|
|
856
|
+
* Writes raw bytes to the open standard-input channel.
|
|
834
857
|
*
|
|
835
858
|
* @remarks
|
|
836
859
|
* Never rejects, and adds no framing: the bytes reach the child exactly as given, with no
|
|
@@ -847,11 +870,11 @@ export declare interface SessionInterface {
|
|
|
847
870
|
* promise settles: bytes mutated inside that window are the bytes the child receives.
|
|
848
871
|
*
|
|
849
872
|
* @param bytes - The payload to write, already framed by the caller
|
|
850
|
-
* @returns True
|
|
873
|
+
* @returns True if the host accepted the bytes without reporting a fault; false otherwise (the channel was closed, destroyed, ended, failed, or the write remained unconfirmed through `delivery`)
|
|
851
874
|
*/
|
|
852
875
|
write(bytes: Uint8Array): Promise<boolean>;
|
|
853
876
|
/**
|
|
854
|
-
*
|
|
877
|
+
* Closes the standard-input channel and leaves the child running.
|
|
855
878
|
*
|
|
856
879
|
* @remarks
|
|
857
880
|
* Never rejects, and terminates nothing: `stopping` stays false, no signal is sent, no drain
|
|
@@ -872,7 +895,7 @@ export declare interface SessionInterface {
|
|
|
872
895
|
*/
|
|
873
896
|
end(): Promise<void>;
|
|
874
897
|
/**
|
|
875
|
-
*
|
|
898
|
+
* Terminates the child process tree, awaits its observed exit, and reaches the terminal moment.
|
|
876
899
|
*
|
|
877
900
|
* @remarks
|
|
878
901
|
* Never rejects. On Windows the whole tree is killed immediately through `taskkill`, with a
|
|
@@ -883,11 +906,11 @@ export declare interface SessionInterface {
|
|
|
883
906
|
* `stdout` and `stderr` events stop, and `exit` settles. A caller that stops a child and keeps
|
|
884
907
|
* listening therefore reaches the end of the stream and needs no second call to release it.
|
|
885
908
|
*
|
|
886
|
-
* @returns True
|
|
909
|
+
* @returns True if the child's native exit was observed; false otherwise (the confirmation deadline elapsed without it)
|
|
887
910
|
*/
|
|
888
911
|
stop(): Promise<boolean>;
|
|
889
912
|
/**
|
|
890
|
-
*
|
|
913
|
+
* Stops the child, closes its standard-input channel, reaches the terminal moment, and destroys the
|
|
891
914
|
* observation emitter.
|
|
892
915
|
*
|
|
893
916
|
* @remarks
|
|
@@ -904,7 +927,7 @@ export declare interface SessionInterface {
|
|
|
904
927
|
}
|
|
905
928
|
|
|
906
929
|
/**
|
|
907
|
-
*
|
|
930
|
+
* Configures one raw byte session over a supervised child.
|
|
908
931
|
*
|
|
909
932
|
* @remarks
|
|
910
933
|
* This is {@link ProcessOptions} without `backlog` and without `writable`. A session frames nothing
|
|
@@ -924,22 +947,22 @@ export declare interface SessionOptions {
|
|
|
924
947
|
readonly on?: EmitterHooks<SessionEventMap>;
|
|
925
948
|
readonly error?: EmitterErrorHandler;
|
|
926
949
|
readonly command: ProcessCommand;
|
|
927
|
-
/**
|
|
950
|
+
/** Names the working directory the child runs in. */
|
|
928
951
|
readonly workspace: string;
|
|
929
|
-
/**
|
|
952
|
+
/** Sets the cooperative POSIX window in milliseconds between `SIGTERM` and `SIGKILL`. Default: {@link PROCESS_GRACE}. */
|
|
930
953
|
readonly grace?: number;
|
|
931
|
-
/**
|
|
954
|
+
/** Sets the milliseconds the package waits for the child's read ends to close after the native exit or an initiated termination, before cutting them off; `0` cuts them off as soon as the bound is armed. Default: {@link PROCESS_DRAIN}. */
|
|
932
955
|
readonly drain?: number;
|
|
933
|
-
/**
|
|
956
|
+
/** Sets the maximum retained stderr tail in bytes. Default: {@link PROCESS_EVIDENCE}. */
|
|
934
957
|
readonly evidence?: number;
|
|
935
|
-
/**
|
|
958
|
+
/** Sets the milliseconds an unconfirmed {@link SessionInterface.write} waits before resolving `false`. `0` or omitted disables the bound. */
|
|
936
959
|
readonly delivery?: number;
|
|
937
|
-
/**
|
|
960
|
+
/** Terminates the child through the same bounded `stop` when this signal aborts. */
|
|
938
961
|
readonly signal?: AbortSignal;
|
|
939
962
|
}
|
|
940
963
|
|
|
941
964
|
/**
|
|
942
|
-
*
|
|
965
|
+
* Represents the resolved spawn form of one command: the executable to launch, the argument vector to pass,
|
|
943
966
|
* and whether the host receives that vector verbatim.
|
|
944
967
|
*
|
|
945
968
|
* @remarks
|