Documentation
¶
Overview ¶
Package hermes reads sessions from Hermes Agent's SQLite state database.
Hermes Agent (Nous Research's hermes-agent) keeps every conversation it has — in its own CLI and TUI, in cron jobs, in a Telegram chat through its gateway — in one database, `<hermes home>/state.db`. The `sessions` table carries per-session token counters and Hermes's own cost figure, and `messages` keeps the prose, the prompts and the tool calls. Reading it is a translation job, as OpenCode's is: the numbers arrive finished and are mapped onto Caprock's event model, never recomputed.
The database belongs to another program that is writing to it while we read. It is opened with mode=ro, which never takes a write lock, and a busy timeout, so a moment where Hermes holds the database is a wait rather than an error. It is never opened with immutable=1: Hermes runs in WAL mode, and an immutable open both misses whatever sits in the WAL and may read a page mid-change. Nothing here writes, creates or migrates anything.
Everything below was read from Hermes Agent v0.21.6's own source (hermes_state_common.py, hermes_state_usage.py, agent/usage_pricing.py, agent/session_source.py, hermes_state_ids.py) on 2026-10-15; see .ai/24-hermes.md.
Index ¶
- Constants
- func Background(source string) bool
- func DBPath() string
- func Home() string
- func IDTime(id string) (time.Time, bool)
- func Open(path string) (*sql.DB, error)
- func ToolInput(hermes string, in map[string]any, cwd string) map[string]any
- func ToolName(hermes string) string
- type Ingester
- type Message
- type Session
- type Stats
- type ToolCall
Constants ¶
const ( BasisActual = "actual" // the provider reported what it billed BasisEstimated = "estimated" // Hermes priced the tokens from its own table BasisIncluded = "included" // a subscription route: no per-call invoice BasisUnknown = "unknown" // Hermes could not price it )
Cost bases, as the UI labels them.
const Agent = "hermes"
Agent is the value sessions read from Hermes carry in sessions.agent.
const EnvHome = "HERMES_HOME"
EnvHome is Hermes's own override for its data directory.
Variables ¶
This section is empty.
Functions ¶
func Background ¶
Background reports whether nobody was reading the session as it ran. Hermes defines its attended sources itself (agent/session_source.py, ATTENDED_SOURCES): its CLI, TUI, desktop app and ACP editors. Everything else — cron, a Telegram or Slack chat through the gateway, a one-shot run, a kanban worker — is work that happened without a person watching it.
func Home ¶
func Home() string
Home is the directory Hermes keeps its state in, resolved the way Hermes resolves it (hermes_constants.get_hermes_home): HERMES_HOME when set, else %LOCALAPPDATA%\hermes on Windows and ~/.hermes everywhere else. "" when no home directory can be found at all.
func IDTime ¶
IDTime is the moment Hermes's own session id was minted, when the id has the CLI's `YYYYMMDD_HHMMSS_<hex>` shape (hermes_state_ids.new_session_id), in local time as Hermes writes it. The CLI mints the id when it starts and creates the row only on the first message, so this — not started_at — is when a process Caprock spawned began.
func Open ¶
Open opens Hermes's database read-only. SQLite opens lazily, so a file that is not a database (or one that is locked) is only found out on the first query; callers read Sessions once before announcing anything.
func ToolInput ¶
ToolInput reshapes a call's arguments into a Claude Code hook payload's tool_input: Hermes's `path` becomes `file_path` for the file tools (a relative one resolved against the session's folder, so per-directory attribution places it), and stays `path` for a search. Every other key is kept as Hermes wrote it.
Types ¶
type Ingester ¶
type Ingester struct {
// Link files a session under the Caprock session that started it, when
// Caprock did (internal/sessionlink). Nil keeps Hermes's own ids.
Link *sessionlink.Linker
// contains filtered or unexported fields
}
Ingester copies Hermes's sessions into Caprock's store.
It polls, as the OpenCode reader does: Hermes has outbound webhooks and shell hooks, but cost lives only in state.db, and the database is the one source that also carries history from before Caprock was installed.
Hermes keeps usage per session, not per message: every API call adds its tokens and its cost to the session's counters (update_token_counts, the delta path — the only one 0.21.6 uses). So the importer reconciles. Each pass it compares the session's counters with what Caprock has stored for it and records the difference on the newest assistant message of the pass, or, when no new message arrived with it, on a usage record of its own. Caprock's totals therefore equal Hermes's, whatever order messages and counters were flushed in, and a re-read or a restart adds nothing: the difference is zero.
Every write is keyed — messages by Hermes's message id, usage records by the counters they bring the session up to — and `(session_id, key)` is unique in the store.
func NewIngester ¶
NewIngester builds an ingester over an already-open Hermes database.
type Message ¶
type Message struct {
ID int64
SessionID string
Role string // user, assistant, tool, system
Content string
ToolName string
ToolCalls string // JSON, OpenAI's shape
At time.Time
// Summary marks the synthetic summary Hermes writes when it compresses a
// conversation: its words, not the model's reply.
Summary bool
}
Message is one row of Hermes's `messages` table.
type Session ¶
type Session struct {
ID string
Source string // cli, tui, desktop, acp, cron, telegram, oneshot, …
ParentID string
Model string
Title string
Cwd string
Branch string
Started time.Time
Ended time.Time
EndReason string
LastActivity time.Time
// The cumulative counters Hermes keeps per session. InputTokens is fresh
// input: Hermes's prompt is input + cache read + cache write
// (CanonicalUsage.prompt_tokens), the same split as Caprock's.
InputTokens, OutputTokens int64
CacheReadTokens, CacheWriteTokens int64
ReasoningTokens int64
APICalls, ToolCalls, Messages int64
BillingProvider, BillingMode string
CostStatus, CostSource string
Estimated, Actual sql.NullFloat64
// The model_config markers Hermes writes on a child row, which say what
// kind of child it is (hermes_state_common.py, delegate_tool.py).
DelegateFrom, BranchedFrom, ResetFrom string
}
Session is one row of Hermes's `sessions` table, with the figures Caprock uses. Times are Hermes's own unix seconds converted to time.Time; a zero time means the column was NULL.
func Sessions ¶
Sessions reads every session, oldest first, so a parent is always read before the children it spawned.
func (Session) Cost ¶
Cost is the session's spend and what kind of figure it is. Hermes's actual figure wins when Hermes says it is real — status "actual", or a source that is the provider's own billing — and is recorded; otherwise its estimate. A subscription route is priced at zero and called that. ok is false when Hermes has no figure at all, which Caprock shows as unpriced rather than as a guess (rule 6).
A provider profile may hand Hermes the provider's own figure as the call's cost (providers/base.py get_usage_cost, "distinguish estimates from invoices"); Hermes then writes it to estimated_cost_usd with status "actual" and leaves actual_cost_usd empty, so that pair reads as actual too. Hermes's own readers take COALESCE(actual_cost_usd, estimated_cost_usd) (hermes_state_maintenance.py), which is the same figure.
type Stats ¶
type Stats struct {
Sessions int `json:"sessions"`
Events int `json:"events"`
Unpriced int `json:"unpriced,omitempty"`
Background int `json:"background,omitempty"`
LastPoll int64 `json:"last_poll_ms,omitempty"`
}
Stats is what the daemon reports about the Hermes reader.
type ToolCall ¶
type ToolCall struct {
ID string
Name string // Hermes's own name: terminal, read_file, patch, …
Input map[string]any
}
ToolCall is one call an assistant message asked for.