diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index e989f05..07d4fe2 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -168,6 +168,12 @@ jobs: with: # Build output is written into the `src/` package (see package.json). path: ./src/dist + # The RFC 9727 API catalog lives at `.well-known/api-catalog`, and this + # action drops dot-files and dot-directories by default — so the file is + # built and validated but never reaches GitHub Pages, and the edge Worker + # then faithfully propagates the origin's 404. `true` ships hidden files + # (it still excludes `.git`/`.github`). + include-hidden-files: true deploy: needs: build diff --git a/AGENTS.md b/AGENTS.md index 7df67a5..307593d 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -206,4 +206,6 @@ src/src/data/projects/.yml` against a clone of its repository. | 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) | +| A2A / OAuth / ACP discovery | `src/src/lib/discovery/{agent-card,oauth,acp}.ts`, `/.well-known/{agent-card.json,oauth-authorization-server,oauth-protected-resource,acp.json}` (ADR 0020) | +| Agent Skills, MCP and Web Bot Auth discovery | `src/src/lib/discovery/{agent-skills,mcp-server-card,web-bot-auth}.ts`, `src/src/scripts/webmcp.ts`, `/mcp` (edge Worker `worker/src/mcp.ts`), `/.well-known/{agent-skills/index.json,mcp/server-card.json,http-message-signatures-directory}` (ADR 0021) | | Architecture decisions | `docs/decisions/*.md` | diff --git a/README.md b/README.md index c9dff95..c69a05e 100644 --- a/README.md +++ b/README.md @@ -612,8 +612,11 @@ generated discovery layer: a partitioned sitemap (`/sitemap-index.xml` → is derived from the project catalogue, the docs manifest and the release cache — 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, +Worker, and `/auth.md` plus the A2A Agent Card, OAuth and ACP discovery documents +(`/.well-known/agent-card.json`, `oauth-authorization-server`, +`oauth-protected-resource`, `acp.json`) record that the site has no login, no +authorization server and no commerce (ADR 0019, ADR 0020). After a successful +deployment, IndexNow notifies participating engines about changed URLs only. ```shell diff --git a/docs/decisions/0019-auth-md.md b/docs/decisions/0019-auth-md.md index 28a2fe0..1c3b38b 100644 --- a/docs/decisions/0019-auth-md.md +++ b/docs/decisions/0019-auth-md.md @@ -1,6 +1,6 @@ # ADR 0019 — `/auth.md` for a site with no login -- Status: accepted +- Status: accepted (superseded in part by [ADR 0020](./0020-agent-and-oauth-discovery.md)) - Date: 2026-04-12 ## Context diff --git a/docs/decisions/0020-agent-and-oauth-discovery.md b/docs/decisions/0020-agent-and-oauth-discovery.md new file mode 100644 index 0000000..936cbd2 --- /dev/null +++ b/docs/decisions/0020-agent-and-oauth-discovery.md @@ -0,0 +1,97 @@ +# ADR 0020 — Agent and OAuth discovery for a site with no login + +- Status: accepted +- Date: 2026-04-12 + +## Context + +Agent-readiness tooling (isitagentready.com) probes a set of standard `.well-known` +paths beyond the RFC 9727 API catalog (ADR 0017) and `/auth.md` (ADR 0019): + +- `/.well-known/agent-card.json` — the A2A Agent Card (A2A protocol, "Agent Discovery"); +- `/.well-known/oauth-authorization-server` — OAuth 2.0 Authorization Server Metadata (RFC 8414); +- `/.well-known/oauth-protected-resource` — OAuth 2.0 Protected Resource Metadata (RFC 9728); +- `/.well-known/acp.json` — the Agentic Commerce Protocol discovery document. + +`purview.dev` is a **public, read-only static site with no login**: no accounts, no +hosted API, no protected resource, no authorization server and no commerce +(ADR 0001). For every one of these paths the *absence* is the truth, and ADR 0019 +published nothing, letting `/auth.md` state the absence in prose — its rejected +alternatives called a published OAuth document "fabrication". + +Two facts changed that judgement: + +1. **A 404 is a worse answer than a stub.** An agent that probes a standard path and + gets a 404 cannot tell "no such surface" from "not implemented yet". A small, + well-formed document that says *"public resource, no credential required, no + commerce here"* is a truthful, machine-readable answer; the 404 is not. +2. **The `_comment` makes it explicit.** The site already publishes a no-op surface + on principle: the API catalog and `/auth.md` exist to describe what the origin + serves without inventing APIs (ADR 0017, 0019). These documents are the same + pattern, one path further, provided they say what they are in band. + +## Decision + +Generate the four documents at build time (from `src/src/lib/discovery/`) and write +them into `dist/.well-known/`, exactly like the API catalog and `/auth.md`: + +- `agent-card.ts` — an A2A Agent Card for the read-only documentation surface: the + required `name`/`version`/`description`, a `supportedInterfaces` entry pointing at + the origin over `HTTP+JSON`, `capabilities`, and one fully-described `skills` entry. +- `oauth.ts` — RFC 8414 authorization-server metadata and RFC 9728 protected-resource + metadata. The resource metadata names the origin, self-references the origin as its + authorization server, and points `resource_documentation` at `/auth.md`. +- `acp.ts` — an ACP discovery document shaped to the spec (protocol name and version, + API base URL, transports, services). + +**Every document is explicitly a stub — that is the honesty rule.** Each carries a +top-level `_comment` stating, in band, that the origin has no task server, no +authorization server and no commerce, that the endpoints it names are reserved and +non-operational, and that nothing requires a credential. The paths the OAuth metadata +names (`/oauth/authorize`, `/oauth/token`, `/.well-known/jwks.json`) serve nothing; +the ACP `capabilities.services` value describes the shape of the document, not a +working integration. The documents are "explicit rather than implied" (ADR 0019) and +they agree with `/auth.md`. + +Serving: + +- The `.json` paths (`agent-card.json`, `acp.json`) are typed `application/json` by the host. +- The extension-less OAuth paths are typed `application/octet-stream` by a static host, + which an agent that checks the media type skips, so the edge Worker sets + `application/json` (`worker/src/index.ts`), exactly as it does for the API catalog + (ADR 0016, ADR 0017). + +`discovery:validate` fails the build when any document is missing or malformed, so a +half-formed surface never ships. + +## Consequences + +- `a2aAgentCard`, `oauthDiscovery`, `oauthProtectedResource` — and the commerce `acp` + surface — resolve to well-formed documents instead of 404s, so an agent gets a + truthful machine-readable answer. +- The documents are generated, so they track the site identity and version and cannot + drift; each has unit, dist and Worker test coverage, and `check-generated` requires + all four in `dist/`. +- Four more generated artifacts, and two more Worker-special-cased paths to maintain. +- **The stubs describe surfaces the origin does not serve.** That is a deliberate, + documented trade: the alternative — a bare 404 — is *less* honest to a machine + client, because it cannot distinguish "none" from "not yet". If Purview ever ships an + authenticated API or a commerce flow, these documents become real and their + `_comment` is removed; nothing else in the discovery layer changes. +- If the readiness ecosystem ever treats these documents as proof that the *flows* + work, this decision must be revisited: the documents state plainly that they do not. + +## Alternatives considered + +- **Publish nothing and let `/auth.md` state the absence in prose** (ADR 0019). A + machine client does not read prose before deciding; the 404 is indistinguishable from + an unimplemented surface. Superseded. +- **Point the OAuth metadata at a real third-party authorization server.** Fabrication + with a real victim: the site would name an issuer it has no relationship with. + Rejected. +- **Implement a real authorization server in the Worker.** Adds an interactive login to + a site that must not have one, plus a credential store to a static site. Rejected. +- **A hand-written static file per path.** Simple, but it would sit outside the + discovery model, its validator and its version source, and could drift. Rejected in + favour of generation. + diff --git a/docs/decisions/0021-skills-mcp-and-web-bot-auth.md b/docs/decisions/0021-skills-mcp-and-web-bot-auth.md new file mode 100644 index 0000000..474bd23 --- /dev/null +++ b/docs/decisions/0021-skills-mcp-and-web-bot-auth.md @@ -0,0 +1,123 @@ +# ADR 0021 — Skills, MCP, WebMCP and Web Bot Auth discovery + +- Status: accepted +- Date: 2026-12-04 + +## Context + +Agent-readiness tooling (isitagentready.com) probes four further standard +surfaces beyond the A2A card, OAuth metadata and ACP document of ADR 0020, plus a +DNS-based discovery mechanism: + +- `/.well-known/agent-skills/index.json` — the Agent Skills Discovery index + ([cloudflare/agent-skills-discovery-rfc](https://github.com/cloudflare/agent-skills-discovery-rfc), v0.2.0); +- `/.well-known/mcp/server-card.json` — an MCP Server Card + ([SEP-1649](https://github.com/modelcontextprotocol/modelcontextprotocol/pull/2127)); +- WebMCP — in-browser tools registered on + `document.modelContext` / `navigator.modelContext` + ([WebMCP](https://webmachinelearning.github.io/webmcp/)); +- `/.well-known/http-message-signatures-directory` — a Web Bot Auth JWKS directory + ([WebBotAuth WG](https://datatracker.ietf.org/wg/webbotauth/about/)); +- `_agents` DNS records — DNS for AI Discovery (DNS-AID). + +ADR 0020 established the pattern: a standard path that an agent probes should +resolve to a **truthful, machine-readable answer** rather than a 404, and the +document must say what it is in band. This ADR applies that pattern to the four +HTTP surfaces, and — where a surface can be *real* — makes it real rather than a +stub. purview.dev genuinely publishes Agent Skills and genuinely serves its +documentation, so the Agent Skills index and the MCP server are real features, +not stubs; Web Bot Auth is real for the one bot request the site sends. + +## Decision + +Generate the discovery documents at build time (from `src/src/lib/discovery/`, +written by `emit.ts`), serve the runtime behaviour from the edge Worker +(`worker/`), and validate every artifact in `discovery:validate`. + +### Agent Skills discovery index + +`agent-skills.ts` builds `/.well-known/agent-skills/index.json` from the +`SKILL.md` files themselves: the `description` from each file's front matter and +the `digest` (`sha256:{hex}`) from its bytes, so the index cannot drift from what +is served. It lists two sets, deduplicated by name (this repository's own skills +first): + +- **this repository's own skills** (`skills//SKILL.md`), copied by the + build to `/.well-known/agent-skills//` — the location the RFC's authors + conventionally use — so the `url` is same-origin. These are committed with the + site, so the index is never empty; +- the **mirrored project skills** (ADR 0010) already served at + `/skills///SKILL.md`. + +### MCP Server Card and a read-only MCP server + +`mcp-server-card.ts` publishes `/.well-known/mcp/server-card.json` for the +endpoint `https://purview.dev/mcp`. Because a card that advertises a server the +origin does not run would be dishonest, `worker/src/mcp.ts` implements a +**dependency-free, read-only** MCP server (Streamable HTTP, JSON-RPC 2.0) that +exposes the catalogue as tools (`search_projects`, `list_projects`, +`get_project`) and the site's machine-readable documents as resources. The card's +`capabilities` states the truth — `tools` and `resources` are served, `prompts` +are not. The server only ever fetches the origin; it writes nothing and needs no +credential. + +### Web Bot Auth + +`web-bot-auth.ts` publishes the JWKS directory and signs the site's outbound bot +request. The **public** Ed25519 key is committed (so the directory always +resolves); the **private** key is the `WEB_BOT_AUTH_PRIVATE_JWK` deploy secret, +generated with `bun run web-bot-auth:key`. `discovery:indexnow` signs its +`POST /indexnow` with `Signature-Agent`, `Signature-Input` and `Signature` +headers (RFC 9421 / HTTP Message Signatures). With no secret set the request is +still sent, simply unsigned. + +### WebMCP + +`src/src/scripts/webmcp.ts` registers read-only tools (`search-projects`, +`list-projects`, `open-page`) on page load through +`document.modelContext.registerTool()` (falling back to +`navigator.modelContext`), under one `AbortController`. It is loaded by both the +site layout and the Starlight pages, and it no-ops on a browser without the API. + +### DNS for AI Discovery (DNS-AID) + +DNS records are outside this repository (the zone is controlled separately), so +they are documented as a one-time operator step in `docs/discovery.md` rather +than generated. The records are `SVCB`/`HTTPS` records under `_agents` with +`alpn` and port parameters, DNSSEC-signed. + +## Consequences + +- `agentSkills`, `mcpServerCard`, `webMcp` and `webBotAuth` resolve to real, + truthful surfaces instead of 404s. +- The Agent Skills index, the MCP card and the JWKS directory are generated from + their sources, so they track the skills, the site version and the key and + cannot drift; each has unit, dist and Worker coverage, and `check-generated` + requires all three in `dist/`. +- The MCP server is a new runtime surface in the Worker; it is isolated to + `POST /mcp` and its own tests, and passes every other request through as + before. It is deployed with the Worker, so it needs + `CLOUDFLARE_API_TOKEN`/`CLOUDFLARE_ACCOUNT_ID` like the rest of the edge + behaviour (the site itself needs neither). +- Web Bot Auth makes the site's IndexNow request verifiable. The committed public + key is a real Ed25519 key; rotating it means regenerating the pair and updating + both the constant and the secret. +- DNS-AID remains an operator action; nothing in the build can pass it alone. + +## Alternatives considered + +- **Stub the MCP card** (declare no capabilities, point at the origin), as ADR + 0020 does for OAuth and ACP. Rejected: the site *can* serve documentation over + MCP cheaply, and a card that claims a capability the origin does not have — or + omits one it could provide — is less useful than a small real server. +- **List only the mirrored project skills.** Rejected: a checkout without a data + sync would publish an empty index, and this repository's own skills are + published by this origin too. Both sets belong. +- **Serve the repository's skills from their GitHub URLs.** Rejected: same-origin + URLs are simpler, verifiable against the digest, and need no second host. +- **Generate the Web Bot Auth key at build time.** Rejected: the build must not + hold a private key, and the public directory must exist without a secret. A + committed public key plus a deploy secret keeps the key private. +- **Sign nothing (publish the directory only).** Rejected: Web Bot Auth is only + meaningful if the request is signed; the directory without a signature proves + nothing. diff --git a/docs/discovery.md b/docs/discovery.md index 5f696cc..35b3bbb 100644 --- a/docs/discovery.md +++ b/docs/discovery.md @@ -30,6 +30,15 @@ release cache). **There is no hand-maintained list of URLs.** | 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`) | +| A2A Agent Card | `/.well-known/agent-card.json` (A2A; the read-only documentation surface) | integration (`lib/discovery/agent-card.ts`) | +| OAuth authorization-server metadata | `/.well-known/oauth-authorization-server` (RFC 8414; a no-auth stub) | integration (`lib/discovery/oauth.ts`) | +| OAuth protected-resource metadata | `/.well-known/oauth-protected-resource` (RFC 9728; a no-auth stub) | integration (`lib/discovery/oauth.ts`) | +| ACP discovery | `/.well-known/acp.json` (Agentic Commerce Protocol; a non-commerce stub) | integration (`lib/discovery/acp.ts`) | +| Agent Skills index | `/.well-known/agent-skills/index.json` (and each skill under `/.well-known/agent-skills//`) | integration (`lib/discovery/agent-skills.ts`) | +| MCP Server Card | `/.well-known/mcp/server-card.json` (SEP-1649) | integration (`lib/discovery/mcp-server-card.ts`) | +| Read-only MCP server | `/mcp` (JSON-RPC 2.0 over Streamable HTTP) | edge Worker (`worker/src/mcp.ts`) | +| Web Bot Auth directory | `/.well-known/http-message-signatures-directory` (a JWKS) | integration (`lib/discovery/web-bot-auth.ts`) | +| WebMCP tools | registered on page load (`document.modelContext`) | site layout + Starlight (`src/src/scripts/webmcp.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 | @@ -283,6 +292,12 @@ the file is missing or points anywhere off-origin (ADR 0017). The document must served as `application/linkset+json`, which a static host cannot set for an extension-less file — the edge Worker sets it. +`.well-known/` is a **dot-directory**, and `actions/upload-pages-artifact` drops +hidden files and directories by default. The deploy workflow therefore sets +`include-hidden-files: true` (`.github/workflows/deploy.yml`); without it the +catalog is built and validated in `dist/` but never reaches GitHub Pages, so the +Worker faithfully 404s the request. + ### Discovery `Link` headers (RFC 8288 / RFC 9727 §3) The homepage response advertises the machine-readable surface above in HTTP @@ -328,6 +343,96 @@ H1 does not name `auth.md`. Verify: curl -s https://purview.dev/auth.md | head -n 1 # expect: # auth.md ``` +### Agent, OAuth and commerce discovery (ADR 0020) + +Agent tooling also probes four further standard paths. purview.dev has no agent task +server, no login and no commerce, so each document is generated to state that plainly — +an explicit stub beats a 404 an agent cannot interpret (ADR 0020): + +- **`/.well-known/agent-card.json`** — an A2A Agent Card. `supportedInterfaces` points + at the origin over `HTTP+JSON`, and a single skill describes the read-only + documentation surface. It names no task endpoint. +- **`/.well-known/oauth-authorization-server`** (RFC 8414) and + **`/.well-known/oauth-protected-resource`** (RFC 9728) — OAuth discovery metadata for + a site with nothing to protect. The protected-resource document names the origin as + its own authorization server and points `resource_documentation` at `/auth.md`; the + endpoints the authorization-server document lists (`/oauth/authorize`, + `/oauth/token`, `/.well-known/jwks.json`) are reserved and serve nothing. +- **`/.well-known/acp.json`** — an Agentic Commerce Protocol discovery document, shaped + to the spec so the (absent) commerce surface is discoverable; it states that the + origin sells nothing. + +Every document carries a top-level `_comment` that says what it is: a public, +no-credential origin with no task server and no commerce. This is the "explicit rather +than implied" rule of `/auth.md` (ADR 0019) applied to the paths an agent probes. The +`.json` paths are typed `application/json` by the host; the edge Worker sets that type +on the two extension-less OAuth paths, which a static host would otherwise serve as +`application/octet-stream` (ADR 0020). `discovery:validate` fails the build when any of +the four is missing or malformed. Verify: + +```shell +curl -s https://purview.dev/.well-known/agent-card.json +curl -s https://purview.dev/.well-known/oauth-protected-resource +curl -s https://purview.dev/.well-known/acp.json +``` + +### Skills, MCP, WebMCP and Web Bot Auth (ADR 0021) + +Four further surfaces an agent probes are generated the same way — and, where the +origin can genuinely serve them, made real rather than stubbed: + +- **`/.well-known/agent-skills/index.json`** — the Agent Skills Discovery index + (RFC v0.2.0). It lists every skill this origin publishes: the repository's own + skills (`purview-site-integration`, …), copied by the build under + `/.well-known/agent-skills//`, and the mirrored project skills at + `/skills///`. Each entry carries a `sha256:` digest of the `SKILL.md` + so a client can verify what it fetched. +- **`/.well-known/mcp/server-card.json`** — an MCP Server Card (SEP-1649) for the + read-only MCP server at `/mcp` (`worker/src/mcp.ts`). `serverInfo`, a + `streamable-http` transport whose endpoint is `https://purview.dev/mcp`, and + `capabilities` (`tools` and `resources` true, `prompts` false). +- **`/mcp`** — a dependency-free, read-only MCP server (Streamable HTTP). It + answers JSON-RPC `initialize`, `tools/list`, `tools/call` (`search_projects`, + `list_projects`, `get_project`), `resources/list`, `resources/read` and + `prompts/list`; it writes nothing and requires no credential. It is served by + the edge Worker, so it is deployed only when the Cloudflare secrets are set. +- **`/.well-known/http-message-signatures-directory`** — a Web Bot Auth JWKS. It + publishes the origin's Ed25519 public key so a receiving site can verify the + site's own outbound bot request. `discovery:indexnow` signs its request with + `Signature-Agent` / `Signature-Input` / `Signature`; the private key is the + `WEB_BOT_AUTH_PRIVATE_JWK` secret, generated with `bun run web-bot-auth:key`. +- **WebMCP** — `src/src/scripts/webmcp.ts` registers read-only page tools + (`search-projects`, `list-projects`, `open-page`) on `document.modelContext` + (falling back to `navigator.modelContext`) on page load, under one + `AbortController`. It is a no-op on a browser without the API. + +`discovery:validate` fails the build when the index, the card or the JWKS +directory is missing or malformed. Verify: + +```shell +curl -s https://purview.dev/.well-known/agent-skills/index.json +curl -s https://purview.dev/.well-known/mcp/server-card.json +curl -s https://purview.dev/.well-known/http-message-signatures-directory +curl -s -X POST https://purview.dev/mcp -H 'content-type: application/json' \ + -d '{"jsonrpc":"2.0","id":1,"method":"tools/list"}' +``` + +#### DNS for AI Discovery (DNS-AID) + +DNS-AID publishes agent endpoints in DNS under the `_agents` namespace. The zone +is controlled separately from this repository, so this is a **one-time operator +step** — the build cannot create it. Publish `SVCB` (or `HTTPS`) records that name +each endpoint with its `alpn` and port, and sign the zone with DNSSEC: + +```dns +_index._agents.purview.dev. 3600 IN HTTPS 1 purview.dev. alpn="h2" port=443 mandatory=alpn,port +_a2a._agents.purview.dev. 3600 IN SVCB 1 purview.dev. alpn="a2a" port=443 mandatory=alpn,port +_mcp._agents.purview.dev. 3600 IN SVCB 1 purview.dev. alpn="mcp" port=443 mandatory=alpn,port +``` + +The scanner resolves these over DNS-over-HTTPS; a validating resolver must return +authenticated data, so DNSSEC signing is required for the check to pass. + ## Local development IndexNow never runs during normal local development: it requires an explicit @@ -359,6 +464,12 @@ Automated (nothing to do per deploy): RFC 9727 §3) — ADR 0018 - [x] `/auth.md` generated for a no-login site (Auth.md; states there is nothing to register) — ADR 0019 +- [x] A2A Agent Card, OAuth and ACP discovery documents generated for a no-login, + non-commerce site — ADR 0020 +- [x] Agent Skills index, MCP Server Card and Web Bot Auth JWKS directory + generated — ADR 0021 +- [x] Read-only MCP server at `/mcp` (edge Worker) — ADR 0021 +- [x] WebMCP page tools registered on page load — ADR 0021 One-time (operator): @@ -388,6 +499,20 @@ One-time (operator): 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) +- [ ] Verify `https://purview.dev/.well-known/agent-card.json` and + `https://purview.dev/.well-known/acp.json` (the host types them `application/json`) +- [ ] Verify `https://purview.dev/.well-known/oauth-protected-resource` and + `https://purview.dev/.well-known/oauth-authorization-server` return + `application/json` (the Worker sets the type; ADR 0020) +- [ ] Set `WEB_BOT_AUTH_PRIVATE_JWK` (from `bun run web-bot-auth:key`) so the + IndexNow request is signed (ADR 0021) +- [ ] Verify `https://purview.dev/.well-known/agent-skills/index.json`, + `https://purview.dev/.well-known/mcp/server-card.json` and + `https://purview.dev/.well-known/http-message-signatures-directory` +- [ ] Verify the read-only MCP endpoint + (`curl -s -X POST https://purview.dev/mcp -H 'content-type: application/json' -d '{"jsonrpc":"2.0","id":1,"method":"tools/list"}'`) +- [ ] Publish the DNS-AID `_agents` SVCB/HTTPS records and sign the zone with + DNSSEC (ADR 0021) ## Security diff --git a/package.json b/package.json index f5bfe08..fa33d3a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "purview-dev", - "version": "0.12.0", + "version": "0.13.0", "private": true, "description": "Purview-Dev public website and unified documentation portal (workspace root).", "license": "MIT", @@ -34,7 +34,8 @@ "test": "bun run --cwd src test", "test:dist": "bun run --cwd src test:dist", "typecheck": "bun run --cwd src typecheck", - "upstream:state": "bun run --cwd src upstream:state" + "upstream:state": "bun run --cwd src upstream:state", + "web-bot-auth:key": "bun run --cwd src web-bot-auth:key" }, "engines": { "bun": ">=1.4.4", diff --git a/src/package.json b/src/package.json index 69bad8d..346cec6 100644 --- a/src/package.json +++ b/src/package.json @@ -30,7 +30,8 @@ "test": "bun test tests/unit", "test:dist": "bun test tests/dist", "typecheck": "astro check", - "upstream:state": "bun run scripts/upstream-state.ts" + "upstream:state": "bun run scripts/upstream-state.ts", + "web-bot-auth:key": "bun run scripts/web-bot-auth-key.ts" }, "dependencies": { "@astrojs/markdown-satteri": "0.4.9", diff --git a/src/scripts/check-generated.ts b/src/scripts/check-generated.ts index b07fda3..dfcb7fd 100644 --- a/src/scripts/check-generated.ts +++ b/src/scripts/check-generated.ts @@ -312,6 +312,16 @@ async function run(): Promise { requireDistFile('discover.json'); requireDistFile('robots.txt'); requireDistFile('auth.md'); + // Agent-readiness discovery surfaces (ADR 0020): the standard paths an agent + // probes, generated for this public site so they resolve instead of 404ing. + requireDistFile('.well-known/agent-card.json'); + requireDistFile('.well-known/oauth-authorization-server'); + requireDistFile('.well-known/oauth-protected-resource'); + requireDistFile('.well-known/acp.json'); + // Agent Skills, MCP and Web Bot Auth surfaces (ADR 0021). + requireDistFile('.well-known/agent-skills/index.json'); + requireDistFile('.well-known/mcp/server-card.json'); + requireDistFile('.well-known/http-message-signatures-directory'); validateProjectLlmsBundles(); validateProjectAssets(); diff --git a/src/scripts/discovery/validate.ts b/src/scripts/discovery/validate.ts index 8f6fa2a..508f007 100644 --- a/src/scripts/discovery/validate.ts +++ b/src/scripts/discovery/validate.ts @@ -3,14 +3,22 @@ import type { DiscoverableResource } from '../../src/lib/discovery/types'; import { existsSync, readFileSync, statSync } from 'node:fs'; import { resolve } from 'node:path'; +import { AGENT_SKILLS_SCHEMA } from '../../src/lib/discovery/agent-skills'; import { documentedProjects, loadDiscoveryContext } from '../../src/lib/discovery/resources'; import { DISCOVERY_MANIFEST_SCHEMA_VERSION } from '../../src/lib/discovery/types'; import { + ACP_DISCOVERY_PATH, + AGENT_CARD_PATH, + AGENT_SKILLS_INDEX_PATH, API_CATALOG_PATH, AUTH_MD_PATH, DISCOVER_JSON_PATH, + MCP_SERVER_CARD_PATH, + OAUTH_AUTHORIZATION_SERVER_PATH, + OAUTH_PROTECTED_RESOURCE_PATH, ROBOTS_PATH, SITEMAP_INDEX_PATH, + WEB_BOT_AUTH_DIRECTORY_PATH, isCanonicalUrl, projectChannelLlmsFullUrl, projectChannelLlmsUrl, @@ -29,8 +37,9 @@ import { loadProjects } from '../../src/lib/manifest/load'; * genuine discovery errors (missing files, malformed XML, non-absolute or * off-origin URLs, duplicate canonicals, a robots.txt that does not advertise * 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). + * valid on-origin linkset, an A2A Agent Card, OAuth metadata or ACP document + * that is missing a required field, 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; @@ -187,6 +196,308 @@ export function validateAuthMd(content: string): string[] { return []; } +/** Whether a value is an absolute `http(s)` URL. */ +function isAbsoluteHttpUrl(value: unknown): value is string { + return typeof value === 'string' && /^https?:\/\/[^\s/]+/i.test(value); +} + +/** Parse JSON, returning either the object or a single prefixed error. */ +function parseJsonObject(content: string, label: string): Record | string[] { + let parsed: unknown; + try { + parsed = JSON.parse(content); + } catch { + return [`${label} is not valid JSON.`]; + } + if (typeof parsed !== 'object' || parsed === null || Array.isArray(parsed)) { + return [`${label} is not a JSON object.`]; + } + return parsed as Record; +} + +/** + * Validate the A2A Agent Card (`/.well-known/agent-card.json`). + * + * The A2A spec's required fields are enforced — a non-empty `name`, `version` + * and `description`, a `supportedInterfaces` entry with an absolute service URL + * and a transport, a `capabilities` object, and at least one `skills` entry with + * `id`, `name` and `description` — so the card an agent reads is never + * half-formed. ADR 0020. + */ +export function validateAgentCard(content: string): string[] { + const card = parseJsonObject(content, 'agent-card'); + if (Array.isArray(card)) { + return card; + } + const errors: string[] = []; + for (const field of ['name', 'version', 'description']) { + const value = card[field]; + if (typeof value !== 'string' || value.trim().length === 0) { + errors.push(`agent-card is missing a non-empty "${field}".`); + } + } + const interfaces = card.supportedInterfaces; + if (!Array.isArray(interfaces) || interfaces.length === 0) { + errors.push('agent-card has no supportedInterfaces.'); + } else { + interfaces.forEach((raw, index) => { + const entry = raw as Record; + if (!isAbsoluteHttpUrl(entry.url)) { + errors.push(`agent-card supportedInterfaces[${index}] has no absolute service URL.`); + } + const transport = entry.transport ?? entry.protocolBinding; + if (typeof transport !== 'string' || transport.trim().length === 0) { + errors.push(`agent-card supportedInterfaces[${index}] declares no transport protocol.`); + } + }); + } + if (typeof card.capabilities !== 'object' || card.capabilities === null) { + errors.push('agent-card declares no capabilities.'); + } + const skills = card.skills; + if (!Array.isArray(skills) || skills.length === 0) { + errors.push('agent-card lists no skills.'); + } else { + skills.forEach((raw, index) => { + const skill = raw as Record; + for (const field of ['id', 'name', 'description']) { + const value = skill[field]; + if (typeof value !== 'string' || value.trim().length === 0) { + errors.push(`agent-card skills[${index}] is missing a non-empty "${field}".`); + } + } + }); + } + return errors; +} + +/** + * Validate the OAuth authorization-server metadata + * (`/.well-known/oauth-authorization-server`, RFC 8414 / OIDC Discovery). + * + * The four endpoints the RFC requires are checked to be absolute URLs and the + * two capability lists the readiness check looks for must be present and + * non-empty. The document is a no-auth stub (ADR 0020), so only its shape is + * enforced — the site does not serve the flows it describes. + */ +export function validateOAuthAuthorizationServerMetadata(content: string): string[] { + const metadata = parseJsonObject(content, 'oauth-authorization-server'); + if (Array.isArray(metadata)) { + return metadata; + } + const errors: string[] = []; + for (const field of ['issuer', 'authorization_endpoint', 'token_endpoint', 'jwks_uri']) { + if (!isAbsoluteHttpUrl(metadata[field])) { + errors.push(`oauth-authorization-server "${field}" is not an absolute URL.`); + } + } + for (const field of ['grant_types_supported', 'response_types_supported']) { + const value = metadata[field]; + if (!Array.isArray(value) || value.length === 0) { + errors.push(`oauth-authorization-server "${field}" is missing or empty.`); + } + } + return errors; +} + +/** + * Validate the OAuth protected-resource metadata + * (`/.well-known/oauth-protected-resource`, RFC 9728). + * + * `resource` must be an absolute URL and `authorization_servers` a non-empty + * array of absolute URLs, so a client can always find the (here, no-auth) + * authorization server the resource names. ADR 0020. + */ +export function validateOAuthProtectedResourceMetadata(content: string): string[] { + const metadata = parseJsonObject(content, 'oauth-protected-resource'); + if (Array.isArray(metadata)) { + return metadata; + } + const errors: string[] = []; + if (!isAbsoluteHttpUrl(metadata.resource)) { + errors.push('oauth-protected-resource "resource" is not an absolute URL.'); + } + const servers = metadata.authorization_servers; + if (!Array.isArray(servers) || servers.length === 0) { + errors.push('oauth-protected-resource lists no authorization_servers.'); + } else { + servers.forEach((server, index) => { + if (!isAbsoluteHttpUrl(server)) { + errors.push( + `oauth-protected-resource authorization_servers[${index}] is not an absolute URL.`, + ); + } + }); + } + return errors; +} + +/** + * Validate the ACP discovery document (`/.well-known/acp.json`). + * + * `protocol.name` must be `"acp"` with a `protocol.version`, `api_base_url` an + * absolute `http(s)` URL, `transports` a non-empty array, and + * `capabilities.services` a non-empty array. The document is a non-commerce stub + * for this site (ADR 0020), so only its shape is enforced. + */ +export function validateAcpDiscovery(content: string): string[] { + const document = parseJsonObject(content, 'acp'); + if (Array.isArray(document)) { + return document; + } + const errors: string[] = []; + const protocol = document.protocol as Record | undefined; + if (typeof protocol !== 'object' || protocol === null) { + errors.push('acp has no protocol object.'); + } else { + if (protocol.name !== 'acp') { + errors.push('acp protocol.name is not "acp".'); + } + if (typeof protocol.version !== 'string' || protocol.version.trim().length === 0) { + errors.push('acp protocol.version is missing.'); + } + } + if (!isAbsoluteHttpUrl(document.api_base_url)) { + errors.push('acp api_base_url is not an absolute URL.'); + } + const transports = document.transports; + if (!Array.isArray(transports) || transports.length === 0) { + errors.push('acp lists no transports.'); + } + const capabilities = document.capabilities as Record | undefined; + const services = capabilities?.services; + if (!Array.isArray(services) || services.length === 0) { + errors.push('acp capabilities.services is missing or empty.'); + } + return errors; +} + +/** SHA-256 digest form the Agent Skills Discovery RFC requires. */ +const AGENT_SKILL_DIGEST = /^sha256:[0-9a-f]{64}$/; +/** A skill name: lowercase alphanumeric with internal hyphens (1-64 chars). */ +const AGENT_SKILL_NAME = /^[a-z0-9](?:[a-z0-9-]{0,62}[a-z0-9])?$/; + +/** + * Validate the Agent Skills Discovery index + * (`/.well-known/agent-skills/index.json`). + * + * The RFC pins the `$schema`, and every entry must carry a compliant `name`, a + * `type` of `skill-md` or `archive`, a non-empty `description`, a `url` and a + * `sha256:` digest so a client can verify what it fetched. ADR 0021. + */ +export function validateAgentSkillsIndex(content: string): string[] { + const index = parseJsonObject(content, 'agent-skills index'); + if (Array.isArray(index)) { + return index; + } + const errors: string[] = []; + if (index.$schema !== AGENT_SKILLS_SCHEMA) { + errors.push(`agent-skills index "$schema" is not ${AGENT_SKILLS_SCHEMA}.`); + } + const skills = index.skills; + if (!Array.isArray(skills) || skills.length === 0) { + errors.push('agent-skills index lists no skills.'); + return errors; + } + skills.forEach((raw, position) => { + const skill = raw as Record; + if (typeof skill.name !== 'string' || !AGENT_SKILL_NAME.test(skill.name)) { + errors.push(`agent-skills skills[${position}] has an invalid name.`); + } + if (skill.type !== 'skill-md' && skill.type !== 'archive') { + errors.push(`agent-skills skills[${position}] has an invalid type.`); + } + if (typeof skill.description !== 'string' || skill.description.trim().length === 0) { + errors.push(`agent-skills skills[${position}] has no description.`); + } + if (typeof skill.url !== 'string' || skill.url.trim().length === 0) { + errors.push(`agent-skills skills[${position}] has no url.`); + } + if (typeof skill.digest !== 'string' || !AGENT_SKILL_DIGEST.test(skill.digest)) { + errors.push(`agent-skills skills[${position}] has no sha256 digest.`); + } + }); + return errors; +} + +/** + * Validate the Web Bot Auth JWKS directory + * (`/.well-known/http-message-signatures-directory`). + * + * It must carry at least one public key, and each key must include the material + * a verifier needs for its type (OKP `crv`/`x`, EC `crv`/`x`/`y`, RSA `n`/`e`, + * or `oct` `k`), so a receiving site can actually verify a signature. ADR 0021. + */ +export function validateWebBotAuthDirectory(content: string): string[] { + const directory = parseJsonObject(content, 'Web Bot Auth directory'); + if (Array.isArray(directory)) { + return directory; + } + const keys = directory.keys; + if (!Array.isArray(keys) || keys.length === 0) { + return ['Web Bot Auth directory contains no keys.']; + } + const errors: string[] = []; + keys.forEach((raw, position) => { + const key = raw as Record; + const has = (field: string): boolean => typeof key[field] === 'string' && key[field] !== ''; + if (!has('kty')) { + errors.push(`Web Bot Auth key[${position}] has no "kty".`); + return; + } + if (key.kty === 'OKP' && !(has('crv') && has('x'))) { + errors.push(`Web Bot Auth key[${position}] (OKP) is missing "crv"/"x".`); + } else if (key.kty === 'EC' && !(has('crv') && has('x') && has('y'))) { + errors.push(`Web Bot Auth key[${position}] (EC) is missing "crv"/"x"/"y".`); + } else if (key.kty === 'RSA' && !(has('n') && has('e'))) { + errors.push(`Web Bot Auth key[${position}] (RSA) is missing "n"/"e".`); + } else if (key.kty === 'oct' && !has('k')) { + errors.push(`Web Bot Auth key[${position}] (oct) is missing "k".`); + } else if (!['OKP', 'EC', 'RSA', 'oct'].includes(String(key.kty))) { + errors.push(`Web Bot Auth key[${position}] has an unknown "kty".`); + } + }); + return errors; +} + +/** + * Validate the MCP Server Card (`/.well-known/mcp/server-card.json`). + * + * Per SEP-1649 the card must name the server (`serverInfo.name` and `version`), + * give a transport with an `endpoint` URL (`url` is accepted as its equivalent), + * and declare `capabilities`. The endpoint is the read-only server in + * `worker/src/mcp.ts`; ADR 0021. + */ +export function validateMcpServerCard(content: string): string[] { + const card = parseJsonObject(content, 'mcp server card'); + if (Array.isArray(card)) { + return card; + } + const errors: string[] = []; + const info = card.serverInfo as Record | undefined; + if (typeof info !== 'object' || info === null) { + errors.push('mcp server card has no serverInfo.'); + } else { + for (const field of ['name', 'version']) { + const value = info[field]; + if (typeof value !== 'string' || value.trim().length === 0) { + errors.push(`mcp server card serverInfo is missing a non-empty "${field}".`); + } + } + } + const transport = card.transport as Record | undefined; + if (typeof transport !== 'object' || transport === null || typeof transport.type !== 'string') { + errors.push('mcp server card declares no transport type.'); + } + if (!isAbsoluteHttpUrl(transport?.endpoint ?? card.url)) { + errors.push('mcp server card declares no transport endpoint URL.'); + } + if (typeof card.capabilities !== 'object' || card.capabilities === null) { + errors.push('mcp server card declares no capabilities.'); + } + return errors; +} + export function validateDiscovery( dist = resolve('dist'), options: DiscoveryValidationOptions = {}, @@ -310,6 +621,51 @@ export function validateDiscovery( } } + // --- agent-readiness discovery surfaces (ADR 0020) ---------------------- + // Each standard path must resolve to a well-formed document, so an agent that + // probes it gets the site's truthful, no-auth / no-commerce answer rather than + // a 404. The Worker sets the media type for the extension-less paths. + const discoverySurfaces: { + path: string; + label: string; + validate: (content: string) => string[]; + }[] = [ + { path: AGENT_CARD_PATH, label: 'agent card', validate: validateAgentCard }, + { + path: OAUTH_AUTHORIZATION_SERVER_PATH, + label: 'OAuth authorization-server metadata', + validate: validateOAuthAuthorizationServerMetadata, + }, + { + path: OAUTH_PROTECTED_RESOURCE_PATH, + label: 'OAuth protected-resource metadata', + validate: validateOAuthProtectedResourceMetadata, + }, + { path: ACP_DISCOVERY_PATH, label: 'ACP discovery document', validate: validateAcpDiscovery }, + { + path: AGENT_SKILLS_INDEX_PATH, + label: 'Agent Skills index', + validate: validateAgentSkillsIndex, + }, + { path: MCP_SERVER_CARD_PATH, label: 'MCP server card', validate: validateMcpServerCard }, + { + path: WEB_BOT_AUTH_DIRECTORY_PATH, + label: 'Web Bot Auth directory', + validate: validateWebBotAuthDirectory, + }, + ]; + for (const surface of discoverySurfaces) { + const content = readDist(surface.path); + if (!content) { + fail(`Missing ${surface.label}: ${surface.path}`); + continue; + } + scanForDevUrls(surface.label, content); + for (const error of surface.validate(content)) { + fail(error); + } + } + // --- root llms files ----------------------------------------------------- // Note: the LLM bundles are documentation content and may legitimately show // `localhost` examples, so the development-URL scan is applied only to the diff --git a/src/scripts/web-bot-auth-key.ts b/src/scripts/web-bot-auth-key.ts new file mode 100644 index 0000000..b8ab9fe --- /dev/null +++ b/src/scripts/web-bot-auth-key.ts @@ -0,0 +1,35 @@ +import { createHash, generateKeyPairSync } from 'node:crypto'; +import { mkdirSync, writeFileSync } from 'node:fs'; +import { resolve } from 'node:path'; + +/** + * `bun run web-bot-auth:key` + * + * Generate the Ed25519 key pair behind Web Bot Auth (ADR 0021). The **public** + * key is printed in the JWK form that goes into + * `lib/discovery/web-bot-auth.ts` (the committed + * `/.well-known/http-message-signatures-directory`); the **private** key is + * written to `src/.cache/web-bot-auth/private.jwk` (gitignored) so it can be set + * as the `WEB_BOT_AUTH_PRIVATE_JWK` repository secret that signs outbound + * requests. Neither key is committed: only the operator places the private half + * in the secret store. + */ + +const { publicKey, privateKey } = generateKeyPairSync('ed25519'); +const pub = publicKey.export({ format: 'jwk' }) as { kty: string; crv: string; x: string }; +const priv = privateKey.export({ format: 'jwk' }); + +// RFC 7638 JWK thumbprint: the `kid` receivers use to select the key. +const thumbprint = JSON.stringify({ crv: pub.crv, kty: pub.kty, x: pub.x }); +const kid = createHash('sha256').update(thumbprint).digest('base64url'); +const publicJwk = { kty: pub.kty, crv: pub.crv, x: pub.x, alg: 'Ed25519', use: 'sig', kid }; + +const directory = resolve('.cache', 'web-bot-auth'); +mkdirSync(directory, { recursive: true }); +const privateFile = resolve(directory, 'private.jwk'); +writeFileSync(privateFile, `${JSON.stringify(priv, null, 2)}\n`, 'utf8'); + +console.log('Public key — paste into lib/discovery/web-bot-auth.ts (WEB_BOT_AUTH_PUBLIC_KEY):\n'); +console.log(JSON.stringify(publicJwk, null, 2)); +console.log(`\nPrivate key written to ${privateFile}`); +console.log('Set it as the WEB_BOT_AUTH_PRIVATE_JWK repository secret to sign outbound requests.'); diff --git a/src/src/components/starlight/Head.astro b/src/src/components/starlight/Head.astro index 3a48a67..fc25b46 100644 --- a/src/src/components/starlight/Head.astro +++ b/src/src/components/starlight/Head.astro @@ -166,3 +166,6 @@ const structuredData = + diff --git a/src/src/layouts/SiteLayout.astro b/src/src/layouts/SiteLayout.astro index f198970..41f5c2e 100644 --- a/src/src/layouts/SiteLayout.astro +++ b/src/src/layouts/SiteLayout.astro @@ -75,6 +75,9 @@ const ogImage = absoluteUrl(image ?? '/og/default.png'); + { structuredData && (