[PR #1059] [CLOSED] feat: character-scoped regex scripts with ST card import #4908

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

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/1059
Author: @kolacheee
Created: 5/21/2026
Status: ❌ Closed

Base: staging ← Head: feature/character-scoped-regex


📝 Commits (3)

  • 671b8a0 feat: add character-scoped regex scripts with ST card import
  • 31f4bba feat: add per-character isolation, tri-state mode, and Chat Settings UI for scoped regex
  • 73f90f0 fix: include game party member IDs in scoped regex script fetch

📊 Changes

16 files changed (+628 additions, -45 deletions)

View changed files

📝 packages/client/src/components/characters/CharacterEditor.tsx (+117 -1)
📝 packages/client/src/components/chat/ChatInput.tsx (+16 -6)
📝 packages/client/src/components/chat/ChatMessage.tsx (+16 -2)
📝 packages/client/src/components/chat/ChatSettingsDrawer.tsx (+206 -4)
📝 packages/client/src/components/chat/ConversationInput.tsx (+21 -8)
📝 packages/client/src/components/game/GameNarration.tsx (+20 -2)
📝 packages/client/src/hooks/use-apply-regex.ts (+45 -15)
📝 packages/client/src/hooks/use-regex-scripts.ts (+5 -3)
📝 packages/server/src/db/schema/regex-scripts.ts (+2 -0)
📝 packages/server/src/routes/characters.routes.ts (+2 -0)
📝 packages/server/src/routes/import.routes.ts (+6 -0)
📝 packages/server/src/routes/regex-scripts.routes.ts (+6 -1)
📝 packages/server/src/services/import/st-character.importer.ts (+112 -1)
📝 packages/server/src/services/storage/regex-scripts.storage.ts (+51 -2)
📝 packages/shared/src/schemas/regex.schema.ts (+1 -0)
📝 packages/shared/src/types/regex.ts (+2 -0)

📄 Description

Summary

  • Adds a nullable characterId column to the regex scripts table, enabling scripts to be scoped to a specific character rather than applying globally
  • Automatically extracts and imports embedded regex scripts from SillyTavern character cards during import, converting ST format to ME format
  • Client hooks pass active chat character IDs so character-scoped scripts load alongside global scripts during chat
  • Per-character regex isolation with a tri-state mode selector (Disabled / Exclusive / Chat) persisted in chat metadata
  • Chat Settings UI with collapsible per-character script groups and individual on/off toggles
  • Character Editor gains a "Regex Scripts" tab for viewing imported scripts
  • Global Regex Scripts panel no longer shows character-scoped entries

Why

SillyTavern character cards embed regex_scripts in their extensions metadata — these scripts transform AI output to render custom UI elements like expression sprites, mood widgets, and structural HTML. Without importing these scripts, cards that rely on regex-driven theming (like the KZK card) render without their intended visual presentation.

In group chats, scoped scripts must be isolated per-character so one character's regexes don't transform another character's messages. The tri-state mode gives users control: Exclusive (default) keeps each character's scripts on their own messages, Disabled turns off scoped scripts entirely, and Chat applies all scoped scripts globally (useful for 1-on-1 chats where users want scoped scripts to also apply to their own persona).

Changes

Schema & types:

  • packages/server/src/db/schema/regex-scripts.ts — add character_id column
  • packages/shared/src/types/regex.ts — add characterId to RegexScript
  • packages/shared/src/schemas/regex.schema.ts — add characterId to create schema

Storage & API:

  • packages/server/src/services/storage/regex-scripts.storage.ts — add listForCharacters, listByCharacter, createBatch, removeByCharacter methods; list() filtered to global-only (characterId IS NULL)
  • packages/server/src/routes/regex-scripts.routes.ts — support ?characterIds= query param on list endpoint
  • packages/server/src/routes/characters.routes.ts — clean up character-scoped scripts on character deletion

Import:

  • packages/server/src/services/import/st-character.importer.ts — extract extensions.regex_scripts from ST cards, convert format (numeric placements → named, disabled → enabled, /pattern/flags → separate fields), batch-create as character-scoped scripts
  • packages/server/src/routes/import.routes.ts — add regex script fields to inspect preview responses

Client — per-character isolation:

  • packages/client/src/hooks/use-apply-regex.ts — tri-state ScopedRegexMode (disabled / exclusive / chat) with filterForMode() that gates which scripts run per message
  • packages/client/src/components/chat/ChatMessage.tsx — passes message.characterId and scopedRegexMode from chat metadata to applyToAIOutput
  • packages/client/src/components/game/GameNarration.tsx — maps messageId → characterId for source attribution, passes scopedMode and characterId per message
  • packages/client/src/components/chat/ChatInput.tsx — passes scopedMode to applyToUserInput
  • packages/client/src/components/chat/ConversationInput.tsx — passes scopedMode to applyToUserInput at all three call sites

Client — Chat Settings UI:

  • packages/client/src/components/chat/ChatSettingsDrawer.tsx — new "Scoped Regex Scripts" section with ScopedRegexModeSelector (tri-state button group with hover tooltips) and ScopedRegexCharacterGroups (collapsible per-character groups with enabled/total counts and individual On/Off toggles)

Client — Character Editor:

  • packages/client/src/components/characters/CharacterEditor.tsx — new "Regex Scripts" tab (after Lorebook) showing imported scripts with pattern, flags, replacement, placement badges, on/off toggle, and delete with confirmation

Test plan

  • Import a SillyTavern character card with embedded regex scripts — verify scripts appear in the regex editor with the character association
  • Verify imported scripts apply to AI output in chat with that character
  • Verify global regex scripts still work alongside character-scoped ones
  • Delete a character with scoped scripts — verify the scripts are cleaned up
  • Import a card without regex scripts — verify no errors, lorebook import unaffected
  • In a group chat, verify Exclusive mode only applies each character's scripts to their own messages
  • Verify Disabled mode turns off all scoped scripts (global scripts still apply)
  • Verify Chat mode applies all scoped scripts to every message including user input
  • Verify the mode selector persists across page reloads (stored in chat metadata)
  • In Chat Settings, expand a character group and toggle individual scripts on/off — verify changes take effect
  • In Character Editor, verify the Regex Scripts tab shows imported scripts with correct metadata
  • Verify the global Regex Scripts panel (sidebar) does not show character-scoped entries

🤖 Generated with Claude Code


🔄 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/1059 **Author:** [@kolacheee](https://github.com/kolacheee) **Created:** 5/21/2026 **Status:** ❌ Closed **Base:** `staging` ← **Head:** `feature/character-scoped-regex` --- ### 📝 Commits (3) - [`671b8a0`](https://github.com/Pasta-Devs/Marinara-Engine/commit/671b8a0d31dbc0f7e97344e6120397bccc873c65) feat: add character-scoped regex scripts with ST card import - [`31f4bba`](https://github.com/Pasta-Devs/Marinara-Engine/commit/31f4bbad2a2572368c762efa1fbdcab5b7a46e1f) feat: add per-character isolation, tri-state mode, and Chat Settings UI for scoped regex - [`73f90f0`](https://github.com/Pasta-Devs/Marinara-Engine/commit/73f90f05cd3a59fe0c1cf02654e60ff96196aeaf) fix: include game party member IDs in scoped regex script fetch ### 📊 Changes **16 files changed** (+628 additions, -45 deletions) <details> <summary>View changed files</summary> 📝 `packages/client/src/components/characters/CharacterEditor.tsx` (+117 -1) 📝 `packages/client/src/components/chat/ChatInput.tsx` (+16 -6) 📝 `packages/client/src/components/chat/ChatMessage.tsx` (+16 -2) 📝 `packages/client/src/components/chat/ChatSettingsDrawer.tsx` (+206 -4) 📝 `packages/client/src/components/chat/ConversationInput.tsx` (+21 -8) 📝 `packages/client/src/components/game/GameNarration.tsx` (+20 -2) 📝 `packages/client/src/hooks/use-apply-regex.ts` (+45 -15) 📝 `packages/client/src/hooks/use-regex-scripts.ts` (+5 -3) 📝 `packages/server/src/db/schema/regex-scripts.ts` (+2 -0) 📝 `packages/server/src/routes/characters.routes.ts` (+2 -0) 📝 `packages/server/src/routes/import.routes.ts` (+6 -0) 📝 `packages/server/src/routes/regex-scripts.routes.ts` (+6 -1) 📝 `packages/server/src/services/import/st-character.importer.ts` (+112 -1) 📝 `packages/server/src/services/storage/regex-scripts.storage.ts` (+51 -2) 📝 `packages/shared/src/schemas/regex.schema.ts` (+1 -0) 📝 `packages/shared/src/types/regex.ts` (+2 -0) </details> ### 📄 Description ## Summary - Adds a nullable `characterId` column to the regex scripts table, enabling scripts to be scoped to a specific character rather than applying globally - Automatically extracts and imports embedded regex scripts from SillyTavern character cards during import, converting ST format to ME format - Client hooks pass active chat character IDs so character-scoped scripts load alongside global scripts during chat - Per-character regex isolation with a tri-state mode selector (Disabled / Exclusive / Chat) persisted in chat metadata - Chat Settings UI with collapsible per-character script groups and individual on/off toggles - Character Editor gains a "Regex Scripts" tab for viewing imported scripts - Global Regex Scripts panel no longer shows character-scoped entries ## Why SillyTavern character cards embed `regex_scripts` in their extensions metadata — these scripts transform AI output to render custom UI elements like expression sprites, mood widgets, and structural HTML. Without importing these scripts, cards that rely on regex-driven theming (like the KZK card) render without their intended visual presentation. In group chats, scoped scripts must be isolated per-character so one character's regexes don't transform another character's messages. The tri-state mode gives users control: **Exclusive** (default) keeps each character's scripts on their own messages, **Disabled** turns off scoped scripts entirely, and **Chat** applies all scoped scripts globally (useful for 1-on-1 chats where users want scoped scripts to also apply to their own persona). ## Changes **Schema & types:** - `packages/server/src/db/schema/regex-scripts.ts` — add `character_id` column - `packages/shared/src/types/regex.ts` — add `characterId` to `RegexScript` - `packages/shared/src/schemas/regex.schema.ts` — add `characterId` to create schema **Storage & API:** - `packages/server/src/services/storage/regex-scripts.storage.ts` — add `listForCharacters`, `listByCharacter`, `createBatch`, `removeByCharacter` methods; `list()` filtered to global-only (`characterId IS NULL`) - `packages/server/src/routes/regex-scripts.routes.ts` — support `?characterIds=` query param on list endpoint - `packages/server/src/routes/characters.routes.ts` — clean up character-scoped scripts on character deletion **Import:** - `packages/server/src/services/import/st-character.importer.ts` — extract `extensions.regex_scripts` from ST cards, convert format (numeric placements → named, `disabled` → `enabled`, `/pattern/flags` → separate fields), batch-create as character-scoped scripts - `packages/server/src/routes/import.routes.ts` — add regex script fields to inspect preview responses **Client — per-character isolation:** - `packages/client/src/hooks/use-apply-regex.ts` — tri-state `ScopedRegexMode` (`disabled` / `exclusive` / `chat`) with `filterForMode()` that gates which scripts run per message - `packages/client/src/components/chat/ChatMessage.tsx` — passes `message.characterId` and `scopedRegexMode` from chat metadata to `applyToAIOutput` - `packages/client/src/components/game/GameNarration.tsx` — maps messageId → characterId for source attribution, passes `scopedMode` and `characterId` per message - `packages/client/src/components/chat/ChatInput.tsx` — passes `scopedMode` to `applyToUserInput` - `packages/client/src/components/chat/ConversationInput.tsx` — passes `scopedMode` to `applyToUserInput` at all three call sites **Client — Chat Settings UI:** - `packages/client/src/components/chat/ChatSettingsDrawer.tsx` — new "Scoped Regex Scripts" section with `ScopedRegexModeSelector` (tri-state button group with hover tooltips) and `ScopedRegexCharacterGroups` (collapsible per-character groups with enabled/total counts and individual On/Off toggles) **Client — Character Editor:** - `packages/client/src/components/characters/CharacterEditor.tsx` — new "Regex Scripts" tab (after Lorebook) showing imported scripts with pattern, flags, replacement, placement badges, on/off toggle, and delete with confirmation ## Test plan - [ ] Import a SillyTavern character card with embedded regex scripts — verify scripts appear in the regex editor with the character association - [ ] Verify imported scripts apply to AI output in chat with that character - [ ] Verify global regex scripts still work alongside character-scoped ones - [ ] Delete a character with scoped scripts — verify the scripts are cleaned up - [ ] Import a card without regex scripts — verify no errors, lorebook import unaffected - [ ] In a group chat, verify Exclusive mode only applies each character's scripts to their own messages - [ ] Verify Disabled mode turns off all scoped scripts (global scripts still apply) - [ ] Verify Chat mode applies all scoped scripts to every message including user input - [ ] Verify the mode selector persists across page reloads (stored in chat metadata) - [ ] In Chat Settings, expand a character group and toggle individual scripts on/off — verify changes take effect - [ ] In Character Editor, verify the Regex Scripts tab shows imported scripts with correct metadata - [ ] Verify the global Regex Scripts panel (sidebar) does not show character-scoped entries 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-22 04:11:38 +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#4908
No description provided.