@lifeonlars/prime-yggdrasil 0.2.5 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -158,13 +158,29 @@ npm run build
158
158
 
159
159
  ### Scripts
160
160
  ```bash
161
- npm run dev # Start Storybook
162
- npm run build # Build library
163
- npm run test:contrast # Test color contrast
161
+ npm run storybook # Start Storybook development server
162
+ npm run build # Build library package
163
+ npm run build-storybook # Build static Storybook for deployment
164
+ npm run test:contrast # Test color contrast (APCA)
164
165
  npm run test:themes # Validate theme structure
166
+ npm run lint # Lint TypeScript/JavaScript
165
167
  npm run lint:css # Lint CSS files
168
+ npm run chromatic # Run visual regression tests
166
169
  ```
167
170
 
171
+ ### Testing
172
+
173
+ **Storybook Built-in Testing:**
174
+ - **Play functions** - Interactive tests run automatically when viewing stories
175
+ - **Accessibility tests** - `@storybook/addon-a11y` checks components for a11y violations
176
+ - **Visual regression** - Chromatic integration for catching visual changes
177
+
178
+ **CI/CD Pipeline:**
179
+ - GitHub Actions runs on every push/PR
180
+ - Validates linting, builds, and accessibility
181
+ - Chromatic visual regression testing (on push to main/master)
182
+ - See [`.github/workflows/ci.yml`](.github/workflows/ci.yml) for details
183
+
168
184
  ## 📊 Project Stats
169
185
 
170
186
  - **Semantic Tokens**: 727 color replacements (96% coverage)
@@ -173,25 +189,152 @@ npm run lint:css # Lint CSS files
173
189
  - **Contrast**: WCAG 3.0 (APCA) validated
174
190
  - **Dark Mode**: Optimized shadows with white rim strategy
175
191
 
176
- ## 🤖 AI Agent Integration
192
+ ## 🤖 AI Agent Infrastructure
193
+
194
+ Yggdrasil includes **6 specialized AI agents** that prevent drift, guide composition, and enforce design system compliance.
195
+
196
+ ### 🚀 Quick Start: Initialize Agents
197
+
198
+ ```bash
199
+ npx @lifeonlars/prime-yggdrasil init
200
+ ```
201
+
202
+ This copies 4 active agents + 2 future specs to your project's `.ai/yggdrasil/` directory.
203
+
204
+ ### 📋 The 6 Agents
205
+
206
+ #### Active Agents (Phase 1-4 Complete)
207
+
208
+ 1. **Block Composer** - Composition-first UI planning
209
+ - Prevents bespoke component creation
210
+ - Suggests PrimeReact components + existing Blocks
211
+ - Specifies all 5+ states (default, hover, focus, active, disabled)
212
+
213
+ 2. **PrimeFlex Guard** - Layout constraint enforcement
214
+ - Allows PrimeFlex for layout/spacing ONLY (not design)
215
+ - Critical rule: NO PrimeFlex on PrimeReact components (except `w-full` on inputs)
216
+ - Maintains 4px grid discipline
217
+
218
+ 3. **Semantic Token Intent** - State-complete token selection
219
+ - Ensures all states defined (default, hover, focus, active, disabled)
220
+ - Validates token pairings work in light/dark modes
221
+ - Prevents hardcoded colors and foundation tokens in app code
222
+
223
+ 4. **Drift Validator** - Comprehensive policy enforcement
224
+ - 7 core rules (no hardcoded colors, no PrimeFlex on components, etc.)
225
+ - ESLint plugin + CLI validation
226
+ - Autofix capability for safe violations
227
+
228
+ #### Future Agents (Phase 6 Specs Ready)
229
+
230
+ 5. **Interaction Patterns** *(specification complete)*
231
+ - Standardizes empty/loading/error/success patterns
232
+ - Enforces keyboard navigation and focus management
233
+ - Ensures copy is clear, pragmatic, non-fluffy
234
+
235
+ 6. **Accessibility** *(specification complete)*
236
+ - WCAG 2.1 AA minimum compliance
237
+ - Contrast ratio validation
238
+ - Ensures color is not the only cue (icons, text, patterns)
239
+ - Validates ARIA and semantic HTML
240
+
241
+ ### 🛠️ Agent Tools
242
+
243
+ **ESLint Plugin** (Phase 3)
244
+ ```bash
245
+ npm install --save-dev @lifeonlars/eslint-plugin-yggdrasil
246
+ ```
247
+
248
+ ```js
249
+ // eslint.config.js
250
+ import yggdrasil from '@lifeonlars/eslint-plugin-yggdrasil';
251
+
252
+ export default [
253
+ {
254
+ plugins: { '@lifeonlars/yggdrasil': yggdrasil },
255
+ rules: yggdrasil.configs.recommended.rules // Warnings for adoption
256
+ // Or: yggdrasil.configs.strict.rules // Errors for enforcement
257
+ }
258
+ ];
259
+ ```
260
+
261
+ **CLI Validation** (Phase 4)
262
+ ```bash
263
+ # Report-only validation
264
+ npx @lifeonlars/prime-yggdrasil validate
265
+
266
+ # Detailed audit with recommendations
267
+ npx @lifeonlars/prime-yggdrasil audit
268
+
269
+ # Apply automatic fixes
270
+ npx @lifeonlars/prime-yggdrasil audit --fix
271
+
272
+ # JSON output for CI/CD
273
+ npx @lifeonlars/prime-yggdrasil validate --format json
274
+ ```
275
+
276
+ ### 📖 Agent Documentation
277
+
278
+ **For Consumers:**
279
+ - [`.ai/yggdrasil/README.md`](./.ai/agents/README.md) - Quick start guide (copied to your project)
280
+ - [`docs/AESTHETICS.md`](./docs/AESTHETICS.md) - Mandatory aesthetic principles reference
281
+ - [`docs/PRIMEFLEX-POLICY.md`](./docs/PRIMEFLEX-POLICY.md) - Complete PrimeFlex allowlist
282
+
283
+ **For Agent Developers:**
284
+ - [`.ai/agents/block-composer.md`](./.ai/agents/block-composer.md) - Composition planning
285
+ - [`.ai/agents/primeflex-guard.md`](./.ai/agents/primeflex-guard.md) - Layout constraints
286
+ - [`.ai/agents/semantic-token-intent.md`](./.ai/agents/semantic-token-intent.md) - Token selection
287
+ - [`.ai/agents/drift-validator.md`](./.ai/agents/drift-validator.md) - Policy enforcement
288
+ - [`.ai/agents/interaction-patterns.md`](./.ai/agents/interaction-patterns.md) - Behavioral patterns *(future)*
289
+ - [`.ai/agents/accessibility.md`](./.ai/agents/accessibility.md) - WCAG compliance *(future)*
290
+
291
+ ### 🎯 Agent Workflow Example
292
+
293
+ **Implementing a User Profile Form:**
294
+
295
+ 1. **Block Composer** - "Use `<Card>` + `<InputText>` + `<Button>`. Specify loading/empty/error states."
296
+ 2. **PrimeFlex Guard** - "Use `flex flex-column gap-3 p-4` for layout. NO `bg-*` or `rounded-*` utilities."
297
+ 3. **Semantic Token Intent** - "Use `var(--surface-neutral-primary)` for card, `var(--text-neutral-default)` for labels."
298
+ 4. **Drift Validator** - "✅ No violations. All rules passing."
299
+
300
+ ### 🔧 Dual Enforcement Strategy
301
+
302
+ **Prevention (Agents guide before code is written)**
303
+ - Block Composer prevents bespoke UI
304
+ - PrimeFlex Guard prevents utility chaos
305
+ - Semantic Token Intent prevents styling violations
306
+
307
+ **Detection (ESLint + CLI catch violations after)**
308
+ - ESLint: Code-time detection in IDE (fast feedback)
309
+ - CLI: Runtime validation with deeper analysis (pre-commit, CI/CD)
310
+
311
+ ### 🚀 Migration Path
312
+
313
+ 1. **Week 1**: Install update, run `npx @lifeonlars/prime-yggdrasil init`
314
+ 2. **Week 2**: Read agent documentation in `.ai/yggdrasil/`
315
+ 3. **Week 3**: Install ESLint plugin (`recommended` config - warnings only)
316
+ 4. **Week 4**: Run `yggdrasil audit` on existing code, apply fixes incrementally
317
+ 5. **Week 5+**: Switch to ESLint `strict` config (errors) for new code
318
+
319
+ ### 📊 Enforcement Stats
177
320
 
178
- Yggdrasil is specifically designed to guide AI agents toward component-driven development:
321
+ - **7 ESLint Rules** - Warnings (recommended) or errors (strict)
322
+ - **5 CLI Validation Rules** - Report-only or autofix mode
323
+ - **4 Active Agents** - Guidance during development
324
+ - **2 Future Agents** - Specifications ready for Phase 6
179
325
 
180
- 1. **Comprehensive Documentation** - AI agents can read [AI-AGENT-GUIDE.md](./docs/AI-AGENT-GUIDE.md)
181
- 2. **Decision Trees** - Step-by-step component selection guidance
182
- 3. **Token Reference** - Quick lookup for semantic tokens
183
- 4. **Anti-Patterns** - Clear examples of what NOT to do
184
- 5. **Validation Rules** - Optional ESLint/pre-commit hooks
326
+ ### Example AI Prompt (with Agents)
185
327
 
186
- ### Example AI Prompt
187
328
  ```
188
329
  I'm building a React app with Yggdrasil design system.
189
330
 
190
331
  Before implementing UI:
191
- 1. Read: node_modules/@lifeonlars/prime-yggdrasil/docs/AI-AGENT-GUIDE.md
192
- 2. Check: Is there a PrimeReact component for this?
193
- 3. Use: Semantic tokens only (no hardcoded colors)
194
- 4. Follow: 4px grid for all spacing
332
+ 1. Read: .ai/yggdrasil/block-composer.md
333
+ 2. Read: docs/AESTHETICS.md (mandatory reference)
334
+ 3. Check: Is there a PrimeReact component for this?
335
+ 4. Use: Semantic tokens only (no hardcoded colors)
336
+ 5. Follow: 4px grid for all spacing
337
+ 6. Validate: Run `yggdrasil audit` before committing
195
338
 
196
339
  Create a user profile form with name, email, and submit button.
197
340
  ```
@@ -0,0 +1,134 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * Yggdrasil CLI - Design System Agent Infrastructure
5
+ *
6
+ * Commands:
7
+ * init - Initialize Yggdrasil agents in your project
8
+ * validate - Validate code against design system rules (Phase 4)
9
+ * audit - Detailed audit with autofix suggestions (Phase 4)
10
+ */
11
+
12
+ import { fileURLToPath } from 'url';
13
+ import { dirname, join } from 'path';
14
+ import { existsSync } from 'fs';
15
+
16
+ const __filename = fileURLToPath(import.meta.url);
17
+ const __dirname = dirname(__filename);
18
+
19
+ const args = process.argv.slice(2);
20
+ const command = args[0];
21
+
22
+ // Parse command-line arguments
23
+ function parseArgs(args) {
24
+ const options = {};
25
+ for (let i = 1; i < args.length; i++) {
26
+ const arg = args[i];
27
+ if (arg === '--fix') {
28
+ options.fix = true;
29
+ } else if (arg === '--format') {
30
+ options.format = args[++i];
31
+ } else if (arg === '--rules') {
32
+ options.rules = args[++i];
33
+ } else if (arg.startsWith('--')) {
34
+ // Skip unknown options
35
+ console.warn(`⚠️ Unknown option: ${arg}`);
36
+ }
37
+ }
38
+ return options;
39
+ }
40
+
41
+ async function main() {
42
+ const options = parseArgs(args);
43
+
44
+ switch (command) {
45
+ case 'init':
46
+ const { initCommand } = await import('../commands/init.js');
47
+ await initCommand();
48
+ break;
49
+
50
+ case 'validate':
51
+ const { validateCommand } = await import('../commands/validate.js');
52
+ await validateCommand(options);
53
+ break;
54
+
55
+ case 'audit':
56
+ const { auditCommand } = await import('../commands/audit.js');
57
+ await auditCommand(options);
58
+ break;
59
+
60
+ case '--version':
61
+ case '-v':
62
+ const packageJsonPath = join(__dirname, '../../package.json');
63
+ if (existsSync(packageJsonPath)) {
64
+ const pkg = await import(packageJsonPath, { assert: { type: 'json' } });
65
+ console.log(pkg.default.version);
66
+ }
67
+ break;
68
+
69
+ case '--help':
70
+ case '-h':
71
+ case undefined:
72
+ printHelp();
73
+ break;
74
+
75
+ default:
76
+ console.error(`❌ Unknown command: ${command}`);
77
+ console.log('');
78
+ printHelp();
79
+ process.exit(1);
80
+ }
81
+ }
82
+
83
+ function printHelp() {
84
+ console.log(`
85
+ 🌳 Yggdrasil CLI - AI-Agent-Friendly Design System
86
+
87
+ Usage:
88
+ npx @lifeonlars/prime-yggdrasil <command> [options]
89
+
90
+ Commands:
91
+ init Initialize Yggdrasil agents in your project
92
+ validate Validate code against design system rules
93
+ audit Detailed audit with autofix suggestions
94
+
95
+ Options:
96
+ -h, --help Show this help message
97
+ -v, --version Show version number
98
+
99
+ Validate/Audit Options:
100
+ --format <type> Output format: cli (default), json, markdown
101
+ --rules <list> Comma-separated list of rules to check
102
+ --fix Apply automatic fixes (audit only)
103
+
104
+ Examples:
105
+ # Initialize agents in your project
106
+ npx @lifeonlars/prime-yggdrasil init
107
+
108
+ # Validate code (report-only)
109
+ npx @lifeonlars/prime-yggdrasil validate
110
+
111
+ # Detailed audit with recommendations
112
+ npx @lifeonlars/prime-yggdrasil audit
113
+
114
+ # Audit with automatic fixes
115
+ npx @lifeonlars/prime-yggdrasil audit --fix
116
+
117
+ # Validate specific rules only
118
+ npx @lifeonlars/prime-yggdrasil validate --rules no-tailwind,no-hardcoded-colors
119
+
120
+ # Output as JSON for CI/CD integration
121
+ npx @lifeonlars/prime-yggdrasil validate --format json
122
+
123
+ # Generate markdown report
124
+ npx @lifeonlars/prime-yggdrasil audit --format markdown > audit-report.md
125
+
126
+ Documentation:
127
+ https://github.com/lifeonlars/prime-yggdrasil#readme
128
+ `);
129
+ }
130
+
131
+ main().catch((error) => {
132
+ console.error('❌ Error:', error.message);
133
+ process.exit(1);
134
+ });