The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(config): flag schema-unknown nested keys in `hermes config get`
DavidMetcalfe5abda7e721c4
diff --git a/hermes_cli/config.py b/hermes_cli/config.pyindex 026e910ce35..65fe063c40e 100644--- a/hermes_cli/config.py+++ b/hermes_cli/config.py@@ -3524,6 +3524,31 @@ def _unknown_subkey_refusal(key: str, suggestion: Optional[str]) -> str:return "\n".join(lines)+def _is_unread_nested_key(key: str) -> bool:+ """True when *key* is a NESTED path under a known top-level section that the schema does not+ define (``compression.compressor.enabled``) — the phantom-key class ``config get`` must flag,+ because the value it echoes is read by nothing. Custom top-level keys are exempt: arbitrary+ top-level scalars are a supported feature (bridged into ``os.environ`` for skills/external+ tools), and open-subkey sections (``plugins``, ``custom_providers``, ...) accept any child."""+ segments = _split_key_path(key)+ if len(segments) < 2 or segments[0] not in _known_top_level_keys():+ return False+ return not _validate_config_key(key)[0]+++def _print_unread_key_notice(key: str) -> None:+ """Read-path mirror of ``_print_unknown_key_notice``: the value is echoed from the config file+ but nothing in the schema reads it, so it must not look like a live setting. Written to stderr+ so stdout stays parseable for tooling; the command still exits 0 — a notice must never turn a+ successful read into a failure."""+ _, suggestion = _validate_config_key(key)+ print(color(+ f"⚠ '{key}' is not a recognized config key — Hermes does not read it; the value printed "+ "above comes from your config file.", Colors.YELLOW), file=sys.stderr)+ if suggestion:+ print(color(f" Did you mean: {suggestion}", Colors.YELLOW), file=sys.stderr)++def set_config_value(key: str, value: str, force: bool = False):"""Set a configuration value at a dotted ``key``; ``value`` is auto-coerced to bool/int/float.``force`` writes an unknown path under a known section (otherwise refused), skips the@@ -3629,7 +3654,8 @@ def get_config_value(key: str, *, as_json: bool = False, raw: bool = False):this command from sessions whose transcripts persist (#84106, #110758)."""from hermes_cli.config_env_routing import is_env_setting_key, read_env_setting- if _is_env_config_key(key):+ is_env_key = _is_env_config_key(key)+ if is_env_key:env_value = get_env_value(key.upper())value = _MISSING if env_value is None else env_valueelif is_env_setting_key(key):@@ -3652,7 +3678,9 @@ def get_config_value(key: str, *, as_json: bool = False, raw: bool = False):else:value = redact_config_value(value)- print(_format_config_get_value(value, as_json=as_json))+ print(_format_config_get_value(value, as_json=as_json), flush=True)+ if not is_env_key and _is_unread_nested_key(key):+ _print_unread_key_notice(key)def unset_config_value(key: str):diff --git a/tests/hermes_cli/test_set_config_value.py b/tests/hermes_cli/test_set_config_value.pyindex 988a6d20515..35719defb61 100644--- a/tests/hermes_cli/test_set_config_value.py+++ b/tests/hermes_cli/test_set_config_value.py@@ -219,6 +219,55 @@ class TestConfigGetUnset:assert "Unset platforms.teams.extra.access_token" in capsys.readouterr().out+class TestConfigGetPhantomKeyNotice:+ """``config get`` must not echo a schema-unknown nested key as if it were live: the value comes+ from the file, but nothing reads it. The notice goes to stderr so stdout stays parseable, and+ custom top-level keys / open-subkey sections stay unflagged (both are supported).+ """++ def test_unknown_nested_key_flags_on_stderr_and_keeps_stdout_parseable(+ self, _isolated_hermes_home, capsys+ ):+ (_isolated_hermes_home / "config.yaml").write_text(+ "compression:\n compressor:\n enabled: true\n"+ )++ args = argparse.Namespace(config_command="get", key="compression.compressor.enabled", json=True)+ config_command(args)++ captured = capsys.readouterr()+ assert json.loads(captured.out) is True+ assert "not a recognized config key" in captured.err++ @pytest.mark.parametrize(+ "key, body",+ [+ ("terminal.timeout", "terminal:\n timeout: 120\n"),+ ("my_custom_setting", "my_custom_setting: hello\n"),+ ("mcp_servers.local.url", "mcp_servers:\n local:\n url: http://127.0.0.1:1\n"),+ ],+ )+ def test_recognized_and_custom_keys_are_not_flagged(+ self, _isolated_hermes_home, capsys, key, body+ ):+ (_isolated_hermes_home / "config.yaml").write_text(body)++ args = argparse.Namespace(config_command="get", key=key, json=False)+ config_command(args)++ captured = capsys.readouterr()+ assert captured.out.strip()+ assert "not a recognized config key" not in captured.err++ def test_missing_key_exits_without_a_notice(self, _isolated_hermes_home, capsys):+ args = argparse.Namespace(config_command="get", key="compression.nonexistent_thing", json=False)+ with pytest.raises(SystemExit) as exc:+ config_command(args)++ assert exc.value.code == 1+ assert "not a recognized config key" not in capsys.readouterr().err++# ---------------------------------------------------------------------------# List navigation — regression tests for #17876# ---------------------------------------------------------------------------