RPG Mode — Design Document
Overview
Story-first platforms have one known complaint about games: "the dice aren't real, the AI just decides whether you
succeed" (AI Dungeon reviews, docs-internal/product/competitive-research-latitude-aidungeon-voyage.md:76). Voyage
sells the fix as its product: the engine decides, the narrator describes. Our Game Direction (docs-internal/vision/GAME_DIRECTION.md)
names the same gap from the inside — the check / resolution mechanic is MISSING (GAME_DIRECTION.md:121-122).
RPG mode closes it with five mechanics:
- Dice — real rolls on the server, animated in the story even though the outcome is fixed before the model writes.
- Skills — named checks with a rank on the character sheet, used by the reader or called by an AI game master.
- Inventory — items gained, lost, equipped and used, where using an item is an event with effects.
- Map travel — a layered map (world → region → place) the party moves across; code owns where they are, what it costs to get somewhere, and what they've discovered.
- Fixed-contract trackers — a small set of system-defined tracker kinds (HP, attributes, skills, currency,
conditions, XP, inventory, location, discovered places, the in-world clock) whose shape the code knows, so the UI can
draw a health bar, a sheet, a bag and a map instead of
hp: 14.
All five are one thing underneath: something happened in this turn that isn't prose. They ride the chat events model, not four bespoke features (owner, 2026-10-28: "we should do this as a whole").
Where it lives — a Hybrid package, played in the RPG console
Game Direction's second principle (owner, 2026-09-20): chat and games are two surfaces over the same primitives. The owner's framing (2026-10-28) sets what each surface sells:
- Chat is the freeform, text-based contract with the most customization. The text is the truth; the reader can shape and correct everything. A predefined building block — a specialized tracker kind, dice — is a plug-in to that freeform, which is why it's cheap there: it rides the freeform contract instead of replacing it.
- The RPG is a locked contract, thoroughly tested. Its value is that it is not purely freeform text: a sheet, a bag of items with icons, a dice tray and a layered map, backed by code that enforces the rules — a game's feel, not a chat with numbers in it. "Pre-defined trackers with fixed contracts" is what lets the UI draw those.
The package carries the contract; the reader plays it. An RPG game is a package with an RPG config. Its creator picks the dice system and the options and defines attributes, skills, items and the starting sheet. A reader starts the package and plays — rolling, using skills and items — but changes no rule. That answers Game Direction's fork #5 ("is a game a Package?") with yes, and fork #4 (rules ownership) with a split: dice systems are platform, the content they resolve is the package's.
It is always Hybrid. The AI game master is the beat leg, exactly as the Visual Novel's director is: a VN run is a
Hybrid conversation with a scene graph bound to it (docs-internal/visual-novel/VISUAL_NOVEL_PROTOTYPE.md:23-29). An
RPG story is a Hybrid conversation with an RPG config bound to it. Every design line below is judged by the VN's test:
is this Hybrid with a value pinned, or new machinery? Package start lets readers pick the pipeline since the
mode_locked pin was retired (hybrid-pipeline.md Package start, 2026-09-20); an RPG package is the one exception —
fn_create_conversation_from_package starts it as Hybrid whatever the reader's preference, because the config can't run
without the director. The exception keys on the package having an RPG config, not on the retired column.
It plays in its own console. A locked contract with visuals of its own needs a surface built around it, not
controls bolted onto a freeform one — so RPG mode gets the RPG console, the games surface, exactly as the Visual
Novel got visualNovelConsole:
- Built by extraction. The VN console already has the signed-in product shell (
SessionGate,SignInCard,ProductShell, the account menu), a story shelf and the deploy wiring. The RPG console is its second consumer, so that shell is lifted intoshared/first (refactor-first, rule of two) — not copied. - Reuses the story renderer. The transcript, reply rows and Story events slot come from
shared/src/chat/story/(what chat. renders with); the console adds the sheet, the bag and the dice tray around them. One transcript component, two surfaces. - Chat gets the primitives, not the game. See Chat first below: dice, plain checks, tracker kinds and AI-called checks are chat features a reader opts into; the sheet, the bag's Use, declared effects, the map and the package's rules are the console's.
- Start routes there. Start on an RPG package opens the new story in the RPG console.
Ready to elevate. The config is one validated document. At start the conversation copies the package's config
(web_conversations.rpg_config, with the dice system's key and version), so a creator editing the package never
changes a running story. Elevating to readers later is making selected fields of that copy reader-writable through the
same validator — no new shape, no migration of the config.
| Level | Who sets what | When |
|---|---|---|
| L1 | the package creator sets everything; readers set nothing | v1 |
| L2 | readers change chosen options on their copy (difficulty shown/hidden, re-roll policy) | later |
| L3 | creator-authored dice systems through the same validator | later |
Chat first — the primitives land in chat, the game stays in the console
The two surfaces are one set of building blocks under two contracts. In chat a block plugs into the freeform: it's optional, the reader configures it, and the text stays correctable around it. In the console the same block is locked into the package's tested contract and drawn as game UI. So every block that makes sense without a package's rules is built in chat first — real product, not a test harness — and the console takes the same code and locks it. That order also proves the riskiest machinery (staging, the composite guard, the seam resolution, delta ops) on real chats before the console exists.
| Building block | In chat (a plug-in to the freeform) | In the RPG console (locked, tested, drawn) |
|---|---|---|
| Dice | A dice control in chat.'s composer: free notation and quick dice, Roll now / Roll with my message, the cue and the line. Classic and Hybrid | The dice tray, with the sheet's skills and items in it |
| Checks | A bare check: a label, a tier and an optional modifier, read by the dice system the reader picks for the story (§1) | Skill and item checks with modifiers from the sheet, declared effects |
| AI-called checks | Hybrid only: "The AI may call for checks". The director picks an action and a tier from a code-built menu; the server rolls | The same, with the package's skills and usable items in the menu, and the package's mode preset |
| Tracker kinds | Resource, currency, conditions, XP, clock, inventory (a bag without Use) in the tracker form, with their renderers and delta ops. Readers can correct values, as with every chat tracker | The package's contract set, plus attributes and skills, seeded from the sheet, read-only |
| Place | The built-in Place tracker (LOCATION_TRACKER.md M1–M2) | Locked under the map's mapped prefix (§7) |
| Inventory | The uncatalogued bag kind: names and counts, correctable | The package's catalog: item icons, equip slots, Use with effects |
| Map travel | — | The console only: the layered map, pins, routes, the party marker |
Chat's settings for these live where every chat feature's do: Settings → Features (the user's default) and the story's own settings, off by default, so a reader who never turns them on sees chat exactly as today. They ship to every signed-in reader like any chat option — the staff-only gate is the console's, not the primitives'.
The pieces are built where both consumers reach them from the start: the dice control, the cue and the line in
shared/src/chat/events/, the dice engine and the check resolution in Core. The console's tray is the chat control
with the sheet added, not a second one.
The VN gains checks too. Luna wants exactly this ("Player asserts a theory, system adjudicates"). A VN transition
may carry a check (door.force needs Strength vs Hard). It is the same check primitive the director calls in RPG mode,
so it is built once.
Design Goals
- Code is god of what is. Every number — every die face, every total, every HP point — comes from server code. The story model never rolls, never sets a difficulty, never writes state. There is no "narrative dice" mode.
- The event is true before the cue plays. The Dream Shards cue rule, verbatim: a cue describes something that
already happened; skip every cue and the story is identical (
dreamShardsConsole/src/anim/cues.ts:1-25). - One event model. Rolls, checks and item use are event kinds in the research's approach B, not columns of their own.
- The snapshot stays the tracker truth. Contract trackers live in
tracker_jsonlike every tracker; branch, the summary timeline and corrections keep working; only the eval write and its failure path learn to apply event ops. - Pinned now, elevatable later. The creator's config is data in one validated shape, copied onto the story; a reader layer later writes the same shape. Nothing is hard-coded that a later level would have to dig out.
- A story that doesn't use these features is untouched. No events → byte-identical prompts, same number of eval calls. Classic gains only what a reader turns on — dice, bare checks, tracker kinds; never AI-called checks or the game.
- Chat first. A primitive that works without a package's rules ships in chat before the console, and the console reuses that code with the contract pinned.
Non-Goals
Deliberately out of scope:
- Classic RPG. An RPG package is Hybrid only (owner, 2026-10-28). Classic chats get the reader-called primitives (dice, bare checks, tracker kinds), never the game.
- Reader customization of an RPG package. No per-story rule changes on a package's RPG story in v1 (L2 later). The chat primitives are the reader's own and fully customizable; that's the chat surface, not the game.
- The game in chat. No sheet with attributes and skills, no declared effects, no item Use, no map, no mode presets in chat. or chat-v2. chat-v2 renders the event lines and the tracker kinds; the dice control and the AI-checks setting are chat.'s only.
- A combat engine — initiative, turn order, multiple combatants' HP, positioning, a grid. Its own spec, inside the RPG console.
- Model-decided outcomes. No mode lets the LLM pick a number or a success. "AI mode" means the AI calls the check and picks a difficulty tier; the server rolls. This is the pain point the whole feature exists to fix.
- Client-side randomness. The browser never rolls, not even for a preview. A refresh can't re-roll.
- Character creation (point-buy, class pickers). The sheet starts from the package's
sheet. - Automatic levelling. XP is a tracker; what a level grants is a later rule.
- Creator-authored dice systems (L3). v1 ships four system dice systems; authoring goes through the same validator
later (the VN graph precedent,
VN_SCENE_ENGINE.md:181-189). - Party / multiplayer, Discord, crafting, trading. Trackers are web-only; inventory.md's out-of-scope list holds.
The primitives
1. Dice systems and the package's RPG config
Two documents, split by owner (fork #4):
- A dice system is platform: how a check is rolled and read. v1 dice systems are JSON resources in the repo, loaded
and validated by a catalog (the
SceneGraphCatalogprecedent: a refused one is logged and never served; validation never throws). Creator-authored dice systems are L3, through the same validator. - The RPG config is the package's: which dice system, the mode and options, and the content it resolves —
attributes, skills, items, the tracker set and the starting sheet. Stored on the package (
packages.rpg_config, validated against its dice system on save), copied onto the conversation at start.
// dice system — platform
{
"key": "d20_fantasy", "version": 1, "label": "d20 Fantasy",
"check": {
"dice": "1d20",
"resolution": "dc", // dc | bands | roll_under | pool
"advantage": true, // adv/dis allowed
"crit": { "success": 20, "failure": 1 } // natural faces, null = off
},
"difficulty": { "easy": 10, "medium": 15, "hard": 20, "very_hard": 25 },
"modifier": "half_minus_5" // how an attribute value becomes a modifier
}
// RPG config — the package's (copied to web_conversations.rpg_config at start)
{
"v": 1,
"diceSystem": { "key": "d20_fantasy", "version": 1 },
"mode": "both", // deterministic | game_master | both
"options": { "advantage": true, "crits": true, "difficultyShown": true,
"secretRolls": false, "checksPerTurn": 1, "reroll": "once" }, // reroll: none | once
"attributes": [ { "key": "str", "label": "Strength" }, { "key": "dex", "label": "Dexterity" } ],
"skills": [
{ "key": "lockpicking", "label": "Lockpicking", "attribute": "dex",
"description": "Opening locks without the key.",
"effects": { "critical_failure": [ { "tracker": "hp", "op": "damage", "amount": "1d4" } ] } }
],
"items": [ /* inventory.md's item fields + "effects" */ ],
"trackers": [ // the contract tracker set, see §4
{ "key": "hp", "kind": "resource" },
{ "key": "attributes", "kind": "attributes" }, { "key": "skills", "kind": "skills" }
],
"sheet": { "hp": { "current": 12, "max": 12 }, "str": 12, "dex": 15, "lockpicking": 1 }
}
trackers is the story's whole tracker set. Every tracker an effect, a cost or the sheet names is listed there with
its kind (hp above: the Lockpicking effect and the sheet both name it). A config that names a tracker it doesn't list
is refused on save, with every other problem: a running story holds only its copy of the config, so the copy has to say
which trackers it plays by.
reroll is none or once. An earlier draft of this example spelled it once_per_turn; that spelling is still
read, as once.
System dice systems shipped in v1 — these are the "various options" for deterministic dice, picked by the creator:
| Key | Check | Outcome |
|---|---|---|
d20_fantasy |
1d20 + modifier vs a difficulty number |
success / failure; natural 20 and 1 are crits |
story_2d6 |
2d6 + modifier, no difficulty |
bands: 6 or less miss · 7–9 partial · 10+ hit |
percentile |
1d100 roll-under the skill value |
success / failure; doubles under = critical |
dice_pool |
N d6, N = attribute + skill |
count faces of 5+; 0 fail · 1 partial · 2+ success |
Every resolution produces one value from a shared tier vocabulary: critical_failure · failure · partial · success · critical_success. Prose, lines, cues and effects key on the tier, so a dice-system swap never breaks a consumer.
The bare check — a check with no sheet. Chat has no attributes or skills, so each dice system also declares how a check reads from just a difficulty tier and the reader's modifier (a whole number, −10 to +10, default 0). The console's skill checks are the same resolution with the modifier computed from the sheet.
| Key | Bare check |
|---|---|
d20_fantasy |
1d20 + modifier vs the tier's number |
story_2d6 |
2d6 + modifier + the tier's shift (easy +1 · medium 0 · hard −1 · very hard −2), read in bands |
percentile |
1d100 under the tier's target (easy 75 · medium 50 · hard 25 · very hard 10) plus 5 × modifier |
dice_pool |
3 + modifier + the tier's shift d6 (at least 1), counted as above |
In a chat story the reader picks the dice system in the story's settings (default d20_fantasy); the record carries
its key + version either way.
2. The dice engine
Core/Services/Rpg/Dice/ — pure, HTTP-free, no LLM.
- Notation:
NdM,+k / -k, keep highest/lowest (4d6kh3), advantage / disadvantage (2d20kh1/kl1), exploding (1d6!), dice pools (5d6>=5). Bounds: at most 100 dice, at most 1000 faces, explosion capped at 10. - Randomness:
RandomNumberGeneratoron the server, the only nondeterministic input. - The record stores the faces. Given the faces, everything else is recomputed — so a stored roll is verifiable and a test can feed faces instead of RNG.
{ "notation": "1d20+3", "faces": [14], "kept": [14], "modifier": 3,
"modifierParts": [ { "label": "Dexterity", "value": 2 }, { "label": "Lockpicking", "value": 1 } ],
"total": 17, "against": { "tier": "medium", "value": 15, "shown": true },
"outcome": "success", "crit": false }
3. Checks — who calls, who sets the difficulty, who rolls
The request was an AI mode and a deterministic mode with options. They reconcile with goal 1 only as two independent axes — the server always rolls:
| Axis | Deterministic | AI |
|---|---|---|
| Who calls for the check | the reader (Roll control, Use skill, Use item) or a rule (Story Scripts, later) | the AI game master — Hybrid's beat leg, picking from a menu of legal checks |
| Who sets the difficulty | the dice system's table (difficulty), or the skill/item's declared value |
the game master picks a named tier (easy … very_hard), never a number |
| Who rolls | the server | the server |
| What the outcome does | declared effects — the skill or item says what each tier changes, code applies it | narrated — the prose tells the tier; the tracker eval observes what changed |
In chat the reader sets the axes directly in the story's settings: the dice system, "The AI may call for checks" (Hybrid only, off by default), difficulty shown or hidden, the re-roll policy. Chat outcomes are always narrated — there's no config to declare effects in.
Modes are presets over the axes, chosen by the creator in the package's config:
- Deterministic — the reader (and later rules) call; table difficulty; declared effects where present. The game master never calls a check.
- Game master — only the director calls checks and picks the tier; declared effects where present, narrated otherwise. The director is the beat leg, so it costs no extra call.
- Both (default) — the reader may roll, and the game master may also call checks.
Options (the creator's, in the config; L2 may hand some to readers): dice system; mode; advantage/disadvantage
on/off; crits on/off; difficulty shown or hidden (hidden: the line names the tier, never the number);
secret rolls (game-master checks show only the outcome; faces are kept on the record for export); checks per turn
(1–2, default 1); free notation in the tray on/off; re-roll policy (none / once per staged roll; none / once in the
config).
Re-roll exists only before sending. A staged Roll now may be re-rolled once (if the policy allows), and the line says so. Once a roll is sent it is the turn's: no Re-roll, no discard. A staged roll can't be cleared either — the next send consumes it. That keeps every version of a reply narrating one roll without a "re-roll after the reply exists" case to define.
The game master's contract (AI mode). The VN blocking precedent in spirit (VN_SCENE_ENGINE.md:193-228) — a
code-consumed field, a menu, a guard — with the director's lookups as the parsing model:
The beat gains one code-consumed field,
checks, read frombeat_raw, never from the parsed narrative fields. It is modelled on the director'slookups, not on the VN'sblocking:blockingis JSON-only, while a chat reader's own director mode may answer in labeled text, where an unknownChecks:line would run on into the previous section and reach the prose (BeatParser.cs:340-341has a fixed label set). So:checksis a discard label inBeatParser, likelookups(BeatParser.cs:389-392), and is stripped in the degraded and salvage tiers (theBeatLookups.Strippath);- a
BeatChecks.Parsereads it from a JSON key or aChecks:line holding a JSON array (theBeatLookupsshape); checksjoinssceneas a quiet-turn key (BeatParser.cs:242-243), so a beat that carries only checks parses as an empty beat rather than degrading into the writer's note as raw JSON.
"checks": [ { "skill": "lockpicking", "tier": "hard", "why": "the lock is old and rusted" } ] // RPG "checks": [ { "action": "climb the sea wall", "tier": "hard" } ] // chat: a bare checkThe menu the director sees is built by code: in chat, the tier names and the bare-check shape; in an RPG story, also the config's skills with the character's rank and the usable items in the inventory. It is a user-role block (
LlmMessageSource.CheckMenu, CHAT_EVENTS.md §8) and stripped from the prose leg — theSceneMenu/ Author's Note mechanism (HybridProseLeg.cs:49-56): the director sees options, the prose sees outcomes.The contract text is code's. The menu block itself tells the director how to call a check and to keep its beat outcome-neutral on a check turn, so any director mode can call checks — a chat reader's own Hybrid pair included. The RPG console's seeded modes tune style; they don't carry the contract.
The guard is a pure validator.
IBeatGuard.Judgeis synchronous and runs beforeBeatLeakScreen(BeatDirectionStage.cs:240-292), so it only judges: an unknown skill, an unusable item, a missing or over-long action (60 characters), an unknown tier, or more checks than allowed (the config'schecksPerTurn; chat: 1) → one retry with the reason appended; a second reject →Acceptwith the checks dropped and the drop logged. NotIBeatGuard.Degrade: that swaps the director's narrative for the guard's neutral beat, and the point is to keep the narrative and lose only the checks. Every reject is logged with its reason.One guard slot today.
IBeatGuardis a singleTryAddSingleton(WebChatServiceCollectionExtensions.cs:131, one_beatGuardfield). M4 makes it a composite — guards judged in order, one shared retry budget, one combined correction message, telemetry once — so the VN guard and the check guard can run on one turn (M9).The beat is written before the roll, so a beat that says "she picks the lock" can meet a
failure. On a turn where it calls a check, the director's narrative fields must stay outcome-neutral (the menu's contract: set up the attempt, never its result), and the tracker eval — which on Hybrid reads the beat, not the prose (WebTrackerEvalService.cs:189-200) — reads theCheckOutcomeline and the prose on a check turn.Resolution happens in
BeatDirectionStageafter the guard (pre-LLM Order 550, aftercompute_allocation500), onceGuardedBeatAsynchas returned the accepted attempt and the leak screen has run: the stage rolls the accepted checks, stages them (below), sends theeventsframe, and builds the outcome block. No post-LLM stage can do this: by then the prose has streamed.The outcome reaches the prose leg through the director's note, not an injector. Both beat-leg shapes carry every current-turn block unfiltered (
HybridLegPlanner.cs:301-310,698), and a game-master outcome only exists after the beat anyway. So the stage appends theCheckOutcomeblock beside the note in step 5 (BeatDirectionStage.cs:342-343) — "Lockpicking check: 14 + 3 = 17 against Medium (15) — success." — and does the same in theReusedBeatbranch (:173-208) from the stored record on a prose-only regenerate. It is priced with the note: it rides the note's accepted residual and theFitProseToWindowAsyncrefit, since the reservation at Order 500 precedes the beat.Persisted the moment it rolls, before the
eventsframe goes out — so a reader who sees the dice can't stop the turn and get a fresh roll. On a send the reader's row doesn't exist yet (storage inserts it with the reply), so the check goes to the conversation'sstaged_events, and the turn's storage transaction moves it onto the new reader row (CHAT_EVENTS.md §3). A turn that ends before storage (stop before the first token, a failure) leaves it staged; the next send's director is handed it as already resolved and narrates it.Only a send calls checks. A turn's event set is frozen when it is sent: on a regenerate the guard refuses any new
checksormove, also on a turn that had none (CHAT_EVENTS.md §3). A full regenerate's director sees the turn's resolved checks as settled in its menu block, and the prose gets the same outcome through the step-5 append.Reader rolls resolve before the pipeline runs — at the roll endpoint (Roll now) or at the send door (Roll with my message) — and are staged durably either way, then moved onto the reader's row by the storage transaction, so the pipeline only reads them. Their block is an ordinary current-turn injector and reaches both legs: the director plans around the outcome.
Not tool calling. The story model has no tool calling in the chat pipeline (NativeToolCalling /
TextToolProtocol serve only the Assistant harness), and a mid-prose tool call would put the roll inside the reply,
breaking the before-reply phase. The director is the only "decide before writing" slot, which is why RPG mode is
Hybrid. A conversation's pipeline is fixed at creation (ConversationPipelineType), hence the package-start clamp.
4. Fixed-contract trackers (tracker kinds)
Today a tracker's value_type (freeform / numeric / percentage / enum / list / datetime) is chosen per tracker and the
renderer only knows the type, not the meaning — hp and affection are both "numeric". A tracker kind is a
system-defined template that pins key shape, type, range, renderer, eval vocabulary and prompt wording. A tracker bound
from a kind keeps the kind's contract for its lifetime.
| Kind | Value | Renders as | Eval says (delta ops) | Code enforces |
|---|---|---|---|---|
resource (HP, MP, stamina) |
current / max |
bar with numbers; flashes on change | damage n · heal n · set_max n |
clamp to 0 … max |
attributes |
key → whole number, −20 to 100 |
sheet block with modifiers | — (set by the game, from the package's sheet) | the dice system's modifier rule |
skills |
skill → rank, a whole number, −20 to 100 |
sheet rows with total bonus | — (set by the game, from the package's sheet; advancement later) | skill keys exist in the config |
currency |
integer | coin badge | gain n · spend n |
never below 0 |
conditions |
list of label + optional turns |
chips with a counter | add · remove |
turns counts down per reply in code, at the reply's snapshot write |
xp |
xp (the level is derived from the thresholds, never stored) | progress to next level | gain n |
level thresholds from the config |
inventory |
inventory.md's item state | the bag + equipped slots | add · remove · qty · equip · unequip |
catalog rules, stack limits, capacity |
clock |
in-world minutes since the start | Day 4 · evening (the tracker's day parts) | advance <duration> |
never goes backwards |
In chat, inventory is a bag without a catalog: items are names (or the entries of a linked item lorebook, the T1
link below), with quantities and capacity, and no Use. The catalog, equip slots that matter and item_use are the
package's (§6).
Where a kind lives. Today every tracker is user-owned (trackers.created_by_user_id is NOT NULL, the only
insert is fn_upsert_tracker) and there is no template or system flag. A kind is therefore a column, not a row
owner: trackers.contract_kind (NULL = a free tracker, as today), mirrored by hand across the SQL CHECK, a C# enum
and the TS const like value_type is. A kind's own settings — a resource's starting max, XP's level thresholds, the
clock's day parts, a bag's capacity — sit on the tracker row in one trackers.kind_config JSON column, validated per
kind, so the kind works without a package. One column rather than one per setting, because every new column is a
fn_upsert_tracker signature change mirrored in C#, TS and the Composer apply path (78:112-113,
68e_composer_apply_functions.sql:205). The row holds starting settings only; the live value — a resource's
current / max after a set_max — is the snapshot's.
In chat a kind is one more choice in the tracker form (Forge and the workbench's tracker editor), offered next to the value types: resource, currency, conditions, XP, clock and inventory. Attributes and skills are not offered there — they mean nothing without a package's attribute and skill lists. Its values stay correctable by the reader like every chat tracker; delta ops, the cap and the renderer are the same code the console uses.
A reader can add one to their own story. Today trackers bind only to a character (owner_type 0) or a package
(6), and nothing writes conversation bindings yet (TrackerSetUnion.cs:34-35, trackers.md T2) — so a reader playing
someone else's character couldn't get an HP bar or a bag at all. M3 lands conversation bindings (owner_type 4,
already allowed by the CHECK): the reader adds a tracker — kind or free — to the story from its settings, and
TrackerSetUnion gains the conversation leg. A creator still binds kinds to their characters and packages as today.
In an RPG package the creator adds kinds in the package's RPG step; each becomes an
ordinary creator-owned tracker with the kind set, bound to the package (owner_type = 6, written today by
fn_save_package_full), so a story started from the package resolves them through TrackerSetUnion like any package
tracker. The contract is enforced by the kind, wherever the row came from.
- Keys are per creator.
idx_trackers_owner_keyis unique on(created_by_user_id, key). A contract tracker row is generic (its starting value comes from the config'ssheet), so a creator's second RPG package reuses the samehprow; a key already held by a creator's free tracker is refused in the RPG step with a rename prompt. The seeded package's system rows (user 0) use one shared set, never one per dice system. - The contract wins a key clash.
TrackerSetUniondedupes first-wins with the package leg after the character leg (TrackerSetUnion.cs:99-105), so a bound character's freehpwould shadow the package's contracthp. M3 changes the rule: a kind tracker beats a free one on the same key, and the package save warns when a bound character carries such a key. The synthesised roster stays first, so it still ownscast(:75-81). - Structured values refuse, never truncate.
TrackerValueWritescaps a value at 500 characters and cuts a list by dropping trailing items (TrackerValueWrites.cs:95-97,133-139) — for a bag that is silent item loss. Structured kinds get a per-kind cap (inventory: 4,000 characters; attributes: 1,500; skills: 4,000) and a value over it is refused and logged, never cut. The cap is C#-only today (CreatorFieldLimits.TrackerInitialValue, no SQL length check), so every writer learns it: the eval'sForEval, the scene save (ConversationsEndpoints.cs:70,2753,2890), the inline edit, and greeting starts (GreetingTrackerStarts.cs:43, whose raw 500 check runs before the definition is known). Contract trackers count against the cap like any tracker;Tracker.DefaultMaxTrackersis 40 since 2026-11-07 (it was 8; the raise M3 asked for shipped ahead of it) — the owner, 2026-10-28: the real bound is the model's input, not a product limit — and a set is measured in tokens (TrackerTokenCost, a warning overTracker.MaxTrackerTokens; trackers.md The token figure). The sheet's injected size therefore belongs in the context budget: contract kinds inject in the compact form, and the fit check (context_fit) counts them like any tracker block.
Storage stays the flat snapshot. A structured kind's value is a canonical JSON string, the way list already is
(TrackerValueFormatter). Nothing new is added to web_messages for state; branch, the tracker_state lock and the
summary timeline keep working unchanged. Two writers do change — the eval write and the eval-failure path — see
Declared effects below.
The eval emits deltas for structured kinds, never a restated whole. A resource gets damage 3, not a fresh
current: 11; an inventory gets add health_potion, not a re-listed bag. Code applies the op, clamps, validates and
writes the snapshot. A restated whole is how state silently drops items — the same mismatch the living lorebook's
relationships and the journal both had before their merge ops (commit 7329a48ab).
Declared effects are ops on the event, re-applied at every snapshot write of the reply. A value written once at
storage doesn't survive: the eval builds the reply's state from the prior row and writes the whole map
(WebTrackerEvalService.cs:209,294-308,364-366; fn_write_tracker_eval_snapshot never reads the target row's own
tracker_json, 78_tracker_functions.sql:894-933), so it would clobber the effect. A storage-time value would also
read a stale prior while the previous reply's detached eval is still in flight, and would move the eval's catch-up
watermark (any non-empty earlier snapshot anchors it, WebTrackerEvalService.cs:562-566).
So an effect is stored as an op on the event record (hp damage 4, dice already rolled into the amount) and applied
by C#:
- at the eval write —
prior + the eval's values for free trackers + drift-merge, then ops last: the eval's own delta ops for structured kinds, then the event ops — in SQL under the same lock, in a newfn_write_tracker_eval_snapshot_with_effects. Ops go after the drift-merge because that merge keeps a reader's mid-eval correction whole ("the user wins",78_tracker_functions.sql:876-933): applied before it, an eval'sadd swordwould vanish under the reader's corrected bag. The eval's answers on effect keys are ignored. It lands the effects of every turn in its catch-up window, so an eval that stands down loses none; - when the eval fails, is Off or skips —
prior + event ops + per-reply code ops. Today those paths write nothing; writing here is a deliberate divergence that closes the exchange for the watermark (CHAT_EVENTS.md §6 has the full rule); - per-reply code ops (a condition's
turnsticking down) count as effects: they trigger the no-eval write, and an eval write over a catch-up window of N replies ticks N times — once per reply.
There is no storage-time write, so the stored snapshot lands when the eval writes (or on the failure path), and the
existing conversation_trackers push carries it. The sheet doesn't wait for it: the console projects the turn's
event ops onto the last snapshot for display the moment the event arrives — the event is already true, the same cue
rule — and swaps to the stored snapshot when the push lands. The dice land on "−4" and the HP bar drops with them.
An RPG story pins the per-conversation trackers feature on (FeatureId.Trackers — the reader has no switch for it) and
its eval cadence to per_message. The platform-wide Features.EnableTrackers stays the operator's kill switch; with it
off, RPG packages can't be started.
The starting sheet is the opening snapshot: fn_seed_opening_tracker_snapshot / OpeningTrackerSnapshot seed it
from the conversation's rpg_config.sheet, so the first reply's prior is the package's sheet, not each tracker's
generic initial value.
Readers don't edit the sheet. In an RPG story the scene editor is read-only for contract trackers — HP set by hand would make every check meaningless. Free trackers in the same package stay editable as today. (Hand-correcting a mis-applied effect is an L2 question.)
Attributes and skills are set by the game only. The two sheet kinds take no eval op, and a reader can't change them anywhere a chat tracker is corrected; the refusal names the tracker: "Attributes: the game sets this, so it can't be changed here." Their creator can rename the row, describe it and show or hide it, but not change its key, kind, type or start value: the package's config finds the row by its key, and the starting numbers are the config's sheet.
Hidden stays hidden. A contract tracker with "Visible to the user" off never appears in an event line, a target or a cue (the research's SCENE-GATE extension, §3.9).
5. Skills
A skill is defined in the package's config (key, label, governing attribute, description) and ranked on the
sheet (the skills tracker). Using one is a check: modifier = attribute modifier + rank bonus, rolled with the
dice system's dice.
How each dice system reads the sheet (as built for M5; the three rows after d20_fantasy are defaults, see Open
Questions):
| Key | Skill check |
|---|---|
d20_fantasy |
1d20 + attribute modifier + rank against the tier's number; the attribute modifier is half the attribute, rounded down, minus 5 (10 gives 0, 15 gives +2) |
story_2d6 |
2d6 + attribute modifier + rank + the tier's shift, read in bands; the attribute modifier is d20_fantasy's (half the attribute, rounded down, minus 5), never the raw value |
percentile |
1d100 at or under rank + (the tier's target − Medium's); the attribute isn't used |
dice_pool |
attribute + rank + the tier's shift d6, at least 1 die and at most 100, counted as in §1 |
A skill may declare cost (paid before the roll, e.g. mp -3) and effects per tier (e.g. a Heal on success:
hp heal 2d4). A skill with no roll — an ability — is a cost plus effects with an automatic success.
- Dice are drawn in one order: the cost's, then the check's, then the effects'.
- A cost is judged before any die, on the most it can be. A cost of
1d4MP needs 4 MP, and the refusal says "Needs up to 4 MP, you have 1."; a fixed cost says "Needs 3 MP, you have 1." A refused roll draws nothing, so asking again can't find a cheaper roll. (Judging on the most it can be is the built default; see Open Questions.) - A cost on a tracker the story hides or doesn't bind gates nothing and is dropped, as its op would be when the event lands. A hidden tracker is never named in a refusal.
- A re-roll doesn't pay again. It carries the cost already paid, as it was rolled, and rolls only the check and the new outcome's effects.
6. Inventory
Inventory System is the design; RPG mode makes two decisions it left open:
- Changes are delta ops from the eval (§4), applied by code.
- Using an item is an event,
item_use, with the item's declared effects (consume one; a potion'sheal 2d4). The reader uses an item from the bag; the game master may use one through its menu.
Catalog only in an RPG story. Items exist only in the package's catalog; an unknown item from the eval is dropped and logged. Chat's uncatalogued bag (§4) is the same kind with the catalog check off.
Reused, not rebuilt:
- Item lore rides the shipped "trackers as inputs" mechanism (T1): a tracker linked to a lorebook takes its values
from entry names and pins the held entries into the knowledge section every turn
(
WebTrackerPinnedKnowledgeSource). An item'slorebookEntryIduses the same pin for equipped items — no second injection path. A list tracker linked to an item lorebook is already a primitive inventory; theinventorykind is its typed upgrade (quantities, slots, effects). - The living lorebook is not the inventory. The story registry's
thingentities are narrative, eval-derived facts; theinventorykind is the mechanical truth. The registry may still note "the rusted key" as a thing; it never decides whether the reader holds it.
7. Map travel (layered)
Where the party is, is what is — code owns it. The model narrates the road; it never moves the party across the map.
The places are the Place tracker's places. Chat is getting a built-in Place tracker
(docs-internal/architecture/chat-engine/LOCATION_TRACKER.md, planned): value type Place = 6, a path of names from
widest to narrowest (["Ardent Coast","Saltmere","The Drowned Lantern"]), lorebook entries flagged This is a place
with an Inside parent (lorebook_entries.is_place / parent_place_entry_id), Living Lorebook places beside them,
and the current place plus its nearest ancestors pinned into knowledge. RPG mode uses that tracker, not a second
one: the same value type, storage (a name path in tracker_json, never ids), resolver (PlacePathResolver), place
index (IStoryPlaceIndex), breadcrumb, pins, timeline and history formatting. Its hierarchy is the map's hierarchy —
an RPG package's places are lorebook place entries in its lorebook, and the map adds only what Place deliberately
leaves out (its Non-Goals: maps, coordinates, travel time, distances). LOCATION_TRACKER.md §10 records what RPG mode
needs from it.
What the map adds — a spatial layer over the place tree. A map layer belongs to one place entry (or the root) and shows that place's child places as pins on a picture, with routes between them. Ardent Coast (a place) has a layer whose pins are its children Saltmere, The Gull Steps, Wreckers' Cove; Saltmere has a layer with The Drowned Lantern, Harbour market, The Tide Chapel. Depth comes from the lorebook's Inside chain; the map never restates it.
// in the package's RPG config — places are referenced by lorebook entry (the config is authored and validated
// against the package's lorebooks; tracker snapshots still store names only, as Place requires)
"map": {
"v": 1,
"layers": [
{ "place": null, // the root layer: top-level places
"image": "gallery:8812",
"pins": [ { "entry": 5101, "at": [0.42, 0.61] }, { "entry": 5102, "at": [0.70, 0.30] } ],
"routes": [ { "from": 5101, "to": 5102, "time": "3d",
"cost": [ { "tracker": "rations", "op": "spend", "amount": 3 } ],
"encounter": { "chance": 0.25, "table": "coast_road" } } ] },
{ "place": 5101, // Ardent Coast's layer: its child places
"image": "gallery:8813", "entrances": [ 5120 ],
"pins": [ { "entry": 5120, "at": [0.31, 0.44], "discovered": true } ],
"routes": [ { "from": 5120, "to": 5121, "time": "4h", "when": { "flag": "bridge_repaired" } } ] }
],
"start": 5140 // a place entry; the start path is its Inside chain
}
- Routes live inside one layer. Moving between places in different layers goes up to the layer where their
ancestors share a route, crosses it, and enters the destination's layer at one of its
entrances. Code computes the path and its summedtimeandcost(shortest by time over discovered routes); the reader sees them before confirming. - A route may be gated (
when: a tracker value, an item held, a flag) and may cost (effect ops: rations, coin, stamina) — the same op vocabulary as skills and items. - Encounters are rolled, never decided by the model: a route's
chanceis rolled by the server when the party sets out; a hit draws from the package's encounter table (also rolled) and becomes part of the travel event. The prose narrates it; the game master may call checks from it. - The validator follows the VN scene graph's catalog rules (
SceneGraphValidator) and checks against the place tree: a pin whose entry isn't a place, isn't in the package's lorebooks, or isn't a child of its layer's place; a route between layers; astartwith no route in; an entrance outside its layer — refused with every problem listed. The VN's locations and this map share a vocabulary on purpose (move,when, effects); converging them is a later conversation of its own (after M9 and M10), not v1.
Mapped places are mechanical; below them the story wins. The Place tracker's rule — the story wins, an unknown place is recorded, never refused — still holds, but only below the deepest mapped place. In an RPG story:
- the path down to the current mapped place is written only by travel events;
- the tracker eval may still refine inside it (
… › The Drowned Lantern › Back room): segments under the mapped prefix follow LOCATION_TRACKER.md §5 unchanged (free text, registry places, resolution); - an eval answer that changes the mapped prefix is dropped for those segments and logged — the narrator can walk into the back room, not to Greyfen.
The state — the Place tracker, the clock kind and one map-only kind, discovered:
| Tracker | Value | Renders as | Eval says | Code enforces |
|---|---|---|---|---|
| Place (the built-in) | a name path | the breadcrumb Ardent Coast › Saltmere › The Drowned Lantern | segments below the mapped prefix only | travel events own the mapped prefix |
discovered |
a set of place paths (names, like Place — no ids in a snapshot) | fog on the map | reveal <place> (mapped places only) |
unknown places dropped |
clock (§4, shipped in chat first) |
in-world minutes since the start | Day 4 · evening | advance <duration>; travel advances it by the route's time |
never goes backwards |
Moving. Two callers, as for checks (§3):
- The reader opens the map (from the sheet's breadcrumb or the console's map button), zooms between layers, taps a
discovered destination, sees the route, time, cost and whether it risks an encounter, and confirms. That stages a
travelevent (or sends it with their message, like a roll). - The game master gets reachable destinations in its menu ("go Saltmere → The Gull Steps — 4h, needs the
bridge") and may pick one in
move, a sibling ofchecks; code validates it like a check. The VN'sblocking.moveis the precedent.
The travel event (before-reply, on the reader's row) records the path, the time and cost ops, the encounter
roll and its result. Its line: — Travel · Saltmere → The Gull Steps · 4h · encounter: none —. Its cue: the party's
marker walks the route on the map. Its prompt block (TravelOutcome, both legs for a reader move, prose only for a
game-master move): "The party travels from Saltmere to The Gull Steps by the cliff road, about four hours. Nothing
waylays them." Its ops land on the Place tracker, clock and the cost trackers by the same rule as every effect (§4).
The place's lore follows the party — through Place's own pins. LOCATION_TRACKER.md §6 already pins the current
place's entry and its nearest ancestors (cap 3, budget-exempt, leg tracker). RPG mode adds nothing there; a travel
event that lands a new path moves the pins on the next turn exactly as an eval-recorded move does. A place the party
hasn't discovered is never listed in the eval's Known places, never pinned, and never named on a line or the map.
The map in the console. A full-screen layer (desktop: beside the transcript; phone: a sheet) drawn from the layer's gallery image, pins and SVG routes on top, in render layers: art → routes → fog → pins → the party marker. Undiscovered places are hidden or fogged by the creator's choice. Pinch / scroll zooms; tapping a place that has its own layer drops into it; the breadcrumb climbs back up. Keyboard: arrows move between pins, Enter opens, Escape climbs.
Depends on LOCATION_TRACKER.md M1–M2 (the Place value type, the place flag and Inside parent on entries, the place index, the pins) and its §10 RPG requirements. M10 builds on them; it doesn't build a second place system.
Not in v1: tile or hex grids on the travel map (the scene grid inside one place is in, owner decision 2026-11-12, see the map-layers plan), free movement between pins, procedurally generated maps, other actors moving on the map (NPC positions stay narrative), and a reader editing the map.
The ultimate form, later: a 2D moving mode (owner, 2026-10-28). The party walks a 2D scene instead of jumping
between pins — the reader moves their character through a place, and walking up to a door, a person or a chest is how
a turn starts. It is a presentation over the same truth: code still owns position (finer-grained than a place path),
travel is still a travel event, and what happens on arrival is still narrated. Building the layered map on code-owned
places, events and lorebook places now is what keeps that door open; nothing in v1 assumes position is only a pin.
Its own spec when it comes.
Chat events: the answers this plan needs
The research's questions are now decided in docs-internal/architecture/chat-engine/CHAT_EVENTS.md §1 (2026-10-28); the table below matches it.
| # | Question | Lean | Why |
|---|---|---|---|
| O1 | Shape | B — turn_events on the row, staged_events on the conversation, one catalog, tracker changes derived |
Dice, skills and items are three stored kinds; A pays the seams three times |
| O2 | Does a regenerate re-roll? | No — not a reader roll and not a game-master check: both live on the reader's row and every version narrates them. Re-roll exists only on a staged roll, before sending, and the line says "re-rolled" | Otherwise swipe is a free re-roll |
| O3 | Who calls a check? | Reader first (M2, chat), the AI (M4, chat Hybrid), rules with Story Scripts; in an RPG story the package's mode picks | §3 |
| O4 | Do outcomes replay in later prompts? | No — one-shot; the prose and the snapshot carry it | Byte-identical prompts for event-free turns; no history bloat |
| O5 | Public pages show events? | Owner decides | Product call |
| O6 | Feature off: do recorded events render? | Yes — they are a record; only injection and landing stop | — |
| O7 | Same change before and after: one line or two? | One merged line for directions; for a check, the check line then the tracker change (they say different things: 17 vs 15 and HP 14 → 11) | — |
| O8 | chat-v2 parity | Dice and checks are controls in chat., lines (read-only) in chat-v2; tracker kinds render in both | chat. is the chat surface that grows; chat-v2 reads the same records |
| O9 | Rules ownership in the record | The record carries the dice system's key + version, never rules |
Ownership can move without a record migration |
Event kinds these primitives add (all before-reply, all stored on the reader's row except where noted):
| Kind | Source | Data | Prompt block (legs) |
|---|---|---|---|
dice_roll |
reader | the dice record, a free-text label | DiceRoll (both legs) |
check |
reader | a skill (RPG) or a label (a bare check), tier, dice record, outcome, effect ops (RPG only) | CheckOutcome (both legs) |
check |
game master (the AI, in chat or RPG) | as above; the action text for a bare check | CheckOutcome (prose leg only, appended with the director's note — §3) |
item_use |
reader / game master | item slug, effect ops, any dice | CheckOutcome (as check, by source) |
travel |
reader / game master | path, time and cost ops, encounter roll and result | TravelOutcome (as check, by source) |
A game-master check belongs to the turn, not the version. If it lived on the reply row, a swipe would re-run the
director and re-roll — the free re-roll O2 exists to forbid. So the first game-master check of a turn is written onto
the reader's row (source game_master) — staged first on a send, see §3 — and every later version of the turn
reads it:
- Full regenerate — the director runs again but is handed the turn's resolved checks as already settled
("Resolved this turn: Lockpicking vs Hard — failure. Don't call another check."); the guard refuses any new
checksormoveentry, on a turn that had none as well; the sameCheckOutcomereaches the prose leg. - Prose-only regenerate — the
ReusedBeatbranch skips the director and the guard (BeatDirectionStage.cs:173-194); the stored record is read from the reader's row and the sameCheckOutcomeis injected. Nothing is rolled. - Delete — deleting the turn's reply (the version shown, which takes every version) takes the check with it: the turn is gone, and its roll would otherwise sit on the reader's row where nothing shows or removes it (owner, 2026-11-02; CHAT_EVENTS.md §5). Deleting a version that isn't shown keeps it. Deleting the reader's message removes it too. Either way, sending again is a new turn with a new roll; that is visible in the transcript and accepted.
The dice animation
The outcome is fixed before the model writes, and the animation plays anyway — goal 2 makes that the design, not a trick. The cue is told the recorded faces; it tumbles and lands on them.
| When | Delivery | What the reader sees |
|---|---|---|
| Roll now (reader, before writing) | the roll endpoint returns the record; it is staged | dice tumble in the dice control (chat.) or tray (console), land; the reader writes knowing the outcome |
| Roll with send (reader) | a new SSE events frame — on Hybrid emitted with the beat_running stage frame (ChatPipeline.cs:488), because start only comes after every pre-stage, director included (:681,689), too late; on Classic in the gate slot after the last pre-stage, before start (ChatPipeline.cs:603-610 — never between pre-stages, which would lose the turn's embedding accounting) |
dice tumble between the reader's turn and the reply while the director thinks (Classic: before the first token) |
| Game-master check | the events frame at the beat → prose stage change |
dice tumble under the reader's turn; the reply streams in under them |
| Reload, history, export | the stored record | the line with the final faces; cues never replay |
One refinement to the research's rule. The research says a cue never blocks the prose (§3.4). For a game-master check the first tokens can arrive mid-tumble and spoil the result. So the client holds the reveal, not the stream: tokens keep arriving and buffering, and the reply appears when the dice settle, capped at 1.6 s; a tap skips it. Reduced motion: no cue, no hold.
The line (the accessible text, the PDF line, the Discord line later):
— Lockpicking · 14 + 3 = 17 vs Medium 15 · success —. With a hidden difficulty: — Lockpicking · 14 + 3 = 17 vs Medium · success — (the sum stays; only the number it is against goes). With secret rolls: — Lockpicking vs Medium · success —.
(d20_fantasy's numbers: Easy 10, Medium 15, Hard 20, Very hard 25.)
The cue is 2D (SVG dice per die size, d4–d20 and d100), lives in shared/src/chat/events/cues/, and has a
coverage test: every event kind declares a line and declares whether it has a cue.
Wire. The events frame is a new PipelineTokenType, a case in WebChatSseFrames.MapPipelineTokenToEvent and
the VN mapper, null in the protected-reader mapper (WebChatSfwSseFrames.cs:51-78 — the SFW lane is Classic-only,
so an RPG turn never reaches it; a protected reader's chat roll gets its line from the stored record on read, with no
cue), and a new type with its fields on the ChatStreamFrame interface
(shared/src/types/chatStream.ts:100). It stays out of done, whose key set is pinned by
ChatSseDoneFramePromptTests; the stored record reaches a reload through the message read.
Surfaces
Chat — the primitives (chat. first)
- The dice control sits in chat.'s composer once Dice is on for the story: quick dice (d4–d20, d100), a free-notation field, a Check tab (label, tier, modifier), Roll now and Roll with my message. A staged roll shows as a line above the field with Re-roll (by the story's policy) — the same composer-line slot tracker transitions' staged direction uses.
- The story's settings (chat.'s story drawer; the user's defaults in Settings → Features): Dice on/off, the dice system, difficulty shown or hidden, the re-roll policy, and on a Hybrid story "The AI may call for checks".
- The tracker form offers the kinds (§4); chat.'s scene and chat-v2's tracker bar draw them with the kind's renderer — the same components the console's sheet uses.
- chat-v2 renders the lines and the kinds and gains no dice control.
Authoring — the package creator
- A seeded first-party package first. Like the VN's After Hours, one RPG package is seeded (system rows,
created_by_user_id = 0) so M5–M7 build and play against real content before any authoring UI exists. - The package workbench gains an RPG step: on/off, dice system, mode, options, attributes, skills (with effects), items (inventory.md's fields, gallery images, effects), contract trackers, the starting sheet. It stages into the workbench's one draft and saves with it; the validator refuses a bad config with every problem listed, never the first only.
- The game master's leg modes default to seeded system modes (RPG Game Master, RPG Prose) that set the tone;
the package's own Hybrid pair may replace either. The
checkscontract travels in the code-built menu (§3), so no mode can drop it (the VN rule: the code-consumed block is fixed at every level). - The package page says it before Start: RPG · d20 Fantasy · Game master — the label that tells an RPG from a
visual novel, since both are Hybrid packages (
GAME_DIRECTION.mdChat, visual novel, RPG — what the reader gets).
Play — the RPG console
The play surface's structure follows the phone board docs-internal/mockups/RpgPhone.dc.html ("walk the scene, chat on
arrival, the bar"), as the owner answered it (2026-11-06). The board's names, numbers and dice are sample content: they
size and stress the UI and seed the prototype's fixtures, and they decide no rule.
- A shelf of the reader's RPG stories, most recently played first, and the RPG packages they can start.
- Start on an RPG package (from its page or the shelf) creates the story as Hybrid — no pipeline choice — and opens it here.
- The scene first. The screen leads with where the party is: the scene, the party, the moves of this turn, and a small snippet of what is happening now.
- The sheet: open on a desk, folded on a phone (a space choice). Four panels — Character, Skills, Bag, Bonds — stand open in a column on a desktop; on a phone they fold away behind the bar and the menu, to give the screen to the scene. Contract trackers draw by their kind's renderer — HP bars, attributes and skills with bonuses, coins, condition chips, XP; free trackers the package binds draw as values.
- Bonds and the party, on trackers. A bond is a package tracker (trust and affection toward the persona) with a place of its own to be drawn: the Bonds panel and a companion's panel. People not met yet aren't listed. Party members are tracker-backed state too — each companion's HP and conditions are trackers — drawn on the party strip; a companion can be told to use a skill (a check under the story's dice system), given an item, or spoken to in private. No new machinery: the tracker substrate (§4) carries both.
- Movement in layers. The scene's tiles are walked a step at a time within the turn's moves (the persona's speed, after conditions), with End turn; the zones name where the party is. This is the finest layer of movement, not a replacement: §7's world → region → place travel stays the layers above it.
- Talking to who is here. A chat is only with someone in the scene: the party, or a person the party stands beside. Opening their chat on arrival is one of the supported options (the package's), not the only one; private chat is only with a companion who is present.
- Actions trigger dice. An action is a skill or a usable item from the sheet; pressing it stages its check on the composer's line (the slot a staged roll uses in chat.) for Roll now. Its dice are the primitives' — the story's dice system with the skill's bonus, against the difficulty the game sets, and the effects it declares (§3, §5, §6). chat.'s dice control stays behind "Roll dice…" for packages that allow free rolls (UC-4).
- The action bar is the phone's. Not everything fits a phone's screen and some things are used again and again: the bar holds the reader's chosen skills and items, per story, on either side. On a desktop everything is reachable without it — skills and items in their panels — and the bar may stay as a quick row; nothing is reachable through the bar alone.
- The bag: a grid of the catalog's item icons (their gallery images) with counts, equipped marks, and Use, Inspect and Put on bar on an item. Chat's bag is a list of names; the console's is the drawn one.
- A snippet, then the whole story. The scene shows a small snippet of what is current (the visual novel's concept); a tap opens the whole history and conversation, drawn by the shared story renderer, event lines in the Story events slot.
- The rules, read-only, in the game menu (d20 Fantasy · Game master · difficulty shown): read once or when needed, so not on the phone screen all the time. There is no RPG control for the reader.
Narration stays open; mechanics don't (owner, 2026-10-28). The reader fixes details of the text exactly as in chat: regenerate a reply (full or prose-only), edit a reply's text, edit their own message. None of that touches the mechanics — no edit or regenerate rolls, re-rolls, or re-applies an effect; every version narrates the turn's recorded rolls and checks, and the sheet moves only by event ops and the eval. The sheet itself is read-only to the reader.
Elsewhere
- chat. and chat-v2 on an RPG story: if an RPG story's transcript is shown there, its lines render read-only through the shared projection; no roll control, no sheet — the story's rules are the console's.
- Published and shared pages show the events (owner, 2026-10-28: O5 yes): rolls, checks, item use and visible-tracker changes, following the story's rating and the protected-reader rules the chapter markers already apply. A hidden tracker never appears; secret rolls stay secret.
Cost
- Rolls, checks, effects: code. Free.
- The game master: the beat leg already runs; the menu adds input tokens only.
- Contract trackers: the same tracker eval call; the delta ops add no call.
Implementation Plan (Sliced)
| Milestone | Scope | Push unit | |
|---|---|---|---|
✅ built 2026-10-28 (19df61402) |
M0 — events projection | CHAT_EVENTS.md M0: lift the derived tracker-change projection from chat.'s sceneModel.ts into shared/src/chat/events/; the stage direction, chat-v2 and the PDF read it. Behaviour-preserving |
own |
✅ built 2026-10-29 (1b3c515a3, bd0f1f850) |
M1 — event storage + direction |
CHAT_EVENTS.md M1: turn_events, staged_events, every seam (branch copy, insert function, record, DTO, JSON export, PDF, SSE events frame); tracker transitions rebuilt on it |
one unit |
✅ built 2026-10-29 (87e86280d, c8cb6fb53, 320972242, 926a67faf) |
M2 — dice + bare checks in chat | Dice engine, the dice-system catalog + validator with the four system dice systems and their bare checks; dice_roll and reader check kinds; the roll endpoint (staged roll), Roll with my message at the send door, Re-roll by policy; DiceRoll / CheckOutcome blocks; the cue + the line in shared/src/chat/events/; chat.'s dice control and the story's dice settings (user default + story, off by default); chat-v2 lines. Classic and Hybrid |
own |
🚧 in progress 2026-11-22 (the three owner decisions are made, with their defaults; conversation bindings shipped with trackers T2, 703cd43c0) |
M3 — tracker kinds in chat | trackers.contract_kind + kind_config (the column already landed with Stage trackers, with one kind; M3 widens it); conversation bindings (owner_type 4, the TrackerSetUnion leg, add-a-tracker in the story's settings); resource, currency, conditions, XP, clock and the uncatalogued inventory bag; the eval's delta ops applied after the drift-merge; per-kind value caps that refuse at every writer; the kinds in the tracker form; kind renderers in chat.'s scene and chat-v2's tracker bar (shared components); kind-beats-free precedence in TrackerSetUnion; condition turns ticking on the snapshot write paths; the raised Tracker.DefaultMaxTrackers |
own |
| ✅ built 2026-10-31, off by default | M4 — AI-called checks in chat | Hybrid: the checks beat field (bare checks), the code-built CheckMenu with the contract text, the composite IBeatGuard, attempt-2 accept-without-checks, resolution in the beat-direction seam, staging + the turn-pinned check (full and prose-only regenerates replay it, the guard refuses new checks), the reveal hold, the eval reading the outcome on check turns; the story setting |
own |
🚧 built and landed 2026-11-23 (f51646f0d, f057a9f98, e6b3216f5, d5f960d67 pushed; 1d850767f, 94ff8fcf2 not pushed); the rpg. edge prefixes not landed; partly proven live locally |
M5 — the RPG console + package config + sheet | Lift the VN console's shell into shared/; the RPG console (shelf, story view on the shared story renderer, sheet column, composer with chat.'s dice control + the sheet, read-only rules), its Railway service and worker route, staff-only; packages.rpg_config + its validator, the copy to web_conversations.rpg_config at start, the Hybrid start clamp and the Start route; the seeded package; the attributes and skills kinds; the opening snapshot from rpg_config.sheet (fn_seed_opening_tracker_snapshot / OpeningTrackerSnapshot); skill checks with sheet modifiers; declared effects as event ops through CHAT_EVENTS.md §6's landing; the console's projected display of ops until the snapshot lands; the read-only sheet; the trackers feature pinned on |
one unit |
| 📋 | M6 — inventory (RPG) | The package's item catalog on the inventory kind, equip slots, the bag panel, item_use, item effects with dice |
own |
| 📋 | M7 — game master (RPG) | The package's skills and usable items in M4's menu, the mode presets (deterministic / game master / both) from the config, the seeded RPG Game Master / RPG Prose style modes | own |
| 📋 | M8 — creator authoring | The workbench RPG step, the package page line, package save of contract trackers | own |
| 📋 | M9 — VN checks | A VN transition may require a check; the scene engine resolves it with the same primitive and M4's composite guard | own |
| 📋 | M10 — map travel | Needs LOCATION_TRACKER.md M1–M2 and lands its §10 (R1–R11). The map document + validator over the place tree; the Place tracker as the location, the discovered kind (clock is M3's); the console's layered map view; reader travel (travel event, path + cost + encounter rolls, the walk cue, TravelOutcome); the game master's move (after M7); the map step in the workbench (after M8) |
own |
M0–M1 are CHAT_EVENTS.md's milestones (M1 carries tracker transitions). M2–M4 are chat and ship to readers on their
own. Every one of M2–M4 needs M1 (staging and consume, the current-turn injector base, the events frame,
fn_write_tracker_eval_snapshot_with_effects); M3's condition ticking also needs M1's no-eval write. M2 and M3 are
independent of each other; M4 needs M2. The Place tracker (LOCATION_TRACKER.md M1–M2) runs in parallel on chat. M5
needs M2–M3; M6 needs M3 and M5; M7 needs M4 and M5; M8 needs M5; M9 needs M4; M10 needs M7 and M8. M8 can move ahead
of M7 if creators should build RPG packages before the game master exists.
Open Questions
For the owner:
- Classic or Hybrid? Hybrid only (owner, 2026-10-28).
- Is a game a Package? (fork #5) Yes — the package carries the RPG config (owner, 2026-10-28).
- Who configures? The package's creator; readers nothing in v1 (owner, 2026-10-28).
- O5 — events on published and shared pages. Yes (owner, 2026-10-28), following the story's rating.
- Sheet corrections. Contract trackers are read-only to readers in v1; a creator-allowed "correct the sheet" is L2. Narration stays open to regenerate and edit (owner, 2026-10-28).
- Chat or console? The game plays in the RPG console — the games surface (2026-10-28, from the two-surfaces principle; an earlier draft put the whole game in chat. and was withdrawn). The primitives land in chat first and the console takes them over (owner, 2026-10-28: "a lot of these things will be reusable for standard chat and can be partially tested there already … then we can just take it and use it in the RPG").
- Console access at launch. Staff-only first, like the VN console (rights ≥ 2), then opened (owner, 2026-10-28). The seeded package stays unlisted until then.
- Which reader options come first at L2. Difficulty shown/hidden and the re-roll policy (owner, 2026-10-28 — low stakes, the lean stands).
- Does
story_2d6add the raw attribute, or the d20 modifier? The d20 modifier (owner, Relay eod-431): the attribute is read throughd20_fantasy's rule (half, rounded down, minus 5) before it is added, with rank and the tier's shift (§5). - Is a rolled cost judged on the most it can be? Yes (owner, Relay eod-431), as built: before any die (§5), so a refusal draws nothing and asking again can't find a cheaper roll.
- What does the roll line say when the attributes are hidden? Nothing about them (owner, Relay eod-433): when every attributes tracker on the story is hidden, the line names no attribute and no bonus; the dice and the total still show. The stored record keeps everything.
- One attributes tracker and one skills tracker per game? Not enforced for now (owner, Relay eod-436: "Let's not enforce any limits now, we will see after the showcase is done.").
Decided here (engineering): dice systems are platform, content is the package's (fork #4); the config is copied
onto the conversation at start; the Hybrid start clamp keys on the RPG config; the tier vocabulary; storage in the flat
snapshot; trackers.contract_kind as a column; contract trackers bound to the package; Tracker.DefaultMaxTrackers
raised (owner: bounded by model input); a contract tracker beats a free one on the same key; structured values refuse
over their cap, never truncate; delta ops; effects as ops on the event, applied at the eval write and on eval
failure (no storage-time write); faces on every record; game-master checks resolve in the beat-direction seam and are
pinned to the turn on the reader's row; Re-roll only before sending; outcome-neutral beats on check turns; no tool
calling; the reveal hold (1.6 s cap); 2D cues; the menu is director-only; the console lifts the VN console's shell into shared/;
chat's primitives — reader dice and bare checks (Classic and Hybrid), AI-called bare checks (Hybrid), tracker kinds
without attributes and skills — ship to every signed-in reader, off by default; each dice system declares a bare
check; the check contract's text lives in the code-built menu, not in a mode; chat.'s dice control is the console's
tray with the sheet added.
Related documents
docs-internal/architecture/chat-engine/CHAT_EVENTS_RESEARCH.md— the event model this builds on- Tracker transitions — the first stored event kind (
direction) - Inventory System · Trackers · Hybrid pipeline
docs-internal/vision/GAME_DIRECTION.md— the two surfaces; chat vs visual novel vs RPG from the reader's side; the missing resolution layerdocs-internal/visual-novel/VISUAL_NOVEL_PROTOTYPE.md,VN_SCENE_ENGINE.md— the pinned-Hybrid precedent
Acceptance Criteria
The feature is not done until every box below is verified ✅ against the running product. Each milestone gates on its own block plus every invariant.
User use cases — satisfiable + accessible (verify by driving the UI, not the code):
Chat (M2–M4):
- UC-C1 (M2) As a chat. reader, I can turn Dice on in my story's settings (or as my default in Settings →
Features), see the dice control appear in the composer, roll
2d6+1with Roll now, watch the dice land, and read the line with the faces and total. With Dice off, the composer is exactly as today. - UC-C2 (M2) As a chat. reader, I can make a bare check — Climb the sea wall · Hard · +1 — with my message, on a
Classic and on a Hybrid story; the dice play before the reply, and the prompt carries its
CheckOutcome(both legs on Hybrid; prompt capture,game-testingmock LLM). - UC-C3 (M2) As a chat. reader, I can switch my story's dice system to
story_2d6,percentileordice_pooland see the next bare check resolve and read by that system. - UC-5 (M2) As a reader, I can swipe a reply and every version's prompt carries the same roll; on a staged roll (before sending) Re-roll changes it once and the line says so; after sending there is no Re-roll control.
- UC-14 (M2) As a reader, I can fix a detail of the narration: regenerate a reply (full or prose-only), edit a reply's text, edit my own message — and the turn's roll and check records and their ops stay exactly as they were (tracker values follow the new version's own eval, with the same ops applied).
- UC-C4 (M2) As a chat-v2 reader of a story with rolls, I see the roll and check lines read-only and no dice control.
- UC-15 (M2) As a signed-in adult reading a published story with rolls, or anyone holding its share link, I see the roll and check lines and the visible tracker changes beside the prose (a logged-out visitor sees no published transcript today, and that doesn't change).
- UC-C5 (M3) As a reader of someone else's character, I can add a Resource tracker with a max of 12 to my story
from its settings (and as a creator, bind one to my character from the tracker form), and see an HP bar — not
hp: 12— in chat.'s scene and chat-v2's tracker bar; when the reply says I'm hurt, the bar drops and stays within 0–12. - UC-C6 (M3) As a reader, I can add a bag (the Inventory kind) to my story: items the story gives me appear with quantities, and I can correct a wrong count from the scene editor like any chat tracker.
- UC-C7 (M3) As a reader, I see coins, condition chips with their turns left, XP towards the next level and the in-world clock (Day 2 · evening) drawn by their kind.
- UC-C8 (M4) (First half verified on the mock rail 2026-10-31; the real-model half is open.) As a chat. reader of a Hybrid story with "The AI may call for checks" on, with the mock director
emitting
checks: [{ action: "climb the sea wall", tier: "hard" }], I write "I climb" and see the check line and dice under my turn, and the prose prompt carries theCheckOutcome. Then, against a real model, the reply reads as that outcome (judged by eye, screenshot as proof). On a Classic story the setting isn't offered. - UC-13 (M4) (Prose-only driven in chat. 2026-10-31; full regenerate on the mock rail through the API.) As a reader, I swipe a reply whose turn had an AI-called check, and the new version shows the same check line with the same faces — no new roll — for a full and for a prose-only regenerate.
The RPG console (M5–M10):
- UC-1 (M5) As a reader with console access, I can open the RPG console, see the seeded package on the shelf, press Start, and land in the console on a Hybrid story with the sheet on screen — no pipeline choice asked. The same Start from the package's own page lands in the same place.
- UC-1b (M5) As a reader of an RPG story, I can find it again on the console shelf and continue it.
- UC-1c (release)
staff-preview: rpgAs a reader the RPG console is meant for, I can open it without being staff: the preview key is gone and the console no longer shows "isn't open yet" to anyone it serves. - UC-2 (M5) As a reader, I can open the dice tray from the composer, pick Lockpicking, press Roll now, watch the dice land, and read the line with the faces, bonus, total and outcome.
- UC-4 (M5) As a reader of a package that allows free rolls, I can type free notation (
2d6+1) in the tray; on a package that doesn't, the field isn't there. - UC-6 (M5) As a reader of an RPG package, I see an HP bar, attributes and skills with bonuses, a coin badge and condition chips in the sheet column (a pull-up tab on a phone) — the same renderers as chat — starting from the package's sheet values, and I can't edit them.
- UC-7 (M5) As a reader, I can fail a check whose skill declares
damage 1d6and see the HP bar drop by the rolled amount on that reply. - UC-16 (M5) As a reader who opens an RPG story's transcript in chat. or chat-v2, I see the event lines read-only and no dice control or sheet.
- UC-8 (M6) As a reader, I can open the bag, use a health potion, watch the heal dice, and see the potion count and HP change on the reply.
- UC-9 (M7) As a reader of a package in Game master or Both mode, with the mock director emitting
checks: [lockpicking, hard], I write "I try to pick the lock" and see the Lockpicking line and dice under my turn, and the prose prompt carries itsCheckOutcome. - UC-10 (M8) As a creator, I can open my package in the workbench, turn RPG on in its RPG step, pick a dice system and mode, add skills, items and a sheet, save, and start my own package as an RPG story.
- UC-12 (M8) As a creator, a config with a skill on an unknown attribute is refused on save with every problem listed, and nothing is saved.
- UC-17 (M10) As a reader, I can open the map from the sheet's breadcrumb, zoom from the world layer into a region and a place, see where the party is and which places are discovered, tap a destination, see its route, time, cost and encounter risk, confirm, watch the marker walk it, and see the breadcrumb, clock and rations change on the reply.
- UC-18 (M10) As a reader, I can't pick an undiscovered place or a gated route; the map says why (the bridge is out).
- UC-19 (M10) As a reader in Game master mode, with the mock director emitting
move: saltmere → gull_steps, I see the travel line and the marker move, and the prose prompt carries theTravelOutcome.
Both:
- UC-11 As a reader with reduced motion on, I get every line with no cue and no reveal hold.
Behavior:
- Every die face comes from the server; the roll endpoint and the
eventsframe carry faces the client only displays. A refresh mid-tumble shows the same faces. - A stored dice record recomputes to the same total and outcome from its faces (a test feeds faces, not RNG).
- Each system dice system resolves its tier per the tables in §1 — its sheet check and its bare check — including crits, advantage/disadvantage, bands, the tier shifts and a pool never below one die.
- A reader's correction of a chat kind (a bag count, HP) saves through the scene editor and the next eval's delta ops apply on top of the corrected value.
- A structured kind's eval output is applied as delta ops; a resource never leaves
0 … max; currency never goes below 0; a condition'sturnscounts down by one per reply. - Declared effects land on their reply's snapshot over the eval for their keys: with the eval succeeding (the eval
write applies the ops; the eval's own ops on those keys are ignored for that reply), and with the eval call failing
or timing out (prior + ops) — both under the
tracker_statelock, and only these two paths advance the catch-up watermark. - Turn N+1 with an effect while turn N's eval is still in flight: after both evals,
hpequals N's value minus the effect. - A structured value over its kind's cap is refused and logged; no item is silently dropped.
- A kind tracker wins over a free one on the same key in the story's tracker set (a package's contract
hpover a bound character's freehp). - A creator's second RPG package reuses their existing contract
hprow; a free tracker already keyedhpis refused in the RPG step with a rename prompt. - The check menu reaches the beat leg and not the prose leg, in chat and in RPG (prompt capture,
game-testingmock LLM). (Chat verified 2026-10-31; RPG is M7.) - The menu carries the check contract itself: a chat reader's own Hybrid director mode that says nothing about checks still gets the call shape and the outcome-neutral instruction in its prompt.
- (Chat verified 2026-10-31; a skill is M7.) An AI-called check with an unknown skill or tier, or a missing or over-long action, is retried once with the reason, then the beat is accepted with the checks dropped (not degraded); the reply still arrives; both rejects are logged.
- A VN turn with checks (M9) runs both guards on one retry budget: one re-run at most, one combined correction.
- A reader roll's block reaches both legs; a game-master check's block reaches the prose leg only; neither reaches any later turn's prompt.
- On a check turn the tracker eval's input carries the
CheckOutcomeline and the prose. - A labeled-text beat with a
Checks:line: the checks are read, and nothing of that line reaches the director's note or the prose prompt. A beat carrying onlychecksparses as an empty beat, never as raw JSON in the note. - An AI-called check's outcome is in the prose prompt and not the beat prompt — on the fresh turn and on a
prose-only regenerate (
ReusedBeat); the menu is in the beat prompt and not the prose prompt (prompt capture). - A reader's correction made while an eval runs and the eval's delta op on the same key both land (bag
[a], reader saves[a, b]mid-eval, eval saysadd c→[a, b, c]). - With the eval cadence Off, a condition
{poisoned, turns 2}readsturns 1after one reply; an eval over a three-reply catch-up window ticks it three times. - On Classic the
eventsframe goes out only after the last pre-stage, and the turn's embedding accounting is unchanged (PreStageEmbeddingAccountingTests' sibling). - Hidden difficulty: the line, the prompt block and the PDF name the tier, never the number. Secret rolls: the line shows no faces or total; the JSON export keeps them.
- The prose reveal is held until the dice settle or 1.6 s, whichever first; tapping reveals at once; the stream is never paused.
Invariants that must stay true (carve-outs):
- A story with dice, AI-called checks and tracker kinds off, and no RPG config, sends byte-identical prompts to today and makes the same number of model calls per turn.
- The story model never produces a number that becomes a roll, a total, a difficulty value or a state change; the director produces only a skill/item key or an action label, and a tier name.
- The tracker snapshot stays the only tracker truth: an inline edit or scene save of a free tracker re-derives the change line, events store effect ops (never resulting values), and the scene editor refuses a reader's write to a contract tracker in an RPG story — chat kinds stay correctable.
- No event is a
web_messagesrow; replies stay one row per version. - Classic gets only the reader-called primitives: no Classic story offers "The AI may call for checks", builds a
check menu or reads an RPG config, and an RPG package can't start as Classic (an explicit
isHybrid: falsestill landspipeline_type = 1). - Non-RPG packages keep the reader's pipeline choice at Start exactly as today.
- A reader has no control that changes the RPG config; the story reads its rules only from its copied config.
- Editing a package's RPG config changes no story already started from it (the copy holds); a new Start gets the new config.
- A hidden contract tracker never appears in a line, a cue, a menu, a prompt outcome block, the PDF, or a share link.
- Free trackers keep their current types, renderers and eval behaviour; binding a kind changes nothing about an existing tracker.
- Chat keeps every option the reader can set today; every chat primitive is off until the reader turns it on; chat. and chat-v2 gain no game control (sheet, item Use, map, package rules), and chat-v2 gains no dice control.
- The console reuses chat's code: the tray is chat.'s dice control, the sheet's renderers are the tracker kinds' renderers, and the check resolution and guard are M2's and M4's (no second copy in the console's tree).
- No regenerate, reply edit or message edit rolls, re-rolls or re-resolves anything; each version's snapshot applies the same recorded ops, once.
- A reader can't switch the trackers feature off on an RPG story.
Edges:
- Stop before the first token after a game-master check has rolled (its dice already shown): the check stays staged, and the next send narrates it as already resolved — no new roll.
- A published or shared page never shows a hidden tracker's change, a secret roll's faces, or anything the story's rating withholds from a protected reader.
- While the console is staff-only, a non-staff signed-in user who opens it gets the console's no-access page, and Start on an RPG package is not offered to them; the seeded package isn't listed in Browse. The chat primitives stay available to that user throughout.
- A protected (SFW-lane) reader can roll: the line comes from the stored record after the reply, with no cue; a held reader-only row stores no events and leaves the roll staged.
- A chat story whose chosen dice system the catalog no longer serves shows it as unavailable in the story's settings, offers the others, refuses new rolls until one is picked, and keeps every recorded line.
- With the platform-wide
Features.EnableTrackersoff, an RPG package's Start is refused with a message; existing RPG stories still render their recorded lines. - A synthetic exit (balance block, refusal, failure, stop before the first token) stores no turn and leaves a staged roll staged; the next send narrates the same roll.
- Branching copies stored rolls with their rows and does not copy a staged roll.
- Deleting a reply (the version shown) removes the turn's reader-row rolls; deleting a version that isn't shown keeps them; deleting the reader's message removes them.
- A dice system that fails validation is not offered in the workbench; a story whose copied config names a dice system the catalog no longer serves shows the rules as unavailable, keeps every recorded line, refuses new rolls with a message, and still chats.
- A skill removed from a package's config: stories already started keep it (their copy); old records still render their line from the record.
- An RPG package whose stored config no longer validates can't be started; its page says why.
- An effect on an unbound tracker is dropped and logged, not written.
- Notation over the bounds (101 dice, 1001 faces) is refused with a message, and nothing is rolled.
- Use item with a count of 0 is refused before anything is rolled.
- The event stream down: the roll still lands; the line appears from the message read; no cue plays late.
- Another user's conversation: the roll endpoint answers 404, the same as a missing one.
- A travel whose cost the party can't pay (2 rations, 1 held) is refused before anything rolls, with the reason.
- A game-master
moveto an undiscovered node, a gated route or a node in another tree branch with no route is rejected by the guard like a bad check (retry once, then accept with no move). - The eval never changes the Place tracker's mapped prefix (it may add rooms below it); a
revealof a place not on the map is dropped and logged. - Swiping a travel turn keeps the same path, time, cost and encounter result on every version.
- A map that fails validation can't be saved; a story whose copied map no longer validates shows the map as unavailable and still plays without travel.
- An undiscovered node's name and lore reach no prompt, line, map label or published page.