Skip to content

fix(regex): let a script tick both display-only and prompt-only - #388

Merged
hydall merged 1 commit into
nightlyfrom
claude/regex-nbsp-replacement-4patuc
Sep 5, 2026
Merged

fix(regex): let a script tick both display-only and prompt-only#388
hydall merged 1 commit into
nightlyfrom
claude/regex-nbsp-replacement-4patuc

Conversation

@hydall

@hydall hydall commented Sep 5, 2026

Copy link
Copy Markdown
Owner

SillyTavern treats "Only Format Display" (markdownOnly) and "Only Format Prompt" (promptOnly) as two independent opt-ins and ORs them — getRegexedString in public/scripts/extensions/regex/engine.js:

(script.markdownOnly && isMarkdown) ||
(script.promptOnly && isPrompt) ||
(!script.markdownOnly && !script.promptOnly && !isMarkdown && !isPrompt)

Glaze required both at once (&&-of-negatives), and no caller ever passes isMarkdown and isPrompt together — ChatMessageMapper.toMap passes only isMarkdown: true, applyPromptRegexes only isPrompt: true. A script with both flags was therefore dead in every pass. An imported pair such as "Use Figure Spaces" / "Return Normal Spaces" swapped spaces for U+2007 in the outgoing prompt but never swapped them back for display.

Changes

  • applyRegexes (lib/core/llm/regex_service.dart) now runs a script when either opt-in matches the current pass, mirroring ST. The storage pass (run-on-edit, neither flag set) still skips both kinds, so a display rewrite is never baked into the stored message.
  • displayRegexesProvider (lib/core/state/active_regex_provider.dart) stops dropping a promptOnly script that also ticks markdownOnly — that second gate kept such a script out of the display list even with the engine fixed.

Verification

  • Added test/regex_service_test.dart cases: a markdownOnly + promptOnly script fires in the display pass and in the prompt pass but not in the storage pass, and the promptOnly half of the pair rewrites spaces only in the prompt.
  • Flag semantics checked against the SillyTavern sources (engine.js getRegexedString, plus the isMarkdown: true / isPrompt: true call sites in public/script.js).
  • flutter analyze and flutter test were not run — no Flutter SDK in the agent environment; relying on CI for both.

🤖 Generated with Claude Code

https://claude.ai/code/session_01PeAHpjepbusNwo4X5DQDsp


Generated by Claude Code

SillyTavern treats "Only Format Display" (markdownOnly) and "Only Format
Prompt" (promptOnly) as two independent opt-ins and ORs them; Glaze
required both at once, so a script with both flags never ran — no caller
passes isMarkdown and isPrompt together. An imported pair such as "Use
Figure Spaces" / "Return Normal Spaces" therefore swapped spaces for
U+2007 in the prompt but never swapped them back for display.

- applyRegexes now runs a script when either opt-in matches the current
  pass, while the storage (run-on-edit) pass still skips both kinds so a
  display rewrite is never baked into the stored message
- displayRegexesProvider stops dropping a promptOnly script that also
  ticks markdownOnly
- tests cover both passes plus the storage pass for the both-flags case
  and the prompt-only half of the pair

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PeAHpjepbusNwo4X5DQDsp
@hydall
hydall merged commit f0080ff into nightly Sep 5, 2026
3 checks passed
@hydall
hydall deleted the claude/regex-nbsp-replacement-4patuc branch September 6, 2026 16:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants