# Install Live Agent Watch on this website

You are an AI coding assistant. The owner of this codebase wants to add **Live Agent Watch**, a
privacy-preserving monitor that tells them when AI agents visit their site. Follow these steps exactly.

## Rules you must follow

1. **Plan first.** Read the codebase and present a short plan to the owner. Do not change any file
   until the owner approves the plan.
2. **Never put secrets in code.** The site key is read from the environment variable
   `AGENTWATCH_SITE_KEY`. Do not ask the owner to paste the key into this chat. Do not write it into
   any file that is committed.
3. **Report, don't block.** Do not add blocking, rate limiting, redirects or response changes. The
   watcher only observes.
4. **Collect as little as possible.** Send ONLY: time, method, path (without anything after "?" or
   "#", redacted), status, duration_ms, client IP, user agent, and country (only from a header the
   host sets). Never send cookies, bodies, query strings or other headers.
5. **Fail open.** If Live Agent Watch is unreachable or slow, the site must behave exactly as before.
   Add a test that proves this.
6. **No packages.** Live Agent Watch has no npm, PyPI or Composer package. You write one small,
   dependency-free file from our reference snippet.
7. Do not edit robots.txt or sitemaps.

## Site details

- Site: {{site_name}} ({{site_url}}), sector: {{sector}}
- Public site id: {{public_id}}
- Endpoint: https://api.liveagentwatch.com

## Step 1 — Work out how the site is built

Identify the language and web framework, how HTML pages are produced (server-rendered templates or a
separately hosted frontend), and where it is hosted (Vercel, Cloudflare, Fly, Render, AWS behind a
load balancer, nginx, …). The host decides which header holds the real visitor IP.

## Step 2 — Read the contract and pick a snippet

- Watcher rules W1–W10 and the IP header for each host: https://api.liveagentwatch.com/spec/contract.md
- Reference snippets (Express, Next.js, Django, Flask, FastAPI, Laravel, WordPress):
  https://api.liveagentwatch.com/spec/snippets/README.md
- Protocol: https://api.liveagentwatch.com/spec/protocol.md
- Test vectors: https://api.liveagentwatch.com/spec/vectors/redact.json and
  https://api.liveagentwatch.com/spec/vectors/skip.json

For any other stack, follow the same flow as the snippets in the site's own language.

WordPress: use `php/wordpress.php` unchanged as a must-use plugin (`wp-content/mu-plugins/agentwatch.php`)
and put the canary note from Step 5 in place of its placeholder (the line between `<<<'HTML'` and
`HTML;`). It adds the note itself, so don't also edit the theme.

## Step 3 — Present the plan, then wait for approval

Include: the watcher file you will add (show its full code), the files you will change, where the
middleware goes (after proxy/real-IP setup, BEFORE auth and rate-limiting middleware), which header
gives the real visitor IP on this host and why, where the canary snippet goes, the tests you will
add, and the setting the owner must add in their host.

## Step 4 — Add the watcher

Add the watcher file and register it as planned.

## Step 5 — Add the canary note

- Server-rendered HTML: paste this once in the base layout, just before `</body>`:

  {{canary_snippet}}

- Separately hosted frontend (e.g. a React app on Vercel): add to its `index.html` `<head>`:
  `<script async src="https://api.liveagentwatch.com/c/{{public_id}}.js"></script>`
- Both, if the backend serves an API and the frontend is hosted separately.

## Step 6 — Test

- Run the redaction and skip test vectors against the watcher's functions in a unit test.
- Add a test that sets `AGENTWATCH_ENDPOINT=http://127.0.0.1:9` and checks a normal request returns
  the same status and body as without the watcher.
- Run the existing test suite.
- If `AGENTWATCH_SITE_KEY` is set locally, send one note your watcher produced to
  `POST https://api.liveagentwatch.com/v1/events?dry_run=1` and show the owner the response
  (expect `accepted: 1` and no warnings). If it isn't set, tell the owner the install page will
  confirm the connection after they deploy.

## Step 7 — Hand over to the owner

Tell the owner, in plain language:

1. Add `AGENTWATCH_SITE_KEY` in their hosting settings (link to their host's docs). The key is on
   their Live Agent Watch install page. WordPress: `define('AGENTWATCH_SITE_KEY', '…');` in
   wp-config.php instead.
2. Deploy.
3. Open their Live Agent Watch install page and wait for "First visit received". The page can also
   check that the canary note is on the home page.

List every file you changed.
