@stayicon/drift-guard 0.1.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.md +201 -0
- package/bin/drift-guard.mjs +2 -0
- package/dist/chunk-27T45SVD.js +627 -0
- package/dist/chunk-27T45SVD.js.map +1 -0
- package/dist/cli/index.d.ts +1 -0
- package/dist/cli/index.js +203 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/index.d.ts +132 -0
- package/dist/index.js +21 -0
- package/dist/index.js.map +1 -0
- package/package.json +70 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 drift-guard contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
# π‘οΈ drift-guard
|
|
2
|
+
|
|
3
|
+
**Protect your UI from AI coding agents' design drift.**
|
|
4
|
+
|
|
5
|
+
> When AI writes code, your design survives.
|
|
6
|
+
|
|
7
|
+
[](https://www.npmjs.com/package/drift-guard)
|
|
8
|
+
[](https://opensource.org/licenses/MIT)
|
|
9
|
+
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
## The Problem
|
|
13
|
+
|
|
14
|
+
You created a beautiful design in Stitch/Figma/v0. You brought it into your codebase. It looks great.
|
|
15
|
+
|
|
16
|
+
Then you ask Claude Code / Codex / Cursor to *"add a login feature"*...
|
|
17
|
+
|
|
18
|
+
**And your design is gone.** Colors changed. Spacing broke. Fonts shifted. The original design? Nowhere to be found.
|
|
19
|
+
|
|
20
|
+
This is **Design Drift** β the #1 pain point of AI-assisted frontend development in 2026.
|
|
21
|
+
|
|
22
|
+
## The Solution
|
|
23
|
+
|
|
24
|
+
**drift-guard** locks your design tokens before AI agents touch your code, then detects and blocks any unauthorized changes.
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
# 1. Lock your design
|
|
28
|
+
npx drift-guard init
|
|
29
|
+
|
|
30
|
+
# 2. Generate AI protection rules
|
|
31
|
+
npx drift-guard rules
|
|
32
|
+
|
|
33
|
+
# 3. After AI makes changes, check for drift
|
|
34
|
+
npx drift-guard check
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## How It Works
|
|
38
|
+
|
|
39
|
+
```
|
|
40
|
+
βββββββββββββββββββββββββββββββββββββββββββββββββββ
|
|
41
|
+
β Your Design (Stitch/Figma/CSS) β
|
|
42
|
+
β βββββββ βββββββ βββββββ βββββββ βββββββ β
|
|
43
|
+
β βColorβ βFont β βSpaceβ βShadeβ βRadiusβ β
|
|
44
|
+
β ββββ¬βββ ββββ¬βββ ββββ¬βββ ββββ¬βββ ββββ¬βββ β
|
|
45
|
+
β βββββββββ΄ββββββββ΄ββββββββ΄ββββββββ β
|
|
46
|
+
β β β
|
|
47
|
+
β drift-guard init β
|
|
48
|
+
β β β
|
|
49
|
+
β βββββββββββββΌβββββββββββββ β
|
|
50
|
+
β β .design-guard/ β β
|
|
51
|
+
β β snapshot.json π β β
|
|
52
|
+
β βββββββββββββ¬βββββββββββββ β
|
|
53
|
+
β β β
|
|
54
|
+
β drift-guard rules β
|
|
55
|
+
β β β
|
|
56
|
+
β ββββββββ ββββββββ ββββββββ ββββββββ ββββββββ β
|
|
57
|
+
β β.cur- β βCLAU- β βAGEN- β βcopi- β β.cli- β β
|
|
58
|
+
β βsor- β βDE.md β βTS.md β βlot β βne- β β
|
|
59
|
+
β βrules β β β β β βinst. β βrules β β
|
|
60
|
+
β ββββββββ ββββββββ ββββββββ ββββββββ ββββββββ β
|
|
61
|
+
β β
|
|
62
|
+
β AI agents now KNOW your design is protected π‘οΈ β
|
|
63
|
+
βββββββββββββββββββββββββββββββββββββββββββββββββββ
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
## Quick Start
|
|
67
|
+
|
|
68
|
+
### 1. Initialize (lock your design)
|
|
69
|
+
|
|
70
|
+
```bash
|
|
71
|
+
# Scan your project's CSS files
|
|
72
|
+
npx drift-guard init
|
|
73
|
+
|
|
74
|
+
# Or lock from a Stitch/HTML export
|
|
75
|
+
npx drift-guard init --from design.html
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
### 2. Generate AI protection rules
|
|
79
|
+
|
|
80
|
+
```bash
|
|
81
|
+
# Generate rules for ALL AI tools
|
|
82
|
+
npx drift-guard rules
|
|
83
|
+
|
|
84
|
+
# Or for a specific tool
|
|
85
|
+
npx drift-guard rules --format cursorrules
|
|
86
|
+
npx drift-guard rules --format claude-md
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
This creates rule files that tell AI agents: *"Don't touch these design tokens."*
|
|
90
|
+
|
|
91
|
+
### 3. Check for drift after AI changes
|
|
92
|
+
|
|
93
|
+
```bash
|
|
94
|
+
# Check if design tokens were changed
|
|
95
|
+
npx drift-guard check
|
|
96
|
+
|
|
97
|
+
# Set custom threshold (default: 10%)
|
|
98
|
+
npx drift-guard check --threshold 5
|
|
99
|
+
|
|
100
|
+
# JSON output for CI
|
|
101
|
+
npx drift-guard check --output json
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
### 4. Update snapshot (after intentional design changes)
|
|
105
|
+
|
|
106
|
+
```bash
|
|
107
|
+
npx drift-guard snapshot update
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
## What Gets Protected
|
|
111
|
+
|
|
112
|
+
| Category | Properties | Example |
|
|
113
|
+
|----------|-----------|---------|
|
|
114
|
+
| π¨ Colors | `color`, `background-color`, `border-color`, CSS variables | `--primary: #1a73e8` |
|
|
115
|
+
| π Fonts | `font-family`, `font-size`, `font-weight`, `line-height` | `font-family: Inter` |
|
|
116
|
+
| π Spacing | `margin`, `padding`, `gap` | `padding: 16px 24px` |
|
|
117
|
+
| π«οΈ Shadows | `box-shadow`, `text-shadow` | `box-shadow: 0 4px 6px rgba(0,0,0,0.1)` |
|
|
118
|
+
| β Radius | `border-radius` | `border-radius: 8px` |
|
|
119
|
+
| π Layout | `display`, `flex-direction`, `justify-content`, `align-items` | `display: flex` |
|
|
120
|
+
|
|
121
|
+
## Supported AI Tools
|
|
122
|
+
|
|
123
|
+
drift-guard generates protection rules for:
|
|
124
|
+
|
|
125
|
+
- **Cursor** β `.cursorrules`
|
|
126
|
+
- **Claude Code** β `CLAUDE.md`
|
|
127
|
+
- **Codex / Gemini** β `AGENTS.md`
|
|
128
|
+
- **GitHub Copilot** β `.github/copilot-instructions.md`
|
|
129
|
+
- **Cline** β `.clinerules`
|
|
130
|
+
|
|
131
|
+
## CI/CD Integration
|
|
132
|
+
|
|
133
|
+
```yaml
|
|
134
|
+
# .github/workflows/design-guard.yml
|
|
135
|
+
name: Design Guard
|
|
136
|
+
on: [pull_request]
|
|
137
|
+
jobs:
|
|
138
|
+
check-drift:
|
|
139
|
+
runs-on: ubuntu-latest
|
|
140
|
+
steps:
|
|
141
|
+
- uses: actions/checkout@v4
|
|
142
|
+
- uses: actions/setup-node@v4
|
|
143
|
+
with:
|
|
144
|
+
node-version: '20'
|
|
145
|
+
- run: npx drift-guard check --ci
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
## Configuration
|
|
149
|
+
|
|
150
|
+
After `drift-guard init`, config is stored in `.design-guard/config.json`:
|
|
151
|
+
|
|
152
|
+
```json
|
|
153
|
+
{
|
|
154
|
+
"cssFiles": ["src/**/*.css", "app/**/*.css"],
|
|
155
|
+
"htmlFiles": ["**/*.html"],
|
|
156
|
+
"threshold": 10,
|
|
157
|
+
"trackCategories": ["color", "font", "spacing", "shadow", "radius", "layout"],
|
|
158
|
+
"ignore": ["node_modules/**", "dist/**"]
|
|
159
|
+
}
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
## Programmatic API
|
|
163
|
+
|
|
164
|
+
```typescript
|
|
165
|
+
import { createSnapshot, detectDrift, generateRules } from 'drift-guard';
|
|
166
|
+
|
|
167
|
+
// Create a snapshot
|
|
168
|
+
const snapshot = await createSnapshot('./my-project');
|
|
169
|
+
|
|
170
|
+
// Detect drift
|
|
171
|
+
const report = await detectDrift('./my-project', snapshot, 10);
|
|
172
|
+
console.log(`Drift score: ${report.driftScore}%`);
|
|
173
|
+
|
|
174
|
+
// Generate rules
|
|
175
|
+
const rules = generateRules(snapshot, 'claude-md');
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
## Why Not Visual Regression Testing?
|
|
179
|
+
|
|
180
|
+
| Feature | drift-guard | BackstopJS / Percy |
|
|
181
|
+
|---------|-------------|-------------------|
|
|
182
|
+
| **When** | Before commit (pre-commit) | After deploy (QA) |
|
|
183
|
+
| **What** | Design tokens (code-level) | Screenshots (pixel-level) |
|
|
184
|
+
| **AI-aware** | β
Generates agent rules | β No AI integration |
|
|
185
|
+
| **Speed** | < 1 second | Minutes (browser rendering) |
|
|
186
|
+
| **Dependencies** | Zero (no browser) | Headless Chrome required |
|
|
187
|
+
| **Cost** | Free, forever | Percy: $99+/mo for teams |
|
|
188
|
+
|
|
189
|
+
## Philosophy
|
|
190
|
+
|
|
191
|
+
> AI should **add features**, not **destroy design**.
|
|
192
|
+
|
|
193
|
+
drift-guard doesn't fight AI β it teaches AI where the boundaries are. Your design tokens are the constitution. AI agents follow the law.
|
|
194
|
+
|
|
195
|
+
## Contributing
|
|
196
|
+
|
|
197
|
+
Contributions welcome! See [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines.
|
|
198
|
+
|
|
199
|
+
## License
|
|
200
|
+
|
|
201
|
+
MIT Β© drift-guard contributors
|