[PR #1238] [CLOSED] feat(magic-rewrite): V1 — AI-assisted text rewriting for editors #4998

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

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/1238
Author: @kevin-ho
Created: 5/26/2026
Status: ❌ Closed

Base: staging ← Head: feat/magic-rewrite-v1


📝 Commits (3)

  • 19411f3 Fix mobile composer text input collapse (#1136)
  • 77a30fa Fix tracker aliases, avatars, HUD temps, and changelog (#1137)
  • 1a9b2dd feat(magic-rewrite): V1 — instruction + diff rewrite for editors

📊 Changes

15 files changed (+601 additions, -109 deletions)

View changed files

📝 CHANGELOG.md (+16 -0)
📝 packages/client/src/components/chat/ConversationInput.tsx (+5 -5)
📝 packages/client/src/components/chat/RoleplayHUD.tsx (+19 -37)
📝 packages/client/src/components/lorebooks/LorebookFormFields.tsx (+78 -24)
📝 packages/client/src/components/panels/SettingsPanel.tsx (+1 -1)
📝 packages/client/src/components/panels/settings/TrackerCardColorSettings.tsx (+17 -11)
📝 packages/client/src/components/ui/ExpandedTextarea.tsx (+84 -17)
➕ packages/client/src/components/ui/MagicRewritePanel.tsx (+148 -0)
📝 packages/client/src/features/tracker-panel/hooks/use-tracker-sprite-lookup.ts (+11 -6)
📝 packages/client/src/features/tracker-panel/lib/tracker-metadata.ts (+31 -0)
📝 packages/client/src/lib/character-display.ts (+40 -0)
📝 packages/server/src/routes/generate.routes.ts (+8 -4)
📝 packages/server/src/routes/generate/generate-route-utils.ts (+40 -4)
📝 packages/server/src/routes/index.ts (+2 -0)
➕ packages/server/src/routes/magic-rewrite.routes.ts (+101 -0)

📄 Description

Linked issue

Closes #1183

Why this change

Writing and maintaining long-form text entries — character descriptions, persona definitions, lorebook entries — is tedious. Other RP platforms offer AI-assisted rewriting with natural language instructions ("add more detail about their childhood," "convert to XML format," "make this more token-efficient"). Currently Marinara has no built-in mechanism for this. A third-party extension exists as a proof of concept but requires users to manually enter API keys. This PR ships the feature natively, reusing Marinara's existing connection infrastructure.

What changed

  • packages/server/src/routes/magic-rewrite.routes.ts (new): POST /api/magic-rewrite/generate — accepts text and instruction, resolves an LLM connection through the existing default → default agent fallback chain, returns rewritten text. No new DB columns, no migrations.
  • packages/client/src/components/ui/MagicRewritePanel.tsx (new): Instruction textarea, generate button, word-level LCS diff view (green additions, red deletions). Falls back to plain text for inputs over 3 000 words. Includes HelpTooltip noting agent connection usage.
  • packages/client/src/components/ui/ExpandedTextarea.tsx (modified): Rewrite button in fullscreen editor header, Apply/Back controls. Escape key suppressed during rewrite mode.
  • packages/client/src/components/lorebooks/LorebookFormFields.tsx (modified): Same rewrite integration in lorebook expanded content modal. Modal widened to max-w-5xl.
  • packages/server/src/routes/index.ts (modified): Registered magic-rewrite routes under /api/magic-rewrite.

Intentionally omitted (follow-up PRs)

Per maintainer feedback on #1184, V1 is scoped to the core rewrite flow:

  • Rewrite-specific default connection selection (defaultForRewrite flag)
  • DB migration / schema changes
  • Connection editor toggle UI
  • Character card / lorebook context injection
  • Chat history context selection

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

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)

Screenshot 2026-05-25 193644

🔄 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/1238 **Author:** [@kevin-ho](https://github.com/kevin-ho) **Created:** 5/26/2026 **Status:** ❌ Closed **Base:** `staging` ← **Head:** `feat/magic-rewrite-v1` --- ### 📝 Commits (3) - [`19411f3`](https://github.com/Pasta-Devs/Marinara-Engine/commit/19411f3675ea22a60b5803feecfd0e8b17a6ab06) Fix mobile composer text input collapse (#1136) - [`77a30fa`](https://github.com/Pasta-Devs/Marinara-Engine/commit/77a30fa4ee43b368f4ba4709b0161705e7c05881) Fix tracker aliases, avatars, HUD temps, and changelog (#1137) - [`1a9b2dd`](https://github.com/Pasta-Devs/Marinara-Engine/commit/1a9b2dd9cc80d637aa5cd408933d5ce3cf74e597) feat(magic-rewrite): V1 — instruction + diff rewrite for editors ### 📊 Changes **15 files changed** (+601 additions, -109 deletions) <details> <summary>View changed files</summary> 📝 `CHANGELOG.md` (+16 -0) 📝 `packages/client/src/components/chat/ConversationInput.tsx` (+5 -5) 📝 `packages/client/src/components/chat/RoleplayHUD.tsx` (+19 -37) 📝 `packages/client/src/components/lorebooks/LorebookFormFields.tsx` (+78 -24) 📝 `packages/client/src/components/panels/SettingsPanel.tsx` (+1 -1) 📝 `packages/client/src/components/panels/settings/TrackerCardColorSettings.tsx` (+17 -11) 📝 `packages/client/src/components/ui/ExpandedTextarea.tsx` (+84 -17) ➕ `packages/client/src/components/ui/MagicRewritePanel.tsx` (+148 -0) 📝 `packages/client/src/features/tracker-panel/hooks/use-tracker-sprite-lookup.ts` (+11 -6) 📝 `packages/client/src/features/tracker-panel/lib/tracker-metadata.ts` (+31 -0) 📝 `packages/client/src/lib/character-display.ts` (+40 -0) 📝 `packages/server/src/routes/generate.routes.ts` (+8 -4) 📝 `packages/server/src/routes/generate/generate-route-utils.ts` (+40 -4) 📝 `packages/server/src/routes/index.ts` (+2 -0) ➕ `packages/server/src/routes/magic-rewrite.routes.ts` (+101 -0) </details> ### 📄 Description <!-- Target branch: `staging`. The default base in this UI is `main` (release branch). --> <!-- Change the base to `staging` before submitting unless this is a maintainer-approved mainline change. --> <!-- See CONTRIBUTING.md § Branches. --> ## Linked issue <!-- Every PR should reference a feature request or issue report. If there isn't one yet, open one first to gather opinions: --> <!-- https://github.com/Pasta-Devs/Marinara-Engine/issues/new/choose --> Closes #1183 ## Why this change <!-- What user problem, bug, or goal does this solve? --> Writing and maintaining long-form text entries — character descriptions, persona definitions, lorebook entries — is tedious. Other RP platforms offer AI-assisted rewriting with natural language instructions ("add more detail about their childhood," "convert to XML format," "make this more token-efficient"). Currently Marinara has no built-in mechanism for this. A third-party extension exists as a proof of concept but requires users to manually enter API keys. This PR ships the feature natively, reusing Marinara's existing connection infrastructure. ## What changed <!-- List the key changes in this PR --> - **`packages/server/src/routes/magic-rewrite.routes.ts`** (new): `POST /api/magic-rewrite/generate` — accepts `text` and `instruction`, resolves an LLM connection through the existing default → default agent fallback chain, returns rewritten text. No new DB columns, no migrations. - **`packages/client/src/components/ui/MagicRewritePanel.tsx`** (new): Instruction textarea, generate button, word-level LCS diff view (green additions, red deletions). Falls back to plain text for inputs over 3 000 words. Includes `HelpTooltip` noting agent connection usage. - **`packages/client/src/components/ui/ExpandedTextarea.tsx`** (modified): Rewrite button in fullscreen editor header, Apply/Back controls. Escape key suppressed during rewrite mode. - **`packages/client/src/components/lorebooks/LorebookFormFields.tsx`** (modified): Same rewrite integration in lorebook expanded content modal. Modal widened to `max-w-5xl`. - **`packages/server/src/routes/index.ts`** (modified): Registered magic-rewrite routes under `/api/magic-rewrite`. ### Intentionally omitted (follow-up PRs) Per maintainer feedback on #1184, V1 is scoped to the core rewrite flow: - Rewrite-specific default connection selection (`defaultForRewrite` flag) - DB migration / schema changes - Connection editor toggle UI - Character card / lorebook context injection - Chat history context selection ## Validation <!-- Required: include commands run and/or manual checks performed --> - [x] `pnpm check` passes locally - [ ] 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) - [ ] Above manual verification completed (describe below) - [x] Read and followed `CONTRIBUTING.md` ### Manual verification notes <!-- Describe exactly what you tested in a real browser/app, step by step. --> <!-- ⚠️ If an AI agent filled out or ticked these boxes for you, treat them as a TO-DO LIST, not as proof the work is done. Verify each item yourself --> <!-- before submitting. If you haven't verified it, untick the box. --> - ## 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="2101" height="1331" alt="Screenshot 2026-05-25 193644" src="https://github.com/user-attachments/assets/395567c1-8651-47c7-b6f3-19274d5c0f4d" /> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-22 04:12:20 +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#4998
No description provided.