The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(models): preserve discovery provenance and endpoint identity
Vadelma7e61bd38c63a
diff --git a/hermes_cli/config.py b/hermes_cli/config.pyindex 0b7a68a2d9b..ccfdb406eba 100644--- a/hermes_cli/config.py+++ b/hermes_cli/config.py@@ -1485,7 +1485,10 @@ def _normalize_custom_provider_entry(}normalized_models[model_id.strip()] = model_metaif normalized_models:- normalized_models["__explicit_model_allowlist__"] = True+ if normalized_models.get("__discovered_model_catalog__"):+ normalized_models.pop("__explicit_model_allowlist__", None)+ else:+ normalized_models["__explicit_model_allowlist__"] = Truenormalized["models"] = normalized_modelscontext_length = entry.get("context_length")diff --git a/hermes_cli/model_switch.py b/hermes_cli/model_switch.pyindex e2a7baeaf90..779cce08706 100644--- a/hermes_cli/model_switch.py+++ b/hermes_cli/model_switch.py@@ -88,7 +88,10 @@ def _declared_model_ids(value: Any) -> list[str]:if isinstance(value, dict):for model_id in value:- if model_id == "__explicit_model_allowlist__":+ if model_id in {+ "__explicit_model_allowlist__",+ "__discovered_model_catalog__",+ }:continue_add(model_id)return ids@@ -126,14 +129,21 @@ def _models_config_is_allowlist(value: Any) -> bool:if isinstance(value, str):return bool(value.strip())if isinstance(value, dict):- return bool(value.get("__explicit_model_allowlist__"))+ return bool(+ value.get("__explicit_model_allowlist__")+ and not value.get("__discovered_model_catalog__")+ )if isinstance(value, (list, tuple)):return bool(_declared_model_ids(value))return Falsedef _save_discovered_models_to_config(- api_url: str, model_ids: list[str]+ api_url: str,+ model_ids: list[str],+ *,+ api_mode: Optional[str] = None,+ headers: Optional[dict[str, str]] = None,) -> None:"""Persist discovered models into ``custom_providers`` in config.yaml.@@ -160,9 +170,18 @@ def _save_discovered_models_to_config(for entry in providers:if not isinstance(entry, dict):continue- entry_url = (entry.get("base_url", "") or entry.get("url", "") or "").strip()+ entry_url = (entry.get("base_url", "") or entry.get("url", "")).strip()if entry_url.rstrip("/").lower() != norm_url:continue+ entry_mode = str(+ entry.get("api_mode") or entry.get("transport") or ""+ ).strip().lower() or None+ if entry_mode != api_mode:+ continue+ if headers is not None:+ entry_headers = _extra_headers_from_config(entry)+ if entry_headers != headers:+ continueexisting = entry.get("models")# Preserve per-model metadata: when ``models`` is a mapping# (e.g. ``{"model-a": {"context_length": 8192}}``) or a list of@@ -178,7 +197,10 @@ def _save_discovered_models_to_config(# config writes on every picker open.if isinstance(existing, list) and existing == model_ids:continue- entry["models"] = model_ids+ entry["models"] = {+ "__discovered_model_catalog__": True,+ **{model_id: {} for model_id in model_ids},+ }changed = Trueif changed:@@ -1650,7 +1672,13 @@ def switch_model(# is already in vendor/model format and the colon is a variant# tag (:free, :extended, :fast) that must be preserved.colon_pos = raw_input.find(":")- if colon_pos > 0 and "/" not in raw_input and is_aggregator(current_provider):+ if (+ colon_pos > 0+ and "/" not in raw_input+ and is_aggregator(current_provider)+ and not str(current_provider).strip().lower().startswith("custom")+ and str(current_provider).strip().lower() != "ollama"+ ):left = raw_input[:colon_pos].strip().lower()right = raw_input[colon_pos + 1:].strip()if left and right:@@ -3738,7 +3766,12 @@ def list_authenticated_providers(native_catalog_empty = not live_modelsgrp["models"] = live_modelsgrp["total_models"] = len(live_models)- _save_discovered_models_to_config(api_url, live_models)+ _save_discovered_models_to_config(+ api_url,+ live_models,+ api_mode=grp.get("api_mode"),+ headers=grp.get("extra_headers") or None,+ )except _MODEL_DISCOVERY_ERRORS:passelif _discovery_allowed:diff --git a/tests/hermes_cli/test_model_switch_custom_providers.py b/tests/hermes_cli/test_model_switch_custom_providers.pyindex 9272de95e37..13dc8737f24 100644--- a/tests/hermes_cli/test_model_switch_custom_providers.py+++ b/tests/hermes_cli/test_model_switch_custom_providers.py@@ -1409,7 +1409,7 @@ def test_discovered_models_auto_saved_to_cache(monkeypatch):monkeypatch.setattr("hermes_cli.models.fetch_api_models", fake_fetch_api_models)monkeypatch.setattr("hermes_cli.model_switch._save_discovered_models_to_config",- lambda api_url, model_ids: save_calls.append((api_url, model_ids)),+ lambda api_url, model_ids, **kwargs: save_calls.append((api_url, model_ids)),)custom_providers = [@@ -1521,7 +1521,7 @@ def test_model_flow_named_custom_persists_discovered_models(monkeypatch):save_calls = []monkeypatch.setattr("hermes_cli.model_switch._save_discovered_models_to_config",- lambda api_url, model_ids: save_calls.append((api_url, model_ids)),+ lambda api_url, model_ids, **kwargs: save_calls.append((api_url, model_ids)),)from hermes_cli.model_setup_flows import _model_flow_named_custom@@ -1881,7 +1881,7 @@ def test_cached_catalog_is_not_written_back_to_config(monkeypatch):saves = []monkeypatch.setattr("hermes_cli.model_switch._save_discovered_models_to_config",- lambda api_url, model_ids: saves.append((api_url, model_ids)),+ lambda api_url, model_ids, **kwargs: saves.append((api_url, model_ids)),)row, _ = _no_probe_local_row(@@ -2075,7 +2075,8 @@ def test_auto_saved_catalog_round_trips_without_pinning(tmp_path, monkeypatch):_save_discovered_models_to_config(_LOCAL_ENDPOINT, list(_LOCAL_CATALOG))saved = yaml.safe_load(cfg_path.read_text())["custom_providers"][0]- assert saved["models"] == _LOCAL_CATALOG, "probe result should be persisted"+ assert saved["models"]["__discovered_model_catalog__"] is True+ assert [m for m in saved["models"] if not m.startswith("__")] == _LOCAL_CATALOG# The persisted shape is what the picker will read on the next open. It# must not, on a keyless entry, suppress discovery of a wider catalog.