@parcha/agentrun-computer 0.1.0-beta.35 → 0.1.0-beta.36

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 (63) hide show
  1. package/README.md +108 -21
  2. package/box/Dockerfile +3 -1
  3. package/box/agentrun-archil +59 -7
  4. package/box/build-daytona.py +20 -4
  5. package/dist/browser.d.ts +61 -10
  6. package/dist/browser.js +125 -3
  7. package/dist/browserbase.d.ts +45 -20
  8. package/dist/browserbase.js +161 -17
  9. package/dist/chrome.d.ts +3 -4
  10. package/dist/chrome.js +6 -11
  11. package/dist/computerd-linux-amd64 +0 -0
  12. package/dist/computerd-linux-arm64 +0 -0
  13. package/dist/conformance/daytona.d.ts +4 -0
  14. package/dist/conformance/daytona.js +5 -0
  15. package/dist/daytona.d.ts +13 -1
  16. package/dist/daytona.js +55 -36
  17. package/dist/descriptor.d.ts +24 -2
  18. package/dist/descriptor.js +11 -0
  19. package/dist/descriptors/browserbase.d.ts +1 -0
  20. package/dist/descriptors/browserbase.js +2 -0
  21. package/dist/descriptors/daytona.d.ts +23 -2
  22. package/dist/descriptors/daytona.js +34 -2
  23. package/dist/descriptors/index.d.ts +28 -1
  24. package/dist/descriptors/index.js +1 -1
  25. package/dist/descriptors/kernel.d.ts +1 -0
  26. package/dist/descriptors/kernel.js +2 -0
  27. package/dist/descriptors/modal.d.ts +4 -0
  28. package/dist/descriptors/modal.js +11 -1
  29. package/dist/descriptors/orgo.d.ts +11 -0
  30. package/dist/descriptors/orgo.js +6 -1
  31. package/dist/descriptors/phone-harness.d.ts +5 -0
  32. package/dist/descriptors/phone-harness.js +3 -0
  33. package/dist/docker/egress.d.ts +4 -3
  34. package/dist/docker/egress.js +7 -6
  35. package/dist/docker.js +7 -5
  36. package/dist/e2b.js +1 -1
  37. package/dist/index.d.ts +5 -5
  38. package/dist/index.js +4 -4
  39. package/dist/janitor.d.ts +5 -4
  40. package/dist/janitor.js +1 -1
  41. package/dist/kernel.d.ts +16 -24
  42. package/dist/kernel.js +93 -18
  43. package/dist/kinds.d.ts +9 -4
  44. package/dist/labels.d.ts +10 -2
  45. package/dist/labels.js +30 -7
  46. package/dist/local-chrome.d.ts +3 -1
  47. package/dist/local-chrome.js +8 -4
  48. package/dist/modal.d.ts +3 -3
  49. package/dist/modal.js +71 -57
  50. package/dist/mount-archil.d.ts +25 -3
  51. package/dist/mount-archil.js +39 -8
  52. package/dist/orgo-desktop.d.ts +15 -6
  53. package/dist/orgo-desktop.js +295 -53
  54. package/dist/orgo-names.d.ts +129 -3
  55. package/dist/orgo-names.js +211 -8
  56. package/dist/orgo.d.ts +18 -7
  57. package/dist/orgo.js +381 -69
  58. package/dist/phone-harness.d.ts +3 -2
  59. package/dist/phone-harness.js +25 -8
  60. package/dist/protocol.d.ts +5 -0
  61. package/dist/provider.d.ts +63 -1
  62. package/dist/provider.js +8 -3
  63. package/package.json +1 -1
package/dist/labels.js CHANGED
@@ -3,8 +3,9 @@
3
3
  // (releaseOlder, in janitor.ts). Both names live here alone, with the run label's hash: a provider whose computers keep
4
4
  // only that (Orgo's names) lists it under RUN_HASH_LABEL, so a caller can still tell whose run a computer is.
5
5
  //
6
- // An agent's persistent computer carries its owner as two more labels, set at create: agentrun.owner=agent:<id>, and
7
- // the owner's idle TTL when it set one. The run and epoch labels then name the claim that holds it now.
6
+ // An agent's persistent computer carries its owner as more labels, set at create: agentrun.owner=agent:<id>, the
7
+ // agent's server when the owner names one, and the owner's idle TTL when it set one. The run and epoch labels then name
8
+ // the claim that holds it now.
8
9
  import { createHash } from "node:crypto";
9
10
  import { epochProblem } from "./mount.js";
10
11
  import { ownerProblem } from "./provider.js";
@@ -39,20 +40,35 @@ export function runHash(run) {
39
40
  }
40
41
  /** The agent a persistent computer belongs to, as agent:<id>. */
41
42
  export const OWNER_LABEL = "agentrun.owner";
43
+ /** The server that agent is on, when the owner names one (owner.server). */
44
+ export const OWNER_SERVER_LABEL = "agentrun.owner-server";
42
45
  /** The owner's idle TTL of a persistent computer, in milliseconds, in decimal: how long it may stay detached. */
43
46
  export const IDLE_TTL_LABEL = "agentrun.idle-ttl-ms";
44
47
  /** A whole number as a label holds it: decimal digits, no sign, no leading zero, no space. */
45
48
  const DECIMAL = /^(?:0|[1-9][0-9]*)$/;
46
- /** The labels of an agent's computer: its owner, and its idle TTL when the owner set one. Throws, in words, on an owner that is not one. */
49
+ /**
50
+ * The labels of an agent's computer: its owner, its server when the owner names one, and its idle TTL when the owner
51
+ * set one. Throws, in words, on an owner that is not one.
52
+ */
47
53
  export function ownerLabels(owner) {
48
54
  const problem = ownerProblem(owner);
49
55
  if (problem !== undefined)
50
56
  throw new TypeError(problem);
51
- return { [OWNER_LABEL]: `agent:${owner.agent}`, ...(owner.idleTtlMs === undefined ? {} : { [IDLE_TTL_LABEL]: String(owner.idleTtlMs) }) };
57
+ return {
58
+ [OWNER_LABEL]: `agent:${owner.agent}`,
59
+ ...(owner.server === undefined ? {} : { [OWNER_SERVER_LABEL]: owner.server }),
60
+ ...(owner.idleTtlMs === undefined ? {} : { [IDLE_TTL_LABEL]: String(owner.idleTtlMs) }),
61
+ };
62
+ }
63
+ /** The labels an owner's listing filters by: its agent's, and its server's when it names one (no idle TTL). */
64
+ export function ownerFilter(owner) {
65
+ const { [IDLE_TTL_LABEL]: _, ...labels } = ownerLabels({ agent: owner.agent, ...(owner.server === undefined ? {} : { server: owner.server }) });
66
+ return labels;
52
67
  }
53
68
  /**
54
69
  * A computer's owner, read from its labels: undefined for a run's computer (no owner label). An owner label that is not
55
- * agent:<id>, or an idle TTL that is not a decimal whole number above 0, is invalid, in words naming what it reads.
70
+ * agent:<id>, a server label that is not a server id, or an idle TTL that is not a decimal whole number above 0, is
71
+ * invalid, in words naming what it reads.
56
72
  */
57
73
  export function ownerOf(labels) {
58
74
  if (typeof labels !== "object" || labels === null || Array.isArray(labels))
@@ -63,13 +79,20 @@ export function ownerOf(labels) {
63
79
  const agent = typeof text === "string" && text.startsWith("agent:") ? text.slice("agent:".length) : undefined;
64
80
  if (agent === undefined || ownerProblem({ agent }) !== undefined)
65
81
  return fail("invalid", `the label ${OWNER_LABEL} reads ${JSON.stringify(text)}, not agent:<id>`);
82
+ let owner = { agent };
83
+ if (Object.hasOwn(labels, OWNER_SERVER_LABEL)) {
84
+ const server = labels[OWNER_SERVER_LABEL];
85
+ if (typeof server !== "string" || ownerProblem({ agent, server }) !== undefined)
86
+ return fail("invalid", `the label ${OWNER_SERVER_LABEL} reads ${JSON.stringify(server)}, not a server's id`);
87
+ owner = { agent, server };
88
+ }
66
89
  if (!Object.hasOwn(labels, IDLE_TTL_LABEL))
67
- return ok({ agent });
90
+ return ok(owner);
68
91
  const ttl = labels[IDLE_TTL_LABEL];
69
92
  const idleTtlMs = typeof ttl === "string" && DECIMAL.test(ttl) ? Number(ttl) : Number.NaN;
70
93
  if (!(Number.isSafeInteger(idleTtlMs) && idleTtlMs > 0))
71
94
  return fail("invalid", `the label ${IDLE_TTL_LABEL} reads ${JSON.stringify(ttl)}, not a whole number of milliseconds above 0`);
72
- return ok({ agent, idleTtlMs });
95
+ return ok({ ...owner, idleTtlMs });
73
96
  }
74
97
  /** An epoch as a label holds it: decimal digits, no sign, no leading zero, no space. */
75
98
  const EPOCH_TEXT = DECIMAL;
@@ -40,7 +40,9 @@ export declare class LocalBrowserProvider implements ComputerProvider {
40
40
  * A browser: our supervisor ends it at its deadline, and list reads that deadline, so the janitor sweeps one whose
41
41
  * supervisor is gone (lifetime janitor); it reaches public addresses only, through its egress proxy (network open), or
42
42
  * only a list's hosts among them (network allow);
43
- * it runs on this host, as this user, isolated by Chrome's sandbox alone (isolation host).
43
+ * it runs on this host, as this user, isolated by Chrome's sandbox alone (isolation host). Its sessions (browser) end
44
+ * at their deadline, a wall clock, and take a viewport (spec.browser.viewport, its window); no profile, no stealth,
45
+ * and headless is the provider's option, not a session's.
44
46
  */
45
47
  capabilities(): ComputerCapabilities;
46
48
  /** The Chrome this provider runs: the option's, else one found; null when there is none. */
@@ -27,7 +27,7 @@ import { lstat, mkdir, readdir, readFile, rm, writeFile } from "node:fs/promises
27
27
  import { tmpdir } from "node:os";
28
28
  import { join, resolve } from "node:path";
29
29
  import { fileURLToPath } from "node:url";
30
- import { browserClient, browserHello, carries, labelsProblem } from "./browser.js";
30
+ import { browserClient, browserHello, browserSpecRefusals, carries, labelsProblem } from "./browser.js";
31
31
  import { alive, answeringPath, CHROME_FLAGS, checkChrome, findChrome, killTree, NO_CHROME, AS_ROOT, runsWith, singletonDir } from "./chrome.js";
32
32
  import { LOCAL } from "./descriptors/local-chrome.js";
33
33
  import { BROWSER_IMAGE } from "./descriptors/shared.js";
@@ -80,7 +80,7 @@ export const CAPABILITIES = LOCAL.capabilities;
80
80
  const ID = /^lb-[0-9a-f]{16}$/;
81
81
  const idProblem = (id) => (typeof id === "string" && ID.test(id) ? undefined : `${typeof id === "string" ? JSON.stringify(id) : String(id)} is not a local browser's id`);
82
82
  const refOf = (id) => ({ id, name: id });
83
- const SPEC_FIELDS = new Set(["image", "lifetimeMs", "network", "labels"]);
83
+ const SPEC_FIELDS = new Set(["image", "lifetimeMs", "network", "labels", "browser"]);
84
84
  const sleep = (ms) => new Promise((done) => setTimeout(done, ms));
85
85
  const readJson = async (file) => {
86
86
  try {
@@ -112,7 +112,9 @@ export class LocalBrowserProvider {
112
112
  * A browser: our supervisor ends it at its deadline, and list reads that deadline, so the janitor sweeps one whose
113
113
  * supervisor is gone (lifetime janitor); it reaches public addresses only, through its egress proxy (network open), or
114
114
  * only a list's hosts among them (network allow);
115
- * it runs on this host, as this user, isolated by Chrome's sandbox alone (isolation host).
115
+ * it runs on this host, as this user, isolated by Chrome's sandbox alone (isolation host). Its sessions (browser) end
116
+ * at their deadline, a wall clock, and take a viewport (spec.browser.viewport, its window); no profile, no stealth,
117
+ * and headless is the provider's option, not a session's.
116
118
  */
117
119
  capabilities() {
118
120
  return {
@@ -125,6 +127,7 @@ export class LocalBrowserProvider {
125
127
  groups: [...CAPABILITIES[0].groups],
126
128
  maxLifetimeMs: LOCAL_MAX_LIFETIME_MS,
127
129
  release: ["delete"],
130
+ browser: { timeout: "wall-clock" },
128
131
  };
129
132
  }
130
133
  /** The Chrome this provider runs: the option's, else one found; null when there is none. */
@@ -153,6 +156,7 @@ export class LocalBrowserProvider {
153
156
  const net = browserNetworkOf(network);
154
157
  if ("problem" in net)
155
158
  refusals.push({ field: "network", message: net.problem });
159
+ refusals.push(...browserSpecRefusals(given.browser, { timeout: "wall-clock" }, LOCAL.label));
156
160
  if (labels !== undefined) {
157
161
  const problem = labelsProblem(labels);
158
162
  if (problem)
@@ -205,7 +209,7 @@ export class LocalBrowserProvider {
205
209
  created: new Date(now).toISOString(),
206
210
  deadline: new Date(now + runLifetimeMs(spec)).toISOString(),
207
211
  executablePath: this.executable(),
208
- args: [...CHROME_FLAGS, ...(this.#headed ? [] : ["--headless=new"]), WINDOW],
212
+ args: [...CHROME_FLAGS, ...(this.#headed ? [] : ["--headless=new"]), spec.browser?.viewport ? `--window-size=${spec.browser.viewport.width},${spec.browser.viewport.height}` : WINDOW],
209
213
  ...networkRecord(spec.network),
210
214
  };
211
215
  try {
package/dist/modal.d.ts CHANGED
@@ -290,9 +290,9 @@ export declare class ModalProvider implements ComputerProvider {
290
290
  */
291
291
  list(labels: Record<string, string>, { signal }?: CallContext): Promise<Result<ComputerInfo[]>>;
292
292
  /**
293
- * Modal reads no policy back. Open is open, nothing being wider; none is read back by the probe from inside, and is
294
- * another network in words when any of its addresses answered (an address that only accepted, and sent nothing back,
295
- * leaves it none). A change is refused: it is fixed at create.
293
+ * Modal reads no policy back. A computer here is made with none, read back by the probe from inside, and is another
294
+ * network in words when any of its addresses answered (an address that only accepted, and sent nothing back, leaves it
295
+ * none). A change is refused: it is fixed at create.
296
296
  */
297
297
  network(ref: ComputerRef, policy?: NetworkSpec, { signal }?: CallContext): Promise<Result<NetworkPolicy>>;
298
298
  /**
package/dist/modal.js CHANGED
@@ -11,7 +11,7 @@ import { COMPUTER_LABEL, DAEMON_IN_COMPUTER, DEADLINE_LABEL, DEFAULT_CPUS, DEFAU
11
11
  import { OWN_NETWORK_ONLY, probeOwnNetworkDrift, TOOL_USER } from "./isolation.js";
12
12
  import { releaseOlder } from "./janitor.js";
13
13
  import { EPOCH_LABEL, epochOf, RUN_LABEL } from "./labels.js";
14
- import { checkMount, readBackOf } from "./mount.js";
14
+ import { checkMount } from "./mount.js";
15
15
  import { ARCHIL_HELPER, ARCHIL_MOUNT_LABEL, ARCHIL_TOOL_UID, archilMount, archilRefusals, archilRelease, claimEpoch, mountDrift, readArchilMount, recordedArchil as recordedArchilOf, syncingClient, } from "./mount-archil.js";
16
16
  import { checkGpu, checkTenure, runLifetimeMs, } from "./provider.js";
17
17
  import { failFor, ok, vendorFail } from "./result.js";
@@ -257,6 +257,8 @@ const SPEC_FIELDS = new Set(["image", "lifetimeMs", "network", "cpus", "memoryMb
257
257
  const NUL = "a NUL byte cannot be passed to Modal";
258
258
  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";
259
259
  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";
260
+ /** The runtime a computer runs on: gVisor, Modal's one GPU runtime, exactly when it has a GPU; a VM otherwise. */
261
+ const runtimeOf = (recorded) => (recorded.gpu === undefined ? "vm" : "gvisor");
260
262
  const isNumber = (value) => typeof value === "number" && Number.isFinite(value);
261
263
  const isWhole = (value) => typeof value === "number" && Number.isSafeInteger(value);
262
264
  const show = (value) => (value === undefined ? "nothing" : JSON.stringify(value));
@@ -433,32 +435,41 @@ function recordedOf(tags) {
433
435
  }
434
436
  return `spec: the tag ${SPEC_TAG} reads ${show(tags[SPEC_TAG])}, not the spec create writes`;
435
437
  }
436
- /** The network a computer was created with, as list reports it: a tag only the host's token writes. */
438
+ /** The network a computer was created with, as list reports it: none, the one this provider makes, where the spec tag
439
+ * (a tag only the host's token writes) is create's. */
437
440
  function recordedNetwork(tags) {
438
- const recorded = recordedOf(tags);
439
- if (typeof recorded !== "string" && (recorded.network === "none" || recorded.network === "open"))
440
- return recorded.network;
441
- return { other: `the tag ${SPEC_TAG} names no network this provider makes` };
441
+ if (typeof recordedOf(tags) !== "string")
442
+ return "none";
443
+ return { other: `the tag ${SPEC_TAG} is not the spec create writes, so the computer's network is not known` };
442
444
  }
443
445
  /**
444
446
  * The Archil mount a computer's spec tag records (recordedArchilOf, shared), or undefined when it records none: the
445
- * tag's mount, under the epoch the tag recorded it at, which must be the label's.
447
+ * tag's source, its folder the recorded agent's for the run label's run, exclusive, under the epoch the tag recorded it
448
+ * at, which must be the label's.
446
449
  */
447
450
  function recordedArchil(tags) {
448
451
  const recorded = recordedOf(tags);
449
452
  if (typeof recorded === "string" || recorded.mount === undefined)
450
453
  return undefined;
451
454
  const read = epochOf(tags);
452
- const { kind, disk, region, folder, epoch: was } = (recorded.mount ?? {});
453
- if (kind !== "archil" || typeof disk !== "string" || typeof region !== "string" || typeof folder !== "string") {
455
+ const { disk, region, agent, epoch: was } = (recorded.mount ?? {});
456
+ const run = tags[RUN_LABEL];
457
+ if (typeof disk !== "string" || typeof region !== "string" || typeof agent !== "string" || run === undefined) {
454
458
  return recordedArchilOf(tags, { other: `the tag ${SPEC_TAG} records a mount this provider never makes` });
455
459
  }
456
- const mount = { kind, disk, region, folder };
460
+ const mount = { kind: "archil", disk, region, folder: `agents/${agent}/runs/${run}/work` };
457
461
  if (read.ok && was !== read.value) {
458
462
  return recordedArchilOf(tags, { mount, other: `the tag ${SPEC_TAG} records the mount under epoch ${show(was)}, yet the label ${EPOCH_LABEL} reads ${read.value}` });
459
463
  }
460
464
  return recordedArchilOf(tags, { mount });
461
465
  }
466
+ /** Modal holds a sandbox's tags, their names and values together, to 512 bytes: a create past it is refused at Modal
467
+ * ("a sandbox's cumulative tags size (533 bytes) cannot exceed 512 bytes", 11-12). */
468
+ const MAX_TAG_BYTES = 512;
469
+ /** The <agent> of an Archil folder agents/<agent>/runs/<run>/work, the shape check() holds it to. */
470
+ const folderAgent = (folder) => folder.split("/")[1];
471
+ /** The bytes Modal counts of `tags`: every name and value, in UTF-8. */
472
+ const tagBytes = (tags) => Object.entries(tags).reduce((sum, [key, value]) => sum + Buffer.byteLength(key) + Buffer.byteLength(value), 0);
462
473
  /** Every way the probe's report differs from what the computer should be. */
463
474
  function probeDrift(probe, expected) {
464
475
  const found = [];
@@ -599,7 +610,7 @@ export class ModalProvider {
599
610
  const refusals = [];
600
611
  const refuse = (field, message) => refusals.push({ field, message });
601
612
  const given = (typeof spec === "object" && spec !== null ? spec : {});
602
- const { image, lifetimeMs, network, cpus, memoryMb, pids, labels, workdir, user, mount } = given;
613
+ const { image, network, cpus, memoryMb, pids, labels, workdir, user, mount } = given;
603
614
  if (typeof image !== "string" || image.trim() === "" || image.startsWith("-") || /\s/.test(image)) {
604
615
  refuse("image", `an image is required: a registry tag for linux/amd64 that Modal can pull, such as ${MODAL_DEFAULT_IMAGE}`);
605
616
  }
@@ -646,8 +657,34 @@ export class ModalProvider {
646
657
  continue;
647
658
  refuse(field, `a Modal computer does not support ${field}`);
648
659
  }
660
+ // What create would tag the sandbox with, its name and deadline as long as create's always are, within Modal's bound.
661
+ if (refusals.length === 0) {
662
+ const { tags } = this.#tags(spec, "computer-000000000000", new Date(0).toISOString());
663
+ const bytes = tagBytes(tags);
664
+ if (bytes > MAX_TAG_BYTES) {
665
+ const sizes = Object.entries(tags).map(([key, value]) => `${key} ${Buffer.byteLength(key) + Buffer.byteLength(value)}`).join(", ");
666
+ refuse(spec.mount === undefined ? "labels" : "mount", `a Modal sandbox's tags come to at most ${MAX_TAG_BYTES} bytes, names and values together, and this computer's would come to ${bytes} (${sizes}): give a shorter image, mount folder or labels`);
667
+ }
668
+ }
649
669
  return refusals;
650
670
  }
671
+ /** What create records of `spec` in its spec tag, and the sandbox's tags: the caller's labels, then this provider's own. */
672
+ #tags(spec, name, deadline) {
673
+ const mount = spec.mount?.kind === "archil" ? spec.mount : undefined;
674
+ const recorded = {
675
+ image: spec.image,
676
+ // An Archil computer's tools run as the tool user alone.
677
+ user: mount === undefined ? (userOf(spec.user) ?? this.#user) : ARCHIL_USER,
678
+ cpus: spec.cpus ?? DEFAULT_CPUS,
679
+ memoryMb: spec.memoryMb ?? DEFAULT_MEMORY_MB,
680
+ workdir: spec.workdir ?? WORK,
681
+ // The folder's agent and the claim's epoch: check() held the folder's run and the epoch to the labels before an
682
+ // Archil spec gets here.
683
+ ...(mount === undefined ? {} : { mount: { disk: mount.disk, region: mount.region, agent: folderAgent(mount.folder), epoch: claimEpoch(spec.labels) } }),
684
+ ...(spec.gpu === undefined ? {} : { gpu: { type: spec.gpu.type, count: spec.gpu.count } }),
685
+ };
686
+ return { recorded, tags: { ...spec.labels, [COMPUTER_LABEL]: "1", [NAME_TAG]: name, [DEADLINE_LABEL]: deadline, [SPEC_TAG]: JSON.stringify(recorded) } };
687
+ }
651
688
  async create(spec, { signal } = {}) {
652
689
  const refusals = this.check(spec);
653
690
  if (refusals.length > 0)
@@ -672,23 +709,8 @@ export class ModalProvider {
672
709
  const deadline = new Date(Date.now() + runLifetimeMs(spec)).toISOString();
673
710
  // An Archil mount is made under the run's claim (check() held the spec to both labels), for the tool user alone.
674
711
  const archil = spec.mount?.kind === "archil" ? { mount: spec.mount, run: spec.labels?.[RUN_LABEL], epoch: claimEpoch(spec.labels) } : undefined;
675
- const user = archil === undefined ? (userOf(spec.user) ?? this.#user) : ARCHIL_USER;
676
- const workdir = spec.workdir ?? WORK;
677
- const cpus = spec.cpus ?? DEFAULT_CPUS;
678
- const memoryMb = spec.memoryMb ?? DEFAULT_MEMORY_MB;
679
- const recorded = {
680
- image: spec.image,
681
- user,
682
- network: spec.network,
683
- cpus,
684
- memoryMb,
685
- workdir,
686
- // Modal offers GPUs on gVisor only: a GPU computer's runtime, read back by the probe's kernel like a VM's.
687
- runtime: spec.gpu === undefined ? "vm" : "gvisor",
688
- ...(archil === undefined ? {} : { mount: readBackOf(archil.mount, archil.epoch) }),
689
- ...(spec.gpu === undefined ? {} : { gpu: { type: spec.gpu.type, count: spec.gpu.count } }),
690
- };
691
- const tags = { ...spec.labels, [COMPUTER_LABEL]: "1", [NAME_TAG]: name, [DEADLINE_LABEL]: deadline, [SPEC_TAG]: JSON.stringify(recorded) };
712
+ const { recorded, tags } = this.#tags(spec, name, deadline);
713
+ const { user, workdir, cpus, memoryMb } = recorded;
692
714
  // With daemonImage the daemon comes in as a layer of the computer's own image, there before the command starts.
693
715
  // Without, the command is the entrypoint, which waits for the upload below. Either way the computer needs no
694
716
  // network to get it. HOME is a directory init gives the computer's user.
@@ -720,7 +742,8 @@ export class ModalProvider {
720
742
  : modalCommands({ deadline, user, waitSeconds: Math.ceil(waitMs / 1000), home: WORK, ...(gate === undefined ? {} : { gate }) }).entrypoint;
721
743
  const cpuLimit = cpus / CPUS_PER_CORE;
722
744
  const params = {
723
- runtime: recorded.runtime,
745
+ // Modal offers GPUs on gVisor only: a GPU computer's runtime, read back by the probe's kernel like a VM's.
746
+ runtime: runtimeOf(recorded),
724
747
  ...(spec.gpu === undefined ? {} : { gpu: modalGpu(spec.gpu) }),
725
748
  command,
726
749
  // Modal ends the sandbox at its timeout: the lifetime, in the whole seconds the SDK takes.
@@ -931,14 +954,14 @@ export class ModalProvider {
931
954
  const found = [
932
955
  ...tagDrift(tags, read.value),
933
956
  ...helloDrift(inside.value.hello, this.#expected()),
934
- ...probeDrift(inside.value.probe, { user: recorded.user, network: recorded.network, runtime: recorded.runtime }),
957
+ ...probeDrift(inside.value.probe, { user: recorded.user, network: "none", runtime: runtimeOf(recorded) }),
935
958
  ...(archil === undefined ? [] : mountDrift(archil.expected, inside.value.mount)),
936
959
  ];
937
960
  if (found.length > 0)
938
961
  return fail("refused", `it did not match its spec: ${found.join("; ")}`);
939
962
  // Which way init fenced its programs, as hello read it back: said once a way other than the plain one was taken.
940
- 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`] : [];
941
- return ok([...probeNotes(inside.value.probe, recorded.network), ...fence]);
963
+ 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 ${runtimeOf(recorded)} may not make one itself`] : [];
964
+ return ok([...probeNotes(inside.value.probe, "none"), ...fence]);
942
965
  }
943
966
  /** One connection's hello and the probe through it, and an Archil computer's mount read back, the connection closed after. */
944
967
  async #inside(sandbox, name, signal, patient = false, archil) {
@@ -1190,12 +1213,8 @@ export class ModalProvider {
1190
1213
  if (typeof recorded === "string")
1191
1214
  found.push(recorded);
1192
1215
  else {
1193
- // gvisor exactly for a GPU computer, vm for every other: anything else this provider never makes.
1194
- const runtime = recorded.gpu === undefined ? "vm" : "gvisor";
1195
- if (recorded.runtime !== runtime)
1196
- 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"}`);
1197
- const { image, network, cpus, memoryMb, workdir, user, gpu } = recorded;
1198
- const refusals = this.check({ image, lifetimeMs: 1, network, cpus, memoryMb, workdir, user, ...(gpu === undefined ? {} : { gpu }) });
1216
+ const { image, cpus, memoryMb, workdir, user, gpu } = recorded;
1217
+ const refusals = this.check({ image, lifetimeMs: 1, network: "none", cpus, memoryMb, workdir, user, ...(gpu === undefined ? {} : { gpu }) });
1199
1218
  found.push(...refusals.map(({ field, message }) => `${field}: ${message}, as recorded at create`));
1200
1219
  // No exec in a computer whose user is root: the bridge would run what that user could have replaced.
1201
1220
  if (isRootUser(user))
@@ -1208,14 +1227,15 @@ export class ModalProvider {
1208
1227
  const { hello, probe, mount } = inside.value;
1209
1228
  found.push(...helloDrift(hello, this.#expected()));
1210
1229
  if (typeof recorded !== "string")
1211
- found.push(...probeDrift(probe, { user: recorded.user, network: recorded.network, runtime: recorded.runtime }));
1230
+ found.push(...probeDrift(probe, { user: recorded.user, network: "none", runtime: runtimeOf(recorded) }));
1212
1231
  // The mount read back from inside is the one the spec tag records, under the computer's epoch label.
1213
1232
  if (archil !== undefined)
1214
1233
  found.push(...mountDrift(archil.expected, mount));
1215
1234
  if (found.length > 0 || typeof recorded === "string" || deadline === undefined) {
1216
1235
  return fail("refused", `the computer ${name} does not match this provider, so attach refuses it and it is left as it is: ${found.join("; ")}`);
1217
1236
  }
1218
- const { image, network, cpus, memoryMb, workdir, gpu } = recorded;
1237
+ const { image, cpus, memoryMb, workdir, gpu } = recorded;
1238
+ const network = "none";
1219
1239
  const notes = probeNotes(probe, network);
1220
1240
  return ok({
1221
1241
  ...ref,
@@ -1300,9 +1320,9 @@ export class ModalProvider {
1300
1320
  return ok(infos);
1301
1321
  }
1302
1322
  /**
1303
- * Modal reads no policy back. Open is open, nothing being wider; none is read back by the probe from inside, and is
1304
- * another network in words when any of its addresses answered (an address that only accepted, and sent nothing back,
1305
- * leaves it none). A change is refused: it is fixed at create.
1323
+ * Modal reads no policy back. A computer here is made with none, read back by the probe from inside, and is another
1324
+ * network in words when any of its addresses answered (an address that only accepted, and sent nothing back, leaves it
1325
+ * none). A change is refused: it is fixed at create.
1306
1326
  */
1307
1327
  async network(ref, policy, { signal } = {}) {
1308
1328
  const problem = refProblem(ref);
@@ -1318,20 +1338,14 @@ export class ModalProvider {
1318
1338
  const recorded = recordedNetwork(found.value.tags);
1319
1339
  if (typeof recorded !== "string")
1320
1340
  return fail("refused", `the computer ${ref.name}: ${"other" in recorded ? recorded.other : JSON.stringify(recorded)}`);
1321
- if (policy !== undefined && policy !== recorded)
1322
- return fail("refused", `${FIXED}: ${ref.name} was created with network ${recorded}, not ${policy}`);
1323
- let read = recorded;
1324
- if (recorded === "none") {
1325
- const root = rootRecorded(found.value.tags, ref.name);
1326
- if (root)
1327
- return root;
1328
- const inside = await this.#inside(found.value.sandbox, ref.name, signal);
1329
- if (!inside.ok)
1330
- return inside;
1331
- const { reached } = inside.value.probe;
1332
- if (reached.length > 0)
1333
- read = { other: `created with network none, yet from inside an answer came back from ${reached.join(", ")}` };
1334
- }
1341
+ const root = rootRecorded(found.value.tags, ref.name);
1342
+ if (root)
1343
+ return root;
1344
+ const inside = await this.#inside(found.value.sandbox, ref.name, signal);
1345
+ if (!inside.ok)
1346
+ return inside;
1347
+ const { reached } = inside.value.probe;
1348
+ const read = reached.length > 0 ? { other: `created with network none, yet from inside an answer came back from ${reached.join(", ")}` } : recorded;
1335
1349
  if (policy === undefined || policy === read)
1336
1350
  return ok(read);
1337
1351
  return fail("refused", `${ref.name} was asked to keep network ${policy}, and reads back: ${typeof read === "string" ? read : JSON.stringify(read)}`);
@@ -58,6 +58,25 @@ export declare const ARCHIL_REGION = "[a-z0-9]+-[a-z0-9][a-z0-9-]{0,62}";
58
58
  export declare function archilRefusals(spec: ComputerSpec): Refusal[];
59
59
  /** The sha256 of the helper this package ships (box/agentrun-archil): the one an image must have. */
60
60
  export declare function helperSha256(): string;
61
+ /**
62
+ * An egress gateway for the archil client (parcha-proxy's archil-egress): with one, the helper's mount starts
63
+ * `computerd archil-relay` and redirects root's TCP to Archil's 8100 and 32050 to it, and the relay carries each
64
+ * connection to the gateway's lane for its port with a PROXY v2 header naming the original destination. The gateway
65
+ * forwards only to a destination that proves, by certificate, the Archil name the client asked for.
66
+ */
67
+ export interface ArchilEgress {
68
+ /** The gateway's IPv4 address. */
69
+ gateway: string;
70
+ /** The gateway's port for the client's connections to 8100 (the mount endpoint). */
71
+ mountLane: number;
72
+ /** The gateway's port for the client's connections to 32050 (the file servers). */
73
+ dataLane: number;
74
+ }
75
+ /**
76
+ * Reads `<IPv4 gateway>:<mount lane>:<data lane>`, such as 10.60.0.40:18100:42050, as the helper checks it: an IPv4
77
+ * address and two different ports, neither 8100 nor 32050. Anything else throws, in words.
78
+ */
79
+ export declare function archilEgressOf(text: string): ArchilEgress;
61
80
  export interface ArchilMountOptions {
62
81
  root: ArchilRoot;
63
82
  mount: ArchilMount;
@@ -71,6 +90,8 @@ export interface ArchilMountOptions {
71
90
  }>>;
72
91
  /** The bound of each step in the computer. */
73
92
  timeoutMs: number;
93
+ /** The egress gateway the archil client reaches Archil through; none, and it reaches Archil as the computer's network allows. */
94
+ egress?: ArchilEgress;
74
95
  signal?: AbortSignal;
75
96
  }
76
97
  /**
@@ -85,10 +106,11 @@ export interface ArchilMountOptions {
85
106
  * Another computer of the run at the claim's own epoch is never forced off: while one is listed there is no
86
107
  * revoke, and a held folder refuses in words;
87
108
  * 4. serve: the resident sync server, which holds no token.
88
- * The archil client and serve run in the computer's own network namespace, which reaches Archil; the tools' network is
89
- * init's own namespace, loopback alone (computerd init --own-network), so there is no firewall to set here.
109
+ * The archil client and serve run in the computer's own network namespace, which reaches Archil (through the egress
110
+ * gateway, when one is given: the helper sets the relay and its redirect); the tools' network is init's own namespace,
111
+ * loopback alone (computerd init --own-network), so there is no firewall to set here.
90
112
  */
91
- export declare function archilMount({ root, mount, self: computer, releaseOlder, timeoutMs, signal }: ArchilMountOptions): Promise<Result<void>>;
113
+ export declare function archilMount({ root, mount, self: computer, releaseOlder, timeoutMs, egress, signal }: ArchilMountOptions): Promise<Result<void>>;
92
114
  /**
93
115
  * A computerd client whose every call that may change the folder (files.write, move, remove and mkdir; tar.push.begin,
94
116
  * which makes the destination and the folders above it, so a push never ended leaves none unsynced; tar.push.end, and
@@ -120,7 +120,12 @@ const PREFLIGHT = [
120
120
  'echo "archil $(/usr/bin/archil --version 2>/dev/null | head -n 1)"',
121
121
  `echo "tool $(id -u ${ARCHIL_TOOL_USER} 2>/dev/null):$(id -g ${ARCHIL_TOOL_USER} 2>/dev/null)"`,
122
122
  'echo "sudo $(command -v sudo 2>/dev/null || echo none)"',
123
+ // The FUSE device, which the archil client mounts through: the runtime gives it, not the image (Daytona's GPU host
124
+ // gives none, live 11-11).
125
+ 'echo "fuse $([ -c /dev/fuse ] && echo present || echo absent)"',
123
126
  ].join("\n");
127
+ /** Why a computer's preflight says the Archil folder cannot be mounted at all, before anything else is checked. */
128
+ const NO_FUSE = "this computer has no /dev/fuse, so the Archil folder can't be mounted";
124
129
  /** How the preflight's words differ from the image the package ships, one line each; none when they do not. */
125
130
  function preflightDrift(output, expectedSha) {
126
131
  const lines = new Map();
@@ -144,14 +149,36 @@ function preflightDrift(output, expectedSha) {
144
149
  found.push(`the tool user ${ARCHIL_TOOL_USER} is not ${ARCHIL_TOOL_UID}:${ARCHIL_TOOL_UID} (${show(lines.get("tool"))})`);
145
150
  if (lines.get("sudo") !== "none")
146
151
  found.push(`the image has sudo (${show(lines.get("sudo"))}), which gives the tool user a way to root`);
152
+ if (lines.get("fuse") !== "present")
153
+ found.push(`the preflight did not find /dev/fuse (${show(lines.get("fuse"))})`);
147
154
  return found;
148
155
  }
149
156
  /** What Archil answers a mount of a folder another client holds. */
150
157
  const HELD = "has an outstanding delegation";
158
+ const IPV4 = /^(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)\.){3}(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)$/;
159
+ const LANE = /^[1-9]\d{0,4}$/;
160
+ /** Archil's own ports, which the computer redirects to the relay: no lane may be one. */
161
+ const ARCHIL_PORTS = new Set([8100, 32050]);
162
+ /**
163
+ * Reads `<IPv4 gateway>:<mount lane>:<data lane>`, such as 10.60.0.40:18100:42050, as the helper checks it: an IPv4
164
+ * address and two different ports, neither 8100 nor 32050. Anything else throws, in words.
165
+ */
166
+ export function archilEgressOf(text) {
167
+ const [gateway = "", mount = "", data = "", ...rest] = text.split(":");
168
+ const mountLane = Number(mount);
169
+ const dataLane = Number(data);
170
+ const lane = (port, n) => LANE.test(port) && n <= 65535 && !ARCHIL_PORTS.has(n);
171
+ if (rest.length > 0 || !IPV4.test(gateway) || !lane(mount, mountLane) || !lane(data, dataLane) || mountLane === dataLane) {
172
+ throw new Error(`the Archil egress is <IPv4 gateway>:<mount lane>:<data lane>, such as 10.60.0.40:18100:42050, with two different ports, neither 8100 nor 32050; not ${JSON.stringify(text)}`);
173
+ }
174
+ return { gateway, mountLane, dataLane };
175
+ }
151
176
  /** The helper's argv for a verb. */
152
- function helper(verb, mount) {
153
- if (verb === "mount" || verb === "revoke")
154
- return [ARCHIL_HELPER, verb, mount.disk, mount.region, mount.folder];
177
+ function helper(verb, mount, egress) {
178
+ if (verb === "mount" || verb === "revoke") {
179
+ const way = egress === undefined ? [] : [`egress=${egress.gateway}:${egress.mountLane}:${egress.dataLane}`];
180
+ return [ARCHIL_HELPER, verb, mount.disk, mount.region, mount.folder, ...way];
181
+ }
155
182
  return [ARCHIL_HELPER, verb];
156
183
  }
157
184
  /**
@@ -166,10 +193,11 @@ function helper(verb, mount) {
166
193
  * Another computer of the run at the claim's own epoch is never forced off: while one is listed there is no
167
194
  * revoke, and a held folder refuses in words;
168
195
  * 4. serve: the resident sync server, which holds no token.
169
- * The archil client and serve run in the computer's own network namespace, which reaches Archil; the tools' network is
170
- * init's own namespace, loopback alone (computerd init --own-network), so there is no firewall to set here.
196
+ * The archil client and serve run in the computer's own network namespace, which reaches Archil (through the egress
197
+ * gateway, when one is given: the helper sets the relay and its redirect); the tools' network is init's own namespace,
198
+ * loopback alone (computerd init --own-network), so there is no firewall to set here.
171
199
  */
172
- export async function archilMount({ root, mount, self: computer, releaseOlder, timeoutMs, signal }) {
200
+ export async function archilMount({ root, mount, self: computer, releaseOlder, timeoutMs, egress, signal }) {
173
201
  const step = async (argv, what, stdin) => {
174
202
  const ran = await root.run(argv, { timeoutMs, ...(stdin === undefined ? {} : { stdin }), ...(signal ? { signal } : {}) });
175
203
  if (!ran.ok)
@@ -180,6 +208,9 @@ export async function archilMount({ root, mount, self: computer, releaseOlder, t
180
208
  const pre = await step(["sh", "-c", PREFLIGHT, "sh", ARCHIL_HELPER], "preflight");
181
209
  if (!pre.ok)
182
210
  return pre;
211
+ // No FUSE device: the mount cannot happen whatever else holds, so that is the one reason given.
212
+ if (/^fuse absent$/m.test(pre.value.output))
213
+ return fail("refused", NO_FUSE);
183
214
  const drift = preflightDrift(pre.value.output, helperSha256());
184
215
  if (pre.value.exitCode !== 0 || drift.length > 0) {
185
216
  return fail("refused", `the computer is not as the Archil image makes it: ${drift.length > 0 ? drift.join("; ") : `the preflight exited ${pre.value.exitCode}`}`);
@@ -207,7 +238,7 @@ export async function archilMount({ root, mount, self: computer, releaseOlder, t
207
238
  return checked;
208
239
  }
209
240
  let verb = force ? "revoke" : "mount";
210
- let took = await step(helper(verb, mount), verb, `${mount.token}\n`);
241
+ let took = await step(helper(verb, mount, egress), verb, `${mount.token}\n`);
211
242
  if (!took.ok)
212
243
  return took;
213
244
  if (verb === "mount" && took.value.exitCode !== 0 && took.value.output.includes(HELD) && twins.length > 0) {
@@ -218,7 +249,7 @@ export async function archilMount({ root, mount, self: computer, releaseOlder, t
218
249
  if (!checked.ok)
219
250
  return checked;
220
251
  verb = "revoke";
221
- took = await step(helper(verb, mount), verb, `${mount.token}\n`);
252
+ took = await step(helper(verb, mount, egress), verb, `${mount.token}\n`);
222
253
  if (!took.ok)
223
254
  return took;
224
255
  }
@@ -1,6 +1,7 @@
1
1
  import { type OrgoRest } from "./orgo-channel.js";
2
+ import { type OrgoLedger } from "./orgo-names.js";
2
3
  import { type ComputerClient, type DaemonMethod, type DaemonMethods, type Group, type HelloResult } from "./protocol.js";
3
- 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, type ReleaseHow } from "./provider.js";
4
+ import { type AttachContext, type AttachedComputer, type CallContext, type ComputerCapabilities, type ComputerConnection, type ComputerInfo, type ComputerProvider, type ComputerRef, type ComputerSpec, type CreatedComputer, type NetworkPolicy, type NetworkSpec, type Refusal, type ReleaseContext, type ReleaseHow } from "./provider.js";
4
5
  import { type Result } from "./result.js";
5
6
  import { type ScreenWatch, type ScreenWatchHandlers, type WatchOptions } from "./screen-watch.js";
6
7
  export type OrgoDesktopOs = "windows" | "macos";
@@ -35,6 +36,8 @@ export interface OrgoDesktopOptions {
35
36
  timeouts?: Partial<OrgoDesktopTimeouts>;
36
37
  /** The version the computer's hello reports; default the provider's. Only the conformance drift case sets another. */
37
38
  daemonVersion?: string;
39
+ /** Where agents' own computers' labels are kept (the server's computer ledger); default one in this process's memory. */
40
+ ledger?: OrgoLedger;
38
41
  }
39
42
  /** What differs between the two desktops. */
40
43
  interface Profile {
@@ -80,11 +83,13 @@ export declare class OrgoDesktopProvider implements ComputerProvider {
80
83
  #private;
81
84
  readonly id = "orgo";
82
85
  readonly version: string;
83
- constructor({ os, apiKey, workspaceId, apiUrl, fetch, maxLifetimeMs, timeouts, daemonVersion }: OrgoDesktopOptions);
86
+ constructor({ os, apiKey, workspaceId, apiUrl, fetch, maxLifetimeMs, timeouts, daemonVersion, ledger }: OrgoDesktopOptions);
84
87
  /**
85
88
  * daemon none: the provider answers every method over Orgo's API. lifetime janitor: the deadline is in the name, and
86
89
  * on Windows Orgo's end (whole hours) is the backstop. network open alone, never read back from inside: Orgo has no
87
- * egress control and no computerd runs here to probe from inside. release delete alone.
90
+ * egress control and no computerd runs here to probe from inside. release delete. persistence on Windows alone: an
91
+ * agent's computer detaches to its disk (Orgo's stop keeps files, apps and settings, not memory), so it does not
92
+ * resume where it was. A Mac takes no owner: Orgo stops none, so it cannot be detached.
88
93
  */
89
94
  capabilities(): ComputerCapabilities;
90
95
  check(spec: ComputerSpec): Refusal[];
@@ -102,7 +107,7 @@ export declare class OrgoDesktopProvider implements ComputerProvider {
102
107
  id: string;
103
108
  } | {
104
109
  labels: Record<string, string>;
105
- }, { signal }?: CallContext): Promise<Result<AttachedComputer>>;
110
+ }, { signal, claim }?: AttachContext): Promise<Result<AttachedComputer>>;
106
111
  /**
107
112
  * Every computer of this provider in the workspace that carries all of these labels. The run and the epoch are read
108
113
  * from the name, with nothing run in a computer, so a stopped one is listed too; any other label is read from the
@@ -115,8 +120,12 @@ export declare class OrgoDesktopProvider implements ComputerProvider {
115
120
  }>>;
116
121
  /** open: what Orgo gives, the one network here; never read from inside, and a change is refused. */
117
122
  network(ref: ComputerRef, policy?: NetworkSpec, { signal }?: CallContext): Promise<Result<NetworkPolicy>>;
118
- /** delete: idempotent, a computer Orgo no longer has is done; it waits until Orgo no longer has it. No stop. */
119
- release(ref: ComputerRef, how: ReleaseHow, { signal }?: CallContext): Promise<Result<void>>;
123
+ /**
124
+ * delete: idempotent, a computer Orgo no longer has is done; it waits until Orgo no longer has it. detach, for an
125
+ * agent's own Windows computer alone: Orgo's stop archives its disk, and it reads frozen. A Mac has no agent's
126
+ * computer to detach (Orgo's stop takes none). No stop: a run's computer is deleted. Either forgets the pointer.
127
+ */
128
+ release(ref: ComputerRef, how: ReleaseHow, { signal, claim }?: ReleaseContext): Promise<Result<void>>;
120
129
  /**
121
130
  * Moves the deadline to now + ttlMs, never earlier and never past the most the labels file holds: Orgo's end first
122
131
  * where there is one, in whole hours with an Idempotency-Key, then the name's, then the labels file. A computer's