[PR #8202] [MERGED] Game Mode: AI reasons in the fight log with Debug on; fight setup that isn't cut off; starting gear keeps every kit #8182

Closed
opened 2026-10-25 04:04:30 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/8202
Author: @kolacheee
Created: 10/23/2026
Status: ✅ Merged
Merged: 10/23/2026
Merged by: @kolacheee

Base: staging ← Head: claude/game-mode-cloud-nx3wjf


📝 Commits (10+)

  • 97784c2 Ruleset combat: the AI's reasons in the log with Debug on
  • 4520e59 Merge Pasta-Devs staging into claude/game-mode-cloud-nx3wjf
  • 3f43bcc Ruleset combat: reasons never cost the fight an event; name whom a walk closed on
  • 169251b Starting gear: taking a kit again keeps the first in the record
  • e9dd2d4 Combat setup: say when the model's answer was cut off, and leave it room to finish
  • a00d904 Combat setup: think at medium at most, one setup at a time, and a failed one waits for Retry
  • 4f6773f Merge Pasta-Devs staging into claude/game-mode-cloud-nx3wjf
  • 886a104 Starting gear: the marker keeps a bag's newest forty kits, never dropping the one just taken
  • cce4472 Merge remote-tracking branch 'up/staging' into claude/game-mode-cloud-nx3wjf
  • 9c1ab7c Combat setup test: the setup asks for its own 12000-token floor, not the connection's smaller size

📊 Changes

21 files changed (+823 additions, -58 deletions)

View changed files

📝 packages/client/src/components/game/GameNarration.tsx (+6 -1)
📝 packages/client/src/components/game/GameSurface.tsx (+33 -1)
📝 packages/client/src/components/game/RulesetCombatLog.tsx (+8 -2)
📝 packages/client/src/components/game/RulesetCombatStatus.tsx (+3 -1)
📝 packages/client/src/components/game/StartingGearPicker.tsx (+1 -1)
➕ packages/client/src/lib/combat-setup-failures.ts (+55 -0)
📝 packages/client/src/lib/ruleset-combat-log-rich.ts (+14 -1)
📝 packages/client/src/lib/ruleset-combat-log.ts (+34 -0)
📝 packages/client/src/localization/locales/en.json (+19 -0)
📝 packages/server/src/routes/encounter.routes.ts (+120 -9)
📝 packages/server/src/services/game/combat-boss.service.ts (+2 -1)
📝 packages/server/src/services/game/game-starting-gear.service.ts (+4 -2)
📝 packages/server/src/services/game/ruleset-combat-director.service.ts (+129 -16)
📝 packages/server/src/services/generation/agent-generation-parameters.ts (+26 -0)
📝 packages/shared/src/features/combat-ai.ts (+62 -16)
📝 packages/shared/src/features/combat-director.ts (+28 -1)
📝 scripts/regressions/combat-boss-provider.regression.ts (+2 -1)
📝 scripts/regressions/game-ruleset-classic-items.regression.ts (+71 -2)
📝 scripts/regressions/game-ruleset-starting-gear.regression.ts (+8 -2)
📝 scripts/regressions/ruleset-combat-director.regression.ts (+154 -0)

...and 1 more files

📄 Description

Linked issue

Closes #8201
Closes #8204
Closes #8207

Why this change

  • Before:
    • In a ruleset fight, there was no way to see why the Engine played an opponent or a companion the way it did.
    • With a thinking model at a high effort, a fight's setup could be cut off part way and show only "Combat generation failed." Opening the chat again started another multi-minute setup each time, sometimes two at once.
    • A character who took a second starting kit of the same kind lost the first from the record.
  • After:
    • With Debug on, each AI step in the fight log is followed by a short aside, for example "Why Corwin did that: heavy damage to Thorn Lurker; worth the limited use it spends; likely takes Thorn Lurker out of the fight." It is read back from the picker's own scoring, and no model is asked.
    • The setup leaves room for its answer. A cut-off is named as one, only one setup runs per chat at a time, and a failed setup waits for Retry Combat.
    • The starting gear record keeps every kit taken, up to the newest forty in each bag.

What changed

  • AI reasons:
    • rankCombatCandidates scores every candidate exactly as chooseCombatCandidate does, and also returns what each part added. chooseRankedCombatCandidate returns the pick with those parts. chooseCombatCandidate is unchanged for its callers.
    • The ruleset director records a reasoning event after each step its picker takes, including window answers. It holds up to three of the largest parts of the score, the walk taken to act from where it did, or that it closed on an opponent. That opponent is the one nearest by the walk left to reach any cell they fill, as the closing move measures. The wording is ruleset-neutral.
    • When the fight's events are cut back to RULESET_COMBAT_EVENT_LIMIT, reasons go first, so they never cost a player an event of the fight.
    • Both fight logs show these lines only while Debug is on. The board's log draws them as an indented italic aside.
    • The boss prompt leaves reasoning events out.
  • Fight setup (/encounter/init):
    • It logs its reasoning effort, max tokens, finish reason, length and output tokens.
    • It asks for at least its own 12000-token budget, even when the connection names a smaller one, and thinks at medium effort at most. Where the connection's provider counts thinking inside max tokens and does not add room for it, the same room an agent call gets is added.
    • A cut-off answer is spotted by the provider's finish reason, or by JSON that ends inside a string or with an object still open. It is asked for once more with thinking off. If that is cut off too, the reply is a 502 with reason: "cut-off", and the screen's banner says the setup was cut off and how to give it more room.
    • A second setup request for a chat while one runs waits for it and gets the same answer.
    • A failed setup is remembered for its turn in this browser, so reopening the chat shows the failure and waits for Retry Combat.
  • Starting gear: taking a gear again adds it to gameStartingGearTaken instead of replacing the earlier one of its kind. Writer and reader both keep a bag's newest forty, so the kit just taken is never the one dropped.
  • English strings: game.combat.ruleset.event.reasoning, game.combat.ruleset.event.reason.*, ui.game.gamenarration.combatGenerationCutOff.

Validation

  • Shared build, server and client typecheck, client lanes typecheck, react-hooks lint on changed client files, and the locale check, all run locally (the cloud container has no pnpm, so these were run directly).
  • Regressions:
    • ruleset-combat-director: full AI fights on two rulesets, a walk past a walled-in foe, and reasons trimmed first.
    • ruleset-combat-screen-client
    • combat-ai
    • game-ruleset-classic-items: cut-off detection; a cut-off setup is named, a thinking connection gets medium room and then a thinking-off retry, and two requests at once make one model call.
    • combat-boss-provider: the setup keeps its own 12000-token floor over a connection's 4096.
    • game-ruleset-starting-gear (the newest forty kept), game-ruleset-starting-coins, game-ruleset-strict-starting-gear, game-ruleset-sheet-builder, multiplayer-game-persona
    • world-kit-battlefields, world-kit-elements
  • 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

  • The fight setup changes were played on a real model with a thinking connection (Max Output 16000, xhigh). Before, setups were cut off at about 19,000 characters. After, two setups finished with finish=stop and the board showed.
  • Sample reasons from an AI-played fight on the 5e example board: "nothing in reach, so it sprinted toward Thorn Lurker"; "heavy damage to Thorn Lurker; worth the limited use it spends; likely takes Thorn Lurker out of the fight".

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)

UI evidence (if applicable)

  • Log lines only, plus the setup banner's wording. No screenshot yet.

🔄 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/8202 **Author:** [@kolacheee](https://github.com/kolacheee) **Created:** 10/23/2026 **Status:** ✅ Merged **Merged:** 10/23/2026 **Merged by:** [@kolacheee](https://github.com/kolacheee) **Base:** `staging` ← **Head:** `claude/game-mode-cloud-nx3wjf` --- ### 📝 Commits (10+) - [`97784c2`](https://github.com/Pasta-Devs/Marinara-Engine/commit/97784c283c74d1b151cd0e08ea622fa0224ccb41) Ruleset combat: the AI's reasons in the log with Debug on - [`4520e59`](https://github.com/Pasta-Devs/Marinara-Engine/commit/4520e592a2a72704022ef43ec5159cf7cd90a1ca) Merge Pasta-Devs staging into claude/game-mode-cloud-nx3wjf - [`3f43bcc`](https://github.com/Pasta-Devs/Marinara-Engine/commit/3f43bcc38febe4beb23a253402e4b283cd5f0ac0) Ruleset combat: reasons never cost the fight an event; name whom a walk closed on - [`169251b`](https://github.com/Pasta-Devs/Marinara-Engine/commit/169251bbf53658b55c3dedbc28655b9c238ae475) Starting gear: taking a kit again keeps the first in the record - [`e9dd2d4`](https://github.com/Pasta-Devs/Marinara-Engine/commit/e9dd2d49eea195167eef28946a940ca9e6aa457d) Combat setup: say when the model's answer was cut off, and leave it room to finish - [`a00d904`](https://github.com/Pasta-Devs/Marinara-Engine/commit/a00d904d2d25b6ee804ca508d0f710991608929e) Combat setup: think at medium at most, one setup at a time, and a failed one waits for Retry - [`4f6773f`](https://github.com/Pasta-Devs/Marinara-Engine/commit/4f6773fd2084fe621f78e08fd03043a01c549d2d) Merge Pasta-Devs staging into claude/game-mode-cloud-nx3wjf - [`886a104`](https://github.com/Pasta-Devs/Marinara-Engine/commit/886a1048f2266dae262a668298cc5a14bfdf9362) Starting gear: the marker keeps a bag's newest forty kits, never dropping the one just taken - [`cce4472`](https://github.com/Pasta-Devs/Marinara-Engine/commit/cce4472d85acf9441aa3f61c8bc29875feb5bd0d) Merge remote-tracking branch 'up/staging' into claude/game-mode-cloud-nx3wjf - [`9c1ab7c`](https://github.com/Pasta-Devs/Marinara-Engine/commit/9c1ab7c900d47ab78a13f71bf757f464865b078d) Combat setup test: the setup asks for its own 12000-token floor, not the connection's smaller size ### 📊 Changes **21 files changed** (+823 additions, -58 deletions) <details> <summary>View changed files</summary> 📝 `packages/client/src/components/game/GameNarration.tsx` (+6 -1) 📝 `packages/client/src/components/game/GameSurface.tsx` (+33 -1) 📝 `packages/client/src/components/game/RulesetCombatLog.tsx` (+8 -2) 📝 `packages/client/src/components/game/RulesetCombatStatus.tsx` (+3 -1) 📝 `packages/client/src/components/game/StartingGearPicker.tsx` (+1 -1) ➕ `packages/client/src/lib/combat-setup-failures.ts` (+55 -0) 📝 `packages/client/src/lib/ruleset-combat-log-rich.ts` (+14 -1) 📝 `packages/client/src/lib/ruleset-combat-log.ts` (+34 -0) 📝 `packages/client/src/localization/locales/en.json` (+19 -0) 📝 `packages/server/src/routes/encounter.routes.ts` (+120 -9) 📝 `packages/server/src/services/game/combat-boss.service.ts` (+2 -1) 📝 `packages/server/src/services/game/game-starting-gear.service.ts` (+4 -2) 📝 `packages/server/src/services/game/ruleset-combat-director.service.ts` (+129 -16) 📝 `packages/server/src/services/generation/agent-generation-parameters.ts` (+26 -0) 📝 `packages/shared/src/features/combat-ai.ts` (+62 -16) 📝 `packages/shared/src/features/combat-director.ts` (+28 -1) 📝 `scripts/regressions/combat-boss-provider.regression.ts` (+2 -1) 📝 `scripts/regressions/game-ruleset-classic-items.regression.ts` (+71 -2) 📝 `scripts/regressions/game-ruleset-starting-gear.regression.ts` (+8 -2) 📝 `scripts/regressions/ruleset-combat-director.regression.ts` (+154 -0) _...and 1 more files_ </details> ### 📄 Description ## Linked issue Closes #8201 Closes #8204 Closes #8207 ## Why this change - Before: - In a ruleset fight, there was no way to see why the Engine played an opponent or a companion the way it did. - With a thinking model at a high effort, a fight's setup could be cut off part way and show only "Combat generation failed." Opening the chat again started another multi-minute setup each time, sometimes two at once. - A character who took a second starting kit of the same kind lost the first from the record. - After: - With Debug on, each AI step in the fight log is followed by a short aside, for example "Why Corwin did that: heavy damage to Thorn Lurker; worth the limited use it spends; likely takes Thorn Lurker out of the fight." It is read back from the picker's own scoring, and no model is asked. - The setup leaves room for its answer. A cut-off is named as one, only one setup runs per chat at a time, and a failed setup waits for Retry Combat. - The starting gear record keeps every kit taken, up to the newest forty in each bag. ## What changed - AI reasons: - `rankCombatCandidates` scores every candidate exactly as `chooseCombatCandidate` does, and also returns what each part added. `chooseRankedCombatCandidate` returns the pick with those parts. `chooseCombatCandidate` is unchanged for its callers. - The ruleset director records a `reasoning` event after each step its picker takes, including window answers. It holds up to three of the largest parts of the score, the walk taken to act from where it did, or that it closed on an opponent. That opponent is the one nearest by the walk left to reach any cell they fill, as the closing move measures. The wording is ruleset-neutral. - When the fight's events are cut back to `RULESET_COMBAT_EVENT_LIMIT`, reasons go first, so they never cost a player an event of the fight. - Both fight logs show these lines only while Debug is on. The board's log draws them as an indented italic aside. - The boss prompt leaves `reasoning` events out. - Fight setup (`/encounter/init`): - It logs its reasoning effort, max tokens, finish reason, length and output tokens. - It asks for at least its own 12000-token budget, even when the connection names a smaller one, and thinks at medium effort at most. Where the connection's provider counts thinking inside max tokens and does not add room for it, the same room an agent call gets is added. - A cut-off answer is spotted by the provider's finish reason, or by JSON that ends inside a string or with an object still open. It is asked for once more with thinking off. If that is cut off too, the reply is a 502 with `reason: "cut-off"`, and the screen's banner says the setup was cut off and how to give it more room. - A second setup request for a chat while one runs waits for it and gets the same answer. - A failed setup is remembered for its turn in this browser, so reopening the chat shows the failure and waits for Retry Combat. - Starting gear: taking a gear again adds it to `gameStartingGearTaken` instead of replacing the earlier one of its kind. Writer and reader both keep a bag's newest forty, so the kit just taken is never the one dropped. - English strings: `game.combat.ruleset.event.reasoning`, `game.combat.ruleset.event.reason.*`, `ui.game.gamenarration.combatGenerationCutOff`. ## Validation - [x] Shared build, server and client typecheck, client lanes typecheck, react-hooks lint on changed client files, and the locale check, all run locally (the cloud container has no `pnpm`, so these were run directly). - [x] Regressions: - `ruleset-combat-director`: full AI fights on two rulesets, a walk past a walled-in foe, and reasons trimmed first. - `ruleset-combat-screen-client` - `combat-ai` - `game-ruleset-classic-items`: cut-off detection; a cut-off setup is named, a thinking connection gets medium room and then a thinking-off retry, and two requests at once make one model call. - `combat-boss-provider`: the setup keeps its own 12000-token floor over a connection's 4096. - `game-ruleset-starting-gear` (the newest forty kept), `game-ruleset-starting-coins`, `game-ruleset-strict-starting-gear`, `game-ruleset-sheet-builder`, `multiplayer-game-persona` - `world-kit-battlefields`, `world-kit-elements` - [ ] Container (Docker / Podman) built and ran without issue - [x] Ran the app, clicked through the changes manually - [ ] 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 - The fight setup changes were played on a real model with a thinking connection (Max Output 16000, xhigh). Before, setups were cut off at about 19,000 characters. After, two setups finished with `finish=stop` and the board showed. - Sample reasons from an AI-played fight on the 5e example board: "nothing in reach, so it sprinted toward Thorn Lurker"; "heavy damage to Thorn Lurker; worth the limited use it spends; likely takes Thorn Lurker out of the fight". ## Docs and release impact - [x] 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) ## UI evidence (if applicable) - Log lines only, plus the setup banner's wording. No screenshot yet. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-25 04:04:30 +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#8182
No description provided.