refactor: extract cli_display.py from cli.py (−988 lines) - #79790
Open
xandgate wants to merge 2 commits into
Open
refactor: extract cli_display.py from cli.py (−988 lines)#79790xandgate wants to merge 2 commits into
xandgate wants to merge 2 commits into
Conversation
Extracts ANSI/skin helpers, light-mode detection/remap, output-history record/replay, file-drop and attachment detection, ChatConsole, banners, and slash-command detection into cli_display.py. cli.py re-imports all moved names. Tests re-pointed at cli_display for mutable global access (_LIGHT_MODE_CACHE, _OUTPUT_HISTORY). Known issue: _install_skin_light_mode_hook + 2 light-mode tests need fixing — mutable global reassignment doesn't propagate through re-import. Part of the god-file modularization goal from AGENTS.md. Supersedes part of NousResearch#12355.
Move _install_skin_light_mode_hook() call from cli.py to cli_display.py module load. This ensures the hook fires regardless of which module imports cli_display first (test or cli). Also removes the duplicate call from cli.py since the import-time call in cli_display handles it.
This was referenced Aug 6, 2026
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.
Extracts ANSI/skin helpers, light-mode detection/remap, output-history
record/replay, file-drop and attachment detection, ChatConsole, banners,
and slash-command detection into cli_display.py.
cli.py re-imports all moved names. Tests re-pointed at cli_display for
mutable global access (_LIGHT_MODE_CACHE, _OUTPUT_HISTORY).
Part of the god-file modularization goal from AGENTS.md. Supersedes part of #12355.
What does this PR do?
Extracts the display/UI cluster from
cli.py(18,485 lines) into a focusedcli_display.pymodule (1,076 lines), as part of the god-file modularization goal inAGENTS.md("Refactor god-files into clean modules").The display cluster handles ANSI color helpers, light-mode detection and color remapping, output history record/replay, the interactive
ChatConsoleclass, file-drop/attachment detection, banners, and slash-command detection. All items are UI/display helpers with no dependencies on theHermesCLIclass._install_skin_light_mode_hook()is called atcli_display.pyimport time (not fromcli.py), ensuring the hook fires regardless of which module imports it first. Tests that reset mutable globals (_LIGHT_MODE_CACHE,_OUTPUT_HISTORY) are re-pointed atcli_displaydirectly.Part 3 of 3, splitting the old #12355 into independently reviewable extractions:
Related Issue
Supersedes #12355 (same extraction, re-done from current main after 3,993 commits diverged). Split into 3 smaller PRs for easier review.
Type of Change
Changes Made
cli_display.py(1,076 lines) with verbatim moves of:_hex_to_ansi(),_SkinAwareAnsi,_b(),_d(),_accent_hex(),_rich_text_from_ansi()_detect_light_mode(),_maybe_remap_for_light_mode(),_install_skin_light_mode_hook(),_luminance_from_hex(),_query_osc11_background()_coerce_output_history_limit(),_configure_output_history(),_clear_output_history(),_suspend_output_history(),_record_output_history(),_replay_output_history()_cprint(),ChatConsole,_build_compact_banner(),_looks_like_slash_command()_resolve_attachment_path(),_detect_file_drop(),_format_image_attachment_badges(),_should_auto_attach_clipboard_image_on_paste()_strip_markdown_syntax(),_preserve_windows_dot_segments_for_markdown(),realign_markdown_tables()_terminal_width_for_streaming(),_render_final_assistant_content()_COMMAND_SPINNER_FRAMES,_ACCENT_ANSI_DEFAULT,_BOLD,_RST,_STREAM_PAD,_LIGHT_MODE_REMAP,_OUTPUT_HISTORY_*,_IMAGE_EXTENSIONS,_OSC_ESCAPE_REcli.py(18,485 → 17,497 lines, −988 net):from cli_display import (...)re-import block (54 names)_install_skin_light_mode_hook()call (now handled atcli_displayimport time)cli_displaydirectly for mutable global access:tests/cli/test_cli_light_mode.py(fixture + docstring)tests/cli/test_cprint_bg_thread.py(import + docstring)How to Test
python -c "import cli_display; print('ok')"— module imports cleanlypython -c "import cli; print('ok')"— cli.py still imports with re-exportspytest tests/cli tests/hermes_cli -x→ 1233 passed, 1 skipped, 1 pre-existing failure (test_resume_quiet_stderr.py— fails on cleanmaintoo)pytest tests/cli/test_cli_light_mode.py tests/cli/test_cprint_bg_thread.py -x→ 16 passed (light-mode hook + output history verified)Checklist
Code
refactor: extract cli_display.py from cli.py (−988 lines))pytest tests/ -qand all tests pass (1233 passed, 1 skipped; 1 pre-existing failure on clean main)Documentation & Housekeeping
docs/, docstrings) — or N/Acli-config.yaml.exampleif I added/changed config keys — or N/ACONTRIBUTING.mdorAGENTS.mdif I changed architecture or workflows — or N/AScreenshots / Logs
The 1 failure (test_resume_quiet_stderr.py) is pre-existing on clean main.