[GH-ISSUE #2700] [Issue]: ST regex script import drops options (markdownOnly/substituteRegex/runOnEdit), remaps placements, force-defaults flags to gi #1346

Closed
opened 2026-10-21 05:31:54 +07:00 by bsakaguchi · 2 comments
Owner

Originally created by @kolacheee on GitHub (Jun 21, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/2700

Originally assigned to: @SpicyMarinara on GitHub.

Summary

Importing a SillyTavern character card's embedded regex scripts alters their behavior: ST options markdownOnly / substituteRegex / runOnEdit are silently dropped, placements other than user-input/AI-output are remapped to AI-output, and bare/no-flag patterns are force-defaulted to case-insensitive global (gi) — changing which text matches.

Expected behavior

An imported ST regex script should behave the same as in SillyTavern: same scope (display vs prompt), same placements, and the same matching flags as the source pattern.

Actual behavior

convertStRegexScripts (st-character.importer.ts:113-159):

  • Options dropped. It forces promptOnly: false (:148) and never reads ST's markdownOnly, substituteRegex, or runOnEdit. So a script ST runs on the prompt (or as a macro substitution, or on edit) is imported as a display-only, non-substituting, non-edit script — different scope/behavior.
  • Placements remapped. convertStPlacements (:96-105) only handles ST placement 1 (user input) and 2 (AI output); any other placement (slash commands, world info, reasoning) is dropped, and an empty result defaults to ["ai_output"] (:137). So scripts scoped to other placements are silently remapped to AI output.
  • Flags corrupted. Flags are derived as (delimited?.[2] || "gi").replace(/[^gimsuy]/g, "") then forced to include g (:129-130). A bare ST source (no /.../flags delimiters) is force-defaulted to case-insensitive global even if ST treated it case-sensitively — changing which text matches.

How it breaks the pipeline

Code trace (staging @ b826f8f4) — packages/server/src/services/import/st-character.importer.ts:

  • convertStRegexScripts :113-159; promptOnly: false :148; flags :129-130.
  • convertStPlacements :96-105; placement default :137.

Steps to reproduce

  • Import a card whose extensions.regex_scripts has a script with markdownOnly:false (a prompt-affecting script) → it imports as display-only.
  • Import a script with placement:[5] (or any non-1/2) → it imports as AI-output.
  • Import a script whose findRegex is a bare source (no slashes) intended case-sensitive → it imports as gi and matches case-insensitively.

Suggested fix

Map ST's full regex option set: read markdownOnly/substituteRegex/runOnEdit and ST's "Only Format Prompt" to set promptOnly/display vs prompt scope faithfully; map all ST placements (or at least preserve unknown ones rather than collapsing to AI-output); and derive flags only from the source — do not force i/g onto a bare source that didn't have them (default to the ST-equivalent flag set, not gi).

Environment

  • Marinara Engine version: 2.0.0 (staging @ b826f8f4)
  • Install type: source
  • OS + version: All (code-level defect, platform-independent)
  • Browser or app shell: All

Additional context

Found via a systematic multi-agent audit of import/export round-trips. Affects ST cards/users who rely on embedded regex scripts. Part of a set of import/export fidelity issues filed together.

Template check

Please uncheck (untick) the box below before submitting so we know you read the template. It is intentionally pre-checked:

  • I DID NOT read this template and provide the requested details.
Originally created by @kolacheee on GitHub (Jun 21, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/2700 Originally assigned to: @SpicyMarinara on GitHub. ## Summary Importing a SillyTavern character card's embedded regex scripts alters their behavior: ST options `markdownOnly` / `substituteRegex` / `runOnEdit` are silently dropped, placements other than user-input/AI-output are remapped to AI-output, and bare/no-flag patterns are force-defaulted to case-insensitive global (`gi`) — changing which text matches. ## Expected behavior An imported ST regex script should behave the same as in SillyTavern: same scope (display vs prompt), same placements, and the same matching flags as the source pattern. ## Actual behavior `convertStRegexScripts` (`st-character.importer.ts:113-159`): - **Options dropped.** It forces `promptOnly: false` (`:148`) and never reads ST's `markdownOnly`, `substituteRegex`, or `runOnEdit`. So a script ST runs on the prompt (or as a macro substitution, or on edit) is imported as a display-only, non-substituting, non-edit script — different scope/behavior. - **Placements remapped.** `convertStPlacements` (`:96-105`) only handles ST placement `1` (user input) and `2` (AI output); any other placement (slash commands, world info, reasoning) is dropped, and an empty result defaults to `["ai_output"]` (`:137`). So scripts scoped to other placements are silently remapped to AI output. - **Flags corrupted.** Flags are derived as `(delimited?.[2] || "gi").replace(/[^gimsuy]/g, "")` then forced to include `g` (`:129-130`). A bare ST source (no `/.../flags` delimiters) is force-defaulted to **case-insensitive global** even if ST treated it case-sensitively — changing which text matches. ## How it breaks the pipeline Code trace (staging @ `b826f8f4`) — `packages/server/src/services/import/st-character.importer.ts`: - `convertStRegexScripts` `:113-159`; `promptOnly: false` `:148`; flags `:129-130`. - `convertStPlacements` `:96-105`; placement default `:137`. ## Steps to reproduce - Import a card whose `extensions.regex_scripts` has a script with `markdownOnly:false` (a prompt-affecting script) → it imports as display-only. - Import a script with `placement:[5]` (or any non-1/2) → it imports as AI-output. - Import a script whose `findRegex` is a bare source (no slashes) intended case-sensitive → it imports as `gi` and matches case-insensitively. ## Suggested fix Map ST's full regex option set: read `markdownOnly`/`substituteRegex`/`runOnEdit` and ST's "Only Format Prompt" to set `promptOnly`/display vs prompt scope faithfully; map all ST placements (or at least preserve unknown ones rather than collapsing to AI-output); and derive flags only from the source — do not force `i`/`g` onto a bare source that didn't have them (default to the ST-equivalent flag set, not `gi`). ## Environment - Marinara Engine version: 2.0.0 (staging @ `b826f8f4`) - Install type: source - OS + version: All (code-level defect, platform-independent) - Browser or app shell: All ## Additional context Found via a systematic multi-agent audit of import/export round-trips. Affects ST cards/users who rely on embedded regex scripts. Part of a set of import/export fidelity issues filed together. ## Template check Please **uncheck (untick)** the box below before submitting so we know you read the template. It is intentionally pre-checked: - [ ] I DID NOT read this template and provide the requested details.
Author
Owner

@kolacheee commented on GitHub (Jun 21, 2026):

Veracity self-review — correction / clarification
Automated post-filing review of this issue against the current working tree. The reported bug remains valid; the notes below refine its scope, accuracy, or suggested fix for whoever implements it.

Clarification after reading the code (packages/server/src/services/import/st-character.importer.ts, packages/shared/src/types/regex.ts, packages/server/src/db/schema/regex-scripts.ts, packages/server/src/services/regex/regex-application.ts):

  1. ST semantics correction in the repro. markdownOnly:false does NOT mean "prompt-affecting." In SillyTavern the prompt-scope flag is promptOnly:true; markdownOnly:false + promptOnly:false means "alter the actual message" (affects display AND prompt, and persists). The genuine scope inversion here is: an ST script with promptOnly:true imports as display-only because line 148 hardcodes promptOnly: false. Please reword the first repro step to: "Import a script with promptOnly:true -> it imports as display-only (line 148 hardcodes promptOnly: false)."

  2. Model limitation (fixable scope vs out-of-scope). Marinara's regex model cannot represent several of these options: RegexPlacement is only "ai_output" | "user_input" (regex.ts:6 — no slash-command/world-info/reasoning), and neither the RegexScript type nor the Drizzle table (db/schema/regex-scripts.ts) has markdownOnly/substituteRegex/runOnEdit fields. Marinara also always macro-substitutes the find pattern (regex-application.ts:110 calls resolveScriptString on findRegex unconditionally), so substituteRegex is effectively always-ON, not "dropped." So the fixable-in-the-importer parts are: (a) set promptOnly from ST's promptOnly instead of hardcoding false; (b) stop collapsing unknown placements to ai_output (line 137) — skip the unrepresentable placement/script rather than silently remapping; (c) fix the flags (see #3). Mapping the remaining ST options (markdownOnly/substituteRegex/runOnEdit, and non-1/2 placements) requires extending the data model (type + zod + DB schema + apply logic) and should be split into a separate model-extension issue rather than implied as a simple "map all options" fix.

  3. Flags scope is broader than the repro states. The || "gi" fallback (line 129) fires for ANY pattern with empty flags, not just a bare (slash-less) source. A delimited ST pattern with no flags — /pattern/, the common ST form — also gets forced to gi (verified against the exact code: /Hello/ -> flags "gi"; /Hello/g -> "g"; Hello -> "gi"). In ST, /pattern/ means case-sensitive + first-match-only; importing it as gi flips BOTH case sensitivity and match count. This is the highest-impact, clearly-correct part of the fix: derive flags only from the source and do not force i or g. Note this will change current import output (ST scripts without g become first-match-only) — that is the intended correction, not a regression.

<!-- gh-comment-id:4761102328 --> @kolacheee commented on GitHub (Jun 21, 2026): > **Veracity self-review — correction / clarification** > _Automated post-filing review of this issue against the current working tree. The reported bug remains valid; the notes below refine its scope, accuracy, or suggested fix for whoever implements it._ Clarification after reading the code (packages/server/src/services/import/st-character.importer.ts, packages/shared/src/types/regex.ts, packages/server/src/db/schema/regex-scripts.ts, packages/server/src/services/regex/regex-application.ts): 1) ST semantics correction in the repro. `markdownOnly:false` does NOT mean "prompt-affecting." In SillyTavern the prompt-scope flag is `promptOnly:true`; `markdownOnly:false` + `promptOnly:false` means "alter the actual message" (affects display AND prompt, and persists). The genuine scope inversion here is: an ST script with `promptOnly:true` imports as display-only because line 148 hardcodes `promptOnly: false`. Please reword the first repro step to: "Import a script with `promptOnly:true` -> it imports as display-only (line 148 hardcodes `promptOnly: false`)." 2) Model limitation (fixable scope vs out-of-scope). Marinara's regex model cannot represent several of these options: `RegexPlacement` is only `"ai_output" | "user_input"` (regex.ts:6 — no slash-command/world-info/reasoning), and neither the `RegexScript` type nor the Drizzle table (db/schema/regex-scripts.ts) has `markdownOnly`/`substituteRegex`/`runOnEdit` fields. Marinara also always macro-substitutes the find pattern (regex-application.ts:110 calls `resolveScriptString` on `findRegex` unconditionally), so `substituteRegex` is effectively always-ON, not "dropped." So the fixable-in-the-importer parts are: (a) set `promptOnly` from ST's `promptOnly` instead of hardcoding `false`; (b) stop collapsing unknown placements to `ai_output` (line 137) — skip the unrepresentable placement/script rather than silently remapping; (c) fix the flags (see #3). Mapping the remaining ST options (markdownOnly/substituteRegex/runOnEdit, and non-1/2 placements) requires extending the data model (type + zod + DB schema + apply logic) and should be split into a separate model-extension issue rather than implied as a simple "map all options" fix. 3) Flags scope is broader than the repro states. The `|| "gi"` fallback (line 129) fires for ANY pattern with empty flags, not just a bare (slash-less) source. A delimited ST pattern with no flags — `/pattern/`, the common ST form — also gets forced to `gi` (verified against the exact code: `/Hello/` -> flags "gi"; `/Hello/g` -> "g"; `Hello` -> "gi"). In ST, `/pattern/` means case-sensitive + first-match-only; importing it as `gi` flips BOTH case sensitivity and match count. This is the highest-impact, clearly-correct part of the fix: derive flags only from the source and do not force `i` or `g`. Note this will change current import output (ST scripts without `g` become first-match-only) — that is the intended correction, not a regression.
Author
Owner

@SpicyMarinara commented on GitHub (Jun 21, 2026):

Addressed in branch codex/spicy-issue-sweep-2026-06-21.

What changed:

  • ST regex imports now set promptOnly from ST-style prompt-only fields instead of hardcoding display-only behavior.
  • Regex flags are derived only from the source pattern. /pattern/ and bare pattern now import with no flags instead of being forced to gi; /pattern/g stays g.
  • Placement arrays containing only unrepresentable ST placements are skipped instead of silently remapped to ai_output.
  • Mixed representable placements such as user-input/AI-output still import normally.

Skipped by design: markdownOnly, runOnEdit, and non-user/non-AI placements require extending Marinara's regex data model and apply logic; this importer fix avoids corrupting them into different behavior.

Final repo checks will run after the full issue sweep.

<!-- gh-comment-id:4761564007 --> @SpicyMarinara commented on GitHub (Jun 21, 2026): Addressed in branch `codex/spicy-issue-sweep-2026-06-21`. What changed: - ST regex imports now set `promptOnly` from ST-style prompt-only fields instead of hardcoding display-only behavior. - Regex flags are derived only from the source pattern. `/pattern/` and bare `pattern` now import with no flags instead of being forced to `gi`; `/pattern/g` stays `g`. - Placement arrays containing only unrepresentable ST placements are skipped instead of silently remapped to `ai_output`. - Mixed representable placements such as user-input/AI-output still import normally. Skipped by design: `markdownOnly`, `runOnEdit`, and non-user/non-AI placements require extending Marinara's regex data model and apply logic; this importer fix avoids corrupting them into different behavior. Final repo checks will run after the full issue sweep.
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#1346
No description provided.