From 256d08368864bc0e20d2e971a79d37b9628a0a9e Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 18 Oct 2026 14:13:11 +0000 Subject: [PATCH 1/6] =?UTF-8?q?AC6:=20the=20cirrus=20standard=20=E2=80=94?= =?UTF-8?q?=20no=20kiox,=20generated=20component=20docs,=20the=20context?= =?UTF-8?q?=20pack?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Remove kiox.yaml/kiox.lock and their two blueprint modules: nothing ran the kiox pin (v2.15.0); every workflow pins orun through orun-action. - Generate docs/{overview,architecture,runbook}.md for all eight components from what each declares (tooling/catalog/gen-component-docs.py), and fail Baseline CI when they drift (--check). - Add ai/context/{current,decisions,open-risks}.md (this repository's own; nothing places them). - Close out AC5 (shipped, tagged baseline-v1) and record AC6 (AC-7). - design.md: mark what AC5 superseded — Workers AI is the default model (the gateway only with AI_GATEWAY_API_KEY), AUTH_SECRET is optional (the database's key), wrangler.jsonc is committed, the Supabase root publishes three outputs; risk AC-C notes the lookups are now gateway-only. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01D8AmgTwmnp4M8mgmnS9aha --- .github/workflows/baseline.yml | 6 + ai/context/current.md | 43 ++ ai/context/decisions.md | 20 + ai/context/open-risks.md | 17 + apps/web/docs/architecture.md | 31 ++ apps/web/docs/overview.md | 22 + apps/web/docs/runbook.md | 40 ++ infra/db-migrate/docs/architecture.md | 19 + infra/db-migrate/docs/overview.md | 21 + infra/db-migrate/docs/runbook.md | 19 + .../docs/architecture.md | 31 ++ .../cloudflare-hyperdrive/docs/overview.md | 20 + .../cloudflare-hyperdrive/docs/runbook.md | 20 + .../cloudflare-r2/docs/architecture.md | 29 + .../terraform/cloudflare-r2/docs/overview.md | 19 + infra/terraform/cloudflare-r2/docs/runbook.md | 20 + infra/terraform/supabase/docs/architecture.md | 31 ++ infra/terraform/supabase/docs/overview.md | 20 + infra/terraform/supabase/docs/runbook.md | 20 + kiox.lock | 11 - kiox.yaml | 6 - packages/db/docs/architecture.md | 11 + packages/db/docs/overview.md | 20 + packages/db/docs/runbook.md | 25 + repo-blueprint.yaml | 12 +- specs/epics/README.md | 2 +- .../epics/ai-chatbot/IMPLEMENTATION-STATUS.md | 40 +- specs/epics/ai-chatbot/README.md | 7 +- specs/epics/ai-chatbot/design.md | 68 ++- specs/epics/ai-chatbot/epic.yaml | 7 + specs/epics/ai-chatbot/implementation-plan.md | 27 +- .../ai-chatbot/risks-and-open-questions.md | 5 + tasks/AC-7.TaskContract.yaml | 33 ++ testing/phases.test.sh | 2 +- tests/db/docs/architecture.md | 8 + tests/db/docs/overview.md | 18 + tests/db/docs/runbook.md | 26 + tests/web/docs/architecture.md | 16 + tests/web/docs/overview.md | 18 + tests/web/docs/runbook.md | 26 + tooling/catalog/gen-component-docs.py | 519 ++++++++++++++++++ tooling/rebrand/rebrand.mjs | 1 - 42 files changed, 1299 insertions(+), 57 deletions(-) create mode 100644 ai/context/current.md create mode 100644 ai/context/decisions.md create mode 100644 ai/context/open-risks.md create mode 100644 apps/web/docs/architecture.md create mode 100644 apps/web/docs/overview.md create mode 100644 apps/web/docs/runbook.md create mode 100644 infra/db-migrate/docs/architecture.md create mode 100644 infra/db-migrate/docs/overview.md create mode 100644 infra/db-migrate/docs/runbook.md create mode 100644 infra/terraform/cloudflare-hyperdrive/docs/architecture.md create mode 100644 infra/terraform/cloudflare-hyperdrive/docs/overview.md create mode 100644 infra/terraform/cloudflare-hyperdrive/docs/runbook.md create mode 100644 infra/terraform/cloudflare-r2/docs/architecture.md create mode 100644 infra/terraform/cloudflare-r2/docs/overview.md create mode 100644 infra/terraform/cloudflare-r2/docs/runbook.md create mode 100644 infra/terraform/supabase/docs/architecture.md create mode 100644 infra/terraform/supabase/docs/overview.md create mode 100644 infra/terraform/supabase/docs/runbook.md delete mode 100644 kiox.lock delete mode 100644 kiox.yaml create mode 100644 packages/db/docs/architecture.md create mode 100644 packages/db/docs/overview.md create mode 100644 packages/db/docs/runbook.md create mode 100644 tasks/AC-7.TaskContract.yaml create mode 100644 tests/db/docs/architecture.md create mode 100644 tests/db/docs/overview.md create mode 100644 tests/db/docs/runbook.md create mode 100644 tests/web/docs/architecture.md create mode 100644 tests/web/docs/overview.md create mode 100644 tests/web/docs/runbook.md create mode 100644 tooling/catalog/gen-component-docs.py diff --git a/.github/workflows/baseline.yml b/.github/workflows/baseline.yml index e3ce03f..abda763 100644 --- a/.github/workflows/baseline.yml +++ b/.github/workflows/baseline.yml @@ -52,6 +52,12 @@ jobs: echo "── $t" bash "testing/$t.test.sh" done + # Every component's docs/{overview,architecture,runbook}.md is generated + # from what the component declares (its manifest, Worker config, + # Terraform, migrations, package scripts). A pull request that changes + # one of those facts without regenerating the pages fails here. + - name: Component docs match their manifests + run: python3 tooling/catalog/gen-component-docs.py --check # Tier 1. THE BLUEPRINT, READ AND PLACED BY THE BINARY A BOOTSTRAP RUNS. # diff --git a/ai/context/current.md b/ai/context/current.md new file mode 100644 index 0000000..af3797a --- /dev/null +++ b/ai/context/current.md @@ -0,0 +1,43 @@ +# ai-chatbot — where this repository stands + +The entry page for anyone (or any agent) picking this repository up. It is +this repository's own state and does not ship to a chatbot built from it; the +two pages that do are [operations.md](operations.md) and +[deployment.md](deployment.md). + +## What it is + +Vercel's Next.js AI Chatbot on Cloudflare Workers + Static Assets (through +`@opennextjs/cloudflare`): a Supabase Postgres reached through Hyperdrive, +attachments in R2, and Workers AI as the default model provider. It is +packaged as an Orun baseline: `orun new --blueprint repo-blueprint.yaml` +builds a new chatbot in its own repository and takes it to live on stage and +prod in one landing (`01-product`: Supabase, then Hyperdrive, then the +migrations, then the app, with the R2 bucket beside them), then records what +went live (`02-docs`). + +## Release + +| | | +|---|---| +| Latest tag | `baseline-v1` (AC5, [#6](https://github.com/sourceplane/ai-chatbot/pull/6)) | +| On `main` since | AC6 — the cirrus standard (no kiox, generated component docs, this context pack) | +| Proven live | No. Everything short of the platform is proven offline in Baseline CI: the e2e tier builds the product in orun's staged job tree, migrates a local Postgres with its own runner and serves the Worker over local R2 with a stand-in AI binding. No bootstrap from a tag has run against a workspace yet: the three applies, db-migrate against a real project, a real deploy, Workers AI itself (AC-K) and the `BLOB` binding under the deploy token (AC-L) are unproven | + +## Where to read + +| Question | Page | +|---|---| +| What shipped, and every departure from upstream | `specs/epics/ai-chatbot/IMPLEMENTATION-STATUS.md` | +| Why it is built this way | [decisions.md](decisions.md), then `specs/epics/ai-chatbot/design.md` (passages AC5 superseded are marked) | +| What could still go wrong | [open-risks.md](open-risks.md), then `specs/epics/ai-chatbot/risks-and-open-questions.md` | +| How to instantiate it | `BOOTSTRAP.md`, `docs/phases/` | +| What each component is | `/docs/` beside each `component.yaml` — `apps/web`, `packages/db`, `infra/db-migrate`, `infra/terraform/{supabase,cloudflare-hyperdrive,cloudflare-r2}`, `tests/{web,db}` (generated; `python3 tooling/catalog/gen-component-docs.py`) | + +## Next + +1. Bootstrap one chatbot from a tag against a workspace with Cloudflare and + Supabase connected, and record its timings: the first proof of the + applies, the deploy, Workers AI's models and tools (AC-K) and the R2 + binding under the deploy token (AC-L). +2. Cut the next `baseline-vN` with `tag.yml` so the registry can pin AC6. diff --git a/ai/context/decisions.md b/ai/context/decisions.md new file mode 100644 index 0000000..f13e187 --- /dev/null +++ b/ai/context/decisions.md @@ -0,0 +1,20 @@ +# ai-chatbot — decisions + +The choices that shape this repository, one line each, with where the full +reasoning lives. Superseded decisions stay listed, marked, so the history +reads in order. + +| # | Decision | Why | Source | +|---|---|---|---| +| 1 | OpenNext on Workers + Static Assets, `next` pinned to 16.3.8 | The newest Next the adapter boots; the Worker serves SSR, streaming routes and `proxy.ts` | `specs/epics/ai-chatbot/design.md` §2, epic README | +| 2 | Supabase Postgres through Hyperdrive, one `postgres` client per `getDb()` call; the schema in `packages/db`, applied by db-migrate | A Workers socket cannot outlive its request; drizzle-kit stays for local databases | design.md §2, risk AC-A | +| 3 | Attachments in R2 behind `/api/files/`, public by unguessable URL | As Vercel Blob's `access: "public"`: the model provider and `next/image` fetch without the cookie | design.md §2, risk AC-B | +| 4 | Static-assets incremental cache; no Redis (resumable streams and the IP rate limit off) | Nothing revalidates or is `"use cache"`; both Redis features are opt-in upstream | design.md §4, risks AC-C, AC-D | +| 5 | Workers AI through the `AI` binding is the default model provider (Kimi K2.6 chat, GLM 4.7 Flash titles); the AI Gateway's models only with `AI_GATEWAY_API_KEY`. *Supersedes "the gateway, unchanged" (AC1–AC4)* | The platform brokers no AI vendor: a fresh product must chat with nothing configured | IMPLEMENTATION-STATUS (AC5), risk AC-K | +| 6 | The session key is `AUTH_SECRET` if set, else one migration `020_app_secrets` generated into `app_private.secrets`. *Supersedes "Worker secrets set by hand" (AC-H)* | A bootstrap cannot set a Worker secret; `app_private` is not a schema the Data API exposes | IMPLEMENTATION-STATUS (AC5), risk AC-N | +| 7 | Row-level security with no policy on every table in `public` (`030_row_level_security`) | Supabase's Data API serves `public` to the anon key; the app owns the tables | risk AC-M | +| 8 | `apps/web/wrangler.jsonc` is committed as the fixture render; every lane re-renders it (stage/prod from wiring, dev from the fixture) | The lane's structure check needs it in a fresh checkout, before the build | IMPLEMENTATION-STATUS (AC5), `apps/web/component.yaml` | +| 9 | One landing (`01-product`) then the record (`02-docs`); infra before app enforced on main, advisory on a pull request; the R2 root on its own `r2-data` key | A landing has a fixed cost; the plan carries deploy order; the deploy token does not cover R2 | `repo-blueprint.yaml`, `epic.yaml` (AC5), risk AC-L | +| 10 | stack-tectonic 0.19.0, not 0.20.0 | 0.20.0 links each job's `node_modules` out of its tree, which Next 16's Turbopack refuses | `intent.yaml`, BOOTSTRAP.md | +| 11 | orun is pinned only where it runs (the `orun-action` `version:` in each workflow); no kiox | `kiox.yaml` pinned a version (v2.15.0) nothing ran | IMPLEMENTATION-STATUS (AC6) | +| 12 | Component docs are generated from the manifests and checked in CI | A hand-written copy of the dependency graph and bindings drifts silently | `tooling/catalog/gen-component-docs.py` | diff --git a/ai/context/open-risks.md b/ai/context/open-risks.md new file mode 100644 index 0000000..1c4a298 --- /dev/null +++ b/ai/context/open-risks.md @@ -0,0 +1,17 @@ +# ai-chatbot — open risks + +What is not yet proven or not yet decided. The full write-up of every risk, +including the accepted and resolved ones, is +`specs/epics/ai-chatbot/risks-and-open-questions.md`; this page lists only +what is still live, so it should be short. + +| ID | Risk | State | What closes it | +|---|---|---|---| +| AC-K | Workers AI is the default but cannot be called offline: that Kimi K2.6 and GLM 4.7 Flash are served on the account, that their tool calls drive the artifact tools, and that the suggestions tool's structured output is honoured are unproven (the e2e uses a stand-in binding) | OPEN | A live bootstrap that chats, titles and edits an artifact | +| AC-L | The Worker's `BLOB` R2 binding is attached by `wrangler deploy` under the `workers-deploy` token; whether Cloudflare accepts it is unverified, and the fix would be the platform's token template | OPEN (platform) | The first live `web` deploy | + +Not yet exercised live either, though resolved offline: that the Management +API runs migrations as `postgres`, so it owns the tables (AC-M; the guard +stops the migration if not). Accepted, and worth knowing before you change +them: AC-C (static-assets cache), AC-D (no Redis), AC-G (no BotID), AC-I +(bcrypt at module load), AC-O (a prerender/resume mismatch logged on `/`). diff --git a/apps/web/docs/architecture.md b/apps/web/docs/architecture.md new file mode 100644 index 0000000..328bf3c --- /dev/null +++ b/apps/web/docs/architecture.md @@ -0,0 +1,31 @@ +# web — architecture + +Built by the turbo pipeline from `apps/web` and deployed with wrangler. + +| | | +|---|---| +| Worker config | `apps/web/wrangler.template.jsonc` | +| Entry | `.open-next/worker.js` | +| Compatibility date | `2026-10-01` | +| Compatibility flags | `nodejs_compat`, `global_fetch_strictly_public` | + +## Bindings + +| Binding | Kind | Source | +|---|---|---| +| `BLOB` | R2 bucket | `r2_bucket_name` from `cloudflare-r2` | +| `HYPERDRIVE` | Hyperdrive (pooled Postgres) | `hyperdrive_id` from `cloudflare-hyperdrive` | +| `AI` | Workers AI | account-level; no resource to provision | +| `ASSETS` | Static assets | `.open-next/assets` | + +Identifiers marked *from* a component are filled in at deploy time from +that component's published outputs for the environment being deployed. + +## Wiring + +Resolved at deploy time from secrets the infrastructure lanes publish (names only): + +- `WIRING_CLOUDFLARE_HYPERDRIVE_PROD` +- `WIRING_CLOUDFLARE_HYPERDRIVE_STAGE` +- `WIRING_CLOUDFLARE_R2_PROD` +- `WIRING_CLOUDFLARE_R2_STAGE` diff --git a/apps/web/docs/overview.md b/apps/web/docs/overview.md new file mode 100644 index 0000000..d893753 --- /dev/null +++ b/apps/web/docs/overview.md @@ -0,0 +1,22 @@ +# web + +Vercel's Next.js AI Chatbot (Next.js on Cloudflare Workers + Static Assets via @opennextjs/cloudflare, per environment) + +A Cloudflare Worker with Static Assets (server rendering plus static files), deployed per environment by its CI lane. + +| | | +|---|---| +| Type | `cloudflare-workers-assets-turbo` | +| Source | `apps/web` | +| Package | `@app/web` | +| Environments | `dev`: `verify` · `stage`: `verify`, `deploy` on a push to `main` · `prod`: `verify`, `deploy` on a push to `main` | + +## Depends on + +- **cloudflare-hyperdrive** — Provisions Cloudflare Hyperdrive resources for stage and prod Supabase Postgres databases +- **cloudflare-r2** — Provisions the Cloudflare R2 bucket the app binds (stage and prod) +- **db-migrate** — Applies database migrations to stage and prod Supabase instances + +## Depended on by + +- (none) diff --git a/apps/web/docs/runbook.md b/apps/web/docs/runbook.md new file mode 100644 index 0000000..e9a2232 --- /dev/null +++ b/apps/web/docs/runbook.md @@ -0,0 +1,40 @@ +# web — runbook + +## How it runs + +Pull requests verify it; a merge to `main` deploys it to `stage`, `prod`. +CI plans what changed (`orun plan --changed`) and runs each lane with `orun run`; +the plan orders a component after everything it depends on. + +## Local commands + +```bash +pnpm --filter @app/web dev +pnpm --filter @app/web build +pnpm --filter @app/web typecheck +pnpm --filter @app/web lint +pnpm --filter @app/web preview +``` + +## Verify + +After a deploy the lane runs this smoke against the environment it +deployed (`ORUN_ENVIRONMENT`); `DEPLOYED_URL` overrides the URL: + +```bash +pong=$(curl -sf "${DEPLOYED_URL}/ping") && echo "${pong}" | grep -qx pong && health=$(curl -sf "${DEPLOYED_URL}/api/health") && echo "${health}" | grep -q '"ok":true' +``` + +## Rollback + +Revert the commit on `main`. The next convergence applies the previous desired +state; nothing was changed out of band, so there is nothing else to undo. + +## Common failures + +- **A `WIRING_*` secret is missing at deploy**: an infrastructure lane upstream + has not applied for this environment yet. Within one convergence the plan + runs it first; on its own, re-run that lane. +- **The smoke fails right after a first deploy**: a new workers.dev route can + answer 4xx for a few seconds and the lane retries. A failure that persists + is a regression in the deployed code. diff --git a/infra/db-migrate/docs/architecture.md b/infra/db-migrate/docs/architecture.md new file mode 100644 index 0000000..6b88da9 --- /dev/null +++ b/infra/db-migrate/docs/architecture.md @@ -0,0 +1,19 @@ +# db-migrate — architecture + +Applies the migrations under `packages/db/src/migrations` in order, recording each one +it applies so a run only ever applies what is new. An already-applied migration +is never edited: a change is a new, later migration. + +## Migrations + +- `000_control` +- `010_initial` +- `020_app_secrets` +- `030_row_level_security` + +## Resolved at run time (names only) + +- `SUPABASE_ACCESS_TOKEN` +- `SUPABASE_DB_PASSWORD` +- `SUPABASE_DB_URL` +- `SUPABASE_PROJECT_REF` diff --git a/infra/db-migrate/docs/overview.md b/infra/db-migrate/docs/overview.md new file mode 100644 index 0000000..16dfe32 --- /dev/null +++ b/infra/db-migrate/docs/overview.md @@ -0,0 +1,21 @@ +# db-migrate + +Applies database migrations to stage and prod Supabase instances + +Applies this repository's ordered database migrations per environment: plan on pull requests, apply on merge to `main`. + +| | | +|---|---| +| Type | `db-migrate` | +| Source | `infra/db-migrate` | +| Environments | `stage`: `plan`, `apply` on a push to `main` · `prod`: `plan`, `apply` on a push to `main` | + +## Depends on + +- **db** — The database migrations and their runner (built by the db-migrate component before it plans or applies) +- **supabase** — Provisions Supabase projects for stage and prod and wires credentials into orun secrets +- **cloudflare-hyperdrive** — Provisions Cloudflare Hyperdrive resources for stage and prod Supabase Postgres databases + +## Depended on by + +- **web** — Vercel's Next.js AI Chatbot (Next.js on Cloudflare Workers + Static Assets via @opennextjs/cloudflare, per environment) diff --git a/infra/db-migrate/docs/runbook.md b/infra/db-migrate/docs/runbook.md new file mode 100644 index 0000000..04a50d1 --- /dev/null +++ b/infra/db-migrate/docs/runbook.md @@ -0,0 +1,19 @@ +# db-migrate — runbook + +## How it runs + +Pull requests plan it; a merge to `main` applies it to `stage`, `prod`. +CI plans what changed (`orun plan --changed`) and runs each lane with `orun run`; +the plan orders a component after everything it depends on. + +## Rollback + +Revert the commit on `main`. The next convergence applies the previous desired +state; nothing was changed out of band, so there is nothing else to undo. + +## Common failures + +- **An applied migration's file changed**: the run stops rather than guess. + Restore the file and write the change as a new migration. +- **The database is unreachable**: the infrastructure lane it depends on has + not applied for this environment; that lane runs first in a convergence. diff --git a/infra/terraform/cloudflare-hyperdrive/docs/architecture.md b/infra/terraform/cloudflare-hyperdrive/docs/architecture.md new file mode 100644 index 0000000..5929684 --- /dev/null +++ b/infra/terraform/cloudflare-hyperdrive/docs/architecture.md @@ -0,0 +1,31 @@ +# cloudflare-hyperdrive — architecture + +A `terraform` root at `infra/terraform/cloudflare-hyperdrive/terraform`. + +- **State** lives in the Orun Cloud HTTP state backend — no local state and + no state bucket to manage. +- **Credentials are brokered per run** from the workspace's provider + connections and resolved by name; none is stored in this repository. +- **Adoption** (`adopt.tf`): when state is empty but the resource already + exists, plan-time import adopts it instead of failing. + +## Resources + +- `cloudflare_hyperdrive_config.postgres` + +## Published outputs + +Written as job-output secrets on each environment after an apply; deploy +lanes downstream resolve them by name. + +| Secret | Terraform output | +|---|---| +| `WIRING_CLOUDFLARE_HYPERDRIVE` | `wiring` | + +## Resolved at run time (names only) + +- `CLOUDFLARE_ACCOUNT_ID` +- `CLOUDFLARE_API_TOKEN` +- `TF_VAR_cloudflare_account_id` +- `TF_VAR_supabase_db_password` +- `TF_VAR_supabase_project_ref` diff --git a/infra/terraform/cloudflare-hyperdrive/docs/overview.md b/infra/terraform/cloudflare-hyperdrive/docs/overview.md new file mode 100644 index 0000000..2a96df0 --- /dev/null +++ b/infra/terraform/cloudflare-hyperdrive/docs/overview.md @@ -0,0 +1,20 @@ +# cloudflare-hyperdrive + +Provisions Cloudflare Hyperdrive resources for stage and prod Supabase Postgres databases + +Terraform-managed infrastructure, planned and applied per environment by its CI lane. + +| | | +|---|---| +| Type | `terraform` | +| Source | `infra/terraform/cloudflare-hyperdrive` | +| Environments | `stage`: `plan-only`, `apply` on a push to `main` · `prod`: `plan-only`, `apply` on a push to `main` | + +## Depends on + +- **supabase** — Provisions Supabase projects for stage and prod and wires credentials into orun secrets + +## Depended on by + +- **db-migrate** — Applies database migrations to stage and prod Supabase instances +- **web** — Vercel's Next.js AI Chatbot (Next.js on Cloudflare Workers + Static Assets via @opennextjs/cloudflare, per environment) diff --git a/infra/terraform/cloudflare-hyperdrive/docs/runbook.md b/infra/terraform/cloudflare-hyperdrive/docs/runbook.md new file mode 100644 index 0000000..016c2b5 --- /dev/null +++ b/infra/terraform/cloudflare-hyperdrive/docs/runbook.md @@ -0,0 +1,20 @@ +# cloudflare-hyperdrive — runbook + +## How it runs + +Pull requests plan it; a merge to `main` applies it to `stage`, `prod`. +CI plans what changed (`orun plan --changed`) and runs each lane with `orun run`; +the plan orders a component after everything it depends on. + +## Rollback + +Revert the commit on `main`. The next convergence applies the previous desired +state; nothing was changed out of band, so there is nothing else to undo. + +## Common failures + +- **Provider authentication fails**: the workspace's provider connection is + missing or revoked. Reconnect it in the console; credentials are brokered + from it per run. +- **"Already exists" on a first apply**: state is empty but the resource is + not. `adopt.tf` imports it at plan time; if it still fails, the resource was renamed outside Terraform. diff --git a/infra/terraform/cloudflare-r2/docs/architecture.md b/infra/terraform/cloudflare-r2/docs/architecture.md new file mode 100644 index 0000000..f528c5b --- /dev/null +++ b/infra/terraform/cloudflare-r2/docs/architecture.md @@ -0,0 +1,29 @@ +# cloudflare-r2 — architecture + +A `terraform` root at `infra/terraform/cloudflare-r2/terraform`. + +- **State** lives in the Orun Cloud HTTP state backend — no local state and + no state bucket to manage. +- **Credentials are brokered per run** from the workspace's provider + connections and resolved by name; none is stored in this repository. +- **Adoption** (`adopt.tf`): when state is empty but the resource already + exists, plan-time import adopts it instead of failing. + +## Resources + +- `cloudflare_r2_bucket.app` + +## Published outputs + +Written as job-output secrets on each environment after an apply; deploy +lanes downstream resolve them by name. + +| Secret | Terraform output | +|---|---| +| `WIRING_CLOUDFLARE_R2` | `wiring` | + +## Resolved at run time (names only) + +- `CLOUDFLARE_ACCOUNT_ID` +- `CLOUDFLARE_API_TOKEN` +- `TF_VAR_cloudflare_account_id` diff --git a/infra/terraform/cloudflare-r2/docs/overview.md b/infra/terraform/cloudflare-r2/docs/overview.md new file mode 100644 index 0000000..0eec70a --- /dev/null +++ b/infra/terraform/cloudflare-r2/docs/overview.md @@ -0,0 +1,19 @@ +# cloudflare-r2 + +Provisions the Cloudflare R2 bucket the app binds (stage and prod) + +Terraform-managed infrastructure, planned and applied per environment by its CI lane. + +| | | +|---|---| +| Type | `terraform` | +| Source | `infra/terraform/cloudflare-r2` | +| Environments | `stage`: `plan-only`, `apply` on a push to `main` · `prod`: `plan-only`, `apply` on a push to `main` | + +## Depends on + +- (none) + +## Depended on by + +- **web** — Vercel's Next.js AI Chatbot (Next.js on Cloudflare Workers + Static Assets via @opennextjs/cloudflare, per environment) diff --git a/infra/terraform/cloudflare-r2/docs/runbook.md b/infra/terraform/cloudflare-r2/docs/runbook.md new file mode 100644 index 0000000..37bee3b --- /dev/null +++ b/infra/terraform/cloudflare-r2/docs/runbook.md @@ -0,0 +1,20 @@ +# cloudflare-r2 — runbook + +## How it runs + +Pull requests plan it; a merge to `main` applies it to `stage`, `prod`. +CI plans what changed (`orun plan --changed`) and runs each lane with `orun run`; +the plan orders a component after everything it depends on. + +## Rollback + +Revert the commit on `main`. The next convergence applies the previous desired +state; nothing was changed out of band, so there is nothing else to undo. + +## Common failures + +- **Provider authentication fails**: the workspace's provider connection is + missing or revoked. Reconnect it in the console; credentials are brokered + from it per run. +- **"Already exists" on a first apply**: state is empty but the resource is + not. `adopt.tf` imports it at plan time; if it still fails, the resource was renamed outside Terraform. diff --git a/infra/terraform/supabase/docs/architecture.md b/infra/terraform/supabase/docs/architecture.md new file mode 100644 index 0000000..511ac12 --- /dev/null +++ b/infra/terraform/supabase/docs/architecture.md @@ -0,0 +1,31 @@ +# supabase — architecture + +A `terraform` root at `infra/terraform/supabase/terraform`. + +- **State** lives in the Orun Cloud HTTP state backend — no local state and + no state bucket to manage. +- **Credentials are brokered per run** from the workspace's provider + connections and resolved by name; none is stored in this repository. +- **Adoption** (`adopt.tf`): when state is empty but the resource already + exists, plan-time import adopts it instead of failing. + +## Resources + +- `random_password.db_password` +- `supabase_project.this` + +## Published outputs + +Written as job-output secrets on each environment after an apply; deploy +lanes downstream resolve them by name. + +| Secret | Terraform output | +|---|---| +| `SUPABASE_PROJECT_REF` | `project_ref` | +| `SUPABASE_DB_PASSWORD` | `database_password` | +| `SUPABASE_DB_URL` | `connection_uri` | + +## Resolved at run time (names only) + +- `SUPABASE_ACCESS_TOKEN` +- `TF_VAR_supabaseOrgId` diff --git a/infra/terraform/supabase/docs/overview.md b/infra/terraform/supabase/docs/overview.md new file mode 100644 index 0000000..145a0e8 --- /dev/null +++ b/infra/terraform/supabase/docs/overview.md @@ -0,0 +1,20 @@ +# supabase + +Provisions Supabase projects for stage and prod and wires credentials into orun secrets + +Terraform-managed infrastructure, planned and applied per environment by its CI lane. + +| | | +|---|---| +| Type | `terraform` | +| Source | `infra/terraform/supabase` | +| Environments | `stage`: `plan-only`, `apply` on a push to `main` · `prod`: `plan-only`, `apply` on a push to `main` | + +## Depends on + +- (none) + +## Depended on by + +- **cloudflare-hyperdrive** — Provisions Cloudflare Hyperdrive resources for stage and prod Supabase Postgres databases +- **db-migrate** — Applies database migrations to stage and prod Supabase instances diff --git a/infra/terraform/supabase/docs/runbook.md b/infra/terraform/supabase/docs/runbook.md new file mode 100644 index 0000000..d240972 --- /dev/null +++ b/infra/terraform/supabase/docs/runbook.md @@ -0,0 +1,20 @@ +# supabase — runbook + +## How it runs + +Pull requests plan it; a merge to `main` applies it to `stage`, `prod`. +CI plans what changed (`orun plan --changed`) and runs each lane with `orun run`; +the plan orders a component after everything it depends on. + +## Rollback + +Revert the commit on `main`. The next convergence applies the previous desired +state; nothing was changed out of band, so there is nothing else to undo. + +## Common failures + +- **Provider authentication fails**: the workspace's provider connection is + missing or revoked. Reconnect it in the console; credentials are brokered + from it per run. +- **"Already exists" on a first apply**: state is empty but the resource is + not. `adopt.tf` imports it at plan time; if it still fails, the resource was renamed outside Terraform. diff --git a/kiox.lock b/kiox.lock deleted file mode 100644 index 6e14690..0000000 --- a/kiox.lock +++ /dev/null @@ -1,11 +0,0 @@ -apiVersion: kiox.io/v1 -kind: WorkspaceLock -metadata: - name: example-platform -providers: - - alias: orun - provider: sourceplane/orun - source: ghcr.io/sourceplane/orun:v2.15.0 - version: v2.15.0 - resolved: ghcr.io/sourceplane/orun@sha256:1d28be8612dc8d8083b508f97cd71a24c090f6472c43c71f68455e3709a6a3c1 - store: e02472f57f2eb5fb5168b7d270ea547e5bffbf83824c4286abd7ba20f87cb9d1 diff --git a/kiox.yaml b/kiox.yaml deleted file mode 100644 index d654da0..0000000 --- a/kiox.yaml +++ /dev/null @@ -1,6 +0,0 @@ -apiVersion: kiox.io/v1 -kind: Workspace -metadata: - name: example-platform -providers: - orun: ghcr.io/sourceplane/orun:v2.15.0 diff --git a/packages/db/docs/architecture.md b/packages/db/docs/architecture.md new file mode 100644 index 0000000..135d4b4 --- /dev/null +++ b/packages/db/docs/architecture.md @@ -0,0 +1,11 @@ +# db — architecture + +A workspace package at `packages/db`, consumed at build time by the components +that depend on it. It holds no credentials and opens no connections of its own. + +## Exports + +- `.` +- `./manifest` +- `./runner` +- `./types` diff --git a/packages/db/docs/overview.md b/packages/db/docs/overview.md new file mode 100644 index 0000000..859cdce --- /dev/null +++ b/packages/db/docs/overview.md @@ -0,0 +1,20 @@ +# db + +The database migrations and their runner (built by the db-migrate component before it plans or applies) + +A workspace package built by the turbo pipeline. It deploys nothing itself: its lane type-checks, lints, tests and builds it. + +| | | +|---|---| +| Type | `turbo-package` | +| Source | `packages/db` | +| Package | `@saas/db` | +| Environments | `dev`: `quick-check` · `stage`: `quick-check` · `prod`: `quick-check` | + +## Depends on + +- (none) + +## Depended on by + +- **db-migrate** — Applies database migrations to stage and prod Supabase instances diff --git a/packages/db/docs/runbook.md b/packages/db/docs/runbook.md new file mode 100644 index 0000000..3fa7445 --- /dev/null +++ b/packages/db/docs/runbook.md @@ -0,0 +1,25 @@ +# db — runbook + +## How it runs + +Its lane runs on every pull request that changes it; it has no deployed surface. +CI plans what changed (`orun plan --changed`) and runs each lane with `orun run`; +the plan orders a component after everything it depends on. + +## Local commands + +```bash +pnpm --filter @saas/db build +pnpm --filter @saas/db typecheck +pnpm --filter @saas/db lint +``` + +## Rollback + +Revert the commit on `main`. The next convergence applies the previous desired +state; nothing was changed out of band, so there is nothing else to undo. + +## Common failures + +- **A dependent fails to build after a change here**: run `pnpm typecheck` + across the workspace before merging. diff --git a/repo-blueprint.yaml b/repo-blueprint.yaml index c5bb351..651b859 100644 --- a/repo-blueprint.yaml +++ b/repo-blueprint.yaml @@ -193,16 +193,6 @@ modules: source: baseline from: turbo.json to: turbo.json - - name: root-kiox - mode: copy - source: baseline - from: kiox.yaml - to: kiox.yaml - - name: root-kiox-lock - mode: copy - source: baseline - from: kiox.lock - to: kiox.lock - name: root-gitignore mode: copy source: baseline @@ -438,7 +428,7 @@ phases: await: "One convergence is running per environment: the Supabase project first (five to seven minutes to come up), then Hyperdrive over its database, then the migrations, then the app — with the R2 bucket created beside them. Nothing is stuck." done: "{{ .inputs.reponame }} is live on stage and prod — {{ .meta.files }} files on main, branded as {{ .inputs.productname }}, chatting on Workers AI with its database reachable through Hyperdrive. That took {{ .meta.elapsed }}." failed: "The product did not come up. The failing lane above names the component — supabase, cloudflare-hyperdrive, cloudflare-r2, db-migrate or web — and the provider's own error is in its log; whatever was provisioned is still there." - modules: [ai-deployment, ai-operations, cloudflare-hyperdrive, cloudflare-r2, db, db-migrate, db-tests, github-workflows, rebrand-values, root-gitignore, root-intent, root-kiox, root-kiox-lock, root-package-json, root-pnpm-lock, root-pnpm-workspace, root-readme, root-turbo, supabase, tooling-eslint, tooling-migrations, tooling-tsconfig, tooling-wire, vscode, web, web-tests] + modules: [ai-deployment, ai-operations, cloudflare-hyperdrive, cloudflare-r2, db, db-migrate, db-tests, github-workflows, rebrand-values, root-gitignore, root-intent, root-package-json, root-pnpm-lock, root-pnpm-workspace, root-readme, root-turbo, supabase, tooling-eslint, tooling-migrations, tooling-tsconfig, tooling-wire, vscode, web, web-tests] # THE PLATFORM MUST BE ABLE TO SEE THE REPOSITORY BEFORE IT EXISTS. Every # phase lands a pull request that files under its task, and the platform # learns of a PR only through the GitHub App installation on the account diff --git a/specs/epics/README.md b/specs/epics/README.md index 5386ab9..6b886c5 100644 --- a/specs/epics/README.md +++ b/specs/epics/README.md @@ -7,6 +7,6 @@ folder is the adoption; the merge creates the epic in the workspace. | Epic | Cluster | Status | What it is | |------|---------|--------|------------| -| [`ai-chatbot/`](./ai-chatbot/) | **AC** | 🔄 AC5 in review | Vercel's Next.js AI Chatbot, equivalent in code and function, on Cloudflare Workers with Supabase Postgres, Hyperdrive and R2 — and an Orun baseline that instantiates it in one landing, chatting on Workers AI (AC5) | +| [`ai-chatbot/`](./ai-chatbot/) | **AC** | ✅ Shipped (`baseline-v1`); live bootstrap pending | Vercel's Next.js AI Chatbot, equivalent in code and function, on Cloudflare Workers with Supabase Postgres, Hyperdrive and R2 — and an Orun baseline that instantiates it in one landing, chatting on Workers AI (AC5) | As-built ≠ intent: what shipped lives in each epic's `IMPLEMENTATION-STATUS.md`. diff --git a/specs/epics/ai-chatbot/IMPLEMENTATION-STATUS.md b/specs/epics/ai-chatbot/IMPLEMENTATION-STATUS.md index 915c8a4..46c5165 100644 --- a/specs/epics/ai-chatbot/IMPLEMENTATION-STATUS.md +++ b/specs/epics/ai-chatbot/IMPLEMENTATION-STATUS.md @@ -15,7 +15,8 @@ the code departed from `design.md` or from the upstream template. | AC2 — the schema through db-migrate | ✅ Shipped (planned offline; apply gated on a linked workspace) | [#3](https://github.com/sourceplane/ai-chatbot/pull/3) | | AC3 — Supabase, Hyperdrive and R2 from Terraform | ✅ Shipped (validated; apply gated on a linked workspace) | [#4](https://github.com/sourceplane/ai-chatbot/pull/4) | | AC4 — ready to instantiate | ✅ Shipped | [#5](https://github.com/sourceplane/ai-chatbot/pull/5) | -| AC5 — a baseline | 🔄 In review | this PR | +| AC5 — a baseline | ✅ Shipped | [#6](https://github.com/sourceplane/ai-chatbot/pull/6) (AC-6), tagged `baseline-v1` | +| AC6 — the cirrus standard | ✅ Shipped | AC-7 — on `main` after `baseline-v1`, not yet tagged | ## Departures from the upstream template (AC1–AC4) @@ -135,6 +136,43 @@ guard (AC-M). the Supabase root publishes Lumen's three outputs only; every infra edge is enforced on main and advisory on pull requests; stack-tectonic 0.19.0. +## The cirrus standard (AC6) + +Nothing about the chatbot changed. What changed is the baseline around it: + +| What | Before | After | Why | +|---|---|---|---| +| orun pin | `kiox.yaml` (v2.15.0) + `kiox.lock`, shipped to every product | gone; orun is pinned where it runs, the `orun-action` `version:` in each workflow | nothing ran the kiox pin, and it disagreed with the lanes (v2.78.4) | +| `root-kiox`, `root-kiox-lock` modules | in `01-product` | removed (`testing/phases.test.sh` and the rebrand's skip list follow) | a product is placed with 294 files: 272 − 2 kiox + 24 docs pages | +| component docs | none | `docs/overview.md`, `architecture.md`, `runbook.md` beside each of the eight `component.yaml` | cirrus-baseline documents every component; the workspace Docs library renders `docs/` beside each manifest | +| how the docs stay true | — | `tooling/catalog/gen-component-docs.py` derives them from the manifest, the Worker config, Terraform, migrations and package scripts; Baseline CI runs it with `--check` | a hand-written copy of a manifest drifts silently | +| context pack | `operations.md`, `deployment.md` | plus `current.md`, `decisions.md`, `open-risks.md` | cirrus-baseline's shape; the three new pages are this repository's own and no module places them (the leak gate still allows exactly two) | +| status | AC5 "in review" | AC5 shipped and tagged `baseline-v1` | the tag existed; the documents had not caught up | +| `design.md` | §2–§7 and §9 still described AC1–AC4: the gateway "unchanged", Workers AI a rejected alternative, `wrangler.jsonc` git-ignored, `AUTH_SECRET` and the gateway key set by hand, seven Supabase outputs | each superseded passage marked and the as-built fact beside it | the design contradicted the code AC5 shipped | + +## Verified (AC6) + +- `testing/{manifest,phases,coverage,rebrand,retouch,bootstrap-defer,wire}.test.sh` + green; `gen-component-docs.py --check` green (8 components, 24 pages). +- `orun new --status` at v2.58.11: `01-product` 294 files, `02-docs` + hook-only. +- `testing/leak.test.sh` at v2.58.11: 294 files derived (272 on `main` + before), 287 text files read; ai/context still exactly the two declared + pages; the generated pages name no factory path. +- `testing/placement.test.sh` at v2.78.4 (the workflow's pin for it): 294 + files placed, both landings, branded, re-tenanted; the product's own plan + orders supabase → cloudflare-hyperdrive → db-migrate → web and + cloudflare-r2 → web, enforced on main, advisory on a pull request; + `--resume` changes nothing. +- `pnpm install --frozen-lockfile`, `wire:fixture` (the tree unchanged), + `typecheck`, `lint`, `test` (57 tests: 47 in `tests/web`, 10 in + `tests/db`), `build` green. +- `testing/e2e.test.sh` at v2.78.4 green: the stage db-migrate and web lanes + in staged job trees, `wrangler dev` over a local Postgres, R2 and the + stand-in AI binding, a guest's chat streamed, titled and listed, an + attachment, a registration; `anon`/`authenticated` read nothing. +- `orun task check AC-7` complete. + ## Verified - AC1–AC4: Checks (typecheck, lint, test, build); the Worker under diff --git a/specs/epics/ai-chatbot/README.md b/specs/epics/ai-chatbot/README.md index 28655c3..3977051 100644 --- a/specs/epics/ai-chatbot/README.md +++ b/specs/epics/ai-chatbot/README.md @@ -8,15 +8,15 @@ The upstream code stays the code: `app/(chat)/api/chat/route.ts` with `streamTex | Field | Value | |-------|-------| -| Status | 🔄 AC5 in review — AC0–AC4 landed (#1–#5); AC5 makes the repository an Orun baseline (one landing), Workers AI the default model provider, the session key the database's own and row-level security universal. The Supabase, Hyperdrive and R2 applies, db-migrate and a live deploy are gated on a linked workspace | -| Cluster | **AC** (AC0–AC5) | +| Status | ✅ AC0–AC5 shipped (#1–#6), tagged `baseline-v1`: AC5 made the repository an Orun baseline (one landing), Workers AI the default model provider, the session key the database's own and row-level security universal. AC6 (the cirrus standard, AC-7) on `main`, not yet tagged. The Supabase, Hyperdrive and R2 applies, db-migrate and a live deploy are not yet proven by a live bootstrap (risks AC-K, AC-L) | +| Cluster | **AC** (AC0–AC6) | | Owner(s) | `apps/web` (the app) · `tests/web` (vitest) · `packages/db` + `tests/db` (the schema) · `infra/terraform/{supabase,cloudflare-hyperdrive,cloudflare-r2}` + `infra/db-migrate` | | Builds on | `lumen` conventions — the `supabase`, `cloudflare-hyperdrive` and `db-migrate` components, `@saas/db`, the orun-secrets wiring, the per-request `postgres` client; `cirrus-baseline` for the R2 root and the repository shape | | Upstream | [vercel/ai-chatbot](https://github.com/vercel/ai-chatbot) v3.1 (AI SDK 7, Next 16, next-auth v5 beta, Drizzle) | | Changes | Adds the Workers build, the monorepo wrapper, tests, the migrations package, the infra roots and the deploy contract; in the template's code: the per-call Postgres client, the R2 attachment routes, and shims for the Vercel-only modules (`lib/bot.ts`, `lib/geo.ts`, an empty `instrumentation.ts`) | | Decisions locked | (1) OpenNext on Workers + Static Assets, `next` pinned to 16.3.8. (2) Postgres through Hyperdrive, one `postgres` client per `getDb()` call, never at module scope. (3) Attachments in R2 behind `/api/files/`, public by unguessable URL exactly as Vercel Blob's `access: "public"` was. (4) The schema ships in `packages/db` and is applied by db-migrate; drizzle-kit stays for local development. (5) Static-assets incremental cache: the app has no `use cache` and nothing revalidates. (6) No Redis: resumable streams and the IP rate limit stay off, as upstream does without `REDIS_URL`. (7) `AUTH_SECRET` and `AI_GATEWAY_API_KEY` are Worker secrets set once per environment — **superseded by AC5**: both are optional; Workers AI through the `AI` binding is the default model provider, and the session key defaults to one the database generates. | | Gate | AC1 is the first user-visible rung and is verified without a database (the Worker boots, the routes answer). AC2 and AC3 need a workspace with Supabase and Cloudflare connections to apply; they are verified by `plan`, `terraform validate` and the offline migration tests. | -| Shipped as | `main` after [#5](https://github.com/sourceplane/ai-chatbot/pull/5); verified locally under `wrangler dev` with dummy secrets and no Postgres (the Worker boots, every route answers) | +| Shipped as | `baseline-v1` ([#6](https://github.com/sourceplane/ai-chatbot/pull/6)), then AC6 on `main`; proven offline (Baseline CI: contract, leak, placement and the e2e tier), deploy gated until a workspace is linked | ## Read order @@ -35,3 +35,4 @@ The upstream code stays the code: `app/(chat)/api/chat/route.ts` with `streamTex | AC3 — Supabase, Hyperdrive and R2 from Terraform | the three roots and the app's wiring from them | the roots validate; the wiring keys match the template's tokens | | AC4 — ready to instantiate | README, as-built status | a reader can run, test, preview and deploy it | | AC5 — a baseline | the card, the build document, `.baseline/`, the rebrand engine, the bootstrap helpers, `testing/`; Workers AI by default, the database's session key, RLS, the committed wrangler config, `/api/health`, the R2 root on its own `r2-data` key | Baseline CI green: contract, leak, placement (infra before app) and the e2e tier | +| AC6 — the cirrus standard | no kiox, generated component docs, the context pack, status that agrees with the tags and the code | Baseline CI green with the docs check | diff --git a/specs/epics/ai-chatbot/design.md b/specs/epics/ai-chatbot/design.md index d26934c..8c68762 100644 --- a/specs/epics/ai-chatbot/design.md +++ b/specs/epics/ai-chatbot/design.md @@ -1,5 +1,11 @@ # ai-chatbot — design +> AC5 (a baseline) changed parts of this design: Workers AI is the default +> model provider, the session key is the database's own unless `AUTH_SECRET` +> is set, `wrangler.jsonc` is committed, and every table has row-level +> security. The passages it superseded are marked below and kept for the +> history; `IMPLEMENTATION-STATUS.md` is the as-built record. + ## 1. What the template is Next.js App Router (16, `cacheComponents`, React Compiler) + AI SDK 7. The @@ -36,19 +42,20 @@ the `Geo` type), `@vercel/otel` + `@ai-sdk/otel` in `instrumentation.ts`, | BotID (`withBotId`, `checkBotId`, `initBotId`) | Removed; `lib/bot.ts` `checkBotId()` always returns `{ isBot: false }`, with the pointer to Cloudflare Bot Management / Turnstile. `instrumentation-client.ts` (which only initialised BotID) is gone | | `@vercel/otel` + `@ai-sdk/otel` in `instrumentation.ts` | An empty `register()`; the Worker's `observability.enabled` gives logs and traces. `streamText`'s `telemetry` option stays and is a no-op without a registered tracer | | `@vercel/analytics` | `components/cloudflare-web-analytics.tsx`, rendered in the root layout only when `NEXT_PUBLIC_CF_BEACON_TOKEN` is set at build time | -| Vercel AI Gateway (`ai`'s `gateway` provider, `AI_GATEWAY_API_KEY`; OIDC on Vercel) | Unchanged — an HTTPS API; the key is a Worker secret. `baseURL` on the provider can point at Cloudflare AI Gateway's OpenAI-compatible endpoint instead, with no other change | +| Vercel AI Gateway (`ai`'s `gateway` provider, `AI_GATEWAY_API_KEY`; OIDC on Vercel) | **Superseded by AC5.** Workers AI through the Worker's `AI` binding (`workers-ai-provider`) is the default: Kimi K2.6 (`@cf/moonshotai/kimi-k2.6`) for the chat and the artifact tools, GLM 4.7 Flash (`@cf/zai-org/glm-4.7-flash`, thinking off) for titles. Upstream's gateway models are offered only when the optional `AI_GATEWAY_API_KEY` Worker secret is set (`getAvailableModels`). *AC1–AC4: unchanged — an HTTPS API, its key a Worker secret.* | | Resumable streams + IP rate limit over Redis (`REDIS_URL`) | Off: no `REDIS_URL` is set. `consumeSseStream` returns before touching the stream context, `checkIpRateLimit` returns before touching Redis — both as upstream intends without Redis. The packages stay in the bundle, unused | -| Project env vars in the dashboard (`AUTH_SECRET`, `AI_GATEWAY_API_KEY`) | Worker secrets: `.dev.vars` locally, `wrangler secret put` once per environment | +| Project env vars in the dashboard (`AUTH_SECRET`, `AI_GATEWAY_API_KEY`) | Worker secrets: `.dev.vars` locally, `wrangler secret put` once per environment. **Since AC5 both are optional**: unset, the session key is the one migration `020_app_secrets` generated into `app_private.secrets` (`lib/auth-secret.ts`), and the chat runs on Workers AI only | | Deploy on push | Orun: `apps/web/component.yaml` (`cloudflare-workers-assets-turbo`) deploys `ai-chatbot-web-{stage,prod}` on merge to `main` once the product is linked, after the three roots and db-migrate | ## 3. The request flow ``` browser ──► ai-chatbot-web- (Worker) - ├─ proxy.ts: /ping → pong; no session → /api/auth/guest + ├─ proxy.ts: /ping → pong, /api/health → ok; no session → /api/auth/guest ├─ next-auth: credentials / guest ──► getDb() ──► HYPERDRIVE ──► Supabase Postgres ├─ POST /api/chat ──► getDb() (entitlement, chat, messages) - │ └─► AI Gateway (HTTPS, AI_GATEWAY_API_KEY) ──► model + │ ├─► AI binding (Workers AI) ──► model (the default, since AC5) + │ └─► AI Gateway (HTTPS, AI_GATEWAY_API_KEY) ──► model (only with the key) ├─ POST /api/files/upload ──► BLOB.put(/) ──► R2 └─ GET /api/files// ──► BLOB.get ──► stream (public by URL) ``` @@ -65,7 +72,9 @@ the guest sign-in and create a user per fetch). / `revalidateTag` / `unstable_cache`, and every page is dynamic behind `auth()`; what `next build` pre-renders is the static shells. The static-assets incremental cache serves those from the Worker's assets -(`populateCache local` in the build script), the shape every port in the +(`populateCache local` in the build script — since AC5, the same copy made +by `scripts/populate-static-assets-cache.mjs`, which opens no platform +proxy), the shape every port in the series uses when nothing revalidates. The composable cache that the static-assets cache does not support is not used. @@ -73,7 +82,9 @@ The one caching hint left is `fetch(..., { next: { revalidate } })` in `lib/ai/models.ts` (the gateway's model-capability and availability lookups). On a read-only cache that data-cache write is a no-op, so those lookups go to the gateway on each call; `/api/models` still sets a day-long -`Cache-Control` for the browser. A deployment that wants them cached swaps +`Cache-Control` for the browser. (Since AC5 the Workers AI models declare +their capabilities, so these lookups happen only for gateway models, offered +only when `AI_GATEWAY_API_KEY` is set.) A deployment that wants them cached swaps `open-next.config.ts` to `r2IncrementalCache` on the same bucket (a second binding `NEXT_INC_CACHE_R2_BUCKET` on the `cloudflare-r2` wiring token, plus the `WORKER_SELF_REFERENCE` service binding named `ai-chatbot-web-`); @@ -84,27 +95,34 @@ the Orun lane, and first requests render on demand. Not taken here. ``` infra/terraform/supabase ──apply──► orun secrets (project/ rung) - SUPABASE_PROJECT_REF, SUPABASE_DB_PASSWORD, SUPABASE_DB_URL, SUPABASE_URL, - SUPABASE_ANON_KEY, SUPABASE_SERVICE_ROLE_KEY, WIRING_SUPABASE + SUPABASE_PROJECT_REF, SUPABASE_DB_PASSWORD, SUPABASE_DB_URL + (Lumen's three outputs since AC5; the API keys and WIRING_SUPABASE are gone) │ ├──► infra/terraform/cloudflare-hyperdrive (origin = the project's Postgres) │ ──apply──► WIRING_CLOUDFLARE_HYPERDRIVE {hyperdrive_id, hyperdrive_name} ├──► infra/db-migrate (plan|apply packages/db/src/migrations through the Management API) │ -infra/terraform/cloudflare-r2 ──apply──► WIRING_CLOUDFLARE_R2 {r2_bucket_name} +infra/terraform/cloudflare-r2 ──apply──► WIRING_CLOUDFLARE_R2 {r2_bucket_name} (its own r2-data key) │ apps/web/component.yaml secretEnv ◄──────────┘ WIRING_CLOUDFLARE_HYPERDRIVE_, WIRING_CLOUDFLARE_R2_ → tooling/wire/live.mjs → wrangler.jsonc (hyperdrive id, r2 bucket_name) -Worker secrets (per environment, by hand): AUTH_SECRET, AI_GATEWAY_API_KEY +Worker secrets (per environment, by hand) — optional since AC5: + AUTH_SECRET (unset: the key 020_app_secrets generated in app_private.secrets) + AI_GATEWAY_API_KEY (unset: Workers AI only, through the AI binding) Build-time, optional: NEXT_PUBLIC_CF_BEACON_TOKEN ``` `wrangler.template.jsonc` carries `@@wiring(cloudflare-hyperdrive/__ENV__:hyperdrive_id)@@` -and `@@wiring(cloudflare-r2/__ENV__:r2_bucket_name)@@`. The verify lane (and -`pnpm run wire:fixture`) renders it from `wiring.fixture.json`; the deploy -lane renders it from the live documents for `$ORUN_ENVIRONMENT`. The -rendered `wrangler.jsonc` is git-ignored. The Hyperdrive binding also names +and `@@wiring(cloudflare-r2/__ENV__:r2_bucket_name)@@`. `pnpm run +wire:fixture` renders it from `wiring.fixture.json`. ~~The verify lane renders +it from the fixture, the deploy lane from the live documents; the rendered +`wrangler.jsonc` is git-ignored.~~ **Superseded by AC5:** `wrangler.jsonc` is +committed as the fixture render (with a GENERATED banner), so the lane's +structure check finds it in a fresh checkout, and every lane re-renders it in +its own job tree — stage and prod from that environment's wiring documents +(refusing to build without them), dev from the fixture +(`live.mjs --fixture-envs dev`). The Hyperdrive binding also names a `localConnectionString` (a Postgres on localhost) for `wrangler dev` and `next dev`. @@ -115,13 +133,14 @@ apps/web the template (app/, components/, lib/, artifacts/, lib/db/queries.ts getDb(): the per-call Hyperdrive client; every query as written lib/geo.ts, lib/bot.ts the @vercel/functions and BotID stand-ins app/(chat)/api/files/ upload → R2; [...key] → serve from R2 - component.yaml render wrangler from the two wiring documents, build with turbo, deploy, smoke /ping - wrangler.template.jsonc worker name, nodejs_compat, ASSETS, HYPERDRIVE (+ localConnectionString), BLOB + component.yaml render wrangler from the two wiring documents, build with turbo, deploy, smoke /ping and /api/health + wrangler.template.jsonc worker name, nodejs_compat, ASSETS, HYPERDRIVE (+ localConnectionString), BLOB, AI (since AC5) + wrangler.jsonc the fixture render, committed (since AC5) wiring.fixture.json offline values for the verify lane open-next.config.ts static-assets incremental cache -packages/db @saas/db: the control migration + 010_initial (the template's SQL), the runner +packages/db @saas/db: the control migration + 010_initial (the template's SQL), 020_app_secrets and 030_row_level_security (AC5), the runner infra/db-migrate applies packages/db/src/migrations per environment (depends on db, supabase) -infra/terraform/supabase the Supabase project per environment (Lumen's root + API keys) +infra/terraform/supabase the Supabase project per environment (Lumen's root; its API-key outputs dropped in AC5) infra/terraform/cloudflare-hyperdrive the Hyperdrive config over that project's Postgres infra/terraform/cloudflare-r2 the attachments bucket per environment tests/web vitest: lib/utils, entitlements, the bot and geo shims, the two attachment routes (mocked session, mocked R2) @@ -135,7 +154,10 @@ needs a running app with a database and a model key and is not run in CI. `next build` (Turbopack, standalone output traced from the monorepo root, `cacheComponents` and `reactCompiler` kept, the `experimental.*` flags -kept) → `opennextjs-cloudflare build --skipBuild` → `populateCache local`. +kept) → `opennextjs-cloudflare build --skipBuild` → `populateCache local` +(since AC5, `scripts/populate-static-assets-cache.mjs`: the same copy, +without opening the platform proxy, so a build needs no Cloudflare +credential). Lint is the template's own `ultracite check` (Biome 2.5), wired as the package's `lint` script so `turbo run lint` runs it. @@ -160,11 +182,15 @@ which is kept as written and untested. Worker (an HTTPS API), but leaves a Vercel dependency and a Vercel bill in a Cloudflare deployment; R2 behind the Worker's own route is a one-file change on each side. -- **Workers AI as the model.** The template is gateway-shaped: model ids, +- ~~**Workers AI as the model.** The template is gateway-shaped: model ids, `gatewayOrder`, the capabilities and availability lookups all speak the AI Gateway's API. Swapping the provider would change the model list and the UI; pointing the same provider at Cloudflare AI Gateway is the - no-code-change option a deployment can take. + no-code-change option a deployment can take.~~ **Reversed in AC5:** + Workers AI is the default. A product built unattended must chat with only + Cloudflare and Supabase connected, and the platform brokers no AI vendor + (risk AC-K). The gateway's models stay, as upstream lists them, offered + only when `AI_GATEWAY_API_KEY` is set. - **R2 incremental cache from the start.** Nothing revalidates and nothing is `"use cache"`; the only beneficiary would be the fetch data cache for the gateway's model lookups. The static-assets cache needs no extra diff --git a/specs/epics/ai-chatbot/epic.yaml b/specs/epics/ai-chatbot/epic.yaml index 5baea9e..3e71000 100644 --- a/specs/epics/ai-chatbot/epic.yaml +++ b/specs/epics/ai-chatbot/epic.yaml @@ -45,3 +45,10 @@ spec: - "every table in public has row-level security and no policy: Supabase's Data API (anon, authenticated) reads and writes nothing, the app, as the tables' owner, everything" - "Baseline CI is green: contract tests, the blueprint read by the pinned orun, the leak gate, the offline bootstrap and the product's plans, and the end-to-end tier (a stand-in AI binding — Workers AI is not called offline)" tasks: [AC-6] + - name: "AC6 — the cirrus standard" + exitCriteria: + - "no file names kiox: orun is pinned where CI runs it (the orun-action `version:` in each workflow)" + - "every component carries generated docs/{overview,architecture,runbook}.md, and Baseline CI fails a pull request whose manifests and pages disagree" + - "ai/context carries this repository's current.md, decisions.md and open-risks.md, and none of them ships to a product" + - "every milestone's status row agrees with the tags" + tasks: [AC-7] diff --git a/specs/epics/ai-chatbot/implementation-plan.md b/specs/epics/ai-chatbot/implementation-plan.md index 959d9bf..edf74f6 100644 --- a/specs/epics/ai-chatbot/implementation-plan.md +++ b/specs/epics/ai-chatbot/implementation-plan.md @@ -62,7 +62,7 @@ the Worker secrets, attachments on R2, the model gateway), - the README quick start works from a fresh clone - the status file lists every PR and departure -## AC5 — a baseline 🔄 +## AC5 — a baseline (AC-6) ✅ The repository becomes an Orun baseline on the Lumen conventions, built the way cirrus-baseline v22 builds a product: in ONE landing. `blueprint.yaml` @@ -96,6 +96,31 @@ What a fresh, unattended build forces on the app: persists and lists it, round-trips an attachment through local R2, registers and signs a user in — and the Data API's roles read none of it +## AC6 — the cirrus standard (AC-7) ✅ + +Bring the baseline to cirrus-baseline's standard, with nothing about the +chatbot itself changing. + +- **No kiox.** `kiox.yaml`/`kiox.lock` pinned an orun (v2.15.0) that nothing + ran: every workflow installs orun itself through `orun-action` with its own + `version:`. The files, their two modules and the rebrand's skip entry go. +- **Component docs.** `tooling/catalog/gen-component-docs.py` writes each of + the eight components' `docs/overview.md`, `docs/architecture.md` and + `docs/runbook.md` from what the component declares, as cirrus-baseline's + do; the pages ship with the component. Baseline CI runs it with `--check`. +- **The context pack.** `ai/context/current.md`, `decisions.md` and + `open-risks.md` beside the two pages a product ships with — this + repository's own, so no module places them. +- **Status that agrees with the tags and the code.** AC5 is shipped and + tagged; `design.md` marks what AC5 superseded (Workers AI by default, the + optional `AUTH_SECRET`, the committed `wrangler.jsonc`). + +**Done when** +- `git grep -i kiox` finds nothing, and the leak gate and the offline + bootstrap pass without the two modules +- the docs check is green in Baseline CI +- this file, the status file and `epic.yaml` agree + ## Sequencing note AC1 is verified without a database: the Worker boots and every route diff --git a/specs/epics/ai-chatbot/risks-and-open-questions.md b/specs/epics/ai-chatbot/risks-and-open-questions.md index fe14a9b..eaddff8 100644 --- a/specs/epics/ai-chatbot/risks-and-open-questions.md +++ b/specs/epics/ai-chatbot/risks-and-open-questions.md @@ -30,6 +30,11 @@ capabilities, one for availability after nine seconds); the browser still caches `/api/models` for a day. The R2 incremental cache on the same bucket is the documented upgrade (design §4) if that cost matters. +*Since AC5:* the Workers AI models declare their capabilities in +`lib/ai/models.ts`, so a chat makes no capability lookups unless +`AI_GATEWAY_API_KEY` is set and the gateway's models are offered; the cost +above applies only to that deployment. + ## AC-D — Resumable streams and the IP rate limit need Redis (ACCEPTED) Both are opt-in on `REDIS_URL` upstream and both degrade cleanly without diff --git a/tasks/AC-7.TaskContract.yaml b/tasks/AC-7.TaskContract.yaml new file mode 100644 index 0000000..d2b8080 --- /dev/null +++ b/tasks/AC-7.TaskContract.yaml @@ -0,0 +1,33 @@ +apiVersion: orun.io/v1 +kind: TaskContract +metadata: + name: AC-7 + title: "The cirrus standard" +spec: + goal: The baseline meets cirrus-baseline's standard — no kiox pin (orun is pinned where CI runs it), every component documented by generated overview/architecture/runbook pages that CI keeps in step with the manifests, the agent context pack, and status documents that agree with the tags and the code + affects: + - kiox.yaml + - kiox.lock + - repo-blueprint.yaml + - testing/phases.test.sh + - tooling/rebrand/** + - tooling/catalog/** + - .github/workflows/baseline.yml + - apps/web/docs/** + - packages/db/docs/** + - infra/db-migrate/docs/** + - infra/terraform/supabase/docs/** + - infra/terraform/cloudflare-hyperdrive/docs/** + - infra/terraform/cloudflare-r2/docs/** + - tests/web/docs/** + - tests/db/docs/** + - ai/context/** + - specs/** + - tasks/** + doneWhen: + - no file names kiox, and the leak gate and the offline bootstrap place a product without it + - every component has docs/overview.md, docs/architecture.md and docs/runbook.md, and `python3 tooling/catalog/gen-component-docs.py --check` is green in Baseline CI + - ai/context carries current.md, decisions.md and open-risks.md for this repository (none of them ships) + - every milestone's status row agrees with the tags, and design.md marks what AC5 superseded + gates: + - checks diff --git a/testing/phases.test.sh b/testing/phases.test.sh index d6a61e3..0be289c 100755 --- a/testing/phases.test.sh +++ b/testing/phases.test.sh @@ -47,7 +47,7 @@ if not phases: PRODUCT = ["ai-deployment", "ai-operations", "cloudflare-hyperdrive", "cloudflare-r2", "db", "db-migrate", "db-tests", "github-workflows", "rebrand-values", "root-gitignore", "root-intent", - "root-kiox", "root-kiox-lock", "root-package-json", "root-pnpm-lock", + "root-package-json", "root-pnpm-lock", "root-pnpm-workspace", "root-readme", "root-turbo", "supabase", "tooling-eslint", "tooling-migrations", "tooling-tsconfig", "tooling-wire", "vscode", "web", "web-tests"] diff --git a/tests/db/docs/architecture.md b/tests/db/docs/architecture.md new file mode 100644 index 0000000..40a7e32 --- /dev/null +++ b/tests/db/docs/architecture.md @@ -0,0 +1,8 @@ +# db-tests — architecture + +A test package at `tests/db`. Its lane runs the suite before it builds. + +## Suites (2) + +- `migrations.test.ts` +- `row-level-security.test.ts` diff --git a/tests/db/docs/overview.md b/tests/db/docs/overview.md new file mode 100644 index 0000000..9bdd262 --- /dev/null +++ b/tests/db/docs/overview.md @@ -0,0 +1,18 @@ +# db-tests + +The test suite for **db**. It deploys nothing: its lane installs, builds and runs the tests. + +| | | +|---|---| +| Type | `turbo-package` | +| Source | `tests/db` | +| Package | `@app/db-tests` | +| Environments | `dev`: `quick-check` | + +## Depends on + +- (none) + +## Depended on by + +- (none) diff --git a/tests/db/docs/runbook.md b/tests/db/docs/runbook.md new file mode 100644 index 0000000..aa64499 --- /dev/null +++ b/tests/db/docs/runbook.md @@ -0,0 +1,26 @@ +# db-tests — runbook + +## How it runs + +Its lane runs on every pull request that changes it; it has no deployed surface. +CI plans what changed (`orun plan --changed`) and runs each lane with `orun run`; +the plan orders a component after everything it depends on. + +## Local commands + +```bash +pnpm --filter @app/db-tests build +pnpm --filter @app/db-tests test +pnpm --filter @app/db-tests typecheck +pnpm --filter @app/db-tests lint +``` + +## Rollback + +Revert the commit on `main`. The next convergence applies the previous desired +state; nothing was changed out of band, so there is nothing else to undo. + +## Common failures + +- **A dependent fails to build after a change here**: run `pnpm typecheck` + across the workspace before merging. diff --git a/tests/web/docs/architecture.md b/tests/web/docs/architecture.md new file mode 100644 index 0000000..c9069af --- /dev/null +++ b/tests/web/docs/architecture.md @@ -0,0 +1,16 @@ +# web-tests — architecture + +A test package at `tests/web`. Its lane runs the suite before it builds. + +## Suites (10) + +- `auth-secret.test.ts` +- `bot.test.ts` +- `entitlements.test.ts` +- `files.test.ts` +- `geo.test.ts` +- `health.test.ts` +- `models.test.ts` +- `proxy.test.ts` +- `utils.test.ts` +- `wrangler-config.test.ts` diff --git a/tests/web/docs/overview.md b/tests/web/docs/overview.md new file mode 100644 index 0000000..6e02b2d --- /dev/null +++ b/tests/web/docs/overview.md @@ -0,0 +1,18 @@ +# web-tests + +The test suite for **web**. It deploys nothing: its lane installs, builds and runs the tests. + +| | | +|---|---| +| Type | `turbo-package` | +| Source | `tests/web` | +| Package | `@app/web-tests` | +| Environments | `dev`: `quick-check` | + +## Depends on + +- (none) + +## Depended on by + +- (none) diff --git a/tests/web/docs/runbook.md b/tests/web/docs/runbook.md new file mode 100644 index 0000000..c687de2 --- /dev/null +++ b/tests/web/docs/runbook.md @@ -0,0 +1,26 @@ +# web-tests — runbook + +## How it runs + +Its lane runs on every pull request that changes it; it has no deployed surface. +CI plans what changed (`orun plan --changed`) and runs each lane with `orun run`; +the plan orders a component after everything it depends on. + +## Local commands + +```bash +pnpm --filter @app/web-tests build +pnpm --filter @app/web-tests test +pnpm --filter @app/web-tests typecheck +pnpm --filter @app/web-tests lint +``` + +## Rollback + +Revert the commit on `main`. The next convergence applies the previous desired +state; nothing was changed out of band, so there is nothing else to undo. + +## Common failures + +- **A dependent fails to build after a change here**: run `pnpm typecheck` + across the workspace before merging. diff --git a/tooling/catalog/gen-component-docs.py b/tooling/catalog/gen-component-docs.py new file mode 100644 index 0000000..2a6a8b8 --- /dev/null +++ b/tooling/catalog/gen-component-docs.py @@ -0,0 +1,519 @@ +#!/usr/bin/env python3 +"""Generate each component's docs (overview / architecture / runbook). + + python3 tooling/catalog/gen-component-docs.py # write + python3 tooling/catalog/gen-component-docs.py --check # fail on drift (CI) + +The Orun workspace's Docs library renders the `docs/` folder next to every +`component.yaml`. These pages are generated, not hand-written, because almost +everything in them is already declared somewhere CI validates: the component's +manifest (type, description, dependencies, environments, the secrets a lane +resolves, the smoke), its Worker config (bindings, triggers, the wiring the +deploy fills in), its Terraform (resources and outputs), its migrations and its +package scripts. A hand-written copy of those facts drifts the first time one +changes; a generated one cannot, because `--check` fails the pull request that +changes the fact without the page. + +What is NOT derivable (why a component exists, what a failure means for this +product in particular) belongs in the component's `description` and in the +product's own docs, not here. + +The pages ship with the component into every product built from this tree, so +they say nothing about where they came from: no factory paths, no generator +path, no provenance. Zero dependencies beyond PyYAML. +""" + +from __future__ import annotations + +import json +import pathlib +import re +import sys + +try: + import yaml +except ImportError: # pragma: no cover - the contract job installs it + sys.exit("gen-component-docs needs PyYAML (pip install pyyaml)") + +ROOT = pathlib.Path(__file__).resolve().parents[2] +ROOTS = ("apps", "packages", "infra", "tests") +SKIP_DIRS = {"node_modules", "dist", ".turbo", "docs", ".next", ".open-next", + ".wrangler", ".svelte-kit", ".nuxt", ".output", ".astro", "coverage"} + +# Paths a shipped page must never name: products are not placed with them. +FACTORY = re.compile( + r"repo-blueprint|BOOTSTRAP\.md|(? str: + """JSONC → JSON: drop comments outside strings, then trailing commas.""" + out, i, n, in_str = [], 0, len(text), False + while i < n: + c = text[i] + if in_str: + out.append(c) + if c == "\\" and i + 1 < n: + out.append(text[i + 1]) + i += 2 + continue + if c == '"': + in_str = False + i += 1 + continue + if c == '"': + in_str = True + out.append(c) + i += 1 + elif text.startswith("//", i): + j = text.find("\n", i) + i = n if j < 0 else j + elif text.startswith("/*", i): + j = text.find("*/", i + 2) + i = n if j < 0 else j + 2 + else: + out.append(c) + i += 1 + return re.sub(r",(\s*[}\]])", r"\1", "".join(out)) + + +def read_json(path: pathlib.Path) -> dict | None: + try: + return json.loads(strip_jsonc(path.read_text(encoding="utf-8"))) + except (OSError, ValueError): + return None + + +def rel(p: pathlib.Path) -> str: + return p.relative_to(ROOT).as_posix() + + +def discover() -> list[dict]: + found = [] + for root in ROOTS: + base = ROOT / root + if not base.is_dir(): + continue + stack = [base] + while stack: + d = stack.pop() + for entry in sorted(d.iterdir()): + if entry.is_dir(): + if entry.name in SKIP_DIRS or entry.name.startswith("."): + continue + if (entry / "main.tf").exists() and not (entry / "component.yaml").exists(): + continue + if len(entry.relative_to(base).parts) <= 3: + stack.append(entry) + elif entry.name == "component.yaml": + found.append(read_component(entry)) + comps = [c for c in found if c["name"] and c["type"]] + return sorted(comps, key=lambda c: c["name"]) + + +def read_component(file: pathlib.Path) -> dict: + doc = yaml.safe_load(file.read_text(encoding="utf-8")) or {} + meta, spec = doc.get("metadata") or {}, doc.get("spec") or {} + params = spec.get("parameters") or {} + deps = [d.get("component") for d in (spec.get("dependsOn") or []) if isinstance(d, dict)] + envs = [] + for e in ((spec.get("subscribe") or {}).get("environments") or []): + rules = [(r.get("profile"), ((r.get("when") or {}).get("triggerRef"))) + for r in (e.get("profileRules") or [])] + envs.append({"name": e.get("name"), "profile": e.get("profile"), "rules": rules}) + return { + "dir": file.parent, + "path": rel(file.parent), + "name": meta.get("name"), + "description": (meta.get("description") or "").strip(), + "type": spec.get("type"), + "deps": [d for d in deps if d], + "secret_env": sorted((spec.get("secretEnv") or {}).keys()), + "envs": envs, + "params": params, + "migrations_path": spec.get("path") if spec.get("type") == "db-migrate" else None, + } + + +def package_of(c: dict) -> dict | None: + return read_json(c["dir"] / "package.json") + + +def worker_config(c: dict) -> tuple[str | None, dict | None]: + """The config a deploy uses: the template when wiring renders one.""" + names = ["wrangler.template.jsonc", c["params"].get("wranglerConfig") or "", + "wrangler.jsonc", "wrangler.json"] + for name in names: + if name and (c["dir"] / name).is_file(): + return name, read_json(c["dir"] / name) + return None, None + + +WIRING = re.compile(r"@@wiring\(([^/)]+)/__ENV__:([^)]+)\)@@") + + +def wired(value) -> str | None: + m = WIRING.search(str(value)) if value is not None else None + return f"`{m.group(2)}` from `{m.group(1)}`" if m else None + + +def bindings(cfg: dict) -> list[tuple[str, str, str]]: + rows = [] + for kv in cfg.get("kv_namespaces") or []: + rows.append((kv.get("binding"), "Workers KV namespace", wired(kv.get("id")) or "declared in the config")) + for b in cfg.get("r2_buckets") or []: + rows.append((b.get("binding"), "R2 bucket", wired(b.get("bucket_name")) or f"`{b.get('bucket_name')}`")) + for d in cfg.get("d1_databases") or []: + rows.append((d.get("binding"), "D1 database", wired(d.get("database_id")) or "declared in the config")) + for h in cfg.get("hyperdrive") or []: + rows.append((h.get("binding"), "Hyperdrive (pooled Postgres)", wired(h.get("id")) or "declared in the config")) + if isinstance(cfg.get("ai"), dict) and cfg["ai"].get("binding"): + rows.append((cfg["ai"]["binding"], "Workers AI", "account-level; no resource to provision")) + for d in ((cfg.get("durable_objects") or {}).get("bindings") or []): + rows.append((d.get("name"), "Durable Object", f"class `{d.get('class_name')}`")) + for s in cfg.get("services") or []: + rows.append((s.get("binding"), "Service binding", f"Worker `{s.get('service')}`")) + for q in ((cfg.get("queues") or {}).get("producers") or []): + rows.append((q.get("binding"), "Queue producer", f"queue `{q.get('queue')}`")) + for r in cfg.get("ratelimits") or []: + simple = r.get("simple") or {} + rows.append((r.get("name"), "Rate limiter", + f"{simple.get('limit')} requests / {simple.get('period')}s per location")) + assets = cfg.get("assets") or {} + if assets.get("binding"): + rows.append((assets["binding"], "Static assets", f"`{assets.get('directory')}`")) + return [r for r in rows if r[0]] + + +def tf_facts(c: dict) -> dict: + tf_dir = c["dir"] / (c["params"].get("terraformDir") or "terraform") + resources, outputs, variables, backend = [], [], [], None + for f in sorted(tf_dir.glob("*.tf")) if tf_dir.is_dir() else []: + text = f.read_text(encoding="utf-8") + resources += [f"{t}.{n}" for t, n in re.findall(r'^resource\s+"([^"]+)"\s+"([^"]+)"', text, re.M)] + outputs += re.findall(r'^output\s+"([^"]+)"', text, re.M) + variables += re.findall(r'^variable\s+"([^"]+)"', text, re.M) + m = re.search(r'backend\s+"([^"]+)"', text) + backend = backend or (m.group(1) if m else None) + imports = (tf_dir / "adopt.tf").is_file() if tf_dir.is_dir() else False + return {"dir": rel(tf_dir) if tf_dir.is_dir() else None, "resources": resources, + "outputs": outputs, "variables": variables, "backend": backend, "adopt": imports} + + +def published(c: dict) -> list[tuple[str, str]]: + spec = c["params"].get("secretOutputs") or "" + pairs = [] + for part in str(spec).split(","): + if "=" in part: + k, v = part.split("=", 1) + pairs.append((k.strip(), v.strip())) + return pairs + + +def test_files(c: dict) -> list[str]: + out = [] + for p in sorted(c["dir"].rglob("*")): + if any(part in SKIP_DIRS for part in p.relative_to(c["dir"]).parts): + continue + if p.is_file() and re.search(r"\.(test|spec)\.(ts|tsx|js|mjs|cjs)$", p.name): + out.append(p.name) + return out + + +def migrations(c: dict) -> list[str]: + path = c["migrations_path"] + if not path: + return [] + d = ROOT / path + if not d.is_dir(): + return [] + return sorted(p.name for p in d.iterdir() if p.is_dir() or p.suffix == ".sql") + + +# ── phrasing ───────────────────────────────────────────────────────────── + +KIND = { + "cloudflare-worker-turbo": "A Cloudflare Worker, deployed per environment by its CI lane.", + "cloudflare-workers-assets-turbo": "A Cloudflare Worker with Static Assets (server rendering plus " + "static files), deployed per environment by its CI lane.", + "terraform": "Terraform-managed infrastructure, planned and applied per environment by its CI lane.", + "db-migrate": "Applies this repository's ordered database migrations per environment: " + "plan on pull requests, apply on merge to `main`.", + "turbo-package": "A workspace package built by the turbo pipeline. It deploys nothing itself: " + "its lane type-checks, lints, tests and builds it.", +} + +TRIGGER = {"github-push-main": "a push to `main`", "github-pull-request": "a pull request"} + + +def env_line(e: dict) -> str: + s = f"`{e['name']}`: `{e['profile']}`" + for profile, ref in e["rules"]: + s += f", `{profile}` on {TRIGGER.get(ref, f'`{ref}`')}" + return s + + +def is_tests(c: dict) -> bool: + return c["name"].endswith("-tests") or c["path"].startswith("tests/") + + +def subject_of(c: dict, by_name: dict) -> str | None: + if c["name"].endswith("-tests"): + s = c["name"][: -len("-tests")] + return s if s in by_name else None + return None + + +def bullet_list(names: list[str], by_name: dict) -> list[str]: + if not names: + return ["- (none)"] + out = [] + for n in names: + d = by_name.get(n) + out.append(f"- **{n}** — {d['description']}" if d and d["description"] else f"- **{n}**") + return out + + +# ── pages ──────────────────────────────────────────────────────────────── + +def overview(c: dict, by_name: dict, dependents: list[str]) -> str: + pkg = package_of(c) + kind = KIND.get(c["type"], f"A `{c['type']}` component.") + subject = subject_of(c, by_name) + if is_tests(c): + kind = (f"The test suite for **{subject}**. " if subject else "A test suite. ") + \ + "It deploys nothing: its lane installs, builds and runs the tests." + lines = [f"# {c['name']}", ""] + if c["description"]: + lines += [c["description"], ""] + lines += [kind, "", "| | |", "|---|---|", f"| Type | `{c['type']}` |", f"| Source | `{c['path']}` |"] + if pkg and pkg.get("name"): + lines.append(f"| Package | `{pkg['name']}` |") + if c["envs"]: + lines.append(f"| Environments | {' · '.join(env_line(e) for e in c['envs'])} |") + lines += ["", "## Depends on", "", *bullet_list(c["deps"], by_name), + "", "## Depended on by", "", *bullet_list(dependents, by_name), ""] + return "\n".join(lines) + + +def architecture(c: dict, by_name: dict) -> str: + lines = [f"# {c['name']} — architecture", ""] + t = c["type"] + + if t == "terraform": + f = tf_facts(c) + lines += [f"A `terraform` root at `{f['dir'] or c['path']}`.", ""] + if f["backend"] == "http": + lines += ["- **State** lives in the Orun Cloud HTTP state backend — no local state and", + " no state bucket to manage."] + lines += ["- **Credentials are brokered per run** from the workspace's provider", + " connections and resolved by name; none is stored in this repository."] + if f["adopt"]: + lines += ["- **Adoption** (`adopt.tf`): when state is empty but the resource already", + " exists, plan-time import adopts it instead of failing."] + lines.append("") + if f["resources"]: + lines += ["## Resources", "", *[f"- `{r}`" for r in f["resources"]], ""] + pub = published(c) + if pub: + lines += ["## Published outputs", "", + "Written as job-output secrets on each environment after an apply; deploy", + "lanes downstream resolve them by name.", "", + "| Secret | Terraform output |", "|---|---|", + *[f"| `{k}` | `{v}` |" for k, v in pub], ""] + elif f["outputs"]: + lines += ["## Outputs", "", *[f"- `{o}`" for o in f["outputs"]], ""] + if c["secret_env"]: + lines += ["## Resolved at run time (names only)", "", + *[f"- `{k}`" for k in c["secret_env"]], ""] + return "\n".join(lines) + + if t == "db-migrate": + migs = migrations(c) + lines += [f"Applies the migrations under `{c['migrations_path']}` in order, recording each one", + "it applies so a run only ever applies what is new. An already-applied migration", + "is never edited: a change is a new, later migration.", ""] + if migs: + lines += ["## Migrations", "", *[f"- `{m}`" for m in migs], ""] + if c["secret_env"]: + lines += ["## Resolved at run time (names only)", "", + *[f"- `{k}`" for k in c["secret_env"]], ""] + return "\n".join(lines) + + pkg = package_of(c) + if t.startswith("cloudflare-"): + cfg_name, cfg = worker_config(c) + lines += [f"Built by the turbo pipeline from `{c['path']}` and deployed with wrangler.", ""] + if cfg: + lines += ["| | |", "|---|---|", f"| Worker config | `{c['path']}/{cfg_name}` |"] + if cfg.get("main"): + lines.append(f"| Entry | `{cfg['main']}` |") + if cfg.get("compatibility_date"): + lines.append(f"| Compatibility date | `{cfg['compatibility_date']}` |") + if cfg.get("compatibility_flags"): + lines.append(f"| Compatibility flags | {', '.join(f'`{x}`' for x in cfg['compatibility_flags'])} |") + lines.append("") + rows = bindings(cfg) + lines += ["## Bindings", ""] + if rows: + lines += ["| Binding | Kind | Source |", "|---|---|---|", + *[f"| `{b}` | {k} | {s} |" for b, k, s in rows], ""] + if any("from `" in s for _, _, s in rows): + lines += ["Identifiers marked *from* a component are filled in at deploy time from", + "that component's published outputs for the environment being deployed.", ""] + else: + lines += ["None: the Worker binds no storage or service.", ""] + crons = (cfg.get("triggers") or {}).get("crons") or [] + if crons: + lines += ["## Scheduled triggers", "", *[f"- `{x}`" for x in crons], ""] + env_names = sorted((cfg.get("env") or {}).keys()) + var_names = sorted((cfg.get("vars") or {}).keys()) + if var_names: + lines += ["## Variables", "", ", ".join(f"`{v}`" for v in var_names) + + (f" — overridden per environment ({', '.join(f'`{e}`' for e in env_names)})." + if env_names else "."), ""] + wiring = [k for k in c["secret_env"] if k.startswith("WIRING_")] + others = [k for k in c["secret_env"] if not k.startswith("WIRING_")] + if wiring: + lines += ["## Wiring", "", + "Resolved at deploy time from secrets the infrastructure lanes publish (names only):", + "", *[f"- `{k}`" for k in wiring], ""] + if others: + lines += ["## Secrets resolved by the lane (names only)", "", *[f"- `{k}`" for k in others], ""] + return "\n".join(lines) + + # turbo-package + if is_tests(c): + files = test_files(c) + lines += [f"A test package at `{c['path']}`. Its lane runs the suite before it builds.", ""] + if files: + lines += [f"## Suites ({len(files)})", "", *[f"- `{f}`" for f in files], ""] + return "\n".join(lines) + lines += [f"A workspace package at `{c['path']}`, consumed at build time by the components", + "that depend on it. It holds no credentials and opens no connections of its own.", ""] + if pkg and pkg.get("exports"): + ex = pkg["exports"] + keys = sorted(ex.keys()) if isinstance(ex, dict) else ["."] + lines += ["## Exports", "", *[f"- `{k}`" for k in keys], ""] + return "\n".join(lines) + + +def runbook(c: dict, by_name: dict) -> str: + t = c["type"] + pkg = package_of(c) + lines = [f"# {c['name']} — runbook", "", "## How it runs", ""] + deploys = [e["name"] for e in c["envs"] + if any(ref == "github-push-main" for _, ref in e["rules"])] + if deploys and t in ("terraform", "db-migrate"): + lines += [f"Pull requests plan it; a merge to `main` applies it to " + f"{', '.join(f'`{e}`' for e in deploys)}."] + elif deploys: + lines += [f"Pull requests verify it; a merge to `main` deploys it to " + f"{', '.join(f'`{e}`' for e in deploys)}."] + else: + lines += ["Its lane runs on every pull request that changes it; it has no deployed surface."] + lines += ["CI plans what changed (`orun plan --changed`) and runs each lane with `orun run`;", + "the plan orders a component after everything it depends on.", ""] + + if pkg and pkg.get("scripts"): + name = pkg.get("name") + wanted = [s for s in ("dev", "build", "test", "typecheck", "lint", "preview") if s in pkg["scripts"]] + if name and wanted: + lines += ["## Local commands", "", "```bash", + *[f"pnpm --filter {name} {s}" for s in wanted], "```", ""] + + smoke = c["params"].get("smokeCommand") + if smoke and "No smoke" not in str(smoke): + lines += ["## Verify", "", "After a deploy the lane runs this smoke against the environment it", + "deployed (`ORUN_ENVIRONMENT`); `DEPLOYED_URL` overrides the URL:", "", + "```bash", str(smoke).strip(), "```", ""] + + lines += ["## Rollback", "", + "Revert the commit on `main`. The next convergence applies the previous desired", + "state; nothing was changed out of band, so there is nothing else to undo.", "", + "## Common failures", ""] + if t == "terraform": + lines += ["- **Provider authentication fails**: the workspace's provider connection is", + " missing or revoked. Reconnect it in the console; credentials are brokered", + " from it per run.", + "- **\"Already exists\" on a first apply**: state is empty but the resource is", + " not." + (" `adopt.tf` imports it at plan time; if it still fails, the resource" + " was renamed outside Terraform." if tf_facts(c)["adopt"] else + " Import it, or delete the stray resource, then re-run."), ""] + elif t == "db-migrate": + lines += ["- **An applied migration's file changed**: the run stops rather than guess.", + " Restore the file and write the change as a new migration.", + "- **The database is unreachable**: the infrastructure lane it depends on has", + " not applied for this environment; that lane runs first in a convergence.", ""] + elif t.startswith("cloudflare-"): + lines += ["- **A `WIRING_*` secret is missing at deploy**: an infrastructure lane upstream", + " has not applied for this environment yet. Within one convergence the plan", + " runs it first; on its own, re-run that lane.", + "- **The smoke fails right after a first deploy**: a new workers.dev route can", + " answer 4xx for a few seconds and the lane retries. A failure that persists", + " is a regression in the deployed code.", ""] + else: + lines += ["- **A dependent fails to build after a change here**: run `pnpm typecheck`", + " across the workspace before merging.", ""] + return "\n".join(lines) + + +# ── main ───────────────────────────────────────────────────────────────── + +def main() -> int: + check = "--check" in sys.argv[1:] + comps = discover() + if not comps: + print("no component.yaml found", file=sys.stderr) + return 1 + by_name = {c["name"]: c for c in comps} + dependents: dict[str, list[str]] = {c["name"]: [] for c in comps} + for c in comps: + for d in c["deps"]: + dependents.setdefault(d, []).append(c["name"]) + + drifted, written, leaks = [], 0, [] + for c in comps: + pages = { + "overview.md": overview(c, by_name, sorted(dependents.get(c["name"], []))), + "architecture.md": architecture(c, by_name), + "runbook.md": runbook(c, by_name), + } + for fname, body in pages.items(): + target = c["dir"] / "docs" / fname + for n, line in enumerate(body.splitlines(), 1): + m = FACTORY.search(line) + if m: + leaks.append(f"{rel(target)}:{n} would name {m.group(0)!r}") + current = target.read_text(encoding="utf-8") if target.exists() else None + if current == body: + continue + if check: + drifted.append(rel(target)) + continue + target.parent.mkdir(parents=True, exist_ok=True) + target.write_text(body, encoding="utf-8") + written += 1 + + if leaks: + print("✗ a generated page would name a path products do not have:", file=sys.stderr) + for l in leaks: + print(f" {l}", file=sys.stderr) + return 1 + if check: + if drifted: + print(f"✗ {len(drifted)} component doc(s) differ from what the manifests say:", file=sys.stderr) + for f in drifted: + print(f" {f}", file=sys.stderr) + print("\nRun: python3 tooling/catalog/gen-component-docs.py", file=sys.stderr) + return 1 + print(f"✓ component docs match {len(comps)} component.yaml file(s)") + return 0 + print(f"✓ wrote {written} page(s) for {len(comps)} component(s)") + return 0 + + +if __name__ == "__main__": + sys.exit(main()) diff --git a/tooling/rebrand/rebrand.mjs b/tooling/rebrand/rebrand.mjs index 70fa4ad..0d51757 100644 --- a/tooling/rebrand/rebrand.mjs +++ b/tooling/rebrand/rebrand.mjs @@ -181,7 +181,6 @@ const EXCLUDE_RE = new RegExp( // product claim to be a baseline called by the product's own name. "^\\.baseline/", "^pnpm-lock\\.yaml$", - "^kiox\\.lock$", // Migrations are immutable once applied: db-migrate compares each file's // sha256 to packages/db/src/manifest.ts and to the database's ledger, so // a byte renamed here would stop every later deploy. (None names this From afe5c0b8fccbdfa0d6cfb433f1195ac5fb2aa648 Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 18 Oct 2026 14:21:54 +0000 Subject: [PATCH 2/6] =?UTF-8?q?AC6:=20design.md=20=E2=80=94=20the=20proxy?= =?UTF-8?q?=20passes=20/api/health=20through,=20it=20does=20not=20answer?= =?UTF-8?q?=20it?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01D8AmgTwmnp4M8mgmnS9aha --- specs/epics/ai-chatbot/design.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/specs/epics/ai-chatbot/design.md b/specs/epics/ai-chatbot/design.md index 8c68762..71475a7 100644 --- a/specs/epics/ai-chatbot/design.md +++ b/specs/epics/ai-chatbot/design.md @@ -51,7 +51,7 @@ the `Geo` type), `@vercel/otel` + `@ai-sdk/otel` in `instrumentation.ts`, ``` browser ──► ai-chatbot-web- (Worker) - ├─ proxy.ts: /ping → pong, /api/health → ok; no session → /api/auth/guest + ├─ proxy.ts: /ping → pong; /api/health passes without a session; no session → /api/auth/guest ├─ next-auth: credentials / guest ──► getDb() ──► HYPERDRIVE ──► Supabase Postgres ├─ POST /api/chat ──► getDb() (entitlement, chat, messages) │ ├─► AI binding (Workers AI) ──► model (the default, since AC5) From 0ed0c2b1e739dffdac2a4e649ba8be081ef4963a Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 18 Oct 2026 14:27:24 +0000 Subject: [PATCH 3/6] AC6: word the kiox criterion as the record allows MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Nothing outside this milestone's own record names kiox — the record of the removal necessarily does. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01D8AmgTwmnp4M8mgmnS9aha --- specs/epics/ai-chatbot/epic.yaml | 2 +- specs/epics/ai-chatbot/implementation-plan.md | 5 +++-- tasks/AC-7.TaskContract.yaml | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/specs/epics/ai-chatbot/epic.yaml b/specs/epics/ai-chatbot/epic.yaml index 3e71000..c9e2c2c 100644 --- a/specs/epics/ai-chatbot/epic.yaml +++ b/specs/epics/ai-chatbot/epic.yaml @@ -47,7 +47,7 @@ spec: tasks: [AC-6] - name: "AC6 — the cirrus standard" exitCriteria: - - "no file names kiox: orun is pinned where CI runs it (the orun-action `version:` in each workflow)" + - "nothing outside this milestone's own record names kiox: orun is pinned where CI runs it (the orun-action `version:` in each workflow)" - "every component carries generated docs/{overview,architecture,runbook}.md, and Baseline CI fails a pull request whose manifests and pages disagree" - "ai/context carries this repository's current.md, decisions.md and open-risks.md, and none of them ships to a product" - "every milestone's status row agrees with the tags" diff --git a/specs/epics/ai-chatbot/implementation-plan.md b/specs/epics/ai-chatbot/implementation-plan.md index edf74f6..792a0fa 100644 --- a/specs/epics/ai-chatbot/implementation-plan.md +++ b/specs/epics/ai-chatbot/implementation-plan.md @@ -116,8 +116,9 @@ chatbot itself changing. optional `AUTH_SECRET`, the committed `wrangler.jsonc`). **Done when** -- `git grep -i kiox` finds nothing, and the leak gate and the offline - bootstrap pass without the two modules +- nothing outside this milestone's own record names kiox (`git grep -i + kiox`), and the leak gate and the offline bootstrap pass without the two + modules - the docs check is green in Baseline CI - this file, the status file and `epic.yaml` agree diff --git a/tasks/AC-7.TaskContract.yaml b/tasks/AC-7.TaskContract.yaml index d2b8080..bd7e20c 100644 --- a/tasks/AC-7.TaskContract.yaml +++ b/tasks/AC-7.TaskContract.yaml @@ -25,7 +25,7 @@ spec: - specs/** - tasks/** doneWhen: - - no file names kiox, and the leak gate and the offline bootstrap place a product without it + - nothing outside this milestone's own record names kiox, and the leak gate and the offline bootstrap place a product without it - every component has docs/overview.md, docs/architecture.md and docs/runbook.md, and `python3 tooling/catalog/gen-component-docs.py --check` is green in Baseline CI - ai/context carries current.md, decisions.md and open-risks.md for this repository (none of them ships) - every milestone's status row agrees with the tags, and design.md marks what AC5 superseded From 53a1d480f9d1e41491127813615d3997b09a7a54 Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 18 Oct 2026 14:35:16 +0000 Subject: [PATCH 4/6] Component docs: list optional and per-environment secrets The generator now reads `optionalSecretEnv` (listed as "(optional)") and secrets declared per environment under `subscribe.environments[]`, so a page no longer leaves out a secret its component declares. Its tables are laid out as prettier lays them out, the WIRING_* failure is listed only for Workers that take wiring, and a package is no longer said to hold no credentials. Every starter now carries the identical generator. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01D8AmgTwmnp4M8mgmnS9aha --- apps/web/docs/architecture.md | 22 ++--- apps/web/docs/overview.md | 10 +-- infra/db-migrate/docs/overview.md | 8 +- .../docs/architecture.md | 6 +- .../cloudflare-hyperdrive/docs/overview.md | 8 +- .../cloudflare-r2/docs/architecture.md | 6 +- .../terraform/cloudflare-r2/docs/overview.md | 8 +- infra/terraform/supabase/docs/architecture.md | 8 +- infra/terraform/supabase/docs/overview.md | 8 +- packages/db/docs/architecture.md | 4 +- packages/db/docs/overview.md | 10 +-- tests/db/docs/overview.md | 10 +-- tests/web/docs/overview.md | 10 +-- tooling/catalog/gen-component-docs.py | 88 ++++++++++++------- 14 files changed, 117 insertions(+), 89 deletions(-) diff --git a/apps/web/docs/architecture.md b/apps/web/docs/architecture.md index 328bf3c..0505943 100644 --- a/apps/web/docs/architecture.md +++ b/apps/web/docs/architecture.md @@ -2,23 +2,23 @@ Built by the turbo pipeline from `apps/web` and deployed with wrangler. -| | | -|---|---| -| Worker config | `apps/web/wrangler.template.jsonc` | -| Entry | `.open-next/worker.js` | -| Compatibility date | `2026-10-01` | +| | | +| ------------------- | ----------------------------------------------- | +| Worker config | `apps/web/wrangler.template.jsonc` | +| Entry | `.open-next/worker.js` | +| Compatibility date | `2026-10-01` | | Compatibility flags | `nodejs_compat`, `global_fetch_strictly_public` | ## Bindings -| Binding | Kind | Source | -|---|---|---| -| `BLOB` | R2 bucket | `r2_bucket_name` from `cloudflare-r2` | +| Binding | Kind | Source | +| ------------ | ---------------------------- | -------------------------------------------- | +| `BLOB` | R2 bucket | `r2_bucket_name` from `cloudflare-r2` | | `HYPERDRIVE` | Hyperdrive (pooled Postgres) | `hyperdrive_id` from `cloudflare-hyperdrive` | -| `AI` | Workers AI | account-level; no resource to provision | -| `ASSETS` | Static assets | `.open-next/assets` | +| `AI` | Workers AI | account-level; no resource to provision | +| `ASSETS` | Static assets | `.open-next/assets` | -Identifiers marked *from* a component are filled in at deploy time from +Identifiers marked _from_ a component are filled in at deploy time from that component's published outputs for the environment being deployed. ## Wiring diff --git a/apps/web/docs/overview.md b/apps/web/docs/overview.md index d893753..532b224 100644 --- a/apps/web/docs/overview.md +++ b/apps/web/docs/overview.md @@ -4,11 +4,11 @@ Vercel's Next.js AI Chatbot (Next.js on Cloudflare Workers + Static Assets via @ A Cloudflare Worker with Static Assets (server rendering plus static files), deployed per environment by its CI lane. -| | | -|---|---| -| Type | `cloudflare-workers-assets-turbo` | -| Source | `apps/web` | -| Package | `@app/web` | +| | | +| ------------ | ------------------------------------------------------------------------------------------------------------------ | +| Type | `cloudflare-workers-assets-turbo` | +| Source | `apps/web` | +| Package | `@app/web` | | Environments | `dev`: `verify` · `stage`: `verify`, `deploy` on a push to `main` · `prod`: `verify`, `deploy` on a push to `main` | ## Depends on diff --git a/infra/db-migrate/docs/overview.md b/infra/db-migrate/docs/overview.md index 16dfe32..106657c 100644 --- a/infra/db-migrate/docs/overview.md +++ b/infra/db-migrate/docs/overview.md @@ -4,10 +4,10 @@ Applies database migrations to stage and prod Supabase instances Applies this repository's ordered database migrations per environment: plan on pull requests, apply on merge to `main`. -| | | -|---|---| -| Type | `db-migrate` | -| Source | `infra/db-migrate` | +| | | +| ------------ | ------------------------------------------------------------------------------------------ | +| Type | `db-migrate` | +| Source | `infra/db-migrate` | | Environments | `stage`: `plan`, `apply` on a push to `main` · `prod`: `plan`, `apply` on a push to `main` | ## Depends on diff --git a/infra/terraform/cloudflare-hyperdrive/docs/architecture.md b/infra/terraform/cloudflare-hyperdrive/docs/architecture.md index 5929684..4cb812f 100644 --- a/infra/terraform/cloudflare-hyperdrive/docs/architecture.md +++ b/infra/terraform/cloudflare-hyperdrive/docs/architecture.md @@ -18,9 +18,9 @@ A `terraform` root at `infra/terraform/cloudflare-hyperdrive/terraform`. Written as job-output secrets on each environment after an apply; deploy lanes downstream resolve them by name. -| Secret | Terraform output | -|---|---| -| `WIRING_CLOUDFLARE_HYPERDRIVE` | `wiring` | +| Secret | Terraform output | +| ------------------------------ | ---------------- | +| `WIRING_CLOUDFLARE_HYPERDRIVE` | `wiring` | ## Resolved at run time (names only) diff --git a/infra/terraform/cloudflare-hyperdrive/docs/overview.md b/infra/terraform/cloudflare-hyperdrive/docs/overview.md index 2a96df0..4af25e7 100644 --- a/infra/terraform/cloudflare-hyperdrive/docs/overview.md +++ b/infra/terraform/cloudflare-hyperdrive/docs/overview.md @@ -4,10 +4,10 @@ Provisions Cloudflare Hyperdrive resources for stage and prod Supabase Postgres Terraform-managed infrastructure, planned and applied per environment by its CI lane. -| | | -|---|---| -| Type | `terraform` | -| Source | `infra/terraform/cloudflare-hyperdrive` | +| | | +| ------------ | ---------------------------------------------------------------------------------------------------- | +| Type | `terraform` | +| Source | `infra/terraform/cloudflare-hyperdrive` | | Environments | `stage`: `plan-only`, `apply` on a push to `main` · `prod`: `plan-only`, `apply` on a push to `main` | ## Depends on diff --git a/infra/terraform/cloudflare-r2/docs/architecture.md b/infra/terraform/cloudflare-r2/docs/architecture.md index f528c5b..a0da9e1 100644 --- a/infra/terraform/cloudflare-r2/docs/architecture.md +++ b/infra/terraform/cloudflare-r2/docs/architecture.md @@ -18,9 +18,9 @@ A `terraform` root at `infra/terraform/cloudflare-r2/terraform`. Written as job-output secrets on each environment after an apply; deploy lanes downstream resolve them by name. -| Secret | Terraform output | -|---|---| -| `WIRING_CLOUDFLARE_R2` | `wiring` | +| Secret | Terraform output | +| ---------------------- | ---------------- | +| `WIRING_CLOUDFLARE_R2` | `wiring` | ## Resolved at run time (names only) diff --git a/infra/terraform/cloudflare-r2/docs/overview.md b/infra/terraform/cloudflare-r2/docs/overview.md index 0eec70a..5a16abe 100644 --- a/infra/terraform/cloudflare-r2/docs/overview.md +++ b/infra/terraform/cloudflare-r2/docs/overview.md @@ -4,10 +4,10 @@ Provisions the Cloudflare R2 bucket the app binds (stage and prod) Terraform-managed infrastructure, planned and applied per environment by its CI lane. -| | | -|---|---| -| Type | `terraform` | -| Source | `infra/terraform/cloudflare-r2` | +| | | +| ------------ | ---------------------------------------------------------------------------------------------------- | +| Type | `terraform` | +| Source | `infra/terraform/cloudflare-r2` | | Environments | `stage`: `plan-only`, `apply` on a push to `main` · `prod`: `plan-only`, `apply` on a push to `main` | ## Depends on diff --git a/infra/terraform/supabase/docs/architecture.md b/infra/terraform/supabase/docs/architecture.md index 511ac12..6ab1960 100644 --- a/infra/terraform/supabase/docs/architecture.md +++ b/infra/terraform/supabase/docs/architecture.md @@ -19,11 +19,11 @@ A `terraform` root at `infra/terraform/supabase/terraform`. Written as job-output secrets on each environment after an apply; deploy lanes downstream resolve them by name. -| Secret | Terraform output | -|---|---| -| `SUPABASE_PROJECT_REF` | `project_ref` | +| Secret | Terraform output | +| ---------------------- | ------------------- | +| `SUPABASE_PROJECT_REF` | `project_ref` | | `SUPABASE_DB_PASSWORD` | `database_password` | -| `SUPABASE_DB_URL` | `connection_uri` | +| `SUPABASE_DB_URL` | `connection_uri` | ## Resolved at run time (names only) diff --git a/infra/terraform/supabase/docs/overview.md b/infra/terraform/supabase/docs/overview.md index 145a0e8..d1bf765 100644 --- a/infra/terraform/supabase/docs/overview.md +++ b/infra/terraform/supabase/docs/overview.md @@ -4,10 +4,10 @@ Provisions Supabase projects for stage and prod and wires credentials into orun Terraform-managed infrastructure, planned and applied per environment by its CI lane. -| | | -|---|---| -| Type | `terraform` | -| Source | `infra/terraform/supabase` | +| | | +| ------------ | ---------------------------------------------------------------------------------------------------- | +| Type | `terraform` | +| Source | `infra/terraform/supabase` | | Environments | `stage`: `plan-only`, `apply` on a push to `main` · `prod`: `plan-only`, `apply` on a push to `main` | ## Depends on diff --git a/packages/db/docs/architecture.md b/packages/db/docs/architecture.md index 135d4b4..3f9b079 100644 --- a/packages/db/docs/architecture.md +++ b/packages/db/docs/architecture.md @@ -1,7 +1,7 @@ # db — architecture -A workspace package at `packages/db`, consumed at build time by the components -that depend on it. It holds no credentials and opens no connections of its own. +A workspace package at `packages/db`, consumed by the components that depend +on it. It has no deployed surface of its own. ## Exports diff --git a/packages/db/docs/overview.md b/packages/db/docs/overview.md index 859cdce..c0097af 100644 --- a/packages/db/docs/overview.md +++ b/packages/db/docs/overview.md @@ -4,11 +4,11 @@ The database migrations and their runner (built by the db-migrate component befo A workspace package built by the turbo pipeline. It deploys nothing itself: its lane type-checks, lints, tests and builds it. -| | | -|---|---| -| Type | `turbo-package` | -| Source | `packages/db` | -| Package | `@saas/db` | +| | | +| ------------ | --------------------------------------------------------------------- | +| Type | `turbo-package` | +| Source | `packages/db` | +| Package | `@saas/db` | | Environments | `dev`: `quick-check` · `stage`: `quick-check` · `prod`: `quick-check` | ## Depends on diff --git a/tests/db/docs/overview.md b/tests/db/docs/overview.md index 9bdd262..ea4ef3f 100644 --- a/tests/db/docs/overview.md +++ b/tests/db/docs/overview.md @@ -2,11 +2,11 @@ The test suite for **db**. It deploys nothing: its lane installs, builds and runs the tests. -| | | -|---|---| -| Type | `turbo-package` | -| Source | `tests/db` | -| Package | `@app/db-tests` | +| | | +| ------------ | -------------------- | +| Type | `turbo-package` | +| Source | `tests/db` | +| Package | `@app/db-tests` | | Environments | `dev`: `quick-check` | ## Depends on diff --git a/tests/web/docs/overview.md b/tests/web/docs/overview.md index 6e02b2d..3534e6b 100644 --- a/tests/web/docs/overview.md +++ b/tests/web/docs/overview.md @@ -2,11 +2,11 @@ The test suite for **web**. It deploys nothing: its lane installs, builds and runs the tests. -| | | -|---|---| -| Type | `turbo-package` | -| Source | `tests/web` | -| Package | `@app/web-tests` | +| | | +| ------------ | -------------------- | +| Type | `turbo-package` | +| Source | `tests/web` | +| Package | `@app/web-tests` | | Environments | `dev`: `quick-check` | ## Depends on diff --git a/tooling/catalog/gen-component-docs.py b/tooling/catalog/gen-component-docs.py index 2a6a8b8..9a39931 100644 --- a/tooling/catalog/gen-component-docs.py +++ b/tooling/catalog/gen-component-docs.py @@ -119,7 +119,13 @@ def read_component(file: pathlib.Path) -> dict: params = spec.get("parameters") or {} deps = [d.get("component") for d in (spec.get("dependsOn") or []) if isinstance(d, dict)] envs = [] + # Secrets may be declared for the whole component or per environment + # (`subscribe.environments[].secretEnv`); a page lists both. + req_env = set((spec.get("secretEnv") or {}).keys()) + opt_env = set((spec.get("optionalSecretEnv") or {}).keys()) for e in ((spec.get("subscribe") or {}).get("environments") or []): + req_env |= set((e.get("secretEnv") or {}).keys()) + opt_env |= set((e.get("optionalSecretEnv") or {}).keys()) rules = [(r.get("profile"), ((r.get("when") or {}).get("triggerRef"))) for r in (e.get("profileRules") or [])] envs.append({"name": e.get("name"), "profile": e.get("profile"), "rules": rules}) @@ -130,7 +136,8 @@ def read_component(file: pathlib.Path) -> dict: "description": (meta.get("description") or "").strip(), "type": spec.get("type"), "deps": [d for d in deps if d], - "secret_env": sorted((spec.get("secretEnv") or {}).keys()), + "secret_env": sorted(req_env), + "optional_env": sorted(opt_env - req_env), "envs": envs, "params": params, "migrations_path": spec.get("path") if spec.get("type") == "db-migrate" else None, @@ -232,6 +239,18 @@ def migrations(c: dict) -> list[str]: return sorted(p.name for p in d.iterdir() if p.is_dir() or p.suffix == ".sql") +# ── markdown ───────────────────────────────────────────────────────────── + +def md_table(header: list[str], rows: list[list[str]]) -> list[str]: + """A table laid out the way prettier lays it out, so a repo whose lint is + `prettier --check` accepts the page as written.""" + cols = len(header) + width = [max(3, len(header[i]), *(len(r[i]) for r in rows)) for i in range(cols)] + def line(cells): + return "| " + " | ".join(c.ljust(width[i]) for i, c in enumerate(cells)) + " |" + return [line(header), "| " + " | ".join("-" * w for w in width) + " |", *(line(r) for r in rows)] + + # ── phrasing ───────────────────────────────────────────────────────────── KIND = { @@ -266,6 +285,14 @@ def subject_of(c: dict, by_name: dict) -> str | None: return None +def names_list(c: dict, keep) -> list[str]: + """Secret names a lane resolves, required first; an optional one (from + `optionalSecretEnv`) is resolved when it exists and skipped when not.""" + req = [f"- `{k}`" for k in c["secret_env"] if keep(k)] + opt = [f"- `{k}` (optional)" for k in c["optional_env"] if keep(k)] + return req + opt + + def bullet_list(names: list[str], by_name: dict) -> list[str]: if not names: return ["- (none)"] @@ -288,11 +315,12 @@ def overview(c: dict, by_name: dict, dependents: list[str]) -> str: lines = [f"# {c['name']}", ""] if c["description"]: lines += [c["description"], ""] - lines += [kind, "", "| | |", "|---|---|", f"| Type | `{c['type']}` |", f"| Source | `{c['path']}` |"] + facts = [["Type", f"`{c['type']}`"], ["Source", f"`{c['path']}`"]] if pkg and pkg.get("name"): - lines.append(f"| Package | `{pkg['name']}` |") + facts.append(["Package", f"`{pkg['name']}`"]) if c["envs"]: - lines.append(f"| Environments | {' · '.join(env_line(e) for e in c['envs'])} |") + facts.append(["Environments", " · ".join(env_line(e) for e in c["envs"])]) + lines += [kind, "", *md_table(["", ""], facts)] lines += ["", "## Depends on", "", *bullet_list(c["deps"], by_name), "", "## Depended on by", "", *bullet_list(dependents, by_name), ""] return "\n".join(lines) @@ -321,13 +349,11 @@ def architecture(c: dict, by_name: dict) -> str: lines += ["## Published outputs", "", "Written as job-output secrets on each environment after an apply; deploy", "lanes downstream resolve them by name.", "", - "| Secret | Terraform output |", "|---|---|", - *[f"| `{k}` | `{v}` |" for k, v in pub], ""] + *md_table(["Secret", "Terraform output"], [[f"`{k}`", f"`{v}`"] for k, v in pub]), ""] elif f["outputs"]: lines += ["## Outputs", "", *[f"- `{o}`" for o in f["outputs"]], ""] - if c["secret_env"]: - lines += ["## Resolved at run time (names only)", "", - *[f"- `{k}`" for k in c["secret_env"]], ""] + if c["secret_env"] or c["optional_env"]: + lines += ["## Resolved at run time (names only)", "", *names_list(c, lambda k: True), ""] return "\n".join(lines) if t == "db-migrate": @@ -337,9 +363,8 @@ def architecture(c: dict, by_name: dict) -> str: "is never edited: a change is a new, later migration.", ""] if migs: lines += ["## Migrations", "", *[f"- `{m}`" for m in migs], ""] - if c["secret_env"]: - lines += ["## Resolved at run time (names only)", "", - *[f"- `{k}`" for k in c["secret_env"]], ""] + if c["secret_env"] or c["optional_env"]: + lines += ["## Resolved at run time (names only)", "", *names_list(c, lambda k: True), ""] return "\n".join(lines) pkg = package_of(c) @@ -347,21 +372,20 @@ def architecture(c: dict, by_name: dict) -> str: cfg_name, cfg = worker_config(c) lines += [f"Built by the turbo pipeline from `{c['path']}` and deployed with wrangler.", ""] if cfg: - lines += ["| | |", "|---|---|", f"| Worker config | `{c['path']}/{cfg_name}` |"] + facts = [["Worker config", f"`{c['path']}/{cfg_name}`"]] if cfg.get("main"): - lines.append(f"| Entry | `{cfg['main']}` |") + facts.append(["Entry", f"`{cfg['main']}`"]) if cfg.get("compatibility_date"): - lines.append(f"| Compatibility date | `{cfg['compatibility_date']}` |") + facts.append(["Compatibility date", f"`{cfg['compatibility_date']}`"]) if cfg.get("compatibility_flags"): - lines.append(f"| Compatibility flags | {', '.join(f'`{x}`' for x in cfg['compatibility_flags'])} |") - lines.append("") + facts.append(["Compatibility flags", ", ".join(f"`{x}`" for x in cfg["compatibility_flags"])]) + lines += [*md_table(["", ""], facts), ""] rows = bindings(cfg) lines += ["## Bindings", ""] if rows: - lines += ["| Binding | Kind | Source |", "|---|---|---|", - *[f"| `{b}` | {k} | {s} |" for b, k, s in rows], ""] + lines += [*md_table(["Binding", "Kind", "Source"], [[f"`{b}`", k, s] for b, k, s in rows]), ""] if any("from `" in s for _, _, s in rows): - lines += ["Identifiers marked *from* a component are filled in at deploy time from", + lines += ["Identifiers marked _from_ a component are filled in at deploy time from", "that component's published outputs for the environment being deployed.", ""] else: lines += ["None: the Worker binds no storage or service.", ""] @@ -374,14 +398,14 @@ def architecture(c: dict, by_name: dict) -> str: lines += ["## Variables", "", ", ".join(f"`{v}`" for v in var_names) + (f" — overridden per environment ({', '.join(f'`{e}`' for e in env_names)})." if env_names else "."), ""] - wiring = [k for k in c["secret_env"] if k.startswith("WIRING_")] - others = [k for k in c["secret_env"] if not k.startswith("WIRING_")] + wiring = names_list(c, lambda k: k.startswith("WIRING_")) + others = names_list(c, lambda k: not k.startswith("WIRING_")) if wiring: lines += ["## Wiring", "", "Resolved at deploy time from secrets the infrastructure lanes publish (names only):", - "", *[f"- `{k}`" for k in wiring], ""] + "", *wiring, ""] if others: - lines += ["## Secrets resolved by the lane (names only)", "", *[f"- `{k}`" for k in others], ""] + lines += ["## Secrets resolved by the lane (names only)", "", *others, ""] return "\n".join(lines) # turbo-package @@ -391,8 +415,8 @@ def architecture(c: dict, by_name: dict) -> str: if files: lines += [f"## Suites ({len(files)})", "", *[f"- `{f}`" for f in files], ""] return "\n".join(lines) - lines += [f"A workspace package at `{c['path']}`, consumed at build time by the components", - "that depend on it. It holds no credentials and opens no connections of its own.", ""] + lines += [f"A workspace package at `{c['path']}`, consumed by the components that depend", + "on it. It has no deployed surface of its own.", ""] if pkg and pkg.get("exports"): ex = pkg["exports"] keys = sorted(ex.keys()) if isinstance(ex, dict) else ["."] @@ -448,10 +472,14 @@ def runbook(c: dict, by_name: dict) -> str: "- **The database is unreachable**: the infrastructure lane it depends on has", " not applied for this environment; that lane runs first in a convergence.", ""] elif t.startswith("cloudflare-"): - lines += ["- **A `WIRING_*` secret is missing at deploy**: an infrastructure lane upstream", - " has not applied for this environment yet. Within one convergence the plan", - " runs it first; on its own, re-run that lane.", - "- **The smoke fails right after a first deploy**: a new workers.dev route can", + _, cfg = worker_config(c) + takes_wiring = any(k.startswith("WIRING_") for k in c["secret_env"] + c["optional_env"]) or \ + bool(cfg and WIRING.search(json.dumps(cfg))) + if takes_wiring: + lines += ["- **A `WIRING_*` secret is missing at deploy**: an infrastructure lane upstream", + " has not applied for this environment yet. Within one convergence the plan", + " runs it first; on its own, re-run that lane."] + lines += ["- **The smoke fails right after a first deploy**: a new workers.dev route can", " answer 4xx for a few seconds and the lane retries. A failure that persists", " is a regression in the deployed code.", ""] else: From 362fba1c3cad51f30a6ca1f13b6492e7bff1de67 Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 21 Oct 2026 12:07:42 +0000 Subject: [PATCH 5/6] AC6: read the workers.dev subdomain from the Cloudflare connection - blueprint.yaml: the subdomain input is `from: connection.cloudflare.workersSubdomain`, as cirrus-baseline since baseline-v23 (#30); the console renders no field for it - testing/manifest.test.sh: cirrus's rule verbatim, accepting the source only when spec.requires.integrations lists its provider (mutation-checked) - repo-blueprint.yaml, BOOTSTRAP.md, docs/phases/README.md: only a hand-run build passes --set subdomain - records: AC-8 under AC6, status, plan, epic index, ai/context Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01D8AmgTwmnp4M8mgmnS9aha --- BOOTSTRAP.md | 6 +++ ai/context/current.md | 13 +++--- ai/context/decisions.md | 1 + blueprint.yaml | 13 ++++++ docs/phases/README.md | 6 ++- repo-blueprint.yaml | 5 ++- specs/epics/README.md | 2 +- .../epics/ai-chatbot/IMPLEMENTATION-STATUS.md | 40 ++++++++++++++++++- specs/epics/ai-chatbot/README.md | 6 +-- specs/epics/ai-chatbot/epic.yaml | 3 +- specs/epics/ai-chatbot/implementation-plan.md | 5 +++ tasks/AC-8.TaskContract.yaml | 25 ++++++++++++ testing/manifest.test.sh | 15 ++++++- 13 files changed, 122 insertions(+), 18 deletions(-) create mode 100644 tasks/AC-8.TaskContract.yaml diff --git a/BOOTSTRAP.md b/BOOTSTRAP.md index 6b92eed..0c4f30c 100644 --- a/BOOTSTRAP.md +++ b/BOOTSTRAP.md @@ -74,6 +74,12 @@ orun new --blueprint repo-blueprint.yaml \ --set subdomain= ``` +`subdomain` is the workers.dev subdomain of the Cloudflare account you deploy +into (Workers & Pages → your subdomain). A build started from the console, or +with `orun baseline new --from bst_…`, never asks for it: the platform reads +it from the workspace's Cloudflare connection, the same one the deploy tokens +mint from. Only a hand-run build like this one passes it. + **`--run-hooks` is the difference between placing files and bootstrapping a product.** Without it `orun new` writes the tree and stops: no repository, no landing, no convergence watch, no probe. That is deliberate — it is what diff --git a/ai/context/current.md b/ai/context/current.md index af3797a..6f0080c 100644 --- a/ai/context/current.md +++ b/ai/context/current.md @@ -20,8 +20,8 @@ went live (`02-docs`). | | | |---|---| -| Latest tag | `baseline-v1` (AC5, [#6](https://github.com/sourceplane/ai-chatbot/pull/6)) | -| On `main` since | AC6 — the cirrus standard (no kiox, generated component docs, this context pack) | +| Latest tag | `baseline-v2` (AC6 — the cirrus standard, [#7](https://github.com/sourceplane/ai-chatbot/pull/7) and [#8](https://github.com/sourceplane/ai-chatbot/pull/8): no kiox, generated component docs, this context pack, and the workers.dev subdomain read from the Cloudflare connection instead of asked) | +| Before it | `baseline-v1` (AC5, [#6](https://github.com/sourceplane/ai-chatbot/pull/6)) | | Proven live | No. Everything short of the platform is proven offline in Baseline CI: the e2e tier builds the product in orun's staged job tree, migrates a local Postgres with its own runner and serves the Worker over local R2 with a stand-in AI binding. No bootstrap from a tag has run against a workspace yet: the three applies, db-migrate against a real project, a real deploy, Workers AI itself (AC-K) and the `BLOB` binding under the deploy token (AC-L) are unproven | ## Where to read @@ -36,8 +36,7 @@ went live (`02-docs`). ## Next -1. Bootstrap one chatbot from a tag against a workspace with Cloudflare and - Supabase connected, and record its timings: the first proof of the - applies, the deploy, Workers AI's models and tools (AC-K) and the R2 - binding under the deploy token (AC-L). -2. Cut the next `baseline-vN` with `tag.yml` so the registry can pin AC6. +1. Bootstrap one chatbot from `baseline-v2` against a workspace with + Cloudflare and Supabase connected, and record its timings: the first + proof of the applies, the deploy, Workers AI's models and tools (AC-K) + and the R2 binding under the deploy token (AC-L). diff --git a/ai/context/decisions.md b/ai/context/decisions.md index f13e187..e84871a 100644 --- a/ai/context/decisions.md +++ b/ai/context/decisions.md @@ -18,3 +18,4 @@ reads in order. | 10 | stack-tectonic 0.19.0, not 0.20.0 | 0.20.0 links each job's `node_modules` out of its tree, which Next 16's Turbopack refuses | `intent.yaml`, BOOTSTRAP.md | | 11 | orun is pinned only where it runs (the `orun-action` `version:` in each workflow); no kiox | `kiox.yaml` pinned a version (v2.15.0) nothing ran | IMPLEMENTATION-STATUS (AC6) | | 12 | Component docs are generated from the manifests and checked in CI | A hand-written copy of the dependency graph and bindings drifts silently | `tooling/catalog/gen-component-docs.py` | +| 13 | `subdomain` is read from the Cloudflare connection (`from: connection.cloudflare.workersSubdomain`), never asked | It belongs to the account like its id and has one right answer; a typed one could only be wrong, and showed up after deploy in the public origin, the smoke and the probes | `blueprint.yaml`, IMPLEMENTATION-STATUS (AC-8) | diff --git a/blueprint.yaml b/blueprint.yaml index 5b74cb0..5f4ac5e 100644 --- a/blueprint.yaml +++ b/blueprint.yaml @@ -101,6 +101,19 @@ spec: pattern: "^[a-z0-9][a-z0-9-]{0,62}$" help: The workers.dev subdomain of the Cloudflare account the app deploys into. example: acme + # READ FROM THE CLOUDFLARE CONNECTION, not asked. The subdomain belongs + # to the account the same way its id does, and there is exactly one + # right answer — a typed one could only be wrong, and wrong showed up + # after deploy, in the public origin the Open Graph links are built + # from, the deploy's smoke, the phase probes and the verify URLs below. + # The integration reads it from Cloudflare at connect and on its hourly + # health check; the bootstrap door fills this input from the connection + # the build is BOUND to, the same one CLOUDFLARE_ACCOUNT_ID and the + # deploy tokens mint from, so all three name one account. The console + # renders no field for it. An account with no workers.dev subdomain + # refuses the build at the door, naming the fix, before anything is + # created. + from: connection.cloudflare.workersSubdomain # ── PREVIEW ONLY. repo-blueprint.yaml's `orun.integrations/reconcile@v1` # hooks mint these, brokered, during 01-product. ───────────────────────── diff --git a/docs/phases/README.md b/docs/phases/README.md index ce492d7..3d1a7b4 100644 --- a/docs/phases/README.md +++ b/docs/phases/README.md @@ -60,8 +60,10 @@ the blueprint's **required** inputs — `reponame`, `productname`, must be supplied on every invocation, single-phase ones included. A `--values` file is easier than repeating `--set`. -- `subdomain` — the workers.dev subdomain of the Cloudflare account. It is - in every URL the phases probe. +- `subdomain` — the workers.dev subdomain of the Cloudflare account you + deploy into. It is in every URL the phases probe. A console or + `--from bst_…` build reads it from the Cloudflare connection; pass it only + for a hand-run build. - `orunWorkspace` — workspace id (`ws_…`). Unset, it is the workspace the build runs in (`from: workspace`); with none anywhere, a placeholder that fails loudly rather than silently claiming another tenant's workspace. diff --git a/repo-blueprint.yaml b/repo-blueprint.yaml index 651b859..e52f8c7 100644 --- a/repo-blueprint.yaml +++ b/repo-blueprint.yaml @@ -57,7 +57,10 @@ inputs: default: "your-workers-subdomain" description: >- The workers.dev subdomain of the Cloudflare account the app deploys - into — its URLs and the probes. + into — its URLs and the probes. A console or `--from bst_…` build gets + it from the workspace's Cloudflare connection (blueprint.yaml declares + `from: connection.cloudflare.workersSubdomain`); pass it with --set + only for a hand-run build. repoPrivate: type: boolean default: true diff --git a/specs/epics/README.md b/specs/epics/README.md index 6b886c5..855c47a 100644 --- a/specs/epics/README.md +++ b/specs/epics/README.md @@ -7,6 +7,6 @@ folder is the adoption; the merge creates the epic in the workspace. | Epic | Cluster | Status | What it is | |------|---------|--------|------------| -| [`ai-chatbot/`](./ai-chatbot/) | **AC** | ✅ Shipped (`baseline-v1`); live bootstrap pending | Vercel's Next.js AI Chatbot, equivalent in code and function, on Cloudflare Workers with Supabase Postgres, Hyperdrive and R2 — and an Orun baseline that instantiates it in one landing, chatting on Workers AI (AC5) | +| [`ai-chatbot/`](./ai-chatbot/) | **AC** | ✅ Shipped (`baseline-v2`); live bootstrap pending | Vercel's Next.js AI Chatbot, equivalent in code and function, on Cloudflare Workers with Supabase Postgres, Hyperdrive and R2 — and an Orun baseline that instantiates it in one landing, chatting on Workers AI (AC5) | As-built ≠ intent: what shipped lives in each epic's `IMPLEMENTATION-STATUS.md`. diff --git a/specs/epics/ai-chatbot/IMPLEMENTATION-STATUS.md b/specs/epics/ai-chatbot/IMPLEMENTATION-STATUS.md index 46c5165..05c47ac 100644 --- a/specs/epics/ai-chatbot/IMPLEMENTATION-STATUS.md +++ b/specs/epics/ai-chatbot/IMPLEMENTATION-STATUS.md @@ -16,7 +16,7 @@ the code departed from `design.md` or from the upstream template. | AC3 — Supabase, Hyperdrive and R2 from Terraform | ✅ Shipped (validated; apply gated on a linked workspace) | [#4](https://github.com/sourceplane/ai-chatbot/pull/4) | | AC4 — ready to instantiate | ✅ Shipped | [#5](https://github.com/sourceplane/ai-chatbot/pull/5) | | AC5 — a baseline | ✅ Shipped | [#6](https://github.com/sourceplane/ai-chatbot/pull/6) (AC-6), tagged `baseline-v1` | -| AC6 — the cirrus standard | ✅ Shipped | AC-7 — on `main` after `baseline-v1`, not yet tagged | +| AC6 — the cirrus standard | ✅ Shipped | [#7](https://github.com/sourceplane/ai-chatbot/pull/7) (AC-7), [#8](https://github.com/sourceplane/ai-chatbot/pull/8) (AC-8), tagged `baseline-v2` | ## Departures from the upstream template (AC1–AC4) @@ -150,6 +150,44 @@ Nothing about the chatbot changed. What changed is the baseline around it: | status | AC5 "in review" | AC5 shipped and tagged `baseline-v1` | the tag existed; the documents had not caught up | | `design.md` | §2–§7 and §9 still described AC1–AC4: the gateway "unchanged", Workers AI a rejected alternative, `wrangler.jsonc` git-ignored, `AUTH_SECRET` and the gateway key set by hand, seven Supabase outputs | each superseded passage marked and the as-built fact beside it | the design contradicted the code AC5 shipped | +### The subdomain from the Cloudflare connection (AC-8) + +`subdomain` was the one input an operator typed that the platform could +answer itself: it belongs to the Cloudflare account the same way its id does, +and it has exactly one right answer. A typed one could only be wrong, and +wrong showed up after deploy — in the public origin the Open Graph links are +built from, the deploy's smoke, the phase probes and the console's verify +URLs. `blueprint.yaml` now declares +`from: connection.cloudflare.workersSubdomain`, as cirrus-baseline does since +baseline-v23: the Cloudflare integration reads the subdomain at connect and on +its hourly health check, and the bootstrap door fills the input from the +connection the build is bound to — the same one `CLOUDFLARE_ACCOUNT_ID` and the +deploy tokens mint from. The console renders no field for it, and an account +with no workers.dev subdomain is refused at the door with the fix named. + +- `testing/manifest.test.sh` takes cirrus-baseline's rule verbatim: the source + is accepted, and only when `spec.requires.integrations` lists its provider. +- `repo-blueprint.yaml` keeps the input and its default; it, `BOOTSTRAP.md` + and `docs/phases/README.md` say only a hand-run build passes + `--set subdomain`. +- Nothing a product carries changes: the rename writes the value where it + always did (`workersDevSubdomain`, the URLs), and the probes read it as + before. + +Verified: + +- `testing/{manifest,phases,coverage,rebrand,retouch,bootstrap-defer,wire}.test.sh` + green; `gen-component-docs.py --check` green (8 components). +- Mutation: with `cloudflare` dropped from `spec.requires.integrations`, + `manifest.test.sh` fails with exactly one finding, naming + `inputs[subdomain]`; restored, it passes. +- `orun new --status` at v2.58.11: `01-product` pending, 294 files. + `testing/leak.test.sh` at v2.58.11: 294 files derived, 287 text files read. + `testing/placement.test.sh` at v2.78.4: 294 files placed, both landings; the + product's own plan orders supabase → cloudflare-hyperdrive → db-migrate → + web and cloudflare-r2 → web; `--resume` changes nothing. +- `orun task check AC-8` complete. + ## Verified (AC6) - `testing/{manifest,phases,coverage,rebrand,retouch,bootstrap-defer,wire}.test.sh` diff --git a/specs/epics/ai-chatbot/README.md b/specs/epics/ai-chatbot/README.md index 3977051..9ea2baa 100644 --- a/specs/epics/ai-chatbot/README.md +++ b/specs/epics/ai-chatbot/README.md @@ -8,7 +8,7 @@ The upstream code stays the code: `app/(chat)/api/chat/route.ts` with `streamTex | Field | Value | |-------|-------| -| Status | ✅ AC0–AC5 shipped (#1–#6), tagged `baseline-v1`: AC5 made the repository an Orun baseline (one landing), Workers AI the default model provider, the session key the database's own and row-level security universal. AC6 (the cirrus standard, AC-7) on `main`, not yet tagged. The Supabase, Hyperdrive and R2 applies, db-migrate and a live deploy are not yet proven by a live bootstrap (risks AC-K, AC-L) | +| Status | ✅ AC0–AC5 shipped (#1–#6), tagged `baseline-v1`: AC5 made the repository an Orun baseline (one landing), Workers AI the default model provider, the session key the database's own and row-level security universal. AC6 (the cirrus standard, AC-7 #7 and AC-8 #8) tagged `baseline-v2`. The Supabase, Hyperdrive and R2 applies, db-migrate and a live deploy are not yet proven by a live bootstrap (risks AC-K, AC-L) | | Cluster | **AC** (AC0–AC6) | | Owner(s) | `apps/web` (the app) · `tests/web` (vitest) · `packages/db` + `tests/db` (the schema) · `infra/terraform/{supabase,cloudflare-hyperdrive,cloudflare-r2}` + `infra/db-migrate` | | Builds on | `lumen` conventions — the `supabase`, `cloudflare-hyperdrive` and `db-migrate` components, `@saas/db`, the orun-secrets wiring, the per-request `postgres` client; `cirrus-baseline` for the R2 root and the repository shape | @@ -16,7 +16,7 @@ The upstream code stays the code: `app/(chat)/api/chat/route.ts` with `streamTex | Changes | Adds the Workers build, the monorepo wrapper, tests, the migrations package, the infra roots and the deploy contract; in the template's code: the per-call Postgres client, the R2 attachment routes, and shims for the Vercel-only modules (`lib/bot.ts`, `lib/geo.ts`, an empty `instrumentation.ts`) | | Decisions locked | (1) OpenNext on Workers + Static Assets, `next` pinned to 16.3.8. (2) Postgres through Hyperdrive, one `postgres` client per `getDb()` call, never at module scope. (3) Attachments in R2 behind `/api/files/`, public by unguessable URL exactly as Vercel Blob's `access: "public"` was. (4) The schema ships in `packages/db` and is applied by db-migrate; drizzle-kit stays for local development. (5) Static-assets incremental cache: the app has no `use cache` and nothing revalidates. (6) No Redis: resumable streams and the IP rate limit stay off, as upstream does without `REDIS_URL`. (7) `AUTH_SECRET` and `AI_GATEWAY_API_KEY` are Worker secrets set once per environment — **superseded by AC5**: both are optional; Workers AI through the `AI` binding is the default model provider, and the session key defaults to one the database generates. | | Gate | AC1 is the first user-visible rung and is verified without a database (the Worker boots, the routes answer). AC2 and AC3 need a workspace with Supabase and Cloudflare connections to apply; they are verified by `plan`, `terraform validate` and the offline migration tests. | -| Shipped as | `baseline-v1` ([#6](https://github.com/sourceplane/ai-chatbot/pull/6)), then AC6 on `main`; proven offline (Baseline CI: contract, leak, placement and the e2e tier), deploy gated until a workspace is linked | +| Shipped as | `baseline-v1` ([#6](https://github.com/sourceplane/ai-chatbot/pull/6)), then `baseline-v2` (AC6: [#7](https://github.com/sourceplane/ai-chatbot/pull/7), [#8](https://github.com/sourceplane/ai-chatbot/pull/8)); proven offline (Baseline CI: contract, leak, placement and the e2e tier), deploy gated until a workspace is linked | ## Read order @@ -35,4 +35,4 @@ The upstream code stays the code: `app/(chat)/api/chat/route.ts` with `streamTex | AC3 — Supabase, Hyperdrive and R2 from Terraform | the three roots and the app's wiring from them | the roots validate; the wiring keys match the template's tokens | | AC4 — ready to instantiate | README, as-built status | a reader can run, test, preview and deploy it | | AC5 — a baseline | the card, the build document, `.baseline/`, the rebrand engine, the bootstrap helpers, `testing/`; Workers AI by default, the database's session key, RLS, the committed wrangler config, `/api/health`, the R2 root on its own `r2-data` key | Baseline CI green: contract, leak, placement (infra before app) and the e2e tier | -| AC6 — the cirrus standard | no kiox, generated component docs, the context pack, status that agrees with the tags and the code | Baseline CI green with the docs check | +| AC6 — the cirrus standard | no kiox, generated component docs, the context pack, status that agrees with the tags and the code; the subdomain read from the Cloudflare connection | Baseline CI green with the docs check; the card asks for no subdomain | diff --git a/specs/epics/ai-chatbot/epic.yaml b/specs/epics/ai-chatbot/epic.yaml index c9e2c2c..26d8353 100644 --- a/specs/epics/ai-chatbot/epic.yaml +++ b/specs/epics/ai-chatbot/epic.yaml @@ -51,4 +51,5 @@ spec: - "every component carries generated docs/{overview,architecture,runbook}.md, and Baseline CI fails a pull request whose manifests and pages disagree" - "ai/context carries this repository's current.md, decisions.md and open-risks.md, and none of them ships to a product" - "every milestone's status row agrees with the tags" - tasks: [AC-7] + - "the console card reads subdomain from the Cloudflare connection (from: connection.cloudflare.workersSubdomain), as cirrus-baseline since baseline-v23" + tasks: [AC-7, AC-8] diff --git a/specs/epics/ai-chatbot/implementation-plan.md b/specs/epics/ai-chatbot/implementation-plan.md index 792a0fa..52bb5d7 100644 --- a/specs/epics/ai-chatbot/implementation-plan.md +++ b/specs/epics/ai-chatbot/implementation-plan.md @@ -114,6 +114,11 @@ chatbot itself changing. - **Status that agrees with the tags and the code.** AC5 is shipped and tagged; `design.md` marks what AC5 superseded (Workers AI by default, the optional `AUTH_SECRET`, the committed `wrangler.jsonc`). +- **The subdomain from the Cloudflare connection (AC-8).** The card declares + `subdomain` as `from: connection.cloudflare.workersSubdomain`, as + cirrus-baseline does since baseline-v23, so the console asks for nothing the + connection already knows; `testing/manifest.test.sh` requires the source's + provider in `spec.requires.integrations`. **Done when** - nothing outside this milestone's own record names kiox (`git grep -i diff --git a/tasks/AC-8.TaskContract.yaml b/tasks/AC-8.TaskContract.yaml new file mode 100644 index 0000000..ead0a5c --- /dev/null +++ b/tasks/AC-8.TaskContract.yaml @@ -0,0 +1,25 @@ +apiVersion: orun.io/v1 +kind: TaskContract +metadata: + name: AC-8 + title: "The subdomain from the Cloudflare connection" +spec: + goal: "The console card reads the workers.dev subdomain from the workspace's Cloudflare connection (`from: connection.cloudflare.workersSubdomain`) instead of asking for it, as cirrus-baseline does since baseline-v23, and the manifest gate holds that source to a connection the card requires" + affects: + - blueprint.yaml + - repo-blueprint.yaml + - testing/manifest.test.sh + - BOOTSTRAP.md + - docs/phases/README.md + - ai/context/current.md + - ai/context/decisions.md + - specs/epics/README.md + - specs/epics/ai-chatbot/** + - tasks/AC-8.TaskContract.yaml + doneWhen: + - "blueprint.yaml declares `from: connection.cloudflare.workersSubdomain` on `subdomain`, so the console renders no field for it" + - testing/manifest.test.sh accepts that source only when spec.requires.integrations lists its provider, and fails naming the input when it does not (mutation-checked) + - BOOTSTRAP.md, docs/phases and repo-blueprint.yaml say only a hand-run build passes `--set subdomain` + - the contract tests, the docs check, the leak gate and the offline bootstrap are green + gates: + - checks diff --git a/testing/manifest.test.sh b/testing/manifest.test.sh index 3fd6af8..5374cb5 100755 --- a/testing/manifest.test.sh +++ b/testing/manifest.test.sh @@ -217,9 +217,20 @@ for path in manifests: # field for it (saas-bootstrap-console BC-K5). Two ways to get it # wrong, and the platform refuses both — check them here too, so the # mistake is caught in this repo rather than at a live bootstrap. + # + # A `connection..` source is read from the connection + # the build is bound to, so the provider must be one the manifest + # requires — the platform's parser refuses it otherwise. + sources_known = ("repo.name", "repo.owner", "repo.fullName", + "connection.cloudflare.workersSubdomain") src = field.get("from") - if src is not None and src not in ("repo.name", "repo.owner", "repo.fullName"): - B(f"inputs[{key}].from is {src!r} — must be repo.name, repo.owner or repo.fullName") + if src is not None and src not in sources_known: + B(f"inputs[{key}].from is {src!r} — must be one of {', '.join(sources_known)}") + if isinstance(src, str) and src.startswith("connection."): + provider = src.split(".")[1] + if provider not in ((spec.get("requires") or {}).get("integrations") or []): + B(f"inputs[{key}].from is {src!r} but spec.requires.integrations " + f"does not list {provider} — there is no connection to read it from") # ── secrets: BOTH or NEITHER, checked both ways ─────────────────────── declared = {s.get("key"): (s.get("provider"), s.get("template")) for s in (spec.get("secrets") or [])} From 60248c1a3b9af9914e4f00114b91f7335fcde4de Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 22 Oct 2026 03:45:51 +0000 Subject: [PATCH 6/6] =?UTF-8?q?AC7:=20the=20console=20asks=20for=20no=20do?= =?UTF-8?q?main=20=E2=80=94=20the=20domain=20is=20set=20later?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The app goes live on workers.dev from its first deploy and nothing in the build needs a domain, so the console no longer asks for one. The logic that uses a domain stays where it is, waiting for one. - blueprint.yaml: no productdomain input - repo-blueprint.yaml: productdomain is optional, default empty - rebrand.mjs: productdomain no longer required; empty brands the reserved placeholder .example.com (RFC 2606) where the domain goes (BASE_DOMAIN in intent.yaml, every environment), so setting it later is replacing one string - the product README ("Custom domain", beside SITE_URL) and ai/context/operations.md say how to set it - testing/fixtures/acme.json carries no domain; rebrand.test.sh pins the placeholder; baseline.yml's blueprint read sets no domain - records: AC7 / AC-9, tagged baseline-v3 Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01D8AmgTwmnp4M8mgmnS9aha --- .baseline/product/README.md | 5 ++ .github/workflows/baseline.yml | 1 - BOOTSTRAP.md | 14 ++++-- README.md | 2 +- ai/context/current.md | 7 +-- ai/context/decisions.md | 1 + ai/context/operations.md | 2 +- blueprint.yaml | 11 +++-- docs/phases/README.md | 12 +++-- repo-blueprint.yaml | 13 +++-- specs/epics/README.md | 2 +- .../epics/ai-chatbot/IMPLEMENTATION-STATUS.md | 47 +++++++++++++++++++ specs/epics/ai-chatbot/README.md | 7 +-- specs/epics/ai-chatbot/epic.yaml | 6 +++ specs/epics/ai-chatbot/implementation-plan.md | 9 ++++ tasks/AC-9.TaskContract.yaml | 30 ++++++++++++ testing/fixtures/acme.json | 10 ++-- testing/rebrand.test.sh | 8 ++++ tooling/rebrand/rebrand.mjs | 10 ++-- 19 files changed, 162 insertions(+), 35 deletions(-) create mode 100644 tasks/AC-9.TaskContract.yaml diff --git a/.baseline/product/README.md b/.baseline/product/README.md index c2c1336..1e9de4f 100644 --- a/.baseline/product/README.md +++ b/.baseline/product/README.md @@ -157,6 +157,11 @@ own domain, attach the domain to the Worker in Cloudflare (Workers & Pages → under that environment's `env:` in `intent.yaml` — the Open Graph images are absolute links, built from it — and merge: the next deploy uses it. +The repository names the domain in one more place, `BASE_DOMAIN` in +`intent.yaml` (one line per environment), which the product was born with as +the reserved placeholder `ai-chatbot.example.com`. Replace it with your +domain in the same change. + ## CI | Workflow | What it runs | diff --git a/.github/workflows/baseline.yml b/.github/workflows/baseline.yml index abda763..d3eeab7 100644 --- a/.github/workflows/baseline.yml +++ b/.github/workflows/baseline.yml @@ -97,7 +97,6 @@ jobs: --out "$(mktemp -d)" \ --set reponame=acme-chat \ --set "productname=Acme Chat" \ - --set productdomain=acme.dev \ --set githuborg=acme-inc - name: the leak gate — what a product carries run: bash testing/leak.test.sh diff --git a/BOOTSTRAP.md b/BOOTSTRAP.md index 0c4f30c..30636e1 100644 --- a/BOOTSTRAP.md +++ b/BOOTSTRAP.md @@ -69,7 +69,7 @@ cd ai-chatbot orun new --blueprint repo-blueprint.yaml \ --out ~/products/acme-chat --run-hooks --resume \ --set reponame=acme-chat --set productname="Acme Chat" \ - --set productdomain=acme.dev --set githuborg=acme-inc \ + --set githuborg=acme-inc \ --set orunWorkspace=ws_XXXXXXXX \ --set subdomain= ``` @@ -106,9 +106,13 @@ orun new --blueprint repo-blueprint.yaml --out ~/products/acme-chat --run-hooks `02-docs` reads the identity back from `.rebrand/values.json` in the placed tree, but the blueprint's **required** inputs — `reponame`, `productname`, -`productdomain`, `githuborg` — are validated before anything runs, so pass -them every time (a `--values` file is easier). The full guide, one page per -phase: [docs/phases/README.md](docs/phases/README.md). +`githuborg` — are validated before anything runs, so pass them every time (a +`--values` file is easier). The domain is not one of them: the product goes live +on workers.dev, and `productdomain` defaults to empty, which brands the +reserved placeholder `.example.com` into `BASE_DOMAIN` for an owner +to replace when they attach a domain (README, "Custom domain"). Pass +`--set productdomain=` only for a product that already has its domain. +The full guide, one page per phase: [docs/phases/README.md](docs/phases/README.md). | flag | what it does | |---|---| @@ -247,5 +251,5 @@ at the tag and refuses the whole catalogue if it 404s. | The convergence reported green, then `verify` got 404 | a second workflow ran on the push to main and the watch took its run. Only `ci.yml` may run on a push to main; `checks.yml` runs on pull requests only | | The product's `intent.yaml` says `workspace: ws_SET_ME` | `orunWorkspace` was empty and the build ran outside a workspace; set it and re-run `01-product` | | A bootstrap stopped before `02-docs`; prod no longer waits on stage | the gate is deferred, not dropped: run `02-docs`, or `node tooling/bootstrap/promotion.mjs --restore --file /intent.yaml` | -| `✕ input "productdomain" is required` | all four required inputs must be set on every invocation, single-phase ones included | +| `✕ input "productname" is required` | all three required inputs (`reponame`, `productname`, `githuborg`) must be set on every invocation, single-phase ones included | | `unknown flag: --phase` or a parse error in the blueprint | the CLI is below the v2.58.11 floor | diff --git a/README.md b/README.md index 3582419..8edeaf9 100644 --- a/README.md +++ b/README.md @@ -37,7 +37,7 @@ the milestones and the as-built status, including every departure. git clone --depth 1 --branch https://github.com/sourceplane/ai-chatbot cd ai-chatbot orun new --blueprint repo-blueprint.yaml --out ~/products/acme-chat --run-hooks --resume \ - --set reponame=acme-chat --set productname="Acme Chat" --set productdomain=acme.dev \ + --set reponame=acme-chat --set productname="Acme Chat" \ --set githuborg=acme-inc --set subdomain= ``` diff --git a/ai/context/current.md b/ai/context/current.md index 6f0080c..4477d91 100644 --- a/ai/context/current.md +++ b/ai/context/current.md @@ -20,8 +20,9 @@ went live (`02-docs`). | | | |---|---| -| Latest tag | `baseline-v2` (AC6 — the cirrus standard, [#7](https://github.com/sourceplane/ai-chatbot/pull/7) and [#8](https://github.com/sourceplane/ai-chatbot/pull/8): no kiox, generated component docs, this context pack, and the workers.dev subdomain read from the Cloudflare connection instead of asked) | -| Before it | `baseline-v1` (AC5, [#6](https://github.com/sourceplane/ai-chatbot/pull/6)) | +| Latest tag | `baseline-v3` (AC7 — the domain is set later, [#9](https://github.com/sourceplane/ai-chatbot/pull/9): the console asks for no domain, and a product is born with the placeholder `.example.com` for an owner to replace) | +| Before it | `baseline-v2` (AC6 — the cirrus standard, [#7](https://github.com/sourceplane/ai-chatbot/pull/7) and [#8](https://github.com/sourceplane/ai-chatbot/pull/8): no kiox, generated component docs, this context pack, and the workers.dev subdomain read from the Cloudflare connection instead of asked) | +| Before that | `baseline-v1` (AC5, [#6](https://github.com/sourceplane/ai-chatbot/pull/6)) | | Proven live | No. Everything short of the platform is proven offline in Baseline CI: the e2e tier builds the product in orun's staged job tree, migrates a local Postgres with its own runner and serves the Worker over local R2 with a stand-in AI binding. No bootstrap from a tag has run against a workspace yet: the three applies, db-migrate against a real project, a real deploy, Workers AI itself (AC-K) and the `BLOB` binding under the deploy token (AC-L) are unproven | ## Where to read @@ -36,7 +37,7 @@ went live (`02-docs`). ## Next -1. Bootstrap one chatbot from `baseline-v2` against a workspace with +1. Bootstrap one chatbot from `baseline-v3` against a workspace with Cloudflare and Supabase connected, and record its timings: the first proof of the applies, the deploy, Workers AI's models and tools (AC-K) and the R2 binding under the deploy token (AC-L). diff --git a/ai/context/decisions.md b/ai/context/decisions.md index e84871a..30c0458 100644 --- a/ai/context/decisions.md +++ b/ai/context/decisions.md @@ -19,3 +19,4 @@ reads in order. | 11 | orun is pinned only where it runs (the `orun-action` `version:` in each workflow); no kiox | `kiox.yaml` pinned a version (v2.15.0) nothing ran | IMPLEMENTATION-STATUS (AC6) | | 12 | Component docs are generated from the manifests and checked in CI | A hand-written copy of the dependency graph and bindings drifts silently | `tooling/catalog/gen-component-docs.py` | | 13 | `subdomain` is read from the Cloudflare connection (`from: connection.cloudflare.workersSubdomain`), never asked | It belongs to the account like its id and has one right answer; a typed one could only be wrong, and showed up after deploy in the public origin, the smoke and the probes | `blueprint.yaml`, IMPLEMENTATION-STATUS (AC-8) | +| 14 | The console asks for no domain; an empty `productdomain` brands the placeholder `.example.com` | The product goes live on workers.dev and nothing in the build needs a domain; attaching one is an owner's step, and the placeholder keeps every place the domain goes in the repository, ready to replace | `repo-blueprint.yaml`, `tooling/rebrand/rebrand.mjs`, IMPLEMENTATION-STATUS (AC-9) | diff --git a/ai/context/operations.md b/ai/context/operations.md index 268c1c3..cd7bc2f 100644 --- a/ai/context/operations.md +++ b/ai/context/operations.md @@ -172,7 +172,7 @@ orun integrations list --org --json && orun cloud check --org | turn the AI Gateway on | `wrangler secret put AI_GATEWAY_API_KEY --name ai-chatbot-web-` | | redeploy without a change | edit the last line of the component's `component.yaml` (`# orun: redeploy `) and merge — it is a deploy trigger, nothing reads it | | rotate the session key | `wrangler secret put AUTH_SECRET --name ai-chatbot-web-` (32+ random bytes); every session ends | -| serve a custom domain | attach it to the Worker in Cloudflare (Workers & Pages → the Worker → Settings → Domains & Routes), then set `SITE_URL` under the environment's `env:` in `intent.yaml` (the Open Graph images' origin) and merge | +| serve a custom domain | attach it to the Worker in Cloudflare (Workers & Pages → the Worker → Settings → Domains & Routes), then set `SITE_URL` under the environment's `env:` in `intent.yaml` (the Open Graph images' origin), replace the placeholder `ai-chatbot.example.com` in its `BASE_DOMAIN` with the domain, and merge | | headless credentials | `ORUN_TOKEN` (workspace-scoped) + `GITHUB_TOKEN` | The deployment record is the bootstrap's `02-docs` phase. Re-running it (the diff --git a/blueprint.yaml b/blueprint.yaml index 5f4ac5e..400ca61 100644 --- a/blueprint.yaml +++ b/blueprint.yaml @@ -72,6 +72,12 @@ spec: # already holds says so with `from`. repo-blueprint.yaml declares the same # names; `repoPrivate`, `orunWorkspace` and `epicSlug` are build inputs with # defaults (or filled from the build's workspace) and are not asked. + # + # NOR IS THE DOMAIN. The product goes live on workers.dev, and a domain is an + # owner's step after the bootstrap: `productdomain` defaults to empty, the + # rebrand writes the reserved placeholder `.example.com` where + # the domain goes, and the product's README ("Custom domain") says how to set + # it. Nothing that needs a domain is removed — it waits for one. inputs: - key: reponame label: Repo name @@ -83,11 +89,6 @@ spec: pattern: "^[A-Za-z0-9][A-Za-z0-9 .,'&-]{1,48}$" help: The name people see — in every page title and the sidebar. example: Acme Chat - - key: productdomain - label: Product domain - pattern: "^[a-z0-9]([a-z0-9-]*[a-z0-9])?(\\.[a-z0-9]([a-z0-9-]*[a-z0-9])?)+$" - help: The domain the product will answer on. It does not need to exist — the app goes live on workers.dev first. - example: acme.dev - key: githuborg label: GitHub organisation pattern: "^[A-Za-z0-9][A-Za-z0-9-]*$" diff --git a/docs/phases/README.md b/docs/phases/README.md index 3d1a7b4..d6b65ad 100644 --- a/docs/phases/README.md +++ b/docs/phases/README.md @@ -56,9 +56,15 @@ carry, so it is an owner's step after the bootstrap (the product's README, `01-product` takes the product's identity once and writes it into the repo (`.rebrand/values.json`); `02-docs` reads it back from the placed tree. But the blueprint's **required** inputs — `reponame`, `productname`, -`productdomain`, `githuborg` — are validated before any phase runs, so they -must be supplied on every invocation, single-phase ones included. A -`--values` file is easier than repeating `--set`. +`githuborg` — are validated before any phase runs, so they must be supplied +on every invocation, single-phase ones included. A `--values` file is easier +than repeating `--set`. + +- `productdomain` — NOT ASKED, default empty. The product goes live on + workers.dev; empty brands the reserved placeholder `.example.com` + into `BASE_DOMAIN`, for an owner to replace when they attach a domain (the + product's README, "Custom domain"). Pass it only for a product that already + has its domain. - `subdomain` — the workers.dev subdomain of the Cloudflare account you deploy into. It is in every URL the phases probe. A console or diff --git a/repo-blueprint.yaml b/repo-blueprint.yaml index e52f8c7..29f186d 100644 --- a/repo-blueprint.yaml +++ b/repo-blueprint.yaml @@ -38,11 +38,16 @@ inputs: description: The product's display name (e.g. "Acme Chat") — in every page title and the sidebar. productdomain: type: string - required: true + default: "" description: >- - The domain the product will answer on (e.g. acme.dev) — BASE_DOMAIN and - the custom-domain guidance. It does not need to exist: the app answers - on workers.dev from its first deploy. + The product's own domain, once it has one (e.g. acme.dev). NOT ASKED: + the app answers on workers.dev from its first deploy, and a domain is an + owner's step after it. Empty, the rebrand writes the reserved + placeholder `.example.com` where the domain goes (BASE_DOMAIN + in intent.yaml, for every environment), so setting it later is + replacing that one string — the product's README, "Custom domain", says + how. Pass it with --set only to brand a hand-run build with a domain it + already has. githuborg: type: string pattern: "^[A-Za-z0-9][A-Za-z0-9-]*$" diff --git a/specs/epics/README.md b/specs/epics/README.md index 855c47a..d2a042b 100644 --- a/specs/epics/README.md +++ b/specs/epics/README.md @@ -7,6 +7,6 @@ folder is the adoption; the merge creates the epic in the workspace. | Epic | Cluster | Status | What it is | |------|---------|--------|------------| -| [`ai-chatbot/`](./ai-chatbot/) | **AC** | ✅ Shipped (`baseline-v2`); live bootstrap pending | Vercel's Next.js AI Chatbot, equivalent in code and function, on Cloudflare Workers with Supabase Postgres, Hyperdrive and R2 — and an Orun baseline that instantiates it in one landing, chatting on Workers AI (AC5) | +| [`ai-chatbot/`](./ai-chatbot/) | **AC** | ✅ Shipped (`baseline-v3`); live bootstrap pending | Vercel's Next.js AI Chatbot, equivalent in code and function, on Cloudflare Workers with Supabase Postgres, Hyperdrive and R2 — and an Orun baseline that instantiates it in one landing, chatting on Workers AI (AC5) | As-built ≠ intent: what shipped lives in each epic's `IMPLEMENTATION-STATUS.md`. diff --git a/specs/epics/ai-chatbot/IMPLEMENTATION-STATUS.md b/specs/epics/ai-chatbot/IMPLEMENTATION-STATUS.md index 05c47ac..661cfac 100644 --- a/specs/epics/ai-chatbot/IMPLEMENTATION-STATUS.md +++ b/specs/epics/ai-chatbot/IMPLEMENTATION-STATUS.md @@ -17,6 +17,7 @@ the code departed from `design.md` or from the upstream template. | AC4 — ready to instantiate | ✅ Shipped | [#5](https://github.com/sourceplane/ai-chatbot/pull/5) | | AC5 — a baseline | ✅ Shipped | [#6](https://github.com/sourceplane/ai-chatbot/pull/6) (AC-6), tagged `baseline-v1` | | AC6 — the cirrus standard | ✅ Shipped | [#7](https://github.com/sourceplane/ai-chatbot/pull/7) (AC-7), [#8](https://github.com/sourceplane/ai-chatbot/pull/8) (AC-8), tagged `baseline-v2` | +| AC7 — the domain is set later | ✅ Shipped | [#9](https://github.com/sourceplane/ai-chatbot/pull/9) (AC-9), tagged `baseline-v3` | ## Departures from the upstream template (AC1–AC4) @@ -188,6 +189,52 @@ Verified: web and cloudflare-r2 → web; `--resume` changes nothing. - `orun task check AC-8` complete. +## The domain is set later (AC7, AC-9) + +The console asked for the product's domain, with help text that said it did +not need to exist — and nothing in the build needed one: the app answers on +workers.dev from its first deploy, its public origin (`SITE_URL`, the Open +Graph images' base) falls back to the environment's workers.dev URL until an +owner sets it, the smoke and the phase probes read workers.dev, and the one +place the repository names the domain is `BASE_DOMAIN` in `intent.yaml` (one +line per environment: dev, stage, prod). A domain is an owner's step after +the bootstrap (README, "Custom domain"), so the form no longer asks for it. + +- `blueprint.yaml` declares no `productdomain` input; the console asks for + the product's name alone. +- `repo-blueprint.yaml`'s `productdomain` is optional, default empty. Nothing + else in the build reads it — no hook, probe or `when:` — so an empty value + is harmless; `.rebrand/values.json` records `""`. A hand-run build may still + pass `--set productdomain=` for a product that already has its domain. +- `rebrand.mjs` no longer requires it. Empty, it brands the reserved + placeholder `.example.com` (RFC 2606 — never someone else's + domain) where the domain goes, so setting it later is replacing one + string; the product README ("Custom domain", beside `SITE_URL`) and + `ai/context/operations.md` say so. +- `testing/fixtures/acme.json` carries no domain, so the leak gate, the + offline bootstrap and the e2e tier exercise exactly what a console build + supplies; `testing/rebrand.test.sh` pins the placeholder for an absent and + an empty domain; `baseline.yml`'s blueprint read sets no domain. + +Nothing that needs a domain was removed — it waits for one. + +Verified: + +- `testing/{manifest,phases,coverage,rebrand,retouch,bootstrap-defer,wire}.test.sh` + green; `gen-component-docs.py --check` green (8 components). +- At v2.58.11 (the blueprint job's pin): `orun new --status` with no + `productdomain` reads the document (`01-product` pending, 294 files); + `testing/leak.test.sh` 294 files derived, 287 text files read. +- At v2.78.4 (the placement pin): `testing/placement.test.sh` 294 files + placed, both landings; the product's own plan orders supabase → + cloudflare-hyperdrive → db-migrate → web and cloudflare-r2 → web; + `--resume` changes nothing. +- The offline bootstrap of the fixture leaves `.rebrand/values.json` + `productdomain` empty and `BASE_DOMAIN: acme-chatbot-hq.example.com` in all + three environments of the product's `intent.yaml` (and the same string in + its README and `operations.md`); no line names `ai-chatbot.example.com`. +- `orun task check AC-9` complete. + ## Verified (AC6) - `testing/{manifest,phases,coverage,rebrand,retouch,bootstrap-defer,wire}.test.sh` diff --git a/specs/epics/ai-chatbot/README.md b/specs/epics/ai-chatbot/README.md index 9ea2baa..d81455e 100644 --- a/specs/epics/ai-chatbot/README.md +++ b/specs/epics/ai-chatbot/README.md @@ -8,15 +8,15 @@ The upstream code stays the code: `app/(chat)/api/chat/route.ts` with `streamTex | Field | Value | |-------|-------| -| Status | ✅ AC0–AC5 shipped (#1–#6), tagged `baseline-v1`: AC5 made the repository an Orun baseline (one landing), Workers AI the default model provider, the session key the database's own and row-level security universal. AC6 (the cirrus standard, AC-7 #7 and AC-8 #8) tagged `baseline-v2`. The Supabase, Hyperdrive and R2 applies, db-migrate and a live deploy are not yet proven by a live bootstrap (risks AC-K, AC-L) | -| Cluster | **AC** (AC0–AC6) | +| Status | ✅ AC0–AC7 shipped (#1–#9): AC0–AC5 tagged `baseline-v1` (AC5 made the repository an Orun baseline in one landing, Workers AI the default model provider, the session key the database's own and row-level security universal); AC6 (the cirrus standard, AC-7 #7 and AC-8 #8) tagged `baseline-v2`; AC7 (the domain is set later, AC-9 #9) tagged `baseline-v3`. The Supabase, Hyperdrive and R2 applies, db-migrate and a live deploy are not yet proven by a live bootstrap (risks AC-K, AC-L) | +| Cluster | **AC** (AC0–AC7) | | Owner(s) | `apps/web` (the app) · `tests/web` (vitest) · `packages/db` + `tests/db` (the schema) · `infra/terraform/{supabase,cloudflare-hyperdrive,cloudflare-r2}` + `infra/db-migrate` | | Builds on | `lumen` conventions — the `supabase`, `cloudflare-hyperdrive` and `db-migrate` components, `@saas/db`, the orun-secrets wiring, the per-request `postgres` client; `cirrus-baseline` for the R2 root and the repository shape | | Upstream | [vercel/ai-chatbot](https://github.com/vercel/ai-chatbot) v3.1 (AI SDK 7, Next 16, next-auth v5 beta, Drizzle) | | Changes | Adds the Workers build, the monorepo wrapper, tests, the migrations package, the infra roots and the deploy contract; in the template's code: the per-call Postgres client, the R2 attachment routes, and shims for the Vercel-only modules (`lib/bot.ts`, `lib/geo.ts`, an empty `instrumentation.ts`) | | Decisions locked | (1) OpenNext on Workers + Static Assets, `next` pinned to 16.3.8. (2) Postgres through Hyperdrive, one `postgres` client per `getDb()` call, never at module scope. (3) Attachments in R2 behind `/api/files/`, public by unguessable URL exactly as Vercel Blob's `access: "public"` was. (4) The schema ships in `packages/db` and is applied by db-migrate; drizzle-kit stays for local development. (5) Static-assets incremental cache: the app has no `use cache` and nothing revalidates. (6) No Redis: resumable streams and the IP rate limit stay off, as upstream does without `REDIS_URL`. (7) `AUTH_SECRET` and `AI_GATEWAY_API_KEY` are Worker secrets set once per environment — **superseded by AC5**: both are optional; Workers AI through the `AI` binding is the default model provider, and the session key defaults to one the database generates. | | Gate | AC1 is the first user-visible rung and is verified without a database (the Worker boots, the routes answer). AC2 and AC3 need a workspace with Supabase and Cloudflare connections to apply; they are verified by `plan`, `terraform validate` and the offline migration tests. | -| Shipped as | `baseline-v1` ([#6](https://github.com/sourceplane/ai-chatbot/pull/6)), then `baseline-v2` (AC6: [#7](https://github.com/sourceplane/ai-chatbot/pull/7), [#8](https://github.com/sourceplane/ai-chatbot/pull/8)); proven offline (Baseline CI: contract, leak, placement and the e2e tier), deploy gated until a workspace is linked | +| Shipped as | `baseline-v3` ([#9](https://github.com/sourceplane/ai-chatbot/pull/9), AC7: no domain asked), `baseline-v2` (AC6: [#7](https://github.com/sourceplane/ai-chatbot/pull/7), [#8](https://github.com/sourceplane/ai-chatbot/pull/8)), `baseline-v1` ([#6](https://github.com/sourceplane/ai-chatbot/pull/6)); proven offline (Baseline CI: contract, leak, placement and the e2e tier), deploy gated until a workspace is linked | ## Read order @@ -36,3 +36,4 @@ The upstream code stays the code: `app/(chat)/api/chat/route.ts` with `streamTex | AC4 — ready to instantiate | README, as-built status | a reader can run, test, preview and deploy it | | AC5 — a baseline | the card, the build document, `.baseline/`, the rebrand engine, the bootstrap helpers, `testing/`; Workers AI by default, the database's session key, RLS, the committed wrangler config, `/api/health`, the R2 root on its own `r2-data` key | Baseline CI green: contract, leak, placement (infra before app) and the e2e tier | | AC6 — the cirrus standard | no kiox, generated component docs, the context pack, status that agrees with the tags and the code; the subdomain read from the Cloudflare connection | Baseline CI green with the docs check; the card asks for no subdomain | +| AC7 — the domain is set later | the console asks for no domain; an empty `productdomain` brands the placeholder `.example.com` for an owner to replace | Baseline CI green on a fixture with no domain | diff --git a/specs/epics/ai-chatbot/epic.yaml b/specs/epics/ai-chatbot/epic.yaml index 26d8353..83fdbef 100644 --- a/specs/epics/ai-chatbot/epic.yaml +++ b/specs/epics/ai-chatbot/epic.yaml @@ -53,3 +53,9 @@ spec: - "every milestone's status row agrees with the tags" - "the console card reads subdomain from the Cloudflare connection (from: connection.cloudflare.workersSubdomain), as cirrus-baseline since baseline-v23" tasks: [AC-7, AC-8] + - name: "AC7 — the domain is set later" + exitCriteria: + - "the console card asks for no domain: a product goes live on workers.dev, and productdomain is an optional build input that defaults to empty" + - "a product built without a domain is branded with the reserved placeholder .example.com wherever the domain goes (BASE_DOMAIN), and its README says how an owner sets the real one" + - "Baseline CI places, leak-checks and plans a product built with no domain" + tasks: [AC-9] diff --git a/specs/epics/ai-chatbot/implementation-plan.md b/specs/epics/ai-chatbot/implementation-plan.md index 52bb5d7..e79a46c 100644 --- a/specs/epics/ai-chatbot/implementation-plan.md +++ b/specs/epics/ai-chatbot/implementation-plan.md @@ -127,6 +127,15 @@ chatbot itself changing. - the docs check is green in Baseline CI - this file, the status file and `epic.yaml` agree +## AC7 — the domain is set later (AC-9) ✅ + +**Done when** the console card asks for no domain; `productdomain` is an +optional build input, empty by default; a product built without one is branded +with the reserved placeholder `.example.com` where the domain goes +(`BASE_DOMAIN` in `intent.yaml`) and its README says how an owner sets the real one; +Baseline CI places, leak-checks and plans a product built with no domain. +Shipped in `baseline-v3`. + ## Sequencing note AC1 is verified without a database: the Worker boots and every route diff --git a/tasks/AC-9.TaskContract.yaml b/tasks/AC-9.TaskContract.yaml new file mode 100644 index 0000000..3a1f440 --- /dev/null +++ b/tasks/AC-9.TaskContract.yaml @@ -0,0 +1,30 @@ +apiVersion: orun.io/v1 +kind: TaskContract +metadata: + name: AC-9 + title: "The domain is set later" +spec: + goal: "The console no longer asks for the product's domain. A product goes live on workers.dev; productdomain is an optional build input (default empty), the rebrand writes the reserved placeholder .example.com where the domain goes (BASE_DOMAIN), and the product's README says how an owner replaces it once a domain is attached" + affects: + - blueprint.yaml + - repo-blueprint.yaml + - tooling/rebrand/rebrand.mjs + - testing/rebrand.test.sh + - testing/fixtures/acme.json + - .github/workflows/baseline.yml + - .baseline/product/README.md + - BOOTSTRAP.md + - README.md + - docs/phases/README.md + - ai/context/operations.md + - ai/context/current.md + - ai/context/decisions.md + - specs/** + - tasks/** + doneWhen: + - blueprint.yaml declares no productdomain input, and repo-blueprint.yaml's productdomain is optional with an empty default + - "rebrand.mjs no longer requires productdomain and brands .example.com when it is empty (testing/rebrand.test.sh)" + - testing/fixtures/acme.json carries no domain, so the leak gate and the offline bootstrap exercise what a console build supplies + - the contract tests, the docs check, the leak gate and the offline bootstrap are green + gates: + - checks diff --git a/testing/fixtures/acme.json b/testing/fixtures/acme.json index 197014a..b658828 100644 --- a/testing/fixtures/acme.json +++ b/testing/fixtures/acme.json @@ -6,16 +6,16 @@ "AWKWARD rather than tidy — a product name with an apostrophe and an", "ampersand (both legal in the card's pattern, both special in TypeScript", "strings, HTML and a PR title), a hyphenated repo slug that CONTAINS the", - "word `chatbot`, an owner other than the baseline's, and a multi-label", - "domain — because a fixture that only uses values the templates were", - "written against proves the templates work on the values they were", - "written against.", + "word `chatbot`, an owner other than the baseline's, and NO domain — a", + "console build asks for none, so the placeholder .example.com", + "is what a product is born with — because a fixture that only uses values", + "the templates were written against proves the templates work on the", + "values they were written against.", "Every key here is an input repo-blueprint.yaml declares. A key it does not", "declare is a fixture that has drifted, and orun refuses it." ], "reponame": "acme-chatbot-hq", "productname": "Sam's Chat & Answers", - "productdomain": "chat.acme.dev", "githuborg": "acme-inc", "subdomain": "acme", "orunWorkspace": "ws_0000000000000000000000000000000f", diff --git a/testing/rebrand.test.sh b/testing/rebrand.test.sh index 99533d3..8ccacfe 100755 --- a/testing/rebrand.test.sh +++ b/testing/rebrand.test.sh @@ -82,6 +82,14 @@ check "the origin the build bakes into absolute metadata URLs: worker name and s check "the placeholder domain is the product's domain, not a renamed slug" \ "$acme" intent.yaml ' BASE_DOMAIN: ai-chatbot.example.com' \ ' BASE_DOMAIN: acme.dev' +check "no domain given: the reserved placeholder, for an owner to replace later" \ + '{"reponame":"acme-chat","productname":"Acme Chat","githuborg":"acme-inc","subdomain":"acme"}' \ + intent.yaml ' BASE_DOMAIN: ai-chatbot.example.com' \ + ' BASE_DOMAIN: acme-chat.example.com' +check "an empty domain is no domain" \ + '{"reponame":"acme-chat","productname":"Acme Chat","productdomain":""}' \ + intent.yaml ' BASE_DOMAIN: ai-chatbot.example.com' \ + ' BASE_DOMAIN: acme-chat.example.com' check "the repo slug" \ "$acme" package.json ' "name": "ai-chatbot",' \ ' "name": "acme-chat",' diff --git a/tooling/rebrand/rebrand.mjs b/tooling/rebrand/rebrand.mjs index 0d51757..b2e4c1e 100644 --- a/tooling/rebrand/rebrand.mjs +++ b/tooling/rebrand/rebrand.mjs @@ -27,7 +27,7 @@ // { // "reponame": "acme-chat", // required — repo slug // "productname": "Acme Chat", // required — the product's display name -// "productdomain": "acme.dev", // required — the product domain +// "productdomain": "acme.dev", // optional — default .example.com (set later) // "githuborg": "acme-inc", // owner of the product repo (source link in docs) // "brandSlug": "acme", // default: reponame — worker name prefix // "subdomain": "acme", // default: your-workers-subdomain @@ -68,7 +68,7 @@ if (!verifyOnly && !valuesPath) { } if (valuesPath) { values = JSON.parse(fs.readFileSync(valuesPath, "utf8")); - for (const required of ["reponame", "productname", "productdomain"]) { + for (const required of ["reponame", "productname"]) { if (typeof values[required] !== "string" || values[required].length === 0) { console.error(`rebrand: values file is missing required field "${required}"`); process.exit(2); @@ -133,7 +133,11 @@ const rx = (s) => s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"); // All fields are unused under --verify; the fallbacks keep derivation total. const reponame = values.reponame ?? ""; const productname = values.productname ?? ""; -const productdomain = values.productdomain ?? ""; +// The domain is NOT ASKED at bootstrap: a product goes live on workers.dev and an +// owner sets a domain later. Until then the reserved placeholder +// `.example.com` (RFC 2606 — it can never be someone else's) stands +// wherever the domain goes, so setting it is replacing one string. +const productdomain = (values.productdomain ?? "").trim() || (reponame ? `${reponame}.example.com` : ""); const githuborg = (values.githuborg ?? "").trim() || baseline.githubOwner; const brandSlug = (values.brandSlug ?? "").trim() || reponame; const subdomain = (values.subdomain ?? "").trim() || "your-workers-subdomain";