open-standards/wai/wai-quantum-views/build.sh
Transaction Science d4d5f4dd48 wai-quantum: the engine's answers as views inside agent hosts, the receipt checked in the view
Both MCP servers serve six ui:// views (a circuit, a result with its
verdict, a receipt, a critique, an estimate's frontier, a device target's
map) through the protocol's extension for interactive views, version
2026-01-26, to a host that says it draws them: each tool names its view in
_meta.ui.resourceUri, the view's data (the engine's layout and the circuit
in words, a target's map) rides in the result's _meta, and the service's
poll_quantum_job, which a view calls while a job runs, is kept from the
model. The service keeps no session, so the client's word travels in the
session id it is given at initialize. Every host gets each such answer in
plain words.

The views are one self-contained page (736 KB, held under 1 MiB) built from
the Studio's components, carrying the engine (wai-quantum-views) as
WebAssembly and translated to JavaScript. Under the extension's default
content-security policy the browser refuses WebAssembly, so the JavaScript
form checks the receipt there; a scripted host in a headless browser draws
every view from both servers under both policies and holds the check, a
changed result, the size and no outside request. The page rebuilds to the
same bytes in the CI image.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-28 08:42:54 -04:00

35 lines
2.2 KiB
Shell
Executable file

#!/usr/bin/env bash
# Build the page every view of WAI Quantum is served from: this crate for
# WebAssembly, the same build translated to JavaScript, and the page around
# them (wai/quantum-studio/build-views.mjs). Writes wai/wai-quantum/views/,
# which the engine serves (wai_quantum::engine::views) and the repository keeps.
#
# bash build.sh [OUT_DIR]
#
# It needs Rust with the wasm32-unknown-unknown target and Node with
# wai/quantum-studio's packages installed (npm ci there): binaryen, pinned in
# its package.json, optimises the WebAssembly and translates it. The build is
# the same bytes on every host with the same toolchain: paths are remapped out
# of the binary and nothing in it names the time or the machine.
set -euo pipefail
here=$(cd "$(dirname "$0")" && pwd)
root=$(cd "$here/../.." && pwd)
studio="$root/wai/quantum-studio"
out=${1:-"$root/wai/wai-quantum/views"}
target=${CARGO_TARGET_DIR:-"$here/target"}
# The standard library's own sources, where rust-src is installed, read as they do where it is not.
sysroot=$(cd "$here" && rustc --print sysroot)
commit=$(cd "$here" && rustc -vV | sed -n 's/^commit-hash: //p')
export RUSTFLAGS="--remap-path-prefix=$root=/open-standards --remap-path-prefix=${CARGO_HOME:-$HOME/.cargo}=/cargo --remap-path-prefix=$sysroot/lib/rustlib/src/rust=/rustc/$commit"
(cd "$here" && cargo build --locked --release --target wasm32-unknown-unknown)
wasm="$target/wasm32-unknown-unknown/release/wai_quantum_views.wasm"
tmp=$(mktemp -d)
trap 'rm -rf "$tmp"' EXIT
features="--enable-bulk-memory --enable-sign-ext --enable-mutable-globals --enable-nontrapping-float-to-int --enable-multivalue --enable-reference-types"
cd "$studio"
# The WebAssembly the page carries: optimised for size, its custom sections dropped.
npx --no-install wasm-opt $features -Oz --strip-debug --strip-producers "$wasm" -o "$tmp/views.wasm"
# The same, lowered to what the translation takes, and translated to JavaScript.
npx --no-install wasm-opt $features --llvm-memory-copy-fill-lowering --llvm-nontrapping-fptoint-lowering --signext-lowering "$tmp/views.wasm" -o "$tmp/lowered.wasm"
npx --no-install wasm2js -Oz "$tmp/lowered.wasm" -o "$tmp/views.mjs"
node "$studio/build-views.mjs" --wasm "$tmp/views.wasm" --js "$tmp/views.mjs" --out "$out"