/** * Visual comparison validation for Figma-to-code loops. * * Three-layer hybrid approach for maximum accuracy: * * Layer 1 — pixelmatch: Fast pixel-level diff scoring. If diff < threshold → pass immediately (no LLM cost). * Layer 2 — LLM Vision: When pixelmatch detects significant differences, sends both images + diff overlay * to an LLM vision API for semantic interpretation (actionable feedback the agent can fix). * Layer 3 — Playwright strict assertion: Final gate after fixes. Strict pixel-by-pixel comparison * with tight threshold catches anything the LLM missed. * * Playwright + pixelmatch are auto-installed when visual validation is triggered and not found. */ import type { LLMUsage } from '../llm/api.js'; import { type LLMProvider } from '../llm/providers.js'; export interface VisualValidationResult { success: boolean; /** Whether validation was skipped (not the same as passing) */ skipped?: boolean; /** Reason validation was skipped */ skipReason?: string; issues: string[]; /** Pixel diff ratio (0–1) from pixelmatch */ diffRatio?: number; /** Path to diff overlay image (if generated) */ diffImagePath?: string; usage?: LLMUsage; } export interface VisualValidationOptions { provider?: LLMProvider; model?: string; /** Viewport width for screenshot capture (default: 1920) */ viewportWidth?: number; /** Viewport height for screenshot capture (default: 1080) */ viewportHeight?: number; /** Timeout for dev server startup in ms (default: 30000) */ serverTimeout?: number; /** Logging callback for progress messages */ log?: (msg: string) => void; /** Whether this is a re-check after fixes (enables strict final gate) */ strictMode?: boolean; /** Force LLM vision analysis regardless of pixel diff ratio (for final iteration) */ alwaysUseLLM?: boolean; } /** * Capture a full-page screenshot of a URL using Playwright. * Returns the screenshot as a PNG Buffer, or null if capture fails. */ export declare function captureScreenshot(url: string, viewport?: { width: number; height: number; }, playwrightModule?: any): Promise; export interface PixelDiffResult { /** Ratio of different pixels (0–1) */ diffRatio: number; /** Absolute number of different pixels */ diffPixels: number; /** Total pixels compared */ totalPixels: number; /** PNG buffer of the diff overlay (red = different) */ diffImage: Buffer; } /** * Compare two PNG images at the pixel level using pixelmatch. * When dimensions differ significantly (>15%), resizes the implementation * screenshot to match the design screenshot using sharp. This handles the * case where Figma API caps frame screenshots at 4096px (reducing scale) * while Playwright captures at full 2x resolution. */ export declare function pixelDiff(designPng: Buffer, implPng: Buffer): Promise; /** * Compare screenshots using LLM vision, including a pixel diff overlay for precision. */ export declare function compareWithLLMVision(designBuffer: Buffer, implBuffer: Buffer, diffBuffer: Buffer, options?: { provider?: LLMProvider; model?: string; }): Promise<{ matches: boolean; issues: string[]; usage?: LLMUsage; }>; /** * Run the full three-layer visual validation pipeline: * * 1. Start dev server → capture implementation screenshot * 2. Layer 1 (pixelmatch): fast pixel diff scoring * - If diff < 2% in strict mode → PASS (pixel perfect) * - If diff < 5% → PASS (close enough, skip LLM) * - If diff >= 5% → proceed to Layer 2 * 3. Layer 2 (LLM Vision): semantic comparison with diff overlay * - Returns actionable issues for the agent to fix * 4. Layer 3 (strict mode): after agent fixes, re-run with strict threshold * - If diff still > 2% → format pixel diff details as feedback * * Returns success=true if validation passes or cannot be performed. */ export declare function runVisualValidation(cwd: string, designScreenshots: string[], options?: VisualValidationOptions): Promise; //# sourceMappingURL=visual-validation.d.ts.map