[PR #5373] [MERGED] fix(prompt): preserve lorebook tags in agent requests #6742

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

📋 Pull Request Information

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

Base: staging ← Head: fix/5372-lorebook-agent-verbatim


📝 Commits (2)

  • 3499abd test(prompt): reproduce agent lorebook escaping
  • 5d9a24f fix(prompt): preserve lorebook tags in agent requests

📊 Changes

3 files changed (+31 additions, -5 deletions)

View changed files

📝 CHANGELOG.md (+1 -0)
📝 packages/server/src/services/agents/agent-executor.ts (+9 -3)
📝 scripts/regressions/prompt.regression.ts (+21 -2)

📄 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 #5372

Why this change

  • User-authored lorebook tags were still HTML-entity escaped in agent prompts even though the main assembled prompt correctly preserved them verbatim.
  • This changed model-visible </dottore_lore> / <mari_lore> into &lt;/dottore_lore&gt; / &lt;mari_lore&gt;, wasting tokens and weakening authored structure.

What changed

  • Preserve lorebook entry bodies with the existing prompt-leaf sanitizer in activated, per-agent triggered, and Lorebook Keeper context.
  • Continue escaping IDs, names, keys, and other structural XML attribute values.
  • Add focused regression coverage for literal angle brackets and ampersands, plus an Unreleased changelog entry.

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

Automated validation completed:

  • pnpm check
  • pnpm build:shared && node ./scripts/run-regressions.mjs --filter scripts/regressions/prompt.regression.ts
  • DATA_DIR=<isolated temporary directory> pnpm regression:node (142/142 regression files passed)
  • git diff --check

Manual verification notes

  • Enable debug prompt logging and verify literal lorebook tags remain unchanged in an agent provider request.

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)

UI evidence (if applicable)

  • Not applicable; this is a server-side prompt serialization correction.

Summary by CodeRabbit

  • Bug Fixes
    • Agent prompts now preserve user-authored lorebook tags and ampersands exactly as entered.
    • Lorebook content is no longer converted into HTML entities when included in prompts.
    • Entry names and other attributes continue to be safely escaped where appropriate.

🔄 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/5373 **Author:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Created:** 8/21/2026 **Status:** ✅ Merged **Merged:** 8/21/2026 **Merged by:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Base:** `staging` ← **Head:** `fix/5372-lorebook-agent-verbatim` --- ### 📝 Commits (2) - [`3499abd`](https://github.com/Pasta-Devs/Marinara-Engine/commit/3499abd4f6295fc012143564c83184b0452629ac) test(prompt): reproduce agent lorebook escaping - [`5d9a24f`](https://github.com/Pasta-Devs/Marinara-Engine/commit/5d9a24fdf44331503ae66048c8033c977b201dd8) fix(prompt): preserve lorebook tags in agent requests ### 📊 Changes **3 files changed** (+31 additions, -5 deletions) <details> <summary>View changed files</summary> 📝 `CHANGELOG.md` (+1 -0) 📝 `packages/server/src/services/agents/agent-executor.ts` (+9 -3) 📝 `scripts/regressions/prompt.regression.ts` (+21 -2) </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 #5372 ## Why this change - User-authored lorebook tags were still HTML-entity escaped in agent prompts even though the main assembled prompt correctly preserved them verbatim. - This changed model-visible `</dottore_lore>` / `<mari_lore>` into `&lt;/dottore_lore&gt;` / `&lt;mari_lore&gt;`, wasting tokens and weakening authored structure. ## What changed - Preserve lorebook entry bodies with the existing prompt-leaf sanitizer in activated, per-agent triggered, and Lorebook Keeper context. - Continue escaping IDs, names, keys, and other structural XML attribute values. - Add focused regression coverage for literal angle brackets and ampersands, plus an Unreleased changelog entry. ## 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` Automated validation completed: - `pnpm check` - `pnpm build:shared && node ./scripts/run-regressions.mjs --filter scripts/regressions/prompt.regression.ts` - `DATA_DIR=<isolated temporary directory> pnpm regression:node` (142/142 regression files passed) - `git diff --check` ### Manual verification notes - Enable debug prompt logging and verify literal lorebook tags remain unchanged in an agent provider request. ## 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) ## UI evidence (if applicable) - Not applicable; this is a server-side prompt serialization correction. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Agent prompts now preserve user-authored lorebook tags and ampersands exactly as entered. * Lorebook content is no longer converted into HTML entities when included in prompts. * Entry names and other attributes continue to be safely escaped where appropriate. <!-- 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:13:18 +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#6742
No description provided.