Documentation
¶
Index ¶
- func GetDBPath() (string, error)
- func GetDataDir() (string, error)
- func NewID() string
- func ParseIDTime(id string) time.Time
- func ShortID(id string) string
- func TruncateSummary(content string) string
- type Config
- type ListOptions
- type Message
- type NoopStore
- func (s *NoopStore) AddMessage(ctx context.Context, sessionID string, msg *Message) error
- func (s *NoopStore) ClearCurrent(ctx context.Context) error
- func (s *NoopStore) Close() error
- func (s *NoopStore) Create(ctx context.Context, sess *Session) error
- func (s *NoopStore) Delete(ctx context.Context, id string) error
- func (s *NoopStore) Get(ctx context.Context, id string) (*Session, error)
- func (s *NoopStore) GetCurrent(ctx context.Context) (*Session, error)
- func (s *NoopStore) GetMessages(ctx context.Context, sessionID string, limit, offset int) ([]Message, error)
- func (s *NoopStore) List(ctx context.Context, opts ListOptions) ([]SessionSummary, error)
- func (s *NoopStore) Search(ctx context.Context, query string, limit int) ([]SearchResult, error)
- func (s *NoopStore) SetCurrent(ctx context.Context, sessionID string) error
- func (s *NoopStore) Update(ctx context.Context, sess *Session) error
- type SQLiteStore
- func (s *SQLiteStore) AddMessage(ctx context.Context, sessionID string, msg *Message) error
- func (s *SQLiteStore) ClearCurrent(ctx context.Context) error
- func (s *SQLiteStore) Close() error
- func (s *SQLiteStore) Create(ctx context.Context, sess *Session) error
- func (s *SQLiteStore) Delete(ctx context.Context, id string) error
- func (s *SQLiteStore) Get(ctx context.Context, id string) (*Session, error)
- func (s *SQLiteStore) GetCurrent(ctx context.Context) (*Session, error)
- func (s *SQLiteStore) GetMessages(ctx context.Context, sessionID string, limit, offset int) ([]Message, error)
- func (s *SQLiteStore) List(ctx context.Context, opts ListOptions) ([]SessionSummary, error)
- func (s *SQLiteStore) Search(ctx context.Context, query string, limit int) ([]SearchResult, error)
- func (s *SQLiteStore) SetCurrent(ctx context.Context, sessionID string) error
- func (s *SQLiteStore) Update(ctx context.Context, sess *Session) error
- type SearchResult
- type Session
- type SessionSummary
- type Store
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetDataDir ¶
GetDataDir returns the XDG data directory for term-llm. Uses $XDG_DATA_HOME if set, otherwise ~/.local/share
func NewID ¶
func NewID() string
NewID generates a unique session ID using a timestamp prefix and random suffix. Format: YYYYMMDD-HHMMSS-RANDOM (e.g., "20240115-143052-a1b2c3") This format:
- Sorts chronologically by default
- Is human-readable for debugging
- Has enough randomness to prevent collisions
func ParseIDTime ¶
ParseIDTime extracts the timestamp from a session ID. Returns zero time if parsing fails.
func ShortID ¶
ShortID returns a shortened version of the session ID for display. Example: "20240115-143052-a1b2c3" -> "240115-1430"
func TruncateSummary ¶
TruncateSummary returns the first line of content, truncated to 100 chars.
Types ¶
type Config ¶
type Config struct {
Enabled bool `mapstructure:"enabled"` // Master switch
MaxAgeDays int `mapstructure:"max_age_days"` // Auto-delete after N days (0=never)
MaxCount int `mapstructure:"max_count"` // Keep at most N sessions (0=unlimited)
}
Config holds session storage configuration.
func DefaultConfig ¶
func DefaultConfig() Config
DefaultConfig returns the default session configuration.
type ListOptions ¶
type ListOptions struct {
Provider string // Filter by provider
Model string // Filter by model
Limit int // Max results (0 = use default)
Offset int // Pagination offset
Archived bool // Include archived sessions
}
ListOptions configures session listing.
type Message ¶
type Message struct {
ID int64 `json:"id"`
SessionID string `json:"session_id"`
Role llm.Role `json:"role"`
Parts []llm.Part `json:"parts"` // Full parts array
TextContent string `json:"text_content"` // Extracted text for display/FTS
DurationMs int64 `json:"duration_ms,omitempty"`
CreatedAt time.Time `json:"created_at"`
Sequence int `json:"sequence"`
}
Message represents a message in a session. The Parts field stores the full llm.Message.Parts as JSON to preserve tool calls and results exactly.
func NewMessage ¶
NewMessage creates a new Message from an llm.Message with the given session ID and sequence.
func (*Message) ExtractTextContent ¶
ExtractTextContent extracts and concatenates all text parts from the message.
func (*Message) PartsJSON ¶
PartsJSON returns the Parts field serialized to JSON for database storage.
func (*Message) SetPartsFromJSON ¶
SetPartsFromJSON deserializes JSON into the Parts field.
func (*Message) ToLLMMessage ¶
ToLLMMessage converts a Message back to an llm.Message.
type NoopStore ¶
type NoopStore struct{}
NoopStore is a no-op implementation of Store used when sessions are disabled. It silently discards all writes and returns empty results for reads.
func (*NoopStore) AddMessage ¶
func (*NoopStore) GetCurrent ¶
func (*NoopStore) GetMessages ¶
func (*NoopStore) List ¶
func (s *NoopStore) List(ctx context.Context, opts ListOptions) ([]SessionSummary, error)
func (*NoopStore) SetCurrent ¶
type SQLiteStore ¶
type SQLiteStore struct {
// contains filtered or unexported fields
}
SQLiteStore implements Store using SQLite.
func NewSQLiteStore ¶
func NewSQLiteStore(cfg Config) (*SQLiteStore, error)
NewSQLiteStore creates a new SQLite-based session store.
func (*SQLiteStore) AddMessage ¶
AddMessage adds a message to a session.
func (*SQLiteStore) ClearCurrent ¶
func (s *SQLiteStore) ClearCurrent(ctx context.Context) error
ClearCurrent removes the current session marker.
func (*SQLiteStore) Close ¶
func (s *SQLiteStore) Close() error
Close closes the database connection.
func (*SQLiteStore) Create ¶
func (s *SQLiteStore) Create(ctx context.Context, sess *Session) error
Create inserts a new session.
func (*SQLiteStore) Delete ¶
func (s *SQLiteStore) Delete(ctx context.Context, id string) error
Delete removes a session and its messages.
func (*SQLiteStore) GetCurrent ¶
func (s *SQLiteStore) GetCurrent(ctx context.Context) (*Session, error)
GetCurrent retrieves the current session.
func (*SQLiteStore) GetMessages ¶
func (s *SQLiteStore) GetMessages(ctx context.Context, sessionID string, limit, offset int) ([]Message, error)
GetMessages retrieves messages for a session.
func (*SQLiteStore) List ¶
func (s *SQLiteStore) List(ctx context.Context, opts ListOptions) ([]SessionSummary, error)
List returns sessions matching the options.
func (*SQLiteStore) Search ¶
func (s *SQLiteStore) Search(ctx context.Context, query string, limit int) ([]SearchResult, error)
Search finds sessions containing the query text using FTS5.
func (*SQLiteStore) SetCurrent ¶
func (s *SQLiteStore) SetCurrent(ctx context.Context, sessionID string) error
SetCurrent marks a session as the current one.
type SearchResult ¶
type SearchResult struct {
SessionID string `json:"session_id"`
MessageID int64 `json:"message_id"`
SessionName string `json:"session_name"`
Summary string `json:"summary"`
Snippet string `json:"snippet"` // Matched text snippet
Provider string `json:"provider"`
Model string `json:"model"`
CreatedAt time.Time `json:"created_at"`
}
SearchResult represents a search match.
type Session ¶
type Session struct {
ID string `json:"id"`
Name string `json:"name,omitempty"`
Summary string `json:"summary,omitempty"` // First user message or auto-generated
Provider string `json:"provider"`
Model string `json:"model"`
CWD string `json:"cwd,omitempty"` // Working directory at session start
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
Archived bool `json:"archived,omitempty"`
ParentID string `json:"parent_id,omitempty"` // For session branching
// Session settings (restored on resume unless overridden)
Search bool `json:"search,omitempty"` // Web search enabled
Tools string `json:"tools,omitempty"` // Enabled tools (comma-separated)
MCP string `json:"mcp,omitempty"` // Enabled MCP servers (comma-separated)
}
Session represents a chat session stored in the database.
type SessionSummary ¶
type SessionSummary struct {
ID string `json:"id"`
Name string `json:"name,omitempty"`
Summary string `json:"summary,omitempty"`
Provider string `json:"provider"`
Model string `json:"model"`
MessageCount int `json:"message_count"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
SessionSummary is a lightweight view of a session for listing.
type Store ¶
type Store interface {
// Session CRUD
Create(ctx context.Context, s *Session) error
Get(ctx context.Context, id string) (*Session, error)
Update(ctx context.Context, s *Session) error
Delete(ctx context.Context, id string) error
// Listing and search
List(ctx context.Context, opts ListOptions) ([]SessionSummary, error)
Search(ctx context.Context, query string, limit int) ([]SearchResult, error)
// Message operations - stores full llm.Message with Parts
AddMessage(ctx context.Context, sessionID string, msg *Message) error
GetMessages(ctx context.Context, sessionID string, limit, offset int) ([]Message, error)
// Current session tracking (for auto-resume)
SetCurrent(ctx context.Context, sessionID string) error
GetCurrent(ctx context.Context) (*Session, error)
ClearCurrent(ctx context.Context) error
// Lifecycle
Close() error
}
Store is the interface for session persistence.