@parcha/agentrun-computer 0.1.0-beta.38 → 0.1.0-beta.40

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 (97) hide show
  1. package/README.md +126 -83
  2. package/box/Dockerfile +5 -54
  3. package/box/README.md +9 -3
  4. package/box/build-daytona.py +2 -2
  5. package/box/build-e2b.mjs +1 -1
  6. package/box/install.sh +87 -0
  7. package/box/recipe.d.mts +5 -0
  8. package/box/recipe.mjs +12 -10
  9. package/dist/agent37.d.ts +17 -4
  10. package/dist/agent37.js +98 -17
  11. package/dist/box-image.d.ts +14 -0
  12. package/dist/box-image.js +24 -0
  13. package/dist/computerd-linux-amd64 +0 -0
  14. package/dist/computerd-linux-arm64 +0 -0
  15. package/dist/computerd.json +2 -2
  16. package/dist/conformance/agent37.d.ts +9 -4
  17. package/dist/conformance/agent37.js +23 -11
  18. package/dist/conformance/browserbase.js +3 -3
  19. package/dist/conformance/cases/apps.d.ts +1 -1
  20. package/dist/conformance/cases/apps.js +1 -1
  21. package/dist/conformance/cases/isolation.d.ts +18 -3
  22. package/dist/conformance/cases/isolation.js +73 -6
  23. package/dist/conformance/cases/lifetime.js +30 -0
  24. package/dist/conformance/cases/mount.js +4 -2
  25. package/dist/conformance/cases/provider.js +88 -1
  26. package/dist/conformance/cli.js +29 -9
  27. package/dist/conformance/e2b.js +9 -4
  28. package/dist/conformance/exec-stream.d.ts +44 -7
  29. package/dist/conformance/exec-stream.js +347 -88
  30. package/dist/conformance/kernel.js +2 -2
  31. package/dist/conformance/modal.js +1 -1
  32. package/dist/conformance/orgo.js +2 -2
  33. package/dist/conformance/report.js +3 -0
  34. package/dist/conformance/runner.js +127 -9
  35. package/dist/conformance/types.d.ts +21 -0
  36. package/dist/daytona.d.ts +0 -5
  37. package/dist/daytona.js +19 -28
  38. package/dist/descriptor.d.ts +5 -3
  39. package/dist/descriptors/agent37.d.ts +3 -11
  40. package/dist/descriptors/agent37.js +9 -10
  41. package/dist/descriptors/daytona.d.ts +1 -1
  42. package/dist/descriptors/daytona.js +5 -2
  43. package/dist/descriptors/docker.d.ts +13 -1
  44. package/dist/descriptors/docker.js +3 -1
  45. package/dist/descriptors/e2b.d.ts +2 -9
  46. package/dist/descriptors/e2b.js +8 -8
  47. package/dist/descriptors/index.d.ts +21 -19
  48. package/dist/descriptors/index.js +1 -3
  49. package/dist/descriptors/modal.d.ts +2 -6
  50. package/dist/descriptors/modal.js +8 -6
  51. package/dist/descriptors/orgo.js +2 -1
  52. package/dist/docker/egress-main.js +23 -15
  53. package/dist/docker/egress.d.ts +6 -4
  54. package/dist/docker/egress.js +24 -16
  55. package/dist/docker/inspect.d.ts +2 -2
  56. package/dist/docker/inspect.js +5 -5
  57. package/dist/docker.d.ts +6 -5
  58. package/dist/docker.js +12 -11
  59. package/dist/e2b.d.ts +12 -2
  60. package/dist/e2b.js +42 -19
  61. package/dist/host.d.ts +113 -59
  62. package/dist/host.js +5 -0
  63. package/dist/hosted/framed-exec.d.ts +49 -0
  64. package/dist/hosted/framed-exec.js +185 -0
  65. package/dist/hosted/network.d.ts +23 -0
  66. package/dist/hosted/network.js +77 -0
  67. package/dist/hosted/process.d.ts +13 -5
  68. package/dist/hosted/process.js +35 -12
  69. package/dist/hosted/provider.d.ts +16 -9
  70. package/dist/hosted/provider.js +475 -170
  71. package/dist/hosted/rest.d.ts +20 -2
  72. package/dist/hosted/rest.js +24 -10
  73. package/dist/hosted/scripts.d.ts +27 -7
  74. package/dist/hosted/scripts.js +77 -18
  75. package/dist/{agent37-ssh.d.ts → hosted/ssh-exec.d.ts} +19 -9
  76. package/dist/{agent37-ssh.js → hosted/ssh-exec.js} +38 -19
  77. package/dist/hosted/values.d.ts +21 -0
  78. package/dist/hosted/values.js +55 -0
  79. package/dist/index.d.ts +1 -1
  80. package/dist/index.js +1 -1
  81. package/dist/isolation.d.ts +0 -2
  82. package/dist/isolation.js +3 -4
  83. package/dist/modal.d.ts +8 -2
  84. package/dist/modal.js +21 -15
  85. package/dist/mount-archil.d.ts +5 -4
  86. package/dist/mount-archil.js +5 -6
  87. package/dist/orgo.js +6 -4
  88. package/dist/providers.d.ts +4 -1
  89. package/dist/surface/api.d.ts +0 -9
  90. package/dist/surface/core.d.ts +7 -2
  91. package/dist/surface/core.js +12 -4
  92. package/dist/surface/index.d.ts +1 -1
  93. package/dist/surface/index.js +1 -1
  94. package/dist/surface/script.d.ts +4 -0
  95. package/dist/surface/script.js +9 -3
  96. package/package.json +1 -1
  97. package/box/build-agent37.mjs +0 -158
package/box/README.md CHANGED
@@ -5,9 +5,15 @@ client pinned by version and sha256, the root helper `agentrun-archil`, the tool
5
5
  2510), FUSE and nftables, a desktop with nothing started (Xvfb, xfwm4 and the apps an agent opens), and no sudo. One
6
6
  image serves a sandbox and a desktop. The Dockerfile's comment says what each part is for.
7
7
 
8
- Its tag is the recipe's hash: the first 12 hex of the sha256 of `Dockerfile` and `agentrun-archil`, the one file it
9
- copies (`recipe.mjs`). A changed recipe is a new image, and the same recipe is the one built before.
8
+ Every step of the build is `install.sh`, POSIX shell run as root on the Dockerfile's base (`python:3.12-slim`), with
9
+ `agentrun-archil` beside it. The Dockerfile only copies the two and runs it. A vendor that builds images in its own
10
+ account from a running machine (a snapshot, a blueprint, a template) boots that base, copies both files into one folder,
11
+ runs `sh install.sh` as root and snapshots the result. A second run on the same machine ends the same.
12
+
13
+ Its tag is the recipe's hash: the first 12 hex of the sha256 of `Dockerfile`, `install.sh` and `agentrun-archil`, the
14
+ files it copies (`recipe.mjs`). A changed recipe is a new image, and the same recipe is the one built before.
10
15
 
11
16
  Each release publishes it (`.github/workflows/release.yml`, the `box` job) as `ghcr.io/parcha-ai/agentrun-box:<recipe hash>`
12
17
  and `:<release tag>`, for linux/amd64, and builds the public E2B template `agentrun-archil-<recipe hash>` from it (the
13
- `box-e2b` job). The build-* scripts here say how to build it for each provider.
18
+ `box-e2b` job), which E2B's provider starts in any account as `boxE2bTemplate()` (`src/box-image.ts`). The build-*
19
+ scripts here say how to build it for each provider.
@@ -1,6 +1,6 @@
1
1
  # Build the Archil image (this folder's Dockerfile) as a Daytona snapshot, with Daytona's Python SDK (`pip install
2
2
  # daytona`) and its key in DAYTONA_API_KEY, and print the snapshot's name, which a Daytona computer's spec names as its
3
- # image (no Daytona computer takes an Archil mount: Archil's client hangs on its sandboxes). The name is the recipe's hash (the Dockerfile and the files it copies), so a changed recipe is
3
+ # image (no Daytona computer takes an Archil mount: Archil's client hangs on its sandboxes). The name is the recipe's hash (the Dockerfile and the files it copies, install.sh among them), so a changed recipe is
4
4
  # a new snapshot, and the same recipe is the one built before: Daytona then refuses the name, and the printed name is
5
5
  # the one to use. Its size is 2 CPUs, 4 GB of memory and a 10 GB disk.
6
6
  #
@@ -26,7 +26,7 @@ if args:
26
26
  gpu = args[1]
27
27
 
28
28
  here = os.path.dirname(os.path.abspath(__file__))
29
- recipe = b"".join(open(os.path.join(here, name), "rb").read() for name in ("Dockerfile", "agentrun-archil"))
29
+ recipe = b"".join(open(os.path.join(here, name), "rb").read() for name in ("Dockerfile", "install.sh", "agentrun-archil"))
30
30
  digest = hashlib.sha256(recipe).hexdigest()[:12]
31
31
  name = f"agentrun-archil-gpu-{gpu.lower()}-{digest}" if gpu else f"agentrun-archil-{digest}"
32
32
  print(f"build-daytona: snapshot {name}", file=sys.stderr)
package/box/build-e2b.mjs CHANGED
@@ -7,7 +7,7 @@
7
7
  //
8
8
  // With no --image it builds this folder's Dockerfile. --image builds from the published box image instead
9
9
  // (ghcr.io/parcha-ai/agentrun-box:<the recipe's hash>, release.yml's box job), whose tag must be this recipe's hash; on
10
- // it the Dockerfile's sudo guard runs again, and its USER and CMD are the template's (recipe.mjs onImage).
10
+ // it install.sh's checked step runs again, and the Dockerfile's USER and CMD are the template's (recipe.mjs onImage).
11
11
  //
12
12
  // --public makes the template public once it is built (E2B's v2 PATCH /v2/templates/{id}, public: true), so another
13
13
  // team's sandbox starts from it, and prints the names E2B gives it. release.yml's box-e2b job runs both.
package/box/install.sh ADDED
@@ -0,0 +1,87 @@
1
+ #!/bin/sh
2
+ # The box image's build, as POSIX shell: every step of it, run as root on the base the Dockerfile starts from
3
+ # (python:3.12-slim, Debian). The Dockerfile copies this file and agentrun-archil into one folder and runs it, and that is
4
+ # all it does. A vendor that builds images in its own account (a snapshot, a blueprint, a template) does the same: it
5
+ # boots that base, puts both files in one folder there, runs `sh install.sh` as root, and snapshots the machine under a
6
+ # name that carries the recipe's hash (recipe.mjs). The Dockerfile's comment says what each part of the image is for.
7
+ #
8
+ # sh install.sh the whole build
9
+ # sh install.sh checked the last step alone: any sudo taken away, then every check. recipe.mjs's onImage runs it on
10
+ # the published image, after E2B's template builder has added sudo there.
11
+ #
12
+ # It reads the network only through apt (Debian's mirrors) and for Archil's package. Run twice on one machine it ends the
13
+ # same, for a vendor's snapshot flow may retry it: each step that makes something looks for it first.
14
+ set -eu
15
+
16
+ # The archil client the live checks ran. A sum that reads `unpinned` stops the build, saying so: pin both before any build.
17
+ ARCHIL_VERSION=0.10.1-1793222256
18
+ ARCHIL_SHA256_AMD64=f219e70287e8152f3f0c7222e1c3319f4665897235af7c33a8846e56a5a5786a
19
+ ARCHIL_SHA256_ARM64=10ed430e51c268af095dd9e6c7aa6cdbb951d2430d62a76458719db168f40c0e
20
+ # Where the provider runs the root helper from.
21
+ HELPER=/usr/local/sbin/agentrun-archil
22
+
23
+ here=$(dirname "$0")
24
+
25
+ # A coding agent's tools, FUSE, nftables and the archil client (checked by sha256), the tool user, and /workspace.
26
+ packages() {
27
+ arch="$(dpkg --print-architecture)"
28
+ case "$arch" in
29
+ amd64) sum="$ARCHIL_SHA256_AMD64" ;;
30
+ arm64) sum="$ARCHIL_SHA256_ARM64" ;;
31
+ *) echo "no archil client for $arch" >&2; exit 1 ;;
32
+ esac
33
+ case "$sum" in unpinned) echo "archil ${ARCHIL_VERSION} for $arch has no pinned sha256 yet: set ARCHIL_SHA256_$(echo "$arch" | tr a-z A-Z) to the package's sum" >&2; exit 1 ;; esac
34
+ apt-get update -qq
35
+ DEBIAN_FRONTEND=noninteractive apt-get install -y -qq --no-install-recommends \
36
+ git curl ca-certificates nodejs npm ripgrep fuse3 nftables >/dev/null
37
+ if [ "$(dpkg-query -W -f '${Version}' archil 2>/dev/null)" != "$ARCHIL_VERSION" ]; then
38
+ curl -fsSL -o /tmp/archil.deb "https://s3.amazonaws.com/archil-client/pkg/archil_${ARCHIL_VERSION}_${arch}.deb"
39
+ echo "$sum /tmp/archil.deb" | sha256sum -c -
40
+ DEBIAN_FRONTEND=noninteractive apt-get install -y -qq --no-install-recommends /tmp/archil.deb >/dev/null
41
+ fi
42
+ rm -rf /var/lib/apt/lists/* /tmp/archil.deb
43
+ getent group agentrun-tool >/dev/null || groupadd --gid 2510 agentrun-tool
44
+ id -u agentrun-tool >/dev/null 2>&1 || useradd --uid 2510 --gid 2510 --no-create-home --home-dir /tmp --shell /bin/sh agentrun-tool
45
+ install -d -o root -g root -m 0755 /workspace
46
+ }
47
+
48
+ # The desktop: Xvfb and xfwm4, which the provider starts through computerd as the tool user on :0, and the apps an agent
49
+ # opens. Each program and each app's desktop file is checked here. It comes before the last step, so a package that
50
+ # brought sudo is taken away and checked gone there (a check here would refuse E2B's build, whose builder adds sudo first).
51
+ desktop() {
52
+ apt-get update -qq
53
+ DEBIAN_FRONTEND=noninteractive apt-get install -y -qq --no-install-recommends \
54
+ xvfb xfwm4 x11-xserver-utils xfce4-terminal mousepad firefox-esr xdotool fonts-dejavu-core adwaita-icon-theme >/dev/null
55
+ rm -rf /var/lib/apt/lists/*
56
+ for x in Xvfb xfwm4 dbus-run-session xsetroot xfce4-terminal mousepad firefox-esr xdotool; do command -v "$x" >/dev/null || { echo "the image has no $x" >&2; exit 1; }; done
57
+ for app in org.xfce.mousepad xfce4-terminal firefox-esr; do [ -f "/usr/share/applications/$app.desktop" ] || { echo "the image has no desktop file $app.desktop" >&2; exit 1; }; done
58
+ }
59
+
60
+ # The root helper, from beside this file.
61
+ helper() {
62
+ cp "$here/agentrun-archil" "$HELPER"
63
+ }
64
+
65
+ # What the helper runs, where it runs it from: an image that lacks one fails here, not at a run's first mount. And no way
66
+ # to root for the tool user: no sudo, no sudoers. A provider's builder may add sudo to the base before these steps
67
+ # (E2B's does): it is taken away first, the package where it is installed and every sudoers file, then checked gone.
68
+ checked() {
69
+ if dpkg -s sudo >/dev/null 2>&1; then SUDO_FORCE_REMOVE=yes DEBIAN_FRONTEND=noninteractive apt-get purge -y -qq sudo >/dev/null; fi
70
+ rm -rf /etc/sudoers /etc/sudoers.d
71
+ chown root:root "$HELPER"
72
+ chmod 0755 "$HELPER"
73
+ for x in /usr/bin/archil /usr/bin/awk /usr/bin/realpath /usr/bin/mount /usr/bin/chown /usr/bin/find /usr/bin/id /usr/bin/ls; do
74
+ [ -x "$x" ] || { echo "the image has no $x" >&2; exit 1; }
75
+ done
76
+ ! command -v sudo >/dev/null 2>&1 || { echo "the image has sudo" >&2; exit 1; }
77
+ [ ! -e /etc/sudoers ] && [ ! -e /etc/sudoers.d ] || { echo "the image has a sudoers file" >&2; exit 1; }
78
+ ids="$(id -u agentrun-tool):$(id -g agentrun-tool)"
79
+ [ "$ids" = "2510:2510" ] || { echo "agentrun-tool is $ids" >&2; exit 1; }
80
+ archil --version | head -1
81
+ }
82
+
83
+ case "$*" in
84
+ "") packages; desktop; helper; checked ;;
85
+ checked) checked ;;
86
+ *) echo "usage: sh install.sh [checked]" >&2; exit 2 ;;
87
+ esac
@@ -0,0 +1,5 @@
1
+ // recipe.mjs's types, for src/box-image.ts, which names the published image by the recipe's hash.
2
+ export declare const RECIPE: readonly string[];
3
+ export declare function recipeHash(dir?: string): string;
4
+ export declare function instructionMatching(dockerfile: string, pattern: RegExp): string;
5
+ export declare function onImage(image: string, dockerfile?: string): string;
package/box/recipe.mjs CHANGED
@@ -1,19 +1,20 @@
1
- // The box image's recipe: the files it is made of (this folder's Dockerfile and what it copies) and their hash, the
2
- // first 12 hex of their sha256. Every build names what it makes by that hash, so a changed recipe is a new image and the
3
- // same recipe is the one built before: the E2B template agentrun-archil-<hash> (build-e2b.mjs), the Daytona snapshot
4
- // of the same name (build-daytona.py hashes the same files), and the published image ghcr.io/parcha-ai/agentrun-box:<hash>
5
- // (release.yml's box job reads recipeHash()).
1
+ // The box image's recipe: the files it is made of (this folder's Dockerfile and what it copies: install.sh, the build,
2
+ // and the helper) and their hash, the first 12 hex of their sha256. Every build names what it makes by that hash, so a
3
+ // changed recipe is a new image and the same recipe is the one built before: the E2B template agentrun-archil-<hash>
4
+ // (build-e2b.mjs), the Daytona snapshot of the same name (build-daytona.py hashes the same files), the published image
5
+ // ghcr.io/parcha-ai/agentrun-box:<hash> (release.yml's box job reads recipeHash()), and what a provider's prepareImage
6
+ // builds or registers in a vendor's account.
6
7
  //
7
8
  // And the E2B template's Dockerfile on that published image (build-e2b.mjs --image): E2B's builder provisions a base
8
- // before a template's steps, sudo among what it adds (the Dockerfile says so), so on the image the Dockerfile's sudo
9
- // guard runs again, as root, and its USER and CMD are the template's.
9
+ // before a template's steps, sudo among what it adds (install.sh says so), so on the image install.sh's last step runs
10
+ // again, as root, and the Dockerfile's USER and CMD are the template's.
10
11
  import { createHash } from "node:crypto";
11
12
  import { readFileSync } from "node:fs";
12
13
  import { dirname, join } from "node:path";
13
14
  import { fileURLToPath } from "node:url";
14
15
 
15
16
  /** Every file the image is made of: the Dockerfile and what it copies. */
16
- export const RECIPE = ["Dockerfile", "agentrun-archil"];
17
+ export const RECIPE = ["Dockerfile", "install.sh", "agentrun-archil"];
17
18
 
18
19
  const here = dirname(fileURLToPath(import.meta.url));
19
20
 
@@ -37,7 +38,8 @@ export function instructionMatching(dockerfile, pattern) {
37
38
  throw new Error(`the box Dockerfile has no instruction matching ${pattern}`);
38
39
  }
39
40
 
40
- /** The template's Dockerfile on the published image: the image, the Dockerfile's sudo guard again, its USER and CMD. */
41
+ /** The template's Dockerfile on the published image: the image, install.sh's checked step again, the Dockerfile's USER and CMD. */
41
42
  export function onImage(image, dockerfile = readFileSync(join(here, "Dockerfile"), "utf8")) {
42
- return [`FROM ${image}`, ...[/^RUN [^]*dpkg -s sudo/, /^USER /, /^CMD /].map((pattern) => instructionMatching(dockerfile, pattern))].join("\n") + "\n";
43
+ const checked = ["COPY install.sh /tmp/agentrun-box/install.sh", "RUN sh /tmp/agentrun-box/install.sh checked && rm -rf /tmp/agentrun-box"];
44
+ return [`FROM ${image}`, ...checked, ...[/^USER /, /^CMD /].map((pattern) => instructionMatching(dockerfile, pattern))].join("\n") + "\n";
43
45
  }
package/dist/agent37.d.ts CHANGED
@@ -1,5 +1,7 @@
1
- import { type Ssh2Module } from "./agent37-ssh.js";
2
1
  import { HostedProvider, type HostedOptions, type HostedTimeouts } from "./hosted/provider.js";
2
+ import { type Ssh2Module } from "./hosted/ssh-exec.js";
3
+ import type { CallContext } from "./provider.js";
4
+ import { type Result } from "./result.js";
3
5
  /** A WebSocket as this provider uses one: Node's global WebSocket (undici), which takes headers, or the same slice. */
4
6
  export interface WebSocketLike {
5
7
  binaryType: string;
@@ -72,7 +74,7 @@ export interface Agent37ProviderOptions extends Omit<HostedOptions, "maxLifetime
72
74
  region?: Agent37Region;
73
75
  /**
74
76
  * linux (default): no screen; desktop: an X server started through the daemon (Xvfb on :0 unless options.desktop says
75
- * otherwise), so the spec's image is a template that has one: our box template, agentrun-box (box/build-agent37.mjs).
77
+ * otherwise), so the spec's image is a template that has one: our box template, which prepareImage() registers.
76
78
  */
77
79
  kind?: "desktop" | "linux";
78
80
  /** The longest lifetime check takes: 24 h by default, the janitor's cap; Agent37 itself never ends an instance. */
@@ -94,10 +96,21 @@ export declare function create(options: Agent37Options): Promise<Agent37Provider
94
96
  /** The conformance CLI's module for Agent37: its live switch, the run's cap, its template and the drifted twin. */
95
97
  export declare const conformance: () => Promise<typeof import("./conformance/agent37.js")>;
96
98
  /**
97
- * Computers that are Agent37 instances, on the shared adapter. A spec's image is an Agent37 template's name:
98
- * "agent37-base", Agent37's plain Linux, for a sandbox; "agentrun-box", our box template with Xvfb, for a desktop.
99
+ * Computers that are Agent37 instances, on the shared adapter. A spec's image is an Agent37 template's name, such as
100
+ * "agent37-base", Agent37's plain Linux. A server starts every one from the template prepareImage() answers: our box
101
+ * image, registered in the key's own workspace.
99
102
  */
100
103
  export declare class Agent37Provider extends HostedProvider {
104
+ /**
105
+ * The provider contract's prepareImage (its descriptor declares it): the box image the release publishes
106
+ * (box-image.ts), as the workspace template agentrun-box-<recipe hash>, registered from the public image the first
107
+ * time the workspace needs it, so a new recipe is a new template and the one before is left as it is. ok with the
108
+ * template's name; onWait is told "pull" once, before a registration it waits on, never when the workspace has it.
109
+ * A sandbox and a desktop start from the same image.
110
+ */
111
+ prepareImage(context?: CallContext & {
112
+ onWait?: (making: "build" | "pull", tag: string) => void;
113
+ }): Promise<Result<string>>;
101
114
  constructor(options: Agent37ProviderOptions);
102
115
  }
103
116
  /** The workspace a key reaches, in words, for the sweep's scope: the key's sha256 prefix, never the key. */
package/dist/agent37.js CHANGED
@@ -1,4 +1,4 @@
1
- // The Agent37 host: Agent37 Cloud instances (kind linux, or kind desktop on our box template, agentrun-box, whose Xvfb
1
+ // The Agent37 host: Agent37 Cloud instances (kind linux, or kind desktop on our box template, agentrun-box-<hash>, whose Xvfb
2
2
  // the adapter starts through the daemon), each a whole VM by default (type "vm"), or a gVisor sandbox
3
3
  // (type "default"). The control plane is Agent37's REST API over fetch (https://api.agent37.com/v1, a Bearer key);
4
4
  // every command (the daemon's upload, its install, init's start, the stdio bridge) goes over SSH, as root, through the
@@ -10,14 +10,16 @@
10
10
  // (./hosted/provider.ts). Every vendor fact here is cited in the README's Agent37 section.
11
11
  import { createHash } from "node:crypto";
12
12
  import { Duplex } from "node:stream";
13
- import { pemOf, SshExec, SshTunnelError } from "./agent37-ssh.js";
13
+ import { boxImageRef, boxRecipeHash } from "./box-image.js";
14
14
  import { AGENT37, AGENT37_BASE_TEMPLATE } from "./descriptors/agent37.js";
15
15
  import { DEADLINE_LABEL, show } from "./drift.js";
16
16
  import { HostError } from "./host.js";
17
17
  import { orThrow } from "./hosted/process.js";
18
18
  import { jsonOf, rest } from "./hosted/rest.js";
19
19
  import { HostedProvider } from "./hosted/provider.js";
20
+ import { pemOf, SshExec, SshTunnelError } from "./hosted/ssh-exec.js";
20
21
  import { dateOf, DOMAIN, isWhole } from "./hosted/values.js";
22
+ import { failFor, ok } from "./result.js";
21
23
  /** Not a literal, so no type checker or bundler resolves ssh2 from this package. */
22
24
  const SSH2_PACKAGE = "ssh2";
23
25
  const DEFAULT_API_URL = "https://api.agent37.com";
@@ -39,13 +41,25 @@ const SHAPES = [
39
41
  { cpu: 4, memory: 32 },
40
42
  ];
41
43
  const MAX_CPUS = 4;
42
- /** metadata's cap, serialized (docs: instances/edit, "up to 4 KB serialized"). */
44
+ /**
45
+ * metadata's cap, serialized (docs: instances/edit, "up to 4 KB serialized"): check() holds the names and values to it,
46
+ * and create the JSON, its quotes and commas too.
47
+ */
43
48
  const METADATA_MAX_BYTES = 4096;
44
49
  /** A VM boots inside the create's POST, which answers once it runs (docs: instances/create, Defaults). */
45
50
  const DEFAULT_CREATE_MS = 300_000;
46
51
  /** How much a tunnel may hold unsent before a write waits for it (the WebSocket's bufferedAmount). */
47
52
  const TUNNEL_HIGH_WATER = 1024 * 1024;
48
53
  const TUNNEL_POLL_MS = 10;
54
+ /**
55
+ * A registration copies the image into the workspace's storage before it answers, "up to a few minutes for a large
56
+ * image" (docs: templates, Register a workspace template): the POST's bound, and the wait on another's registration.
57
+ */
58
+ const REGISTER_MS = 15 * 60_000;
59
+ /** One read of a template. */
60
+ const TEMPLATE_READ_MS = 30_000;
61
+ /** How often a template another registration is making is read again. */
62
+ const TEMPLATE_POLL_MS = 1_000;
49
63
  /** An id held to Agent37's form before it reaches a URL or a host name (an id is also a DNS label here): not_found else. */
50
64
  function instanceId(id) {
51
65
  if (!INSTANCE_ID.test(id))
@@ -209,7 +223,7 @@ class Agent37Host {
209
223
  #declared;
210
224
  constructor(options) {
211
225
  this.#apiKey = options.apiKey;
212
- this.#ssh = new SshExec({ ssh2: options.ssh2, privateKey: options.sshKey, tunnelOf: (id) => this.#tunnel(id) });
226
+ this.#ssh = new SshExec({ ssh2: options.ssh2, loginOf: () => ({ username: "root", privateKey: options.sshKey }), tunnelOf: (id) => this.#tunnel(id) });
213
227
  this.#client = rest({
214
228
  base: options.apiUrl,
215
229
  headers: () => ({ Authorization: `Bearer ${options.apiKey}`, Accept: "application/json" }),
@@ -225,19 +239,17 @@ class Agent37Host {
225
239
  this.#WebSocket = options.WebSocket;
226
240
  this.#proxyDomain = options.proxyDomain;
227
241
  this.#declared = { type: options.type, region: options.region };
228
- const runtime = options.type === "vm" ? "vm" : "gvisor";
229
242
  this.facts = {
230
243
  daemon: "child",
231
- isolation: runtime,
244
+ // The adapter holds the probe's kernel to it: gVisor's for type default, never for a VM.
245
+ isolation: options.type === "vm" ? "vm" : "gvisor",
232
246
  lifetime: "janitor",
233
247
  maxLifetimeMs: DAY_MS,
234
248
  arch: "amd64",
235
249
  vendorAgentPorts: [AGENT37_SSH_PORT, AGENT37_TTYD_PORT],
236
- // The box template has xfwm4 (box/build-agent37.mjs): the apps an agent opens are framed and focused.
250
+ // The box template is the box image (box/Dockerfile), which has xfwm4: the apps an agent opens are framed and focused.
237
251
  windowManager: true,
238
- specFields: ["cpus", "memoryMb"],
239
- labelRules: { maxBytes: METADATA_MAX_BYTES, measure: "json" },
240
- runtime: () => runtime,
252
+ labels: { bytes: METADATA_MAX_BYTES },
241
253
  };
242
254
  }
243
255
  errorCode(error) {
@@ -250,7 +262,7 @@ class Agent37Host {
250
262
  ws.binaryType = "arraybuffer";
251
263
  return { ...tunnelOf(ws, host), host };
252
264
  }
253
- /** argv as root over SSH (agent37-ssh.ts): one connection per instance through its tunnel, shared by its execs. */
265
+ /** argv as root over SSH (hosted/ssh-exec.ts): one connection per instance through its tunnel, shared by its execs. */
254
266
  async exec(id, argv, ctx) {
255
267
  return this.#ssh.exec(instanceId(id), argv, ctx);
256
268
  }
@@ -262,7 +274,7 @@ class Agent37Host {
262
274
  throw new HostError("vendor", `${method} ${path} answered ${answer.status} with no JSON body`);
263
275
  return parsed;
264
276
  }
265
- /** An Agent37 template is a name, with an optional @<version>; a size is one of Agent37's four shapes. The adapter holds metadata to 4 KB (labelRules). */
277
+ /** An Agent37 template is a name, with an optional @<version>; a size is one of Agent37's four shapes. The adapter holds metadata to 4 KB (facts.labels.bytes). */
266
278
  check(given) {
267
279
  const refusals = [];
268
280
  const { image, cpus, memoryMb } = given;
@@ -279,10 +291,15 @@ class Agent37Host {
279
291
  }
280
292
  /**
281
293
  * POST /v1/instances: the template, the type and region, the size when the spec asks one, the request's name as the
282
- * instance's name, the labels as metadata, deny-all (or allow-all for an Archil computer's root), auto-sleep off and
283
- * no public port. It answers once the instance runs (docs: instances/create, Defaults).
294
+ * instance's name, the labels as metadata, deny-all (or allow-all where the adapter asks egress: an Archil computer's root, or the
295
+ * egress proxy of a network open or a list), auto-sleep off and
296
+ * no public port. It answers once the instance runs (docs: instances/create, Defaults). req.backstopAt is left:
297
+ * Agent37 has no delete or stop timer to set it on, so the janitor alone ends an instance.
284
298
  */
285
299
  async create(req, ctx) {
300
+ const bytes = Buffer.byteLength(JSON.stringify(req.labels));
301
+ if (bytes > METADATA_MAX_BYTES)
302
+ throw new HostError("invalid", `Agent37 holds an instance's metadata to ${METADATA_MAX_BYTES} bytes as JSON, and this one's would be ${bytes}: give shorter labels`);
286
303
  const shape = req.cpus !== undefined || req.memoryMb !== undefined ? shapeOf(req.cpus, req.memoryMb) : undefined;
287
304
  const made = await this.#rest("POST", "/v1/instances", {
288
305
  template: req.image,
@@ -291,7 +308,7 @@ class Agent37Host {
291
308
  ...(shape === undefined ? {} : { resources: { cpu: shape.cpu, memory: shape.memory } }),
292
309
  name: req.name,
293
310
  metadata: req.labels,
294
- network: req.network === "open" ? "allow-all" : "deny-all",
311
+ network: req.egress ? "allow-all" : "deny-all",
295
312
  auto_sleep: false,
296
313
  public_ports: [],
297
314
  }, ctx);
@@ -342,6 +359,45 @@ class Agent37Host {
342
359
  const instance = await this.#rest("GET", path, undefined, ctx);
343
360
  await this.#rest("PATCH", path, { metadata: { ...(instance.metadata ?? {}), [DEADLINE_LABEL]: endsAt.toISOString() } }, ctx);
344
361
  }
362
+ /** GET /v1/templates/{name}: whether the workspace has it (404: it has not), else a HostError in Agent37's words. */
363
+ async #hasTemplate(name, signal) {
364
+ const read = orThrow(await this.#client.call("GET", this.#client.url(`/v1/templates/${name}`), { timeoutMs: TEMPLATE_READ_MS, accept: (status) => status === 200 || status === 404 }, signal));
365
+ return read.status === 200;
366
+ }
367
+ /**
368
+ * The workspace template `name`, made from the public image `imageRef` when the workspace has none (docs: templates):
369
+ * GET it; on a 404, `registering` is told, then POST /v1/templates { name, image_ref }, which answers once Agent37 has
370
+ * copied the image into the workspace. A 409 is another registration of the name, which this waits for, reading the
371
+ * template until the workspace has it. Throws a HostError in Agent37's words.
372
+ */
373
+ async template(name, imageRef, registering, signal) {
374
+ if (await this.#hasTemplate(name, signal))
375
+ return;
376
+ registering();
377
+ const json = { name, image_ref: imageRef, description: `AgentRun's box image ${imageRef}, registered by the server that first needed it` };
378
+ const posted = orThrow(await this.#client.call("POST", this.#client.url("/v1/templates"), { json, timeoutMs: REGISTER_MS, accept: (status) => (status >= 200 && status < 300) || status === 409 }, signal));
379
+ if (posted.status !== 409)
380
+ return;
381
+ const end = Date.now() + REGISTER_MS;
382
+ while (!(await this.#hasTemplate(name, signal))) {
383
+ if (Date.now() > end)
384
+ throw new HostError("timeout", `another registration of ${name} was not done within ${REGISTER_MS / 60_000} minutes`);
385
+ await new Promise((resolve, reject) => {
386
+ const done = () => {
387
+ clearTimeout(timer);
388
+ reject(new HostError("aborted", `the wait on another registration of ${name} was aborted`));
389
+ };
390
+ const timer = setTimeout(() => {
391
+ signal?.removeEventListener("abort", done);
392
+ resolve();
393
+ }, TEMPLATE_POLL_MS);
394
+ if (signal?.aborted)
395
+ done();
396
+ else
397
+ signal?.addEventListener("abort", done, { once: true });
398
+ });
399
+ }
400
+ }
345
401
  }
346
402
  /**
347
403
  * An Agent37Provider from its options alone; it reads no environment. The key is options.apiKey and the SSH key
@@ -357,11 +413,36 @@ export async function create(options) {
357
413
  }
358
414
  /** The conformance CLI's module for Agent37: its live switch, the run's cap, its template and the drifted twin. */
359
415
  export const conformance = () => import("./conformance/agent37.js");
416
+ const fail = failFor(AGENT37.id);
360
417
  /**
361
- * Computers that are Agent37 instances, on the shared adapter. A spec's image is an Agent37 template's name:
362
- * "agent37-base", Agent37's plain Linux, for a sandbox; "agentrun-box", our box template with Xvfb, for a desktop.
418
+ * Computers that are Agent37 instances, on the shared adapter. A spec's image is an Agent37 template's name, such as
419
+ * "agent37-base", Agent37's plain Linux. A server starts every one from the template prepareImage() answers: our box
420
+ * image, registered in the key's own workspace.
363
421
  */
364
422
  export class Agent37Provider extends HostedProvider {
423
+ /**
424
+ * The provider contract's prepareImage (its descriptor declares it): the box image the release publishes
425
+ * (box-image.ts), as the workspace template agentrun-box-<recipe hash>, registered from the public image the first
426
+ * time the workspace needs it, so a new recipe is a new template and the one before is left as it is. ok with the
427
+ * template's name; onWait is told "pull" once, before a registration it waits on, never when the workspace has it.
428
+ * A sandbox and a desktop start from the same image.
429
+ */
430
+ async prepareImage(context = {}) {
431
+ const name = `agentrun-box-${boxRecipeHash()}`;
432
+ const ref = boxImageRef();
433
+ let registering = false;
434
+ try {
435
+ await this.host.template(name, ref, () => {
436
+ registering = true;
437
+ context.onWait?.("pull", ref);
438
+ }, context.signal);
439
+ return ok(name);
440
+ }
441
+ catch (error) {
442
+ const said = error instanceof Error ? error.message : String(error);
443
+ return fail(codeOf(error), registering ? `registering ${ref} as the Agent37 template ${name}: ${said}` : `reading the Agent37 template ${name}: ${said}`);
444
+ }
445
+ }
365
446
  constructor(options) {
366
447
  const { apiKey, sshKey, ssh2, fetch: fetcher = globalThis.fetch, WebSocket = globalThis.WebSocket, apiUrl = DEFAULT_API_URL, proxyDomain = DEFAULT_PROXY_DOMAIN, type = "vm", region = "us", timeouts = {}, ...rest } = options ?? {};
367
448
  if (typeof apiKey !== "string" || apiKey === "")
@@ -0,0 +1,14 @@
1
+ /** Where the release publishes the box image. */
2
+ export declare const BOX_IMAGE_REPOSITORY = "ghcr.io/parcha-ai/agentrun-box";
3
+ /** The box recipe's hash, 12 hex, read once from this package's box/ folder. */
4
+ export declare function boxRecipeHash(): string;
5
+ /** The published box image this package's recipe names: ghcr.io/parcha-ai/agentrun-box:<recipe hash>. */
6
+ export declare const boxImageRef: () => string;
7
+ /**
8
+ * The E2B team that publishes the box template: release.yml's box-e2b job builds the box image as the E2B template
9
+ * agentrun-archil-<recipe hash> (box/build-e2b.mjs --image --public) in this team, and makes it public, so any E2B
10
+ * account starts it as <team slug>/<template>. The slug is E2B's name for the publishing team.
11
+ */
12
+ export declare const BOX_E2B_PUBLISHER = "agentrun-oss";
13
+ /** The public E2B template of the box image this package's recipe names: <publisher>/agentrun-archil-<recipe hash>. */
14
+ export declare const boxE2bTemplate: () => string;
@@ -0,0 +1,24 @@
1
+ // The box image as the release publishes it (release.yml's box job): box/Dockerfile built for amd64 and pushed, public,
2
+ // as ghcr.io/parcha-ai/agentrun-box:<recipe hash>. The hash is box/recipe.mjs's, read from the box/ folder this package
3
+ // ships, so a server names the image its own release published. A provider whose computers start from it (Agent37
4
+ // registers it in the owner's workspace, Modal pulls it) asks for it by this name; E2B starts from the public template
5
+ // the release builds from it (boxE2bTemplate).
6
+ import { recipeHash } from "../box/recipe.mjs";
7
+ /** Where the release publishes the box image. */
8
+ export const BOX_IMAGE_REPOSITORY = "ghcr.io/parcha-ai/agentrun-box";
9
+ let hash;
10
+ /** The box recipe's hash, 12 hex, read once from this package's box/ folder. */
11
+ export function boxRecipeHash() {
12
+ hash ??= recipeHash();
13
+ return hash;
14
+ }
15
+ /** The published box image this package's recipe names: ghcr.io/parcha-ai/agentrun-box:<recipe hash>. */
16
+ export const boxImageRef = () => `${BOX_IMAGE_REPOSITORY}:${boxRecipeHash()}`;
17
+ /**
18
+ * The E2B team that publishes the box template: release.yml's box-e2b job builds the box image as the E2B template
19
+ * agentrun-archil-<recipe hash> (box/build-e2b.mjs --image --public) in this team, and makes it public, so any E2B
20
+ * account starts it as <team slug>/<template>. The slug is E2B's name for the publishing team.
21
+ */
22
+ export const BOX_E2B_PUBLISHER = "agentrun-oss";
23
+ /** The public E2B template of the box image this package's recipe names: <publisher>/agentrun-archil-<recipe hash>. */
24
+ export const boxE2bTemplate = () => `${BOX_E2B_PUBLISHER}/agentrun-archil-${boxRecipeHash()}`;
Binary file
Binary file
@@ -1,4 +1,4 @@
1
1
  {
2
- "version": "0.1.0-beta.38",
3
- "source": "sha256:95e013be031ee2a63d9f52a82e540cf0ed71f42cf82b40f93b8843673875c30a"
2
+ "version": "0.1.0-beta.40",
3
+ "source": "sha256:6514fb8f5147c8a35230596771da93b7678f70ac83bb202ac37171921896fb31"
4
4
  }
@@ -8,7 +8,7 @@ export { ARCHIL_ENV } from "./archil.js";
8
8
  /** The environment this module reads, by name, each for the option its comment names, the live switch and the run's template. */
9
9
  export declare const AGENT37_ENV: {
10
10
  readonly live: "AGENTRUN_COMPUTER_LIVE_AGENT37";
11
- /** The template every computer of the run starts from; default agent37-base, or agentrun-box for kind desktop. */
11
+ /** The template every computer of the run starts from; default agent37-base, or the box template for kind desktop. */
12
12
  readonly template: "COMPUTER_AGENT37_TEMPLATE";
13
13
  /** kind: linux (default) or desktop. */
14
14
  readonly kind: "COMPUTER_AGENT37_KIND";
@@ -32,7 +32,7 @@ export declare const AGENT37_ENV: {
32
32
  /** The names this module reads, under the conformance modules' common name (ConformanceModule.ENV). */
33
33
  export declare const ENV: {
34
34
  readonly live: "AGENTRUN_COMPUTER_LIVE_AGENT37";
35
- /** The template every computer of the run starts from; default agent37-base, or agentrun-box for kind desktop. */
35
+ /** The template every computer of the run starts from; default agent37-base, or the box template for kind desktop. */
36
36
  readonly template: "COMPUTER_AGENT37_TEMPLATE";
37
37
  /** kind: linux (default) or desktop. */
38
38
  readonly kind: "COMPUTER_AGENT37_KIND";
@@ -72,8 +72,13 @@ export interface Agent37ModuleOptions extends Pick<Agent37Options, "ssh2" | "fet
72
72
  /** For mountFor("archil"): the disk's object API, or the SDK's Archil client, in place of the host's disk package. */
73
73
  archil?: Pick<ArchilRunFolderOptions, "objects" | "Archil" | "baseUrl">;
74
74
  }
75
- /** The template every computer of the run starts from: COMPUTER_AGENT37_TEMPLATE, or agentrun-box for kind desktop, else agent37-base. */
76
- export declare function conformanceImage({ env }?: Pick<Agent37ModuleOptions, "env">): string;
75
+ /**
76
+ * The template every computer of the run starts from: COMPUTER_AGENT37_TEMPLATE, else agent37-base, else for kind
77
+ * desktop the box template, which the run's provider registers in the key's workspace first (prepareImage, live).
78
+ */
79
+ export declare function conformanceImage(options?: Agent37ModuleOptions, { signal }?: {
80
+ signal?: AbortSignal;
81
+ }): Promise<string>;
77
82
  /** The provider the CLI runs; throws in words without the live switch, or when a setting is missing or wrong. */
78
83
  export declare function createProvider(options?: Agent37ModuleOptions): Promise<Agent37Provider>;
79
84
  /** The same provider uploading a daemon that reports version <version>-drift, for the drift.version case. */
@@ -1,6 +1,6 @@
1
1
  // Agent37 for the conformance CLI: `npm run conformance -w @parcha/agentrun-computer -- --provider agent37`.
2
2
  // It makes real instances, which bill per minute until deleted, so it runs only with AGENTRUN_COMPUTER_LIVE_AGENT37=1
3
- // and a key the lead has OKed, under COMPUTER_AGENT37_API_KEY, beside COMPUTER_AGENT37_SSH_KEY, the private half (its
3
+ // and a key for an account you can bill, under COMPUTER_AGENT37_API_KEY, beside COMPUTER_AGENT37_SSH_KEY, the private half (its
4
4
  // contents) of an SSH key registered on the same workspace. The provider reads no environment: this module reads its
5
5
  // own COMPUTER_AGENT37_* names (never AGENT37_API_KEY, which may hold another team's key) and passes each to create()
6
6
  // as its option. The live switch is checked first, before any other setting is read. The live sweep (sweep.ts,
@@ -11,15 +11,15 @@
11
11
  // ends an instance on its own: every computer of a run lives at most 30 minutes, by init's deadline and the janitor's
12
12
  // label, and the run's sweep deletes what is left.
13
13
  //
14
- // COMPUTER_AGENT37_KIND=desktop runs the desktop's cases (screen, input) on agentrun-box, the box template
15
- // box/build-agent37.mjs publishes in the key's workspace: build it there first, or name another with an X server in
16
- // COMPUTER_AGENT37_TEMPLATE.
14
+ // COMPUTER_AGENT37_KIND=desktop runs the desktop's cases (screen, input) on the box template, agentrun-box-<recipe
15
+ // hash>, which the run registers in the key's workspace first through the provider's prepareImage() (from the public
16
+ // image the release publishes), or on another with an X server named in COMPUTER_AGENT37_TEMPLATE.
17
17
  //
18
18
  // For the mount cases, mountFor("archil") makes a fresh run folder on the Archil disk COMPUTER_ARCHIL_DISK names, as
19
19
  // the E2B module does (./archil.ts); with no disk named it makes none, and the cases are skipped. An Archil computer
20
20
  // needs a provider whose daemon user is the tool user: COMPUTER_AGENT37_USER=2510:2510, the default.
21
21
  import { create, workspaceOf } from "../agent37.js";
22
- import { AGENT37_BASE_TEMPLATE, AGENT37_BOX_TEMPLATE } from "../descriptors/agent37.js";
22
+ import { AGENT37_BASE_TEMPLATE } from "../descriptors/agent37.js";
23
23
  import { archilRunFolder, archilSettings } from "./archil.js";
24
24
  import { buildDriftDaemon, DRIFT_VERSION } from "./drift-daemon.js";
25
25
  /** The Archil disk's settings for the mount cases, by name (COMPUTER_ARCHIL_*: all five, or none). */
@@ -27,7 +27,7 @@ export { ARCHIL_ENV } from "./archil.js";
27
27
  /** The environment this module reads, by name, each for the option its comment names, the live switch and the run's template. */
28
28
  export const AGENT37_ENV = {
29
29
  live: "AGENTRUN_COMPUTER_LIVE_AGENT37",
30
- /** The template every computer of the run starts from; default agent37-base, or agentrun-box for kind desktop. */
30
+ /** The template every computer of the run starts from; default agent37-base, or the box template for kind desktop. */
31
31
  template: "COMPUTER_AGENT37_TEMPLATE",
32
32
  /** kind: linux (default) or desktop. */
33
33
  kind: "COMPUTER_AGENT37_KIND",
@@ -87,16 +87,28 @@ export function settingsFromEnv(env = process.env) {
87
87
  export const CONFORMANCE_MAX_LIFETIME_MS = 30 * 60_000;
88
88
  /** For the run's report: what this configuration means for the suite. */
89
89
  export const conformanceNotes = [
90
- "agent37: every computer is an instance (type vm by default), made with network deny-all, auto-sleep off and no public port, read back from Agent37 and probed from inside; the daemon is a child, started over SSH through the platform's sshd (port 22022; it and the platform's web terminal on 7681 are declared as the vendor's agent), and every command goes over that SSH as root. Agent37 never ends an instance on its own: lifetime janitor, capped at 30 minutes for the run. No stream() (a screen is streamed through agentrun), so screen.stream is skipped. Kind desktop (COMPUTER_AGENT37_KIND=desktop) starts from agentrun-box, our box image as a template of the key's workspace (box/build-agent37.mjs), with Xvfb on :0 started through the daemon as the tool user.",
90
+ "agent37: every computer is an instance (type vm by default), made with network deny-all, auto-sleep off and no public port, read back from Agent37 and probed from inside; the daemon is a child, started over SSH through the platform's sshd (port 22022; it and the platform's web terminal on 7681 are declared as the vendor's agent), and every command goes over that SSH as root. Agent37 never ends an instance on its own: lifetime janitor, capped at 30 minutes for the run. No stream() (a screen is streamed through agentrun), so screen.stream is skipped. Kind desktop (COMPUTER_AGENT37_KIND=desktop) starts from agentrun-box-<recipe hash>, our box image registered as a template of the key's workspace (prepareImage), with Xvfb on :0 started through the daemon as the tool user.",
91
91
  ];
92
92
  function live(env) {
93
93
  if (env[AGENT37_ENV.live] !== "1") {
94
- throw new Error(`the Agent37 conformance module makes real instances, which bill until deleted: set ${AGENT37_ENV.live}=1, with a key the lead has OKed, to run it`);
94
+ throw new Error(`the Agent37 conformance module makes real instances, which bill until deleted: set ${AGENT37_ENV.live}=1, with a key for an account you can bill, to run it`);
95
95
  }
96
96
  }
97
- /** The template every computer of the run starts from: COMPUTER_AGENT37_TEMPLATE, or agentrun-box for kind desktop, else agent37-base. */
98
- export function conformanceImage({ env = process.env } = {}) {
99
- return env[AGENT37_ENV.template] || (env[AGENT37_ENV.kind] === "desktop" ? AGENT37_BOX_TEMPLATE : AGENT37_BASE_TEMPLATE);
97
+ /**
98
+ * The template every computer of the run starts from: COMPUTER_AGENT37_TEMPLATE, else agent37-base, else for kind
99
+ * desktop the box template, which the run's provider registers in the key's workspace first (prepareImage, live).
100
+ */
101
+ export async function conformanceImage(options = {}, { signal } = {}) {
102
+ const { env = process.env } = options;
103
+ const named = env[AGENT37_ENV.template];
104
+ if (named)
105
+ return named;
106
+ if (env[AGENT37_ENV.kind] !== "desktop")
107
+ return AGENT37_BASE_TEMPLATE;
108
+ const ready = await (await createProvider(options)).prepareImage(signal ? { signal } : {});
109
+ if (!ready.ok)
110
+ throw new Error(`the Agent37 box template: ${ready.error.message}`);
111
+ return ready.value;
100
112
  }
101
113
  /** The test doubles a caller hands in, each only when given. */
102
114
  const doubles = ({ ssh2, fetch, WebSocket, timeouts, onNote }) => ({