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

Web target, plan 2: the browser page

This plan builds slice 3 of the spec: manifoldx export --web writes a page that any static server can serve, where three.js draws the exported glTF, the GUI is HTML, and browser input reaches the transpiled systems in the same frame form the replay uses. It ends with the first consumer's web build coming from export --web and its hand-written JavaScript deleted. run --web (slice 4) gets its own plan.

goalmanifoldx export --web app.py OUT/, then python -m http.server -d OUT: the page loads with a progress bar, draws the scene as the desktop does within a measured colour threshold, shows the GUI, takes keyboard, mouse and pointer lock, runs the systems every animation frame, and names the Python file and line of an error. architecturemanifoldx.js stays the engine core with no three.js and no DOM, so the Node replay keeps working; browser-only modules sit on it: input.js (DOM events to Frames, pointer lock), scene.js (glTF, extras, calibration, handles to three.js objects), gui.js (HTML panels), sourcemap.js (Python lines), progress.js, and browser.js, the bootstrap index.html loads. three.js 0.186.1 is vendored in the wheel. techPython 3.13; plain ES modules; three.js 0.186.1 (vendored, minified); Node 20+ for node --test; Playwright for Python with Chromium for the browser tests, in a separate CI job. spec.knowledge/analysis/2026-11-06-web-target-design.html (sections 06, 07, 10 slice 3, 11) builds onplan 1, merged to main as #141. This plan's branch feat/web-target-2 starts from that merge; its PR targets main. later plansplan 3: run --web (slice 4), with the overlay that quotes the Python source and the agent commands against the tab.

How the pieces fit

index.htmlimportmap, fallback text browser.jsbootstrap, loop, errors scene.js input.js gui.js sourcemap.js progress.js vendor/three manifoldx.js (core)no three.js, no DOM replay.mjs (Node)unchanged entry

Solid arrows: browser imports. Dashed: Node imports the same core. browser.js imports manifoldx.js for loadApp, step and the trace helpers.

Open questions

Settled here with a recommendation each; the tasks follow the recommendation. A maintainer's different answer changes only the task named.

Q1 · The sky calibration factor

The spec says three.js's sky comes out 8 to 16% darker. The first consumer's viewer settled on scaling scene.environmentIntensity by 1.5, measured as bringing the mean colour within 1 to 6% per channel, with the sun uncorrected. The two statements do not give the same factor.

recommendStart from 1.5 for the environment and 1.0 for the sun, and let task 10's lit scene decide: if 1.5 misses the threshold, sweep the factor in steps of 0.05 and keep the one with the smallest worst channel error. Write the measured numbers in the comment beside CALIBRATION.

Q2 · Pointer lock in headless Chromium

Whether headless Chromium under Playwright grants requestPointerLock is not settled by the code; if it refuses, the runtime clears pointer_captured on the next frame and the browser trace diverges from Python's, where a capture always takes.

recommendTask 9 step 1 probes it. If the real lock is refused, the test installs an init script that replaces requestPointerLock/exitPointerLock with a fake that sets document.pointerLockElement and fires pointerlockchange, and records navigator.userActivation.isActive at each call; the test asserts every request came with an active user activation.

Q3 · Phones and touch

The first consumer's page supports touch: drag to look, tap to pick at the finger. The spec does not mention touch, and phones have no pointer lock.

recommendPointer events of any pointer type feed the mouse fields, as rendercanvas's own browser backend does (a touch is button 1, its motion is d, its position pos). capture_pointer(True) returns False where the canvas has no requestPointerLock or the last pointer was a touch, as the desktop returns False with no window. Add fov to engine.camera's surface so the consumer can build a ray at mouse_pos in Python and pick at a tap (task 1).

Q4 · The consumer's page features with no manifoldx counterpart

Its page has a menu of named views tied to the URL hash, a ?fps counter, a centred crosshair and a help list. The desktop GUI paints every anchor as top-left (render/passes/gui.py:398, manifoldx#13).

recommendThe HTML GUI honours all nine anchors as the widgets declare them; the desktop bug stays its own issue. The crosshair becomes a centred Panel with a Text("+"), the help list Text widgets, the views keys handled in the consumer's Python (as its desktop viewer does), the fps counter a ValueDisplay or nothing. The URL hash is dropped until slice 4 puts the view in engine.state.

Q5 · Widgets beyond Panel, Text and ValueDisplay

The spec defers Button, Slider and Toggle; Image is not mentioned.

recommendThe export fails on any of them in engine.gui with the GUI widget Button is not supported by export --web yet (panel 0, child 2), exit 1, nothing written: a silent drop would be a wrong app, the same rule as the subset.

Q6 · Where Playwright and the GPU come from in CI

The repo has no Playwright dependency. The visual check needs a headless Python frame, and tests/conftest.py:37 skips every adapter request on a runner without one.

recommendA browser dependency group with playwright, and a second CI job, browser, that installs it, runs playwright install --with-deps chromium and apt-get install mesa-vulkan-drivers (lavapipe gives wgpu a CPU adapter), then runs tests/web/browser only. The main job stays as it is, so the GPU tests do not start running there; without the group the browser tests skip with playwright not installed.

Q7 · Escape while the pointer is locked

While the pointer is locked, Chromium takes Escape to release it and does not deliver the keydown to the page. An app that releases on just_pressed("Escape"), as web_walk does, then never sees that frame.

recommendWhen the lock ends without the app asking, the next frame's just holds "Escape" (unless an Escape keydown already arrived) and pointer_captured reads False. The app's own branch runs, and its capture_pointer(False) is a no-op on an unlocked page.

Q8 · Plan 1's task 14

Plan 1's last task (the consumer replays in its own CI) is still pending. It needs the same pin and the same three API swaps as this plan's last task.

recommendFold it into task 12: one consumer branch pins manifoldx after both PRs merge, adds the replay test and CI, then moves the web build to export --web. If plan 1's task 14 lands first on its own, task 12 skips its first three steps.

settledPlan 1's task 14 runs on its own in the consumer's repo now that #141 is merged, so task 12 skips its first three steps.

Q9 · The GUI's font

The desktop measures and draws GUI text with DejaVu Sans Mono (viz/text.py:19). With the browser's default font, a fixed-width panel wraps or clips differently.

recommendCopy DejaVuSansMono.ttf (343 KB, already in the wheel) into the export as fonts/ and use it through @font-face, so the layout matches; the spec makes layout, not pixels, the goal.

Global constraints

Review focus

File structure

fileresponsibility
src/manifoldx/web/js/manifoldx.jsthe core, Node and browser: state loading, createEngine with scene hooks, ScriptInput over the widened frame, step, guiValues, and the trace helpers moved from replay.mjs (toJSON, pathValue, traceEntry)
src/manifoldx/web/js/input.jsFrameBuilder (DOM-like events to one Frame per animation frame), attachDom, PointerLock
src/manifoldx/web/js/scene.jsthe glTF in three.js: extras (background, fog, environment, sun, shadows), CALIBRATION, BasicMaterial shading, handles to meshes and materials, the camera each frame
src/manifoldx/web/js/gui.jsthe state's GUI description to HTML; panelCss as a pure function; text updates; pointer_over_gui
src/manifoldx/web/js/sourcemap.jsline mappings of the app's .js.map files; a JS stack to Python file:line
src/manifoldx/web/js/progress.jsthe loading line (sizes, rate, time left)
src/manifoldx/web/js/browser.jsthe bootstrap: fetch with progress, renderer, loadApp with hooks, the animation loop, the error panel, window.__mx
src/manifoldx/web/js/index.htmlthe page template: importmap, canvas, GUI layer, progress, fallback text
src/manifoldx/web/vendor/three/three.js 0.186.1: three.module.js, three.core.js (minified builds), addons/loaders/GLTFLoader.js, addons/utils/BufferGeometryUtils.js, LICENSE, VERSION, SOURCE
src/manifoldx/web/gui.pygui_spec(engine): panels, anchors, offsets, resolved styles, getter indexes; the unsupported-widget error
src/manifoldx/web/replay.pyPython ScriptInput over the widened frame
src/manifoldx/web/types.py, snapshot.pyengine.gui.pointer_over_gui and engine.camera.fov in RUNTIME_SURFACE; fov and up in the state's camera
src/manifoldx/web/export.pywrites index.html, the browser modules, vendor/three/, fonts/, the state's gui
tests/web/js/*.test.mjsNode tests of the pure browser modules, run by tests/web/test_node_suites.py
tests/web/browser/Playwright tests: replay parity in Chromium, the page's failure modes, visual parity
tests/web/apps/lit_yard.pya test app with StandardMaterial, sun, shadows, the sky environment and fog, for the calibration
.github/workflows/test.yml, pyproject.tomlthe browser job and dependency group

Tasks

1The frame form grows; the engine surface gains gui and fovweb/replay.py · js/manifoldx.js · web/types.py · web/snapshot.py · tests/web/test_frames.py · tests/web/js/runtime.test.mjs

interfaces

produces Frame gains optional fields, read as empty when absent: "up": [str] keys released this frame · "released": [int] buttons released this frame · "pos": [x, y] pointer position in CSS pixels from the canvas's top-left · "wheel": [dx, dy] · "mods": [str] held modifiers among Alt, Control, Meta, Shift, sorted · both ScriptInputs answer just_released, just_mouse_released, mouse_pos, wheel_delta, modifiers from them · RUNTIME_SURFACE: engine.gui with pointer_over_gui: BOOL; engine.camera.fov: NUM · state.json engine.camera gains "fov" (degrees) and "up" · JS Camera holds fov and up (Float32Array)
  1. Write the failing tests in tests/web/test_frames.py: a small app whose system writes engine.state["r"] = [inp.just_released("w"), inp.just_mouse_released(1), list(inp.mouse_pos), list(inp.wheel_delta), list(inp.modifiers), engine.gui.pointer_over_gui, engine.camera.fov], replayed on both sides over the frames below; compare is None and the Python trace's frame 1 reads [True, True, [12.0, 30.0], [0.0, -3.0], ["Shift"], False, 50.0] for an engine whose camera has fov=50. Also: the existing fixture tests/web/fixtures/web_walk_script.json still replays with no mismatch (the fields are optional).
  2. Run uv run pytest tests/web/test_frames.py -v: fails (the app's engine.gui and camera.fov are unknown to the transpiler; the frame fields are ignored).
  3. Implement: the optional fields in both ScriptInput.set_frame/setFrame (the class docstrings and the module docstring of replay.py list them); the two surface entries; fov and up in snapshot.py's engine section and in the JS Camera; engine.gui resolves to the object createEngine already makes. Add one case per new getter to tests/web/js/runtime.test.mjs.
  4. Run uv run pytest tests/web/test_frames.py tests/web/test_replay.py tests/web/test_node_suites.py -v: pass.
  5. Commit: feat(web): releases, pointer position, wheel and modifiers in replay frames.
verify

uv run pytest tests/web/test_frames.py tests/web/test_replay.py tests/web/test_node_suites.py -q: all pass, none skipped on a host with Node.

2The core takes scene hooks; trace helpers move into itjs/manifoldx.js · js/replay.mjs · tests/web/js/runtime.test.mjs

interfaces

consumes task 1 · produces createEngine({w, h, camera, materials, log, state, hooks}) with hooks = {setMaterial(entityIndex: number, materialId: number): void, capture(on: boolean): boolean}, both optional; headless defaults: no-op and () => true · engine.set_material logs ["material", entity, id] then calls hooks.setMaterial · input.capture_pointer(on) calls hooks.capture(on); on true sets the flag and logs ["capture", on], on false logs nothing and returns false · input.lockLost(): the flag reads false from now · loadApp(state, modules, options) passes options.hooks through · exported from manifoldx.js: toJSON(value), pathValue(app, path), traceEntry(app, paths, logStart) -> object; replay.mjs imports them
  1. Write the failing Node tests: with hooks, set_material(h, m) calls setMaterial(h.index, m.id) once and still logs; a capture hook returning false leaves pointer_captured false and the log unchanged; lockLost() clears the flag; traceEntry returns the same object replay() built before, for one frame of the web_walk export (build it in the test with export_web from a Python fixture that writes the folder once per session). And a static check: manifoldx.js's source contains no import other than ./pyrt.js and no document, window or three.
  2. Run uv run pytest tests/web/test_node_suites.py -v: fails.
  3. Implement. The log stays the trace's record in the browser too; the hooks are where the browser acts.
  4. Run uv run pytest tests/web/test_node_suites.py tests/web/test_replay.py -v: pass, the replay unchanged.
  5. Commit: refactor(web): the runtime core takes scene hooks and owns the trace helpers.
verify

uv run pytest tests/web/test_node_suites.py tests/web/test_replay.py -q: pass; node src/manifoldx/web/js/replay.mjs run in a fresh export prints the same JSON as before the change.

3Vendor three.js 0.186.1 into the wheelsrc/manifoldx/web/vendor/three/ · tests/web/test_vendor.py

interfaces

produces manifoldx.web.export.THREE_VERSION = "0.186.1" · VENDOR = Path(__file__).parent / "vendor" / "three" holding three.module.js, three.core.js, addons/loaders/GLTFLoader.js, addons/utils/BufferGeometryUtils.js, LICENSE, VERSION, SOURCE
  1. Write the failing test tests/web/test_vendor.py: every file above exists; VERSION reads THREE_VERSION; each vendored JS file's import specifiers (from "...") are "three" or a relative path to a vendored file, so the folder makes no request outside itself; three.module.js's first 300 bytes hold the license header.
  2. Run it: fails.
  3. Fetch the package once into scratch outside the repo: npm pack three@0.186.1, check its integrity against npm view three@0.186.1 dist.integrity, and copy build/three.module.min.js as three.module.js, build/three.core.min.js as three.core.js (fix the one import ./three.core.min.js to ./three.core.js), the two addons from examples/jsm/, and LICENSE. Write SOURCE: the tarball name, its integrity string and the files taken, so the next upgrade repeats the step. Delete the scratch.
  4. Run the test: pass. Then uv build --wheel -o "$TMP/whl" and unzip -l "$TMP"/whl/*.whl | grep -c web/vendor/three: 7.
  5. Commit: chore(web): vendor three.js 0.186.1.
verify

uv run pytest tests/web/test_vendor.py -q: pass; the wheel lists the seven vendored files.

4Browser input: DOM events to Frames, and pointer lockjs/input.js · tests/web/js/input.test.mjs

interfaces

consumes task 1's Frame, task 2's hooks · produces class FrameBuilder: keyDown({key, code, repeat, altKey, ctrlKey, metaKey, shiftKey}), keyUp({code, ...mods}), pointerDown({button, x, y, pointerType}), pointerUp({button, x, y}), pointerMove({movementX, movementY, x, y}), wheel({deltaX, deltaY, deltaMode}), blur(), lockEnded(), take(viewport: [w, h]) -> Frame · attachDom(canvas, builder, {devicePixelRatio}) -> detach() · class PointerLock(canvas, doc, builder) with request(on) -> boolean (the capture hook), locked: boolean
  1. Write the failing Node tests over plain objects (no DOM):
  2. Write the failing PointerLock tests with a fake canvas and document: request(true) calls canvas.requestPointerLock() and returns true when doc.userActivation is active; with no activation it arms a one-shot pointerdown listener that makes the request, and returns true; with no requestPointerLock on the canvas, or the last pointer a touch, it returns false (Q3); a pointerlockerror or a pointerlockchange to unlocked that the app did not ask for calls builder.lockEnded(), which makes the next frame's just hold "Escape" unless an Escape keydown came (Q7), and calls the engine's input.lockLost(); request(false) calls doc.exitPointerLock() only when locked.
  3. Run uv run pytest tests/web/test_node_suites.py -v: fails.
  4. Implement input.js. attachDom listens on window for keys and blur, on the canvas for pointerdown (with setPointerCapture), on window for pointermove/pointerup, wheel (passive false, preventDefault), contextmenu (prevented, so a right drag looks). It calls preventDefault on Tab and on Space, so the page neither moves focus nor scrolls; it leaves Control+W and other browser shortcuts alone. Positions are CSS pixels relative to the canvas's bounding box.
  5. Run: pass.
  6. Commit: feat(web): DOM input to replay frames, and pointer lock.
verify

node --test tests/web/js/input.test.mjs: all pass.

5The scene in three.js: extras, calibration, handlesjs/scene.js · tests/web/js/scene.test.mjs

interfaces

consumes task 3's vendor, task 2's hooks, plan 1's glTF extras (node extras.mx = {entity, material}, scene extras.manifoldx = {background, fog?, shadows?, environment?, mx_materials}) · produces CALIBRATION = {environment: 1.5, sun: 1.0} · async buildScene(THREE, gltf, renderer) -> MxScene with .scene, .camera (PerspectiveCamera), .entities: Map<number, Mesh[]>, .materials: Map<number, Material>, .setMaterial(entity, id) (the hook), .sync(engine) (camera from engine.camera, aspect from engine.w/h), .materialOf(entity) -> id | null, .setCalibration(partial)
  1. Write the failing Node tests in tests/web/js/scene.test.mjs, over the web_walk export's scene.glb parsed with the vendored GLTFLoader.parseAsync (Node 20+ has the globals it needs for an untextured glb) and a stub renderer (capabilities.maxTextureSize 4096; buildScene calls the PMREM generator only when the scene has an environment). Assertions: entities holds every mx.entity in the glTF and each value lists the meshes under that node; materials holds every id of mx_materials, including the gold that no entity uses at export; setMaterial(box, goldId) makes each mesh of that entity use materials.get(goldId) and materialOf(box) === goldId; a glTF material named BasicMaterial or PhongMaterial becomes the mx basic material (next step) with the same linear colour and fog: false; scene.background equals extras.background as linear RGB; after sync, the three camera's position, up, fov, near, far and aspect equal the engine's and its world direction equals get_forward() within 1e-6. If GLTFLoader cannot parse in Node after all, move these assertions into task 9's browser test and record it under "where this plan departs".
  2. Run: fails.
  3. Implement buildScene:
    • BasicMaterial and PhongMaterial: the desktop lights them with a fixed light, 0.3 + 0.7 * max(dot(n, normalize(1, 1, 1)), 0) in world space (resources.py:109-118; Phong uses Basic's shader, resources.py:1850). Draw them with a MeshBasicMaterial whose onBeforeCompile multiplies the diffuse colour by that brightness from the world normal, fog: false (the desktop fogs only StandardMaterial). Without this an unlit scene such as web_walk renders black.
    • Background, fog (THREE.Fog from start, end, colour), and the environment as the first consumer builds it: the float32 equirectangular buffer view, rows flipped, to a half-float DataTexture, through PMREMGenerator.fromEquirectangular, scene.environmentIntensity = env.intensity * CALIBRATION.environment.
    • The sun: the loader's directional light scaled by CALIBRATION.sun; with shadows, every mesh casts and receives, and the light's orthographic shadow camera is fitted once to the scene's bounding sphere (the desktop's auto_fit), map size min(resolution, maxTextureSize), bias -0.0005, normalBias 0.05, radius = pcf_radius; with auto_fit: false use target, extent, near, far.
    • Renderer settings are browser.js's (task 8): outputColorSpace = SRGBColorSpace, NoToneMapping, shadowMap.type = PCFShadowMap.
  4. Run: pass.
  5. Commit: feat(web): the exported scene in three.js with manifoldx's calibration.
verify

node --test tests/web/js/scene.test.mjs: pass.

6The GUI as HTMLweb/gui.py · web/export.py · js/gui.js · tests/web/test_gui_spec.py · tests/web/js/gui.test.mjs

interfaces

consumes plan 1's find_roots (getter roots in panel walk order) · produces gui_spec(engine) -> dict: {"scale": float, "design_height": float | None, "panels": [node]}, node {"kind": "Panel", "anchor", "offset": [x, y], "style": {resolved}, "children": [node]} · {"kind": "Text", "text", "style"} · {"kind": "ValueDisplay", "value": k, "min_width", "style"} where k is the index among the getter roots · GuiUnsupported(what) raised for Button, Slider, Toggle, Image (Q5) · state.json "gui" · JS panelCss(node, scale, isRoot) -> {[cssProperty]: string}, buildGui(layer, spec) -> Gui with .update(values: string[]), .rescale(engineH), .pointerOver: boolean
  1. Write the failing Python tests: gui_spec of web_walk's engine equals the expected dict (one panel, top-left, offset [16, 16], the style with width 240, height 76, padding 8, bg "#1a1a1aC0" and the theme's other keys resolved, three ValueDisplays with values 0, 1, 2); a style class defined with style.define is resolved into the spec; an engine with a Button makes export_web return 1, print the GUI widget Button is not supported by export --web yet (panel 0, child 1), and write nothing.
  2. Write the failing Node tests of panelCss: direction "v" is flex-direction: column, "h" row; padding "4 8" becomes four pixel values; every size, padding, gap, border, radius, font size and offset is multiplied by the scale; the nine anchors place a root panel (top-right with offset [16, 16] is right: 16px; top: 16px, center is left: 50%; top: 50% with a translate(-50%, -50%) then the offset); bg "#1a1a1aC0" passes through as CSS hex; width: null leaves the width to content; a flex value becomes flex-grow.
  3. Run uv run pytest tests/web/test_gui_spec.py tests/web/test_node_suites.py -v: fails.
  4. Implement. gui_spec lives in web/gui.py and walks engine.gui._panels as find_roots does; export_web writes it under "gui" and turns GuiUnsupported into exit 1. buildGui builds divs in a layer over the canvas, text through textContent only, the font "mx-gui" (DejaVu Sans Mono from fonts/, Q9), white-space: pre, overflow: hidden on sized panels; update writes a ValueDisplay's text only when it changed; rescale recomputes when design_height is set; pointerenter/pointerleave on root panels keep pointerOver, which browser.js copies into engine.gui.pointer_over_gui each frame. Panels take pointer events, so a click on a panel does not reach the canvas, as the desktop's bridge consumes it.
  5. Run: pass.
  6. Commit: feat(web): the GUI as HTML from the widgets' anchor, offset and style.
verify

uv run pytest tests/web/test_gui_spec.py -q and node --test tests/web/js/gui.test.mjs: pass.

7Python lines for errors in the pagejs/sourcemap.js · tests/web/js/sourcemap.test.mjs · tests/web/test_node_suites.py

interfaces

consumes plan 1's source maps (one segment per emitted line, sources rewritten to the app path by export.py) · produces lineTable(map) -> Int32Array (generated line to 1-based Python line, 0 where unmapped) · pythonFrames(stack: string, maps: {[jsUrlSuffix]: {source, lines}}) -> [{file, line, fn}], the JS frames under app/ mapped, others dropped · describe(error, maps) -> string: "app.py:57 in walk: TypeError: Cannot read properties of null (reading 'x')", the first Python frame, then the rest as " called from app.py:121 in tick"
  1. Write the failing Node test, driven from tests/web/test_node_suites.py with a fixture: export a two-module app whose system calls a helper in the second module that reads an attribute of None; in Node, import the module, run the system, catch the error, and check describe(err, maps) starts with helper.py:LINE in helper where LINE is the line of the attribute read, and names the system's call line next. Use Chromium's and V8's stack form (at fn (url:line:col)); Firefox's form (fn@url:line:col) parses too.
  2. Run: fails.
  3. Implement: base64 VLQ decoding of mappings, keeping each generated line's first segment's source line.
  4. Run: pass.
  5. Commit: feat(web): Python file and line for a JS error from the source maps.
verify

uv run pytest tests/web/test_node_suites.py -k sourcemap -q: pass.

8The page: index.html, the bootstrap and what export writesjs/index.html · js/browser.js · js/progress.js · web/export.py · tests/web/test_export_web.py · tests/web/js/progress.test.mjs

interfaces

consumes tasks 2–7 · produces the export folder adds index.html, browser.js, input.js, scene.js, gui.js, sourcemap.js, progress.js, vendor/three/, fonts/DejaVuSansMono.ttf · index.html carries <title> from engine.title, <meta name="scene-bytes"> and <meta name="scene-gzip-bytes"> · window.__mx = {ready: Promise, app, scene, gui, frames: Frame[], trace: object[], error: string | null, manual(on: boolean), tick(dt: number) -> {frame, entry}, loadStats: {bytes}} · progressLine({fraction, download, rate, received}), RateMeter, frameDt(now, last) = min((now - last) / 1000, 0.1)
  1. Write the failing tests: export_web of web_walk writes every file above; index.html's title is Web walk, its scene-bytes equals the size of scene.glb and scene-gzip-bytes the size of gzip.compress(glb, 9); its importmap maps "three" to ./vendor/three/three.module.js and "three/addons/" to ./vendor/three/addons/; it contains the fallback text serve this folder over HTTP (python -m http.server); no file in the folder names an http: or https: URL outside comments and the license. Node tests of progressLine and RateMeter ported from the first consumer's tests (sizes in KB and MB, the rate over the last 3 s, "about N s left" under 90 s and "about N min left" above), and of frameDt (a 5 s gap from a background tab gives 0.1).
  2. Run uv run pytest tests/web/test_export_web.py tests/web/test_node_suites.py -v: fails.
  3. Implement browser.js, in this order: check WebGL2 (else the error panel says the browser has none); fetch state.json and the app modules; fetch scene.glb streamed, counting bytes against scene-bytes and showing progressLine in the progress element (wire bytes from scene-gzip-bytes when the response is gzip-encoded); GLTFLoader.parseAsync; the renderer (pixel ratio min(devicePixelRatio, 2), the settings of task 5); buildScene; buildGui; loadApp(state, modules, {hooks: {setMaterial: mx.setMaterial, capture: lock.request}}); attachDom; hide the progress element; then renderer.setAnimationLoop: each frame frame = builder.take([canvas.clientWidth, canvas.clientHeight]), engine.gui.pointer_over_gui = gui.pointerOver, engine.input.setFrame(frame), step(app, frameDt(now, last)), gui.update(guiValues(app)), scene.sync(engine), render. A resize of the canvas reaches the engine through the frame's vp (as the replay does) and the renderer through setSize(w, h, false). An error thrown by the app's code pauses the loop and shows describe(err, maps) in the error panel, also in __mx.error and console.error; an error while loading shows its message and the HTTP hint. manual(true) stops the loop; tick(dt) runs one frame as the loop does, appends to __mx.frames and __mx.trace (traceEntry with the paths given by __mx.paths), and returns them.
  4. Implement the export side: copy the modules, vendor/three/ and the font; render index.html from the template with html.escape on the title.
  5. Run: pass. Then open it once by hand: uv run manifoldx export --web examples/web_walk.py "$TMP/ww" && uv run python -m http.server -d "$TMP/ww" 8765 and load it in a browser (aegis's browser_open on http://127.0.0.1:8765 works): the yard draws, the panel reads picked: nothing, a click captures, WASD walks.
  6. Commit: feat(web): export --web writes the browser page.
verify

uv run pytest tests/web/test_export_web.py -q and node --test tests/web/js/progress.test.mjs: pass; the manual look shows the scene and the panel.

9Chromium replays web_walk as Python doespyproject.toml · tests/web/browser/conftest.py · tests/web/browser/test_page.py

interfaces

consumes task 8's window.__mx, plan 1's replay_python and compare · produces dependency group browser = ["playwright>=1.55"] · fixtures served(folder) -> url (a python -m http.server subprocess on a free port of 127.0.0.1, stopped by PID at teardown), chromium (headless, args --enable-unsafe-swiftshader, --use-angle=swiftshader), web_walk_export (session-scoped export into tmp_path_factory)
  1. Write conftest.py: skip the folder with playwright not installed when import playwright fails and chromium not installed when launching fails. Probe pointer lock (Q2): in a page served from the export, click the canvas and read document.pointerLockElement after pointerlockchange or 1 s. Keep the fake lock of Q2 as an init script, used only when the probe fails; the probe's result is printed in the test output.
  2. Write the failing test test_chromium_matches_python: open the page with viewport 800×500, await __mx.ready, set __mx.paths = ["rig.pos", "rig.yaw", "rig.mode", "selected"], __mx.manual(true). Drive a DOM-level script of about 200 ticks through Playwright's real input (page.keyboard.down/up, page.mouse.move/down/up, page.mouse.wheel, page.set_viewport_size), one __mx.tick(1/60) after each step's events: walk with W and D, a click that captures, mouse look, three clicks aimed at different boxes (aim them by setting the look first with mouse moves the test computes from the boxes' centres), Tab, Space and Shift in fly mode, a release by exitPointerLock (the Escape path of Q7), a right drag, a resize to 640×480. Then: Also assert the frames the page built hold what the script did: the tick after keyboard.down("w") has "w" in just and keys; the tick after the resize has vp == [640, 480].
  3. Write the failing page tests: test_file_url_says_to_serve (open index.html as file://: the text serve this folder over HTTP is visible); test_error_names_the_python_line (a test app tests/web/apps/raises.py whose system reads an attribute of None after 5 frames: after 6 ticks __mx.error starts with raises.py:LINE in, the error panel shows it, further ticks run nothing); test_high_density_and_resize (a context with device_scale_factor=2: after a tick engine.w is the CSS width, the canvas's width attribute is twice it, scene.camera.aspect is w / h); test_progress_counts_the_scene (__mx.loadStats.bytes equals the scene-bytes meta and the progress element is hidden after ready); test_lock_lost_releases (capture, then document.exitPointerLock() from the test: the next tick's frame has "Escape" in just and pointer_captured is false).
  4. Write the breaking tests: swap two entries of __mx.scene.entities before the script, and the material assertion fails; patch the page's FrameBuilder so key names keep their case, and compare returns a mismatch. Each must fail for the reason named.
  5. Run uv sync --group browser && uv run pytest tests/web/browser/test_page.py -v on a host with Chromium: fails before the fixes the run shows, then passes. On a shared host, reuse the Chromium already in ~/.cache/ms-playwright by pinning playwright to the version that cache matches, rather than downloading another.
  6. Commit: test(web): Chromium replays web_walk as Python does.
verify

uv run pytest tests/web/browser/test_page.py -v: 8 passed (the replay, five page tests, two breaking cases); without the group, all skipped with playwright not installed.

10Visual parity: mean colour per channeltests/web/apps/lit_yard.py · tests/web/browser/test_visual.py · js/scene.js (CALIBRATION)

interfaces

consumes task 5's CALIBRATION and setCalibration, task 9's fixtures, Engine.render_frame · produces mean_rgb(img: np.ndarray) -> tuple[float, float, float] in 0–255 · THRESHOLD = 0.08: for each channel, abs(web - py) <= max(THRESHOLD * py, 4.0)
  1. Write tests/web/apps/lit_yard.py: a ground and five boxes in StandardMaterial of different colours and roughness, set_sun with a DirectionalLight, enable_shadows(), set_environment("sky"), enable_fog(20, 60), a fixed camera looking over the yard, no GUI, no systems. Keep it under 50 lines.
  2. Write the failing test, parametrised over web_walk and lit_yard at 320×200: the Python side captures the engine as replay_python does, removes engine.gui's panels, calls engine.render_frame() until the environment's precompute is done (not engine._loading(), so the loading panel is not in the frame), and takes mean_rgb; the browser side opens the export at 320×200 with device scale 1, hides #mx-gui, ticks once with an empty frame, screenshots the canvas, and takes mean_rgb. Each channel within the threshold. The test prints both means and the ratio per channel.
  3. Write the breaking test: setCalibration({environment: 1.0}) on lit_yard, and swapping the mx basic material for plain MeshStandardMaterial on web_walk; each must exceed the threshold. If a break stays within it, the threshold is too loose: tighten it to the measured worst case plus 2 points and say so in the test's comment.
  4. Run on a host with a wgpu adapter (lavapipe is enough): uv run pytest tests/web/browser/test_visual.py -v -s. If lit_yard misses with 1.5, sweep CALIBRATION.environment as Q1 says, keep the best, and write the measured means and the chosen factor in the comment beside CALIBRATION.
  5. Commit: test(web): visual parity of the browser page with the desktop frame.
verify

uv run pytest tests/web/browser/test_visual.py -v -s: 4 passed (2 scenes, 2 breaks); the printed ratios are within the threshold.

11CI job, docs and the PR.github/workflows/test.yml · know-how/web-export.md · AGENTS.md · CHANGELOG.md
  1. Add the browser job to .github/workflows/test.yml, beside test:
  2. Update know-how/web-export.md: the page replaces "there is no browser page yet"; serving the folder; what the page does (progress, input mapping with the frame's new fields, pointer lock and its user-gesture rule, Escape, touch, the GUI's supported widgets and anchors, the error panel); the calibration and how to re-measure it; the browser tests and the browser group; how to upgrade three.js (the SOURCE file). Update the sub-projects line in AGENTS.md to name this plan. Add the CHANGELOG entry under [Unreleased].
  3. Run make lint and the tests of tests/web outside browser/; leave make test and the browser tests to CI.
  4. Push feat/web-target-2, open the PR against main referencing #140, and work it until every CI job is green. Then merge it.
verify

CI: test and browser green on the PR; the browser job's log shows tasks 9 and 10's tests passed, none skipped.

12The first consumer's web build comes from export --webthe consumer's repository: app code, a replay test, its CI, its web build; its hand-written JS deleted

Runs in the first consumer's repository after both manifoldx PRs merge; its own issue, branch and PR. It folds in plan 1's task 14 (Q8): skip steps 1–3 if that task already landed.

  1. Pin manifoldx to the merge commit. Replace the three private workarounds with engine.set_material, engine.input.capture_pointer and engine.input.viewport_size; its desktop tests and its screenshot command still pass.
  2. Add a replay test: manifoldx export --web of the app into a temp folder, its own 900-frame script, paths=["rig.pos", "rig.yaw", "rig.pitch", "rig.mode", "selected", "captured"], compare is None.
  3. CI: install mesa-vulkan-drivers so the startup's textures get a CPU device, then run the replay test.
  4. Move what the hand-written page does into the Python app, as Q3 and Q4 recommend: the info panel, mode line and help as GUI widgets; the crosshair as a centred panel; views as keys; picking at a tap through mouse_pos and camera.fov when capture_pointer returns False. Each change keeps its desktop tests passing.
  5. Make its web build run manifoldx export --web into its output folder, and its deploy procedure publish that folder. The page loads, walks, picks and shows the panel on the deployed site, checked in a browser, and its visual check against the desktop screenshot stays within the threshold of task 10.
  6. Delete the hand-written page: its viewer, HUD, rig, spatial and terrain modules, progress module, index.html, vendor/three/, their JS tests and package.json, and the golden files that only fed them. Update its agent docs and its deploy know-how. git grep -l "three" in the consumer finds nothing outside lock files and docs that explain the move.
verify

The consumer's CI runs the replay green; its deployed page is the export's; its repository holds no JavaScript of its own.

Where this plan departs from the spec

Self-review