manifoldxplan · web target 5b execution: subagent-driven, one queue worker per task#1402026-11-07
0 of 0 done

Web target, plan 5b: events and widgets

The second of slice 5's three plans. Frame code in the page gets engine.emit and handlers that run, the desktop's input events with their payloads, a frame event with engine.elapsed, a wall clock read through time.time(), random.Random bit for bit, and the five widgets a phone app needs: Button, Slider, Toggle, Image and a new Joystick, which lands on the desktop first. A page that frames the export talks to it through events. It ends with examples/web_crowd.py carrying a panel of all five widgets and a handler per event, replayed with no mismatch in Node and in Chromium, where Playwright drives each widget with a real pointer.

goalExport examples/web_crowd.py with a second panel: a Button throws a wave, a Slider sets gravity, a Toggle turns the spin on and off, a Joystick blows a wind over the boxes, an Image shows an SVG. Handlers on frame, the seven input events, every widget event and an app event (fell) keep counts in engine.state. The Python, Node and Chromium replays deliver the same events in the same order, frame by frame. architectureOne event queue per side, in the desktop's order (Engine._draw_frame, src/manifoldx/engine.py:1238-1247): the frame event, then what was emitted during the previous frame, then the events that came in since. The replay frame gains events, the input events and outside emits the page saw, in order, and clock. A pointer event over a widget carries the widget and the pointer's place inside it, because the page's DOM is its hit test; the desktop's GUI bridge gets a seam so the Python replay reads that target instead of hit-testing its own layout. Widget events then come out of the desktop's own widget code in Python, and out of a port of it in manifoldx.js, one frame after the pointer event, as on the desktop. techPython 3.13 and numpy 2; plain ES modules; Node 20+ for node --test and the replay; three.js 0.186.1 as vendored; Playwright with Chromium in the existing browser CI job on lavapipe, with a touch context and the DevTools protocol for two pointers at once. spec.knowledge/analysis/2026-11-07-web-target-slice5-design.html (approved; sections 02, 06, 07, 10, 12 and 13, Q1, Q4 and Q5 of section 16) builds onplan 5a (merged as #166), and plans 1 to 3 before it. This plan's branch is feat/web-target-5b from main at db6ef90; its PR targets main. Plan 5c (skinned entities and the second consumer) follows it. code it changesdesktop: src/manifoldx/input.py, src/manifoldx/gui/bridge.py, slider.py, painter.py, __init__.py, new joystick.py. web: src/manifoldx/web/ gui.py, snapshot.py, reach.py, types.py, transpile.py, replay.py, and in js/: pyrt.js, manifoldx.js, input.js, gui.js, browser.js, replay.mjs. examples/web_crowd.py.

Done when

The spec's criterion for 5b, as tests

examples/web_crowd.py has a panel with a Button, a Slider, a Toggle, an Image and a Joystick, and a handler for each event the app can receive: frame, key_down, key_up, pointer_down, pointer_up, pointer_move, wheel, resize, gui:button:wave:click, gui:slider:gravity:change and :commit, gui:toggle:spin:change, gui:joystick:wind:change and the app's own fell.

Replay, Python against Node: compare(replay_python(...), replay_node(...)) is None in tests/web/test_web_crowd.py on a 600-frame script whose frames carry key, pointer, wheel and resize events and pointer events routed to each widget. The trace's new events key (the names delivered each frame, in order) is part of the comparison.

Chromium: tests/web/browser/test_web_crowd_page.py drives each widget through Playwright's mouse (click the Button, drag the Slider, click the Toggle, drag the Joystick, press an arrow key after clicking the Slider) and a two-pointer touch (the Joystick held while the Button is tapped); compare(replay_python(page_frames), page_trace) is None, and the frame checks pass: the frame of each press holds its pointer_down with that widget's index, the next frame's trace delivers its gui: event, the clock never runs backwards.

Breaking tests, each shown to make compare fail (task 10, and task 11 for the last): emits delivered in the frame that made them; a widget's value changed after its event is queued instead of before; the random state not loaded from the export; one pointer capture for all pointers instead of one per pointer. 5a's four breaking tests still fail as they did. CI's test and browser jobs are green.

Global constraints

Review focus

File structure

fileresponsibility
src/manifoldx/input.pyPointerEvent.pointer_id: int = 0 (task 1)
src/manifoldx/gui/bridge.pya capture per pointer, the _locate seam, focus and arrow keys (task 1)
src/manifoldx/gui/slider.pySlider._on_step(sign, engine) (task 1)
src/manifoldx/gui/joystick.py, painter.py, __init__.pythe Joystick widget, painted like the Slider, exported from manifoldx.gui (task 2)
src/manifoldx/web/js/pyrt.jsRandom, MT19937 as CPython's; $rt.setClock, $rt.time_time
src/manifoldx/web/js/manifoldx.jsEventBus, advance(app, frame, dt), the input event objects, GuiBridge and the widget hooks, the widgets' runtime objects
src/manifoldx/web/js/input.jsFrameBuilder records events (with widget targets) and clock; emit(name, payload) for outside events
src/manifoldx/web/js/gui.jsButton, Slider, Toggle, Joystick and Image drawn from the resolved style, ARIA, targetOf(domEvent)
src/manifoldx/web/js/browser.js, replay.mjsboth call advance; the host-page bridge; agent emits into the frame
src/manifoldx/web/gui.pygui_spec for the five widgets; widget_list(engine) in the snapshot's walk order
src/manifoldx/web/snapshot.pythe {"__random": ...} value form; the random module's state
src/manifoldx/web/types.py, reach.py, transpile.pythe surface of emit, elapsed, the event classes, the widgets, random and time.time; a handler's payload type
src/manifoldx/web/replay.pyframes delivered through the engine's own bus; event_of; the routed GUI bridge; the clock; events in the trace
examples/web_crowd.pythe controls panel and a handler per event
tests/gui/test_bridge.py, test_slider.py, test_joystick.py, test_painter.pythe desktop side
tests/web/test_random.py, test_events.py, test_input_events.py, test_clock.py, test_widgets.py, test_web_crowd.pyPython tests, most through Node (run_both, replay_node)
tests/web/apps/events.py, widgets.pysmall test apps for tasks 4 to 7
tests/web/js/input.test.mjs, gui.test.mjsthe frame builder's events and the drawn widgets, in Node
tests/web/browser/test_host_page.py, test_web_crowd_page.pyChromium: the host page, the widgets under a real pointer and two touches

Tasks

1Desktop: the GUI bridge captures per pointer, locates through a seam, and steps a focused Slider with the arrow keys (changes behaviour)input.py · gui/bridge.py · gui/slider.py · tests/gui/test_bridge.py · tests/gui/test_slider.py · CHANGELOG.md

This task changes one desktop behaviour: after a pointer goes down on a Slider, the arrow keys step it, as Q4 settled for the page and the parity rule then requires of the desktop. An app that drives its camera with the arrow keys and has a Slider sees the Slider move too once the user has clicked it, until a click lands outside every widget. The other two changes keep behaviour: PointerEvent gains a field with a default, and the bridge keeps one capture per pointer, which on the desktop is always pointer 0, so a new down still ends the capture as it does today (src/manifoldx/gui/bridge.py:53-61).

interfaces

consumes _GuiBridge (src/manifoldx/gui/bridge.py:14-88), PointerEvent (src/manifoldx/input.py:38-57), hit_test · produces PointerEvent.pointer_id: int = 0, the last field; _GuiBridge._captured: dict[int, Widget]; _GuiBridge._locate(ev) -> tuple[PointerEvent, tuple[Widget, LayoutBox] | None], the event in UI pixels and the interactive widget under it, the one method a replay replaces; _GuiBridge._focused: Widget | None, set by a pointer down that hits an interactive widget, cleared by one that hits nothing; a key_down handler on the bridge; Slider._on_step(sign: int, engine); STEPS = {"ArrowLeft": -1, "ArrowDown": -1, "ArrowRight": 1, "ArrowUp": 1} in bridge.py; SLIDER_STEPS = 20 in slider.py
  1. Write the failing tests. In tests/gui/test_bridge.py, with the file's existing engine and panel helpers: In tests/gui/test_slider.py: test_on_step_moves_a_twentieth_of_the_range (min 2, max 4, value 3, _on_step(1, eng): value 3.1 exactly as 3 + 1 * (4 - 2) / 20, events change then commit). Run uv run pytest tests/gui/test_bridge.py tests/gui/test_slider.py -q: the new tests fail (no pointer_id, no _locate, no _on_step).
  2. Implement. PointerEvent gains pointer_id: int = 0 after phase; _InputBridge._build_pointer_event leaves it 0 (rendercanvas's glfw backend has no touch, ntouches is always 0). In _GuiBridge._on_pointer: the input-capture early return stays first; then ev, hit = self._locate(ev); the captured branch reads self._captured.get(ev.pointer_id) and removes only that pointer's entry; a down that hits nothing sets _focused = None; a down that hits sets _focused = widget after dispatching. _locate holds today's scaling and hit_test call, unchanged. The bridge registers @engine.on("key_down") beside its pointer handlers, so it stays manifoldx's own handler, not a root (reach._internal); it calls self._focused._on_step(STEPS[ev.key], engine) when the focused widget is a Slider and the key is in STEPS. Slider._on_step sets value = max(min, min(max, value + sign * (max - min) / SLIDER_STEPS)), then emits :change and :commit with {"value": self.value}.
  3. Run uv run pytest tests/gui -q: all pass. A test that relied on the single capture is a finding: report it in the commit body.
  4. Add to CHANGELOG.md under [Unreleased], ### Changed: After a pointer goes down on a Slider, the arrow keys step it by a twentieth of its range (Left and Down lower it, Right and Up raise it), emitting change and commit, until a pointer goes down outside every widget (#140). Under ### Added: PointerEvent.pointer_id, 0 on the desktop; the GUI keeps one pointer capture per pointer (#140).
  5. Commit: feat(gui): a capture per pointer, and arrow keys on a focused Slider (#140), the body saying that the arrow keys are a behaviour change.
verify

uv run pytest tests/gui -q: all pass, the six new tests included. Make _captured a single slot again once: test_a_capture_is_per_pointer fails.

2Desktop: the Joystick widgetgui/joystick.py · gui/painter.py · gui/__init__.py · tests/gui/test_joystick.py · tests/gui/test_painter.py

interfaces

consumes Widget, the bridge's per-pointer capture (task 1), the painter's draw_rect · produces manifoldx.gui.Joystick(*, name: str, style=None, style_overrides=None) with _is_gui_interactive = True, _gui_captures_pointer = True, value: tuple[float, float] (starts (0.0, 0.0)), intrinsic_size() -> (96.0, 96.0), _update_from(ev), _on_pointer_down, _on_pointer_move, _on_pointer_up, each emitting gui:joystick:<name>:change with {"value": self.value} after setting it
  1. Write the failing tests in tests/gui/test_joystick.py, with test_slider.py's fake engine and pointer: In tests/gui/test_painter.py: test_joystick_paints_a_pad_and_a_knob: two RectOps, the pad the widget's box with radius == box.w / 2 in bg, the knob 0.4 * box.w wide in fg, centred at the box's centre moved by value * (r - knob / 2), y down on screen for a positive value[1]. Run uv run pytest tests/gui/test_joystick.py tests/gui/test_painter.py -q: fails on the import.
  2. Implement src/manifoldx/gui/joystick.py beside slider.py. _update_from(ev): r = min(box.w, box.h) * 0.5, x = (ev.x - (box.x + box.w * 0.5)) / r, y = -(ev.y - (box.y + box.h * 0.5)) / r, n = math.sqrt(x * x + y * y), divide both by n when n > 1.0; nothing when the box is missing or has no width. Add the painter branch after the Slider's and the import and __all__ entry in manifoldx/gui/__init__.py; the module docstring lists it among the interactive widgets.
  3. Run the same command: all pass. Then uv run pytest tests/gui -q.
  4. Commit: feat(gui): a Joystick widget (#140).
verify

uv run pytest tests/gui -q: all pass, the six new tests included.

3random.Random in frame code, MT19937 as CPython'sjs/pyrt.js · web/snapshot.py · web/types.py · web/transpile.py · js/manifoldx.js · tests/web/test_random.py

interfaces

consumes _Writer.value (src/manifoldx/web/snapshot.py), LIBS and RUNTIME_SURFACE (src/manifoldx/web/types.py:630, :659), tests/web/parity.py's run_both · produces pyrt class Random with static fromState({key, pos, gauss}), getstate() -> {key, pos, gauss}, random(), getrandbits(k) for 0 <= k <= 53, uniform(a, b), randrange(start, stop = null, step = 1), randint(a, b), choice(seq); $rt.random, the module's own instance; the value form {"__random": {"key": [624 ints], "pos": int, "gauss": float | null}}; state.json's "random" (the module instance's state, written when reached code calls a module function); RANDOM = obj("random.Random") in types.py; LIBS["random"]
  1. Write the failing tests in tests/web/test_random.py, compared bit for bit (rel=0): Run uv run pytest tests/web/test_random.py -q: fails at transpiling (random is not a library the subset knows).
  2. Runtime. MT19937 as Modules/_randommodule.c: genrand_uint32 regenerates the 624 words when pos reaches 624, then tempers (y ^= y >>> 11; y ^= (y << 7) & 0x9d2c5680; y ^= (y << 15) & 0xefc60000; y ^= y >>> 18) with Math.imul and >>> 0 wherever a product or shift could leave 32 bits. random(): a = u32 >>> 5, b = u32 >>> 6, (a * 67108864 + b) / 9007199254740992. getrandbits(k): k 0 gives 0; k up to 32 gives u32 >>> (32 - k); past 32 the words go little-endian, the last shifted right by its unused bits, as _random_Random_getrandbits_impl does; past 53 it throws. The rest as Lib/random.py of Python 3.13: _randbelow_with_getrandbits (k = n.bit_length(), draw until below n), randrange's three branches and their ValueError messages, randint(a, b) = randrange(a, b + 1), uniform(a, b) = a + (b - a) * random(), choice(seq) = seq[_randbelow(len(seq))]. gauss is carried, never used.
  3. Snapshot and types. _Writer.value writes a random.Random as the form above; when reached code names random.random, random.uniform, random.randint, random.randrange or random.choice, random._inst's state goes under "random", and loadApp sets $rt.random from it. LiveTypes.of types an instance as RANDOM; the surface gives its five methods (random and uniform NUM, randrange and randint INT, choice the element type of its list). Any other attribute of random or of an instance, a call of random.Random(...) or random.seed(...) in frame code, and from random import ... fail the export with the message above or the subset's usual one.
  4. Transpile: R.uniform(a, b) on a RANDOM is a method call on the resolved object; random.uniform(a, b) becomes $rt.random.uniform(a, b); randrange's optional arguments pass positionally.
  5. Run the same command: all pass.
  6. Commit: feat(web): random.Random in frame code, bit for bit with CPython.
verify

uv run pytest tests/web/test_random.py tests/web/test_snapshot.py tests/web/test_types.py -q: all pass, the 14 parametrized draws and the breaking test included.

4One event queue: engine.emit, the frame event, engine.elapsed, handlers in both replaysjs/manifoldx.js · js/replay.mjs · js/browser.js · web/replay.py · web/types.py · web/reach.py · tests/web/test_events.py · tests/web/apps/events.py

interfaces

consumes step and fire (src/manifoldx/web/js/manifoldx.js:862, :872), replay_python (src/manifoldx/web/replay.py:143-198), EventBus (src/manifoldx/events.py) · produces JS class EventBus (emit(name, payload = null), pending: [name, payload][], delivered: string[], drain(deliver) which swaps pending for a new list before delivering, as dispatch_pending does); engine.bus, engine.emit, engine.elapsed, engine.frame; advance(app, frame, dt), exported from manifoldx.js: engine.input.setFrame(frame), then elapsed, the queue (frame event first, the frame's events last), delivery, then step; step keeps its signature; fire is removed. Trace entries gain "events": [name], the names delivered this frame in order. Python: replay_python delivers each frame through engine._event_bus; DELIVERED records names by wrapping the bus's _deliver. Types: Engine.emit (fn, NONE), Engine.elapsed (NUM, read only); a handler's payload types as dict_of(STR, NUM) for "frame" and from its annotation otherwise
  1. Write tests/web/apps/events.py: a system tick that emits ("ping", {"n": k}) on frames 3 and 4 (counting in engine.state); @engine.on("ping") def on_ping(p: dict) appends [engine.state["frame"], p["n"]] to engine.state["pings"] and emits ("pong", {}) when p["n"] == 4; on("pong") counts; on("frame") def on_frame(p: dict) stores p["frame"], p["elapsed"] and p["dt"] in engine.state; a second on("frame") handler registered after it appends to a list, to check the registration order. Then the failing tests in tests/web/test_events.py: Run uv run pytest tests/web/test_events.py -q: fails at the export (engine.emit is not on the runtime surface).
  2. Python replay. Per frame, in this order, as Engine._draw_frame (src/manifoldx/engine.py:1221-1253): engine.input.set_frame(frame); engine.elapsed stays 0.0 on the first frame and adds dt on each later one; engine._gui_bridge.begin_frame(); each entry of frame.get("events", []) through engine.emit(name, event_of(name, payload)) (task 5 fills event_of; here it returns the payload); engine._event_bus._pending.insert(0, ("frame", {"dt": dt, "elapsed": engine.elapsed, "frame": engine._frame_index})); dispatch_pending(engine); the systems; the flush; engine._frame_index += 1. The names come from a wrapper of engine._event_bus._deliver set once per replay; the trace entry's "events" holds this frame's.
  3. Runtime. EventBus and advance follow the interfaces; delivery calls each handler root of that name in app.roots order with the payload (and a read-only Query when the root has components, as fire did). replay.mjs's replay and browser.js's runFrame call advance instead of setFrame, fire and step; the agent's events array in browser.js stays until task 9 and is passed as the frame's events. traceEntry writes bus.delivered and clears it.
  4. Types and reach. RUNTIME_SURFACE["manifoldx.Engine"] gains emit and elapsed. In Reach's root seeding (src/manifoldx/web/reach.py:248-254), a handler's first parameter types from EVENT_PAYLOADS, a new table in types.py that tasks 5 and 7 extend ({"frame": dict_of(STR, NUM)} here), unless it is annotated; an unannotated payload of another event fails with the message above.
  5. Run uv run pytest tests/web/test_events.py tests/web/test_replay.py tests/web/test_frames.py tests/web/test_node_suites.py -q: all pass; the older replays gain events: ["frame"] on both sides.
  6. Commit: feat(web): engine.emit, the frame event and handlers in the page, in the desktop's order.
verify

uv run pytest tests/web/test_events.py tests/web/test_replay.py tests/web/test_frames.py tests/web/test_node_suites.py tests/web/test_reach.py -q: all pass, the breaking test included.

5Input events: the DOM's events in the frame, their payload classes on both sidesjs/input.js · js/manifoldx.js · web/replay.py · web/types.py · tests/web/test_input_events.py · tests/web/js/input.test.mjs

interfaces

consumes FrameBuilder and attachDom (src/manifoldx/web/js/input.js), advance and EVENT_PAYLOADS (task 4), KeyEvent, PointerEvent (with pointer_id, task 1), WheelEvent, ResizeEvent (src/manifoldx/input.py:28-77) · produces the frame's optional "events", entries [name, payload]: ["key_down" | "key_up", {"key", "modifiers": [str], "is_down"}], ["pointer_down" | "pointer_up" | "pointer_move", {"x", "y", "dx", "dy", "button", "buttons": [int], "modifiers": [str], "phase", "pointer_id", "gui"?}], ["wheel", {"dx", "dy", "x", "y", "buttons", "modifiers"}], ["resize", {"width", "height", "pixel_ratio"}]; FrameBuilder records them in DOM order and take() returns them; replay.event_of(name, payload) builds the dataclass for the seven input names (tuples for the lists) and returns any other payload as is; JS eventOf(name, payload) builds frozen plain objects with the same fields; EVENT_PAYLOADS gains the four classes, and RUNTIME_SURFACE their fields (key STR, modifiers tuple_of(STR, ...), x NUM, button INT, buttons a tuple of INT, pointer_id INT, width INT, pixel_ratio NUM, ...)
  1. Write the failing Node tests in tests/web/js/input.test.mjs: And in tests/web/test_input_events.py, on tests/web/apps/events.py extended with one handler per input event (each stores its payload's fields as a list in engine.state, the pointer handler also engine.input.mouse_pos): Run uv run pytest tests/web/test_input_events.py tests/web/test_node_suites.py -q: fails.
  2. Implement in input.js: each FrameBuilder handler also pushes its event; dx, dy are this event's position minus the last pointer event's on a move and 0 on a down or up, the last position re-anchored on each, as _InputBridge._build_pointer_event (src/manifoldx/input.py:346-365); buttons are the held buttons after the event, sorted; pointer_id 0 for isPrimary, else pointerId; take(viewport) adds ["resize", {width, height, pixel_ratio}] when the viewport differs from the last frame's (not on the first frame), then returns events and resets them. keyUp of a key not held adds nothing. blur() adds a key_up per held key and a pointer_up per held button, as its releases.
  3. In replay.py, event_of as the interfaces say, used by task 4's loop; KEY_EVENTS, POINTER_EVENTS as module constants beside it. In manifoldx.js, eventOf, used by advance; other names go through fromJSON.
  4. Run the same command: all pass. Update replay.py's module docstring with the events field.
  5. Commit: feat(web): the desktop's input events in the page and the replay frame.
verify

uv run pytest tests/web/test_input_events.py tests/web/test_events.py tests/web/test_node_suites.py tests/web/test_replay.py -q: all pass.

6The clock: time.time() in frame code reads the frame'sjs/pyrt.js · js/input.js · js/manifoldx.js · web/types.py · web/transpile.py · web/replay.py · tests/web/test_clock.py

interfaces

consumes advance (task 4), LIBS · produces the frame's optional "clock", seconds since the epoch as a float, read once by FrameBuilder.take() (Date.now() / 1000), 0.0 when absent; pyrt $rt.setClock(seconds) and $rt.time_time(); advance calls setClock first; LIBS["time"] with one function, time.time (NUM); replay._clock(seconds), a context manager that sets time.time to return the frame's clock while the frame runs and restores it
  1. Write the failing tests in tests/web/test_clock.py: Run uv run pytest tests/web/test_clock.py -q: fails.
  2. Implement as the interfaces say. In the Python replay, _clock wraps the whole frame (delivery and systems); setup is outside it and sees the real time.
  3. Run the same command: all pass.
  4. Commit: feat(web): time.time() in frame code reads the frame's clock.
verify

uv run pytest tests/web/test_clock.py tests/web/test_events.py tests/web/test_node_suites.py -q: all pass.

7The five widgets in the runtime: their state, the routed bridge, the widget code on both sidesweb/gui.py · web/types.py · web/replay.py · js/manifoldx.js · tests/web/test_widgets.py · tests/web/test_gui_spec.py · tests/web/apps/widgets.py

interfaces

consumes gui_spec and GuiUnsupported (src/manifoldx/web/gui.py:24-63), _GuiBridge._locate and the per-pointer capture (task 1), Joystick (task 2), advance and event_of (tasks 4, 5), guiWidgets (src/manifoldx/web/js/manifoldx.js) · produces gui nodes for Button (name, label), Slider (name, min, max, value, label), Toggle (name, value, label), Joystick (name, value), Image (svg: the SVG text or null, size: svg_size); GuiUnsupported is left for widgets outside these; widget_list(engine) -> list[Widget], by "widget" index; a pointer payload's optional "gui": [widget, fx, fy], the widget the page routed the event to and the pointer's place in that widget's box as fractions of its width and height; Python replay._routed(engine, routes), which replaces engine._gui_bridge._locate for the replay: an event in routes (by id) becomes (replace(ev, x=fx, y=fy), (widget, UNIT)) with UNIT = LayoutBox(0.0, 0.0, 1.0, 1.0), any other (ev, None); JS class GuiBridge in manifoldx.js, a line-for-line port of _GuiBridge with the same _locate rule, and WIDGET_HOOKS, ports of each widget's _on_pointer_* and _on_step; the runtime widget objects gain the fields above and Button.was_clicked(); RUNTIME_SURFACE and WRITABLE for the five; EVENT_PAYLOADS for gui:button:*:click (dict_of(STR, UNKNOWN)), gui:slider:*:change|commit (dict_of(STR, NUM)), gui:toggle:*:change (dict_of(STR, BOOL)), gui:joystick:*:change (dict_of(STR, tuple_of(NUM, NUM))), matched by pattern
  1. Write tests/web/apps/widgets.py: one top-left panel with Button(name="go", label="Go"), Slider(name="speed", min=0, max=4, value=1, label="speed"), Toggle(name="lit", value=False, label="lit"), Joystick(name="pad") and an Image of a small SVG string; each widget a module global. A system reads GO.was_clicked(), SPEED.value, LIT.value and PAD.value into engine.state and, on frame 20, writes SPEED.value = 3.0, GO.label = "Again" and LIT.value = True; a handler per widget event appends [engine.state["frame"], payload["value"]] (the click [frame]). Then the failing tests in tests/web/test_widgets.py, whose script routes pointer events by widget index read from state.json's gui: In tests/web/test_gui_spec.py: the five nodes with their fields; widget_list(engine)[n] is the widget whose node has "widget": n; a Widget subclass outside the five still fails with GuiUnsupported. Run uv run pytest tests/web/test_widgets.py tests/web/test_gui_spec.py -q: fails at the export (Button is not supported by export --web yet).
  2. Snapshot and surface. gui_spec writes the five nodes; Image.svg_data decodes as UTF-8. RUNTIME_SURFACE: manifoldx.gui.Button name, label, was_clicked (fn, BOOL), style_overrides; Slider name, value, min, max, label, style_overrides; Toggle name, value (BOOL), label, style_overrides; Joystick name, value (tuple_of(NUM, NUM)), style_overrides; Image style_overrides. WRITABLE: Button label, Slider value min max, Toggle value, Joystick value, and style_overrides of each.
  3. Python replay. After setup, replay_python sets engine._gui_bridge._locate = _routed(engine, routes); each pointer entry of the frame with a "gui" key adds routes[id(ev)] = (widget_list(engine)[i], fx, fy) for the event object it emits. The desktop's bridge then runs as it is: the hooks, the latch, the capture per pointer, pointer_over_gui, the focus and the arrow keys.
  4. Runtime. createEngine makes engine.gui.bridge = new GuiBridge(engine); advance resets engine.gui.pointer_over_gui before delivery, and delivery calls the bridge for pointer_down, pointer_move, pointer_up and key_down before the handler roots, as the bridge's handlers were registered first on the desktop (src/manifoldx/engine.py:364). WIDGET_HOOKS follow button.py, slider.py, toggle.py and joystick.py statement for statement, setting the value, then engine.emit. The widget objects of guiWidgets carry kind, name, their fields and, for a Button, _latch.
  5. Run the same command: all pass. Then uv run pytest tests/web/test_export_web.py -q: the case that expected Button is not supported now expects the export to succeed; change it to a widget class the page lacks (a Widget subclass defined in the test).
  6. Commit: feat(web): Button, Slider, Toggle, Joystick and Image in the runtime, through the desktop's widget code.
verify

uv run pytest tests/web/test_widgets.py tests/web/test_gui_spec.py tests/web/test_export_web.py tests/web/test_events.py -q: all pass, the breaking test included.

8The page draws the widgets from their style and records where each pointer wentjs/gui.js · js/input.js · js/browser.js · tests/web/js/gui.test.mjs · tests/web/js/input.test.mjs

Two page behaviours change here, both toward the desktop's. A pointer that goes down on the GUI is also a click in the frame (buttons, clicks, pos), as the desktop's input layer records every pointer event before the GUI sees it (src/manifoldx/input.py:316); today the panels swallow it. And engine.gui.pointer_over_gui comes from the bridge (an event this frame hit an interactive widget), no longer from hovering a root panel (src/manifoldx/web/js/browser.js:170).

interfaces

consumes the gui nodes and GuiBridge (task 7), FrameBuilder (task 5), panelCss and buildGui (src/manifoldx/web/js/gui.js) · produces widgetCss(node, scale) -> {property: value} for the four drawn widgets; buildGui(layer, spec)'s result gains targetOf(domEvent) -> [widget, fx, fy] | null (the widget that holds this pointer, else the interactive widget under domEvent.target) and hold(pointerId, widget), release(pointerId); sync(widgets) also applies label, value, min, max and the ARIA values; attachDom(canvas, builder, {gui}) listens on the GUI layer for pointerdown and passes gui.targetOf(ev) to builder.pointerDown(ev, target), and the window's pointermove and pointerup pass theirs; data-mx-widget on each widget element; pointerOver is removed
  1. Write the failing tests in tests/web/js/gui.test.mjs, over the file's fake document: In tests/web/js/input.test.mjs: a pointer down on the GUI is a click and carries its target (the frame's clicks holds 1, its pointer_down payload holds gui). Run uv run pytest tests/web/test_node_suites.py -q: the gui and input suites fail.
  2. Implement in gui.js. Each widget is built from node.style (bg, fg, border, border_color, radius, font_size, times the scale), as the painter reads the same keys (src/manifoldx/gui/painter.py:214-292): the Button a <button type="button"> with its label centred; the Slider a track with a fill of width t (the painter's t), role="slider", aria-valuemin, aria-valuemax, aria-valuenow, aria-label its label, tabindex="0"; the Toggle a 14 px box, its inner mark when on, and its label, role="switch", aria-checked; the Joystick a pad of its intrinsic 96 px (or its style's size) with a knob 0.4 of its width; the Image an <img> whose src is data:image/svg+xml;charset=utf-8, plus the encoded SVG. Every interactive element has touch-action: none. On pointerdown, the Slider and the Joystick call setPointerCapture on their element and hold; pointerup and pointercancel release. Text goes in through textContent only.
  3. In input.js, FrameBuilder.pointerDown(ev, target = null) and its move and up add gui: target to the payload when it is not null. attachDom takes {gui} and wires the listeners above; positions stay CSS pixels from the canvas's top-left. In browser.js, the line that copies gui.pointerOver goes; the GUI's targetOf is passed to attachDom, and a swapped version's GUI replaces it.
  4. Run the same command: all pass.
  5. Commit: feat(web): the page draws Button, Slider, Toggle, Joystick and Image, and routes pointers to them.
verify

uv run pytest tests/web/test_node_suites.py -q: all pass. Chromium runs in task 11.

9The host-page bridge, and an agent's emit in the framejs/browser.js · js/input.js · js/manifoldx.js · tests/web/browser/test_host_page.py · tests/web/browser/test_run_web.py

interfaces

consumes EventBus and advance (task 4), encodeState and fromJSON (src/manifoldx/web/js/manifoldx.js:964, :994), the dev socket's case "emit" (browser.js:327) · produces FrameBuilder.emit(name, payload), an outside event recorded in the frame's events in arrival order, its payload plain JSON; hooks.delivered(name, payload) in createEngine, called by delivery for every event except frame and the seven input events; browser.js sets it to dispatch new CustomEvent("mx:emit", {detail: {name, payload: encodeState(payload)}}) on window and, when window.parent !== window, window.parent.postMessage({mx: "emit", name, payload}, "*"); a message listener takes {mx: "emit", name: string, payload} from window.parent only and calls builder.emit; the agent's emit calls builder.emit too, and browser.js's events array goes
  1. Write the failing tests in tests/web/browser/test_host_page.py, on tests/web/apps/events.py's export with an on("host:hello") handler (payload dict) that counts and emits ("app:ack", {"n": payload["n"]}). The test writes host.html beside the export in a temporary copy: an iframe of index.html, a message listener that collects into window.got, and a function that posts {mx: "emit", name: "host:hello", payload: {n: 2}} to the frame: In tests/web/browser/test_run_web.py, the agent's emit test now also asserts that the emitted event is in the frame's events and that a replay of the tab's frames matches. Run uv run pytest tests/web/browser/test_host_page.py -v where Chromium runs: fails.
  2. Implement as the interfaces say. A payload from the host goes through fromJSON on delivery, as an agent's does; the frame keeps the JSON, so the Python replay emits the same dict.
  3. Run uv run pytest tests/web/browser/test_host_page.py tests/web/browser/test_run_web.py -v: all pass, no skips.
  4. Commit: feat(web): a host page talks to the export through events.
verify

uv run pytest tests/web/browser/test_host_page.py tests/web/browser/test_run_web.py tests/web/test_node_suites.py -v: all pass with no skips on a host with Chromium; otherwise push and read the browser job, which fails on any skip.

10web_crowd's controls panel, a handler per event, its Node replay and the breaking testsexamples/web_crowd.py · tests/web/test_web_crowd.py · tests/web/fixtures/web_crowd_script.json

interfaces

consumes tasks 1 to 9; 5a's script, PATCHES, _copy, _patch and fixtures (tests/web/test_web_crowd.py) · produces examples/web_crowd.py with the controls panel; script(seed, n) extended with events and widget routes; WIDGETS, the widget indices read from the export's state.json; four more entries in PATCHES
  1. Extend examples/web_crowd.py, keeping its style (constants at the top, plain functions, the docstring's controls updated):
    • A second top-left panel under the first (the desktop's hit test places top-left panels only, src/manifoldx/gui/hit_test.py:42-52) with WAVE = Button(name="wave", label="Throw a wave"), GRAVITY = Slider(name="gravity", min=0.0, max=12.0, value=6.0, label="gravity"), SPIN = Toggle(name="spin", value=True, label="spin"), WIND = Joystick(name="wind") and an Image of a short inline SVG (a compass rose).
    • on("gui:button:wave:click") emits ("throw", {}); on("throw") adds 1 to engine.state["throws"]; spawn_wave throws on Space or while throws is positive, taking one.
    • drift reads gravity from engine.state["g"], which on("gui:slider:gravity:change") sets; :commit appends the value to engine.state["commits"]; the spin applies only while SPIN.value; on("gui:toggle:spin:change") counts; the wind adds WIND.value scaled by 2 m/s to x and z of v, read in the system; on("gui:joystick:wind:change") keeps the last value.
    • drift emits ("fell", {"n": k}) with the number of boxes it destroys when k > 0; on("fell") adds to engine.state["fallen"].
    • Each ring is jittered by RNG = random.Random(1107): RNG.uniform(-0.3, 0.3) per box on its radius, built with a list comprehension at the spawn.
    • Handlers on frame (keeps payload["elapsed"]), key_down and key_up (count), pointer_down, pointer_up and pointer_move (the last [x, y, pointer_id] of each), wheel (moves the camera along its view by dy, clamped), resize ([width, height]).
    • pick ignores a click while engine.gui.pointer_over_gui; WAVE.was_clicked() is read by pick to clear the pick, as a second use of the latch.
    • A system keeps time.time() % 60.0 in engine.state["sec"] and a ValueDisplay shows it, so frame code reads the clock.
  2. Extend the script in tests/web/test_web_crowd.py (regenerate the fixture with --regen): keep 5a's keys, clicks and resize, and record each as the page does (key and pointer events, a resize event at 300); add clicks routed to the Button at 60 and 61 (two clicks, two throws), a drag on the Slider from fx 0.2 to 0.9 over frames 80 to 90, a Toggle at 100, a Joystick drag at fx (0.8, 0.5) over 220 to 260 with a Button tap of pointer_id 4 at 240, a wheel at 270, an ArrowLeft at 280, a clock from 1762500000.0 growing by 1/60. Then: The four new patches each name a real text in the exported file, chosen when the code exists, as 5a's do.
  3. Run uv run pytest tests/web/test_web_crowd.py -q; fix what the replay finds in the task that owns it, and note it in this plan's departures, until all pass.
  4. Commit: feat(examples): web_crowd's controls, every widget and event in the page.
verify

uv run pytest tests/web/test_web_crowd.py -q: all pass, eight breaking cases included. uv run python examples/web_crowd.py opens a window where the five widgets work with the mouse and the arrow keys step the gravity Slider after it is clicked, checked by its --render --duration 2 MP4 or manifoldx look under manifoldx run on a host with a GPU or lavapipe.

11Chromium: each widget under a real pointer, two touches at once, the frame checkstests/web/browser/test_web_crowd_page.py · tests/web/browser/conftest.py

interfaces

consumes the browser conftest's open_page, served, crowd_export, BATCHES_OF; task 10's example and PATHS · produces open_page(..., touch=False), which makes the context with has_touch=True when asked; touch(page, points), two-finger input through page.context.new_cdp_session(page) and Input.dispatchTouchEvent; widget_box(page, name), the bounding box of [data-mx-widget] for the widget of that name
  1. Write the tests in tests/web/browser/test_web_crowd_page.py, one __mx.tick(1/60) after each step as 5a's drive does: Run uv run pytest tests/web/browser/test_web_crowd_page.py tests/web/browser/test_page.py tests/web/browser/test_visual.py tests/web/browser/test_run_web.py -v on a host with Chromium and lavapipe. Each failure is a defect of an earlier task or of the page: fix it there, and note in the departures section what the browser forced. test_page.py's drive of web_walk clicks over its panel only if it did before; if a click there now changes its trace (task 8's GUI clicks), the test's frames say so and the expectation moves with them.
  2. Commit: test(web): web_crowd's widgets in Chromium, two pointers, the frame checks.
verify

uv run pytest tests/web/browser -v: all pass with no skips on a host with Chromium; otherwise push and read the browser job, which fails on any skip.

12The docs: events, widgets, the clock, random, the host pageknow-how/web-export.md · know-how/agent-loop.md · CHANGELOG.md · AGENTS.md · examples/README.md
  1. know-how/web-export.md: replace the paragraph that says engine.emit is not there yet (line 250) with a section "Events in the page": the order of a frame's queue and that an emit waits a frame, the seven input events and their payload fields, the frame event and engine.elapsed, a handler's payload annotation, time.time() and the frame's clock; in "The GUI", the five widgets, their fields and events, what frame code may write, the arrow keys, the Joystick's y up, top-left panels for desktop parity, and that a pointer on the GUI is also a click (check engine.gui.pointer_over_gui); random.Random made at setup and seeded for replays (an unseeded generator differs between any two runs); a section "A host page around the export" with the message forms; in "Replaying", the frame's events and clock, the gui target of a pointer event, the trace's events. Add plan 5b's path to the plans line at the top.
  2. know-how/agent-loop.md: manifoldx emit reaches the tab in the next frame's events, recorded in its frames.
  3. CHANGELOG.md under [Unreleased], ### Added: events, input events, the frame event and engine.elapsed, time.time(), random.Random, the five widgets and the Joystick, the host-page bridge, web_crowd's controls. AGENTS.md's web target line: plan 5b and its path. examples/README.md: web_crowd's line names its controls.
  4. Commit: docs(web): events, widgets, the clock, random and the host page.
verify

The know-how's commands and snippets run as written: export examples/web_crowd.py, replay its fixture in Node, open the page with python -m http.server in the folder and use each widget. rg -n "not there yet" know-how/web-export.md prints nothing.

Where this plan departs from the spec

Open questions, settled

The maintainer settled all three questions on 2026-11-07 by accepting each recommendation. Each one keeps its question; its last paragraph is now the decision.

1 · Fixed timestep and engine.elapsed on the desktopsettled · maintainer

Under set_fixed_timestep, Engine.run's frames never advance engine.elapsed, so engine.delay() and elapsed_at() never resolve there; only render_frame adds the dt (src/manifoldx/engine.py:1477). The page adds every frame's dt.

decisionThe fixed timestep is out of 5b, since no replay runs that mode. Adding the fixed dt in _compute_dt on the desktop is filed as gia-uh/manifoldx#168.

2 · The arrow keys on a desktop Slidersettled · maintainer

Task 1 makes the arrow keys step a Slider after it is clicked, on the desktop as in the page. An app that steers with the arrows sees the Slider move until a click lands elsewhere. The alternative was to drop arrow keys from Q4's decision, which loses the page's keyboard access to the Slider.

decisionThe arrow keys step a clicked Slider on the desktop, and the CHANGELOG lists it under Changed as a behaviour change.

3 · Panels anchored elsewhere than top-leftsettled · maintainer

The desktop hit-tests top-left panels only (manifoldx#13), so a Button in a bottom-right panel clicks in the page and not on the desktop.

decisionweb_crowd's panels stay top-left in 5b, and #13 (anchors on the desktop) is fixed before plan 5c, whose second consumer puts its buttons in a column on a side.

Self-review

Spec coverage, 5b of section 12: emit (task 4), the input events (5), the frame's events and clock (4, 5, 6), MT19937 (3), the host-page bridge (9), Button, Slider, Toggle, Image and Joystick, desktop first (1, 2, 7, 8). Done: web_crowd's panel and a handler per event (10), its Chromium replay with each widget under Playwright's pointer and the frame checks (11). Section 13's items for 5b: random.Random over 10,000 draws per method from a seeded and a mid-stream state, rel=0 (3); the breaking tests on emits in the same frame, the widget value after its event and the random state (10); the two-pointer touch (11); Joystick in the painter and the bridge (2). Sections 06 and 07's rules: the frame event's payload and order (4), a handler's read-only query kept from 5a (4), the latch consumed on read (7), the Slider's pointer captured while dragging (1, 7, 8), ARIA roles and the arrow keys (1, 8).

Names across tasks: pointer_id, _captured, _locate, _focused, _on_step (1) in 7; Joystick (2) in 7, 8, 10; Random and {"__random"} (3) in 10; EventBus, advance, EVENT_PAYLOADS, the trace's events (4) in 5 to 11; event_of, eventOf, the frame's events (5) in 7, 9, 10; clock, setClock (6) in 10, 11; widget_list, _routed, UNIT, GuiBridge, WIDGET_HOOKS, the gui target (7) in 8, 10, 11; targetOf, data-mx-widget (8) in 11; FrameBuilder.emit, hooks.delivered (9) in 10 and 11.

Proportion: code is given for tests whose assertions carry values; implementations are named by signature and the desktop file and line they follow statement for statement.