@parcha/agentrun-computer 0.1.0-beta.40 → 0.1.0-beta.41
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 +31 -14
- package/box/Dockerfile +6 -4
- package/box/README.md +8 -0
- package/box/build-daytona.py +3 -1
- package/box/install.sh +68 -7
- package/dist/attach.d.ts +46 -1
- package/dist/attach.js +48 -4
- package/dist/box-image.d.ts +2 -0
- package/dist/box-image.js +10 -0
- package/dist/computerd-linux-amd64 +0 -0
- package/dist/computerd-linux-arm64 +0 -0
- package/dist/computerd.json +2 -2
- package/dist/conformance/cases/provider.js +42 -26
- package/dist/conformance/cli.js +4 -1
- package/dist/conformance/daytona.d.ts +25 -0
- package/dist/conformance/daytona.js +26 -1
- package/dist/conformance/exec-stream.js +14 -6
- package/dist/conformance/runner.js +8 -4
- package/dist/conformance/sweep.d.ts +7 -2
- package/dist/conformance/sweep.js +17 -7
- package/dist/conformance/types.d.ts +21 -0
- package/dist/daytona.d.ts +8 -1
- package/dist/daytona.js +124 -101
- package/dist/descriptor.d.ts +22 -1
- package/dist/descriptor.js +18 -0
- package/dist/descriptors/daytona.d.ts +12 -3
- package/dist/descriptors/daytona.js +15 -7
- package/dist/descriptors/index.d.ts +8 -1
- package/dist/e2b.js +1 -1
- package/dist/host.d.ts +61 -37
- package/dist/hosted/framed-exec.d.ts +8 -19
- package/dist/hosted/framed-exec.js +21 -87
- package/dist/hosted/process.d.ts +2 -0
- package/dist/hosted/process.js +9 -2
- package/dist/hosted/provider.d.ts +41 -4
- package/dist/hosted/provider.js +289 -115
- package/dist/hosted/rest.d.ts +19 -0
- package/dist/hosted/rest.js +76 -0
- package/dist/hosted/scripts.d.ts +50 -0
- package/dist/hosted/scripts.js +116 -1
- package/dist/hosted/ssh-exec.d.ts +7 -6
- package/dist/hosted/ssh-exec.js +35 -52
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/kinds.d.ts +2 -0
- package/dist/modal.js +21 -8
- package/dist/providers.d.ts +4 -2
- package/package.json +1 -1
package/dist/host.d.ts
CHANGED
|
@@ -29,7 +29,12 @@ export interface MachineHost {
|
|
|
29
29
|
create(req: MachineRequest, ctx: HostCall): Promise<{
|
|
30
30
|
id: string;
|
|
31
31
|
}>;
|
|
32
|
-
/**
|
|
32
|
+
/**
|
|
33
|
+
* One machine as the vendor reads it now; undefined once the vendor no longer has it (not found is that, or a
|
|
34
|
+
* HostError not_found), and for a record the vendor keeps of a machine that is deleted and will not come back
|
|
35
|
+
* (Hyperbrowser's closed, Blaxel's TERMINATED), which list leaves out too. gone is one still being destroyed: it holds
|
|
36
|
+
* the wait after a delete, so a host that reads a kept record gone waits out goneMs on every delete.
|
|
37
|
+
*/
|
|
33
38
|
get(id: string, ctx: HostCall): Promise<Machine | undefined>;
|
|
34
39
|
/**
|
|
35
40
|
* The machines of the account the vendor's listing shows for these labels, every page, within ctx.timeoutMs in all.
|
|
@@ -39,7 +44,9 @@ export interface MachineHost {
|
|
|
39
44
|
* none): the adapter keeps those whose get does. A listing may lag a create: two creates of one request on two
|
|
40
45
|
* provider instances can then both make a machine, and the adapter deletes every one but the oldest (createdAt), so
|
|
41
46
|
* a vendor may see a second create deleted. With facts.labels "machine" it lists by req.name where the vendor lists by
|
|
42
|
-
* name, else every machine: the adapter keeps those of the name
|
|
47
|
+
* name, else every machine: the adapter keeps those of the name and of our image (Machine.image), then reads each
|
|
48
|
+
* one's labels from inside it; one whose read fails or does not end is left out of that listing, in words, except
|
|
49
|
+
* from a listing by a request's name, which that read fails.
|
|
43
50
|
*/
|
|
44
51
|
list(labels: Record<string, string>, ctx: HostCall): Promise<Machine[]>;
|
|
45
52
|
/**
|
|
@@ -57,7 +64,10 @@ export interface MachineHost {
|
|
|
57
64
|
* the process writes them, while it runs. Not request and response, never held until the process exits.
|
|
58
65
|
* - Text intact. UTF-8 text both ways, every code point as it was: long lines, \r and \r\n kept (no terminal, no
|
|
59
66
|
* newline translation), nothing added or dropped. Everything the adapter sends or reads is text (the bridge's JSON
|
|
60
|
-
* lines, its upload in base64), and each write() holds whole characters. An exec that carries bytes carries this.
|
|
67
|
+
* lines, its upload in base64), and each write() holds whole characters. An exec that carries bytes carries this. A
|
|
68
|
+
* vendor whose input call ends what it is given with a newline (Daytona's) holds a write's last partial line until
|
|
69
|
+
* its newline or end(), so the process reads its stdin as written: the bridge's lines end in one, and what is
|
|
70
|
+
* read by length is followed by end().
|
|
61
71
|
* - No timeout. The process runs until it exits or kill() ends it: a vendor's command timeout, and any idle timeout
|
|
62
72
|
* on the stream, are off.
|
|
63
73
|
* - stdout and stderr stay apart. wait() answers the process's own exit code. kill() ends the process in the
|
|
@@ -65,10 +75,13 @@ export interface MachineHost {
|
|
|
65
75
|
* end() ends stdin where the vendor can (the adapter calls it at once for a command it gives no input); where it
|
|
66
76
|
* can't, end() does nothing, and nothing the adapter runs waits for it: its upload and its label file's write read a
|
|
67
77
|
* length, a root command's input is one line, its bridge ends by kill(). A vendor whose exec comes in pieces (a start, an event stream, a call per write, no end or no kill) builds
|
|
68
|
-
* this from them with framedExec (./hosted/framed-exec.ts). The exec pre-check (conformance --exec-stream,
|
|
78
|
+
* this from them with framedExec (./hosted/framed-exec.ts), as Daytona's does. The exec pre-check (conformance --exec-stream,
|
|
69
79
|
* src/conformance/exec-stream.ts) checks each of these on a machine made by hand, with exec alone.
|
|
80
|
+
*
|
|
81
|
+
* Every host has it but one whose facts.connect is "dial", which has none (and no upload): its machine's computerd
|
|
82
|
+
* dials the server instead.
|
|
70
83
|
*/
|
|
71
|
-
exec(id: string, argv: readonly string[], ctx: HostCall): Promise<MachineProcess>;
|
|
84
|
+
exec?(id: string, argv: readonly string[], ctx: HostCall): Promise<MachineProcess>;
|
|
72
85
|
/**
|
|
73
86
|
* Puts bytes at path in the machine, as root. Optional: a vendor with no file API leaves it out, and the adapter
|
|
74
87
|
* streams the file through exec's stdin as base64 text, which root decodes (`base64 -d`, in coreutils and busybox).
|
|
@@ -85,16 +98,10 @@ export interface MachineHost {
|
|
|
85
98
|
* vendor's own timer (facts.lifetime "vendor"), or the janitor's deadline label (facts.lifetime "janitor"). A refusal
|
|
86
99
|
* (a HostError limit, in words) when no end the vendor takes lands there without moving it earlier than it is or past
|
|
87
100
|
* the most: nothing moves then. The adapter reads the end back with get (deadlineOf, the deadline label: a vendor that
|
|
88
|
-
* keeps no label change reads its moved timer as that label), and init's deadline follows it.
|
|
89
|
-
*
|
|
101
|
+
* keeps no label change reads its moved timer as that label), and init's deadline follows it. Optional: a host without
|
|
102
|
+
* it has no extend, and a host with facts.labels "machine" is refused one.
|
|
90
103
|
*/
|
|
91
104
|
extend?(id: string, endsAt: Date, ctx: HostCall): Promise<void>;
|
|
92
|
-
/**
|
|
93
|
-
* The vendor's cheapest call that restarts its idle timer (facts.idleMs) on the machine: Cube's or E2B's setTimeout,
|
|
94
|
-
* Railway's heartbeat. The adapter calls it every idleMs / 3 from create, or attach, until release; one that fails is
|
|
95
|
-
* told through onNote and the next one tries again. Required with facts.idleMs; a host with no idle timer leaves it out.
|
|
96
|
-
*/
|
|
97
|
-
keepalive?(id: string, ctx: HostCall): Promise<void>;
|
|
98
105
|
/**
|
|
99
106
|
* The vendor's own rules of a spec, over the adapter's shared ones: an image name it takes, a GPU's image. No call. The
|
|
100
107
|
* spec is an object, as the caller gave it: its fields are not checked yet (an image may be a number).
|
|
@@ -131,14 +138,15 @@ export interface MachineRequest {
|
|
|
131
138
|
lifetimeMs: number;
|
|
132
139
|
/**
|
|
133
140
|
* An ISO time a margin past the most the machine's deadline may reach: create + maxLifetimeMs + BACKSTOP_MARGIN_MS. A
|
|
134
|
-
* janitor's host whose vendor has a delete or stop timer of its own sets it here
|
|
135
|
-
*
|
|
141
|
+
* janitor's host whose vendor has a delete or stop timer of its own sets it here, so the machine still ends when the
|
|
142
|
+
* server that made it is gone. A vendor-lifetime host ignores it.
|
|
136
143
|
*/
|
|
137
144
|
backstopAt: string;
|
|
138
145
|
/**
|
|
139
146
|
* Whether the machine reaches out: true for an Archil computer's root, which reaches Archil, and for a network open
|
|
140
|
-
* or a list, whose egress proxy init starts outside its tools' network (./hosted/network.ts)
|
|
141
|
-
*
|
|
147
|
+
* or a list, whose egress proxy init starts outside its tools' network (./hosted/network.ts), and for every dial
|
|
148
|
+
* machine (boot), which fetches its daemon from the server and dials it. Its tools' own network is init's, loopback
|
|
149
|
+
* alone, read from inside, either way.
|
|
142
150
|
*/
|
|
143
151
|
egress: boolean;
|
|
144
152
|
/** facts.daemon "pid1" alone: the machine's main process (the entrypoint that waits for the daemon, then becomes init). */
|
|
@@ -149,6 +157,15 @@ export interface MachineRequest {
|
|
|
149
157
|
memoryMb?: number;
|
|
150
158
|
/** With facts.user: the spec's user, uid:gid. */
|
|
151
159
|
user?: string;
|
|
160
|
+
/**
|
|
161
|
+
* facts.connect "dial" alone: what the machine's environment holds, every name and value as given, in the vendor's
|
|
162
|
+
* secret-env field where it has one. The box image's agentrun-dial reads it (spec/computer/attach.md, Hosted machines
|
|
163
|
+
* that dial): AGENTRUN_ATTACH_URL, AGENTRUN_ATTACH_TOKEN, AGENTRUN_DAEMON_URL, AGENTRUN_DAEMON_SHA256 and
|
|
164
|
+
* AGENTRUN_INIT_ARGS.
|
|
165
|
+
*/
|
|
166
|
+
boot?: {
|
|
167
|
+
env: Record<string, string>;
|
|
168
|
+
};
|
|
152
169
|
}
|
|
153
170
|
/**
|
|
154
171
|
* One machine as the vendor reads it back. The adapter holds the rest itself: what create asked is in the labels, what
|
|
@@ -163,12 +180,18 @@ export interface Machine {
|
|
|
163
180
|
* keeps one. A machine of a request's name whose labels are not written yet is the request's (provider.md).
|
|
164
181
|
*/
|
|
165
182
|
name?: string;
|
|
183
|
+
/**
|
|
184
|
+
* The image the vendor reads back for this machine. Required in practice with facts.labels "machine": list runs the
|
|
185
|
+
* label read only in a machine of the provider's image option or a box image (isBoxImage), and leaves one with none
|
|
186
|
+
* out, in words.
|
|
187
|
+
*/
|
|
188
|
+
image?: string;
|
|
166
189
|
/**
|
|
167
190
|
* starting: not yet running; stopped: there, not running, and not being deleted (paused, asleep): listed, so the
|
|
168
191
|
* janitor still ends it; gone: being deleted, ended, or failed (why says how).
|
|
169
192
|
*/
|
|
170
193
|
state: "starting" | "running" | "stopped" | "gone";
|
|
171
|
-
/** With facts.lifetime "vendor"
|
|
194
|
+
/** With facts.lifetime "vendor": when the vendor's timer ends it. */
|
|
172
195
|
endsAt?: Date;
|
|
173
196
|
/**
|
|
174
197
|
* When the vendor made it, by its clock, where it says. Two creates of one request on two provider instances can each
|
|
@@ -202,26 +225,17 @@ export type HostDescriptor = Pick<ProviderDescriptor, "id" | "label" | "network"
|
|
|
202
225
|
*/
|
|
203
226
|
export interface HostFacts {
|
|
204
227
|
/**
|
|
205
|
-
* child: the vendor
|
|
206
|
-
* buses in /tmp (/tmp/dbus-*) to the computer's user, since a network namespace does not cut a
|
|
207
|
-
* init is the machine's main process (Modal's, whose sandbox ends when it does), started by
|
|
228
|
+
* child: the vendor starts the adapter's processes through exec, and the adapter starts init that way at boot, after
|
|
229
|
+
* it closes the session buses in /tmp (/tmp/dbus-*) to the computer's user, since a network namespace does not cut a
|
|
230
|
+
* path socket. pid1: init is the machine's main process (Modal's, whose sandbox ends when it does), started by
|
|
231
|
+
* request.command.
|
|
208
232
|
*/
|
|
209
233
|
daemon: "child" | "pid1";
|
|
210
234
|
isolation: ComputerCapabilities["isolation"];
|
|
211
235
|
/** Who ends a machine at its deadline: the vendor's timer, or the janitor by label. */
|
|
212
236
|
lifetime: "vendor" | "janitor";
|
|
213
|
-
/**
|
|
214
|
-
* A janitor's host claims its create sets the vendor's own delete or stop timer from req.backstopAt, and get reads it
|
|
215
|
-
* back as endsAt (the Core case provider.backstop checks it). Only this lets a janitor's host keep labels "machine".
|
|
216
|
-
*/
|
|
217
|
-
backstop?: true;
|
|
218
237
|
/** The vendor's hard cap of a machine's life; the adapter's maxLifetimeMs may only lower it. */
|
|
219
238
|
maxLifetimeMs: number;
|
|
220
|
-
/**
|
|
221
|
-
* Where the vendor ends or pauses a machine no call reaches for a while (an idle timer that can't be switched off): that
|
|
222
|
-
* window, in whole ms. The adapter then calls keepalive every idleMs / 3 while it holds the machine. Default none.
|
|
223
|
-
*/
|
|
224
|
-
idleMs?: number;
|
|
225
239
|
arch: "amd64" | "arm64";
|
|
226
240
|
/** The TCP ports the vendor's own agent listens on inside the machine (E2B's envd 49983). */
|
|
227
241
|
vendorAgentPorts: number[];
|
|
@@ -232,12 +246,14 @@ export interface HostFacts {
|
|
|
232
246
|
/**
|
|
233
247
|
* The most a machine's labels may be, the adapter's own with the caller's: count, how many; bytes, every name and
|
|
234
248
|
* value together, the adapter's at their longest. Past either, check() refuses, and so create, before any host call.
|
|
235
|
-
* Absent: no bound. packed: the
|
|
236
|
-
* list by, the map in parts of at most valueBytes each)
|
|
237
|
-
*
|
|
238
|
-
* the
|
|
239
|
-
* JSON, what a run's output
|
|
240
|
-
* lifetime "vendor"
|
|
249
|
+
* Absent: no bound. packed: the adapter packs the labels it gives create (packLabels, ./hosted/values.ts: one name to
|
|
250
|
+
* list by, the map in parts of at most valueBytes each), unpacks those get and list answer, and asks list for that
|
|
251
|
+
* name alone; the host stores and answers them as they are. count and bytes are then the packed labels'. "machine":
|
|
252
|
+
* the vendor keeps no labels, so the adapter writes them as JSON to a root-only file in the machine (LABEL_FILE,
|
|
253
|
+
* ./hosted/scripts.ts) right after it runs, and reads them back from it: at most 64 KiB as JSON, what a run's output
|
|
254
|
+
* keeps (OUTPUT_MAX, ./hosted/process.ts). Only with lifetime "vendor", since a machine whose labels were never
|
|
255
|
+
* written is ended by the vendor's timer alone, and no extend. get and list answer each machine's image
|
|
256
|
+
* (Machine.image): the labels are read only in one of ours.
|
|
241
257
|
*/
|
|
242
258
|
labels?: {
|
|
243
259
|
count?: number;
|
|
@@ -252,4 +268,12 @@ export interface HostFacts {
|
|
|
252
268
|
* directory, before the daemon's upload, so the computer's user can change nothing root runs. Default none.
|
|
253
269
|
*/
|
|
254
270
|
rootOnly?: readonly string[];
|
|
271
|
+
/**
|
|
272
|
+
* dial: the machine's computerd dials the server, and the host has no exec and no upload. The vendor boots the box
|
|
273
|
+
* image with MachineRequest.boot.env, where agentrun-dial fetches the server's daemon, checks its sha256, starts init
|
|
274
|
+
* and dials the attach route with the machine's own token; every connection goes over that socket
|
|
275
|
+
* (HostedOptions.dial). Not with labels "machine", which are read through exec. Absent: the adapter connects through
|
|
276
|
+
* exec.
|
|
277
|
+
*/
|
|
278
|
+
connect?: "dial";
|
|
255
279
|
}
|
|
@@ -13,7 +13,11 @@ export type FramedEvent = {
|
|
|
13
13
|
export interface ExecPieces<P> {
|
|
14
14
|
/** Starts argv in the machine as root, within ctx, and answers once it has started. */
|
|
15
15
|
start(argv: readonly string[], ctx: HostCall): Promise<P>;
|
|
16
|
-
/**
|
|
16
|
+
/**
|
|
17
|
+
* The process's events from its start, in order; an end with no exit event is an exit the vendor never read (-1),
|
|
18
|
+
* and one that throws fails wait() with its error. framedExec stops reading at the exit event, which returns the
|
|
19
|
+
* iterator: a generator's finally lets go of what it holds.
|
|
20
|
+
*/
|
|
17
21
|
events(handle: P): AsyncIterable<FramedEvent>;
|
|
18
22
|
/** One call that hands text to the process's stdin, answered once the vendor took it. */
|
|
19
23
|
write(handle: P, text: string): Promise<void>;
|
|
@@ -24,26 +28,11 @@ export interface ExecPieces<P> {
|
|
|
24
28
|
*/
|
|
25
29
|
end?(handle: P): Promise<void>;
|
|
26
30
|
/**
|
|
27
|
-
* Ends the process in the machine. Leave it out where the vendor has none: the process then starts under
|
|
28
|
-
* writes its pid and its start time on stderr first (framedExec
|
|
29
|
-
* starts
|
|
31
|
+
* Ends the process in the machine. Leave it out where the vendor has none: the process then starts under
|
|
32
|
+
* PID_WRAPPER (./scripts.ts), which writes its pid and its start time on stderr first (framedExec takes that line off),
|
|
33
|
+
* and kill() starts pidKill, which kills that pid, and every process under it, only while that pid has that start time.
|
|
30
34
|
*/
|
|
31
35
|
kill?(handle: P): Promise<void>;
|
|
32
36
|
}
|
|
33
|
-
/**
|
|
34
|
-
* The sh a process starts under when the vendor has no kill: one line on stderr, its pid and its start time (field 22
|
|
35
|
-
* of /proc/<pid>/stat, counted past the command's name in parentheses, which may hold spaces), then the command in its
|
|
36
|
-
* place, which keeps both.
|
|
37
|
-
*/
|
|
38
|
-
export declare const PID_WRAPPER: string[];
|
|
39
|
-
/**
|
|
40
|
-
* The sh kill() starts, given the pid and start time: a pid whose process has ended, and may be another's now, is let
|
|
41
|
-
* be. Otherwise it kills the process and every process under it (an upload's head and base64 would wait on the open
|
|
42
|
-
* stdin, and hold stderr open, past their sh): each is stopped as it is found, so none forks away, by its parent pid
|
|
43
|
-
* (field 4 of its stat) until a pass over /proc finds no more, and then all are killed.
|
|
44
|
-
*/
|
|
45
|
-
export declare const PID_KILL: string;
|
|
46
37
|
/** argv started through a vendor's pieces, as the MachineProcess exec answers. */
|
|
47
38
|
export declare function framedExec<P>(pieces: ExecPieces<P>, argv: readonly string[], ctx: HostCall): Promise<MachineProcess>;
|
|
48
|
-
/** The JSON value of each line of a body of newline-delimited JSON, as the lines come; a line that is not JSON throws. */
|
|
49
|
-
export declare function ndjson(body: AsyncIterable<Uint8Array>): AsyncIterable<unknown>;
|
|
@@ -5,42 +5,13 @@
|
|
|
5
5
|
// bytes, its events read no faster than the caller reads it; and a vendor with no kill gets one by pid. PROVIDERS.md, "Exec shapes that work", has a worked example.
|
|
6
6
|
import { once } from "node:events";
|
|
7
7
|
import { PassThrough } from "node:stream";
|
|
8
|
-
|
|
9
|
-
* The sh a process starts under when the vendor has no kill: one line on stderr, its pid and its start time (field 22
|
|
10
|
-
* of /proc/<pid>/stat, counted past the command's name in parentheses, which may hold spaces), then the command in its
|
|
11
|
-
* place, which keeps both.
|
|
12
|
-
*/
|
|
13
|
-
export const PID_WRAPPER = ["sh", "-c", 'echo "$$ $(s=$(cat /proc/$$/stat) && set -- ${s##*") "} && echo "${20}")" >&2; exec "$@"', "sh"];
|
|
14
|
-
/**
|
|
15
|
-
* The sh kill() starts, given the pid and start time: a pid whose process has ended, and may be another's now, is let
|
|
16
|
-
* be. Otherwise it kills the process and every process under it (an upload's head and base64 would wait on the open
|
|
17
|
-
* stdin, and hold stderr open, past their sh): each is stopped as it is found, so none forks away, by its parent pid
|
|
18
|
-
* (field 4 of its stat) until a pass over /proc finds no more, and then all are killed.
|
|
19
|
-
*/
|
|
20
|
-
export const PID_KILL = [
|
|
21
|
-
"pid=$1 start=$2",
|
|
22
|
-
'read -r s 2>/dev/null <"/proc/$pid/stat" || exit 0',
|
|
23
|
-
'set -- ${s##*") "}',
|
|
24
|
-
'[ "${20}" = "$start" ] || exit 0',
|
|
25
|
-
'kill -STOP "$pid" 2>/dev/null',
|
|
26
|
-
'all=" $pid " new=$pid',
|
|
27
|
-
'while [ -n "$new" ]; do',
|
|
28
|
-
"\tnew=",
|
|
29
|
-
"\tfor f in /proc/[0-9]*/stat; do",
|
|
30
|
-
'\t\tread -r s 2>/dev/null <"$f" || continue',
|
|
31
|
-
"\t\tp=${s%% *}",
|
|
32
|
-
'\t\tset -- ${s##*") "}',
|
|
33
|
-
'\t\tcase "$all" in *" $p "*) continue ;; esac',
|
|
34
|
-
'\t\tcase "$all" in *" $2 "*) all="$all$p " new="$new $p"; kill -STOP "$p" 2>/dev/null ;; esac',
|
|
35
|
-
"\tdone",
|
|
36
|
-
"done",
|
|
37
|
-
"kill -KILL $all 2>/dev/null",
|
|
38
|
-
"exit 0",
|
|
39
|
-
].join("\n");
|
|
8
|
+
import { PID_WRAPPER, pidKill, pidLine } from "./scripts.js";
|
|
40
9
|
/** argv started through a vendor's pieces, as the MachineProcess exec answers. */
|
|
41
10
|
export async function framedExec(pieces, argv, ctx) {
|
|
42
|
-
|
|
43
|
-
|
|
11
|
+
// With no vendor kill, stderr's first line is the pid and its start time (./scripts.ts, PID_WRAPPER): taken off, and
|
|
12
|
+
// the rest is the process's own.
|
|
13
|
+
const line = pieces.kill === undefined ? pidLine() : undefined;
|
|
14
|
+
const handle = await pieces.start(line ? [...PID_WRAPPER, ...argv] : argv, ctx);
|
|
44
15
|
const stdout = new PassThrough();
|
|
45
16
|
const stderr = new PassThrough();
|
|
46
17
|
// ended: the events stopped, so output and writes are done with. exitRead: the process's own exit came among them; a
|
|
@@ -61,26 +32,14 @@ export async function framedExec(pieces, argv, ctx) {
|
|
|
61
32
|
await Promise.race([once(stream, "drain", { signal }), once(stream, "close", { signal })]).catch(() => { });
|
|
62
33
|
waited.abort();
|
|
63
34
|
};
|
|
64
|
-
// With no vendor kill, stderr's first line is the pid and its start time: held until it ends, then the rest is the
|
|
65
|
-
// process's own.
|
|
66
|
-
let pidLine = byPid ? Buffer.alloc(0) : undefined;
|
|
67
|
-
let gotPid = () => { };
|
|
68
|
-
const pid = new Promise((done) => (gotPid = done));
|
|
69
35
|
const toStderr = async (bytes) => {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
const at = pidLine.indexOf(0x0a);
|
|
74
|
-
if (at < 0)
|
|
75
|
-
return;
|
|
76
|
-
gotPid(pidLine.subarray(0, at).toString("latin1").trim());
|
|
77
|
-
const rest = pidLine.subarray(at + 1);
|
|
78
|
-
pidLine = undefined;
|
|
79
|
-
if (rest.length > 0)
|
|
80
|
-
await push(stderr, rest);
|
|
36
|
+
const own = line ? line.take(bytes) : bytes;
|
|
37
|
+
if (own.length > 0)
|
|
38
|
+
await push(stderr, own);
|
|
81
39
|
};
|
|
82
40
|
const exited = (async () => {
|
|
83
41
|
let code = -1;
|
|
42
|
+
let broke;
|
|
84
43
|
try {
|
|
85
44
|
for await (const event of pieces.events(handle)) {
|
|
86
45
|
if ("exit" in event) {
|
|
@@ -95,15 +54,20 @@ export async function framedExec(pieces, argv, ctx) {
|
|
|
95
54
|
await toStderr(bytes);
|
|
96
55
|
}
|
|
97
56
|
}
|
|
98
|
-
catch {
|
|
99
|
-
// A stream that broke: no exit code was read.
|
|
57
|
+
catch (error) {
|
|
58
|
+
// A stream that broke: no exit code was read, and wait() fails in its words.
|
|
59
|
+
broke = error;
|
|
100
60
|
}
|
|
101
61
|
ended = true;
|
|
102
|
-
|
|
62
|
+
line?.end();
|
|
103
63
|
stdout.end();
|
|
104
64
|
stderr.end();
|
|
65
|
+
if (broke !== undefined)
|
|
66
|
+
throw broke;
|
|
105
67
|
return code;
|
|
106
68
|
})();
|
|
69
|
+
// Nobody may wait (the bridge ends by kill): a broken stream is then no unhandled rejection.
|
|
70
|
+
exited.catch(() => { });
|
|
107
71
|
// The writes as one queue: each call starts once the one before it answered, and one that failed fails every one after.
|
|
108
72
|
// ignoreBOM: a U+FEFF that starts stdin is text like any other, never a mark to drop.
|
|
109
73
|
const decoder = new TextDecoder("utf-8", { ignoreBOM: true });
|
|
@@ -116,17 +80,6 @@ export async function framedExec(pieces, argv, ctx) {
|
|
|
116
80
|
queue = sent;
|
|
117
81
|
return sent;
|
|
118
82
|
};
|
|
119
|
-
/** "<pid> <start time>", once stderr's first line gives it; undefined once the process ended, or past ctx's bound. */
|
|
120
|
-
const pidWithin = async () => {
|
|
121
|
-
let timer;
|
|
122
|
-
const late = new Promise((done) => (timer = setTimeout(() => done(undefined), ctx.timeoutMs)));
|
|
123
|
-
try {
|
|
124
|
-
return await Promise.race([pid, late]);
|
|
125
|
-
}
|
|
126
|
-
finally {
|
|
127
|
-
clearTimeout(timer);
|
|
128
|
-
}
|
|
129
|
-
};
|
|
130
83
|
return {
|
|
131
84
|
stdout,
|
|
132
85
|
stderr,
|
|
@@ -144,12 +97,12 @@ export async function framedExec(pieces, argv, ctx) {
|
|
|
144
97
|
try {
|
|
145
98
|
if (pieces.kill)
|
|
146
99
|
await pieces.kill(handle);
|
|
147
|
-
else {
|
|
100
|
+
else if (line) {
|
|
148
101
|
// Not once its exit was read; and after a stream that broke, only while the pid still has its start time: by
|
|
149
102
|
// then the pid may be another process's.
|
|
150
|
-
const target =
|
|
151
|
-
if (target !==
|
|
152
|
-
const killer = await pieces.start(
|
|
103
|
+
const target = await line.pid(ctx.timeoutMs);
|
|
104
|
+
if (target !== undefined && !exitRead) {
|
|
105
|
+
const killer = await pieces.start(pidKill(target), { timeoutMs: ctx.timeoutMs });
|
|
153
106
|
for await (const event of pieces.events(killer))
|
|
154
107
|
if ("exit" in event)
|
|
155
108
|
break;
|
|
@@ -164,22 +117,3 @@ export async function framedExec(pieces, argv, ctx) {
|
|
|
164
117
|
},
|
|
165
118
|
};
|
|
166
119
|
}
|
|
167
|
-
/** The JSON value of each line of a body of newline-delimited JSON, as the lines come; a line that is not JSON throws. */
|
|
168
|
-
export async function* ndjson(body) {
|
|
169
|
-
const decoder = new TextDecoder();
|
|
170
|
-
let rest = "";
|
|
171
|
-
for await (const chunk of body) {
|
|
172
|
-
rest += decoder.decode(chunk, { stream: true });
|
|
173
|
-
let at = rest.indexOf("\n");
|
|
174
|
-
while (at >= 0) {
|
|
175
|
-
const line = rest.slice(0, at).trim();
|
|
176
|
-
rest = rest.slice(at + 1);
|
|
177
|
-
if (line !== "")
|
|
178
|
-
yield JSON.parse(line);
|
|
179
|
-
at = rest.indexOf("\n");
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
rest += decoder.decode();
|
|
183
|
-
if (rest.trim() !== "")
|
|
184
|
-
yield JSON.parse(rest);
|
|
185
|
-
}
|
package/dist/hosted/process.d.ts
CHANGED
|
@@ -2,6 +2,8 @@ import { type HostCall, type MachineHost } from "../host.js";
|
|
|
2
2
|
import type { ArchilRoot } from "../mount-archil.js";
|
|
3
3
|
import type { ComputerConnection } from "../provider.js";
|
|
4
4
|
import { type ComputerErrorCode, type Result } from "../result.js";
|
|
5
|
+
/** The host's exec; a dial host has none, and a call of it throws unsupported, in words. */
|
|
6
|
+
export declare function execOf(host: MachineHost): NonNullable<MachineHost["exec"]>;
|
|
5
7
|
/** What a call's race adds to the bound it gives the vendor's own call, so the vendor's timeout, not the race, reports a slow call. */
|
|
6
8
|
export declare const CALL_SLACK_MS = 5000;
|
|
7
9
|
export declare const seconds: (ms: number) => string;
|
package/dist/hosted/process.js
CHANGED
|
@@ -5,6 +5,13 @@ import { PassThrough, Writable } from "node:stream";
|
|
|
5
5
|
import { DaemonClient } from "../client.js";
|
|
6
6
|
import { HostError } from "../host.js";
|
|
7
7
|
import { failFor, ok } from "../result.js";
|
|
8
|
+
/** The host's exec; a dial host has none, and a call of it throws unsupported, in words. */
|
|
9
|
+
export function execOf(host) {
|
|
10
|
+
return (host.exec?.bind(host) ??
|
|
11
|
+
(() => {
|
|
12
|
+
throw new HostError("unsupported", `${host.descriptor.label}'s machines have no exec: they dial this server (facts.connect "dial")`);
|
|
13
|
+
}));
|
|
14
|
+
}
|
|
8
15
|
/** What a call's race adds to the bound it gives the vendor's own call, so the vendor's timeout, not the race, reports a slow call. */
|
|
9
16
|
export const CALL_SLACK_MS = 5_000;
|
|
10
17
|
export const seconds = (ms) => `${ms / 1000} s`;
|
|
@@ -147,7 +154,7 @@ export const OUTPUT_MAX = 64 * 1024;
|
|
|
147
154
|
*/
|
|
148
155
|
export async function runToExit(host, id, argv, { stdin, ms, signal, what }) {
|
|
149
156
|
const fail = failFor(host.descriptor.id);
|
|
150
|
-
const started = await hostCall(host, what, (ctx) => host
|
|
157
|
+
const started = await hostCall(host, what, (ctx) => execOf(host)(id, argv, ctx), ms, signal);
|
|
151
158
|
if (!started.ok)
|
|
152
159
|
return started;
|
|
153
160
|
const proc = started.value;
|
|
@@ -226,7 +233,7 @@ export async function openBridge(host, id, { argv, name, version, requestMs, hel
|
|
|
226
233
|
const fail = failFor(host.descriptor.id);
|
|
227
234
|
// Never signalled, only raced: the bridge lives on after this call. It has no command timeout, so one the vendor
|
|
228
235
|
// starts after this was given up on is killed as it lands.
|
|
229
|
-
const started = await hostCall(host, `starting the daemon's stdio bridge in ${name}`, (ctx) => host
|
|
236
|
+
const started = await hostCall(host, `starting the daemon's stdio bridge in ${name}`, (ctx) => execOf(host)(id, argv, { timeoutMs: ctx.timeoutMs }), requestMs, signal, (late) => late.ok && late.value.kill());
|
|
230
237
|
if (!started.ok) {
|
|
231
238
|
const { code, message } = started.error;
|
|
232
239
|
return code === "timeout" || code === "aborted" ? fail(code, `${message}; a bridge that starts after this is killed`) : started;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type AttachHub, type MachineTokens } from "../attach.js";
|
|
1
2
|
import { type DesktopOptions } from "../desktop.js";
|
|
2
3
|
import { type Machine, type MachineHost } from "../host.js";
|
|
3
4
|
import { type ProviderNote } from "../mount-archil.js";
|
|
@@ -65,6 +66,27 @@ export interface HostedOptions {
|
|
|
65
66
|
* Given to the helper's mount and revoke. Unset or empty, the client reaches Archil as the machine's network allows.
|
|
66
67
|
*/
|
|
67
68
|
archilEgress?: string;
|
|
69
|
+
/**
|
|
70
|
+
* The image this provider's computers start from, where its setting names one, exactly as the vendor reads it back
|
|
71
|
+
* (Machine.image). With facts.labels "machine", list reads labels only in a machine of this image or a box image
|
|
72
|
+
* (isBoxImage, ../box-image.ts), and check refuses a spec of any other.
|
|
73
|
+
*/
|
|
74
|
+
image?: string;
|
|
75
|
+
/** What a host whose facts.connect is "dial" needs: create refuses without it, before any call to the vendor. */
|
|
76
|
+
dial?: HostedDial;
|
|
77
|
+
}
|
|
78
|
+
/** The server a dial host's machines reach, and what it holds of them (MachineHost facts.connect "dial"). */
|
|
79
|
+
export interface HostedDial {
|
|
80
|
+
/**
|
|
81
|
+
* The server's public address, AGENTRUN_PUBLIC_URL: https://, which the vendor's machines must reach (http:// only on
|
|
82
|
+
* 127.0.0.1, for tests). They dial its /v2/computers/attach and fetch the daemon from its /v2/computers/daemon, which
|
|
83
|
+
* serves the build at this provider's daemonPath. Empty or unset: create refuses, in words.
|
|
84
|
+
*/
|
|
85
|
+
url?: string;
|
|
86
|
+
/** The server's machine tokens: one minted at each create, revoked at its delete. */
|
|
87
|
+
tokens: MachineTokens;
|
|
88
|
+
/** The server's AttachHub, which the server's attach route gives each minted machine's socket. */
|
|
89
|
+
hub: Pick<AttachHub, "online" | "connection" | "revoke">;
|
|
68
90
|
}
|
|
69
91
|
export declare const NAME_LABEL = "agentrun.computer.name";
|
|
70
92
|
/** The image create was asked for: a vendor may report another name for it (a template's id). */
|
|
@@ -75,6 +97,11 @@ export declare const MAX_LABEL = "agentrun.computer.max-deadline";
|
|
|
75
97
|
export declare const GPU_LABEL = "agentrun.computer.gpu";
|
|
76
98
|
/** The adapter's timeouts, the caller's over its defaults: what a host reads for its own requestMs or pollMs. */
|
|
77
99
|
export declare const timeoutsOf: (timeouts?: Partial<HostedTimeouts>) => HostedTimeouts;
|
|
100
|
+
/**
|
|
101
|
+
* The computerd build a hosted machine of arch runs: HostedProvider's default daemonPath, and the file serve's daemon
|
|
102
|
+
* route serves, so the sha256 a dial machine checks (AGENTRUN_DAEMON_SHA256) is this file's.
|
|
103
|
+
*/
|
|
104
|
+
export declare function hostedDaemonPath(arch: "amd64" | "arm64"): string;
|
|
78
105
|
/** An ISO time a label holds, or undefined when it is missing or not the ISO time create writes. */
|
|
79
106
|
export declare function isoOf(written: string | undefined): Date | undefined;
|
|
80
107
|
/**
|
|
@@ -144,17 +171,27 @@ export declare class HostedProvider implements ComputerProvider {
|
|
|
144
171
|
}
|
|
145
172
|
/**
|
|
146
173
|
* The host's listing by labels, bounded by ms: only the machines that carry every one of them, since a vendor's listing
|
|
147
|
-
* may answer more (MachineHost.list). A host
|
|
148
|
-
*
|
|
174
|
+
* may answer more (MachineHost.list). A packed host is asked for PACKED_NAME alone, the name's where one is asked, and
|
|
175
|
+
* its machines' labels unpacked. A host that keeps labels in the machine lists none: its machines of another name are
|
|
176
|
+
* left out, and the rest kept for foundBy to read.
|
|
149
177
|
*/
|
|
150
178
|
export declare function listedBy(host: MachineHost, what: string, labels: Record<string, string>, ms: number, signal?: AbortSignal): Promise<Result<Machine[]>>;
|
|
179
|
+
/** What foundBy reads with: the timeouts, who hears of a machine a listing leaves out, and the provider's image option. */
|
|
180
|
+
type Finding = Pick<HostedTimeouts, "listMs" | "requestMs"> & {
|
|
181
|
+
onNote?: ProviderNote | undefined;
|
|
182
|
+
image?: string | undefined;
|
|
183
|
+
};
|
|
151
184
|
/**
|
|
152
185
|
* The listing finds, get answers (MachineHost.list): the machines the host's listing by labels names, each read now by
|
|
153
186
|
* readMachine, within requestMs, and its label file where the host keeps labels in the machine. One the vendor no longer
|
|
154
187
|
* has (not found) is dropped, and so is one whose get carries not every label, but a machine of the name asked for whose
|
|
155
|
-
* labels are not written yet. A read that fails
|
|
188
|
+
* labels are not written yet. A label file's read that fails or does not end within requestMs leaves its machine out of
|
|
189
|
+
* this listing alone, told through onNote by its id: one wedged machine never holds up the rest. A listing by a
|
|
190
|
+
* request's name is the exception: what is left of it may be the request's own, so such a read fails it, as a get that
|
|
191
|
+
* fails fails the whole. The label file is read only in a machine whose listed image is ours (ourImage): another's is
|
|
192
|
+
* left out unread, and one that shows no image is left out in words.
|
|
156
193
|
*/
|
|
157
|
-
export declare function foundBy(host: MachineHost, what: string, labels: Record<string, string>, { listMs, requestMs }:
|
|
194
|
+
export declare function foundBy(host: MachineHost, what: string, labels: Record<string, string>, { listMs, requestMs, onNote, image }: Finding, signal?: AbortSignal): Promise<Result<Machine[]>>;
|
|
158
195
|
/**
|
|
159
196
|
* Waits, through waitUntil, until get answers none for a machine after its delete, twice running: the vendor no longer
|
|
160
197
|
* has it. A machine read gone is still going (a vendor still destroying it), so it holds the wait like any other state.
|