@parcha/agentrun-computer 0.1.0-beta.37 → 0.1.0-beta.39
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 +341 -260
- package/box/Dockerfile +18 -1
- package/box/README.md +14 -0
- package/box/build-daytona.py +2 -2
- package/box/build-e2b.mjs +41 -18
- package/box/recipe.d.mts +5 -0
- package/box/recipe.mjs +43 -0
- package/dist/agent37.d.ts +18 -66
- package/dist/agent37.js +187 -464
- package/dist/box-image.d.ts +14 -0
- package/dist/box-image.js +24 -0
- package/dist/browserbase.d.ts +0 -6
- package/dist/browserbase.js +1 -5
- package/dist/client.d.ts +12 -3
- package/dist/client.js +39 -4
- package/dist/computerd-linux-amd64 +0 -0
- package/dist/computerd-linux-arm64 +0 -0
- package/dist/computerd.json +4 -0
- package/dist/conformance/agent37.d.ts +9 -4
- package/dist/conformance/agent37.js +23 -11
- package/dist/conformance/browserbase.js +3 -3
- package/dist/conformance/cases/apps.d.ts +6 -0
- package/dist/conformance/cases/apps.js +18 -5
- package/dist/conformance/cases/isolation.d.ts +22 -5
- package/dist/conformance/cases/isolation.js +97 -16
- package/dist/conformance/cases/mount.js +5 -3
- package/dist/conformance/cases/provider.js +41 -0
- package/dist/conformance/cli.js +72 -11
- package/dist/conformance/daytona.d.ts +9 -20
- package/dist/conformance/daytona.js +12 -21
- package/dist/conformance/e2b.js +9 -4
- package/dist/conformance/exec-stream.d.ts +52 -0
- package/dist/conformance/exec-stream.js +493 -0
- package/dist/conformance/kernel.js +2 -2
- package/dist/conformance/modal.js +1 -1
- package/dist/conformance/orgo.js +2 -2
- package/dist/conformance/sweep.js +8 -8
- package/dist/conformance/types.d.ts +2 -2
- package/dist/create-requests.d.ts +1 -1
- package/dist/daytona.d.ts +17 -133
- package/dist/daytona.js +396 -1452
- package/dist/descriptor.d.ts +11 -4
- package/dist/descriptor.js +7 -0
- package/dist/descriptors/agent37.d.ts +3 -11
- package/dist/descriptors/agent37.js +9 -10
- package/dist/descriptors/daytona.d.ts +7 -6
- package/dist/descriptors/daytona.js +14 -7
- package/dist/descriptors/docker.d.ts +13 -1
- package/dist/descriptors/docker.js +3 -1
- package/dist/descriptors/e2b.d.ts +2 -9
- package/dist/descriptors/e2b.js +8 -8
- package/dist/descriptors/index.d.ts +25 -24
- package/dist/descriptors/index.js +1 -3
- package/dist/descriptors/modal.d.ts +2 -6
- package/dist/descriptors/modal.js +8 -6
- package/dist/descriptors/orgo.js +2 -1
- package/dist/descriptors/shared.d.ts +1 -1
- package/dist/descriptors/shared.js +2 -2
- package/dist/desktop.d.ts +18 -4
- package/dist/desktop.js +89 -9
- package/dist/docker/egress-main.js +23 -15
- package/dist/docker/egress.d.ts +6 -4
- package/dist/docker/egress.js +24 -16
- package/dist/docker/inspect.d.ts +2 -2
- package/dist/docker/inspect.js +5 -5
- package/dist/docker.d.ts +6 -11
- package/dist/docker.js +13 -16
- package/dist/drift.js +4 -4
- package/dist/e2b.d.ts +22 -130
- package/dist/e2b.js +163 -243
- package/dist/host.d.ts +136 -104
- package/dist/host.js +8 -1
- package/dist/hosted/network.d.ts +23 -0
- package/dist/hosted/network.js +77 -0
- package/dist/hosted/process.d.ts +24 -8
- package/dist/hosted/process.js +80 -44
- package/dist/hosted/provider.d.ts +38 -22
- package/dist/hosted/provider.js +500 -341
- package/dist/hosted/rest.d.ts +74 -0
- package/dist/hosted/rest.js +126 -0
- package/dist/hosted/scripts.d.ts +21 -3
- package/dist/hosted/scripts.js +76 -14
- package/dist/hosted/ssh-exec.d.ts +99 -0
- package/dist/hosted/ssh-exec.js +464 -0
- package/dist/hosted/values.d.ts +26 -0
- package/dist/hosted/values.js +63 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/isolation.d.ts +0 -2
- package/dist/isolation.js +3 -4
- package/dist/kernel.d.ts +0 -6
- package/dist/kernel.js +1 -5
- package/dist/kinds.d.ts +3 -1
- package/dist/local-chrome.d.ts +0 -6
- package/dist/local-chrome.js +1 -5
- package/dist/modal.d.ts +15 -86
- package/dist/modal.js +67 -185
- package/dist/mount-archil.d.ts +13 -8
- package/dist/mount-archil.js +27 -17
- package/dist/mount.d.ts +10 -4
- package/dist/mount.js +8 -4
- package/dist/orgo.d.ts +0 -9
- package/dist/orgo.js +8 -13
- package/dist/phone-harness.d.ts +0 -6
- package/dist/phone-harness.js +0 -4
- package/dist/protocol.d.ts +4 -1
- package/dist/protocol.js +1 -0
- package/dist/provider.d.ts +2 -2
- package/dist/providers.d.ts +15 -13
- package/dist/screen-watch.js +34 -6
- package/dist/surface/api.d.ts +14 -11
- package/dist/surface/core.d.ts +23 -5
- package/dist/surface/core.js +105 -15
- package/dist/surface/index.d.ts +1 -1
- package/dist/surface/index.js +1 -1
- package/dist/surface/outline.d.ts +2 -0
- package/dist/surface/outline.js +2 -1
- package/dist/surface/script.d.ts +4 -0
- package/dist/surface/script.js +11 -3
- package/dist/ui-engine.js +19 -3
- package/package.json +2 -3
- package/box/build-agent37.mjs +0 -177
- package/dist/conformance/daytona-sweep.d.ts +0 -18
- package/dist/conformance/daytona-sweep.js +0 -126
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { type ComputerErrorCode, type Result } from "../result.js";
|
|
2
|
+
/**
|
|
3
|
+
* A status as a code: 401 and 403 denied, 404 and 410 not found, 408 timeout, 402/429/507 limit, 400/409/422 invalid,
|
|
4
|
+
* else vendor; 409 is exists on a call that carries the machine's name (RestInit.named).
|
|
5
|
+
*/
|
|
6
|
+
export declare function httpCode(status: number, named?: boolean): ComputerErrorCode;
|
|
7
|
+
export interface RestAnswer {
|
|
8
|
+
status: number;
|
|
9
|
+
bytes: Uint8Array;
|
|
10
|
+
}
|
|
11
|
+
export interface RestInit {
|
|
12
|
+
json?: unknown;
|
|
13
|
+
form?: FormData;
|
|
14
|
+
timeoutMs?: number;
|
|
15
|
+
/**
|
|
16
|
+
* true: send again on no answer, 429 and 5xx (only for a call that may run twice). A function: send again only on an
|
|
17
|
+
* answer it says is a refusal that did not run the call, never on no answer or a timeout.
|
|
18
|
+
*/
|
|
19
|
+
retry?: boolean | ((status: number, bytes: Uint8Array) => boolean);
|
|
20
|
+
/** Whether an answer of this status is a value, with its status, not a failure (not retried). Default: a 2xx. */
|
|
21
|
+
accept?: (status: number) => boolean;
|
|
22
|
+
/**
|
|
23
|
+
* The call carries the machine's name (a create by MachineRequest.name): its 409 is the vendor's word that a machine
|
|
24
|
+
* has that name, exists, which the adapter reads as the machine its listing by the name finds.
|
|
25
|
+
*/
|
|
26
|
+
named?: boolean;
|
|
27
|
+
}
|
|
28
|
+
export interface RestOptions {
|
|
29
|
+
/** The API's root; trailing slashes are cut. `rest.url(path)` joins it. */
|
|
30
|
+
base: string;
|
|
31
|
+
/** The headers of every call (the key, Accept, a source tag). A body's Content-Type is added. */
|
|
32
|
+
headers: () => Record<string, string>;
|
|
33
|
+
/** The provider's id: names a failure of code vendor. */
|
|
34
|
+
vendor: string;
|
|
35
|
+
fetch?: typeof fetch;
|
|
36
|
+
/** The bound of a call that gives none. */
|
|
37
|
+
timeoutMs: number;
|
|
38
|
+
retry?: {
|
|
39
|
+
attempts: number;
|
|
40
|
+
baseMs: number;
|
|
41
|
+
pause?: (ms: number, signal?: AbortSignal) => Promise<void>;
|
|
42
|
+
};
|
|
43
|
+
/** The vendor's own code or words for an answer that is not accepted; what it leaves out is httpCode and `what: status text`. */
|
|
44
|
+
explain?: (answer: {
|
|
45
|
+
status: number;
|
|
46
|
+
bytes: Uint8Array;
|
|
47
|
+
text: string;
|
|
48
|
+
what: string;
|
|
49
|
+
}) => {
|
|
50
|
+
code?: ComputerErrorCode;
|
|
51
|
+
message?: string;
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
/** The JSON a body holds; null for none or for text that is not JSON. */
|
|
55
|
+
export declare function jsonOf(bytes: Uint8Array): unknown;
|
|
56
|
+
export interface Rest {
|
|
57
|
+
url(path: string): string;
|
|
58
|
+
call(method: string, url: string, init?: RestInit, signal?: AbortSignal): Promise<Result<RestAnswer>>;
|
|
59
|
+
/** call, with the body read as JSON (null for none). */
|
|
60
|
+
json(method: string, url: string, init?: RestInit, signal?: AbortSignal): Promise<Result<unknown>>;
|
|
61
|
+
}
|
|
62
|
+
export declare function rest(options: RestOptions): Rest;
|
|
63
|
+
/**
|
|
64
|
+
* Every item of a paged listing. next gets the cursor of the page to read (none for the first) and answers its items and
|
|
65
|
+
* the cursor of the page after it, or nothing at the end. A cursor that comes back twice, or a listing past max pages,
|
|
66
|
+
* is a failure: this provider would miss machines.
|
|
67
|
+
*/
|
|
68
|
+
export declare function allPages<T>(next: (cursor: string | undefined) => Promise<Result<{
|
|
69
|
+
items: T[];
|
|
70
|
+
next?: string;
|
|
71
|
+
}>>, max: number, of: {
|
|
72
|
+
vendor: string;
|
|
73
|
+
what: string;
|
|
74
|
+
}): Promise<Result<T[]>>;
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
// A vendor's REST API, once: fetch with the key in a header, JSON or form both ways, one bound, a retry rule the vendor
|
|
2
|
+
// chooses, and a failure that names the method, path and status and never a header. The status table and the
|
|
3
|
+
// cursor-page loop are here too, so a REST vendor writes only its own words and its own retry rule.
|
|
4
|
+
import { errorOf, fail, ok, vendorFail } from "../result.js";
|
|
5
|
+
import { pause } from "./process.js";
|
|
6
|
+
/**
|
|
7
|
+
* A status as a code: 401 and 403 denied, 404 and 410 not found, 408 timeout, 402/429/507 limit, 400/409/422 invalid,
|
|
8
|
+
* else vendor; 409 is exists on a call that carries the machine's name (RestInit.named).
|
|
9
|
+
*/
|
|
10
|
+
export function httpCode(status, named = false) {
|
|
11
|
+
if (status === 401 || status === 403)
|
|
12
|
+
return "denied";
|
|
13
|
+
if (status === 404 || status === 410)
|
|
14
|
+
return "not_found";
|
|
15
|
+
if (status === 408)
|
|
16
|
+
return "timeout";
|
|
17
|
+
if (status === 402 || status === 429 || status === 507)
|
|
18
|
+
return "limit";
|
|
19
|
+
if (status === 409)
|
|
20
|
+
return named ? "exists" : "invalid";
|
|
21
|
+
if (status === 400 || status === 422)
|
|
22
|
+
return "invalid";
|
|
23
|
+
return "vendor";
|
|
24
|
+
}
|
|
25
|
+
const decoder = new TextDecoder();
|
|
26
|
+
/** The JSON a body holds; null for none or for text that is not JSON. */
|
|
27
|
+
export function jsonOf(bytes) {
|
|
28
|
+
const text = decoder.decode(bytes);
|
|
29
|
+
if (text === "")
|
|
30
|
+
return null;
|
|
31
|
+
try {
|
|
32
|
+
return JSON.parse(text);
|
|
33
|
+
}
|
|
34
|
+
catch {
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
/** Whether fetch failed on a redirect it was told not to follow. */
|
|
39
|
+
function redirected(cause) {
|
|
40
|
+
const inner = cause?.cause;
|
|
41
|
+
return /redirect/i.test(`${cause?.message ?? ""} ${inner?.message ?? ""}`);
|
|
42
|
+
}
|
|
43
|
+
export function rest(options) {
|
|
44
|
+
const base = options.base.replace(/\/+$/, "");
|
|
45
|
+
const fetcher = options.fetch ?? fetch;
|
|
46
|
+
const wait = options.retry?.pause ?? pause;
|
|
47
|
+
async function call(method, url, init = {}, signal) {
|
|
48
|
+
const what = `${method} ${new URL(url).pathname}`;
|
|
49
|
+
const attempts = init.retry === undefined || init.retry === false || options.retry === undefined ? 1 : options.retry.attempts;
|
|
50
|
+
const timeoutMs = init.timeoutMs ?? options.timeoutMs;
|
|
51
|
+
const accepted = init.accept ?? ((status) => status >= 200 && status < 300);
|
|
52
|
+
for (let attempt = 1;; attempt++) {
|
|
53
|
+
if (signal?.aborted)
|
|
54
|
+
return fail("aborted", `${what} was aborted`);
|
|
55
|
+
const timeout = AbortSignal.timeout(timeoutMs);
|
|
56
|
+
let failure;
|
|
57
|
+
let retryable;
|
|
58
|
+
try {
|
|
59
|
+
const headers = init.json === undefined ? options.headers() : { ...options.headers(), "Content-Type": "application/json" };
|
|
60
|
+
// Never a redirect: a followed one keeps the key, and could carry a call to another host.
|
|
61
|
+
const response = await fetcher(url, {
|
|
62
|
+
method,
|
|
63
|
+
headers,
|
|
64
|
+
body: init.json === undefined ? init.form : JSON.stringify(init.json),
|
|
65
|
+
redirect: "error",
|
|
66
|
+
signal: signal ? AbortSignal.any([signal, timeout]) : timeout,
|
|
67
|
+
});
|
|
68
|
+
const bytes = new Uint8Array(await response.arrayBuffer());
|
|
69
|
+
if (accepted(response.status))
|
|
70
|
+
return ok({ status: response.status, bytes });
|
|
71
|
+
const own = typeof init.retry === "function";
|
|
72
|
+
retryable = own ? init.retry(response.status, bytes) : init.retry === true && (response.status === 429 || response.status >= 500);
|
|
73
|
+
const text = decoder.decode(bytes).replace(/\s+/g, " ").slice(0, 300);
|
|
74
|
+
const said = options.explain?.({ status: response.status, bytes, text, what }) ?? {};
|
|
75
|
+
failure = errorOf(said.code ?? httpCode(response.status, init.named), said.message ?? `${what}: ${response.status} ${text}`, options.vendor);
|
|
76
|
+
}
|
|
77
|
+
catch (cause) {
|
|
78
|
+
if (signal?.aborted)
|
|
79
|
+
return fail("aborted", `${what} was aborted`);
|
|
80
|
+
// No answer: the request may have reached the vendor, so only a call that may run twice is sent again.
|
|
81
|
+
retryable = init.retry === true;
|
|
82
|
+
if (timeout.aborted)
|
|
83
|
+
failure = { code: "timeout", message: `${what} did not answer within ${timeoutMs / 1000} s` };
|
|
84
|
+
else if (redirected(cause))
|
|
85
|
+
return vendorFail(options.vendor, `${what}: the API answered with a redirect, which is never followed: it would carry the key`);
|
|
86
|
+
else
|
|
87
|
+
failure = { code: "vendor", vendor: options.vendor, message: `${what}: ${cause.message}` };
|
|
88
|
+
}
|
|
89
|
+
if (!retryable || attempt >= attempts)
|
|
90
|
+
return { ok: false, error: failure };
|
|
91
|
+
await wait((options.retry?.baseMs ?? 0) * 2 ** (attempt - 1), signal);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
return {
|
|
95
|
+
url: (path) => `${base}${path}`,
|
|
96
|
+
call,
|
|
97
|
+
async json(method, url, init, signal) {
|
|
98
|
+
const answer = await call(method, url, init, signal);
|
|
99
|
+
return answer.ok ? ok(jsonOf(answer.value.bytes)) : answer;
|
|
100
|
+
},
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Every item of a paged listing. next gets the cursor of the page to read (none for the first) and answers its items and
|
|
105
|
+
* the cursor of the page after it, or nothing at the end. A cursor that comes back twice, or a listing past max pages,
|
|
106
|
+
* is a failure: this provider would miss machines.
|
|
107
|
+
*/
|
|
108
|
+
export async function allPages(next, max, of) {
|
|
109
|
+
const found = [];
|
|
110
|
+
const seen = new Set();
|
|
111
|
+
let cursor;
|
|
112
|
+
for (let page = 0; page < max; page++) {
|
|
113
|
+
const read = await next(cursor);
|
|
114
|
+
if (!read.ok)
|
|
115
|
+
return read;
|
|
116
|
+
found.push(...read.value.items);
|
|
117
|
+
const after = read.value.next;
|
|
118
|
+
if (after === undefined || after === "")
|
|
119
|
+
return ok(found);
|
|
120
|
+
if (seen.has(after))
|
|
121
|
+
return vendorFail(of.vendor, `${of.what}'s cursor ${after} came back twice`);
|
|
122
|
+
seen.add(after);
|
|
123
|
+
cursor = after;
|
|
124
|
+
}
|
|
125
|
+
return vendorFail(of.vendor, `${of.what} ran past ${max} pages`);
|
|
126
|
+
}
|
package/dist/hosted/scripts.d.ts
CHANGED
|
@@ -8,6 +8,14 @@ export declare const shellCommand: (script: string, args: readonly string[]) =>
|
|
|
8
8
|
export declare const shellLine: (argv: readonly string[]) => string;
|
|
9
9
|
/** Where start leaves what init writes, root's alone: the words a create that never hears the daemon gives back. */
|
|
10
10
|
export declare const INIT_LOG = "/run/agentrun-init.log";
|
|
11
|
+
/**
|
|
12
|
+
* The session buses a vendor's own processes leave in /tmp (Daytona's D-Bus, /tmp/dbus-Y8OW6E3FDx), which no network
|
|
13
|
+
* namespace cuts: every child host's create closes them to the computer's user before init starts. The window
|
|
14
|
+
* manager's bus is its own, at an abstract address, so closing these takes nothing from it.
|
|
15
|
+
*/
|
|
16
|
+
export declare const SESSION_BUSES: readonly string[];
|
|
17
|
+
/** The sockets the sockets script closed, from its `closed <path>` lines. */
|
|
18
|
+
export declare function closedSocketsOf(output: string): string[];
|
|
11
19
|
/**
|
|
12
20
|
* Where a pid1 Archil computer's entrypoint waits for root's word that the run's folder is mounted: beside the daemon,
|
|
13
21
|
* in the directory install makes root's alone before root makes the gate, so no other user can make it early. (A path
|
|
@@ -19,6 +27,10 @@ export interface HostedCommands {
|
|
|
19
27
|
install: string[];
|
|
20
28
|
/** child: init's start, detached; it answers once init is started. */
|
|
21
29
|
start: string[];
|
|
30
|
+
/** child: the session buses in /tmp (SESSION_BUSES) closed to others, run before start. */
|
|
31
|
+
sockets: string[];
|
|
32
|
+
/** Write taken off every user but root on the host's rootOnly paths, run before the daemon's upload. */
|
|
33
|
+
rootOnly: string[];
|
|
22
34
|
stdio: string[];
|
|
23
35
|
log: string[];
|
|
24
36
|
/** pid1: the machine's command. */
|
|
@@ -28,14 +40,18 @@ export interface HostedCommands {
|
|
|
28
40
|
* The adapter's commands for one computer. Init's flags are the child's (childCommands) for both modes: --own-network
|
|
29
41
|
* always, the display and the most deadline.extend may move the deadline to when given. waitS bounds a pid1 entrypoint's
|
|
30
42
|
* wait for the daemon (and gate, for an Archil computer); with atomic, install moves the daemon into place last, and only
|
|
31
|
-
* once it reads sha256, when given, then writes nonce, when given, to the marker the entrypoint waits for.
|
|
43
|
+
* once it reads sha256, when given, then writes nonce, when given, to the marker the entrypoint waits for. sockets are
|
|
44
|
+
* the patterns a child's sockets command closes (default SESSION_BUSES); rootOnly the paths its root-only command takes
|
|
45
|
+
* others' write off (default none).
|
|
32
46
|
*/
|
|
33
|
-
export declare function hostedCommands({ staging, deadline, user, display, maxDeadline, atomic, waitS, gate, sha256, nonce, }?: ChildCommandOptions & {
|
|
47
|
+
export declare function hostedCommands({ staging, deadline, user, display, maxDeadline, atomic, waitS, gate, sha256, nonce, sockets, rootOnly, network, }?: ChildCommandOptions & {
|
|
34
48
|
atomic?: boolean;
|
|
35
49
|
waitS?: number;
|
|
36
50
|
gate?: string;
|
|
37
51
|
sha256?: string;
|
|
38
52
|
nonce?: string;
|
|
53
|
+
sockets?: readonly string[];
|
|
54
|
+
rootOnly?: readonly string[];
|
|
39
55
|
}): HostedCommands;
|
|
40
56
|
export interface ChildCommandOptions {
|
|
41
57
|
/** Where the vendor's upload left the daemon. */
|
|
@@ -48,13 +64,15 @@ export interface ChildCommandOptions {
|
|
|
48
64
|
display?: string;
|
|
49
65
|
/** The most deadline.extend may move the deadline to, an ISO time; none, and the deadline cannot move. */
|
|
50
66
|
maxDeadline?: string;
|
|
67
|
+
/** The network form init's egress proxy serves (./network.ts networkFormOf): open, or allow: and a list; none, no proxy. */
|
|
68
|
+
network?: string;
|
|
51
69
|
}
|
|
52
70
|
/**
|
|
53
71
|
* The three shell commands a child-daemon provider sends into a computer, exactly: install (the upload moved into place,
|
|
54
72
|
* its sha256 printed), init (long-lived) and stdio (one per connection). Each is one string for a shell, `sh -c` with
|
|
55
73
|
* every argument quoted.
|
|
56
74
|
*/
|
|
57
|
-
export declare function childCommands({ staging, deadline, user, display, maxDeadline }?: ChildCommandOptions): {
|
|
75
|
+
export declare function childCommands({ staging, deadline, user, display, maxDeadline, network }?: ChildCommandOptions): {
|
|
58
76
|
install: string;
|
|
59
77
|
init: string;
|
|
60
78
|
stdio: string;
|
package/dist/hosted/scripts.js
CHANGED
|
@@ -60,15 +60,17 @@ export function installerOf(output) {
|
|
|
60
60
|
* them (Daytona's toolbox, E2B's envd), which runs commands as root for whoever reaches it: a network of their own,
|
|
61
61
|
* their loopback alone, no vsock, no other process of their uid (src/isolation.ts). Init holds every process and ends
|
|
62
62
|
* them at the deadline. A display, when given, is init's DISPLAY, the X display its screen and input methods drive; a
|
|
63
|
-
* maximum, when given, is the most deadline.extend may move the deadline to
|
|
63
|
+
* maximum, when given, is the most deadline.extend may move the deadline to; a network form, when given (open, or
|
|
64
|
+
* allow: and a list), has init start the egress proxy that serves it before it leaves the machine's network
|
|
65
|
+
* (./network.ts). */
|
|
64
66
|
const INIT_SCRIPT = [
|
|
65
67
|
"# agentrun-computer: init",
|
|
66
|
-
// The display is v, not x: held() assigns x, and runs before the exec that reads it.
|
|
67
|
-
"d=$1; t=$2; w=$3; h=$4; r=$5; v=${6-}; m=${7-}",
|
|
68
|
+
// The display is v, not x: held() assigns x, and runs before the exec that reads it. The network form is n.
|
|
69
|
+
"d=$1; t=$2; w=$3; h=$4; r=$5; v=${6-}; m=${7-}; n=${8-}",
|
|
68
70
|
HELD,
|
|
69
71
|
'held "$d" >&2 || exit 6',
|
|
70
72
|
ROOT,
|
|
71
|
-
`exec $p env -i PATH=${PATH} HOME="$h" AGENTRUN_COMPUTERD_SOCKET="$r/computerd.sock" \${v:+DISPLAY="$v"} sh -c 'cd "$HOME" && exec "$@"' sh "$d" init --deadline "$t" --user "$w" --own-network \${m:+--max-deadline "$m"}`,
|
|
73
|
+
`exec $p env -i PATH=${PATH} HOME="$h" AGENTRUN_COMPUTERD_SOCKET="$r/computerd.sock" \${v:+DISPLAY="$v"} sh -c 'cd "$HOME" && exec "$@"' sh "$d" init --deadline "$t" --user "$w" --own-network \${m:+--max-deadline "$m"} \${n:+--network "$n"}`,
|
|
72
74
|
].join("\n");
|
|
73
75
|
/** The bridge one connection runs: stdin and stdout to init's socket. As root, to reach a socket in a directory that is
|
|
74
76
|
* the daemon's user's alone; it only carries bytes, and the command's user is root or has passwordless sudo already.
|
|
@@ -88,6 +90,56 @@ export const INIT_LOG = `${SOCKET_DIR}-init.log`;
|
|
|
88
90
|
* none, so the vendor's call ends at once and nothing of it holds init. As root, or through passwordless sudo.
|
|
89
91
|
*/
|
|
90
92
|
const START_SCRIPT = ["# agentrun-computer: start", "l=$1; shift", ROOT, `exec $p sh -c 'exec >"$0" 2>&1 </dev/null; setsid "$@" &' "$l" "$@"`].join("\n");
|
|
93
|
+
/**
|
|
94
|
+
* The session buses a vendor's own processes leave in /tmp (Daytona's D-Bus, /tmp/dbus-Y8OW6E3FDx), which no network
|
|
95
|
+
* namespace cuts: every child host's create closes them to the computer's user before init starts. The window
|
|
96
|
+
* manager's bus is its own, at an abstract address, so closing these takes nothing from it.
|
|
97
|
+
*/
|
|
98
|
+
export const SESSION_BUSES = ["/tmp/dbus-*"];
|
|
99
|
+
/**
|
|
100
|
+
* Takes others' access off every path unix socket the patterns ($@, each a shell pattern with no space) name, as
|
|
101
|
+
* root: what init does itself under /run (daemon/internal/isolate CloseSystemSockets), for a vendor's socket
|
|
102
|
+
* elsewhere. The owner's and group's access stays, so the vendor's own service keeps its socket; the computer's user
|
|
103
|
+
* is neither. A link is never followed. Prints `closed <path>` for each socket it closed and `failed <path>` for one
|
|
104
|
+
* it could not; any failure fails the script, and create then refuses the computer.
|
|
105
|
+
*/
|
|
106
|
+
const SOCKETS_SCRIPT = [
|
|
107
|
+
"# agentrun-computer: sockets",
|
|
108
|
+
ROOT,
|
|
109
|
+
"failed=0",
|
|
110
|
+
'for g in "$@"; do',
|
|
111
|
+
"\tfor s in $g; do",
|
|
112
|
+
'\t\t[ -S "$s" ] && [ ! -L "$s" ] || continue',
|
|
113
|
+
'\t\tif $p chmod o-rwx "$s"; then echo "closed $s"; else echo "failed $s"; failed=1; fi',
|
|
114
|
+
"\tdone",
|
|
115
|
+
"done",
|
|
116
|
+
"exit $failed",
|
|
117
|
+
].join("\n");
|
|
118
|
+
/**
|
|
119
|
+
* Makes each path ($@) root's alone, as root, and for a directory everything under it (no link is followed): root owns
|
|
120
|
+
* every entry (a link itself, `chown -h`), and no group or other user may write one. Only the entries that need it are
|
|
121
|
+
* changed. Then it reads them back: an entry not root's alone fails the script, and create then refuses the computer.
|
|
122
|
+
* An owner who is not root could give write back with chmod, so the owner is made root as well as the mode. A path the
|
|
123
|
+
* image lacks is skipped. For a host whose image leaves places root runs or reads open to other users
|
|
124
|
+
* (HostFacts.rootOnly); it runs before the daemon's upload. Root is the user `$p` runs as, read by `id -u`.
|
|
125
|
+
*/
|
|
126
|
+
const ROOT_ONLY_SCRIPT = [
|
|
127
|
+
"# agentrun-computer: root-only",
|
|
128
|
+
ROOT,
|
|
129
|
+
'r=$($p id -u) || { echo "running a command as root failed"; exit 5; }',
|
|
130
|
+
'for f in "$@"; do',
|
|
131
|
+
'\t[ -e "$f" ] || [ -L "$f" ] || continue',
|
|
132
|
+
'\t[ ! -L "$f" ] || { echo "$f is a symbolic link"; exit 6; }',
|
|
133
|
+
'\t$p find "$f" ! -user "$r" -exec chown -h "$r" {} + || { echo "making root the owner of $f failed"; exit 5; }',
|
|
134
|
+
'\t$p find "$f" ! -type l -perm /022 -exec chmod go-w {} + || { echo "taking write off $f failed"; exit 5; }',
|
|
135
|
+
'\tw=$($p find "$f" \\( ! -user "$r" -o ! -type l -perm /022 \\) -print 2>/dev/null | head -n 1)',
|
|
136
|
+
'\t[ -z "$w" ] || { echo "$w is not root\'s alone"; exit 5; }',
|
|
137
|
+
"done",
|
|
138
|
+
].join("\n");
|
|
139
|
+
/** The sockets the sockets script closed, from its `closed <path>` lines. */
|
|
140
|
+
export function closedSocketsOf(output) {
|
|
141
|
+
return output.split("\n").flatMap((line) => (line.startsWith("closed ") ? [line.slice("closed ".length).trim()] : []));
|
|
142
|
+
}
|
|
91
143
|
/** The last words init wrote to its log, as root; nothing when it wrote none. */
|
|
92
144
|
const LOG_SCRIPT = ["# agentrun-computer: log", "l=$1", ROOT, '$p tail -c 2000 "$l" 2>/dev/null || true'].join("\n");
|
|
93
145
|
/**
|
|
@@ -130,30 +182,40 @@ export const ARCHIL_GATE = `${DAEMON_IN_COMPUTER.slice(0, DAEMON_IN_COMPUTER.las
|
|
|
130
182
|
* The adapter's commands for one computer. Init's flags are the child's (childCommands) for both modes: --own-network
|
|
131
183
|
* always, the display and the most deadline.extend may move the deadline to when given. waitS bounds a pid1 entrypoint's
|
|
132
184
|
* wait for the daemon (and gate, for an Archil computer); with atomic, install moves the daemon into place last, and only
|
|
133
|
-
* once it reads sha256, when given, then writes nonce, when given, to the marker the entrypoint waits for.
|
|
185
|
+
* once it reads sha256, when given, then writes nonce, when given, to the marker the entrypoint waits for. sockets are
|
|
186
|
+
* the patterns a child's sockets command closes (default SESSION_BUSES); rootOnly the paths its root-only command takes
|
|
187
|
+
* others' write off (default none).
|
|
134
188
|
*/
|
|
135
|
-
export function hostedCommands({ staging = "", deadline = "", user = TOOL_USER, display = "", maxDeadline = "", atomic = false, waitS = 600, gate, sha256 = "", nonce = "", } = {}) {
|
|
136
|
-
const init =
|
|
137
|
-
|
|
138
|
-
init.push(display, maxDeadline);
|
|
139
|
-
const initArgs = ["init", "--deadline", deadline, "--user", user, "--own-network", ...(maxDeadline === "" ? [] : ["--max-deadline", maxDeadline])];
|
|
189
|
+
export function hostedCommands({ staging = "", deadline = "", user = TOOL_USER, display = "", maxDeadline = "", atomic = false, waitS = 600, gate, sha256 = "", nonce = "", sockets = SESSION_BUSES, rootOnly = [], network = "", } = {}) {
|
|
190
|
+
const init = initScriptArgs({ deadline, user, display, maxDeadline, network });
|
|
191
|
+
const initArgs = ["init", "--deadline", deadline, "--user", user, "--own-network", ...(maxDeadline === "" ? [] : ["--max-deadline", maxDeadline]), ...(network === "" ? [] : ["--network", network])];
|
|
140
192
|
return {
|
|
141
193
|
install: argvOf(INSTALL_SCRIPT, [staging, DAEMON_IN_COMPUTER, WORK, SOCKET_DIR, ...(atomic ? ["1", sha256, nonce] : [])]),
|
|
142
194
|
start: argvOf(START_SCRIPT, [INIT_LOG, ...argvOf(INIT_SCRIPT, init)]),
|
|
143
195
|
stdio: argvOf(STDIO_SCRIPT, [DAEMON_IN_COMPUTER, SOCKET_DIR]),
|
|
144
196
|
log: argvOf(LOG_SCRIPT, [INIT_LOG]),
|
|
197
|
+
sockets: argvOf(SOCKETS_SCRIPT, sockets),
|
|
198
|
+
rootOnly: argvOf(ROOT_ONLY_SCRIPT, rootOnly),
|
|
145
199
|
entrypoint: argvOf(ENTRYPOINT_SCRIPT, [DAEMON_IN_COMPUTER, String(waitS), WORK, display, nonce, ...(gate === undefined ? [] : ["--gate", gate]), ...initArgs]),
|
|
146
200
|
};
|
|
147
201
|
}
|
|
202
|
+
/** The init script's arguments: the daemon, the deadline, the user, home and the socket's folder, then the display, the
|
|
203
|
+
* maximum and the network form, each empty when not given, where any of them is. */
|
|
204
|
+
function initScriptArgs({ deadline = "", user = TOOL_USER, display = "", maxDeadline = "", network = "" }) {
|
|
205
|
+
const init = [DAEMON_IN_COMPUTER, deadline, user, WORK, SOCKET_DIR];
|
|
206
|
+
if (network !== "")
|
|
207
|
+
init.push(display, maxDeadline, network);
|
|
208
|
+
else if (display !== "" || maxDeadline !== "")
|
|
209
|
+
init.push(display, maxDeadline);
|
|
210
|
+
return init;
|
|
211
|
+
}
|
|
148
212
|
/**
|
|
149
213
|
* The three shell commands a child-daemon provider sends into a computer, exactly: install (the upload moved into place,
|
|
150
214
|
* its sha256 printed), init (long-lived) and stdio (one per connection). Each is one string for a shell, `sh -c` with
|
|
151
215
|
* every argument quoted.
|
|
152
216
|
*/
|
|
153
|
-
export function childCommands({ staging = "", deadline = "", user = TOOL_USER, display = "", maxDeadline = "" } = {}) {
|
|
154
|
-
const init =
|
|
155
|
-
if (display !== "" || maxDeadline !== "")
|
|
156
|
-
init.push(display, maxDeadline);
|
|
217
|
+
export function childCommands({ staging = "", deadline = "", user = TOOL_USER, display = "", maxDeadline = "", network = "" } = {}) {
|
|
218
|
+
const init = initScriptArgs({ deadline, user, display, maxDeadline, network });
|
|
157
219
|
return {
|
|
158
220
|
install: shellCommand(INSTALL_SCRIPT, [staging, DAEMON_IN_COMPUTER, WORK, SOCKET_DIR]),
|
|
159
221
|
init: shellCommand(INIT_SCRIPT, init),
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { Duplex } from "node:stream";
|
|
2
|
+
import type { HostCall, MachineProcess } from "../host.js";
|
|
3
|
+
/** A readable side of an ssh2 channel, as this provider uses it: piped, or drained. */
|
|
4
|
+
export interface Ssh2Readable {
|
|
5
|
+
pipe(destination: NodeJS.WritableStream): unknown;
|
|
6
|
+
resume(): unknown;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* The slice of an ssh2 channel this provider uses (ssh2@1.17.0 lib/Channel.js): the channel is stdout. No signal
|
|
10
|
+
* request: ssh2 sends one only while stdin is open (Channel.js:237-246), so a kill goes by the process group instead.
|
|
11
|
+
*/
|
|
12
|
+
export interface Ssh2Channel extends Ssh2Readable {
|
|
13
|
+
readonly stderr: Ssh2Readable;
|
|
14
|
+
write(data: Uint8Array, callback?: (error?: Error | null) => void): boolean;
|
|
15
|
+
/** Sends end of file on stdin and keeps the channel open (Channel.js:200-205). */
|
|
16
|
+
eof(): void;
|
|
17
|
+
close(): void;
|
|
18
|
+
/** exit-status, or exit-signal with a null code (client.js:666-678). */
|
|
19
|
+
on(event: "exit", listener: (code: number | null, signal?: string) => void): unknown;
|
|
20
|
+
on(event: "close", listener: () => void): unknown;
|
|
21
|
+
on(event: "error", listener: (error: Error) => void): unknown;
|
|
22
|
+
}
|
|
23
|
+
/** The options of ssh2's Client.connect this provider gives (ssh2@1.17.0 lib/client.js). */
|
|
24
|
+
export interface Ssh2ConnectConfig {
|
|
25
|
+
sock: Duplex;
|
|
26
|
+
username: string;
|
|
27
|
+
privateKey?: string;
|
|
28
|
+
password?: string;
|
|
29
|
+
readyTimeout: number;
|
|
30
|
+
keepaliveInterval: number;
|
|
31
|
+
keepaliveCountMax: number;
|
|
32
|
+
}
|
|
33
|
+
/** The slice of an ssh2 Client this provider uses. */
|
|
34
|
+
export interface Ssh2Client {
|
|
35
|
+
connect(config: Ssh2ConnectConfig): unknown;
|
|
36
|
+
exec(command: string, callback: (error: Error | undefined, channel: Ssh2Channel) => void): unknown;
|
|
37
|
+
end(): unknown;
|
|
38
|
+
destroy(): unknown;
|
|
39
|
+
once(event: "ready", listener: () => void): unknown;
|
|
40
|
+
once(event: "error", listener: (error: Error) => void): unknown;
|
|
41
|
+
on(event: "error", listener: (error: Error) => void): unknown;
|
|
42
|
+
on(event: "close" | "end", listener: () => void): unknown;
|
|
43
|
+
removeListener(event: "error", listener: (error: Error) => void): unknown;
|
|
44
|
+
}
|
|
45
|
+
/** The ssh2 package as this provider uses it: its Client class. The host's own, or anything with the same slice. */
|
|
46
|
+
export interface Ssh2Module {
|
|
47
|
+
Client: new () => Ssh2Client;
|
|
48
|
+
}
|
|
49
|
+
/** A tunnel failed before its SSH handshake, or while it carried the stream: the one failure a retry may repeat. */
|
|
50
|
+
export declare class SshTunnelError extends Error {
|
|
51
|
+
name: string;
|
|
52
|
+
}
|
|
53
|
+
/** One stream to a machine's sshd, as a vendor's hook gives it: its bytes as a Duplex, resolved once open, and the host named in words. */
|
|
54
|
+
export interface SshTunnel {
|
|
55
|
+
duplex: Duplex;
|
|
56
|
+
/** Resolves once the stream is open; rejects (an SshTunnelError, for a retry) when it fails to open. */
|
|
57
|
+
opened: Promise<void>;
|
|
58
|
+
/** The host's name, in the words of an error. */
|
|
59
|
+
host: string;
|
|
60
|
+
}
|
|
61
|
+
/** How a vendor opens the stream to machine id's sshd: a fresh one per call, nothing started before it is used. */
|
|
62
|
+
export type SshTunnelOf = (id: string) => SshTunnel;
|
|
63
|
+
/** How a host logs in to a machine's sshd: as root (MachineHost.exec's user), by a key or a password. */
|
|
64
|
+
export interface SshLogin {
|
|
65
|
+
username: string;
|
|
66
|
+
/** A private key in the PEM armor ssh2 reads (see pemOf). */
|
|
67
|
+
privateKey?: string;
|
|
68
|
+
password?: string;
|
|
69
|
+
/** What no error may carry, beside the key and the password, which never do: a key inside the username (Morph's). */
|
|
70
|
+
secrets?: readonly string[];
|
|
71
|
+
}
|
|
72
|
+
export interface SshExecOptions {
|
|
73
|
+
/** The host's own ssh2 package, or anything with the same slice. */
|
|
74
|
+
ssh2: Ssh2Module;
|
|
75
|
+
/** The login to machine id. */
|
|
76
|
+
loginOf: (id: string) => SshLogin;
|
|
77
|
+
tunnelOf: SshTunnelOf;
|
|
78
|
+
}
|
|
79
|
+
/** MachineHost.exec over SSH: argv as the host's login, as channels on one connection per machine, shared by its execs. */
|
|
80
|
+
export declare class SshExec {
|
|
81
|
+
#private;
|
|
82
|
+
constructor({ ssh2, loginOf, tunnelOf }: SshExecOptions);
|
|
83
|
+
/** Ends every connection to machine id, channels and all: the vendor calls it once the machine is deleted. */
|
|
84
|
+
closeAll(id: string): void;
|
|
85
|
+
/**
|
|
86
|
+
* argv as the host's login over SSH, under WRAPPER, as one channel on the machine's shared connection (#start).
|
|
87
|
+
* stdout and stderr are the channel's, piped; end sends end of file. wait answers once the channel closes, with the
|
|
88
|
+
* exit-status, or -1 for an exit by signal or none. kill ends the process group over a channel of its own (on a
|
|
89
|
+
* connection with room), then closes the exec's channel, never a connection; if the close does not come, wait
|
|
90
|
+
* answers -1 and the connection takes no new channel.
|
|
91
|
+
*/
|
|
92
|
+
exec(id: string, argv: readonly string[], ctx: HostCall): Promise<MachineProcess>;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* A private key in the PEM armor ssh2 reads (its parser wants the BEGIN and END lines on lines of their own), or
|
|
96
|
+
* undefined when text is not one. A key pasted into Settings → Computers comes back on one line, since a password
|
|
97
|
+
* field drops line breaks: its body is wrapped again at 70 characters, as ssh-keygen writes it.
|
|
98
|
+
*/
|
|
99
|
+
export declare function pemOf(text: string): string | undefined;
|