[PR #3308] [MERGED] feat(turn-games): personality-driven bot moves + seat-aware game context in chat #5872

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

📋 Pull Request Information

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

Base: staging ← Head: fix/turn-game-personality-context


📝 Commits (5)

  • aee6b88 feat(turn-games): personality-driven bot moves + seat-aware game context in chat
  • 59bd453 Merge branch 'staging' into fix/turn-game-personality-context
  • b36fe4c feat(turn-games): personality-gated hand secrecy + one game load per generation turn
  • c28f540 Merge remote-tracking branch 'pasta/fix/turn-game-personality-context' into fix/turn-game-personality-context
  • 0b16186 feat(turn-games): personality-gate plan secrecy in open-information games

📊 Changes

6 files changed (+168 additions, -34 deletions)

View changed files

📝 packages/server/src/routes/generate.routes.ts (+37 -13)
📝 packages/server/src/services/turn-games/turn-game-bot-runner.service.ts (+7 -1)
📝 packages/server/src/services/turn-games/turn-game-runner.service.ts (+58 -20)
📝 packages/shared/src/features/turn-games/chess/engine.ts (+26 -0)
📝 packages/shared/src/features/turn-games/engine.types.ts (+15 -0)
📝 packages/shared/src/features/turn-games/uno/engine.ts (+25 -0)

📄 Description

Linked issue

Closes #3306

Why this change

The turn-game framework (UNO, chess) plays mechanically today: a bot seat's persona is included in the move prompt but nothing instructs the model to let it shape the move, so personality is narration-only flavor. And when the user talks to a character mid-game, every responder gets the same hand-free spectator snapshot — a character can't answer "how's your hand looking?" or "what was your last move?", and the in-progress chess context carries no move history at all. Both gaps break the illusion that the characters are actually playing.

What changed

  • Move selection is personality-directed. The bot runner's move-selection system prompt now tells the model to pick the move this character would make — bold characters take risks, cautious ones play safe, cunning ones save strong plays, and grudges from table talk matter — rather than the objectively strongest legal move. UNO's per-turn board summary also gains a "What just happened" recent-plays block so a bot can react to the moves that led to its turn (chess already carried history in its move prompt).

  • New engine-contract method participantSummary(state, seatId) (engine.types.ts, implemented for UNO and chess): a seat-aware variant of spectatorSummary that appends the seat's OWN information — their UNO hand, their chess color/opponent, whether it's their move, and their own most recent action — while keeping all other seats' hidden information redacted. Falls back to the spectator text for unseated viewers.

  • getTurnGameContextText(db, chatId, seatId?) selects the participant view for seated viewers and pairs it with seated-specific guidance (own your moves, hint or bluff about your hand in character, never recite stats or list hidden cards, never reveal other players' hidden information).

  • Per-responder injection in generate.routes.ts. The conversation-path game-context injection moved from one shared pre-loop block into generateForCharacter, so each responding character gets the board from their own seat. Privacy guards: a merged group generation that may voice several characters stays on the hand-free spectator view (new speaksOnlyTargetCharacter parameter — true for the individual loop, single explicit @mention, regen target, and non-group chats), and impersonation receives the human seat's view.

  • The chess in-progress spectator summary now includes recent move history (Recent moves: 1. c4 e5 …) instead of only the single last move.

  • Hand secrecy is personality-gated per game type. New engine-contract flag hiddenInformation (UNO true, chess false). In hidden-information games the seated guidance frames the hand as private — keeping it hidden is part of playing, and whether the character deflects, teases, bluffs, or lets something slip when asked is up to their personality (hand counts stay public). In open-information games like chess the position is public and freely discussable, but the character's plans stay a personality-gated secret — whether they share, deflect, or misdirect about their intentions is their call.

  • One game load per generation turn. getTurnGameContextBuilder(db, chatId) loads the game (visible-anchor scan + state parse) once per request and returns a per-seat text builder; generateForCharacter calls the builder per responding character, so a sequential group turn no longer re-scans the chat once per character. getTurnGameContextText remains as a one-shot wrapper.

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

Tested on a build deployed to my private instance, in a merged-mode group conversation with five characters:

  • Mid-game chess: asked a seated character how the game was going — she correctly recounted her own move (e5) and the opponent's opener (c4), and two spectating characters identified 1. c4 as the English Opening. That history knowledge comes from the new context block; the old in-progress chess context had no move list.
  • UNO, six seats: an explicit @mention of a seated character produced a reply citing her exact hand count, hinting at a strong card without listing her hand, and recounting the previous Reverse — and the reply voiced only the mentioned character. A plain-name (non-mention) question in merged mode correctly fell back to the spectator view.
  • Personality-through-play observed live: the sweet character apologized while playing a Draw Two; the snarky one skipped the human player immediately after his Wild +4 with an on-brand quip.
  • No hidden-hand leaks in any reply; engine state, board UI, and hand counts stayed consistent throughout; zero browser console errors.
  • Local suites: 52/52 across the five turn-game test files (engine + runner + bot runner), including two new seat-aware context regression tests (UNO exact-hand assertion; chess color + own-last-move + history).

Remaining for reviewers to double-check: individual-response group mode mid-game, and continue/regenerate flows on a game-active chat.

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)

UI evidence (if applicable)

Not applicable — no UI changes; the visible effect is in generated chat content and bot move choice.

Summary by CodeRabbit

  • New Features

    • Turn-based game updates now show a more accurate board view for each character, based on who is speaking or being addressed.
    • Game summaries are now seat-aware, so players can see their own turn status and relevant private details where applicable.
    • Chess and UNO displays now include more recent action context and clearer turn/status guidance.
  • Bug Fixes

    • Fixed cases where game prompts could show the wrong perspective during merged or impersonated character responses.

🔄 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/3308 **Author:** [@Romuromylus](https://github.com/Romuromylus) **Created:** 7/6/2026 **Status:** ✅ Merged **Merged:** 7/6/2026 **Merged by:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Base:** `staging` ← **Head:** `fix/turn-game-personality-context` --- ### 📝 Commits (5) - [`aee6b88`](https://github.com/Pasta-Devs/Marinara-Engine/commit/aee6b888c10b223e689f973b97b3d7de59f56cbd) feat(turn-games): personality-driven bot moves + seat-aware game context in chat - [`59bd453`](https://github.com/Pasta-Devs/Marinara-Engine/commit/59bd4531ce416035bcd13a5d1349d067bca29075) Merge branch 'staging' into fix/turn-game-personality-context - [`b36fe4c`](https://github.com/Pasta-Devs/Marinara-Engine/commit/b36fe4c65833ada182dcc3cb8843c735609986e2) feat(turn-games): personality-gated hand secrecy + one game load per generation turn - [`c28f540`](https://github.com/Pasta-Devs/Marinara-Engine/commit/c28f5409d64743d2efe3f335ebe680c61bf975af) Merge remote-tracking branch 'pasta/fix/turn-game-personality-context' into fix/turn-game-personality-context - [`0b16186`](https://github.com/Pasta-Devs/Marinara-Engine/commit/0b1618669053a00ee52f49991b68a0595b98b643) feat(turn-games): personality-gate plan secrecy in open-information games ### 📊 Changes **6 files changed** (+168 additions, -34 deletions) <details> <summary>View changed files</summary> 📝 `packages/server/src/routes/generate.routes.ts` (+37 -13) 📝 `packages/server/src/services/turn-games/turn-game-bot-runner.service.ts` (+7 -1) 📝 `packages/server/src/services/turn-games/turn-game-runner.service.ts` (+58 -20) 📝 `packages/shared/src/features/turn-games/chess/engine.ts` (+26 -0) 📝 `packages/shared/src/features/turn-games/engine.types.ts` (+15 -0) 📝 `packages/shared/src/features/turn-games/uno/engine.ts` (+25 -0) </details> ### 📄 Description ## Linked issue Closes #3306 ## Why this change The turn-game framework (UNO, chess) plays mechanically today: a bot seat's persona is included in the move prompt but nothing instructs the model to let it shape the move, so personality is narration-only flavor. And when the user talks to a character mid-game, every responder gets the same hand-free spectator snapshot — a character can't answer "how's your hand looking?" or "what was your last move?", and the in-progress chess context carries no move history at all. Both gaps break the illusion that the characters are actually playing. ## What changed - **Move selection is personality-directed.** The bot runner's move-selection system prompt now tells the model to pick the move *this character* would make — bold characters take risks, cautious ones play safe, cunning ones save strong plays, and grudges from table talk matter — rather than the objectively strongest legal move. UNO's per-turn board summary also gains a "What just happened" recent-plays block so a bot can react to the moves that led to its turn (chess already carried history in its move prompt). - **New engine-contract method `participantSummary(state, seatId)`** (`engine.types.ts`, implemented for UNO and chess): a seat-aware variant of `spectatorSummary` that appends the seat's OWN information — their UNO hand, their chess color/opponent, whether it's their move, and their own most recent action — while keeping all other seats' hidden information redacted. Falls back to the spectator text for unseated viewers. - **`getTurnGameContextText(db, chatId, seatId?)`** selects the participant view for seated viewers and pairs it with seated-specific guidance (own your moves, hint or bluff about your hand in character, never recite stats or list hidden cards, never reveal other players' hidden information). - **Per-responder injection in `generate.routes.ts`.** The conversation-path game-context injection moved from one shared pre-loop block into `generateForCharacter`, so each responding character gets the board from their own seat. Privacy guards: a merged group generation that may voice several characters stays on the hand-free spectator view (new `speaksOnlyTargetCharacter` parameter — true for the individual loop, single explicit @mention, regen target, and non-group chats), and impersonation receives the human seat's view. - The chess in-progress spectator summary now includes recent move history (`Recent moves: 1. c4 e5 …`) instead of only the single last move. - **Hand secrecy is personality-gated per game type.** New engine-contract flag `hiddenInformation` (UNO `true`, chess `false`). In hidden-information games the seated guidance frames the hand as private — keeping it hidden is part of playing, and whether the character deflects, teases, bluffs, or lets something slip when asked is up to their personality (hand *counts* stay public). In open-information games like chess the position is public and freely discussable, but the character's *plans* stay a personality-gated secret — whether they share, deflect, or misdirect about their intentions is their call. - **One game load per generation turn.** `getTurnGameContextBuilder(db, chatId)` loads the game (visible-anchor scan + state parse) once per request and returns a per-seat text builder; `generateForCharacter` calls the builder per responding character, so a sequential group turn no longer re-scans the chat once per character. `getTurnGameContextText` remains as a one-shot wrapper. ## 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 Tested on a build deployed to my private instance, in a merged-mode group conversation with five characters: - Mid-game chess: asked a seated character how the game was going — she correctly recounted her own move (e5) and the opponent's opener (c4), and two spectating characters identified 1. c4 as the English Opening. That history knowledge comes from the new context block; the old in-progress chess context had no move list. - UNO, six seats: an explicit @mention of a seated character produced a reply citing her exact hand count, hinting at a strong card without listing her hand, and recounting the previous Reverse — and the reply voiced only the mentioned character. A plain-name (non-mention) question in merged mode correctly fell back to the spectator view. - Personality-through-play observed live: the sweet character apologized while playing a Draw Two; the snarky one skipped the human player immediately after his Wild +4 with an on-brand quip. - No hidden-hand leaks in any reply; engine state, board UI, and hand counts stayed consistent throughout; zero browser console errors. - Local suites: 52/52 across the five turn-game test files (engine + runner + bot runner), including two new seat-aware context regression tests (UNO exact-hand assertion; chess color + own-last-move + history). Remaining for reviewers to double-check: individual-response group mode mid-game, and continue/regenerate flows on a game-active chat. ## 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) ## UI evidence (if applicable) Not applicable — no UI changes; the visible effect is in generated chat content and bot move choice. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Turn-based game updates now show a more accurate board view for each character, based on who is speaking or being addressed. * Game summaries are now seat-aware, so players can see their own turn status and relevant private details where applicable. * Chess and UNO displays now include more recent action context and clearer turn/status guidance. * **Bug Fixes** * Fixed cases where game prompts could show the wrong perspective during merged or impersonated character responses. <!-- 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-22 04:20:23 +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#5872
No description provided.