The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(moa): drop PyYAML from the deletion tests and offset config.py growth
Brooklyn Nicholsonee91fdc84d0a
diff --git a/hermes_cli/config.py b/hermes_cli/config.pyindex 7fc80a65641..c899458eab0 100644--- a/hermes_cli/config.py+++ b/hermes_cli/config.py@@ -1882,26 +1882,6 @@ def _canonicalize_config(config: Dict[str, Any]) -> Dict[str, Any]:return _normalize_root_model_keys(_normalize_max_turns_config(config))-def _apply_user_moa_presets(merged: Dict[str, Any], raw: Dict[str, Any]) -> None:- """Treat an explicit user MoA preset map as authoritative.-- ``moa.presets`` is a named map. Generic default merging must not union the- schema's built-in names into a user map, because that resurrects presets- the user deleted. An omitted ``moa.presets`` key still receives defaults;- an explicit empty map remains empty.- """- raw_moa = raw.get("moa") if isinstance(raw, dict) else None- if not isinstance(raw_moa, dict) or "presets" not in raw_moa:- return- raw_presets = raw_moa.get("presets")- if not isinstance(raw_presets, dict):- return- merged_moa = merged.get("moa")- if not isinstance(merged_moa, dict):- return- merged_moa["presets"] = copy.deepcopy(raw_presets)--# Sentinel for an unlimited turn budget. ``sys.maxsize`` survives the str->int round-trip through# the HERMES_MAX_ITERATIONS env bridge, works in every ``<``/``>=``/``max - used`` comparison in# the iteration budget without an "unlimited" special case, and is unreachable in practice.@@ -2314,10 +2294,11 @@ def _last_known_good_fallback(config_path: Path, path_key: str, cache_sig, exc:# It holds the raw file (``${VAR}`` templates intact), so it goes through the same# canonicalize -> expand -> managed-overlay pipeline as a normal load.from hermes_cli.config_backups import load_newest_good_backup+ from hermes_cli.moa_config import apply_user_moa_presetsraw_good = load_newest_good_backup(config_path)if raw_good is not None:merged_good = _deep_merge(copy.deepcopy(DEFAULT_CONFIG), raw_good)- _apply_user_moa_presets(merged_good, raw_good)+ apply_user_moa_presets(merged_good, raw_good)normalized = _canonicalize_config(merged_good)expanded_good: Dict[str, Any] = _expand_env_vars(normalized) # type: ignore[assignment]lkg, _ = _merge_managed_overlay(expanded_good)@@ -2425,7 +2406,8 @@ def _load_config_impl(*, want_deepcopy: bool) -> Dict[str, Any]:user_config.pop("max_turns", None)config = _deep_merge(config, user_config)- _apply_user_moa_presets(config, user_config)+ from hermes_cli.moa_config import apply_user_moa_presets+ apply_user_moa_presets(config, user_config)# A copy of the file that just parsed is what a FRESH process falls back to when the# next edit breaks the YAML (see _last_known_good_fallback). backup_config() skips# byte-identical repeats and keeps a bounded count, so steady-state loads cost one stat.diff --git a/hermes_cli/moa_config.py b/hermes_cli/moa_config.pyindex 74365438565..66559bb6e3b 100644--- a/hermes_cli/moa_config.py+++ b/hermes_cli/moa_config.py@@ -291,6 +291,27 @@ def resolve_moa_preset(config: Any, name: str | None = None) -> dict[str, Any]:return deepcopy(preset)+def apply_user_moa_presets(merged: dict[str, Any], raw: Any) -> None:+ """Treat an explicit user MoA preset map as authoritative.++ ``moa.presets`` is a named map. Generic default merging must not union the+ schema's built-in names into a user map, because that resurrects presets+ the user deleted. An omitted ``moa.presets`` key still receives defaults;+ an explicit empty map remains empty. Called by the config load/merge paths+ right after ``_deep_merge``.+ """+ raw_moa = raw.get("moa") if isinstance(raw, dict) else None+ if not isinstance(raw_moa, dict) or "presets" not in raw_moa:+ return+ raw_presets = raw_moa.get("presets")+ if not isinstance(raw_presets, dict):+ return+ merged_moa = merged.get("moa")+ if not isinstance(merged_moa, dict):+ return+ merged_moa["presets"] = deepcopy(raw_presets)++def exact_moa_preset_name(config: Any, text: str) -> str | None:"""Return the preset name iff ``text`` exactly matches an *enabled* preset.diff --git a/tests/hermes_cli/test_moa_preset_deletion.py b/tests/hermes_cli/test_moa_preset_deletion.pyindex 0cb491cc40e..0ae43a5e297 100644--- a/tests/hermes_cli/test_moa_preset_deletion.py+++ b/tests/hermes_cli/test_moa_preset_deletion.py@@ -23,7 +23,6 @@ import threadingfrom pathlib import Pathimport pytest-import yamlfrom hermes_cli.web_models import MoaConfigPayload, MoaModelSlot, MoaPresetPayloadfrom hermes_cli.web_routers.models import set_moa_models@@ -38,12 +37,17 @@ def _preset(model: str) -> MoaPresetPayload:def _on_disk(home) -> dict:- return yaml.safe_load((home / "config.yaml").read_text(encoding="utf-8")) or {}+ from ruamel.yaml import YAML++ return YAML(typ="rt").load((home / "config.yaml").read_text(encoding="utf-8")) or {}def _seed(home, monkeypatch, moa: dict, **sections) -> None:+ from ruamel.yaml import YAML+monkeypatch.setenv("HERMES_HOME", str(home))- (home / "config.yaml").write_text(yaml.safe_dump({"moa": moa, **sections}), encoding="utf-8")+ with (home / "config.yaml").open("w", encoding="utf-8") as fh:+ YAML(typ="rt").dump({"moa": moa, **sections}, fh)def _three_presets() -> dict: