@celilo/cli 0.8.1 → 0.8.2

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 (4) hide show
  1. package/AGENTS.md +94 -0
  2. package/CLI_USAGE.md +433 -0
  3. package/README.md +48 -1539
  4. package/package.json +4 -2
package/AGENTS.md ADDED
@@ -0,0 +1,94 @@
1
+ # AGENTS.md — `@celilo/cli`
2
+
3
+ Celilo is a **home-lab orchestration system**: you describe infrastructure as
4
+ **modules**, and celilo deploys them onto a fleet (Proxmox LXC/VM) and wires them
5
+ together through versioned **capabilities**. This file orients an AI agent to
6
+ build and ship apps on celilo. **Read the local docs below before searching the
7
+ web** — they are the source of truth; the hosted copies at
8
+ `https://celilo.computer/docs` lag them.
9
+
10
+ This file ships **inside the npm package**: the `./`-prefixed docs in the doc map
11
+ are installed alongside it (grep them offline). The repo-relative entries point
12
+ at the source repository / hosted docs, which the tarball does not carry.
13
+
14
+ ## Mental model (learn these five things)
15
+
16
+ - **Module** — a directory with a `manifest.yml` and `celilo/scripts/` hooks,
17
+ packaged into a `.netapp` artifact and published to **celilo-registry**.
18
+ Everything celilo deploys is a module.
19
+ - **Capability** — a module `provides:` capabilities (e.g. `public_web`, `idp`,
20
+ `source_forge`) at a **versioned contract**, and consumers `requires:` them.
21
+ Consumers bind to the **capability** version (`provides.capabilities[].version`)
22
+ — *not* the module's own `version`. Bump the capability version on a contract
23
+ change; that's the load-bearing semver.
24
+ - **Hook** — a lifecycle script (`on_install`, `health_check`, `on_backup`, …) in
25
+ `celilo/scripts/`, written with `defineHook(...)` from `@celilo/capabilities`.
26
+ Hooks receive typed clients for the capabilities they `requires`/`optional`.
27
+ - **Build bus** — app repo CI publishes a `.netapp` to celilo-registry →
28
+ celilo-mgr **polls** → `module upgrade` → deploy → verify. No manual hop.
29
+ - **Versioning** — `manifest.yml#version` is the **payload** version; `+N` is the
30
+ recipe revision; `version_source` declares how the version is set. See below.
31
+
32
+ ## Building an app (the happy path)
33
+
34
+ An **app** is a module that provides no capability (it serves content), so set
35
+ `version_source: { kind: changeset }`.
36
+
37
+ 1. **`manifest.yml`** — `id` (kebab-case), `celilo_contract: "1.0"`, `version`,
38
+ the capabilities you `requires:` (e.g. `public_web`, `idp`), `variables`,
39
+ `hooks`, and `version_source`. Keep the schema directive on line 1 so your
40
+ editor validates:
41
+ `# yaml-language-server: $schema=../../schemas/module-manifest.schema.json`
42
+ 2. **Hooks** in `celilo/scripts/` — at least `on_install` (provision) and
43
+ `health_check`. Use `defineHook`; required capabilities are typed non-null.
44
+ 3. **CI/CD** — copy the reference workflows + add the `register-forge` deploy
45
+ hook so your repo gets a scoped publish token (see `APP_CI_REFERENCE.md`).
46
+ 4. **Version with changesets** — `celilo module changeset --bump <major|minor|
47
+ patch>` in each behaviour-changing PR; `celilo module version` stamps
48
+ `manifest.yml#version` + CHANGELOG at release. Pick the bump by deploy **blast
49
+ radius** (major ⇒ safe deploy w/ backup; patch ⇒ fast).
50
+ 5. **Ship** — `celilo module check .` then `celilo module publish .`. On the
51
+ fleet: `module update` (registry sweep) → `module deploy <id>` → `module
52
+ health`.
53
+
54
+ ## CLI you'll use
55
+
56
+ ```
57
+ celilo module import <name|path> # pull a module
58
+ celilo module check [dir] # validate: schema, capabilities, git-hygiene
59
+ celilo module changeset --bump <b> -m … # author a version changeset (module-id keyed)
60
+ celilo module version [dir] # stamp version+CHANGELOG from changesets
61
+ celilo module publish [dir] # build .netapp + publish to celilo-registry
62
+ celilo module deploy <id> / update / health # deploy + verify on the fleet
63
+ ```
64
+
65
+ ## Conventions / rules
66
+
67
+ - Module `id` is **kebab-case**; pin `celilo_contract: "1.0"`.
68
+ - **`version_source`** picks how `version` is sourced: `changeset` (apps/content —
69
+ authored via changesets, ordered by `+N`), `pin` (wraps upstream software —
70
+ `version` = the installed upstream version, resolver-checked), `recipe`
71
+ (config-only modules — no payload version; `+N` orders). Default `recipe`.
72
+ - The capability **contract** semver lives in `provides.capabilities[].version`,
73
+ independent of the module `version`. Don't conflate them.
74
+ - **Never hand-edit `schemas/module-manifest.schema.json`** — it's generated from
75
+ `src/manifest/schema.ts` via `bun run export:schema`.
76
+ - Validate before publishing; `celilo module check` mirrors the publish gates.
77
+
78
+ ## Doc map (read in this order)
79
+
80
+ Shipped **inside this package** (offline, grep-friendly):
81
+
82
+ - `./CLI_USAGE.md` — full CLI reference + common workflows.
83
+ - `./schemas/system_config.json` — the system-config contract.
84
+ - `./src/manifest/schema.ts` — Zod source of the manifest schema (the published
85
+ `module-manifest.schema.json` is generated from it via `bun run export:schema`).
86
+
87
+ In the **source repo / hosted docs** (not carried in the tarball):
88
+
89
+ - `design/MODULE_DEVELOPMENT_GUIDE.md` — author a module (start here).
90
+ - `v2/BUILD_BUS.md` — how a change reaches the fleet.
91
+ - `v2/APP_CI_REFERENCE.md` — wire an app's CI/CD (the copy-me recipe).
92
+ - `v2/MODULE_VERSIONING.md` — what `version` means; `version_source`.
93
+ - `schemas/module-manifest.schema.json` — the manifest contract.
94
+ - `https://celilo.computer/docs` — hosted docs (LAN; the repo docs lead).
package/CLI_USAGE.md ADDED
@@ -0,0 +1,433 @@
1
+ # Celilo CLI Usage Guide
2
+
3
+ Common workflows and command patterns for the Celilo CLI.
4
+
5
+ ## Quick Reference
6
+
7
+ ```bash
8
+ # Import and setup
9
+ celilo module import <path>
10
+ celilo system config set <key> <value>
11
+ celilo module config set <module> <key> <value>
12
+ celilo secret set <module> <name> <value>
13
+ celilo module generate <module>
14
+
15
+ # Query and inspect
16
+ celilo module list
17
+ celilo module config get <module>
18
+ celilo system config get [key]
19
+ celilo system vault-password
20
+
21
+ # Manage
22
+ celilo module remove <module>
23
+ celilo help
24
+ ```
25
+
26
+ ## Common Workflows
27
+
28
+ ### 1. Setting Up a New Module
29
+
30
+ ```bash
31
+ # Step 1: Import the module
32
+ ./celilo module import modules/homebridge
33
+ # Output: Successfully imported module: homebridge
34
+ # Files copied to: /tmp/celilo/modules/homebridge
35
+
36
+ # Step 2: Configure system-wide settings (if not already set)
37
+ ./celilo system config set dns.primary 192.168.0.1
38
+ ./celilo system config set dns.fallback "8.8.8.8 1.1.1.1"
39
+ ./celilo system config set routing.internal_gateway 192.168.0.254
40
+
41
+ # Step 3: Configure module-specific settings
42
+ ./celilo module config set homebridge vmid 2110
43
+ ./celilo module config set homebridge hostname iot
44
+ ./celilo module config set homebridge container_ip "192.168.0.110/24"
45
+ ./celilo module config set homebridge gateway 192.168.0.254
46
+ ./celilo module config set homebridge vlan 192
47
+ ./celilo module config set homebridge cores 2
48
+ ./celilo module config set homebridge memory 2048
49
+ ./celilo module config set homebridge storage datacenter
50
+ ./celilo module config set homebridge rootfs_size 20G
51
+
52
+ # Step 4: Set secrets
53
+ ./celilo secret set homebridge api_key "your_api_key_here"
54
+ ./celilo secret set homebridge db_password "your_password_here"
55
+
56
+ # Step 5: Generate infrastructure code
57
+ ./celilo module generate homebridge
58
+ # Output: Successfully generated 8 files:
59
+ # - terraform/main.tf
60
+ # - terraform/variables.tf
61
+ # - ...
62
+
63
+ # Step 6: Review generated files
64
+ ls -la /tmp/celilo/modules/homebridge/generated/
65
+ cd /tmp/celilo/modules/homebridge/generated/
66
+ ```
67
+
68
+ ### 2. Inspecting Configuration
69
+
70
+ ```bash
71
+ # List all modules
72
+ ./celilo module list
73
+
74
+ # Get all config for a module
75
+ ./celilo module config get homebridge
76
+
77
+ # Get specific config value
78
+ ./celilo module config get homebridge hostname
79
+
80
+ # Get all system config
81
+ ./celilo system config get
82
+
83
+ # Get specific system config
84
+ ./celilo system config get dns.primary
85
+ ```
86
+
87
+ ### 3. Working with Secrets
88
+
89
+ ```bash
90
+ # Set a secret
91
+ ./celilo secret set homebridge api_key "secret_value"
92
+
93
+ # View encrypted secrets file
94
+ MODULE=homebridge
95
+ SECRETS_FILE=/tmp/celilo/modules/$MODULE/generated/ansible/inventory/secrets.yml
96
+
97
+ # Check it's encrypted
98
+ head -1 $SECRETS_FILE
99
+ # Should show: $ANSIBLE_VAULT;1.1;AES256
100
+
101
+ # Decrypt and view
102
+ ansible-vault view $SECRETS_FILE \
103
+ --vault-password-file=<(./celilo system vault-password)
104
+
105
+ # Edit encrypted secrets directly (if needed)
106
+ ansible-vault edit $SECRETS_FILE \
107
+ --vault-password-file=<(./celilo system vault-password)
108
+ ```
109
+
110
+ ### 4. Regenerating After Changes
111
+
112
+ ```bash
113
+ # Change configuration
114
+ ./celilo module config set homebridge cores 4
115
+ ./celilo module config set homebridge memory 4096
116
+
117
+ # Regenerate
118
+ ./celilo module generate homebridge
119
+
120
+ # Generated files will reflect new configuration
121
+ ```
122
+
123
+ ### 5. Removing a Module
124
+
125
+ ```bash
126
+ # Remove module (cascade deletes all config and secrets)
127
+ ./celilo module remove homebridge
128
+
129
+ # Verify removal
130
+ ./celilo module list
131
+ # Should no longer show homebridge
132
+
133
+ # Manually clean up generated files if needed
134
+ rm -rf /tmp/celilo/modules/homebridge/
135
+ ```
136
+
137
+ ### 6. Using Generated Infrastructure
138
+
139
+ ```bash
140
+ # Terraform workflow
141
+ cd /tmp/celilo/modules/homebridge/generated/terraform
142
+ terraform init
143
+ terraform plan
144
+ terraform apply
145
+
146
+ # Ansible workflow
147
+ cd /tmp/celilo/modules/homebridge/generated/ansible
148
+ ansible-playbook playbook.yml \
149
+ -i inventory/ \
150
+ --vault-password-file=<(celilo system vault-password)
151
+ ```
152
+
153
+ ## Advanced Usage
154
+
155
+ ### Running from Different Directories
156
+
157
+ ```bash
158
+ # From anywhere (using wrapper script)
159
+ /path/to/celilo/celilo module list
160
+
161
+ # From backend directory (using bun)
162
+ cd /path/to/celilo/backend
163
+ bun run src/cli/index.ts module list
164
+
165
+ # From backend directory (using npm script)
166
+ cd /path/to/celilo/backend
167
+ bun run dev -- module list
168
+ ```
169
+
170
+ ### Custom Database Location
171
+
172
+ ```bash
173
+ # Set environment variable
174
+ export CELILO_DB_PATH=/custom/path/celilo.db
175
+
176
+ # Run migrations
177
+ bun run db:migrate
178
+
179
+ # Use CLI (will use custom database)
180
+ ./celilo module list
181
+ ```
182
+
183
+ ### Custom Output Directory
184
+
185
+ ```bash
186
+ # Generate to specific location
187
+ ./celilo module generate homebridge --output /custom/output/path
188
+ ```
189
+
190
+ ### Scripting with Celilo
191
+
192
+ ```bash
193
+ #!/bin/bash
194
+ # Example: setup-homebridge.sh
195
+
196
+ set -e # Exit on error
197
+
198
+ MODULE=homebridge
199
+
200
+ # Import module
201
+ ./celilo module import "modules/$MODULE"
202
+
203
+ # Configure system
204
+ ./celilo system config set dns.primary 192.168.0.1
205
+ ./celilo system config set routing.internal_gateway 192.168.0.254
206
+
207
+ # Configure module (read from config file or environment)
208
+ ./celilo module config set $MODULE vmid "${VMID}"
209
+ ./celilo module config set $MODULE hostname "${HOSTNAME}"
210
+ ./celilo module config set $MODULE container_ip "${CONTAINER_IP}"
211
+
212
+ # Set secrets (from secure source)
213
+ ./celilo secret set $MODULE api_key "${API_KEY}"
214
+
215
+ # Generate
216
+ ./celilo module generate $MODULE
217
+
218
+ echo "Setup complete! Generated files at:"
219
+ echo " /tmp/celilo/modules/$MODULE/generated/"
220
+ ```
221
+
222
+ ### Debugging
223
+
224
+ ```bash
225
+ # Check if module was imported correctly
226
+ ./celilo module list
227
+
228
+ # Verify configuration
229
+ ./celilo module config get homebridge
230
+
231
+ # Check database directly
232
+ sqlite3 celilo.db "SELECT * FROM modules;"
233
+ sqlite3 celilo.db "SELECT * FROM module_configs WHERE module_id='homebridge';"
234
+
235
+ # View encrypted secrets (verify they're not plaintext)
236
+ sqlite3 celilo.db "SELECT name, substr(encrypted_value, 1, 20) || '...' AS encrypted FROM secrets WHERE module_id='homebridge';"
237
+
238
+ # Check generated files exist
239
+ ls -la /tmp/celilo/modules/homebridge/generated/
240
+
241
+ # Validate generated Terraform
242
+ cd /tmp/celilo/modules/homebridge/generated/terraform
243
+ terraform fmt -check
244
+ terraform validate
245
+ ```
246
+
247
+ ## Common Patterns
248
+
249
+ ### Bulk Configuration
250
+
251
+ ```bash
252
+ # Set multiple values in sequence
253
+ for key in vmid hostname container_ip gateway vlan cores memory storage; do
254
+ ./celilo module config set homebridge $key "${!key}"
255
+ done
256
+ ```
257
+
258
+ ### Configuration from File
259
+
260
+ ```bash
261
+ # Read config from YAML/JSON and apply
262
+ # Example config.yml:
263
+ # homebridge:
264
+ # vmid: 2110
265
+ # hostname: iot
266
+ # ...
267
+
268
+ # Using yq or jq
269
+ while IFS='=' read -r key value; do
270
+ ./celilo module config set homebridge "$key" "$value"
271
+ done < <(yq eval '.homebridge | to_entries | .[] | .key + "=" + (.value | tostring)' config.yml)
272
+ ```
273
+
274
+ ### Export Configuration
275
+
276
+ ```bash
277
+ # Export all config for a module
278
+ ./celilo module config get homebridge > homebridge-config.txt
279
+
280
+ # Export system config
281
+ ./celilo system config get > system-config.txt
282
+ ```
283
+
284
+ ### Validate Before Generate
285
+
286
+ ```bash
287
+ # Check all required config is set
288
+ REQUIRED_KEYS="vmid hostname container_ip gateway vlan"
289
+
290
+ for key in $REQUIRED_KEYS; do
291
+ if ! ./celilo module config get homebridge $key &>/dev/null; then
292
+ echo "ERROR: Missing required config: $key"
293
+ exit 1
294
+ fi
295
+ done
296
+
297
+ # All required config present, generate
298
+ ./celilo module generate homebridge
299
+ ```
300
+
301
+ ## Tips & Tricks
302
+
303
+ ### 1. Use Absolute Paths for Module Import
304
+
305
+ ```bash
306
+ # Relative path (preferred - works from celilo root)
307
+ ./celilo module import ../modules/homebridge
308
+
309
+ # Absolute path (use your actual path)
310
+ ./celilo module import /path/to/celilo/modules/homebridge
311
+ ```
312
+
313
+ The wrapper script handles relative path conversion automatically for `module import`.
314
+
315
+ ### 2. Quote Values with Spaces or Special Characters
316
+
317
+ ```bash
318
+ # Correct
319
+ ./celilo module config set homebridge bridge_name "Home Bridge"
320
+ ./celilo system config set dns.fallback "8.8.8.8 1.1.1.1"
321
+
322
+ # Wrong (will only set first word)
323
+ ./celilo module config set homebridge bridge_name Home Bridge
324
+ ```
325
+
326
+ ### 3. Store Vault Password Securely
327
+
328
+ ```bash
329
+ # DO NOT store vault password in plain files
330
+ # BAD: echo "password" > vault-pass.txt
331
+
332
+ # GOOD: Use celilo CLI with process substitution
333
+ ansible-vault view secrets.yml \
334
+ --vault-password-file=<(./celilo system vault-password)
335
+
336
+ # GOOD: Export to environment (for scripts)
337
+ export ANSIBLE_VAULT_PASSWORD=$(./celilo system vault-password)
338
+ ```
339
+
340
+ ### 4. Check Help for Any Command
341
+
342
+ ```bash
343
+ ./celilo help # General help
344
+ ./celilo module --help # Module command help
345
+ ./celilo module config --help # Config subcommand help (shows same general help)
346
+ ```
347
+
348
+ ### 5. Validate Manifests Before Import
349
+
350
+ ```bash
351
+ # Module imports will validate automatically, but you can check manually
352
+ cd backend
353
+ bun run src/cli/index.ts module import ../modules/homebridge
354
+ # Look for validation error messages
355
+ ```
356
+
357
+ ## Troubleshooting
358
+
359
+ ### "Module not found" After Import
360
+
361
+ **Check import succeeded**:
362
+ ```bash
363
+ ./celilo module list
364
+ ```
365
+
366
+ **Verify files copied**:
367
+ ```bash
368
+ ls -la /tmp/celilo/modules/homebridge/
369
+ ```
370
+
371
+ **Check database**:
372
+ ```bash
373
+ sqlite3 celilo.db "SELECT id, name, state FROM modules;"
374
+ ```
375
+
376
+ ### "Variable not found" During Generate
377
+
378
+ **Check configuration is set**:
379
+ ```bash
380
+ ./celilo module config get homebridge
381
+ ```
382
+
383
+ **Check system config**:
384
+ ```bash
385
+ ./celilo system config get
386
+ ```
387
+
388
+ **Identify missing variables**:
389
+ ```bash
390
+ # Error message will show which variables are missing:
391
+ # Error: Failed to resolve variables in templates:
392
+ # terraform/main.tf:
393
+ # $self:cores: Self variable 'cores' not found in module configuration
394
+ ```
395
+
396
+ Set the missing config and regenerate.
397
+
398
+ ### "Failed to generate Ansible secrets"
399
+
400
+ **Check Ansible is installed**:
401
+ ```bash
402
+ ansible-vault --version
403
+ ```
404
+
405
+ **If Ansible is missing**:
406
+ ```bash
407
+ # macOS
408
+ brew install ansible
409
+
410
+ # Ubuntu/Debian
411
+ sudo apt-get install ansible
412
+ ```
413
+
414
+ ### Generated Files Not Where Expected
415
+
416
+ **Default location**: `/tmp/celilo/modules/<module-id>/generated/`
417
+
418
+ **Custom location**:
419
+ ```bash
420
+ ./celilo module generate homebridge --output /custom/path
421
+ ```
422
+
423
+ **Check generation output**:
424
+ ```bash
425
+ ./celilo module generate homebridge
426
+ # Output shows: "Output: /tmp/celilo/modules/homebridge/generated"
427
+ ```
428
+
429
+ ## Next Steps
430
+
431
+ - Read [INTEGRATION_TESTS.md](backend/INTEGRATION_TESTS.md) for testing workflows
432
+ - Read [backend/README.md](backend/README.md) for architecture details
433
+ - Check [SETUP.md](SETUP.md) for installation and setup guides