[PR #7766] [MERGED] feat(game): Game data in the State Editor (#7743, slices 1-2) #7918

Closed
opened 2026-10-24 04:08:49 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/7766
Author: @ylli-selmani
Created: 10/17/2026
Status: ✅ Merged
Merged: 10/17/2026
Merged by: @ylli-selmani

Base: staging ← Head: feat/game-data-state-editor


📝 Commits (5)

  • 0b00f97 feat(game): read-only Game data view in the State Editor (#7743 slice 1)
  • 3fa87f8 feat(game): save hand edits of game data through a checked route (#7743 slice 2)
  • f4f3281 fix(game): keep ruleset sheets and party NPCs in game data edits (#7743)
  • 5225254 fix(game): a saved game data edit stays saved when reading it back fails (#7743)
  • bf67ac4 fix(game): clear the Game data editor's notice once a save lands (#7743)

📊 Changes

16 files changed (+1439 additions, -27 deletions)

View changed files

📝 packages/client/src/components/game/GameSurface.tsx (+8 -0)
📝 packages/client/src/components/layout/ModalRenderer.tsx (+6 -0)
➕ packages/client/src/components/modals/GameDataEditorModal.tsx (+234 -0)
📝 packages/client/src/components/ui/state-editor/StateEditor.tsx (+22 -5)
📝 packages/client/src/components/ui/state-editor/StateFieldsView.tsx (+28 -20)
📝 packages/client/src/components/ui/state-editor/StateJsonField.tsx (+4 -0)
➕ packages/client/src/lib/state-editor/game-data-editor-source.ts (+197 -0)
📝 packages/client/src/lib/state-editor/state-editor-json.ts (+1 -0)
📝 packages/client/src/lib/state-editor/state-editor.types.ts (+2 -0)
📝 packages/client/src/localization/locales/en.json (+82 -2)
📝 packages/server/src/routes/game.routes.ts (+47 -0)
➕ packages/server/src/services/game/game-data-edit.service.ts (+293 -0)
📝 packages/shared/src/index.ts (+1 -0)
➕ packages/shared/src/utils/game-data-edit.ts (+95 -0)
➕ scripts/regressions/game-data-edit.regression.ts (+309 -0)
📝 scripts/regressions/state-editor.regression.ts (+110 -0)

📄 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 #7743 (slices 1 and 2). Slices 3 to 6 (inventory, world, story script / party sheet / widgets, checkpoint + Load) come in a second PR, which closes the issue.

Why this change

Game Mode keeps most of its state in chat metadata: the party's cards, NPCs, journal, story, maps. When the model gets one of them wrong (an NPC with the wrong reputation, a quest stuck open), there's no screen to fix it. The only generic writer, PATCH /api/chats/:id/metadata, merges any key unchecked and replaces lists like gameNpcs wholesale, so it can quietly undo a turn that landed in between.

What changed

  • Game controls → Edit game data opens the State Editor on the game's own data, grouped into sections: Party Cards, NPCs, Journal, Player Notes, Story, Session Summaries, Maps & Position, Session, Ids & Links, and so on. A warning at the top says hand edits can break a game.
  • Editable: Party Cards, NPCs, Journal, Player Notes, Story (world overview, story arc, plot twists, party arcs) and Session Summaries. They save through a new PATCH /api/game/:chatId/data, never the generic metadata PATCH.
    • Only keys on an allow-list (GAME_DATA_EDITABLE_KEYS in shared) are accepted. New Game Mode keys stay read-only until someone adds them on purpose.
    • Each key has its own check:
      • Names can't change. Cards, NPCs, the party, live sheets and bags find each other by name (normalizeCharacterLookupName). Party cards and arcs can't be added or removed.
      • NPCs keep their ids. Reputation is clamped to -100..100. An NPC who joined the party can't be removed.
      • Ruleset sheets. A changed ruleset sheet is read through the game's pinned ruleset (readRulesetSheetEnvelope). A sheet can't be removed.
      • Session summaries change only in their text. Their number, timestamp and stats snapshot stay as the session left them.
      • Limits. Text and list lengths, plus 256 KB per key.
    • Staleness per key: the editor sends the value it opened with. If any key changed since (a turn landed meanwhile), the whole save is refused with 409 and the editor offers a Reload. One refused key refuses the whole save, so nothing lands half-checked. The write goes through the metadata queue (patchMetadata updater).
    • Refusals come back as reason codes, which the client shows in the user's language.
  • Read-only, still shown and searchable: inventory, world, story script, party sheet and HUD widgets (their own routes, in the second PR); maps, time and weather, combat, loot, session and ids (rebuilt or kept by the game); and any other game* key, under Settings or Other, so data from future Game Mode work is never hidden.
  • Narrower than the issue: setup preferences (gameSetupConfig) and prompt and media settings stay editable only in Chat Settings, which already edits them. That leaves one save path per key.
  • The State Editor gained read-only sections (a lock in the list, a Read-only badge, tinted fields). Its search hint now says "Select one to open it" instead of "to edit it".

Commits

  • 0b00f9746 slice 1: read-only Game data view in the State Editor
  • 3fa87f86f slice 2: save hand edits of game data through a checked route
  • f4f3281fa keep ruleset sheets and party NPCs; shorter warning (local CodeRabbit)

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

Ran on f4f3281fa: pnpm check passes. The only lint warning is HomeProfessorMariChat.tsx:380, which is already on staging. Regressions: game-data-edit (new), state-editor, open-issues and assigned-issue-sweep pass. On 3fa87f86f, every capability-* regression (19/19) and every game-* regression (307/307) also passed. Negative controls: removing the read-only guard or the NPC rename check makes the regressions fail. Local CodeRabbit found 3 minor issues, all handled in f4f3281fa. The one partly declined: the stale notice keeps the game-state editor's wording.

Manual verification notes

Checked in the browser (dark, default theme) on a seeded test game:

  • desktop, and a phone at 375 px (••• → Game controls → Edit game data);
  • search across sections;
  • read-only sections;
  • editing an NPC's reputation and saving it (stored value checked);
  • a rename, refused with the message shown under the diff;
  • a stale save: the game changed an NPC while the editor was open, so the save is refused, the game's change is kept, and Reload shows it.

Still to do by hand:

  • Light mode and the SillyTavern theme.
  • A game with a real ruleset: edit a party card's ruleset sheet and save.
  • A game whose party includes an NPC: try to remove that NPC.

Docs and release impact

  • No docs changes needed
  • Updated docs (README / CONTRIBUTING / android/README) 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)

The second PR updates docs/game/sessions-and-saves.md with the Load checkpoint button and opens the [docs-i18n] follow-up.

UI evidence (if applicable)

Game controls → Edit game data:

Edit game data in Game controls

Search across game data (taken in slice 1, when every section was still read-only):

Search across sections

A rename refused in review (taken before the warning was shortened):

Rename refused

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features
    • Added a Game Controls option to view and edit game metadata for the active chat.
    • Metadata is organized into sections, with protected sections clearly marked as read-only.
    • The editor validates changes before saving and reports invalid edits or conflicts.
    • After a successful save, the editor refreshes the metadata and confirms the update.
    • Closing with unsaved changes prompts for confirmation; metadata can be reloaded if it becomes outdated or fails to load.

🔄 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/7766 **Author:** [@ylli-selmani](https://github.com/ylli-selmani) **Created:** 10/17/2026 **Status:** ✅ Merged **Merged:** 10/17/2026 **Merged by:** [@ylli-selmani](https://github.com/ylli-selmani) **Base:** `staging` ← **Head:** `feat/game-data-state-editor` --- ### 📝 Commits (5) - [`0b00f97`](https://github.com/Pasta-Devs/Marinara-Engine/commit/0b00f97463b7db797cc2efcf50d6e2fb512bd1e9) feat(game): read-only Game data view in the State Editor (#7743 slice 1) - [`3fa87f8`](https://github.com/Pasta-Devs/Marinara-Engine/commit/3fa87f86f8085437716cca6ed02bb5eeeb9ec227) feat(game): save hand edits of game data through a checked route (#7743 slice 2) - [`f4f3281`](https://github.com/Pasta-Devs/Marinara-Engine/commit/f4f3281fad49f468563b53ed65ba3896af485a89) fix(game): keep ruleset sheets and party NPCs in game data edits (#7743) - [`5225254`](https://github.com/Pasta-Devs/Marinara-Engine/commit/5225254f1a9526b81b9a42c260a5b30b6d2fff2e) fix(game): a saved game data edit stays saved when reading it back fails (#7743) - [`bf67ac4`](https://github.com/Pasta-Devs/Marinara-Engine/commit/bf67ac4ab017f69aef4d9d3f5d59e1a660631dbe) fix(game): clear the Game data editor's notice once a save lands (#7743) ### 📊 Changes **16 files changed** (+1439 additions, -27 deletions) <details> <summary>View changed files</summary> 📝 `packages/client/src/components/game/GameSurface.tsx` (+8 -0) 📝 `packages/client/src/components/layout/ModalRenderer.tsx` (+6 -0) ➕ `packages/client/src/components/modals/GameDataEditorModal.tsx` (+234 -0) 📝 `packages/client/src/components/ui/state-editor/StateEditor.tsx` (+22 -5) 📝 `packages/client/src/components/ui/state-editor/StateFieldsView.tsx` (+28 -20) 📝 `packages/client/src/components/ui/state-editor/StateJsonField.tsx` (+4 -0) ➕ `packages/client/src/lib/state-editor/game-data-editor-source.ts` (+197 -0) 📝 `packages/client/src/lib/state-editor/state-editor-json.ts` (+1 -0) 📝 `packages/client/src/lib/state-editor/state-editor.types.ts` (+2 -0) 📝 `packages/client/src/localization/locales/en.json` (+82 -2) 📝 `packages/server/src/routes/game.routes.ts` (+47 -0) ➕ `packages/server/src/services/game/game-data-edit.service.ts` (+293 -0) 📝 `packages/shared/src/index.ts` (+1 -0) ➕ `packages/shared/src/utils/game-data-edit.ts` (+95 -0) ➕ `scripts/regressions/game-data-edit.regression.ts` (+309 -0) 📝 `scripts/regressions/state-editor.regression.ts` (+110 -0) </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`. ## Linked issue Part of #7743 (slices 1 and 2). Slices 3 to 6 (inventory, world, story script / party sheet / widgets, checkpoint + Load) come in a second PR, which closes the issue. ## Why this change Game Mode keeps most of its state in chat metadata: the party's cards, NPCs, journal, story, maps. When the model gets one of them wrong (an NPC with the wrong reputation, a quest stuck open), there's no screen to fix it. The only generic writer, `PATCH /api/chats/:id/metadata`, merges any key unchecked and replaces lists like `gameNpcs` wholesale, so it can quietly undo a turn that landed in between. ## What changed - **Game controls → Edit game data** opens the State Editor on the game's own data, grouped into sections: Party Cards, NPCs, Journal, Player Notes, Story, Session Summaries, Maps & Position, Session, Ids & Links, and so on. A warning at the top says hand edits can break a game. - **Editable:** Party Cards, NPCs, Journal, Player Notes, Story (world overview, story arc, plot twists, party arcs) and Session Summaries. They save through a new **`PATCH /api/game/:chatId/data`**, never the generic metadata PATCH. - Only keys on an allow-list (`GAME_DATA_EDITABLE_KEYS` in shared) are accepted. New Game Mode keys stay read-only until someone adds them on purpose. - Each key has its own check: - **Names can't change.** Cards, NPCs, the party, live sheets and bags find each other by name (`normalizeCharacterLookupName`). Party cards and arcs can't be added or removed. - **NPCs keep their ids.** Reputation is clamped to -100..100. An NPC who joined the party can't be removed. - **Ruleset sheets.** A changed ruleset sheet is read through the game's pinned ruleset (`readRulesetSheetEnvelope`). A sheet can't be removed. - **Session summaries change only in their text.** Their number, timestamp and stats snapshot stay as the session left them. - **Limits.** Text and list lengths, plus 256 KB per key. - **Staleness per key:** the editor sends the value it opened with. If any key changed since (a turn landed meanwhile), the whole save is refused with 409 and the editor offers a Reload. One refused key refuses the whole save, so nothing lands half-checked. The write goes through the metadata queue (`patchMetadata` updater). - Refusals come back as reason codes, which the client shows in the user's language. - **Read-only, still shown and searchable:** inventory, world, story script, party sheet and HUD widgets (their own routes, in the second PR); maps, time and weather, combat, loot, session and ids (rebuilt or kept by the game); and any other `game*` key, under Settings or Other, so data from future Game Mode work is never hidden. - **Narrower than the issue:** setup preferences (`gameSetupConfig`) and prompt and media settings stay editable only in Chat Settings, which already edits them. That leaves one save path per key. - The State Editor gained read-only sections (a lock in the list, a Read-only badge, tinted fields). Its search hint now says "Select one to open it" instead of "to edit it". ### Commits - [x] `0b00f9746` slice 1: read-only Game data view in the State Editor - [x] `3fa87f86f` slice 2: save hand edits of game data through a checked route - [x] `f4f3281fa` keep ruleset sheets and party NPCs; shorter warning (local CodeRabbit) ## 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` Ran on `f4f3281fa`: `pnpm check` passes. The only lint warning is `HomeProfessorMariChat.tsx:380`, which is already on staging. Regressions: `game-data-edit` (new), `state-editor`, `open-issues` and `assigned-issue-sweep` pass. On `3fa87f86f`, every `capability-*` regression (19/19) and every `game-*` regression (307/307) also passed. Negative controls: removing the read-only guard or the NPC rename check makes the regressions fail. Local CodeRabbit found 3 minor issues, all handled in `f4f3281fa`. The one partly declined: the stale notice keeps the game-state editor's wording. ### Manual verification notes Checked in the browser (dark, default theme) on a seeded test game: - desktop, and a phone at 375 px (••• → Game controls → Edit game data); - search across sections; - read-only sections; - editing an NPC's reputation and saving it (stored value checked); - a rename, refused with the message shown under the diff; - a stale save: the game changed an NPC while the editor was open, so the save is refused, the game's change is kept, and Reload shows it. Still to do by hand: - [ ] Light mode and the SillyTavern theme. - [ ] A game with a real ruleset: edit a party card's ruleset sheet and save. - [ ] A game whose party includes an NPC: try to remove that NPC. ## Docs and release impact - [ ] No docs changes needed - [ ] Updated docs (README / CONTRIBUTING / android/README) 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) The second PR updates `docs/game/sessions-and-saves.md` with the Load checkpoint button and opens the `[docs-i18n]` follow-up. ## UI evidence (if applicable) Game controls → Edit game data: ![Edit game data in Game controls](https://raw.githubusercontent.com/ylli-selmani/Marinara-Engine-Ylli-Edits/pr-assets/state-editor/10a-game-controls-entry.jpg) Search across game data (taken in slice 1, when every section was still read-only): ![Search across sections](https://raw.githubusercontent.com/ylli-selmani/Marinara-Engine-Ylli-Edits/pr-assets/state-editor/10b-game-data-search.jpg) A rename refused in review (taken before the warning was shortened): ![Rename refused](https://raw.githubusercontent.com/ylli-selmani/Marinara-Engine-Ylli-Edits/pr-assets/state-editor/11a-game-data-rename-refused.jpg) 🤖 Generated with [Claude Code](https://claude.com/claude-code) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Added a Game Controls option to view and edit game metadata for the active chat. * Metadata is organized into sections, with protected sections clearly marked as read-only. * The editor validates changes before saving and reports invalid edits or conflicts. * After a successful save, the editor refreshes the metadata and confirms the update. * Closing with unsaved changes prompts for confirmation; metadata can be reloaded if it becomes outdated or fails to load. <!-- 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-24 04:08:49 +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#7918
No description provided.