layerbase 0.4.2 → 1.2.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.
Files changed (49) hide show
  1. package/README.md +186 -45
  2. package/dist/cli.js +310 -46
  3. package/dist/cli.js.map +1 -1
  4. package/dist/commands/agent-init.js +112 -0
  5. package/dist/commands/agent-init.js.map +1 -0
  6. package/dist/commands/cloud-branch.js +97 -0
  7. package/dist/commands/cloud-branch.js.map +1 -0
  8. package/dist/commands/cloud-write.js +133 -0
  9. package/dist/commands/cloud-write.js.map +1 -0
  10. package/dist/commands/connection-string.js +17 -16
  11. package/dist/commands/connection-string.js.map +1 -1
  12. package/dist/commands/import.js +96 -0
  13. package/dist/commands/import.js.map +1 -0
  14. package/dist/commands/interactive.js +2 -0
  15. package/dist/commands/interactive.js.map +1 -1
  16. package/dist/commands/key-login.js +48 -0
  17. package/dist/commands/key-login.js.map +1 -0
  18. package/dist/commands/ls.js +17 -5
  19. package/dist/commands/ls.js.map +1 -1
  20. package/dist/commands/migrate.js +331 -0
  21. package/dist/commands/migrate.js.map +1 -0
  22. package/dist/commands/whoami-run.js +87 -0
  23. package/dist/commands/whoami-run.js.map +1 -0
  24. package/dist/commands/whoami.js +1 -1
  25. package/dist/commands/whoami.js.map +1 -1
  26. package/dist/lib/cli-output.js +28 -0
  27. package/dist/lib/cli-output.js.map +1 -0
  28. package/dist/lib/cloud-api.js +338 -20
  29. package/dist/lib/cloud-api.js.map +1 -1
  30. package/dist/lib/commands.js +90 -18
  31. package/dist/lib/commands.js.map +1 -1
  32. package/dist/lib/config.js +18 -0
  33. package/dist/lib/config.js.map +1 -1
  34. package/dist/lib/confirm.js +17 -0
  35. package/dist/lib/confirm.js.map +1 -0
  36. package/dist/lib/duration.js +33 -0
  37. package/dist/lib/duration.js.map +1 -0
  38. package/dist/lib/migration-catalog.js +209 -0
  39. package/dist/lib/migration-catalog.js.map +1 -0
  40. package/dist/lib/redact.js +23 -0
  41. package/dist/lib/redact.js.map +1 -0
  42. package/dist/lib/select.js +48 -0
  43. package/dist/lib/select.js.map +1 -0
  44. package/dist/lib/version.js +26 -0
  45. package/dist/lib/version.js.map +1 -0
  46. package/dist/ui/app.js +1 -1
  47. package/dist/ui/app.js.map +1 -1
  48. package/package.json +6 -3
  49. package/skills/layerbase/SKILL.md +222 -0
package/dist/cli.js CHANGED
@@ -7,74 +7,338 @@ import { runExec } from './commands/connect.js';
7
7
  import { runInteractive } from './commands/interactive.js';
8
8
  import { runClone } from './commands/clone.js';
9
9
  import { runSpindb } from './lib/run-spindb.js';
10
- const cli = meow(`
11
- Usage
12
- $ layerbase <command> [options]
13
-
14
- Commands
15
- login Sign in via your browser; saves a token to ~/.layerbase-cli
16
- logout Remove the stored credentials
17
- whoami Show the signed-in account (--json to script it)
18
- ls List your cloud databases
19
- connect <db> Connect with the right client for the engine
20
- clone <db> [name] Clone a cloud database into a local spindb container
21
- psql <db> Connect to a Postgres-family database
22
- redis-cli <db> Connect to a Redis/Valkey database
23
- mysql <db> Connect to a MySQL/MariaDB database
24
- connection-string <db> Print the connection string (reveals the password)
25
- spindb [args...] Run the local spindb CLI (passes args through)
26
- alias Set up the short lb command (only if it is free)
27
-
28
- Run with no command for the interactive prompt (type /commands). Also lbase.
29
-
30
- Options
31
- --print With connect: show connection info, do not exec
32
- --json With ls: print JSON instead of a table
33
- --api-url <url> Cloud API base (env: LAYERBASE_API_URL)
10
+ import { registeredCommandNames } from './lib/commands.js';
11
+ import { getVersion } from './lib/version.js';
12
+ import { configureCloudAuth } from './lib/cloud-api.js';
13
+ import { runWhoami } from './commands/whoami-run.js';
14
+ import { runKeyLogin } from './commands/key-login.js';
15
+ import { runCreate, runDestroy, runStart, runStop, } from './commands/cloud-write.js';
16
+ import { runBranch } from './commands/cloud-branch.js';
17
+ import { runAgentInit } from './commands/agent-init.js';
18
+ import { runMigrate } from './commands/migrate.js';
19
+ import { runImport } from './commands/import.js';
20
+ const VERSION = getVersion();
21
+ const UNIFIED_HELP = `
22
+ Layerbase ${VERSION} - local-first database CLI (also as lbase)
23
+
24
+ Local databases (drop-in for spindb - every spindb command works)
25
+ create, ls, start, stop, connect, clone, branch, backup, restore, run,
26
+ query, pull, menu, ...
27
+ Anything not listed under "Cloud account" runs against your local spindb
28
+ install verbatim, flags included. Run "lbase <cmd> --help" for details.
29
+
30
+ Cloud account
31
+ login / logout / whoami Manage your Layerbase session
32
+ cloud ls List your cloud databases (--json to script)
33
+ cloud create <name> --engine <e> [--ttl 2h] Provision a database
34
+ cloud delete <db> --yes Delete a cloud database
35
+ cloud start / stop <db> Start or stop a cloud database
36
+ cloud branch <db> <name> Create/reset/delete/ls database branches
37
+ cloud connect <db> Connect with the engine's native client
38
+ cloud clone <db> [name] Clone a cloud database into local spindb
39
+ cloud connection-string <db> Print the connection string (reveals password)
40
+ psql / mysql / redis-cli <db> Connect to a cloud database by engine
41
+ migrate --source <s> --target <db> Import an external database into a cloud DB
42
+ import <dumpfile> --target <db> Import a dump file into a cloud database
43
+ agent init [--global] Install the Layerbase skill for AI agents
44
+ alias Set up the short "lb" command
45
+ chat Interactive console for your Layerbase account
46
+
47
+ Headless auth (CI / agents)
48
+ Set LAYERBASE_API_KEY (or pass --api-key) to run cloud commands with no
49
+ browser: calls go straight to the cloud API. "layerbase login --api-key
50
+ <key>" saves it. Create a key at https://layerbase.com/cloud/settings.
51
+
52
+ Notes
53
+ bare = spindb, cloud = "lbase cloud <verb>"
54
+ "lbase --help" / "--version" show this help / the layerbase version.
55
+ "lbase version" forwards to spindb's version command.
34
56
 
35
57
  Examples
36
- $ layerbase # interactive menu
37
- $ layerbase login
38
- $ layerbase ls
39
- $ layerbase psql my-db
40
- $ layerbase spindb create postgres
41
- `, {
58
+ $ lbase # spindb's interactive menu
59
+ $ lbase create my-db --engine sqlite
60
+ $ lbase login
61
+ $ lbase cloud ls --json
62
+ $ LAYERBASE_API_KEY=sk_... lbase cloud create ci-db --engine postgresql --ttl 2h
63
+ $ lbase psql my-cloud-db
64
+ `;
65
+ const CLOUD_HELP = `
66
+ Cloud account commands
67
+
68
+ lbase cloud ls List your cloud databases (--json to script)
69
+ lbase cloud create <name> --engine <e> [--ttl 2h] [--json]
70
+ Provision a database (--ttl makes it transient)
71
+ lbase cloud delete <db> --yes Delete a database (--yes to skip the prompt)
72
+ lbase cloud start <db> Start a database
73
+ lbase cloud stop <db> Stop a database
74
+ lbase cloud branch <db> <name> Create or reuse a branch
75
+ lbase cloud branch reset <db> <name> Re-fork a branch from its parent
76
+ lbase cloud branch delete <db> <name> Delete a branch
77
+ lbase cloud branch ls <db> List a database branches
78
+ lbase cloud connect <db> Connect with the engine's native client
79
+ lbase cloud clone <db> [name] Clone a cloud database into local spindb
80
+ lbase cloud connection-string <db> (alias: url)
81
+ Print the connection string (reveals password)
82
+ lbase psql / mysql / redis-cli <db> Connect to a cloud database by engine
83
+
84
+ "<db>" accepts a cloud database id or its name. Set LAYERBASE_API_KEY (or pass
85
+ --api-key) to run these headlessly with no browser login.
86
+ `;
87
+ const MIGRATE_HELP = `
88
+ layerbase migrate - import an external database INTO a cloud database
89
+
90
+ layerbase migrate --source <id> --target <db-id-or-name> [creds] [--yes] [--json]
91
+
92
+ Sources and their credential flags
93
+ Connection-string sources (paste one URL with --connection-string, alias --url):
94
+ postgres postgresql://user:password@host:5432/dbname
95
+ mysql mysql://user:password@host:3306/dbname
96
+ mariadb mysql://... (MariaDB is MySQL-compatible)
97
+ redis redis:// or rediss://
98
+ valkey redis:// or rediss://
99
+ vercel-kv the KV_URL (rediss://) from your Vercel project
100
+
101
+ API-key sources (we discover the account, then you pick a database):
102
+ neon --source-key <napi_...>
103
+ supabase --source-key <sbp_...> --source-secret <db password>
104
+ render --source-key <rnd_...>
105
+ railway --source-key <token>
106
+ planetscale --source-key <service token> --source-id <service token id>
107
+ upstash --source-key <mgmt api key> --source-id <account email>
108
+ algolia --source-key <admin api key> --source-id <application id> (--app-id)
109
+ turso --source-key <auth token> --source-id <libsql:// url> (--url)
110
+
111
+ Friendly aliases: --token = --source-key; --app-id / --email / --token-id / --url
112
+ fill --source-id; --db-password = --source-secret.
113
+
114
+ Picking a source database
115
+ --source-db <label-or-number> choose among discovered databases in a non-TTY.
116
+
117
+ Output
118
+ --json prints ONE final JSON result object (no interim progress lines):
119
+ { ok, runId, status, databaseId, report } on success
120
+ { ok: false, runId, status, error } on failure
121
+ Without --json, status + progress lines stream to stdout while the run polls.
122
+
123
+ Credentials are never written to stdout, stderr, or --json output. In an
124
+ interactive terminal, missing credentials are prompted for; in CI, a missing
125
+ required flag exits 1 and lists what to pass.
126
+ `;
127
+ const IMPORT_HELP = `
128
+ layerbase import - restore a dump file INTO a cloud database
129
+
130
+ layerbase import <dumpfile> --target <db-id-or-name> [--yes] [--json]
131
+
132
+ Uploads the dump straight to storage (presigned), then restores it over the
133
+ target database. Validates the file exists and is non-empty first and warns on
134
+ very large files; the server enforces the hard size cap. --json prints a final
135
+ { ok, message, database, engine, bytesUploaded } result.
136
+ `;
137
+ function printHelp() {
138
+ process.stdout.write(`${UNIFIED_HELP}\n`);
139
+ }
140
+ // Both migrate/import reach meow (registered verbs), which has autoHelp off, so
141
+ // a --help/-h/`help` subtoken is handled here explicitly. Reads the raw argv for
142
+ // the flag (meow strips it into flags) plus the parsed `help` subtoken.
143
+ function wantsHelp(rest) {
144
+ return (process.argv.includes('--help') ||
145
+ process.argv.includes('-h') ||
146
+ rest[0] === 'help');
147
+ }
148
+ function printCloudHelp() {
149
+ process.stdout.write(`${CLOUD_HELP}\n`);
150
+ }
151
+ // Dispatch a "lbase cloud <verb> ..." invocation to the existing cloud command
152
+ // implementations. Flags (e.g. --json on cloud ls) are already parsed by meow.
153
+ async function runCloud(rest, flags) {
154
+ const [sub = '', ...cloudArgs] = rest;
155
+ if (!sub) {
156
+ printCloudHelp();
157
+ process.exit(0);
158
+ }
159
+ if (sub === 'ls') {
160
+ render(_jsx(App, { command: "ls", args: [], flags: flags }));
161
+ return;
162
+ }
163
+ if (sub === 'create') {
164
+ process.exit(await runCreate({ args: cloudArgs, flags }));
165
+ }
166
+ if (sub === 'delete' || sub === 'rm' || sub === 'destroy') {
167
+ process.exit(await runDestroy({ args: cloudArgs, flags }));
168
+ }
169
+ if (sub === 'start') {
170
+ process.exit(await runStart({ args: cloudArgs, flags }));
171
+ }
172
+ if (sub === 'stop') {
173
+ process.exit(await runStop({ args: cloudArgs, flags }));
174
+ }
175
+ if (sub === 'branch') {
176
+ process.exit(await runBranch({ args: cloudArgs, flags }));
177
+ }
178
+ if (sub === 'connect') {
179
+ await runExec({ command: 'connect', args: cloudArgs, flags });
180
+ return;
181
+ }
182
+ if (sub === 'clone') {
183
+ const dbRef = cloudArgs[0];
184
+ if (!dbRef) {
185
+ process.stderr.write('Usage: layerbase cloud clone <db> [local-name]\n');
186
+ process.exit(1);
187
+ }
188
+ process.exit(await runClone({ dbRef, localName: cloudArgs[1] }));
189
+ }
190
+ // `url` is accepted as a sub-alias for connection-string (matching spindb's
191
+ // own url|connection-string naming).
192
+ if (sub === 'connection-string' || sub === 'url') {
193
+ render(_jsx(App, { command: "connection-string", args: cloudArgs, flags: flags }));
194
+ return;
195
+ }
196
+ process.stderr.write(`Unknown cloud command: ${sub}\n`);
197
+ printCloudHelp();
198
+ process.exit(1);
199
+ }
200
+ // Everything below is a pre-meow raw-argv interception. It is the single
201
+ // dispatch point for the whole CLI. We read process.argv verbatim (never
202
+ // through meow, which strips/reorders flags and would corrupt forwarded spindb
203
+ // commands) and forward everything from the command token onward, flags and
204
+ // order preserved. meow is constructed AFTER these interceptions, so it only
205
+ // ever parses a genuinely layerbase-owned command.
206
+ const rawArgs = process.argv.slice(2);
207
+ const firstArgIndex = rawArgs.findIndex((arg) => !arg.startsWith('-'));
208
+ const leadingCommand = firstArgIndex >= 0 ? rawArgs[firstArgIndex] : '';
209
+ // First-token help/version flags (no command before them) render layerbase's
210
+ // own unified help / version. After a spindb-bound token they forward verbatim
211
+ // via the fallthrough below (so "lbase create --help" reaches spindb's help).
212
+ if (!leadingCommand && rawArgs.length > 0) {
213
+ const flag = rawArgs[0];
214
+ if (flag === '--help' || flag === '-h') {
215
+ printHelp();
216
+ process.exit(0);
217
+ }
218
+ if (flag === '--version' || flag === '-v') {
219
+ process.stdout.write(`${VERSION}\n`);
220
+ process.exit(0);
221
+ }
222
+ }
223
+ // Bare invocation with no args: on a TTY hand off to spindb's interactive menu
224
+ // (the zero-arg case of the fallthrough); in a non-TTY context (pipes, CI)
225
+ // print the unified help and exit 0 instead of hanging on a prompt.
226
+ if (rawArgs.length === 0) {
227
+ if (process.stdin.isTTY) {
228
+ process.exit(await runSpindb([]));
229
+ }
230
+ printHelp();
231
+ process.exit(0);
232
+ }
233
+ // Explicit "spindb" prefix: strip the token, forward the rest to spindb. Kept
234
+ // as an explicit escape hatch even though bare fallthrough covers most cases.
235
+ if (leadingCommand === 'spindb') {
236
+ process.exit(await runSpindb(rawArgs.slice(firstArgIndex + 1)));
237
+ }
238
+ // Local-first fallthrough: any first token that is NOT a registered layerbase
239
+ // verb forwards verbatim to the local spindb CLI, INCLUDING the token itself,
240
+ // flags and order preserved. This is what makes "lbase create / list / backup /
241
+ // branch / connect / clone / ls / url ..." behave exactly like the same spindb
242
+ // command. The registered verbs are the ONLY bare words layerbase owns; the
243
+ // bare namespace otherwise belongs entirely to spindb.
244
+ const REGISTERED_COMMANDS = new Set(registeredCommandNames());
245
+ if (leadingCommand && !REGISTERED_COMMANDS.has(leadingCommand)) {
246
+ process.exit(await runSpindb(rawArgs.slice(firstArgIndex)));
247
+ }
248
+ const cli = meow(UNIFIED_HELP, {
42
249
  importMeta: import.meta,
250
+ autoHelp: false,
251
+ autoVersion: false,
252
+ version: VERSION,
43
253
  flags: {
44
254
  print: { type: 'boolean', default: false },
45
255
  json: { type: 'boolean', default: false },
46
256
  apiUrl: { type: 'string' },
257
+ // Headless auth: an sk_ key overrides the browser JWT and routes cloud
258
+ // calls straight to the cloud /v1 API.
259
+ apiKey: { type: 'string' },
260
+ // Cloud-mutation flags.
261
+ engine: { type: 'string' },
262
+ ttl: { type: 'string' },
263
+ yes: { type: 'boolean', default: false, shortFlag: 'y' },
264
+ force: { type: 'boolean', default: false },
265
+ global: { type: 'boolean', default: false },
266
+ // migrate / import flags.
267
+ source: { type: 'string' },
268
+ target: { type: 'string' },
269
+ sourceDb: { type: 'string' },
270
+ connectionString: { type: 'string' },
271
+ sourceKey: { type: 'string' },
272
+ sourceId: { type: 'string' },
273
+ sourceSecret: { type: 'string' },
274
+ // Friendly per-source credential aliases (resolved in migrate.ts).
275
+ appId: { type: 'string' },
276
+ email: { type: 'string' },
277
+ tokenId: { type: 'string' },
278
+ token: { type: 'string' },
279
+ url: { type: 'string' },
280
+ dbPassword: { type: 'string' },
47
281
  },
48
282
  });
49
- const EXEC_COMMANDS = new Set(['connect', 'psql', 'redis-cli', 'mysql']);
283
+ // The --api-key flag wins over LAYERBASE_API_KEY and the stored key. Set it once
284
+ // before any cloud command runs.
285
+ configureCloudAuth({ apiKey: cli.flags.apiKey });
286
+ const EXEC_COMMANDS = new Set(['psql', 'redis-cli', 'mysql']);
50
287
  const [command = '', ...rest] = cli.input;
51
288
  if (command === 'help') {
52
- cli.showHelp(0);
289
+ printHelp();
290
+ process.exit(0);
53
291
  }
54
- else if (!command) {
55
- // No command: interactive menu on a TTY, help otherwise (pipes, CI).
56
- if (process.stdin.isTTY) {
57
- await runInteractive(cli.flags);
292
+ else if (command === 'whoami') {
293
+ process.exit(await runWhoami({ json: cli.flags.json ?? false }));
294
+ }
295
+ else if (command === 'login' && cli.flags.apiKey) {
296
+ // Headless key login (no browser). Interactive browser login still runs via
297
+ // the Ink <Login> below when no --api-key is passed.
298
+ process.exit(await runKeyLogin({
299
+ apiKey: cli.flags.apiKey,
300
+ json: cli.flags.json ?? false,
301
+ }));
302
+ }
303
+ else if (command === 'agent') {
304
+ const [sub] = rest;
305
+ if (sub === 'init') {
306
+ process.exit(await runAgentInit({ flags: cli.flags }));
58
307
  }
59
- else {
60
- cli.showHelp(0);
308
+ process.stderr.write('Usage: layerbase agent init [--global] [--force]\n');
309
+ process.exit(1);
310
+ }
311
+ else if (command === 'chat') {
312
+ // chat is the ONLY entry into the Ink interactive console (the bare no-arg
313
+ // launch moved to spindb). It needs a real terminal for the prompt.
314
+ if (!process.stdin.isTTY) {
315
+ process.stderr.write('layerbase chat needs an interactive terminal.\n');
316
+ process.exit(1);
61
317
  }
318
+ await runInteractive(cli.flags);
62
319
  }
63
- else if (command === 'spindb') {
64
- process.exit(await runSpindb(rest));
320
+ else if (command === 'migrate') {
321
+ if (wantsHelp(rest)) {
322
+ process.stdout.write(`${MIGRATE_HELP}\n`);
323
+ process.exit(0);
324
+ }
325
+ process.exit(await runMigrate({ flags: cli.flags }));
65
326
  }
66
- else if (command === 'clone') {
67
- const dbRef = rest[0];
68
- if (!dbRef) {
69
- process.stderr.write('Usage: layerbase clone <db> [local-name]\n');
70
- process.exit(1);
327
+ else if (command === 'import') {
328
+ if (wantsHelp(rest)) {
329
+ process.stdout.write(`${IMPORT_HELP}\n`);
330
+ process.exit(0);
71
331
  }
72
- process.exit(await runClone({ dbRef, localName: rest[1] }));
332
+ process.exit(await runImport({ args: rest, flags: cli.flags }));
333
+ }
334
+ else if (command === 'cloud') {
335
+ await runCloud(rest, cli.flags);
73
336
  }
74
337
  else if (EXEC_COMMANDS.has(command)) {
75
338
  await runExec({ command, args: rest, flags: cli.flags });
76
339
  }
77
340
  else {
341
+ // login, logout, whoami, alias.
78
342
  render(_jsx(App, { command: command, args: rest, flags: cli.flags }));
79
343
  }
80
344
  //# sourceMappingURL=cli.js.map
package/dist/cli.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.tsx"],"names":[],"mappings":";AAAA,OAAO,IAAI,MAAM,MAAM,CAAA;AACvB,OAAO,EAAE,MAAM,EAAE,MAAM,KAAK,CAAA;AAC5B,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAA;AAC9B,OAAO,EAAE,O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GAAG,YAAY,IAAI,CAAC,CAAA;QACzC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;IACjB,CAAC;IACD,OAAO,CAAC,IAAI,CAAC,MAAM,UAAU,CAAC,EAAE,KAAK,EAAE,GAAG,CAAC,KAAK,EAAE,CAAC,CAAC,CAAA;AACtD,CAAC;KAAM,IAAI,OAAO,KAAK,QAAQ,EAAE,CAAC;IAChC,IAAI,SAAS,CAAC,IAAI,CAAC,EAAE,CAAC;QACpB,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,WAAW,IAAI,CAAC,CAAA;QACxC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;IACjB,CAAC;IACD,OAAO,CAAC,IAAI,CAAC,MAAM,SAAS,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,CAAC,KAAK,EAAE,CAAC,CAAC,CAAA;AACjE,CAAC;KAAM,IAAI,OAAO,KAAK,OAAO,EAAE,CAAC;IAC/B,MAAM,QAAQ,CAAC,IAAI,EAAE,GAAG,CAAC,KAAK,CAAC,CAAA;AACjC,CAAC;KAAM,IAAI,aAAa,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC;IACtC,MAAM,OAAO,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,CAAC,KAAK,EAAE,CAAC,CAAA;AAC1D,CAAC;KAAM,CAAC;IACN,gCAAgC;IAChC,MAAM,CAAC,KAAC,GAAG,IAAC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,CAAC,KAAK,GAAI,CAAC,CAAA;AACjE,CAAC"}
@@ -0,0 +1,112 @@
1
+ import { homedir } from 'node:os';
2
+ import { join } from 'node:path';
3
+ import { fileURLToPath } from 'node:url';
4
+ import { mkdir, readFile, writeFile, access } from 'node:fs/promises';
5
+ import { DEFAULT_API_URL } from '../lib/cloud-api.js';
6
+ import { confirm } from '../lib/confirm.js';
7
+ // Where the canonical skill is served (frontmatter-first text/markdown). The web
8
+ // base is overridable via LAYERBASE_API_URL; LAYERBASE_SKILL_URL overrides the
9
+ // whole URL for testing.
10
+ function skillUrl() {
11
+ return (process.env.LAYERBASE_SKILL_URL ?? `${DEFAULT_API_URL}/skill.md`);
12
+ }
13
+ // The copy bundled in the npm tarball (shipped separately). It has a short
14
+ // leading HTML comment BEFORE the frontmatter; strict skill parsers want `---`
15
+ // on line 1, so strip a leading <!-- ... --> block when installing from it.
16
+ function bundledSkillPath() {
17
+ return fileURLToPath(new URL('../../skills/layerbase/SKILL.md', import.meta.url));
18
+ }
19
+ function stripLeadingHtmlComment(content) {
20
+ return content.replace(/^\uFEFF?\s*<!--[\s\S]*?-->\s*\r?\n/, '');
21
+ }
22
+ async function fetchSkill() {
23
+ try {
24
+ const response = await fetch(skillUrl(), {
25
+ headers: { 'user-agent': 'layerbase-cli agent-init' },
26
+ signal: AbortSignal.timeout(15_000),
27
+ });
28
+ if (!response.ok)
29
+ return null;
30
+ return await response.text();
31
+ }
32
+ catch {
33
+ return null;
34
+ }
35
+ }
36
+ async function readBundledSkill() {
37
+ try {
38
+ const raw = await readFile(bundledSkillPath(), 'utf8');
39
+ return stripLeadingHtmlComment(raw);
40
+ }
41
+ catch {
42
+ return null;
43
+ }
44
+ }
45
+ async function fileExists(path) {
46
+ try {
47
+ await access(path);
48
+ return true;
49
+ }
50
+ catch {
51
+ return false;
52
+ }
53
+ }
54
+ const AGENTS_SNIPPET = `
55
+ Add this to your AGENTS.md so Codex and other agents can use Layerbase:
56
+
57
+ ## Layerbase
58
+ The \`layerbase\` CLI (npm i -g layerbase) manages local and cloud databases.
59
+ Set LAYERBASE_API_KEY for headless cloud access: create, branch, and delete
60
+ transient databases in CI without a browser.
61
+ Capabilities, live prices, and migration sources: https://layerbase.com/agents.md
62
+ Full skill: read .claude/skills/layerbase/SKILL.md
63
+ `;
64
+ // `layerbase agent init [--global] [--force]`: install the Layerbase skill for
65
+ // coding agents. Fetches the canonical skill, falling back to the bundled copy
66
+ // offline. Never overwrites without consent (--force in non-TTY).
67
+ export async function runAgentInit(options) {
68
+ const global = options.flags.global ?? false;
69
+ const force = options.flags.force ?? false;
70
+ const baseDir = global
71
+ ? join(homedir(), '.claude', 'skills', 'layerbase')
72
+ : join(process.cwd(), '.claude', 'skills', 'layerbase');
73
+ const target = join(baseDir, 'SKILL.md');
74
+ if (await fileExists(target)) {
75
+ if (!force) {
76
+ if (!process.stdin.isTTY) {
77
+ process.stderr.write(`${target} already exists. Pass --force to overwrite.\n`);
78
+ return 1;
79
+ }
80
+ const ok = await confirm(`Overwrite existing skill at ${target}?`);
81
+ if (!ok) {
82
+ process.stdout.write('Aborted.\n');
83
+ return 1;
84
+ }
85
+ }
86
+ }
87
+ let content = await fetchSkill();
88
+ let source = 'layerbase.com';
89
+ if (content == null) {
90
+ content = await readBundledSkill();
91
+ source = 'bundled copy';
92
+ }
93
+ if (content == null) {
94
+ process.stderr.write('Could not fetch the Layerbase skill from ' +
95
+ `${skillUrl()} and no bundled copy is available. ` +
96
+ 'Check your network connection or reinstall the layerbase package.\n');
97
+ return 1;
98
+ }
99
+ try {
100
+ await mkdir(baseDir, { recursive: true });
101
+ await writeFile(target, content, { mode: 0o644 });
102
+ }
103
+ catch (error) {
104
+ process.stderr.write(`Could not write ${target}: ${error.message}\n`);
105
+ return 1;
106
+ }
107
+ process.stdout.write(`Installed the Layerbase skill (${source}) to:\n`);
108
+ process.stdout.write(` ${target}\n`);
109
+ process.stdout.write(AGENTS_SNIPPET);
110
+ return 0;
111
+ }
112
+ //# sourceMappingURL=agent-init.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agent-init.js","sourceRoot":"","sources":["../../src/commands/agent-init.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;AACjC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAChC,OAAO,EAAE,aAA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AO,CAAC,MAAM,CAAC,KAAK,CAAC,YAAY,CAAC,CAAA;gBAClC,OAAO,CAAC,CAAA;YACV,CAAC;QACH,CAAC;IACH,CAAC;IAED,IAAI,OAAO,GAAG,MAAM,UAAU,EAAE,CAAA;IAChC,IAAI,MAAM,GAAG,eAAe,CAAA;IAC5B,IAAI,OAAO,IAAI,IAAI,EAAE,CAAC;QACpB,OAAO,GAAG,MAAM,gBAAgB,EAAE,CAAA;QAClC,MAAM,GAAG,cAAc,CAAA;IACzB,CAAC;IACD,IAAI,OAAO,IAAI,IAAI,EAAE,CAAC;QACpB,OAAO,CAAC,MAAM,CAAC,KAAK,CAClB,2CAA2C;YACzC,GAAG,QAAQ,EAAE,qCAAqC;YAClD,qEAAqE,CACxE,CAAA;QACD,OAAO,CAAC,CAAA;IACV,CAAC;IAED,IAAI,CAAC;QACH,MAAM,KAAK,CAAC,OAAO,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAA;QACzC,MAAM,SAAS,CAAC,MAAM,EAAE,OAAO,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAA;IACnD,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,CAAC,MAAM,CAAC,KAAK,CAClB,mBAAmB,MAAM,KAAM,KAAe,CAAC,OAAO,IAAI,CAC3D,CAAA;QACD,OAAO,CAAC,CAAA;IACV,CAAC;IAED,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,kCAAkC,MAAM,SAAS,CAAC,CAAA;IACvE,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,MAAM,IAAI,CAAC,CAAA;IACrC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,cAAc,CAAC,CAAA;IACpC,OAAO,CAAC,CAAA;AACV,CAAC"}
@@ -0,0 +1,97 @@
1
+ import { createBranch, deleteBranch, listBranches, resetBranch, resolveDatabaseId, } from '../lib/cloud-api.js';
2
+ import { reportError, writeJson } from '../lib/cli-output.js';
3
+ const BRANCH_USAGE = 'Usage:\n' +
4
+ ' layerbase cloud branch <db> <branch-name> Create/reuse a branch\n' +
5
+ ' layerbase cloud branch reset <db> <name> Re-fork a branch from parent\n' +
6
+ ' layerbase cloud branch delete <db> <name> Delete a branch\n' +
7
+ ' layerbase cloud branch ls <db> List a database branches\n';
8
+ function printBranch(branch) {
9
+ process.stdout.write(`${branch.name} (${branch.status})\n`);
10
+ if (branch.connectionString) {
11
+ process.stdout.write(`${branch.connectionString}\n`);
12
+ }
13
+ }
14
+ async function runBranchCreate(db, name, json, action) {
15
+ if (!db || !name) {
16
+ process.stderr.write(BRANCH_USAGE);
17
+ return 1;
18
+ }
19
+ try {
20
+ const parentId = await resolveDatabaseId(db);
21
+ const branch = action === 'reset'
22
+ ? await resetBranch({ parentId, name })
23
+ : await createBranch({ parentId, name });
24
+ if (json) {
25
+ writeJson({ ok: true, ...branch });
26
+ }
27
+ else {
28
+ printBranch(branch);
29
+ }
30
+ return 0;
31
+ }
32
+ catch (error) {
33
+ return reportError(error, json);
34
+ }
35
+ }
36
+ async function runBranchDelete(db, name, json) {
37
+ if (!db || !name) {
38
+ process.stderr.write(BRANCH_USAGE);
39
+ return 1;
40
+ }
41
+ try {
42
+ const parentId = await resolveDatabaseId(db);
43
+ await deleteBranch({ parentId, name });
44
+ if (json) {
45
+ writeJson({ ok: true, deleted: name });
46
+ }
47
+ else {
48
+ process.stdout.write(`Deleted branch ${name}.\n`);
49
+ }
50
+ return 0;
51
+ }
52
+ catch (error) {
53
+ return reportError(error, json);
54
+ }
55
+ }
56
+ async function runBranchList(db, json) {
57
+ if (!db) {
58
+ process.stderr.write(BRANCH_USAGE);
59
+ return 1;
60
+ }
61
+ try {
62
+ const parentId = await resolveDatabaseId(db);
63
+ const branches = await listBranches(parentId);
64
+ if (json) {
65
+ writeJson(branches);
66
+ return 0;
67
+ }
68
+ if (branches.length === 0) {
69
+ process.stdout.write('No branches.\n');
70
+ return 0;
71
+ }
72
+ for (const branch of branches) {
73
+ process.stdout.write(`${branch.name}\t${branch.status}\t${branch.id}\n`);
74
+ }
75
+ return 0;
76
+ }
77
+ catch (error) {
78
+ return reportError(error, json);
79
+ }
80
+ }
81
+ // Dispatch `cloud branch ...`. `args` is everything after the `branch` token.
82
+ export async function runBranch(options) {
83
+ const json = options.flags.json ?? false;
84
+ const [first, ...rest] = options.args;
85
+ if (first === 'ls' || first === 'list') {
86
+ return runBranchList(rest[0], json);
87
+ }
88
+ if (first === 'reset') {
89
+ return runBranchCreate(rest[0], rest[1], json, 'reset');
90
+ }
91
+ if (first === 'delete' || first === 'rm') {
92
+ return runBranchDelete(rest[0], rest[1], json);
93
+ }
94
+ // Default: create/reuse a branch named args[1] off database args[0].
95
+ return runBranchCreate(first, rest[0], json, 'create');
96
+ }
97
+ //# sourceMappingURL=cloud-branch.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cloud-branch.js","sourceRoot":"","sources":["../../src/commands/cloud-branch.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,EACZ,YAAY,EACZ,YAAY,EACZ,WAAW,EACX,iBAAiB,GAClB,MAAM,iBAAiB,CAAA;AAGxB,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAA;AAEzD,MAAM,YAAY,GAChB,UAAU;IACV,uEAAuE;IACvE,8EAA8E;IAC9E,iEAAiE;IACjE,0EAA0E,CAAA;AAE5E,SAAS,WAAW,CAAC,MAAkB;IACrC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,MAAM,CAAC,IAAI,KAAK,MAAM,CAAC,MAAM,KAAK,CAAC,CAAA;IAC3D,IAAI,MAAM,CAAC,gBAAgB,EAAE,CAAC;QAC5B,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,MAAM,CAAC,gBAAgB,IAAI,CAAC,CAAA;IACtD,CAAC;AACH,CAAC;AAED,KAAK,UAAU,eAAe,CAC5B,EAAsB,EACtB,IAAwB,EACxB,IAAa,EACb,MA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