#!/bin/bash # dual-runtime-start.sh — Orchestrate the full sovereign dual runtime # Layer 1: WASM agent sandbox (browser/iPython) # Layer 2: 6502 sovereign VM (control plane) # Layer 3: M5 compatibility bridge (API layer) # All connected through ORTHO-32-T doorbell mechanism set -e echo "╔══════════════════════════════════════════════════════════╗" echo "║ SOVEREIGN DUAL RUNTIME ║" echo "║ 6502 VM · M5 Bridge · WASM Sandbox · WORM Chain ║" echo "║ θ = 89/2462 · Bel Esprit D'Accord Irrevocable Trust ║" echo "╚══════════════════════════════════════════════════════════╝" # Create required directories mkdir -p /sovereign/{worm,doorbell,data,qemu/images} # Seal genesis block GENESIS_HASH=$(echo "genesis:$(date -u +%s)" | sha256sum | cut -c1-16) echo "{\"hash\":\"${GENESIS_HASH}\",\"prev\":\"0000000000000000\",\"agent\":\"system\",\"event\":\"dual_runtime_start\"}" \ >> /sovereign/worm/chain.jsonl echo "[boot] WORM genesis sealed: ${GENESIS_HASH}" # ── Start 6502 VM (background) ──────────────────────────── if [ -f /sovereign/vm6502/target/release/sovereign-vm6502 ]; then echo "[boot] Starting 6502 sovereign VM..." /sovereign/vm6502/target/release/sovereign-vm6502 & VM6502_PID=$! echo "[boot] 6502 VM PID: ${VM6502_PID}" else echo "[boot] 6502 VM not compiled — running heartbeat stub..." ( phases=("T0 RESET" "T1 NAND" "T2 SASS" "T3 IR" "T4 MMA" "T5 MMA" "T6 MMA" "T7 MMA" "T8 ROOF" "T9 WORM" "T10 SOVEREIGN_ACTIVE") i=0 while true; do echo "[6502] ${phases[$((i % 11))]}" i=$((i+1)) sleep 1.2 done ) & fi # ── Start M5 bridge (background) ───────────────────────── if [ -f /sovereign/m5-bridge/target/release/sovereign-m5-bridge ]; then echo "[boot] Starting M5 compatibility bridge..." /sovereign/m5-bridge/target/release/sovereign-m5-bridge & M5_PID=$! echo "[boot] M5 bridge PID: ${M5_PID}" else echo "[boot] M5 bridge not compiled — running Python stub..." python3 -c " import http.server, json, threading class Handler(http.server.BaseHTTPRequestHandler): def log_message(self, *a): pass def do_GET(self): self.send_response(200) self.send_header('Content-Type','application/json') self.send_header('Access-Control-Allow-Origin','*') self.end_headers() self.wfile.write(json.dumps({'m5':'Running','docker':'Containerized','vm6502':'SOVEREIGN_ACTIVE'}).encode()) server = http.server.HTTPServer(('0.0.0.0', 9091), Handler) print('[M5] Python stub on :9091') server.serve_forever() " & fi # ── Start WASM sandbox web server ──────────────────────── echo "[boot] Starting WASM agent sandbox on :8788..." python3 -m http.server 8788 --directory /sovereign/wasm & WASM_PID=$! echo "" echo "╔══════════════════════════════════════════════════════════╗" echo "║ SOVEREIGN DUAL RUNTIME — ALL SYSTEMS GO ║" echo "║ ║" echo "║ WASM Sandbox: http://localhost:8788/agent-sandbox.html║" echo "║ M5 Bridge API: http://localhost:9091/api/runtime-status║" echo "║ 6502 Telemetry: http://localhost:9090 (if compiled) ║" echo "║ WORM Chain: /sovereign/worm/chain.jsonl ║" echo "╚══════════════════════════════════════════════════════════╝" # Tail WORM chain to stdout echo "" echo "[worm] Tailing WORM chain..." tail -f /sovereign/worm/chain.jsonl 2>/dev/null | while read line; do echo "[worm] $line" done & # Keep container alive wait