The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(config): fix container type for unseeded roots, top-level lists and bare-name list slots
teknium19c088a7a78f5
diff --git a/hermes_cli/config.py b/hermes_cli/config.pyindex 79ea3181c31..6873e225fcd 100644--- a/hermes_cli/config.py+++ b/hermes_cli/config.py@@ -3427,37 +3427,50 @@ def _coerce_config_set_value(key: str, value: str) -> Any:return value-# Legacy roots absent from DEFAULT_CONFIG whose container type is nonetheless fixed.-_LEGACY_CONTAINER_TYPES = {"custom_providers": "list"}+# Container roots absent from DEFAULT_CONFIG whose shape is nonetheless fixed by their readers,+# so the guardrail holds before anything is on disk (#114471: `model.aliases notamap`).+_KNOWN_CONTAINER_TYPES = {+ "custom_providers": "list",+ "providers": "mapping",+ "model.aliases": "mapping",+ "model_aliases": "mapping",+}+# List slots whose readers go through ``parse_config_string_list``: a bare name is one entry.+_SCALAR_AS_ONE_ITEM_LIST_KEYS = frozenset({"agent.disabled_toolsets", "skills.disabled"})def _expected_container_type(key: str, user_config: Dict[str, Any]) -> Optional[str]:- """``"list"`` / ``"mapping"`` when the schema (``DEFAULT_CONFIG``, the legacy-root table, or- the value already on disk) fixes *key* to a container; ``None`` for scalars and open paths.- Single-segment keys skip the schema lookup: replacing a whole section is- ``_guard_section_overwrite``'s call (``--force``, the bare ``model`` shorthand)."""+ """``"list"`` / ``"mapping"`` when the schema (``DEFAULT_CONFIG``, the known-container table,+ or the value already on disk) fixes *key* to a container; ``None`` for scalars and open paths.+ A single-segment key that is a mapping *section* in the schema skips the lookup: replacing a+ whole section is ``_guard_section_overwrite``'s call (``--force``, the bare ``model`` shorthand)."""parts = _split_key_path(key)- schema_node = cfg_get(DEFAULT_CONFIG, *parts) if len(parts) > 1 else None+ schema_node = cfg_get(DEFAULT_CONFIG, *parts)+ if len(parts) == 1 and isinstance(schema_node, dict):+ schema_node = Noneexisting = _get_nested(user_config, key)- for node in (schema_node, _LEGACY_CONTAINER_TYPES.get(key), existing):- if isinstance(node, dict):+ for node in (schema_node, _KNOWN_CONTAINER_TYPES.get(key), existing):+ if isinstance(node, dict) or node == "mapping":return "mapping"if isinstance(node, list) or node == "list":return "list"return None-def _refuse_container_type_mismatch(key: str, value: Any, user_config: Dict[str, Any], force: bool) -> None:+def _refuse_container_type_mismatch(key: str, value: Any, user_config: Dict[str, Any], force: bool) -> Any:"""Hard guardrail: never store a value of the wrong shape where the schema wants a list or amapping — every reader would ignore it while ``config get`` echoed it back. ``--force`` keepsits documented meaning (replace a whole mapping section); a non-list in a list slot is never- readable, so it has no override."""+ readable, so it has no override. Returns the value to store: a bare name for a+ ``parse_config_string_list``-read slot becomes a one-item list."""expected = _expected_container_type(key, user_config)if expected is None:- return+ return value+ if expected == "list" and isinstance(value, str) and key in _SCALAR_AS_ONE_ITEM_LIST_KEYS:+ return [value]ok = isinstance(value, list) if expected == "list" else isinstance(value, dict)if ok or (expected == "mapping" and force):- return+ return valuegot = type(value).__name__ if not isinstance(value, str) else "string"literal = "[item, ...]" if expected == "list" else "{key: value}"_exit_invalid(@@ -3648,7 +3661,7 @@ def set_config_value(key: str, value: str, force: bool = False):if key.strip().lower().startswith("model.") and isinstance(_model_val, str) and _model_val:user_config["model"] = {"default": _model_val}key = _guard_section_overwrite(key, value, user_config, force)- _refuse_container_type_mismatch(key, value, user_config, force)+ value = _refuse_container_type_mismatch(key, value, user_config, force)try:_set_nested(user_config, key, value)except ValueError as e:diff --git a/tests/hermes_cli/test_set_config_value.py b/tests/hermes_cli/test_set_config_value.pyindex bb963026097..2e59b4be939 100644--- a/tests/hermes_cli/test_set_config_value.py+++ b/tests/hermes_cli/test_set_config_value.py@@ -1067,3 +1067,26 @@ class TestContainerTypeRefusal:saved = _yaml.safe_load(_read_config(_isolated_hermes_home))assert saved["custom_providers"] == [{"name": "ok", "base_url": "http://h/v1"}]assert saved["model"] == {"default": "bar", "aliases": "replaced"}++ @pytest.mark.parametrize("key", ["model.aliases", "providers", "toolsets"])+ def test_unseeded_or_top_level_container_key_is_refused_without_on_disk_value(+ self, _isolated_hermes_home, key):+ # #114471 writer atom: the shape is fixed by the readers, not by what is on disk yet.+ self._write_config(_isolated_hermes_home, {"model": {"default": "m"}})++ with pytest.raises(SystemExit):+ set_config_value(key, "notacontainer")++ import yaml as _yaml+ saved = _yaml.safe_load(_read_config(_isolated_hermes_home))+ assert saved == {"model": {"default": "m"}}++ def test_bare_name_for_string_list_slot_is_stored_as_one_item_list(self, _isolated_hermes_home):+ # agent.disabled_toolsets readers accept a bare name (parse_config_string_list); keep it writable.+ self._write_config(_isolated_hermes_home, {"model": {"default": "m"}})++ set_config_value("agent.disabled_toolsets", "web")++ import yaml as _yaml+ saved = _yaml.safe_load(_read_config(_isolated_hermes_home))+ assert saved["agent"]["disabled_toolsets"] == ["web"]diff --git a/website/docs/reference/cli-commands.md b/website/docs/reference/cli-commands.mdindex e2c282c3914..393129fe9e8 100644--- a/website/docs/reference/cli-commands.md+++ b/website/docs/reference/cli-commands.md@@ -1252,7 +1252,7 @@ Subcommands:| `show` | Show current config values. || `edit` | Open `config.yaml` in your editor. || `get <key> [--json] [--raw]` | Print a single config value by dotted key (e.g. `hermes config get model.default`). `--json` emits machine-readable output. Credential-shaped values (`api_key`, `*_TOKEN`, `*_SECRET`, `password`, …) are masked (`sk-o...7890`) because the agent runs this from sessions whose transcripts persist; `--raw` prints the real value (or set `security.redact_secrets: false`). A nested key under a known section that the schema does not define (`compression.compressor.enabled`) still prints its file value, plus a stderr notice that Hermes may not read it; stdout and the exit code (0) are unchanged. |-| `set <key> <value> [--force]` | Set a config value. Dotted paths go to `config.yaml`; every `UPPER_SNAKE` name (`OPENROUTER_API_KEY`, `DISCORD_HOME_CHANNEL`, `TELEGRAM_GROUP_ALLOWED_USERS`, `HERMES_TIMEZONE`, …) is an environment variable and goes to `.env` — the same file the platform setup flows and `/sethome` write, and the one every runtime reader resolves against. `config set` never writes an `UPPER_SNAKE` key into `config.yaml`, `--force` included; names on the env writer's denylist (`HERMES_YOLO_MODE`, `PATH`, …) are refused outright; any other `UPPER_SNAKE` name is saved to `.env` as-is (plugins, skills and external tools read it from the process environment). A known key written under the wrong prefix (`gateway.discord.foo`, where `discord.foo` is itself a known key) is refused with a did-you-mean and nothing is written; any other unknown path under a known section (`agent.max_turnz`, or a runtime-read key that has no seeded default) is written with a did-you-mean notice, and an unknown lowercase *top-level* key is written with a notice (top-level scalars are bridged into the environment for skills). `--force` writes the refused wrong-prefix path too. Values are type-checked against the schema: a key that must hold a list or a mapping (`custom_providers`, `model.aliases`, `display.platforms`, any key already holding one) refuses a plain string or a wrong-shaped literal, and a value that looks like a list/mapping but is not valid YAML/JSON is refused instead of being stored as a string — nothing is written and the error names the expected type. Pass a YAML/JSON literal (`hermes config set custom_providers '[{name: x, base_url: https://...}]'`); to store a string that merely starts with `[` or `{`, quote it in YAML (`"'[text'"`). `--force` still replaces a whole mapping section; a non-list in a list slot has no override. |+| `set <key> <value> [--force]` | Set a config value. Dotted paths go to `config.yaml`; every `UPPER_SNAKE` name (`OPENROUTER_API_KEY`, `DISCORD_HOME_CHANNEL`, `TELEGRAM_GROUP_ALLOWED_USERS`, `HERMES_TIMEZONE`, …) is an environment variable and goes to `.env` — the same file the platform setup flows and `/sethome` write, and the one every runtime reader resolves against. `config set` never writes an `UPPER_SNAKE` key into `config.yaml`, `--force` included; names on the env writer's denylist (`HERMES_YOLO_MODE`, `PATH`, …) are refused outright; any other `UPPER_SNAKE` name is saved to `.env` as-is (plugins, skills and external tools read it from the process environment). A known key written under the wrong prefix (`gateway.discord.foo`, where `discord.foo` is itself a known key) is refused with a did-you-mean and nothing is written; any other unknown path under a known section (`agent.max_turnz`, or a runtime-read key that has no seeded default) is written with a did-you-mean notice, and an unknown lowercase *top-level* key is written with a notice (top-level scalars are bridged into the environment for skills). `--force` writes the refused wrong-prefix path too. Values are type-checked against the schema: a key that must hold a list or a mapping (`custom_providers`, `model.aliases`, `display.platforms`, any key already holding one) refuses a plain string or a wrong-shaped literal, and a value that looks like a list/mapping but is not valid YAML/JSON is refused instead of being stored as a string — nothing is written and the error names the expected type. Pass a YAML/JSON literal (`hermes config set custom_providers '[{name: x, base_url: https://...}]'`); to store a string that merely starts with `[` or `{`, quote it in YAML (`"'[text'"`). `--force` still replaces a whole mapping section; a non-list in a list slot has no override, except that a bare name for a list of names read leniently (`agent.disabled_toolsets`, `skills.disabled`) is stored as a one-item list. || `unset <key>` | Remove a config key, reverting it to the built-in default. For `UPPER_SNAKE` names this removes the `.env` entry and also drops a stale top-level `config.yaml` copy left by older `config set` runs (`get` reports such a copy as stale). || `path` | Print the config file path. || `env-path` | Print the `.env` file path. |