diff --git a/cli.py b/cli.py index fbc8f8525..20996aecc 100644 --- a/cli.py +++ b/cli.py @@ -3897,23 +3897,14 @@ class HermesCLI: def _handle_profile_command(self): """Display active profile name and home directory.""" - from hermes_constants import get_hermes_home, display_hermes_home + from hermes_constants import display_hermes_home + from hermes_cli.profiles import get_active_profile_name - home = get_hermes_home() display = display_hermes_home() - - profiles_parent = Path.home() / ".hermes" / "profiles" - try: - rel = home.relative_to(profiles_parent) - profile_name = str(rel).split("/")[0] - except ValueError: - profile_name = None + profile_name = get_active_profile_name() print() - if profile_name: - print(f" Profile: {profile_name}") - else: - print(" Profile: default") + print(f" Profile: {profile_name}") print(f" Home: {display}") print() diff --git a/gateway/run.py b/gateway/run.py index 2d907e08a..94381d8be 100644 --- a/gateway/run.py +++ b/gateway/run.py @@ -4393,31 +4393,16 @@ class GatewayRunner: async def _handle_profile_command(self, event: MessageEvent) -> str: """Handle /profile — show active profile name and home directory.""" - from hermes_constants import get_hermes_home, display_hermes_home - from pathlib import Path + from hermes_constants import display_hermes_home + from hermes_cli.profiles import get_active_profile_name - home = get_hermes_home() display = display_hermes_home() + profile_name = get_active_profile_name() - # Detect profile name from HERMES_HOME path - # Profile paths look like: ~/.hermes/profiles/ - profiles_parent = Path.home() / ".hermes" / "profiles" - try: - rel = home.relative_to(profiles_parent) - profile_name = str(rel).split("/")[0] - except ValueError: - profile_name = None - - if profile_name: - lines = [ - f"👤 **Profile:** `{profile_name}`", - f"📂 **Home:** `{display}`", - ] - else: - lines = [ - "👤 **Profile:** default", - f"📂 **Home:** `{display}`", - ] + lines = [ + f"👤 **Profile:** `{profile_name}`", + f"📂 **Home:** `{display}`", + ] return "\n".join(lines) diff --git a/tests/cli/test_cli_status_command.py b/tests/cli/test_cli_status_command.py index bff642fdf..ed6fbd7d2 100644 --- a/tests/cli/test_cli_status_command.py +++ b/tests/cli/test_cli_status_command.py @@ -1,5 +1,6 @@ """Tests for CLI /status command behavior.""" from datetime import datetime +from pathlib import Path from types import SimpleNamespace from unittest.mock import MagicMock, patch @@ -83,3 +84,18 @@ def test_show_session_status_prints_gateway_style_summary(): _, kwargs = cli_obj.console.print.call_args assert kwargs.get("highlight") is False assert kwargs.get("markup") is False + + +def test_profile_command_reports_custom_root_profile(monkeypatch, tmp_path, capsys): + """Profile detection works for custom-root deployments (not under ~/.hermes).""" + cli_obj = _make_cli() + profile_home = tmp_path / "profiles" / "coder" + + monkeypatch.setenv("HERMES_HOME", str(profile_home)) + monkeypatch.setattr(Path, "home", lambda: tmp_path / "unrelated-home") + + cli_obj._handle_profile_command() + + out = capsys.readouterr().out + assert "Profile: coder" in out + assert f"Home: {profile_home}" in out diff --git a/tests/gateway/test_status_command.py b/tests/gateway/test_status_command.py index 0dbd5980b..554480087 100644 --- a/tests/gateway/test_status_command.py +++ b/tests/gateway/test_status_command.py @@ -209,3 +209,28 @@ async def test_status_command_bypasses_active_session_guard(): assert "Agent Running" in sent[0] assert not interrupt_event.is_set(), "/status incorrectly triggered an agent interrupt" assert session_key not in adapter._pending_messages, "/status was incorrectly queued" + + +@pytest.mark.asyncio +async def test_profile_command_reports_custom_root_profile(monkeypatch, tmp_path): + """Gateway /profile detects custom-root profiles (not under ~/.hermes).""" + from pathlib import Path + + session_entry = SessionEntry( + session_key=build_session_key(_make_source()), + session_id="sess-1", + created_at=datetime.now(), + updated_at=datetime.now(), + platform=Platform.TELEGRAM, + chat_type="dm", + ) + runner = _make_runner(session_entry) + profile_home = tmp_path / "profiles" / "coder" + + monkeypatch.setenv("HERMES_HOME", str(profile_home)) + monkeypatch.setattr(Path, "home", lambda: tmp_path / "unrelated-home") + + result = await runner._handle_profile_command(_make_event("/profile")) + + assert "**Profile:** `coder`" in result + assert f"**Home:** `{profile_home}`" in result