fix: resolve .env path from ~/.hermes/ in cli.py, matching run_agent.py pattern

Load ~/.hermes/.env first with project root as dev fallback, and remove
redundant second load_dotenv call inside load_cli_config(). Also sets
MSWEA_GLOBAL_CONFIG_DIR so mini-swe-agent shares the same config.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Dean Kerr
2026-02-26 18:37:20 +11:00
parent 6c86c7c4a9
commit cf3236ed27

29
cli.py
View File

@@ -49,16 +49,26 @@ import threading
import queue
# Load environment variables first
# Load .env from ~/.hermes/.env first, then project root as dev fallback
from dotenv import load_dotenv
from hermes_constants import OPENROUTER_BASE_URL
env_path = Path(__file__).parent / '.env'
if env_path.exists():
_hermes_home = Path(os.getenv("HERMES_HOME", Path.home() / ".hermes"))
_user_env = _hermes_home / ".env"
_project_env = Path(__file__).parent / '.env'
if _user_env.exists():
try:
load_dotenv(dotenv_path=env_path, encoding="utf-8")
load_dotenv(dotenv_path=_user_env, encoding="utf-8")
except UnicodeDecodeError:
load_dotenv(dotenv_path=env_path, encoding="latin-1")
load_dotenv(dotenv_path=_user_env, encoding="latin-1")
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")
# Point mini-swe-agent at ~/.hermes/ so it shares our config
os.environ.setdefault("MSWEA_GLOBAL_CONFIG_DIR", str(_hermes_home))
# =============================================================================
# Configuration Loading
@@ -132,15 +142,6 @@ def load_cli_config() -> Dict[str, Any]:
else:
config_path = project_config_path
# Also load .env from ~/.hermes/.env if it exists
user_env_path = Path.home() / '.hermes' / '.env'
if user_env_path.exists():
from dotenv import load_dotenv
try:
load_dotenv(dotenv_path=user_env_path, override=True, encoding="utf-8")
except UnicodeDecodeError:
load_dotenv(dotenv_path=user_env_path, override=True, encoding="latin-1")
# Default configuration
defaults = {
"model": {