@parcha/agentrun-computer 0.1.0-beta.37 → 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/README.md +259 -203
- package/box/Dockerfile +18 -1
- package/box/README.md +13 -0
- package/box/build-agent37.mjs +8 -27
- 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 +2 -63
- package/dist/agent37.js +104 -461
- package/dist/browserbase.d.ts +0 -6
- package/dist/browserbase.js +1 -5
- package/dist/client.d.ts +12 -3
- package/dist/client.js +39 -4
- package/dist/computerd-linux-amd64 +0 -0
- package/dist/computerd-linux-arm64 +0 -0
- package/dist/computerd.json +4 -0
- package/dist/conformance/cases/apps.d.ts +6 -0
- package/dist/conformance/cases/apps.js +18 -5
- 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/cli.js +66 -6
- package/dist/conformance/daytona.d.ts +9 -20
- package/dist/conformance/daytona.js +12 -21
- package/dist/conformance/exec-stream.d.ts +45 -0
- package/dist/conformance/exec-stream.js +486 -0
- package/dist/conformance/sweep.js +8 -8
- package/dist/conformance/types.d.ts +2 -2
- package/dist/create-requests.d.ts +1 -1
- package/dist/daytona.d.ts +20 -131
- package/dist/daytona.js +405 -1450
- package/dist/descriptor.d.ts +6 -1
- package/dist/descriptor.js +7 -0
- package/dist/descriptors/agent37.d.ts +1 -1
- package/dist/descriptors/agent37.js +1 -1
- package/dist/descriptors/daytona.d.ts +6 -5
- package/dist/descriptors/daytona.js +9 -5
- package/dist/descriptors/index.d.ts +4 -5
- 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 +0 -6
- package/dist/docker.js +1 -5
- package/dist/drift.js +4 -4
- package/dist/e2b.d.ts +10 -128
- package/dist/e2b.js +130 -233
- package/dist/host.d.ts +106 -87
- package/dist/host.js +8 -1
- package/dist/hosted/process.d.ts +22 -8
- package/dist/hosted/process.js +75 -44
- package/dist/hosted/provider.d.ts +35 -21
- package/dist/hosted/provider.js +312 -261
- package/dist/hosted/rest.d.ts +66 -0
- package/dist/hosted/rest.js +121 -0
- package/dist/hosted/scripts.d.ts +8 -2
- package/dist/hosted/scripts.js +27 -2
- package/dist/hosted/values.d.ts +5 -0
- package/dist/hosted/values.js +8 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/kernel.d.ts +0 -6
- package/dist/kernel.js +1 -5
- package/dist/kinds.d.ts +3 -1
- package/dist/local-chrome.d.ts +0 -6
- package/dist/local-chrome.js +1 -5
- package/dist/modal.d.ts +7 -84
- package/dist/modal.js +50 -174
- 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.d.ts +0 -9
- package/dist/orgo.js +2 -9
- package/dist/phone-harness.d.ts +0 -6
- package/dist/phone-harness.js +0 -4
- package/dist/protocol.d.ts +4 -1
- package/dist/protocol.js +1 -0
- package/dist/provider.d.ts +2 -2
- package/dist/providers.d.ts +11 -12
- package/dist/screen-watch.js +34 -6
- package/dist/surface/api.d.ts +14 -2
- package/dist/surface/core.d.ts +16 -3
- package/dist/surface/core.js +95 -13
- package/dist/surface/outline.d.ts +2 -0
- package/dist/surface/outline.js +2 -1
- package/dist/surface/script.js +2 -0
- package/dist/ui-engine.js +19 -3
- package/package.json +2 -3
- package/dist/conformance/daytona-sweep.d.ts +0 -18
- package/dist/conformance/daytona-sweep.js +0 -126
package/box/Dockerfile
CHANGED
|
@@ -10,7 +10,12 @@
|
|
|
10
10
|
# the computer's, which reaches Archil;
|
|
11
11
|
# - nftables, for the helper's mount with an egress gateway alone: it redirects root's TCP to Archil's 8100 and 32050
|
|
12
12
|
# to computerd's archil relay on the computer's loopback;
|
|
13
|
-
# - /workspace, empty and root's, where the helper mounts the run's folder
|
|
13
|
+
# - /workspace, empty and root's, where the helper mounts the run's folder;
|
|
14
|
+
# - a desktop, with nothing started: Xvfb and xfwm4 (with dbus-run-session, which xfconf's packages bring) and
|
|
15
|
+
# xsetroot (x11-xserver-utils, the desktop's background), which the provider starts through computerd as the tool
|
|
16
|
+
# user on :0 (src/desktop.ts), and the apps E2B Desktop has that are cheap to carry: Xfce's terminal and text editor,
|
|
17
|
+
# Firefox ESR, and xdotool. computerd's apps group lists and opens them by their desktop files. No VNC server comes
|
|
18
|
+
# with it. One image serves a sandbox and a desktop (an Agent37 desktop starts from it too).
|
|
14
19
|
#
|
|
15
20
|
# No sudo and no sudoers file: the image's user is root, so the provider's own exec (Daytona's toolbox, Modal's exec,
|
|
16
21
|
# E2B's commands as root) runs the helper as root, and the tool user has no way to root. The build fails if the base
|
|
@@ -46,6 +51,18 @@ RUN set -eu; \
|
|
|
46
51
|
useradd --uid 2510 --gid 2510 --no-create-home --home-dir /tmp --shell /bin/sh agentrun-tool; \
|
|
47
52
|
install -d -o root -g root -m 0755 /workspace
|
|
48
53
|
|
|
54
|
+
# The desktop: Xvfb and xfwm4, which the provider starts through computerd as the tool user on :0, and the apps an agent
|
|
55
|
+
# opens. Each program and each app's desktop file is checked here. It comes before the sudo guard below, so a package
|
|
56
|
+
# that brought sudo would be taken away and checked gone there (a check here would refuse E2B's build, whose builder adds
|
|
57
|
+
# sudo before these steps).
|
|
58
|
+
RUN set -eu; \
|
|
59
|
+
apt-get update -qq; \
|
|
60
|
+
DEBIAN_FRONTEND=noninteractive apt-get install -y -qq --no-install-recommends \
|
|
61
|
+
xvfb xfwm4 x11-xserver-utils xfce4-terminal mousepad firefox-esr xdotool fonts-dejavu-core adwaita-icon-theme >/dev/null; \
|
|
62
|
+
rm -rf /var/lib/apt/lists/*; \
|
|
63
|
+
for x in Xvfb xfwm4 dbus-run-session xsetroot xfce4-terminal mousepad firefox-esr xdotool; do command -v "$x" >/dev/null || { echo "the image has no $x" >&2; exit 1; }; done; \
|
|
64
|
+
for app in org.xfce.mousepad xfce4-terminal firefox-esr; do [ -f "/usr/share/applications/$app.desktop" ] || { echo "the image has no desktop file $app.desktop" >&2; exit 1; }; done
|
|
65
|
+
|
|
49
66
|
COPY agentrun-archil /usr/local/sbin/agentrun-archil
|
|
50
67
|
|
|
51
68
|
# What the helper runs, where it runs it from: an image that lacks one fails here, not at a run's first mount. And no
|
package/box/README.md
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# The box image
|
|
2
|
+
|
|
3
|
+
The image a remote computer with an Archil mount starts from: a small Debian with a coding agent's tools, the archil
|
|
4
|
+
client pinned by version and sha256, the root helper `agentrun-archil`, the tool user `agentrun-tool` (uid and gid
|
|
5
|
+
2510), FUSE and nftables, a desktop with nothing started (Xvfb, xfwm4 and the apps an agent opens), and no sudo. One
|
|
6
|
+
image serves a sandbox and a desktop. The Dockerfile's comment says what each part is for.
|
|
7
|
+
|
|
8
|
+
Its tag is the recipe's hash: the first 12 hex of the sha256 of `Dockerfile` and `agentrun-archil`, the one file it
|
|
9
|
+
copies (`recipe.mjs`). A changed recipe is a new image, and the same recipe is the one built before.
|
|
10
|
+
|
|
11
|
+
Each release publishes it (`.github/workflows/release.yml`, the `box` job) as `ghcr.io/parcha-ai/agentrun-box:<recipe hash>`
|
|
12
|
+
and `:<release tag>`, for linux/amd64, and builds the public E2B template `agentrun-archil-<recipe hash>` from it (the
|
|
13
|
+
`box-e2b` job). The build-* scripts here say how to build it for each provider.
|
package/box/build-agent37.mjs
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
// Build the box image (this folder's Dockerfile,
|
|
1
|
+
// Build the box image (this folder's Dockerfile, its desktop included) as a template of an Agent37 workspace, through
|
|
2
2
|
// Agent37's cloud build, with the workspace's key in AGENT37_API_KEY, and print the template's name: an Agent37 desktop
|
|
3
3
|
// starts from it (src/descriptors/agent37.ts AGENT37_BOX_TEMPLATE), and so can an Archil computer.
|
|
4
4
|
//
|
|
5
5
|
// Agent37 keeps a template's revisions under one name (docs: agents-api/templates), so the name is fixed, agentrun-box,
|
|
6
|
-
// and the recipe's hash (the Dockerfile
|
|
6
|
+
// and the recipe's hash (recipe.mjs: the Dockerfile and the files it copies) goes in the template's description: a
|
|
7
7
|
// workspace whose template already names this hash is built nothing, and a changed recipe publishes a new revision,
|
|
8
8
|
// which every instance made after it starts from. Builds are free, at most three at once per workspace and 45 minutes
|
|
9
9
|
// each. The calls, in order (docs: templates, "Build an image in the cloud"):
|
|
@@ -15,49 +15,30 @@
|
|
|
15
15
|
// GET /v1/template-builds/{id}/logs?offset=N until status succeeded or failed (a poll registers the template)
|
|
16
16
|
//
|
|
17
17
|
// AGENT37_API_KEY=... node packages/computer/box/build-agent37.mjs
|
|
18
|
-
import { createHash } from "node:crypto";
|
|
19
18
|
import { readFileSync } from "node:fs";
|
|
20
19
|
import { dirname, join } from "node:path";
|
|
21
20
|
import { fileURLToPath } from "node:url";
|
|
22
21
|
import { gzipSync } from "node:zlib";
|
|
22
|
+
import { RECIPE, recipeHash } from "./recipe.mjs";
|
|
23
23
|
|
|
24
24
|
/** The template's name in every workspace: AGENT37_BOX_TEMPLATE. */
|
|
25
25
|
export const NAME = "agentrun-box";
|
|
26
26
|
export const API_URL = "https://api.agent37.com";
|
|
27
|
-
/** Every file the image is made of
|
|
28
|
-
export
|
|
29
|
-
/**
|
|
30
|
-
* What a desktop adds to box/Dockerfile: Xvfb, which the provider starts through computerd as the tool user on :0
|
|
31
|
-
* (src/desktop.ts). Nothing starts it here, and no window manager, VNC server or sudo comes with it.
|
|
32
|
-
*/
|
|
33
|
-
export const DESKTOP = `
|
|
34
|
-
# A desktop (build-agent37.mjs): Xvfb, which the provider starts through computerd as the tool user on :0.
|
|
35
|
-
RUN set -eu; \\
|
|
36
|
-
apt-get update -qq; \\
|
|
37
|
-
DEBIAN_FRONTEND=noninteractive apt-get install -y -qq --no-install-recommends xvfb >/dev/null; \\
|
|
38
|
-
rm -rf /var/lib/apt/lists/*; \\
|
|
39
|
-
command -v Xvfb >/dev/null || { echo "the image has no Xvfb" >&2; exit 1; }; \\
|
|
40
|
-
! command -v sudo >/dev/null 2>&1 || { echo "the image has sudo" >&2; exit 1; }
|
|
41
|
-
`;
|
|
27
|
+
/** Every file the image is made of: the Dockerfile (its desktop included) and what it copies (recipe.mjs). */
|
|
28
|
+
export { RECIPE };
|
|
42
29
|
/** How often a build's log is read, and the longest a build is waited for: Agent37's 45 minutes, and some. */
|
|
43
30
|
const POLL_MS = 5_000;
|
|
44
31
|
const BUILD_MS = 50 * 60_000;
|
|
45
32
|
|
|
46
33
|
const here = dirname(fileURLToPath(import.meta.url));
|
|
47
34
|
|
|
48
|
-
/** The recipe's files, read from dir,
|
|
35
|
+
/** The recipe's files, read from dir, and its 12-hex hash: recipe.mjs's, the one every build and the published image carry. */
|
|
49
36
|
export function recipeOf(dir = here) {
|
|
50
|
-
|
|
51
|
-
const dockerfile = Buffer.concat([files.Dockerfile, Buffer.from(DESKTOP)]);
|
|
52
|
-
const hash = createHash("sha256")
|
|
53
|
-
.update(Buffer.concat([...RECIPE.map((name) => files[name]), Buffer.from(DESKTOP)]))
|
|
54
|
-
.digest("hex")
|
|
55
|
-
.slice(0, 12);
|
|
56
|
-
return { hash, files: { ...files, Dockerfile: dockerfile } };
|
|
37
|
+
return { hash: recipeHash(dir), files: Object.fromEntries(RECIPE.map((name) => [name, readFileSync(join(dir, name))])) };
|
|
57
38
|
}
|
|
58
39
|
|
|
59
40
|
/** The template's description: the recipe's hash is how a later build knows this one is current. */
|
|
60
|
-
export const descriptionOf = (hash) => `AgentRun's box image (Archil client and helper, tool user, Xvfb), recipe ${hash}`;
|
|
41
|
+
export const descriptionOf = (hash) => `AgentRun's box image (Archil client and helper, tool user, Xvfb, xfwm4 and apps), recipe ${hash}`;
|
|
61
42
|
|
|
62
43
|
/** One ustar header block: a file at the archive's root, owned by root. */
|
|
63
44
|
function header(name, mode, size) {
|
package/box/build-daytona.py
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Build the Archil image (this folder's Dockerfile) as a Daytona snapshot, with Daytona's Python SDK (`pip install
|
|
2
|
-
# daytona`) and its key in DAYTONA_API_KEY, and print the snapshot's name
|
|
3
|
-
#
|
|
2
|
+
# daytona`) and its key in DAYTONA_API_KEY, and print the snapshot's name, which a Daytona computer's spec names as its
|
|
3
|
+
# image (no Daytona computer takes an Archil mount: Archil's client hangs on its sandboxes). The name is the recipe's hash (the Dockerfile and the files it copies), so a changed recipe is
|
|
4
4
|
# a new snapshot, and the same recipe is the one built before: Daytona then refuses the name, and the printed name is
|
|
5
5
|
# the one to use. Its size is 2 CPUs, 4 GB of memory and a 10 GB disk.
|
|
6
6
|
#
|
package/box/build-e2b.mjs
CHANGED
|
@@ -1,32 +1,55 @@
|
|
|
1
|
-
// Build the Archil image
|
|
2
|
-
// the
|
|
3
|
-
//
|
|
4
|
-
//
|
|
5
|
-
// and 4 GB of memory.
|
|
1
|
+
// Build the Archil image as an E2B template, with the host's own e2b SDK (in this repository, the root devDependency
|
|
2
|
+
// the lock pins) and its key in E2B_API_KEY, and print the template's name: an E2B computer with an Archil mount names it
|
|
3
|
+
// as its spec's image. The name is agentrun-archil-<the recipe's hash> (recipe.mjs), so a changed recipe is a new
|
|
4
|
+
// template, and the same recipe is the one built before (E2B's cache). Its size is 2 CPUs and 4 GB of memory.
|
|
6
5
|
//
|
|
7
|
-
// E2B_API_KEY=... node packages/computer/box/build-e2b.mjs
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
// E2B_API_KEY=... node packages/computer/box/build-e2b.mjs [--image <ref>] [--public]
|
|
7
|
+
//
|
|
8
|
+
// With no --image it builds this folder's Dockerfile. --image builds from the published box image instead
|
|
9
|
+
// (ghcr.io/parcha-ai/agentrun-box:<the recipe's hash>, release.yml's box job), whose tag must be this recipe's hash; on
|
|
10
|
+
// it the Dockerfile's sudo guard runs again, and its USER and CMD are the template's (recipe.mjs onImage).
|
|
11
|
+
//
|
|
12
|
+
// --public makes the template public once it is built (E2B's v2 PATCH /v2/templates/{id}, public: true), so another
|
|
13
|
+
// team's sandbox starts from it, and prints the names E2B gives it. release.yml's box-e2b job runs both.
|
|
10
14
|
import { dirname, join } from "node:path";
|
|
11
15
|
import { fileURLToPath } from "node:url";
|
|
16
|
+
import { parseArgs } from "node:util";
|
|
17
|
+
import { onImage, recipeHash } from "./recipe.mjs";
|
|
18
|
+
|
|
19
|
+
const here = dirname(fileURLToPath(import.meta.url));
|
|
20
|
+
const hash = recipeHash(here);
|
|
21
|
+
const name = "agentrun-archil-" + hash;
|
|
12
22
|
|
|
23
|
+
const { values } = parseArgs({ options: { image: { type: "string" }, public: { type: "boolean", default: false } } });
|
|
24
|
+
if (values.image !== undefined && !values.image.endsWith(`:${hash}`)) {
|
|
25
|
+
console.error(`build-e2b: ${values.image} is not this recipe's image: its tag must be the recipe's hash, ${hash}`);
|
|
26
|
+
process.exit(2);
|
|
27
|
+
}
|
|
28
|
+
if (!process.env.E2B_API_KEY) {
|
|
29
|
+
console.error("build-e2b: set E2B_API_KEY to the key of the E2B team the template is built in");
|
|
30
|
+
process.exit(2);
|
|
31
|
+
}
|
|
13
32
|
/** The host's own SDK, as the E2B provider takes it: by a name that is not a literal, never this package's dependency. */
|
|
14
33
|
const E2B_PACKAGE = "e2b";
|
|
15
|
-
const { Template } = await import(E2B_PACKAGE).catch(() => {
|
|
34
|
+
const { Template, ApiClient, ConnectionConfig } = await import(E2B_PACKAGE).catch(() => {
|
|
16
35
|
console.error(`build-e2b: the ${E2B_PACKAGE} package is not installed: run npm ci at the repository root (it is a root devDependency there), or install ${E2B_PACKAGE} beside this script`);
|
|
17
36
|
process.exit(2);
|
|
18
37
|
});
|
|
19
|
-
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
const RECIPE = ["Dockerfile", "agentrun-archil"];
|
|
23
|
-
const recipe = Buffer.concat(RECIPE.map((name) => readFileSync(join(here, name))));
|
|
24
|
-
const name = "agentrun-archil-" + createHash("sha256").update(recipe).digest("hex").slice(0, 12);
|
|
25
|
-
console.error(`build-e2b: template ${name}`);
|
|
26
|
-
const template = Template({ fileContextPath: here }).fromDockerfile(join(here, "Dockerfile"));
|
|
27
|
-
await Template.build(template, name, {
|
|
38
|
+
console.error(`build-e2b: template ${name}${values.image ? ` from ${values.image}` : ""}`);
|
|
39
|
+
const template = Template({ fileContextPath: here }).fromDockerfile(values.image ? onImage(values.image) : join(here, "Dockerfile"));
|
|
40
|
+
const built = await Template.build(template, name, {
|
|
28
41
|
cpuCount: 2,
|
|
29
42
|
memoryMB: 4096,
|
|
30
43
|
onBuildLogs: (entry) => console.error(String(entry?.message ?? entry)),
|
|
31
44
|
});
|
|
45
|
+
if (values.public) {
|
|
46
|
+
const client = new ApiClient(new ConnectionConfig({ apiKey: process.env.E2B_API_KEY }));
|
|
47
|
+
const { data, error, response } = await client.api.PATCH("/v2/templates/{templateID}", { params: { path: { templateID: built.templateId } }, body: { public: true } });
|
|
48
|
+
if (error) {
|
|
49
|
+
console.error(`build-e2b: making ${name} public failed: ${response.status} ${error.message ?? JSON.stringify(error)}`);
|
|
50
|
+
process.exit(1);
|
|
51
|
+
}
|
|
52
|
+
console.error(`build-e2b: ${name} is public as ${data.names.join(", ")}`);
|
|
53
|
+
console.log(`public=${data.names.join(",")}`);
|
|
54
|
+
}
|
|
32
55
|
console.log(`template=${name}`);
|
package/box/recipe.mjs
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
// The box image's recipe: the files it is made of (this folder's Dockerfile and what it copies) and their hash, the
|
|
2
|
+
// first 12 hex of their sha256. Every build names what it makes by that hash, so a changed recipe is a new image and the
|
|
3
|
+
// same recipe is the one built before: the E2B template agentrun-archil-<hash> (build-e2b.mjs), the Daytona snapshot
|
|
4
|
+
// of the same name (build-daytona.py hashes the same files), and the published image ghcr.io/parcha-ai/agentrun-box:<hash>
|
|
5
|
+
// (release.yml's box job reads recipeHash()).
|
|
6
|
+
//
|
|
7
|
+
// And the E2B template's Dockerfile on that published image (build-e2b.mjs --image): E2B's builder provisions a base
|
|
8
|
+
// before a template's steps, sudo among what it adds (the Dockerfile says so), so on the image the Dockerfile's sudo
|
|
9
|
+
// guard runs again, as root, and its USER and CMD are the template's.
|
|
10
|
+
import { createHash } from "node:crypto";
|
|
11
|
+
import { readFileSync } from "node:fs";
|
|
12
|
+
import { dirname, join } from "node:path";
|
|
13
|
+
import { fileURLToPath } from "node:url";
|
|
14
|
+
|
|
15
|
+
/** Every file the image is made of: the Dockerfile and what it copies. */
|
|
16
|
+
export const RECIPE = ["Dockerfile", "agentrun-archil"];
|
|
17
|
+
|
|
18
|
+
const here = dirname(fileURLToPath(import.meta.url));
|
|
19
|
+
|
|
20
|
+
/** The recipe's hash, read from dir: 12 hex. */
|
|
21
|
+
export function recipeHash(dir = here) {
|
|
22
|
+
const recipe = Buffer.concat(RECIPE.map((name) => readFileSync(join(dir, name))));
|
|
23
|
+
return createHash("sha256").update(recipe).digest("hex").slice(0, 12);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** The Dockerfile's first instruction that pattern matches, its continuation lines kept. */
|
|
27
|
+
export function instructionMatching(dockerfile, pattern) {
|
|
28
|
+
const lines = dockerfile.split("\n");
|
|
29
|
+
for (let start = 0; start < lines.length; start++) {
|
|
30
|
+
if (!/^[A-Z]+ /.test(lines[start])) continue;
|
|
31
|
+
let end = start;
|
|
32
|
+
while (lines[end].endsWith("\\") && end + 1 < lines.length) end++;
|
|
33
|
+
const instruction = lines.slice(start, end + 1).join("\n");
|
|
34
|
+
if (pattern.test(instruction)) return instruction;
|
|
35
|
+
start = end;
|
|
36
|
+
}
|
|
37
|
+
throw new Error(`the box Dockerfile has no instruction matching ${pattern}`);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** The template's Dockerfile on the published image: the image, the Dockerfile's sudo guard again, its USER and CMD. */
|
|
41
|
+
export function onImage(image, dockerfile = readFileSync(join(here, "Dockerfile"), "utf8")) {
|
|
42
|
+
return [`FROM ${image}`, ...[/^RUN [^]*dpkg -s sudo/, /^USER /, /^CMD /].map((pattern) => instructionMatching(dockerfile, pattern))].join("\n") + "\n";
|
|
43
|
+
}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { Duplex } from "node:stream";
|
|
2
|
+
import type { HostCall, MachineProcess } from "./host.js";
|
|
3
|
+
/** A readable side of an ssh2 channel, as this provider uses it: piped, or drained. */
|
|
4
|
+
export interface Ssh2Readable {
|
|
5
|
+
pipe(destination: NodeJS.WritableStream): unknown;
|
|
6
|
+
resume(): unknown;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* The slice of an ssh2 channel this provider uses (ssh2@1.17.0 lib/Channel.js): the channel is stdout. No signal
|
|
10
|
+
* request: ssh2 sends one only while stdin is open (Channel.js:237-246), so a kill goes by the process group instead.
|
|
11
|
+
*/
|
|
12
|
+
export interface Ssh2Channel extends Ssh2Readable {
|
|
13
|
+
readonly stderr: Ssh2Readable;
|
|
14
|
+
write(data: Uint8Array, callback?: (error?: Error | null) => void): boolean;
|
|
15
|
+
/** Sends end of file on stdin and keeps the channel open (Channel.js:200-205). */
|
|
16
|
+
eof(): void;
|
|
17
|
+
close(): void;
|
|
18
|
+
/** exit-status, or exit-signal with a null code (client.js:666-678). */
|
|
19
|
+
on(event: "exit", listener: (code: number | null, signal?: string) => void): unknown;
|
|
20
|
+
on(event: "close", listener: () => void): unknown;
|
|
21
|
+
on(event: "error", listener: (error: Error) => void): unknown;
|
|
22
|
+
}
|
|
23
|
+
/** The options of ssh2's Client.connect this provider gives (ssh2@1.17.0 lib/client.js). */
|
|
24
|
+
export interface Ssh2ConnectConfig {
|
|
25
|
+
sock: Duplex;
|
|
26
|
+
username: "root";
|
|
27
|
+
privateKey: string;
|
|
28
|
+
readyTimeout: number;
|
|
29
|
+
keepaliveInterval: number;
|
|
30
|
+
keepaliveCountMax: number;
|
|
31
|
+
}
|
|
32
|
+
/** The slice of an ssh2 Client this provider uses. */
|
|
33
|
+
export interface Ssh2Client {
|
|
34
|
+
connect(config: Ssh2ConnectConfig): unknown;
|
|
35
|
+
exec(command: string, callback: (error: Error | undefined, channel: Ssh2Channel) => void): unknown;
|
|
36
|
+
end(): unknown;
|
|
37
|
+
destroy(): unknown;
|
|
38
|
+
once(event: "ready", listener: () => void): unknown;
|
|
39
|
+
once(event: "error", listener: (error: Error) => void): unknown;
|
|
40
|
+
on(event: "error", listener: (error: Error) => void): unknown;
|
|
41
|
+
on(event: "close" | "end", listener: () => void): unknown;
|
|
42
|
+
removeListener(event: "error", listener: (error: Error) => void): unknown;
|
|
43
|
+
}
|
|
44
|
+
/** The ssh2 package as this provider uses it: its Client class. The host's own, or anything with the same slice. */
|
|
45
|
+
export interface Ssh2Module {
|
|
46
|
+
Client: new () => Ssh2Client;
|
|
47
|
+
}
|
|
48
|
+
/** A tunnel failed before its SSH handshake, or while it carried the stream: the one failure a retry may repeat. */
|
|
49
|
+
export declare class SshTunnelError extends Error {
|
|
50
|
+
name: string;
|
|
51
|
+
}
|
|
52
|
+
/** One stream to a machine's sshd, as a vendor's hook gives it: its bytes as a Duplex, resolved once open, and the host named in words. */
|
|
53
|
+
export interface SshTunnel {
|
|
54
|
+
duplex: Duplex;
|
|
55
|
+
/** Resolves once the stream is open; rejects (an SshTunnelError, for a retry) when it fails to open. */
|
|
56
|
+
opened: Promise<void>;
|
|
57
|
+
/** The host's name, in the words of an error. */
|
|
58
|
+
host: string;
|
|
59
|
+
}
|
|
60
|
+
/** How a vendor opens the stream to machine id's sshd: a fresh one per call, nothing started before it is used. */
|
|
61
|
+
export type SshTunnelOf = (id: string) => SshTunnel;
|
|
62
|
+
export interface SshExecOptions {
|
|
63
|
+
/** The host's own ssh2 package, or anything with the same slice. */
|
|
64
|
+
ssh2: Ssh2Module;
|
|
65
|
+
/** A private key in the PEM armor ssh2 reads (see pemOf). */
|
|
66
|
+
privateKey: string;
|
|
67
|
+
tunnelOf: SshTunnelOf;
|
|
68
|
+
}
|
|
69
|
+
/** MachineHost.exec over SSH: argv as root, as channels on one connection per machine, shared by its execs. */
|
|
70
|
+
export declare class SshExec {
|
|
71
|
+
#private;
|
|
72
|
+
constructor({ ssh2, privateKey, tunnelOf }: SshExecOptions);
|
|
73
|
+
/** Ends every connection to machine id, channels and all: the vendor calls it once the machine is deleted. */
|
|
74
|
+
closeAll(id: string): void;
|
|
75
|
+
/**
|
|
76
|
+
* argv as root over SSH, under WRAPPER, as one channel on the machine's shared connection (#start). stdout and
|
|
77
|
+
* stderr are the channel's, piped; end sends end of file. wait answers once the channel closes, with the
|
|
78
|
+
* exit-status, or -1 for an exit by signal or none. kill ends the process group over a channel of its own (on a
|
|
79
|
+
* connection with room), then closes the exec's channel, never a connection; if the close does not come, wait
|
|
80
|
+
* answers -1 and the connection takes no new channel.
|
|
81
|
+
*/
|
|
82
|
+
exec(id: string, argv: readonly string[], ctx: HostCall): Promise<MachineProcess>;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* A private key in the PEM armor ssh2 reads (its parser wants the BEGIN and END lines on lines of their own), or
|
|
86
|
+
* undefined when text is not one. A key pasted into Settings → Computers comes back on one line, since a password
|
|
87
|
+
* field drops line breaks: its body is wrapped again at 70 characters, as ssh-keygen writes it.
|
|
88
|
+
*/
|
|
89
|
+
export declare function pemOf(text: string): string | undefined;
|