koigrid 0.1.0 → 0.4.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 ADDED
@@ -0,0 +1,39 @@
1
+ # Changelog
2
+
3
+ All notable changes to the koigrid CLI are documented here. Format: [Keep a Changelog](https://keepachangelog.com). Versions follow [SemVer](https://semver.org).
4
+
5
+ ## [0.4.0] — 2026-07-05
6
+
7
+ ### Added
8
+ - **`--health-path`** on `apps deploy` (e.g. `--health-path /api/health`): koigrid probes that path after each
9
+ deploy. A 5xx / no-response means the container runs but the app is broken (e.g. can't reach its DB) — koigrid
10
+ emits `app.unhealthy` instead of calling it healthy. Closes the "running but broken" blind spot.
11
+
12
+ ## [0.3.0] — 2026-07-05
13
+
14
+ ### Added
15
+ - **HTTP cron jobs**: `koigrid jobs create <name> --schedule "…" --url <url> [--method POST] [--header "K: V"]`.
16
+ koigrid hits the URL on schedule — most crons just call an endpoint with a secret, so no container needed.
17
+ Headers are stored encrypted (put your `CRON_SECRET` there). The EventBridge → HTTP-target equivalent.
18
+
19
+ ## [0.2.0] — 2026-07-04
20
+
21
+ ### Added
22
+ - **`koigrid apps deploy <name> --dir <path>`** — deploy from a **local directory**, no git or Docker required.
23
+ The directory is packaged (excluding `node_modules`, `.git`, `.next`, `dist`, …) and uploaded straight to
24
+ koigrid via a presigned URL, then built on the runner (Dockerfile or nixpacks). Ideal for migrating a private
25
+ app: point at the folder and ship.
26
+ - **`koigrid apps deploy <name> --repo <url> --repo-token <token>`** — deploy a **private git repo** by passing
27
+ a token/deploy-key, without installing the GitHub App in a browser (works for agents/CI). The token is stored
28
+ encrypted at rest and redacted from build logs.
29
+
30
+ ### Notes
31
+ - Both close the #1 adoption blocker found while dogfooding a real app (VicoHR) onto koigrid: a private codebase
32
+ could not be deployed without wiring GitHub OAuth or having Docker locally.
33
+
34
+ ## [0.1.0] — 2026-07-03
35
+
36
+ ### Added
37
+ - Initial release. Commands: `login`, `logout`, `whoami`, `usage`, `apps`, `db`, `redis`, `storage` (buckets),
38
+ `jobs`, `events`, `alarms`, `email`. Designed for AI agents: `--json` on every command, `koigrid help --json`
39
+ to introspect the full command tree, auth via `--token` / `KOIGRID_TOKEN`.
@@ -1,3 +1,4 @@
1
+ import { execFileSync } from 'node:child_process';
1
2
  import { api } from '../api.js';
2
3
  import { output, green } from '../output.js';
3
4
  export async function apps(a) {
@@ -14,10 +15,29 @@ export async function apps(a) {
14
15
  }
15
16
  case 'deploy': {
16
17
  const name = a.positionals[0], image = a.flags.image, repo = a.flags.repo;
17
- if (!name || (!image && !repo))
18
- throw new Error('usage: koigrid apps deploy <name> --image <img>|--repo <git-url> [--port N]');
18
+ const dir = a.flags.dir; // deploy desde un directorio LOCAL (código privado, sin git/Docker)
19
+ const repoToken = a.flags['repo-token']; // token/deploy-key para repos privados
20
+ const healthPath = a.flags['health-path']; // ruta de salud (/api/health) → koigrid detecta apps rotas
21
+ const hc = healthPath ? { healthCheckPath: healthPath } : {};
22
+ if (!name || (!image && !repo && !dir))
23
+ throw new Error('usage: koigrid apps deploy <name> --dir <path>|--image <img>|--repo <git-url> [--repo-token <t>] [--port N]');
19
24
  const port = a.flags.port ? Number(a.flags.port) : 3000;
20
- const app = await api('/apps', { method: 'POST', body: repo ? { name, sourceType: 'git', repo, port } : { name, sourceType: 'image', image, port } });
25
+ // deploy --dir: empaqueta el directorio (excluye lo pesado/irrelevante) → subida presignada a koigrid →
26
+ // el runner lo construye igual que un repo. No requiere git ni Docker local.
27
+ if (dir) {
28
+ const app = await api('/apps', { method: 'POST', body: { name, port, ...hc } });
29
+ const aid = app.app?.id || app.id;
30
+ const up = await api(`/apps/${encodeURIComponent(aid)}/source-upload`, { method: 'POST', body: {} });
31
+ const { uploadUrl, archiveKey } = up.upload;
32
+ const excludes = ['node_modules', '.git', '.next', 'dist', 'build', '.vercel', '.turbo', 'coverage', '.DS_Store'];
33
+ const tar = execFileSync('tar', ['-czf', '-', ...excludes.map((e) => `--exclude=${e}`), '-C', dir, '.'], { maxBuffer: 1024 * 1024 * 1024 });
34
+ const put = await fetch(uploadUrl, { method: 'PUT', headers: { 'content-type': 'application/gzip' }, body: tar });
35
+ if (!put.ok)
36
+ throw new Error(`source upload failed (HTTP ${put.status})`);
37
+ await api(`/apps/${encodeURIComponent(aid)}/deployments`, { method: 'POST', body: { sourceType: 'archive', archiveKey } });
38
+ return json ? console.log(JSON.stringify({ id: aid, status: 'queued', source: 'dir' }, null, 2)) : console.log(green(`✓ Deploying "${name}" from ${dir}…`));
39
+ }
40
+ const app = await api('/apps', { method: 'POST', body: repo ? { name, sourceType: 'git', repo, port, ...(repoToken ? { repoToken } : {}), ...hc } : { name, sourceType: 'image', image, port, ...hc } });
21
41
  const aid = app.app?.id || app.id;
22
42
  await api(`/apps/${encodeURIComponent(aid)}/deployments`, { method: 'POST', body: {} });
23
43
  return json ? console.log(JSON.stringify({ id: aid, status: 'queued' }, null, 2)) : console.log(green(`✓ Deploying "${name}"…`));
@@ -95,19 +115,26 @@ export async function apps(a) {
95
115
  throw new Error('usage: koigrid apps env <id> set KEY=VAL | rm KEY | ls');
96
116
  }
97
117
  case 'domains': {
98
- need(' add <domain> | rm <domain> | ls');
118
+ need(' add <domain> | rm <domain> | ls | verify');
99
119
  const act = a.positionals[1];
120
+ const cols = ['domain', 'status', 'record'];
121
+ const rowsOf = (l) => l.map((x) => (typeof x === 'string' ? { domain: x, status: '', record: '' } : { domain: x.domain, status: x.status ?? '', record: x.record ? `${x.record.type} ${x.record.name} → ${x.record.value}` : '' }));
100
122
  if (!act || act === 'ls') {
101
123
  const r = await api(`/apps/${encodeURIComponent(id)}/domains`);
102
124
  const l = r.domains || r || [];
103
- return output(l, json, { rows: l.map((x) => ({ domain: x.domain || x })), columns: ['domain'] });
125
+ return output(l, json, { rows: rowsOf(l), columns: cols });
126
+ }
127
+ if (act === 'verify') {
128
+ const r = await api(`/apps/${encodeURIComponent(id)}/domains?verify=1`);
129
+ const l = r.domains || r || [];
130
+ return output(l, json, { rows: rowsOf(l), columns: cols });
104
131
  }
105
132
  if (act === 'add') {
106
133
  const d = a.positionals[2];
107
134
  if (!d)
108
135
  throw new Error('need <domain>');
109
136
  const r = await api(`/apps/${encodeURIComponent(id)}/domains`, { method: 'POST', body: { domain: d } });
110
- return console.log(json ? JSON.stringify(r, null, 2) : green(`✓ Added ${d} — set the CNAME shown`));
137
+ return console.log(json ? JSON.stringify(r, null, 2) : green(`✓ Added ${d} — create DNS: ${r.instructions}`));
111
138
  }
112
139
  if (act === 'rm') {
113
140
  const d = a.positionals[2];
@@ -116,7 +143,7 @@ export async function apps(a) {
116
143
  await api(`/apps/${encodeURIComponent(id)}/domains?domain=${encodeURIComponent(d)}`, { method: 'DELETE' });
117
144
  return console.log(green(`✓ Removed ${d}`));
118
145
  }
119
- throw new Error('usage: koigrid apps domains <id> add <domain> | rm <domain> | ls');
146
+ throw new Error('usage: koigrid apps domains <id> add <domain> | rm <domain> | ls | verify');
120
147
  }
121
148
  case 'volumes': {
122
149
  need(' add <name> --size N --mount /path | rm <volId> | ls');
@@ -167,6 +194,20 @@ export async function apps(a) {
167
194
  const r = await api(`/apps/${encodeURIComponent(id)}/github`, { method: 'PUT', body });
168
195
  return console.log(json ? JSON.stringify(r, null, 2) : green(`✓ Connected ${repo}`));
169
196
  }
197
+ case 'resize': {
198
+ need(' [--memory <mb>] [--cpus <n>]');
199
+ if (a.flags.memory === undefined && a.flags.cpus === undefined) {
200
+ const r = await api(`/apps/${encodeURIComponent(id)}/resources`);
201
+ return console.log(json ? JSON.stringify(r, null, 2) : `memory: ${r.resources?.memoryMb}MB · cpus: ${r.resources?.cpus} (plan max: ${r.resources?.planMaxMemoryMb}MB / ${r.resources?.planMaxVcpu} vCPU)`);
202
+ }
203
+ const body = {};
204
+ if (a.flags.memory)
205
+ body.memoryMb = Number(a.flags.memory);
206
+ if (a.flags.cpus)
207
+ body.cpus = Number(a.flags.cpus);
208
+ const r = await api(`/apps/${encodeURIComponent(id)}/resources`, { method: 'PUT', body });
209
+ return console.log(json ? JSON.stringify(r, null, 2) : green(`✓ Resized → ${r.resources?.memoryMb}MB / ${r.resources?.cpus} vCPU${r.resources?.clamped ? ' (clamped to plan max)' : ''}`));
210
+ }
170
211
  default: throw new Error(`unknown: apps ${sub}`);
171
212
  }
172
213
  }
@@ -60,6 +60,57 @@ export async function db(a) {
60
60
  const r = await api(`/databases/${encodeURIComponent(id)}/restore`, { method: 'POST', body });
61
61
  return console.log(json ? JSON.stringify(r, null, 2) : green('✓ Restoring to a new cluster…'));
62
62
  }
63
+ case 'ext':
64
+ case 'extensions': {
65
+ need();
66
+ const name = a.positionals[1];
67
+ if (!name) {
68
+ const r = await api(`/databases/${encodeURIComponent(id)}/extensions`);
69
+ return console.log(json ? JSON.stringify(r, null, 2) : 'allowed: ' + (r.allowed || []).join(', '));
70
+ }
71
+ const r = await api(`/databases/${encodeURIComponent(id)}/extensions`, { method: 'POST', body: { name } });
72
+ return console.log(json ? JSON.stringify(r, null, 2) : green(`✓ Extension ${name} installed`));
73
+ }
74
+ case 'replicas': {
75
+ need();
76
+ const n = a.positionals[1];
77
+ if (n === undefined) {
78
+ const r = await api(`/databases/${encodeURIComponent(id)}/replicas`);
79
+ return console.log(json ? JSON.stringify(r, null, 2) : `replicas: ${r.replicas} / max ${r.maxReplicas}`);
80
+ }
81
+ const r = await api(`/databases/${encodeURIComponent(id)}/replicas`, { method: 'POST', body: { replicas: Number(n) } });
82
+ return console.log(json ? JSON.stringify(r, null, 2) : green(`✓ Scaling to ${n} read replica(s)…`));
83
+ }
84
+ case 'pub':
85
+ case 'publications': {
86
+ need();
87
+ const act = a.positionals[1];
88
+ if (!act || act === 'ls') {
89
+ const r = await api(`/databases/${encodeURIComponent(id)}/publications`);
90
+ const l = r.publications || [];
91
+ return output(l, json, { rows: l.map((x) => ({ name: x.name, allTables: x.allTables ? 'yes' : 'no' })), columns: ['name', 'allTables'] });
92
+ }
93
+ if (act === 'add') {
94
+ const name = a.positionals[2];
95
+ if (!name)
96
+ throw new Error('need <name>');
97
+ const body = { name };
98
+ if (a.flags['all-tables'])
99
+ body.allTables = true;
100
+ else if (a.flags.tables)
101
+ body.tables = String(a.flags.tables).split(',');
102
+ const r = await api(`/databases/${encodeURIComponent(id)}/publications`, { method: 'POST', body });
103
+ return console.log(json ? JSON.stringify(r, null, 2) : green(`✓ Publication ${name} created`));
104
+ }
105
+ if (act === 'rm') {
106
+ const name = a.positionals[2];
107
+ if (!name)
108
+ throw new Error('need <name>');
109
+ await api(`/databases/${encodeURIComponent(id)}/publications?name=${encodeURIComponent(name)}`, { method: 'DELETE' });
110
+ return console.log(green(`✓ Publication ${name} dropped`));
111
+ }
112
+ throw new Error('usage: koigrid db pub <id> ls | add <name> [--all-tables|--tables t1,t2] | rm <name>');
113
+ }
63
114
  default: throw new Error(`unknown: db ${sub}`);
64
115
  }
65
116
  }
@@ -12,11 +12,31 @@ export async function jobs(a) {
12
12
  const name = a.positionals[0];
13
13
  const schedule = a.flags.schedule;
14
14
  const image = a.flags.image;
15
- if (!name || !schedule || !image)
16
- throw new Error('usage: koigrid jobs create <name> --schedule "<cron>" --image <img> [--command "..."]');
17
- const body = { name, schedule, image };
18
- if (a.flags.command)
19
- body.command = a.flags.command;
15
+ const url = a.flags.url;
16
+ if (!name || !schedule || (!image && !url))
17
+ throw new Error('usage: koigrid jobs create <name> --schedule "<cron>" (--image <img> [--command "..."] | --url <url> [--method POST] [--header "K: V"])');
18
+ const body = { name, schedule };
19
+ if (url) {
20
+ // Job HTTP: pega a una URL según el cron (no un contenedor). --header repetible ("K: V").
21
+ body.type = 'http';
22
+ body.url = url;
23
+ if (a.flags.method)
24
+ body.method = String(a.flags.method).toUpperCase();
25
+ const hdrs = [].concat(a.flags.header ?? []);
26
+ if (hdrs.length) {
27
+ body.headers = {};
28
+ for (const h of hdrs) {
29
+ const i = h.indexOf(':');
30
+ if (i > 0)
31
+ body.headers[h.slice(0, i).trim()] = h.slice(i + 1).trim();
32
+ }
33
+ }
34
+ }
35
+ else {
36
+ body.image = image;
37
+ if (a.flags.command)
38
+ body.command = a.flags.command;
39
+ }
20
40
  const r = await api('/jobs', { method: 'POST', body });
21
41
  if (json)
22
42
  console.log(JSON.stringify(r, null, 2));
package/dist/manifest.js CHANGED
@@ -4,11 +4,11 @@ export const CLI_COMMANDS = [
4
4
  { name: 'whoami', summary: 'Show the authenticated account', subs: [], endpoints: ['me'] },
5
5
  { name: 'usage', summary: 'Show usage & cost', subs: [], endpoints: ['usage'] },
6
6
  {
7
- name: 'apps', aliases: ['app'], product: 'apps', summary: 'Deploy and manage apps',
8
- subs: ['ls', 'deploy', 'logs', 'rm', 'scale', 'autoscale', 'env', 'domains', 'volumes', 'cdn', 'github', 'rollback', 'deployments'],
9
- endpoints: ['apps', 'apps/[id]', 'apps/[id]/deployments', 'apps/[id]/logs', 'apps/[id]/scale', 'apps/[id]/autoscale', 'apps/[id]/env', 'apps/[id]/domains', 'apps/[id]/volumes', 'apps/[id]/volumes/[volId]', 'apps/[id]/cdn', 'apps/[id]/github', 'apps/[id]/rollback'],
7
+ name: 'apps', aliases: ['app'], product: 'apps', summary: 'Deploy and manage apps (git repo, container image, or local --dir)',
8
+ subs: ['ls', 'deploy', 'logs', 'rm', 'scale', 'resize', 'autoscale', 'env', 'domains', 'volumes', 'cdn', 'github', 'rollback', 'deployments'],
9
+ endpoints: ['apps', 'apps/[id]', 'apps/[id]/deployments', 'apps/[id]/source-upload', 'apps/[id]/logs', 'apps/[id]/scale', 'apps/[id]/resources', 'apps/[id]/autoscale', 'apps/[id]/env', 'apps/[id]/domains', 'apps/[id]/volumes', 'apps/[id]/volumes/[volId]', 'apps/[id]/cdn', 'apps/[id]/github', 'apps/[id]/rollback'],
10
10
  },
11
- { name: 'db', aliases: ['databases', 'database'], product: 'databases', summary: 'Managed Postgres (HA)', subs: ['ls', 'create', 'rm', 'url', 'metrics', 'backups', 'restore'], endpoints: ['databases', 'databases/[id]', 'databases/[id]/connection', 'databases/[id]/backups', 'databases/[id]/restore', 'databases/[id]/metrics'] },
11
+ { name: 'db', aliases: ['databases', 'database'], product: 'databases', summary: 'Managed Postgres (HA)', subs: ['ls', 'create', 'rm', 'url', 'metrics', 'backups', 'restore', 'ext', 'replicas', 'pub'], endpoints: ['databases', 'databases/[id]', 'databases/[id]/connection', 'databases/[id]/backups', 'databases/[id]/restore', 'databases/[id]/metrics', 'databases/[id]/extensions', 'databases/[id]/replicas', 'databases/[id]/publications'] },
12
12
  { name: 'redis', aliases: ['cache'], product: 'cache', summary: 'Managed Redis (HA)', subs: ['ls', 'create', 'rm', 'url', 'metrics', 'backups', 'restore'], endpoints: ['redis', 'redis/[id]', 'redis/[id]/connection', 'redis/[id]/backups', 'redis/[id]/restore', 'redis/[id]/metrics'] },
13
13
  { name: 'storage', aliases: ['buckets'], product: 'storage', summary: 'Object storage (S3)', subs: ['ls', 'create', 'rm', 'keys', 'key'], endpoints: ['buckets', 'buckets/[id]', 'storage/keys', 'storage/keys/[id]'] },
14
14
  { 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'] },
package/package.json CHANGED
@@ -1,13 +1,14 @@
1
1
  {
2
2
  "name": "koigrid",
3
- "version": "0.1.0",
3
+ "version": "0.4.0",
4
4
  "description": "koigrid CLI \u2014 deploy apps, databases, redis, storage and more from your terminal (or your AI agent).",
5
5
  "bin": {
6
6
  "koigrid": "dist/index.js"
7
7
  },
8
8
  "type": "module",
9
9
  "files": [
10
- "dist"
10
+ "dist",
11
+ "CHANGELOG.md"
11
12
  ],
12
13
  "engines": {
13
14
  "node": ">=18"