[PR #2847] [MERGED] fix(chat): tracker edit targeting, prefill debounce, prompt-editor close, per-chat lorebook disable, convo card info #5767

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

📋 Pull Request Information

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

Base: staging ← Head: fix/tracker-edit-target-and-settings-lag


📝 Commits (5)

  • 76b3320 fix(tracker): target tracker character edits by unique id; debounce Assistant Prefill input
  • 52ead48 fix(tracker): drop edits whose character id vanished; guard prefill draft re-seed while focused
  • ef41ab0 fix(chat): keep the expanded prompt editor open when clicked inside a chat drawer
  • ecab269 feat(lorebook): let users disable auto-activated lorebooks per chat
  • df1ed3f fix(conversation): include character/persona card info when a prompt preset is selected

📊 Changes

15 files changed (+273 additions, -77 deletions)

View changed files

📝 packages/client/src/components/chat/ChatSettingsDrawer.tsx (+30 -6)
➕ packages/client/src/components/ui/DraftTextarea.tsx (+63 -0)
📝 packages/client/src/components/ui/ExpandedTextarea.tsx (+6 -0)
📝 packages/client/src/components/ui/GenerationParametersEditor.tsx (+4 -3)
📝 packages/client/src/features/chat-settings/sections/LorebooksSection.tsx (+43 -18)
📝 packages/client/src/features/tracker-panel/hooks/use-tracker-mutations.ts (+15 -18)
📝 packages/client/src/features/tracker-panel/lib/character-tracker-data.ts (+41 -0)
📝 packages/server/src/routes/chats.routes.ts (+11 -2)
📝 packages/server/src/routes/generate.routes.ts (+16 -16)
📝 packages/server/src/routes/generate/dry-run-route.ts (+2 -2)
📝 packages/server/src/routes/generate/generate-route-utils.ts (+10 -1)
📝 packages/server/src/routes/lorebooks.routes.ts (+2 -2)
📝 packages/server/src/routes/prompts.routes.ts (+2 -2)
📝 packages/server/src/services/lorebook/game-lorebook-scope.ts (+23 -7)
📝 packages/shared/src/types/chat.ts (+5 -0)

📄 Description

Linked issues

Closes #2845
Closes #2846
Closes #2848
Closes #2849
Closes #2850

Why this change

A batch of roleplay- and conversation-mode issues reported by users, bundled into one PR at maintainer request.

  • #2845 — In Roleplay mode with the Character Tracker, editing any present character's fields could save the change onto the first character in the list instead of the one I edited.
  • #2846 — Typing into the Assistant Prefill field under Advanced Parameters made characters appear one at a time, and nearby toggles felt delayed — worse the longer a chat session had been open.
  • #2848 — In Conversation mode, the Prompt Preset "Edit Prompt" window closed on any mouse click and discarded the edit; only keyboard editing worked.
  • #2849 — A character-bound (or global / active-persona) lorebook is force-activated in every non-game chat with no way to disable it per chat, so overlapping books overflow the token budget.
  • #2850 — In Conversation mode with a prompt preset selected, no character/persona card info reached the prompt — only the names — so the model had nothing to characterize.

What changed

#2845 — tracker edit target resolution

  • The tracker panel resolved edit/remove/avatar targets with findIndex by characterId. Present-character ids come from the LLM character-tracker agent and are not guaranteed unique (the prompt allows "ID or name"), so when several present characters shared an id, findIndex always returned the first match and the action landed on character #1.
  • Added resolveCharacterTargetIndex (features/tracker-panel/lib/character-tracker-data.ts): trust the id only when it uniquely identifies one character, otherwise fall back to the rendered index — the same rule findUniqueNamedIndex already applies to the other tracker list mutations. Wired into updateCharacter, removeCharacter, and the avatar-upload flow in use-tracker-mutations.ts.

#2846 — Assistant Prefill input responsiveness

  • The Assistant Prefill textarea was fully controlled by chatParameters and committed every keystroke straight to the per-chat metadata mutation, so the field only advanced after the round-trip re-rendered the settings tree.
  • Added DraftTextarea (components/ui/DraftTextarea.tsx), a local-buffered textarea that commits on blur (and flushes on unmount so closing the drawer mid-edit keeps the text), mirroring the existing DraftNumberInput pattern. Wired it into the Assistant Prefill field.

#2848 — expanded prompt editor closes on click

  • The ExpandedTextarea overlay renders through a portal to document.body, above the chat settings drawer. The drawer's capture-phase pointerdown outside-close handler treated clicks inside the portal as "outside", so the first click (including the Collapse button) closed the drawer and unmounted the editor before its edit could commit.
  • Marked the overlay with data-chat-floating-panel so the drawer's handler treats clicks inside it as inside. Closing now happens only via Collapse/Escape, which route through the editor's onClose and persist the change. Also covers the Game extra-prompt and Scene-instructions expanded editors, which share the component.

#2849 — disable a character-bound lorebook per chat

  • The exclusion plumbing already existed but was only wired to the Game Lorebook Keeper: filterRelevantLorebooks() and listActiveEntries() both honor an excludedLorebookIds filter, but the generation / scan / dry-run / prompt-preview paths only ever passed the game-keeper exclusions, and there was no UI or metadata field for a per-chat exclusion.
  • Server: added ChatMetadata.excludedLorebookIds; renamed resolveGameLorebookScopeExclusions → resolveLorebookScopeExclusions and folded per-chat excludedLorebookIds into the result for every mode, so all callers drop excluded books before injection; validated the field on the metadata PATCH route.
  • Client: a "disable in this chat" control on auto-activated books in the chat Lorebooks panel, disabled books rendered greyed with a re-enable control, written via the metadata mutation. Disabling does not unbind the book — it only suppresses it for this chat. The redundant pin-an-already-active-book control is replaced by disable; inactive books are still added via the picker. Credit to Evie [MARI] for the original root-cause analysis.

#2850 — conversation card info with a preset selected

  • Conversation mode is excluded from the preset assembler, so a preset only supplies the conversation prompt text; it never injects card fields. The identity fallback that would supply them was gated off whenever a preset was present (chatMode !== "game" && !presetId) — correct for roleplay (the assembler covers it) but leaving conversation+preset with nothing.
  • shouldInjectIdentityFallback now always runs for conversation mode regardless of preset. The injector already skips any character/persona whose profile is already in the prompt, so custom conversation prompts that embed {{description}} et al. are not duplicated, and conversation-without-a-preset behavior is unchanged.

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

All five changes verified on a build deployed to my private EasyPanel instance.

  • #2845: seeded a roleplay chat's Present Characters with three characters sharing one characterId, edited the second character's Mood in the docked tracker — the edit persisted to the second character (UI + game-state API); the others were untouched. Previously it landed on the first.
  • #2846: with the chat settings drawer open, typed a 16-character string into Assistant Prefill while watching the network tab — zero metadata PATCH requests while typing, a single commit PATCH on blur. Previously each keystroke fired its own mutation.
  • #2848: opened the conversation Prompt Preset "Edit Prompt" window, clicked inside the textarea — the editor stayed open (previously it closed). Typed a change, hit Collapse — the change persisted (the field flipped to "Custom" / chat-local edit). Reset to default afterward.
  • #2849: in a 5-character conversation chat, the chat Lorebooks panel showed each character book with a "disable" control; disabling a book greyed it and dropped its entries. Verified end-to-end via the lorebook scan API: a character book's constant entry was returned before exclusion, dropped after setting excludedLorebookIds, and returned again after re-enabling; the metadata PATCH rejects a non-array excludedLorebookIds with 400.
  • #2850: created a conversation chat with a described character + a prompt preset, ran a real generation, then inspected the cached/exact prompt (what was actually sent to the model) — it now contains the character's description. Previously the same configuration sent only names.

Caveat for #2850: the in-app "peek prompt" and dry-run previews use a separate best-effort assembler that does not mirror the real generation path, so they can still show only names. The fix is verified against the cached/exact prompt of a real generation; aligning the preview assemblers would be a separate change.

Notes:

  • There is no client-side test runner in this repo (the vitest suite is server-only), so these are manual/live checks. resolveCharacterTargetIndex and resolveLorebookScopeExclusions are pure functions a future test harness could cover directly.
  • Separately investigated a related report — in group conversations, "always on" lorebook entries appearing duplicated for the lead character — but could not reproduce it server-side: the scan/prompt engine returns each present character's constant entries exactly once across the configurations tested (per-character same-named books, a single book bound to multiple present characters, and a character-bound + pinned book). No change was made for that report.

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)

All five changes verified live on the deployed branch as described under Manual verification notes.


🔄 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/2847 **Author:** [@Romuromylus](https://github.com/Romuromylus) **Created:** 6/24/2026 **Status:** ✅ Merged **Merged:** 6/24/2026 **Merged by:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Base:** `staging` ← **Head:** `fix/tracker-edit-target-and-settings-lag` --- ### 📝 Commits (5) - [`76b3320`](https://github.com/Pasta-Devs/Marinara-Engine/commit/76b3320199c49d45c4fb74bfa399326200763791) fix(tracker): target tracker character edits by unique id; debounce Assistant Prefill input - [`52ead48`](https://github.com/Pasta-Devs/Marinara-Engine/commit/52ead489616452ba9b624483be7df83eaaad032a) fix(tracker): drop edits whose character id vanished; guard prefill draft re-seed while focused - [`ef41ab0`](https://github.com/Pasta-Devs/Marinara-Engine/commit/ef41ab099eb86409435c65ff1c4e0cb1b2741a83) fix(chat): keep the expanded prompt editor open when clicked inside a chat drawer - [`ecab269`](https://github.com/Pasta-Devs/Marinara-Engine/commit/ecab269bc0a33646b566c82f139c57fbd4d23294) feat(lorebook): let users disable auto-activated lorebooks per chat - [`df1ed3f`](https://github.com/Pasta-Devs/Marinara-Engine/commit/df1ed3f42033b28377a9f8c6e83a1c13fef2d42d) fix(conversation): include character/persona card info when a prompt preset is selected ### 📊 Changes **15 files changed** (+273 additions, -77 deletions) <details> <summary>View changed files</summary> 📝 `packages/client/src/components/chat/ChatSettingsDrawer.tsx` (+30 -6) ➕ `packages/client/src/components/ui/DraftTextarea.tsx` (+63 -0) 📝 `packages/client/src/components/ui/ExpandedTextarea.tsx` (+6 -0) 📝 `packages/client/src/components/ui/GenerationParametersEditor.tsx` (+4 -3) 📝 `packages/client/src/features/chat-settings/sections/LorebooksSection.tsx` (+43 -18) 📝 `packages/client/src/features/tracker-panel/hooks/use-tracker-mutations.ts` (+15 -18) 📝 `packages/client/src/features/tracker-panel/lib/character-tracker-data.ts` (+41 -0) 📝 `packages/server/src/routes/chats.routes.ts` (+11 -2) 📝 `packages/server/src/routes/generate.routes.ts` (+16 -16) 📝 `packages/server/src/routes/generate/dry-run-route.ts` (+2 -2) 📝 `packages/server/src/routes/generate/generate-route-utils.ts` (+10 -1) 📝 `packages/server/src/routes/lorebooks.routes.ts` (+2 -2) 📝 `packages/server/src/routes/prompts.routes.ts` (+2 -2) 📝 `packages/server/src/services/lorebook/game-lorebook-scope.ts` (+23 -7) 📝 `packages/shared/src/types/chat.ts` (+5 -0) </details> ### 📄 Description ## Linked issues Closes #2845 Closes #2846 Closes #2848 Closes #2849 Closes #2850 ## Why this change A batch of roleplay- and conversation-mode issues reported by users, bundled into one PR at maintainer request. - **#2845** — In Roleplay mode with the Character Tracker, editing any present character's fields could save the change onto the first character in the list instead of the one I edited. - **#2846** — Typing into the Assistant Prefill field under Advanced Parameters made characters appear one at a time, and nearby toggles felt delayed — worse the longer a chat session had been open. - **#2848** — In Conversation mode, the Prompt Preset "Edit Prompt" window closed on any mouse click and discarded the edit; only keyboard editing worked. - **#2849** — A character-bound (or global / active-persona) lorebook is force-activated in every non-game chat with no way to disable it per chat, so overlapping books overflow the token budget. - **#2850** — In Conversation mode with a prompt preset selected, no character/persona card info reached the prompt — only the names — so the model had nothing to characterize. ## What changed **#2845 — tracker edit target resolution** - The tracker panel resolved edit/remove/avatar targets with `findIndex` by `characterId`. Present-character ids come from the LLM character-tracker agent and are not guaranteed unique (the prompt allows "ID or name"), so when several present characters shared an id, `findIndex` always returned the first match and the action landed on character #1. - Added `resolveCharacterTargetIndex` (`features/tracker-panel/lib/character-tracker-data.ts`): trust the id only when it uniquely identifies one character, otherwise fall back to the rendered index — the same rule `findUniqueNamedIndex` already applies to the other tracker list mutations. Wired into `updateCharacter`, `removeCharacter`, and the avatar-upload flow in `use-tracker-mutations.ts`. **#2846 — Assistant Prefill input responsiveness** - The Assistant Prefill textarea was fully controlled by `chatParameters` and committed every keystroke straight to the per-chat metadata mutation, so the field only advanced after the round-trip re-rendered the settings tree. - Added `DraftTextarea` (`components/ui/DraftTextarea.tsx`), a local-buffered textarea that commits on blur (and flushes on unmount so closing the drawer mid-edit keeps the text), mirroring the existing `DraftNumberInput` pattern. Wired it into the Assistant Prefill field. **#2848 — expanded prompt editor closes on click** - The `ExpandedTextarea` overlay renders through a portal to `document.body`, above the chat settings drawer. The drawer's capture-phase `pointerdown` outside-close handler treated clicks inside the portal as "outside", so the first click (including the Collapse button) closed the drawer and unmounted the editor before its edit could commit. - Marked the overlay with `data-chat-floating-panel` so the drawer's handler treats clicks inside it as inside. Closing now happens only via Collapse/Escape, which route through the editor's `onClose` and persist the change. Also covers the Game extra-prompt and Scene-instructions expanded editors, which share the component. **#2849 — disable a character-bound lorebook per chat** - The exclusion plumbing already existed but was only wired to the Game Lorebook Keeper: `filterRelevantLorebooks()` and `listActiveEntries()` both honor an `excludedLorebookIds` filter, but the generation / scan / dry-run / prompt-preview paths only ever passed the game-keeper exclusions, and there was no UI or metadata field for a per-chat exclusion. - Server: added `ChatMetadata.excludedLorebookIds`; renamed `resolveGameLorebookScopeExclusions` → `resolveLorebookScopeExclusions` and folded per-chat `excludedLorebookIds` into the result for every mode, so all callers drop excluded books before injection; validated the field on the metadata PATCH route. - Client: a "disable in this chat" control on auto-activated books in the chat Lorebooks panel, disabled books rendered greyed with a re-enable control, written via the metadata mutation. Disabling does not unbind the book — it only suppresses it for this chat. The redundant pin-an-already-active-book control is replaced by disable; inactive books are still added via the picker. Credit to Evie [MARI] for the original root-cause analysis. **#2850 — conversation card info with a preset selected** - Conversation mode is excluded from the preset assembler, so a preset only supplies the conversation prompt text; it never injects card fields. The identity fallback that would supply them was gated off whenever a preset was present (`chatMode !== "game" && !presetId`) — correct for roleplay (the assembler covers it) but leaving conversation+preset with nothing. - `shouldInjectIdentityFallback` now always runs for conversation mode regardless of preset. The injector already skips any character/persona whose profile is already in the prompt, so custom conversation prompts that embed `{{description}}` et al. are not duplicated, and conversation-without-a-preset behavior is unchanged. ## 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 All five changes verified on a build deployed to my private EasyPanel instance. - **#2845**: seeded a roleplay chat's Present Characters with three characters sharing one `characterId`, edited the second character's Mood in the docked tracker — the edit persisted to the second character (UI + game-state API); the others were untouched. Previously it landed on the first. - **#2846**: with the chat settings drawer open, typed a 16-character string into Assistant Prefill while watching the network tab — zero metadata PATCH requests while typing, a single commit PATCH on blur. Previously each keystroke fired its own mutation. - **#2848**: opened the conversation Prompt Preset "Edit Prompt" window, clicked inside the textarea — the editor stayed open (previously it closed). Typed a change, hit Collapse — the change persisted (the field flipped to "Custom" / chat-local edit). Reset to default afterward. - **#2849**: in a 5-character conversation chat, the chat Lorebooks panel showed each character book with a "disable" control; disabling a book greyed it and dropped its entries. Verified end-to-end via the lorebook scan API: a character book's constant entry was returned before exclusion, dropped after setting `excludedLorebookIds`, and returned again after re-enabling; the metadata PATCH rejects a non-array `excludedLorebookIds` with 400. - **#2850**: created a conversation chat with a described character + a prompt preset, ran a real generation, then inspected the cached/exact prompt (what was actually sent to the model) — it now contains the character's description. Previously the same configuration sent only names. Caveat for #2850: the in-app "peek prompt" and dry-run previews use a separate best-effort assembler that does not mirror the real generation path, so they can still show only names. The fix is verified against the cached/exact prompt of a real generation; aligning the preview assemblers would be a separate change. Notes: - There is no client-side test runner in this repo (the vitest suite is server-only), so these are manual/live checks. `resolveCharacterTargetIndex` and `resolveLorebookScopeExclusions` are pure functions a future test harness could cover directly. - Separately investigated a related report — in group conversations, "always on" lorebook entries appearing duplicated for the lead character — but could not reproduce it server-side: the scan/prompt engine returns each present character's constant entries exactly once across the configurations tested (per-character same-named books, a single book bound to multiple present characters, and a character-bound + pinned book). No change was made for that report. ## 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) All five changes verified live on the deployed branch as described under Manual verification notes. --- <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:20 +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#5767
No description provided.