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/wrangler.template.jsonc (and its committed render, wrangler.jsonc) and the dashboard's <title> in apps/web/index.html — upstream's own label for the template, which the dashboard's kicker keeps; `slug` also names the KV namespace titles (terraform `repo`) and the secret project, and is the first half of the upstream template's directory name and of its index protocol, which the rename never touches; `domain` and `subdomain` are placeholders, because this baseline has never deployed under a name of its own; `githubOwner` is the owner of this repository.",
"slug": "agent-visibility",
"pascal": "AgentVisibility",
"productName": "AI Agent Visibility",
"domain": "agent-visibility.example.com",
"subdomain": "your-workers-subdomain",
"githubOwner": "sourceplane"
}
90 changes: 90 additions & 0 deletions .baseline/product/AGENTS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
# AGENTS.md — agent-visibility

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

## What this is

A site made readable by AI agents: one content store served as `llms.txt`
and `llms-full.txt`, a typed `index.json`, per-page Markdown and JSON-LD,
and a `robots.txt` for AI crawlers, each with a `Content-Signal` header, and
a dashboard previewing them. A Hono Worker on Cloudflare Workers + Static
Assets (the dashboard built by Vite), each page enriched by Workers AI
through the Worker's `AI` binding and cached in a Workers KV namespace that
Terraform provisions per environment. 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 |
|---|---|---|
| `web` | `apps/web` | the Worker and its dashboard, `agent-visibility-web-<env>` |
| `cloudflare-kv` | `infra/terraform/cloudflare-kv` | the KV namespace on stage and prod |
| `web-tests` | `tests/web` | vitest, the Worker over an in-memory KV store and a stand-in model |

## Read first

1. `README.md` — run, test, preview, add pages with the admin token, and how
it deploys.
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/src/worker/index.ts` — every route; then
`apps/web/src/lib/store.ts` (the KV store and when it enriches),
`apps/web/src/enrichment/index.ts` (the model call and its fallback) and
`apps/web/src/enrichment/surfaces.ts` (what each surface renders).
5. `infra/terraform/cloudflare-kv` — the namespace, and the wiring document
(`WIRING_CLOUDFLARE_KV`) the site's build reads its id from.

## Before you push

```bash
pnpm install
pnpm run wire:fixture # apps/web/wrangler.jsonc from the offline fixture
pnpm typecheck && pnpm lint && pnpm test && pnpm build
```

Run them yourself: the pull request's lanes build and dry-deploy the site
and plan the KV root, but do not run the tests or 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: the KV root plans, the site builds and dry-deploys. Nothing
applies or deploys.
- The merge is the deploy. `ci.yml` plans the changed components and runs
each lane: the KV namespace applies first, then the site builds with its
id, hands the stored admin token to the Worker as a secret, deploys and is
smoke-tested — stage, then prod.
- A new component is a directory under `apps/`, `infra/`, `packages/` or
`tests/` with a `component.yaml`; `ai/context/operations.md` says how to
add a binding.

## 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/wrangler.jsonc` is generated. Edit `wrangler.template.jsonc`,
then `pnpm run wire:fixture`, and commit both; the deploy renders its own
config from the template, so a stale committed render misleads local work.
- `apps/web/component.yaml`'s `dependsOn: cloudflare-kv`: it is what makes
the namespace apply before the Worker deploys on `main`.
- 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 site'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: the
admin token is an Orun secret the build strips from its environment
(`env -u ADMIN_TOKEN`) and hands to the 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`).
- `/api/health` must never call the model: the deploy's smoke reads it on
every deploy, and a model call there would spend Workers AI each time.
- `INDEX_PROTOCOL` (`agent-visibility/0.1`, in
`apps/web/src/enrichment/surfaces.ts`) names the shape of `/index.json`
for the agents that read it; change it only with the shape.
- Every surface is public. Nothing private belongs in the store.
169 changes: 169 additions & 0 deletions .baseline/product/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
# agent-visibility

A site made readable by AI agents on every surface they look at — one content
store served as [`/llms.txt`](https://llmstxt.org) and `/llms-full.txt`, a
typed `/index.json`, per-page Markdown (`/<slug>.md`) and schema.org JSON-LD
(`/<slug>.jsonld`, `/jsonld`), and a `/robots.txt` that names the AI crawlers
it welcomes, each with a `Content-Signal` header saying how the content may be
used — with a dashboard at `/` previewing every surface. Each page is
enriched once by **Workers AI** (a title, a summary, key points, topics and a
clean Markdown body) through the Worker's own binding, with no key, and
cached in a **Workers KV** namespace that Terraform provisions per
environment. Cloudflare's
[Agent Visibility template](https://github.com/cloudflare/templates/tree/main/agent-visibility-template)
on **Cloudflare Workers + Static Assets**.

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 site uses into
[ai/context/deployment.md](ai/context/deployment.md); how the site deploys
and how to operate it is in
[ai/context/operations.md](ai/context/operations.md).
<!-- 02-docs:end -->

Every surface is **public by design**: it exists to be read by agents, and
so does everything you add to it. Writes — adding a page, clearing the
cache — are refused until you store an admin token (Adding your pages,
below).

## What is here

| Surface | Where |
|---|---|
| The Worker: every agent surface, the dashboard's API, the optional Web Bot Auth surface | `apps/web/src/worker/index.ts` |
| What the deploy's smoke reads (the store, never the model) | `apps/web/src/worker/health.ts` |
| The enrichment (Workers AI, and its fallback) and the surfaces' renderers | `apps/web/src/enrichment` |
| The KV store, the sample pages, the types | `apps/web/src/lib/store.ts`, `apps/web/src/lib/content.ts`, `apps/web/src/lib/types.ts` |
| The dashboard | `apps/web/src/react-app`, `apps/web/index.html`, built by `apps/web/vite.config.ts` |
| The site's name, the model, the cache's lifetime, the Content-Signal | `vars` in `apps/web/wrangler.template.jsonc` |
| Workers bindings and deploy contract | `apps/web/wrangler.template.jsonc` + `wiring.fixture.json` (→ `wrangler.jsonc`), `component.yaml` |
| The KV namespace (stage, prod) | `infra/terraform/cloudflare-kv` |
| Tests | `tests/web` (vitest, the Worker over an in-memory KV store and a stand-in model) |

## Getting started

```bash
git clone https://github.com/sourceplane/agent-visibility.git
```

```bash
pnpm install
pnpm run wire:fixture # render apps/web/wrangler.jsonc from the offline fixture
pnpm typecheck
pnpm lint
pnpm test
pnpm build # the dashboard → apps/web/dist/client
```

```bash
cp apps/web/.dev.vars.example apps/web/.dev.vars # optional: ADMIN_TOKEN, to try writes
pnpm --filter @app/web dev # http://localhost:8787 — a local KV store, the model off
pnpm --filter @app/web dev:remote # the same with your account's Workers AI (wrangler login first)
```

Workers AI has no local mode. `pnpm dev` runs `wrangler dev --local`, so
every page is enriched by the Worker's fallback from its own text (its
`model` field reads `… (fallback)`); `dev:remote` calls the real model and
may incur Workers AI usage.

Make it yours: the site's name and description are `SITE_NAME` and
`SITE_DESCRIPTION` in `apps/web/wrangler.template.jsonc` (then
`pnpm run wire:fixture`); the pages it starts with are the five samples in
`apps/web/src/lib/content.ts`; the dashboard is `apps/web/src/react-app`.

## Adding your pages

Store an admin token for an environment — the Orun secret `ADMIN_TOKEN`
(`orun secrets set ADMIN_TOKEN --env prod`) — and redeploy that environment
(Deploy by hand, below): the build hands it to the Worker as a Worker secret,
the value over stdin, never in a bundle. Then, with the same value:

```bash
curl -X POST "https://agent-visibility-web-prod.your-workers-subdomain.workers.dev/api/resources" \
-H "Authorization: Bearer $ADMIN_TOKEN" -H "content-type: application/json" \
-d '{"slug":"changelog","title":"Changelog","url":"https://example.com/changelog","body":"# Changelog\n\nv2 adds templates."}'
```

```bash
curl -X POST "https://agent-visibility-web-prod.your-workers-subdomain.workers.dev/api/refresh" \
-H "Authorization: Bearer $ADMIN_TOKEN"
```

The first adds (or replaces) one page — `slug` is 1–63 characters of
`[a-z0-9-]`, `body` HTML or Markdown up to 100 kB, at most 100 pages — and
enriches it; the second clears the enriched cache, so the next read
re-enriches every page. Until the token is stored both answer `401`, and so
does a wrong one. Locally, put it in `apps/web/.dev.vars`. Removing the Orun
secret does not remove the Worker's copy: delete it with
`wrangler secret delete ADMIN_TOKEN --name agent-visibility-web-<env>` too.

The first read of a cold store enriches every page, one model call each, so
it is slow and spends Workers AI usage; the result is cached for
`ENRICHMENT_CACHE_TTL` (an hour), or for a minute when the model failed on a
page and its fallback stood in.

## How the namespace is wired

The Worker binds the namespace as `VISIBILITY_CACHE`. Its id is never
hand-written: `apps/web/wrangler.template.jsonc` names it as a wiring token,
and `wrangler.jsonc` is that template rendered — from `wiring.fixture.json`
(placeholder ids) for local work and verification, and on every deploy from
the document the `cloudflare-kv` Terraform root publishes after its apply
(`WIRING_CLOUDFLARE_KV`, per environment). Edit the template, then
`pnpm run wire:fixture` and commit the render with the template.

KV is eventually consistent: a page added in one location can take up to a
minute to appear in another.

## 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`. The KV namespace applies first, then
the site builds with that environment's namespace id and deploys — to
`stage`, then to `prod` once stage has converged on the same commit; `dev`
only verifies. The Worker is `agent-visibility-web-<env>` on your account's
workers.dev subdomain, and every deploy is smoke-tested over HTTP:
`/api/health` must answer ok, its KV store read — the model never called —
and the dashboard must be served. A pull request runs the same pipeline's
verify lanes, with nothing applied or deployed: the KV namespace planned for
stage and prod, and the site built and dry-deployed for each environment.
They do not run the tests or the linter — run those before you push
(Getting started, above).

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, the namespace ids travel as Orun secrets, and the
admin token is an Orun secret you store; 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, 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 the token, say. A component with nothing to run in that environment
(a test suite in `prod`) is left out with a notice.

## Custom domain

The site answers on workers.dev from its first deploy. To serve it on your
own domain, add the domain to the Cloudflare account the site deploys into
and attach it to the Worker (dashboard → Workers & Pages →
`agent-visibility-web-prod` → Settings → Domains & Routes → Add → Custom
domain). Every surface builds its absolute links from the request it is
answering, so nothing else has to change; the repository names the domain
in one place, `BASE_DOMAIN` in `intent.yaml`, which the site was born with
as the reserved placeholder `agent-visibility.example.com`. Replace it with
your domain in the same change that records it.

## Credits

The site is Cloudflare's
[`agent-visibility-template`](https://github.com/cloudflare/templates/tree/main/agent-visibility-template),
MIT (© 2018 Cloudflare, Inc.; `apps/web/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 applies the KV namespace and deploys the site on stage and prod
affects:
- cloudflare-kv
- web
- web-tests
doneWhen:
- repo pushed, main pinned as default, workspace linked
- WIRING_CLOUDFLARE_KV published on stage and prod
- main convergence green (KV applied, then the site built, deployed and smoke-tested on stage and prod)
- the site answers on both workers.dev URLs
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