open-standards/wai/wai-quantum-views/README.md
Transaction Science 2778ddd525 wai-quantum: the planner under a contract, its reasoning sealed, a provider's answer shadowed
Re-landed from PR #668 (branch wai/quantum-planner-contract, merged with main
495651ddd at 37350335b) as one commit on main, under the land-it model. Five
review rounds; round 5's findings (two high: workers that died as PID 1) were
fixed on the branch, and its CI reds were traced and fixed before landing.

A job may carry a contract (deadline, energy ceiling, cost, accuracy); the
planner chooses a route that meets it or refuses with every route's reason,
and its reasoning is sealed in the receipt. Under #676's reading child the
contract job is planned in the child from the per-method timings the parent
sends, bounded as a job naming its chosen method plus its reasoning, kept
across a restart. Both verifiers (Rust and receipt_verify.py) check the
planner statement beside wasmQ's; the receipts corpus is regenerated with
both kinds (268 crafted receipts, 14 plants caught). The views page carries
its engine raw-deflated and stays under its 1 MiB limit (669,484 bytes).

Passed before the push (Framework, linux; M3, macOS): every repository
check, receipts conformance, breaking, corpora, catalogue, the qpu clients,
energy (wai-rs, wai-quantum full, serve), the CLI tests and clippy, writer,
smoke, cross-simulator corpus, job receipts, wasmQ tests and vectors, the
engine with and without receipts under -D warnings, the docs pages, and the
service suite with clippy.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-09 17:42:46 -05:00

2.7 KiB

wai-quantum-views

The engine inside WAI Quantum's views for agent hosts. A host that draws interactive views (the Model Context Protocol's extension io.modelcontextprotocol/ui, version 2026-01-26) draws a tool's answer from a ui://wai-quantum/* resource: one self-contained page, in a sandboxed frame, with no network (wai_quantum::engine::views). The page draws what the server's engine computed. What it computes itself, the check of the receipt of what it shows, it computes with this crate: the engine's own job::verify, built for WebAssembly and, from the WebAssembly, translated to JavaScript, since a host's content-security policy may refuse to compile WebAssembly (the extension's default policy does) while the page's own script runs.

The interface has no imports: wq_alloc a buffer, write a request (JSON) into it, wq_call it, and read the answer (JSON) at wq_out. The requests are {"op": "verify", "job": {"request", "result"}} (the answer {"valid", "key", "signer"}) and {"op": "version"}.

Building the page

cd wai/quantum-studio && npm ci     # binaryen, pinned, and esbuild
bash wai/wai-quantum-views/build.sh # writes wai/wai-quantum/views/

build.sh builds this crate for wasm32-unknown-unknown (paths remapped out of the binary), optimises it for size and translates it to JavaScript with binaryen, and runs wai/quantum-studio/build-views.mjs, which bundles the views (wai/quantum-studio/src/views/, from the Studio's components) and writes the page and its manifest.json: each part's size and SHA-256, and every source with its SHA-256. The page is 654 KB: the script 94 KB (the Studio's English words among it), the styles 50 KB, and the engine, 335 KB as WebAssembly and 684 KB as JavaScript, each carried raw-deflated (156 KB and 226 KB; 208 KB and 301 KB in base64) and inflated by the page with the platform's DecompressionStream. The JavaScript, which runs only where a host's policy refuses WebAssembly, is then run as an inline script of the page's own. Every view is held under 1 MiB.

On x86_64 Linux with Rust 1.98.0 the build gives the same bytes in a clean CI image. The engine's bytes change when anything in wai-quantum changes (its code is laid out anew), so CI holds the page's script and styles to their sources and warns of an engine to rebuild; the scripted host (wai/quantum-studio/test/views.test.mjs) holds the committed page's engine, in both forms, to the receipts the current servers seal.

Tests

cargo test --release here: a sealed job verifies through the three exports, a changed count or verdict does not, and a compile's certificate verifies. CI: .github/workflows/wai-quantum-views.yml.