[PR #4926] [MERGED] fix(server): give Professor Mari a safe lorebook.deleteEntry action #6545

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

📋 Pull Request Information

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

Base: staging ← Head: fix/mari-lorebook-delete-entry


📝 Commits (2)

  • 629489d fix(server): give Professor Mari a safe lorebook.deleteEntry action (#4924)
  • d9638b1 test: isolate the lorebook.deleteEntry fixture cleanup in a finally block (#4924)

📊 Changes

4 files changed (+78 additions, -1 deletions)

View changed files

📝 CHANGELOG.md (+1 -0)
📝 packages/server/src/services/mari-db/mari-db.service.ts (+25 -0)
📝 packages/server/src/services/professor-mari/workspace-agent.service.ts (+4 -1)
📝 scripts/regressions/open-issues.regression.ts (+48 -0)

📄 Description

Linked issue

Closes #4924

Why this change

Professor Mari had no safe way to delete a single lorebook entry: her app_data toolkit exposes lorebook.addEntry and lorebook.updateEntry but no deleteEntry. When a user asked her to delete one entry, lorebook.deleteEntry failed (not a real action), so she fell back to the raw mari db delete <table> --where <expr> command — a bulk delete with no row-count guard — and removed 77 entries across unrelated lorebooks instead of the one. (The deletion was recoverable via the Keep/Restore card, but the blast radius was the whole matched set.)

What changed

  • packages/server/src/services/mari-db/mari-db.service.ts — added a lorebook.deleteEntry app_data action: it takes entryId, verifies the entry exists (throws otherwise), and deletes exactly that one row ({ kind: "delete", table: "lorebook_entries", id, cascade: false }) through the same executeMutation → Keep/Restore review as add/update. This is the identical shape the CLI's mari lorebooks delete-entry <id> already uses. Also registered delete aliases (lorebook.entry.delete, lorebook.entries.delete, lorebook.entry.remove, lorebook.removeentry, …).
  • packages/server/src/services/professor-mari/workspace-agent.service.ts — registered lorebook.deleteEntry in the action catalog and the Writes quick-ref, added a prompt bullet ("to delete a lorebook entry use lorebook.deleteEntry; never a raw mari db delete, whose --where can remove far more rows than intended; if a raw mari db delete is ever unavoidable, dry-run and confirm the row count first"), and a worked example.
  • scripts/regressions/open-issues.regression.ts — new test that creates a lorebook with two entries, deletes one via lorebook.deleteEntry, and asserts exactly one is removed, the other survives, and deleting a missing id is rejected.
  • CHANGELOG.md — one Fixed entry.

Note on classification: lorebook.deleteEntry is correctly treated as mutating (its suffix isn't in the read-only whitelist), so it can't bypass the review and produces a recoverable Keep/Restore card.

Out of scope (deliberately, per the issue): a broader guardrail on raw mari db delete --where bulk deletes (dry-run-and-confirm before applying) — can be tracked separately.

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, done by me:

  • pnpm check passes (TypeScript + ESLint + build, exit 0).
  • The full open-issues regression passes, including the new scoping test (delete one of two entries → exactly one removed, the other survives, missing id rejected).

Still needs a human (please verify in a real browser, don't trust the boxes above):

  • Ask Mari to delete one lorebook entry; confirm she uses lorebook.deleteEntry, only that entry is removed, and a Keep/Restore card appears (Restore puts it back).
  • Confirm she no longer reaches for mari db delete for a single-entry delete.

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)

CHANGELOG.md updated. No docs/ change and no version bump.

Summary by CodeRabbit

  • New Features

    • Added a safer tool for deleting individual lorebook entries.
    • Supports deletion by entry ID with an explicit apply step.
    • Prevents unintended removal of other entries in the same lorebook.
  • Bug Fixes

    • Deleting a nonexistent lorebook entry now reports a failure instead of proceeding.
  • Documentation

    • Updated guidance and examples to recommend targeted entry deletion over broad database deletion.

🔄 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/4926 **Author:** [@kolacheee](https://github.com/kolacheee) **Created:** 8/11/2026 **Status:** ✅ Merged **Merged:** 8/11/2026 **Merged by:** [@kolacheee](https://github.com/kolacheee) **Base:** `staging` ← **Head:** `fix/mari-lorebook-delete-entry` --- ### 📝 Commits (2) - [`629489d`](https://github.com/Pasta-Devs/Marinara-Engine/commit/629489df8394b4fb2f4649e6f2ec9e04050918a8) fix(server): give Professor Mari a safe lorebook.deleteEntry action (#4924) - [`d9638b1`](https://github.com/Pasta-Devs/Marinara-Engine/commit/d9638b1b0614853c283f518788cbb22484688d91) test: isolate the lorebook.deleteEntry fixture cleanup in a finally block (#4924) ### 📊 Changes **4 files changed** (+78 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `CHANGELOG.md` (+1 -0) 📝 `packages/server/src/services/mari-db/mari-db.service.ts` (+25 -0) 📝 `packages/server/src/services/professor-mari/workspace-agent.service.ts` (+4 -1) 📝 `scripts/regressions/open-issues.regression.ts` (+48 -0) </details> ### 📄 Description ## Linked issue Closes #4924 ## Why this change Professor Mari had **no safe way to delete a single lorebook entry**: her `app_data` toolkit exposes `lorebook.addEntry` and `lorebook.updateEntry` but no `deleteEntry`. When a user asked her to delete one entry, `lorebook.deleteEntry` failed (not a real action), so she fell back to the raw `mari db delete <table> --where <expr>` command — a bulk delete with no row-count guard — and removed **77 entries across unrelated lorebooks** instead of the one. (The deletion was recoverable via the Keep/Restore card, but the blast radius was the whole matched set.) ## What changed - **`packages/server/src/services/mari-db/mari-db.service.ts`** — added a `lorebook.deleteEntry` `app_data` action: it takes `entryId`, verifies the entry exists (throws otherwise), and deletes exactly that one row (`{ kind: "delete", table: "lorebook_entries", id, cascade: false }`) through the same `executeMutation` → Keep/Restore review as add/update. This is the identical shape the CLI's `mari lorebooks delete-entry <id>` already uses. Also registered delete aliases (`lorebook.entry.delete`, `lorebook.entries.delete`, `lorebook.entry.remove`, `lorebook.removeentry`, …). - **`packages/server/src/services/professor-mari/workspace-agent.service.ts`** — registered `lorebook.deleteEntry` in the action catalog and the Writes quick-ref, added a prompt bullet ("to delete a lorebook entry use `lorebook.deleteEntry`; **never** a raw `mari db delete`, whose `--where` can remove far more rows than intended; if a raw `mari db delete` is ever unavoidable, dry-run and confirm the row count first"), and a worked example. - **`scripts/regressions/open-issues.regression.ts`** — new test that creates a lorebook with two entries, deletes one via `lorebook.deleteEntry`, and asserts **exactly one** is removed, the other survives, and deleting a missing id is rejected. - **`CHANGELOG.md`** — one Fixed entry. Note on classification: `lorebook.deleteEntry` is correctly treated as **mutating** (its suffix isn't in the read-only whitelist), so it can't bypass the review and produces a recoverable Keep/Restore card. Out of scope (deliberately, per the issue): a broader guardrail on raw `mari db delete --where` bulk deletes (dry-run-and-confirm before applying) — can be tracked separately. ## 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, done by me: - `pnpm check` passes (TypeScript + ESLint + build, exit 0). - The full `open-issues` regression passes, including the new scoping test (delete one of two entries → exactly one removed, the other survives, missing id rejected). Still needs a human (please verify in a real browser, don't trust the boxes above): - Ask Mari to delete one lorebook entry; confirm she uses `lorebook.deleteEntry`, only that entry is removed, and a Keep/Restore card appears (Restore puts it back). - Confirm she no longer reaches for `mari db delete` for a single-entry delete. ## Docs and release impact - [ ] No docs changes needed - [x] 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) `CHANGELOG.md` updated. No `docs/` change and no version bump. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Added a safer tool for deleting individual lorebook entries. - Supports deletion by entry ID with an explicit apply step. - Prevents unintended removal of other entries in the same lorebook. - **Bug Fixes** - Deleting a nonexistent lorebook entry now reports a failure instead of proceeding. - **Documentation** - Updated guidance and examples to recommend targeted entry deletion over broad database deletion. <!-- 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:25 +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#6545
No description provided.