@lifeonlars/prime-yggdrasil 0.2.6 → 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.md CHANGED
@@ -189,25 +189,151 @@ npm run chromatic # Run visual regression tests
189
189
  - **Contrast**: WCAG 3.0 (APCA) validated
190
190
  - **Dark Mode**: Optimized shadows with white rim strategy
191
191
 
192
- ## 🤖 AI Agent Integration
192
+ ## 🤖 AI Agent Infrastructure
193
193
 
194
- Yggdrasil is specifically designed to guide AI agents toward component-driven development:
194
+ Yggdrasil includes **6 specialized AI agents** that prevent drift, guide composition, and enforce design system compliance.
195
195
 
196
- 1. **Comprehensive Documentation** - AI agents can read [AI-AGENT-GUIDE.md](./docs/AI-AGENT-GUIDE.md)
197
- 2. **Decision Trees** - Step-by-step component selection guidance
198
- 3. **Token Reference** - Quick lookup for semantic tokens
199
- 4. **Anti-Patterns** - Clear examples of what NOT to do
200
- 5. **Validation Rules** - Optional ESLint/pre-commit hooks
196
+ ### 🚀 Quick Start: Initialize Agents
197
+
198
+ ```bash
199
+ npx @lifeonlars/prime-yggdrasil init
200
+ ```
201
+
202
+ This copies all 6 active agents to your project's `.ai/yggdrasil/` directory.
203
+
204
+ ### 📋 The 6 Agents
205
+
206
+ #### Active Agents (All 6 Complete - Phase 6 ✅)
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
+ 5. **Interaction Patterns** - Behavioral consistency *(Phase 6 - NEW ✨)*
229
+ - Enforces state completeness (loading/error/empty/disabled)
230
+ - Detects generic copy (button labels, messages)
231
+ - Validates focus management (Dialog/Modal patterns)
232
+ - Ensures keyboard navigation works correctly
233
+
234
+ 6. **Accessibility** - WCAG 2.1 AA compliance *(Phase 6 - NEW ✨)*
235
+ - Validates alt text on images and icon-only buttons
236
+ - Enforces proper form label associations (htmlFor/id)
237
+ - Checks contrast ratios for text/surface combinations
238
+ - Ensures color is not the only cue (icons, text, patterns)
239
+
240
+ ### 🛠️ Agent Tools
241
+
242
+ **ESLint Plugin** (Phase 3)
243
+ ```bash
244
+ npm install --save-dev @lifeonlars/eslint-plugin-yggdrasil
245
+ ```
246
+
247
+ ```js
248
+ // eslint.config.js
249
+ import yggdrasil from '@lifeonlars/eslint-plugin-yggdrasil';
250
+
251
+ export default [
252
+ {
253
+ plugins: { '@lifeonlars/yggdrasil': yggdrasil },
254
+ rules: yggdrasil.configs.recommended.rules // Warnings for adoption
255
+ // Or: yggdrasil.configs.strict.rules // Errors for enforcement
256
+ }
257
+ ];
258
+ ```
259
+
260
+ **CLI Validation** (Phase 4)
261
+ ```bash
262
+ # Report-only validation
263
+ npx @lifeonlars/prime-yggdrasil validate
264
+
265
+ # Detailed audit with recommendations
266
+ npx @lifeonlars/prime-yggdrasil audit
267
+
268
+ # Apply automatic fixes
269
+ npx @lifeonlars/prime-yggdrasil audit --fix
270
+
271
+ # JSON output for CI/CD
272
+ npx @lifeonlars/prime-yggdrasil validate --format json
273
+ ```
274
+
275
+ ### 📖 Agent Documentation
276
+
277
+ **For Consumers:**
278
+ - [`.ai/yggdrasil/README.md`](./.ai/agents/README.md) - Quick start guide (copied to your project)
279
+ - [`docs/AESTHETICS.md`](./docs/AESTHETICS.md) - Mandatory aesthetic principles reference
280
+ - [`docs/PRIMEFLEX-POLICY.md`](./docs/PRIMEFLEX-POLICY.md) - Complete PrimeFlex allowlist
281
+
282
+ **For Agent Developers:**
283
+ - [`.ai/agents/block-composer.md`](./.ai/agents/block-composer.md) - Composition planning
284
+ - [`.ai/agents/primeflex-guard.md`](./.ai/agents/primeflex-guard.md) - Layout constraints
285
+ - [`.ai/agents/semantic-token-intent.md`](./.ai/agents/semantic-token-intent.md) - Token selection
286
+ - [`.ai/agents/drift-validator.md`](./.ai/agents/drift-validator.md) - Policy enforcement
287
+ - [`.ai/agents/interaction-patterns.md`](./.ai/agents/interaction-patterns.md) - Behavioral patterns *(future)*
288
+ - [`.ai/agents/accessibility.md`](./.ai/agents/accessibility.md) - WCAG compliance *(future)*
289
+
290
+ ### 🎯 Agent Workflow Example
291
+
292
+ **Implementing a User Profile Form:**
293
+
294
+ 1. **Block Composer** - "Use `<Card>` + `<InputText>` + `<Button>`. Specify loading/empty/error states."
295
+ 2. **PrimeFlex Guard** - "Use `flex flex-column gap-3 p-4` for layout. NO `bg-*` or `rounded-*` utilities."
296
+ 3. **Semantic Token Intent** - "Use `var(--surface-neutral-primary)` for card, `var(--text-neutral-default)` for labels."
297
+ 4. **Drift Validator** - "✅ No violations. All rules passing."
298
+
299
+ ### 🔧 Dual Enforcement Strategy
300
+
301
+ **Prevention (Agents guide before code is written)**
302
+ - Block Composer prevents bespoke UI
303
+ - PrimeFlex Guard prevents utility chaos
304
+ - Semantic Token Intent prevents styling violations
305
+
306
+ **Detection (ESLint + CLI catch violations after)**
307
+ - ESLint: Code-time detection in IDE (fast feedback)
308
+ - CLI: Runtime validation with deeper analysis (pre-commit, CI/CD)
309
+
310
+ ### 🚀 Migration Path
311
+
312
+ 1. **Week 1**: Install update, run `npx @lifeonlars/prime-yggdrasil init`
313
+ 2. **Week 2**: Read agent documentation in `.ai/yggdrasil/`
314
+ 3. **Week 3**: Install ESLint plugin (`recommended` config - warnings only)
315
+ 4. **Week 4**: Run `yggdrasil audit` on existing code, apply fixes incrementally
316
+ 5. **Week 5+**: Switch to ESLint `strict` config (errors) for new code
317
+
318
+ ### 📊 Enforcement Stats
319
+
320
+ - **12 CLI Validation Rules** - 7 core + 5 Phase 6 (Interaction Patterns + Accessibility)
321
+ - **6 Active Agents** - All agents operational (Phase 6 complete ✅)
322
+ - **Autofix Support** - State completeness, alt text, form labels, focus management
323
+ - **WCAG 2.1 AA** - Automated accessibility validation
324
+
325
+ ### Example AI Prompt (with Agents)
201
326
 
202
- ### Example AI Prompt
203
327
  ```
204
328
  I'm building a React app with Yggdrasil design system.
205
329
 
206
330
  Before implementing UI:
207
- 1. Read: node_modules/@lifeonlars/prime-yggdrasil/docs/AI-AGENT-GUIDE.md
208
- 2. Check: Is there a PrimeReact component for this?
209
- 3. Use: Semantic tokens only (no hardcoded colors)
210
- 4. Follow: 4px grid for all spacing
331
+ 1. Read: .ai/yggdrasil/block-composer.md
332
+ 2. Read: docs/AESTHETICS.md (mandatory reference)
333
+ 3. Check: Is there a PrimeReact component for this?
334
+ 4. Use: Semantic tokens only (no hardcoded colors)
335
+ 5. Follow: 4px grid for all spacing
336
+ 6. Validate: Run `yggdrasil audit` before committing
211
337
 
212
338
  Create a user profile form with name, email, and submit button.
213
339
  ```
@@ -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
+ });