Validate Fidelity — Spec & Visual Drift Detection
Compare specs and running implementations against the reverse-UI oracle to catch drift before it ships.
Input: $ARGUMENTS = --phase <spec|visual|all> [--domain <NNN-name>] [--focus <component>] [--oracle <path>]
Arguments
--phase (required): spec | visual | all
spec — validate spec document against oracle JSON data
visual — validate running app against oracle screenshots + structure
all — run both phases sequentially for all matching domains
--domain (optional): spec number or name, e.g., 004-home, 002-app-shell. If omitted, validates all domains that have both a spec and an oracle source.
--focus (optional): component name to narrow scope, e.g., sidebar, module-card. Only validates requirements related to this component.
--oracle (optional): path to reverse-UI output directory. Auto-detected if omitted.
Examples
/validate-fidelity --phase spec --domain 004-home
/validate-fidelity --phase visual --domain 004-home
/validate-fidelity --phase all
/validate-fidelity --phase spec --domain 002-app-shell --focus sidebar
/validate-fidelity --phase spec --oracle ./reverse-ui-localhost-3000
Phase 0: Parse Input & Locate Oracle
- Parse
$ARGUMENTS for --phase, --domain, --focus, --oracle.
- If
--phase is missing, ask the user which phase to run.
- Locate the oracle in this priority order:
a.
--oracle flag (explicit path)
b. specs/assets/manifest.json → read meta.baseUrl to derive reverse-ui-{domain}/
c. Glob for reverse-ui-*/manifest.json in current working directory
d. Ask user if not found
- Verify the oracle directory exists and contains
manifest.json.
- If
--domain is specified, locate the corresponding spec file: specs/{domain}.md
- If
--domain is omitted, glob for all specs/*.md files and match each to an oracle page directory.
- Check for component-kit availability:
component-kit-{domain}/manifest.json — if present, use it for more precise validation.
Phase 1: Spec Validation (--phase spec)
Validate a spec document against the oracle's raw JSON data.
Step 1: Parse Spec Requirements
Read the spec .md file and extract each REQ-NNN-XX block. For each requirement, identify quantitative claims:
- Grid column counts
- Dimensions (width, height, gap)
- Color values (hex, rgb, rgba)
- Font families, sizes, weights
- Component counts (nav items, cards, sections)
- Text content (labels, titles, placeholders)
- Animation parameters (duration, easing, keyframes)
- Border radius, opacity, blur values
- Z-index values
- Breakpoint-specific behaviors
Step 2: Find Oracle Counterpart
For each claim, locate the matching data in the oracle:
| Claim type |
Oracle source |
| DOM structure, counts, text |
structure.json → sections, textContent |
| Computed styles, dimensions |
structure.json → nodes[].styles, boundingBox |
| Colors, typography, spacing |
design-tokens.json |
| Shadows, borders, effects |
design-tokens.json → shadows, borders |
| WebGL/shader parameters |
canvas.json → shaders, uniforms |
| Grid layout, responsive |
structure.json + structure-768.json + structure-375.json |
| Component blueprints |
component-kit/components/*.json (if available) |
| Page composition |
component-kit/layout/*.json (if available) |
| Semantic tokens |
component-kit/tokens/semantic-tokens.json (if available) |
If --focus is set, only process requirements whose REQ block or description mentions the focused component.
Step 3: Compare
For each claim, classify the result:
| Result |
Criteria |
Symbol |
| PASS |
Value matches oracle exactly |
✅ |
| WARN (close) |
Value within tolerance (±5% for dimensions, same color family for colors) |
⚠️ |
| FAIL |
Value contradicts oracle |
❌ |
| WARN (not in oracle) |
Claim has no counterpart in any JSON — possible invention |
⚠️ |
| INFO (omission) |
Oracle has data that spec doesn't mention |
ℹ️ |
Tolerance rules:
- Dimensions: ±5% or ±2px (whichever is larger)
- Colors: exact hex/rgb match required (no "close enough" for colors)
- Counts: exact match required (3 columns ≠ 2 columns)
- Text: case-insensitive match, trimmed whitespace
- Font families: primary family must match (fallback stack can differ)
Step 4: Output Fidelity Report
Validating spec {domain} against oracle...
Source: reverse-ui-{domain}/pages/{page}/structure.json
component-kit-{domain}/components/{component}.json (if available)
ERRORS (spec contradicts oracle):
❌ REQ-NNN-XX — {requirement title}
Spec: {spec value}
Oracle: {oracle value}
Source: {json file} → {json path}
❌ REQ-NNN-XX — {requirement title}
Spec: {spec value}
Oracle: {oracle value or "not found"}
Source: {json file} → {json path}
WARNINGS:
⚠️ {description of close match or unverifiable claim}
Spec: {spec value}
Oracle: {oracle value}
OMISSIONS (oracle has data, spec is silent):
ℹ️ {description of missing spec coverage}
Oracle: {oracle value}
Source: {json file} → {json path}
PASSES:
✅ REQ-NNN-XX — {requirement title} ({brief match detail})
✅ REQ-NNN-XX — {requirement title} ({brief match detail})
Score: {pass}/{total} requirements match | {error} errors, {warn} warnings, {omission} omissions
Phase 2: Visual Validation (--phase visual)
Validate a running application against the oracle's screenshots and structure data.
Step 1: Verify Dev Server
Check if the dev server is running:
npm run dev -- --port 5173 & # or detect from spec/oracle
If not running, ask the user to start it.
Step 2: Capture Current State
Use browser tools (mcp__claude-in-chrome__* or mcp__playwright__*) to:
- Navigate to the page URL
- Set viewport to 1440×900 (desktop)
- Take a screenshot
- Read the page structure (accessibility tree or DOM snapshot)
- Extract computed styles for key elements (grid columns, dimensions, colors, fonts)
Step 3: Structural Comparison
Compare the captured DOM against the oracle's structure.json:
| Check |
How |
| Nav item count + labels |
Count sidebar/nav children, compare text |
| Grid column count |
Read gridTemplateColumns computed style |
| Section order + presence |
Compare landmark sequence |
| Text content |
Compare headings, button labels, placeholder text |
| Component dimensions |
Compare bounding boxes (±10% tolerance) |
| Component presence |
Verify all oracle components exist in current DOM |
Step 4: Visual Comparison
Compare the captured screenshot against oracle screenshots:
| Check |
How |
| Key element presence |
WebGL canvas, badges, timestamps, avatars |
| Color tone |
Sidebar dark, cards light, accent colors |
| Layout proportions |
Sidebar width ratio, grid column balance |
| Responsive breakpoints |
Resize to 768px and 375px, compare against oracle tablet/mobile screenshots |
Step 5: Output Visual Fidelity Report
Same format as the spec report, but with screenshot references:
Validating visual output for {domain}...
Captured: {screenshot path}
Oracle: reverse-ui-{domain}/pages/{page}/screenshot-1440.png
STRUCTURAL ERRORS:
❌ Nav items — Expected {n} items, found {m}
Oracle: structure.json → sections[0].children (sidebar nav)
❌ Module grid — Expected {n} columns, found {m}
Oracle: structure.json → sections[2].styles.gridTemplateColumns
VISUAL ISSUES:
⚠️ {description of visual discrepancy}
PASSES:
✅ Sidebar present and dark-themed
✅ Hero heading text matches
✅ Search bar present with correct placeholder
Score: {pass}/{total} checks | {error} errors, {warn} warnings
Phase 3: All Validation (--phase all)
- Glob for all specs:
specs/*.md
- For each spec, run Phase 1 (spec validation)
- For each spec with a running page, run Phase 2 (visual validation)
- Output combined report with per-domain scores and overall score
=== Fidelity Report — All Domains ===
002-app-shell: Spec 8/10 ✅ | Visual 7/9 ✅
004-home: Spec 5/7 ⚠️ | Visual 6/8 ⚠️
005-ideation: Spec 9/9 ✅ | Visual — (no dev server)
Overall: 22/26 spec (84%) | 13/17 visual (76%)
Top issues:
1. ❌ 004-home REQ-004-06 — Module grid columns (2 vs 3)
2. ❌ 004-home REQ-004-05 — Search bar gradient (invented)
3. ❌ 002-app-shell REQ-002-03 — Nav item count (4 vs 8)
Oracle Path Resolution
The skill locates oracle data in this priority:
--oracle <path> — explicit, used as-is
specs/assets/manifest.json → read meta.baseUrl, derive domain, look for reverse-ui-{domain}/
reverse-ui-*/manifest.json — glob in cwd, use the first match (or ask if multiple)
component-kit-*/manifest.json — check alongside reverse-ui for enhanced validation
- Ask user if nothing found
Limitations
- Spec validation is only as good as the requirement extraction — freeform prose without
REQ-NNN-XX markers may be missed
- Visual validation requires a running dev server and browser automation tools
- Color comparison is exact (no perceptual color distance) — rgba(255,255,255,0.2) ≠ rgba(255,255,255,0.19)
- Screenshot comparison is structural, not pixel-diff — subtle spacing or shadow differences may not be caught
- Component-kit data (Phase 10 of reverse-ui) significantly improves validation precision — run
/reverse-ui with --components first for best results
- WebGL/canvas content cannot be structurally compared in visual mode — only presence/absence is checked
1---2name: validate-fidelity3description: Validate specs and implementations against the reverse-UI oracle. Catches drift before it ships. Use when checking if a spec accurately describes the original UI or if an implementation matches the original.4---56# Validate Fidelity — Spec & Visual Drift Detection78Compare specs and running implementations against the reverse-UI oracle to catch drift before it ships.910**Input:** `$ARGUMENTS` = `--phase <spec|visual|all> [--domain <NNN-name>] [--focus <component>] [--oracle <path>]`1112## Arguments1314- `--phase` (required): `spec` | `visual` | `all`15 - `spec` — validate spec document against oracle JSON data16 - `visual` — validate running app against oracle screenshots + structure17 - `all` — run both phases sequentially for all matching domains18- `--domain` (optional): spec number or name, e.g., `004-home`, `002-app-shell`. If omitted, validates all domains that have both a spec and an oracle source.19- `--focus` (optional): component name to narrow scope, e.g., `sidebar`, `module-card`. Only validates requirements related to this component.20- `--oracle` (optional): path to reverse-UI output directory. Auto-detected if omitted.2122### Examples2324```25/validate-fidelity --phase spec --domain 004-home26/validate-fidelity --phase visual --domain 004-home27/validate-fidelity --phase all28/validate-fidelity --phase spec --domain 002-app-shell --focus sidebar29/validate-fidelity --phase spec --oracle ./reverse-ui-localhost-300030```3132## Phase 0: Parse Input & Locate Oracle33341. Parse `$ARGUMENTS` for `--phase`, `--domain`, `--focus`, `--oracle`.352. If `--phase` is missing, ask the user which phase to run.363. Locate the oracle in this priority order:37 a. `--oracle` flag (explicit path)38 b. `specs/assets/manifest.json` → read `meta.baseUrl` to derive `reverse-ui-{domain}/`39 c. Glob for `reverse-ui-*/manifest.json` in current working directory40 d. Ask user if not found414. Verify the oracle directory exists and contains `manifest.json`.425. If `--domain` is specified, locate the corresponding spec file: `specs/{domain}.md`436. If `--domain` is omitted, glob for all `specs/*.md` files and match each to an oracle page directory.447. Check for component-kit availability: `component-kit-{domain}/manifest.json` — if present, use it for more precise validation.4546## Phase 1: Spec Validation (`--phase spec`)4748Validate a spec document against the oracle's raw JSON data.4950### Step 1: Parse Spec Requirements5152Read the spec `.md` file and extract each `REQ-NNN-XX` block. For each requirement, identify quantitative claims:5354- Grid column counts55- Dimensions (width, height, gap)56- Color values (hex, rgb, rgba)57- Font families, sizes, weights58- Component counts (nav items, cards, sections)59- Text content (labels, titles, placeholders)60- Animation parameters (duration, easing, keyframes)61- Border radius, opacity, blur values62- Z-index values63- Breakpoint-specific behaviors6465### Step 2: Find Oracle Counterpart6667For each claim, locate the matching data in the oracle:6869| Claim type | Oracle source |70|-----------|---------------|71| DOM structure, counts, text | `structure.json` → sections, textContent |72| Computed styles, dimensions | `structure.json` → nodes[].styles, boundingBox |73| Colors, typography, spacing | `design-tokens.json` |74| Shadows, borders, effects | `design-tokens.json` → shadows, borders |75| WebGL/shader parameters | `canvas.json` → shaders, uniforms |76| Grid layout, responsive | `structure.json` + `structure-768.json` + `structure-375.json` |77| Component blueprints | `component-kit/components/*.json` (if available) |78| Page composition | `component-kit/layout/*.json` (if available) |79| Semantic tokens | `component-kit/tokens/semantic-tokens.json` (if available) |8081If `--focus` is set, only process requirements whose REQ block or description mentions the focused component.8283### Step 3: Compare8485For each claim, classify the result:8687| Result | Criteria | Symbol |88|--------|----------|--------|89| **PASS** | Value matches oracle exactly | `✅` |90| **WARN (close)** | Value within tolerance (±5% for dimensions, same color family for colors) | `⚠️` |91| **FAIL** | Value contradicts oracle | `❌` |92| **WARN (not in oracle)** | Claim has no counterpart in any JSON — possible invention | `⚠️` |93| **INFO (omission)** | Oracle has data that spec doesn't mention | `ℹ️` |9495**Tolerance rules:**96- Dimensions: ±5% or ±2px (whichever is larger)97- Colors: exact hex/rgb match required (no "close enough" for colors)98- Counts: exact match required (3 columns ≠ 2 columns)99- Text: case-insensitive match, trimmed whitespace100- Font families: primary family must match (fallback stack can differ)101102### Step 4: Output Fidelity Report103104```105Validating spec {domain} against oracle...106107Source: reverse-ui-{domain}/pages/{page}/structure.json108 component-kit-{domain}/components/{component}.json (if available)109110ERRORS (spec contradicts oracle):111 ❌ REQ-NNN-XX — {requirement title}112 Spec: {spec value}113 Oracle: {oracle value}114 Source: {json file} → {json path}115116 ❌ REQ-NNN-XX — {requirement title}117 Spec: {spec value}118 Oracle: {oracle value or "not found"}119 Source: {json file} → {json path}120121WARNINGS:122 ⚠️ {description of close match or unverifiable claim}123 Spec: {spec value}124 Oracle: {oracle value}125126OMISSIONS (oracle has data, spec is silent):127 ℹ️ {description of missing spec coverage}128 Oracle: {oracle value}129 Source: {json file} → {json path}130131PASSES:132 ✅ REQ-NNN-XX — {requirement title} ({brief match detail})133 ✅ REQ-NNN-XX — {requirement title} ({brief match detail})134135Score: {pass}/{total} requirements match | {error} errors, {warn} warnings, {omission} omissions136```137138## Phase 2: Visual Validation (`--phase visual`)139140Validate a running application against the oracle's screenshots and structure data.141142### Step 1: Verify Dev Server143144Check if the dev server is running:145```bash146npm run dev -- --port 5173 & # or detect from spec/oracle147```148149If not running, ask the user to start it.150151### Step 2: Capture Current State152153Use browser tools (`mcp__claude-in-chrome__*` or `mcp__playwright__*`) to:1541551. Navigate to the page URL1562. Set viewport to 1440×900 (desktop)1573. Take a screenshot1584. Read the page structure (accessibility tree or DOM snapshot)1595. Extract computed styles for key elements (grid columns, dimensions, colors, fonts)160161### Step 3: Structural Comparison162163Compare the captured DOM against the oracle's `structure.json`:164165| Check | How |166|-------|-----|167| Nav item count + labels | Count sidebar/nav children, compare text |168| Grid column count | Read `gridTemplateColumns` computed style |169| Section order + presence | Compare landmark sequence |170| Text content | Compare headings, button labels, placeholder text |171| Component dimensions | Compare bounding boxes (±10% tolerance) |172| Component presence | Verify all oracle components exist in current DOM |173174### Step 4: Visual Comparison175176Compare the captured screenshot against oracle screenshots:177178| Check | How |179|-------|-----|180| Key element presence | WebGL canvas, badges, timestamps, avatars |181| Color tone | Sidebar dark, cards light, accent colors |182| Layout proportions | Sidebar width ratio, grid column balance |183| Responsive breakpoints | Resize to 768px and 375px, compare against oracle tablet/mobile screenshots |184185### Step 5: Output Visual Fidelity Report186187Same format as the spec report, but with screenshot references:188189```190Validating visual output for {domain}...191192Captured: {screenshot path}193Oracle: reverse-ui-{domain}/pages/{page}/screenshot-1440.png194195STRUCTURAL ERRORS:196 ❌ Nav items — Expected {n} items, found {m}197 Oracle: structure.json → sections[0].children (sidebar nav)198 199 ❌ Module grid — Expected {n} columns, found {m}200 Oracle: structure.json → sections[2].styles.gridTemplateColumns201202VISUAL ISSUES:203 ⚠️ {description of visual discrepancy}204205PASSES:206 ✅ Sidebar present and dark-themed207 ✅ Hero heading text matches208 ✅ Search bar present with correct placeholder209210Score: {pass}/{total} checks | {error} errors, {warn} warnings211```212213## Phase 3: All Validation (`--phase all`)2142151. Glob for all specs: `specs/*.md`2162. For each spec, run Phase 1 (spec validation)2173. For each spec with a running page, run Phase 2 (visual validation)2184. Output combined report with per-domain scores and overall score219220```221=== Fidelity Report — All Domains ===222223002-app-shell: Spec 8/10 ✅ | Visual 7/9 ✅224004-home: Spec 5/7 ⚠️ | Visual 6/8 ⚠️225005-ideation: Spec 9/9 ✅ | Visual — (no dev server)226227Overall: 22/26 spec (84%) | 13/17 visual (76%)228Top issues:229 1. ❌ 004-home REQ-004-06 — Module grid columns (2 vs 3)230 2. ❌ 004-home REQ-004-05 — Search bar gradient (invented)231 3. ❌ 002-app-shell REQ-002-03 — Nav item count (4 vs 8)232```233234## Oracle Path Resolution235236The skill locates oracle data in this priority:2372381. `--oracle <path>` — explicit, used as-is2392. `specs/assets/manifest.json` → read `meta.baseUrl`, derive domain, look for `reverse-ui-{domain}/`2403. `reverse-ui-*/manifest.json` — glob in cwd, use the first match (or ask if multiple)2414. `component-kit-*/manifest.json` — check alongside reverse-ui for enhanced validation2425. Ask user if nothing found243244## Limitations245246- Spec validation is only as good as the requirement extraction — freeform prose without `REQ-NNN-XX` markers may be missed247- Visual validation requires a running dev server and browser automation tools248- Color comparison is exact (no perceptual color distance) — rgba(255,255,255,0.2) ≠ rgba(255,255,255,0.19)249- Screenshot comparison is structural, not pixel-diff — subtle spacing or shadow differences may not be caught250- Component-kit data (Phase 10 of reverse-ui) significantly improves validation precision — run `/reverse-ui` with `--components` first for best results251- WebGL/canvas content cannot be structurally compared in visual mode — only presence/absence is checked