Monorepo for Aesthetic.Computer
aesthetic.computer
1# Implementation Plan: Unified KidLisp Execution
2
3## Phase 1: Immediate Fix - Use Embedded Layer System
4
5### Current Problem
6```javascript
7// Current broken approach in disk.mjs:
8kidlisp() -> creates instance -> calls pieceObject.paint(api) directly
9```
10
11### Solution
12```javascript
13// New unified approach:
14kidlisp() -> creates embedded layer -> uses same pipeline as $code
15```
16
17## Implementation Steps
18
19### 1. Create Embedded Layer API in KidLisp
20Add a public method to create embedded layers programmatically:
21
22```javascript
23// In kidlisp.mjs:
24createProgrammaticEmbeddedLayer(source, x, y, width, height, options = {}) {
25 // Use same logic as $code parsing but for programmatic creation
26 // Return layer ID for tracking
27}
28```
29
30### 2. Modify disk.mjs kidlisp() Function
31Replace direct execution with embedded layer creation:
32
33```javascript
34// In disk.mjs:
35kidlisp: (x, y, width, height, source) => {
36 // Get main KidLisp instance (if exists) or create shared one
37 const mainKidLispInstance = getOrCreateMainKidLispInstance();
38
39 // Create embedded layer using same pipeline as $code
40 const layerId = mainKidLispInstance.createProgrammaticEmbeddedLayer(
41 source, x, y, width, height, { isNestedInstance: true }
42 );
43
44 // Layer will be rendered automatically in next frame via renderEmbeddedLayers()
45 return layerId;
46}
47```
48
49### 3. Shared Instance Management
50Instead of separate instances per buffer, use a shared system:
51
52```javascript
53// Global KidLisp instance for JavaScript API calls
54let sharedKidLispInstance = null;
55
56function getOrCreateMainKidLispInstance() {
57 if (!sharedKidLispInstance) {
58 sharedKidLispInstance = new lisp.KidLisp();
59 sharedKidLispInstance.isEmbeddedContext = true;
60 }
61 return sharedKidLispInstance;
62}
63```
64
65### 4. Frame Integration
66Ensure the shared instance participates in main frame execution:
67
68```javascript
69// In the main paint loop, ensure shared instance renders its layers
70if (sharedKidLispInstance) {
71 sharedKidLispInstance.renderEmbeddedLayers(api);
72}
73```
74
75## Benefits of This Approach
76
771. **Same Code Path**: JavaScript kidlisp() uses identical execution as $code
782. **No Divergence**: All features work consistently
793. **Proper Buffering**: Uses same buffer management as embedded layers
804. **Frame Integration**: Automatic participation in main frame execution
815. **Effect Persistence**: Blur and other effects accumulate correctly
82
83## Testing Strategy
84
85Create test cases that verify:
86- JavaScript kidlisp() executes wipe/ink/line commands
87- Blur effects persist across frames
88- Buffer contexts work correctly
89- Performance is comparable to embedded $code
90
91## Rollback Plan
92
93If unified approach has issues:
941. Keep current separate instance approach as fallback
952. Add feature flag to switch between approaches
963. Gradually migrate once stable
97
98## Success Criteria
99
100✅ All console logs show wipe/ink/line execution for left buffer
101✅ Blur effects work identically in JavaScript API and $code
102✅ No missing commands in any execution path
103✅ Performance parity with current embedded system
104
105This approach eliminates the dual code paths that cause the current inconsistency.