refactor(hermes_cli): squeeze blank lines after lazy imports (AST-neutral)
This commit is contained in:
@@ -12,7 +12,6 @@ import sys
|
||||
|
||||
def _cmd_memory_off():
|
||||
from hermes_cli.config import load_config, save_config
|
||||
|
||||
config = load_config()
|
||||
if not isinstance(config.get("memory"), dict):
|
||||
config["memory"] = {}
|
||||
@@ -24,7 +23,6 @@ def _cmd_memory_off():
|
||||
|
||||
def _cmd_memory_reset(args):
|
||||
from hermes_constants import get_hermes_home, display_hermes_home
|
||||
|
||||
mem_dir = get_hermes_home() / "memories"
|
||||
target = getattr(args, "target", "all")
|
||||
files_to_reset = []
|
||||
@@ -69,7 +67,6 @@ def cmd_memory(args):
|
||||
_cmd_memory_reset(args)
|
||||
else:
|
||||
from hermes_cli.memory_setup import memory_command
|
||||
|
||||
memory_command(args)
|
||||
|
||||
|
||||
@@ -86,7 +83,6 @@ def cmd_acp(args):
|
||||
"""Launch Hermes Agent as an ACP server."""
|
||||
try:
|
||||
from acp_adapter.entry import main as acp_main
|
||||
|
||||
acp_main([flag for attr, flag in _ACP_FLAGS if getattr(args, attr, False)])
|
||||
except ImportError:
|
||||
print("ACP dependencies not installed.", file=sys.stderr)
|
||||
@@ -99,16 +95,13 @@ def cmd_tools(args):
|
||||
action = getattr(args, "tools_action", None)
|
||||
if action in {"list", "disable", "enable"}:
|
||||
from hermes_cli.tools_config import tools_disable_enable_command
|
||||
|
||||
tools_disable_enable_command(args)
|
||||
elif action == "post-setup":
|
||||
from hermes_cli.tools_config import run_post_setup_command
|
||||
|
||||
sys.exit(run_post_setup_command(args))
|
||||
else:
|
||||
_require_tty("tools")
|
||||
from hermes_cli.tools_config import tools_command
|
||||
|
||||
tools_command(args)
|
||||
|
||||
|
||||
@@ -117,7 +110,6 @@ def cmd_insights(args):
|
||||
try:
|
||||
from hermes_state import SessionDB
|
||||
from agent.insights import InsightsEngine
|
||||
|
||||
db = SessionDB()
|
||||
engine = InsightsEngine(db)
|
||||
report = engine.generate(days=args.days, source=args.source)
|
||||
@@ -139,13 +131,11 @@ def _dict_or_empty(value) -> dict:
|
||||
def cmd_monitoring(args):
|
||||
"""Gateway monitoring status: health & diagnostics export posture."""
|
||||
from hermes_cli.config import load_config
|
||||
|
||||
action = getattr(args, "monitoring_action", None) or "status"
|
||||
mon = _dict_or_empty(load_config().get("monitoring"))
|
||||
|
||||
if action == "status":
|
||||
from agent.monitoring import otlp_exporter
|
||||
|
||||
gh = _dict_or_empty(mon.get("gateway_health_export"))
|
||||
otlp = _dict_or_empty(_dict_or_empty(mon.get("export")).get("otlp"))
|
||||
|
||||
@@ -181,13 +171,11 @@ def cmd_skills(args):
|
||||
if action == "config":
|
||||
_require_tty("skills config")
|
||||
from hermes_cli.skills_config import skills_command as skills_config_command
|
||||
|
||||
skills_config_command(args)
|
||||
elif action in ("trust", "untrust"):
|
||||
_cmd_skills_trust(args)
|
||||
else:
|
||||
from hermes_cli.skills_hub import skills_command
|
||||
|
||||
skills_command(args)
|
||||
|
||||
|
||||
@@ -198,14 +186,12 @@ def _cmd_skills_trust(args):
|
||||
(nearest ancestor with ``.git``).
|
||||
"""
|
||||
from pathlib import Path
|
||||
|
||||
from agent.skill_utils import (
|
||||
PROJECT_SKILLS_SUBDIRS,
|
||||
_candidate_project_skills_dirs,
|
||||
find_project_root,
|
||||
iter_skill_index_files)
|
||||
from hermes_cli.config import load_config, save_config
|
||||
|
||||
action = args.skills_action
|
||||
raw_path = getattr(args, "path", None)
|
||||
if raw_path:
|
||||
|
||||
@@ -32,7 +32,6 @@ def _pyproject_project(debug_fmt: str | None = None) -> dict | None:
|
||||
return None
|
||||
try:
|
||||
import tomllib
|
||||
|
||||
with pyproject.open("rb") as handle:
|
||||
project = tomllib.load(handle).get("project", {})
|
||||
except Exception as exc:
|
||||
@@ -58,7 +57,6 @@ def _parse_requirements(raw_deps: list[str]) -> list[tuple[str, "object | None",
|
||||
parsed: list[tuple[str, "object | None", str]] = []
|
||||
try:
|
||||
from packaging.requirements import Requirement # type: ignore
|
||||
|
||||
for spec in raw_deps:
|
||||
try:
|
||||
req = Requirement(spec)
|
||||
@@ -283,7 +281,6 @@ def _recover_core_update_marker_locked() -> None:
|
||||
# ensure_uv bootstraps the installer itself when missing (the early pass's
|
||||
# stdlib-only lookup cannot), so a venv whose uv vanished mid-update still heals.
|
||||
from hermes_cli.managed_uv import ensure_uv
|
||||
|
||||
ensure_uv()
|
||||
|
||||
# Shared stdlib executor: this late path and the pre-import early pass run exactly
|
||||
@@ -358,7 +355,6 @@ def _windows_shim_in_process_chain() -> Path | None:
|
||||
|
||||
try:
|
||||
import psutil
|
||||
|
||||
me = psutil.Process()
|
||||
for proc in [me] + list(me.parents()):
|
||||
try:
|
||||
@@ -412,7 +408,6 @@ def _reexec_dependency_sync_off_windows_shim() -> bool:
|
||||
return False
|
||||
|
||||
from hermes_constants import venv_python_path
|
||||
|
||||
python_exe = venv_python_path(shim.parent.parent, windows=True)
|
||||
cmd = [str(python_exe), "-m", "hermes_cli.main", *sys.argv[1:]]
|
||||
if python_exe.is_file():
|
||||
@@ -439,13 +434,11 @@ def _default_venv_install_target() -> tuple[list[str], dict[str, str] | None]:
|
||||
from hermes_cli.main import PROJECT_ROOT, _is_termux_env
|
||||
try:
|
||||
from hermes_cli.managed_uv import ensure_uv
|
||||
|
||||
uv_bin = ensure_uv()
|
||||
except Exception:
|
||||
uv_bin = None
|
||||
if uv_bin:
|
||||
from hermes_constants import project_venv_dir
|
||||
|
||||
venv_dir = project_venv_dir(PROJECT_ROOT) or PROJECT_ROOT / "venv"
|
||||
env = {**os.environ, "VIRTUAL_ENV": str(venv_dir)}
|
||||
if _is_termux_env(env):
|
||||
@@ -511,7 +504,6 @@ def _venv_scripts_dir() -> Path | None:
|
||||
"""Return the venv Scripts directory if we're running inside the project venv."""
|
||||
from hermes_cli.main import PROJECT_ROOT, _is_windows
|
||||
from hermes_constants import project_venv_dir, venv_bin_dir
|
||||
|
||||
venv_dir = project_venv_dir(PROJECT_ROOT)
|
||||
if venv_dir is None:
|
||||
return None
|
||||
@@ -649,7 +641,6 @@ def _cleanup_pending_shim_renames(scripts_dir: Path) -> int:
|
||||
return 0
|
||||
try:
|
||||
import winreg
|
||||
|
||||
with winreg.OpenKey(
|
||||
winreg.HKEY_LOCAL_MACHINE, _PENDING_RENAME_KEY, 0,
|
||||
winreg.KEY_QUERY_VALUE | winreg.KEY_SET_VALUE,
|
||||
@@ -970,7 +961,6 @@ def _interpreter_scripts_dir() -> Path | None:
|
||||
"""
|
||||
from hermes_cli.main import _is_windows
|
||||
from hermes_constants import venv_bin_dir
|
||||
|
||||
exe = Path(sys.executable)
|
||||
# sys.executable lives IN the bin/Scripts dir; parent.parent is the env root.
|
||||
cand = venv_bin_dir(exe.parent.parent, windows=_is_windows())
|
||||
@@ -1216,7 +1206,6 @@ def _resolve_install_target_python(
|
||||
from hermes_cli.main import _is_windows
|
||||
if env and "VIRTUAL_ENV" in env:
|
||||
from hermes_constants import venv_python_path
|
||||
|
||||
candidate = venv_python_path(Path(env["VIRTUAL_ENV"]), windows=_is_windows())
|
||||
if candidate.exists():
|
||||
return candidate
|
||||
@@ -1253,7 +1242,6 @@ def _resolve_node_runtime_npm() -> str | None:
|
||||
"""
|
||||
from hermes_cli.main import _is_windows
|
||||
from hermes_constants import find_node_executable
|
||||
|
||||
npm = find_node_executable("npm")
|
||||
if _is_windows():
|
||||
return npm
|
||||
|
||||
@@ -123,7 +123,6 @@ def apply_managed_overlay(config: dict) -> dict:
|
||||
return config
|
||||
# Imported lazily to avoid an import cycle (config imports managed_scope).
|
||||
from hermes_cli.config import _deep_merge, _expand_env_vars, _normalize_root_model_keys
|
||||
|
||||
managed_expanded = _normalize_root_model_keys(_expand_env_vars(managed))
|
||||
# _normalize_root_model_keys only promotes the string when root provider/base_url
|
||||
# keys exist to migrate; handle the bare case here (matches cli.py) so _deep_merge
|
||||
|
||||
@@ -43,7 +43,6 @@ def _config_settings() -> tuple[bool, float, int, float]:
|
||||
# cooldown check), and a full-config deepcopy per attempt is exactly the
|
||||
# allocator garbage this module exists to release.
|
||||
from hermes_cli.config import load_config_readonly
|
||||
|
||||
config = load_config_readonly() or {}
|
||||
context = config.get("context") if isinstance(config, dict) else None
|
||||
settings = context.get("memory_trim") if isinstance(context, dict) else None
|
||||
|
||||
@@ -94,5 +94,4 @@ def cmd_migrate_xai(args: Any) -> int:
|
||||
def _resolve_config_path() -> Path:
|
||||
"""Best-effort: locate the active config.yaml on disk."""
|
||||
from hermes_cli.config import get_hermes_home
|
||||
|
||||
return get_hermes_home() / "config.yaml"
|
||||
|
||||
Reference in New Issue
Block a user