designsnitch 0.1.0 → 0.3.0

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
@@ -1,42 +1,123 @@
1
1
  # designsnitch
2
2
 
3
- AI가 만든 UI 코드에서 디자인이 틀린 곳을 찾아내는 도구입니다. 기준은 프로젝트의 디자인 시스템입니다. 토큰과 컴포넌트 규칙을 벗어난 곳을 찾고, 무엇으로 고치면 되는지 알려줍니다.
3
+ English | [Korean](./README.ko.md)
4
4
 
5
- 세 부분으로 되어 있습니다.
5
+ designsnitch helps keep a UI codebase manageable and consistent when the project has no design system, or has one in name only. It is built for code written by AI agents, which produce plausible UI quickly and scatter colors, spacing and components across screens as they go.
6
6
 
7
- | 부분 | 하는 일 |
8
- | --- | --- |
9
- | 검사 엔진 | 코드를 AST로 분석해 위반 위치와 대체 후보를 찾습니다. |
10
- | CLI | `designsnitch check`로 검사를 실행합니다. 사람이 읽는 출력과 JSON 출력을 냅니다. |
11
- | 에이전트 스킬 | AI 에이전트에게 언제 검사하고, 무엇을 고치고, 무엇을 사람에게 물을지 알려줍니다. |
7
+ It works inside the code, with no designer or Figma file required.
12
8
 
13
- 첫 지원 대상은 **React/Next.js + Tailwind CSS** 프로젝트입니다.
9
+ 1. **Establish a standard.** It collects the values the code already uses so you can turn them into tokens.
10
+ 2. **Keep to it.** It checks new code against that standard and tells you what to use instead.
11
+ 3. **Clean up.** It helps bring code that has already drifted back to the standard.
14
12
 
15
- > **상태:** MVP(0.1.x). [지금 되는 것](#지금-되는-것) 아래의 나머지 내용은 목표 설계이며, 정해지지 않은 부분은 [미정 사항](#미정-사항)에 모아 두었습니다.
13
+ Deciding what the standard is stays with the developer. The tool's job is to bring what is needed to make that decision.
16
14
 
17
- ## 지금 되는 것
15
+ It has four parts.
18
16
 
19
- Tailwind 클래스에 값을 직접 쓴 곳(`bg-[#3B82F6]`, `p-[16px]`)과 raw 태그를 찾아서 디자인 시스템과 비교합니다.
17
+ | Part | What it is for |
18
+ | --- | --- |
19
+ | CLI | A tool for the AI agent. It collects the colors in use, checks code, and says what to do with each violation. |
20
+ | Agent skills | Tell an AI agent how to set the project up, when to run the CLI, what to fix, and what to ask a person about. |
21
+ | ESLint plugin | Blocks and warns. The same rules show up as errors and warnings in the editor and in the lint step. |
22
+ | Agent hook | Blocks while the code is being written. The agent is told about errors after each edit and cannot finish while errors it can fix remain. |
20
23
 
21
- | 규칙 | 등급 | 잡는 것 |
22
- | --- | --- | --- |
23
- | `color-use-token` | 오류 | 토큰이 있는 색을 hex로 씀 |
24
- | `color-unknown` | 경고 | 토큰이 없는 hex |
25
- | `scale-use-token` | 오류 | 스케일에 있는 간격, 폰트 크기, radius를 임의 값으로 씀 |
26
- | `scale-unknown` | 경고 | 스케일에 없는 간격, 폰트 크기, radius |
27
- | `use-ds-component` | 오류 | 디자인 시스템 컴포넌트가 있는 raw 태그를 디자인 시스템 경로 밖에서 씀 |
24
+ It supports **React/Next.js projects that use Tailwind CSS v4**.
28
25
 
29
- ### 설치
26
+ > **Status:** MVP (0.2.x). Messages are in English by default and can be switched to Korean. See [Language](#language).
27
+
28
+ ## Getting started
30
29
 
31
30
  ```sh
32
31
  npm install --save-dev designsnitch
32
+ npx designsnitch install
33
33
  ```
34
34
 
35
- Node.js 22 이상이 필요합니다.
35
+ The second command installs the agent skills and registers the agent hook. Node.js 22 or later is required.
36
+
37
+ | Agent | Command | Skills go to | Hook goes to |
38
+ | --- | --- | --- | --- |
39
+ | Claude Code | `npx designsnitch install` | `.claude/skills` | `.claude/settings.json` |
40
+ | Codex | `npx designsnitch install --agent codex` | `.agents/skills` | `.codex/hooks.json` |
41
+ | Gemini CLI | `npx designsnitch install --agent gemini` | `.agents/skills` | `.gemini/settings.json` |
42
+ | Grok Build | `npx designsnitch install --agent grok` | `.grok/skills` | `.grok/hooks/designsnitch.json` |
43
+ | All of them | `npx designsnitch install --agent all` | | |
44
+
45
+ Codex, Gemini CLI and Grok Build run a new project hook only after you approve or trust it. Open the agent in the project and approve when it asks. In Grok Build, use `/hooks-trust` or start it with `--trust`.
46
+
47
+ | Agent | How the hook was checked |
48
+ | --- | --- |
49
+ | Claude Code | Run with the real agent. It wrote a hex color, was told by the hook, and switched to the token class. |
50
+ | Codex | Run with the real agent. Same result. |
51
+ | Gemini CLI | **Not tested.** Built from the official Gemini CLI documentation. |
52
+ | Grok Build | **Not tested.** Built from the official xAI documentation. See the note under [Agent hook](#agent-hook). |
53
+
54
+ The skills follow the open Agent Skills format, so any agent that supports it can use them. The standard installer puts them where each agent looks: `npx skills add icecokel/designsnitch`. It installs the skills only, not the hook.
55
+
56
+ Then ask your coding agent:
57
+
58
+ > Set up designsnitch in this project.
59
+
60
+ The agent follows the `designsnitch-setup` skill and does the rest.
61
+
62
+ 1. It checks that the project is supported.
63
+ 2. It finds the token CSS and the shared component directory, and writes `designsnitch.config.json`.
64
+ 3. If the project has no color tokens, it collects the colors the code uses and proposes tokens. Nothing is written until you approve.
65
+ 4. It puts the rules into ESLint, installing ESLint if the project has none.
66
+ 5. It shows you what it chose and what the first check found.
67
+
68
+ From then on:
69
+
70
+ - The agent is told about errors right after it edits a file, and cannot finish while errors it can fix remain.
71
+ - Errors fail the lint step, and show up in the editor.
72
+ - `npx designsnitch check` reports where the code stands at any time.
73
+
74
+ To do any of this without an agent, see [Setting up by hand](#setting-up-by-hand).
75
+
76
+ ## Why
36
77
 
37
- ### 설정
78
+ When there is no standard, every screen makes its own choices. An AI agent makes them quickly and plausibly, and they add up.
38
79
 
39
- 프로젝트 루트에 `designsnitch.config.json`을 만듭니다. [에이전트 스킬](#에이전트-스킬)을 쓰면 에이전트가 저장소를 읽어서 이 파일을 만듭니다.
80
+ - The same blue is `#3B82F6` on one screen and `#3B82F5` on another.
81
+ - A color is written by hand in a hundred places, so changing the brand color or adding dark mode means finding every one of them.
82
+ - Each screen builds its own button from `<button>`, each a little different, some without a focus style.
83
+
84
+ The result is a codebase that is hard to manage and a product that is hard to keep consistent. And with no standard, there is nothing to check new code against. designsnitch helps you set a standard from what the code already does, and then holds new code to it.
85
+
86
+ ## What it catches
87
+
88
+ Severity follows one rule.
89
+
90
+ | Severity | Meaning |
91
+ | --- | --- |
92
+ | **Error** | The design system has a token or component for this, and the code did not use it. Even if the screen looks the same today, this code will not follow when the design system changes. |
93
+ | **Warning** | The design system has no matching token. A person has to decide whether a new value is really needed or it is a mistake. |
94
+
95
+ | Rule | Severity | What it catches |
96
+ | --- | --- | --- |
97
+ | `color-use-token` | Error | A hex color that has a token, written as an arbitrary value (`bg-[#3B82F6]`) or in a CSS declaration (`color: #3B82F6`) |
98
+ | `color-unknown` | Warning | A hex color with no matching token |
99
+ | `use-ds-component` | Error | A raw tag such as `<button>` used outside the design system directory, when a shared component replaces it |
100
+
101
+ Every error comes with what to use instead: a class or component in JS and TS files, and `var(--token)` in CSS files.
102
+
103
+ ## Commands
104
+
105
+ | Command | What it does |
106
+ | --- | --- |
107
+ | `designsnitch install` | Copies the skills and registers the agent hook in the project. `--agent claude` (default), `codex`, `gemini`, `grok` or `all`. |
108
+ | `designsnitch colors` | Lists the colors the code uses. Works without a config file. |
109
+ | `designsnitch check` | Checks code against the standard and says what to do with each violation. |
110
+ | `designsnitch hook` | Called from the agent's hook. Checks the files the agent just changed. |
111
+
112
+ `check` and `colors` take paths, `--format json`, and `--config <file>`. Every command takes `--lang en|ko`.
113
+
114
+ ## Setting up by hand
115
+
116
+ ```sh
117
+ npm install --save-dev designsnitch
118
+ ```
119
+
120
+ Create `designsnitch.config.json` in the project root.
40
121
 
41
122
  ```json
42
123
  {
@@ -45,78 +126,137 @@ Node.js 22 이상이 필요합니다.
45
126
  "path": "./components/ui",
46
127
  "replaces": {
47
128
  "button": ["SolidButton", "IconButton"],
48
- "input": "Input",
129
+ "input": { "component": "Input", "when": { "type": ["text", "email", null] } },
49
130
  "dialog": "Dialog"
50
131
  }
51
132
  }
52
133
  }
53
134
  ```
54
135
 
55
- | 항목 | 설명 |
136
+ Then run the check.
137
+
138
+ ```sh
139
+ npx designsnitch check # the whole project
140
+ npx designsnitch check src/PayButton.tsx # some files only
141
+ npx designsnitch check --format json # for CI and AI agents
142
+ ```
143
+
144
+ The fields are described in [Configuration](#configuration). To block violations, add the rules to [ESLint](#eslint) and register the [agent hook](#agent-hook).
145
+
146
+ ## Starting without tokens
147
+
148
+ Some projects have no color tokens yet: colors are written straight into the code. `designsnitch colors` lists the colors the code uses, so you can turn them into tokens. It works without a config file.
149
+
150
+ ```sh
151
+ npx designsnitch colors
152
+ npx designsnitch colors --format json
153
+ ```
154
+
155
+ ```
156
+ Colors used in the code: 5 hex, 1 from the default palette (10 uses, 1 file checked)
157
+
158
+ Hex colors
159
+ #3a11d8 3 uses 1 file bg 2, string 1
160
+ #484646 2 uses 1 file text 2
161
+ #ffffff 2 uses 1 file bg 1, text 1
162
+ #484645 1 use 1 file text 1
163
+ #e2e1e5 1 use 1 file border 1
164
+
165
+ Tailwind default palette
166
+ gray-700 1 use 1 file text 1
167
+ ```
168
+
169
+ | Part of the output | Meaning |
56
170
  | --- | --- |
57
- | `tokens` | 토큰이 정의된 CSS 파일입니다. 필수입니다. |
58
- | `components.path` | 디자인 시스템 컴포넌트가 있는 경로입니다. 이 안에서는 raw 태그를 써도 됩니다. |
59
- | `components.replaces` | raw 태그와 그것을 대체하는 컴포넌트입니다. 컴포넌트가 여러 개면 배열로 적습니다. |
171
+ | `Hex colors` | Hex colors, most used first, with the number of uses and files. |
172
+ | `bg 2`, `text 1` | Uses per Tailwind utility. `bg-[#3a11d8]` counts under `bg`. |
173
+ | `string 1` | Strings that are a hex color on their own, such as inline styles and chart options. |
174
+ | `CSS 2` | Uses in CSS declarations. The JSON output breaks these down by property. |
175
+ | `Tailwind default palette` | Colors from Tailwind's default palette used by name, such as `text-gray-700`. |
176
+
177
+ When a config file exists, each color also shows the tokens that already have that value (`token: --color-brand`), or `no token` when there is none. The JSON output has the same data plus a few example locations per color.
60
178
 
61
- `components`를 생략하면 컴포넌트 검사를 하지 않습니다.
179
+ The [`designsnitch-palette` skill](#agent-skills) uses this output to propose tokens, and writes them after you approve.
62
180
 
63
- 토큰 CSS에서 읽는 변수는 다음과 같습니다.
181
+ ## Configuration
64
182
 
65
- | 변수 | 쓰임 | 없을 때 |
183
+ | Field | Description |
184
+ | --- | --- |
185
+ | `tokens` | The CSS file that defines the tokens. Required. |
186
+ | `components.path` | The directory that holds the design system components. Raw tags are allowed inside it. |
187
+ | `components.replaces` | Raw tags and the components that replace them. Use an array when several components replace one tag. Use `{ "component": ..., "when": { ... } }` when a component covers only some variants of the tag (see below). |
188
+ | `lang` | The language of the messages: `en` (default) or `ko`. |
189
+
190
+ Without `components`, the component check is skipped. Use `--config <file>` to read a config file from another path.
191
+
192
+ A shared component often covers only some variants of a tag. An `Input` component may cover text fields but not `<input type="file">`. `when` lists the attribute values the component covers. `null` means the attribute is absent.
193
+
194
+ ```json
195
+ "input": { "component": "Input", "when": { "type": ["text", "email", null] } }
196
+ ```
197
+
198
+ - `<input type="file">` is not reported, because the component does not cover it.
199
+ - `<input type="text">` and `<input>` are reported as errors that can be replaced.
200
+ - `<input type={kind}>` and `<input {...props}>` are reported, but marked `ask`: the value is only known at runtime, or a spread may override it, so replacing is not known to be safe.
201
+
202
+ This is what is read from the token CSS.
203
+
204
+ | Variable | Used for | When missing |
66
205
  | --- | --- | --- |
67
- | `--color-*` | 색. 값이 hex이거나, `var()`로 hex 값을 가진 변수를 가리켜야 합니다. | 모든 hex가 경고가 됩니다 |
68
- | `--spacing` | 간격 단위 | Tailwind 기본값 `0.25rem`을 씁니다 |
69
- | `--radius-*` | radius | radius를 검사하지 않습니다 |
70
- | `--text-*` | 폰트 크기 | 폰트 크기를 검사하지 않습니다 |
206
+ | `--color-*` | Colors. The value must be a hex color, or a `var()` that leads to one. | Every hex color becomes a warning |
207
+
208
+ Both of these shapes work.
71
209
 
72
210
  ```css
211
+ /* Values directly in @theme */
73
212
  @theme {
74
213
  --color-primary-500: #3B82F6;
75
214
  --color-surface: #ffffff;
76
- --radius-sm: 0.25rem;
77
- --radius-md: 0.375rem;
78
- --text-sm: 0.875rem;
79
- --text-base: 1rem;
215
+ }
216
+
217
+ /* Values in :root, referenced from @theme */
218
+ :root {
219
+ --primary-500: #3B82F6;
220
+ }
221
+ @theme {
222
+ --color-primary-500: var(--primary-500);
80
223
  }
81
224
  ```
82
225
 
83
- ### 실행
226
+ ## Language
84
227
 
85
- ```sh
86
- npx designsnitch check # 프로젝트 전체
87
- npx designsnitch check src/PayButton.tsx # 일부만
88
- npx designsnitch check --format json # CI나 AI 에이전트용
89
- ```
228
+ Messages are in English by default. To read them in Korean, set `"lang": "ko"` in `designsnitch.config.json`, set the environment variable `DESIGNSNITCH_LANG=ko`, or pass `--lang ko`. When more than one is given, `--lang` wins, then the config file, then the environment variable.
229
+
230
+ The ESLint plugin reads the same `lang` from its settings. Rule names, the layout of the output and the JSON field names are the same in both languages.
231
+
232
+ ## Output
90
233
 
91
234
  ```
92
- 디자인 시스템: 색 토큰 2개, radius 토큰 2개, 폰트 크기 토큰 2개, 컴포넌트 2개
235
+ Design system: 2 color tokens, 2 components
93
236
 
94
237
  src/PayButton.tsx
95
- 5:6 오류 <button> 대신 디자인 시스템 컴포넌트를 사용하세요: Button (./components/ui) (use-ds-component)
96
- 7:10 오류 rounded-[6px]의 값은 radius 토큰에 있습니다. 대신 사용: rounded-md (scale-use-token)
97
- 7:24 오류 px-[16px]의 값은 간격 스케일에 있습니다. 대신 사용: px-4 (scale-use-token)
98
- 7:34 경고 py-[7px]의 값은 간격 스케일에 없습니다. 가까운 값: py-1.5 (6px), py-2 (8px) (scale-unknown)
99
- 7:55 오류 bg-[#3B82F6]의 색은 토큰 --color-primary-500의 값입니다. 대신 사용: bg-primary-500 (color-use-token)
100
- 8:26 경고 bg-[#3B82F5]의 색은 토큰에 없습니다. (color-unknown)
101
-
102
- 오류 4개, 경고 2개 (파일 3개 검사)
238
+ 5:6 error Use a design system component instead of <button>: Button (./components/ui) (use-ds-component)
239
+ 7:55 error bg-[#3B82F6] has the same color as --color-primary-500. Use instead: bg-primary-500 (color-use-token)
240
+ 8:26 warning The color of bg-[#3B82F5] is not in the tokens. (color-unknown)
241
+
242
+ 2 errors, 1 warning (3 files checked)
243
+ 2 can be replaced right away, 1 needs a person's decision
103
244
  ```
104
245
 
105
- 첫 줄은 설정에서 읽어 낸 토큰과 컴포넌트의 개수입니다. 경로를 잘못 적으면 여기서 0개로 드러납니다. 색 토큰을 하나도 읽지 못하면 `주의:`로 시작하는 줄이 함께 나옵니다.
246
+ The first line shows how many tokens and components were read from the config. A wrong path shows up here as a zero. If no color token could be read, a line starting with `Note:` explains why. The last line says how many violations can be replaced right away and how many need a person's decision.
106
247
 
107
- `--format json`은 같은 결과를 구조화해서 냅니다.
248
+ `--format json` prints the same result as structured data.
108
249
 
109
250
  ```json
110
251
  {
111
- "designSystem": {
112
- "colorTokens": 2,
113
- "radiusTokens": 2,
114
- "textTokens": 2,
115
- "components": 2,
116
- "replacedTags": 2
117
- },
252
+ "designSystem": { "colorTokens": 2, "components": 2, "replacedTags": 2 },
118
253
  "problems": [],
119
- "summary": { "files": 3, "errors": 4, "warnings": 2 },
254
+ "next": [
255
+ "action \"replace\" (2): replace found with the value in candidates.",
256
+ "action \"ask\" (1): do not change these. Ask the user, and include how often and for what each color is used, which `designsnitch colors` shows.",
257
+ "After fixing, run the same command again."
258
+ ],
259
+ "summary": { "files": 3, "errors": 2, "warnings": 1 },
120
260
  "violations": [
121
261
  {
122
262
  "file": "src/PayButton.tsx",
@@ -126,254 +266,205 @@ src/PayButton.tsx
126
266
  "endColumn": 67,
127
267
  "rule": "color-use-token",
128
268
  "severity": "error",
129
- "message": "bg-[#3B82F6]의 색은 토큰 --color-primary-500의 값입니다. 대신 사용: bg-primary-500",
269
+ "message": "bg-[#3B82F6] has the same color as --color-primary-500. Use instead: bg-primary-500",
130
270
  "found": "bg-[#3B82F6]",
131
- "candidates": ["bg-primary-500"]
271
+ "candidates": ["bg-primary-500"],
272
+ "action": "replace"
132
273
  }
133
274
  ]
134
275
  }
135
276
  ```
136
277
 
137
- | 필드 | 내용 |
278
+ | Field | Content |
138
279
  | --- | --- |
139
- | `designSystem` | 설정에서 읽어 낸 토큰과 컴포넌트의 개수 |
140
- | `problems` | 결과를 믿기 어렵게 만드는 설정 문제. 정상이면 빈 배열입니다. |
141
- | `violations[].found` | 위반한 코드 조각 |
142
- | `violations[].candidates` | 대신 쓸 클래스나 컴포넌트. 없으면 빈 배열입니다. |
143
-
144
- | 종료 코드 | 의미 |
280
+ | `designSystem` | How many tokens and components were read from the config |
281
+ | `problems` | Config problems that make the result unreliable. Empty when everything is fine. |
282
+ | `violations[].found` | The offending piece of code |
283
+ | `violations[].candidates` | The classes or components to use instead. Empty when there are none. |
284
+ | `violations[].action` | How to handle the violation. `replace`: replacing `found` with the only candidate keeps the screen and the behavior the same. `ask`: a person has to decide: several candidates, a color with no token, a token whose value differs between themes, or a component whose props are dynamic or spread. `repair`: the file could not be parsed. |
285
+ | `next` | What an agent should do with this result, in order |
286
+
287
+ | Exit code | Meaning |
145
288
  | --- | --- |
146
- | 0 | 오류 없음 (경고만 있어도 0) |
147
- | 1 | 오류 있음 |
148
- | 2 | 실행하지 못함 (설정 파일, 토큰 CSS, 컴포넌트 경로가 없음, 잘못된 인자) |
289
+ | 0 | No errors (warnings alone still exit 0) |
290
+ | 1 | Errors found |
291
+ | 2 | Could not run (missing config file, token CSS or component directory, or bad arguments) |
149
292
 
150
- 검사는 프로젝트의 ESLint 설정과 무관하게 돌아갑니다. `.js`, `.jsx`, `.ts`, `.tsx` 파일을 보고, `node_modules`, `.next`, `dist`, `build`, `out`, `coverage`는 건너뜁니다.
293
+ The check does not depend on the project's ESLint config. It reads `.js`, `.jsx`, `.ts`, `.tsx` and `.css` files and skips `node_modules`, `.next`, `dist`, `build`, `out` and `coverage`.
151
294
 
152
- ### 예외
295
+ ## Exceptions
153
296
 
154
- 의도적으로 허용하는 곳에는 주석을 답니다.
297
+ Mark intentional exceptions with a comment.
155
298
 
156
299
  ```tsx
157
- {/* eslint-disable-next-line designsnitch/color-unknown -- 캠페인 전용 색 */}
158
- <p className="text-[#FF00AA]">캠페인</p>
300
+ {/* eslint-disable-next-line designsnitch/color-unknown -- campaign-only color */}
301
+ <p className="text-[#FF00AA]">Campaign</p>
159
302
  ```
160
303
 
161
- ### 에이전트 스킬
304
+ In a CSS file, put this comment on the line before the declaration.
162
305
 
163
- `skills/designsnitch/SKILL.md`가 스킬입니다. 에이전트의 스킬 디렉터리에 복사해서 씁니다. Claude Code라면 다음과 같습니다.
164
-
165
- ```sh
166
- mkdir -p .claude/skills
167
- cp -r node_modules/designsnitch/skills/designsnitch .claude/skills/
306
+ ```css
307
+ .campaign {
308
+ /* designsnitch-disable-next-line -- campaign-only color */
309
+ color: #FF00AA;
310
+ }
168
311
  ```
169
312
 
170
- 스킬은 에이전트에게 다음을 지시합니다.
313
+ ## Agent skills
171
314
 
172
- 1. 설정 파일이 없으면 저장소에서 토큰 CSS와 공용 컴포넌트 경로를 찾아 `designsnitch.config.json`을 만들고, 검사를 실행해 읽어 낸 개수를 확인한 뒤 사람에게 보여줍니다.
173
- 2. UI 코드를 수정한 뒤 `designsnitch check --format json`을 실행합니다.
174
- 3. 오류이고 후보가 하나뿐인 위반만 고칩니다.
175
- 4. 후보가 여러 개이거나 경고인 것은 고치지 않고, 후보와 맥락을 사람에게 보여줍니다.
176
- 5. 다시 검사합니다.
315
+ `npx designsnitch install` copies the skills into `.claude/skills` for Claude Code, into `.agents/skills` for Codex and Gemini CLI with `--agent codex` or `--agent gemini`, and into `.grok/skills` for Grok Build with `--agent grok`. Run it again after upgrading the package to get the current versions. The skills are in the `skills/` directory of the package if you want to copy them somewhere else.
177
316
 
178
- 설정 파일은 판정 기준이므로, 에이전트는 없을 때 새로 만들 수만 있고 이미 있는 설정은 사람에게 묻지 않고 고치지 않습니다.
317
+ Each skill does one job.
179
318
 
180
- ### ESLint 플러그인으로 쓰기
319
+ | Skill | When the agent uses it | What it does |
320
+ | --- | --- | --- |
321
+ | `designsnitch-check` | After changing UI code | Runs the check, replaces what can be replaced, and asks a person about the rest with the facts needed to decide. |
322
+ | `designsnitch-setup` | When the config file is missing | Finds the token CSS and the shared component directory in the codebase, writes `designsnitch.config.json`, verifies what was read, and then wires the ESLint plugin and the agent hook. |
323
+ | `designsnitch-palette` | When the project has no color tokens | Collects the colors in use with `designsnitch colors`, proposes tokens, and writes them after a person approves. |
324
+ | `designsnitch-hooks` | As part of setup | Registers `designsnitch hook` with the coding agent, so it is told about errors after each edit and cannot finish while fixable errors remain. |
325
+ | `designsnitch-eslint` | As part of setup | Puts the rules into the project's ESLint, and installs ESLint if the project has none. Asks first if the project already has errors. |
326
+
327
+ The skills share a few rules. The agent does not pick one of several candidates on its own, does not silence a rule to make the check pass, and does not change an existing config file or token without asking. The config file and the tokens are the standard the code is judged against.
181
328
 
182
- 같은 규칙을 프로젝트의 ESLint에 넣어 에디터에서 볼 수도 있습니다. 설정은 `settings.designsnitch`에 같은 내용을 적습니다.
329
+ ## ESLint
330
+
331
+ The same rules can run inside your project's ESLint, so violations show up in the editor and in the lint step you already have. The ESLint config reads `designsnitch.config.json`, so the standard is written in one place.
183
332
 
184
333
  ```js
185
334
  // eslint.config.js
186
335
  import designsnitch from "designsnitch";
336
+ import designSystem from "./designsnitch.config.json" with { type: "json" };
187
337
 
188
338
  export default [
189
- designsnitch.configs.recommended,
339
+ // ...your existing config
190
340
  {
191
- settings: {
192
- designsnitch: { tokens: "./app/globals.css" },
341
+ files: ["**/*.{js,jsx,ts,tsx}"],
342
+ plugins: { designsnitch },
343
+ settings: { designsnitch: designSystem },
344
+ rules: {
345
+ // error: the design system has a token or component for this, and it was not used
346
+ "designsnitch/color-use-token": "error",
347
+ "designsnitch/use-ds-component": "error",
348
+ // warn: the value is not in the design system, so a person has to decide
349
+ "designsnitch/color-unknown": "warn",
193
350
  },
194
351
  },
195
352
  ];
196
353
  ```
197
354
 
198
- ### 검사 범위
199
-
200
- - **검사하는 곳:** 코드 안의 문자열과 템플릿 리터럴입니다. `className`뿐 아니라 `cn()`, `clsx()`, `cva()`의 인자도 잡힙니다. 주석은 보지 않습니다.
201
- - **간격:** padding, margin, gap, space 유틸리티만 봅니다. `w-[320px]` 같은 크기 유틸리티는 보지 않습니다.
202
- - **간격 스케일:** 간격 단위의 0.5배수(`p-0.5`, `p-1.5`, `p-4`)와 `p-px`를 스케일로 봅니다.
203
- - **단위:** `px`와 `rem`만 봅니다. `1rem`은 16px로 계산합니다.
204
-
205
- ### 아직 안 되는 것
206
-
207
- - hex가 아닌 색(`rgb()`, `hsl()`, `oklch()`)
208
- - Tailwind 기본 테마의 값. 프로젝트의 토큰 CSS에 적힌 값만 읽습니다.
209
- - 색의 가장 가까운 토큰 제시
210
- - 어느 테마의 값인지 알려주기. 토큰이 테마마다 다른 값을 가지면 그 값들을 모두 토큰의 값으로 보지만, 어느 테마인지는 구분하지 않습니다.
211
- - 인라인 스타일
212
- - 직접 만든 컴포넌트와 디자인 시스템 컴포넌트의 스타일 비교
213
- - 스킬을 설치해 주는 명령
214
-
215
- ### 개발
216
-
217
- ```sh
218
- npm install
219
- npm test
220
- ```
221
-
222
- ## 왜 필요한가
355
+ The same set of rules is available as `designsnitch.configs.recommended`. In a project that already has many violations, the error-level rules will make the existing lint step fail, so run `designsnitch check` first to see how many there are. Replacement candidates appear as ESLint suggestions, which editors show as quick fixes. CSS files are checked by the CLI only, not through ESLint.
223
356
 
224
- AI 에이전트가 만든 UI는 얼핏 보면 그럴듯하지만, 자세히 보면 조금씩 틀려 있는 경우가 많습니다.
357
+ ## Blocking violations
225
358
 
226
- - primary 색을 토큰 대신 `bg-[#3B82F6]`으로 박아 둬서, 다크 모드로 바꾸면 그 부분만 색이 그대로 남습니다.
227
- - 버튼 색이 primary와 거의 같지만 미묘하게 다릅니다.
228
- - 간격이 `p-4`여야 할 곳에 `p-[15px]`나 `p-[18px]`가 들어가 있습니다.
229
- - 디자인 시스템에 Button이 있는데 `<button>`으로 새로 만들어서, 높이가 조금 낮거나 focus 스타일이 없습니다.
230
-
231
- 이런 차이는 리뷰에서 눈으로 잡기 어렵습니다. designsnitch는 코드를 분석해서 이런 곳을 찾아냅니다.
232
-
233
- ## 판단 기준
234
-
235
- | 등급 | 의미 |
236
- | --- | --- |
237
- | **오류** | 디자인 시스템에 쓸 토큰이나 컴포넌트가 있는데 쓰지 않았습니다. 지금 화면이 같아 보여도, 디자인 시스템이 바뀌면 이 코드만 따라가지 않습니다. |
238
- | **경고** | 디자인 시스템에 맞는 토큰이 없습니다. 새 값이 정말 필요한 건지 실수인지 사람이 판단해야 합니다. |
359
+ The CLI and the skills put an AI agent in a position to do the right thing. Blocking is done in two other places.
239
360
 
240
- ## 감지 대상 한눈에 보기
241
-
242
- | 대상 | 오류 | 경고 |
361
+ | Where | When it catches a violation | How |
243
362
  | --- | --- | --- |
244
- | 색 | 토큰이 있는 색을 hex로 씀 | 토큰이 없는 hex |
245
- | 간격, 폰트 크기, radius | 토큰 값과 같은 숫자를 직접 씀 | 스케일에 없는 값 |
246
- | 컴포넌트 | 디자인 시스템 컴포넌트가 있는데 raw 태그나 직접 만든 컴포넌트를 씀 | 없음 |
247
-
248
- ## 검사하는 곳
249
-
250
- Tailwind 프로젝트에서 값을 직접 쓰는 곳은 주로 두 군데입니다.
251
-
252
- - **임의 값 클래스:** `bg-[#3B82F6]`, `p-[15px]`, `rounded-[6px]`, `text-[13px]`처럼 대괄호 안에 값을 직접 쓴 클래스입니다. `className` 문자열과 `cn()`, `clsx()`, `cva()` 같은 함수의 인자를 봅니다.
253
- - **인라인 스타일:** `style={{ color: "#3B82F6", padding: 16 }}`
363
+ | ESLint plugin | In the editor and in the lint step | Errors fail the lint step. Run lint in CI and require it to pass, and nothing with an error can be merged. |
364
+ | Agent hook | While the agent is writing code | `designsnitch hook` runs after each edit and before the agent finishes. |
254
365
 
255
- 이 문서에서는 편의상 hex라고 부르지만, `rgb()`, `hsl()`, `oklch()`로 쓴 색도 같은 색으로 변환해서 비교합니다.
366
+ ### Agent hook
256
367
 
257
- ## 감지 대상
368
+ A skill is advice that an agent may not follow. A hook is run by the agent's runtime every time. `npx designsnitch install` registers it for Claude Code. This is what it adds to `.claude/settings.json`.
258
369
 
259
- ### 1. 색
260
-
261
- #### 토큰이 있는 색을 hex로 씀 (오류)
262
-
263
- 색 값이 토큰 값과 같으면, 그 토큰의 클래스를 쓰라고 알려줍니다.
264
-
265
- ```
266
- src/features/checkout/PayButton.tsx:12:18 오류
267
- bg-[#3B82F6] 의 색은 토큰 --color-primary-500 의 값입니다.
268
- → bg-primary-500 을 사용하세요.
370
+ ```json
371
+ {
372
+ "hooks": {
373
+ "PostToolUse": [
374
+ {
375
+ "matcher": "Edit|Write|MultiEdit",
376
+ "hooks": [{ "type": "command", "command": "npx designsnitch hook" }]
377
+ }
378
+ ],
379
+ "Stop": [
380
+ {
381
+ "hooks": [{ "type": "command", "command": "npx designsnitch hook" }]
382
+ }
383
+ ]
384
+ }
385
+ }
269
386
  ```
270
387
 
271
- 토큰이 테마마다 다른 값을 가지면, 어느 테마의 값과 같든 같은 방식으로 잡습니다.
388
+ `designsnitch hook` checks only the files the agent just changed, and blocks only errors the change added.
272
389
 
273
- ```
274
- src/features/checkout/Card.tsx:8:14 오류
275
- bg-[#FFFFFF] 의 색은 라이트 테마의 --color-surface 값입니다.
276
- 다크 테마에서는 --color-surface 가 #111827 이므로 이 부분만 흰색으로 남습니다.
277
- → bg-surface 를 사용하세요.
278
- ```
390
+ - It compares each file with its version in git `HEAD`. An error counts as new when there are more of it (the same rule and the same code) than in `HEAD`. Errors that were already there do not block, even if lines moved. A file that is not in `HEAD` yet has only new errors.
391
+ - After an edit, if the file has new errors, the agent receives them along with what to do next.
392
+ - When the agent is about to finish, it is stopped if new errors it can fix itself remain. Errors that need a person's decision do not stop it, because it has to stop in order to ask.
393
+ - Warnings never block, and files the agent did not touch are left alone.
394
+ - Outside a git repository, or before the first commit, every error in the changed files counts.
279
395
 
280
- #### 토큰이 없는 hex (경고)
396
+ For Codex, `npx designsnitch install --agent codex` writes the same two hooks to `.codex/hooks.json`, with `apply_patch` as the matcher. Codex often edits files with shell commands, which that matcher does not see. Those edits are caught when Codex is about to finish, because the hook then checks every file git reports as changed.
281
397
 
282
- 팔레트에 없는 색입니다. 팔레트 색과 아주 가까우면 근사값이나 오타일 가능성이 크므로, 가장 가까운 토큰을 함께 제시합니다.
398
+ For Gemini CLI, `npx designsnitch install --agent gemini` writes the hooks to `.gemini/settings.json` under Gemini CLI's own event names: `AfterTool` for `write_file` and `replace`, and `AfterAgent` for when it is about to answer, where exit code 2 makes it try again with the errors as feedback. This follows the official Gemini CLI documentation and has not been tested with Gemini CLI.
283
399
 
284
- ```
285
- src/features/checkout/PayButton.tsx:20:18 경고
286
- bg-[#3B82F5] 의 색은 팔레트에 없습니다.
287
- 가장 가까운 토큰: --color-primary-500 (#3B82F6) → bg-primary-500
288
- ```
400
+ For Grok Build, `npx designsnitch install --agent grok` writes `.grok/hooks/designsnitch.json` with `PostToolUse` and `Stop`, following the official xAI documentation. It has not been tested with Grok Build, and one point is uncertain: the documentation calls `PreToolUse` the only blocking event and does not say what exit code 2 does after a tool or at the end of a turn. Grok Build may therefore report the errors without stopping the agent. Grok Build also reads Claude Code's `.claude/settings.json`, so with `--agent all` the hook can run twice in Grok Build. That is harmless.
289
401
 
290
- ### 2. 간격, 폰트 크기, radius
402
+ The command reads an optional JSON object from stdin (`tool_input.file_path`, `hook_event_name`, `stop_hook_active`, or the same fields in camelCase as Grok Build sends them), exits with 2 and writes to stderr when it blocks, and falls back to the files git reports as changed when no file is given. Other agents with command hooks that follow these conventions can use it too. The `designsnitch-hooks` skill sets this up.
291
403
 
292
- #### 토큰 값과 같은 숫자를 직접 씀 (오류)
404
+ ### Tailwind's default palette
293
405
 
294
- ```
295
- src/features/checkout/Summary.tsx:30:5 오류
296
- p-[16px] 는 간격 스케일에 있는 값입니다.
297
- → p-4 를 사용하세요.
298
- ```
299
-
300
- #### 스케일에 없는 값 (경고)
406
+ designsnitch does not flag default palette classes such as `bg-blue-500`. If the project should only use its own tokens, Tailwind v4 can remove the default palette, and then those classes stop working at all.
301
407
 
302
- ```
303
- src/features/checkout/Summary.tsx:42:5 경고
304
- p-[15px] 는 간격 스케일에 없습니다.
305
- 가장 가까운 값: p-4 (16px)
408
+ ```css
409
+ @theme {
410
+ --color-*: initial;
411
+ --color-primary-500: #3B82F6;
412
+ }
306
413
  ```
307
414
 
308
- ### 3. 컴포넌트
415
+ ## Scope
309
416
 
310
- #### 디자인 시스템 컴포넌트를 쓰지 않음 (오류)
417
+ - **Where it looks in JS and TS:** string literals and template literals. This covers `className` and the arguments of `cn()`, `clsx()` and `cva()`. Comments are ignored.
418
+ - **Where it looks in CSS:** hex colors in declaration values, in `.css` files including CSS Modules. Declarations that define a variable (`--name: ...`) are skipped, since that is where tokens are defined. Only colors are checked in CSS for now.
419
+ - **Themes:** when a token has different values per theme, all of them count as that token's value. Replacing a hex color with such a token changes the color in the other themes, so those errors are marked `ask`.
420
+ - **Fixes:** designsnitch reports candidates and never rewrites code by itself, even when there is only one candidate.
311
421
 
312
- 디자인 시스템 경로 밖에서 다음을 찾습니다.
422
+ ### Not supported yet
313
423
 
314
- - 디자인 시스템 컴포넌트가 대체하는 raw 태그(`button`, `input`, `select`, `dialog` 등)
315
- - 기존 디자인 시스템 컴포넌트와 역할이 같은, 직접 만든 컴포넌트
424
+ - Colors that are not hex (`rgb()`, `hsl()`, `oklch()`)
425
+ - Values from Tailwind's default theme. Only the values written in the project's token CSS are read.
426
+ - Tailwind v3 (`tailwind.config.js`)
427
+ - The nearest token for a color that has none
428
+ - Inline styles
429
+ - SCSS and other preprocessors
430
+ - Spacing, font size and radius. They were left out of this version on purpose.
431
+ - Classes inside `@apply`
432
+ - Comparing a hand-made component's styles with the design system component
433
+ - Installing the hook for agents other than Claude Code, Codex, Gemini CLI and Grok Build
316
434
 
317
- 직접 만든 컴포넌트는 디자인 시스템 컴포넌트와 스타일을 비교해서, 다른 점이 있으면 함께 보여줍니다. 바꿨을 때 화면이 어떻게 달라지는지 미리 알 수 있습니다.
435
+ Comparing a screen with a design file such as Figma is out of scope. The standard is the design system alone.
318
436
 
319
- - 크기, padding, radius, 색이 다른지
320
- - hover, focus, disabled 같은 상태 스타일이 빠졌는지
437
+ ## How it works
321
438
 
322
- ```
323
- src/features/checkout/ConfirmModal.tsx:5:10 오류
324
- raw <dialog> 를 디자인 시스템 밖에서 사용했습니다.
325
- → @/components/ui/Dialog 를 사용하세요.
326
- ```
327
-
328
- ```
329
- src/features/checkout/ConfirmButton.tsx:4:10 오류
330
- 디자인 시스템 Button 과 역할이 같은 컴포넌트입니다.
331
- - height 36px (Button: 40px)
332
- - :focus-visible 스타일 없음
333
- → @/components/ui/Button 을 사용하세요.
334
- ```
335
-
336
- > 이 절의 출력은 목표 동작을 설명하는 예시입니다. 실제 출력은 [실행](#실행)을 보세요.
337
-
338
- ## 설계
339
-
340
- ### 구조
341
-
342
- 스킬과 실행 도구를 나누는 방식은 Chrome 팀의 Modern Web Guidance를 참고했습니다. 판정은 CLI가 하고, 스킬은 에이전트가 언제 CLI를 부르고 결과를 어떻게 다룰지만 정합니다. 사람과 AI가 같은 규칙과 같은 결과를 씁니다.
439
+ The split between a skill and a tool that does the work follows Modern Web Guidance by the Chrome team. The CLI makes the verdicts, and the skills only decide when the agent calls the CLI and what it does with the result. People and AI use the same rules and the same results.
343
440
 
344
- | 층 | 위치 | 하는 일 |
441
+ | Layer | Location | What it does |
345
442
  | --- | --- | --- |
346
- | 코어 | `src/core` | 토큰 CSS를 읽어 "값 → 토큰" 표를 만들고, 문자열에서 임의 값 클래스를 찾고, 스케일과 비교합니다. ESLint에 의존하지 않습니다. |
347
- | 규칙 | `src/rules` | AST에서 문자열과 JSX 태그를 찾아 코어에 묻고, 위반과 대체 후보를 보고합니다. ESLint 규칙 형식입니다. |
348
- | 검사 엔진 | `src/check.js` | 규칙을 프로젝트에 실행하고 결과를 위반 목록으로 정리합니다. 내부에서 ESLint를 AST 실행기로 씁니다. |
349
- | CLI | `src/cli.js` | 인자와 설정 파일을 읽어 엔진을 부르고, 결과를 출력합니다. |
350
- | 스킬 | `skills/designsnitch` | 에이전트용 지시문입니다. |
443
+ | Core | `src/core` | Reads the token CSS into a value-to-token table, and finds color classes and values in strings and CSS. Does not depend on ESLint. |
444
+ | Rules | `src/rules` | Find strings and JSX tags in the AST, ask the core, and report violations with candidates. Written as ESLint rules. |
445
+ | Check engine | `src/check.js` | Runs the rules on a project and turns the results into a list of violations. Uses ESLint internally to parse and walk the code. |
446
+ | CLI | `src/cli.js` | Reads arguments and the config file, calls the engine, and prints the result. |
447
+ | Hook | `src/hook.js` | Checks the files an agent just changed and decides whether to block. |
448
+ | Skills | `skills/` | Instructions for the agent, one skill per job. |
351
449
 
352
- 오류와 경고는 별도 규칙으로 나눕니다. 대체 후보는 ESLint의 제안(suggestion)으로 보고하므로, 에디터에서는 빠른 수정으로 보이고 CLI의 JSON에는 `candidates`로 나옵니다. 후보가 하나여도 자동 수정은 하지 않습니다.
450
+ ## Development
353
451
 
354
- ### 남은 것
355
-
356
- 1. hex가 아닌 색 읽기
357
- 2. Tailwind 기본 테마 값 읽기
358
- 3. 인라인 스타일 검사
359
- 4. 직접 만든 컴포넌트와 디자인 시스템 컴포넌트 비교. 오탐 기준이 잡히기 전에는 오류로 처리하지 않고 경고나 후보로만 보여줍니다.
360
- 5. 스킬 설치 명령
452
+ ```sh
453
+ npm install
454
+ npm test
455
+ ```
361
456
 
362
- ## 범위 밖
457
+ ### Releasing
363
458
 
364
- - **화면별 시안과의 비교:** Figma 같은 시안 파일을 읽어서 "이 화면이 시안대로인가"를 보는 일은 하지 않습니다. 기준은 디자인 시스템 하나입니다.
365
- - **CSS 파일:** `.css`와 CSS Modules 안의 값은 첫 버전에서 검사하지 않습니다.
459
+ Merging into `main` does not publish anything. Pushing a version tag makes GitHub Actions run the tests and publish to npm.
366
460
 
367
- ## 미정 사항
461
+ ```sh
462
+ npm version patch # bumps package.json, commits, and creates a tag such as v0.1.1
463
+ git push --follow-tags # pushing the commit and the tag starts the release
464
+ ```
368
465
 
369
- | 항목 | 내용 |
370
- | --- | --- |
371
- | Tailwind 버전 | CSS의 `@theme`으로 토큰을 정의하는 v4를 먼저 지원한다고 가정했습니다. `tailwind.config.js`를 쓰는 v3도 지원할지 정해야 합니다. |
372
- | Tailwind 기본 팔레트 | 디자인 시스템에 `bg-primary`가 있는데 `bg-blue-500`을 쓴 경우를 잡을지 정해야 합니다. 임의 값은 아니지만 디자인 시스템을 벗어난 색일 수 있습니다. |
373
- | 간격 스케일의 정의 | 지금은 간격 단위의 0.5배수를 모두 스케일로 봅니다. 프로젝트가 쓰는 단계만 허용하도록 좁힐지 정해야 합니다. |
374
- | 근사값 판정 | 토큰이 없는 색이나 값을 볼 때, 얼마나 가까워야 가장 가까운 토큰을 제시할지 정해야 합니다. |
375
- | 역할 판정 | 직접 만든 컴포넌트가 어떤 디자인 시스템 컴포넌트와 역할이 같은지 판단하는 방법을 정해야 합니다. |
466
+ The release stops if the tag and the version in `package.json` differ, or if the tagged commit is not on `main`.
376
467
 
377
- ## 라이선스
468
+ ## License
378
469
 
379
470
  [MIT](./LICENSE)