@unieai/rabi-subprocess-local 0.0.0-stage → 0.2.2-rc.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +7 -2
  3. package/lib/index.js +1706 -0
  4. package/lib/output.js +239 -0
  5. package/lib/runner-launch-CKTiL8M8.js +1556 -0
  6. package/lib/runner.js +432 -0
  7. package/lib/types/bin.d.ts +7 -0
  8. package/lib/types/control-spawn.d.ts +19 -0
  9. package/lib/types/index.d.ts +59 -0
  10. package/lib/types/linux-execve.d.ts +9 -0
  11. package/lib/types/linux-scope-selector.d.ts +60 -0
  12. package/lib/types/linux-scope.d.ts +124 -0
  13. package/lib/types/managed-owner.d.ts +36 -0
  14. package/lib/types/output.d.ts +137 -0
  15. package/lib/types/process-inspector.d.ts +142 -0
  16. package/lib/types/runner-launch.d.ts +68 -0
  17. package/lib/types/runner-protocol.d.ts +113 -0
  18. package/lib/types/shell-activity.d.ts +37 -0
  19. package/lib/types/spawn-runner.d.ts +37 -0
  20. package/lib/types/spawn.d.ts +86 -0
  21. package/lib/types/terminal.d.ts +80 -0
  22. package/lib/types/windows-inspector.d.ts +79 -0
  23. package/lib/types/windows-job.d.ts +30 -0
  24. package/locale/de.json +6 -0
  25. package/locale/en.json +5 -0
  26. package/locale/es.json +6 -0
  27. package/locale/fr.json +6 -0
  28. package/locale/ja.json +6 -0
  29. package/locale/pt.json +6 -0
  30. package/locale/ru.json +6 -0
  31. package/locale/zh.json +6 -0
  32. package/package.json +54 -4
  33. package/scripts/ensure-spawn-helper.mjs +16 -0
  34. package/src/bin.ts +25 -0
  35. package/src/control-spawn.ts +35 -0
  36. package/src/index.ts +387 -0
  37. package/src/linux-execve.ts +92 -0
  38. package/src/linux-scope-selector.ts +101 -0
  39. package/src/linux-scope.ts +726 -0
  40. package/src/managed-owner.ts +56 -0
  41. package/src/output.ts +313 -0
  42. package/src/process-inspector.ts +560 -0
  43. package/src/runner-launch.ts +315 -0
  44. package/src/runner-protocol.ts +281 -0
  45. package/src/shell-activity.ts +131 -0
  46. package/src/spawn-runner.ts +488 -0
  47. package/src/spawn.ts +500 -0
  48. package/src/terminal.ts +479 -0
  49. package/src/windows-inspector.ts +346 -0
  50. package/src/windows-job.ts +269 -0
@@ -0,0 +1,124 @@
1
+ /** Linux user-systemd scope launch and managed-range ownership. */
2
+ import { spawn, spawnSync } from 'node:child_process';
3
+ import type { SubprocessOutcome, SubprocessSpawnSpec, SubprocessTerminalSpawnSpec } from '@unieai/rabi-subprocess';
4
+ import { loadLinuxExecve } from './linux-execve.ts';
5
+ import type { BoundProcessOwner, ManagedProcessLaunch } from './managed-owner.ts';
6
+ import type { RunnerInvocation } from './runner-launch.ts';
7
+ /** Test seams for systemd command execution. */
8
+ export interface LinuxScopeInternals {
9
+ spawn?: typeof spawn;
10
+ spawnSync?: typeof spawnSync;
11
+ systemctlQuery?: (command: string, args: readonly string[]) => Promise<SystemctlResult>;
12
+ systemdRun?: string;
13
+ systemctl?: string;
14
+ runnerInvocation?: RunnerInvocation;
15
+ resolveRunnerInvocation?: () => RunnerInvocation;
16
+ runnerAvailable?: (invocation: RunnerInvocation) => boolean;
17
+ loadLinuxExecve?: typeof loadLinuxExecve;
18
+ sleep?: (delayMs: number, signal?: AbortSignal) => Promise<void>;
19
+ /** Kernel unix socket table read by the user-manager confirmation; defaults to /proc/net/unix. */
20
+ unixSocketTable?: string;
21
+ }
22
+ interface SystemctlResult {
23
+ status: number | null;
24
+ stdout: string;
25
+ stderr: string;
26
+ error?: Error;
27
+ }
28
+ /** systemd-run options that keep target argv literal; empty where scope mode never expands argv. */
29
+ export type LiteralArgvOptions = readonly string[];
30
+ /**
31
+ * Confirm this exact runner entry and libc execve binding without a probe mode.
32
+ * @param internals - optional runner and libc-binding seams used by tests.
33
+ * @returns whether the bootstrap can enter the final target.
34
+ */
35
+ export declare function probeLinuxBootstrap(internals?: LinuxScopeInternals): boolean;
36
+ /**
37
+ * Confirm current literal-argv transient-scope support before selecting native launch.
38
+ * @param internals - optional systemd command seams used by tests.
39
+ * @returns the options that keep target argv literal, or undefined when the user manager cannot create the scope.
40
+ */
41
+ export declare function probeLinuxScope(internals?: LinuxScopeInternals): LiteralArgvOptions | undefined;
42
+ /**
43
+ * Check every Linux native prerequisite on each call.
44
+ * @param internals - optional native capability seams used by tests.
45
+ * @returns the literal-argv scope options when Linux native containment is available, otherwise undefined.
46
+ */
47
+ export declare function probeLinuxNative(internals?: LinuxScopeInternals): LiteralArgvOptions | undefined;
48
+ /**
49
+ * Query the user manager once through systemctl.
50
+ * @param internals - optional systemctl seam used by tests.
51
+ * @returns whether the query succeeds.
52
+ */
53
+ export declare function probeLinuxManager(internals?: LinuxScopeInternals): boolean;
54
+ /**
55
+ * Identify the user manager's listener on `$XDG_RUNTIME_DIR/systemd/private`, the socket
56
+ * `systemd-run --user` connects through.
57
+ * @param internals - optional socket-table seam used by tests.
58
+ * @returns the listening socket's inode from the kernel socket table, or undefined when
59
+ * XDG_RUNTIME_DIR is unset or nothing in this network namespace listens there.
60
+ */
61
+ export declare function linuxManagerListener(internals?: LinuxScopeInternals): string | undefined;
62
+ /**
63
+ * Identify the systemd-run binary that scope launches resolve through PATH, so a package upgrade
64
+ * that replaces it triggers another probe of its literal-argv options.
65
+ * @param internals - optional systemd-run seam used by tests.
66
+ * @returns the device, inode, size, and modification time of the first match, or undefined when none resolves.
67
+ */
68
+ export declare function systemdRunIdentity(internals?: LinuxScopeInternals): string | undefined;
69
+ /**
70
+ * Confirm the user manager before a scope launch. A listener on its private socket confirms it
71
+ * without a child process; otherwise one systemctl query decides. A hung manager that still
72
+ * listens passes, and its scope launch fails with LinuxScopeNotStartedError.
73
+ * @param internals - optional socket-table and systemctl seams used by tests.
74
+ * @returns whether a scope launch can reach the user manager.
75
+ */
76
+ export declare function confirmLinuxManager(internals?: LinuxScopeInternals): boolean;
77
+ interface DirectRange {
78
+ running(): boolean;
79
+ /** True for group TERM delivery, direct signal submission, or proven direct-PID absence. */
80
+ signal(signal: 'SIGTERM' | 'SIGKILL'): boolean;
81
+ /** Direct exit/error settlement, independent of output drain and managed-range completion. */
82
+ settled: Promise<unknown>;
83
+ }
84
+ /** A scope launch whose bootstrap never consumed its launch request, so its target never ran. */
85
+ export declare class LinuxScopeNotStartedError extends Error {
86
+ readonly name = "LinuxScopeNotStartedError";
87
+ }
88
+ /**
89
+ * Send a direct-process signal, distinguishing an absent PID from failed delivery.
90
+ * @param pid - owned direct-process identity whose exit notification can still be pending.
91
+ * @param send - platform signal operation; true means the signal was submitted.
92
+ * @returns whether the signal was submitted or the owned PID is already absent.
93
+ */
94
+ export declare function signalLinuxDirectProcess(pid: number, send: () => boolean): boolean;
95
+ /** Linux PTY invocation and owner for the exact one-shot scope/bootstrap. */
96
+ export interface LinuxTerminalScopeLaunch {
97
+ command: string;
98
+ args: string[];
99
+ cwd: string;
100
+ env: NodeJS.ProcessEnv;
101
+ bindOwner: (direct: DirectRange) => BoundProcessOwner;
102
+ resolveOutcome: (outcome: SubprocessOutcome) => SubprocessOutcome;
103
+ cleanup: () => void;
104
+ }
105
+ /**
106
+ * Prepare one Linux PTY scope using the same launch request and bootstrap core.
107
+ * @param spec - terminal target request.
108
+ * @param targetEnv - validated complete target environment.
109
+ * @param literalArgv - options from the provider's positive scope probe.
110
+ * @param internals - optional runner and systemd seams used by tests.
111
+ * @returns invocation and ownership callbacks; requested termination preserves the observed signal even before bootstrap consumption.
112
+ */
113
+ export declare function prepareLinuxTerminalScope(spec: SubprocessTerminalSpawnSpec, targetEnv: Record<string, string>, literalArgv: LiteralArgvOptions, internals?: LinuxScopeInternals): LinuxTerminalScopeLaunch;
114
+ /**
115
+ * Launch one ordinary target inside a transient user scope.
116
+ * @param spec - ordinary target request.
117
+ * @param targetEnv - validated complete target environment.
118
+ * @param literalArgv - options from the provider's positive scope probe.
119
+ * @param internals - optional runner and systemd seams used by tests.
120
+ * @returns streams, result, and scope owner; requested termination preserves the observed signal even before bootstrap consumption.
121
+ */
122
+ export declare function launchLinuxScope(spec: SubprocessSpawnSpec, targetEnv: Record<string, string>, literalArgv: LiteralArgvOptions, internals?: LinuxScopeInternals): ManagedProcessLaunch;
123
+ export {};
124
+ //# sourceMappingURL=linux-scope.d.ts.map
@@ -0,0 +1,36 @@
1
+ /** Minimal managed-range ownership bound to one ordinary subprocess handle. */
2
+ import type { Duplex, Readable, Writable } from 'node:stream';
3
+ import type { SubprocessOutcome } from '@unieai/rabi-subprocess';
4
+ /** Platform owner used by termination and whole-range settlement. */
5
+ export interface BoundProcessOwner {
6
+ /** Signal the managed range; `cancellationReason` is used only before Windows target commit. */
7
+ signal(signal: 'SIGTERM' | 'SIGKILL', cancellationReason?: unknown): void;
8
+ /** Wait for the same managed range to become empty; reject when it cannot be observed. */
9
+ waitForExit(): Promise<void>;
10
+ /**
11
+ * Count tasks in the native range, including descendants outside the observable process tree.
12
+ * @returns the current count, or undefined when observation is unavailable.
13
+ */
14
+ inspectTaskCount?(): number | undefined;
15
+ /** Synchronously force final termination during JavaScript-observable host exit. */
16
+ terminateForHostExit(): void;
17
+ /** Release provider-private protocol artifacts after outcome and range settlement. */
18
+ cleanup?(): void;
19
+ }
20
+ /** Platform launch facts consumed by the common stdio and result lifecycle. */
21
+ export interface ManagedProcessLaunch {
22
+ stdin: Writable | null;
23
+ stdout: Readable | null;
24
+ stderr: Readable | null;
25
+ control?: Duplex | undefined;
26
+ direct: Promise<SubprocessOutcome>;
27
+ owner: BoundProcessOwner;
28
+ }
29
+ /**
30
+ * Apply an optional abort bound to one shared wait promise.
31
+ * @param pending - managed-range wait shared by all callers.
32
+ * @param signal - optional caller cancellation signal.
33
+ * @returns whether the managed-range wait completed before cancellation.
34
+ */
35
+ export declare function waitWithAbort(pending: Promise<void>, signal?: AbortSignal): Promise<boolean>;
36
+ //# sourceMappingURL=managed-owner.d.ts.map
@@ -0,0 +1,137 @@
1
+ import type { CollectedOutput } from '@unieai/rabi-subprocess';
2
+ /**
3
+ * Receives one spill failure so the owner can log it through its own logger.
4
+ * Called at most once per collector, after the spill has been discarded and
5
+ * the in-memory tail has kept collecting. A reporter that throws is contained
6
+ * and its failure written to stderr.
7
+ * @param error - the `node:fs` failure from opening or appending the spill file.
8
+ * @param label - the stream label of the collector that failed.
9
+ */
10
+ export type SpillFailureReporter = (error: unknown, label: string) => void;
11
+ /** Spill storage for one collected stream; `undefined` means tail-only collection. */
12
+ export interface SpillOptions {
13
+ /** Whole-stream byte cap beyond which an incomplete spill is discarded. */
14
+ maxBytes: number;
15
+ /** Private directory receiving the spill file. */
16
+ dir: string;
17
+ /** Owner-side report of a spill open or write failure. */
18
+ onFailure: SpillFailureReporter;
19
+ }
20
+ /**
21
+ * Build the reporter an owner passes as {@link SpillOptions.onFailure}: one
22
+ * error-level log line naming the owner and stream, with the failure appended
23
+ * so its `code`, `syscall`, and `path` reach the log.
24
+ * @param logger - the owner's plugin logger.
25
+ * @param owner - the component named in the line.
26
+ * @returns the reporter.
27
+ */
28
+ export declare function logSpillFailure(logger: {
29
+ error(message: string, ...detail: unknown[]): void;
30
+ }, owner: string): SpillFailureReporter;
31
+ /** Inputs a managed native process needs before its output streams are bound. */
32
+ export interface ManagedProcessBinding {
33
+ /** Directory receiving spill files. */
34
+ spillDir: string;
35
+ /** Receives a spill open or write failure. */
36
+ onSpillFailure: SpillFailureReporter;
37
+ }
38
+ /**
39
+ * Prepare fallible output storage before starting a managed native process.
40
+ * This is the explicit resolve step for spill inputs: the spill directory
41
+ * defaults to the private per-process directory, and the failure reporter
42
+ * defaults to a stderr line when the caller has no logger.
43
+ * @param internals - optional caller-owned spill directory and failure reporter.
44
+ * @returns binding inputs whose spill directory is ready for use.
45
+ */
46
+ export declare function prepareManagedProcessBinding(internals?: {
47
+ spillDir?: string;
48
+ onSpillFailure?: SpillFailureReporter;
49
+ }): ManagedProcessBinding;
50
+ /**
51
+ * Collects one stream with a bounded in-memory tail. With spill options, on
52
+ * first overflow a spill file is created and every chunk (including those
53
+ * already collected) is appended there while the full stream remains within
54
+ * the cap; without them, only the in-memory tail is ever retained (the
55
+ * diagnostic-tail shape — a language server's stderr).
56
+ *
57
+ * Spilling is best-effort: a spill open or write failure discards the spill,
58
+ * reports once through {@link SpillOptions.onFailure}, and never interrupts
59
+ * in-memory collection, because `push()` runs inside the stream's `'data'`
60
+ * listener where a thrown error would become an uncaught exception.
61
+ *
62
+ * Tail-keep rationale (pi/OpenCode): errors and final results cluster at the
63
+ * end of command output; the spill file covers the head.
64
+ */
65
+ export declare class OutputCollector {
66
+ private readonly maxBytes;
67
+ private readonly label;
68
+ private readonly spill;
69
+ private chunks;
70
+ private bytes;
71
+ private dropped;
72
+ private spillFd;
73
+ private spillFile;
74
+ private spillDisabled;
75
+ /** Total bytes ever pushed (not just retained). */
76
+ private total;
77
+ /**
78
+ * @param maxBytes - in-memory tail cap in bytes.
79
+ * @param label - stream label used in spill file names and failure reports.
80
+ * @param spill - spill storage; omit for tail-only collection.
81
+ */
82
+ constructor(maxBytes: number, label: string, spill: SpillOptions | undefined);
83
+ /**
84
+ * Ingest one stream chunk, counting it toward the whole-stream total. On
85
+ * first overflow of the in-memory cap a spill file is opened (when spilling
86
+ * is enabled) and every chunk (already-collected ones included) is appended
87
+ * there from then on; the in-memory tail then drops whole chunks from its
88
+ * head (or the head of a single over-cap chunk) until it fits the cap again.
89
+ * @param chunk - the raw bytes from one stream 'data' event.
90
+ */
91
+ push(chunk: Buffer): void;
92
+ /**
93
+ * Open the spill file lazily and append `chunk` (and any prior chunks once).
94
+ * Runs inside the stream's `'data'` listener, so every filesystem failure is
95
+ * contained here: the spill is discarded, reported once, and collection
96
+ * continues with the in-memory tail alone.
97
+ */
98
+ private spillAll;
99
+ /** Stop spilling and remove the file once it can no longer hold the complete stream. */
100
+ private discardSpill;
101
+ /**
102
+ * Incremental read in whole-stream byte coordinates: returns everything
103
+ * pushed since `fromByte`. When `fromByte` has already slid out of the
104
+ * in-memory tail window, the read is `lossy` — it returns the whole
105
+ * retained tail and the gap is only recoverable from the spill file.
106
+ * @param fromByte - whole-stream offset to resume from (a prior read's `nextOffset`; 0 for the first read).
107
+ * @returns the delta text, the offset for the next read, the `lossy` flag, and the spill path when one was created.
108
+ */
109
+ readFrom(fromByte: number): {
110
+ text: string;
111
+ nextOffset: number;
112
+ lossy: boolean;
113
+ spillPath?: string;
114
+ };
115
+ /**
116
+ * Copy the retained raw tail with its position in the complete observed stream.
117
+ * @returns independent tail bytes and the total byte count before truncation.
118
+ */
119
+ snapshot(): {
120
+ bytes: Buffer;
121
+ totalBytes: number;
122
+ };
123
+ /**
124
+ * Close the spill file once the stream has ended. A failed close (delayed
125
+ * writeback fault) stops advertising the spill path — the file may be
126
+ * missing its tail — while every in-memory read keeps working. Idempotent;
127
+ * the spawn path seals both collectors at settlement so reads after exit
128
+ * never point at a still-open file.
129
+ */
130
+ seal(): void;
131
+ /**
132
+ * Seal the spill file and return the final output.
133
+ * @returns the final collected output: tail text, truncation flag, and the spill path when intact.
134
+ */
135
+ finalize(): CollectedOutput;
136
+ }
137
+ //# sourceMappingURL=output.d.ts.map
@@ -0,0 +1,142 @@
1
+ /** Platform process-table inspection for terminal readiness, signals, and teardown. */
2
+ import type { SubprocessTerminalSignal } from '@unieai/rabi-subprocess';
3
+ /** PID plus start identity, preventing teardown escalation after PID reuse. */
4
+ export interface ProcessIdentity {
5
+ pid: number;
6
+ started: string;
7
+ }
8
+ interface FileStatus {
9
+ readonly rdev: number;
10
+ isCharacterDevice(): boolean;
11
+ }
12
+ /**
13
+ * One observation of the platform process table, shared by every question a
14
+ * single readiness poll or teardown pass asks.
15
+ *
16
+ * The table is read at most once, on the first question that needs it — a
17
+ * `/bin/ps` fork on macOS, a `/proc` walk on Linux, a Toolhelp32 enumeration on
18
+ * Windows. Later questions never re-read it, which is what keeps a poll's cost
19
+ * independent of how many descendants the running command spawned. Windows
20
+ * liveness needs no table at all: wait state is a per-handle question there, so
21
+ * a snapshot asked only for liveness never enumerates.
22
+ *
23
+ * A snapshot answers what the process table showed, which is what batch
24
+ * filtering wants and what signalling must not use: {@link ProcessInspector.isAlive}
25
+ * is the fence a signal takes, because it reads current state instead.
26
+ */
27
+ export interface ProcessSnapshot {
28
+ /** Whether the process-table scan omitted no unreadable rows; absent means unverified. */
29
+ readonly complete?: boolean;
30
+ /**
31
+ * Return the root and its transitive descendants as observed, children first.
32
+ * @param rootPid - tree root to descend from.
33
+ * @returns Observed root and descendants, children before parents.
34
+ */
35
+ tree(rootPid: number): ProcessIdentity[];
36
+ /**
37
+ * Return observed members of one POSIX process session.
38
+ * @param sessionId - POSIX session identifier.
39
+ * @returns Observed session members, empty where the platform's table omits session ids.
40
+ */
41
+ session(sessionId: number): ProcessIdentity[];
42
+ /**
43
+ * Return whether the exact identity was a non-quiescent process.
44
+ * @param identity - PID plus start identity to match.
45
+ * @returns Whether that exact identity — not merely that PID — was running.
46
+ */
47
+ alive(identity: ProcessIdentity): boolean;
48
+ }
49
+ /** Injectable OS process operations used by one local PTY session. */
50
+ export interface ProcessInspector {
51
+ foregroundPgid(shellPid: number): number | undefined;
52
+ /**
53
+ * Report whether the foreground group waits on the terminal shell's stdin.
54
+ *
55
+ * @param pgid Foreground process-group identifier.
56
+ * @param shellPid Persistent terminal shell process identifier.
57
+ * @returns Whether a group member is blocked reading the shell's terminal input.
58
+ */
59
+ isStdinWaiting(pgid: number, shellPid: number): boolean;
60
+ /**
61
+ * Read the process table once and answer tree, session, and liveness from it.
62
+ * @returns A process-table observation whose reads are shared.
63
+ * @throws when the platform process table cannot be enumerated.
64
+ */
65
+ snapshot(): ProcessSnapshot;
66
+ /**
67
+ * Return whether the exact identity is a non-quiescent process right now.
68
+ *
69
+ * Reads the narrowest per-identity source the platform offers rather than a
70
+ * whole table, so a signalling round can re-check every target without
71
+ * paying for a scan. Callers filtering many members at once want
72
+ * {@link ProcessSnapshot.alive} instead.
73
+ *
74
+ * @param identity - PID plus start identity to match.
75
+ * @returns Whether that exact identity — not merely that PID — is running.
76
+ */
77
+ isAlive(identity: ProcessIdentity): boolean;
78
+ signalGroup(pgid: number, signal: SubprocessTerminalSignal): void;
79
+ /**
80
+ * Signal one exact process identity, fenced against PID reuse.
81
+ *
82
+ * The fence reads current state immediately before the signal. An observation
83
+ * taken earlier in the same round cannot stand in for it: the observation
84
+ * preserves the original PID-to-start-time pairing, so a recycled PID would
85
+ * still match and take a signal meant for the process that exited.
86
+ *
87
+ * @param identity - PID plus start identity to signal.
88
+ * @param signal - termination signal to deliver.
89
+ */
90
+ signalProcess(identity: ProcessIdentity, signal: 'SIGTERM' | 'SIGKILL'): void;
91
+ }
92
+ /** Testable boundary around filesystem, process-table, and signal syscalls. */
93
+ export interface ProcessInspectorInternals {
94
+ readFile(path: string): string;
95
+ readDir(path: string): string[];
96
+ readLink(path: string): string;
97
+ stat(path: string): FileStatus;
98
+ open(path: string): number;
99
+ read(fd: number, buffer: Buffer, length: number, position: number): number;
100
+ close(fd: number): void;
101
+ exec(file: string, args: string[]): string;
102
+ kill(pid: number, signal: NodeJS.Signals): void;
103
+ }
104
+ interface ProcStat {
105
+ pid: number;
106
+ parentPid: number;
107
+ pgrp: number;
108
+ session: number;
109
+ state: string;
110
+ ttyDevice: number;
111
+ tpgid: number;
112
+ started: string;
113
+ }
114
+ /**
115
+ * Parse fields used from Linux `/proc/<pid>/stat`, including parenthesized comm text.
116
+ * @param text - complete stat line.
117
+ * @returns Parsed identity/group fields, or undefined for malformed input.
118
+ */
119
+ export declare function parseProcStat(text: string): ProcStat | undefined;
120
+ /**
121
+ * Find an executing member of a Linux process group. `false` means the group
122
+ * contains only zombie/dead entries; `undefined` means the process table could
123
+ * not prove either outcome. A still-executing `knownMember` is returned from
124
+ * its own stat entry without enumerating `/proc`, so repeated polls of a
125
+ * long-lived group cost one file read instead of one per host process.
126
+ * @param processGroupId - POSIX process-group id to inspect.
127
+ * @param knownMember - member PID returned by an earlier call, if any.
128
+ * @param internals - injectable process-table operations.
129
+ * @returns An executing member's PID; `false` when every group entry is
130
+ * zombie/dead; `undefined` when `/proc` is unreadable or lists no group entry.
131
+ */
132
+ export declare function linuxProcessGroupLiveMember(processGroupId: number, knownMember?: number, internals?: ProcessInspectorInternals): number | false | undefined;
133
+ /**
134
+ * Create the supported platform inspector or fail at plugin load.
135
+ * @param platform - target Node platform.
136
+ * @param arch - target CPU architecture for Linux syscall numbers.
137
+ * @param internals - filesystem/process boundary, injectable for deterministic tests.
138
+ * @returns Platform process inspector.
139
+ */
140
+ export declare function createProcessInspector(platform?: NodeJS.Platform, arch?: NodeJS.Architecture, internals?: ProcessInspectorInternals): ProcessInspector;
141
+ export {};
142
+ //# sourceMappingURL=process-inspector.d.ts.map
@@ -0,0 +1,68 @@
1
+ /** Parent-side invocation and bootstrap state for the private native runner. */
2
+ import type { StdioOptions } from 'node:child_process';
3
+ import type { SubprocessSpawnSpec } from '@unieai/rabi-subprocess';
4
+ /** The one private environment variable consumed before target state is restored. */
5
+ export declare const SUBPROCESS_RUNNER_ENV: "RABI_SUBPROCESS_RUNNER";
6
+ /** Sentinel used by the packaged bootstrap for the Windows IPC runner. */
7
+ export declare const WINDOWS_RUNNER_SELECTION: "windows";
8
+ /** Non-empty command tuple used to launch the private runner entry. */
9
+ export type RunnerInvocation = [string, ...string[]];
10
+ /**
11
+ * Resolve the source, built, or packaged entry that calls the same runner core.
12
+ * @returns executable and arguments for the active runtime form.
13
+ */
14
+ export declare function spawnRunnerInvocation(): RunnerInvocation;
15
+ /**
16
+ * Check the concrete runner executable and entry paths without executing a probe mode.
17
+ * @param invocation - resolved executable and runner-entry arguments.
18
+ * @returns whether every concrete executable or entry path is accessible.
19
+ */
20
+ export declare function runnerInvocationAvailable(invocation?: RunnerInvocation): boolean;
21
+ /**
22
+ * Build the bootstrap-safe environment; target overrides arrive through request/IPC.
23
+ * @param selection - private runner selector or Linux launch-request locator.
24
+ * @param invocation - resolved runner invocation whose source form needs the workspace paths map.
25
+ * @returns environment for the runner before target state is restored.
26
+ */
27
+ export declare function runnerEnvironment(selection: string, invocation?: RunnerInvocation): NodeJS.ProcessEnv;
28
+ /**
29
+ * Read and delete the private selector before importing or restoring target state.
30
+ * @param env - mutable environment containing the private selector.
31
+ * @returns the consumed selector, or undefined when no runner was requested.
32
+ */
33
+ export declare function consumeRunnerSelection(env?: NodeJS.ProcessEnv): string | undefined;
34
+ /**
35
+ * Require the private argv delimiter and at least one target argv entry.
36
+ * @param argv - private runner arguments.
37
+ * @returns copied target argv after the private delimiter.
38
+ */
39
+ export declare function parseRunnerTargetArgv(argv: readonly string[]): string[];
40
+ /**
41
+ * Build direct Linux target stdio, or isolated Windows runner stdio with IPC
42
+ * on fd 3 and target carriers on fd 4 through fd 6; optional control uses fd 7.
43
+ * @param spec - ordinary subprocess request whose stdio modes are preserved.
44
+ * @param ipc - whether to isolate the runner and add its private Node IPC descriptor.
45
+ * @param stdinCarrier - runner fd 4 carrier; Windows ignore passes an opened null-device fd.
46
+ * @returns child-process stdio options for the runner.
47
+ */
48
+ export declare function runnerStdio(spec: SubprocessSpawnSpec, ipc: boolean, stdinCarrier?: 'pipe' | number): Exclude<StdioOptions, string>;
49
+ /**
50
+ * Resolve the executable path with libuv/Node Windows spawn search order while
51
+ * preserving the caller's original command-line argv entry separately.
52
+ * @param command - original target argv[0].
53
+ * @param cwd - final target working directory used for relative search roots.
54
+ * @param env - final target environment containing the child PATH.
55
+ * @param exists - injectable non-directory candidate probe used by tests.
56
+ * @param currentEnv - runner environment supplying PATH fallback and cwd-search policy.
57
+ * @returns a resolved application name suitable for `CreateProcessW`, or undefined when no candidate exists.
58
+ */
59
+ export declare function resolveWindowsExecutable(command: string, cwd: string, env: Readonly<Record<string, string>>, exists?: (candidate: string) => boolean, currentEnv?: Readonly<Record<string, string | undefined>>): string | undefined;
60
+ /**
61
+ * Materialize and synchronously validate the final target environment.
62
+ * @param spec - final target argv, cwd, and environment overrides.
63
+ * @returns complete target environment after Node-equivalent validation.
64
+ */
65
+ export declare function targetEnvironment(spec: Pick<SubprocessSpawnSpec, 'argv' | 'cwd' | 'env'> & {
66
+ stdio?: SubprocessSpawnSpec['stdio'];
67
+ }): Record<string, string>;
68
+ //# sourceMappingURL=runner-launch.d.ts.map
@@ -0,0 +1,113 @@
1
+ /** Closed private transports shared by the native subprocess runner. */
2
+ /** Target state restored by the Linux bootstrap after systemd establishes the scope. */
3
+ export interface LinuxLaunchRequest {
4
+ cwd: string;
5
+ env: Record<string, string>;
6
+ /** Only child-owned pipe endpoints may have their shared file status flags changed. */
7
+ pipeFds?: number[];
8
+ control?: 'pipe';
9
+ }
10
+ /** Bounded Node-shaped error fields allowed across a private runner boundary. */
11
+ export interface SerializedRunnerError {
12
+ name: string;
13
+ message: string;
14
+ code?: string;
15
+ syscall?: string;
16
+ path?: string;
17
+ }
18
+ /** A Linux pre-exec failure published beside its consumed request. */
19
+ export type LinuxStartupError = {
20
+ type: 'error';
21
+ error: SerializedRunnerError;
22
+ };
23
+ /** The only parent-to-runner start message on Windows. */
24
+ export interface WindowsStartRequest {
25
+ type: 'start';
26
+ cwd: string;
27
+ env: Record<string, string>;
28
+ control?: 'pipe';
29
+ }
30
+ /** The only parent-to-runner control message on Windows. */
31
+ export interface WindowsTerminateRequest {
32
+ type: 'terminate';
33
+ }
34
+ /** Exactly one direct-result branch is sent by a connected Windows runner. */
35
+ export type WindowsRunnerResult = {
36
+ type: 'target-exit';
37
+ exitCode: number;
38
+ } | {
39
+ type: 'error';
40
+ error: SerializedRunnerError;
41
+ };
42
+ /** Private paths owned by one Linux ordinary or PTY spawn. */
43
+ export interface LinuxLaunchFiles {
44
+ directory: string;
45
+ requestPath: string;
46
+ startupErrorPath: string;
47
+ }
48
+ /**
49
+ * Create a private 0700 directory and one complete 0600 launch request.
50
+ * @param request - target cwd and complete environment for the bootstrap.
51
+ * @returns private paths owned by this launch.
52
+ */
53
+ export declare function createLinuxLaunchFiles(request: LinuxLaunchRequest): LinuxLaunchFiles;
54
+ /**
55
+ * Derive the only permitted startup-error path from an absolute request locator.
56
+ * @param requestPath - absolute path to the private launch-request file.
57
+ * @returns validated sibling paths for this launch.
58
+ */
59
+ export declare function linuxLaunchFilesFromLocator(requestPath: string): LinuxLaunchFiles;
60
+ /**
61
+ * Strictly read and remove a one-shot Linux launch request.
62
+ * @param requestPath - private launch-request path to consume.
63
+ * @returns validated target cwd and environment.
64
+ */
65
+ export declare function consumeLinuxLaunchRequest(requestPath: string): LinuxLaunchRequest;
66
+ /**
67
+ * Publish one strict 0600 Linux pre-exec error.
68
+ * @param files - private paths for this launch.
69
+ * @param error - bounded spawn or runner failure to publish.
70
+ */
71
+ export declare function writeLinuxStartupError(files: LinuxLaunchFiles, error: LinuxStartupError): void;
72
+ /**
73
+ * Read the Linux pre-exec error, if the bootstrap published one.
74
+ * @param path - expected startup-error path.
75
+ * @returns the validated failure, or undefined when none was published.
76
+ */
77
+ export declare function readLinuxStartupError(path: string): LinuxStartupError | undefined;
78
+ /**
79
+ * Strictly parse the single Windows start message.
80
+ * @param value - untrusted IPC payload.
81
+ * @returns validated target start request.
82
+ */
83
+ export declare function parseWindowsStartRequest(value: unknown): WindowsStartRequest;
84
+ /**
85
+ * Return true only for the exact, payload-free Windows terminate control.
86
+ * @param value - untrusted IPC payload.
87
+ * @returns whether the payload is the exact terminate request.
88
+ */
89
+ export declare function isWindowsTerminateRequest(value: unknown): value is WindowsTerminateRequest;
90
+ /**
91
+ * Strictly parse one of the two Windows direct-result branches.
92
+ * @param value - untrusted IPC payload.
93
+ * @returns validated direct-result message.
94
+ */
95
+ export declare function parseWindowsRunnerResult(value: unknown): WindowsRunnerResult;
96
+ /**
97
+ * Convert an unknown failure into the bounded cross-process error record.
98
+ * @param error - failure caught at the process boundary.
99
+ * @returns bounded serializable error fields.
100
+ */
101
+ export declare function serializeRunnerError(error: unknown): SerializedRunnerError;
102
+ /**
103
+ * Rebuild a Node-shaped Error from a strict runner record.
104
+ * @param serialized - validated bounded error fields.
105
+ * @returns reconstructed Error with supported Node fields.
106
+ */
107
+ export declare function deserializeRunnerError(serialized: SerializedRunnerError): Error;
108
+ /**
109
+ * Best-effort removal of only the private paths created for this Linux spawn.
110
+ * @param files - exact private paths owned by this launch.
111
+ */
112
+ export declare function cleanupLinuxLaunchFiles(files: LinuxLaunchFiles): void;
113
+ //# sourceMappingURL=runner-protocol.d.ts.map
@@ -0,0 +1,37 @@
1
+ import type { SubprocessTerminalActivity, SubprocessTerminalSpawnSpec } from '@unieai/rabi-subprocess';
2
+ /** Opt-in startup integration and revision tracking for one ordinary interactive shell. */
3
+ export declare class ShellActivity {
4
+ private readonly directory;
5
+ readonly argv: readonly string[];
6
+ readonly env: Record<string, string>;
7
+ private revision;
8
+ private observed;
9
+ private invalidated;
10
+ private state;
11
+ /**
12
+ * @param directory - private startup and status file directory.
13
+ * @param argv - shell launch preserving supported user startup files.
14
+ * @param env - environment with any temporary startup redirect.
15
+ */
16
+ constructor(directory: string, argv: readonly string[], env: Record<string, string>);
17
+ /** Invalidate prompt evidence before delivering input or a foreground signal. */
18
+ invalidate(): void;
19
+ /**
20
+ * Read the latest top-level shell transition, fenced against input since that transition.
21
+ * @param pid - original shell process id.
22
+ * @returns lifecycle evidence; process ownership must be checked separately.
23
+ */
24
+ inspect(pid: number): SubprocessTerminalActivity;
25
+ /** Remove private startup and status files after process quiescence. */
26
+ dispose(): void;
27
+ private read;
28
+ }
29
+ /**
30
+ * Prepare optional Bash or Zsh integration for a plain, non-login interactive launch.
31
+ * @param spec - terminal request; custom arguments and wrapped executables remain unmodified.
32
+ * @param env - scrubbed target environment.
33
+ * @param platform - execution platform.
34
+ * @returns private integration, or undefined for unsupported launches.
35
+ */
36
+ export declare function prepareShellActivity(spec: SubprocessTerminalSpawnSpec, env: Record<string, string>, platform: NodeJS.Platform): ShellActivity | undefined;
37
+ //# sourceMappingURL=shell-activity.d.ts.map