designsnitch 0.2.0 → 0.4.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.ko.md +139 -34
- package/README.md +159 -55
- package/bin/designsnitch.js +51 -17
- package/package.json +4 -4
- package/skills/designsnitch-check/SKILL.md +38 -14
- package/skills/designsnitch-eslint/SKILL.md +2 -0
- package/skills/designsnitch-hooks/SKILL.md +83 -8
- package/skills/designsnitch-palette/SKILL.md +8 -6
- package/skills/designsnitch-setup/SKILL.md +22 -2
- package/src/check.js +155 -45
- package/src/cli.js +33 -36
- package/src/colors.js +4 -2
- package/src/config.js +62 -26
- package/src/core/classes.js +12 -0
- package/src/core/css.js +4 -3
- package/src/core/tokens.js +66 -12
- package/src/format.js +29 -41
- package/src/hook.js +79 -20
- package/src/install.js +104 -46
- package/src/messages.js +299 -0
- package/src/rules/color-unknown.js +18 -8
- package/src/rules/color-use-token.js +39 -17
- package/src/rules/load-tokens.js +29 -24
- package/src/rules/suggest.js +12 -4
- package/src/rules/unchecked-hex.js +25 -0
- package/src/rules/use-ds-component.js +36 -12
- package/src/rules/visit-style.js +64 -0
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# designsnitch
|
|
2
2
|
|
|
3
|
-
English | [
|
|
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
|
|
|
@@ -23,7 +23,7 @@ It has four parts.
|
|
|
23
23
|
|
|
24
24
|
It supports **React/Next.js projects that use Tailwind CSS v4**.
|
|
25
25
|
|
|
26
|
-
> **Status:** MVP (0.2.x).
|
|
26
|
+
> **Status:** MVP (0.2.x). Messages are in English by default and can be switched to Korean. See [Language](#language).
|
|
27
27
|
|
|
28
28
|
## Getting started
|
|
29
29
|
|
|
@@ -32,7 +32,26 @@ npm install --save-dev designsnitch
|
|
|
32
32
|
npx designsnitch install
|
|
33
33
|
```
|
|
34
34
|
|
|
35
|
-
The second command
|
|
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.
|
|
36
55
|
|
|
37
56
|
Then ask your coding agent:
|
|
38
57
|
|
|
@@ -75,22 +94,22 @@ Severity follows one rule.
|
|
|
75
94
|
|
|
76
95
|
| Rule | Severity | What it catches |
|
|
77
96
|
| --- | --- | --- |
|
|
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`) |
|
|
97
|
+
| `color-use-token` | Error | A hex color that has a token, written as an arbitrary value (`bg-[#3B82F6]`), in an inline style (`style={{ color: "#3B82F6" }}`) or in a CSS declaration (`color: #3B82F6`) |
|
|
79
98
|
| `color-unknown` | Warning | A hex color with no matching token |
|
|
80
99
|
| `use-ds-component` | Error | A raw tag such as `<button>` used outside the design system directory, when a shared component replaces it |
|
|
81
100
|
|
|
82
|
-
Every error comes with what to use instead: a class or component in JS and TS files, and `var(--token)` in CSS files.
|
|
101
|
+
Every error comes with what to use instead: a class or component in JS and TS files, and `var(--token)` in inline styles and CSS files. Tailwind v4 outputs a theme variable when the source uses it with `var()`, so `var(--token)` in an inline style renders the same color.
|
|
83
102
|
|
|
84
103
|
## Commands
|
|
85
104
|
|
|
86
105
|
| Command | What it does |
|
|
87
106
|
| --- | --- |
|
|
88
|
-
| `designsnitch install` | Copies the skills and registers the agent hook in the project. |
|
|
107
|
+
| `designsnitch install` | Copies the skills and registers the agent hook in the project. `--agent claude` (default), `codex`, `gemini`, `grok` or `all`. |
|
|
89
108
|
| `designsnitch colors` | Lists the colors the code uses. Works without a config file. |
|
|
90
109
|
| `designsnitch check` | Checks code against the standard and says what to do with each violation. |
|
|
91
110
|
| `designsnitch hook` | Called from the agent's hook. Checks the files the agent just changed. |
|
|
92
111
|
|
|
93
|
-
`check` and `colors` take paths, `--format json`, and `--config <file>`.
|
|
112
|
+
`check` and `colors` take paths, `--format json`, and `--config <file>`. Every command takes `--lang en|ko`.
|
|
94
113
|
|
|
95
114
|
## Setting up by hand
|
|
96
115
|
|
|
@@ -107,7 +126,7 @@ Create `designsnitch.config.json` in the project root.
|
|
|
107
126
|
"path": "./components/ui",
|
|
108
127
|
"replaces": {
|
|
109
128
|
"button": ["SolidButton", "IconButton"],
|
|
110
|
-
"input": "Input",
|
|
129
|
+
"input": { "component": "Input", "when": { "type": ["text", "email", null] } },
|
|
111
130
|
"dialog": "Dialog"
|
|
112
131
|
}
|
|
113
132
|
}
|
|
@@ -134,28 +153,28 @@ npx designsnitch colors --format json
|
|
|
134
153
|
```
|
|
135
154
|
|
|
136
155
|
```
|
|
137
|
-
|
|
156
|
+
Colors used in the code: 5 hex, 1 from the default palette (10 uses, 1 file checked)
|
|
138
157
|
|
|
139
|
-
|
|
140
|
-
#3a11d8 3
|
|
141
|
-
#484646 2
|
|
142
|
-
#ffffff 2
|
|
143
|
-
#484645 1
|
|
144
|
-
#e2e1e5 1
|
|
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
|
|
145
164
|
|
|
146
|
-
Tailwind
|
|
147
|
-
gray-700 1
|
|
165
|
+
Tailwind default palette
|
|
166
|
+
gray-700 1 use 1 file text 1
|
|
148
167
|
```
|
|
149
168
|
|
|
150
169
|
| Part of the output | Meaning |
|
|
151
170
|
| --- | --- |
|
|
152
|
-
| `
|
|
171
|
+
| `Hex colors` | Hex colors, most used first, with the number of uses and files. |
|
|
153
172
|
| `bg 2`, `text 1` | Uses per Tailwind utility. `bg-[#3a11d8]` counts under `bg`. |
|
|
154
|
-
|
|
|
173
|
+
| `string 1` | Strings that are a hex color on their own, such as inline styles and chart options. |
|
|
155
174
|
| `CSS 2` | Uses in CSS declarations. The JSON output breaks these down by property. |
|
|
156
|
-
| `Tailwind
|
|
175
|
+
| `Tailwind default palette` | Colors from Tailwind's default palette used by name, such as `text-gray-700`. |
|
|
157
176
|
|
|
158
|
-
When a config file exists, each color also shows the tokens that already have that value (
|
|
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.
|
|
159
178
|
|
|
160
179
|
The [`designsnitch-palette` skill](#agent-skills) uses this output to propose tokens, and writes them after you approve.
|
|
161
180
|
|
|
@@ -163,11 +182,35 @@ The [`designsnitch-palette` skill](#agent-skills) uses this output to propose to
|
|
|
163
182
|
|
|
164
183
|
| Field | Description |
|
|
165
184
|
| --- | --- |
|
|
166
|
-
| `tokens` | The CSS file that defines the tokens. Required. |
|
|
185
|
+
| `tokens` | The CSS file that defines the tokens. Required. Either a path, or an object with `file` and the optional `exclude` and `prefer` (see below). |
|
|
167
186
|
| `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. |
|
|
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`. |
|
|
169
189
|
|
|
170
|
-
Without `components`, the component check is skipped. Use `--config <file>` to read a config file from another path.
|
|
190
|
+
Without `components`, the component check is skipped. Use `--config <file>` to read a config file from another path. Paths in the config file are relative to the directory of the config file.
|
|
191
|
+
|
|
192
|
+
When several tokens share one value, every hex color with that value has several candidates, and each one needs a person's decision. The object form of `tokens` settles this once, in the config.
|
|
193
|
+
|
|
194
|
+
```json
|
|
195
|
+
"tokens": {
|
|
196
|
+
"file": "app/globals.css",
|
|
197
|
+
"exclude": ["--color-legacy-*"],
|
|
198
|
+
"prefer": ["--color-brand-"]
|
|
199
|
+
}
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
- `exclude` drops tokens from the standard: exact names, or a prefix ending in `*`. A color that only an excluded token has counts as a color with no token. Other tokens can still refer to an excluded one with `var()`.
|
|
203
|
+
- `prefer` lists token prefixes in order. When the first prefix that matches leaves exactly one candidate, that candidate is the only one, and the error can be replaced right away. When it leaves several, they are all kept and a person decides.
|
|
204
|
+
|
|
205
|
+
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.
|
|
206
|
+
|
|
207
|
+
```json
|
|
208
|
+
"input": { "component": "Input", "when": { "type": ["text", "email", null] } }
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
- `<input type="file">` is not reported, because the component does not cover it.
|
|
212
|
+
- `<input type="text">` and `<input>` are reported as errors that can be replaced.
|
|
213
|
+
- `<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.
|
|
171
214
|
|
|
172
215
|
This is what is read from the token CSS.
|
|
173
216
|
|
|
@@ -193,47 +236,95 @@ Both of these shapes work.
|
|
|
193
236
|
}
|
|
194
237
|
```
|
|
195
238
|
|
|
239
|
+
## Language
|
|
240
|
+
|
|
241
|
+
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.
|
|
242
|
+
|
|
243
|
+
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.
|
|
244
|
+
|
|
196
245
|
## Output
|
|
197
246
|
|
|
198
247
|
```
|
|
199
|
-
|
|
248
|
+
Design system: 2 color tokens, 2 components
|
|
200
249
|
|
|
201
250
|
src/PayButton.tsx
|
|
202
|
-
5:6
|
|
203
|
-
7:55
|
|
204
|
-
8:26
|
|
251
|
+
5:6 error Use a design system component instead of <button>: Button (./components/ui) (use-ds-component)
|
|
252
|
+
7:55 error bg-[#3B82F6] has the same color as --color-primary-500. Use instead: bg-primary-500 (color-use-token)
|
|
253
|
+
8:26 warning The color of bg-[#3B82F5] is not in the tokens. (color-unknown)
|
|
205
254
|
|
|
206
|
-
|
|
207
|
-
|
|
255
|
+
2 errors, 1 warning (3 files checked)
|
|
256
|
+
2 can be replaced right away, 1 needs a person's decision (1 decision)
|
|
208
257
|
```
|
|
209
258
|
|
|
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
|
|
259
|
+
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, how many need a person's decision, and how many separate questions those come down to.
|
|
211
260
|
|
|
212
|
-
`--format json` prints the same result as structured data.
|
|
261
|
+
`--format json` prints the same result as structured data. This example has one violation of each kind, and leaves the rest out.
|
|
213
262
|
|
|
214
263
|
```json
|
|
215
264
|
{
|
|
216
|
-
"designSystem": { "colorTokens":
|
|
265
|
+
"designSystem": { "colorTokens": 4, "components": 1, "replacedTags": 1 },
|
|
217
266
|
"problems": [],
|
|
218
267
|
"next": [
|
|
219
|
-
"action
|
|
220
|
-
"
|
|
221
|
-
"
|
|
268
|
+
"action \"replace\" (2): replace found with the value in candidates.",
|
|
269
|
+
"Before making changes, ask the user about the 2 entries in decisions. Include how often each comes up, the candidates, and the reasons for asking.",
|
|
270
|
+
"After fixing, run the same command again."
|
|
222
271
|
],
|
|
223
|
-
"summary": { "files":
|
|
272
|
+
"summary": { "files": 1, "errors": 4, "warnings": 1 },
|
|
224
273
|
"violations": [
|
|
225
274
|
{
|
|
226
275
|
"file": "src/PayButton.tsx",
|
|
227
|
-
"line":
|
|
228
|
-
"column":
|
|
229
|
-
"endLine":
|
|
230
|
-
"endColumn":
|
|
276
|
+
"line": 3,
|
|
277
|
+
"column": 24,
|
|
278
|
+
"endLine": 3,
|
|
279
|
+
"endColumn": 36,
|
|
231
280
|
"rule": "color-use-token",
|
|
232
281
|
"severity": "error",
|
|
233
|
-
"message": "bg-[#3B82F6]
|
|
282
|
+
"message": "bg-[#3B82F6] has the same color as --color-brand-500. Use instead: bg-brand-500",
|
|
234
283
|
"found": "bg-[#3B82F6]",
|
|
235
|
-
"candidates": ["bg-
|
|
284
|
+
"candidates": ["bg-brand-500"],
|
|
285
|
+
"recommended": "bg-brand-500",
|
|
236
286
|
"action": "replace"
|
|
287
|
+
},
|
|
288
|
+
{
|
|
289
|
+
"file": "src/PayButton.tsx",
|
|
290
|
+
"line": 3,
|
|
291
|
+
"column": 37,
|
|
292
|
+
"endLine": 3,
|
|
293
|
+
"endColumn": 51,
|
|
294
|
+
"rule": "color-use-token",
|
|
295
|
+
"severity": "error",
|
|
296
|
+
"message": "text-[#484646] has the same color as --color-text-primary, --color-neutral-30. Use instead: text-text-primary, text-neutral-30",
|
|
297
|
+
"found": "text-[#484646]",
|
|
298
|
+
"candidates": ["text-text-primary", "text-neutral-30"],
|
|
299
|
+
"recommended": "text-text-primary",
|
|
300
|
+
"action": "ask"
|
|
301
|
+
}
|
|
302
|
+
],
|
|
303
|
+
"decisions": [
|
|
304
|
+
{
|
|
305
|
+
"id": "decision-1",
|
|
306
|
+
"rule": "color-use-token",
|
|
307
|
+
"subject": "#484646",
|
|
308
|
+
"uses": 2,
|
|
309
|
+
"files": 1,
|
|
310
|
+
"locations": [
|
|
311
|
+
{ "file": "src/PayButton.tsx", "line": 3, "column": 37 },
|
|
312
|
+
{ "file": "src/PayButton.tsx", "line": 4, "column": 24 }
|
|
313
|
+
],
|
|
314
|
+
"candidates": ["text-text-primary", "text-neutral-30"],
|
|
315
|
+
"recommended": "text-text-primary",
|
|
316
|
+
"reasons": ["multiple-candidates"]
|
|
317
|
+
},
|
|
318
|
+
{
|
|
319
|
+
"id": "decision-2",
|
|
320
|
+
"rule": "color-unknown",
|
|
321
|
+
"subject": "#3b82f5",
|
|
322
|
+
"uses": 1,
|
|
323
|
+
"files": 1,
|
|
324
|
+
"locations": [{ "file": "src/PayButton.tsx", "line": 4, "column": 39 }],
|
|
325
|
+
"candidates": [],
|
|
326
|
+
"recommended": null,
|
|
327
|
+
"reasons": ["no-token"]
|
|
237
328
|
}
|
|
238
329
|
]
|
|
239
330
|
}
|
|
@@ -245,8 +336,11 @@ The first line shows how many tokens and components were read from the config. A
|
|
|
245
336
|
| `problems` | Config problems that make the result unreliable. Empty when everything is fine. |
|
|
246
337
|
| `violations[].found` | The offending piece of code |
|
|
247
338
|
| `violations[].candidates` | The classes or components to use instead. Empty when there are none. |
|
|
248
|
-
| `violations[].
|
|
339
|
+
| `violations[].recommended` | The candidate that fits how the color is used: a `text-` class gets the token named for text, a border gets the one named for borders. Only set when exactly one candidate fits, and only a suggestion: an `ask` stays an `ask`. For `replace`, it is the candidate. |
|
|
340
|
+
| `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. |
|
|
341
|
+
| `decisions` | The `ask` violations grouped into questions: one per color or tag with the same candidates. Each has how often it comes up (`uses`, `files`), up to five `locations`, the `candidates`, a `recommended` candidate when every location agrees, and the `reasons` a person has to decide: `multiple-candidates`, `no-token`, `themed-token` or `dynamic-props`. Most used first. |
|
|
249
342
|
| `next` | What an agent should do with this result, in order |
|
|
343
|
+
| `unchecked` | Hex colors in other strings that were not checked (`hexColors`), and how many files they are in (`files`). The text output adds a line when there are any. |
|
|
250
344
|
|
|
251
345
|
| Exit code | Meaning |
|
|
252
346
|
| --- | --- |
|
|
@@ -276,7 +370,7 @@ In a CSS file, put this comment on the line before the declaration.
|
|
|
276
370
|
|
|
277
371
|
## Agent skills
|
|
278
372
|
|
|
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.
|
|
373
|
+
`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.
|
|
280
374
|
|
|
281
375
|
Each skill does one job.
|
|
282
376
|
|
|
@@ -316,6 +410,8 @@ export default [
|
|
|
316
410
|
];
|
|
317
411
|
```
|
|
318
412
|
|
|
413
|
+
Paths in the settings are resolved from ESLint's working directory. If `designsnitch.config.json` is not next to `eslint.config.js`, as in a monorepo, add the directory the paths are relative to: `settings: { designsnitch: { ...designSystem, root: "apps/web" } }`.
|
|
414
|
+
|
|
319
415
|
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
416
|
|
|
321
417
|
## Blocking violations
|
|
@@ -349,13 +445,21 @@ A skill is advice that an agent may not follow. A hook is run by the agent's run
|
|
|
349
445
|
}
|
|
350
446
|
```
|
|
351
447
|
|
|
352
|
-
`designsnitch hook` checks only the files the agent just changed.
|
|
448
|
+
`designsnitch hook` checks only the files the agent just changed, and blocks only errors the change added.
|
|
449
|
+
|
|
450
|
+
- 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.
|
|
451
|
+
- After an edit, if the file has new errors, the agent receives them along with what to do next.
|
|
452
|
+
- 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.
|
|
453
|
+
- Warnings never block, and files the agent did not touch are left alone.
|
|
454
|
+
- Outside a git repository, or before the first commit, every error in the changed files counts.
|
|
455
|
+
|
|
456
|
+
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.
|
|
457
|
+
|
|
458
|
+
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.
|
|
353
459
|
|
|
354
|
-
|
|
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.
|
|
460
|
+
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.
|
|
357
461
|
|
|
358
|
-
The command reads an optional JSON object from stdin (`tool_input.file_path`, `hook_event_name`, `stop_hook_active
|
|
462
|
+
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.
|
|
359
463
|
|
|
360
464
|
### Tailwind's default palette
|
|
361
465
|
|
|
@@ -370,9 +474,9 @@ designsnitch does not flag default palette classes such as `bg-blue-500`. If the
|
|
|
370
474
|
|
|
371
475
|
## Scope
|
|
372
476
|
|
|
373
|
-
- **Where it looks in JS and TS:** string literals and template literals
|
|
374
|
-
- **Where it looks in CSS:** hex colors in declaration values, in `.css` files including CSS Modules.
|
|
375
|
-
- **Themes:** when a token has different values per theme, all of them count as that token's value.
|
|
477
|
+
- **Where it looks in JS and TS:** arbitrary color classes in string literals and template literals, which covers `className` and the arguments of `cn()`, `clsx()` and `cva()`, and hex colors written as strings in a JSX `style` object. Comments are ignored. Hex colors in other strings, such as theme objects and chart options, are not checked: their purpose cannot be told from the code. The check counts them in `unchecked` so that you know they are there, and `designsnitch colors` lists them.
|
|
478
|
+
- **Where it looks in CSS:** hex colors in declaration values, in `.css` files including CSS Modules. In the token CSS, declarations that define a variable (`--name: ...`) are skipped, since that is where tokens are defined. In every other CSS file they are checked like any other declaration. Only colors are checked in CSS for now.
|
|
479
|
+
- **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`.
|
|
376
480
|
- **Fixes:** designsnitch reports candidates and never rewrites code by itself, even when there is only one candidate.
|
|
377
481
|
|
|
378
482
|
### Not supported yet
|
|
@@ -381,12 +485,12 @@ designsnitch does not flag default palette classes such as `bg-blue-500`. If the
|
|
|
381
485
|
- Values from Tailwind's default theme. Only the values written in the project's token CSS are read.
|
|
382
486
|
- Tailwind v3 (`tailwind.config.js`)
|
|
383
487
|
- The nearest token for a color that has none
|
|
384
|
-
- Inline
|
|
488
|
+
- Inline style values that are computed, such as `color: active ? "#3B82F6" : "#fff"`
|
|
385
489
|
- SCSS and other preprocessors
|
|
386
490
|
- Spacing, font size and radius. They were left out of this version on purpose.
|
|
387
491
|
- Classes inside `@apply`
|
|
388
492
|
- Comparing a hand-made component's styles with the design system component
|
|
389
|
-
- Installing the
|
|
493
|
+
- Installing the hook for agents other than Claude Code, Codex, Gemini CLI and Grok Build
|
|
390
494
|
|
|
391
495
|
Comparing a screen with a design file such as Figma is out of scope. The standard is the design system alone.
|
|
392
496
|
|
package/bin/designsnitch.js
CHANGED
|
@@ -1,21 +1,55 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
process.
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
});
|
|
2
|
+
|
|
3
|
+
const MINIMUM_NODE_MAJOR = 22;
|
|
4
|
+
|
|
5
|
+
/** @param {string} version process.versions.node 와 같은 형식의 버전 */
|
|
6
|
+
export function isSupportedNodeVersion(version) {
|
|
7
|
+
return Number(version.split(".", 1)[0]) >= MINIMUM_NODE_MAJOR;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
const version = process.versions.node;
|
|
11
|
+
const supported = isSupportedNodeVersion(version);
|
|
12
|
+
if (await isEntrypoint()) await main();
|
|
13
|
+
|
|
14
|
+
async function isEntrypoint() {
|
|
15
|
+
const entry = process.argv[1];
|
|
16
|
+
if (!entry) return false;
|
|
17
|
+
// 설치된 실행 파일은 심볼릭 링크일 수 있다.
|
|
18
|
+
const { existsSync, realpathSync } = await import("node:fs");
|
|
19
|
+
return existsSync(entry) && realpathSync(entry) === realpathSync(new URL(import.meta.url));
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
async function main() {
|
|
23
|
+
const argv = process.argv.slice(2);
|
|
24
|
+
if (!supported) {
|
|
25
|
+
let flagLang;
|
|
26
|
+
for (const [index, arg] of argv.entries()) {
|
|
27
|
+
if (arg === "--") break;
|
|
28
|
+
if (arg === "--lang") flagLang = argv[index + 1];
|
|
29
|
+
else if (arg.startsWith("--lang=")) flagLang = arg.slice("--lang=".length);
|
|
30
|
+
}
|
|
31
|
+
const { messages, resolveLang } = await import("../src/messages.js");
|
|
32
|
+
const message = messages(resolveLang(flagLang)).nodeVersionUnsupported;
|
|
33
|
+
process.stderr.write(`${message({ minimum: MINIMUM_NODE_MAJOR, version })}\n`);
|
|
34
|
+
process.exitCode = 2;
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// 출력을 받는 쪽이 먼저 닫으면(예: `designsnitch check | head`) 조용히 끝낸다.
|
|
39
|
+
process.stdout.on("error", (error) => {
|
|
40
|
+
if (error.code === "EPIPE") process.exit();
|
|
41
|
+
throw error;
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
const { run } = await import("../src/cli.js");
|
|
45
|
+
process.exitCode = await run(argv, {
|
|
46
|
+
cwd: process.cwd(),
|
|
47
|
+
// hook 명령은 에이전트가 표준 입력으로 주는 JSON 을 읽는다.
|
|
48
|
+
stdin: argv[0] === "hook" && !process.stdin.isTTY ? await readStdin() : undefined,
|
|
49
|
+
stdout: process.stdout,
|
|
50
|
+
stderr: process.stderr,
|
|
51
|
+
});
|
|
52
|
+
}
|
|
19
53
|
|
|
20
54
|
// 입력이 끝나지 않는 환경에서도 멈추지 않도록 잠깐만 기다린다.
|
|
21
55
|
function readStdin(timeoutMs = 2000) {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "designsnitch",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "AI
|
|
3
|
+
"version": "0.4.0",
|
|
4
|
+
"description": "Keep AI-written UI code manageable and consistent, even without a design system. CLI, agent skills, ESLint plugin and agent hook for React/Next.js with Tailwind CSS v4.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./src/index.js",
|
|
7
7
|
"exports": "./src/index.js",
|
|
@@ -16,14 +16,14 @@
|
|
|
16
16
|
},
|
|
17
17
|
"dependencies": {
|
|
18
18
|
"@typescript-eslint/parser": "^8.73.0",
|
|
19
|
-
"eslint": "
|
|
19
|
+
"eslint": "^9 || ^10",
|
|
20
20
|
"postcss": "^8.4.0"
|
|
21
21
|
},
|
|
22
22
|
"devDependencies": {
|
|
23
23
|
"vitest": "^3.0.0"
|
|
24
24
|
},
|
|
25
25
|
"bin": {
|
|
26
|
-
"designsnitch": "
|
|
26
|
+
"designsnitch": "bin/designsnitch.js"
|
|
27
27
|
},
|
|
28
28
|
"engines": {
|
|
29
29
|
"node": ">=22"
|
|
@@ -27,11 +27,11 @@ The exit code is 0 (no errors), 1 (errors found), or 2 (could not run). On 2, re
|
|
|
27
27
|
"designSystem": { "colorTokens": 175, "components": 4, "replacedTags": 2 },
|
|
28
28
|
"problems": [],
|
|
29
29
|
"next": [
|
|
30
|
-
"action
|
|
31
|
-
"
|
|
32
|
-
"
|
|
30
|
+
"action \"replace\" (1): replace found with the value in candidates.",
|
|
31
|
+
"Before making changes, ask the user about the 1 entry in decisions. Include how often each comes up, the candidates, and the reasons for asking.",
|
|
32
|
+
"After fixing, run the same command again."
|
|
33
33
|
],
|
|
34
|
-
"summary": { "files":
|
|
34
|
+
"summary": { "files": 2, "errors": 3, "warnings": 0 },
|
|
35
35
|
"violations": [
|
|
36
36
|
{
|
|
37
37
|
"file": "src/features/checkout/PayButton.tsx",
|
|
@@ -41,24 +41,44 @@ The exit code is 0 (no errors), 1 (errors found), or 2 (could not run). On 2, re
|
|
|
41
41
|
"endColumn": 40,
|
|
42
42
|
"rule": "color-use-token",
|
|
43
43
|
"severity": "error",
|
|
44
|
-
"message": "bg-[#3B82F6]
|
|
44
|
+
"message": "bg-[#3B82F6] has the same color as --color-primary-500. Use instead: bg-primary-500",
|
|
45
45
|
"found": "bg-[#3B82F6]",
|
|
46
46
|
"candidates": ["bg-primary-500"],
|
|
47
|
+
"recommended": "bg-primary-500",
|
|
47
48
|
"action": "replace"
|
|
48
49
|
}
|
|
50
|
+
],
|
|
51
|
+
"decisions": [
|
|
52
|
+
{
|
|
53
|
+
"id": "decision-1",
|
|
54
|
+
"rule": "color-use-token",
|
|
55
|
+
"subject": "#484646",
|
|
56
|
+
"uses": 2,
|
|
57
|
+
"files": 2,
|
|
58
|
+
"locations": [
|
|
59
|
+
{ "file": "src/features/checkout/PayButton.tsx", "line": 9, "column": 14 },
|
|
60
|
+
{ "file": "src/features/checkout/Summary.tsx", "line": 4, "column": 20 }
|
|
61
|
+
],
|
|
62
|
+
"candidates": ["text-text-primary", "text-neutral-30"],
|
|
63
|
+
"recommended": "text-text-primary",
|
|
64
|
+
"reasons": ["multiple-candidates"]
|
|
65
|
+
}
|
|
49
66
|
]
|
|
50
67
|
}
|
|
51
68
|
```
|
|
52
69
|
|
|
53
|
-
- `next` lists what to do, in order.
|
|
70
|
+
- `next` lists what to do, in order. `next` and `message` are sentences, in English or in Korean depending on the project's `lang` setting. The fields below carry the same information, so you never need to parse them.
|
|
54
71
|
- `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.
|
|
72
|
+
- `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 inline styles and `.css` files.
|
|
73
|
+
- `recommended` is the candidate whose token is named for how the color is used here, such as the text token for a `text-` class. It is a suggestion to put in front of the user, not permission to replace.
|
|
74
|
+
- `decisions` groups every `ask` violation into questions: one per color or tag with the same candidates, most used first. Each has `uses`, `files`, up to five `locations`, the `candidates`, a `recommended` candidate when all locations agree, and `reasons` (`multiple-candidates`, `no-token`, `themed-token`, `dynamic-props`). Ask the user about decisions, not about single violations.
|
|
75
|
+
- `unchecked` counts hex colors in other strings, such as theme objects and chart options, that the check could not judge. They are not violations. If the count is large and those strings feed the UI, mention it to the user: `npx designsnitch colors` lists them.
|
|
56
76
|
- `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
77
|
- A non-empty `problems` means the config is broken and the results cannot be trusted. Tell the user before fixing anything.
|
|
58
78
|
|
|
59
79
|
| `rule` | Severity | Meaning |
|
|
60
80
|
| --- | --- | --- |
|
|
61
|
-
| `color-use-token` | error | A hex color that has a token was written as an arbitrary value, or directly in a CSS declaration. |
|
|
81
|
+
| `color-use-token` | error | A hex color that has a token was written as an arbitrary value, in an inline style, or directly in a CSS declaration. |
|
|
62
82
|
| `color-unknown` | warning | A hex color with no matching token. |
|
|
63
83
|
| `use-ds-component` | error | A raw tag was used outside the design system directory although a shared component replaces it. |
|
|
64
84
|
| `parse-error` | error | The file could not be parsed. |
|
|
@@ -67,22 +87,26 @@ The exit code is 0 (no errors), 1 (errors found), or 2 (could not run). On 2, re
|
|
|
67
87
|
|
|
68
88
|
| `action` | What it means | What to do |
|
|
69
89
|
| --- | --- | --- |
|
|
70
|
-
| `replace` | An error
|
|
71
|
-
| `ask` | A person has to decide:
|
|
90
|
+
| `replace` | An error whose only candidate keeps the screen and the behavior the same. | Replace `found` with the candidate. |
|
|
91
|
+
| `ask` | A person has to decide: several candidates, a color that has no token, a token whose value differs between themes, or a component whose props are dynamic or spread. `message` says which. | Do not change it. Ask the user as described in section 4. |
|
|
72
92
|
| `repair` | The file could not be parsed. | Fix the syntax error, then check again. |
|
|
73
93
|
|
|
74
94
|
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
95
|
|
|
76
96
|
## 4. Ask so the user can decide
|
|
77
97
|
|
|
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
|
|
98
|
+
Deciding is the user's job. Your job is to make the decision easy. Do not hand over a bare list of violations. Take the questions from `decisions`, most used first. For each one, give:
|
|
79
99
|
|
|
80
100
|
1. **What has to be decided**, in one sentence.
|
|
81
|
-
2. **The facts.**
|
|
101
|
+
2. **The facts.** `uses`, `files` and `locations` say how often and where. For a color, run `npx designsnitch colors --format json` to see what it is used for (text, background, border) and which tokens are close to it. Open one or two of the locations if the use is unclear.
|
|
82
102
|
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.**
|
|
103
|
+
4. **Your recommendation and why.** Start from `recommended` when it is set, and say why it fits.
|
|
104
|
+
|
|
105
|
+
`decisions` already groups the same question. Thirty uses of one unknown color are one decision, not thirty.
|
|
106
|
+
|
|
107
|
+
If many decisions are the same choice between two token families, for example `--color-brand-500` and `--color-blue-500` every time, the config can settle it once. Tell the user that `prefer` in the `tokens` setting of `designsnitch.config.json` would pick the family, and ask before changing the config.
|
|
84
108
|
|
|
85
|
-
|
|
109
|
+
If most decisions are `no-token`, the project is missing tokens rather than making mistakes. Suggest the `designsnitch-palette` skill instead of asking about each color.
|
|
86
110
|
|
|
87
111
|
An example for an error with several candidates:
|
|
88
112
|
|
|
@@ -99,6 +99,8 @@ export default [
|
|
|
99
99
|
];
|
|
100
100
|
```
|
|
101
101
|
|
|
102
|
+
Paths in `designsnitch.config.json` are relative to the config file. ESLint resolves them from its own working directory, so this works when both files sit in the project root. If the config file is somewhere else, as in a monorepo where ESLint runs from the repository root, add the directory the paths are relative to: `settings: { designsnitch: { ...designSystem, root: "apps/web" } }`. The same applies to 3A.
|
|
103
|
+
|
|
102
104
|
If `package.json` has `"type": "module"`, name the file `eslint.config.js`. Otherwise name it `eslint.config.mjs`.
|
|
103
105
|
|
|
104
106
|
Add a lint script if the project has none.
|