@kvbox/cli 0.6.9 → 0.6.11

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
@@ -155,7 +155,7 @@ async function spin(message, work, opts = {}) {
155
155
  }
156
156
 
157
157
  // src/program.ts
158
- import { Command as Command123 } from "commander";
158
+ import { Command as Command130 } from "commander";
159
159
 
160
160
  // ../shared/src/version.ts
161
161
  import { createRequire } from "module";
@@ -170,10 +170,10 @@ function versionOf(srcFileUrl, injected) {
170
170
  }
171
171
 
172
172
  // src/version.ts
173
- var VERSION = versionOf(import.meta.url, true ? "0.6.9" : void 0);
173
+ var VERSION = versionOf(import.meta.url, true ? "0.6.11" : void 0);
174
174
 
175
175
  // src/commands/vm/index.ts
176
- import { Command as Command38 } from "commander";
176
+ import { Command as Command39 } from "commander";
177
177
 
178
178
  // src/commands/vm/connect.ts
179
179
  import { spawnSync as spawnSync3 } from "child_process";
@@ -240,6 +240,8 @@ function paths(home = kvboxHome()) {
240
240
  },
241
241
  assets: join(home, "assets"),
242
242
  kernel: join(home, "assets", "vmlinux"),
243
+ /** A kernel an image asks for by name in its image.json (`"kernel": "android"`): assets/vmlinux-<name>, put there by install-server.sh. */
244
+ namedKernel: (name) => join(home, "assets", `vmlinux-${name}`),
243
245
  /** Symlink to the current base image, assets/rootfs-<version>.ext4; boxes keep using the version they were made from. */
244
246
  rootfs: join(home, "assets", "rootfs.ext4"),
245
247
  baseImage: (version) => join(home, "assets", `rootfs-${version}.ext4`),
@@ -454,6 +456,12 @@ var BackupSchema = z.object({
454
456
  createdAt: z.string(),
455
457
  finishedAt: z.string().nullable()
456
458
  });
459
+ var BackupLimitSchema = z.object({
460
+ perDay: z.number().int(),
461
+ used: z.number().int(),
462
+ nextAt: z.string().nullable()
463
+ });
464
+ var NamedBackupLimitSchema = BackupLimitSchema.extend({ owner: z.string(), name: z.string() });
457
465
  var HostBackupRequest = z.object({ id: z.string(), key: z.string() });
458
466
  var HostBackupManifestSchema = z.object({
459
467
  id: z.string(),
@@ -496,6 +504,16 @@ var VolumeBackupSchema = z.object({
496
504
  createdAt: z.string(),
497
505
  finishedAt: z.string().nullable()
498
506
  });
507
+ var BackupScheduleSchema = z.object({
508
+ enabled: z.boolean(),
509
+ /** 0-23, UTC. Kept while it is off, so turning it on again keeps the hour. */
510
+ hour: z.number().int().min(0).max(23),
511
+ nextAt: z.string().nullable(),
512
+ lastAt: z.string().nullable(),
513
+ lastBackup: z.string().nullable(),
514
+ lastError: z.string().nullable()
515
+ });
516
+ var SetBackupScheduleRequest = z.object({ enabled: z.boolean().optional(), hour: z.number().int().min(0).max(23).optional() });
499
517
  var HostVolumeBackupManifestSchema = z.object({ id: z.string(), sizeBytes: z.number().int(), chunks: z.array(z.string().nullable()) });
500
518
  var HostVolumeRestoreRequest = z.object({
501
519
  id: z.string(),
@@ -878,6 +896,11 @@ var CapacitySchema = z.object({
878
896
  reservedMemMib: z.number().int(),
879
897
  reservedVcpu: z.number().int(),
880
898
  running: z.number().int(),
899
+ /**
900
+ * MiB of RAM the host keeps back from its boxes (config.json `memHeadroomMib`). Absent on a kvbox-server
901
+ * from before the setting, which keeps 2 GB (`OLD_HOST_MEM_HEADROOM_MIB`).
902
+ */
903
+ memHeadroomMib: z.number().int().optional(),
881
904
  /** Absent on a host from before volumes (#91): it cannot take one. */
882
905
  disk: DiskCapacitySchema.optional(),
883
906
  /**
@@ -1024,6 +1047,16 @@ var CronUsageSchema = z.object({
1024
1047
  /** When it was made. */
1025
1048
  historyFrom: z.string().nullable()
1026
1049
  });
1050
+ var BackupUsageSchema = z.object({
1051
+ id: z.string(),
1052
+ kind: z.string(),
1053
+ name: z.string(),
1054
+ owner: z.string(),
1055
+ ownerKind: z.enum(["user", "org"]).optional(),
1056
+ /** How many paid backups turned ready in the window. */
1057
+ count: z.number().int(),
1058
+ cost: z.object({ amount: z.number(), currency: z.string() })
1059
+ });
1027
1060
  var UsageDayItemSchema = z.object({
1028
1061
  id: z.string(),
1029
1062
  name: z.string(),
@@ -1044,7 +1077,9 @@ var UsageDaySchema = z.object({
1044
1077
  /** Object storage that existed that day (#182); absent on a day without any. */
1045
1078
  storage: z.array(UsageDayItemSchema).optional(),
1046
1079
  /** Cron services that existed that day (#190); absent on a day without any. */
1047
- cron: z.array(UsageDayItemSchema).optional()
1080
+ cron: z.array(UsageDayItemSchema).optional(),
1081
+ /** Paid backups that turned ready that day, summed per thing backed up (`id` is `<owner>/<kind>:<name>`); absent on a day without any. */
1082
+ backups: z.array(UsageDayItemSchema).optional()
1048
1083
  });
1049
1084
  var UsageReportSchema = z.object({
1050
1085
  window: z.object({ from: z.string(), to: z.string() }),
@@ -1059,6 +1094,8 @@ var UsageReportSchema = z.object({
1059
1094
  storage: z.array(VolumeUsageSchema).optional(),
1060
1095
  /** Cron services (#190, control plane only): one row per service a slug has or had. Absent when there is none. */
1061
1096
  cron: z.array(CronUsageSchema).optional(),
1097
+ /** Paid backups (control plane only): one row per box, volume or service backed up by hand in the window. Absent when there is none. */
1098
+ backups: z.array(BackupUsageSchema).optional(),
1062
1099
  /** With `?by=day` only, oldest day first. */
1063
1100
  days: z.array(UsageDaySchema).optional(),
1064
1101
  totals: z.object({
@@ -1068,7 +1105,7 @@ var UsageReportSchema = z.object({
1068
1105
  diskGibHours: z.number(),
1069
1106
  volumeHours: z.number().optional(),
1070
1107
  volumeGibHours: z.number().optional(),
1071
- /** Boxes, volumes, object storage and cron services together. */
1108
+ /** Boxes, volumes, object storage, cron services and paid backups together. */
1072
1109
  cost: z.object({ amount: z.number(), currency: z.string() }).optional()
1073
1110
  })
1074
1111
  });
@@ -2051,9 +2088,6 @@ var Kvbox = class {
2051
2088
  // src/client.ts
2052
2089
  import { z as z11 } from "zod";
2053
2090
 
2054
- // ../shared/src/managed.ts
2055
- import { z as z8 } from "zod";
2056
-
2057
2091
  // ../shared/src/usage.ts
2058
2092
  import { z as z7 } from "zod";
2059
2093
  var PricingSchema = z7.object({
@@ -2073,7 +2107,12 @@ var PricingSchema = z7.object({
2073
2107
  storageGibHour: z7.number().nonnegative().default(0),
2074
2108
  storageIncludedGib: z7.number().int().nonnegative().default(0),
2075
2109
  /** The cron service (#190): an hour of one cron service existing, whatever it holds or fires. A price list from before it charges nothing. */
2076
- cronHour: z7.number().nonnegative().default(0)
2110
+ cronHour: z7.number().nonnegative().default(0),
2111
+ /**
2112
+ * One backup a person starts, of anything, charged once it is ready (decision "A backup taken by hand
2113
+ * costs a flat price…"); a failed one and a scheduled one cost nothing. A price list from before it charges nothing.
2114
+ */
2115
+ backup: z7.number().nonnegative().default(0)
2077
2116
  });
2078
2117
  var PriceListSchema = PricingSchema.extend({ welcomeCredit: z7.number().nonnegative() });
2079
2118
  var HOUR_MS = 36e5;
@@ -2103,6 +2142,7 @@ function sumUsage(items, pricing) {
2103
2142
  var DAY_MS = 24 * HOUR_MS;
2104
2143
 
2105
2144
  // ../shared/src/managed.ts
2145
+ import { z as z8 } from "zod";
2106
2146
  var PriceSchema = z8.object({ perMonth: z8.number(), storagePerMonth: z8.number(), currency: z8.string() });
2107
2147
  var ManagedCatalogEntrySchema = z8.object({
2108
2148
  /** The kind, as in `/managed/<kind>`: `postgres`. */
@@ -2137,7 +2177,13 @@ var CreateManagedRequest = z8.object({
2137
2177
  password: z8.string().optional(),
2138
2178
  storageGib: z8.number().int().optional(),
2139
2179
  /** Place it on the host of this box, so the box can be linked to it. */
2140
- near: z8.string().optional()
2180
+ near: z8.string().optional(),
2181
+ /**
2182
+ * A backup of a database of the same kind and major version, of the same account (#186): the new
2183
+ * service starts on its data, a removed service's included. Its settings (Postgres: database, user)
2184
+ * are the backup's; the password is the new one.
2185
+ */
2186
+ fromBackup: z8.string().optional()
2141
2187
  });
2142
2188
  var ManagedHealthSchema = z8.object({
2143
2189
  /** Its first start has finished: it has set itself up on its storage. */
@@ -2179,11 +2225,17 @@ var ManagedSchema = z8.object({
2179
2225
  /** Connection strings with the password as `****`. */
2180
2226
  urls: UrlsSchema,
2181
2227
  price: PriceSchema,
2228
+ /** Its nightly backup (#186 slice 4): on from creation, `kvbox <kind> backup schedule` changes it. Null for a control plane from before schedules. */
2229
+ backupSchedule: BackupScheduleSchema.nullable().default(null),
2182
2230
  /** Only in `GET /managed/<kind>/<name>` (asked live): null when it is not running or did not answer. */
2183
2231
  health: ManagedHealthSchema.nullable().optional()
2184
2232
  });
2185
2233
  var ManagedSecretSchema = z8.object({ password: z8.string(), urls: UrlsSchema });
2186
- var CreatedManagedSchema = ManagedSchema.extend({ secret: ManagedSecretSchema });
2234
+ var CreatedManagedSchema = ManagedSchema.extend({
2235
+ secret: ManagedSecretSchema,
2236
+ /** The backup it was made from (`fromBackup`), when it was. */
2237
+ fromBackup: z8.string().optional()
2238
+ });
2187
2239
  var ResetPasswordRequest = z8.object({ password: z8.string().optional() });
2188
2240
  var SetPublicRequest = z8.object({ on: z8.boolean() });
2189
2241
  var ManagedLinkRequest = z8.object({ box: z8.string() });
@@ -2203,7 +2255,10 @@ var ManagedBackupSchema = z8.object({
2203
2255
  dataBytes: z8.number().int().nullable(),
2204
2256
  /** What this backup added to storage (encrypted, compressed): the chunks no earlier backup had. */
2205
2257
  uploadedBytes: z8.number().int().nullable(),
2258
+ /** Who asked for it; for a scheduled one, the database's creator. */
2206
2259
  createdBy: z8.string().nullable(),
2260
+ /** Started by the database's backup schedule, not by a person: it does not count toward the daily limit. */
2261
+ scheduled: z8.boolean().default(false),
2207
2262
  createdAt: z8.string(),
2208
2263
  finishedAt: z8.string().nullable()
2209
2264
  });
@@ -2368,6 +2423,34 @@ var BucketKeySchema = z10.object({
2368
2423
  var CreateBucketKeyRequest = z10.object({ name: z10.string().optional(), readOnly: z10.boolean().optional() });
2369
2424
  var CreatedBucketKeySchema = BucketKeySchema.extend({ secret: z10.string(), endpoint: z10.string().nullable(), region: z10.string() });
2370
2425
  var GrowStorageRequest = z10.object({ sizeGib: z10.number().int() });
2426
+ var StorageBackupSchema = z10.object({
2427
+ id: z10.string(),
2428
+ owner: z10.string(),
2429
+ status: z10.enum(BACKUP_STATUSES),
2430
+ /** Why it failed; null otherwise. */
2431
+ error: z10.string().nullable(),
2432
+ /** The storage's volume when taken. */
2433
+ diskBytes: z10.number().int().nullable(),
2434
+ /** What it holds: the slots that are not all zeros. */
2435
+ dataBytes: z10.number().int().nullable(),
2436
+ /** What this backup added to the backup store (encrypted, compressed). */
2437
+ uploadedBytes: z10.number().int().nullable(),
2438
+ /** The buckets it holds, and how many access keys they had, as kvbox knew them when it was taken. */
2439
+ buckets: z10.array(z10.string()),
2440
+ keys: z10.number().int(),
2441
+ createdBy: z10.string().nullable(),
2442
+ createdAt: z10.string(),
2443
+ finishedAt: z10.string().nullable()
2444
+ });
2445
+ var RestoredKeySchema = z10.object({ bucket: z10.string(), id: z10.string(), name: z10.string() });
2446
+ var StorageRestoreSchema = z10.object({
2447
+ backup: z10.string(),
2448
+ storage: ObjectStorageSchema,
2449
+ buckets: z10.object({ kept: z10.array(z10.string()), returned: z10.array(z10.string()), removed: z10.array(z10.string()) }),
2450
+ keys: z10.object({ dropped: z10.array(RestoredKeySchema), revoked: z10.array(RestoredKeySchema) }),
2451
+ checked: z10.boolean(),
2452
+ warnings: z10.array(z10.string())
2453
+ });
2371
2454
  var OBJECT_LIST_MAX = 1e3;
2372
2455
  var SHARE_LINK_MAX_SEC = 7 * 24 * 3600;
2373
2456
  var UPLOAD_URL_SEC = 12 * 3600;
@@ -2755,6 +2838,10 @@ var ServerClient = class {
2755
2838
  balance(org) {
2756
2839
  return this.call("GET", "/billing/balance", BalanceSchema, void 0, org);
2757
2840
  }
2841
+ /** The control plane's price list (`GET /pricing`); a control plane only. */
2842
+ priceList() {
2843
+ return this.call("GET", "/pricing", PriceListSchema);
2844
+ }
2758
2845
  /** Redeem a promo code (#163) for the caller's slug, or for `--org`'s org, which they own; a control plane only. */
2759
2846
  redeem(code) {
2760
2847
  return this.call("POST", "/billing/redeem", RedeemResponseSchema, { code });
@@ -2876,6 +2963,24 @@ var ServerClient = class {
2876
2963
  growStorage(sizeGib) {
2877
2964
  return this.call("POST", "/storage/grow", ObjectStorageSchema, { sizeGib });
2878
2965
  }
2966
+ /** Backups of the slug's whole object storage (#186 slice 3), newest first. */
2967
+ storageBackups() {
2968
+ return this.call("GET", "/storage/backups", z11.array(StorageBackupSchema));
2969
+ }
2970
+ storageBackup(id) {
2971
+ return this.call("GET", `/storage/backups/${encodeURIComponent(id)}`, StorageBackupSchema);
2972
+ }
2973
+ /** Starts one; it runs in the background (`running`), `storageBackup` says how it ended. */
2974
+ createStorageBackup() {
2975
+ return this.call("POST", "/storage/backups", StorageBackupSchema);
2976
+ }
2977
+ /**
2978
+ * Every bucket and key goes back to the backup's; the storage restarts. Waits for the whole download
2979
+ * (the control plane gives its host 2 h) and for the storage to answer again, so 2 h 10 min.
2980
+ */
2981
+ restoreStorageBackup(id) {
2982
+ return this.call("POST", `/storage/backups/${encodeURIComponent(id)}/restore`, StorageRestoreSchema, {}, void 0, 2 * 36e5 + 10 * 6e4);
2983
+ }
2879
2984
  // ---- managed services (#173): the control plane's alone ----
2880
2985
  managedPath(kind, name, rest = "") {
2881
2986
  return `/managed/${encodeURIComponent(kind)}${name === void 0 ? "" : `/${encodeURIComponent(name)}`}${rest}`;
@@ -2887,8 +2992,9 @@ var ServerClient = class {
2887
2992
  listManaged(kind, opts = {}) {
2888
2993
  return this.call("GET", `${kind === void 0 ? "/managed" : this.managedPath(kind)}${allQuery(opts)}`, z11.array(ManagedSchema), void 0, opts.org);
2889
2994
  }
2995
+ /** From a backup (`fromBackup`) it waits for the restore too: the control plane gives its host 2 h for the download. */
2890
2996
  createManaged(kind, req) {
2891
- return this.call("POST", this.managedPath(kind), CreatedManagedSchema, req);
2997
+ return this.call("POST", this.managedPath(kind), CreatedManagedSchema, req, void 0, req.fromBackup === void 0 ? void 0 : 2 * 36e5 + 10 * 6e4);
2892
2998
  }
2893
2999
  /** With `health`, asked of the service itself. */
2894
3000
  getManaged(kind, name) {
@@ -2925,6 +3031,14 @@ var ServerClient = class {
2925
3031
  managedBackup(kind, name, id) {
2926
3032
  return this.call("GET", this.managedPath(kind, name, `/backups/${encodeURIComponent(id)}`), ManagedBackupSchema);
2927
3033
  }
3034
+ /** When the service is backed up on its own (#186 slice 4): nightly from its creation. */
3035
+ managedBackupSchedule(kind, name) {
3036
+ return this.call("GET", this.managedPath(kind, name, "/backup-schedule"), BackupScheduleSchema);
3037
+ }
3038
+ /** On or off, or another hour (UTC, which turns it on). */
3039
+ setManagedBackupSchedule(kind, name, change) {
3040
+ return this.call("PUT", this.managedPath(kind, name, "/backup-schedule"), BackupScheduleSchema, change);
3041
+ }
2928
3042
  /** Starts one; it runs in the background (`running`), `managedBackup` says how it ended. */
2929
3043
  createManagedBackup(kind, name) {
2930
3044
  return this.call("POST", this.managedPath(kind, name, "/backups"), ManagedBackupSchema);
@@ -3615,25 +3729,25 @@ async function runSsh(ssh, opts) {
3615
3729
  }).finally(() => clearTimeout(timer));
3616
3730
  return { status: status2, chunks, timedOut };
3617
3731
  }
3618
- 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) => {
3619
- const client = await clientFor(cmd.optsWithGlobals());
3620
- let ep;
3621
- let cert;
3622
- let owner;
3732
+ async function reachBox(globals, name, direct) {
3733
+ const client = await clientFor(globals);
3623
3734
  try {
3624
3735
  let box2 = pickRef(await boxesFor(client, name), name, me(client));
3625
3736
  if (!box2) throw new KvboxError(`box ${name}: not found (kvbox ls)`);
3626
3737
  if (box2.status === "stopped") throw new KvboxError(`box ${name} is stopped (kvbox start ${name})`);
3627
- cert = await ensureCert(client, void 0, void 0, { owner: box2.owner });
3628
- owner = box2.owner;
3738
+ const cert = await ensureCert(client, void 0, void 0, { owner: box2.owner });
3629
3739
  const wasRunning = box2.status === "running";
3630
3740
  if (!wasRunning) box2 = await wakeUp(client, box2, displayName(box2, me(client)));
3631
- ep = sshEndpoint(box2, client.target, opts.direct);
3741
+ const ep = sshEndpoint(box2, client.target, direct);
3632
3742
  if (!wasRunning) await spin(`waiting for ${name} to accept SSH\u2026`, waitForSsh(ep));
3633
- else if (opts.direct) await checkDirect(ep);
3743
+ else if (direct) await checkDirect(ep);
3744
+ return { ep, cert, owner: box2.owner };
3634
3745
  } finally {
3635
3746
  await client.close();
3636
3747
  }
3748
+ }
3749
+ 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) => {
3750
+ const { ep, cert, owner } = await reachBox(cmd.optsWithGlobals(), name, opts.direct);
3637
3751
  const remote = remoteCommand(cmdArgs, opts.env ?? []);
3638
3752
  const stdinIsTty = process.stdin.isTTY === true;
3639
3753
  const ssh = [
@@ -3664,9 +3778,66 @@ var execCommand = new Command3("exec").description("run a command in a box and e
3664
3778
  process.exit(status2);
3665
3779
  });
3666
3780
 
3781
+ // src/commands/vm/cp.ts
3782
+ import { spawn as spawn3 } from "child_process";
3783
+ import { Command as Command4 } from "commander";
3784
+ function parseSide(arg, platform = process.platform) {
3785
+ if (platform === "win32" && /^[A-Za-z]:[\\/]/.test(arg)) return { box: void 0, path: arg };
3786
+ const m = /^([^/:\\]+(?:\/[^/:\\]+)?):(.*)$/s.exec(arg);
3787
+ if (!m || arg.startsWith("./") || arg.startsWith("../")) return { box: void 0, path: arg };
3788
+ return { box: m[1], path: m[2] };
3789
+ }
3790
+ function parseCopy(src, dest, platform = process.platform) {
3791
+ const from = parseSide(src, platform);
3792
+ const to = parseSide(dest, platform);
3793
+ if (from.box !== void 0 && to.box !== void 0) {
3794
+ throw new KvboxError("both sides are in a box: copy between this machine and one box (kvbox cp <file> <box>:<path>)");
3795
+ }
3796
+ const box2 = from.box ?? to.box;
3797
+ if (box2 === void 0) {
3798
+ throw new KvboxError("neither side is in a box: write the box side as <box>:<path> (kvbox cp ./app.apk dev:app.apk)");
3799
+ }
3800
+ return { box: box2, from, to };
3801
+ }
3802
+ function scpArgs(ep, from, to, recursive) {
3803
+ const ssh = sshArgs(ep);
3804
+ const options = ssh.slice(0, -1).map((a) => a === "-p" ? "-P" : a);
3805
+ const host = ep.host.includes(":") ? `[${ep.host}]` : ep.host;
3806
+ const side = (s) => s.box === void 0 ? s.path : `${ep.user}@${host}:${s.path === "" ? "." : s.path}`;
3807
+ return [...recursive ? ["-r"] : [], ...options, side(from), side(to)];
3808
+ }
3809
+ async function runScp(args) {
3810
+ const child = spawn3("scp", args, { stdio: ["inherit", "inherit", "pipe"] });
3811
+ let refused = false;
3812
+ child.stderr?.on("data", (c2) => {
3813
+ process.stderr.write(c2);
3814
+ if (c2.toString("utf8").includes("Permission denied")) refused = true;
3815
+ });
3816
+ const status2 = await new Promise((resolve4, reject) => {
3817
+ child.once("error", (err) => reject(new KvboxError(`could not run scp: ${err.message}`)));
3818
+ child.once("close", (code, signal) => resolve4(code ?? (signal === "SIGINT" ? 130 : 1)));
3819
+ });
3820
+ return { status: status2, refused };
3821
+ }
3822
+ var cpCommand = new Command4("cp").description("copy files between this machine and a box (kvbox cp ./f <box>:f, kvbox cp <box>:f .)").argument("<src>", "a local path, or <box>:<path>").argument("<dest>", "a local path, or <box>:<path>").option("-r, --recursive", "copy directories").option("--direct", "on the box's host: ssh to the box's private ip, not through the public address or relay").action(async (src, dest, opts, cmd) => {
3823
+ const { box: box2, from, to } = parseCopy(src, dest);
3824
+ const { ep, cert, owner } = await reachBox(cmd.optsWithGlobals(), box2, opts.direct);
3825
+ const args = scpArgs(ep, from, to, opts.recursive === true);
3826
+ const first = await runScp(args);
3827
+ let status2 = first.status;
3828
+ if (status2 !== 0 && first.refused) {
3829
+ const again = await clientFor(cmd.optsWithGlobals());
3830
+ if (await renewAfterRefusal(again, cert, owner).finally(() => again.close())) {
3831
+ info("renewed your SSH certificate, trying again\u2026");
3832
+ ({ status: status2 } = await runScp(args));
3833
+ }
3834
+ }
3835
+ if (status2 !== 0) process.exit(status2);
3836
+ });
3837
+
3667
3838
  // src/commands/vm/fork.ts
3668
- import { Command as Command4, Option as Option2 } from "commander";
3669
- var forkCommand = new Command4("fork").description("copy a box, running or stopped, into a new one on the same host (--org: into an org)").argument("<box>", "the box to copy").argument("[name]", "the copy's name (box1, box2, \u2026 when omitted)").addOption(new Option2("-s, --size <size>", "the copy's size, for a stopped box only (default: the box's)").choices(SIZE_NAMES)).option("--auto-hibernate <duration>", "hibernate the copy after this long without network traffic (30m, 4h, 1d; off: never; default: the box's)").option("--force", "skip the capacity guard").option("--json", "print the new box as JSON").action(async (source, name, opts, cmd) => {
3839
+ import { Command as Command5, Option as Option2 } from "commander";
3840
+ var forkCommand = new Command5("fork").description("copy a box, running or stopped, into a new one on the same host (--org: into an org)").argument("<box>", "the box to copy").argument("[name]", "the copy's name (box1, box2, \u2026 when omitted)").addOption(new Option2("-s, --size <size>", "the copy's size, for a stopped box only (default: the box's)").choices(SIZE_NAMES)).option("--auto-hibernate <duration>", "hibernate the copy after this long without network traffic (30m, 4h, 1d; off: never; default: the box's)").option("--force", "skip the capacity guard").option("--json", "print the new box as JSON").action(async (source, name, opts, cmd) => {
3670
3841
  const autoHibernateSec = opts.autoHibernate === void 0 ? void 0 : parseIdleTimeout(opts.autoHibernate);
3671
3842
  const client = await clientFor(cmd.optsWithGlobals());
3672
3843
  try {
@@ -3692,10 +3863,10 @@ var forkCommand = new Command4("fork").description("copy a box, running or stopp
3692
3863
  });
3693
3864
 
3694
3865
  // src/commands/vm/get.ts
3695
- import { Command as Command6 } from "commander";
3866
+ import { Command as Command7 } from "commander";
3696
3867
 
3697
3868
  // src/commands/vm/ls.ts
3698
- import { Command as Command5 } from "commander";
3869
+ import { Command as Command6 } from "commander";
3699
3870
  function ownerCell(b, me2) {
3700
3871
  const slug = slugOf(b.owner);
3701
3872
  if (slug === me2) return "private";
@@ -3705,7 +3876,7 @@ function addressOf(b) {
3705
3876
  if (b.ssh !== void 0) return b.ssh.host;
3706
3877
  return b.ip === "" ? "-" : b.ip;
3707
3878
  }
3708
- var lsCommand = new Command5("ls").description("list boxes with status and address (yours and your orgs'; --org <slug> for one org)").option("-a, --all", "every box on the platform (platform admins only)").option("--json", "print as JSON").action(async (opts, cmd) => {
3879
+ var lsCommand = new Command6("ls").description("list boxes with status and address (yours and your orgs'; --org <slug> for one org)").option("-a, --all", "every box on the platform (platform admins only)").option("--json", "print as JSON").action(async (opts, cmd) => {
3709
3880
  const client = await clientFor(cmd.optsWithGlobals());
3710
3881
  try {
3711
3882
  const cloud = client.target.kind === "cloud";
@@ -3777,7 +3948,7 @@ async function findBox(client, text2) {
3777
3948
  }
3778
3949
 
3779
3950
  // src/commands/vm/get.ts
3780
- var getCommand = new Command6("get").description("show one box in full: status, size, address, HTTPS name, ports, auto-hibernate").argument("<name>", "box name").option("--json", "print the box as JSON").action(async (name, opts, cmd) => {
3951
+ var getCommand = new Command7("get").description("show one box in full: status, size, address, HTTPS name, ports, auto-hibernate").argument("<name>", "box name").option("--json", "print the box as JSON").action(async (name, opts, cmd) => {
3781
3952
  const client = await clientFor(cmd.optsWithGlobals());
3782
3953
  try {
3783
3954
  const user = me(client);
@@ -3830,8 +4001,8 @@ function getRows(box2, subs, user) {
3830
4001
  }
3831
4002
 
3832
4003
  // src/commands/vm/hibernate.ts
3833
- import { Command as Command7 } from "commander";
3834
- var hibernateCommand = new Command7("hibernate").description("save a box's memory to disk and free its RAM (kvbox wake continues it where it left off)").argument("<name>", "box name").option("--json", "print the box as JSON").action(async (name, opts, cmd) => {
4004
+ import { Command as Command8 } from "commander";
4005
+ var hibernateCommand = new Command8("hibernate").description("save a box's memory to disk and free its RAM (kvbox wake continues it where it left off)").argument("<name>", "box name").option("--json", "print the box as JSON").action(async (name, opts, cmd) => {
3835
4006
  const client = await clientFor(cmd.optsWithGlobals());
3836
4007
  try {
3837
4008
  const box2 = await spin(`hibernating ${name} (saving its memory to disk)\u2026`, client.hibernateMachine(name));
@@ -3843,13 +4014,13 @@ var hibernateCommand = new Command7("hibernate").description("save a box's memor
3843
4014
  });
3844
4015
 
3845
4016
  // src/commands/vm/link.ts
3846
- import { Command as Command8 } from "commander";
4017
+ import { Command as Command9 } from "commander";
3847
4018
  function parseLinkPort(text2) {
3848
4019
  const port = Number(text2);
3849
4020
  if (!Number.isInteger(port) || port < 1 || port > 65535) throw new KvboxError(`--port: expected a port from 1 to 65535, got "${text2}"`);
3850
4021
  return port;
3851
4022
  }
3852
- 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) => {
4023
+ var linkCommand = new Command9("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) => {
3853
4024
  const port = parseLinkPort(opts.port);
3854
4025
  const client = await clientFor(cmd.optsWithGlobals());
3855
4026
  try {
@@ -3872,8 +4043,8 @@ var linkCommand = new Command8("link").description("let one box reach a port of
3872
4043
  });
3873
4044
 
3874
4045
  // src/commands/vm/links.ts
3875
- import { Command as Command9 } from "commander";
3876
- 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) => {
4046
+ import { Command as Command10 } from "commander";
4047
+ var linksCommand = new Command10("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) => {
3877
4048
  const client = await clientFor(cmd.optsWithGlobals());
3878
4049
  try {
3879
4050
  const user = me(client);
@@ -3906,8 +4077,8 @@ var linksCommand = new Command9("links").description("list the links between box
3906
4077
  });
3907
4078
 
3908
4079
  // src/commands/vm/pause.ts
3909
- import { Command as Command10 } from "commander";
3910
- 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) => {
4080
+ import { Command as Command11 } from "commander";
4081
+ var pauseCommand = new Command11("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) => {
3911
4082
  const client = await clientFor(cmd.optsWithGlobals());
3912
4083
  try {
3913
4084
  const box2 = await spin(`pausing ${name}\u2026`, client.pauseMachine(name));
@@ -3919,7 +4090,7 @@ var pauseCommand = new Command10("pause").description("freeze a box in place (me
3919
4090
  });
3920
4091
 
3921
4092
  // src/commands/vm/proxy/claim.ts
3922
- import { Command as Command11 } from "commander";
4093
+ import { Command as Command12 } from "commander";
3923
4094
 
3924
4095
  // ../shared/src/names.ts
3925
4096
  import { createHmac } from "crypto";
@@ -3990,7 +4161,7 @@ function assertDomain(text2, proxyDomain) {
3990
4161
  }
3991
4162
 
3992
4163
  // src/commands/vm/proxy/claim.ts
3993
- var claimCommand = new Command11("claim").description(`give a box an HTTPS address, https://<subdomain>.kvbox.app, serving one of its ports (up to ${MAX_BOX_SUBDOMAINS} per box)`).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) => {
4164
+ var claimCommand = new Command12("claim").description(`give a box an HTTPS address, https://<subdomain>.kvbox.app, serving one of its ports (up to ${MAX_BOX_SUBDOMAINS} per box)`).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) => {
3994
4165
  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>");
3995
4166
  if (subArg !== void 0) assertSubdomain(subArg);
3996
4167
  if (opts.port !== void 0) parsePorts([opts.port]);
@@ -4019,11 +4190,11 @@ var claimCommand = new Command11("claim").description(`give a box an HTTPS addre
4019
4190
  });
4020
4191
 
4021
4192
  // src/commands/vm/proxy/index.ts
4022
- import { Command as Command17 } from "commander";
4193
+ import { Command as Command18 } from "commander";
4023
4194
 
4024
4195
  // src/commands/vm/proxy/add.ts
4025
- import { Command as Command12 } from "commander";
4026
- 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("--sub <subdomain>", "with --name: which of the box's subdomains it goes under (needed when it has more than one)").option("--json", "print the new forwards as JSON").action(async (name, portTexts, opts, cmd) => {
4196
+ import { Command as Command13 } from "commander";
4197
+ var addCommand = new Command13("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("--sub <subdomain>", "with --name: which of the box's subdomains it goes under (needed when it has more than one)").option("--json", "print the new forwards as JSON").action(async (name, portTexts, opts, cmd) => {
4027
4198
  const guestPorts = parsePorts(portTexts);
4028
4199
  if (opts.name !== void 0) {
4029
4200
  assertRouteName(opts.name);
@@ -4066,7 +4237,7 @@ var addCommand = new Command12("add").description("publish box ports on the inte
4066
4237
  });
4067
4238
 
4068
4239
  // src/commands/vm/proxy/ls.ts
4069
- import { Command as Command13 } from "commander";
4240
+ import { Command as Command14 } from "commander";
4070
4241
  async function subdomainsOf2(client) {
4071
4242
  try {
4072
4243
  return await client.listSubdomains();
@@ -4075,7 +4246,7 @@ async function subdomainsOf2(client) {
4075
4246
  return [];
4076
4247
  }
4077
4248
  }
4078
- 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) => {
4249
+ var lsCommand2 = new Command14("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) => {
4079
4250
  const client = await clientFor(cmd.optsWithGlobals());
4080
4251
  try {
4081
4252
  const user = me(client);
@@ -4101,8 +4272,8 @@ var lsCommand2 = new Command13("ls").description("list the box ports published o
4101
4272
  });
4102
4273
 
4103
4274
  // src/commands/vm/proxy/release.ts
4104
- import { Command as Command14 } from "commander";
4105
- var releaseCommand = new Command14("release").description("give up one of a box's HTTPS addresses and every name under it").argument("<box>", "box name").option("--sub <subdomain>", "which of the box's subdomains (needed when it has more than one)").option("-y, --yes", "do not ask for confirmation").action(async (name, opts, cmd) => {
4275
+ import { Command as Command15 } from "commander";
4276
+ var releaseCommand = new Command15("release").description("give up one of a box's HTTPS addresses and every name under it").argument("<box>", "box name").option("--sub <subdomain>", "which of the box's subdomains (needed when it has more than one)").option("-y, --yes", "do not ask for confirmation").action(async (name, opts, cmd) => {
4106
4277
  const client = await clientFor(cmd.optsWithGlobals());
4107
4278
  try {
4108
4279
  requireCloud(client);
@@ -4121,8 +4292,8 @@ var releaseCommand = new Command14("release").description("give up one of a box'
4121
4292
  });
4122
4293
 
4123
4294
  // src/commands/vm/proxy/rm.ts
4124
- import { Command as Command15 } from "commander";
4125
- 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("--sub <subdomain>", "with --name: which of the box's subdomains the name is under (needed when it has more than one)").option("-y, --yes", "do not ask for confirmation").action(async (name, portTexts, opts, cmd) => {
4295
+ import { Command as Command16 } from "commander";
4296
+ var rmCommand = new Command16("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("--sub <subdomain>", "with --name: which of the box's subdomains the name is under (needed when it has more than one)").option("-y, --yes", "do not ask for confirmation").action(async (name, portTexts, opts, cmd) => {
4126
4297
  if (opts.name !== void 0) {
4127
4298
  assertRouteName(opts.name);
4128
4299
  if (portTexts.length > 0) throw new KvboxError("--name frees a name, not ports: kvbox vm proxy rm <box> --name <name>");
@@ -4156,8 +4327,8 @@ var rmCommand = new Command15("rm").description("stop publishing box ports, or a
4156
4327
  });
4157
4328
 
4158
4329
  // src/commands/vm/proxy/set-port.ts
4159
- import { Command as Command16 } from "commander";
4160
- 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("--sub <subdomain>", "which of the box's subdomains (needed when it has more than one)").option("--json", "print the subdomain as JSON").action(async (name, portText, opts, cmd) => {
4330
+ import { Command as Command17 } from "commander";
4331
+ var setPortCommand = new Command17("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("--sub <subdomain>", "which of the box's subdomains (needed when it has more than one)").option("--json", "print the subdomain as JSON").action(async (name, portText, opts, cmd) => {
4161
4332
  const [port] = parsePorts([portText]);
4162
4333
  const client = await clientFor(cmd.optsWithGlobals());
4163
4334
  try {
@@ -4175,14 +4346,14 @@ var setPortCommand = new Command16("set-port").description("point a box's HTTPS
4175
4346
  });
4176
4347
 
4177
4348
  // src/commands/vm/proxy/index.ts
4178
- var proxyCommand = new Command17("proxy").description("publish box ports on the internet").addCommand(addCommand).addCommand(lsCommand2).addCommand(rmCommand).addCommand(claimCommand).addCommand(setPortCommand).addCommand(releaseCommand);
4349
+ var proxyCommand = new Command18("proxy").description("publish box ports on the internet").addCommand(addCommand).addCommand(lsCommand2).addCommand(rmCommand).addCommand(claimCommand).addCommand(setPortCommand).addCommand(releaseCommand);
4179
4350
  for (const cmd of proxyCommand.commands) cmd.option("--org <slug>", "act in this org (- for your personal boxes)");
4180
4351
 
4181
4352
  // src/commands/vm/hook/index.ts
4182
- import { Command as Command21 } from "commander";
4353
+ import { Command as Command22 } from "commander";
4183
4354
 
4184
4355
  // src/commands/vm/hook/create.ts
4185
- import { Command as Command18 } from "commander";
4356
+ import { Command as Command19 } from "commander";
4186
4357
 
4187
4358
  // src/commands/vm/hook/shared.ts
4188
4359
  function requireCloud2(client) {
@@ -4190,7 +4361,7 @@ function requireCloud2(client) {
4190
4361
  }
4191
4362
 
4192
4363
  // src/commands/vm/hook/create.ts
4193
- var createCommand = new Command18("create").description("make a URL that wakes the box when called (a GitHub webhook, cron, any automation)").argument("<box>", "box name").option("--json", "print as JSON").action(async (name, opts, cmd) => {
4364
+ var createCommand = new Command19("create").description("make a URL that wakes the box when called (a GitHub webhook, cron, any automation)").argument("<box>", "box name").option("--json", "print as JSON").action(async (name, opts, cmd) => {
4194
4365
  const client = await clientFor(cmd.optsWithGlobals(), { autoStart: false });
4195
4366
  try {
4196
4367
  requireCloud2(client);
@@ -4214,8 +4385,8 @@ var createCommand = new Command18("create").description("make a URL that wakes t
4214
4385
  });
4215
4386
 
4216
4387
  // src/commands/vm/hook/ls.ts
4217
- import { Command as Command19 } from "commander";
4218
- var lsCommand3 = new Command19("ls").alias("list").description("list a box's wake hooks").argument("<box>", "box name").option("--json", "print as JSON").action(async (name, opts, cmd) => {
4388
+ import { Command as Command20 } from "commander";
4389
+ var lsCommand3 = new Command20("ls").alias("list").description("list a box's wake hooks").argument("<box>", "box name").option("--json", "print as JSON").action(async (name, opts, cmd) => {
4219
4390
  const client = await clientFor(cmd.optsWithGlobals(), { autoStart: false });
4220
4391
  try {
4221
4392
  requireCloud2(client);
@@ -4236,8 +4407,8 @@ var lsCommand3 = new Command19("ls").alias("list").description("list a box's wak
4236
4407
  });
4237
4408
 
4238
4409
  // src/commands/vm/hook/rm.ts
4239
- import { Command as Command20 } from "commander";
4240
- var rmCommand2 = new Command20("rm").alias("remove").description("remove a wake hook: its URL stops working").argument("<box>", "box name").argument("<id>", "the hook's id (kvbox vm hook ls <box>)").option("-y, --yes", "do not ask for confirmation").option("--json", "print the removed hook as JSON").action(async (name, id, opts, cmd) => {
4410
+ import { Command as Command21 } from "commander";
4411
+ var rmCommand2 = new Command21("rm").alias("remove").description("remove a wake hook: its URL stops working").argument("<box>", "box name").argument("<id>", "the hook's id (kvbox vm hook ls <box>)").option("-y, --yes", "do not ask for confirmation").option("--json", "print the removed hook as JSON").action(async (name, id, opts, cmd) => {
4241
4412
  const client = await clientFor(cmd.optsWithGlobals(), { autoStart: false });
4242
4413
  try {
4243
4414
  requireCloud2(client);
@@ -4259,23 +4430,80 @@ var rmCommand2 = new Command20("rm").alias("remove").description("remove a wake
4259
4430
  });
4260
4431
 
4261
4432
  // src/commands/vm/hook/index.ts
4262
- var hookCommand = new Command21("hook").description("URLs that wake a box when called (GitHub webhooks, cron, any automation)").addCommand(createCommand).addCommand(lsCommand3).addCommand(rmCommand2);
4433
+ var hookCommand = new Command22("hook").description("URLs that wake a box when called (GitHub webhooks, cron, any automation)").addCommand(createCommand).addCommand(lsCommand3).addCommand(rmCommand2);
4263
4434
  for (const cmd of hookCommand.commands) cmd.option("--org <slug>", "act in this org (- for your personal boxes)");
4264
4435
 
4265
4436
  // src/commands/vm/backup/index.ts
4266
- import { Command as Command26 } from "commander";
4437
+ import { Command as Command28 } from "commander";
4267
4438
 
4268
4439
  // src/commands/vm/backup/create.ts
4269
- import { Command as Command22 } from "commander";
4440
+ import { Command as Command24 } from "commander";
4270
4441
 
4271
4442
  // src/commands/vm/backup/shared.ts
4272
4443
  import { setTimeout as sleep3 } from "timers/promises";
4444
+
4445
+ // src/commands/vm/usage.ts
4446
+ import { Command as Command23 } from "commander";
4447
+ var usageCommand = new Command23("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) => {
4448
+ let since;
4449
+ if (opts.since !== void 0) {
4450
+ const t = Date.parse(opts.since);
4451
+ if (Number.isNaN(t)) throw new KvboxError(`--since ${opts.since}: not a date; write it like 2026-10-19 or 2026-10-19T08:00:00Z`);
4452
+ since = new Date(t).toISOString();
4453
+ }
4454
+ const client = await clientFor(cmd.optsWithGlobals());
4455
+ try {
4456
+ const u = await client.machineUsage(name, since);
4457
+ if (opts.json) json(u);
4458
+ else process.stdout.write(block(u));
4459
+ } finally {
4460
+ await client.close();
4461
+ }
4462
+ });
4463
+ var day = (iso) => iso.slice(0, 10);
4464
+ var SYMBOLS = { EUR: "\u20AC", USD: "$", GBP: "\xA3" };
4465
+ function money(amount, currency) {
4466
+ const sign = amount < 0 ? "-" : "";
4467
+ const n = Math.abs(amount).toFixed(2);
4468
+ const sym = SYMBOLS[currency.toUpperCase()];
4469
+ return sym === void 0 ? `${sign}${n} ${currency}` : `${sign}${sym}${n}`;
4470
+ }
4471
+ function block(u) {
4472
+ const estimated = u.estimatedStops === 0 ? "" : color.dim(` (${u.estimatedStops} stop time${u.estimatedStops === 1 ? "" : "s"} estimated)`);
4473
+ const rows2 = [
4474
+ ["name", boxName(u.name)],
4475
+ ["status", status(u.status)],
4476
+ ["window", `${day(u.window.from)} to ${day(u.window.to)}`],
4477
+ ["running", duration(u.seconds.running) + estimated],
4478
+ ["standby", duration(u.seconds.standby)],
4479
+ ["hibernated", duration(u.seconds.hibernated)],
4480
+ ["stopped", duration(u.seconds.stopped)],
4481
+ ["vcpu-h", hours(u.vcpuHours)],
4482
+ ["ram GiB-h", hours(u.ramGibHours)],
4483
+ ["disk GiB-h", hours(u.diskGibHours)]
4484
+ ];
4485
+ if (u.cost !== void 0) rows2.push(["cost", `${money(u.cost.amount, u.cost.currency)} ${color.dim("(estimated)")}`]);
4486
+ if (u.historyFrom !== null && u.historyFrom > u.window.from) {
4487
+ rows2.push(["history", color.dim(`from ${u.historyFrom.slice(0, 16).replace("T", " ")} UTC; the box is older, but its time before that was not recorded`)]);
4488
+ }
4489
+ const w = Math.max(...rows2.map(([k]) => k.length));
4490
+ return rows2.map(([k, v]) => `${" ".repeat(w - k.length)}${k}: ${v}`).join("\n") + "\n";
4491
+ }
4492
+
4493
+ // src/commands/vm/backup/shared.ts
4273
4494
  function requireCloud3(client) {
4274
4495
  if (client.target.kind !== "cloud") throw new KvboxError("backups need the kvbox cloud: kvbox login (this host's own socket has none)");
4275
4496
  }
4276
4497
  var POLL_MS = 2e3;
4277
4498
  var POLL_TRIES = 30;
4278
4499
  var WAIT_MS = 7 * 36e5;
4500
+ async function printCost(client, done, nightly = false) {
4501
+ const prices = await client.priceList().catch(() => void 0);
4502
+ if (!prices || prices.backup <= 0) return;
4503
+ const price = money(prices.backup, prices.currency);
4504
+ const included = nightly ? "; the nightly backup is included" : "";
4505
+ info(color.dim(done ? ` cost: ${price}${included}` : ` costs ${price} once it is ready, nothing if it fails${included}`));
4506
+ }
4279
4507
  async function untilSettled(ask, what, id, where, opts = {}) {
4280
4508
  const { pollMs = POLL_MS, tries = POLL_TRIES, waitMs = WAIT_MS } = opts;
4281
4509
  const lostTrack = (why) => new KvboxError(`stopped waiting for backup ${id} of ${what} (${why}); it may still be running: ${where}`);
@@ -4316,7 +4544,7 @@ async function removeListed(client, listed, nameOf, name, id, what, yes) {
4316
4544
  }
4317
4545
 
4318
4546
  // src/commands/vm/backup/create.ts
4319
- var createCommand2 = new Command22("create").description("back up a box's disk to the kvbox cloud (encrypted; memory and volumes not included)").argument("<box>", "box name").option("--wait", "stay until the backup is ready (by default it runs in the background)").option("--json", "print the backup as JSON").action(async (name, opts, cmd) => {
4547
+ var createCommand2 = new Command24("create").description("back up a box's disk to the kvbox cloud (encrypted; memory and volumes not included)").argument("<box>", "box name").option("--wait", "stay until the backup is ready (by default it runs in the background)").option("--json", "print the backup as JSON").action(async (name, opts, cmd) => {
4320
4548
  const client = await clientFor(cmd.optsWithGlobals(), { autoStart: false });
4321
4549
  try {
4322
4550
  requireCloud3(client);
@@ -4328,6 +4556,7 @@ var createCommand2 = new Command22("create").description("back up a box's disk t
4328
4556
  else {
4329
4557
  info(`${color.green("\u2713")} backup ${started.id} of box ${color.bold(box2)} started; it runs in the background`);
4330
4558
  info(color.dim(` status: kvbox vm backup ls ${box2}`));
4559
+ await printCost(client, false);
4331
4560
  }
4332
4561
  return;
4333
4562
  }
@@ -4338,14 +4567,15 @@ var createCommand2 = new Command22("create").description("back up a box's disk t
4338
4567
  info(`${color.green("\u2713")} backup ${done.id} of box ${color.bold(box2)}: ${sizeLine(done)}`);
4339
4568
  if ((found.volumes?.length ?? 0) > 0) info(color.dim(` not included: volume${found.volumes.length > 1 ? "s" : ""} ${found.volumes.map((v) => v.name).join(", ")}`));
4340
4569
  info(color.dim(` restore with: kvbox vm backup restore ${box2} ${done.id}`));
4570
+ await printCost(client, true);
4341
4571
  } finally {
4342
4572
  await client.close();
4343
4573
  }
4344
4574
  });
4345
4575
 
4346
4576
  // src/commands/vm/backup/ls.ts
4347
- import { Command as Command23 } from "commander";
4348
- var lsCommand4 = new Command23("ls").alias("list").description("list backups: every box's, or one box's").argument("[box]", "box name (default: every box)").option("--json", "print as JSON").action(async (name, opts, cmd) => {
4577
+ import { Command as Command25 } from "commander";
4578
+ var lsCommand4 = new Command25("ls").alias("list").description("list backups: every box's, or one box's").argument("[box]", "box name (default: every box)").option("--json", "print as JSON").action(async (name, opts, cmd) => {
4349
4579
  const client = await clientFor(cmd.optsWithGlobals(), { autoStart: false });
4350
4580
  try {
4351
4581
  requireCloud3(client);
@@ -4379,8 +4609,8 @@ var lsCommand4 = new Command23("ls").alias("list").description("list backups: ev
4379
4609
  });
4380
4610
 
4381
4611
  // src/commands/vm/backup/restore.ts
4382
- import { Command as Command24 } from "commander";
4383
- var restoreCommand = new Command24("restore").description("put a backup back: the box's disk becomes the backup's (a running box restarts)").argument("<box>", "box name").argument("<id>", "the backup's id (kvbox vm backup ls <box>)").option("-y, --yes", "do not ask for confirmation").option("--json", "print the box as JSON").action(async (name, id, opts, cmd) => {
4612
+ import { Command as Command26 } from "commander";
4613
+ var restoreCommand = new Command26("restore").description("put a backup back: the box's disk becomes the backup's (a running box restarts)").argument("<box>", "box name").argument("<id>", "the backup's id (kvbox vm backup ls <box>)").option("-y, --yes", "do not ask for confirmation").option("--json", "print the box as JSON").action(async (name, id, opts, cmd) => {
4384
4614
  const client = await clientFor(cmd.optsWithGlobals(), { autoStart: false });
4385
4615
  try {
4386
4616
  requireCloud3(client);
@@ -4404,8 +4634,8 @@ var restoreCommand = new Command24("restore").description("put a backup back: th
4404
4634
  });
4405
4635
 
4406
4636
  // src/commands/vm/backup/rm.ts
4407
- import { Command as Command25 } from "commander";
4408
- var rmCommand3 = new Command25("rm").alias("remove").description("remove a backup for good (a box's that is gone too)").argument("<box>", "box name").argument("<id>", "the backup's id (kvbox vm backup ls <box>)").option("-y, --yes", "do not ask for confirmation").action(async (box2, id, opts, cmd) => {
4637
+ import { Command as Command27 } from "commander";
4638
+ var rmCommand3 = new Command27("rm").alias("remove").description("remove a backup for good (a box's that is gone too)").argument("<box>", "box name").argument("<id>", "the backup's id (kvbox vm backup ls <box>)").option("-y, --yes", "do not ask for confirmation").action(async (box2, id, opts, cmd) => {
4409
4639
  const client = await clientFor(cmd.optsWithGlobals(), { autoStart: false });
4410
4640
  try {
4411
4641
  requireCloud3(client);
@@ -4416,12 +4646,12 @@ var rmCommand3 = new Command25("rm").alias("remove").description("remove a backu
4416
4646
  });
4417
4647
 
4418
4648
  // src/commands/vm/backup/index.ts
4419
- var backupCommand = new Command26("backup").description("back up a box's disk to the kvbox cloud, list backups, restore or remove one").addCommand(createCommand2).addCommand(lsCommand4).addCommand(restoreCommand).addCommand(rmCommand3);
4649
+ var backupCommand = new Command28("backup").description("back up a box's disk to the kvbox cloud, list backups, restore or remove one").addCommand(createCommand2).addCommand(lsCommand4).addCommand(restoreCommand).addCommand(rmCommand3);
4420
4650
  for (const cmd of backupCommand.commands) cmd.option("--org <slug>", "act in this org (- for your personal boxes)");
4421
4651
 
4422
4652
  // src/commands/vm/rescale.ts
4423
- import { Command as Command27, Option as Option3 } from "commander";
4424
- var rescaleCommand = new Command27("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("--force", "skip the capacity guard when a running box grows").option("--json", "print the box as JSON").action(async (name, opts, cmd) => {
4653
+ import { Command as Command29, Option as Option3 } from "commander";
4654
+ var rescaleCommand = new Command29("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("--force", "skip the capacity guard when a running box grows").option("--json", "print the box as JSON").action(async (name, opts, cmd) => {
4425
4655
  const req = {
4426
4656
  ...opts.size !== void 0 ? { size: opts.size } : {},
4427
4657
  ...opts.vcpu !== void 0 ? { vcpu: parseCount(opts.vcpu) } : {},
@@ -4467,8 +4697,8 @@ function parseGib(flag, text2) {
4467
4697
  }
4468
4698
 
4469
4699
  // src/commands/vm/resume.ts
4470
- import { Command as Command28 } from "commander";
4471
- var resumeCommand = new Command28("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) => {
4700
+ import { Command as Command30 } from "commander";
4701
+ var resumeCommand = new Command30("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) => {
4472
4702
  const client = await clientFor(cmd.optsWithGlobals());
4473
4703
  try {
4474
4704
  const box2 = await spin(`resuming ${name}\u2026`, client.resumeMachine(name));
@@ -4480,8 +4710,8 @@ var resumeCommand = new Command28("resume").description("continue a box that is
4480
4710
  });
4481
4711
 
4482
4712
  // src/commands/vm/rm.ts
4483
- import { Command as Command29 } from "commander";
4484
- var rmCommand4 = new Command29("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) => {
4713
+ import { Command as Command31 } from "commander";
4714
+ var rmCommand4 = new Command31("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) => {
4485
4715
  const client = await clientFor(cmd.optsWithGlobals());
4486
4716
  try {
4487
4717
  const box2 = pickRef(await boxesFor(client, name), name, me(client));
@@ -4501,10 +4731,10 @@ var rmCommand4 = new Command29("rm").description("destroy a box (its disk is del
4501
4731
  });
4502
4732
 
4503
4733
  // src/commands/vm/set.ts
4504
- import { Command as Command30 } from "commander";
4734
+ import { Command as Command32 } from "commander";
4505
4735
 
4506
4736
  // src/swap.ts
4507
- import { spawn as spawn3 } from "child_process";
4737
+ import { spawn as spawn4 } from "child_process";
4508
4738
  var SWAP_FILE = "/rom/overlay/swapfile";
4509
4739
  var SWAP_KEEP_FREE_MIB = 1024;
4510
4740
  var SWAP_MIN_MIB = 256;
@@ -4566,7 +4796,7 @@ function parseSwapReport(output) {
4566
4796
  return { sizeMib: Math.round(Number(m[1]) / 1024), usedMib: Math.round(Number(m[2]) / 1024), zswap: m[3] === "Y" || m[3] === "1" };
4567
4797
  }
4568
4798
  function runSwap(ep, mib) {
4569
- const child = spawn3("ssh", ["-n", ...sshArgs(ep), swapCommand(mib)], { stdio: ["ignore", "pipe", "pipe"] });
4799
+ const child = spawn4("ssh", ["-n", ...sshArgs(ep), swapCommand(mib)], { stdio: ["ignore", "pipe", "pipe"] });
4570
4800
  const chunks = [];
4571
4801
  child.stdout.on("data", (c2) => chunks.push(c2));
4572
4802
  child.stderr.on("data", (c2) => chunks.push(c2));
@@ -4577,7 +4807,7 @@ function runSwap(ep, mib) {
4577
4807
  }
4578
4808
 
4579
4809
  // src/commands/vm/set.ts
4580
- var setCommand = new Command30("set").description("change a box's settings, e.g. --auto-hibernate 30m (off: never), --idle-check /home/kvbox/idle.sh, --swap 2G").argument("<name>", "box name").option("--auto-hibernate <duration>", "hibernate the box after this long without network traffic (30m, 4h, 1d; off: never)").option("--idle-check <script>", "a script in the box that exits 0 when it is idle, asked instead of network traffic (off: none)").option("--swap <size>", "a swap file on the box's disk for memory spikes such as a build (2G, 512M; off: none)").option("--json", "print the box as JSON").action(async (name, opts, cmd) => {
4810
+ var setCommand = new Command32("set").description("change a box's settings, e.g. --auto-hibernate 30m (off: never), --idle-check /home/kvbox/idle.sh, --swap 2G").argument("<name>", "box name").option("--auto-hibernate <duration>", "hibernate the box after this long without network traffic (30m, 4h, 1d; off: never)").option("--idle-check <script>", "a script in the box that exits 0 when it is idle, asked instead of network traffic (off: none)").option("--swap <size>", "a swap file on the box's disk for memory spikes such as a build (2G, 512M; off: none)").option("--json", "print the box as JSON").action(async (name, opts, cmd) => {
4581
4811
  if (opts.autoHibernate === void 0 && opts.idleCheck === void 0 && opts.swap === void 0) {
4582
4812
  throw new KvboxError("nothing to change: give --auto-hibernate, --idle-check or --swap");
4583
4813
  }
@@ -4646,8 +4876,8 @@ function parseIdleCheck(text2) {
4646
4876
  }
4647
4877
 
4648
4878
  // src/commands/vm/start.ts
4649
- import { Command as Command31 } from "commander";
4650
- var startCommand = new Command31("start").description("boot a stopped box again (same name, IP and disk)").argument("<name>", "box name").option("--force", "skip the capacity guard").option("--json", "print the box as JSON").action(async (name, opts, cmd) => {
4879
+ import { Command as Command33 } from "commander";
4880
+ var startCommand = new Command33("start").description("boot a stopped box again (same name, IP and disk)").argument("<name>", "box name").option("--force", "skip the capacity guard").option("--json", "print the box as JSON").action(async (name, opts, cmd) => {
4651
4881
  const client = await clientFor(cmd.optsWithGlobals());
4652
4882
  try {
4653
4883
  const box2 = await spin(`booting ${name}\u2026`, client.startMachine(name, opts.force ?? false));
@@ -4659,8 +4889,8 @@ var startCommand = new Command31("start").description("boot a stopped box again
4659
4889
  });
4660
4890
 
4661
4891
  // src/commands/vm/stop.ts
4662
- import { Command as Command32 } from "commander";
4663
- var stopCommand = new Command32("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) => {
4892
+ import { Command as Command34 } from "commander";
4893
+ var stopCommand = new Command34("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) => {
4664
4894
  const client = await clientFor(cmd.optsWithGlobals());
4665
4895
  try {
4666
4896
  const box2 = await spin(`shutting ${name} down\u2026`, client.stopMachine(name));
@@ -4672,8 +4902,8 @@ var stopCommand = new Command32("stop").description("shut a box down (its disk i
4672
4902
  });
4673
4903
 
4674
4904
  // src/commands/vm/top.ts
4675
- import { Command as Command33 } from "commander";
4676
- var topCommand = new Command33("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) => {
4905
+ import { Command as Command35 } from "commander";
4906
+ var topCommand = new Command35("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) => {
4677
4907
  const client = await clientFor(cmd.optsWithGlobals());
4678
4908
  try {
4679
4909
  const running = (await client.listMachines({ all: opts.all })).filter((b) => b.status === "running");
@@ -4733,8 +4963,8 @@ function topRows(entries, cloud) {
4733
4963
  }
4734
4964
 
4735
4965
  // src/commands/vm/unlink.ts
4736
- import { Command as Command34 } from "commander";
4737
- var unlinkCommand = new Command34("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) => {
4966
+ import { Command as Command36 } from "commander";
4967
+ var unlinkCommand = new Command36("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) => {
4738
4968
  const port = parseLinkPort(opts.port);
4739
4969
  if (!await confirm(`Cut box ${from} off from box ${name} port ${port}? Its open connections close too.`, opts.yes ?? false)) {
4740
4970
  info("cancelled");
@@ -4755,8 +4985,8 @@ var unlinkCommand = new Command34("unlink").description("take a link away (kvbox
4755
4985
  });
4756
4986
 
4757
4987
  // src/commands/vm/update.ts
4758
- import { Command as Command35 } from "commander";
4759
- var updateCommand = new Command35("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) => {
4988
+ import { Command as Command37 } from "commander";
4989
+ var updateCommand = new Command37("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) => {
4760
4990
  const client = await clientFor(cmd.optsWithGlobals());
4761
4991
  try {
4762
4992
  const before = pickRef(await boxesFor(client, name), name, me(client));
@@ -4777,57 +5007,9 @@ var updateCommand = new Command35("update").description("move a box onto the cur
4777
5007
  }
4778
5008
  });
4779
5009
 
4780
- // src/commands/vm/usage.ts
4781
- import { Command as Command36 } from "commander";
4782
- var usageCommand = new Command36("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) => {
4783
- let since;
4784
- if (opts.since !== void 0) {
4785
- const t = Date.parse(opts.since);
4786
- if (Number.isNaN(t)) throw new KvboxError(`--since ${opts.since}: not a date; write it like 2026-10-19 or 2026-10-19T08:00:00Z`);
4787
- since = new Date(t).toISOString();
4788
- }
4789
- const client = await clientFor(cmd.optsWithGlobals());
4790
- try {
4791
- const u = await client.machineUsage(name, since);
4792
- if (opts.json) json(u);
4793
- else process.stdout.write(block(u));
4794
- } finally {
4795
- await client.close();
4796
- }
4797
- });
4798
- var day = (iso) => iso.slice(0, 10);
4799
- var SYMBOLS = { EUR: "\u20AC", USD: "$", GBP: "\xA3" };
4800
- function money(amount, currency) {
4801
- const sign = amount < 0 ? "-" : "";
4802
- const n = Math.abs(amount).toFixed(2);
4803
- const sym = SYMBOLS[currency.toUpperCase()];
4804
- return sym === void 0 ? `${sign}${n} ${currency}` : `${sign}${sym}${n}`;
4805
- }
4806
- function block(u) {
4807
- const estimated = u.estimatedStops === 0 ? "" : color.dim(` (${u.estimatedStops} stop time${u.estimatedStops === 1 ? "" : "s"} estimated)`);
4808
- const rows2 = [
4809
- ["name", boxName(u.name)],
4810
- ["status", status(u.status)],
4811
- ["window", `${day(u.window.from)} to ${day(u.window.to)}`],
4812
- ["running", duration(u.seconds.running) + estimated],
4813
- ["standby", duration(u.seconds.standby)],
4814
- ["hibernated", duration(u.seconds.hibernated)],
4815
- ["stopped", duration(u.seconds.stopped)],
4816
- ["vcpu-h", hours(u.vcpuHours)],
4817
- ["ram GiB-h", hours(u.ramGibHours)],
4818
- ["disk GiB-h", hours(u.diskGibHours)]
4819
- ];
4820
- if (u.cost !== void 0) rows2.push(["cost", `${money(u.cost.amount, u.cost.currency)} ${color.dim("(estimated)")}`]);
4821
- if (u.historyFrom !== null && u.historyFrom > u.window.from) {
4822
- rows2.push(["history", color.dim(`from ${u.historyFrom.slice(0, 16).replace("T", " ")} UTC; the box is older, but its time before that was not recorded`)]);
4823
- }
4824
- const w = Math.max(...rows2.map(([k]) => k.length));
4825
- return rows2.map(([k, v]) => `${" ".repeat(w - k.length)}${k}: ${v}`).join("\n") + "\n";
4826
- }
4827
-
4828
5010
  // src/commands/vm/wake.ts
4829
- import { Command as Command37 } from "commander";
4830
- var wakeCommand = new Command37("wake").description("continue a hibernated box where it left off (same name, IP and disk)").argument("<name>", "box name").option("--force", "skip the capacity guard").option("--json", "print the box as JSON").action(async (name, opts, cmd) => {
5011
+ import { Command as Command38 } from "commander";
5012
+ var wakeCommand = new Command38("wake").description("continue a hibernated box where it left off (same name, IP and disk)").argument("<name>", "box name").option("--force", "skip the capacity guard").option("--json", "print the box as JSON").action(async (name, opts, cmd) => {
4831
5013
  const client = await clientFor(cmd.optsWithGlobals());
4832
5014
  try {
4833
5015
  const box2 = await spin(`waking ${name} (loading its memory from disk)\u2026`, client.wakeMachine(name, opts.force ?? false));
@@ -4839,19 +5021,19 @@ var wakeCommand = new Command37("wake").description("continue a hibernated box w
4839
5021
  });
4840
5022
 
4841
5023
  // src/commands/vm/index.ts
4842
- var vmCommand = new Command38("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(hookCommand).addCommand(backupCommand).addCommand(linkCommand).addCommand(unlinkCommand).addCommand(linksCommand).addCommand(rmCommand4);
5024
+ var vmCommand = new Command39("vm").enablePositionalOptions().description("manage boxes (each one is a Firecracker microVM)").addCommand(newCommand).addCommand(forkCommand).addCommand(lsCommand).addCommand(getCommand).addCommand(connectCommand).addCommand(execCommand).addCommand(cpCommand).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(hookCommand).addCommand(backupCommand).addCommand(linkCommand).addCommand(unlinkCommand).addCommand(linksCommand).addCommand(rmCommand4);
4843
5025
  for (const cmd of vmCommand.commands) if (cmd !== proxyCommand && cmd !== hookCommand && cmd !== backupCommand) cmd.option("--org <slug>", "act in this org (- for your personal boxes)");
4844
- var vmAliases = [newCommand, lsCommand, getCommand, connectCommand, execCommand, stopCommand, startCommand, pauseCommand, resumeCommand, hibernateCommand, wakeCommand, rmCommand4, claimCommand];
5026
+ var vmAliases = [newCommand, lsCommand, getCommand, connectCommand, execCommand, cpCommand, stopCommand, startCommand, pauseCommand, resumeCommand, hibernateCommand, wakeCommand, rmCommand4, claimCommand];
4845
5027
 
4846
5028
  // src/commands/login.ts
4847
5029
  import { hostname as osHostname2 } from "os";
4848
5030
  import { createInterface as createInterface2 } from "readline/promises";
4849
5031
  import { setTimeout as sleep4 } from "timers/promises";
4850
5032
  import { Writable } from "stream";
4851
- import { Command as Command39 } from "commander";
5033
+ import { Command as Command40 } from "commander";
4852
5034
 
4853
5035
  // src/browser.ts
4854
- import { spawn as spawn4 } from "child_process";
5036
+ import { spawn as spawn5 } from "child_process";
4855
5037
  function isWebLink(url) {
4856
5038
  if (/[^\x21-\x7e]/.test(url)) return false;
4857
5039
  let parsed;
@@ -4876,7 +5058,7 @@ function openBrowser(url) {
4876
5058
  const argv = browserCommand(url);
4877
5059
  if (argv === null) return;
4878
5060
  try {
4879
- const child = spawn4(argv[0], argv.slice(1), { stdio: "ignore", detached: true });
5061
+ const child = spawn5(argv[0], argv.slice(1), { stdio: "ignore", detached: true });
4880
5062
  child.on("error", () => {
4881
5063
  });
4882
5064
  child.unref();
@@ -4885,7 +5067,7 @@ function openBrowser(url) {
4885
5067
  }
4886
5068
 
4887
5069
  // src/commands/login.ts
4888
- var loginCommand = new Command39("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("--password", "log in with email and password instead of approving a code in the web app").option("-e, --email <email>", "account email, for a password login (prompted otherwise)").option("--password-stdin", "read the password from the first line of stdin (for scripts)").action(async (urlArg, opts) => {
5070
+ var loginCommand = new Command40("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("--password", "log in with email and password instead of approving a code in the web app").option("-e, --email <email>", "account email, for a password login (prompted otherwise)").option("--password-stdin", "read the password from the first line of stdin (for scripts)").action(async (urlArg, opts) => {
4889
5071
  const url = normalizeUrl(urlArg ?? DEFAULT_CLOUD_URL);
4890
5072
  const byPassword = opts.password === true || opts.passwordStdin === true || opts.email !== void 0;
4891
5073
  const session = byPassword ? await runLogin(url, await readCredentials(opts), paths()) : await runDeviceLogin(url, paths());
@@ -4995,8 +5177,8 @@ async function firstLine(stream) {
4995
5177
  }
4996
5178
 
4997
5179
  // src/commands/logout.ts
4998
- import { Command as Command40 } from "commander";
4999
- var logoutCommand = new Command40("logout").description("log out of the control plane; commands target this machine's kvbox-server again").action(async () => {
5180
+ import { Command as Command41 } from "commander";
5181
+ var logoutCommand = new Command41("logout").description("log out of the control plane; commands target this machine's kvbox-server again").action(async () => {
5000
5182
  const p = paths();
5001
5183
  const session = await readSession(p).catch(() => null);
5002
5184
  switch (await runLogout(p)) {
@@ -5034,8 +5216,8 @@ async function runLogout(p = paths()) {
5034
5216
  }
5035
5217
 
5036
5218
  // src/commands/whoami.ts
5037
- import { Command as Command41 } from "commander";
5038
- var whoamiCommand = new Command41("whoami").description("show which account and control plane commands target (or local mode)").option("--json", "print as JSON").action(async (opts, cmd) => {
5219
+ import { Command as Command42 } from "commander";
5220
+ var whoamiCommand = new Command42("whoami").description("show which account and control plane commands target (or local mode)").option("--json", "print as JSON").action(async (opts, cmd) => {
5039
5221
  if (!cmd.optsWithGlobals().local && envLogin()) {
5040
5222
  const target = await resolveTarget({});
5041
5223
  if (target.kind !== "cloud") return;
@@ -5060,10 +5242,10 @@ function describeSession(session) {
5060
5242
  }
5061
5243
 
5062
5244
  // src/commands/key/index.ts
5063
- import { Command as Command45 } from "commander";
5245
+ import { Command as Command46 } from "commander";
5064
5246
 
5065
5247
  // src/commands/key/create.ts
5066
- import { Command as Command42 } from "commander";
5248
+ import { Command as Command43 } from "commander";
5067
5249
 
5068
5250
  // src/commands/key/shared.ts
5069
5251
  async function keyClient(cmd) {
@@ -5100,7 +5282,7 @@ function expiryText(expiresAt, now = Date.now()) {
5100
5282
  }
5101
5283
 
5102
5284
  // src/commands/key/create.ts
5103
- var createCommand3 = new Command42("create").description("make an API key for a program: CI, an agent, the SDK (the key is shown once)").argument("<name>", "what to call the key: lowercase letters, digits, '.', '_' or '-'").option("--expires <when>", `when it stops working: a duration (30d, 12h; m is minutes), a day (2027-01-31), or never; ${DEFAULT_API_KEY_DAYS}d by default`).option("--json", "print as JSON").action(async (name, opts, cmd) => {
5285
+ var createCommand3 = new Command43("create").description("make an API key for a program: CI, an agent, the SDK (the key is shown once)").argument("<name>", "what to call the key: lowercase letters, digits, '.', '_' or '-'").option("--expires <when>", `when it stops working: a duration (30d, 12h; m is minutes), a day (2027-01-31), or never; ${DEFAULT_API_KEY_DAYS}d by default`).option("--json", "print as JSON").action(async (name, opts, cmd) => {
5104
5286
  const expiresAt = opts.expires === void 0 ? void 0 : parseExpires(opts.expires);
5105
5287
  const client = await keyClient(cmd);
5106
5288
  try {
@@ -5118,8 +5300,8 @@ var createCommand3 = new Command42("create").description("make an API key for a
5118
5300
  });
5119
5301
 
5120
5302
  // src/commands/key/ls.ts
5121
- import { Command as Command43 } from "commander";
5122
- var lsCommand5 = new Command43("ls").alias("list").description("list your API keys (never the keys themselves)").option("--json", "print as JSON").action(async (opts, cmd) => {
5303
+ import { Command as Command44 } from "commander";
5304
+ var lsCommand5 = new Command44("ls").alias("list").description("list your API keys (never the keys themselves)").option("--json", "print as JSON").action(async (opts, cmd) => {
5123
5305
  const client = await keyClient(cmd);
5124
5306
  try {
5125
5307
  const keys = await client.listApiKeys();
@@ -5138,8 +5320,8 @@ var lsCommand5 = new Command43("ls").alias("list").description("list your API ke
5138
5320
  });
5139
5321
 
5140
5322
  // src/commands/key/rm.ts
5141
- import { Command as Command44 } from "commander";
5142
- var rmCommand5 = new Command44("rm").alias("remove").description("remove an API key: whatever uses it stops working").argument("<name>", "the key's name (kvbox key ls)").option("-y, --yes", "do not ask for confirmation").action(async (name, opts, cmd) => {
5323
+ import { Command as Command45 } from "commander";
5324
+ var rmCommand5 = new Command45("rm").alias("remove").description("remove an API key: whatever uses it stops working").argument("<name>", "the key's name (kvbox key ls)").option("-y, --yes", "do not ask for confirmation").action(async (name, opts, cmd) => {
5143
5325
  const client = await keyClient(cmd);
5144
5326
  try {
5145
5327
  if (!await confirm(`Remove API key ${name}? Whatever uses it stops working.`, opts.yes ?? false)) {
@@ -5155,14 +5337,14 @@ var rmCommand5 = new Command44("rm").alias("remove").description("remove an API
5155
5337
  });
5156
5338
 
5157
5339
  // src/commands/key/index.ts
5158
- var keyCommand = new Command45("key").aliases(["keys"]).description("API keys: named tokens a program (CI, an agent, the SDK) uses as KVBOX_TOKEN in place of a login").addCommand(createCommand3).addCommand(lsCommand5).addCommand(rmCommand5);
5340
+ var keyCommand = new Command46("key").aliases(["keys"]).description("API keys: named tokens a program (CI, an agent, the SDK) uses as KVBOX_TOKEN in place of a login").addCommand(createCommand3).addCommand(lsCommand5).addCommand(rmCommand5);
5159
5341
 
5160
5342
  // src/commands/snapshots/index.ts
5161
- import { Command as Command49 } from "commander";
5343
+ import { Command as Command50 } from "commander";
5162
5344
 
5163
5345
  // src/commands/snapshots/ls.ts
5164
- import { Command as Command46 } from "commander";
5165
- var lsCommand6 = new Command46("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) => {
5346
+ import { Command as Command47 } from "commander";
5347
+ var lsCommand6 = new Command47("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) => {
5166
5348
  const client = await clientFor(cmd.optsWithGlobals());
5167
5349
  try {
5168
5350
  const cloud = client.target.kind === "cloud";
@@ -5193,8 +5375,8 @@ var lsCommand6 = new Command46("ls").description("list snapshots (yours and your
5193
5375
  });
5194
5376
 
5195
5377
  // src/commands/snapshots/new.ts
5196
- import { Command as Command47 } from "commander";
5197
- var newCommand2 = new Command47("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 (box2, name, opts, cmd) => {
5378
+ import { Command as Command48 } from "commander";
5379
+ var newCommand2 = new Command48("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 (box2, name, opts, cmd) => {
5198
5380
  const client = await clientFor(cmd.optsWithGlobals());
5199
5381
  try {
5200
5382
  const req = { box: box2, name, ...opts.replace ? { replace: true } : {} };
@@ -5207,8 +5389,8 @@ var newCommand2 = new Command47("new").description("freeze a running box (memory
5207
5389
  });
5208
5390
 
5209
5391
  // src/commands/snapshots/rm.ts
5210
- import { Command as Command48 } from "commander";
5211
- var rmCommand6 = new Command48("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) => {
5392
+ import { Command as Command49 } from "commander";
5393
+ var rmCommand6 = new Command49("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) => {
5212
5394
  if (!await confirm(`Delete snapshot ${name}?`, opts.yes ?? false)) {
5213
5395
  info("cancelled");
5214
5396
  process.exitCode = 1;
@@ -5224,14 +5406,14 @@ var rmCommand6 = new Command48("rm").description("delete a snapshot (boxes made
5224
5406
  });
5225
5407
 
5226
5408
  // src/commands/snapshots/index.ts
5227
- var snapshotsCommand = new Command49("snapshots").aliases(["snapshot", "snap"]).description("freeze running boxes into snapshots and manage them").addCommand(newCommand2).addCommand(lsCommand6).addCommand(rmCommand6);
5409
+ var snapshotsCommand = new Command50("snapshots").aliases(["snapshot", "snap"]).description("freeze running boxes into snapshots and manage them").addCommand(newCommand2).addCommand(lsCommand6).addCommand(rmCommand6);
5228
5410
  for (const cmd of snapshotsCommand.commands) cmd.option("--org <slug>", "act in this org (- for your personal boxes)");
5229
5411
 
5230
5412
  // src/commands/org/index.ts
5231
- import { Command as Command55 } from "commander";
5413
+ import { Command as Command56 } from "commander";
5232
5414
 
5233
5415
  // src/commands/org/ls.ts
5234
- import { Command as Command50 } from "commander";
5416
+ import { Command as Command51 } from "commander";
5235
5417
 
5236
5418
  // src/commands/org/context.ts
5237
5419
  var NOT_LOGGED_IN2 = "orgs live on the control plane: kvbox login first";
@@ -5251,7 +5433,7 @@ function orgFor(opts, target) {
5251
5433
  }
5252
5434
 
5253
5435
  // src/commands/org/ls.ts
5254
- var lsCommand7 = new Command50("ls").description("list the orgs you belong to and your role in each").option("--json", "print as JSON").action(async (opts, cmd) => {
5436
+ var lsCommand7 = new Command51("ls").description("list the orgs you belong to and your role in each").option("--json", "print as JSON").action(async (opts, cmd) => {
5255
5437
  const client = await cloudClientFor(cmd.optsWithGlobals());
5256
5438
  try {
5257
5439
  const orgs = await client.listOrgs();
@@ -5273,8 +5455,8 @@ function orgRows(orgs) {
5273
5455
  }
5274
5456
 
5275
5457
  // src/commands/org/members.ts
5276
- import { Command as Command51, Option as Option4 } from "commander";
5277
- var lsCommand8 = new Command51("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) => {
5458
+ import { Command as Command52, Option as Option4 } from "commander";
5459
+ var lsCommand8 = new Command52("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) => {
5278
5460
  const client = await cloudClientFor(cmd.optsWithGlobals());
5279
5461
  try {
5280
5462
  const org = await client.getOrg(orgFor(opts, client.target));
@@ -5288,7 +5470,7 @@ var lsCommand8 = new Command51("ls").description("list an org's members and thei
5288
5470
  await client.close();
5289
5471
  }
5290
5472
  });
5291
- var addCommand2 = new Command51("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) => {
5473
+ var addCommand2 = new Command52("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) => {
5292
5474
  const client = await cloudClientFor(cmd.optsWithGlobals());
5293
5475
  try {
5294
5476
  const slug = orgFor(opts, client.target);
@@ -5298,7 +5480,7 @@ var addCommand2 = new Command51("add").description("add a user to an org (admins
5298
5480
  await client.close();
5299
5481
  }
5300
5482
  });
5301
- var rmCommand7 = new Command51("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) => {
5483
+ var rmCommand7 = new Command52("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) => {
5302
5484
  const client = await cloudClientFor(cmd.optsWithGlobals());
5303
5485
  try {
5304
5486
  const slug = orgFor(opts, client.target);
@@ -5314,11 +5496,11 @@ var rmCommand7 = new Command51("rm").description("remove a member (or leave: rem
5314
5496
  await client.close();
5315
5497
  }
5316
5498
  });
5317
- var membersCommand = new Command51("members").description("who is in an org and what they may do").addCommand(lsCommand8).addCommand(addCommand2).addCommand(rmCommand7);
5499
+ var membersCommand = new Command52("members").description("who is in an org and what they may do").addCommand(lsCommand8).addCommand(addCommand2).addCommand(rmCommand7);
5318
5500
 
5319
5501
  // src/commands/org/new.ts
5320
- import { Command as Command52 } from "commander";
5321
- var newCommand3 = new Command52("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) => {
5502
+ import { Command as Command53 } from "commander";
5503
+ var newCommand3 = new Command53("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) => {
5322
5504
  const client = await cloudClientFor(cmd.optsWithGlobals());
5323
5505
  try {
5324
5506
  const org = await client.createOrg({ slug, name: opts.name ?? slug });
@@ -5334,8 +5516,8 @@ var newCommand3 = new Command52("new").description("create an org; you become it
5334
5516
  });
5335
5517
 
5336
5518
  // src/commands/org/rm.ts
5337
- import { Command as Command53 } from "commander";
5338
- var rmCommand8 = new Command53("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) => {
5519
+ import { Command as Command54 } from "commander";
5520
+ var rmCommand8 = new Command54("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) => {
5339
5521
  if (!await confirm(`Delete org ${slug}? Its members lose access; its slug stays taken.`, opts.yes ?? false)) {
5340
5522
  info("cancelled");
5341
5523
  process.exitCode = 1;
@@ -5351,8 +5533,8 @@ var rmCommand8 = new Command53("rm").description("delete an org (owners only; re
5351
5533
  });
5352
5534
 
5353
5535
  // src/commands/org/role.ts
5354
- import { Argument, Command as Command54 } from "commander";
5355
- var roleCommand = new Command54("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) => {
5536
+ import { Argument, Command as Command55 } from "commander";
5537
+ var roleCommand = new Command55("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) => {
5356
5538
  const client = await cloudClientFor(cmd.optsWithGlobals());
5357
5539
  try {
5358
5540
  const slug = orgFor(opts, client.target);
@@ -5364,11 +5546,11 @@ var roleCommand = new Command54("role").description("change a member's role (own
5364
5546
  });
5365
5547
 
5366
5548
  // src/commands/org/index.ts
5367
- var orgCommand = new Command55("org").description("orgs: shared slugs that own boxes, with owners, admins and members").addCommand(lsCommand7).addCommand(newCommand3).addCommand(membersCommand).addCommand(roleCommand).addCommand(rmCommand8);
5549
+ var orgCommand = new Command56("org").description("orgs: shared slugs that own boxes, with owners, admins and members").addCommand(lsCommand7).addCommand(newCommand3).addCommand(membersCommand).addCommand(roleCommand).addCommand(rmCommand8);
5368
5550
 
5369
5551
  // src/commands/usage.ts
5370
- import { Command as Command56 } from "commander";
5371
- var usageCommand2 = new Command56("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) => {
5552
+ import { Command as Command57 } from "commander";
5553
+ var usageCommand2 = new Command57("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) => {
5372
5554
  for (const [name, value] of [
5373
5555
  ["since", opts.since],
5374
5556
  ["until", opts.until]
@@ -5390,7 +5572,8 @@ var usageCommand2 = new Command56("usage").description("what your boxes and volu
5390
5572
  const volumes = report.volumes ?? [];
5391
5573
  const storage = report.storage ?? [];
5392
5574
  const cron = report.cron ?? [];
5393
- if (report.boxes.length === 0 && volumes.length === 0 && storage.length === 0 && cron.length === 0) info("no usage in this window");
5575
+ const backups = report.backups ?? [];
5576
+ if (report.boxes.length === 0 && volumes.length === 0 && storage.length === 0 && cron.length === 0 && backups.length === 0) info("no usage in this window");
5394
5577
  else if (report.boxes.length > 0) table(perUser ? userRows(perUser) : usageRows(report, cloud));
5395
5578
  if (volumes.length > 0) {
5396
5579
  info(volumes.length === 1 ? "1 volume" : `${volumes.length} volumes`);
@@ -5404,8 +5587,13 @@ var usageCommand2 = new Command56("usage").description("what your boxes and volu
5404
5587
  info(cron.length === 1 ? "1 cron service" : `${cron.length} cron services`);
5405
5588
  table(cronRows(report, cloud));
5406
5589
  }
5407
- if ((volumes.length > 0 || storage.length > 0 || cron.length > 0) && report.totals.cost !== void 0) {
5408
- const what = ["boxes", ...volumes.length > 0 ? ["volumes"] : [], ...storage.length > 0 ? ["object storage"] : [], ...cron.length > 0 ? ["cron services"] : []];
5590
+ if (backups.length > 0) {
5591
+ const taken = backups.reduce((n, b) => n + b.count, 0);
5592
+ info(taken === 1 ? "1 backup taken by hand" : `${taken} backups taken by hand`);
5593
+ table(backupRows(report, cloud));
5594
+ }
5595
+ if ((volumes.length > 0 || storage.length > 0 || cron.length > 0 || backups.length > 0) && report.totals.cost !== void 0) {
5596
+ const what = ["boxes", ...volumes.length > 0 ? ["volumes"] : [], ...storage.length > 0 ? ["object storage"] : [], ...cron.length > 0 ? ["cron services"] : [], ...backups.length > 0 ? ["backups"] : []];
5409
5597
  info(`total: ${money(report.totals.cost.amount, report.totals.cost.currency)} ${color.dim(`(${what.slice(0, -1).join(", ")} and ${what.at(-1)}, estimated)`)}`);
5410
5598
  }
5411
5599
  if (cloud) {
@@ -5508,6 +5696,15 @@ function cronRows(report, cloud) {
5508
5696
  ...priced ? { cost: money(s.cost?.amount ?? 0, currency) } : {}
5509
5697
  }));
5510
5698
  }
5699
+ function backupRows(report, cloud) {
5700
+ return (report.backups ?? []).map((b) => ({
5701
+ name: b.kind === "storage" ? "object storage" : b.name,
5702
+ kind: b.kind,
5703
+ ...cloud ? { owner: ownerCell2(b, cloud.me) } : {},
5704
+ backups: String(b.count),
5705
+ cost: money(b.cost.amount, b.cost.currency)
5706
+ }));
5707
+ }
5511
5708
  function byUser(report) {
5512
5709
  const groups = /* @__PURE__ */ new Map();
5513
5710
  for (const b of report.boxes) {
@@ -5524,7 +5721,7 @@ function byUser(report) {
5524
5721
  return u;
5525
5722
  });
5526
5723
  users.sort((a, b) => a.user === null ? 1 : b.user === null ? -1 : a.user.localeCompare(b.user));
5527
- return { window: report.window, users, ...report.volumes === void 0 ? {} : { volumes: report.volumes }, ...report.storage === void 0 ? {} : { storage: report.storage }, ...report.cron === void 0 ? {} : { cron: report.cron }, totals: report.totals };
5724
+ return { window: report.window, users, ...report.volumes === void 0 ? {} : { volumes: report.volumes }, ...report.storage === void 0 ? {} : { storage: report.storage }, ...report.cron === void 0 ? {} : { cron: report.cron }, ...report.backups === void 0 ? {} : { backups: report.backups }, totals: report.totals };
5528
5725
  }
5529
5726
  function userRows(r) {
5530
5727
  const priced = r.totals.cost !== void 0;
@@ -5550,8 +5747,8 @@ function userRows(r) {
5550
5747
  }
5551
5748
 
5552
5749
  // src/commands/credit.ts
5553
- import { Command as Command57 } from "commander";
5554
- var creditCommand = new Command57("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) => {
5750
+ import { Command as Command58 } from "commander";
5751
+ var creditCommand = new Command58("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) => {
5555
5752
  const client = await clientFor(cmd.optsWithGlobals(), { autoStart: false });
5556
5753
  try {
5557
5754
  if (client.target.kind === "local") throw new KvboxError("credit lives on the control plane: kvbox login first");
@@ -5580,8 +5777,8 @@ function creditRow(b, me2) {
5580
5777
  }
5581
5778
 
5582
5779
  // src/commands/redeem.ts
5583
- import { Command as Command58 } from "commander";
5584
- var redeemCommand = new Command58("redeem").description("redeem a promo code for credit, on your account or (--org) an org you own").argument("<code>", "the code, like KV-7F3K-9QXM-2HBD").option("--org <slug>", "give the credit to this org, which you own; it cannot be moved later").option("--json", "print as JSON").action(async (code, opts, cmd) => {
5780
+ import { Command as Command59 } from "commander";
5781
+ var redeemCommand = new Command59("redeem").description("redeem a promo code for credit, on your account or (--org) an org you own").argument("<code>", "the code, like KV-7F3K-9QXM-2HBD").option("--org <slug>", "give the credit to this org, which you own; it cannot be moved later").option("--json", "print as JSON").action(async (code, opts, cmd) => {
5585
5782
  const client = await clientFor(cmd.optsWithGlobals(), { autoStart: false });
5586
5783
  try {
5587
5784
  if (client.target.kind === "local") throw new KvboxError("codes are redeemed on the control plane: kvbox login first");
@@ -5601,7 +5798,7 @@ var redeemCommand = new Command58("redeem").description("redeem a promo code for
5601
5798
  // src/commands/deploy/index.ts
5602
5799
  import { access as access5, readFile as readFile7 } from "fs/promises";
5603
5800
  import { basename as basename2, resolve as resolve3 } from "path";
5604
- import { Command as Command59, InvalidArgumentError as InvalidArgumentError2, Option as Option5 } from "commander";
5801
+ import { Command as Command60, InvalidArgumentError as InvalidArgumentError2, Option as Option5 } from "commander";
5605
5802
 
5606
5803
  // src/commands/deploy/config.ts
5607
5804
  import { readFile as readFile5, writeFile as writeFile3 } from "fs/promises";
@@ -5911,7 +6108,7 @@ var nodeTemplate = {
5911
6108
  };
5912
6109
 
5913
6110
  // src/commands/deploy/templates/react.ts
5914
- import { spawn as spawn5 } from "child_process";
6111
+ import { spawn as spawn6 } from "child_process";
5915
6112
  import { access as access2 } from "fs/promises";
5916
6113
  import { join as join4 } from "path";
5917
6114
  var OUT_DIRS = ["dist", "build"];
@@ -5919,7 +6116,7 @@ async function runBuild(dir, pm) {
5919
6116
  const args = runScript(pm, "build");
5920
6117
  info(`${color.dim("$")} ${pm} ${args.join(" ")}`);
5921
6118
  const status2 = await new Promise((resolve4, reject) => {
5922
- const child = spawn5(pm, args, { cwd: dir, stdio: ["ignore", process.stderr, process.stderr], shell: process.platform === "win32" });
6119
+ const child = spawn6(pm, args, { cwd: dir, stdio: ["ignore", process.stderr, process.stderr], shell: process.platform === "win32" });
5923
6120
  child.once("error", (err) => reject(new KvboxError(`could not run ${pm}: ${err.message}`)));
5924
6121
  child.once("close", (code) => resolve4(code ?? 1));
5925
6122
  });
@@ -6218,7 +6415,7 @@ function subdomainFor(name) {
6218
6415
  }
6219
6416
 
6220
6417
  // src/commands/deploy/ship.ts
6221
- import { spawn as spawn6 } from "child_process";
6418
+ import { spawn as spawn7 } from "child_process";
6222
6419
  import { readdir, stat as stat2 } from "fs/promises";
6223
6420
  import { join as join7 } from "path";
6224
6421
  var IMAGE_TOO_OLD = 3;
@@ -6240,8 +6437,8 @@ async function measure(dir, exclude = []) {
6240
6437
  return total;
6241
6438
  }
6242
6439
  async function ship(ep, dir, remote, exclude = []) {
6243
- const tar = spawn6("tar", ["-cf", "-", ...exclude.map((e) => `--exclude=${e}`), "-C", dir, "."], { stdio: ["ignore", "pipe", "pipe"] });
6244
- const ssh = spawn6("ssh", [...sshArgs(ep), remote], { stdio: ["pipe", "pipe", "pipe"] });
6440
+ const tar = spawn7("tar", ["-cf", "-", ...exclude.map((e) => `--exclude=${e}`), "-C", dir, "."], { stdio: ["ignore", "pipe", "pipe"] });
6441
+ const ssh = spawn7("ssh", [...sshArgs(ep), remote], { stdio: ["pipe", "pipe", "pipe"] });
6245
6442
  tar.stdout.pipe(ssh.stdin);
6246
6443
  const chunks = [];
6247
6444
  ssh.stdout.on("data", (c2) => chunks.push(c2));
@@ -6269,7 +6466,7 @@ async function ship(ep, dir, remote, exclude = []) {
6269
6466
  return { status: status2, output: Buffer.concat(chunks).toString("utf8") };
6270
6467
  }
6271
6468
  async function run(ep, remote) {
6272
- const ssh = spawn6("ssh", [...sshArgs(ep), remote], { stdio: ["ignore", "pipe", "pipe"] });
6469
+ const ssh = spawn7("ssh", [...sshArgs(ep), remote], { stdio: ["ignore", "pipe", "pipe"] });
6273
6470
  const chunks = [];
6274
6471
  ssh.stdout.on("data", (c2) => chunks.push(c2));
6275
6472
  ssh.stderr.on("data", (c2) => chunks.push(c2));
@@ -6866,7 +7063,7 @@ async function readPackageJson(dir) {
6866
7063
  }
6867
7064
 
6868
7065
  // src/commands/deploy/index.ts
6869
- var deployCommand = new Command59("deploy").description("put the app in this directory (React, Next.js, a Node server, a Dockerfile or a static site) 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 and the directory 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 box port of a Next.js app, Node server or container (default 3000; saved to kvbox.json)", parsePort).option("--only <service>", "with several services in kvbox.json: deploy this one only (repeatable)", (v, all) => [...all ?? [], v]).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) => {
7066
+ var deployCommand = new Command60("deploy").description("put the app in this directory (React, Next.js, a Node server, a Dockerfile or a static site) 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 and the directory 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 box port of a Next.js app, Node server or container (default 3000; saved to kvbox.json)", parsePort).option("--only <service>", "with several services in kvbox.json: deploy this one only (repeatable)", (v, all) => [...all ?? [], v]).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) => {
6870
7067
  const dir = resolve3(dirArg ?? ".");
6871
7068
  const pkg = await readPackageJson2(dir);
6872
7069
  const facts = { indexHtml: await exists2(resolve3(dir, "index.html")), dockerfile: await exists2(resolve3(dir, "Dockerfile")) };
@@ -7023,15 +7220,15 @@ async function settle2(dir, pkg, facts, saved, opts, orgFlag, cloud) {
7023
7220
  }
7024
7221
 
7025
7222
  // src/commands/volume/index.ts
7026
- import { Command as Command71 } from "commander";
7223
+ import { Command as Command72 } from "commander";
7027
7224
 
7028
7225
  // src/commands/volume/attach.ts
7029
- import { Command as Command60 } from "commander";
7226
+ import { Command as Command61 } from "commander";
7030
7227
  function describeMount(machine, volume2, box2) {
7031
7228
  const path = machine.volumes?.find((v) => volume2 === v.name || volume2.endsWith(`/${v.name}`))?.mountPath ?? volumeMountPath(volume2.slice(volume2.lastIndexOf("/") + 1));
7032
7229
  return machine.status === "running" ? ` the box was restarted; the volume is at ${path} inside it` : ` box ${box2} is ${machine.status}; the volume is at ${path} once it runs`;
7033
7230
  }
7034
- var attachCommand = new Command60("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) => {
7231
+ var attachCommand = new Command61("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) => {
7035
7232
  if (volumeArg === void 0 || boxArg === void 0) askOrUsage("give the volume and the box: kvbox volume attach <volume> <box>");
7036
7233
  const client = await clientFor(cmd.optsWithGlobals());
7037
7234
  try {
@@ -7050,11 +7247,11 @@ var attachCommand = new Command60("attach").description("attach a volume to a bo
7050
7247
  });
7051
7248
 
7052
7249
  // src/commands/volume/backup/index.ts
7053
- import { Command as Command65 } from "commander";
7250
+ import { Command as Command66 } from "commander";
7054
7251
 
7055
7252
  // src/commands/volume/backup/create.ts
7056
- import { Command as Command61 } from "commander";
7057
- var createCommand4 = new Command61("create").description("back up a volume's disk to the kvbox cloud (encrypted)").argument("<volume>", "volume name").option("--wait", "stay until the backup is ready (by default it runs in the background)").option("--json", "print the backup as JSON").action(async (volume2, opts, cmd) => {
7253
+ import { Command as Command62 } from "commander";
7254
+ var createCommand4 = new Command62("create").description("back up a volume's disk to the kvbox cloud (encrypted)").argument("<volume>", "volume name").option("--wait", "stay until the backup is ready (by default it runs in the background)").option("--json", "print the backup as JSON").action(async (volume2, opts, cmd) => {
7058
7255
  const client = await clientFor(cmd.optsWithGlobals(), { autoStart: false });
7059
7256
  try {
7060
7257
  requireCloud3(client);
@@ -7064,6 +7261,7 @@ var createCommand4 = new Command61("create").description("back up a volume's dis
7064
7261
  else {
7065
7262
  info(`${color.green("\u2713")} backup ${started.id} of volume ${color.bold(volume2)} started; it runs in the background`);
7066
7263
  info(color.dim(` status: kvbox volume backup ls ${volume2}`));
7264
+ await printCost(client, false);
7067
7265
  }
7068
7266
  return;
7069
7267
  }
@@ -7073,14 +7271,15 @@ var createCommand4 = new Command61("create").description("back up a volume's dis
7073
7271
  if (opts.json) return;
7074
7272
  info(`${color.green("\u2713")} backup ${done.id} of volume ${color.bold(volume2)}: ${sizeLine(done)}`);
7075
7273
  info(color.dim(` restore with: kvbox volume backup restore ${volume2} ${done.id}`));
7274
+ await printCost(client, true);
7076
7275
  } finally {
7077
7276
  await client.close();
7078
7277
  }
7079
7278
  });
7080
7279
 
7081
7280
  // src/commands/volume/backup/ls.ts
7082
- import { Command as Command62 } from "commander";
7083
- var lsCommand9 = new Command62("ls").alias("list").description("list volume backups: every volume's, or one volume's").argument("[volume]", "volume name (default: every volume)").option("--json", "print as JSON").action(async (volume2, opts, cmd) => {
7281
+ import { Command as Command63 } from "commander";
7282
+ var lsCommand9 = new Command63("ls").alias("list").description("list volume backups: every volume's, or one volume's").argument("[volume]", "volume name (default: every volume)").option("--json", "print as JSON").action(async (volume2, opts, cmd) => {
7084
7283
  const client = await clientFor(cmd.optsWithGlobals(), { autoStart: false });
7085
7284
  try {
7086
7285
  requireCloud3(client);
@@ -7113,8 +7312,8 @@ var lsCommand9 = new Command62("ls").alias("list").description("list volume back
7113
7312
  });
7114
7313
 
7115
7314
  // src/commands/volume/backup/restore.ts
7116
- import { Command as Command63 } from "commander";
7117
- var restoreCommand2 = new Command63("restore").description("put a backup back: the volume's data becomes the backup's (a running box holding it restarts)").argument("<volume>", "volume name").argument("<id>", "the backup's id (kvbox volume backup ls <volume>)").option("-y, --yes", "do not ask for confirmation").option("--json", "print the volume as JSON").action(async (volume2, id, opts, cmd) => {
7315
+ import { Command as Command64 } from "commander";
7316
+ var restoreCommand2 = new Command64("restore").description("put a backup back: the volume's data becomes the backup's (a running box holding it restarts)").argument("<volume>", "volume name").argument("<id>", "the backup's id (kvbox volume backup ls <volume>)").option("-y, --yes", "do not ask for confirmation").option("--json", "print the volume as JSON").action(async (volume2, id, opts, cmd) => {
7118
7317
  const client = await clientFor(cmd.optsWithGlobals(), { autoStart: false });
7119
7318
  try {
7120
7319
  requireCloud3(client);
@@ -7137,8 +7336,8 @@ var restoreCommand2 = new Command63("restore").description("put a backup back: t
7137
7336
  });
7138
7337
 
7139
7338
  // src/commands/volume/backup/rm.ts
7140
- import { Command as Command64 } from "commander";
7141
- var rmCommand9 = new Command64("rm").alias("remove").description("remove a backup for good (a volume's that is gone too)").argument("<volume>", "volume name").argument("<id>", "the backup's id (kvbox volume backup ls <volume>)").option("-y, --yes", "do not ask for confirmation").action(async (volume2, id, opts, cmd) => {
7339
+ import { Command as Command65 } from "commander";
7340
+ var rmCommand9 = new Command65("rm").alias("remove").description("remove a backup for good (a volume's that is gone too)").argument("<volume>", "volume name").argument("<id>", "the backup's id (kvbox volume backup ls <volume>)").option("-y, --yes", "do not ask for confirmation").action(async (volume2, id, opts, cmd) => {
7142
7341
  const client = await clientFor(cmd.optsWithGlobals(), { autoStart: false });
7143
7342
  try {
7144
7343
  requireCloud3(client);
@@ -7149,11 +7348,11 @@ var rmCommand9 = new Command64("rm").alias("remove").description("remove a backu
7149
7348
  });
7150
7349
 
7151
7350
  // src/commands/volume/backup/index.ts
7152
- var backupCommand2 = new Command65("backup").description("back up a volume's disk to the kvbox cloud, list backups, restore or remove one").addCommand(createCommand4).addCommand(lsCommand9).addCommand(restoreCommand2).addCommand(rmCommand9);
7351
+ var backupCommand2 = new Command66("backup").description("back up a volume's disk to the kvbox cloud, list backups, restore or remove one").addCommand(createCommand4).addCommand(lsCommand9).addCommand(restoreCommand2).addCommand(rmCommand9);
7153
7352
  for (const cmd of backupCommand2.commands) cmd.option("--org <slug>", "act in this org (- for your personal volumes)");
7154
7353
 
7155
7354
  // src/commands/volume/create.ts
7156
- import { Command as Command66 } from "commander";
7355
+ import { Command as Command67 } from "commander";
7157
7356
  function parseGib2(text2, label = "--size") {
7158
7357
  const mib = parseMib(text2);
7159
7358
  if (mib === void 0 || mib % 1024 !== 0) throw new KvboxError(`${label} ${text2}: write whole GB, like 50 or 50GB`);
@@ -7169,7 +7368,7 @@ function sizeProblem(answer) {
7169
7368
  return err instanceof KvboxError ? err.message.replace(/^--size \S+: /, "") : String(err);
7170
7369
  }
7171
7370
  }
7172
- var createCommand5 = new Command66("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) => {
7371
+ var createCommand5 = new Command67("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) => {
7173
7372
  const ask = interactive();
7174
7373
  if (nameArg === void 0 || opts.size === void 0) askOrUsage("give the name and the size: kvbox volume create <name> --size <gb> --box <box>");
7175
7374
  const name = nameArg ?? await text("Volume name", { validate: (a) => VOLUME_NAME_RE.test(a) ? void 0 : VOLUME_NAME_RULE });
@@ -7202,8 +7401,8 @@ var createCommand5 = new Command66("create").alias("new").description("create a
7202
7401
  });
7203
7402
 
7204
7403
  // src/commands/volume/detach.ts
7205
- import { Command as Command67 } from "commander";
7206
- var detachCommand = new Command67("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) => {
7404
+ import { Command as Command68 } from "commander";
7405
+ var detachCommand = new Command68("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) => {
7207
7406
  if (volumeArg === void 0) askOrUsage("give the volume: kvbox volume detach <volume> [box]");
7208
7407
  const client = await clientFor(cmd.optsWithGlobals());
7209
7408
  try {
@@ -7228,8 +7427,8 @@ var detachCommand = new Command67("detach").description("detach a volume from a
7228
7427
  });
7229
7428
 
7230
7429
  // src/commands/volume/grow.ts
7231
- import { Command as Command68 } from "commander";
7232
- var growCommand = new Command68("grow").alias("resize").description("make a volume larger (a running box holding it is restarted once)").argument("<volume>", "volume name").argument("<GB>", "the new size in GB, larger than what it has").option("--json", "print the volume as JSON").action(async (name, size, opts, cmd) => {
7430
+ import { Command as Command69 } from "commander";
7431
+ var growCommand = new Command69("grow").alias("resize").description("make a volume larger (a running box holding it is restarted once)").argument("<volume>", "volume name").argument("<GB>", "the new size in GB, larger than what it has").option("--json", "print the volume as JSON").action(async (name, size, opts, cmd) => {
7233
7432
  const sizeGib = parseGib2(size, "size");
7234
7433
  const client = await clientFor(cmd.optsWithGlobals());
7235
7434
  try {
@@ -7242,8 +7441,8 @@ var growCommand = new Command68("grow").alias("resize").description("make a volu
7242
7441
  });
7243
7442
 
7244
7443
  // src/commands/volume/ls.ts
7245
- import { Command as Command69 } from "commander";
7246
- var lsCommand10 = new Command69("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) => {
7444
+ import { Command as Command70 } from "commander";
7445
+ var lsCommand10 = new Command70("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) => {
7247
7446
  const client = await clientFor(cmd.optsWithGlobals());
7248
7447
  try {
7249
7448
  const cloud = client.target.kind === "cloud";
@@ -7274,8 +7473,8 @@ var lsCommand10 = new Command69("ls").alias("list").description("list volumes: s
7274
7473
  });
7275
7474
 
7276
7475
  // src/commands/volume/rm.ts
7277
- import { Command as Command70 } from "commander";
7278
- var rmCommand10 = new Command70("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) => {
7476
+ import { Command as Command71 } from "commander";
7477
+ var rmCommand10 = new Command71("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) => {
7279
7478
  if (!await confirm(`Delete volume ${name} and everything on it?`, opts.yes ?? false)) {
7280
7479
  info("cancelled");
7281
7480
  process.exitCode = 1;
@@ -7291,15 +7490,18 @@ var rmCommand10 = new Command70("rm").alias("remove").description("delete a volu
7291
7490
  });
7292
7491
 
7293
7492
  // src/commands/volume/index.ts
7294
- var volumeCommand = new Command71("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(createCommand5).addCommand(lsCommand10).addCommand(attachCommand).addCommand(detachCommand).addCommand(growCommand).addCommand(rmCommand10);
7493
+ var volumeCommand = new Command72("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(createCommand5).addCommand(lsCommand10).addCommand(attachCommand).addCommand(detachCommand).addCommand(growCommand).addCommand(rmCommand10);
7295
7494
  for (const cmd of volumeCommand.commands) cmd.option("--org <slug>", "act in this org (- for your personal volumes)");
7296
7495
  volumeCommand.addCommand(backupCommand2);
7297
7496
 
7298
7497
  // src/commands/bucket/index.ts
7299
- import { Command as Command81 } from "commander";
7498
+ import { Command as Command87 } from "commander";
7300
7499
 
7301
- // src/commands/bucket/create.ts
7302
- import { Command as Command72 } from "commander";
7500
+ // src/commands/bucket/backup/index.ts
7501
+ import { Command as Command77 } from "commander";
7502
+
7503
+ // src/commands/bucket/backup/create.ts
7504
+ import { Command as Command73 } from "commander";
7303
7505
 
7304
7506
  // src/commands/bucket/shared.ts
7305
7507
  async function bucketClient(cmd) {
@@ -7324,8 +7526,124 @@ function printRows(rows2) {
7324
7526
  `);
7325
7527
  }
7326
7528
 
7529
+ // src/commands/bucket/backup/create.ts
7530
+ var createCommand6 = new Command73("create").description("back up your object storage (every bucket and key) to the kvbox cloud, encrypted").option("--wait", "stay until the backup is ready (by default it runs in the background)").option("--json", "print the backup as JSON").action(async (opts, cmd) => {
7531
+ const client = await bucketClient(cmd);
7532
+ const ls = "kvbox bucket backup ls";
7533
+ try {
7534
+ const started = await client.createStorageBackup();
7535
+ const what = `the object storage of ${started.owner}`;
7536
+ if (!opts.wait) {
7537
+ if (opts.json) json(started);
7538
+ else {
7539
+ info(`${color.green("\u2713")} backup ${started.id} of ${what} started (${started.buckets.length} ${started.buckets.length === 1 ? "bucket" : "buckets"}); it runs in the background`);
7540
+ info(color.dim(` status: ${ls}`));
7541
+ await printCost(client, false);
7542
+ }
7543
+ return;
7544
+ }
7545
+ const done = await spin(`backing up ${what}\u2026`, untilSettled(() => client.storageBackup(started.id), what, started.id, ls));
7546
+ if (opts.json) json(done);
7547
+ if (done.status === "failed") throw new KvboxError(`backup ${done.id} of ${what} failed: ${done.error ?? "no reason given"}`);
7548
+ if (opts.json) return;
7549
+ info(`${color.green("\u2713")} backup ${done.id} of ${what}: ${done.buckets.join(", ")}; ${sizeLine(done)}`);
7550
+ info(color.dim(` restore with: kvbox bucket backup restore ${done.id}`));
7551
+ await printCost(client, true);
7552
+ } finally {
7553
+ await client.close();
7554
+ }
7555
+ });
7556
+
7557
+ // src/commands/bucket/backup/ls.ts
7558
+ import { Command as Command74 } from "commander";
7559
+ var lsCommand11 = new Command74("ls").alias("list").description("list the backups of your object storage").option("--json", "print as JSON").action(async (opts, cmd) => {
7560
+ const client = await bucketClient(cmd);
7561
+ try {
7562
+ const list = await client.storageBackups();
7563
+ if (opts.json) {
7564
+ json(list);
7565
+ return;
7566
+ }
7567
+ if (list.length === 0) {
7568
+ info("no backups yet; make one with: kvbox bucket backup create");
7569
+ return;
7570
+ }
7571
+ const anyError = list.some((b) => b.error !== null);
7572
+ table(
7573
+ list.map((b) => ({
7574
+ id: b.id,
7575
+ status: b.status === "ready" ? color.green(b.status) : b.status === "failed" ? color.red(b.status) : color.yellow(b.status),
7576
+ buckets: b.buckets.join(","),
7577
+ keys: b.keys,
7578
+ data: b.dataBytes === null ? "-" : gbShort(b.dataBytes),
7579
+ uploaded: b.uploadedBytes === null ? "-" : gbShort(b.uploadedBytes),
7580
+ by: b.createdBy ?? "-",
7581
+ taken: age(b.createdAt),
7582
+ ...anyError ? { error: b.error ?? "" } : {}
7583
+ }))
7584
+ );
7585
+ } finally {
7586
+ await client.close();
7587
+ }
7588
+ });
7589
+
7590
+ // src/commands/bucket/backup/restore.ts
7591
+ import { Command as Command75 } from "commander";
7592
+ var restoreCommand3 = new Command75("restore").description("put a backup back: every bucket and key becomes the backup's (the storage restarts)").argument("<id>", "the backup's id (kvbox bucket backup ls)").option("-y, --yes", "do not ask for confirmation").option("--json", "print what changed as JSON").action(async (id, opts, cmd) => {
7593
+ const client = await bucketClient(cmd);
7594
+ try {
7595
+ const backup = await client.storageBackup(id);
7596
+ const what = `the object storage of ${backup.owner}`;
7597
+ const question = `Restore ${what} from backup ${backup.id} (${age(backup.createdAt)} ago, ${sizeLine(backup)}; buckets ${backup.buckets.join(", ")})? Everything written since is lost: buckets made since are removed with their files, and access keys made since stop working. It restarts.`;
7598
+ if (!await confirm(question, opts.yes ?? false)) {
7599
+ info("cancelled");
7600
+ process.exitCode = 1;
7601
+ return;
7602
+ }
7603
+ const done = await spin(`restoring ${what} from ${backup.id}\u2026`, client.restoreStorageBackup(id));
7604
+ if (opts.json) {
7605
+ json(done);
7606
+ return;
7607
+ }
7608
+ info(`${color.green("\u2713")} ${what} restored from backup ${backup.id}`);
7609
+ const list = (names2) => names2.join(", ");
7610
+ if (done.buckets.kept.length > 0) info(` buckets as they were then: ${list(done.buckets.kept)}`);
7611
+ if (done.buckets.returned.length > 0) info(` buckets back (removed since; no keys, make new ones): ${list(done.buckets.returned)}`);
7612
+ if (done.buckets.removed.length > 0) warn(` buckets gone (made since): ${list(done.buckets.removed)}`);
7613
+ if (done.keys.dropped.length > 0) warn(` keys that no longer work (made since): ${list(done.keys.dropped.map((k) => `${k.id} (${k.bucket}/${k.name})`))}`);
7614
+ if (done.keys.revoked.length > 0) info(` keys removed since stay removed: ${list(done.keys.revoked.map((k) => k.id))}`);
7615
+ for (const w of done.warnings) warn(` ${w}`);
7616
+ } finally {
7617
+ await client.close();
7618
+ }
7619
+ });
7620
+
7621
+ // src/commands/bucket/backup/rm.ts
7622
+ import { Command as Command76 } from "commander";
7623
+ var rmCommand11 = new Command76("rm").alias("remove").description("remove a backup of your object storage for good").argument("<id>", "the backup's id (kvbox bucket backup ls)").option("-y, --yes", "do not ask for confirmation").action(async (id, opts, cmd) => {
7624
+ const client = await bucketClient(cmd);
7625
+ try {
7626
+ const backup = (await client.storageBackups()).find((b) => b.id === id);
7627
+ if (!backup) throw new NotFoundError(`backup ${id} of your object storage`);
7628
+ const question = `Remove backup ${backup.id} of the object storage of ${backup.owner} (${age(backup.createdAt)} ago, ${backup.status === "ready" ? sizeLine(backup) : backup.status})? It cannot be restored after this.`;
7629
+ if (!await confirm(question, opts.yes ?? false)) {
7630
+ info("cancelled");
7631
+ process.exitCode = 1;
7632
+ return;
7633
+ }
7634
+ await client.removeBackup(backup.id);
7635
+ info(`${color.green("\u2713")} backup ${backup.id} of the object storage of ${backup.owner} removed`);
7636
+ } finally {
7637
+ await client.close();
7638
+ }
7639
+ });
7640
+
7641
+ // src/commands/bucket/backup/index.ts
7642
+ var backupCommand3 = new Command77("backup").aliases(["backups"]).description("back up your object storage to the kvbox cloud, list backups, restore or remove one").addCommand(createCommand6).addCommand(lsCommand11).addCommand(restoreCommand3).addCommand(rmCommand11);
7643
+
7327
7644
  // src/commands/bucket/create.ts
7328
- var createCommand6 = new Command72("create").description("make a bucket (the first one also makes your object storage)").argument("<name>", "bucket name: 3-63 lowercase letters, digits and '-'").option("--size <GB>", "how much your object storage may hold, when this is your first bucket (default 10)").option("--region <region>", "the S3 region of your object storage (ro-west-1, de-center-1), when this is your first bucket").option("--near <box>", "put the object storage on the host of this box, when this is your first bucket").option("--json", "print as JSON").action(async (name, opts, cmd) => {
7645
+ import { Command as Command78 } from "commander";
7646
+ var createCommand7 = new Command78("create").description("make a bucket (the first one also makes your object storage)").argument("<name>", "bucket name: 3-63 lowercase letters, digits and '-'").option("--size <GB>", "how much your object storage may hold, when this is your first bucket (default 10)").option("--region <region>", "the S3 region of your object storage (ro-west-1, de-center-1), when this is your first bucket").option("--near <box>", "put the object storage on the host of this box, when this is your first bucket").option("--json", "print as JSON").action(async (name, opts, cmd) => {
7329
7647
  const sizeGib = opts.size === void 0 ? void 0 : parseGib2(opts.size);
7330
7648
  const client = await bucketClient(cmd);
7331
7649
  try {
@@ -7345,8 +7663,8 @@ var createCommand6 = new Command72("create").description("make a bucket (the fir
7345
7663
  });
7346
7664
 
7347
7665
  // src/commands/bucket/grow.ts
7348
- import { Command as Command73 } from "commander";
7349
- var growCommand2 = new Command73("grow").description("make your object storage larger (all your buckets share it; it restarts once)").argument("<GB>", "the new size in GB, larger than what it has").option("--json", "print the object storage as JSON").action(async (size, opts, cmd) => {
7666
+ import { Command as Command79 } from "commander";
7667
+ var growCommand2 = new Command79("grow").description("make your object storage larger (all your buckets share it; it restarts once)").argument("<GB>", "the new size in GB, larger than what it has").option("--json", "print the object storage as JSON").action(async (size, opts, cmd) => {
7350
7668
  const sizeGib = parseGib2(size, "size");
7351
7669
  const client = await bucketClient(cmd);
7352
7670
  try {
@@ -7359,8 +7677,8 @@ var growCommand2 = new Command73("grow").description("make your object storage l
7359
7677
  });
7360
7678
 
7361
7679
  // src/commands/bucket/info.ts
7362
- import { Command as Command74 } from "commander";
7363
- var infoCommand = new Command74("info").description("one bucket: its address, what it holds, how full your object storage is").argument("<name>", "bucket name").option("--json", "print as JSON").action(async (name, opts, cmd) => {
7680
+ import { Command as Command80 } from "commander";
7681
+ var infoCommand = new Command80("info").description("one bucket: its address, what it holds, how full your object storage is").argument("<name>", "bucket name").option("--json", "print as JSON").action(async (name, opts, cmd) => {
7364
7682
  const client = await bucketClient(cmd);
7365
7683
  try {
7366
7684
  const b = await client.getBucket(name);
@@ -7389,11 +7707,11 @@ with the AWS CLI: aws s3 ls s3://${b.name} --endpoint-url ${b.endpoint}`));
7389
7707
  });
7390
7708
 
7391
7709
  // src/commands/bucket/key/index.ts
7392
- import { Command as Command78 } from "commander";
7710
+ import { Command as Command84 } from "commander";
7393
7711
 
7394
7712
  // src/commands/bucket/key/create.ts
7395
- import { Command as Command75 } from "commander";
7396
- var createCommand7 = new Command75("create").description("make an access key for a bucket (the secret is shown once)").argument("<bucket>", "bucket name").option("--name <label>", "what to call the key, to tell it from the others").option("--read-only", "the key reads the bucket but cannot write to it").option("--json", "print as JSON").action(async (bucket, opts, cmd) => {
7713
+ import { Command as Command81 } from "commander";
7714
+ var createCommand8 = new Command81("create").description("make an access key for a bucket (the secret is shown once)").argument("<bucket>", "bucket name").option("--name <label>", "what to call the key, to tell it from the others").option("--read-only", "the key reads the bucket but cannot write to it").option("--json", "print as JSON").action(async (bucket, opts, cmd) => {
7397
7715
  const client = await bucketClient(cmd);
7398
7716
  try {
7399
7717
  const key = await client.createBucketKey(bucket, { ...opts.name !== void 0 ? { name: opts.name } : {}, ...opts.readOnly ? { readOnly: true } : {} });
@@ -7416,8 +7734,8 @@ var createCommand7 = new Command75("create").description("make an access key for
7416
7734
  });
7417
7735
 
7418
7736
  // src/commands/bucket/key/ls.ts
7419
- import { Command as Command76 } from "commander";
7420
- var lsCommand11 = new Command76("ls").alias("list").description("list a bucket's access keys (never their secrets)").argument("<bucket>", "bucket name").option("--json", "print as JSON").action(async (bucket, opts, cmd) => {
7737
+ import { Command as Command82 } from "commander";
7738
+ var lsCommand12 = new Command82("ls").alias("list").description("list a bucket's access keys (never their secrets)").argument("<bucket>", "bucket name").option("--json", "print as JSON").action(async (bucket, opts, cmd) => {
7421
7739
  const client = await bucketClient(cmd);
7422
7740
  try {
7423
7741
  const keys = await client.listBucketKeys(bucket);
@@ -7436,8 +7754,8 @@ var lsCommand11 = new Command76("ls").alias("list").description("list a bucket's
7436
7754
  });
7437
7755
 
7438
7756
  // src/commands/bucket/key/rm.ts
7439
- import { Command as Command77 } from "commander";
7440
- var rmCommand11 = new Command77("rm").alias("remove").description("delete an access key: whatever uses it stops reaching the bucket").argument("<bucket>", "bucket name").argument("<access-key>", "the access key id (kvbox bucket key ls)").option("-y, --yes", "do not ask for confirmation").action(async (bucket, id, opts, cmd) => {
7757
+ import { Command as Command83 } from "commander";
7758
+ var rmCommand12 = new Command83("rm").alias("remove").description("delete an access key: whatever uses it stops reaching the bucket").argument("<bucket>", "bucket name").argument("<access-key>", "the access key id (kvbox bucket key ls)").option("-y, --yes", "do not ask for confirmation").action(async (bucket, id, opts, cmd) => {
7441
7759
  const client = await bucketClient(cmd);
7442
7760
  try {
7443
7761
  if (!await confirm(`Delete key ${id} of bucket ${bucket}? Whatever uses it stops working.`, opts.yes ?? false)) {
@@ -7453,11 +7771,11 @@ var rmCommand11 = new Command77("rm").alias("remove").description("delete an acc
7453
7771
  });
7454
7772
 
7455
7773
  // src/commands/bucket/key/index.ts
7456
- var keyCommand2 = new Command78("key").aliases(["keys"]).description("access keys of a bucket: what your app signs in with").addCommand(createCommand7).addCommand(lsCommand11).addCommand(rmCommand11);
7774
+ var keyCommand2 = new Command84("key").aliases(["keys"]).description("access keys of a bucket: what your app signs in with").addCommand(createCommand8).addCommand(lsCommand12).addCommand(rmCommand12);
7457
7775
 
7458
7776
  // src/commands/bucket/ls.ts
7459
- import { Command as Command79 } from "commander";
7460
- var lsCommand12 = new Command79("ls").alias("list").description("list buckets, and the object storage they are in").option("-a, --all", "every bucket on the platform (platform admins only)").option("--json", "print as JSON").action(async (opts, cmd) => {
7777
+ import { Command as Command85 } from "commander";
7778
+ var lsCommand13 = new Command85("ls").alias("list").description("list buckets, and the object storage they are in").option("-a, --all", "every bucket on the platform (platform admins only)").option("--json", "print as JSON").action(async (opts, cmd) => {
7461
7779
  const client = await bucketClient(cmd);
7462
7780
  try {
7463
7781
  const buckets = await client.listBuckets({ all: opts.all });
@@ -7487,8 +7805,8 @@ var lsCommand12 = new Command79("ls").alias("list").description("list buckets, a
7487
7805
  });
7488
7806
 
7489
7807
  // src/commands/bucket/rm.ts
7490
- import { Command as Command80 } from "commander";
7491
- var rmCommand12 = new Command80("rm").alias("remove").description("delete an empty bucket and its keys (the last one takes your object storage with it)").argument("<name>", "bucket name").option("--force", "your last bucket only: delete it with everything in it").option("-y, --yes", "do not ask for confirmation").action(async (name, opts, cmd) => {
7808
+ import { Command as Command86 } from "commander";
7809
+ var rmCommand13 = new Command86("rm").alias("remove").description("delete an empty bucket and its keys (the last one takes your object storage with it)").argument("<name>", "bucket name").option("--force", "your last bucket only: delete it with everything in it").option("-y, --yes", "do not ask for confirmation").action(async (name, opts, cmd) => {
7492
7810
  const client = await bucketClient(cmd);
7493
7811
  try {
7494
7812
  const question = opts.force ? `Delete bucket ${name} with everything in it, and the object storage it is in?` : `Delete bucket ${name} and its keys?`;
@@ -7507,18 +7825,18 @@ var rmCommand12 = new Command80("rm").alias("remove").description("delete an emp
7507
7825
  });
7508
7826
 
7509
7827
  // src/commands/bucket/index.ts
7510
- var bucketCommand = new Command81("bucket").aliases(["buckets"]).description("object storage: S3 buckets for your files, and the access keys your apps use").addCommand(createCommand6).addCommand(lsCommand12).addCommand(infoCommand).addCommand(growCommand2).addCommand(rmCommand12).addCommand(keyCommand2);
7828
+ var bucketCommand = new Command87("bucket").aliases(["buckets"]).description("object storage: S3 buckets for your files, and the access keys your apps use").addCommand(createCommand7).addCommand(lsCommand13).addCommand(infoCommand).addCommand(growCommand2).addCommand(rmCommand13).addCommand(keyCommand2).addCommand(backupCommand3);
7511
7829
  var withOrg = (cmd) => cmd.option("--org <slug>", "act in this org (- for your personal buckets)");
7512
7830
  for (const cmd of bucketCommand.commands) {
7513
- if (cmd === keyCommand2) cmd.commands.forEach(withOrg);
7831
+ if (cmd === keyCommand2 || cmd === backupCommand3) cmd.commands.forEach(withOrg);
7514
7832
  else withOrg(cmd);
7515
7833
  }
7516
7834
 
7517
7835
  // src/commands/cron/index.ts
7518
- import { Command as Command94 } from "commander";
7836
+ import { Command as Command100 } from "commander";
7519
7837
 
7520
7838
  // src/commands/cron/create.ts
7521
- import { Command as Command82 } from "commander";
7839
+ import { Command as Command88 } from "commander";
7522
7840
 
7523
7841
  // src/commands/cron/shared.ts
7524
7842
  async function cronClient(cmd) {
@@ -7579,7 +7897,7 @@ function printRows2(rows2) {
7579
7897
  var noTriggers = (service) => info(`cron service ${service} has no triggers yet; add one with: kvbox cron trigger add ${service} <box> "0 6 * * *" --port 3000 (or --run "<command>")`);
7580
7898
 
7581
7899
  // src/commands/cron/create.ts
7582
- var createCommand8 = new Command82("create").description("make a cron service: a named set of triggers").argument("<name>", "what to call it (lowercase letters, digits and '-')").option("--json", "print as JSON").action(async (name, opts, cmd) => {
7900
+ var createCommand9 = new Command88("create").description("make a cron service: a named set of triggers").argument("<name>", "what to call it (lowercase letters, digits and '-')").option("--json", "print as JSON").action(async (name, opts, cmd) => {
7583
7901
  const client = await cronClient(cmd);
7584
7902
  try {
7585
7903
  const service = await client.createCronService(name);
@@ -7596,8 +7914,8 @@ var createCommand8 = new Command82("create").description("make a cron service: a
7596
7914
  });
7597
7915
 
7598
7916
  // src/commands/cron/info.ts
7599
- import { Command as Command83 } from "commander";
7600
- var infoCommand2 = new Command83("info").alias("get").description("show a cron service and its triggers").argument("<name>", "cron service name").option("--json", "print as JSON").action(async (name, opts, cmd) => {
7917
+ import { Command as Command89 } from "commander";
7918
+ var infoCommand2 = new Command89("info").alias("get").description("show a cron service and its triggers").argument("<name>", "cron service name").option("--json", "print as JSON").action(async (name, opts, cmd) => {
7601
7919
  const client = await cronClient(cmd);
7602
7920
  try {
7603
7921
  const service = await client.getCronService(name);
@@ -7621,8 +7939,8 @@ var infoCommand2 = new Command83("info").alias("get").description("show a cron s
7621
7939
  });
7622
7940
 
7623
7941
  // src/commands/cron/ls.ts
7624
- import { Command as Command84 } from "commander";
7625
- var lsCommand13 = new Command84("ls").alias("list").description("list cron services").option("-a, --all", "every cron service on the platform (platform admins only)").option("--json", "print as JSON").action(async (opts, cmd) => {
7942
+ import { Command as Command90 } from "commander";
7943
+ var lsCommand14 = new Command90("ls").alias("list").description("list cron services").option("-a, --all", "every cron service on the platform (platform admins only)").option("--json", "print as JSON").action(async (opts, cmd) => {
7626
7944
  const client = await cronClient(cmd);
7627
7945
  try {
7628
7946
  const services = await client.listCronServices({ all: opts.all });
@@ -7642,8 +7960,8 @@ var lsCommand13 = new Command84("ls").alias("list").description("list cron servi
7642
7960
  });
7643
7961
 
7644
7962
  // src/commands/cron/rm.ts
7645
- import { Command as Command85 } from "commander";
7646
- var rmCommand13 = new Command85("rm").alias("remove").description("delete a cron service, its triggers and their run history").argument("<name>", "cron service name").option("-y, --yes", "do not ask for confirmation").action(async (name, opts, cmd) => {
7963
+ import { Command as Command91 } from "commander";
7964
+ var rmCommand14 = new Command91("rm").alias("remove").description("delete a cron service, its triggers and their run history").argument("<name>", "cron service name").option("-y, --yes", "do not ask for confirmation").action(async (name, opts, cmd) => {
7647
7965
  const client = await cronClient(cmd);
7648
7966
  try {
7649
7967
  if (!await confirm(`Delete cron service ${name}? Its triggers stop firing and their run history is deleted.`, opts.yes ?? false)) {
@@ -7659,10 +7977,10 @@ var rmCommand13 = new Command85("rm").alias("remove").description("delete a cron
7659
7977
  });
7660
7978
 
7661
7979
  // src/commands/cron/trigger/index.ts
7662
- import { Command as Command93 } from "commander";
7980
+ import { Command as Command99 } from "commander";
7663
7981
 
7664
7982
  // src/commands/cron/trigger/add.ts
7665
- import { Command as Command86 } from "commander";
7983
+ import { Command as Command92 } from "commander";
7666
7984
  function portOf(value) {
7667
7985
  const n = Number(value);
7668
7986
  if (!Number.isInteger(n) || n < 1 || n > 65535) throw new KvboxError(`--port ${value}: a port is a number from 1 to 65535`);
@@ -7682,7 +8000,7 @@ function timeoutOf(value) {
7682
8000
  if (sec > MAX_CRON_COMMAND_TIMEOUT_SEC) throw new KvboxError(`--timeout ${value}: a command may run for ${MAX_CRON_COMMAND_TIMEOUT_SEC / 60} minutes at most`);
7683
8001
  return sec;
7684
8002
  }
7685
- var addCommand3 = new Command86("add").description("add a trigger: on a schedule, call a port of a box or run a command in it").argument("<service>", "cron service name").argument("<box>", "the box it acts on").argument("<expr>", 'cron expression in quotes, five fields: "0 6 * * *" is every day at 06:00').option("--port <n>", "call this port, the one your app listens on in the box").option("--path <path>", "with --port: path and query to request (default: /)").option("--method <method>", `with --port: HTTP method, ${CRON_METHODS.join(" or ")} (default: POST)`).option("--run <command>", 'or run this command in the box, in quotes: "node ~/app/embed.js"').option("--timeout <duration>", `with --run: stop the command after this long (90s, 10m, 1h; default: ${DEFAULT_CRON_COMMAND_TIMEOUT_SEC / 60}m)`).option("--tz <zone>", "time zone the schedule is read in, like Europe/Bucharest", "UTC").option("--json", "print as JSON").action(async (service, box2, expr, opts, cmd) => {
8003
+ var addCommand3 = new Command92("add").description("add a trigger: on a schedule, call a port of a box or run a command in it").argument("<service>", "cron service name").argument("<box>", "the box it acts on").argument("<expr>", 'cron expression in quotes, five fields: "0 6 * * *" is every day at 06:00').option("--port <n>", "call this port, the one your app listens on in the box").option("--path <path>", "with --port: path and query to request (default: /)").option("--method <method>", `with --port: HTTP method, ${CRON_METHODS.join(" or ")} (default: POST)`).option("--run <command>", 'or run this command in the box, in quotes: "node ~/app/embed.js"').option("--timeout <duration>", `with --run: stop the command after this long (90s, 10m, 1h; default: ${DEFAULT_CRON_COMMAND_TIMEOUT_SEC / 60}m)`).option("--tz <zone>", "time zone the schedule is read in, like Europe/Bucharest", "UTC").option("--json", "print as JSON").action(async (service, box2, expr, opts, cmd) => {
7686
8004
  let action;
7687
8005
  if (opts.run !== void 0) {
7688
8006
  if (opts.port !== void 0 || opts.path !== void 0 || opts.method !== void 0) throw new KvboxError("a trigger runs a command or calls a port: use --run, or --port with --path and --method, not both");
@@ -7709,8 +8027,8 @@ var addCommand3 = new Command86("add").description("add a trigger: on a schedule
7709
8027
  });
7710
8028
 
7711
8029
  // src/commands/cron/trigger/ls.ts
7712
- import { Command as Command87 } from "commander";
7713
- var lsCommand14 = new Command87("ls").alias("list").description("list a cron service's triggers").argument("<service>", "cron service name").option("--json", "print as JSON").action(async (service, opts, cmd) => {
8030
+ import { Command as Command93 } from "commander";
8031
+ var lsCommand15 = new Command93("ls").alias("list").description("list a cron service's triggers").argument("<service>", "cron service name").option("--json", "print as JSON").action(async (service, opts, cmd) => {
7714
8032
  const client = await cronClient(cmd);
7715
8033
  try {
7716
8034
  const triggers = await client.listCronTriggers(service);
@@ -7726,8 +8044,8 @@ var lsCommand14 = new Command87("ls").alias("list").description("list a cron ser
7726
8044
  });
7727
8045
 
7728
8046
  // src/commands/cron/trigger/pause.ts
7729
- import { Command as Command88 } from "commander";
7730
- var pauseCommand2 = new Command88("pause").description("stop a trigger from firing until it is resumed").argument("<service>", "cron service name").argument("<id>", "trigger id (kvbox cron trigger ls)").option("--json", "print as JSON").action(async (service, id, opts, cmd) => {
8047
+ import { Command as Command94 } from "commander";
8048
+ var pauseCommand2 = new Command94("pause").description("stop a trigger from firing until it is resumed").argument("<service>", "cron service name").argument("<id>", "trigger id (kvbox cron trigger ls)").option("--json", "print as JSON").action(async (service, id, opts, cmd) => {
7731
8049
  const client = await cronClient(cmd);
7732
8050
  try {
7733
8051
  const trigger = await client.setCronTriggerEnabled(service, id, false);
@@ -7742,8 +8060,8 @@ var pauseCommand2 = new Command88("pause").description("stop a trigger from firi
7742
8060
  });
7743
8061
 
7744
8062
  // src/commands/cron/trigger/resume.ts
7745
- import { Command as Command89 } from "commander";
7746
- var resumeCommand2 = new Command89("resume").description("let a paused trigger fire again").argument("<service>", "cron service name").argument("<id>", "trigger id (kvbox cron trigger ls)").option("--json", "print as JSON").action(async (service, id, opts, cmd) => {
8063
+ import { Command as Command95 } from "commander";
8064
+ var resumeCommand2 = new Command95("resume").description("let a paused trigger fire again").argument("<service>", "cron service name").argument("<id>", "trigger id (kvbox cron trigger ls)").option("--json", "print as JSON").action(async (service, id, opts, cmd) => {
7747
8065
  const client = await cronClient(cmd);
7748
8066
  try {
7749
8067
  const trigger = await client.setCronTriggerEnabled(service, id, true);
@@ -7758,8 +8076,8 @@ var resumeCommand2 = new Command89("resume").description("let a paused trigger f
7758
8076
  });
7759
8077
 
7760
8078
  // src/commands/cron/trigger/rm.ts
7761
- import { Command as Command90 } from "commander";
7762
- var rmCommand14 = new Command90("rm").alias("remove").description("delete a trigger and its run history").argument("<service>", "cron service name").argument("<id>", "trigger id (kvbox cron trigger ls)").option("-y, --yes", "do not ask for confirmation").action(async (service, id, opts, cmd) => {
8079
+ import { Command as Command96 } from "commander";
8080
+ var rmCommand15 = new Command96("rm").alias("remove").description("delete a trigger and its run history").argument("<service>", "cron service name").argument("<id>", "trigger id (kvbox cron trigger ls)").option("-y, --yes", "do not ask for confirmation").action(async (service, id, opts, cmd) => {
7763
8081
  const client = await cronClient(cmd);
7764
8082
  try {
7765
8083
  if (!await confirm(`Delete trigger ${id} of cron service ${service}? Its run history is deleted too.`, opts.yes ?? false)) {
@@ -7775,8 +8093,8 @@ var rmCommand14 = new Command90("rm").alias("remove").description("delete a trig
7775
8093
  });
7776
8094
 
7777
8095
  // src/commands/cron/trigger/run.ts
7778
- import { Command as Command91 } from "commander";
7779
- var runCommand = new Command91("run").description("fire a trigger now, once, besides its schedule").argument("<service>", "cron service name").argument("<id>", "trigger id (kvbox cron trigger ls)").option("--json", "print as JSON").action(async (service, id, opts, cmd) => {
8096
+ import { Command as Command97 } from "commander";
8097
+ var runCommand = new Command97("run").description("fire a trigger now, once, besides its schedule").argument("<service>", "cron service name").argument("<id>", "trigger id (kvbox cron trigger ls)").option("--json", "print as JSON").action(async (service, id, opts, cmd) => {
7780
8098
  const client = await cronClient(cmd);
7781
8099
  try {
7782
8100
  const trigger = await client.runCronTrigger(service, id);
@@ -7792,13 +8110,13 @@ var runCommand = new Command91("run").description("fire a trigger now, once, bes
7792
8110
  });
7793
8111
 
7794
8112
  // src/commands/cron/trigger/runs.ts
7795
- import { Command as Command92 } from "commander";
8113
+ import { Command as Command98 } from "commander";
7796
8114
  function limitOf(value) {
7797
8115
  const n = Number(value);
7798
8116
  if (!Number.isInteger(n) || n < 1) throw new KvboxError(`-n ${value}: a number of runs, 1 or more`);
7799
8117
  return n;
7800
8118
  }
7801
- var runsCommand = new Command92("runs").aliases(["logs"]).description("show how a trigger's last runs ended").argument("<service>", "cron service name").argument("<id>", "trigger id (kvbox cron trigger ls)").option("-n, --limit <count>", "how many runs to show", "20").option("--json", "print as JSON").action(async (service, id, opts, cmd) => {
8119
+ var runsCommand = new Command98("runs").aliases(["logs"]).description("show how a trigger's last runs ended").argument("<service>", "cron service name").argument("<id>", "trigger id (kvbox cron trigger ls)").option("-n, --limit <count>", "how many runs to show", "20").option("--json", "print as JSON").action(async (service, id, opts, cmd) => {
7802
8120
  const limit = limitOf(opts.limit);
7803
8121
  const client = await cronClient(cmd);
7804
8122
  try {
@@ -7828,10 +8146,10 @@ var runsCommand = new Command92("runs").aliases(["logs"]).description("show how
7828
8146
  });
7829
8147
 
7830
8148
  // src/commands/cron/trigger/index.ts
7831
- var triggerCommand = new Command93("trigger").aliases(["triggers"]).description("a cron service's triggers: a schedule and the request it sends to a box").addCommand(addCommand3).addCommand(lsCommand14).addCommand(runsCommand).addCommand(runCommand).addCommand(pauseCommand2).addCommand(resumeCommand2).addCommand(rmCommand14);
8149
+ var triggerCommand = new Command99("trigger").aliases(["triggers"]).description("a cron service's triggers: a schedule and the request it sends to a box").addCommand(addCommand3).addCommand(lsCommand15).addCommand(runsCommand).addCommand(runCommand).addCommand(pauseCommand2).addCommand(resumeCommand2).addCommand(rmCommand15);
7832
8150
 
7833
8151
  // src/commands/cron/index.ts
7834
- var cronCommand = new Command94("cron").description("cron: call a box on a schedule, waking it first if it sleeps").addCommand(createCommand8).addCommand(lsCommand13).addCommand(infoCommand2).addCommand(rmCommand13).addCommand(triggerCommand);
8152
+ var cronCommand = new Command100("cron").description("cron: call a box on a schedule, waking it first if it sleeps").addCommand(createCommand9).addCommand(lsCommand14).addCommand(infoCommand2).addCommand(rmCommand14).addCommand(triggerCommand);
7835
8153
  var withOrg2 = (cmd) => cmd.option("--org <slug>", "act in this org (- for your personal cron services)");
7836
8154
  for (const cmd of cronCommand.commands) {
7837
8155
  if (cmd === triggerCommand) cmd.commands.forEach(withOrg2);
@@ -7839,13 +8157,13 @@ for (const cmd of cronCommand.commands) {
7839
8157
  }
7840
8158
 
7841
8159
  // src/commands/managed/kind.ts
7842
- import { Command as Command112 } from "commander";
8160
+ import { Command as Command119 } from "commander";
7843
8161
 
7844
8162
  // src/commands/managed/backup/index.ts
7845
- import { Command as Command100 } from "commander";
8163
+ import { Command as Command107 } from "commander";
7846
8164
 
7847
8165
  // src/commands/managed/backup/create.ts
7848
- import { Command as Command96 } from "commander";
8166
+ import { Command as Command102 } from "commander";
7849
8167
 
7850
8168
  // src/commands/managed/shared.ts
7851
8169
  import "commander";
@@ -7900,10 +8218,25 @@ function infoRows(spec, m, user) {
7900
8218
  rows2.push(...settingRows(spec, m.settings), ["password", color.dim(`kvbox ${spec.command} password ${name}`)]);
7901
8219
  rows2.push(["private", `${m.urls.private} ${color.dim(m.links.length > 0 ? `(from ${m.links.join(", ")})` : `(no box is linked: kvbox ${spec.command} link ${name} <box>)`)}`]);
7902
8220
  rows2.push(["public", m.urls.public ?? color.dim(`off (kvbox ${spec.command} public ${name} on)`)]);
8221
+ if (m.backupSchedule !== null) rows2.push(["backups", scheduleText2(spec, name, m.backupSchedule)]);
7903
8222
  rows2.push(["cost", `${money(m.price.perMonth, m.price.currency)} a month while it runs, ${money(m.price.storagePerMonth, m.price.currency)} stopped ${color.dim("(estimated)")}`]);
7904
8223
  rows2.push(["created", `${age(m.createdAt)}${m.createdBy ? ` by ${m.createdBy}` : ""}`]);
7905
8224
  return rows2;
7906
8225
  }
8226
+ function scheduleText2(spec, name, s, now = Date.now()) {
8227
+ const at = `${String(s.hour).padStart(2, "0")}:00 UTC`;
8228
+ if (!s.enabled) return color.dim(`not on their own (kvbox ${spec.command} backup schedule ${name} --on, at ${at})`);
8229
+ const nextMs = s.nextAt === null ? null : Date.parse(s.nextAt) - now;
8230
+ const next = s.nextAt === null || nextMs === null ? "" : nextMs > -6e4 ? `, next in ${inHours(nextMs)}` : `, ${color.yellow(`due since ${s.nextAt.slice(0, 16).replace("T", " ")} UTC, waiting for the backup job`)}`;
8231
+ const failed = s.lastError !== null ? color.yellow(` last one failed: ${s.lastError}`) : "";
8232
+ return `daily at ${at}${next}${failed}`;
8233
+ }
8234
+ function inHours(ms) {
8235
+ const min = Math.max(0, Math.round(ms / 6e4));
8236
+ if (min < 60) return `${min}m`;
8237
+ const h = Math.floor(min / 60);
8238
+ return h < 24 ? `${h}h ${min % 60}m` : `${Math.floor(h / 24)}d ${h % 24}h`;
8239
+ }
7907
8240
  function printRows3(rows2) {
7908
8241
  const width2 = Math.max(...rows2.map(([label]) => label.length));
7909
8242
  for (const [label, value] of rows2) process.stdout.write(`${color.dim(label.padEnd(width2))} ${value}
@@ -7928,7 +8261,7 @@ function parseStorage(text2, flag) {
7928
8261
  }
7929
8262
 
7930
8263
  // src/commands/managed/backup/create.ts
7931
- var createCommand9 = (spec) => new Command96("create").description("back up a database to the kvbox cloud (encrypted)").argument("<db>", "its name").option("--wait", "stay until the backup is ready (by default it runs in the background)").option("--json", "print the backup as JSON").action(async (name, opts, cmd) => {
8264
+ var createCommand10 = (spec) => new Command102("create").description("back up a database to the kvbox cloud (encrypted)").argument("<db>", "its name").option("--wait", "stay until the backup is ready (by default it runs in the background)").option("--json", "print the backup as JSON").action(async (name, opts, cmd) => {
7932
8265
  const client = await managedClient(cmd);
7933
8266
  const ls = `kvbox ${spec.command} backup ls ${name}`;
7934
8267
  try {
@@ -7938,6 +8271,7 @@ var createCommand9 = (spec) => new Command96("create").description("back up a da
7938
8271
  else {
7939
8272
  info(`${color.green("\u2713")} backup ${started.id} of database ${color.bold(name)} started; it runs in the background`);
7940
8273
  info(color.dim(` status: ${ls}`));
8274
+ await printCost(client, false, true);
7941
8275
  }
7942
8276
  return;
7943
8277
  }
@@ -7947,47 +8281,67 @@ var createCommand9 = (spec) => new Command96("create").description("back up a da
7947
8281
  if (opts.json) return;
7948
8282
  info(`${color.green("\u2713")} backup ${done.id} of database ${color.bold(name)}: ${sizeLine(done)}`);
7949
8283
  info(color.dim(` restore with: kvbox ${spec.command} backup restore ${name} ${done.id}`));
8284
+ await printCost(client, true, true);
7950
8285
  } finally {
7951
8286
  await client.close();
7952
8287
  }
7953
8288
  });
7954
8289
 
7955
8290
  // src/commands/managed/backup/ls.ts
7956
- import { Command as Command97 } from "commander";
7957
- var lsCommand15 = (spec) => new Command97("ls").alias("list").description("list backups: every database's, or one database's").argument("[db]", "its name (default: every database)").option("--json", "print as JSON").action(async (name, opts, cmd) => {
7958
- const client = await managedClient(cmd);
7959
- try {
7960
- const list = name === void 0 ? await client.listManagedBackups(spec.kind) : await client.managedBackups(spec.kind, name);
7961
- if (opts.json) {
7962
- json(list);
7963
- return;
7964
- }
7965
- if (list.length === 0) {
7966
- info(name === void 0 ? `no backups yet; make one with: kvbox ${spec.command} backup create <db>` : `database ${name} has no backups; make one with: kvbox ${spec.command} backup create ${name}`);
7967
- return;
8291
+ import { Command as Command103 } from "commander";
8292
+ var lsCommand16 = (spec) => {
8293
+ const removedOnes = async (err, name, client) => {
8294
+ if (!(err instanceof CallError && err.status === 404)) throw err;
8295
+ const gone = (await client.listManagedBackups(spec.kind)).filter((b) => b.name === name || `${b.owner}/${b.name}` === name);
8296
+ if (gone.length === 0) throw err;
8297
+ const own = name.includes("/") ? [] : gone.filter((b) => b.owner === me(client));
8298
+ return own.length > 0 ? own : gone;
8299
+ };
8300
+ return new Command103("ls").alias("list").description("list backups: every database's, or one database's").argument("[db]", "its name (default: every database)").option("--json", "print as JSON").action(async (name, opts, cmd) => {
8301
+ const client = await managedClient(cmd);
8302
+ try {
8303
+ const list = name === void 0 ? await client.listManagedBackups(spec.kind) : await client.managedBackups(spec.kind, name).catch((err) => removedOnes(err, name, client));
8304
+ if (opts.json) {
8305
+ json(list);
8306
+ return;
8307
+ }
8308
+ const schedule = name === void 0 ? null : await client.managedBackupSchedule(spec.kind, name).catch(() => null);
8309
+ const footer = () => {
8310
+ if (schedule !== null) info(`${color.dim("on its own:")} ${scheduleText2(spec, name, schedule)}`);
8311
+ };
8312
+ if (list.length === 0) {
8313
+ info(name === void 0 ? `no backups yet; make one with: kvbox ${spec.command} backup create <db>` : `database ${name} has no backups; make one with: kvbox ${spec.command} backup create ${name}`);
8314
+ footer();
8315
+ return;
8316
+ }
8317
+ const anyError = list.some((b) => b.error !== null);
8318
+ const others = [...new Set(list.filter((b) => b.owner !== me(client)).map((b) => b.owner))];
8319
+ table(
8320
+ list.map((b) => ({
8321
+ id: b.id,
8322
+ ...name === void 0 || others.length > 0 ? { database: b.owner === me(client) ? b.name : `${b.owner}/${b.name}` } : {},
8323
+ status: b.status === "ready" ? color.green(b.status) : b.status === "failed" ? color.red(b.status) : color.yellow(b.status),
8324
+ version: b.version,
8325
+ data: b.dataBytes === null ? "-" : gbShort(b.dataBytes),
8326
+ uploaded: b.uploadedBytes === null ? "-" : gbShort(b.uploadedBytes),
8327
+ by: b.scheduled ? color.dim("schedule") : b.createdBy ?? "-",
8328
+ taken: age(b.createdAt),
8329
+ ...anyError ? { error: b.error ?? "" } : {}
8330
+ }))
8331
+ );
8332
+ footer();
8333
+ if (name !== void 0 && others.length > 0) {
8334
+ info(color.dim(`A backup of ${others.join(", ")} makes a database there: kvbox ${spec.command} create <name> --from-backup <id> --org ${others[0]}`));
8335
+ }
8336
+ } finally {
8337
+ await client.close();
7968
8338
  }
7969
- const anyError = list.some((b) => b.error !== null);
7970
- table(
7971
- list.map((b) => ({
7972
- id: b.id,
7973
- ...name === void 0 ? { database: b.owner === me(client) ? b.name : `${b.owner}/${b.name}` } : {},
7974
- status: b.status === "ready" ? color.green(b.status) : b.status === "failed" ? color.red(b.status) : color.yellow(b.status),
7975
- version: b.version,
7976
- data: b.dataBytes === null ? "-" : gbShort(b.dataBytes),
7977
- uploaded: b.uploadedBytes === null ? "-" : gbShort(b.uploadedBytes),
7978
- by: b.createdBy ?? "-",
7979
- taken: age(b.createdAt),
7980
- ...anyError ? { error: b.error ?? "" } : {}
7981
- }))
7982
- );
7983
- } finally {
7984
- await client.close();
7985
- }
7986
- });
8339
+ });
8340
+ };
7987
8341
 
7988
8342
  // src/commands/managed/backup/restore.ts
7989
- import { Command as Command98 } from "commander";
7990
- var restoreCommand3 = (spec) => new Command98("restore").description("put a backup back: the database's data becomes the backup's (it restarts)").argument("<db>", "its name").argument("<id>", `the backup's id (kvbox ${spec.command} backup ls <db>)`).option("-y, --yes", "do not ask for confirmation").option("--json", "print the database as JSON").action(async (name, id, opts, cmd) => {
8343
+ import { Command as Command104 } from "commander";
8344
+ var restoreCommand4 = (spec) => new Command104("restore").description("put a backup back: the database's data becomes the backup's (it restarts)").argument("<db>", "its name").argument("<id>", `the backup's id (kvbox ${spec.command} backup ls <db>)`).option("-y, --yes", "do not ask for confirmation").option("--json", "print the database as JSON").action(async (name, id, opts, cmd) => {
7991
8345
  const client = await managedClient(cmd);
7992
8346
  try {
7993
8347
  const backup = await client.managedBackup(spec.kind, name, id);
@@ -8009,8 +8363,8 @@ var restoreCommand3 = (spec) => new Command98("restore").description("put a back
8009
8363
  });
8010
8364
 
8011
8365
  // src/commands/managed/backup/rm.ts
8012
- import { Command as Command99 } from "commander";
8013
- var rmCommand15 = (spec) => new Command99("rm").alias("remove").description("remove a backup for good (a database's that is gone too)").argument("<db>", "its name").argument("<id>", `the backup's id (kvbox ${spec.command} backup ls <db>)`).option("-y, --yes", "do not ask for confirmation").action(async (name, id, opts, cmd) => {
8366
+ import { Command as Command105 } from "commander";
8367
+ var rmCommand16 = (spec) => new Command105("rm").alias("remove").description("remove a backup for good (a database's that is gone too)").argument("<db>", "its name").argument("<id>", `the backup's id (kvbox ${spec.command} backup ls <db>)`).option("-y, --yes", "do not ask for confirmation").action(async (name, id, opts, cmd) => {
8014
8368
  const client = await managedClient(cmd);
8015
8369
  try {
8016
8370
  await removeListed(client, await client.listManagedBackups(spec.kind), (b) => b.name, name, id, `database ${name}`, opts.yes ?? false);
@@ -8019,34 +8373,71 @@ var rmCommand15 = (spec) => new Command99("rm").alias("remove").description("rem
8019
8373
  }
8020
8374
  });
8021
8375
 
8376
+ // src/commands/managed/backup/schedule.ts
8377
+ import { Command as Command106 } from "commander";
8378
+ var scheduleCommand = (spec) => new Command106("schedule").description("show or change when a database is backed up on its own (daily, UTC)").argument("<db>", "its name").option("--at <hour>", "back it up daily at this hour, 0-23 UTC (turns it on)").option("--off", "stop backing it up on its own").option("--on", "back it up on its own again, at the hour it had").option("--json", "print the schedule as JSON").action(async (name, opts, cmd) => {
8379
+ if (opts.off && (opts.on || opts.at !== void 0)) throw new KvboxError("--off takes neither --on nor --at");
8380
+ const hour = opts.at === void 0 ? void 0 : parseHour(opts.at);
8381
+ const client = await managedClient(cmd);
8382
+ try {
8383
+ const change = { ...opts.off ? { enabled: false } : opts.on ? { enabled: true } : {}, ...hour !== void 0 ? { hour } : {} };
8384
+ const changed = Object.keys(change).length > 0;
8385
+ const schedule = changed ? await client.setManagedBackupSchedule(spec.kind, name, change) : await client.managedBackupSchedule(spec.kind, name);
8386
+ if (opts.json) {
8387
+ json(schedule);
8388
+ return;
8389
+ }
8390
+ info(`${changed ? `${color.green("\u2713")} ` : ""}database ${color.bold(name)}: ${scheduleText2(spec, name, schedule)}`);
8391
+ if (schedule.lastAt !== null) {
8392
+ const last = schedule.lastError !== null ? color.red(`failed: ${schedule.lastError}`) : schedule.lastBackup !== null ? `backup ${schedule.lastBackup}` : "starting a backup";
8393
+ info(color.dim(` last turn ${schedule.lastAt.slice(0, 16).replace("T", " ")} UTC: `) + last);
8394
+ }
8395
+ } finally {
8396
+ await client.close();
8397
+ }
8398
+ });
8399
+ function parseHour(text2) {
8400
+ const m = /^(\d{1,2})(?::00)?$/.exec(text2.trim());
8401
+ const hour = m ? Number(m[1]) : NaN;
8402
+ if (!Number.isInteger(hour) || hour < 0 || hour > 23) throw new KvboxError(`--at ${text2}: an hour of the day, 0-23 (UTC), like 3 or 03:00`);
8403
+ return hour;
8404
+ }
8405
+
8022
8406
  // src/commands/managed/backup/index.ts
8023
- var backupCommand3 = (spec) => {
8024
- const command = new Command100("backup").description("back up a database to the kvbox cloud, list backups, restore or remove one");
8025
- for (const make of [createCommand9, lsCommand15, restoreCommand3, rmCommand15]) command.addCommand(make(spec).option("--org <slug>", "act in this org (- for your personal databases)"));
8407
+ var backupCommand4 = (spec) => {
8408
+ const command = new Command107("backup").description("back up a database to the kvbox cloud, list backups, restore or remove one, or change its nightly schedule");
8409
+ for (const make of [createCommand10, lsCommand16, restoreCommand4, rmCommand16, scheduleCommand]) command.addCommand(make(spec).option("--org <slug>", "act in this org (- for your personal databases)"));
8026
8410
  return command;
8027
8411
  };
8028
8412
 
8029
8413
  // src/commands/managed/create.ts
8030
- import { Command as Command101 } from "commander";
8414
+ import { Command as Command108 } from "commander";
8031
8415
  import { setTimeout as sleep5 } from "timers/promises";
8032
8416
  var READY_WAIT_MS = 9e4;
8033
8417
  var READY_STEP_MS = 2e3;
8034
- var createCommand10 = (spec) => {
8035
- const command = new Command101("create").alias("new").description(`create a ${spec.title} database: a name is all it needs`).argument("<name>", "its name (1-12 chars, lowercase letters, digits and '-'); a linked box reaches it at <name>.<account>.kvbox");
8418
+ var createCommand11 = (spec) => {
8419
+ const command = new Command108("create").alias("new").description(`create a ${spec.title} database: a name is all it needs`).argument("<name>", "its name (1-12 chars, lowercase letters, digits and '-'); a linked box reaches it at <name>.<account>.kvbox");
8036
8420
  for (const o of spec.options) command.option(`--${o.name} <${o.arg}>`, o.help);
8037
- return command.option("--password <password>", "its password (default: generated)").option("--storage <gb>", `storage for the data in GB (default: ${spec.storageGib}; it can grow later)`).option("--near <box>", "run it on the host of this box, so the box can be linked to it").option("--json", "print it as JSON, password included").action(async (name, opts, cmd) => {
8421
+ return command.option("--password <password>", "its password (default: generated)").option("--storage <gb>", `storage for the data in GB (default: ${spec.storageGib}; it can grow later)`).option("--near <box>", "run it on the host of this box, so the box can be linked to it").option("--from-backup <id>", `start it on this backup's data, a removed database's too (kvbox ${spec.command} backup ls)`).option("--json", "print it as JSON, password included").action(async (name, opts, cmd) => {
8038
8422
  const options = Object.fromEntries(spec.options.flatMap((o) => typeof opts[o.name] === "string" ? [[o.name, opts[o.name]]] : []));
8039
8423
  const req = {
8040
8424
  name,
8041
8425
  ...Object.keys(options).length > 0 ? { options } : {},
8042
8426
  ...opts.password !== void 0 ? { password: opts.password } : {},
8043
8427
  ...opts.storage !== void 0 ? { storageGib: parseStorage(opts.storage, "--storage") } : {},
8044
- ...opts.near !== void 0 ? { near: opts.near } : {}
8428
+ ...opts.near !== void 0 ? { near: opts.near } : {},
8429
+ ...opts.fromBackup !== void 0 ? { fromBackup: opts.fromBackup } : {}
8045
8430
  };
8046
8431
  const client = await managedClient(cmd);
8047
8432
  try {
8048
- const made = await spin(`creating ${spec.title} database ${name}\u2026`, client.createManaged(spec.kind, req));
8433
+ const doing = opts.fromBackup === void 0 ? `creating ${spec.title} database ${name}\u2026` : `creating ${spec.title} database ${name} from backup ${opts.fromBackup}\u2026`;
8434
+ const made = await spin(doing, client.createManaged(spec.kind, req));
8049
8435
  const shown = shownName3(made, me(client));
8436
+ if (opts.fromBackup !== void 0 && made.fromBackup === void 0) {
8437
+ throw new KvboxError(
8438
+ `this control plane does not know --from-backup yet: database ${shown} was made empty, not from backup ${opts.fromBackup}; remove it with: kvbox ${spec.command} rm ${shown}`
8439
+ );
8440
+ }
8050
8441
  const ready = await spin(`starting ${spec.title}\u2026`, async () => {
8051
8442
  for (const until2 = Date.now() + READY_WAIT_MS; Date.now() < until2; await sleep5(READY_STEP_MS)) {
8052
8443
  const now = await client.getManaged(spec.kind, shown).catch(() => void 0);
@@ -8058,7 +8449,8 @@ var createCommand10 = (spec) => {
8058
8449
  json({ ...made, ready });
8059
8450
  return;
8060
8451
  }
8061
- info(`${color.green("\u2713")} database ${color.bold(shown)} ${ready ? "is ready" : "is created and still starting"} ${color.dim(`(${spec.title} ${made.version}, ${made.storageGib} GB of storage)`)}`);
8452
+ const restored = made.fromBackup === void 0 ? "" : `, the data of backup ${made.fromBackup}`;
8453
+ info(`${color.green("\u2713")} database ${color.bold(shown)} ${ready ? "is ready" : "is created and still starting"} ${color.dim(`(${spec.title} ${made.version}, ${made.storageGib} GB of storage${restored})`)}`);
8062
8454
  printRows3([...settingRows(spec, made.settings), ...secretRows(made.secret)].map(([label, value]) => [` ${label}`, value]));
8063
8455
  info("");
8064
8456
  info("Nobody can reach it yet. To let something in:");
@@ -8073,8 +8465,8 @@ var createCommand10 = (spec) => {
8073
8465
  };
8074
8466
 
8075
8467
  // src/commands/managed/grow.ts
8076
- import { Command as Command102 } from "commander";
8077
- var growCommand3 = (spec) => new Command102("grow").description("give a database more storage (it restarts once)").argument("<db>", "its name").argument("<GB>", "the new size in GB, larger than what it has").option("--json", "print as JSON").action(async (name, size, opts, cmd) => {
8468
+ import { Command as Command109 } from "commander";
8469
+ var growCommand3 = (spec) => new Command109("grow").description("give a database more storage (it restarts once)").argument("<db>", "its name").argument("<GB>", "the new size in GB, larger than what it has").option("--json", "print as JSON").action(async (name, size, opts, cmd) => {
8078
8470
  const storageGib = parseStorage(size, "size");
8079
8471
  const client = await managedClient(cmd);
8080
8472
  try {
@@ -8087,8 +8479,8 @@ var growCommand3 = (spec) => new Command102("grow").description("give a database
8087
8479
  });
8088
8480
 
8089
8481
  // src/commands/managed/info.ts
8090
- import { Command as Command103 } from "commander";
8091
- var infoCommand3 = (spec) => new Command103("info").alias("get").description("show one database: status, storage used, how to connect").argument("<db>", "its name").option("--json", "print as JSON").action(async (name, opts, cmd) => {
8482
+ import { Command as Command110 } from "commander";
8483
+ var infoCommand3 = (spec) => new Command110("info").alias("get").description("show one database: status, storage used, how to connect").argument("<db>", "its name").option("--json", "print as JSON").action(async (name, opts, cmd) => {
8092
8484
  const client = await managedClient(cmd);
8093
8485
  try {
8094
8486
  const m = await client.getManaged(spec.kind, name);
@@ -8100,8 +8492,8 @@ var infoCommand3 = (spec) => new Command103("info").alias("get").description("sh
8100
8492
  });
8101
8493
 
8102
8494
  // src/commands/managed/link.ts
8103
- import { Command as Command104 } from "commander";
8104
- var linkCommand2 = (spec) => new Command104("link").description("let a box reach a database privately (same host)").argument("<db>", "the database").argument("<box>", "the box that connects to it").option("--json", "print as JSON").action(async (name, box2, opts, cmd) => {
8495
+ import { Command as Command111 } from "commander";
8496
+ var linkCommand2 = (spec) => new Command111("link").description("let a box reach a database privately (same host)").argument("<db>", "the database").argument("<box>", "the box that connects to it").option("--json", "print as JSON").action(async (name, box2, opts, cmd) => {
8105
8497
  const client = await managedClient(cmd);
8106
8498
  try {
8107
8499
  const m = await spin(`linking ${box2} to ${name}\u2026`, client.linkManaged(spec.kind, name, box2));
@@ -8117,7 +8509,7 @@ var linkCommand2 = (spec) => new Command104("link").description("let a box reach
8117
8509
  });
8118
8510
 
8119
8511
  // src/commands/managed/ls.ts
8120
- import { Command as Command105 } from "commander";
8512
+ import { Command as Command112 } from "commander";
8121
8513
  function listRows(items, user, kindColumn) {
8122
8514
  return items.map((m) => ({
8123
8515
  owner: m.owner === user ? "private" : m.owner,
@@ -8131,7 +8523,7 @@ function listRows(items, user, kindColumn) {
8131
8523
  created: age(m.createdAt)
8132
8524
  }));
8133
8525
  }
8134
- var lsCommand16 = (spec) => new Command105("ls").alias("list").description(spec ? `list your ${spec.title} databases` : "list every managed database, whatever its kind").option("-a, --all", "every one on the platform (platform admins only)").option("--json", "print as JSON").action(async (opts, cmd) => {
8526
+ var lsCommand17 = (spec) => new Command112("ls").alias("list").description(spec ? `list your ${spec.title} databases` : "list every managed database, whatever its kind").option("-a, --all", "every one on the platform (platform admins only)").option("--json", "print as JSON").action(async (opts, cmd) => {
8135
8527
  const client = await managedClient(cmd);
8136
8528
  try {
8137
8529
  const items = await client.listManaged(spec?.kind, { all: opts.all });
@@ -8151,8 +8543,8 @@ var lsCommand16 = (spec) => new Command105("ls").alias("list").description(spec
8151
8543
  });
8152
8544
 
8153
8545
  // src/commands/managed/password.ts
8154
- import { Command as Command106 } from "commander";
8155
- var passwordCommand = (spec) => new Command106("password").description("show a database's password, or set a new one with --reset").argument("<db>", "its name").option("--reset", "make a new password; the old one stops working").option("--json", "print as JSON").action(async (name, opts, cmd) => {
8546
+ import { Command as Command113 } from "commander";
8547
+ var passwordCommand = (spec) => new Command113("password").description("show a database's password, or set a new one with --reset").argument("<db>", "its name").option("--reset", "make a new password; the old one stops working").option("--json", "print as JSON").action(async (name, opts, cmd) => {
8156
8548
  const client = await managedClient(cmd);
8157
8549
  try {
8158
8550
  const secret = opts.reset ? await spin(`setting a new password on ${name}\u2026`, client.resetManagedPassword(spec.kind, name)) : await client.managedPassword(spec.kind, name);
@@ -8168,8 +8560,8 @@ var passwordCommand = (spec) => new Command106("password").description("show a d
8168
8560
  });
8169
8561
 
8170
8562
  // src/commands/managed/public.ts
8171
- import { Command as Command107 } from "commander";
8172
- var publicCommand = (spec) => new Command107("public").description("open a database to the internet, or close it again").argument("<db>", "its name").argument("<state>", "on: reachable from anywhere with the password; off: only linked boxes").option("--json", "print as JSON").action(async (name, state, opts, cmd) => {
8563
+ import { Command as Command114 } from "commander";
8564
+ var publicCommand = (spec) => new Command114("public").description("open a database to the internet, or close it again").argument("<db>", "its name").argument("<state>", "on: reachable from anywhere with the password; off: only linked boxes").option("--json", "print as JSON").action(async (name, state, opts, cmd) => {
8173
8565
  if (state !== "on" && state !== "off") throw new KvboxError(`write on or off: kvbox ${spec.command} public ${name} on`);
8174
8566
  const client = await managedClient(cmd);
8175
8567
  try {
@@ -8190,8 +8582,8 @@ var publicCommand = (spec) => new Command107("public").description("open a datab
8190
8582
  });
8191
8583
 
8192
8584
  // src/commands/managed/rm.ts
8193
- import { Command as Command108 } from "commander";
8194
- var rmCommand16 = (spec) => new Command108("rm").alias("remove").description("delete a database and all its data").argument("<db>", "its name").option("-y, --yes", "do not ask for confirmation").action(async (name, opts, cmd) => {
8585
+ import { Command as Command115 } from "commander";
8586
+ var rmCommand17 = (spec) => new Command115("rm").alias("remove").description("delete a database and all its data").argument("<db>", "its name").option("-y, --yes", "do not ask for confirmation").action(async (name, opts, cmd) => {
8195
8587
  const client = await managedClient(cmd);
8196
8588
  try {
8197
8589
  if (!await confirm(`Delete database ${name} and all its data? There is no backup.`, opts.yes ?? false)) {
@@ -8207,8 +8599,8 @@ var rmCommand16 = (spec) => new Command108("rm").alias("remove").description("de
8207
8599
  });
8208
8600
 
8209
8601
  // src/commands/managed/start.ts
8210
- import { Command as Command109 } from "commander";
8211
- var startCommand2 = (spec) => new Command109("start").description("run a stopped database again").argument("<db>", "its name").option("--json", "print as JSON").action(async (name, opts, cmd) => {
8602
+ import { Command as Command116 } from "commander";
8603
+ var startCommand2 = (spec) => new Command116("start").description("run a stopped database again").argument("<db>", "its name").option("--json", "print as JSON").action(async (name, opts, cmd) => {
8212
8604
  const client = await managedClient(cmd);
8213
8605
  try {
8214
8606
  const m = await spin(`starting ${name}\u2026`, client.startManaged(spec.kind, name));
@@ -8220,8 +8612,8 @@ var startCommand2 = (spec) => new Command109("start").description("run a stopped
8220
8612
  });
8221
8613
 
8222
8614
  // src/commands/managed/stop.ts
8223
- import { Command as Command110 } from "commander";
8224
- var stopCommand2 = (spec) => new Command110("stop").description("shut a database down, keeping its data (only its storage is charged)").argument("<db>", "its name").option("--json", "print as JSON").action(async (name, opts, cmd) => {
8615
+ import { Command as Command117 } from "commander";
8616
+ var stopCommand2 = (spec) => new Command117("stop").description("shut a database down, keeping its data (only its storage is charged)").argument("<db>", "its name").option("--json", "print as JSON").action(async (name, opts, cmd) => {
8225
8617
  const client = await managedClient(cmd);
8226
8618
  try {
8227
8619
  const m = await spin(`stopping ${name}\u2026`, client.stopManaged(spec.kind, name));
@@ -8233,8 +8625,8 @@ var stopCommand2 = (spec) => new Command110("stop").description("shut a database
8233
8625
  });
8234
8626
 
8235
8627
  // src/commands/managed/unlink.ts
8236
- import { Command as Command111 } from "commander";
8237
- var unlinkCommand2 = (spec) => new Command111("unlink").description("stop a box from reaching a database").argument("<db>", "the database").argument("<box>", "the box that was linked to it").option("--json", "print as JSON").action(async (name, box2, opts, cmd) => {
8628
+ import { Command as Command118 } from "commander";
8629
+ var unlinkCommand2 = (spec) => new Command118("unlink").description("stop a box from reaching a database").argument("<db>", "the database").argument("<box>", "the box that was linked to it").option("--json", "print as JSON").action(async (name, box2, opts, cmd) => {
8238
8630
  const client = await managedClient(cmd);
8239
8631
  try {
8240
8632
  const m = await spin(`unlinking ${box2} from ${name}\u2026`, client.unlinkManaged(spec.kind, name, box2));
@@ -8247,11 +8639,11 @@ var unlinkCommand2 = (spec) => new Command111("unlink").description("stop a box
8247
8639
 
8248
8640
  // src/commands/managed/kind.ts
8249
8641
  function kindCommand(spec, description) {
8250
- const command = new Command112(spec.command).aliases(spec.aliases).description(description);
8251
- for (const make of [createCommand10, lsCommand16, infoCommand3, passwordCommand, publicCommand, linkCommand2, unlinkCommand2, growCommand3, stopCommand2, startCommand2, rmCommand16]) {
8642
+ const command = new Command119(spec.command).aliases(spec.aliases).description(description);
8643
+ for (const make of [createCommand11, lsCommand17, infoCommand3, passwordCommand, publicCommand, linkCommand2, unlinkCommand2, growCommand3, stopCommand2, startCommand2, rmCommand17]) {
8252
8644
  command.addCommand(make(spec).option("--org <slug>", "act in this org (- for your personal databases)"));
8253
8645
  }
8254
- command.addCommand(backupCommand3(spec));
8646
+ command.addCommand(backupCommand4(spec));
8255
8647
  return command;
8256
8648
  }
8257
8649
 
@@ -8262,14 +8654,14 @@ var pgCommand = kindCommand(POSTGRES2, "managed PostgreSQL: a database kvbox run
8262
8654
  var redisCommand = kindCommand(REDIS, "managed Redis (Valkey): a Redis kvbox runs for you, private until you link a box or make it public");
8263
8655
 
8264
8656
  // src/commands/managed/index.ts
8265
- import { Command as Command113 } from "commander";
8266
- var managedCommand = new Command113("managed").description(`databases kvbox runs for you, every kind together (${KINDS.map((k) => `${k.title}: kvbox ${k.command}`).join(", ")})`).addCommand(lsCommand16().option("--org <slug>", "act in this org (- for your personal databases)"));
8657
+ import { Command as Command120 } from "commander";
8658
+ var managedCommand = new Command120("managed").description(`databases kvbox runs for you, every kind together (${KINDS.map((k) => `${k.title}: kvbox ${k.command}`).join(", ")})`).addCommand(lsCommand17().option("--org <slug>", "act in this org (- for your personal databases)"));
8267
8659
 
8268
8660
  // src/commands/env/index.ts
8269
- import { Command as Command117 } from "commander";
8661
+ import { Command as Command124 } from "commander";
8270
8662
 
8271
8663
  // src/commands/env/ls.ts
8272
- import { Command as Command114 } from "commander";
8664
+ import { Command as Command121 } from "commander";
8273
8665
 
8274
8666
  // src/commands/env/shared.ts
8275
8667
  function requireCloud4(client) {
@@ -8296,7 +8688,7 @@ function firstBootHint(box2, name) {
8296
8688
  }
8297
8689
 
8298
8690
  // src/commands/env/ls.ts
8299
- var lsCommand17 = new Command114("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) => {
8691
+ var lsCommand18 = new Command121("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) => {
8300
8692
  const client = await clientFor(cmd.optsWithGlobals(), { autoStart: false });
8301
8693
  try {
8302
8694
  if (opts.box !== void 0) {
@@ -8335,8 +8727,8 @@ var lsCommand17 = new Command114("ls").alias("list").description("list the varia
8335
8727
  });
8336
8728
 
8337
8729
  // src/commands/env/rm.ts
8338
- import { Command as Command115 } from "commander";
8339
- var rmCommand17 = new Command115("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 (names2, opts, cmd) => {
8730
+ import { Command as Command122 } from "commander";
8731
+ var rmCommand18 = new Command122("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 (names2, opts, cmd) => {
8340
8732
  const client = await clientFor(cmd.optsWithGlobals(), { autoStart: false });
8341
8733
  try {
8342
8734
  const target = opts.box === void 0 ? void 0 : await findBox2(client, opts.box);
@@ -8373,8 +8765,8 @@ var rmCommand17 = new Command115("rm").alias("remove").description("remove varia
8373
8765
  });
8374
8766
 
8375
8767
  // src/commands/env/set.ts
8376
- import { Command as Command116 } from "commander";
8377
- var setCommand2 = new Command116("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) => {
8768
+ import { Command as Command123 } from "commander";
8769
+ var setCommand2 = new Command123("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) => {
8378
8770
  const client = await clientFor(cmd.optsWithGlobals(), { autoStart: false });
8379
8771
  try {
8380
8772
  const owner = opts.box === void 0 ? requireCloud4(client) : void 0;
@@ -8411,14 +8803,14 @@ var setCommand2 = new Command116("set").description("add or change a variable; b
8411
8803
  });
8412
8804
 
8413
8805
  // src/commands/env/index.ts
8414
- var envCommand = new Command117("env").description("environment variables every box of yours gets when it starts (secrets too)").addCommand(lsCommand17, { isDefault: true }).addCommand(setCommand2).addCommand(rmCommand17);
8806
+ var envCommand = new Command124("env").description("environment variables every box of yours gets when it starts (secrets too)").addCommand(lsCommand18, { isDefault: true }).addCommand(setCommand2).addCommand(rmCommand18);
8415
8807
  for (const cmd of envCommand.commands) cmd.option("--org <slug>", "the org's variables instead of yours");
8416
8808
 
8417
8809
  // src/commands/domain/index.ts
8418
- import { Command as Command121 } from "commander";
8810
+ import { Command as Command128 } from "commander";
8419
8811
 
8420
8812
  // src/commands/domain/add.ts
8421
- import { Command as Command118 } from "commander";
8813
+ import { Command as Command125 } from "commander";
8422
8814
 
8423
8815
  // src/commands/domain/shared.ts
8424
8816
  function requireCloud5(client) {
@@ -8438,7 +8830,7 @@ function hostIn(name, zone) {
8438
8830
  }
8439
8831
 
8440
8832
  // src/commands/domain/add.ts
8441
- var addCommand4 = new Command118("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) => {
8833
+ var addCommand4 = new Command125("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) => {
8442
8834
  const domain = assertDomain(domainArg.trim().toLowerCase());
8443
8835
  const port = opts.port === void 0 ? void 0 : parsePorts([opts.port])[0];
8444
8836
  const client = await clientFor(cmd.optsWithGlobals());
@@ -8474,8 +8866,8 @@ kvbox checks every minute; ${domain} is served at ${d.url} once its records are
8474
8866
  });
8475
8867
 
8476
8868
  // src/commands/domain/ls.ts
8477
- import { Command as Command119 } from "commander";
8478
- var lsCommand18 = new Command119("ls").alias("list").description("list your custom domains and whether they are live").option("--json", "print as JSON").action(async (opts, cmd) => {
8869
+ import { Command as Command126 } from "commander";
8870
+ var lsCommand19 = new Command126("ls").alias("list").description("list your custom domains and whether they are live").option("--json", "print as JSON").action(async (opts, cmd) => {
8479
8871
  const client = await clientFor(cmd.optsWithGlobals());
8480
8872
  try {
8481
8873
  requireCloud5(client);
@@ -8504,8 +8896,8 @@ var lsCommand18 = new Command119("ls").alias("list").description("list your cust
8504
8896
  });
8505
8897
 
8506
8898
  // src/commands/domain/rm.ts
8507
- import { Command as Command120 } from "commander";
8508
- var rmCommand18 = new Command120("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) => {
8899
+ import { Command as Command127 } from "commander";
8900
+ var rmCommand19 = new Command127("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) => {
8509
8901
  const domain = domainArg.trim().toLowerCase();
8510
8902
  const client = await clientFor(cmd.optsWithGlobals());
8511
8903
  try {
@@ -8526,15 +8918,15 @@ var rmCommand18 = new Command120("rm").alias("remove").description("stop serving
8526
8918
  });
8527
8919
 
8528
8920
  // src/commands/domain/index.ts
8529
- var domainCommand = new Command121("domain").alias("domains").description("serve a box at a domain of your own").addCommand(addCommand4).addCommand(lsCommand18).addCommand(rmCommand18);
8921
+ var domainCommand = new Command128("domain").alias("domains").description("serve a box at a domain of your own").addCommand(addCommand4).addCommand(lsCommand19).addCommand(rmCommand19);
8530
8922
  for (const cmd of domainCommand.commands) cmd.option("--org <slug>", "act in this org (- for your personal boxes)");
8531
8923
 
8532
8924
  // src/commands/update.ts
8533
- import { spawn as spawn7 } from "child_process";
8925
+ import { spawn as spawn8 } from "child_process";
8534
8926
  import { mkdtempSync, rmSync, writeFileSync as writeFileSync2 } from "fs";
8535
8927
  import { tmpdir } from "os";
8536
8928
  import { join as join9 } from "path";
8537
- import { Command as Command122 } from "commander";
8929
+ import { Command as Command129 } from "commander";
8538
8930
 
8539
8931
  // src/update.ts
8540
8932
  import { mkdirSync, readFileSync as readFileSync3, writeFileSync } from "fs";
@@ -8648,12 +9040,12 @@ async function download(url) {
8648
9040
  }
8649
9041
  function run2(cmd, args) {
8650
9042
  return new Promise((resolve4, reject) => {
8651
- const child = spawn7(cmd, args, { stdio: "inherit" });
9043
+ const child = spawn8(cmd, args, { stdio: "inherit" });
8652
9044
  child.on("error", (err) => reject(new KvboxError(`could not run ${cmd}: ${err.message}`)));
8653
9045
  child.on("exit", (code, signal) => resolve4(code ?? (signal ? 1 : 0)));
8654
9046
  });
8655
9047
  }
8656
- var selfUpdateCommand = new Command122("update").description("update kvbox to the latest version (reruns the installer from kvbox.sh, agent skill included)").action(async () => {
9048
+ var selfUpdateCommand = new Command129("update").description("update kvbox to the latest version (reruns the installer from kvbox.sh, agent skill included)").action(async () => {
8657
9049
  suppressUpdateNotice();
8658
9050
  const inst = installerFor(process.platform, process.env["KVBOX_INSTALL_URL"] || INSTALL_BASE);
8659
9051
  let code;
@@ -8695,6 +9087,7 @@ var HELP_GROUPS = [
8695
9087
  ["get", "show one box in full"],
8696
9088
  ["connect", "open a shell in a box, or run a command there (short: cn)"],
8697
9089
  ["exec", "run a command in a box and exit with its status"],
9090
+ ["cp", "copy files between this machine and a box"],
8698
9091
  ["claim", "give a box an HTTPS address, https://<name>.kvbox.app"],
8699
9092
  ["deploy", "put the app in this directory on a box with its own HTTPS address"],
8700
9093
  ["rm", "destroy a box and its disk"]
@@ -8780,7 +9173,7 @@ function installRootHelp(program) {
8780
9173
 
8781
9174
  // src/program.ts
8782
9175
  function buildProgram() {
8783
- const program = new Command123("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 and KVBOX_TOKEN").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();
9176
+ const program = new Command130("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 and KVBOX_TOKEN").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();
8784
9177
  program.addCommand(vmCommand);
8785
9178
  program.addCommand(snapshotsCommand);
8786
9179
  program.addCommand(volumeCommand);