fix: resolve garbled ANSI escape codes in status printouts#2265
Closed
amethystani wants to merge 1 commit into
Closed
fix: resolve garbled ANSI escape codes in status printouts#2265amethystani wants to merge 1 commit into
amethystani wants to merge 1 commit into
Conversation
…rch#2262) Two related root causes for the '?[33mTool progress: NEW?[0m' garbling reported on kitty, alacritty, ghostty and gnome-console: 1. /verbose label printing used self.console.print() with Rich markup ([yellow]...[/]). self.console is a plain Rich Console() whose output goes directly to sys.stdout, which patch_stdout's StdoutProxy intercepts and mangles raw ANSI sequences. 2. Context pressure status lines (e.g. 'approaching compaction') from AIAgent._safe_print() had the same problem -- _safe_print() was a @staticmethod that always called builtin print(), bypassing the prompt_toolkit renderer entirely. Fix: - Convert AIAgent._safe_print() from @staticmethod to an instance method that delegates to self._print_fn (defaults to builtin print, preserving all non-CLI behaviour). - After the CLI creates its AIAgent instance, wire self.agent._print_fn to the existing _cprint() helper which routes through prompt_toolkit.print_formatted_text(ANSI(text)). - Rewrite the /verbose feedback labels to use hermes_cli.colors.Colors ANSI constants in f-strings and emit them via _cprint() directly, removing the Rich-markup-inside-patch_stdout anti-pattern. Fixes NousResearch#2262
Contributor
|
Closing for now — will revisit later. |
3 tasks
Contributor
|
Cherry-picked and merged via PR #2448 with your authorship preserved. Added a follow-up fix: changed |
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
Fixes #2262 — garbled terminal output like
?[33mTool progress: NEW?[0mon kitty, alacritty, ghostty and gnome-console.Root Cause
Two separate callsites bypass
_cprint(), the existing helper that routes ANSI-coloured text through prompt_toolkit'sprint_formatted_text(ANSI(...))renderer. Inside the interactive chat loop,patch_stdout'sStdoutProxyintercepts rawprint()/Console.print()calls and mangles ANSI escape sequences, replacing the ESC byte with?.Callsite 1 —
/verbosefeedback labels (cli.py):Callsite 2 — context pressure status (
run_agent.py):Fix
run_agent.py: Convert_safe_printfrom a@staticmethodto an instance method that delegates toself._print_fn(defaults toprint, preserving all non-CLI behaviour).cli.py: After creating theAIAgentinstance, setself.agent._print_fn = _cprintso all agent status output flows through the prompt_toolkit renderer.cli.py: Replace Rich markup in/verboselabels withhermes_cli.colors.ColorsANSI constants in f-strings, and emit via_cprint()directly.Testing