canicode 0.6.4 → 0.7.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.
package/README.md CHANGED
@@ -23,14 +23,6 @@
23
23
  <img src="docs/screenshot.png" alt="CanICode Report" width="720">
24
24
  </p>
25
25
 
26
- ```bash
27
- npm install -g canicode
28
- canicode init --token YOUR_FIGMA_TOKEN
29
- canicode analyze "https://www.figma.com/design/ABC123/MyDesign?node-id=1-234"
30
- ```
31
-
32
- > Run `canicode docs setup` for the full setup guide — CLI, MCP Server, Claude Skills, and all options.
33
-
34
26
  ---
35
27
 
36
28
  ## How It Works
@@ -48,27 +40,7 @@ canicode analyze "https://www.figma.com/design/ABC123/MyDesign?node-id=1-234"
48
40
 
49
41
  Each issue is classified: **Blocking** > **Risk** > **Missing Info** > **Suggestion**.
50
42
 
51
- Scores use density + diversity weighting per category, combined into an overall grade (S/A+/A/B+/B/C+/C/D/F). Rule scores are calibrated against actual code conversion difficulty — see [Calibration](docs/CALIBRATION.md) for how scores are validated.
52
-
53
- ---
54
-
55
- ## Everything is Configurable
56
-
57
- | What | How | Example |
58
- |------|-----|---------|
59
- | **Presets** | Built-in score profiles | `canicode analyze <url> --preset strict` |
60
- | **Config overrides** | Adjust scores, severity, exclude nodes | `canicode analyze <url> --config ./config.json` |
61
- | **Custom rules** | Add your own checks with pattern matching | `canicode analyze <url> --custom-rules ./rules.json` |
62
- | **Combine** | Use all together | `canicode analyze <url> --preset ai-ready --config ./config.json --custom-rules ./rules.json` |
63
-
64
- | Preset | What it does |
65
- |--------|-------------|
66
- | `relaxed` | Downgrades blocking → risk, scores −50% |
67
- | `dev-friendly` | Layout and handoff rules only |
68
- | `ai-ready` | Structure and naming weights +150% |
69
- | `strict` | All rules enabled, scores +150% |
70
-
71
- > **Custom rules tip:** Ask any LLM *"Write a canicode custom rule that checks X"* — it can generate the JSON for you. See [`docs/CUSTOMIZATION.md`](docs/CUSTOMIZATION.md) for the full guide.
43
+ Scores use density + diversity weighting per category, combined into an overall grade (S/A+/A/B+/B/C+/C/D/F). Rule scores are calibrated against actual code conversion difficulty — see [`docs/CALIBRATION.md`](docs/CALIBRATION.md).
72
44
 
73
45
  ---
74
46
 
@@ -76,39 +48,24 @@ Scores use density + diversity weighting per category, combined into an overall
76
48
 
77
49
  Five ways to use CanICode. Pick one.
78
50
 
79
- ### Figma Plugin (under review)
80
-
81
- Install from **[Figma Community](https://www.figma.com/community/plugin/1617144221046795292/canicode)** — analyze directly inside Figma. No tokens needed.
82
-
83
- ### Web (no install)
84
-
85
- Go to **[let-sunny.github.io/canicode](https://let-sunny.github.io/canicode/)**, paste a Figma URL, and get results instantly in your browser.
86
-
87
- ### CLI (standalone)
51
+ ### 1. CLI
88
52
 
89
53
  ```bash
90
54
  npx canicode analyze "https://www.figma.com/design/ABC123/MyDesign?node-id=1-234"
91
-
92
- # Or install globally
93
- npm install -g canicode
94
- canicode analyze "https://www.figma.com/design/ABC123/MyDesign?node-id=1-234"
95
55
  ```
96
56
 
97
- To enable "Comment on Figma" buttons in reports, set your Figma token:
57
+ Setup:
98
58
  ```bash
99
59
  canicode init --token figd_xxxxxxxxxxxxx
100
60
  ```
101
61
 
102
62
  > **Get your token:** Figma → Settings → Security → Personal access tokens → Generate new token
103
63
 
104
- ### MCP Server (Claude Code / Cursor / Claude Desktop)
64
+ ### 2. MCP Server (Claude Code / Cursor / Claude Desktop)
105
65
 
106
66
  **Claude Code (recommended — with official Figma MCP, no token needed):**
107
67
  ```bash
108
- # 1. Install canicode MCP server
109
68
  claude mcp add canicode -- npx -y -p canicode canicode-mcp
110
-
111
- # 2. Install official Figma MCP (enables token-free analysis)
112
69
  claude mcp add -s project -t http figma https://mcp.figma.com/mcp
113
70
  ```
114
71
 
@@ -117,243 +74,39 @@ claude mcp add -s project -t http figma https://mcp.figma.com/mcp
117
74
  claude mcp add canicode -e FIGMA_TOKEN=figd_xxxxxxxxxxxxx -- npx -y -p canicode canicode-mcp
118
75
  ```
119
76
 
120
- **Cursor** (`~/.cursor/mcp.json`):
121
- ```json
122
- {
123
- "mcpServers": {
124
- "canicode": {
125
- "command": "npx",
126
- "args": ["-y", "-p", "canicode", "canicode-mcp"],
127
- "env": {
128
- "FIGMA_TOKEN": "figd_xxxxxxxxxxxxx"
129
- }
130
- }
131
- }
132
- }
133
- ```
134
-
135
- **Claude Desktop** (`~/Library/Application Support/Claude/claude_desktop_config.json`):
136
- ```json
137
- {
138
- "mcpServers": {
139
- "canicode": {
140
- "command": "npx",
141
- "args": ["-y", "-p", "canicode", "canicode-mcp"],
142
- "env": {
143
- "FIGMA_TOKEN": "figd_xxxxxxxxxxxxx"
144
- }
145
- }
146
- }
147
- }
148
- ```
77
+ For Cursor / Claude Desktop config, see [`docs/CUSTOMIZATION.md`](docs/CUSTOMIZATION.md).
149
78
 
150
79
  Then ask: *"Analyze this Figma design: https://www.figma.com/design/..."*
151
80
 
152
- > With `FIGMA_TOKEN` set, the HTML report includes "Comment on Figma" buttons that post analysis findings directly to Figma nodes.
153
-
154
- ---
155
-
156
- <details>
157
- <summary><strong>Data Sources</strong></summary>
158
-
159
- | Flag | Source | Token required |
160
- |------|--------|----------------|
161
- | (none) | Figma REST API | Yes |
162
- | `--api` | Figma REST API (explicit) | Yes |
163
-
164
- For token-free analysis, use the **canicode MCP server** with the official Figma MCP, or the **`/canicode` skill** in Claude Code.
165
-
166
- Token priority:
167
- 1. `--token` flag (one-time override)
168
- 2. `FIGMA_TOKEN` env var (CI/CD)
169
- 3. `~/.canicode/config.json` (`canicode init`)
170
-
171
- </details>
172
-
173
- <details>
174
- <summary><strong>Presets</strong></summary>
175
-
176
- | Preset | Behavior |
177
- |--------|----------|
178
- | `relaxed` | Downgrades blocking to risk, reduces scores by 50% |
179
- | `dev-friendly` | Focuses on layout and handoff rules only |
180
- | `ai-ready` | Boosts structure and naming rule weights by 150% |
181
- | `strict` | Enables all rules, increases all scores by 150% |
182
-
183
- ```bash
184
- canicode analyze <url> --preset strict
185
- ```
186
-
187
- </details>
188
-
189
-
190
- <details>
191
- <summary><strong>Config Overrides</strong></summary>
192
-
193
- Override rule scores, severity, node exclusions, and global settings:
194
-
195
- ```bash
196
- canicode analyze <url> --config ./my-config.json
197
- ```
198
-
199
- ```json
200
- {
201
- "excludeNodeNames": ["chatbot", "ad-banner", "wip"],
202
- "gridBase": 4,
203
- "rules": {
204
- "no-auto-layout": { "score": -15, "severity": "blocking" },
205
- "default-name": { "enabled": false }
206
- }
207
- }
208
- ```
209
-
210
- | Option | Description |
211
- |--------|-------------|
212
- | `gridBase` | Spacing grid unit (default: 4) |
213
- | `colorTolerance` | Color difference tolerance (default: 10) |
214
- | `excludeNodeTypes` | Node types to skip |
215
- | `excludeNodeNames` | Node name patterns to skip |
216
- | `rules.<id>.score` | Override rule score |
217
- | `rules.<id>.severity` | Override rule severity |
218
- | `rules.<id>.enabled` | Enable/disable a rule |
219
-
220
- See [`examples/config.json`](examples/config.json) | [`docs/CUSTOMIZATION.md`](docs/CUSTOMIZATION.md) | Run `canicode docs config`
81
+ ### 3. Web (no install)
221
82
 
222
- </details>
223
-
224
- <details>
225
- <summary><strong>Custom Rules</strong></summary>
226
-
227
- Add project-specific checks with declarative pattern matching:
228
-
229
- ```bash
230
- canicode analyze <url> --custom-rules ./my-rules.json
231
- ```
232
-
233
- ```json
234
- [
235
- {
236
- "id": "icon-not-component",
237
- "category": "component",
238
- "severity": "blocking",
239
- "score": -10,
240
- "match": {
241
- "type": ["FRAME", "GROUP"],
242
- "maxWidth": 48,
243
- "maxHeight": 48,
244
- "hasChildren": true,
245
- "nameContains": "icon"
246
- },
247
- "message": "\"{name}\" is an icon but not a component",
248
- "why": "Icons that are not components cannot be reused consistently.",
249
- "impact": "Developers will hardcode icon SVGs instead of using a shared component.",
250
- "fix": "Convert this icon to a component and publish it to the design system library."
251
- }
252
- ]
253
- ```
254
-
255
- Conditions use AND logic — all must match for the rule to fire. Available conditions: `type`, `notType`, `nameContains`, `nameNotContains`, `namePattern`, `minWidth`, `maxWidth`, `minHeight`, `maxHeight`, `hasAutoLayout`, `hasChildren`, `minChildren`, `maxChildren`, `isComponent`, `isInstance`, `hasComponentId`, `isVisible`, `hasFills`, `hasStrokes`, `hasEffects`, `minDepth`, `maxDepth`.
256
-
257
- Combine with config overrides:
258
- ```bash
259
- canicode analyze <url> --config ./config.json --custom-rules ./rules.json
260
- ```
261
-
262
- > **Tip:** Ask any LLM *"Write a canicode custom rule that checks X"* with the conditions above — it can generate the JSON for you.
263
-
264
- See [`examples/custom-rules.json`](examples/custom-rules.json) | [`docs/CUSTOMIZATION.md`](docs/CUSTOMIZATION.md)
265
-
266
- </details>
267
-
268
- <details>
269
- <summary><strong>Scoring Algorithm</strong></summary>
270
-
271
- ```
272
- Final Score = (Density Score × 0.7) + (Diversity Score × 0.3)
273
-
274
- Density Score = 100 - (weighted issue count / node count) × 100
275
- Diversity Score = (1 - unique violated rules / total rules in category) × 100
276
- ```
277
-
278
- Severity weights issues — a single blocking issue counts 3x more than a suggestion. Scores are calculated per category and combined into an overall grade (S/A+/A/B+/B/C+/C/D/F).
279
-
280
- > Weights and rule scores are validated through a 4-agent calibration pipeline. See [docs/CALIBRATION.md](docs/CALIBRATION.md) for details.
281
-
282
- </details>
283
-
284
- <details>
285
- <summary><strong>MCP Server Details</strong></summary>
286
-
287
- The `canicode-mcp` server exposes two tools: `analyze` and `list-rules`.
288
-
289
- **Route A — Figma MCP relay (no token):**
290
-
291
- ```
292
- Claude Code → Figma MCP get_metadata → XML node tree
293
- Claude Code → canicode MCP analyze(designData: XML) → result
294
- ```
295
-
296
- **Route B — REST API direct (token):**
297
-
298
- ```
299
- Claude Code → canicode MCP analyze(input: URL) → internal fetch → result
300
- ```
301
-
302
- Route A requires two MCP servers (figma + canicode). Route B requires one + a saved token.
303
-
304
- The `analyze` tool accepts `designData` (XML/JSON from Figma MCP) or `input` (Figma URL / fixture path). When both are provided, `designData` takes priority.
305
-
306
- </details>
307
-
308
- <details>
309
- <summary><strong>Save Fixture</strong></summary>
83
+ Go to **[let-sunny.github.io/canicode](https://let-sunny.github.io/canicode/)**, paste a Figma URL, and get results instantly in your browser.
310
84
 
311
- Save Figma file data as JSON for offline analysis:
85
+ ### 4. Figma Plugin (under review)
312
86
 
313
- ```bash
314
- canicode save-fixture https://www.figma.com/design/ABC123/MyDesign
315
- ```
316
-
317
- </details>
87
+ Install from **[Figma Community](https://www.figma.com/community/plugin/1617144221046795292/canicode)** — analyze directly inside Figma. No tokens needed.
318
88
 
319
89
  ---
320
90
 
321
- <details>
322
- <summary><strong>Tech Stack</strong></summary>
323
-
324
- | Layer | Tool |
325
- |-------|------|
326
- | Runtime | Node.js (>= 18) |
327
- | Language | TypeScript (strict mode) |
328
- | Package Manager | pnpm |
329
- | Validation | Zod |
330
- | Testing | Vitest |
331
- | CLI | cac |
332
- | Build | tsup |
91
+ ## Customization
333
92
 
334
- </details>
93
+ | What | How |
94
+ |------|-----|
95
+ | **Presets** | `--preset relaxed \| dev-friendly \| ai-ready \| strict` |
96
+ | **Config overrides** | `--config ./config.json` — adjust scores, severity, exclude nodes |
97
+ | **Custom rules** | `--custom-rules ./rules.json` — add project-specific checks |
335
98
 
336
- <details>
337
- <summary><strong>Calibration (Internal)</strong></summary>
99
+ > Ask any LLM *"Write a canicode custom rule that checks X"* — it can generate the JSON for you.
338
100
 
339
- Rule scores are validated against actual code conversion difficulty via a calibration pipeline. This runs inside Claude Code using `/calibrate-loop` not exposed as a CLI command.
101
+ See [`docs/CUSTOMIZATION.md`](docs/CUSTOMIZATION.md) for the full guide, examples, and all available options.
340
102
 
341
- The pipeline uses 4 subagents:
342
- 1. **Runner** — Analyzes a fixture and extracts issue data
343
- 2. **Converter** — Converts flagged Figma nodes to code via Figma MCP
344
- 3. **Critic** — Reviews proposed score adjustments
345
- 4. **Arbitrator** — Makes final decisions and commits changes
346
-
347
- </details>
103
+ ---
348
104
 
349
- <details>
350
- <summary><strong>Development</strong></summary>
105
+ ## Development
351
106
 
352
107
  ```bash
353
- git clone https://github.com/let-sunny/canicode.git
354
- cd canicode
355
- pnpm install
356
- pnpm build
108
+ git clone https://github.com/let-sunny/canicode.git && cd canicode
109
+ pnpm install && pnpm build
357
110
  ```
358
111
 
359
112
  ```bash
@@ -362,7 +115,7 @@ pnpm test # run tests
362
115
  pnpm lint # type check
363
116
  ```
364
117
 
365
- </details>
118
+ For architecture details, see [`CLAUDE.md`](CLAUDE.md). For calibration pipeline, see [`docs/CALIBRATION.md`](docs/CALIBRATION.md).
366
119
 
367
120
  ## Roadmap
368
121