refactor(hermes_cli): group C — drop blank lines after function-local imports

This commit is contained in:
Teknium
2026-09-02 21:36:19 -07:00
parent 12e3ae890b
commit 381d88f433
4 changed files with 0 additions and 37 deletions
-4
View File
@@ -34,10 +34,8 @@ def _personalities_from_cli_config() -> Dict[str, Any]:
global _personalities_memo
from cli import load_cli_config
from hermes_cli.personality import available_personalities
try:
from hermes_cli.config import get_config_path
cfg_path = get_config_path()
st = cfg_path.stat()
sig = (str(cfg_path), st.st_mtime_ns, st.st_size)
@@ -107,7 +105,6 @@ def _personality_completions(sub_text: str, sub_lower: str):
"""/personality — ``none`` plus configured personalities."""
try:
from hermes_cli.personality import describe_personality
personalities = _personalities_from_cli_config()
rows = chain(
[("none", "clear personality overlay")],
@@ -162,7 +159,6 @@ def _handoff_completions(sub_text: str, sub_lower: str):
return
try:
from gateway.config import load_gateway_config
gw = load_gateway_config()
platforms = gw.get_connected_platforms()
except Exception:
-16
View File
@@ -107,7 +107,6 @@ def _table_summary(summary: str, *, limit: int = 76) -> str:
def _split_line(line: str) -> list[str]:
# Windows-safe splitter: plain shlex posix=True eats backslashes in paths.
from hermes_cli._subprocess_compat import split_command_line
try:
return split_command_line(line)
except ValueError as exc:
@@ -139,7 +138,6 @@ def _format_sessions(sessions: Sequence[dict]) -> str:
def _format_job(job: dict, action: str) -> str:
from cron.jobs import effective_job_state
job_id = job.get("id") or job.get("job_id") or "?"
return f"{action} job: {job.get('name') or '(unnamed)'} ({job_id}) [{effective_job_state(job)}]"
@@ -594,14 +592,12 @@ def _apply_confirmed_defaults(args: argparse.Namespace) -> None:
def _version(_engine: HermesConsoleEngine, args: list[str]) -> str:
_expect_no_args(args, "version")
from hermes_cli._startup_fast import print_fast_version_info
return _capture_output(lambda: print_fast_version_info(check_updates=True))
def _status(_engine: HermesConsoleEngine, args: list[str]) -> str:
_expect_no_args(args, "status")
from hermes_cli.status import show_status
output = _capture_output(lambda: show_status(SimpleNamespace(all=False, deep=False)))
return _strip_console_status_footer(output)
@@ -622,7 +618,6 @@ def _logs(_engine: HermesConsoleEngine, args: list[str]) -> str:
if ns.lines < 1 or ns.lines > 500:
raise ConsoleCommandError("logs --lines must be between 1 and 500")
from hermes_cli.logs import list_logs, tail_log
if ns.log_name == "list":
return _capture_output(list_logs)
return _capture_output(
@@ -634,7 +629,6 @@ def _logs(_engine: HermesConsoleEngine, args: list[str]) -> str:
def _session_db():
"""``with _session_db() as db:`` — SessionDB closed on exit."""
from hermes_state import SessionDB
return closing(SessionDB())
@@ -667,7 +661,6 @@ def _sessions_stats(_engine: HermesConsoleEngine, args: list[str]) -> str:
def _config_path(_engine: HermesConsoleEngine, args: list[str]) -> str:
_expect_no_args(args, "config path")
from hermes_cli.config import get_config_path
return str(get_config_path())
@@ -675,7 +668,6 @@ def _config_set(_engine: HermesConsoleEngine, args: list[str]) -> str:
if len(args) < 2:
raise ConsoleCommandError("Usage: config set <key> <value>")
from hermes_cli.config import set_config_value
return _capture_output(lambda: set_config_value(args[0], " ".join(args[1:])))
@@ -683,7 +675,6 @@ def _config_set(_engine: HermesConsoleEngine, args: list[str]) -> str:
def _config_migrate(_engine: HermesConsoleEngine, args: list[str]) -> None:
_expect_no_args(args, "config migrate")
from hermes_cli.config import migrate_config
results = migrate_config(interactive=False, quiet=False)
if results.get("env_added") or results.get("config_added"):
print("Configuration updated.")
@@ -696,7 +687,6 @@ def _config_migrate(_engine: HermesConsoleEngine, args: list[str]) -> None:
def _guard_exports(db, session_ids: list[str]) -> None:
"""Per-session export budget: only an individual runaway transcript trips it; 0 disables."""
from hermes_state import SessionExportTooLargeError, resolved_max_export_messages
limit = resolved_max_export_messages()
if limit <= 0:
return
@@ -765,7 +755,6 @@ def _sessions_repair(_engine: HermesConsoleEngine, args: list[str]) -> None:
"sessions repair", args, (("--check-only",), dict(action="store_true")),
(("--no-backup",), dict(action="store_true")))
from hermes_state import DEFAULT_DB_PATH, _db_opens_cleanly, repair_state_db_schema
db_path = DEFAULT_DB_PATH
if not db_path.exists():
print(f"No session database at {db_path} (nothing to repair).")
@@ -794,7 +783,6 @@ def _profile_status(_engine: HermesConsoleEngine, args: list[str]) -> str:
def _cron_list(_engine: HermesConsoleEngine, args: list[str]) -> str:
ns = _parse("cron list", args, (("--all",), dict(action="store_true")))
from hermes_cli.cron import cron_list
return _capture_output(lambda: cron_list(show_all=ns.all))
@@ -803,7 +791,6 @@ def _cron_job_action(args: list[str], usage: str, action: str, run) -> str:
if len(args) != 1:
raise ConsoleCommandError(f"Usage: {usage}")
from cron.jobs import AmbiguousJobReference
try:
job = run(args[0])
except AmbiguousJobReference as exc:
@@ -815,7 +802,6 @@ def _cron_job_action(args: list[str], usage: str, action: str, run) -> str:
def _cron_pause(_engine: HermesConsoleEngine, args: list[str]) -> str:
from cron.jobs import pause_job
return _cron_job_action(
args, "cron pause <job>", "Paused",
lambda ref: pause_job(ref, reason="paused from hermes console"))
@@ -826,7 +812,6 @@ def _cron_resume(_engine: HermesConsoleEngine, args: list[str]) -> str:
if ns.at and ns.run_now:
raise ConsoleCommandError("Use exactly one of --at or --run-now.")
from cron.jobs import AmbiguousJobReference, _hermes_now, rearm_oneshot, resume_job
try:
if ns.at or ns.run_now:
job = rearm_oneshot(ns.job, _hermes_now().isoformat() if ns.run_now else ns.at)
@@ -841,7 +826,6 @@ def _cron_resume(_engine: HermesConsoleEngine, args: list[str]) -> str:
def _cron_run(_engine: HermesConsoleEngine, args: list[str]) -> str:
from cron.jobs import trigger_job
return _cron_job_action(args, "cron run <job>", "Triggered", trigger_job)
-10
View File
@@ -66,7 +66,6 @@ def _print_unmanaged_summary() -> None:
``skill_manage(create)`` are eligible but unmanaged, so no automatic transition touches them.
"""
from tools import skill_usage
try:
unmanaged = skill_usage.unmanaged_report()
except Exception:
@@ -84,7 +83,6 @@ def _print_unmanaged_summary() -> None:
def _cmd_status(args) -> int:
from agent import curator
from tools import skill_usage
state = curator.load_state()
paused = state.get("paused", False)
summary = state.get("last_run_summary") or "(none)"
@@ -249,7 +247,6 @@ def _cmd_unpin(args) -> int: return _set_pin(args, False)
def _cmd_list_unmanaged(args) -> int:
"""Itemize the unmanaged population that `status` summarizes (input for `adopt`)."""
from tools import skill_usage
rows = skill_usage.unmanaged_report()
if not rows:
print("curator: no unmanaged skills — every eligible skill is managed")
@@ -276,7 +273,6 @@ def _cmd_adopt(args) -> int:
skill, not that it AUTHORED it.
"""
from tools import skill_usage
names = list(getattr(args, "skill", None) or [])
adopt_all = bool(getattr(args, "all_unmanaged", False))
if adopt_all:
@@ -413,7 +409,6 @@ def _cmd_backup(args) -> int:
def _cmd_ledger(args) -> int:
"""List per-mutation audit ledger entries (newest first)."""
from tools import skill_ledger
rows = skill_ledger.list_entries(
skill=getattr(args, "skill", None), limit=getattr(args, "limit", None) or 20)
if not rows:
@@ -446,7 +441,6 @@ def _cmd_purge(args) -> int:
from hermes_cli.config import cfg_get, load_config
from tools import skill_ledger
from tools.skill_usage import _archive_dir
ttl_days = getattr(args, "days", None)
if ttl_days is None:
ttl_days = int(cfg_get(load_config(), "curator", "archive_ttl_days", default=0) or 0)
@@ -463,7 +457,6 @@ def _cmd_purge(args) -> int:
import shutil
import time
cutoff = time.time() - ttl_days * 86400
candidates = sorted(
p for p in archive_root.iterdir() if p.is_dir() and p.stat().st_mtime < cutoff)
@@ -508,7 +501,6 @@ def _rollback_ledger_entry(args, entry_id: str) -> int:
A pre-rollback safety ledger entry is taken first; fails closed if that capture fails.
"""
from tools import skill_ledger
entry = skill_ledger.get_entry(entry_id)
if entry is None:
print(
@@ -532,7 +524,6 @@ def _rollback_ledger_entry(args, entry_id: str) -> int:
def _cmd_rollback(args) -> int:
"""Restore the skills tree from a snapshot, or a single mutation from the audit ledger."""
from agent import curator_backup
entry_id = getattr(args, "entry_id", None)
if entry_id:
return _rollback_ledger_entry(args, entry_id)
@@ -595,7 +586,6 @@ def _cmd_usage(args) -> int:
"""Usage telemetry for ALL skills on disk (bundled + hub included), with provenance."""
import json as _json
from tools import skill_usage
rows = skill_usage.usage_report()
prov_filter = getattr(args, "provenance", None)
if prov_filter:
-7
View File
@@ -111,7 +111,6 @@ def _read_numbered_input(prompt_text: str) -> str | _NumberedNavigation:
# Setup may run without the classic CLI, which normally installs CSI-u aliases at startup.
from hermes_cli.pt_input_extras import install_modify_other_keys_aliases
install_modify_other_keys_aliases()
bindings = KeyBindings()
@@ -155,7 +154,6 @@ def _curses_style_attr(curses, style: Optional[str], *, is_cursor: bool):
def _addnstr(stdscr, y: int, x: int, text: str, n: int, attr) -> None:
"""``stdscr.addnstr`` that swallows ``curses.error`` (drawing past the screen edge)."""
import curses
try:
stdscr.addnstr(y, x, text, n, attr)
except curses.error:
@@ -165,7 +163,6 @@ def _addnstr(stdscr, y: int, x: int, text: str, n: int, attr) -> None:
def _draw_title_and_hint(stdscr, title: str, hint: str, max_x: int, *, hint_row: int = 1) -> None:
"""Bold/yellow menu title on row 0, dim key hint on ``hint_row``."""
import curses
hattr = curses.A_BOLD | (curses.color_pair(2) if curses.has_colors() else 0)
_addnstr(stdscr, 0, 0, title, max_x - 1, hattr)
_addnstr(stdscr, hint_row, 0, hint, max_x - 1, curses.A_DIM)
@@ -186,7 +183,6 @@ def _draw_segments(stdscr, y: int, x: int, segments, max_x: int) -> None:
def _draw_description_line(stdscr, y: int, text: str, max_x: int) -> None:
"""Draw a description line, highlighting ★ in yellow when colors exist."""
import curses
star_attr = curses.color_pair(2) if curses.has_colors() else curses.A_NORMAL
segments = []
for i, part in enumerate(text.split("★")):
@@ -201,7 +197,6 @@ def _draw_radio_item(
stdscr, y: int, x: int, item: RadioItem, max_x: int, *, is_cursor: bool) -> None:
"""Draw a plain or segmented radiolist item starting at column ``x``."""
import curses
if isinstance(item, str):
attr = _curses_style_attr(curses, None, is_cursor=is_cursor)
_addnstr(stdscr, y, x, item, max(0, max_x - 1 - x), attr)
@@ -215,7 +210,6 @@ def _draw_radio_item(
def _draw_plain_row(stdscr, y: int, line: str, max_x: int, *, is_cursor: bool) -> None:
"""Draw a plain menu row, bold green when it is the cursor row."""
import curses
_addnstr(stdscr, y, 0, line, max_x - 1, _curses_style_attr(curses, None, is_cursor=is_cursor))
@@ -462,7 +456,6 @@ def _decode_escape_sequence(stdscr) -> str:
def _decode_menu_key(stdscr, key: int) -> str:
"""Normalize an already-read keypress to a menu action (lets loops peek the raw key first)."""
import curses
plain = {
curses.KEY_UP: NAV_UP, ord("k"): NAV_UP, curses.KEY_DOWN: NAV_DOWN, ord("j"): NAV_DOWN,
curses.KEY_LEFT: NAV_BACK, 3: NAV_INTERRUPT, # 3 = Ctrl+C in raw/cbreak mode