[PR #3360] [MERGED] fix(lorebooks): add unembed action + clarify embedded-lorebook UX #5899

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

📋 Pull Request Information

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

Base: staging ← Head: fix/3359-unembed-lorebook


📝 Commits (4)

  • 514258b fix(lorebooks): add unembed action + clarify embedded-lorebook UX (#3359)
  • 96ac1c4 fix(lorebooks): make Remove from card an immediate server write + toast (#3359)
  • a94edb6 Address embedded lorebook unembed race
  • 55047e4 Block embedded lorebook import remove overlap

📊 Changes

6 files changed (+176 additions, -12 deletions)

View changed files

📝 CHANGELOG.md (+1 -0)
📝 packages/client/src/components/characters/CharacterEditor.tsx (+109 -6)
📝 packages/client/src/components/lorebooks/LorebookAssignmentSection.tsx (+11 -2)
📝 packages/client/src/hooks/use-lorebooks.ts (+2 -2)
📝 packages/server/src/routes/characters.routes.ts (+14 -1)
📝 packages/server/src/services/lorebook/character-book-sync.ts (+39 -1)

📄 Description

Linked issue

Closes #3359

Why this change

The Character editor's Lorebook tab gave no way to unembed a lorebook. Once a lorebook was baked into a card (data.character_book), the row's 🗑️ only unlinked the standalone copy — it never cleared character_book, so the embedded lorebook silently persisted in the card (still listed, still exported), and "Removed …" implied it was gone. Separately, "Edit Linked Lorebook" opens the standalone mirror (which syncs into character_book), muddling the embedded-vs-linked distinction.

Verified beforehand (see #3359): this was purely a UX/management gap, not a data-integrity or double-injection bug — an embedded character_book is inert at runtime; only the standalone activates.

What changed

  • New "Remove from card" action in the Lorebook tab, shown whenever the card has an embedded lorebook — including the orphaned case where no standalone exists. It's an immediate server write (new DELETE /characters/:id/embedded-lorebook → clearEmbeddedLorebookFromCharacter, which drops data.character_book and the extensions.importMetadata.embeddedLorebook pointer), reconciled with the editor exactly the way Embed / Import / Reimport already are: patch formData when the editor is dirty (so other unsaved edits survive and a later Save can't re-embed it) and re-sync from the detail refetch when it's clean. Clearing the pointer also stops the standalone→character_book sync from re-baking it. The linked standalone lorebook, if any, is left intact. Destructive → gated behind a window.confirm, shows a spinner while working, and toasts on success.
  • Renamed "Edit Linked Lorebook" → "Edit Embedded Lorebook" and clarified the helper text ("Edit opens the lorebook editor; changes sync back into the card's embedded copy"). Also refreshed the four stale code comments that referenced the old button label (in CharacterEditor.tsx, use-lorebooks.ts, and character-book-sync.ts).
  • Clearer 🗑️ feedback: when the row being unlinked is the embedded lorebook, the toast and tooltip now say it only unlinks and the embedded copy stays — pointing to "Remove from card."

Server: one new DELETE route + clearEmbeddedLorebookFromCharacter (a sibling of the existing clearCharacterEmbeddedLorebook). No shared-package or schema changes.

Note: an earlier revision of this PR staged the removal in formData (apply-on-Save). Live testing showed that was confusing — a hard refresh before Save reloaded server state and appeared to "restore" the embedded lorebook — so removal is now an immediate server write, consistent with the other embedded-lorebook actions.

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

  • Client build (tsc) and ESLint pass: pnpm --filter @marinara-engine/client build, pnpm --filter @marinara-engine/client lint. (Full pnpm check is blocked on Windows by the pre-existing server build.mjs issue, unrelated to this change.)
  • Manually verify the click-through (needs a real app + a character with an embedded lorebook):
    1. Open a character that has an embedded lorebook; confirm Remove from card appears in the Lorebook tab.
    2. Click it → confirm → it removes immediately with a toast; the embedded entries + Reimport/Edit row disappear, and a hard refresh (Ctrl+Shift+R) shows it stays gone (no Save needed). Then edit the still-linked standalone (if any) and confirm the embedded copy does not resurrect.
    3. With other unsaved edits in the editor, click Remove from card → confirm the other edits are preserved (editor stays dirty) and Save persists everything without re-embedding.
    4. With a linked-but-not-embedded lorebook, confirm Remove from card is not shown for it and "Embed into card" still works.
    5. Verify Remove from card also appears + works for a character whose card has character_book but no standalone (orphaned case).
    6. Unlink the embedded row via 🗑️ → confirm the toast says it only unlinked and the embedded copy stays.

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)

CHANGELOG updated (Fixed). No version bump.

UI evidence (if applicable)

{655CFF28-8E61-427F-8164-28C5C66EFA39} {BB3345DE-B25B-426F-8191-8BC3F3AA1EA3} {7E26D522-B03D-45A7-A438-A74CD25626D9}

Summary by CodeRabbit

  • New Features

    • Added a Remove from card action for embedded lorebooks on character cards.
    • Updated labels and messaging to distinguish embedded vs. linked lorebooks.
  • Bug Fixes

    • Removing a lorebook from a character card now leaves any standalone lorebook copy intact.
    • Success and confirmation messages now clearly explain what is removed and what remains.
    • The remove action is blocked while a related update is still in progress.

🔄 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/3360 **Author:** [@kolacheee](https://github.com/kolacheee) **Created:** 7/8/2026 **Status:** ✅ Merged **Merged:** 7/8/2026 **Merged by:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Base:** `staging` ← **Head:** `fix/3359-unembed-lorebook` --- ### 📝 Commits (4) - [`514258b`](https://github.com/Pasta-Devs/Marinara-Engine/commit/514258b1f0f99de74745cd9c94855fc2432d6331) fix(lorebooks): add unembed action + clarify embedded-lorebook UX (#3359) - [`96ac1c4`](https://github.com/Pasta-Devs/Marinara-Engine/commit/96ac1c4b858e4f3c0504b261ea2339b2db001935) fix(lorebooks): make Remove from card an immediate server write + toast (#3359) - [`a94edb6`](https://github.com/Pasta-Devs/Marinara-Engine/commit/a94edb6145100369b3c9dc528bc2733c831b1c63) Address embedded lorebook unembed race - [`55047e4`](https://github.com/Pasta-Devs/Marinara-Engine/commit/55047e486571b8d449f5917511a952af765e29ed) Block embedded lorebook import remove overlap ### 📊 Changes **6 files changed** (+176 additions, -12 deletions) <details> <summary>View changed files</summary> 📝 `CHANGELOG.md` (+1 -0) 📝 `packages/client/src/components/characters/CharacterEditor.tsx` (+109 -6) 📝 `packages/client/src/components/lorebooks/LorebookAssignmentSection.tsx` (+11 -2) 📝 `packages/client/src/hooks/use-lorebooks.ts` (+2 -2) 📝 `packages/server/src/routes/characters.routes.ts` (+14 -1) 📝 `packages/server/src/services/lorebook/character-book-sync.ts` (+39 -1) </details> ### 📄 Description ## Linked issue Closes #3359 ## Why this change The Character editor's **Lorebook** tab gave no way to *unembed* a lorebook. Once a lorebook was baked into a card (`data.character_book`), the row's 🗑️ only **unlinked the standalone copy** — it never cleared `character_book`, so the embedded lorebook silently persisted in the card (still listed, still exported), and "Removed …" implied it was gone. Separately, **"Edit Linked Lorebook"** opens the standalone mirror (which syncs into `character_book`), muddling the embedded-vs-linked distinction. Verified beforehand (see #3359): this was purely a UX/management gap, **not** a data-integrity or double-injection bug — an embedded `character_book` is inert at runtime; only the standalone activates. ## What changed - **New "Remove from card" action** in the Lorebook tab, shown whenever the card has an embedded lorebook — including the orphaned case where no standalone exists. It's an **immediate server write** (new `DELETE /characters/:id/embedded-lorebook` → `clearEmbeddedLorebookFromCharacter`, which drops `data.character_book` and the `extensions.importMetadata.embeddedLorebook` pointer), reconciled with the editor exactly the way **Embed / Import / Reimport** already are: patch `formData` when the editor is dirty (so other unsaved edits survive and a later Save can't re-embed it) and re-sync from the detail refetch when it's clean. Clearing the pointer also stops the standalone→`character_book` sync from re-baking it. The linked standalone lorebook, if any, is left intact. Destructive → gated behind a `window.confirm`, shows a spinner while working, and toasts on success. - **Renamed "Edit Linked Lorebook" → "Edit Embedded Lorebook"** and clarified the helper text ("Edit opens the lorebook editor; changes sync back into the card's embedded copy"). Also refreshed the four stale code comments that referenced the old button label (in `CharacterEditor.tsx`, `use-lorebooks.ts`, and `character-book-sync.ts`). - **Clearer 🗑️ feedback:** when the row being unlinked is the embedded lorebook, the toast and tooltip now say it only unlinks and the embedded copy stays — pointing to "Remove from card." Server: one new `DELETE` route + `clearEmbeddedLorebookFromCharacter` (a sibling of the existing `clearCharacterEmbeddedLorebook`). No shared-package or schema changes. > Note: an earlier revision of this PR staged the removal in `formData` (apply-on-Save). Live testing showed that was confusing — a hard refresh before Save reloaded server state and appeared to "restore" the embedded lorebook — so removal is now an immediate server write, consistent with the other embedded-lorebook actions. ## 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 - Client build (tsc) and ESLint pass: `pnpm --filter @marinara-engine/client build`, `pnpm --filter @marinara-engine/client lint`. (Full `pnpm check` is blocked on Windows by the pre-existing server `build.mjs` issue, unrelated to this change.) - **Manually verify the click-through** (needs a real app + a character with an embedded lorebook): 1. Open a character that has an embedded lorebook; confirm **Remove from card** appears in the Lorebook tab. 2. Click it → confirm → it removes immediately with a toast; the embedded entries + Reimport/Edit row disappear, and a hard refresh (Ctrl+Shift+R) shows it stays gone (no Save needed). Then edit the still-linked standalone (if any) and confirm the embedded copy does not resurrect. 3. With **other unsaved edits** in the editor, click **Remove from card** → confirm the other edits are preserved (editor stays dirty) and Save persists everything without re-embedding. 4. With a *linked-but-not-embedded* lorebook, confirm **Remove from card** is not shown for it and "Embed into card" still works. 5. Verify **Remove from card** also appears + works for a character whose card has `character_book` but **no** standalone (orphaned case). 6. Unlink the embedded row via 🗑️ → confirm the toast says it only unlinked and the embedded copy stays. ## 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) CHANGELOG updated (Fixed). No version bump. ## UI evidence (if applicable) <img width="807" height="561" alt="{655CFF28-8E61-427F-8164-28C5C66EFA39}" src="https://github.com/user-attachments/assets/f31b95cf-0b38-4bf3-aff3-c7dcf817d77c" /> <img width="808" height="597" alt="{BB3345DE-B25B-426F-8191-8BC3F3AA1EA3}" src="https://github.com/user-attachments/assets/a3608edd-5f46-4073-bb87-61c1d30d2f03" /> <img width="806" height="599" alt="{7E26D522-B03D-45A7-A438-A74CD25626D9}" src="https://github.com/user-attachments/assets/333f5422-378c-40b9-ac72-51035d8efb9b" /> <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Added a **Remove from card** action for embedded lorebooks on character cards. * Updated labels and messaging to distinguish **embedded** vs. **linked** lorebooks. * **Bug Fixes** * Removing a lorebook from a character card now leaves any standalone lorebook copy intact. * Success and confirmation messages now clearly explain what is removed and what remains. * The remove action is blocked while a related update is still in progress. <!-- 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-23 04:04:57 +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#5899
No description provided.