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

Web target, plan 3: manifoldx run --web, the dev loop

This plan builds slice 4 of the spec. manifoldx run --web app.py serves the export on 127.0.0.1, watches the app's sources, and on each save reruns setup, transpiles, snapshots and pushes the new version to the open tab. The tab imports the new modules and the new snapshot, keeps its three.js scene when the scene did not change, keeps engine.state as the desktop reloader does, and resumes without a page reload. The agent commands work against the tab. It ends with the first consumer's camera kept in engine.state, staying put across a save, and its reload time measured.

goalRun manifoldx run --web app.py and open the printed URL. A save shows in the tab with engine.state kept; an edit that fails to load or transpile leaves the running version with an overlay naming the Python line; an exception in a frame pauses with the Python traceback and the next save resumes; manifoldx look, state, set, emit, events and log answer from the tab. architectureThe export splits into building a version in memory and writing it. A WebReloader (a HotReloader with no window) rebuilds on each change and writes numbered version folders beside shared static files under .manifoldx/web/, which the existing dev server now also serves. The server talks to the tab over Server-Sent Events, and the tab answers with POSTs. In the page, browser.js learns to load a version from a base path and to swap one in place, and a new dev.js holds the dev loop's browser side: the stream, the overlay and the agent commands. manifoldx.js stays free of the DOM and gains the state codec both ways. techPython 3.13, stdlib only on the server (http.server, no websocket library); plain ES modules; Node 20+ for node --test; Playwright with Chromium for the browser tests, in the existing browser CI job on lavapipe. spec.knowledge/analysis/2026-11-06-web-target-design.html (section 08, slice 4 of section 10, the first open question of section 13) builds onplan 1 (#141) and plan 2 (#146), with the follow-ups of #150, all on main. This plan's branch is feat/web-target-3; its PR targets main. code it changessrc/manifoldx/web/export.py, src/manifoldx/hot.py, src/manifoldx/devchannel.py, src/manifoldx/cli.py, src/manifoldx/engine.py (one parameter), the page's modules in src/manifoldx/web/js/. New: src/manifoldx/web/dev.py, src/manifoldx/web/devstate.py, src/manifoldx/web/js/dev.js.

The reload budget, measured

The spec leaves open how fast a save must show and asks this slice to measure the first consumer before tuning. Its export was timed by phase on the shared 4-core host with lavapipe, twice in one process (the second run drops the app's modules and reruns, as a reload does), with manifoldx at main plus #150:

4.9 sfirst export: device, textures, meshes, transpile, write
2.6 ssecond export in the same process, the shape of a reload
4.4 MBscene.glb, byte-identical across the two runs, so a content hash can skip it
236 KBstate.json; the app's transpiled modules are 10 files, 56 KB
phasefirstsecondunder run --web
setup: module code until engine.run()0.18 s0.08 ssame
startup on a headless frame (textures, meshes)3.37 s0.97 ssame; the device is reused (1.43 s of the first run)
reach and types0.72 s0.95 ssame; the largest piece left to tune
snapshot, transpile, GUI spec0.09 s0.12 ssame
glb export0.07 s0.05 sbuilt and hashed; written only when the hash is new
writing, of which three.js, fonts and page files0.48 s0.46 sstatic files written once at start: about 0.05 s per version

The expected budget, from save to the new version drawn in the tab, about 2.5 s for a code-only edit on this host: up to 0.25 s until the poll sees the file, about 0.05 s to get the tab's state, 2.2 s to rebuild, then the push and a swap of about 0.1 to 0.2 s (fetch 236 KB of state, import 10 modules, rebuild the GUI). An edit that changes the scene adds the parse of a new 4.4 MB glb, estimated at 0.3 to 0.6 s. Task 10 measures the real numbers in a tab and reports them; tuning reach (cache per-module results by source hash) and the startup's textures (the app's own engine.state cache, as know-how/hot-reload.md advises) are left to follow-up issues unless a reload exceeds 3 s.

How the pieces fit

a savemtime poll, 0.25 s ask the tabreload_state: tab freezes, sends state merge into Statedevstate.merge_tab_state rerun setupHotReloader._load, startup build_exportreach, snapshot, transpile, glb write v{n}/scenes/<sha>.glb if new push versionSSE /api/web/streamor failed: file:line tab swapsimport v{n}/app, load state,keep scene if sha same resumeoverlay: v{n} · livelog: tab swap ms agent commandslook state set emit log

The orange path is one reload. The dashed blue paths are the agent commands, which the server forwards to the tab as calls over the same stream.

Open questions

None of these is settled by the code or the spec. Each has a recommendation, and the tasks follow it. A maintainer's different answer changes only the task named.

Q1 · What of the tab's engine.state crosses back to Python

The spec says the tab sends its engine.state and setup reruns with it. In the tab, the state is runtime values: a dict is a Map, a tuple and a list are both arrays, a float32 vector is a Float32Array, and a value may be an object of a transpiled class or a handle. Python's State may also hold keys that never crossed (report.json's state_left_out), such as the texture cache keyed by tuples that know-how/hot-reload.md recommends.

recommendThe tab encodes its state with the snapshot's own value forms (__dict, __set, __f32, __f64, __float) and marks what is not plain data as {"__skip": "<what>"}. Python decodes against its previous value: an array comes back a tuple where the old value at that path was a tuple; __f32 becomes a float32 numpy array. Only the keys that crossed in the last snapshot are replaced or deleted; left-out keys and keys whose value holds a __skip keep Python's value, and each kept key is logged once. Task 2.

Q2 · Frames that run while the reload builds

A reload of the first consumer takes about 2.5 s. If the tab keeps running while Python rebuilds from the state it sent, the camera motion of those seconds is lost when the new version loads, and the view jumps back.

recommendThe tab freezes when it answers the reload's state request: it stops running systems, keeps the last frame on screen and shows v3 · reloading. It resumes on the new version, or on failed, or after 30 s without either. The desktop reloader blocks its window for the same time (src/manifoldx/hot.py:175 reloads inside step()), so the two behave alike. Tasks 5 and 6.

Q3 · More than one tab

The spec speaks of "the open tab". A person may open two, or reload one, or an agent's Playwright page may sit beside a person's tab.

recommendEvery connected tab receives every version. The tab that connected last answers the calls (state, set, emit, look); when it disconnects, the previous one takes over. Each tab sends its id in the stream URL. Task 4.

Q4 · A tab that opens after the state moved on

A tab opened, or reloaded with F5, loads the current version, whose snapshot holds the state of the last save. The camera then returns to where it was at that save, though the spec keeps the state "without a tab" as the last one received.

recommendA tab sends its encoded state with navigator.sendBeacon on pagehide, and every reply to a call carries it too. When a tab connects and the state the server last received differs from the current version's, the server rebuilds as on a save (reason tab, no file changed) and the new tab swaps to it. Task 4.

Q5 · What manifoldx look shows, given an HTML GUI

The desktop look includes the GUI (know-how/agent-loop.md, the API table). In the tab the GUI is HTML over the canvas, which a canvas read does not include, and a page cannot screenshot its own DOM without a library.

recommendThe tab draws the WebGL frame into a 2D canvas of the same size, then paints each visible GUI element over it from its bounding box and computed style: background colour, then each text line in the GUI's font and colour. Pixel equality with the HTML is not a goal, as the spec says of the GUI; the text and the layout are. Task 7.

Q6 · Logging from frame code

The spec says log includes the tab's console. know-how/agent-loop.md tells apps to log what the person does with engine.log(text), usually from a system, but engine.log is not in RUNTIME_SURFACE (src/manifoldx/web/types.py:455), and in the runtime engine.log is already the trace's array of calls (src/manifoldx/web/js/manifoldx.js:238).

recommendAdd engine.log(text) to the surface. The runtime's call record is renamed engine.calls (the trace's JSON key stays log, so fixtures and replay.py do not change). In the tab, engine.log sends its line to the server's log as the desktop's does; in Node it collects lines in engine.lines. The tab's console warnings and errors go to the log with the prefix tab: . Task 7.

Q7 · The transport between server and tab

The dev server is a stdlib ThreadingHTTPServer (src/manifoldx/devchannel.py:342). A websocket needs a library or a hand-written framing layer.

recommendServer-Sent Events for server to tab (GET /api/web/stream, one blocked thread per tab, which the threading server already gives), POSTs for tab to server. EventSource reconnects by itself when the server restarts. Task 4.

Q8 · Where versions live and what the URLs are

The spec says "export into a new version folder". The page imports app modules by URL, and the browser caches an ES module by its URL for the page's life, so a new version needs new URLs. The dev page already owns /.

recommendUnder --web the server serves .manifoldx/web/: the app at /, the dev page at /dev, versions at /v{n}/ (app/, state.json, report.json), scenes at /scenes/<sha>.glb, and the static files (page modules, runtime, vendor/three/, fonts/) once at the root. A version's modules import ../../pyrt.js, so every version shares one runtime instance. The server keeps the last three versions and the scenes they name, and deletes the rest. Tasks 1 and 3.

Q9 · --debug with --web

--debug measures the window's frames in Python (src/manifoldx/devchannel.py:119). Under --web no Python frames run after startup.

recommendRefuse the pair: --debug measures the window's frames; under --web the tab runs them, exit 2. Frame metrics from the tab are a later step. Task 8.

Global constraints

Review focus

File structure

fileresponsibility
src/manifoldx/web/export.pybuild_export (a version in memory, with per-phase timings), write_static, write_version, page_html; export_web composed from them
src/manifoldx/web/devstate.pythe tab's encoded state back to Python values; the merge into the shared State
src/manifoldx/web/dev.pyTab (connected tabs, the stream, calls and replies) and WebReloader (the rebuild loop, version folders, pruning, error lines)
src/manifoldx/hot.py_load also records the app's __main__ module; reload()'s module dropping becomes _drop_modules()
src/manifoldx/engine.py_ensure_offscreen(supersample, gpu=None) passes gpu to _init_canvas
src/manifoldx/devchannel.pyunder --web: static files, /api/web/*, and state, set, emit and look routed to the tab; the dev page moves to /dev
src/manifoldx/cli.pyrun --web
src/manifoldx/web/types.pyengine.log in RUNTIME_SURFACE
src/manifoldx/web/js/manifoldx.jsencodeState, fromJSON, mergePatch, stateView, fire; engine.calls and engine.log(text)
src/manifoldx/web/js/browser.jsloadVersion(base, info) and swap(info); the frame loop over a replaceable app; dev mode when the page has <meta name="mx-dev">
src/manifoldx/web/js/dev.jsthe stream, the overlay's status, freeze and resume, calls answered, console forwarding, the look composite
src/manifoldx/web/js/scene.js, gui.jsresetMaterials(); destroy()
src/manifoldx/web/js/index.html{{dev}} slot for the dev meta and the overlay element
tests/web/test_build_export.py, test_devstate.py, test_dev_web.pyPython tests: the split export, the codec, the reloader and the server against a scripted tab
tests/web/js/dev.test.mjs, runtime.test.mjsNode tests of the codec, patches, events and the overlay's status
tests/web/apps/dev_orbit.pya test app for the dev loop: an orbit camera in engine.state, a coloured box, a GUI Text, an event with a docstring
tests/web/browser/test_run_web.pyChromium against a real manifoldx run --web: saves, errors, agent commands

Tasks

1The export splits into building a version and writing itweb/export.py · engine.py · tests/web/test_build_export.py

interfaces

consumes capture_engine, find_roots, reach_app, snapshot, transpile_app(sources, reach=, runtime=), gui_spec, export_engine as export_web uses them today (src/manifoldx/web/export.py:66-151) · produces build_export(engine, main, root, *, app_label, runtime="../pyrt.js", gpu=None) -> Built, raising TranspileError (with the file's real path, as export_web rewrites it today), SnapshotError or GuiUnsupported; @dataclass Built: modules: dict[str, tuple[str, str]] (name to code and source-map JSON with sources set), state: dict, report: dict, glb: bytes, scene_sha: str (sha256 hex, first 16), title: str, crossed: frozenset[str] (the engine.state keys the snapshot wrote), left_out: list[SnapshotError], timings: dict[str, float] (seconds, keys startup reach snapshot transpile gui scene) · write_static(out) (the page's modules, the runtime, vendor/three/, fonts/; with dev=True also dev.js) · write_version(built, out, scene_path="scene.glb") (app/, state.json, report.json, the glb at scene_path relative to out unless it exists) · page_html(title, scene_bytes, scene_gzip_bytes, dev=False) -> str · Engine._ensure_offscreen(supersample, gpu=None)
  1. Write the failing tests in tests/web/test_build_export.py, on examples/web_walk.py through capture_engine:
  2. Run uv run pytest tests/web/test_build_export.py -q: fails with ImportError: cannot import name 'build_export'.
  3. Move the body of export_web after capture_engine into build_export (the _as_main block, startup with engine._ensure_offscreen(1, gpu=gpu), the error path rewrite, the report) and the writing into write_static, write_version and page_html. export_web becomes capture, build, write_static(out), write_version(built, out), index.html from page_html, and the left out of the state lines; its exit codes and messages stay. build_export calls export_engine into a temporary file in the system temp dir and reads its bytes; scene.export-report.json moves into Built.report["scene_report"] and write_version writes it beside the glb as today. In engine.py, _ensure_offscreen takes gpu=None and passes it to _init_canvas. index.html gets a {{dev}} slot in the head, empty for the export.
  4. Run the new tests and the export's: uv run pytest tests/web/test_build_export.py tests/web/test_export_web.py -q: all pass.
  5. Commit: refactor(web): build an export in memory, then write it.
verify

uv run pytest tests/web/test_build_export.py tests/web/test_export_web.py -q: all pass, the five new tests included; git diff main -- tests/web/test_export_web.py is empty.

2engine.state crosses back: the codec both waysweb/devstate.py · js/manifoldx.js · tests/web/test_devstate.py · tests/web/js/runtime.test.mjs

interfaces

consumes the snapshot's value forms (src/manifoldx/web/snapshot.py:12-27), hot.State, Built.crossed (task 1) · produces JS: encodeState(map) -> value (plain JSON with {"__dict": [[k, v], ...]}, {"__set": [...]}, {"__f32": [...]}, {"__f64": [...]}, {"__float": "nan"|"inf"|"-inf"}, arrays as JSON arrays, and {"__skip": what} for an object of a transpiled class, a handle, a function or a cycle); fromJSON(value) (a JSON value to runtime values: objects to Map, recursively); mergePatch(map, patch) (RFC 7386 on a Map, patch already through fromJSON); stateView(map) -> plain JSON (for GET /api/state: a Map as an object, typed arrays and Sets as arrays, a skipped value as its what string, as the desktop's repr fallback) · Python: devstate.decode(value, like=None); devstate.merge_tab_state(state: State, tab: dict, crossed: frozenset[str]) -> list[str] (the keys it kept from Python, with why)
  1. Write the failing Python tests in tests/web/test_devstate.py:
  2. Write the failing Node tests in tests/web/js/runtime.test.mjs: encodeState of a Map holding a Map, a Float32Array, a Set, NaN, an Object.create object of a class and a cycle gives the forms above, the last two as __skip with "an object of Viewer" and "a cycle"; fromJSON({"cam": {"yaw": 1}}) is a Map of a Map; mergePatch merges nested Maps, deletes on null, replaces arrays whole; stateView shows a handle as "<material 3>".
  3. Run uv run pytest tests/web/test_devstate.py tests/web/test_node_suites.py -q: fails on the missing names.
  4. Implement devstate.py and the four JS functions. decode walks like beside the value: a dict decodes each key against like.get(key), a list against like[i] when lengths match. merge_tab_state decodes the top level against the current state, then for each crossed key: absent in the tab's state deletes it, a value containing __skip anywhere keeps Python's whole key, anything else replaces it; a key not crossed keeps Python's value; a key new in the tab is added.
  5. Run the same command: passes.
  6. Commit: feat(web): engine.state from the tab back to Python.
verify

uv run pytest tests/web/test_devstate.py tests/web/test_node_suites.py -q: all pass; the round-trip test fails if decode drops the like argument (try it once).

3WebReloader: rebuild on save into version foldersweb/dev.py · hot.py · tests/web/test_dev_web.py · tests/web/apps/dev_orbit.py

interfaces

consumes HotReloader (src/manifoldx/hot.py:52), tasks 1 and 2 · produces HotReloader._load() also sets self.main (the app's __main__ module at engine.run()); HotReloader._drop_modules() (lines 141-149 of today's reload, unchanged behaviour) · class WebReloader(HotReloader): __init__(script=None, module=None, argv=(), poll=0.25, channel=True, port=PORT, web_root=None) (default <app root>/.manifoldx/web), tab: Tab (task 4; a stub with call and push until then), version: int, current: dict | None (the last version message), start(), reload(reason="edit"), step(), run() · version message {"type": "version", "version": n, "base": "v{n}/", "scene": "scenes/<sha>.glb", "scene_sha", "scene_bytes", "scene_gzip_bytes", "title", "state_sha"} · failure message {"type": "failed", "running": n, "text": "app.py:12: SyntaxError: invalid syntax"} · error_line(exc, root) -> str
  1. Write tests/web/apps/dev_orbit.py: an orbit camera whose yaw, pitch and dist live in engine.state.cam (a dict set with setdefault), a system that turns yaw with A and D and places the camera from the state every frame, one box whose colour is a module constant BOX = "#4080c0", a top-left Panel with a Text reading SPEED = 1.0 through a ValueDisplay, an @engine.on("bump") handler with the docstring Turn the camera: {"by": degrees}. that adds to yaw, and an engine.state key ("cache", 1) holding a 2-d array that cannot cross. No startup handler, so it needs no device.
  2. Write the failing tests in tests/web/test_dev_web.py, with a scripted tab (FakeTab: records pushes, answers reload_state with a value the test sets):
  3. Run uv run pytest tests/web/test_dev_web.py -q: fails with ModuleNotFoundError: manifoldx.web.dev.
  4. In hot.py, record self.main in _load (the captured lambda appends (engine, sys.modules.get("__main__"))) and move the dropping into _drop_modules(). Run uv run pytest tests/test_hot_reload.py -q: 9 passed.
  5. Implement WebReloader in src/manifoldx/web/dev.py. start(): _load(), write_static(web_root, dev=True), build and write v1 with runtime="../../pyrt.js" and scene_path=f"../scenes/{sha}.glb", write index.html from page_html(..., dev=True), open the channel. reload(reason): ask the tab (tab.call("reload_state", timeout=0.5); on NoTab or timeout, keep self.state), merge_tab_state with the last Built.crossed, log each kept key once per run, _drop_modules(), _load(), detach the previous engine, build with gpu= the previous engine's (adapter, device, format) when it had a device, write v{n+1}, push the version message, prune to the last three versions and the scenes they name. A failure at any step pushes failed with error_line and keeps self.engine, self.current and the version number. step(): poll, reload, channel.run_jobs(); run() loops step() with a 0.05 s sleep until interrupted, then closes the channel. error_line: a TranspileError or SnapshotError as its str; a SyntaxError from its filename and lineno; otherwise the innermost traceback frame in an app file; the path relative to the app's root, then : Type: message.
  6. Log one line per reload with the timings: reloaded v4 in 2.41 s (state 0.02, setup 0.08, startup 0.97, reach 0.95, snapshot 0.09, transpile 0.03, gui 0.00, scene kept 0.05, write 0.04), scene new in place of scene kept when the sha changed; and reload failed, kept v3: <error line>. Print both to stderr as manifoldx run --web: ....
  7. Run uv run pytest tests/web/test_dev_web.py tests/test_hot_reload.py -q: all pass.
  8. Commit: feat(web): WebReloader rebuilds the export on every save.
verify

uv run pytest tests/web/test_dev_web.py tests/test_hot_reload.py -q: all pass. Break it once: make reload skip the tab's state, and test_code_edit_keeps_the_scene_and_takes_the_tab_state fails on yaw.

4The dev server talks to the tabweb/dev.py · devchannel.py · tests/web/test_dev_web.py

interfaces

consumes Channel, _Handler, _bind (src/manifoldx/devchannel.py:179-349), WebReloader (task 3) · produces class Tab: connect(tab_id) -> queue, disconnect(tab_id), push(message) (to every tab), call(kind, body=None, timeout=5.0) (to the answering tab: the last connected; raises NoTab or TimeoutError), reply(call_id, payload), last_state (the last encoded state any reply or beacon carried) · Channel(root, hot, port, debug=False, web=None): with web (the WebReloader) it serves the routes below · call message {"type": "call", "id": n, "kind": "reload_state"|"state"|"patch"|"emit"|"look", "body": ...} · reply body {"ok": true, "value": ..., "state": encoded} or {"ok": false, "error": "..."}; a look's reply is the PNG with Content-Type: image/png
request (under --web)does
GET /, /v{n}/..., /scenes/..., /vendor/...files from the web root; Content-Type by suffix (.js and .mjs text/javascript, .json, .map, .glb model/gltf-binary, .ttf font/ttf, .html); a path that resolves outside the root is 404
GET /devthe dev page that GET / serves today
GET /api/web/currentthe current version message
GET /api/web/stream?tab=IDServer-Sent Events: the current version first, then every push and every call to this tab; a comment line every 15 s keeps it open
POST /api/web/reply/IDthe answer to call ID
POST /api/web/statethe tab's encoded state (the pagehide beacon)
POST /api/web/log[{"level", "text"}], each line into the log
GET, PATCH /api/state; POST /api/events/NAME; GET /api/lookforwarded to the answering tab (state, patch, emit, look); with no tab, 503 no tab is open: open http://127.0.0.1:PORT/
GET /api/eventsfrom the Python engine, as today, without startup and shutdown, whose handlers do not run in the tab
GET /api/metrics404 metrics are not measured under --web
  1. Write the failing tests, extending tests/web/test_dev_web.py with an HTTP tab client in Python (a thread that reads /api/web/stream line by line with urllib and posts replies): test_stream_starts_with_the_current_version; test_state_is_the_tabs (GET /api/state returns what the client answers); test_set_and_emit_reach_the_tab (the client receives patch with the body and emit with {"name": "bump", "payload": {"by": 10}}; an unknown event is 404 with the known ones, answered from the Python engine without a call); test_no_tab_is_503; test_the_last_tab_answers (two clients: the second answers; after it disconnects, the first); test_static_files_and_types (/browser.js is text/javascript; /../pyproject.toml and /v1/../../x are 404); test_a_tab_with_a_newer_state_triggers_a_rebuild (Q4: a beacon with a state whose cam differs, then a new client connects: a version 2 with reason tab follows); test_tab_gone_during_reload (the client stops answering: the reload completes after 0.5 s with the last state).
  2. Run uv run pytest tests/web/test_dev_web.py -q: the new tests fail.
  3. Implement Tab in dev.py and the routes in devchannel.py. Each stream is a queue.SimpleQueue its handler thread drains, writing data: <json>\n\n and flushing; a write error disconnects it. call holds a Future per id. The forwarded state, set and emit answer as the desktop's do (the state as stateView returns it, a patch returning the new state, an emit {"emitted": name, "handlers": n}), and log the same lines (state patched: ..., event bump {...}). The Q4 check runs in connect: when last_state's sha differs from current["state_sha"], the reloader's main loop gets a reload("tab") job.
  4. Run uv run pytest tests/web/test_dev_web.py tests/test_dev_channel.py -q: all pass.
  5. Commit: feat(web): the dev server streams versions and calls to the tab.
verify

uv run pytest tests/web/test_dev_web.py tests/test_dev_channel.py -q: all pass, the desktop channel's 14 unchanged.

5The tab swaps to a new version in placejs/browser.js · js/dev.js · js/scene.js · js/gui.js · js/index.html · tests/web/js/dev.test.mjs

interfaces

consumes the version message (task 3), the stream (task 4), encodeState (task 2), loadApp, buildScene, buildGui, PointerLock · produces in browser.js: loadVersion(base, info) -> Version ({state, modules, maps, app}; fetches ${base}state.json, imports ${base}app/${name}.js, reads the maps) and swap(info) (the steps below); __mx.version (the running number), __mx.swaps ([{version, ms, scene: "kept"|"new"}]) · in dev.js: connect(mx, {url, onVersion, onFailed, onCall}); status(model, message) -> model (pure: {version, phase: "live"|"reloading"|"failed"|"paused"|"offline", text}) · scene.resetMaterials() (every entity back to the material the glTF gave it) · gui.destroy() (removes its elements and listeners)
  1. Write the failing Node tests in tests/web/js/dev.test.mjs for status: a reloading then version 4 gives {version: 4, phase: "live"}; version 3 after version 4 is ignored (two saves close together); failed keeps the running version with its text; a stream error gives offline and the next version clears it. Register the suite in tests/web/test_node_suites.py.
  2. Write the failing scene and GUI tests in tests/web/js/scene.test.mjs and gui.test.mjs: after setMaterial(e, highlight), resetMaterials() puts the glTF's material back on every mesh of e and materialOf(e) is its original id; destroy() leaves the layer empty.
  3. Run uv run pytest tests/web/test_node_suites.py -q: fails.
  4. Implement. browser.js keeps the renderer, canvas, FrameBuilder, PointerLock and DOM listeners for the page's life, and holds the running Version in a variable that runFrame reads. In dev mode (<meta name="mx-dev">, written by page_html(dev=True)) it gets the version from /api/web/current, loads the scene from info.scene and imports dev.js. swap(info): ignore a version not above the running one; loadVersion; if info.scene_sha equals the running one, scene.resetMaterials(), else fetch, parse and buildScene the new glb and dispose the old one's geometries, materials and textures; gui.destroy() and buildGui from the new state; loadApp with the same hooks; set lock.input to the new input and tell it the lock is on when lock.locked; clear mx.error and hide the error panel; resume the loop; record __mx.swaps; post tab: v4 in 84 ms (scene kept) to the log. The answer to reload_state freezes the loop (Q2) and returns encodeState(engine.state); failed or 30 s without a version unfreezes. A swap that throws (a module that fails to import) shows its error as a load error does and keeps the running version.
  5. Run uv run pytest tests/web/test_node_suites.py -q: passes.
  6. Commit: feat(web): the tab swaps to a new version without a page reload.
verify

uv run pytest tests/web/test_node_suites.py -q: all pass. Task 8 checks the swap itself in Chromium.

6The overlay: reload status and errors with the Python linejs/dev.js · js/browser.js · js/index.html · tests/web/js/dev.test.mjs

interfaces

consumes status (task 5), describe (src/manifoldx/web/js/sourcemap.js), the failed message (task 3) · produces #mx-dev (a status line at the bottom right, dev mode only) and the existing #mx-error panel; overlayText(model) -> {status, panel} (pure)

The overlay's text, exact:

whenstatus lineerror panel
runningv3 · livehidden
from the state request to the swapv4 · reloadingunchanged
an edit failed to load or transpilev3 · reload failed, running v3the failure's text, e.g. dev_orbit.py:12: SyntaxError: '(' was never closed, then Fix it and save: the tab keeps running v3.
an exception in a framev3 · paused until the next editdescribe's text, as today (raises.py:26 in tick: TypeError: ... and its callers)
the stream is downv3 · dev server gone, retryingunchanged
  1. Write the failing Node tests of overlayText for each row above, the strings exact.
  2. Run uv run pytest tests/web/test_node_suites.py -q: fails.
  3. Implement. A frame exception in dev mode stops the loop as today, sets the phase to paused and posts paused until the next edit: <describe's first line> to the log, the line the desktop writes (src/manifoldx/hot.py:186). The next version clears the error and resumes. The overlay is placed so it does not cover a top-left GUI panel; it has pointer-events: none.
  4. Run uv run pytest tests/web/test_node_suites.py -q: passes.
  5. Commit: feat(web): the dev overlay names the reload's state and the Python line.
verify

uv run pytest tests/web/test_node_suites.py -q: all pass. Task 8 checks each row in Chromium.

7Agent commands answered by the tabjs/dev.js · js/manifoldx.js · js/replay.mjs · web/types.py · tests/web/js/runtime.test.mjs · tests/web/test_state_access.py

interfaces

consumes the calls (task 4), stateView, fromJSON, mergePatch (task 2) · produces fire(app, event, payload) in manifoldx.js (calls every handler root of that event with the payload, in registration order); engine.calls (today's engine.log array, renamed; traceEntry still writes it under the key log); engine.log(text) in the runtime (Node: appends to engine.lines; the tab: hooks.log(text)); "log": fn("manifoldx.Engine.log", NONE) in RUNTIME_SURFACE; lookPng(canvas, guiLayer, render) -> Promise<Blob> in dev.js
  1. Write the failing tests. Parity (tests/web/test_state_access.py): a system that calls engine.log(f"yaw {yaw:.1f}") transpiles, and in Node the lines are engine.lines. Runtime (runtime.test.mjs): fire(app, "bump", fromJSON({"by": 10})) runs the handler root once with a Map; an event no root handles does nothing; replay.mjs's output is unchanged by the rename (run tests/web/test_replay.py).
  2. Run uv run pytest tests/web/test_state_access.py tests/web/test_node_suites.py tests/web/test_replay.py -q: the new tests fail.
  3. Implement the runtime and surface changes. Then the tab's answers in dev.js: state replies stateView(engine.state); patch applies mergePatch(engine.state, fromJSON(body)) between frames and replies the new view; emit queues [name, fromJSON(payload)] and runFrame fires the queue before the systems, as the desktop runs emitted events at the start of the next frame (know-how/agent-loop.md, Gotchas); look renders the current frame (also while paused or frozen), draws the WebGL canvas into a 2D canvas of the drawing buffer's size within the same task, paints the GUI per Q5 scaled by the device pixel ratio, and posts the PNG. Every reply carries encodeState(engine.state) as state (Q4). console.warn, console.error, window.onerror and unhandled rejections post tab: ... lines, batched every 250 ms; hooks.log posts the app's lines without the prefix.
  4. Run the same command: passes.
  5. Commit: feat(web): look, state, set, emit and log against the tab.
verify

uv run pytest tests/web/test_state_access.py tests/web/test_node_suites.py tests/web/test_replay.py -q: all pass, the replay fixture unchanged.

8manifoldx run --web, end to end in Chromiumcli.py · tests/test_cli.py · tests/web/browser/test_run_web.py · tests/web/browser/conftest.py

interfaces

consumes tasks 1 to 7, the chromium and open_page fixtures and the fake lock (tests/web/browser/conftest.py) · produces manifoldx run --web [-m module | app.py] [--port N] [-- app args], printing manifoldx run --web: open http://127.0.0.1:PORT/ (dev page at /dev); fixture run_web(app_path) -> url (a subprocess in a tmp_path copy of the app, stopped by PID, reading the URL from .manifoldx/server.json)
  1. Write the failing CLI tests: run --web --debug exits 2 with Q9's message; run --web with neither script nor module is the existing usage error.
  2. Write the failing Chromium tests in tests/web/browser/test_run_web.py, each on a fresh copy of dev_orbit.py: In test_agent_commands, run the real CLI in the app's folder: manifoldx state cam prints the tab's yaw; manifoldx set '{"cam": {"yaw": 0}}' moves the tab's camera on the next tick; manifoldx emit bump '{"by": 10}' adds 10 to yaw on the next tick; manifoldx events prints bump with its docstring; manifoldx look writes a PNG of the canvas's drawing-buffer size whose pixel at the panel's centre is the panel's background within 8 per channel, and whose centre pixel is the box's colour within 8; manifoldx log --match 'tab: v2' finds the swap line after a save.
  3. Write the breaking tests: with the tab's reload_state answer replaced by an empty state (an init script), test_a_save_swaps_and_keeps_the_state fails on yaw; with resetMaterials replaced by a no-op, test_a_kept_scene_drops_runtime_materials fails.
  4. Run uv run pytest tests/test_cli.py tests/web/browser/test_run_web.py -v: fails.
  5. Add --web to run in cli.py: WebReloader(script=..., module=..., argv=app_args, **port).run(). Fix what the Chromium run finds; record each fix in "where this plan departs" with the file and line.
  6. Run the same command: passes.
  7. Commit: feat(web): manifoldx run --web, the dev loop in the browser.
verify

uv run pytest tests/test_cli.py tests/web/browser/test_run_web.py -v: all pass, the two breaking cases included, nothing skipped on a host with the browser group.

9Docs, changelog and the PRknow-how/hot-reload.md · know-how/web-export.md · know-how/agent-loop.md · AGENTS.md · CHANGELOG.md
  1. know-how/hot-reload.md: a section "In the browser: run --web" with the command, what a save does (the steps of the flow above), what crosses back from the tab (Q1), the freeze (Q2), the overlay's lines, the layout of .manifoldx/web/, and the measured reload of the first consumer once task 10 has it.
  2. know-how/agent-loop.md: the commands under --web (which tab answers, look's GUI composite, engine.log from frame code, the tab: lines, no metrics, 503 without a tab). know-how/web-export.md: drop "run --web is not there yet", add engine.log to the surface list. AGENTS.md: run --web in Quick Commands, and the Web target line names plan 3 and drops the stale "plan 2 on feat/web-target-2".
  3. CHANGELOG.md under [Unreleased]: manifoldx run --web, engine.log in the web subset, build_export.
  4. Commit docs(web): run --web in the know-how, push the branch, open the PR against main with Closes left off (#140 stays open for the second consumer), and work it until CI's test, web and browser jobs are green.
verify

CI green on the PR, the browser job listing test_run_web.py with no skips; grep -rn "not there yet" know-how/ finds nothing about run --web.

10The first consumer: its camera in engine.state, its reload measuredthe consumer's repository: app code, a reload test, its docs

Runs in the first consumer's repository after this plan's PR merges; its own issue, branch and PR, as plan 2's task 12 did. Its web build already comes from export --web (on the consumer's web-export branch at the time of writing).

  1. Pin manifoldx to the merge commit. Move the camera rig's place into engine.state as plain data: engine.state.setdefault("camera", {"pos": [x, y, z], "yaw": ..., "pitch": ..., "mode": ...}) from the default view; the rig starts from it at setup, and the frame system writes it back every frame (engine.state.camera = {...}, attribute form, floats from the rig), so a reload loses nothing (know-how/hot-reload.md, "keep the value in state"). The engine is created before the rig reads the state. Its desktop tests, its replay test and its screenshot command still pass, and the desktop manifoldx run keeps the camera across a save too.
  2. Add a reload test in its browser tests (skipped where Chromium is missing): manifoldx run --web of the app in a temp copy, walk for 60 ticks, read engine.state.camera, edit a constant the panel shows, wait for __mx.version === 2; the camera's pos, yaw, pitch and mode are equal to before the save to 1e-9, __mx.scene.scene.uuid is unchanged, and the panel shows the new text.
  3. Measure: start manifoldx run --web of the app, open the tab in Chromium, save five code-only edits and one edit that changes a material's colour, 10 s apart. Read the reloaded v{n} in ... and tab: v{n} in ... lines with manifoldx log. Report on manifoldx #140, without naming the consumer: the median and worst save-to-swap time for code-only edits and the scene edit, the phase split, the host (cores, GPU or lavapipe) and whether 3 s held. Write the numbers in know-how/hot-reload.md's run --web section (a docs PR in manifoldx), and open a follow-up issue for any phase that keeps a reload above 3 s.
  4. Update the consumer's agent docs: its dev loop is manifoldx run --web.
verify

The consumer's reload test passes on its CI; #140 has the measured reload with its phases; the slice's "done when" of the spec holds: a save shows in the open tab with engine.state kept, and the camera stays where it was.

Where this plan departs from the spec

Self-review