@capybara-hq/device 0.1.0-rc.1 → 0.1.0-rc.2
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 +14 -14
- package/dist/api.d.ts +1 -1
- package/dist/args.d.ts +1 -1
- package/dist/args.js +1 -1
- package/dist/cli.js +1 -1
- package/dist/client.d.ts +2 -2
- package/dist/client.js +2 -2
- package/dist/commands/login.js +12 -10
- package/dist/commands/start.js +1 -1
- package/dist/commands/status.js +1 -1
- package/dist/exec/docker.d.ts +8 -8
- package/dist/exec/docker.js +14 -14
- package/dist/exec/fs-helper.d.ts +1 -1
- package/dist/exec/fs-helper.js +1 -1
- package/dist/exec/os.d.ts +5 -5
- package/dist/exec/os.js +4 -4
- package/dist/exec/shared.d.ts +6 -6
- package/dist/exec/shared.js +9 -9
- package/dist/exec/types.d.ts +1 -1
- package/dist/policy.d.ts +3 -3
- package/dist/policy.js +2 -2
- package/dist/server-ops.d.ts +1 -1
- package/dist/server-ops.js +2 -2
- package/dist/state.d.ts +5 -5
- package/dist/state.js +4 -4
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# @capybara-hq/device
|
|
2
2
|
|
|
3
3
|
`capybara-device` connects a laptop or server to a [Capybara](https://github.com/capybara-hq/core)
|
|
4
|
-
deployment as
|
|
4
|
+
deployment as a device: the platform's agents run commands and read and write files on this
|
|
5
5
|
machine, inside a sandbox, while the program is online.
|
|
6
6
|
|
|
7
7
|
Runs on macOS and Linux. Native Windows is refused: use WSL (then it is a Linux machine) or Docker
|
|
@@ -16,13 +16,13 @@ capybara-device status [--json]
|
|
|
16
16
|
capybara-device logout
|
|
17
17
|
```
|
|
18
18
|
|
|
19
|
-
`login` shows a code like `BCDF-GHJK`; with `--no-browser` it prints the address (`<url>/
|
|
20
|
-
the code to enter on any signed-in browser, where you pick the org and the
|
|
19
|
+
`login` shows a code like `BCDF-GHJK`; with `--no-browser` it prints the address (`<url>/devices/link`) and
|
|
20
|
+
the code to enter on any signed-in browser, where you pick the org and the device (a new one or
|
|
21
21
|
an existing connected one of yours) after reading what the program can do. Logging in again from
|
|
22
|
-
another machine into the same
|
|
22
|
+
another machine into the same device replaces the first machine (its credential is revoked).
|
|
23
23
|
`stop` ends the running program, `drain` makes it accept no new commands and exit when the running
|
|
24
24
|
ones finish. `logout` stops a running program, then forgets the credential (the machine stays
|
|
25
|
-
connected on the platform until it is revoked there). Deleting the
|
|
25
|
+
connected on the platform until it is revoked there). Deleting the device in the web app
|
|
26
26
|
revokes the machine and stops the program; the files in the working directory stay on your machine.
|
|
27
27
|
|
|
28
28
|
The deployment must route `/device/connect` on its public URL to the gateway role (see
|
|
@@ -31,16 +31,16 @@ While connecting keeps failing, `start` retries and prints why at most once a mi
|
|
|
31
31
|
status (a 404 usually means that route is missing), the close reason, or the network error.
|
|
32
32
|
|
|
33
33
|
`start` exits 0, after printing why, when retrying cannot help: the machine was revoked or the
|
|
34
|
-
|
|
34
|
+
device deleted, the program is too old for the deployment (426), another login replaced this
|
|
35
35
|
connection, or the machine is not logged in. Other failures exit non-zero, so a service (below)
|
|
36
36
|
restarts the program after those and leaves it stopped after the terminal ones; fix the cause
|
|
37
37
|
(log in again, upgrade), then run `start` or `service install` again.
|
|
38
38
|
|
|
39
39
|
If the working directory (or its marker `.capybara-device`, or one of `workspace/`, `skills/`,
|
|
40
40
|
`tmp/`) is removed, the program never recreates it: operations answer that the files are lost and
|
|
41
|
-
the
|
|
42
|
-
`capybara-device login` into the same
|
|
43
|
-
and the platform rebuilds the
|
|
41
|
+
the device page says so. To start afresh, run `capybara-device logout` and then
|
|
42
|
+
`capybara-device login` into the same device: login recreates the directory and the marker,
|
|
43
|
+
and the platform rebuilds the device on its next use.
|
|
44
44
|
|
|
45
45
|
Commands: `login --url <url> [--no-browser] [--dir <path>] [--mode os|docker]`, `logout`,
|
|
46
46
|
`status [--json]`, `start`, `stop`, `drain`, `policy [show|set <key> <value>]` and
|
|
@@ -51,14 +51,14 @@ State lives in `$XDG_CONFIG_HOME/capybara-device` (default `~/.config/capybara-d
|
|
|
51
51
|
deployment's reconnect grace and frame limit: a result larger than the frame limit is answered
|
|
52
52
|
with an error instead) and `policy.json` (a file with wrong field types stops `start` with an
|
|
53
53
|
error naming it).
|
|
54
|
-
The working directory (default `~/capybara-device/<
|
|
54
|
+
The working directory (default `~/capybara-device/<deviceId>`) holds `workspace/`, `skills/`
|
|
55
55
|
and `tmp/`.
|
|
56
56
|
|
|
57
57
|
In OS mode every command runs inside `@anthropic-ai/sandbox-runtime` (macOS Seatbelt, Linux
|
|
58
58
|
bubblewrap; Linux needs `bwrap` and `socat`): writes only under `workspace/` and `tmp/`,
|
|
59
59
|
`skills/` read only, `~/.ssh`, cloud CLI credentials, `~/.netrc`, `~/.gnupg`, browser profiles and
|
|
60
60
|
this program's state directory unreadable. Network is limited to the domains of the local policy
|
|
61
|
-
that the
|
|
61
|
+
that the device's egress also allows; with an empty policy (the default) commands reach no
|
|
62
62
|
network at all. Only you edit the policy, the platform can never widen it:
|
|
63
63
|
|
|
64
64
|
```bash
|
|
@@ -77,8 +77,8 @@ down with it).
|
|
|
77
77
|
|
|
78
78
|
## Docker mode
|
|
79
79
|
|
|
80
|
-
`login --mode docker` runs every command with `docker exec` in one container per
|
|
81
|
-
(`capybara-device-<
|
|
80
|
+
`login --mode docker` runs every command with `docker exec` in one container per device
|
|
81
|
+
(`capybara-device-<deviceId>`, started on first use from
|
|
82
82
|
`ghcr.io/capybara-hq/capybara-sandbox:<tag>`, the sandbox image of this release). On Linux commands
|
|
83
83
|
run as your own uid:gid, so they can write the mounted directories you own (a root user falls back to
|
|
84
84
|
the image's `sandbox` user, uid 1000); on macOS as the image's `sandbox` user. `<dir>/workspace`, `<dir>/skills` (read only) and `<dir>/tmp` are mounted
|
|
@@ -88,7 +88,7 @@ at `/workspace`, `/skills` and `/tmp`; the container has a read-only root file s
|
|
|
88
88
|
match and recreated when they change; it stays running (idle) between starts.
|
|
89
89
|
|
|
90
90
|
Docker mode has no domain allowlist: a command has either no network (`--network none`, when the
|
|
91
|
-
local policy or the
|
|
91
|
+
local policy or the device's egress allows no domain) or the default bridge, with the whole
|
|
92
92
|
internet. Use OS mode to limit commands to the domains of the local policy.
|
|
93
93
|
|
|
94
94
|
## Running at login
|
package/dist/api.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ export interface AuthorizeResponse {
|
|
|
9
9
|
export interface TokenResponse {
|
|
10
10
|
credential: string;
|
|
11
11
|
orgId: string;
|
|
12
|
-
|
|
12
|
+
deviceId: string;
|
|
13
13
|
connectUrl: string;
|
|
14
14
|
reconnectGraceSeconds: number;
|
|
15
15
|
/** The program uses 16 MiB when it is absent. */
|
package/dist/args.d.ts
CHANGED
|
@@ -31,7 +31,7 @@ export type Command = {
|
|
|
31
31
|
} | {
|
|
32
32
|
command: "help";
|
|
33
33
|
};
|
|
34
|
-
export declare const USAGE = "Usage:\n capybara-device login --url <url> [--no-browser] [--dir <path>] [--mode os|docker]\n Connect this machine: approve the code in the browser\n capybara-device logout Forget the credential on this machine\n capybara-device status [--json] Show whether this machine is logged in\n capybara-device start Connect and serve the
|
|
34
|
+
export declare const USAGE = "Usage:\n capybara-device login --url <url> [--no-browser] [--dir <path>] [--mode os|docker]\n Connect this machine: approve the code in the browser\n capybara-device logout Forget the credential on this machine\n capybara-device status [--json] Show whether this machine is logged in\n capybara-device start Connect and serve the device\n capybara-device stop Stop the running program\n capybara-device drain Finish running commands, accept no new ones, then stop\n capybara-device policy [show] Show the local policy\n capybara-device policy set <key> <value>\n capybara-device service install|uninstall\n Run at login as a user service";
|
|
35
35
|
/** Thrown for a bad command line; the message is shown with the usage. */
|
|
36
36
|
export declare class UsageError extends Error {
|
|
37
37
|
}
|
package/dist/args.js
CHANGED
|
@@ -4,7 +4,7 @@ export const USAGE = `Usage:
|
|
|
4
4
|
Connect this machine: approve the code in the browser
|
|
5
5
|
capybara-device logout Forget the credential on this machine
|
|
6
6
|
capybara-device status [--json] Show whether this machine is logged in
|
|
7
|
-
capybara-device start Connect and serve the
|
|
7
|
+
capybara-device start Connect and serve the device
|
|
8
8
|
capybara-device stop Stop the running program
|
|
9
9
|
capybara-device drain Finish running commands, accept no new ones, then stop
|
|
10
10
|
capybara-device policy [show] Show the local policy
|
package/dist/cli.js
CHANGED
package/dist/client.d.ts
CHANGED
|
@@ -3,8 +3,8 @@ import type { Executor } from "./exec/types.js";
|
|
|
3
3
|
import type { Credential } from "./state.js";
|
|
4
4
|
export declare const OUTDATED_MESSAGE = "This capybara-device is too old for the deployment. Upgrade it: npm install -g @capybara-hq/device";
|
|
5
5
|
export declare const DISCONNECTED_MESSAGE = "This machine was disconnected from the deployment. Run capybara-device logout, then capybara-device login.";
|
|
6
|
-
export declare const REPLACED_MESSAGE = "This machine connected elsewhere: a newer connection to this
|
|
7
|
-
export declare const DELETED_MESSAGE = "The
|
|
6
|
+
export declare const REPLACED_MESSAGE = "This machine connected elsewhere: a newer connection to this device replaced this one.";
|
|
7
|
+
export declare const DELETED_MESSAGE = "The device was deleted on the deployment. The files on this machine stay where they are.";
|
|
8
8
|
/** The answer sent instead of a result whose frame would exceed the connection's frame limit. */
|
|
9
9
|
export declare const TOO_LARGE_MESSAGE = "result larger than the connection's frame limit";
|
|
10
10
|
export interface ConnectOptions {
|
package/dist/client.js
CHANGED
|
@@ -4,8 +4,8 @@ import { logEntryFor, runOp } from "./server-ops.js";
|
|
|
4
4
|
import { PROGRAM_VERSION } from "./version.js";
|
|
5
5
|
export const OUTDATED_MESSAGE = "This capybara-device is too old for the deployment. Upgrade it: npm install -g @capybara-hq/device";
|
|
6
6
|
export const DISCONNECTED_MESSAGE = "This machine was disconnected from the deployment. Run capybara-device logout, then capybara-device login.";
|
|
7
|
-
export const REPLACED_MESSAGE = "This machine connected elsewhere: a newer connection to this
|
|
8
|
-
export const DELETED_MESSAGE = "The
|
|
7
|
+
export const REPLACED_MESSAGE = "This machine connected elsewhere: a newer connection to this device replaced this one.";
|
|
8
|
+
export const DELETED_MESSAGE = "The device was deleted on the deployment. The files on this machine stay where they are.";
|
|
9
9
|
/** The answer sent instead of a result whose frame would exceed the connection's frame limit. */
|
|
10
10
|
export const TOO_LARGE_MESSAGE = "result larger than the connection's frame limit";
|
|
11
11
|
/** A failing connection is reported at most this often. */
|
package/dist/commands/login.js
CHANGED
|
@@ -2,7 +2,7 @@ import { spawn } from "node:child_process";
|
|
|
2
2
|
import { hostname } from "node:os";
|
|
3
3
|
import { isAbsolute, resolve } from "node:path";
|
|
4
4
|
import { ApiError, authorize, programVersion, token } from "../api.js";
|
|
5
|
-
import {
|
|
5
|
+
import { prepareDeviceDir } from "../exec/shared.js";
|
|
6
6
|
import { DEFAULT_MAX_FRAME_BYTES, defaultWorkDir, readCredential, writeCredential, } from "../state.js";
|
|
7
7
|
const SLOW_DOWN_STEP_SECONDS = 5;
|
|
8
8
|
function defaultOpen(platform) {
|
|
@@ -80,39 +80,41 @@ export async function login(cmd, deps) {
|
|
|
80
80
|
try {
|
|
81
81
|
const granted = await token(fetchFn, baseUrl, auth.deviceCode);
|
|
82
82
|
const dir = cmd.dir === undefined
|
|
83
|
-
? defaultWorkDir(granted.
|
|
83
|
+
? defaultWorkDir(granted.deviceId, deps.home)
|
|
84
84
|
: isAbsolute(cmd.dir)
|
|
85
85
|
? cmd.dir
|
|
86
86
|
: resolve(cmd.dir);
|
|
87
|
-
// Recreates a lost directory, marker or root: the
|
|
88
|
-
|
|
87
|
+
// Recreates a lost directory, marker or root: the device starts afresh.
|
|
88
|
+
prepareDeviceDir(dir);
|
|
89
89
|
writeCredential(deps.stateDir, {
|
|
90
90
|
url: baseUrl,
|
|
91
91
|
connectUrl: granted.connectUrl,
|
|
92
92
|
credential: granted.credential,
|
|
93
93
|
orgId: granted.orgId,
|
|
94
|
-
|
|
94
|
+
deviceId: granted.deviceId,
|
|
95
95
|
dir,
|
|
96
96
|
mode: cmd.mode,
|
|
97
97
|
reconnectGraceSeconds: granted.reconnectGraceSeconds,
|
|
98
98
|
maxFrameBytes: granted.maxFrameBytes ?? DEFAULT_MAX_FRAME_BYTES,
|
|
99
99
|
});
|
|
100
|
-
out(`Logged in.
|
|
100
|
+
out(`Logged in. Device ${granted.deviceId}, working directory ${dir}`);
|
|
101
101
|
return 0;
|
|
102
102
|
}
|
|
103
103
|
catch (e) {
|
|
104
104
|
if (!(e instanceof ApiError))
|
|
105
105
|
throw e;
|
|
106
|
-
if (e.code === "
|
|
106
|
+
if (e.code === "device_sign_in.slow_down")
|
|
107
107
|
interval += SLOW_DOWN_STEP_SECONDS;
|
|
108
|
-
else if (e.code === "
|
|
108
|
+
else if (e.code === "device_sign_in.authorization_pending" ||
|
|
109
|
+
e.status === 0 ||
|
|
110
|
+
e.status >= 500) {
|
|
109
111
|
// Keep polling at the normal interval: pending, a network blip or a server error.
|
|
110
112
|
}
|
|
111
|
-
else if (e.code === "
|
|
113
|
+
else if (e.code === "device_sign_in.expired") {
|
|
112
114
|
err("The code expired before it was approved. Run `capybara-device login` again.");
|
|
113
115
|
return 1;
|
|
114
116
|
}
|
|
115
|
-
else if (e.code === "
|
|
117
|
+
else if (e.code === "device_sign_in.denied") {
|
|
116
118
|
err("The login was denied in the browser.");
|
|
117
119
|
return 1;
|
|
118
120
|
}
|
package/dist/commands/start.js
CHANGED
|
@@ -61,7 +61,7 @@ export async function start(deps) {
|
|
|
61
61
|
conn = (deps.connect ?? connect)(cred, executor, { log: new CommandLog(stateDir), err });
|
|
62
62
|
if (drainRequested)
|
|
63
63
|
conn.drain();
|
|
64
|
-
out(`capybara-device: serving
|
|
64
|
+
out(`capybara-device: serving device ${cred.deviceId} (${cred.mode} mode)`);
|
|
65
65
|
return await conn.done;
|
|
66
66
|
}
|
|
67
67
|
finally {
|
package/dist/commands/status.js
CHANGED
|
@@ -23,7 +23,7 @@ export function status(stateDir, json, out, err) {
|
|
|
23
23
|
"Logged in.",
|
|
24
24
|
` deployment: ${cred.url}`,
|
|
25
25
|
` organization: ${cred.orgId}`,
|
|
26
|
-
`
|
|
26
|
+
` device: ${cred.deviceId}`,
|
|
27
27
|
` directory: ${cred.dir}`,
|
|
28
28
|
` mode: ${cred.mode}`,
|
|
29
29
|
].join("\n"));
|
package/dist/exec/docker.d.ts
CHANGED
|
@@ -5,13 +5,13 @@ import { type Executor } from "./types.js";
|
|
|
5
5
|
export declare const SANDBOX_IMAGE_TAG = "0.1.0-rc.5";
|
|
6
6
|
export declare const SANDBOX_IMAGE = "ghcr.io/capybara-hq/capybara-sandbox:0.1.0-rc.5";
|
|
7
7
|
/**
|
|
8
|
-
* The user commands run as. On Linux the bind-mounted
|
|
8
|
+
* The user commands run as. On Linux the bind-mounted device directory belongs to the host user,
|
|
9
9
|
* so the container runs as that uid:gid (never root: a root host user falls back to the image's user).
|
|
10
10
|
* Docker Desktop (macOS) maps file ownership itself, so the image's user is used there.
|
|
11
11
|
*/
|
|
12
12
|
export declare function containerUser(platform?: NodeJS.Platform, uid?: number | undefined, gid?: number | undefined): string;
|
|
13
|
-
/** Container name of
|
|
14
|
-
export declare function containerName(
|
|
13
|
+
/** Container name of a device. */
|
|
14
|
+
export declare function containerName(deviceId: string): string;
|
|
15
15
|
/** Whether the docker CLI can reach a daemon, and why not. */
|
|
16
16
|
export declare function dockerAvailability(): Promise<{
|
|
17
17
|
ok: true;
|
|
@@ -20,14 +20,14 @@ export declare function dockerAvailability(): Promise<{
|
|
|
20
20
|
reason: string;
|
|
21
21
|
}>;
|
|
22
22
|
export interface DockerExecutorOptions {
|
|
23
|
-
/** The
|
|
23
|
+
/** The device directory (from login). */
|
|
24
24
|
dir: string;
|
|
25
|
-
|
|
25
|
+
deviceId: string;
|
|
26
26
|
policy: Policy;
|
|
27
27
|
}
|
|
28
28
|
/**
|
|
29
29
|
* Runs every command with `docker exec` in one long-lived container of the published sandbox
|
|
30
|
-
* image: the
|
|
30
|
+
* image: the device directory's workspace, skills (read only) and tmp are mounted at
|
|
31
31
|
* /workspace, /skills and /tmp. Workspace and tmp files are read and written inside the container
|
|
32
32
|
* (as the `sandbox` user, so a link a command plants resolves in the container and never on the
|
|
33
33
|
* host); the skills directory, which commands cannot write, is accessed from the host with the
|
|
@@ -43,7 +43,7 @@ export declare class DockerExecutor implements Executor {
|
|
|
43
43
|
private readonly hostRoots;
|
|
44
44
|
private readonly guard;
|
|
45
45
|
private readonly hostFiles;
|
|
46
|
-
/** Marks every process of this
|
|
46
|
+
/** Marks every process of this device's commands: `<dirKey>.<tag>`. */
|
|
47
47
|
private readonly dirKey;
|
|
48
48
|
private readonly running;
|
|
49
49
|
private chain;
|
|
@@ -111,7 +111,7 @@ export declare class DockerExecutor implements Executor {
|
|
|
111
111
|
private killMarker;
|
|
112
112
|
killTagged(tags: string[]): Promise<void>;
|
|
113
113
|
killAll(): Promise<void>;
|
|
114
|
-
/** Kills every process carrying this
|
|
114
|
+
/** Kills every process carrying this device's marker (also a previous run's). */
|
|
115
115
|
killLeftovers(): Promise<void>;
|
|
116
116
|
/** Kills every running command; the container stays for the next start. */
|
|
117
117
|
dispose(): Promise<void>;
|
package/dist/exec/docker.js
CHANGED
|
@@ -13,7 +13,7 @@ export const SANDBOX_IMAGE = `ghcr.io/capybara-hq/capybara-sandbox:${SANDBOX_IMA
|
|
|
13
13
|
/** The image's `sandbox` user. */
|
|
14
14
|
const IMAGE_USER = "1000:1000";
|
|
15
15
|
/**
|
|
16
|
-
* The user commands run as. On Linux the bind-mounted
|
|
16
|
+
* The user commands run as. On Linux the bind-mounted device directory belongs to the host user,
|
|
17
17
|
* so the container runs as that uid:gid (never root: a root host user falls back to the image's user).
|
|
18
18
|
* Docker Desktop (macOS) maps file ownership itself, so the image's user is used there.
|
|
19
19
|
*/
|
|
@@ -26,11 +26,11 @@ const SPEC_LABEL = "capybara.device.spec";
|
|
|
26
26
|
/** A file operation in the container that takes longer than this is killed. */
|
|
27
27
|
const FILE_OP_TIMEOUT_S = 30;
|
|
28
28
|
const ROOTS = DEFAULT_SANDBOX_ROOTS;
|
|
29
|
-
/** Container name of
|
|
30
|
-
export function containerName(
|
|
31
|
-
return `capybara-device-${
|
|
29
|
+
/** Container name of a device. */
|
|
30
|
+
export function containerName(deviceId) {
|
|
31
|
+
return `capybara-device-${deviceId}`;
|
|
32
32
|
}
|
|
33
|
-
/** Runs `docker <args>` to completion (not a command of the
|
|
33
|
+
/** Runs `docker <args>` to completion (not a command of the device). */
|
|
34
34
|
function docker(args, o = {}) {
|
|
35
35
|
return new Promise((resolvePromise, reject) => {
|
|
36
36
|
const child = spawn("docker", args, { stdio: [o.input ? "pipe" : "ignore", "pipe", "pipe"] });
|
|
@@ -121,7 +121,7 @@ if [ -e "$f" ] && [ ! -f "$f" ]; then exit ${E_NOT_FILE}; fi
|
|
|
121
121
|
cat > "$f" || exit ${E_FAIL}`;
|
|
122
122
|
/**
|
|
123
123
|
* Runs every command with `docker exec` in one long-lived container of the published sandbox
|
|
124
|
-
* image: the
|
|
124
|
+
* image: the device directory's workspace, skills (read only) and tmp are mounted at
|
|
125
125
|
* /workspace, /skills and /tmp. Workspace and tmp files are read and written inside the container
|
|
126
126
|
* (as the `sandbox` user, so a link a command plants resolves in the container and never on the
|
|
127
127
|
* host); the skills directory, which commands cannot write, is accessed from the host with the
|
|
@@ -137,7 +137,7 @@ export class DockerExecutor {
|
|
|
137
137
|
hostRoots;
|
|
138
138
|
guard;
|
|
139
139
|
hostFiles;
|
|
140
|
-
/** Marks every process of this
|
|
140
|
+
/** Marks every process of this device's commands: `<dirKey>.<tag>`. */
|
|
141
141
|
dirKey;
|
|
142
142
|
running = new Set();
|
|
143
143
|
chain = Promise.resolve();
|
|
@@ -155,7 +155,7 @@ export class DockerExecutor {
|
|
|
155
155
|
this.hostRoots = osRoots(this.dir);
|
|
156
156
|
this.guard = new RootGuard(this.dir, this.hostRoots);
|
|
157
157
|
this.hostFiles = new HostFiles(this.hostRoots);
|
|
158
|
-
this.name = containerName(opts.
|
|
158
|
+
this.name = containerName(opts.deviceId);
|
|
159
159
|
this.dirKey = createHash("sha256").update(this.dir).digest("hex").slice(0, 16);
|
|
160
160
|
}
|
|
161
161
|
async ensureRoot() {
|
|
@@ -199,7 +199,7 @@ export class DockerExecutor {
|
|
|
199
199
|
"--workdir",
|
|
200
200
|
ROOTS.workspace,
|
|
201
201
|
"--label",
|
|
202
|
-
`capybara.device.
|
|
202
|
+
`capybara.device.id=${this.opts.deviceId}`,
|
|
203
203
|
...this.wanted().flatMap((m) => [
|
|
204
204
|
"--mount",
|
|
205
205
|
`type=bind,source=${m.source},target=${m.dest}${m.rw ? "" : ",readonly"}`,
|
|
@@ -233,11 +233,11 @@ export class DockerExecutor {
|
|
|
233
233
|
if (this.ready)
|
|
234
234
|
return;
|
|
235
235
|
if (!existsSync(this.dir)) {
|
|
236
|
-
throw new DeviceOpError("error", "the
|
|
236
|
+
throw new DeviceOpError("error", "the device directory is gone");
|
|
237
237
|
}
|
|
238
238
|
for (const r of Object.values(this.hostRoots)) {
|
|
239
239
|
if (r.includes(",")) {
|
|
240
|
-
throw new DeviceOpError("error", `the
|
|
240
|
+
throw new DeviceOpError("error", `the device directory ${this.dir} contains a comma`);
|
|
241
241
|
}
|
|
242
242
|
mkdirSync(r, { recursive: true });
|
|
243
243
|
}
|
|
@@ -549,7 +549,7 @@ export class DockerExecutor {
|
|
|
549
549
|
const p = resolve(path);
|
|
550
550
|
const roots = Object.values(ROOTS);
|
|
551
551
|
if (!roots.some((r) => isUnder(p, r))) {
|
|
552
|
-
throw policyError(`${path} is outside the
|
|
552
|
+
throw policyError(`${path} is outside the device's roots (${roots.join(", ")})`);
|
|
553
553
|
}
|
|
554
554
|
return p;
|
|
555
555
|
}
|
|
@@ -591,7 +591,7 @@ export class DockerExecutor {
|
|
|
591
591
|
case E_MISSING:
|
|
592
592
|
return null;
|
|
593
593
|
case E_OUTSIDE:
|
|
594
|
-
throw policyError(`${path} resolves outside the
|
|
594
|
+
throw policyError(`${path} resolves outside the device's roots`);
|
|
595
595
|
case E_NOT_FILE:
|
|
596
596
|
throw policyError(`${path} is not a regular file`);
|
|
597
597
|
case E_DANGLING:
|
|
@@ -653,7 +653,7 @@ export class DockerExecutor {
|
|
|
653
653
|
r.killed = true;
|
|
654
654
|
await this.killLeftovers();
|
|
655
655
|
}
|
|
656
|
-
/** Kills every process carrying this
|
|
656
|
+
/** Kills every process carrying this device's marker (also a previous run's). */
|
|
657
657
|
async killLeftovers() {
|
|
658
658
|
await this.killScript("", `${this.dirKey}.`);
|
|
659
659
|
}
|
package/dist/exec/fs-helper.d.ts
CHANGED
|
@@ -9,4 +9,4 @@
|
|
|
9
9
|
* read → `null` | `{ b64, truncated }`; stat → `null` | `{ size, isDir }`; write → `null`.
|
|
10
10
|
* Non-regular files (FIFOs, sockets, devices) are refused without blocking (`O_NONBLOCK`).
|
|
11
11
|
*/
|
|
12
|
-
export declare const FS_HELPER_SCRIPT = "\n(() => {\n const fs = require(\"fs\");\n const path = require(\"path\");\n const C = fs.constants;\n const [op, p, maxS, ...roots] = process.argv.slice(1);\n const out = (o) => process.stdout.write(JSON.stringify(o));\n const realRoots = roots.map((r) => { try { return fs.realpathSync(r); } catch { return r; } });\n const under = (r) => realRoots.some((x) => r === x || r.startsWith(x + \"/\"));\n const missing = (e) => e && (e.code === \"ENOENT\" || e.code === \"ENOTDIR\");\n const real = (q) => { try { return fs.realpathSync(q); } catch (e) { if (missing(e)) return null; throw e; } };\n const outside = (r) => out({ e: \"policy\", m: p + \" resolves to \" + r + \", outside the
|
|
12
|
+
export declare const FS_HELPER_SCRIPT = "\n(() => {\n const fs = require(\"fs\");\n const path = require(\"path\");\n const C = fs.constants;\n const [op, p, maxS, ...roots] = process.argv.slice(1);\n const out = (o) => process.stdout.write(JSON.stringify(o));\n const realRoots = roots.map((r) => { try { return fs.realpathSync(r); } catch { return r; } });\n const under = (r) => realRoots.some((x) => r === x || r.startsWith(x + \"/\"));\n const missing = (e) => e && (e.code === \"ENOENT\" || e.code === \"ENOTDIR\");\n const real = (q) => { try { return fs.realpathSync(q); } catch (e) { if (missing(e)) return null; throw e; } };\n const outside = (r) => out({ e: \"policy\", m: p + \" resolves to \" + r + \", outside the device's roots\" });\n try {\n if (op === \"read\" || op === \"stat\") {\n const r = real(p);\n if (r === null) return out({ r: null });\n if (!under(r)) return outside(r);\n const fd = fs.openSync(r, C.O_RDONLY | C.O_NONBLOCK | C.O_NOFOLLOW);\n try {\n const st = fs.fstatSync(fd);\n if (op === \"stat\") return out({ r: { size: st.size, isDir: st.isDirectory() } });\n if (st.isDirectory()) return out({ r: null });\n if (!st.isFile()) return out({ e: \"policy\", m: p + \" is not a regular file\" });\n const max = Number(maxS);\n const want = Math.min(st.size, max);\n const buf = Buffer.alloc(want);\n let off = 0;\n while (off < want) {\n const n = fs.readSync(fd, buf, off, want - off, off);\n if (n === 0) break;\n off += n;\n }\n return out({ r: { b64: buf.subarray(0, off).toString(\"base64\"), truncated: st.size > max } });\n } finally {\n fs.closeSync(fd);\n }\n }\n if (op === \"write\") {\n const data = fs.readFileSync(0);\n const parent = path.dirname(p);\n let anc = parent;\n while (real(anc) === null && anc !== path.dirname(anc)) anc = path.dirname(anc);\n const ra = real(anc);\n if (ra === null || !under(ra)) return outside(ra);\n fs.mkdirSync(parent, { recursive: true });\n const rp = real(parent);\n if (rp === null) return out({ e: \"error\", m: \"cannot create \" + parent });\n if (!under(rp)) return outside(rp);\n let file = path.join(rp, path.basename(p));\n let st = null;\n try { st = fs.lstatSync(file); } catch (e) { if (!missing(e)) throw e; }\n if (st && st.isSymbolicLink()) {\n const r = real(file);\n if (r === null) return out({ e: \"policy\", m: p + \" is a dangling symbolic link\" });\n if (!under(r)) return outside(r);\n file = r;\n }\n const fd = fs.openSync(file, C.O_WRONLY | C.O_CREAT | C.O_NONBLOCK | C.O_NOFOLLOW, 0o644);\n try {\n if (!fs.fstatSync(fd).isFile()) return out({ e: \"policy\", m: p + \" is not a regular file\" });\n fs.ftruncateSync(fd, 0);\n let off = 0;\n while (off < data.length) off += fs.writeSync(fd, data, off, data.length - off, off);\n } finally {\n fs.closeSync(fd);\n }\n return out({ r: null });\n }\n out({ e: \"error\", m: \"unknown helper op \" + op });\n } catch (e) {\n out({ e: \"error\", m: String((e && e.message) || e) });\n }\n})();\n";
|
package/dist/exec/fs-helper.js
CHANGED
|
@@ -20,7 +20,7 @@ export const FS_HELPER_SCRIPT = `
|
|
|
20
20
|
const under = (r) => realRoots.some((x) => r === x || r.startsWith(x + "/"));
|
|
21
21
|
const missing = (e) => e && (e.code === "ENOENT" || e.code === "ENOTDIR");
|
|
22
22
|
const real = (q) => { try { return fs.realpathSync(q); } catch (e) { if (missing(e)) return null; throw e; } };
|
|
23
|
-
const outside = (r) => out({ e: "policy", m: p + " resolves to " + r + ", outside the
|
|
23
|
+
const outside = (r) => out({ e: "policy", m: p + " resolves to " + r + ", outside the device's roots" });
|
|
24
24
|
try {
|
|
25
25
|
if (op === "read" || op === "stat") {
|
|
26
26
|
const r = real(p);
|
package/dist/exec/os.d.ts
CHANGED
|
@@ -11,7 +11,7 @@ export declare function sandboxAvailability(): {
|
|
|
11
11
|
reason: string;
|
|
12
12
|
};
|
|
13
13
|
export interface OsExecutorOptions {
|
|
14
|
-
/** The
|
|
14
|
+
/** The device directory (from login). */
|
|
15
15
|
dir: string;
|
|
16
16
|
policy: Policy;
|
|
17
17
|
/** The home whose secret paths are denied (default: the user's home). */
|
|
@@ -22,7 +22,7 @@ export interface OsExecutorOptions {
|
|
|
22
22
|
/**
|
|
23
23
|
* Runs every command inside `@anthropic-ai/sandbox-runtime` (macOS Seatbelt, Linux bubblewrap):
|
|
24
24
|
* writes only under the workspace and tmp roots, the secret paths unreadable, network only to
|
|
25
|
-
* the intersection of the local policy and the
|
|
25
|
+
* the intersection of the local policy and the device's egress. File operations in the
|
|
26
26
|
* workspace and tmp roots run in a sandboxed helper too. Construct it with
|
|
27
27
|
* {@link createOsExecutor}; the constructor alone serves only `ensureRoot` and the skills root.
|
|
28
28
|
*/
|
|
@@ -31,7 +31,7 @@ export declare class OsExecutor implements Executor {
|
|
|
31
31
|
readonly mode: "os";
|
|
32
32
|
readonly roots: SandboxRoots;
|
|
33
33
|
private readonly dir;
|
|
34
|
-
/** Marks every process of this
|
|
34
|
+
/** Marks every process of this device's commands: `<dirKey>.<tag>`. */
|
|
35
35
|
private readonly dirKey;
|
|
36
36
|
private readonly groups;
|
|
37
37
|
private pruneTimer;
|
|
@@ -67,14 +67,14 @@ export declare class OsExecutor implements Executor {
|
|
|
67
67
|
} | null>;
|
|
68
68
|
killTagged(tags: string[]): Promise<void>;
|
|
69
69
|
killAll(): Promise<void>;
|
|
70
|
-
/** Kills every process carrying this
|
|
70
|
+
/** Kills every process carrying this device's marker (also a previous run's). */
|
|
71
71
|
killLeftovers(): Promise<void>;
|
|
72
72
|
/** Kills every running command and shuts the sandbox's proxies down. */
|
|
73
73
|
dispose(): Promise<void>;
|
|
74
74
|
}
|
|
75
75
|
/**
|
|
76
76
|
* The OS sandbox executor: checks the platform and dependencies, starts the sandbox's proxies
|
|
77
|
-
* once for this process, and kills what a previous run of this
|
|
77
|
+
* once for this process, and kills what a previous run of this device left running.
|
|
78
78
|
* Network is denied unless a command's own list allows it.
|
|
79
79
|
*/
|
|
80
80
|
export declare function createOsExecutor(opts: OsExecutorOptions): Promise<OsExecutor>;
|
package/dist/exec/os.js
CHANGED
|
@@ -58,7 +58,7 @@ function pidAlive(pid) {
|
|
|
58
58
|
/**
|
|
59
59
|
* Runs every command inside `@anthropic-ai/sandbox-runtime` (macOS Seatbelt, Linux bubblewrap):
|
|
60
60
|
* writes only under the workspace and tmp roots, the secret paths unreadable, network only to
|
|
61
|
-
* the intersection of the local policy and the
|
|
61
|
+
* the intersection of the local policy and the device's egress. File operations in the
|
|
62
62
|
* workspace and tmp roots run in a sandboxed helper too. Construct it with
|
|
63
63
|
* {@link createOsExecutor}; the constructor alone serves only `ensureRoot` and the skills root.
|
|
64
64
|
*/
|
|
@@ -67,7 +67,7 @@ export class OsExecutor {
|
|
|
67
67
|
mode = "os";
|
|
68
68
|
roots;
|
|
69
69
|
dir;
|
|
70
|
-
/** Marks every process of this
|
|
70
|
+
/** Marks every process of this device's commands: `<dirKey>.<tag>`. */
|
|
71
71
|
dirKey;
|
|
72
72
|
groups = new Set();
|
|
73
73
|
pruneTimer;
|
|
@@ -367,7 +367,7 @@ export class OsExecutor {
|
|
|
367
367
|
this.killGroup(g);
|
|
368
368
|
await this.killLeftovers();
|
|
369
369
|
}
|
|
370
|
-
/** Kills every process carrying this
|
|
370
|
+
/** Kills every process carrying this device's marker (also a previous run's). */
|
|
371
371
|
async killLeftovers() {
|
|
372
372
|
const prefix = `${this.dirKey}.`;
|
|
373
373
|
await killMarked((v) => v.startsWith(prefix));
|
|
@@ -383,7 +383,7 @@ export class OsExecutor {
|
|
|
383
383
|
}
|
|
384
384
|
/**
|
|
385
385
|
* The OS sandbox executor: checks the platform and dependencies, starts the sandbox's proxies
|
|
386
|
-
* once for this process, and kills what a previous run of this
|
|
386
|
+
* once for this process, and kills what a previous run of this device left running.
|
|
387
387
|
* Network is denied unless a command's own list allows it.
|
|
388
388
|
*/
|
|
389
389
|
export async function createOsExecutor(opts) {
|
package/dist/exec/shared.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import type { SandboxRoots } from "@capybara-hq/plugin-sdk";
|
|
2
2
|
import { DeviceOpError } from "./types.js";
|
|
3
|
-
/** The file that marks a directory as
|
|
3
|
+
/** The file that marks a directory as a device directory this program has used. */
|
|
4
4
|
export declare const ROOT_MARKER = ".capybara-device";
|
|
5
5
|
/** How long a finished command's output pipes may stay open (held by a background child). */
|
|
6
6
|
export declare const PIPE_GRACE_MS = 200;
|
|
7
7
|
export declare const ENV_NAME_RE: RegExp;
|
|
8
|
-
/** The roots of
|
|
8
|
+
/** The roots of a device directory: `<dir>/workspace`, `<dir>/skills`, `<dir>/tmp`. */
|
|
9
9
|
export declare function osRoots(dir: string): SandboxRoots;
|
|
10
10
|
/**
|
|
11
11
|
* The longest prefix of `b` that does not end inside a UTF-8 sequence (a cut buffer's tail is
|
|
@@ -28,12 +28,12 @@ export declare class OutputCap {
|
|
|
28
28
|
text(stream: "stdout" | "stderr"): string;
|
|
29
29
|
}
|
|
30
30
|
/**
|
|
31
|
-
* Creates (or completes)
|
|
32
|
-
* calls it, so logging in again after the files were lost starts the
|
|
31
|
+
* Creates (or completes) a device directory: the marker and the three roots. Only `login`
|
|
32
|
+
* calls it, so logging in again after the files were lost starts the device afresh.
|
|
33
33
|
*/
|
|
34
|
-
export declare function
|
|
34
|
+
export declare function prepareDeviceDir(dir: string): void;
|
|
35
35
|
/**
|
|
36
|
-
* The
|
|
36
|
+
* The device directory's marker and roots. Once the marker exists, the directory, the marker
|
|
37
37
|
* or any root vanishing is "gone": nothing is recreated silently (log in again to start afresh).
|
|
38
38
|
*/
|
|
39
39
|
export declare class RootGuard {
|
package/dist/exec/shared.js
CHANGED
|
@@ -2,12 +2,12 @@ import { constants, existsSync, mkdirSync, writeFileSync } from "node:fs";
|
|
|
2
2
|
import { lstat, mkdir, open, realpath } from "node:fs/promises";
|
|
3
3
|
import { basename, dirname, isAbsolute, join, resolve } from "node:path";
|
|
4
4
|
import { DeviceOpError } from "./types.js";
|
|
5
|
-
/** The file that marks a directory as
|
|
5
|
+
/** The file that marks a directory as a device directory this program has used. */
|
|
6
6
|
export const ROOT_MARKER = ".capybara-device";
|
|
7
7
|
/** How long a finished command's output pipes may stay open (held by a background child). */
|
|
8
8
|
export const PIPE_GRACE_MS = 200;
|
|
9
9
|
export const ENV_NAME_RE = /^[A-Za-z_][A-Za-z0-9_]*$/;
|
|
10
|
-
/** The roots of
|
|
10
|
+
/** The roots of a device directory: `<dir>/workspace`, `<dir>/skills`, `<dir>/tmp`. */
|
|
11
11
|
export function osRoots(dir) {
|
|
12
12
|
return { workspace: join(dir, "workspace"), skills: join(dir, "skills"), tmp: join(dir, "tmp") };
|
|
13
13
|
}
|
|
@@ -69,12 +69,12 @@ export class OutputCap {
|
|
|
69
69
|
return (this.cut[stream] ? utf8Prefix(all) : all).toString("utf8");
|
|
70
70
|
}
|
|
71
71
|
}
|
|
72
|
-
const MARKER_TEXT = "This directory is a capybara-device
|
|
72
|
+
const MARKER_TEXT = "This directory is a capybara-device directory.\n";
|
|
73
73
|
/**
|
|
74
|
-
* Creates (or completes)
|
|
75
|
-
* calls it, so logging in again after the files were lost starts the
|
|
74
|
+
* Creates (or completes) a device directory: the marker and the three roots. Only `login`
|
|
75
|
+
* calls it, so logging in again after the files were lost starts the device afresh.
|
|
76
76
|
*/
|
|
77
|
-
export function
|
|
77
|
+
export function prepareDeviceDir(dir) {
|
|
78
78
|
for (const r of Object.values(osRoots(dir)))
|
|
79
79
|
mkdirSync(r, { recursive: true });
|
|
80
80
|
const marker = join(dir, ROOT_MARKER);
|
|
@@ -82,7 +82,7 @@ export function prepareEnvironmentDir(dir) {
|
|
|
82
82
|
writeFileSync(marker, MARKER_TEXT);
|
|
83
83
|
}
|
|
84
84
|
/**
|
|
85
|
-
* The
|
|
85
|
+
* The device directory's marker and roots. Once the marker exists, the directory, the marker
|
|
86
86
|
* or any root vanishing is "gone": nothing is recreated silently (log in again to start afresh).
|
|
87
87
|
*/
|
|
88
88
|
export class RootGuard {
|
|
@@ -127,7 +127,7 @@ export class HostFiles {
|
|
|
127
127
|
throw policyError(`${path} is not an absolute path`);
|
|
128
128
|
const p = resolve(path);
|
|
129
129
|
if (!this.rootList().some((r) => isUnder(p, r))) {
|
|
130
|
-
throw policyError(`${path} is outside the
|
|
130
|
+
throw policyError(`${path} is outside the device's roots (${this.rootList().join(", ")})`);
|
|
131
131
|
}
|
|
132
132
|
return p;
|
|
133
133
|
}
|
|
@@ -162,7 +162,7 @@ export class HostFiles {
|
|
|
162
162
|
async checkReal(path, real) {
|
|
163
163
|
const roots = await Promise.all(this.rootList().map((r) => realpath(r).catch(() => r)));
|
|
164
164
|
if (!roots.some((r) => isUnder(real, r))) {
|
|
165
|
-
throw policyError(`${path} resolves to ${real}, outside the
|
|
165
|
+
throw policyError(`${path} resolves to ${real}, outside the device's roots`);
|
|
166
166
|
}
|
|
167
167
|
return real;
|
|
168
168
|
}
|
package/dist/exec/types.d.ts
CHANGED
|
@@ -22,7 +22,7 @@ export interface Executor {
|
|
|
22
22
|
killTagged(tags: string[]): Promise<void>;
|
|
23
23
|
killAll(): Promise<void>;
|
|
24
24
|
/**
|
|
25
|
-
* Creates the
|
|
25
|
+
* Creates the device directory (and its marker file) on first use. "gone" when it existed
|
|
26
26
|
* before and has vanished; it is never recreated silently.
|
|
27
27
|
*/
|
|
28
28
|
ensureRoot(): Promise<"ok" | "gone">;
|
package/dist/policy.d.ts
CHANGED
|
@@ -11,15 +11,15 @@ export declare const DENIED_SECRET_PATHS: readonly string[];
|
|
|
11
11
|
export declare function deniedSecretPaths(home?: string): string[];
|
|
12
12
|
/**
|
|
13
13
|
* Paths sandbox-runtime makes writable without being asked (its own temp directory and two home
|
|
14
|
-
* convenience directories). They lie outside the
|
|
14
|
+
* convenience directories). They lie outside the device directory, so they are denied.
|
|
15
15
|
*/
|
|
16
16
|
export declare function implicitWritePaths(home?: string): string[];
|
|
17
17
|
/**
|
|
18
|
-
* The domains one command may reach: what the
|
|
18
|
+
* The domains one command may reach: what the device's egress allows, cut to the local
|
|
19
19
|
* policy. The cloud can only narrow it: an empty policy allows nothing, whatever the egress.
|
|
20
20
|
*/
|
|
21
21
|
export declare function effectiveEgress(policy: Pick<Policy, "allowedDomains">, limits: Pick<SandboxLimits, "egress" | "allowHosts">): string[];
|
|
22
|
-
/** The sandbox-runtime configuration of one
|
|
22
|
+
/** The sandbox-runtime configuration of one device. */
|
|
23
23
|
export interface SrtConfig {
|
|
24
24
|
filesystem: {
|
|
25
25
|
denyRead: string[];
|
package/dist/policy.js
CHANGED
|
@@ -40,7 +40,7 @@ export function deniedSecretPaths(home = homedir()) {
|
|
|
40
40
|
}
|
|
41
41
|
/**
|
|
42
42
|
* Paths sandbox-runtime makes writable without being asked (its own temp directory and two home
|
|
43
|
-
* convenience directories). They lie outside the
|
|
43
|
+
* convenience directories). They lie outside the device directory, so they are denied.
|
|
44
44
|
*/
|
|
45
45
|
export function implicitWritePaths(home = homedir()) {
|
|
46
46
|
return [
|
|
@@ -58,7 +58,7 @@ function covers(pattern, host) {
|
|
|
58
58
|
return pattern.startsWith("*.") && host.endsWith(pattern.slice(1));
|
|
59
59
|
}
|
|
60
60
|
/**
|
|
61
|
-
* The domains one command may reach: what the
|
|
61
|
+
* The domains one command may reach: what the device's egress allows, cut to the local
|
|
62
62
|
* policy. The cloud can only narrow it: an empty policy allows nothing, whatever the egress.
|
|
63
63
|
*/
|
|
64
64
|
export function effectiveEgress(policy, limits) {
|
package/dist/server-ops.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { type Executor } from "./exec/types.js";
|
|
|
4
4
|
/** The local-log line for a finished request. */
|
|
5
5
|
export declare function logEntryFor(req: KernelReq, res: DeviceRes, now: Date): CommandLogEntry;
|
|
6
6
|
/**
|
|
7
|
-
* Runs one request on the executor and returns the answer. A vanished
|
|
7
|
+
* Runs one request on the executor and returns the answer. A vanished device directory
|
|
8
8
|
* answers `fs_gone` for every operation except `stop`. Never throws.
|
|
9
9
|
*/
|
|
10
10
|
export declare function runOp(executor: Executor, req: KernelReq, signal: AbortSignal): Promise<DeviceRes>;
|
package/dist/server-ops.js
CHANGED
|
@@ -14,7 +14,7 @@ export function logEntryFor(req, res, now) {
|
|
|
14
14
|
};
|
|
15
15
|
}
|
|
16
16
|
/**
|
|
17
|
-
* Runs one request on the executor and returns the answer. A vanished
|
|
17
|
+
* Runs one request on the executor and returns the answer. A vanished device directory
|
|
18
18
|
* answers `fs_gone` for every operation except `stop`. Never throws.
|
|
19
19
|
*/
|
|
20
20
|
export async function runOp(executor, req, signal) {
|
|
@@ -29,7 +29,7 @@ export async function runOp(executor, req, signal) {
|
|
|
29
29
|
ok: false,
|
|
30
30
|
error: {
|
|
31
31
|
kind: "fs_gone",
|
|
32
|
-
message: "The
|
|
32
|
+
message: "The device directory on this machine existed and is gone. It is not recreated automatically.",
|
|
33
33
|
},
|
|
34
34
|
};
|
|
35
35
|
}
|
package/dist/state.d.ts
CHANGED
|
@@ -5,12 +5,12 @@ export interface Credential {
|
|
|
5
5
|
connectUrl: string;
|
|
6
6
|
credential: string;
|
|
7
7
|
orgId: string;
|
|
8
|
-
|
|
8
|
+
deviceId: string;
|
|
9
9
|
dir: string;
|
|
10
10
|
mode: DeviceMode;
|
|
11
|
-
/** The deployment's `
|
|
11
|
+
/** The deployment's `devices.local.reconnectGraceSeconds`, returned with the credential. */
|
|
12
12
|
reconnectGraceSeconds: number;
|
|
13
|
-
/** The deployment's `
|
|
13
|
+
/** The deployment's `devices.local.maxFrameBytes`: no frame this program sends is larger. */
|
|
14
14
|
maxFrameBytes: number;
|
|
15
15
|
}
|
|
16
16
|
/** Local limits the person sets for this machine. */
|
|
@@ -27,8 +27,8 @@ type Env = Record<string, string | undefined>;
|
|
|
27
27
|
export declare function stateDir(env?: Env, home?: string): string;
|
|
28
28
|
export declare function credentialPath(dir: string): string;
|
|
29
29
|
export declare function policyPath(dir: string): string;
|
|
30
|
-
/** The default working directory of
|
|
31
|
-
export declare function defaultWorkDir(
|
|
30
|
+
/** The default working directory of a device: `~/capybara-device/<deviceId>`. */
|
|
31
|
+
export declare function defaultWorkDir(deviceId: string, home?: string): string;
|
|
32
32
|
export declare function writePrivate(file: string, text: string): void;
|
|
33
33
|
export declare function writeCredential(dir: string, cred: Credential): void;
|
|
34
34
|
/** The stored credential; undefined when absent. Throws on a file other users can read, or on bad content. */
|
package/dist/state.js
CHANGED
|
@@ -21,9 +21,9 @@ export function credentialPath(dir) {
|
|
|
21
21
|
export function policyPath(dir) {
|
|
22
22
|
return join(dir, "policy.json");
|
|
23
23
|
}
|
|
24
|
-
/** The default working directory of
|
|
25
|
-
export function defaultWorkDir(
|
|
26
|
-
return join(home, "capybara-device",
|
|
24
|
+
/** The default working directory of a device: `~/capybara-device/<deviceId>`. */
|
|
25
|
+
export function defaultWorkDir(deviceId, home = homedir()) {
|
|
26
|
+
return join(home, "capybara-device", deviceId);
|
|
27
27
|
}
|
|
28
28
|
export function writePrivate(file, text) {
|
|
29
29
|
mkdirSync(join(file, ".."), { recursive: true, mode: 0o700 });
|
|
@@ -56,7 +56,7 @@ export function readCredential(dir) {
|
|
|
56
56
|
catch (e) {
|
|
57
57
|
throw new Error(`${file} is not valid JSON (${e.message})`);
|
|
58
58
|
}
|
|
59
|
-
for (const key of ["url", "connectUrl", "credential", "orgId", "
|
|
59
|
+
for (const key of ["url", "connectUrl", "credential", "orgId", "deviceId", "dir", "mode"]) {
|
|
60
60
|
if (typeof raw[key] !== "string") {
|
|
61
61
|
throw new Error(`${file} is invalid: missing ${key}; log in again`);
|
|
62
62
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@capybara-hq/device",
|
|
3
|
-
"version": "0.1.0-rc.
|
|
4
|
-
"description": "capybara-device: connects a laptop or server to a Capybara deployment as
|
|
3
|
+
"version": "0.1.0-rc.2",
|
|
4
|
+
"description": "capybara-device: connects a laptop or server to a Capybara deployment as a device",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"dependencies": {
|
|
35
35
|
"@anthropic-ai/sandbox-runtime": "0.0.81",
|
|
36
36
|
"ws": "^8.18.0",
|
|
37
|
-
"@capybara-hq/plugin-sdk": "^0.1.0-rc.
|
|
37
|
+
"@capybara-hq/plugin-sdk": "^0.1.0-rc.9"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
40
|
"@types/ws": "^8.5.13"
|