disk 1.14.0 → 1.15.0

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.
@@ -0,0 +1,150 @@
1
+ //#region src/sandbox-desktop.ts
2
+ /**
3
+ * Sandbox desktops: a Linux desktop (Ubuntu, XFCE, Firefox) served over VNC
4
+ * through noVNC on {@link DESKTOP_PORT}, from the image at
5
+ * {@link DESKTOP_IMAGE} (github.com/archil-data/sandbox-desktop). Inside the
6
+ * sandbox, `desktopctl` runs the desktop as supervised services; the noVNC
7
+ * server only connects a viewer that presents the desktop's token.
8
+ *
9
+ * Everything here runs commands through the sandbox process API, so it works
10
+ * wherever the SDK does. To view a private desktop from Node, see
11
+ * `openDesktopTunnel` in `disk/tunnel`.
12
+ */
13
+ const DESKTOP_IMAGE = "ghcr.io/archil-data/sandbox-desktop:latest";
14
+ const DESKTOP_PORT = 6080;
15
+ /** A browser on the desktop is sluggish with less. */
16
+ const DESKTOP_VCPUS = 2;
17
+ const DESKTOP_MEMORY_MIB = 4096;
18
+ /**
19
+ * Session cap for desktops. Viewer traffic doesn't count as sandbox activity,
20
+ * so desktops run with idle expiry off and this cap instead.
21
+ */
22
+ const DESKTOP_MAX_TTL_SECONDS = 14400;
23
+ const COMMAND_NOT_FOUND = 127;
24
+ const DISPLAY = "DISPLAY=:1";
25
+ const KEYS = /^[A-Za-z0-9_+ ]+$/;
26
+ /** Path on the desktop's noVNC server that opens the viewer and connects with `token`. */
27
+ function desktopViewerPath(token) {
28
+ return `/vnc.html?${new URLSearchParams({
29
+ autoconnect: "1",
30
+ resize: "remote",
31
+ reconnect: "1",
32
+ path: `websockify?token=${token}`
33
+ })}`;
34
+ }
35
+ var DesktopNotInstalledError = class extends Error {
36
+ constructor(sandboxName) {
37
+ super(`Sandbox '${sandboxName}' doesn't have the Archil desktop installed; create it with desktop: true or from an image based on ${DESKTOP_IMAGE}`);
38
+ this.name = "DesktopNotInstalledError";
39
+ }
40
+ };
41
+ /** The desktop of one sandbox: `sandbox.desktop`. */
42
+ var SandboxDesktop = class {
43
+ sandbox;
44
+ /** @internal */
45
+ constructor(sandbox) {
46
+ this.sandbox = sandbox;
47
+ }
48
+ /**
49
+ * Starts the desktop if it isn't running (safe to call repeatedly) and
50
+ * returns the viewer token. Anyone holding the token can view and control
51
+ * the desktop through a link to its port.
52
+ */
53
+ async start() {
54
+ const { token } = JSON.parse(await this.run("desktopctl up"));
55
+ return { token };
56
+ }
57
+ /** The current viewer token. `rotate` replaces it first; a fork should rotate so it doesn't share its parent's. */
58
+ async token(options = {}) {
59
+ return (await this.run(options.rotate ? "desktopctl token --rotate" : "desktopctl token")).trim();
60
+ }
61
+ /**
62
+ * Publishes the desktop on a public HTTPS hostname and returns a viewer
63
+ * link. Anyone with the link can see and control the desktop until
64
+ * {@link unshare}.
65
+ */
66
+ async share() {
67
+ const { token } = await this.start();
68
+ return `https://${await this.sandbox.exposePort(DESKTOP_PORT)}${desktopViewerPath(token)}`;
69
+ }
70
+ /** Removes the public hostname, invalidates every existing link, and disconnects current viewers. */
71
+ async unshare() {
72
+ await this.sandbox.unexposePort(DESKTOP_PORT);
73
+ await this.run("desktopctl revoke");
74
+ }
75
+ /** A PNG of the whole screen. */
76
+ async screenshot() {
77
+ return decodeBase64((await this.run(`${DISPLAY} scrot -o /tmp/.archil-desktop-shot.png && base64 -w0 /tmp/.archil-desktop-shot.png`)).trim());
78
+ }
79
+ /** The screen size in pixels. */
80
+ async size() {
81
+ const [width, height] = (await this.run(`${DISPLAY} xdotool getdisplaygeometry`)).trim().split(/\s+/).map(Number);
82
+ return {
83
+ width,
84
+ height
85
+ };
86
+ }
87
+ async moveMouse(x, y) {
88
+ await this.run(`${DISPLAY} xdotool mousemove ${coordinate(x)} ${coordinate(y)}`);
89
+ }
90
+ async click(x, y, options = {}) {
91
+ const button = {
92
+ left: 1,
93
+ middle: 2,
94
+ right: 3
95
+ }[options.button ?? "left"];
96
+ const repeat = options.double ? " --repeat 2" : "";
97
+ await this.run(`${DISPLAY} xdotool mousemove ${coordinate(x)} ${coordinate(y)} click${repeat} ${button}`);
98
+ }
99
+ async scroll(direction, amount = 3) {
100
+ const button = {
101
+ up: 4,
102
+ down: 5,
103
+ left: 6,
104
+ right: 7
105
+ }[direction];
106
+ await this.run(`${DISPLAY} xdotool click --repeat ${count(amount)} ${button}`);
107
+ }
108
+ /** Types `text` into the focused window. */
109
+ async type(text) {
110
+ await this.run(`${DISPLAY} xdotool type --delay 12 -- "$ARCHIL_DESKTOP_TEXT"`, { ARCHIL_DESKTOP_TEXT: text });
111
+ }
112
+ /** Presses a key or chord in xdotool's syntax, e.g. "Return", "ctrl+l", "ctrl+shift+t". */
113
+ async key(keys) {
114
+ if (!KEYS.test(keys)) throw new Error(`Invalid key '${keys}'; use names like Return, ctrl+l, or alt+F4`);
115
+ await this.run(`${DISPLAY} xdotool key -- $ARCHIL_DESKTOP_KEYS`, { ARCHIL_DESKTOP_KEYS: keys });
116
+ }
117
+ /** Starts a program on the desktop as its user, e.g. `["firefox", "https://archil.com"]`. It keeps running after this returns. */
118
+ async launch(argv) {
119
+ if (argv.length === 0) throw new Error("launch needs a program to run");
120
+ await this.run(`desktopctl launch ${argv.map(shellQuote).join(" ")}`);
121
+ }
122
+ async run(command, env) {
123
+ const result = await this.sandbox.exec(command, env ? { env } : void 0);
124
+ if (result.exitCode === COMMAND_NOT_FOUND) throw new DesktopNotInstalledError(this.sandbox.name);
125
+ if (result.exitCode !== 0) {
126
+ const name = command.split(" ").find((word) => !word.includes("="));
127
+ throw new Error(`${name} failed in sandbox '${this.sandbox.name}': ${(result.stderr || result.stdout).trim()}`);
128
+ }
129
+ return result.stdout;
130
+ }
131
+ };
132
+ function coordinate(value) {
133
+ if (!Number.isFinite(value) || value < 0) throw new Error(`Invalid screen coordinate ${value}`);
134
+ return Math.round(value);
135
+ }
136
+ function count(value) {
137
+ if (!Number.isInteger(value) || value < 1 || value > 100) throw new Error(`Scroll amount must be an integer from 1 to 100`);
138
+ return value;
139
+ }
140
+ function shellQuote(value) {
141
+ return `'${value.replaceAll("'", `'\\''`)}'`;
142
+ }
143
+ function decodeBase64(text) {
144
+ const binary = atob(text);
145
+ const bytes = new Uint8Array(binary.length);
146
+ for (let index = 0; index < binary.length; index++) bytes[index] = binary.charCodeAt(index);
147
+ return bytes;
148
+ }
149
+ //#endregion
150
+ export { DESKTOP_VCPUS as a, desktopViewerPath as c, DESKTOP_PORT as i, DESKTOP_MAX_TTL_SECONDS as n, DesktopNotInstalledError as o, DESKTOP_MEMORY_MIB as r, SandboxDesktop as s, DESKTOP_IMAGE as t };
@@ -0,0 +1,197 @@
1
+ //#region src/sandbox-desktop.ts
2
+ /**
3
+ * Sandbox desktops: a Linux desktop (Ubuntu, XFCE, Firefox) served over VNC
4
+ * through noVNC on {@link DESKTOP_PORT}, from the image at
5
+ * {@link DESKTOP_IMAGE} (github.com/archil-data/sandbox-desktop). Inside the
6
+ * sandbox, `desktopctl` runs the desktop as supervised services; the noVNC
7
+ * server only connects a viewer that presents the desktop's token.
8
+ *
9
+ * Everything here runs commands through the sandbox process API, so it works
10
+ * wherever the SDK does. To view a private desktop from Node, see
11
+ * `openDesktopTunnel` in `disk/tunnel`.
12
+ */
13
+ const DESKTOP_IMAGE = "ghcr.io/archil-data/sandbox-desktop:latest";
14
+ const DESKTOP_PORT = 6080;
15
+ /** A browser on the desktop is sluggish with less. */
16
+ const DESKTOP_VCPUS = 2;
17
+ const DESKTOP_MEMORY_MIB = 4096;
18
+ /**
19
+ * Session cap for desktops. Viewer traffic doesn't count as sandbox activity,
20
+ * so desktops run with idle expiry off and this cap instead.
21
+ */
22
+ const DESKTOP_MAX_TTL_SECONDS = 14400;
23
+ const COMMAND_NOT_FOUND = 127;
24
+ const DISPLAY = "DISPLAY=:1";
25
+ const KEYS = /^[A-Za-z0-9_+ ]+$/;
26
+ /** Path on the desktop's noVNC server that opens the viewer and connects with `token`. */
27
+ function desktopViewerPath(token) {
28
+ return `/vnc.html?${new URLSearchParams({
29
+ autoconnect: "1",
30
+ resize: "remote",
31
+ reconnect: "1",
32
+ path: `websockify?token=${token}`
33
+ })}`;
34
+ }
35
+ var DesktopNotInstalledError = class extends Error {
36
+ constructor(sandboxName) {
37
+ super(`Sandbox '${sandboxName}' doesn't have the Archil desktop installed; create it with desktop: true or from an image based on ${DESKTOP_IMAGE}`);
38
+ this.name = "DesktopNotInstalledError";
39
+ }
40
+ };
41
+ /** The desktop of one sandbox: `sandbox.desktop`. */
42
+ var SandboxDesktop = class {
43
+ sandbox;
44
+ /** @internal */
45
+ constructor(sandbox) {
46
+ this.sandbox = sandbox;
47
+ }
48
+ /**
49
+ * Starts the desktop if it isn't running (safe to call repeatedly) and
50
+ * returns the viewer token. Anyone holding the token can view and control
51
+ * the desktop through a link to its port.
52
+ */
53
+ async start() {
54
+ const { token } = JSON.parse(await this.run("desktopctl up"));
55
+ return { token };
56
+ }
57
+ /** The current viewer token. `rotate` replaces it first; a fork should rotate so it doesn't share its parent's. */
58
+ async token(options = {}) {
59
+ return (await this.run(options.rotate ? "desktopctl token --rotate" : "desktopctl token")).trim();
60
+ }
61
+ /**
62
+ * Publishes the desktop on a public HTTPS hostname and returns a viewer
63
+ * link. Anyone with the link can see and control the desktop until
64
+ * {@link unshare}.
65
+ */
66
+ async share() {
67
+ const { token } = await this.start();
68
+ return `https://${await this.sandbox.exposePort(DESKTOP_PORT)}${desktopViewerPath(token)}`;
69
+ }
70
+ /** Removes the public hostname, invalidates every existing link, and disconnects current viewers. */
71
+ async unshare() {
72
+ await this.sandbox.unexposePort(DESKTOP_PORT);
73
+ await this.run("desktopctl revoke");
74
+ }
75
+ /** A PNG of the whole screen. */
76
+ async screenshot() {
77
+ return decodeBase64((await this.run(`${DISPLAY} scrot -o /tmp/.archil-desktop-shot.png && base64 -w0 /tmp/.archil-desktop-shot.png`)).trim());
78
+ }
79
+ /** The screen size in pixels. */
80
+ async size() {
81
+ const [width, height] = (await this.run(`${DISPLAY} xdotool getdisplaygeometry`)).trim().split(/\s+/).map(Number);
82
+ return {
83
+ width,
84
+ height
85
+ };
86
+ }
87
+ async moveMouse(x, y) {
88
+ await this.run(`${DISPLAY} xdotool mousemove ${coordinate(x)} ${coordinate(y)}`);
89
+ }
90
+ async click(x, y, options = {}) {
91
+ const button = {
92
+ left: 1,
93
+ middle: 2,
94
+ right: 3
95
+ }[options.button ?? "left"];
96
+ const repeat = options.double ? " --repeat 2" : "";
97
+ await this.run(`${DISPLAY} xdotool mousemove ${coordinate(x)} ${coordinate(y)} click${repeat} ${button}`);
98
+ }
99
+ async scroll(direction, amount = 3) {
100
+ const button = {
101
+ up: 4,
102
+ down: 5,
103
+ left: 6,
104
+ right: 7
105
+ }[direction];
106
+ await this.run(`${DISPLAY} xdotool click --repeat ${count(amount)} ${button}`);
107
+ }
108
+ /** Types `text` into the focused window. */
109
+ async type(text) {
110
+ await this.run(`${DISPLAY} xdotool type --delay 12 -- "$ARCHIL_DESKTOP_TEXT"`, { ARCHIL_DESKTOP_TEXT: text });
111
+ }
112
+ /** Presses a key or chord in xdotool's syntax, e.g. "Return", "ctrl+l", "ctrl+shift+t". */
113
+ async key(keys) {
114
+ if (!KEYS.test(keys)) throw new Error(`Invalid key '${keys}'; use names like Return, ctrl+l, or alt+F4`);
115
+ await this.run(`${DISPLAY} xdotool key -- $ARCHIL_DESKTOP_KEYS`, { ARCHIL_DESKTOP_KEYS: keys });
116
+ }
117
+ /** Starts a program on the desktop as its user, e.g. `["firefox", "https://archil.com"]`. It keeps running after this returns. */
118
+ async launch(argv) {
119
+ if (argv.length === 0) throw new Error("launch needs a program to run");
120
+ await this.run(`desktopctl launch ${argv.map(shellQuote).join(" ")}`);
121
+ }
122
+ async run(command, env) {
123
+ const result = await this.sandbox.exec(command, env ? { env } : void 0);
124
+ if (result.exitCode === COMMAND_NOT_FOUND) throw new DesktopNotInstalledError(this.sandbox.name);
125
+ if (result.exitCode !== 0) {
126
+ const name = command.split(" ").find((word) => !word.includes("="));
127
+ throw new Error(`${name} failed in sandbox '${this.sandbox.name}': ${(result.stderr || result.stdout).trim()}`);
128
+ }
129
+ return result.stdout;
130
+ }
131
+ };
132
+ function coordinate(value) {
133
+ if (!Number.isFinite(value) || value < 0) throw new Error(`Invalid screen coordinate ${value}`);
134
+ return Math.round(value);
135
+ }
136
+ function count(value) {
137
+ if (!Number.isInteger(value) || value < 1 || value > 100) throw new Error(`Scroll amount must be an integer from 1 to 100`);
138
+ return value;
139
+ }
140
+ function shellQuote(value) {
141
+ return `'${value.replaceAll("'", `'\\''`)}'`;
142
+ }
143
+ function decodeBase64(text) {
144
+ const binary = atob(text);
145
+ const bytes = new Uint8Array(binary.length);
146
+ for (let index = 0; index < binary.length; index++) bytes[index] = binary.charCodeAt(index);
147
+ return bytes;
148
+ }
149
+ //#endregion
150
+ Object.defineProperty(exports, "DESKTOP_IMAGE", {
151
+ enumerable: true,
152
+ get: function() {
153
+ return DESKTOP_IMAGE;
154
+ }
155
+ });
156
+ Object.defineProperty(exports, "DESKTOP_MAX_TTL_SECONDS", {
157
+ enumerable: true,
158
+ get: function() {
159
+ return DESKTOP_MAX_TTL_SECONDS;
160
+ }
161
+ });
162
+ Object.defineProperty(exports, "DESKTOP_MEMORY_MIB", {
163
+ enumerable: true,
164
+ get: function() {
165
+ return DESKTOP_MEMORY_MIB;
166
+ }
167
+ });
168
+ Object.defineProperty(exports, "DESKTOP_PORT", {
169
+ enumerable: true,
170
+ get: function() {
171
+ return DESKTOP_PORT;
172
+ }
173
+ });
174
+ Object.defineProperty(exports, "DESKTOP_VCPUS", {
175
+ enumerable: true,
176
+ get: function() {
177
+ return DESKTOP_VCPUS;
178
+ }
179
+ });
180
+ Object.defineProperty(exports, "DesktopNotInstalledError", {
181
+ enumerable: true,
182
+ get: function() {
183
+ return DesktopNotInstalledError;
184
+ }
185
+ });
186
+ Object.defineProperty(exports, "SandboxDesktop", {
187
+ enumerable: true,
188
+ get: function() {
189
+ return SandboxDesktop;
190
+ }
191
+ });
192
+ Object.defineProperty(exports, "desktopViewerPath", {
193
+ enumerable: true,
194
+ get: function() {
195
+ return desktopViewerPath;
196
+ }
197
+ });
@@ -1,7 +1,166 @@
1
- import { O as REGION_URLS, p as Archil } from "./src-DGB_iQTG.mjs";
1
+ import { O as REGION_URLS, k as ArchilApiError, p as Archil } from "./src-BFPiWUCL.mjs";
2
+ import "./sandbox-desktop-CrvuoiGi.mjs";
2
3
  import { chmod, mkdir, open, readFile, rename, rm, stat } from "node:fs/promises";
3
4
  import { dirname, join } from "node:path";
4
5
  import { homedir } from "node:os";
6
+ //#region src/cli/ui.ts
7
+ const ESC = "\x1B[";
8
+ const CLEAR_LINE$1 = "\r\x1B[2K";
9
+ const HIDE_CURSOR$1 = "\x1B[?25l";
10
+ const SHOW_CURSOR$1 = "\x1B[?25h";
11
+ const FRAMES$1 = [
12
+ "⠋",
13
+ "⠙",
14
+ "⠹",
15
+ "⠸",
16
+ "⠼",
17
+ "⠴",
18
+ "⠦",
19
+ "⠧",
20
+ "⠇",
21
+ "⠏"
22
+ ];
23
+ const SHOW_ELAPSED_AFTER_MS = 1e3;
24
+ const ANSI$1 = /\x1b\[[0-9;?]*[A-Za-z]/g;
25
+ function visibleLength(text) {
26
+ return text.replace(ANSI$1, "").length;
27
+ }
28
+ function colorEnabled(stream, env = process.env) {
29
+ if (env.NO_COLOR) return false;
30
+ if (env.FORCE_COLOR && env.FORCE_COLOR !== "0") return true;
31
+ return Boolean(stream.isTTY) && env.TERM !== "dumb";
32
+ }
33
+ function styles(enabled) {
34
+ const wrap = (open, close) => (text) => enabled ? `${ESC}${open}m${text}${ESC}${close}m` : text;
35
+ return {
36
+ bold: wrap(1, 22),
37
+ dim: wrap(2, 22),
38
+ underline: wrap(4, 24),
39
+ red: wrap(31, 39),
40
+ green: wrap(32, 39),
41
+ yellow: wrap(33, 39),
42
+ cyan: wrap(36, 39),
43
+ magenta: wrap(35, 39)
44
+ };
45
+ }
46
+ function formatDuration(milliseconds) {
47
+ if (milliseconds < 1e3) return `${Math.max(0, Math.round(milliseconds))}ms`;
48
+ const seconds = milliseconds / 1e3;
49
+ if (seconds < 60) return `${seconds.toFixed(1)}s`;
50
+ const minutes = Math.floor(seconds / 60);
51
+ if (minutes < 60) return `${minutes}m ${Math.floor(seconds % 60)}s`;
52
+ return `${Math.floor(minutes / 60)}h ${minutes % 60}m`;
53
+ }
54
+ function createUi(stream, options = {}) {
55
+ const interactive = Boolean(stream.isTTY);
56
+ const style = styles(colorEnabled(stream, options.env));
57
+ const now = options.now ?? Date.now;
58
+ const symbol = {
59
+ ok: style.green("✓"),
60
+ fail: style.red("✗"),
61
+ warn: style.yellow("!"),
62
+ info: style.cyan("›")
63
+ };
64
+ const fit = (text) => {
65
+ const width = stream.columns ?? 0;
66
+ if (width <= 0 || visibleLength(text) < width) return text;
67
+ return `${text.replace(ANSI$1, "").slice(0, width - 2)}…`;
68
+ };
69
+ return {
70
+ interactive,
71
+ style,
72
+ async step(label, operation, done) {
73
+ if (!interactive) return operation({ update: () => {} });
74
+ const started = now();
75
+ let current = label;
76
+ let frame = 0;
77
+ const draw = () => {
78
+ const elapsed = now() - started;
79
+ const timer = elapsed >= SHOW_ELAPSED_AFTER_MS ? ` ${style.dim(formatDuration(elapsed))}` : "";
80
+ stream.write(`${CLEAR_LINE$1}${fit(`${style.cyan(FRAMES$1[frame++ % FRAMES$1.length])} ${current}${timer}`)}`);
81
+ };
82
+ stream.write(HIDE_CURSOR$1);
83
+ draw();
84
+ const timer = setInterval(draw, 80);
85
+ try {
86
+ const result = await operation({ update: (next) => {
87
+ current = next;
88
+ draw();
89
+ } });
90
+ const message = typeof done === "function" ? done(result) : done ?? current;
91
+ stream.write(`${CLEAR_LINE$1}${symbol.ok} ${message} ${style.dim(formatDuration(now() - started))}\n`);
92
+ return result;
93
+ } catch (error) {
94
+ stream.write(`${CLEAR_LINE$1}${symbol.fail} ${current}\n`);
95
+ throw error;
96
+ } finally {
97
+ clearInterval(timer);
98
+ stream.write(SHOW_CURSOR$1);
99
+ }
100
+ },
101
+ success: (message) => {
102
+ stream.write(`${symbol.ok} ${message}\n`);
103
+ },
104
+ warn: (message) => {
105
+ stream.write(`${symbol.warn} ${message}\n`);
106
+ },
107
+ info: (message) => {
108
+ stream.write(`${symbol.info} ${message}\n`);
109
+ },
110
+ details(rows) {
111
+ const width = Math.max(...rows.map(([label]) => label.length));
112
+ for (const [label, value] of rows) stream.write(` ${style.dim(label.padEnd(width))} ${value}\n`);
113
+ },
114
+ blank: () => {
115
+ stream.write("\n");
116
+ },
117
+ live(text) {
118
+ if (!interactive) return {
119
+ update: () => {},
120
+ stop: () => {}
121
+ };
122
+ let stopped = false;
123
+ stream.write(HIDE_CURSOR$1);
124
+ stream.write(`${CLEAR_LINE$1}${fit(text)}`);
125
+ return {
126
+ update(next) {
127
+ if (!stopped) stream.write(`${CLEAR_LINE$1}${fit(next)}`);
128
+ },
129
+ stop(final) {
130
+ if (stopped) return;
131
+ stopped = true;
132
+ stream.write(`${CLEAR_LINE$1}${final ? `${final}\n` : ""}${SHOW_CURSOR$1}`);
133
+ }
134
+ };
135
+ }
136
+ };
137
+ }
138
+ /** Colors for sandbox statuses in tables and summaries. */
139
+ function statusStyle(style, status) {
140
+ switch (status) {
141
+ case "running": return style.green(status);
142
+ case "paused": return style.yellow(status);
143
+ case "failed": return style.red(status);
144
+ case "stopped":
145
+ case "exited":
146
+ case "deleted": return style.dim(status);
147
+ default: return style.cyan(status);
148
+ }
149
+ }
150
+ /** Prints an error as `✗ message`, with a hint for the common fixable cases (or, with `legacy`, the original `Error (status): message`). */
151
+ function printError(error, stream = process.stderr, commandName = "archil", { legacy = false } = {}) {
152
+ const status = typeof error === "object" && error !== null && "status" in error ? error.status : void 0;
153
+ const message = error instanceof Error ? error.message : String(error);
154
+ if (legacy) {
155
+ stream.write(`${error instanceof ArchilApiError ? `Error (${error.status}): ` : ""}${message}\n`);
156
+ return;
157
+ }
158
+ const style = styles(colorEnabled(stream));
159
+ stream.write(`${style.red("✗")} ${message}${status ? style.dim(` (HTTP ${status})`) : ""}\n`);
160
+ if (status === 401 || status === 403 || /Not signed in|Missing API key|Missing region/.test(message)) stream.write(` ${style.dim(`Sign in with ${style.bold("archil login")}, or set ARCHIL_API_KEY and ARCHIL_REGION.`)}\n`);
161
+ else if (/^error: (unknown|missing|too many|option)/.test(message)) stream.write(` ${style.dim(`See ${style.bold(`${commandName} --help`)}.`)}\n`);
162
+ }
163
+ //#endregion
5
164
  //#region src/cli/command.ts
6
165
  /** A usage problem with the command line itself (unknown option, missing argument). */
7
166
  var CliUsageError = class extends Error {};
@@ -127,6 +286,14 @@ var Command = class Command {
127
286
  this._action = handler;
128
287
  return this;
129
288
  }
289
+ /** This command's own options, for shell completion. */
290
+ optionList() {
291
+ return this._options;
292
+ }
293
+ /** This command's positional argument names, in order, for shell completion. */
294
+ argumentList() {
295
+ return this._arguments;
296
+ }
130
297
  opts() {
131
298
  return { ...this._values };
132
299
  }
@@ -484,13 +651,17 @@ async function validateCredentialAndResolveRegion(options, probe = async ({ apiK
484
651
  }
485
652
  //#endregion
486
653
  //#region src/cli/output.ts
654
+ const ANSI = /\x1b\[[0-9;?]*[A-Za-z]/g;
655
+ const visible = (text) => text.replace(ANSI, "").length;
656
+ const pad = (text, width) => text + " ".repeat(Math.max(0, width - visible(text)));
657
+ /** Renders a boxed table; cells may contain ANSI colors, which don't count toward widths. */
487
658
  function renderTable(rows, headers) {
488
659
  const all = headers ? [headers, ...rows] : rows;
489
660
  if (all.length === 0) return "";
490
661
  const columnCount = Math.max(...all.map((row) => row.length));
491
- const widths = Array.from({ length: columnCount }, (_, index) => Math.max(...all.map((row) => (row[index] ?? "").length)));
662
+ const widths = Array.from({ length: columnCount }, (_, index) => Math.max(...all.map((row) => visible(row[index] ?? ""))));
492
663
  const border = (left, middle, right) => left + widths.map((width) => "─".repeat(width + 2)).join(middle) + right;
493
- const line = (row) => "│ " + widths.map((width, index) => (row[index] ?? "").padEnd(width)).join(" │ ") + " │";
664
+ const line = (row) => "│ " + widths.map((width, index) => pad(row[index] ?? "", width)).join(" │ ") + " │";
494
665
  const output = [border("╭", "┬", "╮")];
495
666
  if (headers) output.push(line(headers), border("├", "┼", "┤"));
496
667
  output.push(...rows.map(line), border("╰", "┴", "╯"));
@@ -658,6 +829,7 @@ function addProfileCommands(program, validateCredential = validateCredentialAndR
658
829
  }
659
830
  //#endregion
660
831
  //#region src/cli/sandbox-options.ts
832
+ const DEFAULT_IMAGE = "ubuntu:26.04";
661
833
  function validateSandboxName(name) {
662
834
  if (name === void 0) return void 0;
663
835
  const value = name.trim();
@@ -687,13 +859,14 @@ function parseEnvironment(entries) {
687
859
  return environment;
688
860
  }
689
861
  function parseCreateSandboxOptions(name, options) {
862
+ const desktop = options.desktop ?? false;
690
863
  return {
691
864
  name: validateSandboxName(name),
692
- vcpuCount: optionalInteger(options.vcpuCount, "CPU count", 1, 32),
693
- memSizeMiB: optionalInteger(options.memSizeMib, "Memory", 256, 65536),
694
- baseImage: options.baseImage,
695
- maxTtlSeconds: optionalInteger(options.maxTtlSeconds, "Max TTL", 1, 2147483647),
696
- idleTtlSeconds: optionalInteger(options.idleTtlSeconds, "Idle TTL", 0, 86400),
865
+ vcpuCount: optionalInteger(options.vcpuCount, "CPU count", 1, 32) ?? (desktop ? 2 : void 0),
866
+ memSizeMiB: optionalInteger(options.memSizeMib, "Memory", 256, 65536) ?? (desktop ? 4096 : void 0),
867
+ baseImage: options.baseImage ?? (desktop ? "ghcr.io/archil-data/sandbox-desktop:latest" : DEFAULT_IMAGE),
868
+ maxTtlSeconds: optionalInteger(options.maxTtlSeconds, "Max TTL", 1, 2147483647) ?? (desktop ? 14400 : void 0),
869
+ idleTtlSeconds: optionalInteger(options.idleTtlSeconds, "Idle TTL", 0, 86400) ?? (desktop ? 0 : void 0),
697
870
  onTimeout: optionalTimeoutAction(options.onTimeout),
698
871
  maxConcurrentExecs: optionalInteger(options.maxConcurrentProcesses, "Max concurrent processes", 1, 1024),
699
872
  env: parseEnvironment(options.env)
@@ -706,4 +879,4 @@ function parseRunOptions(options) {
706
879
  };
707
880
  }
708
881
  //#endregion
709
- export { addGlobalOptions as a, resolveProgramCredentials as c, Command as d, validateSandboxName as i, renderTable as l, parseCreateSandboxOptions as n, addProfileCommands as o, parseRunOptions as r, isProfileCommand as s, optionalInteger as t, spinner as u };
882
+ export { printError as C, formatDuration as S, styles as T, writeProfileCredential as _, addGlobalOptions as a, colorEnabled as b, resolveProgramCredentials as c, saveProfiles as d, renderTable as f, resolveCliCredentials as g, readProfileCredential as h, validateSandboxName as i, deleteProfile as l, deleteProfileCredential as m, parseCreateSandboxOptions as n, addProfileCommands as o, validateCredentialAndResolveRegion as p, parseRunOptions as r, isProfileCommand as s, optionalInteger as t, loadProfiles as u, diskConfigDir as v, statusStyle as w, createUi as x, Command as y };
@@ -1,3 +1,4 @@
1
+ import { n as DESKTOP_MAX_TTL_SECONDS, r as DESKTOP_MEMORY_MIB, s as SandboxDesktop } from "./sandbox-desktop-CrvuoiGi.mjs";
1
2
  import { t as toSegments } from "./paths-Br9snUhy.mjs";
2
3
  import { create, fromBinary, toBinary } from "@bufbuild/protobuf";
3
4
  import { ClientFrameSchema, Exit_Status, Limits, ServerFrameSchema, WindowUpdateSchema } from "@archildata/api-types/process";
@@ -289,7 +290,7 @@ function deriveS3BaseUrl(controlBaseUrl) {
289
290
  }
290
291
  //#endregion
291
292
  //#region src/version.ts
292
- const VERSION = "1.14.0";
293
+ const VERSION = "1.15.0";
293
294
  const USER_AGENT = `archil-js/${VERSION}`;
294
295
  //#endregion
295
296
  //#region src/client.ts
@@ -2578,6 +2579,8 @@ var Sandbox = class Sandbox {
2578
2579
  /** @deprecated Use run() and attach(). Removed in the next version. */
2579
2580
  processes;
2580
2581
  files;
2582
+ /** The sandbox's Linux desktop, for sandboxes created with `desktop: true`. */
2583
+ desktop;
2581
2584
  /** @internal */
2582
2585
  _client;
2583
2586
  _processConnection;
@@ -2589,6 +2592,7 @@ var Sandbox = class Sandbox {
2589
2592
  this._processConnection = new ProcessConnection(() => this._connectionEndpoint());
2590
2593
  this.processes = new SandboxProcesses(this, () => this._processConnection.disconnect());
2591
2594
  this.files = new SandboxFiles(this);
2595
+ this.desktop = new SandboxDesktop(this);
2592
2596
  }
2593
2597
  /** @internal Overwrite this sandbox's fields in place from a fresh wire snapshot. */
2594
2598
  _apply(data) {
@@ -2946,6 +2950,14 @@ var Sandboxes = class {
2946
2950
  return new Sandbox(await unwrap(retryApiRequest(() => this._client.GET("/api/sandboxes/{sid}", { params: { path: { sid: id } } }), "transient")), this._client);
2947
2951
  }
2948
2952
  async create(request = {}, options = {}) {
2953
+ if (request.desktop) request = {
2954
+ ...request.imageId === void 0 && { baseImage: "ghcr.io/archil-data/sandbox-desktop:latest" },
2955
+ vcpuCount: 2,
2956
+ memSizeMiB: DESKTOP_MEMORY_MIB,
2957
+ idleTtlSeconds: 0,
2958
+ maxTtlSeconds: DESKTOP_MAX_TTL_SECONDS,
2959
+ ...Object.fromEntries(Object.entries(request).filter(([, value]) => value !== void 0))
2960
+ };
2949
2961
  const body = {
2950
2962
  name: request.name,
2951
2963
  vcpu_count: request.vcpuCount,