@parcha/agentrun-computer 0.1.0-beta.47 → 0.1.0-beta.49

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1405,8 +1405,8 @@ conformance module's `dialKit()` refuses, as E2B's does: the Core run happens in
1405
1405
  run image with `COMPUTER_MODAL_CONNECT=dial` is the box image, the one that holds `agentrun-dial` (debian:bookworm-slim
1406
1406
  on exec, as before).
1407
1407
 
1408
- A dial sandbox may be a desktop (`kind: "desktop"`): the box image's X server and xfwm4, started over the socket it
1409
- dialed, at 2 CPUs and 4 GiB on the VM runtime, with no GPU. On exec a Modal computer is kind `linux` alone, and the
1408
+ A dial sandbox may be a desktop (`kind: "desktop"`): the box image's X server, started over the socket it dialed, and
1409
+ xfwm4, which computerd starts, at 2 CPUs and 4 GiB on the VM runtime, with no GPU. On exec a Modal computer is kind `linux` alone, and the
1410
1410
  constructor refuses `kind: "desktop"` in words. The descriptor's desktop configuration selects `connect: "dial"` itself,
1411
1411
  so a server whose `modalConnect` is exec still makes its desktop over dial (it needs the dial's public address). In
1412
1412
  serve's Mode 2 the run's folder is an Archil mount, which a dial machine takes none of yet, so a Modal desktop there is
@@ -1561,7 +1561,7 @@ the TTL.
1561
1561
 
1562
1562
  | Capability | Declared | Why |
1563
1563
  | --- | --- | --- |
1564
- | `kind` | `linux` | a Linux shell with computerd: exec, files and processes |
1564
+ | `kind` | `linux`; `desktop` on dial | a Linux shell with computerd: exec, files and processes; on dial, `kind: "desktop"` adds the box snapshot's display ([Daytona on dial](#daytona-on-dial)) |
1565
1565
  | `lifetime` | `vendor` | `ttlMinutes` destroys the sandbox in any state once it elapses; set to the lifetime in whole minutes, rounded up. Init also ends every process at the deadline itself. |
1566
1566
  | `network` | `none`, `open`, `allow` | none: `networkBlockAll` at create, and the daemon's own network namespace; open and a list: not blocked (the account's tier may still limit where it goes), and the daemon's own namespace whose one way out is init's egress proxy (public internet only; a list's hosts alone) |
1567
1567
  | `vendorAgentPorts` | `[2280]` | the toolbox's port, on every interface; isolation.vendor-agent checks a program of the computer's user reaches it on neither loopback |
@@ -1644,7 +1644,7 @@ when it runs (`settingsFromEnv`) and passes each to `create()` as the option in
1644
1644
  (`apiKey`, required), `COMPUTER_DAYTONA_API_URL` (`apiUrl`), `COMPUTER_DAYTONA_DAEMON` (`daemonPath`),
1645
1645
  `COMPUTER_DAYTONA_ARCH` (`arch`), `COMPUTER_DAYTONA_TARGET` (`target`), `COMPUTER_DAYTONA_CLASS` (`sandboxClass`),
1646
1646
  `COMPUTER_DAYTONA_USER` (`daemonUser`), `COMPUTER_DAYTONA_GPU_SNAPSHOT` (`gpuSnapshot`) and `COMPUTER_DAYTONA_CONNECT`
1647
- (`connect`). It exports `createProvider()` and `createDriftedProvider()` (which builds a
1647
+ (`connect`); the providers it makes also read `COMPUTER_DAYTONA_KIND` (`kind`, `desktop` on dial only). It exports `createProvider()` and `createDriftedProvider()` (which builds a
1648
1648
  daemon of another version with Go), and reads `COMPUTER_DAYTONA_SNAPSHOT` (the run's image; unset, `"default"`,
1649
1649
  Daytona's default snapshot, or on dial the box image's snapshot, `agentrun-box-<recipe hash>`). It never reads `DAYTONA_API_KEY`, `DAYTONA_API_URL` or `DAYTONA_TARGET`, not even as a
1650
1650
  fallback: on a host that runs other Daytona work they may hold another organization's key. Those are serve's names,
@@ -1681,8 +1681,11 @@ default) a Daytona sandbox dials the server instead ([PROVIDERS.md](PROVIDERS.md
1681
1681
  no exec and no upload, and nothing goes through the toolbox: create sends the boot env as `CreateSandbox.env` and
1682
1682
  `networkBlockAll: false` (the machine's root reaches the server; network none is init's, inside), and the snapshot's
1683
1683
  entrypoint runs `agentrun-dial`. No Archil mount, no GPU, and not `image: "default"` (Daytona's default snapshot holds
1684
- no `agentrun-dial`): `check()` refuses each in words. Labels as on exec. A Daytona computer is kind `linux` alone, on
1685
- dial as on exec; why: [PROVIDERS.md](PROVIDERS.md#machines-that-dial-in).
1684
+ no `agentrun-dial`): `check()` refuses each in words. Labels as on exec. A dial sandbox may be a desktop
1685
+ (`kind: "desktop"`): the box snapshot's X server, started over the socket it dialed, and xfwm4, which computerd starts
1686
+ (init's `--window-manager`), at the snapshot's 2 CPUs and 4 GiB, with no GPU. On exec a Daytona computer is kind
1687
+ `linux` alone, and the constructor refuses `kind: "desktop"` in words; the descriptor's desktop configuration selects
1688
+ `connect: "dial"` itself. Why computerd, not the client, starts the manager here: [PROVIDERS.md](PROVIDERS.md#machines-that-dial-in).
1686
1689
  What each part of a dial sandbox rests on:
1687
1690
 
1688
1691
  - **A snapshot, never an image.** A create names a snapshot; a snapshot is made from "any publicly accessible image"
@@ -1894,12 +1897,11 @@ E2B's envd is the sandbox's first process, a systemd service with `Restart=alway
1894
1897
  whose start answers after the call gave up on it (its bound passed, or the caller aborted) is killed as it lands.
1895
1898
  6. A desktop's X server, `Xvfb :0 -screen 0 1280x800x24 -nolisten tcp`, starts through the daemon with
1896
1899
  `process.start`, as the computer's user, and create waits until hello declares the display (`src/desktop.ts`,
1897
- shared with Docker). Then xfwm4, which the template has, starts the same way on it (`xfwm4 --compositor=off
1898
- --sm-client-disable`, `WINDOW_MANAGER`), so the apps an agent opens are framed and focused. xfwm4 reads its
1899
- settings over a session bus and exits without one. So it runs under `dbus-run-session`, in a user namespace (the
1900
- same uid) and a network namespace of its own (`unshare --user --map-current-user --net`), and its bus listens on an
1901
- abstract name there, which a program of the computer's user cannot connect to. One that joins those namespaces
1902
- (nsenter) can, as the same uid can ptrace xfwm4. xfwm4 reaches the display by its path. It and every app `apps.launch` opens get `NO_AT_BRIDGE=1`: the template has at-spi2-core, so GTK's
1900
+ shared with Docker). Then computerd starts xfwm4 itself (init `--window-manager`, where the host's facts say
1901
+ `windowManager`; see `daemon/internal/windowmanager`) on a session bus of its own, in a network namespace root
1902
+ made, so the apps an agent opens are framed and focused; hello's `windowManager` says it runs, which create waits
1903
+ on. A program of the user can't join it: root made it, and the user holds no capability there; the same uid may
1904
+ still ptrace xfwm4. It and every app `apps.launch` opens get `NO_AT_BRIDGE=1`: the template has at-spi2-core, so GTK's
1903
1905
  accessibility bridge would start an at-spi bus, a socket of the user's at `/work/.cache/at-spi/bus_0` that nothing
1904
1906
  of ours uses. An app also gets no session bus (`DBUS_SESSION_BUS_ADDRESS=disabled:`). Given none, it would start
1905
1907
  one with the template's dbus-launch, and that bus starts gnome-keyring-daemon, a socket of the user's at
@@ -2061,8 +2063,8 @@ provider does in `process.env`. `COMPUTER_E2B_PUBLIC_STREAM` is no longer read.
2061
2063
  With `connect: "dial"` (a server's `e2bConnect` setting; `exec` by default) an E2B sandbox dials the server instead
2062
2064
  ([PROVIDERS.md](PROVIDERS.md#machines-that-dial-in)): a desktop by default, as on exec, since the box template has
2063
2065
  the desktop (`box/install.sh`'s `desktop` step), or kind linux; no Archil mount, and the host has no
2064
- exec and no upload. A desktop's launch adds `DISPLAY` to the boot env, and its X server and xfwm4 start over the
2065
- socket the sandbox dialed, through `process.start`. A dial desktop whose X server has gone is not refused at `connect()`
2066
+ exec and no upload. A desktop's launch adds `DISPLAY` and init's `--window-manager` to the boot env; its X server
2067
+ starts over the socket the sandbox dialed, through `process.start`, and computerd starts xfwm4 once it answers. A dial desktop whose X server has gone is not refused at `connect()`
2066
2068
  as on exec: it reads back kind `linux`, and its screen, input, apps and ui calls are refused in words, never sent, until
2067
2069
  its hello says `desktop` again. E2B runs a template's start command once, at the template's build, and snapshots it running, so
2068
2070
  it never sees a create's env ([docs.e2b.dev/template/start-ready-command](https://docs.e2b.dev/template/start-ready-command)).
@@ -2219,8 +2221,8 @@ kernel `4.19.0-gvisor`): root has no `CAP_SYS_ADMIN`, and init made its namespac
2219
2221
  `create({ kind: "desktop", ... })` (serve builds the descriptor's desktop configuration so) makes a desktop: the
2220
2222
  adapter gives init `DISPLAY` and starts `Xvfb :0 -screen 0 1280x800x24 -nolisten tcp` through the daemon as the tool
2221
2223
  user (`src/desktop.ts`), as on E2B, so the X server is one process in init's table, in its own network namespace, and
2222
- ends with the computer; xfwm4 starts the same way once the display answers, its session bus out of the user's reach, as
2223
- on E2B. It starts from the box image the release publishes, `ghcr.io/parcha-ai/agentrun-box:<recipe hash>`
2224
+ ends with the computer; computerd starts xfwm4 itself once the display answers (init's `--window-manager`), its
2225
+ session bus out of the user's reach, as on E2B. It starts from the box image the release publishes, `ghcr.io/parcha-ai/agentrun-box:<recipe hash>`
2224
2226
  (`box/Dockerfile`: the archil client, the helper, the tool user, FUSE, no sudo, plus Xvfb, xfwm4, and the apps E2B
2225
2227
  Desktop has that are cheap to carry, which the `apps` group lists and opens), as a template of the key's own workspace
2226
2228
  named `agentrun-box-<recipe hash>`. A sandbox that mounts an Archil disk starts from the same template.
@@ -2468,6 +2470,12 @@ kind browser that declares them.
2468
2470
  | `profile` | a context: `browserSettings.context { id, persist }` | a profile by name: `profile { name, save_changes }`, made first if Kernel does not know it | not declared |
2469
2471
  | `profiles { create, remove }` | `POST /v1/contexts`, `DELETE /v1/contexts/{id}` | `POST /profiles` under a random name (the pointer), `DELETE /profiles/{name}` | none |
2470
2472
  | `downloads { list, read }` | `GET /v1/downloads?sessionId=` (paged), `GET /v1/downloads/{id}`, cut at `maxBytes` | none | none |
2473
+ | `sessionUsage(ref)` | `GET /v1/sessions/{id}`: its `startedAt`, `endedAt` and `proxyBytes` | none | none |
2474
+
2475
+ `sessionUsage(ref)` is the vendor's own record of a session, for a host that reconciles its own measure of a session's
2476
+ time with the vendor's bill: `{ startedAt, endedAt, proxyBytes }`, each null where the vendor's answer does not hold a
2477
+ well-formed one (a session still running has no end), never a zero in its place; undefined for a session the vendor
2478
+ does not know. A host reads it once, when it lets the session go.
2471
2479
 
2472
2480
  A pointer is a capability: whoever holds it opens the profile, so no error's words carry one.
2473
2481
 
@@ -2937,7 +2945,7 @@ pass, facts: [{ id, value, means }], factsProblem? }`.
2937
2945
  An id is resolved through the provider registry, and only there; the usage lists every id it holds. A module path is
2938
2946
  resolved from the directory npm was run in. It exits 0 when Core passes, 1 when it fails, 2 on a
2939
2947
  usage error, and 3 on a partial run; `--json` prints the report object (`{ provider, providerVersion, kind,
2940
- daemonMode, image, daemons: [{ computer, role, version, os, arch, fence? }], only?, coreNotRun?, results: [{ id, level,
2948
+ daemonMode, image, daemons: [{ computer, role, version, os, arch, fence?, windowManager? }], only?, coreNotRun?, results: [{ id, level,
2941
2949
  group, status, reason?, undeclared? }], core, undeclared, cleanup, computers: { peak, cap? }, notes?, computerNotes? }`).
2942
2950
  `computers.peak` is the most computers the run had alive at once, each counted from its create's call until its release
2943
2951
  (the text report's `computers alive at once: <peak> at most` line). `--concurrency <n>` (`concurrency` in
package/dist/browser.d.ts CHANGED
@@ -181,13 +181,26 @@ export interface BrowserDownloads {
181
181
  /** The file's bytes, streamed; the stream fails in words once it passes maxBytes. */
182
182
  read(ref: ComputerRef, name: string, maxBytes: number, context?: CallContext): Promise<Result<AsyncIterable<Uint8Array>>>;
183
183
  }
184
+ /**
185
+ * A session as its vendor itself records it, for a host that reconciles its own measure of a session with the vendor's
186
+ * bill: when the vendor says the session started and ended, and the bytes it moved through the vendor's proxy. Each
187
+ * field is null where the vendor's record does not say it (a session still running has no end; a vendor that reports no
188
+ * proxy traffic has no bytes), never a zero standing in for one.
189
+ */
190
+ export interface BrowserSessionUsage {
191
+ startedAt: string | null;
192
+ endedAt: string | null;
193
+ proxyBytes: number | null;
194
+ }
184
195
  /**
185
196
  * A provider of browsers, with the members its features may bring: profiles where capabilities().browser declares
186
- * profiles, downloads where it declares downloads.
197
+ * profiles, downloads where it declares downloads. sessionUsage, where the vendor keeps a record of each session it ran:
198
+ * that record, read once (a host reads it when the session is let go); undefined for a session the vendor does not know.
187
199
  */
188
200
  export interface BrowserComputerProvider extends ComputerProvider {
189
201
  readonly profiles?: BrowserProfiles;
190
202
  readonly downloads?: BrowserDownloads;
203
+ sessionUsage?(ref: ComputerRef, context?: CallContext): Promise<Result<BrowserSessionUsage | undefined>>;
191
204
  }
192
205
  /** Whether a provider is a browser provider: its capabilities are of kind browser and declare its sessions' features. */
193
206
  export declare function isBrowserProvider(provider: ComputerProvider): provider is BrowserComputerProvider;
@@ -1,4 +1,4 @@
1
- import { type BrowserComputerProvider, type BrowserDownloads, type BrowserProfiles, type BrowserStream, type ReleaseConfirm } from "./browser.js";
1
+ import { type BrowserComputerProvider, type BrowserDownloads, type BrowserProfiles, type BrowserSessionUsage, type BrowserStream, type ReleaseConfirm } from "./browser.js";
2
2
  import { type AttachedComputer, type CallContext, type ComputerCapabilities, type ComputerConnection, type ComputerInfo, type ComputerProvider, type ComputerRef, type ComputerSpec, type CreateContext, type CreatedComputer, type NetworkPolicy, type NetworkSpec, type Refusal, type ReleaseHow } from "./provider.js";
3
3
  import { type Result } from "./result.js";
4
4
  export declare const BROWSERBASE_API_URL = "https://api.browserbase.com";
@@ -22,6 +22,11 @@ export interface BrowserbaseSession {
22
22
  connectUrl?: string;
23
23
  userMetadata?: Record<string, unknown>;
24
24
  expiresAt?: string;
25
+ /** When the session started and ended, as Browserbase records them (no end while it runs). */
26
+ startedAt?: string;
27
+ endedAt?: string;
28
+ /** The bytes the session moved through Browserbase's proxy. */
29
+ proxyBytes?: number;
25
30
  }
26
31
  /** A session's live view as GET /v1/sessions/{id}/debug answers it: every URL in it is a secret. */
27
32
  export interface BrowserbaseDebug {
@@ -120,6 +125,11 @@ export declare class BrowserbaseProvider implements ComputerProvider, BrowserCom
120
125
  * unless declared.
121
126
  */
122
127
  create(spec: ComputerSpec, context: CreateContext): Promise<Result<CreatedComputer>>;
128
+ /**
129
+ * The session as Browserbase records it (GET /v1/sessions/{id}): its start, its end and its proxy bytes, each null where
130
+ * the answer does not hold a well-formed one. undefined for a session Browserbase does not know (404).
131
+ */
132
+ sessionUsage(ref: ComputerRef, { signal }?: CallContext): Promise<Result<BrowserSessionUsage | undefined>>;
123
133
  /**
124
134
  * Settings' test: one read of the project's running sessions (GET /v1/sessions?status=RUNNING), which makes nothing.
125
135
  * A refused key is unauthorized and a Browserbase not reached unreachable; the words name the call, never the key.
@@ -316,6 +316,27 @@ export class BrowserbaseProvider {
316
316
  }
317
317
  return vendorFail("browserbase", `Browserbase kept answering more pages of downloads past ${MAX_PAGES}`);
318
318
  }
319
+ /**
320
+ * The session as Browserbase records it (GET /v1/sessions/{id}): its start, its end and its proxy bytes, each null where
321
+ * the answer does not hold a well-formed one. undefined for a session Browserbase does not know (404).
322
+ */
323
+ async sessionUsage(ref, { signal } = {}) {
324
+ const problem = idProblem(ref?.id, NAME);
325
+ if (problem)
326
+ return fail("invalid", problem);
327
+ let found;
328
+ try {
329
+ found = await this.#api.retrieve(ref.id, signal);
330
+ }
331
+ catch (error) {
332
+ return vendorFailure("browserbase", NAME, "GET /v1/sessions/{id}", error);
333
+ }
334
+ if (!found)
335
+ return ok(undefined);
336
+ const at = (value) => (typeof value === "string" && Number.isFinite(Date.parse(value)) ? new Date(Date.parse(value)).toISOString() : null);
337
+ const bytes = found.proxyBytes;
338
+ return ok({ startedAt: at(found.startedAt), endedAt: at(found.endedAt), proxyBytes: typeof bytes === "number" && Number.isSafeInteger(bytes) && bytes >= 0 ? bytes : null });
339
+ }
319
340
  async #listDownloads(ref, { signal } = {}) {
320
341
  const rows = await this.#downloadRows(ref?.id, signal);
321
342
  if (!rows.ok)
Binary file
Binary file
@@ -1,4 +1,4 @@
1
1
  {
2
- "version": "0.1.0-beta.47",
3
- "source": "sha256:83076566cf0a21895c12558066f3c852be325fd362a36c1024be04dc080a6e16"
2
+ "version": "0.1.0-beta.49",
3
+ "source": "sha256:cda430945f036061ea4f8a49fe0d619a058f1876cd3dd6ae75b1e2514d5dba35"
4
4
  }
@@ -5,6 +5,7 @@ import type { Case, CaseContext } from "../types.js";
5
5
  export declare function shoot(t: CaseContext, region?: Rect): Promise<{
6
6
  shot: ScreenShotResult;
7
7
  image: Png;
8
+ png: Buffer;
8
9
  }>;
9
10
  /** Why this computer's screen is not captured, as hello's screen.capture says it off (an attached Mac whose owner has
10
11
  * not granted the screen); undefined when it is on, or not declared, which a computer of the screen group means as on. */
@@ -36,7 +36,7 @@ export async function shoot(t, region) {
36
36
  catch (error) {
37
37
  throw new Error(`${what}: ${error instanceof Error ? error.message : String(error)}`);
38
38
  }
39
- return { shot, image };
39
+ return { shot, image, png };
40
40
  }
41
41
  /** Why this computer's screen is not captured, as hello's screen.capture says it off (an attached Mac whose owner has
42
42
  * not granted the screen); undefined when it is on, or not declared, which a computer of the screen group means as on. */
@@ -61,23 +61,32 @@ export const screenCases = [
61
61
  const off = captureOff(t);
62
62
  if (off !== undefined)
63
63
  return refusedOff(t, off, "screen.shot");
64
- const { shot, image } = await shoot(t);
65
- t.assert(shot.width > 0 && shot.height > 0, `the shot is ${shot.width}x${shot.height}`);
66
- t.deepEqual([image.width, image.height], [shot.width, shot.height], "the PNG's size (IHDR), against the shot's width and height");
67
- t.assert(typeof shot.scale === "number" && shot.scale > 0, `scale is a number above 0, not ${JSON.stringify(shot.scale)}`);
68
- const region = [Math.floor(shot.width / 4), Math.floor(shot.height / 4), Math.max(1, Math.floor(shot.width / 2)), Math.max(1, Math.floor(shot.height / 2))];
69
- const part = await shoot(t, region);
70
- t.deepEqual([part.image.width, part.image.height], [region[2], region[3]], `the PNG of region ${JSON.stringify(region)}: its size (IHDR)`);
71
- t.deepEqual([part.shot.width, part.shot.height], [region[2], region[3]], `the shot of region ${JSON.stringify(region)}: its width and height`);
72
- if (t.provider.capabilities().kind !== "desktop")
73
- return;
74
- const fixture = await t.fixture();
75
- const [x, y, w, h] = fixture.bounds;
76
- const painted = (await shoot(t)).image;
77
- for (const [i, [fx, fy]] of [[0.25, 0.25], [0.75, 0.25], [0.25, 0.75], [0.75, 0.75]].entries()) {
78
- const px = Math.floor(x + fx * w);
79
- const py = Math.floor(y + fy * h);
80
- t.deepEqual(painted.rgb(px, py), FIXTURE_COLORS[i], `the fixture's ${QUADRANTS[i]} quadrant, at (${px}, ${py})`);
64
+ const { shot, image, png } = await shoot(t);
65
+ // The run's frame, handed over once however the case ends: its last whole shot (on a desktop that reached it, the
66
+ // one with the fixture painted).
67
+ let frame = png;
68
+ try {
69
+ t.assert(shot.width > 0 && shot.height > 0, `the shot is ${shot.width}x${shot.height}`);
70
+ t.deepEqual([image.width, image.height], [shot.width, shot.height], "the PNG's size (IHDR), against the shot's width and height");
71
+ t.assert(typeof shot.scale === "number" && shot.scale > 0, `scale is a number above 0, not ${JSON.stringify(shot.scale)}`);
72
+ const region = [Math.floor(shot.width / 4), Math.floor(shot.height / 4), Math.max(1, Math.floor(shot.width / 2)), Math.max(1, Math.floor(shot.height / 2))];
73
+ const part = await shoot(t, region);
74
+ t.deepEqual([part.image.width, part.image.height], [region[2], region[3]], `the PNG of region ${JSON.stringify(region)}: its size (IHDR)`);
75
+ t.deepEqual([part.shot.width, part.shot.height], [region[2], region[3]], `the shot of region ${JSON.stringify(region)}: its width and height`);
76
+ if (t.provider.capabilities().kind !== "desktop")
77
+ return;
78
+ const fixture = await t.fixture();
79
+ const [x, y, w, h] = fixture.bounds;
80
+ const last = await shoot(t);
81
+ frame = last.png;
82
+ for (const [i, [fx, fy]] of [[0.25, 0.25], [0.75, 0.25], [0.25, 0.75], [0.75, 0.75]].entries()) {
83
+ const px = Math.floor(x + fx * w);
84
+ const py = Math.floor(y + fy * h);
85
+ t.deepEqual(last.image.rgb(px, py), FIXTURE_COLORS[i], `the fixture's ${QUADRANTS[i]} quadrant, at (${px}, ${py})`);
86
+ }
87
+ }
88
+ finally {
89
+ t.onScreenshot(frame);
81
90
  }
82
91
  },
83
92
  },
@@ -32,6 +32,8 @@ export declare const DAYTONA_ENV: {
32
32
  readonly archilEgress: "COMPUTER_DAYTONA_ARCHIL_EGRESS";
33
33
  /** connect: exec (default) or dial, which needs the public server's process (dialKit). */
34
34
  readonly connect: "COMPUTER_DAYTONA_CONNECT";
35
+ /** kind: linux (default) or desktop, which create() takes on dial alone. */
36
+ readonly kind: "COMPUTER_DAYTONA_KIND";
35
37
  };
36
38
  /** The names this module reads, under the conformance modules' common name (ConformanceModule.ENV). */
37
39
  export declare const ENV: {
@@ -60,6 +62,8 @@ export declare const ENV: {
60
62
  readonly archilEgress: "COMPUTER_DAYTONA_ARCHIL_EGRESS";
61
63
  /** connect: exec (default) or dial, which needs the public server's process (dialKit). */
62
64
  readonly connect: "COMPUTER_DAYTONA_CONNECT";
65
+ /** kind: linux (default) or desktop, which create() takes on dial alone. */
66
+ readonly kind: "COMPUTER_DAYTONA_KIND";
63
67
  };
64
68
  /**
65
69
  * The provider's options this module reads from env, each only when its name is set; throws in words without the key,
@@ -12,6 +12,7 @@ import { DAYTONA_DEFAULT_SNAPSHOT } from "../descriptors/daytona.js";
12
12
  import { archilRunFolder, archilSettings } from "./archil.js";
13
13
  import { dialOnlyFromServer } from "./dial-only.js";
14
14
  import { buildDriftDaemon, DRIFT_VERSION } from "./drift-daemon.js";
15
+ import { kindFrom } from "./kind.js";
15
16
  /** The Archil disk's settings for the mount cases, by name (COMPUTER_ARCHIL_*: all five, or none). */
16
17
  export { ARCHIL_ENV } from "./archil.js";
17
18
  /** The environment this module reads, by name, each for the option its comment names. */
@@ -41,6 +42,8 @@ export const DAYTONA_ENV = {
41
42
  archilEgress: "COMPUTER_DAYTONA_ARCHIL_EGRESS",
42
43
  /** connect: exec (default) or dial, which needs the public server's process (dialKit). */
43
44
  connect: "COMPUTER_DAYTONA_CONNECT",
45
+ /** kind: linux (default) or desktop, which create() takes on dial alone. */
46
+ kind: "COMPUTER_DAYTONA_KIND",
44
47
  };
45
48
  /** The names this module reads, under the conformance modules' common name (ConformanceModule.ENV). */
46
49
  export const ENV = DAYTONA_ENV;
@@ -92,6 +95,8 @@ export const conformanceNotes = [
92
95
  function optionsOf({ env = process.env, fetch, webSocket, timeouts, onNote, dial, daemonPath }) {
93
96
  return {
94
97
  ...settingsFromEnv(env),
98
+ // create() refuses any other kind, and desktop without dial, in words.
99
+ ...kindFrom(env, DAYTONA_ENV.kind),
95
100
  ...(daemonPath === undefined ? {} : { daemonPath }),
96
101
  autoStopMinutes: CONFORMANCE_AUTO_STOP_MINUTES,
97
102
  autoDeleteMinutes: CONFORMANCE_AUTO_DELETE_MINUTES,
@@ -59,7 +59,7 @@ export function formatReport(report) {
59
59
  }
60
60
  // Each computer's daemon, named with its role: computers of one run may answer differently (a GPU computer's fence).
61
61
  for (const daemon of daemons)
62
- lines.push(`daemon ${daemon.computer} (${daemon.role}): ${said(daemon)}${daemon.fence === undefined ? "" : ` · fence ${daemon.fence}`}`);
62
+ lines.push(`daemon ${daemon.computer} (${daemon.role}): ${said(daemon)}${daemon.fence === undefined ? "" : ` · fence ${daemon.fence}`}${daemon.windowManager === undefined ? "" : ` · window manager ${daemon.windowManager.state}${daemon.windowManager.why ? `: ${daemon.windowManager.why}` : ""}`}`);
63
63
  for (const note of report.notes ?? [])
64
64
  lines.push(`note: ${note}`);
65
65
  for (const { computer, role, note } of report.computerNotes ?? [])
@@ -280,7 +280,7 @@ export async function runConformance(provider, options) {
280
280
  const sawHello = (computer, hello, role) => {
281
281
  if (report.daemons.some((daemon) => daemon.computer === computer))
282
282
  return;
283
- report.daemons.push({ computer, role: roles.get(computer) ?? role, version: hello.version, os: hello.os, arch: hello.arch, ...(hello.fence === undefined ? {} : { fence: hello.fence }) });
283
+ report.daemons.push({ computer, role: roles.get(computer) ?? role, version: hello.version, os: hello.os, arch: hello.arch, ...(hello.fence === undefined ? {} : { fence: hello.fence }), ...(hello.windowManager === undefined ? {} : { windowManager: hello.windowManager }) });
284
284
  };
285
285
  /**
286
286
  * The run's shared computer, made the first time a case needs it or the daemon's hello, and again after it made way
@@ -660,6 +660,9 @@ export async function runConformance(provider, options) {
660
660
  observe(words) {
661
661
  observed.push(words);
662
662
  },
663
+ onScreenshot(png) {
664
+ options.onScreenshot?.(png);
665
+ },
663
666
  };
664
667
  await c.run(t);
665
668
  };
@@ -1,5 +1,5 @@
1
1
  import type { MountKind, MountSpec } from "../mount.js";
2
- import type { ComputerClient, ComputerKind, ComputerOs, DaemonMethod, DaemonMethods, ExecRunParams, Group, HelloResult, NetworkFence } from "../protocol.js";
2
+ import type { ComputerClient, ComputerKind, ComputerOs, DaemonMethod, DaemonMethods, ExecRunParams, Group, HelloResult, NetworkFence, WindowManagerFact } from "../protocol.js";
3
3
  import type { ComputerConnection, ComputerProvider, ComputerRef, ComputerSpec, DaemonMode, GpuSpec } from "../provider.js";
4
4
  import type { ComputerError, ComputerErrorCode, Result } from "../result.js";
5
5
  import type { KindCapabilities } from "../kinds.js";
@@ -137,6 +137,8 @@ export interface CaseContext {
137
137
  skip(reason: string): never;
138
138
  /** Records what the case saw without asserting it (its result's observed), for a fact not yet known either way. */
139
139
  observe(words: string): void;
140
+ /** Hands a whole screenshot, its PNG's bytes, to the run's onScreenshot (ConformanceOptions), when it has one. */
141
+ onScreenshot(png: Uint8Array): void;
140
142
  }
141
143
  export interface Case {
142
144
  /** `<group>.<name>`. */
@@ -260,7 +262,10 @@ export type ComputerRole = string;
260
262
  export interface CreatedNote extends ComputerNote {
261
263
  role: ComputerRole;
262
264
  }
263
- /** What one computer's first hello said: the computer, its role, and the fence when it names one. */
265
+ /**
266
+ * What one computer's first hello said: the computer, its role, the fence when it names one, and the window manager
267
+ * computerd started when it says one (a live run's evidence that computerd, not create, started it).
268
+ */
264
269
  export interface ComputerDaemon {
265
270
  computer: string;
266
271
  role: ComputerRole;
@@ -268,6 +273,7 @@ export interface ComputerDaemon {
268
273
  os: string;
269
274
  arch: string;
270
275
  fence?: NetworkFence;
276
+ windowManager?: WindowManagerFact;
271
277
  }
272
278
  /**
273
279
  * The server a dial host's machines reach (MachineHost facts.connect "dial"), as the run stands it up: its machine
@@ -325,6 +331,9 @@ export interface ConformanceOptions {
325
331
  mountFor?: (kind: MountKind) => Promise<RunFolder | undefined> | RunFolder | undefined;
326
332
  /** Called as each case ends. */
327
333
  onResult?: (result: CaseResult) => void;
334
+ /** Called once with the last whole screenshot screen.screenshot-size read, its PNG's bytes, whether the case passes or
335
+ * fails after it: a frame of what the screen showed. */
336
+ onScreenshot?: (png: Uint8Array) => void;
328
337
  /** Notes the provider module gives for the report, printed before the verdict. */
329
338
  notes?: string[];
330
339
  /** The longest one case may run; default 180 s. */
package/dist/daytona.d.ts CHANGED
@@ -19,7 +19,7 @@ export type DaytonaTimeouts = HostedTimeouts & {
19
19
  };
20
20
  /**
21
21
  * The Daytona provider's options: the key and Daytona's own settings, then the shared adapter's (HostedOptions), kind
22
- * among them: linux alone, kind desktop refused in its descriptor's unserved words (kindRefusal).
22
+ * among them: a desktop on connect dial alone (kindRefusal; the why is PROVIDERS.md's Daytona bullet).
23
23
  */
24
24
  export interface DaytonaProviderOptions extends Omit<HostedOptions, "desktop" | "maxLifetimeMs" | "timeouts"> {
25
25
  /** The Daytona API key. The caller passes it; this provider never reads the environment and never puts it in a computer. */
package/dist/daytona.js CHANGED
@@ -142,6 +142,10 @@ class DaytonaHost {
142
142
  maxLifetimeMs: MAX_LIFETIME_MS,
143
143
  arch: options.arch,
144
144
  vendorAgentPorts: [TOOLBOX_PORT],
145
+ // A snapshot of box/Dockerfile has xfwm4 (box/install.sh's desktop step), for a desktop (connect dial alone).
146
+ // computerd starts it as root makes its network namespace: the tool user can make none here (Sysbox, with
147
+ // kernel.apparmor_restrict_unprivileged_userns=1, measured 11-19).
148
+ windowManager: true,
145
149
  ...(options.connect === "dial" ? { connect: options.connect } : {}),
146
150
  };
147
151
  if (options.connect === "exec") {
@@ -1,6 +1,4 @@
1
1
  import type { GpuCapability } from "../provider.js";
2
- /** Why Daytona gives no desktop (measured 11-19): PROVIDERS.md, Machines that dial in. The descriptor's unserved desktop. */
3
- export declare const DAYTONA_NO_DESKTOP = "its sandboxes run under AppArmor's restrict_unprivileged_userns, so the tool user can't make the user and network namespaces the window manager runs in";
4
2
  /** The key that turns on a Daytona computer's Archil mount: the operator's Archil egress relay (archilEgress). */
5
3
  export declare const DAYTONA_ARCHIL_EGRESS = "DAYTONA_ARCHIL_EGRESS";
6
4
  /** Why a Daytona computer made with no Archil egress takes no Archil mount: check() refuses one in these words. */
@@ -91,10 +89,20 @@ export declare const DAYTONA: {
91
89
  };
92
90
  readonly image?: string;
93
91
  readonly options?: Readonly<Record<string, unknown>>;
92
+ }, {
93
+ readonly options: {
94
+ readonly kind: "desktop";
95
+ readonly connect: "dial";
96
+ };
97
+ readonly kind: import("../protocol.js").ComputerKind;
98
+ readonly groups: import("../protocol.js").Group[];
99
+ readonly gpu?: GpuCapability;
100
+ readonly persistence?: {
101
+ keepsState: true;
102
+ resume: boolean;
103
+ };
104
+ readonly image?: string;
94
105
  }];
95
- readonly unserved: {
96
- readonly desktop: "its sandboxes run under AppArmor's restrict_unprivileged_userns, so the tool user can't make the user and network namespaces the window manager runs in";
97
- };
98
106
  readonly defaultImage: {
99
107
  readonly sandbox: "default";
100
108
  };
@@ -1,9 +1,7 @@
1
1
  // Daytona's descriptor: a sandbox on Daytona's cloud, with GPUs when asked; the run's folder on an Archil disk only where
2
2
  // the operator gives an Archil egress relay (a self-hosted Daytona target), never on Daytona's hosted cloud.
3
3
  import { defineProvider } from "../descriptor.js";
4
- import { SANDBOX } from "./shared.js";
5
- /** Why Daytona gives no desktop (measured 11-19): PROVIDERS.md, Machines that dial in. The descriptor's unserved desktop. */
6
- export const DAYTONA_NO_DESKTOP = "its sandboxes run under AppArmor's restrict_unprivileged_userns, so the tool user can't make the user and network namespaces the window manager runs in";
4
+ import { LINUX_DESKTOP, SANDBOX } from "./shared.js";
7
5
  /** The key that turns on a Daytona computer's Archil mount: the operator's Archil egress relay (archilEgress). */
8
6
  export const DAYTONA_ARCHIL_EGRESS = "DAYTONA_ARCHIL_EGRESS";
9
7
  /** Why a Daytona computer made with no Archil egress takes no Archil mount: check() refuses one in these words. */
@@ -92,9 +90,12 @@ export const DAYTONA = defineProvider({
92
90
  // its programs' one way out is init's egress proxy, which reaches the public internet alone, and with a list its hosts
93
91
  // alone (hosted/network.ts).
94
92
  network: ["none", "open", "allow"],
95
- // A linux computer, with GPUs when asked. No desktop, on any connect (DAYTONA_NO_DESKTOP).
96
- capabilities: [{ ...SANDBOX, gpu: DAYTONA_GPU }],
97
- unserved: { desktop: DAYTONA_NO_DESKTOP },
93
+ // A linux computer, with GPUs when asked; or, on connect dial alone, a desktop with none: a snapshot of box/Dockerfile's
94
+ // X server, started through computerd over the socket the sandbox dialed, and xfwm4, which computerd starts itself
95
+ // (init --window-manager), at the snapshot's 2 CPUs and 4 GiB (box/build-daytona.py). The desktop's configuration
96
+ // selects dial itself, whatever daytonaConnect says: a provider on connect exec refuses kind desktop when it is made
97
+ // (kindRefusal; the why is PROVIDERS.md's Daytona bullet).
98
+ capabilities: [{ ...SANDBOX, gpu: DAYTONA_GPU }, { ...LINUX_DESKTOP, options: { kind: "desktop", connect: "dial" } }],
98
99
  defaultImage: { sandbox: DAYTONA_DEFAULT_SNAPSHOT },
99
100
  // The operator's own snapshot for every Daytona computer, named here; the default snapshot stands while unset. A
100
101
  // computer with an Archil mount needs a snapshot of box/Dockerfile (box/build-daytona.py prints its name).
@@ -80,10 +80,20 @@ export declare const DESCRIPTORS: readonly [{
80
80
  };
81
81
  readonly image?: string;
82
82
  readonly options?: Readonly<Record<string, unknown>>;
83
+ }, {
84
+ readonly options: {
85
+ readonly kind: "desktop";
86
+ readonly connect: "dial";
87
+ };
88
+ readonly kind: import("../protocol.js").ComputerKind;
89
+ readonly groups: import("../protocol.js").Group[];
90
+ readonly gpu?: import("../provider.js").GpuCapability;
91
+ readonly persistence?: {
92
+ keepsState: true;
93
+ resume: boolean;
94
+ };
95
+ readonly image?: string;
83
96
  }];
84
- readonly unserved: {
85
- readonly desktop: "its sandboxes run under AppArmor's restrict_unprivileged_userns, so the tool user can't make the user and network namespaces the window manager runs in";
86
- };
87
97
  readonly defaultImage: {
88
98
  readonly sandbox: "default";
89
99
  };
package/dist/desktop.d.ts CHANGED
@@ -10,29 +10,16 @@ export interface DesktopOptions {
10
10
  }
11
11
  /** The groups a desktop declares besides exec, files and processes: apps is computerd's, from the desktop's .desktop files. */
12
12
  export declare const DESKTOP_GROUPS: readonly ["screen", "input.pointer", "input.keys", "apps"];
13
- /**
14
- * The window manager a host's desktops run where its facts say so (HostFacts.windowManager: E2B's and Agent37's), once
15
- * the display answers: it frames, stacks and focuses the windows apps.launch opens. xfwm4, which both images have, with
16
- * no compositor and no session manager. It reads its settings from xfconfd over a session bus, and exits at once
17
- * without one ("Xfconf could not be initialized"). So it runs in a session bus of its own (dbus-run-session, WINDOW_MANAGER_BUS, written to a file of
18
- * its own under /tmp), in a user namespace (the same uid) and a network namespace of its own: a program of the
19
- * computer's user reaches no socket of that bus, unless it joins those namespaces (nsenter), as the same uid may
20
- * ptrace xfwm4. xfwm4 reaches the display as any program does, by its path. First, xsetroot paints the screen behind
21
- * every window one slate colour, so a desktop with no window open is not a black screen a person reads as broken; a
22
- * paint that fails starts xfwm4 all the same.
23
- */
24
- export declare const WINDOW_MANAGER: readonly string[];
25
13
  /** The desktop options with their defaults, or a throw in words. */
26
14
  export declare function desktopOf({ display, server, timeoutMs }: DesktopOptions): Required<DesktopOptions>;
27
15
  /**
28
16
  * Starts the desktop's X server through the daemon (process.start) and waits until hello declares the display: the
29
17
  * server ending first, or the bound passing, is a failure in words, with the server's own last words, as the vendor's
30
- * (code vendor, vendor the provider's id). version is the client's, sent with each hello. windowManager: the host's
31
- * desktops run WINDOW_MANAGER (HostFacts.windowManager), started once the display answers.
18
+ * (code vendor, vendor the provider's id). version is the client's, sent with each hello. Once the display answers, a
19
+ * hello with windowManager (computerd was asked to start it) is waited on until the manager runs.
32
20
  */
33
- export declare function startDisplay(client: ComputerClient, desktop: Required<DesktopOptions>, { version, vendor, signal, windowManager }: {
21
+ export declare function startDisplay(client: ComputerClient, desktop: Required<DesktopOptions>, { version, vendor, signal }: {
34
22
  version: string;
35
23
  vendor: string;
36
24
  signal?: AbortSignal | undefined;
37
- windowManager?: boolean;
38
25
  }): Promise<Result<void>>;
package/dist/desktop.js CHANGED
@@ -1,60 +1,18 @@
1
1
  // A desktop on an X server computerd starts itself: the provider gives init DISPLAY, then starts the X server through
2
2
  // the daemon with process.start, as any program, so the server is in init's process table and ends with the computer.
3
3
  // The daemon reaches the display once it answers, and hello declares screen, input.pointer, input.keys and apps from then
4
- // on (hello re-checks the display on each call). A window manager, when the desktop has one, starts next, the same way.
5
- // Docker's desktops, E2B's and Agent37's start the display this way.
4
+ // on (hello re-checks the display on each call). A window manager, when the desktop has one, comes next: computerd starts
5
+ // it itself when init was asked to (init --window-manager; see daemon/internal/windowmanager), and create waits on
6
+ // hello's windowManager until it runs.
7
+ // Docker's desktops, E2B's, Agent37's and Daytona's start the display this way.
6
8
  import { setTimeout as sleep } from "node:timers/promises";
7
9
  import { fail, ok, vendorFail } from "./result.js";
8
10
  /** The groups a desktop declares besides exec, files and processes: apps is computerd's, from the desktop's .desktop files. */
9
11
  export const DESKTOP_GROUPS = ["screen", "input.pointer", "input.keys", "apps"];
10
- /**
11
- * The session bus the window manager reads its settings over: dbus's own session config, but listening on an abstract
12
- * name, which only a program in the bus's own network namespace reaches. dbus's unix:tmpdir is a socket under /tmp
13
- * with dbus 1.16 (Agent37's box), which every program of the user reaches.
14
- */
15
- const WINDOW_MANAGER_BUS = `<busconfig>
16
- <type>session</type>
17
- <keep_umask/>
18
- <listen>unix:abstract=/agentrun/window-manager</listen>
19
- <auth>EXTERNAL</auth>
20
- <standard_session_servicedirs/>
21
- <policy context="default">
22
- <allow send_destination="*" eavesdrop="true"/>
23
- <allow eavesdrop="true"/>
24
- <allow own="*"/>
25
- </policy>
26
- </busconfig>`;
27
- /**
28
- * The window manager a host's desktops run where its facts say so (HostFacts.windowManager: E2B's and Agent37's), once
29
- * the display answers: it frames, stacks and focuses the windows apps.launch opens. xfwm4, which both images have, with
30
- * no compositor and no session manager. It reads its settings from xfconfd over a session bus, and exits at once
31
- * without one ("Xfconf could not be initialized"). So it runs in a session bus of its own (dbus-run-session, WINDOW_MANAGER_BUS, written to a file of
32
- * its own under /tmp), in a user namespace (the same uid) and a network namespace of its own: a program of the
33
- * computer's user reaches no socket of that bus, unless it joins those namespaces (nsenter), as the same uid may
34
- * ptrace xfwm4. xfwm4 reaches the display as any program does, by its path. First, xsetroot paints the screen behind
35
- * every window one slate colour, so a desktop with no window open is not a black screen a person reads as broken; a
36
- * paint that fails starts xfwm4 all the same.
37
- */
38
- export const WINDOW_MANAGER = [
39
- "unshare",
40
- "--user",
41
- "--map-current-user",
42
- "--net",
43
- "--",
44
- "sh",
45
- "-c",
46
- 'xsetroot -solid "#3b4b5c"; bus=$(mktemp) && printf "%s" "$1" > "$bus" && exec dbus-run-session --config-file="$bus" -- xfwm4 --compositor=off --sm-client-disable',
47
- "sh",
48
- WINDOW_MANAGER_BUS,
49
- ];
50
- /** WINDOW_MANAGER as create's errors name it: what runs, without the shell line and the bus's config. */
51
- const WINDOW_MANAGER_WORDS = "unshare --user --map-current-user --net -- dbus-run-session -- xfwm4 --compositor=off --sm-client-disable";
52
12
  const DISPLAY = /^:\d{1,5}(\.\d{1,5})?$/;
53
13
  /** How often create asks the daemon whether the display is up yet. */
54
14
  const DISPLAY_POLL_MS = 100;
55
- /** How long create watches a window manager it started: one that ends within it (it could not take the display) fails create. */
56
- const WM_SETTLE_MS = 1_000;
57
- /** The longest create gives a window manager's start and that watch, apart from the display's own timeoutMs. */
15
+ /** The longest create waits on the window manager computerd starts, apart from the display's own timeoutMs. */
58
16
  const WM_BOUND_MS = 15_000;
59
17
  /** The longest a Node timer or AbortSignal.timeout holds. */
60
18
  const MAX_TIMER_MS = 2 ** 31 - 1;
@@ -76,10 +34,10 @@ export function desktopOf({ display = ":0", server, timeoutMs = 30_000 }) {
76
34
  /**
77
35
  * Starts the desktop's X server through the daemon (process.start) and waits until hello declares the display: the
78
36
  * server ending first, or the bound passing, is a failure in words, with the server's own last words, as the vendor's
79
- * (code vendor, vendor the provider's id). version is the client's, sent with each hello. windowManager: the host's
80
- * desktops run WINDOW_MANAGER (HostFacts.windowManager), started once the display answers.
37
+ * (code vendor, vendor the provider's id). version is the client's, sent with each hello. Once the display answers, a
38
+ * hello with windowManager (computerd was asked to start it) is waited on until the manager runs.
81
39
  */
82
- export async function startDisplay(client, desktop, { version, vendor, signal, windowManager = false }) {
40
+ export async function startDisplay(client, desktop, { version, vendor, signal }) {
83
41
  const server = desktop.server.join(" ");
84
42
  // Every call takes a signal that ends at the bound, so a hello the X connection setup holds, or a daemon that stops
85
43
  // answering, cannot outwait it. A call that failed because the bound passed is the timeout; the caller's own abort
@@ -96,8 +54,9 @@ export async function startDisplay(client, desktop, { version, vendor, signal, w
96
54
  const hello = await client.call("hello", { client: `@parcha/agentrun-computer ${version}` }, { signal: either });
97
55
  if (!hello.ok)
98
56
  return timedOut() ? late() : hello;
99
- if (Array.isArray(hello.value.groups) && hello.value.groups.includes("screen"))
100
- return windowManager ? await startWindowManager(client, desktop, vendor, signal) : ok(undefined);
57
+ if (Array.isArray(hello.value.groups) && hello.value.groups.includes("screen")) {
58
+ return hello.value.windowManager ? await awaitWindowManager(client, desktop, { version, vendor, caller: signal }) : ok(undefined);
59
+ }
101
60
  const waited = await client.call("process.wait", { id, timeoutMs: 0 }, { signal: either });
102
61
  if (waited.ok && !waited.value.running) {
103
62
  const read = await client.call("process.read", { id, stream: "stderr", offset: 0 }, { signal: either });
@@ -115,34 +74,27 @@ export async function startDisplay(client, desktop, { version, vendor, signal, w
115
74
  }
116
75
  }
117
76
  /**
118
- * Starts WINDOW_MANAGER on the display that answers. A manager that cannot start, or ends
119
- * within WM_SETTLE_MS (xfwm4 with no session bus, or no display it may open), fails create with its last words. It has
120
- * its own bound, WM_BOUND_MS, not what is left of the display's: a display that came up late still gets its manager's
121
- * full second. The caller's abort still ends it.
77
+ * Waits on the window manager computerd starts itself (hello's windowManager, init --window-manager) until hello says it
78
+ * runs: one that ended fails create in computerd's words, its last lines among them. The bound is WM_BOUND_MS; the
79
+ * caller's abort still ends it.
122
80
  */
123
- async function startWindowManager(client, desktop, vendor, caller) {
124
- const manager = WINDOW_MANAGER_WORDS;
81
+ async function awaitWindowManager(client, desktop, { version, vendor, caller }) {
125
82
  const bound = AbortSignal.timeout(WM_BOUND_MS);
126
83
  const signal = caller ? AbortSignal.any([caller, bound]) : bound;
127
- const stopped = (code, message) => caller?.aborted
84
+ const stopped = () => caller?.aborted
128
85
  ? fail("aborted", "create was aborted while the window manager started")
129
- : bound.aborted
130
- ? fail("timeout", `the window manager (${manager}) did not start on ${desktop.display} within ${WM_BOUND_MS / 1000} s`)
131
- : fail(code, message);
132
- // NO_AT_BRIDGE: GTK (xfwm4's toolkit) asks its session bus for no accessibility bus. On E2B Desktop, which has
133
- // at-spi2-core, that bus is an at-spi-bus-launcher and a socket of the user's under its home (~/.cache/at-spi/bus_0).
134
- const env = { DISPLAY: desktop.display, NO_AT_BRIDGE: "1" };
135
- const started = await client.call("process.start", { argv: [...WINDOW_MANAGER], env }, { signal });
136
- if (!started.ok)
137
- return stopped(started.error.code, `the window manager (${manager}) did not start on ${desktop.display}: ${started.error.message}`);
138
- const { id } = started.value;
139
- const waited = await client.call("process.wait", { id, timeoutMs: WM_SETTLE_MS }, { signal });
140
- if (!waited.ok)
141
- return stopped(waited.error.code, `the window manager (${manager}) could not be waited on: ${waited.error.message}`);
142
- if (waited.value.running)
143
- return ok(undefined);
144
- const read = await client.call("process.read", { id, stream: "stderr", offset: 0 }, { signal });
145
- const words = read.ok ? Buffer.from(read.value.data, "base64").toString("utf8").trim().split("\n").slice(-5).join("; ") : "";
146
- const how = waited.value.signal ? `signal ${waited.value.signal}` : `exit code ${waited.value.exitCode}`;
147
- return vendorFail(vendor, `the window manager (${manager}) ended with ${how} within ${WM_SETTLE_MS / 1000} s of starting on ${desktop.display}${words ? `: ${words}` : ""}`);
86
+ : fail("timeout", `the window manager computerd starts did not run on ${desktop.display} within ${WM_BOUND_MS / 1000} s`);
87
+ for (;;) {
88
+ const hello = await client.call("hello", { client: `@parcha/agentrun-computer ${version}` }, { signal });
89
+ if (!hello.ok)
90
+ return signal.aborted ? stopped() : fail(hello.error.code, `hello, while the window manager computerd starts came up on ${desktop.display}: ${hello.error.message}`);
91
+ const fact = hello.value.windowManager;
92
+ if (fact?.state === "running")
93
+ return ok(undefined);
94
+ if (fact?.state === "ended")
95
+ return vendorFail(vendor, fact.why ?? `the window manager computerd starts ended on ${desktop.display}`);
96
+ await sleep(DISPLAY_POLL_MS, undefined, { signal }).catch(() => undefined);
97
+ if (signal.aborted)
98
+ return stopped();
99
+ }
148
100
  }
package/dist/host.d.ts CHANGED
@@ -224,7 +224,7 @@ export interface HostFacts {
224
224
  arch: "amd64" | "arm64";
225
225
  /** The TCP ports the vendor's own agent listens on inside the machine (E2B's envd 49983). */
226
226
  vendorAgentPorts: number[];
227
- /** Whether its desktops run WINDOW_MANAGER (xfwm4, which its image has) once the display answers. Default none. */
227
+ /** Whether its desktops run a window manager (xfwm4, which its image has), which computerd starts (init --window-manager). Default none. */
228
228
  windowManager?: boolean;
229
229
  /** What spec.user may ask for, beside the daemon user: with it, the spec's user goes in MachineRequest.user. */
230
230
  user?: Array<"root" | "uid">;
@@ -685,6 +685,8 @@ export class HostedProvider {
685
685
  return this.#fail("refused", `labels: ${stored.problem}`);
686
686
  const archil = spec.mount?.kind === "archil";
687
687
  const user = this.#userOf(spec);
688
+ // A desktop whose host runs a window manager has computerd start it (init --window-manager).
689
+ const windowManager = this.#desktop !== undefined && this.host.facts.windowManager === true;
688
690
  const commands = hostedCommands({
689
691
  staging: `${STAGING}${randomBytes(8).toString("hex")}`,
690
692
  deadline,
@@ -701,10 +703,11 @@ export class HostedProvider {
701
703
  network: formOf(spec.network),
702
704
  // A synced folder's /workspace, the computer's user's, made by install before init.
703
705
  workspace: spec.mount?.kind === "sync",
706
+ windowManager,
704
707
  });
705
708
  const backstopAt = new Date(now + this.#maxLifetimeMs + BACKSTOP_MARGIN_MS).toISOString();
706
709
  const run = spec.labels?.[RUN_LABEL];
707
- const boot = this.#dialing ? await this.#boot(name, backstopAt, { deadline, user, maxDeadline, network: formOf(spec.network) }, sha256, typeof run === "string" ? run : undefined) : undefined;
710
+ const boot = this.#dialing ? await this.#boot(name, backstopAt, { deadline, user, maxDeadline, network: formOf(spec.network), windowManager }, sha256, typeof run === "string" ? run : undefined) : undefined;
708
711
  if (boot !== undefined && !boot.ok)
709
712
  return boot;
710
713
  const request = {
@@ -999,7 +1002,7 @@ export class HostedProvider {
999
1002
  async #checkInside(connection, name, network, starting, want, signal, folder) {
1000
1003
  let current = connection;
1001
1004
  if (starting && this.#desktop) {
1002
- const shown = await startDisplay(connection.client, this.#desktop, { version: VERSION, vendor: this.id, signal, windowManager: this.host.facts.windowManager === true });
1005
+ const shown = await startDisplay(connection.client, this.#desktop, { version: VERSION, vendor: this.id, signal });
1003
1006
  if (!shown.ok)
1004
1007
  return shown;
1005
1008
  const hello = await connection.client.call("hello", { client: `@parcha/agentrun-computer ${VERSION}` }, { signal: bounded(this.#timeouts.helloMs, signal) });
@@ -47,7 +47,7 @@ export interface HostedCommands {
47
47
  * the patterns a child's sockets command closes (default SESSION_BUSES); rootOnly the paths its root-only command takes
48
48
  * others' write off (default none). With workspace, install makes WORKSPACE the user's, 0700: a synced folder's.
49
49
  */
50
- export declare function hostedCommands({ staging, deadline, user, display, maxDeadline, atomic, waitS, gate, sha256, nonce, sockets, rootOnly, network, workspace, }?: ChildCommandOptions & {
50
+ export declare function hostedCommands({ staging, deadline, user, display, maxDeadline, atomic, waitS, gate, sha256, nonce, sockets, rootOnly, network, workspace, windowManager, }?: ChildCommandOptions & {
51
51
  atomic?: boolean;
52
52
  waitS?: number;
53
53
  gate?: string;
@@ -70,19 +70,21 @@ export interface ChildCommandOptions {
70
70
  maxDeadline?: string;
71
71
  /** The network form init's egress proxy serves (./network.ts networkFormOf): open, or allow: and a list; none, no proxy. */
72
72
  network?: string;
73
+ /** Init starts the desktop's window manager on the display (--window-manager): a desktop whose host runs one. */
74
+ windowManager?: boolean;
73
75
  }
74
76
  /**
75
77
  * init's flags, as start and a pid1 entrypoint give them: the deadline, the user, --own-network, and the most
76
- * deadline.extend may move it to and the network form where given. A dial machine's AGENTRUN_INIT_ARGS, space-separated:
77
- * no value holds a space.
78
+ * deadline.extend may move it to, the network form and --window-manager where given. A dial machine's
79
+ * AGENTRUN_INIT_ARGS, space-separated: no value holds a space.
78
80
  */
79
- export declare function initFlags({ deadline, user, maxDeadline, network }: Omit<ChildCommandOptions, "staging" | "display">): string[];
81
+ export declare function initFlags({ deadline, user, maxDeadline, network, windowManager }: Omit<ChildCommandOptions, "staging" | "display">): string[];
80
82
  /**
81
83
  * The three shell commands a child-daemon provider sends into a computer, exactly: install (the upload moved into place,
82
84
  * its sha256 printed), init (long-lived) and stdio (one per connection). Each is one string for a shell, `sh -c` with
83
85
  * every argument quoted.
84
86
  */
85
- export declare function childCommands({ staging, deadline, user, display, maxDeadline, network }?: ChildCommandOptions): {
87
+ export declare function childCommands({ staging, deadline, user, display, maxDeadline, network, windowManager }?: ChildCommandOptions): {
86
88
  install: string;
87
89
  init: string;
88
90
  stdio: string;
@@ -67,15 +67,17 @@ export function installerOf(output) {
67
67
  * them at the deadline. A display, when given, is init's DISPLAY, the X display its screen and input methods drive; a
68
68
  * maximum, when given, is the most deadline.extend may move the deadline to; a network form, when given (open, or
69
69
  * allow: and a list), has init start the egress proxy that serves it before it leaves the machine's network
70
- * (./network.ts). */
70
+ * (./network.ts); a ninth argument, when not empty, has init start the desktop's window manager on the display
71
+ * (--window-manager). */
71
72
  const INIT_SCRIPT = [
72
73
  "# agentrun-computer: init",
73
- // The display is v, not x: held() assigns x, and runs before the exec that reads it. The network form is n.
74
- "d=$1; t=$2; w=$3; h=$4; r=$5; v=${6-}; m=${7-}; n=${8-}",
74
+ // The display is v, not x: held() assigns x, and runs before the exec that reads it. The network form is n, the
75
+ // window manager g.
76
+ "d=$1; t=$2; w=$3; h=$4; r=$5; v=${6-}; m=${7-}; n=${8-}; g=${9-}",
75
77
  HELD,
76
78
  'held "$d" >&2 || exit 6',
77
79
  ROOT,
78
- `exec $p env -i PATH=${PATH} HOME="$h" AGENTRUN_COMPUTERD_SOCKET="$r/computerd.sock" \${v:+DISPLAY="$v"} sh -c 'cd "$HOME" && exec "$@"' sh "$d" init --deadline "$t" --user "$w" --own-network \${m:+--max-deadline "$m"} \${n:+--network "$n"}`,
80
+ `exec $p env -i PATH=${PATH} HOME="$h" AGENTRUN_COMPUTERD_SOCKET="$r/computerd.sock" \${v:+DISPLAY="$v"} sh -c 'cd "$HOME" && exec "$@"' sh "$d" init --deadline "$t" --user "$w" --own-network \${m:+--max-deadline "$m"} \${n:+--network "$n"} \${g:+--window-manager}`,
79
81
  ].join("\n");
80
82
  /** The bridge one connection runs: stdin and stdout to init's socket. As root, to reach a socket in a directory that is
81
83
  * the daemon's user's alone; it only carries bytes, and the command's user is root or has passwordless sudo already.
@@ -193,9 +195,9 @@ export const ARCHIL_GATE = `${DAEMON_IN_COMPUTER.slice(0, DAEMON_IN_COMPUTER.las
193
195
  * the patterns a child's sockets command closes (default SESSION_BUSES); rootOnly the paths its root-only command takes
194
196
  * others' write off (default none). With workspace, install makes WORKSPACE the user's, 0700: a synced folder's.
195
197
  */
196
- export function hostedCommands({ staging = "", deadline = "", user = TOOL_USER, display = "", maxDeadline = "", atomic = false, waitS = 600, gate, sha256 = "", nonce = "", sockets = SESSION_BUSES, rootOnly = [], network = "", workspace = false, } = {}) {
197
- const init = initScriptArgs({ deadline, user, display, maxDeadline, network });
198
- const initArgs = ["init", ...initFlags({ deadline, user, maxDeadline, network })];
198
+ export function hostedCommands({ staging = "", deadline = "", user = TOOL_USER, display = "", maxDeadline = "", atomic = false, waitS = 600, gate, sha256 = "", nonce = "", sockets = SESSION_BUSES, rootOnly = [], network = "", workspace = false, windowManager = false, } = {}) {
199
+ const init = initScriptArgs({ deadline, user, display, maxDeadline, network, windowManager });
200
+ const initArgs = ["init", ...initFlags({ deadline, user, maxDeadline, network, windowManager })];
199
201
  const atomicArgs = atomic ? ["1", sha256, nonce] : workspace ? ["", "", ""] : [];
200
202
  return {
201
203
  install: argvOf(INSTALL_SCRIPT, [staging, DAEMON_IN_COMPUTER, WORK, SOCKET_DIR, ...atomicArgs, ...(workspace ? [WORKSPACE, user] : [])]),
@@ -209,17 +211,28 @@ export function hostedCommands({ staging = "", deadline = "", user = TOOL_USER,
209
211
  }
210
212
  /**
211
213
  * init's flags, as start and a pid1 entrypoint give them: the deadline, the user, --own-network, and the most
212
- * deadline.extend may move it to and the network form where given. A dial machine's AGENTRUN_INIT_ARGS, space-separated:
213
- * no value holds a space.
214
+ * deadline.extend may move it to, the network form and --window-manager where given. A dial machine's
215
+ * AGENTRUN_INIT_ARGS, space-separated: no value holds a space.
214
216
  */
215
- export function initFlags({ deadline = "", user = TOOL_USER, maxDeadline = "", network = "" }) {
216
- return ["--deadline", deadline, "--user", user, "--own-network", ...(maxDeadline === "" ? [] : ["--max-deadline", maxDeadline]), ...(network === "" ? [] : ["--network", network])];
217
+ export function initFlags({ deadline = "", user = TOOL_USER, maxDeadline = "", network = "", windowManager = false }) {
218
+ return [
219
+ "--deadline",
220
+ deadline,
221
+ "--user",
222
+ user,
223
+ "--own-network",
224
+ ...(maxDeadline === "" ? [] : ["--max-deadline", maxDeadline]),
225
+ ...(network === "" ? [] : ["--network", network]),
226
+ ...(windowManager ? ["--window-manager"] : []),
227
+ ];
217
228
  }
218
229
  /** The init script's arguments: the daemon, the deadline, the user, home and the socket's folder, then the display, the
219
- * maximum and the network form, each empty when not given, where any of them is. */
220
- function initScriptArgs({ deadline = "", user = TOOL_USER, display = "", maxDeadline = "", network = "" }) {
230
+ * maximum, the network form and the window manager ("1"), each empty when not given, where any of them is. */
231
+ function initScriptArgs({ deadline = "", user = TOOL_USER, display = "", maxDeadline = "", network = "", windowManager = false }) {
221
232
  const init = [DAEMON_IN_COMPUTER, deadline, user, WORK, SOCKET_DIR];
222
- if (network !== "")
233
+ if (windowManager)
234
+ init.push(display, maxDeadline, network, "1");
235
+ else if (network !== "")
223
236
  init.push(display, maxDeadline, network);
224
237
  else if (display !== "" || maxDeadline !== "")
225
238
  init.push(display, maxDeadline);
@@ -230,8 +243,8 @@ function initScriptArgs({ deadline = "", user = TOOL_USER, display = "", maxDead
230
243
  * its sha256 printed), init (long-lived) and stdio (one per connection). Each is one string for a shell, `sh -c` with
231
244
  * every argument quoted.
232
245
  */
233
- export function childCommands({ staging = "", deadline = "", user = TOOL_USER, display = "", maxDeadline = "", network = "" } = {}) {
234
- const init = initScriptArgs({ deadline, user, display, maxDeadline, network });
246
+ export function childCommands({ staging = "", deadline = "", user = TOOL_USER, display = "", maxDeadline = "", network = "", windowManager = false } = {}) {
247
+ const init = initScriptArgs({ deadline, user, display, maxDeadline, network, windowManager });
235
248
  return {
236
249
  install: shellCommand(INSTALL_SCRIPT, [staging, DAEMON_IN_COMPUTER, WORK, SOCKET_DIR]),
237
250
  init: shellCommand(INIT_SCRIPT, init),
package/dist/index.d.ts CHANGED
@@ -17,7 +17,7 @@ export { type DockerVolume, VOLUME_SUBPATH_ENGINE } from "./docker/volume.js";
17
17
  export { DEFAULT_DOCKER_IMAGE, DOCKER_BASE, DOCKER_RECIPE, DOCKER_RECIPE_HAS, ensureImage, type EnsureImageOptions, IMAGE_REPOSITORY, IMAGE_TIMEOUT_MS, type ImageSource, imageSourceProblem, type Making, RECIPE_LABEL, recipeHash, recipeTag, } from "./docker/image.js";
18
18
  export { EGRESS_IMAGE, EGRESS_LABEL, EGRESS_MOUNT, EGRESS_SOCKET } from "./docker/egress.js";
19
19
  export { ARCHIL_HELPER, ARCHIL_SYNC_SOCKET, ARCHIL_TOOL_UID, ARCHIL_TOOL_USER, ARCHIL_VERSION, type ArchilMount, type ArchilEgress, type ArchilMountOptions, type ArchilRoot, type ProviderNote, archilEgressOf, archilLabels, archilMount, archilReadBack, archilRefusals, archilRelease, archilSync, claimEpoch, helperSha256, MOUNT_LABEL, mountDrift, mountWords, type RecordedFolder, type RecordedSource, readMount, recordedFolder, recordedMount, SYNC_LABELS, syncingClient, } from "./mount-archil.js";
20
- export { type BrowserComputerProvider, type BrowserDownloads, type BrowserFile, type BrowserProfiles, browserSpecRefusals, type BrowserStream, isBrowserProvider, BrowserVendorError, CREATE_LABEL, causeOf, memoryUrls, RECOVER_MS, type ReleaseConfirm, type RestReply, type UrlStore, } from "./browser.js";
20
+ export { type BrowserComputerProvider, type BrowserDownloads, type BrowserFile, type BrowserProfiles, type BrowserSessionUsage, browserSpecRefusals, type BrowserStream, isBrowserProvider, BrowserVendorError, CREATE_LABEL, causeOf, memoryUrls, RECOVER_MS, type ReleaseConfirm, type RestReply, type UrlStore, } from "./browser.js";
21
21
  export { CHROME_ENV, CHROME_FLAGS, checkChrome, chromeFence, findChrome, killTree, NO_CHROME } from "./chrome.js";
22
22
  export { DAEMON_IN_COMPUTER, helloDrift, type HelloExpected } from "./drift.js";
23
23
  export { drift, hostOf, inspectDrift, mountOf, networkOf, type DockerHost, type DockerInfo, type DockerInspect, type DriftExpected } from "./docker/inspect.js";
@@ -68,6 +68,11 @@ export interface HelloResult {
68
68
  display?: string;
69
69
  /** How init holds its programs off the computer's network, when it gave them one of their own (init --own-network). */
70
70
  fence?: NetworkFence;
71
+ /**
72
+ * The desktop's window manager computerd starts itself (init --window-manager), and how it goes. Absent where computerd
73
+ * starts none: a client whose host's desktops run one then starts it itself.
74
+ */
75
+ windowManager?: WindowManagerFact;
71
76
  /** The main screen, in points. Absent on a computer with no screen. */
72
77
  screen?: ScreenSize;
73
78
  /**
@@ -119,6 +124,15 @@ export type Feature = keyof typeof FEATURES;
119
124
  * no CAP_SYS_ADMIN). Either way the programs reach their own loopback alone.
120
125
  */
121
126
  export type NetworkFence = "netns" | "userns-netns";
127
+ /**
128
+ * The window manager computerd starts once the display answers: "starting" until it answers and through the manager's
129
+ * first second, "running" once the manager has run that second, "ended" when it ended or never started, with why in
130
+ * words (how it ended, when, and its last lines).
131
+ */
132
+ export interface WindowManagerFact {
133
+ state: "starting" | "running" | "ended";
134
+ why?: string;
135
+ }
122
136
  /** Every NetworkFence, as hello may report it. */
123
137
  export declare const NETWORK_FENCES: readonly NetworkFence[];
124
138
  export type PingParams = Record<string, never>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@parcha/agentrun-computer",
3
- "version": "0.1.0-beta.47",
3
+ "version": "0.1.0-beta.49",
4
4
  "description": "The open platform's computer protocol: a daemon in every computer, and one provisioner per vendor, starting with Docker.",
5
5
  "keywords": [
6
6
  "agentrun",