disk 1.12.1 → 1.14.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,28 @@
1
+ //#region src/paths.ts
2
+ /**
3
+ * Normalize a filesystem path to its segments, resolving "." and ".." (so a
4
+ * path means the same as in a shell, and ".." can't escape above the root) and
5
+ * optionally stripping a shell-style mount prefix (e.g. "/mnt" or "/mnt/archil")
6
+ * so a path copied from a `run_bash` command resolves the same way.
7
+ *
8
+ * toSegments("/a/b/../c") -> ["a", "c"]
9
+ * toSegments("/mnt/x", "/mnt") -> ["x"]
10
+ * toSegments("/../../etc/x") -> ["etc", "x"]
11
+ */
12
+ function toSegments(path, containerRoot) {
13
+ let p = (path ?? "").trim();
14
+ if (containerRoot) {
15
+ const root = containerRoot.replace(/\/+$/, "");
16
+ if (p === root) p = "/";
17
+ else if (p.startsWith(root + "/")) p = p.slice(root.length);
18
+ }
19
+ const resolved = [];
20
+ for (const seg of p.split("/")) {
21
+ if (seg === "" || seg === ".") continue;
22
+ if (seg === "..") resolved.pop();
23
+ else resolved.push(seg);
24
+ }
25
+ return resolved;
26
+ }
27
+ //#endregion
28
+ export { toSegments as t };
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
- import { k as ArchilApiError, p as Archil } from "./src-CsxpFPq3.mjs";
3
- import { a as addGlobalOptions, c as resolveProgramCredentials, d as Command, i as validateSandboxName, l as renderTable, n as parseCreateSandboxOptions, o as addProfileCommands, r as parseRunOptions, s as isProfileCommand, u as spinner } from "./sandbox-options-Df_pRGJW.mjs";
2
+ import { k as ArchilApiError, p as Archil } from "./src-DGB_iQTG.mjs";
3
+ import { a as addGlobalOptions, c as resolveProgramCredentials, d as Command, i as validateSandboxName, l as renderTable, n as parseCreateSandboxOptions, o as addProfileCommands, r as parseRunOptions, s as isProfileCommand, u as spinner } from "./sandbox-options-trHjQs_f.mjs";
4
4
  import { createRequire } from "node:module";
5
5
  import { createInterface } from "node:readline/promises";
6
6
  //#region src/cli/sandbox-output.ts
@@ -50,6 +50,7 @@ function formatSandbox(sandbox, format) {
50
50
  ["platform", sandbox.platform ?? ""],
51
51
  ["max TTL", `${sandbox.maxTtlSeconds} seconds`],
52
52
  ["idle TTL", sandbox.idleTtlSeconds === 0 ? "disabled" : `${sandbox.idleTtlSeconds} seconds`],
53
+ ["on timeout", sandbox.onTimeout],
53
54
  ["max concurrent processes", String(sandbox.maxConcurrentExecs)],
54
55
  ["created", date(sandbox.createdAt)],
55
56
  ["running", date(sandbox.runningAt)],
@@ -61,6 +62,41 @@ function formatSandbox(sandbox, format) {
61
62
  return renderTable(rows.filter(([, value]) => value !== ""));
62
63
  }
63
64
  //#endregion
65
+ //#region src/cli/write-output.ts
66
+ /**
67
+ * Writes `data`, then waits while the stream is full. A stream that closes or
68
+ * fails never emits `drain`, so either ends the wait with an error instead.
69
+ */
70
+ async function writeOutput(stream, data) {
71
+ if (stream.write(data) !== false || !stream.on || !stream.off) return;
72
+ const { on, off } = {
73
+ on: stream.on.bind(stream),
74
+ off: stream.off.bind(stream)
75
+ };
76
+ await new Promise((resolve, reject) => {
77
+ const drained = () => {
78
+ remove();
79
+ resolve();
80
+ };
81
+ const closed = () => {
82
+ remove();
83
+ reject(/* @__PURE__ */ new Error("Output stream closed"));
84
+ };
85
+ const failed = (error) => {
86
+ remove();
87
+ reject(error instanceof Error ? error : new Error(String(error)));
88
+ };
89
+ const remove = () => {
90
+ off("drain", drained);
91
+ off("close", closed);
92
+ off("error", failed);
93
+ };
94
+ on("drain", drained);
95
+ on("close", closed);
96
+ on("error", failed);
97
+ });
98
+ }
99
+ //#endregion
64
100
  //#region src/cli/sandbox-shell.ts
65
101
  async function runSandboxShell(options) {
66
102
  const stdin = options.stdin ?? process.stdin;
@@ -151,14 +187,7 @@ async function runSandboxShell(options) {
151
187
  cols: stdout.columns ?? 80,
152
188
  rows: stdout.rows ?? 24
153
189
  },
154
- collectOutput: false,
155
- onOutput: ({ data }) => {
156
- try {
157
- stdout.write(data);
158
- } catch (error) {
159
- fail(error);
160
- }
161
- }
190
+ collectOutput: false
162
191
  });
163
192
  stdin.setRawMode(true);
164
193
  terminalConfigured = true;
@@ -169,8 +198,11 @@ async function runSandboxShell(options) {
169
198
  stderr.write(`Archil shell process ${remote.id}; Ctrl+] exits\n`);
170
199
  stdin.on("data", onInput);
171
200
  stdin.resume();
201
+ const streaming = (async () => {
202
+ for await (const { data } of remote.output) await writeOutput(stdout, data);
203
+ })();
172
204
  result = await Promise.race([
173
- remote.wait(),
205
+ streaming.then(() => remote.wait()),
174
206
  termination,
175
207
  failure
176
208
  ]);
@@ -184,6 +216,7 @@ async function runSandboxShell(options) {
184
216
  stdin.pause();
185
217
  if (remote && !result && !terminationRequested) await remote.kill().catch(() => {});
186
218
  if (remote) await remote.disconnect().catch(() => {});
219
+ await options.sandbox.processes.disconnect();
187
220
  }
188
221
  }
189
222
  //#endregion
@@ -282,7 +315,7 @@ function createSandboxProgram(dependencies) {
282
315
  formatOption(program.command("get <id|name>").description("Show sandbox details")).action(async (target, options) => {
283
316
  output(formatSandbox(await resolveSandbox(requireService(), target), options.output));
284
317
  });
285
- waitOption(formatOption(program.command("create [name]").description("Create a sandbox"))).option("--vcpu-count <count>", "Virtual CPU count (1-32)").option("--mem-size-mib <mib>", "Memory in MiB (256-65536)").option("--base-image <image>", "Public OCI image", "ubuntu:26.04").option("--max-ttl-seconds <seconds>", "Maximum sandbox lifetime").option("--idle-ttl-seconds <seconds>", "Seconds without a process connection before pausing (0 disables)").option("--max-concurrent-processes <count>", "Maximum attached processes").option("--env <name=value>", "Set an environment variable (repeatable)", (value, previous) => [...previous, value], []).action(async (name, options) => {
318
+ waitOption(formatOption(program.command("create [name]").description("Create a sandbox"))).option("--vcpu-count <count>", "Virtual CPU count (1-32)").option("--mem-size-mib <mib>", "Memory in MiB (256-65536)").option("--base-image <image>", "Public OCI image", "ubuntu:26.04").option("--max-ttl-seconds <seconds>", "Maximum sandbox lifetime").option("--idle-ttl-seconds <seconds>", "Seconds without a process connection before pausing (0 disables)").option("--on-timeout <pause|delete>", "Pause (default) or delete the sandbox when a TTL runs out").option("--max-concurrent-processes <count>", "Maximum attached processes").option("--env <name=value>", "Set an environment variable (repeatable)", (value, previous) => [...previous, value], []).action(async (name, options) => {
286
319
  const sandbox = await withSpinner("Creating sandbox", options.wait, () => requireService().create(parseCreateSandboxOptions(name, options), { wait: options.wait }));
287
320
  output(formatSandbox(sandbox, options.output));
288
321
  });
@@ -410,11 +443,7 @@ Use -- before the command so its flags are not parsed as sandbox options.
410
443
  const shellCommand = command.map((argument) => argument === "" ? "''" : `'${argument.replaceAll("'", `'"'"'`)}'`).join(" ");
411
444
  remote = await sandbox.run(shellCommand, {
412
445
  ...runOptions,
413
- collectOutput: options.output === "json",
414
- onOutput: options.output === "json" ? void 0 : ({ stream, data }) => {
415
- if (stream === "stderr" && data.byteLength > 0) receivedStderr = true;
416
- return (stream === "stdout" ? stdout : stderr).write(data);
417
- }
446
+ collectOutput: options.output === "json"
418
447
  });
419
448
  try {
420
449
  await remote.closeStdin();
@@ -424,7 +453,13 @@ Use -- before the command so its flags are not parsed as sandbox options.
424
453
  signals.on("SIGINT", onSigint);
425
454
  signals.on("SIGTERM", onSigterm);
426
455
  signals.on("SIGHUP", onSighup);
427
- result = await Promise.race([remote.wait(), termination]);
456
+ const streaming = options.output === "json" ? Promise.resolve() : (async () => {
457
+ for await (const { stream, data } of remote.output) {
458
+ if (stream === "stderr" && data.length) receivedStderr = true;
459
+ await writeOutput(stream === "stdout" ? stdout : stderr, data);
460
+ }
461
+ })();
462
+ result = await Promise.race([streaming.then(() => remote.wait()), termination]);
428
463
  if (options.output === "json") output(JSON.stringify(result, null, 2));
429
464
  else if (result.status !== "completed" && !receivedStderr) {
430
465
  let diagnostic;
@@ -438,6 +473,7 @@ Use -- before the command so its flags are not parsed as sandbox options.
438
473
  removeSignalListeners();
439
474
  if (remote && !result && !terminationStarted) await remote.kill().catch(() => {});
440
475
  await remote?.disconnect().catch(() => {});
476
+ await sandbox.processes.disconnect();
441
477
  }
442
478
  });
443
479
  formatOption(program.command("shell <id|name>").description("Open an interactive shell in a running sandbox")).action(async (target, options) => {
@@ -1,4 +1,4 @@
1
- import { O as REGION_URLS, p as Archil } from "./src-CsxpFPq3.mjs";
1
+ import { O as REGION_URLS, p as Archil } from "./src-DGB_iQTG.mjs";
2
2
  import { chmod, mkdir, open, readFile, rename, rm, stat } from "node:fs/promises";
3
3
  import { dirname, join } from "node:path";
4
4
  import { homedir } from "node:os";
@@ -670,6 +670,10 @@ function optionalInteger(value, label, min, max) {
670
670
  if (!Number.isInteger(parsed) || parsed < min || parsed > max) throw new Error(`${label} must be an integer from ${min} to ${max}`);
671
671
  return parsed;
672
672
  }
673
+ function optionalTimeoutAction(value) {
674
+ if (value === void 0 || value === "pause" || value === "delete") return value;
675
+ throw new Error("On timeout must be 'pause' or 'delete'");
676
+ }
673
677
  function parseEnvironment(entries) {
674
678
  if (entries.length === 0) return void 0;
675
679
  const environment = {};
@@ -690,6 +694,7 @@ function parseCreateSandboxOptions(name, options) {
690
694
  baseImage: options.baseImage,
691
695
  maxTtlSeconds: optionalInteger(options.maxTtlSeconds, "Max TTL", 1, 2147483647),
692
696
  idleTtlSeconds: optionalInteger(options.idleTtlSeconds, "Idle TTL", 0, 86400),
697
+ onTimeout: optionalTimeoutAction(options.onTimeout),
693
698
  maxConcurrentExecs: optionalInteger(options.maxConcurrentProcesses, "Max concurrent processes", 1, 1024),
694
699
  env: parseEnvironment(options.env)
695
700
  };