# Agent Page Protocol

Agent-first web browsing protocol. Structured JSON page manifests replace HTML/DOM as the canonical page representation. A Chrome extension renders manifests for humans.

Two audiences, one source of truth.

## Status

Draft **v0.5** (wire 1.0 + 1.1) - specification, reference implementation, and agent tool layer. 6 workspaces, 435 tests green (conformance: 142 protocol vectors).

## Repository layout

| Path | Description |
|------|-------------|
| [`SPEC.md`](SPEC.md) | Full protocol specification (wire 1.0) |
| [`CLIENT-TOOL-CONTRACT.md`](CLIENT-TOOL-CONTRACT.md) | Normative contract for the CLI and MCP tool layer (tool-contract 1.0) |
| [`schema/`](schema/) | JSON Schema (`manifest`, `state-node`, `diff-document`, `action-request`, `error-envelope`, tool session schemas) |
| [`packages/server`](packages/server/) | `@agent-page/server` - Express middleware: negotiation, diffs, CSRF, idempotency, confirmation, async, well-known |
| [`packages/client`](packages/client/) | `@agent-page/client` - agent SDK: cache, hydrate, diff, policy, navigation, action dispatch |
| [`packages/conformance`](packages/conformance/) | `@agent-page/conformance` - 142 protocol vectors + auth/idempotency/confirmation/CSRF/events suites |
| [`packages/tool-core`](packages/tool-core/) | `@agent-page/tool-core` - shared session store, digests, holds, credentials resolver |
| [`packages/cli`](packages/cli/) | `@agent-page/cli` (`agent-page`) - stateful CLI: open, act, confirm, challenge, watch, discover |
| [`packages/mcp`](packages/mcp/) | `@agent-page/mcp` - MCP server: 10 fixed tools (`app_discover` ... `app_reset`) |
| [`extension/`](extension/) | Chrome MV3 renderer (vanilla JS; load unpacked) |
| [`examples/flights`](examples/flights/) | Appendix D flight booking example (search → filter → book → pay) |

## Getting started

```bash
npm install
npm run build
npm test
```

### Chrome extension

1. Open `chrome://extensions`
2. Enable **Developer mode**
3. **Load unpacked** → select [`extension/`](extension/)
4. Use the toolbar popup for per-origin Accept rewriting / Render APP toggles

### Flights example

```bash
npm run example:flights
# listens on http://localhost:3456
```

Happy path: `GET /flights` → search → results table → `filter` diff → `select_flight` → `confirm_booking` (428 challenge → confirmed diff).

### Shirt shop prompt demo

```bash
npm run waypoint
# opens the prompt UI at http://127.0.0.1:5173
```

Describe a shirt to find (for example, “Find a navy tee in large”). Waypoint uses the local APP shirt-shop mock and pauses for approval before placing the order. `npm run test:waypoint` runs the focused integration tests.

## Media types

| Media type | Purpose |
|------------|---------|
| `application/vnd.agent-page+json` | Page Manifest |
| `application/vnd.agent-page-diff+json` | Diff Document |
| `application/vnd.agent-page-error+json` | Error Envelope |
| `application/vnd.agent-page-action+json` | Action Request |

Key headers: `X-APP-Version`, `X-APP-Page-Id`, `X-APP-Response-Mode`, `X-APP-Client`, `X-APP-Idempotency-Key`, `X-APP-If-Match-Version`, `X-APP-Confirmation`, `X-APP-Origin`.

## Spec

See [`SPEC.md`](SPEC.md) for the full protocol (wire format, security, extension architecture, conformance).
