@botiverse/oar 0.100.0 → 0.101.0
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/README.md +2 -2
- package/dist/contracts/session-options.d.ts +1 -1
- package/dist/runtimes/codex/installation-candidates.d.ts +31 -0
- package/dist/runtimes/codex/installation-candidates.d.ts.map +1 -0
- package/dist/runtimes/codex/installation-candidates.js +92 -0
- package/dist/runtimes/codex/installation-candidates.js.map +1 -0
- package/dist/runtimes/codex/installation.d.ts +1 -30
- package/dist/runtimes/codex/installation.d.ts.map +1 -1
- package/dist/runtimes/codex/installation.js +2 -82
- package/dist/runtimes/codex/installation.js.map +1 -1
- package/dist/runtimes/cursor/access.d.ts +68 -0
- package/dist/runtimes/cursor/access.d.ts.map +1 -0
- package/dist/runtimes/cursor/access.js +77 -0
- package/dist/runtimes/cursor/access.js.map +1 -0
- package/dist/runtimes/cursor/auth-status.d.ts +4 -3
- package/dist/runtimes/cursor/auth-status.d.ts.map +1 -1
- package/dist/runtimes/cursor/auth-status.js +20 -18
- package/dist/runtimes/cursor/auth-status.js.map +1 -1
- package/dist/runtimes/cursor/index.d.ts +50 -10
- package/dist/runtimes/cursor/index.d.ts.map +1 -1
- package/dist/runtimes/cursor/index.js +40 -21
- package/dist/runtimes/cursor/index.js.map +1 -1
- package/dist/runtimes/cursor/installation.d.ts +1 -1
- package/dist/runtimes/cursor/installation.d.ts.map +1 -1
- package/dist/runtimes/cursor/installation.js +5 -2
- package/dist/runtimes/cursor/installation.js.map +1 -1
- package/dist/runtimes/cursor/list-models.d.ts +4 -2
- package/dist/runtimes/cursor/list-models.d.ts.map +1 -1
- package/dist/runtimes/cursor/list-models.js +31 -14
- package/dist/runtimes/cursor/list-models.js.map +1 -1
- package/dist/runtimes/cursor/login.d.ts +8 -3
- package/dist/runtimes/cursor/login.d.ts.map +1 -1
- package/dist/runtimes/cursor/login.js +29 -22
- package/dist/runtimes/cursor/login.js.map +1 -1
- package/dist/runtimes/cursor/logout.d.ts +3 -3
- package/dist/runtimes/cursor/logout.d.ts.map +1 -1
- package/dist/runtimes/cursor/logout.js +19 -18
- package/dist/runtimes/cursor/logout.js.map +1 -1
- package/dist/runtimes/cursor/model.d.ts +5 -0
- package/dist/runtimes/cursor/model.d.ts.map +1 -1
- package/dist/runtimes/cursor/model.js +10 -1
- package/dist/runtimes/cursor/model.js.map +1 -1
- package/dist/runtimes/cursor/sdk.d.ts +0 -4
- package/dist/runtimes/cursor/sdk.d.ts.map +1 -1
- package/dist/runtimes/cursor/sdk.js +5 -11
- package/dist/runtimes/cursor/sdk.js.map +1 -1
- package/dist/runtimes/cursor/session-process.d.ts +31 -0
- package/dist/runtimes/cursor/session-process.d.ts.map +1 -0
- package/dist/runtimes/cursor/session-process.js +80 -0
- package/dist/runtimes/cursor/session-process.js.map +1 -0
- package/dist/runtimes/cursor/session.d.ts +2 -2
- package/dist/runtimes/cursor/session.d.ts.map +1 -1
- package/dist/runtimes/cursor/session.js +10 -10
- package/dist/runtimes/cursor/session.js.map +1 -1
- package/dist/runtimes/cursor/subprocess/channel.d.ts +37 -0
- package/dist/runtimes/cursor/subprocess/channel.d.ts.map +1 -0
- package/dist/runtimes/cursor/subprocess/channel.js +170 -0
- package/dist/runtimes/cursor/subprocess/channel.js.map +1 -0
- package/dist/runtimes/cursor/subprocess/child-script.d.ts +12 -0
- package/dist/runtimes/cursor/subprocess/child-script.d.ts.map +1 -0
- package/dist/runtimes/cursor/subprocess/child-script.js +257 -0
- package/dist/runtimes/cursor/subprocess/child-script.js.map +1 -0
- package/dist/runtimes/cursor/subprocess/proxy.d.ts +11 -0
- package/dist/runtimes/cursor/subprocess/proxy.d.ts.map +1 -0
- package/dist/runtimes/cursor/subprocess/proxy.js +242 -0
- package/dist/runtimes/cursor/subprocess/proxy.js.map +1 -0
- package/dist/shared/executable/environment-marker.d.ts +21 -0
- package/dist/shared/executable/environment-marker.d.ts.map +1 -0
- package/dist/shared/executable/environment-marker.js +137 -0
- package/dist/shared/executable/environment-marker.js.map +1 -0
- package/dist/shared/executable/node-script.d.ts +53 -0
- package/dist/shared/executable/node-script.d.ts.map +1 -0
- package/dist/shared/executable/node-script.js +131 -0
- package/dist/shared/executable/node-script.js.map +1 -0
- package/package.json +5 -1
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
2
|
+
import { readdirSync, readFileSync, statSync } from "node:fs";
|
|
3
|
+
import { readdir, readFile, stat } from "node:fs/promises";
|
|
4
|
+
/*
|
|
5
|
+
* An environment marker: a variable a child is started with, which every
|
|
6
|
+
* process it starts inherits unless that process clears its environment.
|
|
7
|
+
* After the child is gone, the processes still carrying it are the ones it
|
|
8
|
+
* started, even those reparented away from it (a shell's `cmd &` or `nohup`
|
|
9
|
+
* job, once the shell exited) and outside its process group, which a
|
|
10
|
+
* parent-pid walk or a group kill cannot find. This is the approach of
|
|
11
|
+
* Jenkins' ProcessTreeKiller. Linux only: it reads `/proc/<pid>/environ`,
|
|
12
|
+
* which holds a process's environment as it was started; elsewhere there is
|
|
13
|
+
* no portable way to read another process's environment, and nothing is
|
|
14
|
+
* scanned.
|
|
15
|
+
*/
|
|
16
|
+
/** A fresh marker: `NAME=1`, the name unique to one child. Not a secret. */
|
|
17
|
+
export function newEnvironmentMarker() {
|
|
18
|
+
const name = `OAR_CURSOR_CHILD_${randomUUID().replaceAll("-", "")}`;
|
|
19
|
+
return { name, entry: `${name}=1` };
|
|
20
|
+
}
|
|
21
|
+
/** The pids of this user's processes, other than this one, started with `entry` (`NAME=value`) in their environment. Linux only; empty elsewhere. */
|
|
22
|
+
export function markedProcesses(entry) {
|
|
23
|
+
if (process.platform !== "linux") {
|
|
24
|
+
return [];
|
|
25
|
+
}
|
|
26
|
+
const uid = process.getuid?.();
|
|
27
|
+
const found = [];
|
|
28
|
+
let names = [];
|
|
29
|
+
try {
|
|
30
|
+
names = readdirSync("/proc");
|
|
31
|
+
}
|
|
32
|
+
catch {
|
|
33
|
+
return found;
|
|
34
|
+
}
|
|
35
|
+
for (const name of names) {
|
|
36
|
+
const pid = Number(name);
|
|
37
|
+
if (!/^\d+$/u.test(name) || pid === process.pid) {
|
|
38
|
+
continue;
|
|
39
|
+
}
|
|
40
|
+
try {
|
|
41
|
+
if (statSync(`/proc/${name}`).uid !== uid) {
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
if (readFileSync(`/proc/${name}/environ`, "latin1").split("\0").includes(entry)) {
|
|
45
|
+
found.push(pid);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
catch {
|
|
49
|
+
// Gone meanwhile, or not readable: not ours to end.
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return found;
|
|
53
|
+
}
|
|
54
|
+
const live = new Set();
|
|
55
|
+
let exitHookInstalled = false;
|
|
56
|
+
/** Scan passes at most: a marked process may fork between a pass's read and its kill, so a pass that found some is followed by another. */
|
|
57
|
+
const PASSES = 5;
|
|
58
|
+
function kill(pids) {
|
|
59
|
+
for (const pid of pids) {
|
|
60
|
+
try {
|
|
61
|
+
process.kill(pid, "SIGKILL");
|
|
62
|
+
}
|
|
63
|
+
catch { /* Gone meanwhile. */ }
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
/** SIGKILL every process `markedProcesses(entry)` finds, pass after pass until one finds none (at most five). Synchronous, so an `exit` hook can call it. */
|
|
67
|
+
export function killMarked(entry) {
|
|
68
|
+
for (let pass = 0; pass < PASSES; pass += 1) {
|
|
69
|
+
const found = markedProcesses(entry);
|
|
70
|
+
if (found.length === 0) {
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
kill(found);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
/** The same without blocking the event loop: `/proc` is read asynchronously. */
|
|
77
|
+
export async function markedProcessesAsync(entry) {
|
|
78
|
+
if (process.platform !== "linux") {
|
|
79
|
+
return [];
|
|
80
|
+
}
|
|
81
|
+
const uid = process.getuid?.();
|
|
82
|
+
let names = [];
|
|
83
|
+
try {
|
|
84
|
+
names = await readdir("/proc");
|
|
85
|
+
}
|
|
86
|
+
catch {
|
|
87
|
+
return [];
|
|
88
|
+
}
|
|
89
|
+
const checked = await Promise.all(names.map(async (name) => {
|
|
90
|
+
const pid = Number(name);
|
|
91
|
+
if (!/^\d+$/u.test(name) || pid === process.pid) {
|
|
92
|
+
return null;
|
|
93
|
+
}
|
|
94
|
+
try {
|
|
95
|
+
const owner = await stat(`/proc/${name}`);
|
|
96
|
+
if (owner.uid !== uid) {
|
|
97
|
+
return null;
|
|
98
|
+
}
|
|
99
|
+
const environment = await readFile(`/proc/${name}/environ`, "latin1");
|
|
100
|
+
return environment.split("\0").includes(entry) ? pid : null;
|
|
101
|
+
}
|
|
102
|
+
catch {
|
|
103
|
+
return null;
|
|
104
|
+
}
|
|
105
|
+
}));
|
|
106
|
+
return checked.filter((pid) => pid !== null);
|
|
107
|
+
}
|
|
108
|
+
/** `killMarked` without blocking the event loop. */
|
|
109
|
+
export async function killMarkedAsync(entry) {
|
|
110
|
+
for (let pass = 0; pass < PASSES; pass += 1) {
|
|
111
|
+
// oxlint-disable-next-line eslint/no-await-in-loop -- each pass reads the table after the previous pass's kills.
|
|
112
|
+
const found = await markedProcessesAsync(entry);
|
|
113
|
+
if (found.length === 0) {
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
kill(found);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Keep `entry` scanned for while its child may run: a host that calls
|
|
121
|
+
* `process.exit` ends the marked processes from its `exit` hook too.
|
|
122
|
+
* Returns the release, for once the child exited and its marked processes
|
|
123
|
+
* were ended.
|
|
124
|
+
*/
|
|
125
|
+
export function trackEnvironmentMarker(entry) {
|
|
126
|
+
live.add(entry);
|
|
127
|
+
if (!exitHookInstalled) {
|
|
128
|
+
exitHookInstalled = true;
|
|
129
|
+
process.once("exit", () => {
|
|
130
|
+
for (const marker of live) {
|
|
131
|
+
killMarked(marker);
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
return () => { live.delete(entry); };
|
|
136
|
+
}
|
|
137
|
+
//# sourceMappingURL=environment-marker.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"environment-marker.js","sources":["../../../src/shared/executable/environment-marker.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAC9D,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAE3D;;;;;;;;;;;GAWG;AAEH,4EAA4E;AAC5E,MAAM,UAAU,oBAAoB;IAClC,MAAM,IAAI,GAAG,oBAAoB,UAAU,EAAE,CAAC,UAAU,CAAC,GAAG,EAAE,EAAE,CAAC,EAAE,CAAC;IACpE,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,IAAI,IAAI,EAAE,CAAC;AACtC,CAAC;AAED,qJAAqJ;AACrJ,MAAM,UAAU,eAAe,CAAC,KAAa;IAC3C,IAAI,OAAO,CAAC,QAAQ,KAAK,OAAO,EAAE,CAAC;QAAC,OAAO,EAAE,CAAC;IAAC,CAAC;IAChD,MAAM,GAAG,GAAG,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC;IAC/B,MAAM,KAAK,GAAa,EAAE,CAAC;IAC3B,IAAI,KAAK,GAAa,EAAE,CAAC;IACzB,IAAI,CAAC;QAAC,KAAK,GAAG,WAAW,CAAC,OAAO,CAAC,CAAC;IAAC,CAAC;IAAC,MAAM,CAAC;QAAC,OAAO,KAAK,CAAC;IAAC,CAAC;IAC7D,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,MAAM,GAAG,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC;QACzB,IAAI,CAAC,QAAQ,CAAC,IAAI,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GAAG,EAAiB,EAAE,CAAC,GAAG,KAAK,IAAI,CAAC,CAAC;AAC9D,CAAC;AAED,oDAAoD;AACpD,MAAM,CAAC,KAAK,UAAU,eAAe,CAAC,KAAa;IACjD,KAAK,IAAI,IAAI,GAAG,CAAC,EAAE,IAAI,GAAG,MAAM,EAAE,IAAI,IAAI,CAAC,EAAE,CAAC;QAC5C,iHAAiH;QACjH,MAAM,KAAK,GAAG,MAAM,oBAAoB,CAAC,KAAK,CAAC,CAAC;QAChD,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAAC,OAAO;QAAC,CAAC;QACnC,IAAI,CAAC,KAAK,CAAC,CAAC;IACd,CAAC;AACH,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,sBAAsB,CAAC,KAAa;IAClD,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IAChB,IAAI,CAAC,iBAAiB,EAAE,CAAC;QACvB,iBAAiB,GAAG,IAAI,CAAC;QACzB,OAAO,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,EAAE;YACxB,KAAK,MAAM,MAAM,IAAI,IAAI,EAAE,CAAC;gBAAC,UAAU,CAAC,MAAM,CAAC,CAAC;YAAC,CAAC;QACpD,CAAC,CAAC,CAAC;IACL,CAAC;IACD,OAAO,GAAG,EAAE,GAAG,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;AACvC,CAAC"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/** How a Node script child ended, with the last 8 KiB of its stderr. */
|
|
2
|
+
export interface NodeScriptExit {
|
|
3
|
+
readonly code: number | null;
|
|
4
|
+
readonly signal: NodeJS.Signals | null;
|
|
5
|
+
readonly stderr: string;
|
|
6
|
+
}
|
|
7
|
+
/** A Node child running a script given on its command line, talking over Node IPC. */
|
|
8
|
+
export interface NodeScriptChild {
|
|
9
|
+
readonly pid: number | undefined;
|
|
10
|
+
/** False once the channel is gone; a message sent then is dropped, and the exit is what gets recorded. */
|
|
11
|
+
send(message: object): boolean;
|
|
12
|
+
onMessage(listener: (message: unknown) => void): void;
|
|
13
|
+
/** Settles once the child exited (or could not be spawned) and the descendants seen before a stop were ended. */
|
|
14
|
+
readonly exited: Promise<NodeScriptExit>;
|
|
15
|
+
/**
|
|
16
|
+
* Stop the child and the descendants found below it. First the process table is
|
|
17
|
+
* read and the child's descendants remembered (by parent pid, so also
|
|
18
|
+
* tools that lead process groups of their own). Then `ask` lets the child
|
|
19
|
+
* stop itself, if given; after the grace period (`killGraceMs()`), or at
|
|
20
|
+
* once without `ask`, SIGTERM to its process group, SIGKILL to the group
|
|
21
|
+
* and the remembered descendants after another grace period (POSIX);
|
|
22
|
+
* `taskkill /T /F` on its tree (Windows). Once the child exited, the
|
|
23
|
+
* remembered descendants still running are sent SIGKILL
|
|
24
|
+
* (process-shutdown.ts, `killTree`). `captureTree: false` skips the read,
|
|
25
|
+
* for a child that starts nothing. Idempotent; settles with the exit.
|
|
26
|
+
*/
|
|
27
|
+
stop(ask?: () => void, captureTree?: boolean): Promise<NodeScriptExit>;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Run `script` with this host's own Node (`process.execPath -e script
|
|
31
|
+
* argument`), stdin ignored, stdout and stderr piped (stdout is drained
|
|
32
|
+
* unread, stderr kept as a tail), and a Node IPC channel with `advanced`
|
|
33
|
+
* serialization. The child is spawned detached on every platform. On POSIX
|
|
34
|
+
* it leads its own process group. On Windows Node otherwise puts it in a job
|
|
35
|
+
* object that ends it together with a dying host, before it can end its own
|
|
36
|
+
* tree; the cost is that a detached Windows child has no console, so a
|
|
37
|
+
* console program it starts without `windowsHide` may open a visible window
|
|
38
|
+
* (process-signals.ts). The script itself must end its tree when its IPC
|
|
39
|
+
* channel disconnects (the host died, SIGKILL included): nothing in the host
|
|
40
|
+
* can then. It is tracked with `trackOwnedProcess`, so a host that calls
|
|
41
|
+
* `process.exit` still ends it and its descendants. On any exit the child's
|
|
42
|
+
* process group is sent SIGKILL (POSIX), which reaches what is left of it.
|
|
43
|
+
* With `marker` (an `environment-marker.ts` entry the caller put in `env`),
|
|
44
|
+
* every process of this user still carrying it is sent SIGKILL once the
|
|
45
|
+
* child exited, for whatever reason (an asynchronous `/proc` scan, repeated
|
|
46
|
+
* until a pass finds none, at most five), and from the host's own `exit`
|
|
47
|
+
* hook (Linux only). The
|
|
48
|
+
* caller sets the environment, including `ELECTRON_RUN_AS_NODE=1` when
|
|
49
|
+
* `process.execPath` may be Electron. Throws in a compiled single executable
|
|
50
|
+
* host (node-eval.ts), which cannot run one.
|
|
51
|
+
*/
|
|
52
|
+
export declare function spawnNodeScript(script: string, argument: string, env: NodeJS.ProcessEnv, marker?: string): NodeScriptChild;
|
|
53
|
+
//# sourceMappingURL=node-script.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"node-script.d.ts","sources":["../../../src/shared/executable/node-script.ts"],"names":[],"mappings":"AAQA,wEAAwE;AACxE,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC,OAAO,GAAG,IAAI,CAAC;IACvC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACzB;AAED,sFAAsF;AACtF,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,CAAC;IACjC,0GAA0G;IAC1G,IAAI,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC;IAC/B,SAAS,CAAC,QAAQ,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,IAAI,GAAG,IAAI,CAAC;IACtD,iHAAiH;IACjH,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC,cAAc,CAAC,CAAC;IACzC;;;;;;;;;;;OAWG;IACH,IAAI,CAAC,GAAG,CAAC,EAAE,MAAM,IAAI,EAAE,WAAW,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,cAAc,CAAC,CAAC;CACxE;AAKD;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,CAAC,UAAU,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,eAAe,CAoF1H"}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import { spawn } from "node:child_process";
|
|
2
|
+
import { nodeEvalExecutable } from "./node-eval.js";
|
|
3
|
+
import { StderrTail } from "./diagnostics.js";
|
|
4
|
+
import { killMarkedAsync, trackEnvironmentMarker } from "./environment-marker.js";
|
|
5
|
+
import { trackOwnedProcess } from "./ownership.js";
|
|
6
|
+
import { processShutdown } from "./process-shutdown.js";
|
|
7
|
+
import { killGraceMs, OWN_PROCESS_GROUP, signalProcessGroup } from "./process-signals.js";
|
|
8
|
+
/** How long the exit waits for stderr to drain after the process itself ended. */
|
|
9
|
+
const STDERR_DRAIN_MS = 250;
|
|
10
|
+
/**
|
|
11
|
+
* Run `script` with this host's own Node (`process.execPath -e script
|
|
12
|
+
* argument`), stdin ignored, stdout and stderr piped (stdout is drained
|
|
13
|
+
* unread, stderr kept as a tail), and a Node IPC channel with `advanced`
|
|
14
|
+
* serialization. The child is spawned detached on every platform. On POSIX
|
|
15
|
+
* it leads its own process group. On Windows Node otherwise puts it in a job
|
|
16
|
+
* object that ends it together with a dying host, before it can end its own
|
|
17
|
+
* tree; the cost is that a detached Windows child has no console, so a
|
|
18
|
+
* console program it starts without `windowsHide` may open a visible window
|
|
19
|
+
* (process-signals.ts). The script itself must end its tree when its IPC
|
|
20
|
+
* channel disconnects (the host died, SIGKILL included): nothing in the host
|
|
21
|
+
* can then. It is tracked with `trackOwnedProcess`, so a host that calls
|
|
22
|
+
* `process.exit` still ends it and its descendants. On any exit the child's
|
|
23
|
+
* process group is sent SIGKILL (POSIX), which reaches what is left of it.
|
|
24
|
+
* With `marker` (an `environment-marker.ts` entry the caller put in `env`),
|
|
25
|
+
* every process of this user still carrying it is sent SIGKILL once the
|
|
26
|
+
* child exited, for whatever reason (an asynchronous `/proc` scan, repeated
|
|
27
|
+
* until a pass finds none, at most five), and from the host's own `exit`
|
|
28
|
+
* hook (Linux only). The
|
|
29
|
+
* caller sets the environment, including `ELECTRON_RUN_AS_NODE=1` when
|
|
30
|
+
* `process.execPath` may be Electron. Throws in a compiled single executable
|
|
31
|
+
* host (node-eval.ts), which cannot run one.
|
|
32
|
+
*/
|
|
33
|
+
export function spawnNodeScript(script, argument, env, marker) {
|
|
34
|
+
const node = nodeEvalExecutable();
|
|
35
|
+
if (node === null) {
|
|
36
|
+
throw new Error("this host is a compiled single executable (Node SEA or Bun standalone): its executable would start the application again instead of a Node script, so it cannot run a Node script child");
|
|
37
|
+
}
|
|
38
|
+
const child = spawn(node, ["-e", script, argument], {
|
|
39
|
+
env,
|
|
40
|
+
stdio: ["ignore", "pipe", "pipe", "ipc"],
|
|
41
|
+
serialization: "advanced",
|
|
42
|
+
detached: true,
|
|
43
|
+
windowsHide: true,
|
|
44
|
+
});
|
|
45
|
+
trackOwnedProcess(child);
|
|
46
|
+
const releaseMarker = marker === undefined ? null : trackEnvironmentMarker(marker);
|
|
47
|
+
const shutdown = processShutdown(child, { killTree: true });
|
|
48
|
+
const stderr = new StderrTail();
|
|
49
|
+
const stderrClosed = Promise.withResolvers();
|
|
50
|
+
child.stdout?.resume();
|
|
51
|
+
// As for line processes, `OAR_CHILD_STDERR=inherit` also forwards it to the host's stderr.
|
|
52
|
+
const inherit = process.env.OAR_CHILD_STDERR === "inherit";
|
|
53
|
+
child.stderr?.on("data", (chunk) => {
|
|
54
|
+
stderr.append(chunk);
|
|
55
|
+
if (inherit) {
|
|
56
|
+
process.stderr.write(chunk);
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
child.stderr?.once("close", () => { stderrClosed.resolve(); });
|
|
60
|
+
if (child.stderr === null) {
|
|
61
|
+
stderrClosed.resolve();
|
|
62
|
+
}
|
|
63
|
+
const ended = Promise.withResolvers();
|
|
64
|
+
let backstop = undefined;
|
|
65
|
+
child.once("exit", (code, signal) => {
|
|
66
|
+
clearTimeout(backstop);
|
|
67
|
+
// What it started may still be in its group (POSIX); the group is ours to end.
|
|
68
|
+
if (OWN_PROCESS_GROUP && child.pid !== undefined) {
|
|
69
|
+
signalProcessGroup(child, "SIGKILL");
|
|
70
|
+
}
|
|
71
|
+
ended.resolve({ code, signal });
|
|
72
|
+
shutdown.nativeExited();
|
|
73
|
+
});
|
|
74
|
+
child.on("error", (error) => {
|
|
75
|
+
if (child.pid === undefined) {
|
|
76
|
+
stderr.append(error.message);
|
|
77
|
+
stderrClosed.resolve();
|
|
78
|
+
ended.resolve({ code: null, signal: null });
|
|
79
|
+
shutdown.nativeExited();
|
|
80
|
+
releaseMarker?.();
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
const exited = (async () => {
|
|
84
|
+
const { code, signal } = await ended.promise;
|
|
85
|
+
// And what it started that kept the marker, wherever it was reparented (Linux; read without blocking the loop).
|
|
86
|
+
if (marker !== undefined && child.pid !== undefined) {
|
|
87
|
+
await killMarkedAsync(marker);
|
|
88
|
+
}
|
|
89
|
+
releaseMarker?.();
|
|
90
|
+
await shutdown.finished;
|
|
91
|
+
const drained = Promise.withResolvers();
|
|
92
|
+
const timer = setTimeout(drained.resolve, STDERR_DRAIN_MS);
|
|
93
|
+
await Promise.race([stderrClosed.promise, drained.promise]);
|
|
94
|
+
clearTimeout(timer);
|
|
95
|
+
return { code, signal, stderr: stderr.text() };
|
|
96
|
+
})();
|
|
97
|
+
const running = () => child.pid !== undefined && child.exitCode === null && child.signalCode === null;
|
|
98
|
+
let stopping = false;
|
|
99
|
+
return {
|
|
100
|
+
pid: child.pid,
|
|
101
|
+
send(message) {
|
|
102
|
+
if (!child.connected) {
|
|
103
|
+
return false;
|
|
104
|
+
}
|
|
105
|
+
return child.send(message, () => { });
|
|
106
|
+
},
|
|
107
|
+
onMessage(listener) { child.on("message", listener); },
|
|
108
|
+
exited,
|
|
109
|
+
async stop(ask, captureTree = true) {
|
|
110
|
+
if (!stopping && running()) {
|
|
111
|
+
stopping = true;
|
|
112
|
+
// Remember its descendants while it still runs: once it is gone they are no longer below it.
|
|
113
|
+
// A child known to start nothing skips the read (on Windows a process-table query of its own).
|
|
114
|
+
if (captureTree) {
|
|
115
|
+
await shutdown.prepare();
|
|
116
|
+
}
|
|
117
|
+
if (ask !== undefined && running()) {
|
|
118
|
+
shutdown.markNativeStop();
|
|
119
|
+
ask();
|
|
120
|
+
backstop = setTimeout(() => { shutdown.stop(); }, killGraceMs());
|
|
121
|
+
}
|
|
122
|
+
else {
|
|
123
|
+
shutdown.stop();
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
const exit = await exited;
|
|
127
|
+
return exit;
|
|
128
|
+
},
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
//# sourceMappingURL=node-script.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"node-script.js","sources":["../../../src/shared/executable/node-script.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3C,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AACpD,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,eAAe,EAAE,sBAAsB,EAAE,MAAM,yBAAyB,CAAC;AAClF,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACnD,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,WAAW,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAgC1F,kFAAkF;AAClF,MAAM,eAAe,GAAG,GAAG,CAAC;AAE5B;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,U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E,WAAW,GAAG,IAAI;YAChC,IAAI,CAAC,QAAQ,IAAI,OAAO,EAAE,EAAE,CAAC;gBAC3B,QAAQ,GAAG,IAAI,CAAC;gBAChB,6FAA6F;gBAC7F,+FAA+F;gBAC/F,IAAI,WAAW,EAAE,CAAC;oBAAC,MAAM,QAAQ,CAAC,OAAO,EAAE,CAAC;gBAAC,CAAC;gBAC9C,IAAI,GAAG,KAAK,SAAS,IAAI,OAAO,EAAE,EAAE,CAAC;oBACnC,QAAQ,CAAC,cAAc,EAAE,CAAC;oBAC1B,GAAG,EAAE,CAAC;oBACN,QAAQ,GAAG,UAAU,CAAC,GAAG,EAAE,GAAG,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,WAAW,EAAE,CAAC,CAAC;gBACnE,CAAC;qBAAM,CAAC;oBACN,QAAQ,CAAC,IAAI,EAAE,CAAC;gBAClB,CAAC;YACH,CAAC;YACD,MAAM,IAAI,GAAG,MAAM,MAAM,CAAC;YAC1B,OAAO,IAAI,CAAC;QACd,CAAC;KACF,CAAC;AACJ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@botiverse/oar",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.101.0",
|
|
4
4
|
"description": "A programming interface for all agent harnesses: provider-independent contracts for controlling and observing agent runtimes",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -51,6 +51,10 @@
|
|
|
51
51
|
"types": "./dist/pi-durable.d.ts",
|
|
52
52
|
"import": "./dist/pi-durable.js"
|
|
53
53
|
},
|
|
54
|
+
"./runtimes/codex/installation-candidates": {
|
|
55
|
+
"types": "./dist/runtimes/codex/installation-candidates.d.ts",
|
|
56
|
+
"import": "./dist/runtimes/codex/installation-candidates.js"
|
|
57
|
+
},
|
|
54
58
|
"./runtimes/*": {
|
|
55
59
|
"types": "./dist/runtimes/*/index.d.ts",
|
|
56
60
|
"import": "./dist/runtimes/*/index.js"
|