The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(config): address Greptile's third review of the config backend seam
kshitijk4poor8c63d4609875
diff --git a/hermes_cli/config.py b/hermes_cli/config.pyindex 11a7bf1e7f6..f7b70160d8b 100644--- a/hermes_cli/config.py+++ b/hermes_cli/config.py@@ -24,7 +24,6 @@ import sysimport tempfileimport threadingfrom contextlib import contextmanager, suppress-from dataclasses import dataclassfrom decimal import Decimal, InvalidOperationfrom pathlib import Pathfrom typing import Dict, Any, Literal, Optional, List, Tuple, Set@@ -45,6 +44,7 @@ from hermes_constants import (# Re-export from hermes_constants — canonical definition lives there.from hermes_constants import get_hermes_home, get_process_hermes_homefrom utils import atomic_replace, fast_safe_load, file_signature, mkstemp_beside+from hermes_cli.config_issues import ConfigIssue, _issue # noqa: F401 ConfigIssue re-exportedfrom hermes_cli.config_backend import (config_exists, config_version, probe_config_readable, read_config_doc, supports_file_tooling, # noqa: F401 config_exists re-exported for facadeswrite_config_document)@@ -974,18 +974,6 @@ _VALID_CUSTOM_PROVIDER_FIELDS = {_CUSTOM_PROVIDER_LIKE_FIELDS = {"base_url", "api_key", "rate_limit_delay", "api_mode"}-@dataclass-class ConfigIssue:- """A detected config structure problem."""- severity: str # "error", "warning"- message: str- hint: str---def _issue(issues: list[ConfigIssue], severity: str, message: str, hint: str) -> None:- issues.append(ConfigIssue(severity, message, hint))--def _require_fields(issues: list[ConfigIssue], entry: dict[str, Any], label: str,fields: tuple[tuple[str, str], ...], suffix: str = "") -> None:diff --git a/hermes_cli/config_backend.py b/hermes_cli/config_backend.pyindex fe92b25b832..97affbb2ace 100644--- a/hermes_cli/config_backend.py+++ b/hermes_cli/config_backend.py@@ -94,8 +94,9 @@ class FileBackend:# that are not a home's config.yaml (see ``_route``).@staticmethoddef version_path(path: Path) -> Tuple[int, int, int, int]:+ st = path.stat() # before the import: a missing file must not need the utils stack (PM runtime)from utils import file_signature- return file_signature(path.stat())+ return file_signature(st)@staticmethoddef read_path(path: Path) -> Any:diff --git a/hermes_cli/config_home.py b/hermes_cli/config_home.pyindex 18cc76a50a7..4dc3b84efd2 100644--- a/hermes_cli/config_home.py+++ b/hermes_cli/config_home.py@@ -81,7 +81,7 @@ def initialize_home(home: Path, subdirs: tuple[str, ...], ensured: set[str]) ->def config_load_issue(exc: Exception):- from hermes_cli.config import ConfigIssue+ from hermes_cli.config_issues import ConfigIssueif isinstance(exc, (HomeInitializationError, OSError)):return ConfigIssue(diff --git a/hermes_cli/config_issues.py b/hermes_cli/config_issues.pynew file mode 100644index 00000000000..1298d35f510--- /dev/null+++ b/hermes_cli/config_issues.py@@ -0,0 +1,19 @@+"""The issue record config validation emits (``hermes config check``, doctor, startup warnings).++Its own module so the facade (``hermes_cli.config``) and its check siblings share it without+a facade import from the siblings."""++from dataclasses import dataclass+from typing import List+++@dataclass+class ConfigIssue:+ """A detected config structure problem."""+ severity: str # "error", "warning"+ message: str+ hint: str+++def _issue(issues: List[ConfigIssue], severity: str, message: str, hint: str) -> None:+ issues.append(ConfigIssue(severity, message, hint))diff --git a/hermes_cli/config_value_checks.py b/hermes_cli/config_value_checks.pyindex 50525425395..6b21c27acf8 100644--- a/hermes_cli/config_value_checks.py+++ b/hermes_cli/config_value_checks.py@@ -3,7 +3,7 @@from typing import Any, Dict, List-from hermes_cli.config import ConfigIssue, _issue+from hermes_cli.config_issues import ConfigIssue, _issuedef _validate_voice(config: Dict[str, Any], issues: List[ConfigIssue]) -> None:diff --git a/pm/plugins_state.py b/pm/plugins_state.pyindex 30bcf3bdd30..d6a4a4d5275 100644--- a/pm/plugins_state.py+++ b/pm/plugins_state.py@@ -29,14 +29,19 @@ def read_home_selection(home: Path) -> Optional[dict[str, Any]]:An unreadable selection raises rather than shrinking the next dependency generation;empty YAML is an explicit empty configuration, as in the CLI loader."""- # Missing YAML support is a broken runtime, not an empty plugin selection.- from ruamel.yaml.error import YAMLError- from hermes_cli.config_backend import config_exists, read_config_doc+ from hermes_cli.config_backend import config_version, read_config_docconfig_path = home / "config.yaml"- # Existence first: a home without config needs no YAML stack (PM's own runtime tree has none).- if not config_exists(config_path):+ # Stat before the YAML stack: a home without config needs none (PM's own runtime tree has none).+ # Only a missing file means "no config"; a symlink loop or permission error still refuses.+ try:+ config_version(config_path)+ except FileNotFoundError:return None+ except OSError as exc:+ raise ValueError(f"could not read plugin selection: {config_path}") from exc+ # Missing YAML support is a broken runtime, not an empty plugin selection.+ from ruamel.yaml.error import YAMLErrortry:config = read_config_doc(config_path)except FileNotFoundError:diff --git a/scripts/check_config_yaml_readers.py b/scripts/check_config_yaml_readers.pyindex 79b34b7e404..5816ef4cb2f 100644--- a/scripts/check_config_yaml_readers.py+++ b/scripts/check_config_yaml_readers.py@@ -128,8 +128,9 @@ class _Scanner:for a in (*scope.args.posonlyargs, *scope.args.args, *scope.args.kwonlyargs):if a.arg in CONFIG_PARAM_NAMES:names.add(a.arg)- # Two passes so `a = home / "config.yaml"; b = a` binds b too.- for _ in range(2):+ # Until no new name binds, so alias chains (`a = home / "config.yaml"; b = a; c = b`) of any length bind.+ while True:+ before = len(names)for node in _scope_nodes(scope):if isinstance(node, ast.Assign):pairs = [(t, node.value) for t in node.targets]@@ -143,7 +144,8 @@ class _Scanner:continuefor target, value in pairs:self._bind(target, value, names)- return names+ if len(names) == before:+ return namesdef _bind(self, target: ast.AST, value: ast.AST, names: set[str]) -> None:"""Add *target* (a name, ``self.attr``, or an unpacked tuple element) when *value* is a config path."""diff --git a/tests/hermes_cli/test_config_backend.py b/tests/hermes_cli/test_config_backend.pyindex 080ed5044f3..aaddad32d0c 100644--- a/tests/hermes_cli/test_config_backend.py+++ b/tests/hermes_cli/test_config_backend.py@@ -257,6 +257,7 @@ class TestReaderGate:"p = home / 'config.yaml'\n return io.open(p)","p = home / 'config.yaml'\n return builtins.open(p)","p = home / 'config.yaml'\n return open(file=p)",+ "first = home / 'config.yaml'\n second = first\n third = second\n return third.read_text()",])def test_every_binding_form_is_tracked(self, tmp_path, body):# Tuple unpacking, attributes, loop targets, unbound Path methods, copies, byte reads.diff --git a/tests/pm/test_plugins_state.py b/tests/pm/test_plugins_state.pyindex 420ca23e68a..5a0f2ff85fc 100644--- a/tests/pm/test_plugins_state.py+++ b/tests/pm/test_plugins_state.py@@ -96,6 +96,16 @@ def test_unreadable_profile_state_is_not_an_empty_selection(homes, monkeypatch,enabled_member_dirs()+def test_unreadable_config_link_is_not_an_empty_selection(homes):+ # Only a missing file means "no config": a symlink loop must refuse, not drop the home's plugins.+ default_home, _ = homes+ config = default_home / "config.yaml"+ config.unlink(missing_ok=True)+ config.symlink_to(config)+ with pytest.raises(ValueError, match=re.escape(str(config))):+ pstate.enabled_plugins_ordered()++def test_missing_config_parser_is_not_an_empty_plugin_selection(homes, monkeypatch):import sys