[PR #845] [MERGED] feat(lorebooks): add keyword-test panel to lorebook editor #4804

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

📋 Pull Request Information

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

Base: main ← Head: feat/lorebook-keyword-test-panel


📝 Commits (3)

  • 7c7d5ec feat(lorebooks): add keyword-test panel to lorebook editor (#816)
  • 52ebd4d Merge branch 'main' into feat/lorebook-keyword-test-panel
  • ab42137 Merge branch 'main' into feat/lorebook-keyword-test-panel

📊 Changes

5 files changed (+241 additions, -81 deletions)

View changed files

📝 packages/client/src/components/lorebooks/LorebookEditor.tsx (+119 -0)
📝 packages/client/src/components/lorebooks/LorebookEntryRow.tsx (+41 -1)
📝 packages/server/src/services/lorebook/keyword-scanner.ts (+1 -80)
📝 packages/shared/src/index.ts (+1 -0)
➕ packages/shared/src/utils/lorebook-keyword-matching.ts (+79 -0)

📄 Description

Linked issue

Closes #816

Why this change

Lorebook authors — especially newcomers to World Info — don't have a good way to sanity-check which entries would actually be triggered by a given paragraph of chat text. Today the only ways to find out are (a) load the lorebook into a chat and roleplay until you happen to hit the keys, or (b) read every entry's keys list and mentally simulate the matcher (which gets unwieldy with regex / whole-word / case-sensitive / selective + secondary-keys / selectiveLogic in the mix). The result is keys that fire too eagerly or not at all, and bloated entries that the author has no fast feedback loop to tune.

This adds a focused authoring aid right where the entries are edited: paste sample text, see which entries that text would activate.

Per maintainer triage on #816 (cha1latte's normal-scope label and "least risky next step is to keep it scoped to keyword-trigger preview behavior"), this PR deliberately covers only the keyword-trigger preview surface. Context-budget, memory-aware, and runtime-state simulation are not included.

What changed

New collapsible "Keyword test" panel at the top of the Entries tab (packages/client/src/components/lorebooks/LorebookEditor.tsx). Collapsed by default so it doesn't crowd the editor for users who don't need it. When expanded:

  • Multi-line textarea for sample chat text (debounced 150ms).
  • Header summary chip showing match count (N matches).
  • Below-textarea summary line: N of M enabled entries would activate.
  • Inline explanation of what's in scope vs. out of scope.

Per-row match indicator (packages/client/src/components/lorebooks/LorebookEntryRow.tsx). When the preview is active, matched entries get:

  • An emerald 3px left-edge accent strip (absolute-positioned, doesn't fight the row's existing ring / border radius).
  • A small "Would activate" chip with a sparkles icon, placed just after the status dot.
  • Constant entries get the same treatment in amber + "Always active" — they trigger regardless of text, so visually flagging them keeps the preview honest.

Shared keyword-matching helpers (packages/shared/src/utils/lorebook-keyword-matching.ts). The three pure functions that decide whether a key matches text — testKeyword, testPrimaryKeys, testSecondaryKeys — were previously inline in packages/server/src/services/lorebook/keyword-scanner.ts. Moved them to a new shared util module so the editor preview and the real server scanner use the same code path. This is the load-bearing piece of the PR: it prevents the preview from drifting from real activation behavior over time.

Server scanner now imports the shared helpers. No behavior change on the server — the deleted local copies were byte-identical to the new shared versions.

Explicit scope

In scope (preview honors these):

  • keys (primary)
  • secondaryKeys + selective + selectiveLogic
  • useRegex, matchWholeWords, caseSensitive
  • enabled (disabled entries are skipped)
  • constant (flagged separately as "Always active")

Out of scope (deliberately not simulated):

  • Timing: sticky / cooldown / delay (no chat history → no runtime state)
  • probability (preview should be deterministic)
  • characterFilterMode / characterTagFilterMode / generationTriggerFilterMode (depend on a live chat context)
  • Semantic embedding fallback (preview is keyword-focused per triage)
  • Recursive scan (out of scope per triage)
  • Group selection / groupWeight (out of scope per triage)

These can land in follow-up PRs if the keyword-only preview proves useful.

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

  • Open any lorebook with multiple keyword-keyed entries. Switch to the Entries tab. Confirm the "Keyword test" header is present and collapsed by default with the flask icon.
  • Expand the panel and confirm the explanatory caption + textarea + clear-X are present.
  • Paste a paragraph that contains the exact primary key text of a couple of entries (e.g. for a character lorebook, the names of characters with their own entries). Confirm those rows pick up an emerald left-edge accent and a "Would activate" chip near the entry name, the header chip shows N matches, and the summary line shows N of M enabled entries would activate.
  • Confirm other entries stay unhighlighted.
  • Click the clear-X — all accents and chips should disappear, header chip should hide.
  • If the lorebook has a constant entry, confirm it's flagged with an amber accent + "Always active" chip whenever there's any text in the box, and that disabling that entry (toggle) removes the flag (since enabled: false short-circuits before constant).
  • Edit an entry to use regex (e.g. a regex like ^Mr\.\s+\w+) and confirm the preview honors the regex flag.
  • Toggle the entry's "Selective" status and add a secondary key. Type text matching the primary key but not the secondary — the entry should NOT highlight. Add text matching both — the entry SHOULD highlight.
  • Toggle caseSensitive and matchWholeWords on an entry and confirm preview matches change accordingly.
  • Verify behavior with an invalid regex key (the helper falls back to plain-text substring matching — should not crash the panel).
  • Verify the panel stays collapsed across navigations (state is component-local — not persisted).

I tested most of these on my fork deployment with a real lorebook (23 entries, Selective mode mix); leaving the boxes unchecked per repo CLAUDE.md so the maintainer can re-verify on their own setup.

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)

The panel's collapsed state shows only the flask icon and the Keyword test label inline with the search/sort row. Expanded shows the scope blurb, textarea, and (when text is present) the summary line. Per-row indicators are a 3px emerald (or amber for constant) left-edge stripe + an emerald (or amber) sparkles + Would activate (or Always active) chip placed immediately after the status dot.


🔄 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/845 **Author:** [@Romuromylus](https://github.com/Romuromylus) **Created:** 5/14/2026 **Status:** ✅ Merged **Merged:** 5/14/2026 **Merged by:** [@Romuromylus](https://github.com/Romuromylus) **Base:** `main` ← **Head:** `feat/lorebook-keyword-test-panel` --- ### 📝 Commits (3) - [`7c7d5ec`](https://github.com/Pasta-Devs/Marinara-Engine/commit/7c7d5ec7787565af80588fe751be8762b4bfcc70) feat(lorebooks): add keyword-test panel to lorebook editor (#816) - [`52ebd4d`](https://github.com/Pasta-Devs/Marinara-Engine/commit/52ebd4d25efa9f421f9b29afc8ed17e006bd9c7c) Merge branch 'main' into feat/lorebook-keyword-test-panel - [`ab42137`](https://github.com/Pasta-Devs/Marinara-Engine/commit/ab421375ed16c0d0c8b5f61b5c23aa037c44e59b) Merge branch 'main' into feat/lorebook-keyword-test-panel ### 📊 Changes **5 files changed** (+241 additions, -81 deletions) <details> <summary>View changed files</summary> 📝 `packages/client/src/components/lorebooks/LorebookEditor.tsx` (+119 -0) 📝 `packages/client/src/components/lorebooks/LorebookEntryRow.tsx` (+41 -1) 📝 `packages/server/src/services/lorebook/keyword-scanner.ts` (+1 -80) 📝 `packages/shared/src/index.ts` (+1 -0) ➕ `packages/shared/src/utils/lorebook-keyword-matching.ts` (+79 -0) </details> ### 📄 Description ## Linked issue Closes #816 ## Why this change Lorebook authors — especially newcomers to World Info — don't have a good way to sanity-check which entries would actually be triggered by a given paragraph of chat text. Today the only ways to find out are (a) load the lorebook into a chat and roleplay until you happen to hit the keys, or (b) read every entry's keys list and mentally simulate the matcher (which gets unwieldy with regex / whole-word / case-sensitive / selective + secondary-keys / selectiveLogic in the mix). The result is keys that fire too eagerly or not at all, and bloated entries that the author has no fast feedback loop to tune. This adds a focused authoring aid right where the entries are edited: paste sample text, see which entries that text would activate. Per maintainer triage on #816 (cha1latte's `normal-scope` label and "least risky next step is to keep it scoped to keyword-trigger preview behavior"), this PR deliberately covers only the keyword-trigger preview surface. Context-budget, memory-aware, and runtime-state simulation are not included. ## What changed **New collapsible "Keyword test" panel at the top of the Entries tab** (`packages/client/src/components/lorebooks/LorebookEditor.tsx`). Collapsed by default so it doesn't crowd the editor for users who don't need it. When expanded: - Multi-line textarea for sample chat text (debounced 150ms). - Header summary chip showing match count (`N matches`). - Below-textarea summary line: `N of M enabled entries would activate.` - Inline explanation of what's in scope vs. out of scope. **Per-row match indicator** (`packages/client/src/components/lorebooks/LorebookEntryRow.tsx`). When the preview is active, matched entries get: - An emerald 3px left-edge accent strip (absolute-positioned, doesn't fight the row's existing ring / border radius). - A small "Would activate" chip with a sparkles icon, placed just after the status dot. - Constant entries get the same treatment in amber + "Always active" — they trigger regardless of text, so visually flagging them keeps the preview honest. **Shared keyword-matching helpers** (`packages/shared/src/utils/lorebook-keyword-matching.ts`). The three pure functions that decide whether a key matches text — `testKeyword`, `testPrimaryKeys`, `testSecondaryKeys` — were previously inline in `packages/server/src/services/lorebook/keyword-scanner.ts`. Moved them to a new shared util module so the editor preview and the real server scanner use the same code path. This is the load-bearing piece of the PR: it prevents the preview from drifting from real activation behavior over time. **Server scanner now imports the shared helpers.** No behavior change on the server — the deleted local copies were byte-identical to the new shared versions. ### Explicit scope In scope (preview honors these): - `keys` (primary) - `secondaryKeys` + `selective` + `selectiveLogic` - `useRegex`, `matchWholeWords`, `caseSensitive` - `enabled` (disabled entries are skipped) - `constant` (flagged separately as "Always active") Out of scope (deliberately not simulated): - Timing: `sticky` / `cooldown` / `delay` (no chat history → no runtime state) - `probability` (preview should be deterministic) - `characterFilterMode` / `characterTagFilterMode` / `generationTriggerFilterMode` (depend on a live chat context) - Semantic embedding fallback (preview is keyword-focused per triage) - Recursive scan (out of scope per triage) - Group selection / `groupWeight` (out of scope per triage) These can land in follow-up PRs if the keyword-only preview proves useful. ## 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 - Open any lorebook with multiple keyword-keyed entries. Switch to the Entries tab. Confirm the "Keyword test" header is present and collapsed by default with the flask icon. - Expand the panel and confirm the explanatory caption + textarea + clear-X are present. - Paste a paragraph that contains the exact primary key text of a couple of entries (e.g. for a character lorebook, the names of characters with their own entries). Confirm those rows pick up an emerald left-edge accent and a "Would activate" chip near the entry name, the header chip shows `N matches`, and the summary line shows `N of M enabled entries would activate.` - Confirm other entries stay unhighlighted. - Click the clear-X — all accents and chips should disappear, header chip should hide. - If the lorebook has a constant entry, confirm it's flagged with an amber accent + "Always active" chip whenever there's any text in the box, and that disabling that entry (toggle) removes the flag (since `enabled: false` short-circuits before constant). - Edit an entry to use regex (e.g. a regex like `^Mr\.\s+\w+`) and confirm the preview honors the regex flag. - Toggle the entry's "Selective" status and add a secondary key. Type text matching the primary key but not the secondary — the entry should NOT highlight. Add text matching both — the entry SHOULD highlight. - Toggle `caseSensitive` and `matchWholeWords` on an entry and confirm preview matches change accordingly. - Verify behavior with an invalid regex key (the helper falls back to plain-text substring matching — should not crash the panel). - Verify the panel stays collapsed across navigations (state is component-local — not persisted). I tested most of these on my fork deployment with a real lorebook (23 entries, Selective mode mix); leaving the boxes unchecked per repo CLAUDE.md so the maintainer can re-verify on their own setup. ## 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) The panel's collapsed state shows only the flask icon and the `Keyword test` label inline with the search/sort row. Expanded shows the scope blurb, textarea, and (when text is present) the summary line. Per-row indicators are a 3px emerald (or amber for constant) left-edge stripe + an emerald (or amber) `sparkles + Would activate` (or `Always active`) chip placed immediately after the status dot. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-22 04:10:48 +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#4804
No description provided.