Skip to content

The cross-harness, self-improving memory layer for AI agents. Join our community: https://discord.com/invite/zdNChS2fBu

trim fixture

Justin D'Souza4d08d0db7e7c
diff --git a/README.md b/README.md
index 1094b6a1..fdd23aad 100644
--- a/README.md
+++ b/README.md
@@ -136,9 +136,9 @@ records during rollout, testing, and investigations.
Beacon writes endpoint activity to a stable local `runtime.jsonl` file. The
active file rotates at 10 MiB with five numbered local archives, keeping the
endpoint handoff file bounded while external SIEM forwarders continue tailing
-the active path. The dashboard and local validation commands read the active log
-in this release; SIEM destinations remain the source of truth for long-term
-retention and search.
+the active path. The dashboard reads the active log plus retained numbered
+archives for local triage; SIEM destinations remain the source of truth for
+long-term retention and search.
<p align="center">
<img src="images/dashboard-overview.png" alt="Beacon dashboard overview" width="860">
diff --git a/cli/beacon-hooks/internal/logging/endpoint_event_test.go b/cli/beacon-hooks/internal/logging/endpoint_event_test.go
index ffb0507b..c84e0268 100644
--- a/cli/beacon-hooks/internal/logging/endpoint_event_test.go
+++ b/cli/beacon-hooks/internal/logging/endpoint_event_test.go
@@ -40,18 +40,18 @@ func TestEndpointEventStillWritesStructuredTelemetry(t *testing.T) {
func TestEndpointEventRotatesRuntimeLog(t *testing.T) {
logPath := filepath.Join(t.TempDir(), "runtime.jsonl")
- t.Setenv("BEACON_ENDPOINT_LOG", logPath)
- if err := os.WriteFile(logPath, []byte(strings.Repeat("old", 4*1024*1024)), 0644); err != nil {
+ if err := os.WriteFile(logPath, []byte("old log contents"), 0644); err != nil {
t.Fatalf("write existing log: %v", err)
}
- logger := NewLoggerForPlatform("pre-tool", "test")
- logger.EndpointEvent("approval.allowed", "approval", "info", "Pre-tool observed", nil)
+ if err := appendEndpointJSONL(logPath, []byte("{\"message\":\"new event\"}\n"), 1, 2); err != nil {
+ t.Fatalf("appendEndpointJSONL returned error: %v", err)
+ }
- if rotated, err := os.ReadFile(logPath + ".1"); err != nil || len(rotated) == 0 {
- t.Fatalf("expected rotated archive, len=%d err=%v", len(rotated), err)
+ if rotated, err := os.ReadFile(logPath + ".1"); err != nil || string(rotated) != "old log contents" {
+ t.Fatalf("expected rotated archive, data=%q err=%v", string(rotated), err)
}
- if current, err := os.ReadFile(logPath); err != nil || !strings.Contains(string(current), "Pre-tool observed") {
+ if current, err := os.ReadFile(logPath); err != nil || !strings.Contains(string(current), "new event") {
t.Fatalf("expected current log to contain new event, data=%q err=%v", string(current), err)
}
}
diff --git a/cli/beacon/internal/endpoint/dashboard/events.go b/cli/beacon/internal/endpoint/dashboard/events.go
index d61244d4..f620e880 100644
--- a/cli/beacon/internal/endpoint/dashboard/events.go
+++ b/cli/beacon/internal/endpoint/dashboard/events.go
@@ -6,6 +6,7 @@ import (
"encoding/json"
"fmt"
"os"
+ "path/filepath"
"sort"
"strconv"
"strings"
@@ -62,16 +63,33 @@ type EventResult struct {
func ReadEvents(path string, query EventQuery) (EventResult, error) {
limit := normalizeLimit(query.Limit)
- file, err := os.Open(path)
+ result := EventResult{Limit: limit, Query: strings.TrimSpace(query.Q), Filters: activeFilters(query)}
+ for _, source := range eventSources(path) {
+ if err := readEventsFromSource(source, query, &result, limit); err != nil {
+ return EventResult{}, err
+ }
+ }
+ sort.SliceStable(result.Events, func(i, j int) bool {
+ if result.Events[i].Parsed.Equal(result.Events[j].Parsed) {
+ return result.Events[i].ID > result.Events[j].ID
+ }
+ return result.Events[i].Parsed.After(result.Events[j].Parsed)
+ })
+ result.Returned = len(result.Events)
+ result.Truncated = result.TotalMatched > len(result.Events)
+ return result, nil
+}
+
+func readEventsFromSource(source eventSource, query EventQuery, result *EventResult, limit int) error {
+ file, err := os.Open(source.path)
if err != nil {
if os.IsNotExist(err) {
- return EventResult{Events: []EventRecord{}, Limit: limit}, nil
+ return nil
}
- return EventResult{}, err
+ return err
}
defer file.Close()
- result := EventResult{Limit: limit, Query: strings.TrimSpace(query.Q), Filters: activeFilters(query)}
scanner := bufio.NewScanner(file)
scanner.Buffer(make([]byte, 0, 64*1024), 4*1024*1024)
@@ -90,7 +108,7 @@ func ReadEvents(path string, query EventQuery) (EventResult, error) {
normalizeDashboardEvent(&event)
parsed, _ := time.Parse(time.RFC3339, event.Timestamp)
record := EventRecord{
- ID: fmt.Sprintf("line-%d", lineNo),
+ ID: source.lineID(lineNo),
Line: lineNo,
Event: event,
Raw: append(json.RawMessage(nil), line...),
@@ -102,29 +120,33 @@ func ReadEvents(path string, query EventQuery) (EventResult, error) {
}
result.TotalMatched++
result.Events = append(result.Events, record)
+ sort.SliceStable(result.Events, func(i, j int) bool {
+ if result.Events[i].Parsed.Equal(result.Events[j].Parsed) {
+ return result.Events[i].ID > result.Events[j].ID
+ }
+ return result.Events[i].Parsed.After(result.Events[j].Parsed)
+ })
if len(result.Events) > limit {
- copy(result.Events, result.Events[1:])
result.Events = result.Events[:limit]
}
}
if err := scanner.Err(); err != nil {
- return EventResult{}, err
+ return err
}
-
- sort.SliceStable(result.Events, func(i, j int) bool {
- return result.Events[i].Line > result.Events[j].Line
- })
- result.Returned = len(result.Events)
- result.Truncated = result.TotalMatched > len(result.Events)
- return result, nil
+ return nil
}
func FindEvent(path, id string) (EventRecord, bool, error) {
- lineNo, ok := parseLineID(id)
+ sourceIndex, lineNo, ok := parseRecordID(id)
if !ok {
return EventRecord{}, false, nil
}
- file, err := os.Open(path)
+ sources := eventSources(path)
+ if sourceIndex >= len(sources) {
+ return EventRecord{}, false, nil
+ }
+ source := sources[sourceIndex]
+ file, err := os.Open(source.path)
if err != nil {
if os.IsNotExist(err) {
return EventRecord{}, false, nil
@@ -152,7 +174,7 @@ func FindEvent(path, id string) (EventRecord, bool, error) {
normalizeDashboardEvent(&event)
parsed, _ := time.Parse(time.RFC3339, event.Timestamp)
return EventRecord{
- ID: id,
+ ID: source.lineID(lineNo),
Line: lineNo,
Event: event,
Raw: append(json.RawMessage(nil), line...),
@@ -166,6 +188,46 @@ func FindEvent(path, id string) (EventRecord, bool, error) {
return EventRecord{}, false, nil
}
+type eventSource struct {
+ path string
+ archive int
+}
+
+func (s eventSource) lineID(line int) string {
+ if s.archive == 0 {
+ return fmt.Sprintf("line-%d", line)
+ }
+ return fmt.Sprintf("archive-%d-line-%d", s.archive, line)
+}
+
+func eventSources(path string) []eventSource {
+ sources := []eventSource{{path: path}}
+ dir := filepath.Dir(path)
+ base := filepath.Base(path)
+ entries, err := os.ReadDir(dir)
+ if err != nil {
+ return sources
+ }
+ prefix := base + "."
+ var archives []eventSource
+ for _, entry := range entries {
+ name := entry.Name()
+ suffix, ok := strings.CutPrefix(name, prefix)
+ if !ok {
+ continue
+ }
+ index, err := strconv.Atoi(suffix)
+ if err != nil || index <= 0 {
+ continue
+ }
+ archives = append(archives, eventSource{path: filepath.Join(dir, name), archive: index})
+ }
+ sort.Slice(archives, func(i, j int) bool {
+ return archives[i].archive < archives[j].archive
+ })
+ return append(sources, archives...)
+}
+
func normalizeDashboardEvent(event *schema.Event) {
metricName := metricEventName(event)
if event.Event.Category == "" && metricName != "" {
@@ -450,16 +512,27 @@ func truthy(value string) bool {
}
}
-func parseLineID(id string) (int, bool) {
+func parseRecordID(id string) (int, int, bool) {
+ if archiveID, rest, ok := strings.Cut(strings.TrimPrefix(id, "archive-"), "-line-"); ok && strings.HasPrefix(id, "archive-") {
+ archive, err := strconv.Atoi(archiveID)
+ if err != nil || archive <= 0 {
+ return 0, 0, false
+ }
+ lineNo, err := strconv.Atoi(rest)
+ if err != nil || lineNo <= 0 {
+ return 0, 0, false
+ }
+ return archive, lineNo, true
+ }
line, ok := strings.CutPrefix(id, "line-")
if !ok {
- return 0, false
+ return 0, 0, false
}
lineNo, err := strconv.Atoi(line)
if err != nil || lineNo <= 0 {
- return 0, false
+ return 0, 0, false
}
- return lineNo, true
+ return 0, lineNo, true
}
func WazuhLevel(action string) int {
diff --git a/cli/beacon/internal/endpoint/dashboard/events_test.go b/cli/beacon/internal/endpoint/dashboard/events_test.go
index 13d39c40..bb6b9fa5 100644
--- a/cli/beacon/internal/endpoint/dashboard/events_test.go
+++ b/cli/beacon/internal/endpoint/dashboard/events_test.go
@@ -250,6 +250,33 @@ func TestReadEventsFiltersByModel(t *testing.T) {
}
}
+func TestReadEventsIncludesRotatedArchives(t *testing.T) {
+ path := filepath.Join(t.TempDir(), "runtime.jsonl")
+ writeTestLog(t, path+".2",
+ testEvent("2026-05-13T01:00:00Z", "cursor", "command.executed", "command", "repo-a"),
+ )
+ writeTestLog(t, path+".1",
+ testEvent("2026-05-13T01:01:00Z", "cursor", "file.modified", "file", "repo-b"),
+ )
+ writeTestLog(t, path,
+ testEvent("2026-05-13T01:02:00Z", "cursor", "prompt.submitted", "prompt", "repo-c"),
+ )
+
+ result, err := ReadEvents(path, EventQuery{Limit: 10})
+ if err != nil {
+ t.Fatalf("ReadEvents returned error: %v", err)
+ }
+ if result.TotalMatched != 3 || len(result.Events) != 3 {
+ t.Fatalf("matched events = total %d len %d, want 3/3", result.TotalMatched, len(result.Events))
+ }
+ wantIDs := []string{"line-1", "archive-1-line-1", "archive-2-line-1"}
+ for i, want := range wantIDs {
+ if result.Events[i].ID != want {
+ t.Fatalf("event %d ID = %q, want %q", i, result.Events[i].ID, want)
+ }
+ }
+}
+
func TestFindEventCanReadOutsideTailWindow(t *testing.T) {
path := filepath.Join(t.TempDir(), "runtime.jsonl")
lines := make([][]byte, 0, maxEventLimit+1)
@@ -268,6 +295,22 @@ func TestFindEventCanReadOutsideTailWindow(t *testing.T) {
}
}
+func TestFindEventCanReadRotatedArchive(t *testing.T) {
+ path := filepath.Join(t.TempDir(), "runtime.jsonl")
+ writeTestLog(t, path+".1",
+ testEvent("2026-05-13T01:00:00Z", "cursor", "command.executed", "command", "repo-a"),
+ testEvent("2026-05-13T01:01:00Z", "cursor", "file.modified", "file", "repo-b"),
+ )
+
+ record, ok, err := FindEvent(path, "archive-1-line-2")
+ if err != nil {
+ t.Fatalf("FindEvent returned error: %v", err)
+ }
+ if !ok || record.Event.Event.Action != "file.modified" {
+ t.Fatalf("FindEvent returned ok=%t action=%q, want archive-1-line-2 file.modified", ok, record.Event.Event.Action)
+ }
+}
+
func TestHandlerEventEndpointOmitsRawAndSetsSecurityHeaders(t *testing.T) {
path := filepath.Join(t.TempDir(), "runtime.jsonl")
writeTestLog(t, path, testEvent("2026-05-13T01:00:00Z", "cursor", "prompt.submitted", "prompt", "repo-a"))