[PR #231] [MERGED] fix(game): strip JSON-content tags fully in GM narration parser #4519

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

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/231
Author: @Romuromylus
Created: 4/25/2026
Status: ✅ Merged
Merged: 4/26/2026
Merged by: @LukaTheHero

Base: main ← Head: fix/gm-tag-parser-json-content


📝 Commits (3)

  • 62b6fd0 fix(game): strip JSON-content tags fully in GM narration parser
  • 26832b7 fix(game): make Note/Book preservation case-insensitive
  • 8a33968 Merge branch 'main' into fix/gm-tag-parser-json-content

📊 Changes

1 file changed (+65 additions, -8 deletions)

View changed files

📝 packages/client/src/lib/game-tag-parser.ts (+65 -8)

📄 Description

Why this change

In Game Mode, GM dialogue sometimes ends in a trailing }] for users on models that invent their own structured tags. The catch-all stripper in parseGmTags, stripGmTags, and stripGmTagsKeepReadables uses /\[\w+:[^\]]*\]/g, which matches up to the first ]. When the GM emits an unrecognized tag whose body contains a JSON array (e.g. [some_tag: {"x":[1,2]}]), the regex matches [some_tag: {"x":[1,2] (stopping at the inner ]) and leaves }] trailing in user-visible content.

What changed

  • Added stripUnknownBracketTags in packages/client/src/lib/game-tag-parser.ts: a quote-aware walker that tracks "/' strings (with \ escapes) and [/] depth, so JSON content inside a model-invented tag is removed along with its outer brackets.
  • Replaced the three /\[\w+:[^\]]*\]/g callsites — in parseGmTags, stripGmTags, and stripGmTagsKeepReadables — with stripUnknownBracketTags.
  • Optional keep predicate so stripGmTagsKeepReadables can skip [Note:] and [Book:] (preserving previous inline-readables behavior).
  • No changes to recognized-tag parsing and no public API changes — only the catch-all behavior is touched.

Validation

  • pnpm check (TypeScript + ESLint clean; client build succeeds)
  • Manual verification completed (describe below)

Manual verification notes

  • Deployed the patched build to a private instance and reproduced the original bug on the unpatched baseline (Game Mode, model that emits structured tags). After the patch, the trailing }] no longer appears.
  • Spot-checked recognized-tag parsing in Game Mode ([music:], [choices:], [combat:], [direction:], [widget:], [Note:], [Book:]) — all still parsed and stripped as before.
  • [Note:] / [Book:] content still rendered inline via stripGmTagsKeepReadables.

Docs and release impact

  • No docs changes needed

UI evidence (if applicable)

N/A — backend tag-parser fix, output is plain text rendered in the existing GM dialogue surface. The user-visible difference is the absence of trailing }] in narration.

Summary by CodeRabbit

  • Bug Fixes
    • Improved tag parsing reliability when tags contain nested brackets or quoted strings, ensuring complete tag removal in all cases.

🔄 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/231 **Author:** [@Romuromylus](https://github.com/Romuromylus) **Created:** 4/25/2026 **Status:** ✅ Merged **Merged:** 4/26/2026 **Merged by:** [@LukaTheHero](https://github.com/LukaTheHero) **Base:** `main` ← **Head:** `fix/gm-tag-parser-json-content` --- ### 📝 Commits (3) - [`62b6fd0`](https://github.com/Pasta-Devs/Marinara-Engine/commit/62b6fd07cfafb0557132a131063a48d20922232a) fix(game): strip JSON-content tags fully in GM narration parser - [`26832b7`](https://github.com/Pasta-Devs/Marinara-Engine/commit/26832b7e0267505a9d675a4cb15903cd7014591f) fix(game): make Note/Book preservation case-insensitive - [`8a33968`](https://github.com/Pasta-Devs/Marinara-Engine/commit/8a339682ecfd051b0bb0ff13811a633e68f7f082) Merge branch 'main' into fix/gm-tag-parser-json-content ### 📊 Changes **1 file changed** (+65 additions, -8 deletions) <details> <summary>View changed files</summary> 📝 `packages/client/src/lib/game-tag-parser.ts` (+65 -8) </details> ### 📄 Description ## Why this change In Game Mode, GM dialogue sometimes ends in a trailing `}]` for users on models that invent their own structured tags. The catch-all stripper in `parseGmTags`, `stripGmTags`, and `stripGmTagsKeepReadables` uses `/\[\w+:[^\]]*\]/g`, which matches up to the **first** `]`. When the GM emits an unrecognized tag whose body contains a JSON array (e.g. `[some_tag: {"x":[1,2]}]`), the regex matches `[some_tag: {"x":[1,2]` (stopping at the inner `]`) and leaves `}]` trailing in user-visible content. ## What changed - Added `stripUnknownBracketTags` in `packages/client/src/lib/game-tag-parser.ts`: a quote-aware walker that tracks `"`/`'` strings (with `\` escapes) and `[`/`]` depth, so JSON content inside a model-invented tag is removed along with its outer brackets. - Replaced the three `/\[\w+:[^\]]*\]/g` callsites — in `parseGmTags`, `stripGmTags`, and `stripGmTagsKeepReadables` — with `stripUnknownBracketTags`. - Optional `keep` predicate so `stripGmTagsKeepReadables` can skip `[Note:]` and `[Book:]` (preserving previous inline-readables behavior). - No changes to recognized-tag parsing and no public API changes — only the catch-all behavior is touched. ## Validation - [x] `pnpm check` (TypeScript + ESLint clean; client build succeeds) - [x] Manual verification completed (describe below) ### Manual verification notes - Deployed the patched build to a private instance and reproduced the original bug on the unpatched baseline (Game Mode, model that emits structured tags). After the patch, the trailing `}]` no longer appears. - Spot-checked recognized-tag parsing in Game Mode (`[music:]`, `[choices:]`, `[combat:]`, `[direction:]`, `[widget:]`, `[Note:]`, `[Book:]`) — all still parsed and stripped as before. - `[Note:]` / `[Book:]` content still rendered inline via `stripGmTagsKeepReadables`. ## Docs and release impact - [x] No docs changes needed ## UI evidence (if applicable) N/A — backend tag-parser fix, output is plain text rendered in the existing GM dialogue surface. The user-visible difference is the absence of trailing `}]` in narration. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Improved tag parsing reliability when tags contain nested brackets or quoted strings, ensuring complete tag removal in all cases. <!-- 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:08:21 +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#4519
No description provided.