designsnitch 0.1.0 → 0.2.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,104 @@
1
1
  # designsnitch
2
2
 
3
- AI가 만든 UI 코드에서 디자인이 틀린 곳을 찾아내는 도구입니다. 기준은 프로젝트의 디자인 시스템입니다. 토큰과 컴포넌트 규칙을 벗어난 곳을 찾고, 무엇으로 고치면 되는지 알려줍니다.
3
+ English | [한국어](./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.
8
+
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.
12
12
 
13
- 첫 지원 대상은 **React/Next.js + Tailwind CSS** 프로젝트입니다.
13
+ Deciding what the standard is stays with the developer. The tool's job is to bring what is needed to make that decision.
14
14
 
15
- > **상태:** MVP(0.1.x). [지금 되는 것](#지금-되는-것) 아래의 나머지 내용은 목표 설계이며, 정해지지 않은 부분은 [미정 사항](#미정-사항)에 모아 두었습니다.
15
+ It has four parts.
16
16
 
17
- ## 지금 되는 것
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. |
18
23
 
19
- Tailwind 클래스에 값을 직접 쓴 곳(`bg-[#3B82F6]`, `p-[16px]`)과 raw 태그를 찾아서 디자인 시스템과 비교합니다.
24
+ It supports **React/Next.js projects that use Tailwind CSS v4**.
20
25
 
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 태그를 디자인 시스템 경로 밖에서 씀 |
26
+ > **Status:** MVP (0.2.x). CLI messages are in Korean for now. The JSON output carries the same information in language-neutral fields.
28
27
 
29
- ### 설치
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 copies the agent skills into `.claude/skills` and registers the agent hook in `.claude/settings.json`. It targets Claude Code for now. Node.js 22 or later is required.
36
+
37
+ Then ask your coding agent:
38
+
39
+ > Set up designsnitch in this project.
40
+
41
+ The agent follows the `designsnitch-setup` skill and does the rest.
42
+
43
+ 1. It checks that the project is supported.
44
+ 2. It finds the token CSS and the shared component directory, and writes `designsnitch.config.json`.
45
+ 3. If the project has no color tokens, it collects the colors the code uses and proposes tokens. Nothing is written until you approve.
46
+ 4. It puts the rules into ESLint, installing ESLint if the project has none.
47
+ 5. It shows you what it chose and what the first check found.
48
+
49
+ From then on:
50
+
51
+ - The agent is told about errors right after it edits a file, and cannot finish while errors it can fix remain.
52
+ - Errors fail the lint step, and show up in the editor.
53
+ - `npx designsnitch check` reports where the code stands at any time.
54
+
55
+ To do any of this without an agent, see [Setting up by hand](#setting-up-by-hand).
56
+
57
+ ## Why
58
+
59
+ When there is no standard, every screen makes its own choices. An AI agent makes them quickly and plausibly, and they add up.
60
+
61
+ - The same blue is `#3B82F6` on one screen and `#3B82F5` on another.
62
+ - 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.
63
+ - Each screen builds its own button from `<button>`, each a little different, some without a focus style.
64
+
65
+ 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.
66
+
67
+ ## What it catches
36
68
 
37
- ### 설정
69
+ Severity follows one rule.
38
70
 
39
- 프로젝트 루트에 `designsnitch.config.json`을 만듭니다. [에이전트 스킬](#에이전트-스킬)을 쓰면 에이전트가 저장소를 읽어서 이 파일을 만듭니다.
71
+ | Severity | Meaning |
72
+ | --- | --- |
73
+ | **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. |
74
+ | **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. |
75
+
76
+ | Rule | Severity | What it catches |
77
+ | --- | --- | --- |
78
+ | `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`) |
79
+ | `color-unknown` | Warning | A hex color with no matching token |
80
+ | `use-ds-component` | Error | A raw tag such as `<button>` used outside the design system directory, when a shared component replaces it |
81
+
82
+ Every error comes with what to use instead: a class or component in JS and TS files, and `var(--token)` in CSS files.
83
+
84
+ ## Commands
85
+
86
+ | Command | What it does |
87
+ | --- | --- |
88
+ | `designsnitch install` | Copies the skills and registers the agent hook in the project. |
89
+ | `designsnitch colors` | Lists the colors the code uses. Works without a config file. |
90
+ | `designsnitch check` | Checks code against the standard and says what to do with each violation. |
91
+ | `designsnitch hook` | Called from the agent's hook. Checks the files the agent just changed. |
92
+
93
+ `check` and `colors` take paths, `--format json`, and `--config <file>`.
94
+
95
+ ## Setting up by hand
96
+
97
+ ```sh
98
+ npm install --save-dev designsnitch
99
+ ```
100
+
101
+ Create `designsnitch.config.json` in the project root.
40
102
 
41
103
  ```json
42
104
  {
@@ -52,71 +114,113 @@ Node.js 22 이상이 필요합니다.
52
114
  }
53
115
  ```
54
116
 
55
- | 항목 | 설명 |
117
+ Then run the check.
118
+
119
+ ```sh
120
+ npx designsnitch check # the whole project
121
+ npx designsnitch check src/PayButton.tsx # some files only
122
+ npx designsnitch check --format json # for CI and AI agents
123
+ ```
124
+
125
+ The fields are described in [Configuration](#configuration). To block violations, add the rules to [ESLint](#eslint) and register the [agent hook](#agent-hook).
126
+
127
+ ## Starting without tokens
128
+
129
+ 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.
130
+
131
+ ```sh
132
+ npx designsnitch colors
133
+ npx designsnitch colors --format json
134
+ ```
135
+
136
+ ```
137
+ 코드에서 쓰는 색: hex 5개, 기본 팔레트 1개 (사용 10곳, 파일 1개 검사)
138
+
139
+ hex 색
140
+ #3a11d8 3곳 파일 1개 bg 2, 문자열 1
141
+ #484646 2곳 파일 1개 text 2
142
+ #ffffff 2곳 파일 1개 bg 1, text 1
143
+ #484645 1곳 파일 1개 text 1
144
+ #e2e1e5 1곳 파일 1개 border 1
145
+
146
+ Tailwind 기본 팔레트
147
+ gray-700 1곳 파일 1개 text 1
148
+ ```
149
+
150
+ | Part of the output | Meaning |
56
151
  | --- | --- |
57
- | `tokens` | 토큰이 정의된 CSS 파일입니다. 필수입니다. |
58
- | `components.path` | 디자인 시스템 컴포넌트가 있는 경로입니다. 이 안에서는 raw 태그를 써도 됩니다. |
59
- | `components.replaces` | raw 태그와 그것을 대체하는 컴포넌트입니다. 컴포넌트가 여러 개면 배열로 적습니다. |
152
+ | `hex 색` (hex colors) | Hex colors, most used first, with the number of uses (`곳`) and files (`파일`). |
153
+ | `bg 2`, `text 1` | Uses per Tailwind utility. `bg-[#3a11d8]` counts under `bg`. |
154
+ | `문자열 1` (strings) | Strings that are a hex color on their own, such as inline styles and chart options. |
155
+ | `CSS 2` | Uses in CSS declarations. The JSON output breaks these down by property. |
156
+ | `Tailwind 기본 팔레트` (default palette) | Colors from Tailwind's default palette used by name, such as `text-gray-700`. |
157
+
158
+ When a config file exists, each color also shows the tokens that already have that value (`토큰: --color-brand`), or `토큰 없음` when there is none. The JSON output has the same data plus a few example locations per color.
60
159
 
61
- `components`를 생략하면 컴포넌트 검사를 하지 않습니다.
160
+ The [`designsnitch-palette` skill](#agent-skills) uses this output to propose tokens, and writes them after you approve.
62
161
 
63
- 토큰 CSS에서 읽는 변수는 다음과 같습니다.
162
+ ## Configuration
163
+
164
+ | Field | Description |
165
+ | --- | --- |
166
+ | `tokens` | The CSS file that defines the tokens. Required. |
167
+ | `components.path` | The directory that holds the design system components. Raw tags are allowed inside it. |
168
+ | `components.replaces` | Raw tags and the components that replace them. Use an array when several components replace one tag. |
64
169
 
65
- | 변수 | 쓰임 | 없을 때 |
170
+ Without `components`, the component check is skipped. Use `--config <file>` to read a config file from another path.
171
+
172
+ This is what is read from the token CSS.
173
+
174
+ | Variable | Used for | When missing |
66
175
  | --- | --- | --- |
67
- | `--color-*` | 색. 값이 hex이거나, `var()`로 hex 값을 가진 변수를 가리켜야 합니다. | 모든 hex가 경고가 됩니다 |
68
- | `--spacing` | 간격 단위 | Tailwind 기본값 `0.25rem`을 씁니다 |
69
- | `--radius-*` | radius | radius를 검사하지 않습니다 |
70
- | `--text-*` | 폰트 크기 | 폰트 크기를 검사하지 않습니다 |
176
+ | `--color-*` | Colors. The value must be a hex color, or a `var()` that leads to one. | Every hex color becomes a warning |
177
+
178
+ Both of these shapes work.
71
179
 
72
180
  ```css
181
+ /* Values directly in @theme */
73
182
  @theme {
74
183
  --color-primary-500: #3B82F6;
75
184
  --color-surface: #ffffff;
76
- --radius-sm: 0.25rem;
77
- --radius-md: 0.375rem;
78
- --text-sm: 0.875rem;
79
- --text-base: 1rem;
80
185
  }
81
- ```
82
186
 
83
- ### 실행
84
-
85
- ```sh
86
- npx designsnitch check # 프로젝트 전체
87
- npx designsnitch check src/PayButton.tsx # 일부만
88
- npx designsnitch check --format json # CI나 AI 에이전트용
187
+ /* Values in :root, referenced from @theme */
188
+ :root {
189
+ --primary-500: #3B82F6;
190
+ }
191
+ @theme {
192
+ --color-primary-500: var(--primary-500);
193
+ }
89
194
  ```
90
195
 
196
+ ## Output
197
+
91
198
  ```
92
- 디자인 시스템: 색 토큰 2개, radius 토큰 2개, 폰트 크기 토큰 2개, 컴포넌트 2개
199
+ 디자인 시스템: 색 토큰 2개, 컴포넌트 2개
93
200
 
94
201
  src/PayButton.tsx
95
202
  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
203
  7:55 오류 bg-[#3B82F6]의 색은 토큰 --color-primary-500의 값입니다. 대신 사용: bg-primary-500 (color-use-token)
100
204
  8:26 경고 bg-[#3B82F5]의 색은 토큰에 없습니다. (color-unknown)
101
205
 
102
- 오류 4개, 경고 2개 (파일 3개 검사)
206
+ 오류 2개, 경고 1개 (파일 3개 검사)
207
+ 바로 바꿀 수 있는 것 2건, 사람이 정해야 하는 것 1건
103
208
  ```
104
209
 
105
- 첫 줄은 설정에서 읽어 낸 토큰과 컴포넌트의 개수입니다. 경로를 잘못 적으면 여기서 0개로 드러납니다. 색 토큰을 하나도 읽지 못하면 `주의:`로 시작하는 줄이 함께 나옵니다.
210
+ 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 `주의:` (notice) explains why. `오류` means error and `경고` means warning. The last line says how many violations can be replaced right away (`바로 바꿀 수 있는 것`) and how many need a person's decision (`사람이 정해야 하는 것`).
106
211
 
107
- `--format json`은 같은 결과를 구조화해서 냅니다.
212
+ `--format json` prints the same result as structured data.
108
213
 
109
214
  ```json
110
215
  {
111
- "designSystem": {
112
- "colorTokens": 2,
113
- "radiusTokens": 2,
114
- "textTokens": 2,
115
- "components": 2,
116
- "replacedTags": 2
117
- },
216
+ "designSystem": { "colorTokens": 2, "components": 2, "replacedTags": 2 },
118
217
  "problems": [],
119
- "summary": { "files": 3, "errors": 4, "warnings": 2 },
218
+ "next": [
219
+ "action이 replace인 2건은 found를 candidates의 값으로 바꾸세요.",
220
+ "action이 ask인 1건은 바꾸지 말고 사용자에게 물으세요. ...",
221
+ "고친 뒤 같은 명령을 다시 실행하세요."
222
+ ],
223
+ "summary": { "files": 3, "errors": 2, "warnings": 1 },
120
224
  "violations": [
121
225
  {
122
226
  "file": "src/PayButton.tsx",
@@ -128,252 +232,195 @@ src/PayButton.tsx
128
232
  "severity": "error",
129
233
  "message": "bg-[#3B82F6]의 색은 토큰 --color-primary-500의 값입니다. 대신 사용: bg-primary-500",
130
234
  "found": "bg-[#3B82F6]",
131
- "candidates": ["bg-primary-500"]
235
+ "candidates": ["bg-primary-500"],
236
+ "action": "replace"
132
237
  }
133
238
  ]
134
239
  }
135
240
  ```
136
241
 
137
- | 필드 | 내용 |
242
+ | Field | Content |
138
243
  | --- | --- |
139
- | `designSystem` | 설정에서 읽어 낸 토큰과 컴포넌트의 개수 |
140
- | `problems` | 결과를 믿기 어렵게 만드는 설정 문제. 정상이면 빈 배열입니다. |
141
- | `violations[].found` | 위반한 코드 조각 |
142
- | `violations[].candidates` | 대신 쓸 클래스나 컴포넌트. 없으면 빈 배열입니다. |
143
-
144
- | 종료 코드 | 의미 |
244
+ | `designSystem` | How many tokens and components were read from the config |
245
+ | `problems` | Config problems that make the result unreliable. Empty when everything is fine. |
246
+ | `violations[].found` | The offending piece of code |
247
+ | `violations[].candidates` | The classes or components to use instead. Empty when there are none. |
248
+ | `violations[].action` | How to handle the violation. `replace`: an error with exactly one candidate, so replace `found` with it. `ask`: a person has to decide (several candidates, or a color with no token). `repair`: the file could not be parsed. |
249
+ | `next` | What an agent should do with this result, in order |
250
+
251
+ | Exit code | Meaning |
145
252
  | --- | --- |
146
- | 0 | 오류 없음 (경고만 있어도 0) |
147
- | 1 | 오류 있음 |
148
- | 2 | 실행하지 못함 (설정 파일, 토큰 CSS, 컴포넌트 경로가 없음, 잘못된 인자) |
253
+ | 0 | No errors (warnings alone still exit 0) |
254
+ | 1 | Errors found |
255
+ | 2 | Could not run (missing config file, token CSS or component directory, or bad arguments) |
149
256
 
150
- 검사는 프로젝트의 ESLint 설정과 무관하게 돌아갑니다. `.js`, `.jsx`, `.ts`, `.tsx` 파일을 보고, `node_modules`, `.next`, `dist`, `build`, `out`, `coverage`는 건너뜁니다.
257
+ 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
258
 
152
- ### 예외
259
+ ## Exceptions
153
260
 
154
- 의도적으로 허용하는 곳에는 주석을 답니다.
261
+ Mark intentional exceptions with a comment.
155
262
 
156
263
  ```tsx
157
- {/* eslint-disable-next-line designsnitch/color-unknown -- 캠페인 전용 색 */}
158
- <p className="text-[#FF00AA]">캠페인</p>
264
+ {/* eslint-disable-next-line designsnitch/color-unknown -- campaign-only color */}
265
+ <p className="text-[#FF00AA]">Campaign</p>
159
266
  ```
160
267
 
161
- ### 에이전트 스킬
268
+ In a CSS file, put this comment on the line before the declaration.
162
269
 
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/
270
+ ```css
271
+ .campaign {
272
+ /* designsnitch-disable-next-line -- campaign-only color */
273
+ color: #FF00AA;
274
+ }
168
275
  ```
169
276
 
170
- 스킬은 에이전트에게 다음을 지시합니다.
277
+ ## Agent skills
278
+
279
+ `npx designsnitch install` copies the skills into `.claude/skills`. 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.
171
280
 
172
- 1. 설정 파일이 없으면 저장소에서 토큰 CSS와 공용 컴포넌트 경로를 찾아 `designsnitch.config.json`을 만들고, 검사를 실행해 읽어 낸 개수를 확인한 뒤 사람에게 보여줍니다.
173
- 2. UI 코드를 수정한 뒤 `designsnitch check --format json`을 실행합니다.
174
- 3. 오류이고 후보가 하나뿐인 위반만 고칩니다.
175
- 4. 후보가 여러 개이거나 경고인 것은 고치지 않고, 후보와 맥락을 사람에게 보여줍니다.
176
- 5. 다시 검사합니다.
281
+ Each skill does one job.
282
+
283
+ | Skill | When the agent uses it | What it does |
284
+ | --- | --- | --- |
285
+ | `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. |
286
+ | `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. |
287
+ | `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. |
288
+ | `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. |
289
+ | `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. |
177
290
 
178
- 설정 파일은 판정 기준이므로, 에이전트는 없을 때 새로 만들 수만 있고 이미 있는 설정은 사람에게 묻지 않고 고치지 않습니다.
291
+ 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.
179
292
 
180
- ### ESLint 플러그인으로 쓰기
293
+ ## ESLint
181
294
 
182
- 같은 규칙을 프로젝트의 ESLint에 넣어 에디터에서 볼 수도 있습니다. 설정은 `settings.designsnitch`에 같은 내용을 적습니다.
295
+ 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
296
 
184
297
  ```js
185
298
  // eslint.config.js
186
299
  import designsnitch from "designsnitch";
300
+ import designSystem from "./designsnitch.config.json" with { type: "json" };
187
301
 
188
302
  export default [
189
- designsnitch.configs.recommended,
303
+ // ...your existing config
190
304
  {
191
- settings: {
192
- designsnitch: { tokens: "./app/globals.css" },
305
+ files: ["**/*.{js,jsx,ts,tsx}"],
306
+ plugins: { designsnitch },
307
+ settings: { designsnitch: designSystem },
308
+ rules: {
309
+ // error: the design system has a token or component for this, and it was not used
310
+ "designsnitch/color-use-token": "error",
311
+ "designsnitch/use-ds-component": "error",
312
+ // warn: the value is not in the design system, so a person has to decide
313
+ "designsnitch/color-unknown": "warn",
193
314
  },
194
315
  },
195
316
  ];
196
317
  ```
197
318
 
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
- ## 왜 필요한가
223
-
224
- AI 에이전트가 만든 UI는 얼핏 보면 그럴듯하지만, 자세히 보면 조금씩 틀려 있는 경우가 많습니다.
225
-
226
- - primary 색을 토큰 대신 `bg-[#3B82F6]`으로 박아 둬서, 다크 모드로 바꾸면 그 부분만 색이 그대로 남습니다.
227
- - 버튼 색이 primary와 거의 같지만 미묘하게 다릅니다.
228
- - 간격이 `p-4`여야 할 곳에 `p-[15px]`나 `p-[18px]`가 들어가 있습니다.
229
- - 디자인 시스템에 Button이 있는데 `<button>`으로 새로 만들어서, 높이가 조금 낮거나 focus 스타일이 없습니다.
319
+ 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.
230
320
 
231
- 이런 차이는 리뷰에서 눈으로 잡기 어렵습니다. designsnitch는 코드를 분석해서 이런 곳을 찾아냅니다.
321
+ ## Blocking violations
232
322
 
233
- ## 판단 기준
323
+ The CLI and the skills put an AI agent in a position to do the right thing. Blocking is done in two other places.
234
324
 
235
- | 등급 | 의미 |
236
- | --- | --- |
237
- | **오류** | 디자인 시스템에 쓸 토큰이나 컴포넌트가 있는데 쓰지 않았습니다. 지금 화면이 같아 보여도, 디자인 시스템이 바뀌면 이 코드만 따라가지 않습니다. |
238
- | **경고** | 디자인 시스템에 맞는 토큰이 없습니다. 새 값이 정말 필요한 건지 실수인지 사람이 판단해야 합니다. |
239
-
240
- ## 감지 대상 한눈에 보기
241
-
242
- | 대상 | 오류 | 경고 |
325
+ | Where | When it catches a violation | How |
243
326
  | --- | --- | --- |
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 }}`
254
-
255
- 이 문서에서는 편의상 hex라고 부르지만, `rgb()`, `hsl()`, `oklch()`로 쓴 색도 같은 색으로 변환해서 비교합니다.
256
-
257
- ## 감지 대상
327
+ | 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. |
328
+ | Agent hook | While the agent is writing code | `designsnitch hook` runs after each edit and before the agent finishes. |
258
329
 
259
- ### 1. 색
330
+ ### Agent hook
260
331
 
261
- #### 토큰이 있는 색을 hex로 씀 (오류)
332
+ 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`.
262
333
 
263
- 색 값이 토큰 값과 같으면, 그 토큰의 클래스를 쓰라고 알려줍니다.
264
-
265
- ```
266
- src/features/checkout/PayButton.tsx:12:18 오류
267
- bg-[#3B82F6] 의 색은 토큰 --color-primary-500 의 값입니다.
268
- → bg-primary-500 을 사용하세요.
269
- ```
270
-
271
- 토큰이 테마마다 다른 값을 가지면, 어느 테마의 값과 같든 같은 방식으로 잡습니다.
272
-
273
- ```
274
- src/features/checkout/Card.tsx:8:14 오류
275
- bg-[#FFFFFF] 의 색은 라이트 테마의 --color-surface 값입니다.
276
- 다크 테마에서는 --color-surface 가 #111827 이므로 이 부분만 흰색으로 남습니다.
277
- → bg-surface 를 사용하세요.
334
+ ```json
335
+ {
336
+ "hooks": {
337
+ "PostToolUse": [
338
+ {
339
+ "matcher": "Edit|Write|MultiEdit",
340
+ "hooks": [{ "type": "command", "command": "npx designsnitch hook" }]
341
+ }
342
+ ],
343
+ "Stop": [
344
+ {
345
+ "hooks": [{ "type": "command", "command": "npx designsnitch hook" }]
346
+ }
347
+ ]
348
+ }
349
+ }
278
350
  ```
279
351
 
280
- #### 토큰이 없는 hex (경고)
281
-
282
- 팔레트에 없는 색입니다. 팔레트 색과 아주 가까우면 근사값이나 오타일 가능성이 크므로, 가장 가까운 토큰을 함께 제시합니다.
352
+ `designsnitch hook` checks only the files the agent just changed.
283
353
 
284
- ```
285
- src/features/checkout/PayButton.tsx:20:18 경고
286
- bg-[#3B82F5] 의 색은 팔레트에 없습니다.
287
- 가장 가까운 토큰: --color-primary-500 (#3B82F6) → bg-primary-500
288
- ```
354
+ - After an edit, if the file has errors, the agent receives them along with what to do next.
355
+ - When the agent is about to finish, it is stopped if 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.
356
+ - Warnings never block, and violations in files the agent did not touch are left alone.
289
357
 
290
- ### 2. 간격, 폰트 크기, radius
358
+ The command reads an optional JSON object from stdin (`tool_input.file_path`, `hook_event_name`, `stop_hook_active`), 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
359
 
292
- #### 토큰 값과 같은 숫자를 직접 씀 (오류)
293
-
294
- ```
295
- src/features/checkout/Summary.tsx:30:5 오류
296
- p-[16px] 는 간격 스케일에 있는 값입니다.
297
- → p-4 를 사용하세요.
298
- ```
360
+ ### Tailwind's default palette
299
361
 
300
- #### 스케일에 없는 값 (경고)
362
+ 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
363
 
302
- ```
303
- src/features/checkout/Summary.tsx:42:5 경고
304
- p-[15px] 는 간격 스케일에 없습니다.
305
- 가장 가까운 값: p-4 (16px)
364
+ ```css
365
+ @theme {
366
+ --color-*: initial;
367
+ --color-primary-500: #3B82F6;
368
+ }
306
369
  ```
307
370
 
308
- ### 3. 컴포넌트
371
+ ## Scope
309
372
 
310
- #### 디자인 시스템 컴포넌트를 쓰지 않음 (오류)
373
+ - **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.
374
+ - **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.
375
+ - **Themes:** when a token has different values per theme, all of them count as that token's value.
376
+ - **Fixes:** designsnitch reports candidates and never rewrites code by itself, even when there is only one candidate.
311
377
 
312
- 디자인 시스템 경로 밖에서 다음을 찾습니다.
378
+ ### Not supported yet
313
379
 
314
- - 디자인 시스템 컴포넌트가 대체하는 raw 태그(`button`, `input`, `select`, `dialog` 등)
315
- - 기존 디자인 시스템 컴포넌트와 역할이 같은, 직접 만든 컴포넌트
380
+ - Colors that are not hex (`rgb()`, `hsl()`, `oklch()`)
381
+ - Values from Tailwind's default theme. Only the values written in the project's token CSS are read.
382
+ - Tailwind v3 (`tailwind.config.js`)
383
+ - The nearest token for a color that has none
384
+ - Inline styles
385
+ - SCSS and other preprocessors
386
+ - Spacing, font size and radius. They were left out of this version on purpose.
387
+ - Classes inside `@apply`
388
+ - Comparing a hand-made component's styles with the design system component
389
+ - Installing the skills and the hook for agents other than Claude Code
316
390
 
317
- 직접 만든 컴포넌트는 디자인 시스템 컴포넌트와 스타일을 비교해서, 다른 점이 있으면 함께 보여줍니다. 바꿨을 때 화면이 어떻게 달라지는지 미리 알 수 있습니다.
391
+ Comparing a screen with a design file such as Figma is out of scope. The standard is the design system alone.
318
392
 
319
- - 크기, padding, radius, 색이 다른지
320
- - hover, focus, disabled 같은 상태 스타일이 빠졌는지
393
+ ## How it works
321
394
 
322
- ```
323
- src/features/checkout/ConfirmModal.tsx:5:10 오류
324
- raw <dialog> 를 디자인 시스템 밖에서 사용했습니다.
325
- → @/components/ui/Dialog 를 사용하세요.
326
- ```
395
+ 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.
327
396
 
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가 같은 규칙과 같은 결과를 씁니다.
343
-
344
- | 층 | 위치 | 하는 일 |
397
+ | Layer | Location | What it does |
345
398
  | --- | --- | --- |
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` | 에이전트용 지시문입니다. |
351
-
352
- 오류와 경고는 별도 규칙으로 나눕니다. 대체 후보는 ESLint의 제안(suggestion)으로 보고하므로, 에디터에서는 빠른 수정으로 보이고 CLI의 JSON에는 `candidates`로 나옵니다. 후보가 하나여도 자동 수정은 하지 않습니다.
399
+ | 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. |
400
+ | Rules | `src/rules` | Find strings and JSX tags in the AST, ask the core, and report violations with candidates. Written as ESLint rules. |
401
+ | 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. |
402
+ | CLI | `src/cli.js` | Reads arguments and the config file, calls the engine, and prints the result. |
403
+ | Hook | `src/hook.js` | Checks the files an agent just changed and decides whether to block. |
404
+ | Skills | `skills/` | Instructions for the agent, one skill per job. |
353
405
 
354
- ### 남은 것
406
+ ## Development
355
407
 
356
- 1. hex가 아닌 색 읽기
357
- 2. Tailwind 기본 테마 값 읽기
358
- 3. 인라인 스타일 검사
359
- 4. 직접 만든 컴포넌트와 디자인 시스템 컴포넌트 비교. 오탐 기준이 잡히기 전에는 오류로 처리하지 않고 경고나 후보로만 보여줍니다.
360
- 5. 스킬 설치 명령
408
+ ```sh
409
+ npm install
410
+ npm test
411
+ ```
361
412
 
362
- ## 범위 밖
413
+ ### Releasing
363
414
 
364
- - **화면별 시안과의 비교:** Figma 같은 시안 파일을 읽어서 "이 화면이 시안대로인가"를 보는 일은 하지 않습니다. 기준은 디자인 시스템 하나입니다.
365
- - **CSS 파일:** `.css`와 CSS Modules 안의 값은 첫 버전에서 검사하지 않습니다.
415
+ Merging into `main` does not publish anything. Pushing a version tag makes GitHub Actions run the tests and publish to npm.
366
416
 
367
- ## 미정 사항
417
+ ```sh
418
+ npm version patch # bumps package.json, commits, and creates a tag such as v0.1.1
419
+ git push --follow-tags # pushing the commit and the tag starts the release
420
+ ```
368
421
 
369
- | 항목 | 내용 |
370
- | --- | --- |
371
- | Tailwind 버전 | CSS의 `@theme`으로 토큰을 정의하는 v4를 먼저 지원한다고 가정했습니다. `tailwind.config.js`를 쓰는 v3도 지원할지 정해야 합니다. |
372
- | Tailwind 기본 팔레트 | 디자인 시스템에 `bg-primary`가 있는데 `bg-blue-500`을 쓴 경우를 잡을지 정해야 합니다. 임의 값은 아니지만 디자인 시스템을 벗어난 색일 수 있습니다. |
373
- | 간격 스케일의 정의 | 지금은 간격 단위의 0.5배수를 모두 스케일로 봅니다. 프로젝트가 쓰는 단계만 허용하도록 좁힐지 정해야 합니다. |
374
- | 근사값 판정 | 토큰이 없는 색이나 값을 볼 때, 얼마나 가까워야 가장 가까운 토큰을 제시할지 정해야 합니다. |
375
- | 역할 판정 | 직접 만든 컴포넌트가 어떤 디자인 시스템 컴포넌트와 역할이 같은지 판단하는 방법을 정해야 합니다. |
422
+ The release stops if the tag and the version in `package.json` differ, or if the tagged commit is not on `main`.
376
423
 
377
- ## 라이선스
424
+ ## License
378
425
 
379
426
  [MIT](./LICENSE)