koigrid 0.13.0 → 0.15.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,6 +4,20 @@ All notable changes to the koigrid CLI are documented here. Format: [Keep a Chan
4
4
 
5
5
  ## [Unreleased]
6
6
 
7
+ ## [0.15.0] — 2026-11-27
8
+
9
+ ### Added
10
+
11
+ - `koigrid db maintenance <id> apply ca_rotation`: present the certificate signed by the database's new internal CA now instead of waiting for its maintenance window (applied live, no restart).
12
+ - `koigrid sandboxes vm ai keys|set|rm|block|unblock|usage`: AI credentials for the project's VMs. A VM never sees the real key: it gets a placeholder and `ANTHROPIC_BASE_URL` / `OPENAI_BASE_URL` / `OPENROUTER_BASE_URL` pointing to the AI proxy of its host. `ai set <provider>` reads the key from stdin or `--key-file`, never from an argument. `ai block <vm>` stops the AI of one VM at once; `ai usage <vm>` shows its requests and tokens per day, provider and model.
13
+
14
+ ## [0.14.0] — 2026-11-27
15
+
16
+ ### Added
17
+
18
+ - `koigrid sandboxes vm retention [standard|zero]`: what koigrid keeps of your VMs; `zero` stops recording the command history (org owner/admin).
19
+ - `koigrid sandboxes vm share <vm>` and `koigrid sandboxes vm unshare <vm> [--key FILE.pub | --no-keys]`: share a VM with the organization or make it private to its creator (other members see it but cannot use it; every SSH key except yours is removed).
20
+
7
21
  ## [0.13.0] — 2026-11-27
8
22
 
9
23
  ### Added
@@ -850,7 +850,7 @@ export async function db(a) {
850
850
  if (act === 'apply') {
851
851
  const action = a.positionals[2];
852
852
  if (!action)
853
- throw new Error('usage: koigrid db maintenance <id> apply <resize|replication_verify_ca|minor_upgrade|dcs_tls>');
853
+ throw new Error('usage: koigrid db maintenance <id> apply <resize|replication_verify_ca|minor_upgrade|dcs_tls|ca_rotation>');
854
854
  const r = await api(`/databases/${encodeURIComponent(id)}/maintenance/apply`, { method: 'POST', body: { action } });
855
855
  if (json)
856
856
  return console.log(JSON.stringify(r, null, 2));
@@ -50,6 +50,15 @@ export async function sandboxes(a) {
50
50
  if (s.logs)
51
51
  console.log(s.logs);
52
52
  }
53
+ /** Todo stdin como texto (para una clave que no debe ir en un argumento). Sin stdin redirigido, vacío. */
54
+ async function leerStdin() {
55
+ if (process.stdin.isTTY)
56
+ return '';
57
+ const trozos = [];
58
+ for await (const t of process.stdin)
59
+ trozos.push(t);
60
+ return Buffer.concat(trozos).toString('utf8');
61
+ }
53
62
  const USO_VM = `usage: koigrid sandboxes vm <action> …
54
63
  ls list VMs
55
64
  run [--dir LOCAL] [--size S] [--from SNAPSHOT] [--keep] -- <command…>
@@ -62,6 +71,11 @@ const USO_VM = `usage: koigrid sandboxes vm <action> …
62
71
  env set <vm> [--env KEY=VALUE]… [--repo owner/repo]… [--environment FILE.json] [--safe-for-third-parties]
63
72
  replace it (values may use \${{ shared.KEY }}, \${{ db.<name>.DATABASE_URL }}…)
64
73
  token <vm> [--expires SECONDS] [--read-only] an API token that only works on this VM, to hand to someone else
74
+ retention [standard|zero] what koigrid keeps of your VMs; zero stops recording the command history (owner/admin)
75
+ share <vm> share it with the organization: every member can use it (the default)
76
+ unshare <vm> [--key FILE.pub | --no-keys]
77
+ make it private: other members see it but cannot use it; every SSH key except
78
+ yours (~/.ssh/id_*.pub or --key) is removed from the VM. Creator or org owner/admin
65
79
  usage <vm> [--days N] what it has used: seconds running, GB·h and cost, per day (≤90 days)
66
80
  history <vm> [--limit N] [--before ISO] commands run in it (direct and background), newest first, 90 days
67
81
  ps <vm> processes running now, highest CPU first
@@ -71,6 +85,12 @@ const USO_VM = `usage: koigrid sandboxes vm <action> …
71
85
  ports public|private <vm> <port> make it public or private · ports rm <vm> <port>: stop exposing it
72
86
  ports url <vm> <port> [--expires S] a signed URL for that port (default 1 h, max 7 days), shown once
73
87
  ports urls <vm> <port> its signed URLs · ports revoke <vm> <port> <url-id>: revoke one
88
+ ai keys AI credentials of the project's VMs (provider and last 4 characters, never the key)
89
+ ai set <provider> [--key-file F] set or rotate one (anthropic | openai | openrouter); the key comes from stdin or
90
+ the file, never as an argument. The VM only gets a placeholder and a proxy URL
91
+ ai rm <provider> remove it (cuts it at once on running VMs)
92
+ ai block|unblock <vm> block or unblock the AI of one VM (403 from the proxy, even while running)
93
+ ai usage <vm> [--days N] AI requests, errors and tokens of the VM per day, provider and model (≤90 days)
74
94
  ssh <vm> [-- command] SSH into the VM (wakes it if paused); needs your key on it (ssh-key set)
75
95
  ssh-key set <vm> [--key FILE.pub]… replace the keys allowed in (default ~/.ssh/id_ed25519.pub) · ssh-key ls <vm>
76
96
  ssh-config <vm> [--write] the ~/.ssh/config block for ssh, VS Code and Cursor (--write adds it, and the VM host key)
@@ -306,6 +326,87 @@ async function vm(a, json) {
306
326
  }
307
327
  return console.log(JSON.stringify(r));
308
328
  }
329
+ // ── Retención de datos de las VMs de la organización (ficha 536d1044) ──
330
+ if (accion === 'retention') {
331
+ const r = objetivo ? await api('/sandboxes/data-retention', { method: 'PATCH', body: { mode: objetivo } }) : await api('/sandboxes/data-retention');
332
+ if (json)
333
+ return console.log(JSON.stringify(r, null, 2));
334
+ const t = r.retention;
335
+ return console.log(`${green(t.mode)} · command history: ${t.commandHistoryDays ? `${t.commandHistoryDays} days` : 'not recorded'} · always kept: billing sessions, audit events`);
336
+ }
337
+ // ── Compartir con la organización o hacerla privada (ficha a535a786) ──
338
+ if (accion === 'share' || accion === 'unshare') {
339
+ const vmNombre = objetivo;
340
+ if (!vmNombre)
341
+ throw new Error(USO_VM);
342
+ const body = { visibility: accion === 'share' ? 'shared' : 'private' };
343
+ if (accion === 'unshare') {
344
+ let propias = [];
345
+ if (!a.flags['no-keys']) {
346
+ try {
347
+ propias = clavesLocales(a.flags.key);
348
+ }
349
+ catch (e) {
350
+ if (a.flags.key)
351
+ throw e;
352
+ }
353
+ }
354
+ body.sshPublicKeys = propias;
355
+ }
356
+ const r = await api(`/sandboxes/vms/${encodeURIComponent(vmNombre)}/visibility`, { method: 'PUT', body });
357
+ if (json)
358
+ return console.log(JSON.stringify(r, null, 2));
359
+ return console.log(green(`✓ ${vmNombre} is ${r.vm?.visibility}`) + (accion === 'unshare' ? ` · ${(body.sshPublicKeys || []).length} SSH key(s) kept` : ''));
360
+ }
361
+ // ── Credenciales de IA (ficha 8c053e74, hueco 17): la VM recibe un relleno; el proxy de su host pone la clave real ──
362
+ if (accion === 'ai') {
363
+ const sub = objetivo;
364
+ const arg2 = a.positionals[2];
365
+ let r;
366
+ if (sub === 'keys')
367
+ r = await api('/sandboxes/vms/ai-credentials');
368
+ else if (sub === 'set') {
369
+ if (!arg2)
370
+ throw new Error(USO_VM);
371
+ // ⛔ nunca como argumento: quedaría en el historial del shell y en el `ps` de la máquina
372
+ const key = (a.flags['key-file'] ? readFileSync(String(a.flags['key-file']).replace(/^~(?=\/)/, homedir()), 'utf8') : await leerStdin()).trim();
373
+ if (!key)
374
+ throw new Error('the key comes from stdin or --key-file (e.g. koigrid sandboxes vm ai set anthropic < key.txt)');
375
+ r = await api('/sandboxes/vms/ai-credentials', { method: 'PUT', body: { provider: arg2, key } });
376
+ }
377
+ else if (sub === 'rm') {
378
+ if (!arg2)
379
+ throw new Error(USO_VM);
380
+ r = await api(`/sandboxes/vms/ai-credentials/${encodeURIComponent(arg2)}`, { method: 'DELETE' });
381
+ }
382
+ else if (sub === 'block' || sub === 'unblock') {
383
+ if (!arg2)
384
+ throw new Error(USO_VM);
385
+ r = await api(`/sandboxes/vms/${encodeURIComponent(arg2)}/ai-access`, { method: 'PUT', body: { blocked: sub === 'block' } });
386
+ }
387
+ else if (sub === 'usage') {
388
+ if (!arg2)
389
+ throw new Error(USO_VM);
390
+ r = await api(`/sandboxes/vms/${encodeURIComponent(arg2)}/ai-usage${a.flags.days ? `?days=${encodeURIComponent(String(a.flags.days))}` : ''}`);
391
+ }
392
+ else
393
+ throw new Error(USO_VM);
394
+ if (json)
395
+ return console.log(JSON.stringify(r, null, 2));
396
+ if (sub === 'keys') {
397
+ if (!r.credentials.length)
398
+ return console.log(`no AI credentials: koigrid sandboxes vm ai set <${r.providers.map((p) => p.id).join('|')}> < key.txt`);
399
+ for (const c of r.credentials)
400
+ console.log(`${c.provider} …${c.keyHint} ${c.updatedAt}`);
401
+ return;
402
+ }
403
+ if (sub === 'usage') {
404
+ for (const u of r.usage)
405
+ console.log(`${u.day} ${u.provider} ${u.model || '-'} ${u.requests} req ${u.errors} err in ${u.inputTokens} out ${u.outputTokens} cache ${u.cacheReadTokens}/${u.cacheWriteTokens}`);
406
+ return console.log(`total ${r.totals.requests} req ${r.totals.errors} err in ${r.totals.inputTokens} out ${r.totals.outputTokens}${r.blocked ? '\t(AI blocked)' : ''}`);
407
+ }
408
+ return console.log(JSON.stringify(r));
409
+ }
309
410
  // ── SSH (ficha daa6b24a): por la puerta de koigrid, cifrado de punta a punta con la VM ──
310
411
  if (accion === 'ssh-key') {
311
412
  const sub = objetivo;
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]/ports', 'sandboxes/vms/[id]/ports/[port]', 'sandboxes/vms/[id]/ports/[port]/urls', 'sandboxes/vms/[id]/ports/[port]/urls/[urlId]', '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'] },
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]/visibility', 'sandboxes/data-retention', 'sandboxes/vms/[id]/environment', 'sandboxes/vms/[id]/tokens', 'sandboxes/vms/[id]/ports', 'sandboxes/vms/[id]/ports/[port]', 'sandboxes/vms/[id]/ports/[port]/urls', 'sandboxes/vms/[id]/ports/[port]/urls/[urlId]', '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', 'sandboxes/vms/ai-credentials', 'sandboxes/vms/ai-credentials/[provider]', 'sandboxes/vms/[id]/ai-access', 'sandboxes/vms/[id]/ai-usage'] },
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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "koigrid",
3
- "version": "0.13.0",
3
+ "version": "0.15.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"