Skip to content

refactor(doctor): extract section banner + fail-and-issue helpers#27830

Merged
kshitijk4poor merged 1 commit into
NousResearch:mainfrom
kshitijk4poor:chore/doctor-dedup-helpers
May 18, 2026
Merged

refactor(doctor): extract section banner + fail-and-issue helpers#27830
kshitijk4poor merged 1 commit into
NousResearch:mainfrom
kshitijk4poor:chore/doctor-dedup-helpers

Conversation

@kshitijk4poor

@kshitijk4poor kshitijk4poor commented May 18, 2026

Copy link
Copy Markdown
Collaborator

Summary

hermes_cli/doctor.py had two recurring patterns. This PR extracts two helpers and collapses every occurrence of both patterns — pure mechanical dedup with byte-identical output (verified by diffing live run_doctor() runs against origin/main).

Result: −5 net LOC (+128 / −133). The LOC delta is modest after wrapping long _fail_and_issue calls onto multi-line form for readability — the real win is uniform call shape and removal of two parallel-pattern footguns. There is now exactly one way to emit a diagnostic that pairs a user-visible failure with a fix instruction.

What changed

Pattern 1: Section headers (15 instances)

Each diagnostic section began with a 5-line decoration block:

# =========================================================================
# Check: Configuration Files
# =========================================================================
print()
print(color("◆ Configuration Files", Colors.CYAN, Colors.BOLD))

Replaced with a single helper call:

_section("Configuration Files")

The helper:

def _section(title: str) -> None:
    """Print a doctor section banner: blank line + bold cyan ◆ title."""
    print()
    print(color(f"◆ {title}", Colors.CYAN, Colors.BOLD))

Pattern 2: check_fail + issues.append pairs (18 instances)

The doctor frequently emits a failure marker AND appends a fix instruction:

check_fail(name, "(missing)")
issues.append(f"Install {name}: {_python_install_cmd()} {module}")

Replaced with one call:

_fail_and_issue(name, "(missing)", f"Install {name}: {_python_install_cmd()} {module}", issues)

The helper:

def _fail_and_issue(text: str, detail: str, fix: str, issues: list[str]) -> None:
    """Emit a check_fail and append the corresponding fix instruction."""
    check_fail(text, detail)
    issues.append(fix)

Call shape: single-line where the call fits under 120 chars (5 sites), multi-line where it would exceed (13 sites). Let line length decide form rather than maintaining two parallel patterns.

Test plan

  • ✅ All 69 tests pass across tests/hermes_cli/test_doctor.py, test_doctor_command_install.py, test_doctor_dedicated_provider_skip.py
  • ruff check hermes_cli/doctor.py clean
  • ✅ Byte-identical runtime output: ran run_doctor() against both origin/main and this branch with the same isolated $HERMES_HOME, diffed the captured stdout — diff -q reports no differences.

Behavior

Byte-identical to before. _section produces the same print() + print(color(...)) sequence the original code did, and _fail_and_issue does the same check_fail + issues.append calls in the same order.

All previously-test-imported module attributes (run_doctor, _apply_doctor_tool_availability_overrides, _build_apikey_providers_list, _check_gateway_service_linger, _doctor_tool_availability_detail, _honcho_is_configured_for_doctor, _python_install_cmd, _system_package_install_cmd, _APIKEY_PROVIDERS_CACHE) are unchanged. The 2 new helpers (_section, _fail_and_issue) are module-local and _-prefixed.

Refs

#23972 — dedup-only refactor in line with the "net-LOC-negative" discipline established in the May 17 tracker update. The win here is uniform call shape more than LOC count — the file is now free of parallel check_fail + issues.append and # === banner patterns.

@alt-glitch alt-glitch added type/refactor Code restructuring, no behavior change comp/cli CLI entry point, hermes_cli/, setup wizard P3 Low — cosmetic, nice to have labels May 18, 2026
@kshitijk4poor kshitijk4poor force-pushed the chore/doctor-dedup-helpers branch from 94261be to 964c9b1 Compare May 18, 2026 07:20
`hermes_cli/doctor.py` had two recurring patterns:

1. **15 section headers** of the form `print() ; print(color("◆ Name", Colors.CYAN, Colors.BOLD))`
   bracketed by 3-line `# =====` / `# Check: X` / `# =====` comment banners.

2. **Paired `check_fail(...) ; issues.append(...)`** for every diagnostic that emits both a
   user-visible failure and an auto-fix instruction.

Add two helpers and collapse the patterns:

  def _section(title):
      print()
      print(color(f"◆ {title}", Colors.CYAN, Colors.BOLD))

  def _fail_and_issue(text, detail, fix, issues):
      check_fail(text, detail)
      issues.append(fix)

Replacements:
- 15 `# =====/# X/# =====` banner triples + section header pairs compressed to `_section(...)`
- All 18 `check_fail + issues.append` pairs collapsed to `_fail_and_issue(...)` (single-line
  where the call fits under 120 chars, multi-line where it doesn't)
- Net -5 LOC (`+128 / -133`)

The LOC delta is modest after wrapping long calls onto multi-line form for readability — the
real win is uniform call shape and removal of two parallel-pattern footguns. There is now
exactly one way to emit a diagnostic that pairs a user-visible failure with a fix instruction.

Behavior is byte-identical. `_section` produces the same blank line + bold-cyan output the
inline two prints did, and `_fail_and_issue` does the same `check_fail + issues.append`
sequence in the same order. Verified empirically by diffing live `run_doctor()` stdout from
this branch against `origin/main` — `diff -q` reports zero differences.

Test plan:
- All 69 tests across test_doctor.py, test_doctor_command_install.py, and
  test_doctor_dedicated_provider_skip.py pass
- `ruff check hermes_cli/doctor.py` clean
- Live `run_doctor()` output byte-identical to origin/main

Refs NousResearch#23972 (Phase 2 tracker — dedup-only refactor in line with the "net-LOC-negative"
discipline).
@kshitijk4poor kshitijk4poor force-pushed the chore/doctor-dedup-helpers branch from 964c9b1 to 540fac2 Compare May 18, 2026 07:28
@kshitijk4poor kshitijk4poor changed the title refactor(doctor): extract section banner + fail-and-issue helpers (-64 LOC) refactor(doctor): extract section banner + fail-and-issue helpers May 18, 2026
@kshitijk4poor kshitijk4poor merged commit 41f1edd into NousResearch:main May 18, 2026
15 of 16 checks passed
@kshitijk4poor kshitijk4poor deleted the chore/doctor-dedup-helpers branch May 18, 2026 07:48
Lillard01 pushed a commit to Lillard01/hermes-agent that referenced this pull request May 21, 2026
…usResearch#27830)

`hermes_cli/doctor.py` had two recurring patterns:

1. **15 section headers** of the form `print() ; print(color("◆ Name", Colors.CYAN, Colors.BOLD))`
   bracketed by 3-line `# =====` / `# Check: X` / `# =====` comment banners.

2. **Paired `check_fail(...) ; issues.append(...)`** for every diagnostic that emits both a
   user-visible failure and an auto-fix instruction.

Add two helpers and collapse the patterns:

  def _section(title):
      print()
      print(color(f"◆ {title}", Colors.CYAN, Colors.BOLD))

  def _fail_and_issue(text, detail, fix, issues):
      check_fail(text, detail)
      issues.append(fix)

Replacements:
- 15 `# =====/# X/# =====` banner triples + section header pairs compressed to `_section(...)`
- All 18 `check_fail + issues.append` pairs collapsed to `_fail_and_issue(...)` (single-line
  where the call fits under 120 chars, multi-line where it doesn't)
- Net -5 LOC (`+128 / -133`)

The LOC delta is modest after wrapping long calls onto multi-line form for readability — the
real win is uniform call shape and removal of two parallel-pattern footguns. There is now
exactly one way to emit a diagnostic that pairs a user-visible failure with a fix instruction.

Behavior is byte-identical. `_section` produces the same blank line + bold-cyan output the
inline two prints did, and `_fail_and_issue` does the same `check_fail + issues.append`
sequence in the same order. Verified empirically by diffing live `run_doctor()` stdout from
this branch against `origin/main` — `diff -q` reports zero differences.

Test plan:
- All 69 tests across test_doctor.py, test_doctor_command_install.py, and
  test_doctor_dedicated_provider_skip.py pass
- `ruff check hermes_cli/doctor.py` clean
- Live `run_doctor()` output byte-identical to origin/main

Refs NousResearch#23972 (Phase 2 tracker — dedup-only refactor in line with the "net-LOC-negative"
discipline).
gweeteve pushed a commit to gweeteve/hermes-agent that referenced this pull request Jun 2, 2026
…usResearch#27830)

`hermes_cli/doctor.py` had two recurring patterns:

1. **15 section headers** of the form `print() ; print(color("◆ Name", Colors.CYAN, Colors.BOLD))`
   bracketed by 3-line `# =====` / `# Check: X` / `# =====` comment banners.

2. **Paired `check_fail(...) ; issues.append(...)`** for every diagnostic that emits both a
   user-visible failure and an auto-fix instruction.

Add two helpers and collapse the patterns:

  def _section(title):
      print()
      print(color(f"◆ {title}", Colors.CYAN, Colors.BOLD))

  def _fail_and_issue(text, detail, fix, issues):
      check_fail(text, detail)
      issues.append(fix)

Replacements:
- 15 `# =====/# X/# =====` banner triples + section header pairs compressed to `_section(...)`
- All 18 `check_fail + issues.append` pairs collapsed to `_fail_and_issue(...)` (single-line
  where the call fits under 120 chars, multi-line where it doesn't)
- Net -5 LOC (`+128 / -133`)

The LOC delta is modest after wrapping long calls onto multi-line form for readability — the
real win is uniform call shape and removal of two parallel-pattern footguns. There is now
exactly one way to emit a diagnostic that pairs a user-visible failure with a fix instruction.

Behavior is byte-identical. `_section` produces the same blank line + bold-cyan output the
inline two prints did, and `_fail_and_issue` does the same `check_fail + issues.append`
sequence in the same order. Verified empirically by diffing live `run_doctor()` stdout from
this branch against `origin/main` — `diff -q` reports zero differences.

Test plan:
- All 69 tests across test_doctor.py, test_doctor_command_install.py, and
  test_doctor_dedicated_provider_skip.py pass
- `ruff check hermes_cli/doctor.py` clean
- Live `run_doctor()` output byte-identical to origin/main

Refs NousResearch#23972 (Phase 2 tracker — dedup-only refactor in line with the "net-LOC-negative"
discipline).
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.

2 participants