cc680dc392
Characters are already owned by the player, not the game, and were meant to be reusable — but the DM had no way to actually retrieve one. upsert_character_sheet is write-only, so telling the DM "I'll bring my character Tillo Eichenherz" led it to create a second, blank "Tillo Eichenherz" (empty stats, thinner ability text) instead of reusing the real one, then ask for all six ability scores again as if nothing existed. Two fixes: 1. New link_existing_character tool: given a player name and a character name, looks it up among that player's own characters (ownership enforced — never someone else's) and links it to game_participants.character_id, returning the full sheet so the DM can continue with real data immediately. System prompt now tells the DM to call this the moment a player names a previously-played character, instead of asking for stats. 2. run_dm_turn now auto-injects the full sheet of every already-linked character into the system prompt every turn (name, stats, combat stats, HP, abilities, equipment, background), with an explicit "already exists, don't ask again" instruction — this is the actual root-cause fix: even a character linked some other way (the existing join-with-character_id flow, or a future UI) now stays visible to the DM turn after turn instead of only living in whatever's left of the truncated chat window. Also manually repaired the user's real "Schwarze Segel" game, which had already hit this bug — re-pointed its participant back to the real Tillo Eichenherz instead of the accidental duplicate (left the duplicate in place rather than deleting data; it's a normal delete away via the character-delete feature if unwanted). Verified live against x.ai: a fresh game where the player said "Ich nehme meinen alten Charakter Tillo Eichenherz" linked to the real character on the first message (no duplicate created — confirmed by row count), and a follow-up question about AC/Strength got the exact real values (RK 18, Stärke 15) pulled from the injected sheet, not re-asked or invented. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>