@celilo/cli 0.8.2 → 0.9.1

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 (46) hide show
  1. package/AGENTS.md +10 -18
  2. package/CELILO_CORE_MODULES.md +61 -0
  3. package/CELILO_SUBSYSTEMS.md +83 -0
  4. package/README.md +1539 -48
  5. package/drizzle/0012_module_systems_sizing.sql +3 -0
  6. package/drizzle/0013_dns_view_overrides.sql +1 -0
  7. package/drizzle/meta/_journal.json +15 -1
  8. package/package.json +5 -10
  9. package/src/capabilities/well-known.test.ts +12 -66
  10. package/src/capabilities/well-known.ts +11 -12
  11. package/src/cli/command-registry.ts +65 -1
  12. package/src/cli/commands/module-upgrade.test.ts +29 -0
  13. package/src/cli/commands/module-upgrade.ts +57 -24
  14. package/src/cli/commands/proxmox-instance-list.test.ts +77 -0
  15. package/src/cli/commands/proxmox-instance-list.ts +140 -0
  16. package/src/cli/commands/proxmox-instance-resize.ts +235 -0
  17. package/src/cli/commands/proxmox-node-list.ts +1 -34
  18. package/src/cli/commands/proxmox-resize-guards.test.ts +55 -0
  19. package/src/cli/commands/proxmox-resize-guards.ts +102 -0
  20. package/src/cli/commands/proxmox-service.ts +38 -0
  21. package/src/cli/completion.ts +11 -37
  22. package/src/cli/index.ts +15 -0
  23. package/src/cli/validators.test.ts +1 -206
  24. package/src/cli/validators.ts +0 -168
  25. package/src/db/schema.ts +21 -1
  26. package/src/hooks/capability-loader.ts +22 -0
  27. package/src/manifest/template-validator.test.ts +31 -1
  28. package/src/manifest/template-validator.ts +9 -0
  29. package/src/services/aspect-approvals.test.ts +52 -0
  30. package/src/services/aspect-approvals.ts +41 -8
  31. package/src/services/deployed-systems.test.ts +73 -1
  32. package/src/services/deployed-systems.ts +72 -0
  33. package/src/services/dns-internal-records.test.ts +76 -3
  34. package/src/services/dns-internal-records.ts +52 -3
  35. package/src/services/dns-provider-backfill.ts +15 -3
  36. package/src/services/fleet-checks.test.ts +18 -16
  37. package/src/services/machine-detector.ts +34 -12
  38. package/src/services/programmatic-responder.aspect.test.ts +157 -0
  39. package/src/services/programmatic-responder.ts +51 -0
  40. package/src/templates/generator.ts +49 -1
  41. package/src/utils/shell.test.ts +1 -163
  42. package/src/utils/shell.ts +0 -100
  43. package/src/validation/schemas.ts +0 -5
  44. package/src/variables/context.ts +36 -7
  45. package/CLI_USAGE.md +0 -433
  46. package/src/config/env.ts +0 -41
package/AGENTS.md CHANGED
@@ -7,10 +7,6 @@ build and ship apps on celilo. **Read the local docs below before searching the
7
7
  web** — they are the source of truth; the hosted copies at
8
8
  `https://celilo.computer/docs` lag them.
9
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
10
  ## Mental model (learn these five things)
15
11
 
16
12
  - **Module** — a directory with a `manifest.yml` and `celilo/scripts/` hooks,
@@ -77,18 +73,14 @@ celilo module deploy <id> / update / health # deploy + verify on the fleet
77
73
 
78
74
  ## Doc map (read in this order)
79
75
 
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.
76
+ - `./CELILO_SUBSYSTEMS.md` map of the infrastructure primitives celilo already
77
+ implements (IPAM, capabilities, firewall/DNS, generator, …), with entry-point files.
78
+ - `./CELILO_CORE_MODULES.md` — the production modules celilo ships in `modules/`
79
+ (what each provides/requires, its role in the fleet).
80
+ - `../../design/MODULE_DEVELOPMENT_GUIDE.md` — author a module (start here).
81
+ - `./CLI_USAGE.md` full CLI reference + workflows.
82
+ - `../../v2/BUILD_BUS.md` — how a change reaches the fleet.
83
+ - `../../v2/APP_CI_REFERENCE.md` wire an app's CI/CD (the copy-me recipe).
84
+ - `../../v2/MODULE_VERSIONING.md` — what `version` means; `version_source`.
85
+ - `../../schemas/module-manifest.schema.json` — the manifest contract.
94
86
  - `https://celilo.computer/docs` — hosted docs (LAN; the repo docs lead).
@@ -0,0 +1,61 @@
1
+ # Celilo Core Modules
2
+
3
+ **What this is:** the production modules celilo ships in `modules/` — the infrastructure celilo
4
+ actually *deploys*. Companion to [CELILO_SUBSYSTEMS.md](./CELILO_SUBSYSTEMS.md) (which maps
5
+ celilo's own engine). Use this to know what already exists before building a new module, and to
6
+ understand how the fleet wires together via capabilities.
7
+
8
+ Each entry: `module id` — what it is — **provides** / **requires** capabilities. Its source is
9
+ `modules/<id>/manifest.yml`; capability contracts are listed in
10
+ [CELILO_SUBSYSTEMS.md](./CELILO_SUBSYSTEMS.md).
11
+
12
+ > **Paths below are relative to the celilo source-repo root** (e.g. `modules/caddy/manifest.yml`)
13
+ > — references into the source tree, not links relative to this file (this doc also ships inside
14
+ > the `@celilo/cli` npm package). Re-grep manifests if an entry looks stale.
15
+
16
+ > How the graph closes: a public app (`requires: public_web`) is served by **caddy**, which
17
+ > `requires: dns_registrar` (**namecheap**) to publish its name and `firewall` (**greenwave** /
18
+ > **iptables**) to open the port. Internal name resolution comes from a **dns_internal** provider
19
+ > (**knot-unbound-internal** / **technitium**). Identity comes from **authentik** (`idp`). That's
20
+ > the whole edge: DNS + firewall + ingress + identity, each a swappable provider module.
21
+
22
+ ## Network fabric (DNS / firewall / DHCP)
23
+
24
+ - **greenwave** — GreenWave C4000XG ISP router driver; port-forwarding + public-IP discovery via REST. **provides:** `firewall`, `dhcp_server`.
25
+ - **iptables** — iptables firewall + NAT; cross-VLAN port exposure with recursive upstream delegation. **provides:** `firewall`.
26
+ - **knot-unbound-internal** — split-horizon internal DNS via Knot (authoritative) + Unbound (recursive); lightweight, plain apt, no .NET. **provides:** `dns_internal`. Ships a base-module-aspect (`modules/knot-unbound-internal/base-module-aspect/`).
27
+ - **technitium** — internal split-horizon DNS resolver + authoritative server (web UI + HTTP API); heavier alternative to knot-unbound. **provides:** `dns_internal`. Ships a base-module-aspect (`modules/technitium/base-module-aspect/`).
28
+ - **namecheap** — public DNS A-record management via Namecheap Dynamic DNS API (HTTP, no browser automation). **provides:** `dns_registrar`.
29
+
30
+ ## Public edge (ingress / identity)
31
+
32
+ - **caddy** — reverse proxy with automatic HTTPS (HTTP-01 ACME); the standard HTTPS ingress. **provides:** `public_web`. **requires:** `dns_registrar`, `firewall`.
33
+ - **authentik** — Authentik identity provider with OIDC (Docker Compose: server, worker, Postgres, Redis). **provides:** `idp`. **requires:** `public_web`, `dns_registrar`, `firewall`.
34
+
35
+ ## Celilo's own infrastructure (self-hosted)
36
+
37
+ - **celilo-mgmt** — the celilo management server itself, deployed as a module (replaces install.sh + `system init`; ships daemon, runs migrations, self-registers). **provides:** `celilo_event_bus`, `celilo_module_deploy_worker`. **requires:** `cross_module_read`. See `v2/MANAGEMENT_AS_NETAPP.md`.
38
+ - **celilo-registry** — module registry server (Cargo sparse protocol); stores `.netapp` files, serves index + search/download API. **provides:** `registry_publish`. **requires:** `public_web`, `dns_registrar`.
39
+ - **celilo-apt-repo** — Debian apt repository (reprepro + Bun HTTP server) serving the celilo `.deb` at apt.celilo.computer. **provides:** `apt_publish`. **requires:** `public_web`, `dns_registrar`.
40
+ - **celilo-website** — public docs site (static Astro) served via Caddy on celilo.computer. **requires:** `public_web`, `dns_registrar`.
41
+
42
+ ## Git forge & CI pipeline
43
+
44
+ - **forgejo** — self-hosted Forgejo git forge (git-over-SSH, OIDC, public ingress). **provides:** `source_forge`. **requires:** `public_web`, `idp`, `firewall`, `dns_registrar`. See `v2/CI_PIPELINE.md`.
45
+ - **forgejo-runner** — host-mode (LXC) Forgejo Actions runner for unit/lint jobs; outbound-only, lives in dmz. **requires:** `source_forge`. See `v2/FORGEJO_RUNNER.md`.
46
+ - **forgejo-builder** — VM-based, Docker-capable Forgejo Actions runner (`requires.system.type: vm`) for hermetic release builds + the cele2e suite. **requires:** `source_forge`.
47
+ - **npm-cache-node** — self-hosted npm registry as a pass-through disk cache (proxies upstream). **requires:** `public_web`, `dns_registrar`. See `v2/NPM_CACHE_NODE.md`.
48
+
49
+ ## Applications
50
+
51
+ - **homebridge** — HomeKit bridge for smart-home devices (VeSync, Leviton, Lutron, TP-Link, Tuya). No capabilities (leaf app).
52
+
53
+ ## E2E fixtures & probes (not production apps)
54
+
55
+ - **source-forge-probe** — hostless e2e probe that exercises the `source_forge` capability (issue/revoke runner token) against a deployed Forgejo. **requires:** `source_forge`.
56
+ - **test-ansible-output** — e2e fixture that runs 25×1s sleep tasks to assert Ansible output streams in real time. Not a real app.
57
+ - **vm-smoke** — throwaway module proving celilo's generic `type: vm` deploy path end-to-end (template clone → cloud-init → Ansible reach). No capabilities.
58
+
59
+ ## Archived / superseded
60
+
61
+ `modules/archive/` holds retired modules — **dns-external** (VPS authoritative DNS + WireGuard, superseded by the `dns_internal`/`dns_registrar` split), **gmail** (email-reading capability), **namecheap-api** (registrar-config via Namecheap API, superseded by the **namecheap** DDNS module). Reference only; not deployed.
@@ -0,0 +1,83 @@
1
+ # Celilo Subsystem Inventory
2
+
3
+ **What this is:** a map of infrastructure primitives celilo **already implements**, with the
4
+ entry-point file for each. It exists so agents stop reinventing features (the trigger case:
5
+ IP/VMID allocation, which is already IPAM).
6
+
7
+ **The rule:** Assume celilo already provides any infrastructure primitive (IP/VMID
8
+ allocation, secrets, DNS, firewall, cross-module data, packaging, event scheduling).
9
+ Before proposing to build one — or asking the operator how to do it — grep this
10
+ inventory / the codebase and cite what you found. Only raise a question if the search
11
+ is genuinely empty, or the real choice is between existing mechanisms.
12
+
13
+ This is an *implemented-feature* map. For terminology see `GLOSSARY.md`; for architecture
14
+ see `design/README.md`. Companion doc: [CELILO_CORE_MODULES.md](./CELILO_CORE_MODULES.md)
15
+ (the production modules celilo ships).
16
+
17
+ > **All file paths below are relative to the celilo source-repo root** (e.g.
18
+ > `apps/celilo/src/ipam/allocator.ts`). They are references into the source tree, not links
19
+ > relative to this file — this doc also ships inside the `@celilo/cli` npm package, where the
20
+ > wider repo isn't present. Paths drift; if an entry looks wrong, re-grep and fix it here.
21
+
22
+ ---
23
+
24
+ ## Allocation & infrastructure selection
25
+
26
+ - **IPAM (IP/VMID allocation)** — `apps/celilo/src/ipam/allocator.ts` — `allocateIPFromSubnet`, `allocateVMID`, `reserveIP`/`unreserveIP`, `inferZoneFromIP`, `getAllocation`. Auto-wrapper: `apps/celilo/src/ipam/auto-allocator.ts` — `allocateForModule` / `deallocateForModule`.
27
+ - **Infrastructure selection (container-service vs machine pool)** — `apps/celilo/src/services/machine-pool.ts` (`getMachineByHostname`, `addMachine`, `assignModuleToMachine`) and `apps/celilo/src/services/container-service.ts` (`getContainerServiceByName`, `addContainerService`, `verifyContainerService`). Provider API clients: `apps/celilo/src/api-clients/proxmox.ts`, `apps/celilo/src/api-clients/digitalocean.ts`.
28
+ - **Zone detection / system config** — `apps/celilo/src/services/zone-detector.ts` — `detectZoneFromIp` reads `network.<zone>.subnet` from the `systemConfig` table.
29
+
30
+ ## Capability system (cross-module data & functions)
31
+
32
+ - **Define a capability function** — `packages/capabilities/src/define-capability-function.ts` — `defineCapabilityFunction`.
33
+ - **Canonical capability registry** — `packages/capabilities/src/capability-registry.ts` — `KNOWN_CAPABILITY_NAMES` (the authoritative list), `CapabilityRegistry` type. Public surface: `packages/capabilities/src/index.ts`.
34
+ - **Loader (wires provider factories into hook contexts)** — `apps/celilo/src/hooks/capability-loader.ts` — `loadCapabilityFunctions`, `resolveFirewallNatIp`.
35
+ - **Ledger wrappers (stateful capabilities)** — `apps/celilo/src/services/dns-registrations.ts` (`withDnsRegistrationLedger`), `apps/celilo/src/services/dns-internal-records.ts` (`withDnsInternalLedger`).
36
+
37
+ ### Known capabilities (impl → provider module)
38
+
39
+ | capability | impl | provider module(s) |
40
+ |---|---|---|
41
+ | `public_web` | `packages/capabilities/src/public-web.ts` (`createPublicWeb`) | caddy |
42
+ | `idp` | `packages/capabilities/src/idp.ts` | authentik |
43
+ | `dns_registrar` | `packages/capabilities/src/dns-registrar.ts` (`registerHost`) | namecheap |
44
+ | `firewall` | `packages/capabilities/src/firewall.ts` (`exposeService`, `unexposeService`, `listExposedServices`) | greenwave, iptables |
45
+ | `dns_internal` | `packages/capabilities/src/dns-internal.ts` | knot-unbound-internal, technitium |
46
+ | `dhcp_server` | `packages/capabilities/src/dhcp-server.ts` | greenwave |
47
+ | `source_forge` | `packages/capabilities/src/source-forge.ts` | forgejo |
48
+ | `registry_publish` | `packages/capabilities/src/registry-publish.ts` | celilo-registry |
49
+ | `cross_module_read` | `packages/capabilities/src/cross-module-read.ts` | framework (read other modules' capability data) |
50
+
51
+ ## Hooks & deploy
52
+
53
+ - **Hook executor / ABI** — `apps/celilo/src/hooks/executor.ts` (`invokeHook`, `executeHookScript`, `checkRequiredCapabilities`), types in `apps/celilo/src/hooks/types.ts` (`HookContext`, `HookDefinition`, `HookName`). Named-hook runner: `apps/celilo/src/hooks/run-named-hook.ts`. Manifest hook config: `apps/celilo/src/hooks/load-hook-config.ts`.
54
+ - **Deploy pipeline** — `apps/celilo/src/services/module-deploy.ts`.
55
+ - **DNS provider backfill** (re-emit registrations when a provider deploys) — `apps/celilo/src/services/dns-provider-backfill.ts` — `isDnsInternalProvider`, `backfillProviderDns`.
56
+ - **Base-module aspects (fan-out across the fleet)** — `apps/celilo/src/services/aspect-runner.ts` — `planAspectFanOut`, `runAspectFanOut`, `maybeRunAspectForTrigger`. Aspect content lives in `modules/<m>/base-module-aspect/` (e.g. knot-unbound-internal, technitium).
57
+
58
+ ## Generation & templating
59
+
60
+ - **Generator** — `apps/celilo/src/templates/generator.ts` — `generateTemplates` (orchestration), plus Terraform/Ansible file handling.
61
+ - **Variable resolution** — `apps/celilo/src/variables/resolver.ts` (parser: `apps/celilo/src/variables/parser.ts`). Supported prefixes: `$self`, `$system`, `$secret`, `$system_secret`, `$capability`, `$infra`.
62
+
63
+ ## Secrets
64
+
65
+ - **Vault / encryption** — `apps/celilo/src/secrets/vault.ts` (`deriveVaultPassword`, `getVaultPassword` — Ansible Vault) and `apps/celilo/src/secrets/encryption.ts` (`encryptSecret`/`decryptSecret`, AES-256-GCM).
66
+
67
+ ## Packaging, registry & publish
68
+
69
+ - **Module packaging** — `apps/celilo/src/module/packaging/` — `build.ts` (`buildModule`), `extract.ts`, `checksum.ts`, `signature.ts` (`signChecksums`/`verifySignature`), `release-metadata.ts`, `audit.ts`.
70
+ - **Publish driver** — `scripts/publish.ts` shims to `apps/celilo/src/cli/commands/publish/` (workspace npm packages via `bun publish` + module registry; preflight stale-version/stale-manifest gates).
71
+
72
+ ## Persistence
73
+
74
+ - **DB schema** — `apps/celilo/src/db/schema.ts`. Client: `apps/celilo/src/db/client.ts`. Migration runner: `apps/celilo/src/db/migrate.ts`. Migrations: `apps/celilo/drizzle/`.
75
+
76
+ ## Events
77
+
78
+ - **Event bus** — `packages/event-bus/src/index.ts` — `Bus`, `openBus`, `defineEvents`, `defineHandler`, `runDispatcher`, pattern matching + timer ticks (`emitDueTimerTicks`, `retentionSweep`).
79
+
80
+ ## E2E simulation
81
+
82
+ - **cele2e harness** — `packages/e2e/src/` — `runner.ts`, `container-manager.ts` (`startNetwork`, `reconnectNetwork`), `network-builder.ts` (`NetworkBuilder`).
83
+ - **Run wrapper** — `infra/scripts/cele2e-run.sh` lives in the separate `infra/` clone, **not** in this repo. See the cele2e section of the repo-root `CLAUDE.md` for the operator workflow.