fix(config): config set/get still recognise terminal.singularity_image
The key left DEFAULT_CONFIG with the backend, but the singularity plugin reads it and its setup text says `hermes config set terminal.singularity_image <image>`; set and get now flagged it "not a recognized config key ... Hermes may not read it". A seeded default would hide the plugin's TERMINAL_SINGULARITY_IMAGE fallback, so _validate_config_key accepts left_core_migration.LEFT_CORE_TERMINAL_KEYS (the renamed RETIRED_TERMINAL_ENV_COPIES, which unset already consults) instead. The wrong-prefix refusal text moves to hermes_cli/config_key_notices.py to keep config.py under its line cap. Review: https://github.com/NousResearch/hermes-agent/pull/142561#pullrequestreview (kshitijk4poor, item 2)
This commit is contained in:
@@ -3086,7 +3086,8 @@ def _validate_config_key(key: str) -> tuple[bool, Optional[str]]:
|
||||
|
||||
# A leading underscore on the FIRST segment marks an intentionally non-schema internal key
|
||||
# (test harnesses/tooling); only the first segment is exempt so ``agent._max_turns`` is caught.
|
||||
if top.startswith("_") or top in _PLATFORM_CONTAINER_KEYS:
|
||||
from hermes_cli.left_core_migration import LEFT_CORE_TERMINAL_KEYS
|
||||
if top.startswith("_") or top in _PLATFORM_CONTAINER_KEYS or key in LEFT_CORE_TERMINAL_KEYS:
|
||||
return True, None
|
||||
|
||||
known = _known_top_level_keys()
|
||||
@@ -3394,15 +3395,6 @@ def _print_unknown_key_notice(key: str, suggestion: Optional[str]) -> None:
|
||||
print(color(" (Use --force to skip this notice.)", Colors.DIM))
|
||||
|
||||
|
||||
def _unknown_subkey_refusal(key: str, suggestion: Optional[str]) -> str:
|
||||
lines = [color(f"✗ '{key}' is not a recognized config key — nothing was written.", Colors.RED)]
|
||||
if suggestion:
|
||||
lines.append(color(f" Did you mean: {suggestion}", Colors.YELLOW))
|
||||
lines.append(color(
|
||||
" (Custom top-level keys are supported; use --force to write this path anyway.)", Colors.DIM))
|
||||
return "\n".join(lines)
|
||||
|
||||
|
||||
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 a known key given under the wrong prefix (``gateway.discord.foo`` where
|
||||
@@ -3457,7 +3449,8 @@ def set_config_value(key: str, value: str, force: bool = False):
|
||||
# seeded default. Refuse only the positive wrong-prefix case from #112003; other unknown
|
||||
# paths keep the post-write warning so valid runtime settings remain configurable.
|
||||
if not is_known and not force and _is_wrong_prefix_suggestion(key, suggestion):
|
||||
_exit_invalid(_unknown_subkey_refusal(key, suggestion))
|
||||
from hermes_cli.config_key_notices import unknown_subkey_refusal
|
||||
_exit_invalid(unknown_subkey_refusal(key, suggestion))
|
||||
|
||||
if key == "display.language":
|
||||
from hermes_cli.config_language import display_language_error
|
||||
@@ -3638,8 +3631,8 @@ def unset_config_value(key: str):
|
||||
if legacy_key:
|
||||
removed = _unset_nested(user_config, legacy_key) or removed
|
||||
|
||||
from hermes_cli.left_core_migration import RETIRED_TERMINAL_ENV_COPIES
|
||||
env_var = terminal_config_env_var_for_key(key) or RETIRED_TERMINAL_ENV_COPIES.get(key)
|
||||
from hermes_cli.left_core_migration import LEFT_CORE_TERMINAL_KEYS
|
||||
env_var = terminal_config_env_var_for_key(key) or LEFT_CORE_TERMINAL_KEYS.get(key)
|
||||
if env_var and key != "terminal.cwd":
|
||||
removed = remove_env_value(env_var) or removed
|
||||
|
||||
|
||||
17
hermes_cli/config_key_notices.py
Normal file
17
hermes_cli/config_key_notices.py
Normal file
@@ -0,0 +1,17 @@
|
||||
"""Notices ``hermes config set`` prints for a key path the schema does not know."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Optional
|
||||
|
||||
from hermes_cli.colors import Colors, color
|
||||
|
||||
|
||||
def unknown_subkey_refusal(key: str, suggestion: Optional[str]) -> str:
|
||||
"""The refusal for a known key given under the wrong prefix (``gateway.discord.foo``)."""
|
||||
lines = [color(f"✗ '{key}' is not a recognized config key — nothing was written.", Colors.RED)]
|
||||
if suggestion:
|
||||
lines.append(color(f" Did you mean: {suggestion}", Colors.YELLOW))
|
||||
lines.append(color(
|
||||
" (Custom top-level keys are supported; use --force to write this path anyway.)", Colors.DIM))
|
||||
return "\n".join(lines)
|
||||
@@ -39,10 +39,11 @@ from hermes_cli.memory_provider_migration import (
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
# ``terminal.*`` keys ``hermes config set`` also wrote to ``.env`` while core shipped their backend. The
|
||||
# plugin still reads that copy as a fallback, so ``hermes config unset`` keeps removing it: otherwise the
|
||||
# old value returns instead of the default.
|
||||
RETIRED_TERMINAL_ENV_COPIES = {"terminal.singularity_image": "TERMINAL_SINGULARITY_IMAGE"}
|
||||
# ``terminal.*`` keys a left-core plugin still reads -> the ``.env`` copy core's ``hermes config set`` also
|
||||
# wrote. Not in DEFAULT_CONFIG (a seeded default would hide the plugin's env fallback), so ``config
|
||||
# set/get`` recognise them here, and ``config unset`` removes that copy too: the plugin falls back to it,
|
||||
# and the old value would return instead of the default.
|
||||
LEFT_CORE_TERMINAL_KEYS = {"terminal.singularity_image": "TERMINAL_SINGULARITY_IMAGE"}
|
||||
|
||||
|
||||
def _read_config(home: Path) -> dict:
|
||||
|
||||
@@ -148,3 +148,16 @@ def test_config_unset_removes_the_env_copy_core_used_to_write(tmp_path, monkeypa
|
||||
unset_config_value("terminal.singularity_image")
|
||||
assert "singularity_image" not in (home / "config.yaml").read_text(encoding="utf-8")
|
||||
assert "TERMINAL_SINGULARITY_IMAGE" not in (home / ".env").read_text(encoding="utf-8")
|
||||
|
||||
|
||||
def test_config_set_and_get_still_recognize_the_image_key(tmp_path, monkeypatch, capsys):
|
||||
# The plugin reads terminal.singularity_image and its setup text says `hermes config set
|
||||
# terminal.singularity_image <image>`; leaving DEFAULT_CONFIG must not make it an unknown key.
|
||||
home = _home(tmp_path, config="terminal:\n backend: singularity\n")
|
||||
monkeypatch.setenv("HERMES_HOME", str(home))
|
||||
from hermes_cli.config import get_config_value, set_config_value
|
||||
set_config_value("terminal.singularity_image", "docker://python:3.12")
|
||||
get_config_value("terminal.singularity_image")
|
||||
out = capsys.readouterr()
|
||||
assert "docker://python:3.12" in out.out
|
||||
assert "not a recognized config key" not in out.out + out.err
|
||||
|
||||
Reference in New Issue
Block a user