The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(model-switch): split YYYYMMDD date stamps from version tuple in _model_sort_key
Sohom Sahaun21bc9ba341a6
diff --git a/contributors/emails/[email protected] b/contributors/emails/[email protected]new file mode 100644index 00000000000..e69de29bb2ddiff --git a/hermes_cli/model_switch.py b/hermes_cli/model_switch.pyindex a5d7273d336..35b758c45d2 100644--- a/hermes_cli/model_switch.py+++ b/hermes_cli/model_switch.py@@ -884,8 +884,24 @@ def _model_sort_key(model_id: str, prefix: str) -> tuple:suffix = suffix_buf.lower().strip("-_.")suffix = suffix.strip()+ # Split out YYYYMMDD date stamps (e.g. claude-opus-4-20250514): they are+ # snapshot markers, not version components, and would otherwise dwarf+ # real point versions (20250514 > 8). Kept as a trailing tiebreaker so+ # bare IDs sort before their dated snapshots, and newer snapshots before+ # older ones. The 19_000_101 threshold reclassifies only 8-digit stamps,+ # so shorter numeric components (mistral-large-2411, gpt-4-0613) keep+ # their current behavior.+ version_nums: list[float] = []+ date_stamp = 0.0+ for n in nums:+ if n >= 19_000_101:+ date_stamp = max(date_stamp, n)+ else:+ version_nums.append(n)+# Negate versions so higher → sorts first- version_key = tuple(-n for n in nums)+ version_key = tuple(-n for n in version_nums)+ date_key = (0.0, 0.0) if date_stamp == 0.0 else (1.0, -date_stamp)# Suffix quality ranking: pro/max > (no suffix) > omni/flash/mini/lite# Lower number = preferred@@ -897,7 +913,7 @@ def _model_sort_key(model_id: str, prefix: str) -> tuple:_SUFFIX_RANK = {"pro": 0, "max": 0, "plus": 0, "turbo": 0, "sol": 0}suffix_rank = _SUFFIX_RANK.get(suffix, 1)- return version_key + (suffix_rank, suffix)+ return version_key + (suffix_rank, suffix) + date_keydef resolve_alias(diff --git a/tests/hermes_cli/test_ollama_cloud_auth.py b/tests/hermes_cli/test_ollama_cloud_auth.pyindex 24e8e753bf4..d6eba2a1c82 100644--- a/tests/hermes_cli/test_ollama_cloud_auth.py+++ b/tests/hermes_cli/test_ollama_cloud_auth.py@@ -278,6 +278,43 @@ class TestResolveAliasEdgeCases:assert result[1] == "my-model"+# ---------------------------------------------------------------------------+# resolve_alias: sort-key date-stamp handling+# ---------------------------------------------------------------------------++class TestResolveAliasSorting:+ """resolve_alias must pick the highest-version model, correctly+ ignoring YYYYMMDD snapshot stamps that would otherwise dwarf real+ version numbers (e.g. claude-opus-4-20250514 vs claude-opus-4-8)."""++ def test_anthropic_opus_picks_latest(self, monkeypatch):+ """Date-stamped snapshot ID must not outrank a higher point version."""+ import hermes_cli.model_switch as ms++ monkeypatch.setattr(ms, "_ensure_direct_aliases", lambda: None)+ monkeypatch.setattr(ms, "DIRECT_ALIASES", {})+ monkeypatch.setattr(ms, "list_provider_models",+ lambda p: ["claude-opus-4-1", "claude-opus-4-7",+ "claude-opus-4-8",+ "claude-opus-4-20250514"])+ result = ms.resolve_alias("opus", "anthropic")+ assert result is not None and result[1] == "claude-opus-4-8"++ def test_unsynced_new_model_wins(self, monkeypatch):+ """A just-released model missing from models.dev still outranks+ older, dated siblings (static _PROVIDER_MODELS merge scenario)."""+ import hermes_cli.model_switch as ms++ monkeypatch.setattr(ms, "_ensure_direct_aliases", lambda: None)+ monkeypatch.setattr(ms, "DIRECT_ALIASES", {})+ monkeypatch.setattr(ms, "list_provider_models",+ lambda p: ["claude-opus-4-7", "claude-opus-4-8",+ "claude-opus-4-20250514",+ "claude-opus-4-9"])+ result = ms.resolve_alias("opus", "anthropic")+ assert result is not None and result[1] == "claude-opus-4-9"++# ---------------------------------------------------------------------------# switch_model: direct alias base_url override# ---------------------------------------------------------------------------