Skip to content

Latest commit

 

History

History
89 lines (62 loc) · 5.1 KB

visual-validation.md

File metadata and controls

89 lines (62 loc) · 5.1 KB

PixelForge AI — Browser Runtime & Visual Validation

Visual validation is the cornerstone of PixelForge AI. Rather than assuming generated code matches the design, PixelForge renders the software in a real browser, captures photographic evidence, and verifies layout fidelity through perceptual diffing.


1. Browser Execution Priority

The browser runtime engine operates on a strict multi-tier priority model:

┌─────────────────────────────────────────────────────────┐
│                     Capability Check                    │
└────────────────────────────┬────────────────────────────┘
                             │
            ┌────────────────┴────────────────┐
            │ Has Agent Native Browser Tool?  │
            └───────┬─────────────────┬───────┘
                    │ YES             │ NO
                    ▼                 ▼
          ┌──────────────────┐   ┌──────────────────┐
          │    Priority 1    │   │    Priority 2    │
          │ Built-in Browser │   │    Playwright    │
          │ Provider         │   │ Fallback Runtime │
          └──────────────────┘   └──────────────────┘

Priority 1: Built-in Agent Browser Capability

Whenever the Agent runtime provides an integrated browser environment (such as OpenCode openchamber_web, Claude Code browser tools, or Model Context Protocol browser servers), PixelForge routes navigation and screenshot requests through this built-in capability. This eliminates unnecessary subprocess overhead and utilizes the agent's active sandbox.

Priority 2: Playwright Fallback Provider

If no agent-native browser is active, PixelForge autonomously falls back to a standalone headless Playwright Chromium runtime. Playwright is treated as an independent fallback, ensuring the project remains fully functional across headless CI pipelines and terminal CLI environments.


2. Standard Viewport Matrix & Multi-Viewport Suite

PixelForge tests interfaces across standardized viewport configurations:

Preset Dimensions Device Scale Intended Verification Target
desktop-large 2560 x 1440 px 1x Ultra-wide monitors (verifies no awkward right-side blanks)
desktop 1440 x 900 px 1x Standard laptop/desktop widescreen UI
laptop 1280 x 800 px 1x Compact laptops (MacBook Air 13")
tablet 768 x 1024 px 2x iPad / Tablet portrait viewports
mobile 390 x 844 px 3x Modern mobile smartphone viewports (iPhone 14/15/16)

Automated Multi-Viewport Suite

Run npm run cli:capture -- --target <url_or_file> --out ./validation --viewport multi to automatically produce all 5 canonical viewports and verify there are zero horizontal scrollbars or layout fractures.


3. Strict 5-Tier Optimization Priority

When discrepancies are detected, PixelForge follows a strict hierarchy of fixes:

  1. Priority 1 (Layout & Viewport): Viewport occupancy (100vw, min-h-screen), root wrappers, columns, and grid architecture.
  2. Priority 2 (Component Geometry & Spacing): Component widths, min-heights, flex auto-margins, paddings, and section gaps.
  3. Priority 3 (Typography): Font family, font weight, line-height, letter spacing, and fluid clamp() rules.
  4. Priority 4 (Colors & Contrast): Background palettes, radial gradients, glassmorphism, and border contrasts.
  5. Priority 5 (Micro Details): SVG icon precision, border radii, elevation shadows, and hover animations.

Never optimize minor icons or shadows while major layout breaks or right-side blank areas exist.


4. Perceptual Diffing Algorithm & Objective Scores

PixelForge utilizes the pixelmatch anti-aliasing aware comparison algorithm combined with pngjs data stream normalization:

$$ \text{Similarity Score} = \left( 1 - \frac{\text{Diff Pixels}}{\text{Total Pixels}} \right) \times 100% $$

Anti-Aliasing Handling

PixelForge filters font smoothing and sub-pixel edge rendering variations to avoid false-positive mismatches caused by browser font rasterizers.

Spatial Clustering

Diff pixels are aggregated into spatial clusters using a 32x32 block grid. Clusters identify whether discrepancies are concentrated in headers, hero elements, cards, or footers.


5. Autonomous Refinement Loop

When similarity is below the benchmark target (95.0%):

  1. The DiffAnalyzer converts pixel clusters into semantic diagnoses.
  2. The agent reads the diagnosis (e.g. Top Navigation: py-4 should be py-6).
  3. The agent applies a surgical edit to the component.
  4. The browser re-renders and validates.
  5. The loop repeats (up to 3 times) until convergence.