File size: 6,646 Bytes
108cd52 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 | ---
license: other
license_name: sovereign-source-license-v2
library_name: custom
tags:
- code
- sovereign-compute
---
# Perplexity Macro VM
**Sovereign Source License v1.0** β Copyright (c) 2026 Ahmad Ali Parr + Jessica Westerhoff, BEL ESPRIT D ACCORD TRUST HOLDINGS INC. Patent Pending.
Deterministic 16-bit research VM that runs Perplexity-style planning, search, evidence, critique, and synthesis compiled to ROM. Elixir GenServer OTP + Phoenix LiveView streams every retired instruction. Host does web/model/code work behind typed capability boundaries; VM owns control flow.
> **Live Agent Console** β https://snapkittywest.github.io/perplexity-macro-vm/
## Features
- **Ollama / OpenAI / OpenRouter** model integration (local or cloud)
- **Python execution** via Pyodide (runs in browser, no server needed)
- **Web search** via DuckDuckGo (client-side)
- **Terminal tools** (client-side simulation, backend-ready)
- **Tool calling protocol** β model can invoke tools automatically
- **Deterministic VM** β 16-bit, 65K words, typed capabilities, transcript hashing
## Architecture
```
Phoenix LiveView (trace | regs | memory | graph)
^ PubSub
TraceHub (ring buffer 50k)
^ {:retired, trace}
MacroVM GenServer β fetch/decode/execute -> commit -> emit one trace
^ capability request | host result v
ResearchBroker (search/fetch/LLM/evidence) Compiler (.pqm -> ROM)
```
VM owns control flow and acceptance policy. Host returns typed evidence records to a waiting `RQ` instruction.
## VM Contract
```
Word: 16 bits, 65,536 words
ROM: $0000-$1FFF RAM: $2000-$DFFF MMIO: $E000-$E0FF Stack: descending, RAM-backed
Regs: A,B,C,D, PC, SP=0xDFFF, BP, FLAGS
Cycles: fixed per opcode
State: %State{rom, ram, regs, cycles, retired, halted?, waiting?, fuel=128, transcript_hash, breakpoints, watches, trace_seq}
```
## Instruction Set
| Op | Mnemonic | Cyc | Meaning |
|---|---|---|---|
| 00 | NOP | 1 | |
| 01 | LDI r,imm16 | 2 | |
| 02 | LD r,[addr] | 3 | |
| 03 | ST [addr],r | 3 | |
| 04 | ADD rd,rs | 1 | |
| 05 | XOR rd,rs | 1 | |
| 06 | CMP ra,rb | 1 | |
| 07 | JMP addr | 2 | |
| 08 | JZ addr | 2/3 | |
| 09 | CALL addr | 3 | |
| 0A | RET | 3 | |
| 0B | DEC r | 1 | |
| 0C | HALT code | 1 | |
| 20 | RQ cap,ptr,len | 4 | capability request |
| 21 | POLL rd | 2 | status |
| 22 | READ rd,off | 3 | host result word |
| 23 | VERIFY ptr,len | 6 | schema/CRC |
| 24 | EVIDENCE claim,src | 3 | provenance |
| 25 | COVERAGE rd | 4 | cited-claim coverage |
| 26 | DISAGREE rd | 5 | contradiction flags |
| 27 | HASH ptr,len | 8+ | transcript hash |
| 28 | FUEL | 1 | trap at zero |
| 29 | EMIT kind,ptr,len | 3 | checkpoint |
| 2A | CONFIRM cap | 2 | one-shot auth |
Capabilities: `01=search 02=fetch 03=browser 04=code 05=local_model 06=file_read 07=file_write 08=calendar 09=email` β sensitive require `CONFIRM` + expiring token.
## Agent Console
**Live:** https://snapkittywest.github.io/perplexity-macro-vm/
Clean chat interface with tool calling:
1. **Connect** β Pick provider (Ollama/OpenRouter/OpenAI), enter credentials
2. **Chat** β Ask anything, model can call tools automatically
3. **Tools** β Python (Pyodide), web search (DuckDuckGo), terminal
4. **Terminal panel** β Toggle to see tool execution log
```
Onboarding -> Provider Selection -> Chat Interface
|
Tool Detection (```python, ```search, ```terminal)
|
Tool Execution (Pyodide / API / simulated)
|
Result -> Model -> Answer
```
### Tool Calling
The model can invoke tools by emitting fenced code blocks:
```python
# Python execution (Pyodide, runs in browser)
import numpy as np
print(np.mean([1, 2, 3, 4, 5]))
```
```search
WebGPU latest news 2025
```
```terminal
ls -la
```
Results are fed back to the model for synthesis.
### Run locally
```bash
# Just open the HTML file
open docs/agent-console/index.html
# Or serve with Python
cd docs/agent-console && python -m http.server 8080
```
## Macro Language .pqm
`programs/research_loop.pqm` β declarative research logic compiled to ROM.
```
program research_loop
const fuel_budget=12, min_sources=3
entry: fuel fuel_budget
plan: request search, query("topic decomposition") -> await -> verify -> branch_invalid retry_plan
search: request search, subquestion batch -> await -> verify -> evidence -> coverage -> branch_lt min_sources, search
read: request fetch, selected -> await -> verify -> evidence -> disagreement -> branch_true critique
synthesize: request local_model, render_cited_answer -> await -> verify -> emit final -> halt
critique: request search, counterevidence -> await -> verify -> jump synthesize
```
Compiler: `lexer -> parser -> typed AST -> policy checker -> CFG -> label resolution -> opcode selection -> .pqr + .pqmap + manifest.json`.
## API Endpoints (Research Host)
All via `ResearchBroker` -> `Adapters.*`. Every adapter returns normalized TLV-compatible maps with `source_hash`.
* **Tavily** `Adapters.Search` β `POST https://api.tavily.com/search`
* **Wikipedia** `Adapters.Wikipedia` β `GET https://en.wikipedia.org/w/api.php`
* **Mathematica** `Adapters.Mathematica` β `POST https://api.wolframalpha.com/v1/query`
* **Dictionary** `Adapters.Dictionary` β `GET https://api.dictionaryapi.dev/api/v2/entries/en/<word>`
* **Fetch** `Adapters.Fetch` β generic GET with allowlist
* **Browser** `Adapters.Browser` β Playwright automation
* **Code** `Adapters.Code` β sandboxed Python/JS
* **Local Model** `Adapters.LocalModel` β Ollama/LM Studio
## Run (Elixir Backend)
```bash
mix deps.get
mix test
iex -S mix
# Phoenix at http://localhost:4000
mix compile.pqm programs/research_loop.pqm --out priv/rom/
```
## Layout
```
cfg/macro_rom.cfg
asm/crc16.s
docs/agent-console/ # Frontend (static, GitHub Pages)
apps/AgentConsole/ # Swift frontend
java-sdk/ # Java SDK (Maven)
lib/perplexity_macro/ # Elixir backend
proofs/MacroProtocol.lean # Verification
programs/research_loop.pqm # VM programs
priv/rom/ # Compiled ROM
```
## License
**Sovereign Source License v1.0**
Copyright (c) 2026 Ahmad Ali Parr + Jessica Westerhoff
BEL ESPRIT D ACCORD TRUST HOLDINGS INC.
This software is provided under the Sovereign Source License. Use, modification, and distribution are permitted only as authorized by the copyright holders. Patent Pending.
|