Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 68 additions & 0 deletions .baseline/product/AGENTS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# supabase-starter — notes for coding agents

You are in the repository of a live product. Read this before you change
anything; `README.md` is the same product told for the person who runs it.

## What this is

A Next.js app with Supabase Auth — email and password sign-up, sign-in,
password reset, sessions in cookies refreshed by a proxy, a protected page —
built by OpenNext into one Cloudflare Worker, with a Supabase project per
environment (`stage`, `prod`) created by Terraform. Orun deploys it: a merge
to `main` converges what it changed, the Supabase project before the app and
stage before prod. `dev` only verifies.

| component | path | what it is |
|---|---|---|
| `web` | `apps/web` | the app and its Worker build (`component.yaml`, `next.config.ts`, `wrangler.template.jsonc`) |
| `supabase` | `infra/terraform/supabase` | the Supabase project per environment and its Auth settings |
| `web-tests` | `tests/web` | the vitest suite |

`intent.yaml` declares the environments, the workspace and how CI plans; each
`component.yaml` declares one component and what it depends on.

## Read first

1. `README.md` — what is where, running it locally, "Email", "Your first
table", "Custom domain".
2. `ai/context/operations.md` — how a deploy works, the secrets model,
row-level security, the common operations.
3. `ai/context/deployment.md` — the live URLs, the workspace and the secrets,
by name, as last probed.
4. `apps/web/lib/supabase` — the browser and server clients, the session
proxy, and what the auth forms say when Supabase refuses.
5. `infra/terraform/supabase` — `component.yaml` (its parameters and what it
publishes) and `terraform/main.tf`.

## How a change lands

- Work is tracked as tasks on the Orun workspace (`orun task list`). One task,
one branch, one pull request against `main` — `orun pr open` names the
branch after the task and records it in the pull request.
- Before you push: `pnpm install`, `pnpm run wire:fixture`, `pnpm typecheck`,
`pnpm lint`, `pnpm test`, `pnpm build`. `checks.yml` runs the same on the
pull request; `orun validate` and `orun plan` show what `ci.yml` will plan.
- Merging is deploying. Watch the run on `main`, then probe the URLs in
`ai/context/deployment.md`: a run that planned nothing deployed nothing.
- A table in `public` gets row-level security and `auth.uid()` policies in the
statement that creates it — the publishable key is public by design.
- A new component is a directory under `apps/`, `infra/` or `packages/` with a
`component.yaml`, declaring `dependsOn` on any infrastructure whose
published secrets it reads.

## Do not touch

- `execution.state.workspace` in `intent.yaml`: every remote operation and
every CI credential is scoped to it.
- `apps/web/wrangler.jsonc` by hand: edit `wrangler.template.jsonc` and run
`pnpm run wire:fixture`. Never commit a real project's URL or key.
- `ai/context/deployment.md`, and the README between `<!-- 02-docs:begin -->`
and `<!-- 02-docs:end -->`: both are rendered from probes.
- The Auth URLs in the Supabase dashboard: the apply owns the Site URL, the
redirect allow-list and `mailer_autoconfirm`, and undoes a dashboard edit.
- Secret values, anywhere — the repository, `ai/context/`, a log, GitHub.
Provider credentials are brokered per run; secrets are inspected by name.
- `checks.yml` on pull requests only: on `main`, `ci.yml` is the one run a
commit has.
- The last line of a `component.yaml` (`# orun: redeploy …`) is a deploy
trigger; change it only to redeploy that component.
3 changes: 3 additions & 0 deletions .baseline/product/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ deploys and how to operate it is in
| The Supabase project (stage, prod) and its Auth settings | `infra/terraform/supabase` |
| Tests | `tests/web` (vitest) |

A coding agent starts at [AGENTS.md](AGENTS.md): what to read first, how a
change lands, and what not to touch.

## Getting started

```bash
Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ coverage/
plan.json
next-env.d.ts

# Python bytecode
__pycache__/
*.pyc

# Terraform
.terraform/
*.tfstate
Expand Down
6 changes: 5 additions & 1 deletion ai/context/current.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ environment), then records what went live (`02-docs`).
| | |
|---|---|
| Latest tag | `baseline-v4` (SS7 — the domain is set later: the console asks for no domain, and a product is born with the placeholder `<reponame>.example.com` in `BASE_DOMAIN` for an owner to replace); `baseline-v3` is SS6 (the cirrus standard), `baseline-v2` SS5, `baseline-v1` SS4 |
| In review | SS8 (SS-10) — the build reads true in the console's build panel (saas-build-panel BV4): honest, short step lines, no authored await line (the engine says what a phase waits on), labelled landings, a quiet docs re-probe, and an `AGENTS.md` in every product. Untagged |
| Proven live | No. Nothing has been applied against a real Supabase organization: no Terraform apply, no live deploy, no live bootstrap (risk SS-I). Everything short of the platform is proven offline in Baseline CI, against a local Supabase stand-in |

## Where to read
Expand All @@ -33,7 +34,10 @@ environment), then records what went live (`02-docs`).

## Next

1. Bootstrap one product from `baseline-v4` against a workspace with a
1. Cut `baseline-v5` once SS8 merges, so the registry can pin a build whose
lines the panel reads true (the labels and the quiet re-probe take effect
with orun v2.86; earlier releases ignore them).
2. Bootstrap one product from the latest tag against a workspace with a
Supabase connection, and record its timings — the apply, the brokered
token's reach to the API-keys and Auth-config endpoints, a sign-up on the
first deploy (closes SS-I).
2 changes: 2 additions & 0 deletions ai/context/decisions.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,5 @@ reads in order.
| 12 | Component docs are generated from the manifests and checked in CI | A hand-written copy of the dependency graph, bindings and published outputs drifts silently | `tooling/catalog/gen-component-docs.py` |
| 13 | The console card reads `subdomain` from the Cloudflare connection (`from: connection.cloudflare.workersSubdomain`); only a hand-run build passes it | It belongs to the account like its id and has one right answer; a typed one could only be wrong, and wrong showed up after deploy (cirrus-baseline since baseline-v23) | `blueprint.yaml`, IMPLEMENTATION-STATUS (SS-8) |
| 14 | The console asks for no domain; an empty `productdomain` brands the placeholder `<reponame>.example.com` | The app goes live on workers.dev and nothing in the build needs a domain (the origin is `SITE_URL`, else workers.dev); attaching one is an owner's step, and the placeholder keeps the place the domain goes in the repository, ready to replace | `repo-blueprint.yaml`, `tooling/rebrand/rebrand.mjs`, IMPLEMENTATION-STATUS (SS-9) |
| 15 | No phase authors an await line, and every step line holds for each outcome its hook can have | The build panel shows hook lines verbatim as progress and a phase's waiting line as what the build waits on — also while a connection probe waits. Only the engine knows what that is, and with no authored line it says it ("<title>: <reason>"); its reasons are whole clauses, so an authored frame such as "Waiting on {{ .meta.waitingOn }}." read "Waiting on waiting for …". And a line written for one outcome ("merged" when there was nothing to land) lies in the other (saas-build-panel BV4) | `repo-blueprint.yaml`, `testing/phases.test.sh`, IMPLEMENTATION-STATUS (SS-10) |
| 16 | Every product ships `AGENTS.md`, from `.baseline/product/` like its README | The build ends by handing the owner a prompt to clone the repository with a coding agent; the agent needs to know what to read and what not to touch. At this repository's root it would brief this repository's agents about the product | `repo-blueprint.yaml` (`root-agents`), IMPLEMENTATION-STATUS (SS-10) |
2 changes: 1 addition & 1 deletion ai/context/operations.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ orun integrations list --org <ws> --json && orun cloud check --org <ws>
|---|---|
| deploy a change | merge to `main`; watch the run; failed lanes → `gh run rerun --failed` |
| require email confirmation | SMTP first, then `authEmailConfirmation: "true"` (above) |
| add a table | create it with `enable row level security` and `auth.uid()` policies (above); the day the product has migrations, Lumen's `packages/db` + `db-migrate` is the shape, reading `SUPABASE_DB_URL` |
| add a table | create it with `enable row level security` and `auth.uid()` policies (above); the day the product has migrations, they go in a component under `packages/` with a migrate step that reads `SUPABASE_DB_URL` (Evolution, below) |
| redeploy without a change | edit the last line of the component's `component.yaml` (`# orun: redeploy <reason> <stamp>`) and merge — it is a deploy trigger, nothing reads it |
| serve a custom domain | attach it to the Worker in Cloudflare (README, "Custom domain"), set `SITE_URL` under `environments.prod.env` in `intent.yaml`, replace the placeholder `supabase-starter.example.com` in `intent.yaml`'s `BASE_DOMAIN` with it (a record; nothing builds a URL from it), and touch the redeploy line of both `apps/web/component.yaml` and `infra/terraform/supabase/component.yaml` in the same PR (an `intent.yaml` change alone plans nothing) |
| headless credentials | `ORUN_TOKEN` (workspace-scoped) + `GITHUB_TOKEN` |
Expand Down
5 changes: 3 additions & 2 deletions docs/phases/01-product.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ provisions and deploys it on stage and prod: the Supabase project, its Auth
pointed at the app, and then the app — in that order, per environment.

**Places** every module `repo-blueprint.yaml` declares: the root manifests,
CI, tooling and identity; the discovery roots; `infra/terraform/supabase`;
the product's README and `AGENTS.md` (where a coding agent starts), CI,
tooling and identity; the discovery roots; `infra/terraform/supabase`;
`apps/web`; and `tests/web`. `testing/phases.test.sh` holds the set.

**Requires** three live connections, probed and waited for (up to ten
Expand Down Expand Up @@ -43,7 +44,7 @@ main and reads the order off it: `supabase → web`.
| `repo` | `orun.repo/ensure@v1`: creates (or finds) `<githuborg>/<reponame>` |
| `link` | the repository becomes the workspace's (`orun cloud link`, best effort; `orun cloud check` is the gate). Every convergence lane authenticates over GitHub OIDC through that link |
| `secret-*` | four `orun.integrations/reconcile@v1` hooks, one key and one scope each: `CLOUDFLARE_API_TOKEN` (workers-deploy), `CLOUDFLARE_ACCOUNT_ID` (account-id), `SUPABASE_ACCESS_TOKEN` (management-access), `SUPABASE_ORG_ID` (org-id). Keys that exist are kept |
| `land` | one PR, checked (Checks, and `plan` alone on a bootstrap branch), then merged |
| `land` | one PR, checked (Checks, and `plan` alone on a bootstrap branch), then merged; labelled `Product` in the build panel |
| `converge` (await) | `orun.run/watch@v1` on the merge commit's run; resumes it up to three times |
| `wiring` (await) | `orun.secrets/exists@v1`: `WIRING_SUPABASE`, `SUPABASE_PROJECT_REF`, `SUPABASE_DB_PASSWORD` and `SUPABASE_DB_URL` on stage and prod |
| `verify` (await) | `orun.http/probe@v1`: `/` and `/api/health` on both workers.dev URLs |
Expand Down
4 changes: 2 additions & 2 deletions docs/phases/02-docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ no phase may require this one.)
| `promotion` | restores `environments.prod.promotion` — from now on prod deploys only after stage |
| `dev-lanes` | restores dev's activation on pushes to main |
| `render` | `hooks/render-deployment-docs.sh`: probes `/` and `/api/health` on both environments, reads from the health check whether sign-up is open and whether it asks for email confirmation, lists the secrets by name and the workspace's integrations, and regenerates `ai/context/deployment.md` and the README's live-deployment section |
| `land` | one PR, waited for and merged. It touches no component, so it deploys nothing |
| `verify` (await) | the same probe `01-product` ended on |
| `land` | one PR, waited for and merged, labelled `Docs` in the build panel. It touches no component, so it deploys nothing |
| `verify` (await) | the same probe `01-product` ended on, `quiet`: it files no second set of addresses |

## Re-running it

Expand Down
19 changes: 19 additions & 0 deletions docs/phases/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,25 @@ domain needs zone permissions the brokered `workers-deploy` token does not
carry, so it is an owner's step after the bootstrap (the product's README,
"Custom domain").

## What a phase says

The console's build panel shows a hook's `narrate:` verbatim as the build's
progress and a phase's `narrate.await` as what it is waiting on; from orun
v2.86 the engine's facts pin the repository, the epic, each pull request and
the live addresses beside them. So every line says one true thing about the
world, briefly, and no line asserts a state (`testing/phases.test.sh`):

- neither phase authors an `await` line: the engine says what a phase waits
on — "<title>: <reason>" — which is also the line while `01-product`'s
probe waits for a connection, and only the engine knows the reason;
- a line holds for every outcome its hook can have: the repository's says
whether this build created it, a landing names its pull request or says
there was nothing to land, a brokered key's holds whether it was minted now
or kept;
- each landing carries a `label:` (`Product`, `Docs`), and `02-docs`'s
re-probe is `quiet: true`, so the panel gets one set of addresses. orun
releases before v2.86 ignore both keys.

## Inputs

`01-product` takes the product's identity once and writes it into the repo
Expand Down
7 changes: 4 additions & 3 deletions infra/terraform/supabase/component.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,10 @@ spec:
# project sends email (the product's README, "Email").
authEmailConfirmation: "false"
# SEC-JOB: post-apply, these outputs are queued on the runner's sink and
# lease-published onto the project/{{env}} rung by the runner. Lumen's
# three database credentials, and WIRING_SUPABASE — the project URL and
# the publishable (anon) key, the one document the app's deploy reads.
# lease-published onto the project/{{env}} rung by the runner. The
# project's three database credentials, and WIRING_SUPABASE — the project
# URL and the publishable (anon) key, the one document the app's deploy
# reads.
# The service-role key is never published.
secretOutputs: "SUPABASE_PROJECT_REF=project_ref,SUPABASE_DB_PASSWORD=database_password,SUPABASE_DB_URL=connection_uri,WIRING_SUPABASE=wiring"

Expand Down
8 changes: 4 additions & 4 deletions infra/terraform/supabase/terraform/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,10 @@ resource "supabase_project" "this" {
#
# Credentials leave this module ONLY through the outputs component.yaml's
# `secretOutputs` names, which the runner lease-publishes onto the project's
# environment rung after the apply (never argv, never a log). Lumen's three
# database credentials below are published for the owner and for any later
# step that migrates the database; the app reads the `wiring` document further
# down. No Secrets Manager.
# environment rung after the apply (never argv, never a log). The project's
# three database credentials below are published for the owner and for any
# later step that migrates the database; the app reads the `wiring` document
# further down. No Secrets Manager.

output "project_ref" {
description = "Supabase project reference ID"
Expand Down
2 changes: 1 addition & 1 deletion intent.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ kind: Intent

metadata:
name: supabase-starter
description: Vercel's Next.js + Supabase starter (Supabase Auth with cookie sessions, protected routes) ported to Cloudflare Workers + Static Assets with a Terraform-provisioned Supabase project, on the Lumen baseline conventions
description: Vercel's Next.js + Supabase starter (Supabase Auth with cookie sessions, protected routes) on Cloudflare Workers + Static Assets, with a Supabase project per environment provisioned by Terraform and deployed through Orun
namespace: sourceplane

execution:
Expand Down
Loading
Loading