@lifeonlars/prime-yggdrasil 0.2.6 → 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
@@ -189,25 +189,152 @@ 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 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
320
+
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
325
+
326
+ ### Example AI Prompt (with Agents)
201
327
 
202
- ### Example AI Prompt
203
328
  ```
204
329
  I'm building a React app with Yggdrasil design system.
205
330
 
206
331
  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
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
211
338
 
212
339
  Create a user profile form with name, email, and submit button.
213
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
+ });