[PR #2157] [MERGED] feat: duplicate lorebook entries #5452

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

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/2157
Author: @kolacheee
Created: 6/4/2026
Status: ✅ Merged
Merged: 6/4/2026
Merged by: @cha1latte

Base: refactor ← Head: feat/lorebook-entry-duplication


📝 Commits (1)

  • 4038969 feat: duplicate lorebook entries

📊 Changes

2 files changed (+46 additions, -1 deletions)

View changed files

📝 src/features/catalog/lorebooks/components/entries/LorebookEntryRow.tsx (+23 -1)
📝 src/features/catalog/lorebooks/hooks/use-lorebooks.ts (+23 -0)

📄 Description

Linked issue

Closes #2127 — Halfway, this PR is the entry-duplication part. Nested folders will follow as a separate PR.

Why this change

  • Re-creating a lorebook entry by hand — re-typing its keys, filters, injection/activation settings, and content — is tedious when you want a near-identical variant. A one-click duplicate is a pure QoL win, and it's fully additive (no existing behavior changes).

What changed

  • useDuplicateLorebookEntry hook (hooks/use-lorebooks.ts) — clones an entry through the existing generic storageApi.create("lorebook-entries", …) path: the create schema strips the server-managed id/createdAt/updatedAt, the name gets a " (Copy)" suffix, and every other field carries over verbatim — folderId, keys/secondaryKeys, all character/tag/trigger filters, position/depth/order, probability, timing, grouping, embedding, and activation conditions. Invalidates the same queries as useCreateLorebookEntry.
  • Duplicate button (components/entries/LorebookEntryRow.tsx) — a Copy-icon button in the per-row actions, immediately left of the existing delete button. Mirrors delete's hover-reveal pattern (always visible on mobile) with neutral styling; disabled while the mutation is in flight.

No backend/Rust changes. Unlike duplicate_character (which needs Rust to deep-copy the managed avatar file on disk), lorebook entries have no managed on-disk asset — their entire CRUD already rides the generic storage gateway — so duplication is a pure client-side row clone. No new Tauri command, no lib.rs registration.

Refactor impact

Primary owner: Catalog / Lorebooks editor (frontend)

Impact areas reviewed:

  • hooks/use-lorebooks.ts (new useDuplicateLorebookEntry mutation) and components/entries/LorebookEntryRow.tsx (the row's duplicate button). No engine, storage-contract, or Rust changes.

Boundary notes:

  • Confined to the lorebooks feature UI and its React Query layer. Reuses the existing generic storageApi.create and the established createLorebookEntrySchema rather than adding a parallel path; no new storage collection, command, or cross-boundary call.

Pressure points touched:

  • None of the flagged ones — no ModeSurface/GameSurface/shared mode UI, no src-tauri/src/lib.rs command registration, no import modules. Lorebook entry row only.

Validation

  • Matching validation command passes locally (for example pnpm typecheck, pnpm build, pnpm check:architecture, pnpm check:docs, or full pnpm check when warranted)
  • Full pnpm check passes before PR push/handoff
  • Human/manual validation completed by contributor or reviewer

Manual verification notes

  • pnpm typecheck (tsc -b) clean; check:architecture, check:frontend, check:discovery, check:docs, and check:unused all pass locally.
  • Verified by hand in the running Tauri build: clicking the duplicate icon creates a "… (Copy)" entry that preserves the source's content, keys, position (↑Char), order, and probability (confirmed token count and inline controls match the original); the copy lands in the same container; repeated duplication works. Confirmed in light and dark mode, and at the mobile breakpoint (≤768px — the inline controls collapse into the ⋯ menu and the copy/delete buttons go always-visible, no overflow, names truncate).

Feature Discoverability

  • Updated src/features/shell/discovery/ because this PR adds or materially changes a user-discoverable feature, workflow, setting, mode, panel, import path, agent, media capability, or advanced tool.
  • N/A because this PR is only a bugfix, refactor, test, docs, internal wiring, visual polish, copy edit, or compatibility fix and does not add a new thing users need to find.

Reason:

  • N/A — adds a per-row action button alongside the existing delete action within the lorebook editor; a QoL action inside an existing panel, not a new discoverable surface.

Docs and release impact

  • No docs changes needed
  • Updated README.md
  • Updated CONTRIBUTING.md
  • Updated docs/developer/
  • Updated repo skills or AGENTS.md
  • Confirmed this PR does not restore old staging/package-workspace/release claims

Proof

Core claim:

  • A one-click duplicate produces a faithful, independent copy of a lorebook entry in the same container, with all activation/injection settings preserved and only the name changed.

Verification run:

  • pnpm typecheck plus check:architecture / check:frontend / check:discovery / check:docs / check:unused (all green), plus manual in-app testing in the Tauri build.

Evidence:

  • The duplicated rows mirror the source's ↑Char position, ord: 1, p: 100%, and # 12 token count (identical content) — differing only by the " (Copy)" name — confirming the whole entry (not just the name) is cloned.
  • The duplicate button renders consistently in light + dark mode and at the mobile breakpoint.

Known behavior (intended, not a bug):

  • The copy inherits the source's exact order, so it sorts immediately after the original in the common case. When several entries share the same order value (e.g., all at the default), the copy lands at the end of that same-order group rather than directly beneath the source. This is deliberate: the only way to force flush placement is to renumber the whole container, which would overwrite every sibling's order — and order also drives prompt-injection priority. Non-invasive placement was chosen over exact adjacency.

Manual verification requested:

  • None beyond the above; reviewers can confirm by duplicating any lorebook entry and checking the copy's drawer matches the source.

UI evidence

image (in larger view Duplicate and Trash buttons hidden by default until moused over) image image

🔄 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/2157 **Author:** [@kolacheee](https://github.com/kolacheee) **Created:** 6/4/2026 **Status:** ✅ Merged **Merged:** 6/4/2026 **Merged by:** [@cha1latte](https://github.com/cha1latte) **Base:** `refactor` ← **Head:** `feat/lorebook-entry-duplication` --- ### 📝 Commits (1) - [`4038969`](https://github.com/Pasta-Devs/Marinara-Engine/commit/40389697f5ec8aa7a1953786177a437a33b463c6) feat: duplicate lorebook entries ### 📊 Changes **2 files changed** (+46 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `src/features/catalog/lorebooks/components/entries/LorebookEntryRow.tsx` (+23 -1) 📝 `src/features/catalog/lorebooks/hooks/use-lorebooks.ts` (+23 -0) </details> ### 📄 Description ## Linked issue Closes #2127 — Halfway, this PR is the entry-duplication part. Nested folders will follow as a separate PR. ## Why this change - Re-creating a lorebook entry by hand — re-typing its keys, filters, injection/activation settings, and content — is tedious when you want a near-identical variant. A one-click duplicate is a pure QoL win, and it's fully additive (no existing behavior changes). ## What changed - **`useDuplicateLorebookEntry` hook** (`hooks/use-lorebooks.ts`) — clones an entry through the existing generic `storageApi.create("lorebook-entries", …)` path: the create schema strips the server-managed `id`/`createdAt`/`updatedAt`, the name gets a `" (Copy)"` suffix, and **every other field carries over verbatim** — `folderId`, keys/secondaryKeys, all character/tag/trigger filters, position/depth/order, probability, timing, grouping, embedding, and activation conditions. Invalidates the same queries as `useCreateLorebookEntry`. - **Duplicate button** (`components/entries/LorebookEntryRow.tsx`) — a `Copy`-icon button in the per-row actions, immediately left of the existing delete button. Mirrors delete's hover-reveal pattern (always visible on mobile) with neutral styling; disabled while the mutation is in flight. **No backend/Rust changes.** Unlike `duplicate_character` (which needs Rust to deep-copy the managed avatar file on disk), lorebook entries have no managed on-disk asset — their entire CRUD already rides the generic storage gateway — so duplication is a pure client-side row clone. No new Tauri command, no `lib.rs` registration. ## Refactor impact Primary owner: Catalog / Lorebooks editor (frontend) Impact areas reviewed: - `hooks/use-lorebooks.ts` (new `useDuplicateLorebookEntry` mutation) and `components/entries/LorebookEntryRow.tsx` (the row's duplicate button). No engine, storage-contract, or Rust changes. Boundary notes: - Confined to the lorebooks feature UI and its React Query layer. Reuses the existing generic `storageApi.create` and the established `createLorebookEntrySchema` rather than adding a parallel path; no new storage collection, command, or cross-boundary call. Pressure points touched: - None of the flagged ones — no `ModeSurface`/`GameSurface`/shared mode UI, no `src-tauri/src/lib.rs` command registration, no import modules. Lorebook entry row only. ## Validation - [x] Matching validation command passes locally (for example `pnpm typecheck`, `pnpm build`, `pnpm check:architecture`, `pnpm check:docs`, or full `pnpm check` when warranted) - [x] Full `pnpm check` passes before PR push/handoff - [x] Human/manual validation completed by contributor or reviewer ### Manual verification notes - `pnpm typecheck` (`tsc -b`) clean; `check:architecture`, `check:frontend`, `check:discovery`, `check:docs`, and `check:unused` all pass locally. - Verified by hand in the running Tauri build: clicking the duplicate icon creates a `"… (Copy)"` entry that preserves the source's content, keys, position (`↑Char`), order, and probability (confirmed token count and inline controls match the original); the copy lands in the same container; repeated duplication works. Confirmed in **light and dark mode**, and at the **mobile breakpoint** (≤768px — the inline controls collapse into the `⋯` menu and the copy/delete buttons go always-visible, no overflow, names truncate). ## Feature Discoverability - [ ] Updated `src/features/shell/discovery/` because this PR adds or materially changes a user-discoverable feature, workflow, setting, mode, panel, import path, agent, media capability, or advanced tool. - [x] N/A because this PR is only a bugfix, refactor, test, docs, internal wiring, visual polish, copy edit, or compatibility fix and does not add a new thing users need to find. Reason: - N/A — adds a per-row action button alongside the existing delete action within the lorebook editor; a QoL action inside an existing panel, not a new discoverable surface. ## Docs and release impact - [x] No docs changes needed - [ ] Updated `README.md` - [ ] Updated `CONTRIBUTING.md` - [ ] Updated `docs/developer/` - [ ] Updated repo skills or `AGENTS.md` - [x] Confirmed this PR does not restore old staging/package-workspace/release claims ## Proof Core claim: - A one-click duplicate produces a faithful, independent copy of a lorebook entry in the same container, with all activation/injection settings preserved and only the name changed. Verification run: - `pnpm typecheck` plus `check:architecture` / `check:frontend` / `check:discovery` / `check:docs` / `check:unused` (all green), plus manual in-app testing in the Tauri build. Evidence: - The duplicated rows mirror the source's `↑Char` position, `ord: 1`, `p: 100%`, and `# 12` token count (identical content) — differing only by the `" (Copy)"` name — confirming the whole entry (not just the name) is cloned. - The duplicate button renders consistently in light + dark mode and at the mobile breakpoint. Known behavior (intended, not a bug): - The copy inherits the source's exact `order`, so it sorts immediately after the original in the common case. When several entries share the **same** `order` value (e.g., all at the default), the copy lands at the end of that same-order group rather than directly beneath the source. This is deliberate: the only way to force flush placement is to renumber the whole container, which would overwrite every sibling's `order` — and `order` also drives prompt-injection priority. Non-invasive placement was chosen over exact adjacency. Manual verification requested: - None beyond the above; reviewers can confirm by duplicating any lorebook entry and checking the copy's drawer matches the source. ## UI evidence <img width="1263" height="542" alt="image" src="https://github.com/user-attachments/assets/a1776202-39db-44d9-896e-e84088d34bff" /> (in larger view Duplicate and Trash buttons hidden by default until moused over) <img width="1071" height="780" alt="image" src="https://github.com/user-attachments/assets/6edcb338-36c3-4c98-94de-c418e765619b" /> <img width="1072" height="780" alt="image" src="https://github.com/user-attachments/assets/6c58d490-8541-4908-b62d-aa848a26ccf3" /> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-22 04:16:27 +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#5452
No description provided.