The snapshot is {t:'walls', scene, walls:[{id, a, b, ...}]} per DESIGN 6.1:
scene lives on the frame, entries carry only the wall record. The client
required scene on each entry and dropped every snapshot wall, so a GM
reload/reconnect showed canvas.dataset.walls==='0' while the server still
blocked player sight.
Pass the enclosing frame's scene into wallViewFromFrame and keep an entry's
own scene as the tolerant fallback. The server already matched DESIGN, so
no wall wire shape changed.
Tests: client reducer from a real snapshot frame, WS pin that a snapshot
entry equals a wall delta record, and e2e reload plus server-restart.
The old e2e missed it because every wall test built walls in-session.
FFF VTT client
Vite + TypeScript + PixiJS v8, plain DOM overlay, proto 2 (DESIGN §7, ADR-0011). No framework.
Run and gates
All through devbox, from the repo root:
devbox run client-test # Vitest: pure reducer + protocol client + envelope (no DOM, no GPU)
devbox run e2e # builds client/dist, then Chromium against the real server through the
# TLS/HTTP2 test nginx (client/e2e/*.test.mjs, playwright-core)
devbox run test # the server gate; unaffected by the client
devbox run -- bash -c 'cd client && npm run dev' # local dev (Vite, no server API on :5173)
npm run build = tsc --noEmit && vite build into client/dist, which the test/production nginx
serves at / (DESIGN §11.1). client/dist and client/node_modules are not committed.
The one seam that matters
src/reducer.ts is pure: server frames and connection events in, state out. It must never import
Pixi, the DOM, or the socket. Its unit tests (test/*.test.ts) are the contract. Everything else
is wiring:
| File | Owns |
|---|---|
src/protocol.ts |
Wire types, envelope/ack/closing guards, intent encoding, /ws?proto=2 URL. Pure. |
src/reducer.ts |
RootState, phase machine (boot/connecting/signin/live/reload/offline), hello reset, slice registry. Pure. |
src/slices/*.ts |
Append-only domain state (roster today; fog, tokens, walls, panels later). |
src/ws.ts |
Socket, reqId counter, pending map, close-code mapping, backoff and retry. No DOM. |
src/shell.ts |
Sign-in, HUD/roster, fatal screens. Plain DOM, textContent only. |
src/render/stage.ts |
One Pixi Application, one world container, fixed layers. Pixi lives here and in modules only. |
src/render/modules/*.ts |
Append-only render modules. |
src/main.ts |
Wiring: store -> shell/stage, /join, connect. |
Convention for the M4 fan-out (T7, T8/T9, T10, T11/T12)
The registry is a build-time glob, so parallel tickets are file-disjoint: no shared import list to merge and no registry file to edit.
- State slice: add
src/slices/<feature>.tsexportingexport const slice: Slice<YourState>(name,init(),reduce(state, event, root)). It is registered automatically. Read it withsliceOf<YourState>(state, '<name>').helloresets every slice for you (DESIGN §6.3): never keep server-derived state outside a slice or the core session. - Render module: add
src/render/modules/<feature>.tsexportingexport const renderModule: RenderModule(name,mount(context), optional teardown). Draw into your layer:tiles,grid,tokens,fog(players),gm(GM only),dom. - Panel/DOM: add
src/panels/<feature>.tsand mount under the existing#panelshost; do not rewrite the sign-in flow. Server strings go throughtextContent(neverinnerHTML); token labels useBitmapTextwith the pre-installedBitmapFont(DESIGN §7.2). - No per-frame full redraw: subscribe to the store and touch only entities that changed (DESIGN §7.2). Keep the DOM overlay work per frame minimal.
- Protocol: only the catalogue in DESIGN §6.1. The client ignores unknown frame types/fields
(§6.2).
closingreasons map throughcloseOutcome:proto-mismatch-> reload,revoked-> sign-in,evicted/malformed-flood-> offline. Do not invent wire fields; server-side additions are separate tickets (e.g.seen_by, T12).
Suggested ownership (no file overlap): T7 fog = slices/fog.ts + render/modules/fog.ts; T8/T9
tokens/drag = slices/tokens.ts, slices/move.ts, render/modules/tokens.ts; T10 walls =
slices/walls.ts + render/modules/walls.ts; T11/T12 GM panels = slices/admin.ts +
src/panels/*.ts. src/reducer.ts, src/main.ts and src/render/stage.ts are already generic;
change them only if a slice needs a new core event, and say so in the PR.
Protocol notes already encoded
/ws?proto=2; a mismatch isclosing{reason:"proto-mismatch",code:4003}then close. The reason is read from the lastclosingframe because browsers report 1005 at the mummy pin (ADR-0019).helloresets all state; the resync after it rebuilds the view. PendingreqIds survive ahelloon a live connection and die with the socket (DESIGN §6.3).- Sign-in is
POST /join(form body, key never in the URL). A401for a wrong key and for an unknown key is shown as the same "Key not recognised." (DESIGN §3.2, story 3). - No game data (and no Pixi
Application) exists before a livehello; a visitor without a session only sees the sign-in page.
Traffic audit and the M4 measurement (T13, #76)
- Traffic audit (
e2e/audit.test.mjs) is the independent proof that the player browser cannot become a leak. It records the page's own WebSocket frames and HTTP responses and applies its own rules: only the 13 player frame types; no wall field and no GM-only token column at any depth; no other player's id and no token outside the player's sight; vision polygons only for controlled tokens; explored cells only inside a historical own-vision bbox; tiles only under/tiles/, only 200/403, every served tile covering an explored cell, and/_tiles/unreachable. The banned-key list is written in the test, never imported fromtools/leakcheck.nim, so the proof is independent of the server's own list. A second test is the negative control: the same rules run against a-d:leakfaultbuild withLEAK_FAULT=otherVisionand must catch the injected foreign polygon. - 50-token measurement: the server half is
tools/fogbench.nim(devbox run fogbench, Full HD 1920×1080, the max scene, 50 tokens, thousands of walls); the headless half ise2e/fogbench.test.mjs. Numbers and the honest caveat (SwiftShader is a floor, not a phone) are inresults/m4-fog-bench.md. The real 60 fps run is #77.
Name, badge and reconnect (T5, #68)
- First sign-in name prompt. A live player with
me.name === nullgets the#namesection instead of the HUD, and no Pixi stage (the server sends no scene, no state, until named). Submitting sendsplayer.setname; the server acks before the secondhello(FIXED #33), so a refusal's code becomes visible text on the prompt (name-taken→ "That name is taken. Choose another.",invalidandnot-allowedhave their own copy) and an acceptance is followed by thehellothat resets every slice plus the 6.3 resync. The prompt is keyed on state, so it cannot come back and survives a reload with the same session. - Badge (
#badge[data-state]):connectedwhile live;reconnectingwhile the socket backs off, with the stale map staying on screen;offlinewhen the browser reports no network (navigator.onLine/online/offlineevents) or after a terminal outcome (evicted,malformed-flood,server-shutdown). Hidden on boot, sign-in and reload. - Reconnect (DESIGN 6.3): a transport close (no
closingframe) after a connection has been live retries withbackoffDelay: base 1/2/4/8/10 s then the cap, ±20 % jitter (RECONNECT_BASE_DELAYS_MS,RECONNECT_JITTER). Terminal reasons never retry:revoked→ sign-in,proto-mismatch→ reload. PendingreqIds die with the socket; a browseronlineevent callsretryNow()to skip the rest of the wait. The view is not cleared on a drop:hellois the reset point, and the resync that follows rebuilds tokens, fog, explored, markers and lists. - Two devices of one player both stay live and receive the same frame stream (each connection
has its own
knowntable, DESIGN 6.3). - Proof:
test/ws.test.ts(schedule, retry state machine, pending drop) andtest/reducer.test.ts(badge transitions, reconnect reset, name errors) are the unit seam;e2e/session.test.mjskills and restarts the real server under a live page, drops the browser network withcontext.setOffline, asserts the badge transitions and the full resync frames, and runs two pages on one key.
Map tiles, grid and pan/zoom (T6, #69)
- Camera (
src/viewport.ts, pure): the world container isscreen = world * zoom + (x, y). Players clamp at0.5and the GM has no player floor (a1/64sanity floor only keeps the transform non-singular); both clamp at4.0(ADR-0013, spec #63 decision 7). Wheel and pinch zoom around the pointer/midpoint, one-finger drag pans. Input is hand-rolled DOM pointer/wheel events on the canvas (src/render/modules/camera.ts, DESIGN 7.2: no Pixi federated events), and the canvas getstouch-action: none. - Camera is not a reducer slice. It is local UI state; a
helloresets every slice by design, and a reconnect must not move the player's view.ViewportModelis owned by the render layer and reset only when a new stage is created. The canvas carries the e2e factsdata-zoom,data-gridanddata-view(viewport px). - Tiles (
src/tiles.tsscheduler +src/render/modules/tiles.tslayer): the wanted set isvisibleTiles()— every tile intersecting the viewport plus exactly one tile of margin, clamped to the scene — ordered centre-out (orderTilesCentreOut), so a survey fill grows from what the eye is on instead of the top-left corner. The scheduler keeps at mostTILE_CONCURRENCY(32, the measured knee on a Full HD scene) loads in flight, drops queued tiles that leave the window, never asks twice for a tile, and remembers a403asdenied: the gate has said "not yours", so it is not retried in a loop (it is asked once more whenfog.freshsays its cells were explored). A404/5xx/network failure is transient: up to 3 loads with 250/500 ms backoff, and a reconnect (hello) or a scene/art_versionchange resets the budget and re-asks. The settle path is incremental (one settle = one tile), so filling tens of thousands of tiles is not quadratic. The decoded-texture cache is module-level and keyed by URL, so a reconnect keeps every tile; a newart_versionchanges every URL, so it drops the cache and refetches.data-tilesisreadyonce the current pass is complete: every wanted tile has a terminal answer (ok,denied, or a stored transienterrorthat waits for a retry, a new window or a reconnect). A transienterroris deliberately not pending, otherwise one host hiccup would hold the flag atloadingand hang every e2e readiness wait.data-tile-requestscounts fetches;data-tile-distinctcounts the distinct tile URLs fetched, so the #70 re-ask of a tile whose 403 became allowed shows in the former, not the latter. - One request per tile:
fetchthencreateImageBitmap(decode off the main thread). An<img>error carries no status, so classifying it cost a secondfetchfor every failure; the fetch-first path gets 403 vs 404/5xx from the same response and lets the scheduler retry a missing tile instead of leaving a permanent hole. - Grid (
src/render/modules/grid.ts): oneTilingSpriteover agrid_sizecell texture, drawn once, toggled by#grid-toggle(story 18). No per-frame redraw. - Tile-size gate (a) (
client/e2e/map.test.mjs): mobile emulation 412×869 CSS px, DPR 2.625, touch; real server through the TLS/HTTP2 nginx; viewport 412×869 at zoom 1. Each sample is a fresh page load measured from the canvas becoming visible todata-tiles=ready, i.e. one first viewport filling. A single wall-clock sample is host-load-sensitive, so the gate is the fastest of 4 samples after 1 warm-up (min-of-N, TESTING §5.3), asserted against 2× the 1 s budget (the documented saturated-host tolerance) and printed with every sample on every run. Measured 2026-11-21: 439 ms fastest on the dev host (samples 628, 778, 444, 439 ms); 1.3–1.9 s fastest under a saturated 16-core host with the same binary. The same test then applies CDP's 4× CPU throttle for the grid, pinch and reconnect checks. Note: under the 4× throttle the fill itself takes ~3.2 s, because CDP multiplies each of the ~480 image-load callbacks; that measures the throttler rather than the app, so the gate is measured at real CPU and gate (b), the real-phone run (#77), remains authoritative for phone speed.
GM wall editor, round-1 fields (T10, #73)
- State:
src/slices/walls.tsis the GM wall slice:walls(full snapshot on connect/resync),wall(upsert, doors included) andwall_gone, plus the editor's selected id and its single-step undo descriptor. Wall frames are GM-only, and the slice also ignores them on a player-shaped session, so a server bug could not quietly turn the client into a wall-data renderer.helloresets it like every slice. - Pure rules:
src/wallEditor.tsexpands the four 5.8 presets (wall,door,window,one_way), deriveskindin the fixed order (window, one_way, door, wall, else custom), computes the one-way arrow toward the blind side named bysight_dir, snaps to endpoints then the grid, and builds the exact DESIGN 6.1 payloads. A preset payload carries onlypreset(never a raw switch,open:falseincluded);wall.updatenever carriesopenbecause opening and closing aredoor.set. The same module holds the local pre-flight validation so an impossible combination is shown before an intent leaves the browser. - Renderer + input:
src/render/modules/walls.tsdraws each wall on thegmlayer (derived-kind colour, open doors dashed, secret doors dotted, selected endpoints, the one-way arrow and the marker switch). Input precedence is explicit: token drag (#72) wins first and consumes its gesture; wall drawing wins next while a preset is armed (the two clicks never pan); otherwise the camera (#69) pans and a click with no movement selects the nearest wall. A drag that moved is a pan, not a selection. The canvas publishesdata-walls,data-wall-kinds,data-wall-selected,data-wall-arrows,data-wall-markers,data-wall-draw,data-wall-previewanddata-wall-undofor the e2e. - Panel:
src/panels/walls.tsadds#gm-wallsunder#panelsvia the render module (no shared bootstrap edit): preset buttons arm the draw, then the selected wall exposes its server-derived kind, label,player_marker, door/open/close,secret/locked, the advanced raw switches (withApply switches), the one-way flip, delete and Undo. A locked or secret door's open action showslocked: unlock first/secret: clear secret firstand the one click that clears the block instead of sending a refused intent. No thickness, height or position control (ADR-0012). Controls are repopulated only when the server record changed (src/panels/wallSync.ts): the ack dispatch carries the previous record, so repopulating on every render would revert a just-toggled switch for the round trip until thewallframe lands (and a host pause could make that visible). - Proof:
test/walls.test.ts(slice load/upsert/remove/reset, player frames ignored, preset expansion, derived kind, arrow side, snap, payload XOR rules,openexcluded from updates, undo intents, local validation) ande2e/walls.test.mjs(real server: draw all four presets, label, marker, locked hint + one-click unlock, open/close, advanced invalid combination shown, delete + undo, a token drag still beats draw mode, and the player's fog pixels change for a wall, a one-way flip, a door open/close and the marker, with no wall data in the player's frames).
Tokens, labels, statuses and the two lists (T8, #71)
- State:
src/slices/tokens.ts(tokenupsert,token_gone,helloreset;tokensOf),src/slices/characters.ts(character/character_gone,ownCharactersOf) andsrc/slices/encountered.ts(fullreplace,set/deldiff, grey flag; the GM's per-player copies are ignored). All three are append-only slice files: the registry andmain.tsare untouched. - Renderer:
src/render/tokenBoard.tsis the pure half. It turns the store's events into the exact nodes to touch —entered,updated,left, or ahelloreset — and keeps the view it last drew, so a frame that moves one token updates one container and nothing else (DESIGN 7.2). It also seeds itself from the reducer on mount, becauseapp.init()is async and the resync can beat the stage.src/render/modules/tokens.tsis the Pixi half: pooled containers on thetokenslayer in world coordinates (the camera from #69 transforms the layer's parent, never a token), one shared unit-circleGraphicsContextper kind scaled to the effective radius, andBitmapTextlabels from one pre-installedBitmapFont(fff-token-label: Latin, accented Latin and ASCII) assigned only when the name actually changed.stuckandsqueezedare drawn badges (barred ring, inward brackets); the cause is never drawn because a player never receives it. - Instrumentation for the "only changed entities touched" acceptance criterion lives on the
canvas dataset:
data-tokens,data-token-entered,data-token-updated,data-token-left,data-token-labels,data-token-ids,data-token-statuses. It is updated only when a patch did something, ande2e/tokens.test.mjsreads it against the real server. - Lists panel:
src/panels/lists.ts(#listsunder the shell's#panels:#characters,#encountered, rows withdata-character/data-tokenanddata-grey,textContentonly) is mounted bysrc/render/modules/lists.ts, a render module, so the panel's lifetime is the live stage's and no shared bootstrap file had to change. Greyed rows carry bothdata-grey="true"and thegreyclass, plus an "out of sight" label so the state is not colour-only. - Drag seam (#72):
applyView(node, view, stats, at?)already takes the position to draw, so a drag module can pass its optimistic position for the node under the pointer and let the authoritative view resume on ack/rollback. The reducer's token view stays the server's word. - Proof:
test/tokens.test.ts(enter/update/leave, status names withoutsource, GM fields, malformed frames),test/lists.test.ts(own characters, encountered full/diff/grey, GM copies),test/token-board.test.ts(one changed entity per frame, no phantom enter+leave, reset onhello, seeding) ande2e/tokens.test.mjs(real server: player and GM token sets, agm_onlytoken the player never receives, the stuck badge, both lists,token_goneplus the grey flip, and one-entity updates with unchanged label builds).