diff --git a/docs/DESIGN.md b/docs/DESIGN.md index 7184df1..47badbc 100644 --- a/docs/DESIGN.md +++ b/docs/DESIGN.md @@ -1,6 +1,6 @@ # FFF_vtt design -Status: draft v0.4, 2026-11-08 (owner decisions recorded in section 14; v0.4 records Q4 (tile_size 32 px), the outbox lock invariant (4.2, 4.3), and the follow-ups in 3.4, 8, 11.1, 12, 13. All of Q1-Q24 are RESOLVED or DEFERRED; none OPEN). Audience: the owner and coding agents. +Status: draft v0.5, 2026-11-08 (owner decisions recorded in section 14; v0.4 records Q4 (tile_size 32 px), the outbox lock invariant (4.2, 4.3), and the follow-ups in 3.4, 8, 11.1, 12, 13; v0.5 records the M2 move-rule decisions in 5.5 and updates 3.4, 4.2, 5.1, 5.4, 6.1, 7.4, 8, 10.3, 12, 13. All of Q1-Q24 are RESOLVED or DEFERRED; none OPEN). Audience: the owner and coding agents. Legend: - **[FIXED]** owner decision, not up for debate here. @@ -140,7 +140,7 @@ Notes: | T5 | Tile-edge over-disclosure: one 32 px cell grazed by vision, never revoked | tile_size = explored cell = 32 px, no server masking, authoring rule ~32 px (Q4 FIXED) | documented, not testable as a leak; M4 timing gates (13) | | T6 | Invite/session theft via logs, referrer, history | session != invite, log redaction, no-referrer, HTTPS only | config test (grep logs for secret) [new] | | T7 | Cross-site WS hijack | Origin check + SameSite=Strict | new test | -| T8 | **Wall-probing oracle via move validation** [INFERRED, not in prototype tests]: `moveBlocked` answers `ok:false` for any chosen segment, with unlimited length; binary searching lets a player map walls beyond LOS and tell open from closed doors | cap step length per intent (= token vision radius, Q18 FIXED), rate limit intents per connection, uniform nack that carries only the old position | new probing test: count wall/door facts recoverable from nacks beyond LOS | +| T8 | **Wall-probing oracle via move validation** [INFERRED, not in prototype tests]: `moveBlocked` answers `ok:false` for any chosen segment, with unlimited length; binary searching lets a player map walls beyond LOS and tell open from closed doors | cap step length per intent (= token's effective vision radius, scene default if no vision; 5.5, Q18 FIXED), rate limit intents per connection, uniform nack that carries only the old position (5.5) | M2 in-process probing test (5.5, 13); WS version in M3 (10.3): count wall/door facts recoverable from nacks beyond LOS | | T9 | Info via error replies (`not yours` echoing a position) | errors are static strings, never state; move of non-owned token gives `error` without position [MEASURED rule, README Findings] | leak test (e) | | T10 | Message-size or rate DoS, slow client memory growth | max frame size, per-connection rate limit, connection cap; **bounded per-connection outbox** (byte/message caps, state coalescing), lagging clients stopped and resynced (4.3, Q13); mummy queue is unbounded [MEASURED finding, README mummy caveats] | new tests (10.3 slow client, protocol) | | T11 | Timing/size side channels (message bytes reveal hidden activity) | accepted; only deliver messages when state visible to that recipient changes | not tested | @@ -169,7 +169,7 @@ Single process, in-memory authoritative state, SQLite as write-through persisten Under the single global lock (as prototype, order proven correct by 3 x 60 s runs): 1. **Parse** with strict type checks (prototype pattern: kind checks per field). Unknown `t` -> `error`. 2. **Authorize**: role/ownership. -3. **Validate**: bounds, step cap (T8), collision (`moveBlocked` with token radius), referential integrity, property schema. +3. **Validate**: bounds, step cap (T8), collision (player moves: 5.5; GM moves skip walls and step cap), referential integrity, property schema. 4. **Apply** to memory. 5. **Recompute** vision only for players whose input changed (mover's owner; all players for door/wall changes). Update explored; collect `fresh`. 6. **Persist**: `BEGIN; ...; COMMIT` including dirty explored chunks. @@ -182,9 +182,9 @@ Invariants (carry from prototype): - A failed validation mutates nothing, bumps nothing, persists nothing. - Non-owned/malformed requests get `error`, never an ack (an ack would echo an unseen position). -Known limitation [PROPOSED fix]: prototype checks only the centre path a->b and the destination circle, not the swept circle (corner clipping possible, `HANDOFF.md`). With step cap the exposure is bounded; M2 decides swept-circle check (capsule vs wall distance). +Known limitation of the prototype, fixed in M2 [FIXED, accepted default; 5.5]: it checks only the centre path a->b and the destination circle, not the swept circle (corner clipping possible, `HANDOFF.md`). M2 adds the capsule (swept-circle) check and the step cap. -Second limitation [INFERRED]: a fast drag sampled at ~50 ms can produce a straight segment that cuts a corner the pointer path did not, causing a nack and a snap-back. Mitigation: client sends intermediate points when the step would exceed the cap (token vision radius, Q18); server clamps nothing silently (clamping would leak the hit distance, T8). +Second limitation [INFERRED]: a fast drag sampled at ~50 ms can produce a straight segment that cuts a corner the pointer path did not, causing a nack and a snap-back. Mitigation: client sends intermediate points when the step would exceed the cap (token's effective vision radius, 5.5, Q18); server clamps nothing silently (clamping would leak the hit distance, T8). ### 4.3 Locking and threading - mummy: `WebSocket.send` appends the encoded frame to one server-wide deque under `sendQueueLock` and wakes the IO thread; worker threads handle events; per-socket events are serialized [MEASURED reading, `prototype-server-vision/README.md` "mummy suitability", mummy.nim ~L262-311]. @@ -240,7 +240,7 @@ explored_chunk(player_id, scene_id, cx, cy, bits BLOB, PRIMARY KEY(player_id, sc - **Visibility polygon** from token centre: cast rays to every blocking wall endpoint at angle -eps, 0, +eps (`RayEps` = 1e-4 rad), plus an inscribed 64-gon of radius R as range limit; sort by angle; each ray returns nearest hit among wall segments + circle segments; result = CCW polygon. Open doors (`door && open`) do not block. - **Explored**: `cellsTouched(poly, cell)` marks every grid cell that the polygon overlaps; union into the player's explored set. Vertex-in-cell test added after a bug (polygon wholly inside one cell) [MEASURED bug log, prototype `NOTES.md`; covered by `tests/tgeometry.nim`, suite "cells", test "tiny polygon inside one cell"]. - **Token visibility** to a player: token centre inside any of the player's polygons (even-odd `inside`). -- **Move validation**: inclusive segment intersection on blocking walls (touching = blocked, so no squeezing through shared vertices) AND destination circle at distance >= token radius from every blocking wall. +- **Move validation (prototype)**: inclusive segment intersection on blocking walls (touching = blocked, so no squeezing through shared vertices) AND destination circle at distance >= token radius from every blocking wall. Replaced by the M2 rules in 5.5; the prototype result is a baseline only. ### 5.2 Edge cases handled and tested [MEASURED, `tests/tgeometry.nim`, 33 test blocks / 98 checks ported, none dropped, `results/nimble-test.log`] - Collinear rays skipped (neighbouring +-eps rays cover them). @@ -265,14 +265,43 @@ Conclusions: - Skip recompute when the token moved but its polygon is unchanged (prototype already compares `np == r.polys`). ### 5.4 Known limitations (carry forward) -- Token exactly on a wall cannot move off it: `moveBlocked` counts any touch as a hit, so every move from that point is blocked, even a perpendicular step to the open side [MEASURED limit, `tests/tgeometry.nim` test "KNOWN LIMITATION: token exactly on a wall cannot move off it"; also in the `server/geometry.nim` header]. Known limitation, not a policy. Fix: escape rule in M2 (section 13). The escape is required by Q14 so the GM can move such a token: mechanism [PROPOSED], requirement [FIXED]. A validated move cannot reach this state (a destination within r of a wall is rejected) [INFERRED from `moveBlocked`]; it can arise from a wall/door edit landing on a token (Q14: status `blocked`), or from a placement intent (6.1 does not say whether placements are collision-checked). -- Closing a door (or editing a wall) on a token [FIXED, Q14]: the token gets status `blocked`. The server refuses that token's player moves; the GM can still move it; status clears when the wall is removed or the door opened, or when the GM clears it. Current pin: `tests/tgeometry.nim`, suite "door/wall closing on a token", test "door closed on a token: Q14 undecided, DESIGN 5.4 vs 12 H2 conflict": a token whose centre is 10 px off a closed door may move to a clear spot, may not stay overlapped, and may not cross the door. It pins `moveBlocked` only; it is replaced in M2 by tests of the policy above. +- Token exactly on a wall cannot move off it: `moveBlocked` counts any touch as a hit, so every move from that point is blocked, even a perpendicular step to the open side [MEASURED limit, `tests/tgeometry.nim` test "KNOWN LIMITATION: token exactly on a wall cannot move off it"; also in the `server/geometry.nim` header]. Known limitation, not a policy. Fixed in M2 by the escape rule (5.5). The escape is required by Q14 so the GM can move such a token: mechanism [PROPOSED], requirement [FIXED]. A validated move cannot reach this state (a destination within r of a wall is rejected) [INFERRED from `moveBlocked`]; it arises from a wall/door edit (`blocked` trigger, 5.5) or from a GM placement on a wall (GM placements ignore walls, 5.5); the escape rule covers both. +- Closing a door (or editing a wall) on a token [FIXED, Q14]: the token gets `blocked` (trigger narrowed to circle overlap, 5.5). The server refuses that token's player moves; the GM can still move it; status clears when the wall is removed or the door opened, or when the GM clears it. Current pin: `tests/tgeometry.nim`, suite "door/wall closing on a token", test "door closed on a token: Q14 undecided, DESIGN 5.4 vs 12 H2 conflict": a token whose centre is 10 px off a closed door may move to a clear spot, may not stay overlapped, and may not cross the door. It pins `moveBlocked` only; it is replaced in M2 by tests of the 5.5 policy (under the 5.5 trigger this token is `blocked`, so player moves are refused). - Boundary epsilon ambiguity (RayEps 1e-4, inclusive tolerances). - Explored and tile checks in the leak test recompute with the server's own `cellsTouched`: self-consistency only (caveat in 10.2). New independent oracle in section 10. - Doors/walls changing does not un-explore anything; explored only grows [MEASURED behaviour]. - Single uniform vision radius in prototype; v1 uses a per-entity numeric property (`vision_radius`) with scene default; no light/darkvision [FIXED, Q7]. - Vision origin = token centre, radius is not clipped by the token's own size. +### 5.5 Move rules and `blocked` (M2 decisions, 2026-11-08) +Normative for M2. Replaces the prototype move validation (5.1) and the move-related limitations in 4.2 and 5.4. Implemented as a pure in-process module with unit tests; the WebSocket layer only maps its result to `moveAck`. The WebSocket probing test is M3. + +Notation: token centre `c`, radius `r` (scene `token_radius`), start `s`, destination `d`. Blocking wall: segment with `kind=wall`, or `kind=door` with `open=false`; open doors do not block. `dist(X, W)` = distance from point or segment `X` to segment `W`. "Overlaps" = `dist < r` (strict; touching at exactly r is clear). + +**`blocked` flag** (stored bool on the entity, persisted) [FIXED, owner (B) and Q14, except where marked] +- Set [FIXED, owner (B)]: a wall is added, or a door is closed, and the new blocking segment overlaps any part of the token's circle, i.e. `dist(c, W) < r`. Centre-on-wall is not required. +- Clear [FIXED, Q14]: the wall is removed, the door is opened, or the GM clears it. The GM-clear wire intent is defined in M3, not M2. +- `wall.update` = remove then add for this rule [PROPOSED; not in the owner's list]. +- GM placements and GM moves never set `blocked` [PROPOSED; follows from (D)]. + +**Player move `s -> d`** [FIXED, accepted default]. Checks in order; any failure gives the uniform nack. +1. Owner check (non-owned -> `error`, as now) and token not `blocked`. +2. Step cap [FIXED, owner]: `|d - s| <= cap`, where `cap` = the token's `vision_radius` if the token has `vision` and sets it, else the scene's `vision_radius_default`. +3. For each blocking wall `W`: + - if `dist(s, W) < r` (start overlaps `W`, escape case): allowed only if the path `s->d` does not cross `W` (crossing at parameter t > eps; collinear overlap counts as crossing) AND `dist(d, W) >= r`; + - otherwise (swept/capsule check): allowed only if `dist(segment s->d, W) >= r`, which also gives `dist(d, W) >= r`. +4. Accept: `moveAck{ok:true, pos:d}`. Nack: `moveAck{ok:false, pos:s}` for blocked, over-cap and collision alike. No reason field. + +**GM move** [FIXED, owner (D)]: no wall check, no step cap, ignores `blocked`. Bounds and referential checks still apply. + +**Wall index** [FIXED, accepted default, H3]: radius-bbox cull first; uniform spatial grid over walls only if the 5k-wall bench misses target (13, M2). + +**Thresholds and tolerances** [FIXED, accepted default]: `eps` and any float tolerance are chosen by the implementer and documented in the module header. Oracle comparisons use 0.5 px, as the leak checker (T14). + +**Regression baseline** [FIXED, accepted default]: "results equal old implementation" = `visibilityPolygon` and `cellsTouched` on the prototype leak transcripts plus `tests/fixtures/scene.json`. `moveBlocked` is excluded: its results change on purpose. + +**Unconfirmed** [PROPOSED, owner to confirm]: (a) `wall.update` as remove + add; (b) a door opened while another closed wall still overlaps the token clears `blocked` (literal Q14 wording). + --- ## 6. Protocol @@ -285,9 +314,9 @@ Client -> server (intents). Authority column: P = player, G = GM. | t | fields (contract) | who | server behaviour | |---|---|---|---| -| `move` | `reqId:int, id, pos:[x,y]` | P (owned) / G (any) | validate; reply `moveAck` (+ `token` diffs); non-owned -> `error`; P move of a token with status `blocked` -> `moveAck{ok:false}` (Q14) | -| `door` | `id, open:bool` | G | toggle; recompute all players; sets/clears `blocked` on tokens under it (Q14) | -| `wall.add` / `wall.update` / `wall.remove` | wall fields / `id` | G | validate geometry; recompute all players; GM-only broadcast of wall delta; sets/clears `blocked` on tokens under it (Q14) | +| `move` | `reqId:int, id, pos:[x,y]` | P (owned) / G (any) | validate; reply `moveAck` (+ `token` diffs); non-owned -> `error`; P move refused (`blocked`, over step cap, or wall collision; 5.5) -> `moveAck{ok:false, pos:old}`, one uniform nack; G move ignores walls, step cap and `blocked` (5.5) | +| `door` | `id, open:bool` | G | toggle; recompute all players; close sets `blocked` on tokens whose circle overlaps the door, open clears it (Q14, 5.5) | +| `wall.add` / `wall.update` / `wall.remove` | wall fields / `id` | G | validate geometry; recompute all players; GM-only broadcast of wall delta; add sets `blocked` on tokens whose circle overlaps the wall, remove clears it, update = remove + add (Q14, 5.5; update PROPOSED) | | `entity.create` / `entity.update` / `entity.remove` | kind, name, pos, owner, props buckets | G | validate against property schema; view diff | | `prop.set` | `id, bucket, key, value` | G (v1) | owner-bucket writes by players come with FFF actions (section 9) | | `scene.set` | scene meta | G | broadcasts new `hello`-equivalent reset to all; no `scene.activate` (one scene, Q3) | @@ -304,7 +333,7 @@ Server -> client. | `door` | `id, open` | GM only (players learn only via LOS changes) | | `vision` | `polys` (integer px, owned tokens only) | player | | `explored` | `cells` (full on connect, fresh cells after) | player | -| `token` | `id, name, kind, pos, mine, status` (e.g. `blocked`, Q14), visible props | per visibility | +| `token` | `id, name, kind, pos, mine, blocked` (bool, Q14, 5.5), visible props | per visibility | | `remove` | `id` (left LOS / deleted) | per visibility | | `moveAck` | `reqId, ok, pos` | sender only | | `error` | static `msg` code | sender only | @@ -365,7 +394,7 @@ Prototype `client/src/main.ts`: explored rects appended to a `Graphics` mask for ### 7.4 Input and UI - Mouse: wheel zoom, drag pan, drag token. Touch: one finger drag/pan, two-finger pinch/pan [MEASURED works on Note 10]. - Wall editor (GM) [FIXED, Q6: in v1, kinds `wall`|`door` only]: click-click segments, snap to grid/endpoints optional, door tool, delete, undo of last edit [PROPOSED]; submits `wall.*` intents; server is the validator. -- Grid snap on drop: client option, off by default [FIXED, Q18]. Server accepts any in-bounds free position within the step cap (token vision radius, Q18 FIXED). +- Grid snap on drop: client option, off by default [FIXED, Q18]. Server accepts any in-bounds position within the step cap and clear of walls (5.5; step cap = effective vision radius, Q18 FIXED). ### 7.5 Prediction and rollback for own moves - Players do **not** know the walls, so the client cannot predict collisions [INFERRED, consequence of strict model]. Prediction = optimistic placement of the dragged sprite, send `move` with `reqId` at <= 20 Hz, and a final send on release. @@ -384,7 +413,7 @@ All ids are server-assigned, opaque, non-guessable where they are exposed to pla - **Scene** (exactly one in v1, Q3): `id, name, w, h` (px), `tile_size` (32 default = `explored_cell` [FIXED, Q4]; 64 is the per-scene fallback), `explored_cell` (32 default; `tile_size % cell == 0` required, prototype assumes it silently), `grid_size`, `vision_radius_default`, `art_version`, `active`, free-form `extra`. - **Wall/Door**: `id, scene, a:[x,y], b:[x,y], kind ('wall'|'door'), open:bool, flags`. `blocks = not (door and open)`. GM-only everywhere. Later kinds (window, one-way, secret door) are extra `kind`/`flags` values; v1 geometry treats any non-open blocker identically. - **Entity (token and anything else) [PROPOSED, FFF seam]**: - - `id, scene, kind` (free string: `pc`, `npc`, `item`...), `name`, `pos`, `radius`, `owner` (player id or null = GM-controlled), `gm_only`, `flags` (`vision`, `blocks_move`...), `vision_radius` (optional; per-entity numeric with scene default, Q7 FIXED), `status` (e.g. `blocked`, Q14). + - `id, scene, kind` (free string: `pc`, `npc`, `item`...), `name`, `pos`, `radius`, `owner` (player id or null = GM-controlled), `gm_only`, `flags` (`vision`, `blocks_move`...), `vision_radius` (optional; per-entity numeric with scene default, Q7 FIXED; also the player step cap, 5.5), `blocked` (bool stored flag, Q14, 5.5). - `props`: three JSON objects by visibility bucket: `public` (anyone who sees the entity), `owner` (owner + GM), `gm` (GM only). Keys are strings, values JSON scalars/arrays/objects with a size cap. No hidden state beyond these buckets and `gm_only` in v1 [FIXED, Q19]. - The server never interprets props in v1 except via a registered property schema (type, bucket, writable-by) used for validation and for FFF later. - **Player**: `id, name, role (gm|player), colour`. Exactly one GM. @@ -436,7 +465,7 @@ Principles carried from the prototype: the checker must be independent of the co ### 10.3 New - **Fault classes** for new data: `GMONLY_TOKEN`, `OWNER_PROP`, `GM_PROP`, `GLOBAL_COUNTER` (gseq side channel), `WALL_DELTA` (wall.add reaches player), `INVITE_IN_LOG`. Each with an injected fault and exact-class assertion, same as existing. -- **Probing test (T8)**: a hostile client issues arbitrary far moves; assertion: facts about walls/doors beyond LOS recoverable from replies <= a bounded amount (step cap), and uniform error shape. +- **Probing test (T8)**: M2, in-process against the move-rules module (5.5): arbitrary far moves; assertion: facts about walls/doors beyond LOS recoverable from replies <= a bounded amount (step cap), and uniform nack shape. M3: same test over WS with a hostile client (moved from M2). - **Auth tests**: invite revoke, one invite reused on several devices (Q10 FIXED), Origin mismatch rejected, cookie flags present. - **Protocol tests**: proto mismatch, unknown message type both directions, oversized frame, malformed JSON flood, rate limit. - **Persistence**: migration tests (old DB -> new), chunked explored round trip, restart test extended to wall CRUD and entity props. @@ -490,15 +519,15 @@ Source: `prototype-server-vision/HANDOFF.md` (and README/NOTES worries). | # | Item | Decision / open | Milestone | |---|---|---|---| | H1 | Port geometry + tests as-is | Decision: port `geometry.nim`, `tgeometry.nim`, mutation check, leak harness first | M1 | -| H2 | Token on a wall can't leave (inclusive `segsCross`); closing a door or editing a wall on a token | Decision [FIXED, Q14]: token gets status `blocked` (player moves refused, GM moves allowed, clears on wall removal, door open, or GM clear). Escape fix for the on-wall case is required so GM can move it; mechanism PROPOSED, see 13 M2. Existing pin test replaced in M2. | M2 | -| H3 | O(rays x walls) vision | Decision: radius-bbox cull now, uniform spatial grid over walls when bench shows need; 5k-wall bench gate | M2 | +| H2 | Token on a wall can't leave (inclusive `segsCross`); closing a door or editing a wall on a token | Decision [FIXED, Q14]: token gets `blocked` (player moves refused, GM moves allowed, clears on wall removal, door open, or GM clear). Trigger = circle overlap [FIXED, owner]; escape + capsule rule [FIXED, accepted default]; both in 5.5. Pin tests replaced in M2. | M2 | +| H3 | O(rays x walls) vision | Decision: radius-bbox cull now; uniform spatial grid over walls only if the 5k-wall bench misses target (5.5) | M2 | | H4 | `cellsTouched` ~12x polygon | Decision: scanline rasterization, differential test vs ported version | M2 | | H5 | Shared-endpoint test gap | Decision: port with a test that fails if either arm is removed; new mutation (d) | M1 | | H6 | Single machine, loopback, power-save timings | Decision: keep as baseline only; real-network run required | M7 | | H7 | Boundary epsilon ambiguity | Decision: keep `RayEps`, 0.5 px tolerance in checkers; documented | M1 | | H8 | Tile leak: whole 256 px tile | Decision [FIXED, Q4]: `tile_size` = explored cell = 32 px; residual leak <= one cell, never revoked; no server masking; M4 gates (headless mobile-emulation + phone run); fallback 64 px per-scene config | M4 | | H9 | Invite = cookie = permanent bearer, no expiry, binds 0.0.0.0, needs HTTPS | Decision: session != invite, revoke/regenerate, log redaction, bind 127.0.0.1, HTTPS via nginx. Sessions never expire; one invite reusable across devices (Q10 FIXED); invite secrets plaintext (Q11 FIXED) | M3 | -| H10 | Move collision: centre path + dest circle, not swept circle | Decision: add swept-circle check; add step cap (T8) | M2 | +| H10 | Move collision: centre path + dest circle, not swept circle | Decision: capsule (swept-circle) check + escape rule, 5.5; step cap = effective vision radius, 5.5 (T8) | M2 | | H11 | Leak test explored/tile checks self-consistent | Decision: add independent explored oracle | M2 | | H12 | Full vision polygon (~3 KB) per player move | Decision [FIXED, Q16]: full polygon, integer px, only on change; delta/binary post-v1 | M3 | | H13 | Explored sent whole + one SQLite row per cell | Decision: chunked bitmaps in DB; RLE on connect | M3 | @@ -514,7 +543,7 @@ Source: `prototype-server-vision/HANDOFF.md` (and README/NOTES worries). | H23 | Tiles don't update on door change | Decision: by design (static art); doors never part of art | -- | | H24 | Prototype `gmOnly` unused (my finding, not in HANDOFF) | Decision: enforce + fault class | M3 | | H25 | Player-visible `gseq` side channel (my finding) | Decision: per-connection counter | M3 | -| H26 | Move-validation wall-probing oracle (my finding) | Decision: step cap + rate limit + uniform nack + test | M2/M3 | +| H26 | Move-validation wall-probing oracle (my finding) | Decision: step cap + rate limit + uniform nack + test (in-process M2, over WS M3; 5.5) | M2/M3 | --- @@ -525,10 +554,9 @@ Each is small, ends with a green gate, and no milestone depends on browser UI be - **M1 - Port geometry + tests.** - Scope: new repo layout (`server/`, `tools/`, `tests/`), devbox config, `geometry.nim` + `tgeometry.nim`, mutation script, add mutation (d) and the shared-endpoint arm test. - Accept: `nimble test` green: 33 test blocks / 98 checks ported, none dropped (plus new tests on top); mutations a-d each fail >= 1 test, control passes; repo builds with devbox only. -- **M2 - Vision engine v2.** - - Scope: scanline `cellsTouched`, differential + independent explored oracle tests, spatial grid for walls, swept-circle move check, step cap (= token vision radius, Q18), bench harness incl. 5k-wall scene, `blocked` token status (Q14) and its tests. - - Token-on-wall escape [requirement FIXED by Q14; mechanism PROPOSED, 5.4 / H2]: in `moveBlocked`, ignore the t=0 hit of a wall the token stands on when the segment does not cross that wall at t>eps and the destination is >= r from it. Moves through the wall stay blocked; moves along it stay blocked (collinear overlap is not an escape). Replace the KNOWN LIMITATION test with positive assertions. Replace the Q14 pin test ("door closed on a token") with tests of the `blocked` policy. - - Accept: results equal old implementation on the corpus; polygon+cells bench <= prototype (0.451 ms) on the prototype scene and polygon < 1 ms on the 5k-wall scene [targets PROPOSED]; probing test passes; token-on-wall escape positive tests pass; `blocked`-status tests pass (player move refused, GM move allowed, status cleared on wall removal / door open / GM clear). +- **M2 - Vision engine v2 and move rules** (decisions in 5.5, recorded 2026-11-08). + - Scope: scanline `cellsTouched`, differential + independent explored oracle tests, radius-bbox wall cull (spatial grid only if the 5k bench misses), capsule/swept move check and token-on-wall escape (5.5), step cap = effective vision radius (5.5), `blocked` flag with circle-overlap trigger (5.5), GM moves ignore walls and step cap, bench harness incl. 5k-wall scene, pure in-process move-rules module with unit tests. The WS/hostile-client harness is M3, not M2. + - Accept: `visibilityPolygon` and `cellsTouched` equal the old implementation on the corpus (5.5); `moveBlocked` excluded (its results change on purpose); polygon+cells bench <= prototype (0.451 ms) on the prototype scene and polygon < 1 ms on the 5k-wall scene [targets PROPOSED]; in-process probing test passes; escape and capsule positive and negative unit tests pass; `blocked` tests pass (overlap trigger, player move refused, GM move allowed, cleared on wall removal / door open / GM clear); over-cap move gives the same nack as a blocked move; thresholds documented in the module header; oracle tolerance 0.5 px. The KNOWN LIMITATION test and the Q14 pin test are replaced with positive assertions and `blocked`-policy tests. - **M3 - Server core.** - Scope: entities with bucketed props, players, invites/sessions, scenes, chunked explored persistence, typed per-recipient views and single egress, per-connection counters, proto versioning, wall/entity CRUD intents, Origin check, plaintext invite secrets and non-expiring sessions (Q10, Q11), SQLite schema + migrations. - Accept: ported leak test (A and B) + fault test with the extended fault classes: all caught with exact class sets, clean build passes; restart test passes incl. CRUD; auth tests pass; no secrets in logs. @@ -577,3 +605,5 @@ Each is small, ends with a green gate, and no milestone depends on browser UI be 24. Q24 - Repo conventions: should this design live in `docs/DESIGN.md` plus ADRs under `docs/adr/` and a `GLOSSARY.md` (AGENTS.md references both, neither exists yet)? Should prototypes remain in-tree or move to an archive branch once ported? **RESOLVED [FIXED (owner decision), 2026-11-08]:** `GLOSSARY.md` and `docs/adr/` per AGENTS.md; prototypes stay in-tree until the M4 client port, then archived. Owner also decided 2026-11-08 [FIXED (owner decision)]: restore drill belongs in M6 (sections 11.2, 13). + +Owner also decided 2026-11-08 (M2): move rules, `blocked` trigger and GM move bypass are recorded in 5.5; M2 scope and accept criteria in 13.