[GH-ISSUE #1127] [Tech debt]: Unify speaker-tag parsing across ChatMessage and ConversationMessage #558

Closed
opened 2026-10-20 17:30:11 +07:00 by bsakaguchi · 2 comments
Owner

Originally created by @aeriondyseti on GitHub (May 24, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/1127

Originally assigned to: @cha1latte on GitHub.

The situation

The client has three independent implementations of <speaker="Name">…</speaker> handling right now:

  1. packages/client/src/components/chat/ChatMessage.tsx plain-text branch — renderWithSpeakerTags (around line 258)
  2. packages/client/src/components/chat/ChatMessage.tsx HTML branch — inline String.replace (around line 572)
  3. packages/client/src/components/chat/ConversationMessage.tsx — parseSpeakerTags (around line 193)

Each uses a slightly different regex and a slightly different fallback for unknown speakers or missing colour maps. A bug fix in one path doesn't automatically reach the others — #1125 fixed (1), but (2) and (3) had to be audited by hand for parity. That's the kind of footgun that grows over time.

What I'd suggest

Extract a shared parser that returns a structured representation, and have each surface render that structure with its own styling rules:

type SpeakerSegment =
  | { kind: "narration"; text: string }
  | { kind: "speaker"; name: string; text: string };

function parseSpeakerTags(text: string): SpeakerSegment[];

Three call sites, one parser. The regex-per-surface coupling goes away.

Why now

The fix for #1125 surfaced a textbook SRP violation: renderWithSpeakerTags had two responsibilities (stripping tags + colouring per speaker) entangled in a single early-return condition — and that entanglement was the bug. Splitting parse → render at the architecture level prevents the same class of bug from recurring in the sibling implementations.

Done when

  • One shared parser used by all three surfaces.
  • Visible behaviour unchanged from current (post-#1125) state.
  • Manual verification across group/solo chat in both roleplay and conversation surfaces.

Out of scope

Bare-tag handling — see #1126. A unified parser would probably fix that as a side-effect, but the regex-alignment decision should be made deliberately, not snuck in.


Surfaced during code review of #1125.

Originally created by @aeriondyseti on GitHub (May 24, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/1127 Originally assigned to: @cha1latte on GitHub. ## The situation The client has three independent implementations of `<speaker="Name">…</speaker>` handling right now: 1. `packages/client/src/components/chat/ChatMessage.tsx` plain-text branch — `renderWithSpeakerTags` (around line 258) 2. `packages/client/src/components/chat/ChatMessage.tsx` HTML branch — inline `String.replace` (around line 572) 3. `packages/client/src/components/chat/ConversationMessage.tsx` — `parseSpeakerTags` (around line 193) Each uses a slightly different regex and a slightly different fallback for unknown speakers or missing colour maps. A bug fix in one path doesn't automatically reach the others — #1125 fixed (1), but (2) and (3) had to be audited by hand for parity. That's the kind of footgun that grows over time. ## What I'd suggest Extract a shared parser that returns a structured representation, and have each surface render that structure with its own styling rules: ```ts type SpeakerSegment = | { kind: "narration"; text: string } | { kind: "speaker"; name: string; text: string }; function parseSpeakerTags(text: string): SpeakerSegment[]; ``` Three call sites, one parser. The regex-per-surface coupling goes away. ## Why now The fix for #1125 surfaced a textbook SRP violation: `renderWithSpeakerTags` had two responsibilities (stripping tags + colouring per speaker) entangled in a single early-return condition — and that entanglement was the bug. Splitting parse → render at the architecture level prevents the same class of bug from recurring in the sibling implementations. ## Done when - One shared parser used by all three surfaces. - Visible behaviour unchanged from current (post-#1125) state. - Manual verification across group/solo chat in both roleplay and conversation surfaces. ## Out of scope Bare-tag handling — see #1126. A unified parser would probably fix that as a side-effect, but the regex-alignment decision should be made deliberately, not snuck in. --- Surfaced during code review of #1125.
Author
Owner

@cha1latte commented on GitHub (May 25, 2026):

Triage note: labeling this as normal-scope because the issue is a focused client tech-debt cleanup: one shared speaker-tag parser used by existing chat surfaces with visible behavior preserved.

The least risky next step is to keep the change limited to parser extraction and parity verification across the current render paths.

<!-- gh-comment-id:4536671450 --> @cha1latte commented on GitHub (May 25, 2026): Triage note: labeling this as `normal-scope` because the issue is a focused client tech-debt cleanup: one shared speaker-tag parser used by existing chat surfaces with visible behavior preserved. The least risky next step is to keep the change limited to parser extraction and parity verification across the current render paths.
Author
Owner

@cha1latte commented on GitHub (May 25, 2026):

Merged in #1128

<!-- gh-comment-id:4537151109 --> @cha1latte commented on GitHub (May 25, 2026): Merged in #1128
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#558
No description provided.