The cross-harness, self-improving memory layer for AI agents. Join our community: https://discord.com/invite/zdNChS2fBu
Go agent-ai-cliagent-harnessesagent-securitybrowser-extensionciclaude-codecloudcodexcursordetection-engineeringjevknowledge-basememorymobile-device-managementobservabilitysecuritysecurity-information-and-event-managementsecurity-toolstelemetrytraces
fix(hermes): honor HERMES_HOME and native data roots for session stores (#854)
Rudy Mizrahi Celekliba4e5e6039a0
diff --git a/cli/beacon/cmd/endpoint_hermes.go b/cli/beacon/cmd/endpoint_hermes.goindex 19e1c9bc..062c3298 100644--- a/cli/beacon/cmd/endpoint_hermes.go+++ b/cli/beacon/cmd/endpoint_hermes.go@@ -58,7 +58,7 @@ func init() {for _, c := range []*cobra.Command{endpointHermesSyncCmd, endpointHermesStatusCmd} {f := c.Flags()- f.StringVar(&endpointHermesOpts.dbPath, "db", "", "Hermes state database (default ~/.hermes/state.db)")+ f.StringVar(&endpointHermesOpts.dbPath, "db", "", "Hermes state database (default $HERMES_HOME/state.db when set, otherwise the native Hermes data root)")f.StringVar(&endpointHermesOpts.statePath, "state", "", "Collector cursor file (default ~/.beacon/endpoint/state/hermes.json)")f.BoolVar(&endpointOpts.jsonOutput, "json", false, "Print the result as JSON")f.BoolVar(&endpointOpts.userMode, "user", true, "Use per-user endpoint paths")diff --git a/cli/beacon/internal/hermessession/collect.go b/cli/beacon/internal/hermessession/collect.goindex fcdff1c1..5e74f05d 100644--- a/cli/beacon/internal/hermessession/collect.go+++ b/cli/beacon/internal/hermessession/collect.go@@ -13,6 +13,8 @@ import ("net/url""os""path/filepath"+ "regexp"+ "runtime""strconv""strings""time"@@ -120,12 +122,50 @@ type MappedEvent struct {}func DefaultDBPath() string {+ if override := strings.TrimSpace(os.Getenv("HERMES_HOME")); override != "" {+ path := hermesExpandVars(override)+ if home, err := os.UserHomeDir(); err == nil {+ if path == "~" {+ path = home+ } else if strings.HasPrefix(path, "~/") || (runtime.GOOS == "windows" && strings.HasPrefix(path, `~\`)) {+ path = filepath.Join(home, path[2:])+ }+ }+ return filepath.Join(path, "state.db")+ }+ suffix := os.Getenv("HERMES_DATA_DIR_SUFFIX")+ if runtime.GOOS == "windows" {+ if base := strings.TrimSpace(os.Getenv("LOCALAPPDATA")); base != "" {+ return filepath.Join(base, "hermes"+suffix, "state.db")+ }+ }if home, err := os.UserHomeDir(); err == nil && strings.TrimSpace(home) != "" {- return filepath.Join(home, ".hermes", "state.db")+ if runtime.GOOS == "windows" {+ return filepath.Join(home, "AppData", "Local", "hermes"+suffix, "state.db")+ }+ return filepath.Join(home, ".hermes"+suffix, "state.db")}return filepath.Join(os.TempDir(), "hermes", "state.db")}+var hermesEnvReference = regexp.MustCompile(`\$\{([^}]*)\}|\$([A-Za-z0-9_]+)`)++// hermesExpandVars expands $VAR and ${VAR} like Python's os.path.expandvars, which Hermes+// uses: references to unset variables are left as written.+func hermesExpandVars(path string) string {+ return hermesEnvReference.ReplaceAllStringFunc(path, func(reference string) string {+ parts := hermesEnvReference.FindStringSubmatch(reference)+ name := parts[1]+ if parts[2] != "" {+ name = parts[2]+ }+ if value, ok := os.LookupEnv(name); ok {+ return value+ }+ return reference+ })+}+func DefaultStatePath() string {base := filepath.Join(os.TempDir(), "beacon")if home, err := os.UserHomeDir(); err == nil && strings.TrimSpace(home) != "" {diff --git a/cli/beacon/internal/hermessession/default_path_test.go b/cli/beacon/internal/hermessession/default_path_test.gonew file mode 100644index 00000000..5a97cec4--- /dev/null+++ b/cli/beacon/internal/hermessession/default_path_test.go@@ -0,0 +1,64 @@+package hermessession++import (+ "os"+ "path/filepath"+ "runtime"+ "testing"++ "github.com/asymptote-labs/agent-beacon/cli/beacon/internal/testenv"+)++func TestDefaultDBPathFollowsHermesHome(t *testing.T) {+ home := t.TempDir()+ testenv.SetHome(t, home)+ profile := filepath.Join(home, "profiles", "work")+ t.Setenv("HERMES_DATA_DIR_SUFFIX", "")+ t.Setenv("LOCALAPPDATA", filepath.Join(home, "LocalAppData"))+ defaultPath := filepath.Join(home, ".hermes", "state.db")+ if runtime.GOOS == "windows" {+ defaultPath = filepath.Join(home, "LocalAppData", "hermes", "state.db")+ }+ t.Setenv("BEACON_HERMES_PROFILE_FIXTURE", profile)+ for _, tc := range []struct{ name, override, want string }{+ {"default", "", defaultPath},+ {"blank", " ", defaultPath},+ {"absolute profile", profile, filepath.Join(profile, "state.db")},+ {"trimmed profile", " " + profile + " ", filepath.Join(profile, "state.db")},+ {"home expansion", "~/profiles/work", filepath.Join(profile, "state.db")},+ {"environment expansion", "$BEACON_HERMES_PROFILE_FIXTURE", filepath.Join(profile, "state.db")},+ {"braced environment expansion", "${BEACON_HERMES_PROFILE_FIXTURE}", filepath.Join(profile, "state.db")},+ } {+ t.Run(tc.name, func(t *testing.T) {+ t.Setenv("HERMES_HOME", tc.override)+ if got := DefaultDBPath(); got != tc.want {+ t.Fatalf("DefaultDBPath() = %q, want %q", got, tc.want)+ }+ })+ }+}++func TestHermesExpansionPreservesUnsetReference(t *testing.T) {+ t.Setenv("BEACON_UNSET_FIXTURE", "")+ if err := os.Unsetenv("BEACON_UNSET_FIXTURE"); err != nil {+ t.Fatal(err)+ }+ if got := hermesExpandVars("$BEACON_UNSET_FIXTURE/work"); got != "$BEACON_UNSET_FIXTURE/work" {+ t.Fatalf("unset expansion=%q", got)+ }+}++func TestDefaultHermesRootIncludesProducerSuffix(t *testing.T) {+ home := t.TempDir()+ testenv.SetHome(t, home)+ t.Setenv("HERMES_HOME", "")+ t.Setenv("HERMES_DATA_DIR_SUFFIX", "-owned-fixture")+ t.Setenv("LOCALAPPDATA", filepath.Join(home, "LocalAppData"))+ want := filepath.Join(home, ".hermes-owned-fixture", "state.db")+ if runtime.GOOS == "windows" {+ want = filepath.Join(home, "LocalAppData", "hermes-owned-fixture", "state.db")+ }+ if got := DefaultDBPath(); got != want {+ t.Fatalf("suffixed default=%q, want %q", got, want)+ }+}diff --git a/docs/cli/handoff.mdx b/docs/cli/handoff.mdxindex dc7dd08d..db2705eb 100644--- a/docs/cli/handoff.mdx+++ b/docs/cli/handoff.mdx@@ -27,7 +27,7 @@ Sessions come from each runtime's own local session store, not from Beacon's run| Prime Agent | `~/.prime/agent`, both `sessions` and `session-artifacts` (or `PRIME_AGENT_CODING_AGENT_DIR`) | `prime` || Factory Droid | `~/.factory/sessions` | `droid` || GitHub Copilot CLI | `~/.copilot/session-state` | `copilot` |-| Hermes Agent | `~/.hermes/state.db` | `hermes` |+| Hermes Agent | `$HERMES_HOME/state.db` when set; otherwise `~/.hermes/state.db` (Windows: `%LOCALAPPDATA%/hermes/state.db`) | `hermes` || DeepSeek Harness | `~/.dsh/sessions` (or under `DSH_HOME`) | `dsh` || fx | `~/.fx/sessions` | `fx` || Grok Build | `~/.grok/sessions` | `grok` |diff --git a/docs/runtimes/hermes-agent.mdx b/docs/runtimes/hermes-agent.mdxindex f3ac94c6..2cc9a804 100644--- a/docs/runtimes/hermes-agent.mdx+++ b/docs/runtimes/hermes-agent.mdx@@ -60,7 +60,9 @@ Hermes Agent hooks support user-level config only. Project-level installs are re## Session database sync-`beacon endpoint hermes sync` reads committed rows from Hermes Agent's state database after Hermes has written them. The cursor is stored in Beacon endpoint state and advances by session message id. Use `--print` to preview mapped events without writing the runtime log or advancing the cursor.+`beacon endpoint hermes sync` reads committed rows from Hermes Agent's state database after Hermes has written them. Session status, sync, and handoff use `$HERMES_HOME/state.db` when `HERMES_HOME` is set in Beacon's environment, expanding a leading `~/` and `$VAR`/`${VAR}` references. Otherwise they use Hermes's native data root: `~/.hermes` on macOS/Linux or `%LOCALAPPDATA%/hermes` on Windows, with `HERMES_DATA_DIR_SUFFIX` appended when set. A profile selected only through `hermes -p` or `hermes profile use` is not followed; pass `--db <path>` to status/sync or `--store-dir hermes=<path>` to handoff to select its database explicitly.++The cursor is stored in Beacon endpoint state and advances by session message id. Use `--print` to preview mapped events without writing the runtime log or advancing the cursor.For scheduled collection, run `beacon endpoint hermes sync --watch`, or run one-shot `sync` from your scheduler. Live hooks remain the real-time path.