designsnitch 0.0.0-stage → 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/LICENSE +21 -0
- package/README.ko.md +426 -0
- package/README.md +425 -2
- package/bin/designsnitch.js +40 -0
- package/package.json +48 -4
- package/skills/designsnitch-check/SKILL.md +107 -0
- package/skills/designsnitch-eslint/SKILL.md +128 -0
- package/skills/designsnitch-hooks/SKILL.md +90 -0
- package/skills/designsnitch-palette/SKILL.md +140 -0
- package/skills/designsnitch-setup/SKILL.md +107 -0
- package/src/check.js +241 -0
- package/src/cli.js +112 -0
- package/src/colors.js +166 -0
- package/src/config.js +66 -0
- package/src/core/classes.js +46 -0
- package/src/core/color.js +13 -0
- package/src/core/css.js +54 -0
- package/src/core/tokens.js +50 -0
- package/src/engine.js +37 -0
- package/src/files.js +46 -0
- package/src/format.js +85 -0
- package/src/hook.js +100 -0
- package/src/index.js +29 -0
- package/src/install.js +95 -0
- package/src/rules/color-unknown.js +24 -0
- package/src/rules/color-use-token.js +38 -0
- package/src/rules/load-tokens.js +49 -0
- package/src/rules/suggest.js +16 -0
- package/src/rules/use-ds-component.js +41 -0
- package/src/rules/visit-strings.js +29 -0
package/README.md
CHANGED
|
@@ -1,3 +1,426 @@
|
|
|
1
|
-
#
|
|
1
|
+
# designsnitch
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
English | [한국어](./README.ko.md)
|
|
4
|
+
|
|
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
|
+
|
|
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
|
+
|
|
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
|
+
|
|
15
|
+
It has four parts.
|
|
16
|
+
|
|
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. |
|
|
23
|
+
|
|
24
|
+
It supports **React/Next.js projects that use Tailwind CSS v4**.
|
|
25
|
+
|
|
26
|
+
> **Status:** MVP (0.2.x). CLI messages are in Korean for now. The JSON output carries the same information in language-neutral fields.
|
|
27
|
+
|
|
28
|
+
## Getting started
|
|
29
|
+
|
|
30
|
+
```sh
|
|
31
|
+
npm install --save-dev designsnitch
|
|
32
|
+
npx designsnitch install
|
|
33
|
+
```
|
|
34
|
+
|
|
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
|
|
68
|
+
|
|
69
|
+
Severity follows one rule.
|
|
70
|
+
|
|
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.
|
|
102
|
+
|
|
103
|
+
```json
|
|
104
|
+
{
|
|
105
|
+
"tokens": "./app/globals.css",
|
|
106
|
+
"components": {
|
|
107
|
+
"path": "./components/ui",
|
|
108
|
+
"replaces": {
|
|
109
|
+
"button": ["SolidButton", "IconButton"],
|
|
110
|
+
"input": "Input",
|
|
111
|
+
"dialog": "Dialog"
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
```
|
|
116
|
+
|
|
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 |
|
|
151
|
+
| --- | --- |
|
|
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.
|
|
159
|
+
|
|
160
|
+
The [`designsnitch-palette` skill](#agent-skills) uses this output to propose tokens, and writes them after you approve.
|
|
161
|
+
|
|
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. |
|
|
169
|
+
|
|
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 |
|
|
175
|
+
| --- | --- | --- |
|
|
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.
|
|
179
|
+
|
|
180
|
+
```css
|
|
181
|
+
/* Values directly in @theme */
|
|
182
|
+
@theme {
|
|
183
|
+
--color-primary-500: #3B82F6;
|
|
184
|
+
--color-surface: #ffffff;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/* Values in :root, referenced from @theme */
|
|
188
|
+
:root {
|
|
189
|
+
--primary-500: #3B82F6;
|
|
190
|
+
}
|
|
191
|
+
@theme {
|
|
192
|
+
--color-primary-500: var(--primary-500);
|
|
193
|
+
}
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
## Output
|
|
197
|
+
|
|
198
|
+
```
|
|
199
|
+
디자인 시스템: 색 토큰 2개, 컴포넌트 2개
|
|
200
|
+
|
|
201
|
+
src/PayButton.tsx
|
|
202
|
+
5:6 오류 <button> 대신 디자인 시스템 컴포넌트를 사용하세요: Button (./components/ui) (use-ds-component)
|
|
203
|
+
7:55 오류 bg-[#3B82F6]의 색은 토큰 --color-primary-500의 값입니다. 대신 사용: bg-primary-500 (color-use-token)
|
|
204
|
+
8:26 경고 bg-[#3B82F5]의 색은 토큰에 없습니다. (color-unknown)
|
|
205
|
+
|
|
206
|
+
오류 2개, 경고 1개 (파일 3개 검사)
|
|
207
|
+
바로 바꿀 수 있는 것 2건, 사람이 정해야 하는 것 1건
|
|
208
|
+
```
|
|
209
|
+
|
|
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 (`사람이 정해야 하는 것`).
|
|
211
|
+
|
|
212
|
+
`--format json` prints the same result as structured data.
|
|
213
|
+
|
|
214
|
+
```json
|
|
215
|
+
{
|
|
216
|
+
"designSystem": { "colorTokens": 2, "components": 2, "replacedTags": 2 },
|
|
217
|
+
"problems": [],
|
|
218
|
+
"next": [
|
|
219
|
+
"action이 replace인 2건은 found를 candidates의 값으로 바꾸세요.",
|
|
220
|
+
"action이 ask인 1건은 바꾸지 말고 사용자에게 물으세요. ...",
|
|
221
|
+
"고친 뒤 같은 명령을 다시 실행하세요."
|
|
222
|
+
],
|
|
223
|
+
"summary": { "files": 3, "errors": 2, "warnings": 1 },
|
|
224
|
+
"violations": [
|
|
225
|
+
{
|
|
226
|
+
"file": "src/PayButton.tsx",
|
|
227
|
+
"line": 7,
|
|
228
|
+
"column": 55,
|
|
229
|
+
"endLine": 7,
|
|
230
|
+
"endColumn": 67,
|
|
231
|
+
"rule": "color-use-token",
|
|
232
|
+
"severity": "error",
|
|
233
|
+
"message": "bg-[#3B82F6]의 색은 토큰 --color-primary-500의 값입니다. 대신 사용: bg-primary-500",
|
|
234
|
+
"found": "bg-[#3B82F6]",
|
|
235
|
+
"candidates": ["bg-primary-500"],
|
|
236
|
+
"action": "replace"
|
|
237
|
+
}
|
|
238
|
+
]
|
|
239
|
+
}
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
| Field | Content |
|
|
243
|
+
| --- | --- |
|
|
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 |
|
|
252
|
+
| --- | --- |
|
|
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) |
|
|
256
|
+
|
|
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`.
|
|
258
|
+
|
|
259
|
+
## Exceptions
|
|
260
|
+
|
|
261
|
+
Mark intentional exceptions with a comment.
|
|
262
|
+
|
|
263
|
+
```tsx
|
|
264
|
+
{/* eslint-disable-next-line designsnitch/color-unknown -- campaign-only color */}
|
|
265
|
+
<p className="text-[#FF00AA]">Campaign</p>
|
|
266
|
+
```
|
|
267
|
+
|
|
268
|
+
In a CSS file, put this comment on the line before the declaration.
|
|
269
|
+
|
|
270
|
+
```css
|
|
271
|
+
.campaign {
|
|
272
|
+
/* designsnitch-disable-next-line -- campaign-only color */
|
|
273
|
+
color: #FF00AA;
|
|
274
|
+
}
|
|
275
|
+
```
|
|
276
|
+
|
|
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.
|
|
280
|
+
|
|
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. |
|
|
290
|
+
|
|
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.
|
|
292
|
+
|
|
293
|
+
## ESLint
|
|
294
|
+
|
|
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.
|
|
296
|
+
|
|
297
|
+
```js
|
|
298
|
+
// eslint.config.js
|
|
299
|
+
import designsnitch from "designsnitch";
|
|
300
|
+
import designSystem from "./designsnitch.config.json" with { type: "json" };
|
|
301
|
+
|
|
302
|
+
export default [
|
|
303
|
+
// ...your existing config
|
|
304
|
+
{
|
|
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",
|
|
314
|
+
},
|
|
315
|
+
},
|
|
316
|
+
];
|
|
317
|
+
```
|
|
318
|
+
|
|
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.
|
|
320
|
+
|
|
321
|
+
## Blocking violations
|
|
322
|
+
|
|
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.
|
|
324
|
+
|
|
325
|
+
| Where | When it catches a violation | How |
|
|
326
|
+
| --- | --- | --- |
|
|
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. |
|
|
329
|
+
|
|
330
|
+
### Agent hook
|
|
331
|
+
|
|
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`.
|
|
333
|
+
|
|
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
|
+
}
|
|
350
|
+
```
|
|
351
|
+
|
|
352
|
+
`designsnitch hook` checks only the files the agent just changed.
|
|
353
|
+
|
|
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.
|
|
357
|
+
|
|
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.
|
|
359
|
+
|
|
360
|
+
### Tailwind's default palette
|
|
361
|
+
|
|
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.
|
|
363
|
+
|
|
364
|
+
```css
|
|
365
|
+
@theme {
|
|
366
|
+
--color-*: initial;
|
|
367
|
+
--color-primary-500: #3B82F6;
|
|
368
|
+
}
|
|
369
|
+
```
|
|
370
|
+
|
|
371
|
+
## Scope
|
|
372
|
+
|
|
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.
|
|
377
|
+
|
|
378
|
+
### Not supported yet
|
|
379
|
+
|
|
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
|
|
390
|
+
|
|
391
|
+
Comparing a screen with a design file such as Figma is out of scope. The standard is the design system alone.
|
|
392
|
+
|
|
393
|
+
## How it works
|
|
394
|
+
|
|
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.
|
|
396
|
+
|
|
397
|
+
| Layer | Location | What it does |
|
|
398
|
+
| --- | --- | --- |
|
|
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. |
|
|
405
|
+
|
|
406
|
+
## Development
|
|
407
|
+
|
|
408
|
+
```sh
|
|
409
|
+
npm install
|
|
410
|
+
npm test
|
|
411
|
+
```
|
|
412
|
+
|
|
413
|
+
### Releasing
|
|
414
|
+
|
|
415
|
+
Merging into `main` does not publish anything. Pushing a version tag makes GitHub Actions run the tests and publish to npm.
|
|
416
|
+
|
|
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
|
+
```
|
|
421
|
+
|
|
422
|
+
The release stops if the tag and the version in `package.json` differ, or if the tagged commit is not on `main`.
|
|
423
|
+
|
|
424
|
+
## License
|
|
425
|
+
|
|
426
|
+
[MIT](./LICENSE)
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { run } from "../src/cli.js";
|
|
3
|
+
|
|
4
|
+
// 출력을 받는 쪽이 먼저 닫으면(예: `designsnitch check | head`) 조용히 끝낸다.
|
|
5
|
+
process.stdout.on("error", (error) => {
|
|
6
|
+
if (error.code === "EPIPE") process.exit();
|
|
7
|
+
throw error;
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
const argv = process.argv.slice(2);
|
|
11
|
+
|
|
12
|
+
process.exitCode = await run(argv, {
|
|
13
|
+
cwd: process.cwd(),
|
|
14
|
+
// hook 명령은 에이전트가 표준 입력으로 주는 JSON 을 읽는다.
|
|
15
|
+
stdin: argv[0] === "hook" && !process.stdin.isTTY ? await readStdin() : undefined,
|
|
16
|
+
stdout: process.stdout,
|
|
17
|
+
stderr: process.stderr,
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
// 입력이 끝나지 않는 환경에서도 멈추지 않도록 잠깐만 기다린다.
|
|
21
|
+
function readStdin(timeoutMs = 2000) {
|
|
22
|
+
return new Promise((resolve) => {
|
|
23
|
+
let data = "";
|
|
24
|
+
const done = () => {
|
|
25
|
+
process.stdin.pause();
|
|
26
|
+
resolve(data);
|
|
27
|
+
};
|
|
28
|
+
const timer = setTimeout(done, timeoutMs);
|
|
29
|
+
process.stdin.setEncoding("utf8");
|
|
30
|
+
process.stdin.on("data", (chunk) => (data += chunk));
|
|
31
|
+
process.stdin.on("end", () => {
|
|
32
|
+
clearTimeout(timer);
|
|
33
|
+
done();
|
|
34
|
+
});
|
|
35
|
+
process.stdin.on("error", () => {
|
|
36
|
+
clearTimeout(timer);
|
|
37
|
+
done();
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,50 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "designsnitch",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "AI가 만든 UI 코드에서 디자인 시스템을 벗어난 곳을 찾는 CLI와 ESLint 플러그인",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./src/index.js",
|
|
7
|
+
"exports": "./src/index.js",
|
|
8
|
+
"files": [
|
|
9
|
+
"bin",
|
|
10
|
+
"src",
|
|
11
|
+
"skills"
|
|
12
|
+
],
|
|
13
|
+
"scripts": {
|
|
14
|
+
"test": "vitest run",
|
|
15
|
+
"test:watch": "vitest"
|
|
16
|
+
},
|
|
17
|
+
"dependencies": {
|
|
18
|
+
"@typescript-eslint/parser": "^8.73.0",
|
|
19
|
+
"eslint": ">=9",
|
|
20
|
+
"postcss": "^8.4.0"
|
|
21
|
+
},
|
|
22
|
+
"devDependencies": {
|
|
23
|
+
"vitest": "^3.0.0"
|
|
24
|
+
},
|
|
25
|
+
"bin": {
|
|
26
|
+
"designsnitch": "./bin/designsnitch.js"
|
|
27
|
+
},
|
|
28
|
+
"engines": {
|
|
29
|
+
"node": ">=22"
|
|
30
|
+
},
|
|
31
|
+
"repository": {
|
|
32
|
+
"type": "git",
|
|
33
|
+
"url": "git+https://github.com/icecokel/designsnitch.git"
|
|
34
|
+
},
|
|
35
|
+
"homepage": "https://github.com/icecokel/designsnitch#readme",
|
|
36
|
+
"bugs": {
|
|
37
|
+
"url": "https://github.com/icecokel/designsnitch/issues"
|
|
38
|
+
},
|
|
39
|
+
"keywords": [
|
|
40
|
+
"design-system",
|
|
41
|
+
"design-tokens",
|
|
42
|
+
"tailwindcss",
|
|
43
|
+
"lint",
|
|
44
|
+
"eslint",
|
|
45
|
+
"eslintplugin",
|
|
46
|
+
"agent-skill",
|
|
47
|
+
"cli"
|
|
48
|
+
],
|
|
49
|
+
"license": "MIT"
|
|
50
|
+
}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: designsnitch-check
|
|
3
|
+
description: After creating or editing UI code in a React/Next.js + Tailwind project, check it against the project's design system (color tokens and shared components) and fix what is off. Use when you have changed components, pages, className values or styles, or when the user asks for a design system check or cleanup.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# designsnitch-check
|
|
7
|
+
|
|
8
|
+
After you change UI code, run the design system check before you finish. The CLI makes the verdicts and tells you what to do with each one. This document covers how to act on that, and how to ask the user when a decision is theirs.
|
|
9
|
+
|
|
10
|
+
## 1. Run the check
|
|
11
|
+
|
|
12
|
+
Pass the files you changed. Without paths, the whole project is checked.
|
|
13
|
+
|
|
14
|
+
```sh
|
|
15
|
+
npx designsnitch check src/features/checkout/PayButton.tsx --format json
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
The exit code is 0 (no errors), 1 (errors found), or 2 (could not run). On 2, read the message on stderr.
|
|
19
|
+
|
|
20
|
+
- The config file `designsnitch.config.json` is missing: follow the `designsnitch-setup` skill first, then come back.
|
|
21
|
+
- The token CSS could not be read: the message names the file, line and column. Fix that syntax error first. Nothing can be judged while the standard itself is broken.
|
|
22
|
+
|
|
23
|
+
## 2. Read the result
|
|
24
|
+
|
|
25
|
+
```json
|
|
26
|
+
{
|
|
27
|
+
"designSystem": { "colorTokens": 175, "components": 4, "replacedTags": 2 },
|
|
28
|
+
"problems": [],
|
|
29
|
+
"next": [
|
|
30
|
+
"action이 replace인 1건은 found를 candidates의 값으로 바꾸세요.",
|
|
31
|
+
"action이 ask인 1건은 바꾸지 말고 사용자에게 물으세요. ...",
|
|
32
|
+
"고친 뒤 같은 명령을 다시 실행하세요."
|
|
33
|
+
],
|
|
34
|
+
"summary": { "files": 1, "errors": 2, "warnings": 0 },
|
|
35
|
+
"violations": [
|
|
36
|
+
{
|
|
37
|
+
"file": "src/features/checkout/PayButton.tsx",
|
|
38
|
+
"line": 7,
|
|
39
|
+
"column": 28,
|
|
40
|
+
"endLine": 7,
|
|
41
|
+
"endColumn": 40,
|
|
42
|
+
"rule": "color-use-token",
|
|
43
|
+
"severity": "error",
|
|
44
|
+
"message": "bg-[#3B82F6]의 색은 토큰 --color-primary-500의 값입니다. 대신 사용: bg-primary-500",
|
|
45
|
+
"found": "bg-[#3B82F6]",
|
|
46
|
+
"candidates": ["bg-primary-500"],
|
|
47
|
+
"action": "replace"
|
|
48
|
+
}
|
|
49
|
+
]
|
|
50
|
+
}
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
- `next` lists what to do, in order. It is written in Korean, like `message`. The fields below carry the same information, so you do not need to parse either.
|
|
54
|
+
- `action` says how to handle each violation. Section 3 covers each value.
|
|
55
|
+
- `found` is the offending piece of code. `candidates` lists what to use instead: classes or components in JS and TS files, and `var(--token)` in `.css` files.
|
|
56
|
+
- `designSystem` counts the tokens and components read from the config. `colorTokens` 0 means the project has no color tokens that can be read: follow the `designsnitch-palette` skill to establish them before touching any color.
|
|
57
|
+
- A non-empty `problems` means the config is broken and the results cannot be trusted. Tell the user before fixing anything.
|
|
58
|
+
|
|
59
|
+
| `rule` | Severity | Meaning |
|
|
60
|
+
| --- | --- | --- |
|
|
61
|
+
| `color-use-token` | error | A hex color that has a token was written as an arbitrary value, or directly in a CSS declaration. |
|
|
62
|
+
| `color-unknown` | warning | A hex color with no matching token. |
|
|
63
|
+
| `use-ds-component` | error | A raw tag was used outside the design system directory although a shared component replaces it. |
|
|
64
|
+
| `parse-error` | error | The file could not be parsed. |
|
|
65
|
+
|
|
66
|
+
## 3. Act on each violation
|
|
67
|
+
|
|
68
|
+
| `action` | What it means | What to do |
|
|
69
|
+
| --- | --- | --- |
|
|
70
|
+
| `replace` | An error with exactly one candidate. | Replace `found` with the candidate. |
|
|
71
|
+
| `ask` | A person has to decide: an error with several candidates, or a color that has no token. | Do not change it. Ask the user as described in section 4. |
|
|
72
|
+
| `repair` | The file could not be parsed. | Fix the syntax error, then check again. |
|
|
73
|
+
|
|
74
|
+
For `use-ds-component`, replacing means more than renaming the tag. Read the design system component file to learn its props, add the import, and remove className values that duplicate styles the component already has.
|
|
75
|
+
|
|
76
|
+
## 4. Ask so the user can decide
|
|
77
|
+
|
|
78
|
+
Deciding is the user's job. Your job is to make the decision easy. Do not hand over a bare list of violations. For each decision, give:
|
|
79
|
+
|
|
80
|
+
1. **What has to be decided**, in one sentence.
|
|
81
|
+
2. **The facts.** Run `npx designsnitch colors --format json` and report how often the color is used, in how many files, and for what (text, background, border). Open one or two of the locations if the use is unclear.
|
|
82
|
+
3. **What each choice changes.** Say whether the screen will look different, and how many places would be edited.
|
|
83
|
+
4. **Your recommendation and why.**
|
|
84
|
+
|
|
85
|
+
Group decisions that are the same question. Thirty uses of one unknown color are one decision, not thirty.
|
|
86
|
+
|
|
87
|
+
An example for an error with several candidates:
|
|
88
|
+
|
|
89
|
+
> `text-[#484646]` matches two tokens: `--color-text-primary` and `--color-neutral-30`. It appears 137 times, almost always as body text (`text-`). Either token renders the same color today, so nothing changes on screen. They will diverge if the neutral scale is ever retuned. I recommend `text-text-primary`, because the use is text and that token is named for it. Shall I replace all 137?
|
|
90
|
+
|
|
91
|
+
An example for a color with no token:
|
|
92
|
+
|
|
93
|
+
> `#3B82F5` is used 3 times, all as a button background. It is one step away from `--color-primary-500` (`#3B82F6`), which is used 88 times, so it is probably a typo. Replacing it changes the color by an amount the eye cannot see. I recommend replacing the 3 with `bg-primary-500`. If it is a separate color on purpose, it needs its own token.
|
|
94
|
+
|
|
95
|
+
## 5. Check again
|
|
96
|
+
|
|
97
|
+
After fixing, run the same command again. Stop when the only items left are waiting on the user's decision.
|
|
98
|
+
|
|
99
|
+
## 6. Report
|
|
100
|
+
|
|
101
|
+
Report what you fixed and what you left, separately. For what you left, use the form from section 4.
|
|
102
|
+
|
|
103
|
+
## What not to do
|
|
104
|
+
|
|
105
|
+
- Do not edit `designsnitch.config.json` or the token CSS to make the check pass. They are the standard the code is judged against. If one of them seems wrong, explain why and ask the user.
|
|
106
|
+
- Do not add `eslint-disable` or `designsnitch-disable-next-line` comments, lower a rule's severity, or turn a rule off to make the check pass. If an exception seems necessary, ask the user.
|
|
107
|
+
- Do not pick one of several candidates on your own.
|