Skip to content

The agent that grows with you

refactor(hermes_cli): model_switch_providers defensive-layer collapse; moa_cmd tidy

Teknium8b7c584a27dc
diff --git a/hermes_cli/moa_cmd.py b/hermes_cli/moa_cmd.py
index dcf89d17266..46a28b3518a 100644
--- a/hermes_cli/moa_cmd.py
+++ b/hermes_cli/moa_cmd.py
@@ -70,8 +70,7 @@ def _print_config(config: dict[str, Any]) -> None:
print(f"Default: {cfg['default_preset']}")
print(f"Active in config: {cfg.get('active_preset') or '(off)'}")
for name, preset in cfg["presets"].items():
- marker = "*" if name == cfg["default_preset"] else " "
- print(f"\n{marker} {name}")
+ print(f"\n{'*' if name == cfg['default_preset'] else ' '} {name}")
print(" Reference models:")
for idx, slot in enumerate(preset["reference_models"], start=1):
print(f" {idx}. {_format_slot(slot)}")
diff --git a/hermes_cli/moa_config.py b/hermes_cli/moa_config.py
index 67e14099e55..458415d1651 100644
--- a/hermes_cli/moa_config.py
+++ b/hermes_cli/moa_config.py
@@ -204,7 +204,6 @@ def validate_moa_payload(raw: Any) -> list[str]:
agg_issue = _slot_problem(preset.get("aggregator"))
if agg_issue:
problems.append(f"preset '{label}' aggregator: {agg_issue}")
-
return problems
@@ -215,7 +214,6 @@ def _normalize_preset(raw: Any) -> dict[str, Any]:
cleaned = (_clean_slot(item, include_enabled=True) for item in _reference_slots(raw.get("reference_models")))
refs = [item for item in cleaned if item is not None]
policy = str(raw.get("degraded_reference_policy") or "loud").strip().lower()
-
return {
"enabled": _coerce_bool(raw.get("enabled"), True),
"reference_models": refs or _default_reference_models(),
@@ -268,7 +266,6 @@ def normalize_moa_config(raw: Any) -> dict[str, Any]:
active_name = str(raw.get("active_preset") or "").strip()
if active_name not in presets:
active_name = ""
-
return {
"default_preset": default_name,
"active_preset": active_name,
diff --git a/hermes_cli/model_switch.py b/hermes_cli/model_switch.py
index f01634ae847..189994c2532 100644
--- a/hermes_cli/model_switch.py
+++ b/hermes_cli/model_switch.py
@@ -355,7 +355,6 @@ def _may_reuse_session_credential(session_base_url: str, alias_base_url: str) ->
class StartupModelRoute(NamedTuple):
"""Model/provider pair resolved before an agent is constructed."""
-
model: str
provider: str = ""
base_url: str = ""
@@ -436,7 +435,6 @@ def resolve_startup_model_route(
@dataclass
class ModelSwitchResult:
"""Result of a model switch attempt."""
-
success: bool
new_model: str = ""
target_provider: str = ""
@@ -458,7 +456,6 @@ class ModelSwitchResult:
@dataclass(frozen=True)
class ModelFlagParseResult:
"""Parsed flags for a /model command."""
-
model_input: str
explicit_provider: str = ""
is_global: bool = False
@@ -499,7 +496,6 @@ def parse_model_flags_detailed(raw_args: str) -> ModelFlagParseResult:
else:
filtered.append(parts[i])
i += 1
-
return ModelFlagParseResult(model_input=" ".join(filtered).strip(), explicit_provider=explicit_provider, **flags)
@@ -563,7 +559,6 @@ class ModelSwitchRequest:
via :data:`MODEL_SWITCH_ERROR_TEXT`. ``model_input`` keeps it a drop-in for
:class:`ModelFlagParseResult` consumers.
"""
-
raw: str
target: str
explicit_provider: str = ""
@@ -601,7 +596,6 @@ def parse_model_switch_args(raw: str) -> ModelSwitchRequest:
# First matching flag wins: once > session > global > default.
scope = next((name for name, on in (("once", parsed.is_once), ("session", parsed.is_session),
("global", parsed.is_global)) if on), "default")
-
return ModelSwitchRequest(
raw=raw, target=parsed.model_input, explicit_provider=parsed.explicit_provider,
is_global=parsed.is_global, is_session=parsed.is_session, is_once=parsed.is_once,
@@ -717,7 +711,6 @@ class AmbiguousAliasError(Exception):
Raised by :func:`resolve_alias` instead of silently picking one via version-sort heuristics.
``candidates`` is sorted best-guess-first (see :func:`_model_sort_key`) for display only.
"""
-
def __init__(self, alias: str, provider: str, candidates: list[str]):
self.alias = alias
self.provider = provider
@@ -1091,7 +1084,6 @@ class _Switch:
resolves its block); the credential step fills ``api_key`` / ``base_url`` / ``api_mode`` /
``validation_headers``.
"""
-
raw_input: str
current_provider: str
current_model: str
@@ -1500,7 +1492,6 @@ def _build_switch_result(st: _Switch) -> ModelSwitchResult:
request_overrides = _custom_provider_request_overrides(cp_for_ro) or None if cp_for_ro else None
except Exception:
request_overrides = None
-
return ModelSwitchResult(
success=True, new_model=st.new_model, target_provider=st.target_provider,
provider_changed=st.provider_changed, api_key=st.api_key, base_url=st.base_url, api_mode=st.api_mode,
diff --git a/hermes_cli/model_switch_providers.py b/hermes_cli/model_switch_providers.py
index e9bc88ee472..fd84faef1e5 100644
--- a/hermes_cli/model_switch_providers.py
+++ b/hermes_cli/model_switch_providers.py
@@ -362,7 +362,6 @@ def _has_fast_aws_sdk_signal() -> bool:
"""
def _set(name: str) -> bool:
return bool(os.environ.get(name, "").strip())
-
return (
_set("AWS_BEARER_TOKEN_BEDROCK")
or (_set("AWS_ACCESS_KEY_ID") and _set("AWS_SECRET_ACCESS_KEY"))
@@ -595,7 +594,6 @@ class _PickerBuild:
3 ``providers:`` entries + 3b the bare active custom endpoint, 4 ``custom_providers:`` entries.
Every ``hermes_cli.auth/models`` import in the row builders stays lazy so tests can patch
those modules."""
-
current_provider: str
current_base_url: str
current_model: str
@@ -626,10 +624,7 @@ class _PickerBuild:
def record_builtin_endpoint(self, slug: str) -> None:
"""Prefer the live env override (e.g. DASHSCOPE_BASE_URL) over the static inference_base_url
so dedup matches what a user typing that URL into custom_providers would actually hit."""
- try:
- from hermes_cli.auth import PROVIDER_REGISTRY
- except Exception:
- return
+ from hermes_cli.auth import PROVIDER_REGISTRY
pcfg = PROVIDER_REGISTRY.get(slug)
if not pcfg:
return
@@ -717,7 +712,7 @@ def _overlay_has_creds(b: _PickerBuild, pid: str, hermes_slug: str, overlay) ->
"""Section-2 credential ladder: env/SDK, external-process executable, auth store, pool,
anthropic's external credential files."""
from hermes_cli.model_switch import _credential_pool_is_usable
- if getattr(overlay, "keyless", False):
+ if overlay.keyless:
return True # served anonymously (opencode-free)
if overlay.auth_type == "aws_sdk":
has_creds = _has_aws_sdk_creds_for_listing(hermes_slug, b.current_provider)
@@ -799,11 +794,7 @@ def _lap_overlay_rows(b: _PickerBuild, data: dict) -> None:
def _lap_canonical_rows(b: _PickerBuild) -> None:
"""Section 2b: CANONICAL_PROVIDERS missed by sections 1/2."""
from hermes_cli.auth import PROVIDER_REGISTRY
- try:
- from hermes_cli.models import CANONICAL_PROVIDERS
- except ImportError:
- CANONICAL_PROVIDERS = []
-
+ from hermes_cli.models import CANONICAL_PROVIDERS
for cp in CANONICAL_PROVIDERS:
if _skip(b.seen_slugs, b.excluded, cp.slug):
continue
@@ -1231,5 +1222,4 @@ def list_picker_providers(
is_custom_endpoint = bool(p.get("is_user_defined")) and bool(p.get("api_url"))
if p.get("models") or is_custom_endpoint:
filtered.append(p)
-
return filtered