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
feat(hermes): record on the cursor whether a session's ids are keyed by home
Saurav Singh54b4a68daa87
diff --git a/cli/beacon/internal/hermessession/collect.go b/cli/beacon/internal/hermessession/collect.goindex 7e28acbf..90351005 100644--- a/cli/beacon/internal/hermessession/collect.go+++ b/cli/beacon/internal/hermessession/collect.go@@ -40,6 +40,12 @@ type Cursor struct {ReasoningTokens int64 `json:"reasoning_tokens,omitempty"`CostUSD float64 `json:"cost_usd,omitempty"`PendingCalls map[string]json.RawMessage `json:"pending_calls,omitempty"`+ // KeyedByHome keys the session's event ids by the Hermes home this cursor belongs to. It is set+ // when another home already holds the session id, as a cloned profile does: both start from a+ // copy of one state.db, and once the copies diverge their message ids count up independently, so+ // unkeyed ids would name different events the same. It is decided before the session's first+ // event is written and never changes after, so a session's ids stay stable.+ KeyedByHome bool `json:"keyed_by_home,omitempty"`}type State struct {@@ -258,8 +264,12 @@ func collectSession(store *Store, session Session, state *State, opts CollectOptif err != nil {return false, err}- mapped, pending := MapSession(session, messages, cursor)home := filepath.Dir(store.Path())+ idHome := ""+ if cursor.KeyedByHome {+ idHome = canonicalHome(home)+ }+ mapped, pending := mapSession(session, messages, cursor, idHome)for i := range mapped {mapped[i].Event.Harness.ConfigPath = homemapped[i].Event.Harness.Profile = Profile(home)diff --git a/cli/beacon/internal/hermessession/event_id_test.go b/cli/beacon/internal/hermessession/event_id_test.goindex f0c6130b..f4c8c4d5 100644--- a/cli/beacon/internal/hermessession/event_id_test.go+++ b/cli/beacon/internal/hermessession/event_id_test.go@@ -105,3 +105,32 @@ func TestMapSessionKeysEventIDsByHome(t *testing.T) {}}}++// A cursor marked KeyedByHome keeps keying the session's ids by its home on every sweep, so events+// written later in the session never fall back to the unkeyed ids another home writes.+func TestCollectOnceKeysEventIDsForACursorMarkedKeyed(t *testing.T) {+ dir := t.TempDir()+ dbPath := filepath.Join(dir, "state.db")+ createHermesFixtureDB(t, dbPath)+ statePath := filepath.Join(dir, "hermes-state.json")+ state := &State{Version: StateVersion, Sessions: map[string]*Cursor{"hermes-session-1": {KeyedByHome: true}}}+ if err := state.Save(statePath); err != nil {+ t.Fatal(err)+ }+ logPath := filepath.Join(dir, "runtime.jsonl")+ if _, err := CollectOnce(CollectOptions{DBPath: dbPath, StatePath: statePath, LogPath: logPath, Write: true, UserMode: true}); err != nil {+ t.Fatal(err)+ }+ for _, ev := range readEvents(t, logPath) {+ if ev.Event.ID == fixtureEventIDs[ev.Event.Action] {+ t.Fatalf("%s kept the unkeyed id %s", ev.Event.Action, ev.Event.ID)+ }+ }+ saved, err := LoadState(statePath)+ if err != nil {+ t.Fatal(err)+ }+ if cursor := saved.Sessions["hermes-session-1"]; cursor == nil || !cursor.KeyedByHome || !cursor.Started {+ t.Fatalf("cursor = %#v, want it collected and still keyed by home", cursor)+ }+}