Skip to content

refactor: extract cli_config.py from cli.py (−605 lines) - #79784

Open
xandgate wants to merge 1 commit into
NousResearch:mainfrom
xandgate:refactor/cli-config-extract
Open

refactor: extract cli_config.py from cli.py (−605 lines)#79784
xandgate wants to merge 1 commit into
NousResearch:mainfrom
xandgate:refactor/cli-config-extract

Conversation

@xandgate

@xandgate xandgate commented Aug 6, 2026

Copy link
Copy Markdown

Extracts config loading/saving, prefill message handling, reasoning/service-tier parsing, and content-processing helpers into cli_config.py.

cli.py re-imports all moved names, so existing from cli import X call sites keep working. Tests that monkeypatched _hermes_home now patch cli_config.

Supersedes #12355 which was stale (main moved 3993 commits ahead).

What does this PR do?

Extracts the configuration cluster from cli.py (18,485 lines) into a focused cli_config.py module (641 lines), as part of the god-file modularization goal in AGENTS.md ("Refactor god-files into clean modules").

The config cluster is a self-contained group of 10 top-level functions that handle config loading/saving, prefill message resolution, and reasoning/service-tier parsing. They have clean boundaries and no dependencies on the HermesCLI class or main(). This is the first of 3 small PRs 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_config.py (641 lines) with verbatim moves of:
    • _REASONING_TAGS, _strip_reasoning_tags(), _assistant_content_as_text(), _assistant_copy_text()
    • _load_prefill_messages(), _resolve_prefill_messages_file()
    • _parse_reasoning_config(), _parse_service_tier_config()
    • load_cli_config() (~491 lines), save_config_value()
  • Modified cli.py (18,485 → 17,880 lines, −605 net):
    • Removed extracted function bodies
    • Added from cli_config import (...) re-import block after existing imports
  • Updated 9 test files to patch cli_config._hermes_home instead of cli._hermes_home:
    • tests/cli/test_cli_init.py (4 sites)
    • tests/cli/test_cli_save_config_value.py
    • tests/hermes_cli/test_config_env_expansion.py (2 sites)
    • tests/hermes_cli/test_ignore_user_config_flags.py
    • tests/hermes_cli/test_managed_scope_cli_config.py
    • tests/hermes_cli/test_reasoning_full_command.py
    • tests/hermes_cli/test_timestamps_command.py
    • tests/test_tui_gateway_server.py

How to Test

  1. python -c "import cli_config; 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 →761 passed, 1 skipped, 1 pre-existing failure (test_resume_quiet_stderr.py — fails on clean main too)

Checklist

Code

  • I've read the Contributing Guide
  • My commit messages follow Conventional Commits (refactor: extract cli_config.py from cli.py (−605 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 (761 passed, 1 skipped; 1 pre-existing failure on clean main)
  • I've added tests for my changes (updated 9 test files to patch the new module)
  • 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 tests/hermes_cli -x 
================== 1 failed, 761 passed, 1 skipped in 55.24s ==================
The 1 failure (test_resume_quiet_stderr.py) is pre-existing on clean main.

Extracts config loading/saving, prefill message handling, reasoning/service-tier
parsing, and content-processing helpers into cli_config.py.

cli.py re-imports all moved names, so existing `from cli import X` call sites
keep working. Tests that monkeypatched `_hermes_home` now patch `cli_config`.

Supersedes NousResearch#12355 which was stale (main moved 3993 commits ahead).
@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 area/config Config system, migrations, profiles sweeper:risk-compatibility Sweeper risk: may break existing users, config, migrations, defaults, or upgrades labels Aug 6, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

This was generated by AI during triage.

Related: this is the focused Part 1 split of the broader open #12355 cli.py extraction. It is a subset, not a duplicate.

@xandgate

xandgate commented Aug 6, 2026

Copy link
Copy Markdown
Author

Thanks @alt-glitch. Correct — this is the focused Part 1 of 3 PRs splitting the stale #12355 into independently reviewable extractions. Parts 2 and 3 are now open: #79789 (cli_git.py) and #79790 (cli_display.py). Each can be reviewed and merged independently.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/config Config system, migrations, profiles comp/cli CLI entry point, hermes_cli/, setup wizard P3 Low — cosmetic, nice to have sweeper:risk-compatibility Sweeper risk: may break existing users, config, migrations, defaults, or upgrades type/refactor Code restructuring, no behavior change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants