Skip to content

Commit cc9b1fe

Browse files
feat(desktop): add design reference to html skill
Signed-off-by: Sun-sunshine06 <Sun-sunshine06@users.noreply.github.com>
1 parent 631143d commit cc9b1fe

3 files changed

Lines changed: 209 additions & 0 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@open-codesign/desktop": minor
3+
---
4+
5+
Add the built-in `design-reference-to-html` method skill for screenshot/mockup-to-HTML recreation. The skill is an Open CoDesign-native rewrite that uses workspace files, `App.jsx`, `DESIGN.md`, `preview()`, and optional `gen_image()` instead of vendoring external skill directories or browser scripts.
Lines changed: 203 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,203 @@
1+
---
2+
schemaVersion: 1
3+
name: design-reference-to-html
4+
description: >
5+
Recreates an existing visual reference, such as a UI screenshot, mockup export,
6+
Figma frame image, dashboard, SaaS screen, empty state, or landing-page capture,
7+
as high-quality HTML/CSS or App.jsx. Use only when the user provides a concrete
8+
visual reference, not for text-only page design.
9+
aliases: [design-to-html, screenshot-to-html, visual-reference, screenshot-recreate]
10+
dependencies: [responsive-layout]
11+
validationHints:
12+
- visual reference is mapped before code is written
13+
- complex brand or illustration assets are treated as assets, not improvised CSS
14+
- preview screenshots are compared against the reference before done
15+
trigger:
16+
providers: ['*']
17+
scope: system
18+
disable_model_invocation: false
19+
user_invocable: true
20+
---
21+
22+
## Design Reference Recreation
23+
24+
Use this workflow when the user asks to recreate, copy, convert, or implement a
25+
visible design reference as HTML/CSS, `App.jsx`, or a local web artifact.
26+
27+
Do not use it for ordinary product design from prose. If there is no screenshot,
28+
mockup, exported frame, or equivalent visual artifact, use normal frontend
29+
design judgment instead.
30+
31+
## Core Contract
32+
33+
Do not jump straight from image to code.
34+
35+
Work as an error-reduction loop:
36+
37+
1. Inspect the visual reference and build a compact page map.
38+
2. Separate code-rendered UI from external visual assets.
39+
3. Decide the reference canvas, target viewport, and scaling strategy.
40+
4. Implement structure first, then visual polish.
41+
5. Run `preview(path)` and inspect the rendered result.
42+
6. Compare the preview screenshot against the reference by region.
43+
7. Correct concrete visual differences and preview again before `done(path)`.
44+
45+
## Inputs To Establish
46+
47+
Infer these from the prompt, attachments, workspace files, and `inspect_workspace`
48+
when possible. Ask only when missing information would change the output format
49+
or fidelity target.
50+
51+
- Visual reference: screenshot, mockup export, frame image, browser capture, or
52+
local reference asset.
53+
- Output surface: default to `App.jsx` in an Open CoDesign workspace; use
54+
standalone `.html` only when requested or when editing an existing HTML file.
55+
- Reference canvas: preserve the image aspect ratio when dimensions are known.
56+
- Verification viewport: match the reference size when practical, then also
57+
check the user-facing viewport if different.
58+
- Asset availability: logos, illustrations, product screenshots, device renders,
59+
photos, icon sets, or only the flat reference image.
60+
- Responsive scope: desktop-only unless the user requests mobile/tablet or the
61+
existing artifact clearly needs breakpoints.
62+
63+
## Page Map Before Code
64+
65+
Before writing source, make a short implementation map:
66+
67+
- Overall regions: header, sidebar, hero, content grid, panels, footer, overlays.
68+
- Layout ratios: column widths, row heights, primary alignment, visible margins.
69+
- Component inventory: visible UI pieces in top-to-bottom, left-to-right order.
70+
- Color and surfaces: background, cards, borders, shadows, accent colors.
71+
- Typography: heading/body/helper sizes, weights, line-height, casing.
72+
- Shape and density: radius scale, padding rhythm, gaps, shadow softness.
73+
- Asset candidates: logos, photos, screenshots, illustrations, 3D objects,
74+
detailed empty-state art, or brand key visuals.
75+
76+
Keep the map concise. It is a checklist for implementation, not a long critique.
77+
78+
## Asset Separation
79+
80+
Render with HTML/CSS:
81+
82+
- Navigation, sidebars, tabs, menus, cards, panels, forms, tables, buttons,
83+
labels, badges, dividers, text, simple charts, and simple icons from an
84+
existing icon library.
85+
86+
Treat as assets:
87+
88+
- Brand logos and marks.
89+
- Detailed illustrations, hero art, 3D renders, people photos, textures.
90+
- Product screenshots, app mockups, detailed empty-state images.
91+
- Any shape where exact brand detail matters more than layout structure.
92+
93+
If removing an element leaves the UI skeleton intact, it is probably an asset.
94+
If removing it breaks the page structure, it is probably code-rendered UI.
95+
96+
Do not hand-draw logos or complex illustrations with ad hoc CSS/SVG. Prefer, in
97+
order:
98+
99+
1. Existing user-supplied assets in the workspace.
100+
2. A cropped asset from the reference, when available and clear enough.
101+
3. A stable neutral placeholder that preserves layout.
102+
4. `gen_image(prompt, path)` only when the user asked for generated/redrawn
103+
bitmap assets and the current provider supports it.
104+
105+
Report placeholders and low-quality crops in the final summary.
106+
107+
## Canvas And Fit
108+
109+
For screenshot recreation, distinguish:
110+
111+
- Reference canvas: the design image/artboard being copied.
112+
- Display viewport: the browser or preview size used to inspect the result.
113+
114+
Standalone visual reproductions should preserve the reference aspect ratio.
115+
Use an outer shell plus a stable stage rather than scattering viewport math
116+
through every element:
117+
118+
```css
119+
html,
120+
body {
121+
width: 100%;
122+
height: 100%;
123+
margin: 0;
124+
}
125+
126+
.preview-shell {
127+
min-height: 100vh;
128+
display: grid;
129+
place-items: center;
130+
overflow: hidden;
131+
background: var(--page-bg);
132+
}
133+
134+
.design-stage {
135+
width: min(100vw, calc(100vh * var(--reference-ratio)));
136+
max-height: 100vh;
137+
aspect-ratio: var(--reference-ratio);
138+
position: relative;
139+
overflow: hidden;
140+
}
141+
```
142+
143+
Define `--page-bg` and `--reference-ratio` in the artifact stylesheet before
144+
using this pattern. For a 1440 by 900 reference, `--reference-ratio` is
145+
`1440 / 900`.
146+
147+
Use a normal responsive layout for production app screens, but still preserve
148+
the reference proportions at the target breakpoint before adding other
149+
breakpoints.
150+
151+
Avoid direct `transform: scale(...)` on a centered fixed canvas unless a parent
152+
frame also reserves the scaled layout size. Otherwise the visual canvas and the
153+
layout box disagree, which causes clipped edges or large empty bands.
154+
155+
## Build Rules
156+
157+
- Match proportions and alignment before tuning shadows or gradients.
158+
- Use CSS variables for repeated colors, spacing, typography, radius, and
159+
shadows; update `DESIGN.md` when the reference establishes a reusable system.
160+
- Use explicit dimensions, `aspect-ratio`, grid tracks, `object-fit`, and
161+
min/max constraints for repeated units and asset slots.
162+
- Keep text content faithful to the reference. Do not add visible explanatory
163+
labels unless the reference shows them.
164+
- Prefer local assets and app-provided libraries. Do not install packages,
165+
download images, or add external hotlinks without user approval.
166+
- Use the repo's existing framework and source entry. In Open CoDesign, default
167+
to `App.jsx`; reserve `index.html` for standalone exports or existing HTML
168+
workspaces.
169+
170+
## Preview And Compare
171+
172+
Always run `preview(path)` before `done(path)` when the preview tool is
173+
available. Inspect:
174+
175+
- Canvas fit: no unintended crop, squeeze, overflow, or corner anchoring.
176+
- Region layout: header, sidebar, main content, repeated cards, footer.
177+
- Typography: hierarchy, wrapping, weight, line-height, and text color.
178+
- Surfaces: background hue, card contrast, border opacity, radius, shadows.
179+
- Assets: size, crop, aspect ratio, resolution, and style match.
180+
- Density: gaps, padding, vertical rhythm, and whether the page feels too empty
181+
or too cramped.
182+
- Responsive behavior when mobile/tablet is in scope.
183+
184+
Convert vague visual mismatch into actionable edits:
185+
186+
- "Hero starts about 24px too low."
187+
- "Cards need 8px less vertical padding."
188+
- "The sidebar is too wide relative to the reference."
189+
- "The product screenshot slot should use `object-fit: contain`, not stretch."
190+
191+
Iterate with focused edits, preview again, then stop when remaining differences
192+
are minor, blocked by missing assets, or outside the requested scope.
193+
194+
## Delivery
195+
196+
When calling `done(path)` and summarizing for the user, include:
197+
198+
- What file or artifact was implemented.
199+
- Which reference and viewport were checked.
200+
- Which assets were used, cropped, generated, or represented by placeholders.
201+
- Remaining visual gaps or unverified assumptions.
202+
203+
Do not claim pixel-perfect fidelity unless preview comparison supports it.

packages/core/src/skills/loader.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ describe('loadSkillsFromDir()', () => {
6767
expect(ids).toContain('app-shell-navigation');
6868
expect(ids).toContain('accessibility-states');
6969
expect(ids).toContain('design-system-baton');
70+
expect(ids).toContain('design-reference-to-html');
7071
expect(ids).toContain('responsive-layout');
7172
expect(ids).toContain('data-viz-recharts');
7273
expect(ids).toContain('mobile-mock');

0 commit comments

Comments
 (0)