Documentation
¶
Overview ¶
Package hermeshost is the host half of Hermes mirroring (docs/design/hermes.md, Phase 2): what muster-mirror reads from a Hermes home — the terminal breadcrumbs, the SQLite session store, the shell-hook allowlist — and the status files its own `muster-mirror hermes-hook` writes.
🔴 IT NEVER WRITES HERMES DATA, WITH ONE EXCEPTION THAT IS NOT THE DAEMON: the shell-hook allowlist writer (allowlist.go), which only the host's Home Manager activation runs (`muster-mirror hermes-allowlist`), never the mirroring daemon. ⚠ "Never writes data" is not "creates no file": SQLite's read-only connection to a WAL database creates state.db-wal and state.db-shm when they do not exist (a WAL reader needs the shared-memory index), as any Hermes reader does. It writes no row.
🔴 AND ONLY THESE FILES. state.db holds whole conversations; the same home holds auth.json, .env, config.yaml (which can carry inline keys), pastes/ (Hermes's on-disk copies of large pastes, muster's messages included) and more. Every path under a Hermes home is built HERE, from Home.dir, which no other file of this package may read (TestOnlyHomeGoReadsTheHermesHome), and TestTheHermesHomeLedger watches, with inotify, every file under the home that the exercised read paths open (the locator, the transcript reader, the consent check — listed in its exerciseReadPath) and fails when one is outside ReadPaths. A reader added without an exercise there is not watched.
🔴 NO READ FOLLOWS A SYMLINK OR WAITS ON A FIFO: every file is opened with O_NOFOLLOW|O_NONBLOCK|O_NOCTTY and must be a regular file (openRegular), so a planted `terminal-sessions/tty-…` → `../auth.json` is refused before a byte is read, and a FIFO cannot hang the listing. The one symlink allowed is the allowlist's into the Nix store (a Home Manager file). And no error ever quotes a file's content.
Index ¶
- Constants
- Variables
- func BreadcrumbName(tty string) string
- func CheckIdle(s termscreen.Screen) error
- func CheckPasted(s termscreen.Screen, text string) error
- func Collapses(text string) bool
- func DefaultHomeDir(getenv func(string) string) string
- func GatewayMasked(s string) bool
- func HandleHook(in io.Reader, dir StatusDir, now time.Time, writer Writer) error
- func HasViLabel(text string) bool
- func HookCommand(bin string) string
- func InputRow(s termscreen.Screen) string
- func InputRows(text string, promptWidth, columns int) int
- func InputWidth(s termscreen.Screen) int
- func IsScreenRefusal(err error) (string, bool)
- func LooksLikeHermes(s termscreen.Screen) bool
- func MusterHookCommand(command string) bool
- func NonTerminalLabel(s string) bool
- func PendingTerminalCommandsOf(rows []Row) []string
- func PromptWidth(s termscreen.Screen) int
- func Render(r Row) []cctranscript.Event
- func SameLineage(a, b Lineage) bool
- func ValidHookCommand(command string) error
- type AllowlistCheck
- type ApprovalPrompt
- type Believed
- type Breadcrumb
- type ClarifyQuestion
- type DeclaredHook
- type Fingerprint
- type Gateway
- type Home
- func (h Home) Attach(ctx context.Context, session string) (*Viewer, []ApprovalPrompt, error)
- func (h Home) CheckAllowlist(command string) (AllowlistCheck, error)
- func (h Home) DeclaredHooks() ([]DeclaredHook, error)
- func (h Home) Identify(ctx context.Context) (Gateway, error)
- func (h Home) OpenState() *State
- func (h Home) ReadBreadcrumb(tty string) (Breadcrumb, error)
- func (h Home) String() string
- func (h Home) ViMode() (bool, error)
- func (h Home) WriteAllowlist(command string, now time.Time) (changed bool, err error)
- type LabelShape
- type Lineage
- type Locator
- type Page
- type PaneSession
- type Row
- type ScreenRefusal
- type Session
- type Snapshot
- type State
- func (s *State) Backfill(ctx context.Context, root string, n int) (Page, error)
- func (s *State) Close() error
- func (s *State) DisplayKeys(ctx context.Context, ids []int64) (map[int64]string, error)
- func (s *State) Home() Home
- func (s *State) PendingClarify(ctx context.Context, root string) ([]ClarifyQuestion, error)
- func (s *State) PendingTerminalCommands(ctx context.Context, root string) ([]string, error)
- func (s *State) Snapshot(ctx context.Context, id string) (Snapshot, error)
- func (s *State) Tail(ctx context.Context, root string, cursor int64, limit int) (Page, error)
- type StatusDir
- type StatusFile
- type Viewer
- type ViewerEvent
- type Writer
Constants ¶
const ( ReasonNoStatusFile = "" /* 133-byte string literal not displayed */ ReasonWriterGone = "the Hermes gateway that wrote the status has exited" ReasonNoLease = "the status says a turn is running but no turn lease is live" ReasonLeaseLive = "the status says idle but a turn lease is live" ReasonNewerMessage = "the status says idle but the conversation has a newer message" )
The reasons a status is unknown, as -list -hermes prints them.
const ( EventPreLLMCall = "pre_llm_call" EventHumanInputRequest = "on_human_input_request" EventHumanInputResolved = "on_human_input_resolved" EventSessionEnd = "on_session_end" EventSessionFinalize = "on_session_finalize" )
The events the hook is registered for, and what each writes.
const ( NoViewNoBreadcrumb = "" /* 129-byte string literal not displayed */ NoViewOldBreadcrumb = "the breadcrumb predates the Hermes process in the pane (it is a previous CLI's)" NoViewNoSession = "the breadcrumb's session is not in state.db" NoViewArchived = "the breadcrumb's session is archived or hidden" NoViewSwitched = "the terminal switched sessions (/resume or /branch)" )
The reasons a pane has no rendered view, as -list -hermes prints them.
const ( ScreenNoLayout = "the pane does not show Hermes's input area as muster knows it" ScreenBelow = "" /* 145-byte string literal not displayed */ ScreenNoStatusBar = "" /* 183-byte string literal not displayed */ ScreenStash = "Hermes's prompt-stash panel is open" ScreenTooShort = "the pane is too short to show anything above Hermes's status bar, where an open stash panel would be (make the pane taller)" ScreenVi = "Hermes's status bar shows a vi-mode label, and muster never sends to Hermes in vi mode" ScreenImages = "images are attached in Hermes's input box, and Enter would send them with the message" ScreenNotIdle = "Hermes's input line is not its idle prompt (a question, an approval, a password prompt or a turn is on screen)" ScreenText = "Hermes's input box already holds text" ScreenNotPasted = "Hermes's input box does not hold exactly the message after the paste" )
The screen check's refusals, as a person reads them (after "Not sent: ").
const ( // MaxApprovalCommand bounds a command, in runes, before the wire's own // caps. MaxApprovalCommand = 2000 // MaxApprovalDescription bounds a description, in runes. MaxApprovalDescription = 500 )
The bounds of an approval as the viewer keeps it.
const ( // EventApprovalRequest: a new approval (Prompt). EventApprovalRequest = "approval.request" // EventApprovalSettled: the approval PromptID was answered. EventApprovalSettled = "approval.settled" )
The kinds of ViewerEvent.
const DefaultStatusDir = "~/.muster/hermes-status"
DefaultStatusDir is where the status files live unless the daemon says otherwise: muster's own directory, 0700.
const EndReasonCompression = "compression"
EndReasonCompression is the end_reason of a session that continued in a compression child (the legacy rotation, compression.in_place: false).
const HookSubcommand = "hermes-hook"
HookSubcommand is the muster-mirror verb Hermes runs as the hook.
const MaxInputRows = 8
MaxInputRows is the most rows Hermes's input area shows (its Dimension max).
const Pin = "5fc490e2b34123212d73ef316086f939567a725a"
Pin is the Hermes commit muster supports (docs/design/hermes.md, Versions).
Variables ¶
var ( // ErrNoGateway is errNoGateway, for a caller to tell "none running" from // a refusal. ErrNoGateway = errNoGateway // ErrGatewayUnsafe is errGatewayUnsafe. ErrGatewayUnsafe = errGatewayUnsafe // ErrGatewayNotPin: the gateway booted from another commit than Pin. ErrGatewayNotPin = errors.New("the Hermes gateway is not the pinned commit") // ErrGatewayNotReady: the gateway answered, but not as a ready owner of // this home muster can attach to (starting, draining, another profile, // no session authority). ErrGatewayNotReady = errors.New("the Hermes gateway is not ready for a viewer") // ErrGatewayProtocol: the gateway's answer is not what the pin answers. ErrGatewayProtocol = errors.New("the Hermes gateway answered something muster cannot read") )
var ( // ErrApprovalRefused: the gateway did not take the answer (already // settled, timed out, another generation). Nothing was answered. ErrApprovalRefused = errors.New("Hermes did not take the answer") // ErrViewerNotSent: the request never reached the gateway (the viewer had // ended, or the write failed). Nothing was answered. ErrViewerNotSent = errors.New("the request did not reach Hermes's gateway") // ErrViewerNoAnswer: the request was sent and no answer came (a timeout, // or the gateway hung up): its outcome is unknown. ErrViewerNoAnswer = errors.New("Hermes's gateway did not answer") )
DiagnosticReadPaths is what `-list -hermes` may open under a Hermes home: the daemon's ReadPaths and config.yaml, of which it decodes `hooks:` only.
var ErrAllowlistUnreadable = errors.New("the shell-hook allowlist is not a JSON object with an approvals list; fix or remove it by hand")
ErrAllowlistUnreadable: the current allowlist is not a JSON object with an approvals list. The writer refuses to replace it (it would drop whatever the person approved); Hermes itself treats it as empty.
var ErrConfigUnreadable = errors.New("config.yaml's hooks section could not be read")
ErrConfigUnreadable: config.yaml is not YAML whose hooks section is the shape Hermes reads. Never the decoder's error, which quotes the file.
var ErrIgnored = errors.New("ignored")
ErrIgnored: the event is not one the hook writes for, or names no valid session; nothing was written, and that is not a failure.
var ErrNoBreadcrumb = errors.New("no breadcrumb for this terminal")
ErrNoBreadcrumb: the terminal has no breadcrumb (Hermes's session.terminal_continue is off, or the CLI has not attached yet).
var ErrNoSession = errors.New("state.db has no such session")
ErrNoSession: state.db has no session with the id asked for.
var ErrSchema = errors.New("state.db is not the schema this muster-mirror reads")
ErrSchema: state.db does not have a column this reader needs.
var ErrViModeUnreadable = errors.New("config.yaml's display section could not be read")
ErrViModeUnreadable: config.yaml's display section is not the shape Hermes reads. Never the decoder's error, which quotes the file.
var GatewayMasks = []string{"***", "...", "«redacted", "[REDACTED"}
THE GATEWAY'S OWN MASKS (audit #212). Before an approval reaches any client, the pinned Hermes rewrites its command twice: redact_sensitive_text in the approval gate (P:tools/approval.py:855), then _redact_approval_command in the gateway (P:gateway/run.py:577, the same redactor with force=True). A mask can swallow shell syntax — measured: `ls -H X-Api-Key:a;rm -rf ~/work` arrives as `ls -H X-Api-Key:*** -rf ~/work` — so a command carrying ANY of its masks is not the command that runs, and muster never offers to approve it from a card.
⚠ A MASK IS NOT THE ONLY REWRITE: the redactor can also DROP characters without leaving one (a value of only control or zero-width characters becomes empty; edges are trimmed). That is caught by approvable's other rules, not here: the command must be printable ASCII and equal the RAW command of a pending terminal call in the conversation.
The forms, read from the pinned agent/redact.py (the literals its mask functions emit); TestTheGatewayMasksCoverAPinnedSample (livehermes) pins that file by sha256 and runs a SAMPLE through both passes:
- "***" the placeholder (mask_secret, _mask_token, the assignment, header, URL and repr passes); "****" (a phone's middle) contains it;
- "..." mask_secret's head...tail form;
- "«redacted" the non-reusable sentinels («redacted:…», «redacted-secret», «redacted-vault-secret»);
- "[REDACTED" [REDACTED PRIVATE KEY].
("[redacted: nesting limit]" is the structure walker's, never a string redaction's: not listed.) ⚠ "..." also appears in commands nobody masked (`git diff a...b`): such a command is offered deny only — a false refusal, the safe way round.
var HookEvents = []string{EventPreLLMCall, EventHumanInputRequest, EventHumanInputResolved, EventSessionEnd, EventSessionFinalize}
HookEvents is every event the host's Hermes config must register the hook for, in the order the docs list them. The allowlist writer makes exactly these (event, command) pairs present.
var NonTerminalLabels = []LabelShape{
{Prefix: "<", Suffix: "> (plugin approval rule)"},
{Prefix: "<write to ", Suffix: ">"},
{Prefix: "computer_use: "},
{Prefix: "execute_code <<"},
}
THE NON-TERMINAL GATES' LABELS (audit #212, round 3). The description allowlist above is not enough on its own: a plugin's approval rule (P:tools/approval.py request_tool_approval, reached from P:hermes_cli/plugins.py's pre_tool_call) takes its description from the PLUGIN's reason — free text, which can equal a terminal description — and shows the label `<tool> (plugin approval rule)`. An injected model can then issue, in one batch, the plugin-gated call AND a `terminal` call whose command is that very label: both checks pass, and "once" would approve the plugin-gated call, which the card never showed. So a command shaped like any pinned non-terminal gate's label is never offered "once", whatever its description and whatever is pending.
The shapes, read from the pin (TestTheApprovalGatesMatchThePin (livehermes) re-extracts every approval site and evaluates each label's f-string through NonTerminalLabel, so a pin bump that adds a gate or changes a label is RED):
- `<{tool_name}> (plugin approval rule)` — P:tools/approval.py request_tool_approval;
- `<write to {…}>` — P:tools/file_tools_write_guards.py, the SSH-config write guard and the protected agent-instruction write guard;
- `computer_use: {…}` — P:tools/computer_use/tool.py _request_approval;
- `execute_code <<'PY'\n…` — P:tools/approval.py check_execute_code_guard (several lines, so never "once" anyway).
The other non-terminal gates — an MCP elicitation, an untrusted MCP tool, a payment-card fill (P:tools/approval_prompt.py request_elicitation_consent) — show free text with a fixed-format description no terminal gate emits, so the description allowlist refuses them; and an `edit` approval carries a diff (ApprovalPrompt.Unshown).
var ReadPaths = []string{
"state.db",
"state.db-wal",
"state.db-shm",
"terminal-sessions/tty-*",
"shell-hooks-allowlist.json",
"gateway.sock",
"gateway.sock.path",
}
THE ALLOWLIST. ReadPaths is every path under a Hermes home that muster-mirror's read path opens, as globs relative to the home (SQLite opens state.db's -wal and -shm itself, as part of opening state.db).
🔴 NEVER auth.json, .env, config.yaml, profiles/*/.env, memories/, skills/, logs/, telemetry/, pastes/, or runtime/active_sessions.json (not authoritative: S3). A new entry here is a design change: it is reviewed against docs/design/hermes.md's "Secret hygiene", and the ledger test that holds this list must change with it.
var TerminalDescriptions = map[string]bool{}/* 111 elements not displayed */
THE TERMINAL GATE'S DESCRIPTIONS (audit #212, round 2). The pinned Hermes asks for approval through more than one gate, and every one reaches the viewer with the same fields: a terminal command (P:tools/approval.py's check_dangerous_command / check_all_command_guards, whose description is detect_dangerous_command's), but also a file write guard (P:tools/file_tools_write_guards.py:389, "command" = the LABEL `<write to …/.ssh/config>`), a plugin's approval rule (`<tool> (plugin approval rule)`), computer use (`computer_use: …`) and execute_code. Only the first approves a command that IS what will run.
So muster offers "once" only for an approval whose description is one the TERMINAL gate emits — this list, read from the pinned P:tools/approval_detection.py: every DANGEROUS_PATTERNS description, _PARSER_LIMIT_DESCRIPTION, _MALFORMED_EXEC_DESCRIPTION, _GATEWAY_LIFECYCLE_SPLICE_DESCRIPTION and the static execution-flag findings — AND whose command is a pending `terminal` call's command in the conversation (State.PendingTerminalCommands): an allowlist. (A plugin rule's description is plugin text and can be on it, so NonTerminalLabels below refuses the label shapes too — on top of the allowlist, never in place of it.) ("arbitrary program execution via …", built at run time, is not listed: such an approval is deny only, the safe way round.) TestTheTerminalGateLedgerMatchesThePin (livehermes) re-extracts the list from the pin and pins both source files by sha256, so a pin bump that adds a pattern or a gate is RED.
var ViLabels = map[string][3]string{
"af": {"INVOEG", "VERVANG", "NORMAAL"},
"ar": {"إدراج", "استبدال", "عادي"},
"de": {"EINFÜGEN", "ERSETZEN", "NORMAL"},
"en": {"INSERT", "REPLACE", "NORMAL"},
"es": {"INSERTAR", "REEMPLAZAR", "NORMAL"},
"fr": {"INSERTION", "REMPLACEMENT", "NORMAL"},
"ga": {"IONSÁIGH", "IONADAIGH", "GNÁTH"},
"hu": {"BESZÚRÁS", "CSERE", "NORMÁL"},
"it": {"INSERT", "REPLACE", "NORMAL"},
"ja": {"INSERT", "REPLACE", "NORMAL"},
"ko": {"INSERT", "REPLACE", "NORMAL"},
"pt": {"INSERIR", "SUBSTITUIR", "NORMAL"},
"ru": {"ВСТАВКА", "ЗАМЕНА", "ОБЫЧНЫЙ"},
"tr": {"EKLE", "DEĞİŞTİR", "NORMAL"},
"uk": {"ВСТАВКА", "ЗАМІНА", "ЗВИЧАЙНИЙ"},
"zh": {"插入", "替换", "普通"},
"zh-hant": {"INSERT", "REPLACE", "NORMAL"},
}
ViLabels is the vi-mode label of Hermes's status bar in every language Hermes bundles at the pin, by language: cli.status_bar.vim_insert, vim_replace and vim_normal of P:locales/<lang>.yaml, for the 17 of SUPPORTED_LANGUAGES (P:agent/i18n.py:33-36).
🔴 EXTRACTED FROM THE PINNED SOURCE, AND CHECKED AGAINST IT: TestViLabelsMatchThePinnedLocales (build tag livehermes, `make test-livehermes`) re-reads the installed Hermes's locales and fails on any difference, so a pin bump re-extracts them.
⚠ DEFENCE IN DEPTH, NEVER A GATE (docs/design/hermes.md, vi mode): the label is the last status-bar fragment, the first a narrow pane trims, absent when the bar is hidden, and a plugin pack or a user overlay can change it. A host whose Hermes uses vi mode must not enable -hermes-send at all.
var WritePaths = []string{
"shell-hooks-allowlist.json.lock",
".shell-hooks-allowlist.json.*.tmp",
"shell-hooks-allowlist.json",
}
WritePaths is every path under a Hermes home the allowlist WRITER (not the daemon) opens to write: Hermes's own lock file, a temp file, and the allowlist it renames into place.
Functions ¶
func BreadcrumbName ¶
BreadcrumbName is the file name Hermes gives the breadcrumb of the terminal whose device is tty (/dev/pts/3 → tty-dev-pts-3): the device path stripped of whitespace and of leading and trailing '/', every character outside [A-Za-z0-9._-] replaced by '-', at most 120 characters (P:hermes_cli/terminal_breadcrumbs.py, _sanitize and get_terminal_id). "" for a tty that is not a device path.
func CheckIdle ¶
func CheckIdle(s termscreen.Screen) error
CheckIdle is the screen check before a paste: nil when s shows Hermes's idle, empty input line in its full frame, else a *ScreenRefusal.
func CheckPasted ¶
func CheckPasted(s termscreen.Screen, text string) error
CheckPasted is the screen check after the paste, before Enter: s must show the same frame and status bar as CheckIdle, the idle prompt, and in the input box EXACTLY text — compared with every space removed, since the box wraps it — or exactly one collapse placeholder whose line count is text's. Anything else is a *ScreenRefusal (ScreenNotPasted when only the box's contents are wrong).
func Collapses ¶
Collapses reports whether Hermes, at its default thresholds, replaces a bracketed paste of text with a placeholder: 5 or more newlines, or 2,000 or more characters (P:hermes_cli/cli_tui_mixin.py:1691-1696, :1724-1727; paste_collapse_threshold counts NEWLINES, so it is 6 lines, not 5).
func DefaultHomeDir ¶
DefaultHomeDir is the Hermes home a Hermes CLI started with getenv's environment uses: $HERMES_HOME, else ~/.hermes. "" when neither can be found.
func GatewayMasked ¶
GatewayMasked reports whether s carries any of the gateway's masks.
func HandleHook ¶
HandleHook writes the status file payload's event calls for, into dir, at now, recording writer. ErrIgnored for an event it does not handle or a session id it does not accept (the gateway also fires hooks for API, cron and bot sessions, whose ids are validated the same way).
func HasViLabel ¶
HasViLabel reports whether status-bar text holds a vi-mode label as a whole word, in any bundled language. A session title that happens to hold one is a false refusal, which is safe.
func HookCommand ¶
HookCommand is the hook's command line for the muster-mirror binary at bin: what the host's Hermes config declares as each event's `command`, and what the allowlist must hold exactly.
func InputRow ¶
func InputRow(s termscreen.Screen) string
InputRow is the text of the input area's first row on s, "" when s has no frame: a diagnostic, never a gate.
func InputRows ¶
InputRows is how many rows Hermes's input area needs to show text whole after an idle prompt promptWidth cells wide, in a pane columns wide: Hermes's own estimate (P:hermes_cli/cli_terminal_input.py:548-569) without its cap of 8. A text needing more than 8 is scrolled in the box, its prompt row out of sight, so the post-paste check could not see it whole.
func InputWidth ¶
func InputWidth(s termscreen.Screen) int
InputWidth is the input area's width on s (its rules'), 0 when s has no frame.
func IsScreenRefusal ¶
IsScreenRefusal reports whether err is a refusal of the screen check, and which.
func LooksLikeHermes ¶
func LooksLikeHermes(s termscreen.Screen) bool
LooksLikeHermes is the paste guard's best-effort chrome check: s shows an input area framed by two rules of one width with a `❯` on its first row, AND Hermes's own ☤ — its status bar above the frame, or the busy prompt. 🔴 The ☤ is what keeps it off Claude Code, whose idle screen is also a `❯` between two rules (internal/askdrive's fixtures; TestLooksLikeHermes). ⚠ It FAILS OPEN when Hermes's chrome is not drawn (for 0.35 s after a resize; a narrow pane's compact chrome; the status bar turned off) — the process walk is the guard; this is an extra (docs/design/hermes.md, the paste guard).
func MusterHookCommand ¶
MusterHookCommand reports whether command is a muster-mirror hermes-hook command (any binary path).
func NonTerminalLabel ¶
NonTerminalLabel reports whether s has the shape of a label a pinned non-terminal gate shows in place of a command (NonTerminalLabels).
func PendingTerminalCommandsOf ¶
PendingTerminalCommandsOf is the `command` of every pending `terminal` call in rows.
func PromptWidth ¶
func PromptWidth(s termscreen.Screen) int
PromptWidth is the idle prompt's width on s's first input row (`❯ ` is 2, `coder ❯ ` 8), 0 when s has none.
func Render ¶
func Render(r Row) []cctranscript.Event
Render is r's events. A row it draws nothing for has none.
func SameLineage ¶
SameLineage: a and b are the same sessions in the same order.
func ValidHookCommand ¶
ValidHookCommand reports why command cannot be the hook's command, nil when it can: an absolute path to a muster-mirror binary, with no whitespace in it (Hermes splits the command into argv), then exactly HookSubcommand.
Types ¶
type AllowlistCheck ¶
type AllowlistCheck struct {
// Command is the hook command checked for.
Command string
// Missing are the HookEvents whose (event, Command) pair is NOT
// allowlisted: each such hook, if configured, is skipped by the gateway and
// makes every new CLI stop on the [y/N] prompt.
Missing []string
// Other are the allowlisted muster-mirror hermes-hook entries for another
// command, "event command" each: a host whose Hermes config names a
// different binary than this one.
Other []string
}
AllowlistCheck is what -list -hermes reports about the hook's consent.
type ApprovalPrompt ¶
type ApprovalPrompt struct {
// PromptID is the gateway's id for it (32 hex at the pin).
PromptID string
// Generation is the session's execution generation it was asked in.
Generation int64
// Command is the command waiting to run; Description why Hermes asks.
Command string
Description string
// Choices are what the gateway offers (once, deny, session, always), in
// its order.
Choices []string
// Unshown: the approval carries content muster does not render (an
// `edit` diff — gateway/session_local_editor.py — or any field beyond
// these): never offered "once" from muster.
Unshown bool
}
ApprovalPrompt is one pending approval, as the gateway names it.
func (ApprovalPrompt) Offers ¶
func (p ApprovalPrompt) Offers(choice string) bool
Offers reports whether p offers choice.
type Believed ¶
type Believed struct {
Status string
// Since is the status file's time (Unix ms) when Status is believed, 0
// otherwise.
Since int64
// Reason is why Status is unknown, "" when it is believed.
Reason string
// Kind is what a believed waiting status waits on — "approval",
// "clarify" or "sudo", as the hook recorded it (S2) — "" for any other
// status. It says which ask muster shows (Phase 4).
Kind string
}
Believed is a Hermes window's status as muster reports it: a status file cross-checked against the turn lease and the newest message row (docs/design/hermes.md, "Believing a status file"). Status "" is UNKNOWN, which holds the send queue and refuses every send; Reason then says why.
func Believe ¶
func Believe(f StatusFile, found bool, snap Snapshot, now time.Time, alive func(pid int, start string) bool) Believed
Believe is the status muster reports for a conversation whose newest status file is f (found false: none), given snap, read at now. alive reports whether a process with that pid and /proc start time still runs.
- none: unknown, naming the missing hook — never idle.
- busy or waiting: believed only while its writer (the gateway) is alive AND the root has a live lease (expires_at > now). A stale busy is unknown.
- idle — the dangerous direction, a false idle invites a send: believed only when NO lease is live for the root AND no message in the lineage is newer than the file (slack 0: the final row precedes on_session_end, and a new turn's user row precedes its pre_llm_call, S2).
type Breadcrumb ¶
Breadcrumb is a terminal's breadcrumb as Hermes writes it (P:hermes_cli/terminal_breadcrumbs.py, write_breadcrumb): the session the CLI on that terminal runs, and when it said so. Measured (S3): written at the CLI's first gateway attach and on /new; unchanged across compression (it keeps the logical root); left STALE by /resume and /branch; never deleted when the CLI exits (pruned after 30 days).
type ClarifyQuestion ¶
ClarifyQuestion is one question of a pending clarify.
func PendingClarifyOf ¶
func PendingClarifyOf(rows []Row) []ClarifyQuestion
PendingClarifyOf is the questions of the newest clarify call in rows (oldest first) that no tool row answers; nil when there is none.
type DeclaredHook ¶
DeclaredHook is one `hooks:` entry: an event and its command.
type Fingerprint ¶
Fingerprint is the lineage's transcript fingerprint.
func (Fingerprint) After ¶
func (f Fingerprint) After(rows []Row) Fingerprint
After is f with rows (a tail read past f) appended: what the fingerprint must be if nothing but those appends happened.
type Gateway ¶
type Gateway struct {
// CodeSHA is the commit it booted from.
CodeSHA string
// InstanceID names this run of it; a ticket is bound to it.
InstanceID string
// ProfileID is the id it serves this home under.
ProfileID string
// APIOrigin is its loopback API, "http://127.0.0.1:<port>".
APIOrigin string
// PID is the gateway's process id, for a diagnostic.
PID int
}
Gateway is what a gateway's identify says, checked.
type Home ¶
type Home struct {
// contains filtered or unexported fields
}
Home is one Hermes home ($HERMES_HOME, else ~/.hermes).
func (Home) Attach ¶
Attach attaches a viewer to this home's gateway for session and returns it with the session's pending approvals. Every refusal names why: no gateway (ErrNoGateway), not the pin (ErrGatewayNotPin), a check that failed (ErrGatewayUnsafe), an answer muster cannot read (ErrGatewayProtocol).
func (Home) CheckAllowlist ¶
func (h Home) CheckAllowlist(command string) (AllowlistCheck, error)
CheckAllowlist compares h's allowlist with the pairs command needs. It READS the allowlist only. (The configured hooks are in config.yaml, which muster never reads: it can hold inline keys.)
func (Home) DeclaredHooks ¶
func (h Home) DeclaredHooks() ([]DeclaredHook, error)
DeclaredHooks is every `hooks:` entry of h's config.yaml, in file order (event by event); none, and no error, when there is no config.yaml.
func (Home) Identify ¶
Identify asks this home's gateway who it is, and checks the answer: the pinned commit (ErrGatewayNotPin), a ready owner of THIS home with session authority and a loopback API (ErrGatewayNotReady, ErrGatewayProtocol), as Hermes's own client checks it (P:hermes_cli/gateway_runtime.py, _endpoint). ErrNoGateway when none is running.
func (Home) ReadBreadcrumb ¶
func (h Home) ReadBreadcrumb(tty string) (Breadcrumb, error)
ReadBreadcrumb is the breadcrumb Hermes wrote for the terminal tty (/dev/pts/N). The session id must be one the wire carries (mirror.ValidAgentSession) and ts a finite positive time; anything else is an error, never a guess.
func (Home) ViMode ¶
ViMode reports whether h's Hermes runs its CLI in vi mode: config.yaml's display.vim_mode, read as Hermes reads it — Python's bool() of the YAML 1.1 value (P:hermes_cli/cli_init_mixin.py:566), so a quoted "no" is TRUE and an empty or null one false. No config.yaml, no display section or no vim_mode is off. 🔴 THE display: SECTION ONLY, its vim_mode alone: the file can carry inline keys, so it is decoded into a struct with no other field and no error quotes it. The daemon reads it only when it runs with -hermes-send (on each hello and each send), and `-list -hermes` reads it.
func (Home) WriteAllowlist ¶
WriteAllowlist makes muster's (event, command) pairs — every HookEvents event with command — present in h's allowlist exactly once, removes muster-mirror hermes-hook entries for any OTHER command, keeps every other approval, and writes NOTHING ELSE: only the approvals schema is carried over, so no foreign content (another key, another field) is ever copied into the rewritten file. changed is false when the file already said exactly that, and then it is not rewritten.
🔴 WHY OLDER muster-mirror ENTRIES ARE REMOVED: on Nix every upgrade changes the binary's store path, so each Home Manager switch would leave the previous path's five approvals behind — a growing list of consents for binaries that no longer exist (and that a garbage collection lets a later store path reuse). The command written is the one the host's Hermes config declares, which the activation passes in.
🔴 THE TARGET IS NEVER A SYMLINK OUT OF THE NIX STORE. A link into the store (a Home Manager file) is read and REPLACED by a real file — Hermes writes the same file when someone answers y/N, which a read-only link would break. Any other symlink is refused, nothing written.
type LabelShape ¶
type LabelShape struct{ Prefix, Suffix string }
LabelShape is one non-terminal gate's label: a prefix and a suffix.
type Lineage ¶
type Lineage []Session
Lineage is a conversation's sessions, root first, tip last: the session asked for, its compression ancestors and its compression continuations.
type Locator ¶
type Locator struct {
State *State
Status StatusDir
// Now is the clock (nil = time.Now).
Now func() time.Time
// Alive reports whether a process with that pid and /proc start time still
// runs (the status file's writer).
Alive func(pid int, start string) bool
}
Locator resolves Hermes panes for one home.
type Page ¶
type Page struct {
// Lineage is the conversation as this read found it.
Lineage Lineage
// Rows are the rows read, in display (backfill) or id (tail) order.
Rows []Row
// Cursor is the id the next tail reads past: the highest id of any row of
// the lineage this read saw, whatever its active flag.
Cursor int64
// Fingerprint is the lineage's, in the same read.
Fingerprint Fingerprint
// More: the backfill had more display rows than it returned.
More bool
// Prompts is a backfill's prompt index: every prompt of the conversation
// (its Line is its row id), not only the returned rows'.
Prompts []cctranscript.PromptRef
}
Page is one read of a conversation's transcript.
type PaneSession ¶
type PaneSession struct {
// Breadcrumb is the terminal's breadcrumb as read (zero when it could not
// be).
Breadcrumb Breadcrumb
// Lineage is the conversation, root first, when the breadcrumb resolved;
// nil otherwise.
Lineage Lineage
// Session is the conversation's logical id — the lineage root, which a
// rotation does not change — or "" when the pane has NO rendered view.
Session string
// NoView is why Session is "", "" when it is set.
NoView string
// Status is the pane's status; unknown whenever Session is "".
Status Believed
}
PaneSession is what a Hermes pane resolves to.
type Row ¶
type Row struct {
ID int64
SessionID string
Role string
Content string
ToolCallID string
ToolCalls string
ToolName string
FinishReason string
DisplayKind string
UID string
Timestamp float64
Active bool
Compacted bool
// DisplayMetadata is the display_metadata column as stored ("" for NULL);
// CompressedSummary is _compressed_summary.
DisplayMetadata string
CompressedSummary bool
}
Row is one messages row, the columns the renderer reads.
func (Row) DisplayKey ¶
DisplayKey is what decides how a row is drawn beyond its content: its display_kind, display_metadata and _compressed_summary. Hermes can stamp these AFTER writing the row (an auto_continue or process_complete row), and no fingerprint column moves when it does (transcript_revision's trigger watches content, not display columns).
func (Row) Hidden ¶
Hidden: a row Hermes never renders — a compaction summary (_compressed_summary=1, a user-role row Hermes wrote) or a model-only row (display_metadata.model_only: a micro-compaction merge the model reads but nobody typed as one message; P:hermes_state_messages.py:1090, P:gateway/session_controls.py:106).
type ScreenRefusal ¶
type ScreenRefusal struct{ Rule string }
ScreenRefusal is why the screen check refused: Rule is one of the Screen* constants, the person's words.
func (*ScreenRefusal) Error ¶
func (e *ScreenRefusal) Error() string
type Session ¶
type Session struct {
ID string
Parent string
Source string
// Ended: ended_at is set; EndReason is end_reason ("" for NULL).
Ended bool
EndReason string
Archived bool
Hidden bool
}
Session is one sessions row, the columns this reader uses.
type Snapshot ¶
type Snapshot struct {
Lineage Lineage
// LeaseExpires is the root's session_turn_leases.expires_at (Unix
// seconds), 0 when it holds none.
LeaseExpires float64
// NewestMessage is the newest messages.timestamp in the lineage (Unix
// seconds), 0 for none.
NewestMessage float64
}
Snapshot is what one read of state.db says about a conversation: its lineage, the turn lease of its root, and its newest message.
type State ¶
type State struct {
// contains filtered or unexported fields
}
State is a read-only connection to a Hermes home's state.db (docs/design/hermes.md, "Transcript reading").
- ONE long-lived connection per home, opened read-only (Home.stateDBURI: mode=ro, never immutable=1, busy_timeout, query_only);
- every read is a short transaction, so the writer's checkpoints are not held back;
- SQLITE_BUSY and a transient SQLITE_IOERR are retried (P:hermes_state_readpool.py does the same: a mode=ro reader sees a transient IOERR mid-checkpoint);
- the columns it reads are feature-detected with PRAGMA table_info, and a missing one is an error naming it: muster-mirror refuses a schema it cannot read rather than guessing.
It is safe for concurrent use.
func (*State) Backfill ¶
Backfill reads the last n display rows of root's conversation, the cursor past every row, and the fingerprint — one read transaction.
func (*State) DisplayKeys ¶
DisplayKeys is the current DisplayKey of each of ids that still exists.
func (*State) PendingClarify ¶
PendingClarify is PendingClarifyOf the last rows of root's conversation.
func (*State) PendingTerminalCommands ¶
PendingTerminalCommands is PendingTerminalCommandsOf the last rows of root's conversation.
func (*State) Snapshot ¶
Snapshot reads id's lineage, its root's lease and its newest message in ONE read transaction.
type StatusDir ¶
type StatusDir string
StatusDir is a directory of status files.
func (StatusDir) Newest ¶
Newest is the newest valid status file among ids (a lineage: the hook writes the PHYSICAL id, so a rotated conversation's status is in its child's file), and false when none of them has one — or when ctx ends first (the listing's own deadline bounds every read).
func (StatusDir) Read ¶
func (d StatusDir) Read(id string) (StatusFile, error)
Read is session id's status file, os.ErrNotExist when there is none, an error for one that is not a valid status file for id.
func (StatusDir) Write ¶
func (d StatusDir) Write(f StatusFile) error
Write writes f as its session's status file — under the directory's lock, through a temp file and a rename, mode 0600 in a 0700 directory.
🔴 THE LATER ARRIVAL WINS, AND since ONLY GOES UP. Hermes runs a session's hooks synchronously, one after another, in its gateway, so the order writes arrive in is the order the events happened in. Two in one millisecond (an on_session_end then an on_session_finalize, or a resolve then a turn end) would otherwise tie; and a clock stepped back would make an older status look newer. So when the file already holds a since at or after f's, f is written at that since + 1 ms: deterministic, and the newest event's.
type StatusFile ¶
type StatusFile struct {
V int `json:"v"`
SessionID string `json:"session_id"`
// Status is mirror.StatusBusy, StatusIdle or StatusWaiting.
Status string `json:"status"`
// Since is when the hook wrote it, Unix milliseconds.
Since int64 `json:"since"`
// Kind is a waiting request's kind (approval, clarify, sudo), "" otherwise;
// RequestID its id.
Kind string `json:"kind"`
RequestID string `json:"request_id"`
// WriterPID and WriterStart are the process that ran the hook — the Hermes
// GATEWAY, the hook's parent (S2: hooks run in the gateway) — and its
// /proc start time: a busy file whose writer is gone is stale.
WriterPID int `json:"writer_pid"`
WriterStart string `json:"writer_start"`
}
StatusFile is one status file.
type Viewer ¶
type Viewer struct {
// Session is the session the gateway resumed (its logical id), which
// every answer names.
Session string
// contains filtered or unexported fields
}
Viewer is one attachment to a gateway, for one session.
func (*Viewer) Close ¶
func (v *Viewer) Close()
Close ends the viewer. Closing a viewer never stops its session (the gateway's own rule: "closing a viewer never stops its authority").
func (*Viewer) Done ¶
func (v *Viewer) Done() <-chan struct{}
Done is closed when the viewer has ended (Close, or the gateway hung up).
func (*Viewer) Events ¶
func (v *Viewer) Events() <-chan ViewerEvent
Events are the session's approval changes while attached; closed when the viewer is done.
type ViewerEvent ¶
type ViewerEvent struct {
Kind string
Prompt ApprovalPrompt
PromptID string
}
ViewerEvent is a change to what the session waits on.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package hermestest builds fake Hermes homes for tests: a scratch directory holding a REAL SQLite state.db created from the schema Hermes itself creates at the pin (schema-5fc490e.sql: its triggers included, so an insert gets its display_order and message_uid the way Hermes's own do), in WAL mode with a writer connection held open the way a running gateway holds one, plus breadcrumbs and decoy secret files.
|
Package hermestest builds fake Hermes homes for tests: a scratch directory holding a REAL SQLite state.db created from the schema Hermes itself creates at the pin (schema-5fc490e.sql: its triggers included, so an insert gets its display_order and message_uid the way Hermes's own do), in WAL mode with a writer connection held open the way a running gateway holds one, plus breadcrumbs and decoy secret files. |