Commit graph

23208 commits

Author SHA1 Message Date
Sebastian Herrlinger
4908880798 fix(widgets-rs): the web host reports fetch errors and GPU op errors with the template's line
The host passes the template's lines to the run (programLines), reports a fetch rejection the program let escape in
phase fetch (by the run's error's kind), and reports a GPU batch's errors at its post's line and column (the frame
request that carried it). scripts/report-check.ts checks the six cases' reports in headless Chromium.
2026-11-26 20:20:46 +01:00
Sebastian Herrlinger
bca83284a1 fix(widgets-rs): widget-web locates live failures in the widget template and keeps fetch kinds
LiveOptions::program_lines (startLive's programLines) declares the template's lines (Runtime::program_lines), so an
error raised in the preludes is at the template's nearest line. A fetch rejection is a located error with its kind,
and uncaught it is the run's error of that kind (CapabilityDenied, ...), raw or rethrown by widget.fetch. A GPU batch's
post carries its line and column (`at`) for the client's errors in it, and an invalid draw fails at its post
(Error::Draw has a line and column). Tests: the five cases natively, on the real preludes.
2026-11-26 20:20:46 +01:00
Sebastian Herrlinger
d8b0f68fcb feat(widgets): psychoscript 0.1.2 and psychoscript-mobile 0.2.0; widget.fetch rethrows the host's error
The prelude rethrows a fetch rejection that has a kind (the same { kind, message }) instead of a copy, so a host's
location and kind for it stay. widgets-rs takes psychoscript 0.1.2 and psychoscript-mobile 0.2.0 (program_lines,
fetch kinds, GPU errors at their post).
2026-11-26 20:06:14 +01:00
Sebastian Herrlinger
761635c74c build(widgets-rs): psychoscript 0.1.1, psychoscript-gpu and psychoscript-mobile 0.1.0 from crates.io
No git dependency on PsychoScript; wgpu-hal stays patched to its vendored Metal fix, now at PsychoScript dev 2ef493f (a
published crate can't carry it).
2026-11-26 18:32:16 +01:00
Sebastian Herrlinger
1ffc2f39dc fix(widgets-rs): widget-mobile's build scripts find psychoscript-mobile from crates.io too 2026-11-26 17:44:58 +01:00
Sebastian Herrlinger
6b1fa48913 fix(widgets-rs): the wasm build remaps cargo's git checkouts too
psychoscript now comes from PsychoScript's git rev (patched, as the other crates use it): without the remap the
module carried this machine's checkout paths in its panic messages.
2026-11-26 15:40:47 +01:00
Sebastian Herrlinger
4c7bfdf717 docs(widgets-rs): widget-mobile's encoder and test docs say what they do now 2026-11-26 15:33:38 +01:00
Sebastian Herrlinger
65797cd22f docs(specs): widgets-gpu's host side points to psychoscript-gpu's README
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.
2026-11-26 15:32:10 +01:00
Sebastian Herrlinger
d808c71598 docs(widgets-rs): the workspace's README, and widget-mobile's own README
packages/widgets-rs/README.md: the crates, how PsychoScript's crates are pinned and bumped, the toolchain and the
commands. widget-mobile/README.md replaces the copied psychoscript-mobile README: what the crate adds (the widget
encoder's behaviour, ShaderCanvas, OpenCode widgets on this API with widgetEncoder()), its build outputs and its tests;
psychoscript-mobile's README covers the rest.
2026-11-26 15:32:10 +01:00
Sebastian Herrlinger
d63f5c5cf3 Merge branch 'widgets-rs-web' into widgets-rs
# Conflicts:
#	packages/widgets-rs/.gitignore
#	packages/widgets-rs/Cargo.lock
#	packages/widgets-rs/Cargo.toml
2026-11-26 15:26:43 +01:00
Sebastian Herrlinger
6efe36ffe9 fix(widgets-rs): widget-mobile's Swift bindings get a file of their own in the PsychoScript module
uniffi-bindgen-swift names a crate's Swift file after its module_name: with psychoscript-mobile's name it overwrote
PsychoScript.swift. WidgetMobile.swift is compiled into the same `PsychoScript` target (its helpers are fileprivate).
2026-11-26 15:23:18 +01:00
Sebastian Herrlinger
045607ce9e feat(widgets-rs): widget-wire and widget-mobile, the widget layer the apps ship
A Rust workspace for the widget hosts' native code, on PsychoScript's crates by git rev (psychoscript-gpu and
psychoscript-mobile aren't on crates.io yet; psychoscript patched to the same rev, and wgpu-hal to its vendored Metal
fix).

- widget-wire: the binary wire format, from psychoscript's mobile branch; GPU batches are psychoscript-gpu's `Arg`
  and `Batch`, and the `wgsl` shorthand moved here with it. Its tests read packages/widget/test/fixtures in place:
  all 58 wire fixtures and draw.json.
- widget-mobile: the one native library each app ships, psychoscript-mobile's UniFFI API plus the widget encoder
  (`widgetEncoder()`, on psychoscript-mobile's LiveGpu) and `ShaderCanvas`; built by psychoscript-mobile's
  build-ios.sh and build-android.sh. Its widget and GPU tests moved here, on packages/widget's preludes and fixtures
  in place (the 58 wire and 53 GPU fixtures).
2026-11-26 15:17:54 +01:00
Sebastian Herrlinger
64b294433e feat(widgets-rs): web, the browser widget host on widget-web
packages/widgets-rs/web: PsychoScript's web/ (web branch e16ce7e), the TypeScript host that runs widgets in Web
Workers on widget-web's WebAssembly, as package widget-web.

The module is widget_web_bg.wasm (was psychoscript_web_bg.wasm): scripts/build-wasm.sh builds crate widget-web in the
workspace one level up, with the opencode checkout's root remapped to /opencode, and the worker, the host's default
module URL, build.ts and the package's exports follow. dist/ is no longer committed (it holds the ~10 MB module):
bash scripts/build-wasm.sh && bun run build makes it. The scripts read the fixtures and preludes in place from
packages/widget, and fixtures.ts takes it by default. The bundle is otherwise byte for byte the web branch's.
2026-11-26 15:08:19 +01:00
Sebastian Herrlinger
f90b351ae8 feat(widgets-rs): widget-web, PsychoScript's browser bindings as a crate here
A new Rust workspace, packages/widgets-rs, with crates/widget-web: psychoscript-web from PsychoScript's web branch
(e16ce7e), renamed (lib widget_web), on psychoscript 0.1 from crates.io instead of a path to a patched copy.

psychoscript 0.1 always has typed arrays, so the two Runtime::typed_arrays(true) calls go, and the test that a plain
run has none now says every run has them. Otherwise the code is as it was.

The tests read the fixtures (packages/widget/test/fixtures) and the preludes (packages/widget/src) in place instead of
copies. The views they compare byte for byte, the copies' <name>.wire files (JSON.stringify(view)), are now written
from each fixture's view in the test, the same bytes for all 46.
2026-11-26 14:58:25 +01:00
OpenCode Agent
9e274cdc0f fix(core): the wheel reaches a widget only under pointer capture
Without capture the wheel scrolls the page or transcript and is never delivered; under capture it
is { kind: "wheel", dx, dy }, where captured moves go, summed per frame. The Wheel type and the
wheel wire fixture lose x and y; the prelude is unchanged.
2026-11-23 17:54:45 +00:00
OpenCode Agent
e2a4c7a3ce feat(core): a wheel pointer event for canvases that take input
widgets-input.md specifies { kind: "wheel", x, y, dx, dy } in logical pixels (lines 40 px, pages
the canvas's size), summed per frame, delivered as move is, and { kind, dx, dy } under capture.
The prelude passes it to onPointer and leaves widget.pointer alone. Two wire fixtures (wheel,
wheel-captured) take the TypeScript host's outcome, as protocol 1's prelude doesn't know the event;
four fixtures' prelude line numbers move by 5.
2026-11-23 17:49:10 +00:00
OpenCode Agent
9bc542c8aa docs(specs): a dev-mode fps readout on animating canvases 2026-11-23 16:44:04 +00:00
OpenCode Agent
7684bebebe docs(specs): GPU canvases on Android need API 35 or newer, never only 35 and 36 2026-11-23 16:23:43 +00:00
OpenCode Agent
d32d15ab59 docs(specs): client-error reasons are dev mode only, captured once per state change
Outside dev mode client errors are neither logged nor shown, as before. The reason is captured when
a canvas becomes unavailable or stops, never per frame, batch or call, so nothing on a hot path pays
for it with dev mode off.
2026-11-23 15:03:33 +00:00
OpenCode Agent
9226059764 docs(specs): client errors carry an exact reason, shown on the widget in dev mode
Every client error and GPU-unavailable state has a reason; clients log it, and in dev mode show
it under the canvas placeholder or as a dev line on the widget. Outside dev mode nothing more
shows.
2026-11-23 15:01:10 +00:00
OpenCode Agent
eec50d96c6 docs(specs): program budgets count the program thread's CPU time
The step timeout, the live slice and the draw budget count CPU time, so a loaded machine no
longer stops an idle widget as a program error; a 10x wall-clock backstop remains for a program
stuck in a synchronous host call. The web worker and the TypeScript host stay on wall clock, and
say why.
2026-11-23 13:02:35 +00:00
OpenCode Agent
2364311f19 fix(core): one GPU reset is one strike, however many losses it brings
A loss is a strike only if the run's GPU work finished on a device since its previous strike (or
its start): a recovery that discards each new device's first work lost Rune's device four times
and stopped an innocent widget. LiveWidget.loseDevice takes { inFlight, finished }; fixture loss
inputs carry finished; hang-one-reset-several-losses shows three losses in one reset stop nothing.
2026-11-23 12:24:55 +00:00
OpenCode Agent
c975131d67 docs(specs): cite Google Play's User Generated Content and AI-Generated Content policies
Item (b) quotes both (checked 2026-11-23): sharing needs accepted terms of use, and agent-made
widgets, as AI-generated content, need in-app reporting too.
2026-11-23 11:09:12 +00:00
OpenCode Agent
c6d7f12987 docs(specs): the store-policy requirements widgets must meet
widgets-store-policy.md quotes the Apple App Review Guidelines, Google Play's Device and Network
Abuse and REQUEST_INSTALL_PACKAGES policies and Android developer verification (checked
2026-11-23): what already complies, the to-do list of cross-host features (network consent,
report and block, an index with universal links, an age gate, the 4.7.2 statement, what never to
add, no generated per-widget apps) and the open questions for Apple. widgets.md links it.
2026-11-23 11:07:54 +00:00
OpenCode Agent
0a6b8ba1b4 feat(core): browser-style GPU hangs: two strikes in 30 s stop a run
widgets-gpu.md drops the 30 ms aborted-work and 250 ms-at-loss rules, keeps the 250 ms unfinished
rule, and adds strikes: a device loss while a run has GPU work in flight is a strike, and two 30 s
apart or less stop every GPU canvas of the run ('the GPU work hung; the canvas is stopped').
LiveWidget.loseDevice takes inFlight and applies it; fixture loss inputs carry inFlight, and two
new fixtures show a stop and a loss with no work in flight being no strike.
2026-11-23 10:50:35 +00:00
OpenCode Agent
810f458dea test(core): error-too-many-draws gets its batches from its source
Its 20,000 generated ops aren't recorded: "batches": "from-source" tells drivers to run the
source for them, as they run raw programs. The GPU fixtures go from 668,839 to 147,200 bytes.
2026-11-23 10:31:18 +00:00
OpenCode Agent
2aaf246ec3 docs(specs): a batch that fails at op i keeps what ops 0..i-1 did
As separate WebGPU calls would: resources made, writes and submits before it take effect; an
encoder or pass still open at op i is dropped. The host checks' handle state already does this;
error-keeps-the-ops-before-it shows a later batch using a handle the failed batch made.
2026-11-23 09:54:51 +00:00
OpenCode Agent
88fdba88db docs(specs): a submit the GPU aborted after 30 ms is a GPU hang; one message for hangs
macOS aborts heavy work about 50 ms in, before any time threshold, and blames other queues; hosts
that can tell (Metal, through a host hook) count an aborted submit that ran 30 ms as a hang. Every
hang stop says 'the GPU work hung; the canvas is stopped'.
2026-11-23 08:10:25 +00:00
OpenCode Agent
87e4f52969 docs(specs): the GPU-hang threshold is 250 ms, below the macOS watchdog
The watchdog (~0.5 s) blames the app's queue and the killed work looks finished, so the at-loss
rule never fired. A submit unfinished 250 ms after it stops its canvases: 'the GPU work took over
250 ms; the canvas is stopped'. The at-loss rule stays, as a safety net.
2026-11-23 07:36:34 +00:00
OpenCode Agent
025edf0ee0 docs(specs): GPU hangs on a queue widgets share blame only the hung submit's widget 2026-11-23 07:12:58 +00:00
OpenCode Agent
34e06478f5 docs(specs): a device loss blames the oldest submit running 250 ms as a GPU hang
The macOS watchdog kills hung work at about 0.5 s, before the 1 s rule, so each loss restarted the
heavy widget. At a loss, the oldest unfinished submit that had run at least 250 ms counts as a GPU
hang; no loss reason needed.
2026-11-23 07:12:23 +00:00
OpenCode Agent
1ef86872b1 docs(specs): a GPU hang that draws into no canvas stops every GPU canvas
As for a program error that renders into none.
2026-11-23 06:21:38 +00:00
OpenCode Agent
4678e59dd8 docs(specs): a GPU hang stops its canvases for the run
GPU work (a live batch or a wgsl shader frame) still unfinished 1 s after its submit stops every
canvas it draws into: a client error 'the GPU work took over 1 s; the canvas is stopped', ahead of
the 50 ms shader rule. A device loss after it doesn't restart those canvases.
2026-11-23 06:21:15 +00:00
OpenCode Agent
9b94a46b77 test(core): widget tests don't depend on wall-clock limits; spec the slow-shader stop
Tests that don't prove the 250 ms step timeout or the 50 ms live slice run with limits no test
comes near (test/limits.ts); those that prove them set them. The post-rate test waits until all
30 renders are posted (a send marks it) instead of assuming the loop ends within a few turns.
20 full runs under load, all green.

widgets.md: a host never submits a shader frame while the previous one draws; one still
unfinished 50 ms after its submit three frames in a row stops on its last frame, a client error
'the shader took over 50 ms a frame, three frames in a row'.
2026-11-23 05:42:40 +00:00
OpenCode Agent
d2c7ca8e4c feat(core): the maze example steers on touch and starts down a corridor
Drag to look and hold still to walk, beside WASD and mouse-look; it starts facing the open
corridor. widgets-input.md says touch never grants pointer capture: touches stay absolute drags.
2026-11-23 05:17:15 +00:00
OpenCode Agent
3efef1c622 test(core): GPU fixtures prove non-finite numbers stay numbers
error-nan-rows-per-image (writeTexture rowsPerImage NaN) and error-infinite-depth-clear-value
(depthClearValue Infinity) fail where null would pass. Recorded batches write a number JSON can't
hold as { "$num": "NaN" | "Infinity" | "-Infinity" }, only there.
2026-11-23 03:06:37 +00:00
OpenCode Agent
f8119b8bcc feat(core): GPU ops read as JSON reads them; restored runs are a device loss
gpu.ts reads a batch's ops as native and web hosts do: an undefined list item is null, an undefined
member absent (copying only what changes). widgets-gpu.md says so in Transport and Host checks, and
defines a run restored from a snapshot as a device loss that keeps the greatest handle and the
stopped canvases. Two new raw GPU fixtures.
2026-11-23 03:03:22 +00:00
OpenCode Agent
6fefac75b2 test(core): GPU fixtures for the batch's shape and the canvases it stops
raw-bytes-not-an-array-buffer posts valid ops into scene with a Uint8Array for bytes (stops
["scene"]); raw-ops-not-a-list posts a string for ops (stops all). Raw fixtures of the wrong shape
keep their batches, with bytes null when they aren't an ArrayBuffer and ops as posted.
2026-11-23 01:48:42 +00:00
OpenCode Agent
ddac5fcaaf feat(core): a canvas's texture is only rendered into, a host check naming the canvas
A copy from or into a canvas's texture, a write into it or a binding of a view of it fails
'<path> uses canvas "<key>"'s texture, which can only be rendered into' on every host, so the
web (RENDER_ATTACHMENT alone) and native hosts agree. configure's usage is ignored: the program's
canvas texture has usage RENDER_ATTACHMENT. Four new GPU fixtures.
2026-11-23 00:45:55 +00:00
OpenCode Agent
7111a03254 test(core): GPU fixtures record frame requests without a batch
batches now has each bare frame request in its place as { frame: true, ops: [], bytes: "" }, so a
driver replaying them ends each frame, and resets the per-frame counts, where the program did.
Only frame-counts-reset-at-a-bare-frame gains an entry.
2026-11-23 00:26:15 +00:00
OpenCode Agent
8d5400dd45 feat(core): settle the widget GPU findings from the native and web hosts
widgets-gpu.md: a pass renders into a canvas through its resolveTarget too; a batch from before
the program learned of a device loss is dropped quietly; canvases are clamped to 4096 with their
aspect ratio kept; per-frame counts reset at every frame request; a canvas is cleared once per
frame; batch-shape checks may come from the host's conversion; a canvas an error stopped stays
stopped for the run and a new device doesn't restart it; validation messages are the GPU
implementation's own.

gpu.ts and LiveWidget follow, with five new GPU fixtures and a test for stopped canvases.
2026-11-23 00:19:16 +00:00
OpenCode Agent
4a5fc3e70a refactor(core): widget host functions fail at the call with Host.error, not an Effect defect
located() throws psychoscript's Host.error of the thrown error's class and message: the same
located, real-class errors as before, without psychoscript/effect.
2026-11-23 00:08:55 +00:00
OpenCode Agent
065b86db1d build(core): widget runs have typed arrays (psychoscript rust b30b1c2, typedArrays: true)
The widget packages pin psychoscript to rust b30b1c2, where typed arrays are opt-in; steps, draws,
live runs and compiles turn them on, and widgets.md lists the globals. The GPU and wire fixtures
regenerate unchanged; without the opt-in the GPU ones fail.
2026-11-23 00:05:49 +00:00
OpenCode Agent
b18aa923d3 perf(core): live-only code moves to a live prelude, served only in live programs
prelude-live.js holds widget (with widget.gpu) and __widget_live; a step widget template's program
is prelude + "\n" + source, a live one's prelude + "\n" + livePrelude + "\n" + source, and
versions hash the program as served. Lint reserves both preludes' names; positions stay
source-relative per mode. Steps compile and run faster than before widget.gpu.

Also lands the widgets-gpu.md changes 0786c7331 described but didn't carry: the live input's gpu,
the flag globals, the normalised op shapes, error ops, which canvases an error stops, Host checks
and Conformance; and widgets-live.md's rule that GPU batches never overtake waiting posts.
2026-11-23 00:00:17 +00:00
OpenCode Agent
0786c7331c feat(core): widget.gpu, the WebGPU subset for live widgets, with host checks and conformance fixtures
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).
2026-11-22 23:51:45 +00:00
OpenCode Agent
cb1e19652c feat(core): one draw command check for every host, with shared fixtures
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.
2026-11-22 22:53:00 +00:00
OpenCode Agent
35f0712e3d feat(core): live post rate coalesces renders and draws; draw posts need a key
One rule for every host: render and draw posts take tokens from a bucket of 8 refilled at 240 a
second; over it they wait, the latest render and the latest draw per canvas key replacing earlier
ones, and go out as tokens come, or all at once when the run ends (not on a client stop). Frame
requests are idempotent and never counted or dropped, so a 120 Hz game doesn't freeze; submit,
dismiss, capture and GPU batches aren't counted, and the post rate is no longer a program error.
A draw post without a string key is an invalid post; the TypeScript host's by-id draw path is gone.
2026-11-22 20:31:17 +00:00
OpenCode Agent
816a4416dd feat(core): widget runs take views 100 levels deep (maxValueDepth 202)
Widget packages pin psychoscript to rust 7b09bac (limits.maxValueDepth); the TypeScript host runs
steps and live programs at 202, the depth of a 100-level view. Fixtures add 100-level views (one
with the deepest prop) and a 150-level one, and 101 now fails in the host's walk.
2026-11-22 14:21:12 +00:00
OpenCode Agent
0f5e90b8d9 perf(core): native draw steps emit their commands instead of returning them
__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.
2026-11-22 14:08:45 +00:00
OpenCode Agent
7fa6666a13 refactor(core): the prelude drops its in-script tree building; every host is native
The prelude keeps only protocol 2: __widget_native_step and the native live path, with handlers
found by path. The tree building, handler table and __widget_step go; tests hold the hosts to the
last prelude that had them (test/fixtures/scripted-prelude.js) and to the closure reference walk.
The spec keeps protocol 1 as history only, and says clients show protocol errors without a retry.
2026-11-22 14:05:22 +00:00