[GH-ISSUE #7743] [Feature]: Edit Game Mode data in the State Editor #4273

Closed
opened 2026-10-21 06:13:57 +07:00 by bsakaguchi · 0 comments
Owner

Originally created by @ylli-selmani on GitHub (Oct 16, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/7743

Originally assigned to: @ylli-selmani on GitHub.

What problem does this solve?

The State Editor (#7736, shipped in #7737 and #7739) fixes roleplay tracker data and chat variables. Game Mode keeps most of its state elsewhere, in chat metadata: the party's character cards, NPCs, journal and quests, inventory stacks, story, world. When the model gets one of these wrong (an NPC with the wrong reputation, a quest stuck open, a duplicated item), there's no screen to fix it.

The only generic way to write those keys today is PATCH /api/chats/:id/metadata. It merges any key with no checks and replaces arrays like gameNpcs or gameCharacterCards with the client's copy, so it can quietly undo a turn that landed in between. It shouldn't be used for this.

Proposed solution

A Game data source for the State Editor, shown in Game Mode chats, with a clear warning that hand edits can break a game. The plan follows kolacheee's review of what is safe to edit and how.

Editable, through one new validating route. A new server route saves only keys on an allow-list (so new keys from upcoming Game Mode work stay locked until they're added on purpose). Each key gets its own check, and the write goes through the chat metadata queue. A server-side staleness check refuses a save when a key changed since the editor opened it.

  • gameCharacterCards (each rulesetSheet through readRulesetSheetEnvelope)
  • gameNpcs (id kept, reputation clamped to -100..100)
  • Journal notes and quests, gamePlayerNotes
  • gameWorldOverview, gameStoryArc, gamePlotTwists, gamePartyArcs
  • The text of gamePreviousSessionSummaries
  • The preference fields of gameSetupConfig, and the prompt and media settings

Names. Cards, NPCs, party ids, live sheet state (rulesetLive) and bag holders all match on the normalized character name. The first version refuses renames, with a message saying why.

Saved through the routes that already check them:

  • Inventory: the editor diffs old against new and sends ops to POST /api/game/inventory (add, take, set, rename, give, equip, …). That route checks the item book, writes the journal and updates the turn in one queued transaction. Never through playerStats.inventory in the game-state PATCH, which only writes the turn's tracker copy.
  • World: the edits layer from #7473, read with GET /api/game/:chatId/world/edit and saved with PUT /api/game/:chatId/world/edits (schema, issue and story checks, snapshot re-save). gameWorld itself is never written.
  • Story via PUT /:chatId/story, party sheet via the party sheet service (revision check, 409 when stale), HUD widgets via PUT /:chatId/widgets.

Read-only sections (shown so you can see and search them, never saved):

  • Rebuilt by the server: gameJournal as reconciled on read, gameMap/gameMaps/activeGameMapId and party position, dungeon walk keys, gameTime, gameWeather, gameMorale, scene and music caches, gameInventoryTurn.
  • Bookkeeping: ids and pins (gameId, linked chat ids, gameRuleset, gameExperienceId, gameStyle, gameIntro, gameWorldKit, gameMapPack, gameInitialSetup, gamePartyCharacterIds), lifecycle keys, gamePartySheetRevision, gameRulesetAdvancementBase, gameInventedItems, gameLootedFights, gameStartingGearTaken, live combat (gameCombatState, gameTacticalCombatSnapshot), metadataWriteOrdinals.

Undo: saving creates a checkpoint first. That only works once checkpoints also save the game's metadata (#7742), so that lands first. A Load checkpoint button comes with this feature, since the client has none yet.

Character and party sheet saving stays open to players, as it is in play. It isn't put behind admin-only.

Planned slices (commits, listed with hashes in each PR body):

  1. Read-only Game data view: every key above as a section, plus read-only section support in the editor.
  2. The validating route and the editable allow-list sections, with the warning.
  3. Inventory through ops.
  4. World edits layer.
  5. Story, party sheet and widgets through their routes.
  6. Checkpoint before save, and Load checkpoint (needs #7742).

Alternatives considered

  • Write through PATCH /api/chats/:id/metadata. No checks, and arrays replace wholesale, so it can undo a turn that landed meanwhile.
  • A deny-list of keys not to touch. Every new Game Mode key would become editable by default. An allow-list ages better.
  • Edit playerStats.inventory in the game-state PATCH. In Game Mode that copy drifts from the real stacks in metadata.gameInventory.

Additional context

  • Scope and safety reviewed with kolacheee, who has no in-app editor planned for these routes.
  • Inspired by Voyage's state editor, which shows the whole game state with a big warning.
  • Follow-up to #7736 (State Editor). Prerequisite: #7742.

Template check

  • I DID NOT read this template and provide the requested details.
Originally created by @ylli-selmani on GitHub (Oct 16, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/7743 Originally assigned to: @ylli-selmani on GitHub. ## What problem does this solve? The State Editor (#7736, shipped in #7737 and #7739) fixes roleplay tracker data and chat variables. Game Mode keeps most of its state elsewhere, in chat metadata: the party's character cards, NPCs, journal and quests, inventory stacks, story, world. When the model gets one of these wrong (an NPC with the wrong reputation, a quest stuck open, a duplicated item), there's no screen to fix it. The only generic way to write those keys today is `PATCH /api/chats/:id/metadata`. It merges any key with no checks and replaces arrays like `gameNpcs` or `gameCharacterCards` with the client's copy, so it can quietly undo a turn that landed in between. It shouldn't be used for this. ## Proposed solution A **Game data** source for the State Editor, shown in Game Mode chats, with a clear warning that hand edits can break a game. The plan follows kolacheee's review of what is safe to edit and how. **Editable, through one new validating route.** A new server route saves only keys on an **allow-list** (so new keys from upcoming Game Mode work stay locked until they're added on purpose). Each key gets its own check, and the write goes through the chat metadata queue. A server-side staleness check refuses a save when a key changed since the editor opened it. - `gameCharacterCards` (each `rulesetSheet` through `readRulesetSheetEnvelope`) - `gameNpcs` (`id` kept, reputation clamped to -100..100) - Journal notes and quests, `gamePlayerNotes` - `gameWorldOverview`, `gameStoryArc`, `gamePlotTwists`, `gamePartyArcs` - The text of `gamePreviousSessionSummaries` - The preference fields of `gameSetupConfig`, and the prompt and media settings **Names.** Cards, NPCs, party ids, live sheet state (`rulesetLive`) and bag holders all match on the normalized character name. The first version refuses renames, with a message saying why. **Saved through the routes that already check them:** - **Inventory:** the editor diffs old against new and sends ops to `POST /api/game/inventory` (`add`, `take`, `set`, `rename`, `give`, `equip`, …). That route checks the item book, writes the journal and updates the turn in one queued transaction. Never through `playerStats.inventory` in the game-state PATCH, which only writes the turn's tracker copy. - **World:** the edits layer from #7473, read with `GET /api/game/:chatId/world/edit` and saved with `PUT /api/game/:chatId/world/edits` (schema, issue and story checks, snapshot re-save). `gameWorld` itself is never written. - **Story** via `PUT /:chatId/story`, **party sheet** via the party sheet service (revision check, 409 when stale), **HUD widgets** via `PUT /:chatId/widgets`. **Read-only sections** (shown so you can see and search them, never saved): - Rebuilt by the server: `gameJournal` as reconciled on read, `gameMap`/`gameMaps`/`activeGameMapId` and party position, dungeon walk keys, `gameTime`, `gameWeather`, `gameMorale`, scene and music caches, `gameInventoryTurn`. - Bookkeeping: ids and pins (`gameId`, linked chat ids, `gameRuleset`, `gameExperienceId`, `gameStyle`, `gameIntro`, `gameWorldKit`, `gameMapPack`, `gameInitialSetup`, `gamePartyCharacterIds`), lifecycle keys, `gamePartySheetRevision`, `gameRulesetAdvancementBase`, `gameInventedItems`, `gameLootedFights`, `gameStartingGearTaken`, live combat (`gameCombatState`, `gameTacticalCombatSnapshot`), `metadataWriteOrdinals`. **Undo:** saving creates a checkpoint first. That only works once checkpoints also save the game's metadata (#7742), so that lands first. A **Load checkpoint** button comes with this feature, since the client has none yet. Character and party sheet saving stays open to players, as it is in play. It isn't put behind admin-only. **Planned slices** (commits, listed with hashes in each PR body): 1. Read-only Game data view: every key above as a section, plus read-only section support in the editor. 2. The validating route and the editable allow-list sections, with the warning. 3. Inventory through ops. 4. World edits layer. 5. Story, party sheet and widgets through their routes. 6. Checkpoint before save, and Load checkpoint (needs #7742). ## Alternatives considered - **Write through `PATCH /api/chats/:id/metadata`.** No checks, and arrays replace wholesale, so it can undo a turn that landed meanwhile. - **A deny-list of keys not to touch.** Every new Game Mode key would become editable by default. An allow-list ages better. - **Edit `playerStats.inventory` in the game-state PATCH.** In Game Mode that copy drifts from the real stacks in `metadata.gameInventory`. ## Additional context - Scope and safety reviewed with kolacheee, who has no in-app editor planned for these routes. - Inspired by Voyage's state editor, which shows the whole game state with a big warning. - Follow-up to #7736 (State Editor). Prerequisite: #7742. ## Template check - [ ] I DID NOT read this template and provide the requested details.
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#4273
No description provided.