# Hermes
An [ACP (Agent Client Protocol)](https://agentclientprotocol.com) client designed for integration with Neovim.
## π Overview
Hermes is a messaging layer for Neovim. It has no built-in UI, instead it provides APIs and hooks for building your own workflow while routing client-agent communication.
Hermes focuses on:
- APIs for making requests to AI Assistants (prompt, connect, authenticate, etc)
- Hooks into requests from AI assistants that require responses (permission requests, access requests, etc)
- Autocommands for updates on communication between the user (client) and assistant (agent)
## β¨ Features
- [x] Full implementation of ACP Client (Built on the official [Rust ACP Sdk](https://github.com/agentclientprotocol/rust-sdk))
- [x] Support for all registered ACP Agents ([Full list here](https://agentclientprotocol.com/get-started/agents))
- [x] Configurable capabilities (filesystem, terminal, etc)
- [x] Autocommands for messages/notifications
- [x] Communication over Stdio, TCP, Socket, and HTTP protocols
- [x] Neovim 0.12 progress integration via `nvim_echo` with `kind="progress"`
- [x] Luarocks integration
- [x] NixOS intgration
### βοΈ Requirements
- Neovim 0.11 or later
### π» Supported Platforms
Binaries are available for:
- **Linux:** x86_64, aarch64 (arm64)
- **macOS:** x86_64, arm64
- **Windows:** x86_64
> [!NOTE]
> Hermes will automatically detect and download a pre-built binary for supported platforms.
>
> You can disable this if you would prefer to [build from source](#-building-from-source)
> ```lua
> -- Will have to set up manually with `:Hermes build` or build manually from source
> require("hermes").setup({
> download = {
> auto = false,
> },
> })
> ```
## π¦ Installation
**vim.pack** (v0.12+)
```lua
vim.pack.add({ "Ruddickmg/hermes.nvim" })
```
**lazy.nvim**
```lua
{
"Ruddickmg/hermes.nvim",
config = function()
require("hermes").setup()
end
}
```
**rocks.nvim**
```vim
:Rocks install hermes.nvim
```
**NixOS**
Hermes can be installed to nix directly as a flake or via `nixpkgs.vimPlugins.hermes-nvim`.
```nix
programs.nixvim = {
extraPlugins = [ pkgs.vimPlugins.hermes-nvim ];
};
```
## β¨οΈ Commands
Open the most recent log file in a new tab (read-only, cursor at the end). The buffer's filetype follows your `log.file.format` configuration β JSON logs open as `jsonl` (newline-delimited JSON).
```vim
:Hermes log
```
Fetch the latest release from GitHub and replaces the current binary.
```vim
:Hermes update
```
> Triggers [Progress](#progress) autocommand while downloading
Download the currently configured version.
```vim
:Hermes install
```
> Triggers [Progress](#progress) autocommand while downloading
Remove the binary. Run `:Hermes install` or use Hermes API to re-download.
```vim
:Hermes clean
```
Compile from source (requires Rust toolchain). Runs asynchronously without blocking Neovim.
```vim
:Hermes build
```
Cancel an in-progress source build. Shows warning if no build is running.
```vim
:Hermes cancel
```
## π API
Hermes exposes the following functions for sending requests to AI assistants.
> [!WARNING]
> Methods marked βOptionalβ are implemented by Hermes but are not mandatory for agent implementations.
### βοΈ Setup
Configure Hermes plugin settings.
```lua
local hermes = require("hermes")
local LogFormat = hermes.LogFormat
-- Basic usage with no arguments (uses all defaults)
hermes.setup()
-- Configure specific permissions
hermes.setup({
permissions = {
fs_write_access = true,
terminal_access = true,
}
})
-- Full configuration defaults
hermes.setup({
download = {
version = "latest", -- specify which hermes release to use
auto = true, -- automatically download pre-built binary (set to false to build manually), defaults to false on Nixos environments
timeout = 60, -- timeout in seconds for download
},
root_markers = { ".git" }, -- used to detect the project root by matching file names in the root directory
permissions = {
fs_write_access = true, -- Allow file writes to the agent
fs_read_access = true, -- Allow file reads to the agent
terminal_access = true, -- Allow terminal access to the agent
request_permissions = true, -- Allow agent to send permission requests
send_notifications = true, -- Allow the agent to send notifications
elicitation = {
form = true, -- Allow the agent to send form elicitation requests
url = true, -- Allow the agent to send URL elicitation requests
reject_unknown_elicitation_values = false, -- Reject responses for unknown/future elicitation property types
},
},
distributions = { -- path to distributions
uvx = true, -- allows installing agents via UVX (default: true, false in Nix environments)
npx = true, -- allows installing agents via NPX (default: true, false in Nix environments)
binary = { -- configuration for binary behavior
path = vim.fn.stdpath('state') .. "/nvim/hermes/binaries", -- path where binaries will be downloaded to
enabled = true, -- allows installing agents via binary (default: true, false in Nix environments)
},
},
terminal = {
delete = true, -- Auto-delete terminals on exit
enabled = true, -- Enable terminal functionality
buffered = true, -- Buffer terminal output
},
buffer = {
auto_save = false, -- Auto-save modified files after writing to them
},
session = {
store_history = true, -- Store session history locally when agent does not support load_session
},
log = {
-- send logs to stdio
stdio = {
-- only logs of the set value and above will be sent
level = vim.log.levels.OFF or "off",
-- logs stdio logs will be formatted with the selected format
format = LogFormat.compact,
-- show ansi symbols
show_ansi = false,
},
-- send logs to Neovim "notify"
notification = {
level = vim.log.levels.ERROR or "error",
show_ansi = false, -- show ansi symbols
format = LogFormat.compact,
},
-- send logs to Neovim ":messages"
message = {
level = vim.log.levels.OFF or "off",
show_ansi = false, -- show ansi symbols
format = LogFormat.compact,
},
-- send logs to log files
file = {
level = vim.log.levels.OFF or "off",
format = LogFormat.json,
path = vim.fn.stdpath('state') .. "/nvim/hermes/logs", -- path to log file(s)
name = "hermes.log", -- name of log file
show_ansi = false, -- show ansi symbols
max_size = 10485760, -- 10mb in bytes
max_files = 5, -- Max log files to generate
},
},
progress = {
cmdline = false, -- Show progress messages in cmdline (0.12+ only)
update_frequency = 150 -- how often to poll the download for progress in milliseconds
},
agents = { -- User-defined agent connections to add to the agents list, keyed by agent id.
opencode = { -- matching ids with an agent from the ACP registry will override the registered agent.
command = "opencode", -- command to run for stdio connections
args = { "acp" }, -- command arguments
icon = "~/icons/opencode.svg", -- HTTP(S) URL or local path to an SVG icon (optional)
description = "Some custom description",
},
},
})
```
> [!NOTE]
> - `setup()` does not have to be called, hermes will operate off of defaults without it
> - Configuration changes are applied immediately
> - Multiple `setup()` calls merge configurations - only specified fields are updated
> - All unspecified fields preserve their existing values
### π€ Agents
This method retrieves a list of available agents to choose from.
```lua
local hermes = require("hermes")
-- get list of agents
hermes.agents()
-- example with config options
hermes.agents({
update = true, -- pull down the most up to date list from the ACP registry (will use last downloaded/pre-bundled registry if false)
url = "https://cdn.agentclientprotocol.com/registry/v1/latest/registry.json", -- URL to pull ACP registry from
})
```
> **Triggers:**
> - [AgentList](#agentslist) autocommand upon completion.
> - [Progress](#progress) autocommand if the `update` option is enabled (for registry download progress)
### π Connect
This method allows you to connect to an agent, it takes the agent name and the protocol for the connection (defaults to `stdio`).
```lua
local hermes = require("hermes")
local Autocommand = hermes.Autocommand
local Protocol = hermes.Protocol
local Distribution = hermes.Distribution
-- connect to pre-defined agent
hermes.connect("github-copilot-cli")
-- configure protocol
hermes.connect("opencode", {
protocol = Protocol.http,
})
-- configure distribution
hermes.connect("kilo", {
-- Some agents have multiple different distributions; you can specify which to use.
distribution = Distribution.binary, -- "binary", "npx", and/or "uvx"
})
-- connect to custom agent (not pre-defined)
hermes.connect(
"my-claude", -- this will be the key you use for other methods (disconnect for example)
{
protocol = Protocol.socket, -- optional (Defaults to "stdio")
command = "claude-acp",
args = { "--socket", "/tmp/claude.sock" },
}
)
-- connect to TCP socket
hermes.connect(
"copilot",
{
protocol = Protocol.tcp,
host = "localhost",
port = 8080,
}
)
--example
vim.api.nvim_create_autocmd("User", {
group = "hermes",
pattern = Autocommand.AgentList,
callback = function(args)
---@type HermesAgentList
local data = args.data
local agent = table.remove(data.agents) -- select auth method id somehow
hermes.connect(agent.id, {
distribution = table.remove(agent.distributions), -- select distribution somehow
})
end,
})
```
> **Triggers:**
> - [ConnectionInitialized](#connectioninitialized) autocommand upon completion.
> - [Progress](#progress) autocommand if the `distributions.binary.enabled` configuration is enabled (reports binary download progress)
### π Disconnect
Below are examples of how you can disconnect from agent(s).
```lua
local hermes = require("hermes")
-- disconnect from a single agent
hermes.disconnect("copilot");
-- disconnect from a list of agents
hermes.disconnect({ "copilot", "opencode" })
-- disconnect from all agents
hermes.disconnect()
```
### πͺ Logout
Below are examples of how you can log out from agent(s).
```lua
local hermes = require("hermes")
-- logout a single agent
hermes.logout("copilot");
-- logout a list of agents
hermes.logout({ "copilot", "opencode" })
-- logout all agents
hermes.logout()
```
> **Triggers:** [LoggedOut](#loggedout) autocommand upon completion.
### π Authenticate
Handle agent authentication.
```lua
local hermes = require("hermes")
local Autocommand = hermes.Autocommand
-- function signature
hermes.authenticate(auth_method_id)
-- example
vim.api.nvim_create_autocmd("User", {
group = "hermes",
pattern = Autocommand.ConnectionInitialized,
callback = function(args)
---@type HermesConnectionInitialized
local data = args.data
local auth_method_id = table.remove(data.authMethods).id -- select auth method id somehow
hermes.authenticate(auth_method_id)
end,
})
```
> **Triggers:** [Authenticated](#authenticated) on success, or [TerminalAuthentication](#terminalauthentication) when the selected method is terminal.
### π¬ Prompt
> **Note on `promptId`:** All agent notification autocommands (sourced from π€ Agent) include a `promptId` field. This UUID is generated when a prompt is sent (via `prompt()`) or when a user message chunk arrives from the agent, and it is attached to all subsequent notifications for that session so you can correlate messages within a single prompt/response cycle.
Send prompts to the agent
There are five types of prompts you can send to an agent
- [text](https://agentclientprotocol.com/protocol/content#text-content): Human readable prompts
- [link](https://agentclientprotocol.com/protocol/content#resource-link): Links to resources (url, file path, etc)
- [embedded](https://agentclientprotocol.com/protocol/content#embedded-resource): Similar to a link, but including the contents of the resource link (preferred over link if available)
- [image](https://agentclientprotocol.com/protocol/content#image-content): An image (encoded as a base64)
- [audio](https://agentclientprotocol.com/protocol/content#audio-content): Audio content for communication (encoded as base64)
```lua
local hermes = require("hermes")
local Autocommand = hermes.Autocommand
local ContentType = hermes.ContentType
-- single prompt call signature
hermes.prompt(session_id, {
type = ContentType.text,
text = "What time is it?"
})
-- multiple prompt call signature
hermes.prompt(session_id, {
{
type = ContentType.text,
text = "What time is it?"
},
{
type = ContentType.link,
name = "Example file",
uri = "/path/to/example.txt"
},
{ -- text
type = ContentType.embedded,
resource = {
uri = "file:///home/user/script.py",
mimeType = "text/x-python",
text = "def hello():\n print('Hello, world!')"
}
},
{ -- blob
type = ContentType.embedded,
resource = {
uri = "file:///home/user/script.py",
mimeType = "application/pdf",
blob = "Base64-encoded binary data"
}
},
{
type = ContentType.image,
data = "base64-encoded-image-data",
mimeType = "image/png"
},
{
type = ContentType.audio,
data = "base64-encoded-audio-data",
mimeType = "audio/wav"
}
}
-- example
vim.api.nvim_create_autocmd("User", {
group = "hermes",
pattern = Autocommand.SessionCreated,
callback = function(args)
---@type HermesSessionCreated
local data = args.data
local sessionId = data.sessionId
local prompt_id = hermes.prompt(sessionId, {
type = ContentType.text,
text = "What time is it?"
})
end,
})
```
> **Triggers:** [Prompted](#prompted) autocommand upon completion.
### β Create Session
Create a new session. If no arguments are provided, the session defaults to either the project root or the current directory.
```lua
local hermes = require("hermes")
local McpServerType = hermes.McpServerType
-- use default session configuration
hermes.create_session()
-- customize connection configuration
hermes.create_session({
cwd = ".", -- path to create the session in (optional)
additional_directories = {}, -- more directories to include in addition to the root directory (relative paths are relative to cwd)
mcp_servers = {
{ -- Http or Sse MCP server definition
type = McpServerType.http, -- or "sse"
name = "Human readable name for MCP server",
url = "http://url-to-mcp-server.com",
headers = {
{ ["Content-Type"] = "application/json" },
{ header_name = "header value" },
},
},
{ -- Stdio MCP server definition
type = McpServerType.stdio,
name = "Human readable name for MCP server",
command = "/path/to/the/MCP/server/executable",
args = { "run", "--flag", "something" },
-- Environment variables to set when launching the MCP server.
env = {
{ name = "ENVIRONMENT_VAR_NAME", value = "value" },
},
},
},
})
```
> **Triggers:** [SessionCreated](#sessioncreated) autocommand upon completion.
### π Load Session (**Optional**)
Load an existing session (replays session history)
```lua
local hermes = require("hermes")
local Autocommand = hermes.Autocommand
local McpServerType = hermes.McpServerType
local session_id = "some-session-id"
-- call signature (uses defaults)
hermes.load_session(session_id)
-- call signature (with further configuration)
hermes.load_session(session_id, {
cwd = ".", -- path to load the session from (optional, defaults to either project root or current directory)
additional_directories = {}, -- more directories to include in addition to the root directory (relative paths are relative to cwd)
mcp_servers = {
{ -- Http or Sse MCP server definition
type = McpServerType.http, -- or "sse"
name = "Human readable name for MCP server",
url = "http://url-to-mcp-server.com",
headers = {
{ ["Content-Type"] = "application/json" },
{ header_name = "header value" },
},
},
{ -- Stdio MCP server definition
type = McpServerType.stdio,
name = "Human readable name for MCP server",
command = "/path/to/the/MCP/server/executable",
args = { "run", "--flag", "something" },
-- Environment variables to set when launching the MCP server.
env = {
{ name = "ENVIRONMENT_VAR_NAME", value = "value" },
},
},
},
})
-- example
vim.api.nvim_create_autocmd("User", {
group = "hermes",
pattern = Autocommand.SessionCreated,
callback = function(args)
---@type HermesSessionCreated
local data = args.data
local session_id = data.sessionId
hermes.load_session(session_id)
end,
})
```
> **Triggers:** [SessionLoaded](#sessionloaded) autocommand upon completion
### βΆοΈ Resume Session (**Optional**)
Resume an existing session (without replaying the session history)
```lua
local hermes = require("hermes")
local Autocommand = hermes.Autocommand
local McpServerType = hermes.McpServerType
local session_id = "some-session-id"
-- call signature (uses defaults)
hermes.resume_session(session_id)
-- call signature (with further configuration)
hermes.resume_session(session_id, {
cwd = ".", -- path to load the session from (optional, defaults to either project root or current directory)
additional_directories = {}, -- more directories to include in addition to the root directory (relative paths are relative to cwd)
mcp_Servers = {
{ -- Http or Sse MCP server definition
type = McpServerType.http, -- or "sse"
name = "Human readable name for MCP server",
url = "http://url-to-mcp-server.com",
headers = {
{ ["Content-Type"] = "application/json" },
{ header_name = "header value" },
},
},
{ -- Stdio MCP server definition
type = McpServerType.stdio,
name = "Human readable name for MCP server",
command = "/path/to/the/MCP/server/executable",
args = { "run", "--flag", "something" },
-- Environment variables to set when launching the MCP server.
env = {
{ name = "ENVIRONMENT_VAR_NAME", value = "value" },
},
},
},
})
-- example
vim.api.nvim_create_autocmd("User", {
group = "hermes",
pattern = Autocommand.SessionCreated,
callback = function(args)
---@type HermesSessionCreated
local data = args.data
local session_id = data.sessionId
hermes.resume_session(session_id)
end,
})
```
> **Triggers:** [SessionResumed](#sessionresumed) autocommand upon completion
### π List Sessions (**Optional**)
List sessions, can be filtered by project path or cursor pagination.
```lua
local hermes = require("hermes")
local Autocommand = hermes.Autocommand
-- list all sessions
hermes.list_sessions()
-- filter by directory
hermes.list_sessions({
cwd = "/path/to/directory",
})
-- filter by cursor based pagination
hermes.list_sessions({
cursor = "abc123",
})
-- example
vim.api.nvim_create_autocmd("User", {
group = "hermes",
pattern = Autocommand.SessionsListed,
callback = function(args)
---@type HermesSessionsListed
local data = args.data
local next_page = data.nextCursor
-- get next page of sessions with this cursor in the current directory
hermes.list_sessions({
cwd = vim.fn.getcwd(),
cursor = next_page,
})
end,
})
```
> **Triggers:** [SessionsListed](#sessionslisted) autocommand upon completion
### β Close Session (**Optional**)
Close active session and free all resources associated with it
```lua
local hermes = require("hermes")
local Autocommand = hermes.Autocommand
local session_id = "session-id-from-create-session-response"
-- call signature
hermes.close_session(session_id)
-- example
vim.api.nvim_create_autocmd("User", {
group = "hermes",
pattern = Autocommand.SessionCreated,
callback = function(args)
---@type HermesSessionCreated
local data = args.data
local session_id = data.sessionId
hermes.close_session(session_id)
end,
})
```
> **Triggers:** [SessionClosed](#sessionclosed) autocommand upon completion
### ποΈ Delete Session (**Optional**)
Delete session from the session list
```lua
local hermes = require("hermes")
local Autocommand = hermes.Autocommand
local session_id = "session-id-from-create-session-response"
-- call signature
hermes.delete_session(session_id)
-- delete multiple sessions
hermes.delete_session({ session_id, "other-session-id" })
-- cancel session(s) before deleting them (defaults to true; set to false to disable this behavior)
hermes.delete_session(session_id, { cancel = true })
-- example
vim.api.nvim_create_autocmd("User", {
group = "hermes",
pattern = Autocommand.SessionCreated,
callback = function(args)
---@type HermesSessionCreated
local data = args.data
local session_id = data.sessionId
hermes.delete_session(session_id)
end,
})
```
> **Triggers:** [SessionDeleted](#sessiondeleted) autocommand upon completion
> [!WARNING]
### βΉοΈ Cancel (**Optional**)
Cancel the current operation of the agent (e.g., stop generating text, stop a tool call in progress, etc).
```lua
local hermes = require("hermes")
local Autocommand = hermes.Autocommand
local session_id = 'session-id-from-create-session-response'
-- call signature (session ID or pending request ID)
hermes.cancel(session_id)
-- example
vim.api.nvim_create_autocmd("User", {
group = "hermes",
pattern = Autocommand.PermissionRequest,
callback = function(args)
---@type HermesPermissionRequest
local data = args.data
local request_id = data.requestId
hermes.cancel(request_id)
end,
})
```
> **Triggers:** [RequestCancelled](#requestcancelled) autocommand upon completion.
> [!NOTE]
> [RequestCancelled](#requestcancelled) may also be triggered by the agent (agents can cancel requests)
### π― Set mode (**Optional**)
Set what mode the agent is in (the plan/build modes for opencode for example)
```lua
local hermes = require("hermes")
local Autocommand = hermes.Autocommand
local session_id = "some-session-id"
local mode_id = "some-mode-id"
-- call signature
hermes.set_mode(session_id, mode_id)
-- example
vim.api.nvim_create_autocmd("User", {
group = "hermes",
pattern = Autocommand.ModeUpdated,
callback = function(args)
---@type HermesModeUpdated
local data = args.data
print("Mode changed to: " .. data.name)
end,
})
```
> **Triggers:** [ModeUpdated](#modeupdated) autocommand upon completion.
### π― Modes
Get the selectable modes for a session.
```lua
local hermes = require("hermes")
local Autocommand = hermes.Autocommand
-- call signature
hermes.modes(session_id)
-- example
vim.api.nvim_create_autocmd("User", {
group = "hermes",
pattern = Autocommand.Modes,
callback = function(args)
---@type HermesModes
local data = args.data
local options = data.options
for _, option in ipairs(options) do
print("Mode: " .. option.name .. " (value: " .. option.value .. ")")
end
end,
})
```
> **Triggers:** [Modes](#modes-1) autocommand with a `Selection` payload containing:
> - `options` (array): Available mode options
> - `current` (object): The currently selected mode
### π§ Set model (**Optional**)
Set what model the agent is using.
```lua
local hermes = require("hermes")
local Autocommand = hermes.Autocommand
-- call signature
hermes.set_model(sessionId, modelId)
-- example
vim.api.nvim_create_autocmd("User", {
group = "hermes",
pattern = Autocommand.SessionModelUpdated,
callback = function(args)
---@type HermesSessionModelUpdated
local data = args.data
print("Model changed to: " .. data.name)
end,
})
```
> **Triggers:** [SessionModelUpdated](#sessionmodelupdated) autocommand upon completion.
### π§ Models
Get the selectable models for a session.
```lua
local hermes = require("hermes")
local Autocommand = hermes.Autocommand
local session_id = "some-session-id"
-- call signature
hermes.models(session_id)
-- example
vim.api.nvim_create_autocmd("User", {
group = "hermes",
pattern = Autocommand.Models,
callback = function(args)
---@type HermesModels
local data = args.data
local options = data.options
for _, option in ipairs(options) do
print("Model: " .. option.name .. " (value: " .. option.value .. ")")
end
end,
})
```
> **Triggers:** [Models](#models-1) autocommand with a `Selection` payload containing:
> - `options` (array): Available model options
> - `current` (object): The currently selected model
### βοΈ Model configurations
Get the model configuration options for a session.
```lua
local hermes = require("hermes")
local Autocommand = hermes.Autocommand
-- call signature
hermes.model_configurations(session_id)
-- example
vim.api.nvim_create_autocmd("User", {
group = "hermes",
pattern = Autocommand.ModelConfigurations,
callback = function(args)
---@type HermesModelConfigurations
local configs = args.data
for _, config in ipairs(configs) do
print("Config: " .. config.name .. " (current: " .. config.selection.current.value .. ")")
end
end,
})
```
> **Triggers:** [ModelConfigurations](#modelconfigurations) autocommand with an array of model configuration options.
### βοΈ Configure model (**Optional**)
Configure a model option for a session. Takes a table with `id` and `value` keys.
```lua
local hermes = require("hermes")
local Autocommand = hermes.Autocommand
-- call signature
hermes.configure_model(session_id, { id = "context_size", value = "200k" })
-- example
vim.api.nvim_create_autocmd("User", {
group = "hermes",
pattern = Autocommand.ModelConfigurationUpdated,
callback = function(args)
print("Model configuration updated")
end,
})
```
> **Triggers:** [ModelConfigurationUpdated](#modelconfigurationupdated) autocommand upon completion.
### π Set thought_level (**Optional**)
Set the thought level for a session.
```lua
local hermes = require("hermes")
local Autocommand = hermes.Autocommand
-- call signature
hermes.set_thought_level(sessionId, thoughtLevelId)
-- example
vim.api.nvim_create_autocmd("User", {
group = "hermes",
pattern = Autocommand.ThoughtLevelUpdated,
callback = function(args)
---@type HermesThoughtLevelUpdated
local data = args.data
print("Thought level changed to: " .. data.name)
end,
})
```
> **Triggers:** [ThoughtLevelUpdated](#thoughtlevelupdated) autocommand upon completion.
### π Thought levels
Get the selectable thought levels for a session.
```lua
local hermes = require("hermes")
local Autocommand = hermes.Autocommand
-- call signature
hermes.thought_levels(session_id)
-- example
vim.api.nvim_create_autocmd("User", {
group = "hermes",
pattern = Autocommand.ThoughtLevels,
callback = function(args)
---@type HermesThoughtLevels
local data = args.data
local options = data.options
for _, option in ipairs(options) do
print("Thought Level: " .. option.name .. " (value: " .. option.value .. ")")
end
end,
})
```
> **Triggers:** [ThoughtLevels](#thoughtlevels) autocommand with a `Selection` payload containing:
> - `options` (array): Available thought level options
> - `current` (object): The currently selected thought level
### βοΈ Config options
Get all configuration options available for a session.
```lua
local hermes = require("hermes")
local Autocommand = hermes.Autocommand
-- call signature
hermes.config_options(session_id)
-- example
vim.api.nvim_create_autocmd("User", {
group = "hermes",
pattern = Autocommand.ConfigOptions,
callback = function(args)
---@type HermesConfigOptions
local options = args.data
for _, option in ipairs(options) do
print(option.name .. " (" .. option.type .. ") = " .. tostring(option.currentValue))
end
end,
})
```
> **Triggers:** [ConfigOptions](#configoptions) autocommand with the array of all
> configuration options.
### βοΈ Set config option (**Optional**)
Set a single configuration option by id. Takes a table with `id` and `value` keys.
`value` may be a string (for select options) or a boolean (for boolean options).
```lua
local hermes = require("hermes")
local Autocommand = hermes.Autocommand
-- call signature
hermes.set_config_option(session_id, { id = "brave_mode", value = true })
-- example: toggle a boolean option whenever the agent reports new values
vim.api.nvim_create_autocmd("User", {
group = "hermes",
pattern = Autocommand.ConfigOptions,
callback = function(args)
---@type HermesConfigOptions
local options = args.data
for _, option in ipairs(options) do
if option.id == "brave_mode" then
hermes.set_config_option(session_id, {
id = option.id,
value = not option.currentValue,
})
end
end
end,
})
```
> **Triggers:** [ConfigurationUpdated](#configurationupdated) autocommand upon completion.
### β©οΈ Respond
When an agent makes a request that requires user input (such as a permission request), it triggers an autocommand and pauses until the user responds. Use the `respond` method with the request ID to resume the agent's operation. If no autocommand handler is defined, a default workflow will be triggered. Requests can be disabled via the setup configuration.
> [!WARNING]
> While Hermes is a complete ACP client, most agents available today don't fully utilize the protocol. The following autocommands are [optional features](https://agentclientprotocol.com/protocol/overview#optional-methods-2) and often handled through agent-specific tools rather than calling the ACP methods that trigger them. This means some Hermes capabilities may not be exercised depending on which agent you use.
#### π Permission request
```lua
local hermes = require("hermes")
local Autocommand = hermes.Autocommand
-- call signature
hermes.respond("requestId", "optionId")
-- example:
vim.api.nvim_create_autocmd("User", {
group = "hermes",
pattern = Autocommand.PermissionRequest,
callback = function(args)
---@type HermesPermissionRequest
local data = args.data
local selected_option_id = table.remove(data.options).id -- select id somehow
local request_id = data.requestId
hermes.respond(request_id, selected_option_id)
end,
})
```
> **Responds to:** [PermissionRequest](#permissionrequest) autocommand.
>
> **Default behavior:** If no autocommand handler is defined for `PermissionRequest`, Hermes will use the native Neovim select menu to gather a response from the user.
#### βοΈ Write to file
```lua
local hermes = require("hermes")
local Autocommand = hermes.Autocommand
-- call signature
hermes.respond("requestId")
-- example:
vim.api.nvim_create_autocmd("User", {
group = "hermes",
pattern = Autocommand.WriteTextFile,
callback = function(args)
---@type HermesWriteTextFile
local data = args.data
local request_id = data.requestId
-- writing to a file doesn't take any data, but a notification is required when it is finished
hermes.respond(request_id)
end,
})
```
> **Responds to:** [WriteTextFile](#writetextfile) autocommand.
>
> **Default behavior:** If no autocommand handler is defined for `WriteTextFile`, Hermes will:
> - Update buffers if they are open and mark them as modified (will not automatically save)
> - Refresh the view of any modified buffers
> - Write to the file on disk if it is not open in a buffer
#### π Read from file
```lua
local hermes = require("hermes")
local Autocommand = hermes.Autocommand
-- call signature
hermes.respond("requestId", "Hello World!")
-- example:
vim.api.nvim_create_autocmd("User", {
group = "hermes",
pattern = Autocommand.ReadTextFile,
callback = function(args)
---@type HermesReadTextFile
local data = args.data
local requestId = data.requestId
local filename = data.path
local _start = data.line -- optional, may not be provided by the agent
local _end = data.limit -- optional, may not be provided by the agent
local file = io.open(filename, "r")
local content = file:read("*all")
file:close()
hermes.respond(requestId, content)
end,
})
```
> **Responds to:** [ReadTextFile](#readtextfile) autocommand.
>
> **Default behavior:** If no autocommand handler is defined for `ReadTextFile`, Hermes will:
> - Read the file from disk if one is not open in a buffer
> - Read the current state of the open buffer if the target file is open
> - Start at the `line` number if defined
> - End at the `limit` number if defined
#### π Authentication via terminal
```lua
local hermes = require("hermes")
local Autocommand = hermes.Autocommand
-- simple boolean response, true if successful, false if authentication failed
local successfully_authenticated = true;
-- call signature
hermes.respond("requestId", successfully_authenticated);
vim.api.nvim_create_autocmd("User", {
group = "hermes",
pattern = Autocommand.TerminalAuthentication,
callback = function(event)
---@type HermesTerminalAuthentication
local data = event.data
local request_id = data.requestId
-- set up commands
local cmd = vim.list_extend({ data.command }, data.args or {})
local env = vim.tbl_extend("force", vim.fn.environ(), data.env or {})
-- trigger authentication flow
vim.api.nvim_command("botright new")
vim.fn.termopen(cmd, {
env = env,
on_exit = function(_, exit_code)
hermes.respond(request_id, exit_code == 0)
end,
})
end,
})
```
> **Responds to:** [TerminalAuthentication](#terminalauthentication) autocommand.
>
> **Default behavior:** If no autocommand handler is defined for `TerminalAuthentication`, Hermes will:
> - Report terminal authentication as unsupported (no default can be applied)
#### π» Create Terminal for agent communication
```lua
local hermes = require("hermes")
local Autocommand = hermes.Autocommand
local terminals = {}
-- call signature
hermes.respond("requestId", "terminalId")
-- example:
vim.api.nvim_create_autocmd("User", {
group = "hermes",
pattern = Autocommand.TerminalCreate,
callback = function(event)
---@type HermesTerminalCreate
local data = event.data
local terminal_id = "your-generated-terminal-id" -- generate a unique id for terminal
local request_id = data.requestId
local command = data.command
local term_args = data.args or {}
local byte_limit = data.outputByteLimit
-- lua combines args and command (add command to the beginning of args)
table.insert(term_args, 1, command)
terminals[terminal_id] = vim.fn.jobstart(term_args, {
env = data.env,
cwd = data.cwd,
})
hermes.respond(request_id, terminal_id);
end,
})
```
> **Responds to:** [TerminalCreate](#terminalcreate) autocommand.
>
> **Default behavior:** If no autocommand handler is defined for `TerminalCreate`, Hermes will:
> - Create a terminal attached to a buffer (hidden by default)
> - Handle byte limit constraints if defined
> [!WARNING]
> If no `TerminalCreate` autocommand is registered, Hermes will use default functionality to manage **all** subsequent terminal interaction.
#### π€ Provide terminal output to the assistant
```lua
local hermes = require("hermes")
local Autocommand = hermes.Autocommand
local terminals = {}
local is_truncated = true;
-- call signature (truncated defaults to false)
hermes.respond("requestId", "terminal output text")
-- call signature with truncation defined
hermes.respond("requestId", {
output = "terminal output text",
truncated = is_truncated,
})
-- example:
vim.api.nvim_create_autocmd("User", {
group = "hermes",
pattern = Autocommand.TerminalOutput,
callback = function(args)
---@type HermesTerminalOutput
local data = args.data
local requestId = data.requestId
local terminalId = data.terminalId
local terminalOutput = terminals[terminalId].output -- get output somehow
hermes.respond(requestId, terminalOutput);
end,
})
```
> **Responds to:** [TerminalOutput](#terminaloutput) autocommand.
>
> **Default behavior:** If no autocommand handler is defined for [TerminalCreate](#terminalcreate), Hermes will:
> - Collect and send the terminal output to the agent
#### πͺ Reporting terminal exit
```lua
local hermes = require("hermes")
local Autocommand = hermes.Autocommand
local terminals = {}
-- call signature for termination signal
hermes.respond("requestId", "SIGTERM")
-- call signature for exit code
hermes.respond("requestId", 0)
-- call signature with exit code and termination signal
hermes.respond("requestId", {
exitCode = 9,
signal = "SIGKILL"
})
-- example:
vim.api.nvim_create_autocmd("User", {
group = "hermes",
pattern = Autocommand.TerminalExit,
callback = function(args)
---@type HermesTerminalExit
local data = args.data
local requestId = data.requestId
local terminalId = data.terminalId
hermes.respond(requestId, {
exitCode = terminals[terminalId].exitCode, -- get output somehow
signal = terminals[terminalId].signal, -- get output somehow
});
end,
})
```
> **Responds to:** [TerminalExit](#terminalexit) autocommand.
>
> **Default behavior:** If no autocommand handler is defined for [TerminalCreate](#terminalcreate), Hermes will:
> - Wait for and report terminal exit details
#### β‘ Kill terminal process
```lua
local hermes = require("hermes")
local Autocommand = hermes.Autocommand
local terminals = {}
-- call signature with exit code and termination signal
hermes.respond("requestId")
-- example:
vim.api.nvim_create_autocmd("User", {
group = "hermes",
pattern = Autocommand.TerminalKill,
callback = function(args)
---@type HermesTerminalKill
local data = args.data
local request_id = data.requestId
hermes.respond(request_id);
end,
})
```
> **Responds to:** [TerminalKill](#terminalkill) autocommand.
>
> **Default behavior:** If no autocommand handler is defined for [TerminalCreate](#terminalcreate), Hermes will:
> - Stop the process running in the terminal
#### π Release terminal process
```lua
local hermes = require("hermes")
local Autocommand = hermes.Autocommand
local terminals = {}
-- call signature with exit code and termination signal
hermes.respond("requestId")
-- example:
vim.api.nvim_create_autocmd("User", {
group = "hermes",
pattern = Autocommand.TerminalRelease,
callback = function(args)
---@type HermesTerminalRelease
local data = args.data
local request_id = data.requestId
hermes.respond(request_id);
end,
})
```
> **Responds to:** [TerminalRelease](#terminalrelease) autocommand.
>
> **Default behavior:** If no autocommand handler is defined for [TerminalCreate](#terminalcreate), Hermes will:
> - Stop any process running in the terminal
> - Remove the terminal
> - Delete the attached buffer (can be configured to omit this step)
#### π User/Form input (elicitation)
```lua
local hermes = require("hermes")
local Autocommand = hermes.Autocommand
local ElicitationAction = hermes.ElicitationAction
-- Accept and provide content for the requested fields:
hermes.respond("requestId", {
action = ElicitationAction.accept,
content = { name = "Alice", age = 30 },
})
-- Decline without providing content:
hermes.respond("requestId", { action = ElicitationAction.decline })
-- Cancel the elicitation entirely:
hermes.respond("requestId", { action = ElicitationAction.cancel })
-- example:
vim.api.nvim_create_autocmd("User", {
group = "hermes",
pattern = Autocommand.FormElicitation,
callback = function(args)
---@type HermesFormElicitation
local data = args.data
local requestId = data.requestId
local mode = data.mode -- "form"
local message = data.message -- the prompt shown to the user
hermes.respond(requestId, {
action = ElicitationAction.accept,
content = { name = vim.fn.input(message .. ": ") },
})
end,
})
```
> **Responds to:** [FormElicitation](#formelicitation) autocommand.
>
> **Default behavior:** If no autocommand handler is defined for [FormElicitation](#formelicitation), Hermes will:
> - Report that form elicitation is not a supported capability
> - Cancel any elicitation requests it may receive (should not happen when capabilities are reported as unsupported)
#### π Browser input (elicitation)
```lua
local hermes = require("hermes")
local Autocommand = hermes.Autocommand
local ElicitationAction = hermes.ElicitationAction
-- Decline without providing content:
hermes.respond("requestId", { action = ElicitationAction.decline })
-- Cancel the elicitation entirely:
hermes.respond("requestId", { action = ElicitationAction.cancel })
-- example:
vim.api.nvim_create_autocmd("User", {
group = "hermes",
pattern = Autocommand.UrlElicitation,
callback = function(args)
---@type HermesUrlElicitation
local data = args.data
local requestId = data.requestId
hermes.respond(requestId, { action = ElicitationAction.decline })
end,
})
```
> **Responds to:** [UrlElicitation](#urlelicitation) autocommand.
>
> **Default behavior:** If no autocommand handler is defined for [UrlElicitation](#urlelicitation), Hermes will:
> - Report that url elicitation is not a supported capability
> - Cancel any elicitation requests it may receive (should not happen when capabilities are reported as unsupported)
## π‘ Autocommands
Hermes generates autocommands for all communication between agent and client. Here's an example of hooking into one:
```lua
local hermes = require("hermes")
local Autocommand = hermes.Autocommand
vim.api.nvim_create_autocmd("User", {
group = "hermes",
pattern = Autocommand.AgentTextMessage,
callback = function(args)
---@type HermesAgentTextMessage
local data = args.data
print("Received some text from our assistant: " .. data.update.content.text)
end,
})
```
Below is a list of all autocommands and their associated data (passed to the callback in the `args.data` field). Hermes will only trigger autocommands if there is a listener defined for it (I.E. You have created one like the example above)
> [!TIP]
> Every autocommand's payload has a corresponding LuaLS class named after the autocommand (e.g. `AgentTextMessage` delivers a `HermesAgentTextMessage` payload, `PermissionRequest` delivers a `HermesPermissionRequest`, `ConfigOptions` delivers a `HermesConfigOptions` array). Cast `args.data` inside your callback β as in the example above β to get completion and type checking for the payload fields.
| Autocommand | Description | Source | Schema |
|---|---|---|---|
AgentImageMessage |
An image from the agent | π€ Agent | |
AgentImageThought |
Visual reasoning/thought from the agent | π€ Agent | |
AgentList |
List of available agents | β‘ agents() | |
AgentResourceLinkMessage |
A resource link from the agent | π€ Agent | |
AgentResourceLinkThought |
Resource link thought from the agent | π€ Agent | |
AgentResourceMessage |
A resource from the agent | π€ Agent | |
AgentResourceThought |
Resource-based thought from the agent | π€ Agent | |
AgentTextMessage |
A text message from the agent | π€ Agent | |
AgentTextThought |
Textual thought/reasoning from the agent | π€ Agent | |
Authenticated |
Authentication completed | β‘ authenticate() | |
AvailableCommands |
Available commands are updated | π€ Agent | |
CompactionSummaryChunk |
Streamed chunk of a compaction summary | π€ Agent | |
CompactionUpdate |
Status update for a context compaction | π€ Agent | |
ConfigOptions |
All configuration options for a session | β‘ config_options() | |
ConfigurationOption |
Configuration option updates | π€ Agent | |
ConfigurationUpdated |
Session configuration updated | β‘ set_config_option() / configure_model() | |
ConnectionInitialized |
Connection established with agent | β‘ connect() | |
ElicitationComplete |
Agent notifies that an elicitation has completed | π€ Agent (notification) | |
FormElicitation |
Agent requests form-based elicitation (structured user input) | π€ Agent (requires -> respond()) | |
LoggedOut |
Agent logout completed | β‘ logout() | |
ModeCurrent |
Current mode changes | π€ Agent | |
ModelConfigurations |
Available model configuration options retrieved | β‘ model_configurations() | |
ModelConfigurationUpdated |
Model configuration options updated | β‘ configure_model() | |
Models |
Available models retrieved | β‘ models() | |
Modes |
Available modes retrieved | β‘ modes() | |
ModeUpdated |
Session mode changed | β‘ set_mode() | |
Notice |
Informational notice for the user | π€ Agent | |
PermissionRequest |
Agent requests permission to execute a tool | π€ Agent (requires -> respond()) | |
Plan |
Agent generates a plan | π€ Agent | |
Progress |
Download progress update (binary, registry, agent) | β‘ :Hermes install, :Hermes update, agents(), connect(), setup() | |
Prompted |
Agent response received | β‘ prompt() | |
ReadTextFile |
Agent requests to read a text file | π€ Agent (requires -> respond()) | |
RequestCancelled |
Cancelled a pending request (Can be triggered by the user or the agent) | π€ Agent (notification), β‘ cancel() | |
SessionClosed |
Active session closed | β‘ close_session() | |
SessionCreated |
New session created | β‘ create_session() | |
SessionDeleted |
Session deleted | β‘ delete_session() | |
SessionForked |
Session forked successfully | β‘ fork_session() | |
SessionLoaded |
Session loaded successfully | β‘ load_session() | |
SessionModelUpdated |
Session model updated | β‘ set_model() | |
SessionResumed |
Session resumed successfully | β‘ resume_session() | |
SessionsListed |
Session list received | β‘ list_sessions() | |
SessionUpdate |
Session metadata updated (title, timestamps, etc.) | π€ Agent | |
TerminalAuthentication |
Terminal auth method selected, run it in a terminal | β‘ authenticate() | |
TerminalCreate |
Agent requests to create a terminal for command execution | π€ Agent (requires -> respond()) | |
TerminalExit |
Agent requests notification when terminal process exits | π€ Agent (requires -> respond()) | |
TerminalKill |
Agent requests to kill a terminal process | π€ Agent (requires -> respond()) | |
TerminalOutput |
Agent requests terminal output | π€ Agent (requires -> respond()) | |
TerminalRelease |
Agent requests to release a terminal | π€ Agent (requires -> respond()) | |
ThoughtLevels |
Available thought levels retrieved | β‘ thought_levels() | |
ThoughtLevelUpdated |
Session thought level updated | β‘ set_thought_level() | |
ToolCall |
Agent makes a tool call | π€ Agent | |
ToolCallUpdate |
Tool call is updated (e.g., progress, output) | π€ Agent | |
UrlElicitation |
Agent requests URL-based elicitation (direct user to a browser URL) | π€ Agent (requires -> respond()) | |
UsageUpdate |
Session usage metrics update (tokens, cost) | π€ Agent | |
UserImageMessage |
An image sent from the client | π€ Agent | |
UserResourceLinkMessage |
A resource link from the client | π€ Agent | |
UserResourceMessage |
A resource sent from the client | π€ Agent | |
UserTextMessage |
Message text sent from the client | π€ Agent | |
WriteTextFile |
Agent requests to write to a text file | π€ Agent (requires -> respond()) | |