fix(tui): markdown — guard intraword underscores + clean protocol sentinels#13204
Merged
Conversation
The inline markdown regex matched `_..._` / `__...__` anywhere, so file paths like `browser_screenshot_ecc1c3feab.png` got mid-path italics. Require non-word flanking (`(?<!\w)` / `(?!\w)`) on underscore emphasis so snake_case identifiers and paths render literally, matching the CommonMark intraword rule. `*` / `**` keep intraword semantics.
The agent emits `MEDIA:<path>` to signal file delivery to the gateway, and `[[audio_as_voice]]` as a voice-delivery hint. The gateway strips both before sending to Telegram/Discord/Slack, but the TUI was rendering them raw through markdown — which is also how the intraword underscore bug originally surfaced (`browser_screenshot_ecc…`). At the `Md` layer, detect both sentinels on their own line: - `MEDIA:<path>` → `▸ <path>` with the path rendered literal and wrapped in a `Link` for OSC 8 hyperlink support (absolute paths get a `file://` URL, so modern terminals make them click-to-open). - `[[audio_as_voice]]` → dropped silently; it has no meaning in TUI. Covers tests for quoted/backticked MEDIA variants, Windows drive paths, whitespace, and the inline-in-prose case (left untouched — still protected by the intraword-underscore guard).
✅ Review Complete - LGTMTested - all 9 markdown rendering tests passing Test Results
Detailed AnalysisIntraword underscore fix ✅
Test coverage ✅
RecommendationMerge immediately. This fix:
No additional changes needed. Ready for merge. Reviewer: @teknium1 |
3 tasks
ulasbilgen
pushed a commit
to ulasbilgen/hermes-adhd-agent
that referenced
this pull request
May 1, 2026
…wn-intraword-underscore fix(tui): markdown — guard intraword underscores + clean protocol sentinels
aj-nt
pushed a commit
to aj-nt/hermes-agent
that referenced
this pull request
May 1, 2026
…wn-intraword-underscore fix(tui): markdown — guard intraword underscores + clean protocol sentinels
Luminet2023
pushed a commit
to Luminet2023/hermes-agent
that referenced
this pull request
May 1, 2026
…wn-intraword-underscore fix(tui): markdown — guard intraword underscores + clean protocol sentinels
02356abc
pushed a commit
to 02356abc/hermes-agent
that referenced
this pull request
May 14, 2026
…wn-intraword-underscore fix(tui): markdown — guard intraword underscores + clean protocol sentinels
gweeteve
pushed a commit
to gweeteve/hermes-agent
that referenced
this pull request
Jun 2, 2026
…wn-intraword-underscore fix(tui): markdown — guard intraword underscores + clean protocol sentinels
Egavasyug
pushed a commit
to Egavasyug/hermes-agent
that referenced
this pull request
Jun 10, 2026
…wn-intraword-underscore fix(tui): markdown — guard intraword underscores + clean protocol sentinels
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Two related fixes for the TUI markdown renderer, both rooted in "what shouldn't be markdown".
1. Intraword underscores stay literal
Md'sINLINE_REmatched_..._and__...__with no word-boundary guard, so paths andsnake_caseidentifiers rendered mid-italic/bold. Example:browser_screenshot_ecc1c3feab.pngshowed_screenshot_italicized mid-path.Gated
_/__emphasis with(?<!\w)/(?!\w)on both the render regex and the table-widthstripInlineMarkup.*/**intentionally keep intraword behavior — that's CommonMark-legal and rarely wrong in practice.2. Protocol sentinels get clean handling
The agent emits
MEDIA:<path>to tell the gateway to deliver a file, and[[audio_as_voice]]to request voice-message delivery. The gateway strips both (_clean_for_displayinstream_consumer.py), but the TUI was passing them through markdown — which is where the original bug showed up.At the
Mdlayer:MEDIA:<path>on its own line →▸ <path>(dim triangle, amber underlined, literal path) wrapped inLinkfor OSC 8 hyperlink support (absolute paths getfile://so modern terminals make them clickable).[[audio_as_voice]]→ dropped; it has no meaning in TUI.Mid-prose
MEDIA:tokens (rare) are intentionally left untouched and rely on the intraword-underscore guard to stay literal.Test plan
npm testinui-tui/— 109/109 passing, 7 new cases inmarkdown.test.ts.tsc --noEmitclean.eslintclean on touched files.Before
After
Why not generic path-detection?
Punting on speculative "detect anything code-like and skip markdown" — heuristic explosion, false positives on prose (
use the /api/users endpointrendering monospaced), and the real offender was the CommonMark intraword rule plus two well-defined protocol sentinels. Targeted beats clever.