[PR #4796] [MERGED] feat(server): teach workspace Professor Mari to author well-parameterized lorebooks #6501

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

📋 Pull Request Information

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

Base: staging ← Head: feat/4791-mari-lorebook-authoring


📝 Commits (7)

  • 619286b feat(server): teach workspace Professor Mari to author well-parameterized lorebooks
  • c280c59 Merge branch 'staging' into feat/4791-mari-lorebook-authoring
  • ec206ed fix(server): address CodeRabbit review on Mari lorebook authoring (#4796)
  • b56fc5e Merge branch 'staging' into feat/4791-mari-lorebook-authoring
  • 25d96b6 test(server): cover the no-headings and >40-headings docs_read miss branches
  • 9d67fc1 fix(server): tighten docs heading parser + scope Mari embedding check to her connection
  • 74930d4 fix(server): restrict docs heading fences to <=3-space indentation

📊 Changes

6 files changed (+315 additions, -25 deletions)

View changed files

📝 package.json (+1 -1)
📝 packages/server/src/services/mari-db/mari-db.service.ts (+34 -5)
📝 packages/server/src/services/professor-mari/documentation-tools.ts (+53 -13)
📝 packages/server/src/services/professor-mari/workspace-agent.service.ts (+23 -5)
📝 scripts/regressions/open-issues.regression.ts (+118 -0)
📝 scripts/regressions/professor-mari-documentation.regression.ts (+86 -1)

📄 Description

Linked issue

Closes #4791

Why this change

When a user asks the workspace Home assistant (Professor Mari) to build a lorebook — e.g. "make a lorebook for the setting Vlad the vampire lives in" — she produced near-skeletal entries: Name + Content + a couple of keys, and essentially nothing else. Two root causes, both fixed here:

  • Her lorebook.create / addEntry / updateEntry paths silently hardcoded the advanced entry fields (selective, selectiveLogic, matchWholeWords, caseSensitive, useRegex), so even a perfect prompt could not get her to set them.
  • Her prompt never taught the insertion-strategy choices (constant vs keyed, whole-word matching, selective disambiguation, grouping, placement, semantic), never modeled a well-parameterized example, and had no review step to catch weak entries.

The result was functional-but-shallow world info that under-used the engine's own capabilities. This teaches her to author good lorebooks and gives her the tools to actually do it.

What changed

Engine

  • Expose selective, selectiveLogic, matchWholeWords, caseSensitive, useRegex on the workspace lorebook.create (entries array), addEntry, and updateEntry paths — previously hardcoded and ignored by buildLorebookEntryCreateRow + assignLorebookEntryActionFields. selectiveLogic is validated against the stored enum (and/and_all/or/not/not_all); invalid input falls back to the default.
  • Surface embeddingModelConfigured into Mari's <workspace_context> (via isMemoryRecallVectorizerAvailable, cached, guarded) so her semantic guidance stays conditional on an embedding model actually being configured.

Prompt

  • Add a compact insertion-strategy heuristic + a user-gated fidelity-review loop to her lorebook guidance, and upgrade the worked example to a well-parameterized one (constant premise + keyed entries + matchWholeWords on an ambiguous name + filled descriptions).
  • Complete the lorebook.create entry field list in the tool schema.

Docs tool

  • docs_read heading miss now lists the file's available headings instead of a bare throw, so Mari can self-correct a wrong heading.
  • Wire the previously orphaned professor-mari-documentation regression into CI.

Tests

  • Extend the open-issues regression: entry-field round-trip through create, addEntry, and updateEntry, plus selectiveLogic validation (invalid → default / ignored).
  • Extend the documentation regression: a heading miss now lists the available headings.

Notes / follow-ups (surfaced by adversarial review)

  • Mari can now author regex keys (useRegex). Scan-time regex is already guarded (isPatternSafe + a 50 ms vm timeout with literal fallback), so the added ReDoS surface is bounded.
  • embeddingModelConfigured is computed against the default connection; if a user's default connection differs from the workspace connection it can misreport. Advisory-only signal.
  • The mari CLI lorebooks add-entry / update-entry still hardcodes these fields (pre-existing; Mari is directed to use app_data, not the CLI). Worth a small follow-up issue for CLI parity.

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

Automated (run locally, all green — boxes left unticked for the human to confirm):

  • pnpm check (tsc + eslint + client build) passes.
  • Regressions pass: open-issues, professor-mari-documentation, professor-mari-prompt-context, professor-mari-fetch-tiers, entity-embedding-store, professor-mari-fetch-integration, professor-mari-relevance-names.

Still needs a real browser/app pass (NOT yet done):

  • In the Home Professor Mari chat, ask her to build a lorebook for a setting (e.g. "make a lorebook for the setting Vlad the vampire lives in"). Confirm the created entries include a constant premise entry, keyed detail entries, and filled descriptions — not Name/Content only.
  • Confirm she OFFERS a fidelity pass rather than running it unprompted; accept it and confirm she reads entries back and refines (e.g. narrows an over-broad key / adds matchWholeWords).
  • With no embedding model configured, confirm she does not lean on "semantic"; with one configured, confirm she may keep rarely-named lore non-constant.
  • docs_read with a wrong heading returns the available-headings hint.

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)

No docs/ files change in this PR, so no docs-i18n mirroring is required. The user-facing docs improvement (authoring strategy + non-skeletal examples) is tracked separately in #4792. No version bump.

Summary by CodeRabbit

  • New Features

    • Lorebook entries now support selective matching, whole-word matching, case sensitivity, and regular expressions.
    • Lorebook updates preserve valid matching settings and apply sensible defaults.
    • Workspace guidance includes expanded lorebook authoring instructions and semantic recall context.
  • Bug Fixes

    • Documentation lookup ignores headings inside code blocks, preserves headings such as “C#”, and respects heading hierarchy.
    • Heading errors identify available headings, handle documents without headings, and truncate long lists clearly.
    • Improved handling when memory-recall services are unavailable.

🔄 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/4796 **Author:** [@kolacheee](https://github.com/kolacheee) **Created:** 8/9/2026 **Status:** ✅ Merged **Merged:** 8/9/2026 **Merged by:** [@kolacheee](https://github.com/kolacheee) **Base:** `staging` ← **Head:** `feat/4791-mari-lorebook-authoring` --- ### 📝 Commits (7) - [`619286b`](https://github.com/Pasta-Devs/Marinara-Engine/commit/619286be51bd9e033ee9f26ad7f5bfd1a18f0749) feat(server): teach workspace Professor Mari to author well-parameterized lorebooks - [`c280c59`](https://github.com/Pasta-Devs/Marinara-Engine/commit/c280c599a4a7f15dedef0fe8c93ce766daac7445) Merge branch 'staging' into feat/4791-mari-lorebook-authoring - [`ec206ed`](https://github.com/Pasta-Devs/Marinara-Engine/commit/ec206ede46a630d9a261e0a211545f0bf7238065) fix(server): address CodeRabbit review on Mari lorebook authoring (#4796) - [`b56fc5e`](https://github.com/Pasta-Devs/Marinara-Engine/commit/b56fc5e3854fe2101d6c80012fe21acefe441d40) Merge branch 'staging' into feat/4791-mari-lorebook-authoring - [`25d96b6`](https://github.com/Pasta-Devs/Marinara-Engine/commit/25d96b6ffd9879c107c888546587b90434cecc2f) test(server): cover the no-headings and >40-headings docs_read miss branches - [`9d67fc1`](https://github.com/Pasta-Devs/Marinara-Engine/commit/9d67fc152164872ee35a368c7c80d768a2c9d211) fix(server): tighten docs heading parser + scope Mari embedding check to her connection - [`74930d4`](https://github.com/Pasta-Devs/Marinara-Engine/commit/74930d4522584d5414370d1321bef40ad192ae5b) fix(server): restrict docs heading fences to <=3-space indentation ### 📊 Changes **6 files changed** (+315 additions, -25 deletions) <details> <summary>View changed files</summary> 📝 `package.json` (+1 -1) 📝 `packages/server/src/services/mari-db/mari-db.service.ts` (+34 -5) 📝 `packages/server/src/services/professor-mari/documentation-tools.ts` (+53 -13) 📝 `packages/server/src/services/professor-mari/workspace-agent.service.ts` (+23 -5) 📝 `scripts/regressions/open-issues.regression.ts` (+118 -0) 📝 `scripts/regressions/professor-mari-documentation.regression.ts` (+86 -1) </details> ### 📄 Description ## Linked issue Closes #4791 ## Why this change When a user asks the workspace Home assistant (Professor Mari) to build a lorebook — e.g. *"make a lorebook for the setting Vlad the vampire lives in"* — she produced near-skeletal entries: Name + Content + a couple of keys, and essentially nothing else. Two root causes, both fixed here: - Her `lorebook.create` / `addEntry` / `updateEntry` paths **silently hardcoded** the advanced entry fields (`selective`, `selectiveLogic`, `matchWholeWords`, `caseSensitive`, `useRegex`), so even a perfect prompt could not get her to set them. - Her prompt never taught the insertion-strategy choices (constant vs keyed, whole-word matching, selective disambiguation, grouping, placement, semantic), never modeled a well-parameterized example, and had no review step to catch weak entries. The result was functional-but-shallow world info that under-used the engine's own capabilities. This teaches her to author good lorebooks and gives her the tools to actually do it. ## What changed **Engine** - Expose `selective`, `selectiveLogic`, `matchWholeWords`, `caseSensitive`, `useRegex` on the workspace `lorebook.create` (entries array), `addEntry`, and `updateEntry` paths — previously hardcoded and ignored by `buildLorebookEntryCreateRow` + `assignLorebookEntryActionFields`. `selectiveLogic` is validated against the stored enum (`and`/`and_all`/`or`/`not`/`not_all`); invalid input falls back to the default. - Surface `embeddingModelConfigured` into Mari's `<workspace_context>` (via `isMemoryRecallVectorizerAvailable`, cached, guarded) so her semantic guidance stays conditional on an embedding model actually being configured. **Prompt** - Add a compact insertion-strategy heuristic + a **user-gated** fidelity-review loop to her lorebook guidance, and upgrade the worked example to a well-parameterized one (constant premise + keyed entries + `matchWholeWords` on an ambiguous name + filled descriptions). - Complete the `lorebook.create` entry field list in the tool schema. **Docs tool** - `docs_read` heading miss now lists the file's available headings instead of a bare throw, so Mari can self-correct a wrong heading. - Wire the previously **orphaned** `professor-mari-documentation` regression into CI. **Tests** - Extend the open-issues regression: entry-field round-trip through `create`, `addEntry`, and `updateEntry`, plus `selectiveLogic` validation (invalid → default / ignored). - Extend the documentation regression: a heading miss now lists the available headings. **Notes / follow-ups (surfaced by adversarial review)** - Mari can now author regex keys (`useRegex`). Scan-time regex is already guarded (`isPatternSafe` + a 50 ms vm timeout with literal fallback), so the added ReDoS surface is bounded. - `embeddingModelConfigured` is computed against the **default** connection; if a user's default connection differs from the workspace connection it can misreport. Advisory-only signal. - The `mari` **CLI** `lorebooks add-entry` / `update-entry` still hardcodes these fields (pre-existing; Mari is directed to use `app_data`, not the CLI). Worth a small follow-up issue for CLI parity. ## 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 Automated (run locally, all green — boxes left unticked for the human to confirm): - `pnpm check` (tsc + eslint + client build) passes. - Regressions pass: `open-issues`, `professor-mari-documentation`, `professor-mari-prompt-context`, `professor-mari-fetch-tiers`, `entity-embedding-store`, `professor-mari-fetch-integration`, `professor-mari-relevance-names`. Still needs a real browser/app pass (NOT yet done): - In the Home Professor Mari chat, ask her to build a lorebook for a setting (e.g. "make a lorebook for the setting Vlad the vampire lives in"). Confirm the created entries include a `constant` premise entry, keyed detail entries, and filled `description`s — not Name/Content only. - Confirm she OFFERS a fidelity pass rather than running it unprompted; accept it and confirm she reads entries back and refines (e.g. narrows an over-broad key / adds `matchWholeWords`). - With no embedding model configured, confirm she does not lean on "semantic"; with one configured, confirm she may keep rarely-named lore non-constant. - `docs_read` with a wrong heading returns the available-headings hint. ## Docs and release impact - [x] 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) No `docs/` files change in this PR, so no `docs-i18n` mirroring is required. The user-facing docs improvement (authoring strategy + non-skeletal examples) is tracked separately in #4792. No version bump. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Lorebook entries now support selective matching, whole-word matching, case sensitivity, and regular expressions. * Lorebook updates preserve valid matching settings and apply sensible defaults. * Workspace guidance includes expanded lorebook authoring instructions and semantic recall context. * **Bug Fixes** * Documentation lookup ignores headings inside code blocks, preserves headings such as “C#”, and respects heading hierarchy. * Heading errors identify available headings, handle documents without headings, and truncate long lists clearly. * Improved handling when memory-recall services are unavailable. <!-- 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:11:02 +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#6501
No description provided.