The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(config): inline the phantom-key notice into get_config_value, trim to 2 tests, docs
teknium1efc035905116
diff --git a/hermes_cli/config.py b/hermes_cli/config.pyindex 65fe063c40e..18bed060da7 100644--- a/hermes_cli/config.py+++ b/hermes_cli/config.py@@ -3524,31 +3524,6 @@ 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@@ -3654,8 +3629,7 @@ 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- is_env_key = _is_env_config_key(key)- if is_env_key:+ if _is_env_config_key(key):env_value = get_env_value(key.upper())value = _MISSING if env_value is None else env_valueelif is_env_setting_key(key):@@ -3679,8 +3653,20 @@ def get_config_value(key: str, *, as_json: bool = False, raw: bool = False):value = redact_config_value(value)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)++ # Phantom-key notice (#112348): a nested path under a KNOWN section that the schema does not+ # define (``compression.compressor.enabled``) is echoed straight from the user's file and read+ # by nothing, so it must not look like a live setting. Custom top-level keys stay exempt (they+ # are bridged into os.environ for skills) and ``_validate_config_key`` already accepts+ # open-subkey sections. stderr keeps stdout/--json parseable; the exit code stays 0.+ if _split_key_path(key)[0] in _known_top_level_keys():+ is_known, suggestion = _validate_config_key(key)+ if not is_known:+ 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 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 35719defb61..ab0709f8957 100644--- a/tests/hermes_cli/test_set_config_value.py+++ b/tests/hermes_cli/test_set_config_value.py@@ -236,7 +236,7 @@ class TestConfigGetPhantomKeyNotice:config_command(args)captured = capsys.readouterr()- assert json.loads(captured.out) is True+ assert json.loads(captured.out) is True # stdout stays parseable: notice is stderr-onlyassert "not a recognized config key" in captured.err@pytest.mark.parametrize(@@ -259,15 +259,6 @@ class TestConfigGetPhantomKeyNotice: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# ---------------------------------------------------------------------------diff --git a/website/docs/reference/cli-commands.md b/website/docs/reference/cli-commands.mdindex 4d0cab7c548..f3a797f35c8 100644--- a/website/docs/reference/cli-commands.md+++ b/website/docs/reference/cli-commands.md@@ -1242,7 +1242,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`). |+| `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 does 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). An unknown path under a known section (`gateway.discord.foo`) is refused with a did-you-mean and nothing is written; an unknown lowercase *top-level* key is written with a notice (top-level scalars are bridged into the environment for skills). `--force` writes either of those. || `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. |diff --git a/website/docs/user-guide/configuration.md b/website/docs/user-guide/configuration.mdindex f54ec48b5e3..80a8759decb 100644--- a/website/docs/user-guide/configuration.md+++ b/website/docs/user-guide/configuration.md@@ -47,7 +47,7 @@ hermes config set OPENROUTER_API_KEY sk-or-... # Saves to .env```:::tip-The `hermes config set` command automatically routes values to the right file — every `UPPER_SNAKE` name (`OPENROUTER_API_KEY`, `DISCORD_HOME_CHANNEL`, `TELEGRAM_GROUP_ALLOWED_USERS`, `HERMES_TIMEZONE`, …) is an environment variable and is saved to `.env`, never to `config.yaml`; dotted settings go to `config.yaml`. Any other `UPPER_SNAKE` name is saved to `.env` as-is (it is exported to the process environment for plugins and skills); names on the env writer's denylist (`HERMES_YOLO_MODE`, `PATH`, …) are refused. A misspelled path under a known section (`gateway.discord.foo`) is refused with a did-you-mean before anything is written; pass `--force` to write it anyway.+The `hermes config set` command automatically routes values to the right file — every `UPPER_SNAKE` name (`OPENROUTER_API_KEY`, `DISCORD_HOME_CHANNEL`, `TELEGRAM_GROUP_ALLOWED_USERS`, `HERMES_TIMEZONE`, …) is an environment variable and is saved to `.env`, never to `config.yaml`; dotted settings go to `config.yaml`. Any other `UPPER_SNAKE` name is saved to `.env` as-is (it is exported to the process environment for plugins and skills); names on the env writer's denylist (`HERMES_YOLO_MODE`, `PATH`, …) are refused. A misspelled path under a known section (`gateway.discord.foo`) is refused with a did-you-mean before anything is written; pass `--force` to write it anyway. `hermes config get` on such a path prints the value from your file together with a stderr notice that Hermes does not read it, so a leftover key cannot pass for a live setting.:::## Configuration Precedence