[PR #4836] [MERGED] feat(mari-db): let Professor Mari see and edit specific parts of a preset (#4812) #6512

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

📋 Pull Request Information

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

Base: staging ← Head: fix/4812-mari-preset-granular


📝 Commits (3)

  • b125e6f feat(mari-db): let Professor Mari see and edit specific parts of a preset (#4812)
  • 4abdabf Merge branch 'staging' into fix/4812-mari-preset-granular
  • d14d063 Merge branch 'staging' into fix/4812-mari-preset-granular

📊 Changes

6 files changed (+1241 additions, -14 deletions)

View changed files

📝 CHANGELOG.md (+1 -0)
📝 docs/home/professor-mari.md (+1 -0)
📝 package.json (+2 -1)
📝 packages/server/src/services/mari-db/mari-db.service.ts (+899 -9)
📝 packages/server/src/services/professor-mari/workspace-agent.service.ts (+26 -4)
➕ scripts/regressions/mari-preset-granular.regression.ts (+312 -0)

📄 Description

Linked issue

Fixes #4812.

Why this change

Professor Mari could only create or replace a whole preset. preset.get returned bare section-id arrays with no content, and nothing resolved to a patch against one section, so she couldn't single out "the formatting section" to add a line — while the same request asked out-of-character to the roleplay AI (which has the preset rendered into its prompt as text) succeeded easily. In the reporter's words, she "lacks the ability to see or edit parts of presets."

What changed

Granular section / group / choice-block actions on MariDbService, modeled on the lorebook entry actions and all routed through executeMutation, so each edit gets the reversible Keep/Restore review for free:

  • Read: preset.sections / getSection, preset.groups / getGroup, preset.choiceBlocks / getChoiceBlock — a compact index (id + name + a content preview, ordered by the preset's sectionOrder/groupOrder) plus a full single-item read. This is the "let her see it" half.
  • Update: preset.updateSection / updateGroup / updateChoiceBlock via a plain patch on the child table. A marker section rejects a content patch (its content is generated).
  • Add: preset.addSection / addGroup insert the child and append its id to the parent's order array in one atomic reviewable plan (a child missing from the order array is never assembled); preset.addChoiceBlock is a plain insert (choice-blocks order by their own sortOrder).
  • Delete: two small custom planners (preset-section-delete, preset-group-delete) prune the order array and delete the row; deleting a group orphans its member sections and un-nests its child groups, exactly matching the storage layer's removeGroup. restorePlan reverses all of these FK-safe.

"Add a line to a specific spot" is served by getSection → splice the line into the full content → updateSection — the section is the finest addressable unit (content is one opaque text column; there is no line/offset addressing).

CLI: a new mari presets command group (list|get|sections|get-section|groups|get-group|choice-blocks|get-choice-block, add/update/delete for each child type, and create/update via --json) that parses flags and delegates to the same handlers, so the granular edits are available from the shell too.

Folded-in data-safety fix (from the merged #4825 review): planRelatedInserts now refuses a colliding child id the same way planInsert does. On the file-native backend a colliding child insert already hard-fails; the guard's value is failing early with a clear message and fixing a deceptive apply:false preview (which showed the colliding child as a clean insert) instead of a late unique-constraint abort.

Prompt, docs/home/professor-mari.md, and CHANGELOG.md updated.

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

  • pnpm check (TypeScript + ESLint + localization + build) passes.
  • New pnpm regression:mari-preset-granular (wired into the regression:issues lane) drives the real service through: seed a preset → read (she sees section content) → a targeted update that changes only that section and reverts on Restore → add (appended to sectionOrder) → delete (pruned) → group-delete (orphans its sections) → a CLI round-trip (mari presets sections, mari presets add-section --apply) → the child-clobber guard. The professor-mari prompt/documentation regressions still pass.
  • An adversarial review caught one real bug that this PR fixes: the new preset reads weren't matched by the workspace read-only classifier, so Mari's verify-after-edit loop would have misfired on exactly this workflow (she'd read a section back to confirm and not get credit). Fixed, plus an updateChoiceBlock empty-options guard and identifier/variableName de-duplication for single add/rename.
  • Manually verify in browser: in the Home Professor Mari chat, ask her to add a line to a specific section of a preset you use; confirm she reads the section, shows a Keep/Restore card, and the edit lands in the right spot without touching other sections.

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)

Updated docs/home/professor-mari.md (one capability bullet) and CHANGELOG.md. A [docs-i18n] follow-up will be filed to mirror the professor-mari.md change. No version bump.

Summary by CodeRabbit

  • New Features

    • Added granular editing for Professor Mari prompt presets, including individual sections, groups, and choice blocks.
    • Added CLI commands to list, view, create, update, and delete preset components.
    • Added validation to protect preset data, ordering, references, and identifiers.
    • Added workspace assistant actions and quick-reference guidance for preset management.
  • Documentation

    • Added guidance and examples for reading and modifying individual preset components.
  • Tests

    • Added regression coverage for granular preset operations, ordering, deletions, validation, and CLI consistency.

🔄 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/4836 **Author:** [@kolacheee](https://github.com/kolacheee) **Created:** 8/9/2026 **Status:** ✅ Merged **Merged:** 8/10/2026 **Merged by:** [@kolacheee](https://github.com/kolacheee) **Base:** `staging` ← **Head:** `fix/4812-mari-preset-granular` --- ### 📝 Commits (3) - [`b125e6f`](https://github.com/Pasta-Devs/Marinara-Engine/commit/b125e6fce049b138ef2036ad5a474ec7fb70df99) feat(mari-db): let Professor Mari see and edit specific parts of a preset (#4812) - [`4abdabf`](https://github.com/Pasta-Devs/Marinara-Engine/commit/4abdabf8600bac8e49d1be2893105510b3ac5784) Merge branch 'staging' into fix/4812-mari-preset-granular - [`d14d063`](https://github.com/Pasta-Devs/Marinara-Engine/commit/d14d063b52666431f32e33d6074cc3e614ebac3f) Merge branch 'staging' into fix/4812-mari-preset-granular ### 📊 Changes **6 files changed** (+1241 additions, -14 deletions) <details> <summary>View changed files</summary> 📝 `CHANGELOG.md` (+1 -0) 📝 `docs/home/professor-mari.md` (+1 -0) 📝 `package.json` (+2 -1) 📝 `packages/server/src/services/mari-db/mari-db.service.ts` (+899 -9) 📝 `packages/server/src/services/professor-mari/workspace-agent.service.ts` (+26 -4) ➕ `scripts/regressions/mari-preset-granular.regression.ts` (+312 -0) </details> ### 📄 Description ## Linked issue Fixes #4812. ## Why this change Professor Mari could only create or **replace a whole preset**. `preset.get` returned bare section-id arrays with no content, and nothing resolved to a patch against one section, so she couldn't single out "the formatting section" to add a line — while the same request asked out-of-character to the roleplay AI (which has the preset rendered into its prompt as text) succeeded easily. In the reporter's words, she "lacks the ability to see or edit parts of presets." ## What changed Granular section / group / choice-block actions on `MariDbService`, modeled on the lorebook entry actions and all routed through `executeMutation`, so each edit gets the reversible **Keep/Restore review** for free: - **Read:** `preset.sections` / `getSection`, `preset.groups` / `getGroup`, `preset.choiceBlocks` / `getChoiceBlock` — a compact index (id + name + a content preview, ordered by the preset's `sectionOrder`/`groupOrder`) plus a full single-item read. This is the "let her *see* it" half. - **Update:** `preset.updateSection` / `updateGroup` / `updateChoiceBlock` via a plain patch on the child table. A marker section rejects a content patch (its content is generated). - **Add:** `preset.addSection` / `addGroup` insert the child **and** append its id to the parent's order array in one atomic reviewable plan (a child missing from the order array is never assembled); `preset.addChoiceBlock` is a plain insert (choice-blocks order by their own `sortOrder`). - **Delete:** two small custom planners (`preset-section-delete`, `preset-group-delete`) prune the order array and delete the row; deleting a group **orphans** its member sections and un-nests its child groups, exactly matching the storage layer's `removeGroup`. `restorePlan` reverses all of these FK-safe. "Add a line to a specific spot" is served by `getSection` → splice the line into the full content → `updateSection` — the section is the finest addressable unit (content is one opaque text column; there is no line/offset addressing). **CLI:** a new `mari presets` command group (`list|get|sections|get-section|groups|get-group|choice-blocks|get-choice-block`, `add/update/delete` for each child type, and `create`/`update` via `--json`) that parses flags and delegates to the same handlers, so the granular edits are available from the shell too. **Folded-in data-safety fix (from the merged #4825 review):** `planRelatedInserts` now refuses a colliding child id the same way `planInsert` does. On the file-native backend a colliding child insert already hard-fails; the guard's value is failing **early with a clear message** and fixing a **deceptive `apply:false` preview** (which showed the colliding child as a clean insert) instead of a late unique-constraint abort. Prompt, `docs/home/professor-mari.md`, and `CHANGELOG.md` updated. ## 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 - `pnpm check` (TypeScript + ESLint + localization + build) passes. - New `pnpm regression:mari-preset-granular` (wired into the `regression:issues` lane) drives the real service through: seed a preset → **read** (she sees section content) → a **targeted update** that changes only that section and **reverts on Restore** → **add** (appended to `sectionOrder`) → **delete** (pruned) → **group-delete** (orphans its sections) → a **CLI** round-trip (`mari presets sections`, `mari presets add-section --apply`) → the child-clobber guard. The professor-mari prompt/documentation regressions still pass. - An adversarial review caught one real bug that this PR fixes: the new preset *reads* weren't matched by the workspace read-only classifier, so Mari's verify-after-edit loop would have misfired on exactly this workflow (she'd read a section back to confirm and not get credit). Fixed, plus an `updateChoiceBlock` empty-options guard and identifier/variableName de-duplication for single add/rename. - **Manually verify in browser:** in the Home Professor Mari chat, ask her to add a line to a specific section of a preset you use; confirm she reads the section, shows a Keep/Restore card, and the edit lands in the right spot without touching other sections. ## 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) Updated `docs/home/professor-mari.md` (one capability bullet) and `CHANGELOG.md`. A `[docs-i18n]` follow-up will be filed to mirror the professor-mari.md change. No version bump. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Added granular editing for Professor Mari prompt presets, including individual sections, groups, and choice blocks. * Added CLI commands to list, view, create, update, and delete preset components. * Added validation to protect preset data, ordering, references, and identifiers. * Added workspace assistant actions and quick-reference guidance for preset management. * **Documentation** * Added guidance and examples for reading and modifying individual preset components. * **Tests** * Added regression coverage for granular preset operations, ordering, deletions, validation, and CLI consistency. <!-- 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:08 +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#6512
No description provided.