[PR #1985] [MERGED] Fix lorebook depth history anchoring #5379

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

📋 Pull Request Information

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

Base: refactor ← Head: fix/issue-1979-lorebook-depth-bounds


📝 Commits (2)

  • 4f19960 Fix lorebook depth history anchoring
  • beef7ee Merge remote-tracking branch 'upstream/refactor' into fix/issue-1979-lorebook-depth-bounds

📊 Changes

4 files changed (+206 additions, -3 deletions)

View changed files

📝 src/engine/generation-core/lorebooks/prompt-injector.test.ts (+54 -2)
📝 src/engine/generation-core/lorebooks/prompt-injector.ts (+12 -1)
➕ src/engine/generation/prompt-assembly.test.ts (+125 -0)
📝 src/engine/generation/prompt-assembly.ts (+15 -0)

📄 Description

Linked issue

Closes #1979

Why this change

  • Refactor prompt assembly was anchoring at depth lorebook entries against the full assembled prompt, so prompt sections that sit after chat history could shift depth-injected lore out of the legacy/ST-style history window.

What changed

  • Restored bounded depth-injection options on the engine lorebook prompt injector.
  • Derived depth-injection bounds from assembled chat-history messages before injecting lorebook, character depth prompt, and author-note depth entries.
  • Added focused regression coverage for bounded injector behavior, prompt assembly with a post-history prompt section, and no-history fallback behavior.

Refactor impact

Primary owner:

  • engine generation

Impact areas reviewed:

  • Lorebook depth injection
  • Prompt assembly ordering
  • Character depth prompts and author notes that share the same depth injector

Boundary notes:

  • Kept the change inside src/engine; no React, shared API, Rust, storage schema, dependency, or remote-runtime boundary changes.

Pressure points touched:

  • Runtime prompt assembly immediately before regex application and final message merging.

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

  • Codex reproduced the pre-fix ordering failure with a focused Vitest harness: old behavior placed the depth lore entry after the post-history prompt block.
  • Codex verified the fixed behavior with pnpm exec vitest run src/engine/generation-core/lorebooks/prompt-injector.test.ts src/engine/generation/prompt-assembly.test.ts; 2 files passed, 4 tests passed.
  • Codex ran final pnpm check; line endings, architecture, frontend typecheck, Rust check, docs, discovery metadata, and unused-code checks passed.
  • No human-only manual verification is required for the core prompt-ordering claim.

Feature Discoverability

Check exactly one:

  • 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:

  • Bugfix only; no user-discoverable feature or setting is added.

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

UI evidence

N/A; this is an engine prompt-ordering fix with command/harness proof rather than a visible UI change.


🔄 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/1985 **Author:** [@cha1latte](https://github.com/cha1latte) **Created:** 6/2/2026 **Status:** ✅ Merged **Merged:** 6/2/2026 **Merged by:** [@cha1latte](https://github.com/cha1latte) **Base:** `refactor` ← **Head:** `fix/issue-1979-lorebook-depth-bounds` --- ### 📝 Commits (2) - [`4f19960`](https://github.com/Pasta-Devs/Marinara-Engine/commit/4f19960fe521ac31e11ce4e3e09bd608c74cadf3) Fix lorebook depth history anchoring - [`beef7ee`](https://github.com/Pasta-Devs/Marinara-Engine/commit/beef7ee819e91f55b10e3c041e111998de807a68) Merge remote-tracking branch 'upstream/refactor' into fix/issue-1979-lorebook-depth-bounds ### 📊 Changes **4 files changed** (+206 additions, -3 deletions) <details> <summary>View changed files</summary> 📝 `src/engine/generation-core/lorebooks/prompt-injector.test.ts` (+54 -2) 📝 `src/engine/generation-core/lorebooks/prompt-injector.ts` (+12 -1) ➕ `src/engine/generation/prompt-assembly.test.ts` (+125 -0) 📝 `src/engine/generation/prompt-assembly.ts` (+15 -0) </details> ### 📄 Description <!-- Target branch: `refactor`. Change the base to `refactor` before submitting unless a maintainer explicitly asked for another base. --> <!-- Keep all checkboxes unchecked until a human has actually verified them. --> ## Linked issue Closes #1979 ## Why this change - Refactor prompt assembly was anchoring `at depth` lorebook entries against the full assembled prompt, so prompt sections that sit after chat history could shift depth-injected lore out of the legacy/ST-style history window. ## What changed - Restored bounded depth-injection options on the engine lorebook prompt injector. - Derived depth-injection bounds from assembled chat-history messages before injecting lorebook, character depth prompt, and author-note depth entries. - Added focused regression coverage for bounded injector behavior, prompt assembly with a post-history prompt section, and no-history fallback behavior. ## Refactor impact Primary owner: - engine generation Impact areas reviewed: - Lorebook depth injection - Prompt assembly ordering - Character depth prompts and author notes that share the same depth injector Boundary notes: - Kept the change inside `src/engine`; no React, shared API, Rust, storage schema, dependency, or remote-runtime boundary changes. Pressure points touched: - Runtime prompt assembly immediately before regex application and final message merging. ## Validation <!-- Check only what you personally ran or manually verified. Treat unchecked items as explicit TODOs. --> <!-- Do not submit *.test.ts or *.test.tsx files as PR proof; cite existing checks, command output, app/browser/Tauri verification, or manual notes instead. --> - [ ] 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 - Codex reproduced the pre-fix ordering failure with a focused Vitest harness: old behavior placed the depth lore entry after the post-history prompt block. - Codex verified the fixed behavior with `pnpm exec vitest run src/engine/generation-core/lorebooks/prompt-injector.test.ts src/engine/generation/prompt-assembly.test.ts`; 2 files passed, 4 tests passed. - Codex ran final `pnpm check`; line endings, architecture, frontend typecheck, Rust check, docs, discovery metadata, and unused-code checks passed. - No human-only manual verification is required for the core prompt-ordering claim. ## Feature Discoverability Check exactly one: - [ ] 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: - Bugfix only; no user-discoverable feature or setting is added. ## 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 ## UI evidence N/A; this is an engine prompt-ordering fix with command/harness proof rather than a visible UI change. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-22 04:15: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#5379
No description provided.