Monorepo for Aesthetic.Computer
aesthetic.computer
1# KidLisp Singleton Refactor
2
3## 🎯 Objective
4Refactor the KidLisp system from multiple instances with complex embedded layer management to a single global instance integrated at the core level, similar to other AC systems like `tape.` and synth.
5
6## 🔍 Current Problems
7- Multiple KidLisp instances causing frame collision
8- Complex embedded layer cache management
9- Buffer context switching issues
10- Inconsistent state management across instances
11- Over-engineered evaluation logic
12
13## 🏗️ New Architecture
14
15### Single Global Instance
16```javascript
17// disk.mjs
18let globalKidLispInstance = null;
19
20function initializeGlobalKidLisp(api) {
21 if (!globalKidLispInstance) {
22 globalKidLispInstance = new KidLisp();
23 globalKidLispInstance.setAPI(api); // Always use main API context
24 }
25}
26```
27
28### Simplified kidlisp() Function
29```javascript
30// Simple function that hooks into global instance
31function kidlisp(source, options = {}) {
32 if (!globalKidLispInstance) return;
33
34 const { x = 0, y = 0, width, height, alpha = 255 } = options;
35
36 // Create buffer for this call
37 const buffer = createBuffer(width || api.screen.width, height || api.screen.height);
38
39 // Execute on isolated buffer
40 globalKidLispInstance.executeOnBuffer(source, buffer);
41
42 // Paste result to main screen
43 if (api.paste) {
44 api.paste(buffer, x, y, alpha);
45 }
46}
47```
48
49## 📋 Implementation Plan
50
51### Phase 1: Core Infrastructure (30 min)
521. **Create global instance in disk.mjs**
53 - Add globalKidLispInstance variable
54 - Add initialization function
55 - Hook into main paint/act loop
56
572. **Simplify KidLisp class**
58 - Remove embedded layer management
59 - Remove multiple instance logic
60 - Add executeOnBuffer method
61
62### Phase 2: Refactor API Integration (45 min)
633. **Update kidlisp() function**
64 - Remove complex embedded layer creation
65 - Use simple buffer operations
66 - Direct paste to main screen
67
684. **Remove complex caching**
69 - Remove embeddedLayerCache
70 - Remove frame collision logic
71 - Remove shouldLayerEvaluate complexity
72
73### Phase 3: Integration & Testing (30 min)
745. **Update disk.mjs integration**
75 - Initialize global instance in boot
76 - Hook into paint function
77 - Remove renderProgrammaticLayers complexity
78
796. **Test cases**
80 - Test kidlisp-in-js piece
81 - Verify $bop and other embedded pieces work
82 - Ensure no performance regression
83
84### Phase 4: Cleanup (15 min)
857. **Remove obsolete code**
86 - Remove embedded layer system
87 - Remove multiple instance management
88 - Clean up debug logging
89
90## 🎯 Expected Benefits
91
92### Performance
93- Single instance = less memory overhead
94- No frame collision checks
95- Simplified evaluation logic
96- Direct buffer operations
97
98### Maintainability
99- Consistent with AC architecture
100- Single source of truth
101- Simpler debugging
102- Less complex state management
103
104### Functionality
105- More reliable kidlisp() calls
106- Better buffer management
107- Consistent API context
108- Cleaner integration
109
110## 🧪 Testing Strategy
111
112### Test Cases
1131. **Basic kidlisp() calls** - Simple wipe, ink, drawing
1142. **Buffer positioning** - x, y, width, height parameters
1153. **Alpha blending** - Transparency support
1164. **Complex expressions** - Multi-command sequences
1175. **Embedded pieces** - $bop, $cow compatibility
1186. **Performance** - No frame rate degradation
119
120### Regression Testing
121- Ensure existing pieces still work
122- Verify no visual artifacts
123- Check memory usage
124- Validate API compatibility
125
126## 📊 Success Criteria
127
128✅ kidlisp() function works reliably
129✅ No frame collision issues
130✅ Simplified codebase
131✅ Better performance
132✅ Consistent with AC architecture
133✅ All existing functionality preserved
134
135## 🚀 Deployment
136
1371. Implement in feature branch
1382. Test thoroughly with existing pieces
1393. Performance benchmark
1404. Merge to main after validation
141
142---
143
144**Estimated Total Time:** 2 hours
145**Priority:** High - Fixes critical rendering issues
146**Impact:** High - Simplifies architecture significantly