db

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Mar 9, 2026 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// DefaultMessageLimit is the default number of messages returned.
	DefaultMessageLimit = 100
	// MaxMessageLimit is the maximum number of messages returned.
	MaxMessageLimit = 1000
)
View Source
const (
	DefaultSearchLimit = 50
	MaxSearchLimit     = 500
)
View Source
const (
	// DefaultSessionLimit is the default number of sessions returned.
	DefaultSessionLimit = 200
	// MaxSessionLimit is the maximum number of sessions returned.
	MaxSessionLimit = 500
)
View Source
const MaxHeatmapDays = 366

MaxHeatmapDays is the maximum number of day entries the heatmap will return. Ranges exceeding this are clamped to the most recent MaxHeatmapDays from the end date.

Variables

View Source
var ErrInvalidCursor = errors.New("invalid cursor")

ErrInvalidCursor is returned when a cursor cannot be decoded or verified.

View Source
var ErrSessionExcluded = errors.New("session excluded")

ErrSessionExcluded is returned by UpsertSession when the session was permanently deleted by the user. Callers should skip any follow-up writes (messages, tool_calls) for this session.

Functions

This section is empty.

Types

type ActivityEntry

type ActivityEntry struct {
	Date              string         `json:"date"`
	Sessions          int            `json:"sessions"`
	Messages          int            `json:"messages"`
	UserMessages      int            `json:"user_messages"`
	AssistantMessages int            `json:"assistant_messages"`
	ToolCalls         int            `json:"tool_calls"`
	ThinkingMessages  int            `json:"thinking_messages"`
	ByAgent           map[string]int `json:"by_agent"`
}

ActivityEntry is one time bucket in the activity timeline.

type ActivityResponse

type ActivityResponse struct {
	Granularity string          `json:"granularity"`
	Series      []ActivityEntry `json:"series"`
}

ActivityResponse wraps the activity series.

type AgentInfo added in v0.9.0

type AgentInfo struct {
	Name         string `json:"name"`
	SessionCount int    `json:"session_count"`
}

AgentInfo holds an agent name and its session count.

type AgentSummary

type AgentSummary struct {
	Sessions int `json:"sessions"`
	Messages int `json:"messages"`
}

AgentSummary holds per-agent counts for the summary.

type AnalyticsFilter

type AnalyticsFilter struct {
	From            string // ISO date YYYY-MM-DD, inclusive
	To              string // ISO date YYYY-MM-DD, inclusive
	Machine         string // optional machine filter
	Project         string // optional project filter
	Agent           string // optional agent filter
	Timezone        string // IANA timezone for day bucketing
	DayOfWeek       *int   // nil = all, 0=Mon, 6=Sun (ISO)
	Hour            *int   // nil = all, 0-23
	MinUserMessages int    // user_message_count >= N
	ExcludeOneShot  bool   // exclude sessions with user_message_count <= 1
	ActiveSince     string // ISO timestamp cutoff
}

AnalyticsFilter is the shared filter for all analytics queries.

func (AnalyticsFilter) HasTimeFilter

func (f AnalyticsFilter) HasTimeFilter() bool

HasTimeFilter returns true when hour-of-day or day-of-week filtering is active.

type AnalyticsSummary

type AnalyticsSummary struct {
	TotalSessions  int                      `json:"total_sessions"`
	TotalMessages  int                      `json:"total_messages"`
	ActiveProjects int                      `json:"active_projects"`
	ActiveDays     int                      `json:"active_days"`
	AvgMessages    float64                  `json:"avg_messages"`
	MedianMessages int                      `json:"median_messages"`
	P90Messages    int                      `json:"p90_messages"`
	MostActive     string                   `json:"most_active_project"`
	Concentration  float64                  `json:"concentration"`
	Agents         map[string]*AgentSummary `json:"agents"`
}

AnalyticsSummary is the response for the summary endpoint.

type DB

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

DB manages a write connection and a read-only pool. The reader and writer fields use atomic.Pointer so that concurrent HTTP handler goroutines can safely read while Reopen/CloseConnections swap the underlying *sql.DB.

func Open

func Open(path string) (*DB, error)

Open creates or opens a SQLite database at the given path. It configures WAL mode, mmap, and returns a DB with separate writer and reader connections.

If an existing database has an outdated schema (missing columns), it is deleted and recreated from scratch. If the schema is current but the data version is stale, the database is preserved and file mtimes are reset to trigger a re-sync on the next cycle.

func (*DB) BulkStarSessions added in v0.11.0

func (db *DB) BulkStarSessions(sessionIDs []string) error

BulkStarSessions stars multiple sessions in a single transaction. Used for migrating localStorage stars to the database.

func (*DB) Close

func (db *DB) Close() error

Close closes both writer and reader connections, plus any retired pools left over from previous Reopen calls.

func (*DB) CloseConnections added in v0.8.0

func (db *DB) CloseConnections() error

CloseConnections closes both connections without reopening, releasing file locks so the database file can be renamed. Also drains any retired pools from previous Reopen calls. Callers must call Reopen afterwards to restore service.

func (*DB) CopyExcludedSessionsFrom added in v0.11.0

func (d *DB) CopyExcludedSessionsFrom(
	sourcePath string,
) error

CopyExcludedSessionsFrom copies the excluded_sessions table from the source DB so permanently deleted sessions survive full DB rebuilds. The source must not have active connections.

func (*DB) CopyInsightsFrom added in v0.8.0

func (db *DB) CopyInsightsFrom(sourcePath string) error

CopyInsightsFrom copies all insights from the database at sourcePath into this database using ATTACH/DETACH.

func (*DB) CopyOrphanedDataFrom added in v0.10.0

func (d *DB) CopyOrphanedDataFrom(
	sourcePath string,
) (int, error)

CopyOrphanedDataFrom copies sessions (and their messages and tool_calls) that exist in the source database but not in this database. This preserves archived sessions whose source files no longer exist on disk.

Orphaned sessions are identified by ID-diff: any session present in the source but absent from the target after a full file sync. This correctly captures sessions whose source files were deleted, moved, or otherwise lost — exactly the set that would be dropped by a naive DB swap.

The source database must not have active connections (call CloseConnections on its DB handle first). Uses ATTACH DATABASE on a pinned connection for atomicity.

func (*DB) CopySessionMetadataFrom added in v0.11.0

func (d *DB) CopySessionMetadataFrom(
	sourcePath string,
) error

CopySessionMetadataFrom merges user-managed data from the source DB into sessions that were re-synced into this DB. This preserves display_name, deleted_at, starred_sessions, and pinned_messages across full DB rebuilds.

func (*DB) DecodeCursor

func (db *DB) DecodeCursor(s string) (SessionCursor, error)

DecodeCursor parses a base64-encoded cursor string.

func (*DB) DeleteInsight added in v0.4.0

func (db *DB) DeleteInsight(id int64) error

DeleteInsight removes an insight by ID.

func (*DB) DeleteSession

func (db *DB) DeleteSession(id string) error

DeleteSession removes a session and its messages (cascading). The session ID is recorded in excluded_sessions so the sync engine does not re-import it from disk. Both operations run in a single transaction. The exclusion is only written when a session row was actually deleted, preventing ghost entries for non-existent IDs.

func (*DB) DeleteSessionIfTrashed added in v0.11.0

func (db *DB) DeleteSessionIfTrashed(id string) (int64, error)

DeleteSessionIfTrashed atomically deletes a session only if it is currently in the trash (deleted_at IS NOT NULL). Returns the number of rows affected. This avoids a TOCTOU race between checking deleted_at and performing the delete.

func (*DB) DeleteSessions

func (db *DB) DeleteSessions(ids []string) (int, error)

DeleteSessions removes multiple sessions by ID in a single transaction. Batches operations in groups of 500 to stay under SQLite variable limits. Deleted IDs are recorded in excluded_sessions so the sync engine does not re-import them. Returns count of deleted rows.

func (*DB) DeleteSkippedFile added in v0.5.0

func (db *DB) DeleteSkippedFile(path string) error

DeleteSkippedFile removes a single skip cache entry.

func (*DB) DropFTS added in v0.8.0

func (db *DB) DropFTS() error

DropFTS drops the FTS table and its triggers. This makes bulk message delete+reinsert fast by avoiding per-row FTS index updates. Call RebuildFTS after to restore search.

func (*DB) EmptyTrash added in v0.11.0

func (db *DB) EmptyTrash() (int, error)

EmptyTrash permanently deletes all soft-deleted sessions. Session IDs are recorded in excluded_sessions so the sync engine does not re-import them. Both operations run in a single transaction to prevent ghost exclusions when the delete fails. Returns the count of deleted rows.

func (*DB) EncodeCursor

func (db *DB) EncodeCursor(endedAt, id string, total ...int) string

EncodeCursor returns a base64-encoded cursor string.

func (*DB) FileBackedSessionCount added in v0.8.0

func (db *DB) FileBackedSessionCount(
	ctx context.Context,
) (int, error)

FileBackedSessionCount returns the number of root sessions synced from files (excludes OpenCode, which is DB-backed). Used by ResyncAll to decide whether empty file discovery should abort the swap.

func (*DB) FindPruneCandidates

func (db *DB) FindPruneCandidates(
	f PruneFilter,
) ([]Session, error)

FindPruneCandidates returns sessions matching all filter criteria. Returns full Session rows including file metadata.

func (*DB) GetAgents added in v0.9.0

func (db *DB) GetAgents(
	ctx context.Context, excludeOneShot bool,
) ([]AgentInfo, error)

GetAgents returns distinct agent names with session counts.

func (*DB) GetAllMessages

func (db *DB) GetAllMessages(
	ctx context.Context, sessionID string,
) ([]Message, error)

GetAllMessages returns all messages for a session ordered by ordinal.

func (*DB) GetAnalyticsActivity

func (db *DB) GetAnalyticsActivity(
	ctx context.Context, f AnalyticsFilter,
	granularity string,
) (ActivityResponse, error)

GetAnalyticsActivity returns session/message counts grouped by time bucket.

func (*DB) GetAnalyticsHeatmap

func (db *DB) GetAnalyticsHeatmap(
	ctx context.Context, f AnalyticsFilter,
	metric string,
) (HeatmapResponse, error)

GetAnalyticsHeatmap returns daily counts with intensity levels.

func (*DB) GetAnalyticsHourOfWeek

func (db *DB) GetAnalyticsHourOfWeek(
	ctx context.Context, f AnalyticsFilter,
) (HourOfWeekResponse, error)

GetAnalyticsHourOfWeek returns message counts bucketed by day-of-week and hour-of-day in the user's timezone.

func (*DB) GetAnalyticsProjects

func (db *DB) GetAnalyticsProjects(
	ctx context.Context, f AnalyticsFilter,
) (ProjectsAnalyticsResponse, error)

GetAnalyticsProjects returns per-project analytics.

func (*DB) GetAnalyticsSessionShape

func (db *DB) GetAnalyticsSessionShape(
	ctx context.Context, f AnalyticsFilter,
) (SessionShapeResponse, error)

GetAnalyticsSessionShape returns distribution histograms for session length, duration, and autonomy ratio.

func (*DB) GetAnalyticsSummary

func (db *DB) GetAnalyticsSummary(
	ctx context.Context, f AnalyticsFilter,
) (AnalyticsSummary, error)

GetAnalyticsSummary returns aggregate statistics.

func (*DB) GetAnalyticsTools

func (db *DB) GetAnalyticsTools(
	ctx context.Context, f AnalyticsFilter,
) (ToolsAnalyticsResponse, error)

GetAnalyticsTools returns tool usage analytics aggregated from the tool_calls table.

func (*DB) GetAnalyticsTopSessions

func (db *DB) GetAnalyticsTopSessions(
	ctx context.Context, f AnalyticsFilter, metric string,
) (TopSessionsResponse, error)

GetAnalyticsTopSessions returns the top 10 sessions by the given metric ("messages" or "duration") within the filter.

func (*DB) GetAnalyticsVelocity

func (db *DB) GetAnalyticsVelocity(
	ctx context.Context, f AnalyticsFilter,
) (VelocityResponse, error)

GetAnalyticsVelocity computes turn cycle, first response, and throughput metrics with breakdowns by agent and complexity.

func (*DB) GetChildSessions added in v0.7.0

func (db *DB) GetChildSessions(
	ctx context.Context, parentID string,
) ([]Session, error)

GetChildSessions returns sessions whose parent_session_id matches the given parentID, ordered by started_at ascending.

func (*DB) GetFileInfoByPath added in v0.4.1

func (db *DB) GetFileInfoByPath(
	path string,
) (size int64, mtime int64, ok bool)

GetFileInfoByPath returns file_size and file_mtime for a session identified by file_path. Used for codex/gemini files where the session ID requires parsing.

func (*DB) GetInsight added in v0.4.0

func (db *DB) GetInsight(
	ctx context.Context, id int64,
) (*Insight, error)

GetInsight returns a single insight by ID. Returns nil, nil if not found.

func (*DB) GetMachines

func (db *DB) GetMachines(
	ctx context.Context, excludeOneShot bool,
) ([]string, error)

GetMachines returns distinct machine names.

func (*DB) GetMessageByOrdinal

func (db *DB) GetMessageByOrdinal(
	sessionID string, ordinal int,
) (*Message, error)

GetMessageByOrdinal returns a single message by session ID and ordinal.

func (*DB) GetMessages

func (db *DB) GetMessages(
	ctx context.Context,
	sessionID string, from, limit int, asc bool,
) ([]Message, error)

GetMessages returns paginated messages for a session. from: starting ordinal (inclusive) limit: max messages to return asc: true for ascending ordinal order, false for descending

func (*DB) GetMinimap

func (db *DB) GetMinimap(
	ctx context.Context, sessionID string,
) ([]MinimapEntry, error)

GetMinimap returns lightweight metadata for all messages in a session.

func (*DB) GetMinimapFrom

func (db *DB) GetMinimapFrom(
	ctx context.Context, sessionID string, from int,
) ([]MinimapEntry, error)

GetMinimapFrom returns lightweight metadata for messages in a session starting at ordinal >= from.

func (*DB) GetPinnedMessageIDs added in v0.11.0

func (db *DB) GetPinnedMessageIDs(
	ctx context.Context, sessionID string,
) (map[int64]bool, error)

GetPinnedMessageIDs returns message IDs that are pinned for a session.

func (*DB) GetProjects

func (db *DB) GetProjects(
	ctx context.Context, excludeOneShot bool,
) ([]ProjectInfo, error)

GetProjects returns project names with session counts.

func (*DB) GetSession

func (db *DB) GetSession(
	ctx context.Context, id string,
) (*Session, error)

GetSession returns a single session by ID, excluding soft-deleted (trashed) sessions.

func (*DB) GetSessionFileInfo

func (db *DB) GetSessionFileInfo(
	id string,
) (size int64, mtime int64, ok bool)

GetSessionFileInfo returns file_size and file_mtime for a session. Used for fast skip checks during sync.

func (*DB) GetSessionFull

func (db *DB) GetSessionFull(
	ctx context.Context, id string,
) (*Session, error)

GetSessionFull returns a single session by ID with all file metadata.

func (*DB) GetStats

func (db *DB) GetStats(
	ctx context.Context, excludeOneShot bool,
) (Stats, error)

GetStats returns database statistics, counting only root sessions with messages (matching the session list filter).

func (*DB) HasFTS

func (db *DB) HasFTS() bool

HasFTS checks if Full Text Search is available.

func (*DB) InsertInsight added in v0.4.0

func (db *DB) InsertInsight(s Insight) (int64, error)

InsertInsight inserts an insight and returns its ID.

func (*DB) InsertMessages

func (db *DB) InsertMessages(msgs []Message) error

InsertMessages batch-inserts messages for a session.

func (*DB) IsSessionExcluded added in v0.11.0

func (db *DB) IsSessionExcluded(id string) bool

IsSessionExcluded returns true if the session ID was permanently deleted by the user.

func (*DB) ListInsights added in v0.4.0

func (db *DB) ListInsights(
	ctx context.Context, f InsightFilter,
) ([]Insight, error)

ListInsights returns insights matching the filter, ordered by created_at DESC, capped at 500 rows.

func (*DB) ListPinnedMessages added in v0.11.0

func (db *DB) ListPinnedMessages(
	ctx context.Context, sessionID string,
) ([]PinnedMessage, error)

ListPinnedMessages returns all pins, optionally filtered by session. Pass empty sessionID for all pins across all sessions. When listing all pins, message content and role are included.

func (*DB) ListSessions

func (db *DB) ListSessions(
	ctx context.Context, f SessionFilter,
) (SessionPage, error)

ListSessions returns a cursor-paginated list of sessions.

func (*DB) ListStarredSessionIDs added in v0.11.0

func (db *DB) ListStarredSessionIDs(
	ctx context.Context,
) ([]string, error)

ListStarredSessionIDs returns all starred session IDs.

func (*DB) ListTrashedSessions added in v0.11.0

func (db *DB) ListTrashedSessions(
	ctx context.Context,
) ([]Session, error)

ListTrashedSessions returns sessions that have been soft-deleted.

func (*DB) LoadSkippedFiles added in v0.5.0

func (db *DB) LoadSkippedFiles() (map[string]int64, error)

LoadSkippedFiles returns all persisted skip cache entries as a map from file_path to file_mtime.

func (*DB) MaxOrdinal added in v0.5.0

func (db *DB) MaxOrdinal(sessionID string) int

MaxOrdinal returns the highest ordinal for a session, or -1 if the session has no messages.

func (*DB) MessageCount

func (db *DB) MessageCount(sessionID string) (int, error)

MessageCount returns the number of messages for a session.

func (*DB) NeedsResync added in v0.10.0

func (db *DB) NeedsResync() bool

NeedsResync reports whether the database was opened with a stale data version, indicating the caller should trigger a full resync (build fresh DB, copy orphaned data, swap) rather than an incremental sync.

func (*DB) Path added in v0.8.0

func (db *DB) Path() string

Path returns the file path of the database.

func (*DB) PinMessage added in v0.11.0

func (db *DB) PinMessage(
	sessionID string, messageID int64, note *string,
) (int64, error)

PinMessage creates a pin for a message. If the message is already pinned, the note is updated. The message must belong to the specified session (enforced via INSERT ... SELECT).

func (*DB) PurgeExcludedSessions added in v0.11.0

func (db *DB) PurgeExcludedSessions() error

PurgeExcludedSessions removes any session rows whose IDs appear in excluded_sessions. Used after a resync to clean up sessions that were synced before their exclusion was recorded.

func (*DB) Reader

func (db *DB) Reader() *sql.DB

Reader returns the read-only connection pool.

func (*DB) RebuildFTS added in v0.8.0

func (db *DB) RebuildFTS() error

RebuildFTS recreates the FTS table, triggers, and repopulates the index from the messages table.

func (*DB) RenameSession added in v0.11.0

func (db *DB) RenameSession(id string, displayName *string) error

RenameSession sets or clears the display_name for a session. Pass nil to clear a custom name (reverts to first_message).

func (*DB) Reopen added in v0.8.0

func (db *DB) Reopen() error

Reopen closes and reopens both connections to the same path. Used after an atomic file swap to pick up the new database contents. Preserves cursorSecret.

func (*DB) ReplaceSessionMessages

func (db *DB) ReplaceSessionMessages(
	sessionID string, msgs []Message,
) error

ReplaceSessionMessages deletes existing and inserts new messages in a single transaction.

func (*DB) ReplaceSkippedFiles added in v0.5.0

func (db *DB) ReplaceSkippedFiles(
	entries map[string]int64,
) error

ReplaceSkippedFiles replaces all skip cache entries in a single transaction. This is called after each sync cycle to persist the in-memory skip cache.

func (*DB) ResetAllMtimes added in v0.6.0

func (db *DB) ResetAllMtimes() error

ResetAllMtimes zeroes file_mtime for every session, forcing the next sync to re-process all files regardless of whether their size+mtime matches what was previously stored.

func (*DB) RestoreSession added in v0.11.0

func (db *DB) RestoreSession(id string) (int64, error)

RestoreSession clears deleted_at, making the session visible again. Returns the number of rows affected (0 if session doesn't exist or is not in trash).

func (*DB) Search

func (db *DB) Search(
	ctx context.Context, f SearchFilter,
) (SearchPage, error)

Search performs FTS5 full-text search across messages.

func (*DB) SetCursorSecret

func (db *DB) SetCursorSecret(secret []byte)

SetCursorSecret updates the secret key used for cursor signing.

func (*DB) SoftDeleteSession added in v0.11.0

func (db *DB) SoftDeleteSession(id string) error

SoftDeleteSession marks a session as deleted by setting deleted_at.

func (*DB) StarSession added in v0.11.0

func (db *DB) StarSession(sessionID string) (bool, error)

StarSession marks a session as starred. Uses INSERT...SELECT with an EXISTS check so the operation is atomic and avoids FK errors if the session is concurrently deleted. Returns false if the session does not exist (idempotent for already-starred).

func (*DB) UnpinMessage added in v0.11.0

func (db *DB) UnpinMessage(sessionID string, messageID int64) error

UnpinMessage removes a pin.

func (*DB) UnstarSession added in v0.11.0

func (db *DB) UnstarSession(sessionID string) error

UnstarSession removes a session's star.

func (*DB) Update

func (db *DB) Update(fn func(tx *sql.Tx) error) error

Update executes fn within a write lock and transaction. The transaction is committed if fn returns nil, rolled back otherwise.

func (*DB) UpsertSession

func (db *DB) UpsertSession(s Session) error

UpsertSession inserts or updates a session. Sessions that were permanently deleted (in excluded_sessions) are silently skipped.

type DistributionBucket

type DistributionBucket struct {
	Label string `json:"label"`
	Count int    `json:"count"`
}

DistributionBucket is a labeled count for histogram display.

type HeatmapEntry

type HeatmapEntry struct {
	Date  string `json:"date"`
	Value int    `json:"value"`
	Level int    `json:"level"`
}

HeatmapEntry is one day in the heatmap calendar.

type HeatmapLevels

type HeatmapLevels struct {
	L1 int `json:"l1"`
	L2 int `json:"l2"`
	L3 int `json:"l3"`
	L4 int `json:"l4"`
}

HeatmapLevels defines the quartile thresholds for levels 1-4.

type HeatmapResponse

type HeatmapResponse struct {
	Metric      string         `json:"metric"`
	Entries     []HeatmapEntry `json:"entries"`
	Levels      HeatmapLevels  `json:"levels"`
	EntriesFrom string         `json:"entries_from"`
}

HeatmapResponse wraps the heatmap data.

type HourOfWeekCell

type HourOfWeekCell struct {
	DayOfWeek int `json:"day_of_week"` // 0=Mon, 6=Sun
	Hour      int `json:"hour"`        // 0-23
	Messages  int `json:"messages"`
}

HourOfWeekCell is one cell in the 7x24 hour-of-week grid.

type HourOfWeekResponse

type HourOfWeekResponse struct {
	Cells []HourOfWeekCell `json:"cells"`
}

HourOfWeekResponse wraps the hour-of-week heatmap data.

type Insight added in v0.4.0

type Insight struct {
	ID        int64   `json:"id"`
	Type      string  `json:"type"`
	DateFrom  string  `json:"date_from"`
	DateTo    string  `json:"date_to"`
	Project   *string `json:"project"`
	Agent     string  `json:"agent"`
	Model     *string `json:"model"`
	Prompt    *string `json:"prompt"`
	Content   string  `json:"content"`
	CreatedAt string  `json:"created_at"`
}

Insight represents a row in the insights table.

type InsightFilter added in v0.4.0

type InsightFilter struct {
	Type       string // "daily_activity" or "agent_analysis"
	Project    string // "" = no filter
	GlobalOnly bool   // true = project IS NULL only
}

InsightFilter specifies how to query insights.

type Message

type Message struct {
	ID            int64        `json:"id"`
	SessionID     string       `json:"session_id"`
	Ordinal       int          `json:"ordinal"`
	Role          string       `json:"role"`
	Content       string       `json:"content"`
	Timestamp     string       `json:"timestamp"`
	HasThinking   bool         `json:"has_thinking"`
	HasToolUse    bool         `json:"has_tool_use"`
	ContentLength int          `json:"content_length"`
	ToolCalls     []ToolCall   `json:"tool_calls,omitempty"`
	ToolResults   []ToolResult `json:"-"` // transient, for pairing
}

Message represents a row in the messages table.

type MinimapEntry

type MinimapEntry struct {
	Ordinal       int    `json:"ordinal"`
	Role          string `json:"role"`
	ContentLength int    `json:"content_length"`
	HasThinking   bool   `json:"has_thinking"`
	HasToolUse    bool   `json:"has_tool_use"`
}

MinimapEntry is a lightweight message summary for minimap rendering.

func SampleMinimap

func SampleMinimap(
	entries []MinimapEntry, max int,
) []MinimapEntry

SampleMinimap downsamples entries to at most max points while preserving ordering and both endpoints.

type Percentiles

type Percentiles struct {
	P50 float64 `json:"p50"`
	P90 float64 `json:"p90"`
}

Percentiles holds p50 and p90 values.

type PinnedMessage added in v0.11.0

type PinnedMessage struct {
	ID        int64   `json:"id"`
	SessionID string  `json:"session_id"`
	MessageID int64   `json:"message_id"`
	Ordinal   int     `json:"ordinal"`
	Note      *string `json:"note,omitempty"`
	Content   *string `json:"content,omitempty"`
	Role      *string `json:"role,omitempty"`
	CreatedAt string  `json:"created_at"`

	// Session metadata — populated only for the "all pins" query.
	SessionProject      *string `json:"session_project,omitempty"`
	SessionAgent        *string `json:"session_agent,omitempty"`
	SessionDisplayName  *string `json:"session_display_name,omitempty"`
	SessionFirstMessage *string `json:"session_first_message,omitempty"`
}

PinnedMessage represents a row in the pinned_messages table.

type ProjectAnalytics

type ProjectAnalytics struct {
	Name           string         `json:"name"`
	Sessions       int            `json:"sessions"`
	Messages       int            `json:"messages"`
	FirstSession   string         `json:"first_session"`
	LastSession    string         `json:"last_session"`
	AvgMessages    float64        `json:"avg_messages"`
	MedianMessages int            `json:"median_messages"`
	Agents         map[string]int `json:"agents"`
	DailyTrend     float64        `json:"daily_trend"`
}

ProjectAnalytics holds analytics for a single project.

type ProjectInfo

type ProjectInfo struct {
	Name         string `json:"name"`
	SessionCount int    `json:"session_count"`
}

ProjectInfo holds a project name and its session count.

type ProjectsAnalyticsResponse

type ProjectsAnalyticsResponse struct {
	Projects []ProjectAnalytics `json:"projects"`
}

ProjectsAnalyticsResponse wraps the projects list.

type PruneFilter

type PruneFilter struct {
	Project      string // substring match (LIKE '%x%')
	MaxMessages  *int   // user messages <= N (nil = no filter)
	Before       string // ended_at < date (YYYY-MM-DD)
	FirstMessage string // first_message LIKE 'prefix%'
}

PruneFilter defines criteria for finding sessions to prune. Filters combine with AND. At least one must be set.

func (PruneFilter) HasFilters

func (f PruneFilter) HasFilters() bool

HasFilters reports whether at least one filter is set.

type SearchFilter

type SearchFilter struct {
	Query   string
	Project string
	Cursor  int // offset for pagination
	Limit   int
}

SearchFilter specifies search parameters.

type SearchPage

type SearchPage struct {
	Results    []SearchResult `json:"results"`
	NextCursor int            `json:"next_cursor,omitempty"`
}

SearchPage holds paginated search results.

type SearchResult

type SearchResult struct {
	SessionID string  `json:"session_id"`
	Project   string  `json:"project"`
	Ordinal   int     `json:"ordinal"`
	Role      string  `json:"role"`
	Timestamp string  `json:"timestamp"`
	Snippet   string  `json:"snippet"`
	Rank      float64 `json:"rank"`
}

SearchResult holds a message match with session context.

type Session

type Session struct {
	ID               string  `json:"id"`
	Project          string  `json:"project"`
	Machine          string  `json:"machine"`
	Agent            string  `json:"agent"`
	FirstMessage     *string `json:"first_message"`
	DisplayName      *string `json:"display_name,omitempty"`
	StartedAt        *string `json:"started_at"`
	EndedAt          *string `json:"ended_at"`
	MessageCount     int     `json:"message_count"`
	UserMessageCount int     `json:"user_message_count"`
	ParentSessionID  *string `json:"parent_session_id,omitempty"`
	RelationshipType string  `json:"relationship_type,omitempty"`
	DeletedAt        *string `json:"deleted_at,omitempty"`
	FilePath         *string `json:"file_path,omitempty"`
	FileSize         *int64  `json:"file_size,omitempty"`
	FileMtime        *int64  `json:"file_mtime,omitempty"`
	FileHash         *string `json:"file_hash,omitempty"`
	CreatedAt        string  `json:"created_at"`
}

Session represents a row in the sessions table.

type SessionCursor

type SessionCursor struct {
	EndedAt string `json:"e"`
	ID      string `json:"i"`
	Total   int    `json:"t,omitempty"`
}

SessionCursor is the opaque pagination token.

type SessionFilter

type SessionFilter struct {
	Project         string
	ExcludeProject  string // exclude sessions with this project name
	Machine         string
	Agent           string
	Date            string // exact date YYYY-MM-DD
	DateFrom        string // range start (inclusive)
	DateTo          string // range end (inclusive)
	ActiveSince     string // ISO-8601 timestamp; filters on most recent activity
	MinMessages     int    // message_count >= N (0 = no filter)
	MaxMessages     int    // message_count <= N (0 = no filter)
	MinUserMessages int    // user_message_count >= N (0 = no filter)
	ExcludeOneShot  bool   // exclude sessions with user_message_count <= 1
	Cursor          string // opaque cursor from previous page
	Limit           int
}

SessionFilter specifies how to query sessions.

type SessionPage

type SessionPage struct {
	Sessions   []Session `json:"sessions"`
	NextCursor string    `json:"next_cursor,omitempty"`
	Total      int       `json:"total"`
}

SessionPage is a page of session results.

type SessionShapeResponse

type SessionShapeResponse struct {
	Count                int                  `json:"count"`
	LengthDistribution   []DistributionBucket `json:"length_distribution"`
	DurationDistribution []DistributionBucket `json:"duration_distribution"`
	AutonomyDistribution []DistributionBucket `json:"autonomy_distribution"`
}

SessionShapeResponse holds distribution histograms for session characteristics.

type Stats

type Stats struct {
	SessionCount    int     `json:"session_count"`
	MessageCount    int     `json:"message_count"`
	ProjectCount    int     `json:"project_count"`
	MachineCount    int     `json:"machine_count"`
	EarliestSession *string `json:"earliest_session"`
}

Stats holds database-wide statistics.

type ToolAgentBreakdown

type ToolAgentBreakdown struct {
	Agent      string              `json:"agent"`
	Total      int                 `json:"total"`
	Categories []ToolCategoryCount `json:"categories"`
}

ToolAgentBreakdown holds tool usage breakdown for one agent.

type ToolCall

type ToolCall struct {
	MessageID           int64  `json:"-"`
	SessionID           string `json:"-"`
	ToolName            string `json:"tool_name"`
	Category            string `json:"category"`
	ToolUseID           string `json:"tool_use_id,omitempty"`
	InputJSON           string `json:"input_json,omitempty"`
	SkillName           string `json:"skill_name,omitempty"`
	ResultContentLength int    `json:"result_content_length,omitempty"`
	ResultContent       string `json:"result_content,omitempty"`
	SubagentSessionID   string `json:"subagent_session_id,omitempty"`
}

ToolCall represents a single tool invocation stored in the tool_calls table.

type ToolCategoryCount

type ToolCategoryCount struct {
	Category string  `json:"category"`
	Count    int     `json:"count"`
	Pct      float64 `json:"pct"`
}

ToolCategoryCount holds a count and percentage for one tool category.

type ToolResult added in v0.4.0

type ToolResult struct {
	ToolUseID     string
	ContentLength int
	ContentRaw    string // raw JSON of the content field; decode lazily
}

ToolResult holds a tool_result content block for pairing.

type ToolTrendEntry

type ToolTrendEntry struct {
	Date  string         `json:"date"`
	ByCat map[string]int `json:"by_category"`
}

ToolTrendEntry holds tool call counts for one time bucket.

type ToolsAnalyticsResponse

type ToolsAnalyticsResponse struct {
	TotalCalls int                  `json:"total_calls"`
	ByCategory []ToolCategoryCount  `json:"by_category"`
	ByAgent    []ToolAgentBreakdown `json:"by_agent"`
	Trend      []ToolTrendEntry     `json:"trend"`
}

ToolsAnalyticsResponse wraps tool usage analytics.

type TopSession

type TopSession struct {
	ID           string  `json:"id"`
	Project      string  `json:"project"`
	FirstMessage *string `json:"first_message"`
	MessageCount int     `json:"message_count"`
	DurationMin  float64 `json:"duration_min"`
}

TopSession holds summary info for a ranked session.

type TopSessionsResponse

type TopSessionsResponse struct {
	Metric   string       `json:"metric"`
	Sessions []TopSession `json:"sessions"`
}

TopSessionsResponse wraps the top sessions list.

type VelocityBreakdown

type VelocityBreakdown struct {
	Label    string           `json:"label"`
	Sessions int              `json:"sessions"`
	Overview VelocityOverview `json:"overview"`
}

VelocityBreakdown is velocity metrics for a subgroup.

type VelocityOverview

type VelocityOverview struct {
	TurnCycleSec          Percentiles `json:"turn_cycle_sec"`
	FirstResponseSec      Percentiles `json:"first_response_sec"`
	MsgsPerActiveMin      float64     `json:"msgs_per_active_min"`
	CharsPerActiveMin     float64     `json:"chars_per_active_min"`
	ToolCallsPerActiveMin float64     `json:"tool_calls_per_active_min"`
}

VelocityOverview holds aggregate velocity metrics.

type VelocityResponse

type VelocityResponse struct {
	Overall      VelocityOverview    `json:"overall"`
	ByAgent      []VelocityBreakdown `json:"by_agent"`
	ByComplexity []VelocityBreakdown `json:"by_complexity"`
}

VelocityResponse wraps overall and grouped velocity metrics.

Jump to

Keyboard shortcuts

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