Documentation
¶
Index ¶
- Constants
- func DefaultDBPath() string
- type EventNameCount
- type StatsStore
- func (s *StatsStore) BuildToolStats(ctx context.Context, since, until time.Time) (*ToolStats, error)
- func (s *StatsStore) Close() error
- func (s *StatsStore) InsertEvent(ctx context.Context, sessionID, eventName, toolName, cwd, errorType string, ...) error
- func (s *StatsStore) Prune(ctx context.Context) (int64, error)
- func (s *StatsStore) QueryByEventName(ctx context.Context, since, until time.Time) ([]EventNameCount, error)
- func (s *StatsStore) QueryByHour(ctx context.Context, since, until time.Time) ([]TimeBucket, error)
- func (s *StatsStore) QueryByTool(ctx context.Context, since, until time.Time) ([]ToolCount, error)
- func (s *StatsStore) QueryTotal(ctx context.Context, since, until time.Time) (int, error)
- type TimeBucket
- type ToolCount
- type ToolStats
- type Writer
Constants ¶
const RetentionDays = 30
RetentionDays is the rolling window for event retention.
Variables ¶
This section is empty.
Functions ¶
func DefaultDBPath ¶
func DefaultDBPath() string
DefaultDBPath returns the path to the stats database (~/.human/stats.db), creating the directory if needed.
Types ¶
type EventNameCount ¶
EventNameCount holds an event name and its count.
type StatsStore ¶
type StatsStore struct {
// contains filtered or unexported fields
}
StatsStore persists tool call events in SQLite for historical trend queries.
func NewStatsStore ¶
func NewStatsStore(dbPath string) (*StatsStore, error)
NewStatsStore opens (or creates) a SQLite database at dbPath and ensures the schema is up to date. Use ":memory:" for in-memory databases in tests.
func (*StatsStore) BuildToolStats ¶
func (s *StatsStore) BuildToolStats(ctx context.Context, since, until time.Time) (*ToolStats, error)
BuildToolStats runs all aggregation queries for a time range and returns a ready-to-render ToolStats.
func (*StatsStore) InsertEvent ¶
func (s *StatsStore) InsertEvent(ctx context.Context, sessionID, eventName, toolName, cwd, errorType string, ts time.Time) error
InsertEvent persists a single tool call event.
func (*StatsStore) Prune ¶
func (s *StatsStore) Prune(ctx context.Context) (int64, error)
Prune deletes events older than RetentionDays.
func (*StatsStore) QueryByEventName ¶
func (s *StatsStore) QueryByEventName(ctx context.Context, since, until time.Time) ([]EventNameCount, error)
QueryByEventName returns event counts grouped by event_name for the given time range.
func (*StatsStore) QueryByHour ¶
func (s *StatsStore) QueryByHour(ctx context.Context, since, until time.Time) ([]TimeBucket, error)
QueryByHour returns event counts grouped by hour for the given time range.
func (*StatsStore) QueryByTool ¶
QueryByTool returns tool call counts grouped by tool_name for the given time range.
func (*StatsStore) QueryTotal ¶
QueryTotal returns the total event count for the given time range.
type TimeBucket ¶
TimeBucket holds a time bucket label and its event count.
type ToolStats ¶
type ToolStats struct {
ByTool []ToolCount `json:"by_tool"`
ByHour []TimeBucket `json:"by_hour"`
ByEventName []EventNameCount `json:"by_event_name"`
TotalEvents int `json:"total_events"`
Since time.Time `json:"since"`
Until time.Time `json:"until"`
}
ToolStats is the pre-aggregated stats payload sent to the TUI.
type Writer ¶
type Writer struct {
// contains filtered or unexported fields
}
Writer accepts hook events on a channel and inserts them into a StatsStore in a single background goroutine. Call Close to drain remaining events and shut down.
func NewWriter ¶
NewWriter creates a Writer and starts the background drain goroutine. The goroutine runs until ctx is cancelled or Close is called.
func (*Writer) Close ¶
func (w *Writer) Close()
Close signals the writer to stop and waits for the background goroutine to finish draining. It is idempotent and safe to call after ctx cancellation has already stopped the goroutine.
func (*Writer) Send ¶
func (w *Writer) Send(evt hookevents.Event)
Send enqueues an event for async persistence. If the channel is full the event is dropped silently (trends tolerate small gaps). The data channel is never closed, so Send is safe to call concurrently with — and after — Close without panicking; the quit case just discards events once shut down.