[PR #373] [CLOSED] Lorebook folders #4588

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

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/373
Author: @kolacheee
Created: 5/3/2026
Status: ❌ Closed

Base: main ← Head: lorebook-folders


📝 Commits (9)

📊 Changes

11 files changed (+1985 additions, -886 deletions)

View changed files

📝 CHANGELOG.md (+3 -0)
📝 packages/client/src/components/lorebooks/LorebookEditor.tsx (+543 -833)
➕ packages/client/src/components/lorebooks/LorebookEntryRow.tsx (+746 -0)
➕ packages/client/src/components/lorebooks/LorebookFolderRow.tsx (+228 -0)
📝 packages/client/src/hooks/use-lorebooks.ts (+86 -3)
📝 packages/server/src/db/schema/lorebooks.ts (+32 -1)
📝 packages/server/src/routes/lorebooks.routes.ts (+58 -4)
📝 packages/server/src/services/import/marinara.importer.ts (+56 -30)
📝 packages/server/src/services/storage/lorebooks.storage.ts (+164 -15)
📝 packages/shared/src/schemas/lorebook.schema.ts (+25 -0)
📝 packages/shared/src/types/lorebook.ts (+44 -0)

📄 Description

<html>

Summary

Adds a flat collapsible folder system to the Lorebook editor so large lorebooks (especially ones with many entries that exist mainly for AI agents to manage) can be organized into named groups instead of one long vertical list.

Builds on the previously-merged inline-edit row work — folders are a parallel structure that sit above the existing entry rows.

Why

Large lorebooks become hard to navigate quickly: stable / agent-managed entries dominate vertical space, drowning out the entries the user is actively editing. A collapsible folder lets the user park "set-and-forget" entries out of view without disabling them, and gives a single toggle to gate a whole bucket on/off.

Behavior

  • Folders are flat in this PR. The schema includes a parentFolderId field reserved as null so a follow-up PR can add nesting without another migration. The route layer rejects non-null values for now.
  • Two toggles per folder. A collapse chevron (UI-only, persisted in localStorage per-lorebook) and an enable toggle (server-persisted). When the enable toggle is OFF, every entry inside the folder is excluded from activation regardless of the entry's own enabled flag — and the entry's own flag is preserved untouched, so re-enabling the folder restores each entry's previous individual setting.
  • Each folder is its own container. Sort by Order works inside the folder independently from root entries and from other folders. A folder full of high-Order entries can sit at the top of the list above root-level entries with low Order without conflict — that was an explicit ask in the issue framing.
  • Move UX: dropdown picker on each entry row (always available) and drag-and-drop across containers (when sort=Order with empty search). Drop on a folder header → entry moves to the top of that folder. Drop in the empty body of a folder → entry lands at the end. Drop in the root list → moves to root.
  • Folder reorder via DnD between folder headers, mirroring the existing entry DnD pattern.
  • When folder grouping doesn't make sense (search active, or sort is non-Order), the entries tab falls back to the existing flat list. A small "folder view paused" hint appears in the summary line. Folders aren't deleted — they reappear when the user clears search and re-selects Order.
  • Deleting a folder reparents entries to root (sets their folderId back to null) instead of cascading. The confirmation dialog says so explicitly.

Architecture

Layer What changed
packages/shared New LorebookFolder type. New createLorebookFolderSchema / updateLorebookFolderSchema. New folderId field on LorebookEntry (defaults to null).
packages/server/src/db/schema/lorebooks.ts New lorebook_folders table (id, lorebook_id FK, name, enabled, parent_folder_id, order, timestamps). New folder_id nullable column on lorebook_entries.
packages/server/src/services/storage/lorebooks.storage.ts Folder CRUD + reorder. Activation gate update in listActiveEntries — disabled-folder ID set excludes contained entries. reorderEntries now takes optional folderId so dragging within one container doesn't renumber another.
packages/server/src/routes/lorebooks.routes.ts New GET / POST / PATCH / DELETE / PUT-reorder endpoints under /lorebooks/:id/folders. Export envelopes now include a folders array. Entry-reorder route accepts an optional folderId body field. Non-null parentFolderId rejected with 400.
packages/server/src/services/import/marinara.importer.ts Re-imports folders from the export envelope and remaps old folder IDs → new folder IDs before creating entries, so a round-tripped lorebook keeps its folder structure.
packages/client/src/hooks/use-lorebooks.ts New folder hooks: useLorebookFolders, useCreateLorebookFolder, useUpdateLorebookFolder, useDeleteLorebookFolder, useReorderLorebookFolders. useReorderLorebookEntries now accepts a folderId arg.
packages/client/src/components/lorebooks/LorebookFolderRow.tsx (new) Collapsible folder header with enable toggle, inline rename, entry-count badge, drag handle, hover-revealed delete.
packages/client/src/components/lorebooks/LorebookEntryRow.tsx Adds a folder picker (CompactSelect of folders + "(none)") shown only when at least one folder exists.
packages/client/src/components/lorebooks/LorebookEditor.tsx Restructures the Entries tab to render a folder block + a root block when sort=Order with empty search. Cross-container DnD with source/target container tracking. New "Add Folder" button. localStorage helpers for collapse state.
CHANGELOG.md Entry under 1.5.6.

Known limitations

  • Nesting is intentionally not implemented. The schema reserves parentFolderId so a follow-up PR can add it without another migration; the route currently rejects non-null values.
  • DnD ignores the search/non-Order sort modes (drag handles disabled, matching previous behavior). The folder picker dropdown still works in those modes, so cross-folder moves are always available.
  • Folder view doesn't display badges on entries when grouping is suppressed (search/non-Order sort). The "folder view paused" hint in the summary is the only signal that folders exist in those modes — fine for now but could be richer later.
  • Entry order numbering across containers will accumulate gaps over time as entries move between folders. This is harmless (it doesn't affect activation; lower-Order = earlier) and gets renumbered to (i+1)*10 within a container the next time a drag-reorder happens inside it.

Test plan

A subset of these were exercised live in the running engine. The rest still need eyes-on verification before merging — they're called out below.

  • [x] pnpm install && pnpm db:push — confirmed locally; schema changes applied without errors.
  • [x] pnpm check passes locally with no new errors.
  • [x] Open an existing lorebook with several entries — opened a 6-entry lorebook; entries rendered correctly. No regression vs the inline-edit experience.
  • [x] Click "Add Folder" — confirmed a new folder appears in the folders block, named "New Folder", expanded, enabled. (Append-at-bottom rather than at-the-top, by design — places it after existing folders without disrupting them.)
  • [x] Rename the folder by clicking the name and editing — confirmed change persists after blur and propagates to entry-row folder dropdowns.
  • [x] Pick a root entry's folder dropdown → choose the new folder — entry moved into the folder, count badge incremented, and the entry's order was preserved (the cross-container fix).
  • [x] Collapse the folder by clicking the header — entries inside hid, chevron rotated. Reloaded the page → folder stayed collapsed via the lorebook-folder-collapsed:<lorebookId> localStorage key.
  • [x] Disable the folder with the enable toggle — verified via the /api/lorebooks/active/entries endpoint that entries inside the disabled folder are correctly gated out (4 of 6 entries returned), while each entry's own enabled flag in /api/lorebooks/:id/entries remained true. Did not run a live chat-generation pass — the activation-gate is verified at the API layer rather than through end-to-end model output. Eyes-on chat-generation pass still recommended before merge.
  • [x] Re-enable the folder — /api/lorebooks/active/entries returned all 6 entries, individual flags still untouched.
  • [x] Drag a root entry onto a folder header — manually verified by the contributor; Order is now preserved on cross-container drops.
  • [x] Drag an entry from one folder to another folder — manually verified by the contributor; both containers stay sorted by Order.
  • [x] Drag an entry from a folder back to root — manually verified by the contributor after the empty-root drop-zone fix; the amber drop zone appears with "Drop here to move out of the folder" hint when root is empty.
  • [x] Drag a folder up/down to reorder folders among siblings.
  • [x] Delete a folder that contains entries — confirmation dialog showed "The 1 entry inside will be moved back to the root level." Entry was reparented (folderId: null), no data loss.
  • [x] Search for an entry — folders disappeared, flat list rendered, "Folder view paused (clear search and sort by Order)" hint visible.
  • [x] Sort by "Name A→Z" — folders disappeared, entries listed alphabetically across containers; switching back to Order with empty search restored the folder block.
  • [x] Light mode AND dark mode — folder header, indentation lines, dropdowns and amber accents readable in both themes.
  • [x] Mobile viewport (~400px) — CSS class parity confirmed (folder row uses the same group flex … gap-2 and max-md:opacity-100 pattern as the entry row that already passes mobile review), but could have a cleaner look. Made a change so that it would wrap on overflow, instead of pushing Add Entry off to the side.
  • [x] Empty folder — body shows the "Empty — drag an entry here or pick this folder from an entry's folder selector." hint.
  • [x] Empty lorebook (no entries, no folders) — existing "No entries yet — add one to get started" empty state appears unchanged.
  • [x] Export a lorebook with folders → import the exported file — Was able to export and import a lorebook with folders without issue.
  • [x] Imported a SillyTavern World Info file without issue.
  • [ ] AI lorebook keeper / lorebook maker still creates entries successfully (they default to root). Not yet verified, as I do not have an agent that automates lorebook entries and cannot test this. The shared schema's folderId defaults to null and the storage layer accepts the field, so default behavior should be unchanged.

Screenshots

Dark Mode image

Light Mode
image

Mobile
image

</html>

🔄 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/373 **Author:** [@kolacheee](https://github.com/kolacheee) **Created:** 5/3/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `lorebook-folders` --- ### 📝 Commits (9) - [`0b6c70c`](https://github.com/Pasta-Devs/Marinara-Engine/commit/0b6c70c5d9ed44aebafbdaf24b5a47513844b90a) Add files via upload - [`9593ed4`](https://github.com/Pasta-Devs/Marinara-Engine/commit/9593ed42e07c29be4fdc2d074c31f027564f8e3c) Add files via upload - [`81b1930`](https://github.com/Pasta-Devs/Marinara-Engine/commit/81b19300b6f695b7150092a6ef31ff8c55ecb3c6) Add files via upload - [`f613957`](https://github.com/Pasta-Devs/Marinara-Engine/commit/f6139571be8abdf17161da3d107a671cbb43aa68) Add files via upload - [`2ac512f`](https://github.com/Pasta-Devs/Marinara-Engine/commit/2ac512fe7f4cab01176dd5c6b983d783bbf7cee2) Add files via upload - [`fedf2b3`](https://github.com/Pasta-Devs/Marinara-Engine/commit/fedf2b34fc54d9c0ac8075ea8aa4bf8f8a96a2b7) Add files via upload - [`ff5bade`](https://github.com/Pasta-Devs/Marinara-Engine/commit/ff5bade9a3016494b45001f089227e93a605628c) Add files via upload - [`fbdc07c`](https://github.com/Pasta-Devs/Marinara-Engine/commit/fbdc07c62ff29ff3281f98d7ee1e6f9c3e840ca5) Add files via upload - [`ed8a765`](https://github.com/Pasta-Devs/Marinara-Engine/commit/ed8a7656b8a884641f1d83595ab01d501be5d909) Add files via upload ### 📊 Changes **11 files changed** (+1985 additions, -886 deletions) <details> <summary>View changed files</summary> 📝 `CHANGELOG.md` (+3 -0) 📝 `packages/client/src/components/lorebooks/LorebookEditor.tsx` (+543 -833) ➕ `packages/client/src/components/lorebooks/LorebookEntryRow.tsx` (+746 -0) ➕ `packages/client/src/components/lorebooks/LorebookFolderRow.tsx` (+228 -0) 📝 `packages/client/src/hooks/use-lorebooks.ts` (+86 -3) 📝 `packages/server/src/db/schema/lorebooks.ts` (+32 -1) 📝 `packages/server/src/routes/lorebooks.routes.ts` (+58 -4) 📝 `packages/server/src/services/import/marinara.importer.ts` (+56 -30) 📝 `packages/server/src/services/storage/lorebooks.storage.ts` (+164 -15) 📝 `packages/shared/src/schemas/lorebook.schema.ts` (+25 -0) 📝 `packages/shared/src/types/lorebook.ts` (+44 -0) </details> ### 📄 Description <html> <body> <h2>Summary</h2> <p>Adds a flat collapsible folder system to the Lorebook editor so large lorebooks (especially ones with many entries that exist mainly for AI agents to manage) can be organized into named groups instead of one long vertical list.</p> <p>Builds on the previously-merged inline-edit row work — folders are a parallel structure that sit above the existing entry rows.</p> <h2>Why</h2> <p>Large lorebooks become hard to navigate quickly: stable / agent-managed entries dominate vertical space, drowning out the entries the user is actively editing. A collapsible folder lets the user park "set-and-forget" entries out of view without disabling them, and gives a single toggle to gate a whole bucket on/off.</p> <h2>Behavior</h2> <ul> <li><strong>Folders are flat</strong> in this PR. The schema includes a <code>parentFolderId</code> field reserved as <code>null</code> so a follow-up PR can add nesting without another migration. The route layer rejects non-null values for now.</li> <li><strong>Two toggles per folder.</strong> A <em>collapse</em> chevron (UI-only, persisted in <code>localStorage</code> per-lorebook) and an <em>enable</em> toggle (server-persisted). When the enable toggle is OFF, every entry inside the folder is excluded from activation regardless of the entry's own <code>enabled</code> flag — and the entry's own flag is preserved untouched, so re-enabling the folder restores each entry's previous individual setting.</li> <li><strong>Each folder is its own container.</strong> Sort by Order works inside the folder independently from root entries and from other folders. A folder full of high-Order entries can sit at the top of the list above root-level entries with low Order without conflict — that was an explicit ask in the issue framing.</li> <li><strong>Move UX:</strong> dropdown picker on each entry row (always available) and drag-and-drop across containers (when sort=Order with empty search). Drop on a folder header → entry moves to the top of that folder. Drop in the empty body of a folder → entry lands at the end. Drop in the root list → moves to root.</li> <li><strong>Folder reorder via DnD</strong> between folder headers, mirroring the existing entry DnD pattern.</li> <li><strong>When folder grouping doesn't make sense</strong> (search active, or sort is non-Order), the entries tab falls back to the existing flat list. A small "folder view paused" hint appears in the summary line. Folders aren't deleted — they reappear when the user clears search and re-selects Order.</li> <li><strong>Deleting a folder reparents entries to root</strong> (sets their <code>folderId</code> back to <code>null</code>) instead of cascading. The confirmation dialog says so explicitly.</li> </ul> <h2>Architecture</h2> Layer | What changed -- | -- packages/shared | New LorebookFolder type. New createLorebookFolderSchema / updateLorebookFolderSchema. New folderId field on LorebookEntry (defaults to null). packages/server/src/db/schema/lorebooks.ts | New lorebook_folders table (id, lorebook_id FK, name, enabled, parent_folder_id, order, timestamps). New folder_id nullable column on lorebook_entries. packages/server/src/services/storage/lorebooks.storage.ts | Folder CRUD + reorder. Activation gate update in listActiveEntries — disabled-folder ID set excludes contained entries. reorderEntries now takes optional folderId so dragging within one container doesn't renumber another. packages/server/src/routes/lorebooks.routes.ts | New GET / POST / PATCH / DELETE / PUT-reorder endpoints under /lorebooks/:id/folders. Export envelopes now include a folders array. Entry-reorder route accepts an optional folderId body field. Non-null parentFolderId rejected with 400. packages/server/src/services/import/marinara.importer.ts | Re-imports folders from the export envelope and remaps old folder IDs → new folder IDs before creating entries, so a round-tripped lorebook keeps its folder structure. packages/client/src/hooks/use-lorebooks.ts | New folder hooks: useLorebookFolders, useCreateLorebookFolder, useUpdateLorebookFolder, useDeleteLorebookFolder, useReorderLorebookFolders. useReorderLorebookEntries now accepts a folderId arg. packages/client/src/components/lorebooks/LorebookFolderRow.tsx (new) | Collapsible folder header with enable toggle, inline rename, entry-count badge, drag handle, hover-revealed delete. packages/client/src/components/lorebooks/LorebookEntryRow.tsx | Adds a folder picker (CompactSelect of folders + "(none)") shown only when at least one folder exists. packages/client/src/components/lorebooks/LorebookEditor.tsx | Restructures the Entries tab to render a folder block + a root block when sort=Order with empty search. Cross-container DnD with source/target container tracking. New "Add Folder" button. localStorage helpers for collapse state. CHANGELOG.md | Entry under 1.5.6. <h2>Known limitations</h2> <ul> <li>Nesting is intentionally not implemented. The schema reserves <code>parentFolderId</code> so a follow-up PR can add it without another migration; the route currently rejects non-null values.</li> <li>DnD ignores the search/non-Order sort modes (drag handles disabled, matching previous behavior). The folder picker dropdown still works in those modes, so cross-folder moves are always available.</li> <li>Folder view doesn't display badges on entries when grouping is suppressed (search/non-Order sort). The "folder view paused" hint in the summary is the only signal that folders exist in those modes — fine for now but could be richer later.</li> <li>Entry <code>order</code> numbering across containers will accumulate gaps over time as entries move between folders. This is harmless (it doesn't affect activation; lower-Order = earlier) and gets renumbered to (i+1)*10 within a container the next time a drag-reorder happens inside it.</li> </ul> <h2>Test plan</h2> <p>A subset of these were exercised live in the running engine. The rest still need eyes-on verification before merging — they're called out below.</p> <ul> <li>[x] <strong><code>pnpm install</code> &amp;&amp; <code>pnpm db:push</code></strong> — confirmed locally; schema changes applied without errors.</li> <li>[x] <strong><code>pnpm check</code></strong> passes locally with no new errors.</li> <li>[x] <strong>Open an existing lorebook</strong> with several entries — opened a 6-entry lorebook; entries rendered correctly. No regression vs the inline-edit experience.</li> <li>[x] <strong>Click "Add Folder"</strong> — confirmed a new folder appears in the folders block, named "New Folder", expanded, enabled. (Append-at-bottom rather than at-the-top, by design — places it after existing folders without disrupting them.)</li> <li>[x] <strong>Rename the folder</strong> by clicking the name and editing — confirmed change persists after blur and propagates to entry-row folder dropdowns.</li> <li>[x] <strong>Pick a root entry's folder dropdown → choose the new folder</strong> — entry moved into the folder, count badge incremented, <strong>and the entry's <code>order</code> was preserved</strong> (the cross-container fix).</li> <li>[x] <strong>Collapse the folder</strong> by clicking the header — entries inside hid, chevron rotated. Reloaded the page → folder stayed collapsed via the <code>lorebook-folder-collapsed:&lt;lorebookId&gt;</code> localStorage key.</li> <li>[x] <strong>Disable the folder</strong> with the enable toggle — verified via the <code>/api/lorebooks/active/entries</code> endpoint that entries inside the disabled folder are correctly gated out (4 of 6 entries returned), while each entry's own <code>enabled</code> flag in <code>/api/lorebooks/:id/entries</code> remained <code>true</code>. Did <strong>not</strong> run a live chat-generation pass — the activation-gate is verified at the API layer rather than through end-to-end model output. <em>Eyes-on chat-generation pass still recommended before merge.</em></li> <li>[x] <strong>Re-enable the folder</strong> — <code>/api/lorebooks/active/entries</code> returned all 6 entries, individual flags still untouched.</li> <li>[x] <strong>Drag a root entry onto a folder header</strong> — manually verified by the contributor; Order is now preserved on cross-container drops.</li> <li>[x] <strong>Drag an entry from one folder to another folder</strong> — manually verified by the contributor; both containers stay sorted by Order.</li> <li>[x] <strong>Drag an entry from a folder back to root</strong> — manually verified by the contributor after the empty-root drop-zone fix; the amber drop zone appears with "Drop here to move out of the folder" hint when root is empty.</li> <li>[x] <strong>Drag a folder up/down</strong> to reorder folders among siblings.</li> <li>[x] <strong>Delete a folder</strong> that contains entries — confirmation dialog showed "The 1 entry inside will be moved back to the root level." Entry was reparented (<code>folderId: null</code>), no data loss.</li> <li>[x] <strong>Search for an entry</strong> — folders disappeared, flat list rendered, "Folder view paused (clear search and sort by Order)" hint visible.</li> <li>[x] <strong>Sort by "Name A→Z"</strong> — folders disappeared, entries listed alphabetically across containers; switching back to Order with empty search restored the folder block.</li> <li>[x] <strong>Light mode AND dark mode</strong> — folder header, indentation lines, dropdowns and amber accents readable in both themes.</li> <li>[x] <strong>Mobile viewport (~400px)</strong> — CSS class parity confirmed (folder row uses the same <code>group flex … gap-2</code> and <code>max-md:opacity-100</code> pattern as the entry row that already passes mobile review), but could have a cleaner look. Made a change so that it would wrap on overflow, instead of pushing Add Entry off to the side.</li> <li>[x] <strong>Empty folder</strong> — body shows the "Empty — drag an entry here or pick this folder from an entry's folder selector." hint.</li> <li>[x] <strong>Empty lorebook</strong> (no entries, no folders) — existing "No entries yet — add one to get started" empty state appears unchanged.</li> <li>[x] <strong>Export a lorebook with folders → import the exported file</strong> — Was able to export and import a lorebook with folders without issue.</li> <li>[x] <strong>Imported a SillyTavern World Info file without issue.</strong></li> <li>[ ] <strong>AI lorebook keeper / lorebook maker</strong> still creates entries successfully (they default to root). <em>Not yet verified, as I do not have an agent that automates lorebook entries and cannot test this.</em> The shared schema's <code>folderId</code> defaults to null and the storage layer accepts the field, so default behavior should be unchanged.</li> </ul> <h2>Screenshots</h2> Dark Mode <img width="2549" height="1259" alt="image" src="https://github.com/user-attachments/assets/8e0ba438-5c6b-4887-8d1e-b91ab6e7ffc6" /> Light Mode <img width="2533" height="1201" alt="image" src="https://github.com/user-attachments/assets/ee1d7570-d436-4970-a394-fe68107c9187" /> Mobile <img width="1262" height="1425" alt="image" src="https://github.com/user-attachments/assets/1154aa53-d59e-425b-9747-df277bfb781f" /> </body> </html> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-22 04:08: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#4588
No description provided.