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): show sessions keyed by home in hermes status
Saurav Singh43ade3e6f4a1
diff --git a/cli/beacon/cmd/endpoint_hermes.go b/cli/beacon/cmd/endpoint_hermes.goindex 1e9ffd47..1734d852 100644--- a/cli/beacon/cmd/endpoint_hermes.go+++ b/cli/beacon/cmd/endpoint_hermes.go@@ -147,6 +147,9 @@ type hermesSessionStatus struct {LastMessageID int64 `json:"last_message_id"`CollectedMessageID int64 `json:"collected_message_id"`Collected bool `json:"collected"`+ // IDsKeyedByHome is set when this home keys the session's event ids by its own path, because+ // another home, such as the profile it was cloned from, had already collected the same session id.+ IDsKeyedByHome bool `json:"ids_keyed_by_home,omitempty"`}type hermesStatusReport struct {@@ -202,6 +205,7 @@ func runEndpointHermesStatus(cmd *cobra.Command, args []string) error {if cursor := state.Sessions[session.ID]; cursor != nil {status.CollectedMessageID = cursor.LastMessageIDstatus.Collected = cursor.Started && cursor.LastMessageID >= lastID && (session.EndedAtMS == 0 || cursor.EndedAtMS == session.EndedAtMS)+ status.IDsKeyedByHome = cursor.KeyedByHome}report.Sessions = append(report.Sessions, status)}@@ -219,6 +223,9 @@ func runEndpointHermesStatus(cmd *cobra.Command, args []string) error {if session.Collected {mark = "collected"}+ if session.IDsKeyedByHome {+ mark += ", ids keyed by home"+ }fmt.Fprintf(cmd.OutOrStdout(), "- %s [%s] messages %d/%d %s\n",session.SessionID, mark, session.CollectedMessageID, session.LastMessageID, session.Title)}diff --git a/cli/beacon/cmd/endpoint_hermes_test.go b/cli/beacon/cmd/endpoint_hermes_test.goindex de141607..48e269c5 100644--- a/cli/beacon/cmd/endpoint_hermes_test.go+++ b/cli/beacon/cmd/endpoint_hermes_test.go@@ -1,12 +1,16 @@package cmdimport (+ "bytes"+ "database/sql"+ "encoding/json""os""path/filepath""strings""testing""github.com/asymptote-labs/agent-beacon/cli/beacon/internal/hermessession"+ "github.com/spf13/cobra")// The cursor is what keeps a scheduled sweep from re-appending every Hermes session's whole@@ -112,3 +116,67 @@ func TestHermesKeyedCursorSeedsFromTheLegacyCursor(t *testing.T) {t.Errorf("a non-default home would inherit the legacy cursor %q", other)}}++// Status names the sessions whose event ids a home keys by its own path, so a cloned profile's+// events can be told apart from the ones the home it came from wrote under the same session id.+func TestHermesStatusReportsSessionsKeyedByHome(t *testing.T) {+ dir := t.TempDir()+ dbPath := filepath.Join(dir, "state.db")+ db, err := sql.Open("sqlite", dbPath)+ if err != nil {+ t.Fatal(err)+ }+ for _, stmt := range []string{+ `CREATE TABLE sessions (id TEXT PRIMARY KEY, source TEXT NOT NULL, started_at REAL NOT NULL)`,+ `CREATE TABLE messages (id INTEGER PRIMARY KEY AUTOINCREMENT, session_id TEXT NOT NULL, role TEXT NOT NULL, content TEXT, timestamp REAL NOT NULL)`,+ `INSERT INTO sessions (id, source, started_at) VALUES ('cloned', 'cli', 1780632830), ('own', 'cli', 1780632831)`,+ `INSERT INTO messages (session_id, role, content, timestamp) VALUES ('cloned', 'user', 'hi', 1780632832), ('own', 'user', 'hi', 1780632833)`,+ } {+ if _, err := db.Exec(stmt); err != nil {+ db.Close()+ t.Fatal(err)+ }+ }+ db.Close()+ statePath := filepath.Join(dir, "hermes.json")+ state := &hermessession.State{Version: hermessession.StateVersion, Sessions: map[string]*hermessession.Cursor{+ "cloned": {Started: true, LastMessageID: 1, KeyedByHome: true},+ "own": {Started: true, LastMessageID: 2},+ }}+ if err := state.Save(statePath); err != nil {+ t.Fatal(err)+ }++ savedHermes, savedEndpoint := endpointHermesOpts, endpointOpts+ t.Cleanup(func() { endpointHermesOpts, endpointOpts = savedHermes, savedEndpoint })+ endpointHermesOpts.dbPath, endpointHermesOpts.statePath = dbPath, statePath+ endpointOpts.userMode, endpointOpts.systemMode = true, false++ run := func(jsonOutput bool) string {+ t.Helper()+ endpointOpts.jsonOutput = jsonOutput+ var out bytes.Buffer+ cmd := &cobra.Command{}+ cmd.SetOut(&out)+ if err := runEndpointHermesStatus(cmd, nil); err != nil {+ t.Fatal(err)+ }+ return out.String()+ }++ var report hermesStatusReport+ if err := json.Unmarshal([]byte(run(true)), &report); err != nil {+ t.Fatal(err)+ }+ keyed := map[string]bool{}+ for _, session := range report.Sessions {+ keyed[session.SessionID] = session.IDsKeyedByHome+ }+ if len(keyed) != 2 || !keyed["cloned"] || keyed["own"] {+ t.Fatalf("ids_keyed_by_home = %v, want only the cloned session", keyed)+ }+ text := run(false)+ if !strings.Contains(text, "- cloned [collected, ids keyed by home]") || strings.Contains(text, "- own [collected, ids keyed by home]") {+ t.Fatalf("status text = %q, want only the cloned session marked keyed", text)+ }+}