[PR #204] [MERGED] feat: add Card Evolution Auditor agent with user-approval modal #4504

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

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/204
Author: @cha1latte
Created: 4/23/2026
Status: ✅ Merged
Merged: 4/23/2026
Merged by: @SpicyMarinara

Base: main ← Head: feat/card-evolution-auditor


📝 Commits (3)

  • 2ed22ab feat: add Card Evolution Auditor agent with user-approval modal
  • 5271d2f Merge branch 'main' into feat/card-evolution-auditor
  • b91b390 fix: address Card Evolution Auditor review comments

📊 Changes

9 files changed (+586 additions, -6 deletions)

View changed files

📝 packages/client/src/components/layout/ModalRenderer.tsx (+6 -0)
➕ packages/client/src/components/modals/CharacterCardUpdateModal.tsx (+238 -0)
📝 packages/client/src/hooks/use-generate.ts (+164 -0)
📝 packages/client/src/stores/agent.store.ts (+31 -1)
📝 packages/server/src/routes/generate.routes.ts (+2 -0)
📝 packages/server/src/services/agents/agent-executor.ts (+39 -3)
📝 packages/shared/src/constants/agent-prompts.ts (+30 -0)
📝 packages/shared/src/schemas/agent.schema.ts (+1 -0)
📝 packages/shared/src/types/agent.ts (+75 -2)

📄 Description

Summary

Adds a new post-processing agent — Card Evolution Auditor — that watches the roleplay for durable changes to a character (dropped out of school, moved cities, changed hair, etc.) and proposes targeted edits to the character card's fields. Unlike the Lorebook Keeper, which writes back automatically, character card edits require the user's explicit approval via a confirmation modal showing the old → new diff per field.

This introduces a new character_card_update agent result type in the shared schemas and wires it through the full pipeline: server-side parsing and emission, a client-side pending-approval queue, a confirmation modal, and a surgical field-level apply path that preserves everything around the edited sentence.

card_evolution_auditor

Why

Character cards drift from what's actually true in long roleplays. A character graduates, quits their job, changes their appearance — but the card still describes them the old way, which then contaminates future generations. This agent closes that loop without risking silent card rewrites that the user didn't sign off on.

Architecture

Layer Change
packages/shared New character_card_update enum value, built-in agent registration, default prompt, CharacterCardUpdateResult + CharacterCardFieldUpdate types. AgentContext.characters widened to optionally carry richer card fields.
packages/server Agent executor maps card-evolution-auditor to the new result type and marks it JSON-output. buildAgentExtras emits a <character_cards> block with full fields only when this agent is in the batch — no token cost for other agents. No auto-apply: the server only emits the SSE event.
packages/client New pendingCardUpdates queue in agent.store. use-generate handles the SSE event, resolves the target character by matching oldText against each chat character's fields, and opens the modal. New CharacterCardUpdateModal with per-edit diff, stale detection, and field.replace(oldText, newText) apply logic.

Known limitations

  1. Conversation mode: ChatSettingsDrawer.tsx hides the "Enable Agents" section in Conversation mode, so this agent (like all agents) isn't reachable from Convo chats today. This predates this PR; not a regression. Backend already supports chatMode=conversation. Happy to follow up with a one-line change if you want the toggle exposed there.
  2. Target character resolution: the agent's JSON doesn't identify which character an edit applies to. The client heuristic matches oldText against each chat character's fields to pick the owner. Works cleanly for single-character chats and for multi-character chats where the edited text is unambiguous. A future prompt change to emit explicit characterName per edit would remove the heuristic — left out of this PR to keep scope tight.

Test plan

  • pnpm check passes (lint + production build across all packages).
  • Manual end-to-end test in Roleplay mode: enabled agent on a chat, sent a message establishing a permanent hair-color change, agent produced a valid updates array, modal appeared with correct character name and old→new diff, approval applied the edit surgically (surrounding description preserved), rejection dismissed without changes.
  • Verified buildAgentExtras emits <character_cards> only when card-evolution-auditor is in the agent batch — other agents' context is unchanged.
  • Stale detection: edits whose oldText no longer matches the current field value are flagged and excluded from the approve action.

Summary by CodeRabbit

  • New Features
    • AI-suggested character card edits are queued for user review instead of auto-applying.
    • New review modal previews before/after snippets, flags stale proposals, and lets you approve, reject, or process the queue progressively.
    • Approving applies targeted substring edits and advances the queue; rejecting skips entries.
    • An auditor agent can detect durable character evolutions and surface proposals for review.
    • Characters now surface additional creator notes and richer card fields for agent reasoning.

🔄 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/204 **Author:** [@cha1latte](https://github.com/cha1latte) **Created:** 4/23/2026 **Status:** ✅ Merged **Merged:** 4/23/2026 **Merged by:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Base:** `main` ← **Head:** `feat/card-evolution-auditor` --- ### 📝 Commits (3) - [`2ed22ab`](https://github.com/Pasta-Devs/Marinara-Engine/commit/2ed22ab7b9cfb6ca40cbdc8bdbc97a21c26742bc) feat: add Card Evolution Auditor agent with user-approval modal - [`5271d2f`](https://github.com/Pasta-Devs/Marinara-Engine/commit/5271d2ffcf877fe13f0029a3e770edc692bfb7c6) Merge branch 'main' into feat/card-evolution-auditor - [`b91b390`](https://github.com/Pasta-Devs/Marinara-Engine/commit/b91b390db70a89eda0c2820345b3b1210efc15bf) fix: address Card Evolution Auditor review comments ### 📊 Changes **9 files changed** (+586 additions, -6 deletions) <details> <summary>View changed files</summary> 📝 `packages/client/src/components/layout/ModalRenderer.tsx` (+6 -0) ➕ `packages/client/src/components/modals/CharacterCardUpdateModal.tsx` (+238 -0) 📝 `packages/client/src/hooks/use-generate.ts` (+164 -0) 📝 `packages/client/src/stores/agent.store.ts` (+31 -1) 📝 `packages/server/src/routes/generate.routes.ts` (+2 -0) 📝 `packages/server/src/services/agents/agent-executor.ts` (+39 -3) 📝 `packages/shared/src/constants/agent-prompts.ts` (+30 -0) 📝 `packages/shared/src/schemas/agent.schema.ts` (+1 -0) 📝 `packages/shared/src/types/agent.ts` (+75 -2) </details> ### 📄 Description ## Summary Adds a new post-processing agent — **Card Evolution Auditor** — that watches the roleplay for durable changes to a character (dropped out of school, moved cities, changed hair, etc.) and proposes targeted edits to the character card's fields. Unlike the Lorebook Keeper, which writes back automatically, character card edits require the user's explicit approval via a confirmation modal showing the old → new diff per field. This introduces a new `character_card_update` agent result type in the shared schemas and wires it through the full pipeline: server-side parsing and emission, a client-side pending-approval queue, a confirmation modal, and a surgical field-level apply path that preserves everything around the edited sentence. <img width="725" height="467" alt="card_evolution_auditor" src="https://github.com/user-attachments/assets/dd712908-c6a4-4e15-adc8-dedf72bc5093" /> ## Why Character cards drift from what's actually true in long roleplays. A character graduates, quits their job, changes their appearance — but the card still describes them the old way, which then contaminates future generations. This agent closes that loop without risking silent card rewrites that the user didn't sign off on. ## Architecture | Layer | Change | |---|---| | `packages/shared` | New `character_card_update` enum value, built-in agent registration, default prompt, `CharacterCardUpdateResult` + `CharacterCardFieldUpdate` types. `AgentContext.characters` widened to optionally carry richer card fields. | | `packages/server` | Agent executor maps `card-evolution-auditor` to the new result type and marks it JSON-output. `buildAgentExtras` emits a `<character_cards>` block with full fields **only when this agent is in the batch** — no token cost for other agents. No auto-apply: the server only emits the SSE event. | | `packages/client` | New `pendingCardUpdates` queue in `agent.store`. `use-generate` handles the SSE event, resolves the target character by matching `oldText` against each chat character's fields, and opens the modal. New `CharacterCardUpdateModal` with per-edit diff, stale detection, and `field.replace(oldText, newText)` apply logic. | ## Known limitations 1. **Conversation mode:** `ChatSettingsDrawer.tsx` hides the "Enable Agents" section in Conversation mode, so this agent (like all agents) isn't reachable from Convo chats today. This predates this PR; not a regression. Backend already supports `chatMode=conversation`. Happy to follow up with a one-line change if you want the toggle exposed there. 2. **Target character resolution:** the agent's JSON doesn't identify *which* character an edit applies to. The client heuristic matches `oldText` against each chat character's fields to pick the owner. Works cleanly for single-character chats and for multi-character chats where the edited text is unambiguous. A future prompt change to emit explicit `characterName` per edit would remove the heuristic — left out of this PR to keep scope tight. ## Test plan - [x] `pnpm check` passes (lint + production build across all packages). - [x] Manual end-to-end test in Roleplay mode: enabled agent on a chat, sent a message establishing a permanent hair-color change, agent produced a valid `updates` array, modal appeared with correct character name and old→new diff, approval applied the edit surgically (surrounding description preserved), rejection dismissed without changes. - [x] Verified `buildAgentExtras` emits `<character_cards>` only when `card-evolution-auditor` is in the agent batch — other agents' context is unchanged. - [x] Stale detection: edits whose `oldText` no longer matches the current field value are flagged and excluded from the approve action. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * AI-suggested character card edits are queued for user review instead of auto-applying. * New review modal previews before/after snippets, flags stale proposals, and lets you approve, reject, or process the queue progressively. * Approving applies targeted substring edits and advances the queue; rejecting skips entries. * An auditor agent can detect durable character evolutions and surface proposals for review. * Characters now surface additional creator notes and richer card fields for agent reasoning. <!-- 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:08:13 +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#4504
No description provided.