mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-04-29 01:31:41 +00:00
Adds full ACP support enabling hermes-agent to work as a coding agent inside VS Code (via vscode-acp extension), Zed, JetBrains IDEs, and any ACP-compatible editor. ## New module: acp_adapter/ - server.py: HermesACPAgent implementing all 15 Agent protocol methods (initialize, authenticate, new/load/list/fork/resume session, prompt, cancel, set mode/model/config, on_connect) - session.py: Thread-safe SessionManager with per-session AIAgent lifecycle - events.py: Callback factories translating hermes callbacks to ACP session_update notifications (tool_call, agent_thought, agent_message) - tools.py: Tool kind mapping (20+ tools → read/edit/execute/search/fetch/think) and content builders (diffs for file edits, terminal output, text previews) - permissions.py: Bridges hermes approval_callback to ACP requestPermission RPC for dangerous command approval dialogs in the editor - auth.py: Provider credential verification - entry.py: CLI entry point with .env loading and stderr logging ## Integration points - run_agent.py: ACP tool bridge hook in _execute_tool_calls() for delegating file/terminal operations to the editor - hermes_cli/main.py: 'hermes acp' subcommand - pyproject.toml: [acp] optional dependency, hermes-acp entry point, included in [all] extras (auto-installed via install.sh) ## Supporting files - acp_registry/agent.json: ACP Registry manifest - acp_registry/icon.svg: Hermes caduceus icon - docs/acp-setup.md: User-facing setup guide for VS Code, Zed, JetBrains ## Tests - 41 new tests across 5 test files covering tools, sessions, permissions, server lifecycle, and auth - Full test suite: 2901 passed, 0 failures ## User flow 1. hermes is already installed (install.sh) 2. Install 'ACP Client' extension in VS Code 3. Configure: command='hermes', args=['acp'] 4. Chat with Hermes in the editor — diffs, terminals, approval dialogs, thinking blocks all rendered natively
106 lines
3.7 KiB
Python
106 lines
3.7 KiB
Python
"""Tests for acp_adapter.session — SessionManager and SessionState."""
|
|
|
|
import pytest
|
|
from unittest.mock import MagicMock
|
|
|
|
from acp_adapter.session import SessionManager, SessionState
|
|
|
|
|
|
@pytest.fixture()
|
|
def manager():
|
|
"""SessionManager with a mock agent factory (avoids needing API keys)."""
|
|
return SessionManager(agent_factory=lambda: MagicMock(name="MockAIAgent"))
|
|
|
|
|
|
# ---------------------------------------------------------------------------
|
|
# create / get
|
|
# ---------------------------------------------------------------------------
|
|
|
|
|
|
class TestCreateSession:
|
|
def test_create_session_returns_state(self, manager):
|
|
state = manager.create_session(cwd="/tmp/work")
|
|
assert isinstance(state, SessionState)
|
|
assert state.cwd == "/tmp/work"
|
|
assert state.session_id
|
|
assert state.history == []
|
|
assert state.agent is not None
|
|
|
|
def test_session_ids_are_unique(self, manager):
|
|
s1 = manager.create_session()
|
|
s2 = manager.create_session()
|
|
assert s1.session_id != s2.session_id
|
|
|
|
def test_get_session(self, manager):
|
|
state = manager.create_session()
|
|
fetched = manager.get_session(state.session_id)
|
|
assert fetched is state
|
|
|
|
def test_get_nonexistent_session_returns_none(self, manager):
|
|
assert manager.get_session("does-not-exist") is None
|
|
|
|
|
|
# ---------------------------------------------------------------------------
|
|
# fork
|
|
# ---------------------------------------------------------------------------
|
|
|
|
|
|
class TestForkSession:
|
|
def test_fork_session_deep_copies_history(self, manager):
|
|
original = manager.create_session()
|
|
original.history.append({"role": "user", "content": "hello"})
|
|
original.history.append({"role": "assistant", "content": "hi"})
|
|
|
|
forked = manager.fork_session(original.session_id, cwd="/new")
|
|
assert forked is not None
|
|
|
|
# History should be equal in content
|
|
assert len(forked.history) == 2
|
|
assert forked.history[0]["content"] == "hello"
|
|
|
|
# But a deep copy — mutating one doesn't affect the other
|
|
forked.history.append({"role": "user", "content": "extra"})
|
|
assert len(original.history) == 2
|
|
assert len(forked.history) == 3
|
|
|
|
def test_fork_session_has_new_id(self, manager):
|
|
original = manager.create_session()
|
|
forked = manager.fork_session(original.session_id)
|
|
assert forked is not None
|
|
assert forked.session_id != original.session_id
|
|
|
|
def test_fork_nonexistent_returns_none(self, manager):
|
|
assert manager.fork_session("bogus-id") is None
|
|
|
|
|
|
# ---------------------------------------------------------------------------
|
|
# list / cleanup / remove
|
|
# ---------------------------------------------------------------------------
|
|
|
|
|
|
class TestListAndCleanup:
|
|
def test_list_sessions_empty(self, manager):
|
|
assert manager.list_sessions() == []
|
|
|
|
def test_list_sessions_returns_created(self, manager):
|
|
s1 = manager.create_session(cwd="/a")
|
|
s2 = manager.create_session(cwd="/b")
|
|
listing = manager.list_sessions()
|
|
ids = {s["session_id"] for s in listing}
|
|
assert s1.session_id in ids
|
|
assert s2.session_id in ids
|
|
assert len(listing) == 2
|
|
|
|
def test_cleanup_clears_all(self, manager):
|
|
manager.create_session()
|
|
manager.create_session()
|
|
assert len(manager.list_sessions()) == 2
|
|
manager.cleanup()
|
|
assert manager.list_sessions() == []
|
|
|
|
def test_remove_session(self, manager):
|
|
state = manager.create_session()
|
|
assert manager.remove_session(state.session_id) is True
|
|
assert manager.get_session(state.session_id) is None
|
|
# Removing again returns False
|
|
assert manager.remove_session(state.session_id) is False
|