[PR #7520] [MERGED] Professor Mari: move tools, round review and message storage out of the run loop #7773

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

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/7520
Author: @Gunterlie
Created: 10/13/2026
Status: ✅ Merged
Merged: 10/13/2026
Merged by: @Gunterlie

Base: feat/mari-pi-runtime ← Head: feat/mari-pi-runtime-1-extract


📝 Commits (6)

  • d29a2df Move Mari's workspace tool commands into WorkspaceCommands
  • d2817ed Keep executeWorkspaceCommand delegate reachable for scripts
  • 466db9a Extract Mari's per-round safety review into workspace-round-review
  • 0ff8b5b Extract Mari's message storage into workspace-message-store
  • 11f7340 Pin the round-review call sites in the run loop and format touched regressions
  • 5985535 Mark type-only imports in workspace-commands

📊 Changes

14 files changed (+1683 additions, -1230 deletions)

View changed files

📝 packages/server/src/services/professor-mari/workspace-agent.service.ts (+125 -1199)
➕ packages/server/src/services/professor-mari/workspace-commands.ts (+1090 -0)
➕ packages/server/src/services/professor-mari/workspace-message-store.ts (+110 -0)
➕ packages/server/src/services/professor-mari/workspace-round-review.ts (+147 -0)
📝 scripts/regressions/mari-ask-latch.regression.ts (+8 -5)
📝 scripts/regressions/mari-edit-flow-revert.regression.ts (+3 -1)
📝 scripts/regressions/mari-guard-sibling-paths.regression.ts (+9 -4)
📝 scripts/regressions/mari-permissions-mode.regression.ts (+26 -6)
📝 scripts/regressions/mari-polish.regression.ts (+3 -1)
📝 scripts/regressions/mari-write-readback.regression.ts (+3 -1)
📝 scripts/regressions/mari/review-cards.regression.ts (+6 -3)
➕ scripts/regressions/professor-mari/round-review.regression.ts (+132 -0)
📝 scripts/regressions/professor-mari/shell-sandbox.regression.ts (+9 -4)
📝 scripts/regressions/prompt.regression.ts (+12 -6)

📄 Description

Linked issue

No linked issue. This is planned work: slice 1 of 2 on the integration branch feat/mari-pi-runtime (a trial of a second, pi-based runtime for Professor Mari, switchable in her settings). This PR targets that integration branch, not staging.

Why this change

  • Professor Mari's agent loop, her tool commands, her safety checks and her message storage all lived in one 5,491-line class. A second runtime cannot reuse the tools and safety checks without copying them, and copied sandbox code drifts.
  • The safety checks could only run inside a live model loop, so they were hard to test on their own.
  • This slice changes no behavior. It only makes the shared parts callable from outside the loop, so slice 2 can add the pi runtime on top of the same tools, the same checks and the same stored records.

What changed

  • workspace-commands.ts (new): class WorkspaceCommands holds every tool command (read, write, edit, shell, mari, app data, package service), the path guards and the single mutation queue. Run-scoped state (permissions mode, the Manual and ask-latch floors, decision context) stays owned by the service and is read through a callback at use time.
  • workspace-round-review.ts (new): the per-round sequencing of the safety checks that was inline in prompt() — deferral of mutating commands, the completion-claim audit with its repair budgets, and the stop after repeated equal failures.
  • workspace-message-store.ts (new): creating the assistant message and building its extra, one code path for every exit (normal, deferral, error, abort).
  • workspace-agent.service.ts: 5,491 → 4,417 lines. Every previous export is still importable from this path. Thin delegates remain where regression scripts call them.
  • Regressions: scripts that assert on source text now read the new files too. New scripts/regressions/professor-mari/round-review.regression.ts drives the extracted review with recorded inputs (clean round, false "done" claim, readback mismatch, repeated-failure stop). mari-permissions-mode.regression.ts pins the three loop call sites so the loop keeps passing its local permissions mode and one review state per run.

Left inline on purpose, because moving them would change loop control: protocol and empty-frame repair, the length-limit stop, the chip repair and the round-limit summary.

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

Not done by a person yet. To verify by hand:

  • Manually verify Professor Mari can read a file and run a simple shell command.
  • Manually verify a character edit in Manual mode shows the held change and applies after approval.
  • Manually verify a change in Auto mode applies and the change card shows it.
  • Manually verify the shell sandbox on a host with bwrap (see Proof).

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 change.

Proof

Run by agents on commit 59855358d:

  • pnpm check: exit 0.
  • node ./scripts/run-regressions.mjs --filter mari: 49/49 passed.
  • node ./scripts/run-regressions.mjs --filter scripts/regressions/prompt.regression.ts: 1/1 passed.
  • Read-only adversarial review (Opus): no behavior change found. Moved code compared against the base commit: identical apart from this.x rewiring. Same order of checks, counters, limits, events, texts and stored extra keys. One mutation queue. The import cycle between the new files and the service evaluates nothing at module top level.
  • Local CodeRabbit: 1 minor finding (type-only imports in workspace-commands.ts), fixed in 59855358d.

Not proven:

  • The review host has no bwrap, so the shell sandbox runtime path was not executed. commandBash is shown identical by text comparison only.
  • round-review.regression.ts does not cover the mid-run repair budget, the staged and unverified prompts, or awaitingAuthorization. The existing loop-level scripts still cover those paths.

Known trade-offs:

  • The three new files import helpers back from workspace-agent.service.ts (import cycle, safe at load). About 30 helpers were exported from the service for them.
  • executeWorkspaceCommand is now public on the service so regression scripts can reach it. No runtime effect.

🔄 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/7520 **Author:** [@Gunterlie](https://github.com/Gunterlie) **Created:** 10/13/2026 **Status:** ✅ Merged **Merged:** 10/13/2026 **Merged by:** [@Gunterlie](https://github.com/Gunterlie) **Base:** `feat/mari-pi-runtime` ← **Head:** `feat/mari-pi-runtime-1-extract` --- ### 📝 Commits (6) - [`d29a2df`](https://github.com/Pasta-Devs/Marinara-Engine/commit/d29a2df453f6d5826dd19c26973ead74c14481a2) Move Mari's workspace tool commands into WorkspaceCommands - [`d2817ed`](https://github.com/Pasta-Devs/Marinara-Engine/commit/d2817ed55ed086f4efd53c897be54363ba1e7fcc) Keep executeWorkspaceCommand delegate reachable for scripts - [`466db9a`](https://github.com/Pasta-Devs/Marinara-Engine/commit/466db9a1e2f85f6359329426f0a594a57c97600a) Extract Mari's per-round safety review into workspace-round-review - [`0ff8b5b`](https://github.com/Pasta-Devs/Marinara-Engine/commit/0ff8b5b5043c327190af9747b8d6cbb97e7e6203) Extract Mari's message storage into workspace-message-store - [`11f7340`](https://github.com/Pasta-Devs/Marinara-Engine/commit/11f734068fb3f34f5dbac06d88cf50be00c20385) Pin the round-review call sites in the run loop and format touched regressions - [`5985535`](https://github.com/Pasta-Devs/Marinara-Engine/commit/59855358d5e2a4f9ce08e3e36aad047b121f863c) Mark type-only imports in workspace-commands ### 📊 Changes **14 files changed** (+1683 additions, -1230 deletions) <details> <summary>View changed files</summary> 📝 `packages/server/src/services/professor-mari/workspace-agent.service.ts` (+125 -1199) ➕ `packages/server/src/services/professor-mari/workspace-commands.ts` (+1090 -0) ➕ `packages/server/src/services/professor-mari/workspace-message-store.ts` (+110 -0) ➕ `packages/server/src/services/professor-mari/workspace-round-review.ts` (+147 -0) 📝 `scripts/regressions/mari-ask-latch.regression.ts` (+8 -5) 📝 `scripts/regressions/mari-edit-flow-revert.regression.ts` (+3 -1) 📝 `scripts/regressions/mari-guard-sibling-paths.regression.ts` (+9 -4) 📝 `scripts/regressions/mari-permissions-mode.regression.ts` (+26 -6) 📝 `scripts/regressions/mari-polish.regression.ts` (+3 -1) 📝 `scripts/regressions/mari-write-readback.regression.ts` (+3 -1) 📝 `scripts/regressions/mari/review-cards.regression.ts` (+6 -3) ➕ `scripts/regressions/professor-mari/round-review.regression.ts` (+132 -0) 📝 `scripts/regressions/professor-mari/shell-sandbox.regression.ts` (+9 -4) 📝 `scripts/regressions/prompt.regression.ts` (+12 -6) </details> ### 📄 Description ## Linked issue No linked issue. This is planned work: slice 1 of 2 on the integration branch `feat/mari-pi-runtime` (a trial of a second, pi-based runtime for Professor Mari, switchable in her settings). This PR targets that integration branch, not `staging`. ## Why this change - Professor Mari's agent loop, her tool commands, her safety checks and her message storage all lived in one 5,491-line class. A second runtime cannot reuse the tools and safety checks without copying them, and copied sandbox code drifts. - The safety checks could only run inside a live model loop, so they were hard to test on their own. - This slice changes no behavior. It only makes the shared parts callable from outside the loop, so slice 2 can add the pi runtime on top of the same tools, the same checks and the same stored records. ## What changed - `workspace-commands.ts` (new): class `WorkspaceCommands` holds every tool command (read, write, edit, shell, `mari`, app data, package service), the path guards and the single mutation queue. Run-scoped state (permissions mode, the Manual and ask-latch floors, decision context) stays owned by the service and is read through a callback at use time. - `workspace-round-review.ts` (new): the per-round sequencing of the safety checks that was inline in `prompt()` — deferral of mutating commands, the completion-claim audit with its repair budgets, and the stop after repeated equal failures. - `workspace-message-store.ts` (new): creating the assistant message and building its `extra`, one code path for every exit (normal, deferral, error, abort). - `workspace-agent.service.ts`: 5,491 → 4,417 lines. Every previous export is still importable from this path. Thin delegates remain where regression scripts call them. - Regressions: scripts that assert on source text now read the new files too. New `scripts/regressions/professor-mari/round-review.regression.ts` drives the extracted review with recorded inputs (clean round, false "done" claim, readback mismatch, repeated-failure stop). `mari-permissions-mode.regression.ts` pins the three loop call sites so the loop keeps passing its local permissions mode and one review state per run. Left inline on purpose, because moving them would change loop control: protocol and empty-frame repair, the length-limit stop, the chip repair and the round-limit summary. ## 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 Not done by a person yet. To verify by hand: - Manually verify Professor Mari can read a file and run a simple shell command. - Manually verify a character edit in Manual mode shows the held change and applies after approval. - Manually verify a change in Auto mode applies and the change card shows it. - Manually verify the shell sandbox on a host with `bwrap` (see Proof). ## 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 change. ## Proof Run by agents on commit `59855358d`: - `pnpm check`: exit 0. - `node ./scripts/run-regressions.mjs --filter mari`: 49/49 passed. - `node ./scripts/run-regressions.mjs --filter scripts/regressions/prompt.regression.ts`: 1/1 passed. - Read-only adversarial review (Opus): no behavior change found. Moved code compared against the base commit: identical apart from `this.x` rewiring. Same order of checks, counters, limits, events, texts and stored `extra` keys. One mutation queue. The import cycle between the new files and the service evaluates nothing at module top level. - Local CodeRabbit: 1 minor finding (type-only imports in `workspace-commands.ts`), fixed in `59855358d`. Not proven: - The review host has no `bwrap`, so the shell sandbox runtime path was not executed. `commandBash` is shown identical by text comparison only. - `round-review.regression.ts` does not cover the mid-run repair budget, the `staged` and `unverified` prompts, or `awaitingAuthorization`. The existing loop-level scripts still cover those paths. Known trade-offs: - The three new files import helpers back from `workspace-agent.service.ts` (import cycle, safe at load). About 30 helpers were exported from the service for them. - `executeWorkspaceCommand` is now public on the service so regression scripts can reach it. No runtime effect. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-24 04:07:22 +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#7773
No description provided.