[PR #5730] [MERGED] feat(mari): Permissions Mode — Auto / Manual / Accept edits / Plan / Bypass #6907

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

📋 Pull Request Information

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

Base: staging ← Head: feat/5725-mari-permissions-mode


📝 Commits (10+)

  • 1e175b3 feat(mari): Permissions Mode - Auto / Manual / Accept edits / Plan / Bypass (#5725)
  • 89c5e62 fix(mari): close the Permissions Mode review findings
  • 3a9646f feat(mari): per-chat Permissions Mode with a global default (#5725)
  • a34cf3d fix(mari): make the per-chat mode display switch-safe
  • a9c4157 chore(mari): drop now-unused deps from changePermissionsMode
  • deef52a fix(mari): close the CodeRabbit round on Permissions Mode
  • c3ed994 fix(mari): close CodeRabbit round 2 - restore the deletion boundary, guard superseded-run writes
  • 3037734 fix(mari): address the out-of-diff-range review findings
  • ffd44fc fix(mari): chain mode writes, scope the pending hold, satisfy repo validators
  • 03f10a7 fix(mari): one shared write chain for BOTH Permissions Mode surfaces

📊 Changes

16 files changed (+1066 additions, -18 deletions)

View changed files

📝 CHANGELOG.md (+2 -0)
📝 e2e/core-flows.e2e.ts (+6 -0)
📝 packages/client/src/components/chat/HomeProfessorMariChat.tsx (+207 -2)
📝 packages/client/src/components/panels/SettingsPanel.tsx (+10 -0)
📝 packages/client/src/components/panels/settings/SettingControls.tsx (+96 -0)
➕ packages/client/src/lib/mari-permissions-write-chain.ts (+29 -0)
📝 packages/client/src/localization/locales/en.json (+16 -0)
📝 packages/server/src/routes/professor-mari-workspace.routes.ts (+43 -2)
📝 packages/server/src/services/mari-db/mari-db.service.ts (+74 -1)
📝 packages/server/src/services/professor-mari/workspace-agent.service.ts (+191 -12)
➕ packages/shared/src/constants/mari-permissions-mode.ts (+42 -0)
📝 packages/shared/src/index.ts (+1 -0)
📝 packages/shared/src/types/chat.ts (+2 -0)
📝 packages/shared/src/types/professor-mari-workspace.ts (+7 -0)
➕ scripts/regressions/mari-permissions-mode.regression.ts (+337 -0)
📝 scripts/regressions/open-issues.regression.ts (+3 -1)

📄 Description

Linked issue

Closes #5725.

Stacked on #5727 #5727 and #5728 have merged and this branch is rebased onto them — the diff is now the feature alone (two commits: the feature and its adversarial-review fix round).

Why this change

Mari's permission posture has been a pendulum: some users found her too edit-happy (#4813 → #4838), and the stricter gate added afterwards produced the redundant double-confirmation flow removed in #5727. No single default satisfies both a user who says "present your proposal" and means describe it in chat, and a power user who wants edits applied the moment they ask. A user-selectable mode — like the Claude app's picker — replaces the one-size-fits-all posture with policy the user chooses, and takes the pressure off the default forever.

What changed

The five modes (server-enforced, not just prompt-suggested):

Mode Behavior
Auto (default) Exactly the current behavior — Mari judges from your words and saved memories.
Manual Every response describing mutating commands defers them behind the existing Accept-chip flow; post-approval command frames (empty say) execute.
Accept edits Record edits apply without a pending Keep/Restore card (history + undo journal still recorded). Deletions always keep their card.
Plan A hard floor in the command executor: mutating commands are refused with an instructive error; apply:false dry-runs stay allowed; Mari lays out exact edits in chat.
Bypass Accept-edits plus no ask-first deferral at all.

Floors that hold in every mode: sensitive-file staging, Personal Extension approval, dependency-install approval (all structural), and the Keep/Restore card on deletions (delete/forget/remove/uninstall actions) — under card-suppressing modes it is a destructive action's last undo surface.

Architecture (follows the docs-language settings pattern): shared enum constants; the setting lives in app_settings under a key deliberately absent from the generic ALLOWED_KEYS passthrough, owned by dedicated validated GET/PUT /permissions-mode routes (zod enum, privileged-gated); read fresh per run and per status() call (never latched — the workspace service singleton caches at first call); a mode switch never reset()s the agent, so an in-flight turn finishes under the mode it started with. Accept-edits/Bypass ride a reviewPolicy field on the app_data envelope, honored at mari-db's single executeMutation choke point. The mode-specific prompt block is spliced after the saved-memories block — the mode is the user's explicit current selection, so it outranks a stale memory (which may further restrict, never loosen) — and it overrides the static prompt's Keep/Restore promises where a mode suppresses the card.

Client: the mode rides MariWorkspaceStatus; a shield button in Mari's panel header opens the five-mode picker (optimistic update + rollback), and Settings → Application gains a searchable select with the same write path.

Design calls (maintainer-reviewed)

  1. Bypass keeps the deletion card and all structural floors — approved as shipped.
  2. Mode outranks memories; memories may only tighten — approved as shipped.
  3. Per-chat mode with a global default — the maintainer asked for per-chat now rather than later, so the mode is resolved per run as chat override ?? global default: the shield picker in Mari's header sets the open chat's mode (with a "Use default" row that follows the global setting), Settings → Application sets the default, the override lives in chat metadata written through the queued #5076 patch by the same validated PUT, the status payload is chat-scoped (effective mode + default + source), and the raw-db floor extends to the override (a chats-metadata write that changes it is blocked; whole-chat deletes stay allowed).
  4. Mari cannot switch modes herself — approved as shipped; per the maintainer, self-switching should never be implemented.

Candidate follow-up (from CodeRabbit round 2, not implemented here): a structural one-shot accept for Manual mode — the Accept chip could set a server-side token consumed by the next run — instead of the current last-message-flag arming. Declined intent-parsing of accept words for the same reason #5721 removed the authorization regexes; Manual mode never suppresses Keep/Restore cards, which bounds the residual.

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 lint, all three package builds, and the e2e type lane are green locally; format:check fails repo-wide on this Windows checkout (pre-existing autocrlf CRLF; touched files were run through Prettier directly).
  • New regression mari-permissions-mode passes: functional checks on the pure pieces (stored-mode normalizer tolerates junk/absence/storage failure; per-mode prompt renderer incl. the memory-precedence rule) plus source pins on every enforcement seam, the after-memories splice order, the no-reset rule, and the ALLOWED_KEYS exclusion. Sibling lanes (mari-edit-flow-revert, prompt.regression, issue-sweep-5380-5434) stay green.
  • A two-lens adversarial review (enforcement soundness; prompt coherence + client correctness) raised 13 findings; 7 were confirmed by independent verification and are all fixed in the second commit. The two high-severity ones were structural: the transient review-policy field leaked into the mari CLI path (a stale auto-keep could strip the Keep/Restore card from CLI deletions, even after switching back to Auto — now reset at both entry points and on exit), and Mari could rewrite her own mode row via raw mari db patch on app_settings (a prompt-injection escalation path to Bypass — now blocked by a change-level planMutation floor covering every raw-db mutation kind). Also fixed: manual mode gained a real server floor for silent (empty-say) mutating frames — they execute only in the run right after an approved deferral; plan mode's guidance points at app_data apply:false for previews; the mode picker refetches status after its PUT so an in-flight poll can't clobber the optimistic patch; the Settings select refetches on focus so it tracks header changes; and all ten mode labels/descriptions are now en.json values rendered through the localization bridge (they were hardcoded English on a safety-relevant control). The 6 refuted findings included three manual/bypass semantics attacks that turned out to be the modes' documented, user-selected contracts. A second focused review of the per-chat layer confirmed 2 further findings, fixed in the final commits: a chat switch never refetched the now chat-scoped status, so the shield could show the previous chat's mode in exactly the pre-send window (a switch now refetches immediately, stale responses dropped), and the picker's same-value short-circuits keyed on that stale state could silently drop a "Use default" de-escalation (removed — every click sends the idempotent write and converges via the post-PUT refetch).
  • Please verify manually: switch modes from the shield button in Mari's header; in Plan, ask for an edit ("make X more cynical") — she should lay out the exact changes and the transcript should show refused mutating commands if she tries; in Manual, the same ask should produce a description + Accept chip, then apply on accept; in Accept edits, a requested edit should apply with no Keep/Restore card while a delete still shows one.

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 updated under [Unreleased] → Added. The Professor Mari guides under docs/ are deliberately untouched (docs-i18n mirror debt is batched per the maintainer's standing call); a docs section should ride the next catch-up round.

UI evidence (if applicable)

The shield-button picker in Mari's panel header and the Settings → Application select are the visible additions.

Summary by CodeRabbit

  • New Features

    • Added Professor Mari’s Permissions Mode with Auto, Manual, Accept edits, Plan, and Bypass options.
    • Set a global default in Settings or override it for individual chats from Mari’s header.
    • Changes apply to the next run without interrupting active runs.
    • Manual and Plan modes provide additional safeguards; deletions and sensitive changes always require review.
    • View the active mode and restore any chat to the global default at any time.
  • Documentation

    • Documented Permissions Mode in the unreleased changelog.

🔄 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/5730 **Author:** [@kolacheee](https://github.com/kolacheee) **Created:** 9/1/2026 **Status:** ✅ Merged **Merged:** 9/2/2026 **Merged by:** [@kolacheee](https://github.com/kolacheee) **Base:** `staging` ← **Head:** `feat/5725-mari-permissions-mode` --- ### 📝 Commits (10+) - [`1e175b3`](https://github.com/Pasta-Devs/Marinara-Engine/commit/1e175b3a0b85266b6ed3249c962d7cfd5d5a1067) feat(mari): Permissions Mode - Auto / Manual / Accept edits / Plan / Bypass (#5725) - [`89c5e62`](https://github.com/Pasta-Devs/Marinara-Engine/commit/89c5e62b1ae7c6cc6354d0f59a19944b46ffc2d8) fix(mari): close the Permissions Mode review findings - [`3a9646f`](https://github.com/Pasta-Devs/Marinara-Engine/commit/3a9646f5023d6bddc2ce37bc85ab371bb9b58a2c) feat(mari): per-chat Permissions Mode with a global default (#5725) - [`a34cf3d`](https://github.com/Pasta-Devs/Marinara-Engine/commit/a34cf3df5a34f74ebc43e3c2c7556472ad3509f5) fix(mari): make the per-chat mode display switch-safe - [`a9c4157`](https://github.com/Pasta-Devs/Marinara-Engine/commit/a9c41579f877559c08547c739af333104c71e165) chore(mari): drop now-unused deps from changePermissionsMode - [`deef52a`](https://github.com/Pasta-Devs/Marinara-Engine/commit/deef52a18bb9676626a92f97900a9f77dcddf4c8) fix(mari): close the CodeRabbit round on Permissions Mode - [`c3ed994`](https://github.com/Pasta-Devs/Marinara-Engine/commit/c3ed994502993c5777967fe15c9007b50d9902a3) fix(mari): close CodeRabbit round 2 - restore the deletion boundary, guard superseded-run writes - [`3037734`](https://github.com/Pasta-Devs/Marinara-Engine/commit/303773406252e1dab0879d0166c710567e25ab80) fix(mari): address the out-of-diff-range review findings - [`ffd44fc`](https://github.com/Pasta-Devs/Marinara-Engine/commit/ffd44fc9821ea649f1206e5f46a1c29faec54ed7) fix(mari): chain mode writes, scope the pending hold, satisfy repo validators - [`03f10a7`](https://github.com/Pasta-Devs/Marinara-Engine/commit/03f10a7cb360f8291627cdbaf31a5c4d4caf8cd9) fix(mari): one shared write chain for BOTH Permissions Mode surfaces ### 📊 Changes **16 files changed** (+1066 additions, -18 deletions) <details> <summary>View changed files</summary> 📝 `CHANGELOG.md` (+2 -0) 📝 `e2e/core-flows.e2e.ts` (+6 -0) 📝 `packages/client/src/components/chat/HomeProfessorMariChat.tsx` (+207 -2) 📝 `packages/client/src/components/panels/SettingsPanel.tsx` (+10 -0) 📝 `packages/client/src/components/panels/settings/SettingControls.tsx` (+96 -0) ➕ `packages/client/src/lib/mari-permissions-write-chain.ts` (+29 -0) 📝 `packages/client/src/localization/locales/en.json` (+16 -0) 📝 `packages/server/src/routes/professor-mari-workspace.routes.ts` (+43 -2) 📝 `packages/server/src/services/mari-db/mari-db.service.ts` (+74 -1) 📝 `packages/server/src/services/professor-mari/workspace-agent.service.ts` (+191 -12) ➕ `packages/shared/src/constants/mari-permissions-mode.ts` (+42 -0) 📝 `packages/shared/src/index.ts` (+1 -0) 📝 `packages/shared/src/types/chat.ts` (+2 -0) 📝 `packages/shared/src/types/professor-mari-workspace.ts` (+7 -0) ➕ `scripts/regressions/mari-permissions-mode.regression.ts` (+337 -0) 📝 `scripts/regressions/open-issues.regression.ts` (+3 -1) </details> ### 📄 Description ## Linked issue Closes #5725. > ~~Stacked on #5727~~ **#5727 and #5728 have merged and this branch is rebased onto them** — the diff is now the feature alone (two commits: the feature and its adversarial-review fix round). ## Why this change Mari's permission posture has been a pendulum: some users found her too edit-happy (#4813 → #4838), and the stricter gate added afterwards produced the redundant double-confirmation flow removed in #5727. No single default satisfies both a user who says "present your proposal" and means *describe it in chat*, and a power user who wants edits applied the moment they ask. A user-selectable mode — like the Claude app's picker — replaces the one-size-fits-all posture with policy the user chooses, and takes the pressure off the default forever. ## What changed **The five modes** (server-enforced, not just prompt-suggested): | Mode | Behavior | | --- | --- | | **Auto** (default) | Exactly the current behavior — Mari judges from your words and saved memories. | | **Manual** | Every response describing mutating commands defers them behind the existing Accept-chip flow; post-approval command frames (empty `say`) execute. | | **Accept edits** | Record edits apply without a pending Keep/Restore card (history + undo journal still recorded). Deletions always keep their card. | | **Plan** | A hard floor in the command executor: mutating commands are refused with an instructive error; `apply:false` dry-runs stay allowed; Mari lays out exact edits in chat. | | **Bypass** | Accept-edits plus no ask-first deferral at all. | **Floors that hold in every mode:** sensitive-file staging, Personal Extension approval, dependency-install approval (all structural), and the Keep/Restore card on deletions (`delete`/`forget`/`remove`/`uninstall` actions) — under card-suppressing modes it is a destructive action's last undo surface. **Architecture** (follows the docs-language settings pattern): shared enum constants; the setting lives in `app_settings` under a key deliberately absent from the generic `ALLOWED_KEYS` passthrough, owned by dedicated validated `GET`/`PUT /permissions-mode` routes (zod enum, privileged-gated); read fresh per run and per `status()` call (never latched — the workspace service singleton caches at first call); a mode switch never `reset()`s the agent, so an in-flight turn finishes under the mode it started with. Accept-edits/Bypass ride a `reviewPolicy` field on the `app_data` envelope, honored at mari-db's single `executeMutation` choke point. The mode-specific prompt block is spliced **after** the saved-memories block — the mode is the user's explicit current selection, so it outranks a stale memory (which may further restrict, never loosen) — and it overrides the static prompt's Keep/Restore promises where a mode suppresses the card. **Client:** the mode rides `MariWorkspaceStatus`; a shield button in Mari's panel header opens the five-mode picker (optimistic update + rollback), and Settings → Application gains a searchable select with the same write path. ## Design calls (maintainer-reviewed) 1. **Bypass keeps the deletion card and all structural floors** — approved as shipped. 2. **Mode outranks memories; memories may only tighten** — approved as shipped. 3. **Per-chat mode with a global default** — the maintainer asked for per-chat now rather than later, so the mode is resolved per run as *chat override ?? global default*: the shield picker in Mari's header sets the open chat's mode (with a "Use default" row that follows the global setting), Settings → Application sets the default, the override lives in chat metadata written through the queued #5076 patch by the same validated PUT, the status payload is chat-scoped (effective mode + default + source), and the raw-db floor extends to the override (a chats-metadata write that changes it is blocked; whole-chat deletes stay allowed). 4. **Mari cannot switch modes herself** — approved as shipped; per the maintainer, self-switching should never be implemented. Candidate follow-up (from CodeRabbit round 2, not implemented here): a structural one-shot accept for Manual mode — the Accept chip could set a server-side token consumed by the next run — instead of the current last-message-flag arming. Declined intent-parsing of accept words for the same reason #5721 removed the authorization regexes; Manual mode never suppresses Keep/Restore cards, which bounds the residual. ## 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 lint`, all three package builds, and the e2e type lane are green locally; `format:check` fails repo-wide on this Windows checkout (pre-existing autocrlf CRLF; touched files were run through Prettier directly). - New regression `mari-permissions-mode` passes: functional checks on the pure pieces (stored-mode normalizer tolerates junk/absence/storage failure; per-mode prompt renderer incl. the memory-precedence rule) plus source pins on every enforcement seam, the after-memories splice order, the no-reset rule, and the `ALLOWED_KEYS` exclusion. Sibling lanes (`mari-edit-flow-revert`, `prompt.regression`, `issue-sweep-5380-5434`) stay green. - A two-lens adversarial review (enforcement soundness; prompt coherence + client correctness) raised 13 findings; 7 were confirmed by independent verification and are all fixed in the second commit. The two high-severity ones were structural: the transient review-policy field leaked into the `mari` CLI path (a stale auto-keep could strip the Keep/Restore card from CLI deletions, even after switching back to Auto — now reset at both entry points and on exit), and Mari could rewrite her own mode row via raw `mari db patch` on `app_settings` (a prompt-injection escalation path to Bypass — now blocked by a change-level `planMutation` floor covering every raw-db mutation kind). Also fixed: manual mode gained a real server floor for silent (empty-say) mutating frames — they execute only in the run right after an approved deferral; plan mode's guidance points at `app_data apply:false` for previews; the mode picker refetches status after its PUT so an in-flight poll can't clobber the optimistic patch; the Settings select refetches on focus so it tracks header changes; and all ten mode labels/descriptions are now en.json values rendered through the localization bridge (they were hardcoded English on a safety-relevant control). The 6 refuted findings included three manual/bypass semantics attacks that turned out to be the modes' documented, user-selected contracts. A second focused review of the per-chat layer confirmed 2 further findings, fixed in the final commits: a chat switch never refetched the now chat-scoped status, so the shield could show the previous chat's mode in exactly the pre-send window (a switch now refetches immediately, stale responses dropped), and the picker's same-value short-circuits keyed on that stale state could silently drop a "Use default" de-escalation (removed — every click sends the idempotent write and converges via the post-PUT refetch). - **Please verify manually:** switch modes from the shield button in Mari's header; in **Plan**, ask for an edit ("make X more cynical") — she should lay out the exact changes and the transcript should show refused mutating commands if she tries; in **Manual**, the same ask should produce a description + Accept chip, then apply on accept; in **Accept edits**, a requested edit should apply with no Keep/Restore card while a delete still shows one. ## 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 updated under **[Unreleased] → Added**. The Professor Mari guides under `docs/` are deliberately untouched (docs-i18n mirror debt is batched per the maintainer's standing call); a docs section should ride the next catch-up round. ## UI evidence (if applicable) The shield-button picker in Mari's panel header and the Settings → Application select are the visible additions. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Added Professor Mari’s Permissions Mode with Auto, Manual, Accept edits, Plan, and Bypass options. - Set a global default in Settings or override it for individual chats from Mari’s header. - Changes apply to the next run without interrupting active runs. - Manual and Plan modes provide additional safeguards; deletions and sensitive changes always require review. - View the active mode and restore any chat to the global default at any time. - **Documentation** - Documented Permissions Mode in the unreleased changelog. <!-- 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:14:48 +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#6907
No description provided.