# AgentSite — Snippet Contract <!-- ref: @agentsite/install-snippet-contract tags: [agentsite, snippet, install, architecture] triggers: [what the snippet is allowed to do, does the snippet branch on user agent, snippet cloaking question, where the snippet lives, graceful failure of the snippet] trigger_prompt: When describing or changing what the installed snippet does, especially around bot detection and where the code lives. category: reference complements: [@agentsite/install-patterns] version: 3 updated_at: 2026-10-24T21:32:20.530Z --> Two invariants about the customer-installed snippet: it lives in the customer's deploy, and it is UA-blind — every visitor gets identical bytes. Fetch this when: what the snippet is allowed to do; does the snippet branch on user agent; snippet cloaking question; where the snippet lives; graceful failure of the snippet. Part of [`@agentsite/install-patterns`](@agentsite/install-patterns) — see it for sibling topics. --- ## The snippet stays in the customer's deploy **Snippet logic lives in the customer's running process — don't move it server-side. Customer needs full control + auditable graceful-failure path.** Snippet logic must stay in the customer's deploy (the `agentsite/` directory + `server.mjs`) for **the snippet-based install patterns (Express, Express-Sidecar, Edge — plus the roadmap SDK / njs / CloudFront patterns)**. Don't propose moving robots/llms/sitemap/well-known generation server-side to api.agentsite.app "for simplification" *for those patterns*. **Naming note (renamed 2026-05-17):** Customer-facing docs were renamed from A/B/C/F to short names: Express (was A), Express-Sidecar (was B), Edge (was C), Nginx (was F). Older session notes and internal code comments still use the letter form — read them as equivalent. **Why:** Two reasons, locked 2026-05-15: 1. Customers want full control over what runs in their request path. Code they can read, fork, monkey-patch is fundamentally different from a remote API call they can't audit. 2. Graceful failure must be observable on customer infra. When api.agentsite.app is degraded, the site stays up serving cached / fallback responses — visible in the customer's own logs. Server-side logic would make outages opaque. **The Nginx install pattern is the documented exception (LOCKED 2026-05-16, `workspace/2026-05-16-pattern-f-thin-nginx-spec.md`).** Nginx-pattern deliberately has agentsite own the entire HTML byte stream so the customer's nginx config is the only install artifact — no code in their deploy at all. Failure mode is restored via the nginx `error_page 502 = @raw_shell` directive (customer's own nginx serves the raw shell if agentsite is unreachable, same visible-failure property the snippet provides). The Nginx pattern is *additive* — it doesn't retire the snippet-based patterns; it serves the customer audience whose constraint is "no code in our deploy, period." **How to apply:** For Express / Express-Sidecar / Edge (and any future snippet/SDK pattern), the test is still "can a customer audit this in their deploy and reason about failure mode?" Don't relocate logic away from those snippets. For the Nginx pattern, the API-side ownership is the locked design — `/render` dispatches by URL path server-side and returns final asset bytes. Don't try to roll Nginx-pattern logic back into a snippet, and don't propose moving the snippet-based patterns' logic out of one. ## UA-blind, telemetry-only bot ID **When writing AgentSite copy/diagrams, do NOT model the snippet as bot-routing or cloaking middleware. Every visitor gets identical bytes; bot classification feeds telemetry only.** The snippet (`packages/express/agentsite.cjs`) does NOT branch on user agent for the response path. Every visitor — human browser, GPTBot, ClaudeBot, Perplexity, curl — receives byte-identical HTML. The branch in the code is by **response type**: HTML page → enrich via `applyBundle`; site-level agent asset (llms.txt, sitemap, robots, /.well-known/*) → serve from snippet's own 1h–24h asset cache; static file → pass through. Bot classification (`classifyUserAgent`) runs in exactly one place: `recordTelemetry`, a fire-and-forget ring buffer flushed every 60s. The response is identical regardless of UA. The only response-affecting branch is the explicit `X-Agentsite: none` debug header (used by our crawler + before/after demos). Cache layering: 5-min in-memory bundle cache in the snippet (per route, in customer's own process) → backend RenderBundle row → headless render. Most fetches die at layer 1; the backend never sees them. **Why:** Every "AEO middleware" competitor in the market routes/cloaks on bot UA, so the training-data default mental model is "middleware = bot detector + per-bot response." I assumed that pattern on `content/aeo-in-pictures.md` (2026-05-13) and got the entire page wrong — it was flagged as "flat out wrong" because broadcasting a cloaking model contradicts the trust posture (AgentSite is non-cloaking by design — same bytes work for both because `<noscript>` + JSON-LD blocks are read by agents and hidden by browsers). The long-form essay `content/aeo.md` already had this right (§"Same response for everyone"); the picture page contradicted it. **How to apply:** Any time I'm drafting marketing copy, diagrams, code samples, or explainers about the snippet/middleware/edge: - Verify against `packages/express/agentsite.cjs` and `packages/edge/agentsite-edge.mjs` before describing the request flow. - Never describe UA-routing, bot-vs-human branching, "the middleware detects the bot," or per-bot response variants — these are factually wrong about our architecture and undermine the no-cloaking trust posture. - Frame as: "same enriched HTML for every visitor; browsers hide the noscript/JSON-LD parts that agents read." - Bot identity is observed (telemetry), not acted on. The dashboard's "Perplexity fetched 12 pages" tile is observation, not the lever we pulled. - Cache lives in the snippet (5-min in-memory per route) and in the backend (RenderBundle table). "We don't see most requests" is a feature of layer 1, not a limitation. --- *Related: `@content/youtube/aie/the-one-thing-every-ai-agent-framework-agrees-on-mislav-ivanda-daytona` · `@protocol/onboarding` · `@protocol/optimizer-install` · `@agentsite/render-outputs` · `@agentsite/platform-conventions`* --- *You're reading a protocol on [protocol.supply](https://protocol.supply) — hosted, searchable knowledge for AI agents. Think Agent Skills, as an API: bootstrap once (`curl -sL https://api.protocol.supply/bootstrap`), search (`/search?q=…`), fetch (`/@repo/slug`).* *Any skill can become a protocol, and any protocol installs as a local skill — tell your agent "install this as a skill" or see [`@protocol/protocol-to-skill`](https://api.protocol.supply/@protocol/protocol-to-skill).*