Monorepo for Aesthetic.Computer aesthetic.computer
at main 177 lines 7.5 kB view raw view rendered
1# AC Native — Stack Report 2 3*Last updated: 2026-03-11* 4 5## What Is This? 6 7AC Native is a bare-metal Linux system that boots from USB (or internal disk) directly into a creative computing runtime. No distro, no systemd, no desktop — just a custom kernel running a C binary as PID 1 that executes JavaScript "pieces" via QuickJS. 8 9## The Stack 10 11### Layer 0: Hardware 12- **Target**: ThinkPad X1 Nano Gen 2 (primary), any x86_64 UEFI machine 13- **Display**: DRM (Direct Rendering Manager) — writes pixels directly to framebuffer 14- **Audio**: ALSA (Advanced Linux Sound Architecture) — PCM output + Flite TTS 15- **Input**: evdev — keyboard, trackpad, touchscreen, joystick, NuPhy analog keys 16- **WiFi**: Intel iwlwifi (9260, AX200, AX201) via wpa_supplicant + dhclient 17- **Storage**: FAT32 EFI System Partition on USB or internal NVMe 18 19### Layer 1: Kernel 20- **Linux 6.14.2** — custom minimal config (~200 options vs ~5000 in a typical distro) 21- **No distro** — not Fedora, Ubuntu, or anything else. Raw kernel + initramfs 22- **EFI stub boot** — kernel IS the bootloader (BOOTX64.EFI on FAT32 ESP) 23- **Embedded initramfs** — root filesystem is LZ4-compressed CPIO archive baked into the kernel 24- **Size**: ~40MB total (kernel + initramfs) 25 26### Layer 2: Initramfs (Root Filesystem) 27Everything the system needs lives in a ~33MB compressed archive: 28 29| Component | Size | Purpose | 30|-----------|------|---------| 31| ac-native binary | 1.1 MB | PID 1 — the entire runtime | 32| Shared libraries | ~40 MB (uncompressed) | libc, libdrm, libasound, libssl, etc. | 33| WiFi firmware | 4.9 MB | Intel iwlwifi microcode | 34| Flite TTS | 5.2 MB | Text-to-speech (2 voices) | 35| ALSA config | 352 KB | Audio device configuration | 36| WiFi tools | ~6 MB | wpa_supplicant, dhclient, iw, ip | 37| Dropbear SSH | 228 KB | SSH daemon for remote access | 38| CA certificates | ~200 KB | HTTPS trust chain | 39| Pieces (.mjs) | ~120 KB | JavaScript programs | 40| Shell + utils | ~3 MB | bash, grep, curl, etc. | 41 42### Layer 3: ac-native (The Runtime) 43A single C binary (~1.1MB) that does everything: 44 45- **PID 1 init**: Mounts /proc, /sys, /dev, /tmp. Sets CPU governor. Finds boot device 46- **Display**: DRM initialization, double-buffered framebuffer, 60fps vsync 47- **Graphics**: Software rasterizer — wipe, ink, line, box, circle, plot, write (bitmap fonts) 48- **Audio**: ALSA PCM output with synthesizer (sine, square, saw, triangle, noise) 49- **Input**: Multi-device polling (keyboard, mouse, trackpad, touch, analog keys) 50- **WiFi**: Scan, connect, DHCP — full network stack management 51- **JavaScript**: QuickJS engine with custom AC API bindings 52- **Networking**: curl (HTTP/S), WebSocket client (TLS), UDP client 53- **OTA updates**: Download vmlinuz, flash to EFI partition, verify, reboot 54- **Config**: JSON config on FAT32 partition (handle, colors, tokens) 55- **SSH**: Dropbear daemon for remote access 56 57### Layer 4: Pieces (JavaScript) 58Interactive programs executed by QuickJS with lifecycle functions: 59 60``` 61boot() → [act() → sim() → paint()] × 60fps → leave() 62``` 63 64**Current pieces:** 65- `notepat.mjs` — Musical notation pad (default boot piece, ~96KB) 66- `prompt.mjs` — Command line with KidLisp evaluation 67- `lisp.mjs` — KidLisp visual evaluator 68- `claude.mjs` — Claude API chat client (OAuth refresh tokens) 69- `roz.mjs` — Character piece 70 71## Boot Sequence 72 73``` 74UEFI firmware 75 → BOOTX64.EFI (Linux kernel with embedded initramfs) 76 → /init (symlink to /ac-native) 77 → mount /proc /sys /dev /tmp 78 → mount EFI partition to /mnt 79 → read /mnt/config.json (handle, colors, tokens) 80 → init display (DRM) 81 → render boot title ("hi @jeffrey" with custom colors) 82 → init audio → boot beep (E5→B5 two-tone) 83 → init input (keyboard, trackpad, etc.) 84 → init WiFi (auto-connect to saved network) 85 → load piece.mjs → call boot() 86 → main loop: input_poll → act → sim → paint → present 87``` 88 89**Boot time target**: Sub-second to interactive piece. 90 91## Network Architecture 92 93All networking is **outbound only** (except SSH when enabled): 94 95- **HTTP/S**: curl via system() — used for OTA checks, clock sync, API calls 96- **WebSocket**: Custom TLS client in background pthread — AC chat/multiplayer 97- **UDP**: Raw datagrams for lightweight co-presence data 98- **SSH**: Dropbear on port 22 (auto-starts on WiFi connect) 99 100## OTA Update Flow 101 1021. Check version: `GET https://aesthetic.computer/api/native/version` 1032. Download kernel: `GET https://aesthetic.computer/api/native/vmlinuz` (binary fetch with progress) 1043. Flash to EFI: Copy to /mnt/EFI/BOOT/BOOTX64.EFI with fsync + syncfs 1054. Verify: Drop page caches, byte-for-byte comparison of source vs destination 1065. Reboot: Show verified bytes count, then `reboot(RB_AUTOBOOT)` 107 108## Claude Integration (3 Approaches) 109 110### 1. Direct API Client (claude.mjs) 111- Pure JavaScript piece running in QuickJS 112- Uses `system.fetchPost()` for HTTP POST requests 113- OAuth: Stores refresh token in config.json, exchanges for access token 114- Calls `/v1/messages` API with Claude Sonnet 115- No external dependencies 116 117### 2. SSH Remote Access (dropbear) 118- Lightweight SSH daemon (~228KB) bundled in initramfs 119- Auto-starts when WiFi connects 120- SSH in from any machine on the local network 121- Run Claude Code CLI remotely over the SSH session 122- `ssh root@<device-ip>` 123 124### 3. Node.js + Claude Code CLI (planned) 125- Bundle Node.js binary in initramfs 126- `system.execNode(script)` runs JS via Node subprocess 127- Could run actual `@anthropic-ai/claude-code` package 128- Renders output through AC native display 129 130## Key Files 131 132``` 133fedac/native/ 134 src/ 135 ac-native.c — PID 1, main loop, boot sequence 136 js-bindings.c/h — QuickJS ↔ C API (graphics, audio, network, system) 137 drm-display.c/h — DRM framebuffer display 138 audio.c/h — ALSA audio + synthesizer 139 input.c/h — evdev input handling 140 wifi.c/h — WiFi management 141 ws-client.c/h — WebSocket client 142 graph.c/h — Software rasterizer 143 font.c/h — Bitmap font renderer 144 pieces/ 145 notepat.mjs — Musical notation (default piece) 146 prompt.mjs — Command prompt 147 claude.mjs — Claude API client 148 lisp.mjs — KidLisp evaluator 149 scripts/ 150 build-and-flash.sh — Full build pipeline 151 upload-release.sh — OTA release to DO Spaces 152 kernel/ 153 config-minimal — Linux kernel config 154 build-kernel.sh — Kernel compilation script 155 Makefile — ac-native binary build 156``` 157 158## Build Pipeline 159 160``` 161make CC=gcc → build/ac-native (1.1MB) 162scripts/build-and-flash.sh → build/vmlinuz (~40MB) 163 ├── compile ac-native 164 ├── create initramfs (copy binary + libs + firmware + tools + pieces) 165 ├── compress with LZ4 166 ├── build Linux kernel with embedded initramfs 167 └── flash to USB via mtools (no root mount needed) 168``` 169 170## What Makes This Different 171 172- **No OS layer**: No systemd, no package manager, no filesystem hierarchy. Just kernel + one binary 173- **Sub-second boot**: UEFI → interactive in under 1 second 174- **Single binary runtime**: Everything in one ~1.1MB C program 175- **JavaScript pieces**: Creative programs with immediate-mode graphics, audio synthesis, network 176- **OTA with verification**: Flash + fsync + drop caches + byte-compare before reboot 177- **Fits on any USB**: ~40MB total, boots on any UEFI x86_64 machine