@kvbox/cli 0.5.27 → 0.5.29

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/kvbox.js CHANGED
@@ -149,7 +149,7 @@ async function spin(message, work, opts = {}) {
149
149
  }
150
150
 
151
151
  // src/program.ts
152
- import { Command as Command65 } from "commander";
152
+ import { Command as Command68 } from "commander";
153
153
 
154
154
  // ../shared/src/version.ts
155
155
  import { createRequire } from "module";
@@ -164,10 +164,10 @@ function versionOf(srcFileUrl, injected) {
164
164
  }
165
165
 
166
166
  // src/version.ts
167
- var VERSION = versionOf(import.meta.url, true ? "0.5.27" : void 0);
167
+ var VERSION = versionOf(import.meta.url, true ? "0.5.29" : void 0);
168
168
 
169
169
  // src/commands/vm/index.ts
170
- import { Command as Command26 } from "commander";
170
+ import { Command as Command29 } from "commander";
171
171
 
172
172
  // src/commands/vm/connect.ts
173
173
  import { spawnSync as spawnSync2 } from "child_process";
@@ -217,6 +217,16 @@ function paths(home = kvboxHome()) {
217
217
  /** Symlink to the current base image, assets/rootfs-<version>.ext4; boxes keep using the version they were made from. */
218
218
  rootfs: join(home, "assets", "rootfs.ext4"),
219
219
  baseImage: (version) => join(home, "assets", `rootfs-${version}.ext4`),
220
+ /**
221
+ * Every other image (#87), one dir each so nothing collides with the base's `rootfs-*.ext4`:
222
+ * assets/images/<image>/rootfs-<version>.ext4, and rootfs.ext4 there the symlink to its current one.
223
+ */
224
+ images: join(home, "assets", "images"),
225
+ image: (image) => ({
226
+ dir: join(home, "assets", "images", image),
227
+ rootfs: join(home, "assets", "images", image, "rootfs.ext4"),
228
+ version: (version) => join(home, "assets", "images", image, `rootfs-${version}.ext4`)
229
+ }),
220
230
  machines: join(home, "machines"),
221
231
  snapshots: join(home, "snapshots"),
222
232
  /** Boxes and snapshots are filed by owner: machines/<owner>/<name>. The owner is part of a box's identity. */
@@ -227,6 +237,8 @@ function paths(home = kvboxHome()) {
227
237
  return {
228
238
  dir,
229
239
  meta: join(dir, "meta.json"),
240
+ /** The box's own environment variables (#87), merged over its owner's at boot. Mode 600: values in the clear. */
241
+ env: join(dir, "env.json"),
230
242
  /** The box's writable layer, stacked on the read-only base image inside the guest. */
231
243
  overlay: join(dir, "overlay.ext4"),
232
244
  /**
@@ -274,6 +286,8 @@ function paths(home = kvboxHome()) {
274
286
  meta: join(dir, "meta.json"),
275
287
  vmstate: join(dir, "vmstate"),
276
288
  mem: join(dir, "mem"),
289
+ /** The box's own environment variables when it was taken (#87); a restore starts with them. */
290
+ env: join(dir, "env.json"),
277
291
  /** Copy of the box's overlay at the moment of the snapshot; the base image is referenced by version in meta.json. */
278
292
  overlay: join(dir, "overlay.ext4")
279
293
  };
@@ -431,6 +445,8 @@ var PortsRequest = z2.object({
431
445
  ports: z2.array(z2.object({ guestPort: z2.number().int().min(1).max(65535), proto: PortProtoSchema.optional() })).min(1).max(MAX_BOX_PORTS)
432
446
  });
433
447
  var BoxPortSchema = z2.number().int().min(1).max(65535);
448
+ var BoxLinkSchema = z2.object({ from: z2.string(), port: BoxPortSchema });
449
+ var LinkRequest = z2.object({ from: z2.string().min(1), fromOwner: z2.string().optional(), port: BoxPortSchema });
434
450
  var ClaimSubdomainRequest = z2.object({ name: z2.string(), port: BoxPortSchema });
435
451
  var SubdomainPortRequest = z2.object({ port: BoxPortSchema });
436
452
  var SubdomainRouteRequest = z2.object({ name: z2.string(), port: BoxPortSchema });
@@ -471,7 +487,9 @@ var MachineSchema = z2.object({
471
487
  diskUsedBytes: z2.number().int(),
472
488
  // what that sparse file really occupies on the host
473
489
  base: z2.string(),
474
- // base image version the box's overlay stacks on
490
+ // version of the image the box's overlay stacks on
491
+ /** The image (#87) when it is not the base one: `postgres`. `base` is then that image's version. */
492
+ image: z2.string().optional(),
475
493
  createdAt: z2.string(),
476
494
  source: z2.string(),
477
495
  // "base", "snapshot:<owner/name>" or "fork:<owner/name>" (#79)
@@ -494,7 +512,14 @@ var MachineSchema = z2.object({
494
512
  /** Seconds without network traffic before the host hibernates the box (#47). Absent: never. */
495
513
  autoHibernateSec: z2.number().int().positive().optional(),
496
514
  /** Volumes attached to the box (#52), in drive order; each is mounted at `mountPath` while the box runs. Absent: none. */
497
- volumes: z2.array(z2.object({ name: z2.string(), sizeGib: z2.number().int(), mountPath: z2.string() })).optional()
515
+ volumes: z2.array(z2.object({ name: z2.string(), sizeGib: z2.number().int(), mountPath: z2.string() })).optional(),
516
+ /** Boxes that may reach this one, each on one port (#98). Absent: none. */
517
+ links: z2.array(BoxLinkSchema).optional(),
518
+ /**
519
+ * Only in what `POST /machines` answers, for an image that declares one (#87): how to reach what it
520
+ * serves, e.g. `postgres://postgres:<password>@db.kvbox:5432/postgres`. Holds the box's variables.
521
+ */
522
+ connect: z2.string().optional()
498
523
  });
499
524
  var VolumeSchema = z2.object({
500
525
  /** The host's 6-hex volume id (#91): the ledger's key, so a name removed and made again is two volumes. */
@@ -531,6 +556,16 @@ var EnvVarSchema = z2.object({
531
556
  secret: z2.boolean(),
532
557
  updatedAt: z2.string()
533
558
  });
559
+ var BoxEnvSchema = z2.object({
560
+ box: z2.string(),
561
+ vars: z2.array(EnvVarSchema)
562
+ });
563
+ var BoxEnvChangeSchema = z2.object({
564
+ box: z2.string(),
565
+ name: z2.string(),
566
+ /** Whether the box is running now: the change waits for its next start. */
567
+ running: z2.boolean()
568
+ });
534
569
  var SetEnvRequest = z2.object({
535
570
  value: z2.string(),
536
571
  secret: z2.boolean().optional()
@@ -559,7 +594,16 @@ var CreateMachineRequest = z2.object({
559
594
  */
560
595
  sshKeys: z2.array(z2.string()).optional(),
561
596
  /** Seconds without network traffic before the box is hibernated (#47); 0: never. Absent: the host's default. */
562
- autoHibernateSec: z2.number().int().min(0).optional()
597
+ autoHibernateSec: z2.number().int().min(0).optional(),
598
+ /**
599
+ * Place the box on the host of this box (#98, `kvbox new --near`), so the two can be linked. Only the
600
+ * control plane reads it; a host has one place to put a box.
601
+ */
602
+ near: z2.string().optional(),
603
+ /** The image to boot (#87, `kvbox new --base postgres`). Absent: the base image. */
604
+ image: z2.string().optional(),
605
+ /** The box's own environment variables (#87, `kvbox new -e NAME=value`), over its owner's. */
606
+ env: z2.array(z2.object({ name: z2.string(), value: z2.string() })).optional()
563
607
  });
564
608
  var ForkMachineRequest = z2.object({
565
609
  name: z2.string().optional(),
@@ -594,7 +638,9 @@ var SnapshotSchema = z2.object({
594
638
  source: z2.string(),
595
639
  // the box it was taken from, as owner/name
596
640
  base: z2.string(),
597
- // base image version the overlay stacks on; a restore needs the same one
641
+ // version of the image the overlay stacks on; a restore needs the same one
642
+ /** As in MachineSchema: the image when it is not the base one (#87). */
643
+ image: z2.string().optional(),
598
644
  vcpu: z2.number().int(),
599
645
  memMib: z2.number().int(),
600
646
  sizeBytes: z2.number().int(),
@@ -603,7 +649,9 @@ var SnapshotSchema = z2.object({
603
649
  });
604
650
  var CreateSnapshotRequest = z2.object({
605
651
  box: z2.string(),
606
- name: z2.string()
652
+ name: z2.string(),
653
+ /** Retake a snapshot under a name that exists (#83): the old one goes only once the new one is complete. */
654
+ replace: z2.boolean().optional()
607
655
  });
608
656
  var DiskCapacitySchema = z2.object({
609
657
  totalGib: z2.number().int(),
@@ -619,7 +667,12 @@ var CapacitySchema = z2.object({
619
667
  reservedVcpu: z2.number().int(),
620
668
  running: z2.number().int(),
621
669
  /** Absent on a host from before volumes (#91): it cannot take one. */
622
- disk: DiskCapacitySchema.optional()
670
+ disk: DiskCapacitySchema.optional(),
671
+ /**
672
+ * The images a new box can be made from here (#87), with the version `new` uses; the base is `base`.
673
+ * Absent on a host from before images: it has only the base.
674
+ */
675
+ images: z2.array(z2.object({ name: z2.string(), version: z2.string() })).optional()
623
676
  });
624
677
  var RecoveryReportSchema = z2.object({
625
678
  at: z2.string(),
@@ -1137,6 +1190,14 @@ var ServerClient = class {
1137
1190
  removePorts(name, req) {
1138
1191
  return this.call("DELETE", `/machines/${encodeURIComponent(name)}/ports`, MachineSchema, req);
1139
1192
  }
1193
+ /** Let box `from` reach this box's `port` (#98); the answer is the box with every link into it. */
1194
+ addLink(name, req) {
1195
+ return this.call("POST", `/machines/${encodeURIComponent(name)}/links`, MachineSchema, req);
1196
+ }
1197
+ /** Take a link away (#98). */
1198
+ removeLink(name, req) {
1199
+ return this.call("DELETE", `/machines/${encodeURIComponent(name)}/links`, MachineSchema, req);
1200
+ }
1140
1201
  /** HTTPS names (#31), the control plane's only: the box's subdomain, claimed for its default port. */
1141
1202
  claimSubdomain(name, req) {
1142
1203
  return this.call("PUT", `/machines/${encodeURIComponent(name)}/subdomain`, SubdomainSchema, req);
@@ -1205,8 +1266,9 @@ var ServerClient = class {
1205
1266
  return this.call("DELETE", `/snapshots/${encodeURIComponent(name)}`, z3.undefined());
1206
1267
  }
1207
1268
  // ---- environment variables (#88), a control plane only: the caller's slug, or `--org`'s ----
1208
- listEnv() {
1209
- return this.call("GET", "/env", z3.array(EnvVarSchema));
1269
+ /** `org`: that org's list instead of `--org`'s (or the caller's own). */
1270
+ listEnv(org) {
1271
+ return this.call("GET", "/env", z3.array(EnvVarSchema), void 0, org);
1210
1272
  }
1211
1273
  setEnv(name, req) {
1212
1274
  return this.call("PUT", `/env/${encodeURIComponent(name)}`, EnvChangeSchema, req);
@@ -1214,6 +1276,16 @@ var ServerClient = class {
1214
1276
  removeEnv(name) {
1215
1277
  return this.call("DELETE", `/env/${encodeURIComponent(name)}`, EnvChangeSchema);
1216
1278
  }
1279
+ // ---- a box's own variables (#87), kept on its host, over its owner's at its next start ----
1280
+ boxEnv(name) {
1281
+ return this.call("GET", `/machines/${encodeURIComponent(name)}/env`, BoxEnvSchema);
1282
+ }
1283
+ setBoxEnv(name, variable, req) {
1284
+ return this.call("POST", `/machines/${encodeURIComponent(name)}/env/${encodeURIComponent(variable)}`, BoxEnvChangeSchema, req);
1285
+ }
1286
+ removeBoxEnv(name, variable) {
1287
+ return this.call("DELETE", `/machines/${encodeURIComponent(name)}/env/${encodeURIComponent(variable)}`, BoxEnvChangeSchema);
1288
+ }
1217
1289
  // ---- volumes (#52) ----
1218
1290
  listVolumes(opts = {}) {
1219
1291
  return this.call("GET", `/volumes${allQuery(opts)}`, z3.array(VolumeSchema), void 0, opts.org);
@@ -1625,19 +1697,49 @@ async function pickVolume(client, keep, none) {
1625
1697
 
1626
1698
  // src/commands/vm/new.ts
1627
1699
  import { Command, Option } from "commander";
1628
- var newCommand = new Command("new").description("boot a new box from the base image or a snapshot").argument("[name]", "box name (box1, box2, \u2026 when omitted)").addOption(new Option("-s, --size <size>", "box size (default: server config, s)").choices(SIZE_NAMES)).option("-f, --from <snapshot>", "start from a snapshot instead of the base image").option("--auto-hibernate <duration>", "hibernate the box after this long without network traffic (30m, 4h, 1d; off: never; default: server config, off)").option("--force", "skip the capacity guard").option("--json", "print the box as JSON").action(async (name, opts, cmd) => {
1700
+
1701
+ // ../shared/src/env.ts
1702
+ var ENV_NAME_RE = /^[A-Za-z_][A-Za-z0-9_]*$/;
1703
+ var ENV_RESERVED = ["PATH", "HOME", "USER", "SHELL"];
1704
+ var ENV_MAX_VALUE_BYTES = 4096;
1705
+ function envNameProblem(name) {
1706
+ if (!ENV_NAME_RE.test(name)) return `${JSON.stringify(name)} is not a variable name: letters, digits and _, not starting with a digit`;
1707
+ if (ENV_RESERVED.includes(name)) return `${name} is the box's own and cannot be set`;
1708
+ if (name.startsWith("KVBOX_")) return `${name}: names starting with KVBOX_ are kept for kvbox`;
1709
+ return null;
1710
+ }
1711
+ function envValueProblem(value) {
1712
+ if (/[\n\r\0]/.test(value)) return "a value is one line: no line breaks (base64 a multi-line value such as a key file)";
1713
+ if (Buffer.byteLength(value, "utf8") > ENV_MAX_VALUE_BYTES) return `a value is at most ${ENV_MAX_VALUE_BYTES / 1024} KB`;
1714
+ return null;
1715
+ }
1716
+
1717
+ // src/commands/vm/new.ts
1718
+ var newCommand = new Command("new").description("boot a new box from an image (the base one, or e.g. postgres) or a snapshot").argument("[name]", "box name (box1, box2, \u2026 when omitted)").addOption(new Option("-s, --size <size>", "box size (default: server config, s)").choices(SIZE_NAMES)).option("-b, --base <image>", "the image to boot: base (default) or one the host has, e.g. postgres").option("-e, --env <NAME=value>", "a variable of the box's own, over yours (repeatable; change later with kvbox env set --box)", collect, []).option("-f, --from <snapshot>", "start from a snapshot instead of an image").option("--near <box>", "put it on the same host as this box, so the two can be linked (kvbox vm link)").option("--auto-hibernate <duration>", "hibernate the box after this long without network traffic (30m, 4h, 1d; off: never; default: server config, off)").option("--force", "skip the capacity guard").option("--json", "print the box as JSON").action(async (name, opts, cmd) => {
1629
1719
  const autoHibernateSec = opts.autoHibernate === void 0 ? void 0 : parseIdleTimeout(opts.autoHibernate);
1720
+ const env = parseEnvFlags(opts.env);
1630
1721
  const client = await clientFor(cmd.optsWithGlobals());
1631
1722
  try {
1632
- const what = opts.from !== void 0 ? `restoring ${name ?? "a new box"} from snapshot ${opts.from}\u2026` : `booting ${name ?? "a new box"}\u2026`;
1723
+ const what = opts.from !== void 0 ? `restoring ${name ?? "a new box"} from snapshot ${opts.from}\u2026` : `booting ${name ?? "a new box"}${opts.base !== void 0 && opts.base !== "base" ? ` from image ${opts.base}` : ""}\u2026`;
1633
1724
  const box = await spin(what, client.createMachine({
1634
1725
  ...name !== void 0 ? { name } : {},
1635
1726
  ...opts.size !== void 0 ? { size: opts.size } : {},
1636
1727
  ...opts.from !== void 0 ? { from: opts.from } : {},
1728
+ ...opts.base !== void 0 ? { image: opts.base } : {},
1729
+ ...env.length > 0 ? { env } : {},
1730
+ ...opts.near !== void 0 ? { near: opts.near } : {},
1637
1731
  ...autoHibernateSec !== void 0 ? { autoHibernateSec } : {},
1638
1732
  ...opts.force ? { force: true } : {}
1639
1733
  }));
1640
1734
  if (autoHibernateSec && !box.autoHibernateSec) warn(`box ${name ?? box.name}: its host runs a kvbox-server too old for auto-hibernate; it will not hibernate on its own`);
1735
+ if (opts.base !== void 0 && opts.base !== "base" && box.image === void 0) {
1736
+ warn(`box ${box.name}: its host runs a kvbox-server too old for images; it booted the base image, not ${opts.base}`);
1737
+ }
1738
+ if (env.length > 0) {
1739
+ const kept = await keptVars(client, displayName(box, me(client)), env.map((v) => v.name));
1740
+ if (kept === "too old") warn(`box ${box.name}: its host runs a kvbox-server too old for a box's own variables; it has none of the -e ones`);
1741
+ else if (kept !== true) warn(`box ${box.name}: could not check its -e variables (${kept}); kvbox env ls --box ${displayName(box, me(client))} shows them`);
1742
+ }
1641
1743
  if (opts.json) {
1642
1744
  json(box);
1643
1745
  return;
@@ -1649,10 +1751,24 @@ var newCommand = new Command("new").description("boot a new box from the base im
1649
1751
  if (opts.from !== void 0) info(` connect with: kvbox connect ${displayName(box, user)} (already up: everything that ran in the snapshot is running)`);
1650
1752
  else info(` connect with: kvbox connect ${displayName(box, user)} (SSH is up a couple of seconds after boot)`);
1651
1753
  if (box.autoHibernateSec) info(` it ${autoHibernateText(box.autoHibernateSec)}`);
1754
+ if (box.connect !== void 0) {
1755
+ info(` reach it at: ${box.connect}`);
1756
+ info(` from another box once linked: kvbox vm link <box> ${displayName(box, user)} --port <port>`);
1757
+ info(` its variables: kvbox env ls --box ${displayName(box, user)}`);
1758
+ }
1652
1759
  } finally {
1653
1760
  await client.close();
1654
1761
  }
1655
1762
  });
1763
+ async function keptVars(client, box, names) {
1764
+ try {
1765
+ const have = new Set((await client.boxEnv(box)).vars.map((v) => v.name));
1766
+ return names.every((n) => have.has(n)) ? true : "too old";
1767
+ } catch (err) {
1768
+ const message = err.message;
1769
+ return /no route:|too old/.test(message) ? "too old" : message;
1770
+ }
1771
+ }
1656
1772
  function displayName(box, user) {
1657
1773
  return user !== void 0 && slugOf(box.owner) !== user ? `${slugOf(box.owner)}/${box.name}` : box.name;
1658
1774
  }
@@ -1663,6 +1779,22 @@ function describe(box, user) {
1663
1779
  function autoHibernateText(sec) {
1664
1780
  return sec ? `hibernates after ${duration(sec)} without network traffic (kvbox connect wakes it)` : "never hibernates on its own";
1665
1781
  }
1782
+ function collect(value, previous) {
1783
+ return [...previous, value];
1784
+ }
1785
+ function parseEnvFlags(flags) {
1786
+ const out = /* @__PURE__ */ new Map();
1787
+ for (const flag of flags) {
1788
+ const eq = flag.indexOf("=");
1789
+ if (eq <= 0) throw new KvboxError(`-e ${flag}: expected NAME=value`);
1790
+ const name = flag.slice(0, eq);
1791
+ const value = flag.slice(eq + 1);
1792
+ const problem = envNameProblem(name) ?? envValueProblem(value);
1793
+ if (problem !== null) throw new KvboxError(`-e ${name}: ${problem}`);
1794
+ out.set(name, value);
1795
+ }
1796
+ return [...out].map(([name, value]) => ({ name, value }));
1797
+ }
1666
1798
  var UNIT_SEC = { m: 60, h: 3600, d: 86400 };
1667
1799
  function parseIdleTimeout(text2) {
1668
1800
  const t = text2.trim().toLowerCase();
@@ -1732,7 +1864,7 @@ function remoteCommand(cmdArgs, env) {
1732
1864
  }
1733
1865
  var TIMEOUT_EXIT = 124;
1734
1866
  var SSH_FAILED2 = 255;
1735
- function collect(value, previous) {
1867
+ function collect2(value, previous) {
1736
1868
  return [...previous ?? [], value];
1737
1869
  }
1738
1870
  function positiveSeconds(value) {
@@ -1760,7 +1892,7 @@ async function runSsh(ssh, opts) {
1760
1892
  }).finally(() => clearTimeout(timer));
1761
1893
  return { status: status2, chunks, timedOut };
1762
1894
  }
1763
- var execCommand = new Command3("exec").description("run a command in a box and exit with its status (kvbox exec <name> -- <cmd>)").argument("<name>", "box name").argument("<cmd...>", "command, passed to the box's shell as one string (pipes, &&, cd work)").option("-e, --env <KEY=VALUE>", "set an environment variable for the command (repeatable)", collect).option("--timeout <seconds>", "kill the command after N seconds and exit 124", positiveSeconds).option("--tty", "allocate a pseudo-terminal (for interactive tools like htop)").option("--json", 'capture output and print {"output": "...", "exit_code": N}').option("--direct", "on the box's host: ssh to the box's private ip, not through the public address or relay").action(async (name, cmdArgs, opts, cmd) => {
1895
+ var execCommand = new Command3("exec").description("run a command in a box and exit with its status (kvbox exec <name> -- <cmd>)").argument("<name>", "box name").argument("<cmd...>", "command, passed to the box's shell as one string (pipes, &&, cd work)").option("-e, --env <KEY=VALUE>", "set an environment variable for the command (repeatable)", collect2).option("--timeout <seconds>", "kill the command after N seconds and exit 124", positiveSeconds).option("--tty", "allocate a pseudo-terminal (for interactive tools like htop)").option("--json", 'capture output and print {"output": "...", "exit_code": N}').option("--direct", "on the box's host: ssh to the box's private ip, not through the public address or relay").action(async (name, cmdArgs, opts, cmd) => {
1764
1896
  const client = await clientFor(cmd.optsWithGlobals());
1765
1897
  let ep;
1766
1898
  let cert;
@@ -1877,7 +2009,8 @@ function lsRows(boxes, cloud) {
1877
2009
  address: addressOf(b),
1878
2010
  size: b.status === "unknown" ? "-" : `${shape(b.vcpu, b.memMib, b.diskBytes)} ${color.dim(`(${gbShort(b.diskUsedBytes)} used)`)}`,
1879
2011
  created: age(b.createdAt),
1880
- base: b.status === "unknown" || b.base === "" ? "-" : b.base
2012
+ // An image other than the base one (#87) is named: `postgres v0.1.0`.
2013
+ base: b.status === "unknown" || b.base === "" ? "-" : b.image !== void 0 ? `${b.image} ${b.base}` : b.base
1881
2014
  }));
1882
2015
  }
1883
2016
 
@@ -1975,9 +2108,72 @@ var hibernateCommand = new Command7("hibernate").description("save a box's memor
1975
2108
  }
1976
2109
  });
1977
2110
 
1978
- // src/commands/vm/pause.ts
2111
+ // src/commands/vm/link.ts
1979
2112
  import { Command as Command8 } from "commander";
1980
- var pauseCommand = new Command8("pause").description("freeze a box in place (memory and processes kept, no CPU used; kvbox resume continues it instantly)").argument("<name>", "box name").option("--json", "print the box as JSON").action(async (name, opts, cmd) => {
2113
+ function parseLinkPort(text2) {
2114
+ const port = Number(text2);
2115
+ if (!Number.isInteger(port) || port < 1 || port > 65535) throw new KvboxError(`--port: expected a port from 1 to 65535, got "${text2}"`);
2116
+ return port;
2117
+ }
2118
+ var linkCommand = new Command8("link").description("let one box reach a port of another (private, same host; never public)").argument("<from>", "the box that connects").argument("<box>", "the box it may reach").requiredOption("-p, --port <port>", "the port in <box>").option("--json", "print the link as JSON").action(async (from, name, opts, cmd) => {
2119
+ const port = parseLinkPort(opts.port);
2120
+ const client = await clientFor(cmd.optsWithGlobals());
2121
+ try {
2122
+ const box = await spin(`linking ${from} to ${name}:${port}\u2026`, client.addLink(name, { from, port }));
2123
+ const user = me(client);
2124
+ const shown = displayName(box, user);
2125
+ if (opts.json) {
2126
+ json({ from, box: shown, port });
2127
+ return;
2128
+ }
2129
+ const fromName = from.slice(from.lastIndexOf("/") + 1);
2130
+ const link = box.links?.find((l) => l.port === port && l.from.slice(l.from.lastIndexOf("/") + 1) === fromName);
2131
+ const apart = link !== void 0 ? link.from.includes("/") : from.includes("/") && from.split("/")[0] !== slugOf(box.owner);
2132
+ const host = apart ? `${box.name}.${slugOf(box.owner)}.kvbox` : `${box.name}.kvbox`;
2133
+ info(`${color.green("\u2713")} box ${color.bold(from)} can reach ${color.bold(`${host}:${port}`)}`);
2134
+ if (box.status !== "running") info(` box ${shown} is ${box.status}: the link opens when it runs`);
2135
+ } finally {
2136
+ await client.close();
2137
+ }
2138
+ });
2139
+
2140
+ // src/commands/vm/links.ts
2141
+ import { Command as Command9 } from "commander";
2142
+ var linksCommand = new Command9("links").description("list the links between boxes (kvbox vm link)").argument("[box]", "only links into or out of this box").option("--json", "print as JSON").action(async (name, opts, cmd) => {
2143
+ const client = await clientFor(cmd.optsWithGlobals());
2144
+ try {
2145
+ const user = me(client);
2146
+ const machines = await client.listMachines();
2147
+ const picked = name === void 0 ? void 0 : pickRef(machines, name, user);
2148
+ const unlisted = name === void 0 || name.includes("/") || user === void 0 ? name : `${client.target.kind === "cloud" ? client.target.org ?? user : user}/${name}`;
2149
+ const wanted = picked === void 0 ? unlisted : `${slugOf(picked.owner)}/${picked.name}`;
2150
+ const rows2 = machines.flatMap((b) => {
2151
+ const box = displayName(b, user);
2152
+ const slug = box.includes("/") ? box.split("/")[0] : void 0;
2153
+ return (b.links ?? []).map((l) => {
2154
+ const source = l.from.includes("/") ? l.from : `${slugOf(b.owner)}/${l.from}`;
2155
+ const from = slug !== void 0 && !l.from.includes("/") ? `${slug}/${l.from}` : l.from;
2156
+ const row = { from: user !== void 0 && from.startsWith(`${user}/`) ? from.slice(user.length + 1) : from, box, port: l.port };
2157
+ return { row, ends: [`${slugOf(b.owner)}/${b.name}`, source] };
2158
+ });
2159
+ }).filter((r) => wanted === void 0 || r.ends.includes(wanted)).map((r) => r.row).sort((a, b) => a.box.localeCompare(b.box) || a.from.localeCompare(b.from) || a.port - b.port);
2160
+ if (opts.json) {
2161
+ json(rows2);
2162
+ return;
2163
+ }
2164
+ if (rows2.length === 0) {
2165
+ info(name === void 0 ? "no links (kvbox vm link <from> <box> --port <port>)" : `box ${name} has no links`);
2166
+ return;
2167
+ }
2168
+ table(rows2);
2169
+ } finally {
2170
+ await client.close();
2171
+ }
2172
+ });
2173
+
2174
+ // src/commands/vm/pause.ts
2175
+ import { Command as Command10 } from "commander";
2176
+ var pauseCommand = new Command10("pause").description("freeze a box in place (memory and processes kept, no CPU used; kvbox resume continues it instantly)").argument("<name>", "box name").option("--json", "print the box as JSON").action(async (name, opts, cmd) => {
1981
2177
  const client = await clientFor(cmd.optsWithGlobals());
1982
2178
  try {
1983
2179
  const box = await spin(`pausing ${name}\u2026`, client.pauseMachine(name));
@@ -1989,7 +2185,7 @@ var pauseCommand = new Command8("pause").description("freeze a box in place (mem
1989
2185
  });
1990
2186
 
1991
2187
  // src/commands/vm/proxy/claim.ts
1992
- import { Command as Command9 } from "commander";
2188
+ import { Command as Command11 } from "commander";
1993
2189
 
1994
2190
  // ../shared/src/names.ts
1995
2191
  import { createHmac } from "crypto";
@@ -2059,7 +2255,7 @@ function assertDomain(text2, proxyDomain) {
2059
2255
  }
2060
2256
 
2061
2257
  // src/commands/vm/proxy/claim.ts
2062
- var claimCommand = new Command9("claim").description("give a box its HTTPS address, https://<subdomain>.kvbox.app, serving one of its ports").argument("[box]", "box name (picked from a list when left out)").argument("[subdomain]", "3-63 lowercase letters, digits and '-'; must be free (asked for when left out)").option("--port <port>", "the box port the address serves (asked for when left out)").option("--json", "print the subdomain as JSON").action(async (nameArg, subArg, opts, cmd) => {
2258
+ var claimCommand = new Command11("claim").description("give a box its HTTPS address, https://<subdomain>.kvbox.app, serving one of its ports").argument("[box]", "box name (picked from a list when left out)").argument("[subdomain]", "3-63 lowercase letters, digits and '-'; must be free (asked for when left out)").option("--port <port>", "the box port the address serves (asked for when left out)").option("--json", "print the subdomain as JSON").action(async (nameArg, subArg, opts, cmd) => {
2063
2259
  if (nameArg === void 0 || subArg === void 0 || opts.port === void 0) askOrUsage("give the box, the subdomain and the port: kvbox vm proxy claim <box> <subdomain> --port <port>");
2064
2260
  if (subArg !== void 0) assertSubdomain(subArg);
2065
2261
  if (opts.port !== void 0) parsePorts([opts.port]);
@@ -2087,11 +2283,11 @@ var claimCommand = new Command9("claim").description("give a box its HTTPS addre
2087
2283
  });
2088
2284
 
2089
2285
  // src/commands/vm/proxy/index.ts
2090
- import { Command as Command15 } from "commander";
2286
+ import { Command as Command17 } from "commander";
2091
2287
 
2092
2288
  // src/commands/vm/proxy/add.ts
2093
- import { Command as Command10 } from "commander";
2094
- var addCommand = new Command10("add").description("publish box ports on the internet; each gets a random public port, or an HTTPS name with --name").argument("<box>", "box name").argument("<port...>", "ports inside the box, e.g. 3000 8080").option("--udp", "UDP instead of TCP").option("--name <name>", "serve the port at https://<name>.<subdomain>.kvbox.app (one port; needs kvbox vm proxy claim first)").option("--json", "print the new forwards as JSON").action(async (name, portTexts, opts, cmd) => {
2289
+ import { Command as Command12 } from "commander";
2290
+ var addCommand = new Command12("add").description("publish box ports on the internet; each gets a random public port, or an HTTPS name with --name").argument("<box>", "box name").argument("<port...>", "ports inside the box, e.g. 3000 8080").option("--udp", "UDP instead of TCP").option("--name <name>", "serve the port at https://<name>.<subdomain>.kvbox.app (one port; needs kvbox vm proxy claim first)").option("--json", "print the new forwards as JSON").action(async (name, portTexts, opts, cmd) => {
2095
2291
  const guestPorts = parsePorts(portTexts);
2096
2292
  if (opts.name !== void 0) {
2097
2293
  assertRouteName(opts.name);
@@ -2132,7 +2328,7 @@ var addCommand = new Command10("add").description("publish box ports on the inte
2132
2328
  });
2133
2329
 
2134
2330
  // src/commands/vm/proxy/ls.ts
2135
- import { Command as Command11 } from "commander";
2331
+ import { Command as Command13 } from "commander";
2136
2332
  async function subdomainsOf(client) {
2137
2333
  try {
2138
2334
  return await client.listSubdomains();
@@ -2141,7 +2337,7 @@ async function subdomainsOf(client) {
2141
2337
  return [];
2142
2338
  }
2143
2339
  }
2144
- var lsCommand2 = new Command11("ls").description("list the box ports published on the internet").argument("[box]", "only this box").option("--json", "print as JSON").action(async (name, opts, cmd) => {
2340
+ var lsCommand2 = new Command13("ls").description("list the box ports published on the internet").argument("[box]", "only this box").option("--json", "print as JSON").action(async (name, opts, cmd) => {
2145
2341
  const client = await clientFor(cmd.optsWithGlobals());
2146
2342
  try {
2147
2343
  const user = me(client);
@@ -2167,8 +2363,8 @@ var lsCommand2 = new Command11("ls").description("list the box ports published o
2167
2363
  });
2168
2364
 
2169
2365
  // src/commands/vm/proxy/release.ts
2170
- import { Command as Command12 } from "commander";
2171
- var releaseCommand = new Command12("release").description("give up a box's HTTPS address and every name under it").argument("<box>", "box name").option("-y, --yes", "do not ask for confirmation").action(async (name, opts, cmd) => {
2366
+ import { Command as Command14 } from "commander";
2367
+ var releaseCommand = new Command14("release").description("give up a box's HTTPS address and every name under it").argument("<box>", "box name").option("-y, --yes", "do not ask for confirmation").action(async (name, opts, cmd) => {
2172
2368
  const client = await clientFor(cmd.optsWithGlobals());
2173
2369
  try {
2174
2370
  requireCloud(client);
@@ -2187,8 +2383,8 @@ var releaseCommand = new Command12("release").description("give up a box's HTTPS
2187
2383
  });
2188
2384
 
2189
2385
  // src/commands/vm/proxy/rm.ts
2190
- import { Command as Command13 } from "commander";
2191
- var rmCommand = new Command13("rm").description("stop publishing box ports, or an HTTPS name with --name").argument("<box>", "box name").argument("[port...]", "ports inside the box, as given to add").option("--udp", "the UDP forwards of those ports").option("--name <name>", "the HTTPS name to free (kvbox vm proxy release frees the whole subdomain)").option("-y, --yes", "do not ask for confirmation").action(async (name, portTexts, opts, cmd) => {
2386
+ import { Command as Command15 } from "commander";
2387
+ var rmCommand = new Command15("rm").description("stop publishing box ports, or an HTTPS name with --name").argument("<box>", "box name").argument("[port...]", "ports inside the box, as given to add").option("--udp", "the UDP forwards of those ports").option("--name <name>", "the HTTPS name to free (kvbox vm proxy release frees the whole subdomain)").option("-y, --yes", "do not ask for confirmation").action(async (name, portTexts, opts, cmd) => {
2192
2388
  if (opts.name !== void 0) {
2193
2389
  assertRouteName(opts.name);
2194
2390
  if (portTexts.length > 0) throw new KvboxError("--name frees a name, not ports: kvbox vm proxy rm <box> --name <name>");
@@ -2220,8 +2416,8 @@ var rmCommand = new Command13("rm").description("stop publishing box ports, or a
2220
2416
  });
2221
2417
 
2222
2418
  // src/commands/vm/proxy/set-port.ts
2223
- import { Command as Command14 } from "commander";
2224
- var setPortCommand = new Command14("set-port").description("point a box's HTTPS address at another of its ports").argument("<box>", "box name").argument("<port>", "the box port https://<subdomain>.kvbox.app serves from now on").option("--json", "print the subdomain as JSON").action(async (name, portText, opts, cmd) => {
2419
+ import { Command as Command16 } from "commander";
2420
+ var setPortCommand = new Command16("set-port").description("point a box's HTTPS address at another of its ports").argument("<box>", "box name").argument("<port>", "the box port https://<subdomain>.kvbox.app serves from now on").option("--json", "print the subdomain as JSON").action(async (name, portText, opts, cmd) => {
2225
2421
  const [port] = parsePorts([portText]);
2226
2422
  const client = await clientFor(cmd.optsWithGlobals());
2227
2423
  try {
@@ -2239,12 +2435,12 @@ var setPortCommand = new Command14("set-port").description("point a box's HTTPS
2239
2435
  });
2240
2436
 
2241
2437
  // src/commands/vm/proxy/index.ts
2242
- var proxyCommand = new Command15("proxy").description("publish box ports on the internet").addCommand(addCommand).addCommand(lsCommand2).addCommand(rmCommand).addCommand(claimCommand).addCommand(setPortCommand).addCommand(releaseCommand);
2438
+ var proxyCommand = new Command17("proxy").description("publish box ports on the internet").addCommand(addCommand).addCommand(lsCommand2).addCommand(rmCommand).addCommand(claimCommand).addCommand(setPortCommand).addCommand(releaseCommand);
2243
2439
  for (const cmd of proxyCommand.commands) cmd.option("--org <slug>", "act in this org (- for your personal boxes)");
2244
2440
 
2245
2441
  // src/commands/vm/rescale.ts
2246
- import { Command as Command16, Option as Option3 } from "commander";
2247
- var rescaleCommand = new Command16("rescale").description("change a box's vCPUs, memory or disk (e.g. --vcpu 4 --mem 16GB); a running box restarts").argument("<name>", "box name").addOption(new Option3("-s, --size <size>", "a preset to start from").choices(SIZE_NAMES)).option("--vcpu <n>", "number of vCPUs").option("--mem <size>", "memory, e.g. 16GB or 4096MB").option("--disk <size>", "disk size, e.g. 32GB (grow only)").option("--json", "print the box as JSON").action(async (name, opts, cmd) => {
2442
+ import { Command as Command18, Option as Option3 } from "commander";
2443
+ var rescaleCommand = new Command18("rescale").description("change a box's vCPUs, memory or disk (e.g. --vcpu 4 --mem 16GB); a running box restarts").argument("<name>", "box name").addOption(new Option3("-s, --size <size>", "a preset to start from").choices(SIZE_NAMES)).option("--vcpu <n>", "number of vCPUs").option("--mem <size>", "memory, e.g. 16GB or 4096MB").option("--disk <size>", "disk size, e.g. 32GB (grow only)").option("--json", "print the box as JSON").action(async (name, opts, cmd) => {
2248
2444
  const req = {
2249
2445
  ...opts.size !== void 0 ? { size: opts.size } : {},
2250
2446
  ...opts.vcpu !== void 0 ? { vcpu: parseCount(opts.vcpu) } : {},
@@ -2289,8 +2485,8 @@ function parseGib(flag, text2) {
2289
2485
  }
2290
2486
 
2291
2487
  // src/commands/vm/resume.ts
2292
- import { Command as Command17 } from "commander";
2293
- var resumeCommand = new Command17("resume").description("continue a box that is in standby (kvbox pause)").argument("<name>", "box name").option("--json", "print the box as JSON").action(async (name, opts, cmd) => {
2488
+ import { Command as Command19 } from "commander";
2489
+ var resumeCommand = new Command19("resume").description("continue a box that is in standby (kvbox pause)").argument("<name>", "box name").option("--json", "print the box as JSON").action(async (name, opts, cmd) => {
2294
2490
  const client = await clientFor(cmd.optsWithGlobals());
2295
2491
  try {
2296
2492
  const box = await spin(`resuming ${name}\u2026`, client.resumeMachine(name));
@@ -2302,8 +2498,8 @@ var resumeCommand = new Command17("resume").description("continue a box that is
2302
2498
  });
2303
2499
 
2304
2500
  // src/commands/vm/rm.ts
2305
- import { Command as Command18 } from "commander";
2306
- var rmCommand2 = new Command18("rm").description("destroy a box (its disk is deleted; snapshots are kept)").argument("<name>", "box name").option("-y, --yes", "do not ask for confirmation").action(async (name, opts, cmd) => {
2501
+ import { Command as Command20 } from "commander";
2502
+ var rmCommand2 = new Command20("rm").description("destroy a box (its disk is deleted; snapshots are kept)").argument("<name>", "box name").option("-y, --yes", "do not ask for confirmation").action(async (name, opts, cmd) => {
2307
2503
  const client = await clientFor(cmd.optsWithGlobals());
2308
2504
  try {
2309
2505
  const box = pickRef(await boxesFor(client, name), name, me(client));
@@ -2323,8 +2519,8 @@ var rmCommand2 = new Command18("rm").description("destroy a box (its disk is del
2323
2519
  });
2324
2520
 
2325
2521
  // src/commands/vm/set.ts
2326
- import { Command as Command19 } from "commander";
2327
- var setCommand = new Command19("set").description("change a box's settings, e.g. --auto-hibernate 30m (off: never)").argument("<name>", "box name").option("--auto-hibernate <duration>", "hibernate the box after this long without network traffic (30m, 4h, 1d; off: never)").option("--json", "print the box as JSON").action(async (name, opts, cmd) => {
2522
+ import { Command as Command21 } from "commander";
2523
+ var setCommand = new Command21("set").description("change a box's settings, e.g. --auto-hibernate 30m (off: never)").argument("<name>", "box name").option("--auto-hibernate <duration>", "hibernate the box after this long without network traffic (30m, 4h, 1d; off: never)").option("--json", "print the box as JSON").action(async (name, opts, cmd) => {
2328
2524
  if (opts.autoHibernate === void 0) throw new KvboxError("nothing to change: give --auto-hibernate");
2329
2525
  const autoHibernateSec = parseIdleTimeout(opts.autoHibernate);
2330
2526
  const client = await clientFor(cmd.optsWithGlobals());
@@ -2343,8 +2539,8 @@ var setCommand = new Command19("set").description("change a box's settings, e.g.
2343
2539
  });
2344
2540
 
2345
2541
  // src/commands/vm/start.ts
2346
- import { Command as Command20 } from "commander";
2347
- var startCommand = new Command20("start").description("boot a stopped box again (same name, IP and disk)").argument("<name>", "box name").option("--json", "print the box as JSON").action(async (name, opts, cmd) => {
2542
+ import { Command as Command22 } from "commander";
2543
+ var startCommand = new Command22("start").description("boot a stopped box again (same name, IP and disk)").argument("<name>", "box name").option("--json", "print the box as JSON").action(async (name, opts, cmd) => {
2348
2544
  const client = await clientFor(cmd.optsWithGlobals());
2349
2545
  try {
2350
2546
  const box = await spin(`booting ${name}\u2026`, client.startMachine(name));
@@ -2356,8 +2552,8 @@ var startCommand = new Command20("start").description("boot a stopped box again
2356
2552
  });
2357
2553
 
2358
2554
  // src/commands/vm/stop.ts
2359
- import { Command as Command21 } from "commander";
2360
- var stopCommand = new Command21("stop").description("shut a box down (its disk is kept; start it again with kvbox start)").argument("<name>", "box name").option("--json", "print the box as JSON").action(async (name, opts, cmd) => {
2555
+ import { Command as Command23 } from "commander";
2556
+ var stopCommand = new Command23("stop").description("shut a box down (its disk is kept; start it again with kvbox start)").argument("<name>", "box name").option("--json", "print the box as JSON").action(async (name, opts, cmd) => {
2361
2557
  const client = await clientFor(cmd.optsWithGlobals());
2362
2558
  try {
2363
2559
  const box = await spin(`shutting ${name} down\u2026`, client.stopMachine(name));
@@ -2369,8 +2565,8 @@ var stopCommand = new Command21("stop").description("shut a box down (its disk i
2369
2565
  });
2370
2566
 
2371
2567
  // src/commands/vm/top.ts
2372
- import { Command as Command22 } from "commander";
2373
- var topCommand = new Command22("top").description("load, memory and disk of each running box, as the box itself sees them").option("-a, --all", "every running box on the platform (platform admins only)").option("--json", "print as JSON").action(async (opts, cmd) => {
2568
+ import { Command as Command24 } from "commander";
2569
+ var topCommand = new Command24("top").description("load, memory and disk of each running box, as the box itself sees them").option("-a, --all", "every running box on the platform (platform admins only)").option("--json", "print as JSON").action(async (opts, cmd) => {
2374
2570
  const client = await clientFor(cmd.optsWithGlobals());
2375
2571
  try {
2376
2572
  const running = (await client.listMachines({ all: opts.all })).filter((b) => b.status === "running");
@@ -2429,9 +2625,31 @@ function topRows(entries, cloud) {
2429
2625
  });
2430
2626
  }
2431
2627
 
2628
+ // src/commands/vm/unlink.ts
2629
+ import { Command as Command25 } from "commander";
2630
+ var unlinkCommand = new Command25("unlink").description("take a link away (kvbox vm link)").argument("<from>", "the box that connects").argument("<box>", "the box it reaches").requiredOption("-p, --port <port>", "the port in <box>").option("-y, --yes", "do not ask for confirmation").option("--json", "print the removed link as JSON").action(async (from, name, opts, cmd) => {
2631
+ const port = parseLinkPort(opts.port);
2632
+ if (!await confirm(`Cut box ${from} off from box ${name} port ${port}? Its open connections close too.`, opts.yes ?? false)) {
2633
+ info("cancelled");
2634
+ process.exitCode = 1;
2635
+ return;
2636
+ }
2637
+ const client = await clientFor(cmd.optsWithGlobals());
2638
+ try {
2639
+ await spin(`unlinking ${from} from ${name}:${port}\u2026`, client.removeLink(name, { from, port }));
2640
+ if (opts.json) {
2641
+ json({ from, box: name, port });
2642
+ return;
2643
+ }
2644
+ info(`${color.green("\u2713")} box ${color.bold(from)} no longer reaches ${color.bold(name)} port ${port}`);
2645
+ } finally {
2646
+ await client.close();
2647
+ }
2648
+ });
2649
+
2432
2650
  // src/commands/vm/update.ts
2433
- import { Command as Command23 } from "commander";
2434
- var updateCommand = new Command23("update").description("move a box onto the current base image (its files stay; a running box restarts)").argument("<name>", "box name").option("--json", "print the box as JSON").action(async (name, opts, cmd) => {
2651
+ import { Command as Command26 } from "commander";
2652
+ var updateCommand = new Command26("update").description("move a box onto the current base image (its files stay; a running box restarts)").argument("<name>", "box name").option("--json", "print the box as JSON").action(async (name, opts, cmd) => {
2435
2653
  const client = await clientFor(cmd.optsWithGlobals());
2436
2654
  try {
2437
2655
  const before = pickRef(await boxesFor(client, name), name, me(client));
@@ -2453,8 +2671,8 @@ var updateCommand = new Command23("update").description("move a box onto the cur
2453
2671
  });
2454
2672
 
2455
2673
  // src/commands/vm/usage.ts
2456
- import { Command as Command24 } from "commander";
2457
- var usageCommand = new Command24("usage").description("how long a box ran, slept and sat stopped, as vCPU-hours, RAM and disk GiB-hours (and cost, when the host prices them)").argument("<name>", "box name").option("--since <date>", "count from this date instead of the box's creation, e.g. 2026-10-01").option("--json", "print as JSON").action(async (name, opts, cmd) => {
2674
+ import { Command as Command27 } from "commander";
2675
+ var usageCommand = new Command27("usage").description("how long a box ran, slept and sat stopped, as vCPU-hours, RAM and disk GiB-hours (and cost, when the host prices them)").argument("<name>", "box name").option("--since <date>", "count from this date instead of the box's creation, e.g. 2026-10-01").option("--json", "print as JSON").action(async (name, opts, cmd) => {
2458
2676
  let since;
2459
2677
  if (opts.since !== void 0) {
2460
2678
  const t = Date.parse(opts.since);
@@ -2501,8 +2719,8 @@ function block(u) {
2501
2719
  }
2502
2720
 
2503
2721
  // src/commands/vm/wake.ts
2504
- import { Command as Command25 } from "commander";
2505
- var wakeCommand = new Command25("wake").description("continue a hibernated box where it left off (same name, IP and disk)").argument("<name>", "box name").option("--json", "print the box as JSON").action(async (name, opts, cmd) => {
2722
+ import { Command as Command28 } from "commander";
2723
+ var wakeCommand = new Command28("wake").description("continue a hibernated box where it left off (same name, IP and disk)").argument("<name>", "box name").option("--json", "print the box as JSON").action(async (name, opts, cmd) => {
2506
2724
  const client = await clientFor(cmd.optsWithGlobals());
2507
2725
  try {
2508
2726
  const box = await spin(`waking ${name} (loading its memory from disk)\u2026`, client.wakeMachine(name));
@@ -2514,15 +2732,15 @@ var wakeCommand = new Command25("wake").description("continue a hibernated box w
2514
2732
  });
2515
2733
 
2516
2734
  // src/commands/vm/index.ts
2517
- var vmCommand = new Command26("vm").enablePositionalOptions().description("manage boxes (each one is a Firecracker microVM)").addCommand(newCommand).addCommand(forkCommand).addCommand(lsCommand).addCommand(getCommand).addCommand(connectCommand).addCommand(execCommand).addCommand(stopCommand).addCommand(startCommand).addCommand(pauseCommand).addCommand(resumeCommand).addCommand(hibernateCommand).addCommand(wakeCommand).addCommand(updateCommand).addCommand(rescaleCommand).addCommand(setCommand).addCommand(usageCommand).addCommand(topCommand).addCommand(proxyCommand).addCommand(rmCommand2);
2735
+ var vmCommand = new Command29("vm").enablePositionalOptions().description("manage boxes (each one is a Firecracker microVM)").addCommand(newCommand).addCommand(forkCommand).addCommand(lsCommand).addCommand(getCommand).addCommand(connectCommand).addCommand(execCommand).addCommand(stopCommand).addCommand(startCommand).addCommand(pauseCommand).addCommand(resumeCommand).addCommand(hibernateCommand).addCommand(wakeCommand).addCommand(updateCommand).addCommand(rescaleCommand).addCommand(setCommand).addCommand(usageCommand).addCommand(topCommand).addCommand(proxyCommand).addCommand(linkCommand).addCommand(unlinkCommand).addCommand(linksCommand).addCommand(rmCommand2);
2518
2736
  for (const cmd of vmCommand.commands) if (cmd !== proxyCommand) cmd.option("--org <slug>", "act in this org (- for your personal boxes)");
2519
2737
  var vmAliases = [newCommand, lsCommand, getCommand, connectCommand, execCommand, stopCommand, startCommand, pauseCommand, resumeCommand, hibernateCommand, wakeCommand, rmCommand2, claimCommand];
2520
2738
 
2521
2739
  // src/commands/server/index.ts
2522
- import { Command as Command34 } from "commander";
2740
+ import { Command as Command37 } from "commander";
2523
2741
 
2524
2742
  // src/commands/server/join.ts
2525
- import { Command as Command27 } from "commander";
2743
+ import { Command as Command30 } from "commander";
2526
2744
 
2527
2745
  // src/commands/server/daemon.ts
2528
2746
  import { spawn as spawn3 } from "child_process";
@@ -2576,7 +2794,7 @@ function runKvboxServer(args) {
2576
2794
  }
2577
2795
 
2578
2796
  // src/commands/server/join.ts
2579
- var joinCommand = new Command27("join").description("put this machine behind a control plane (needs a one-time token minted there) and restart its server").argument("<control-plane-url>", "the control plane, e.g. https://api.kvbox.sh").requiredOption("--token <token>", "one-time join token from the control plane").option("--advertise <host-or-ip>", "address the control plane reaches this machine at (default: its default-route address)").option("--name <name>", "how the control plane lists this machine (default: hostname)").action(async (url, opts) => {
2797
+ var joinCommand = new Command30("join").description("put this machine behind a control plane (needs a one-time token minted there) and restart its server").argument("<control-plane-url>", "the control plane, e.g. https://api.kvbox.sh").requiredOption("--token <token>", "one-time join token from the control plane").option("--advertise <host-or-ip>", "address the control plane reaches this machine at (default: its default-route address)").option("--name <name>", "how the control plane lists this machine (default: hostname)").action(async (url, opts) => {
2580
2798
  const args = ["join", url, "--token", opts.token];
2581
2799
  if (opts.advertise !== void 0) args.push("--advertise", opts.advertise);
2582
2800
  if (opts.name !== void 0) args.push("--name", opts.name);
@@ -2586,8 +2804,8 @@ var joinCommand = new Command27("join").description("put this machine behind a c
2586
2804
  });
2587
2805
 
2588
2806
  // src/commands/server/leave.ts
2589
- import { Command as Command28 } from "commander";
2590
- var leaveCommand = new Command28("leave").description("take this machine out from behind its control plane and restart its server").action(async () => {
2807
+ import { Command as Command31 } from "commander";
2808
+ var leaveCommand = new Command31("leave").description("take this machine out from behind its control plane and restart its server").action(async () => {
2591
2809
  const p = paths();
2592
2810
  for (const line of (await runKvboxServer(["leave"])).split("\n")) info(line);
2593
2811
  if (await runningPid(p) === null) return;
@@ -2596,14 +2814,14 @@ var leaveCommand = new Command28("leave").description("take this machine out fro
2596
2814
  });
2597
2815
 
2598
2816
  // src/commands/server/relay.ts
2599
- import { Command as Command29 } from "commander";
2600
- var relayCommand = new Command29("relay").description("reach the internet through a relay (paste what `kvbox-relay add` printed on the relay VM); `off` takes the tunnel down").argument("<join-string>", "the line `kvbox-relay add` printed, or `off`").action(async (joinString) => {
2817
+ import { Command as Command32 } from "commander";
2818
+ var relayCommand = new Command32("relay").description("reach the internet through a relay (paste what `kvbox-relay add` printed on the relay VM); `off` takes the tunnel down").argument("<join-string>", "the line `kvbox-relay add` printed, or `off`").action(async (joinString) => {
2601
2819
  for (const line of (await runKvboxServer(["relay", joinString])).split("\n")) info(line);
2602
2820
  });
2603
2821
 
2604
2822
  // src/commands/server/start.ts
2605
- import { Command as Command30 } from "commander";
2606
- var startCommand2 = new Command30("start").description("start the local kvbox-server in the background").action(async (_opts, cmd) => {
2823
+ import { Command as Command33 } from "commander";
2824
+ var startCommand2 = new Command33("start").description("start the local kvbox-server in the background").action(async (_opts, cmd) => {
2607
2825
  const client = await clientFor({ ...cmd.optsWithGlobals(), local: true }, { autoStart: false });
2608
2826
  try {
2609
2827
  const health = await client.health();
@@ -2619,8 +2837,8 @@ var startCommand2 = new Command30("start").description("start the local kvbox-se
2619
2837
  });
2620
2838
 
2621
2839
  // src/commands/server/status.ts
2622
- import { Command as Command31 } from "commander";
2623
- var statusCommand = new Command31("status").description("show whether this machine's server is running, its control plane and which base image new boxes get").option("--json", "print as JSON").action(async (opts, cmd) => {
2840
+ import { Command as Command34 } from "commander";
2841
+ var statusCommand = new Command34("status").description("show whether this machine's server is running, its control plane and which base image new boxes get").option("--json", "print as JSON").action(async (opts, cmd) => {
2624
2842
  const client = await clientFor({ ...cmd.optsWithGlobals(), local: true });
2625
2843
  try {
2626
2844
  const health = await client.health();
@@ -2652,8 +2870,8 @@ var statusCommand = new Command31("status").description("show whether this machi
2652
2870
  });
2653
2871
 
2654
2872
  // src/commands/server/stop.ts
2655
- import { Command as Command32 } from "commander";
2656
- var stopCommand2 = new Command32("stop").description("stop the local server (running boxes are not affected)").action(async () => {
2873
+ import { Command as Command35 } from "commander";
2874
+ var stopCommand2 = new Command35("stop").description("stop the local server (running boxes are not affected)").action(async () => {
2657
2875
  const pid = await runningPid(paths());
2658
2876
  if (pid === null) throw new KvboxError("kvbox-server is not running");
2659
2877
  await stopLocalServer(pid);
@@ -2661,8 +2879,8 @@ var stopCommand2 = new Command32("stop").description("stop the local server (run
2661
2879
  });
2662
2880
 
2663
2881
  // src/commands/server/trust-ca.ts
2664
- import { Command as Command33 } from "commander";
2665
- var trustCaCommand = new Command33("trust-ca").description("make every cloud box on this machine trust a new SSH CA (after `ca rotate` on the control plane)").argument("[public-key]", "the CA public key (or its cert-authority line); or --from-cloud").option("--from-cloud", "ask the control plane this host joined for its current CA, show the fingerprint, then ask").option("-y, --yes", "do not ask for confirmation").option("--json", "print the report as JSON").action(async (publicKey, opts, cmd) => {
2882
+ import { Command as Command36 } from "commander";
2883
+ var trustCaCommand = new Command36("trust-ca").description("make every cloud box on this machine trust a new SSH CA (after `ca rotate` on the control plane)").argument("[public-key]", "the CA public key (or its cert-authority line); or --from-cloud").option("--from-cloud", "ask the control plane this host joined for its current CA, show the fingerprint, then ask").option("-y, --yes", "do not ask for confirmation").option("--json", "print the report as JSON").action(async (publicKey, opts, cmd) => {
2666
2884
  if (publicKey === void 0 && !opts.fromCloud) throw new KvboxError("give the CA public key, or --from-cloud to fetch it from the control plane this host joined");
2667
2885
  if (publicKey !== void 0 && opts.fromCloud) throw new KvboxError("either a public key or --from-cloud, not both");
2668
2886
  const client = await clientFor({ ...cmd.optsWithGlobals(), local: true });
@@ -2700,7 +2918,7 @@ function describeReport(report) {
2700
2918
  }
2701
2919
 
2702
2920
  // src/commands/server/index.ts
2703
- var serverCommand = new Command34("server").description("run or manage the kvbox server").addCommand(startCommand2).addCommand(statusCommand).addCommand(stopCommand2).addCommand(joinCommand).addCommand(leaveCommand).addCommand(relayCommand).addCommand(trustCaCommand);
2921
+ var serverCommand = new Command37("server").description("run or manage the kvbox server").addCommand(startCommand2).addCommand(statusCommand).addCommand(stopCommand2).addCommand(joinCommand).addCommand(leaveCommand).addCommand(relayCommand).addCommand(trustCaCommand);
2704
2922
 
2705
2923
  // src/commands/login.ts
2706
2924
  import { spawnSync as spawnSync3 } from "child_process";
@@ -2708,8 +2926,8 @@ import { mkdir as mkdir3, readFile as readFile5, writeFile as writeFile3 } from
2708
2926
  import { hostname as osHostname } from "os";
2709
2927
  import { createInterface as createInterface2 } from "readline/promises";
2710
2928
  import { Writable } from "stream";
2711
- import { Command as Command35 } from "commander";
2712
- var loginCommand = new Command35("login").description("log in to the kvbox cloud (or your own control plane) and target it from now on").argument("[url]", `control plane URL (default: ${DEFAULT_CLOUD_URL})`).option("-e, --email <email>", "account email (prompted otherwise)").option("--password-stdin", "read the password from the first line of stdin (for scripts)").action(async (urlArg, opts) => {
2929
+ import { Command as Command38 } from "commander";
2930
+ var loginCommand = new Command38("login").description("log in to the kvbox cloud (or your own control plane) and target it from now on").argument("[url]", `control plane URL (default: ${DEFAULT_CLOUD_URL})`).option("-e, --email <email>", "account email (prompted otherwise)").option("--password-stdin", "read the password from the first line of stdin (for scripts)").action(async (urlArg, opts) => {
2713
2931
  const url = normalizeUrl(urlArg ?? DEFAULT_CLOUD_URL);
2714
2932
  const creds = await readCredentials(opts);
2715
2933
  const session = await runLogin(url, creds, paths());
@@ -2789,8 +3007,8 @@ async function firstLine(stream) {
2789
3007
  }
2790
3008
 
2791
3009
  // src/commands/logout.ts
2792
- import { Command as Command36 } from "commander";
2793
- var logoutCommand = new Command36("logout").description("log out of the control plane; commands target this machine's kvbox-server again").action(async () => {
3010
+ import { Command as Command39 } from "commander";
3011
+ var logoutCommand = new Command39("logout").description("log out of the control plane; commands target this machine's kvbox-server again").action(async () => {
2794
3012
  const p = paths();
2795
3013
  const session = await readSession(p).catch(() => null);
2796
3014
  switch (await runLogout(p)) {
@@ -2827,8 +3045,8 @@ async function runLogout(p = paths()) {
2827
3045
  }
2828
3046
 
2829
3047
  // src/commands/whoami.ts
2830
- import { Command as Command37 } from "commander";
2831
- var whoamiCommand = new Command37("whoami").description("show which account and control plane commands target (or local mode)").option("--json", "print as JSON").action(async (opts) => {
3048
+ import { Command as Command40 } from "commander";
3049
+ var whoamiCommand = new Command40("whoami").description("show which account and control plane commands target (or local mode)").option("--json", "print as JSON").action(async (opts) => {
2832
3050
  const session = await readSession();
2833
3051
  if (opts.json) {
2834
3052
  json(session ? { user: session.user, url: session.url, sshCertExpires: session.sshCertExpires ?? null } : null);
@@ -2844,11 +3062,11 @@ function describeSession(session) {
2844
3062
  }
2845
3063
 
2846
3064
  // src/commands/snapshots/index.ts
2847
- import { Command as Command41 } from "commander";
3065
+ import { Command as Command44 } from "commander";
2848
3066
 
2849
3067
  // src/commands/snapshots/ls.ts
2850
- import { Command as Command38 } from "commander";
2851
- var lsCommand3 = new Command38("ls").description("list snapshots (yours and your orgs'; --org <slug> for one org)").option("-a, --all", "every snapshot on the platform (platform admins only)").option("--json", "print as JSON").action(async (opts, cmd) => {
3068
+ import { Command as Command41 } from "commander";
3069
+ var lsCommand3 = new Command41("ls").description("list snapshots (yours and your orgs'; --org <slug> for one org)").option("-a, --all", "every snapshot on the platform (platform admins only)").option("--json", "print as JSON").action(async (opts, cmd) => {
2852
3070
  const client = await clientFor(cmd.optsWithGlobals());
2853
3071
  try {
2854
3072
  const cloud = client.target.kind === "cloud";
@@ -2879,21 +3097,22 @@ var lsCommand3 = new Command38("ls").description("list snapshots (yours and your
2879
3097
  });
2880
3098
 
2881
3099
  // src/commands/snapshots/new.ts
2882
- import { Command as Command39 } from "commander";
2883
- var newCommand2 = new Command39("new").description("freeze a running box (memory + disk) into a snapshot; the box keeps running").argument("<box>", "box name").argument("<name>", "snapshot name").option("--json", "print the snapshot as JSON").action(async (box, name, opts, cmd) => {
3100
+ import { Command as Command42 } from "commander";
3101
+ var newCommand2 = new Command42("new").description("freeze a running box (memory + disk) into a snapshot; the box keeps running").argument("<box>", "box name").argument("<name>", "snapshot name").option("--replace", "retake a snapshot that exists under this name; the old one stays until the new one is complete").option("--json", "print the snapshot as JSON").action(async (box, name, opts, cmd) => {
2884
3102
  const client = await clientFor(cmd.optsWithGlobals());
2885
3103
  try {
2886
- const snap = await spin(`saving snapshot ${name} from box ${box} (memory + disk)\u2026`, client.createSnapshot({ box, name }));
3104
+ const req = { box, name, ...opts.replace ? { replace: true } : {} };
3105
+ const snap = await spin(`saving snapshot ${name} from box ${box} (memory + disk)\u2026`, client.createSnapshot(req));
2887
3106
  if (opts.json) json(snap);
2888
- else info(`${color.green("\u2713")} snapshot ${name} saved from box ${box} (${gb(snap.sizeBytes)} on disk); start a warm clone with: kvbox new --from ${name}`);
3107
+ else info(`${color.green("\u2713")} snapshot ${name} ${opts.replace ? "retaken" : "saved"} from box ${box} (${gb(snap.sizeBytes)} on disk); start a warm clone with: kvbox new --from ${name}`);
2889
3108
  } finally {
2890
3109
  await client.close();
2891
3110
  }
2892
3111
  });
2893
3112
 
2894
3113
  // src/commands/snapshots/rm.ts
2895
- import { Command as Command40 } from "commander";
2896
- var rmCommand3 = new Command40("rm").description("delete a snapshot (boxes made from it are not affected)").argument("<name>", "snapshot name").option("-y, --yes", "do not ask for confirmation").action(async (name, opts, cmd) => {
3114
+ import { Command as Command43 } from "commander";
3115
+ var rmCommand3 = new Command43("rm").description("delete a snapshot (boxes made from it are not affected)").argument("<name>", "snapshot name").option("-y, --yes", "do not ask for confirmation").action(async (name, opts, cmd) => {
2897
3116
  if (!await confirm(`Delete snapshot ${name}?`, opts.yes ?? false)) {
2898
3117
  info("cancelled");
2899
3118
  process.exitCode = 1;
@@ -2909,14 +3128,14 @@ var rmCommand3 = new Command40("rm").description("delete a snapshot (boxes made
2909
3128
  });
2910
3129
 
2911
3130
  // src/commands/snapshots/index.ts
2912
- var snapshotsCommand = new Command41("snapshots").aliases(["snapshot", "snap"]).description("freeze running boxes into snapshots and manage them").addCommand(newCommand2).addCommand(lsCommand3).addCommand(rmCommand3);
3131
+ var snapshotsCommand = new Command44("snapshots").aliases(["snapshot", "snap"]).description("freeze running boxes into snapshots and manage them").addCommand(newCommand2).addCommand(lsCommand3).addCommand(rmCommand3);
2913
3132
  for (const cmd of snapshotsCommand.commands) cmd.option("--org <slug>", "act in this org (- for your personal boxes)");
2914
3133
 
2915
3134
  // src/commands/org/index.ts
2916
- import { Command as Command47 } from "commander";
3135
+ import { Command as Command50 } from "commander";
2917
3136
 
2918
3137
  // src/commands/org/ls.ts
2919
- import { Command as Command42 } from "commander";
3138
+ import { Command as Command45 } from "commander";
2920
3139
 
2921
3140
  // src/commands/org/context.ts
2922
3141
  var NOT_LOGGED_IN = "orgs live on the control plane: kvbox login first";
@@ -2936,7 +3155,7 @@ function orgFor(opts, target) {
2936
3155
  }
2937
3156
 
2938
3157
  // src/commands/org/ls.ts
2939
- var lsCommand4 = new Command42("ls").description("list the orgs you belong to and your role in each").option("--json", "print as JSON").action(async (opts, cmd) => {
3158
+ var lsCommand4 = new Command45("ls").description("list the orgs you belong to and your role in each").option("--json", "print as JSON").action(async (opts, cmd) => {
2940
3159
  const client = await cloudClientFor(cmd.optsWithGlobals());
2941
3160
  try {
2942
3161
  const orgs = await client.listOrgs();
@@ -2958,8 +3177,8 @@ function orgRows(orgs) {
2958
3177
  }
2959
3178
 
2960
3179
  // src/commands/org/members.ts
2961
- import { Command as Command43, Option as Option4 } from "commander";
2962
- var lsCommand5 = new Command43("ls").description("list an org's members and their roles").option("-o, --org <slug>", "the org (or --org before the command)").option("--json", "print as JSON").action(async (opts, cmd) => {
3180
+ import { Command as Command46, Option as Option4 } from "commander";
3181
+ var lsCommand5 = new Command46("ls").description("list an org's members and their roles").option("-o, --org <slug>", "the org (or --org before the command)").option("--json", "print as JSON").action(async (opts, cmd) => {
2963
3182
  const client = await cloudClientFor(cmd.optsWithGlobals());
2964
3183
  try {
2965
3184
  const org = await client.getOrg(orgFor(opts, client.target));
@@ -2973,7 +3192,7 @@ var lsCommand5 = new Command43("ls").description("list an org's members and thei
2973
3192
  await client.close();
2974
3193
  }
2975
3194
  });
2976
- var addCommand2 = new Command43("add").description("add a user to an org (admins and owners; only an owner can add an owner)").argument("<user>", "their username").addOption(new Option4("-r, --role <role>", "their role").choices(ORG_ROLES).default("member")).option("-o, --org <slug>", "the org (or --org before the command)").action(async (user, opts, cmd) => {
3195
+ var addCommand2 = new Command46("add").description("add a user to an org (admins and owners; only an owner can add an owner)").argument("<user>", "their username").addOption(new Option4("-r, --role <role>", "their role").choices(ORG_ROLES).default("member")).option("-o, --org <slug>", "the org (or --org before the command)").action(async (user, opts, cmd) => {
2977
3196
  const client = await cloudClientFor(cmd.optsWithGlobals());
2978
3197
  try {
2979
3198
  const slug = orgFor(opts, client.target);
@@ -2983,7 +3202,7 @@ var addCommand2 = new Command43("add").description("add a user to an org (admins
2983
3202
  await client.close();
2984
3203
  }
2985
3204
  });
2986
- var rmCommand4 = new Command43("rm").description("remove a member (or leave: remove yourself)").argument("<user>", "their username").option("-o, --org <slug>", "the org (or --org before the command)").option("-y, --yes", "do not ask for confirmation").action(async (user, opts, cmd) => {
3205
+ var rmCommand4 = new Command46("rm").description("remove a member (or leave: remove yourself)").argument("<user>", "their username").option("-o, --org <slug>", "the org (or --org before the command)").option("-y, --yes", "do not ask for confirmation").action(async (user, opts, cmd) => {
2987
3206
  const client = await cloudClientFor(cmd.optsWithGlobals());
2988
3207
  try {
2989
3208
  const slug = orgFor(opts, client.target);
@@ -2999,11 +3218,11 @@ var rmCommand4 = new Command43("rm").description("remove a member (or leave: rem
2999
3218
  await client.close();
3000
3219
  }
3001
3220
  });
3002
- var membersCommand = new Command43("members").description("who is in an org and what they may do").addCommand(lsCommand5).addCommand(addCommand2).addCommand(rmCommand4);
3221
+ var membersCommand = new Command46("members").description("who is in an org and what they may do").addCommand(lsCommand5).addCommand(addCommand2).addCommand(rmCommand4);
3003
3222
 
3004
3223
  // src/commands/org/new.ts
3005
- import { Command as Command44 } from "commander";
3006
- var newCommand3 = new Command44("new").description("create an org; you become its owner (the slug is permanent, the name is not)").argument("<slug>", "the org's slug: lowercase, like a username (acme)").option("-n, --name <name>", "display name (default: the slug)").option("--json", "print the org as JSON").action(async (slug, opts, cmd) => {
3224
+ import { Command as Command47 } from "commander";
3225
+ var newCommand3 = new Command47("new").description("create an org; you become its owner (the slug is permanent, the name is not)").argument("<slug>", "the org's slug: lowercase, like a username (acme)").option("-n, --name <name>", "display name (default: the slug)").option("--json", "print the org as JSON").action(async (slug, opts, cmd) => {
3007
3226
  const client = await cloudClientFor(cmd.optsWithGlobals());
3008
3227
  try {
3009
3228
  const org = await client.createOrg({ slug, name: opts.name ?? slug });
@@ -3019,8 +3238,8 @@ var newCommand3 = new Command44("new").description("create an org; you become it
3019
3238
  });
3020
3239
 
3021
3240
  // src/commands/org/rm.ts
3022
- import { Command as Command45 } from "commander";
3023
- var rmCommand5 = new Command45("rm").description("delete an org (owners only; remove its boxes and snapshots first)").argument("<slug>", "the org").option("-y, --yes", "do not ask for confirmation").action(async (slug, opts, cmd) => {
3241
+ import { Command as Command48 } from "commander";
3242
+ var rmCommand5 = new Command48("rm").description("delete an org (owners only; remove its boxes and snapshots first)").argument("<slug>", "the org").option("-y, --yes", "do not ask for confirmation").action(async (slug, opts, cmd) => {
3024
3243
  if (!await confirm(`Delete org ${slug}? Its members lose access; its slug stays taken.`, opts.yes ?? false)) {
3025
3244
  info("cancelled");
3026
3245
  process.exitCode = 1;
@@ -3036,8 +3255,8 @@ var rmCommand5 = new Command45("rm").description("delete an org (owners only; re
3036
3255
  });
3037
3256
 
3038
3257
  // src/commands/org/role.ts
3039
- import { Argument, Command as Command46 } from "commander";
3040
- var roleCommand = new Command46("role").description("change a member's role (owners only)").argument("<user>", "their username").addArgument(new Argument("<role>", "owner, admin or member").choices(ORG_ROLES)).option("-o, --org <slug>", "the org (default: the current context)").action(async (user, role, opts, cmd) => {
3258
+ import { Argument, Command as Command49 } from "commander";
3259
+ var roleCommand = new Command49("role").description("change a member's role (owners only)").argument("<user>", "their username").addArgument(new Argument("<role>", "owner, admin or member").choices(ORG_ROLES)).option("-o, --org <slug>", "the org (default: the current context)").action(async (user, role, opts, cmd) => {
3041
3260
  const client = await cloudClientFor(cmd.optsWithGlobals());
3042
3261
  try {
3043
3262
  const slug = orgFor(opts, client.target);
@@ -3049,10 +3268,10 @@ var roleCommand = new Command46("role").description("change a member's role (own
3049
3268
  });
3050
3269
 
3051
3270
  // src/commands/org/index.ts
3052
- var orgCommand = new Command47("org").description("orgs: shared slugs that own boxes, with owners, admins and members").addCommand(lsCommand4).addCommand(newCommand3).addCommand(membersCommand).addCommand(roleCommand).addCommand(rmCommand5);
3271
+ var orgCommand = new Command50("org").description("orgs: shared slugs that own boxes, with owners, admins and members").addCommand(lsCommand4).addCommand(newCommand3).addCommand(membersCommand).addCommand(roleCommand).addCommand(rmCommand5);
3053
3272
 
3054
3273
  // src/commands/usage.ts
3055
- import { Command as Command48 } from "commander";
3274
+ import { Command as Command51 } from "commander";
3056
3275
 
3057
3276
  // ../shared/src/usage.ts
3058
3277
  import { z as z4 } from "zod";
@@ -3089,7 +3308,7 @@ function sumUsage(items, pricing) {
3089
3308
  }
3090
3309
 
3091
3310
  // src/commands/usage.ts
3092
- var usageCommand2 = new Command48("usage").description("what your boxes and volumes used this month (or --since/--until): running time, vCPU-h, RAM and disk GiB-h, cost").option("--since <date>", "count from this date, e.g. 2026-10-01 (default: the 1st of this month)").option("--until <date>", "count up to this date (default: now)").option("--org <slug>", "one org's boxes only").option("-a, --all", "every box on the platform (platform admins only)").option("--by-user", "one line per user who made the boxes (e.g. who spent what in --org)").option("--json", "print as JSON").action(async (opts, cmd) => {
3311
+ var usageCommand2 = new Command51("usage").description("what your boxes and volumes used this month (or --since/--until): running time, vCPU-h, RAM and disk GiB-h, cost").option("--since <date>", "count from this date, e.g. 2026-10-01 (default: the 1st of this month)").option("--until <date>", "count up to this date (default: now)").option("--org <slug>", "one org's boxes only").option("-a, --all", "every box on the platform (platform admins only)").option("--by-user", "one line per user who made the boxes (e.g. who spent what in --org)").option("--json", "print as JSON").action(async (opts, cmd) => {
3093
3312
  for (const [name, value] of [
3094
3313
  ["since", opts.since],
3095
3314
  ["until", opts.until]
@@ -3235,8 +3454,8 @@ function userRows(r) {
3235
3454
  }
3236
3455
 
3237
3456
  // src/commands/credit.ts
3238
- import { Command as Command49 } from "commander";
3239
- var creditCommand = new Command49("credit").description("the prepaid credit left on your account and on each of your orgs").option("--org <slug>", "one org only").option("--json", "print as JSON").action(async (opts, cmd) => {
3457
+ import { Command as Command52 } from "commander";
3458
+ var creditCommand = new Command52("credit").description("the prepaid credit left on your account and on each of your orgs").option("--org <slug>", "one org only").option("--json", "print as JSON").action(async (opts, cmd) => {
3240
3459
  const client = await clientFor(cmd.optsWithGlobals(), { autoStart: false });
3241
3460
  try {
3242
3461
  if (client.target.kind === "local") throw new KvboxError("credit lives on the control plane: kvbox login first");
@@ -3266,7 +3485,7 @@ function creditRow(b, me2) {
3266
3485
  // src/commands/deploy/index.ts
3267
3486
  import { readFile as readFile7 } from "fs/promises";
3268
3487
  import { basename, resolve as resolve2 } from "path";
3269
- import { Command as Command50, Option as Option5 } from "commander";
3488
+ import { Command as Command53, InvalidArgumentError as InvalidArgumentError2, Option as Option5 } from "commander";
3270
3489
 
3271
3490
  // src/commands/deploy/config.ts
3272
3491
  import { readFile as readFile6, writeFile as writeFile4 } from "fs/promises";
@@ -3287,10 +3506,12 @@ function runScript(pm, script) {
3287
3506
  return pm === "yarn" ? [script] : ["run", script];
3288
3507
  }
3289
3508
 
3290
- // src/commands/deploy/templates/nextjs.ts
3509
+ // src/commands/deploy/templates/server.ts
3291
3510
  var APP_DIR = "/srv/app/current";
3292
3511
  var SERVICE = "kvbox-app";
3293
- var PORT = 3e3;
3512
+ var START_WAIT_SEC = 30;
3513
+ var APP_NOT_LISTENING = 4;
3514
+ var LOG_MARKER = "--- kvbox-app log ---";
3294
3515
  function commands(pm) {
3295
3516
  switch (pm) {
3296
3517
  case "pnpm":
@@ -3303,12 +3524,67 @@ function commands(pm) {
3303
3524
  return { setup: [], install: "if [ -f package-lock.json ]; then npm ci; else npm install; fi", build: "npm run build", start: "npm run start" };
3304
3525
  }
3305
3526
  }
3527
+ function serverRemote(opts) {
3528
+ const c = commands(opts.pm);
3529
+ const unit = [
3530
+ "[Unit]",
3531
+ "Description=kvbox deploy: the app in " + APP_DIR,
3532
+ "After=network.target",
3533
+ "",
3534
+ "[Service]",
3535
+ "User=kvbox",
3536
+ `WorkingDirectory=${APP_DIR}`,
3537
+ // PORT on the command line: the proxied address points at it, and nothing in the environment
3538
+ // file below may move the app off it (env's PORT, say, copied from a .env).
3539
+ `ExecStart=/usr/bin/env PORT=${opts.port} ${c.start}`,
3540
+ "Environment=NODE_ENV=production",
3541
+ // The box owner's variables (#88, base v0.10.0+; the `-` makes an older box start without them).
3542
+ "EnvironmentFile=-/etc/kvbox/env",
3543
+ "Restart=always",
3544
+ "RestartSec=2",
3545
+ "",
3546
+ "[Install]",
3547
+ "WantedBy=multi-user.target"
3548
+ ];
3549
+ return [
3550
+ "set -e",
3551
+ "test -d /srv/app -a -w /srv/app || exit 3",
3552
+ "rm -rf /srv/app/.incoming /srv/app/.old",
3553
+ "mkdir -p /srv/app/.incoming",
3554
+ "tar -xf - -C /srv/app/.incoming",
3555
+ "cd /srv/app/.incoming",
3556
+ // Not NODE_ENV=production here: the install would skip devDependencies, which the build needs (TypeScript, Tailwind).
3557
+ `export ${["CI=1", ...opts.env ?? []].join(" ")}`,
3558
+ ...c.setup,
3559
+ c.install,
3560
+ ...opts.build ? [c.build] : [],
3561
+ "cd /",
3562
+ `sudo -n tee /etc/systemd/system/${SERVICE}.service >/dev/null <<'UNIT'`,
3563
+ ...unit,
3564
+ "UNIT",
3565
+ `if [ -e ${APP_DIR} ]; then mv ${APP_DIR} /srv/app/.old; fi`,
3566
+ `mv /srv/app/.incoming ${APP_DIR}`,
3567
+ "sudo -n systemctl daemon-reload",
3568
+ `sudo -n systemctl enable --quiet ${SERVICE}`,
3569
+ `sudo -n systemctl restart ${SERVICE}`,
3570
+ "rm -rf /srv/app/.old",
3571
+ // bash's /dev/tcp: no curl or nc in the image needed.
3572
+ "i=0",
3573
+ `until timeout 1 bash -c '</dev/tcp/127.0.0.1/${opts.port}' 2>/dev/null; do`,
3574
+ " i=$((i+1))",
3575
+ ` if [ "$i" -ge ${START_WAIT_SEC} ]; then echo '${LOG_MARKER}'; sudo -n journalctl -u ${SERVICE} -n 20 --no-pager -o cat || true; exit ${APP_NOT_LISTENING}; fi`,
3576
+ " sleep 1",
3577
+ "done"
3578
+ ].join("\n");
3579
+ }
3580
+
3581
+ // src/commands/deploy/templates/nextjs.ts
3306
3582
  var nextjsTemplate = {
3307
3583
  id: "nextjs",
3308
3584
  label: "Next.js",
3309
3585
  hint: "source shipped; installed, built and run in the box on port 3000",
3310
3586
  size: "s",
3311
- port: PORT,
3587
+ port: 3e3,
3312
3588
  detect(pkg) {
3313
3589
  if (!pkg) return false;
3314
3590
  return "next" in { ...pkg.dependencies, ...pkg.devDependencies };
@@ -3319,60 +3595,37 @@ var nextjsTemplate = {
3319
3595
  if (typeof ctx.pkg?.scripts?.[script] !== "string") throw new KvboxError(`${ctx.dir}: package.json has no "${script}" script; Next.js needs "build": "next build" and "start": "next start"`);
3320
3596
  }
3321
3597
  const pm = await packageManager(ctx.dir);
3322
- return { outDir: ctx.dir, exclude: ["node_modules", ".next", ".git"], pm, what: "the source" };
3598
+ return { outDir: ctx.dir, exclude: ["node_modules", ".next", ".git"], pm, what: "the source", boxBuild: true };
3323
3599
  },
3324
- /**
3325
- * The source lands in a staging directory and is installed and built there while the old app
3326
- * keeps serving; only then is it swapped into place and the service restarted, so a failed
3327
- * install or build leaves the running app alone. The unit is rewritten every time, so a changed
3328
- * package manager or start script takes effect. /srv/app is the kvbox user's (image v0.8.0+). The
3329
- * build runs in the deploy's SSH session, so it sees the owner's variables (`kvbox env`) too.
3330
- */
3331
- remote(built) {
3332
- const c = commands(built.pm);
3333
- const unit = [
3334
- "[Unit]",
3335
- "Description=kvbox deploy: the app in " + APP_DIR,
3336
- "After=network.target",
3337
- "",
3338
- "[Service]",
3339
- "User=kvbox",
3340
- `WorkingDirectory=${APP_DIR}`,
3341
- // PORT on the command line: the proxied address points at it, and nothing in the environment
3342
- // file below may move the app off it (env's PORT, say, copied from a .env).
3343
- `ExecStart=/usr/bin/env PORT=${PORT} ${c.start}`,
3344
- "Environment=NODE_ENV=production",
3345
- // The box owner's variables (#88, base v0.10.0+; the `-` makes an older box start without them).
3346
- "EnvironmentFile=-/etc/kvbox/env",
3347
- "Restart=always",
3348
- "RestartSec=2",
3349
- "",
3350
- "[Install]",
3351
- "WantedBy=multi-user.target"
3352
- ];
3353
- return [
3354
- "set -e",
3355
- "test -d /srv/app -a -w /srv/app || exit 3",
3356
- "rm -rf /srv/app/.incoming /srv/app/.old",
3357
- "mkdir -p /srv/app/.incoming",
3358
- "tar -xf - -C /srv/app/.incoming",
3359
- "cd /srv/app/.incoming",
3360
- // Not NODE_ENV=production here: the install would skip devDependencies, which the build needs (TypeScript, Tailwind).
3361
- "export CI=1 NEXT_TELEMETRY_DISABLED=1",
3362
- ...c.setup,
3363
- c.install,
3364
- c.build,
3365
- "cd /",
3366
- `sudo -n tee /etc/systemd/system/${SERVICE}.service >/dev/null <<'UNIT'`,
3367
- ...unit,
3368
- "UNIT",
3369
- `if [ -e ${APP_DIR} ]; then mv ${APP_DIR} /srv/app/.old; fi`,
3370
- `mv /srv/app/.incoming ${APP_DIR}`,
3371
- "sudo -n systemctl daemon-reload",
3372
- `sudo -n systemctl enable --quiet ${SERVICE}`,
3373
- `sudo -n systemctl restart ${SERVICE}`,
3374
- "rm -rf /srv/app/.old"
3375
- ].join("\n");
3600
+ remote(built, port) {
3601
+ return serverRemote({ pm: built.pm, port, build: true, env: ["NEXT_TELEMETRY_DISABLED=1"] });
3602
+ }
3603
+ };
3604
+
3605
+ // src/commands/deploy/templates/node.ts
3606
+ var FRAMEWORKS = ["express", "fastify", "koa", "@nestjs/core", "@hono/node-server"];
3607
+ var nodeTemplate = {
3608
+ id: "node",
3609
+ label: "Node server",
3610
+ hint: "Express, Fastify, Hono, NestJS\u2026: installed and run in the box on $PORT (3000)",
3611
+ size: "xs",
3612
+ port: 3e3,
3613
+ customPort: true,
3614
+ detect(pkg) {
3615
+ if (!pkg) return false;
3616
+ const deps = { ...pkg.dependencies, ...pkg.devDependencies };
3617
+ return FRAMEWORKS.some((f) => f in deps);
3618
+ },
3619
+ async build(ctx) {
3620
+ if (typeof ctx.pkg?.scripts?.["start"] !== "string") {
3621
+ throw new KvboxError(`${ctx.dir}: package.json has no "start" script; the box runs it to start the server (for example "start": "node server.js")`);
3622
+ }
3623
+ const pm = await packageManager(ctx.dir);
3624
+ const boxBuild = typeof ctx.pkg.scripts["build"] === "string";
3625
+ return { outDir: ctx.dir, exclude: ["node_modules", ".git"], pm, what: "the source", boxBuild };
3626
+ },
3627
+ remote(built, port) {
3628
+ return serverRemote({ pm: built.pm, port, build: built.boxBuild === true });
3376
3629
  }
3377
3630
  };
3378
3631
 
@@ -3442,7 +3695,7 @@ var reactTemplate = {
3442
3695
  };
3443
3696
 
3444
3697
  // src/commands/deploy/templates/index.ts
3445
- var TEMPLATES = [reactTemplate, nextjsTemplate];
3698
+ var TEMPLATES = [reactTemplate, nextjsTemplate, nodeTemplate];
3446
3699
  var TEMPLATE_IDS = TEMPLATES.map((t) => t.id);
3447
3700
  function templateById(id) {
3448
3701
  const t = TEMPLATES.find((x) => x.id === id);
@@ -3469,7 +3722,9 @@ var DeployConfigSchema = z5.object({
3469
3722
  }).optional(),
3470
3723
  size: z5.enum(SIZE_NAMES).optional(),
3471
3724
  /** The build output directory, relative to the app; the template's default when absent. */
3472
- dist: z5.string().optional()
3725
+ dist: z5.string().optional(),
3726
+ /** The port the app serves, for a Node server that hardcodes one; the template's (3000) when absent. */
3727
+ port: z5.number().int().min(1).max(65535).optional()
3473
3728
  });
3474
3729
  async function readConfig(dir) {
3475
3730
  const path = join4(dir, CONFIG_FILE);
@@ -3558,7 +3813,7 @@ async function ship(ep, dir, remote, exclude = []) {
3558
3813
  var shipping = { ship, measure, waitForSsh };
3559
3814
 
3560
3815
  // src/commands/deploy/index.ts
3561
- var deployCommand = new Command50("deploy").description("put the app in this directory (React or Next.js) on a box with its own HTTPS address; redeploy by running it again").argument("[dir]", "the app's directory (default: the current one)").addOption(new Option5("-t, --template <template>", "what kind of app it is (detected from package.json when not given)").choices(TEMPLATE_IDS)).option("-n, --name <name>", "the box's name (default: the directory's name)").option("--sub <subdomain>", "its HTTPS name, https://<subdomain>.kvbox.app (default: the box's name)").addOption(new Option5("-s, --size <size>", "size of the box when it has to be made").choices(SIZE_NAMES)).option("-y, --yes", "ask nothing: take the defaults for whatever the flags and kvbox.json leave open").option("--json", "print the result as JSON").option("--org <slug>", "deploy into this org's boxes (saved to kvbox.json)").action(async (dirArg, opts, cmd) => {
3816
+ var deployCommand = new Command53("deploy").description("put the app in this directory (React, Next.js or a Node server) on a box with its own HTTPS address; redeploy by running it again").argument("[dir]", "the app's directory (default: the current one)").addOption(new Option5("-t, --template <template>", "what kind of app it is (detected from package.json when not given)").choices(TEMPLATE_IDS)).option("-n, --name <name>", "the box's name (default: the directory's name)").option("--sub <subdomain>", "its HTTPS name, https://<subdomain>.kvbox.app (default: the box's name)").addOption(new Option5("-s, --size <size>", "size of the box when it has to be made").choices(SIZE_NAMES)).option("--port <port>", "the port a Node server listens on, when it does not use $PORT (default 3000; saved to kvbox.json)", parsePort).option("-y, --yes", "ask nothing: take the defaults for whatever the flags and kvbox.json leave open").option("--json", "print the result as JSON").option("--org <slug>", "deploy into this org's boxes (saved to kvbox.json)").action(async (dirArg, opts, cmd) => {
3562
3817
  const dir = resolve2(dirArg ?? ".");
3563
3818
  const pkg = await readPackageJson(dir);
3564
3819
  const saved = await readConfig(dir);
@@ -3585,8 +3840,10 @@ var deployCommand = new Command50("deploy").description("put the app in this dir
3585
3840
  const box = created || wasRunning ? found : await wakeUp(client, found, ref);
3586
3841
  const ep = sshEndpoint(box, client.target);
3587
3842
  if (!wasRunning) await spin(`waiting for ${ref} to accept SSH\u2026`, shipping.waitForSsh(ep));
3588
- const shipIt = () => shipping.ship(ep, built.outDir, template.remote(built), built.exclude);
3589
- const doing = built.dist === void 0 ? `shipping ${built.what} (${size.files} files, ${gb(size.bytes)}) to ${ref} and building there, a minute or two\u2026` : `shipping ${built.what} (${size.files} files, ${gb(size.bytes)}) to ${ref}\u2026`;
3843
+ const port = config.port ?? template.port;
3844
+ const shipIt = () => shipping.ship(ep, built.outDir, template.remote(built, port), built.exclude);
3845
+ const there = built.boxBuild ? "installing and building there" : "installing there";
3846
+ const doing = built.dist === void 0 ? `shipping ${built.what} (${size.files} files, ${gb(size.bytes)}) to ${ref} and ${there}, a minute or two\u2026` : `shipping ${built.what} (${size.files} files, ${gb(size.bytes)}) to ${ref}\u2026`;
3590
3847
  let result = await spin(doing, shipIt);
3591
3848
  if (result.status === SSH_FAILED3 && await renewAfterRefusal(client, cert, box.owner)) {
3592
3849
  info("renewed your SSH certificate, trying again\u2026");
@@ -3599,11 +3856,19 @@ ${result.output.trim()}` : ""}`, SSH_FAILED3);
3599
3856
  `box ${ref} runs an image too old for the ${template.label} template (base v0.8.0 or newer). Update the box (kvbox vm update ${ref}) once its host has the new image, or deploy under another name (--name) to get a fresh box`
3600
3857
  );
3601
3858
  }
3859
+ if (result.status === APP_NOT_LISTENING) {
3860
+ const log = result.output.split(LOG_MARKER)[1]?.trim();
3861
+ throw new KvboxError(
3862
+ `the app did not answer on port ${port} within ${START_WAIT_SEC} s: it crashed, or listens on another port. It must listen on process.env.PORT (${port})${template.customPort ? ", or say its port with --port" : ""}. Its log: kvbox exec ${ref} -- journalctl -u kvbox-app${log ? `
3863
+ last lines:
3864
+ ${log}` : ""}`
3865
+ );
3866
+ }
3602
3867
  if (result.status !== 0) throw new KvboxError(`deploying to ${ref} failed (exit ${result.status}):
3603
3868
  ${result.output.trim()}`);
3604
- let url = `http://${box.ip}`;
3869
+ let url = `http://${box.ip}${port === 80 ? "" : `:${port}`}`;
3605
3870
  if (cloud) {
3606
- const got = await address(client, box, ref, config, template);
3871
+ const got = await address(client, box, ref, config, port);
3607
3872
  url = got.url;
3608
3873
  if (got.subdomain !== config.subdomain) await writeConfig(dir, { ...config, subdomain: got.subdomain, ...built.dist !== void 0 && built.dist !== config.dist ? { dist: built.dist } : {} });
3609
3874
  }
@@ -3620,6 +3885,11 @@ ${result.output.trim()}`);
3620
3885
  await client.close();
3621
3886
  }
3622
3887
  });
3888
+ function parsePort(v) {
3889
+ const n = Number(v);
3890
+ if (!Number.isInteger(n) || n < 1 || n > 65535) throw new InvalidArgumentError2("expected a port, 1-65535");
3891
+ return n;
3892
+ }
3623
3893
  async function readPackageJson(dir) {
3624
3894
  try {
3625
3895
  return JSON.parse(await readFile7(resolve2(dir, "package.json"), "utf8"));
@@ -3663,7 +3933,7 @@ async function settle(dir, pkg, saved, opts, orgFlag, cloud) {
3663
3933
  const initial = detected ? TEMPLATES.indexOf(detected) : 0;
3664
3934
  templateId = await select("Template", TEMPLATES.map((t) => ({ value: t.id, label: t.label, hint: t === detected ? `${t.hint} \xB7 detected` : t.hint })), initial);
3665
3935
  }
3666
- if (templateId === void 0) throw new KvboxError(`could not tell what kind of app ${dir} is (no package.json of a Vite, Create React App or Next.js project): say it with --template ${TEMPLATE_IDS.join("|")}`);
3936
+ if (templateId === void 0) throw new KvboxError(`could not tell what kind of app ${dir} is (no package.json of a Vite, Create React App or Next.js project, or of a server on Express, Fastify, Koa, Hono or NestJS): say it with --template ${TEMPLATE_IDS.join("|")}`);
3667
3937
  const template = templateById(templateId);
3668
3938
  let name = defaults.name;
3669
3939
  if (open.name && ask) name = await text("Box name", { default: defaults.name, validate: (a) => BOX_NAME_RE.test(a) ? void 0 : NAME_RULE });
@@ -3682,6 +3952,8 @@ async function settle(dir, pkg, saved, opts, orgFlag, cloud) {
3682
3952
  if (open.size && ask) {
3683
3953
  size = await select("Box size", SIZE_NAMES.map((s) => ({ value: s, label: s, hint: `${SIZES[s].vcpu} vCPU, ${SIZES[s].memMib / 1024} GB RAM, ${SIZES[s].diskGib} GB disk` })), SIZE_NAMES.indexOf(template.size));
3684
3954
  }
3955
+ if (opts.port !== void 0 && !template.customPort) throw new KvboxError(`--port is for a Node server; the ${template.label} template serves port ${template.port}`);
3956
+ const port = opts.port ?? (template.customPort ? saved?.port : void 0);
3685
3957
  const org = orgFlag ?? saved?.org;
3686
3958
  const config = {
3687
3959
  template: template.id,
@@ -3689,7 +3961,8 @@ async function settle(dir, pkg, saved, opts, orgFlag, cloud) {
3689
3961
  ...org !== void 0 ? { org } : {},
3690
3962
  ...subdomain !== void 0 ? { subdomain } : {},
3691
3963
  size,
3692
- ...saved?.dist !== void 0 ? { dist: saved.dist } : {}
3964
+ ...saved?.dist !== void 0 ? { dist: saved.dist } : {},
3965
+ ...port !== void 0 ? { port } : {}
3693
3966
  };
3694
3967
  return { config, template, fresh };
3695
3968
  }
@@ -3719,15 +3992,15 @@ async function refuseOtherAddress(client, config) {
3719
3992
  `box ${ref} already answers at ${have.url}, not ${config.subdomain}. To keep the address: kvbox deploy --sub ${have.subdomain}. To move it: kvbox vm proxy release ${ref}, then deploy again`
3720
3993
  );
3721
3994
  }
3722
- async function address(client, box, ref, config, template) {
3995
+ async function address(client, box, ref, config, port) {
3723
3996
  const have = (await client.listSubdomains()).find((s) => s.box === box.name && s.owner === slugOf(box.owner));
3724
3997
  if (have) {
3725
- if (have.port !== template.port) await client.setSubdomainPort(ref, { port: template.port });
3998
+ if (have.port !== port) await client.setSubdomainPort(ref, { port });
3726
3999
  return { url: have.url, subdomain: have.subdomain };
3727
4000
  }
3728
4001
  const wanted = config.subdomain ?? subdomainFor(config.name);
3729
4002
  try {
3730
- const sub = await spin(`claiming https://${wanted}.kvbox.app\u2026`, client.claimSubdomain(ref, { name: wanted, port: template.port }));
4003
+ const sub = await spin(`claiming https://${wanted}.kvbox.app\u2026`, client.claimSubdomain(ref, { name: wanted, port }));
3731
4004
  return { url: sub.url, subdomain: sub.subdomain };
3732
4005
  } catch (err) {
3733
4006
  if (!(err instanceof KvboxError)) throw err;
@@ -3737,15 +4010,15 @@ the app is on box ${ref} but has no address yet: pick another with kvbox deploy
3737
4010
  }
3738
4011
 
3739
4012
  // src/commands/volume/index.ts
3740
- import { Command as Command56 } from "commander";
4013
+ import { Command as Command59 } from "commander";
3741
4014
 
3742
4015
  // src/commands/volume/attach.ts
3743
- import { Command as Command51 } from "commander";
4016
+ import { Command as Command54 } from "commander";
3744
4017
  function describeMount(machine, volume, box) {
3745
4018
  const path = machine.volumes?.find((v) => volume === v.name || volume.endsWith(`/${v.name}`))?.mountPath ?? volumeMountPath(volume.slice(volume.lastIndexOf("/") + 1));
3746
4019
  return machine.status === "running" ? ` the box was restarted; the volume is at ${path} inside it` : ` box ${box} is ${machine.status}; the volume is at ${path} once it runs`;
3747
4020
  }
3748
- var attachCommand = new Command51("attach").description("attach a volume to a box at /mnt/<volume> (a running box is restarted to take it)").argument("[volume]", "volume name (picked from a list when left out)").argument("[box]", "box name (picked from a list when left out)").option("--json", "print the box as JSON").action(async (volumeArg, boxArg, opts, cmd) => {
4021
+ var attachCommand = new Command54("attach").description("attach a volume to a box at /mnt/<volume> (a running box is restarted to take it)").argument("[volume]", "volume name (picked from a list when left out)").argument("[box]", "box name (picked from a list when left out)").option("--json", "print the box as JSON").action(async (volumeArg, boxArg, opts, cmd) => {
3749
4022
  if (volumeArg === void 0 || boxArg === void 0) askOrUsage("give the volume and the box: kvbox volume attach <volume> <box>");
3750
4023
  const client = await clientFor(cmd.optsWithGlobals());
3751
4024
  try {
@@ -3764,7 +4037,7 @@ var attachCommand = new Command51("attach").description("attach a volume to a bo
3764
4037
  });
3765
4038
 
3766
4039
  // src/commands/volume/create.ts
3767
- import { Command as Command52 } from "commander";
4040
+ import { Command as Command55 } from "commander";
3768
4041
  function parseGib2(text2) {
3769
4042
  const mib = parseMib(text2);
3770
4043
  if (mib === void 0 || mib % 1024 !== 0) throw new KvboxError(`--size ${text2}: write whole GB, like 50 or 50GB`);
@@ -3780,7 +4053,7 @@ function sizeProblem(answer) {
3780
4053
  return err instanceof KvboxError ? err.message.replace(/^--size \S+: /, "") : String(err);
3781
4054
  }
3782
4055
  }
3783
- var createCommand = new Command52("create").alias("new").description("create a volume for a box: an empty disk of its own at /mnt/<name> inside it (a running box is restarted)").argument("[name]", "volume name (1-12 chars; the box mounts it at /mnt/<name>; asked for when left out)").option("--size <gb>", "size in GB, like 50 or 50GB (whole GB; it only occupies what is written)").option("--box <box>", "the box it is for: made on that box's host and attached to it (required on kvbox.sh; optional with --local)").option("--json", "print the volume as JSON").action(async (nameArg, opts, cmd) => {
4056
+ var createCommand = new Command55("create").alias("new").description("create a volume for a box: an empty disk of its own at /mnt/<name> inside it (a running box is restarted)").argument("[name]", "volume name (1-12 chars; the box mounts it at /mnt/<name>; asked for when left out)").option("--size <gb>", "size in GB, like 50 or 50GB (whole GB; it only occupies what is written)").option("--box <box>", "the box it is for: made on that box's host and attached to it (required on kvbox.sh; optional with --local)").option("--json", "print the volume as JSON").action(async (nameArg, opts, cmd) => {
3784
4057
  const ask = interactive();
3785
4058
  if (nameArg === void 0 || opts.size === void 0) askOrUsage("give the name and the size: kvbox volume create <name> --size <gb> --box <box>");
3786
4059
  const name = nameArg ?? await text("Volume name", { validate: (a) => VOLUME_NAME_RE.test(a) ? void 0 : VOLUME_NAME_RULE });
@@ -3813,8 +4086,8 @@ var createCommand = new Command52("create").alias("new").description("create a v
3813
4086
  });
3814
4087
 
3815
4088
  // src/commands/volume/detach.ts
3816
- import { Command as Command53 } from "commander";
3817
- var detachCommand = new Command53("detach").description("detach a volume from a box; its data is kept (a running box is restarted)").argument("[volume]", "volume name (picked from a list when left out)").argument("[box]", "box name (the one the volume is on when left out)").option("--json", "print the box as JSON").action(async (volumeArg, boxArg, opts, cmd) => {
4089
+ import { Command as Command56 } from "commander";
4090
+ var detachCommand = new Command56("detach").description("detach a volume from a box; its data is kept (a running box is restarted)").argument("[volume]", "volume name (picked from a list when left out)").argument("[box]", "box name (the one the volume is on when left out)").option("--json", "print the box as JSON").action(async (volumeArg, boxArg, opts, cmd) => {
3818
4091
  if (volumeArg === void 0) askOrUsage("give the volume: kvbox volume detach <volume> [box]");
3819
4092
  const client = await clientFor(cmd.optsWithGlobals());
3820
4093
  try {
@@ -3839,8 +4112,8 @@ var detachCommand = new Command53("detach").description("detach a volume from a
3839
4112
  });
3840
4113
 
3841
4114
  // src/commands/volume/ls.ts
3842
- import { Command as Command54 } from "commander";
3843
- var lsCommand6 = new Command54("ls").alias("list").description("list volumes: size, what they occupy, which box has them").option("-a, --all", "every volume on the platform (platform admins only)").option("--json", "print as JSON").action(async (opts, cmd) => {
4115
+ import { Command as Command57 } from "commander";
4116
+ var lsCommand6 = new Command57("ls").alias("list").description("list volumes: size, what they occupy, which box has them").option("-a, --all", "every volume on the platform (platform admins only)").option("--json", "print as JSON").action(async (opts, cmd) => {
3844
4117
  const client = await clientFor(cmd.optsWithGlobals());
3845
4118
  try {
3846
4119
  const cloud = client.target.kind === "cloud";
@@ -3871,8 +4144,8 @@ var lsCommand6 = new Command54("ls").alias("list").description("list volumes: si
3871
4144
  });
3872
4145
 
3873
4146
  // src/commands/volume/rm.ts
3874
- import { Command as Command55 } from "commander";
3875
- var rmCommand6 = new Command55("rm").alias("remove").description("delete a volume and everything on it (detach it first)").argument("<name>", "volume name").option("-y, --yes", "do not ask for confirmation").action(async (name, opts, cmd) => {
4147
+ import { Command as Command58 } from "commander";
4148
+ var rmCommand6 = new Command58("rm").alias("remove").description("delete a volume and everything on it (detach it first)").argument("<name>", "volume name").option("-y, --yes", "do not ask for confirmation").action(async (name, opts, cmd) => {
3876
4149
  if (!await confirm(`Delete volume ${name} and everything on it?`, opts.yes ?? false)) {
3877
4150
  info("cancelled");
3878
4151
  process.exitCode = 1;
@@ -3888,14 +4161,14 @@ var rmCommand6 = new Command55("rm").alias("remove").description("delete a volum
3888
4161
  });
3889
4162
 
3890
4163
  // src/commands/volume/index.ts
3891
- var volumeCommand = new Command56("volume").aliases(["volumes", "vol"]).description("disks of their own: create one, attach it to a box at /mnt/<name>, move it to another box later").addCommand(createCommand).addCommand(lsCommand6).addCommand(attachCommand).addCommand(detachCommand).addCommand(rmCommand6);
4164
+ var volumeCommand = new Command59("volume").aliases(["volumes", "vol"]).description("disks of their own: create one, attach it to a box at /mnt/<name>, move it to another box later").addCommand(createCommand).addCommand(lsCommand6).addCommand(attachCommand).addCommand(detachCommand).addCommand(rmCommand6);
3892
4165
  for (const cmd of volumeCommand.commands) cmd.option("--org <slug>", "act in this org (- for your personal volumes)");
3893
4166
 
3894
4167
  // src/commands/env/index.ts
3895
- import { Command as Command60 } from "commander";
4168
+ import { Command as Command63 } from "commander";
3896
4169
 
3897
4170
  // src/commands/env/ls.ts
3898
- import { Command as Command57 } from "commander";
4171
+ import { Command as Command60 } from "commander";
3899
4172
 
3900
4173
  // src/commands/env/shared.ts
3901
4174
  function requireCloud2(client) {
@@ -3906,11 +4179,44 @@ function reach(boxes, verb) {
3906
4179
  if (boxes === 0) return verb === "get" ? "no boxes yet, every new one gets it" : "no boxes yet";
3907
4180
  return boxes === 1 ? `1 box ${verb}s it when it next starts` : `${boxes} boxes ${verb} it when they next start`;
3908
4181
  }
4182
+ async function findBox2(client, name) {
4183
+ const box = pickRef(await boxesFor(client, name), name, me(client));
4184
+ if (!box) throw new KvboxError(`box ${name}: not found (kvbox ls)`);
4185
+ return { box, ref: displayName(box, me(client)) };
4186
+ }
4187
+ function boxReach(running, verb) {
4188
+ return running ? `it ${verb} it when it next starts (kvbox stop, kvbox start)` : `it ${verb} it when it starts`;
4189
+ }
4190
+ function firstBootHint(box, name) {
4191
+ if (box.image === "postgres" && /^POSTGRES_(USER|PASSWORD|DB)$/.test(name)) {
4192
+ return `${name} is read once, when the box first boots: the database keeps the user, password and database it was made with (change them with psql in the box)`;
4193
+ }
4194
+ return void 0;
4195
+ }
3909
4196
 
3910
4197
  // src/commands/env/ls.ts
3911
- var lsCommand7 = new Command57("ls").alias("list").description("list the variables (a secret shows as (sealed))").option("--json", "print as JSON").action(async (opts, cmd) => {
4198
+ var lsCommand7 = new Command60("ls").alias("list").description("list the variables (a secret shows as (sealed))").option("--box <box>", "what this box gets: its own variables and the ones it inherits").option("--json", "print as JSON").action(async (opts, cmd) => {
3912
4199
  const client = await clientFor(cmd.optsWithGlobals(), { autoStart: false });
3913
4200
  try {
4201
+ if (opts.box !== void 0) {
4202
+ const { box, ref } = await findBox2(client, opts.box);
4203
+ const own = await client.boxEnv(ref);
4204
+ const slug = slugOf(box.owner);
4205
+ const theirs = client.target.kind === "cloud" ? await client.listEnv(slug === me(client) ? void 0 : slug) : [];
4206
+ const mine = new Set(own.vars.map((v) => v.name));
4207
+ const inherited = theirs.filter((v) => !mine.has(v.name));
4208
+ if (opts.json) {
4209
+ json({ box: own.box, vars: own.vars, inherited });
4210
+ return;
4211
+ }
4212
+ if (own.vars.length === 0 && inherited.length === 0) {
4213
+ info(`box ${ref} gets no variables; set one with: kvbox env set NAME value --box ${ref}`);
4214
+ return;
4215
+ }
4216
+ const row = (v, from) => ({ name: v.name, value: v.secret ? color.dim("(sealed)") : v.value, from, updated: age(v.updatedAt) });
4217
+ table([...own.vars.map((v) => row(v, "box")), ...inherited.map((v) => row(v, color.dim(slug)))]);
4218
+ return;
4219
+ }
3914
4220
  const owner = requireCloud2(client);
3915
4221
  const vars = await client.listEnv();
3916
4222
  if (opts.json) {
@@ -3928,11 +4234,12 @@ var lsCommand7 = new Command57("ls").alias("list").description("list the variabl
3928
4234
  });
3929
4235
 
3930
4236
  // src/commands/env/rm.ts
3931
- import { Command as Command58 } from "commander";
3932
- var rmCommand7 = new Command58("rm").alias("remove").description("remove variables; boxes lose them when they next start").argument("<names...>", "variable names").option("-y, --yes", "do not ask for confirmation").option("--json", "print as JSON").action(async (names, opts, cmd) => {
4237
+ import { Command as Command61 } from "commander";
4238
+ var rmCommand7 = new Command61("rm").alias("remove").description("remove variables; boxes lose them when they next start").argument("<names...>", "variable names").option("-y, --yes", "do not ask for confirmation").option("--box <box>", "remove this box's own variables (yours, or the org's, of the same name come back)").option("--json", "print as JSON").action(async (names, opts, cmd) => {
3933
4239
  const client = await clientFor(cmd.optsWithGlobals(), { autoStart: false });
3934
4240
  try {
3935
- const owner = requireCloud2(client);
4241
+ const target = opts.box === void 0 ? void 0 : await findBox2(client, opts.box);
4242
+ const owner = target === void 0 ? requireCloud2(client) : `box ${target.ref}`;
3936
4243
  if (!await confirm(`Remove ${names.join(", ")} from ${owner}'s variables?`, opts.yes ?? false)) {
3937
4244
  info("cancelled");
3938
4245
  process.exitCode = 1;
@@ -3942,6 +4249,12 @@ var rmCommand7 = new Command58("rm").alias("remove").description("remove variabl
3942
4249
  const failed = [];
3943
4250
  for (const name of names) {
3944
4251
  try {
4252
+ if (target !== void 0) {
4253
+ const c2 = await spin(`removing ${name}\u2026`, client.removeBoxEnv(target.ref, name));
4254
+ changes.push(c2);
4255
+ if (!opts.json) info(`${color.green("\u2713")} removed ${c2.name} from ${owner}: ${boxReach(c2.running, "loses")}`);
4256
+ continue;
4257
+ }
3945
4258
  const c = await spin(`removing ${name}\u2026`, client.removeEnv(name));
3946
4259
  changes.push(c);
3947
4260
  if (!opts.json) info(`${color.green("\u2713")} removed ${c.name} from ${owner}: ${reach(c.boxes, "lose")}`);
@@ -3959,29 +4272,12 @@ var rmCommand7 = new Command58("rm").alias("remove").description("remove variabl
3959
4272
  });
3960
4273
 
3961
4274
  // src/commands/env/set.ts
3962
- import { Command as Command59 } from "commander";
3963
-
3964
- // ../shared/src/env.ts
3965
- var ENV_NAME_RE = /^[A-Za-z_][A-Za-z0-9_]*$/;
3966
- var ENV_RESERVED = ["PATH", "HOME", "USER", "SHELL"];
3967
- var ENV_MAX_VALUE_BYTES = 4096;
3968
- function envNameProblem(name) {
3969
- if (!ENV_NAME_RE.test(name)) return `${JSON.stringify(name)} is not a variable name: letters, digits and _, not starting with a digit`;
3970
- if (ENV_RESERVED.includes(name)) return `${name} is the box's own and cannot be set`;
3971
- if (name.startsWith("KVBOX_")) return `${name}: names starting with KVBOX_ are kept for kvbox`;
3972
- return null;
3973
- }
3974
- function envValueProblem(value) {
3975
- if (/[\n\r\0]/.test(value)) return "a value is one line: no line breaks (base64 a multi-line value such as a key file)";
3976
- if (Buffer.byteLength(value, "utf8") > ENV_MAX_VALUE_BYTES) return `a value is at most ${ENV_MAX_VALUE_BYTES / 1024} KB`;
3977
- return null;
3978
- }
3979
-
3980
- // src/commands/env/set.ts
3981
- var setCommand2 = new Command59("set").description("add or change a variable; boxes get it when they next start").argument("[name]", "variable name, e.g. DATABASE_URL (asked for when left out)").argument("[value]", "its value (asked for when left out; hidden with --secret)").option("--secret", "write-only: the value is never shown again, by any command").option("--json", "print as JSON").action(async (nameArg, valueArg, opts, cmd) => {
4275
+ import { Command as Command62 } from "commander";
4276
+ var setCommand2 = new Command62("set").description("add or change a variable; boxes get it when they next start").argument("[name]", "variable name, e.g. DATABASE_URL (asked for when left out)").argument("[value]", "its value (asked for when left out; hidden with --secret)").option("--secret", "write-only: the value is never shown again, by any command").option("--box <box>", "this box's own variable, over yours (or the org's) of the same name").option("--json", "print as JSON").action(async (nameArg, valueArg, opts, cmd) => {
3982
4277
  const client = await clientFor(cmd.optsWithGlobals(), { autoStart: false });
3983
4278
  try {
3984
- const owner = requireCloud2(client);
4279
+ const owner = opts.box === void 0 ? requireCloud2(client) : void 0;
4280
+ const target = opts.box === void 0 ? void 0 : await findBox2(client, opts.box);
3985
4281
  const ask = interactive();
3986
4282
  if ((nameArg === void 0 || valueArg === void 0) && !ask) throw new KvboxError("give the name and the value: kvbox env set NAME VALUE (or run it in a terminal to be asked)");
3987
4283
  const name = nameArg ?? await text("Variable name", { validate: (a) => envNameProblem(a) ?? void 0 });
@@ -3990,12 +4286,23 @@ var setCommand2 = new Command59("set").description("add or change a variable; bo
3990
4286
  const value = valueArg ?? (opts.secret ? await hiddenText(`Value for ${name}`) : await text(`Value for ${name}`, { trim: false }));
3991
4287
  const valueProblem = envValueProblem(value);
3992
4288
  if (valueProblem !== null) throw new KvboxError(valueProblem);
4289
+ const what = opts.secret ? `${name} (secret)` : name;
4290
+ if (target !== void 0) {
4291
+ const change2 = await spin(`setting ${name}\u2026`, client.setBoxEnv(target.ref, name, { value, secret: opts.secret ?? false }));
4292
+ if (opts.json) {
4293
+ json(change2);
4294
+ return;
4295
+ }
4296
+ info(`${color.green("\u2713")} set ${what} on box ${color.bold(target.ref)}: ${boxReach(change2.running, "gets")}`);
4297
+ const hint = firstBootHint(target.box, name);
4298
+ if (hint !== void 0) warn(hint);
4299
+ return;
4300
+ }
3993
4301
  const change = await spin(`setting ${name}\u2026`, client.setEnv(name, { value, secret: opts.secret ?? false }));
3994
4302
  if (opts.json) {
3995
4303
  json(change);
3996
4304
  return;
3997
4305
  }
3998
- const what = opts.secret ? `${name} (secret)` : name;
3999
4306
  info(`${color.green("\u2713")} set ${what} for ${owner}: ${reach(change.boxes, "get")}`);
4000
4307
  } finally {
4001
4308
  await client.close();
@@ -4003,14 +4310,14 @@ var setCommand2 = new Command59("set").description("add or change a variable; bo
4003
4310
  });
4004
4311
 
4005
4312
  // src/commands/env/index.ts
4006
- var envCommand = new Command60("env").description("environment variables every box of yours gets when it starts (secrets too)").addCommand(lsCommand7, { isDefault: true }).addCommand(setCommand2).addCommand(rmCommand7);
4313
+ var envCommand = new Command63("env").description("environment variables every box of yours gets when it starts (secrets too)").addCommand(lsCommand7, { isDefault: true }).addCommand(setCommand2).addCommand(rmCommand7);
4007
4314
  for (const cmd of envCommand.commands) cmd.option("--org <slug>", "the org's variables instead of yours");
4008
4315
 
4009
4316
  // src/commands/domain/index.ts
4010
- import { Command as Command64 } from "commander";
4317
+ import { Command as Command67 } from "commander";
4011
4318
 
4012
4319
  // src/commands/domain/add.ts
4013
- import { Command as Command61 } from "commander";
4320
+ import { Command as Command64 } from "commander";
4014
4321
 
4015
4322
  // src/commands/domain/shared.ts
4016
4323
  function requireCloud3(client) {
@@ -4020,9 +4327,17 @@ var boxOf2 = (d, user) => user !== void 0 && d.owner !== user ? `${d.owner}/${d.
4020
4327
  function domainJson(d, user) {
4021
4328
  return { domain: d.domain, box: boxOf2(d, user), port: d.port, status: d.status, www: d.www, url: d.url, error: d.error, records: d.records, createdAt: d.createdAt };
4022
4329
  }
4330
+ function zoneOf(domain) {
4331
+ const labels = domain.split(".");
4332
+ const n = labels.length > 2 && labels.at(-1).length === 2 && labels.at(-2).length <= 3 ? 3 : 2;
4333
+ return labels.slice(-n).join(".");
4334
+ }
4335
+ function hostIn(name, zone) {
4336
+ return name === zone ? "@" : name.endsWith(`.${zone}`) ? name.slice(0, -(zone.length + 1)) : name;
4337
+ }
4023
4338
 
4024
4339
  // src/commands/domain/add.ts
4025
- var addCommand3 = new Command61("add").description("serve a box at a domain of your own, https://<domain>, with its certificate made for you").argument("<domain>", "a domain you control, like example.com or app.example.com").argument("<box>", "box name").option("--port <port>", "the box port the domain serves (default: the port of its kvbox.app address)").option("--json", "print the domain as JSON").action(async (domainArg, name, opts, cmd) => {
4340
+ var addCommand3 = new Command64("add").description("serve a box at a domain of your own, https://<domain>, with its certificate made for you").argument("<domain>", "a domain you control, like example.com or app.example.com").argument("<box>", "box name").option("--port <port>", "the box port the domain serves (default: the port of its kvbox.app address)").option("--json", "print the domain as JSON").action(async (domainArg, name, opts, cmd) => {
4026
4341
  const domain = assertDomain(domainArg.trim().toLowerCase());
4027
4342
  const port = opts.port === void 0 ? void 0 : parsePorts([opts.port])[0];
4028
4343
  const client = await clientFor(cmd.optsWithGlobals());
@@ -4041,10 +4356,11 @@ var addCommand3 = new Command61("add").description("serve a box at a domain of y
4041
4356
  return;
4042
4357
  }
4043
4358
  info(`${color.green("\u2713")} ${domain} added for box ${color.bold(box)} port ${d.port}, waiting for its DNS`);
4359
+ const zone = zoneOf(domain);
4044
4360
  info(`
4045
- At the company that runs the DNS of ${domain}, add:
4361
+ At the company that runs the DNS of ${zone}, add:
4046
4362
  `);
4047
- table(d.records.map((r) => ({ type: r.type, name: r.name, value: r.value })));
4363
+ table(d.records.map((r) => ({ type: r.type, host: hostIn(r.name, zone), value: r.value })));
4048
4364
  info(`
4049
4365
  (the TXT record shows ${domain} is yours; keep it, it is checked again if the domain ever goes back to pending)`);
4050
4366
  if (d.records.some((r) => r.type === "CNAME")) info(` (the www record is optional: with it, www.${domain} serves the same site)`);
@@ -4057,8 +4373,8 @@ kvbox checks every minute; ${domain} is served at ${d.url} once its records are
4057
4373
  });
4058
4374
 
4059
4375
  // src/commands/domain/ls.ts
4060
- import { Command as Command62 } from "commander";
4061
- var lsCommand8 = new Command62("ls").alias("list").description("list your custom domains and whether they are live").option("--json", "print as JSON").action(async (opts, cmd) => {
4376
+ import { Command as Command65 } from "commander";
4377
+ var lsCommand8 = new Command65("ls").alias("list").description("list your custom domains and whether they are live").option("--json", "print as JSON").action(async (opts, cmd) => {
4062
4378
  const client = await clientFor(cmd.optsWithGlobals());
4063
4379
  try {
4064
4380
  requireCloud3(client);
@@ -4087,8 +4403,8 @@ var lsCommand8 = new Command62("ls").alias("list").description("list your custom
4087
4403
  });
4088
4404
 
4089
4405
  // src/commands/domain/rm.ts
4090
- import { Command as Command63 } from "commander";
4091
- var rmCommand8 = new Command63("rm").alias("remove").description("stop serving a box at a custom domain").argument("<domain>", "the domain").option("-y, --yes", "do not ask for confirmation").action(async (domainArg, opts, cmd) => {
4406
+ import { Command as Command66 } from "commander";
4407
+ var rmCommand8 = new Command66("rm").alias("remove").description("stop serving a box at a custom domain").argument("<domain>", "the domain").option("-y, --yes", "do not ask for confirmation").action(async (domainArg, opts, cmd) => {
4092
4408
  const domain = domainArg.trim().toLowerCase();
4093
4409
  const client = await clientFor(cmd.optsWithGlobals());
4094
4410
  try {
@@ -4109,12 +4425,12 @@ var rmCommand8 = new Command63("rm").alias("remove").description("stop serving a
4109
4425
  });
4110
4426
 
4111
4427
  // src/commands/domain/index.ts
4112
- var domainCommand = new Command64("domain").alias("domains").description("serve a box at a domain of your own").addCommand(addCommand3).addCommand(lsCommand8).addCommand(rmCommand8);
4428
+ var domainCommand = new Command67("domain").alias("domains").description("serve a box at a domain of your own").addCommand(addCommand3).addCommand(lsCommand8).addCommand(rmCommand8);
4113
4429
  for (const cmd of domainCommand.commands) cmd.option("--org <slug>", "act in this org (- for your personal boxes)");
4114
4430
 
4115
4431
  // src/program.ts
4116
4432
  function buildProgram() {
4117
- const program = new Command65("kvbox").description("self-hosted Firecracker microVMs with Docker-like ergonomics").version(VERSION, "-v, --version").option("--local", "use this machine's kvbox-server over its socket, ignoring kvbox login").option("--org <slug>", "the org: where kvbox new creates, and which box a name means when it is not one of yours; before the command here, or after it").showHelpAfterError().enablePositionalOptions();
4433
+ const program = new Command68("kvbox").description("self-hosted Firecracker microVMs with Docker-like ergonomics").version(VERSION, "-v, --version").option("--local", "use this machine's kvbox-server over its socket, ignoring kvbox login").option("--org <slug>", "the org: where kvbox new creates, and which box a name means when it is not one of yours; before the command here, or after it").showHelpAfterError().enablePositionalOptions();
4118
4434
  program.addCommand(vmCommand);
4119
4435
  program.addCommand(snapshotsCommand);
4120
4436
  program.addCommand(volumeCommand);