From 696e2316a861868af6106c7a8d4caf2d82797b0a Mon Sep 17 00:00:00 2001 From: Dean Kerr Date: Thu, 26 Feb 2026 19:01:13 +1100 Subject: [PATCH] fix: respect HERMES_HOME and add encoding fallback in rl_cli.py MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Consistent with other entry points: use _hermes_home from HERMES_HOME env var, and add UTF-8 → latin-1 encoding fallback on load_dotenv. Co-Authored-By: Claude Opus 4.6 --- rl_cli.py | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/rl_cli.py b/rl_cli.py index eaeec1d96d..3aa0412d4c 100644 --- a/rl_cli.py +++ b/rl_cli.py @@ -27,19 +27,25 @@ from pathlib import Path import fire import yaml -# Load environment variables from .env file +# Load .env from ~/.hermes/.env first, then project root as dev fallback from dotenv import load_dotenv -# Load from ~/.hermes/.env first, then local .env -hermes_env_path = Path.home() / '.hermes' / '.env' -local_env_path = Path(__file__).parent / '.env' +_hermes_home = Path(os.getenv("HERMES_HOME", Path.home() / ".hermes")) +_user_env = _hermes_home / ".env" +_project_env = Path(__file__).parent / '.env' -if hermes_env_path.exists(): - load_dotenv(dotenv_path=hermes_env_path) - print(f"✅ Loaded environment variables from {hermes_env_path}") -elif local_env_path.exists(): - load_dotenv(dotenv_path=local_env_path) - print(f"✅ Loaded environment variables from {local_env_path}") +if _user_env.exists(): + try: + load_dotenv(dotenv_path=_user_env, encoding="utf-8") + except UnicodeDecodeError: + load_dotenv(dotenv_path=_user_env, encoding="latin-1") + print(f"✅ Loaded environment variables from {_user_env}") +elif _project_env.exists(): + try: + load_dotenv(dotenv_path=_project_env, encoding="utf-8") + except UnicodeDecodeError: + load_dotenv(dotenv_path=_project_env, encoding="latin-1") + print(f"✅ Loaded environment variables from {_project_env}") # Set terminal working directory to tinker-atropos submodule # This ensures terminal commands run in the right context for RL work @@ -77,7 +83,7 @@ def load_hermes_config() -> dict: Returns: dict: Configuration with model, base_url, etc. """ - config_path = Path.home() / '.hermes' / 'config.yaml' + config_path = _hermes_home / 'config.yaml' config = { "model": DEFAULT_MODEL,