The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(config): read deprecated cwd settings from dotenv
fangliquanflq31561e37ed7a
diff --git a/hermes_cli/config.py b/hermes_cli/config.pyindex d2d5c65e26a..261566cce3c 100644--- a/hermes_cli/config.py+++ b/hermes_cli/config.py@@ -2227,10 +2227,17 @@ def warn_deprecated_cwd_env_vars(config: Optional[Dict[str, Any]] = None) -> Non"""Warn if MESSAGING_CWD or TERMINAL_CWD is set in .env instead of config.yaml.These env vars are deprecated — the canonical setting is terminal.cwd- in config.yaml. Prints a migration hint to stderr.+ in config.yaml. Read the file rather than ``os.environ`` because runtime+ config bridges and session restoration legitimately set ``TERMINAL_CWD``.+ Prints a migration hint to stderr."""- messaging_cwd = os.environ.get("MESSAGING_CWD")- terminal_cwd_env = os.environ.get("TERMINAL_CWD")+ try:+ env_map = load_env()+ except Exception:+ return++ messaging_cwd = str(env_map.get("MESSAGING_CWD") or "").strip()+ terminal_cwd_env = str(env_map.get("TERMINAL_CWD") or "").strip()if config is None:try:@@ -2250,7 +2257,6 @@ def warn_deprecated_cwd_env_vars(config: Optional[Dict[str, Any]] = None) -> Nonf"this is deprecated.")if terminal_cwd_env and not config_has_explicit_cwd:- # TERMINAL_CWD in env but not from config bridge — likely from .envlines.append(f" \033[33m⚠\033[0m TERMINAL_CWD={terminal_cwd_env} found in .env — "f"this is deprecated."diff --git a/tests/hermes_cli/test_deprecated_cwd_warning.py b/tests/hermes_cli/test_deprecated_cwd_warning.pyindex e17f1287ad2..e583f2220e4 100644--- a/tests/hermes_cli/test_deprecated_cwd_warning.py+++ b/tests/hermes_cli/test_deprecated_cwd_warning.py@@ -1,29 +1,63 @@"""Tests for warn_deprecated_cwd_env_vars() migration warning."""+def _write_env(monkeypatch, tmp_path, content):+ hermes_home = tmp_path / ".hermes"+ hermes_home.mkdir()+ (hermes_home / ".env").write_text(content, encoding="utf-8")+ monkeypatch.setenv("HERMES_HOME", str(hermes_home))+ return hermes_home++class TestDeprecatedCwdWarning:"""Warn when MESSAGING_CWD or TERMINAL_CWD is set in .env."""- def test_messaging_cwd_triggers_warning(self, monkeypatch, capsys):- monkeypatch.setenv("MESSAGING_CWD", "/some/path")+ def test_process_environment_does_not_trigger_warning(+ self, monkeypatch, tmp_path, capsys+ ):+ _write_env(monkeypatch, tmp_path, "# TERMINAL_CWD=.\n")+ monkeypatch.setenv("MESSAGING_CWD", "/process/message-path")+ monkeypatch.setenv("TERMINAL_CWD", "/process/terminal-path")++ from hermes_cli.config import warn_deprecated_cwd_env_vars++ warn_deprecated_cwd_env_vars(config={})++ assert capsys.readouterr().err == ""++ def test_both_deprecated_vars_in_dotenv_warn(+ self, monkeypatch, tmp_path, capsys+ ):+ _write_env(+ monkeypatch,+ tmp_path,+ "MESSAGING_CWD=/msg/path\nTERMINAL_CWD=/term/path\n",+ )+ monkeypatch.delenv("MESSAGING_CWD", raising=False)monkeypatch.delenv("TERMINAL_CWD", raising=False)from hermes_cli.config import warn_deprecated_cwd_env_vars+warn_deprecated_cwd_env_vars(config={})captured = capsys.readouterr()assert "MESSAGING_CWD" in captured.err+ assert "TERMINAL_CWD" in captured.errassert "deprecated" in captured.err.lower()assert "config.yaml" in captured.err-- def test_both_deprecated_vars_warn(self, monkeypatch, capsys):- monkeypatch.setenv("MESSAGING_CWD", "/msg/path")- monkeypatch.setenv("TERMINAL_CWD", "/term/path")+ def test_commented_and_empty_dotenv_values_do_not_warn(+ self, monkeypatch, tmp_path, capsys+ ):+ _write_env(+ monkeypatch,+ tmp_path,+ "# MESSAGING_CWD=/commented\nTERMINAL_CWD=\n",+ )+ monkeypatch.setenv("TERMINAL_CWD", "/process/bridge")from hermes_cli.config import warn_deprecated_cwd_env_vars+warn_deprecated_cwd_env_vars(config={})- captured = capsys.readouterr()- assert "MESSAGING_CWD" in captured.err- assert "TERMINAL_CWD" in captured.err+ assert capsys.readouterr().err == ""