koigrid 0.11.0 → 0.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -4,10 +4,22 @@ All notable changes to the koigrid CLI are documented here. Format: [Keep a Chan
4
4
 
5
5
  ## [Unreleased]
6
6
 
7
+ ## [0.12.0] — 2026-11-27
8
+
9
+ ### Added
10
+
11
+ - `koigrid db ext <id>`: the extensions installed in each database (also those created with `CREATE EXTENSION` outside the API) and the preloaded libraries, read live from a running member; says why when no member answers instead of printing an empty list.
12
+
7
13
  ## [0.11.0] — 2026-11-26
8
14
 
9
15
  ### Added
10
16
 
17
+ - `koigrid sandboxes vm create <name> --from <snapshot>`: a VM born from a named snapshot (template), with its disk, memory and size.
18
+ - `koigrid sandboxes vm snapshots` (no VM): the named snapshots of the project, also of deleted VMs; `vm snapshot-rm <snapshot>` deletes one. A named snapshot now outlives its VM.
19
+ - `koigrid sandboxes vm snapshot-ls <snapshot> [path]` and `snapshot-cat <snapshot> <path>`: read the snapshot disk without booting it.
20
+ - `koigrid sandboxes vm run [--dir LOCAL] [--size S] [--from SNAPSHOT] [--keep] -- <command>`: one go — creates a VM, uploads the folder to /root/work, runs the command with live output (exits with its code), prints the cost and deletes the VM.
21
+ - `koigrid sandboxes vm history <vm>`: the commands run in the VM (direct and background), newest first, kept 90 days; `vm ps <vm>`: the processes running now.
22
+ - `koigrid sandboxes vm snapshot-share <snapshot> [--expires-days N]`: a code (shown once) another organization uses with `vm create --from`; `snapshot-shares` lists the codes given and `snapshot-unshare <snapshot> <share-id>` revokes one.
11
23
  - `koigrid apps github-repos`: the repositories your connected GitHub App installations can deploy, latest push first (or the link to connect GitHub).
12
24
  - `koigrid apps deploy --repo <github-url> --github-installation <id>`: links the app to the GitHub App before the first deploy, so a private repo clones without a token and every push redeploys.
13
25
  - `koigrid dns list`, `koigrid logs list` and `koigrid wordpress list`: `list` now works as an alias of `ls` in every command that lists, as it already did in the rest.
@@ -305,7 +305,19 @@ export async function db(a) {
305
305
  const name = a.positionals[1];
306
306
  if (!name) {
307
307
  const r = await api(`/databases/${encodeURIComponent(id)}/extensions`);
308
- return console.log(json ? JSON.stringify(r, null, 2) : 'allowed: ' + (r.allowed || []).join(', '));
308
+ if (json)
309
+ return console.log(JSON.stringify(r, null, 2));
310
+ console.log('allowed: ' + (r.allowed || []).join(', '));
311
+ const inst = r.installed;
312
+ if (!inst)
313
+ return;
314
+ if (!inst.measured)
315
+ return console.log(`installed: not measured (${inst.reason})`);
316
+ if (inst.preloadLibraries?.length)
317
+ console.log('preloaded: ' + inst.preloadLibraries.join(', '));
318
+ for (const d of inst.databases || [])
319
+ console.log(`installed in ${d.name}: ` + d.extensions.map((e) => `${e.name} ${e.version}`).join(', '));
320
+ return;
309
321
  }
310
322
  // `--schema` (paridad con la API): instala la extensión en ese schema. Es el camino de los ex-Supabase —
311
323
  // sus dumps declaran tipos como `extensions.vector`, así que sin esto el restore falla con "type
@@ -52,13 +52,19 @@ export async function sandboxes(a) {
52
52
  }
53
53
  const USO_VM = `usage: koigrid sandboxes vm <action> …
54
54
  ls list VMs
55
+ run [--dir LOCAL] [--size S] [--from SNAPSHOT] [--keep] -- <command…>
56
+ one go: create a VM, upload the folder to /root/work, run the command there
57
+ (live output, exits with its code), print the cost, delete the VM (--keep: don't)
55
58
  create <name> [--size small|medium|large|xlarge] [--auto-pause MIN] [--label k=v] [--ssh-key FILE.pub]
59
+ create <name> --from <snapshot> born from a named snapshot (template) or a share code (koisnap_…): its disk and memory, its size
56
60
  [--env KEY=VALUE]… [--repo owner/repo]… [--environment FILE.json] [--safe-for-third-parties]
57
61
  env <vm> its environment: variable names, files, repositories, last apply (never values)
58
62
  env set <vm> [--env KEY=VALUE]… [--repo owner/repo]… [--environment FILE.json] [--safe-for-third-parties]
59
63
  replace it (values may use \${{ shared.KEY }}, \${{ db.<name>.DATABASE_URL }}…)
60
64
  token <vm> [--expires SECONDS] [--read-only] an API token that only works on this VM, to hand to someone else
61
65
  usage <vm> [--days N] what it has used: seconds running, GB·h and cost, per day (≤90 days)
66
+ history <vm> [--limit N] [--before ISO] commands run in it (direct and background), newest first, 90 days
67
+ ps <vm> processes running now, highest CPU first
62
68
  limits fair-use ceilings of your VMs and how much of each is used
63
69
  ssh <vm> [-- command] SSH into the VM (wakes it if paused); needs your key on it (ssh-key set)
64
70
  ssh-key set <vm> [--key FILE.pub]… replace the keys allowed in (default ~/.ssh/id_ed25519.pub) · ssh-key ls <vm>
@@ -73,7 +79,13 @@ const USO_VM = `usage: koigrid sandboxes vm <action> …
73
79
  commands stop <vm> <cmd> SIGTERM to its process group, SIGKILL after 5 s
74
80
  pause|resume|stop|start <vm>
75
81
  fork <vm> --name <new>
76
- snapshot <vm> --name <label> · snapshots <vm>
82
+ snapshot <vm> --name <label> · snapshots <vm> (a named snapshot outlives its VM)
83
+ snapshots named snapshots of the project, also of deleted VMs
84
+ snapshot-rm <snapshot> delete a named snapshot (id or name; cannot be undone)
85
+ snapshot-ls <snapshot> [path] a directory of the snapshot disk, without booting it (default /root)
86
+ snapshot-cat <snapshot> <path> a file of the snapshot disk, without booting it (up to 700 KB)
87
+ snapshot-share <snapshot> [--expires-days N] a code another organization uses as --from (shown once)
88
+ snapshot-shares <snapshot> codes given (prefix, uses, expiry) · snapshot-unshare <snapshot> <share-id>
77
89
  update <vm> [--auto-pause MIN] [--size …] [--label k=v]
78
90
  rm <vm>
79
91
  files ls <vm> [path] [--depth N] · files find <vm> <path> --name '*.ts'
@@ -158,8 +170,12 @@ async function vm(a, json) {
158
170
  const l = r.vms || [];
159
171
  return output(l, json, { rows: l.map(filaVm), columns: ['name', 'size', 'status', 'ssh', 'autoPause', 'id'] });
160
172
  }
173
+ if (accion === 'run')
174
+ return correrDePuntaAPunta(a, json);
161
175
  if (accion === 'create') {
162
176
  const body = { name: necesita() };
177
+ if (a.flags.from)
178
+ body.fromSnapshot = String(a.flags.from);
163
179
  if (a.flags.size)
164
180
  body.size = String(a.flags.size);
165
181
  if (a.flags['auto-pause'] !== undefined)
@@ -186,6 +202,24 @@ async function vm(a, json) {
186
202
  return console.log(JSON.stringify(r, null, 2));
187
203
  return muestraEntorno(r.environment || {});
188
204
  }
205
+ if (accion === 'history') {
206
+ const q = new URLSearchParams();
207
+ if (a.flags.limit !== undefined)
208
+ q.set('limit', String(Number(a.flags.limit)));
209
+ if (a.flags.before)
210
+ q.set('before', String(a.flags.before));
211
+ const r = await api(`/sandboxes/vms/${encodeURIComponent(necesita())}/history${q.size ? `?${q}` : ''}`);
212
+ const l = r.entries || [];
213
+ output(l, json, { rows: l.map((x) => ({ started: x.startedAt, kind: x.kind, status: x.status, exit: x.exitCode ?? '', ms: x.durationMs ?? '', command: String(x.command).slice(0, 80) })), columns: ['started', 'kind', 'status', 'exit', 'ms', 'command'] });
214
+ if (!json && r.nextBefore)
215
+ console.log(`more: --before ${r.nextBefore}`);
216
+ return;
217
+ }
218
+ if (accion === 'ps') {
219
+ const r = await api(`/sandboxes/vms/${encodeURIComponent(necesita())}/processes`);
220
+ const l = r.processes || [];
221
+ return output(l, json, { rows: l.map((x) => ({ pid: x.pid, user: x.user, cpu: x.cpuPct, rssMb: Math.round(x.rssKb / 1024), secs: x.elapsedSec, command: String(x.command).slice(0, 80) })), columns: ['pid', 'user', 'cpu', 'rssMb', 'secs', 'command'] });
222
+ }
189
223
  if (accion === 'usage') {
190
224
  const dias = a.flags.days ? `?days=${Number(a.flags.days)}` : '';
191
225
  const r = await api(`/sandboxes/vms/${encodeURIComponent(necesita())}/usage${dias}`);
@@ -324,6 +358,60 @@ async function vm(a, json) {
324
358
  return console.log(JSON.stringify(r, null, 2));
325
359
  return console.log(green(`✓ snapshot ${r.snapshot?.name} (${r.snapshot?.id})`));
326
360
  }
361
+ if (accion === 'snapshots' && !objetivo) {
362
+ const r = await api('/sandboxes/snapshots');
363
+ const l = r.snapshots || [];
364
+ return output(l, json, { rows: l.map((x) => ({ name: x.name, size: x.size, bytes: x.sizeBytes ?? '', vm: `${x.vm?.name}${x.vm?.deleted ? ' (deleted)' : ''}`, created: x.createdAt, id: String(x.id) })), columns: ['name', 'size', 'bytes', 'vm', 'created', 'id'] });
365
+ }
366
+ if (accion === 'snapshot-ls') {
367
+ const ruta = a.positionals[2] ? `?path=${encodeURIComponent(String(a.positionals[2]))}` : '';
368
+ const r = await api(`/sandboxes/snapshots/${encodeURIComponent(necesita())}/files${ruta}`);
369
+ const l = r.entries || [];
370
+ return output(l, json, { rows: l.map((x) => ({ type: x.type, size: x.size, mode: x.mode, path: x.path })), columns: ['type', 'size', 'mode', 'path'] });
371
+ }
372
+ if (accion === 'snapshot-cat') {
373
+ const ruta = a.positionals[2];
374
+ if (!ruta)
375
+ throw new Error(USO_VM);
376
+ const r = await api(`/sandboxes/snapshots/${encodeURIComponent(necesita())}/files/content?path=${encodeURIComponent(String(ruta))}`);
377
+ if (json)
378
+ return console.log(JSON.stringify(r, null, 2));
379
+ process.stdout.write(Buffer.from(r.contentBase64 || '', 'base64'));
380
+ if (r.truncated)
381
+ console.error(`\n(truncated: the file has ${r.size} bytes, shown ${r.maxBytes})`);
382
+ return;
383
+ }
384
+ if (accion === 'snapshot-share') {
385
+ const body = {};
386
+ if (a.flags['expires-days'] !== undefined)
387
+ body.expiresInDays = Number(a.flags['expires-days']);
388
+ const r = await api(`/sandboxes/snapshots/${encodeURIComponent(necesita())}/shares`, { method: 'POST', body });
389
+ if (json)
390
+ return console.log(JSON.stringify(r, null, 2));
391
+ console.log(green(`✓ share code (shown only now): ${r.code}`));
392
+ console.log(` use it with: koigrid sandboxes vm create <name> --from ${r.code}`);
393
+ return console.error(` ${r.warning}`);
394
+ }
395
+ if (accion === 'snapshot-shares') {
396
+ const r = await api(`/sandboxes/snapshots/${encodeURIComponent(necesita())}/shares`);
397
+ const l = r.shares || [];
398
+ return output(l, json, { rows: l.map((x) => ({ code: `${x.codePrefix}…`, uses: x.uses, expires: x.expiresAt ?? 'never', revoked: x.revokedAt ?? '', created: x.createdAt, id: String(x.id) })), columns: ['code', 'uses', 'expires', 'revoked', 'created', 'id'] });
399
+ }
400
+ if (accion === 'snapshot-unshare') {
401
+ const share = a.positionals[2];
402
+ if (!share)
403
+ throw new Error(USO_VM);
404
+ const r = await api(`/sandboxes/snapshots/${encodeURIComponent(necesita())}/shares/${encodeURIComponent(String(share))}`, { method: 'DELETE' });
405
+ if (json)
406
+ return console.log(JSON.stringify(r, null, 2));
407
+ return console.log(green(`✓ share ${share} revoked`));
408
+ }
409
+ if (accion === 'snapshot-rm') {
410
+ await api(`/sandboxes/snapshots/${encodeURIComponent(necesita())}`, { method: 'DELETE' });
411
+ if (json)
412
+ return console.log(JSON.stringify({ deleted: true }));
413
+ return console.log(green(`✓ snapshot ${objetivo} deleted`));
414
+ }
327
415
  if (accion === 'snapshots') {
328
416
  const r = await api(`/sandboxes/vms/${encodeURIComponent(necesita())}/snapshots`);
329
417
  const l = r.snapshots || [];
@@ -425,6 +513,58 @@ async function seguirOrden(vmId, ruta, cuerpo, json, cmd) {
425
513
  cuerpo = undefined;
426
514
  }
427
515
  }
516
+ /**
517
+ * `vm run` (hueco 15, como `boat run`): crear → subir la carpeta → ejecutar en directo → coste → borrar. La VM se borra
518
+ * SIEMPRE al acabar (también si la orden falla o se corta con Ctrl-C), salvo --keep; si no se pudo borrar, se dice cómo.
519
+ */
520
+ async function correrDePuntaAPunta(a, json) {
521
+ const args = a.passthrough ?? [];
522
+ if (!args.length)
523
+ throw new Error(USO_VM);
524
+ const { DIR_DE_RUN, nombreDeRun, ordenDeShell } = await import('../vm-run');
525
+ const body = { name: a.flags.name ? String(a.flags.name) : nombreDeRun(new Date(), Math.random().toString(36).slice(2)) };
526
+ if (a.flags.from)
527
+ body.fromSnapshot = String(a.flags.from);
528
+ if (a.flags.size)
529
+ body.size = String(a.flags.size);
530
+ const creada = (await api('/sandboxes/vms', { method: 'POST', body })).vm;
531
+ if (!creada || creada.status !== 'running')
532
+ throw new Error(`the VM did not start: ${creada?.statusReason ?? creada?.status ?? 'no answer'}`);
533
+ const id = String(creada.id);
534
+ const borrar = async () => {
535
+ if (a.flags.keep)
536
+ return console.error(`kept: koigrid sandboxes vm rm ${creada.name}`);
537
+ try {
538
+ await api(`/sandboxes/vms/${encodeURIComponent(id)}`, { method: 'DELETE' });
539
+ if (!json)
540
+ console.error(`✓ VM ${creada.name} deleted`);
541
+ }
542
+ catch (e) {
543
+ console.error(`could not delete the VM (${e.message}); delete it with: koigrid sandboxes vm rm ${creada.name}`);
544
+ }
545
+ };
546
+ const alCortar = () => { void borrar().finally(() => process.exit(130)); };
547
+ process.once('SIGINT', alCortar);
548
+ try {
549
+ if (!json)
550
+ console.error(`✓ VM ${creada.name} (${creada.size}) running`);
551
+ if (a.flags.dir) {
552
+ const { execFileSync } = await import('node:child_process');
553
+ const tgz = execFileSync('tar', ['-czf', '-', '--exclude=node_modules', '--exclude=.git', '-C', String(a.flags.dir), '.'], { maxBuffer: 6 * 1024 ** 3 });
554
+ const r = await subirGrande(id, tgz, DIR_DE_RUN, true);
555
+ if (!json)
556
+ console.error(`✓ ${a.flags.dir} → ${DIR_DE_RUN} (${r.uploadedBytes} bytes packed)`);
557
+ }
558
+ await seguirOrden(id, `/sandboxes/vms/${encodeURIComponent(id)}/exec`, { command: ordenDeShell(args), cwd: a.flags.dir ? DIR_DE_RUN : '/root', stream: true }, json);
559
+ const u = (await api(`/sandboxes/vms/${encodeURIComponent(id)}/usage?days=1`)).usage;
560
+ if (u && !json)
561
+ console.error(`cost: $${u.total?.costUsd ?? 0} (${Math.round(u.total?.seconds ?? 0)} s at $${u.pricePerHourUsd}/h)${u.billed ? '' : ' — measured, not charged'}`);
562
+ }
563
+ finally {
564
+ process.off('SIGINT', alCortar);
565
+ await borrar();
566
+ }
567
+ }
428
568
  // koigrid sandboxes vm files — ficheros de una VM (ficha VM-FICHEROS, lib/api/vm-ficheros.ts).
429
569
  async function ficheros(a, json) {
430
570
  const sub = a.positionals[1] || 'ls';
package/dist/manifest.js CHANGED
@@ -50,7 +50,7 @@ export const CLI_COMMANDS = [
50
50
  { name: 'analytics', product: 'analytics', summary: 'Privacy-first web analytics (no cookies)', subs: ['sites', 'create', 'stats', 'rm'], endpoints: ['analytics/sites', 'analytics/sites/[id]', 'analytics/sites/[id]/stats'] },
51
51
  { name: 'errors', aliases: ['error'], product: 'errors', summary: 'Error tracking (capture exceptions, group by fingerprint)', subs: ['ls', 'token', 'resolve', 'reopen', 'rm'], endpoints: ['errors', 'errors/groups/[id]'] },
52
52
  { name: 'speed', aliases: ['vitals'], product: 'speed-insights', summary: 'Speed Insights (Core Web Vitals: LCP/CLS/FCP/TTFB)', subs: ['ls'], endpoints: ['speed-insights', 'speed-insights/[id]'] },
53
- { name: 'sandboxes', aliases: ['sandbox', 'sb'], product: 'sandboxes', summary: 'Ephemeral runs (image+command once) and persistent agent VMs (sandboxes vm …: pause with memory, fork, exec, ssh, environment, VM-scoped tokens)', subs: ['run', 'ls', 'get', 'vm'], endpoints: ['sandboxes', 'sandboxes/[id]', 'sandboxes/vms', 'sandboxes/vms/[id]', 'sandboxes/vms/[id]/exec', 'sandboxes/vms/[id]/pause', 'sandboxes/vms/[id]/resume', 'sandboxes/vms/[id]/stop', 'sandboxes/vms/[id]/start', 'sandboxes/vms/[id]/fork', 'sandboxes/vms/[id]/ssh-keys', 'sandboxes/vms/[id]/environment', 'sandboxes/vms/[id]/tokens', 'sandboxes/vms/[id]/usage', 'sandboxes/vms/limits', 'sandboxes/vms/[id]/snapshots', 'sandboxes/vms/[id]/commands', 'sandboxes/vms/[id]/commands/[cmd]', 'sandboxes/vms/[id]/commands/[cmd]/stream', 'sandboxes/vms/[id]/files', 'sandboxes/vms/[id]/files/content', 'sandboxes/vms/[id]/files/move', 'sandboxes/vms/[id]/files/mkdir', 'sandboxes/vms/[id]/files/chmod', 'sandboxes/vms/[id]/files/replace', 'sandboxes/vms/[id]/files/upload-url', 'sandboxes/vms/[id]/files/upload-complete', 'sandboxes/vms/[id]/files/download-url'] },
53
+ { name: 'sandboxes', aliases: ['sandbox', 'sb'], product: 'sandboxes', summary: 'Ephemeral runs (image+command once) and persistent agent VMs (sandboxes vm …: pause with memory, fork, exec, ssh, environment, VM-scoped tokens)', subs: ['run', 'ls', 'get', 'vm'], endpoints: ['sandboxes', 'sandboxes/[id]', 'sandboxes/vms', 'sandboxes/vms/[id]', 'sandboxes/vms/[id]/exec', 'sandboxes/vms/[id]/pause', 'sandboxes/vms/[id]/resume', 'sandboxes/vms/[id]/stop', 'sandboxes/vms/[id]/start', 'sandboxes/vms/[id]/fork', 'sandboxes/vms/[id]/ssh-keys', 'sandboxes/vms/[id]/environment', 'sandboxes/vms/[id]/tokens', 'sandboxes/vms/[id]/usage', 'sandboxes/vms/[id]/history', 'sandboxes/vms/[id]/processes', 'sandboxes/vms/limits', 'sandboxes/vms/[id]/snapshots', 'sandboxes/snapshots', 'sandboxes/snapshots/[id]', 'sandboxes/snapshots/[id]/files', 'sandboxes/snapshots/[id]/shares', 'sandboxes/snapshots/[id]/shares/[shareId]', 'sandboxes/snapshots/[id]/files/content', 'sandboxes/vms/[id]/commands', 'sandboxes/vms/[id]/commands/[cmd]', 'sandboxes/vms/[id]/commands/[cmd]/stream', 'sandboxes/vms/[id]/files', 'sandboxes/vms/[id]/files/content', 'sandboxes/vms/[id]/files/move', 'sandboxes/vms/[id]/files/mkdir', 'sandboxes/vms/[id]/files/chmod', 'sandboxes/vms/[id]/files/replace', 'sandboxes/vms/[id]/files/upload-url', 'sandboxes/vms/[id]/files/upload-complete', 'sandboxes/vms/[id]/files/download-url'] },
54
54
  { name: 'images', aliases: ['image', 'img'], product: 'images', summary: 'Image optimization (resize/re-encode on the fly, allowlisted)', subs: ['config', 'allow', 'usage'], endpoints: ['images/config', 'images/usage'] },
55
55
  { name: 'waf', aliases: ['firewall'], product: 'firewall', summary: 'Firewall/WAF — allow/block rules (IP/country/path…) + evaluate', subs: ['rules', 'add', 'rm', 'evaluate'], endpoints: ['waf/rules', 'waf/rules/[id]', 'waf/evaluate'] },
56
56
  { name: 'webhooks', aliases: ['webhook', 'hooks'], product: 'webhooks', summary: 'Outbound webhooks — platform events → your URL, signed + retried', subs: ['ls', 'create', 'enable', 'disable', 'deliveries', 'rm'], endpoints: ['webhooks', 'webhooks/[id]', 'webhooks/[id]/deliveries'] },
package/dist/vm-run.js ADDED
@@ -0,0 +1,13 @@
1
+ // cli/src/vm-run.ts — lo puro de `koigrid sandboxes vm run` (hueco 15 de docs/design/VMS.md §6-bis, ficha 3153e09c):
2
+ // una orden de punta a punta en una VM de usar y tirar, como `boat run`. Aquí sólo lo que se prueba sin red.
3
+ /** Une los argumentos tras `--` en UNA orden de shell, citando cada uno (POSIX): `ls "a b"` llega como dos argumentos. */
4
+ export function ordenDeShell(args) {
5
+ return args.map((a) => (/^[A-Za-z0-9_./:=@%+,-]+$/.test(a) ? a : `'${a.replace(/'/g, `'\\''`)}'`)).join(' ');
6
+ }
7
+ /** Nombre de la VM de usar y tirar: reconocible en la lista y sin chocar con otra del mismo minuto. */
8
+ export function nombreDeRun(ahora, azar) {
9
+ const t = ahora.toISOString().slice(0, 19).replace(/[-:]/g, '').replace('T', '-');
10
+ return `run-${t}-${azar.toLowerCase().replace(/[^a-z0-9]/g, '').slice(0, 4)}`;
11
+ }
12
+ /** Donde se deja la carpeta subida y desde donde corre la orden. */
13
+ export const DIR_DE_RUN = '/root/work';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "koigrid",
3
- "version": "0.11.0",
3
+ "version": "0.12.0",
4
4
  "description": "koigrid CLI — deploy apps, databases, redis, storage and more from your terminal (or your AI agent).",
5
5
  "bin": {
6
6
  "koigrid": "dist/index.js"