canicode 0.11.0 → 0.11.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.
@@ -180,6 +180,22 @@ Override score, severity, or enable/disable individual rules:
180
180
 
181
181
  Configure the canicode MCP server so Cursor exposes `analyze`, `gotcha-survey`, and other tools.
182
182
 
183
+ ### Which MCP file affects which host?
184
+
185
+ Two different JSON locations are easy to confuse because both can live in a git repo and both use an `mcpServers` object. (See GitHub #436.)
186
+
187
+ | Path | Read by | Purpose |
188
+ | --- | --- | --- |
189
+ | **`.mcp.json`** at the **repository root** | **Claude Code** — `claude mcp add …` (project or user scope) persists entries here. | Shared with teammates when committed; this is the file skills and onboarding mean when they say “check `.mcp.json`” in a **Claude Code** context. |
190
+ | **`.cursor/mcp.json`** | **Cursor** — project-scoped MCP list ([Cursor MCP docs — configuration locations](https://cursor.com/docs/context/mcp)). | Team-shared MCP for Cursor Agent in that workspace. |
191
+ | **`~/.cursor/mcp.json`** | **Cursor** — global MCP list (same doc). | Personal MCP available across all projects; merged with project config (project wins if the same server name appears twice). |
192
+
193
+ **Cursor does not use the repo-root `.mcp.json` for MCP.** If you only edit `.mcp.json` because you copied a Claude Code snippet, Cursor will not load those servers until you add the same `mcpServers` entries under **`.cursor/mcp.json`** or **`~/.cursor/mcp.json`**, then reload MCP or restart Cursor.
194
+
195
+ **Claude Code does not read `.cursor/mcp.json`.** Register servers with `claude mcp add …` (or maintain the root `.mcp.json` format Claude Code expects for your install).
196
+
197
+ **Canicode CLI (`canicode init`):** When suggesting Figma MCP setup for Cursor-heavy flows, the init command treats **either** repo-root `.mcp.json` **or** `.cursor/mcp.json` as evidence that Figma MCP is configured — so mixed-host repos still get accurate “already configured” detection. That does **not** mean Cursor loads `.mcp.json`; it only avoids false negatives when both files exist.
198
+
183
199
  ### Project config (`.cursor/mcp.json`)
184
200
 
185
201
  Create or merge into `.cursor/mcp.json` in your repository root:
@@ -197,6 +213,13 @@ Create or merge into `.cursor/mcp.json` in your repository root:
197
213
 
198
214
  Use long-form `--package` (short `-p` can confuse some parsers). Set your Figma token once with `npx canicode init --token figd_…` — the MCP server reads `~/.canicode/config.json`; you do not need `FIGMA_TOKEN` in the MCP block unless your team prefers env injection.
199
215
 
216
+ ### Figma MCP server id and tool names in Cursor (#437)
217
+
218
+ Cursor may show an MCP **server id** in the UI that is **not** literally the key you typed in `mcpServers` (for example a workspace or project prefix). Skills and docs often say “the `figma` MCP” or “call `use_figma`” as shorthand — **your session’s truth is the live tool list** after MCP reload (Cursor: MCP / Tools panel), not the string `figma` or `use_figma` read from a config file alone.
219
+
220
+ - If roundtrip fails with “cannot find `use_figma`” but Figma MCP shows as connected, open the tool list and note the **exact** tool identifier Cursor exposes (it may be namespaced).
221
+ - Keep the Figma MCP entry in `.cursor/mcp.json` (or `~/.cursor/mcp.json`) per [Figma’s MCP docs](https://developers.figma.com/docs/figma-mcp-server/) — then rely on the host-reported tool name when wiring skills or debugging.
222
+
200
223
  ### Gotcha survey in Cursor
201
224
 
202
225
  1. Add the MCP config above and restart Cursor (or reload MCP).
@@ -208,7 +231,7 @@ Use long-form `--package` (short `-p` can confuse some parsers). Set your Figma
208
231
  - [ ] MCP: Cursor shows `canicode` connected and the tools list includes `gotcha-survey` (and `analyze` if testing roundtrip Step 1).
209
232
  - [ ] Figma MCP: `use_figma` is available when testing **roundtrip** (install + restart host if tools are missing).
210
233
  - [ ] Calling `gotcha-survey` with a local fixture path returns JSON with `designGrade` and `questions` / `isReadyForCodeGen`.
211
- - [ ] After the Q&A loop, `npx canicode upsert-gotcha-section …` succeeds and updates `.claude/skills/canicode-gotchas/SKILL.md`.
234
+ - [ ] After the Q&A loop, `npx canicode upsert-gotcha-section --file … --design-key … --input=-` (JSON payload on stdin per `canicode-gotchas` Step 4b) succeeds and updates `.claude/skills/canicode-gotchas/SKILL.md`.
212
235
  - [ ] Optional: @ **canicode-roundtrip** — Step 4 reads `helpers.js` from `.cursor/skills/canicode-roundtrip/helpers.js` after `canicode init --cursor-skills`.
213
236
 
214
237
  ---
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "canicode",
3
- "version": "0.11.0",
3
+ "version": "0.11.1",
4
4
  "mcpName": "io.github.let-sunny/canicode",
5
5
  "description": "Lint Figma designs for AI code-gen and roundtrip the answers back into the file. CLI + MCP server.",
6
6
  "type": "module",
@@ -13,6 +13,12 @@ This skill works with either channel — the CLI or the canicode MCP server. Bot
13
13
  - A **saved fixture** (from `canicode calibrate-save-fixture`)
14
14
  - A **FIGMA_TOKEN** for live Figma URLs
15
15
 
16
+ ### Step 0: Verify canicode MCP tools are loaded (optional fast path)
17
+
18
+ Before shelling out to `npx canicode analyze …`, check whether the **`analyze` MCP tool** is available in **this** session — not only whether `.mcp.json` lists `canicode`. New MCP registrations usually need a **restart or MCP reload** before tools appear.
19
+
20
+ If you must use the CLI fallback, say so out loud: the user may have added `claude mcp add canicode …` but not restarted yet (#433). After restart/reload, `analyze` via MCP avoids the `npx` spawn. The fallback is valid — silence makes users think the MCP install failed.
21
+
16
22
  ## How to Analyze
17
23
 
18
24
  ### From a Figma URL
@@ -5,6 +5,8 @@ description: Gotcha survey (Claude Code or Cursor) — Q&A workflow; answers acc
5
5
 
6
6
  # CanICode Gotchas — Design Gotcha Survey
7
7
 
8
+ **Channel contrast:** **`canicode-gotchas`** (**this skill**) persists answers **only** in **local** `.claude/skills/canicode-gotchas/SKILL.md` — **memo-only**, no Plugin write to Figma. **`canicode-roundtrip`** writes to the **canvas**. Use gotchas when you want Q&A captured for code-gen context without mutating the file.
9
+
8
10
  Run a gotcha survey on a Figma design to collect implementation context that Figma cannot encode natively, capture developer/designer answers, and upsert them into **`.claude/skills/canicode-gotchas/SKILL.md`** so downstream `figma-implement-design` runs have annotation-ready context. In this model, rules do rule-based best-practice detection, and gotcha is the annotation output from that detection. Some gotchas come from violation rules (what is wrong and how to resolve it); others come from info-collection rules (neutral context Figma cannot represent, like interaction intent/state).
9
11
 
10
12
  **Install location:** The workflow prose may live under `.claude/skills/canicode-gotchas/SKILL.md` (default `canicode init`) or be copied to `.cursor/skills/canicode-gotchas/SKILL.md` (`canicode init --cursor-skills`). The **authoritative gotcha store** is always **`.claude/skills/canicode-gotchas/SKILL.md`** — the CLI `upsert-gotcha-section` writes there only. In the `.claude` copy, this file has two regions: the **Workflow** below (installed by `canicode init`, never overwritten manually) and the **Collected Gotchas** region at the bottom (one numbered section per design, replaced in place on re-runs).
@@ -18,6 +20,12 @@ Run a gotcha survey on a Figma design to collect implementation context that Fig
18
20
 
19
21
  ## Workflow
20
22
 
23
+ ### Step 0: Verify canicode MCP tools are loaded (optional fast path)
24
+
25
+ Before Step 1, verify that `gotcha-survey` is callable in **this** session — not merely listed in `.mcp.json`. Newly registered MCP servers usually need a **host restart or MCP reload** before tools appear (same pattern as `/canicode-roundtrip` Step 0 for the Figma MCP).
26
+
27
+ When you fall back to `npx canicode gotcha-survey … --json`, tell the user explicitly: the canicode MCP may not be loaded yet. They should register it (`claude mcp add canicode -- npx --yes --package=canicode canicode-mcp`, or the Cursor/`mcp.json` equivalent in the Customization guide) and **restart the IDE or reload MCP** — then the next session can use the MCP tool without spawning `npx`. The CLI fallback is correct behavior; silence makes users think registration failed (#433).
28
+
21
29
  ### Step 1: Run the gotcha survey
22
30
 
23
31
  If the `gotcha-survey` MCP tool is available, call it with the user's Figma URL:
@@ -115,77 +123,48 @@ The `core/contracts/design-key.ts` helper (`computeDesignKey`) handles every sha
115
123
 
116
124
  File-state detection (4-way: missing / valid / missing-heading / clobbered) and section walking (find existing `## #NNN — ...` by `Design key` substring, otherwise compute the next monotonic zero-padded NNN) are deterministic markdown operations and live in `core/gotcha/upsert-gotcha-section.ts` with vitest coverage — do not re-implement them in prose (per ADR-016).
117
125
 
118
- Render the per-design section markdown using the **Output Template** below with the literal string `{{SECTION_NUMBER}}` in the header (the CLI substitutes the right NNN for you preserves it on replace, computes the next monotonic value on append). Then invoke:
126
+ Build **one JSON object** on stdin for `upsert-gotcha-section`. The CLI renders the section markdown from `survey` + `answers` via `renderGotchaSection` in TypeScript (#439) severity, rule text, node ids, and instance context come **verbatim** from `gotcha-survey --json`; the skill must not paste LLM-authored section prose.
127
+
128
+ Payload shape:
129
+
130
+ ```json
131
+ {
132
+ "survey": {
133
+ "designKey": "<same as Step 4a>",
134
+ "designGrade": "<from gotcha-survey>",
135
+ "questions": "<full questions[] array from gotcha-survey — preserve order>"
136
+ },
137
+ "answers": {
138
+ "<nodeId>": { "answer": "…" }
139
+ },
140
+ "designName": "<Figma file name or fixture label>",
141
+ "figmaUrl": "<the user's input URL or path>",
142
+ "analyzedAt": "<ISO 8601 timestamp when you upsert>",
143
+ "today": "<YYYY-MM-DD local date for the section title>"
144
+ }
145
+ ```
146
+
147
+ For skipped / n/a: use `{ "skipped": true }` for that `nodeId`, or omit the key. Skipped questions do **not** get per-question rows; `renderGotchaSection` appends a compact **`#### Skipped (N)`** block listing each `ruleId` with a count (`ruleId` lines sorted lexically — see `src/core/gotcha/render-gotcha-section.ts`).
148
+
149
+ Invoke (cac requires `--input=-`, not `--input -`, so the stdin sentinel survives parsing — #420):
119
150
 
120
151
  ```bash
121
152
  npx canicode upsert-gotcha-section \
122
153
  --file .claude/skills/canicode-gotchas/SKILL.md \
123
154
  --design-key "<designKey from Step 4a>" \
124
- --section - # then pipe the rendered section markdown through stdin
155
+ --input=-
125
156
  ```
126
157
 
127
- The CLI prints a JSON result `{ state, action, sectionNumber, wrote, userMessage }`:
158
+ Pipe the JSON object on stdin. `--design-key` must equal `survey.designKey` (the CLI validates the match).
159
+
160
+ The CLI prints JSON `{ state, action, sectionNumber, wrote, userMessage, designKey }`:
128
161
 
129
162
  - `wrote: true` → success. `action` is `"replace"` (preserved `sectionNumber`) or `"append"` (next monotonic `sectionNumber`).
130
163
  - `wrote: false` with `state: "missing"` → tell the user: *"Your gotchas SKILL.md is not installed yet. Run `canicode init` first, then re-invoke this skill."* Stop here.
131
164
  - `wrote: false` with `state: "clobbered"` → tell the user: *"Your gotchas SKILL.md is missing the canicode YAML frontmatter (pre-#340 single-design clobber). Run `canicode init --force` to restore the workflow, then re-run this survey — your answers will land in a clean numbered section."* Stop here.
132
165
  - `wrote: true` with `state: "missing-heading"` → silent recovery. The CLI injected the `# Collected Gotchas` heading and appended the section; the workflow region above is untouched.
133
166
 
134
- The Workflow region above must never be touched. Do NOT copy Workflow prose into the per-design section; the section only carries metadata + gotcha answers.
135
-
136
- ## Output Template
137
-
138
- Each per-design section in the `# Collected Gotchas` region has this exact shape:
139
-
140
- ````markdown
141
- ## #NNN — {designName} — {YYYY-MM-DD}
142
-
143
- - **Figma URL**: {figmaUrl}
144
- - **Design key**: {designKey}
145
- - **Grade**: {designGrade}
146
- - **Analyzed at**: {analyzedAt}
147
-
148
- ### Gotchas
149
-
150
- #### {ruleId} — {nodeName}
151
-
152
- - **Severity**: {severity}
153
- - **Node ID**: {nodeId}
154
- - **Instance context** (omit this bullet if `instanceContext` was not in the survey question): parent instance `parentInstanceNodeId`, source node `sourceNodeId`, component `sourceComponentName` / `sourceComponentId` when present — roundtrip apply uses this to write on the source definition when instance overrides fail.
155
- - **Question**: {question}
156
- - **Answer**: {userAnswer}
157
-
158
- (repeat for each question)
159
- ````
160
-
161
- ### Field mapping
162
-
163
- | Field | Source |
164
- |-------|--------|
165
- | `NNN` | `sectionNumber` — zero-padded three-digit index. Preserved on re-run, incremented on append. |
166
- | `designName` | Figma file name or fixture name from the input |
167
- | `YYYY-MM-DD` | Today's date (the day you are running the survey) |
168
- | `figmaUrl` | The input URL or fixture path provided by the user |
169
- | `designKey` | `survey.designKey` from the gotcha-survey response (see Step 4a) |
170
- | `designGrade` | `designGrade` from gotcha-survey response |
171
- | `analyzedAt` | Current timestamp (ISO 8601) |
172
- | `ruleId` | `ruleId` from each question |
173
- | `nodeName` | `nodeName` from each question |
174
- | `severity` | `severity` from each question (blocking / risk / missing-info — the last surfaces only for info-collection rules per #406) |
175
- | `nodeId` | `nodeId` from each question |
176
- | `instanceContext` | When present on the question, copy `parentInstanceNodeId`, `sourceNodeId`, `sourceComponentId`, `sourceComponentName` into the bullet above (roundtrip / Plugin apply) |
177
- | `question` | `question` from each question |
178
- | `userAnswer` | The answer collected from the user in Step 3 |
179
-
180
- ### Skipped questions
181
-
182
- If the user skipped a question or said "n/a", still include it in the section with:
183
-
184
- ```markdown
185
- - **Answer**: _(skipped)_
186
- ```
187
-
188
- This ensures the code generation agent knows the gotcha exists even if no answer was provided.
167
+ The Workflow region above must never be touched.
189
168
 
190
169
  ## Edge Cases
191
170
 
@@ -195,7 +174,7 @@ This ensures the code generation agent knows the gotcha exists even if no answer
195
174
  - **Workflow region**: Never modified. If you notice the Workflow region has been edited by the user, leave their edits alone — only the `# Collected Gotchas` region is under skill control.
196
175
  - **Pre-#340 clobbered file** (the YAML frontmatter was rewritten to a per-design variant, so the canonical `canicode-gotchas` frontmatter is missing): tell the user to run `canicode init --force` to restore the workflow, then re-run the survey. The prior single-design content cannot be automatically migrated into a `## #001` section — the user re-runs and gets a clean section.
197
176
  - **MCP tool not available**: Fall back to `npx canicode gotcha-survey <input> --json` — the CLI returns the same `GotchaSurvey` shape. If the CLI is also unavailable (e.g. no node runtime), tell the user to install the canicode MCP server or the `canicode` npm package (see Prerequisites).
198
- - **Partial answers**: If the user stops mid-survey, upsert the section with answers collected so far. Mark remaining questions as _(skipped)_.
177
+ - **Partial answers**: If the user stops mid-survey, upsert the section with answers collected so far. Remaining questions count toward **`#### Skipped (N)`** (omit keys or `{ "skipped": true }`).
199
178
  - **Manual section deletion**: If the user deletes a middle section by hand, do not renumber existing sections. The next new section still gets `(highest existing number) + 1`; numeric gaps are acceptable (same pattern as `.claude/docs/ADR.md`).
200
179
 
201
180
  # Collected Gotchas