fix(tui): prefer raw text over rendered ANSI in render-markdown mode#16464
Closed
0xsir0000 wants to merge 1 commit into
Closed
fix(tui): prefer raw text over rendered ANSI in render-markdown mode#164640xsir0000 wants to merge 1 commit into
0xsir0000 wants to merge 1 commit into
Conversation
…ousResearch#16391) When `final_response_markdown: render` is set, the gateway populates `payload.rendered` with Rich-generated ANSI (cursor moves, line clears, color codes). Ink's <Md> renderer cannot interpret those sequences and displays them as garbled, overlapping text. `recordMessageComplete` now prefers `payload.text` over `payload.rendered` so Ink renders raw markdown via its own component. `recordMessageDelta` ignores the `rendered` fragment entirely during streaming — it was otherwise replacing the whole accumulated buffer with an incomplete Rich fragment on every delta, dropping prior content. Fixes NousResearch#16391
Collaborator
3 tasks
Contributor
|
The 'prefer raw text over rendered ANSI' fix was independently applied on current main via #16391. Your analysis was correct; the same root cause was addressed with similar logic. Closing as already-fixed. Thanks @0xsir0000! |
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.
What does this PR do?
When
display.final_response_markdown: renderis set, the TUI gateway populatespayload.renderedwith Rich-generated ANSI (cursor moves like\x1b[A, line clears\x1b[K, color codes). Ink's<Md>renderer cannot interpret those sequences and displays them as garbled, overlapping output — color layering, misaligned columns, escape artifacts.The TUI's
turnControllerwas prioritizingrenderedover the raw markdown text in two places:recordMessageComplete(ui-tui/src/app/turnController.ts:426) — usedpayload.rendered ?? payload.textfor the final assistant message, so Ink got ANSI instead of raw markdown.recordMessageDelta(ui-tui/src/app/turnController.ts:519) —this.bufRef = rendered ?? this.bufRef + text. Worse:renderedarrives as an incomplete Rich fragment on every streaming tick, so this replaced the full accumulated buffer with that fragment, dropping prior content.The CLI and other gateway platforms (Telegram, Discord, …) feed
renderedto real terminal emulators that interpret Rich ANSI correctly. Ink does not — it has its own markdown renderer inui-tui/src/components/markdown.tsxand just needs the raw markdown.Related Issue
Fixes #16391
Type of Change
Changes Made
ui-tui/src/app/turnController.ts—recordMessageCompletenow preferspayload.text;recordMessageDeltaignoresrenderedand accumulatestextonly.ui-tui/src/__tests__/createGatewayEventHandler.test.ts— two new tests covering the complete and delta paths.How to Test
~/.hermes/config.yaml:hermes --tuiand ask for a multi-paragraph reply (or one with tables/code blocks).<Md>component.Automated:
Notes
This is the minimal targeted fix (Option A from the issue). Two follow-ups remain possible but are out of scope here:
display.tui_prefer_raw_text.renderedpopulation for TUI sessions entirely (tui_gateway/server.py:2319and:2264). That would also save the wasted Rich render work for TUI clients.