Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -9876,6 +9876,8 @@ def process_command(self, command: str) -> bool:
self.show_help()
elif canonical == "profile":
self._handle_profile_command()
elif canonical == "whoami":
self._handle_whoami_command()
elif canonical == "tools":
self._handle_tools_command(cmd_original)
elif canonical == "toolsets":
Expand Down
16 changes: 16 additions & 0 deletions hermes_cli/cli_commands_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -704,6 +704,22 @@ def _handle_profile_command(self):
print(f" Home: {display}")
print()

def _handle_whoami_command(self):
"""Show the local operator's slash-command access on this CLI.

The classic CLI runs on the operator's own machine, so the operator is
the local admin (unrestricted) — mirroring the gateway's
``unrestricted`` tier when no admin list is configured for a scope.
"""
import getpass

print()
print(f" You — local CLI (this machine)")
print(f" User: {getpass.getuser()}")
print(f" Tier: admin (local operator)")
print(f" Slash commands: all available")
print()

def _handle_handoff_command(self, cmd_original: str) -> bool:
"""Handle ``/handoff <platform>`` — transfer this CLI session to a gateway platform.

Expand Down
62 changes: 62 additions & 0 deletions tests/cli/test_whoami_command.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
"""Tests for the /whoami CLI command.

/whoami is registered in COMMAND_REGISTRY but used to have no dispatch branch
in HermesCLI.process_command — typing it printed "Unknown command:
/whoami". These tests lock in the dispatch wiring and the handler behavior.
"""

from __future__ import annotations

import getpass
from unittest.mock import MagicMock, patch

from cli import HermesCLI


def _make_cli() -> HermesCLI:
cli_obj = HermesCLI.__new__(HermesCLI)
cli_obj.config = {}
cli_obj.console = MagicMock()
cli_obj.agent = None
cli_obj.conversation_history = []
cli_obj.session_id = None
cli_obj._pending_input = MagicMock()
cli_obj._app = None
cli_obj._pending_resume_sessions = None
return cli_obj


class TestWhoamiDispatch:
"""The command must route to its handler — not fall through to "Unknown"."""

def test_whoami_dispatches_to_handler(self):
cli_obj = _make_cli()
with patch.object(cli_obj, "_handle_whoami_command") as mock_handler:
result = cli_obj.process_command("/whoami")

mock_handler.assert_called_once_with()
assert result is True

def test_whoami_is_not_unknown_command(self):
cli_obj = _make_cli()
with (
patch("cli._cprint") as mock_cprint,
patch.object(cli_obj, "_handle_whoami_command"),
):
result = cli_obj.process_command("/whoami")

printed = " ".join(str(c) for c in mock_cprint.call_args_list)
assert "Unknown command" not in printed
assert result is True


class TestHandleWhoamiCommand:
def test_reports_local_admin_tier(self, capsys):
cli_obj = _make_cli()
cli_obj._handle_whoami_command()

out = capsys.readouterr().out
assert "local CLI" in out
assert getpass.getuser() in out
assert "Tier: admin" in out
assert "all available" in out