@rizom/ops 0.2.0-alpha.19 → 0.2.0-alpha.190

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 (45) hide show
  1. package/README.md +3 -1
  2. package/dist/brains-ops.js +282 -195
  3. package/dist/cert-bootstrap.d.ts +3 -1
  4. package/dist/content-repo-ref.d.ts +10 -0
  5. package/dist/content-repo.d.ts +1 -0
  6. package/dist/deploy.js +99 -166
  7. package/dist/entries/deploy.d.ts +3 -2
  8. package/dist/images.d.ts +76 -0
  9. package/dist/index.d.ts +3 -0
  10. package/dist/index.js +283 -195
  11. package/dist/load-registry.d.ts +21 -2
  12. package/dist/observed-status.d.ts +1 -1
  13. package/dist/origin-ca.d.ts +1 -1
  14. package/dist/parse-args.d.ts +3 -0
  15. package/dist/push-secrets.d.ts +2 -9
  16. package/dist/push-target.d.ts +1 -2
  17. package/dist/run-command.d.ts +1 -1
  18. package/dist/run-subprocess.d.ts +1 -6
  19. package/dist/schema.d.ts +62 -155
  20. package/dist/secrets-encrypt.d.ts +5 -13
  21. package/dist/ssh-key-bootstrap.d.ts +1 -26
  22. package/dist/user-add.d.ts +15 -0
  23. package/dist/verify-user.d.ts +19 -0
  24. package/package.json +44 -42
  25. package/templates/rover-pilot/.env.schema +17 -3
  26. package/templates/rover-pilot/.github/workflows/build.yml +64 -17
  27. package/templates/rover-pilot/.github/workflows/deploy.yml +100 -61
  28. package/templates/rover-pilot/.github/workflows/reconcile.yml +21 -1
  29. package/templates/rover-pilot/README.md +3 -1
  30. package/templates/rover-pilot/deploy/scripts/decrypt-user-secrets.ts +34 -6
  31. package/templates/rover-pilot/deploy/scripts/helpers.ts +3 -0
  32. package/templates/rover-pilot/deploy/scripts/resolve-deploy-handles.ts +12 -3
  33. package/templates/rover-pilot/deploy/scripts/resolve-missing-images.ts +13 -0
  34. package/templates/rover-pilot/deploy/scripts/resolve-user-config.ts +22 -2
  35. package/templates/rover-pilot/deploy/scripts/sync-content-repo.ts +51 -47
  36. package/templates/rover-pilot/deploy/scripts/update-dns.ts +14 -4
  37. package/templates/rover-pilot/deploy/scripts/validate-secrets.ts +1 -1
  38. package/templates/rover-pilot/docs/onboarding-checklist.md +32 -12
  39. package/templates/rover-pilot/docs/operator-playbook.md +117 -6
  40. package/templates/rover-pilot/docs/user-onboarding.md +67 -332
  41. package/templates/rover-pilot/pilot.yaml +1 -1
  42. package/templates/rover-pilot/.kamal/hooks/pre-deploy +0 -9
  43. package/templates/rover-pilot/deploy/Caddyfile +0 -67
  44. package/templates/rover-pilot/deploy/Dockerfile +0 -38
  45. package/templates/rover-pilot/deploy/kamal/deploy.yml +0 -40
@@ -5,53 +5,6 @@ import { dirname, join } from "node:path";
5
5
  import { execFileSync } from "node:child_process";
6
6
  import { readJsonResponse, requireEnv } from "./helpers";
7
7
 
8
- const handle = requireEnv("HANDLE");
9
- const contentRepo = requireEnv("CONTENT_REPO");
10
- const token = requireEnv("GIT_SYNC_TOKEN");
11
- const sourceDir = join("users", handle, "content");
12
-
13
- if (!existsSync(sourceDir)) {
14
- process.exit(0);
15
- }
16
-
17
- const { owner, repo } = parseRepoSlug(contentRepo);
18
- await ensureGitHubRepo({ owner, repo, token });
19
-
20
- const tempRoot = await mkdtemp(join(tmpdir(), "brains-ops-content-"));
21
- const checkoutDir = join(tempRoot, "repo");
22
- const remoteUrl = buildAuthenticatedRemoteUrl(owner, repo, token);
23
-
24
- runGit(["clone", remoteUrl, checkoutDir]);
25
- runGit(["-C", checkoutDir, "checkout", "-B", "main"]);
26
-
27
- const copiedFiles = await copyMissingFiles(sourceDir, checkoutDir);
28
- if (copiedFiles === 0) {
29
- process.exit(0);
30
- }
31
-
32
- runGit(["-C", checkoutDir, "config", "user.name", "brains-ops[bot]"]);
33
- runGit([
34
- "-C",
35
- checkoutDir,
36
- "config",
37
- "user.email",
38
- "41898282+github-actions[bot]@users.noreply.github.com",
39
- ]);
40
- runGit(["-C", checkoutDir, "add", "."]);
41
-
42
- if (hasNoStagedChanges(checkoutDir)) {
43
- process.exit(0);
44
- }
45
-
46
- runGit([
47
- "-C",
48
- checkoutDir,
49
- "commit",
50
- "-m",
51
- `chore(content): seed ${handle} anchor profile`,
52
- ]);
53
- runGit(["-C", checkoutDir, "push", "origin", "HEAD:main"]);
54
-
55
8
  const STALE_ANCHOR_PROFILE_MARKERS = [
56
9
  "name: Your Name Here",
57
10
  "Delete this and write your own",
@@ -68,6 +21,55 @@ interface GitHubRepoResponse {
68
21
  private?: boolean;
69
22
  }
70
23
 
24
+ async function main(): Promise<void> {
25
+ const handle = requireEnv("HANDLE");
26
+ const contentRepo = requireEnv("CONTENT_REPO");
27
+ const token = requireEnv("GIT_SYNC_TOKEN");
28
+ const sourceDir = join("users", handle, "content");
29
+
30
+ if (!existsSync(sourceDir)) {
31
+ return;
32
+ }
33
+
34
+ const { owner, repo } = parseRepoSlug(contentRepo);
35
+ await ensureGitHubRepo({ owner, repo, token });
36
+
37
+ const tempRoot = await mkdtemp(join(tmpdir(), "brains-ops-content-"));
38
+ const checkoutDir = join(tempRoot, "repo");
39
+ const remoteUrl = buildAuthenticatedRemoteUrl(owner, repo, token);
40
+
41
+ runGit(["clone", remoteUrl, checkoutDir]);
42
+ runGit(["-C", checkoutDir, "checkout", "-B", "main"]);
43
+
44
+ const copiedFiles = await copyMissingFiles(sourceDir, checkoutDir);
45
+ if (copiedFiles === 0) {
46
+ return;
47
+ }
48
+
49
+ runGit(["-C", checkoutDir, "config", "user.name", "brains-ops[bot]"]);
50
+ runGit([
51
+ "-C",
52
+ checkoutDir,
53
+ "config",
54
+ "user.email",
55
+ "41898282+github-actions[bot]@users.noreply.github.com",
56
+ ]);
57
+ runGit(["-C", checkoutDir, "add", "."]);
58
+
59
+ if (hasNoStagedChanges(checkoutDir)) {
60
+ return;
61
+ }
62
+
63
+ runGit([
64
+ "-C",
65
+ checkoutDir,
66
+ "commit",
67
+ "-m",
68
+ `chore(content): seed ${handle} anchor profile`,
69
+ ]);
70
+ runGit(["-C", checkoutDir, "push", "origin", "HEAD:main"]);
71
+ }
72
+
71
73
  async function ensureGitHubRepo(
72
74
  options: EnsureGitHubRepoOptions,
73
75
  ): Promise<void> {
@@ -177,3 +179,5 @@ function isStaleAnchorProfile(content: string): boolean {
177
179
  content.includes(marker),
178
180
  );
179
181
  }
182
+
183
+ await main();
@@ -16,8 +16,11 @@ interface CloudflareResult {
16
16
  result?: Array<{ id: string }>;
17
17
  }
18
18
 
19
- async function upsertRecord(name: string): Promise<void> {
20
- const lookupUrl = `${baseUrl}/zones/${zoneId}/dns_records?type=A&name=${encodeURIComponent(name)}`;
19
+ async function findRecordId(
20
+ name: string,
21
+ type: "A" | "CNAME",
22
+ ): Promise<string | undefined> {
23
+ const lookupUrl = `${baseUrl}/zones/${zoneId}/dns_records?type=${type}&name=${encodeURIComponent(name)}`;
21
24
  const lookup = await fetch(lookupUrl, { headers });
22
25
  const payload = (await readJsonResponse(
23
26
  lookup,
@@ -27,9 +30,16 @@ async function upsertRecord(name: string): Promise<void> {
27
30
  throw new Error(`Cloudflare DNS lookup failed: ${JSON.stringify(payload)}`);
28
31
  }
29
32
 
30
- const existing = payload.result?.[0];
33
+ return payload.result?.[0]?.id;
34
+ }
35
+
36
+ async function upsertRecord(name: string): Promise<void> {
37
+ // Prefer an existing A record. If the hostname currently has a CNAME,
38
+ // replace that CNAME in-place so deploys can claim legacy www aliases.
39
+ const existing =
40
+ (await findRecordId(name, "A")) ?? (await findRecordId(name, "CNAME"));
31
41
  const url = existing
32
- ? `${baseUrl}/zones/${zoneId}/dns_records/${existing.id}`
42
+ ? `${baseUrl}/zones/${zoneId}/dns_records/${existing}`
33
43
  : `${baseUrl}/zones/${zoneId}/dns_records`;
34
44
 
35
45
  const response = await fetch(url, {
@@ -4,7 +4,7 @@ import { parseEnvSchema } from "./helpers";
4
4
  const envSchemaPath = ".env.schema";
5
5
  const schema = parseEnvSchema(readFileSync(envSchemaPath, "utf8"));
6
6
  const requiredKeys = schema
7
- .filter((entry) => entry.required)
7
+ .filter((entry) => entry.required && entry.key !== "BWS_ACCESS_TOKEN")
8
8
  .map((entry) => entry.key);
9
9
 
10
10
  const missing: string[] = [];
@@ -4,23 +4,43 @@
4
4
  2. Run `bunx brains-ops age-key:bootstrap <repo> --push-to gh`.
5
5
  3. Fill in `pilot.yaml`.
6
6
  - keep your pinned `brainVersion`
7
- - confirm shared selectors for `aiApiKey`, `gitSyncToken`, and `mcpAuthToken`
7
+ - confirm shared selectors for `aiApiKey`, `gitSyncToken`, and `contentRepoAdminToken`
8
+ - use different tokens for `contentRepoAdminToken` and `gitSyncToken`: admin creates/checks content repos; sync is used by runtime directory-sync
8
9
  - confirm `agePublicKey`
9
- 4. Add or edit `users/<handle>.yaml`.
10
- - Discord is enabled by default for pilot users
11
- - if the user should be an anchor there, set `discord.anchorUserId` to their Discord user ID
12
- 5. Add the user to a cohort in `cohorts/*.yaml`.
10
+ 4. Run `bunx brains-ops user:add <repo> <handle> --cohort <cohort>`.
11
+ - Web chat is the primary interface; it needs no per-user setup beyond the passkey.
12
+ - `user:add` currently writes `discord: enabled: true`; set it to `false` unless the user's cohort actually uses Discord.
13
+ - if the user should be an anchor on Discord, add `--anchor-id <discord-user-id>`.
14
+ - the command creates `users/<handle>.yaml`, `users/<handle>.secrets.yaml`, and the cohort membership without duplicating existing entries.
15
+ 5. Edit the generated user file if the anchor profile needs richer metadata.
16
+ - Set `setup.delivery: email` and `setup.email` so the user gets the passkey setup email — this is the default onboarding path.
17
+ - For ATProto publishing, add `atproto.identifier` to the user file; put only `atprotoAppPassword` in the per-user secrets file.
18
+ - Ensure `SETUP_EMAIL_API_KEY` and `SETUP_EMAIL_FROM` exist as GitHub Secrets before deploying any email-setup user.
13
19
  6. Run `bunx brains-ops render <repo>`.
14
20
  7. Run `bunx brains-ops ssh-key:bootstrap <repo> --push-to gh`.
15
21
  8. Run `bunx brains-ops cert:bootstrap <repo> --push-to gh`.
16
- 9. Keep raw user secret material locally for now (`.env.local`, file-backed env vars, or equivalent local inputs).
22
+ 9. Keep raw user secret material locally for now (`.env.local`, file-backed env vars, or equivalent local inputs), including `CONTENT_REPO_ADMIN_TOKEN` for operator onboarding.
17
23
  10. Run `bunx brains-ops secrets:encrypt <repo> <handle>`.
18
24
  11. Commit and push `users/<handle>.secrets.yaml.age`.
19
25
  12. Run `bunx brains-ops onboard <repo> <handle>`.
20
- 13. Verify the deployed rover core contract:
21
- - `https://<handle>.rizom.ai/health` returns `200`
22
- - unauthenticated `POST https://<handle>.rizom.ai/mcp` returns `401`
26
+ 13. Verify the deployed Rover contract:
27
+ - all presets:
28
+ - `https://<handle>.rizom.ai/health` returns `200`
29
+ - `https://<handle>.rizom.ai/chat` loads the web chat and accepts passkey sign-in
30
+ - `https://<handle>.rizom.ai/` loads the dashboard (or site surface on `default` preset)
31
+ - `https://<handle>.rizom.ai/cms` loads the CMS/login surface
32
+ - unauthenticated `POST https://<handle>.rizom.ai/mcp` returns the expected auth failure
33
+ - content repo exists and runtime sync is healthy
34
+ - background jobs are not repeatedly failing, except for expected missing optional integrations
35
+ - for `presetOverride: default` users:
36
+ - initial site build completes
23
37
  14. For fleet upgrades, edit `pilot.yaml.brainVersion` and push once; CI rebuilds the shared image tag, refreshes generated user env files, and redeploys affected users.
24
- 15. Hand the Discord setup details to the user. If they need direct client access, also hand over the MCP connection details.
25
- 16. If you are also giving them a content repo workflow, describe it first as a normal git repo of markdown/text files; mention Obsidian only as an optional editor.
26
- 17. Send `docs/user-onboarding.md` to the user as the pilot handoff guide.
38
+ 15. Confirm the user received the setup email, registered their passkey, and can sign in to web chat at `https://<handle>.rizom.ai/chat`. That completes the default onboarding; everything below is per-cohort extras.
39
+ 16. Hand over the browser surfaces:
40
+ - Chat (primary): `https://<handle>.rizom.ai/chat`
41
+ - Dashboard: `https://<handle>.rizom.ai/`
42
+ - CMS: `https://<handle>.rizom.ai/cms`, plus GitHub token guidance if CMS editing is part of their cohort
43
+ 17. For Discord-enabled cohorts, hand the Discord setup details to the user as a secondary chat surface.
44
+ 18. If they need direct client access (MCP), use OAuth/passkey-capable clients where possible.
45
+ 19. If you are also giving them a content repo workflow, describe it as optional and frame git/Obsidian as an advanced file-based path, not the default.
46
+ 20. Send `docs/user-onboarding.md` to the user as the pilot handoff guide.
@@ -60,15 +60,126 @@ When `@rizom/ops` changes the scaffolded deploy contract:
60
60
  3. review the resulting changes to `.env.schema`, `deploy/scripts/`, and workflows in git
61
61
  4. commit the updated deploy artifacts together
62
62
 
63
- ## Rover-core verification notes
63
+ ## Rover verification notes
64
64
 
65
- Rover core is MCP-only. Do not expect the bare domain to serve a website.
65
+ Use the verification script after deploy:
66
66
 
67
- Use these checks after deploy:
67
+ ```sh
68
+ bunx brains-ops verify-user . <handle>
69
+ ```
70
+
71
+ It checks every Rover preset:
68
72
 
69
73
  - `https://<handle>.rizom.ai/health` should return `200`
70
- - unauthenticated `POST https://<handle>.rizom.ai/mcp` should return `401 Unauthorized: Bearer token required`
71
- - a bare `GET /` may also return `401`; that is expected for rover core and does not indicate a bad deploy
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
76
+
77
+ Additional `rover:core` note:
78
+
79
+ - Rover core is MCP-only; a bare `GET /` may return `401`, which does not indicate a bad deploy.
80
+
81
+ For `preset: default`, the script also checks:
82
+
83
+ - `https://<handle>.rizom.ai/` loads the browser/site surface
84
+ - `https://<handle>.rizom.ai/cms` loads the CMS/login surface
85
+
86
+ Manual checks that remain:
87
+
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
91
+
92
+ ## One-user `rover:default` baseline canary
93
+
94
+ Run this before adding custom site/theme packages or rolling a larger browser/CMS-first cohort.
95
+
96
+ 1. Create or choose a canary cohort with the default preset:
97
+
98
+ ```yaml
99
+ presetOverride: default
100
+ ```
101
+
102
+ 2. Add exactly one canary user to that cohort.
103
+ 3. For browser/CMS-first onboarding, configure setup email in `users/<handle>.yaml`:
104
+
105
+ ```yaml
106
+ setup:
107
+ delivery: email
108
+ email: user@example.com
109
+ ```
110
+
111
+ 4. Encrypt the user's secrets and commit only the `.age` file.
112
+ 5. Run `bunx brains-ops onboard . <handle>`.
113
+ 6. Run `bunx brains-ops verify-user . <handle>` with no custom site/theme overrides.
114
+ 7. Ask the user to complete passkey setup from the setup email.
115
+ 8. Continue to visual customization only after the canary is healthy.
116
+
117
+ Rollback:
118
+
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
122
+
123
+ ## Setup email checklist
124
+
125
+ Use this for browser/CMS-first users who should receive their own first-passkey setup link by email.
126
+
127
+ 1. Add setup delivery to the user file:
128
+
129
+ ```yaml
130
+ setup:
131
+ delivery: email
132
+ email: user@example.com
133
+ ```
134
+
135
+ 2. Configure these GitHub Secrets before deploy:
136
+ - `SETUP_EMAIL_API_KEY`
137
+ - `SETUP_EMAIL_FROM`
138
+
139
+ 3. Reconcile/deploy the user or cohort:
140
+ - `bunx brains-ops onboard . <handle>`
141
+ - or `bunx brains-ops reconcile-cohort . <cohort>`
142
+
143
+ 4. Verify the generated `users/<handle>/brain.yaml` contains `auth-service.setupEmail` and `email-resend` config.
144
+ 5. Ask the user to complete passkey setup from the email link, then use:
145
+ - Dashboard: `https://<handle>.rizom.ai/`
146
+ - CMS: `https://<handle>.rizom.ai/cms`
147
+
148
+ Notes:
149
+
150
+ - The setup URL is generated and sent by the running brain; operators should not scrape logs or SSH into the instance to retrieve it.
151
+ - 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
+ - `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
+
154
+ ## AT Protocol smoke/config checklist
155
+
156
+ Use this when enabling AT Protocol publishing for a single pilot user.
157
+
158
+ 1. Add the public PDS identifier to the user file:
159
+
160
+ ```yaml
161
+ atproto:
162
+ identifier: rizom-test.bsky.social
163
+ ```
164
+
165
+ 2. Put the app password in `users/<handle>.secrets.yaml`:
166
+
167
+ ```yaml
168
+ atprotoAppPassword: <app-password>
169
+ ```
170
+
171
+ 3. Encrypt the per-user secret payload:
172
+ - `bunx brains-ops secrets:encrypt . <handle>`
173
+ 4. Reconcile/deploy the user or cohort:
174
+ - `bunx brains-ops onboard . <handle>`
175
+ - or `bunx brains-ops reconcile-cohort . <cohort>`
176
+ 5. Verify the generated `users/<handle>/brain.yaml` contains `plugins.atproto.identifier` and `appPassword: ${ATPROTO_APP_PASSWORD}`.
177
+
178
+ Notes:
179
+
180
+ - The ATProto identifier is public instance config and belongs in `users/<handle>.yaml`.
181
+ - The ATProto app password is secret and belongs only in the encrypted per-user secret payload.
182
+ - For smoke deployments, pin only the smoke cohort/user to the released brain version that contains ATProto support.
72
183
 
73
184
  ## Discord bot token checklist
74
185
 
@@ -97,7 +208,7 @@ Notes:
97
208
  - Do not reuse the same Discord bot token across multiple pilot users.
98
209
  - Discord is the default pilot interface moving forward.
99
210
  - The encrypted `users/<handle>.secrets.yaml.age` file is the durable checked-in deploy input; your local env is only the operator staging source.
100
- - MCP is optional and mainly for direct client access or specific testing workflows.
211
+ - Direct MCP client access should use OAuth/passkey-capable clients where possible.
101
212
  - When explaining the content workflow, describe it first as a normal **git repo** of **markdown/text files**.
102
213
  - Position **Obsidian** as optional: it is just one possible editor for those same files, not the default requirement.
103
214