@kvbox/cli 0.5.43 → 0.5.45

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/kvbox.js CHANGED
@@ -149,7 +149,7 @@ async function spin(message, work, opts = {}) {
149
149
  }
150
150
 
151
151
  // src/program.ts
152
- import { Command as Command77 } from "commander";
152
+ import { Command as Command69 } from "commander";
153
153
 
154
154
  // ../shared/src/version.ts
155
155
  import { createRequire } from "module";
@@ -164,7 +164,7 @@ function versionOf(srcFileUrl, injected) {
164
164
  }
165
165
 
166
166
  // src/version.ts
167
- var VERSION = versionOf(import.meta.url, true ? "0.5.43" : void 0);
167
+ var VERSION = versionOf(import.meta.url, true ? "0.5.45" : void 0);
168
168
 
169
169
  // src/commands/vm/index.ts
170
170
  import { Command as Command37 } from "commander";
@@ -191,6 +191,14 @@ function paths(home = kvboxHome()) {
191
191
  serverSock: join(home, "server.sock"),
192
192
  serverPid: join(home, "server.pid"),
193
193
  serverLog: join(home, "server.log"),
194
+ /**
195
+ * The host's self-update (`POST /update`, the control plane's admin): `update.json` is its state
196
+ * (install-server.sh --update writes it), `update/` holds the downloaded script and its log.
197
+ */
198
+ updateState: join(home, "update.json"),
199
+ updateDir: join(home, "update"),
200
+ updateScript: join(home, "update", "install-server.sh"),
201
+ updateLog: join(home, "update", "update.log"),
194
202
  /** The CLI's login to the control plane (`kvbox login`): url, bearer token, user. Mode 600. */
195
203
  cli: join(home, "cli.json"),
196
204
  /** The CLI's last look at npm for a newer @kvbox/cli: `{checkedAt, latest}`, at most once a day (cli update.ts). */
@@ -205,7 +213,7 @@ function paths(home = kvboxHome()) {
205
213
  tls: join(home, "tls"),
206
214
  tlsKey: join(home, "tls", "key.pem"),
207
215
  tlsCert: join(home, "tls", "cert.pem"),
208
- /** The host's WireGuard tunnel to its relay (`kvbox server relay`, #50): the conf net-setup.sh installs for wg-quick. Mode 600. */
216
+ /** The host's WireGuard tunnel to its relay (`kvbox-server relay`, #50): the conf net-setup.sh installs for wg-quick. Mode 600. */
209
217
  relay: join(home, "relay"),
210
218
  relayConf: join(home, "relay", "kvbox.conf"),
211
219
  bin: join(home, "bin"),
@@ -772,7 +780,9 @@ var CapacitySchema = z2.object({
772
780
  * The images a new box can be made from here (#87), with the version `new` uses; the base is `base`.
773
781
  * Absent on a host from before images: it has only the base.
774
782
  */
775
- images: z2.array(z2.object({ name: z2.string(), version: z2.string() })).optional()
783
+ images: z2.array(z2.object({ name: z2.string(), version: z2.string() })).optional(),
784
+ /** kvbox-server's version, so the control plane's host list shows it without a call per host. Older servers omit it. */
785
+ version: z2.string().optional()
776
786
  });
777
787
  var ImageSchema = z2.object({ name: z2.string(), version: z2.string().nullable() });
778
788
  var RecoveryReportSchema = z2.object({
@@ -781,6 +791,16 @@ var RecoveryReportSchema = z2.object({
781
791
  leftStopped: z2.array(z2.string()),
782
792
  failed: z2.array(z2.object({ box: z2.string(), error: z2.string() }))
783
793
  });
794
+ var HostUpdateSchema = z2.object({
795
+ state: z2.enum(["running", "done", "failed"]),
796
+ startedAt: z2.string(),
797
+ finishedAt: z2.string().nullable(),
798
+ /** kvbox-server's version when the update started, and when it ended (null while running or when it failed before). */
799
+ from: z2.string(),
800
+ to: z2.string().nullable(),
801
+ error: z2.string().nullable(),
802
+ needsManual: z2.array(z2.string())
803
+ });
784
804
  var HealthSchema = z2.object({
785
805
  ok: z2.literal(true),
786
806
  version: z2.string(),
@@ -809,7 +829,9 @@ var HealthSchema = z2.object({
809
829
  lastRestartAt: z2.string().nullable().optional()
810
830
  }).nullable().optional(),
811
831
  /** Boxes brought back at the server's last start; null when there were none or it is still at it. Older servers omit it. */
812
- recovery: RecoveryReportSchema.nullable().optional()
832
+ recovery: RecoveryReportSchema.nullable().optional(),
833
+ /** The last self-update; null when none ran. Older servers omit it. */
834
+ update: HostUpdateSchema.nullable().optional()
813
835
  });
814
836
  var MachineUsageSchema = z2.object({
815
837
  name: z2.string(),
@@ -1048,7 +1070,7 @@ var SshCertResponseSchema = z2.object({
1048
1070
  });
1049
1071
  var SshCaResponseSchema = z2.object({
1050
1072
  publicKey: z2.string(),
1051
- /** CAs replaced by `ca rotate` (#55), newest first; a box still holding one of these has not had `kvbox server trust-ca` run on its host. */
1073
+ /** CAs replaced by `ca rotate` (#55), newest first; a box still holding one of these has not had `kvbox-server trust-ca` run on its host. */
1052
1074
  retired: z2.array(z2.object({ publicKey: z2.string(), retiredAt: z2.string() })).optional()
1053
1075
  });
1054
1076
  var HostSshCaResponseSchema = z2.object({
@@ -1080,7 +1102,7 @@ var HostJoinRequestSchema = z2.object({
1080
1102
  url: z2.string().url(),
1081
1103
  fingerprint: z2.string().regex(/^([0-9A-F]{2}:){31}[0-9A-F]{2}$/),
1082
1104
  publicAddress: z2.string().min(1),
1083
- /** Where the host is (`kvbox server join --country`): a code or an English name. */
1105
+ /** Where the host is (`kvbox-server join --country`): a code or an English name. */
1084
1106
  country: z2.string().optional()
1085
1107
  });
1086
1108
  var HostJoinResponseSchema = z2.object({
@@ -1095,7 +1117,14 @@ var CloudHostSchema = z2.object({
1095
1117
  lastSeenAt: z2.string().nullable(),
1096
1118
  capacity: CapacitySchema.nullable(),
1097
1119
  /** ISO 3166-1 alpha-2 code (`RO`), null when nobody said where the host is. */
1098
- country: z2.string().nullable()
1120
+ country: z2.string().nullable(),
1121
+ /** kvbox-server's version as of the poller's last look (`capacity.version`); null before one, or for a server older than 0.5.45. */
1122
+ version: z2.string().nullable()
1123
+ });
1124
+ var HostInfoSchema = z2.object({
1125
+ host: CloudHostSchema,
1126
+ health: HealthSchema.nullable(),
1127
+ error: z2.string().nullable()
1099
1128
  });
1100
1129
  var HostPatchRequest = z2.object({ country: z2.string().nullable() });
1101
1130
  var CountrySchema = z2.object({ code: z2.string(), name: z2.string() });
@@ -1139,7 +1168,7 @@ function groupWithMember(gid, user, groupFile) {
1139
1168
  return void 0;
1140
1169
  }
1141
1170
 
1142
- // src/systemd.ts
1171
+ // ../shared/src/systemd.ts
1143
1172
  import { spawnSync } from "child_process";
1144
1173
  import { readFileSync as readFileSync2 } from "fs";
1145
1174
  import { resolve } from "path";
@@ -1163,9 +1192,6 @@ function unitActive() {
1163
1192
  const res = spawnSync("systemctl", ["is-active", UNIT], { encoding: "utf8" });
1164
1193
  return (res.stdout ?? "").trim() === "active";
1165
1194
  }
1166
- function startsAtBoot(p) {
1167
- return hasUnitFor(p) && spawnSync("systemctl", ["is-enabled", "--quiet", UNIT]).status === 0;
1168
- }
1169
1195
 
1170
1196
  // src/client.ts
1171
1197
  var ORG_SLUG_RE = /^[a-z0-9][a-z0-9._-]{0,31}$/;
@@ -1224,7 +1250,7 @@ var ServerClient = class {
1224
1250
  await spin("starting kvbox-server\u2026", startLocalServer(paths(), 5e3));
1225
1251
  return this.call(method, path, schema, body, org, timeoutMs);
1226
1252
  }
1227
- throw new KvboxError(`kvbox-server is not running (${String(code)}); start it with: kvbox server start`);
1253
+ throw new KvboxError(`kvbox-server is not running (${String(code)}); start it with: kvbox-server start -d`);
1228
1254
  }
1229
1255
  throw new KvboxError(cloudDown(this.target.url, String(code)));
1230
1256
  }
@@ -1581,10 +1607,13 @@ async function checkDirect(ep) {
1581
1607
  }
1582
1608
  var NOT_A_HOST_HINT = "kvbox-server is not installed, so this machine is not a kvbox host. Set it up with install-server.sh, or log in to the cloud with: kvbox login";
1583
1609
  async function lastErrorLine(logPath, from = 0) {
1584
- const { readFile: readFile9 } = await import("fs/promises");
1585
- const text2 = (await readFile9(logPath).catch(() => Buffer.alloc(0))).subarray(from).toString("utf8");
1586
- const lines = text2.trimEnd().split("\n").slice(-20).reverse();
1587
- return lines.find((l) => l.startsWith("error: "))?.slice("error: ".length);
1610
+ const { readFile: readFile8 } = await import("fs/promises");
1611
+ const text2 = (await readFile8(logPath).catch(() => Buffer.alloc(0))).subarray(from).toString("utf8");
1612
+ for (const line of text2.trimEnd().split("\n").slice(-20).reverse()) {
1613
+ const m = /^(?:\[[^\]]*\])?\[?error\]?: (.*)$/.exec(line);
1614
+ if (m?.[1] !== void 0) return m[1];
1615
+ }
1616
+ return void 0;
1588
1617
  }
1589
1618
  async function startLocalServer(p = paths(), timeoutMs = 5e3) {
1590
1619
  await mkdir2(p.home, { recursive: true });
@@ -3291,199 +3320,14 @@ var vmCommand = new Command37("vm").enablePositionalOptions().description("manag
3291
3320
  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)");
3292
3321
  var vmAliases = [newCommand, lsCommand, getCommand, connectCommand, execCommand, stopCommand, startCommand, pauseCommand, resumeCommand, hibernateCommand, wakeCommand, rmCommand3, claimCommand];
3293
3322
 
3294
- // src/commands/server/index.ts
3295
- import { Command as Command45 } from "commander";
3296
-
3297
- // src/commands/server/join.ts
3298
- import { Command as Command38 } from "commander";
3299
-
3300
- // src/commands/server/daemon.ts
3301
- import { spawn as spawn4 } from "child_process";
3302
- import { readFile as readFile4 } from "fs/promises";
3303
- import { setTimeout as sleep3 } from "timers/promises";
3304
- async function runningPid(p = paths()) {
3305
- let pid;
3306
- try {
3307
- pid = Number.parseInt(await readFile4(p.serverPid, "utf8"), 10);
3308
- } catch {
3309
- return null;
3310
- }
3311
- return alive(pid) ? pid : null;
3312
- }
3313
- function alive(pid) {
3314
- try {
3315
- process.kill(pid, 0);
3316
- return true;
3317
- } catch {
3318
- return false;
3319
- }
3320
- }
3321
- async function stopLocalServer(pid, timeoutMs = 1e4) {
3322
- process.kill(pid, "SIGTERM");
3323
- const deadline = Date.now() + timeoutMs;
3324
- while (alive(pid)) {
3325
- if (Date.now() > deadline) throw new KvboxError(`kvbox-server (pid ${pid}) did not stop within ${timeoutMs / 1e3}s`);
3326
- await sleep3(100);
3327
- }
3328
- }
3329
- async function restartLocalServer(p = paths()) {
3330
- const pid = await runningPid(p);
3331
- if (pid !== null) await stopLocalServer(pid);
3332
- return (await startLocalServer(p)).pid;
3333
- }
3334
- function runKvboxServer(args) {
3335
- return new Promise((resolve3, reject) => {
3336
- const child = spawn4("kvbox-server", args, { stdio: ["ignore", "pipe", "pipe"] });
3337
- let out = "";
3338
- let err = "";
3339
- child.stdout.on("data", (chunk) => out += chunk.toString());
3340
- child.stderr.on("data", (chunk) => err += chunk.toString());
3341
- child.once("error", (e) => {
3342
- reject(new KvboxError(e.code === "ENOENT" ? NOT_A_HOST_HINT : `could not run kvbox-server: ${e.message}`));
3343
- });
3344
- child.once("close", (code) => {
3345
- if (code === 0) resolve3(out.trimEnd());
3346
- else reject(new KvboxError(err.trim().replace(/^error: /, "") || `kvbox-server ${args[0] ?? ""} exited with code ${String(code)}`, code === 2 ? 2 : 1));
3347
- });
3348
- });
3349
- }
3350
-
3351
- // src/commands/server/join.ts
3352
- var joinCommand = new Command38("join").description("put this machine behind a control plane (needs a one-time token minted there) and restart its server").argument("<control-plane-url>", "the control plane, e.g. https://api.kvbox.sh").requiredOption("--token <token>", "one-time join token from the control plane").option("--advertise <host-or-ip>", "address the control plane reaches this machine at (default: its default-route address)").option("--name <name>", "how the control plane lists this machine (default: hostname)").option("--country <country>", "where this machine is, a name or a code (romania, US); kvbox new --country places boxes by it").action(async (url, opts) => {
3353
- const args = ["join", url, "--token", opts.token];
3354
- if (opts.advertise !== void 0) args.push("--advertise", opts.advertise);
3355
- if (opts.name !== void 0) args.push("--name", opts.name);
3356
- if (opts.country !== void 0) args.push("--country", opts.country);
3357
- for (const line of (await runKvboxServer(args)).split("\n")) info(line);
3358
- const pid = await spin("restarting kvbox-server\u2026", restartLocalServer(paths()));
3359
- info(`kvbox-server restarted (pid ${pid}); it answers the control plane now`);
3360
- });
3361
-
3362
- // src/commands/server/leave.ts
3363
- import { Command as Command39 } from "commander";
3364
- var leaveCommand = new Command39("leave").description("take this machine out from behind its control plane and restart its server").action(async () => {
3365
- const p = paths();
3366
- for (const line of (await runKvboxServer(["leave"])).split("\n")) info(line);
3367
- if (await runningPid(p) === null) return;
3368
- const pid = await spin("restarting kvbox-server\u2026", restartLocalServer(p));
3369
- info(`kvbox-server restarted (pid ${pid}); only this machine talks to it now`);
3370
- });
3371
-
3372
- // src/commands/server/relay.ts
3373
- import { Command as Command40 } from "commander";
3374
- var relayCommand = new Command40("relay").description("reach the internet through a relay (paste what `kvbox-relay add` printed on the relay VM); `off` takes the tunnel down").argument("<join-string>", "the line `kvbox-relay add` printed, or `off`").action(async (joinString) => {
3375
- for (const line of (await runKvboxServer(["relay", joinString])).split("\n")) info(line);
3376
- });
3377
-
3378
- // src/commands/server/start.ts
3379
- import { Command as Command41 } from "commander";
3380
- var startCommand2 = new Command41("start").description("start the local kvbox-server in the background").action(async (_opts, cmd) => {
3381
- const client = await clientFor({ ...cmd.optsWithGlobals(), local: true }, { autoStart: false });
3382
- try {
3383
- const health = await client.health();
3384
- info(`kvbox-server ${health.version} is already running (pid ${health.pid})`);
3385
- return;
3386
- } catch {
3387
- } finally {
3388
- await client.close();
3389
- }
3390
- const { pid, socketPath, viaGroup } = await startLocalServer(paths());
3391
- info(`kvbox-server started (pid ${pid}), listening on ${socketPath}`);
3392
- if (viaGroup !== void 0) info(`started through the ${viaGroup} group, which this shell does not have yet (log out and back in to get it)`);
3393
- });
3394
-
3395
- // src/commands/server/status.ts
3396
- import { Command as Command42 } from "commander";
3397
- var statusCommand = new Command42("status").description("show whether this machine's server is running, its control plane and which base image new boxes get").option("--json", "print as JSON").action(async (opts, cmd) => {
3398
- const client = await clientFor({ ...cmd.optsWithGlobals(), local: true });
3399
- try {
3400
- const health = await client.health();
3401
- const atBoot = startsAtBoot(paths());
3402
- if (opts.json) json({ ...health, startsAtBoot: atBoot });
3403
- else {
3404
- info(`kvbox-server ${health.version} running, pid ${health.pid}`);
3405
- info(atBoot ? "starts at boot: yes, and brings back the boxes that were running" : "starts at boot: no (install-server.sh sets that up)");
3406
- const r = health.recovery;
3407
- if (r) {
3408
- if (r.booted.length > 0) info(`after the last restart it booted again: ${r.booted.join(", ")}`);
3409
- if (r.leftStopped.length > 0) info(`left stopped (were in standby, their memory was lost): ${r.leftStopped.join(", ")}`);
3410
- for (const f of r.failed) info(`did not come back: ${f.box} (${f.error})`);
3411
- }
3412
- if (health.controlPlane) info(`control plane: ${health.controlPlane.name} at ${health.controlPlane.url}, this host answers it on ${health.controlPlane.hostUrl}`);
3413
- else info("control plane: none (kvbox server join <url> --token <token> puts this machine behind one)");
3414
- if (health.relay) {
3415
- info(`relay: ${health.relay.name} lends this machine ${health.relay.publicIp} (tunnel to ${health.relay.endpoint})`);
3416
- if (health.relay.restarts && health.relay.lastRestartAt) {
3417
- info(`the tunnel stopped carrying traffic and was redialed ${health.relay.restarts} time(s) since the server started, last at ${health.relay.lastRestartAt}`);
3418
- }
3419
- }
3420
- if (health.base === null) info("base image: none usable yet (run install-server.sh)");
3421
- else info(`base image: ${health.base} (what kvbox new uses; kvbox vm update <box> moves an older box onto it)`);
3422
- }
3423
- } finally {
3424
- await client.close();
3425
- }
3426
- });
3427
-
3428
- // src/commands/server/stop.ts
3429
- import { Command as Command43 } from "commander";
3430
- var stopCommand2 = new Command43("stop").description("stop the local server (running boxes are not affected)").action(async () => {
3431
- const pid = await runningPid(paths());
3432
- if (pid === null) throw new KvboxError("kvbox-server is not running");
3433
- await stopLocalServer(pid);
3434
- info(`kvbox-server stopped (pid ${pid})`);
3435
- });
3436
-
3437
- // src/commands/server/trust-ca.ts
3438
- import { Command as Command44 } from "commander";
3439
- var trustCaCommand = new Command44("trust-ca").description("make every cloud box on this machine trust a new SSH CA (after `ca rotate` on the control plane)").argument("[public-key]", "the CA public key (or its cert-authority line); or --from-cloud").option("--from-cloud", "ask the control plane this host joined for its current CA, show the fingerprint, then ask").option("-y, --yes", "do not ask for confirmation").option("--json", "print the report as JSON").action(async (publicKey, opts, cmd) => {
3440
- if (publicKey === void 0 && !opts.fromCloud) throw new KvboxError("give the CA public key, or --from-cloud to fetch it from the control plane this host joined");
3441
- if (publicKey !== void 0 && opts.fromCloud) throw new KvboxError("either a public key or --from-cloud, not both");
3442
- const client = await clientFor({ ...cmd.optsWithGlobals(), local: true });
3443
- try {
3444
- let key = publicKey;
3445
- if (key === void 0) {
3446
- const ca = await client.cloudCa();
3447
- info(`${ca.controlPlane} says its SSH CA is ${ca.fingerprint}`);
3448
- if (!await confirm(`make every cloud box on this machine trust it (in place of the CA it trusts now)?`, opts.yes ?? false)) {
3449
- throw new KvboxError("cancelled", 130);
3450
- }
3451
- key = ca.publicKey;
3452
- }
3453
- const report = await client.trustCa({ publicKey: key });
3454
- if (opts.json) json(report);
3455
- else describeReport(report);
3456
- } finally {
3457
- await client.close();
3458
- }
3459
- });
3460
- var WHEN = {
3461
- start: "is stopped: it trusts the CA from its next start",
3462
- wake: "is hibernated: it trusts the CA from its next wake",
3463
- resume: "is in standby: it trusts the CA from its next resume",
3464
- later: "is running but could not take it now; it trusts the CA from its next stop and start"
3465
- };
3466
- function describeReport(report) {
3467
- info(`CA ${report.fingerprint}`);
3468
- for (const box of report.updated) info(`box ${box} now trusts the CA`);
3469
- for (const p of report.pending) info(`box ${p.box} ${WHEN[p.when]}${p.why ? ` (${p.why})` : ""}`);
3470
- for (const f of report.failed) warn(`box ${f.box}: ${f.error}`);
3471
- const parts = [`${report.updated.length} box(es) updated now`, `${report.pending.length} pending`, `${report.failed.length} failed`];
3472
- if (report.local > 0) parts.push(`${report.local} local box(es) untouched (they trust this host's key only)`);
3473
- info(parts.join(", "));
3474
- }
3475
-
3476
- // src/commands/server/index.ts
3477
- var serverCommand = new Command45("server").description("run or manage the kvbox server").addCommand(startCommand2).addCommand(statusCommand).addCommand(stopCommand2).addCommand(joinCommand).addCommand(leaveCommand).addCommand(relayCommand).addCommand(trustCaCommand);
3478
-
3479
3323
  // src/commands/login.ts
3480
3324
  import { spawnSync as spawnSync3 } from "child_process";
3481
- import { mkdir as mkdir3, readFile as readFile5, writeFile as writeFile3 } from "fs/promises";
3325
+ import { mkdir as mkdir3, readFile as readFile4, writeFile as writeFile3 } from "fs/promises";
3482
3326
  import { hostname as osHostname } from "os";
3483
3327
  import { createInterface as createInterface2 } from "readline/promises";
3484
3328
  import { Writable } from "stream";
3485
- import { Command as Command46 } from "commander";
3486
- var loginCommand = new Command46("login").description("log in to the kvbox cloud (or your own control plane) and target it from now on").argument("[url]", `control plane URL (default: ${DEFAULT_CLOUD_URL})`).option("-e, --email <email>", "account email (prompted otherwise)").option("--password-stdin", "read the password from the first line of stdin (for scripts)").action(async (urlArg, opts) => {
3329
+ import { Command as Command38 } from "commander";
3330
+ var loginCommand = new Command38("login").description("log in to the kvbox cloud (or your own control plane) and target it from now on").argument("[url]", `control plane URL (default: ${DEFAULT_CLOUD_URL})`).option("-e, --email <email>", "account email (prompted otherwise)").option("--password-stdin", "read the password from the first line of stdin (for scripts)").action(async (urlArg, opts) => {
3487
3331
  const url = normalizeUrl(urlArg ?? DEFAULT_CLOUD_URL);
3488
3332
  const creds = await readCredentials(opts);
3489
3333
  const session = await runLogin(url, creds, paths());
@@ -3524,10 +3368,10 @@ async function runLogin(url, creds, p = paths(), hostname = osHostname()) {
3524
3368
  }
3525
3369
  async function ensureSshKey(p = paths(), hostname = osHostname()) {
3526
3370
  const pubPath = `${p.sshKey}.pub`;
3527
- const pub = await readFile5(pubPath, "utf8").catch(() => null);
3371
+ const pub = await readFile4(pubPath, "utf8").catch(() => null);
3528
3372
  if (pub !== null) return pub.trim();
3529
3373
  await mkdir3(p.ssh, { recursive: true, mode: 448 });
3530
- const havePrivate = await readFile5(p.sshKey).then(() => true, () => false);
3374
+ const havePrivate = await readFile4(p.sshKey).then(() => true, () => false);
3531
3375
  const args = havePrivate ? ["-y", "-f", p.sshKey] : ["-q", "-t", "ed25519", "-N", "", "-C", `kvbox@${hostname}`, "-f", p.sshKey];
3532
3376
  const res = spawnSync3("ssh-keygen", args, { stdio: ["ignore", "pipe", "pipe"], encoding: "utf8" });
3533
3377
  if (res.error) {
@@ -3536,7 +3380,7 @@ async function ensureSshKey(p = paths(), hostname = osHostname()) {
3536
3380
  }
3537
3381
  if (res.status !== 0) throw new KvboxError(`ssh-keygen failed: ${res.stderr.trim()}`);
3538
3382
  if (havePrivate) await writeFile3(pubPath, res.stdout.trim() + "\n");
3539
- return (await readFile5(pubPath, "utf8")).trim();
3383
+ return (await readFile4(pubPath, "utf8")).trim();
3540
3384
  }
3541
3385
  async function prompt(question, io) {
3542
3386
  const rl = createInterface2({ input: io.input, output: io.output });
@@ -3563,8 +3407,8 @@ async function firstLine(stream) {
3563
3407
  }
3564
3408
 
3565
3409
  // src/commands/logout.ts
3566
- import { Command as Command47 } from "commander";
3567
- var logoutCommand = new Command47("logout").description("log out of the control plane; commands target this machine's kvbox-server again").action(async () => {
3410
+ import { Command as Command39 } from "commander";
3411
+ var logoutCommand = new Command39("logout").description("log out of the control plane; commands target this machine's kvbox-server again").action(async () => {
3568
3412
  const p = paths();
3569
3413
  const session = await readSession(p).catch(() => null);
3570
3414
  switch (await runLogout(p)) {
@@ -3601,8 +3445,8 @@ async function runLogout(p = paths()) {
3601
3445
  }
3602
3446
 
3603
3447
  // src/commands/whoami.ts
3604
- import { Command as Command48 } from "commander";
3605
- var whoamiCommand = new Command48("whoami").description("show which account and control plane commands target (or local mode)").option("--json", "print as JSON").action(async (opts) => {
3448
+ import { Command as Command40 } from "commander";
3449
+ var whoamiCommand = new Command40("whoami").description("show which account and control plane commands target (or local mode)").option("--json", "print as JSON").action(async (opts) => {
3606
3450
  const session = await readSession();
3607
3451
  if (opts.json) {
3608
3452
  json(session ? { user: session.user, url: session.url, sshCertExpires: session.sshCertExpires ?? null } : null);
@@ -3618,11 +3462,11 @@ function describeSession(session) {
3618
3462
  }
3619
3463
 
3620
3464
  // src/commands/snapshots/index.ts
3621
- import { Command as Command52 } from "commander";
3465
+ import { Command as Command44 } from "commander";
3622
3466
 
3623
3467
  // src/commands/snapshots/ls.ts
3624
- import { Command as Command49 } from "commander";
3625
- var lsCommand5 = new Command49("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) => {
3468
+ import { Command as Command41 } from "commander";
3469
+ var lsCommand5 = new Command41("ls").description("list snapshots (yours and your orgs'; --org <slug> for one org)").option("-a, --all", "every snapshot on the platform (platform admins only)").option("--json", "print as JSON").action(async (opts, cmd) => {
3626
3470
  const client = await clientFor(cmd.optsWithGlobals());
3627
3471
  try {
3628
3472
  const cloud = client.target.kind === "cloud";
@@ -3653,8 +3497,8 @@ var lsCommand5 = new Command49("ls").description("list snapshots (yours and your
3653
3497
  });
3654
3498
 
3655
3499
  // src/commands/snapshots/new.ts
3656
- import { Command as Command50 } from "commander";
3657
- var newCommand2 = new Command50("new").description("freeze a running box (memory + disk) into a snapshot; the box keeps running").argument("<box>", "box name").argument("<name>", "snapshot name").option("--replace", "retake a snapshot that exists under this name; the old one stays until the new one is complete").option("--json", "print the snapshot as JSON").action(async (box, name, opts, cmd) => {
3500
+ import { Command as Command42 } from "commander";
3501
+ var newCommand2 = new Command42("new").description("freeze a running box (memory + disk) into a snapshot; the box keeps running").argument("<box>", "box name").argument("<name>", "snapshot name").option("--replace", "retake a snapshot that exists under this name; the old one stays until the new one is complete").option("--json", "print the snapshot as JSON").action(async (box, name, opts, cmd) => {
3658
3502
  const client = await clientFor(cmd.optsWithGlobals());
3659
3503
  try {
3660
3504
  const req = { box, name, ...opts.replace ? { replace: true } : {} };
@@ -3667,8 +3511,8 @@ var newCommand2 = new Command50("new").description("freeze a running box (memory
3667
3511
  });
3668
3512
 
3669
3513
  // src/commands/snapshots/rm.ts
3670
- import { Command as Command51 } from "commander";
3671
- var rmCommand4 = new Command51("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) => {
3514
+ import { Command as Command43 } from "commander";
3515
+ var rmCommand4 = new Command43("rm").description("delete a snapshot (boxes made from it are not affected)").argument("<name>", "snapshot name").option("-y, --yes", "do not ask for confirmation").action(async (name, opts, cmd) => {
3672
3516
  if (!await confirm(`Delete snapshot ${name}?`, opts.yes ?? false)) {
3673
3517
  info("cancelled");
3674
3518
  process.exitCode = 1;
@@ -3684,14 +3528,14 @@ var rmCommand4 = new Command51("rm").description("delete a snapshot (boxes made
3684
3528
  });
3685
3529
 
3686
3530
  // src/commands/snapshots/index.ts
3687
- var snapshotsCommand = new Command52("snapshots").aliases(["snapshot", "snap"]).description("freeze running boxes into snapshots and manage them").addCommand(newCommand2).addCommand(lsCommand5).addCommand(rmCommand4);
3531
+ var snapshotsCommand = new Command44("snapshots").aliases(["snapshot", "snap"]).description("freeze running boxes into snapshots and manage them").addCommand(newCommand2).addCommand(lsCommand5).addCommand(rmCommand4);
3688
3532
  for (const cmd of snapshotsCommand.commands) cmd.option("--org <slug>", "act in this org (- for your personal boxes)");
3689
3533
 
3690
3534
  // src/commands/org/index.ts
3691
- import { Command as Command58 } from "commander";
3535
+ import { Command as Command50 } from "commander";
3692
3536
 
3693
3537
  // src/commands/org/ls.ts
3694
- import { Command as Command53 } from "commander";
3538
+ import { Command as Command45 } from "commander";
3695
3539
 
3696
3540
  // src/commands/org/context.ts
3697
3541
  var NOT_LOGGED_IN = "orgs live on the control plane: kvbox login first";
@@ -3711,7 +3555,7 @@ function orgFor(opts, target) {
3711
3555
  }
3712
3556
 
3713
3557
  // src/commands/org/ls.ts
3714
- var lsCommand6 = new Command53("ls").description("list the orgs you belong to and your role in each").option("--json", "print as JSON").action(async (opts, cmd) => {
3558
+ var lsCommand6 = new Command45("ls").description("list the orgs you belong to and your role in each").option("--json", "print as JSON").action(async (opts, cmd) => {
3715
3559
  const client = await cloudClientFor(cmd.optsWithGlobals());
3716
3560
  try {
3717
3561
  const orgs = await client.listOrgs();
@@ -3733,8 +3577,8 @@ function orgRows(orgs) {
3733
3577
  }
3734
3578
 
3735
3579
  // src/commands/org/members.ts
3736
- import { Command as Command54, Option as Option4 } from "commander";
3737
- var lsCommand7 = new Command54("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) => {
3580
+ import { Command as Command46, Option as Option4 } from "commander";
3581
+ var lsCommand7 = new Command46("ls").description("list an org's members and their roles").option("-o, --org <slug>", "the org (or --org before the command)").option("--json", "print as JSON").action(async (opts, cmd) => {
3738
3582
  const client = await cloudClientFor(cmd.optsWithGlobals());
3739
3583
  try {
3740
3584
  const org = await client.getOrg(orgFor(opts, client.target));
@@ -3748,7 +3592,7 @@ var lsCommand7 = new Command54("ls").description("list an org's members and thei
3748
3592
  await client.close();
3749
3593
  }
3750
3594
  });
3751
- var addCommand2 = new Command54("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) => {
3595
+ var addCommand2 = new Command46("add").description("add a user to an org (admins and owners; only an owner can add an owner)").argument("<user>", "their username").addOption(new Option4("-r, --role <role>", "their role").choices(ORG_ROLES).default("member")).option("-o, --org <slug>", "the org (or --org before the command)").action(async (user, opts, cmd) => {
3752
3596
  const client = await cloudClientFor(cmd.optsWithGlobals());
3753
3597
  try {
3754
3598
  const slug = orgFor(opts, client.target);
@@ -3758,7 +3602,7 @@ var addCommand2 = new Command54("add").description("add a user to an org (admins
3758
3602
  await client.close();
3759
3603
  }
3760
3604
  });
3761
- var rmCommand5 = new Command54("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) => {
3605
+ var rmCommand5 = new Command46("rm").description("remove a member (or leave: remove yourself)").argument("<user>", "their username").option("-o, --org <slug>", "the org (or --org before the command)").option("-y, --yes", "do not ask for confirmation").action(async (user, opts, cmd) => {
3762
3606
  const client = await cloudClientFor(cmd.optsWithGlobals());
3763
3607
  try {
3764
3608
  const slug = orgFor(opts, client.target);
@@ -3774,11 +3618,11 @@ var rmCommand5 = new Command54("rm").description("remove a member (or leave: rem
3774
3618
  await client.close();
3775
3619
  }
3776
3620
  });
3777
- var membersCommand = new Command54("members").description("who is in an org and what they may do").addCommand(lsCommand7).addCommand(addCommand2).addCommand(rmCommand5);
3621
+ var membersCommand = new Command46("members").description("who is in an org and what they may do").addCommand(lsCommand7).addCommand(addCommand2).addCommand(rmCommand5);
3778
3622
 
3779
3623
  // src/commands/org/new.ts
3780
- import { Command as Command55 } from "commander";
3781
- var newCommand3 = new Command55("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) => {
3624
+ import { Command as Command47 } from "commander";
3625
+ var newCommand3 = new Command47("new").description("create an org; you become its owner (the slug is permanent, the name is not)").argument("<slug>", "the org's slug: lowercase, like a username (acme)").option("-n, --name <name>", "display name (default: the slug)").option("--json", "print the org as JSON").action(async (slug, opts, cmd) => {
3782
3626
  const client = await cloudClientFor(cmd.optsWithGlobals());
3783
3627
  try {
3784
3628
  const org = await client.createOrg({ slug, name: opts.name ?? slug });
@@ -3794,8 +3638,8 @@ var newCommand3 = new Command55("new").description("create an org; you become it
3794
3638
  });
3795
3639
 
3796
3640
  // src/commands/org/rm.ts
3797
- import { Command as Command56 } from "commander";
3798
- var rmCommand6 = new Command56("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) => {
3641
+ import { Command as Command48 } from "commander";
3642
+ var rmCommand6 = new Command48("rm").description("delete an org (owners only; remove its boxes and snapshots first)").argument("<slug>", "the org").option("-y, --yes", "do not ask for confirmation").action(async (slug, opts, cmd) => {
3799
3643
  if (!await confirm(`Delete org ${slug}? Its members lose access; its slug stays taken.`, opts.yes ?? false)) {
3800
3644
  info("cancelled");
3801
3645
  process.exitCode = 1;
@@ -3811,8 +3655,8 @@ var rmCommand6 = new Command56("rm").description("delete an org (owners only; re
3811
3655
  });
3812
3656
 
3813
3657
  // src/commands/org/role.ts
3814
- import { Argument, Command as Command57 } from "commander";
3815
- var roleCommand = new Command57("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) => {
3658
+ import { Argument, Command as Command49 } from "commander";
3659
+ var roleCommand = new Command49("role").description("change a member's role (owners only)").argument("<user>", "their username").addArgument(new Argument("<role>", "owner, admin or member").choices(ORG_ROLES)).option("-o, --org <slug>", "the org (default: the current context)").action(async (user, role, opts, cmd) => {
3816
3660
  const client = await cloudClientFor(cmd.optsWithGlobals());
3817
3661
  try {
3818
3662
  const slug = orgFor(opts, client.target);
@@ -3824,10 +3668,10 @@ var roleCommand = new Command57("role").description("change a member's role (own
3824
3668
  });
3825
3669
 
3826
3670
  // src/commands/org/index.ts
3827
- var orgCommand = new Command58("org").description("orgs: shared slugs that own boxes, with owners, admins and members").addCommand(lsCommand6).addCommand(newCommand3).addCommand(membersCommand).addCommand(roleCommand).addCommand(rmCommand6);
3671
+ var orgCommand = new Command50("org").description("orgs: shared slugs that own boxes, with owners, admins and members").addCommand(lsCommand6).addCommand(newCommand3).addCommand(membersCommand).addCommand(roleCommand).addCommand(rmCommand6);
3828
3672
 
3829
3673
  // src/commands/usage.ts
3830
- import { Command as Command59 } from "commander";
3674
+ import { Command as Command51 } from "commander";
3831
3675
 
3832
3676
  // ../shared/src/usage.ts
3833
3677
  import { z as z4 } from "zod";
@@ -3866,7 +3710,7 @@ function sumUsage(items, pricing) {
3866
3710
  }
3867
3711
 
3868
3712
  // src/commands/usage.ts
3869
- var usageCommand2 = new Command59("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) => {
3713
+ var usageCommand2 = new Command51("usage").description("what your boxes and volumes used this month (or --since/--until): running time, vCPU-h, RAM and disk GiB-h, cost").option("--since <date>", "count from this date, e.g. 2026-10-01 (default: the 1st of this month)").option("--until <date>", "count up to this date (default: now)").option("--org <slug>", "one org's boxes only").option("-a, --all", "every box on the platform (platform admins only)").option("--by-user", "one line per user who made the boxes (e.g. who spent what in --org)").option("--json", "print as JSON").action(async (opts, cmd) => {
3870
3714
  for (const [name, value] of [
3871
3715
  ["since", opts.since],
3872
3716
  ["until", opts.until]
@@ -4012,8 +3856,8 @@ function userRows(r) {
4012
3856
  }
4013
3857
 
4014
3858
  // src/commands/credit.ts
4015
- import { Command as Command60 } from "commander";
4016
- var creditCommand = new Command60("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) => {
3859
+ import { Command as Command52 } from "commander";
3860
+ var creditCommand = new Command52("credit").description("the prepaid credit left on your account and on each of your orgs").option("--org <slug>", "one org only").option("--json", "print as JSON").action(async (opts, cmd) => {
4017
3861
  const client = await clientFor(cmd.optsWithGlobals(), { autoStart: false });
4018
3862
  try {
4019
3863
  if (client.target.kind === "local") throw new KvboxError("credit lives on the control plane: kvbox login first");
@@ -4041,17 +3885,17 @@ function creditRow(b, me2) {
4041
3885
  }
4042
3886
 
4043
3887
  // src/commands/deploy/index.ts
4044
- import { access as access4, readFile as readFile8 } from "fs/promises";
3888
+ import { access as access4, readFile as readFile7 } from "fs/promises";
4045
3889
  import { basename, resolve as resolve2 } from "path";
4046
- import { Command as Command61, InvalidArgumentError as InvalidArgumentError2, Option as Option5 } from "commander";
3890
+ import { Command as Command53, InvalidArgumentError as InvalidArgumentError2, Option as Option5 } from "commander";
4047
3891
 
4048
3892
  // src/commands/deploy/config.ts
4049
- import { readFile as readFile7, writeFile as writeFile4 } from "fs/promises";
3893
+ import { readFile as readFile6, writeFile as writeFile4 } from "fs/promises";
4050
3894
  import { join as join6 } from "path";
4051
3895
  import { z as z5 } from "zod";
4052
3896
 
4053
3897
  // src/commands/deploy/templates/docker.ts
4054
- import { readFile as readFile6 } from "fs/promises";
3898
+ import { readFile as readFile5 } from "fs/promises";
4055
3899
  import { join as join2 } from "path";
4056
3900
 
4057
3901
  // src/commands/deploy/templates/server.ts
@@ -4150,7 +3994,7 @@ var dockerTemplate = {
4150
3994
  },
4151
3995
  /** No local build: the box does it. The Dockerfile is read for its EXPOSE port only. */
4152
3996
  async build(ctx) {
4153
- const dockerfile = await readFile6(join2(ctx.dir, "Dockerfile"), "utf8").catch(() => void 0);
3997
+ const dockerfile = await readFile5(join2(ctx.dir, "Dockerfile"), "utf8").catch(() => void 0);
4154
3998
  if (dockerfile === void 0) throw new KvboxError(`${ctx.dir}: no Dockerfile; the Docker template builds the image from it`);
4155
3999
  const containerPort = exposedPort(dockerfile);
4156
4000
  return { outDir: ctx.dir, exclude: ["node_modules", ".git"], pm: "npm", what: "the source", ...containerPort !== void 0 ? { containerPort } : {} };
@@ -4257,7 +4101,7 @@ var nodeTemplate = {
4257
4101
  };
4258
4102
 
4259
4103
  // src/commands/deploy/templates/react.ts
4260
- import { spawn as spawn5 } from "child_process";
4104
+ import { spawn as spawn4 } from "child_process";
4261
4105
  import { access as access2 } from "fs/promises";
4262
4106
  import { join as join4 } from "path";
4263
4107
  var OUT_DIRS = ["dist", "build"];
@@ -4265,7 +4109,7 @@ async function runBuild(dir, pm) {
4265
4109
  const args = runScript(pm, "build");
4266
4110
  info(`${color.dim("$")} ${pm} ${args.join(" ")}`);
4267
4111
  const status2 = await new Promise((resolve3, reject) => {
4268
- const child = spawn5(pm, args, { cwd: dir, stdio: ["ignore", process.stderr, process.stderr], shell: process.platform === "win32" });
4112
+ const child = spawn4(pm, args, { cwd: dir, stdio: ["ignore", process.stderr, process.stderr], shell: process.platform === "win32" });
4269
4113
  child.once("error", (err) => reject(new KvboxError(`could not run ${pm}: ${err.message}`)));
4270
4114
  child.once("close", (code) => resolve3(code ?? 1));
4271
4115
  });
@@ -4382,7 +4226,7 @@ async function readConfig(dir) {
4382
4226
  const path = join6(dir, CONFIG_FILE);
4383
4227
  let raw;
4384
4228
  try {
4385
- raw = await readFile7(path, "utf8");
4229
+ raw = await readFile6(path, "utf8");
4386
4230
  } catch (err) {
4387
4231
  if (err.code === "ENOENT") return void 0;
4388
4232
  throw err;
@@ -4412,7 +4256,7 @@ function subdomainFor(name) {
4412
4256
  }
4413
4257
 
4414
4258
  // src/commands/deploy/ship.ts
4415
- import { spawn as spawn6 } from "child_process";
4259
+ import { spawn as spawn5 } from "child_process";
4416
4260
  import { readdir, stat as stat2 } from "fs/promises";
4417
4261
  import { join as join7 } from "path";
4418
4262
  var IMAGE_TOO_OLD = 3;
@@ -4434,8 +4278,8 @@ async function measure(dir, exclude = []) {
4434
4278
  return total;
4435
4279
  }
4436
4280
  async function ship(ep, dir, remote, exclude = []) {
4437
- const tar = spawn6("tar", ["-cf", "-", ...exclude.map((e) => `--exclude=${e}`), "-C", dir, "."], { stdio: ["ignore", "pipe", "pipe"] });
4438
- const ssh = spawn6("ssh", [...sshArgs(ep), remote], { stdio: ["pipe", "pipe", "pipe"] });
4281
+ const tar = spawn5("tar", ["-cf", "-", ...exclude.map((e) => `--exclude=${e}`), "-C", dir, "."], { stdio: ["ignore", "pipe", "pipe"] });
4282
+ const ssh = spawn5("ssh", [...sshArgs(ep), remote], { stdio: ["pipe", "pipe", "pipe"] });
4439
4283
  tar.stdout.pipe(ssh.stdin);
4440
4284
  const chunks = [];
4441
4285
  ssh.stdout.on("data", (c) => chunks.push(c));
@@ -4465,7 +4309,7 @@ async function ship(ep, dir, remote, exclude = []) {
4465
4309
  var shipping = { ship, measure, waitForSsh };
4466
4310
 
4467
4311
  // src/commands/deploy/index.ts
4468
- var deployCommand = new Command61("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("-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) => {
4312
+ var deployCommand = new Command53("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("-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) => {
4469
4313
  const dir = resolve2(dirArg ?? ".");
4470
4314
  const pkg = await readPackageJson(dir);
4471
4315
  const facts = { indexHtml: await exists(resolve2(dir, "index.html")), dockerfile: await exists(resolve2(dir, "Dockerfile")) };
@@ -4550,7 +4394,7 @@ function parsePort(v) {
4550
4394
  var exists = (path) => access4(path).then(() => true, () => false);
4551
4395
  async function readPackageJson(dir) {
4552
4396
  try {
4553
- return JSON.parse(await readFile8(resolve2(dir, "package.json"), "utf8"));
4397
+ return JSON.parse(await readFile7(resolve2(dir, "package.json"), "utf8"));
4554
4398
  } catch (err) {
4555
4399
  if (err.code === "ENOENT") return void 0;
4556
4400
  throw new KvboxError(`${resolve2(dir, "package.json")}: ${err.message}`);
@@ -4676,15 +4520,15 @@ the app is on box ${ref} but has no address yet: pick another with kvbox deploy
4676
4520
  }
4677
4521
 
4678
4522
  // src/commands/volume/index.ts
4679
- import { Command as Command67 } from "commander";
4523
+ import { Command as Command59 } from "commander";
4680
4524
 
4681
4525
  // src/commands/volume/attach.ts
4682
- import { Command as Command62 } from "commander";
4526
+ import { Command as Command54 } from "commander";
4683
4527
  function describeMount(machine, volume, box) {
4684
4528
  const path = machine.volumes?.find((v) => volume === v.name || volume.endsWith(`/${v.name}`))?.mountPath ?? volumeMountPath(volume.slice(volume.lastIndexOf("/") + 1));
4685
4529
  return machine.status === "running" ? ` the box was restarted; the volume is at ${path} inside it` : ` box ${box} is ${machine.status}; the volume is at ${path} once it runs`;
4686
4530
  }
4687
- var attachCommand = new Command62("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) => {
4531
+ var attachCommand = new Command54("attach").description("attach a volume to a box at /mnt/<volume> (a running box is restarted to take it)").argument("[volume]", "volume name (picked from a list when left out)").argument("[box]", "box name (picked from a list when left out)").option("--json", "print the box as JSON").action(async (volumeArg, boxArg, opts, cmd) => {
4688
4532
  if (volumeArg === void 0 || boxArg === void 0) askOrUsage("give the volume and the box: kvbox volume attach <volume> <box>");
4689
4533
  const client = await clientFor(cmd.optsWithGlobals());
4690
4534
  try {
@@ -4703,7 +4547,7 @@ var attachCommand = new Command62("attach").description("attach a volume to a bo
4703
4547
  });
4704
4548
 
4705
4549
  // src/commands/volume/create.ts
4706
- import { Command as Command63 } from "commander";
4550
+ import { Command as Command55 } from "commander";
4707
4551
  function parseGib2(text2) {
4708
4552
  const mib = parseMib(text2);
4709
4553
  if (mib === void 0 || mib % 1024 !== 0) throw new KvboxError(`--size ${text2}: write whole GB, like 50 or 50GB`);
@@ -4719,7 +4563,7 @@ function sizeProblem(answer) {
4719
4563
  return err instanceof KvboxError ? err.message.replace(/^--size \S+: /, "") : String(err);
4720
4564
  }
4721
4565
  }
4722
- var createCommand3 = new Command63("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) => {
4566
+ var createCommand3 = new Command55("create").alias("new").description("create a volume for a box: an empty disk of its own at /mnt/<name> inside it (a running box is restarted)").argument("[name]", "volume name (1-12 chars; the box mounts it at /mnt/<name>; asked for when left out)").option("--size <gb>", "size in GB, like 50 or 50GB (whole GB; it only occupies what is written)").option("--box <box>", "the box it is for: made on that box's host and attached to it (required on kvbox.sh; optional with --local)").option("--json", "print the volume as JSON").action(async (nameArg, opts, cmd) => {
4723
4567
  const ask = interactive();
4724
4568
  if (nameArg === void 0 || opts.size === void 0) askOrUsage("give the name and the size: kvbox volume create <name> --size <gb> --box <box>");
4725
4569
  const name = nameArg ?? await text("Volume name", { validate: (a) => VOLUME_NAME_RE.test(a) ? void 0 : VOLUME_NAME_RULE });
@@ -4752,8 +4596,8 @@ var createCommand3 = new Command63("create").alias("new").description("create a
4752
4596
  });
4753
4597
 
4754
4598
  // src/commands/volume/detach.ts
4755
- import { Command as Command64 } from "commander";
4756
- var detachCommand = new Command64("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) => {
4599
+ import { Command as Command56 } from "commander";
4600
+ var detachCommand = new Command56("detach").description("detach a volume from a box; its data is kept (a running box is restarted)").argument("[volume]", "volume name (picked from a list when left out)").argument("[box]", "box name (the one the volume is on when left out)").option("--json", "print the box as JSON").action(async (volumeArg, boxArg, opts, cmd) => {
4757
4601
  if (volumeArg === void 0) askOrUsage("give the volume: kvbox volume detach <volume> [box]");
4758
4602
  const client = await clientFor(cmd.optsWithGlobals());
4759
4603
  try {
@@ -4778,8 +4622,8 @@ var detachCommand = new Command64("detach").description("detach a volume from a
4778
4622
  });
4779
4623
 
4780
4624
  // src/commands/volume/ls.ts
4781
- import { Command as Command65 } from "commander";
4782
- var lsCommand8 = new Command65("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) => {
4625
+ import { Command as Command57 } from "commander";
4626
+ var lsCommand8 = new Command57("ls").alias("list").description("list volumes: size, what they occupy, which box has them").option("-a, --all", "every volume on the platform (platform admins only)").option("--json", "print as JSON").action(async (opts, cmd) => {
4783
4627
  const client = await clientFor(cmd.optsWithGlobals());
4784
4628
  try {
4785
4629
  const cloud = client.target.kind === "cloud";
@@ -4810,8 +4654,8 @@ var lsCommand8 = new Command65("ls").alias("list").description("list volumes: si
4810
4654
  });
4811
4655
 
4812
4656
  // src/commands/volume/rm.ts
4813
- import { Command as Command66 } from "commander";
4814
- var rmCommand7 = new Command66("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) => {
4657
+ import { Command as Command58 } from "commander";
4658
+ var rmCommand7 = new Command58("rm").alias("remove").description("delete a volume and everything on it (detach it first)").argument("<name>", "volume name").option("-y, --yes", "do not ask for confirmation").action(async (name, opts, cmd) => {
4815
4659
  if (!await confirm(`Delete volume ${name} and everything on it?`, opts.yes ?? false)) {
4816
4660
  info("cancelled");
4817
4661
  process.exitCode = 1;
@@ -4827,14 +4671,14 @@ var rmCommand7 = new Command66("rm").alias("remove").description("delete a volum
4827
4671
  });
4828
4672
 
4829
4673
  // src/commands/volume/index.ts
4830
- var volumeCommand = new Command67("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(createCommand3).addCommand(lsCommand8).addCommand(attachCommand).addCommand(detachCommand).addCommand(rmCommand7);
4674
+ var volumeCommand = new Command59("volume").aliases(["volumes", "vol"]).description("disks of their own: create one, attach it to a box at /mnt/<name>, move it to another box later").addCommand(createCommand3).addCommand(lsCommand8).addCommand(attachCommand).addCommand(detachCommand).addCommand(rmCommand7);
4831
4675
  for (const cmd of volumeCommand.commands) cmd.option("--org <slug>", "act in this org (- for your personal volumes)");
4832
4676
 
4833
4677
  // src/commands/env/index.ts
4834
- import { Command as Command71 } from "commander";
4678
+ import { Command as Command63 } from "commander";
4835
4679
 
4836
4680
  // src/commands/env/ls.ts
4837
- import { Command as Command68 } from "commander";
4681
+ import { Command as Command60 } from "commander";
4838
4682
 
4839
4683
  // src/commands/env/shared.ts
4840
4684
  function requireCloud4(client) {
@@ -4861,7 +4705,7 @@ function firstBootHint(box, name) {
4861
4705
  }
4862
4706
 
4863
4707
  // src/commands/env/ls.ts
4864
- var lsCommand9 = new Command68("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) => {
4708
+ var lsCommand9 = new Command60("ls").alias("list").description("list the variables (a secret shows as (sealed))").option("--box <box>", "what this box gets: its own variables and the ones it inherits").option("--json", "print as JSON").action(async (opts, cmd) => {
4865
4709
  const client = await clientFor(cmd.optsWithGlobals(), { autoStart: false });
4866
4710
  try {
4867
4711
  if (opts.box !== void 0) {
@@ -4900,8 +4744,8 @@ var lsCommand9 = new Command68("ls").alias("list").description("list the variabl
4900
4744
  });
4901
4745
 
4902
4746
  // src/commands/env/rm.ts
4903
- import { Command as Command69 } from "commander";
4904
- var rmCommand8 = new Command69("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) => {
4747
+ import { Command as Command61 } from "commander";
4748
+ var rmCommand8 = new Command61("rm").alias("remove").description("remove variables; boxes lose them when they next start").argument("<names...>", "variable names").option("-y, --yes", "do not ask for confirmation").option("--box <box>", "remove this box's own variables (yours, or the org's, of the same name come back)").option("--json", "print as JSON").action(async (names2, opts, cmd) => {
4905
4749
  const client = await clientFor(cmd.optsWithGlobals(), { autoStart: false });
4906
4750
  try {
4907
4751
  const target = opts.box === void 0 ? void 0 : await findBox2(client, opts.box);
@@ -4938,8 +4782,8 @@ var rmCommand8 = new Command69("rm").alias("remove").description("remove variabl
4938
4782
  });
4939
4783
 
4940
4784
  // src/commands/env/set.ts
4941
- import { Command as Command70 } from "commander";
4942
- var setCommand2 = new Command70("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) => {
4785
+ import { Command as Command62 } from "commander";
4786
+ var setCommand2 = new Command62("set").description("add or change a variable; boxes get it when they next start").argument("[name]", "variable name, e.g. DATABASE_URL (asked for when left out)").argument("[value]", "its value (asked for when left out; hidden with --secret)").option("--secret", "write-only: the value is never shown again, by any command").option("--box <box>", "this box's own variable, over yours (or the org's) of the same name").option("--json", "print as JSON").action(async (nameArg, valueArg, opts, cmd) => {
4943
4787
  const client = await clientFor(cmd.optsWithGlobals(), { autoStart: false });
4944
4788
  try {
4945
4789
  const owner = opts.box === void 0 ? requireCloud4(client) : void 0;
@@ -4976,14 +4820,14 @@ var setCommand2 = new Command70("set").description("add or change a variable; bo
4976
4820
  });
4977
4821
 
4978
4822
  // src/commands/env/index.ts
4979
- var envCommand = new Command71("env").description("environment variables every box of yours gets when it starts (secrets too)").addCommand(lsCommand9, { isDefault: true }).addCommand(setCommand2).addCommand(rmCommand8);
4823
+ var envCommand = new Command63("env").description("environment variables every box of yours gets when it starts (secrets too)").addCommand(lsCommand9, { isDefault: true }).addCommand(setCommand2).addCommand(rmCommand8);
4980
4824
  for (const cmd of envCommand.commands) cmd.option("--org <slug>", "the org's variables instead of yours");
4981
4825
 
4982
4826
  // src/commands/domain/index.ts
4983
- import { Command as Command75 } from "commander";
4827
+ import { Command as Command67 } from "commander";
4984
4828
 
4985
4829
  // src/commands/domain/add.ts
4986
- import { Command as Command72 } from "commander";
4830
+ import { Command as Command64 } from "commander";
4987
4831
 
4988
4832
  // src/commands/domain/shared.ts
4989
4833
  function requireCloud5(client) {
@@ -5003,7 +4847,7 @@ function hostIn(name, zone) {
5003
4847
  }
5004
4848
 
5005
4849
  // src/commands/domain/add.ts
5006
- var addCommand3 = new Command72("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) => {
4850
+ var addCommand3 = new Command64("add").description("serve a box at a domain of your own, https://<domain>, with its certificate made for you").argument("<domain>", "a domain you control, like example.com or app.example.com").argument("<box>", "box name").option("--port <port>", "the box port the domain serves (default: the port of its kvbox.app address)").option("--json", "print the domain as JSON").action(async (domainArg, name, opts, cmd) => {
5007
4851
  const domain = assertDomain(domainArg.trim().toLowerCase());
5008
4852
  const port = opts.port === void 0 ? void 0 : parsePorts([opts.port])[0];
5009
4853
  const client = await clientFor(cmd.optsWithGlobals());
@@ -5039,8 +4883,8 @@ kvbox checks every minute; ${domain} is served at ${d.url} once its records are
5039
4883
  });
5040
4884
 
5041
4885
  // src/commands/domain/ls.ts
5042
- import { Command as Command73 } from "commander";
5043
- var lsCommand10 = new Command73("ls").alias("list").description("list your custom domains and whether they are live").option("--json", "print as JSON").action(async (opts, cmd) => {
4886
+ import { Command as Command65 } from "commander";
4887
+ var lsCommand10 = new Command65("ls").alias("list").description("list your custom domains and whether they are live").option("--json", "print as JSON").action(async (opts, cmd) => {
5044
4888
  const client = await clientFor(cmd.optsWithGlobals());
5045
4889
  try {
5046
4890
  requireCloud5(client);
@@ -5069,8 +4913,8 @@ var lsCommand10 = new Command73("ls").alias("list").description("list your custo
5069
4913
  });
5070
4914
 
5071
4915
  // src/commands/domain/rm.ts
5072
- import { Command as Command74 } from "commander";
5073
- var rmCommand9 = new Command74("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) => {
4916
+ import { Command as Command66 } from "commander";
4917
+ var rmCommand9 = new Command66("rm").alias("remove").description("stop serving a box at a custom domain").argument("<domain>", "the domain").option("-y, --yes", "do not ask for confirmation").action(async (domainArg, opts, cmd) => {
5074
4918
  const domain = domainArg.trim().toLowerCase();
5075
4919
  const client = await clientFor(cmd.optsWithGlobals());
5076
4920
  try {
@@ -5091,15 +4935,15 @@ var rmCommand9 = new Command74("rm").alias("remove").description("stop serving a
5091
4935
  });
5092
4936
 
5093
4937
  // src/commands/domain/index.ts
5094
- var domainCommand = new Command75("domain").alias("domains").description("serve a box at a domain of your own").addCommand(addCommand3).addCommand(lsCommand10).addCommand(rmCommand9);
4938
+ var domainCommand = new Command67("domain").alias("domains").description("serve a box at a domain of your own").addCommand(addCommand3).addCommand(lsCommand10).addCommand(rmCommand9);
5095
4939
  for (const cmd of domainCommand.commands) cmd.option("--org <slug>", "act in this org (- for your personal boxes)");
5096
4940
 
5097
4941
  // src/commands/update.ts
5098
- import { spawn as spawn7 } from "child_process";
4942
+ import { spawn as spawn6 } from "child_process";
5099
4943
  import { mkdtempSync, rmSync, writeFileSync as writeFileSync2 } from "fs";
5100
4944
  import { tmpdir } from "os";
5101
4945
  import { join as join8 } from "path";
5102
- import { Command as Command76 } from "commander";
4946
+ import { Command as Command68 } from "commander";
5103
4947
 
5104
4948
  // src/update.ts
5105
4949
  import { mkdirSync, readFileSync as readFileSync3, writeFileSync } from "fs";
@@ -5213,12 +5057,12 @@ async function download(url) {
5213
5057
  }
5214
5058
  function run(cmd, args) {
5215
5059
  return new Promise((resolve3, reject) => {
5216
- const child = spawn7(cmd, args, { stdio: "inherit" });
5060
+ const child = spawn6(cmd, args, { stdio: "inherit" });
5217
5061
  child.on("error", (err) => reject(new KvboxError(`could not run ${cmd}: ${err.message}`)));
5218
5062
  child.on("exit", (code, signal) => resolve3(code ?? (signal ? 1 : 0)));
5219
5063
  });
5220
5064
  }
5221
- var selfUpdateCommand = new Command76("update").description("update kvbox to the latest version (reruns the installer from kvbox.sh, agent skill included)").action(async () => {
5065
+ var selfUpdateCommand = new Command68("update").description("update kvbox to the latest version (reruns the installer from kvbox.sh, agent skill included)").action(async () => {
5222
5066
  suppressUpdateNotice();
5223
5067
  const inst = installerFor(process.platform, process.env["KVBOX_INSTALL_URL"] || INSTALL_BASE);
5224
5068
  let code;
@@ -5240,13 +5084,12 @@ var selfUpdateCommand = new Command76("update").description("update kvbox to the
5240
5084
 
5241
5085
  // src/program.ts
5242
5086
  function buildProgram() {
5243
- const program = new Command77("kvbox").description("self-hosted Firecracker microVMs with Docker-like ergonomics").version(VERSION, "-v, --version").option("--local", "use this machine's kvbox-server over its socket, ignoring kvbox login").option("--org <slug>", "the org: where kvbox new creates, and which box a name means when it is not one of yours; before the command here, or after it").showHelpAfterError().enablePositionalOptions();
5087
+ const program = new Command69("kvbox").description("self-hosted Firecracker microVMs with Docker-like ergonomics").version(VERSION, "-v, --version").option("--local", "use this machine's kvbox-server over its socket, ignoring kvbox login").option("--org <slug>", "the org: where kvbox new creates, and which box a name means when it is not one of yours; before the command here, or after it").showHelpAfterError().enablePositionalOptions();
5244
5088
  program.addCommand(vmCommand);
5245
5089
  program.addCommand(snapshotsCommand);
5246
5090
  program.addCommand(volumeCommand);
5247
5091
  program.addCommand(envCommand);
5248
5092
  program.addCommand(domainCommand);
5249
- program.addCommand(serverCommand);
5250
5093
  program.addCommand(loginCommand);
5251
5094
  program.addCommand(logoutCommand);
5252
5095
  program.addCommand(whoamiCommand);