[PR #3126] [MERGED] feat(turn-games): add chess as the second conversation-mode table game #5809

Closed
opened 2026-10-22 04:19:42 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/3126
Author: @Romuromylus
Created: 7/2/2026
Status: ✅ Merged
Merged: 7/2/2026
Merged by: @SpicyMarinara

Base: staging ← Head: feat/turn-games-chess


📝 Commits (7)

  • 62fe8d5 feat(turn-games): add chess playable in conversation mode
  • 498e4fe fix(client): guard board stores by gameType across the turn-game surface
  • 7519ef6 fix(client): close game setup modals when a game starts underneath them
  • 5db006e fix(client): unstick game setup modals left mounted after auto-close
  • 6f1f450 refactor(turn-games): harden seat-ref resolver and drop dead chess field
  • 4093ac8 fix(client): let game setup modals reopen after a finished game
  • 80ea8ab fix(client): recover turn-game boards from patches dropped in background chats

📊 Changes

28 files changed (+1734 additions, -34 deletions)

View changed files

📝 packages/client/src/components/chat/ChatSettingsDrawer.tsx (+5 -0)
📝 packages/client/src/components/chat/ChatSetupWizard.tsx (+1 -0)
➕ packages/client/src/components/chat/ChessBoard.tsx (+424 -0)
➕ packages/client/src/components/chat/ChessSetup.tsx (+148 -0)
📝 packages/client/src/components/chat/ConversationInput.tsx (+8 -2)
📝 packages/client/src/components/chat/ConversationView.tsx (+18 -7)
📝 packages/client/src/components/chat/UnoSetup.tsx (+11 -1)
📝 packages/client/src/components/ui/Modal.tsx (+13 -0)
➕ packages/client/src/hooks/turn-game-keys.ts (+12 -0)
➕ packages/client/src/hooks/use-chess.ts (+137 -0)
📝 packages/client/src/hooks/use-generate.ts (+40 -4)
📝 packages/client/src/hooks/use-uno.ts (+14 -10)
📝 packages/client/src/lib/slash-commands.ts (+14 -0)
➕ packages/client/src/stores/chess-game.store.ts (+36 -0)
📝 packages/server/src/routes/generate.routes.ts (+61 -6)
📝 packages/server/src/services/conversation/character-commands.ts (+16 -0)
📝 packages/server/src/services/turn-games/turn-game-bot-runner.service.ts (+2 -2)
📝 packages/shared/package.json (+1 -0)
📝 packages/shared/scripts/generate-feature-registries.mjs (+1 -1)
➕ packages/shared/src/features/turn-games/chess/engine.manifest.ts (+5 -0)

...and 8 more files

📄 Description

Linked issue

Closes #

No pre-existing tracking issue. Happy to open a feature request for the record if maintainers want one linked.

Why this change

  • The turn-game framework we shipped with UNO (#2721) made a promise: adding a new game should be one folder under packages/shared/src/features/turn-games/<game>/ implementing TurnGameEngine, plus a per-game client surface, with the server runner, REST routes, SSE, and persistence all staying game-agnostic. Chess is the first game built against that contract, so it doubles as a real test of whether the abstraction holds.
  • It held: the server needed zero framework changes to run chess. The only server edits are the [chess] conversation command wiring, which mirrors [uno] exactly.
  • For players, this adds a second table game to conversation mode: a one-on-one chess match against a character, who talks at the table while the system runs the board.

What changed

  • Shared chess engine (packages/shared/src/features/turn-games/chess/) implementing TurnGameEngine. Moves are SAN, validated by chess.js; the LLM proposes a move via a single chess_move tool and the engine falls back to a deterministic legal move if the model stalls or proposes something illegal, so a game can never wedge. applyMove never throws. Auto-draws (stalemate, insufficient material, threefold repetition, fifty-move) are detected from move history; there is no draw-offer handshake in this version (noted under scope below).
  • chess.js dependency added to packages/shared only. Server and client resolve it transitively through shared and never import it directly.
  • [chess] conversation command, mirroring [uno]: server dispatch, a natural-language launcher, a /chess slash command, and a settings toggle. A character that includes [chess] takes the opposing seat; the system runs the board.
  • Client board surface: ChessBoard (hand-authored inline SVG pieces, click-to-move, promotion picker, board flip when the human plays black, check / last-move highlights, captured-piece rows), a ChessSetup modal (pick one opponent, choose colour), a dedicated store, and a use-chess hook over the existing game-agnostic /turn-games REST surface.
  • Turn-game framework robustness fixes found while reviewing this work, several of which also affect UNO and are fixed for both games: guard the board stores by gameType so one game's view can never paint another's board; fix setup-modal lifecycle so a modal auto-closes when a game starts underneath it but can still be reopened for a rematch after a finished game; and recover a board when a state patch arrives while the chat is backgrounded (previously the board could get stuck on switch-back until resign or reload).

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

  • pnpm check passes (TypeScript + ESLint across all three packages). Local engine + runner tests pass: engine conformance is fuzzed against a fresh chess.js oracle, and the bot-runner path is pinned to confirm the legal-move list is injected into the model prompt. (Those tests are local-only and not part of this diff, matching how the UNO suite is kept.)
  • The production container builds and boots healthy; the built bundle serves the chess client surface.
  • In-browser pass against a live model:
    • /chess setup modal, board render, click-to-move with legal-target dots.
    • A real game against a character: legal SAN moves land with in-character narration, castling resolves, and moves persist across a reload.
    • Board flips correctly when the human plays black, and the bot plays the opening move when it draws white.
    • Promotion picker, resign (X clears the board and ends the game), and the [chess] acceptance gate (only the agreeing character is seated).
    • Free-chat spectator awareness: a non-seated character can talk about the live game.
    • UNO regression: started a game after chess and played several turns — the shared SSE dispatch and the store/modal fixes behave correctly for both games. Scene banner is suppressed during an active game.

Docs and release impact

  • No docs changes needed
  • Updated docs (README / CONTRIBUTING / android/README / CHANGELOG) as needed
  • Version/release files updated (only if this PR includes a version bump)

Scope / follow-ups

  • v1 supports auto-draws only; a draw offer/accept handshake is a natural follow-up.
  • A pre-existing framework race (a mount-time hydration fetch can briefly lose to an in-flight SSE patch on the singleton board stores) is noted for a separate change; it predates this branch and is not a chess regression.

🔄 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/3126 **Author:** [@Romuromylus](https://github.com/Romuromylus) **Created:** 7/2/2026 **Status:** ✅ Merged **Merged:** 7/2/2026 **Merged by:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Base:** `staging` ← **Head:** `feat/turn-games-chess` --- ### 📝 Commits (7) - [`62fe8d5`](https://github.com/Pasta-Devs/Marinara-Engine/commit/62fe8d5010adc211054e680906a8b033ac63432b) feat(turn-games): add chess playable in conversation mode - [`498e4fe`](https://github.com/Pasta-Devs/Marinara-Engine/commit/498e4feb32ce3cbd3293a98af9444a0294ea3e45) fix(client): guard board stores by gameType across the turn-game surface - [`7519ef6`](https://github.com/Pasta-Devs/Marinara-Engine/commit/7519ef650838e20b9ddc7afd35e2d6d901455e0d) fix(client): close game setup modals when a game starts underneath them - [`5db006e`](https://github.com/Pasta-Devs/Marinara-Engine/commit/5db006e8af491fe51900bb66027938b3b7bc8dfc) fix(client): unstick game setup modals left mounted after auto-close - [`6f1f450`](https://github.com/Pasta-Devs/Marinara-Engine/commit/6f1f4502d2246a54f31a9442098d50828bd6d809) refactor(turn-games): harden seat-ref resolver and drop dead chess field - [`4093ac8`](https://github.com/Pasta-Devs/Marinara-Engine/commit/4093ac8db27b8e4c52a7275d922d9cc9ed71b066) fix(client): let game setup modals reopen after a finished game - [`80ea8ab`](https://github.com/Pasta-Devs/Marinara-Engine/commit/80ea8abc0ea6ffb6ad80cf1201e6d4166a981e3d) fix(client): recover turn-game boards from patches dropped in background chats ### 📊 Changes **28 files changed** (+1734 additions, -34 deletions) <details> <summary>View changed files</summary> 📝 `packages/client/src/components/chat/ChatSettingsDrawer.tsx` (+5 -0) 📝 `packages/client/src/components/chat/ChatSetupWizard.tsx` (+1 -0) ➕ `packages/client/src/components/chat/ChessBoard.tsx` (+424 -0) ➕ `packages/client/src/components/chat/ChessSetup.tsx` (+148 -0) 📝 `packages/client/src/components/chat/ConversationInput.tsx` (+8 -2) 📝 `packages/client/src/components/chat/ConversationView.tsx` (+18 -7) 📝 `packages/client/src/components/chat/UnoSetup.tsx` (+11 -1) 📝 `packages/client/src/components/ui/Modal.tsx` (+13 -0) ➕ `packages/client/src/hooks/turn-game-keys.ts` (+12 -0) ➕ `packages/client/src/hooks/use-chess.ts` (+137 -0) 📝 `packages/client/src/hooks/use-generate.ts` (+40 -4) 📝 `packages/client/src/hooks/use-uno.ts` (+14 -10) 📝 `packages/client/src/lib/slash-commands.ts` (+14 -0) ➕ `packages/client/src/stores/chess-game.store.ts` (+36 -0) 📝 `packages/server/src/routes/generate.routes.ts` (+61 -6) 📝 `packages/server/src/services/conversation/character-commands.ts` (+16 -0) 📝 `packages/server/src/services/turn-games/turn-game-bot-runner.service.ts` (+2 -2) 📝 `packages/shared/package.json` (+1 -0) 📝 `packages/shared/scripts/generate-feature-registries.mjs` (+1 -1) ➕ `packages/shared/src/features/turn-games/chess/engine.manifest.ts` (+5 -0) _...and 8 more files_ </details> ### 📄 Description ## Linked issue <!-- No prior feature request covered this; opening one retroactively to gather opinions is still worthwhile, but the work and verification are complete. --> Closes # _No pre-existing tracking issue. Happy to open a feature request for the record if maintainers want one linked._ ## Why this change - The turn-game framework we shipped with UNO (#2721) made a promise: adding a new game should be one folder under `packages/shared/src/features/turn-games/<game>/` implementing `TurnGameEngine`, plus a per-game client surface, with the server runner, REST routes, SSE, and persistence all staying game-agnostic. Chess is the first game built against that contract, so it doubles as a real test of whether the abstraction holds. - It held: the server needed **zero** framework changes to run chess. The only server edits are the `[chess]` conversation command wiring, which mirrors `[uno]` exactly. - For players, this adds a second table game to conversation mode: a one-on-one chess match against a character, who talks at the table while the system runs the board. ## What changed - **Shared chess engine** (`packages/shared/src/features/turn-games/chess/`) implementing `TurnGameEngine`. Moves are SAN, validated by `chess.js`; the LLM proposes a move via a single `chess_move` tool and the engine falls back to a deterministic legal move if the model stalls or proposes something illegal, so a game can never wedge. `applyMove` never throws. Auto-draws (stalemate, insufficient material, threefold repetition, fifty-move) are detected from move history; there is no draw-offer handshake in this version (noted under scope below). - **`chess.js` dependency** added to `packages/shared` only. Server and client resolve it transitively through shared and never import it directly. - **`[chess]` conversation command**, mirroring `[uno]`: server dispatch, a natural-language launcher, a `/chess` slash command, and a settings toggle. A character that includes `[chess]` takes the opposing seat; the system runs the board. - **Client board surface**: `ChessBoard` (hand-authored inline SVG pieces, click-to-move, promotion picker, board flip when the human plays black, check / last-move highlights, captured-piece rows), a `ChessSetup` modal (pick one opponent, choose colour), a dedicated store, and a `use-chess` hook over the existing game-agnostic `/turn-games` REST surface. - **Turn-game framework robustness fixes** found while reviewing this work, several of which also affect UNO and are fixed for both games: guard the board stores by `gameType` so one game's view can never paint another's board; fix setup-modal lifecycle so a modal auto-closes when a game starts underneath it but can still be reopened for a rematch after a finished game; and recover a board when a state patch arrives while the chat is backgrounded (previously the board could get stuck on switch-back until resign or reload). ## Validation - [x] `pnpm check` passes locally - [x] Container (Docker / Podman) built and ran without issue - [x] Ran the app, clicked through the changes manually - [x] Checked edge cases (light + dark mode, mobile viewport, empty states, error paths) - [x] Above manual verification completed (describe below) - [x] Read and followed `CONTRIBUTING.md` ### Manual verification notes - `pnpm check` passes (TypeScript + ESLint across all three packages). Local engine + runner tests pass: engine conformance is fuzzed against a fresh `chess.js` oracle, and the bot-runner path is pinned to confirm the legal-move list is injected into the model prompt. (Those tests are local-only and not part of this diff, matching how the UNO suite is kept.) - The production container builds and boots healthy; the built bundle serves the chess client surface. - In-browser pass against a live model: - `/chess` setup modal, board render, click-to-move with legal-target dots. - A real game against a character: legal SAN moves land with in-character narration, castling resolves, and moves persist across a reload. - Board flips correctly when the human plays black, and the bot plays the opening move when it draws white. - Promotion picker, resign (X clears the board and ends the game), and the `[chess]` acceptance gate (only the agreeing character is seated). - Free-chat spectator awareness: a non-seated character can talk about the live game. - UNO regression: started a game after chess and played several turns — the shared SSE dispatch and the store/modal fixes behave correctly for both games. Scene banner is suppressed during an active game. ## Docs and release impact - [x] No docs changes needed - [ ] Updated docs (README / CONTRIBUTING / android/README / CHANGELOG) as needed - [ ] Version/release files updated (only if this PR includes a version bump) <!-- No version-bearing files are touched in this PR. --> ## Scope / follow-ups - v1 supports auto-draws only; a draw offer/accept handshake is a natural follow-up. - A pre-existing framework race (a mount-time hydration fetch can briefly lose to an in-flight SSE patch on the singleton board stores) is noted for a separate change; it predates this branch and is not a chess regression. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-22 04:19:42 +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#5809
No description provided.