一键导入
demerzel-perception-loop
Phase 3 visual perception loop — generate UI targets, diff against actual renders, and auto-fix iteratively until convergence.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Phase 3 visual perception loop — generate UI targets, diff against actual renders, and auto-fix iteratively until convergence.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Use when a pull request needs review by a different AI model than the one that authored it, or when configuring cross-model code review pipelines in CI/CD.
Run Demerzel's autonomous driver — full cycle or individual phases across all repos
Capture meaningful session state (current cursor, in-flight work, live hypotheses, open questions, do-NOT-carry-forward, success criteria) to state/digests/latest.md so the next session — including one after auto-compaction — can re-enter without re-discovering context cold. Distinct from /learnings (which captures surprises). Validates against docs/contracts/digest-schema.json.
Autonomous research scheduler — selects the most under-researched department by coverage ratio, generates questions from completeness gaps, cross-model validates, auto-produces courses at T>=0.8, rate-limited to 6 cycles/day with kill switch
Personalized AI tutor — turns any topic into a customized, progress-tracked learning course. Use when the user wants to LEARN a concept, skill, language, tool, or domain. Creates a MISSION, curated RESOURCES, iterative lessons with self-checks, and learning-records that persist across sessions. NOT for interrogating the user about their own design (use brainstorming/IDSD for that).
Run one bounded supervised autonomous cycle on the Demerzel governance repo. Picks the smallest unchecked governance slice inside allow_edit, implements it, runs the oracle (`pwsh scripts/verify.ps1`), emits cycle evidence, and stops. Refuses to run unless dev-process-overseer reports loop-eligible and the preflight passes. Use when asked to "run one supervised loop", "advance governance autonomously", or "do one cycle and stop".
| name | demerzel-perception-loop |
| description | Phase 3 visual perception loop — generate UI targets, diff against actual renders, and auto-fix iteratively until convergence. |
Phase 1 (render-critic) gave the AI eyes — it can see what it built. Phase 3 gives the AI a blueprint — it knows what it should have built, and closes the gap automatically.
The perception loop generates a reference target from a natural-language UI description, screenshots the actual render, computes pixel-level and semantic similarity, identifies discrepancies, generates fixes, and re-renders until the actual converges on the target.
/demerzel perception-loop [component-path] --target [description|image-path]
Examples:
/demerzel perception-loop src/components/Dashboard.tsx --target "dark theme dashboard with 3-column grid, left sidebar nav, header with breadcrumbs"
/demerzel perception-loop src/pages/demos/Spectrum.tsx --target refs/spectrum-mockup.png
/demerzel perception-loop src/components/Card.tsx --target "minimal card with rounded corners, subtle shadow, 16px padding, sans-serif typography"
Phase A: Target Generation
Step 1: Parse target specification
↓ natural-language description OR reference image path
Step 2: Generate reference representation
├── Text target → structured UI spec (layout tree + style tokens)
└── Image target → load reference image directly
Step 3: Decompose into scorable dimensions
↓ extract: layout structure, color palette, typography, spacing, component inventory
Phase B: Baseline Capture (delegates to render-critic Steps 1-6)
Step 4: Ensure error-free render
↓ run render-critic error loop (max 5 iterations)
Step 5: Screenshot actual render
↓ capture via Windows MCP
Phase C: Perception Diff
Step 6: Structural comparison
├── Layout diff — expected vs actual component hierarchy
├── Color diff — palette extraction and distance (CIEDE2000)
├── Typography diff — font family, size, weight, line-height
├── Spacing diff — margin/padding measurements vs target
└── Component inventory — missing/extra/misplaced elements
Step 7: Compute similarity scores
↓ per-dimension scores + weighted aggregate
Phase D: Auto-Fix Loop
Step 8: Rank discrepancies by impact
↓ highest-weight dimension failures first
Step 9: Generate targeted fix
├── Layout mismatch → adjust grid/flex/position CSS
├── Color mismatch → update color values, CSS variables
├── Typography mismatch → fix font-family, size, weight
├── Spacing mismatch → adjust margin/padding values
└── Missing component → generate JSX stub
Step 10: Apply fix → HMR reload → re-screenshot → re-score
↓ return to Step 6
Phase E: Convergence Gate
Step 11: Check convergence criteria
↓ converged → Step 12
↓ not converged AND iterations < max → Step 8
↓ not converged AND iterations = max → Step 13
Step 12: Ship verdict
↓ similarity >= 0.85 for 2 consecutive iterations → CONVERGED
Step 13: Escalation
↓ report best score achieved + remaining discrepancies → human
Phase F: Compound
Step 14: Harvest patterns
↓ target→fix mappings → Seldon knowledge base
↓ convergence velocity → optimize future fix ordering
Accept one of two target forms:
| Form | Input | Output |
|---|---|---|
| Natural language | --target "dark dashboard with sidebar" | Structured UI spec |
| Reference image | --target refs/mockup.png | Reference image for direct comparison |
For natural-language targets, extract a structured spec:
target_spec:
layout:
type: grid|flex|stack
columns: N
regions: [header, sidebar, main, footer]
colors:
background: dark|light|custom
primary: color description
accent: color description
typography:
family: sans-serif|serif|mono
scale: compact|normal|spacious
spacing:
density: tight|normal|relaxed
unit: px value
components:
- name: component description
location: region
required: true|false
For text targets: Convert the structured spec into a reference model — not a rendered image, but a scorable set of assertions about what the UI should look like. Each assertion maps to a scoring dimension.
For image targets: Load the reference image directly. Extract the same scorable dimensions via visual analysis of the reference.
From either target form, produce a scoring rubric:
rubric:
layout_structure:
weight: 0.30
assertions:
- "3-column grid layout present"
- "sidebar on left, 250px wide"
- "header spans full width"
color_palette:
weight: 0.25
assertions:
- "background is dark (#1a1a2e or similar)"
- "primary text is light (#e0e0e0 or similar)"
- "accent color present in interactive elements"
typography:
weight: 0.20
assertions:
- "sans-serif font family"
- "heading size >= 24px"
- "body text 14-16px"
spacing:
weight: 0.15
assertions:
- "consistent 16px padding in content areas"
- "8px gap between grid items"
component_inventory:
weight: 0.10
assertions:
- "navigation links in sidebar"
- "breadcrumb in header"
- "data cards in main area"
Delegate entirely to render-critic. The perception loop does NOT begin scoring until the render is error-free. This is a hard prerequisite — never score a broken page.
Invoke: /demerzel render-critic [component-path]
Wait for: error-free render (render-critic Steps 1-5)
Capture: screenshot via Windows MCP (render-critic Step 6)
Compare the actual screenshot against each rubric assertion:
| Dimension | Method | Metric |
|---|---|---|
| Layout structure | DOM inspection via DevTools + visual analysis | Assertion pass rate (0-1) |
| Color palette | CSS computed style extraction + screenshot sampling | CIEDE2000 color distance (< 10 = match) |
| Typography | Computed font properties via DevTools | Exact match on family, within 2px on size |
| Spacing | Computed margin/padding via DevTools | Within 4px of target |
| Component inventory | DOM element presence check | Present/absent binary per component |
dimension_score = assertions_passed / total_assertions (per dimension)
aggregate_score = sum(dimension_score * dimension_weight)
Report format:
Perception Loop — Iteration 1
Layout structure: 0.67 (2/3 assertions passed)
Color palette: 0.33 (1/3 assertions passed)
Typography: 1.00 (3/3 assertions passed)
Spacing: 0.50 (1/2 assertions passed)
Component inventory: 0.80 (4/5 assertions passed)
─────────────────────────────────────
Aggregate: 0.63 (target: 0.85)
Top discrepancies:
1. [color] Background is #ffffff, target is dark (#1a1a2e) — delta: 0.25 weight
2. [layout] Missing sidebar — delta: 0.10 weight
3. [spacing] Content padding 8px, target 16px — delta: 0.075 weight
Order discrepancies by dimension_weight * (1 - dimension_score) — fix highest-impact gaps first.
For each fix:
Fix confidence by type:
| Fix Type | Confidence | Rationale |
|---|---|---|
| Color value change | 0.95 | Deterministic — swap one value |
| Spacing adjustment | 0.90 | Deterministic — change margin/padding |
| Font property change | 0.90 | Deterministic — change font-family/size |
| Layout restructure | 0.70 | May affect sibling components |
| Component addition | 0.60 | Requires understanding component API |
| Complex layout rewrite | 0.40 | Structural change — escalate |
Apply fix → wait for HMR (~500ms) → re-screenshot → re-score
Each iteration is logged with:
CONVERGED if:
aggregate_score >= 0.85 for 2 consecutive iterations
CONTINUE if:
aggregate_score < 0.85 AND iterations < max_iterations
AND score_delta > 0.02 (still making progress)
STALLED if:
score_delta <= 0.02 for 2 consecutive iterations (not improving)
→ escalate even if under max_iterations
EXHAUSTED if:
iterations >= max_iterations
→ escalate with best-achieved score
When converged:
When stalled or exhausted:
Harvest for Seldon knowledge base:
| Dimension | Weight | Rationale |
|---|---|---|
| Layout structure | 0.30 | Structural correctness is the foundation |
| Color palette | 0.25 | Color is the most immediately visible quality signal |
| Typography | 0.20 | Readability is critical for usability |
| Spacing | 0.15 | Contributes to polish but less critical than structure |
| Component inventory | 0.10 | Missing components are caught by layout/completeness overlap |
| Threshold | Value | Meaning |
|---|---|---|
| Converged | >= 0.85 (2 consecutive) | Target achieved — ship |
| Acceptable | >= 0.70 | Close enough — minor polish remaining |
| Needs work | >= 0.50 | Significant gaps — continue iterating |
| Far from target | < 0.50 | Major structural differences — likely needs human guidance |
| Parameter | Value | Rationale |
|---|---|---|
| Max iterations | 8 | More than render-critic (5) because target convergence is harder |
| Stall detection | 2 iterations with delta <= 0.02 | Stop wasting cycles on diminishing returns |
| Max fixes per iteration | 3 | Apply multiple non-conflicting fixes per cycle for efficiency |
state/perception-loop/
target-spec.json — current target specification (structured rubric)
iteration-log.json — per-iteration scores, fixes applied, deltas
convergence-history.json — historical convergence data across components
verified-components.json — components that passed perception verification
render-critic (Phase 1) perception-loop (Phase 3)
───────────────────── ──────────────────────────
Fix console errors Generate target from description
Score visual quality Diff actual vs target
Ship when score >= 0.9 Converge actual toward target
No reference target Reference-driven scoring
Reactive (fix what's broken) Proactive (build toward intent)
Dependency: perception-loop delegates error-fixing to render-critic.
perception-loop begins AFTER render-critic achieves error-free render.