[PR #577] [MERGED] Fix/lorebook scoping #4680

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

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/577
Author: @Promansis
Created: 5/8/2026
Status: ✅ Merged
Merged: 5/9/2026
Merged by: @Romuromylus

Base: main ← Head: fix/lorebook-scoping


📝 Commits (10+)

  • 7f638a4 first pass lorebook fix
  • 49bee2c lorebook second pass
  • d45dd01 Lorebook pass #3
  • 18d6f82 Lorebook final pass
  • a7d5772 UI changes in the Chat Drawer and Lorebook editor
  • aec3891 defaults syntax tweak
  • de51ccb fix: restore lorebook editor error state
  • e180d82 fix: disabled lorebooks no longer slip into activeLorebookIdSet just because they’re pinned
  • adc4d9e Fix lorebook marker character matching
  • bdc7eb6 Show stale lorebook resource links

📊 Changes

36 files changed (+2689 additions, -441 deletions)

View changed files

📝 packages/client/src/components/chat/ChatSettingsDrawer.tsx (+156 -25)
📝 packages/client/src/components/lorebooks/LorebookEditor.tsx (+378 -104)
📝 packages/client/src/components/panels/LorebooksPanel.tsx (+83 -60)
📝 packages/client/src/components/presets/PresetEditor.tsx (+91 -4)
📝 packages/client/src/hooks/use-chats.ts (+12 -1)
📝 packages/client/src/hooks/use-generate.ts (+3 -0)
📝 packages/client/src/hooks/use-lorebooks.ts (+13 -20)
📝 packages/client/src/hooks/use-presets.ts (+2 -1)
📝 packages/server/src/db/file-backed-store.ts (+4 -0)
📝 packages/server/src/db/migrate.ts (+91 -1)
📝 packages/server/src/db/schema/lorebooks.ts (+35 -1)
📝 packages/server/src/routes/backup.routes.ts (+20 -0)
📝 packages/server/src/routes/chats.routes.ts (+27 -3)
📝 packages/server/src/routes/generate.routes.ts (+117 -41)
📝 packages/server/src/routes/generate/dry-run-route.ts (+68 -4)
📝 packages/server/src/routes/generate/lorebook-keeper-utils.ts (+4 -0)
📝 packages/server/src/routes/lorebooks.routes.ts (+22 -2)
📝 packages/server/src/routes/prompt-reviewer.routes.ts (+2 -0)
📝 packages/server/src/routes/prompts.routes.ts (+34 -0)
📝 packages/server/src/services/import/marinara.importer.ts (+17 -0)

...and 16 more files

📄 Description

Why this change

Closes #588 (or Fixes/Resolves) referencing an open issue.

  • Global lorebook was not wired in or had UI
  • No max lorebook context
  • Timing on the lorebook entities was not working
  • Lorebooks werent working in game mode most the time (passed as null)
  • ST imported lorebooks weren't importing some settings like title of entry
  • Imported lorebooks from ME to ME didn't have the links persist.
  • The lorebook markers were a bit sideways
  • Prevents lorebooks stacking in chats

What changed

  • Added global lorebook scope plus multi-character and multi-persona lorebook links.
    • Updated lorebook filtering so global, pinned/chat, character-linked, persona-linked, and chat-scoped lorebooks activate consistently.
    • Added per-chat lorebook runtime state for ephemeral entries, sticky, cooldown, and delay behavior.
    • Added default lorebook token budget handling and max activated entry enforcement.
    • Improved Lorebook editor scope controls, active-scope summary, linked resource pickers, and stale/deleted lorebook handling.
    • Added prompt/preset warnings and marker copy for active lorebooks without lorebook insertion markers.
    • Updated imports, migrations, storage, backup, dry-run/prompt-review paths, and prompt assembly to preserve the new lorebook fields.
    • Added/updated server tests for migrations, lorebook processing, timing behavior, scoping, and SillyTavern character import behavior.

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

    • Ran pnpm check; TypeScript, ESLint, and production builds passed.
  • Built the standard Docker image with docker build -t marinara-engine:pr-check -f Dockerfile ..
  • Manually reviewed the lorebook editor changes, scope controls, prompt marker warnings, and related lorebook activation paths.
  • Checked behavior around global lorebooks, linked character/persona scopes, chat-attached lorebooks, token budget handling, and deleted/stale lorebook editor recovery.
  • Reviewed light/dark mode and responsive UI behavior for the updated lorebook controls.

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)

chrome_ZLn4sKhBJZ image

Summary by CodeRabbit

  • New Features
    • Lorebooks can link to multiple characters/personas and be marked Global.
    • Chat shows why a lorebook is active (Global/Character/Persona/Chat) and supports pin/unpin per chat.
    • Per-chat lorebook token budget (0 = unlimited) and global default.
    • Entry timing state with sticky/cooldown/delay and preview-mode scans.
    • Lorebook editor/picker UI: multi-select linking, improved filtering, and clearer empty states.
    • Preset UI warns when presets lack lorebook markers but active lorebooks exist.

🔄 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/577 **Author:** [@Promansis](https://github.com/Promansis) **Created:** 5/8/2026 **Status:** ✅ Merged **Merged:** 5/9/2026 **Merged by:** [@Romuromylus](https://github.com/Romuromylus) **Base:** `main` ← **Head:** `fix/lorebook-scoping` --- ### 📝 Commits (10+) - [`7f638a4`](https://github.com/Pasta-Devs/Marinara-Engine/commit/7f638a4143d9cf6cfb61a30225e8b39a64b094f9) first pass lorebook fix - [`49bee2c`](https://github.com/Pasta-Devs/Marinara-Engine/commit/49bee2c8d39bd62a6162125322c8ff09da7defb6) lorebook second pass - [`d45dd01`](https://github.com/Pasta-Devs/Marinara-Engine/commit/d45dd01a5470ba52cf4533db28dbf0576fc5e551) Lorebook pass #3 - [`18d6f82`](https://github.com/Pasta-Devs/Marinara-Engine/commit/18d6f8264d398e8beb6676ac5050c7ecd7d3fa25) Lorebook final pass - [`a7d5772`](https://github.com/Pasta-Devs/Marinara-Engine/commit/a7d57725605df8e69103fda461c5a94ce6a12040) UI changes in the Chat Drawer and Lorebook editor - [`aec3891`](https://github.com/Pasta-Devs/Marinara-Engine/commit/aec389151c5b19e89ac7d5c312012d806809b43b) defaults syntax tweak - [`de51ccb`](https://github.com/Pasta-Devs/Marinara-Engine/commit/de51ccb3f3487b81b74922ac2d2ed0664a565e29) fix: restore lorebook editor error state - [`e180d82`](https://github.com/Pasta-Devs/Marinara-Engine/commit/e180d824e7157085cb455629705e1394e8cad3bf) fix: disabled lorebooks no longer slip into activeLorebookIdSet just because they’re pinned - [`adc4d9e`](https://github.com/Pasta-Devs/Marinara-Engine/commit/adc4d9e984ff8b37f7cf148f022351efd1b9b31a) Fix lorebook marker character matching - [`bdc7eb6`](https://github.com/Pasta-Devs/Marinara-Engine/commit/bdc7eb6f9a14921fed7a76a5538067c345a46dc6) Show stale lorebook resource links ### 📊 Changes **36 files changed** (+2689 additions, -441 deletions) <details> <summary>View changed files</summary> 📝 `packages/client/src/components/chat/ChatSettingsDrawer.tsx` (+156 -25) 📝 `packages/client/src/components/lorebooks/LorebookEditor.tsx` (+378 -104) 📝 `packages/client/src/components/panels/LorebooksPanel.tsx` (+83 -60) 📝 `packages/client/src/components/presets/PresetEditor.tsx` (+91 -4) 📝 `packages/client/src/hooks/use-chats.ts` (+12 -1) 📝 `packages/client/src/hooks/use-generate.ts` (+3 -0) 📝 `packages/client/src/hooks/use-lorebooks.ts` (+13 -20) 📝 `packages/client/src/hooks/use-presets.ts` (+2 -1) 📝 `packages/server/src/db/file-backed-store.ts` (+4 -0) 📝 `packages/server/src/db/migrate.ts` (+91 -1) 📝 `packages/server/src/db/schema/lorebooks.ts` (+35 -1) 📝 `packages/server/src/routes/backup.routes.ts` (+20 -0) 📝 `packages/server/src/routes/chats.routes.ts` (+27 -3) 📝 `packages/server/src/routes/generate.routes.ts` (+117 -41) 📝 `packages/server/src/routes/generate/dry-run-route.ts` (+68 -4) 📝 `packages/server/src/routes/generate/lorebook-keeper-utils.ts` (+4 -0) 📝 `packages/server/src/routes/lorebooks.routes.ts` (+22 -2) 📝 `packages/server/src/routes/prompt-reviewer.routes.ts` (+2 -0) 📝 `packages/server/src/routes/prompts.routes.ts` (+34 -0) 📝 `packages/server/src/services/import/marinara.importer.ts` (+17 -0) _...and 16 more files_ </details> ### 📄 Description ## Why this change Closes #588 (or Fixes/Resolves) referencing an open issue. <!-- What user problem, bug, or goal does this solve? --> - Global lorebook was not wired in or had UI - No max lorebook context - Timing on the lorebook entities was not working - Lorebooks werent working in game mode most the time (passed as null) - ST imported lorebooks weren't importing some settings like title of entry - Imported lorebooks from ME to ME didn't have the links persist. - The lorebook markers were a bit sideways - Prevents lorebooks stacking in chats ## What changed <!-- List the key changes in this PR --> - Added global lorebook scope plus multi-character and multi-persona lorebook links. - Updated lorebook filtering so global, pinned/chat, character-linked, persona-linked, and chat-scoped lorebooks activate consistently. - Added per-chat lorebook runtime state for ephemeral entries, sticky, cooldown, and delay behavior. - Added default lorebook token budget handling and max activated entry enforcement. - Improved Lorebook editor scope controls, active-scope summary, linked resource pickers, and stale/deleted lorebook handling. - Added prompt/preset warnings and marker copy for active lorebooks without lorebook insertion markers. - Updated imports, migrations, storage, backup, dry-run/prompt-review paths, and prompt assembly to preserve the new lorebook fields. - Added/updated server tests for migrations, lorebook processing, timing behavior, scoping, and SillyTavern character import behavior. ## Validation <!-- Required: include commands run and/or manual checks performed --> - [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 <!-- Describe exactly what you tested in a real browser/app, step by step. --> <!-- ⚠️ If an AI agent filled out or ticked these boxes for you, treat them --> <!-- as a TO-DO LIST, not as proof the work is done. Verify each item yourself --> <!-- before submitting. If you haven't verified it, untick the box. --> - - Ran `pnpm check`; TypeScript, ESLint, and production builds passed. - Built the standard Docker image with `docker build -t marinara-engine:pr-check -f Dockerfile .`. - Manually reviewed the lorebook editor changes, scope controls, prompt marker warnings, and related lorebook activation paths. - Checked behavior around global lorebooks, linked character/persona scopes, chat-attached lorebooks, token budget handling, and deleted/stale lorebook editor recovery. - Reviewed light/dark mode and responsive UI behavior for the updated lorebook controls. ## Docs and release impact - [x] No docs changes needed - [x] Updated docs (README / CONTRIBUTING / android/README / CHANGELOG) as needed - [x] Version/release files updated (only if this PR includes a version bump) ## UI evidence (if applicable) <!-- Add before/after screenshots or recordings for UI changes --> <img width="347" height="474" alt="chrome_ZLn4sKhBJZ" src="https://github.com/user-attachments/assets/3672953b-7962-40fc-90a0-85a80f0a24a3" /> <img width="855" height="611" alt="image" src="https://github.com/user-attachments/assets/27de4421-fa4b-4db4-a6d6-b07137e140d6" /> <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Lorebooks can link to multiple characters/personas and be marked Global. * Chat shows why a lorebook is active (Global/Character/Persona/Chat) and supports pin/unpin per chat. * Per-chat lorebook token budget (0 = unlimited) and global default. * Entry timing state with sticky/cooldown/delay and preview-mode scans. * Lorebook editor/picker UI: multi-select linking, improved filtering, and clearer empty states. * Preset UI warns when presets lack lorebook markers but active lorebooks exist. <!-- 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:09:44 +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#4680
No description provided.