@parcha/agentrun-computer 0.1.0-beta.36 → 0.1.0-beta.38
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/NOTICE +2 -0
- package/README.md +547 -478
- package/box/Dockerfile +18 -1
- package/box/README.md +13 -0
- package/box/build-agent37.mjs +158 -0
- package/box/build-daytona.py +2 -2
- package/box/build-e2b.mjs +41 -18
- package/box/recipe.mjs +43 -0
- package/dist/agent37-ssh.d.ts +89 -0
- package/dist/agent37-ssh.js +445 -0
- package/dist/agent37.d.ts +104 -0
- package/dist/agent37.js +402 -0
- package/dist/attach.d.ts +146 -0
- package/dist/attach.js +469 -0
- package/dist/browserbase.d.ts +2 -10
- package/dist/browserbase.js +3 -6
- package/dist/client.d.ts +45 -4
- package/dist/client.js +92 -4
- package/dist/computerd-linux-amd64 +0 -0
- package/dist/computerd-linux-arm64 +0 -0
- package/dist/computerd.json +4 -0
- package/dist/conformance/agent37.d.ts +96 -0
- package/dist/conformance/agent37.js +154 -0
- package/dist/conformance/cases/apps.d.ts +11 -0
- package/dist/conformance/cases/apps.js +173 -73
- package/dist/conformance/cases/health.js +14 -0
- package/dist/conformance/cases/index.js +2 -0
- package/dist/conformance/cases/isolation.d.ts +7 -5
- package/dist/conformance/cases/isolation.js +44 -14
- package/dist/conformance/cases/mount.js +1 -1
- package/dist/conformance/cases/provider.js +27 -1
- package/dist/conformance/cases/screen.d.ts +3 -0
- package/dist/conformance/cases/screen.js +18 -0
- package/dist/conformance/cases/settings.d.ts +29 -23
- package/dist/conformance/cases/settings.js +76 -58
- package/dist/conformance/cases/touch.js +19 -17
- package/dist/conformance/cases/ui.d.ts +2 -0
- package/dist/conformance/cases/ui.js +475 -0
- package/dist/conformance/cli.d.ts +9 -0
- package/dist/conformance/cli.js +94 -9
- package/dist/conformance/daytona.d.ts +9 -20
- package/dist/conformance/daytona.js +12 -21
- package/dist/conformance/e2b.d.ts +6 -0
- package/dist/conformance/e2b.js +9 -2
- package/dist/conformance/exec-stream.d.ts +45 -0
- package/dist/conformance/exec-stream.js +486 -0
- package/dist/conformance/fixture.d.ts +1 -1
- package/dist/conformance/fixture.js +25 -1
- package/dist/conformance/modal.d.ts +17 -13
- package/dist/conformance/modal.js +18 -9
- package/dist/conformance/orgo.d.ts +3 -3
- package/dist/conformance/orgo.js +6 -8
- package/dist/conformance/phone-harness.d.ts +6 -2
- package/dist/conformance/phone-harness.js +21 -4
- package/dist/conformance/report.js +1 -1
- package/dist/conformance/runner.js +23 -4
- package/dist/conformance/sweep.d.ts +50 -0
- package/dist/conformance/sweep.js +187 -0
- package/dist/conformance/types.d.ts +13 -5
- package/dist/conformance/ui-fixture.d.ts +56 -0
- package/dist/conformance/ui-fixture.js +43 -0
- package/dist/create-requests.d.ts +51 -0
- package/dist/create-requests.js +121 -0
- package/dist/daytona.d.ts +20 -133
- package/dist/daytona.js +405 -1449
- package/dist/descriptor.d.ts +11 -1
- package/dist/descriptor.js +9 -0
- package/dist/descriptors/agent37.d.ts +41 -0
- package/dist/descriptors/agent37.js +28 -0
- package/dist/descriptors/daytona.d.ts +6 -5
- package/dist/descriptors/daytona.js +9 -5
- package/dist/descriptors/index.d.ts +42 -7
- package/dist/descriptors/index.js +4 -2
- package/dist/descriptors/orgo.d.ts +2 -1
- package/dist/descriptors/orgo.js +3 -2
- package/dist/descriptors/phone-harness.d.ts +1 -1
- package/dist/descriptors/phone-harness.js +2 -2
- package/dist/descriptors/shared.d.ts +1 -1
- package/dist/descriptors/shared.js +2 -2
- package/dist/desktop.d.ts +18 -4
- package/dist/desktop.js +89 -9
- package/dist/docker.d.ts +7 -10
- package/dist/docker.js +272 -34
- package/dist/drift.js +4 -4
- package/dist/e2b.d.ts +16 -290
- package/dist/e2b.js +230 -1393
- package/dist/fake-ui-driver.d.ts +97 -0
- package/dist/fake-ui-driver.js +717 -0
- package/dist/host.d.ts +201 -0
- package/dist/host.js +8 -0
- package/dist/hosted/process.d.ts +81 -0
- package/dist/hosted/process.js +259 -0
- package/dist/hosted/provider.d.ts +160 -0
- package/dist/hosted/provider.js +1415 -0
- package/dist/hosted/rest.d.ts +66 -0
- package/dist/hosted/rest.js +121 -0
- package/dist/hosted/scripts.d.ts +82 -0
- package/dist/{child.js → hosted/scripts.js} +118 -12
- package/dist/hosted/values.d.ts +5 -0
- package/dist/hosted/values.js +8 -0
- package/dist/index.d.ts +7 -3
- package/dist/index.js +7 -4
- package/dist/kernel.d.ts +2 -10
- package/dist/kernel.js +3 -6
- package/dist/kinds.d.ts +11 -2
- package/dist/kinds.js +20 -4
- package/dist/local-chrome.d.ts +2 -10
- package/dist/local-chrome.js +3 -6
- package/dist/modal.d.ts +22 -257
- package/dist/modal.js +183 -1280
- package/dist/mount-archil.d.ts +8 -4
- package/dist/mount-archil.js +22 -11
- package/dist/mount.d.ts +10 -4
- package/dist/mount.js +8 -4
- package/dist/orgo-channel.d.ts +3 -2
- package/dist/orgo-channel.js +5 -2
- package/dist/orgo-desktop.d.ts +9 -4
- package/dist/orgo-desktop.js +33 -13
- package/dist/orgo-workspaces.d.ts +47 -0
- package/dist/orgo-workspaces.js +94 -0
- package/dist/orgo.d.ts +10 -13
- package/dist/orgo.js +32 -21
- package/dist/phone-harness.d.ts +31 -28
- package/dist/phone-harness.js +510 -702
- package/dist/png.d.ts +4 -0
- package/dist/png.js +27 -0
- package/dist/protocol.d.ts +339 -33
- package/dist/protocol.js +97 -3
- package/dist/provider.d.ts +36 -8
- package/dist/provider.js +16 -0
- package/dist/providers.d.ts +11 -12
- package/dist/result.d.ts +1 -1
- package/dist/screen-watch.js +34 -6
- package/dist/surface/api.d.ts +260 -0
- package/dist/surface/api.js +1 -0
- package/dist/surface/core.d.ts +55 -0
- package/dist/surface/core.js +475 -0
- package/dist/surface/index.d.ts +5 -0
- package/dist/surface/index.js +3 -0
- package/dist/surface/outline.d.ts +10 -0
- package/dist/surface/outline.js +51 -0
- package/dist/surface/script.d.ts +10 -0
- package/dist/surface/script.js +94 -0
- package/dist/ui-engine.d.ts +114 -0
- package/dist/ui-engine.js +814 -0
- package/package.json +18 -3
- package/dist/child.d.ts +0 -42
- package/dist/conformance/daytona-sweep.d.ts +0 -18
- package/dist/conformance/daytona-sweep.js +0 -126
- package/dist/conformance/e2b-diagnose.d.ts +0 -16
- package/dist/conformance/e2b-diagnose.js +0 -61
- package/dist/conformance/e2b-sweep.d.ts +0 -18
- package/dist/conformance/e2b-sweep.js +0 -132
- package/dist/conformance/modal-sweep.d.ts +0 -22
- package/dist/conformance/modal-sweep.js +0 -213
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@parcha/agentrun-computer",
|
|
3
|
-
"version": "0.1.0-beta.
|
|
3
|
+
"version": "0.1.0-beta.38",
|
|
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",
|
|
@@ -26,6 +26,10 @@
|
|
|
26
26
|
"types": "./dist/mount.d.ts",
|
|
27
27
|
"default": "./dist/mount.js"
|
|
28
28
|
},
|
|
29
|
+
"./fake-ui-driver": {
|
|
30
|
+
"types": "./dist/fake-ui-driver.d.ts",
|
|
31
|
+
"default": "./dist/fake-ui-driver.js"
|
|
32
|
+
},
|
|
29
33
|
"./docker": {
|
|
30
34
|
"types": "./dist/docker.d.ts",
|
|
31
35
|
"default": "./dist/docker.js"
|
|
@@ -42,6 +46,10 @@
|
|
|
42
46
|
"types": "./dist/e2b.d.ts",
|
|
43
47
|
"default": "./dist/e2b.js"
|
|
44
48
|
},
|
|
49
|
+
"./agent37": {
|
|
50
|
+
"types": "./dist/agent37.d.ts",
|
|
51
|
+
"default": "./dist/agent37.js"
|
|
52
|
+
},
|
|
45
53
|
"./orgo": {
|
|
46
54
|
"types": "./dist/orgo.d.ts",
|
|
47
55
|
"default": "./dist/orgo.js"
|
|
@@ -66,6 +74,10 @@
|
|
|
66
74
|
"types": "./dist/local-chrome.d.ts",
|
|
67
75
|
"default": "./dist/local-chrome.js"
|
|
68
76
|
},
|
|
77
|
+
"./surface": {
|
|
78
|
+
"types": "./dist/surface/index.d.ts",
|
|
79
|
+
"default": "./dist/surface/index.js"
|
|
80
|
+
},
|
|
69
81
|
"./package.json": "./package.json"
|
|
70
82
|
},
|
|
71
83
|
"files": [
|
|
@@ -79,14 +91,17 @@
|
|
|
79
91
|
"scripts": {
|
|
80
92
|
"build": "tsc -p tsconfig.json",
|
|
81
93
|
"build:daemon": "node scripts/build-daemon.mjs",
|
|
94
|
+
"build:phoned": "node scripts/build-phoned.mjs",
|
|
95
|
+
"build:ui-fixture": "node scripts/build-ui-fixture.mjs",
|
|
96
|
+
"check:phoned": "node scripts/check-phoned-jar.mjs",
|
|
97
|
+
"test:phoned": "node scripts/build-phoned.mjs --test && node scripts/build-phoned.mjs --fake && node --test test/phoned/*.test.mjs",
|
|
82
98
|
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
83
99
|
"test": "node --test test/*.test.mjs",
|
|
84
100
|
"test:docker": "node --test --test-timeout=900000 test/docker/*.test.mjs",
|
|
85
101
|
"test:daytona": "node --test --test-timeout=1800000 test/daytona/*.test.mjs",
|
|
86
102
|
"test:modal": "node --test --test-timeout=1800000 test/modal/*.test.mjs",
|
|
87
103
|
"test:e2b": "node --test --test-timeout=1800000 test/e2b/*.test.mjs",
|
|
88
|
-
"conformance": "node dist/conformance/cli.js"
|
|
89
|
-
"daytona:sweep": "node dist/conformance/daytona-sweep.js"
|
|
104
|
+
"conformance": "node dist/conformance/cli.js"
|
|
90
105
|
},
|
|
91
106
|
"repository": {
|
|
92
107
|
"type": "git",
|
package/dist/child.d.ts
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import type { ComputerCapabilities, ComputerConnection } from "./provider.js";
|
|
2
|
-
import { type Result } from "./result.js";
|
|
3
|
-
/** Who ran install, from its output's `installer <uid> <name>[ sudo]` line, in words; undefined when it has none. */
|
|
4
|
-
export declare function installerOf(output: string): string | undefined;
|
|
5
|
-
/** One string for a shell: `sh -c '<script>' sh '<arg>' ...`, every word quoted. */
|
|
6
|
-
export declare const shellCommand: (script: string, args: readonly string[]) => string;
|
|
7
|
-
export interface ChildCommandOptions {
|
|
8
|
-
/** Where the vendor's upload left the daemon. */
|
|
9
|
-
staging?: string;
|
|
10
|
-
/** Init's deadline, an ISO time. */
|
|
11
|
-
deadline?: string;
|
|
12
|
-
/** Who the daemon becomes, uid:gid in numbers. */
|
|
13
|
-
user?: string;
|
|
14
|
-
/** The X display init's screen and input methods drive (its DISPLAY); none for a computer with no screen. */
|
|
15
|
-
display?: string;
|
|
16
|
-
/** The most deadline.extend may move the deadline to, an ISO time; none, and the deadline cannot move. */
|
|
17
|
-
maxDeadline?: string;
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* The three shell commands a child-daemon provider sends into a computer, exactly: install (the upload moved into place,
|
|
21
|
-
* its sha256 printed), init (long-lived) and stdio (one per connection). Each is one string for a shell, `sh -c` with
|
|
22
|
-
* every argument quoted.
|
|
23
|
-
*/
|
|
24
|
-
export declare function childCommands({ staging, deadline, user, display, maxDeadline }?: ChildCommandOptions): {
|
|
25
|
-
install: string;
|
|
26
|
-
init: string;
|
|
27
|
-
stdio: string;
|
|
28
|
-
};
|
|
29
|
-
export interface DaemonExpected {
|
|
30
|
-
version: string;
|
|
31
|
-
uid: string;
|
|
32
|
-
gid: string;
|
|
33
|
-
arch: string;
|
|
34
|
-
kind: ComputerCapabilities["kind"];
|
|
35
|
-
groups: ComputerCapabilities["groups"];
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* What the daemon reports of itself, read back through it: hello, its credentials (no capability in any set,
|
|
39
|
-
* no_new_privs, no groups, a seccomp filter), its network (its own loopback alone, from its /proc/self/net/dev), its
|
|
40
|
-
* working directory and binary. Each read is bounded by timeoutMs and the caller's signal.
|
|
41
|
-
*/
|
|
42
|
-
export declare function daemonDrift(connection: ComputerConnection, expected: DaemonExpected, timeoutMs: number, signal?: AbortSignal): Promise<Result<string[]>>;
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import type { DaytonaProviderOptions } from "../daytona.js";
|
|
2
|
-
/** A stream as main writes to it: done is called once the text is handed on. */
|
|
3
|
-
export interface Writer {
|
|
4
|
-
write(text: string, done?: (error?: Error | null) => void): unknown;
|
|
5
|
-
}
|
|
6
|
-
export interface SweepIo {
|
|
7
|
-
/** Where the settings are read; default process.env. */
|
|
8
|
-
env?: Record<string, string | undefined>;
|
|
9
|
-
fetch?: DaytonaProviderOptions["fetch"];
|
|
10
|
-
webSocket?: DaytonaProviderOptions["webSocket"];
|
|
11
|
-
stdout?: Writer;
|
|
12
|
-
stderr?: Writer;
|
|
13
|
-
/** How long --after reads one deleted sandbox back before it counts as still there; default 60 s. */
|
|
14
|
-
waitMs?: number;
|
|
15
|
-
/** The pause between two reads of one sandbox; default 2 s. */
|
|
16
|
-
pollMs?: number;
|
|
17
|
-
}
|
|
18
|
-
export declare function main(argv: string[], io?: SweepIo): Promise<number>;
|
|
@@ -1,126 +0,0 @@
|
|
|
1
|
-
// The sweep around a live Daytona run, with the conformance module's settings (COMPUTER_DAYTONA_*, never DAYTONA_*):
|
|
2
|
-
//
|
|
3
|
-
// node packages/computer/dist/conformance/daytona-sweep.js --before <file>
|
|
4
|
-
// node packages/computer/dist/conformance/daytona-sweep.js --after <file>
|
|
5
|
-
//
|
|
6
|
-
// --before records the id of every sandbox carrying agentrun.computer=1 into <file>. --after lists them again, deletes
|
|
7
|
-
// (release delete) every one whose id is not in <file> and that carries a conformance run's label (agentrun.conformance,
|
|
8
|
-
// RUN_LABEL), then reads each of those back with GET /sandbox/{id} until Daytona answers 404, up to 60 s each, and
|
|
9
|
-
// prints one JSON line, {"swept":n,"notFound":m,"stillThere":[ids],"leftAlone":k}: swept is every conformance sandbox
|
|
10
|
-
// it found that was not there before, notFound + stillThere.length = swept, and leftAlone counts the new labelled
|
|
11
|
-
// sandboxes with no conformance label, which another user of the account made during the run (a server's computers):
|
|
12
|
-
// never touched. A sandbox in <file> is never touched either: no call names it. Exit 0 when every swept sandbox reads
|
|
13
|
-
// back 404, 1 when one is still there, 2 on a usage error, a before file it cannot read, a missing key or a listing
|
|
14
|
-
// Daytona refused (nothing is deleted then).
|
|
15
|
-
import { readFileSync, writeFileSync } from "node:fs";
|
|
16
|
-
import { COMPUTER_LABEL } from "../drift.js";
|
|
17
|
-
import { isCommand } from "../entry.js";
|
|
18
|
-
import { waitUntil } from "../wait.js";
|
|
19
|
-
import { createProvider } from "./daytona.js";
|
|
20
|
-
import { RUN_LABEL } from "./runner.js";
|
|
21
|
-
const USAGE = `usage: node packages/computer/dist/conformance/daytona-sweep.js --before <file> | --after <file>
|
|
22
|
-
--before <file> record the id of every sandbox carrying ${COMPUTER_LABEL}=1 into <file>
|
|
23
|
-
--after <file> delete every sandbox carrying ${COMPUTER_LABEL}=1 and ${RUN_LABEL} whose id is not in <file>, read
|
|
24
|
-
each back until Daytona answers 404 (up to 60 s each), and print
|
|
25
|
-
{"swept":n,"notFound":m,"stillThere":[ids],"leftAlone":k}; a new one with no ${RUN_LABEL} is left alone
|
|
26
|
-
settings: COMPUTER_DAYTONA_API_KEY (required) and COMPUTER_DAYTONA_API_URL, as the conformance module reads them
|
|
27
|
-
exit: 0 every swept sandbox is gone, 1 one is still there, 2 usage error, unreadable before file, no key, or a refused listing`;
|
|
28
|
-
class Usage extends Error {
|
|
29
|
-
}
|
|
30
|
-
const write = (stream, text) => new Promise((resolve) => void stream.write(text, () => resolve()));
|
|
31
|
-
function parse(argv) {
|
|
32
|
-
let found;
|
|
33
|
-
for (let i = 0; i < argv.length; i++) {
|
|
34
|
-
const [flag = "", inline] = (argv[i] ?? "").split(/=(.*)/s, 2);
|
|
35
|
-
if (flag !== "--before" && flag !== "--after")
|
|
36
|
-
throw new Usage(`unknown option ${flag}`);
|
|
37
|
-
const file = inline ?? argv[++i];
|
|
38
|
-
if (file === undefined || file === "" || file.startsWith("--"))
|
|
39
|
-
throw new Usage(`${flag} needs a file`);
|
|
40
|
-
if (found !== undefined)
|
|
41
|
-
throw new Usage("give --before <file> or --after <file>, one of them");
|
|
42
|
-
found = { mode: flag === "--before" ? "before" : "after", file };
|
|
43
|
-
}
|
|
44
|
-
if (found === undefined)
|
|
45
|
-
throw new Usage("give --before <file> or --after <file>, one of them");
|
|
46
|
-
return found;
|
|
47
|
-
}
|
|
48
|
-
/** The ids a before file holds, or why it is not one. */
|
|
49
|
-
function beforeIds(file) {
|
|
50
|
-
let text;
|
|
51
|
-
try {
|
|
52
|
-
text = readFileSync(file, "utf8");
|
|
53
|
-
}
|
|
54
|
-
catch (error) {
|
|
55
|
-
throw new Usage(`cannot read the before file ${file}: ${error.message}`);
|
|
56
|
-
}
|
|
57
|
-
let record;
|
|
58
|
-
try {
|
|
59
|
-
record = JSON.parse(text);
|
|
60
|
-
}
|
|
61
|
-
catch {
|
|
62
|
-
record = undefined;
|
|
63
|
-
}
|
|
64
|
-
const ids = record?.ids;
|
|
65
|
-
if (!Array.isArray(ids) || !ids.every((id) => typeof id === "string" && id !== ""))
|
|
66
|
-
throw new Usage(`${file} is not a before file: it holds no "ids" array of sandbox ids`);
|
|
67
|
-
return new Set(ids);
|
|
68
|
-
}
|
|
69
|
-
export async function main(argv, io = {}) {
|
|
70
|
-
const { env = process.env, stdout = process.stdout, stderr = process.stderr, waitMs = 60_000, pollMs = 2_000 } = io;
|
|
71
|
-
let args;
|
|
72
|
-
let before;
|
|
73
|
-
let provider;
|
|
74
|
-
try {
|
|
75
|
-
args = parse(argv);
|
|
76
|
-
if (args.mode === "after")
|
|
77
|
-
before = beforeIds(args.file);
|
|
78
|
-
// A release waits for the sandbox to go, for as long as the sweep's own wait.
|
|
79
|
-
provider = createProvider({ env, timeouts: { goneMs: waitMs, pollMs }, ...(io.fetch ? { fetch: io.fetch } : {}), ...(io.webSocket ? { webSocket: io.webSocket } : {}) });
|
|
80
|
-
}
|
|
81
|
-
catch (error) {
|
|
82
|
-
await write(stderr, `${error.message}\n${error instanceof Usage ? `${USAGE}\n` : ""}`);
|
|
83
|
-
return 2;
|
|
84
|
-
}
|
|
85
|
-
const listed = await provider.listLabelled();
|
|
86
|
-
if (!listed.ok) {
|
|
87
|
-
await write(stderr, `listing the sandboxes carrying ${COMPUTER_LABEL}=1 failed, so nothing was ${args.mode === "after" ? "deleted" : "recorded"}: ${listed.error.message}\n`);
|
|
88
|
-
return 2;
|
|
89
|
-
}
|
|
90
|
-
if (before === undefined) {
|
|
91
|
-
const ids = [...new Set(listed.value.map((sb) => sb.id))].sort();
|
|
92
|
-
writeFileSync(args.file, `${JSON.stringify({ label: `${COMPUTER_LABEL}=1`, at: new Date().toISOString(), ids }, null, 2)}\n`);
|
|
93
|
-
await write(stdout, `${JSON.stringify({ recorded: ids.length, file: args.file })}\n`);
|
|
94
|
-
return 0;
|
|
95
|
-
}
|
|
96
|
-
const known = before;
|
|
97
|
-
const added = [...new Map(listed.value.filter((sb) => !known.has(sb.id)).map((sb) => [sb.id, sb])).values()];
|
|
98
|
-
// Only a conformance run's computers: one another user of the account made during the run is not this sweep's.
|
|
99
|
-
const fresh = added.filter((sb) => Object.hasOwn(sb.labels, RUN_LABEL));
|
|
100
|
-
const leftAlone = added.length - fresh.length;
|
|
101
|
-
for (const sb of fresh) {
|
|
102
|
-
const released = await provider.release({ id: sb.id, name: sb.name ?? "" }, "delete");
|
|
103
|
-
if (!released.ok)
|
|
104
|
-
await write(stderr, `${sb.id} (${sb.name ?? "no name"}) was not deleted: ${released.error.message}\n`);
|
|
105
|
-
}
|
|
106
|
-
// Each one read back on its own, at once, through waitUntil: a 404 is gone; anything else, or no answer, is read
|
|
107
|
-
// again every pollMs until its wait ends.
|
|
108
|
-
const gone = await Promise.all(fresh.map(async (sb) => {
|
|
109
|
-
const waited = await waitUntil(() => provider.probe(sb.id), (read) => read.ok && read.value.status === 404, {
|
|
110
|
-
boundMs: waitMs,
|
|
111
|
-
minMs: pollMs,
|
|
112
|
-
maxMs: pollMs,
|
|
113
|
-
what: `${sb.id} to be gone`,
|
|
114
|
-
describe: (read) => `GET /sandbox/${sb.id} answered ${read.ok ? `${read.value.status}${read.value.state ? ` (${read.value.state})` : ""}` : read.error.message}`,
|
|
115
|
-
});
|
|
116
|
-
if (!waited.ok)
|
|
117
|
-
await write(stderr, `${sb.id} is still there: ${waited.error.message}\n`);
|
|
118
|
-
return waited.ok;
|
|
119
|
-
}));
|
|
120
|
-
const stillThere = fresh.filter((_, i) => !gone[i]).map((sb) => sb.id);
|
|
121
|
-
await write(stdout, `${JSON.stringify({ swept: fresh.length, notFound: fresh.length - stillThere.length, stillThere, leftAlone })}\n`);
|
|
122
|
-
return stillThere.length === 0 ? 0 : 1;
|
|
123
|
-
}
|
|
124
|
-
if (isCommand(import.meta)) {
|
|
125
|
-
process.exitCode = await main(process.argv.slice(2));
|
|
126
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { type E2BOptions } from "../e2b.js";
|
|
2
|
-
/** A stream as main writes to it: done is called once the text is handed on. */
|
|
3
|
-
export interface Writer {
|
|
4
|
-
write(text: string, done?: (error?: Error | null) => void): unknown;
|
|
5
|
-
}
|
|
6
|
-
export interface DiagnoseIo extends Pick<E2BOptions, "Sandbox" | "daemonPath" | "timeouts"> {
|
|
7
|
-
/** Where the settings are read; default process.env. */
|
|
8
|
-
env?: Record<string, string | undefined>;
|
|
9
|
-
stdout?: Writer;
|
|
10
|
-
stderr?: Writer;
|
|
11
|
-
/** Aborts the diagnostic: the sandbox is still killed and read back gone. */
|
|
12
|
-
signal?: AbortSignal;
|
|
13
|
-
/** The longest the diagnostic runs before it aborts itself; default 8 minutes, inside the sandbox's 10. */
|
|
14
|
-
boundMs?: number;
|
|
15
|
-
}
|
|
16
|
-
export declare function main(argv: string[], io?: DiagnoseIo): Promise<number>;
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
// The E2B network diagnostic, run once by hand with a key the lead has OKed:
|
|
2
|
-
//
|
|
3
|
-
// AGENTRUN_COMPUTER_LIVE_E2B=1 COMPUTER_E2B_API_KEY=... node packages/computer/dist/conformance/e2b-diagnose.js
|
|
4
|
-
//
|
|
5
|
-
// E2B documents that its firewall accepts an outbound TCP connection before it decides whether the destination is
|
|
6
|
-
// allowed, so from inside a sandbox with no internet access a connection can succeed while nothing reaches the
|
|
7
|
-
// destination (docs.e2b.dev network/internet-access, "Behavior of blocked TCP connections"). The provider's network-none
|
|
8
|
-
// probe refuses only on an answer and records an accept with nothing back in its notes. This makes ONE sandbox exactly as the provider makes one for network
|
|
9
|
-
// none (diagnoseNetworkNone in ../e2b.ts: the same create options, read-back, upload and sha256 check), runs
|
|
10
|
-
// `computerd probe --diagnose` in it (per well-known public address and port: refused, accepted with no answer, or
|
|
11
|
-
// answered), prints one JSON line, then kills the sandbox and reads it back gone, on an error and on an abort (SIGINT,
|
|
12
|
-
// SIGTERM, or the run's own 8-minute bound) too. Its E2B timeout is 10 minutes. It changes nothing in the provider.
|
|
13
|
-
//
|
|
14
|
-
// Settings are the conformance module's (COMPUTER_E2B_API_KEY, COMPUTER_E2B_DOMAIN, COMPUTER_E2B_KIND,
|
|
15
|
-
// COMPUTER_E2B_DAEMON and the rest settingsFromEnv reads; never E2B_API_KEY), passed to the provider's create(), and the
|
|
16
|
-
// template is COMPUTER_E2B_TEMPLATE as for conformance (default "desktop"). The live switch is checked before any of
|
|
17
|
-
// them is read. Exit 0 when a diagnosis came back and the sandbox reads gone, 1 otherwise, 2 on a usage error, no live
|
|
18
|
-
// switch, or a setting the provider refuses (nothing is made then).
|
|
19
|
-
import { create, diagnoseNetworkNone } from "../e2b.js";
|
|
20
|
-
import { isCommand } from "../entry.js";
|
|
21
|
-
import { conformanceImage, E2B_ENV, settingsFromEnv } from "./e2b.js";
|
|
22
|
-
const USAGE = `usage: ${E2B_ENV.live}=1 ${E2B_ENV.key}=<key> node packages/computer/dist/conformance/e2b-diagnose.js
|
|
23
|
-
makes one E2B sandbox as the provider makes one for network none, runs computerd probe --diagnose in it, prints one
|
|
24
|
-
JSON line, and kills the sandbox and reads it back gone. It takes no argument; the template is ${E2B_ENV.template}.
|
|
25
|
-
exit: 0 diagnosed and gone, 1 otherwise, 2 usage error, no live switch, or a refused setting`;
|
|
26
|
-
const BOUND_MS = 8 * 60_000;
|
|
27
|
-
const write = (stream, text) => new Promise((resolve) => void stream.write(text, () => resolve()));
|
|
28
|
-
export async function main(argv, io = {}) {
|
|
29
|
-
const { env = process.env, stdout = process.stdout, stderr = process.stderr, boundMs = BOUND_MS } = io;
|
|
30
|
-
if (env[E2B_ENV.live] !== "1") {
|
|
31
|
-
await write(stderr, `the E2B network diagnostic makes a real sandbox: set ${E2B_ENV.live}=1, with a key the lead has OKed, to run it\n`);
|
|
32
|
-
return 2;
|
|
33
|
-
}
|
|
34
|
-
if (argv.length > 0) {
|
|
35
|
-
await write(stderr, `it takes no argument, not ${argv.join(" ")}\n${USAGE}\n`);
|
|
36
|
-
return 2;
|
|
37
|
-
}
|
|
38
|
-
const key = env[E2B_ENV.key] ?? "";
|
|
39
|
-
// Nothing the SDK or E2B says reaches an output with the key in it.
|
|
40
|
-
const clean = (text) => (key === "" ? text : text.split(key).join("[key]"));
|
|
41
|
-
let provider;
|
|
42
|
-
try {
|
|
43
|
-
provider = await create({ ...settingsFromEnv(env), ...(io.Sandbox ? { Sandbox: io.Sandbox } : {}), ...(io.daemonPath === undefined ? {} : { daemonPath: io.daemonPath }), ...(io.timeouts ? { timeouts: io.timeouts } : {}) });
|
|
44
|
-
}
|
|
45
|
-
catch (error) {
|
|
46
|
-
await write(stderr, `${clean(error.message)}\n`);
|
|
47
|
-
return 2;
|
|
48
|
-
}
|
|
49
|
-
const signal = AbortSignal.any([AbortSignal.timeout(boundMs), ...(io.signal ? [io.signal] : [])]);
|
|
50
|
-
const report = await diagnoseNetworkNone(provider, { image: conformanceImage({ env }), signal });
|
|
51
|
-
await write(stdout, `${clean(JSON.stringify(report))}\n`);
|
|
52
|
-
if (!report.released.gone)
|
|
53
|
-
await write(stderr, `the sandbox was not read back gone: ${clean(report.released.words)}\n`);
|
|
54
|
-
return report.diagnosis !== undefined && report.released.gone ? 0 : 1;
|
|
55
|
-
}
|
|
56
|
-
if (isCommand(import.meta)) {
|
|
57
|
-
const controller = new AbortController();
|
|
58
|
-
for (const name of ["SIGINT", "SIGTERM"])
|
|
59
|
-
process.once(name, () => controller.abort());
|
|
60
|
-
process.exitCode = await main(process.argv.slice(2), { signal: controller.signal });
|
|
61
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { type E2BSandboxClass } from "../e2b.js";
|
|
2
|
-
/** A stream as main writes to it: done is called once the text is handed on. */
|
|
3
|
-
export interface Writer {
|
|
4
|
-
write(text: string, done?: (error?: Error | null) => void): unknown;
|
|
5
|
-
}
|
|
6
|
-
export interface SweepIo {
|
|
7
|
-
/** Where the settings are read; default process.env. */
|
|
8
|
-
env?: Record<string, string | undefined>;
|
|
9
|
-
/** The SDK's Sandbox class; imported from the host's e2b package by default. */
|
|
10
|
-
Sandbox?: E2BSandboxClass;
|
|
11
|
-
stdout?: Writer;
|
|
12
|
-
stderr?: Writer;
|
|
13
|
-
/** How long --after reads one killed sandbox back before it counts as still there; default 60 s. */
|
|
14
|
-
waitMs?: number;
|
|
15
|
-
/** The pause between two reads of one sandbox; default 2 s. */
|
|
16
|
-
pollMs?: number;
|
|
17
|
-
}
|
|
18
|
-
export declare function main(argv: string[], io?: SweepIo): Promise<number>;
|
|
@@ -1,132 +0,0 @@
|
|
|
1
|
-
// The sweep around a live E2B run, with the provider's settings (COMPUTER_E2B_*, never E2B_*):
|
|
2
|
-
//
|
|
3
|
-
// node packages/computer/dist/conformance/e2b-sweep.js --before <file>
|
|
4
|
-
// node packages/computer/dist/conformance/e2b-sweep.js --after <file>
|
|
5
|
-
//
|
|
6
|
-
// --before records into <file> the id of every sandbox E2B lists with the provider's label agentrun.computer=1
|
|
7
|
-
// (Sandbox.list with that metadata, running and paused ones: e2b@2.63.0 dist/index.mjs:5974-5986, 5793-5835). --after
|
|
8
|
-
// lists them again, kills (Sandbox.kill) every one whose id is not in <file> and whose metadata carries a conformance
|
|
9
|
-
// run's label (agentrun.conformance, RUN_LABEL), then reads each of those back with getInfo until E2B no longer has it
|
|
10
|
-
// (SandboxNotFoundError, index.mjs:5431) and no longer lists it, up to 60 s each, and prints one JSON line,
|
|
11
|
-
// {"swept":n,"gone":m,"stillThere":[ids],"leftAlone":k}: swept is every conformance sandbox it found that was not there
|
|
12
|
-
// before, gone + stillThere.length = swept, and leftAlone counts the new labelled sandboxes with no conformance label,
|
|
13
|
-
// which another user of the account made during the run: never touched. A sandbox in <file> is never touched either:
|
|
14
|
-
// no call names it. Exit 0 when every swept sandbox is gone, 1 when one is still there, 2 on a usage error, a before
|
|
15
|
-
// file it cannot read, a missing key, or a listing E2B refused (nothing is killed then).
|
|
16
|
-
//
|
|
17
|
-
// It reads COMPUTER_E2B_API_KEY and COMPUTER_E2B_DOMAIN as the conformance module does (settingsFromEnv in ./e2b.ts)
|
|
18
|
-
// and builds the provider with create(): the key passed to every SDK call explicitly, an ambient E2B_SANDBOX_URL
|
|
19
|
-
// refused. It needs no AGENTRUN_COMPUTER_LIVE_E2B: it makes nothing.
|
|
20
|
-
import { readFileSync, writeFileSync } from "node:fs";
|
|
21
|
-
import { COMPUTER_LABEL } from "../drift.js";
|
|
22
|
-
import { create } from "../e2b.js";
|
|
23
|
-
import { isCommand } from "../entry.js";
|
|
24
|
-
import { E2B_ENV as ENV, settingsFromEnv } from "./e2b.js";
|
|
25
|
-
import { RUN_LABEL } from "./runner.js";
|
|
26
|
-
import { waitUntil } from "../wait.js";
|
|
27
|
-
const USAGE = `usage: node packages/computer/dist/conformance/e2b-sweep.js --before <file> | --after <file>
|
|
28
|
-
--before <file> record the id of every sandbox E2B lists with ${COMPUTER_LABEL}=1 into <file>
|
|
29
|
-
--after <file> kill every sandbox listed with ${COMPUTER_LABEL}=1 and ${RUN_LABEL} whose id is not in <file>, read
|
|
30
|
-
each back until E2B no longer has it (up to 60 s each), and print
|
|
31
|
-
{"swept":n,"gone":m,"stillThere":[ids],"leftAlone":k}; a new one with no ${RUN_LABEL} is left alone
|
|
32
|
-
settings: ${ENV.key} (required) and ${ENV.domain}, as the conformance module reads them; never E2B_API_KEY
|
|
33
|
-
exit: 0 every swept sandbox is gone, 1 one is still there, 2 usage error, unreadable before file, no key, or a refused listing`;
|
|
34
|
-
class Usage extends Error {
|
|
35
|
-
}
|
|
36
|
-
const write = (stream, text) => new Promise((resolve) => void stream.write(text, () => resolve()));
|
|
37
|
-
function parse(argv) {
|
|
38
|
-
let found;
|
|
39
|
-
for (let i = 0; i < argv.length; i++) {
|
|
40
|
-
const [flag = "", inline] = (argv[i] ?? "").split(/=(.*)/s, 2);
|
|
41
|
-
if (flag !== "--before" && flag !== "--after")
|
|
42
|
-
throw new Usage(`unknown option ${flag}`);
|
|
43
|
-
const file = inline ?? argv[++i];
|
|
44
|
-
if (file === undefined || file === "" || file.startsWith("--"))
|
|
45
|
-
throw new Usage(`${flag} needs a file`);
|
|
46
|
-
if (found !== undefined)
|
|
47
|
-
throw new Usage("give --before <file> or --after <file>, one of them");
|
|
48
|
-
found = { mode: flag === "--before" ? "before" : "after", file };
|
|
49
|
-
}
|
|
50
|
-
if (found === undefined)
|
|
51
|
-
throw new Usage("give --before <file> or --after <file>, one of them");
|
|
52
|
-
return found;
|
|
53
|
-
}
|
|
54
|
-
/** The ids a before file holds, or why it is not one. */
|
|
55
|
-
function beforeIds(file) {
|
|
56
|
-
let text;
|
|
57
|
-
try {
|
|
58
|
-
text = readFileSync(file, "utf8");
|
|
59
|
-
}
|
|
60
|
-
catch (error) {
|
|
61
|
-
throw new Usage(`cannot read the before file ${file}: ${error.message}`);
|
|
62
|
-
}
|
|
63
|
-
let record;
|
|
64
|
-
try {
|
|
65
|
-
record = JSON.parse(text);
|
|
66
|
-
}
|
|
67
|
-
catch {
|
|
68
|
-
record = undefined;
|
|
69
|
-
}
|
|
70
|
-
const ids = record?.ids;
|
|
71
|
-
if (!Array.isArray(ids) || !ids.every((id) => typeof id === "string" && id !== ""))
|
|
72
|
-
throw new Usage(`${file} is not a before file: it holds no "ids" array of sandbox ids`);
|
|
73
|
-
return new Set(ids);
|
|
74
|
-
}
|
|
75
|
-
export async function main(argv, io = {}) {
|
|
76
|
-
const { env = process.env, stdout = process.stdout, stderr = process.stderr, waitMs = 60_000, pollMs = 2_000 } = io;
|
|
77
|
-
let args;
|
|
78
|
-
let before;
|
|
79
|
-
let provider;
|
|
80
|
-
try {
|
|
81
|
-
args = parse(argv);
|
|
82
|
-
if (args.mode === "after")
|
|
83
|
-
before = beforeIds(args.file);
|
|
84
|
-
provider = await create({ ...settingsFromEnv(env), ...(io.Sandbox ? { Sandbox: io.Sandbox } : {}), timeouts: { goneMs: waitMs, pollMs } });
|
|
85
|
-
}
|
|
86
|
-
catch (error) {
|
|
87
|
-
await write(stderr, `${error.message}\n${error instanceof Usage ? `${USAGE}\n` : ""}`);
|
|
88
|
-
return 2;
|
|
89
|
-
}
|
|
90
|
-
const listed = await provider.listLabelled();
|
|
91
|
-
if (!listed.ok) {
|
|
92
|
-
await write(stderr, `listing the sandboxes carrying ${COMPUTER_LABEL}=1 failed, so nothing was ${args.mode === "after" ? "killed" : "recorded"}: ${listed.error.message}\n`);
|
|
93
|
-
return 2;
|
|
94
|
-
}
|
|
95
|
-
if (before === undefined) {
|
|
96
|
-
const ids = listed.value.map((sb) => sb.id).sort();
|
|
97
|
-
writeFileSync(args.file, `${JSON.stringify({ label: `${COMPUTER_LABEL}=1`, at: new Date().toISOString(), ids }, null, 2)}\n`);
|
|
98
|
-
await write(stdout, `${JSON.stringify({ recorded: ids.length, file: args.file })}\n`);
|
|
99
|
-
return 0;
|
|
100
|
-
}
|
|
101
|
-
const known = before;
|
|
102
|
-
const added = listed.value.filter((sb) => !known.has(sb.id));
|
|
103
|
-
// Only a conformance run's computers: one another user of the account made during the run is not this sweep's.
|
|
104
|
-
const fresh = added.filter((sb) => Object.hasOwn(sb.labels, RUN_LABEL)).map((sb) => sb.id);
|
|
105
|
-
const leftAlone = added.length - fresh.length;
|
|
106
|
-
for (const id of fresh) {
|
|
107
|
-
const killed = await provider.killById(id);
|
|
108
|
-
if (!killed.ok)
|
|
109
|
-
await write(stderr, `${id} was not killed: ${killed.error.message}\n`);
|
|
110
|
-
}
|
|
111
|
-
// Each read back on its own, at once: gone once getInfo no longer finds it and the label listing no longer shows it.
|
|
112
|
-
const gone = await Promise.all(fresh.map(async (id) => {
|
|
113
|
-
const waited = await waitUntil(async () => {
|
|
114
|
-
const read = await provider.probeGone(id);
|
|
115
|
-
if (!read.ok || !read.value.gone)
|
|
116
|
-
return read.ok ? `E2B reads it ${read.value.state}` : read.error.message;
|
|
117
|
-
const again = await provider.listLabelled();
|
|
118
|
-
if (!again.ok)
|
|
119
|
-
return again.error.message;
|
|
120
|
-
return again.value.some((sb) => sb.id === id) ? "still listed" : "gone";
|
|
121
|
-
}, (state) => state === "gone", { boundMs: waitMs, minMs: pollMs, maxMs: pollMs, what: `${id} to be gone after its kill`, describe: (state) => state });
|
|
122
|
-
if (!waited.ok)
|
|
123
|
-
await write(stderr, `${id} is still there after ${waitMs / 1000} s: ${waited.error.message}\n`);
|
|
124
|
-
return waited.ok;
|
|
125
|
-
}));
|
|
126
|
-
const stillThere = fresh.filter((_, i) => !gone[i]);
|
|
127
|
-
await write(stdout, `${JSON.stringify({ swept: fresh.length, gone: fresh.length - stillThere.length, stillThere, leftAlone })}\n`);
|
|
128
|
-
return stillThere.length === 0 ? 0 : 1;
|
|
129
|
-
}
|
|
130
|
-
if (isCommand(import.meta)) {
|
|
131
|
-
process.exitCode = await main(process.argv.slice(2));
|
|
132
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { type ModalClientConstructor } from "../modal.js";
|
|
2
|
-
/** A stream as main writes to it: done is called once the text is handed on. */
|
|
3
|
-
export interface Writer {
|
|
4
|
-
write(text: string, done?: (error?: Error | null) => void): unknown;
|
|
5
|
-
}
|
|
6
|
-
export interface SweepIo {
|
|
7
|
-
/** Where the settings are read; default process.env. */
|
|
8
|
-
env?: Record<string, string | undefined>;
|
|
9
|
-
/** The SDK's ModalClient; imported from the host's modal package by default. */
|
|
10
|
-
ModalClient?: ModalClientConstructor;
|
|
11
|
-
stdout?: Writer;
|
|
12
|
-
stderr?: Writer;
|
|
13
|
-
/** How long --after reads one terminated sandbox back before it counts as still there; default 60 s. */
|
|
14
|
-
waitMs?: number;
|
|
15
|
-
/** The pause between two reads of one sandbox; default 2 s. */
|
|
16
|
-
pollMs?: number;
|
|
17
|
-
/** One SDK call (apps.fromName, fromId, terminate, poll); default 60 s. */
|
|
18
|
-
callMs?: number;
|
|
19
|
-
/** The whole listing, every page; default 120 s. */
|
|
20
|
-
listMs?: number;
|
|
21
|
-
}
|
|
22
|
-
export declare function main(argv: string[], io?: SweepIo): Promise<number>;
|