disk 1.13.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.
package/dist/cli.mjs CHANGED
@@ -1,285 +1,16 @@
1
1
  #!/usr/bin/env node
2
- import { a as deleteApiKey, k as ArchilApiError, l as listApiKeys, n as createApiKey, r as createDisk, s as getDisk, t as configure, u as listDisks } from "./src-CRvOOCjY.mjs";
3
- import { a as addGlobalOptions, c as resolveProgramCredentials, d as Command, l as renderTable, o as addProfileCommands, s as isProfileCommand, t as optionalInteger } from "./sandbox-options-D99F52j0.mjs";
2
+ import { C as printError, a as addGlobalOptions, o as addProfileCommands, y as Command } from "./sandbox-options-AO9jKF4-.mjs";
3
+ import { n as rewriteDiskExecSugar, t as addDiskCommands } from "./disk-command-CvRVHqnG.mjs";
4
4
  import { createRequire } from "node:module";
5
5
  //#region bin/cli.ts
6
6
  const pkg = createRequire(import.meta.url)("../package.json");
7
- const program = new Command();
8
- program.name("disk").description("Manage Archil disks from the command line").version(pkg.version).hook("preAction", async (_thisCommand, actionCommand) => {
9
- if (isProfileCommand(actionCommand)) return;
10
- const resolved = await resolveProgramCredentials(program);
11
- configure({
12
- apiKey: resolved.apiKey,
13
- region: resolved.region,
14
- baseUrl: resolved.baseUrl
15
- });
16
- });
7
+ const program = new Command().name("disk").description("Manage Archil disks from the command line").version(pkg.version);
17
8
  addGlobalOptions(program);
18
9
  addProfileCommands(program);
19
- function fail(err) {
20
- if (err instanceof ArchilApiError) console.error(`Error (${err.status}): ${err.message}`);
21
- else console.error(err instanceof Error ? err.message : String(err));
10
+ addDiskCommands(program, program, { legacy: true });
11
+ program.parseAsync(rewriteDiskExecSugar(process.argv)).catch((err) => {
12
+ printError(err, process.stderr, "disk", { legacy: true });
22
13
  process.exit(1);
23
- }
24
- function isDiskId(s) {
25
- return /^(dsk-|fs-)[0-9a-fA-F]+$/.test(s);
26
- }
27
- async function resolveDisk(idOrName) {
28
- if (isDiskId(idOrName)) return getDisk(idOrName);
29
- const matches = await listDisks({ name: idOrName });
30
- if (matches.length === 0) throw new ArchilApiError(`No disk found with name '${idOrName}'`, 404);
31
- if (matches.length > 1) throw new ArchilApiError(`Multiple disks match name '${idOrName}' — pass a disk id (dsk-...) instead`, 400);
32
- return matches[0];
33
- }
34
- function formatBytes(n) {
35
- if (n === void 0 || n === null) return void 0;
36
- if (n < 1024) return `${n} B`;
37
- const units = [
38
- "KB",
39
- "MB",
40
- "GB",
41
- "TB",
42
- "PB"
43
- ];
44
- let v = n / 1024;
45
- let i = 0;
46
- while (v >= 1024 && i < units.length - 1) {
47
- v /= 1024;
48
- i++;
49
- }
50
- return `${v.toFixed(v >= 100 ? 0 : v >= 10 ? 1 : 2)} ${units[i]}`;
51
- }
52
- function section(title, body) {
53
- console.log("");
54
- console.log(title);
55
- console.log(body);
56
- }
57
- function printDisk(d) {
58
- console.log(`${d.organization}/${d.name} (${d.id})`);
59
- const visible = [
60
- ["status", d.status],
61
- ["provider", d.provider],
62
- ["region", d.region],
63
- ["created", d.createdAt],
64
- ["last accessed", d.lastAccessed],
65
- ["active data", formatBytes(d.activeDataBytes)],
66
- ["total data", formatBytes(d.totalDataBytes)],
67
- ["monthly usage", d.monthlyUsage]
68
- ].filter(([, v]) => v !== void 0 && v !== null && v !== "").map(([k, v]) => [k, String(v)]);
69
- console.log("");
70
- console.log(renderTable(visible));
71
- if (d.mounts && d.mounts.length > 0) section("Mounts", renderTable(d.mounts.map((m) => [
72
- m.type ?? "?",
73
- m.name ?? m.path ?? "",
74
- m.accessMode ?? ""
75
- ]), [
76
- "type",
77
- "location",
78
- "mode"
79
- ]));
80
- if (d.authorizedUsers && d.authorizedUsers.length > 0) section("Authorized users", renderTable(d.authorizedUsers.map((u) => {
81
- if (u.type === "token") return [
82
- "token",
83
- u.nickname ?? "(no name)",
84
- u.tokenSuffix ? `-${u.tokenSuffix}` : ""
85
- ];
86
- return [
87
- u.type ?? "?",
88
- u.identifier ?? u.principal ?? "",
89
- ""
90
- ];
91
- }), [
92
- "type",
93
- "name / identifier",
94
- "suffix"
95
- ]));
96
- if (d.connectedClients && d.connectedClients.length > 0) section("Connected clients", renderTable(d.connectedClients.map((c) => [
97
- c.id ?? "",
98
- c.ipAddress ?? "",
99
- c.connectedAt ?? ""
100
- ]), [
101
- "id",
102
- "ip",
103
- "connected at"
104
- ]));
105
- }
106
- program.command("list").description("List disks in the current region").option("--limit <n>", "Maximum number of disks to return", (v) => parseInt(v, 10)).option("-o, --output <format>", "Output format: table | json", "table").action(async (opts) => {
107
- try {
108
- const disks = await listDisks({ limit: opts.limit });
109
- if (opts.output === "json") {
110
- console.log(JSON.stringify(disks, null, 2));
111
- return;
112
- }
113
- if (disks.length === 0) {
114
- console.log("No disks found.");
115
- return;
116
- }
117
- const rows = disks.map((d) => [
118
- d.id,
119
- `${d.organization}/${d.name}`,
120
- d.status
121
- ]);
122
- console.log(renderTable(rows, [
123
- "id",
124
- "name",
125
- "status"
126
- ]));
127
- } catch (err) {
128
- fail(err);
129
- }
130
- });
131
- program.command("get <id|name>").description("Show details for a disk (accepts a disk id or name)").option("-o, --output <format>", "Output format: table | json", "table").action(async (idOrName, opts) => {
132
- try {
133
- const d = await resolveDisk(idOrName);
134
- if (opts.output === "json") console.log(JSON.stringify(d, null, 2));
135
- else printDisk(d);
136
- } catch (err) {
137
- fail(err);
138
- }
139
- });
140
- program.command("create <name>").description("Create a new disk").action(async (name) => {
141
- try {
142
- const result = await createDisk({ name });
143
- console.log(`Created disk ${result.disk.organization}/${result.disk.name}`);
144
- console.log(` id: ${result.disk.id}`);
145
- console.log(` status: ${result.disk.status}`);
146
- if (result.token) {
147
- console.log("");
148
- console.log("Disk token (save this — it cannot be retrieved again):");
149
- console.log(` ${result.token}`);
150
- if (result.tokenIdentifier) console.log(` identifier: ${result.tokenIdentifier}`);
151
- }
152
- } catch (err) {
153
- fail(err);
154
- }
155
- });
156
- program.command("delete <id|name>").description("Delete a disk (accepts a disk id or name)").action(async (idOrName) => {
157
- try {
158
- const d = await resolveDisk(idOrName);
159
- await d.delete();
160
- console.log(`Deleted ${d.organization}/${d.name} (${d.id})`);
161
- } catch (err) {
162
- fail(err);
163
- }
164
- });
165
- program.command("exec <id|name> <command...>").description("Run a command in a container with the disk mounted, return stdout/stderr/exit code (accepts a disk id or name)").action(async (idOrName, cmd) => {
166
- try {
167
- const result = await (await resolveDisk(idOrName)).exec(cmd.join(" "));
168
- if (result.stdout) process.stdout.write(result.stdout);
169
- if (result.stderr) process.stderr.write(result.stderr);
170
- process.exit(result.exitCode);
171
- } catch (err) {
172
- fail(err);
173
- }
174
- });
175
- program.command("grep <pattern> <target>").description("Constant-time parallel server-side grep across a disk. <target> is <id|name>[/<path>] — the path after the first '/' is the directory to search (defaults to the disk root). Accepts a disk id or name.").option("--no-recursive", "Search only the given directory, not its subdirectories (recursive is the default)").option("--max-duration <seconds>", "Wall-clock deadline for the whole search").option("--concurrency <n>", "Max parallel grep workers (clamped to fleet capacity)").option("--max-results <n>", "Stop once this many matches are collected").option("-i, --ignore-case", "Match case-insensitively").option("-U, --multiline", "Let matches span lines").option("-g, --glob <glob>", "Include files matching the glob, or exclude with a leading ! (repeatable)", (value, previous) => [...previous, value], []).option("-t, --type <type>", "Only search files of this type, e.g. py (repeatable)", (value, previous) => [...previous, value], []).option("-T, --type-not <type>", "Skip files of this type (repeatable)", (value, previous) => [...previous, value], []).option("-A, --after-context <n>", "Lines of context after each match (max 10)").option("-B, --before-context <n>", "Lines of context before each match (max 10)").option("-C, --context <n>", "Lines of context before and after each match (max 10)").option("-o, --output <format>", "Output format: text | json", "text").action(async (pattern, target, opts) => {
176
- try {
177
- const context = optionalInteger(opts.context, "Context", 0, 10);
178
- const contextBefore = optionalInteger(opts.beforeContext, "Before context", 0, 10) ?? context;
179
- const contextAfter = optionalInteger(opts.afterContext, "After context", 0, 10) ?? context;
180
- const maxDurationSeconds = optionalInteger(opts.maxDuration, "Max duration", 1, 30);
181
- const concurrency = optionalInteger(opts.concurrency, "Concurrency", 1, 100);
182
- const maxResults = optionalInteger(opts.maxResults, "Max results", 1, 1e4);
183
- const slash = target.indexOf("/");
184
- const idOrName = slash === -1 ? target : target.slice(0, slash);
185
- const directory = slash === -1 ? "" : target.slice(slash + 1);
186
- const res = await (await resolveDisk(idOrName)).grep({
187
- directory,
188
- pattern,
189
- recursive: opts.recursive !== false,
190
- maxDurationSeconds,
191
- concurrency,
192
- maxResults,
193
- ignoreCase: opts.ignoreCase,
194
- multiline: opts.multiline,
195
- globs: opts.glob,
196
- types: opts.type,
197
- typesNot: opts.typeNot,
198
- contextBefore,
199
- contextAfter
200
- });
201
- if (opts.output === "json") console.log(JSON.stringify(res, null, 2));
202
- else {
203
- if (res.groups) res.groups.forEach((g, i) => {
204
- if (i > 0) console.log("--");
205
- for (const l of g.lines) {
206
- const sep = l.match ? ":" : "-";
207
- console.log(`${g.file}${sep}${l.line}${sep}${l.text}`);
208
- }
209
- });
210
- else for (const m of res.matches) m.text.split("\n").forEach((text, k) => console.log(`${m.file}:${m.line + k}:${text}`));
211
- console.error(`${res.matches.length} match${res.matches.length === 1 ? "" : "es"} · ${res.filesScanned} files scanned · ${res.containersDispatched} containers · ${res.durationMs}ms · ${res.stoppedReason}`);
212
- if (res.stoppedReason !== "completed") console.error(`warning: search did not complete (${res.stoppedReason}); results may be partial`);
213
- }
214
- process.exit(res.matches.length > 0 ? 0 : 1);
215
- } catch (err) {
216
- fail(err);
217
- }
218
- });
219
- const keys = program.command("api-keys").description("Manage Archil API keys (account-level credentials)");
220
- keys.command("list").description("List API keys").option("--limit <n>", "Maximum number of keys to return", (v) => parseInt(v, 10)).action(async (opts) => {
221
- try {
222
- const ks = await listApiKeys({ limit: opts.limit });
223
- if (ks.length === 0) {
224
- console.log("No API keys found.");
225
- return;
226
- }
227
- for (const k of ks) console.log(`${k.id ?? "-"}\t${k.name ?? "-"}\t${k.createdAt ?? ""}`);
228
- } catch (err) {
229
- fail(err);
230
- }
231
- });
232
- keys.command("create <name>").description("Create a new API key (the key value is shown once)").option("--description <description>", "Optional description").action(async (name, opts) => {
233
- try {
234
- const k = await createApiKey({
235
- name,
236
- description: opts.description
237
- });
238
- console.log(`Created API key ${name} (${k.id ?? "?"})`);
239
- if (k.token) {
240
- console.log("");
241
- console.log("API key value (save this — it cannot be retrieved again):");
242
- console.log(` ${k.token}`);
243
- }
244
- } catch (err) {
245
- fail(err);
246
- }
247
- });
248
- keys.command("delete <id>").description("Delete an API key").action(async (id) => {
249
- try {
250
- await deleteApiKey(id);
251
- console.log(`Deleted API key ${id}`);
252
- } catch (err) {
253
- fail(err);
254
- }
255
14
  });
256
- function rewriteSugar(argv) {
257
- const known = /* @__PURE__ */ new Set([
258
- "list",
259
- "get",
260
- "create",
261
- "delete",
262
- "exec",
263
- "grep",
264
- "api-keys",
265
- "profile",
266
- "sandboxes",
267
- "help",
268
- "--help",
269
- "-h",
270
- "--version",
271
- "-V"
272
- ]);
273
- const head = argv[2];
274
- const next = argv[3];
275
- if (head && next === "exec" && !known.has(head) && !head.startsWith("-")) return [
276
- ...argv.slice(0, 2),
277
- "exec",
278
- head,
279
- ...argv.slice(4)
280
- ];
281
- return argv;
282
- }
283
- program.parseAsync(rewriteSugar(process.argv)).catch(fail);
284
15
  //#endregion
285
16
  export {};
@@ -0,0 +1,285 @@
1
+ import { a as deleteApiKey, k as ArchilApiError, l as listApiKeys, n as createApiKey, r as createDisk, s as getDisk, t as configure, u as listDisks } from "./src-BFPiWUCL.mjs";
2
+ import { C as printError, c as resolveProgramCredentials, f as renderTable, s as isProfileCommand, t as optionalInteger, x as createUi } from "./sandbox-options-AO9jKF4-.mjs";
3
+ //#region src/cli/disk-command.ts
4
+ const DISK_COMMANDS = [
5
+ "list",
6
+ "get",
7
+ "create",
8
+ "delete",
9
+ "exec",
10
+ "grep",
11
+ "api-keys",
12
+ "profile",
13
+ "help"
14
+ ];
15
+ /**
16
+ * Adds the disk commands to `command`. Credentials come from the global
17
+ * options on `credentialsFrom`, which is `command` itself for the standalone
18
+ * `disk` CLI and the root program when nested as `archil disk`.
19
+ */
20
+ function addDiskCommands(command, credentialsFrom, { legacy = false } = {}) {
21
+ const ui = createUi(process.stderr);
22
+ command.hook("preAction", async (_thisCommand, actionCommand) => {
23
+ if (isProfileCommand(actionCommand)) return;
24
+ const resolved = await resolveProgramCredentials(credentialsFrom);
25
+ configure({
26
+ apiKey: resolved.apiKey,
27
+ region: resolved.region,
28
+ baseUrl: resolved.baseUrl
29
+ });
30
+ });
31
+ function fail(err) {
32
+ printError(err, process.stderr, legacy ? "disk" : "archil", { legacy });
33
+ process.exit(1);
34
+ }
35
+ function isDiskId(s) {
36
+ return /^(dsk-|fs-)[0-9a-fA-F]+$/.test(s);
37
+ }
38
+ async function resolveDisk(idOrName) {
39
+ if (isDiskId(idOrName)) return getDisk(idOrName);
40
+ const matches = await listDisks({ name: idOrName });
41
+ if (matches.length === 0) throw new ArchilApiError(`No disk found with name '${idOrName}'`, 404);
42
+ if (matches.length > 1) throw new ArchilApiError(`Multiple disks match name '${idOrName}' — pass a disk id (dsk-...) instead`, 400);
43
+ return matches[0];
44
+ }
45
+ function formatBytes(n) {
46
+ if (n === void 0 || n === null) return void 0;
47
+ if (n < 1024) return `${n} B`;
48
+ const units = [
49
+ "KB",
50
+ "MB",
51
+ "GB",
52
+ "TB",
53
+ "PB"
54
+ ];
55
+ let v = n / 1024;
56
+ let i = 0;
57
+ while (v >= 1024 && i < units.length - 1) {
58
+ v /= 1024;
59
+ i++;
60
+ }
61
+ return `${v.toFixed(v >= 100 ? 0 : v >= 10 ? 1 : 2)} ${units[i]}`;
62
+ }
63
+ function section(title, body) {
64
+ console.log("");
65
+ console.log(title);
66
+ console.log(body);
67
+ }
68
+ function printDisk(d) {
69
+ console.log(`${d.organization}/${d.name} (${d.id})`);
70
+ const visible = [
71
+ ["status", d.status],
72
+ ["provider", d.provider],
73
+ ["region", d.region],
74
+ ["created", d.createdAt],
75
+ ["last accessed", d.lastAccessed],
76
+ ["active data", formatBytes(d.activeDataBytes)],
77
+ ["total data", formatBytes(d.totalDataBytes)],
78
+ ["monthly usage", d.monthlyUsage]
79
+ ].filter(([, v]) => v !== void 0 && v !== null && v !== "").map(([k, v]) => [k, String(v)]);
80
+ console.log("");
81
+ console.log(renderTable(visible));
82
+ if (d.mounts && d.mounts.length > 0) section("Mounts", renderTable(d.mounts.map((m) => [
83
+ m.type ?? "?",
84
+ m.name ?? m.path ?? "",
85
+ m.accessMode ?? ""
86
+ ]), [
87
+ "type",
88
+ "location",
89
+ "mode"
90
+ ]));
91
+ if (d.authorizedUsers && d.authorizedUsers.length > 0) section("Authorized users", renderTable(d.authorizedUsers.map((u) => {
92
+ if (u.type === "token") return [
93
+ "token",
94
+ u.nickname ?? "(no name)",
95
+ u.tokenSuffix ? `-${u.tokenSuffix}` : ""
96
+ ];
97
+ return [
98
+ u.type ?? "?",
99
+ u.identifier ?? u.principal ?? "",
100
+ ""
101
+ ];
102
+ }), [
103
+ "type",
104
+ "name / identifier",
105
+ "suffix"
106
+ ]));
107
+ if (d.connectedClients && d.connectedClients.length > 0) section("Connected clients", renderTable(d.connectedClients.map((c) => [
108
+ c.id ?? "",
109
+ c.ipAddress ?? "",
110
+ c.connectedAt ?? ""
111
+ ]), [
112
+ "id",
113
+ "ip",
114
+ "connected at"
115
+ ]));
116
+ }
117
+ command.command("list").description("List disks in the current region").option("--limit <n>", "Maximum number of disks to return", (v) => parseInt(v, 10)).option("-o, --output <format>", "Output format: table | json", "table").action(async (opts) => {
118
+ try {
119
+ const disks = await ui.step("Loading disks", () => listDisks({ limit: opts.limit }), (found) => `Found ${found.length} disk${found.length === 1 ? "" : "s"}`);
120
+ if (opts.output === "json") {
121
+ console.log(JSON.stringify(disks, null, 2));
122
+ return;
123
+ }
124
+ if (disks.length === 0) {
125
+ console.log("No disks found.");
126
+ return;
127
+ }
128
+ const rows = disks.map((d) => [
129
+ d.id,
130
+ `${d.organization}/${d.name}`,
131
+ d.status
132
+ ]);
133
+ console.log(renderTable(rows, [
134
+ "id",
135
+ "name",
136
+ "status"
137
+ ]));
138
+ } catch (err) {
139
+ fail(err);
140
+ }
141
+ });
142
+ command.command("get <id|name>").description("Show details for a disk (accepts a disk id or name)").option("-o, --output <format>", "Output format: table | json", "table").action(async (idOrName, opts) => {
143
+ try {
144
+ const d = await ui.step(`Loading ${idOrName}`, () => resolveDisk(idOrName), (disk) => `Loaded ${disk.name}`);
145
+ if (opts.output === "json") console.log(JSON.stringify(d, null, 2));
146
+ else printDisk(d);
147
+ } catch (err) {
148
+ fail(err);
149
+ }
150
+ });
151
+ command.command("create <name>").description("Create a new disk").action(async (name) => {
152
+ try {
153
+ const result = await ui.step(`Creating disk ${name}`, () => createDisk({ name }), `Created disk ${ui.style.bold(name)}`);
154
+ console.log(`Created disk ${result.disk.organization}/${result.disk.name}`);
155
+ console.log(` id: ${result.disk.id}`);
156
+ console.log(` status: ${result.disk.status}`);
157
+ if (result.token) {
158
+ console.log("");
159
+ console.log("Disk token (save this — it cannot be retrieved again):");
160
+ console.log(` ${result.token}`);
161
+ if (result.tokenIdentifier) console.log(` identifier: ${result.tokenIdentifier}`);
162
+ }
163
+ } catch (err) {
164
+ fail(err);
165
+ }
166
+ });
167
+ command.command("delete <id|name>").description("Delete a disk (accepts a disk id or name)").action(async (idOrName) => {
168
+ try {
169
+ const d = await resolveDisk(idOrName);
170
+ await ui.step(`Deleting ${d.name}`, () => d.delete(), `Deleted ${ui.style.bold(d.name)}`);
171
+ console.log(`Deleted ${d.organization}/${d.name} (${d.id})`);
172
+ } catch (err) {
173
+ fail(err);
174
+ }
175
+ });
176
+ command.command("exec <id|name> <command...>").description("Run a command in a container with the disk mounted, return stdout/stderr/exit code (accepts a disk id or name)").action(async (idOrName, cmd) => {
177
+ try {
178
+ const d = await resolveDisk(idOrName);
179
+ const result = await ui.step(`Running in ${d.name}`, () => d.exec(cmd.join(" ")), (ran) => `Ran in ${d.name} (exit ${ran.exitCode})`);
180
+ if (result.stdout) process.stdout.write(result.stdout);
181
+ if (result.stderr) process.stderr.write(result.stderr);
182
+ process.exit(result.exitCode);
183
+ } catch (err) {
184
+ fail(err);
185
+ }
186
+ });
187
+ command.command("grep <pattern> <target>").description("Constant-time parallel server-side grep across a disk. <target> is <id|name>[/<path>] — the path after the first '/' is the directory to search (defaults to the disk root). Accepts a disk id or name.").option("--no-recursive", "Search only the given directory, not its subdirectories (recursive is the default)").option("--max-duration <seconds>", "Wall-clock deadline for the whole search").option("--concurrency <n>", "Max parallel grep workers (clamped to fleet capacity)").option("--max-results <n>", "Stop once this many matches are collected").option("-i, --ignore-case", "Match case-insensitively").option("-U, --multiline", "Let matches span lines").option("-g, --glob <glob>", "Include files matching the glob, or exclude with a leading ! (repeatable)", (value, previous) => [...previous, value], []).option("-t, --type <type>", "Only search files of this type, e.g. py (repeatable)", (value, previous) => [...previous, value], []).option("-T, --type-not <type>", "Skip files of this type (repeatable)", (value, previous) => [...previous, value], []).option("-A, --after-context <n>", "Lines of context after each match (max 10)").option("-B, --before-context <n>", "Lines of context before each match (max 10)").option("-C, --context <n>", "Lines of context before and after each match (max 10)").option("-o, --output <format>", "Output format: text | json", "text").action(async (pattern, target, opts) => {
188
+ try {
189
+ const context = optionalInteger(opts.context, "Context", 0, 10);
190
+ const contextBefore = optionalInteger(opts.beforeContext, "Before context", 0, 10) ?? context;
191
+ const contextAfter = optionalInteger(opts.afterContext, "After context", 0, 10) ?? context;
192
+ const maxDurationSeconds = optionalInteger(opts.maxDuration, "Max duration", 1, 30);
193
+ const concurrency = optionalInteger(opts.concurrency, "Concurrency", 1, 100);
194
+ const maxResults = optionalInteger(opts.maxResults, "Max results", 1, 1e4);
195
+ const slash = target.indexOf("/");
196
+ const idOrName = slash === -1 ? target : target.slice(0, slash);
197
+ const directory = slash === -1 ? "" : target.slice(slash + 1);
198
+ const res = await (await resolveDisk(idOrName)).grep({
199
+ directory,
200
+ pattern,
201
+ recursive: opts.recursive !== false,
202
+ maxDurationSeconds,
203
+ concurrency,
204
+ maxResults,
205
+ ignoreCase: opts.ignoreCase,
206
+ multiline: opts.multiline,
207
+ globs: opts.glob,
208
+ types: opts.type,
209
+ typesNot: opts.typeNot,
210
+ contextBefore,
211
+ contextAfter
212
+ });
213
+ if (opts.output === "json") console.log(JSON.stringify(res, null, 2));
214
+ else {
215
+ if (res.groups) res.groups.forEach((g, i) => {
216
+ if (i > 0) console.log("--");
217
+ for (const l of g.lines) {
218
+ const sep = l.match ? ":" : "-";
219
+ console.log(`${g.file}${sep}${l.line}${sep}${l.text}`);
220
+ }
221
+ });
222
+ else for (const m of res.matches) m.text.split("\n").forEach((text, k) => console.log(`${m.file}:${m.line + k}:${text}`));
223
+ console.error(`${res.matches.length} match${res.matches.length === 1 ? "" : "es"} · ${res.filesScanned} files scanned · ${res.containersDispatched} containers · ${res.durationMs}ms · ${res.stoppedReason}`);
224
+ if (res.stoppedReason !== "completed") console.error(`warning: search did not complete (${res.stoppedReason}); results may be partial`);
225
+ }
226
+ process.exit(res.matches.length > 0 ? 0 : 1);
227
+ } catch (err) {
228
+ fail(err);
229
+ }
230
+ });
231
+ const keys = command.command("api-keys").description("Manage Archil API keys (account-level credentials)");
232
+ keys.command("list").description("List API keys").option("--limit <n>", "Maximum number of keys to return", (v) => parseInt(v, 10)).action(async (opts) => {
233
+ try {
234
+ const ks = await listApiKeys({ limit: opts.limit });
235
+ if (ks.length === 0) {
236
+ console.log("No API keys found.");
237
+ return;
238
+ }
239
+ for (const k of ks) console.log(`${k.id ?? "-"}\t${k.name ?? "-"}\t${k.createdAt ?? ""}`);
240
+ } catch (err) {
241
+ fail(err);
242
+ }
243
+ });
244
+ keys.command("create <name>").description("Create a new API key (the key value is shown once)").option("--description <description>", "Optional description").action(async (name, opts) => {
245
+ try {
246
+ const k = await createApiKey({
247
+ name,
248
+ description: opts.description
249
+ });
250
+ console.log(`Created API key ${name} (${k.id ?? "?"})`);
251
+ if (k.token) {
252
+ console.log("");
253
+ console.log("API key value (save this — it cannot be retrieved again):");
254
+ console.log(` ${k.token}`);
255
+ }
256
+ } catch (err) {
257
+ fail(err);
258
+ }
259
+ });
260
+ keys.command("delete <id>").description("Delete an API key").action(async (id) => {
261
+ try {
262
+ await deleteApiKey(id);
263
+ console.log(`Deleted API key ${id}`);
264
+ } catch (err) {
265
+ fail(err);
266
+ }
267
+ });
268
+ }
269
+ /**
270
+ * Rewrites the `<id> exec <cmd...>` sugar into `exec <id> <cmd...>`. `start` is
271
+ * the index in `argv` of the first argument after the disk command itself.
272
+ */
273
+ function rewriteDiskExecSugar(argv, start = 2) {
274
+ const head = argv[start];
275
+ const next = argv[start + 1];
276
+ if (head && next === "exec" && !DISK_COMMANDS.includes(head) && !head.startsWith("-")) return [
277
+ ...argv.slice(0, start),
278
+ "exec",
279
+ head,
280
+ ...argv.slice(start + 2)
281
+ ];
282
+ return argv;
283
+ }
284
+ //#endregion
285
+ export { rewriteDiskExecSugar as n, addDiskCommands as t };
package/dist/index.cjs CHANGED
@@ -1,4 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_sandbox_desktop = require("./sandbox-desktop-DBs8jhKW.cjs");
2
3
  const require_paths = require("./paths-1c4QqbOB.cjs");
3
4
  let _bufbuild_protobuf = require("@bufbuild/protobuf");
4
5
  let _archildata_api_types_process = require("@archildata/api-types/process");
@@ -290,7 +291,7 @@ function deriveS3BaseUrl(controlBaseUrl) {
290
291
  }
291
292
  //#endregion
292
293
  //#region src/version.ts
293
- const VERSION = "1.13.0";
294
+ const VERSION = "1.15.0";
294
295
  const USER_AGENT = `archil-js/${VERSION}`;
295
296
  //#endregion
296
297
  //#region src/client.ts
@@ -1567,6 +1568,8 @@ function imageFromWire(data) {
1567
1568
  digest: data.digest,
1568
1569
  canonicalSource: data.canonical_source,
1569
1570
  failureReason: data.failure_reason,
1571
+ vcpuCount: data.vcpu_count,
1572
+ memSizeMiB: data.mem_size_mib,
1570
1573
  createdAt: new Date(data.created_at),
1571
1574
  updatedAt: new Date(data.updated_at)
1572
1575
  };
@@ -1618,7 +1621,9 @@ var Images = class {
1618
1621
  async _request(request) {
1619
1622
  return imageFromWire(await unwrap(retryApiRequest(() => this._client.POST("/api/images", { body: {
1620
1623
  source: request.source,
1621
- registry_auth: request.registryAuth
1624
+ registry_auth: request.registryAuth,
1625
+ vcpu_count: request.vcpuCount,
1626
+ mem_size_mib: request.memSizeMiB
1622
1627
  } }), "transient")));
1623
1628
  }
1624
1629
  };
@@ -2575,6 +2580,8 @@ var Sandbox = class Sandbox {
2575
2580
  /** @deprecated Use run() and attach(). Removed in the next version. */
2576
2581
  processes;
2577
2582
  files;
2583
+ /** The sandbox's Linux desktop, for sandboxes created with `desktop: true`. */
2584
+ desktop;
2578
2585
  /** @internal */
2579
2586
  _client;
2580
2587
  _processConnection;
@@ -2586,6 +2593,7 @@ var Sandbox = class Sandbox {
2586
2593
  this._processConnection = new ProcessConnection(() => this._connectionEndpoint());
2587
2594
  this.processes = new SandboxProcesses(this, () => this._processConnection.disconnect());
2588
2595
  this.files = new SandboxFiles(this);
2596
+ this.desktop = new require_sandbox_desktop.SandboxDesktop(this);
2589
2597
  }
2590
2598
  /** @internal Overwrite this sandbox's fields in place from a fresh wire snapshot. */
2591
2599
  _apply(data) {
@@ -2943,6 +2951,14 @@ var Sandboxes = class {
2943
2951
  return new Sandbox(await unwrap(retryApiRequest(() => this._client.GET("/api/sandboxes/{sid}", { params: { path: { sid: id } } }), "transient")), this._client);
2944
2952
  }
2945
2953
  async create(request = {}, options = {}) {
2954
+ if (request.desktop) request = {
2955
+ ...request.imageId === void 0 && { baseImage: "ghcr.io/archil-data/sandbox-desktop:latest" },
2956
+ vcpuCount: 2,
2957
+ memSizeMiB: require_sandbox_desktop.DESKTOP_MEMORY_MIB,
2958
+ idleTtlSeconds: 0,
2959
+ maxTtlSeconds: require_sandbox_desktop.DESKTOP_MAX_TTL_SECONDS,
2960
+ ...Object.fromEntries(Object.entries(request).filter(([, value]) => value !== void 0))
2961
+ };
2946
2962
  const body = {
2947
2963
  name: request.name,
2948
2964
  vcpu_count: request.vcpuCount,
@@ -3460,12 +3476,19 @@ exports.Archil = Archil;
3460
3476
  exports.ArchilApiError = ArchilApiError;
3461
3477
  exports.ArchilError = ArchilError;
3462
3478
  exports.ArchilS3Error = ArchilS3Error;
3479
+ exports.DESKTOP_IMAGE = require_sandbox_desktop.DESKTOP_IMAGE;
3480
+ exports.DESKTOP_MAX_TTL_SECONDS = require_sandbox_desktop.DESKTOP_MAX_TTL_SECONDS;
3481
+ exports.DESKTOP_MEMORY_MIB = require_sandbox_desktop.DESKTOP_MEMORY_MIB;
3482
+ exports.DESKTOP_PORT = require_sandbox_desktop.DESKTOP_PORT;
3483
+ exports.DESKTOP_VCPUS = require_sandbox_desktop.DESKTOP_VCPUS;
3484
+ exports.DesktopNotInstalledError = require_sandbox_desktop.DesktopNotInstalledError;
3463
3485
  exports.Disk = Disk;
3464
3486
  exports.DiskMultipart = DiskMultipart;
3465
3487
  exports.Disks = Disks;
3466
3488
  exports.ImageBuildError = ImageBuildError;
3467
3489
  exports.Images = Images;
3468
3490
  exports.Sandbox = Sandbox;
3491
+ exports.SandboxDesktop = require_sandbox_desktop.SandboxDesktop;
3469
3492
  exports.SandboxFileTransferError = SandboxFileTransferError;
3470
3493
  exports.SandboxFiles = SandboxFiles;
3471
3494
  exports.SandboxPauseError = SandboxPauseError;
@@ -3481,6 +3504,7 @@ exports.createApiKey = createApiKey;
3481
3504
  exports.createDisk = createDisk;
3482
3505
  exports.createSandbox = createSandbox;
3483
3506
  exports.deleteApiKey = deleteApiKey;
3507
+ exports.desktopViewerPath = require_sandbox_desktop.desktopViewerPath;
3484
3508
  exports.effectiveUploadPartSize = effectiveUploadPartSize;
3485
3509
  exports.exec = exec;
3486
3510
  exports.getDisk = getDisk;