[PR #4852] [MERGED] feat(mari): give Professor Mari a persistent, retrievable memory (#4851) #6518

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

📋 Pull Request Information

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

Base: staging ← Head: feat/4851-mari-instructions-memory


📝 Commits (1)

  • 1bab3ee feat(mari): give Professor Mari a persistent, retrievable memory (#4851)

📊 Changes

17 files changed (+1795 additions, -15 deletions)

View changed files

📝 CHANGELOG.md (+1 -0)
📝 docs/home/professor-mari.md (+19 -0)
📝 package.json (+2 -1)
📝 packages/client/src/components/chat/HomeProfessorMariChat.tsx (+557 -4)
📝 packages/client/src/localization/locales/en.json (+23 -0)
📝 packages/server/src/db/file-backed-store.ts (+1 -0)
📝 packages/server/src/db/schema/index.ts (+1 -0)
➕ packages/server/src/db/schema/mari-instructions.ts (+28 -0)
📝 packages/server/src/routes/professor-mari-workspace.routes.ts (+69 -1)
📝 packages/server/src/services/mari-db/mari-db.service.ts (+315 -5)
➕ packages/server/src/services/professor-mari/mari-instructions-prompt.ts (+101 -0)
📝 packages/server/src/services/professor-mari/workspace-agent.service.ts (+29 -4)
➕ packages/server/src/services/storage/mari-instructions.storage.ts (+158 -0)
📝 packages/shared/src/types/professor-mari-workspace.ts (+26 -0)
📝 scripts/regressions/mari-db-review-durability.regression.ts (+63 -0)
➕ scripts/regressions/mari-instructions-memory.regression.ts (+374 -0)
📝 scripts/regressions/open-issues.regression.ts (+28 -0)

📄 Description

Linked issue

Closes #4851

Why this change

Professor Mari had no persistent memory of a user's preferences across sessions: every conversation, the user re-explains how they like lorebooks/characters formatted, their conventions, and how eager they want her to be about editing. Behavior also wasn't user-configurable: after #4813/#4816/#4838 tightened her to confirm before editing (the right default), users who preferred the older "just make the edit" behavior had no way to opt back in. The maintainer approved the feature request, with one caveat: watch for token bloat, which is exactly what the index-and-fetch retrieval here is designed around.

What changed

A persistent, retrievable memory for Professor Mari (the Home workspace agent), with both a chat flow and a management panel.

  • Storage: a new mari_instructions file-native table (registered in the schema barrel + FILE_BACKED_TABLES; no STORAGE_VERSION bump, since an additive table is backward/forward-compatible and the launcher-format-guard pairing stays at 4) plus a mari-instructions.storage.ts module. Deliberately not named memory_* (that namespace already means conversation-RAG memory_chunks, agent_memory, scene memories, and the "Important Memories" block).
  • Retrieval, index-and-fetch (the token-bloat answer): only a compact index (title + one-line description + id) of enabled memories is injected every turn via a new <professor_mari_memory> block; full bodies are pulled on relevance with instruction.get. A Persistent memory inlines its body every turn (for the rare directive that must not risk a fetch-miss). Aggregate caps on the index and persistent bodies, with honest "N more not shown" reporting (never silent truncation). Injected fields are sanitized so a memory can't forge the block boundary or fake index lines. Rendering lives in a pure, unit-tested helper (renderMariMemoryPrompt).
  • Mari actions: instruction.list | get | remember | update | forget (with a memory.* alias). Reads classify read-only; remember/update/forget run through the existing mutation pipeline, so every memory Mari writes shows a Keep/Restore review card with the exact text before it persists. Over-cap fields are rejected with a clear error, never silently truncated.
  • Disabled by default + Keep & Enable: a memory Mari saves lands disabled (fully inert, filtered out of the injected block) until the user turns it on. The in-chat review card gains a third Keep & Enable button that keeps the change and switches it on in one click (strictly gated to mari_instructions inserts). This is defense-in-depth: even a hypothetically-planted memory can't take effect until the user explicitly enables it.
  • Memories management panel: a new Memories panel next to the Skills panel (clone of the Skills UI). List, create, edit name/description/content, delete, an enable toggle per memory, a Persistent toggle with a "keep it small; describe always-true behavior" tooltip, and a .md/text Upload. Panel writes go directly through reset-free /instructions routes (the user is the reviewer of their own memory, so no Keep/Restore card and, critically, no workspaceService.reset() that would tear down Mari's live chat session).
  • Precedence & safety (prompt-level): the block frames saved memories as taking precedence over her default behavior where they conflict (this is what enables "opt back into edit-without-asking"). Prompt precedence only: it does not touch any code-enforced gate. The Keep/Restore card always renders, and the hard file/dependency pre-approval gate is untouched. A guidance bullet firewalls self-writes: Mari saves a memory only on a genuine user instruction, never as a reflex to content she just read (so a shared character/lorebook/preset can't plant a standing instruction).
  • Tests/docs: the regression:mari-instructions lane drives the real MariDbService + the pure renderer through remember/list/get/update/forget + Keep/Restore round-trip, the memory.* alias, disabled-by-default, Keep & Enable, the direct panel create/update/remove path, the Persistent flag, over-cap rejection, and the token-bloat + injection-forgery invariants. docs/home/professor-mari.md "Saved memories" section and a CHANGELOG entry.

Out of scope (planned follow-ups): a semantic-ranked index at scale; per-chat vs. global scope; translating the new UI/docs strings to the non-English packs (docs-i18n follow-up #4853).

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 checks already run by the author (please re-run to tick the boxes):

  • pnpm check passes (tsc + lint + client build), on top of a fresh rebase onto staging.
  • regression:mari-instructions passes (server engine + renderer + panel storage + Keep & Enable), plus regression:mari-preset-granular, regression:mari-review-durability, professor-mari-prompt-context, professor-mari-documentation, docs-language, localization-key-references (en at 100%), launcher-format-guard, and file-backed-shutdown.

Manual verification still needed (needs a configured LLM connection and/or a real browser, so the owner must do this):

  • Open the Memories panel from Mari's header: create a memory, edit it, toggle enable and Persistent (check the tooltip), Upload a .md, and delete one. Confirm each round-trips and the panel styling matches the Skills panel in light + dark mode and at a mobile width.
  • Ask Mari "remember that I like my lorebook entries keyed on name + nickname": confirm a Keep/Restore card appears with the exact text, that the saved memory is disabled until enabled, and that Keep & Enable turns it on in one click.
  • Enable a memory, then in a later message ask her to build a lorebook: confirm she consults the memory (fetches it) and follows it.
  • Save a Persistent behavior memory (e.g. "when I ask how to do something, just do it") and enable it: confirm she then acts on a "how do I..." request instead of only explaining.
  • Confirm she does NOT save a memory when a character/lorebook/preset you import contains text telling her to remember something.
  • Known limitation to spot-check: panel edits are direct while Mari's writes leave a pending review. If Mari edits memory X (review open), you then edit X in the panel, then Restore Mari's review, the restore reverts to the journaled snapshot and drops the panel edit (same class as #4812). Low-risk; flagged for awareness.

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)

Docs: updated docs/home/professor-mari.md ("Saved memories") and CHANGELOG.md. The docs-i18n follow-up for the new doc + UI strings is #4853.

UI evidence (if applicable)

{55093BA1-A264-4AE6-A3C9-6AB46EEA6637} {E87A578B-3D41-429B-8B2E-EE6753CE6D5B} {B9E8B90F-1F13-4277-AD2A-9887957E6C61}

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features

    • Added saved memories for Professor Mari with persistent storage and relevance-based retrieval.
    • Added a Memories panel to create, upload, edit, delete, enable, disable, and mark memories as persistent.
    • Added memory actions for remembering, viewing, updating, and forgetting information.
    • Added “Keep & Enable” review support and protection against overwriting newer changes.
    • Memories are disabled by default, with persistent memories prioritized.
  • Documentation

    • Documented how to create and manage Professor Mari memories.
  • Tests

    • Added regression coverage for memory workflows, limits, reviews, and concurrency.

🔄 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/4852 **Author:** [@kolacheee](https://github.com/kolacheee) **Created:** 8/10/2026 **Status:** ✅ Merged **Merged:** 8/10/2026 **Merged by:** [@kolacheee](https://github.com/kolacheee) **Base:** `staging` ← **Head:** `feat/4851-mari-instructions-memory` --- ### 📝 Commits (1) - [`1bab3ee`](https://github.com/Pasta-Devs/Marinara-Engine/commit/1bab3ee1d5aebc5d855e0cc1ee9d232286021ea7) feat(mari): give Professor Mari a persistent, retrievable memory (#4851) ### 📊 Changes **17 files changed** (+1795 additions, -15 deletions) <details> <summary>View changed files</summary> 📝 `CHANGELOG.md` (+1 -0) 📝 `docs/home/professor-mari.md` (+19 -0) 📝 `package.json` (+2 -1) 📝 `packages/client/src/components/chat/HomeProfessorMariChat.tsx` (+557 -4) 📝 `packages/client/src/localization/locales/en.json` (+23 -0) 📝 `packages/server/src/db/file-backed-store.ts` (+1 -0) 📝 `packages/server/src/db/schema/index.ts` (+1 -0) ➕ `packages/server/src/db/schema/mari-instructions.ts` (+28 -0) 📝 `packages/server/src/routes/professor-mari-workspace.routes.ts` (+69 -1) 📝 `packages/server/src/services/mari-db/mari-db.service.ts` (+315 -5) ➕ `packages/server/src/services/professor-mari/mari-instructions-prompt.ts` (+101 -0) 📝 `packages/server/src/services/professor-mari/workspace-agent.service.ts` (+29 -4) ➕ `packages/server/src/services/storage/mari-instructions.storage.ts` (+158 -0) 📝 `packages/shared/src/types/professor-mari-workspace.ts` (+26 -0) 📝 `scripts/regressions/mari-db-review-durability.regression.ts` (+63 -0) ➕ `scripts/regressions/mari-instructions-memory.regression.ts` (+374 -0) 📝 `scripts/regressions/open-issues.regression.ts` (+28 -0) </details> ### 📄 Description ## Linked issue Closes #4851 ## Why this change Professor Mari had no persistent memory of a user's preferences across sessions: every conversation, the user re-explains how they like lorebooks/characters formatted, their conventions, and how eager they want her to be about editing. Behavior also wasn't user-configurable: after #4813/#4816/#4838 tightened her to confirm before editing (the right default), users who *preferred* the older "just make the edit" behavior had no way to opt back in. The maintainer approved the feature request, with one caveat: **watch for token bloat**, which is exactly what the index-and-fetch retrieval here is designed around. ## What changed A persistent, retrievable memory for Professor Mari (the Home workspace agent), with both a chat flow and a management panel. - **Storage:** a new `mari_instructions` file-native table (registered in the schema barrel + `FILE_BACKED_TABLES`; no `STORAGE_VERSION` bump, since an additive table is backward/forward-compatible and the launcher-format-guard pairing stays at 4) plus a `mari-instructions.storage.ts` module. Deliberately **not** named `memory_*` (that namespace already means conversation-RAG `memory_chunks`, `agent_memory`, scene memories, and the "Important Memories" block). - **Retrieval, index-and-fetch (the token-bloat answer):** only a compact **index** (title + one-line description + id) of *enabled* memories is injected every turn via a new `<professor_mari_memory>` block; full bodies are pulled on relevance with `instruction.get`. A **Persistent** memory inlines its body every turn (for the rare directive that must not risk a fetch-miss). Aggregate caps on the index and persistent bodies, with honest "N more not shown" reporting (never silent truncation). Injected fields are sanitized so a memory can't forge the block boundary or fake index lines. Rendering lives in a pure, unit-tested helper (`renderMariMemoryPrompt`). - **Mari actions:** `instruction.list | get | remember | update | forget` (with a `memory.*` alias). Reads classify read-only; `remember/update/forget` run through the existing mutation pipeline, so **every memory Mari writes shows a Keep/Restore review card with the exact text** before it persists. Over-cap fields are rejected with a clear error, never silently truncated. - **Disabled by default + Keep & Enable:** a memory Mari saves lands **disabled** (fully inert, filtered out of the injected block) until the user turns it on. The in-chat review card gains a third **Keep & Enable** button that keeps the change and switches it on in one click (strictly gated to `mari_instructions` inserts). This is defense-in-depth: even a hypothetically-planted memory can't take effect until the user explicitly enables it. - **Memories management panel:** a new **Memories** panel next to the Skills panel (clone of the Skills UI). List, create, edit name/description/content, delete, an **enable** toggle per memory, a **Persistent** toggle with a "keep it small; describe always-true behavior" tooltip, and a `.md`/text **Upload**. Panel writes go directly through reset-free `/instructions` routes (the user is the reviewer of their own memory, so no Keep/Restore card and, critically, no `workspaceService.reset()` that would tear down Mari's live chat session). - **Precedence & safety (prompt-level):** the block frames saved memories as taking precedence over her default behavior where they conflict (this is what enables "opt back into edit-without-asking"). Prompt precedence only: it does **not** touch any code-enforced gate. The Keep/Restore card always renders, and the hard file/dependency pre-approval gate is untouched. A guidance bullet firewalls self-writes: Mari saves a memory **only** on a genuine user instruction, never as a reflex to content she just read (so a shared character/lorebook/preset can't plant a standing instruction). - **Tests/docs:** the `regression:mari-instructions` lane drives the real `MariDbService` + the pure renderer through remember/list/get/update/forget + Keep/Restore round-trip, the `memory.*` alias, disabled-by-default, **Keep & Enable**, the direct panel create/update/remove path, the Persistent flag, over-cap rejection, and the token-bloat + injection-forgery invariants. `docs/home/professor-mari.md` "Saved memories" section and a CHANGELOG entry. Out of scope (planned follow-ups): a semantic-ranked index at scale; per-chat vs. global scope; translating the new UI/docs strings to the non-English packs (docs-i18n follow-up #4853). ## 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 checks already run by the author (please re-run to tick the boxes): - `pnpm check` passes (tsc + lint + client build), on top of a fresh rebase onto `staging`. - `regression:mari-instructions` passes (server engine + renderer + panel storage + Keep & Enable), plus `regression:mari-preset-granular`, `regression:mari-review-durability`, `professor-mari-prompt-context`, `professor-mari-documentation`, `docs-language`, `localization-key-references` (en at 100%), `launcher-format-guard`, and `file-backed-shutdown`. **Manual verification still needed (needs a configured LLM connection and/or a real browser, so the owner must do this):** - Open the **Memories** panel from Mari's header: create a memory, edit it, toggle **enable** and **Persistent** (check the tooltip), **Upload** a `.md`, and delete one. Confirm each round-trips and the panel styling matches the Skills panel in light + dark mode and at a mobile width. - Ask Mari "remember that I like my lorebook entries keyed on name + nickname": confirm a Keep/Restore card appears with the exact text, that the saved memory is **disabled** until enabled, and that **Keep & Enable** turns it on in one click. - Enable a memory, then in a later message ask her to build a lorebook: confirm she consults the memory (fetches it) and follows it. - Save a Persistent behavior memory (e.g. "when I ask how to do something, just do it") and enable it: confirm she then acts on a "how do I..." request instead of only explaining. - Confirm she does NOT save a memory when a character/lorebook/preset you import contains text telling her to remember something. - Known limitation to spot-check: panel edits are direct while Mari's writes leave a pending review. If Mari edits memory X (review open), you then edit X in the panel, then Restore Mari's review, the restore reverts to the journaled snapshot and drops the panel edit (same class as #4812). Low-risk; flagged for awareness. ## Docs and release impact - [ ] No docs changes needed - [x] Updated docs (README / CONTRIBUTING / android/README / CHANGELOG) as needed - [x] 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) Docs: updated `docs/home/professor-mari.md` ("Saved memories") and `CHANGELOG.md`. The docs-i18n follow-up for the new doc + UI strings is #4853. ## UI evidence (if applicable) <img width="796" height="455" alt="{55093BA1-A264-4AE6-A3C9-6AB46EEA6637}" src="https://github.com/user-attachments/assets/fb7e0099-e642-42ce-a59b-747336c61448" /> <img width="842" height="468" alt="{E87A578B-3D41-429B-8B2E-EE6753CE6D5B}" src="https://github.com/user-attachments/assets/a14d7f51-0a55-4842-b7a1-53d260f27733" /> <img width="893" height="485" alt="{B9E8B90F-1F13-4277-AD2A-9887957E6C61}" src="https://github.com/user-attachments/assets/d41dd82a-4dca-4dd3-ac9c-8104108d1cce" /> <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit ## Summary by CodeRabbit * **New Features** * Added saved memories for Professor Mari with persistent storage and relevance-based retrieval. * Added a Memories panel to create, upload, edit, delete, enable, disable, and mark memories as persistent. * Added memory actions for remembering, viewing, updating, and forgetting information. * Added “Keep & Enable” review support and protection against overwriting newer changes. * Memories are disabled by default, with persistent memories prioritized. * **Documentation** * Documented how to create and manage Professor Mari memories. * **Tests** * Added regression coverage for memory workflows, limits, reviews, and concurrency. <!-- 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:11 +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#6518
No description provided.