Monorepo for Aesthetic.Computer aesthetic.computer
at main 547 lines 17 kB view raw view rendered
1# Aesthetic Computer - Architecture Reference for LLMs 2 3> **Last Updated:** 2025-12-07 4> **Purpose:** Comprehensive guide for AI assistants working with this codebase 5 6--- 7 8## 🎯 Project Overview 9 10**Aesthetic Computer (AC)** is a creative coding platform that runs in the browser, featuring: 11- A **piece-based architecture** (small interactive programs called "pieces") 12- **KidLisp** - a Lisp-based visual programming language 13- **WebGPU rendering** with 2D/3D graphics 14- **Real-time collaboration** and multiplayer support 15- **Cross-platform** deployment (web, iOS, Android, desktop) 16 17--- 18 19## 🏗️ Core Architecture 20 21### System Layers 22 23``` 24┌─────────────────────────────────────────────────────────────────────┐ 25│ VS Code / Emacs Frontend │ 26│ (development environment) │ 27├─────────────────────────────────────────────────────────────────────┤ 28│ 🩸 Artery (CDP) │ 🧠 Emacs MCP │ 🌐 Browser (localhost:8888) │ 29├─────────────────────────────────────────────────────────────────────┤ 30│ Aesthetic Computer Core │ 31│ /system - Main web application (Netlify Functions) │ 32│ /system/public - Static frontend assets │ 33│ /kidlisp - KidLisp language runtime │ 34├─────────────────────────────────────────────────────────────────────┤ 35│ Infrastructure │ 36│ Redis │ Session Server │ Stripe │ Cloudflare Tunnel │ Chat Bots │ 37└─────────────────────────────────────────────────────────────────────┘ 38``` 39 40--- 41 42## 📁 Directory Structure 43 44### Top-Level Directories 45 46| Directory | Purpose | 47|-----------|---------| 48| `/system` | Main web app - Netlify dev server, functions, frontend | 49| `/kidlisp` | KidLisp language: parser, interpreter, pieces | 50| `/kidlisp.com` | KidLisp.com website (separate site) | 51| `/artery` | 🩸 CDP-based control interface for AC | 52| `/dotfiles` | Configuration files (Emacs, shell, etc.) | 53| `/vscode-extension` | VS Code extension for AC panel | 54| `/aesthetic-computer-vault` | Private pieces and secrets | 55 56### Key Files 57 58| File | Purpose | 59|------|---------| 60| `/dotfiles/dot_config/emacs.el` | Emacs configuration with `aesthetic-backend` | 61| `/.devcontainer/config.fish` | Fish shell with 50+ `ac-*` functions | 62| `/artery/artery.mjs` | CDP connection library | 63| `/artery/artery-tui.mjs` | Interactive TUI for AC control | 64| `/artery/emacs-mcp.mjs` | MCP server for VS Code ↔ Emacs | 65| `/.vscode/mcp.json` | MCP server configuration | 66 67--- 68 69## 🧠 Emacs Integration 70 71### The `aesthetic-backend` Function 72 73Located in `/dotfiles/dot_config/emacs.el`, this is the main entry point for the development environment: 74 75```elisp 76(defun aesthetic-backend (target-tab) 77 "Creates the tabbed development environment with eat terminals" 78 ...) 79``` 80 81**Creates tabs:** 821. `artery` → 🩸-artery buffer (runs `ac-artery-dev`) 832. `status` → ⚡-url, 🚇-tunnel 843. `stripe` → 💳-stripe-print, 🎫-stripe-ticket 854. `chat` → 🤖-chat-system, 🧠-chat-sotce, ⏰-chat-clock 865. `web 1/2` → 🌐-site, 📋-session 876. `web 2/2` → 🔴-redis, 🔖-bookmarks, 🔥-oven 887. `tests` → 🧪-kidlisp 89 90**Emoji to command mapping:** 91```elisp 92'(("artery" . "🩸") ("url" . "") ("tunnel" . "🚇") 93 ("stripe-print" . "💳") ("stripe-ticket" . "🎫") 94 ("chat-system" . "🤖") ("chat-sotce" . "🧠") ("chat-clock" . "") 95 ("site" . "🌐") ("session" . "📋") ("redis" . "🔴") 96 ("bookmarks" . "🔖") ("kidlisp" . "🧪") ("oven" . "🔥")) 97``` 98 99### Starting the Environment 100 101```bash 102# From fish shell 103aesthetic # Waits for config, starts Emacs daemon, opens aesthetic-backend 104aesthetic-direct # Skips wait, goes straight to aesthetic-backend 105platform # Quick reconnect to existing daemon 106``` 107 108--- 109 110## 🩸 Artery System 111 112### What is Artery? 113 114**Artery** is a **Chrome DevTools Protocol (CDP)** bridge that allows controlling the AC browser instance programmatically. It connects to VS Code's embedded Chromium via port 9222/9224. 115 116### Architecture 117 118``` 119┌────────────────────────────────────────────────────────────────────┐ 120│ VS Code (Electron) ─────────────── CDP Port 9222 ──────────────────│ 121│ │ │ │ 122│ ├── Workbench (main page) │ │ 123│ └── AC Panel (iframe) ◄──────────────┼─── Artery Connection │ 124│ └── localhost:8888 │ │ 125└───────────────────────────────────────────┴────────────────────────┘ 126``` 127 128### CLI Commands 129 130```bash 131# Basic commands 132artery # Show help 133artery panel # Open AC sidebar panel 134artery jump prompt # Navigate to piece 135artery current # Show current piece 136artery repl # Interactive REPL with console streaming 137 138# Emacs integration 139artery emacs # Check Emacs connection 140artery emacs "(version)" # Execute elisp 141artery emacs-buffers # List Emacs buffers 142 143# Split/Multiplayer 144artery frames # List all AC frames 145artery player 1 # Connect to Player 1 (top split) 146artery player 2 # Connect to Player 2 (bottom split) 147 148# KidLisp.com 149artery kidlisp # Open KidLisp.com window in VS Code 150artery kidlisp-test # Run all 26 KidLisp tests 151artery kidlisp-test basic # Run specific test suite 152 # Suites: basic, editor, playback, ui, console, examples, errors 153 154# VS Code Utilities 155artery close-editors # Close all VS Code editor tabs 156 157# Testing 158artery hiphop # Hip-hop beat generator test 159artery 1v1 # Split-screen 1v1 test 160artery perf 10 # Performance monitor (10 seconds) 161``` 162 163### 🌸 Poppy (Default Log Capture) 164 165Use **Poppy** when you need runtime console logs. It opens the AC panel, 166jumps to the piece, and streams logs until you stop it. 167 168```bash 169node artery/poppy.mjs <piece> 170 171# Examples 172node artery/poppy.mjs notepat 173node artery/poppy.mjs prompt 174``` 175 176**Default behavior:** Prefer Poppy for debugging instead of asking for manual 177copy/paste of logs. 178 179### TUI Mode (`artery-tui.mjs`) 180 181Interactive curses-style interface with: 182- `[p]` Open AC Panel 183- `[j]` Jump to piece 184- `[r]` Enter REPL 185- `[e]` Emacs mode 186- `[t]` Performance test 187- `[s]` Split-screen mode 188 189### KidLisp Test Suite (`test-kidlisp.mjs`) 190 191Automated test harness for KidLisp.com with 26 tests using direct CDP connection: 192 193```bash 194artery kidlisp-test # Run all tests 195artery kidlisp-test basic # Run basic suite only 196artery kidlisp-test editor # Test editor operations 197artery kidlisp-test playback # Test play/stop/clear 198artery kidlisp-test ui # Test buttons and theme 199artery kidlisp-test console # Test console output 200artery kidlisp-test examples # Test loading examples 201artery kidlisp-test errors # Test error handling 202``` 203 204**Test Categories:** 205| Suite | Tests | 206|-------|-------| 207| basic | Connection, disk state, API availability | 208| editor | Code insertion, selection, clear operations | 209| playback | Play, stop, clear, state transitions | 210| ui | Theme toggle, example buttons, console visibility | 211| console | Log output, clear console, display | 212| examples | Loading spiral, bounce, ripple examples | 213| errors | Syntax errors, undefined symbols, error recovery | 214 215### CDP Keyboard Simulation 216 217Artery uses `Input.dispatchKeyEvent` CDP method to simulate VS Code keyboard shortcuts: 218 219```javascript 220// Example: Send Ctrl+K, W chord to close all editors 221send('Input.dispatchKeyEvent', { 222 type: 'keyDown', 223 modifiers: 2, // Ctrl 224 key: 'k', 225 code: 'KeyK', 226 windowsVirtualKeyCode: 75 227}); 228``` 229 230This allows invoking VS Code commands without needing an open webview. 231 232--- 233 234## 🔌 MCP (Model Context Protocol) Integration 235 236### What is MCP? 237 238MCP allows VS Code Copilot Chat to call external tools. We have a custom Node.js MCP server that bridges Copilot ↔ Emacs. 239 240### Configuration (`.vscode/mcp.json`) 241 242```json 243{ 244 "servers": { 245 "emacs": { 246 "type": "stdio", 247 "command": "node", 248 "args": ["/workspaces/aesthetic-computer/artery/emacs-mcp.mjs"], 249 "env": { 250 "EMACSCLIENT": "/usr/sbin/emacsclient" 251 } 252 } 253 } 254} 255``` 256 257### Available MCP Tools 258 259| Tool | Description | 260|------|-------------| 261| `mcp_emacs_execute_emacs_lisp` | Execute arbitrary elisp code | 262| `mcp_emacs_emacs_list_buffers` | List all open buffers | 263| `mcp_emacs_emacs_switch_buffer` | Switch to a buffer | 264| `mcp_emacs_emacs_send_keys` | Send keystrokes to eat terminal | 265| `mcp_emacs_emacs_get_buffer_content` | Read buffer content | 266 267### How It Works 268 269``` 270┌──────────────────────────────────────────────────────────────────┐ 271│ VS Code Copilot Chat │ 272│ │ │ 273│ ▼ │ 274│ mcp.json → node emacs-mcp.mjs (stdio JSON-RPC) │ 275│ │ │ 276│ ▼ │ 277│ emacsclient --eval "(elisp code)" │ 278│ │ │ 279│ ▼ │ 280│ Emacs Daemon (eat terminals running fish → ac-* commands) │ 281└──────────────────────────────────────────────────────────────────┘ 282``` 283 284--- 285 286## 🐟 Fish Shell Commands 287 288### Core AC Commands 289 290| Command | Description | 291|---------|-------------| 292| `ac` | cd to AC root, or `ac piece-name` to jump | 293| `ac-site` | Start main dev server (Netlify + esbuild) | 294| `ac-session` | Session server | 295| `ac-url` | URL generation / shortening | 296| `ac-tunnel` | Cloudflare tunnel for public access | 297| `ac-artery` | Interactive artery TUI | 298| `ac-artery-dev` | Artery TUI with hot reload | 299 300### Recording & Packaging 301 302| Command | Description | 303|---------|-------------| 304| `ac-record $piece` | Record MP4/GIF of a piece | 305| `ac-pack $piece` | Package for Teia (IPFS art platform) | 306| `ac-keep $piece` | Create self-contained HTML bundle | 307| `ac-ship` | Package as Electron desktop app | 308 309### Testing 310 311| Command | Description | 312|---------|-------------| 313| `test-notepat` | Automated notepat testing | 314| `test-line` | Line drawing test | 315| `test-melody` | Music generation test | 316 317### KidLisp 318 319| Command | Description | 320|---------|-------------| 321| `st $piece` | Show source tree for a piece | 322| `kidlisp` | KidLisp probe for kidlisp.com | 323 324--- 325 326## 🎮 Piece System 327 328### What is a Piece? 329 330A "piece" is a self-contained interactive program. Each piece has: 331- A main JavaScript/KidLisp file 332- Optional boot, act, sim, paint, beat functions 333- Access to the AC graphics/sound API 334 335### Piece Locations 336 337``` 338/system/public/aesthetic.computer/disks/ # Main pieces 339/kidlisp/pieces/ # KidLisp pieces 340/aesthetic-computer-vault/ # Private pieces 341``` 342 343### Key Pieces 344 345| Piece | Description | 346|-------|-------------| 347| `prompt` | Default landing - command prompt interface | 348| `notepat` | Music pattern sequencer | 349| `line` | Drawing tool | 350| `wand` | 3D wand visualization | 351| `bios` | System configuration | 352 353--- 354 355## 🌐 Development Server 356 357### URLs 358 359| URL | Service | 360|-----|---------| 361| `https://localhost:8888` | Main AC site | 362| `https://localhost:8889` | Jump/control API | 363| `http://localhost:3000` | Session server | 364| Port 9222/9224 | CDP (Chrome DevTools Protocol) | 365 366### Starting Development 367 368```bash 369# Option 1: Full environment via Emacs 370aesthetic 371 372# Option 2: Individual services 373ac-site # Main server 374ac-session # Session server 375ac-tunnel # Public tunnel 376ac-artery-dev # Artery with hot reload 377``` 378 379--- 380 381## 🔧 Common Development Tasks 382 383### Jump to a Piece 384 385```bash 386# Via fish 387ac prompt 388ac notepat 389 390# Via artery CLI 391artery jump prompt 392 393# Via artery TUI 394ac-artery → [j]type piece name 395 396# Via MCP (from Copilot Chat) 397# Use mcp_emacs_emacs_send_keys to send to artery buffer 398``` 399 400### Open AC Panel in VS Code 401 402```bash 403# Via artery 404artery panel 405 406# Via TUI 407ac-artery → [p] 408``` 409 410### Monitor Console Logs 411 412```bash 413# Via artery REPL (streams live) 414artery repl 415 416# Via TUI 417ac-artery → [r] 418``` 419 420### Control from Emacs 421 422```elisp 423;; Switch buffers 424(switch-to-buffer "🩸-artery") 425 426;; Send keys to eat terminal 427(with-current-buffer "🩸-artery" 428 (eat-term-send-string eat-terminal "prompt\n")) 429``` 430 431--- 432 433## 🧪 Testing 434 435### Artery Tests 436 437```bash 438artery hiphop # Music generation 439artery trapwaltz # 3/4 time + trap 440artery 1v1 # Split-screen multiplayer 441``` 442 443### Unit Tests 444 445```bash 446# Via fish 447test-notepat 448test-line 449test-melody 450 451# These use artery internally to control AC 452``` 453 454--- 455 456## 🐛 Debugging Tips 457 458### Check Emacs Daemon 459 460```bash 461check-daemon # Status check 462restart-daemon # Force restart 463``` 464 465### Check Artery Connection 466 467```bash 468artery # Shows help if connected 469artery frames # Lists all AC iframes 470``` 471 472### View Logs 473 474```bash 475# Emacs debug log 476cat /tmp/emacs-debug.log 477 478# AC site logs 479# Look in the 🌐-site buffer in Emacs 480``` 481 482### CDP Issues 483 484If artery can't connect: 4851. Make sure AC panel is open in VS Code 4862. Check `host.docker.internal` resolves (Docker Desktop) 4873. On Linux, socat may need to forward port 9222→9224 488 489--- 490 491## 📚 Key Concepts 492 493### eat Terminal 494 495Emacs Application Terminal - runs fish shell inside Emacs buffers. Each tab in `aesthetic-backend` is an eat terminal running an `ac-*` command. 496 497### CDP (Chrome DevTools Protocol) 498 499Protocol for browser automation. Artery uses it to: 500- Find AC iframe targets 501- Execute JavaScript in browser context 502- Capture console logs 503- Send input events 504 505### MCP (Model Context Protocol) 506 507Anthropic's protocol for AI tool calling. Our `emacs-mcp.mjs` server exposes Emacs operations to VS Code Copilot Chat via JSON-RPC over stdio. 508 509--- 510 511## 🚀 Quick Reference 512 513### Start Development 514```bash 515aesthetic # Full environment 516``` 517 518### Control AC 519```bash 520artery repl # Interactive REPL 521ac-artery # TUI interface 522``` 523 524### From VS Code Copilot 525``` 526# Available MCP tools: 527- mcp_emacs_execute_emacs_lisp 528- mcp_emacs_emacs_list_buffers 529- mcp_emacs_emacs_switch_buffer 530- mcp_emacs_emacs_send_keys 531- mcp_emacs_emacs_get_buffer_content 532``` 533 534--- 535 536## 📝 Notes for AI Assistants 537 5381. **Buffer Naming**: Emacs buffers use emoji prefixes like `🩸-artery`, `🌐-site` 5392. **eat Terminals**: Use `eat-term-send-string` to send commands to fish 5403. **Artery vs MCP**: Artery controls AC browser; MCP controls Emacs 5414. **Fish Shell**: User's shell - no heredocs, use printf/echo instead 5425. **Devcontainer**: Running in Docker on Fedora Linux 5436. **Port Mapping**: CDP on 9222 (host) may map to 9224 (container via socat) 544 545--- 546 547*This document serves as an LLM-readable map of the Aesthetic Computer development environment.*