@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.
- package/LICENSE +21 -0
- package/README.md +7 -2
- package/lib/index.js +1706 -0
- package/lib/output.js +239 -0
- package/lib/runner-launch-CKTiL8M8.js +1556 -0
- package/lib/runner.js +432 -0
- package/lib/types/bin.d.ts +7 -0
- package/lib/types/control-spawn.d.ts +19 -0
- package/lib/types/index.d.ts +59 -0
- package/lib/types/linux-execve.d.ts +9 -0
- package/lib/types/linux-scope-selector.d.ts +60 -0
- package/lib/types/linux-scope.d.ts +124 -0
- package/lib/types/managed-owner.d.ts +36 -0
- package/lib/types/output.d.ts +137 -0
- package/lib/types/process-inspector.d.ts +142 -0
- package/lib/types/runner-launch.d.ts +68 -0
- package/lib/types/runner-protocol.d.ts +113 -0
- package/lib/types/shell-activity.d.ts +37 -0
- package/lib/types/spawn-runner.d.ts +37 -0
- package/lib/types/spawn.d.ts +86 -0
- package/lib/types/terminal.d.ts +80 -0
- package/lib/types/windows-inspector.d.ts +79 -0
- package/lib/types/windows-job.d.ts +30 -0
- package/locale/de.json +6 -0
- package/locale/en.json +5 -0
- package/locale/es.json +6 -0
- package/locale/fr.json +6 -0
- package/locale/ja.json +6 -0
- package/locale/pt.json +6 -0
- package/locale/ru.json +6 -0
- package/locale/zh.json +6 -0
- package/package.json +54 -4
- package/scripts/ensure-spawn-helper.mjs +16 -0
- package/src/bin.ts +25 -0
- package/src/control-spawn.ts +35 -0
- package/src/index.ts +387 -0
- package/src/linux-execve.ts +92 -0
- package/src/linux-scope-selector.ts +101 -0
- package/src/linux-scope.ts +726 -0
- package/src/managed-owner.ts +56 -0
- package/src/output.ts +313 -0
- package/src/process-inspector.ts +560 -0
- package/src/runner-launch.ts +315 -0
- package/src/runner-protocol.ts +281 -0
- package/src/shell-activity.ts +131 -0
- package/src/spawn-runner.ts +488 -0
- package/src/spawn.ts +500 -0
- package/src/terminal.ts +479 -0
- package/src/windows-inspector.ts +346 -0
- package/src/windows-job.ts +269 -0
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/** One-shot Linux exec bootstrap and Windows Job-owning subprocess runner. */
|
|
2
|
+
import { closeHandleChecked, isJobEmpty, pollProcessExit, spawnCurrentTokenJobProcess, terminateJob } from '@unieai/rabi-win32-process';
|
|
3
|
+
import type { CurrentTokenProcessBindings } from '@unieai/rabi-win32-process';
|
|
4
|
+
import { loadLinuxExecve } from './linux-execve.ts';
|
|
5
|
+
import { resolveWindowsExecutable } from './runner-launch.ts';
|
|
6
|
+
type RunnerHost = Pick<NodeJS.Process, 'env' | 'exitCode' | 'connected' | 'cwd' | 'chdir' | 'on' | 'off' | 'once' | 'disconnect'> & {
|
|
7
|
+
send?: NodeJS.Process['send'];
|
|
8
|
+
};
|
|
9
|
+
/** Injectable operations used by the protocol-owner tests. */
|
|
10
|
+
export interface SpawnRunnerInternals {
|
|
11
|
+
execve: ReturnType<typeof loadLinuxExecve>;
|
|
12
|
+
loadWin32ProcessBindings(): CurrentTokenProcessBindings;
|
|
13
|
+
spawnCurrentTokenJobProcess: typeof spawnCurrentTokenJobProcess;
|
|
14
|
+
closeFileDescriptor(fileDescriptor: number): void;
|
|
15
|
+
resolveWindowsExecutable: typeof resolveWindowsExecutable;
|
|
16
|
+
pollProcessExit: typeof pollProcessExit;
|
|
17
|
+
isJobEmpty: typeof isJobEmpty;
|
|
18
|
+
terminateJob: typeof terminateJob;
|
|
19
|
+
closeHandleChecked: typeof closeHandleChecked;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Execute the selected Linux bootstrap or Windows Job runner.
|
|
23
|
+
* @param selection - Windows sentinel or Linux launch-request locator.
|
|
24
|
+
* @param argv - private runner arguments beginning with the target delimiter.
|
|
25
|
+
* @param host - process transport and lifecycle host.
|
|
26
|
+
* @param internals - native and filesystem operations used by the runner.
|
|
27
|
+
*/
|
|
28
|
+
export declare function runSpawnRunner(selection: string, argv: readonly string[], host?: RunnerHost, internals?: SpawnRunnerInternals): Promise<void>;
|
|
29
|
+
/**
|
|
30
|
+
* Best-effort reporting for failures before the selected runner established its owner.
|
|
31
|
+
* @param selection - Windows sentinel, Linux launch-request locator, or no selection.
|
|
32
|
+
* @param error - failure raised before normal runner settlement.
|
|
33
|
+
* @param host - process transport and lifecycle host.
|
|
34
|
+
*/
|
|
35
|
+
export declare function reportSpawnRunnerFailure(selection: string | undefined, error: unknown, host?: RunnerHost): Promise<void>;
|
|
36
|
+
export {};
|
|
37
|
+
//# sourceMappingURL=spawn-runner.d.ts.map
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Process plumbing for the local subprocess service: ordinary process launch
|
|
3
|
+
* with per-stream stdio dispositions, tail-keep collection with spill
|
|
4
|
+
* files, provider-owned range signalling, and common termination scheduling.
|
|
5
|
+
* POSIX owners stage TERM before KILL; Windows owners terminate immediately.
|
|
6
|
+
* This layer reacts to an abort signal; callers own deadlines, teardown
|
|
7
|
+
* ladders, and cause classification.
|
|
8
|
+
* @module rabi-subprocess-local/spawn
|
|
9
|
+
*/
|
|
10
|
+
import { type ChildProcess, type SpawnOptions } from 'node:child_process';
|
|
11
|
+
import type { SubprocessHandle, SubprocessSpawnSpec } from '@unieai/rabi-subprocess';
|
|
12
|
+
import type { ManagedProcessLaunch } from './managed-owner.ts';
|
|
13
|
+
import { type SpillFailureReporter } from './output.ts';
|
|
14
|
+
type SpawnProcess = (program: string, args: readonly string[], options: SpawnOptions) => ChildProcess;
|
|
15
|
+
/**
|
|
16
|
+
* Build a child environment: explicit caller entries override the scrubbed
|
|
17
|
+
* parent base using the target platform's environment-key semantics. A string
|
|
18
|
+
* deliberately restores or overrides an entry; an explicit `undefined`
|
|
19
|
+
* tombstone removes an ordinary ambient entry.
|
|
20
|
+
* @param extra - explicit caller entries and tombstones, merged after the scrub.
|
|
21
|
+
* @returns the environment to hand to `spawn` for the child process.
|
|
22
|
+
*/
|
|
23
|
+
export declare function childEnv(extra?: Readonly<NodeJS.ProcessEnv>): NodeJS.ProcessEnv;
|
|
24
|
+
/** Injectable process, spill, and platform operations. */
|
|
25
|
+
export interface SpawnInternals {
|
|
26
|
+
/** Process spawner (defaults to `node:child_process` `spawn`). */
|
|
27
|
+
spawn?: SpawnProcess;
|
|
28
|
+
/** Directory for spill files (defaults to the OS temp dir). */
|
|
29
|
+
spillDir?: string;
|
|
30
|
+
/** Receives spill open/write failures; the runtime supplies its plugin logger, bare callers get a stderr line. */
|
|
31
|
+
onSpillFailure?: SpillFailureReporter;
|
|
32
|
+
/** Windows tree-termination runner (defaults to `taskkill /PID <pid> /T /F`). */
|
|
33
|
+
taskkill?: (pid: number) => void;
|
|
34
|
+
/** Host platform override for signalling decisions. */
|
|
35
|
+
platform?: NodeJS.Platform;
|
|
36
|
+
/** Linux process-group live-member probe (defaults to `/proc` inspection); receives the member PID it last returned. */
|
|
37
|
+
linuxProcessGroupLiveMember?: (processGroupId: number, knownMember: number | undefined) => number | false | undefined;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Local-only synchronous final termination used by the owning service during
|
|
41
|
+
* host exit and as the last fallback after failed normal disposal. It is
|
|
42
|
+
* intentionally absent from the public subprocess seam.
|
|
43
|
+
*/
|
|
44
|
+
export interface LocalSubprocessHandle extends SubprocessHandle {
|
|
45
|
+
/** Force-terminate the current tree synchronously without starting timers or waits. */
|
|
46
|
+
terminateForHostExit(): void;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Send `sig` to a detached POSIX process group. Never throws: delivery races
|
|
50
|
+
* process exit and may run in a timer callback, so failures are contained and
|
|
51
|
+
* a missing pid is a no-op.
|
|
52
|
+
* @param pid - the group leader's pid, when the spawn published one.
|
|
53
|
+
* @param sig - the signal to deliver to the whole group.
|
|
54
|
+
*/
|
|
55
|
+
export declare function killGroup(pid: number | undefined, sig: NodeJS.Signals): void;
|
|
56
|
+
/**
|
|
57
|
+
* Terminate one Windows process tree with `taskkill /T /F`. Contained like
|
|
58
|
+
* POSIX group signalling — delivery races tree exit, so an absent tree, a
|
|
59
|
+
* nonzero status, or a missing taskkill binary must not break idempotent
|
|
60
|
+
* teardown.
|
|
61
|
+
* @param pid - root process id, when the spawn published one.
|
|
62
|
+
*/
|
|
63
|
+
export declare function taskkillProcessTree(pid: number | undefined): void;
|
|
64
|
+
/**
|
|
65
|
+
* Validate the synchronous portion of one ordinary spawn request.
|
|
66
|
+
* @param spec - exact target request.
|
|
67
|
+
* @throws when grace, cancellation, or argv is invalid before launch.
|
|
68
|
+
*/
|
|
69
|
+
export declare function validateSubprocessSpec(spec: SubprocessSpawnSpec): void;
|
|
70
|
+
/**
|
|
71
|
+
* Bind platform launch facts to the existing stdio, outcome, abort, and termination lifecycle.
|
|
72
|
+
* @param spec - fully resolved argv, cwd, stdio, grace, cancellation, environment.
|
|
73
|
+
* @param launch - platform streams, direct outcome, and managed-range owner.
|
|
74
|
+
* @param internals - spill-directory override and spill failure reporter.
|
|
75
|
+
* @returns live subprocess handle.
|
|
76
|
+
*/
|
|
77
|
+
export declare function bindManagedProcess(spec: SubprocessSpawnSpec, launch: ManagedProcessLaunch, internals?: Pick<SpawnInternals, 'spillDir' | 'onSpillFailure'>): LocalSubprocessHandle;
|
|
78
|
+
/**
|
|
79
|
+
* Spawn one detached PGID/taskkill fallback and bind the common lifecycle.
|
|
80
|
+
* @param spec - fully resolved argv, cwd, stdio, grace, cancellation, environment.
|
|
81
|
+
* @param internals - test-only spill-directory, platform, and taskkill overrides.
|
|
82
|
+
* @returns live subprocess handle.
|
|
83
|
+
*/
|
|
84
|
+
export declare function spawnSubprocess(spec: SubprocessSpawnSpec, internals?: SpawnInternals): LocalSubprocessHandle;
|
|
85
|
+
export {};
|
|
86
|
+
//# sourceMappingURL=spawn.d.ts.map
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/** Local node-pty terminal-process implementation for the subprocess seam. */
|
|
2
|
+
import { PassThrough } from 'node:stream';
|
|
3
|
+
import type { IPty } from 'node-pty';
|
|
4
|
+
import type { SubprocessOutcome, SubprocessTerminalActivity, SubprocessTerminalForeground, SubprocessTerminalHandle, SubprocessTerminalSignal } from '@unieai/rabi-subprocess';
|
|
5
|
+
import type { BoundProcessOwner } from './managed-owner.ts';
|
|
6
|
+
import type { ProcessInspector } from './process-inspector.ts';
|
|
7
|
+
import type { ShellActivity } from './shell-activity.ts';
|
|
8
|
+
/**
|
|
9
|
+
* A local terminal whose native managed range or fallback process-session
|
|
10
|
+
* ownership stays below the PTY backend.
|
|
11
|
+
* The seam's terminate() promise — no write, inspection, or signal in flight
|
|
12
|
+
* after settlement — holds here without operation tracking only because every
|
|
13
|
+
* handle call completes synchronously under the hood (node-pty write, ps-based
|
|
14
|
+
* inspection). A first genuinely asynchronous step in any handle call must add
|
|
15
|
+
* the tracking a remote provider needs.
|
|
16
|
+
*/
|
|
17
|
+
export declare class LocalTerminalHandle implements SubprocessTerminalHandle {
|
|
18
|
+
private readonly terminal;
|
|
19
|
+
private readonly inspector;
|
|
20
|
+
private readonly graceMs;
|
|
21
|
+
private readonly platform;
|
|
22
|
+
private readonly managedOwner?;
|
|
23
|
+
private readonly resolveManagedOutcome?;
|
|
24
|
+
private readonly shellActivity?;
|
|
25
|
+
private readonly onQuiescence?;
|
|
26
|
+
private readonly observeShellExit;
|
|
27
|
+
readonly pid: number;
|
|
28
|
+
readonly output: PassThrough;
|
|
29
|
+
readonly done: Promise<SubprocessOutcome>;
|
|
30
|
+
private readonly outcome;
|
|
31
|
+
private readonly dataDisposable;
|
|
32
|
+
private readonly exitDisposable;
|
|
33
|
+
private cleanup;
|
|
34
|
+
private managedOwnerCleaned;
|
|
35
|
+
private exited;
|
|
36
|
+
private outputPaused;
|
|
37
|
+
private trackedDescendants;
|
|
38
|
+
private activityRevision;
|
|
39
|
+
private activityKey;
|
|
40
|
+
private quiescent;
|
|
41
|
+
private managedRangeEmpty;
|
|
42
|
+
/** The spawned shell's start identity; scans stop adopting members once the root pid no longer carries it. */
|
|
43
|
+
private readonly rootIdentity;
|
|
44
|
+
/**
|
|
45
|
+
* @param terminal - allocated node-pty process.
|
|
46
|
+
* @param inspector - platform process/session operations.
|
|
47
|
+
* @param graceMs - TERM-to-KILL and exit-wait grace.
|
|
48
|
+
* @param platform - host platform; defaults to the running platform, injectable for deterministic tests.
|
|
49
|
+
*/
|
|
50
|
+
constructor(terminal: IPty, inspector: ProcessInspector, graceMs: number, platform?: NodeJS.Platform, managedOwner?: BoundProcessOwner | undefined, resolveManagedOutcome?: ((outcome: SubprocessOutcome) => SubprocessOutcome) | undefined, shellActivity?: Pick<ShellActivity, "inspect" | "invalidate" | "dispose"> | undefined, onQuiescence?: (() => void) | undefined, observeShellExit?: boolean);
|
|
51
|
+
/** Whether node-pty has not yet published the top-level exit event. */
|
|
52
|
+
get running(): boolean;
|
|
53
|
+
write(data: string): Promise<void>;
|
|
54
|
+
resize(cols: number, rows: number): Promise<void>;
|
|
55
|
+
inspectForeground(): Promise<SubprocessTerminalForeground | undefined>;
|
|
56
|
+
inspectActivity(): Promise<SubprocessTerminalActivity>;
|
|
57
|
+
signalForeground(signal: SubprocessTerminalSignal): Promise<number>;
|
|
58
|
+
terminate(): Promise<void>;
|
|
59
|
+
/**
|
|
60
|
+
* Force-terminate the observable session synchronously during Node's exit
|
|
61
|
+
* event. This does not claim quiescence and does not replace terminate().
|
|
62
|
+
*/
|
|
63
|
+
terminateForHostExit(): void;
|
|
64
|
+
private forceStopShell;
|
|
65
|
+
private survivors;
|
|
66
|
+
private descendants;
|
|
67
|
+
private waitForMembers;
|
|
68
|
+
private signalMembers;
|
|
69
|
+
private forceStopDescendants;
|
|
70
|
+
private unionMembers;
|
|
71
|
+
private stopDescendants;
|
|
72
|
+
private stopShell;
|
|
73
|
+
private stopShellWindows;
|
|
74
|
+
private waitForWindowsShellExit;
|
|
75
|
+
private closeOnce;
|
|
76
|
+
private cleanupManagedOwner;
|
|
77
|
+
private closeManagedRange;
|
|
78
|
+
private settleExitIfGone;
|
|
79
|
+
}
|
|
80
|
+
//# sourceMappingURL=terminal.d.ts.map
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Windows process-table operations for terminal readiness, signalling, and
|
|
3
|
+
* teardown: Toolhelp32 snapshot enumeration with GetProcessTimes creation-time
|
|
4
|
+
* identity and process-handle wait-state liveness, the shell pid as a pseudo
|
|
5
|
+
* process group (Windows has no POSIX groups), and taskkill tree signalling.
|
|
6
|
+
* The koffi bindings load lazily so
|
|
7
|
+
* non-Windows processes never touch Win32 libraries; all decision logic takes
|
|
8
|
+
* an injectable internals boundary so suites can pin it on any host.
|
|
9
|
+
* @module rabi-subprocess-local/windows-inspector
|
|
10
|
+
*/
|
|
11
|
+
import type { SubprocessTerminalSignal } from '@unieai/rabi-subprocess';
|
|
12
|
+
import type { ProcessIdentity, ProcessInspector, ProcessSnapshot } from './process-inspector.ts';
|
|
13
|
+
/** One Toolhelp32 process-table row. */
|
|
14
|
+
export interface ProcessEntry {
|
|
15
|
+
pid: number;
|
|
16
|
+
parentPid: number;
|
|
17
|
+
}
|
|
18
|
+
/** Creation identity plus the process object's current wait state. */
|
|
19
|
+
export interface WindowsProcessState {
|
|
20
|
+
/** GetProcessTimes creation identity used to fence PID reuse. */
|
|
21
|
+
started: string;
|
|
22
|
+
/** Whether a zero-time process-handle wait reports the process still running. */
|
|
23
|
+
active: boolean;
|
|
24
|
+
}
|
|
25
|
+
/** Injectable Windows process operations used by one local PTY session. */
|
|
26
|
+
export interface WindowsProcessInspectorInternals {
|
|
27
|
+
/** Enumerate the current process table (pid/parent pairs). */
|
|
28
|
+
snapshot(): ProcessEntry[];
|
|
29
|
+
/** Return one process's creation identity and wait state, or undefined when unreadable. */
|
|
30
|
+
processState(pid: number): WindowsProcessState | undefined;
|
|
31
|
+
/** Terminate one process tree; `force` maps to taskkill `/F`. */
|
|
32
|
+
taskkill(pid: number, force: boolean): void;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Walk a process table from one root in children-first order, retaining only
|
|
36
|
+
* members whose start identity is readable (unreadable members are detector
|
|
37
|
+
* misses, exactly like an unreadable `/proc` entry on Linux).
|
|
38
|
+
* @param entries - the process table snapshot.
|
|
39
|
+
* @param rootPid - the tree root to descend from.
|
|
40
|
+
* @param started - creation-time identity resolver for one member.
|
|
41
|
+
* @returns the root and its current transitive descendants, children first.
|
|
42
|
+
*/
|
|
43
|
+
export declare function windowsProcessTree(entries: ProcessEntry[], rootPid: number, started: (pid: number) => string | undefined): ProcessIdentity[];
|
|
44
|
+
/**
|
|
45
|
+
* Windows {@link ProcessInspector}. The shell pid stands in for a foreground
|
|
46
|
+
* process group: it is a stable pseudo-group that lets the prompt-marker
|
|
47
|
+
* readiness path compare foreground identities, while every actual signal
|
|
48
|
+
* targets the console-wide tree through taskkill (SIGINT is delivered by the
|
|
49
|
+
* terminal handle as a `\x03` input write and never reaches this layer).
|
|
50
|
+
*/
|
|
51
|
+
export declare class WindowsProcessInspector implements ProcessInspector {
|
|
52
|
+
private readonly internals;
|
|
53
|
+
constructor(internals?: WindowsProcessInspectorInternals);
|
|
54
|
+
foregroundPgid(shellPid: number): number;
|
|
55
|
+
isStdinWaiting(_pgid: number, _shellPid: number): boolean;
|
|
56
|
+
isAlive(identity: ProcessIdentity): boolean;
|
|
57
|
+
snapshot(): ProcessSnapshot;
|
|
58
|
+
signalGroup(pgid: number, signal: SubprocessTerminalSignal): void;
|
|
59
|
+
signalProcess(identity: ProcessIdentity, signal: 'SIGTERM' | 'SIGKILL'): void;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Create the Windows process inspector.
|
|
63
|
+
* @param internals - injectable process operations; defaults to the koffi-backed table.
|
|
64
|
+
* @returns the Windows inspector.
|
|
65
|
+
*/
|
|
66
|
+
export declare function createWindowsProcessInspector(internals?: WindowsProcessInspectorInternals): WindowsProcessInspector;
|
|
67
|
+
declare const nativePtr: unique symbol;
|
|
68
|
+
/** Koffi 3 native pointer (a BigInt address), branded so it cannot silently enter numeric contexts. */
|
|
69
|
+
export type NativePtr = bigint & {
|
|
70
|
+
readonly [nativePtr]: true;
|
|
71
|
+
};
|
|
72
|
+
/**
|
|
73
|
+
* True for NULL and INVALID_HANDLE_VALUE returns from Win32 handle APIs.
|
|
74
|
+
* @param value - a handle as koffi may hand it back (pointer, null, or 0n).
|
|
75
|
+
* @returns whether the value signals an invalid handle.
|
|
76
|
+
*/
|
|
77
|
+
export declare function isInvalidHandle(value: NativePtr | null | undefined): boolean;
|
|
78
|
+
export {};
|
|
79
|
+
//# sourceMappingURL=windows-inspector.d.ts.map
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/** Windows parent-side launch and ownership for the private Job runner. */
|
|
2
|
+
import { spawn } from 'node:child_process';
|
|
3
|
+
import type { SubprocessSpawnSpec } from '@unieai/rabi-subprocess';
|
|
4
|
+
import { loadWin32ProcessBindings, probeCurrentTokenJobSupport } from '@unieai/rabi-win32-process';
|
|
5
|
+
import type { ManagedProcessLaunch } from './managed-owner.ts';
|
|
6
|
+
import type { RunnerInvocation } from './runner-launch.ts';
|
|
7
|
+
/** Test seams for runner launch and dynamic capability checks. */
|
|
8
|
+
export interface WindowsJobInternals {
|
|
9
|
+
spawn?: typeof spawn;
|
|
10
|
+
runnerInvocation?: RunnerInvocation;
|
|
11
|
+
resolveRunnerInvocation?: () => RunnerInvocation;
|
|
12
|
+
runnerAvailable?: (invocation: RunnerInvocation) => boolean;
|
|
13
|
+
loadWin32ProcessBindings?: typeof loadWin32ProcessBindings;
|
|
14
|
+
probeCurrentTokenJobSupport?: typeof probeCurrentTokenJobSupport;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Re-check the runner entry, bindings, and current Job capability for every spawn.
|
|
18
|
+
* @param internals - optional runner and Win32 capability seams used by tests.
|
|
19
|
+
* @returns whether the Windows native containment path is currently available.
|
|
20
|
+
*/
|
|
21
|
+
export declare function probeWindowsJob(internals?: WindowsJobInternals): boolean;
|
|
22
|
+
/**
|
|
23
|
+
* Launch one target through a runner that uniquely owns its Job handle.
|
|
24
|
+
* @param spec - ordinary target request.
|
|
25
|
+
* @param targetEnv - validated complete target environment.
|
|
26
|
+
* @param internals - optional runner launch seams used by tests.
|
|
27
|
+
* @returns direct streams, result, and runner-owned managed range.
|
|
28
|
+
*/
|
|
29
|
+
export declare function launchWindowsJob(spec: SubprocessSpawnSpec, targetEnv: Record<string, string>, internals?: WindowsJobInternals): ManagedProcessLaunch;
|
|
30
|
+
//# sourceMappingURL=windows-job.d.ts.map
|
package/locale/de.json
ADDED
package/locale/en.json
ADDED
package/locale/es.json
ADDED
package/locale/fr.json
ADDED
package/locale/ja.json
ADDED
package/locale/pt.json
ADDED
package/locale/ru.json
ADDED
package/locale/zh.json
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,56 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unieai/rabi-subprocess-local",
|
|
3
|
-
"
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"description": "Local-subprocess implementation of the Rabi Harness subprocess seam",
|
|
4
|
+
"version": "0.2.2-rc.5",
|
|
5
|
+
"publishConfig": {
|
|
6
|
+
"access": "public"
|
|
7
|
+
},
|
|
8
|
+
"type": "module",
|
|
9
|
+
"main": "lib/index.js",
|
|
10
|
+
"types": "lib/types/index.d.ts",
|
|
11
|
+
"exports": {
|
|
12
|
+
".": {
|
|
13
|
+
"types": "./lib/types/index.d.ts",
|
|
14
|
+
"default": "./lib/index.js"
|
|
15
|
+
},
|
|
16
|
+
"./runner": {
|
|
17
|
+
"types": "./lib/types/bin.d.ts",
|
|
18
|
+
"default": "./lib/runner.js"
|
|
19
|
+
},
|
|
20
|
+
"./src/*": "./src/*",
|
|
21
|
+
"./package.json": "./package.json",
|
|
22
|
+
"./output": {
|
|
23
|
+
"types": "./lib/types/output.d.ts",
|
|
24
|
+
"default": "./lib/output.js"
|
|
25
|
+
},
|
|
26
|
+
"./locale/*.json": "./locale/*.json"
|
|
27
|
+
},
|
|
28
|
+
"files": [
|
|
29
|
+
"locale/*.json",
|
|
30
|
+
"lib/index.js",
|
|
31
|
+
"lib/runner.js",
|
|
32
|
+
"lib/runner-*.js",
|
|
33
|
+
"lib/output.js",
|
|
34
|
+
"scripts/ensure-spawn-helper.mjs",
|
|
35
|
+
"lib/types/**/*.d.ts",
|
|
36
|
+
"lib/types/**/*.d.ts.map",
|
|
37
|
+
"lib/**/*.js.map",
|
|
38
|
+
"src",
|
|
39
|
+
"README.md"
|
|
40
|
+
],
|
|
41
|
+
"license": "MIT",
|
|
42
|
+
"peerDependencies": {
|
|
43
|
+
"@unieai/rabi-subprocess": "0.2.2-rc.5",
|
|
44
|
+
"@unieai/rabi-timeout": "0.2.2-rc.5",
|
|
45
|
+
"@unieai/cordis": "4.1.0"
|
|
46
|
+
},
|
|
47
|
+
"dependencies": {
|
|
48
|
+
"@unieai/rabi-lazy-require": "0.2.2-rc.5",
|
|
49
|
+
"@unieai/rabi-win32-process": "0.2.2-rc.5",
|
|
50
|
+
"koffi": "3.1.1",
|
|
51
|
+
"node-pty": "1.2.0-beta.15"
|
|
52
|
+
},
|
|
53
|
+
"scripts": {
|
|
54
|
+
"postinstall": "node scripts/ensure-spawn-helper.mjs"
|
|
55
|
+
}
|
|
56
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/** Restore the executable bit stripped from node-pty's prebuilt helper. */
|
|
2
|
+
|
|
3
|
+
import { chmodSync, existsSync } from 'node:fs'
|
|
4
|
+
import { dirname, join } from 'node:path'
|
|
5
|
+
import { fileURLToPath } from 'node:url'
|
|
6
|
+
|
|
7
|
+
const entry = fileURLToPath(import.meta.resolve('node-pty'))
|
|
8
|
+
const packageRoot = dirname(dirname(entry))
|
|
9
|
+
const candidates = [
|
|
10
|
+
join(packageRoot, 'prebuilds', `${process.platform}-${process.arch}`, 'spawn-helper'),
|
|
11
|
+
join(packageRoot, 'build', 'Release', 'spawn-helper'),
|
|
12
|
+
]
|
|
13
|
+
|
|
14
|
+
for (const helper of candidates) {
|
|
15
|
+
if (existsSync(helper)) chmodSync(helper, 0o755)
|
|
16
|
+
}
|
package/src/bin.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/** Thin executable/importable entry for the provider-private runner core. */
|
|
2
|
+
|
|
3
|
+
import { consumeRunnerSelection } from './runner-launch.ts'
|
|
4
|
+
import { reportSpawnRunnerFailure, runSpawnRunner } from './spawn-runner.ts'
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Run a selector already removed by a packaging bootstrap.
|
|
8
|
+
* @param selection - private runner selector or Linux launch-request locator.
|
|
9
|
+
*/
|
|
10
|
+
export async function runSelectedSubprocessRunner(selection: string): Promise<void> {
|
|
11
|
+
try {
|
|
12
|
+
await runSpawnRunner(selection, process.argv.slice(2))
|
|
13
|
+
} catch (error) {
|
|
14
|
+
await reportSpawnRunnerFailure(selection, error)
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
if (import.meta.main) {
|
|
19
|
+
const selection = consumeRunnerSelection()
|
|
20
|
+
if (selection === undefined) {
|
|
21
|
+
process.exitCode = 127
|
|
22
|
+
} else {
|
|
23
|
+
void runSelectedSubprocessRunner(selection)
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/** Parent-side setup for one explicitly requested inherited control pipe. */
|
|
2
|
+
|
|
3
|
+
import { SUBPROCESS_CONTROL_ENV, SUBPROCESS_CONTROL_FD } from '@unieai/rabi-subprocess/control'
|
|
4
|
+
import type { Duplex, Readable, Writable } from 'node:stream'
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Read the optional extra pipe from Node's stdio tuple.
|
|
8
|
+
* @param child - child whose requested extra pipe was allocated by Node.
|
|
9
|
+
* @param control - requested transport, or undefined when absent.
|
|
10
|
+
* @returns the parent duplex endpoint, absent when not requested or native startup failed.
|
|
11
|
+
*/
|
|
12
|
+
export function controlPipe(
|
|
13
|
+
child: { readonly stdio: ReadonlyArray<Readable | Writable | null | undefined> },
|
|
14
|
+
control?: 'pipe',
|
|
15
|
+
): Duplex | undefined {
|
|
16
|
+
// Node's type declaration names only the first five descriptor slots.
|
|
17
|
+
const streams: ReadonlyArray<Readable | Writable | null | undefined> = child.stdio
|
|
18
|
+
return control === 'pipe' ? streams[SUBPROCESS_CONTROL_FD] as Duplex | undefined : undefined
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Stamp the private marker on a fresh child environment after rejecting a caller override.
|
|
23
|
+
* @param env - newly materialized child environment, owned by the caller.
|
|
24
|
+
* @param control - requested control transport, or undefined when absent.
|
|
25
|
+
* @returns the same environment with the provider-owned launch marker when requested.
|
|
26
|
+
*/
|
|
27
|
+
export function controlEnvironment<T extends NodeJS.ProcessEnv>(env: T, control?: 'pipe'): T {
|
|
28
|
+
for (const [key, value] of Object.entries(env)) {
|
|
29
|
+
if (key.toUpperCase() === SUBPROCESS_CONTROL_ENV && value !== undefined) {
|
|
30
|
+
throw new Error(`${SUBPROCESS_CONTROL_ENV} is reserved for subprocess control-channel setup`)
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
if (control === 'pipe') Object.assign(env, { [SUBPROCESS_CONTROL_ENV]: 'pipe' })
|
|
34
|
+
return env
|
|
35
|
+
}
|