session

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Jun 23, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package session implements the SQLite session store for Cortex.

It provides lifecycle management for coding sessions, including creation, retrieval, ending, and querying sessions and their associated observations. The store implements the domain.SessionRepository interface with additional methods for session stats and observations by session queries.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type SessionStats

type SessionStats struct {
	Session          *domain.Session
	ObservationCount int
}

SessionStats represents statistics about a session.

type Stats

type Stats struct {
	TotalSessions     int
	ActiveSessions    int
	EndedSessions     int
	TotalObservations int
	Projects          []string
}

Stats represents overall session statistics.

type Store

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

Store implements the SQLite session store. It provides CRUD operations for sessions and related queries.

func NewStore

func NewStore(db *sql.DB) *Store

NewStore creates a new session store with the given database connection.

func (*Store) Create

func (s *Store) Create(ctx context.Context, session *domain.Session) error

Create inserts a new session into the database. It sets the StartedAt timestamp if not already set. Returns an error if a session with the same ID already exists.

func (*Store) End

func (s *Store) End(ctx context.Context, id string, summary string) error

End marks a session as completed with an optional summary. It sets the ended_at timestamp to the current time and updates the summary. Returns ErrNotFound if the session does not exist. Returns ErrSessionEnded if the session has already ended.

func (*Store) GetByID

func (s *Store) GetByID(ctx context.Context, id string) (*domain.Session, error)

GetByID retrieves a session by its ID. Returns ErrNotFound if the session does not exist.

func (*Store) GetCurrent

func (s *Store) GetCurrent(ctx context.Context, project string) (*domain.Session, error)

GetCurrent retrieves the most recent active session for a project. An active session is one where ended_at is NULL. Returns ErrNotFound if no active session exists for the project.

func (*Store) GetStats

func (s *Store) GetStats(ctx context.Context) (*Stats, error)

GetStats retrieves overall session statistics.

func (*Store) GetWithStats

func (s *Store) GetWithStats(ctx context.Context, id string) (*SessionStats, error)

GetWithStats retrieves a session with its observation count. Returns ErrNotFound if the session does not exist.

func (*Store) List

func (s *Store) List(ctx context.Context, project string) ([]*domain.Session, error)

List retrieves sessions for a project, ordered by most recent first. If project is empty, returns all sessions. Sessions are ordered by started_at descending.

func (*Store) Recent

func (s *Store) Recent(ctx context.Context, project string, limit int) ([]*domain.Session, error)

Recent retrieves the most recent sessions with optional project filter. Sessions are ordered by started_at descending with a limit. If limit is <= 0, a default limit of 5 is used.

func (*Store) RecentWithStats

func (s *Store) RecentWithStats(ctx context.Context, project string, limit int) ([]*SessionStats, error)

RecentWithStats retrieves recent sessions with their observation counts. Sessions are ordered by most recent activity first. If limit is <= 0, a default limit of 5 is used.

Jump to

Keyboard shortcuts

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