@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
package/lib/runner.js
ADDED
|
@@ -0,0 +1,432 @@
|
|
|
1
|
+
import { S as loadLinuxExecve, a as resolveWindowsExecutable, b as serializeRunnerError, f as consumeLinuxLaunchRequest, g as linuxLaunchFilesFromLocator, h as isWindowsTerminateRequest, i as parseRunnerTargetArgv, r as consumeRunnerSelection, t as SUBPROCESS_RUNNER_ENV, v as parseWindowsStartRequest, x as writeLinuxStartupError } from "./runner-launch-CKTiL8M8.js";
|
|
2
|
+
import { closeSync } from "node:fs";
|
|
3
|
+
import { SUBPROCESS_CONTROL_FD } from "@unieai/rabi-subprocess/control";
|
|
4
|
+
import { Win32Error, closeHandleChecked, isJobEmpty, loadWin32ProcessBindings, pollProcessExit, spawnCurrentTokenJobProcess, terminateJob } from "@unieai/rabi-win32-process";
|
|
5
|
+
//#region lib/types/spawn-runner.js
|
|
6
|
+
/** One-shot Linux exec bootstrap and Windows Job-owning subprocess runner. */
|
|
7
|
+
const defaultInternals = {
|
|
8
|
+
/* v8 ignore next -- source/built/packaged subprocess smoke executes this only in a replaceable child process. */
|
|
9
|
+
execve: (...args) => loadLinuxExecve()(...args),
|
|
10
|
+
loadWin32ProcessBindings,
|
|
11
|
+
spawnCurrentTokenJobProcess,
|
|
12
|
+
closeFileDescriptor: closeSync,
|
|
13
|
+
resolveWindowsExecutable,
|
|
14
|
+
pollProcessExit,
|
|
15
|
+
isJobEmpty,
|
|
16
|
+
terminateJob,
|
|
17
|
+
closeHandleChecked
|
|
18
|
+
};
|
|
19
|
+
const NODE_SPAWN_DETAIL_CODES = new Set(["EACCES", "ENOENT"]);
|
|
20
|
+
const WINDOWS_SPAWN_ERROR_CODES = new Map([
|
|
21
|
+
[2, "ENOENT"],
|
|
22
|
+
[3, "ENOENT"],
|
|
23
|
+
[267, "ENOENT"],
|
|
24
|
+
[5, "EPERM"],
|
|
25
|
+
[193, "EFTYPE"],
|
|
26
|
+
[740, "EACCES"]
|
|
27
|
+
]);
|
|
28
|
+
function nodeSpawnError(syscall, code, path) {
|
|
29
|
+
return {
|
|
30
|
+
name: "Error",
|
|
31
|
+
message: `${syscall} ${code}`,
|
|
32
|
+
code,
|
|
33
|
+
syscall,
|
|
34
|
+
...path === void 0 ? {} : { path }
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
function asSpawnError(error, program) {
|
|
38
|
+
const serialized = serializeRunnerError(error);
|
|
39
|
+
if (!(error instanceof Win32Error)) return serialized.code === void 0 ? serialized : nodeSpawnError(`spawn ${program}`, serialized.code, program);
|
|
40
|
+
const code = WINDOWS_SPAWN_ERROR_CODES.get(error.win32Code) ?? "UNKNOWN";
|
|
41
|
+
if (NODE_SPAWN_DETAIL_CODES.has(code)) return nodeSpawnError(`spawn ${program}`, code, program);
|
|
42
|
+
return nodeSpawnError("spawn", code);
|
|
43
|
+
}
|
|
44
|
+
function windowsPathNotFoundError(program) {
|
|
45
|
+
return nodeSpawnError(`spawn ${program}`, "ENOENT", program);
|
|
46
|
+
}
|
|
47
|
+
function windowsStartCancelledError() {
|
|
48
|
+
return {
|
|
49
|
+
name: "Error",
|
|
50
|
+
message: "subprocess target start was cancelled"
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
function linuxPathNotFoundError(program) {
|
|
54
|
+
return Object.assign(/* @__PURE__ */ new Error(`spawn ${program} ENOENT`), {
|
|
55
|
+
code: "ENOENT",
|
|
56
|
+
errno: -2,
|
|
57
|
+
syscall: `spawn ${program}`,
|
|
58
|
+
path: program,
|
|
59
|
+
spawnargs: []
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
function execLinuxFile(file, argv, request, internals) {
|
|
63
|
+
try {
|
|
64
|
+
return internals.execve(file, argv, request.env, request.control, request.pipeFds);
|
|
65
|
+
} catch (error) {
|
|
66
|
+
if (error.code !== "ENOEXEC") throw error;
|
|
67
|
+
return internals.execve("/bin/sh", [
|
|
68
|
+
"/bin/sh",
|
|
69
|
+
file,
|
|
70
|
+
...argv.slice(1)
|
|
71
|
+
], request.env, request.control, request.pipeFds);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
function execLinuxTarget(request, argv, internals) {
|
|
75
|
+
const program = argv[0];
|
|
76
|
+
if (program.includes("/")) return execLinuxFile(program, argv, request, internals);
|
|
77
|
+
const path = request.env.PATH ?? "/usr/bin:/bin";
|
|
78
|
+
let permissionFailure;
|
|
79
|
+
for (const directory of path.split(":")) {
|
|
80
|
+
const root = directory.startsWith("/") ? directory : `${request.cwd}${request.cwd.endsWith("/") ? "" : "/"}${directory}`;
|
|
81
|
+
const candidate = `${root}${root.endsWith("/") ? "" : "/"}${program}`;
|
|
82
|
+
try {
|
|
83
|
+
return execLinuxFile(candidate, argv, request, internals);
|
|
84
|
+
} catch (error) {
|
|
85
|
+
const code = error.code;
|
|
86
|
+
if (code === "EACCES") {
|
|
87
|
+
permissionFailure ??= error;
|
|
88
|
+
continue;
|
|
89
|
+
}
|
|
90
|
+
if (code === "ENOENT" || code === "ENOTDIR") continue;
|
|
91
|
+
throw error;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
throw permissionFailure ?? linuxPathNotFoundError(program);
|
|
95
|
+
}
|
|
96
|
+
function runLinux(locator, argv, host, internals) {
|
|
97
|
+
const files = linuxLaunchFilesFromLocator(locator);
|
|
98
|
+
let request;
|
|
99
|
+
try {
|
|
100
|
+
request = consumeLinuxLaunchRequest(files.requestPath);
|
|
101
|
+
} catch (error) {
|
|
102
|
+
writeLinuxStartupError(files, {
|
|
103
|
+
type: "error",
|
|
104
|
+
error: serializeRunnerError(error)
|
|
105
|
+
});
|
|
106
|
+
host.exitCode = 127;
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
try {
|
|
110
|
+
host.chdir(request.cwd);
|
|
111
|
+
execLinuxTarget({
|
|
112
|
+
...request,
|
|
113
|
+
cwd: host.cwd()
|
|
114
|
+
}, argv, internals);
|
|
115
|
+
} catch (error) {
|
|
116
|
+
writeLinuxStartupError(files, {
|
|
117
|
+
type: "error",
|
|
118
|
+
error: asSpawnError(error, argv[0])
|
|
119
|
+
});
|
|
120
|
+
host.exitCode = 127;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
function sendMessage(host, result) {
|
|
124
|
+
return new Promise((resolve, reject) => {
|
|
125
|
+
if (!host.connected || host.send === void 0) {
|
|
126
|
+
reject(/* @__PURE__ */ new Error("subprocess runner IPC is not connected"));
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
try {
|
|
130
|
+
host.send(result, (error) => {
|
|
131
|
+
if (error === null) resolve();
|
|
132
|
+
else reject(error);
|
|
133
|
+
});
|
|
134
|
+
} catch (error) {
|
|
135
|
+
reject(error instanceof Error ? error : new Error(String(error)));
|
|
136
|
+
}
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
var WindowsJobRunner = class {
|
|
140
|
+
argv;
|
|
141
|
+
host;
|
|
142
|
+
internals;
|
|
143
|
+
api;
|
|
144
|
+
processHandle;
|
|
145
|
+
jobHandle;
|
|
146
|
+
pollTimer;
|
|
147
|
+
startSeen = false;
|
|
148
|
+
terminateRequested = false;
|
|
149
|
+
resultStarted = false;
|
|
150
|
+
resultDelivered = false;
|
|
151
|
+
finished = false;
|
|
152
|
+
completion = Promise.withResolvers();
|
|
153
|
+
constructor(argv, host, internals) {
|
|
154
|
+
this.argv = argv;
|
|
155
|
+
this.host = host;
|
|
156
|
+
this.internals = internals;
|
|
157
|
+
}
|
|
158
|
+
run() {
|
|
159
|
+
if (!this.host.connected || this.host.send === void 0) {
|
|
160
|
+
this.finish(127);
|
|
161
|
+
return this.completion.promise;
|
|
162
|
+
}
|
|
163
|
+
this.host.on("message", this.onMessage);
|
|
164
|
+
this.host.once("disconnect", this.onDisconnect);
|
|
165
|
+
return this.completion.promise;
|
|
166
|
+
}
|
|
167
|
+
onMessage = (value) => {
|
|
168
|
+
if (this.finished) return;
|
|
169
|
+
if (isWindowsTerminateRequest(value)) {
|
|
170
|
+
this.requestTermination();
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
173
|
+
if (this.startSeen) {
|
|
174
|
+
this.runnerFailure(/* @__PURE__ */ new Error("subprocess runner received more than one Windows start request"));
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
let request;
|
|
178
|
+
try {
|
|
179
|
+
request = parseWindowsStartRequest(value);
|
|
180
|
+
} catch (error) {
|
|
181
|
+
this.runnerFailure(error);
|
|
182
|
+
return;
|
|
183
|
+
}
|
|
184
|
+
this.startSeen = true;
|
|
185
|
+
this.start(request);
|
|
186
|
+
};
|
|
187
|
+
onDisconnect = () => {
|
|
188
|
+
if (this.finished) return;
|
|
189
|
+
this.releaseOwnedJob();
|
|
190
|
+
this.finish(127, false);
|
|
191
|
+
};
|
|
192
|
+
async start(request) {
|
|
193
|
+
if (this.terminateRequested) {
|
|
194
|
+
await this.publishTerminalResult({
|
|
195
|
+
type: "error",
|
|
196
|
+
error: windowsStartCancelledError()
|
|
197
|
+
}, 0);
|
|
198
|
+
return;
|
|
199
|
+
}
|
|
200
|
+
await new Promise((resolveImmediate) => {
|
|
201
|
+
setImmediate(resolveImmediate);
|
|
202
|
+
});
|
|
203
|
+
if (this.finished) return;
|
|
204
|
+
if (this.terminateRequested) {
|
|
205
|
+
await this.publishTerminalResult({
|
|
206
|
+
type: "error",
|
|
207
|
+
error: windowsStartCancelledError()
|
|
208
|
+
}, 0);
|
|
209
|
+
return;
|
|
210
|
+
}
|
|
211
|
+
try {
|
|
212
|
+
const [command, ...args] = this.argv;
|
|
213
|
+
const applicationName = this.internals.resolveWindowsExecutable(command, request.cwd, request.env, void 0, { ...this.host.env });
|
|
214
|
+
if (applicationName === void 0) {
|
|
215
|
+
await this.publishTerminalResult({
|
|
216
|
+
type: "error",
|
|
217
|
+
error: windowsPathNotFoundError(command)
|
|
218
|
+
}, 0);
|
|
219
|
+
return;
|
|
220
|
+
}
|
|
221
|
+
this.api = this.internals.loadWin32ProcessBindings();
|
|
222
|
+
const spawned = this.internals.spawnCurrentTokenJobProcess(this.api, {
|
|
223
|
+
command,
|
|
224
|
+
applicationName,
|
|
225
|
+
args,
|
|
226
|
+
cwd: request.cwd,
|
|
227
|
+
env: request.env,
|
|
228
|
+
stdio: {
|
|
229
|
+
stdin: 4,
|
|
230
|
+
stdout: 5,
|
|
231
|
+
stderr: 6,
|
|
232
|
+
...request.control === "pipe" ? { control: SUBPROCESS_CONTROL_FD } : {}
|
|
233
|
+
}
|
|
234
|
+
});
|
|
235
|
+
this.processHandle = spawned.process;
|
|
236
|
+
this.jobHandle = spawned.job;
|
|
237
|
+
for (const fileDescriptor of request.control === "pipe" ? [
|
|
238
|
+
4,
|
|
239
|
+
5,
|
|
240
|
+
6,
|
|
241
|
+
SUBPROCESS_CONTROL_FD
|
|
242
|
+
] : [
|
|
243
|
+
4,
|
|
244
|
+
5,
|
|
245
|
+
6
|
|
246
|
+
]) this.internals.closeFileDescriptor(fileDescriptor);
|
|
247
|
+
this.pollTimer = setInterval(() => {
|
|
248
|
+
this.poll();
|
|
249
|
+
}, 10);
|
|
250
|
+
} catch (error) {
|
|
251
|
+
if (this.jobHandle === void 0 && error instanceof Win32Error && error.api === "CreateProcessW") {
|
|
252
|
+
await this.publishTerminalResult({
|
|
253
|
+
type: "error",
|
|
254
|
+
error: asSpawnError(error, this.argv[0])
|
|
255
|
+
}, 0);
|
|
256
|
+
return;
|
|
257
|
+
}
|
|
258
|
+
await this.runnerFailure(error);
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
requestTermination() {
|
|
262
|
+
if (this.terminateRequested) return;
|
|
263
|
+
this.terminateRequested = true;
|
|
264
|
+
try {
|
|
265
|
+
this.terminateOwnedJob();
|
|
266
|
+
} catch (error) {
|
|
267
|
+
this.runnerFailure(error);
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
terminateOwnedJob() {
|
|
271
|
+
const job = this.jobHandle;
|
|
272
|
+
if (job === void 0) return;
|
|
273
|
+
/* v8 ignore next -- a Job handle is assigned only after the bindings are loaded;
|
|
274
|
+
* the guard above is the only reachable empty-owner state. */
|
|
275
|
+
if (this.api === void 0) return;
|
|
276
|
+
this.internals.terminateJob(this.api, job, 1);
|
|
277
|
+
}
|
|
278
|
+
poll() {
|
|
279
|
+
if (this.finished) return;
|
|
280
|
+
/* v8 ignore next -- poll is installed only after start() stores the bindings; retained as a defensive invariant guard. */
|
|
281
|
+
if (this.api === void 0) return;
|
|
282
|
+
try {
|
|
283
|
+
if (this.processHandle !== void 0) {
|
|
284
|
+
const exitCode = this.internals.pollProcessExit(this.api, this.processHandle);
|
|
285
|
+
if (exitCode !== void 0) {
|
|
286
|
+
this.internals.closeHandleChecked(this.api, this.processHandle, "ordinary direct process");
|
|
287
|
+
this.processHandle = void 0;
|
|
288
|
+
this.publishTerminalResult({
|
|
289
|
+
type: "target-exit",
|
|
290
|
+
exitCode
|
|
291
|
+
});
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
if (this.jobHandle !== void 0 && this.internals.isJobEmpty(this.api, this.jobHandle)) {
|
|
295
|
+
this.internals.closeHandleChecked(this.api, this.jobHandle, "ordinary process Job");
|
|
296
|
+
this.jobHandle = void 0;
|
|
297
|
+
if (this.resultDelivered) this.finish(0);
|
|
298
|
+
}
|
|
299
|
+
} catch (error) {
|
|
300
|
+
this.runnerFailure(error);
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
async publishTerminalResult(result, exitCode) {
|
|
304
|
+
/* v8 ignore next -- each state transition has a single result call site; the guard contains only re-entrant internal defects. */
|
|
305
|
+
if (this.finished || this.resultStarted) return;
|
|
306
|
+
this.resultStarted = true;
|
|
307
|
+
try {
|
|
308
|
+
await sendMessage(this.host, result);
|
|
309
|
+
this.resultDelivered = true;
|
|
310
|
+
} catch {
|
|
311
|
+
this.releaseOwnedJob();
|
|
312
|
+
this.finish(127, false);
|
|
313
|
+
return;
|
|
314
|
+
}
|
|
315
|
+
if (exitCode !== void 0) {
|
|
316
|
+
this.finish(exitCode);
|
|
317
|
+
return;
|
|
318
|
+
}
|
|
319
|
+
if (this.jobHandle === void 0) this.finish(0);
|
|
320
|
+
}
|
|
321
|
+
async runnerFailure(error) {
|
|
322
|
+
/* v8 ignore next -- callers stop/detach on finish; this guard contains only an already-queued internal callback. */
|
|
323
|
+
if (this.finished) return;
|
|
324
|
+
if (!this.resultStarted) {
|
|
325
|
+
this.resultStarted = true;
|
|
326
|
+
try {
|
|
327
|
+
await sendMessage(this.host, {
|
|
328
|
+
type: "error",
|
|
329
|
+
error: serializeRunnerError(error)
|
|
330
|
+
});
|
|
331
|
+
this.resultDelivered = true;
|
|
332
|
+
} catch {}
|
|
333
|
+
}
|
|
334
|
+
this.releaseOwnedJob();
|
|
335
|
+
this.finish(127);
|
|
336
|
+
}
|
|
337
|
+
releaseOwnedJob() {
|
|
338
|
+
if (this.pollTimer !== void 0) clearInterval(this.pollTimer);
|
|
339
|
+
this.pollTimer = void 0;
|
|
340
|
+
const api = this.api;
|
|
341
|
+
if (api === void 0) return;
|
|
342
|
+
if (this.jobHandle !== void 0) {
|
|
343
|
+
try {
|
|
344
|
+
this.internals.terminateJob(api, this.jobHandle, 1);
|
|
345
|
+
} catch {}
|
|
346
|
+
try {
|
|
347
|
+
this.internals.closeHandleChecked(api, this.jobHandle, "ordinary process Job cleanup");
|
|
348
|
+
} catch {}
|
|
349
|
+
this.jobHandle = void 0;
|
|
350
|
+
}
|
|
351
|
+
if (this.processHandle !== void 0) {
|
|
352
|
+
try {
|
|
353
|
+
this.internals.closeHandleChecked(api, this.processHandle, "ordinary direct process cleanup");
|
|
354
|
+
} catch {}
|
|
355
|
+
this.processHandle = void 0;
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
finish(exitCode, disconnect = true) {
|
|
359
|
+
if (this.finished) return;
|
|
360
|
+
this.finished = true;
|
|
361
|
+
if (this.pollTimer !== void 0) clearInterval(this.pollTimer);
|
|
362
|
+
this.pollTimer = void 0;
|
|
363
|
+
this.host.off("message", this.onMessage);
|
|
364
|
+
this.host.off("disconnect", this.onDisconnect);
|
|
365
|
+
this.host.exitCode = exitCode;
|
|
366
|
+
if (disconnect && this.host.connected) this.host.disconnect();
|
|
367
|
+
this.completion.resolve();
|
|
368
|
+
}
|
|
369
|
+
};
|
|
370
|
+
/**
|
|
371
|
+
* Execute the selected Linux bootstrap or Windows Job runner.
|
|
372
|
+
* @param selection - Windows sentinel or Linux launch-request locator.
|
|
373
|
+
* @param argv - private runner arguments beginning with the target delimiter.
|
|
374
|
+
* @param host - process transport and lifecycle host.
|
|
375
|
+
* @param internals - native and filesystem operations used by the runner.
|
|
376
|
+
*/
|
|
377
|
+
async function runSpawnRunner(selection, argv, host = process, internals = defaultInternals) {
|
|
378
|
+
Reflect.deleteProperty(host.env, SUBPROCESS_RUNNER_ENV);
|
|
379
|
+
const targetArgv = parseRunnerTargetArgv(argv);
|
|
380
|
+
if (selection === "windows") {
|
|
381
|
+
await new WindowsJobRunner(targetArgv, host, internals).run();
|
|
382
|
+
return;
|
|
383
|
+
}
|
|
384
|
+
runLinux(selection, targetArgv, host, internals);
|
|
385
|
+
}
|
|
386
|
+
/**
|
|
387
|
+
* Best-effort reporting for failures before the selected runner established its owner.
|
|
388
|
+
* @param selection - Windows sentinel, Linux launch-request locator, or no selection.
|
|
389
|
+
* @param error - failure raised before normal runner settlement.
|
|
390
|
+
* @param host - process transport and lifecycle host.
|
|
391
|
+
*/
|
|
392
|
+
async function reportSpawnRunnerFailure(selection, error, host = process) {
|
|
393
|
+
if (selection === "windows") {
|
|
394
|
+
try {
|
|
395
|
+
await sendMessage(host, {
|
|
396
|
+
type: "error",
|
|
397
|
+
error: serializeRunnerError(error)
|
|
398
|
+
});
|
|
399
|
+
} catch {}
|
|
400
|
+
host.exitCode = 127;
|
|
401
|
+
if (host.connected) host.disconnect();
|
|
402
|
+
return;
|
|
403
|
+
}
|
|
404
|
+
if (selection !== void 0) try {
|
|
405
|
+
writeLinuxStartupError(linuxLaunchFilesFromLocator(selection), {
|
|
406
|
+
type: "error",
|
|
407
|
+
error: serializeRunnerError(error)
|
|
408
|
+
});
|
|
409
|
+
} catch {}
|
|
410
|
+
host.exitCode = 127;
|
|
411
|
+
}
|
|
412
|
+
//#endregion
|
|
413
|
+
//#region lib/types/bin.js
|
|
414
|
+
/** Thin executable/importable entry for the provider-private runner core. */
|
|
415
|
+
/**
|
|
416
|
+
* Run a selector already removed by a packaging bootstrap.
|
|
417
|
+
* @param selection - private runner selector or Linux launch-request locator.
|
|
418
|
+
*/
|
|
419
|
+
async function runSelectedSubprocessRunner(selection) {
|
|
420
|
+
try {
|
|
421
|
+
await runSpawnRunner(selection, process.argv.slice(2));
|
|
422
|
+
} catch (error) {
|
|
423
|
+
await reportSpawnRunnerFailure(selection, error);
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
if (import.meta.main) {
|
|
427
|
+
const selection = consumeRunnerSelection();
|
|
428
|
+
if (selection === void 0) process.exitCode = 127;
|
|
429
|
+
else runSelectedSubprocessRunner(selection);
|
|
430
|
+
}
|
|
431
|
+
//#endregion
|
|
432
|
+
export { runSelectedSubprocessRunner };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/** Thin executable/importable entry for the provider-private runner core. */
|
|
2
|
+
/**
|
|
3
|
+
* Run a selector already removed by a packaging bootstrap.
|
|
4
|
+
* @param selection - private runner selector or Linux launch-request locator.
|
|
5
|
+
*/
|
|
6
|
+
export declare function runSelectedSubprocessRunner(selection: string): Promise<void>;
|
|
7
|
+
//# sourceMappingURL=bin.d.ts.map
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/** Parent-side setup for one explicitly requested inherited control pipe. */
|
|
2
|
+
import type { Duplex, Readable, Writable } from 'node:stream';
|
|
3
|
+
/**
|
|
4
|
+
* Read the optional extra pipe from Node's stdio tuple.
|
|
5
|
+
* @param child - child whose requested extra pipe was allocated by Node.
|
|
6
|
+
* @param control - requested transport, or undefined when absent.
|
|
7
|
+
* @returns the parent duplex endpoint, absent when not requested or native startup failed.
|
|
8
|
+
*/
|
|
9
|
+
export declare function controlPipe(child: {
|
|
10
|
+
readonly stdio: ReadonlyArray<Readable | Writable | null | undefined>;
|
|
11
|
+
}, control?: 'pipe'): Duplex | undefined;
|
|
12
|
+
/**
|
|
13
|
+
* Stamp the private marker on a fresh child environment after rejecting a caller override.
|
|
14
|
+
* @param env - newly materialized child environment, owned by the caller.
|
|
15
|
+
* @param control - requested control transport, or undefined when absent.
|
|
16
|
+
* @returns the same environment with the provider-owned launch marker when requested.
|
|
17
|
+
*/
|
|
18
|
+
export declare function controlEnvironment<T extends NodeJS.ProcessEnv>(env: T, control?: 'pipe'): T;
|
|
19
|
+
//# sourceMappingURL=control-spawn.d.ts.map
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Local Service Provider for the subprocess capability seam. Each spawn owns a
|
|
3
|
+
* platform-selected managed range with the spec's per-stream stdio dispositions.
|
|
4
|
+
* Normal disposal terminates and joins live ranges; Node's synchronous exit
|
|
5
|
+
* phase force-stops any ranges the service still owns. It has no config: every
|
|
6
|
+
* disposition and limit arrives on the spec, so deployment-varying choices
|
|
7
|
+
* stay with the caller's config (the bash executor's, the LSP host's, …).
|
|
8
|
+
* @module @unieai/rabi-subprocess-local
|
|
9
|
+
*/
|
|
10
|
+
import { Context } from '@unieai/cordis';
|
|
11
|
+
import { SubprocessRuntime } from '@unieai/rabi-subprocess';
|
|
12
|
+
import type { SubprocessHandle, SubprocessSpawnSpec, SubprocessTerminalHandle, SubprocessTerminalEnvironment, SubprocessTerminalSpawnSpec } from '@unieai/rabi-subprocess';
|
|
13
|
+
import type { SpawnInternals } from './spawn.ts';
|
|
14
|
+
import type { ProcessInspector } from './process-inspector.ts';
|
|
15
|
+
/**
|
|
16
|
+
* Local subprocess service: platform-selected managed ranges, Node-shaped stdio
|
|
17
|
+
* dispositions (raw pipes, inherit, bounded tail-keep collection with spill
|
|
18
|
+
* files), credential-scrubbed environment, and provider-owned range signalling.
|
|
19
|
+
* POSIX paths stage TERM before KILL; Windows paths terminate immediately.
|
|
20
|
+
* JavaScript-observable host exit also performs synchronous final termination.
|
|
21
|
+
*/
|
|
22
|
+
export declare class LocalSubprocessRuntime extends SubprocessRuntime {
|
|
23
|
+
/** Live handles retained for normal disposal and synchronous host-exit finalization. */
|
|
24
|
+
private live;
|
|
25
|
+
/** Live terminals retained through normal quiescence or host-exit finalization. */
|
|
26
|
+
private terminals;
|
|
27
|
+
/** Caller endpoints retained until close, independently of managed process lifetime. */
|
|
28
|
+
private controlChannels;
|
|
29
|
+
/** Test hook: process, spill, and platform operations forwarded to spawnSubprocess. */
|
|
30
|
+
internals: SpawnInternals;
|
|
31
|
+
/** Provider-lifetime latch suppressing repeated weaker-containment warnings. */
|
|
32
|
+
private fallbackWarningIssued;
|
|
33
|
+
/**
|
|
34
|
+
* Linux native containment decisions. Each probe is a spawnSync that blocks the event loop and forks the
|
|
35
|
+
* host, so the selector reruns it only after an event invalidates the previous verdict.
|
|
36
|
+
*/
|
|
37
|
+
private readonly linuxScope;
|
|
38
|
+
/** Scope decision of the launch in progress; selectContainmentMode sets it immediately before the launch reads it. */
|
|
39
|
+
private linuxScopeDecision;
|
|
40
|
+
/** Test hook for platform process inspection; production resolves lazily on terminal spawn. */
|
|
41
|
+
terminalInspector: ProcessInspector | undefined;
|
|
42
|
+
constructor(ctx: Context);
|
|
43
|
+
/** Spill failures reach the plugin logger; the log line is the only trace of why a result has no spill path. */
|
|
44
|
+
private readonly reportSpillFailure;
|
|
45
|
+
private terminateForHostExit;
|
|
46
|
+
private disposeManagedProcesses;
|
|
47
|
+
resolveExecutable(command: string, env?: Readonly<Record<string, string>>, signal?: AbortSignal): Promise<string>;
|
|
48
|
+
private executableCandidates;
|
|
49
|
+
spawn(spec: SubprocessSpawnSpec): SubprocessHandle;
|
|
50
|
+
/** Probe again before the next launch when a scope launched under generation never started its target. */
|
|
51
|
+
private watchLinuxScopeStart;
|
|
52
|
+
private selectContainmentMode;
|
|
53
|
+
private warnFallback;
|
|
54
|
+
/** @inheritdoc */
|
|
55
|
+
terminalEnvironment(signal?: AbortSignal): Promise<SubprocessTerminalEnvironment>;
|
|
56
|
+
spawnTerminal(spec: SubprocessTerminalSpawnSpec): Promise<SubprocessTerminalHandle>;
|
|
57
|
+
}
|
|
58
|
+
export default LocalSubprocessRuntime;
|
|
59
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/** Lazy libc execve and descriptor bindings used by the one-shot Linux bootstrap. */
|
|
2
|
+
/** Replace the current process image while preserving the supplied argv and environment. */
|
|
3
|
+
export type LinuxExecve = (file: string, argv: string[], env: Record<string, string>, control?: 'pipe', pipeFds?: readonly number[]) => never;
|
|
4
|
+
/**
|
|
5
|
+
* Load libc's execve and fcntl symbols on first use and retain the native bindings.
|
|
6
|
+
* @returns a process-replacing execve operation that throws Node-style errors on failure.
|
|
7
|
+
*/
|
|
8
|
+
export declare function loadLinuxExecve(): LinuxExecve;
|
|
9
|
+
//# sourceMappingURL=linux-execve.d.ts.map
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/** Linux native containment decisions over injected host observations. */
|
|
2
|
+
import type { LiteralArgvOptions } from './linux-scope.ts';
|
|
3
|
+
/** Host observations behind each decision; the runtime supplies the real checks and tests script them. */
|
|
4
|
+
export interface LinuxScopeObservations {
|
|
5
|
+
/** Run the deep transient-scope probe: literal-argv options when a scope can start, otherwise undefined. */
|
|
6
|
+
probe(): LiteralArgvOptions | undefined;
|
|
7
|
+
/** Identify the process listening on the user manager's private socket, or undefined when none listens. */
|
|
8
|
+
managerListener(): string | undefined;
|
|
9
|
+
/** Confirm the user manager before a launch under a positive verdict. */
|
|
10
|
+
confirmManager(): boolean;
|
|
11
|
+
/** Identify the systemd-run binary scope launches resolve, or undefined when none resolves. */
|
|
12
|
+
launcherIdentity(): string | undefined;
|
|
13
|
+
}
|
|
14
|
+
/** Event that made the selector probe: the first selection or one that invalidated the previous verdict. */
|
|
15
|
+
export type LinuxProbeTrigger = 'first' | 'scope-not-started' | 'new-listener' | 'launcher-changed';
|
|
16
|
+
/** One containment decision and the branch that produced it. */
|
|
17
|
+
export type LinuxScopeDecision = {
|
|
18
|
+
readonly kind: 'scope';
|
|
19
|
+
/** A probe found scope support, or a positive verdict confirmed the user manager. */
|
|
20
|
+
readonly reason: 'probe-available' | 'manager-confirmed';
|
|
21
|
+
readonly literalArgv: LiteralArgvOptions;
|
|
22
|
+
/** Probe count when the verdict was made; pass it to scopeNotStarted for a failed launch. */
|
|
23
|
+
readonly generation: number;
|
|
24
|
+
readonly probe: LinuxProbeTrigger | undefined;
|
|
25
|
+
} | {
|
|
26
|
+
readonly kind: 'fallback';
|
|
27
|
+
/**
|
|
28
|
+
* A probe found no scope support; a positive verdict failed to confirm the manager for this launch;
|
|
29
|
+
* or a negative verdict saw no listener or the listener present at the failed probe.
|
|
30
|
+
*/
|
|
31
|
+
readonly reason: 'probe-unavailable' | 'manager-unconfirmed' | 'no-listener' | 'same-listener';
|
|
32
|
+
readonly probe: LinuxProbeTrigger | undefined;
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* Provider-lifetime Linux scope selection. A probe runs on the first selection and again only after
|
|
36
|
+
* a scope launch never started its target, a different user-manager listener appears under a
|
|
37
|
+
* negative verdict, or the systemd-run binary changes under a positive one. A positive verdict
|
|
38
|
+
* confirms the user manager on every selection. Selection is synchronous, so a decision stays
|
|
39
|
+
* valid for the launch that follows it.
|
|
40
|
+
*/
|
|
41
|
+
export declare class LinuxScopeSelector {
|
|
42
|
+
private readonly observe;
|
|
43
|
+
private state;
|
|
44
|
+
private generation;
|
|
45
|
+
/** @param observe - host checks consulted by each selection. */
|
|
46
|
+
constructor(observe: LinuxScopeObservations);
|
|
47
|
+
/**
|
|
48
|
+
* Choose containment for one eligible launch.
|
|
49
|
+
* @returns the decision and the branch that produced it.
|
|
50
|
+
*/
|
|
51
|
+
select(): LinuxScopeDecision;
|
|
52
|
+
/**
|
|
53
|
+
* Record that a scope launched under generation exited before its bootstrap started the target,
|
|
54
|
+
* so the next selection probes again. Launches from a superseded probe are ignored.
|
|
55
|
+
* @param generation - generation of the scope decision that launched it.
|
|
56
|
+
*/
|
|
57
|
+
scopeNotStarted(generation: number): void;
|
|
58
|
+
private probe;
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=linux-scope-selector.d.ts.map
|