twin-o-matic / README.md
SNAPKITTYWEST's picture
docs: replace with real GitHub README
a1df6a0 verified
|
Raw
History Blame Contribute Delete
11.3 kB
---
license: other
library_name: custom
tags:
- code
- sovereign-compute
---
# Twin-O-Matic
**JIT Browser LLM + Live 3D Engine β€” No Server, No API Keys, No Install**
[![License](https://img.shields.io/badge/License-Sovereign%20Source-blue.svg)](LICENSE)
[![Pages](https://img.shields.io/badge/Live-GitHub%20Pages-brightgreen.svg)](https://snapkittywest.github.io/twin-o-matic/)
---
## What Is This
Twin-O-Matic is a browser-based AI agent with tool use. It runs **Llama 3.2 1B** entirely in your GPU via WebLLM/WebGPU and gives the model tools to create **live animated 3D scenes** in real-time.
Open the page. Model loads into VRAM. Type "create a solar system" and watch it appear.
**No server. No API keys. No npm. No install. Just a URL.**
**Live:** https://snapkittywest.github.io/twin-o-matic/
---
## Architecture
```
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ BROWSER β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ THREE.JS VIEWPORT β”‚ LLM TERMINAL β”‚
β”‚ β”‚ β”‚
β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚
β”‚ β”‚ WebGL 3D β”‚ β”‚ β”‚ WebLLM (MLC) β”‚ β”‚
β”‚ β”‚ Renderer β”‚ β”‚ β”‚ Llama 3.2 1B q4f16 β”‚ β”‚
β”‚ β”‚ + Orbit β”‚ β”‚ β”‚ WebGPU compute shaders β”‚ β”‚
β”‚ β”‚ Controls β”‚ β”‚ β”‚ β”‚ β”‚
β”‚ β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”˜ β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚
β”‚ β”‚ β”‚ β”‚ β”‚
β”‚ β–Ό β”‚ β–Ό β”‚
β”‚ Scene Engine β”‚ Tool Parser β”‚
β”‚ (primitives, β”‚ (TOOL: lines β†’ 3D objects) β”‚
β”‚ particles, β”‚ β”‚ β”‚
β”‚ lights, β”‚ β–Ό β”‚
β”‚ animation) β”‚ Template Fallback β”‚
β”‚ β”‚ (scene detection if model β”‚
β”‚ β”‚ doesn't output tools) β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
```
---
## Features
### Browser LLM (WebGPU)
- **Llama 3.2 1B Instruct** quantized to q4f16 β€” runs entirely client-side
- Model weights download once, cached by browser (~700MB)
- Streaming inference with live tok/s counter
- ~25-120 tok/s depending on GPU
- Zero external API calls β€” all computation is local
### 3D Tool Use
The LLM has tools to create and manipulate a live Three.js scene:
| Tool | Description |
|------|-------------|
| `add_box` | Rectangular prism with position, size, color |
| `add_sphere` | Sphere with radius, position, color |
| `add_cylinder` | Cylinder with radius, height, position, color |
| `add_torus` | Torus (ring) with radius, tube thickness, color |
| `add_cone` | Cone with radius, height, position, color |
| `add_particles` | Particle system (count, spread, color) |
| `add_light` | Dynamic point light with position, color, intensity |
| `set_background` | Change scene background color |
| `reset_scene` | Clear all objects |
### Scene Templates
When the model doesn't output tools (1B models are unreliable at structured output), the engine detects scene intent and fires templates:
| Keyword | Scene |
|---------|-------|
| solar, planet, sun | Solar system with planets, rings, star field |
| city, skyline, tower, building | Neon city with varying height towers |
| forest, tree, wood, jungle | Trees (cylinder trunks + cone canopies), berries, fireflies |
| ocean, sea, water, fish | Ocean plane, fish, sailboat, jellyfish |
| space, galaxy, nebula, star | Deep space with nebula particles, planets, rings |
| abstract, art, geometric, shape | Nested tori, cones, cylinders, particle clouds |
Any prompt containing "create", "build", "make", "show", "generate", or "draw" also triggers a template if no tools are output.
### 3D Viewport Controls
- **Orbit** β€” click and drag to rotate camera
- **Zoom** β€” scroll wheel
- **Pan** β€” right-click drag
- **Reset Scene** β€” clear all objects
- **Toggle Spin** β€” stop/start object animation
- **Wireframe** β€” toggle wireframe rendering
- **Explode** β€” fling all objects outward
- **Screenshot** β€” save current frame as PNG
### Animation
All objects float and spin automatically:
- Y-axis rotation at varying speeds
- Sinusoidal hover (bob up and down)
- Each object offset in phase for organic movement
---
## How It Works
1. Page loads β†’ WebGPU adapter detected β†’ model weights stream into GPU
2. User types prompt β†’ sent to Llama 3.2 1B with tool-use system prompt
3. Model outputs `TOOL:` lines β†’ parsed and executed against Three.js scene
4. If model outputs only text β†’ scene detection fires template as fallback
5. Objects appear in viewport with animation
The system prompt includes few-shot examples so the model knows the exact format. The template fallback ensures visuals always appear for scene-creation requests regardless of model output quality.
---
## Requirements
- **Chrome 113+** or **Edge 113+** (WebGPU required)
- **GPU with 2GB+ VRAM** (model is ~700MB quantized)
- That's it. No Node.js. No Python. No server.
---
## Run Locally (Optional)
If you want to serve it locally instead of GitHub Pages:
```bash
git clone https://github.com/SNAPKITTYWEST/twin-o-matic.git
cd twin-o-matic
node server.js
# Open http://localhost:8080
```
The server is only needed for local development. GitHub Pages serves it statically.
---
## TOM: The Recursive Self-Improvement Engine
The Python backend (`tom.py`) is a separate system β€” a recursive self-improvement loop that uses Ollama for local inference:
```
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ OUTER LOOP │────▢│ INNER LOOP │────▢│ WORM CHAIN β”‚
β”‚ (analyzes β”‚ β”‚ (executes β”‚ β”‚ (seals each β”‚
β”‚ failures) │◀────│ tasks) β”‚ β”‚ generation)β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
```
- **Inner Loop** executes tasks with a tunable prompt + hyperparams
- **Outer Loop** analyzes telemetry, classifies failures (A/B/C/D), patches the inner prompt
- **WORM Chain** seals every generation with SHA-256 (append-only, immutable)
- **Assert Gate** validates outer loop patches before promotion (JSON schema, temperature bounds, failure class)
```bash
# Requires Ollama running locally
python tom.py --task "write a Python bubble sort" --generations 5
python tom.py --task "prove x^2 >= 0 in Lean 4" --generations 10
```
---
## Project Structure
```
twin-o-matic/
β”œβ”€β”€ index.html # Root redirect β†’ frontend
β”œβ”€β”€ frontend/
β”‚ β”œβ”€β”€ index.html # Main app (LLM + 3D + tools)
β”‚ └── src/
β”‚ └── engine.mjs # Goldilocks field, SHA-256, WORM chain, Lean verifier
β”œβ”€β”€ tom.py # TOM recursive loop (Python + Ollama)
β”œβ”€β”€ prompts/
β”‚ β”œβ”€β”€ inner_loop.txt # Inner loop system prompt
β”‚ └── outer_loop.txt # Outer loop analysis prompt
β”œβ”€β”€ schemas/
β”‚ β”œβ”€β”€ outer_output_schema.json # Outer loop output validation schema
β”‚ └── hyperparams_schema.json # Hyperparameter bounds
β”œβ”€β”€ server.js # Optional local server (WebSocket mesh)
β”œβ”€β”€ .github/workflows/
β”‚ └── deploy.yml # GitHub Pages auto-deploy
β”œβ”€β”€ LICENSE # Sovereign Source License
└── README.md # This file
```
---
## Engine Module (engine.mjs)
The frontend includes a pure-JS compute engine with no dependencies:
### Goldilocks Field Arithmetic
All operations mod `p = 2^64 - 2^32 + 1` (the Goldilocks prime used in Plonky2/Miden ZK systems):
- `gfAdd(a, b)` β€” addition mod p
- `gfSub(a, b)` β€” subtraction mod p
- `gfMul(a, b)` β€” multiplication mod p
- `gfPow(a, exp)` β€” exponentiation via square-and-multiply
- `gfInv(a)` β€” inverse via Fermat's little theorem (a^(p-2))
### SHA-256
Complete pure-JS implementation. No WebCrypto dependency. Used for WORM sealing.
### WORM Chain
Append-only sealed ledger:
- `wormSeal(data)` β€” hash data + previous seal, append to chain
- `wormChain()` β€” return full chain
- `wormVerify()` β€” verify chain integrity
### Lean Buffer Verifier
Static analysis of Lean 4 buffers:
- Sorry count detection
- Theorem/lemma declaration detection
- Tactic usage analysis (intro, exact, simp, apply, rfl, cases, induction, constructor, rw)
---
## Sovereign Stack Integration
Twin-O-Matic connects to the broader SnapKitty sovereign compute constellation:
```
sov-kernel-monster ← Fortran 2018 quantum density matrix evolution
foundry-intel ← WASM proof lab + JIT verification
bob-orchestrator ← Lean 4 + Ada + Mamba + Prolog reasoning
claudes-harness ← Prolog identity kernel
errant ← Linear Forth ISA with QTT
sovereign-transformer ← Datalog corpus gate
j-matrix-twin ← SUBLEQ attention + J tacit engine
twin-o-matic ← THIS β€” browser LLM + 3D tool use
```
---
## Examples
Try these prompts:
```
create a solar system
build a neon city at night
make a forest with glowing particles
show me deep space with a nebula
create abstract geometric art
build a tower made of rings
make something beautiful
```
Or just chat β€” the model answers questions normally when no scene is detected.
---
## Performance
| GPU | Model Load | Inference |
|-----|-----------|-----------|
| RTX 3080 | ~15s | 80-120 tok/s |
| RTX 3060 | ~20s | 50-80 tok/s |
| M1 Mac | ~25s | 40-60 tok/s |
| Intel Arc | ~30s | 30-50 tok/s |
| Integrated | May not work | β€” |
First load downloads ~700MB of model weights (cached after).
---
## License
```
SOVEREIGN SOURCE LICENSE β€” Apache 2.0
Copyright 2026 Jessica (SNAPKITTYWEST)
All IP belongs to Jessica (jessicalw34@gmail.com)
Licensed under the Apache License, Version 2.0
http://www.apache.org/licenses/LICENSE-2.0
```
---
Built with WebLLM + Three.js + WebGPU. No cloud. No telemetry. Sovereign inference.