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
9 changes: 9 additions & 0 deletions .baseline/identity.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"_comment": "THIS TREE'S OWN IDENTITY — the FROM side of every rebrand. tooling/rebrand/rebrand.mjs reads it to know what to rename AWAY from; a product's identity is the --values file, which is the TO side. Change a value here only together with the tree: these strings must be what the tree actually contains, or the rename silently misses and the product ships carrying this baseline's name. `productName` is the SITE_NAME seam in apps/web/lib/site.ts and apps/preview/lib/site.ts; `slug` also names both Workers (<slug>-web, <slug>-preview) and the secret project; `domain` and `subdomain` are placeholders, because this baseline has never deployed under a name of its own; `githubOwner` is the owner in the repository's own links.",
"slug": "v0-clone",
"pascal": "V0Clone",
"productName": "My App Builder",
"domain": "v0-clone.example.com",
"subdomain": "your-workers-subdomain",
"githubOwner": "sourceplane"
}
88 changes: 88 additions & 0 deletions .baseline/product/AGENTS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
# AGENTS.md — v0-clone

For a coding agent (or a person) about to change this repository.

## What this is

An AI app builder over the v0 Platform API: a v0-style chat that creates and
refines apps, shows their files and a live preview, and deploys them — with
the preview served from an origin of its own. Two Next.js apps on two
Cloudflare Workers + Static Assets (built by `@opennextjs/cloudflare`), each
told the other's origin at build; no database, and the v0 key each visitor's
own (a cookie) unless the owner stores one. It is an
[Orun](https://github.com/sourceplane/orun) repository: `intent.yaml`
declares the environments, and each `component.yaml` is a component Orun
plans and deploys.

| Component | Path | What it is |
|---|---|---|
| `preview` | `apps/preview` | the preview proxy and its Worker, `v0-clone-preview-<env>` |
| `web` | `apps/web` | the host app and its Worker, `v0-clone-web-<env>` |
| `preview-tests` | `tests/preview` | vitest: the key route, the origins, trusted hosts |
| `web-tests` | `tests/web` | vitest: upstream's Design Mode tests, the host's routes |

## Read first

1. `README.md` — run, test, connect v0, and how it deploys; and its security
warning: there are no accounts.
2. `ai/context/operations.md` — the operating contract: deploy order,
secrets, caveats, common operations.
3. `ai/context/deployment.md` — what is live now: URLs, workspace, secrets
by name.
4. `apps/web/components/home/home-client.tsx` and
`apps/web/components/chat/` — the chat; `apps/web/app/api/chats/` — its
routes over the v0 API; `apps/web/lib/v0-client.ts` — which key.
5. `apps/preview/app/api/v0-preview/[chatId]/[[...path]]/route.ts` and
`apps/preview/proxy.ts` — how a preview is served;
`apps/preview/app/api/api-key/route.ts` — how the host hands it a key.

## Before you push

```bash
pnpm install
pnpm typecheck && pnpm lint && pnpm test && pnpm build
```

Run them yourself: the pull request's lanes build and dry-deploy both apps
and run both test suites, but do not run the linter.

## How changes land

- One change, one pull request into `main`. If the work is an Orun task,
open the pull request for it: `orun pr open --task <KEY>`.
- On the pull request, `ci.yml` plans with `orun plan --changed` and
verifies: both apps build and dry-deploy, both test suites run. Nothing
deploys.
- The merge is the deploy. `ci.yml` plans the changed components and runs
each lane: the preview proxy builds with the host's origin, hands a stored
key to its Worker as a secret, deploys and is smoke-tested; then the host
does the same with the proxy's origin — stage, then prod.
- A new component is a directory under `apps/`, `infra/`, `packages/` or
`tests/` with a `component.yaml`.

## What not to touch

- `intent.yaml` → `execution.state.workspace`: the workspace CI
authenticates to. Also the stack-tectonic pin (`0.19.0`); its comment says
why it is not `0.20.0`.
- `apps/web/component.yaml`'s `dependsOn: preview`: it is what makes the
preview origin deploy before the host on `main`, and the host's smoke
checks that origin.
- Each app's `buildCommand`: it inlines the other app's origin
(`NEXT_PUBLIC_V0_PREVIEW_PROXY_URL`, `NEXT_PUBLIC_V0_CLONE_ORIGIN`). Change
an origin under the environment's `env:` in `intent.yaml`, not in code.
- `authorizeProxyRequest` (`apps/web/lib/proxy.ts`,
`apps/preview/lib/authorize.ts`) is a same-origin check, not auth. Replace
it with a session check before storing `V0_API_KEY` without Cloudflare
Access; never loosen it.
- The last line of each `component.yaml` (`# orun: redeploy …`) is a deploy
trigger; change it only to redeploy.
- `ai/context/deployment.md` is regenerated from probed state; a hand edit is
overwritten. `.rebrand/values.json` records the product's identity; leave
it.
- Only `ci.yml` may run on a push to `main`.
- No secret value goes in the repository, and none reaches the build:
`V0_API_KEY` is an Orun secret the build strips from its environment
(`env -u V0_API_KEY`) and hands to each Worker as a Worker secret. The
Cloudflare token and account id are brokered from the workspace's
Cloudflare connection; list secrets by name only (`orun secrets list`).
145 changes: 145 additions & 0 deletions .baseline/product/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
# v0-clone

An AI app builder — describe an app, the [v0 Platform API](https://v0.app/docs/api/platform)
writes it, and you refine it in chat, read and edit its files, restore a
version, design against its live preview and deploy it — with every preview
served from an origin of its own, so generated code never runs beside the
app that holds the key. Vercel's [v0 clone](https://github.com/vercel/v0-sdk/tree/main/examples/v0-clone)
(the v0 SDK's example app) on **two Cloudflare Workers + Static Assets**
through [`@opennextjs/cloudflare`](https://opennext.js.org/cloudflare): the
host app and its preview proxy, each told the other's origin at build. It
keeps no store of its own: chats, files and previews are the v0 API's.

> **Security warning — upstream's, read for Cloudflare.** There are no user
> accounts. With `V0_API_KEY` stored, everyone who can reach the Workers
> shares that key's v0 workspace: they can read, create, change and delete
> chats, run generations at its expense and deploy with the Vercel token the
> key carries. Every server route passes through `authorizeProxyRequest`
> (`apps/web/lib/proxy.ts`, `apps/preview/lib/authorize.ts`), a same-origin
> check only — the seam where real session auth goes. Until it does, **leave
> `V0_API_KEY` unset** (each visitor then uses their own key, through the
> app's dialog) or put [Cloudflare Access](https://developers.cloudflare.com/cloudflare-one/applications/)
> in front of both Workers before you store one.

Building on it with an agent? Start it at [AGENTS.md](AGENTS.md): what to
read first, how a change lands, and what not to touch.

## Live deployment

<!-- 02-docs:begin -->
Not recorded yet. The bootstrap's last phase writes the live URLs, the
workspace and the secrets the product uses into
[ai/context/deployment.md](ai/context/deployment.md); how the product deploys
and how to operate it is in
[ai/context/operations.md](ai/context/operations.md).
<!-- 02-docs:end -->

## What is here

| Surface | Where |
|---|---|
| The host app: the chat, the sidebar, the files, code and preview panes | `apps/web/app`, `apps/web/components` |
| Its server routes over the v0 API: messages, files, Design Mode, imports, restore, deploy | `apps/web/app/api/chats`, `apps/web/app/api/settings/api-key` |
| The preview proxy: each chat's preview, fetched with the key and served into the host's iframe; the key route the host provisions | `apps/preview/app/api/v0-preview`, `apps/preview/app/api/api-key`, `apps/preview/proxy.ts` |
| Where each app finds the other | `apps/web/lib/preview-proxy.ts`, `apps/preview/lib/origins.ts` |
| The v0 key (server, else the visitor's cookie) | `apps/web/lib/v0-client.ts`, `apps/preview/lib/v0-client.ts` |
| The product's name | `apps/web/lib/site.ts`, `apps/preview/lib/site.ts` |
| What each deploy's smoke reads | `apps/web/app/api/health/route.ts`, `apps/preview/app/api/health/route.ts` |
| Workers build and deploy contract | each app's `next.config.mjs`, `open-next.config.ts`, `wrangler.jsonc`, `component.yaml` |
| The Worker-secrets helper | `tooling/wire` |
| Tests | `tests/web` (upstream's Design Mode tests, the host's routes), `tests/preview` (the key route, trusted hosts) |

## Getting started

```bash
pnpm install
pnpm typecheck
pnpm lint
pnpm test
pnpm build # next build + opennextjs-cloudflare build, for both apps
```

```bash
pnpm dev # both apps: the host on http://localhost:3000, the proxy on http://localhost:3001
```

Open the host app and save a v0 API key through its dialog
([v0.app → Settings → API keys](https://v0.app/chat/settings/keys); it needs
write access and generation credits). The key is validated, kept in an
HTTP-only cookie on the host's origin, and handed by your browser straight to
the preview proxy, which keeps its own copy in its own cookie. To serve the
built Workers instead: `pnpm --filter @app/preview preview` and
`pnpm --filter @app/web preview` (wrangler dev; `.dev.vars.example` in each
app).

## Connecting v0

Each app resolves its credential in this order: `V0_API_KEY`, then its own
cookie.

- **Bring your own key (the default).** Leave `V0_API_KEY` unset. Every
visitor saves their own key through the dialog and spends their own credits.
- **One shared key.** Store it per environment as the Orun secret
`V0_API_KEY` (`orun secrets set V0_API_KEY --org <ws> --env <env>`) and
redeploy that environment: both Workers' deploys push it as a Worker
secret (it never reaches a bundle), and the dialog turns read-only. Read
the security warning above first.

## How it deploys

Merges to `main` converge through [Orun](https://github.com/sourceplane/orun):
`.github/workflows/ci.yml` plans the changed components and runs each lane
against the workspace in `intent.yaml`. Per environment, the preview proxy
deploys first as `v0-clone-preview-<env>`, then the host app as
`v0-clone-web-<env>` — the host waits for its proxy — to `stage`, then to
`prod` once stage has converged on the same commit; `dev` only verifies.
Each deploy is smoke-tested over HTTP: the proxy's `/api/health`, then the
host's page, its `/api/health` and the health of the proxy origin it was
built with. Neither needs a v0 key to pass. A pull request runs the same
pipeline's verify lanes, with nothing deployed: both apps built and
dry-deployed per environment, both test suites run.

The pipeline holds one credential, GitHub's own `GITHUB_TOKEN`. The
Cloudflare token and account id are brokered per run from the workspace's
Cloudflare connection, and `V0_API_KEY` is an Orun secret you store if you
want one; nothing provider-shaped is stored in the repository or in GitHub.

**Deploy by hand.** Orunbase's **Deploy** button on a component, or **Run
workflow** on the CI workflow in GitHub's Actions tab (on `main`), runs
`ci.yml` for the environment and components you pick (`web`, `preview`), and
each one deploys exactly as a merge would deploy it. Leave the component
blank to redeploy every component in that environment, with nothing
changed: after storing or rotating `V0_API_KEY`, say. A component with
nothing to run in that environment (a test suite in `prod`) is left out with
a notice.

## Custom domains

Both apps answer on workers.dev from their first deploy. Both workers.dev
hostnames share one registrable domain (`<subdomain>.workers.dev`), so the
preview is cross-origin to the host but same-site with it; for production,
give the preview proxy a domain on a **different registrable domain** from
the host's, as upstream recommends. Attach a domain to each Worker
(dashboard → Workers & Pages → `v0-clone-web-prod` / `v0-clone-preview-prod`
→ Settings → Domains & Routes → Add → Custom domain), then tell each build
the other's origin under the environment's `env:` in `intent.yaml`, and
redeploy both apps:

```yaml
env:
BASE_DOMAIN: acme.com # was the placeholder v0-clone.example.com
V0_PREVIEW_PROXY_URL: https://acme-previews.net # the host's iframe points here
V0_CLONE_ORIGIN: https://app.acme.com # the only origin the proxy lets provision its key
```

## Trusted preview hosts

The preview proxy registers its own hostname in the v0 team's trusted preview
hosts (at most five) the first time it is provisioned with a key or serves a
preview. Stage and prod take two; remove stale ones in v0's settings.

## Credits

Vercel's [v0 clone](https://github.com/vercel/v0-sdk/tree/main/examples/v0-clone)
and the v0 SDK are © Vercel, Inc., under the Apache License 2.0
(`apps/web/LICENSE`, `apps/preview/LICENSE`).
27 changes: 27 additions & 0 deletions .baseline/tasks/01-product.TaskContract.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Task contract template for the 01-product landing.
# Unbound to a key on purpose: `orun.task/ensure@v1` seals and attaches it to
# the key the allocator issues. It lives under `.baseline/`, not `tasks/`,
# because `tasks/` is this repository's own work tree (`intent.yaml` `work:`),
# where an unkeyed contract is an error. gates: [] is a DECLARATION — merge
# alone finishes this task; the main convergence is the gate the bootstrap
# watches, not one the plane observes as a PR check.
#
# The whole product in one landing. `affects` names COMPONENTS, by
# metadata.name: the phase's retouch hook reads this list to decide which
# component.yaml files get the redeploy marker, so a re-run of the phase has a
# diff and exactly these components are re-planned — the deploy set and the
# task plane's statement of the work are one list.
apiVersion: orun.io/v1
kind: TaskContract
spec:
goal: The product's repository is born and linked, the whole product lands in one pull request, and one convergence deploys the preview origin and then the host app on stage and prod
affects:
- preview
- preview-tests
- web
- web-tests
doneWhen:
- repo pushed, main pinned as default, workspace linked
- main convergence green (the preview origin built, deployed and smoke-tested, then the host app, on stage and prod)
- both apps answer on their workers.dev URLs, the host app's health naming its preview origin
gates: []
13 changes: 13 additions & 0 deletions .baseline/tasks/02-docs.TaskContract.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Task contract template for the 02-docs landing. See 01-product's header.
apiVersion: orun.io/v1
kind: TaskContract
spec:
goal: The live deployment is recorded from verified facts as agent-readable state in the product's repo
affects:
- ai/context/deployment.md
- ai/context/operations.md
- README.md
doneWhen:
- committed deployment manifest matches probed reality
- prod waits on stage again, and dev verifies every merge to main again
gates: []
Loading
Loading