eventsource

package
v0.0.12 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 3, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EventStorePath

func EventStorePath(stateDir, sessionID string) string

EventStorePath returns the directory path for a given session's event store. stateDir is the tool's state directory (e.g. ".siren/"), not the repo root.

func EventsDir

func EventsDir(stateDir string) string

EventsDir returns the path to the events directory under stateDir. stateDir is the tool's state directory (e.g. ".siren/"), not the repo root.

func ListExpiredEventFiles

func ListExpiredEventFiles(stateDir string, days int) ([]string, error)

ListExpiredEventFiles returns session names in events/ whose mtime exceeds the given number of days. stateDir is the tool's state directory (e.g. ".siren/"), not the repo root. Supports both directories (new format) and .jsonl files (legacy). Returns an empty slice (not error) when the events directory does not exist.

func LoadLatestResumableState

func LoadLatestResumableState(stateDir string, match func(*domain.SessionState) bool) (*domain.SessionState, string, error)

LoadLatestResumableState finds the most recent event store whose projected state satisfies the given predicate. This allows callers to skip over non-resumable sessions (e.g. scan-only) and find an older interactive session. stateDir is the tool's state directory (e.g. ".siren/"), not the repo root.

func LoadLatestState

func LoadLatestState(stateDir string) (*domain.SessionState, string, error)

LoadLatestState finds the most recent event store in events/ and replays its events to produce a SessionState. stateDir is the tool's state directory (e.g. ".siren/"), not the repo root. Returns the state, the sessionID, and any error.

func LoadState

func LoadState(store *FileEventStore) (*domain.SessionState, error)

LoadState reads all events from the store and projects them into a SessionState. Returns an error if the store is empty (no events to replay).

func PruneEventFiles

func PruneEventFiles(stateDir string, files []string) ([]string, error)

PruneEventFiles deletes the named entries from events/. stateDir is the tool's state directory (e.g. ".siren/"), not the repo root. Supports both directories and files. Entries that no longer exist are silently skipped. Returns the list of names that were processed.

Types

type FileEventStore

type FileEventStore struct {
	// contains filtered or unexported fields
}

FileEventStore implements EventStore using daily JSONL files in a directory. Each file is named YYYY-MM-DD.jsonl and contains one JSON event per line.

func NewFileEventStore

func NewFileEventStore(dir string, logger domain.Logger) *FileEventStore

NewFileEventStore creates a FileEventStore rooted at the given directory.

func (*FileEventStore) Append

func (s *FileEventStore) Append(events ...domain.Event) (domain.AppendResult, error)

Append persists events as JSONL lines to the daily file based on each event's timestamp. All events are validated before any writes occur; if any event is invalid, the entire batch is rejected.

func (*FileEventStore) LoadAll

func (s *FileEventStore) LoadAll() ([]domain.Event, domain.LoadResult, error)

LoadAll reads all JSONL files in lexicographic order and returns events chronologically.

func (*FileEventStore) LoadSince

func (s *FileEventStore) LoadSince(after time.Time) ([]domain.Event, domain.LoadResult, error)

LoadSince returns events with timestamps strictly after the given time.

type LoadAllResult added in v0.0.11

type LoadAllResult struct {
	SessionsLoaded int
	SessionsFailed int
}

LoadAllResult holds statistics from loading events across sessions.

func LoadAllEventsAcrossSessions

func LoadAllEventsAcrossSessions(stateDir string) ([]domain.Event, LoadAllResult, error)

LoadAllEventsAcrossSessions aggregates events from all session stores under events/. stateDir is the tool's state directory (e.g. ".siren/"), not the repo root. Returns nil, LoadAllResult{}, nil when the events directory does not exist.

type SessionRecorder

type SessionRecorder struct {
	// contains filtered or unexported fields
}

SessionRecorder wraps a FileEventStore with automatic SessionID assignment. It is safe for concurrent use within a single process.

func NewSessionRecorder

func NewSessionRecorder(store eventStore, sessionID string) (*SessionRecorder, error)

NewSessionRecorder creates a SessionRecorder for the given session.

func (*SessionRecorder) Record

func (r *SessionRecorder) Record(ev domain.Event) error

Record appends a pre-built event, enriching it with session metadata. SessionID and CorrelationID are set to the session ID. CausationID is set to the previous event's ID.

type StoreHealth added in v0.0.3

type StoreHealth struct {
	Sessions     int    // number of session directories (or legacy flat files) containing events
	Events       int    // total number of valid JSON lines
	CorruptLines int    // number of corrupt JSON lines encountered
	NotFound     bool   // true when the events directory does not exist
	Err          error  // first error encountered (nil = healthy)
	ErrHint      string // human-readable remediation hint
}

StoreHealth summarises the validation result of the event store.

func ValidateStore added in v0.0.3

func ValidateStore(stateDir string) StoreHealth

ValidateStore walks the event store directory tree rooted at stateDir and checks that every event file contains well-formed JSON lines. It returns a StoreHealth summarising the result.

If the events directory does not exist, StoreHealth is returned with Sessions=0, Events=0, Err=nil (not an error — the store simply has no data).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL