@parcha/agentrun-computer 0.0.0-stage → 0.1.0-beta.33
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/LICENSE +202 -0
- package/NOTICE +8 -0
- package/README.md +2411 -2
- package/box/Dockerfile +69 -0
- package/box/agentrun-archil +168 -0
- package/box/build-daytona.py +26 -0
- package/box/build-e2b.mjs +32 -0
- package/box/build-modal.py +17 -0
- package/dist/actions.d.ts +18 -0
- package/dist/actions.js +139 -0
- package/dist/browser.d.ts +151 -0
- package/dist/browser.js +305 -0
- package/dist/browserbase.d.ts +139 -0
- package/dist/browserbase.js +408 -0
- package/dist/child.d.ts +40 -0
- package/dist/child.js +127 -0
- package/dist/client.d.ts +22 -0
- package/dist/client.js +136 -0
- package/dist/computerd-linux-amd64 +0 -0
- package/dist/computerd-linux-arm64 +0 -0
- package/dist/conformance/archil.d.ts +68 -0
- package/dist/conformance/archil.js +152 -0
- package/dist/conformance/browserbase.d.ts +35 -0
- package/dist/conformance/browserbase.js +45 -0
- package/dist/conformance/cases/apps.d.ts +2 -0
- package/dist/conformance/cases/apps.js +155 -0
- package/dist/conformance/cases/browser.d.ts +4 -0
- package/dist/conformance/cases/browser.js +105 -0
- package/dist/conformance/cases/drift.d.ts +2 -0
- package/dist/conformance/cases/drift.js +64 -0
- package/dist/conformance/cases/exec.d.ts +2 -0
- package/dist/conformance/cases/exec.js +125 -0
- package/dist/conformance/cases/files.d.ts +2 -0
- package/dist/conformance/cases/files.js +294 -0
- package/dist/conformance/cases/health.d.ts +2 -0
- package/dist/conformance/cases/health.js +71 -0
- package/dist/conformance/cases/index.d.ts +9 -0
- package/dist/conformance/cases/index.js +37 -0
- package/dist/conformance/cases/input.d.ts +12 -0
- package/dist/conformance/cases/input.js +109 -0
- package/dist/conformance/cases/isolation.d.ts +21 -0
- package/dist/conformance/cases/isolation.js +98 -0
- package/dist/conformance/cases/lifetime.d.ts +2 -0
- package/dist/conformance/cases/lifetime.js +64 -0
- package/dist/conformance/cases/mount.d.ts +2 -0
- package/dist/conformance/cases/mount.js +252 -0
- package/dist/conformance/cases/process.d.ts +2 -0
- package/dist/conformance/cases/process.js +240 -0
- package/dist/conformance/cases/provider.d.ts +2 -0
- package/dist/conformance/cases/provider.js +302 -0
- package/dist/conformance/cases/screen.d.ts +9 -0
- package/dist/conformance/cases/screen.js +230 -0
- package/dist/conformance/cases/settings.d.ts +57 -0
- package/dist/conformance/cases/settings.js +142 -0
- package/dist/conformance/cases/touch.d.ts +2 -0
- package/dist/conformance/cases/touch.js +117 -0
- package/dist/conformance/cases/util.d.ts +7 -0
- package/dist/conformance/cases/util.js +8 -0
- package/dist/conformance/cdp.d.ts +13 -0
- package/dist/conformance/cdp.js +88 -0
- package/dist/conformance/cli.d.ts +29 -0
- package/dist/conformance/cli.js +231 -0
- package/dist/conformance/daytona-sweep.d.ts +18 -0
- package/dist/conformance/daytona-sweep.js +126 -0
- package/dist/conformance/daytona.d.ts +83 -0
- package/dist/conformance/daytona.js +107 -0
- package/dist/conformance/docker.d.ts +38 -0
- package/dist/conformance/docker.js +70 -0
- package/dist/conformance/drift-daemon.d.ts +8 -0
- package/dist/conformance/drift-daemon.js +41 -0
- package/dist/conformance/e2b-diagnose.d.ts +16 -0
- package/dist/conformance/e2b-diagnose.js +61 -0
- package/dist/conformance/e2b-sweep.d.ts +18 -0
- package/dist/conformance/e2b-sweep.js +132 -0
- package/dist/conformance/e2b.d.ts +74 -0
- package/dist/conformance/e2b.js +111 -0
- package/dist/conformance/fixture.d.ts +65 -0
- package/dist/conformance/fixture.js +98 -0
- package/dist/conformance/index.d.ts +8 -0
- package/dist/conformance/index.js +8 -0
- package/dist/conformance/kernel.d.ts +31 -0
- package/dist/conformance/kernel.js +40 -0
- package/dist/conformance/kind.d.ts +23 -0
- package/dist/conformance/kind.js +58 -0
- package/dist/conformance/modal-sweep.d.ts +22 -0
- package/dist/conformance/modal-sweep.js +213 -0
- package/dist/conformance/modal.d.ts +69 -0
- package/dist/conformance/modal.js +76 -0
- package/dist/conformance/orgo.d.ts +41 -0
- package/dist/conformance/orgo.js +69 -0
- package/dist/conformance/phone-harness.d.ts +61 -0
- package/dist/conformance/phone-harness.js +241 -0
- package/dist/conformance/png.d.ts +16 -0
- package/dist/conformance/png.js +132 -0
- package/dist/conformance/report.d.ts +2 -0
- package/dist/conformance/report.js +86 -0
- package/dist/conformance/runner.d.ts +11 -0
- package/dist/conformance/runner.js +585 -0
- package/dist/conformance/tar.d.ts +13 -0
- package/dist/conformance/tar.js +105 -0
- package/dist/conformance/types.d.ts +257 -0
- package/dist/conformance/types.js +24 -0
- package/dist/daemon-copy.d.ts +40 -0
- package/dist/daemon-copy.js +259 -0
- package/dist/daytona.d.ts +180 -0
- package/dist/daytona.js +1498 -0
- package/dist/desktop.d.ts +24 -0
- package/dist/desktop.js +68 -0
- package/dist/docker/egress-main.d.ts +1 -0
- package/dist/docker/egress-main.js +68 -0
- package/dist/docker/egress-proxy.d.ts +53 -0
- package/dist/docker/egress-proxy.js +450 -0
- package/dist/docker/egress-table.d.ts +39 -0
- package/dist/docker/egress-table.js +197 -0
- package/dist/docker/egress.d.ts +109 -0
- package/dist/docker/egress.js +318 -0
- package/dist/docker/image.d.ts +49 -0
- package/dist/docker/image.js +302 -0
- package/dist/docker/stage.d.ts +21 -0
- package/dist/docker/stage.js +290 -0
- package/dist/docker/volume.d.ts +24 -0
- package/dist/docker/volume.js +67 -0
- package/dist/docker.d.ts +156 -0
- package/dist/docker.js +1277 -0
- package/dist/drift.d.ts +200 -0
- package/dist/drift.js +416 -0
- package/dist/e2b.d.ts +337 -0
- package/dist/e2b.js +1516 -0
- package/dist/entry.d.ts +2 -0
- package/dist/entry.js +24 -0
- package/dist/files.d.ts +50 -0
- package/dist/files.js +208 -0
- package/dist/index.d.ts +27 -0
- package/dist/index.js +26 -0
- package/dist/isolation.d.ts +29 -0
- package/dist/isolation.js +71 -0
- package/dist/janitor.d.ts +50 -0
- package/dist/janitor.js +135 -0
- package/dist/kernel.d.ts +113 -0
- package/dist/kernel.js +358 -0
- package/dist/kinds.d.ts +79 -0
- package/dist/kinds.js +133 -0
- package/dist/labels.d.ts +23 -0
- package/dist/labels.js +50 -0
- package/dist/modal.d.ts +302 -0
- package/dist/modal.js +1374 -0
- package/dist/mount-archil.d.ts +164 -0
- package/dist/mount-archil.js +471 -0
- package/dist/mount.d.ts +57 -0
- package/dist/mount.js +104 -0
- package/dist/orgo-channel.d.ts +96 -0
- package/dist/orgo-channel.js +391 -0
- package/dist/orgo.d.ts +139 -0
- package/dist/orgo.js +1006 -0
- package/dist/phone-harness.d.ts +185 -0
- package/dist/phone-harness.js +1420 -0
- package/dist/processes.d.ts +24 -0
- package/dist/processes.js +40 -0
- package/dist/protocol.d.ts +729 -0
- package/dist/protocol.js +54 -0
- package/dist/provider.d.ts +245 -0
- package/dist/provider.js +37 -0
- package/dist/providers.d.ts +68 -0
- package/dist/providers.js +25 -0
- package/dist/result.d.ts +15 -0
- package/dist/result.js +2 -0
- package/dist/screen-watch.d.ts +150 -0
- package/dist/screen-watch.js +490 -0
- package/dist/test-connection.d.ts +17 -0
- package/dist/test-connection.js +26 -0
- package/dist/wait.d.ts +23 -0
- package/dist/wait.js +65 -0
- package/package.json +62 -4
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
// Conformance by kind: the cases a setting kind runs, and whether a provider passes it. One table with the registry
|
|
2
|
+
// (src/kinds.ts): a kind's cases are those whose protocol groups it requires or allows, and a provider passes the kind
|
|
3
|
+
// only when it serves it and every case of each required group passes, at least one of them.
|
|
4
|
+
import { SETTING_KIND_NAMES, SETTING_KINDS, servingRefusals } from "../kinds.js";
|
|
5
|
+
import { GROUPS } from "../protocol.js";
|
|
6
|
+
import { casesFor } from "./cases/index.js";
|
|
7
|
+
const groupsOf = (c) => c.needs.filter((need) => GROUPS.includes(need));
|
|
8
|
+
/** Why a run cannot be by this kind, in words; undefined when it can. Kind none is no computer. */
|
|
9
|
+
export function kindRunProblem(kind) {
|
|
10
|
+
const spec = Object.hasOwn(SETTING_KINDS, kind) ? SETTING_KINDS[kind] : undefined;
|
|
11
|
+
if (spec === undefined)
|
|
12
|
+
return `${JSON.stringify(kind)} is not a setting kind: ${SETTING_KIND_NAMES.join(", ")}`;
|
|
13
|
+
if (spec.machineKinds.length === 0)
|
|
14
|
+
return `kind ${kind} is no computer: there is nothing to run its cases on`;
|
|
15
|
+
return undefined;
|
|
16
|
+
}
|
|
17
|
+
/** The cases a kind draws from when it is given none: a browser kind the browser cases, any other the suite's. */
|
|
18
|
+
const suiteOf = (kind) => casesFor(Object.hasOwn(SETTING_KINDS, kind) && SETTING_KINDS[kind].machineKinds.includes("browser") ? "browser" : undefined);
|
|
19
|
+
/**
|
|
20
|
+
* The cases a kind runs: each whose protocol groups the kind requires or allows, those that need no group (health,
|
|
21
|
+
* provider, drift) among them. None for kind none. Drawn from cases, by default the kind's suite (casesFor).
|
|
22
|
+
*/
|
|
23
|
+
export function kindCases(kind, cases = suiteOf(kind)) {
|
|
24
|
+
if (kindRunProblem(kind) !== undefined)
|
|
25
|
+
return [];
|
|
26
|
+
const allowed = [...SETTING_KINDS[kind].required, ...SETTING_KINDS[kind].optional];
|
|
27
|
+
return cases.filter((c) => groupsOf(c).every((group) => allowed.includes(group)));
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Whether the provider whose capabilities these are passes the kind, by the run's report and its cases (the kind's): it
|
|
31
|
+
* serves the kind; no case of the run failed (a declared optional group that fails would give a loop a broken tool);
|
|
32
|
+
* for each required group, at least one case that needs it passed and no Core case was skipped but for an optional group
|
|
33
|
+
* the computer does not declare; and the run left nothing behind. A Full case's skip is owed by no group: a provider may
|
|
34
|
+
* refuse in words what its kind does not require (a phone's pinch), and it is still tried and reported.
|
|
35
|
+
*/
|
|
36
|
+
export function kindVerdict(kind, capabilities, report, cases = suiteOf(kind)) {
|
|
37
|
+
const problem = kindRunProblem(kind);
|
|
38
|
+
if (problem !== undefined)
|
|
39
|
+
return { kind, verdict: "fail", reasons: [problem] };
|
|
40
|
+
const reasons = [...servingRefusals(capabilities, kind)];
|
|
41
|
+
for (const result of report.results)
|
|
42
|
+
if (result.status === "fail")
|
|
43
|
+
reasons.push(`${result.id} failed: ${result.reason ?? "no reason given"}`);
|
|
44
|
+
const byId = new Map(cases.map((c) => [c.id, c]));
|
|
45
|
+
for (const group of SETTING_KINDS[kind].required) {
|
|
46
|
+
const ofGroup = report.results.filter((result) => byId.get(result.id)?.needs.includes(group));
|
|
47
|
+
for (const result of ofGroup) {
|
|
48
|
+
if (result.status === "skip" && result.undeclared === undefined && byId.get(result.id)?.level === "core")
|
|
49
|
+
reasons.push(`${result.id} was skipped: ${result.reason ?? "no reason given"}`);
|
|
50
|
+
}
|
|
51
|
+
if (!ofGroup.some((result) => result.status === "pass"))
|
|
52
|
+
reasons.push(`no case of ${group} passed`);
|
|
53
|
+
}
|
|
54
|
+
const { left, errors } = report.cleanup;
|
|
55
|
+
if (left.length > 0 || errors.length > 0)
|
|
56
|
+
reasons.push(`the run left ${[...left, ...errors].join("; ")}`);
|
|
57
|
+
return { kind, verdict: reasons.length === 0 ? "pass" : "fail", reasons: [...new Set(reasons)] };
|
|
58
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
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>;
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
// The sweep around a live Modal run, with the provider's settings and client (COMPUTER_MODAL_*, never MODAL_*):
|
|
2
|
+
//
|
|
3
|
+
// node packages/computer/dist/conformance/modal-sweep.js --before <file>
|
|
4
|
+
// node packages/computer/dist/conformance/modal-sweep.js --after <file>
|
|
5
|
+
//
|
|
6
|
+
// --before records into <file> the app and server it listed, and the id of every sandbox in the app COMPUTER_MODAL_APP
|
|
7
|
+
// that carries the provider's tag
|
|
8
|
+
// agentrun.computer=1: sandboxes.list({ appId, tags }) returns those with at least those tags, and running ones only
|
|
9
|
+
// (modal-client@64880502:js/src/sandbox.ts:1116-1159, includeFinished: false), so a finished sandbox is in neither list
|
|
10
|
+
// and needs no sweep. --after refuses a file whose app or server is not the one the environment names now, or that
|
|
11
|
+
// names none, before it lists anything: another app's computers would all read as new. Otherwise it lists them again,
|
|
12
|
+
// reads the tags of every one whose id is not in <file> (getTags: a list filters by exact tag values, and a run's label
|
|
13
|
+
// differs per run), terminates each that carries a conformance run's label (agentrun.conformance, RUN_LABEL), then
|
|
14
|
+
// reads each of those back with sandboxes.fromId and poll (sandbox.ts:960-962, 2766-2772; poll is null while it runs)
|
|
15
|
+
// until it reports an exit code, or Modal no longer knows it, up to 60 s each, and prints one JSON line,
|
|
16
|
+
// {"swept":n,"gone":m,"stillThere":[ids],"leftAlone":k}: swept is every conformance sandbox it found that was not there
|
|
17
|
+
// before, gone + stillThere.length = swept, and leftAlone counts the new tagged sandboxes it did not terminate: no
|
|
18
|
+
// conformance label (another user of the app made them during the run), or tags it could not read (said on stderr).
|
|
19
|
+
// A sandbox in <file> is never touched: no call names it. Exit 0 when every swept sandbox has finished, 1 when one still
|
|
20
|
+
// runs, 2 on a usage error, a before file it cannot read or of another app or server, a missing token or app, or a
|
|
21
|
+
// listing Modal refused (nothing is terminated then).
|
|
22
|
+
//
|
|
23
|
+
// It reads COMPUTER_MODAL_TOKEN_ID, COMPUTER_MODAL_TOKEN_SECRET, COMPUTER_MODAL_APP and COMPUTER_MODAL_SERVER_URL as the
|
|
24
|
+
// conformance module does (settingsFromEnv in ./modal.ts), and builds its client as the provider does (modalClient): the
|
|
25
|
+
// token passed explicitly, the server pinned, an ambient MODAL_SERVER_URL refused. It needs no
|
|
26
|
+
// AGENTRUN_COMPUTER_LIVE_MODAL: it makes nothing.
|
|
27
|
+
import { readFileSync, writeFileSync } from "node:fs";
|
|
28
|
+
import { COMPUTER_LABEL } from "../drift.js";
|
|
29
|
+
import { isCommand } from "../entry.js";
|
|
30
|
+
import { MODAL_DEFAULT_SERVER_URL, modalClient, untilFinished } from "../modal.js";
|
|
31
|
+
import { MODAL_ENV, settingsFromEnv } from "./modal.js";
|
|
32
|
+
import { RUN_LABEL } from "./runner.js";
|
|
33
|
+
const TAG = { [COMPUTER_LABEL]: "1" };
|
|
34
|
+
const USAGE = `usage: node packages/computer/dist/conformance/modal-sweep.js --before <file> | --after <file>
|
|
35
|
+
--before <file> record the app, the server and the id of every running sandbox carrying ${COMPUTER_LABEL}=1 in the app into <file>
|
|
36
|
+
--after <file> refuse a <file> of another app or server; else terminate every running sandbox carrying ${COMPUTER_LABEL}=1
|
|
37
|
+
and ${RUN_LABEL} in the app whose id is not in <file>, read each back until it has finished (up to 60 s
|
|
38
|
+
each), and print {"swept":n,"gone":m,"stillThere":[ids],"leftAlone":k}; a new one with no
|
|
39
|
+
${RUN_LABEL} (or tags it cannot read) is left alone
|
|
40
|
+
settings: ${MODAL_ENV.tokenId} and ${MODAL_ENV.tokenSecret} (required), ${MODAL_ENV.app} (required) and
|
|
41
|
+
${MODAL_ENV.serverUrl}, as the conformance module reads them; never MODAL_TOKEN_ID or MODAL_TOKEN_SECRET
|
|
42
|
+
exit: 0 every swept sandbox has finished, 1 one still runs, 2 usage error, unreadable before file or one of another app
|
|
43
|
+
or server, no token or app, or a refused listing`;
|
|
44
|
+
class Usage extends Error {
|
|
45
|
+
}
|
|
46
|
+
const write = (stream, text) => new Promise((resolve) => void stream.write(text, () => resolve()));
|
|
47
|
+
const words = (error) => {
|
|
48
|
+
const name = error?.name;
|
|
49
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
50
|
+
return `${typeof name === "string" && name !== "Error" ? `${name}: ` : ""}${message}`.replace(/\s+/g, " ").slice(0, 300);
|
|
51
|
+
};
|
|
52
|
+
const notFound = (error) => {
|
|
53
|
+
const { name, code } = (error ?? {});
|
|
54
|
+
return name === "NotFoundError" || code === 5;
|
|
55
|
+
};
|
|
56
|
+
/** The call's value, or the error it threw or rejected with; one that does not answer within ms is an error too. */
|
|
57
|
+
async function bounded(what, run, ms) {
|
|
58
|
+
let timer;
|
|
59
|
+
const timeout = new Promise((_, reject) => {
|
|
60
|
+
timer = setTimeout(() => reject(new Error(`${what} did not answer within ${ms / 1000} s`)), ms);
|
|
61
|
+
});
|
|
62
|
+
try {
|
|
63
|
+
return { ok: true, value: await Promise.race([Promise.resolve().then(run), timeout]) };
|
|
64
|
+
}
|
|
65
|
+
catch (error) {
|
|
66
|
+
return { ok: false, error };
|
|
67
|
+
}
|
|
68
|
+
finally {
|
|
69
|
+
clearTimeout(timer);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
function parse(argv) {
|
|
73
|
+
let found;
|
|
74
|
+
for (let i = 0; i < argv.length; i++) {
|
|
75
|
+
const [flag = "", inline] = (argv[i] ?? "").split(/=(.*)/s, 2);
|
|
76
|
+
if (flag !== "--before" && flag !== "--after")
|
|
77
|
+
throw new Usage(`unknown option ${flag}`);
|
|
78
|
+
const file = inline ?? argv[++i];
|
|
79
|
+
if (file === undefined || file === "" || file.startsWith("--"))
|
|
80
|
+
throw new Usage(`${flag} needs a file`);
|
|
81
|
+
if (found !== undefined)
|
|
82
|
+
throw new Usage("give --before <file> or --after <file>, one of them");
|
|
83
|
+
found = { mode: flag === "--before" ? "before" : "after", file };
|
|
84
|
+
}
|
|
85
|
+
if (found === undefined)
|
|
86
|
+
throw new Usage("give --before <file> or --after <file>, one of them");
|
|
87
|
+
return found;
|
|
88
|
+
}
|
|
89
|
+
function readBefore(file) {
|
|
90
|
+
let text;
|
|
91
|
+
try {
|
|
92
|
+
text = readFileSync(file, "utf8");
|
|
93
|
+
}
|
|
94
|
+
catch (error) {
|
|
95
|
+
throw new Usage(`cannot read the before file ${file}: ${error.message}`);
|
|
96
|
+
}
|
|
97
|
+
let record;
|
|
98
|
+
try {
|
|
99
|
+
record = JSON.parse(text);
|
|
100
|
+
}
|
|
101
|
+
catch {
|
|
102
|
+
record = undefined;
|
|
103
|
+
}
|
|
104
|
+
const { ids, app, serverUrl } = (record ?? {});
|
|
105
|
+
if (!Array.isArray(ids) || !ids.every((id) => typeof id === "string" && id !== ""))
|
|
106
|
+
throw new Usage(`${file} is not a before file: it holds no "ids" array of sandbox ids`);
|
|
107
|
+
return { app, serverUrl, ids: new Set(ids) };
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Why the before file is not of the app and server the environment names now, or undefined when it is. --after takes
|
|
111
|
+
* every tagged sandbox not in the file as new, so a file of another app, or of the same app name on another server,
|
|
112
|
+
* would have it terminate every computer there.
|
|
113
|
+
*/
|
|
114
|
+
function otherPlace(file, before, app, serverUrl) {
|
|
115
|
+
const refuse = (why) => `${file} ${why}, so nothing was listed or terminated: every computer there would read as new`;
|
|
116
|
+
if (typeof before.app !== "string" || before.app === "")
|
|
117
|
+
return refuse(`names no app; it is not a before file of this sweep`);
|
|
118
|
+
if (typeof before.serverUrl !== "string" || before.serverUrl === "")
|
|
119
|
+
return refuse(`names no server; it is not a before file of this sweep`);
|
|
120
|
+
if (before.app !== app)
|
|
121
|
+
return refuse(`was recorded in the app ${before.app}, and ${MODAL_ENV.app} names ${app} now`);
|
|
122
|
+
if (before.serverUrl !== serverUrl)
|
|
123
|
+
return refuse(`was recorded from ${before.serverUrl}, and the sweep would list ${serverUrl} now (${MODAL_ENV.serverUrl})`);
|
|
124
|
+
return undefined;
|
|
125
|
+
}
|
|
126
|
+
/** Every running sandbox in the app carrying the tag, by id, the whole listing within listMs. */
|
|
127
|
+
async function listTagged(sdk, app, callMs, listMs) {
|
|
128
|
+
const found = await bounded(`apps.fromName ${app}`, () => sdk.apps.fromName(app, { createIfMissing: true }), callMs);
|
|
129
|
+
if (!found.ok)
|
|
130
|
+
return found;
|
|
131
|
+
const appId = found.value.appId;
|
|
132
|
+
return bounded("sandboxes.list", async () => {
|
|
133
|
+
const all = new Map();
|
|
134
|
+
for await (const sandbox of sdk.sandboxes.list({ appId, tags: { ...TAG } }))
|
|
135
|
+
all.set(sandbox.sandboxId, sandbox);
|
|
136
|
+
return [...all.values()];
|
|
137
|
+
}, listMs);
|
|
138
|
+
}
|
|
139
|
+
export async function main(argv, io = {}) {
|
|
140
|
+
const { env = process.env, stdout = process.stdout, stderr = process.stderr, waitMs = 60_000, pollMs = 2_000, callMs = 60_000, listMs = 120_000 } = io;
|
|
141
|
+
let args;
|
|
142
|
+
let before;
|
|
143
|
+
let app;
|
|
144
|
+
let sdk;
|
|
145
|
+
let serverUrl;
|
|
146
|
+
try {
|
|
147
|
+
args = parse(argv);
|
|
148
|
+
const recorded = args.mode === "after" ? readBefore(args.file) : undefined;
|
|
149
|
+
const settings = settingsFromEnv(env);
|
|
150
|
+
app = settings.app;
|
|
151
|
+
serverUrl = settings.serverUrl ?? MODAL_DEFAULT_SERVER_URL;
|
|
152
|
+
sdk = await modalClient({ tokenId: settings.tokenId, tokenSecret: settings.tokenSecret, serverUrl, ...(io.ModalClient ? { ModalClient: io.ModalClient } : {}) });
|
|
153
|
+
if (recorded !== undefined) {
|
|
154
|
+
const other = otherPlace(args.file, recorded, app, serverUrl);
|
|
155
|
+
if (other !== undefined)
|
|
156
|
+
throw new Error(other);
|
|
157
|
+
before = recorded.ids;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
catch (error) {
|
|
161
|
+
await write(stderr, `${error.message}\n${error instanceof Usage ? `${USAGE}\n` : ""}`);
|
|
162
|
+
return 2;
|
|
163
|
+
}
|
|
164
|
+
const listed = await listTagged(sdk, app, callMs, listMs);
|
|
165
|
+
if (!listed.ok) {
|
|
166
|
+
await write(stderr, `listing the sandboxes carrying ${COMPUTER_LABEL}=1 in ${app} failed, so nothing was ${args.mode === "after" ? "terminated" : "recorded"}: ${words(listed.error)}\n`);
|
|
167
|
+
return 2;
|
|
168
|
+
}
|
|
169
|
+
if (before === undefined) {
|
|
170
|
+
const ids = listed.value.map((sandbox) => sandbox.sandboxId).sort();
|
|
171
|
+
writeFileSync(args.file, `${JSON.stringify({ tag: `${COMPUTER_LABEL}=1`, app, serverUrl, at: new Date().toISOString(), ids }, null, 2)}\n`);
|
|
172
|
+
await write(stdout, `${JSON.stringify({ recorded: ids.length, file: args.file })}\n`);
|
|
173
|
+
return 0;
|
|
174
|
+
}
|
|
175
|
+
const known = before;
|
|
176
|
+
const added = listed.value.filter((sandbox) => !known.has(sandbox.sandboxId));
|
|
177
|
+
// Only a conformance run's computers: one another user of the app made during the run is not this sweep's. Tags it
|
|
178
|
+
// cannot read leave the sandbox alone, said in words; one Modal no longer knows has finished already.
|
|
179
|
+
const fresh = [];
|
|
180
|
+
let leftAlone = 0;
|
|
181
|
+
for (const sandbox of added) {
|
|
182
|
+
const tags = await bounded(`getTags of ${sandbox.sandboxId}`, () => sandbox.getTags(), callMs);
|
|
183
|
+
if (!tags.ok) {
|
|
184
|
+
if (notFound(tags.error))
|
|
185
|
+
continue;
|
|
186
|
+
await write(stderr, `${sandbox.sandboxId} was left alone: its tags could not be read: ${words(tags.error)}\n`);
|
|
187
|
+
leftAlone += 1;
|
|
188
|
+
}
|
|
189
|
+
else if (Object.hasOwn(tags.value, RUN_LABEL))
|
|
190
|
+
fresh.push(sandbox);
|
|
191
|
+
else
|
|
192
|
+
leftAlone += 1;
|
|
193
|
+
}
|
|
194
|
+
for (const sandbox of fresh) {
|
|
195
|
+
const ended = await bounded(`terminate of ${sandbox.sandboxId}`, () => sandbox.terminate(), callMs);
|
|
196
|
+
if (!ended.ok && !notFound(ended.error))
|
|
197
|
+
await write(stderr, `${sandbox.sandboxId} was not terminated: ${words(ended.error)}\n`);
|
|
198
|
+
}
|
|
199
|
+
// Each read back on its own, at once, through a new handle and the provider's own wait after a terminate
|
|
200
|
+
// (untilFinished): an exit code, or a sandbox Modal no longer knows, is gone.
|
|
201
|
+
const gone = await Promise.all(fresh.map(async ({ sandboxId: id }) => {
|
|
202
|
+
const waited = await untilFinished(async () => (await sdk.sandboxes.fromId(id)).poll(), { name: id, boundMs: waitMs, callMs, minMs: pollMs, maxMs: pollMs });
|
|
203
|
+
if (!waited.ok)
|
|
204
|
+
await write(stderr, `${id} is still running after ${waitMs / 1000} s: ${waited.error.message}\n`);
|
|
205
|
+
return waited.ok;
|
|
206
|
+
}));
|
|
207
|
+
const stillThere = fresh.filter((_, i) => !gone[i]).map((sandbox) => sandbox.sandboxId);
|
|
208
|
+
await write(stdout, `${JSON.stringify({ swept: fresh.length, gone: fresh.length - stillThere.length, stillThere, leftAlone })}\n`);
|
|
209
|
+
return stillThere.length === 0 ? 0 : 1;
|
|
210
|
+
}
|
|
211
|
+
if (isCommand(import.meta)) {
|
|
212
|
+
process.exitCode = await main(process.argv.slice(2));
|
|
213
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import type { MountKind } from "../mount.js";
|
|
2
|
+
import type { ProviderNote } from "../mount-archil.js";
|
|
3
|
+
import type { ComputerProvider } from "../provider.js";
|
|
4
|
+
import { type ModalClientConstructor, type ModalCreateOptions } from "../modal.js";
|
|
5
|
+
import { type ArchilRunFolderOptions } from "./archil.js";
|
|
6
|
+
import type { RunFolder } from "./types.js";
|
|
7
|
+
/** The Archil disk's settings for the mount cases, by name (COMPUTER_ARCHIL_*: all five, or none). */
|
|
8
|
+
export { ARCHIL_ENV } from "./archil.js";
|
|
9
|
+
/** The environment this module reads, by name, each for the option its comment names, and the live switch. */
|
|
10
|
+
export declare const MODAL_ENV: {
|
|
11
|
+
readonly live: "AGENTRUN_COMPUTER_LIVE_MODAL";
|
|
12
|
+
/** tokenId and tokenSecret, required: the Modal token. */
|
|
13
|
+
readonly tokenId: "COMPUTER_MODAL_TOKEN_ID";
|
|
14
|
+
readonly tokenSecret: "COMPUTER_MODAL_TOKEN_SECRET";
|
|
15
|
+
/** app, required: the Modal App the run's sandboxes live in, made when missing. */
|
|
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
|
+
/** serverUrl: the server the token goes to; the SDK's default when unset. */
|
|
20
|
+
readonly serverUrl: "COMPUTER_MODAL_SERVER_URL";
|
|
21
|
+
};
|
|
22
|
+
/** The names this module reads, under the conformance modules' common name (ConformanceModule.ENV). */
|
|
23
|
+
export declare const ENV: {
|
|
24
|
+
readonly live: "AGENTRUN_COMPUTER_LIVE_MODAL";
|
|
25
|
+
/** tokenId and tokenSecret, required: the Modal token. */
|
|
26
|
+
readonly tokenId: "COMPUTER_MODAL_TOKEN_ID";
|
|
27
|
+
readonly tokenSecret: "COMPUTER_MODAL_TOKEN_SECRET";
|
|
28
|
+
/** app, required: the Modal App the run's sandboxes live in, made when missing. */
|
|
29
|
+
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
|
+
/** serverUrl: the server the token goes to; the SDK's default when unset. */
|
|
33
|
+
readonly serverUrl: "COMPUTER_MODAL_SERVER_URL";
|
|
34
|
+
};
|
|
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">;
|
|
37
|
+
/**
|
|
38
|
+
* The provider's options this module reads from env; throws in words without the token or the app, or while
|
|
39
|
+
* MODAL_SERVER_URL is set there (the SDK would send the token to it), never echoing a token.
|
|
40
|
+
*/
|
|
41
|
+
export declare function settingsFromEnv(env?: Record<string, string | undefined>): ModalSettings;
|
|
42
|
+
/** The longest lifetime a computer of a run may ask for: Modal ends each sandbox at its timeout, the lifetime. */
|
|
43
|
+
export declare const CONFORMANCE_MAX_LIFETIME_MS: number;
|
|
44
|
+
export interface ModalModuleOptions {
|
|
45
|
+
/** The environment to read; process.env by default. */
|
|
46
|
+
env?: Record<string, string | undefined>;
|
|
47
|
+
/** The SDK's ModalClient; imported from the host's modal package by default. */
|
|
48
|
+
ModalClient?: ModalClientConstructor;
|
|
49
|
+
/** The daemon to upload, when COMPUTER_MODAL_DAEMON_IMAGE names no image; default this package's dist/computerd-linux-amd64. */
|
|
50
|
+
daemonPath?: string;
|
|
51
|
+
/** Builds this package's daemon for linux/amd64 stamped with version, and gives its path; default go build. */
|
|
52
|
+
buildDaemon?: (version: string) => Promise<string>;
|
|
53
|
+
/** For mountFor("archil"): the disk's object API, or the SDK's Archil client, in place of the host's disk package. */
|
|
54
|
+
archil?: Pick<ArchilRunFolderOptions, "objects" | "Archil" | "baseUrl">;
|
|
55
|
+
/** What the provider says that is no failure: the CLI gives it and puts it in the report. */
|
|
56
|
+
onNote?: ProviderNote;
|
|
57
|
+
}
|
|
58
|
+
export declare function createProvider({ env, ModalClient, daemonPath, onNote }?: ModalModuleOptions): Promise<ComputerProvider>;
|
|
59
|
+
/**
|
|
60
|
+
* 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
|
+
* disk the COMPUTER_ARCHIL_* names name (archilSettings), none when they name none (archilRunFolder, ./archil.ts).
|
|
62
|
+
* Reaching it is a call to Archil, so it needs the live switch.
|
|
63
|
+
*/
|
|
64
|
+
export declare function mountFor(kind: MountKind, { env, archil }?: ModalModuleOptions): Promise<RunFolder | undefined>;
|
|
65
|
+
/**
|
|
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.
|
|
68
|
+
*/
|
|
69
|
+
export declare function createDriftedProvider({ env, ModalClient, buildDaemon }?: ModalModuleOptions): Promise<ComputerProvider>;
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { create } from "../modal.js";
|
|
2
|
+
import { archilRunFolder, archilSettings } from "./archil.js";
|
|
3
|
+
import { buildDriftDaemon, DRIFT_VERSION } from "./drift-daemon.js";
|
|
4
|
+
/** The Archil disk's settings for the mount cases, by name (COMPUTER_ARCHIL_*: all five, or none). */
|
|
5
|
+
export { ARCHIL_ENV } from "./archil.js";
|
|
6
|
+
/** The environment this module reads, by name, each for the option its comment names, and the live switch. */
|
|
7
|
+
export const MODAL_ENV = {
|
|
8
|
+
live: "AGENTRUN_COMPUTER_LIVE_MODAL",
|
|
9
|
+
/** tokenId and tokenSecret, required: the Modal token. */
|
|
10
|
+
tokenId: "COMPUTER_MODAL_TOKEN_ID",
|
|
11
|
+
tokenSecret: "COMPUTER_MODAL_TOKEN_SECRET",
|
|
12
|
+
/** app, required: the Modal App the run's sandboxes live in, made when missing. */
|
|
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
|
+
/** serverUrl: the server the token goes to; the SDK's default when unset. */
|
|
17
|
+
serverUrl: "COMPUTER_MODAL_SERVER_URL",
|
|
18
|
+
};
|
|
19
|
+
/** The names this module reads, under the conformance modules' common name (ConformanceModule.ENV). */
|
|
20
|
+
export const ENV = MODAL_ENV;
|
|
21
|
+
/**
|
|
22
|
+
* The provider's options this module reads from env; throws in words without the token or the app, or while
|
|
23
|
+
* MODAL_SERVER_URL is set there (the SDK would send the token to it), never echoing a token.
|
|
24
|
+
*/
|
|
25
|
+
export function settingsFromEnv(env = process.env) {
|
|
26
|
+
const tokenId = env[MODAL_ENV.tokenId];
|
|
27
|
+
const tokenSecret = env[MODAL_ENV.tokenSecret];
|
|
28
|
+
if (!tokenId || !tokenSecret) {
|
|
29
|
+
throw new Error(`the Modal conformance module needs ${MODAL_ENV.tokenId} and ${MODAL_ENV.tokenSecret}: it takes a key from those names only, never MODAL_TOKEN_ID or MODAL_TOKEN_SECRET`);
|
|
30
|
+
}
|
|
31
|
+
if (env.MODAL_SERVER_URL) {
|
|
32
|
+
throw new Error(`the Modal provider refuses to start while MODAL_SERVER_URL is set: the SDK would send the key there. Unset it, and name the server in ${MODAL_ENV.serverUrl} if it is not the SDK's default`);
|
|
33
|
+
}
|
|
34
|
+
const app = env[MODAL_ENV.app];
|
|
35
|
+
if (!app)
|
|
36
|
+
throw new Error(`the Modal conformance module needs ${MODAL_ENV.app}: the app the run's sandboxes live in`);
|
|
37
|
+
const serverUrl = env[MODAL_ENV.serverUrl];
|
|
38
|
+
const daemonImage = env[MODAL_ENV.daemonImage];
|
|
39
|
+
return { tokenId, tokenSecret, app, ...(serverUrl ? { serverUrl } : {}), ...(daemonImage ? { daemonImage } : {}) };
|
|
40
|
+
}
|
|
41
|
+
/** The longest lifetime a computer of a run may ask for: Modal ends each sandbox at its timeout, the lifetime. */
|
|
42
|
+
export const CONFORMANCE_MAX_LIFETIME_MS = 30 * 60_000;
|
|
43
|
+
function live(env) {
|
|
44
|
+
if (env[MODAL_ENV.live] !== "1") {
|
|
45
|
+
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
|
+
}
|
|
47
|
+
}
|
|
48
|
+
export async function createProvider({ env = process.env, ModalClient, daemonPath, onNote } = {}) {
|
|
49
|
+
live(env);
|
|
50
|
+
// Given COMPUTER_MODAL_DAEMON_IMAGE and a daemonPath, create() takes the image.
|
|
51
|
+
return create({ ...settingsFromEnv(env), ...(daemonPath === undefined ? {} : { daemonPath }), ...(ModalClient ? { ModalClient } : {}), ...(onNote ? { onNote } : {}), maxLifetimeMs: CONFORMANCE_MAX_LIFETIME_MS });
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* A run folder for an Archil mount, and none for any other kind (a Modal computer takes no bind): a fresh folder on the
|
|
55
|
+
* disk the COMPUTER_ARCHIL_* names name (archilSettings), none when they name none (archilRunFolder, ./archil.ts).
|
|
56
|
+
* Reaching it is a call to Archil, so it needs the live switch.
|
|
57
|
+
*/
|
|
58
|
+
export async function mountFor(kind, { env = process.env, archil = {} } = {}) {
|
|
59
|
+
if (kind !== "archil")
|
|
60
|
+
return undefined;
|
|
61
|
+
const settings = archilSettings(env);
|
|
62
|
+
if (settings === undefined)
|
|
63
|
+
return undefined;
|
|
64
|
+
live(env);
|
|
65
|
+
return archilRunFolder({ ...settings, ...archil });
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
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.
|
|
70
|
+
*/
|
|
71
|
+
export async function createDriftedProvider({ env = process.env, ModalClient, buildDaemon = (version) => buildDriftDaemon("amd64", version) } = {}) {
|
|
72
|
+
live(env);
|
|
73
|
+
const { daemonImage: _image, ...settings } = settingsFromEnv(env);
|
|
74
|
+
const daemonPath = await buildDaemon(DRIFT_VERSION);
|
|
75
|
+
return create({ ...settings, daemonPath, ...(ModalClient ? { ModalClient } : {}), maxLifetimeMs: CONFORMANCE_MAX_LIFETIME_MS });
|
|
76
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { type OrgoChannel, type OrgoProvider, type OrgoWebSocketFactory } from "../orgo.js";
|
|
2
|
+
/** The environment this module reads, by name: the live switch, the run's template, and the provider's settings. */
|
|
3
|
+
export declare const ENV: {
|
|
4
|
+
readonly live: "AGENTRUN_COMPUTER_LIVE_ORGO";
|
|
5
|
+
/** The template every computer of the run starts from; default Orgo's base desktop ("linux"). */
|
|
6
|
+
readonly template: "COMPUTER_ORGO_TEMPLATE";
|
|
7
|
+
/** Required: an Orgo API key (never ORGO_API_KEY, which a host may hold for another account). */
|
|
8
|
+
readonly key: "COMPUTER_ORGO_API_KEY";
|
|
9
|
+
/** Required: the workspace the run's computers live in. */
|
|
10
|
+
readonly workspace: "COMPUTER_ORGO_WORKSPACE";
|
|
11
|
+
/** Orgo's API; default https://www.orgo.ai/api. */
|
|
12
|
+
readonly apiUrl: "COMPUTER_ORGO_API_URL";
|
|
13
|
+
};
|
|
14
|
+
/** The longest lifetime a computer of a run may ask for: Orgo's shortest end, 1 h. */
|
|
15
|
+
export declare const CONFORMANCE_MAX_LIFETIME_MS: number;
|
|
16
|
+
/** For the run's report: what this configuration means for the suite. */
|
|
17
|
+
export declare const conformanceNotes: string[];
|
|
18
|
+
export interface OrgoModuleOptions {
|
|
19
|
+
/** Where the settings are read; default process.env. */
|
|
20
|
+
env?: Record<string, string | undefined>;
|
|
21
|
+
/** For tests: the REST calls, the terminal socket, or the whole channel. */
|
|
22
|
+
fetch?: typeof fetch;
|
|
23
|
+
webSocket?: OrgoWebSocketFactory;
|
|
24
|
+
channel?: OrgoChannel;
|
|
25
|
+
/** The daemon to upload; default this package's dist/computerd-linux-amd64. */
|
|
26
|
+
daemonPath?: string;
|
|
27
|
+
/** Builds this package's daemon for linux/amd64 stamped with version, and gives its path; default go build. */
|
|
28
|
+
buildDaemon?: (version: string) => Promise<string>;
|
|
29
|
+
}
|
|
30
|
+
/** The provider's settings from COMPUTER_ORGO_* alone: the key, the workspace, and Orgo's API when named. No word holds the key. */
|
|
31
|
+
export declare function settingsFromEnv(env?: Record<string, string | undefined>): {
|
|
32
|
+
apiKey: string;
|
|
33
|
+
workspaceId: string;
|
|
34
|
+
apiUrl?: string;
|
|
35
|
+
};
|
|
36
|
+
/** The image every computer of the run starts from: COMPUTER_ORGO_TEMPLATE, or Orgo's base desktop. */
|
|
37
|
+
export declare function conformanceImage({ env }?: Pick<OrgoModuleOptions, "env">): string;
|
|
38
|
+
/** The provider the CLI runs; throws in words without the live switch, or when a setting is missing or wrong. */
|
|
39
|
+
export declare function createProvider(options?: OrgoModuleOptions): Promise<OrgoProvider>;
|
|
40
|
+
/** The same provider uploading a daemon that reports version <version>-drift, for the drift.version case. */
|
|
41
|
+
export declare function createDriftedProvider({ buildDaemon, ...options }?: OrgoModuleOptions): Promise<OrgoProvider>;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
// Orgo for the conformance CLI: `npm run conformance -w @parcha/agentrun-computer -- --provider orgo [--image <template>]`.
|
|
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.
|
|
5
|
+
//
|
|
6
|
+
// The daemon is uploaded into each computer (dist/computerd-linux-amd64, `npm run build:daemon`); the drifted provider
|
|
7
|
+
// uploads one built with Go as version <version>-drift. Every computer of a run lives at most 1 h, Orgo's shortest end
|
|
8
|
+
// (ends_in_hours 1): Orgo deletes it then whatever happens to the run.
|
|
9
|
+
import { create, ORGO_BASE_IMAGE } from "../orgo.js";
|
|
10
|
+
import { buildDriftDaemon, DRIFT_VERSION } from "./drift-daemon.js";
|
|
11
|
+
/** The environment this module reads, by name: the live switch, the run's template, and the provider's settings. */
|
|
12
|
+
export const ENV = {
|
|
13
|
+
live: "AGENTRUN_COMPUTER_LIVE_ORGO",
|
|
14
|
+
/** The template every computer of the run starts from; default Orgo's base desktop ("linux"). */
|
|
15
|
+
template: "COMPUTER_ORGO_TEMPLATE",
|
|
16
|
+
/** Required: an Orgo API key (never ORGO_API_KEY, which a host may hold for another account). */
|
|
17
|
+
key: "COMPUTER_ORGO_API_KEY",
|
|
18
|
+
/** Required: the workspace the run's computers live in. */
|
|
19
|
+
workspace: "COMPUTER_ORGO_WORKSPACE",
|
|
20
|
+
/** Orgo's API; default https://www.orgo.ai/api. */
|
|
21
|
+
apiUrl: "COMPUTER_ORGO_API_URL",
|
|
22
|
+
};
|
|
23
|
+
const ORGO_ENV = ENV;
|
|
24
|
+
/** The longest lifetime a computer of a run may ask for: Orgo's shortest end, 1 h. */
|
|
25
|
+
export const CONFORMANCE_MAX_LIFETIME_MS = 60 * 60_000;
|
|
26
|
+
/** For the run's report: what this configuration means for the suite. */
|
|
27
|
+
export const conformanceNotes = [
|
|
28
|
+
"orgo: a Linux desktop on Orgo with computerd inside, on Orgo's own X display :99, its tools as 2510:2510; janitor-ended at the exact deadline its name carries, and within 1 h whatever happens (Orgo deletes it at ends_in_hours 1, the backstop); network none is init's own namespace (--own-network), probed from inside at the outside and at every port root listens on, since Orgo has no egress control; the desktop's path sockets are root's alone but the display's; no mount.",
|
|
29
|
+
];
|
|
30
|
+
function live(env) {
|
|
31
|
+
if (env[ORGO_ENV.live] !== "1") {
|
|
32
|
+
throw new Error(`the Orgo conformance module makes real computers: set ${ORGO_ENV.live}=1, with a key the lead has OKed, to run it`);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
/** The provider's settings from COMPUTER_ORGO_* alone: the key, the workspace, and Orgo's API when named. No word holds the key. */
|
|
36
|
+
export function settingsFromEnv(env = process.env) {
|
|
37
|
+
const apiKey = env[ORGO_ENV.key];
|
|
38
|
+
if (!apiKey)
|
|
39
|
+
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`);
|
|
40
|
+
const workspaceId = env[ORGO_ENV.workspace];
|
|
41
|
+
if (!workspaceId)
|
|
42
|
+
throw new Error(`set ${ORGO_ENV.workspace} to the Orgo workspace the run's computers live in`);
|
|
43
|
+
const apiUrl = env[ORGO_ENV.apiUrl] || undefined;
|
|
44
|
+
return { apiKey, workspaceId, ...(apiUrl ? { apiUrl } : {}) };
|
|
45
|
+
}
|
|
46
|
+
/** The image every computer of the run starts from: COMPUTER_ORGO_TEMPLATE, or Orgo's base desktop. */
|
|
47
|
+
export function conformanceImage({ env = process.env } = {}) {
|
|
48
|
+
return env[ORGO_ENV.template] || ORGO_BASE_IMAGE;
|
|
49
|
+
}
|
|
50
|
+
function build({ env = process.env, fetch, webSocket, channel }, daemonPath) {
|
|
51
|
+
return create({
|
|
52
|
+
...settingsFromEnv(env),
|
|
53
|
+
maxLifetimeMs: CONFORMANCE_MAX_LIFETIME_MS,
|
|
54
|
+
...(fetch ? { fetch } : {}),
|
|
55
|
+
...(webSocket ? { webSocket } : {}),
|
|
56
|
+
...(channel ? { channel } : {}),
|
|
57
|
+
...(daemonPath === undefined ? {} : { daemonPath }),
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
/** The provider the CLI runs; throws in words without the live switch, or when a setting is missing or wrong. */
|
|
61
|
+
export async function createProvider(options = {}) {
|
|
62
|
+
live(options.env ?? process.env);
|
|
63
|
+
return build(options, options.daemonPath);
|
|
64
|
+
}
|
|
65
|
+
/** The same provider uploading a daemon that reports version <version>-drift, for the drift.version case. */
|
|
66
|
+
export async function createDriftedProvider({ buildDaemon = (version) => buildDriftDaemon("amd64", version), ...options } = {}) {
|
|
67
|
+
live(options.env ?? process.env);
|
|
68
|
+
return build(options, await buildDaemon(DRIFT_VERSION));
|
|
69
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { type AdbTransport, type PhoneHarnessProvider, type PhoneLedger, type PhoneProviderOptions } from "../phone-harness.js";
|
|
2
|
+
/** The environment this module reads, by name. */
|
|
3
|
+
export declare const PHONE_ENV: {
|
|
4
|
+
/** The phone harness API key: this module's own name, never the bare PHONE_HARNESS_API_KEY. */
|
|
5
|
+
readonly key: "COMPUTER_PHONE_HARNESS_API_KEY";
|
|
6
|
+
/** android (the default); ios is refused until it is built. */
|
|
7
|
+
readonly platform: "COMPUTER_PHONE_HARNESS_PLATFORM";
|
|
8
|
+
/** The adb CLI's path; default adb on PATH. */
|
|
9
|
+
readonly adb: "COMPUTER_PHONE_HARNESS_ADB";
|
|
10
|
+
/** The ledger's JSON file; default agentrun-phone-ledger.json in the temp dir. */
|
|
11
|
+
readonly ledger: "COMPUTER_PHONE_HARNESS_LEDGER";
|
|
12
|
+
/** 1 to rent phones at all: each one is billed by the minute. */
|
|
13
|
+
readonly live: "AGENTRUN_COMPUTER_LIVE_PHONE_HARNESS";
|
|
14
|
+
};
|
|
15
|
+
/** The names this module reads, under the conformance modules' common name. */
|
|
16
|
+
export declare const ENV: {
|
|
17
|
+
/** The phone harness API key: this module's own name, never the bare PHONE_HARNESS_API_KEY. */
|
|
18
|
+
readonly key: "COMPUTER_PHONE_HARNESS_API_KEY";
|
|
19
|
+
/** android (the default); ios is refused until it is built. */
|
|
20
|
+
readonly platform: "COMPUTER_PHONE_HARNESS_PLATFORM";
|
|
21
|
+
/** The adb CLI's path; default adb on PATH. */
|
|
22
|
+
readonly adb: "COMPUTER_PHONE_HARNESS_ADB";
|
|
23
|
+
/** The ledger's JSON file; default agentrun-phone-ledger.json in the temp dir. */
|
|
24
|
+
readonly ledger: "COMPUTER_PHONE_HARNESS_LEDGER";
|
|
25
|
+
/** 1 to rent phones at all: each one is billed by the minute. */
|
|
26
|
+
readonly live: "AGENTRUN_COMPUTER_LIVE_PHONE_HARNESS";
|
|
27
|
+
};
|
|
28
|
+
export interface PhoneSettings {
|
|
29
|
+
apiKey?: string;
|
|
30
|
+
platform?: "android" | "ios";
|
|
31
|
+
adb?: string;
|
|
32
|
+
ledgerPath?: string;
|
|
33
|
+
}
|
|
34
|
+
/** The provider's settings this module reads from env, each only when its name is set. */
|
|
35
|
+
export declare function settingsFromEnv(env?: Record<string, string | undefined>): PhoneSettings;
|
|
36
|
+
/**
|
|
37
|
+
* A ledger in a JSON file (mode 0600), read whole on each call and written whole by rename, so a reader never sees half
|
|
38
|
+
* a file. Writes (put, remove) are one at a time across processes: in this process through one queue, and between
|
|
39
|
+
* processes by a lock file beside the ledger (<path>.lock), so a write never drops another's entry.
|
|
40
|
+
*
|
|
41
|
+
* The lock names its holder (`<pid> <token>`), and is judged by that holder, not by its age. A live writer's lock is
|
|
42
|
+
* never taken, however old: a write waits for it, up to waitMs (10 s by default) for one holder that never lets go,
|
|
43
|
+
* then fails in words. A lock that keeps passing between live writers is progress, and is waited for. A lock whose
|
|
44
|
+
* holder is gone (it crashed mid-write) is broken at once, by one waiter.
|
|
45
|
+
*/
|
|
46
|
+
export declare function fileLedger(path: string, { waitMs }?: {
|
|
47
|
+
waitMs?: number;
|
|
48
|
+
}): PhoneLedger;
|
|
49
|
+
export interface PhoneModuleOptions extends Pick<PhoneProviderOptions, "fetch" | "now" | "sleep" | "baseUrl"> {
|
|
50
|
+
/** Where the settings are read; default process.env. */
|
|
51
|
+
env?: Record<string, string | undefined>;
|
|
52
|
+
/** The adb runner; default the CLI the settings name. */
|
|
53
|
+
adb?: AdbTransport | string;
|
|
54
|
+
}
|
|
55
|
+
/** The provider the CLI runs. */
|
|
56
|
+
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. */
|
|
58
|
+
export declare function createDriftedProvider(options?: PhoneModuleOptions): Promise<PhoneHarnessProvider>;
|
|
59
|
+
/** The image a run names: a cloud Android has none to choose, so it is read back as this name. */
|
|
60
|
+
export declare function conformanceImage(): string;
|
|
61
|
+
export declare const conformanceNotes: string[];
|