@parcha/agentrun-computer 0.1.0-beta.44 → 0.1.0-beta.46
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 +39 -9
- package/box/Dockerfile +2 -1
- package/box/install.sh +19 -5
- package/dist/attach.d.ts +13 -3
- package/dist/attach.js +182 -15
- package/dist/cloudflare.d.ts +4 -2
- package/dist/cloudflare.js +7 -3
- package/dist/computerd-linux-amd64 +0 -0
- package/dist/computerd-linux-arm64 +0 -0
- package/dist/computerd.json +2 -2
- package/dist/conformance/cases/files.js +7 -1
- package/dist/conformance/cases/mount.js +155 -2
- package/dist/conformance/cases/provider.js +3 -1
- package/dist/conformance/types.d.ts +1 -1
- package/dist/daytona.d.ts +5 -2
- package/dist/daytona.js +8 -4
- package/dist/descriptor.d.ts +34 -4
- package/dist/descriptor.js +40 -6
- package/dist/descriptors/cloudflare.d.ts +14 -1
- package/dist/descriptors/cloudflare.js +7 -3
- package/dist/descriptors/daytona.d.ts +17 -3
- package/dist/descriptors/daytona.js +12 -8
- package/dist/descriptors/e2b.d.ts +1 -0
- package/dist/descriptors/e2b.js +2 -1
- package/dist/descriptors/fly.d.ts +14 -1
- package/dist/descriptors/fly.js +6 -3
- package/dist/descriptors/index.d.ts +60 -2
- package/dist/descriptors/modal.d.ts +16 -2
- package/dist/descriptors/modal.js +10 -6
- package/dist/descriptors/orgo.d.ts +3 -0
- package/dist/descriptors/orgo.js +3 -1
- package/dist/e2b.d.ts +9 -4
- package/dist/e2b.js +8 -8
- package/dist/env-proxy.d.ts +26 -0
- package/dist/env-proxy.js +97 -0
- package/dist/fly.d.ts +4 -3
- package/dist/fly.js +7 -4
- package/dist/hosted/provider.d.ts +2 -1
- package/dist/hosted/provider.js +133 -54
- package/dist/hosted/scripts.d.ts +3 -2
- package/dist/hosted/scripts.js +12 -7
- package/dist/hosted/values.d.ts +2 -5
- package/dist/hosted/values.js +2 -9
- package/dist/index.d.ts +4 -2
- package/dist/index.js +4 -2
- package/dist/kinds.d.ts +4 -2
- package/dist/kinds.js +10 -1
- package/dist/modal.d.ts +5 -2
- package/dist/modal.js +8 -2
- package/dist/morph.js +15 -7
- package/dist/mount-archil.d.ts +33 -17
- package/dist/mount-archil.js +83 -36
- package/dist/mount.d.ts +16 -7
- package/dist/mount.js +13 -8
- package/dist/orgo.js +1 -1
- package/dist/provider.d.ts +1 -1
- package/dist/sync-folder.d.ts +82 -0
- package/dist/sync-folder.js +494 -0
- package/dist/tar.d.ts +34 -0
- package/dist/tar.js +203 -0
- package/package.json +1 -1
- package/dist/conformance/tar.d.ts +0 -13
- package/dist/conformance/tar.js +0 -105
package/README.md
CHANGED
|
@@ -181,8 +181,8 @@ extension](#the-protocol-extension-kind-daemon-modes-screen-input-apps-lifetime)
|
|
|
181
181
|
`--own-network` needs, or `--cap-add ALL`, as 1000:1000, the refusal of 0:0 and the refusal without CAP_SETPCAP), and
|
|
182
182
|
computerd's end at its deadline with the Docker live tests. The test binaries (`CGO_ENABLED=0 go test -c`) also run
|
|
183
183
|
as root in a container by hand: `internal/isolate`'s and the isolated `TestBecome...` need CAP_SYS_ADMIN and
|
|
184
|
-
CAP_NET_ADMIN (`docker run --cap-add SYS_ADMIN --cap-add NET_ADMIN`), and the refusal without them a
|
|
185
|
-
with Docker's defaults.
|
|
184
|
+
CAP_NET_ADMIN (`docker run --cap-add SYS_ADMIN --cap-add NET_ADMIN`), and the refusal without them needs a
|
|
185
|
+
container with Docker's defaults.
|
|
186
186
|
- `computerd probe [--sockets] [--connect <host:port>[/udp]]...` prints one JSON line: the uid and gid it runs as, the
|
|
187
187
|
kernel's release, `interfaces` (the network interfaces its network namespace holds: `["lo"]` alone under
|
|
188
188
|
`--own-network`), `reached` (the targets that answered), `accepted` (the targets that accepted a TCP connection and
|
|
@@ -197,12 +197,19 @@ extension](#the-protocol-extension-kind-daemon-modes-screen-input-apps-lifetime)
|
|
|
197
197
|
[Network none, read from inside](#network-none-read-from-inside-nothing-answers). `computerd probe --diagnose` asks
|
|
198
198
|
more: for 1.1.1.1, 8.8.8.8, 9.9.9.9 and 151.101.1.57 (Fastly's anycast edge, which is no resolver) on 443/tcp,
|
|
199
199
|
80/tcp and 53/udp it reports `refused` (no TCP accept, no UDP answer), `accepted` (an accept, no answer) or
|
|
200
|
-
`answered` (a TLS ServerHello, an `HTTP/1
|
|
200
|
+
`answered` (a TLS ServerHello, an `HTTP/1.x` status line, a DNS response with the query's id), with 3 s to connect and
|
|
201
201
|
3 s to answer, 15 s in all and at most 4 KiB read per check, and a `verdict`: `egress`, `accepted-only` or `none`.
|
|
202
202
|
It sends nothing of the computer's: a ClientHello with a random nonce, `HEAD / HTTP/1.0`, a query for `example.com`.
|
|
203
203
|
- `computerd stdio` is a thin bridge: it connects to the socket (waiting up to 3 s for a computer that has just
|
|
204
204
|
started) and copies bytes both ways until either side ends. With no daemon to reach it says so on stderr and exits 1;
|
|
205
205
|
it never serves on its own.
|
|
206
|
+
- `computerd pair <server URL> [--name <name>]`, `computerd attach` and `computerd unpair` make a Linux box of your own
|
|
207
|
+
a paired computer: pair reads the console's code from stdin and keeps the token in a file only its user can read,
|
|
208
|
+
attach dials with it, unpair deletes it ([attach.md, A Linux box](../../spec/computer/attach.md#a-linux-box)). A box
|
|
209
|
+
with a display pairs as a desktop; one with none (a `linux` hello) pairs as a sandbox that holds a run's folder as a
|
|
210
|
+
synced folder in its `/workspace`, a directory of init's user's own, mode 0700, never a link, made once as root with
|
|
211
|
+
a tmpfiles.d line. A run's shell can read and write everything that user can, so make it a user of its own
|
|
212
|
+
(`useradd --system --create-home agentrun`, no lingering, no crontab), never a person's login user.
|
|
206
213
|
- Init is a child subreaper (PID 1 in Docker is one anyway) and reaps every orphan. It also sweeps, on each SIGCHLD and
|
|
207
214
|
once a second: a child of its own that is not one of its guards can only be an orphan whose guard died (a program can
|
|
208
215
|
kill its own guard, since both run as the same user), so it is killed with everything under it. A process orphaned by
|
|
@@ -681,6 +688,11 @@ setting:
|
|
|
681
688
|
- **E2B, `E2B_SANDBOX_URL`** (`ambientProblem` in `src/e2b.ts`). The SDK sends every sandbox call to it when it is set,
|
|
682
689
|
and no option clears it, so the provider refuses to start while it is set. It only reads.
|
|
683
690
|
|
|
691
|
+
A proxy isn't read from the environment either. E2B's SDK and Morph's SSH gateway, the two clients Node's own proxy
|
|
692
|
+
doesn't reach, follow the one the process installed into Node (`--use-env-proxy`, `NODE_USE_ENV_PROXY` or
|
|
693
|
+
`http.setGlobalProxyFromEnv`, which serve calls at start), as `fetch` does: `src/env-proxy.ts` reads it from Node's
|
|
694
|
+
`https.globalAgent`. A process that installed none has them go direct.
|
|
695
|
+
|
|
684
696
|
`scripts/check-env.mjs` holds the library to this: it reads every file under `src/` outside `src/conformance/`, those
|
|
685
697
|
in its directories (`src/docker/`) included, with TypeScript's parser and fails on any use of `process.env` (dotted,
|
|
686
698
|
bracketed, destructured, aliased, through `globalThis` or an import of `node:process`) but these two, each by its
|
|
@@ -1391,6 +1403,13 @@ conformance module's `dialKit()` refuses, as E2B's does: the Core run happens in
|
|
|
1391
1403
|
run image with `COMPUTER_MODAL_CONNECT=dial` is the box image, the one that holds `agentrun-dial` (debian:bookworm-slim
|
|
1392
1404
|
on exec, as before).
|
|
1393
1405
|
|
|
1406
|
+
A dial sandbox may be a desktop (`kind: "desktop"`): the box image's X server and xfwm4, started over the socket it
|
|
1407
|
+
dialed, at 2 CPUs and 4 GiB on the VM runtime, with no GPU. On exec a Modal computer is kind `linux` alone, and the
|
|
1408
|
+
constructor refuses `kind: "desktop"` in words. The descriptor's desktop configuration selects `connect: "dial"` itself,
|
|
1409
|
+
so a server whose `modalConnect` is exec still makes its desktop over dial (it needs the dial's public address). In
|
|
1410
|
+
serve's Mode 2 the run's folder is an Archil mount, which a dial machine takes none of yet, so a Modal desktop there is
|
|
1411
|
+
refused at `check()` in those words. **Unverified**: Xvfb and the window manager on Modal (no live run yet).
|
|
1412
|
+
|
|
1394
1413
|
## Daytona
|
|
1395
1414
|
|
|
1396
1415
|
```ts
|
|
@@ -1660,7 +1679,11 @@ default) a Daytona sandbox dials the server instead ([PROVIDERS.md](PROVIDERS.md
|
|
|
1660
1679
|
no exec and no upload, and nothing goes through the toolbox: create sends the boot env as `CreateSandbox.env` and
|
|
1661
1680
|
`networkBlockAll: false` (the machine's root reaches the server; network none is init's, inside), and the snapshot's
|
|
1662
1681
|
entrypoint runs `agentrun-dial`. No Archil mount, no GPU, and not `image: "default"` (Daytona's default snapshot holds
|
|
1663
|
-
no `agentrun-dial`): `check()` refuses each in words. Labels as on exec.
|
|
1682
|
+
no `agentrun-dial`): `check()` refuses each in words. Labels as on exec. A dial sandbox may be a desktop
|
|
1683
|
+
(`kind: "desktop"`): the box snapshot's X server and xfwm4, started over the socket it dialed, with the snapshot's 2 CPUs
|
|
1684
|
+
and 4 GB. On exec a Daytona computer is kind `linux` alone, and the constructor refuses `kind: "desktop"` in words. The
|
|
1685
|
+
descriptor's desktop configuration selects `connect: "dial"` itself, so a server whose `daytonaConnect` is exec still
|
|
1686
|
+
makes its desktop over dial. **Unverified**: Xvfb and the window manager on Daytona (no live run yet). What each part rests on:
|
|
1664
1687
|
|
|
1665
1688
|
- **A snapshot, never an image.** A create names a snapshot; a snapshot is made from "any publicly accessible image"
|
|
1666
1689
|
whose tag is not `latest`, `lts` or `stable` ([docs: create snapshots](https://www.daytona.io/docs/en/snapshots.md#create-snapshots)).
|
|
@@ -2036,9 +2059,12 @@ provider does in `process.env`. `COMPUTER_E2B_PUBLIC_STREAM` is no longer read.
|
|
|
2036
2059
|
### E2B on dial
|
|
2037
2060
|
|
|
2038
2061
|
With `connect: "dial"` (a server's `e2bConnect` setting; `exec` by default) an E2B sandbox dials the server instead
|
|
2039
|
-
([PROVIDERS.md](PROVIDERS.md#machines-that-dial-in)):
|
|
2040
|
-
|
|
2041
|
-
exec and no upload.
|
|
2062
|
+
([PROVIDERS.md](PROVIDERS.md#machines-that-dial-in)): a desktop by default, as on exec, since the box template has
|
|
2063
|
+
the desktop (`box/install.sh`'s `desktop` step), or kind linux; no Archil mount, and the host has no
|
|
2064
|
+
exec and no upload. A desktop's launch adds `DISPLAY` to the boot env, and its X server and xfwm4 start over the
|
|
2065
|
+
socket the sandbox dialed, through `process.start`. A dial desktop whose X server has gone is not refused at `connect()`
|
|
2066
|
+
as on exec: it reads back kind `linux`, and its screen, input, apps and ui calls are refused in words, never sent, until
|
|
2067
|
+
its hello says `desktop` again. E2B runs a template's start command once, at the template's build, and snapshots it running, so
|
|
2042
2068
|
it never sees a create's env ([docs.e2b.dev/template/start-ready-command](https://docs.e2b.dev/template/start-ready-command)).
|
|
2043
2069
|
So create starts the box template's `agentrun-dial` itself, once, right after `Sandbox.create`: one envd process as
|
|
2044
2070
|
root with the boot env as that process's env alone (never the sandbox's `envs`, which envd gives every process), after
|
|
@@ -3084,9 +3110,13 @@ fills, and whether it is required), `settings` (a setting that is no key but fil
|
|
|
3084
3110
|
`metered`, `mounts`, `network` (the network forms its computers make, at least one of none, open and allow),
|
|
3085
3111
|
`capabilities` (the kind and groups of each configuration), `defaultImage` (by setting kind),
|
|
3086
3112
|
`prepareImage` (a provider whose `prepareImage()` answers its image before a run: it builds, pulls or names it), `imageEnv` (the server's environment variable
|
|
3087
|
-
that, when set, names the image of every computer of the provider, as Daytona's `AGENTRUN_DAYTONA_SNAPSHOT`), `
|
|
3113
|
+
that, when set, names the image of every computer of the provider, as Daytona's `AGENTRUN_DAYTONA_SNAPSHOT`), `connect`
|
|
3114
|
+
(whether its machines dial the server: `dial` always, as Fly Machines' and Cloudflare's; `either`, as its `connect`
|
|
3115
|
+
option says, which one of its settings fills, as E2B's, Daytona's and Modal's; absent, never), `local`
|
|
3088
3116
|
(a computer on this host), and
|
|
3089
|
-
`ledger` (the option a provider's ledger fills). `
|
|
3117
|
+
`ledger` (the option a provider's ledger fills). `connectOf(descriptor, options)` answers `dial` or `exec` for a provider
|
|
3118
|
+
made with those options, without building it; its built host's `facts.connect` is the same answer, and a server reads
|
|
3119
|
+
it to say where its runs can't take a dial (a runner in a process of its own). `providerFor(id, options)` builds a provider by id from its options and
|
|
3090
3120
|
refuses an id it does not hold, naming the ones it does. The provider file, `src/<vendor>.ts`, exports what a
|
|
3091
3121
|
`ProviderModule` is:
|
|
3092
3122
|
|
package/box/Dockerfile
CHANGED
|
@@ -10,7 +10,8 @@
|
|
|
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; a synced folder's computer has it made the
|
|
14
|
+
# computer user's, 0700, before init (by the provider's install, or by agentrun-dial on a machine that dials);
|
|
14
15
|
# - a desktop, with nothing started: Xvfb and xfwm4 (with dbus-run-session, which xfconf's packages bring) and
|
|
15
16
|
# xsetroot (x11-xserver-utils, the desktop's background), which the provider starts through computerd as the tool
|
|
16
17
|
# user on :0 (src/desktop.ts), and the apps E2B Desktop has that are cheap to carry: Xfce's terminal and text editor,
|
package/box/install.sh
CHANGED
|
@@ -73,19 +73,32 @@ dial() {
|
|
|
73
73
|
# agentrun-dial (written by the box image's install.sh): a machine that dials the server. From the env the provider's
|
|
74
74
|
# create gave it, it fetches the server's computerd with the machine's token, checks its sha256, installs it root's alone
|
|
75
75
|
# where the provider's exec install puts it, starts `computerd init` as that start does, in a clean environment without
|
|
76
|
-
# the token, and becomes `computerd attach` with the attach URL and the token alone in its environment.
|
|
77
|
-
#
|
|
78
|
-
#
|
|
76
|
+
# the token (with DISPLAY, for a desktop), and becomes `computerd attach` with the attach URL and the token alone in its environment. Before init, it
|
|
77
|
+
# gives /workspace to init's user (its --user), 0700, where a synced folder's runner pushes the run's folder. A daemon
|
|
78
|
+
# whose sha256 is not AGENTRUN_DAEMON_SHA256 is removed, and nothing runs. Exits 2 for env missing, 3 when the fetch
|
|
79
|
+
# failed, 4 for a sha256 mismatch, 5 when init never listened, 6 when /workspace was not made init's user's; else it is
|
|
80
|
+
# `computerd attach` and exits as it does.
|
|
79
81
|
set -euf
|
|
80
82
|
DAEMON=/opt/agentrun/computerd
|
|
81
83
|
HOME_DIR=/work
|
|
82
84
|
SOCKET_DIR=/run/agentrun
|
|
83
85
|
INIT_LOG=/run/agentrun-init.log
|
|
86
|
+
WORKSPACE=/workspace
|
|
84
87
|
OWNER=0:0
|
|
85
88
|
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
|
|
86
89
|
for v in AGENTRUN_ATTACH_URL AGENTRUN_ATTACH_TOKEN AGENTRUN_DAEMON_URL AGENTRUN_DAEMON_SHA256 AGENTRUN_INIT_ARGS; do
|
|
87
90
|
eval "[ -n \"\${$v-}\" ]" || { echo "agentrun-dial: $v is not set; the provider's create sets it" >&2; exit 2; }
|
|
88
91
|
done
|
|
92
|
+
# init's user, uid:gid, from its --user: /workspace is that user's alone, never a link.
|
|
93
|
+
user=
|
|
94
|
+
set -- $AGENTRUN_INIT_ARGS
|
|
95
|
+
while [ $# -gt 1 ]; do
|
|
96
|
+
[ "$1" != --user ] || user=$2
|
|
97
|
+
shift
|
|
98
|
+
done
|
|
99
|
+
[ -n "$user" ] || { echo "agentrun-dial: AGENTRUN_INIT_ARGS names no --user; the provider's create sets it" >&2; exit 2; }
|
|
100
|
+
{ [ ! -L "$WORKSPACE" ] && mkdir -p "$WORKSPACE" && chown "$user" "$WORKSPACE" && chmod 0700 "$WORKSPACE"; } ||
|
|
101
|
+
{ echo "agentrun-dial: $WORKSPACE was not made $user's" >&2; exit 6; }
|
|
89
102
|
mkdir -p "${DAEMON%/*}" "$HOME_DIR" "$SOCKET_DIR"
|
|
90
103
|
chown "$OWNER" "${DAEMON%/*}" "$SOCKET_DIR"
|
|
91
104
|
chmod 0755 "${DAEMON%/*}"
|
|
@@ -105,8 +118,9 @@ fi
|
|
|
105
118
|
chown "$OWNER" "$DAEMON.part"
|
|
106
119
|
chmod 0755 "$DAEMON.part"
|
|
107
120
|
mv -f "$DAEMON.part" "$DAEMON"
|
|
108
|
-
# init's arguments are words with no space and no pattern (set -f): split, never globbed.
|
|
109
|
-
|
|
121
|
+
# init's arguments are words with no space and no pattern (set -f): split, never globbed. A desktop's create sets
|
|
122
|
+
# DISPLAY, the display init's screen and input methods drive, as the provider's exec start gives it.
|
|
123
|
+
env -i PATH="$PATH" HOME="$HOME_DIR" AGENTRUN_COMPUTERD_SOCKET="$SOCKET_DIR/computerd.sock" ${DISPLAY:+DISPLAY="$DISPLAY"} \
|
|
110
124
|
setsid sh -c 'cd "$HOME" && exec "$@"' sh "$DAEMON" init $AGENTRUN_INIT_ARGS >"$INIT_LOG" 2>&1 </dev/null &
|
|
111
125
|
i=0
|
|
112
126
|
until [ -S "$SOCKET_DIR/computerd.sock" ]; do
|
package/dist/attach.d.ts
CHANGED
|
@@ -28,7 +28,7 @@ export declare const ATTACH_CLOSE: {
|
|
|
28
28
|
readonly binary: 1003;
|
|
29
29
|
/** A frame over maxLineBytes. */
|
|
30
30
|
readonly tooBig: 1009;
|
|
31
|
-
/** The computer's hello is not what it paired as (another kind or
|
|
31
|
+
/** The computer's hello is not what it paired as (another kind, os or arch): pair again. */
|
|
32
32
|
readonly mismatch: 4400;
|
|
33
33
|
/** The token is unknown or was revoked: pair again. */
|
|
34
34
|
readonly unauthorized: 4401;
|
|
@@ -81,7 +81,7 @@ export declare function socketStreams(socket: AttachSocket): {
|
|
|
81
81
|
export interface PairedComputer {
|
|
82
82
|
id: string;
|
|
83
83
|
name: string;
|
|
84
|
-
/** What it paired as: its hello at pairing. A later hello of another kind or
|
|
84
|
+
/** What it paired as: its hello at pairing. A later hello of another kind, os or arch is refused (ATTACH_CLOSE.mismatch). */
|
|
85
85
|
hello: HelloResult;
|
|
86
86
|
labels: Record<string, string>;
|
|
87
87
|
/** A hosted machine that dials with a minted token (mintedComputer), not a person's: its hello keeps its arch too. */
|
|
@@ -95,6 +95,9 @@ export interface MachineMint {
|
|
|
95
95
|
arch: string;
|
|
96
96
|
/** The machine's backstopAt: past it the token is refused, whatever else holds. */
|
|
97
97
|
expiresAt: Date;
|
|
98
|
+
/** The run the machine works for, as its create's labels name it (RUN_LABEL): what a server's words about its dial
|
|
99
|
+
* name. Absent for a computer of no run. */
|
|
100
|
+
run?: string;
|
|
98
101
|
}
|
|
99
102
|
/**
|
|
100
103
|
* The tokens of hosted machines that dial (spec/computer/attach.md, Hosted machines that dial), as the server's store
|
|
@@ -109,6 +112,10 @@ export interface MachineTokens {
|
|
|
109
112
|
mint(machine: string, mint: MachineMint): Promise<string>;
|
|
110
113
|
/** The machine's token refused from now on; a machine with none is done. */
|
|
111
114
|
revoke(machine: string): Promise<void>;
|
|
115
|
+
/** Why the server refused the machine's dial, in its words (a relay to the runner that minted the token, serve's
|
|
116
|
+
* dial-relay.ts, that it could not make): they name the machine's run, then the machine, and never its token.
|
|
117
|
+
* Undefined while none was refused. A create waiting for the machine's socket ends in these words. */
|
|
118
|
+
refused(machine: string): Promise<string | undefined>;
|
|
112
119
|
}
|
|
113
120
|
/**
|
|
114
121
|
* MachineTokens in one process's memory, as serve's store keeps them (the sha256 alone): for tests and a conformance
|
|
@@ -118,6 +125,7 @@ export declare class MemoryMachineTokens implements MachineTokens {
|
|
|
118
125
|
#private;
|
|
119
126
|
mint(machine: string, mint: MachineMint): Promise<string>;
|
|
120
127
|
revoke(machine: string): Promise<void>;
|
|
128
|
+
refused(_machine: string): Promise<string | undefined>;
|
|
121
129
|
/** The machine and mint a token is good for at `at`: undefined for one unknown, revoked, or past its expiresAt. */
|
|
122
130
|
check(token: string, at?: Date): {
|
|
123
131
|
machine: string;
|
|
@@ -186,6 +194,8 @@ export declare class AttachHub {
|
|
|
186
194
|
/**
|
|
187
195
|
* One paired computer as a provider, id "attached": its capabilities are what it paired as. create claims it for a
|
|
188
196
|
* run (refused while it is offline or another run holds it) and release ends the claim; a person's machine is never
|
|
189
|
-
* made, stopped or deleted by a run.
|
|
197
|
+
* made, stopped or deleted by a run. A desktop or a phone has no init of ours, so its daemon mode is none; a Linux box
|
|
198
|
+
* (kind linux, a sandbox) runs computerd init, a child of its service manager, and takes the run's folder as a synced
|
|
199
|
+
* folder in its /workspace (pairedWorkspaceWhy), read back under the run's claim epoch.
|
|
190
200
|
*/
|
|
191
201
|
export declare function attachedProvider(paired: PairedComputer, hub: AttachHub): ComputerProvider;
|
package/dist/attach.js
CHANGED
|
@@ -7,6 +7,8 @@ import { createHash, randomBytes, randomUUID } from "node:crypto";
|
|
|
7
7
|
import { PassThrough, Writable } from "node:stream";
|
|
8
8
|
import { DaemonClient } from "./client.js";
|
|
9
9
|
import { kindServed } from "./kinds.js";
|
|
10
|
+
import { EPOCH_LABEL, epochOf } from "./labels.js";
|
|
11
|
+
import { checkMount, WORKSPACE } from "./mount.js";
|
|
10
12
|
import { PROTOCOL_VERSION } from "./protocol.js";
|
|
11
13
|
import { checkLifetime, kindRefusals, runLifetimeMs } from "./provider.js";
|
|
12
14
|
import { fail, ok } from "./result.js";
|
|
@@ -36,7 +38,7 @@ export const ATTACH_CLOSE = {
|
|
|
36
38
|
binary: 1003,
|
|
37
39
|
/** A frame over maxLineBytes. */
|
|
38
40
|
tooBig: 1009,
|
|
39
|
-
/** The computer's hello is not what it paired as (another kind or
|
|
41
|
+
/** The computer's hello is not what it paired as (another kind, os or arch): pair again. */
|
|
40
42
|
mismatch: 4400,
|
|
41
43
|
/** The token is unknown or was revoked: pair again. */
|
|
42
44
|
unauthorized: 4401,
|
|
@@ -110,6 +112,10 @@ export class MemoryMachineTokens {
|
|
|
110
112
|
async revoke(machine) {
|
|
111
113
|
this.#drop(machine);
|
|
112
114
|
}
|
|
115
|
+
// One process: its own attach route takes every dial, and no relay to a runner apart is refused.
|
|
116
|
+
async refused(_machine) {
|
|
117
|
+
return undefined;
|
|
118
|
+
}
|
|
113
119
|
#drop(machine) {
|
|
114
120
|
this.#held.delete(this.#hashOf.get(machine) ?? "");
|
|
115
121
|
this.#hashOf.delete(machine);
|
|
@@ -160,12 +166,19 @@ export function helloMismatch(paired, hello) {
|
|
|
160
166
|
if (missing.length > 0) {
|
|
161
167
|
return { code: ATTACH_CLOSE.protocol, message: `${paired.name}'s driver ${hello.version} answered a protocol ${PROTOCOL_VERSION} hello without ${missing.join(", ")}: ${update}` };
|
|
162
168
|
}
|
|
163
|
-
if (paired.minted
|
|
164
|
-
|
|
165
|
-
|
|
169
|
+
if (paired.minted) {
|
|
170
|
+
// A minted desktop says linux until its display answers: its create starts the X server over this socket (desktop.ts).
|
|
171
|
+
const kind = hello.kind === paired.hello.kind || (paired.hello.kind === "desktop" && hello.kind === "linux");
|
|
172
|
+
if (!kind || hello.os !== paired.hello.os || hello.arch !== paired.hello.arch) {
|
|
173
|
+
const was = paired.hello;
|
|
174
|
+
return { code: ATTACH_CLOSE.mismatch, message: `${paired.name} was made a ${was.os} ${was.kind} on ${was.arch} and says ${hello.os} ${hello.kind} on ${hello.arch}: its token is that machine's alone` };
|
|
175
|
+
}
|
|
166
176
|
}
|
|
167
|
-
if (hello.kind !== paired.hello.kind || hello.os !== paired.hello.os) {
|
|
168
|
-
|
|
177
|
+
else if (hello.kind !== paired.hello.kind || hello.os !== paired.hello.os || (hello.arch !== paired.hello.arch && paired.hello.os !== "macos")) {
|
|
178
|
+
// Its arch too, so a token copied to a machine of another arch is refused; but a Mac's: its driver may move from
|
|
179
|
+
// amd64 (under Rosetta) to arm64 on the same machine.
|
|
180
|
+
const was = paired.hello;
|
|
181
|
+
return { code: ATTACH_CLOSE.mismatch, message: `${paired.name} paired as a ${was.os} ${was.kind} on ${was.arch} and now says ${hello.os} ${hello.kind} on ${hello.arch}: pair it again` };
|
|
169
182
|
}
|
|
170
183
|
// A computer that lacks a group its kind needs can't be given to an agent: refused at connect, in the hello's own
|
|
171
184
|
// words for what it is, never at a run's first call.
|
|
@@ -373,22 +386,109 @@ export class AttachHub {
|
|
|
373
386
|
}
|
|
374
387
|
}
|
|
375
388
|
const ATTACHED_NOTE = "an attached computer is a person's own machine: release ends the run's hold on it, and deletes nothing";
|
|
389
|
+
/** How a person makes a Linux box's /workspace, in the words a refusal names it by (attach.md, A Linux box). */
|
|
390
|
+
const WORKSPACE_FIX = `make ${WORKSPACE} a directory of computerd's user's own, mode 0700, as root: the tmpfiles.d line in spec/computer/attach.md, A Linux box (d ${WORKSPACE} 0700 <user> <user> -), then systemd-tmpfiles --create`;
|
|
391
|
+
/**
|
|
392
|
+
* Why the paired Linux box `name`'s /workspace can't hold a run's synced folder, in words naming the fix, or undefined
|
|
393
|
+
* when it can: a directory, never a link (a push follows /workspace itself, then writes only under it, opening each name
|
|
394
|
+
* with O_NOFOLLOW), of the user computerd runs as (the effective uid its /proc/self/status says), with no access for its
|
|
395
|
+
* group or others. Read through `client` (computerd's), which runs nothing on the box.
|
|
396
|
+
*/
|
|
397
|
+
async function pairedWorkspaceWhy(client, name, signal) {
|
|
398
|
+
const options = signal ? { signal } : {};
|
|
399
|
+
const status = await client.call("files.read", { path: "/proc/self/status" }, options);
|
|
400
|
+
if (!status.ok)
|
|
401
|
+
return fail(status.error.code, `reading the user computerd runs as on ${name}: ${status.error.message}`);
|
|
402
|
+
const uid = /^Uid:\s+\d+\s+(\d+)/m.exec(Buffer.from(status.value.data, "base64").toString("utf8"))?.[1];
|
|
403
|
+
if (uid === undefined)
|
|
404
|
+
return fail("invalid", `${name}'s /proc/self/status names no user computerd runs as`);
|
|
405
|
+
const folder = await client.call("files.stat", { path: WORKSPACE, follow: false }, options);
|
|
406
|
+
if (!folder.ok)
|
|
407
|
+
return folder.error.code === "not_found" ? ok(`${name} has no ${WORKSPACE}, where a run's synced folder goes: ${WORKSPACE_FIX}`) : fail(folder.error.code, `reading ${WORKSPACE} on ${name}: ${folder.error.message}`);
|
|
408
|
+
const { type, uid: owner, mode } = folder.value;
|
|
409
|
+
if (type === "symlink")
|
|
410
|
+
return ok(`${WORKSPACE} on ${name} is a link, and a run's synced folder is never written through one: remove it, then ${WORKSPACE_FIX}`);
|
|
411
|
+
if (type !== "dir")
|
|
412
|
+
return ok(`${WORKSPACE} on ${name} is a ${type}, where a run's synced folder needs a directory: remove it, then ${WORKSPACE_FIX}`);
|
|
413
|
+
if (String(owner) !== uid)
|
|
414
|
+
return ok(`${WORKSPACE} on ${name} is uid ${owner}'s, not uid ${uid}'s, the user computerd runs as: ${WORKSPACE_FIX}`);
|
|
415
|
+
if ((mode & 0o077) !== 0)
|
|
416
|
+
return ok(`${WORKSPACE} on ${name} is open to its group or others (mode ${(mode & 0o7777).toString(8).padStart(4, "0")}): ${WORKSPACE_FIX}`);
|
|
417
|
+
return ok(undefined);
|
|
418
|
+
}
|
|
419
|
+
/** Every program computerd still runs on `name` ended, waited for up to 5 s each: the box outlives its runs, and one
|
|
420
|
+
* run holds it at a time, so a program running at a claim is an earlier run's (a background program left when its hold
|
|
421
|
+
* ended at its deadline, or its runner was lost), which could read or write the next run's folder. KILL goes to its
|
|
422
|
+
* process group; init kills what left that group once its guard is gone. */
|
|
423
|
+
async function endPrograms(client, name, signal) {
|
|
424
|
+
const options = signal ? { signal } : {};
|
|
425
|
+
const words = (message) => `ending an earlier run's programs on ${name}: ${message}`;
|
|
426
|
+
for (let from = 0;;) {
|
|
427
|
+
const listed = await client.call("process.list", { from }, options);
|
|
428
|
+
if (!listed.ok)
|
|
429
|
+
return fail(listed.error.code, words(listed.error.message));
|
|
430
|
+
for (const program of listed.value.processes.filter((one) => one.running)) {
|
|
431
|
+
const killed = await client.call("process.signal", { id: program.id, signal: "KILL" }, options);
|
|
432
|
+
if (!killed.ok && killed.error.code !== "not_found")
|
|
433
|
+
return fail(killed.error.code, words(killed.error.message));
|
|
434
|
+
const waited = await client.call("process.wait", { id: program.id, timeoutMs: 5_000 }, options);
|
|
435
|
+
if (waited.ok && waited.value.running)
|
|
436
|
+
return fail("refused", words(`${program.argv.join(" ")} (pid ${program.pid}) is still running 5 s after KILL`));
|
|
437
|
+
}
|
|
438
|
+
if (!listed.value.truncated)
|
|
439
|
+
return ok(undefined);
|
|
440
|
+
from = listed.value.next;
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
/** Everything in `name`'s /workspace removed, the folder itself kept (only root makes one): each entry of its first
|
|
444
|
+
* level, a directory with what it holds, a link removed and never followed (files.remove). An entry a remove can't
|
|
445
|
+
* find (a name that is not UTF-8 reaches the wire changed) is left: a whole listing with one left, or a truncated one
|
|
446
|
+
* that a pass removes nothing of, refuses the box in words naming what was left. */
|
|
447
|
+
async function emptyWorkspace(client, name, signal) {
|
|
448
|
+
const options = signal ? { signal } : {};
|
|
449
|
+
const words = (message) => `emptying ${WORKSPACE} on ${name} of an earlier run's folder: ${message}`;
|
|
450
|
+
for (;;) {
|
|
451
|
+
const listed = await client.call("files.list", { path: WORKSPACE }, options);
|
|
452
|
+
if (!listed.ok)
|
|
453
|
+
return fail(listed.error.code, words(listed.error.message));
|
|
454
|
+
const left = [];
|
|
455
|
+
for (const entry of listed.value.entries) {
|
|
456
|
+
const removed = await client.call("files.remove", { path: entry.path, recursive: true }, options);
|
|
457
|
+
if (removed.ok)
|
|
458
|
+
continue;
|
|
459
|
+
if (removed.error.code !== "not_found")
|
|
460
|
+
return fail(removed.error.code, words(removed.error.message));
|
|
461
|
+
left.push(`${entry.path}: ${removed.error.message}`);
|
|
462
|
+
}
|
|
463
|
+
// A truncated listing is listed again while a pass removes something; what is left past that stays.
|
|
464
|
+
const stuck = listed.value.truncated ? left.length === listed.value.entries.length : left.length > 0;
|
|
465
|
+
if (stuck)
|
|
466
|
+
return fail("refused", words(`${left.length} entries could not be removed (first: ${left[0] ?? "none listed"})`));
|
|
467
|
+
if (!listed.value.truncated)
|
|
468
|
+
return ok(undefined);
|
|
469
|
+
}
|
|
470
|
+
}
|
|
376
471
|
/**
|
|
377
472
|
* One paired computer as a provider, id "attached": its capabilities are what it paired as. create claims it for a
|
|
378
473
|
* run (refused while it is offline or another run holds it) and release ends the claim; a person's machine is never
|
|
379
|
-
* made, stopped or deleted by a run.
|
|
474
|
+
* made, stopped or deleted by a run. A desktop or a phone has no init of ours, so its daemon mode is none; a Linux box
|
|
475
|
+
* (kind linux, a sandbox) runs computerd init, a child of its service manager, and takes the run's folder as a synced
|
|
476
|
+
* folder in its /workspace (pairedWorkspaceWhy), read back under the run's claim epoch.
|
|
380
477
|
*/
|
|
381
478
|
export function attachedProvider(paired, hub) {
|
|
382
479
|
/** What the computer says now: its live hello while attached (an update may add groups), else what it paired as. */
|
|
383
480
|
const now = () => hub.hello(paired.id) ?? paired.hello;
|
|
481
|
+
const box = paired.hello.kind === "linux";
|
|
384
482
|
const capabilities = () => ({
|
|
385
483
|
kind: paired.hello.kind,
|
|
386
484
|
lifetime: "vendor",
|
|
387
485
|
network: ["open"],
|
|
388
486
|
isolation: "machine",
|
|
389
487
|
os: paired.hello.os,
|
|
390
|
-
daemon: "none",
|
|
488
|
+
daemon: box ? "child" : "none",
|
|
391
489
|
groups: [...now().groups],
|
|
490
|
+
// computerd attach dials out, so no agent of ours listens on the box's TCP ports.
|
|
491
|
+
...(box ? { mount: ["sync"], vendorAgentPorts: [] } : {}),
|
|
392
492
|
maxLifetimeMs: 24 * 60 * 60_000,
|
|
393
493
|
release: ["delete"],
|
|
394
494
|
});
|
|
@@ -412,12 +512,50 @@ export function attachedProvider(paired, hub) {
|
|
|
412
512
|
const mine = (asked) => named(asked) !== undefined;
|
|
413
513
|
/** The hold each create request made: a request id makes one hold, ever. */
|
|
414
514
|
const holdsBy = new Map();
|
|
515
|
+
/** A create still readying the box's synced folder, by its request id: its hold, and the answer a retry meanwhile
|
|
516
|
+
* shares once it asks for the same labels. */
|
|
517
|
+
const startingBy = new Map();
|
|
415
518
|
const ended = () => fail("gone", `this run's hold on ${paired.name} has ended (released, or at its deadline): another run may hold it now`);
|
|
416
519
|
const unknown = (id) => fail("not_found", `no attached computer ${id}: this provider is ${paired.name}'s (${paired.id})`);
|
|
417
520
|
const offline = () => fail("gone", `${paired.name} is not attached now: open its driver, which dials this server`);
|
|
418
521
|
const holds = (labels, wanted) => Object.entries(wanted).every(([key, value]) => labels[key] === value);
|
|
419
522
|
/** Why a network other than open is refused: a run never narrows a person's own machine's network. */
|
|
420
523
|
const networkRefusal = (asked) => `${paired.name} is a person's own machine on its own network, which a run cannot block or limit: network ${JSON.stringify(asked)} is refused; ask for network "open"`;
|
|
524
|
+
/** The hold whose create took the run's folder as a synced folder (one run holds the machine at a time). */
|
|
525
|
+
let syncedHold;
|
|
526
|
+
/** The synced folder as the hold's labels record it: under the run's claim epoch. */
|
|
527
|
+
const recorded = () => {
|
|
528
|
+
const epoch = epochOf(hub.claimed(paired.id));
|
|
529
|
+
return epoch.ok ? { kind: "sync", epoch: epoch.value } : { other: `a synced folder with no epoch to read it back under (${epoch.error.message})` };
|
|
530
|
+
};
|
|
531
|
+
/** The synced folder read back from inside the box: its /workspace as pairedWorkspaceWhy holds it, else in words.
|
|
532
|
+
* `fresh`: what an earlier run left is ended and removed first, its programs (endPrograms) and then each entry of the
|
|
533
|
+
* folder (a link removed and never followed), so the run's push goes into an empty folder no other run's program
|
|
534
|
+
* reaches, as into a hosted computer's new one. */
|
|
535
|
+
const folder = async (signal, fresh = false) => {
|
|
536
|
+
const connection = hub.connection(paired.id);
|
|
537
|
+
if (connection === undefined)
|
|
538
|
+
return offline();
|
|
539
|
+
try {
|
|
540
|
+
const why = await pairedWorkspaceWhy(connection.client, paired.name, signal);
|
|
541
|
+
if (!why.ok)
|
|
542
|
+
return why;
|
|
543
|
+
if (why.value !== undefined)
|
|
544
|
+
return ok({ other: why.value });
|
|
545
|
+
if (fresh) {
|
|
546
|
+
const stopped = await endPrograms(connection.client, paired.name, signal);
|
|
547
|
+
if (!stopped.ok)
|
|
548
|
+
return stopped;
|
|
549
|
+
const emptied = await emptyWorkspace(connection.client, paired.name, signal);
|
|
550
|
+
if (!emptied.ok)
|
|
551
|
+
return emptied;
|
|
552
|
+
}
|
|
553
|
+
return ok(recorded());
|
|
554
|
+
}
|
|
555
|
+
finally {
|
|
556
|
+
await connection.close();
|
|
557
|
+
}
|
|
558
|
+
};
|
|
421
559
|
return {
|
|
422
560
|
id: "attached",
|
|
423
561
|
// The driver's version is the computer's, whatever it is: the provider never refuses a newer or older build of one
|
|
@@ -430,6 +568,9 @@ export function attachedProvider(paired, hub) {
|
|
|
430
568
|
...kindRefusals(capabilities()),
|
|
431
569
|
...(spec.owner === undefined ? checkLifetime(spec.lifetimeMs, capabilities()) : []),
|
|
432
570
|
...(spec.network === "open" ? [] : [{ field: "network", message: networkRefusal(spec.network) }]),
|
|
571
|
+
// A Linux box takes the run's folder as a synced folder alone; a desktop or a phone takes none.
|
|
572
|
+
...checkMount(spec.mount, capabilities().mount),
|
|
573
|
+
...(spec.mount?.kind === "sync" && !epochOf(spec.labels).ok ? [{ field: "labels", message: `a synced folder is made under the run's claim epoch: the label ${EPOCH_LABEL} is required` }] : []),
|
|
433
574
|
],
|
|
434
575
|
async create(spec, context) {
|
|
435
576
|
const refusals = this.check(spec);
|
|
@@ -439,7 +580,9 @@ export function attachedProvider(paired, hub) {
|
|
|
439
580
|
return fail("invalid", "create needs a request id (CreateContext.requestId): pass the same one to retry the same request");
|
|
440
581
|
// One hold per request id (provider.md, Idempotent create): a retry while it holds answers it, and after it ended
|
|
441
582
|
// is refused, so a retry never takes the machine from the run that holds it next.
|
|
442
|
-
|
|
583
|
+
// A retry while its synced folder is still being readied is checked as one after, then shares that answer.
|
|
584
|
+
const starting = startingBy.get(context.requestId);
|
|
585
|
+
const before = starting?.hold ?? holdsBy.get(context.requestId);
|
|
443
586
|
if (before !== undefined) {
|
|
444
587
|
if (hub.hold(paired.id) !== before)
|
|
445
588
|
return fail("exists", `${paired.name}'s hold ${before} was made for this request and has ended: create with a new request id`);
|
|
@@ -449,7 +592,7 @@ export function attachedProvider(paired, hub) {
|
|
|
449
592
|
const same = Object.keys(asked).length === Object.keys(claimed).length && holds(claimed, asked);
|
|
450
593
|
if (!same)
|
|
451
594
|
return fail("exists", `${paired.name}'s hold ${before} was made for this request with other labels: create with a new request id`);
|
|
452
|
-
return ok({ ...holdRef(before), notes: [ATTACHED_NOTE] });
|
|
595
|
+
return starting?.answer ?? ok({ ...holdRef(before), notes: [ATTACHED_NOTE] });
|
|
453
596
|
}
|
|
454
597
|
if (!hub.online(paired.id))
|
|
455
598
|
return offline();
|
|
@@ -458,10 +601,28 @@ export function attachedProvider(paired, hub) {
|
|
|
458
601
|
const hold = hub.claim(paired.id, spec.labels ?? {}, deadline);
|
|
459
602
|
if (hold === undefined)
|
|
460
603
|
return fail("refused", `${paired.name} is held by another run: one run at a time`);
|
|
461
|
-
|
|
462
|
-
|
|
604
|
+
if (spec.mount?.kind !== "sync") {
|
|
605
|
+
holdsBy.set(context.requestId, hold);
|
|
606
|
+
return ok({ ...holdRef(hold), notes: [ATTACHED_NOTE] });
|
|
607
|
+
}
|
|
608
|
+
// The run's synced folder goes in the box's /workspace, which must be computerd's user's own directory before
|
|
609
|
+
// anything is pushed there, and is cleared of an earlier run's programs and files: one that is not lets the hold
|
|
610
|
+
// go, in words. A retry of this request meanwhile shares this answer.
|
|
611
|
+
const requestId = context.requestId;
|
|
612
|
+
const answer = (async () => {
|
|
613
|
+
const read = await folder(context.signal, true);
|
|
614
|
+
if (!read.ok || "other" in read.value) {
|
|
615
|
+
hub.unclaim(paired.id, hold);
|
|
616
|
+
return read.ok ? fail("refused", read.value.other) : read;
|
|
617
|
+
}
|
|
618
|
+
syncedHold = hold;
|
|
619
|
+
holdsBy.set(requestId, hold);
|
|
620
|
+
return ok({ ...holdRef(hold), notes: [ATTACHED_NOTE] });
|
|
621
|
+
})().finally(() => startingBy.delete(requestId));
|
|
622
|
+
startingBy.set(requestId, { hold, answer });
|
|
623
|
+
return answer;
|
|
463
624
|
},
|
|
464
|
-
async attach(asked) {
|
|
625
|
+
async attach(asked, context) {
|
|
465
626
|
if ("id" in asked) {
|
|
466
627
|
const which = named(asked);
|
|
467
628
|
if (which === undefined)
|
|
@@ -473,13 +634,19 @@ export function attachedProvider(paired, hub) {
|
|
|
473
634
|
return unknown(JSON.stringify(asked.labels));
|
|
474
635
|
const deadline = hub.deadline(paired.id);
|
|
475
636
|
const found = "id" in asked ? { id: asked.id, name: paired.name } : heldRef();
|
|
476
|
-
|
|
637
|
+
// A hold that took the run's folder reads it back from inside the box, as a hosted computer's is.
|
|
638
|
+
const mounted = syncedHold !== undefined && hub.hold(paired.id) === syncedHold ? await folder(context?.signal) : undefined;
|
|
639
|
+
if (mounted !== undefined && !mounted.ok)
|
|
640
|
+
return mounted;
|
|
641
|
+
return ok({ ...found, spec: { image: "attached", user: "the person's own", network: { other: "the machine's own network" }, kind: paired.hello.kind, ...(deadline === undefined ? {} : { deadline }), ...(mounted === undefined ? {} : { mount: mounted.value }) } });
|
|
477
642
|
},
|
|
478
643
|
async list(labels) {
|
|
479
644
|
const have = { ...paired.labels, ...hub.claimed(paired.id) };
|
|
480
645
|
if (!holds(have, labels))
|
|
481
646
|
return ok([]);
|
|
482
|
-
|
|
647
|
+
// list runs nothing on the box: a hold's synced folder is the one its labels record.
|
|
648
|
+
const mount = syncedHold !== undefined && hub.hold(paired.id) === syncedHold ? { mount: recorded() } : {};
|
|
649
|
+
return ok([{ ref: heldRef(), labels: have, deadline: hub.deadline(paired.id), state: hub.online(paired.id) ? "running" : "stopped", network: { other: "the machine's own network" }, ...mount }]);
|
|
483
650
|
},
|
|
484
651
|
async network(asked, policy) {
|
|
485
652
|
if (!mine(asked))
|
package/dist/cloudflare.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { HostedProvider, type HostedOptions, type HostedTimeouts } from "./hosted/provider.js";
|
|
2
2
|
import type { CallContext } from "./provider.js";
|
|
3
3
|
import { type Result } from "./result.js";
|
|
4
|
-
|
|
4
|
+
/** The Cloudflare provider's options: the relay's address and token, then the shared adapter's (HostedOptions), kind among them. */
|
|
5
|
+
export interface CloudflareProviderOptions extends Omit<HostedOptions, "desktop" | "maxLifetimeMs"> {
|
|
5
6
|
/** The relay Worker's https address, as `wrangler deploy` printed it. */
|
|
6
7
|
relayUrl: string;
|
|
7
8
|
/** The relay's RELAY_TOKEN (`wrangler secret put RELAY_TOKEN`). The caller passes it; this provider reads no environment. */
|
|
@@ -18,7 +19,8 @@ export declare function create(options: CloudflareProviderOptions): CloudflarePr
|
|
|
18
19
|
export declare const conformance: () => Promise<typeof import("./conformance/cloudflare.js")>;
|
|
19
20
|
/**
|
|
20
21
|
* Computers that are Cloudflare Containers, through the operator's relay, each dialing the server that made it: a server
|
|
21
|
-
* with no public https address (AGENTRUN_PUBLIC_URL) refuses a create in words before the relay is called. Kind linux
|
|
22
|
+
* with no public https address (AGENTRUN_PUBLIC_URL) refuses a create in words before the relay is called. Kind linux
|
|
23
|
+
* (default) or desktop, whose X server and window manager start through computerd over the socket the container dialed.
|
|
22
24
|
*/
|
|
23
25
|
export declare class CloudflareProvider extends HostedProvider {
|
|
24
26
|
#private;
|
package/dist/cloudflare.js
CHANGED
|
@@ -62,7 +62,10 @@ class CloudflareHost {
|
|
|
62
62
|
arch: "amd64",
|
|
63
63
|
// No page names an agent of Cloudflare's inside the container (unverified).
|
|
64
64
|
vendorAgentPorts: [],
|
|
65
|
-
|
|
65
|
+
// The relay's image is FROM the box image (relays/cloudflare/Dockerfile), which has xfwm4 (box/install.sh's desktop step).
|
|
66
|
+
windowManager: true,
|
|
67
|
+
// Its descriptor's (connectOf): the container dials the server.
|
|
68
|
+
connect: CLOUDFLARE.connect,
|
|
66
69
|
};
|
|
67
70
|
relayUrl;
|
|
68
71
|
#client;
|
|
@@ -152,7 +155,8 @@ export function create(options) {
|
|
|
152
155
|
export const conformance = () => import("./conformance/cloudflare.js");
|
|
153
156
|
/**
|
|
154
157
|
* Computers that are Cloudflare Containers, through the operator's relay, each dialing the server that made it: a server
|
|
155
|
-
* with no public https address (AGENTRUN_PUBLIC_URL) refuses a create in words before the relay is called. Kind linux
|
|
158
|
+
* with no public https address (AGENTRUN_PUBLIC_URL) refuses a create in words before the relay is called. Kind linux
|
|
159
|
+
* (default) or desktop, whose X server and window manager start through computerd over the socket the container dialed.
|
|
156
160
|
*/
|
|
157
161
|
export class CloudflareProvider extends HostedProvider {
|
|
158
162
|
#relay;
|
|
@@ -165,7 +169,7 @@ export class CloudflareProvider extends HostedProvider {
|
|
|
165
169
|
if (typeof fetcher !== "function")
|
|
166
170
|
throw new Error("options.fetch must be a function, as the global fetch is");
|
|
167
171
|
const host = new CloudflareHost({ relayUrl, relayToken, fetch: fetcher });
|
|
168
|
-
super(host, { ...rest,
|
|
172
|
+
super(host, { ...rest, timeouts: { ...CLOUDFLARE_TIMEOUTS, ...timeouts } });
|
|
169
173
|
this.#relay = host;
|
|
170
174
|
}
|
|
171
175
|
/** The provider contract's prepareImage (its descriptor declares it): the box image the relay was deployed FROM. */
|
|
Binary file
|
|
Binary file
|
package/dist/computerd.json
CHANGED
|
@@ -3,11 +3,17 @@
|
|
|
3
3
|
import { createHash, randomBytes } from "node:crypto";
|
|
4
4
|
import { pullTar, pullTarStream, pushTar, readFile, writeFile } from "../../files.js";
|
|
5
5
|
import { MAX_LIST_ENTRIES } from "../../protocol.js";
|
|
6
|
-
import {
|
|
6
|
+
import { tarOf, untar } from "../../tar.js";
|
|
7
7
|
import { b64, decode, delay } from "./util.js";
|
|
8
8
|
// Most cases work in t.dir(), which finds HOME through exec.run: they need exec as well as files.
|
|
9
9
|
const files = (name, run, needs = ["files", "exec"]) => ({ id: `files.${name}`, level: "core", group: "files", needs, run });
|
|
10
10
|
const sha256 = (bytes) => createHash("sha256").update(bytes).digest("hex");
|
|
11
|
+
/** An entry as one comparable line: its name without "./" or a trailing "/", type, mode, and content hash or target. */
|
|
12
|
+
const describeEntry = (entry) => {
|
|
13
|
+
const name = entry.name.replace(/^\.\//, "").replace(/\/$/, "");
|
|
14
|
+
const what = entry.type === "file" ? sha256(entry.body ?? new Uint8Array()) : entry.type === "symlink" ? `-> ${entry.link}` : "";
|
|
15
|
+
return `${name} ${entry.type} ${entry.mode.toString(8)} ${what}`.trimEnd();
|
|
16
|
+
};
|
|
11
17
|
const sorted = (entries) => entries
|
|
12
18
|
.filter((entry) => !["", ".", "./"].includes(entry.name))
|
|
13
19
|
.map(describeEntry)
|