diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index c7c0e72..e989f05 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -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 diff --git a/AGENTS.md b/AGENTS.md index 09b8720..7df67a5 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -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. @@ -193,4 +201,9 @@ src/src/data/projects/.yml` against a clone of its repository. | Live examples | `src/src/pages/examples/.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` | diff --git a/README.md b/README.md index a8075b2..c9dff95 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/docs/decisions/0016-markdown-for-agents.md b/docs/decisions/0016-markdown-for-agents.md new file mode 100644 index 0000000..3828d29 --- /dev/null +++ b/docs/decisions/0016-markdown-for-agents.md @@ -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//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 `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 `` (`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. diff --git a/docs/decisions/0017-api-catalog.md b/docs/decisions/0017-api-catalog.md new file mode 100644 index 0000000..c9a7de2 --- /dev/null +++ b/docs/decisions/0017-api-catalog.md @@ -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//`. + +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. diff --git a/docs/decisions/0018-link-headers.md b/docs/decisions/0018-link-headers.md new file mode 100644 index 0000000..15506af --- /dev/null +++ b/docs/decisions/0018-link-headers.md @@ -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 `` 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 `` 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. diff --git a/docs/decisions/0019-auth-md.md b/docs/decisions/0019-auth-md.md new file mode 100644 index 0000000..28a2fe0 --- /dev/null +++ b/docs/decisions/0019-auth-md.md @@ -0,0 +1,68 @@ +# ADR 0019 — `/auth.md` for a site with no login + +- Status: accepted +- Date: 2026-04-12 + +## Context + +The emerging Auth.md convention asks a service to publish `/auth.md`: a +Markdown document describing how an automated agent registers and authenticates +with the origin. Agent-readiness tooling checks for the file and for an H1 +heading that names `auth.md`. + +`purview.dev` is a **fully static GitHub Pages site with no login**: no accounts, +no hosted API, no protected resource and therefore no credentials to issue +(ADR 0001). It does publish a rich *public* machine-readable surface — `llms.txt` +/ `llms-full.txt`, `discover.json`, the RFC 9727 API catalog and per-page +Markdown (ADR 0016, ADR 0017) — but none of it is gated. + +For an origin like this, the only truthful "registration" document is one that +says there is nothing to register. Publishing OAuth Protected Resource Metadata, +an authorization-server document or an `agent_auth` block would be fabrication: +there is no authorization server behind it. + +## Decision + +Generate `/auth.md` at build time from `src/src/lib/discovery/auth-md.ts` and +write it from the discovery integration (exactly like `robots.txt` and the API +catalog). It is **self-contained**, because no OAuth metadata exists to reference: + +- it names the **agent audience** (crawlers, retrieval/grounding agents, + documentation and coding assistants); +- it states plainly that there is **no registration or provisioning endpoint** + (and explicitly that there is no `POST /agent/auth` to probe); +- it lists `anonymous` as the only supported method; +- it explains that **credential use does not apply** and that the content policy + lives in `robots.txt` (Content Signals); +- it points at the machine-readable surface an agent *can* use without a + credential. + +The document is validated by `discovery:validate` (present, non-empty, its first +H1 contains `auth.md`), required by `check-generated`, and covered by unit and +dist tests. The edge Worker serves `/auth.md` with +`Content-Type: text/markdown; charset=utf-8` — a static host may type a `.md` +file as `text/plain` — and, more generally, never re-negotiates a resource that +is already Markdown (ADR 0016). + +## Consequences + +- The `authMd` readiness check can pass with an honest document, and agents get + an accurate answer ("no credential needed") instead of a 404 or a fabricated + OAuth surface. +- One more generated artifact with a validator and tests to maintain, and one + more path the Worker special-cases. +- If Purview ever ships a hosted API with OAuth, this document grows a + `service-desc`-style pointer to the Protected Resource Metadata and an + `agent_auth` block; nothing else in the discovery layer changes. Until then the + absence is explicit rather than implied. + +## Alternatives considered + +- **Do nothing.** The readiness check fails and an agent has no authoritative + answer about authentication. Rejected. +- **Publish OAuth Protected Resource Metadata / authorization-server metadata.** + Fabrication: there is no authorization server, no protected resource and no + scopes. A machine client would chase links that resolve to nothing. Rejected. +- **A hand-written `src/public/auth.md`.** Simpler, but it would sit outside the + discovery model, its validator and its tests, and could drift from the content + policy and the resource list. Rejected in favour of generation. diff --git a/docs/discovery.md b/docs/discovery.md index eb1e37b..5f696cc 100644 --- a/docs/discovery.md +++ b/docs/discovery.md @@ -22,11 +22,14 @@ release cache). **There is no hand-maintained list of URLs.** | --- | --- | --- | | Sitemap index | `/sitemap-index.xml` | `purview-discovery` Astro integration | | Child sitemaps | `/sitemaps/pages.xml`, `/sitemaps/projects.xml`, `/sitemaps/llms.xml` | integration | -| Crawler policy | `/robots.txt` | integration (`lib/discovery/robots.ts`) | +| Crawler policy + Content Signals | `/robots.txt` | integration (`lib/discovery/robots.ts`) | | Site map (JSON) | `/discover.json` | integration (`lib/discovery/manifest.ts`) | | Root LLM content | `/llms.txt`, `/llms-small.txt`, `/llms-full.txt` | `starlight-llms-txt` | | Per-project LLM content | `/projects//llms.txt`, `/projects//llms-full.txt` | integration (`lib/discovery/project-llms.ts`) | | Per-version LLM content | `/projects///llms.txt`, `/projects///llms-full.txt` | integration (`lib/discovery/project-llms.ts`) | +| Per-page Markdown | `/docs//…/index.md` (a sibling of each documentation page) | integration (`lib/discovery/emit.ts`) | +| API catalog | `/.well-known/api-catalog` (RFC 9727 linkset) | integration (`lib/discovery/api-catalog.ts`) | +| Agent registration | `/auth.md` (Auth.md; states there is no login or registration) | integration (`lib/discovery/auth-md.ts`) | | IndexNow key file | `/.txt` (written from the secret) | deploy workflow via `bun run discovery:key` | | Internal deployment state | `src/.cache/discovery/state.json` (never published) | integration | @@ -92,6 +95,29 @@ that produced it (`src/src/lib/discovery/last-modified.ts`): The deploy workflow checks out full history (`fetch-depth: 0`) so (1) is accurate in CI. +### Content Signals + +`robots.txt` declares a [Content Signals](https://contentsignals.org/) policy +(`draft-romm-aipref-contentsignals`) so consumers never have to guess a default: + +``` +User-agent: * +Allow: / +Content-Signal: search=yes, ai-input=yes, ai-train=yes +``` + +Purview's policy is **fully open** — the three categories (`search`, `ai-input`, +`ai-train`) are all `yes` — so the content may be indexed for search, used as +input to AI models (RAG/grounding) and used to train models. This matches the +crawler policy above (AI search crawlers are explicitly welcome) and the +machine-readable documentation the site already publishes (`llms.txt`, the +per-project `llms*.txt` bundles). The signal is emitted once, in the site-wide +`User-agent: *` group. `discovery:validate` fails the build if the declaration is +missing or omits any of the three categories. + +To change the policy, edit `src/src/lib/discovery/robots.ts` — the generated file +is never hand-edited. + ## Commands ```shell @@ -108,9 +134,11 @@ bun run discovery:indexnow --dry-run --verbose # include the URL lists `discovery:validate` runs as part of `just validate` and `bun run ci:build`, and fails the build on: missing/malformed sitemaps, non-absolute or off-origin URLs, -duplicate canonicals, a `robots.txt` that does not advertise the sitemap, a -`discover.json` that references unknown projects, missing per-project LLM -resources, and development URLs in production output. +duplicate canonicals, a `robots.txt` that does not advertise the sitemap or +declare a Content-Signal policy for `search`, `ai-input` and `ai-train`, a +`discover.json` that references unknown projects, an API catalog that is missing +or off-origin, missing per-project LLM resources, and development URLs in +production output. The IndexNow key file is a **deploy-time** artifact: the build never sees the key, so the build pipeline does not require it. The deploy workflow runs @@ -194,7 +222,111 @@ indexes, so its visibility follows the Google/Bing strategy. `OAI-SearchBot` is explicitly permitted in `robots.txt`. HTML documentation and the LLM resources are reachable through ordinary links. There is no supported "LLM submission API", so none is invented; `llms.txt` is an additional -representation, not a guarantee of indexing. +representation, not a guarantee of indexing. The [Content +Signals](#content-signals) policy is fully open (`search`, `ai-input` and +`ai-train` are all `yes`), so AI systems may also use the content as model input +and for training. + +### Markdown for Agents (content negotiation) + +An agent can ask for any page in Markdown with `Accept: text/markdown` and get +`Content-Type: text/markdown; charset=utf-8` (with `Vary: accept`), while a +browser keeps getting HTML. Two pieces make that work (ADR 0016): + +1. **Per-page Markdown, built.** Every aggregated documentation page is also + published as `index.md` (for example + `/docs/zodsharp/core-concepts/index.md`) from the same mirror file the HTML is + rendered from (`lib/discovery/page-markdown.ts`, `emit.ts`), and each docs page + links it with ``. The + `llms-full.txt` bundles above remain the *corpus* view — the concatenation of a + project's documentation, not one page. +2. **An edge Worker negotiates.** The origin is GitHub Pages (a file host cannot + vary a response by request header) and Cloudflare's managed *Markdown for + Agents* is Pro/Business/Enterprise only, so neither can negotiate on the Free + plan. `worker/` is a dependency-free Cloudflare Worker on the `purview.dev/*` + route: on `Accept: text/markdown` it serves the page's Markdown sibling + (falling back to `/llms-full.txt`), and passes every other request straight + through to the origin untouched. It reports a rough `x-markdown-tokens` count. + It also sets the RFC 9727 media type on `/.well-known/api-catalog` (below), + which a static host cannot set for an extension-less file. + +The Worker is deployed as part of the main deployment +(`.github/workflows/deploy.yml`, the `worker` job) from the `CLOUDFLARE_API_TOKEN` +/ `CLOUDFLARE_ACCOUNT_ID` secrets; the deploy is skipped when they are unset, so +the site and its CI work without it. Verify: + +```shell +curl -sI -H "Accept: text/markdown" https://purview.dev/docs/zodsharp/core-concepts/ +# expect `content-type: text/markdown; charset=utf-8` and `vary: accept` +``` + +If the zone ever moves to a paid plan, the managed Markdown for Agents feature +can replace the Worker; the per-page Markdown siblings stay useful either way. + +### API catalog (RFC 9727) + +`/.well-known/api-catalog` is an RFC 9727 [linkset](https://www.rfc-editor.org/rfc/rfc9264) — +a machine-readable index of the resources an origin publishes. Despite the name it +is not limited to REST APIs: the Purview products are .NET libraries, not hosted +services, so the catalogue indexes what this origin serves and can describe +mechanically. `lib/discovery/api-catalog.ts` builds it from the catalogue: + +- one entry for the origin (`https://purview.dev/`): `service-desc` → + `/discover.json`, `service-doc` → `/docs/`, `describedby` → `/llms.txt`, + `sitemap` → `/sitemap-index.xml`; +- one entry per documented product: `service-desc` → the product's + `llms-full.txt` (its machine-readable documentation), `service-doc` → + `/docs//`. + +Every URL is on the canonical origin, and `discovery:validate` fails the build if +the file is missing or points anywhere off-origin (ADR 0017). The document must be +served as `application/linkset+json`, which a static host cannot set for an +extension-less file — the edge Worker sets it. + +### Discovery `Link` headers (RFC 8288 / RFC 9727 §3) + +The homepage response advertises the machine-readable surface above in HTTP +[`Link`](https://www.rfc-editor.org/rfc/rfc8288) headers, so an agent can discover +it with `HEAD /` and without parsing a body: + +``` +Link: ; rel="api-catalog"; type="application/linkset+json" +Link: ; rel="service-desc"; type="application/json" +Link: ; rel="service-doc"; type="text/html" +Link: ; rel="describedby"; type="text/markdown" +Link: ; rel="sitemap"; type="application/xml" +``` + +A static file host cannot set a response header, so the edge Worker adds them +(`worker/src/links.ts`, ADR 0018). Only IANA-registered relation types are used, +the targets are root-relative, and they mirror the origin entry of the RFC 9727 +catalog above, so the header and the catalog describe the same surface. The +header rides on both the HTML homepage and its negotiated Markdown; every other +path is passed through untouched. Verify: + +```shell +curl -sI https://purview.dev/ | grep -i '^link:' +``` + +### Agent registration (auth.md) + +`/auth.md` is the Auth.md agent-registration document. purview.dev is a public +static site with **no login**, so the document is deliberately self-contained: it +names the agent audience and states that there is no registration or provisioning +endpoint, no OAuth Protected Resource Metadata or authorization-server metadata, +no `agent_auth` block and no credentials — the only supported method is +`anonymous`. It also points agents at the machine-readable surface they can use +without a credential (`llms.txt`, `discover.json`, the API catalog, per-page +Markdown, the sitemaps). + +It is generated (`lib/discovery/auth-md.ts`, ADR 0019), served as +`text/markdown` by the edge Worker (a static host may type a `.md` file as +`text/plain`), and `discovery:validate` fails the build when it is missing or its +H1 does not name `auth.md`. Verify: + +```shell +curl -s https://purview.dev/auth.md | head -n 1 # expect: # auth.md +``` ## Local development @@ -212,7 +344,8 @@ bun run discovery:indexnow --dry-run Automated (nothing to do per deploy): - [x] Sitemap index + child sitemaps generated -- [x] `robots.txt` generated and references the sitemap +- [x] `robots.txt` generated, references the sitemap, and declares the Content-Signal policy +- [x] `/.well-known/api-catalog` generated (RFC 9727 linkset) - [x] Root `llms.txt` / `llms-full.txt` generated - [x] Per-project `llms.txt` / `llms-full.txt` generated - [x] Per-version `llms.txt` / `llms-full.txt` generated for every published channel @@ -222,6 +355,10 @@ Automated (nothing to do per deploy): - [x] `discovery:validate` enforced in CI - [x] `check:seo` enforced in CI (titles, canonicals, one H1, project-named docs titles, valid JSON-LD) — ADR 0015 +- [x] Homepage discovery `Link` headers emitted by the edge Worker (RFC 8288 / + RFC 9727 §3) — ADR 0018 +- [x] `/auth.md` generated for a no-login site (Auth.md; states there is nothing + to register) — ADR 0019 One-time (operator): @@ -242,6 +379,15 @@ One-time (operator): (`https://purview.dev/projects/zodsharp/llms.txt`) - [ ] Verify a representative versioned LLM resource while a second channel is published (`https://purview.dev/projects/zodsharp/prerelease/llms.txt`) +- [ ] Set `CLOUDFLARE_API_TOKEN` / `CLOUDFLARE_ACCOUNT_ID` so the Markdown for + Agents Worker deploys (ADR 0016) +- [ ] Verify `Accept: text/markdown` negotiation on a live page +- [ ] Verify `https://purview.dev/.well-known/api-catalog` returns + `application/linkset+json` (the Worker sets the type; ADR 0017) +- [ ] Verify the homepage `Link` headers (`curl -sI https://purview.dev/`; the + Worker adds them; ADR 0018) +- [ ] Verify `/auth.md` (`curl -s https://purview.dev/auth.md | head -n 1`; the + Worker serves it as Markdown; ADR 0019) ## Security diff --git a/justfile b/justfile index cb0760a..f27bb2e 100644 --- a/justfile +++ b/justfile @@ -58,6 +58,10 @@ typecheck: test: bun run test +# Run the Markdown-for-agents Worker unit tests (worker/). +worker-test: + bun test worker/tests + # Assert the built output (llms files, sitemap, robots, no secrets). test-dist: bun run test:dist @@ -136,5 +140,5 @@ clean: bun run clean # Authoritative validation: run everything needed to prove the site is safe to merge. -validate: format-check lint typecheck test check-assets check-projects build discovery-validate check-seo check-links check-generated test-dist +validate: format-check lint typecheck test worker-test check-assets check-projects build discovery-validate check-seo check-links check-generated test-dist @echo "Validation passed." diff --git a/package.json b/package.json index 046b2f0..f5bfe08 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "purview-dev", - "version": "0.11.1", + "version": "0.12.0", "private": true, "description": "Purview-Dev public website and unified documentation portal (workspace root).", "license": "MIT", diff --git a/src/config/discovery-integration.ts b/src/config/discovery-integration.ts index df98791..9fa7dcc 100644 --- a/src/config/discovery-integration.ts +++ b/src/config/discovery-integration.ts @@ -16,6 +16,7 @@ import { emitDiscoveryArtifacts } from '../src/lib/discovery/emit'; * * - `/sitemap-index.xml` + `/sitemaps/{pages,projects,llms}.xml` * - `/robots.txt` + * - `/auth.md` (agent registration: states there is nothing to register) * - `/discover.json` (Purview-specific; see `docs/discovery.md`) * - `/projects//llms.txt` + `/projects//llms-full.txt` * - `.cache/discovery/state.json` (internal, never published) diff --git a/src/scripts/check-generated.ts b/src/scripts/check-generated.ts index 58e8604..b07fda3 100644 --- a/src/scripts/check-generated.ts +++ b/src/scripts/check-generated.ts @@ -311,6 +311,7 @@ async function run(): Promise { requireDistFile('sitemaps/llms.xml'); requireDistFile('discover.json'); requireDistFile('robots.txt'); + requireDistFile('auth.md'); validateProjectLlmsBundles(); validateProjectAssets(); diff --git a/src/scripts/discovery/validate.ts b/src/scripts/discovery/validate.ts index aab9031..8f6fa2a 100644 --- a/src/scripts/discovery/validate.ts +++ b/src/scripts/discovery/validate.ts @@ -6,6 +6,8 @@ import { resolve } from 'node:path'; import { documentedProjects, loadDiscoveryContext } from '../../src/lib/discovery/resources'; import { DISCOVERY_MANIFEST_SCHEMA_VERSION } from '../../src/lib/discovery/types'; import { + API_CATALOG_PATH, + AUTH_MD_PATH, DISCOVER_JSON_PATH, ROBOTS_PATH, SITEMAP_INDEX_PATH, @@ -26,8 +28,9 @@ import { loadProjects } from '../../src/lib/manifest/load'; * Post-build validation of the generated discovery artifacts. It fails CI for * genuine discovery errors (missing files, malformed XML, non-absolute or * off-origin URLs, duplicate canonicals, a robots.txt that does not advertise - * the sitemap, a discover.json that references projects that do not exist, or - * development URLs leaking into production output). + * the sitemap or declare a Content-Signal policy, an API catalog that is not a + * valid on-origin linkset, a discover.json that references projects that do not + * exist, or development URLs leaking into production output). */ const DEV_HOST_PATTERN = /https?:\/\/(?:localhost|127\.0\.0\.1|0\.0\.0\.0|\[::1\])(?::\d+)?/i; @@ -85,6 +88,105 @@ export function validateIndexNowKeyFile( return []; } +/** + * Validate the Content Signals declaration in `robots.txt`. + * + * The site must declare a preference for each of the three categories — + * `search`, `ai-input` and `ai-train` — so consumers never have to guess a + * default (https://contentsignals.org/). Returns the error messages to report: + * empty when every category is declared, otherwise one message per problem. + */ +export function validateRobotsContentSignal(robots: string): string[] { + const contentSignal = /Content-Signal:([^\n]+)/i.exec(robots); + if (!contentSignal) { + return ['robots.txt does not declare a Content-Signal policy.']; + } + const directives = contentSignal[1]?.toLowerCase() ?? ''; + const errors: string[] = []; + for (const category of ['search', 'ai-input', 'ai-train']) { + if (!new RegExp(`${category}\\s*=\\s*(?:yes|no)\\b`).test(directives)) { + errors.push(`robots.txt Content-Signal does not declare a value for "${category}".`); + } + } + return errors; +} + +/** The RFC 9727 relations whose values are arrays of links with `href`s. */ +const API_CATALOG_RELATIONS = [ + 'service-desc', + 'service-doc', + 'describedby', + 'sitemap', + 'alternate', + 'status', +] as const; + +/** + * Validate the RFC 9727 API catalog (`/.well-known/api-catalog`). + * + * It must be JSON with a non-empty `linkset` array; every entry needs an + * `anchor`, and every link an entry carries must stay on the canonical origin — + * a catalogue that points off-origin, or at nothing, is worse than none. The + * media type (`application/linkset+json`) is set by the edge Worker and cannot be + * checked from the built files, so it is asserted where it can be: `worker/`. + */ +export function validateApiCatalog(content: string, origin: string): string[] { + let parsed: unknown; + try { + parsed = JSON.parse(content); + } catch { + return ['api-catalog is not valid JSON.']; + } + const linkset = (parsed as { linkset?: unknown }).linkset; + if (!Array.isArray(linkset) || linkset.length === 0) { + return ['api-catalog has no linkset entries.']; + } + const errors: string[] = []; + linkset.forEach((raw, index) => { + const entry = raw as Record; + const anchor = entry.anchor; + if (typeof anchor !== 'string' || anchor.length === 0) { + errors.push(`api-catalog entry ${index} has no anchor.`); + } else if (!isCanonicalUrl(anchor, origin)) { + errors.push(`api-catalog anchor is off-origin: ${anchor}`); + } + for (const relation of API_CATALOG_RELATIONS) { + const links = entry[relation]; + if (!Array.isArray(links)) { + continue; + } + for (const link of links) { + const href = (link as { href?: unknown }).href; + if (typeof href !== 'string' || !isCanonicalUrl(href, origin)) { + errors.push(`api-catalog ${relation} href is off-origin: ${String(href)}`); + } + } + } + }); + return errors; +} + +/** + * Validate the agent-registration document (`/auth.md`). + * + * purview.dev is a static site with no login, so the document exists to state + * that plainly. It must be non-empty Markdown whose first H1 contains `auth.md` + * — the one structural requirement the Auth.md convention makes. + */ +export function validateAuthMd(content: string): string[] { + if (content.trim().length === 0) { + return ['auth.md is empty.']; + } + const headings = [...content.matchAll(/^#[ \t]+(.+)$/gm)].map((match) => match[1]?.trim() ?? ''); + if (headings.length === 0) { + return ['auth.md has no H1 heading.']; + } + if (!(headings[0] ?? '').toLowerCase().includes('auth.md')) { + return ['auth.md H1 heading does not contain "auth.md".']; + } + return []; +} + export function validateDiscovery( dist = resolve('dist'), options: DiscoveryValidationOptions = {}, @@ -179,6 +281,33 @@ export function validateDiscovery( if (!/User-agent:\s*QwantBot/i.test(robots)) { fail('robots.txt does not explicitly permit QwantBot.'); } + // Content Signals (https://contentsignals.org/): every category must be + // declared so consumers never have to guess a default. + for (const error of validateRobotsContentSignal(robots)) { + fail(error); + } + } + + // --- api-catalog (RFC 9727) --------------------------------------------- + const apiCatalog = readDist(API_CATALOG_PATH); + if (!apiCatalog) { + fail(`Missing API catalog: ${API_CATALOG_PATH}`); + } else { + scanForDevUrls('api-catalog', apiCatalog); + for (const error of validateApiCatalog(apiCatalog, origin)) { + fail(error); + } + } + + // --- auth.md (agent registration; none, for a static site) -------------- + const authMd = readDist(AUTH_MD_PATH); + if (!authMd) { + fail(`Missing auth.md: ${AUTH_MD_PATH}`); + } else { + scanForDevUrls('auth.md', authMd); + for (const error of validateAuthMd(authMd)) { + fail(error); + } } // --- root llms files ----------------------------------------------------- diff --git a/src/src/components/starlight/Head.astro b/src/src/components/starlight/Head.astro index e4f482c..3a48a67 100644 --- a/src/src/components/starlight/Head.astro +++ b/src/src/components/starlight/Head.astro @@ -3,6 +3,7 @@ import DefaultHead from '@astrojs/starlight/components/Head.astro'; import { readDocsManifest } from '~/lib/docs/aggregate'; import { CHANNEL_LABELS, channelBasePath, channelDisplayLabel } from '~/lib/docs/channels'; import { docSectionTrail } from '~/lib/docs/sidebar'; +import { docsPageMarkdownPath } from '~/lib/discovery/page-markdown'; import { projectChannelLlmsFullUrl } from '~/lib/discovery/urls'; import { getProjects } from '~/lib/manifest/load'; import { docsIndexTitle, docsPageTitle } from '~/lib/seo'; @@ -31,13 +32,21 @@ const fullUrl = sourceProject === undefined ? null : projectChannelLlmsFullUrl(sourceProject, channel?.id ?? 'live', channel?.default ?? true); +// Prefer the page's own Markdown sibling — the page, not the whole project +// corpus — and fall back to the corpus when the page is not in the manifest +// (so the link never points at nothing). +const pageMarkdownUrl = + sourceProject !== undefined && page && channel ? + absoluteUrl(docsPageMarkdownPath(sourceProject, channel.id, channel.default, page.slug)) + : null; +const markdownUrl = pageMarkdownUrl ?? fullUrl; const alternateLinks = - hasMachineReadable && fullUrl ? + hasMachineReadable && markdownUrl ? [ { - href: fullUrl, + href: markdownUrl, type: 'text/markdown', - title: `${data?.title ?? sourceProject} — machine-readable documentation`, + title: `${data?.title ?? sourceProject} — Markdown`, }, ] : []; diff --git a/src/src/lib/discovery/api-catalog.ts b/src/src/lib/discovery/api-catalog.ts new file mode 100644 index 0000000..e7c305a --- /dev/null +++ b/src/src/lib/discovery/api-catalog.ts @@ -0,0 +1,85 @@ +import { + canonical, + discoverJsonUrl, + docsUrl, + projectLlmsFullUrl, + projectPageUrl, + rootLlmsUrl, + sitemapIndexUrl, +} from './urls'; + +/** + * The `/.well-known/api-catalog` document (RFC 9727). + * + * Despite the name, an API catalog is not limited to REST APIs: it is a + * [linkset](https://www.rfc-editor.org/rfc/rfc9264) — a machine-readable index of + * the resources an origin publishes. The Purview products are .NET libraries + * rather than hosted HTTP services, so the catalogue describes what this origin + * genuinely serves and can describe mechanically: + * + * - one entry for the origin itself, pointing at the site-wide machine-readable + * surface (`/discover.json`, `/llms.txt`, the sitemap index, the docs portal); + * - one entry per documented product, whose public interface is described by the + * product's `llms-full.txt` (`service-desc`) and documented at `/docs//` + * (`service-doc`). + * + * Every URL is on the canonical origin, so the document satisfies the RFC's + * "every URL the catalogue points at is from the same origin" expectation. The + * media type is `application/linkset+json`; a static host serves an + * extension-less file as `application/octet-stream`, so the edge Worker sets the + * header (see `worker/`). + */ + +export interface ApiCatalogLink { + href: string; + type?: string; +} + +export interface ApiCatalogEntry { + anchor: string; + 'service-desc'?: ApiCatalogLink[]; + 'service-doc'?: ApiCatalogLink[]; + describedby?: ApiCatalogLink[]; + sitemap?: ApiCatalogLink[]; + alternate?: ApiCatalogLink[]; + status?: ApiCatalogLink[]; +} + +export interface ApiCatalog { + linkset: ApiCatalogEntry[]; +} + +const HTML = 'text/html'; +const MARKDOWN = 'text/markdown'; +const JSON_TYPE = 'application/json'; +const XML = 'application/xml'; + +/** The origin's own machine-readable surface. */ +function siteEntry(): ApiCatalogEntry { + return { + anchor: canonical('/'), + 'service-desc': [{ href: discoverJsonUrl(), type: JSON_TYPE }], + 'service-doc': [{ href: canonical('/docs/'), type: HTML }], + describedby: [{ href: rootLlmsUrl(), type: MARKDOWN }], + sitemap: [{ href: sitemapIndexUrl(), type: XML }], + }; +} + +/** One documented product: its documentation and machine-readable description. */ +function projectEntry(project: { id: string }): ApiCatalogEntry { + return { + anchor: projectPageUrl(project.id), + 'service-desc': [{ href: projectLlmsFullUrl(project.id), type: MARKDOWN }], + 'service-doc': [{ href: docsUrl(project.id), type: HTML }], + }; +} + +/** The linkset for the given documented projects, origin entry first. */ +export function buildApiCatalog(projects: readonly { id: string }[]): ApiCatalog { + return { linkset: [siteEntry(), ...projects.map(projectEntry)] }; +} + +/** Serialise the API catalog as the build writes it. */ +export function renderApiCatalog(projects: readonly { id: string }[]): string { + return `${JSON.stringify(buildApiCatalog(projects), null, 2)}\n`; +} diff --git a/src/src/lib/discovery/auth-md.ts b/src/src/lib/discovery/auth-md.ts new file mode 100644 index 0000000..de00520 --- /dev/null +++ b/src/src/lib/discovery/auth-md.ts @@ -0,0 +1,67 @@ +/** + * The generated `/auth.md` (the Auth.md agent-registration document). + * + * purview.dev is a **public static site**: no login, no accounts and no hosted + * API (ADR 0001). The Auth.md convention expects a service to describe how an + * agent registers and authenticates; for this origin the honest answer is that + * it does not, so the document exists to say that plainly and to point agents at + * the machine-readable surface they can use without any credential. + * + * It is generated — like `robots.txt` and the RFC 9727 API catalog — so the + * no-registration statement, the content policy and the resource list stay + * consistent with the rest of the site, and it is validated by + * `discovery:validate`. See `docs/decisions/0019-auth-md.md`. + */ +export function renderAuthMd(): string { + return `# auth.md + +Purview-Dev (\`purview.dev\`) is a **public static website**. It has no login, no +user accounts and no hosted API, so there is nothing to authenticate to and no +agent registration to complete. This document is deliberately self-contained: it +states the empty registration surface rather than linking OAuth metadata that +this origin does not publish. + +## Agent audience + +Any automated client — search and AI crawlers, retrieval and grounding agents, +documentation and coding assistants — that reads, indexes or cites the +Purview-Dev catalogue and documentation. + +## Registration and provisioning + +**None.** This origin publishes no protected resource and issues no credentials: + +- no sign-up, accounts or login; +- no agent registration or provisioning endpoint; +- **no \`POST /agent/auth\`** — do not probe it; nothing is created, emailed or + issued; +- no API keys, client registration, tokens or secrets. + +There is no OAuth 2.0 / OIDC authorization server, so no +\`/.well-known/oauth-protected-resource\`, no +\`/.well-known/oauth-authorization-server\` and no \`agent_auth\` block are +published. A request for credentials does not originate from this site. + +## Supported methods + +\`anonymous\` — every resource is public. There is no interactive or agent +registration method to advertise, and assertion-based flows such as ID-JAG or +verified-email do not apply, because there is no protected resource to issue a +credential for. + +## Credential use + +Not applicable — no credentials exist to issue, present or revoke, and none are +ever requested. All content is read anonymously. How the content may be used by +automated systems is declared machine-readably in [robots.txt](/robots.txt) +(Content Signals: \`search=yes, ai-input=yes, ai-train=yes\`). + +## What an agent can use instead (no credentials required) + +- \`/llms.txt\`, \`/llms-full.txt\` — the site's documentation for language models. +- \`/discover.json\` — the machine-readable site map. +- \`/.well-known/api-catalog\` — the RFC 9727 linkset. +- Any page with \`Accept: text/markdown\` — its Markdown representation. +- \`/sitemap-index.xml\` — the sitemaps. +`; +} diff --git a/src/src/lib/discovery/emit.ts b/src/src/lib/discovery/emit.ts index 15f887a..36878c6 100644 --- a/src/src/lib/discovery/emit.ts +++ b/src/src/lib/discovery/emit.ts @@ -5,12 +5,15 @@ import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs'; import { dirname, join, resolve } from 'node:path'; import { DOCS_OUTPUT_DIR } from '../docs/aggregate'; +import { renderApiCatalog } from './api-catalog'; +import { renderAuthMd } from './auth-md'; import { buildDeploymentState, buildDiscoveryManifest, buildManifestProjects, serializeJson, } from './manifest'; +import { docsPageMarkdownPath } from './page-markdown'; import { renderProjectLlms, renderProjectLlmsFull } from './project-llms'; import { buildResources, @@ -22,6 +25,8 @@ import { import { renderRobotsTxt } from './robots'; import { latestLastmod, renderSitemapIndex, renderUrlset } from './sitemap'; import { + API_CATALOG_PATH, + AUTH_MD_PATH, SITEMAP_INDEX_PATH, docsChannelUrl, docsUrl, @@ -94,6 +99,11 @@ export function emitDiscoveryArtifacts(options: EmitOptions): EmitResult { ); write('robots.txt', renderRobotsTxt()); + // RFC 9727 API catalog: an index of the origin's machine-readable surface. + write(API_CATALOG_PATH.replace(/^\//, ''), renderApiCatalog(documentedProjects(ctx))); + // Agent registration (Auth.md): this site has no login, so the document exists + // to say there is nothing to register — see `lib/discovery/auth-md.ts`. + write(AUTH_MD_PATH.replace(/^\//, ''), renderAuthMd()); const manifest = buildDiscoveryManifest({ resources, @@ -158,6 +168,19 @@ export function emitDiscoveryArtifacts(options: EmitOptions): EmitResult { summaryUrl: projectChannelLlmsUrl(project.id, channelId, isDefault), }), ); + // Each page is also published as its own Markdown document, a sibling of + // the built `index.html`, so a `text/markdown` request for one page can be + // answered with that page instead of the whole project corpus. The Worker + // in `worker/` maps a page URL to this sibling (`index.md`). + for (const page of channel?.pages ?? []) { + const content = readPage(page.slug); + if (content) { + write( + docsPageMarkdownPath(project.id, channelId, isDefault, page.slug).replace(/^\//, ''), + content.endsWith('\n') ? content : `${content}\n`, + ); + } + } } } diff --git a/src/src/lib/discovery/page-markdown.ts b/src/src/lib/discovery/page-markdown.ts new file mode 100644 index 0000000..48f6f5b --- /dev/null +++ b/src/src/lib/discovery/page-markdown.ts @@ -0,0 +1,32 @@ +/** + * Per-page Markdown representations of the aggregated documentation. + * + * `llms.txt` / `llms-full.txt` are *corpus* bundles: one document for a whole + * project (or the whole site). They answer "what does this project document", + * not "what does this page say". An agent that requests one URL with + * `Accept: text/markdown` needs the Markdown for *that page*, so every + * aggregated documentation page is also published as its own Markdown document + * at `index.md` (for example `/docs/zodsharp/core-concepts/index.md`). + * + * The Markdown is a sibling of the built `index.html`, written from the exact + * same mirror file the HTML is rendered from, so the two cannot disagree about + * the content. The path scheme (`/index.md`) is the contract the + * Cloudflare Worker in `worker/` relies on to map a page URL to its Markdown; + * change it here and in `worker/src/negotiate.ts` together. + */ + +/** + * Site-relative path of a documentation page's Markdown representation. + * + * `slug` is the page's slug from the docs root (`index` for the landing page), + * `isDefault` selects the channel that owns the canonical `/docs//` URLs. + */ +export function docsPageMarkdownPath( + projectId: string, + channelId: string, + isDefault: boolean, + slug: string, +): string { + const base = isDefault ? `/docs/${projectId}/` : `/docs/${projectId}/${channelId}/`; + return slug === 'index' ? `${base}index.md` : `${base}${slug}/index.md`; +} diff --git a/src/src/lib/discovery/robots.ts b/src/src/lib/discovery/robots.ts index e3fc2d0..8d704c3 100644 --- a/src/src/lib/discovery/robots.ts +++ b/src/src/lib/discovery/robots.ts @@ -11,9 +11,15 @@ import { sitemapIndexUrl } from './urls'; * permitted explicitly, because a general `Allow: /` is not always read as an * affirmative AI-crawler policy. * - **Qwant** (`QwantBot`) is permitted explicitly for the same reason. - * - **Model-training crawlers** are neither permitted nor blocked beyond the - * general `Allow: /`: the site defines no training-specific policy, and - * inventing speculative `User-agent` names is deliberately avoided. + * - **Content Signals** (`https://contentsignals.org/`, IETF + * `draft-romm-aipref-contentsignals`) declare in machine-readable form how + * the content may be used by automated systems. Purview's policy is fully + * open — `search`, `ai-input` and `ai-train` are all `yes` — so the site may + * be indexed for search, used as input to AI models (RAG/grounding) and used + * to train models. The signal is emitted once, in the `User-agent: *` group, + * which is where Content Signals consumers look for a site-wide preference; + * `ai-input`/`ai-train` are not crawler names, so no speculative + * `User-agent` blocks are invented for them. * * The `Sitemap` directive points at the sitemap index, which is what every * crawler above discovers the rest of the site through. @@ -21,11 +27,13 @@ import { sitemapIndexUrl } from './urls'; export function renderRobotsTxt(): string { return [ '# Purview-Dev crawler policy.', - '# Search indexing and AI search crawlers are welcome. No model-training', - '# restrictions are defined; unknown crawlers fall under the "*" section.', + '# Search indexing and AI search crawlers are welcome. The Content-Signal', + '# below declares the site content may be used for search, AI input and', + '# AI training (https://contentsignals.org/).', '', 'User-agent: *', 'Allow: /', + 'Content-Signal: search=yes, ai-input=yes, ai-train=yes', '', '# AI search (ChatGPT Search). Permitted explicitly.', 'User-agent: OAI-SearchBot', diff --git a/src/src/lib/discovery/urls.ts b/src/src/lib/discovery/urls.ts index c2f9894..dd659ed 100644 --- a/src/src/lib/discovery/urls.ts +++ b/src/src/lib/discovery/urls.ts @@ -36,6 +36,10 @@ export const SITEMAP_PROJECTS_PATH = '/sitemaps/projects.xml'; export const SITEMAP_LLMS_PATH = '/sitemaps/llms.xml'; export const DISCOVER_JSON_PATH = '/discover.json'; export const ROBOTS_PATH = '/robots.txt'; +/** RFC 9727 API catalog: an index of the origin's machine-readable resources. */ +export const API_CATALOG_PATH = '/.well-known/api-catalog'; +/** Auth.md agent-registration document: states that there is nothing to register. */ +export const AUTH_MD_PATH = '/auth.md'; export function sitemapIndexUrl(): string { return canonical(SITEMAP_INDEX_PATH); @@ -55,6 +59,12 @@ export function discoverJsonUrl(): string { export function robotsUrl(): string { return canonical(ROBOTS_PATH); } +export function apiCatalogUrl(): string { + return canonical(API_CATALOG_PATH); +} +export function authMdUrl(): string { + return canonical(AUTH_MD_PATH); +} export function rootLlmsUrl(): string { return canonical('/llms.txt'); diff --git a/src/tests/dist/built-output.test.ts b/src/tests/dist/built-output.test.ts index d6bc6b6..5f0b1f6 100644 --- a/src/tests/dist/built-output.test.ts +++ b/src/tests/dist/built-output.test.ts @@ -442,6 +442,28 @@ describe('built SEO outputs', () => { expect(content).toContain('Sitemap: https://purview.dev/sitemap-index.xml'); }); + test('robots.txt declares a Content-Signal policy', () => { + const content = requireBuilt('robots.txt'); + expect(content).toContain('Content-Signal: search=yes, ai-input=yes, ai-train=yes'); + }); + + test('publishes the RFC 9727 API catalog', () => { + const catalog = JSON.parse(requireBuilt('.well-known/api-catalog')) as { + linkset: { anchor?: string }[]; + }; + expect(Array.isArray(catalog.linkset)).toBe(true); + expect(catalog.linkset.length).toBeGreaterThan(1); + expect(catalog.linkset[0]?.anchor).toBe('https://purview.dev/'); + }); + + test('publishes a self-contained auth.md that states there is no login', () => { + const content = requireBuilt('auth.md'); + const h1 = content.match(/^#[ \t]+(.+)$/m)?.[1] ?? ''; + expect(h1.toLowerCase()).toContain('auth.md'); + expect(content).toMatch(/no login/i); + expect(content).toContain('/llms.txt'); + }); + test('discover.json is generated and references the canonical site', () => { const manifest = JSON.parse(requireBuilt('discover.json')) as { schemaVersion: number; diff --git a/src/tests/unit/discovery/discovery-api-catalog.test.ts b/src/tests/unit/discovery/discovery-api-catalog.test.ts new file mode 100644 index 0000000..5eff589 --- /dev/null +++ b/src/tests/unit/discovery/discovery-api-catalog.test.ts @@ -0,0 +1,45 @@ +import { describe, expect, test } from 'bun:test'; + +import { buildApiCatalog, renderApiCatalog } from '../../../src/lib/discovery/api-catalog'; + +const PROJECTS = [{ id: 'zodsharp' }, { id: 'unions' }]; + +describe('API catalog (RFC 9727)', () => { + test('lists the origin first, with its machine-readable surface', () => { + const [site] = buildApiCatalog(PROJECTS).linkset; + expect(site?.anchor).toBe('https://purview.dev/'); + expect(site?.['service-desc']?.[0]?.href).toBe('https://purview.dev/discover.json'); + expect(site?.['service-doc']?.[0]?.href).toBe('https://purview.dev/docs/'); + expect(site?.describedby?.[0]?.href).toBe('https://purview.dev/llms.txt'); + expect(site?.sitemap?.[0]?.href).toBe('https://purview.dev/sitemap-index.xml'); + }); + + test('gives every documented product an anchor, a description and docs', () => { + const catalog = buildApiCatalog(PROJECTS); + expect(catalog.linkset).toHaveLength(PROJECTS.length + 1); + const entry = catalog.linkset.find( + (candidate) => candidate.anchor === 'https://purview.dev/projects/zodsharp/', + ); + expect(entry?.['service-desc']?.[0]?.href).toBe( + 'https://purview.dev/projects/zodsharp/llms-full.txt', + ); + expect(entry?.['service-doc']?.[0]?.href).toBe('https://purview.dev/docs/zodsharp/'); + }); + + test('every entry declares service-desc and service-doc', () => { + for (const entry of buildApiCatalog(PROJECTS).linkset) { + expect(entry['service-desc']?.length).toBeGreaterThan(0); + expect(entry['service-doc']?.length).toBeGreaterThan(0); + } + }); + + test('renders valid JSON on the canonical origin', () => { + const json = renderApiCatalog(PROJECTS); + expect(json.endsWith('\n')).toBe(true); + const parsed = JSON.parse(json) as { linkset: { anchor: string }[] }; + expect(parsed.linkset.length).toBeGreaterThan(0); + for (const entry of parsed.linkset) { + expect(entry.anchor.startsWith('https://purview.dev/')).toBe(true); + } + }); +}); diff --git a/src/tests/unit/discovery/discovery-auth-md.test.ts b/src/tests/unit/discovery/discovery-auth-md.test.ts new file mode 100644 index 0000000..fc999fb --- /dev/null +++ b/src/tests/unit/discovery/discovery-auth-md.test.ts @@ -0,0 +1,41 @@ +import { describe, expect, test } from 'bun:test'; + +import { renderAuthMd } from '../../../src/lib/discovery/auth-md'; + +/** + * `/auth.md` exists for a static site with no login, so the only thing it can + * truthfully describe is the *absence* of a registration surface. These tests + * pin that: the H1 the convention requires, the honest "none" statements, and + * the pointers to the machine-readable surface that needs no credential. + */ +describe('auth.md (agent registration)', () => { + const content = renderAuthMd(); + + test('has an H1 that contains "auth.md"', () => { + const h1 = content.match(/^#[ \t]+(.+)$/m)?.[1] ?? ''; + expect(h1.toLowerCase()).toContain('auth.md'); + }); + + test('states that there is no login, registration or credential', () => { + expect(content).toMatch(/no login/i); + expect(content).toMatch(/no agent registration or provisioning endpoint/i); + expect(content).toContain('`POST /agent/auth`'); + }); + + test('publishes no OAuth metadata and says so explicitly', () => { + expect(content).toContain('`agent_auth` block'); + expect(content).toContain('`/.well-known/oauth-protected-resource`'); + expect(content).toContain('`/.well-known/oauth-authorization-server`'); + }); + + test('points at the machine-readable surface that needs no credentials', () => { + for (const path of ['/llms.txt', '/discover.json', '/.well-known/api-catalog']) { + expect(content).toContain(path); + } + }); + + test('is non-empty Markdown ending with a newline', () => { + expect(content.trim().length).toBeGreaterThan(0); + expect(content.endsWith('\n')).toBe(true); + }); +}); diff --git a/src/tests/unit/discovery/discovery-core.test.ts b/src/tests/unit/discovery/discovery-core.test.ts index 6e8de58..7f3a3b9 100644 --- a/src/tests/unit/discovery/discovery-core.test.ts +++ b/src/tests/unit/discovery/discovery-core.test.ts @@ -3,6 +3,7 @@ import type { DiscoverableResource } from '../../../src/lib/discovery/types'; import { describe, expect, test } from 'bun:test'; import { latestTimestamp, parseGitLogDates } from '../../../src/lib/discovery/last-modified'; +import { renderRobotsTxt } from '../../../src/lib/discovery/robots'; import { renderSitemapIndex, renderUrlset } from '../../../src/lib/discovery/sitemap'; import { canonical, @@ -98,6 +99,23 @@ describe('sitemap generation', () => { }); }); +describe('robots.txt generation', () => { + test('declares the Content-Signal policy for all three categories', () => { + const robots = renderRobotsTxt(); + expect(robots).toContain('Content-Signal: search=yes, ai-input=yes, ai-train=yes'); + // The signal is declared once, in the site-wide "*" group. + expect(robots).toMatch(/User-agent: \*\nAllow: \/\nContent-Signal:/); + }); + + test('permits the search and AI search crawlers and points at the sitemap', () => { + const robots = renderRobotsTxt(); + expect(robots).toContain('User-agent: *'); + expect(robots).toContain('User-agent: OAI-SearchBot'); + expect(robots).toContain('User-agent: QwantBot'); + expect(robots).toContain(`Sitemap: ${sitemapIndexUrl()}`); + }); +}); + describe('last-modified parsing', () => { test('indexes each file by its most recent commit', () => { const output = [ diff --git a/src/tests/unit/discovery/discovery-page-markdown.test.ts b/src/tests/unit/discovery/discovery-page-markdown.test.ts new file mode 100644 index 0000000..9eb6e9f --- /dev/null +++ b/src/tests/unit/discovery/discovery-page-markdown.test.ts @@ -0,0 +1,33 @@ +import { describe, expect, test } from 'bun:test'; + +import { docsPageMarkdownPath } from '../../../src/lib/discovery/page-markdown'; + +/** + * A page's Markdown sibling is what the Markdown-negotiation worker serves, so + * the path scheme is a contract between the build and the worker. These tests + * pin it: `index.md`, with the channel segment mirroring the HTML URL. + */ +describe('docs page Markdown paths', () => { + test('a landing page is the channel base plus index.md', () => { + expect(docsPageMarkdownPath('zodsharp', 'live', true, 'index')).toBe('/docs/zodsharp/index.md'); + expect(docsPageMarkdownPath('zodsharp', 'prerelease', false, 'index')).toBe( + '/docs/zodsharp/prerelease/index.md', + ); + }); + + test('a page mirrors the HTML URL and adds /index.md', () => { + expect(docsPageMarkdownPath('zodsharp', 'live', true, 'core-concepts')).toBe( + '/docs/zodsharp/core-concepts/index.md', + ); + // A nested slug (ADR 0011) stays a path segment. + expect(docsPageMarkdownPath('zodsharp', 'live', true, 'schemas/custom-rules')).toBe( + '/docs/zodsharp/schemas/custom-rules/index.md', + ); + }); + + test('a non-default channel keeps its segment', () => { + expect(docsPageMarkdownPath('zodsharp', 'prerelease', false, 'core-concepts')).toBe( + '/docs/zodsharp/prerelease/core-concepts/index.md', + ); + }); +}); diff --git a/src/tests/unit/discovery/discovery-validate.test.ts b/src/tests/unit/discovery/discovery-validate.test.ts index 2e1d01e..cacb11f 100644 --- a/src/tests/unit/discovery/discovery-validate.test.ts +++ b/src/tests/unit/discovery/discovery-validate.test.ts @@ -1,6 +1,11 @@ import { describe, expect, test } from 'bun:test'; -import { validateIndexNowKeyFile } from '../../../scripts/discovery/validate'; +import { + validateApiCatalog, + validateAuthMd, + validateIndexNowKeyFile, + validateRobotsContentSignal, +} from '../../../scripts/discovery/validate'; /** A reader over an in-memory file map, matching the `readDist` shape. */ function fileAt(files: Record): (path: string) => string | null { @@ -49,3 +54,119 @@ describe('IndexNow key file validation', () => { expect(errors[0]).toContain('key verification file is missing'); }); }); + +/** + * Content Signals (https://contentsignals.org/) let a site state its preference + * for each of `search`, `ai-input` and `ai-train`. The validator requires all + * three to be declared so consumers never have to guess a default. + */ +describe('Content Signals validation', () => { + test('accepts a fully specified policy', () => { + const robots = [ + 'User-agent: *', + 'Allow: /', + 'Content-Signal: search=yes, ai-input=yes, ai-train=yes', + ].join('\n'); + expect(validateRobotsContentSignal(robots)).toEqual([]); + }); + + test('accepts "no" as a value for any category', () => { + const robots = 'User-agent: *\nContent-Signal: search=yes, ai-input=no, ai-train=no'; + expect(validateRobotsContentSignal(robots)).toEqual([]); + }); + + test('rejects a robots.txt with no Content-Signal directive', () => { + const errors = validateRobotsContentSignal('User-agent: *\nAllow: /'); + expect(errors).toHaveLength(1); + expect(errors[0]).toContain('does not declare a Content-Signal policy'); + }); + + test('rejects a policy that omits a category', () => { + const errors = validateRobotsContentSignal('Content-Signal: search=yes, ai-input=yes'); + expect(errors).toHaveLength(1); + expect(errors[0]).toContain('"ai-train"'); + }); + + test('rejects a category without a yes/no value', () => { + const errors = validateRobotsContentSignal( + 'Content-Signal: search=yes, ai-input=maybe, ai-train=no', + ); + expect(errors).toHaveLength(1); + expect(errors[0]).toContain('"ai-input"'); + }); +}); + +/** + * The API catalog (RFC 9727) must be a linkset whose anchors and links all stay + * on the canonical origin, so a catalogue can never point a machine client at + * something the site does not serve. + */ +describe('API catalog validation', () => { + const ORIGIN = 'https://purview.dev'; + const valid = JSON.stringify({ + linkset: [ + { + anchor: 'https://purview.dev/', + 'service-desc': [{ href: 'https://purview.dev/discover.json' }], + 'service-doc': [{ href: 'https://purview.dev/docs/' }], + }, + ], + }); + + test('accepts a valid on-origin linkset', () => { + expect(validateApiCatalog(valid, ORIGIN)).toEqual([]); + }); + + test('rejects content that is not JSON', () => { + const errors = validateApiCatalog('not json', ORIGIN); + expect(errors).toHaveLength(1); + expect(errors[0]).toContain('not valid JSON'); + }); + + test('rejects a missing or empty linkset', () => { + expect(validateApiCatalog('{}', ORIGIN)[0]).toContain('no linkset entries'); + expect(validateApiCatalog('{"linkset":[]}', ORIGIN)[0]).toContain('no linkset entries'); + }); + + test('rejects an entry with no anchor', () => { + const errors = validateApiCatalog('{"linkset":[{}]}', ORIGIN); + expect(errors[0]).toContain('no anchor'); + }); + + test('rejects an off-origin anchor or href', () => { + const offAnchor = validateApiCatalog('{"linkset":[{"anchor":"https://evil.com/"}]}', ORIGIN); + expect(offAnchor[0]).toContain('anchor is off-origin'); + const offHref = validateApiCatalog( + '{"linkset":[{"anchor":"https://purview.dev/","service-doc":[{"href":"https://evil.com/"}]}]}', + ORIGIN, + ); + expect(offHref[0]).toContain('service-doc href is off-origin'); + }); +}); + +/** + * `/auth.md` documents a static site's *absence* of an agent-registration + * surface, so the validator enforces only the structural contract the convention + * defines — non-empty Markdown whose first H1 names `auth.md`. + */ +describe('auth.md validation', () => { + test('accepts content whose H1 contains "auth.md"', () => { + expect(validateAuthMd('# auth.md\n\nNo login.\n')).toEqual([]); + expect(validateAuthMd('# Example auth.md\n')).toEqual([]); + }); + + test('rejects empty content', () => { + expect(validateAuthMd(' \n')).toEqual(['auth.md is empty.']); + }); + + test('rejects content with no H1 heading', () => { + expect(validateAuthMd('Just a paragraph.\n')).toEqual(['auth.md has no H1 heading.']); + expect(validateAuthMd('## auth.md\n')).toEqual(['auth.md has no H1 heading.']); + }); + + test('rejects an H1 that does not name auth.md', () => { + const errors = validateAuthMd('# Authentication\n'); + expect(errors).toHaveLength(1); + expect(errors[0]).toContain('does not contain "auth.md"'); + }); +}); diff --git a/worker/README.md b/worker/README.md new file mode 100644 index 0000000..41783ed --- /dev/null +++ b/worker/README.md @@ -0,0 +1,91 @@ +# Agent-readiness edge Worker + +An edge Worker that supplies the response behaviour the static GitHub Pages +origin cannot: [content negotiation](https://developer.mozilla.org/en-US/docs/Web/HTTP/Guides/Content_negotiation) +for Markdown (so `purview.dev` passes the `markdownNegotiation` agent-readiness +check without the managed Cloudflare feature, which needs a paid plan), the +discovery `Link` headers on the homepage (RFC 8288 / RFC 9727 §3), and the +agent-registration document `/auth.md` served as Markdown. + +## Why a Worker + +`purview.dev` is a static **GitHub Pages** site behind **Cloudflare on the Free +plan**: + +- GitHub Pages is a file host — it cannot vary a response by request header, nor set a response + header the build did not write into a file. +- Cloudflare's managed _Markdown for Agents_ is **Pro / Business / Enterprise + only**, so it is unavailable on Free. + +A Worker on the zone route supplies the missing edge behaviour for free. + +## Behaviour + +| Request | Response | +| --------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------- | +| `/.well-known/api-catalog` | the RFC 9727 linkset (`Content-Type: application/linkset+json; charset=utf-8` — a static host types an extension-less file as `application/octet-stream`) | +| `/auth.md` | the agent-registration Markdown (`Content-Type: text/markdown; charset=utf-8` — a static host may type a `.md` file as `text/plain`) | +| `Accept: text/markdown` on a page with a Markdown sibling | the page's Markdown (`Content-Type: text/markdown; charset=utf-8`, `Vary: accept`, `x-markdown-tokens`) | +| `Accept: text/markdown` on any other page | the site-wide `/llms-full.txt` | +| `GET`/`HEAD` on the homepage (`/`) | the origin's response (HTML or negotiated Markdown) with the discovery `Link` headers added (RFC 8288 / RFC 9727 §3) | +| anything else (browsers, non-homepage, assets, …) | passed straight through to GitHub Pages | + +The page Markdown siblings (`index.md`) are produced by the build — see +`src/src/lib/discovery/page-markdown.ts` and `src/src/lib/discovery/emit.ts`. The +path scheme is a contract: change it here and in `src/index.ts` / `negotiate.ts` +together. + +## Discovery `Link` headers + +The homepage response advertises the origin's machine-readable surface through +HTTP [`Link`](https://www.rfc-editor.org/rfc/rfc8288) headers, so an agent can +find it with `HEAD /` and without parsing a body. A static file host cannot set a +response header, so the Worker adds them (`src/links.ts`, ADR 0018): + +| `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` | + +Only IANA-registered relation types are used and every target is root-relative. +The set mirrors the origin entry of the RFC 9727 API catalog so the header and +the catalog describe the same surface. The header rides on both the HTML homepage +and its negotiated Markdown; every other path is passed through untouched. + +```shell +curl -sI https://purview.dev/ | grep -i '^link:' +``` + +## Test + +```shell +bun test worker/tests # run from the repository root +``` + +## Deploy + +Requires a Cloudflare API token with **Workers Scripts: Edit** for the account, +stored as the repository secrets `CLOUDFLARE_API_TOKEN` and +`CLOUDFLARE_ACCOUNT_ID`. The Worker is deployed as part of the site deployment +(`.github/workflows/deploy.yml`, the `worker` job — it runs after the Pages deploy +and is skipped when the secrets are unset). To deploy by hand: + +```shell +cd worker +CLOUDFLARE_API_TOKEN=… CLOUDFLARE_ACCOUNT_ID=… bunx wrangler@4.171.0 deploy +``` + +Verify before trusting the live route: + +```shell +# The workers.dev URL first (`wrangler deploy` prints it): +curl -sI -H "Accept: text/markdown" https://purview-markdown-for-agents..workers.dev/docs/zodsharp/ +# expect content-type: text/markdown; charset=utf-8 and vary: accept +``` + +## Design + +See `docs/decisions/0016-markdown-for-agents.md`. diff --git a/worker/src/index.ts b/worker/src/index.ts new file mode 100644 index 0000000..f5b70c3 --- /dev/null +++ b/worker/src/index.ts @@ -0,0 +1,185 @@ +import { API_CATALOG_PATH, linkHeaderValues } from './links'; +import { + FALLBACK_MARKDOWN_PATH, + estimateTokens, + markdownCandidatePath, + wantsMarkdown, +} from './negotiate'; + +/** + * Agent-readiness edge behaviour for purview.dev — Cloudflare Worker. + * + * purview.dev is a static GitHub Pages site behind Cloudflare on the Free plan: + * a file host cannot vary a response by request header, and Cloudflare's managed + * Markdown-for-Agents conversion needs a paid plan. This Worker supplies the two + * things a static host cannot: + * + * - **Markdown for Agents.** A `GET` with `Accept: text/markdown` is answered + * with Markdown (`Content-Type: text/markdown`, `Vary: accept`, + * `x-markdown-tokens`). The Markdown served is the page's own sibling + * (`index.md`, built by `src/src/lib/discovery/emit.ts`), falling + * back to the site-wide `/llms-full.txt` corpus when a page has no Markdown of + * its own (ADR 0016). + * - **Discovery `Link` headers.** The homepage response advertises the origin's + * machine-readable surface through `Link` headers (RFC 8288 / RFC 9727 §3), + * whatever representation it served (ADR 0018). + * - **Agent registration `/auth.md`.** Served as Markdown whatever the host typed + * the file as; the document states there is nothing to register (ADR 0019). + * + * Every other request is passed straight through to the origin, so HTML stays + * the default and nothing else changes. See `README.md` next to this file for + * deployment, and `docs/decisions/0016-markdown-for-agents.md` / + * `docs/decisions/0018-link-headers.md` for the design. + */ + +const MARKDOWN_CONTENT_TYPE = 'text/markdown; charset=utf-8'; +const LINKSET_CONTENT_TYPE = 'application/linkset+json; charset=utf-8'; + +/** RFC 9727 API catalog path, also advertised as the homepage `api-catalog` link. */ +export { API_CATALOG_PATH }; + +/** Auth.md agent-registration document, served as Markdown whatever the host types it. */ +export const AUTH_MD_PATH = '/auth.md'; + +/** + * Marks a subrequest this Worker made. When it re-enters the Worker, the + * handler hands it straight to the origin (`fetch(request)`), which terminates + * the self-invocation — the standard Cloudflare route-bypass pattern. + */ +export const ORIGIN_BYPASS_HEADER = 'x-purview-origin-bypass'; + +/** Fetch a path on this zone without re-entering this Worker. */ +async function fetchOrigin(request: Request, path: string): Promise { + const target = new URL(path, request.url); + return fetch( + new Request(target, { + method: 'GET', + headers: { [ORIGIN_BYPASS_HEADER]: '1', accept: 'text/plain, text/markdown, */*' }, + }), + ); +} + +/** + * Serve the API catalog with its RFC 9727 media type. A static host types an + * extension-less file as `application/octet-stream`, which agents that strictly + * check the type will skip, so the header is set here. + */ +async function serveApiCatalog(request: Request): Promise { + const source = await fetchOrigin(request, API_CATALOG_PATH); + const body = await source.text(); + if (!source.ok) { + return new Response(body || 'Not found', { + status: source.status, + headers: { 'content-type': 'text/plain; charset=utf-8' }, + }); + } + return new Response(body, { + status: 200, + headers: { 'content-type': LINKSET_CONTENT_TYPE, 'cache-control': 'public, max-age=300' }, + }); +} + +/** + * Serve the agent-registration document (`/auth.md`) as Markdown. The file is + * plain Markdown on the origin, but a static host may type a `.md` file as + * `text/plain`, so the type is set here (ADR 0019). + */ +async function serveAuthMd(request: Request): Promise { + const source = await fetchOrigin(request, AUTH_MD_PATH); + const body = await source.text(); + if (!source.ok) { + return new Response(body || 'Not found', { + status: source.status, + headers: { 'content-type': 'text/plain; charset=utf-8' }, + }); + } + return new Response(body, { + status: 200, + headers: { 'content-type': MARKDOWN_CONTENT_TYPE, 'cache-control': 'public, max-age=300' }, + }); +} + +/** + * Negotiate a `text/markdown` request into the page's Markdown, falling back to + * the site-wide corpus and finally to the origin's HTML. + */ +async function serveMarkdown(request: Request, pathname: string): Promise { + let source = await fetchOrigin(request, markdownCandidatePath(pathname)); + if (!source.ok) { + source = await fetchOrigin(request, FALLBACK_MARKDOWN_PATH); + } + if (!source.ok) { + // Nothing machine-readable to serve: fall back to the HTML page. + return fetch(request); + } + + const body = await source.text(); + return new Response(body, { + status: 200, + headers: { + 'content-type': MARKDOWN_CONTENT_TYPE, + vary: 'accept', + 'x-markdown-tokens': String(estimateTokens(body)), + 'cache-control': 'public, max-age=300', + }, + }); +} + +/** + * Attach the discovery `Link` headers for a path to whatever the origin served, + * preserving its status and headers. A static GitHub Pages host cannot set a + * response header, so it is added at the edge (RFC 8288 / RFC 9727 §3). + */ +function addLinkHeaders(response: Response, values: readonly string[]): Response { + if (values.length === 0) { + return response; + } + const headers = new Headers(response.headers); + for (const value of values) { + headers.append('link', value); + } + return new Response(response.body, { + status: response.status, + statusText: response.statusText, + headers, + }); +} + +export default { + async fetch(request: Request): Promise { + // A subrequest from this Worker: pass it to the origin, do not re-negotiate. + if (request.headers.get(ORIGIN_BYPASS_HEADER) === '1') { + return fetch(request); + } + const { pathname } = new URL(request.url); + // The API catalog is served with its RFC 9727 media type whatever the origin + // sent (a static host types an extension-less file as application/octet-stream). + if (request.method === 'GET' && pathname === API_CATALOG_PATH) { + return serveApiCatalog(request); + } + // The agent-registration document is Markdown whatever the host typed a `.md` + // file as (a static host may serve it as text/plain). + if (request.method === 'GET' && pathname === AUTH_MD_PATH) { + return serveAuthMd(request); + } + // Only GET (negotiation and links) and HEAD (links) carry edge behaviour; + // every other method is passthrough. + if (request.method !== 'GET' && request.method !== 'HEAD') { + return fetch(request); + } + + // A resource that is already Markdown is never re-negotiated: the page-level + // negotiation below would otherwise answer a `.md` URL with the site corpus. + const markdown = + request.method === 'GET' && + !pathname.toLowerCase().endsWith('.md') && + wantsMarkdown(request.headers.get('accept')); + const links = linkHeaderValues(pathname); + if (!markdown && links.length === 0) { + return fetch(request); + } + + const response = markdown ? await serveMarkdown(request, pathname) : await fetch(request); + return addLinkHeaders(response, links); + }, +}; diff --git a/worker/src/links.ts b/worker/src/links.ts new file mode 100644 index 0000000..64a82dd --- /dev/null +++ b/worker/src/links.ts @@ -0,0 +1,84 @@ +/** + * Discovery `Link` response headers (RFC 8288) for the edge Worker. + * + * RFC 9727 §3 defines the `api-catalog` link relation: a `Link` header field + * with `rel="api-catalog"` points a client at the origin's API catalog + * (`/.well-known/api-catalog`). Section 3.1 allows further *registered* link + * relations to describe the same resource, so the homepage also advertises the + * origin's other machine-readable surfaces with `service-desc`, `service-doc`, + * `describedby` and `sitemap`. + * + * Only IANA-registered relation types are used and every target is + * root-relative, which RFC 8288 permits and the Web Linking convention prefers + * for portability across protocols and ports. These are pure functions so the + * decision logic is unit-testable without the Cloudflare runtime; `src/index.ts` + * attaches the header to the homepage response. A static GitHub Pages host + * cannot set a response header, which is why this lives at the edge (ADR 0018). + * + * The links mirror the origin entry of the RFC 9727 API catalog + * (`src/src/lib/discovery/api-catalog.ts`), so the header and the catalog agree. + */ + +/** RFC 9727 well-known URI, served with its `application/linkset+json` type. */ +export const API_CATALOG_PATH = '/.well-known/api-catalog'; + +export interface DiscoveryLink { + /** An IANA-registered link relation type. */ + rel: string; + /** Root-relative URI reference of the linked resource. */ + href: string; + /** Optional media type of the target, so the link is self-describing. */ + type?: string; + /** Optional human-readable title of the target. */ + title?: string; +} + +/** + * The discovery links every homepage response advertises: the origin's + * machine-readable surface, in the order the API catalog lists it. + */ +export const HOMEPAGE_LINKS: readonly DiscoveryLink[] = [ + { + rel: 'api-catalog', + href: API_CATALOG_PATH, + type: 'application/linkset+json', + title: 'API catalog', + }, + { + rel: 'service-desc', + href: '/discover.json', + type: 'application/json', + title: 'Discovery manifest', + }, + { rel: 'service-doc', href: '/docs/', type: 'text/html', title: 'Documentation' }, + { rel: 'describedby', href: '/llms.txt', type: 'text/markdown', title: 'LLM site index' }, + { rel: 'sitemap', href: '/sitemap-index.xml', type: 'application/xml', title: 'Sitemap' }, +]; + +/** Whether a request path is the site homepage. */ +export function isHomepage(pathname: string): boolean { + const path = pathname === '' ? '/' : pathname; + return path === '/' || path === '/index.html'; +} + +/** Render one discovery link as an RFC 8288 `Link` header field value. */ +export function formatLink(link: DiscoveryLink): string { + const parts = [`<${link.href}>`, `rel="${link.rel}"`]; + if (link.type) { + parts.push(`type="${link.type}"`); + } + if (link.title) { + parts.push(`title="${link.title}"`); + } + return parts.join('; '); +} + +/** + * The `Link` header field values a response for `pathname` should carry. + * + * Only the homepage advertises the discovery surface today; every other path + * returns an empty list and is left exactly as the origin sent it. + */ +export function linkHeaderValues(pathname: string): string[] { + return isHomepage(pathname) ? HOMEPAGE_LINKS.map(formatLink) : []; +} diff --git a/worker/src/negotiate.ts b/worker/src/negotiate.ts new file mode 100644 index 0000000..cb9a1cf --- /dev/null +++ b/worker/src/negotiate.ts @@ -0,0 +1,58 @@ +/** + * Content negotiation for "Markdown for Agents" (Cloudflare Worker). + * + * These are pure functions so the decision logic is unit-testable without the + * Cloudflare runtime. `src/index.ts` wires them into the request handler; the + * page path scheme is the contract with the build (see + * `src/src/lib/discovery/page-markdown.ts`). + */ + +/** Site-relative path served when a page has no Markdown sibling of its own. */ +export const FALLBACK_MARKDOWN_PATH = '/llms-full.txt'; + +/** + * True when the request explicitly asks for Markdown. + * + * Only an explicit `text/markdown` counts: a browser's wildcard accept is not a + * Markdown request and must keep getting HTML. A media range with `q=0` is a + * rejection and is ignored. + */ +export function wantsMarkdown(accept: string | null | undefined): boolean { + if (!accept) { + return false; + } + for (const entry of accept.split(',')) { + const [rawType, ...params] = entry.split(';'); + if (rawType?.trim().toLowerCase() !== 'text/markdown') { + continue; + } + const q = params + .map((param) => param.trim().toLowerCase()) + .find((param) => param.startsWith('q=')); + if (q !== undefined && Number(q.slice(2)) === 0) { + continue; + } + return true; + } + return false; +} + +/** + * The Markdown sibling of a page URL: `/index.md`. + * + * `/docs/zodsharp/core-concepts/` -> `/docs/zodsharp/core-concepts/index.md` + * `/about` -> `/about/index.md`, `/` -> `/index.md`. + */ +export function markdownCandidatePath(pathname: string): string { + const withoutQuery = (pathname.split('?')[0] ?? '/').split('#')[0] ?? '/'; + const withSlash = withoutQuery.endsWith('/') ? withoutQuery : `${withoutQuery}/`; + return `${withSlash}index.md`; +} + +/** + * A coarse, model-agnostic token estimate (~4 characters per token), reported in + * the `x-markdown-tokens` header so agents can budget before downloading. + */ +export function estimateTokens(markdown: string): number { + return Math.ceil(markdown.length / 4); +} diff --git a/worker/tests/handler.test.ts b/worker/tests/handler.test.ts new file mode 100644 index 0000000..2b05c9c --- /dev/null +++ b/worker/tests/handler.test.ts @@ -0,0 +1,204 @@ +import { afterEach, describe, expect, test } from 'bun:test'; + +import handler, { ORIGIN_BYPASS_HEADER } from '../src/index'; + +const realFetch = globalThis.fetch; + +afterEach(() => { + globalThis.fetch = realFetch; +}); + +/** Replace the global fetch with a recorder that resolves a canned response. */ +function stub(resolver: (url: string) => Response): { calls: string[] } { + const calls: string[] = []; + globalThis.fetch = ((input: Request | string | URL) => { + const url = + typeof input === 'string' ? input : input instanceof URL ? input.toString() : input.url; + calls.push(url); + return Promise.resolve(resolver(url)); + }) as unknown as typeof fetch; + return { calls }; +} + +const MARKDOWN = '# Core concepts\n\nSome body text.\n'; + +describe('markdown negotiation handler', () => { + test('passes non-markdown requests straight through', async () => { + const { calls } = stub(() => new Response('page', { status: 200 })); + const response = await handler.fetch( + new Request('https://purview.dev/docs/zodsharp/', { headers: { accept: 'text/html' } }), + ); + expect(await response.text()).toBe('page'); + expect(calls).toEqual(['https://purview.dev/docs/zodsharp/']); + }); + + test('serves the page Markdown sibling with the right headers', async () => { + stub((url) => + url.endsWith('/core-concepts/index.md') + ? new Response(MARKDOWN, { status: 200 }) + : new Response('missing', { status: 404 }), + ); + const response = await handler.fetch( + new Request('https://purview.dev/docs/zodsharp/core-concepts/', { + headers: { accept: 'text/markdown' }, + }), + ); + expect(response.status).toBe(200); + expect(response.headers.get('content-type')).toBe('text/markdown; charset=utf-8'); + expect(response.headers.get('vary')).toBe('accept'); + expect(response.headers.get('x-markdown-tokens')).toBe(String(Math.ceil(MARKDOWN.length / 4))); + expect(await response.text()).toBe(MARKDOWN); + }); + + test('falls back to the site corpus when a page has no Markdown sibling', async () => { + const { calls } = stub((url) => + url.endsWith('/llms-full.txt') + ? new Response('# Whole corpus', { status: 200 }) + : new Response('missing', { status: 404 }), + ); + const response = await handler.fetch( + new Request('https://purview.dev/about/', { headers: { accept: 'text/markdown' } }), + ); + expect(await response.text()).toBe('# Whole corpus'); + expect(calls).toEqual([ + 'https://purview.dev/about/index.md', + 'https://purview.dev/llms-full.txt', + ]); + }); + + test('falls back to the HTML page when nothing machine-readable exists', async () => { + stub((url) => + url.endsWith('.md') || url.endsWith('/llms-full.txt') + ? new Response('no', { status: 404 }) + : new Response('fallback', { status: 200 }), + ); + const response = await handler.fetch( + new Request('https://purview.dev/nowhere/', { headers: { accept: 'text/markdown' } }), + ); + expect(await response.text()).toBe('fallback'); + }); + + test('never re-negotiates its own subrequests', async () => { + const { calls } = stub(() => new Response('origin', { status: 200 })); + const response = await handler.fetch( + new Request('https://purview.dev/docs/zodsharp/', { + headers: { [ORIGIN_BYPASS_HEADER]: '1', accept: 'text/markdown' }, + }), + ); + expect(await response.text()).toBe('origin'); + expect(calls).toEqual(['https://purview.dev/docs/zodsharp/']); + }); + + test('serves the API catalog as a linkset, overriding the origin type', async () => { + const { calls } = stub( + () => + new Response('{"linkset":[]}', { + status: 200, + headers: { 'content-type': 'application/octet-stream' }, + }), + ); + const response = await handler.fetch( + new Request('https://purview.dev/.well-known/api-catalog'), + ); + expect(response.status).toBe(200); + expect(response.headers.get('content-type')).toBe('application/linkset+json; charset=utf-8'); + expect(await response.text()).toBe('{"linkset":[]}'); + expect(calls).toEqual(['https://purview.dev/.well-known/api-catalog']); + }); + + test('propagates a missing API catalog instead of inventing one', async () => { + stub(() => new Response('Not Found', { status: 404 })); + const response = await handler.fetch( + new Request('https://purview.dev/.well-known/api-catalog'), + ); + expect(response.status).toBe(404); + }); +}); + +describe('discovery Link headers', () => { + test('adds the discovery Link headers to the homepage response', async () => { + stub( + () => + new Response('home', { + status: 200, + headers: { 'content-type': 'text/html; charset=utf-8' }, + }), + ); + const response = await handler.fetch( + new Request('https://purview.dev/', { headers: { accept: 'text/html' } }), + ); + expect(response.status).toBe(200); + // The origin's own headers survive the addition. + expect(response.headers.get('content-type')).toBe('text/html; charset=utf-8'); + const link = response.headers.get('link') ?? ''; + expect(link).toContain('; rel="api-catalog"'); + for (const rel of ['api-catalog', 'service-desc', 'service-doc', 'describedby', 'sitemap']) { + expect(link).toContain(`rel="${rel}"`); + } + expect(await response.text()).toBe('home'); + }); + + test('keeps the headers on the negotiated Markdown homepage', async () => { + stub((url) => + url.endsWith('/index.md') + ? new Response(MARKDOWN, { status: 200 }) + : new Response('missing', { status: 404 }), + ); + const response = await handler.fetch( + new Request('https://purview.dev/', { headers: { accept: 'text/markdown' } }), + ); + expect(response.headers.get('content-type')).toBe('text/markdown; charset=utf-8'); + expect(response.headers.get('vary')).toBe('accept'); + expect(response.headers.get('link') ?? '').toContain('rel="api-catalog"'); + }); + + test('adds no Link headers to any other page', async () => { + stub(() => new Response('about', { status: 200 })); + const response = await handler.fetch( + new Request('https://purview.dev/about/', { headers: { accept: 'text/html' } }), + ); + expect(response.headers.get('link')).toBeNull(); + }); + + test('advertises the headers on a HEAD request without a body subrequest', async () => { + const { calls } = stub(() => new Response(null, { status: 200 })); + const response = await handler.fetch(new Request('https://purview.dev/', { method: 'HEAD' })); + expect(response.headers.get('link') ?? '').toContain('rel="service-desc"'); + // A HEAD request is passed straight through; no Markdown sibling is fetched. + expect(calls).toEqual(['https://purview.dev/']); + }); +}); + +describe('auth.md', () => { + test('serves /auth.md as Markdown regardless of the origin content type', async () => { + stub( + () => + new Response('# auth.md\n', { + status: 200, + headers: { 'content-type': 'text/plain; charset=utf-8' }, + }), + ); + const response = await handler.fetch(new Request('https://purview.dev/auth.md')); + expect(response.status).toBe(200); + expect(response.headers.get('content-type')).toBe('text/markdown; charset=utf-8'); + expect(await response.text()).toBe('# auth.md\n'); + }); + + test('does not re-negotiate a resource that is already Markdown', async () => { + const { calls } = stub(() => new Response('# page\n', { status: 200 })); + const response = await handler.fetch( + new Request('https://purview.dev/docs/zodsharp/core-concepts/index.md', { + headers: { accept: 'text/markdown' }, + }), + ); + expect(await response.text()).toBe('# page\n'); + // The Markdown sibling is served directly; the site corpus is never fetched. + expect(calls).toEqual(['https://purview.dev/docs/zodsharp/core-concepts/index.md']); + }); + + test('propagates a missing auth.md instead of inventing one', async () => { + stub(() => new Response('Not Found', { status: 404 })); + const response = await handler.fetch(new Request('https://purview.dev/auth.md')); + expect(response.status).toBe(404); + }); +}); diff --git a/worker/tests/links.test.ts b/worker/tests/links.test.ts new file mode 100644 index 0000000..ed5ac39 --- /dev/null +++ b/worker/tests/links.test.ts @@ -0,0 +1,68 @@ +import { describe, expect, test } from 'bun:test'; + +import { + API_CATALOG_PATH, + HOMEPAGE_LINKS, + formatLink, + isHomepage, + linkHeaderValues, +} from '../src/links'; + +describe('isHomepage', () => { + test('matches the root and its explicit index form', () => { + expect(isHomepage('/')).toBe(true); + expect(isHomepage('')).toBe(true); + expect(isHomepage('/index.html')).toBe(true); + }); + + test('does not match any other path', () => { + expect(isHomepage('/about/')).toBe(false); + expect(isHomepage('/docs/zodsharp/core-concepts/')).toBe(false); + expect(isHomepage('/projects/zodsharp/')).toBe(false); + }); +}); + +describe('formatLink', () => { + test('renders an RFC 8288 Link field value', () => { + expect( + formatLink({ + rel: 'api-catalog', + href: API_CATALOG_PATH, + type: 'application/linkset+json', + }), + ).toBe('; rel="api-catalog"; type="application/linkset+json"'); + }); + + test('includes a quoted title when present', () => { + expect(formatLink({ rel: 'describedby', href: '/llms.txt', title: 'LLM site index' })).toBe( + '; rel="describedby"; title="LLM site index"', + ); + }); + + test('omits the optional type and title when absent', () => { + expect(formatLink({ rel: 'sitemap', href: '/sitemap-index.xml' })).toBe( + '; rel="sitemap"', + ); + }); +}); + +describe('linkHeaderValues', () => { + test('advertises the discovery surface on the homepage', () => { + const values = linkHeaderValues('/'); + expect(values).toHaveLength(HOMEPAGE_LINKS.length); + const rels = values.map((value) => /rel="([^"]+)"/.exec(value)?.[1]); + expect(rels).toEqual(['api-catalog', 'service-desc', 'service-doc', 'describedby', 'sitemap']); + }); + + test('uses only registered relations and root-relative targets', () => { + for (const value of linkHeaderValues('/')) { + expect(value).toMatch(/^<\/[^>]+>; rel="[a-z-]+"/); + expect(value).not.toContain('http'); + } + }); + + test('advertises nothing on any other path', () => { + expect(linkHeaderValues('/about/')).toEqual([]); + expect(linkHeaderValues('/docs/zodsharp/')).toEqual([]); + }); +}); diff --git a/worker/tests/negotiate.test.ts b/worker/tests/negotiate.test.ts new file mode 100644 index 0000000..7db8a39 --- /dev/null +++ b/worker/tests/negotiate.test.ts @@ -0,0 +1,50 @@ +import { describe, expect, test } from 'bun:test'; + +import { estimateTokens, markdownCandidatePath, wantsMarkdown } from '../src/negotiate'; + +describe('wantsMarkdown', () => { + test('is false when there is no Accept header', () => { + expect(wantsMarkdown(null)).toBe(false); + expect(wantsMarkdown(undefined)).toBe(false); + expect(wantsMarkdown('')).toBe(false); + }); + + test('is false for browser and wildcard accepts', () => { + expect(wantsMarkdown('text/html')).toBe(false); + expect(wantsMarkdown('text/html,application/xhtml+xml,*/*;q=0.8')).toBe(false); + }); + + test('is true when text/markdown is one of the options', () => { + expect(wantsMarkdown('text/markdown')).toBe(true); + expect(wantsMarkdown('text/html, text/markdown')).toBe(true); + expect(wantsMarkdown('TEXT/MARKDOWN')).toBe(true); + expect(wantsMarkdown('text/markdown; charset=utf-8')).toBe(true); + }); + + test('honours an explicit q=0 rejection', () => { + expect(wantsMarkdown('text/markdown;q=0')).toBe(false); + expect(wantsMarkdown('text/markdown; q=0.0')).toBe(false); + expect(wantsMarkdown('text/html, text/markdown;q=0.9')).toBe(true); + }); +}); + +describe('markdownCandidatePath', () => { + test('maps a page URL to its Markdown sibling', () => { + expect(markdownCandidatePath('/')).toBe('/index.md'); + expect(markdownCandidatePath('/docs/zodsharp/core-concepts/')).toBe( + '/docs/zodsharp/core-concepts/index.md', + ); + expect(markdownCandidatePath('/docs/zodsharp/core-concepts')).toBe( + '/docs/zodsharp/core-concepts/index.md', + ); + expect(markdownCandidatePath('/about?x=1#section')).toBe('/about/index.md'); + }); +}); + +describe('estimateTokens', () => { + test('is a non-negative, monotonic estimate', () => { + expect(estimateTokens('')).toBe(0); + expect(estimateTokens('abcd')).toBe(1); + expect(estimateTokens('a'.repeat(400))).toBeGreaterThanOrEqual(100); + }); +}); diff --git a/worker/wrangler.toml b/worker/wrangler.toml new file mode 100644 index 0000000..92de153 --- /dev/null +++ b/worker/wrangler.toml @@ -0,0 +1,14 @@ +name = "purview-markdown-for-agents" +main = "src/index.ts" +compatibility_date = "2026-03-01" + +# Expose a workers.dev URL so the behaviour can be verified on its own before the +# route below puts the Worker in front of the live site. +workers_dev = true + +# Front the whole zone so any page URL can answer `Accept: text/markdown`. +# Non-Markdown requests are passed through to the GitHub Pages origin untouched. +# Verify on the workers.dev URL first; promote by keeping this route. +routes = [{ pattern = "purview.dev/*", zone_name = "purview.dev" }] + +observability = { enabled = true }