[PR #3160] [MERGED] feat: Agent Suite — view and edit stored agent data (manual + AI-assisted) #5823

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

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/3160
Author: @kolacheee
Created: 7/2/2026
Status: ✅ Merged
Merged: 7/3/2026
Merged by: @SpicyMarinara

Base: staging ← Head: feat/agent-suite


📝 Commits (7)

  • 41135e4 feat: add Agent Suite rewrite endpoint and shared schema
  • ef7631c feat: add Agent Suite modal for viewing and editing stored agent data
  • a88262b fix: harden Agent Suite against stale-state clobbers and draft loss
  • 7bf1c44 feat: add grounding-context picker to Agent Suite AI rewrites
  • 567903c fix: keep chat drawers open when interacting with toasts and app dialogs
  • 76ed010 Address Agent Suite review feedback
  • 56cbc2c Merge remote-tracking branch 'origin/staging' into feat/agent-suite

📊 Changes

12 files changed (+1524 additions, -89 deletions)

View changed files

📝 CHANGELOG.md (+4 -0)
📝 packages/client/src/App.tsx (+4 -0)
📝 packages/client/src/components/agents/SecretPlotPanel.tsx (+9 -12)
➕ packages/client/src/components/chat/AgentSuiteModal.tsx (+1141 -0)
📝 packages/client/src/components/chat/ChatSettingsDrawer.tsx (+71 -66)
📝 packages/client/src/components/ui/AppDialogRenderer.tsx (+10 -1)
📝 packages/client/src/features/chat-settings/sections/LorebooksSection.tsx (+1 -9)
📝 packages/client/src/hooks/use-agents.ts (+58 -1)
➕ packages/client/src/lib/chat-lorebooks.ts (+93 -0)
📝 packages/server/src/middleware/rate-limit.ts (+3 -0)
📝 packages/server/src/routes/agents.routes.ts (+105 -0)
📝 packages/shared/src/schemas/agent.schema.ts (+25 -0)

📄 Description

Linked issue

Closes #3165

Why this change

  • In earlier Marinara versions, agents and their prompts had fewer guards and were buggier. Legacy chats can carry agents with garbled stored data (memory, tracker state, outputs) that silently pollutes every prompt and degrades the experience.
  • Today that data is only editable in scattered places (Secret Plot panel, tracker HUD, Roleplay HUD popover) — and generic agent memory isn't editable anywhere.
  • The Agent Suite gives users one window to inspect and repair everything the agents in the active chat have stored — manually, or with a targeted AI rewrite (select text → give an instruction → pick a connection).

What changed

Shared (packages/shared)

  • New agentSuiteRewriteSchema + AgentSuiteRewriteInput in agent.schema.ts (connectionId, instruction, selected excerpt, optional document context, optional contextSections grounding blocks, size caps end-to-end).

Server (packages/server)

  • New POST /api/agents/suite/rewrite in agents.routes.ts: one-shot, non-streaming AI rewrite of a stored-data excerpt. Follows the POST /api/translate AI pattern exactly (getWithKey → baseUrl fallback → createLLMProvider → chatComplete, temperature 0.3, wrapping-code-fence strip, 400/502 error convention). System prompt instructs the model to return only the rewritten excerpt and to preserve JSON structure.
  • New rate-limit class for the endpoint (20/min) in middleware/rate-limit.ts so it doesn't sit in the 600/min default class.

Client (packages/client)

  • New AgentSuiteModal.tsx (ui/Modal, max-w-3xl, chatFloatingPanel): agent rail (dropdown on mobile) → per-agent editable data blocks:
    • Stored Memory (all agents) via existing GET/PATCH /agents/memory/:type/:chatId; director memory sits behind a spoiler gate like the Secret Plot panel; per-agent destructive "Clear memory" with confirm.
    • Tracker Data (world-state / character-tracker / persona-stats / custom-tracker / quest) via existing GET/PATCH /chats/:id/game-state — saves flush queued HUD patches, rebuild from a fresh snapshot, target the exact (messageId, swipeIndex), and re-sync the live HUD store.
    • Recent Outputs (custom agents) via existing run endpoints.
    • Every block: draft editing with explicit Save/Reset, dirty tracking, JSON validation, and AI Edit — select text in the editor (or none for the whole block), type an instruction, pick a connection (filterLanguageGenerationConnections), and the rewrite lands in the draft for review. Nothing is persisted without an explicit Save.
    • Add Context in the AI Edit panel: attach grounding sources — the chat's character cards (description/personality/scenario) and entries from its active lorebooks (pinned + global + chat-scoped + character/persona-linked, minus exclusions — mirroring the drawer's activation logic). Sources are wrapped server-side in delimited reference blocks the system prompt treats as grounding-only. Per-section 20k chars (visible truncation marker), 20 sources / 100k chars total, validated on both ends; the selection is shared across all AI edits in the window.
    • Dirty drafts guard close/Escape/agent-switch with a confirm dialog; blocks lock while a save or rewrite is in flight.
  • New hooks in use-agents.ts: useAgentMemory (404 → empty memory), useUpdateAgentMemory, useAgentSuiteRewrite; agentKeys.memory reuses the Secret Plot panel's key shape, and SecretPlotPanel now consumes the shared hook so the key has one queryFn.
  • Launcher row-button in the Agents section of ChatSettingsDrawer.tsx, styled like the existing "Edit Summaries" button.
  • Drawer outside-click fix: the sonner toaster wrapper (App.tsx) and the app-dialog Modal (AppDialogRenderer.tsx) are now tagged data-chat-floating-panel. Previously, dismissing a toast or clicking any confirm-dialog button counted as an outside click, closed the settings/gallery drawer, and unmounted the chat-local modal inside it (destroying unsaved drafts). Found while manually testing the Agent Suite; also fixes the same pre-existing interaction for the Secret Plot regenerate and Memory Recall delete-all confirms.

Docs

  • CHANGELOG.md: feature entry under [Unreleased].

The branch went through two multi-agent adversarial reviews (per-finding verification); 14 + 8 confirmed findings were fixed in follow-up commits (stale-snapshot clobber protection, in-flight edit locking, draft-loss guards, URL encoding, rate limiting, query-key coherence, chat.characterIds string-at-runtime parse, label caps, picker loading/error states, delimiter-safe prompt framing).

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

Checklist for manual verification in a real browser (boxes above reflect the human contributor's own run-through; container run still pending):

  • Open Chat Settings → Agents → Agent Suite in a chat with active agents; confirm the drawer stays open while clicking inside the modal.
  • Select each agent category: a tracker agent (edit + save its slice, confirm the tracker HUD updates), the Narrative Director (spoiler gate, memory edit round-trip), a custom agent (edit a recent output).
  • Run an AI Edit: select a chunk of text, give an instruction, pick a real connection, confirm the rewrite replaces only the selection in the draft and nothing persists until Save.
  • Use Add Context: confirm the picker lists the chat's character cards and active-lorebook entries (including character-linked/embedded lorebooks, not just pinned ones); attach a card + an entry, run a rewrite like "fill in these values" on the World State tracker, and confirm the output reflects the attached card and setting. Also check the loading state and the over-limit message with many large sources attached.
  • Try the guards: Escape with unsaved edits (confirm dialog), switching agents with unsaved edits, saving while agents are running (blocked with banner), Clear memory (confirm dialog). In the discard-confirm dialog, click "Keep Editing" and confirm the drawer + modal + drafts all survive.
  • Trigger a toast (e.g. run an AI rewrite) and dismiss it via its X: the Agent Suite and the drawer must stay open with drafts intact.
  • Empty states: chat with no active agents; agent with no stored memory; no tracker snapshot yet.
  • Light + dark mode, and mobile viewport (~400 px; agent rail becomes a dropdown).

Automated checks already run: pnpm lint (tsc strict + ESLint, all packages) passes; client production build passes (modal adds ~18 kB to the lazy drawer chunk only; main entry byte-identical). pnpm check's final build step fails on this dev machine due to a pre-existing Windows-only build-script bug (unquoted process.execPath, reproducible without this branch) — the server tsc step it wraps passes.

Docs and release impact

  • No docs changes needed
  • Updated docs (README / CONTRIBUTING / android/README / CHANGELOG) as needed
  • Version/release files updated (only if this PR includes a version bump)

UI evidence (if applicable)

{366646D2-AFCE-4F75-9DB2-9B46020EB42B} {E4B18B78-508A-4488-A4DB-5737DD41EF26} {2330495F-55ED-4E3A-8369-C7C72C17A0FC} {9CB76B48-9860-498B-BAF5-529D803D6C40} {090EA49A-6A7A-4B42-8504-BA6A647FEB8A}

Summary by CodeRabbit

  • New Features

    • Added an Agent Suite option in Chat Settings to view and edit stored agent data.
    • Support now includes editing agent memory, tracker state, and recent custom-agent output.
    • Added optional AI-assisted rewrite for selected text with supporting context from related chat data.
  • Bug Fixes

    • Improved dialog and toast interactions so closing toasts won’t accidentally dismiss chat drawers or modals.
  • Chores

    • Updated the changelog with the new Agent Suite feature.

🔄 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/3160 **Author:** [@kolacheee](https://github.com/kolacheee) **Created:** 7/2/2026 **Status:** ✅ Merged **Merged:** 7/3/2026 **Merged by:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Base:** `staging` ← **Head:** `feat/agent-suite` --- ### 📝 Commits (7) - [`41135e4`](https://github.com/Pasta-Devs/Marinara-Engine/commit/41135e487113a647d37fd1ad7221f4a90cdc15c1) feat: add Agent Suite rewrite endpoint and shared schema - [`ef7631c`](https://github.com/Pasta-Devs/Marinara-Engine/commit/ef7631ced002bf973ace361dc37bc8fa2dfda26a) feat: add Agent Suite modal for viewing and editing stored agent data - [`a88262b`](https://github.com/Pasta-Devs/Marinara-Engine/commit/a88262be7b35ac163170cdc8bb368fbb44987c58) fix: harden Agent Suite against stale-state clobbers and draft loss - [`7bf1c44`](https://github.com/Pasta-Devs/Marinara-Engine/commit/7bf1c44244510a0b6fc2d872c6842cf4d5afb327) feat: add grounding-context picker to Agent Suite AI rewrites - [`567903c`](https://github.com/Pasta-Devs/Marinara-Engine/commit/567903c2ed798c7ae6bc7c74cb3631416f0c376b) fix: keep chat drawers open when interacting with toasts and app dialogs - [`76ed010`](https://github.com/Pasta-Devs/Marinara-Engine/commit/76ed0102d432607a109c0b0fee0c68db21ed4563) Address Agent Suite review feedback - [`56cbc2c`](https://github.com/Pasta-Devs/Marinara-Engine/commit/56cbc2c4df5f38d177ebf167fc8f845b14c71750) Merge remote-tracking branch 'origin/staging' into feat/agent-suite ### 📊 Changes **12 files changed** (+1524 additions, -89 deletions) <details> <summary>View changed files</summary> 📝 `CHANGELOG.md` (+4 -0) 📝 `packages/client/src/App.tsx` (+4 -0) 📝 `packages/client/src/components/agents/SecretPlotPanel.tsx` (+9 -12) ➕ `packages/client/src/components/chat/AgentSuiteModal.tsx` (+1141 -0) 📝 `packages/client/src/components/chat/ChatSettingsDrawer.tsx` (+71 -66) 📝 `packages/client/src/components/ui/AppDialogRenderer.tsx` (+10 -1) 📝 `packages/client/src/features/chat-settings/sections/LorebooksSection.tsx` (+1 -9) 📝 `packages/client/src/hooks/use-agents.ts` (+58 -1) ➕ `packages/client/src/lib/chat-lorebooks.ts` (+93 -0) 📝 `packages/server/src/middleware/rate-limit.ts` (+3 -0) 📝 `packages/server/src/routes/agents.routes.ts` (+105 -0) 📝 `packages/shared/src/schemas/agent.schema.ts` (+25 -0) </details> ### 📄 Description ## Linked issue Closes #3165 ## Why this change - In earlier Marinara versions, agents and their prompts had fewer guards and were buggier. Legacy chats can carry agents with garbled stored data (memory, tracker state, outputs) that silently pollutes every prompt and degrades the experience. - Today that data is only editable in scattered places (Secret Plot panel, tracker HUD, Roleplay HUD popover) — and generic agent memory isn't editable anywhere. - The Agent Suite gives users one window to inspect and repair everything the agents in the active chat have stored — manually, or with a targeted AI rewrite (select text → give an instruction → pick a connection). ## What changed **Shared** (`packages/shared`) - New `agentSuiteRewriteSchema` + `AgentSuiteRewriteInput` in `agent.schema.ts` (connectionId, instruction, selected excerpt, optional document context, optional `contextSections` grounding blocks, size caps end-to-end). **Server** (`packages/server`) - New `POST /api/agents/suite/rewrite` in `agents.routes.ts`: one-shot, non-streaming AI rewrite of a stored-data excerpt. Follows the `POST /api/translate` AI pattern exactly (`getWithKey` → baseUrl fallback → `createLLMProvider` → `chatComplete`, temperature 0.3, wrapping-code-fence strip, 400/502 error convention). System prompt instructs the model to return only the rewritten excerpt and to preserve JSON structure. - New rate-limit class for the endpoint (20/min) in `middleware/rate-limit.ts` so it doesn't sit in the 600/min default class. **Client** (`packages/client`) - New `AgentSuiteModal.tsx` (`ui/Modal`, `max-w-3xl`, `chatFloatingPanel`): agent rail (dropdown on mobile) → per-agent editable data blocks: - **Stored Memory** (all agents) via existing `GET/PATCH /agents/memory/:type/:chatId`; director memory sits behind a spoiler gate like the Secret Plot panel; per-agent destructive "Clear memory" with confirm. - **Tracker Data** (world-state / character-tracker / persona-stats / custom-tracker / quest) via existing `GET/PATCH /chats/:id/game-state` — saves flush queued HUD patches, rebuild from a fresh snapshot, target the exact (messageId, swipeIndex), and re-sync the live HUD store. - **Recent Outputs** (custom agents) via existing run endpoints. - Every block: draft editing with explicit Save/Reset, dirty tracking, JSON validation, and **AI Edit** — select text in the editor (or none for the whole block), type an instruction, pick a connection (`filterLanguageGenerationConnections`), and the rewrite lands in the draft for review. Nothing is persisted without an explicit Save. - **Add Context** in the AI Edit panel: attach grounding sources — the chat's character cards (description/personality/scenario) and entries from its active lorebooks (pinned + global + chat-scoped + character/persona-linked, minus exclusions — mirroring the drawer's activation logic). Sources are wrapped server-side in delimited reference blocks the system prompt treats as grounding-only. Per-section 20k chars (visible truncation marker), 20 sources / 100k chars total, validated on both ends; the selection is shared across all AI edits in the window. - Dirty drafts guard close/Escape/agent-switch with a confirm dialog; blocks lock while a save or rewrite is in flight. - New hooks in `use-agents.ts`: `useAgentMemory` (404 → empty memory), `useUpdateAgentMemory`, `useAgentSuiteRewrite`; `agentKeys.memory` reuses the Secret Plot panel's key shape, and `SecretPlotPanel` now consumes the shared hook so the key has one queryFn. - Launcher row-button in the Agents section of `ChatSettingsDrawer.tsx`, styled like the existing "Edit Summaries" button. - Drawer outside-click fix: the sonner toaster wrapper (`App.tsx`) and the app-dialog `Modal` (`AppDialogRenderer.tsx`) are now tagged `data-chat-floating-panel`. Previously, dismissing a toast or clicking any confirm-dialog button counted as an outside click, closed the settings/gallery drawer, and unmounted the chat-local modal inside it (destroying unsaved drafts). Found while manually testing the Agent Suite; also fixes the same pre-existing interaction for the Secret Plot regenerate and Memory Recall delete-all confirms. **Docs** - `CHANGELOG.md`: feature entry under `[Unreleased]`. The branch went through two multi-agent adversarial reviews (per-finding verification); 14 + 8 confirmed findings were fixed in follow-up commits (stale-snapshot clobber protection, in-flight edit locking, draft-loss guards, URL encoding, rate limiting, query-key coherence, `chat.characterIds` string-at-runtime parse, label caps, picker loading/error states, delimiter-safe prompt framing). ## 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 Checklist for manual verification in a real browser (boxes above reflect the human contributor's own run-through; container run still pending): - Open Chat Settings → Agents → **Agent Suite** in a chat with active agents; confirm the drawer stays open while clicking inside the modal. - Select each agent category: a tracker agent (edit + save its slice, confirm the tracker HUD updates), the Narrative Director (spoiler gate, memory edit round-trip), a custom agent (edit a recent output). - Run an **AI Edit**: select a chunk of text, give an instruction, pick a real connection, confirm the rewrite replaces only the selection in the draft and nothing persists until Save. - Use **Add Context**: confirm the picker lists the chat's character cards and active-lorebook entries (including character-linked/embedded lorebooks, not just pinned ones); attach a card + an entry, run a rewrite like "fill in these values" on the World State tracker, and confirm the output reflects the attached card and setting. Also check the loading state and the over-limit message with many large sources attached. - Try the guards: Escape with unsaved edits (confirm dialog), switching agents with unsaved edits, saving while agents are running (blocked with banner), Clear memory (confirm dialog). In the discard-confirm dialog, click "Keep Editing" and confirm the drawer + modal + drafts all survive. - Trigger a toast (e.g. run an AI rewrite) and dismiss it via its X: the Agent Suite and the drawer must stay open with drafts intact. - Empty states: chat with no active agents; agent with no stored memory; no tracker snapshot yet. - Light + dark mode, and mobile viewport (~400 px; agent rail becomes a dropdown). Automated checks already run: `pnpm lint` (tsc strict + ESLint, all packages) passes; client production build passes (modal adds ~18 kB to the lazy drawer chunk only; main entry byte-identical). `pnpm check`'s final build step fails on this dev machine due to a pre-existing Windows-only build-script bug (unquoted `process.execPath`, reproducible without this branch) — the server `tsc` step it wraps passes. ## Docs and release impact - [x] No docs changes needed - [ ] Updated docs (README / CONTRIBUTING / android/README / CHANGELOG) as needed - [ ] Version/release files updated (only if this PR includes a version bump) ## UI evidence (if applicable) <img width="427" height="315" alt="{366646D2-AFCE-4F75-9DB2-9B46020EB42B}" src="https://github.com/user-attachments/assets/b091b125-1b45-4425-9414-e079ee9864fe" /> <img width="1280" height="595" alt="{E4B18B78-508A-4488-A4DB-5737DD41EF26}" src="https://github.com/user-attachments/assets/5c7e72db-81ae-46af-99f4-585f50734976" /> <img width="618" height="544" alt="{2330495F-55ED-4E3A-8369-C7C72C17A0FC}" src="https://github.com/user-attachments/assets/9652f20e-f3a2-4d0b-947a-a12f4308d21d" /> <img width="617" height="543" alt="{9CB76B48-9860-498B-BAF5-529D803D6C40}" src="https://github.com/user-attachments/assets/793a1d7d-a371-4dad-b1bb-2445061ea548" /> <img width="616" height="542" alt="{090EA49A-6A7A-4B42-8504-BA6A647FEB8A}" src="https://github.com/user-attachments/assets/39878284-2b57-4093-a2dd-e1c2a9bd07c4" /> <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Added an **Agent Suite** option in Chat Settings to view and edit stored agent data. * Support now includes editing agent memory, tracker state, and recent custom-agent output. * Added optional AI-assisted rewrite for selected text with supporting context from related chat data. * **Bug Fixes** * Improved dialog and toast interactions so closing toasts won’t accidentally dismiss chat drawers or modals. * **Chores** * Updated the changelog with the new Agent Suite feature. <!-- 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-22 04:19:52 +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#5823
No description provided.