@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.
@@ -0,0 +1,456 @@
1
+ # Phase 6 Implementation Plan: Interaction Patterns & Accessibility Agents
2
+
3
+ **Goal:** Integrate Interaction Patterns and Accessibility agents into active enforcement (CLI validation + ESLint plugin)
4
+
5
+ **Status:** 🚀 In Progress
6
+ **Timeline:** 3-4 weeks
7
+ **Current Version:** 0.3.0 → Target: 0.4.0
8
+
9
+ ---
10
+
11
+ ## Overview
12
+
13
+ Phase 6 activates the final 2 agents from specification to enforcement:
14
+
15
+ 1. **Interaction Patterns Agent** - Behavioral consistency (empty/loading/error, form validation, confirmations, focus management)
16
+ 2. **Accessibility Agent** - WCAG 2.1 AA compliance (contrast, ARIA, keyboard navigation, semantic HTML)
17
+
18
+ Both agents currently have complete specifications (`.ai/agents/*.md`) but are marked as "future" and not yet integrated into CLI/ESLint validation.
19
+
20
+ ---
21
+
22
+ ## Implementation Strategy
23
+
24
+ ### Dual Integration Approach
25
+
26
+ **CLI Validation Rules** (Deeper Analysis)
27
+ - State completeness checks (loading/empty/error/disabled states)
28
+ - Copy tone analysis (generic vs. specific button labels)
29
+ - Contrast ratio validation (APCA calculations)
30
+ - ARIA attribute validation
31
+ - Keyboard navigation patterns
32
+
33
+ **ESLint Rules** (Code-Time Detection)
34
+ - Missing state handlers (no loading/error states)
35
+ - Generic copy patterns (`label="Submit"`, `label="OK"`)
36
+ - Missing ARIA labels on icon-only buttons
37
+ - Color-only indicators (no icon/text fallback)
38
+ - Invalid focus management
39
+
40
+ ---
41
+
42
+ ## Phase 6 Breakdown
43
+
44
+ ### Week 1: CLI Validation Rules (Interaction Patterns)
45
+
46
+ **Goal:** Add 5 interaction pattern validation rules to CLI
47
+
48
+ **Rules to Implement:**
49
+
50
+ 1. **`interaction-patterns/state-completeness`**
51
+ - Detects missing states in async operations
52
+ - Checks for: loading, error, empty states
53
+ - Example violation: `<DataTable value={data} />` without loading/error handling
54
+
55
+ 2. **`interaction-patterns/generic-copy`**
56
+ - Detects generic button labels ("Submit", "OK", "Cancel")
57
+ - Suggests specific alternatives ("Save Changes", "Delete Item")
58
+ - Example violation: `<Button label="Submit" />`
59
+
60
+ 3. **`interaction-patterns/confirmation-overuse`**
61
+ - Flags confirmations on non-destructive actions
62
+ - Example violation: `confirm('Save changes?')`
63
+
64
+ 4. **`interaction-patterns/feedback-mechanism`**
65
+ - Validates Toast vs Message vs Banner usage
66
+ - Checks for appropriate duration and severity
67
+ - Example violation: Using Toast for persistent errors
68
+
69
+ 5. **`interaction-patterns/focus-management`**
70
+ - Validates Dialog/Modal focus patterns
71
+ - Checks for autoFocus on first field
72
+ - Example violation: Dialog without focus management
73
+
74
+ **Implementation Files:**
75
+ - `cli/rules/interaction-patterns/state-completeness.js`
76
+ - `cli/rules/interaction-patterns/generic-copy.js`
77
+ - `cli/rules/interaction-patterns/confirmation-overuse.js`
78
+ - `cli/rules/interaction-patterns/feedback-mechanism.js`
79
+ - `cli/rules/interaction-patterns/focus-management.js`
80
+
81
+ ---
82
+
83
+ ### Week 2: CLI Validation Rules (Accessibility)
84
+
85
+ **Goal:** Add 6 accessibility validation rules to CLI
86
+
87
+ **Rules to Implement:**
88
+
89
+ 1. **`accessibility/missing-alt-text`**
90
+ - Detects images without alt attributes
91
+ - Checks icon-only buttons for aria-label
92
+ - Example violation: `<img src="chart.png" />`
93
+
94
+ 2. **`accessibility/contrast-ratio`**
95
+ - Validates text/surface contrast ratios (APCA)
96
+ - Minimum: 4.5:1 (normal text), 3:1 (large text)
97
+ - Example violation: Light gray text on white background
98
+
99
+ 3. **`accessibility/color-only-indicator`**
100
+ - Detects status indicators using only color
101
+ - Suggests adding icons/text
102
+ - Example violation: `<span style={{color: 'red'}}>Error</span>`
103
+
104
+ 4. **`accessibility/missing-form-labels`**
105
+ - Detects form inputs without labels
106
+ - Validates htmlFor/id associations
107
+ - Example violation: `<InputText />` without label
108
+
109
+ 5. **`accessibility/keyboard-navigation`**
110
+ - Validates interactive elements are keyboard accessible
111
+ - Checks for onClick without onKeyDown on divs
112
+ - Example violation: `<div onClick={handleClick}>Click</div>`
113
+
114
+ 6. **`accessibility/aria-validation`**
115
+ - Validates ARIA attributes and roles
116
+ - Checks for aria-describedby/aria-invalid on errors
117
+ - Example violation: Error message not linked to input
118
+
119
+ **Implementation Files:**
120
+ - `cli/rules/accessibility/missing-alt-text.js`
121
+ - `cli/rules/accessibility/contrast-ratio.js`
122
+ - `cli/rules/accessibility/color-only-indicator.js`
123
+ - `cli/rules/accessibility/missing-form-labels.js`
124
+ - `cli/rules/accessibility/keyboard-navigation.js`
125
+ - `cli/rules/accessibility/aria-validation.js`
126
+
127
+ ---
128
+
129
+ ### Week 3: ESLint Plugin Rules
130
+
131
+ **Goal:** Create ESLint rules for code-time detection
132
+
133
+ **ESLint Rules (11 New Rules):**
134
+
135
+ **Interaction Patterns (5 rules):**
136
+ - `@lifeonlars/yggdrasil/interaction-patterns/require-states` - Enforce state completeness
137
+ - `@lifeonlars/yggdrasil/interaction-patterns/no-generic-copy` - Ban generic button labels
138
+ - `@lifeonlars/yggdrasil/interaction-patterns/no-unnecessary-confirm` - Prevent confirmation overuse
139
+ - `@lifeonlars/yggdrasil/interaction-patterns/feedback-pattern` - Validate Toast/Message/Banner usage
140
+ - `@lifeonlars/yggdrasil/interaction-patterns/focus-trap` - Validate Dialog focus management
141
+
142
+ **Accessibility (6 rules):**
143
+ - `@lifeonlars/yggdrasil/accessibility/require-alt` - Enforce alt text on images
144
+ - `@lifeonlars/yggdrasil/accessibility/icon-button-label` - Require aria-label on icon-only buttons
145
+ - `@lifeonlars/yggdrasil/accessibility/color-cue` - Prevent color-only indicators
146
+ - `@lifeonlars/yggdrasil/accessibility/form-label` - Require labels on form inputs
147
+ - `@lifeonlars/yggdrasil/accessibility/keyboard-handler` - Require keyboard handlers on interactive divs
148
+ - `@lifeonlars/yggdrasil/accessibility/aria-describedby` - Link error messages to inputs
149
+
150
+ **Implementation Files:**
151
+ - `eslint-plugin-yggdrasil/rules/interaction-patterns/*.js` (5 files)
152
+ - `eslint-plugin-yggdrasil/rules/accessibility/*.js` (6 files)
153
+ - Update `eslint-plugin-yggdrasil/configs/recommended.js` (add rules as warnings)
154
+ - Update `eslint-plugin-yggdrasil/configs/strict.js` (add rules as errors)
155
+
156
+ ---
157
+
158
+ ### Week 4: Integration & Documentation
159
+
160
+ **Tasks:**
161
+
162
+ 1. **Update Agent Status**
163
+ - Change status from "🚧 Phase 6 (Future)" to "✅ Active"
164
+ - Update `.ai/agents/interaction-patterns.md`
165
+ - Update `.ai/agents/accessibility.md`
166
+
167
+ 2. **Update README.md**
168
+ - Move Interaction Patterns and Accessibility to "Active Agents" section
169
+ - Update enforcement stats (18 ESLint rules, 16 CLI validation rules)
170
+ - Add Phase 6 completion notice
171
+
172
+ 3. **Update AESTHETICS.md**
173
+ - Change agent status from "(future)" to active
174
+ - Update enforcement stats
175
+
176
+ 4. **Create Testing Guide**
177
+ - `docs/TESTING-GUIDE.md` - How to test interaction patterns and accessibility
178
+ - Include manual testing checklists
179
+ - Add automated testing examples
180
+
181
+ 5. **Update CLI Help**
182
+ - Add new rule descriptions to `--help` output
183
+ - Update examples with new rules
184
+
185
+ 6. **Create Migration Guide**
186
+ - `docs/PHASE-6-MIGRATION.md` - How to adopt new rules
187
+ - Include autofix strategies
188
+ - Add common violations and fixes
189
+
190
+ ---
191
+
192
+ ## Technical Implementation Details
193
+
194
+ ### CLI Validation Architecture
195
+
196
+ **Rule Structure:**
197
+ ```javascript
198
+ // cli/rules/interaction-patterns/state-completeness.js
199
+ export default {
200
+ name: 'interaction-patterns/state-completeness',
201
+ description: 'Enforce state completeness (loading/error/empty/disabled)',
202
+ category: 'interaction-patterns',
203
+ severity: 'warning',
204
+
205
+ validate(fileContent, filePath) {
206
+ const violations = [];
207
+
208
+ // AST parsing to detect async operations without state handling
209
+ // Check for: useEffect, fetch, axios, async functions
210
+ // Ensure: loading state, error state, empty state
211
+
212
+ return violations;
213
+ },
214
+
215
+ autofix(fileContent, violation) {
216
+ // Generate boilerplate state handling code
217
+ return {
218
+ fixed: true,
219
+ content: updatedContent,
220
+ message: 'Added loading/error/empty state handling'
221
+ };
222
+ }
223
+ };
224
+ ```
225
+
226
+ **Validation Engine Updates:**
227
+ ```javascript
228
+ // cli/commands/validate.js
229
+ import interactionPatternsRules from '../rules/interaction-patterns/index.js';
230
+ import accessibilityRules from '../rules/accessibility/index.js';
231
+
232
+ const allRules = {
233
+ ...existingRules,
234
+ ...interactionPatternsRules,
235
+ ...accessibilityRules
236
+ };
237
+ ```
238
+
239
+ ### ESLint Rule Architecture
240
+
241
+ **Rule Structure:**
242
+ ```javascript
243
+ // eslint-plugin-yggdrasil/rules/interaction-patterns/no-generic-copy.js
244
+ export default {
245
+ meta: {
246
+ type: 'suggestion',
247
+ docs: {
248
+ description: 'Enforce specific button labels over generic ones',
249
+ category: 'Interaction Patterns',
250
+ recommended: true
251
+ },
252
+ messages: {
253
+ genericLabel: 'Button label "{{label}}" is too generic. Use specific action like "Save Changes" or "Delete Item".'
254
+ },
255
+ schema: []
256
+ },
257
+
258
+ create(context) {
259
+ return {
260
+ JSXOpeningElement(node) {
261
+ if (node.name.name === 'Button') {
262
+ const labelAttr = node.attributes.find(attr => attr.name?.name === 'label');
263
+ if (labelAttr) {
264
+ const labelValue = labelAttr.value.value;
265
+ const genericLabels = ['Submit', 'OK', 'Cancel', 'Continue'];
266
+
267
+ if (genericLabels.includes(labelValue)) {
268
+ context.report({
269
+ node: labelAttr,
270
+ messageId: 'genericLabel',
271
+ data: { label: labelValue }
272
+ });
273
+ }
274
+ }
275
+ }
276
+ }
277
+ };
278
+ }
279
+ };
280
+ ```
281
+
282
+ ### Contrast Validation (APCA Integration)
283
+
284
+ **Implementation:**
285
+ ```javascript
286
+ // cli/rules/accessibility/contrast-ratio.js
287
+ import { APCAcontrast, sRGBtoY } from 'apca-w3';
288
+
289
+ export default {
290
+ name: 'accessibility/contrast-ratio',
291
+
292
+ validate(fileContent, filePath) {
293
+ // Parse CSS custom properties usage
294
+ // Extract color pairings (text on surface)
295
+ // Calculate APCA contrast
296
+ // Flag violations < Lc 60 (body text) or < Lc 75 (subtitles)
297
+
298
+ const violations = [];
299
+ const colorPairings = extractColorPairings(fileContent);
300
+
301
+ colorPairings.forEach(pairing => {
302
+ const contrast = APCAcontrast(
303
+ sRGBtoY(pairing.text),
304
+ sRGBtoY(pairing.surface)
305
+ );
306
+
307
+ if (Math.abs(contrast) < 60) {
308
+ violations.push({
309
+ line: pairing.line,
310
+ message: `Insufficient contrast (Lc ${contrast.toFixed(1)}). Minimum Lc 60 required for body text.`,
311
+ suggestion: `Use higher contrast token pairing`
312
+ });
313
+ }
314
+ });
315
+
316
+ return violations;
317
+ }
318
+ };
319
+ ```
320
+
321
+ ---
322
+
323
+ ## Testing Strategy
324
+
325
+ ### Unit Tests
326
+ - Each CLI rule has comprehensive test suite
327
+ - Each ESLint rule has test cases covering violations and valid patterns
328
+ - Test both light and dark mode scenarios
329
+
330
+ ### Integration Tests
331
+ - CLI validate/audit commands with Phase 6 rules enabled
332
+ - ESLint plugin with recommended/strict configs
333
+ - Autofix capability testing
334
+
335
+ ### Manual Testing
336
+ - Apply rules to sample consumer project
337
+ - Verify violation detection accuracy
338
+ - Test autofix suggestions
339
+ - Validate false positive rate
340
+
341
+ ---
342
+
343
+ ## Success Metrics
344
+
345
+ **Adoption:**
346
+ - Number of Phase 6 rule violations detected in sample projects
347
+ - Autofix success rate
348
+ - Developer feedback on rule usefulness
349
+
350
+ **Code Quality:**
351
+ - Reduction in missing state handlers
352
+ - Reduction in generic copy usage
353
+ - Reduction in accessibility violations
354
+ - Improved WCAG 2.1 AA compliance scores
355
+
356
+ **Developer Experience:**
357
+ - Faster accessibility compliance
358
+ - Clearer interaction pattern guidance
359
+ - Better error messages and suggestions
360
+
361
+ ---
362
+
363
+ ## Risk Mitigation
364
+
365
+ **Risk 1: High False Positive Rate**
366
+ - Mitigation: Conservative rule thresholds in recommended config
367
+ - Start with warnings, not errors
368
+ - Provide clear opt-out mechanism per rule
369
+
370
+ **Risk 2: Performance Impact**
371
+ - Mitigation: Optimize AST parsing and analysis
372
+ - Cache validation results
373
+ - Provide `--rules` flag to run subset of rules
374
+
375
+ **Risk 3: Breaking Changes**
376
+ - Mitigation: Mark as minor version (0.4.0, not 1.0.0)
377
+ - All rules default to warnings in recommended config
378
+ - Clear migration guide with autofix strategies
379
+
380
+ ---
381
+
382
+ ## Deliverables
383
+
384
+ ### Code Artifacts
385
+ - 11 CLI validation rule implementations
386
+ - 11 ESLint rule implementations
387
+ - Updated CLI commands (validate/audit)
388
+ - Updated ESLint plugin (recommended/strict configs)
389
+
390
+ ### Documentation
391
+ - Updated agent status (interaction-patterns.md, accessibility.md)
392
+ - Updated README.md (Active Agents section)
393
+ - Updated AESTHETICS.md (agent responsibilities)
394
+ - New: `docs/TESTING-GUIDE.md`
395
+ - New: `docs/PHASE-6-MIGRATION.md`
396
+
397
+ ### Publishing
398
+ - Version 0.4.0 release
399
+ - npm publish for main package
400
+ - npm publish for ESLint plugin (separate package)
401
+
402
+ ---
403
+
404
+ ## Timeline Summary
405
+
406
+ | Week | Focus | Deliverables |
407
+ |------|-------|--------------|
408
+ | Week 1 | Interaction Patterns CLI Rules | 5 CLI validation rules |
409
+ | Week 2 | Accessibility CLI Rules | 6 CLI validation rules |
410
+ | Week 3 | ESLint Plugin Rules | 11 ESLint rules + config updates |
411
+ | Week 4 | Integration & Docs | Agent status updates, README, testing guide, migration guide, v0.4.0 release |
412
+
413
+ **Total Timeline: 4 weeks**
414
+
415
+ ---
416
+
417
+ ## Next Steps to Begin Implementation
418
+
419
+ ### Immediate Next Step: Week 1 - Interaction Patterns CLI Rules
420
+
421
+ Start with **`cli/rules/interaction-patterns/state-completeness.js`** - the highest impact rule.
422
+
423
+ This rule needs:
424
+ 1. AST parser to detect async operations (useEffect, fetch, axios)
425
+ 2. State variable detection (useState, useReducer)
426
+ 3. Violation detection: async operation without loading/error/empty states
427
+ 4. Autofix strategy: generate boilerplate state handling
428
+ 5. Test suite with valid/invalid examples
429
+
430
+ **File Structure to Create:**
431
+ ```
432
+ cli/
433
+ ├── rules/
434
+ │ ├── interaction-patterns/
435
+ │ │ ├── index.js # Export all interaction pattern rules
436
+ │ │ ├── state-completeness.js # ⭐ Start here
437
+ │ │ ├── generic-copy.js
438
+ │ │ ├── confirmation-overuse.js
439
+ │ │ ├── feedback-mechanism.js
440
+ │ │ └── focus-management.js
441
+ │ └── accessibility/
442
+ │ ├── index.js # Export all accessibility rules
443
+ │ ├── missing-alt-text.js
444
+ │ ├── contrast-ratio.js
445
+ │ ├── color-only-indicator.js
446
+ │ ├── missing-form-labels.js
447
+ │ ├── keyboard-navigation.js
448
+ │ └── aria-validation.js
449
+ ```
450
+
451
+ Once state-completeness is implemented, the pattern applies to all other rules.
452
+
453
+ ---
454
+
455
+ **Status:** 📋 Plan Complete - Ready for Implementation
456
+ **Last Updated:** 2026-01-11