@parcha/agentrun-computer 0.1.0-beta.48 → 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
@@ -1897,16 +1897,11 @@ E2B's envd is the sandbox's first process, a systemd service with `Restart=alway
1897
1897
  whose start answers after the call gave up on it (its bound passed, or the caller aborted) is killed as it lands.
1898
1898
  6. A desktop's X server, `Xvfb :0 -screen 0 1280x800x24 -nolisten tcp`, starts through the daemon with
1899
1899
  `process.start`, as the computer's user, and create waits until hello declares the display (`src/desktop.ts`,
1900
- shared with Docker). Then xfwm4, which the template has, starts on it (`xfwm4 --compositor=off
1901
- --sm-client-disable`), so the apps an agent opens are framed and focused: computerd starts it itself, asked by
1902
- init's `--window-manager` (the host's facts say `windowManager`), once the display answers, and hello's
1903
- `windowManager` says it runs, which create waits on. xfwm4 reads its settings over a session bus and exits without
1904
- one. So it runs under `dbus-run-session`, as the computer's user, in a network namespace of its own that init makes
1905
- as root before it drops to that user (no user namespace is needed), and its bus listens on an abstract name there,
1906
- which a program of the computer's user cannot connect to. One that joins that namespace (nsenter) can, as the same
1907
- uid can ptrace xfwm4. xfwm4 reaches the display by its path. An older computerd, whose hello has no
1908
- `windowManager`, gets the manager through `process.start`, as before (`WINDOW_MANAGER`, under `unshare --user
1909
- --map-current-user --net`). 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
1910
1905
  accessibility bridge would start an at-spi bus, a socket of the user's at `/work/.cache/at-spi/bus_0` that nothing
1911
1906
  of ours uses. An app also gets no session bus (`DBUS_SESSION_BUS_ADDRESS=disabled:`). Given none, it would start
1912
1907
  one with the template's dbus-launch, and that bus starts gnome-keyring-daemon, a socket of the user's at
@@ -2475,6 +2470,12 @@ kind browser that declares them.
2475
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 |
2476
2471
  | `profiles { create, remove }` | `POST /v1/contexts`, `DELETE /v1/contexts/{id}` | `POST /profiles` under a random name (the pointer), `DELETE /profiles/{name}` | none |
2477
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.
2478
2479
 
2479
2480
  A pointer is a capability: whoever holds it opens the profile, so no error's words carry one.
2480
2481
 
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.48",
3
- "source": "sha256:31803ee5ab55da1b0cdb9ebcdcdda5c9373d4ae4b81eb9459a2504e1111d1966"
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
  },
@@ -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
  };
@@ -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>`. */
@@ -329,6 +331,9 @@ export interface ConformanceOptions {
329
331
  mountFor?: (kind: MountKind) => Promise<RunFolder | undefined> | RunFolder | undefined;
330
332
  /** Called as each case ends. */
331
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;
332
337
  /** Notes the provider module gives for the report, printed before the verdict. */
333
338
  notes?: string[];
334
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: a desktop on connect dial alone (kindRefusal, with DAYTONA_DIAL_DESKTOP's why).
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
@@ -8,7 +8,7 @@
8
8
  // README's Daytona section.
9
9
  import { randomBytes } from "node:crypto";
10
10
  import { connectOf, kindRefusal, mountsOf } from "./descriptor.js";
11
- import { DAYTONA, DAYTONA_DEFAULT_SNAPSHOT, DAYTONA_DIAL_DESKTOP, DAYTONA_GPU, DAYTONA_GPU_REGION, DAYTONA_GPU_SNAPSHOT, daytonaGpuSnapshot } from "./descriptors/daytona.js";
11
+ import { DAYTONA, DAYTONA_DEFAULT_SNAPSHOT, DAYTONA_GPU, DAYTONA_GPU_REGION, DAYTONA_GPU_SNAPSHOT, daytonaGpuSnapshot } from "./descriptors/daytona.js";
12
12
  import { COMPUTER_LABEL } from "./drift.js";
13
13
  import { HostError } from "./host.js";
14
14
  import { framedExec } from "./hosted/framed-exec.js";
@@ -519,7 +519,7 @@ export class DaytonaProvider extends HostedProvider {
519
519
  const via = connectOf(DAYTONA, { connect });
520
520
  const refused = kindRefusal(DAYTONA, { kind: hosted.kind, connect: via });
521
521
  if (refused !== undefined)
522
- throw new Error(hosted.kind === "desktop" ? `${refused}: ${DAYTONA_DIAL_DESKTOP}` : refused);
522
+ throw new Error(refused);
523
523
  if (typeof apiKey !== "string" || apiKey === "")
524
524
  throw new Error("options.apiKey, the Daytona API key, is required: the provider reads no environment, so the caller passes it");
525
525
  const base = new URL(apiUrl);
@@ -1,11 +1,4 @@
1
1
  import type { GpuCapability } from "../provider.js";
2
- /**
3
- * Why a Daytona desktop is made on connect dial alone: its X server and window manager come from a snapshot of
4
- * box/Dockerfile, whose sandbox boots agentrun-dial and dials the server, the path a live run proves; no desktop has run
5
- * on exec, where init is a command started through the toolbox's session. The provider's constructor refuses kind
6
- * desktop on exec in these words, after kindRefusal's.
7
- */
8
- export declare const DAYTONA_DIAL_DESKTOP = "a desktop's sandbox boots from a snapshot of box/Dockerfile and dials this server, and none has run through the toolbox's session commands, so connect \"exec\" makes kind linux";
9
2
  /** The key that turns on a Daytona computer's Archil mount: the operator's Archil egress relay (archilEgress). */
10
3
  export declare const DAYTONA_ARCHIL_EGRESS = "DAYTONA_ARCHIL_EGRESS";
11
4
  /** Why a Daytona computer made with no Archil egress takes no Archil mount: check() refuses one in these words. */
@@ -2,13 +2,6 @@
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
4
  import { LINUX_DESKTOP, SANDBOX } from "./shared.js";
5
- /**
6
- * Why a Daytona desktop is made on connect dial alone: its X server and window manager come from a snapshot of
7
- * box/Dockerfile, whose sandbox boots agentrun-dial and dials the server, the path a live run proves; no desktop has run
8
- * on exec, where init is a command started through the toolbox's session. The provider's constructor refuses kind
9
- * desktop on exec in these words, after kindRefusal's.
10
- */
11
- export const DAYTONA_DIAL_DESKTOP = "a desktop's sandbox boots from a snapshot of box/Dockerfile and dials this server, and none has run through the toolbox's session commands, so connect \"exec\" makes kind linux";
12
5
  /** The key that turns on a Daytona computer's Archil mount: the operator's Archil egress relay (archilEgress). */
13
6
  export const DAYTONA_ARCHIL_EGRESS = "DAYTONA_ARCHIL_EGRESS";
14
7
  /** Why a Daytona computer made with no Archil egress takes no Archil mount: check() refuses one in these words. */
@@ -101,7 +94,7 @@ export const DAYTONA = defineProvider({
101
94
  // X server, started through computerd over the socket the sandbox dialed, and xfwm4, which computerd starts itself
102
95
  // (init --window-manager), at the snapshot's 2 CPUs and 4 GiB (box/build-daytona.py). The desktop's configuration
103
96
  // selects dial itself, whatever daytonaConnect says: a provider on connect exec refuses kind desktop when it is made
104
- // (DAYTONA_DIAL_DESKTOP).
97
+ // (kindRefusal; the why is PROVIDERS.md's Daytona bullet).
105
98
  capabilities: [{ ...SANDBOX, gpu: DAYTONA_GPU }, { ...LINUX_DESKTOP, options: { kind: "desktop", connect: "dial" } }],
106
99
  defaultImage: { sandbox: DAYTONA_DEFAULT_SNAPSHOT },
107
100
  // The operator's own snapshot for every Daytona computer, named here; the default snapshot stands while unset. A
package/dist/desktop.d.ts CHANGED
@@ -10,36 +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, Fly's, Cloudflare's,
15
- * Modal's, Agent37's and Daytona's), once the display answers: it frames, stacks and focuses the windows apps.launch
16
- * opens. xfwm4, which the box image has, with no compositor and no session manager. It reads its settings from xfconfd
17
- * over a session bus, and exits at once without one ("Xfconf could not be initialized"). So it runs in a session bus of
18
- * its own (dbus-run-session, WINDOW_MANAGER_BUS, written to a file of its own under /tmp), in a network namespace of its
19
- * own: a program of the computer's user reaches no socket of that bus, unless it joins that namespace (nsenter), as the
20
- * same uid may ptrace xfwm4. xfwm4 reaches the display as any program does, by its path. First, xsetroot paints the
21
- * screen behind every window one slate colour, so a desktop with no window open is not a black screen a person reads as
22
- * broken; a paint that fails starts xfwm4 all the same.
23
- *
24
- * computerd starts it itself (init --window-manager), as root makes the network namespace and then becomes the
25
- * computer's user, so no user namespace is needed there: the user can make neither on some hosts (Daytona's sandboxes,
26
- * under AppArmor's restrict_unprivileged_userns). This argv is create's own start, through process.start as the
27
- * computer's user, for a computerd whose hello says nothing of one: the user makes the network namespace inside a user
28
- * namespace (the same uid) of its own.
29
- */
30
- export declare const WINDOW_MANAGER: readonly string[];
31
13
  /** The desktop options with their defaults, or a throw in words. */
32
14
  export declare function desktopOf({ display, server, timeoutMs }: DesktopOptions): Required<DesktopOptions>;
33
15
  /**
34
16
  * Starts the desktop's X server through the daemon (process.start) and waits until hello declares the display: the
35
17
  * server ending first, or the bound passing, is a failure in words, with the server's own last words, as the vendor's
36
18
  * (code vendor, vendor the provider's id). version is the client's, sent with each hello. Once the display answers, a
37
- * hello with windowManager (computerd was asked to start it) is waited on until the manager runs; else, with
38
- * windowManager (the host's desktops run one, HostFacts.windowManager), create starts WINDOW_MANAGER itself.
19
+ * hello with windowManager (computerd was asked to start it) is waited on until the manager runs.
39
20
  */
40
- 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 }: {
41
22
  version: string;
42
23
  vendor: string;
43
24
  signal?: AbortSignal | undefined;
44
- windowManager?: boolean;
45
25
  }): Promise<Result<void>>;
package/dist/desktop.js CHANGED
@@ -2,67 +2,17 @@
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
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; hello's windowManager says how it goes), and create starts
6
- // it the same way as the server, through process.start, for a computerd that says nothing of one.
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
7
  // Docker's desktops, E2B's, Agent37's and Daytona's start the display this way.
8
8
  import { setTimeout as sleep } from "node:timers/promises";
9
9
  import { fail, ok, vendorFail } from "./result.js";
10
10
  /** The groups a desktop declares besides exec, files and processes: apps is computerd's, from the desktop's .desktop files. */
11
11
  export const DESKTOP_GROUPS = ["screen", "input.pointer", "input.keys", "apps"];
12
- /**
13
- * The session bus the window manager reads its settings over: dbus's own session config, but listening on an abstract
14
- * name, which only a program in the bus's own network namespace reaches. dbus's unix:tmpdir is a socket under /tmp
15
- * with dbus 1.16 (Agent37's box), which every program of the user reaches.
16
- */
17
- const WINDOW_MANAGER_BUS = `<busconfig>
18
- <type>session</type>
19
- <keep_umask/>
20
- <listen>unix:abstract=/agentrun/window-manager</listen>
21
- <auth>EXTERNAL</auth>
22
- <standard_session_servicedirs/>
23
- <policy context="default">
24
- <allow send_destination="*" eavesdrop="true"/>
25
- <allow eavesdrop="true"/>
26
- <allow own="*"/>
27
- </policy>
28
- </busconfig>`;
29
- /**
30
- * The window manager a host's desktops run where its facts say so (HostFacts.windowManager: E2B's, Fly's, Cloudflare's,
31
- * Modal's, Agent37's and Daytona's), once the display answers: it frames, stacks and focuses the windows apps.launch
32
- * opens. xfwm4, which the box image has, with no compositor and no session manager. It reads its settings from xfconfd
33
- * over a session bus, and exits at once without one ("Xfconf could not be initialized"). So it runs in a session bus of
34
- * its own (dbus-run-session, WINDOW_MANAGER_BUS, written to a file of its own under /tmp), in a network namespace of its
35
- * own: a program of the computer's user reaches no socket of that bus, unless it joins that namespace (nsenter), as the
36
- * same uid may ptrace xfwm4. xfwm4 reaches the display as any program does, by its path. First, xsetroot paints the
37
- * screen behind every window one slate colour, so a desktop with no window open is not a black screen a person reads as
38
- * broken; a paint that fails starts xfwm4 all the same.
39
- *
40
- * computerd starts it itself (init --window-manager), as root makes the network namespace and then becomes the
41
- * computer's user, so no user namespace is needed there: the user can make neither on some hosts (Daytona's sandboxes,
42
- * under AppArmor's restrict_unprivileged_userns). This argv is create's own start, through process.start as the
43
- * computer's user, for a computerd whose hello says nothing of one: the user makes the network namespace inside a user
44
- * namespace (the same uid) of its own.
45
- */
46
- export const WINDOW_MANAGER = [
47
- "unshare",
48
- "--user",
49
- "--map-current-user",
50
- "--net",
51
- "--",
52
- "sh",
53
- "-c",
54
- 'xsetroot -solid "#3b4b5c"; bus=$(mktemp) && printf "%s" "$1" > "$bus" && exec dbus-run-session --config-file="$bus" -- xfwm4 --compositor=off --sm-client-disable',
55
- "sh",
56
- WINDOW_MANAGER_BUS,
57
- ];
58
- /** WINDOW_MANAGER as create's errors name it: what runs, without the shell line and the bus's config. */
59
- const WINDOW_MANAGER_WORDS = "unshare --user --map-current-user --net -- dbus-run-session -- xfwm4 --compositor=off --sm-client-disable";
60
12
  const DISPLAY = /^:\d{1,5}(\.\d{1,5})?$/;
61
13
  /** How often create asks the daemon whether the display is up yet. */
62
14
  const DISPLAY_POLL_MS = 100;
63
- /** How long create watches a window manager it started: one that ends within it (it could not take the display) fails create. */
64
- const WM_SETTLE_MS = 1_000;
65
- /** 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. */
66
16
  const WM_BOUND_MS = 15_000;
67
17
  /** The longest a Node timer or AbortSignal.timeout holds. */
68
18
  const MAX_TIMER_MS = 2 ** 31 - 1;
@@ -85,10 +35,9 @@ export function desktopOf({ display = ":0", server, timeoutMs = 30_000 }) {
85
35
  * Starts the desktop's X server through the daemon (process.start) and waits until hello declares the display: the
86
36
  * server ending first, or the bound passing, is a failure in words, with the server's own last words, as the vendor's
87
37
  * (code vendor, vendor the provider's id). version is the client's, sent with each hello. Once the display answers, a
88
- * hello with windowManager (computerd was asked to start it) is waited on until the manager runs; else, with
89
- * windowManager (the host's desktops run one, HostFacts.windowManager), create starts WINDOW_MANAGER itself.
38
+ * hello with windowManager (computerd was asked to start it) is waited on until the manager runs.
90
39
  */
91
- export async function startDisplay(client, desktop, { version, vendor, signal, windowManager = false }) {
40
+ export async function startDisplay(client, desktop, { version, vendor, signal }) {
92
41
  const server = desktop.server.join(" ");
93
42
  // Every call takes a signal that ends at the bound, so a hello the X connection setup holds, or a daemon that stops
94
43
  // answering, cannot outwait it. A call that failed because the bound passed is the timeout; the caller's own abort
@@ -106,9 +55,7 @@ export async function startDisplay(client, desktop, { version, vendor, signal, w
106
55
  if (!hello.ok)
107
56
  return timedOut() ? late() : hello;
108
57
  if (Array.isArray(hello.value.groups) && hello.value.groups.includes("screen")) {
109
- if (hello.value.windowManager)
110
- return await awaitWindowManager(client, desktop, { version, vendor, caller: signal });
111
- return windowManager ? await startWindowManager(client, desktop, vendor, signal) : ok(undefined);
58
+ return hello.value.windowManager ? await awaitWindowManager(client, desktop, { version, vendor, caller: signal }) : ok(undefined);
112
59
  }
113
60
  const waited = await client.call("process.wait", { id, timeoutMs: 0 }, { signal: either });
114
61
  if (waited.ok && !waited.value.running) {
@@ -128,8 +75,8 @@ export async function startDisplay(client, desktop, { version, vendor, signal, w
128
75
  }
129
76
  /**
130
77
  * Waits on the window manager computerd starts itself (hello's windowManager, init --window-manager) until hello says it
131
- * runs: one that ended fails create in computerd's words, its last lines among them. The bound is WM_BOUND_MS, as for a
132
- * manager create starts. The caller's abort still ends 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.
133
80
  */
134
81
  async function awaitWindowManager(client, desktop, { version, vendor, caller }) {
135
82
  const bound = AbortSignal.timeout(WM_BOUND_MS);
@@ -151,36 +98,3 @@ async function awaitWindowManager(client, desktop, { version, vendor, caller })
151
98
  return stopped();
152
99
  }
153
100
  }
154
- /**
155
- * Starts WINDOW_MANAGER on the display that answers, for a computerd that starts none (its hello has no
156
- * windowManager). A manager that cannot start, or ends
157
- * within WM_SETTLE_MS (xfwm4 with no session bus, or no display it may open), fails create with its last words. It has
158
- * 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
159
- * full second. The caller's abort still ends it.
160
- */
161
- async function startWindowManager(client, desktop, vendor, caller) {
162
- const manager = WINDOW_MANAGER_WORDS;
163
- const bound = AbortSignal.timeout(WM_BOUND_MS);
164
- const signal = caller ? AbortSignal.any([caller, bound]) : bound;
165
- const stopped = (code, message) => caller?.aborted
166
- ? fail("aborted", "create was aborted while the window manager started")
167
- : bound.aborted
168
- ? fail("timeout", `the window manager (${manager}) did not start on ${desktop.display} within ${WM_BOUND_MS / 1000} s`)
169
- : fail(code, message);
170
- // NO_AT_BRIDGE: GTK (xfwm4's toolkit) asks its session bus for no accessibility bus. On E2B Desktop, which has
171
- // 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).
172
- const env = { DISPLAY: desktop.display, NO_AT_BRIDGE: "1" };
173
- const started = await client.call("process.start", { argv: [...WINDOW_MANAGER], env }, { signal });
174
- if (!started.ok)
175
- return stopped(started.error.code, `the window manager (${manager}) did not start on ${desktop.display}: ${started.error.message}`);
176
- const { id } = started.value;
177
- const waited = await client.call("process.wait", { id, timeoutMs: WM_SETTLE_MS }, { signal });
178
- if (!waited.ok)
179
- return stopped(waited.error.code, `the window manager (${manager}) could not be waited on: ${waited.error.message}`);
180
- if (waited.value.running)
181
- return ok(undefined);
182
- const read = await client.call("process.read", { id, stream: "stderr", offset: 0 }, { signal });
183
- const words = read.ok ? Buffer.from(read.value.data, "base64").toString("utf8").trim().split("\n").slice(-5).join("; ") : "";
184
- const how = waited.value.signal ? `signal ${waited.value.signal}` : `exit code ${waited.value.exitCode}`;
185
- return vendorFail(vendor, `the window manager (${manager}) ended with ${how} within ${WM_SETTLE_MS / 1000} s of starting on ${desktop.display}${words ? `: ${words}` : ""}`);
186
- }
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">;
@@ -1002,7 +1002,7 @@ export class HostedProvider {
1002
1002
  async #checkInside(connection, name, network, starting, want, signal, folder) {
1003
1003
  let current = connection;
1004
1004
  if (starting && this.#desktop) {
1005
- 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 });
1006
1006
  if (!shown.ok)
1007
1007
  return shown;
1008
1008
  const hello = await connection.client.call("hello", { client: `@parcha/agentrun-computer ${VERSION}` }, { signal: bounded(this.#timeouts.helloMs, signal) });
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";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@parcha/agentrun-computer",
3
- "version": "0.1.0-beta.48",
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",