# ADR: Live Variant Mode **Status:** Implemented **Date:** 2026-04-12 **Author:** Paul Bakaus + Claude ## Context Impeccable is a design skill for AI coding agents. It teaches AI harnesses (Claude Code, Cursor, Gemini CLI, Codex, etc.) how to produce better frontend design. The skill has 23 commands (bolder, quieter, polish, typeset, etc.) that the agent runs on source code. The missing piece: there was no way to visually iterate on a live page. The user could ask the agent to "make this bolder," but they had to read the code diff, reload the page, and decide if they liked it. If not, they'd ask again, wait, reload, repeat. Slow and disconnected. **Goal:** Let the user select an element directly in the browser, pick a design action, and see N real HTML+CSS variants hot-swapped in. Cycle through them visually, accept or discard, repeat. The agent generates the variants; the browser shows them. ## Decision Build a self-contained live variant mode that ships as part of the impeccable skill (no separate npm install required). The system bridges three parties: the **browser** (where the user picks elements and cycles variants), the **server** (a localhost HTTP server that relays messages), and the **agent** (the AI that generates variants by modifying source files). ### Key architectural decisions **1. Source modification, not DOM patching.** Variants are written to the actual source file, not injected into the browser DOM. This means: - Framework state (React, Vue, etc.) is preserved because the framework's own rendering pipeline handles the update via HMR. - "Accept" is trivial: the winning variant is already in the source. Just remove the other variants. - Variants are real code that the user can inspect in their editor, diff, and commit. **2. SSE + fetch, not WebSocket.** Server-Sent Events (server to browser) + fetch POST (browser to server) instead of WebSocket. This eliminates the `ws` npm dependency entirely. The server is zero-dependency pure Node.js (http, crypto, fs, net, os). This matters because the scripts ship inside the skill directory and run in the user's project without any package installation. **3. Self-contained skill scripts.** All live mode code lives in `skill/scripts/`: - `live-server.mjs` — HTTP server (SSE, poll, source file reader) - `live-poll.mjs` — CLI client for the agent poll/reply loop - `live-wrap.mjs` — CLI helper that finds elements in source and creates variant wrappers - `live-browser.js` — Browser script (element picker, action panel, variant cycler, global bar) When a user installs the skill via `npx skills add pbakaus/impeccable`, they get the live mode without any additional setup. The agent runs the scripts via `node {{scripts_path}}/live-server.mjs`. **4. HTTP long-poll for the agent, not WebSocket or stdin.** The agent communicates with the server via HTTP long-poll (`GET /poll` blocks until a browser event arrives). This works across all AI harnesses because every harness can run a shell command and read its stdout. No harness-specific integration needed. **5. `display: contents` variant wrapper.** Variants are wrapped in a container with `display: contents`, which makes the wrapper invisible to CSS layout. The selected element's relationship with its parent (flex child, grid child, etc.) is preserved. The wrapper carries `data-impeccable-variants` and `data-impeccable-variant-count` attributes that the browser script uses to detect and cycle variants. **6. No-HMR fallback.** For dev servers that don't support HMR (like Bun's static HTML import), the browser fetches the raw source file directly from the live server's `/source` endpoint and injects the variants into the DOM. This works universally, at the cost of losing framework state on that injection. ## Architecture ``` ┌─────────────────────────────────────────────────────────────────┐ │ BROWSER │ │ │ │ live-browser.js (injected via