[PR #8392] [MERGED] feat(mari): keep a read handbook in context while she works on its surface #8572

Closed
opened 2026-11-07 16:45:41 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/8392
Author: @ylli-selmani
Created: 10/26/2026
Status: ✅ Merged
Merged: 10/28/2026
Merged by: @ylli-selmani

Base: staging ← Head: feat/mari-sticky-handbook


📝 Commits (3)

  • de317fb feat(mari): keep a read handbook in context while she works on its surface
  • 5153d08 fix(mari): a dropped handbook can't come back through a touch
  • 48b832e fix(mari): held proposals keep a handbook; the limit drops the idlest

📊 Changes

7 files changed (+326 additions, -12 deletions)

View changed files

📝 packages/server/src/services/professor-mari/mari-skills-prompt.ts (+2 -2)
➕ packages/server/src/services/professor-mari/sticky-handbooks.ts (+103 -0)
📝 packages/server/src/services/professor-mari/workspace-agent.service.ts (+29 -6)
📝 packages/server/src/services/professor-mari/workspace-commands.ts (+24 -3)
📝 packages/server/src/services/professor-mari/workspace-message-store.ts (+3 -0)
📝 scripts/regressions/mari/app-data-envelope-errors.regression.ts (+1 -1)
➕ scripts/regressions/mari/sticky-handbooks.regression.ts (+164 -0)

📄 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

Part of #8391

Why this change

#7827 drops a handbook's text from Professor Mari's history once a turn ends (a handbook is 11–18k chars). But the read-first gate counted it as read for the whole chat. So from turn 2 on ("now shorten her greeting", "add a quirk") she wrote from memory of a handbook she no longer had. Now a handbook she read stays in her prompt, in full, while she keeps working on its surface. It drops when she stops using it, and the gate asks for it again.

What changed

Rules (new sticky-handbooks.ts, pure)

  • Each assistant turn stores extra.mariHandbooks = { read, touched }, built from its successful app_data calls. read holds the built-in skills fetched with skill.get. touched holds the handbooks the turn's other calls route to.
  • A read adds or refreshes a handbook; a touch refreshes one that is already active, but never adds one.
  • At most 2 stay active; reading a third drops the oldest. A handbook drops after 3 turns with no read or write on its surface.
  • The rules are worked out from every stored turn, not the 40-message history window, and rows from before this change count as empty turns.

Prompt (workspace-agent.service.ts)

  • The active handbooks go in a new <active_handbooks> block, after the permissions-mode block. #8375 still puts <workspace_context> last. The block changes only when a handbook comes or goes, so it doesn't break the cache on every turn.
  • buildSkillsPrompt now also returns the skill list, so the block costs no second read.
  • The continuity line for a skill.get now points at the block: "while you keep working on its surface it stays in <active_handbooks>; if it is not there, call skill.get again".

Gate (workspace-commands.ts)

  • armSkillGate starts each turn's gate from the handbooks in that turn's block, so a dropped one is refused once again. The refusal now says "once per turn", not "once per chat".
  • The gate still lets the same turn's resend through, so a disabled or unreadable handbook can't lock a surface.
  • handbooksForAction is exported next to the gate's table, so a call counts toward the same handbooks the gate accepts for it: character.update counts for characters and onboarding, a link counts for both lorebook and characters, and decision content counts for decisions.

Cost: while active, up to two whole handbooks (about 9k tokens at worst) sit in the prompt, against a skill.get round on every turn before. That was a deliberate call, made instead of carrying ~4k sections.

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

Agent-run checks:

  • pnpm check exits 0.
  • New scripts/regressions/mari/sticky-handbooks.regression.ts. It pins:
    • the per-turn record: failed calls, non-built-in skills and other tools are ignored;
    • the routing;
    • the active set: 3 quiet turns, refresh on a write, never added by a write alone, the limit of 2, a re-read making a handbook the newest;
    • the block, and the continuity line;
    • the re-armed gate, through the real WorkspaceCommands.
  • node scripts/run-regressions.mjs --filter passes for professor-mari (23/23), mari- (18/18), skill (4/4), app-data (2/2), pi-runtime (1/1) and sticky-handbooks (1/1). The full suite is left to CI.

Live canary on Gemma 4 12b: pending (Ylli).

Docs and release impact

  • No docs changes needed
  • Updated docs (README / CONTRIBUTING / android/README) 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)

No UI changes.

🤖 Generated with Claude Code


🔄 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/8392 **Author:** [@ylli-selmani](https://github.com/ylli-selmani) **Created:** 10/26/2026 **Status:** ✅ Merged **Merged:** 10/28/2026 **Merged by:** [@ylli-selmani](https://github.com/ylli-selmani) **Base:** `staging` ← **Head:** `feat/mari-sticky-handbook` --- ### 📝 Commits (3) - [`de317fb`](https://github.com/Pasta-Devs/Marinara-Engine/commit/de317fbc5cccdc326b8d1477f9de1f120d5aed0b) feat(mari): keep a read handbook in context while she works on its surface - [`5153d08`](https://github.com/Pasta-Devs/Marinara-Engine/commit/5153d08dfeef6ac4d28cc3e1fc9b289d751b14b6) fix(mari): a dropped handbook can't come back through a touch - [`48b832e`](https://github.com/Pasta-Devs/Marinara-Engine/commit/48b832e3f9d1c811656766d71ab4b40d6386b63a) fix(mari): held proposals keep a handbook; the limit drops the idlest ### 📊 Changes **7 files changed** (+326 additions, -12 deletions) <details> <summary>View changed files</summary> 📝 `packages/server/src/services/professor-mari/mari-skills-prompt.ts` (+2 -2) ➕ `packages/server/src/services/professor-mari/sticky-handbooks.ts` (+103 -0) 📝 `packages/server/src/services/professor-mari/workspace-agent.service.ts` (+29 -6) 📝 `packages/server/src/services/professor-mari/workspace-commands.ts` (+24 -3) 📝 `packages/server/src/services/professor-mari/workspace-message-store.ts` (+3 -0) 📝 `scripts/regressions/mari/app-data-envelope-errors.regression.ts` (+1 -1) ➕ `scripts/regressions/mari/sticky-handbooks.regression.ts` (+164 -0) </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 Part of #8391 ## Why this change #7827 drops a handbook's text from Professor Mari's history once a turn ends (a handbook is 11–18k chars). But the read-first gate counted it as read for the whole chat. So from turn 2 on ("now shorten her greeting", "add a quirk") she wrote from memory of a handbook she no longer had. Now a handbook she read stays in her prompt, in full, while she keeps working on its surface. It drops when she stops using it, and the gate asks for it again. ## What changed **Rules** (new `sticky-handbooks.ts`, pure) - Each assistant turn stores `extra.mariHandbooks = { read, touched }`, built from its successful `app_data` calls. `read` holds the built-in skills fetched with `skill.get`. `touched` holds the handbooks the turn's other calls route to. - A read adds or refreshes a handbook; a touch refreshes one that is already active, but never adds one. - **At most 2** stay active; reading a third drops the oldest. A handbook drops after **3 turns** with no read or write on its surface. - The rules are worked out from every stored turn, not the 40-message history window, and rows from before this change count as empty turns. **Prompt** (`workspace-agent.service.ts`) - The active handbooks go in a new `<active_handbooks>` block, after the permissions-mode block. #8375 still puts `<workspace_context>` last. The block changes only when a handbook comes or goes, so it doesn't break the cache on every turn. - `buildSkillsPrompt` now also returns the skill list, so the block costs no second read. - The continuity line for a `skill.get` now points at the block: "while you keep working on its surface it stays in <active_handbooks>; if it is not there, call skill.get again". **Gate** (`workspace-commands.ts`) - `armSkillGate` starts each turn's gate from the handbooks in that turn's block, so a dropped one is refused once again. The refusal now says "once per turn", not "once per chat". - The gate still lets the same turn's resend through, so a disabled or unreadable handbook can't lock a surface. - `handbooksForAction` is exported next to the gate's table, so a call counts toward the same handbooks the gate accepts for it: `character.update` counts for characters and onboarding, a link counts for both lorebook and characters, and decision content counts for decisions. **Cost:** while active, up to two whole handbooks (about 9k tokens at worst) sit in the prompt, against a `skill.get` round on every turn before. That was a deliberate call, made instead of carrying ~4k sections. ## 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 Agent-run checks: - `pnpm check` exits 0. - New `scripts/regressions/mari/sticky-handbooks.regression.ts`. It pins: - the per-turn record: failed calls, non-built-in skills and other tools are ignored; - the routing; - the active set: 3 quiet turns, refresh on a write, never added by a write alone, the limit of 2, a re-read making a handbook the newest; - the block, and the continuity line; - the re-armed gate, through the real `WorkspaceCommands`. - `node scripts/run-regressions.mjs --filter` passes for `professor-mari` (23/23), `mari-` (18/18), `skill` (4/4), `app-data` (2/2), `pi-runtime` (1/1) and `sticky-handbooks` (1/1). The full suite is left to CI. Live canary on Gemma 4 12b: pending (Ylli). ## Docs and release impact - [ ] No docs changes needed - [ ] Updated docs (README / CONTRIBUTING / android/README) 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) No UI changes. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-07 16:45:41 +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#8572
No description provided.