canicode 0.8.9 → 0.9.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,143 @@
1
+ # Design to Code — Standard Prompt
2
+
3
+ This prompt is used by all code generation pipelines:
4
+ - Calibration Converter
5
+ - Ablation experiments (API-based)
6
+ - User-facing `canicode implement` command (default prompt)
7
+
8
+ ## Stack
9
+ - HTML + CSS (single file)
10
+ - No frameworks, no build step
11
+
12
+ ## Conventions
13
+ - Semantic HTML elements
14
+ - Flexbox / Grid for layout
15
+ - Always include `* { box-sizing: border-box; margin: 0; padding: 0; }` reset
16
+
17
+ ## CRITICAL: Do NOT Interpret. Reproduce Exactly.
18
+
19
+ Every pixel in the Figma file is intentional. A designer made each decision deliberately.
20
+ Your job is to translate the Figma data to HTML+CSS — nothing more.
21
+
22
+ ### Priority Order
23
+ 1. **Pixel-exact reproduction** — match every dimension, color, spacing, font exactly
24
+ 2. **Component reuse** — same component annotation → shared CSS class
25
+ 3. **Design tokens** — repeated values → CSS custom properties
26
+
27
+ Never sacrifice #1 for #2 or #3. Reuse and tokens are structural improvements only — they must not change the visual output.
28
+
29
+ ### Rules
30
+ - Do NOT add any value that isn't in the Figma data (no extra padding, margin, gap, transition)
31
+ - Do NOT add hover effects unless `[hover]:` data is provided in the design tree
32
+ - Do NOT change any value from the Figma data (if it says 160px padding, use 160px)
33
+ - Do NOT "improve" the design — if something looks wrong, reproduce it anyway
34
+ - Do NOT add responsive behavior unless the Figma data explicitly shows it
35
+ - Do NOT use min-height or min-width unless the design tree explicitly includes them — use exact height and width from the data
36
+ - Do NOT add overflow: auto or scroll unless specified
37
+ - Fonts: load via Google Fonts CDN (`<link>` tag). Do NOT use system font fallbacks as primary — the exact font from the data must render.
38
+
39
+ ### Component Reuse
40
+
41
+ Nodes annotated with `[component: ComponentName]` are instances of the same design component.
42
+
43
+ - Define a CSS class for each unique component name (e.g., `[component: Review Card]` → `.review-card { ... }`)
44
+ - If the same component appears multiple times, define the shared styles once in the class, then apply it to each instance
45
+ - `component-properties:` lines show variant overrides — use them to differentiate instances (e.g., different text content, sizes) while keeping shared styles in the class
46
+ - Component name → class name: lowercase, spaces to hyphens (e.g., `Review Card` → `.review-card`)
47
+ - Use CSS classes only — no Web Components, no JavaScript templates
48
+
49
+ ### Design Tokens
50
+
51
+ Extract repeated values into CSS custom properties in `:root { }`.
52
+
53
+ **Colors**: When the same hex color appears 3+ times, define it as a CSS variable:
54
+ ```css
55
+ :root {
56
+ --color-2C2C2C: #2C2C2C;
57
+ --color-0066CC: #0066CC;
58
+ }
59
+ ```
60
+ Then use `var(--color-2C2C2C)` instead of inline `#2C2C2C`.
61
+
62
+ Naming: if a `/* var:... */` comment is present next to a color value, it means the designer bound this color to a design token — always extract these as CSS variables.
63
+
64
+ **Typography**: When `/* text-style: StyleName */` appears in a text node's styles, nodes sharing the same text style name should use a shared CSS class:
65
+ ```css
66
+ .text-heading-large { font-family: "Inter"; font-weight: 700; font-size: 32px; line-height: 40px; }
67
+ ```
68
+ Style name → class name: lowercase, spaces/slashes to hyphens, prefix with `text-` (e.g., `Heading / Large` → `.text-heading-large`).
69
+
70
+ ### SVG Vectors
71
+
72
+ When a node's style includes `svg: <svg>...</svg>`, render it as an inline `<svg>` element:
73
+ - Use the SVG markup exactly as provided — do not modify paths or attributes
74
+ - Preserve the node's dimensions (`width` and `height` from the node header)
75
+ - The `<svg>` replaces the node's HTML element (do not wrap it in an extra `<div>` unless the node has other styles like background or border)
76
+
77
+ ### Hover States
78
+
79
+ When a node includes a `[hover]:` line, generate a `:hover` CSS rule with the provided style changes:
80
+
81
+ ```text
82
+ Button (INSTANCE, 120x40) [component: Button]
83
+ style: background: #2C2C2C
84
+ [hover]: background: #1E1E1E; Icon: fill: #FFFFFF
85
+ ```
86
+
87
+ → generates:
88
+
89
+ ```css
90
+ .button { background: #2C2C2C; }
91
+ .button:hover { background: #1E1E1E; }
92
+ .button:hover .icon { fill: #FFFFFF; }
93
+ ```
94
+
95
+ - Only use hover data that is explicitly provided in `[hover]:` — do not invent hover effects
96
+ - Child styles (e.g., `Icon: fill: #FFFFFF`) use `.parent:hover .child` selector pattern
97
+
98
+ ### Image Assets
99
+
100
+ The design tree uses two distinct image types:
101
+
102
+ **`content-image:`** — leaf node, no children → render as `<img>` tag
103
+ - `content-image: url(images/...)` → `<img src="images/..." />`
104
+ - `object-fit: cover` or `object-fit: contain` is provided alongside — use it directly
105
+
106
+ **`background-image:`** — node has children on top → keep as CSS `background-image`
107
+ - `background-image: url(images/...)` → `background-image: url(images/...)` in CSS
108
+ - `background-size`, `background-position`, `background-repeat` are provided alongside — use as-is
109
+
110
+ **`[IMAGE]` placeholder** — image asset unavailable → use a placeholder color matching the surrounding design
111
+
112
+ ### If data is missing
113
+ When the Figma data does not specify a value, you MUST list it as an interpretation.
114
+ Do not silently guess — always declare what you assumed.
115
+
116
+ ## Output
117
+
118
+ ### 1. Code
119
+ - Place the entire design inside a single root `<div>` as the first child of `<body>` — do NOT apply design styles directly to `<body>` or `<html>`
120
+ - Output as a code block with filename:
121
+
122
+ ```html
123
+ // filename: index.html
124
+ <!DOCTYPE html>
125
+ ...
126
+ ```
127
+
128
+ ### 2. Interpretations
129
+ After the code block, list every value you had to guess or assume.
130
+ Keep this list to **only genuine ambiguities** — do not list standard defaults (e.g., `body { margin: 0 }` is always expected, not an interpretation).
131
+ **Maximum 10 items.** If you have more than 10, keep only the highest-impact ones.
132
+
133
+ ```text
134
+ // interpretations:
135
+ - Used placeholder gray (#CCCCCC) for unavailable image asset
136
+ - Chose "Inter" font weight 500 for ambiguous "Medium" style reference
137
+ ```
138
+
139
+ If you did not interpret anything, write:
140
+
141
+ ```text
142
+ // interpretations: none
143
+ ```
package/README.md CHANGED
@@ -8,19 +8,13 @@
8
8
  <a href="https://www.npmjs.com/package/canicode"><img src="https://img.shields.io/npm/v/canicode.svg" alt="npm version"></a>
9
9
  <a href="https://github.com/let-sunny/canicode/actions/workflows/ci.yml"><img src="https://github.com/let-sunny/canicode/actions/workflows/ci.yml/badge.svg" alt="CI"></a>
10
10
  <a href="https://github.com/let-sunny/canicode/actions/workflows/release.yml"><img src="https://github.com/let-sunny/canicode/actions/workflows/release.yml/badge.svg" alt="Release"></a>
11
- <a href="https://let-sunny.github.io/canicode/"><img src="https://img.shields.io/badge/Try_it-GitHub_Pages-blue" alt="GitHub Pages"></a>
12
- <a href="https://www.figma.com/community/plugin/1617144221046795292/canicode"><img src="https://img.shields.io/badge/Figma_Plugin-under_review-orange" alt="Figma Plugin"></a>
13
- <a href="https://github.com/let-sunny/canicode#mcp-server-claude-code--cursor--claude-desktop"><img src="https://img.shields.io/badge/MCP_Registry-published-green" alt="MCP Registry"></a>
14
- <a href="https://github.com/marketplace/actions/canicode-action"><img src="https://img.shields.io/badge/GitHub_Action-Marketplace-2088FF" alt="GitHub Action"></a>
15
11
  </p>
16
12
 
17
- <p align="center">The design linter that scores how easily your Figma design can be implemented by AI or developers — before a single line of code is written.</p>
13
+ <p align="center"><strong>Stop explaining your designs. Get scored by AI-calibrated rules.</strong></p>
18
14
 
19
- <p align="center">No AI tokens consumed per analysis. Rules run deterministically — AI only validated the scores during development.</p>
20
-
21
- <p align="center"><strong><a href="https://github.com/let-sunny/canicode/discussions/new?category=share-your-figma">Share your Figma design</a></strong> to help improve scoring accuracy.</p>
22
-
23
- <p align="center"><strong><a href="https://let-sunny.github.io/canicode/">Try it in your browser</a></strong> — no install needed.</p>
15
+ <p align="center">
16
+ <strong><a href="https://let-sunny.github.io/canicode/">Try it in your browser</a></strong> — no install needed.
17
+ </p>
24
18
 
25
19
  <p align="center">
26
20
  <img src="docs/images/screenshot.gif" alt="CanICode Report" width="720">
@@ -28,46 +22,78 @@
28
22
 
29
23
  ---
30
24
 
31
- ## How It Works
25
+ ## Why CanICode
32
26
 
33
- 39 rules. 6 categories. Every node in the Figma tree.
27
+ AI can turn Figma designs into code — but the quality depends heavily on **how the design is structured**. Missing Auto Layout drops pixel accuracy from 95% to 63% at different viewports. Raw JSON input wastes 5× more tokens for 15%p worse results.
34
28
 
35
- | Category | Rules | What it checks |
36
- |----------|-------|----------------|
37
- | Layout | 11 | Auto-layout usage, responsive behavior, nesting depth |
38
- | Design Token | 7 | Color/font/shadow tokenization, spacing consistency |
39
- | Component | 6 | Component reuse, detached instances, variant coverage |
40
- | Naming | 5 | Semantic names, default names, naming conventions |
41
- | AI Readability | 5 | Structure clarity, z-index reliance, empty frames |
42
- | Handoff Risk | 5 | Hardcoded values, truncation handling, placeholder images |
29
+ CanICode solves this:
43
30
 
44
- Each issue is classified: **Blocking** > **Risk** > **Missing Info** > **Suggestion**.
31
+ 1. **Analyzes** your Figma design for patterns that hurt AI implementation quality
32
+ 2. **Generates a design-tree** — a curated, CSS-ready representation that AI implements more accurately and efficiently than raw Figma data
33
+ 3. **Scores** responsive readiness, so you fix the design before generating code
45
34
 
46
- ### Rule Scores Validated by AI
35
+ - **16 rules** across 6 categories: Pixel Critical, Responsive Critical, Code Quality, Token Management, Interaction, Semantic
36
+ - **Deterministic** — no AI tokens consumed per analysis, runs in milliseconds
37
+ - **Validated** — [ablation experiments](https://github.com/let-sunny/canicode/wiki) confirmed design-tree achieves 94% pixel accuracy with 5× fewer tokens than raw JSON
47
38
 
48
- Rule scores aren't guesswork. They're validated through a 4-agent debate pipeline that converts real Figma nodes to code and measures actual implementation difficulty.
39
+ ### Scores You Can Trust
49
40
 
50
- 1. **Runner** analyzes the design and flags issues
51
- 2. **Converter** converts the flagged nodes to actual code
52
- 3. **Critic** challenges whether the scores match the real difficulty
53
- 4. **Arbitrator** makes the final call — adjust or keep
41
+ Rule scores aren't guesswork. The calibration pipeline converts real Figma designs to HTML, measures pixel-level similarity (via `visual-compare`), and adjusts scores based on actual implementation difficulty.
54
42
 
55
- - A node that's hard to implement → rule score goes up
56
- - A node that's easy to implement despite the flag → rule score goes down
43
+ - Design that's hard to implement accurately → rule score goes **up**
44
+ - Design that's easy despite the flag → rule score goes **down**
57
45
 
58
- The rules themselves run deterministically on every analysis — no tokens consumed. The AI debate validates scores when new fixtures are added, not on every run. See [`docs/CALIBRATION.md`](docs/CALIBRATION.md).
46
+ The pipeline runs on community fixtures, not on every analysis. Strip ablation uses six `DESIGN_TREE_INFO_TYPES` passes (including `size-constraints` for responsive sizing rules see [`CLAUDE.md`](CLAUDE.md)). See the [Calibration wiki](https://github.com/let-sunny/canicode/wiki/Calibration).
59
47
 
60
48
  ---
61
49
 
62
50
  ## Getting Started
63
51
 
64
- | If you want to... | Use |
65
- |---|---|
66
- | Just try it | **[Web App](https://let-sunny.github.io/canicode/)** — paste a URL, no install |
67
- | Analyze inside Figma | **[Figma Plugin](https://www.figma.com/community/plugin/1617144221046795292/canicode)** (under review) |
68
- | Use with Claude Code / Cursor | **MCP Server** or **Skill** — see below |
69
- | Add to CI/CD | **[GitHub Action](https://github.com/marketplace/actions/canicode-action)** |
70
- | Full control | **CLI** |
52
+ **Quickest way:** **[Open the web app](https://let-sunny.github.io/canicode/)** paste a Figma URL, get a report.
53
+
54
+ **For your workflow:**
55
+
56
+ ```bash
57
+ # CLI one command
58
+ npx canicode analyze "https://www.figma.com/design/ABC123/MyDesign?node-id=1-234"
59
+
60
+ # MCP Server — works with Claude Code, Cursor, Claude Desktop
61
+ claude mcp add canicode -- npx -y -p canicode canicode-mcp
62
+ ```
63
+
64
+ <details>
65
+ <summary><strong>All channels</strong></summary>
66
+
67
+ | Channel | Best for |
68
+ |---------|----------|
69
+ | **[Web App](https://let-sunny.github.io/canicode/)** | Quick check, no install |
70
+ | **[Figma Plugin](https://www.figma.com/community/plugin/1617144221046795292/canicode)** | Analyze inside Figma (under review) |
71
+ | **MCP Server** | Claude Code / Cursor / Claude Desktop integration |
72
+ | **Claude Code Skill** | Lightweight, no MCP install |
73
+ | **CLI** | Full control, CI/CD, offline analysis |
74
+ | **`canicode implement`** | Generate code-ready package (analysis + assets + prompt) |
75
+ | **[GitHub Action](https://github.com/marketplace/actions/canicode-action)** | PR gate with score threshold |
76
+
77
+ </details>
78
+
79
+ ---
80
+
81
+ ## What It Checks
82
+
83
+ | Category | Rules | What it measures |
84
+ |----------|:-----:|------------------|
85
+ | **Pixel Critical** | 3 | Can AI read the layout? (Auto Layout, absolute positioning, groups) |
86
+ | **Responsive Critical** | 2 | Will it work at different viewports? (fixed sizing, size constraints) |
87
+ | **Code Quality** | 4 | Is the design efficient for AI context? (components, variants, nesting) |
88
+ | **Token Management** | 2 | Can AI reproduce exact values? (raw values, spacing grid) |
89
+ | **Interaction** | 2 | Can AI know what happens? (state variants, prototypes) |
90
+ | **Semantic** | 3 | Can AI infer meaning? (semantic names, conventions) |
91
+
92
+ Each issue is classified: **Blocking** > **Risk** > **Missing Info** > **Suggestion**.
93
+
94
+ ---
95
+
96
+ ## Installation
71
97
 
72
98
  <details>
73
99
  <summary><strong>CLI</strong></summary>
@@ -87,7 +113,7 @@ Setup: `canicode init --token figd_xxxxxxxxxxxxx`
87
113
  | View, Collab | 6 req/month | 6 req/month |
88
114
  | Dev, Full | 6 req/month | 10–20 req/min |
89
115
 
90
- Hitting 429 errors? Make sure the file is in a paid workspace. Or use MCP (no token, separate rate limit pool). Or `save-fixture` once and analyze locally. [Full details](https://developers.figma.com/docs/rest-api/rate-limits/)
116
+ Hitting 429 errors? Make sure the file is in a paid workspace. Or `save-fixture` once and analyze locally. [Full details](https://developers.figma.com/docs/rest-api/rate-limits/)
91
117
 
92
118
  </details>
93
119
 
@@ -103,22 +129,38 @@ Then ask: *"Analyze this Figma design: https://www.figma.com/design/..."*
103
129
 
104
130
  canicode's rule engine analyzes the design data — the AI assistant just orchestrates the calls.
105
131
 
106
- Or with a Figma API token (no Figma MCP needed):
132
+ With a Figma API token:
107
133
  ```bash
108
134
  claude mcp add canicode -e FIGMA_TOKEN=figd_xxxxxxxxxxxxx -- npx -y -p canicode canicode-mcp
109
135
  ```
110
136
 
111
- For Cursor / Claude Desktop config, see [`docs/REFERENCE.md`](docs/REFERENCE.md).
137
+ For Cursor / Claude Desktop config, see [`docs/CUSTOMIZATION.md`](docs/CUSTOMIZATION.md).
112
138
 
113
- **Figma MCP Rate Limits**
139
+ </details>
114
140
 
115
- | Plan | Limit |
116
- |------|-------|
117
- | Starter | 6 tool calls/month |
118
- | Pro / Org — Full or Dev seat | 200 tool calls/day |
119
- | Enterprise — Full or Dev seat | 600 tool calls/day |
120
141
 
121
- MCP and CLI use separate rate limit pools — switching to MCP won't affect your CLI quota. [Full details](https://developers.figma.com/docs/figma-mcp-server/plans-access-and-permissions/)
142
+ <details>
143
+ <summary><strong>Design to Code</strong> (prepare implementation package)</summary>
144
+
145
+ ```bash
146
+ canicode implement ./fixtures/my-design
147
+ canicode implement "https://www.figma.com/design/ABC/File?node-id=1-234" --prompt ./my-react-prompt.md --image-scale 3
148
+ ```
149
+
150
+ Outputs a ready-to-use package for AI code generation:
151
+ - `analysis.json` — issues + scores
152
+ - `design-tree.txt` — DOM-like tree with CSS styles + token estimate
153
+ - `images/` — PNG assets with human-readable names (`hero-banner@2x.png`)
154
+ - `vectors/` — SVG assets
155
+ - `PROMPT.md` — code generation prompt (default: HTML+CSS, or your custom prompt)
156
+
157
+ | Option | Default | Description |
158
+ |--------|---------|-------------|
159
+ | `--prompt` | built-in HTML+CSS | Path to your custom prompt file for any stack |
160
+ | `--image-scale` | `2` | Image export scale: `2` for PC, `3` for mobile |
161
+ | `--output` | `./canicode-implement/` | Output directory |
162
+
163
+ Feed `design-tree.txt` + `PROMPT.md` to your AI assistant (Claude, Cursor, etc.) to generate code.
122
164
 
123
165
  </details>
124
166
 
@@ -129,7 +171,7 @@ MCP and CLI use separate rate limit pools — switching to MCP won't affect your
129
171
  cp -r .claude/skills/canicode /your-project/.claude/skills/
130
172
  ```
131
173
 
132
- Requires the official Figma MCP. Then use `/canicode` with a Figma URL.
174
+ Requires FIGMA_TOKEN. Then use `/canicode` with a Figma URL.
133
175
 
134
176
  </details>
135
177
 
@@ -156,11 +198,8 @@ Posts analysis as a PR comment. Fails if score is below threshold. See [**canico
156
198
  |------|-----|
157
199
  | **Presets** | `--preset relaxed \| dev-friendly \| ai-ready \| strict` |
158
200
  | **Config overrides** | `--config ./config.json` — adjust scores, severity, exclude nodes |
159
- | **Custom rules** | `--custom-rules ./rules.json` — add project-specific checks |
160
-
161
- > Ask any LLM *"Write a canicode custom rule that checks X"* — it can generate the JSON for you.
162
201
 
163
- See [`docs/REFERENCE.md`](docs/REFERENCE.md) for the full guide, examples, and all available options.
202
+ See [`docs/CUSTOMIZATION.md`](docs/CUSTOMIZATION.md) for the full guide, examples, and all available options.
164
203
 
165
204
  ---
166
205
 
@@ -177,19 +216,11 @@ pnpm test # run tests
177
216
  pnpm lint # type check
178
217
  ```
179
218
 
180
- For architecture details, see [`CLAUDE.md`](CLAUDE.md). For calibration pipeline, see [`docs/CALIBRATION.md`](docs/CALIBRATION.md).
219
+ For architecture details, see [`CLAUDE.md`](CLAUDE.md). For calibration pipeline, see the [Calibration wiki](https://github.com/let-sunny/canicode/wiki/Calibration).
181
220
 
182
- ## Roadmap
221
+ ## Contributing
183
222
 
184
- - [x] **Phase 1** 39 rules, density-based scoring, HTML reports, presets, scoped analysis
185
- - [x] **Phase 2** — 4-agent calibration pipeline, `/calibrate-loop` debate loop
186
- - [x] **Phase 3** — Config overrides, MCP server, Claude Skills
187
- - [x] **Phase 4** — Figma comment from report (per-issue "Comment" button in HTML report, posts to Figma node via API)
188
- - [x] **Phase 5** — Custom rules with pattern matching (node name/type/attribute conditions)
189
- - [x] **Phase 6** — Screenshot comparison (`visual-compare` CLI: Figma vs AI-generated code, pixel-level diff)
190
- - [x] **Phase 7** — Calibration pipeline upgrade (visual-compare + Gap Analyzer for objective score validation)
191
- - [x] **Phase 8** — Rule discovery pipeline (6-agent debate: researcher → designer → implementer → A/B visual validation → evaluator → critic)
192
- - [ ] **Ongoing** — Rule refinement via calibration + gap analysis on community fixtures
223
+ **[Share your Figma design](https://github.com/let-sunny/canicode/discussions/new?category=share-your-figma)** to help calibrate scores against real-world designs.
193
224
 
194
225
  ## Support
195
226