@rizom/ops 0.2.0-alpha.82 → 0.2.0-alpha.821

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 (76) hide show
  1. package/README.md +84 -3
  2. package/dist/age-key-bootstrap.d.ts +1 -1
  3. package/dist/brains-ops.js +706 -211
  4. package/dist/capability-bundle-migration.d.ts +26 -0
  5. package/dist/cert-bootstrap.d.ts +4 -2
  6. package/dist/content-repo-ref.d.ts +10 -0
  7. package/dist/content-repo.d.ts +1 -1
  8. package/dist/deploy.js +114 -3
  9. package/dist/directory-sync-stress-system.d.ts +75 -0
  10. package/dist/directory-sync-stress.d.ts +117 -0
  11. package/dist/entries/deploy.d.ts +2 -0
  12. package/dist/fetch-with-timeout.d.ts +3 -0
  13. package/dist/fs-paths.d.ts +4 -0
  14. package/dist/health-watchdog-smoke.d.ts +54 -0
  15. package/dist/image-inventory.d.ts +4 -0
  16. package/dist/image-types.d.ts +7 -0
  17. package/dist/images.d.ts +89 -0
  18. package/dist/index.d.ts +7 -0
  19. package/dist/index.js +720 -213
  20. package/dist/legacy-pilot-migration.d.ts +11 -0
  21. package/dist/legacy-projection-job-recovery.d.ts +29 -0
  22. package/dist/load-registry.d.ts +72 -7
  23. package/dist/observed-status.d.ts +1 -1
  24. package/dist/parse-args.d.ts +2 -12
  25. package/dist/preview-domain.d.ts +9 -0
  26. package/dist/provider-key-migration.d.ts +20 -0
  27. package/dist/reconcile-dry-run.d.ts +9 -0
  28. package/dist/run-command.d.ts +22 -5
  29. package/dist/runtime-image-lock.d.ts +12 -0
  30. package/dist/schema.d.ts +132 -172
  31. package/dist/secrets-encrypt.d.ts +9 -11
  32. package/dist/secrets-push.d.ts +1 -1
  33. package/dist/ssh-key-bootstrap.d.ts +1 -26
  34. package/dist/stage-legacy-crossover.d.ts +25 -0
  35. package/dist/stress-command.d.ts +14 -0
  36. package/dist/stress-git-checkout.d.ts +21 -0
  37. package/dist/stress-health-monitor.d.ts +56 -0
  38. package/dist/upgrade.d.ts +10 -0
  39. package/dist/user-add.d.ts +1 -0
  40. package/dist/user-offboard.d.ts +61 -0
  41. package/dist/verify-user.d.ts +5 -2
  42. package/package.json +51 -44
  43. package/templates/rover-pilot/.env.schema +23 -3
  44. package/templates/rover-pilot/.github/actions/varlock-env/action.yml +47 -0
  45. package/templates/rover-pilot/.github/workflows/build.yml +63 -17
  46. package/templates/rover-pilot/.github/workflows/deploy.yml +106 -70
  47. package/templates/rover-pilot/.github/workflows/directory-sync-stress.yml +119 -0
  48. package/templates/rover-pilot/.github/workflows/health-watchdog-smoke.yml +95 -0
  49. package/templates/rover-pilot/.github/workflows/offboard.yml +107 -0
  50. package/templates/rover-pilot/.github/workflows/reconcile.yml +10 -4
  51. package/templates/rover-pilot/.github/workflows/upgrade.yml +104 -0
  52. package/templates/rover-pilot/README.md +14 -6
  53. package/templates/rover-pilot/deploy/scripts/create-predeploy-backup.ts +1265 -0
  54. package/templates/rover-pilot/deploy/scripts/decrypt-user-secrets.ts +84 -23
  55. package/templates/rover-pilot/deploy/scripts/helpers.ts +3 -0
  56. package/templates/rover-pilot/deploy/scripts/install-health-watchdog.ts +144 -0
  57. package/templates/rover-pilot/deploy/scripts/provision-server.ts +51 -21
  58. package/templates/rover-pilot/deploy/scripts/pull-local-models.ts +69 -0
  59. package/templates/rover-pilot/deploy/scripts/reload-homeserver.ts +73 -0
  60. package/templates/rover-pilot/deploy/scripts/resolve-deploy-handles.ts +4 -0
  61. package/templates/rover-pilot/deploy/scripts/resolve-missing-images.ts +13 -0
  62. package/templates/rover-pilot/deploy/scripts/resolve-user-config.ts +74 -9
  63. package/templates/rover-pilot/deploy/scripts/sync-content-repo.ts +51 -47
  64. package/templates/rover-pilot/deploy/scripts/update-dns.ts +58 -12
  65. package/templates/rover-pilot/deploy/scripts/validate-secrets.ts +12 -1
  66. package/templates/rover-pilot/deploy/scripts/verify-runtime-image.ts +18 -0
  67. package/templates/rover-pilot/docs/canonical-crossover-record.md +107 -0
  68. package/templates/rover-pilot/docs/onboarding-checklist.md +23 -24
  69. package/templates/rover-pilot/docs/operator-playbook.md +348 -56
  70. package/templates/rover-pilot/docs/user-onboarding.md +48 -297
  71. package/templates/rover-pilot/package.json +1 -0
  72. package/templates/rover-pilot/pilot.yaml +7 -4
  73. package/dist/origin-ca.d.ts +0 -1
  74. package/dist/push-secrets.d.ts +0 -9
  75. package/dist/push-target.d.ts +0 -2
  76. package/dist/run-subprocess.d.ts +0 -6
@@ -9,30 +9,205 @@ Treat these as checked-in deploy artifacts in the pilot repo:
9
9
  - `deploy/scripts/`
10
10
  - `.github/workflows/build.yml`
11
11
  - `.github/workflows/deploy.yml`
12
+ - `.github/workflows/directory-sync-stress.yml`
13
+ - `.github/workflows/health-watchdog-smoke.yml`
14
+ - `.github/workflows/offboard.yml`
12
15
  - `.github/workflows/reconcile.yml`
13
16
 
14
17
  `.env.schema` is the single source of truth for required and sensitive deploy vars.
15
18
  The deploy scripts and workflows should read from that contract instead of inventing a second list.
16
19
 
17
- The shared pilot image tag is `brain-${brainVersion}`:
20
+ The fleet has one image topology:
18
21
 
19
- - build publishes `brain-${brainVersion}`
20
- - generated `users/<handle>/.env` carries `BRAIN_VERSION=<brainVersion>`
21
- - deploy sets `VERSION=brain-${brainVersion}`
22
+ - one immutable image is published for each effective Brain version and site pin set: `brain-${brainVersion}` for instances without a site override, `brain-${brainVersion}--<pins>--s<digest>` for instances with one (sorted readable pins plus an exact-identity digest; long names omit readable pins); this format selects new immutable tags, never overwrites existing registry images
23
+ - instances with the same version and pins share an image; a site's pin change builds that site's image and no other
24
+ - generated `users/<handle>/.env` carries `BRAIN_VERSION=<brainVersion>`, and `IMAGE_TAG=<tag>` for an instance with site pins
25
+ - build and deploy derive the same effective image tag from the resolved registry
26
+
27
+ ## Reviewed runtime dependencies
28
+
29
+ Use Bun 1.4.0 to prepare the full dependency graph before building a new image:
30
+
31
+ ```sh
32
+ brains-ops images:lock .
33
+ # Or prepare one version/pin set before promotion:
34
+ brains-ops images:lock . --brain-version <exact-version> --site-packages "<exact site/theme pins>"
35
+ ```
36
+
37
+ Review and commit each new `deploy/runtime/<image-tag>/package.json` and `bun.lock`
38
+ together with its desired-state change. The manifest pins Brain and exactly that
39
+ image's site/theme packages, and overrides `postcss-selector-parser` to 7.1.6.
40
+ Review fresh runtime audit and behavior checks; a frozen lock is not proof that
41
+ bundled code, operating-system packages, or every dependency is vulnerability-free.
42
+
43
+ The command resolves dependencies with lifecycle scripts disabled; it does not
44
+ build, publish, deploy, decrypt secrets, or inspect fleet hosts. Existing entries
45
+ are validated and left untouched, never refreshed. A failed new entry retains an
46
+ `.incomplete` marker and diagnostic files and blocks reuse; inspect and preserve
47
+ that evidence before separately approving any recovery.
48
+
49
+ Build refuses missing, incomplete, or mismatched manifests. Docker copies only the
50
+ reviewed manifest and lock for the selected tag and installs production packages
51
+ with `--frozen-lockfile --ignore-scripts`; it never resolves updates with `bun add`.
52
+ Commit both inputs: changing only the manifest without a matching lock fails the
53
+ frozen install before publication.
54
+
55
+ Existing published tags remain immutable and are not rebuilt by adopting this
56
+ scaffold. Existing-image verification still checks only the exact top-level Brain
57
+ and site/theme versions; it does not certify a legacy image's transitive graph.
58
+ The parser fix reaches running instances only through a separately approved new
59
+ image/version rollout, never by overwriting a deployed tag.
22
60
 
23
61
  ## Version bump flow
24
62
 
25
- When `pilot.yaml.brainVersion` changes and you push:
63
+ First generate and review the matching runtime locks. When `pilot.yaml.brainVersion` changes and you push:
26
64
 
27
- 1. build publishes the new shared image tag
65
+ 1. build publishes each missing image, named by Brain version and site pins, and verifies existing images against what their names say they hold
28
66
  2. reconcile refreshes generated `users/<handle>/.env`
29
67
  3. deploy runs for handles whose generated config changed
30
68
  4. generated file commits happen once in a final aggregation step after the deploy matrix finishes
31
69
 
70
+ Every external site and theme package has its own exact version pin. A cohort or
71
+ pilot brain-version bump never changes those package versions implicitly; update each
72
+ pin deliberately from reviewed package and image evidence.
73
+
74
+ Smoke-first upgrades build the canary's image, named by its pins, before promotion.
75
+ Moving other instances onto the tested Brain version reuses that image where their
76
+ pins match it and builds their own where they do not. Explicit Build dispatches build
77
+ exactly the dispatched version and `site_packages` pins.
78
+
79
+ Deploy verifies the actual installed Brain and selected instance's site/theme
80
+ versions on the CI runner after image readiness and before provisioning or
81
+ container replacement. It reads manifests in a read-only, network-disabled
82
+ container without starting the Brain or mounting fleet data. Missing packages,
83
+ wrong versions, or verification failures block deployment, even on manual runs.
84
+ Never bypass this gate or overwrite a deployed tag to recover an older incomplete
85
+ image; review artifact recovery separately.
86
+
32
87
  When a push changes only deploy contract files and no generated `users/<handle>/.env` or `users/<handle>/brain.yaml` files, the deploy workflow exits through its explicit no-op path and prints `No affected user configs; skipping deploy.`
33
88
 
34
89
  They are scaffolded from `@rizom/ops`, then versioned in this repo like any other deploy contract.
35
90
 
91
+ ## Verified pre-deploy rollback snapshots
92
+
93
+ Deploy creates and verifies one target-scoped rollback snapshot after SSH and image readiness, immediately before optional stale-lock release and `kamal setup`. A snapshot failure stops the workflow before container replacement. The current runtime must be ready with an idle job queue; degradation a plugin reports is named in the log and backed up, not refused, because a deploy is often its fix. A genuinely new server with no runtime or persistent state reports `not applicable`; persistent state without an identifiable runtime fails closed.
94
+
95
+ Each snapshot contains transaction-consistent online captures of the six canonical SQLite databases, database hashes and `quick_check` results, the deployed `brain.yaml`, sanitized container and mount metadata, and the Directory Sync checkout. Git capture includes all refs, an observed remote head, staged and unstaged binary patches, and mode-preserving archives of untracked and ignored files. Capture performs no checkout mutation or remote write.
96
+
97
+ Verified snapshots are finalized atomically under:
98
+
99
+ ```text
100
+ /opt/brain-state/backups/predeploy-<handle>-<target>-<UTC timestamp>/
101
+ ```
102
+
103
+ Files use mode `0600` and the directory uses `0700`. A `.incomplete` directory is diagnostic evidence, never a rollback point. Checksums and the versioned manifest must verify before finalization. The default retention is five verified snapshots per target; incomplete or unverified directories do not count, and the snapshot created by the current deployment is never pruned.
104
+
105
+ These are same-server rollback snapshots, not off-host disaster recovery. Push, reconcile and ordinary manual deploys always take one, and there is no automatic restore.
106
+
107
+ A runtime whose own startup work keeps its job queue busy never passes the idle gate, so no deploy can replace it. For that case only, a manually dispatched Deploy can skip the snapshot once the operator has confirmed that the target's last verified snapshot stands:
108
+
109
+ ```sh
110
+ gh workflow run Deploy --ref main \
111
+ -f handle=<handle> \
112
+ -f skip_predeploy_backup=true
113
+ ```
114
+
115
+ The input is off by default and scoped to one handle; push and reconcile deploys carry no inputs, so their snapshot always runs.
116
+
117
+ Restoration requires separate approval: stop replacement/application processes, recheck the selected snapshot's checksums, preserve the current state, restore databases and exact Git state, then validate health, queues, Git checkpoints, durable export intents, preview, and production output before reopening the target.
118
+
119
+ ## Retired projection job recovery
120
+
121
+ A pre-scheduler projection job can remain active after its handler type is retired. Current runtime health reports active job types missing from the finalized execution inventory as degraded. Do not restart repeatedly or relax the snapshot idle gate.
122
+
123
+ Use the recovery command only after read-only evidence proves all of the following for one exact row:
124
+
125
+ - its type is one of the command's fixed legacy projection types;
126
+ - the installed runtime no longer contains that handler;
127
+ - attempt, worker-session, lease, and heartbeat ownership are all absent;
128
+ - no durable progress snapshot or result exists.
129
+
130
+ Preview the exact row first:
131
+
132
+ ```sh
133
+ bunx --package @rizom/ops@<exact-version> brains-ops \
134
+ recover:retire-legacy-projection-job \
135
+ /data/brain-jobs.db <job-id> --type <legacy-type> --dry-run
136
+ ```
137
+
138
+ After separate operator review, replace `--dry-run` with the exact confirmation `--confirm retire:<job-id>`. The command atomically fences against ownership or progress appearing between inspection and retirement, and fails closed if the row changed. It is not a general job cancellation API and cannot retire arbitrary job types. Require operational health and a fully idle queue afterward, then run the unchanged canonical predeploy snapshot and Deploy workflow.
139
+
140
+ ## Canonical contract crossover maintenance window
141
+
142
+ Do not run this procedure without explicit operator approval. The canonical desired state, canonical `@rizom/ops`, and unified runtime image form one contract and must move or roll back together. Complete `docs/canonical-crossover-record.md` as the approval evidence without adding secret values.
143
+
144
+ Before the window, record and review:
145
+
146
+ - the prior pilot commit and exact `@rizom/ops` version;
147
+ - every prior runtime image tag and immutable digest;
148
+ - the reviewed canonical pilot commit;
149
+ - the exact unified `@rizom/brain` and `@rizom/ops` versions;
150
+ - every unified image tag and immutable digest;
151
+ - canary-first rollout order, followed by the remaining cohorts;
152
+ - expected `/health/operate` version, unauthenticated MCP response, site marker, and content repository identity for each posture.
153
+
154
+ Run `bunx brains-ops reconcile-all <canonical-review-copy> --dry-run` against the isolated review copy. The command blocks external content-repository access, leaves the review copy untouched, lists both passes' changed files, and must report second-pass zero drift. Reconciliation owns generated per-user config; only `render` owns the observational `views/users.md` projection.
155
+
156
+ During the approved window:
157
+
158
+ 1. Freeze unrelated merges and releases. Wait for active Build, Reconcile, and Deploy runs to finish, then disable all three pilot workflows with `gh workflow disable build.yml`, `gh workflow disable reconcile.yml`, and `gh workflow disable deploy.yml`.
159
+ 2. Publish and verify the reviewed unified runtime and matching ops artifacts. Do not update pilot desired state until the exact versions are installable and the expected images can be built.
160
+ 3. Apply the reviewed canonical pilot revision while automation remains disabled. Confirm repository names, server/domain identity, content repositories, secret selectors, image names, and tag identity against the review diff.
161
+ 4. Enable only Build, run it for the canonical desired-state revision, and record every resulting image digest. Stop if the observed digest set differs from the cutover record.
162
+ 5. Enable only Reconcile, run it once, and review its generated per-user config commit. It must not rewrite `views/users.md`, and no generated file may combine canonical config with a retired image version.
163
+ 6. Enable Deploy and deploy one handle at a time in the approved order. After each deploy, run `bunx brains-ops verify-user . <handle>`, render observed fleet status, and complete the manual identity, content-sync, and app-managed site checks.
164
+ 7. Run Reconcile a second time. Require no reconciler-owned generated diff and no deploy work before re-enabling normal automation and lifting the merge/release freeze. Observed status rendering remains separate from this convergence gate.
165
+
166
+ If any gate fails, disable all three workflows again. Restore the prior pilot desired-state and dependency revision, reconcile with the prior ops version, and redeploy the prior image tag/digest as one rollback pair. Verify the prior `/health/operate` version and identity/content/site checks before re-enabling automation. Never restore only config or only an image.
167
+
168
+ ## Directory-sync stress gate
169
+
170
+ Use the manual `Directory Sync Stress` workflow only against a disposable smoke user. It refuses a target unless the handle, domain, and content repository all identify smoke, the confirmation input exactly matches `stress:<handle>`, and the user desired state declares the hermetic posture below. Reconcile and deploy this posture before running the workload:
171
+
172
+ ```yaml
173
+ embeddingEnabled: false
174
+ topicExtractionEnabled: false
175
+ skillDerivationEnabled: false
176
+ swotDerivationEnabled: false
177
+ ```
178
+
179
+ Before authorizing a workload, dispatch the workflow once with `verify_only: true`. That mode loads the same Bitwarden/Varlock content credential, clones the smoke content repository, and runs `git push --dry-run` against a temporary stress ref. It creates no ref, performs no content write, does not contact the deployed runtime, and skips cleanup because no probes were created.
180
+
181
+ Profiles are deterministic and reversible:
182
+
183
+ - `regression`: 20 probes;
184
+ - `load`: ramps to 350 probes, updates all, renames 100, updates again, then deletes all;
185
+ - `stress`: ramps to 700 probes and renames 200 before cleanup.
186
+
187
+ The workflow loads operator credentials through Bitwarden/Varlock, but it is separate from Deploy and cannot deploy an image. It creates a rollback branch before the first content write, gates on health timeouts, watchdog restarts, and external AI usage during the monitored workload window, preserves warmup and cleanup samples as evidence, uploads JSON/Markdown/runtime artifacts, and runs an independent idempotent cleanup job with `if: always()`. Once cleanup confirms that no probes remain, it also prunes retained `ops/directory-sync-stress-backup-*` branches; if probes remain, the branches stay available for recovery.
188
+
189
+ Treat any gated health failure, restart, OOM, residual probe, or entity-baseline drift as a failed gate. Do not restart the target during measurement. Recovery is a separate operator action after evidence collection.
190
+
191
+ ## Health watchdog smoke gate
192
+
193
+ Use the manual `Health Watchdog Smoke` workflow only after the `smoke` fleet user has completed a normal Deploy run. The workflow shares the `deploy-<handle>` concurrency group, resolves the server from pilot desired state through Hetzner, loads the existing deploy SSH key through Bitwarden/Varlock, and refuses targets whose handle and domain do not identify smoke. Confirm with `watchdog-smoke:<handle>`.
194
+
195
+ The smoke does not deploy or replace the installed systemd units. It verifies that the installed watchdog exactly matches the packaged canonical payload, then exercises that installed script. It also verifies the deployed rover image label, exact-label selector, active timer, and `/health/live` Docker healthcheck. While holding the timer's global lock, it creates temporary containers for eligible unhealthy, unrelated service-labelled unhealthy, false-labelled unhealthy, and eligible healthy cases. It then requires exactly three eligible restarts followed by budget suppression, diagnostics and state only for the eligible fixture, and no restart of the deployed rover or ineligible fixtures.
196
+
197
+ The primary job uploads remote incident, state, and command evidence. An independent `if: always()` cleanup job removes deterministic fixture names and remote temporary files using the same workflow run ID. Treat missing evidence, unexpected eligibility, deployed-container movement, cleanup failure, or any non-smoke target rejection as a failed gate.
198
+
199
+ ## Stale deploy lock recovery
200
+
201
+ Kamal intentionally leaves its remote deploy lock in place when a deployment is cancelled or interrupted. Confirm that no deployment for the user is still active before releasing the lock, then use the deploy workflow's explicit recovery input:
202
+
203
+ ```sh
204
+ gh workflow run Deploy --ref main \
205
+ -f handle=<handle> \
206
+ -f release_stale_lock=true
207
+ ```
208
+
209
+ Recovery is opt-in and scoped to one handle. Normal push, reconcile, and manual deploy runs never remove a lock automatically.
210
+
36
211
  ## Bootstrap flow
37
212
 
38
213
  For this fleet, operator-local secret material remains the source of truth during onboarding and rotation. The repo stores encrypted per-user secrets, not raw values.
@@ -51,56 +226,97 @@ The shared cert bootstrap writes local cert artifacts under `.brains-ops/certs/s
51
226
 
52
227
  Preview hosts use the shape `<handle>-preview.rizom.ai`, so one wildcard origin cert for `*.rizom.ai` covers both the primary and preview hosts for every pilot user.
53
228
 
54
- ## Upgrading operator behavior
229
+ ## Pilot user offboarding
55
230
 
56
- When `@rizom/ops` changes the scaffolded deploy contract:
231
+ Use the manual **Offboard** workflow for explicit pilot retirement. It is the only
232
+ supported path that removes both checked-in desired state and provider resources.
233
+ Normal reconcile/deploy changes never imply destruction.
57
234
 
58
- 1. bump `@rizom/ops` in `package.json`
59
- 2. rerun the relevant scaffold/reconcile flow
60
- 3. review the resulting changes to `.env.schema`, `deploy/scripts/`, and workflows in git
61
- 4. commit the updated deploy artifacts together
235
+ 1. Enter a comma-separated handle list. The command sorts and deduplicates it.
236
+ 2. Run with `apply: false` and review the exact servers, DNS records, and content
237
+ repositories in the plan.
238
+ 3. Enter the canonical confirmation printed by the dry run, for example
239
+ `sunset:alice,bob`.
240
+ 4. Rerun with `apply: true`.
241
+ 5. Verify the workflow's bot commit removes user YAML, encrypted secrets, generated
242
+ user directories, cohort membership, and rows from `views/users.md`.
62
243
 
63
- ## Rover verification notes
244
+ The apply path archives each private content repository, deletes the user's main and
245
+ preview DNS records, destroys the dedicated Hetzner server, and removes desired state.
246
+ Custom-domain users also lose their managed `www` record. The operation is idempotent,
247
+ but it deliberately creates **no runtime backup**; obtain separate owner approval and
248
+ backup state before apply when retention is required.
64
249
 
65
- Use the verification script after deploy:
250
+ The equivalent operator-local commands are:
66
251
 
67
252
  ```sh
68
- bunx brains-ops verify-user . <handle>
253
+ bunx brains-ops user:offboard . alice bob
254
+ bunx brains-ops user:offboard . alice bob \
255
+ --apply --confirm sunset:alice,bob
69
256
  ```
70
257
 
71
- It checks every Rover preset:
258
+ The deploy handle resolver ignores deleted users, so the generated-file deletions in
259
+ the offboarding commit cannot route those handles back through onboarding/deploy.
260
+
261
+ ## Upgrading operator behavior
262
+
263
+ The pilot repository pins `@rizom/ops` in `package.json`. The scheduled and manually dispatched Upgrade workflow owns routine upgrades to that pin. It refreshes the scaffold on a branch and opens a reviewable PR; it does not change runtime desired state or authorize a deployment.
72
264
 
73
- - `https://<handle>.rizom.ai/health` should return `200`
74
- - unauthenticated `POST https://<handle>.rizom.ai/mcp` should return the expected auth failure
75
- - background jobs should not be repeatedly failing, except for expected missing optional integrations
265
+ Because scaffold refreshes can update `.github/workflows/*`, the workflow must not push with its Actions `GITHUB_TOKEN`. Configure a dedicated GitHub App:
76
266
 
77
- Additional `rover:core` note:
267
+ 1. Install it only on this pilot repository.
268
+ 2. Grant repository permissions `Contents: Read and write`, `Pull requests: Read and write`, and `Workflows: Read and write`; grant nothing else.
269
+ 3. Store its App ID as the repository Actions variable `OPS_UPGRADE_APP_ID`.
270
+ 4. Store its private key as the repository Actions secret `OPS_UPGRADE_APP_PRIVATE_KEY`.
78
271
 
79
- - Rover core is MCP-only; a bare `GET /` may return `401`, which does not indicate a bad deploy.
272
+ The workflow explicitly requests only those three permissions. Checkout persists no credential. After the freshly published `@rizom/ops` finishes, the workflow checks whether it produced a change; only then does it mint a short-lived, repository-scoped App token for the push-and-open-PR steps. A credential that can rewrite `.github/workflows/` therefore does not exist while upgraded package code runs.
80
273
 
81
- For `preset: default`, the script also checks:
274
+ If `OPS_UPGRADE_APP_ID` is unset, or token creation, branch push, or PR creation fails, the run stops with a non-zero status. Repair the CI credential path; never fall back to an operator's personal SSH key or token.
82
275
 
83
- - `https://<handle>.rizom.ai/` loads the browser/site surface
84
- - `https://<handle>.rizom.ai/cms` loads the CMS/login surface
276
+ Adopting this credential flow in an existing pilot repository requires one explicitly reviewed bootstrap PR because the old Upgrade workflow cannot update itself. After that merge, routine upgrades run entirely in CI:
277
+
278
+ 1. dispatch Upgrade with an exact version, or let its schedule select `latest`;
279
+ 2. review the generated package, lockfile, deploy-script, and workflow diff;
280
+ 3. merge the upgrade PR only after its checks pass;
281
+ 4. change runtime desired state separately through the approved canary or fleet rollout flow.
282
+
283
+ ## Canonical verification notes
284
+
285
+ Use the verification script after deploy:
286
+
287
+ ```sh
288
+ bunx brains-ops verify-user . <handle>
289
+ ```
290
+
291
+ For every bundle posture it checks:
292
+
293
+ - `https://<handle>.rizom.ai/health/operate` returns `200`;
294
+ - unauthenticated `POST https://<handle>.rizom.ai/mcp` returns the expected auth failure;
295
+ - background jobs are not repeatedly failing, except for missing optional integrations.
296
+
297
+ A `core`-only instance is MCP-only; a bare `GET /` may return `401` without indicating a bad deploy. When `site` is selected, verification also checks the browser and Studio/login surfaces.
85
298
 
86
299
  Manual checks that remain:
87
300
 
88
- - initial site build is correct for the expected content/theme
89
- - content repo exists and runtime sync is healthy beyond the basic `/health` response
90
- - passkey setup/handoff is completed from the setup email
301
+ - initial app-managed site output is correct for the expected content/theme;
302
+ - content repository identity and runtime sync are healthy;
303
+ - passkey setup/handoff is completed from the setup email.
91
304
 
92
- ## One-user `rover:default` baseline canary
305
+ ## One-user canonical site canary
93
306
 
94
- Run this before adding custom site/theme packages or rolling a larger browser/CMS-first cohort.
307
+ Run this before adding custom site/theme packages or rolling a larger browser/Studio-first cohort.
95
308
 
96
- 1. Create or choose a canary cohort with the default preset:
309
+ 1. Create or choose a canary cohort with explicit bundles:
97
310
 
98
311
  ```yaml
99
- presetOverride: default
312
+ bundles:
313
+ - core
314
+ - site
315
+ - publishing
100
316
  ```
101
317
 
102
318
  2. Add exactly one canary user to that cohort.
103
- 3. For browser/CMS-first onboarding, configure setup email in `users/<handle>.yaml`:
319
+ 3. For browser/Studio-first onboarding, configure setup email in `users/<handle>.yaml`:
104
320
 
105
321
  ```yaml
106
322
  setup:
@@ -114,15 +330,48 @@ Run this before adding custom site/theme packages or rolling a larger browser/CM
114
330
  7. Ask the user to complete passkey setup from the setup email.
115
331
  8. Continue to visual customization only after the canary is healthy.
116
332
 
117
- Rollback:
333
+ Rollback must restore the prior desired-state revision and prior runtime image together. Never pair canonical config with the retired image, or retired config with the canonical image.
334
+
335
+ ## Hosted site and theme package contract
336
+
337
+ Start with the public [site mockup migration guide](https://github.com/rizom-ai/brains/blob/main/docs/site-mockup-migration.md), then apply these hosted-fleet requirements:
118
338
 
119
- - move the canary back to a core cohort, or remove `presetOverride: default` from the cohort
120
- - reconcile generated outputs
121
- - rebuild/redeploy the affected user
339
+ - A site package must default-export `defineSite(...)` and import its authoring API only from `@rizom/site`.
340
+ - A theme package must default-export its CSS as a string. Hosted custom themes currently use the `@rizom/*` scope so the fleet image installs them with the site package; `@brains/*` themes are bundled with `@rizom/brain`.
341
+ - Site and custom theme packages must be public npm packages that install without registry credentials.
342
+ - Site, theme, and brain packages publish independently. Hosted configuration requires exact site and external-theme version pins and never derives one package version from another.
343
+ - Keep site structure and theme CSS in separate packages. Do not put private content or secrets in either package.
344
+
345
+ Configure a user in `users/<handle>.yaml`:
346
+
347
+ ```yaml
348
+ siteOverride:
349
+ package: "@rizom/site-example"
350
+ version: <exact-site-version>
351
+ theme: "@rizom/theme-example"
352
+ themeVersion: <exact-theme-version>
353
+ ```
354
+
355
+ Missing external package versions fail desired-state validation. An instance runs the
356
+ image named by its Brain version and its own pins, so a site/theme pin can change on its
357
+ own: the push builds that image and redeploys that instance. Published tags remain
358
+ immutable; a new pin set is a new tag. Bundled `@brains/*` themes omit `themeVersion`
359
+ because they are not installed as separate packages.
360
+
361
+ ### Custom-package canary and rollback
362
+
363
+ 1. Confirm the exact site/theme versions are public-installable without npm credentials.
364
+ 2. Apply the exact package names and versions to one healthy canonical site canary.
365
+ 3. Push desired state and let the normal Build → Reconcile → Deploy chain create the canary's image and update the canary.
366
+ 4. Run `bunx brains-ops verify-user . <handle>`.
367
+ 5. Manually verify the site, theme, Studio, content sync, and passkey sign-in before adding more users.
368
+
369
+ To roll back, remove or change `siteOverride`, then reconcile and redeploy that user.
370
+ Never mutate an existing image tag.
122
371
 
123
372
  ## Setup email checklist
124
373
 
125
- Use this for browser/CMS-first users who should receive their own first-passkey setup link by email.
374
+ Use this for browser/Studio-first users who should receive their own first-passkey setup link by email.
126
375
 
127
376
  1. Add setup delivery to the user file:
128
377
 
@@ -140,10 +389,10 @@ Use this for browser/CMS-first users who should receive their own first-passkey
140
389
  - `bunx brains-ops onboard . <handle>`
141
390
  - or `bunx brains-ops reconcile-cohort . <cohort>`
142
391
 
143
- 4. Verify the generated `users/<handle>/brain.yaml` contains `auth-service.setupEmail` and `email-resend` config.
392
+ 4. Verify the generated `users/<handle>/brain.yaml` contains `auth-service.setupEmail` set to the user's address and `email` interface config.
144
393
  5. Ask the user to complete passkey setup from the email link, then use:
145
394
  - Dashboard: `https://<handle>.rizom.ai/`
146
- - CMS: `https://<handle>.rizom.ai/cms`
395
+ - Studio: `https://<handle>.rizom.ai/studio`
147
396
 
148
397
  Notes:
149
398
 
@@ -151,32 +400,75 @@ Notes:
151
400
  - The auth service owns setup email dedupe. It should not resend for the same persisted setup token after restart, but should retry failed delivery and resend after token rotation.
152
401
  - `SETUP_EMAIL_FROM` is not marked required because fleets without email setup can omit it, but it is required for users with `setup.delivery: email`.
153
402
 
154
- ## Discord bot token checklist
403
+ ## AT Protocol smoke/config checklist
404
+
405
+ Use this when enabling AT Protocol publishing for a single pilot user.
406
+
407
+ 1. Add the public PDS identifier to the user file. Prefer the account DID as
408
+ the identifier — it survives handle changes. Add `accountDid` too when the
409
+ member wants their handle verified against their subdomain
410
+ (`@<handle>.<domainSuffix>`): the brain then serves it at
411
+ `/.well-known/atproto-did` and Bluesky's "I have my own domain" HTTP
412
+ verification passes with no DNS records.
413
+
414
+ ```yaml
415
+ atproto:
416
+ identifier: did:plc:example123
417
+ accountDid: did:plc:example123
418
+ ```
419
+
420
+ Only for the PDS account designated by the protocol authority's `_lexicon`
421
+ DNS TXT record, also set `lexiconAuthority: true`. Every other fleet user
422
+ must omit it.
423
+
424
+ 2. Put the app password in `users/<handle>.secrets.yaml`:
425
+
426
+ ```yaml
427
+ atprotoAppPassword: <app-password>
428
+ ```
429
+
430
+ 3. Encrypt the per-user secret payload:
431
+ - `bunx brains-ops secrets:encrypt . <handle>`
432
+ 4. Reconcile/deploy the user or cohort:
433
+ - `bunx brains-ops onboard . <handle>`
434
+ - or `bunx brains-ops reconcile-cohort . <cohort>`
435
+ 5. Verify the generated `users/<handle>/brain.yaml` contains `plugins.atproto.identifier` (plus `accountDid` and `lexiconAuthority` when configured) and `appPassword: ${ATPROTO_APP_PASSWORD}`.
436
+
437
+ Notes:
155
438
 
156
- Use this when enabling Discord for a pilot user.
439
+ - The ATProto identifier and authority flag are public instance config and belong in `users/<handle>.yaml`. Only the DNS-designated authority account may set `lexiconAuthority: true`.
440
+ - The ATProto app password is secret and belongs only in the encrypted per-user secret payload.
441
+ - For smoke deployments, pin only the smoke cohort/user to the released brain version that contains ATProto support.
157
442
 
158
- 1. Pick the user handle (for example `smoke`).
443
+ ## Discord application credential checklist
444
+
445
+ Discord is optional. Browser chat with passkey setup is the default pilot interface. Use this checklist only when enabling Discord for a user.
446
+
447
+ 1. Add the user with Discord enabled:
448
+ - `bunx brains-ops user:add . <handle> --cohort <cohort> --discord`
449
+ - Add `--anchor-id <discord-user-id>` if the user should be a Discord anchor. For compatibility, `--anchor-id` also enables Discord when `--discord` is omitted.
159
450
  2. Open the Discord Developer Portal.
160
- 3. Create a **new application** for that user's rover.
451
+ 3. Create a **new application** for that user's brain.
161
452
  4. Add a **Bot** to the application.
162
- 5. Copy the bot token.
163
- 6. Put that value in `.env` or `.env.local` in this repo as `DISCORD_BOT_TOKEN=...` while onboarding that user.
164
- 7. Keep `discord.enabled: true` in `users/<handle>.yaml` unless you explicitly want to disable the primary pilot interface.
165
- 8. Encrypt the current per-user secret payload:
453
+ 5. Copy the bot token, application public key, and application ID.
454
+ 6. Put those values in `.env` or `.env.local` while onboarding that user:
455
+ - `DISCORD_BOT_TOKEN=...`
456
+ - `DISCORD_PUBLIC_KEY=...`
457
+ - `DISCORD_APPLICATION_ID=...`
458
+ 7. Confirm `users/<handle>.yaml` contains `discord.enabled: true` and its secrets template contains `discordBotToken`.
459
+ 8. Encrypt the current per-user credential payload:
166
460
  - `bunx brains-ops secrets:encrypt . <handle>`
167
461
  9. Reconcile/deploy the user or cohort:
168
-
169
- - `bunx brains-ops onboard . <handle>`
170
- - or `bunx brains-ops reconcile-cohort . <cohort>`
171
-
172
- 11. In the Discord Developer Portal, generate an install URL and invite the bot to the right server.
173
- 12. Send a test message in Discord and confirm the rover responds.
462
+ - `bunx brains-ops onboard . <handle>`
463
+ - or `bunx brains-ops reconcile-cohort . <cohort>`
464
+ 10. In the Discord Developer Portal, generate an install URL and invite the bot to the right server.
465
+ 11. Send a test message in Discord and confirm the brain responds.
174
466
 
175
467
  Notes:
176
468
 
177
- - Use **one bot token per user/rover**.
178
- - Do not reuse the same Discord bot token across multiple pilot users.
179
- - Discord is the default pilot interface moving forward.
469
+ - Use **one Discord application credential set per user/brain**.
470
+ - Do not reuse the same Discord application across multiple pilot users.
471
+ - Discord-disabled users generate `anchors: []`, no `plugins.discord` block, and require no Discord secret.
180
472
  - The encrypted `users/<handle>.secrets.yaml.age` file is the durable checked-in deploy input; your local env is only the operator staging source.
181
473
  - Direct MCP client access should use OAuth/passkey-capable clients where possible.
182
474
  - When explaining the content workflow, describe it first as a normal **git repo** of **markdown/text files**.