Commit graph

228 commits

Author SHA1 Message Date
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
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
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
OpenCode Agent
523750c6a1 feat(core): widget protocol 2: split native step output, keys and depth rules, function rule
- __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.
2026-11-22 13:25:02 +00:00
OpenCode Agent
d10749cfce perf(core): widget runners compile each program once; host errors keep the call's position
step, draw and LiveWidget run programs from a bounded cache of compiled programs (Runtime.compile,
the 32 last used). LiveWidget's host functions throw through psychoscript/effect defects, so an
error for posting a function (or an unknown canvas key) reports the call's line and column, as the
interpreter's own argument errors do.
2026-11-22 03:49:09 +00:00
OpenCode Agent
8a565c6b84 feat(core): the TypeScript widget host builds view trees natively, on psychoscript's function markers
step, WidgetSession and LiveWidget run programs under translate.functions "mark" with the native
entry, build the tree in src/tree.ts (byte-identical to the wire fixtures), map live draw keys to
canvas ids, return from a render post whether its view has handlers, and fail functions where
none may go as the interpreter did. Widget packages pin psychoscript to rust c630d87.
2026-11-22 03:43:43 +00:00
OpenCode Agent
60732569af feat(core): native widget hosts build the view tree; the prelude hands them views as built
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.
2026-11-22 03:08:29 +00:00
OpenCode Agent
752e20b710 docs(specs): binary encoding failures follow today's invalid-output rules; standalone GPU batch kind 2026-11-22 02:01:01 +00:00
OpenCode Agent
ec09010ed4 docs(specs): binary format for widget step outputs and live posts on mobile 2026-11-22 01:52:27 +00:00
OpenCode Agent
8820437ef8 docs(specs): the widget heap cap applies to steps and draws too 2026-11-22 01:12:08 +00:00
OpenCode Agent
d7097dae16 docs(specs): physical stack directions; only a canvas with onPointer takes input (pointer: true) 2026-11-22 00:28:23 +00:00
OpenCode Agent
7e383bba95 docs(specs): mobile widget runs go through psychoscript-mobile 2026-11-22 00:23:13 +00:00
OpenCode Agent
aeb1f9266a docs(specs): never draw a widget canvas with a zero size 2026-11-22 00:06:28 +00:00
OpenCode Agent
d4597117e1 docs(specs): settle the widget WebGPU subset's open questions 2026-11-21 23:54:01 +00:00
OpenCode Agent
c61cff66c9 docs(specs): a WebGPU subset for live widget canvases 2026-11-21 23:54:01 +00:00
OpenCode Agent
d30febe837 feat(core): a stack node layers its children, for HUDs over a canvas 2026-11-21 23:54:01 +00:00
OpenCode Agent
94bf3c9fcf feat(core): one canvas node draws with 2D commands or a WGSL shader; remove the shader node 2026-11-21 23:54:01 +00:00