[PR #6336] [MERGED] feat(game): live ruleset sheets and the sheet command (rulesets slice 5) #7143

Closed
opened 2026-10-23 04:16:55 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/6336
Author: @kolacheee
Created: 9/18/2026
Status: ✅ Merged
Merged: 9/18/2026
Merged by: @kolacheee

Base: staging ← Head: feat/rulesets-ingame


📝 Commits (4)

  • bd89365 feat(game): keep ruleset sheets live in a game with the sheet command
  • 077a16d fix(game): make the sheet tag scan one bounded run
  • 02aee09 fix(game): address ruleset live state review findings
  • afaf61e fix(game): strip Unicode line and paragraph separators from sheet values

📊 Changes

30 files changed (+3425 additions, -38 deletions)

View changed files

📝 CHANGELOG.md (+1 -0)
📝 docs/development/game-rulesets-and-sheets-implementation.md (+20 -5)
📝 docs/game/dice-and-skill-checks.md (+1 -0)
📝 docs/game/party-and-npcs.md (+21 -0)
📝 packages/client/src/components/game/GameCharacterSheet.tsx (+48 -1)
➕ packages/client/src/components/game/GameRulesetSheet.tsx (+476 -0)
📝 packages/client/src/components/game/GameSurface.tsx (+120 -1)
📝 packages/client/src/components/game/game-narration-format.ts (+6 -1)
➕ packages/client/src/hooks/use-game-ruleset.ts (+48 -0)
📝 packages/client/src/hooks/use-game-state-patcher.ts (+3 -1)
📝 packages/client/src/lib/game-tag-parser.ts (+12 -0)
📝 packages/client/src/localization/locales/en.json (+41 -0)
📝 packages/server/src/db/schema/game-state.ts (+4 -0)
📝 packages/server/src/routes/chats.routes.ts (+27 -2)
📝 packages/server/src/routes/game.routes.ts (+6 -1)
📝 packages/server/src/routes/generate.routes.ts (+96 -3)
📝 packages/server/src/routes/generate/generate-route-utils.ts (+2 -0)
📝 packages/server/src/services/game/gm-prompts.ts (+55 -0)
➕ packages/server/src/services/game/ruleset-sheet-turn.service.ts (+136 -0)
📝 packages/server/src/services/storage/game-state.storage.ts (+26 -0)

...and 10 more files

📄 Description

Important

Contributions target staging. Only SpicyMarinara may promote this repository's staging branch or a same-repository hotfix/* branch to main.
Outside and first-time contributors also require an approving review from SpicyMarinara.

Linked issue

Part of #6314 (slice 5 of 7; it does not close the issue). Builds on #6330 (slice 4, merged).

Why this change

  • A ruleset sheet that never changes during play is only half a sheet. Hit points, spell slots, class resources, conditions and rests have to move as the story moves, the Game Master has to see them, and a swipe or a regenerated turn must not spend the same slot twice.

What changed

  • Live state rides the game-state snapshot. A new game_state_snapshots.ruleset_live column holds RulesetLiveStates, keyed by normalized card name. It is sparse: only values that were set are stored, and a value back at its default is dropped, so an untouched pool follows its maximum after a level-up. No STORAGE_VERSION bump: an old row reads the column as null, which means every pool at its default.
  • The [sheet: ...] command. The Game Master records changes with one Engine-owned tag: spend, restore (heal is read as restore), damage, temp, track, condition, note, rest. The grammar is the same for every ruleset; every pool, track, condition, note and rest name comes from the ruleset and is matched by id or label. Nothing in the code knows a 5e word. who may be left out (the player) or be party.
  • The Engine owns the arithmetic. Commands are applied after every rewrite of the reply and before it is saved, against the live state the turn STARTED with (for a continuation, the row the continued message already has). Each tag is rewritten in place with result="ok" now="…" or result="refused" reason="…". A result the model writes itself is ignored. A refused command changes nothing, is logged, and the client says so once per turn.
  • Rewind. Every saved turn of a ruleset game writes its row, changed or not. A regenerated turn resolves its base from the messages before it, so it cannot spend twice, and each swipe keeps the state it ended with. A tracker that later rebuilds the same row keeps the live state (create carries it over unless the caller passes one). A new session starts with the state the last one ended with.
  • The Game Master sees the sheets late in the prompt. The command lines, the ruleset's gm.sheetGuidance and one compact block per party member are part of the per-turn format reminder, never the system prompt, because live state changes every turn and the system prompt is what a provider caches. With no ruleset the reminder is byte-identical, and an impersonated turn gets no sheet section.
  • In-game sheet. The character sheet gains a Ruleset sheet block rendered from the definition: pools with minus, plus and a number box (and a Temp box where the pool has one), tracks, notes, condition buttons, one button per rest, a short build summary, and an Edit sheet mode that reuses the library editor on this game's copy. Every button goes through the same applyRulesetSheetOp the Game Master's commands do, and saves through PATCH /chats/:id/game-state, which bounds live state (rulesetLiveStatesSchema) and judges nothing else. An unavailable ruleset or an unreadable stored sheet shows a notice instead of something editable.
  • sheet is reserved, so a package verb with that name is refused, and [sheet:] tags are hidden from the narration.
  • Regressions: game-ruleset-live.regression.ts (the arithmetic, the tag, the prompt block, a second 2d6 ruleset with an empty-start pool to prove nothing is 5e-shaped) and game-ruleset-live-storage.regression.ts (the column, rewind, the edit route, the reminder, an unavailable pin) against a really installed package.
  • Not in this slice: party members' own turns (/party-turn) do not apply sheet commands; only the Game Master's reply does. Layers on top of a ruleset (for example Low Magic on 5e) are recorded in the plan as an open decision for the community-import slice.

Validation

  • pnpm check passes locally
  • Container (Docker / Podman) built and ran without issue
  • Ran the app, clicked through the changes manually
  • Checked edge cases (light + dark mode, mobile viewport, empty states, error paths)
  • Above manual verification completed (describe below)
  • Read and followed CONTRIBUTING.md

Manual verification notes

Commands run locally by the agent: pnpm check (exit 0), pnpm localization:check, the full node regression lane (pnpm regression:node, 305 of 305), and the two new regressions. The agent also drove a scratch server on port 7820 with the 5e package installed and a game seeded through the API (no model was connected): [sheet:] tags did not show in the narration; the sheet showed 25/32 hit points and 1/2 third-level slots from live state; the minus button saved through the route and disabled itself at zero; Long rest returned the state to nothing stored and showed a status line; live geometry at 375 px showed no overflow. Four local CodeRabbit sweeps were run before opening (two lost their connection part way and their partial findings were fixed); the last complete one returned no findings.

Still to verify by hand:

  • Manually play a real turn on 5e with a model connected: have the Game Master cast a spell, confirm the slot drops, swipe and confirm it comes back, regenerate and confirm it is spent once.
  • Manually provoke a refusal (a cast with no slot left) and confirm the notice appears once.
  • Manually use Edit sheet, raise the level, Save sheet, and confirm derived values and pool maximums follow and the library character is unchanged.
  • Manually verify a game with NO ruleset looks exactly as before (no new block, no new prompt text).
  • Manually verify light mode and a phone-width viewport.

Docs and release impact

  • No docs changes needed
  • Updated docs (README / CONTRIBUTING / android/README / CHANGELOG) as needed
  • Translated docs on the docs-i18n branch updated to match, or a [docs-i18n] follow-up issue opened (see CONTRIBUTING.md § Translated documentation)
  • Version/release files updated (only if this PR includes a version bump)

Docs touched: CHANGELOG.md, docs/game/party-and-npcs.md (new section The ruleset sheet), docs/game/dice-and-skill-checks.md, the plan. The [docs-i18n] follow-up is batched for the ruleset slices.

UI evidence (if applicable)

To be added by a human: light, dark and phone-width screenshots of the Ruleset sheet block.

Summary by CodeRabbit

  • New Features

    • Added live ruleset character sheets showing resources, tracks, notes, conditions, rests, and build details.
    • Game Masters can update sheets during play by spending, restoring, damaging, adjusting temporary values, managing conditions, adding notes, and taking rests.
    • Invalid updates are rejected with clear explanations.
    • Sheet values follow the relevant message or swipe, preventing duplicate changes.
    • Added sheet editing, read-only handling, and notices for unavailable or outdated rulesets.
  • Documentation

    • Added guidance for using ruleset sheets and live game state.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Pasta-Devs/Marinara-Engine/pull/6336 **Author:** [@kolacheee](https://github.com/kolacheee) **Created:** 9/18/2026 **Status:** ✅ Merged **Merged:** 9/18/2026 **Merged by:** [@kolacheee](https://github.com/kolacheee) **Base:** `staging` ← **Head:** `feat/rulesets-ingame` --- ### 📝 Commits (4) - [`bd89365`](https://github.com/Pasta-Devs/Marinara-Engine/commit/bd893655ea248c5cbb80fcfbe21214cb6498f325) feat(game): keep ruleset sheets live in a game with the sheet command - [`077a16d`](https://github.com/Pasta-Devs/Marinara-Engine/commit/077a16dff65ae858677b3add7444a913d2d16290) fix(game): make the sheet tag scan one bounded run - [`02aee09`](https://github.com/Pasta-Devs/Marinara-Engine/commit/02aee09c0ab359e57a309b921ce6dfd8680f51ac) fix(game): address ruleset live state review findings - [`afaf61e`](https://github.com/Pasta-Devs/Marinara-Engine/commit/afaf61ef42eee6c38390494fd330c013c02e764b) fix(game): strip Unicode line and paragraph separators from sheet values ### 📊 Changes **30 files changed** (+3425 additions, -38 deletions) <details> <summary>View changed files</summary> 📝 `CHANGELOG.md` (+1 -0) 📝 `docs/development/game-rulesets-and-sheets-implementation.md` (+20 -5) 📝 `docs/game/dice-and-skill-checks.md` (+1 -0) 📝 `docs/game/party-and-npcs.md` (+21 -0) 📝 `packages/client/src/components/game/GameCharacterSheet.tsx` (+48 -1) ➕ `packages/client/src/components/game/GameRulesetSheet.tsx` (+476 -0) 📝 `packages/client/src/components/game/GameSurface.tsx` (+120 -1) 📝 `packages/client/src/components/game/game-narration-format.ts` (+6 -1) ➕ `packages/client/src/hooks/use-game-ruleset.ts` (+48 -0) 📝 `packages/client/src/hooks/use-game-state-patcher.ts` (+3 -1) 📝 `packages/client/src/lib/game-tag-parser.ts` (+12 -0) 📝 `packages/client/src/localization/locales/en.json` (+41 -0) 📝 `packages/server/src/db/schema/game-state.ts` (+4 -0) 📝 `packages/server/src/routes/chats.routes.ts` (+27 -2) 📝 `packages/server/src/routes/game.routes.ts` (+6 -1) 📝 `packages/server/src/routes/generate.routes.ts` (+96 -3) 📝 `packages/server/src/routes/generate/generate-route-utils.ts` (+2 -0) 📝 `packages/server/src/services/game/gm-prompts.ts` (+55 -0) ➕ `packages/server/src/services/game/ruleset-sheet-turn.service.ts` (+136 -0) 📝 `packages/server/src/services/storage/game-state.storage.ts` (+26 -0) _...and 10 more files_ </details> ### 📄 Description > [!IMPORTANT] > Contributions target `staging`. Only `SpicyMarinara` may promote this repository's `staging` branch or a same-repository `hotfix/*` branch to `main`. > Outside and first-time contributors also require an approving review from `SpicyMarinara`. <!-- See CONTRIBUTING.md § Branches. --> ## Linked issue Part of #6314 (slice 5 of 7; it does not close the issue). Builds on #6330 (slice 4, merged). ## Why this change - A ruleset sheet that never changes during play is only half a sheet. Hit points, spell slots, class resources, conditions and rests have to move as the story moves, the Game Master has to see them, and a swipe or a regenerated turn must not spend the same slot twice. ## What changed - **Live state rides the game-state snapshot.** A new `game_state_snapshots.ruleset_live` column holds `RulesetLiveStates`, keyed by normalized card name. It is sparse: only values that were set are stored, and a value back at its default is dropped, so an untouched pool follows its maximum after a level-up. No `STORAGE_VERSION` bump: an old row reads the column as null, which means every pool at its default. - **The `[sheet: ...]` command.** The Game Master records changes with one Engine-owned tag: `spend`, `restore` (`heal` is read as `restore`), `damage`, `temp`, `track`, `condition`, `note`, `rest`. The grammar is the same for every ruleset; every pool, track, condition, note and rest name comes from the ruleset and is matched by id or label. Nothing in the code knows a 5e word. `who` may be left out (the player) or be `party`. - **The Engine owns the arithmetic.** Commands are applied after every rewrite of the reply and before it is saved, against the live state the turn STARTED with (for a continuation, the row the continued message already has). Each tag is rewritten in place with `result="ok" now="…"` or `result="refused" reason="…"`. A `result` the model writes itself is ignored. A refused command changes nothing, is logged, and the client says so once per turn. - **Rewind.** Every saved turn of a ruleset game writes its row, changed or not. A regenerated turn resolves its base from the messages before it, so it cannot spend twice, and each swipe keeps the state it ended with. A tracker that later rebuilds the same row keeps the live state (`create` carries it over unless the caller passes one). A new session starts with the state the last one ended with. - **The Game Master sees the sheets late in the prompt.** The command lines, the ruleset's `gm.sheetGuidance` and one compact block per party member are part of the per-turn format reminder, never the system prompt, because live state changes every turn and the system prompt is what a provider caches. With no ruleset the reminder is byte-identical, and an impersonated turn gets no sheet section. - **In-game sheet.** The character sheet gains a **Ruleset sheet** block rendered from the definition: pools with minus, plus and a number box (and a **Temp** box where the pool has one), tracks, notes, condition buttons, one button per rest, a short build summary, and an **Edit sheet** mode that reuses the library editor on this game's copy. Every button goes through the same `applyRulesetSheetOp` the Game Master's commands do, and saves through `PATCH /chats/:id/game-state`, which bounds live state (`rulesetLiveStatesSchema`) and judges nothing else. An unavailable ruleset or an unreadable stored sheet shows a notice instead of something editable. - **`sheet` is reserved**, so a package verb with that name is refused, and `[sheet:]` tags are hidden from the narration. - **Regressions:** `game-ruleset-live.regression.ts` (the arithmetic, the tag, the prompt block, a second 2d6 ruleset with an empty-start pool to prove nothing is 5e-shaped) and `game-ruleset-live-storage.regression.ts` (the column, rewind, the edit route, the reminder, an unavailable pin) against a really installed package. - **Not in this slice:** party members' own turns (`/party-turn`) do not apply sheet commands; only the Game Master's reply does. Layers on top of a ruleset (for example Low Magic on 5e) are recorded in the plan as an open decision for the community-import slice. ## Validation - [ ] `pnpm check` passes locally - [ ] Container (Docker / Podman) built and ran without issue - [ ] Ran the app, clicked through the changes manually - [ ] Checked edge cases (light + dark mode, mobile viewport, empty states, error paths) - [ ] Above manual verification completed (describe below) - [ ] Read and followed `CONTRIBUTING.md` ### Manual verification notes Commands run locally by the agent: `pnpm check` (exit 0), `pnpm localization:check`, the full node regression lane (`pnpm regression:node`, 305 of 305), and the two new regressions. The agent also drove a scratch server on port 7820 with the 5e package installed and a game seeded through the API (no model was connected): `[sheet:]` tags did not show in the narration; the sheet showed 25/32 hit points and 1/2 third-level slots from live state; the minus button saved through the route and disabled itself at zero; **Long rest** returned the state to nothing stored and showed a status line; live geometry at 375 px showed no overflow. Four local CodeRabbit sweeps were run before opening (two lost their connection part way and their partial findings were fixed); the last complete one returned no findings. Still to verify by hand: - Manually play a real turn on 5e with a model connected: have the Game Master cast a spell, confirm the slot drops, swipe and confirm it comes back, regenerate and confirm it is spent once. - Manually provoke a refusal (a cast with no slot left) and confirm the notice appears once. - Manually use **Edit sheet**, raise the level, **Save sheet**, and confirm derived values and pool maximums follow and the library character is unchanged. - Manually verify a game with NO ruleset looks exactly as before (no new block, no new prompt text). - Manually verify light mode and a phone-width viewport. ## Docs and release impact - [ ] No docs changes needed - [ ] Updated docs (README / CONTRIBUTING / android/README / CHANGELOG) as needed - [ ] Translated docs on the `docs-i18n` branch updated to match, or a `[docs-i18n]` follow-up issue opened (see CONTRIBUTING.md § Translated documentation) - [ ] Version/release files updated (only if this PR includes a version bump) Docs touched: `CHANGELOG.md`, `docs/game/party-and-npcs.md` (new section **The ruleset sheet**), `docs/game/dice-and-skill-checks.md`, the plan. The `[docs-i18n]` follow-up is batched for the ruleset slices. ## UI evidence (if applicable) To be added by a human: light, dark and phone-width screenshots of the **Ruleset sheet** block. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Added live ruleset character sheets showing resources, tracks, notes, conditions, rests, and build details. - Game Masters can update sheets during play by spending, restoring, damaging, adjusting temporary values, managing conditions, adding notes, and taking rests. - Invalid updates are rejected with clear explanations. - Sheet values follow the relevant message or swipe, preventing duplicate changes. - Added sheet editing, read-only handling, and notices for unavailable or outdated rulesets. - **Documentation** - Added guidance for using ruleset sheets and live game state. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-23 04:16:55 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Pasta-Devs/Marinara-Engine#7143
No description provided.