koigrid 0.14.0 → 0.16.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,19 @@ All notable changes to the koigrid CLI are documented here. Format: [Keep a Chan
4
4
 
5
5
  ## [Unreleased]
6
6
 
7
+ ## [0.16.0] — 2026-11-27
8
+
9
+ ### Added
10
+
11
+ - `koigrid redis maintenance <id> [defer [<ISO date>]]`: what is scheduled on a cache (`pendingMaintenance`) and defer the reboot of the machine of a single-node cache, up to 14 days from the notice, like `koigrid db maintenance <id> defer`.
12
+
13
+ ## [0.15.0] — 2026-11-27
14
+
15
+ ### Added
16
+
17
+ - `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).
18
+ - `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.
19
+
7
20
  ## [0.14.0] — 2026-11-27
8
21
 
9
22
  ### 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));
@@ -84,6 +84,30 @@ export async function redis(a) {
84
84
  need();
85
85
  return network('redis', 'redis', id, a, json);
86
86
  }
87
+ case 'maintenance': {
88
+ // Lo programado en la caché (pendingMaintenance de GET /redis/:id); `defer` aplaza el reinicio de la máquina de una
89
+ // caché de un solo nodo (ficha 4b2fd746), como `koigrid db maintenance <id> defer`.
90
+ need();
91
+ if (a.positionals[1] === 'defer') {
92
+ const until = a.positionals[2];
93
+ const r = await api(`/redis/${encodeURIComponent(id)}/maintenance/defer`, { method: 'POST', body: { action: 'host_reboot', ...(until ? { until } : {}) } });
94
+ if (json)
95
+ return console.log(JSON.stringify(r, null, 2));
96
+ return console.log(green(`✓ reinicio de la máquina aplazado: no antes de ${r.deferredUntil}`));
97
+ }
98
+ const r = await api(`/redis/${encodeURIComponent(id)}`);
99
+ const pend = (r.pendingMaintenance ?? []);
100
+ if (json)
101
+ return console.log(JSON.stringify({ pendingMaintenance: pend }, null, 2));
102
+ if (!pend.length)
103
+ return console.log('no pending maintenance');
104
+ for (const m of pend) {
105
+ console.log(`• ${m.action}: ${m.description}`);
106
+ console.log(` impact: ${m.impact}`);
107
+ console.log(` happens at ${m.autoAppliesAt}${m.window ? ` (${m.window})` : ''}${m.action === 'host_reboot' ? ` · defer: koigrid redis maintenance ${id} defer [<ISO date>]` : ''}`);
108
+ }
109
+ return;
110
+ }
87
111
  case 'password': {
88
112
  // Rotar la contraseña sin corte (ficha dd6ffe39): `rotate` añade una nueva (valen las dos), `retire` quita la
89
113
  // anterior cuando las apps ya la usan (se niega si alguien se quedaría fuera, salvo --force). Sin paso, el estado.
@@ -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…>
@@ -76,6 +85,12 @@ const USO_VM = `usage: koigrid sandboxes vm <action> …
76
85
  ports public|private <vm> <port> make it public or private · ports rm <vm> <port>: stop exposing it
77
86
  ports url <vm> <port> [--expires S] a signed URL for that port (default 1 h, max 7 days), shown once
78
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)
79
94
  ssh <vm> [-- command] SSH into the VM (wakes it if paused); needs your key on it (ssh-key set)
80
95
  ssh-key set <vm> [--key FILE.pub]… replace the keys allowed in (default ~/.ssh/id_ed25519.pub) · ssh-key ls <vm>
81
96
  ssh-config <vm> [--write] the ~/.ssh/config block for ssh, VS Code and Cursor (--write adds it, and the VM host key)
@@ -343,6 +358,55 @@ async function vm(a, json) {
343
358
  return console.log(JSON.stringify(r, null, 2));
344
359
  return console.log(green(`✓ ${vmNombre} is ${r.vm?.visibility}`) + (accion === 'unshare' ? ` · ${(body.sshPublicKeys || []).length} SSH key(s) kept` : ''));
345
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
+ }
346
410
  // ── SSH (ficha daa6b24a): por la puerta de koigrid, cifrado de punta a punta con la VM ──
347
411
  if (accion === 'ssh-key') {
348
412
  const sub = objetivo;
package/dist/manifest.js CHANGED
@@ -24,7 +24,7 @@ export const CLI_COMMANDS = [
24
24
  endpoints: ['apps', 'apps/[id]', 'apps/[id]/deployments', 'apps/[id]/source-upload', 'apps/[id]/logs', 'apps/[id]/http', 'apps/[id]/scale', 'apps/[id]/resources', 'apps/[id]/autoscale', 'apps/[id]/scale-out', 'apps/[id]/env', 'apps/[id]/env/verify', 'apps/[id]/domains', 'apps/[id]/domains/verify', 'apps/[id]/volumes', 'apps/[id]/volumes/[volId]', 'apps/[id]/volumes/[volId]/backups', 'apps/[id]/volumes/[volId]/backups/[backupId]/restore', 'apps/[id]/cdn', 'apps/[id]/cache', 'apps/[id]/cache/purge', 'apps/[id]/protection', 'apps/[id]/protection/evaluate', 'apps/[id]/retention', 'apps/[id]/github', 'github/repos', 'apps/[id]/deploy-hooks', 'apps/[id]/deploy-hooks/[hookId]', 'apps/[id]/rollback', 'apps/[id]/pause', 'apps/[id]/resume', 'apps/[id]/restore', 'apps/[id]/migrate', 'apps/[id]/previews', 'apps/[id]/rules', 'apps/[id]/rules/[ruleId]', 'apps/[id]/registry', 'apps/[id]/loadtest'],
25
25
  },
26
26
  { name: 'db', aliases: ['databases', 'database'], product: 'databases', summary: 'Managed Postgres (HA) — incl. SQL console (db query/tables) + branching (db branch) + managed restore (db restore-dump)', subs: ['ls', 'info', 'create', 'rm', 'rename', 'pause', 'resume', 'retention', 'weekly', 'monthly', 'url', 'connect', 'metrics', 'top-queries', 'slots', 'logs', 'backups', 'restore', 'restore-dump', 'fix-ownership', 'analyze', 'import', 'restore-status', 'ext', 'replicas', 'dr-copy', 'network', 'pub', 'query', 'tables', 'branch', 'roles', 'params', 'pooler', 'rotation', 'patching', 'sync', 'slot-cap', 'resize', 'apply-config', 'maintenance', 'subs', 'data', 'rpc'], endpoints: ['databases', 'databases/[id]', 'databases/[id]/pause', 'databases/[id]/resume', 'databases/[id]/connection', 'databases/[id]/backups', 'databases/[id]/restore', 'databases/[id]/restore-dump', 'databases/[id]/restore-dump/upload-url', 'databases/[id]/restore-dump/[jobId]', 'databases/[id]/fix-ownership', 'databases/[id]/analyze', 'databases/[id]/metrics', 'databases/[id]/queries', 'databases/[id]/replication-slots', 'databases/[id]/logs', 'databases/[id]/extensions', 'databases/[id]/replicas', 'databases/[id]/dr-copy', 'databases/[id]/network', 'databases/[id]/publications', 'databases/[id]/subscriptions', 'databases/[id]/subscriptions/preflight', 'databases/[id]/subscriptions/verify', 'databases/[id]/subscriptions/verify/[verificationId]', 'databases/[id]/subscriptions/sync-sequences', 'databases/[id]/apply-config', 'databases/[id]/maintenance/apply', 'databases/[id]/maintenance/defer', 'databases/[id]/query', 'databases/[id]/branches', 'databases/[id]/branches/[branchId]', 'databases/[id]/branches/[branchId]/reset', 'databases/[id]/roles', 'databases/[id]/roles/[roleName]', 'databases/[id]/parameters', 'databases/[id]/pooler', 'databases/[id]/rotation', 'databases/[id]/rotation/rotate', 'databases/[id]/rotation/migrate', 'databases/[id]/data/[table]', 'databases/[id]/rpc/[fn]'] },
27
- { name: 'redis', aliases: ['cache'], product: 'cache', summary: 'Managed Redis (HA)', subs: ['apply-config', 'ls', 'create', 'rm', 'rename', 'resize', 'url', 'connect', 'metrics', 'backups', 'restore', 'dr-copy', 'network', 'password'], endpoints: ['redis/[id]/apply-config', 'redis/[id]/password', 'redis', 'redis/[id]', 'redis/[id]/connection', 'redis/[id]/backups', 'redis/[id]/restore', 'redis/[id]/metrics', 'redis/[id]/dr-copy', 'redis/[id]/network'] },
27
+ { name: 'redis', aliases: ['cache'], product: 'cache', summary: 'Managed Redis (HA)', subs: ['apply-config', 'ls', 'create', 'rm', 'rename', 'resize', 'url', 'connect', 'metrics', 'backups', 'restore', 'dr-copy', 'network', 'password', 'maintenance'], endpoints: ['redis/[id]/apply-config', 'redis/[id]/maintenance/defer', 'redis/[id]/password', 'redis', 'redis/[id]', 'redis/[id]/connection', 'redis/[id]/backups', 'redis/[id]/restore', 'redis/[id]/metrics', 'redis/[id]/dr-copy', 'redis/[id]/network'] },
28
28
  { name: 'storage', aliases: ['buckets'], product: 'storage', summary: 'Object storage (S3): buckets, object browser (list/upload/download/delete), versioning + restore, public read (storage public)', subs: ['ls', 'create', 'rm', 'keys', 'key', 'key-scope', 'versions', 'restore', 'objects', 'upload-url', 'download-url', 'object-rm', 'replication', 'public'], endpoints: ['buckets', 'buckets/[id]', 'buckets/[id]/versions', 'buckets/[id]/objects', 'buckets/[id]/objects/upload-url', 'buckets/[id]/objects/download-url', 'buckets/[id]/public', 'storage/keys', 'storage/keys/[id]', 'storage/keys/[id]/scope'] },
29
29
  { name: 'jobs', aliases: ['cron'], product: 'jobs', summary: 'Cron / scheduled jobs', subs: ['ls', 'create', 'update', 'rm', 'trigger', 'runs'], endpoints: ['jobs', 'jobs/[id]', 'jobs/[id]/runs', 'jobs/[id]/trigger'] },
30
30
  { name: 'events', aliases: ['activity'], product: 'observability', summary: 'Events and metrics', subs: ['ls', 'metrics'], endpoints: ['events', 'metrics'] },
@@ -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]/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'] },
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.14.0",
3
+ "version": "0.16.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"