Skip to content

RG5: rag-chatbot becomes an Orun baseline - #6

Merged
ruehowl merged 2 commits into
mainfrom
claude/blissful-ptolemy-c5ajf8
Oct 15, 2026
Merged

ruehowl merged 2 commits into
mainfrom
claude/blissful-ptolemy-c5ajf8

Conversation

@ruehowl

@ruehowl ruehowl commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

The repository becomes an Orun baseline on the Cloudflare + Supabase (Lumen) conventions, built the way cirrus-baseline v22 builds a product: one landing. It is copied closely from saas-starter's conversion (sourceplane/saas-starter#6), the reference for the Supabase group. Milestone RG5, task RG-6.

What was added

The card (blueprint.yaml)

  • requires.integrations: [github, cloudflare, supabase].
  • spec.secrets previews the five brokered keys. Each one is transcribed from a reconcile hook and resolved by the product's plan:
    • CLOUDFLARE_API_TOKEN (workers-deploy)
    • CLOUDFLARE_HYPERDRIVE_TOKEN (hyperdrive-edit)
    • CLOUDFLARE_ACCOUNT_ID (account-id)
    • SUPABASE_ACCESS_TOKEN (management-access)
    • SUPABASE_ORG_ID (org-id)
  • The card asks for no AI vendor key.
  • Programme 01-product, 02-docs; expectedMinutes: 20.
  • The description says the product creates two Supabase projects (stage and prod), which is the free plan's limit (rule B). BOOTSTRAP.md lists this as an owner prerequisite.

The build document (repo-blueprint.yaml): two phases

  • 01-product places all 25 modules.
    • Post hooks, in the brief's order: retouch, git-init, stage → rebrand, orun-workspace → work-tree --strip, promotion --defer, dev-lanes --defer → restage, rebrand-verify → pnpm lockfile → orun.repo/ensure@v1, then link → five orun.integrations/reconcile@v1 hooks → orun.pr/land@v1.
    • Await hooks:
      • orun.run/watch@v1 on the merge sha;
      • orun.secrets/exists@v1 for SUPABASE_PROJECT_REF, SUPABASE_DB_PASSWORD, SUPABASE_DB_URL and WIRING_CLOUDFLARE_HYPERDRIVE, on stage and prod;
      • orun.http/probe@v1 on / and /api/health, on stage and prod.
  • 02-docs is hook-only: it restores promotion and dev-lanes, renders the record (which now includes the chat's model), lands, and probes.

Deploy order on github-push-main

  • Per environment the order is supabase → cloudflare-hyperdrive → db-migrate → web.
  • Every edge is mode: enforced, with modeRules making it advisory on pull requests.

Workers AI as the model provider (the RAG specifics)

  • Models. The committed wrangler config has an AI binding, and lib/ai/models.ts serves two models through workers-ai-provider 2.0.2 (the AI SDK v5 release):
    • @cf/meta/llama-4-scout-17b-16e-instruct for the chat and understandQuery's generateObject (function calling, JSON mode);
    • @cf/baai/bge-base-en-v1.5 for the embeddings.
  • Streaming. The chat model is wrapped in simulateStreamingMiddleware, so each step is one whole AI.run. The provider can't read a streamed tool call in Workers AI's OpenAI-style shape, and the route chains three tools.
  • Embedding dimension. Migration 020_workers_ai_embeddings resizes embeddings.embedding to vector(768) and rebuilds the HNSW index. It refuses to run while any row holds another model's vector.
    • pgvector itself is still enabled by upstream's migration (010, which is unchanged).
  • Vendor key. AI_GATEWAY_API_KEY is optional. When set, it switches the chat only to upstream's openai/gpt-4o through the gateway. Embeddings stay on Workers AI, because the column is sized to that model.
    • With neither the binding nor the key, the route answers 503 with the reason, not a 500.
    • The product README ("Use a vendor model instead") documents how an owner adds the key.
  • Build needs no Cloudflare credential. Wrangler's platform proxy opens a remote session for any AI binding. Two changes avoid it:
    • next.config.mjs starts the proxy only under next dev;
    • the static-assets cache is populated by scripts/populate-static-assets-cache.mjs, which does the same copy as populateCache local (using OpenNext's own CACHE_DIR) but without the proxy.

Other product changes

  • Row-level security on every table in public (rule A): migration 030_row_level_security plus .enableRLS(), with no policies and saas-starter's guard.
  • The page's public origin is the product's own. Upstream hard-coded its demo origin as metadataBase, so every product would have advertised upstream's og:image on vercel.app. This follows the postgres-drizzle-starter and portfolio-starter-kit pattern:
    • the layout reads NEXT_PUBLIC_SITE_URL;
    • component.yaml's buildCommand sets it to the environment's SITE_URL (for a custom domain) or else its workers.dev URL. The subdomain is written out because the composition exports WORKERS_DEV_SUBDOMAIN to the smoke step only.
  • /api/health checks the database through Hyperdrive, both tables, and that the embeddings column is 768 wide. It reports chat: workers-ai | ai-gateway and calls no model. The deploy's smoke and the probes use it.
  • Name seam. The product name lives in lib/site.ts, which sets the page title. The rebrand leaves the AI SDK guide link alone, because its path ends in this baseline's slug.
  • Infra and pipeline, as in saas-starter:
    • wrangler.jsonc is committed as the fixture render;
    • the supabase root publishes only Lumen's three outputs, and both roots carry Lumen's lock files;
    • stack-tectonic is pinned at 0.19.0;
    • checks.yml runs on pull requests only;
    • ci.yml uses the linked gate on v2.78.4.

Baseline machinery

  • Adapted from saas-starter (portfolio baseline-v2 lineage): .baseline/, the rebrand engine, the bootstrap helpers, the deployment-record hook, ai/context/, docs/phases/, BOOTSTRAP.md, baseline.yml and tag.yml.
  • The product job in baseline.yml installs pgvector for the runner's PostgreSQL.

How it was verified (locally)

Repository checks

  • All green, and the build needs no Cloudflare credential: pnpm install --frozen-lockfile, wire:fixture, typecheck, lint (0 errors, 1 upstream warning), test, build.
  • 45 tests in total.
    • tests/web (32) runs the real chat route, the AI SDK and the provider against a scripted binding: understandQuery → getInformation → answer, addResource, and the 503. It also checks the page's public origin and the build line that sets it.
    • tests/db (13) runs every migration on PGlite with @electric-sql/pglite-pgvector 0.0.9 (the version that pairs with the pinned PGlite 0.5.8). It checks vector(768), cosine ranking, both guards, and RLS against a role with the Data API's grants.
  • drizzle-kit check passes and finds no pending diff.

testing/*.test.sh

  • Contract suites, all green: manifest, phases, coverage, rebrand (which now covers the build's site URL), retouch, bootstrap-defer, leak.
  • placement, green at 2.58.11, 2.78.4 and 2.79.0:
    • the product's push-to-main plan shows the enforced chain;
    • the PR plan shows the same edges as advisory;
    • the plan resolves exactly the 5 minted keys;
    • --resume is a no-op.
  • e2e, green at v2.78.4. The local Postgres has Supabase's roles plus pgvector.
    • The db-migrate lane's own steps apply all four migrations, and a re-apply is a no-op.
    • The web lane, including verify-app-structure, builds in the staged job tree.
    • wrangler dev runs with no .dev.vars and with AI bound to a deterministic Workers AI stand-in (testing/lib/fake-workers-ai.js). It passes:
      • the component's smoke and /, whose og:image is on https://acme-rag-web-stage.acme.workers.dev/ (never vercel.app) and is served;
      • a 404 and /api/health;
      • a document added through the chat, stored as 1 resource and 3 vector(768) rows;
      • a question answered from the one chunk pgvector ranked above 0.3 (0.83);
      • "Sorry, I don't know." for an unrelated question.
    • anon and authenticated read and write neither table.

orun and Terraform

  • orun new --status at v2.58.11, v2.78.4 and 2.79.0; orun validate; orun work check: all clean.
  • terraform fmt, init -backend=false and validate pass on both roots.

Verified only offline:

  • The models. The e2e's Workers AI is a stand-in that answers in the catalog's shapes, so real Llama 4 Scout tool use, JSON-mode acceptance and bge retrieval quality are unproven.
  • The AI binding on deploy. Whether the brokered workers-deploy token can attach an AI binding has not been tried.
  • pgvector as postgres. The e2e stand-in's superuser pre-creates pgvector, because Supabase's supautils isn't there; tests/db runs the CREATE EXTENSION for real.
  • The live half. Not run: a Terraform apply, a db-migrate apply against a real Supabase project, a live deploy, a bootstrap.

🤖 Generated with Claude Code

https://claude.ai/code/session_01AuyckrXahuAVgdmxamUUtk

pullely and others added 2 commits October 15, 2026 20:53
The repository becomes an Orun baseline on the Cloudflare + Supabase
(Lumen) conventions, built the way cirrus-baseline v22 builds a product:
ONE landing (01-product), then a hook-only deployment record (02-docs).
Copied closely from saas-starter's SA5 (sourceplane/saas-starter#6).

- blueprint.yaml (requires [github, cloudflare, supabase]; the five
  brokered keys; the two-Supabase-projects prerequisite) and
  repo-blueprint.yaml (every module in 01-product; the cirrus v22 hook
  chain; await: the convergence, SUPABASE_PROJECT_REF/_DB_PASSWORD/_DB_URL
  and WIRING_CLOUDFLARE_HYPERDRIVE on stage and prod, / and /api/health).
- Infra before app on main: supabase -> cloudflare-hyperdrive ->
  db-migrate -> web, every edge enforced on github-push-main and advisory
  on pull requests.
- Workers AI is the default model provider through an AI binding in the
  committed wrangler config: @cf/meta/llama-4-scout-17b-16e-instruct for
  the chat, @cf/baai/bge-base-en-v1.5 for the embeddings
  (workers-ai-provider 2.0.2, the AI SDK v5 release). AI_GATEWAY_API_KEY
  is optional and switches only the chat to upstream's gateway model.
- Migration 020_workers_ai_embeddings resizes embeddings.embedding to
  vector(768) (with a guard against foreign vectors); 030 enables
  row-level security, no policy, on every table in public. Both have
  drizzle-kit twins; tests/db runs every migration on PGlite with pgvector.
- The build needs no Cloudflare credential: the platform proxy starts only
  under next dev, and the static-assets cache is populated by a copy.
- /api/health, the committed wrangler.jsonc, the rebrand engine and
  name seam, the bootstrap helpers, the deployment-record hook,
  ai/context, docs/phases, BOOTSTRAP.md, testing/ (with a deterministic
  Workers AI stand-in for the e2e), baseline.yml and tag.yml.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AuyckrXahuAVgdmxamUUtk
Upstream's layout hard-coded its demo's origin as metadataBase, which Next
resolves the page's opengraph-image.png against: every product built from
this baseline would have advertised upstream's vercel.app image URL as its
og:image.

- app/(preview)/layout.tsx reads NEXT_PUBLIC_SITE_URL (default
  http://localhost:3000).
- apps/web/component.yaml's buildCommand sets it, as postgres-drizzle-starter
  and portfolio-starter-kit do: the environment's SITE_URL (intent.yaml
  env:, for a custom domain), else its workers.dev URL, the subdomain
  written out because the composition exports WORKERS_DEV_SUBDOMAIN to the
  smoke step only. The page is pre-rendered, so the build bakes it in.
- .env.example documents NEXT_PUBLIC_SITE_URL; intent.yaml, the product
  README, operations.md and BOOTSTRAP.md say how a custom domain sets it.
- rebrand.test.sh covers the line (worker name and subdomain rewritten);
  tests/web holds the layout and the build line; the e2e asserts the served
  page's og:image is on the product's own stage origin, not vercel.app, and
  that the image is served.

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:32
@ruehowl
ruehowl merged commit 42b2895 into main Oct 15, 2026
6 checks passed
ruehowl added a commit that referenced this pull request Oct 21, 2026
…text pack (#7)

* RG6: the cirrus standard — no kiox, generated component docs, the context pack

- 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 seven 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 RG5 (shipped in #6, tagged baseline-v1) and record RG6 (RG-7).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01D8AmgTwmnp4M8mgmnS9aha

* Regenerate component docs: prettier-padded tables, accurate wording

The generator now lays tables out the way prettier does (an app whose lint
is `prettier --check` accepts the pages as written), lists the WIRING_*
failure only for Workers that take wiring, and no longer claims a package
holds no credentials.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01D8AmgTwmnp4M8mgmnS9aha

* 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 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01D8AmgTwmnp4M8mgmnS9aha

---------

Co-authored-by: Claude <noreply@anthropic.com>
ruehowl added a commit that referenced this pull request Oct 21, 2026
* RG6: the cirrus standard — no kiox, generated component docs, the context pack

- 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 seven 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 RG5 (shipped in #6, tagged baseline-v1) and record RG6 (RG-7).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01D8AmgTwmnp4M8mgmnS9aha

* Regenerate component docs: prettier-padded tables, accurate wording

The generator now lays tables out the way prettier does (an app whose lint
is `prettier --check` accepts the pages as written), lists the WIRING_*
failure only for Workers that take wiring, and no longer claims a package
holds no credentials.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01D8AmgTwmnp4M8mgmnS9aha

* 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 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01D8AmgTwmnp4M8mgmnS9aha

* RG6: 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: RG-8 under RG6, status, plan, epic index, ai/context

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01D8AmgTwmnp4M8mgmnS9aha

---------

Co-authored-by: Claude <noreply@anthropic.com>
ruehowl added a commit that referenced this pull request Oct 22, 2026
* RG6: the cirrus standard — no kiox, generated component docs, the context pack

- 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 seven 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 RG5 (shipped in #6, tagged baseline-v1) and record RG6 (RG-7).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01D8AmgTwmnp4M8mgmnS9aha

* Regenerate component docs: prettier-padded tables, accurate wording

The generator now lays tables out the way prettier does (an app whose lint
is `prettier --check` accepts the pages as written), lists the WIRING_*
failure only for Workers that take wiring, and no longer claims a package
holds no credentials.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01D8AmgTwmnp4M8mgmnS9aha

* 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 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01D8AmgTwmnp4M8mgmnS9aha

* RG6: 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: RG-8 under RG6, status, plan, epic index, ai/context

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01D8AmgTwmnp4M8mgmnS9aha

* RG7: the console asks for no domain — the domain is set later

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 <reponame>.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: RG7 / RG-9, tagged baseline-v3

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01D8AmgTwmnp4M8mgmnS9aha

---------

Co-authored-by: Claude <noreply@anthropic.com>
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