The batch format, canvas size, limits, host checks and the generic errors and device loss rules moved to
anomalyco/psychoscript rust/crates/psychoscript-gpu/README.md; widgets-gpu.md keeps the program side, the widget
messages, the wgsl shorthand and conformance. The mobile clients are widget-mobile (packages/widgets-rs) on
psychoscript-mobile and psychoscript-gpu.
The prelude records WebGPU's API (devices, contexts by canvas key, resources, pipelines, bind
groups, command encoders and passes) into batches of ops and bytes with prelude-assigned handles
and every default filled in; batches ride frame requests, or go before other waits and at the
end. device.lost, unavailable GPUs and encoder misuse (error ops) are handled.
The TypeScript host (LiveWidget) passes { available, format } in the live input and checks
batches without a GPU: op shapes, handles and limits, with exact messages; an error stops the
canvases its batch renders into, else all. GPU batches never overtake waiting renders or draws.
widgets-gpu.md gains the normalised op shapes, the host checks and the conformance driver;
test/fixtures/gpu holds 34 fixtures, among them four example widget templates (a lit cube, a
textured quad, post-processing, a first-person maze).
widgets.md (Canvas, Draw command checks) states the rules: lengths before arguments, finite
numbers, alpha and stop offsets clamped to 0..1, text size to 1..512, a negative stroke width 0,
only the spec's weights, aligns and caps, a string text, an optional text style, null object
fields failing, extra elements failing, and the exact messages (draw command <i>: <reason>).
The TypeScript host checks with src/draw.ts instead of its schema and gives normalised commands;
test/fixtures/draw.json holds 89 cases, checked alone, through a draw step and a live draw.
__widget_native_step hands a draw's commands to __widget_emit and returns nothing, so hosts skip
the result conversion; they read the commands as JSON would and check them as a draw output, with
the same failures. Tests hold draws of every built-in and edge cases to the last prelude's results.
- __widget_native_step(__input()) hands the view to the host global __widget_emit and returns the
rest of the step output as the run's result, under its JSON rules; the TypeScript host uses it.
- The prelude's first line declares __widget_protocol = 2; hosts refuse older programs as a program
error (ask the agent to post it again) and newer ones as a client error.
- Keys are strings, numbers or booleans, and views nest at most 100 levels; both are program errors
in phase view, in the prelude's tree building and in native hosts. The boundary depth for 100
levels is 202.
- A function in a host call's argument anywhere but a node's handler props fails the call with the
runtime's TypeError, the view's included.
- Wire fixtures gain the run's result, failures, keys, depth and JSON edge cases.
A host that passes true to __widget_step / __widget_live gets views with handler functions as
psychoscript function markers, assigns path ids itself and returns from a render post whether the
view has handlers; the prelude finds handlers by following an id's path, and live draws post the
canvas key. Without true the prelude builds the tree as before, so wire views are unchanged.
The spec defines the algorithm; the wire fixtures gain the view as built and edge cases, and
tests check both modes against them.