From b2c2f325844c8e41ffbb1ef47ab24bc36ab3b8cf Mon Sep 17 00:00:00 2001 From: nesquena-hermes Date: Fri, 3 Apr 2026 21:00:04 -0700 Subject: [PATCH] fix: CLI session bridge reads active profile's state.db not server launch profile (#59) get_cli_sessions() and get_cli_session_messages() were using HERMES_HOME (the profile the server was launched under) to find state.db. This meant a server launched under the webui profile would read webui's state.db (full of cron runs) instead of the user's actual CLI sessions. Fix: use get_active_hermes_home() which tracks whichever profile the user has selected in the UI. This means: - default profile active -> reads ~/.hermes/state.db (interactive CLI) - camanji profile active -> reads ~/.hermes/profiles/camanji/state.db Falls back to HERMES_HOME env var if profiles module unavailable. Co-authored-by: Nathan Esquenazi --- api/models.py | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/api/models.py b/api/models.py index 71e787e..31f94ab 100644 --- a/api/models.py +++ b/api/models.py @@ -227,7 +227,20 @@ def get_cli_sessions(): except ImportError: return cli_sessions - hermes_home = Path(os.getenv('HERMES_HOME', str(HOME / '.hermes'))).expanduser() + # Use the active WebUI profile's HERMES_HOME to find state.db. + # The active profile is determined by what the user has selected in the UI + # (stored in the server's runtime config). This means: + # - default profile -> ~/.hermes/state.db + # - named profile X -> ~/.hermes/profiles/X/state.db + # We resolve the active profile's home directory rather than just using + # HERMES_HOME (which is the server's launch profile, not necessarily the + # active one after a profile switch). + try: + from api.profiles import get_active_hermes_home + hermes_home = Path(get_active_hermes_home()).expanduser().resolve() + except Exception: + hermes_home = Path(os.getenv('HERMES_HOME', str(HOME / '.hermes'))).expanduser().resolve() + db_path = hermes_home / 'state.db' if not db_path.exists(): return cli_sessions @@ -294,7 +307,11 @@ def get_cli_session_messages(sid): except ImportError: return [] - hermes_home = Path(os.getenv('HERMES_HOME', str(HOME / '.hermes'))).expanduser() + try: + from api.profiles import get_active_hermes_home + hermes_home = Path(get_active_hermes_home()).expanduser().resolve() + except Exception: + hermes_home = Path(os.getenv('HERMES_HOME', str(HOME / '.hermes'))).expanduser().resolve() db_path = hermes_home / 'state.db' if not db_path.exists(): return []