@parcha/agentrun-computer 0.0.0-stage → 0.1.0-beta.33

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.
Files changed (173) hide show
  1. package/LICENSE +202 -0
  2. package/NOTICE +8 -0
  3. package/README.md +2411 -2
  4. package/box/Dockerfile +69 -0
  5. package/box/agentrun-archil +168 -0
  6. package/box/build-daytona.py +26 -0
  7. package/box/build-e2b.mjs +32 -0
  8. package/box/build-modal.py +17 -0
  9. package/dist/actions.d.ts +18 -0
  10. package/dist/actions.js +139 -0
  11. package/dist/browser.d.ts +151 -0
  12. package/dist/browser.js +305 -0
  13. package/dist/browserbase.d.ts +139 -0
  14. package/dist/browserbase.js +408 -0
  15. package/dist/child.d.ts +40 -0
  16. package/dist/child.js +127 -0
  17. package/dist/client.d.ts +22 -0
  18. package/dist/client.js +136 -0
  19. package/dist/computerd-linux-amd64 +0 -0
  20. package/dist/computerd-linux-arm64 +0 -0
  21. package/dist/conformance/archil.d.ts +68 -0
  22. package/dist/conformance/archil.js +152 -0
  23. package/dist/conformance/browserbase.d.ts +35 -0
  24. package/dist/conformance/browserbase.js +45 -0
  25. package/dist/conformance/cases/apps.d.ts +2 -0
  26. package/dist/conformance/cases/apps.js +155 -0
  27. package/dist/conformance/cases/browser.d.ts +4 -0
  28. package/dist/conformance/cases/browser.js +105 -0
  29. package/dist/conformance/cases/drift.d.ts +2 -0
  30. package/dist/conformance/cases/drift.js +64 -0
  31. package/dist/conformance/cases/exec.d.ts +2 -0
  32. package/dist/conformance/cases/exec.js +125 -0
  33. package/dist/conformance/cases/files.d.ts +2 -0
  34. package/dist/conformance/cases/files.js +294 -0
  35. package/dist/conformance/cases/health.d.ts +2 -0
  36. package/dist/conformance/cases/health.js +71 -0
  37. package/dist/conformance/cases/index.d.ts +9 -0
  38. package/dist/conformance/cases/index.js +37 -0
  39. package/dist/conformance/cases/input.d.ts +12 -0
  40. package/dist/conformance/cases/input.js +109 -0
  41. package/dist/conformance/cases/isolation.d.ts +21 -0
  42. package/dist/conformance/cases/isolation.js +98 -0
  43. package/dist/conformance/cases/lifetime.d.ts +2 -0
  44. package/dist/conformance/cases/lifetime.js +64 -0
  45. package/dist/conformance/cases/mount.d.ts +2 -0
  46. package/dist/conformance/cases/mount.js +252 -0
  47. package/dist/conformance/cases/process.d.ts +2 -0
  48. package/dist/conformance/cases/process.js +240 -0
  49. package/dist/conformance/cases/provider.d.ts +2 -0
  50. package/dist/conformance/cases/provider.js +302 -0
  51. package/dist/conformance/cases/screen.d.ts +9 -0
  52. package/dist/conformance/cases/screen.js +230 -0
  53. package/dist/conformance/cases/settings.d.ts +57 -0
  54. package/dist/conformance/cases/settings.js +142 -0
  55. package/dist/conformance/cases/touch.d.ts +2 -0
  56. package/dist/conformance/cases/touch.js +117 -0
  57. package/dist/conformance/cases/util.d.ts +7 -0
  58. package/dist/conformance/cases/util.js +8 -0
  59. package/dist/conformance/cdp.d.ts +13 -0
  60. package/dist/conformance/cdp.js +88 -0
  61. package/dist/conformance/cli.d.ts +29 -0
  62. package/dist/conformance/cli.js +231 -0
  63. package/dist/conformance/daytona-sweep.d.ts +18 -0
  64. package/dist/conformance/daytona-sweep.js +126 -0
  65. package/dist/conformance/daytona.d.ts +83 -0
  66. package/dist/conformance/daytona.js +107 -0
  67. package/dist/conformance/docker.d.ts +38 -0
  68. package/dist/conformance/docker.js +70 -0
  69. package/dist/conformance/drift-daemon.d.ts +8 -0
  70. package/dist/conformance/drift-daemon.js +41 -0
  71. package/dist/conformance/e2b-diagnose.d.ts +16 -0
  72. package/dist/conformance/e2b-diagnose.js +61 -0
  73. package/dist/conformance/e2b-sweep.d.ts +18 -0
  74. package/dist/conformance/e2b-sweep.js +132 -0
  75. package/dist/conformance/e2b.d.ts +74 -0
  76. package/dist/conformance/e2b.js +111 -0
  77. package/dist/conformance/fixture.d.ts +65 -0
  78. package/dist/conformance/fixture.js +98 -0
  79. package/dist/conformance/index.d.ts +8 -0
  80. package/dist/conformance/index.js +8 -0
  81. package/dist/conformance/kernel.d.ts +31 -0
  82. package/dist/conformance/kernel.js +40 -0
  83. package/dist/conformance/kind.d.ts +23 -0
  84. package/dist/conformance/kind.js +58 -0
  85. package/dist/conformance/modal-sweep.d.ts +22 -0
  86. package/dist/conformance/modal-sweep.js +213 -0
  87. package/dist/conformance/modal.d.ts +69 -0
  88. package/dist/conformance/modal.js +76 -0
  89. package/dist/conformance/orgo.d.ts +41 -0
  90. package/dist/conformance/orgo.js +69 -0
  91. package/dist/conformance/phone-harness.d.ts +61 -0
  92. package/dist/conformance/phone-harness.js +241 -0
  93. package/dist/conformance/png.d.ts +16 -0
  94. package/dist/conformance/png.js +132 -0
  95. package/dist/conformance/report.d.ts +2 -0
  96. package/dist/conformance/report.js +86 -0
  97. package/dist/conformance/runner.d.ts +11 -0
  98. package/dist/conformance/runner.js +585 -0
  99. package/dist/conformance/tar.d.ts +13 -0
  100. package/dist/conformance/tar.js +105 -0
  101. package/dist/conformance/types.d.ts +257 -0
  102. package/dist/conformance/types.js +24 -0
  103. package/dist/daemon-copy.d.ts +40 -0
  104. package/dist/daemon-copy.js +259 -0
  105. package/dist/daytona.d.ts +180 -0
  106. package/dist/daytona.js +1498 -0
  107. package/dist/desktop.d.ts +24 -0
  108. package/dist/desktop.js +68 -0
  109. package/dist/docker/egress-main.d.ts +1 -0
  110. package/dist/docker/egress-main.js +68 -0
  111. package/dist/docker/egress-proxy.d.ts +53 -0
  112. package/dist/docker/egress-proxy.js +450 -0
  113. package/dist/docker/egress-table.d.ts +39 -0
  114. package/dist/docker/egress-table.js +197 -0
  115. package/dist/docker/egress.d.ts +109 -0
  116. package/dist/docker/egress.js +318 -0
  117. package/dist/docker/image.d.ts +49 -0
  118. package/dist/docker/image.js +302 -0
  119. package/dist/docker/stage.d.ts +21 -0
  120. package/dist/docker/stage.js +290 -0
  121. package/dist/docker/volume.d.ts +24 -0
  122. package/dist/docker/volume.js +67 -0
  123. package/dist/docker.d.ts +156 -0
  124. package/dist/docker.js +1277 -0
  125. package/dist/drift.d.ts +200 -0
  126. package/dist/drift.js +416 -0
  127. package/dist/e2b.d.ts +337 -0
  128. package/dist/e2b.js +1516 -0
  129. package/dist/entry.d.ts +2 -0
  130. package/dist/entry.js +24 -0
  131. package/dist/files.d.ts +50 -0
  132. package/dist/files.js +208 -0
  133. package/dist/index.d.ts +27 -0
  134. package/dist/index.js +26 -0
  135. package/dist/isolation.d.ts +29 -0
  136. package/dist/isolation.js +71 -0
  137. package/dist/janitor.d.ts +50 -0
  138. package/dist/janitor.js +135 -0
  139. package/dist/kernel.d.ts +113 -0
  140. package/dist/kernel.js +358 -0
  141. package/dist/kinds.d.ts +79 -0
  142. package/dist/kinds.js +133 -0
  143. package/dist/labels.d.ts +23 -0
  144. package/dist/labels.js +50 -0
  145. package/dist/modal.d.ts +302 -0
  146. package/dist/modal.js +1374 -0
  147. package/dist/mount-archil.d.ts +164 -0
  148. package/dist/mount-archil.js +471 -0
  149. package/dist/mount.d.ts +57 -0
  150. package/dist/mount.js +104 -0
  151. package/dist/orgo-channel.d.ts +96 -0
  152. package/dist/orgo-channel.js +391 -0
  153. package/dist/orgo.d.ts +139 -0
  154. package/dist/orgo.js +1006 -0
  155. package/dist/phone-harness.d.ts +185 -0
  156. package/dist/phone-harness.js +1420 -0
  157. package/dist/processes.d.ts +24 -0
  158. package/dist/processes.js +40 -0
  159. package/dist/protocol.d.ts +729 -0
  160. package/dist/protocol.js +54 -0
  161. package/dist/provider.d.ts +245 -0
  162. package/dist/provider.js +37 -0
  163. package/dist/providers.d.ts +68 -0
  164. package/dist/providers.js +25 -0
  165. package/dist/result.d.ts +15 -0
  166. package/dist/result.js +2 -0
  167. package/dist/screen-watch.d.ts +150 -0
  168. package/dist/screen-watch.js +490 -0
  169. package/dist/test-connection.d.ts +17 -0
  170. package/dist/test-connection.js +26 -0
  171. package/dist/wait.d.ts +23 -0
  172. package/dist/wait.js +65 -0
  173. package/package.json +62 -4
@@ -0,0 +1,24 @@
1
+ import type { ComputerClient } from "./protocol.js";
2
+ import { type ComputerErrorCode, type Result } from "./result.js";
3
+ export interface DesktopOptions {
4
+ /** The display the daemon and the X server use, given to the daemon as DISPLAY. Default ":0". */
5
+ display?: string;
6
+ /** The X server's argv, run in the computer as its user. Default Xvfb on the display, 1280x800 at 24 bits, no TCP. */
7
+ server?: readonly string[];
8
+ /** How long create waits for the display to answer after starting the server. Default 30 s. */
9
+ timeoutMs?: number;
10
+ }
11
+ /** The groups a desktop declares besides exec, files and processes. */
12
+ export declare const DESKTOP_GROUPS: readonly ["screen", "input.pointer", "input.keys"];
13
+ /** The desktop options with their defaults, or a throw in words. */
14
+ export declare function desktopOf({ display, server, timeoutMs }: DesktopOptions): Required<DesktopOptions>;
15
+ /**
16
+ * Starts the desktop's X server through the daemon (process.start) and waits until hello declares the display: the
17
+ * server ending first, or the bound passing, is a failure in words, with the server's own last words, under the
18
+ * vendor's code. version is the client's, sent with each hello.
19
+ */
20
+ export declare function startDisplay(client: ComputerClient, desktop: Required<DesktopOptions>, { version, vendor, signal }: {
21
+ version: string;
22
+ vendor: ComputerErrorCode;
23
+ signal?: AbortSignal | undefined;
24
+ }): Promise<Result<void>>;
@@ -0,0 +1,68 @@
1
+ // A desktop on an X server computerd starts itself: the provider gives init DISPLAY, then starts the X server through
2
+ // the daemon with process.start, as any program, so the server is in init's process table and ends with the computer.
3
+ // The daemon reaches the display once it answers, and hello declares screen, input.pointer and input.keys from then on
4
+ // (hello re-checks the display on each call). Docker's desktops and E2B's start the display this way.
5
+ import { setTimeout as sleep } from "node:timers/promises";
6
+ import { fail, ok } from "./result.js";
7
+ /** The groups a desktop declares besides exec, files and processes. */
8
+ export const DESKTOP_GROUPS = ["screen", "input.pointer", "input.keys"];
9
+ const DISPLAY = /^:\d{1,5}(\.\d{1,5})?$/;
10
+ /** How often create asks the daemon whether the display is up yet. */
11
+ const DISPLAY_POLL_MS = 100;
12
+ /** The longest a Node timer or AbortSignal.timeout holds. */
13
+ const MAX_TIMER_MS = 2 ** 31 - 1;
14
+ /** The desktop options with their defaults, or a throw in words. */
15
+ export function desktopOf({ display = ":0", server, timeoutMs = 30_000 }) {
16
+ if (typeof display !== "string" || !DISPLAY.test(display))
17
+ throw new Error(`the desktop's display ${JSON.stringify(display)} must be a local X display, such as :0`);
18
+ const argv = server ?? ["Xvfb", display, "-screen", "0", "1280x800x24", "-nolisten", "tcp"];
19
+ if (!Array.isArray(argv) || argv.length === 0 || !argv.every((arg) => typeof arg === "string" && !arg.includes("\0")) || argv[0] === "") {
20
+ throw new Error("the desktop's server must be a program and its arguments, such as [\"Xvfb\", \":0\"]");
21
+ }
22
+ // AbortSignal.timeout and Node's timers hold at most 2^31 - 1 ms (a longer one throws or fires at once), so a longer
23
+ // bound is refused here, before any computer exists, not in create after the computer is made.
24
+ if (!Number.isSafeInteger(timeoutMs) || timeoutMs <= 0 || timeoutMs > MAX_TIMER_MS) {
25
+ throw new Error(`the desktop's timeoutMs must be a whole number of milliseconds above 0 and at most ${MAX_TIMER_MS}, not ${timeoutMs}`);
26
+ }
27
+ return { display, server: [...argv], timeoutMs };
28
+ }
29
+ /**
30
+ * Starts the desktop's X server through the daemon (process.start) and waits until hello declares the display: the
31
+ * server ending first, or the bound passing, is a failure in words, with the server's own last words, under the
32
+ * vendor's code. version is the client's, sent with each hello.
33
+ */
34
+ export async function startDisplay(client, desktop, { version, vendor, signal }) {
35
+ const server = desktop.server.join(" ");
36
+ // Every call takes a signal that ends at the bound, so a hello the X connection setup holds, or a daemon that stops
37
+ // answering, cannot outwait it. A call that failed because the bound passed is the timeout; the caller's own abort
38
+ // stays aborted.
39
+ const bound = AbortSignal.timeout(desktop.timeoutMs);
40
+ const either = signal ? AbortSignal.any([signal, bound]) : bound;
41
+ const late = () => fail("timeout", `the display ${desktop.display} was not up within ${desktop.timeoutMs / 1000} s of starting the X server (${server})`);
42
+ const timedOut = () => bound.aborted && !signal?.aborted;
43
+ const started = await client.call("process.start", { argv: [...desktop.server] }, { signal: either });
44
+ if (!started.ok)
45
+ return timedOut() ? late() : fail(started.error.code, `the X server (${server}) did not start: ${started.error.message}`);
46
+ const { id } = started.value;
47
+ for (;;) {
48
+ const hello = await client.call("hello", { client: `@parcha/agentrun-computer ${version}` }, { signal: either });
49
+ if (!hello.ok)
50
+ return timedOut() ? late() : hello;
51
+ if (Array.isArray(hello.value.groups) && hello.value.groups.includes("screen"))
52
+ return ok(undefined);
53
+ const waited = await client.call("process.wait", { id, timeoutMs: 0 }, { signal: either });
54
+ if (waited.ok && !waited.value.running) {
55
+ const read = await client.call("process.read", { id, stream: "stderr", offset: 0 }, { signal: either });
56
+ const words = read.ok ? Buffer.from(read.value.data, "base64").toString("utf8").trim().split("\n").slice(-5).join("; ") : "";
57
+ const how = waited.value.signal ? `signal ${waited.value.signal}` : `exit code ${waited.value.exitCode}`;
58
+ return fail(vendor, `the X server (${server}) ended with ${how} before the display ${desktop.display} was up${words ? `: ${words}` : ""}`);
59
+ }
60
+ if (timedOut())
61
+ return late();
62
+ if (signal?.aborted)
63
+ return fail("aborted", "create was aborted while the display came up");
64
+ await sleep(DISPLAY_POLL_MS, undefined, { signal: either }).catch(() => undefined);
65
+ if (signal?.aborted)
66
+ return fail("aborted", "create was aborted while the display came up");
67
+ }
68
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,68 @@
1
+ // The entry a Docker computer's egress proxy container runs (egress.ts makes the container):
2
+ //
3
+ // node egress-main.js --socket <path> --deadline <ISO time> --allow <entries,...> [--local <addresses,...>] [--hint <words>]
4
+ //
5
+ // It refuses to start, exit 2 and why on stdout, with no list, an empty one or a bad entry (a proxy with none would reach
6
+ // every public host), with no socket, or with no deadline it can read. Started, it logs "egress ready allow=<list>" once
7
+ // its socket listens, then one line per decision. It ends, exit 0 and its socket removed, on SIGTERM or SIGINT and at
8
+ // the deadline, the computer's own: an orphaned proxy forwards nothing past its computer's end. `--local` is the Docker
9
+ // host's own addresses, refused as this host's. It imports only node: modules and the proxy: it runs in a bare Node image.
10
+ import { EGRESS_READY, parseAllow, startEgressProxy } from "./egress-proxy.js";
11
+ /** Connections open at once through one computer's proxy, and in all for its life: serve's, for one run's box. */
12
+ const MAX_TUNNELS = 64;
13
+ const MAX_CONNECTIONS = 20_000;
14
+ /** The longest a Node timer holds; a later deadline is waited for in steps of it. */
15
+ const MAX_TIMER_MS = 2_147_483_647;
16
+ const FLAGS = new Set(["--socket", "--deadline", "--allow", "--local", "--hint"]);
17
+ const say = (line) => process.stdout.write(`${line}\n`);
18
+ const refuse = (why) => {
19
+ say(`egress: ${why}, so the proxy does not start`);
20
+ process.exit(2);
21
+ };
22
+ const given = new Map();
23
+ const argv = process.argv.slice(2);
24
+ for (let at = 0; at < argv.length; at += 2) {
25
+ const flag = argv[at];
26
+ if (!FLAGS.has(flag) || given.has(flag) || at + 1 >= argv.length)
27
+ refuse(`${JSON.stringify(flag)} is not one of ${[...FLAGS].join(", ")}, each once and with a value`);
28
+ given.set(flag, argv[at + 1]);
29
+ }
30
+ let allow = [];
31
+ try {
32
+ allow = parseAllow(given.get("--allow") ?? "");
33
+ }
34
+ catch (error) {
35
+ refuse(`its list is not one (${error.message})`);
36
+ }
37
+ if (allow.length === 0)
38
+ refuse("no host list was given: one with none would reach every public host");
39
+ const socketPath = given.get("--socket") ?? "";
40
+ if (!socketPath.startsWith("/"))
41
+ refuse("no socket path was given");
42
+ const deadline = Date.parse(given.get("--deadline") ?? "");
43
+ if (Number.isNaN(deadline))
44
+ refuse("no deadline was given as an ISO time");
45
+ const local = (given.get("--local") ?? "").split(",").filter(Boolean);
46
+ const proxy = await startEgressProxy({
47
+ socketPath,
48
+ maxTunnels: MAX_TUNNELS,
49
+ maxConnections: MAX_CONNECTIONS,
50
+ log: say,
51
+ allow,
52
+ alsoLocal: () => local,
53
+ ...(given.has("--hint") ? { allowHint: given.get("--hint") } : {}),
54
+ });
55
+ say(`${EGRESS_READY} allow=${allow.join(",")}`);
56
+ const end = (why) => {
57
+ say(`egress: ${why}, the proxy ends`);
58
+ void proxy.close().finally(() => process.exit(0));
59
+ };
60
+ for (const signal of ["SIGTERM", "SIGINT"])
61
+ process.once(signal, () => end(`${signal} came`));
62
+ const wait = () => {
63
+ const left = deadline - Date.now();
64
+ if (left <= 0)
65
+ return end(`the deadline ${new Date(deadline).toISOString()} has come`);
66
+ setTimeout(wait, Math.min(left, MAX_TIMER_MS));
67
+ };
68
+ wait();
@@ -0,0 +1,53 @@
1
+ import { type Socket } from "node:net";
2
+ /** `dns.lookup` with `{ all: true }`: every address a name resolves to. */
3
+ export type EgressLookup = (hostname: string, options: {
4
+ all: true;
5
+ verbatim: true;
6
+ }, callback: (error: NodeJS.ErrnoException | null, addresses: {
7
+ address: string;
8
+ family: number;
9
+ }[]) => void) => void;
10
+ export interface EgressProxyOptions {
11
+ /** Where the socket is made: a path in a directory on this machine, never one other hosts mount. A socket there that
12
+ * refuses a connection (its proxy died without removing it) is replaced; one that answers is a live proxy's, and the
13
+ * start is refused (`egress_socket_in_use`); anything else there is refused and left as it is
14
+ * (`egress_socket_path_taken`). */
15
+ socketPath: string;
16
+ /** Connections open at once (tunnels and forwarded requests), past which a new one is refused. */
17
+ maxTunnels: number;
18
+ /** Connections in all, for the proxy's life, past which a new one is refused. */
19
+ maxConnections: number;
20
+ /** One line per decision: the host, the port, the address and the class. */
21
+ log: (line: string) => void;
22
+ /** How a name is resolved (a test's seam). Default: `dns.lookup`. */
23
+ lookup?: EgressLookup;
24
+ /** How a connection is opened to an address the table passed, in its canonical text (a test's seam). Default:
25
+ * `net.connect`. Only an address that was checked ever reaches it. */
26
+ dial?: (address: string, port: number) => Socket;
27
+ /** More addresses to refuse as this host's, beside the interfaces read at each dial: the Docker host's own, which the
28
+ * proxy container cannot see. It can only refuse more. */
29
+ alsoLocal?: () => readonly string[];
30
+ /** The only hosts reached, as parseAllow takes them: exact names, `*.suffix` for the names below one, and CIDRs. Set,
31
+ * every other host, any IP literal outside a listed CIDR, and any port but 80 and 443 are refused 403 (SOCKS reply 2,
32
+ * class `not-listed`) before any lookup. Absent, every public host is reached. */
33
+ allow?: string | readonly string[];
34
+ /** What a refusal for a host off the list says to do, after its words (the caller's, which knows its settings):
35
+ * printable ASCII, since it goes into the status line; anything else refuses the start. */
36
+ allowHint?: string;
37
+ }
38
+ /**
39
+ * A list from its entries, or a comma list of them: each lowercased, a name's trailing dot dropped, the repeats gone.
40
+ * An entry is a name of two labels or more, `*.` and one, or a CIDR (cidrOf: its host bits zero, over no range the
41
+ * address rule refuses). Throws in words, naming the entry, for anything else: an address with no prefix, a port, a URL,
42
+ * a bare `*`.
43
+ */
44
+ export declare function parseAllow(entries: string | readonly string[]): string[];
45
+ /** The ports a list opens: plain HTTP and HTTPS. */
46
+ export declare const LISTED_PORTS: readonly number[];
47
+ /** What the proxy container's entry (egress-main.ts) logs once its socket listens: the provider waits for it. */
48
+ export declare const EGRESS_READY = "egress ready";
49
+ export interface EgressProxy {
50
+ readonly socketPath: string;
51
+ close(): Promise<void>;
52
+ }
53
+ export declare function startEgressProxy(options: EgressProxyOptions): Promise<EgressProxy>;