fix(cli): preserve chat -q answer by gating exit-summary screen clear (#53009) - #53025
Closed
Tranquil-Flow wants to merge 1 commit into
Closed
fix(cli): preserve chat -q answer by gating exit-summary screen clear (#53009)#53025Tranquil-Flow wants to merge 1 commit into
Tranquil-Flow wants to merge 1 commit into
Conversation
…NousResearch#53009) In single-query (-q) mode, the assistant's final answer was printed and then immediately erased by _print_exit_summary() — which unconditionally called _clear_terminal_on_exit() (ESC[3J ESC[2J ESC[H]). The answer was present in the session store but invisible in the terminal. The clear is only needed for interactive TUI teardown (NousResearch#38928) where prompt_toolkit chrome must be cleaned up. Add a clear_screen parameter to _print_exit_summary() (default True, preserving interactive behavior) and pass False from the single-query call site so the answer stays visible above the exit summary. Regression tests cover: - clear_screen=True (default) calls _clear_terminal_on_exit() - clear_screen=False skips the clear - Single-query -q path passes False end-to-end - Interactive path still clears (preserving NousResearch#38928)
Contributor
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
hermes chat -q "<prompt>"prints the assistant's final answer and thenwipes it off the screen a fraction of a second later. What remains is only
the exit summary. The answer was generated and persisted, but never visible.
Root cause
_print_exit_summary()unconditionally calls_clear_terminal_on_exit(),which writes
ESC[3J ESC[2J ESC[H— clearing scrollback and the visiblescreen. In single-query (
-q) mode there is no prompt_toolkit chrome to teardown, so the clear destroys real user-visible output.
Fix
Gate the screen clear behind a
clear_screen: bool = Trueparameter on_print_exit_summary():-q) call site → passesclear_screen=Falseto preservethe printed answer.
True, so the screen-clear forTUI teardown ([Bug]: Hermes Agent does not cleanly hand control back to CLI after session ends #38252 / fix(cli): clear screen on exit so live chrome isn't stranded in scrollback #38928) is unchanged.
stream.isatty()in_clear_terminal_on_exit(); no change needed.All three call sites of
_print_exit_summary()verified:main()single-query (15518 →False),run()stdin-failure path (14770 →default),
run()interactive teardown (14922 → default).Test plan
4 regression tests in
tests/cli/test_chat_q_exit_clear.py:test_print_exit_summary_clears_screen_by_defaulttest_print_exit_summary_skips_clear_when_clear_screen_falseFalseskips the cleartest_single_query_main_skips_clear_on_exit_summary-qpath passesFalseend-to-endtest_print_exit_summary_still_clears_in_interactive_pathFail-without-fix proven: tests fail on
upstream/main(TypeError: unexpected keyword argument 'clear_screen', assertionTrue != False).Closes #53009.
Auto-published by Moonsong via Path B automated pipeline.