[PR #2603] [MERGED] feat(regex): character-scoped regex scripts — tri-state mode (port from #1749) #5688

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

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/2603
Author: @kolacheee
Created: 6/17/2026
Status: ✅ Merged
Merged: 6/18/2026
Merged by: @SpicyMarinara

Base: staging ← Head: feat/staging-scoped-regex


📝 Commits (10+)

  • dedf986 feat(lorebooks): nested folders — server unblock + cycle guard
  • 8ca8af7 feat(lorebooks): nested folders — client tree UI + ancestor-aware disable
  • 600f730 feat(lorebooks): drag-to-nest folders — three-zone drag + root un-nest
  • 5dab11a feat(lorebooks): clone a folder — deep copy of sub-folders and entries
  • 916fa1d fix(lorebooks): drop entries into the innermost folder under the cursor
  • c7cb2b9 fix(lorebooks): arm folder drag synchronously so it reliably starts
  • 2688826 fix(lorebooks): nest a dragged folder when dropped into another folder's body
  • be3cdda fix(lorebooks): stop the un-nest strip from cancelling nested-folder drags
  • c039951 fix(lorebooks): un-nest a subfolder by dragging it down into its parent's body
  • b9377d4 fix(lorebooks): un-nest a folder dropped onto the root-entries area

📊 Changes

131 files changed (+10783 additions, -4199 deletions)

View changed files

📝 package.json (+1 -0)
📝 packages/client/src/components/agents/AgentEditor.tsx (+196 -117)
📝 packages/client/src/components/agents/RegexScriptEditor.tsx (+37 -32)
📝 packages/client/src/components/agents/SecretPlotPanel.tsx (+165 -361)
📝 packages/client/src/components/agents/ToolEditor.tsx (+27 -21)
📝 packages/client/src/components/characters/CharacterEditor.tsx (+28 -36)
📝 packages/client/src/components/characters/CharacterLibraryView.tsx (+7 -7)
➕ packages/client/src/components/chat/AgentAddSetupFields.tsx (+1492 -0)
📝 packages/client/src/components/chat/ChatArea.tsx (+89 -26)
📝 packages/client/src/components/chat/ChatGallery.tsx (+20 -4)
📝 packages/client/src/components/chat/ChatInput.tsx (+74 -41)
📝 packages/client/src/components/chat/ChatMessage.tsx (+79 -15)
📝 packages/client/src/components/chat/ChatRoleplaySurface.tsx (+69 -92)
📝 packages/client/src/components/chat/ChatSettingsDrawer.tsx (+1628 -862)
📝 packages/client/src/components/chat/ChatSetupWizard.tsx (+184 -88)
📝 packages/client/src/components/chat/ConversationInput.tsx (+28 -10)
📝 packages/client/src/components/chat/ConversationMessageShared.tsx (+36 -5)
📝 packages/client/src/components/chat/HomeAchievements.tsx (+21 -13)
📝 packages/client/src/components/chat/HomeProfessorMariChat.tsx (+9 -2)
📝 packages/client/src/components/chat/NewChatConnectionGate.tsx (+5 -8)

...and 80 more files

📄 Description

Linked issue

Closes #2581

Why this change

Regex scripts in staging already support per-script character targeting (targetCharacterIds), but only at prompt-assembly time — those scripts are forced "prompt-only," so they rewrite the prompt sent to the model and never touch what's shown in chat. At display time (the applyToAIOutput / applyToUserInput transforms that shape the visible text), scripts run globally, with no character scope and no per-chat control.

This ports the display-time character scoping from #1749, governed by a per-chat tri-state mode (Disabled / Exclusive / Chat — the same pattern as card theming). It reuses the existing targetCharacterIds as the scope (the array generalizes #1749's single characterId) rather than adding a parallel field, so there's one scope concept across prompt- and display-time.

What changed

Shared

  • types/chat.ts — added scopedRegexMode?: "disabled" | "exclusive" | "chat" to ChatMetadata (mirrors cardCssMode). Defaults to "disabled" — scoped scripts stay off at display unless opted in per chat.

Client

  • use-apply-regex.ts — applyToAIOutput / applyToUserInput accept scopedMode + the message's characterId. A character-scoped script (non-empty targetCharacterIds) now applies at display per the mode: disabled → off; exclusive → only on a target character's own messages; chat → every message. Global scripts (no targets) are unaffected; prompt-time targeting is unchanged.
  • ChatSettingsDrawer — a "Scoped Regex Scripts" tri-state control (Disabled / Exclusive / Chat), shown only when a character-scoped script exists; mirrors the Card Theming control.
  • Message call-sites — ChatMessage (AI output, passes the message's character), ChatInput (user input, 2 paths), ConversationInput (3 paths), and GameNarration (passes the segment's character via a message→character map) all read the chat's mode and pass it through.
  • RegexScriptEditor — character scope and "prompt-only" are now independent toggles, so a scoped script can transform displayed messages (gated by the mode) instead of being forced prompt-only.
  • Import dialogs — ImportCharacterModal + the bulk-import modal gained a "Character only / Global" radio (default Character only) for a bot's embedded regex scripts.
  • Scoped Regex Scripts tab — beneath the mode selector, each chat character's scoped scripts are listed with per-script on/off toggles and a count badge; the section appears only when a character in the chat actually has scoped scripts.

Server

  • st-character.importer.ts — on SillyTavern import, extracts the card's extensions.regex_scripts and creates each as a character-scoped script (targeting the imported character): parses /source/flags (or a bare source), maps numeric placements (1 → user input, 2 → AI output, default AI output), disabled → enabled, and carries trim strings + min/max depth. Patterns that are empty, ReDoS-prone (isPatternSafe), or won't compile are skipped (logged, non-fatal). Imported scripts are display-scoped, so they stay opt-in via the mode. Server-side, so every import path (file, charx, bot browser) is covered.
  • Import scope choice — importSTCharacter + the single/batch/bulk import routes thread a regexScriptScope (character | global, default character). Global drops the imported scripts into the Presets → REGEXES list (empty targetCharacterIds) instead of scoping them to the bot.

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

  • Shared build, server typecheck, and client typecheck + lint all pass.
  • Created a regex script, enable Specific Characters → pick character A, leave prompt-only off. In a 2-character chat, open Chat Settings → Scoped Regex Scripts:
    • Exclusive → the script transforms only A's messages, not the other character's or yours.
    • Chat → it transforms every message, including your input.
    • Disabled → it doesn't run, but a global (no-target) script still does.
  • Confirmed the Scoped Regex Scripts control only appears once a character-scoped script exists.
  • Imported a SillyTavern card that embeds regex_scripts with Character only → the scripts are scoped to that bot; with Global → they land in Presets → REGEXES and apply everywhere.
  • In a chat with a scoped bot, the Scoped Regex Scripts tab lists the bot's scripts with a count badge; toggling a script's dot enables/disables it.

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)

{2C144BEE-4D38-45BC-A47F-BD4DE94F2DAB} {FEFD4131-4FD7-495D-9451-36EE543D53D8}

Summary by CodeRabbit

  • New Features
    • Per-chat Scoped Regex Scripts in chat settings, including display-time scoped regex modes and per-character script toggles.
    • Regex script scope selection (character vs global) added to character and bulk import.
    • PDF attachments supported in chat/conversation inputs, previews, and provider requests.
    • New agent write approval flow via a confirmation modal for required updates.
  • Improvements
    • Regex script Prompt Only and character-scoping behavior are now independent on save/export.
    • Macro resolution and AI regex/script application now respect the chat’s scoped regex configuration.

🔄 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/2603 **Author:** [@kolacheee](https://github.com/kolacheee) **Created:** 6/17/2026 **Status:** ✅ Merged **Merged:** 6/18/2026 **Merged by:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Base:** `staging` ← **Head:** `feat/staging-scoped-regex` --- ### 📝 Commits (10+) - [`dedf986`](https://github.com/Pasta-Devs/Marinara-Engine/commit/dedf9868ef6b2e6b12e1431dd2922de6ded0a534) feat(lorebooks): nested folders — server unblock + cycle guard - [`8ca8af7`](https://github.com/Pasta-Devs/Marinara-Engine/commit/8ca8af717ab8b817e57e3b522bb69b043ce5caf3) feat(lorebooks): nested folders — client tree UI + ancestor-aware disable - [`600f730`](https://github.com/Pasta-Devs/Marinara-Engine/commit/600f7309926837cc085bf2f216931bc6ba36fbf8) feat(lorebooks): drag-to-nest folders — three-zone drag + root un-nest - [`5dab11a`](https://github.com/Pasta-Devs/Marinara-Engine/commit/5dab11a4a8a7ff3b880b0a385de3f6038d9c5d17) feat(lorebooks): clone a folder — deep copy of sub-folders and entries - [`916fa1d`](https://github.com/Pasta-Devs/Marinara-Engine/commit/916fa1dedc1963933df075d9a7743c7aac2799d8) fix(lorebooks): drop entries into the innermost folder under the cursor - [`c7cb2b9`](https://github.com/Pasta-Devs/Marinara-Engine/commit/c7cb2b92452662df96999ff59cd1a1a253f4ffdf) fix(lorebooks): arm folder drag synchronously so it reliably starts - [`2688826`](https://github.com/Pasta-Devs/Marinara-Engine/commit/26888263b1d2b12cb84b9ba519733c1e2a8b03d9) fix(lorebooks): nest a dragged folder when dropped into another folder's body - [`be3cdda`](https://github.com/Pasta-Devs/Marinara-Engine/commit/be3cdda08ff57477535eb86dc53dea5d23d7f68f) fix(lorebooks): stop the un-nest strip from cancelling nested-folder drags - [`c039951`](https://github.com/Pasta-Devs/Marinara-Engine/commit/c039951d17fd607c93b69ab0add8e9cda1ba7f45) fix(lorebooks): un-nest a subfolder by dragging it down into its parent's body - [`b9377d4`](https://github.com/Pasta-Devs/Marinara-Engine/commit/b9377d44f916ebde293594f06258c3caa95a26ea) fix(lorebooks): un-nest a folder dropped onto the root-entries area ### 📊 Changes **131 files changed** (+10783 additions, -4199 deletions) <details> <summary>View changed files</summary> 📝 `package.json` (+1 -0) 📝 `packages/client/src/components/agents/AgentEditor.tsx` (+196 -117) 📝 `packages/client/src/components/agents/RegexScriptEditor.tsx` (+37 -32) 📝 `packages/client/src/components/agents/SecretPlotPanel.tsx` (+165 -361) 📝 `packages/client/src/components/agents/ToolEditor.tsx` (+27 -21) 📝 `packages/client/src/components/characters/CharacterEditor.tsx` (+28 -36) 📝 `packages/client/src/components/characters/CharacterLibraryView.tsx` (+7 -7) ➕ `packages/client/src/components/chat/AgentAddSetupFields.tsx` (+1492 -0) 📝 `packages/client/src/components/chat/ChatArea.tsx` (+89 -26) 📝 `packages/client/src/components/chat/ChatGallery.tsx` (+20 -4) 📝 `packages/client/src/components/chat/ChatInput.tsx` (+74 -41) 📝 `packages/client/src/components/chat/ChatMessage.tsx` (+79 -15) 📝 `packages/client/src/components/chat/ChatRoleplaySurface.tsx` (+69 -92) 📝 `packages/client/src/components/chat/ChatSettingsDrawer.tsx` (+1628 -862) 📝 `packages/client/src/components/chat/ChatSetupWizard.tsx` (+184 -88) 📝 `packages/client/src/components/chat/ConversationInput.tsx` (+28 -10) 📝 `packages/client/src/components/chat/ConversationMessageShared.tsx` (+36 -5) 📝 `packages/client/src/components/chat/HomeAchievements.tsx` (+21 -13) 📝 `packages/client/src/components/chat/HomeProfessorMariChat.tsx` (+9 -2) 📝 `packages/client/src/components/chat/NewChatConnectionGate.tsx` (+5 -8) _...and 80 more files_ </details> ### 📄 Description ## Linked issue Closes #2581 ## Why this change Regex scripts in `staging` already support per-script character targeting (`targetCharacterIds`), but only at **prompt-assembly time** — those scripts are forced "prompt-only," so they rewrite the prompt sent to the model and never touch what's shown in chat. At **display time** (the `applyToAIOutput` / `applyToUserInput` transforms that shape the visible text), scripts run **globally**, with no character scope and no per-chat control. This ports the display-time character scoping from #1749, governed by a per-chat **tri-state mode** (Disabled / Exclusive / Chat — the same pattern as card theming). It **reuses the existing `targetCharacterIds`** as the scope (the array generalizes #1749's single `characterId`) rather than adding a parallel field, so there's one scope concept across prompt- and display-time. ## What changed **Shared** - `types/chat.ts` — added `scopedRegexMode?: "disabled" | "exclusive" | "chat"` to `ChatMetadata` (mirrors `cardCssMode`). Defaults to `"disabled"` — scoped scripts stay off at display unless opted in per chat. **Client** - `use-apply-regex.ts` — `applyToAIOutput` / `applyToUserInput` accept `scopedMode` + the message's `characterId`. A character-scoped script (non-empty `targetCharacterIds`) now applies at display per the mode: `disabled` → off; `exclusive` → only on a target character's own messages; `chat` → every message. Global scripts (no targets) are unaffected; prompt-time targeting is unchanged. - **ChatSettingsDrawer** — a "Scoped Regex Scripts" tri-state control (Disabled / Exclusive / Chat), shown only when a character-scoped script exists; mirrors the Card Theming control. - **Message call-sites** — ChatMessage (AI output, passes the message's character), ChatInput (user input, 2 paths), ConversationInput (3 paths), and GameNarration (passes the segment's character via a message→character map) all read the chat's mode and pass it through. - **RegexScriptEditor** — character scope and "prompt-only" are now independent toggles, so a scoped script can transform displayed messages (gated by the mode) instead of being forced prompt-only. - **Import dialogs** — ImportCharacterModal + the bulk-import modal gained a "Character only / Global" radio (default Character only) for a bot's embedded regex scripts. - **Scoped Regex Scripts tab** — beneath the mode selector, each chat character's scoped scripts are listed with per-script on/off toggles and a count badge; the section appears only when a character in the chat actually has scoped scripts. **Server** - `st-character.importer.ts` — on SillyTavern import, extracts the card's `extensions.regex_scripts` and creates each as a character-scoped script (targeting the imported character): parses `/source/flags` (or a bare source), maps numeric placements (1 → user input, 2 → AI output, default AI output), `disabled` → `enabled`, and carries trim strings + min/max depth. Patterns that are empty, ReDoS-prone (`isPatternSafe`), or won't compile are skipped (logged, non-fatal). Imported scripts are display-scoped, so they stay opt-in via the mode. Server-side, so every import path (file, charx, bot browser) is covered. - **Import scope choice** — `importSTCharacter` + the single/batch/bulk import routes thread a `regexScriptScope` (`character` | `global`, default `character`). Global drops the imported scripts into the Presets → REGEXES list (empty `targetCharacterIds`) instead of scoping them to the bot. ## 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 - Shared build, server typecheck, and client typecheck + lint all pass. - Created a regex script, enable **Specific Characters** → pick character A, leave **prompt-only off**. In a 2-character chat, open Chat Settings → **Scoped Regex Scripts**: - **Exclusive** → the script transforms only A's messages, not the other character's or yours. - **Chat** → it transforms every message, including your input. - **Disabled** → it doesn't run, but a global (no-target) script still does. - Confirmed the **Scoped Regex Scripts** control only appears once a character-scoped script exists. - Imported a SillyTavern card that embeds `regex_scripts` with **Character only** → the scripts are scoped to that bot; with **Global** → they land in Presets → REGEXES and apply everywhere. - In a chat with a scoped bot, the **Scoped Regex Scripts** tab lists the bot's scripts with a count badge; toggling a script's dot enables/disables it. ## 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="1008" height="559" alt="{2C144BEE-4D38-45BC-A47F-BD4DE94F2DAB}" src="https://github.com/user-attachments/assets/61a990cd-8381-41aa-90a8-9071f4d3e392" /> <img width="384" height="543" alt="{FEFD4131-4FD7-495D-9451-36EE543D53D8}" src="https://github.com/user-attachments/assets/8df5d238-3c5a-41cd-8eb8-3ca3d4c256ad" /> <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Per-chat **Scoped Regex Scripts** in chat settings, including display-time scoped regex modes and per-character script toggles. * **Regex script scope** selection (character vs global) added to character and bulk import. * **PDF attachments** supported in chat/conversation inputs, previews, and provider requests. * New **agent write approval** flow via a confirmation modal for required updates. * **Improvements** * Regex script **Prompt Only** and character-scoping behavior are now independent on save/export. * Macro resolution and AI regex/script application now respect the chat’s scoped regex configuration. <!-- 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:18:32 +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#5688
No description provided.