diff --git a/docs/DESIGN.md b/docs/DESIGN.md index 9d5f6be..c61edf8 100644 --- a/docs/DESIGN.md +++ b/docs/DESIGN.md @@ -1,6 +1,6 @@ # FFF_vtt design -Status: draft v0.17, 2026-11-15 (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; v0.6 records #14 (characters and player data) in 3.1, 3.4, 4.1, 4.4, 6.1, 8, 9, 10.3, 13, 14; v0.7 records #6 (players and invites) in 3.1, 3.2, 3.4, 4.4, 6.1, 8, 12, 13, 14; v0.8 records #7 (map tiles) in 3.3, 3.4, 11.1, 13, 14; v0.9 records #9 (test tools) in 2, 10.4, 13, 14; v0.10 records #12 (what M3 done means) in 13, 14; v0.11 records #15 (M3 limits) in 4.3, 6.4, 10.1, 13, 14; v0.12 records #11 (M3 message list) in 3.1, 3.2, 3.4, 4.2, 4.3, 5.5, 5.6, 6, 7.5, 13, 14; v0.13 records the owner review of #11 flags in 1, 3.1, 5.5, 6.1, 8, 14; v0.14 records #17 (getting in: keys, sessions, the auth slice) in 3.2, 4.4, 6.5, 6.6, 8, 11.1, 13, 14; v0.15 records #18 (talking safely: the protocol shell and the `closing` close-reason message) in 3.2, 4.3, 6, 6.1, 6.2, 6.4, 6.5, 10.3, 13, 14; v0.16 records #19 (walls and doors: the scene/wall schema, the wall payload rules and the slice-4 rollout) in 4.4, 6.1, 8, 13, 14; v0.17 records #20 (tokens and sight: the `entity` step, the typed views and the single egress, vision and explored, and the slice-5 rollout) in 4.4, 6.1, 6.3, 8, 10.3, 13, 14. All of Q1-Q24 are RESOLVED or DEFERRED; none OPEN). Audience: the owner and coding agents. +Status: draft v0.18, 2026-11-15 (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; v0.6 records #14 (characters and player data) in 3.1, 3.4, 4.1, 4.4, 6.1, 8, 9, 10.3, 13, 14; v0.7 records #6 (players and invites) in 3.1, 3.2, 3.4, 4.4, 6.1, 8, 12, 13, 14; v0.8 records #7 (map tiles) in 3.3, 3.4, 11.1, 13, 14; v0.9 records #9 (test tools) in 2, 10.4, 13, 14; v0.10 records #12 (what M3 done means) in 13, 14; v0.11 records #15 (M3 limits) in 4.3, 6.4, 10.1, 13, 14; v0.12 records #11 (M3 message list) in 3.1, 3.2, 3.4, 4.2, 4.3, 5.5, 5.6, 6, 7.5, 13, 14; v0.13 records the owner review of #11 flags in 1, 3.1, 5.5, 6.1, 8, 14; v0.14 records #17 (getting in: keys, sessions, the auth slice) in 3.2, 4.4, 6.5, 6.6, 8, 11.1, 13, 14; v0.15 records #18 (talking safely: the protocol shell and the `closing` close-reason message) in 3.2, 4.3, 6, 6.1, 6.2, 6.4, 6.5, 10.3, 13, 14; v0.16 records #19 (walls and doors: the scene/wall schema, the wall payload rules and the slice-4 rollout) in 4.4, 6.1, 8, 13, 14; v0.17 records #20 (tokens and sight: the `entity` step, the typed views and the single egress, vision and explored, and the slice-5 rollout) in 4.4, 6.1, 6.3, 8, 10.3, 13, 14; v0.18 records #23 (characters and names: the `character`/`name_reveal`/`encountered` step, the name rule, the players' names and the `roster` frame, and the four name/character fault classes) in 4.1, 4.4, 6.1, 6.3, 6.4, 6.5, 8, 10.3, 13, 14. 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. @@ -177,7 +177,7 @@ Notes: ### 4.1 State model Single process, in-memory authoritative state, SQLite as write-through persistence (loaded at start, never queried at runtime for reads). -- **World**: scenes; per scene: dimensions, tile config, grid, walls (per-scene stable id, never reused; see 8), entities (tokens). Characters, name reveals and encountered lists (8) are world state too. +- **World**: scenes; per scene: dimensions, tile config, grid, walls (per-scene stable id, never reused; see 8), entities (tokens). Characters, name reveals and encountered lists (8) are world state too: `characters: seq[CharacterRec]`, `reveals: (player, subject) -> one row each` and `encountered: player -> token -> snapshot`, all loaded at startup (slice 8 / #23, `server/characters.nim`). - **Players**: id, name, role (`gm`|`player`), colour; a player is a real person, not a character. Controlled tokens derive from `entity.owner` (token controller); owned characters from `character.owner`. - **Per-player runtime** (`Role` in prototype, renamed `PlayerState`): current vision polygons (one per owned entity with `vision` enabled), `ver` counter bumped on change, explored set, `fresh` cells added by the current mutation. - **Per-connection runtime**: `known` table (entity id -> last sent view), last-sent vision `ver`, per-connection counter, player id, role. @@ -262,6 +262,12 @@ explored_chunk(player_id, scene_id, cx, cy, bits BLOB, PRIMARY KEY(player_id, sc - Step 5 (M3 slice 6, `explored`) [FIXED (owner-delegated, 2026-11-15, #21)]: creates `explored_chunk(player_id INTEGER NOT NULL REFERENCES player(id) ON DELETE CASCADE, scene_id INTEGER NOT NULL REFERENCES scene(id) ON DELETE CASCADE, cx INTEGER NOT NULL, cy INTEGER NOT NULL, bits BLOB NOT NULL CHECK (length(bits) = 512), PRIMARY KEY (player_id, scene_id, cx, cy))`. `(cx, cy)` are **chunk** coordinates (`cell div 64`), not cell coordinates; `bits` is a 512-byte bitmap of 64x64 cells, row-major inside the chunk, least-significant bit first (cell `(cx, cy)` is bit `(cy mod 64) * 64 + (cx mod 64)`, byte `bit div 8`, mask `1 shl (bit mod 8)`). Cells outside the scene stay 0, so a map whose cell count is not a multiple of 64 needs no special case; the v1 scene is 128x128 cells = 2x2 chunks, a 16384 px map 8x8. Both FKs cascade, so `player.remove` and a scene delete take the explored rows with them. The layout is pinned by `tests/texplored.nim` (exact byte/bit positions) and re-read independently by `tools/persistence.test.mjs`, so a refactor cannot silently swap axes or bit order. - Step 6 (M3 slice 7, `token details`) [FIXED (owner-delegated, 2026-11-15, #22)]: adds `entity.props_public`, `props_owner`, `props_gm` (`TEXT NOT NULL DEFAULT '{}'`: one JSON object per visibility bucket) and creates `entity_status(entity_id TEXT REFERENCES entity(id) ON DELETE CASCADE, status TEXT CHECK (status IN ('stuck','squeezed')), source TEXT CHECK (source IN ('walls','GM')), PRIMARY KEY (entity_id, status, source))` - the `(status, source)` set of 5.5. `radius` was already a column from step 4; step 6 is what makes the buckets and the statuses persistent. A token's status rows are rewritten with its row (one transaction), so a status change and the `token` frame that reports it can never disagree after a crash; a wall-derived status change (no row write) rewrites them in the mutation's `NORMAL` transaction. Both FKs cascade, so removing a token removes its entries. - Step 5 write policy [FIXED (owner-delegated), #21]: a mutation persists **only the chunks its refresh dirtied**, and each of those is encoded from the **whole** explored set (a bitmap is a value, not a delta; writing just the new cells would erase the rest). Durability is `NORMAL` (Q12): explored is derived and monotone, unlike GM-authored content. A `token.move` writes the position and its chunks in **one** transaction (both NORMAL); a GM authoring write (`wall.*`, `door.set`, `token.create`/`update`/`remove`) keeps its own `FULL` row transaction and writes the chunks in a second `NORMAL` transaction, both inside the global lock and before the ack, so no ack precedes the cells it reports and no lock hold grows beyond one extra 512 B upsert. Those two commits are not atomic with each other; a crash between them loses explored cells the client was never told about, and the next refresh re-adds any the token can still see (explored never un-explores). +- Step 7 (M3 slice 8, `characters`) [FIXED (owner-delegated, 2026-11-15, #23)]: creates `character(id TEXT PK, owner_player_id INTEGER NOT NULL REFERENCES player(id), descriptive_name, actual_name, reveal_all INTEGER, props_public/owner/gm TEXT '{}', created_at)`, `name_reveal(player_id FK ON DELETE CASCADE, subject_id TEXT, created_at, PRIMARY KEY (player_id, subject_id))` and `encountered(player_id FK ON DELETE CASCADE, entity_id TEXT, character_id TEXT NULL, descriptive_name TEXT NOT NULL, actual_name TEXT NULL, created_at TEXT, PRIMARY KEY (player_id, entity_id))` plus an index on `characters(owner_player_id)` and `encountered(character_id)`; and adds `entity.character_id TEXT REFERENCES character(id)` and `entity.reveal_all INTEGER NOT NULL DEFAULT 0`. Decisions the sketch in 8 left open, all recorded here: + - **One id namespace.** A character id comes from the same 12-character alphabet and the same collision check as a token id (`tokens.freshId` with *both* lists), so `name_reveal.subject_id` can hold either without an ambiguity column. + - **`character.owner_player_id` never dangles.** It is `NOT NULL` with no cascade; `player.remove` calls `characters.transferToGm` before the player DELETE, inside one transaction (3.2). A raw DELETE would raise instead of orphaning a record. `name_reveal` and `encountered` do cascade on the player, because 6.1 deletes that player's reveals and encountered list with them. + - **`encountered` has no FK to `entity` or `character`.** Entries survive token removal, character removal and a `gm_only` flip (8), and only `encountered.remove` deletes one. `character_id` is stored so a rename and a `reveal_all` can follow the snapshots of everyone who met the character; `actual_name NULL` means "this player was never told it" (the writer stores `''`, db_connector cannot bind NULL). + - **`entity.character_id` is nullable and written as a SQL literal**, because db_connector quotes every bound argument as text and cannot send NULL; the value is always an id from the checked alphabet (`tokens.sqlLitId` raises otherwise). The FK is what makes a dangling link impossible, and `character.remove` pre-checks `in-use` so the FK never fires. + - **`entity.descriptive_name`/`actual_name` stay `NOT NULL`**: a token linked to a character stores `''` in both and its names come from the character record (8). Validation refuses a linked token that carries names and a plain token that lacks them, in both directions (6.1). - Startup: load everything into memory, recompute vision for all players (prototype does, in one transaction) so `vision` is never stale vs walls. Slice 5 loads the scene and its tokens; a player's sight state (`PlayerVision`) is created on that player's first connection and recomputed from the current walls, so nothing is stale after a restart. Slice 6 (#21) restores every stored `explored_chunk` row into that player's set before the first connection (`explored.restore`), so a reloaded grid is the grid the player had; polygons are never stored (they are recomputed, 8). - Shutdown: install a SIGTERM handler [prototype has only SIGINT, `HANDOFF.md`]: stop accepting, close sockets, final `wal_checkpoint(TRUNCATE)`, exit. Durability does not depend on it (WAL commit before ack). @@ -415,6 +421,20 @@ Validation for `wall.*`: `a != b`, both in bounds, `kind` in `wall|door`, `flags - `wall.add` assigns the id from the scene's `next_wall_id`, which is monotonic and never reused (#3, 8; removal does not touch it, and a restart reloads it from the DB). - Every write is one transaction with `synchronous=FULL` around it (Q12: GM authoring is the data that is expensive to lose) and `NORMAL` again afterwards; the in-memory scene is updated only after COMMIT, so a failed write leaves memory and DB identical. +**Character and name payload rules [FIXED (owner-delegated), 2026-11-15, #23]** (6.1 was silent on these; slice 8 builds them, module `server/characters.nim`): +- `character.create` takes `descriptive_name`, `actual_name` (the 6.5 text rule, 1..64 code points), an optional `owner` (a player id, default the GM's own) and optional `props`; a missing name, an unknown prop bucket or a mistyped field is `invalid`, an owner player that does not exist is `not-found`. +- `character.update` patches `descriptive_name`/`actual_name` only, at least one of them; `props` is an unknown field there (6.2) and so cannot smuggle a bucket past `prop.*`. +- `character.remove` answers `in-use` while any token links the character (6.5). `character.reassign` takes an existing player id and **never** touches a token's controller (3.1, 8); it also keeps every reveal (8: reveals are not revoked by an owner change). +- `name.reveal` / `name.reveal_all` carry `subject:"character"|"token"` and the subject id; a token that has a character is `invalid` (reveal through the character, 6.1), an unknown subject or player is `not-found`. A reveal writes one `(player, subject)` row; `reveal_all` writes the subject's `reveal_all` flag instead, so it covers players who join later and is idempotent. There is no un-reveal (8). +- `encountered.remove` takes `player` and a token id; a missing player and a missing entry are both `not-found`. +- **The name rule lives once** (`characters.knowsActual` + `visibleName`): a player is told a subject's actual name when the subject is a character they own, when `reveal_all` is set, or when the GM revealed it to them. The token frame, the character frame and every `encountered.name` call it; nothing else re-derives it. +- **`token` frames** gain `character_id` (string for a joined token, `null` for a plain one) **to the GM only**, plus `character_id` for a player who *owns* that character (6.1 leak note 2), and `cprops:{public:{…}}` — the character's `public` bucket for a player who sees a token of a character they do not own, `{}` for a plain token and for the owner, always present so its presence marks nothing (6.1 leak note 3). The GM frame of a linked token carries no `descriptive_name`/`actual_name`/`reveal_all`/`revealed`: those live on the character record. A plain token keeps all four. +- **A token's wire `name`** is `visibleName` of its subject: the character's names when linked, its own when plain. It is no longer always the descriptive name (that was slice 5's placeholder, 6.1 "Names"). +- **`encountered`** is per player and is recorded when a token enters that player's view (main.recordEncounters, before the ack, NORMAL durability like explored): one row per `(player, token)` holding the names that player knows *at that moment*, `grey` = the token is not in that player's view now (moved, removed, or `gm_only`) and never deletes it. `character.update` and a plain-token rename follow the snapshots; `name.reveal`/`reveal_all` fill in the actual name. On a diff the message carries only the entries that changed plus a `del` list (the only way an entry disappears is `encountered.remove`); on connect/resync it is `full:true`. +- **`roster`** is sent on connect (first, 6.3), after `player.setname`/`player.rename`, and after `key.create`/`key.replace`/`player.remove`: the full list every time, `connected` = that player has a live connection. Players receive named players only (6.1 leak note 4); the GM receives every player with `name:null` for an unused key. +- **`player.setname`** is a normalise-then-store intent (trim, then 6.5): `invalid` for a name that is empty or has a control character or exceeds 32 code points, `name-taken` regardless of case ("GM" included: it is an ordinary name in the `player` table), `not-allowed` for the GM, for a player that is already named, or for an unknown player. On success every connection of that player gets `hello` again with `me.name`, then the full resync, and everyone gets `roster`. +- **`player.rename`** (G) takes `id` + `name` and answers `invalid`, `not-found`, `name-taken`; the whole table is in 6.1. **`key.show`** (G) answers `{key}` with the stored plaintext secret (Q11) and refuses the GM's own key with `not-allowed` (CLI only, 3.2). + **Token payload rules [FIXED (owner-delegated), #20 and #22]** (6.1 was silent on these; slices 5 and 7 build them): - `token.create` requires `kind`, `pos`, `descriptive_name` and `actual_name` for a plain token, and accepts `radius` (px > 0; null or absent = the scene default) and `props` (the three buckets, validated below) from slice 7 on. `character_id` is a *known* field no slice can honour yet: it answers `invalid` (silently dropping a GM's field would lose data), and `token.update` does the same for it. The character link lands in slice 8. - A token's effective `radius` is its own `radius` when set, else the scene's `token_radius_default` (5.6). Both the wire `radius` and the move rules use the effective value, so a resize changes the escape/capsule/push geometry immediately (`worldmap.ruleToken`). @@ -502,13 +522,13 @@ Leak notes (R5 review, #11): (1) `kind` is GM-only because a value like `npc` wo - Breaking change -> bump `proto`, document in `docs/` changelog. ### 6.3 Reconnect and resync -- Reconnect = full resync. After `hello` the server sends, in this order [PROPOSED]: `roster`; GM: `walls`, `character` for all, `encountered` per player (full), then `token` for all; player: `character` for owned, `encountered` (full), `vision`, `explored` (full), then `token` for all visible and controlled. Slice 4 sends the `walls` part: one frame to every GM connection immediately after `hello` (players never get one). Slice 5 sends the token half of the sequence: the GM's `token` for every token, and for a named player `vision`, `explored` (full) then `token` for every token it may see or control. `roster`, `character` and `encountered` land with slices 6-8. An unnamed player gets only `hello` until `player.setname` succeeds, which triggers the same sequence on that connection. The client reducer resets everything on `hello` (reconnect-reset bug fixed in prototype, test in `client/src/state.test.ts`, 4/4 pass) [MEASURED]. Clients must tolerate any order after `hello`. +- Reconnect = full resync. After `hello` the server sends, in this order: `roster`; GM: `walls`, `character` for all, `encountered` per player (full), then `token` for all; player: `character` for owned, `encountered` (full), `vision`, `explored` (full), then `token` for all visible and controlled. Slice 4 sends the `walls` part: one frame to every GM connection immediately after `hello` (players never get one). Slice 5 sends the token half of the sequence: the GM's `token` for every token, and for a named player `vision`, `explored` (full) then `token` for every token it may see or control. Slice 6 built the explored restore, and slice 8 (#23) completes the sequence: `roster`, `character` and `encountered` are sent in the order above, and a sighting is recorded before the list is built, so a token that walked into an offline player's sight is in their `encountered` list on the next connect. An unnamed player gets only `hello` until `player.setname` succeeds, which triggers the same sequence on that connection. The client reducer resets everything on `hello` (reconnect-reset bug fixed in prototype, test in `client/src/state.test.ts`, 4/4 pass) [MEASURED]. Clients must tolerate any order after `hello`. - No gap detection and no `resume(since)`: WS over TCP is ordered and lossless while connected, and a reconnect restarts from a full snapshot. Full resync on every reconnect [FIXED, Q15]. Revisit if a measured snapshot exceeds ~100 KB. - Client reconnect: exponential backoff with jitter, cap ~10 s (prototype: fixed 2 s). Pending `reqId`s are dropped with the old connection (client-side, M4); a `hello` on a live connection (`scene.set`, first name) does **not** drop them: their acks still arrive. Assets (tiles) are kept across reconnect because explored only grows [MEASURED prototype behaviour]. - Same player on two connections: both synced; each has its own `known` table. Multiple devices per player allowed (Q10, FIXED), up to 4 (4.3). ### 6.4 Deltas and size -- Tokens: `token` only when the recipient's view of it changed; `token_gone` on leaving view; per-connection `known` table gives correct enter/leave [MEASURED, leak test (c)]. +- Tokens: `token` only when the recipient's view of it changed; `token_gone` on leaving view; per-connection `known` table gives correct enter/leave [MEASURED, leak test (c)]. The stored diff base is the frame **before** the per-connection `n` is stamped: `protocol.withN` deep-copies, so stamping cannot make the next comparison see a different frame and re-send unchanged state (this was a live bug until slice 8; the leak checker now sees a genuinely sparse stream). - Bytes [MEASURED, `results/concurrency-final1-server.log`]: monster move 145 B to a seeing player, 244 B to GM; player move: mover 3359-3653 B (worst 4.9 KB, dominated by the full `vision` polygon + `explored` diff), GM 145 B; door toggle 45 B (prototype `door` message; the M3 `wall` upsert is a little larger). - v1 decisions [FIXED, Q16]: full vision polygon, integer px (halves the text size [INFERRED]), owner only, sent only on change; deltas/binary post-v1. Explored on connect as run-length rows, later diffs as cell lists [PROPOSED]. - Move rate [FIXED (owner-delegated, 2026-11-14, #15)]: client sends at most ~20 Hz while dragging (prototype 50 ms) plus a final position. Server: token bucket per connection, 30 intents/s sustained, burst 100, same for GM and players. Excess intents are refused with `ack {ok:false, code:"rate-limited"}`; no rollback: each intent is atomic (accepted ones stay, rejected ones are never applied); the connection stays open. Reconciling refused optimistic edits is client behaviour (M4). @@ -543,7 +563,7 @@ Leak notes (R5 review, #11): (1) `kind` is GM-only because a value like `npc` wo | `in-use` | `character.remove` while a token links the character | | `no-rules` | `act.do` (reserved, 9) | -Player name text: trimmed, NFC, 1 to 32 code points, no control characters. Character and plain-token names: 1 to 64 code points, same rules. All are rendered with `textContent` (T13). +Player name text: trimmed, NFC, 1 to 32 code points, no control characters. Deviation [FIXED (owner-delegated), #23]: Nim 2.2.12's stdlib has no Unicode normalisation (it lives in a package the pinned dependency set does not include) and adding one is out of slice scope, so a player name is trimmed and compared case-insensitively but stored as typed; two visually identical names written with precomposed vs combining accents would be different names. Nothing else changes. Character and plain-token names: 1 to 64 code points, same rules. All are rendered with `textContent` (T13). **`error` frame (no `reqId`).** Codes `malformed`, `rate-limited` only; connection stays open unless the flood rule fires. @@ -635,8 +655,8 @@ All ids are server-assigned. **Walls [FIXED, owner decision 2026-11-10, #3]**: p - The server never interprets props in v1 except via a registered property schema (type, bucket, writable-by) used for validation and for FFF later. - **Character [FIXED, owner decision 2026-11-10, #14]**: own record, separate from tokens. Fields (indicative): `id` (random, same format as token ids), `owner` (exactly one player id; the GM is a player, so GM ownership = the GM's player id; the GM reassigns), `descriptive_name`, `actual_name` (names rule below), `reveal_all`, `props` (three buckets, identity/base values). A character has any number of tokens in any scene. A new token for a character starts controlled by the character's owner; the GM may change it. Changing a character's owner never changes its tokens' controllers (GM adjusts by hand). Rejected: token controller derived from character; auto-follow on reassignment; all data on the token (duplicated stats); all data on the character. - **Character props vs token props [FIXED, #14]**: the character holds who the figure is (identity, base values); the token holds what is happening to that figure (damage, conditions, scene effects). Plain tokens (monsters, items) keep their own data. Both use the three buckets: `owner` for a character = character owner + GM; for a token = token controller + GM. The server stores both and never interprets them; FFF decides the split (9). A recipient's view of a token is built from its own props and its character's props, each under its own bucket rule [PROPOSED]. -- **Names [FIXED, #14]**: every character and every plain token has a `descriptive_name` (e.g. "a grumpy man") and an `actual_name` (e.g. "Lord Vex"). Players see the descriptive name until the GM reveals the actual name to that player; the GM can also reveal to all at once (`reveal_all`). The owner of a character always sees its actual name. A character's tokens use the character's names, so one reveal covers all of them. Applies to player characters too (introductions). A reveal cannot be undone in v1 (no un-reveal intent). Reveals are not revoked when ownership changes [PROPOSED]. -- **Encountered list [FIXED, #14]**: per player, every token that the player's controlled tokens have ever seen, shown under the name that player knows. Out of sight: greyed ("met before, whereabouts unknown"). `gm_only` tokens never enter it; a token that becomes `gm_only` after a player met it keeps its entry (greyed). Entries are never removed automatically (not on token removal, scene change or a `gm_only` flip); only the GM removes an entry for a player. Server tracks and persists it. No browsable list of all characters for players. Not the player roster (Q9 lists players only). +- **Names [FIXED, #14]**: every character and every plain token has a `descriptive_name` (e.g. "a grumpy man") and an `actual_name` (e.g. "Lord Vex"). Players see the descriptive name until the GM reveals the actual name to that player; the GM can also reveal to all at once (`reveal_all`). The owner of a character always sees its actual name. A character's tokens use the character's names, so one reveal covers all of them. Applies to player characters too (introductions). A reveal cannot be undone in v1 (no un-reveal intent). Reveals are not revoked when ownership changes [PROPOSED]. Built in slice 8 (#23): a reveal is one `(player, subject)` row, and the subject is a character id **or a plain token id** — the two share one id namespace (4.4), so no column distinguishes them. `reveal_all` is a flag on the subject, not a fan-out of rows, so a player who joins later is covered. The one rule that turns a reveal, an owner or a flag into the name a recipient sees is `characters.knowsActual`/`visibleName`; no frame builder re-derives it. +- **Encountered list [FIXED, #14]**: per player, every token that the player's controlled tokens have ever seen, shown under the name that player knows. Out of sight: greyed ("met before, whereabouts unknown"). `gm_only` tokens never enter it; a token that becomes `gm_only` after a player met it keeps its entry (greyed). Entries are never removed automatically (not on token removal, scene change or a `gm_only` flip); only the GM removes an entry for a player. Server tracks and persists it. Built in slice 8 (#23): each entry is a *snapshot* of the names the player knew when it was first sighted (plus the character link, so a rename and a later reveal can follow it), `grey` is computed at frame time, and an entry is recorded on every mutation that could show the token, before the ack. No browsable list of all characters for players. Not the player roster (Q9 lists players only). - **Player**: `id, name (NULL until first sign-in; unique among players), role (gm|player), colour`. Exactly one GM. A player is a real person who signs in with a player key; not a character. A player may own several characters. Max 6 players; unused keys count toward the cap. GM can rename. Remove: see 3.2 [FIXED, #6]. - **Player key**: `player_id, secret (plaintext, re-showable by GM, Q11 FIXED), created`; one current key per player; replace overwrites. Format: 20 symbols in 5 groups of 4 with dashes, alphabet without look-alikes, CSPRNG (~99 bits) [FIXED, #6; implementation detail #17 in 3.2]. The GM's key is the GM player's key (3.2). Not a session [FIXED, #6]. - **Session**: `id, player_id, token_hash (SHA-256 hex of a 32-byte CSPRNG token; the token itself is never stored), created, last_seen`; never expires (Q10 FIXED). @@ -685,8 +705,8 @@ Principles carried from the prototype: the checker must be independent of the co - Leak checker oracle initially only checked "nothing extra", not "everything visible shows"; completeness check is kept (assert (b)). ### 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), `KEY_IN_LOG`, `CHAR_OWNER_PROP`, `ACTUAL_NAME`, `CHAR_LIST`, `CONTROLLER_CHANGE` (#14). Each with an injected fault and exact-class assertion, same as existing. **Slice 5 built** the classes that exist at this slice: `HIDDEN_TOKEN`, `GMONLY_TOKEN`, `WALLDATA`, `WITHHELD`, `NO_REMOVE`, `OWN_VIEW`, `OTHER_PLAYER`, `EXPLORED` (`-d:leakfault` + `LEAK_FAULT=`, `tools/fault.test.mjs`, exact class set per fault, and the shipped binary asserted to contain no `LEAK_FAULT`). `OWNER_PROP`, `GM_PROP` and the new `STATUS_SOURCE` arrive with slice 7 (#22): the leak scenario writes props into all three buckets and sets a GM-sourced status on a token the subject can see, and `tools/leakcheck.nim` refuses the `gm` bucket, the `owner` bucket on a non-controller and any `source` on a player status entry. `ACTUAL_NAME`, `CHAR_LIST`, `CONTROLLER_CHANGE` and `CHAR_OWNER_PROP` stay with slice 8; `TILE` with slice 9; `GLOBAL_COUNTER` is already structurally impossible (per-connection `n`). -- **Characters and names (#14)**: tests for reveal per player and reveal to all; owner sees own actual name; character owner change leaves token controllers unchanged; encountered entries survive token removal and scene change and are removed only by the GM; `gm_only` tokens never enter an encountered list. Fault classes: `ACTUAL_NAME` = unrevealed actual name sent to a player; `CHAR_LIST` = another player's character or encountered entry sent; `CONTROLLER_CHANGE` = owner change altering controllers; `CHAR_OWNER_PROP` = character owner-bucket prop sent to a non-owner. +- **Fault classes** for new data: `GMONLY_TOKEN`, `OWNER_PROP`, `GM_PROP`, `GLOBAL_COUNTER` (gseq side channel), `WALL_DELTA` (wall.add reaches player), `KEY_IN_LOG`, `CHAR_OWNER_PROP`, `ACTUAL_NAME`, `CHAR_LIST`, `CONTROLLER_CHANGE` (#14). Each with an injected fault and exact-class assertion, same as existing. **Slice 5 built** the classes that exist at this slice: `HIDDEN_TOKEN`, `GMONLY_TOKEN`, `WALLDATA`, `WITHHELD`, `NO_REMOVE`, `OWN_VIEW`, `OTHER_PLAYER`, `EXPLORED` (`-d:leakfault` + `LEAK_FAULT=`, `tools/fault.test.mjs`, exact class set per fault, and the shipped binary asserted to contain no `LEAK_FAULT`). `OWNER_PROP`, `GM_PROP` and the new `STATUS_SOURCE` arrive with slice 7 (#22): the leak scenario writes props into all three buckets and sets a GM-sourced status on a token the subject can see, and `tools/leakcheck.nim` refuses the `gm` bucket, the `owner` bucket on a non-controller and any `source` on a player status entry. `ACTUAL_NAME`, `CHAR_LIST`, `CONTROLLER_CHANGE` and `CHAR_OWNER_PROP` **arrive with slice 8 (#23)**: the leak scenario creates a character, puts a token of it next to the subject, writes the character's three prop buckets, renames it, reveals it to one player and to all, reassigns it twice, reveals a plain token, flips a `gm_only` token that the subject had met, removes a token the subject had met and removes one encountered entry. `tools/leakcheck.nim` adds the four classes: an actual name a player may not see in a `token` or an `encountered` frame (`ACTUAL_NAME`); another player's `character` record, a `character_id` on somebody else's token, or an encountered entry the subject never saw (`CHAR_LIST`); a token controller that moved in a group whose intents asked for no controller change — the transcript logs every intent, so `token.create`/`token.update{controller}`/`player.remove` are the only allowed causes (`CONTROLLER_CHANGE`); a `cprops` object carrying anything but the character's `public` bucket (`CHAR_OWNER_PROP`). Two consequences worth recording: the `hidden` and `gmOnly` faults now also produce `NO_REMOVE`, because a leaked token whose frame never changes leaves the client holding it with no message to correct it, which is indistinguishable from a withheld `token_gone` at the client (both invariants really are broken, so both classes are asserted); and `TILE` stays with slice 9 while `GLOBAL_COUNTER` is already structurally impossible (per-connection `n`). +- **Characters and names (#14)**: tests for reveal per player and reveal to all; owner sees own actual name; character owner change leaves token controllers unchanged; encountered entries survive token removal and scene change and are removed only by the GM; `gm_only` tokens never enter an encountered list. Fault classes: `ACTUAL_NAME` = unrevealed actual name sent to a player; `CHAR_LIST` = another player's character or encountered entry sent; `CONTROLLER_CHANGE` = owner change altering controllers; `CHAR_OWNER_PROP` = character owner-bucket prop sent to a non-owner. **Built in slice 8** as the `tools/characters.test.mjs` group, which also carries the two checks 10.3 was missing: "a status source is not shown to a non-GM" (the controller included) and "an encountered entry survives a `gm_only` flip and a token removal" (greyed, never deleted). - **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**: key replace (old key invalid, sessions revoked, live connections closed), remove player (key invalid, characters and tokens pass to GM), one key reused on several devices (Q10 FIXED), Origin mismatch rejected, cookie flags present. - **Protocol tests** (#18, `tools/protocol.test.mjs`): proto missing/non-integer (HTTP 400) and mismatch (`closing` 4003, no `hello`); unknown intent type (`unknown-type`) with unknown fields ignored; exactly one `ack` per `reqId` (reqId 0 and 2^31-1 included); `hello` first with `n = 1` and a per-connection `n` thereafter; `error malformed` for unreadable frames; the malformed flood (nine tolerated, the tenth closes 1008); the intent bucket (burst then `rate-limited`, connection stays open, a refused intent applies nothing, `error rate-limited` for an unreadable frame on an empty bucket); the 64 KB inbound boundary (exactly 64 KB is a message, 64 KB + 1 drops the TCP connection with no close frame); unmasked and bad-opcode frames; the server Ping and the Pong answer to a client Ping; the connection cap (503 + `Retry-After: 5`); and every server-initiated close as `closing` then 1005. @@ -799,7 +819,7 @@ Each is small, ends with a green gate, and no milestone depends on browser UI be 3. **probing**: M2 in-process probing test (T8, H26) re-run over WS with a hostile client (10.3, 5.5). 4. **protocol**: proto mismatch refused, unknown type rejected, oversized frame rejected, malformed flood closed, rate limit hit, connection cap enforced (10.3, T10, 6.2, 6.5; codes and close codes in 6.5; limits and numbers in 4.3 (connections) and 6.4 (frame, intent rate) [FIXED, owner-delegated, #15]). 5. **auth**: key create; key replace (old sessions and live connections closed); remove player; one key on several devices; Origin mismatch rejected; cookie flags present (T7, H9, 3.2, 10.3). - 6. **characters and names**: as #14 (10.3). + 6. **characters and names**: as #14 (10.3). Built by slice 8 (#23): `tools/characters.test.mjs` (ten tests: `player.setname` + `roster`, `player.rename` + `key.show`, `character.create`, reveal per player and `reveal_all`, a plain token's own names and `cprops`, `reassign` leaving controllers alone, `update`/`remove` with `in-use`, the encountered list and `encountered.remove`, the status source, and a restart), plus the four new fault classes in group 1. 7. **restart**: identical state after restart, incl. CRUD (10.1). 8. **persistence**: explored chunks round trip; old DB migrates to new (H13, 4.4, 10.3; migrations are PROPOSED in 4.4). 9. **logs**: no secret in any log; the test greps the logs for every key and session value it used (T6, 11.3 PROPOSED). @@ -817,7 +837,7 @@ Each is small, ends with a green gate, and no milestone depends on browser UI be - Scope: real-network latency/throughput run, iOS/Safari check (if available), one real session with the owner's table, collect SLOW lines. - Accept: documented numbers; defects triaged to issues; go/no-go for v1. - **M3 build slices** [FIXED, owner decision 2026-11-14, #13]: vertical slices, each runnable end-to-end with its own test. Order and blocking: each slice blocked by the previous, except 9 (blocked by 5 only) and 10 (blocked by 1-9). Open technical details (DDL, property-schema registry format, config keys, redaction mechanism) are decided by the builder inside the slice that needs them and recorded here as FIXED (owner-delegated). - 1. Bare server (#16) 2. Getting in (#17) 3. Talking safely (#18) 4. Walls and doors (#19) 5. Tokens and sight (#20) 6. Explored persistence (#21) 7. Token details (#22) 8. Characters and names (#23) 9. Map tiles (#24) 10. Finish line (#25). + 1. Bare server (#16) 2. Getting in (#17) 3. Talking safely (#18) 4. Walls and doors (#19) 5. Tokens and sight (#20) 6. Explored persistence (#21) 7. Token details (#22) 8. Characters and names (#23, done) 9. Map tiles (#24) 10. Finish line (#25). - **Post-v1 candidates**: FFF seam implementation (section 9), drawings/pings/ruler, chat/dice (order decided at M7, Q8), light sources, browser upload UI (Q5), multi-scene (Q3), vision deltas/binary protocol (Q16). --- @@ -881,4 +901,6 @@ Owner also decided 2026-11-15 [FIXED (owner-delegated, 2026-11-15, #20)]: tokens Owner also decided 2026-11-15 [FIXED (owner-delegated, 2026-11-15, #22)]: token details (M3 slice 7). Schema is migration step 6 (`token details`): the three prop buckets on `entity` and `entity_status` (4.4). Intents: `token.resize`, `status.set`, `status.clear`, `prop.set`, `prop.unset`, all GM-only in v1 (6.1; owner-bucket writes by players come with FFF actions, 9, and are a permission change, not a redesign). The payload rules 6.1 left open are fixed in 6.1: the status set and its `source`, the three-bucket caps (64 keys, 1..64-char keys, 8 KB values, per bucket), the property-schema registry (empty at start with a permissive fallback, so v1 accepts any key in any bucket because 8 says the server never interprets props; a registered key is enforced) and the grow-push search. **Modules**: `server/props.nim` (buckets, caps, registry, parsing), `server/moverules.nim` (the status model replaces the M2 `blocked` bool: `stuckWalls`/`squeezedWalls` are the `walls` source, `locked` is the caller's "any entry" bit, per-token radius everywhere, `resizeToken` with the grow search, `placeToken` for GM placement/move), `server/text.nim` (the one copy of the 6.5 text rule, shared by names and prop keys), `server/tokens.nim` (statuses and props on the record and in the row), `server/worldmap.nim` (`ruleToken`/`ruleWall`/`applyOutcome`/`wallsStatuses`: the bridge between the record's entry set and the rules' two booleans), `server/views.nim` (typed per-recipient statuses and buckets). **One rule, one place**: every wall/door edit and every resize runs the pure rules on a snapshot taken *before* the write, then the write, then `applyRuleOutcome` (positions and `walls` statuses in one `NORMAL` transaction, memory after COMMIT); `token.create` computes the placement status before writing the row, so a new token is born with `stuck` if it lands on a wall. Status sources are owned by different layers on purpose: the rules never see `GM` entries, the record never derives `walls` entries. **Tests** (10.1, 10.3): `tests/tprops.nim` (caps, key/value rules, registry enforcement, set/unset, clone isolation), `tests/ttokens.nim` (radius, buckets, statuses round trip, the FK cascade), `tests/tmoverules.nim` (per-token radius, shrink/grow/squeeze, the no-crossing rule, the source independence), `tests/tviews.nim` (bucket and source filtering, one `token` frame per change), `tools/details.test.mjs` (the five intents' acks and codes, grow push and squeeze, stuck/clear, prop caps, who reads which bucket, restart equality), plus the leak scenario's prop/status groups and the `OWNER_PROP`, `GM_PROP`, `STATUS_SOURCE` faults. Mutations am-au pin the bucket filter, the per-bucket cap, the status set/clear, the shrink/grow rules and the push. See 4.4, 5.5, 5.6, 6.1, 8, 10.3. +Owner also decided 2026-11-15 [FIXED (owner-delegated, 2026-11-15, #23)]: characters and names (M3 slice 8). Schema is migration step 7 (`characters`, 4.4): `character`, `name_reveal`, `encountered`, plus `entity.character_id` and `entity.reveal_all`. The decisions 4.4 leaves open are recorded there and the wire rules in 6.1 ("Character and name payload rules"): one id namespace for tokens and characters, an owner that never dangles (`player.remove` transfers to the GM first), an encountered entry with no FK that outlives everything, a linked token that stores `''` names, and `character_id`/`cprops` on the token frame with the ownership rules of 6.1 leak notes 2-3. **Modules**: `server/characters.nim` (records, the name rule, the reveal set, the encountered snapshots, their rows), `server/views.nim` (the typed character and encountered views plus the token-frame additions), `server/tokens.nim` (`characterId`/`revealAll`, the linked-token validation and `sqlLitId`), `server/text.nim` (`normalizedPlayerName`, `validPlayerName`, `sameName`), `server/auth.nim` (`allPlayers`, `nameTaken`, `setName`, `renamePlayer`), `server/main.nim` (`recordEncounters` in every mutation path before the ack, the roster fan-out, `sendHello`/`resync` for `player.setname`). Also fixed here: `protocol.withN` deep-copies before stamping `n`, because the stored diff base was being mutated and every state frame was re-sent on every mutation. **Tests** (10.1, 10.3): `tests/tcharacters.nim` (the name rule, the reveal set, the encounter snapshot, validation, persistence incl. the GM transfer and the `in-use` count), `tests/tviews.nim` (character frames, the owner/non-owner split, `cprops`, `character_gone`, the encountered diff), `tools/characters.test.mjs` (the acceptance group of 13), the leak scenario's ten character/name/encountered groups and the `ACTUAL_NAME`, `CHAR_LIST`, `CONTROLLER_CHANGE`, `CHAR_OWNER_PROP` faults. Mutations av-b4 pin the name rule, the encountered snapshot, the linked-token validation, `in-use`, the GM transfer, the snapshot rename and the `cprops` bucket. See 3.1, 4.1, 4.4, 6.1, 6.3, 6.4, 6.5, 8, 10.3, 13. + Owner also decided 2026-11-15 [FIXED (owner-delegated, 2026-11-15, #21)]: explored persistence (M3 slice 6). Schema is migration step 5 (`explored`): `explored_chunk` keyed by `(player_id, scene_id, cx, cy)` with a 512-byte blob, both FKs cascading (4.4). Chunk format and size are fixed at 64x64 cells = 512 B, row-major LSB-first bits, `(cx, cy)` = chunk coordinates; the layout is pinned by tests and re-read independently by the Node harness. **Write timing**: a mutation writes only the chunks its refresh dirtied, each encoded from the whole explored set, with `NORMAL` durability; a move writes position and chunks in one transaction, a GM authoring write adds a second `NORMAL` chunk transaction under the same lock, both before the ack — the two commits are deliberately not atomic with each other, and the only loss they can cause after a crash is cells no client was acked about, which the next refresh re-adds. Measured: 0.015 ms avg / 0.035 ms p99 per chunk write, 0.7 ms avg / 1-2 ms p99 per move ack (4.3's budget is untouched). **Load**: `explored.restore` fills every player's set at startup from the chunk rows and logs `explored_loaded players= chunks=`; polygons stay recomputed (8). **Tests** (10.1, 10.3): `tests/texplored.nim` (format, whole-chunk encoding, upsert replacement, per-player keying, restore, cost) and `tools/persistence.test.mjs` (fresh-resync round trip, per-player isolation, SIGTERM and SIGKILL restart equality, wall-removal cells surviving after the wall returns, chunk rows decoded independently, move-ack timing, and a schema-4 fixture DB migrated by the real binary). Mutations ag-al pin the bit layout, the chunk coordinate, the restore, the per-player key, the upsert and the dirty-chunk dedupe. See 4.4, 8, 10.3.