canicode 0.11.0 → 0.11.2
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 +18 -6
- package/dist/cli/index.js +670 -188
- package/dist/cli/index.js.map +1 -1
- package/dist/index.d.ts +41 -21
- package/dist/index.js +45 -9
- package/dist/index.js.map +1 -1
- package/dist/mcp/server.js +45 -8
- package/dist/mcp/server.js.map +1 -1
- package/docs/CUSTOMIZATION.md +62 -3
- package/package.json +2 -2
- package/skills/canicode/SKILL.md +6 -0
- package/skills/canicode-gotchas/SKILL.md +91 -66
- package/skills/canicode-roundtrip/SKILL.md +74 -248
- package/skills/canicode-roundtrip/canicode-roundtrip-helpers.d.ts +54 -0
- package/skills/canicode-roundtrip/helpers-bootstrap.js +21 -0
- package/skills/canicode-roundtrip/helpers-installer.js +14 -0
- package/skills/canicode-roundtrip/helpers.js +287 -17
- package/skills/cursor/canicode/SKILL.md +6 -0
- package/skills/cursor/canicode-gotchas/SKILL.md +91 -66
- package/skills/cursor/canicode-roundtrip/SKILL.md +74 -248
- package/skills/cursor/canicode-roundtrip/canicode-roundtrip-helpers.d.ts +54 -0
- package/skills/cursor/canicode-roundtrip/helpers-bootstrap.js +21 -0
- package/skills/cursor/canicode-roundtrip/helpers-installer.js +14 -0
- package/skills/cursor/canicode-roundtrip/helpers.js +287 -17
|
@@ -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:
|
|
@@ -44,13 +52,40 @@ If `isReadyForCodeGen` is `true` or `questions` is empty:
|
|
|
44
52
|
- Do NOT write to `.claude/skills/canicode-gotchas/SKILL.md`.
|
|
45
53
|
- Stop here.
|
|
46
54
|
|
|
55
|
+
### Step 3 — preamble: match the user's language
|
|
56
|
+
|
|
57
|
+
Before rendering any question, detect the user's conversation language from their recent messages in **this** session. Korean vs. English vs. other is usually unambiguous; when ambiguous, default to English and ask the user once which language they prefer.
|
|
58
|
+
|
|
59
|
+
When the user's language is non-English, localize only the **human-readable** strings rendered in the prompt templates below: the `question` text, the `why` line (if shown), the `Hint:` body, the `Example:` body, and the batch shared-prompt wording — including the "Reply with one answer to apply to all …, or **split** to answer each individually" sentence and the `skip` / `n/a` affordance sentence that follows it. Translate at render time only; the rule templates in `core/rules/*` stay English-only per CLAUDE.md and the issue's "Out of scope" list — do not rewrite source.
|
|
60
|
+
|
|
61
|
+
Keep the following English even when localizing, because they are identifiers or structural markers that downstream tools grep for: `ruleId`, `nodeId`, `nodeName`, the severity label in brackets (`[blocking]`, `[risk]`, `[missing-info]`, `[suggestion]`), and the entire markdown scaffolding of the Step 4 upsert section (`## #NNN — …` headings, `Design key`, `#### Skipped (N)`, the per-record field labels). `renderGotchaSection` is the source of truth for that on-disk markdown (ADR-016) and its output stays English.
|
|
62
|
+
|
|
63
|
+
In Step 4, pass the user's answer through **verbatim** into the `answers[<nodeId>].answer` field — do **not** back-translate answers to English. `figma-implement-design` is cross-language by design (see #461), and a round-trip to English introduces translation loss and defeats the "shared language for designer/PM" framing.
|
|
64
|
+
|
|
47
65
|
### Step 3: Present questions to the user
|
|
48
66
|
|
|
49
|
-
The survey response carries a pre-computed `groupedQuestions.groups[].batches[]` shape so this skill never has to sort, partition, or maintain a batchable-rule whitelist in prose. The sort key, `_no-source` sentinel, and batchable-rule
|
|
67
|
+
The survey response carries a pre-computed `groupedQuestions.groups[].batches[]` shape so this skill never has to sort, partition, or maintain a batchable-rule whitelist in prose. The sort key, `_no-source` sentinel, and both batchable-rule lists (`BATCHABLE_RULE_IDS` for `safe` mode, `OPT_IN_BATCHABLE_RULE_IDS` for `opt-in` mode) all live in `core/gotcha/group-and-batch-questions.ts` with vitest coverage (per ADR-016). Iterate over it:
|
|
68
|
+
|
|
69
|
+
**Before presenting the first batch**, display this shortcut notice once so the user knows they can exit early at any point:
|
|
70
|
+
|
|
71
|
+
```
|
|
72
|
+
Survey: {totalBatchCount} question(s) to answer.
|
|
73
|
+
Tip: reply `skip remaining` at any point to bypass the rest with a default no-op annotation and finish immediately.
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
Where `totalBatchCount` is `groupedQuestions.groups.flatMap((g) => g.batches).length`.
|
|
77
|
+
|
|
78
|
+
**After every 3rd batch** (i.e. after batches 3, 6, 9, …), re-surface the shortcut as a brief reminder before presenting the next batch:
|
|
50
79
|
|
|
51
|
-
|
|
80
|
+
```
|
|
81
|
+
(You can still reply `skip remaining` to bypass the remaining questions.)
|
|
82
|
+
```
|
|
52
83
|
|
|
53
|
-
|
|
84
|
+
When the user replies `skip remaining` at any point during Step 3, immediately treat all unanswered batches as skipped (`{ "skipped": true }` for each unanswered `nodeId`) and proceed directly to Step 4 without asking further questions.
|
|
85
|
+
|
|
86
|
+
For every `batch` in `groupedQuestions.groups.flatMap((g) => g.batches)`, branch on `batch.batchMode`:
|
|
87
|
+
|
|
88
|
+
- **`batch.batchMode === "none"`** — single-question batch; the helper guarantees `batch.questions.length === 1`. Render the standard prompt for `batch.questions[0]`:
|
|
54
89
|
|
|
55
90
|
```
|
|
56
91
|
**[{severity}] {ruleId}** — node: {nodeName}
|
|
@@ -61,7 +96,7 @@ For every `batch` in `groupedQuestions.groups.flatMap((g) => g.batches)`:
|
|
|
61
96
|
> Example: {example}
|
|
62
97
|
```
|
|
63
98
|
|
|
64
|
-
-
|
|
99
|
+
- **`batch.batchMode === "safe"` with `batch.questions.length >= 2`** (#369) — rule in `BATCHABLE_RULE_IDS`; one answer is uniformly applicable. Render one shared prompt:
|
|
65
100
|
|
|
66
101
|
```
|
|
67
102
|
**[{severity}] {ruleId}** — {batch.questions.length} instances:
|
|
@@ -79,13 +114,32 @@ For every `batch` in `groupedQuestions.groups.flatMap((g) => g.batches)`:
|
|
|
79
114
|
|
|
80
115
|
Where `sharedQuestionPrompt` reuses the rule's `question` text with the per-node noun replaced by the rule's plural noun (e.g. "These layers all use FILL sizing without min/max constraints. What size boundaries should they share?" instead of repeating the singular phrasing N times).
|
|
81
116
|
|
|
82
|
-
-
|
|
117
|
+
- **`batch.batchMode === "opt-in"` with `batch.questions.length >= 2`** (#426) — rule in `OPT_IN_BATCHABLE_RULE_IDS` (currently `missing-prototype`). The same answer is usually shareable across siblings but may legitimately differ per node — signal that explicitly so the user can opt out of the shared answer with `split`:
|
|
118
|
+
|
|
119
|
+
```
|
|
120
|
+
**[{severity}] {batch.ruleId}** — {batch.questions.length} instances of the same rule:
|
|
121
|
+
- {nodeName₁}
|
|
122
|
+
- {nodeName₂}
|
|
123
|
+
- …
|
|
124
|
+
|
|
125
|
+
{sharedQuestionPrompt}
|
|
126
|
+
|
|
127
|
+
Apply this answer to all {batch.questions.length} occurrences of `{batch.ruleId}`, or reply **split** to answer each individually.
|
|
128
|
+
|
|
129
|
+
> Hint: {hint}
|
|
130
|
+
> Example: {example}
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
Unlike `safe` batches, the prompt frames the answer as a suggested default, not a uniform truth — reuse the rule's existing `example` (e.g. `missing-prototype`'s "navigates to `/product/{id}` detail page") so the user knows the answer can be a pattern, not a literal string shared character-for-character.
|
|
134
|
+
|
|
135
|
+
- **Single-member `safe` or `opt-in` batch (`batch.questions.length === 1`)** — render the single-question template above; the shared-prompt framing collapses to the rule's own wording when there is only one node.
|
|
83
136
|
|
|
84
137
|
Wait for the user's answer before moving to the next batch. The user may:
|
|
85
|
-
- Answer the question / batch directly
|
|
86
|
-
- Say **split** (batch only) to fall back to per-question prompting for that batch
|
|
138
|
+
- Answer the question / batch directly (single value or pattern covers all batch members)
|
|
139
|
+
- Say **split** (batch only) to fall back to per-question prompting for that batch — works the same for both `safe` and `opt-in` batches
|
|
87
140
|
- Say **skip** to skip the question / the entire batch
|
|
88
141
|
- Say **n/a** if the question / the entire batch is not applicable
|
|
142
|
+
- Say **skip remaining** to immediately skip all remaining unanswered batches and proceed to Step 4
|
|
89
143
|
|
|
90
144
|
When applying the batched answer, expand back to per-question records in Step 4 — the gotcha section format stores one record per `nodeId`.
|
|
91
145
|
|
|
@@ -115,77 +169,48 @@ The `core/contracts/design-key.ts` helper (`computeDesignKey`) handles every sha
|
|
|
115
169
|
|
|
116
170
|
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
171
|
|
|
118
|
-
|
|
172
|
+
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.
|
|
173
|
+
|
|
174
|
+
Payload shape:
|
|
175
|
+
|
|
176
|
+
```json
|
|
177
|
+
{
|
|
178
|
+
"survey": {
|
|
179
|
+
"designKey": "<same as Step 4a>",
|
|
180
|
+
"designGrade": "<from gotcha-survey>",
|
|
181
|
+
"questions": "<full questions[] array from gotcha-survey — preserve order>"
|
|
182
|
+
},
|
|
183
|
+
"answers": {
|
|
184
|
+
"<nodeId>": { "answer": "…" }
|
|
185
|
+
},
|
|
186
|
+
"designName": "<Figma file name or fixture label>",
|
|
187
|
+
"figmaUrl": "<the user's input URL or path>",
|
|
188
|
+
"analyzedAt": "<ISO 8601 timestamp when you upsert>",
|
|
189
|
+
"today": "<YYYY-MM-DD local date for the section title>"
|
|
190
|
+
}
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
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`).
|
|
194
|
+
|
|
195
|
+
Invoke (cac requires `--input=-`, not `--input -`, so the stdin sentinel survives parsing — #420):
|
|
119
196
|
|
|
120
197
|
```bash
|
|
121
198
|
npx canicode upsert-gotcha-section \
|
|
122
199
|
--file .claude/skills/canicode-gotchas/SKILL.md \
|
|
123
200
|
--design-key "<designKey from Step 4a>" \
|
|
124
|
-
--
|
|
201
|
+
--input=-
|
|
125
202
|
```
|
|
126
203
|
|
|
127
|
-
|
|
204
|
+
Pipe the JSON object on stdin. `--design-key` must equal `survey.designKey` (the CLI validates the match).
|
|
205
|
+
|
|
206
|
+
The CLI prints JSON `{ state, action, sectionNumber, wrote, userMessage, designKey }`:
|
|
128
207
|
|
|
129
208
|
- `wrote: true` → success. `action` is `"replace"` (preserved `sectionNumber`) or `"append"` (next monotonic `sectionNumber`).
|
|
130
209
|
- `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
210
|
- `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
211
|
- `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
212
|
|
|
134
|
-
The Workflow region above must never be touched.
|
|
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.
|
|
213
|
+
The Workflow region above must never be touched.
|
|
189
214
|
|
|
190
215
|
## Edge Cases
|
|
191
216
|
|
|
@@ -195,5 +220,5 @@ This ensures the code generation agent knows the gotcha exists even if no answer
|
|
|
195
220
|
- **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
221
|
- **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
222
|
- **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.
|
|
223
|
+
- **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
224
|
- **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`).
|