Skip to content

refactor: extract cli_display.py from cli.py (−988 lines) - #79790

Open
xandgate wants to merge 2 commits into
NousResearch:mainfrom
xandgate:refactor/cli-display-extract
Open

refactor: extract cli_display.py from cli.py (−988 lines)#79790
xandgate wants to merge 2 commits into
NousResearch:mainfrom
xandgate:refactor/cli-display-extract

Conversation

@xandgate

@xandgate xandgate commented Aug 6, 2026

Copy link
Copy Markdown

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 focused cli_display.py module (1,076 lines), as part of the god-file modularization goal in AGENTS.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 ChatConsole class, file-drop/attachment detection, banners, and slash-command detection. All items are UI/display helpers with no dependencies on the HermesCLI class.

_install_skin_light_mode_hook() is called at cli_display.py import time (not from cli.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 at cli_display directly.

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

  • ♻️ Refactor (no behavior change)

Changes Made

  • Created cli_display.py (1,076 lines) with verbatim moves of:
    • ANSI/color: _hex_to_ansi(), _SkinAwareAnsi, _b(), _d(), _accent_hex(), _rich_text_from_ansi()
    • Light mode: _detect_light_mode(), _maybe_remap_for_light_mode(), _install_skin_light_mode_hook(), _luminance_from_hex(), _query_osc11_background()
    • Output history: _coerce_output_history_limit(), _configure_output_history(), _clear_output_history(), _suspend_output_history(), _record_output_history(), _replay_output_history()
    • Console/IO: _cprint(), ChatConsole, _build_compact_banner(), _looks_like_slash_command()
    • File handling: _resolve_attachment_path(), _detect_file_drop(), _format_image_attachment_badges(), _should_auto_attach_clipboard_image_on_paste()
    • Markdown: _strip_markdown_syntax(), _preserve_windows_dot_segments_for_markdown(), realign_markdown_tables()
    • Streaming: _terminal_width_for_streaming(), _render_final_assistant_content()
    • Constants: _COMMAND_SPINNER_FRAMES, _ACCENT_ANSI_DEFAULT, _BOLD, _RST, _STREAM_PAD, _LIGHT_MODE_REMAP, _OUTPUT_HISTORY_*, _IMAGE_EXTENSIONS, _OSC_ESCAPE_RE
  • Modified cli.py (18,485 → 17,497 lines, −988 net):
    • Removed extracted function bodies
    • Added from cli_display import (...) re-import block (54 names)
    • Removed duplicate _install_skin_light_mode_hook() call (now handled at cli_display import time)
  • Updated 2 test files to import cli_display directly 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

  1. python -c "import cli_display; print('ok')" — module imports cleanly
  2. python -c "import cli; print('ok')" — cli.py still imports with re-exports
  3. pytest tests/cli tests/hermes_cli -x → 1233 passed, 1 skipped, 1 pre-existing failure (test_resume_quiet_stderr.py — fails on clean main too)
  4. 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

  • I've read the Contributing Guide
  • My commit messages follow Conventional Commits (refactor: extract cli_display.py from cli.py (−988 lines))
  • I searched for existing PRs to make sure this isn't a duplicate
  • My PR contains only changes related to this fix/feature (no unrelated commits)
  • I've run pytest tests/ -q and all tests pass (1233 passed, 1 skipped; 1 pre-existing failure on clean main)
  • I've added tests for my changes (updated 2 test files to patch cli_display mutable globals)
  • I've tested on my platform: Ubuntu 24.04

Documentation & Housekeeping

  • I've updated relevant documentation (README, docs/, docstrings) — or N/A
  • I've updated cli-config.yaml.example if I added/changed config keys — or N/A
  • I've updated CONTRIBUTING.md or AGENTS.md if I changed architecture or workflows — or N/A
  • I've considered cross-platform impact (Windows, macOS) per the compatibility guide — or N/A
  • I've updated tool descriptions/schemas if I changed tool behavior — or N/A

Screenshots / Logs

$ python -m pytest tests/cli/test_cli_light_mode.py tests/cli/test_cprint_bg_thread.py -x
============================== 16 passed in 0.26s ==============================

$ python -m pytest tests/cli tests/hermes_cli -x
======= 1 failed, 1233 passed, 1 skipped in 119.41s =======

The 1 failure (test_resume_quiet_stderr.py) is pre-existing on clean main.

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.
@alt-glitch alt-glitch added type/refactor Code restructuring, no behavior change P3 Low — cosmetic, nice to have comp/cli CLI entry point, hermes_cli/, setup wizard labels Aug 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/cli CLI entry point, hermes_cli/, setup wizard P3 Low — cosmetic, nice to have type/refactor Code restructuring, no behavior change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants