@bagdock/cli 0.1.4 → 0.3.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/README.md CHANGED
@@ -1,9 +1,23 @@
1
1
  # @bagdock/cli
2
2
 
3
- Developer CLI for building, testing, and deploying apps and edges on the Bagdock platform.
3
+ The official CLI for Bagdock. Built for humans, AI agents, and CI/CD pipelines.
4
4
 
5
5
  ## Install
6
6
 
7
+ ### cURL (macOS / Linux)
8
+
9
+ ```bash
10
+ curl -fsSL https://bdok.dev/install.sh | bash
11
+ ```
12
+
13
+ ### PowerShell (Windows)
14
+
15
+ ```powershell
16
+ irm https://bdok.dev/install.ps1 | iex
17
+ ```
18
+
19
+ ### Node.js
20
+
7
21
  ```bash
8
22
  # npm
9
23
  npm install -g @bagdock/cli
@@ -26,12 +40,85 @@ bunx @bagdock/cli --help
26
40
  pnpm dlx @bagdock/cli --help
27
41
  ```
28
42
 
43
+ ### Agent skills
44
+
45
+ This CLI ships with an agent skill that teaches AI coding agents (Cursor, Claude Code, Windsurf, etc.) how to use the Bagdock CLI effectively — including non-interactive flags, output formats, and common pitfalls.
46
+
47
+ ```bash
48
+ npx skills add bagdock/bagdock-skills
49
+ ```
50
+
51
+ ## Local development
52
+
53
+ Use this when you want to change the CLI and run your build locally.
54
+
55
+ ### Prerequisites
56
+
57
+ - Node.js 20+
58
+ - Bun (for building)
59
+
60
+ ### Setup
61
+
62
+ Clone the repo:
63
+
64
+ ```bash
65
+ git clone https://github.com/bagdock/bagdock-cli.git
66
+ cd bagdock-cli
67
+ ```
68
+
69
+ Install dependencies:
70
+
71
+ ```bash
72
+ bun install
73
+ ```
74
+
75
+ Build locally:
76
+
77
+ ```bash
78
+ bun run build
79
+ ```
80
+
81
+ Output: `./dist/bagdock.js`
82
+
83
+ ### Running the CLI locally
84
+
85
+ Use the dev script:
86
+
87
+ ```bash
88
+ bun run dev -- --version
89
+ bun run dev -- doctor
90
+ bun run dev -- keys list --json
91
+ ```
92
+
93
+ Or run the built JS bundle:
94
+
95
+ ```bash
96
+ node dist/bagdock.js --version
97
+ ```
98
+
99
+ ### Making changes
100
+
101
+ After editing source files, rebuild:
102
+
103
+ ```bash
104
+ bun run build
105
+ ```
106
+
107
+ ### Running tests
108
+
109
+ ```bash
110
+ bun run test
111
+ ```
112
+
29
113
  ## Quick start
30
114
 
31
115
  ```bash
32
- # Authenticate with your Bagdock account
116
+ # Authenticate
33
117
  bagdock login
34
118
 
119
+ # Check your environment
120
+ bagdock doctor
121
+
35
122
  # Scaffold a new project
36
123
  bagdock init
37
124
 
@@ -50,34 +137,505 @@ bagdock deploy
50
137
 
51
138
  Both deploy to the Bagdock platform via the CLI. You don't need to manage any infrastructure.
52
139
 
140
+ ## Authentication
141
+
142
+ The CLI resolves your API key using the following priority chain:
143
+
144
+ | Priority | Source | How to set |
145
+ |----------|--------|-----------|
146
+ | 1 (highest) | `--api-key` flag | `bagdock --api-key sk_live_xxx deploy ...` |
147
+ | 2 | `BAGDOCK_API_KEY` env var | `export BAGDOCK_API_KEY=sk_live_xxx` |
148
+ | 3 | `BAGDOCK_TOKEN` env var | `export BAGDOCK_TOKEN=<jwt>` |
149
+ | 4 (lowest) | Config file | `bagdock login` |
150
+
151
+ If no key is found from any source, the CLI errors with code `auth_error`.
152
+
53
153
  ## Commands
54
154
 
55
- | Command | Description |
56
- |---------|-------------|
57
- | `bagdock login` | Authenticate via Device Authorization Grant (opens browser) |
58
- | `bagdock logout` | Clear stored credentials |
59
- | `bagdock whoami` | Show current authenticated user |
60
- | `bagdock init` | Scaffold a new project with `bagdock.json` |
61
- | `bagdock dev` | Start local dev server |
62
- | `bagdock deploy` | Build and deploy to Bagdock |
63
- | `bagdock env set` | Set an environment variable for your project |
64
- | `bagdock env list` | List environment variables |
65
- | `bagdock submit` | Submit for marketplace review |
155
+ ### `bagdock login`
66
156
 
67
- ## Authentication
157
+ Authenticate by starting an OAuth 2.0 Device Authorization Grant flow. The CLI opens your browser to the Bagdock dashboard where you approve access.
158
+
159
+ #### Interactive mode (default in terminals)
160
+
161
+ When run in a terminal, the CLI:
162
+
163
+ 1. Requests a device code from the API
164
+ 2. Displays a one-time code and opens your browser
165
+ 3. Waits for you to enter the code and approve
166
+ 4. Stores credentials at `~/.bagdock/credentials.json`
167
+
168
+ #### Non-interactive mode (CI, pipes, scripts)
169
+
170
+ For headless environments, use an API key instead of interactive login:
171
+
172
+ ```bash
173
+ export BAGDOCK_API_KEY=sk_live_xxx
174
+ bagdock deploy --production --yes
175
+ ```
176
+
177
+ #### Output
178
+
179
+ ```bash
180
+ # JSON output
181
+ bagdock login --json
182
+ # => {"success":true,"config_path":"/Users/you/.bagdock/credentials.json","profile":"default"}
183
+ ```
184
+
185
+ #### Error codes
186
+
187
+ | Code | Cause |
188
+ |------|-------|
189
+ | `auth_error` | Device code request failed |
190
+ | `expired_token` | Device code expired before approval |
191
+ | `access_denied` | User denied authorization |
192
+
193
+ ---
194
+
195
+ ### `bagdock logout`
196
+
197
+ Clear stored credentials for the active profile.
198
+
199
+ ```bash
200
+ bagdock logout
201
+ ```
202
+
203
+ ---
204
+
205
+ ### `bagdock whoami`
206
+
207
+ Show the current authenticated user.
208
+
209
+ ```bash
210
+ bagdock whoami
211
+ # => Logged in as you@example.com
212
+ # Operator: op_abc123
213
+ # Profile: default
214
+ ```
215
+
216
+ JSON output:
217
+
218
+ ```bash
219
+ bagdock whoami --json
220
+ # => {"email":"you@example.com","operator_id":"op_abc123","profile":"default"}
221
+ ```
222
+
223
+ ---
224
+
225
+ ### `bagdock doctor`
226
+
227
+ Run environment diagnostics. Verifies your CLI version, API key, project config, and detects AI agent integrations.
228
+
229
+ ```bash
230
+ bagdock doctor
231
+ ```
232
+
233
+ #### Checks performed
234
+
235
+ | Check | Pass | Warn | Fail |
236
+ |-------|------|------|------|
237
+ | CLI Version | Running latest | Update available or registry unreachable | — |
238
+ | API Key | Key found (shows masked key + source) | — | No key found |
239
+ | Project Config | Valid `bagdock.json` found | No config or incomplete | — |
240
+ | AI Agents | Lists detected agents (or none) | — | — |
241
+
242
+ The API key is always masked in output (e.g. `sk_live_...xxxx`).
243
+
244
+ #### Interactive mode
245
+
246
+ Shows status icons with colored output:
247
+
248
+ ```
249
+ Bagdock Doctor
250
+
251
+ ✔ CLI Version: v0.3.0 (latest)
252
+ ✔ API Key: sk_live_...xxxx (source: env)
253
+ ✔ Project Config: smart-entry (edge/adapter)
254
+ ✔ AI Agents: Detected: Cursor, Claude Desktop
255
+ ```
256
+
257
+ #### JSON mode
258
+
259
+ ```bash
260
+ bagdock doctor --json
261
+ ```
262
+
263
+ ```json
264
+ {
265
+ "ok": true,
266
+ "checks": [
267
+ { "name": "CLI Version", "status": "pass", "message": "v0.3.0 (latest)" },
268
+ { "name": "API Key", "status": "pass", "message": "sk_live_...xxxx (source: env)" },
269
+ { "name": "Project Config", "status": "pass", "message": "smart-entry (edge/adapter)" },
270
+ { "name": "AI Agents", "status": "pass", "message": "Detected: Cursor" }
271
+ ]
272
+ }
273
+ ```
274
+
275
+ Each check has a `status` of `pass`, `warn`, or `fail`. The top-level `ok` is `false` if any check is `fail`.
276
+
277
+ #### Detected AI agents
278
+
279
+ | Agent | Detection method |
280
+ |-------|-----------------|
281
+ | Cursor | `~/.cursor` directory exists |
282
+ | Claude Desktop | Platform-specific config file exists |
283
+ | VS Code | `.vscode/mcp.json` in current directory |
284
+ | Windsurf | `~/.windsurf` directory exists |
285
+ | OpenClaw/Codex | `~/clawd/skills` or `~/.codex` directory exists |
286
+
287
+ #### Exit code
288
+
289
+ Exits `0` when all checks pass or warn. Exits `1` if any check fails.
290
+
291
+ ---
292
+
293
+ ### Switch between profiles
294
+
295
+ If you work across multiple Bagdock operators, the CLI supports named profiles.
296
+
297
+ #### List profiles
298
+
299
+ ```bash
300
+ bagdock auth list
301
+ ```
302
+
303
+ #### Switch active profile
304
+
305
+ ```bash
306
+ bagdock auth switch production
307
+ ```
308
+
309
+ You can also use the global `--profile` (or `-p`) flag on any command to run it with a specific profile:
310
+
311
+ ```bash
312
+ bagdock --profile production deploy --yes
313
+ bagdock -p staging keys list
314
+ ```
315
+
316
+ ---
317
+
318
+ ### `bagdock init [dir]`
319
+
320
+ Scaffold a new project with a `bagdock.json` config file.
68
321
 
69
- The CLI uses the OAuth 2.0 Device Authorization Grant. When you run `bagdock login`, it will:
322
+ | Flag | Description |
323
+ |------|-------------|
324
+ | `--type <edge\|app>` | Deployment target |
325
+ | `--kind <adapter\|comms\|webhook\|ui-extension\|microfrontend>` | Specific project kind |
326
+ | `--category <name>` | Marketplace category |
327
+ | `--slug <name>` | Unique project slug (kebab-case) |
328
+ | `--name <name>` | Display name |
70
329
 
71
- 1. Display a one-time code
72
- 2. Open your browser to the Bagdock dashboard
73
- 3. Ask you to enter the code and approve access
74
- 4. Store credentials locally at `~/.bagdock/credentials.json`
330
+ #### Examples
331
+
332
+ ```bash
333
+ # Interactive scaffolding
334
+ bagdock init
335
+
336
+ # Non-interactive
337
+ bagdock init --type edge --kind adapter --category access_control --slug smart-entry --name "Smart Entry"
338
+ ```
339
+
340
+ ---
341
+
342
+ ### `bagdock deploy`
343
+
344
+ Build and deploy to the Bagdock platform.
345
+
346
+ | Flag | Description |
347
+ |------|-------------|
348
+ | `--production` | Deploy to production (default: staging) |
349
+ | `--preview` | Create an ephemeral preview deployment |
350
+ | `--yes` | Skip confirmation prompts (required in non-TTY) |
351
+
352
+ #### Examples
353
+
354
+ ```bash
355
+ # Deploy to staging
356
+ bagdock deploy
357
+
358
+ # Deploy to production
359
+ bagdock deploy --production --yes
360
+
361
+ # Preview deployment
362
+ bagdock deploy --preview --json
363
+ ```
364
+
365
+ #### Error codes
366
+
367
+ | Code | Cause |
368
+ |------|-------|
369
+ | `auth_error` | Not authenticated |
370
+ | `no_config` | No `bagdock.json` found |
371
+ | `build_error` | Build failed |
372
+ | `deploy_error` | API rejected the deployment |
373
+
374
+ ---
375
+
376
+ ### `bagdock submit`
377
+
378
+ Submit your app for marketplace review. Transitions `review_status` from `draft` to `submitted`.
379
+
380
+ ```bash
381
+ bagdock submit
382
+ ```
383
+
384
+ ---
385
+
386
+ ### `bagdock env list`
387
+
388
+ List environment variables for the current app.
389
+
390
+ ```bash
391
+ bagdock env list
392
+ bagdock env list --json
393
+ ```
394
+
395
+ ### `bagdock env set <key> <value>`
396
+
397
+ Set an environment variable. Takes effect on next deploy.
398
+
399
+ ```bash
400
+ bagdock env set VENDOR_API_KEY sk_live_abc123
401
+ ```
402
+
403
+ ### `bagdock env remove <key>`
404
+
405
+ Remove an environment variable.
406
+
407
+ ```bash
408
+ bagdock env remove VENDOR_API_KEY
409
+ ```
410
+
411
+ ---
412
+
413
+ ### `bagdock keys create`
414
+
415
+ Create a new API key. The raw key is shown **once** on creation.
416
+
417
+ | Flag | Required | Description |
418
+ |------|----------|-------------|
419
+ | `--name <name>` | Yes | Display name for the key |
420
+ | `--environment <live\|test>` | No | Environment (default: `live`) |
421
+ | `--type <secret\|publishable>` | No | Key type (default: `secret`) |
422
+ | `--category <full_access\|restricted>` | No | Access level (default: `full_access`) |
423
+ | `--scopes <scope...>` | No | Permission scopes (for restricted keys) |
424
+
425
+ #### Examples
426
+
427
+ ```bash
428
+ # Create a live secret key
429
+ bagdock keys create --name "GitHub Actions" --environment live
430
+
431
+ # Create a restricted test key
432
+ bagdock keys create --name "Read-Only" --environment test --category restricted --scopes units:read contacts:read
433
+
434
+ # JSON output (capture the raw key)
435
+ bagdock keys create --name "CI Deploy" --json
436
+ ```
437
+
438
+ #### Output
439
+
440
+ ```json
441
+ {
442
+ "id": "ak_abc123",
443
+ "name": "CI Deploy",
444
+ "key": "sk_live_abc123def456...",
445
+ "key_prefix": "sk_live_abc123de",
446
+ "environment": "live",
447
+ "key_type": "secret",
448
+ "created_at": "2026-04-04T12:00:00Z"
449
+ }
450
+ ```
451
+
452
+ ### `bagdock keys list`
453
+
454
+ List API keys (prefix and metadata only — raw keys are never stored).
455
+
456
+ | Flag | Description |
457
+ |------|-------------|
458
+ | `--environment <live\|test>` | Filter by environment |
459
+
460
+ ```bash
461
+ bagdock keys list
462
+ bagdock keys list --environment live --json
463
+ ```
464
+
465
+ ### `bagdock keys delete <id>`
466
+
467
+ Revoke an API key permanently.
468
+
469
+ | Flag | Description |
470
+ |------|-------------|
471
+ | `--yes` | Skip confirmation (required in non-TTY) |
472
+ | `--reason <text>` | Reason for revocation (optional, recorded) |
473
+
474
+ ```bash
475
+ bagdock keys delete ak_abc123 --yes --reason "Key compromised"
476
+ ```
477
+
478
+ #### Error codes
479
+
480
+ | Code | Cause |
481
+ |------|-------|
482
+ | `auth_error` | Not authenticated |
483
+ | `not_found` | Key ID does not exist |
484
+ | `forbidden` | Insufficient permissions |
485
+
486
+ ---
487
+
488
+ ### `bagdock apps list`
489
+
490
+ List deployed apps and edges.
491
+
492
+ ```bash
493
+ bagdock apps list
494
+ bagdock apps list --json
495
+ ```
496
+
497
+ ### `bagdock apps get <slug>`
498
+
499
+ Get details for a specific deployed app.
500
+
501
+ ```bash
502
+ bagdock apps get smart-entry
503
+ bagdock apps get smart-entry --json
504
+ ```
505
+
506
+ ---
507
+
508
+ ### `bagdock logs list`
509
+
510
+ List recent execution log entries.
511
+
512
+ | Flag | Description |
513
+ |------|-------------|
514
+ | `--app <slug>` | Filter by app slug |
515
+ | `--limit <n>` | Number of entries (default: 50, max: 200) |
516
+
517
+ ```bash
518
+ bagdock logs list --app smart-entry --limit 20
519
+ ```
520
+
521
+ ### `bagdock logs tail`
522
+
523
+ Stream logs in real-time.
524
+
525
+ | Flag | Description |
526
+ |------|-------------|
527
+ | `--app <slug>` | App to stream logs for |
528
+
529
+ ```bash
530
+ bagdock logs tail --app smart-entry
531
+ ```
532
+
533
+ ### `bagdock logs get <id>`
534
+
535
+ Get a single log entry by ID.
536
+
537
+ | Flag | Description |
538
+ |------|-------------|
539
+ | `--app <slug>` | App the log belongs to |
540
+
541
+ ```bash
542
+ bagdock logs get log_abc123 --app smart-entry
543
+ ```
544
+
545
+ ---
546
+
547
+ ## Global options
548
+
549
+ These flags work on every command and are passed before the subcommand:
550
+
551
+ ```
552
+ bagdock [global options] <command> [command options]
553
+ ```
554
+
555
+ | Flag | Description |
556
+ |------|-------------|
557
+ | `--api-key <key>` | Override API key for this invocation (takes highest priority) |
558
+ | `-p, --profile <name>` | Profile to use (overrides `BAGDOCK_PROFILE` env var) |
559
+ | `--json` | Force JSON output even in interactive terminals |
560
+ | `-q, --quiet` | Suppress spinners and status output (implies `--json`) |
561
+ | `--version` | Print version and exit |
562
+ | `--help` | Show help text |
563
+
564
+ ## Output behavior
565
+
566
+ The CLI has two output modes:
567
+
568
+ | Mode | When | Stdout | Stderr |
569
+ |------|------|--------|--------|
570
+ | Interactive | Terminal (TTY) | Formatted text | Spinners, prompts |
571
+ | Machine | Piped, CI, or `--json` | JSON | Nothing |
572
+
573
+ Switching is automatic — pipe to another command and JSON output activates:
574
+
575
+ ```bash
576
+ bagdock doctor | jq '.checks[].name'
577
+ bagdock keys list | jq '.[].key_prefix'
578
+ ```
579
+
580
+ ### Error output
581
+
582
+ Errors always exit with code `1` and output structured JSON to stdout:
583
+
584
+ ```json
585
+ { "error": { "code": "auth_error", "message": "No API key found" } }
586
+ ```
587
+
588
+ ## API keys
589
+
590
+ API keys follow a Stripe-style prefix convention:
591
+
592
+ | Prefix | Meaning |
593
+ |--------|---------|
594
+ | `sk_live_` | Secret key, live environment |
595
+ | `sk_test_` | Secret key, test/sandbox environment |
596
+ | `pk_live_` | Publishable key, live |
597
+ | `pk_test_` | Publishable key, test |
598
+ | `rk_live_` | Restricted key, live |
599
+ | `rk_test_` | Restricted key, test |
600
+
601
+ The raw key is shown **once** on creation. Only the prefix and metadata are stored and displayed after that.
602
+
603
+ ## Agent & CI/CD usage
604
+
605
+ ### CI/CD
606
+
607
+ Set `BAGDOCK_API_KEY` as an environment variable — no `bagdock login` needed:
608
+
609
+ ```yaml
610
+ # GitHub Actions
611
+ env:
612
+ BAGDOCK_API_KEY: ${{ secrets.BAGDOCK_API_KEY }}
613
+ steps:
614
+ - run: |
615
+ bagdock deploy --production --yes --json
616
+ ```
617
+
618
+ ### AI agents
619
+
620
+ Agents calling the CLI as a subprocess automatically get JSON output (non-TTY detection). The contract:
621
+
622
+ - **Input**: All required flags must be provided (no interactive prompts)
623
+ - **Output**: JSON to stdout, nothing to stderr
624
+ - **Exit code**: `0` success, `1` error
625
+ - **Errors**: Always include `message` and `code` fields
75
626
 
76
627
  ## Configuration
77
628
 
78
- Each project uses a `bagdock.json` file. All config lives here — no `wrangler.toml` needed. A temporary one is auto-generated for local dev and should be gitignored.
629
+ | Item | Path | Notes |
630
+ |------|------|-------|
631
+ | Config directory | `~/.bagdock/` | Respects `BAGDOCK_INSTALL` |
632
+ | Credentials | `~/.bagdock/credentials.json` | `0600` permissions (owner read/write) |
633
+ | Active profile | Stored in credentials file | Overridden by `--profile` or `BAGDOCK_PROFILE` |
634
+ | Project config | `./bagdock.json` | Per-project, in repo root |
635
+
636
+ ### bagdock.json examples
79
637
 
80
- ### Edge example
638
+ #### Edge (backend worker)
81
639
 
82
640
  ```json
83
641
  {
@@ -90,7 +648,7 @@ Each project uses a `bagdock.json` file. All config lives here — no `wrangler.
90
648
  }
91
649
  ```
92
650
 
93
- ### App example
651
+ #### App (UI extension)
94
652
 
95
653
  ```json
96
654
  {