@orkestrel/process 0.0.4 → 0.0.6

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.
@@ -187,9 +187,13 @@ export declare function detach(command: ProcessCommand_2, options?: DetachOption
187
187
  * rather than on process exit, so a descendant that inherited the child's stdio holds the run open
188
188
  * after the child itself has gone. Give such a run a `timeout`. The child's `environment` merges over
189
189
  * the parent unless the command is `isolated`, then `options.environment` on top, and `options.input`
190
- * overrides `command.input`. Unless `strict` is `false`, a failed run rejects with a
191
- * {@link createExecuteError} carrying the {@link ExecuteResult}. An invalid option or command string rejects
192
- * before the child is spawned, because an async function cannot throw synchronously.
190
+ * overrides `command.input`. A host fault while writing that input terminates the run by design and
191
+ * marks its result failed; a strict rejection carries the host fault as its cause. This differs
192
+ * from `Process` constructor input, whose package-initiated input phase stays quiet. Unless `strict`
193
+ * is `false`, a failed run rejects with a {@link ProcessError} carrying the {@link ExecuteResult};
194
+ * {@link createExecuteError} constructs every rejection outside the input-fault door. An invalid
195
+ * option or command string rejects before the child is spawned, because an async function cannot
196
+ * throw synchronously.
193
197
  *
194
198
  * @param command - The executable, arguments, and optional environment and input
195
199
  * @param options - Working directory, timeout, grace, signal, capture limit, and failure delivery
@@ -358,26 +362,23 @@ export declare function mergeEnvironment(isolated: boolean, base?: Readonly<Reco
358
362
  export declare function mergePlatformEnvironment(platform: NodeJS.Platform, parent: Readonly<Record<string, string | undefined>>, isolated: boolean, base?: Readonly<Record<string, string | undefined>>, override?: Readonly<Record<string, string | undefined>>): NodeJS.ProcessEnv;
359
363
 
360
364
  /**
361
- * One supervised child process with framed output, a bounded backlog, and bounded termination.
365
+ * Supervises one child while keeping every observation channel aligned at termination.
362
366
  *
363
367
  * @remarks
364
- * Standard output is framed through `readline` into a single-consumer stream: each line goes to
365
- * exactly one waiting iterator, so concurrent iterators split the output rather than each receiving
366
- * all of it. While no consumer has ever requested an iterator, stdout keeps draining so `exit` still
367
- * resolves, and retention stops at the `backlog` mark: a
368
- * consumer attaching later receives the retained head, a gap, then the live stream. After an iterator
369
- * has been requested, stdout pauses at the mark and resumes at half of it, so that consumer loses
370
- * nothing before termination and the child feels real backpressure. The mark is soft — the ordinary backlog can
371
- * overshoot it by the line that crossed it plus the rest of its delivered chunk. Termination never
372
- * reapplies backpressure, and retained lines are capped at twice `backlog`; later lines are dropped
373
- * and `truncated` reports the omission. Standard error is decoded and forwarded live as the `stderr`
374
- * event while a byte-bounded raw tail is retained as `evidence`. The typed `emitter` also carries the
375
- * child `error` cause on a spawn fault and the terminal `exit`, alongside the `exit` promise. `pid`,
376
- * `code`, and `signal` read the spawned child directly, so the native exit is readable before the
377
- * `exit` promise settles on stdio close. `stop` ends the whole tree and reports whether the native
378
- * exit was observed; `destroy` stops the child, destroys stdin so every pending `send` settles, and
379
- * destroys the emitter last. `destroy` resolving does not imply the child's stdio has closed, so
380
- * `exit` and `lines` can still be outstanding when a descendant holds an inherited pipe.
368
+ * The child's ending and the supervision's ending are distinct. `pid`, `code`, and `signal` read
369
+ * the host child directly, so they expose native exit as soon as the host records it. `settled`,
370
+ * `exit`, `evidence`, and `lines` reach one terminal moment after the read channels close or the
371
+ * bounded `drain` window cuts them off. That window is armed by the child's native exit and by a
372
+ * termination this package initiated, so every way a child can end reaches the moment. The terminal
373
+ * routine freezes `evidence` and ends `lines` before it destroys stdout, stderr, or the emitter, so
374
+ * the push channel never disappears while a pull channel can still change or wait indefinitely.
375
+ *
376
+ * Standard output is framed through `readline` into a single-consumer stream. Lines already framed
377
+ * and queued remain available through the terminal moment, while bytes arriving after a requested
378
+ * termination may be cut off. Standard error is forwarded through the live `stderr` event and
379
+ * retained as a byte-bounded raw tail until that same moment. `stop` ends the child tree and the
380
+ * observation surfaces. `destroy` performs that stop and then destroys the emitter after the
381
+ * frozen terminal state exists.
381
382
  *
382
383
  * @example
383
384
  * ```ts
@@ -408,41 +409,53 @@ export declare class Process implements ProcessInterface {
408
409
  get signal(): string | null;
409
410
  /** The typed lifecycle observation surface. */
410
411
  get emitter(): EmitterInterface<ProcessEventMap>;
411
- /** The captured stdout lines, in arrival order, ending when the child's stdout closes. */
412
+ /** The captured stdout lines, in arrival order, ending after queued lines at the terminal moment. */
412
413
  get lines(): AsyncIterable<string>;
413
- /** The decoded byte-bounded stderr tail. */
414
+ /** The decoded byte-bounded stderr tail, frozen at the terminal moment. */
414
415
  get evidence(): string;
415
416
  /** True when the `lines` stream omitted output after a retention bound was reached. */
416
417
  get truncated(): boolean;
417
- /** The terminal child state, observed once from the close event. */
418
+ /** True after the terminal moment arrived and `exit` settled. */
419
+ get settled(): boolean;
420
+ /** True after termination began, including after the terminal moment. */
421
+ get stopping(): boolean;
422
+ /** The terminal child state, observed once after stream close or the drain cutoff. */
418
423
  get exit(): Promise<ProcessExit>;
419
424
  /**
420
425
  * Write one line to the open standard-input channel.
421
426
  *
422
427
  * @remarks
423
- * Never rejects. The promise settles when the host reports the line handled, so a line written to
424
- * a child that is not reading stays pending until the child drains it or the channel closes. Every
425
- * terminal teardown path destroys stdin, so a pending write always settles by teardown; a caller
426
- * that needs its own deadline arms a timer and calls `stop`.
428
+ * Never rejects. `true` means the host accepted the bytes without reporting a fault; it does not
429
+ * prove that the child read them. An ordinary write settles when the kernel accepts it. Only a
430
+ * full pipe can hold the write unconfirmed. The `delivery` option can bound that wait, and every
431
+ * terminal teardown path settles pending writes. On Windows 11 with Node v24.18.1, measured on
432
+ * 2026-08-21, a child that closes its own file descriptor 0 can leave the parent pipe writable:
433
+ * the write can settle `true` without a callback error or a stream error while the child remains
434
+ * alive. After `stop` or `destroy` begins, a later call settles `false`. Version 0.0.4 could settle
435
+ * that call `true` before teardown destroyed the pipe; returning `false` avoids claiming delivery
436
+ * for bytes the package is about to discard.
427
437
  *
428
438
  * @param text - The line text without its trailing newline
429
- * @returns True when the line reached the host without error; false when the channel was closed, destroyed, ended, or the write failed
439
+ * @returns True when the host accepted the bytes without reporting a fault; false when the channel was closed, destroyed, ended, failed, or remained unconfirmed through `delivery`
430
440
  */
431
441
  send(text: string): Promise<boolean>;
432
442
  /**
433
- * Terminate the child process tree and await its observed exit.
443
+ * Terminates the child process tree and reaches the terminal observation moment.
434
444
  *
435
445
  * @remarks
436
- * Never rejects, and every call shares one termination.
446
+ * Never rejects, and every call shares one termination. After the termination sequence returns,
447
+ * confirmed or not, it waits at most `drain` for the read channels to close, then cuts them off
448
+ * and settles `exit` when they remain open. A cutoff reached before the native exit reports the
449
+ * `code` and `signal` the host had recorded by then, which is `null` for a child still running.
437
450
  *
438
451
  * @returns True when the child's native exit was observed; false when the confirmation deadline elapsed without it
439
452
  */
440
453
  stop(): Promise<boolean>;
441
454
  /**
442
- * Stop the child, close its standard-input channel, and destroy the observation emitter.
455
+ * Stops the child and destroys the observation emitter after the terminal state freezes.
443
456
  *
444
457
  * @remarks
445
- * Always resolves, including when termination was never confirmed.
458
+ * Always resolves, including when termination was never confirmed. Every call shares one barrier.
446
459
  *
447
460
  * @returns The stable barrier shared by every call
448
461
  */
@@ -465,8 +478,8 @@ export declare class Process implements ProcessInterface {
465
478
  * members, which is what lets a caller drive `stopChild` over a child it spawned itself. Each helper
466
479
  * takes the slice of this contract it reads: `exitCode` and `signalCode` are the host's
467
480
  * authoritative liveness answer, `pid` addresses a POSIX process group, `kill` delivers one signal,
468
- * `once` reports the native exit, and `off` releases that listener when the wait ends at its
469
- * deadline instead.
481
+ * `once` reports the native exit to `waitForExit` or the stream close to `waitForClose`, and `off`
482
+ * releases the corresponding listener when either wait ends.
470
483
  *
471
484
  * A non-detached child stays in its caller's process group, so no group carries its pid. `kill` is
472
485
  * the route that reaches it: `killProcess` signals the negated `pid` first and falls back to `kill`
@@ -487,25 +500,25 @@ export declare interface ProcessChild {
487
500
  */
488
501
  kill(signal: NodeJS.Signals): boolean;
489
502
  /**
490
- * Register a one-shot listener for the native exit.
503
+ * Register a one-shot listener for the native exit or stream close.
491
504
  *
492
- * @param event - The `exit` event name
493
- * @param listener - The listener invoked after the process exits
505
+ * @param event - The `exit` or `close` event name
506
+ * @param listener - The listener invoked after the selected event
494
507
  * @returns Whatever the emitter returns, which the helpers ignore
495
508
  */
496
- once(event: 'exit', listener: () => void): unknown;
509
+ once(event: 'exit' | 'close', listener: () => void): unknown;
497
510
  /**
498
- * Release one previously registered exit listener.
511
+ * Release one previously registered exit or close listener.
499
512
  *
500
513
  * @remarks
501
- * `waitForExit` calls this when its deadline elapses before the exit, so a child that outlives
502
- * several bounded waits accumulates no listeners.
514
+ * `waitForExit` releases its `exit` listener, and `waitForClose` releases its `close` listener, so
515
+ * a child that outlives several bounded waits accumulates neither.
503
516
  *
504
- * @param event - The `exit` event name
517
+ * @param event - The `exit` or `close` event name
505
518
  * @param listener - The listener registered through `once`
506
519
  * @returns Whatever the emitter returns, which the helpers ignore
507
520
  */
508
- off(event: 'exit', listener: () => void): unknown;
521
+ off(event: 'exit' | 'close', listener: () => void): unknown;
509
522
  }
510
523
 
511
524
  /**
@@ -520,9 +533,9 @@ export declare interface ProcessChild {
520
533
  * the child registered. `launch` throws a {@link createDuplicateError} when the id is already live
521
534
  * and a {@link createProtocolError} after `destroy` has begun, including when the caller's own option
522
535
  * getter begins that teardown mid-construction — a spawn fault surfaces through the returned child's
523
- * `exit`, never from `launch`. `destroy` awaits every child's own teardown, which destroys each
524
- * child's observation emitter and leaves every subscription on it silently inert, then destroys the
525
- * registry emitter last.
536
+ * `exit`, never from `launch`. `destroy` awaits every child's own teardown, including the teardown
537
+ * of a child a lost race refused, which destroys each child's observation emitter and leaves every
538
+ * subscription on it silently inert, then destroys the registry emitter last.
526
539
  *
527
540
  * @example
528
541
  * ```ts
@@ -568,11 +581,11 @@ export declare class ProcessManager implements ProcessManagerInterface {
568
581
  * @remarks
569
582
  * {@link Process} reads every option before it spawns, so a caller's own option getter runs while
570
583
  * nothing has started and a throw from one strands no process. A getter that begins `destroy`
571
- * without throwing is the one remaining race, and it leaves a bounded residual: the child is
572
- * already spawned, so the launch is refused with a {@link createProtocolError} and that child is
573
- * torn down asynchronously, bounded by `grace` plus the confirmation window. The `protocol`
574
- * refusal throws synchronously before the `destroy` barrier settles. The barrier does not cover
575
- * that child's asynchronous teardown.
584
+ * without throwing is the one remaining race: the child is already spawned, so the launch is
585
+ * refused with a {@link createProtocolError} and that child is destroyed rather than adopted, its
586
+ * teardown bounded by `grace` plus the confirmation window. The `protocol` refusal throws
587
+ * synchronously, and the `destroy` barrier covers that teardown, so the refused child reaches its
588
+ * terminal moment before the barrier resolves.
576
589
  *
577
590
  * @param id - The registry key, unique among live children
578
591
  * @param options - The child construction options
@@ -747,14 +760,16 @@ export declare function snapshotCommand(command: ProcessCommand): ProcessCommand
747
760
  * Terminates one child process tree and reports whether its native exit was observed.
748
761
  *
749
762
  * @remarks
750
- * Windows ends the whole tree at once through {@link killTree}, falling back to a direct kill after
751
- * the utility fails, because the host has no cooperative termination to offer. A POSIX host signals
752
- * the process group `SIGTERM`, falls back to the direct child when no group owns its pid, waits
753
- * `grace`, then sends `SIGKILL` through the same route. No signal is initiated after the native exit
754
- * is observed; the window between initiating a signal and the host delivering it belongs to the
755
- * operating system. `confirm` bounds each awaited step rather than the call as a whole: on Windows
756
- * it bounds the `taskkill` call and then the final wait, and on a POSIX host `grace` bounds the
757
- * cooperative wait and `confirm` the final one. Never rejects.
763
+ * An already-exited child is returned on before any route to its pid runs, because the host has
764
+ * reaped that number and may have handed it to another process. Windows ends the whole tree at once
765
+ * through {@link killTree}, falling back to a direct kill after the utility fails, because the host
766
+ * has no cooperative termination to offer. A POSIX host signals the process group `SIGTERM`, falls
767
+ * back to the direct child when no group owns its pid, waits `grace`, then sends `SIGKILL` through
768
+ * the same route. No signal is initiated after the native exit is observed; the window between
769
+ * initiating a signal and the host delivering it belongs to the operating system. `confirm` bounds
770
+ * each awaited step rather than the call as a whole: on Windows it bounds the `taskkill` call and
771
+ * then the final wait, and on a POSIX host `grace` bounds the cooperative wait and `confirm` the
772
+ * final one. Never rejects.
758
773
  *
759
774
  * @param child - The child boundary
760
775
  * @param grace - The cooperative POSIX window in milliseconds between `SIGTERM` and `SIGKILL`
@@ -907,6 +922,20 @@ export declare function validateTimer(value: number | undefined, subject: string
907
922
  */
908
923
  export declare function validateWorkspace(workspace: string | undefined): void;
909
924
 
925
+ /**
926
+ * Waits for one child process's streams to close, bounded by a deadline.
927
+ *
928
+ * @param child - The child boundary
929
+ * @param timeout - The milliseconds to wait before giving up
930
+ * @returns True when the host close arrived inside the deadline; false otherwise
931
+ *
932
+ * @example
933
+ * ```ts
934
+ * const closed = await waitForClose(child, 5_000)
935
+ * ```
936
+ */
937
+ export declare function waitForClose(child: Pick<ProcessChild, 'once' | 'off'>, timeout: number): Promise<boolean>;
938
+
910
939
  /**
911
940
  * Waits for one child process's native exit, bounded by a deadline.
912
941
  *
@@ -187,9 +187,13 @@ export declare function detach(command: ProcessCommand_2, options?: DetachOption
187
187
  * rather than on process exit, so a descendant that inherited the child's stdio holds the run open
188
188
  * after the child itself has gone. Give such a run a `timeout`. The child's `environment` merges over
189
189
  * the parent unless the command is `isolated`, then `options.environment` on top, and `options.input`
190
- * overrides `command.input`. Unless `strict` is `false`, a failed run rejects with a
191
- * {@link createExecuteError} carrying the {@link ExecuteResult}. An invalid option or command string rejects
192
- * before the child is spawned, because an async function cannot throw synchronously.
190
+ * overrides `command.input`. A host fault while writing that input terminates the run by design and
191
+ * marks its result failed; a strict rejection carries the host fault as its cause. This differs
192
+ * from `Process` constructor input, whose package-initiated input phase stays quiet. Unless `strict`
193
+ * is `false`, a failed run rejects with a {@link ProcessError} carrying the {@link ExecuteResult};
194
+ * {@link createExecuteError} constructs every rejection outside the input-fault door. An invalid
195
+ * option or command string rejects before the child is spawned, because an async function cannot
196
+ * throw synchronously.
193
197
  *
194
198
  * @param command - The executable, arguments, and optional environment and input
195
199
  * @param options - Working directory, timeout, grace, signal, capture limit, and failure delivery
@@ -358,26 +362,23 @@ export declare function mergeEnvironment(isolated: boolean, base?: Readonly<Reco
358
362
  export declare function mergePlatformEnvironment(platform: NodeJS.Platform, parent: Readonly<Record<string, string | undefined>>, isolated: boolean, base?: Readonly<Record<string, string | undefined>>, override?: Readonly<Record<string, string | undefined>>): NodeJS.ProcessEnv;
359
363
 
360
364
  /**
361
- * One supervised child process with framed output, a bounded backlog, and bounded termination.
365
+ * Supervises one child while keeping every observation channel aligned at termination.
362
366
  *
363
367
  * @remarks
364
- * Standard output is framed through `readline` into a single-consumer stream: each line goes to
365
- * exactly one waiting iterator, so concurrent iterators split the output rather than each receiving
366
- * all of it. While no consumer has ever requested an iterator, stdout keeps draining so `exit` still
367
- * resolves, and retention stops at the `backlog` mark: a
368
- * consumer attaching later receives the retained head, a gap, then the live stream. After an iterator
369
- * has been requested, stdout pauses at the mark and resumes at half of it, so that consumer loses
370
- * nothing before termination and the child feels real backpressure. The mark is soft — the ordinary backlog can
371
- * overshoot it by the line that crossed it plus the rest of its delivered chunk. Termination never
372
- * reapplies backpressure, and retained lines are capped at twice `backlog`; later lines are dropped
373
- * and `truncated` reports the omission. Standard error is decoded and forwarded live as the `stderr`
374
- * event while a byte-bounded raw tail is retained as `evidence`. The typed `emitter` also carries the
375
- * child `error` cause on a spawn fault and the terminal `exit`, alongside the `exit` promise. `pid`,
376
- * `code`, and `signal` read the spawned child directly, so the native exit is readable before the
377
- * `exit` promise settles on stdio close. `stop` ends the whole tree and reports whether the native
378
- * exit was observed; `destroy` stops the child, destroys stdin so every pending `send` settles, and
379
- * destroys the emitter last. `destroy` resolving does not imply the child's stdio has closed, so
380
- * `exit` and `lines` can still be outstanding when a descendant holds an inherited pipe.
368
+ * The child's ending and the supervision's ending are distinct. `pid`, `code`, and `signal` read
369
+ * the host child directly, so they expose native exit as soon as the host records it. `settled`,
370
+ * `exit`, `evidence`, and `lines` reach one terminal moment after the read channels close or the
371
+ * bounded `drain` window cuts them off. That window is armed by the child's native exit and by a
372
+ * termination this package initiated, so every way a child can end reaches the moment. The terminal
373
+ * routine freezes `evidence` and ends `lines` before it destroys stdout, stderr, or the emitter, so
374
+ * the push channel never disappears while a pull channel can still change or wait indefinitely.
375
+ *
376
+ * Standard output is framed through `readline` into a single-consumer stream. Lines already framed
377
+ * and queued remain available through the terminal moment, while bytes arriving after a requested
378
+ * termination may be cut off. Standard error is forwarded through the live `stderr` event and
379
+ * retained as a byte-bounded raw tail until that same moment. `stop` ends the child tree and the
380
+ * observation surfaces. `destroy` performs that stop and then destroys the emitter after the
381
+ * frozen terminal state exists.
381
382
  *
382
383
  * @example
383
384
  * ```ts
@@ -408,41 +409,53 @@ export declare class Process implements ProcessInterface {
408
409
  get signal(): string | null;
409
410
  /** The typed lifecycle observation surface. */
410
411
  get emitter(): EmitterInterface<ProcessEventMap>;
411
- /** The captured stdout lines, in arrival order, ending when the child's stdout closes. */
412
+ /** The captured stdout lines, in arrival order, ending after queued lines at the terminal moment. */
412
413
  get lines(): AsyncIterable<string>;
413
- /** The decoded byte-bounded stderr tail. */
414
+ /** The decoded byte-bounded stderr tail, frozen at the terminal moment. */
414
415
  get evidence(): string;
415
416
  /** True when the `lines` stream omitted output after a retention bound was reached. */
416
417
  get truncated(): boolean;
417
- /** The terminal child state, observed once from the close event. */
418
+ /** True after the terminal moment arrived and `exit` settled. */
419
+ get settled(): boolean;
420
+ /** True after termination began, including after the terminal moment. */
421
+ get stopping(): boolean;
422
+ /** The terminal child state, observed once after stream close or the drain cutoff. */
418
423
  get exit(): Promise<ProcessExit>;
419
424
  /**
420
425
  * Write one line to the open standard-input channel.
421
426
  *
422
427
  * @remarks
423
- * Never rejects. The promise settles when the host reports the line handled, so a line written to
424
- * a child that is not reading stays pending until the child drains it or the channel closes. Every
425
- * terminal teardown path destroys stdin, so a pending write always settles by teardown; a caller
426
- * that needs its own deadline arms a timer and calls `stop`.
428
+ * Never rejects. `true` means the host accepted the bytes without reporting a fault; it does not
429
+ * prove that the child read them. An ordinary write settles when the kernel accepts it. Only a
430
+ * full pipe can hold the write unconfirmed. The `delivery` option can bound that wait, and every
431
+ * terminal teardown path settles pending writes. On Windows 11 with Node v24.18.1, measured on
432
+ * 2026-08-21, a child that closes its own file descriptor 0 can leave the parent pipe writable:
433
+ * the write can settle `true` without a callback error or a stream error while the child remains
434
+ * alive. After `stop` or `destroy` begins, a later call settles `false`. Version 0.0.4 could settle
435
+ * that call `true` before teardown destroyed the pipe; returning `false` avoids claiming delivery
436
+ * for bytes the package is about to discard.
427
437
  *
428
438
  * @param text - The line text without its trailing newline
429
- * @returns True when the line reached the host without error; false when the channel was closed, destroyed, ended, or the write failed
439
+ * @returns True when the host accepted the bytes without reporting a fault; false when the channel was closed, destroyed, ended, failed, or remained unconfirmed through `delivery`
430
440
  */
431
441
  send(text: string): Promise<boolean>;
432
442
  /**
433
- * Terminate the child process tree and await its observed exit.
443
+ * Terminates the child process tree and reaches the terminal observation moment.
434
444
  *
435
445
  * @remarks
436
- * Never rejects, and every call shares one termination.
446
+ * Never rejects, and every call shares one termination. After the termination sequence returns,
447
+ * confirmed or not, it waits at most `drain` for the read channels to close, then cuts them off
448
+ * and settles `exit` when they remain open. A cutoff reached before the native exit reports the
449
+ * `code` and `signal` the host had recorded by then, which is `null` for a child still running.
437
450
  *
438
451
  * @returns True when the child's native exit was observed; false when the confirmation deadline elapsed without it
439
452
  */
440
453
  stop(): Promise<boolean>;
441
454
  /**
442
- * Stop the child, close its standard-input channel, and destroy the observation emitter.
455
+ * Stops the child and destroys the observation emitter after the terminal state freezes.
443
456
  *
444
457
  * @remarks
445
- * Always resolves, including when termination was never confirmed.
458
+ * Always resolves, including when termination was never confirmed. Every call shares one barrier.
446
459
  *
447
460
  * @returns The stable barrier shared by every call
448
461
  */
@@ -465,8 +478,8 @@ export declare class Process implements ProcessInterface {
465
478
  * members, which is what lets a caller drive `stopChild` over a child it spawned itself. Each helper
466
479
  * takes the slice of this contract it reads: `exitCode` and `signalCode` are the host's
467
480
  * authoritative liveness answer, `pid` addresses a POSIX process group, `kill` delivers one signal,
468
- * `once` reports the native exit, and `off` releases that listener when the wait ends at its
469
- * deadline instead.
481
+ * `once` reports the native exit to `waitForExit` or the stream close to `waitForClose`, and `off`
482
+ * releases the corresponding listener when either wait ends.
470
483
  *
471
484
  * A non-detached child stays in its caller's process group, so no group carries its pid. `kill` is
472
485
  * the route that reaches it: `killProcess` signals the negated `pid` first and falls back to `kill`
@@ -487,25 +500,25 @@ export declare interface ProcessChild {
487
500
  */
488
501
  kill(signal: NodeJS.Signals): boolean;
489
502
  /**
490
- * Register a one-shot listener for the native exit.
503
+ * Register a one-shot listener for the native exit or stream close.
491
504
  *
492
- * @param event - The `exit` event name
493
- * @param listener - The listener invoked after the process exits
505
+ * @param event - The `exit` or `close` event name
506
+ * @param listener - The listener invoked after the selected event
494
507
  * @returns Whatever the emitter returns, which the helpers ignore
495
508
  */
496
- once(event: 'exit', listener: () => void): unknown;
509
+ once(event: 'exit' | 'close', listener: () => void): unknown;
497
510
  /**
498
- * Release one previously registered exit listener.
511
+ * Release one previously registered exit or close listener.
499
512
  *
500
513
  * @remarks
501
- * `waitForExit` calls this when its deadline elapses before the exit, so a child that outlives
502
- * several bounded waits accumulates no listeners.
514
+ * `waitForExit` releases its `exit` listener, and `waitForClose` releases its `close` listener, so
515
+ * a child that outlives several bounded waits accumulates neither.
503
516
  *
504
- * @param event - The `exit` event name
517
+ * @param event - The `exit` or `close` event name
505
518
  * @param listener - The listener registered through `once`
506
519
  * @returns Whatever the emitter returns, which the helpers ignore
507
520
  */
508
- off(event: 'exit', listener: () => void): unknown;
521
+ off(event: 'exit' | 'close', listener: () => void): unknown;
509
522
  }
510
523
 
511
524
  /**
@@ -520,9 +533,9 @@ export declare interface ProcessChild {
520
533
  * the child registered. `launch` throws a {@link createDuplicateError} when the id is already live
521
534
  * and a {@link createProtocolError} after `destroy` has begun, including when the caller's own option
522
535
  * getter begins that teardown mid-construction — a spawn fault surfaces through the returned child's
523
- * `exit`, never from `launch`. `destroy` awaits every child's own teardown, which destroys each
524
- * child's observation emitter and leaves every subscription on it silently inert, then destroys the
525
- * registry emitter last.
536
+ * `exit`, never from `launch`. `destroy` awaits every child's own teardown, including the teardown
537
+ * of a child a lost race refused, which destroys each child's observation emitter and leaves every
538
+ * subscription on it silently inert, then destroys the registry emitter last.
526
539
  *
527
540
  * @example
528
541
  * ```ts
@@ -568,11 +581,11 @@ export declare class ProcessManager implements ProcessManagerInterface {
568
581
  * @remarks
569
582
  * {@link Process} reads every option before it spawns, so a caller's own option getter runs while
570
583
  * nothing has started and a throw from one strands no process. A getter that begins `destroy`
571
- * without throwing is the one remaining race, and it leaves a bounded residual: the child is
572
- * already spawned, so the launch is refused with a {@link createProtocolError} and that child is
573
- * torn down asynchronously, bounded by `grace` plus the confirmation window. The `protocol`
574
- * refusal throws synchronously before the `destroy` barrier settles. The barrier does not cover
575
- * that child's asynchronous teardown.
584
+ * without throwing is the one remaining race: the child is already spawned, so the launch is
585
+ * refused with a {@link createProtocolError} and that child is destroyed rather than adopted, its
586
+ * teardown bounded by `grace` plus the confirmation window. The `protocol` refusal throws
587
+ * synchronously, and the `destroy` barrier covers that teardown, so the refused child reaches its
588
+ * terminal moment before the barrier resolves.
576
589
  *
577
590
  * @param id - The registry key, unique among live children
578
591
  * @param options - The child construction options
@@ -747,14 +760,16 @@ export declare function snapshotCommand(command: ProcessCommand): ProcessCommand
747
760
  * Terminates one child process tree and reports whether its native exit was observed.
748
761
  *
749
762
  * @remarks
750
- * Windows ends the whole tree at once through {@link killTree}, falling back to a direct kill after
751
- * the utility fails, because the host has no cooperative termination to offer. A POSIX host signals
752
- * the process group `SIGTERM`, falls back to the direct child when no group owns its pid, waits
753
- * `grace`, then sends `SIGKILL` through the same route. No signal is initiated after the native exit
754
- * is observed; the window between initiating a signal and the host delivering it belongs to the
755
- * operating system. `confirm` bounds each awaited step rather than the call as a whole: on Windows
756
- * it bounds the `taskkill` call and then the final wait, and on a POSIX host `grace` bounds the
757
- * cooperative wait and `confirm` the final one. Never rejects.
763
+ * An already-exited child is returned on before any route to its pid runs, because the host has
764
+ * reaped that number and may have handed it to another process. Windows ends the whole tree at once
765
+ * through {@link killTree}, falling back to a direct kill after the utility fails, because the host
766
+ * has no cooperative termination to offer. A POSIX host signals the process group `SIGTERM`, falls
767
+ * back to the direct child when no group owns its pid, waits `grace`, then sends `SIGKILL` through
768
+ * the same route. No signal is initiated after the native exit is observed; the window between
769
+ * initiating a signal and the host delivering it belongs to the operating system. `confirm` bounds
770
+ * each awaited step rather than the call as a whole: on Windows it bounds the `taskkill` call and
771
+ * then the final wait, and on a POSIX host `grace` bounds the cooperative wait and `confirm` the
772
+ * final one. Never rejects.
758
773
  *
759
774
  * @param child - The child boundary
760
775
  * @param grace - The cooperative POSIX window in milliseconds between `SIGTERM` and `SIGKILL`
@@ -907,6 +922,20 @@ export declare function validateTimer(value: number | undefined, subject: string
907
922
  */
908
923
  export declare function validateWorkspace(workspace: string | undefined): void;
909
924
 
925
+ /**
926
+ * Waits for one child process's streams to close, bounded by a deadline.
927
+ *
928
+ * @param child - The child boundary
929
+ * @param timeout - The milliseconds to wait before giving up
930
+ * @returns True when the host close arrived inside the deadline; false otherwise
931
+ *
932
+ * @example
933
+ * ```ts
934
+ * const closed = await waitForClose(child, 5_000)
935
+ * ```
936
+ */
937
+ export declare function waitForClose(child: Pick<ProcessChild, 'once' | 'off'>, timeout: number): Promise<boolean>;
938
+
910
939
  /**
911
940
  * Waits for one child process's native exit, bounded by a deadline.
912
941
  *