`scripts/run_tests.sh tests/<dir>/` is how a change gets its regression
coverage run, so a test filed under the wrong directory is a test nobody
runs when that code changes. Two kinds of drift had accumulated.
Parallel directories for one source package, folded into the mirror:
tests/acp -> tests/acp_adapter (its __init__/conftest move with it)
tests/cli -> tests/hermes_cli (prompt_toolkit fixture merged into
hermes_cli/conftest.py)
tests/run_agent -> tests/agent (backoff fixture becomes
agent/conftest.py)
tests/relay -> tests/gateway/relay
tests/state -> tests/hermes_state
246 loose files at tests/ root, routed by the package they import/patch:
hermes_cli, hermes_state, agent, gateway, tools, plugins, tui_gateway, cron.
Installer and desktop-update script tests go to tests/scripts/{install,
desktop_update}/. 43 tests of root-level modules (batch_runner, utils,
hermes_constants, packaging) stay at the root.
Filenames drop their issue numbers (95 files: test_89315_x.py -> test_x.py);
the number stays in the module docstring where it has context.
Collisions: test_cli_skin_integration.py existed in both tests/ and tests/cli
with different subsets — merged into one (10 tests, all kept);
run_agent/test_pre_compress_memory_context.py -> agent/..._handoff.py;
tests/test_account_usage.py -> agent/test_account_usage_fetch.py;
tests/test_web_server.py -> hermes_cli/test_web_server_ws_ping.py.
Deleted: test_minisweagent_path.py (empty since PR #2804),
test_model_picker_scroll.py (tested a private copy of the logic, imported
nothing), test_process_loop_event_loop_warning.py (asserted asyncio behaviour,
imported nothing from Hermes).
Repo-root path arithmetic (Path(__file__).parents[N], dirname chains) is
bumped for the 202 files that changed depth and verified by evaluating every
such expression against the new location. classify_changes' desktop-updater
lane prefix, tests-os.yml's ignore glob and every in-tree path comment follow
the moves. tests/test_tests_tree_layout.py keeps the tree from drifting back.
5.0 KiB
sidebar_position, title, description
| sidebar_position | title | description |
|---|---|---|
| 2 | ACP Internals | How the ACP adapter works: lifecycle, sessions, event bridge, approvals, and tool rendering |
ACP Internals
The ACP adapter wraps Hermes' synchronous AIAgent in an async JSON-RPC stdio server.
Key implementation files:
acp_adapter/entry.pyacp_adapter/server.pyacp_adapter/session.pyacp_adapter/events.pyacp_adapter/permissions.pyacp_adapter/tools.pyacp_adapter/auth.py
Boot flow
hermes acp / hermes-acp / python -m acp_adapter
-> acp_adapter.entry.main()
-> parse --version / --check / --setup before server startup
-> load ~/.hermes/.env
-> configure stderr logging
-> construct HermesACPAgent
-> acp.run_agent(agent, use_unstable_protocol=True)
Stdout is reserved for ACP JSON-RPC transport. Human-readable logs go to stderr.
Major components
HermesACPAgent
acp_adapter/server.py implements the ACP agent protocol.
Responsibilities:
- initialize / authenticate
- new/load/resume/fork/list/cancel session methods
- prompt execution
- session model switching
- wiring sync AIAgent callbacks into ACP async notifications
SessionManager
acp_adapter/session.py tracks live ACP sessions.
Each session stores:
session_idagentcwdmodelhistorycancel_event
The manager is thread-safe and supports:
- create
- get
- remove
- fork
- list
- cleanup
- cwd updates
Event bridge
acp_adapter/events.py converts AIAgent callbacks into ACP session_update events.
Bridged callbacks:
tool_progress_callbackthinking_callback(currently set toNonein the ACP bridge — reasoning is forwarded throughstep_callbackinstead)step_callback
Because AIAgent runs in a worker thread while ACP I/O lives on the main event loop, the bridge uses:
asyncio.run_coroutine_threadsafe(...)
Permission bridge
acp_adapter/permissions.py adapts dangerous terminal approval prompts into ACP permission requests.
Mapping:
allow_once-> Hermesonceallow_always-> Hermesalways- reject options -> Hermes
deny
Timeouts and bridge failures deny by default.
Tool rendering helpers
acp_adapter/tools.py maps Hermes tools to ACP tool kinds and builds editor-facing content.
Examples:
patch/write_file-> file diffsterminal-> shell command textread_file/search_files-> text previews- large results -> truncated text blocks for UI safety
Session lifecycle
new_session(cwd)
-> create SessionState
-> create AIAgent(platform="acp", enabled_toolsets=["hermes-acp"])
-> bind task_id/session_id to cwd override
prompt(..., session_id)
-> extract text from ACP content blocks
-> reset cancel event
-> install callbacks + approval bridge
-> run AIAgent in ThreadPoolExecutor
-> update session history
-> emit final agent message chunk
Cancelation
cancel(session_id):
- sets the session cancel event
- calls
agent.interrupt()when available - causes the prompt response to return
stop_reason="cancelled"
Forking
fork_session() deep-copies message history into a new live session, preserving conversation state while giving the fork its own session ID and cwd.
Provider/auth behavior
ACP does not implement its own auth store.
Instead it reuses Hermes' runtime resolver:
acp_adapter/auth.pyhermes_cli/runtime_provider.py
So ACP advertises and uses the currently configured Hermes provider/credentials. It also always advertises a terminal setup auth method (hermes-setup, args --setup) so first-run ACP clients can open Hermes' interactive model/provider configuration before starting a normal ACP session.
Working directory binding
ACP sessions carry an editor cwd.
The session manager binds that cwd to the ACP session ID via task-scoped terminal/file overrides, so file and terminal tools operate relative to the editor workspace.
Duplicate same-name tool calls
The event bridge tracks tool IDs FIFO per tool name, not just one ID per name. This is important for:
- parallel same-name calls
- repeated same-name calls in one step
Without FIFO queues, completion events would attach to the wrong tool invocation.
Approval callback restoration
ACP temporarily installs an approval callback on the terminal tool during prompt execution, then restores the previous callback afterward. This avoids leaving ACP session-specific approval handlers installed globally forever.
Current limitations
- ACP sessions are persisted to the shared
~/.hermes/state.db(SessionDB) and transparently restored across process restarts; they appear insession_search - non-text prompt blocks are currently ignored for request text extraction
- editor-specific UX varies by ACP client implementation
Related files
tests/acp_adapter/— ACP test suitetoolsets.py—hermes-acptoolset definitionhermes_cli/main.py—hermes acpCLI subcommandpyproject.toml—[acp]optional dependency +hermes-acpscript