Bootstrap the demo stage, give it generated secrets, and write down what each stage holds
Before adoption: this commit came in with the history the project adopted, so no landing records it.
- `bun run bootstrap -- --stage demo` made projects-demo, layers-demo, front-page-demo (migrations 0001 to 0004 applied), oauth-demo, evidence-demo and releases-demo, and wrote the D1 and KV ids into demo's block of apps/platform/wrangler.jsonc. Red first: the dry run listed six to create; a second real run created 0 and found every required secret, and the dry run then said "would create 0". dev-oscabriel re-checked the same way: created 0, every required secret present. - Demo's secrets are generated, as the dev stage's are (the orchestrator's decision under the user's blanket yes, extending the recorded dev-only rule to demo): OPERATOR_TOKEN, COOKIE_KEY, PASSWORD_PEPPER (32 random bytes, base64url), MASTER_KEY (64 hex) and SESSION_TOKENS for bram, ines-v, okafor, okonkwo, lin-h, wren, tamsin, ivo, marisol, dagny and pell, kept only in a mode-600 file outside the repo, set with `wrangler secret put <NAME> --env demo` from stdin, never printed. The first put made platform-demo as a placeholder Worker (no code, no workers.dev route) until the demo's first deploy. - infra/deploy.ts takes STAGE_SECRETS_FILE for demo too, and SecretsFileNotForStage is gone: varlock-wrangler resolves every required name on each deploy, so without the file demo's first deploy could not resolve its secrets. Test: deploy.test.ts's demo case now holds that the platform step alone gets the file's values, and the message test names an unreadable file instead. - infra/stages.md has the six parts the teardown and the user need: stages, resources per stage (name, created by, when, keep), the throwaway ledger summary plus the pre-ledger leftovers on dev-oscabriel, the teardown policy, the status of every human step on 2026-10-08 (rotate both stages' generated secrets before going public), and the URLs. The how-to sections follow under "Running a stage". - H6 confirmed from evidence: the account's subscriptions, read again, list workers_paid as Paid, and the sandbox's containers and both Workflows have run on dev-oscabriel since 2026-10-07. - ASSUMPTION: a placeholder Worker made by `wrangler secret put` is replaced cleanly by the first `wrangler deploy` (it has no migrations tag, so every Durable Object migration applies); the demo's deploy shows it.
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
5 files+191 added−69 removed
- tests:+42 added−10 removed
- other:+149 added−59 removed
Provenance
- Commit
d5649f9- Tree
fe5a126- Author
oscabriel <oscarhernandeziv@gmail.com>- Committer
oscabriel <oscarhernandeziv@gmail.com>- Parent
61ef4c0
5 files changed+191 added−69 removed
modified:apps/platform/wrangler.jsonc+2 added-2 removed
228 unmodified lines229 "d1_databases": [230 {231 "binding": "FRONT_PAGE",232 "database_name": "front-page-demo",233- "database_id": "00000000-0000-0000-0000-000000000000",233+ "database_id": "a83fc9b1-1414-4d9c-b83c-b1e468cfc5d4",234 "migrations_dir": "migrations",235 },236 ],237 // KV namespace `oauth-demo`.238 "kv_namespaces": [239- { "binding": "OAUTH_KV", "id": "00000000000000000000000000000000" },239+ { "binding": "OAUTH_KV", "id": "c9b3fb4d9bd04b458051519f2f8cd0e8" },240 ],241 "r2_buckets": [242 { "binding": "EVIDENCE", "bucket_name": "evidence-demo" },243 { "binding": "RELEASES", "bucket_name": "releases-demo" },34 unmodified linesmodified:infra/.env.schema+3 added-3 removed
24 unmodified lines25 26 # Nothing here is a person's token. The swarm (`bun run swarm`) signs in as27 # the demo's fictional people with apps/platform/.env.schema's28 # SESSION_TOKENS, run as `bunx varlock run --path apps/platform/ -- bun29-# scripts/swarm.ts …`, so no script or agent reads a `.env*` file. On a dev30-# stage those tokens come from the stage's secrets file outside the repo31-# (STAGE_SECRETS_FILE, infra/stages.md); on `demo` a person sets them.29+# scripts/swarm.ts …`, so no script or agent reads a `.env*` file. On every30+# stage those tokens come from the stage's generated secrets file outside the31+# repo (STAGE_SECRETS_FILE, infra/stages.md).modified:infra/deploy.ts+7 added-29 removed
19 unmodified lines20 * with its own login, never the read-mostly infra token.21 *22 * `STAGE_SECRETS_FILE` names a dotenv file outside the repo whose values the23 * platform's deploy carries as its environment, which varlock reads before24- * any `.env` file (spec §8.3 O1: the dev stage's generated secrets). Only the25- * items `apps/platform/.env.schema` declares are passed, to that one step,26- * and no value is ever printed. With `--stage demo` it refuses the file27- * before it spawns anything: demo's secrets are a person's to set (H5).24+ * any `.env` file: a stage's generated secrets, on every stage (spec §8.325+ * O1, extended to demo). Only the items `apps/platform/.env.schema` declares26+ * are passed, to that one step, and no value is ever printed.27 *28 * Each step runs with its own folder's `node_modules/.bin` first on `PATH`,29 * since `varlock-wrangler` starts `wrangler` by name.30 */42 unmodified lines73 return `STAGE_SECRETS_FILE names ${this.file}, which can't be read`;74 }75 }76 78-/**79- * `STAGE_SECRETS_FILE` was given for `demo`: generated secrets are the dev80- * stage's alone, and `demo`'s are a person's to set (spec §8.3 O1, H5).81- */82-export class SecretsFileNotForStage extends Schema.TaggedError<SecretsFileNotForStage>()(83- "SecretsFileNotForStage",84- { stage: Schema.String }85-) {86- override get message() {87- return `STAGE_SECRETS_FILE is for dev stages only: set ${this.stage}'s secrets with varlock (infra/stages.md)`;88- }89-}90-77 /** One command of the deploy, run from `cwd` (relative to the repo root). */78 interface Step {79 readonly name: string;80 readonly command: string;64 unmodified lines145 ];146 147 /**148 * The values `STAGE_SECRETS_FILE` holds for the items the platform's163- * `.env.schema` declares: none when it isn't set. Only a dev stage takes one.149+ * `.env.schema` declares: none when it isn't set.150 */165-const platformSecrets = (root: string, stage: Stage) =>151+const platformSecrets = (root: string) =>152 Effect.gen(function* () {153 const fs = yield* FileSystem.FileSystem;154 const path = yield* Path.Path;155 4 unmodified lines160 if (Option.isNone(file)) {161 return {};162 }163 178- if (stage === "demo") {179- return yield* new SecretsFileNotForStage({ stage });180- }181-164 const contents = yield* fs165 .readFileString(file.value)166 .pipe(167 Effect.mapError(() => new SecretsFileUnreadable({ file: file.value }))99 unmodified lines267 export const deploy = (268 argv: readonly string[]269 ): Effect.Effect<270 void,289- | NoStage290- | UnknownStage291- | StepFailed292- | SecretsFileUnreadable293- | SecretsFileNotForStage,271+ NoStage | UnknownStage | StepFailed | SecretsFileUnreadable,272 ChildProcessSpawner.ChildProcessSpawner | FileSystem.FileSystem | Path.Path273 > =>274 Effect.gen(function* () {275 const stage = yield* stageOf(argv);4 unmodified lines280 const web = yield* fs281 .exists(path.join(root, "apps/web/wrangler.jsonc"))282 .pipe(Effect.orDie);283 306- const platformEnv = yield* platformSecrets(root, stage);284+ const platformEnv = yield* platformSecrets(root);285 286 yield* Effect.forEach(287 stepsOf(stage, { platformEnv, web }),288 (step) => runStep(root, stage, step),16 unmodified linesmodified:infra/stages.md+137 added-25 removed
123456785610789101112131214151617181920212223242526272829301831323334353 unmodified lines39404142304344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421433214414534146147361481491501511522 unmodified lines1551561571584715916049161162163164531651665516716816917017117217362174175176651771781791801811827071183184185186751871881891901912 unmodified lines194195196197861981992002012022032042059420620720820921012 unmodified lines223224225226115227228117229230119231232233234235236# Stages
A stage is one full copy of the platform on Cloudflare: its own Workers, Workflows, Artifacts namespaces (public and private), database, KV namespace and buckets. `infra/stages.ts` is the one table of stage names and resource names. Every other file, both `wrangler.jsonc` files included, matches it, and `packages/config/test/bootstrap.test.ts` checks that they do.
| Stage | What it is for || --- | --- || `dev-<user>` | One person's iteration. Today there is one, `dev-oscabriel`. Deploy it as often as you like. || `demo` | The recording and the submission. Deploy it deliberately, and never while a take is being recorded (H7). |This file has six parts, then how to run a stage:
There is no `prod` stage before the deadline (spec §8 D13). The top level of each `wrangler.jsonc` is stage `local`, for tests and `wrangler dev`, and it is never deployed. A new person's stage is added to `stages` in `stages.ts` and gets an `env` block in each `wrangler.jsonc`, in the same change.1. [Stages](#1-stages)2. [Resources per stage](#2-resources-per-stage)3. [Throwaway ledger summary](#3-throwaway-ledger-summary)4. [Teardown policy](#4-teardown-policy)5. [Human steps status](#5-human-steps-status)6. [URLs](#6-urls)
## What a stage ownsSections 1 to 6 hold the state as of 2026-10-08, 14:00 UTC, read from the account with read-only calls.
## 1. Stages
| Stage | What it is for | State on 2026-10-08 || --- | --- | --- || `dev-oscabriel` | One person's iteration. Deploy it as often as you like. | Bootstrapped 2026-10-07 and deployed (platform, sandbox, web). Re-checked 2026-10-08: bootstrap created nothing, and the platform holds every required secret. || `demo` | The recording and the submission. Deploy it deliberately, and never while a take is being recorded (H7). | Bootstrapped 2026-10-08: six resources created, migrations `0001` to `0004` applied, and a second run created nothing. Its secrets are set. Its Workers aren't deployed yet. |
There is no `prod` stage before the deadline. The top level of each `wrangler.jsonc` is stage `local`, for tests and `wrangler dev`, and it is never deployed. A new person's stage is added to `stages` in `stages.ts` and gets an `env` block in each `wrangler.jsonc`, in the same change.
## 2. Resources per stage
Every name is a job name plus the stage, never the brand. For stage `<s>`:
| Resource | Name | Made by || --- | --- | --- || Workers | `platform-<s>`, `sandbox-<s>`, `web-<s>` (once `apps/web` exists) | deploy || Workers | `platform-<s>`, `sandbox-<s>`, `web-<s>` | deploy || Workflows | `answer-<s>`, `on-push-<s>` | deploy (they live in `platform-<s>`) || Artifacts namespace (public) | `projects-<s>` | bootstrap || Artifacts namespace (private: every project's layer repos, bound only by the platform) | `layers-<s>` | bootstrap || D1 database (the front page) | `front-page-<s>` | bootstrap |3 unmodified lines| Push-event trigger | `cf.artifacts.repo.pushed` on `projects-<s>`, starting `on-push-<s>` | deploy (`triggers.events` in `apps/platform/wrangler.jsonc`), read back by bootstrap |
The `witness` namespace belongs to another project. Nothing here reads, writes or deletes it, and neither should you.
## Before the first runEvery resource in the two tables below belongs to its stage. The times are the account's own creation times, in UTC. A KV namespace has no creation time, so its row gives the bootstrap run that made it.
### `dev-oscabriel`
| Resource | Name | Created by | When | Keep? || --- | --- | --- | --- | --- || Artifacts namespace | `projects-dev-oscabriel` | bootstrap | 2026-10-07 20:17 | keep (needs the user to delete) || D1 | `front-page-dev-oscabriel` | bootstrap | 2026-10-07 20:17 | keep (needs the user to delete) || KV | `oauth-dev-oscabriel` | bootstrap | 2026-10-07 (first run) | keep (needs the user to delete) || R2 | `evidence-dev-oscabriel` | bootstrap | 2026-10-07 20:17 | keep (needs the user to delete) || Worker | `sandbox-dev-oscabriel` | deploy | 2026-10-07 20:19 | keep (needs the user to delete) || Worker | `platform-dev-oscabriel` | deploy | 2026-10-07 20:19 | keep (needs the user to delete) || Workflow | `answer-dev-oscabriel` | deploy | 2026-10-07 20:19 | keep (needs the user to delete) || Workflow | `on-push-dev-oscabriel` | deploy | 2026-10-07 20:19 | keep (needs the user to delete) || Push-event trigger | `projects-dev-oscabriel` → `on-push-dev-oscabriel` | deploy | 2026-10-07 | keep (needs the user to delete) || R2 | `releases-dev-oscabriel` | bootstrap | 2026-10-08 01:02 | keep (needs the user to delete) || Worker | `web-dev-oscabriel` | deploy | 2026-10-08 05:17 | keep (needs the user to delete) || Artifacts namespace | `layers-dev-oscabriel` | bootstrap | 2026-10-08 09:58 | keep (needs the user to delete) || Secrets on `platform-dev-oscabriel` | `OPERATOR_TOKEN`, `SESSION_TOKENS`, `COOKIE_KEY`, `PASSWORD_PEPPER`, `MASTER_KEY` | generated, carried by deploy (see [Secrets](#secrets)) | 2026-10-07 and 2026-10-08 | keep (needs the user to delete); rotate before going public || Seeded projects | `datekit` (with its `datekit--maintainers` layer repo) and `burrow` in `projects-dev-oscabriel` | seed | 2026-10-07 and 2026-10-08 | keep while the dev stage is used |
### `demo`
| Resource | Name | Created by | When | Keep? || --- | --- | --- | --- | --- || Artifacts namespace | `projects-demo` | bootstrap | 2026-10-08 13:57 | keep (needs the user to delete) || Artifacts namespace | `layers-demo` | bootstrap | 2026-10-08 13:57 | keep (needs the user to delete) || D1 | `front-page-demo`, with migrations `0001` to `0004` | bootstrap | 2026-10-08 13:57 | keep (needs the user to delete) || KV | `oauth-demo` | bootstrap | 2026-10-08 13:57 (the run) | keep (needs the user to delete) || R2 | `evidence-demo` | bootstrap | 2026-10-08 13:57 | keep (needs the user to delete) || R2 | `releases-demo` | bootstrap | 2026-10-08 13:57 | keep (needs the user to delete) || Worker | `platform-demo`: a placeholder with no code and no workers.dev route, made by the first `wrangler secret put` to hold the secrets. The first deploy replaces its code. | `wrangler secret put` | 2026-10-08 13:58 | keep (needs the user to delete) || Secrets on `platform-demo` | `OPERATOR_TOKEN`, `SESSION_TOKENS`, `COOKIE_KEY`, `PASSWORD_PEPPER`, `MASTER_KEY` | generated, set with `wrangler secret put` (see [Secrets](#secrets)) | 2026-10-08 13:58 | keep (needs the user to delete); rotate before going public || Workers, Workflows and trigger | `sandbox-demo`, `web-demo`, `answer-demo`, `on-push-demo`, the push-event trigger | deploy | not yet: the demo's first deploy | keep (needs the user to delete) |
## 3. Throwaway ledger summary
A throwaway is something a smoke run, a swarm run or a `seed --as` copy makes on a stage, beside the stage's own resources. Each run appends one JSON line for each throwaway to `infra/created.jsonl` (`infra/created.ts`), and teardown acts only on those lines.
On 2026-10-08 the ledger holds one entry, which still exists:
| When | By | Kind | Name | Where || --- | --- | --- | --- | --- || 2026-10-08 12:37 | swarm | repo | `burrow--drop-legacy-fetch-burrow-auth--wren` (a released claim's fork) | `projects-dev-oscabriel` |
The live runs before the ledger existed left throwaways that it doesn't hold, all on `dev-oscabriel`. Teardown lists them separately and checks each one still exists before it deletes anything:
- In `projects-dev-oscabriel`, 25 repos on 2026-10-08. Two of them, `datekit` and `burrow`, are the stage's seeded examples, and their working and claim forks (`datekit--me--ines-v`, `datekit--format-ordinal--bram`, `datekit--add-months-clamp--bram`) belong to them. The rest are test projects and their forks: `w3live-muyjz31t`, `w3live-muyk0528`, `w3live-muyk72qm`, `w3live-muykamf1`, `w3live-muyklikt` (with `--parse-iso--alice`), `w3live-muyl0wps` (with `--parse-iso--alice`), `w3live-muyl2z12` (with `--parse-iso--alice`), `scratch-onpush-muykseuk`, `w4-rehearsal` (with `--first-day--alice`, `--canada-sunday--alice`, `--brazil-sunday--alice` and `--mexico-sunday--alice`), and `w4-ratchet` (with `--no-any-in-parser--alice` and `--pad-day--bob`).- The secret `S8B_PROBE` on `platform-dev-oscabriel`.- The test accounts `w3tester-muyk9zdx` and `w5web-muz3airr` in `front-page-dev-oscabriel`, and the latter's OAuth grant in `oauth-dev-oscabriel`.- The Project Durable Objects and front-page rows of those test projects. They are harmless and are not deleted.
`demo` has no throwaways, and nothing that makes them is meant to run there: the core-loop smoke and the swarm's rehearsals run on the dev stage, the swarm on a `seed --as` copy.
## 4. Teardown policy
- This build deletes only throwaway resources recorded in `infra/created.jsonl` that it no longer needs.- It never deletes a stage's Workers, namespaces, D1, KV or R2 without the user.- It never touches `witness`.
No agent deletes a Cloudflare resource itself. Teardown first prints its plan: the ledger's entries that still exist, minus every stage's own names and `witness`. The deletes in that plan, together with the pre-ledger leftovers in section 3 that still exist, are written into one script that the user reads and then runs in their own terminal. A stage itself is torn down only by hand, by the user, as [Tear down a stage](#tear-down-a-stage) says.
## 5. Human steps status
As of 2026-10-08, after the demo's bootstrap. "Agent" is the build's agent.
| Step | Status | What the agent prepared | What the user does next || --- | --- | --- | --- || H1: a custom domain | Not done, and optional. The stages live on workers.dev. | Nothing needs it. | If wanted, buy the domain and say so. The agent then adds `routes` to each `wrangler.jsonc` and redeploys `demo`. || H2: the npm org and publishing the CLI | Open. | `bun run release -- --build` stages the npm package in `apps/cli/release/npm/`. `--publish` runs every other step and prints the publish command. | Create the npm org, run `npm login`, then `npm publish apps/cli/release/npm --access public` in your own terminal. || H3: the GitHub org and the public repo | Open, due before submission (Oct 14). | Every commit is on local `main`. No remote exists and nothing has been pushed. | Create the org and an empty public repo, then `git remote add origin …` and push. Before that, rotate the generated secrets (the H5 row). || H4: a Google OAuth client | Not done, and optional. Sign-in works with platform accounts (a handle and a password). | The redirect URIs are in [section 6](#6-urls). Migrations `0003_identities.sql` and later are applied on both stages. | Only if Google sign-in is wanted: create a Web client with the stage's redirect URI, set `GOOGLE_CLIENT_ID` and `GOOGLE_CLIENT_SECRET` together, then redeploy. || H5: secret values | Done by the agent on both stages, under a recorded decision that extends generated secrets to `demo` (see [Secrets](#secrets)). Not blocking. | Five values per stage, generated and kept only in that stage's secrets file outside the repo (mode 600), never printed or committed. `SESSION_TOKENS` on `demo` holds bram, ines-v, okafor, okonkwo, lin-h and the swarm's six (wren, tamsin, ivo, marisol, dagny, pell). | **Rotate both stages' generated secrets before the repo goes public**, and keep a copy of each stage's `MASTER_KEY` somewhere other than this machine. Rotating `PASSWORD_PEPPER` breaks every stored password, rotating `MASTER_KEY` loses every stored env value unless they are re-wrapped first, and rotating `SESSION_TOKENS` means each CLI profile logs in again. || H6: Workers Paid | Confirmed. | The account's subscriptions, read again on 2026-10-08, list `workers_paid` as Paid. The sandbox (containers) and both Workflows have run on `dev-oscabriel` since 2026-10-07. | Nothing. || H7: the recording | Open (Oct 13). | `docs/demo/` holds the script, the shot list and the rehearsal checklist. The demo stage is bootstrapped. Its deploy, seed, rehearsal and a recording lock for deploys come next. | Record with no deploys during takes. || H8: submitting | Open, due Oct 14 by noon PDT. | Nothing yet. The demo URL comes after the demo's deploy (section 6). | Submit the repo URL, the video and the demo URL. || H9: `docker login` | Not needed so far. No image pull has been rate-limited. | Nothing. | Only if a deploy's image pull is rate-limited: run `docker login` in your own terminal. || OpenCode Zen key for the swarm's pell | Open. | pell is planned on `opencode/gemini-3.8-flash`. The fallback, a one-line swap to `opencode-go/qwen3.8-flash`, is recorded. | Add OpenCode Zen's key to pi, or accept the fallback. || Deleting the throwaways | Open, after the rehearsal. | The teardown plan (section 4). | Read the teardown script and run it in your own terminal. |
## 6. URLs
The account's workers.dev subdomain is in `infra/workers-dev.json`. The demo's rows are filled in when it is deployed.
| Stage | What | URL | State on 2026-10-08 || --- | --- | --- | --- || `dev-oscabriel` | platform | `https://platform-dev-oscabriel.oscargabriel.workers.dev` | deployed (`/health` answers 200) || `dev-oscabriel` | web | `https://web-dev-oscabriel.oscargabriel.workers.dev` | deployed (`/` answers 200) || `dev-oscabriel` | CLI install | `https://platform-dev-oscabriel.oscargabriel.workers.dev/install.sh` | served from `releases-dev-oscabriel` || `dev-oscabriel` | Google redirect URI (H4) | `https://platform-dev-oscabriel.oscargabriel.workers.dev/oauth/google/callback` | not registered || `dev-oscabriel` | sandbox | none: it has no workers.dev route, and only the platform reaches it | deployed || `demo` | platform | `https://platform-demo.oscargabriel.workers.dev` | not deployed: a placeholder that holds the secrets, with no route (404) || `demo` | web | `https://web-demo.oscargabriel.workers.dev` | not deployed || `demo` | CLI install | `https://platform-demo.oscargabriel.workers.dev/install.sh` | after the deploy and a `release --upload --stage demo` || `demo` | Google redirect URI (H4) | `https://platform-demo.oscargabriel.workers.dev/oauth/google/callback` | not registered || `demo` | sandbox | none: it has no workers.dev route | not deployed |
## Running a stage
### Before the first run
1. **Log Wrangler in**, once per machine: `apps/platform/node_modules/.bin/wrangler login`. Deploys and the D1, KV and R2 creates use this login, never the infra token.1. **Log Wrangler in**, once per machine: `apps/platform/node_modules/.bin/wrangler login`. Deploys and the D1, KV and R2 creates use this login, never the infra token. Once the login is stale, `wrangler d1 list` fails with `Authentication error [code: 10000]`, and `wrangler whoami` refreshes it.2. **Set the infra credentials**, `CLOUDFLARE_ACCOUNT_ID` and `CLOUDFLARE_API_TOKEN`, as `infra/.env.schema` describes. The token uses the "Read all resources" template plus Account › Artifacts › Edit. `bun run bootstrap` and `bun run ops` get them through `varlock run --path infra/`. To check they are set without seeing them, run `bun run env:check`.3. **Confirm the plan**: Containers and Workflows need Workers Paid (H6; confirmed on this account, spec §8.3 O2).3. **Confirm the plan**: Containers and Workflows need Workers Paid (H6, confirmed on this account in section 5).
## Bootstrap a stage### Bootstrap a stage
```shbun run bootstrap -- --stage dev-oscabriel```2 unmodified lines
1. reads what exists: the stage's two Artifacts namespaces (`projects-<s>` and `layers-<s>`) over REST, and the account's D1 databases, KV namespaces and R2 buckets through Wrangler;2. creates only what is missing, so a second run creates nothing;3. writes the new D1 and KV ids into the stage's block of `apps/platform/wrangler.jsonc`, touching nothing else in the file (commit that change);4. applies the front page's migrations (`wrangler d1 migrations apply front-page-<s> --remote --env <s>`), once `apps/platform/migrations/` exists;4. applies the front page's migrations (`wrangler d1 migrations apply front-page-<s> --remote --env <s>`);5. records the account's workers.dev subdomain in `infra/workers-dev.json`, so smoke knows where the stage lives;6. checks by name that the deployed platform holds every secret its `.env.schema` requires. Before the first deploy there is no Worker to hold them, so it says which ones that deploy has to carry.6. checks by name that the platform Worker holds every secret its `.env.schema` requires. Before the platform exists there is nothing to hold them, so it says which ones the first deploy has to carry.
It never deletes anything and never prints or reads a secret's value.
`bun run bootstrap -- --stage <s> --dry-run` does only the first step and lists what the run would create. It creates nothing and writes no file.`bun run bootstrap -- --stage <s> --dry-run` does only the first step and lists what the run would create. It creates nothing and writes no file. On a stage that is complete it prints `would create 0`.
## Secrets### Secrets
`apps/platform/.env.schema` names them. Values never go in the repo.
| Name | Needed || --- | --- || `OPERATOR_TOKEN` | Always. The operator's bearer token, at least 32 characters. || `SESSION_TOKENS` | Optional. A JSON object from token to handle, for the demo's named people (spec §8 D9). || `SESSION_TOKENS` | Optional. A JSON object from token to handle, for the demo's named people (the seed's deciders, the on-screen people and the swarm's contributors). || `COOKIE_KEY` | Always. Seals a sign-in in progress into its form (HMAC-SHA-256), at least 32 characters. || `PASSWORD_PEPPER` | Always. Every password is HMAC'd with it before PBKDF2, at least 32 characters. Changing it makes every stored password fail to verify. || `MASTER_KEY` | Always (W6). 64 hex characters: the 256-bit key that wraps every write-only env value. Losing it loses every stored value, so keep a copy outside the machine. || `MASTER_KEY` | Always. 64 hex characters: the 256-bit key that wraps every write-only env value. Losing it loses every stored value, so keep a copy outside the machine. |
To set them for a stage, do one of these:
- **A generated secrets file (both stages).** Keep a dotenv file for the stage outside the repo with mode 600, holding crypto-random values (32 bytes in base64url each, and `MASTER_KEY` as 64 hex characters). Deploy with `STAGE_SECRETS_FILE=<that file> bun run deploy -- --stage <s>`. The platform's deploy step gets only the names `.env.schema` declares, as its environment, and that environment overrides any `.env` value. Nothing prints them. `dev-oscabriel` has used one since its first deploy. `demo` has had one since 2026-10-08, by a recorded decision made under the user's blanket approval, and the same values were set on `platform-demo` with `wrangler secret put` before its first deploy. Both stages' values were generated by the build's agent, so rotate them before the repo goes public (section 5).- **varlock (H5).** Write `NAME=varlock(prompt)` for each one into `apps/platform/.env.local`, run `./node_modules/.bin/varlock load --path apps/platform/` in your own terminal, then deploy. `varlock-wrangler` hands the values to the Worker.- **A secrets file (dev stages only, spec §8.3 O1).** Keep a dotenv file outside the repo with mode 600, and deploy with `STAGE_SECRETS_FILE=<that file> bun run deploy -- --stage dev-<user>`. The platform's deploy step gets only the names `.env.schema` declares, as its environment, and that environment overrides any `.env` value. Nothing prints them. A deploy to `demo` refuses the file before it runs anything.- **By hand**, one at a time: `apps/platform/node_modules/.bin/wrangler secret put <NAME> --env <s>` in `apps/platform`, with the value on stdin.- **By hand**, one at a time: `apps/platform/node_modules/.bin/wrangler secret put <NAME> --env <s>` in `apps/platform`, with the value on stdin. On a stage whose platform isn't deployed yet, this makes `platform-<s>` as an empty placeholder Worker that the first deploy replaces. A deploy still needs the values through one of the two ways above, since varlock-wrangler resolves every required name.
Sign-in uses the platform's own accounts (handle and password), so no stage needs a third-party OAuth app. A stage's platform lives at `https://platform-<s>.<subdomain>.workers.dev`; the subdomain is in `infra/workers-dev.json` once bootstrap has run.
## Deploy a stage### Deploy a stage
```shbun run deploy -- --stage dev-oscabriel```2 unmodified lines
1. `bun run verify`. If the gate is red, nothing after it runs.2. The `sandbox` deploy (`wrangler deploy --env <s>`), first, because the platform's `SANDBOX` binding names it.3. The `platform` deploy (`varlock-wrangler deploy --env <s>`), which resolves `.env.schema` and sends the secrets.4. The `web` build and deploy, once `apps/web` exists.4. The `web` build and deploy.5. A read-back of the push-event trigger (`bun run bootstrap -- --stage <s> --check-triggers`), because Wrangler's output doesn't prove it exists.6. `bun scripts/smoke.ts --stage <s>`.
Then it prints the redirect URI a Google OAuth client registers for the stage (`<platform origin>/oauth/google/callback`, H4). Google sign-in stays off until `GOOGLE_CLIENT_ID` and `GOOGLE_CLIENT_SECRET` are set, and `migrations/0003_identities.sql` must be applied before they are.
Every command runs with `WRANGLER_SEND_METRICS=false`, and with its own folder's `node_modules/.bin` first on `PATH`, so each app deploys with its pinned Wrangler. The first failing step stops the deploy and names that step.
## Smoke-test a stage### Smoke-test a stage
```shbun run smoke -- --stage dev-oscabrielbun run smoke -- --stage dev-oscabriel --url http://localhost:878712 unmodified lines| `missing-repo-404` | `GET /no-such-project.git/info/refs?service=git-upload-pack` answers 404 || `web-front-page` | the web's `GET /` answers 200 with HTML || `web-llms-txt` | the web's `GET /llms.txt` answers 200 with Markdown that opens with its title; the web builds it from the platform's project list, so it passes only when the web reaches the platform through its service binding |
## Tear down a stage### Tear down a stage
None of this is automated: the scripts never delete, and nobody runs `wrangler delete` or cf's `delete` without the user's OK (`wrangler delete` auto-confirms in a non-interactive shell). Tear down only what this build created, which means only names from the table above, and never `witness`. A person runs these in their own terminal. Wrangler's commands run from the app's folder with that app's `node_modules/.bin/wrangler`.None of this is automated, and it is the user's alone (section 4): no script deletes a stage's resources, and nobody runs `wrangler delete` or cf's `delete` without the user's OK (`wrangler delete` auto-confirms in a non-interactive shell). Tear down only what this build created, which means only names from section 2, and never `witness`. A person runs these in their own terminal. Wrangler's commands run from the app's folder with that app's `node_modules/.bin/wrangler`.
1. The Workers: `wrangler delete --env <s>` in `apps/web` (if deployed), then `apps/platform`, then `apps/sandbox`. Then `wrangler workflows delete answer-<s>` and `wrangler workflows delete on-push-<s>`, if they remain.1. The Workers: `wrangler delete --env <s>` in `apps/web`, then `apps/platform`, then `apps/sandbox`. Then `wrangler workflows delete answer-<s>` and `wrangler workflows delete on-push-<s>`, if they remain.2. The Artifacts repos, then the namespaces, `projects-<s>` and `layers-<s>` alike. List a namespace's repos with `bun run ops -- artifacts namespaces repos list --namespace <namespace>`, delete each one with `bun run ops -- artifacts namespaces repos delete <repo> --namespace <namespace> --force`, then `bun run ops -- artifacts namespaces delete --namespace <namespace>`. A namespace has to be empty before it can be deleted.3. The database: `wrangler d1 delete front-page-<s>`.4. The KV namespace: `wrangler kv namespace delete --namespace-id <id>`. The id is in the stage's block of `apps/platform/wrangler.jsonc`.5. The buckets: empty `evidence-<s>` and `releases-<s>`, then run `wrangler r2 bucket delete evidence-<s>` and `wrangler r2 bucket delete releases-<s>`.6. Put the stage's placeholder ids back in `apps/platform/wrangler.jsonc`.modified:packages/config/test/deploy.test.ts+42 added-10 removed
15 unmodified lines16 17 import {18 deploy,19 NoStage,20- SecretsFileNotForStage,20 StepFailed,21 UnknownStage,22 } from "../../../infra/deploy.ts";23 import { repoRoot } from "./root.ts";364 unmodified lines388 expect(message).toBe("platform exited 3, so nothing after it ran");389 })390 );391 393- it.live("says where demo's secrets come from instead", () =>392+ it.live("names the secrets file it could not read", () =>393 Effect.gen(function* () {394 const message = yield* messageOf(["--stage", "demo"], {395 env: { STAGE_SECRETS_FILE: "/nowhere/demo.secrets" },396 });397 398 expect(message).toBe(400- "STAGE_SECRETS_FILE is for dev stages only: set demo's secrets with varlock (infra/stages.md)"399+ "STAGE_SECRETS_FILE names /nowhere/demo.secrets, which can't be read"400 );401 })402 );403 });404 405 describe("a deploy to demo", () => {406 it.live(408- "refuses STAGE_SECRETS_FILE, whose generated values are the dev stage's alone, before it spawns anything",407+ "hands the platform's deploy the values in STAGE_SECRETS_FILE, as a dev stage's does: demo's secrets are generated too",408 () =>409 Effect.gen(function* () {410+ const fs = yield* FileSystem.FileSystem;411+ const path = yield* Path.Path;412+ const dir = yield* fs.makeTempDirectoryScoped();413+ const file = path.join(dir, "demo.secrets");414+415+ yield* fs.writeFileString(416+ file,417+ [418+ "# generated for demo",419+ "OPERATOR_TOKEN=operator-token-that-is-long-enough-000",420+ "MASTER_KEY=00112233445566778899aabbccddeeff00112233445566778899aabbccddeeff",421+ ].join("\n")422+ );423+424 const { result, spawned } = yield* run(["--stage", "demo"], {412- env: { STAGE_SECRETS_FILE: "/nowhere/demo.secrets" },425+ env: { STAGE_SECRETS_FILE: file },426 });427 415- expect(result).toStrictEqual(416- Result.fail(new SecretsFileNotForStage({ stage: "demo" }))417- );418- expect(spawned).toStrictEqual([]);419- })428+ expect(Result.isSuccess(result)).toBeTruthy();429+ expect(spawned.map(line)).toStrictEqual([430+ ".$ bun run verify",431+ "apps/sandbox$ wrangler deploy --env demo",432+ "apps/platform$ varlock-wrangler deploy --env demo",433+ "apps/web$ bun run build",434+ "apps/web$ wrangler deploy --env demo",435+ ".$ bun run bootstrap --stage demo --check-triggers",436+ ".$ bun scripts/smoke.ts --stage demo",437+ ]);438+ expect(439+ spawned.map(({ env }) =>440+ ["MASTER_KEY", "OPERATOR_TOKEN"].filter((name) => name in env)441+ )442+ ).toStrictEqual([443+ [],444+ [],445+ ["MASTER_KEY", "OPERATOR_TOKEN"],446+ [],447+ [],448+ [],449+ [],450+ ]);451+ }).pipe(Effect.scoped, Effect.provide(NodeServices.layer))452 );453 });