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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (148) hide show
  1. package/NOTICE +2 -0
  2. package/README.md +423 -323
  3. package/box/Dockerfile +3 -1
  4. package/box/agentrun-archil +59 -7
  5. package/box/build-agent37.mjs +177 -0
  6. package/box/build-daytona.py +20 -4
  7. package/dist/agent37.d.ts +165 -0
  8. package/dist/agent37.js +759 -0
  9. package/dist/attach.d.ts +146 -0
  10. package/dist/attach.js +469 -0
  11. package/dist/browser.d.ts +61 -10
  12. package/dist/browser.js +125 -3
  13. package/dist/browserbase.d.ts +46 -23
  14. package/dist/browserbase.js +162 -17
  15. package/dist/chrome.d.ts +3 -4
  16. package/dist/chrome.js +6 -11
  17. package/dist/client.d.ts +33 -1
  18. package/dist/client.js +53 -0
  19. package/dist/computerd-linux-amd64 +0 -0
  20. package/dist/computerd-linux-arm64 +0 -0
  21. package/dist/conformance/agent37.d.ts +96 -0
  22. package/dist/conformance/agent37.js +154 -0
  23. package/dist/conformance/cases/apps.d.ts +5 -0
  24. package/dist/conformance/cases/apps.js +160 -73
  25. package/dist/conformance/cases/health.js +14 -0
  26. package/dist/conformance/cases/index.js +2 -0
  27. package/dist/conformance/cases/provider.js +27 -1
  28. package/dist/conformance/cases/screen.d.ts +3 -0
  29. package/dist/conformance/cases/screen.js +18 -0
  30. package/dist/conformance/cases/settings.d.ts +29 -23
  31. package/dist/conformance/cases/settings.js +76 -58
  32. package/dist/conformance/cases/touch.js +19 -17
  33. package/dist/conformance/cases/ui.d.ts +2 -0
  34. package/dist/conformance/cases/ui.js +475 -0
  35. package/dist/conformance/cli.d.ts +9 -0
  36. package/dist/conformance/cli.js +28 -3
  37. package/dist/conformance/daytona.d.ts +4 -0
  38. package/dist/conformance/daytona.js +5 -0
  39. package/dist/conformance/e2b.d.ts +6 -0
  40. package/dist/conformance/e2b.js +9 -2
  41. package/dist/conformance/fixture.d.ts +1 -1
  42. package/dist/conformance/fixture.js +25 -1
  43. package/dist/conformance/modal.d.ts +17 -13
  44. package/dist/conformance/modal.js +18 -9
  45. package/dist/conformance/orgo.d.ts +3 -3
  46. package/dist/conformance/orgo.js +6 -8
  47. package/dist/conformance/phone-harness.d.ts +6 -2
  48. package/dist/conformance/phone-harness.js +21 -4
  49. package/dist/conformance/report.js +1 -1
  50. package/dist/conformance/runner.js +23 -4
  51. package/dist/conformance/sweep.d.ts +50 -0
  52. package/dist/conformance/sweep.js +187 -0
  53. package/dist/conformance/types.d.ts +11 -3
  54. package/dist/conformance/ui-fixture.d.ts +56 -0
  55. package/dist/conformance/ui-fixture.js +43 -0
  56. package/dist/create-requests.d.ts +51 -0
  57. package/dist/create-requests.js +121 -0
  58. package/dist/daytona.d.ts +15 -5
  59. package/dist/daytona.js +58 -38
  60. package/dist/descriptor.d.ts +29 -2
  61. package/dist/descriptor.js +13 -0
  62. package/dist/descriptors/agent37.d.ts +41 -0
  63. package/dist/descriptors/agent37.js +28 -0
  64. package/dist/descriptors/browserbase.d.ts +1 -0
  65. package/dist/descriptors/browserbase.js +2 -0
  66. package/dist/descriptors/daytona.d.ts +23 -2
  67. package/dist/descriptors/daytona.js +34 -2
  68. package/dist/descriptors/index.d.ts +66 -3
  69. package/dist/descriptors/index.js +5 -3
  70. package/dist/descriptors/kernel.d.ts +1 -0
  71. package/dist/descriptors/kernel.js +2 -0
  72. package/dist/descriptors/modal.d.ts +4 -0
  73. package/dist/descriptors/modal.js +11 -1
  74. package/dist/descriptors/orgo.d.ts +13 -1
  75. package/dist/descriptors/orgo.js +9 -3
  76. package/dist/descriptors/phone-harness.d.ts +6 -1
  77. package/dist/descriptors/phone-harness.js +5 -2
  78. package/dist/docker/egress.d.ts +4 -3
  79. package/dist/docker/egress.js +7 -6
  80. package/dist/docker.d.ts +7 -4
  81. package/dist/docker.js +278 -34
  82. package/dist/e2b.d.ts +9 -165
  83. package/dist/e2b.js +282 -1342
  84. package/dist/fake-ui-driver.d.ts +97 -0
  85. package/dist/fake-ui-driver.js +717 -0
  86. package/dist/host.d.ts +182 -0
  87. package/dist/host.js +1 -0
  88. package/dist/hosted/process.d.ts +67 -0
  89. package/dist/hosted/process.js +228 -0
  90. package/dist/hosted/provider.d.ts +146 -0
  91. package/dist/hosted/provider.js +1364 -0
  92. package/dist/hosted/scripts.d.ts +76 -0
  93. package/dist/{child.js → hosted/scripts.js} +93 -12
  94. package/dist/index.d.ts +11 -7
  95. package/dist/index.js +10 -7
  96. package/dist/janitor.d.ts +5 -4
  97. package/dist/janitor.js +1 -1
  98. package/dist/kernel.d.ts +17 -27
  99. package/dist/kernel.js +94 -18
  100. package/dist/kinds.d.ts +17 -5
  101. package/dist/kinds.js +20 -4
  102. package/dist/labels.d.ts +10 -2
  103. package/dist/labels.js +30 -7
  104. package/dist/local-chrome.d.ts +5 -5
  105. package/dist/local-chrome.js +10 -5
  106. package/dist/modal.d.ts +23 -181
  107. package/dist/modal.js +273 -1232
  108. package/dist/mount-archil.d.ts +25 -3
  109. package/dist/mount-archil.js +39 -8
  110. package/dist/orgo-channel.d.ts +3 -2
  111. package/dist/orgo-channel.js +5 -2
  112. package/dist/orgo-desktop.d.ts +23 -9
  113. package/dist/orgo-desktop.js +328 -66
  114. package/dist/orgo-names.d.ts +129 -3
  115. package/dist/orgo-names.js +211 -8
  116. package/dist/orgo-workspaces.d.ts +47 -0
  117. package/dist/orgo-workspaces.js +94 -0
  118. package/dist/orgo.d.ts +27 -10
  119. package/dist/orgo.js +411 -81
  120. package/dist/phone-harness.d.ts +31 -21
  121. package/dist/phone-harness.js +510 -681
  122. package/dist/png.d.ts +4 -0
  123. package/dist/png.js +27 -0
  124. package/dist/protocol.d.ts +338 -30
  125. package/dist/protocol.js +96 -3
  126. package/dist/provider.d.ts +97 -7
  127. package/dist/provider.js +24 -3
  128. package/dist/result.d.ts +1 -1
  129. package/dist/surface/api.d.ts +248 -0
  130. package/dist/surface/api.js +1 -0
  131. package/dist/surface/core.d.ts +42 -0
  132. package/dist/surface/core.js +393 -0
  133. package/dist/surface/index.d.ts +5 -0
  134. package/dist/surface/index.js +3 -0
  135. package/dist/surface/outline.d.ts +8 -0
  136. package/dist/surface/outline.js +50 -0
  137. package/dist/surface/script.d.ts +10 -0
  138. package/dist/surface/script.js +92 -0
  139. package/dist/ui-engine.d.ts +114 -0
  140. package/dist/ui-engine.js +798 -0
  141. package/package.json +17 -1
  142. package/dist/child.d.ts +0 -42
  143. package/dist/conformance/e2b-diagnose.d.ts +0 -16
  144. package/dist/conformance/e2b-diagnose.js +0 -61
  145. package/dist/conformance/e2b-sweep.d.ts +0 -18
  146. package/dist/conformance/e2b-sweep.js +0 -132
  147. package/dist/conformance/modal-sweep.d.ts +0 -22
  148. package/dist/conformance/modal-sweep.js +0 -213
@@ -4,6 +4,8 @@
4
4
  // Android it is a small APK that logs touches and its own launch to its files directory and shows a button with a fixed
5
5
  // id. This file is their contract: the binary and the APK come with the PRs that first run them. On a Windows desktop it
6
6
  // is a PowerShell script this package carries (windows-fixture.ts), the same window, started detached with Start-Process.
7
+ // On a Mac it is UIFixture.app (daemon-macos) started with --input-log: the same quadrants at the display's top left,
8
+ // whose ready line gives its bounds in pixels.
7
9
  import { readFileSync } from "node:fs";
8
10
  import { readFile, writeFile } from "../files.js";
9
11
  import { WINDOWS_FIXTURE } from "./windows-fixture.js";
@@ -18,7 +20,7 @@ export const FIXTURE_COLORS = [
18
20
  ];
19
21
  /** The fixture APK's application id. */
20
22
  export const FIXTURE_APP_ID = "ai.agentrun.fixture";
21
- /** The APK's button, found in apps.ui_tree by its id. */
23
+ /** The APK's button, found in ui.observe by its id, its name the button's text. */
22
24
  export const FIXTURE_BUTTON = { id: `${FIXTURE_APP_ID}:id/button`, text: "agentrun fixture" };
23
25
  /** Where the APK is written on a phone before apps.install. */
24
26
  export const FIXTURE_APK_PATH = "/data/local/tmp/agentrun-fixture.apk";
@@ -82,6 +84,28 @@ export async function startFixture(t, path, launched) {
82
84
  await ready(t, events, "the Windows desktop fixture");
83
85
  return { bounds: FIXTURE_WINDOW, events, stop };
84
86
  }
87
+ if (kind === "desktop" && os === "macos") {
88
+ // A Mac's fixture is UIFixture.app already on it (path is the app), started by open with --input-log, so it
89
+ // comes to the front as an app does. Its ready line names its pid and its window in screenshot pixels: the
90
+ // window sits at the display's top left, its size in pixels the display's scale times 200 points.
91
+ needs(t, ["exec", "files"], "the macOS desktop fixture");
92
+ const log = `${await t.dir()}/events.jsonl`;
93
+ const started = await t.exec(["/usr/bin/open", "-n", "-a", path, "--args", "--input-log", log]);
94
+ t.equal(started.exitCode, 0, `open of the fixture ${path} (stderr ${JSON.stringify(started.err.trim())})`);
95
+ const events = () => logOf(t, log);
96
+ const readyLine = async () => (await events().catch(() => [])).find((e) => e.event === "ready");
97
+ const stop = async () => {
98
+ const pid = (await readyLine())?.pid;
99
+ if (Number.isSafeInteger(pid))
100
+ await t.client.call("exec.run", { argv: ["/bin/kill", String(pid)], timeoutMs: 30_000 });
101
+ };
102
+ launched(stop);
103
+ await ready(t, events, "the macOS desktop fixture");
104
+ const bounds = (await readyLine())?.bounds;
105
+ const isRect = Array.isArray(bounds) && bounds.length === 4 && bounds.every((n) => Number.isSafeInteger(n));
106
+ t.assert(isRect, `the macOS fixture's ready line gives its bounds as [x, y, w, h], not ${JSON.stringify(bounds)}`);
107
+ return { bounds: bounds, events, stop };
108
+ }
85
109
  if (kind === "desktop") {
86
110
  needs(t, ["exec", "files", "processes"], "the desktop fixture");
87
111
  const dir = await t.dir();
@@ -1,7 +1,7 @@
1
+ import type { MachineHost } from "../host.js";
2
+ import { type ModalClientConstructor, type ModalCreateOptions, type ModalProvider } from "../modal.js";
1
3
  import type { MountKind } from "../mount.js";
2
4
  import type { ProviderNote } from "../mount-archil.js";
3
- import type { ComputerProvider } from "../provider.js";
4
- import { type ModalClientConstructor, type ModalCreateOptions } from "../modal.js";
5
5
  import { type ArchilRunFolderOptions } from "./archil.js";
6
6
  import type { RunFolder } from "./types.js";
7
7
  /** The Archil disk's settings for the mount cases, by name (COMPUTER_ARCHIL_*: all five, or none). */
@@ -14,8 +14,6 @@ export declare const MODAL_ENV: {
14
14
  readonly tokenSecret: "COMPUTER_MODAL_TOKEN_SECRET";
15
15
  /** app, required: the Modal App the run's sandboxes live in, made when missing. */
16
16
  readonly app: "COMPUTER_MODAL_APP";
17
- /** daemonImage: an image holding the daemon, pinned by digest, to COPY --from instead of uploading it. */
18
- readonly daemonImage: "COMPUTER_MODAL_DAEMON_IMAGE";
19
17
  /** serverUrl: the server the token goes to; the SDK's default when unset. */
20
18
  readonly serverUrl: "COMPUTER_MODAL_SERVER_URL";
21
19
  };
@@ -27,13 +25,11 @@ export declare const ENV: {
27
25
  readonly tokenSecret: "COMPUTER_MODAL_TOKEN_SECRET";
28
26
  /** app, required: the Modal App the run's sandboxes live in, made when missing. */
29
27
  readonly app: "COMPUTER_MODAL_APP";
30
- /** daemonImage: an image holding the daemon, pinned by digest, to COPY --from instead of uploading it. */
31
- readonly daemonImage: "COMPUTER_MODAL_DAEMON_IMAGE";
32
28
  /** serverUrl: the server the token goes to; the SDK's default when unset. */
33
29
  readonly serverUrl: "COMPUTER_MODAL_SERVER_URL";
34
30
  };
35
- /** What this module reads from the environment: the token, the app, and the server and daemon image when set. */
36
- export type ModalSettings = Pick<ModalCreateOptions, "tokenId" | "tokenSecret" | "app" | "serverUrl" | "daemonImage">;
31
+ /** What this module reads from the environment: the token, the app, and the server when set. */
32
+ export type ModalSettings = Pick<ModalCreateOptions, "tokenId" | "tokenSecret" | "app" | "serverUrl">;
37
33
  /**
38
34
  * The provider's options this module reads from env; throws in words without the token or the app, or while
39
35
  * MODAL_SERVER_URL is set there (the SDK would send the token to it), never echoing a token.
@@ -46,7 +42,7 @@ export interface ModalModuleOptions {
46
42
  env?: Record<string, string | undefined>;
47
43
  /** The SDK's ModalClient; imported from the host's modal package by default. */
48
44
  ModalClient?: ModalClientConstructor;
49
- /** The daemon to upload, when COMPUTER_MODAL_DAEMON_IMAGE names no image; default this package's dist/computerd-linux-amd64. */
45
+ /** The daemon to upload; default this package's dist/computerd-linux-amd64. */
50
46
  daemonPath?: string;
51
47
  /** Builds this package's daemon for linux/amd64 stamped with version, and gives its path; default go build. */
52
48
  buildDaemon?: (version: string) => Promise<string>;
@@ -55,7 +51,8 @@ export interface ModalModuleOptions {
55
51
  /** What the provider says that is no failure: the CLI gives it and puts it in the report. */
56
52
  onNote?: ProviderNote;
57
53
  }
58
- export declare function createProvider({ env, ModalClient, daemonPath, onNote }?: ModalModuleOptions): Promise<ComputerProvider>;
54
+ /** The provider the CLI runs; throws in words without the live switch, or when a setting is missing or wrong. */
55
+ export declare function createProvider({ env, ModalClient, daemonPath, onNote }?: ModalModuleOptions): Promise<ModalProvider>;
59
56
  /**
60
57
  * A run folder for an Archil mount, and none for any other kind (a Modal computer takes no bind): a fresh folder on the
61
58
  * disk the COMPUTER_ARCHIL_* names name (archilSettings), none when they name none (archilRunFolder, ./archil.ts).
@@ -63,7 +60,14 @@ export declare function createProvider({ env, ModalClient, daemonPath, onNote }?
63
60
  */
64
61
  export declare function mountFor(kind: MountKind, { env, archil }?: ModalModuleOptions): Promise<RunFolder | undefined>;
65
62
  /**
66
- * The same provider uploading a daemon that reports version <version>-drift, for the drift.version case, whatever image
67
- * COMPUTER_MODAL_DAEMON_IMAGE names.
63
+ * The Modal host the live sweep (sweep.ts) lists and deletes through, from the same settings; it needs no live switch,
64
+ * since the sweep makes nothing, and it calls nothing until the sweep does.
68
65
  */
69
- export declare function createDriftedProvider({ env, ModalClient, buildDaemon }?: ModalModuleOptions): Promise<ComputerProvider>;
66
+ export declare function createHost({ env, ModalClient }?: Pick<ModalModuleOptions, "env" | "ModalClient">): Promise<MachineHost>;
67
+ /**
68
+ * Where the sweep lists, in words: the app and the server the settings name. A before file of another app, or of the
69
+ * same app name on another server, would make every computer there read as new, so the sweep refuses it.
70
+ */
71
+ export declare function sweepScope({ env }?: Pick<ModalModuleOptions, "env">): string;
72
+ /** The same provider uploading a daemon that reports version <version>-drift, for the drift.version case. */
73
+ export declare function createDriftedProvider({ env, ModalClient, buildDaemon }?: ModalModuleOptions): Promise<ModalProvider>;
@@ -1,4 +1,4 @@
1
- import { create } from "../modal.js";
1
+ import { create, MODAL_DEFAULT_SERVER_URL } from "../modal.js";
2
2
  import { archilRunFolder, archilSettings } from "./archil.js";
3
3
  import { buildDriftDaemon, DRIFT_VERSION } from "./drift-daemon.js";
4
4
  /** The Archil disk's settings for the mount cases, by name (COMPUTER_ARCHIL_*: all five, or none). */
@@ -11,8 +11,6 @@ export const MODAL_ENV = {
11
11
  tokenSecret: "COMPUTER_MODAL_TOKEN_SECRET",
12
12
  /** app, required: the Modal App the run's sandboxes live in, made when missing. */
13
13
  app: "COMPUTER_MODAL_APP",
14
- /** daemonImage: an image holding the daemon, pinned by digest, to COPY --from instead of uploading it. */
15
- daemonImage: "COMPUTER_MODAL_DAEMON_IMAGE",
16
14
  /** serverUrl: the server the token goes to; the SDK's default when unset. */
17
15
  serverUrl: "COMPUTER_MODAL_SERVER_URL",
18
16
  };
@@ -35,8 +33,7 @@ export function settingsFromEnv(env = process.env) {
35
33
  if (!app)
36
34
  throw new Error(`the Modal conformance module needs ${MODAL_ENV.app}: the app the run's sandboxes live in`);
37
35
  const serverUrl = env[MODAL_ENV.serverUrl];
38
- const daemonImage = env[MODAL_ENV.daemonImage];
39
- return { tokenId, tokenSecret, app, ...(serverUrl ? { serverUrl } : {}), ...(daemonImage ? { daemonImage } : {}) };
36
+ return { tokenId, tokenSecret, app, ...(serverUrl ? { serverUrl } : {}) };
40
37
  }
41
38
  /** The longest lifetime a computer of a run may ask for: Modal ends each sandbox at its timeout, the lifetime. */
42
39
  export const CONFORMANCE_MAX_LIFETIME_MS = 30 * 60_000;
@@ -45,9 +42,9 @@ function live(env) {
45
42
  throw new Error(`the Modal conformance module makes real sandboxes: set ${MODAL_ENV.live}=1, with a key the lead has OKed, to run it`);
46
43
  }
47
44
  }
45
+ /** The provider the CLI runs; throws in words without the live switch, or when a setting is missing or wrong. */
48
46
  export async function createProvider({ env = process.env, ModalClient, daemonPath, onNote } = {}) {
49
47
  live(env);
50
- // Given COMPUTER_MODAL_DAEMON_IMAGE and a daemonPath, create() takes the image.
51
48
  return create({ ...settingsFromEnv(env), ...(daemonPath === undefined ? {} : { daemonPath }), ...(ModalClient ? { ModalClient } : {}), ...(onNote ? { onNote } : {}), maxLifetimeMs: CONFORMANCE_MAX_LIFETIME_MS });
52
49
  }
53
50
  /**
@@ -65,12 +62,24 @@ export async function mountFor(kind, { env = process.env, archil = {} } = {}) {
65
62
  return archilRunFolder({ ...settings, ...archil });
66
63
  }
67
64
  /**
68
- * The same provider uploading a daemon that reports version <version>-drift, for the drift.version case, whatever image
69
- * COMPUTER_MODAL_DAEMON_IMAGE names.
65
+ * The Modal host the live sweep (sweep.ts) lists and deletes through, from the same settings; it needs no live switch,
66
+ * since the sweep makes nothing, and it calls nothing until the sweep does.
70
67
  */
68
+ export async function createHost({ env = process.env, ModalClient } = {}) {
69
+ return (await create({ ...settingsFromEnv(env), ...(ModalClient ? { ModalClient } : {}) })).host;
70
+ }
71
+ /**
72
+ * Where the sweep lists, in words: the app and the server the settings name. A before file of another app, or of the
73
+ * same app name on another server, would make every computer there read as new, so the sweep refuses it.
74
+ */
75
+ export function sweepScope({ env = process.env } = {}) {
76
+ const { app, serverUrl = MODAL_DEFAULT_SERVER_URL } = settingsFromEnv(env);
77
+ return `the app ${app} on ${serverUrl}`;
78
+ }
79
+ /** The same provider uploading a daemon that reports version <version>-drift, for the drift.version case. */
71
80
  export async function createDriftedProvider({ env = process.env, ModalClient, buildDaemon = (version) => buildDriftDaemon("amd64", version) } = {}) {
72
81
  live(env);
73
- const { daemonImage: _image, ...settings } = settingsFromEnv(env);
82
+ const settings = settingsFromEnv(env);
74
83
  const daemonPath = await buildDaemon(DRIFT_VERSION);
75
84
  return create({ ...settings, daemonPath, ...(ModalClient ? { ModalClient } : {}), maxLifetimeMs: CONFORMANCE_MAX_LIFETIME_MS });
76
85
  }
@@ -7,7 +7,7 @@ export declare const ENV: {
7
7
  readonly template: "COMPUTER_ORGO_TEMPLATE";
8
8
  /** Required: an Orgo API key (never ORGO_API_KEY, which a host may hold for another account). */
9
9
  readonly key: "COMPUTER_ORGO_API_KEY";
10
- /** Required: the workspace the run's computers live in. */
10
+ /** The workspace the run's computers live in; default the key's account's one workspace (several are refused in words). */
11
11
  readonly workspace: "COMPUTER_ORGO_WORKSPACE";
12
12
  /** Orgo's API; default https://www.orgo.ai/api. */
13
13
  readonly apiUrl: "COMPUTER_ORGO_API_URL";
@@ -30,10 +30,10 @@ export interface OrgoModuleOptions {
30
30
  /** Builds this package's daemon for linux/amd64 stamped with version, and gives its path; default go build. */
31
31
  buildDaemon?: (version: string) => Promise<string>;
32
32
  }
33
- /** The provider's settings from COMPUTER_ORGO_* alone: the key, the workspace, and Orgo's API when named. No word holds the key. */
33
+ /** The provider's settings from COMPUTER_ORGO_* alone: the key, and the workspace and Orgo's API when named. No word holds the key. */
34
34
  export declare function settingsFromEnv(env?: Record<string, string | undefined>): {
35
35
  apiKey: string;
36
- workspaceId: string;
36
+ workspaceId?: string;
37
37
  apiUrl?: string;
38
38
  };
39
39
  /** The image every computer of the run starts from: "windows" or "macos" for those desktops; else COMPUTER_ORGO_TEMPLATE, or Orgo's base desktop. */
@@ -1,7 +1,7 @@
1
1
  // Orgo for the conformance CLI: `npm run conformance -w @parcha/agentrun-computer -- --provider orgo [--image <template>]`.
2
2
  // It makes real Orgo desktops, so it runs only with AGENTRUN_COMPUTER_LIVE_ORGO=1 and a key the lead has OKed, under
3
- // COMPUTER_ORGO_API_KEY (never ORGO_API_KEY), in the workspace COMPUTER_ORGO_WORKSPACE names. The live switch is checked
4
- // first, before any other setting is read.
3
+ // COMPUTER_ORGO_API_KEY (never ORGO_API_KEY), in the workspace COMPUTER_ORGO_WORKSPACE names, or the key's account's one
4
+ // workspace when it names none. The live switch is checked first, before any other setting is read.
5
5
  //
6
6
  // COMPUTER_ORGO_OS picks the desktop: linux (the default), windows or macos. On Linux the daemon is uploaded into each
7
7
  // computer (dist/computerd-linux-amd64, `npm run build:daemon`); the drifted provider uploads one built with Go as
@@ -19,7 +19,7 @@ export const ENV = {
19
19
  template: "COMPUTER_ORGO_TEMPLATE",
20
20
  /** Required: an Orgo API key (never ORGO_API_KEY, which a host may hold for another account). */
21
21
  key: "COMPUTER_ORGO_API_KEY",
22
- /** Required: the workspace the run's computers live in. */
22
+ /** The workspace the run's computers live in; default the key's account's one workspace (several are refused in words). */
23
23
  workspace: "COMPUTER_ORGO_WORKSPACE",
24
24
  /** Orgo's API; default https://www.orgo.ai/api. */
25
25
  apiUrl: "COMPUTER_ORGO_API_URL",
@@ -46,16 +46,14 @@ function osOf(env) {
46
46
  throw new Error(`${ORGO_ENV.os} is linux, windows or macos, not ${JSON.stringify(os)}`);
47
47
  return os;
48
48
  }
49
- /** The provider's settings from COMPUTER_ORGO_* alone: the key, the workspace, and Orgo's API when named. No word holds the key. */
49
+ /** The provider's settings from COMPUTER_ORGO_* alone: the key, and the workspace and Orgo's API when named. No word holds the key. */
50
50
  export function settingsFromEnv(env = process.env) {
51
51
  const apiKey = env[ORGO_ENV.key];
52
52
  if (!apiKey)
53
53
  throw new Error(`set ${ORGO_ENV.key} to an Orgo API key: the Orgo module reads it there and nowhere else, never from ORGO_API_KEY`);
54
- const workspaceId = env[ORGO_ENV.workspace];
55
- if (!workspaceId)
56
- throw new Error(`set ${ORGO_ENV.workspace} to the Orgo workspace the run's computers live in`);
54
+ const workspaceId = env[ORGO_ENV.workspace] || undefined;
57
55
  const apiUrl = env[ORGO_ENV.apiUrl] || undefined;
58
- return { apiKey, workspaceId, ...(apiUrl ? { apiUrl } : {}) };
56
+ return { apiKey, ...(workspaceId ? { workspaceId } : {}), ...(apiUrl ? { apiUrl } : {}) };
59
57
  }
60
58
  /** The image every computer of the run starts from: "windows" or "macos" for those desktops; else COMPUTER_ORGO_TEMPLATE, or Orgo's base desktop. */
61
59
  export function conformanceImage({ env = process.env } = {}) {
@@ -46,15 +46,19 @@ export declare function settingsFromEnv(env?: Record<string, string | undefined>
46
46
  export declare function fileLedger(path: string, { waitMs }?: {
47
47
  waitMs?: number;
48
48
  }): PhoneLedger;
49
- export interface PhoneModuleOptions extends Pick<PhoneProviderOptions, "fetch" | "now" | "sleep" | "baseUrl"> {
49
+ /** The ui fixture as an Android app (npm run build:ui-fixture), beside the compiled modules: a run installs it on its phones. */
50
+ export declare const UI_FIXTURE_APK: string;
51
+ export interface PhoneModuleOptions extends Pick<PhoneProviderOptions, "fetch" | "now" | "sleep" | "baseUrl" | "phoned"> {
50
52
  /** Where the settings are read; default process.env. */
51
53
  env?: Record<string, string | undefined>;
52
54
  /** The adb runner; default the CLI the settings name. */
53
55
  adb?: AdbTransport | string;
56
+ /** The ui fixture's APK; default UI_FIXTURE_APK. Installed on each phone when it is there. */
57
+ uiFixture?: string;
54
58
  }
55
59
  /** The provider the CLI runs. */
56
60
  export declare function createProvider(options?: PhoneModuleOptions): Promise<PhoneHarnessProvider>;
57
- /** The same provider, whose phone's hello reports another version: connect refuses it, for the drift.version case. */
61
+ /** The same provider, expecting phoned to report another version than its own: connect refuses it, for the drift.version case. */
58
62
  export declare function createDriftedProvider(options?: PhoneModuleOptions): Promise<PhoneHarnessProvider>;
59
63
  /** The image a run names: a cloud Android has none to choose, so it is read back as this name. */
60
64
  export declare function conformanceImage(): string;
@@ -1,13 +1,14 @@
1
1
  // The phone harness for the conformance CLI and the live harness (`--provider phone-harness`): the provider as create()
2
2
  // builds it from the settings this module reads (COMPUTER_PHONE_HARNESS_*), with its ledger in a JSON file so a sweep in
3
- // another process sees the run's phones, and its drifted twin, whose phone's hello reports another version. A phone is
3
+ // another process sees the run's phones, and its drifted twin, which expects phoned to report another version. A phone is
4
4
  // rented by the minute, so nothing is built without AGENTRUN_COMPUTER_LIVE_PHONE_HARNESS=1, and a run's phones live at
5
5
  // most 10 min.
6
6
  // The provider reads no environment: this module reads these names and passes them in as options.
7
7
  import { randomBytes } from "node:crypto";
8
- import { linkSync, mkdirSync, readFileSync, renameSync, unlinkSync, writeFileSync } from "node:fs";
8
+ import { existsSync, linkSync, mkdirSync, readFileSync, renameSync, unlinkSync, writeFileSync } from "node:fs";
9
9
  import { tmpdir } from "node:os";
10
10
  import { dirname, join } from "node:path";
11
+ import { fileURLToPath } from "node:url";
11
12
  import { PHONE_IMAGE } from "../descriptors/phone-harness.js";
12
13
  import { adbCli, create } from "../phone-harness.js";
13
14
  /** The environment this module reads, by name. */
@@ -196,6 +197,14 @@ export function fileLedger(path, { waitMs = LOCK_WAIT_MS } = {}) {
196
197
  };
197
198
  return {
198
199
  put: (entry) => locked(() => write({ ...read(), [entry.id]: entry })),
200
+ // Under the file's lock: the read and the write are one step to every other writer.
201
+ claim: (entry) => locked(() => {
202
+ const entries = read();
203
+ if (entry.id in entries)
204
+ return false;
205
+ write({ ...entries, [entry.id]: entry });
206
+ return true;
207
+ }),
199
208
  get: (id) => read()[id],
200
209
  list: () => Object.values(read()),
201
210
  remove: (id) => locked(() => {
@@ -207,7 +216,9 @@ export function fileLedger(path, { waitMs = LOCK_WAIT_MS } = {}) {
207
216
  }),
208
217
  };
209
218
  }
210
- function optionsOf({ env = process.env, adb, ...rest }) {
219
+ /** The ui fixture as an Android app (npm run build:ui-fixture), beside the compiled modules: a run installs it on its phones. */
220
+ export const UI_FIXTURE_APK = fileURLToPath(new URL("../ui-fixture.apk", import.meta.url));
221
+ function optionsOf({ env = process.env, adb, uiFixture = UI_FIXTURE_APK, ...rest }) {
211
222
  if (env[PHONE_ENV.live] !== "1")
212
223
  throw new Error(`a conformance run rents a cloud phone, billed by the minute: set ${PHONE_ENV.live}=1 to run it`);
213
224
  const settings = settingsFromEnv(env);
@@ -222,6 +233,9 @@ function optionsOf({ env = process.env, adb, ...rest }) {
222
233
  adb: adb !== undefined && typeof adb !== "string" ? adb : adbCli(adb ?? settings.adb ?? "adb", { env: Object.fromEntries(Object.entries(env).filter(([name]) => !Object.values(PHONE_ENV).includes(name))) }),
223
234
  ledger: fileLedger(settings.ledgerPath ?? join(tmpdir(), "agentrun-phone-ledger.json")),
224
235
  maxLifetimeMs: RUN_MAX_LIFETIME_MS,
236
+ // The Full ui cases act on the fixture. Without its APK they skip, each saying it is not installed, and the
237
+ // report's notes say why (conformanceNotes).
238
+ apks: existsSync(uiFixture) ? [uiFixture] : [],
225
239
  ...rest,
226
240
  };
227
241
  }
@@ -229,7 +243,7 @@ function optionsOf({ env = process.env, adb, ...rest }) {
229
243
  export async function createProvider(options = {}) {
230
244
  return create(optionsOf(options));
231
245
  }
232
- /** The same provider, whose phone's hello reports another version: connect refuses it, for the drift.version case. */
246
+ /** The same provider, expecting phoned to report another version than its own: connect refuses it, for the drift.version case. */
233
247
  export async function createDriftedProvider(options = {}) {
234
248
  return create({ ...optionsOf(options), daemonVersion: "0.0.0-drift" });
235
249
  }
@@ -239,4 +253,7 @@ export function conformanceImage() {
239
253
  }
240
254
  export const conformanceNotes = [
241
255
  "phone-harness: a temporary cloud Android emulator, driven over adb; a phone is billed by the minute, and lives at most 10 min in a run",
256
+ existsSync(UI_FIXTURE_APK)
257
+ ? `phone-harness: each phone gets the ui fixture installed (${UI_FIXTURE_APK}) for the Full ui cases`
258
+ : `phone-harness: the ui fixture's APK is not at ${UI_FIXTURE_APK} (npm run build:ui-fixture builds it), so the Full ui cases skip: no phone has the fixture`,
242
259
  ];
@@ -1,4 +1,4 @@
1
- const GROUPS = ["health", "exec", "files", "process", "provider", "drift", "isolation", "mount", "screen", "input", "touch", "apps", "lifetime", "browser", "gpu"];
1
+ const GROUPS = ["health", "exec", "files", "process", "provider", "drift", "isolation", "mount", "screen", "input", "touch", "apps", "ui", "lifetime", "browser", "gpu"];
2
2
  const NAMES_WIDTH = 44;
3
3
  const INDENT = " ".repeat("core ".length + "provider ".length + 1);
4
4
  /** The case names, wrapped to the column's width: the first line, then the rest. */
@@ -192,7 +192,7 @@ export async function runConformance(provider, options) {
192
192
  // The run's signal ends the wait at once (Ctrl-C during setup) and reaches the create; a computer that arrives
193
193
  // after it is deleted as it lands (lateCreate).
194
194
  const stop = new AbortController();
195
- const creating = provider.create(spec(), { signal: signal ? AbortSignal.any([signal, stop.signal]) : stop.signal });
195
+ const creating = provider.create(spec(), { signal: signal ? AbortSignal.any([signal, stop.signal]) : stop.signal, requestId: `${run}/shared` });
196
196
  let created;
197
197
  try {
198
198
  created = await within(creating, caseTimeoutMs, "create", signal);
@@ -346,11 +346,14 @@ export async function runConformance(provider, options) {
346
346
  sawHello(ref.name, once.hello, c.id);
347
347
  return once;
348
348
  };
349
+ /** Each create of the case is its own request: the run, the case and the create's count. */
350
+ let creates = 0;
349
351
  /** create through by, kept: what it gives is deleted when the case ends, or as it comes after that. */
350
- const attempt = (whole, by = provider) => {
351
- const creating = by.create(whole, { signal: caseSignal }).then((created) => {
352
+ const attempt = (whole, by = provider, requestId = `${run}/${c.id}/${++creates}`) => {
353
+ const creating = by.create(whole, { signal: caseSignal, requestId }).then((created) => {
352
354
  noteCreated(created, c.id);
353
- if (created.ok)
355
+ // A retry of one request answers the computer the first attempt made: it is tracked once.
356
+ if (created.ok && !refs.some((one) => one.ref.id === created.value.id))
354
357
  track(created.value, by);
355
358
  return created;
356
359
  });
@@ -627,6 +630,22 @@ async function cleanup(provider, lifetime, labels, report, deleted, ms) {
627
630
  report.cleanup.left = listed.value.map((info) => info.ref.name).sort();
628
631
  else
629
632
  report.cleanup.errors.push(`list ${JSON.stringify(labels)}: ${listed.error.code}: ${listed.error.message}`);
633
+ // Nothing left behind, read from the vendor itself: a provider on the shared machine-host adapter is swept by the
634
+ // run's label through its host, as the live sweep (sweep.ts) does, and every machine it finds must be gone.
635
+ const host = provider.host;
636
+ if (host !== undefined && typeof host.list === "function") {
637
+ const { sweepMachines } = await import("./sweep.js");
638
+ const said = [];
639
+ const swept = await within(sweepMachines(host, { labels, waitMs: ms, onWords: (words) => said.push(words) }), ms * 2, "the sweep of the run's machines");
640
+ report.cleanup.errors.push(...said.map((words) => `sweep: ${words}`));
641
+ if (!swept.ok)
642
+ report.cleanup.errors.push(`sweep: ${swept.error.code}: ${swept.error.message}`);
643
+ else {
644
+ report.cleanup.sweep = swept.value;
645
+ if (swept.value.stillThere.length > 0)
646
+ report.cleanup.errors.push(`sweep: nothing left behind fails: still there ${swept.value.stillThere.join(", ")}`);
647
+ }
648
+ }
630
649
  }
631
650
  catch (error) {
632
651
  report.cleanup.errors.push(words(error));
@@ -0,0 +1,50 @@
1
+ import type { MachineHost } from "../host.js";
2
+ import { type Result } from "../result.js";
3
+ /** What one sweep did: see the file's head. */
4
+ export interface SweepCounts {
5
+ swept: number;
6
+ gone: number;
7
+ stillThere: string[];
8
+ leftAlone: number;
9
+ }
10
+ export interface SweepMachinesOptions {
11
+ /** The labels every machine swept carries, over agentrun.computer=1. */
12
+ labels?: Record<string, string>;
13
+ /** Ids that were there before: never touched. */
14
+ before?: ReadonlySet<string>;
15
+ /** How long one deleted machine is read back before it counts as still there; default 60 s. */
16
+ waitMs?: number;
17
+ /** The pause between two reads of one machine; default 2 s. */
18
+ pollMs?: number;
19
+ /** One vendor call's bound; default 30 s. */
20
+ requestMs?: number;
21
+ /** One whole listing's bound; default 60 s. */
22
+ listMs?: number;
23
+ /** Told, in words, of a machine not deleted or still there. */
24
+ onWords?: (words: string) => void;
25
+ }
26
+ /**
27
+ * The sweep over host: every machine listed with agentrun.computer=1 and `labels`, not in `before`, that carries a
28
+ * conformance run's label is deleted and read back gone; one without it is left alone and counted. A listing the
29
+ * vendor refused is the error, with nothing deleted.
30
+ */
31
+ export declare function sweepMachines(host: MachineHost, { labels, before, waitMs, pollMs, requestMs, listMs, onWords }?: SweepMachinesOptions): Promise<Result<SweepCounts>>;
32
+ /** A stream as main writes to it: done is called once the text is handed on. */
33
+ export interface Writer {
34
+ write(text: string, done?: (error?: Error | null) => void): unknown;
35
+ }
36
+ export interface SweepIo {
37
+ /** Where the settings are read; default process.env. */
38
+ env?: Record<string, string | undefined>;
39
+ /** The host to sweep, in place of the one the provider's conformance module makes from env. */
40
+ host?: MachineHost;
41
+ /** Where that host lists, in words, in place of the module's sweepScope. */
42
+ scope?: string;
43
+ stdout?: Writer;
44
+ stderr?: Writer;
45
+ /** How long --after reads one deleted machine back before it counts as still there; default 60 s. */
46
+ waitMs?: number;
47
+ /** The pause between two reads of one machine; default 2 s. */
48
+ pollMs?: number;
49
+ }
50
+ export declare function main(argv: string[], io?: SweepIo): Promise<number>;
@@ -0,0 +1,187 @@
1
+ // The one live sweep, for every provider on the shared machine-host adapter, with the provider's conformance settings
2
+ // (its COMPUTER_<VENDOR>_* names, read by its conformance module's createHost):
3
+ //
4
+ // node packages/computer/dist/conformance/sweep.js --provider <id> --before <file>
5
+ // node packages/computer/dist/conformance/sweep.js --provider <id> --after <file>
6
+ //
7
+ // --before records into <file> the id of every machine the vendor lists with the adapter's label agentrun.computer=1.
8
+ // --after lists them again, deletes every one whose id is not in <file> and that carries a conformance run's label
9
+ // (agentrun.conformance, RUN_LABEL), then reads each of those back until the vendor no longer has it and no longer lists
10
+ // it, up to 60 s each, and prints one JSON line, {"swept":n,"gone":m,"stillThere":[ids],"leftAlone":k}: swept is every
11
+ // conformance machine it found that was not there before, gone + stillThere.length = swept, and leftAlone counts the new
12
+ // labelled machines with no conformance label, which another user of the account made during the run: never touched. A
13
+ // machine in <file> is never touched either: no call names it, and a before file of another provider is refused, as is
14
+ // one listed elsewhere for a provider whose module names where it lists (sweepScope: an app and a server), since
15
+ // every machine there would read as new.
16
+ // Exit 0 when every swept machine is gone, 1 when one is still there, 2 on a usage error, a before file it cannot read,
17
+ // missing settings, or a listing the vendor refused (nothing is deleted then). It makes nothing, so it needs no live switch.
18
+ //
19
+ // The conformance runner runs the same sweep (sweepMachines) at the end of every run of a hosted provider, over the
20
+ // run's own label: its report's cleanup.sweep, whose stillThere must be empty for Core to pass.
21
+ import { readFileSync, writeFileSync } from "node:fs";
22
+ import { COMPUTER_LABEL } from "../drift.js";
23
+ import { isCommand } from "../entry.js";
24
+ import { hostCall } from "../hosted/process.js";
25
+ import { NAME_LABEL, settleGone } from "../hosted/provider.js";
26
+ import { providerModule } from "../providers.js";
27
+ import { ok } from "../result.js";
28
+ import { RUN_LABEL } from "./runner.js";
29
+ /**
30
+ * The sweep over host: every machine listed with agentrun.computer=1 and `labels`, not in `before`, that carries a
31
+ * conformance run's label is deleted and read back gone; one without it is left alone and counted. A listing the
32
+ * vendor refused is the error, with nothing deleted.
33
+ */
34
+ export async function sweepMachines(host, { labels = {}, before = new Set(), waitMs = 60_000, pollMs = 2_000, requestMs = 30_000, listMs = 60_000, onWords = () => { } } = {}) {
35
+ const listed = await hostCall(host, "the listing", (ctx) => host.list({ ...labels, [COMPUTER_LABEL]: "1" }, ctx), listMs);
36
+ if (!listed.ok)
37
+ return listed;
38
+ const added = listed.value.filter((machine) => !before.has(machine.id));
39
+ // Only a conformance run's machines: one another user of the account made during the run is not this sweep's.
40
+ const fresh = added.filter((machine) => Object.hasOwn(machine.labels, RUN_LABEL));
41
+ const leftAlone = added.length - fresh.length;
42
+ for (const machine of fresh) {
43
+ const deleted = await hostCall(host, `the delete of ${machine.id}`, (ctx) => host.delete(machine.id, ctx), requestMs);
44
+ if (!deleted.ok && deleted.error.code !== "not_found")
45
+ onWords(`${machine.id} was not deleted: ${deleted.error.message}`);
46
+ }
47
+ // Each read back on its own, at once: gone once the vendor no longer has it and its listing no longer shows it.
48
+ const gone = await Promise.all(fresh.map(async (machine) => {
49
+ const name = machine.labels[NAME_LABEL] ?? machine.id;
50
+ const settled = await settleGone(host, { id: machine.id, name }, { requestMs, listMs, pollMs, goneMs: waitMs });
51
+ if (!settled.ok)
52
+ onWords(`${machine.id} is still there after ${waitMs / 1000} s: ${settled.error.message}`);
53
+ return settled.ok;
54
+ }));
55
+ const stillThere = fresh.filter((_, i) => !gone[i]).map((machine) => machine.id);
56
+ return ok({ swept: fresh.length, gone: fresh.length - stillThere.length, stillThere, leftAlone });
57
+ }
58
+ const USAGE = `usage: node packages/computer/dist/conformance/sweep.js --provider <id> --before <file> | --after <file>
59
+ --provider <id> a provider on the shared machine-host adapter (e2b, agent37)
60
+ --before <file> record the id of every machine the vendor lists with ${COMPUTER_LABEL}=1 into <file>
61
+ --after <file> delete every machine listed with ${COMPUTER_LABEL}=1 and ${RUN_LABEL} whose id is not in <file>, read
62
+ each back until the vendor no longer has it (up to 60 s each), and print
63
+ {"swept":n,"gone":m,"stillThere":[ids],"leftAlone":k}; a new one with no ${RUN_LABEL} is left alone
64
+ settings: the provider's conformance module's (COMPUTER_<VENDOR>_*), never the vendor's own names
65
+ exit: 0 every swept machine is gone, 1 one is still there, 2 usage error, unreadable before file, no settings, or a refused listing`;
66
+ class Usage extends Error {
67
+ }
68
+ const write = (stream, text) => new Promise((resolve) => void stream.write(text, () => resolve()));
69
+ function parse(argv) {
70
+ let provider;
71
+ let found;
72
+ for (let i = 0; i < argv.length; i++) {
73
+ const [flag = "", inline] = (argv[i] ?? "").split(/=(.*)/s, 2);
74
+ if (flag !== "--before" && flag !== "--after" && flag !== "--provider")
75
+ throw new Usage(`unknown option ${flag}`);
76
+ const value = inline ?? argv[++i];
77
+ if (value === undefined || value === "" || value.startsWith("--"))
78
+ throw new Usage(`${flag} needs a ${flag === "--provider" ? "provider id" : "file"}`);
79
+ if (flag === "--provider") {
80
+ if (provider !== undefined)
81
+ throw new Usage("give --provider once");
82
+ provider = value;
83
+ continue;
84
+ }
85
+ if (found !== undefined)
86
+ throw new Usage("give --before <file> or --after <file>, one of them");
87
+ found = { mode: flag === "--before" ? "before" : "after", file: value };
88
+ }
89
+ if (provider === undefined)
90
+ throw new Usage("give --provider <id>");
91
+ if (found === undefined)
92
+ throw new Usage("give --before <file> or --after <file>, one of them");
93
+ return { provider, ...found };
94
+ }
95
+ /** The ids a before file of this provider (and of this scope, when the provider names one) holds, or why it is not one. */
96
+ function beforeIds(file, provider, scope) {
97
+ let text;
98
+ try {
99
+ text = readFileSync(file, "utf8");
100
+ }
101
+ catch (error) {
102
+ throw new Usage(`cannot read the before file ${file}: ${error.message}`);
103
+ }
104
+ let record;
105
+ try {
106
+ record = JSON.parse(text);
107
+ }
108
+ catch {
109
+ record = undefined;
110
+ }
111
+ const { ids, provider: recorded } = (record ?? {});
112
+ if (!Array.isArray(ids) || !ids.every((id) => typeof id === "string" && id !== ""))
113
+ throw new Usage(`${file} is not a before file: it holds no "ids" array of machine ids`);
114
+ if (recorded !== provider)
115
+ throw new Usage(`${file} is the before file of ${JSON.stringify(recorded)}, not of ${provider}: sweep each provider with its own`);
116
+ const listed = record.scope;
117
+ if (scope !== undefined && listed !== scope) {
118
+ const words = typeof listed === "string" && listed !== "" ? `was listed in ${listed}` : "names no place it was listed in";
119
+ throw new Usage(`${file} ${words}, and the settings name ${scope} now: every machine there would read as new, so nothing was listed or deleted`);
120
+ }
121
+ return new Set(ids);
122
+ }
123
+ /** The provider's conformance module, for its host and scope. */
124
+ async function moduleOf(provider) {
125
+ let module;
126
+ try {
127
+ module = (await (await providerModule(provider)).conformance?.());
128
+ }
129
+ catch (error) {
130
+ throw new Usage(error.message);
131
+ }
132
+ if (typeof module?.createHost !== "function")
133
+ throw new Usage(`the ${provider} provider is not on the shared machine-host adapter: it has no createHost to sweep with`);
134
+ return module;
135
+ }
136
+ /** Where the module's host lists, in words, read from the same settings; undefined for a provider that names none. */
137
+ function scopeOf(module, env) {
138
+ try {
139
+ return module.sweepScope?.({ env });
140
+ }
141
+ catch (error) {
142
+ throw new Usage(error.message);
143
+ }
144
+ }
145
+ export async function main(argv, io = {}) {
146
+ const { env = process.env, stdout = process.stdout, stderr = process.stderr, waitMs = 60_000, pollMs = 2_000 } = io;
147
+ let args;
148
+ let before;
149
+ let host;
150
+ let scope;
151
+ try {
152
+ args = parse(argv);
153
+ const module = io.host === undefined ? await moduleOf(args.provider) : undefined;
154
+ scope = io.host === undefined ? scopeOf(module, env) : io.scope;
155
+ if (args.mode === "after")
156
+ before = beforeIds(args.file, args.provider, scope);
157
+ host = io.host ?? (await module.createHost({ env }));
158
+ }
159
+ catch (error) {
160
+ await write(stderr, `${error.message}\n${error instanceof Usage ? `${USAGE}\n` : ""}`);
161
+ return 2;
162
+ }
163
+ if (before === undefined) {
164
+ const listed = await hostCall(host, "the listing", (ctx) => host.list({ [COMPUTER_LABEL]: "1" }, ctx), 60_000);
165
+ if (!listed.ok) {
166
+ await write(stderr, `listing the machines carrying ${COMPUTER_LABEL}=1 failed, so nothing was recorded: ${listed.error.message}\n`);
167
+ return 2;
168
+ }
169
+ const ids = listed.value.map((machine) => machine.id).sort();
170
+ writeFileSync(args.file, `${JSON.stringify({ provider: args.provider, ...(scope === undefined ? {} : { scope }), label: `${COMPUTER_LABEL}=1`, at: new Date().toISOString(), ids }, null, 2)}\n`);
171
+ await write(stdout, `${JSON.stringify({ recorded: ids.length, file: args.file })}\n`);
172
+ return 0;
173
+ }
174
+ const said = [];
175
+ const swept = await sweepMachines(host, { before, waitMs, pollMs, onWords: (words) => said.push(words) });
176
+ for (const words of said)
177
+ await write(stderr, `${words}\n`);
178
+ if (!swept.ok) {
179
+ await write(stderr, `listing the machines carrying ${COMPUTER_LABEL}=1 failed, so nothing was deleted: ${swept.error.message}\n`);
180
+ return 2;
181
+ }
182
+ await write(stdout, `${JSON.stringify(swept.value)}\n`);
183
+ return swept.value.stillThere.length === 0 ? 0 : 1;
184
+ }
185
+ if (isCommand(import.meta)) {
186
+ process.exitCode = await main(process.argv.slice(2));
187
+ }