Skip to content

AC5: ai-chatbot becomes an Orun baseline - #6

Merged
ruehowl merged 1 commit into
mainfrom
claude/blissful-ptolemy-c5ajf8
Oct 15, 2026
Merged

ruehowl merged 1 commit into
mainfrom
claude/blissful-ptolemy-c5ajf8

Conversation

@ruehowl

@ruehowl ruehowl commented Oct 15, 2026

Copy link
Copy Markdown
Contributor

AC5 (task AC-6): Vercel's Next.js AI Chatbot on Cloudflare Workers + Supabase becomes an Orun baseline on the Lumen conventions that takes a new chatbot from nothing to live on stage and prod in ONE landing (cirrus-baseline v22's shape), following saas-starter (sourceplane/saas-starter#6) for the supabase → hyperdrive → db-migrate → web chain, the database's own session key and RLS, blob-starter for the R2 root's own r2-data key, and kv-redis-starter for the committed wrangler config. A fresh product chats on Workers AI with no model key and signs guests in and registers users with no AUTH_SECRET.

What was added

The card and the build

  • blueprint.yaml: inputs (reponame, productname, productdomain, githuborg, subdomain); requires.integrations: [github, cloudflare, supabase]; six brokered keys as a preview — CLOUDFLARE_API_TOKEN (workers-deploy), CLOUDFLARE_HYPERDRIVE_TOKEN (hyperdrive-edit), CLOUDFLARE_R2_TOKEN (r2-data), CLOUDFLARE_ACCOUNT_ID (account-id), SUPABASE_ACCESS_TOKEN (management-access), SUPABASE_ORG_ID (org-id); programme 01-product, 02-docs; expectedMinutes: 20. The description and BOOTSTRAP state the owner's prerequisite: two Supabase projects (stage, prod — the free plan's limit). No AI vendor key is asked for.
  • repo-blueprint.yaml:
    • 01-product places every module (26). Post hooks: retouch, git-init, stage, rebrand, orun-workspace, work-tree --strip, promotion --defer, dev-lanes --defer, restage, rebrand-verify, pnpm lockfile, orun.repo/ensure@v1, link, one orun.integrations/reconcile@v1 per key (6), orun.pr/land@v1.
    • Await: orun.run/watch@v1 on the merge sha; orun.secrets/exists@v1 for SUPABASE_PROJECT_REF, SUPABASE_DB_PASSWORD, SUPABASE_DB_URL, WIRING_CLOUDFLARE_HYPERDRIVE, WIRING_CLOUDFLARE_R2 on stage and prod; orun.http/probe@v1 on /ping and /api/health for both. Not /: every chatbot page redirects a visitor with no session to the guest sign-in (307), and the probe wants a 200 (checked against orun's probe locally).
    • 02-docs is hook-only: restore promotion and dev-lanes, render the deployment record (which model provider serves, from /api/health), land, probe.

Infra before app (enforced on github-push-main, advisory on PRs)

  • supabase → cloudflare-hyperdrive → db-migrate → web, and cloudflare-r2 → web, per environment.
  • The cloudflare-r2 root now applies with its own CLOUDFLARE_R2_TOKEN (r2-data), not the deploy token. The Supabase root publishes Lumen's three outputs only; Lumen's provider lock files on all three roots. stack-tectonic 0.19.0.

Workers AI is the default model provider

  • An AI binding in the committed wrangler config; workers-ai-provider 4.0.0 (AI SDK 7 / @ai-sdk/provider 4). Chat and tools: @cf/moonshotai/kimi-k2.6 (default); titles: @cf/zai-org/glm-4.7-flash, thinking off.
  • Upstream's gateway models stay, offered only with AI_GATEWAY_API_KEY. /api/models returns what can answer; the picker shows exactly that; a request for an unavailable model gets the default. Workers AI errors show in the chat; the suggestions tool (structured output) returns its error to the model rather than failing the response.
  • next dev alone opens wrangler's platform proxy (the AI binding has no local mode and would make every build ask for a Cloudflare credential), and the static-assets cache is populated by a copy (scripts/populate-static-assets-cache.mjs) instead of populateCache local, for the same reason.

The session key, RLS and the rest of the app

  • lib/auth-secret.ts: AUTH_SECRET, else the key migration 020_app_secrets generated into app_private.secrets (not exposed by the Data API). Auth.js is initialised lazily so its config can await it; the proxy and the guest route read the same key over the same Hyperdrive binding, once per isolate (/ping and /api/health answer before that read).
  • lib/auth-cookie.ts: the session cookie's __Secure- name is chosen as Auth.js chooses it. Upstream's !isDevelopmentEnvironment made the built Worker served over http (wrangler dev) loop on the guest sign-in.
  • 030_row_level_security (guarded) on all seven tables; .enableRLS() in schema.ts; drizzle twins.
  • apps/web/wrangler.jsonc committed (GENERATED banner); the build renders every lane (--fixture wiring.fixture.json --fixture-envs dev); Checks runs git diff --exit-code after wire:fixture.
  • /api/health; lib/site.ts name seam; metadataBase is the product's origin (NEXT_PUBLIC_SITE_URL from SITE_URL or the workers.dev URL, rebranded) instead of chat.vercel.ai; the header's "Deploy with Vercel" CTA is gone; the sign-in page says "Powered by Workers AI". Redis stays optional (no resumable streams / IP limit without it).

Factory

  • .baseline/, tooling/rebrand (protects github.com/vercel/ai-chatbot and every migration), tooling/bootstrap, tooling/wire (kv-redis-starter's), hooks/render-deployment-docs.sh, ai/context, docs/phases, BOOTSTRAP.md, baseline.yml, tag.yml; ci.yml's linked gate at v2.78.4; checks.yml on pull requests only.
  • testing/: manifest, phases, coverage, rebrand, retouch, bootstrap-defer, wire, leak, placement, e2e; testing/lib/fake-ai/ (the e2e's Workers AI stand-in).
  • Specs: the AC5 milestone, AC-6, risks AC-K…O, and an as-built status that is ai-chatbot's again (AC4 had merged rag-chatbot's by mistake).

How it was verified

Everything ran locally on the committed head (76d9dd2) with no model key and no AUTH_SECRET anywhere; the tree was clean before and after.

  • The repository's own checks: pnpm install --frozen-lockfile, wire:fixture then git diff --exit-code (clean), typecheck, lint (biome: 0 errors; eslint clean), test — tests/web 47 passed in 10 files (new: models, proxy, auth-secret, health, wrangler-config), tests/db 10 passed in 2 files (new: row-level-security in PGlite, the drizzle-twin check) — and build on Turbopack with no Cloudflare credential.
  • Contract tests: manifest, phases, coverage, rebrand (an acme fixture Sam's Chat & Answers; the vercel/ai-chatbot link and migrations protected), retouch, bootstrap-defer, wire — all pass.
  • leak.test.sh at orun v2.58.11 and 2.79.0: 272 files derived, 265 read; no factory path ships or is named; no provenance prose.
  • placement.test.sh at v2.78.4 (the CI pin for this job), 2.79.0 and 2.58.11: the offline bootstrap of both phases; the product branded, re-tenanted, gates restored, record rendered, wrangler.jsonc the fixture render binding AI; the product's own orun plan --trigger github-push-main orders supabase → cloudflare-hyperdrive → db-migrate → web and cloudflare-r2 → web, every edge enforced, stage and prod side by side, nothing on dev; the PR plan holds the same edges advisory (checked at ≥ v2.78.4); the plan resolves exactly the 6 minted keys and all 5 published ones; the build bakes the product's own origin; a --resume is a no-op.
  • e2e.test.sh at v2.78.4: checks at the 01-product landing; the db-migrate lane's own steps apply 000_control_baseline 010_initial 020_app_secrets 030_row_level_security to a local Postgres with Supabase's roles through the Management-API stand-in, a second apply is a no-op, the PR plan verifies checksums offline; the web lane's install, verify-app-structure, build-app (re-rendered from both stage wiring documents), verify-build-output, deploy-dry-run in the staged tree on Turbopack; then wrangler dev with the AI binding pointed at a deterministic stand-in (testing/lib/fake-ai/, a WorkerEntrypoint answering run() like Workers AI's binding):
    • the component's own smoke (/ping, /api/health);
    • / → guest sign-in → a session that Auth.js's own decode opens with the database's key; / titled with the product name; og/twitter image URLs on https://acme-chatbot-hq-web-stage.acme.workers.dev, nothing pointing at Vercel;
    • /login, /register, a 404, /api/models (Workers AI only);
    • an image uploaded to local R2 and read back byte for byte (plus the download link, and 307 without a session);
    • a message to /api/chat streamed back (11 deltas) from @cf/moonshotai/kimi-k2.6, titled by glm-4.7-flash, persisted (Chat + 4 messages) and listed in /api/history; a gateway model with no key answered by the default Workers AI model;
    • a registration and a sign-in through the forms' server actions (wrong password refused, duplicate refused);
    • RLS: 0 of 7 public tables without RLS; postgres neither superuser nor BYPASSRLS; anon and authenticated see 0 users, chats and messages and cannot write; app_private closed to them.
  • orun new --status at v2.58.11, v2.78.4, 2.79.0; orun validate; orun work check clean; terraform init -backend=false && validate on the three roots (v1.15.3).

Verified only offline / not verified: a real Workers AI model (ids, tool calls, structured output); the Supabase, Hyperdrive and R2 applies, db-migrate against a real project, a real deploy and its probes. A GET / logs a Next/React prerender-resume mismatch (React falls back to client rendering); a build of main logs the same line — recorded as risk AC-O, not introduced here.

Open / owner items

  • R2 binding at deploy (platform risk, not fixed here): the bucket applies with r2-data, but web's wrangler deploy attaches the BLOB binding with the workers-deploy token (Workers Scripts + KV). Whether that token may bind R2 is unverified live — same open risk as blob-starter and commerce.
  • Workers AI is verified only offline (a stand-in binding): the model ids, tool calling and structured output on a real account are unproven until a live bootstrap. Usage is billed to the Cloudflare account after the free allocation.
  • Supabase: the connected org needs room for two projects.
  • Optional owner keys after a build: AI_GATEWAY_API_KEY (gateway models), REDIS_URL, AUTH_SECRET (rotation), SITE_URL (custom domain).

🤖 Generated with Claude Code

https://claude.ai/code/session_01AuyckrXahuAVgdmxamUUtk


Generated by Claude Code

The repository is now a baseline on the Cloudflare + Supabase (Lumen)
conventions, built the way cirrus-baseline v22 builds a product: in ONE
landing, after saas-starter (SA5).

- blueprint.yaml (the card): requires [github, cloudflare, supabase]; six
  brokered keys as a preview (CLOUDFLARE_API_TOKEN workers-deploy,
  CLOUDFLARE_HYPERDRIVE_TOKEN hyperdrive-edit, CLOUDFLARE_R2_TOKEN r2-data,
  CLOUDFLARE_ACCOUNT_ID account-id, SUPABASE_ACCESS_TOKEN management-access,
  SUPABASE_ORG_ID org-id); programme 01-product, 02-docs; two Supabase
  projects (stage and prod) stated as the owner's prerequisite. No model key:
  no platform brokers an AI vendor.
- repo-blueprint.yaml: 01-product places every module, retouches, brands,
  re-tenants, strips the work tree, defers promotion and dev's push lanes,
  links, reconciles one key per hook and lands one PR; it awaits the
  convergence, SUPABASE_PROJECT_REF / _DB_PASSWORD / _DB_URL and
  WIRING_CLOUDFLARE_HYPERDRIVE / _R2 on stage and prod, and /ping plus
  /api/health (every page redirects a visitor with no session to the guest
  sign-in, and the probe wants a 200). 02-docs is hook-only.
- One convergence keeps the order: supabase -> cloudflare-hyperdrive ->
  db-migrate -> web and cloudflare-r2 -> web per environment, every edge
  `mode: enforced` on github-push-main with an advisory modeRule for pull
  requests. The R2 root applies with its own r2-data key, not the deploy
  token.
- Workers AI is the default model provider: an `AI` binding in the
  committed wrangler config, workers-ai-provider 4.0.0 (AI SDK 7), Kimi K2.6
  for the chat and tools, GLM 4.7 Flash for titles. The AI Gateway's models
  are offered only with AI_GATEWAY_API_KEY; the picker shows exactly what
  can answer, and a request for an unavailable model gets the default.
  Workers AI's errors show in the chat; the suggestions tool returns its
  structured-output error to the model. next dev alone opens the platform
  proxy, and the static-assets cache is populated by a copy, so a build
  needs no Cloudflare credential.
- The session key is AUTH_SECRET or one the database generated (migration
  020_app_secrets, app_private): Auth.js initialised lazily, the proxy and
  the guest route reading the same key. The session cookie's name is chosen
  as Auth.js chooses it, so the built Worker served over http no longer
  loops on the guest sign-in.
- Row-level security on all seven tables in public (030, guarded), with
  tests/db's PGlite guard test.
- apps/web/wrangler.jsonc committed as the fixture render; build renders
  every lane (dev from the fixture); /api/health; the lib/site.ts name
  seam; metadataBase the product's own origin (NEXT_PUBLIC_SITE_URL from
  SITE_URL or the workers.dev URL), the "Deploy with Vercel" call to action
  gone; stack-tectonic 0.19.0; checks.yml on pull requests only with
  `git diff --exit-code` after wire:fixture; ci.yml's linked gate at v2.78.4.
- .baseline/, the rename engine (the upstream vercel/ai-chatbot link and
  every migration protected), the bootstrap helpers, the deployment-record
  hook, ai/context/, the phase pages, BOOTSTRAP.md, baseline.yml, tag.yml.
- testing/: manifest, phases, coverage, rebrand, retouch, bootstrap-defer,
  wire, leak, placement and e2e (the migrations applied by the lane's own
  steps to a local Postgres with Supabase's roles; the web lane built in the
  staged tree; wrangler dev with a stand-in AI binding — Workers AI cannot
  be called offline — a guest, a streamed chat, persisted and listed, an
  attachment through local R2, a registration and sign-in, and anon /
  authenticated reading none of it).
- The as-built status is ai-chatbot's again (AC4 had merged rag-chatbot's).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AuyckrXahuAVgdmxamUUtk
@ruehowl
ruehowl marked this pull request as ready for review October 15, 2026 21:20
@ruehowl
ruehowl merged commit d40fe52 into main Oct 15, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants