@parcha/agentrun-computer 0.1.0-beta.33 → 0.1.0-beta.34

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 (59) hide show
  1. package/README.md +169 -15
  2. package/dist/browser.d.ts +1 -1
  3. package/dist/browser.js +6 -3
  4. package/dist/browserbase.d.ts +3 -1
  5. package/dist/browserbase.js +3 -1
  6. package/dist/child.d.ts +2 -0
  7. package/dist/child.js +13 -2
  8. package/dist/chrome.d.ts +73 -0
  9. package/dist/chrome.js +224 -0
  10. package/dist/computerd-linux-amd64 +0 -0
  11. package/dist/computerd-linux-arm64 +0 -0
  12. package/dist/conformance/cases/gpu.d.ts +2 -0
  13. package/dist/conformance/cases/gpu.js +108 -0
  14. package/dist/conformance/cases/health.js +83 -3
  15. package/dist/conformance/cases/index.js +2 -0
  16. package/dist/conformance/cases/mount.d.ts +8 -1
  17. package/dist/conformance/cases/mount.js +4 -3
  18. package/dist/conformance/cases/provider.js +14 -0
  19. package/dist/conformance/cli.js +46 -7
  20. package/dist/conformance/local.d.ts +30 -0
  21. package/dist/conformance/local.js +36 -0
  22. package/dist/conformance/report.js +10 -5
  23. package/dist/conformance/runner.js +45 -13
  24. package/dist/conformance/types.d.ts +63 -16
  25. package/dist/daytona.d.ts +32 -3
  26. package/dist/daytona.js +96 -24
  27. package/dist/docker.d.ts +3 -1
  28. package/dist/docker.js +11 -3
  29. package/dist/drift.d.ts +3 -1
  30. package/dist/drift.js +9 -0
  31. package/dist/e2b.d.ts +3 -1
  32. package/dist/e2b.js +7 -4
  33. package/dist/index.d.ts +4 -2
  34. package/dist/index.js +4 -2
  35. package/dist/isolation.d.ts +0 -2
  36. package/dist/isolation.js +0 -16
  37. package/dist/kernel.d.ts +3 -1
  38. package/dist/kernel.js +3 -1
  39. package/dist/kinds.d.ts +10 -4
  40. package/dist/kinds.js +26 -6
  41. package/dist/labels.d.ts +6 -0
  42. package/dist/labels.js +26 -1
  43. package/dist/local-supervisor.d.ts +51 -0
  44. package/dist/local-supervisor.js +221 -0
  45. package/dist/local.d.ts +89 -0
  46. package/dist/local.js +472 -0
  47. package/dist/modal.d.ts +31 -4
  48. package/dist/modal.js +90 -30
  49. package/dist/orgo.d.ts +3 -1
  50. package/dist/orgo.js +14 -27
  51. package/dist/phone-harness.d.ts +3 -1
  52. package/dist/phone-harness.js +7 -4
  53. package/dist/protocol.d.ts +20 -0
  54. package/dist/protocol.js +9 -0
  55. package/dist/provider.d.ts +63 -3
  56. package/dist/provider.js +28 -0
  57. package/dist/providers.d.ts +7 -1
  58. package/dist/providers.js +1 -0
  59. package/package.json +1 -1
package/dist/modal.js CHANGED
@@ -1,4 +1,4 @@
1
- // The Modal provisioner, VM runtime only: every call through the host's own Modal JS SDK client, of which this package
1
+ // The Modal provisioner, on the VM runtime, and on gVisor for a GPU computer (Modal's one GPU runtime): every call through the host's own Modal JS SDK client, of which this package
2
2
  // names only the slice it uses (ModalSdk) and imports nothing. Every SDK fact below is cited in the README's Modal
3
3
  // section, from modal-client@64880502 (js/src) and Modal's docs.
4
4
  import { createHash, randomBytes } from "node:crypto";
@@ -12,15 +12,36 @@ import { releaseOlder } from "./janitor.js";
12
12
  import { EPOCH_LABEL, epochOf, RUN_LABEL } from "./labels.js";
13
13
  import { checkMount, readBackOf } from "./mount.js";
14
14
  import { ARCHIL_HELPER, ARCHIL_MOUNT_LABEL, ARCHIL_TOOL_UID, archilMount, archilRefusals, archilRelease, claimEpoch, mountDrift, readArchilMount, recordedArchil as recordedArchilOf, syncingClient, } from "./mount-archil.js";
15
- import { checkLifetime, } from "./provider.js";
15
+ import { checkGpu, checkLifetime, } from "./provider.js";
16
16
  import { fail, ok } from "./result.js";
17
17
  import { daemonWatch } from "./screen-watch.js";
18
18
  import { connectionError } from "./test-connection.js";
19
19
  import { waitUntil } from "./wait.js";
20
20
  /** The mount kinds a Modal computer takes, as capabilities().mount declares them: the run's folder on an Archil disk. */
21
21
  export const MOUNT = ["archil"];
22
- /** The machine kind and groups of its one configuration: a linux computer. */
23
- export const CAPABILITIES = [{ kind: "linux", groups: ["exec", "files", "processes"] }];
22
+ /** The network a Modal computer's programs get: none, a network of their own (isolation.ts OWN_NETWORK_ONLY). */
23
+ export const NETWORK = ["none"];
24
+ /**
25
+ * The GPU types Modal takes, by its own names (guide/gpu, 11-10): "A100" is the 40 GB one, "A100-40GB" its explicit
26
+ * name. Its "H100!" and "B200+" variants (no upgrade to an H200; a B200 or B300) are not offered: what a computer gets
27
+ * should be what it asked for.
28
+ */
29
+ export const MODAL_GPU_TYPES = ["T4", "L4", "A10", "L40S", "A100", "A100-40GB", "A100-80GB", "RTX-PRO-6000", "H100", "H200", "B200", "B300"];
30
+ /** The most GPUs Modal gives one container: 8 (guide/gpu; an A10 container takes at most 4, which Modal refuses in words past). */
31
+ export const MODAL_GPU_MAX = 8;
32
+ /**
33
+ * The GPUs Modal offers, as capabilities().gpu and CAPABILITIES declare them: on gVisor, Modal's one GPU runtime;
34
+ * preemptible, as Modal may end a GPU container to free capacity; no mount yet, the Archil client's FUSE mount not
35
+ * being proven on gVisor; and the loopback fence made inside a user namespace, as gVisor's root may not make a network
36
+ * namespace itself (a live probe, 11-11: unshare -n refused, unshare -Urn allowed).
37
+ */
38
+ export const MODAL_GPU = Object.freeze({ types: [...MODAL_GPU_TYPES], max: MODAL_GPU_MAX, isolation: "gvisor", preemptible: true, mounts: [], fence: "userns-netns" });
39
+ /** A copy of MODAL_GPU, so no caller can change the provider's own. */
40
+ const modalGpuCapability = () => ({ ...MODAL_GPU, types: [...MODAL_GPU.types], mounts: [] });
41
+ /** A GPU as the SDK takes it: the type, then :count past one ("T4", "H100:8"). */
42
+ const modalGpu = ({ type, count }) => (count === 1 ? type : `${type}:${count}`);
43
+ /** The machine kind, groups and GPUs of its one configuration: a linux computer, with GPUs when asked. */
44
+ export const CAPABILITIES = [{ kind: "linux", groups: ["exec", "files", "processes"], gpu: modalGpuCapability() }];
24
45
  /** A registry tag for linux/amd64 that Modal can pull: the default when a setting names no image. */
25
46
  export const MODAL_DEFAULT_IMAGE = "debian:bookworm-slim";
26
47
  /** The SDK's default server (modal-client@64880502:js/src/config.ts:143). */
@@ -137,6 +158,7 @@ const DEFAULT_TIMEOUTS = {
137
158
  uploadMs: 300_000,
138
159
  releaseMs: 120_000,
139
160
  releasePollMs: 500,
161
+ endedMs: 30_000,
140
162
  mountMs: 120_000,
141
163
  };
142
164
  /** The user an Archil computer's tools run as: the image's agentrun-tool, with no sudo and no capability. */
@@ -221,7 +243,8 @@ const HOLD_SCRIPT = [
221
243
  /**
222
244
  * Init's arguments, after the daemon's path: the one place they are built, for the image route's command and the
223
245
  * entrypoint alike. Init and every tool run in a network namespace of their own, loopback alone (--own-network), an
224
- * Archil computer's too: its archil client and serve run through exec as root, outside it.
246
+ * Archil computer's too: its archil client and serve run through exec as root, outside it. Init makes it itself, or, on
247
+ * gVisor (a GPU computer's runtime), where root may not, inside a user namespace; hello says which (fence).
225
248
  */
226
249
  function initArgs({ deadline, user }) {
227
250
  return ["init", "--deadline", deadline, "--user", user, "--own-network"];
@@ -246,7 +269,7 @@ export function modalCommands({ deadline = "", user = TOOL_USER, waitSeconds = 3
246
269
  const DEFAULT_PROBE_TARGETS = ["1.1.1.1:443", "8.8.8.8:443", "[2606:4700:4700::1111]:443", "1.1.1.1:53/udp", "[2606:4700:4700::1111]:53/udp"];
247
270
  /** How long close waits for the stdio bridge to exit once its stdin has ended. Modal has no kill for an exec. */
248
271
  const CLOSE_WAIT_MS = 5_000;
249
- const SPEC_FIELDS = new Set(["image", "lifetimeMs", "network", "cpus", "memoryMb", "pids", "labels", "workdir", "user", "mount"]);
272
+ const SPEC_FIELDS = new Set(["image", "lifetimeMs", "network", "cpus", "memoryMb", "pids", "labels", "workdir", "user", "mount", "gpu"]);
250
273
  const NUL = "a NUL byte cannot be passed to Modal";
251
274
  const FIXED = "a Modal computer's network is fixed at create: Modal cannot update the policy of a sandbox made with blockNetwork, and updates only an allowlist set at create; create a new computer";
252
275
  const STOP = "Modal has no stop that keeps a sandbox: terminate is a sandbox's only end, and a sandbox that has finished cannot run again; release it with delete";
@@ -290,6 +313,10 @@ function codeOf(error) {
290
313
  // gRPC's UNAUTHENTICATED and PERMISSION_DENIED: a token Modal refused.
291
314
  if (code === 16 || code === 7)
292
315
  return "denied";
316
+ // gRPC's FAILED_PRECONDITION on an exec: the sandbox is ending on its own ("Modal Sandbox is shutting down", from
317
+ // TaskExecStart, when its command, init, has exited). Gone, so create waits to read why.
318
+ if (code === 9)
319
+ return "gone";
293
320
  return "modal";
294
321
  }
295
322
  /** Settles with the promise's result, or a timeout or abort in words once ms pass or signal aborts. */
@@ -454,8 +481,12 @@ function probeDrift(probe, expected) {
454
481
  const user = `${probe.uid}:${probe.gid}`;
455
482
  if (expected.user !== undefined && user !== expected.user)
456
483
  found.push(`user: declared ${expected.user}, read back ${user} (the uid:gid the daemon's programs run as)`);
457
- if (/gvisor/i.test(probe.kernel))
484
+ // The probe's kernel is the only runtime read-back: gVisor exactly for a GPU computer, a VM's kernel for every other.
485
+ const gvisor = /gvisor/i.test(probe.kernel);
486
+ if (expected.runtime === "vm" && gvisor)
458
487
  found.push(`runtime: declared vm, read back gVisor (the kernel reports ${JSON.stringify(probe.kernel)})`);
488
+ if (expected.runtime === "gvisor" && !gvisor)
489
+ found.push(`runtime: declared gVisor (a GPU computer), read back another kernel (${JSON.stringify(probe.kernel)})`);
459
490
  if (expected.network === "none")
460
491
  found.push(...probeNetworkDrift(probe));
461
492
  // Its own network: the live interfaces lo alone (a kernel's quiet tunnels are none), and none it could bring up.
@@ -474,7 +505,7 @@ function tagDrift(given, read) {
474
505
  return found;
475
506
  }
476
507
  /**
477
- * Computers that are Modal sandboxes on the VM runtime. The daemon is uploaded right after create, streamed through an
508
+ * Computers that are Modal sandboxes on the VM runtime, or on gVisor with a GPU. The daemon is uploaded right after create, streamed through an
478
509
  * exec's stdin, while the sandbox's command, a small sh entrypoint, waits for it and then becomes `computerd init`; or,
479
510
  * with daemonImage, it comes in as a layer of the computer's image (COPY --from) and is the command itself. A
480
511
  * connection is `computerd stdio` through exec, so a computer with network none is still reached, and needs no network
@@ -558,7 +589,7 @@ export class ModalProvider {
558
589
  return {
559
590
  kind: "linux",
560
591
  lifetime: "vendor",
561
- network: ["none"],
592
+ network: [...NETWORK],
562
593
  networkReadBack: false,
563
594
  isolation: "vm",
564
595
  os: "linux",
@@ -570,12 +601,15 @@ export class ModalProvider {
570
601
  release: ["delete"],
571
602
  mount: [...MOUNT],
572
603
  vendorAgentPorts: [],
604
+ // A GPU computer runs on gVisor, Modal's one GPU runtime (gpu.isolation): isolation vm is every other computer's.
605
+ gpu: modalGpuCapability(),
573
606
  };
574
607
  }
575
- /** What hello must report: this package's version, the kind and groups declared, and Modal's one architecture. */
608
+ /** What hello must report: this package's version, the kind and groups declared, Modal's one architecture, and the
609
+ * fence init --own-network holds its programs behind (either way: hello says which, and create notes it). */
576
610
  #expected() {
577
611
  const { kind, groups } = this.capabilities();
578
- return { version: VERSION, kind, groups, arch: "amd64" };
612
+ return { version: VERSION, kind, groups, arch: "amd64", fence: true };
579
613
  }
580
614
  check(spec) {
581
615
  const refusals = [];
@@ -620,13 +654,13 @@ export class ModalProvider {
620
654
  if (archil && user !== undefined && !isRootUser(user) && userOf(user) !== ARCHIL_USER) {
621
655
  refuse("user", `a computer with an Archil mount runs its tools as agentrun-tool, ${ARCHIL_USER}, the user its image makes with no way to root; leave user unset or ask for ${ARCHIL_USER}`);
622
656
  }
657
+ // A GPU computer runs on gVisor, Modal's one GPU runtime, where the Archil client's FUSE mount is not yet proven:
658
+ // its gpu.mounts is empty, so checkGpu refuses a GPU with a mount.
659
+ refusals.push(...checkGpu(given.gpu, this.capabilities(), mount));
623
660
  for (const [field, value] of Object.entries(given)) {
624
661
  if (SPEC_FIELDS.has(field) || value === undefined)
625
662
  continue;
626
- if (field === "gpu")
627
- refuse(field, "this provider makes VM computers, and Modal offers GPUs on the gVisor runtime only");
628
- else
629
- refuse(field, `a Modal computer does not support ${field}`);
663
+ refuse(field, `a Modal computer does not support ${field}`);
630
664
  }
631
665
  return refusals;
632
666
  }
@@ -665,8 +699,10 @@ export class ModalProvider {
665
699
  cpus,
666
700
  memoryMb,
667
701
  workdir,
668
- runtime: "vm",
702
+ // Modal offers GPUs on gVisor only: a GPU computer's runtime, read back by the probe's kernel like a VM's.
703
+ runtime: spec.gpu === undefined ? "vm" : "gvisor",
669
704
  ...(archil === undefined ? {} : { mount: readBackOf(archil.mount, archil.epoch) }),
705
+ ...(spec.gpu === undefined ? {} : { gpu: { type: spec.gpu.type, count: spec.gpu.count } }),
670
706
  };
671
707
  const tags = { ...spec.labels, [COMPUTER_LABEL]: "1", [NAME_TAG]: name, [DEADLINE_LABEL]: deadline, [SPEC_TAG]: JSON.stringify(recorded) };
672
708
  // With daemonImage the daemon comes in as a layer of the computer's own image, there before the command starts.
@@ -700,7 +736,8 @@ export class ModalProvider {
700
736
  : modalCommands({ deadline, user, waitSeconds: Math.ceil(waitMs / 1000), home: WORK, ...(gate === undefined ? {} : { gate }) }).entrypoint;
701
737
  const cpuLimit = cpus / CPUS_PER_CORE;
702
738
  const params = {
703
- runtime: "vm",
739
+ runtime: recorded.runtime,
740
+ ...(spec.gpu === undefined ? {} : { gpu: modalGpu(spec.gpu) }),
704
741
  command,
705
742
  // Modal ends the sandbox at its timeout: the lifetime, in the whole seconds the SDK takes.
706
743
  timeoutMs: Math.ceil(spec.lifetimeMs / 1000) * 1000,
@@ -751,17 +788,22 @@ export class ModalProvider {
751
788
  if (checked.ok)
752
789
  return ok(checked.value.length > 0 ? { ...ref, notes: checked.value } : ref);
753
790
  // Read before the terminate, which would end it with its own code: whether the sandbox's command had already ended.
754
- const why = await this.#endedWords(sandbox, archil?.mount.token, signal);
791
+ // A sandbox Modal says is ending on its own (gone) is waited for, bounded, so its command's exit and words are read.
792
+ const why = await this.#endedWords(sandbox, name, archil?.mount.token, checked.error.code === "gone", signal);
755
793
  await letGo();
756
794
  const after = await this.#terminate(sandbox, name, signal);
757
795
  return fail(checked.error.code, `the computer ${name} ${after}: ${checked.error.message}${why}`);
758
796
  }
759
797
  /**
760
798
  * When a create's sandbox has already finished, its command's exit code and the tail of its output (stdout, then
761
- * stderr; the token, if any, cut), in words to append; nothing while it runs or when that cannot be read.
799
+ * stderr; the token, if any, cut), in words to append; nothing while it runs or when that cannot be read. With
800
+ * `ending` (Modal said the sandbox is shutting down), first waits up to endedMs for poll to read it finished: Modal
801
+ * ends a sandbox asynchronously, and poll reads null until then, so its command's words would be lost.
762
802
  */
763
- async #endedWords(sandbox, token, signal) {
764
- const { callMs } = this.#timeouts;
803
+ async #endedWords(sandbox, name, token, ending, signal) {
804
+ const { callMs, endedMs, releasePollMs } = this.#timeouts;
805
+ if (ending)
806
+ await untilFinished(() => sandbox.poll(), { name, boundMs: endedMs, callMs, minMs: Math.min(releasePollMs, RELEASE_POLL_MAX_MS), maxMs: RELEASE_POLL_MAX_MS, signal });
765
807
  const polled = await call("poll of the sandbox", () => sandbox.poll(), callMs, signal);
766
808
  if (!polled.ok || polled.value === null)
767
809
  return "";
@@ -905,10 +947,14 @@ export class ModalProvider {
905
947
  const found = [
906
948
  ...tagDrift(tags, read.value),
907
949
  ...helloDrift(inside.value.hello, this.#expected()),
908
- ...probeDrift(inside.value.probe, { user: recorded.user, network: recorded.network }),
950
+ ...probeDrift(inside.value.probe, { user: recorded.user, network: recorded.network, runtime: recorded.runtime }),
909
951
  ...(archil === undefined ? [] : mountDrift(archil.expected, inside.value.mount)),
910
952
  ];
911
- return found.length === 0 ? ok(probeNotes(inside.value.probe, recorded.network)) : fail("refused", `it did not match its spec: ${found.join("; ")}`);
953
+ if (found.length > 0)
954
+ return fail("refused", `it did not match its spec: ${found.join("; ")}`);
955
+ // Which way init fenced its programs, as hello read it back: said once a way other than the plain one was taken.
956
+ const fence = inside.value.hello.fence === "userns-netns" ? [`fence: userns-netns: init made its programs' network namespace inside a user namespace of its own, as root on ${recorded.runtime} may not make one itself`] : [];
957
+ return ok([...probeNotes(inside.value.probe, recorded.network), ...fence]);
912
958
  }
913
959
  /** One connection's hello and the probe through it, and an Archil computer's mount read back, the connection closed after. */
914
960
  async #inside(sandbox, name, signal, patient = false, archil) {
@@ -1160,10 +1206,12 @@ export class ModalProvider {
1160
1206
  if (typeof recorded === "string")
1161
1207
  found.push(recorded);
1162
1208
  else {
1163
- if (recorded.runtime !== "vm")
1164
- found.push(`runtime: the tag ${SPEC_TAG} says ${show(recorded.runtime)}; this provider makes vm computers`);
1165
- const { image, network, cpus, memoryMb, workdir, user } = recorded;
1166
- const refusals = this.check({ image, lifetimeMs: 1, network, cpus, memoryMb, workdir, user });
1209
+ // gvisor exactly for a GPU computer, vm for every other: anything else this provider never makes.
1210
+ const runtime = recorded.gpu === undefined ? "vm" : "gvisor";
1211
+ if (recorded.runtime !== runtime)
1212
+ found.push(`runtime: the tag ${SPEC_TAG} says ${show(recorded.runtime)}; this provider makes ${runtime} computers ${recorded.gpu === undefined ? "with no GPU" : "with a GPU"}`);
1213
+ const { image, network, cpus, memoryMb, workdir, user, gpu } = recorded;
1214
+ const refusals = this.check({ image, lifetimeMs: 1, network, cpus, memoryMb, workdir, user, ...(gpu === undefined ? {} : { gpu }) });
1167
1215
  found.push(...refusals.map(({ field, message }) => `${field}: ${message}, as recorded at create`));
1168
1216
  // No exec in a computer whose user is root: the bridge would run what that user could have replaced.
1169
1217
  if (isRootUser(user))
@@ -1176,18 +1224,30 @@ export class ModalProvider {
1176
1224
  const { hello, probe, mount } = inside.value;
1177
1225
  found.push(...helloDrift(hello, this.#expected()));
1178
1226
  if (typeof recorded !== "string")
1179
- found.push(...probeDrift(probe, { user: recorded.user, network: recorded.network }));
1227
+ found.push(...probeDrift(probe, { user: recorded.user, network: recorded.network, runtime: recorded.runtime }));
1180
1228
  // The mount read back from inside is the one the spec tag records, under the computer's epoch label.
1181
1229
  if (archil !== undefined)
1182
1230
  found.push(...mountDrift(archil.expected, mount));
1183
1231
  if (found.length > 0 || typeof recorded === "string" || deadline === undefined) {
1184
1232
  return fail("refused", `the computer ${name} does not match this provider, so attach refuses it and it is left as it is: ${found.join("; ")}`);
1185
1233
  }
1186
- const { image, network, cpus, memoryMb, workdir } = recorded;
1234
+ const { image, network, cpus, memoryMb, workdir, gpu } = recorded;
1187
1235
  const notes = probeNotes(probe, network);
1188
1236
  return ok({
1189
1237
  ...ref,
1190
- spec: { image, user: `${probe.uid}:${probe.gid}`, network, cpus, memoryMb, workdir, deadline, kind: hello.kind, ...(archil === undefined || mount === undefined ? {} : { mount }) },
1238
+ spec: {
1239
+ image,
1240
+ user: `${probe.uid}:${probe.gid}`,
1241
+ network,
1242
+ cpus,
1243
+ memoryMb,
1244
+ workdir,
1245
+ deadline,
1246
+ kind: hello.kind,
1247
+ ...(archil === undefined || mount === undefined ? {} : { mount }),
1248
+ // Modal reads no GPU back: what create recorded, on a computer the probe read as gVisor, Modal's GPU runtime.
1249
+ ...(gpu === undefined ? {} : { gpu }),
1250
+ },
1191
1251
  ...(notes.length > 0 ? { notes } : {}),
1192
1252
  });
1193
1253
  }
package/dist/orgo.d.ts CHANGED
@@ -1,11 +1,13 @@
1
1
  import type { KindCapabilities } from "./kinds.js";
2
2
  import { type MountKind } from "./mount.js";
3
3
  import { type OrgoChannel, type OrgoStart, type OrgoWebSocketFactory } from "./orgo-channel.js";
4
- import { type AttachedComputer, type CallContext, type ComputerCapabilities, type ComputerConnection, type ComputerInfo, type ComputerProvider, type ComputerRef, type ComputerSpec, type CreatedComputer, type NetworkPolicy, type NetworkSpec, type Refusal } from "./provider.js";
4
+ import { type AttachedComputer, type CallContext, type ComputerCapabilities, type ComputerConnection, type ComputerInfo, type ComputerProvider, type ComputerRef, type ComputerSpec, type CreatedComputer, type NetworkForm, type NetworkPolicy, type NetworkSpec, type Refusal } from "./provider.js";
5
5
  import { type Result } from "./result.js";
6
6
  import { type ScreenWatch, type ScreenWatchHandlers, type WatchOptions } from "./screen-watch.js";
7
7
  /** The mount kinds an Orgo computer takes: none yet (an Archil mount needs an Orgo template that bakes the helper). */
8
8
  export declare const MOUNT: readonly MountKind[];
9
+ /** The network an Orgo desktop's programs get: none, a network of their own. */
10
+ export declare const NETWORK: readonly NetworkForm[];
9
11
  /** What a built provider declares, known without building one: one configuration, a Linux desktop (the registry's entry). */
10
12
  export declare const CAPABILITIES: readonly KindCapabilities[];
11
13
  /** The conformance CLI's module for Orgo: its live switch, the run's 1 h cap and the drifted twin. */
package/dist/orgo.js CHANGED
@@ -18,15 +18,17 @@ import { childCommands, daemonDrift } from "./child.js";
18
18
  import { DaemonClient } from "./client.js";
19
19
  import { DESKTOP_GROUPS } from "./desktop.js";
20
20
  import { COMPUTER_LABEL, DAEMON_IN_COMPUTER, helloDrift, probeNetworkDrift, probeNotes, probeReportOf, SOCKET_DIR, WORK } from "./drift.js";
21
- import { EPOCH_LABEL, RUN_LABEL } from "./labels.js";
21
+ import { EPOCH_LABEL, RUN_HASH_LABEL, RUN_LABEL, runHash } from "./labels.js";
22
22
  import { checkMount } from "./mount.js";
23
23
  import { ORGO_API_URL, orgoRest, orgoTerminalChannel, START_LOG } from "./orgo-channel.js";
24
- import { checkLifetime, } from "./provider.js";
24
+ import { checkGpu, checkLifetime, } from "./provider.js";
25
25
  import { fail, ok } from "./result.js";
26
26
  import { daemonWatch } from "./screen-watch.js";
27
27
  import { listTested } from "./test-connection.js";
28
28
  /** The mount kinds an Orgo computer takes: none yet (an Archil mount needs an Orgo template that bakes the helper). */
29
29
  export const MOUNT = [];
30
+ /** The network an Orgo desktop's programs get: none, a network of their own. */
31
+ export const NETWORK = ["none"];
30
32
  /** The groups every Orgo computer offers: a Linux shell, files and processes, and the desktop's screen and input. */
31
33
  const GROUPS = ["exec", "files", "processes", ...DESKTOP_GROUPS];
32
34
  /** What a built provider declares, known without building one: one configuration, a Linux desktop (the registry's entry). */
@@ -64,10 +66,11 @@ const STAGING = "/tmp/agentrun-computerd-";
64
66
  const LISTEN_RETRY_MS = 250;
65
67
  /** How often a delete that answers 409 (the computer waking) is tried again. */
66
68
  const DELETE_TRIES = 5;
67
- const SPEC_FIELDS = new Set(["image", "lifetimeMs", "network", "cpus", "memoryMb", "labels"]);
69
+ const SPEC_FIELDS = new Set(["image", "lifetimeMs", "network", "cpus", "memoryMb", "labels", "gpu"]);
68
70
  /** The states in which a computer runs, or is on its way to. */
69
71
  const RUNNING = new Set(["running", "creating", "restarting", "updating", "resuming"]);
70
- const NETWORK = 'an Orgo computer takes network "none" only: Orgo has no egress control, so its tools have no network of their own (init\'s namespace holds them to loopback), and open or an allowlist waits for the proxy-backed feature';
72
+ /** Why a network other than "none" is refused (NETWORK is the forms it makes). */
73
+ const NETWORK_REFUSAL = 'an Orgo computer takes network "none" only: Orgo has no egress control, so its tools have no network of their own (init\'s namespace holds them to loopback), and open or an allowlist waits for the proxy-backed feature';
71
74
  /** The scripts the provider runs as root, each marked on its first line, its arguments after it. */
72
75
  const X11_SCRIPT = ["# agentrun-computer: orgo-x11", "s=$1", '[ -S "$s" ] || { echo "no X socket at $s"; exit 1; }'].join("\n");
73
76
  const LABELS_SCRIPT = ["# agentrun-computer: orgo-labels", 'p=$1; t=$2; d=${p%/*}', 'mkdir -p "$d" && printf \'%s\' "$t" > "$p.part" && chmod 0644 "$p.part" && mv -f "$p.part" "$p"'].join("\n");
@@ -138,25 +141,6 @@ const pause = (ms, signal) => new Promise((done) => {
138
141
  else
139
142
  signal?.addEventListener("abort", finish, { once: true });
140
143
  });
141
- /** The run label's hash, as a name carries it: base32 of its sha256, lower case, 16 letters. */
142
- function runHash(run) {
143
- const alphabet = "abcdefghijklmnopqrstuvwxyz234567";
144
- const bytes = createHash("sha256").update(run, "utf8").digest();
145
- let bits = 0;
146
- let value = 0;
147
- let out = "";
148
- for (const byte of bytes) {
149
- value = (value << 8) | byte;
150
- bits += 8;
151
- while (bits >= 5 && out.length < 16) {
152
- out += alphabet[(value >>> (bits - 5)) & 31];
153
- bits -= 5;
154
- }
155
- if (out.length >= 16)
156
- break;
157
- }
158
- return out;
159
- }
160
144
  /**
161
145
  * The name of a computer with these labels: computer-<hex>, then -r<the run label's hash> and -e<the epoch label> when
162
146
  * the labels carry a run and an epoch that is one, then -d<the deadline> when given: whole seconds since the epoch,
@@ -303,7 +287,7 @@ export class OrgoProvider {
303
287
  return {
304
288
  kind: "desktop",
305
289
  lifetime: "janitor",
306
- network: ["none"],
290
+ network: [...NETWORK],
307
291
  networkReadBack: false,
308
292
  isolation: "vm",
309
293
  os: "linux",
@@ -325,7 +309,7 @@ export class OrgoProvider {
325
309
  refuse("image", `an image is "${BASE}" (Orgo's base desktop) or an Orgo template, namespace/name@version`);
326
310
  refusals.push(...checkLifetime(lifetimeMs, this.capabilities()));
327
311
  if (network !== "none")
328
- refuse("network", NETWORK);
312
+ refuse("network", NETWORK_REFUSAL);
329
313
  if (memoryMb !== undefined && !RAM_GB.some((gb) => gb * 1024 === memoryMb))
330
314
  refuse("memoryMb", "memoryMb is one of Orgo's sizes: 4096, 8192, 16384 or 32768");
331
315
  if (cpus !== undefined && !CPUS.includes(cpus))
@@ -337,6 +321,7 @@ export class OrgoProvider {
337
321
  refuse("labels", bad);
338
322
  }
339
323
  refusals.push(...checkMount(mount, MOUNT));
324
+ refusals.push(...checkGpu(given.gpu, this.capabilities()));
340
325
  for (const [field, value] of Object.entries(given)) {
341
326
  if (SPEC_FIELDS.has(field) || field === "mount" || value === undefined)
342
327
  continue;
@@ -842,8 +827,10 @@ export class OrgoProvider {
842
827
  continue;
843
828
  const ref = { id: record.id, name: record.name };
844
829
  const running = RUNNING.has(record.status);
830
+ // The name keeps the run's hash, not the run: listed with no run to match, the hash is given, so a caller (serve's
831
+ // janitor) can still tell whose run a computer is.
845
832
  let read = {
846
- ...(labels[RUN_LABEL] !== undefined ? { [RUN_LABEL]: labels[RUN_LABEL] } : {}),
833
+ ...(labels[RUN_LABEL] !== undefined ? { [RUN_LABEL]: labels[RUN_LABEL] } : parts.run !== undefined ? { [RUN_HASH_LABEL]: parts.run } : {}),
847
834
  ...(parts.epoch !== undefined ? { [EPOCH_LABEL]: parts.epoch } : {}),
848
835
  };
849
836
  // The janitor's deadline is the name's; a name of an older make has none, and Orgo's end stands for it.
@@ -873,7 +860,7 @@ export class OrgoProvider {
873
860
  if (problem)
874
861
  return fail("invalid", problem);
875
862
  if (policy !== undefined && policy !== "none")
876
- return fail("refused", NETWORK);
863
+ return fail("refused", NETWORK_REFUSAL);
877
864
  const found = await this.#own(ref, signal);
878
865
  if (!found.ok)
879
866
  return found;
@@ -1,7 +1,7 @@
1
1
  import type { KindCapabilities } from "./kinds.js";
2
2
  import type { MountKind } from "./mount.js";
3
3
  import { type Group, type Rect, type UiNode } from "./protocol.js";
4
- import { type AttachedComputer, type CallContext, type ComputerCapabilities, type ComputerConnection, type ComputerInfo, type ComputerProvider, type ComputerRef, type ComputerSpec, type CreatedComputer, type NetworkPolicy, type NetworkSpec, type Refusal } from "./provider.js";
4
+ import { type AttachedComputer, type CallContext, type ComputerCapabilities, type ComputerConnection, type ComputerInfo, type ComputerProvider, type ComputerRef, type ComputerSpec, type CreatedComputer, type NetworkForm, type NetworkPolicy, type NetworkSpec, type Refusal } from "./provider.js";
5
5
  import { type Result } from "./result.js";
6
6
  import { type ScreenWatch, type ScreenWatchHandlers, type WatchOptions } from "./screen-watch.js";
7
7
  /** The phone harness's API. */
@@ -10,6 +10,8 @@ export declare const PHONE_HARNESS_URL = "https://api.phone-harness.com";
10
10
  export declare const PHONE_GROUPS: readonly Group[];
11
11
  /** A phone mounts no folder. */
12
12
  export declare const MOUNT: readonly MountKind[];
13
+ /** The network a cloud phone runs on: the vendor's own, open; it cannot be closed or narrowed. */
14
+ export declare const NETWORK: readonly NetworkForm[];
13
15
  /** The one configuration it offers, as its capabilities() declare it: the kind registry's entry holds the same. */
14
16
  export declare const CAPABILITIES: readonly KindCapabilities[];
15
17
  /** The image a phone is read back by: a cloud Android has none to choose, so a setting that names none takes this. */
@@ -14,8 +14,8 @@ import { readFileSync } from "node:fs";
14
14
  import { createConnection } from "node:net";
15
15
  import { crc32, deflateSync } from "node:zlib";
16
16
  import { checkActions } from "./actions.js";
17
- import { MAX_CHUNK_BYTES, MAX_UI_NODES, } from "./protocol.js";
18
- import { checkLifetime, } from "./provider.js";
17
+ import { MAX_CHUNK_BYTES, MAX_UI_NODES, PROTOCOL_VERSION, } from "./protocol.js";
18
+ import { checkGpu, checkLifetime, } from "./provider.js";
19
19
  import { fail, ok } from "./result.js";
20
20
  import { daemonWatch, redactWords } from "./screen-watch.js";
21
21
  import { listTested } from "./test-connection.js";
@@ -25,6 +25,8 @@ export const PHONE_HARNESS_URL = "https://api.phone-harness.com";
25
25
  export const PHONE_GROUPS = ["screen", "input.touch", "input.keys", "apps", "apps.ui_tree"];
26
26
  /** A phone mounts no folder. */
27
27
  export const MOUNT = [];
28
+ /** The network a cloud phone runs on: the vendor's own, open; it cannot be closed or narrowed. */
29
+ export const NETWORK = ["open"];
28
30
  /** The one configuration it offers, as its capabilities() declare it: the kind registry's entry holds the same. */
29
31
  export const CAPABILITIES = [{ kind: "android", groups: [...PHONE_GROUPS] }];
30
32
  /** The image a phone is read back by: a cloud Android has none to choose, so a setting that names none takes this. */
@@ -259,7 +261,7 @@ export class PhoneHarnessProvider {
259
261
  os: "android",
260
262
  daemon: "none",
261
263
  lifetime: "vendor",
262
- network: ["open"],
264
+ network: [...NETWORK],
263
265
  isolation: "vm",
264
266
  groups: [...PHONE_GROUPS],
265
267
  maxLifetimeMs: this.#maxLifetimeMs,
@@ -280,6 +282,7 @@ export class PhoneHarnessProvider {
280
282
  }
281
283
  if (spec?.mount !== undefined)
282
284
  refusals.push({ field: "mount", message: "mount: a cloud phone mounts no folder" });
285
+ refusals.push(...checkGpu(spec?.gpu, this.capabilities()));
283
286
  return refusals;
284
287
  }
285
288
  // --- the API ---------------------------------------------------------------------------------------------------
@@ -885,7 +888,7 @@ class AdbClient {
885
888
  const dpi = [...density.value.matchAll(/(\d+)/g)].at(-1);
886
889
  this.#scale = dpi ? Number(dpi[1]) / 160 : 1;
887
890
  const reported = abi.value.trim();
888
- this.#hello = { version, os: "android", kind: "android", arch: ARCH[reported] ?? reported, groups: [...PHONE_GROUPS] };
891
+ this.#hello = { protocol: PROTOCOL_VERSION, version, os: "android", kind: "android", arch: ARCH[reported] ?? reported, groups: [...PHONE_GROUPS] };
889
892
  return ok(this.#hello);
890
893
  }
891
894
  close() {
@@ -38,11 +38,21 @@ export type Group = "exec" | "files" | "processes" | "screen" | "input.pointer"
38
38
  export declare const GROUPS: readonly Group[];
39
39
  /** The groups a provider answers itself, which a computerd hello never lists. */
40
40
  export declare const PROVIDER_GROUPS: readonly Group[];
41
+ /**
42
+ * The version of this protocol: its methods, their params and results, the limits and the error kinds, as spec/computer
43
+ * publishes them. hello carries it, apart from the daemon's own version. It changes when the wire changes, not with
44
+ * each release: a minor step adds (a method, an optional field, a group), a major one changes or removes. computerd's
45
+ * Go constant (methods.ProtocolVersion) holds the same value, and a test keeps them equal.
46
+ */
47
+ export declare const PROTOCOL_VERSION = "0.1";
41
48
  export interface HelloParams {
42
49
  /** Who is asking, for the daemon's log: a name and version. */
43
50
  client: string;
44
51
  }
45
52
  export interface HelloResult {
53
+ /** The protocol version this computer speaks: PROTOCOL_VERSION. */
54
+ protocol: string;
55
+ /** The daemon's own version (with daemon none, the provider's). */
46
56
  version: string;
47
57
  os: ComputerOs;
48
58
  kind: ComputerKind;
@@ -51,7 +61,17 @@ export interface HelloResult {
51
61
  groups: Group[];
52
62
  /** The DISPLAY a desktop's screen and input methods drive, such as ":99"; absent on any other computer. */
53
63
  display?: string;
64
+ /** How init holds its programs off the computer's network, when it gave them one of their own (init --own-network). */
65
+ fence?: NetworkFence;
54
66
  }
67
+ /**
68
+ * How init holds its programs off the computer's network: "netns", a network namespace init made itself as root;
69
+ * "userns-netns", one it made inside a user namespace of its own, where root may not make one (gVisor, whose root holds
70
+ * no CAP_SYS_ADMIN). Either way the programs reach their own loopback alone.
71
+ */
72
+ export type NetworkFence = "netns" | "userns-netns";
73
+ /** Every NetworkFence, as hello may report it. */
74
+ export declare const NETWORK_FENCES: readonly NetworkFence[];
55
75
  export type PingParams = Record<string, never>;
56
76
  export type PingResult = Record<string, never>;
57
77
  export interface ExecRunParams {
package/dist/protocol.js CHANGED
@@ -26,6 +26,15 @@ export const MAX_READ_WAIT_MS = 30_000;
26
26
  export const GROUPS = ["exec", "files", "processes", "screen", "input.pointer", "input.keys", "input.touch", "apps", "apps.install", "apps.ui_tree", "cdp", "stream", "downloads"];
27
27
  /** The groups a provider answers itself, which a computerd hello never lists. */
28
28
  export const PROVIDER_GROUPS = ["cdp", "stream", "downloads"];
29
+ /**
30
+ * The version of this protocol: its methods, their params and results, the limits and the error kinds, as spec/computer
31
+ * publishes them. hello carries it, apart from the daemon's own version. It changes when the wire changes, not with
32
+ * each release: a minor step adds (a method, an optional field, a group), a major one changes or removes. computerd's
33
+ * Go constant (methods.ProtocolVersion) holds the same value, and a test keeps them equal.
34
+ */
35
+ export const PROTOCOL_VERSION = "0.1";
36
+ /** Every NetworkFence, as hello may report it. */
37
+ export const NETWORK_FENCES = ["netns", "userns-netns"];
29
38
  /** The most actions one input.actions batch holds. */
30
39
  export const MAX_ACTIONS = 100;
31
40
  /**
@@ -1,10 +1,13 @@
1
1
  import type { MountKind, MountReadBack, MountSpec } from "./mount.js";
2
- import type { ComputerClient, ComputerKind, ComputerOs, Group, HelloResult } from "./protocol.js";
2
+ import type { ComputerClient, ComputerKind, ComputerOs, Group, HelloResult, NetworkFence } from "./protocol.js";
3
3
  import type { Result } from "./result.js";
4
4
  import type { ScreenWatch, ScreenWatchHandlers, WatchOptions } from "./screen-watch.js";
5
5
  export type NetworkSpec = "none" | "open" | {
6
6
  allow: string[];
7
7
  };
8
+ /** A network's form, as a provider declares the ones it makes (capabilities().network, its module's NETWORK): "allow" is
9
+ * NetworkSpec's allowlist. */
10
+ export type NetworkForm = "none" | "open" | "allow";
8
11
  export interface ComputerSpec {
9
12
  image: string;
10
13
  /** Required: a computer with no deadline is refused. */
@@ -22,6 +25,47 @@ export interface ComputerSpec {
22
25
  * refuses any other kind before a vendor call. An Archil token is never in a label, a read-back or an error.
23
26
  */
24
27
  mount?: MountSpec;
28
+ /**
29
+ * GPUs for the computer: a type the provider declares (capabilities().gpu.types, the vendor's own name, such as Modal's
30
+ * "A100-80GB" or Daytona's "H100") and how many, 1 up to capabilities().gpu.max. check() refuses one the provider does
31
+ * not declare in words before a vendor call; a provider that declares no gpu refuses any.
32
+ */
33
+ gpu?: GpuSpec;
34
+ }
35
+ /** A computer's GPUs: one type, and how many of it. */
36
+ export interface GpuSpec {
37
+ type: string;
38
+ count: number;
39
+ }
40
+ /**
41
+ * The GPUs a provider offers: the types it takes, by the vendor's own names, and the most one computer may have; and
42
+ * how a GPU computer differs from the provider's others, each stated where the vendor makes it so.
43
+ */
44
+ export interface GpuCapability {
45
+ types: string[];
46
+ max: number;
47
+ /** A GPU computer's isolation, where it is not capabilities().isolation (Modal's GPUs run on gVisor only). */
48
+ isolation?: ComputerCapabilities["isolation"];
49
+ /** The vendor may end a GPU computer to free capacity, at any time. */
50
+ preemptible?: boolean;
51
+ /** A GPU computer's stop deletes it: nothing of it is kept (Daytona: no pause, no snapshot). */
52
+ stopDeletes?: boolean;
53
+ /** The one region a GPU computer runs in, whatever the provider's own (Daytona's "earth"). */
54
+ region?: string;
55
+ /** The size a GPU computer gets for each GPU (the vendor's defaults). */
56
+ perGpu?: {
57
+ cpus: number;
58
+ memoryMb: number;
59
+ diskMb: number;
60
+ };
61
+ /** The mount kinds a GPU computer takes, where fewer than capabilities().mount: none yet proven on its GPU computers. */
62
+ mounts?: MountKind[];
63
+ /**
64
+ * How init holds a GPU computer's programs off its network, where it is not the plain network namespace: on Modal's
65
+ * gVisor, "userns-netns", one made inside a user namespace, as root there may not make one (measured). The fence holds
66
+ * either way; each computer's hello reads back the one it got.
67
+ */
68
+ fence?: NetworkFence;
25
69
  }
26
70
  /** One kind of allowlist entry a provider takes: how many a list may hold, and the ports an entry opens. */
27
71
  export interface AllowRule {
@@ -47,7 +91,8 @@ export interface ComputerCapabilities {
47
91
  kind: ComputerKind;
48
92
  /** Who ends a computer at its deadline: the vendor, or our janitor by label. */
49
93
  lifetime: "vendor" | "janitor";
50
- network: Array<"none" | "open" | "allow">;
94
+ /** The network forms it makes: its module's NETWORK, which the kind registry's entry holds too. */
95
+ network: NetworkForm[];
51
96
  /** With network "allow": what an allowlist may hold and which ports it opens. */
52
97
  allow?: AllowCapability;
53
98
  /**
@@ -56,7 +101,11 @@ export interface ComputerCapabilities {
56
101
  * once the live bypass cases pass (ruling 9).
57
102
  */
58
103
  networkReadBack?: boolean;
59
- isolation: "container" | "gvisor" | "microvm" | "vm" | "machine";
104
+ /**
105
+ * What keeps the computer's programs apart from everything else. host: they are processes of the machine the
106
+ * provider runs on, as its user (the local browser's Chrome, held only by Chrome's own sandbox and its egress proxy).
107
+ */
108
+ isolation: "container" | "gvisor" | "microvm" | "vm" | "machine" | "host";
60
109
  os: ComputerOs;
61
110
  /**
62
111
  * With release "stop": true when a stop ends in deletion (Daytona with autoDeleteMinutes 0), so release(ref, "stop")
@@ -85,6 +134,8 @@ export interface ComputerCapabilities {
85
134
  * Absent: no vendor's agent runs beside the programs (Docker). A child daemon must declare it.
86
135
  */
87
136
  vendorAgentPorts?: number[];
137
+ /** The GPUs spec.gpu may ask for. Absent: none, and check() refuses any spec.gpu. */
138
+ gpu?: GpuCapability;
88
139
  }
89
140
  /** The os and daemon modes each kind may have; no other pair is valid. */
90
141
  export declare const KIND_SHAPES: Readonly<Record<ComputerKind, {
@@ -98,6 +149,13 @@ export declare function kindRefusals({ kind, os, daemon }: Pick<ComputerCapabili
98
149
  * milliseconds above 0, and at most capabilities().maxLifetimeMs.
99
150
  */
100
151
  export declare function checkLifetime(lifetimeMs: unknown, { lifetime, maxLifetimeMs }: Pick<ComputerCapabilities, "lifetime" | "maxLifetimeMs">): Refusal[];
152
+ /**
153
+ * The one GPU rule every provider's check() shares, with no vendor call: no spec.gpu is no refusal; one given is an
154
+ * object of a declared type (capabilities().gpu.types) and a whole count from 1 to capabilities().gpu.max; a provider
155
+ * that declares no gpu refuses any. With `mount`, the spec's as given, a GPU computer takes only the kinds gpu.mounts
156
+ * names, where it names them. Serve's claim and readiness read the same rule, so a refusal reads alike wherever it is met.
157
+ */
158
+ export declare function checkGpu(gpu: unknown, { gpu: offered }: Pick<ComputerCapabilities, "gpu">, mount?: unknown): Refusal[];
101
159
  /** Why a spec is refused, in words, before any vendor call. */
102
160
  export interface Refusal {
103
161
  field: string;
@@ -130,6 +188,8 @@ export interface ReadBackSpec {
130
188
  kind?: ComputerKind;
131
189
  /** What is mounted at /workspace, never a token; absent when nothing is. */
132
190
  mount?: MountReadBack;
191
+ /** The GPUs the computer was given, as the vendor reports them (Daytona) or as create recorded them (Modal); absent: none. */
192
+ gpu?: GpuSpec;
133
193
  }
134
194
  /**
135
195
  * What a read-back recorded that does not refuse the computer, in words, one line each: under network none, the probe