[PR #6575] [MERGED] feat(lorebooks): activate entries on a Decision model statement #7232

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

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/6575
Author: @kolacheee
Created: 9/23/2026
Status: ✅ Merged
Merged: 9/23/2026
Merged by: @kolacheee

Base: staging ← Head: feat/lorebook-decision-activation


📝 Commits (9)

  • bf0518d feat(lorebooks): activate entries on a Decision model statement
  • 90410a4 docs(lorebooks): document decision activation for entries
  • 197b74d fix(lorebooks): let Trigger decide when secondary keys reject a match; validate Mari's decision fields
  • b208fa1 fix(lorebooks): gate location entries, follow resolved text, rank semantic asks, one budget per turn
  • 527fcb5 fix(lorebooks): an unanswered semantic statement holds a slot only while it can still be asked; hint mentions map entries
  • aaa8176 docs(lorebooks): list every path that asks a Require statement
  • be6a7a5 fix(lorebooks): scope decision discovery's recursion like the real scan
  • e60d341 test(lorebooks): assert scoped decision discovery still recurses
  • 8637ef7 docs(decision): say exactly what a decision model reads

📊 Changes

30 files changed (+1167 additions, -24 deletions)

View changed files

📝 CHANGELOG.md (+4 -0)
📝 docs/connections/decision-models.md (+13 -1)
📝 docs/lorebooks/entries.md (+25 -0)
📝 docs/prompts/conditional-prompts.md (+1 -1)
📝 packages/client/src/components/chat/ChatRoleplayPanels.tsx (+5 -3)
📝 packages/client/src/components/lorebooks/LorebookEntryRow.tsx (+58 -0)
📝 packages/client/src/components/ui/DecisionStatementNote.tsx (+14 -4)
📝 packages/client/src/hooks/use-lorebooks.ts (+8 -4)
📝 packages/client/src/localization/locales/en.json (+11 -0)
📝 packages/server/src/db/schema/lorebooks.ts (+5 -0)
📝 packages/server/src/routes/backup.routes.ts (+2 -0)
📝 packages/server/src/routes/chats.routes.ts (+16 -0)
📝 packages/server/src/routes/generate.routes.ts (+18 -1)
📝 packages/server/src/routes/generate/dry-run-route.ts (+16 -0)
📝 packages/server/src/routes/lorebooks.routes.ts (+29 -0)
📝 packages/server/src/services/decision/prompt-decisions.ts (+54 -0)
📝 packages/server/src/services/import/marinara.importer.ts (+2 -0)
📝 packages/server/src/services/import/st-character.importer.ts (+2 -0)
📝 packages/server/src/services/import/st-lorebook.importer.ts (+6 -0)
📝 packages/server/src/services/lorebook/character-book-sync.ts (+3 -0)

...and 10 more files

📄 Description

Important

Contributions target staging. Only SpicyMarinara may promote this repository's staging branch or a same-repository hotfix/* branch to main.
Outside and first-time contributors also require an approving review from SpicyMarinara.

Linked issue

Closes #6570

Why this change

  • Passing mentions pull in whole entries. An entry keyed on "dragon" was injected when someone only talked about dragons, the same as when one landed in the courtyard.
  • Paraphrases and situations had no trigger. A forest entry did not fire for "under the dark pines", and "combat rules" had to be constant (always paying its tokens) or keyed on words that do not reliably appear.
  • {{#if decision:"..."}} inside an entry (#6569) only trims the text of an entry that has already activated: it still takes budget, feeds recursion and starts timers. Nothing could decide whether the entry activates at all.

What changed

  • Two entry fields, decisionStatement and decisionMode (off / require / trigger), in the shared schema and type, the database, and storage. Rows written before this read as off.
    • Require: the entry activates as it otherwise would (keywords, Constant, semantic matching), and only when the statement is also true.
    • Trigger: the statement alone can activate it whenever its keywords do not, including when a secondary-key rule rejects the keyword match; its keywords still work too. It shows as a new decision activation source.
    • No answer reads as no, so nothing changes for users without a Decision model.
  • Scanner: a statement is asked only once the entry would otherwise activate, after its filters, timing and probability roll, and for Require after its keywords matched. Sticky entries are not asked again.
  • processLorebooks: the scan is synchronous and the budget pass commits macro side effects, so neither can wait for a model. A pure pre-scan (recursion included, over raw entry text) collects the entries waiting on a statement, and they are asked in one request. A second round covers entries reached only through another decision entry. The real scan then runs once with the answers, and the probability rolls are shared across passes.
  • Generation asks through the #6569 per-turn cache, so a lorebook entry and a {{#if decision}} asking the same statement share one answer, and a regeneration activates the same entries. Lorebook statements count toward Decision statements per turn, after the prompt's own. This is wired into all four chat-generation scans: Conversation, Roleplay without a preset, the preset lorebook marker, and Game mode.
  • Previews never ask. Peek Prompt, the dry run and the lorebook scan preview read cached answers only, and Peek Prompt reports unanswered lorebook statements like prompt ones.
  • Import and export keep the fields in the native envelope, the SillyTavern-compatible export (as extra entry keys, which SillyTavern ignores) and its import, character books (V2/V3/charx), the backup export, and copying entries between books. Professor Mari can read and set them. Imported files that use decision activation trigger the #6569 import notice.
  • Editor: a Decision field in the entry drawer with Off / Require / Trigger (styled like the selective-logic buttons), the statement, a per-mode hint (including that a Trigger statement is asked every turn), and the missing-Decision-model warning.
  • Docs: a Decision activation section in docs/lorebooks/entries.md, plus links from the Decision Models and Conditional Prompts guides. The Decision Models guide also gains a "What the model sees" section: only the statement and the recent saved chat messages (the last 5 for decision statements and Smart order), never the preset, cards, persona description, lorebook entries or anything inserted @ Depth.
  • Not covered: Game setup, experience generation, and the lorebook scans agents run for themselves have no chat turn to ask about, so they read decision entries as no. The docs say so. Bulk edit does not set the Decision field.

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

Run by the agent:

  • pnpm check, pnpm localization:check and pnpm regression:node (362 of 362 regressions pass) on the branch rebased onto staging 06bf1a6d6.
  • New scripts/regressions/lorebook-decision-activation.regression.ts:
    • Scanner rules: Require, Trigger, keyword-activated Trigger, a Constant with Require, a probability-0 entry never asked, an empty statement treated as off, and sticky entries staying without being asked.
    • Ask rounds: one request, a second for an entry reached through recursion from a Trigger entry's text, and nothing for an entry whose keywords never matched.
    • Real routes against a fake System One server: Roleplay, Conversation and a preset's lorebook marker each ask and include the entry; a regeneration reuses the answer; a new message asks again; a fresh chat's Peek Prompt never asks and reports the statement.
    • Round trips: compatible export into the SillyTavern importer, and native export into the native importer.
    • Professor Mari: creates an entry with the fields, clears the statement with an empty string, and refuses an unknown mode.
    • Each wiring point was mutation-checked: reverting it makes the regression fail.
  • Local CodeRabbit review: 3 findings, all fixed. A Trigger statement now also applies when secondary keys reject a keyword match. Professor Mari refuses an unknown mode and lets an empty statement clear the field. The native-import assertion checked the source book instead of the imported copy. The fix commit then reviewed clean.

Please verify manually:

  • Open a lorebook entry's drawer, set Decision to Require and to Trigger, type a statement, and confirm it saves, reloads, and shows the right hint for each mode.
  • With Decision model set to None, confirm the warning appears under the statement.
  • In a chat with a Decision model set, give an entry no keywords, set it to Trigger with a statement that fits your next message, send the message, and confirm the entry shows in the active lorebook list with the decision source and in Peek Prompt.
  • Set an entry keyed on a word to Require with a statement that is false for your next message, mention the word in passing, and confirm the entry stays out.
  • Export a lorebook with a decision entry (both formats), import it again, and confirm the field survived. Import a plain SillyTavern world info file and confirm it still imports with Decision off.

Docs and release impact

  • No docs changes needed
  • Updated docs (README / CONTRIBUTING / android/README / CHANGELOG) as needed
  • Translated docs on the docs-i18n branch updated to match, or a [docs-i18n] follow-up issue opened (see CONTRIBUTING.md § Translated documentation)
  • Version/release files updated (only if this PR includes a version bump)

Changed user docs for the batched [docs-i18n] follow-up (#6532): docs/lorebooks/entries.md (new Decision activation section), docs/connections/decision-models.md (one bullet, one sentence, and a new "What the model sees" section), docs/prompts/conditional-prompts.md (one sentence).

UI evidence (if applicable)

Not captured by the agent. The UI change is one field group in the lorebook entry drawer (three mode buttons, a statement box, a hint line and the missing-model warning) and a decision label in the active lorebook list.

Summary by CodeRabbit

  • New Features
    • Configure a lorebook entry’s Decision statement as Off, Require, or Trigger. Require adds a Decision check to normal activation; Trigger lets a statement activate an entry without matching keywords.
    • Decision checks use recent chat messages, are answered once per turn, and count as “no” when no Decision model is available or no answer is received.
    • Preview tools report unanswered checks without asking the Decision model, and active context identifies entries activated by a Decision check.
    • Decision activation settings are preserved when lorebooks are imported or exported.
  • Documentation
    • Added guidance on Decision activation, what information the model considers, and how activation differs from conditional prompt content.

🔄 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/6575 **Author:** [@kolacheee](https://github.com/kolacheee) **Created:** 9/23/2026 **Status:** ✅ Merged **Merged:** 9/23/2026 **Merged by:** [@kolacheee](https://github.com/kolacheee) **Base:** `staging` ← **Head:** `feat/lorebook-decision-activation` --- ### 📝 Commits (9) - [`bf0518d`](https://github.com/Pasta-Devs/Marinara-Engine/commit/bf0518de982b1560d093290e6aa9563c3e6eafc0) feat(lorebooks): activate entries on a Decision model statement - [`90410a4`](https://github.com/Pasta-Devs/Marinara-Engine/commit/90410a4c858cf1035df2280240bb3cba86aa44a9) docs(lorebooks): document decision activation for entries - [`197b74d`](https://github.com/Pasta-Devs/Marinara-Engine/commit/197b74de21fec9171778f2b3d57dd8bf45d90740) fix(lorebooks): let Trigger decide when secondary keys reject a match; validate Mari's decision fields - [`b208fa1`](https://github.com/Pasta-Devs/Marinara-Engine/commit/b208fa1b488d71f8154148ae8d5a93d0af560777) fix(lorebooks): gate location entries, follow resolved text, rank semantic asks, one budget per turn - [`527fcb5`](https://github.com/Pasta-Devs/Marinara-Engine/commit/527fcb5ad58c79254e03b179a7f28a414de7ecaa) fix(lorebooks): an unanswered semantic statement holds a slot only while it can still be asked; hint mentions map entries - [`aaa8176`](https://github.com/Pasta-Devs/Marinara-Engine/commit/aaa8176c5b7b66823284f885651179527cc9fd15) docs(lorebooks): list every path that asks a Require statement - [`be6a7a5`](https://github.com/Pasta-Devs/Marinara-Engine/commit/be6a7a58f3157ad4d09d01abd836ebbf1d23ff2d) fix(lorebooks): scope decision discovery's recursion like the real scan - [`e60d341`](https://github.com/Pasta-Devs/Marinara-Engine/commit/e60d3410d2db4e3d285bbb7c5db7a2f43d9846be) test(lorebooks): assert scoped decision discovery still recurses - [`8637ef7`](https://github.com/Pasta-Devs/Marinara-Engine/commit/8637ef7b12abd0f55406c3d45ab7b8805660cedc) docs(decision): say exactly what a decision model reads ### 📊 Changes **30 files changed** (+1167 additions, -24 deletions) <details> <summary>View changed files</summary> 📝 `CHANGELOG.md` (+4 -0) 📝 `docs/connections/decision-models.md` (+13 -1) 📝 `docs/lorebooks/entries.md` (+25 -0) 📝 `docs/prompts/conditional-prompts.md` (+1 -1) 📝 `packages/client/src/components/chat/ChatRoleplayPanels.tsx` (+5 -3) 📝 `packages/client/src/components/lorebooks/LorebookEntryRow.tsx` (+58 -0) 📝 `packages/client/src/components/ui/DecisionStatementNote.tsx` (+14 -4) 📝 `packages/client/src/hooks/use-lorebooks.ts` (+8 -4) 📝 `packages/client/src/localization/locales/en.json` (+11 -0) 📝 `packages/server/src/db/schema/lorebooks.ts` (+5 -0) 📝 `packages/server/src/routes/backup.routes.ts` (+2 -0) 📝 `packages/server/src/routes/chats.routes.ts` (+16 -0) 📝 `packages/server/src/routes/generate.routes.ts` (+18 -1) 📝 `packages/server/src/routes/generate/dry-run-route.ts` (+16 -0) 📝 `packages/server/src/routes/lorebooks.routes.ts` (+29 -0) 📝 `packages/server/src/services/decision/prompt-decisions.ts` (+54 -0) 📝 `packages/server/src/services/import/marinara.importer.ts` (+2 -0) 📝 `packages/server/src/services/import/st-character.importer.ts` (+2 -0) 📝 `packages/server/src/services/import/st-lorebook.importer.ts` (+6 -0) 📝 `packages/server/src/services/lorebook/character-book-sync.ts` (+3 -0) _...and 10 more files_ </details> ### 📄 Description > [!IMPORTANT] > Contributions target `staging`. Only `SpicyMarinara` may promote this repository's `staging` branch or a same-repository `hotfix/*` branch to `main`. > Outside and first-time contributors also require an approving review from `SpicyMarinara`. <!-- See CONTRIBUTING.md § Branches. --> ## Linked issue Closes #6570 ## Why this change - **Passing mentions pull in whole entries.** An entry keyed on "dragon" was injected when someone only talked about dragons, the same as when one landed in the courtyard. - **Paraphrases and situations had no trigger.** A forest entry did not fire for "under the dark pines", and "combat rules" had to be constant (always paying its tokens) or keyed on words that do not reliably appear. - `{{#if decision:"..."}}` inside an entry (#6569) only trims the text of an entry that has already activated: it still takes budget, feeds recursion and starts timers. Nothing could decide whether the entry activates at all. ## What changed - **Two entry fields**, `decisionStatement` and `decisionMode` (`off` / `require` / `trigger`), in the shared schema and type, the database, and storage. Rows written before this read as `off`. - **Require:** the entry activates as it otherwise would (keywords, Constant, semantic matching), and only when the statement is also true. - **Trigger:** the statement alone can activate it whenever its keywords do not, including when a secondary-key rule rejects the keyword match; its keywords still work too. It shows as a new `decision` activation source. - **No answer reads as no**, so nothing changes for users without a Decision model. - **Scanner:** a statement is asked only once the entry would otherwise activate, after its filters, timing and probability roll, and for Require after its keywords matched. Sticky entries are not asked again. - **`processLorebooks`:** the scan is synchronous and the budget pass commits macro side effects, so neither can wait for a model. A pure pre-scan (recursion included, over raw entry text) collects the entries waiting on a statement, and they are asked in one request. A second round covers entries reached only through another decision entry. The real scan then runs once with the answers, and the probability rolls are shared across passes. - **Generation** asks through the #6569 per-turn cache, so a lorebook entry and a `{{#if decision}}` asking the same statement share one answer, and a regeneration activates the same entries. Lorebook statements count toward **Decision statements per turn**, after the prompt's own. This is wired into all four chat-generation scans: Conversation, Roleplay without a preset, the preset lorebook marker, and Game mode. - **Previews never ask.** Peek Prompt, the dry run and the lorebook scan preview read cached answers only, and Peek Prompt reports unanswered lorebook statements like prompt ones. - **Import and export keep the fields** in the native envelope, the SillyTavern-compatible export (as extra entry keys, which SillyTavern ignores) and its import, character books (V2/V3/charx), the backup export, and copying entries between books. Professor Mari can read and set them. Imported files that use decision activation trigger the #6569 import notice. - **Editor:** a Decision field in the entry drawer with Off / Require / Trigger (styled like the selective-logic buttons), the statement, a per-mode hint (including that a Trigger statement is asked every turn), and the missing-Decision-model warning. - **Docs:** a Decision activation section in `docs/lorebooks/entries.md`, plus links from the Decision Models and Conditional Prompts guides. The Decision Models guide also gains a "What the model sees" section: only the statement and the recent saved chat messages (the last 5 for decision statements and Smart order), never the preset, cards, persona description, lorebook entries or anything inserted @ Depth. - **Not covered:** Game setup, experience generation, and the lorebook scans agents run for themselves have no chat turn to ask about, so they read decision entries as no. The docs say so. Bulk edit does not set the Decision field. ## 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 Run by the agent: - `pnpm check`, `pnpm localization:check` and `pnpm regression:node` (362 of 362 regressions pass) on the branch rebased onto staging `06bf1a6d6`. - New `scripts/regressions/lorebook-decision-activation.regression.ts`: - **Scanner rules:** Require, Trigger, keyword-activated Trigger, a Constant with Require, a probability-0 entry never asked, an empty statement treated as off, and sticky entries staying without being asked. - **Ask rounds:** one request, a second for an entry reached through recursion from a Trigger entry's text, and nothing for an entry whose keywords never matched. - **Real routes** against a fake System One server: Roleplay, Conversation and a preset's lorebook marker each ask and include the entry; a regeneration reuses the answer; a new message asks again; a fresh chat's Peek Prompt never asks and reports the statement. - **Round trips:** compatible export into the SillyTavern importer, and native export into the native importer. - **Professor Mari:** creates an entry with the fields, clears the statement with an empty string, and refuses an unknown mode. - Each wiring point was mutation-checked: reverting it makes the regression fail. - Local CodeRabbit review: 3 findings, all fixed. A Trigger statement now also applies when secondary keys reject a keyword match. Professor Mari refuses an unknown mode and lets an empty statement clear the field. The native-import assertion checked the source book instead of the imported copy. The fix commit then reviewed clean. Please verify manually: - Open a lorebook entry's drawer, set **Decision** to **Require** and to **Trigger**, type a statement, and confirm it saves, reloads, and shows the right hint for each mode. - With **Decision model** set to **None**, confirm the warning appears under the statement. - In a chat with a Decision model set, give an entry no keywords, set it to **Trigger** with a statement that fits your next message, send the message, and confirm the entry shows in the active lorebook list with the **decision** source and in **Peek Prompt**. - Set an entry keyed on a word to **Require** with a statement that is false for your next message, mention the word in passing, and confirm the entry stays out. - Export a lorebook with a decision entry (both formats), import it again, and confirm the field survived. Import a plain SillyTavern world info file and confirm it still imports with Decision off. ## Docs and release impact - [ ] No docs changes needed - [ ] Updated docs (README / CONTRIBUTING / android/README / CHANGELOG) as needed - [ ] Translated docs on the `docs-i18n` branch updated to match, or a `[docs-i18n]` follow-up issue opened (see CONTRIBUTING.md § Translated documentation) - [ ] Version/release files updated (only if this PR includes a version bump) Changed user docs for the batched `[docs-i18n]` follow-up (#6532): `docs/lorebooks/entries.md` (new Decision activation section), `docs/connections/decision-models.md` (one bullet, one sentence, and a new "What the model sees" section), `docs/prompts/conditional-prompts.md` (one sentence). ## UI evidence (if applicable) Not captured by the agent. The UI change is one field group in the lorebook entry drawer (three mode buttons, a statement box, a hint line and the missing-model warning) and a `decision` label in the active lorebook list. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Configure a lorebook entry’s Decision statement as Off, Require, or Trigger. Require adds a Decision check to normal activation; Trigger lets a statement activate an entry without matching keywords. * Decision checks use recent chat messages, are answered once per turn, and count as “no” when no Decision model is available or no answer is received. * Preview tools report unanswered checks without asking the Decision model, and active context identifies entries activated by a Decision check. * Decision activation settings are preserved when lorebooks are imported or exported. * **Documentation** * Added guidance on Decision activation, what information the model considers, and how activation differs from conditional prompt content. <!-- 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:17:46 +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#7232
No description provided.