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
48 changes: 48 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,54 @@ jobs:
# actions/deploy-pages v5.0.1
uses: actions/deploy-pages@368f82528645a54fb793d4d04e342629a3f51346

worker:
# The Markdown-for-Agents / API-catalog Worker (`worker/`, ADRs 0016-0017).
# It fronts purview.dev at the Cloudflare edge, so it is deployed as part of
# this deployment — after the site, so the pages and files it serves are live
# first. It is skipped (never fails) when the Cloudflare credentials are not
# configured, so a fork or a contributor without them is never blocked.
needs: deploy
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- name: Checkout
# actions/checkout v7.0.1
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1

- name: Install Bun
# oven-sh/setup-bun v2.2.0
uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6
with:
bun-version: 1.4.4

- name: Check for Cloudflare credentials
id: creds
env:
TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
ACCOUNT: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
run: |
if [ -n "$TOKEN" ] && [ -n "$ACCOUNT" ]; then
echo "ready=true" >> "$GITHUB_OUTPUT"
else
echo "ready=false" >> "$GITHUB_OUTPUT"
echo "::notice::CLOUDFLARE_API_TOKEN / CLOUDFLARE_ACCOUNT_ID are not set; skipping the Worker deploy."
fi

- name: Test the Worker
if: steps.creds.outputs.ready == 'true'
run: bun test worker/tests

- name: Deploy the Worker
if: steps.creds.outputs.ready == 'true'
working-directory: worker
env:
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
# Pinned so the deploy is reproducible; `wrangler deploy` bundles the
# TypeScript entry point, so the Worker needs no build step.
run: bunx wrangler@4.171.0 deploy

indexnow:
# Runs only after a successful production deployment. A failed deploy must
# never tell search engines that new URLs are live. The site deployment
Expand Down
15 changes: 14 additions & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,15 @@ from the repository root and delegated to the package.

- **Runtime / package manager:** Bun 1.4.4 (`packageManager` pinned; `bun.lock` committed).
- **Framework:** Astro 7 with Starlight 0.42, Tailwind 4, and four small Preact islands. Output is
static HTML; nothing depends on a server at runtime.
static HTML served from GitHub Pages.
- **Edge behaviour lives in `worker/`.** The one runtime component is the small dependency-free
Cloudflare Worker in `worker/`. It sits in front of the origin and shapes responses a static file
host cannot — `Accept: text/markdown` negotiation, the RFC 9727 `/.well-known/api-catalog` media
type, the homepage discovery `Link` headers — and passes every other request through untouched
(ADR 0016, ADR 0018). **This is the designated place for that kind of work:** anything that needs a
request header read or a response header set (a new `.well-known` media type, content negotiation,
HTML headers GitHub Pages cannot express) is added there and tested in `worker/tests/`, never
bolted onto the build, which only ever writes files.
- **All code is TypeScript.** Linting/formatting use the Oxc toolchain (`oxlint`, `oxfmt`).
`oxfmt` does **not** support `.astro` yet (oxc-project/oxc#15665) — format those by hand and rely
on `astro check` + oxlint.
Expand Down Expand Up @@ -193,4 +201,9 @@ src/src/data/projects/<id>.yml` against a clone of its repository.
| Live examples | `src/src/pages/examples/<project-id>.mdx` (linked from the project page automatically) |
| Validation | `justfile`, `src/scripts/{check-links,check-generated,check-assets,check-projects,check-seo}.ts` |
| Upstream-triggered rebuilds | `.github/workflows/upstream-refresh.yml`, `src/scripts/upstream-state.ts`, `src/src/lib/upstream.ts` (ADR 0014) |
| Edge response behaviour (headers, negotiation, `.well-known` types) | `worker/src/index.ts`, `worker/wrangler.toml`, `worker/README.md` (ADR 0016, ADR 0018) |
| Markdown for agents | `worker/` (Cloudflare Worker, deployed by `.github/workflows/deploy.yml`), `src/src/lib/discovery/page-markdown.ts` (ADR 0016) |
| API catalog (RFC 9727) | `src/src/lib/discovery/api-catalog.ts` (ADR 0017), `/.well-known/api-catalog` |
| Discovery `Link` headers (RFC 8288 / RFC 9727 §3) | `worker/src/links.ts`, `worker/src/index.ts` (ADR 0018) |
| Agent registration (Auth.md) | `src/src/lib/discovery/auth-md.ts`, `/auth.md` (ADR 0019) |
| Architecture decisions | `docs/decisions/*.md` |
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -610,8 +610,11 @@ generated discovery layer: a partitioned sitemap (`/sitemap-index.xml` →
`/sitemaps/{pages,projects,llms}.xml`), `robots.txt`, root and per-project
`llms.txt` / `llms-full.txt`, and a Purview-specific `/discover.json`. Everything
is derived from the project catalogue, the docs manifest and the release cache —
there is no hand-maintained URL list. After a successful deployment, IndexNow
notifies participating engines about changed URLs only.
there is no hand-maintained URL list. The homepage response advertises that
surface through HTTP `Link` headers (RFC 8288 / RFC 9727 §3), added by the edge
Worker, and a self-contained `/auth.md` records that the site has no login (so
there is no agent registration to complete). After a successful deployment,
IndexNow notifies participating engines about changed URLs only.

```shell
bun run discovery:validate # validate the built discovery artifacts
Expand Down
80 changes: 80 additions & 0 deletions docs/decisions/0016-markdown-for-agents.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# ADR 0016 — Markdown for Agents: per-page Markdown and an edge negotiation Worker

- Status: accepted
- Date: 2026-04-12

## Context

Agent-readiness tooling expects a site to serve a Markdown representation of a
page when a client asks for it:

```http
GET /docs/zodsharp/core-concepts/ HTTP/2
Accept: text/markdown
```

and to keep serving HTML to everything else. Two facts constrain us:

1. **The origin cannot negotiate.** `purview.dev` is a static **GitHub Pages**
build (ADR 0001). A file host has no `_headers` support and cannot vary a
response by request header, so no amount of Astro code makes the origin answer
`Accept: text/markdown`.
2. **The managed edge feature is out of reach.** Cloudflare proxies the zone, but
its *Markdown for Agents* conversion is **Pro / Business / Enterprise** only
(and SSL for SaaS); the zone is on the **Free** plan.

The site already publishes machine-readable Markdown, but only as *corpus*
bundles: the site-wide `/llms.txt` / `/llms-full.txt` and the per-project (and
per-version) `/projects/<id>/llms-full.txt`. Those answer "what does this project
document", not "what does *this page* say" — the concatenation of a project's
docs is not a representation of one page.

## Decision

Serve per-page Markdown, and negotiate it at the edge with a Worker the site
owns.

1. **Build emits a Markdown sibling per page.** At `astro:build:done` the
discovery integration writes `<page-url>index.md` beside each built
`index.html` (`/docs/zodsharp/core-concepts/index.md`) from the same docs
mirror file the HTML is rendered from (`lib/discovery/page-markdown.ts`,
`emit.ts`). The two representations cannot disagree. Each documentation page
also links its own Markdown through `<link rel="alternate"
type="text/markdown">` (`starlight/Head.astro`), replacing the previous link
that pointed at the whole project corpus.
2. **A Cloudflare Worker negotiates.** `worker/` deploys a dependency-free
Worker on the zone. On `Accept: text/markdown` it serves the page's Markdown
sibling, falling back to `/llms-full.txt` for pages without one, with
`Content-Type: text/markdown; charset=utf-8`, `Vary: accept` and
`x-markdown-tokens`. Every other request is passed straight through to GitHub
Pages, so HTML stays the default and nothing else changes.

## Consequences

- The `markdownNegotiation` check can pass on the Free plan, with no plan change.
- This is the **first runtime component** in an otherwise build-time-static
architecture. It is deliberately tiny (no dependencies), sits only in front of
the origin, and changes no origin behaviour; but it is a new deploy surface
(the `worker` job in `.github/workflows/deploy.yml`, `wrangler.toml`) and a new
thing to keep working.
- **The Worker is the designated home for future edge work.** Anything that needs
a request header read or a response header set — another `.well-known` media
type (as in ADR 0017), content negotiation, or cached HTML headers GitHub Pages
cannot express — is added to `worker/src/index.ts` and covered by
`worker/tests/`. It is never bolted onto the build, which only writes files, and
never assumed of the static host.
- The Worker is deployed **only when `CLOUDFLARE_API_TOKEN` and
`CLOUDFLARE_ACCOUNT_ID` are configured**, so the site and its CI keep working
without it.
- If the zone ever moves to a paid plan, the managed Markdown for Agents feature
can replace the Worker; the per-page Markdown siblings remain useful either way.

## Alternatives considered

- **Do nothing / rely on `llms-full.txt`.** Cheapest, but there is no per-page
representation and the negotiation check stays red. Rejected.
- **Cloudflare managed Markdown for Agents.** Zero code, but requires a paid
plan. Unavailable; kept as the documented upgrade path.
- **A Worker that converts HTML to Markdown at request time.** Avoids build
changes, but needs a converter library in the Worker and produces messier
output than the source Markdown. Rejected in favour of build-time Markdown.
64 changes: 64 additions & 0 deletions docs/decisions/0017-api-catalog.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# ADR 0017 — An RFC 9727 API catalog for a site with no hosted APIs

- Status: accepted
- Date: 2026-04-12

## Context

RFC 9727 defines `/.well-known/api-catalog`: a machine-readable **linkset**
(RFC 9264) that helps automated clients discover what an origin publishes.
Agent-readiness tooling checks for it, and the media type must be
`application/linkset+json`.

Two facts shaped the decision:

1. **Purview publishes no HTTP APIs.** The products are .NET libraries — source
generators, validation, containers, observability, an event-sourcing
framework — not hosted services. There is no REST API, and therefore no
OpenAPI document, to point `service-desc` at in the usual sense.
2. **The name is narrower than the standard.** RFC 9727 is explicitly *not*
limited to REST APIs: its useful relations (`describedby`, `sitemap`,
`alternate`, `license`) point at resources that are not APIs at all. Read
plainly, `/.well-known/api-catalog` is *an index of every machine-readable
thing on the origin*.

purview.dev *does* publish a rich machine-readable surface: `/discover.json`,
`/llms.txt` and `/llms-full.txt`, the partitioned sitemaps, per-project
`llms-full.txt` bundles, and per-page Markdown (ADR 0016).

## Decision

Publish `/.well-known/api-catalog` as an index of that surface, built from the
catalogue at build time (`lib/discovery/api-catalog.ts`):

- **Origin entry** (`anchor: https://purview.dev/`) — `service-desc` →
`/discover.json`, `service-doc` → `/docs/`, `describedby` → `/llms.txt`,
`sitemap` → `/sitemap-index.xml`.
- **One entry per documented product** — `anchor` → the project page,
`service-desc` → the product's `llms-full.txt` (the machine-readable
description of its public interface), `service-doc` → `/docs/<id>/`.

Every URL is on the canonical origin, and `discovery:validate` fails the build on
a missing, malformed or off-origin catalog.

The media type is the one thing the static origin cannot set: a file host types
an extension-less file as `application/octet-stream`. The Cloudflare Worker
(ADR 0016) sets `Content-Type: application/linkset+json` for the path.

## Consequences

- The catalog is generated, never hand-maintained, so it cannot drift from the
catalogue, and it is covered by the unit, dist and discovery checks.
- It truthfully describes what the origin serves without inventing REST APIs.
If Purview ever ships a hosted API, its OpenAPI document becomes the
`service-desc` of a new entry and nothing else changes.
- Passing the readiness check depends on the Worker being deployed (ADR 0016);
the static file alone carries the wrong media type.

## Alternatives considered

- **List the products as REST APIs.** Fabrication: there are none. Rejected.
- **Ship no catalog.** Honest but leaves a standards-track discovery surface
unimplemented for a site whose whole purpose is discovery. Rejected.
- **A hand-written static file.** Simple, but it would drift from the catalogue
and could point at pages that no longer exist. Rejected in favour of generation.
80 changes: 80 additions & 0 deletions docs/decisions/0018-link-headers.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# ADR 0018 — Discovery `Link` headers on the homepage

- Status: accepted
- Date: 2026-04-12

## Context

[RFC 8288](https://www.rfc-editor.org/rfc/rfc8288) defines the HTTP `Link`
response header: the same mechanism as `<link rel="…">` in HTML, except it
travels with the response itself, so a client can discover related resources
without downloading or parsing a body. It even works on responses that have no
HTML at all (`application/json`, a redirect, a `304`).

[RFC 9727 §3](https://www.rfc-editor.org/rfc/rfc9727#section-3) gives that
mechanism a standard relation for API discovery — `api-catalog`, whose target is
the origin's `/.well-known/api-catalog`. Section 3.1 allows additional
*registered* relations alongside it to describe the same resource.

Agent-readiness tooling (isitagentready.com) checks the homepage for `Link`
headers with registered relations and fails the whole "discoverability" group
when they are missing. The site already publishes every target — the RFC 9727
catalog (ADR 0017), `/discover.json`, `/llms.txt`, `/docs/`, the sitemap index —
but a static GitHub Pages host cannot emit a response header, so nothing
advertises them in the one place an agent looks first.

This is the same constraint ADR 0016 already solved for content negotiation and
the linkset media type: the origin is a file host, so header work belongs in the
edge Worker.

## Decision

Attach discovery `Link` headers to the homepage response in the Cloudflare
Worker (`worker/`), which already fronts the zone.

1. **A small, pure module owns the links.** `worker/src/links.ts` defines the
homepage links as data and renders each as an RFC 8288 field value. Only
IANA-registered relation types are used, and every target is root-relative:

| `rel` | target | `type` |
| ------------- | ------------------------ | ------------------------- |
| `api-catalog` | `/.well-known/api-catalog` | `application/linkset+json` |
| `service-desc`| `/discover.json` | `application/json` |
| `service-doc` | `/docs/` | `text/html` |
| `describedby` | `/llms.txt` | `text/markdown` |
| `sitemap` | `/sitemap-index.xml` | `application/xml` |

The set mirrors the origin entry of the RFC 9727 API catalog
(`src/src/lib/discovery/api-catalog.ts`), so the header and the catalog cannot
describe different surfaces.

2. **The Worker adds the headers, preserving the origin response.** For `GET`
and `HEAD` on the homepage (`/` or `/index.html`) the Worker clones the
origin response and appends one `Link` header per entry — on the HTML page and
on the negotiated Markdown alike. Every other path is passed through
untouched, exactly as before.

## Consequences

- `checks.discoverability.linkHeaders` can pass without changing the origin or
the build: the homepage advertises its machine-readable surface in a header an
agent can read with `HEAD /`.
- The links are data in one module (`worker/src/links.ts`), unit-tested without
the Cloudflare runtime, so extending them to more pages later is a data change.
- Like the rest of the Worker, this only takes effect when it is deployed
(ADR 0016); the static site alone cannot set the header. The catalog, the
sitemap and the LLM resources stay correct either way.
- The header and the HTML are consistent by construction: both describe the same
generated surface, and the header reuses the catalog's own targets.

## Alternatives considered

- **Cloudflare Transform Rules (Modify Response Header).** No code and no
deploy of ours, but it duplicates the link set in zone configuration that
lives outside the repository and its review/CI, and it cannot read the
catalogue. Rejected in favour of the Worker the repo already owns (ADR 0016).
- **HTML `<link>` tags only.** Already present for per-page Markdown, but they
require parsing a body and are absent on non-HTML responses. Rejected as a
substitute for the header; kept because they are the HTML-side equivalent.
- **Emit the header from the build.** A static file host writes files, not
response headers, so the build cannot do it. Rejected.
Loading
Loading