@orkestrel/process 0.0.7 → 0.0.8

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.
@@ -16,6 +16,9 @@ import { ProcessManagerEventMap } from '@orkestrel/process';
16
16
  import { ProcessManagerInterface } from '@orkestrel/process';
17
17
  import { ProcessManagerOptions } from '@orkestrel/process';
18
18
  import { ProcessOptions } from '@orkestrel/process';
19
+ import { SessionEventMap } from '@orkestrel/process';
20
+ import { SessionInterface } from '@orkestrel/process';
21
+ import { SessionOptions } from '@orkestrel/process';
19
22
  import { SpawnInput } from '@orkestrel/process';
20
23
 
21
24
  /**
@@ -151,6 +154,25 @@ export declare function createProcess(options: ProcessOptions): ProcessInterface
151
154
  */
152
155
  export declare function createProcessManager(options?: ProcessManagerOptions): ProcessManagerInterface;
153
156
 
157
+ /**
158
+ * Creates one raw byte session over a supervised child process.
159
+ *
160
+ * @param options - Command, workspace, termination, evidence, stdin, and observation settings
161
+ * @returns The launched {@link SessionInterface}
162
+ *
163
+ * @example
164
+ * ```ts
165
+ * import { createSession } from '@orkestrel/process/server'
166
+ *
167
+ * const session = createSession({
168
+ * command: { file: 'node', arguments: ['server.js', '--stdio'] },
169
+ * workspace: process.cwd(),
170
+ * grace: 5000,
171
+ * })
172
+ * ```
173
+ */
174
+ export declare function createSession(options: SessionOptions): SessionInterface;
175
+
154
176
  /**
155
177
  * Spawns one command as a detached process and returns without waiting for it.
156
178
  *
@@ -735,6 +757,108 @@ export declare interface RetentionInterface {
735
757
  retain(chunk: unknown, limit: number): Buffer_2 | undefined;
736
758
  }
737
759
 
760
+ /**
761
+ * Supervises one child and publishes its standard output as raw bytes.
762
+ *
763
+ * @remarks
764
+ * This is the transport face of the supervision engine `Process` also composes. It frames nothing,
765
+ * retains nothing, and decodes nothing on the output side: every chunk the host delivers becomes one
766
+ * `stdout` event carrying that chunk's bytes, in arrival order, so a consumer speaking a
767
+ * length-prefixed or delimiter-framed protocol reads exactly what the child wrote and frames it
768
+ * itself. Standard error is decoded and forwarded as `stderr`, with the same byte-bounded `evidence`
769
+ * tail a `Process` retains, because a diagnostic stream is read rather than parsed.
770
+ *
771
+ * Each emitted chunk is this session's own copy, and a plain `Uint8Array` rather than the host buffer
772
+ * the read produced, so a consumer keeps it, mutates it, concatenates it, and reads its whole backing
773
+ * buffer without reaching memory the host still manages and without depending on a host type.
774
+ *
775
+ * The standard-input channel is open from the spawn, and `end` closes it without terminating
776
+ * anything. That is the member a cooperative protocol reaches for: the child observes end of input
777
+ * and exits on its own, which `ending` reports. `stop` and `destroy` remain the terminations, and
778
+ * `exit` remains the terminal moment — the native exit plus at most `drain` while a descendant holds
779
+ * the inherited read ends.
780
+ *
781
+ * @example
782
+ * ```ts
783
+ * import { Session } from '@orkestrel/process/server'
784
+ *
785
+ * const session = new Session({
786
+ * command: { file: 'node', arguments: ['-e', 'process.stdin.pipe(process.stdout)'] },
787
+ * workspace: process.cwd(),
788
+ * })
789
+ * ```
790
+ */
791
+ export declare class Session implements SessionInterface {
792
+ #private;
793
+ /**
794
+ * Spawn one child process and begin byte capture.
795
+ *
796
+ * @param options - Command, workspace, termination, evidence, stdin, and observation settings
797
+ * @throws A {@link ProcessError} coded `invalid` when an option or command string is malformed
798
+ */
799
+ constructor(options: SessionOptions);
800
+ /** The host process id, fixed when construction returns, or `undefined` when the spawn produced none. */
801
+ get pid(): number | undefined;
802
+ /** The exit code the host recorded, or `null` while the child has not exited and when a signal ended it. */
803
+ get code(): number | null;
804
+ /** The terminating signal name the host recorded, or `null` while the child has not exited and when it exited on its own. */
805
+ get signal(): string | null;
806
+ /** The typed lifecycle observation surface. */
807
+ get emitter(): EmitterInterface<SessionEventMap>;
808
+ /** The decoded byte-bounded stderr tail, frozen at the terminal moment. */
809
+ get evidence(): string;
810
+ /** True after the terminal moment arrived and `exit` settled. */
811
+ get settled(): boolean;
812
+ /** True after termination began, including after the terminal moment. `end` never turns it true. */
813
+ get stopping(): boolean;
814
+ /** The child's own ending, awaited without the terminal moment's drain window. */
815
+ get ending(): Promise<void>;
816
+ /** The terminal child state, observed once after stream close or the drain cutoff. */
817
+ get exit(): Promise<ProcessExit>;
818
+ /**
819
+ * Writes raw bytes to the open standard-input channel.
820
+ *
821
+ * @remarks
822
+ * Never rejects, and appends no terminator: the child receives exactly these bytes. `true` means
823
+ * the host accepted them without reporting a fault; it does not prove that the child read them.
824
+ * The channel can queue the payload, so treat the array as owned by the channel until the
825
+ * returned promise settles.
826
+ *
827
+ * @param bytes - The payload to write, already framed by the caller
828
+ * @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`
829
+ */
830
+ write(bytes: Uint8Array): Promise<boolean>;
831
+ /**
832
+ * Closes the standard-input channel and leaves the child running.
833
+ *
834
+ * @remarks
835
+ * Never rejects and terminates nothing: `stopping` stays false and the terminal moment does not
836
+ * arrive. Every call shares one barrier, which resolves after the host flushes the writes it had
837
+ * already accepted. A later `write` resolves `false`.
838
+ *
839
+ * @returns The stable barrier shared by every call
840
+ */
841
+ end(): Promise<void>;
842
+ /**
843
+ * Terminates the child process tree and reaches the terminal observation moment.
844
+ *
845
+ * @remarks
846
+ * Never rejects, and every call shares one termination bounded by `grace` and `drain`.
847
+ *
848
+ * @returns True when the child's native exit was observed; false when the confirmation deadline elapsed without it
849
+ */
850
+ stop(): Promise<boolean>;
851
+ /**
852
+ * Stops the child and destroys the observation emitter after the terminal state freezes.
853
+ *
854
+ * @remarks
855
+ * Always resolves, including when termination was never confirmed. Every call shares one barrier.
856
+ *
857
+ * @returns The stable barrier shared by every call
858
+ */
859
+ destroy(): Promise<void>;
860
+ }
861
+
738
862
  /**
739
863
  * Takes one owned frozen snapshot of a caller's command.
740
864
  *
@@ -16,6 +16,9 @@ import { ProcessManagerEventMap } from '@orkestrel/process';
16
16
  import { ProcessManagerInterface } from '@orkestrel/process';
17
17
  import { ProcessManagerOptions } from '@orkestrel/process';
18
18
  import { ProcessOptions } from '@orkestrel/process';
19
+ import { SessionEventMap } from '@orkestrel/process';
20
+ import { SessionInterface } from '@orkestrel/process';
21
+ import { SessionOptions } from '@orkestrel/process';
19
22
  import { SpawnInput } from '@orkestrel/process';
20
23
 
21
24
  /**
@@ -151,6 +154,25 @@ export declare function createProcess(options: ProcessOptions): ProcessInterface
151
154
  */
152
155
  export declare function createProcessManager(options?: ProcessManagerOptions): ProcessManagerInterface;
153
156
 
157
+ /**
158
+ * Creates one raw byte session over a supervised child process.
159
+ *
160
+ * @param options - Command, workspace, termination, evidence, stdin, and observation settings
161
+ * @returns The launched {@link SessionInterface}
162
+ *
163
+ * @example
164
+ * ```ts
165
+ * import { createSession } from '@orkestrel/process/server'
166
+ *
167
+ * const session = createSession({
168
+ * command: { file: 'node', arguments: ['server.js', '--stdio'] },
169
+ * workspace: process.cwd(),
170
+ * grace: 5000,
171
+ * })
172
+ * ```
173
+ */
174
+ export declare function createSession(options: SessionOptions): SessionInterface;
175
+
154
176
  /**
155
177
  * Spawns one command as a detached process and returns without waiting for it.
156
178
  *
@@ -735,6 +757,108 @@ export declare interface RetentionInterface {
735
757
  retain(chunk: unknown, limit: number): Buffer_2 | undefined;
736
758
  }
737
759
 
760
+ /**
761
+ * Supervises one child and publishes its standard output as raw bytes.
762
+ *
763
+ * @remarks
764
+ * This is the transport face of the supervision engine `Process` also composes. It frames nothing,
765
+ * retains nothing, and decodes nothing on the output side: every chunk the host delivers becomes one
766
+ * `stdout` event carrying that chunk's bytes, in arrival order, so a consumer speaking a
767
+ * length-prefixed or delimiter-framed protocol reads exactly what the child wrote and frames it
768
+ * itself. Standard error is decoded and forwarded as `stderr`, with the same byte-bounded `evidence`
769
+ * tail a `Process` retains, because a diagnostic stream is read rather than parsed.
770
+ *
771
+ * Each emitted chunk is this session's own copy, and a plain `Uint8Array` rather than the host buffer
772
+ * the read produced, so a consumer keeps it, mutates it, concatenates it, and reads its whole backing
773
+ * buffer without reaching memory the host still manages and without depending on a host type.
774
+ *
775
+ * The standard-input channel is open from the spawn, and `end` closes it without terminating
776
+ * anything. That is the member a cooperative protocol reaches for: the child observes end of input
777
+ * and exits on its own, which `ending` reports. `stop` and `destroy` remain the terminations, and
778
+ * `exit` remains the terminal moment — the native exit plus at most `drain` while a descendant holds
779
+ * the inherited read ends.
780
+ *
781
+ * @example
782
+ * ```ts
783
+ * import { Session } from '@orkestrel/process/server'
784
+ *
785
+ * const session = new Session({
786
+ * command: { file: 'node', arguments: ['-e', 'process.stdin.pipe(process.stdout)'] },
787
+ * workspace: process.cwd(),
788
+ * })
789
+ * ```
790
+ */
791
+ export declare class Session implements SessionInterface {
792
+ #private;
793
+ /**
794
+ * Spawn one child process and begin byte capture.
795
+ *
796
+ * @param options - Command, workspace, termination, evidence, stdin, and observation settings
797
+ * @throws A {@link ProcessError} coded `invalid` when an option or command string is malformed
798
+ */
799
+ constructor(options: SessionOptions);
800
+ /** The host process id, fixed when construction returns, or `undefined` when the spawn produced none. */
801
+ get pid(): number | undefined;
802
+ /** The exit code the host recorded, or `null` while the child has not exited and when a signal ended it. */
803
+ get code(): number | null;
804
+ /** The terminating signal name the host recorded, or `null` while the child has not exited and when it exited on its own. */
805
+ get signal(): string | null;
806
+ /** The typed lifecycle observation surface. */
807
+ get emitter(): EmitterInterface<SessionEventMap>;
808
+ /** The decoded byte-bounded stderr tail, frozen at the terminal moment. */
809
+ get evidence(): string;
810
+ /** True after the terminal moment arrived and `exit` settled. */
811
+ get settled(): boolean;
812
+ /** True after termination began, including after the terminal moment. `end` never turns it true. */
813
+ get stopping(): boolean;
814
+ /** The child's own ending, awaited without the terminal moment's drain window. */
815
+ get ending(): Promise<void>;
816
+ /** The terminal child state, observed once after stream close or the drain cutoff. */
817
+ get exit(): Promise<ProcessExit>;
818
+ /**
819
+ * Writes raw bytes to the open standard-input channel.
820
+ *
821
+ * @remarks
822
+ * Never rejects, and appends no terminator: the child receives exactly these bytes. `true` means
823
+ * the host accepted them without reporting a fault; it does not prove that the child read them.
824
+ * The channel can queue the payload, so treat the array as owned by the channel until the
825
+ * returned promise settles.
826
+ *
827
+ * @param bytes - The payload to write, already framed by the caller
828
+ * @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`
829
+ */
830
+ write(bytes: Uint8Array): Promise<boolean>;
831
+ /**
832
+ * Closes the standard-input channel and leaves the child running.
833
+ *
834
+ * @remarks
835
+ * Never rejects and terminates nothing: `stopping` stays false and the terminal moment does not
836
+ * arrive. Every call shares one barrier, which resolves after the host flushes the writes it had
837
+ * already accepted. A later `write` resolves `false`.
838
+ *
839
+ * @returns The stable barrier shared by every call
840
+ */
841
+ end(): Promise<void>;
842
+ /**
843
+ * Terminates the child process tree and reaches the terminal observation moment.
844
+ *
845
+ * @remarks
846
+ * Never rejects, and every call shares one termination bounded by `grace` and `drain`.
847
+ *
848
+ * @returns True when the child's native exit was observed; false when the confirmation deadline elapsed without it
849
+ */
850
+ stop(): Promise<boolean>;
851
+ /**
852
+ * Stops the child and destroys the observation emitter after the terminal state freezes.
853
+ *
854
+ * @remarks
855
+ * Always resolves, including when termination was never confirmed. Every call shares one barrier.
856
+ *
857
+ * @returns The stable barrier shared by every call
858
+ */
859
+ destroy(): Promise<void>;
860
+ }
861
+
738
862
  /**
739
863
  * Takes one owned frozen snapshot of a caller's command.
740
864
  *