diff --git a/hermes_cli/config.py b/hermes_cli/config.py index a00d37643bb20..3128e63c204c0 100644 --- a/hermes_cli/config.py +++ b/hermes_cli/config.py @@ -4866,14 +4866,21 @@ def set_config_value(key: str, value: str, force: bool = False): _existing = user_config.get(key) if isinstance(_existing, dict): if key == "model": - # Redirect bare-model shorthand to model.default while - # keeping every sibling mapping key intact. - key = "model.default" - print( - f"✓ Redirecting bare 'model' to 'model.default' " - f"(preserving {len(_existing)} existing model sub-key(s))" - ) - # value was already coerced above; proceed to _set_nested + if force: + # --force: allow destructive section overwrite. + print( + f"⚠ Replacing entire 'model' section with a scalar " + f"(discarding {len(_existing)} existing sub-key(s))" + ) + else: + # Redirect bare-model shorthand to model.default while + # keeping every sibling mapping key intact. + key = "model.default" + print( + f"✓ Redirecting bare 'model' to 'model.default' " + f"(preserving {len(_existing)} existing model sub-key(s))" + ) + # value was already coerced above; proceed to _set_nested elif not force: _sub = [k for k in _existing if isinstance(k, str)] print( diff --git a/tests/hermes_cli/test_set_config_value.py b/tests/hermes_cli/test_set_config_value.py index ec588453b51ce..a70e8ebe7491c 100644 --- a/tests/hermes_cli/test_set_config_value.py +++ b/tests/hermes_cli/test_set_config_value.py @@ -643,3 +643,17 @@ class TestMappingGuard: parsed = _yaml.safe_load(_read_config(_isolated_hermes_home)) assert parsed["model"]["default"] == "claude-opus-4" assert parsed["model"]["provider"] == "openai-api" + + def test_model_force_overwrites_entire_section(self, _isolated_hermes_home): + """hermes config set --force model → overwrite entire section.""" + self._write_config(_isolated_hermes_home, { + "model": { + "default": "gpt-4o", + "provider": "openai-api", + "context_length": 128_000, + } + }) + set_config_value("model", "claude-opus-4", force=True) + import yaml as _yaml + parsed = _yaml.safe_load(_read_config(_isolated_hermes_home)) + assert parsed["model"] == "claude-opus-4"