Help us shape the future of Go! Take the 2026 Go Developer Survey

session

package
v1.233.1 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2026 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Overview

Package session is a generated GoMock package.

Index

Constants

View Source
const (
	// DefaultMaxSessions is the default maximum number of sessions to keep.
	DefaultMaxSessions = 40
	// DefaultRetentionDays is the default number of days to retain sessions.
	DefaultRetentionDays = 30
	// RetentionUnset signals that the caller did not explicitly request a
	// retention period, so CleanOldSessions falls back to DefaultRetentionDays.
	// This is distinct from an explicit retentionDays of 0, which now means
	// "delete all sessions immediately" (no positive retention window) —
	// a plain int can't otherwise tell "unset" and "explicitly zero" apart.
	RetentionUnset = -1
)
View Source
const (
	RoleUser      = "user"
	RoleAssistant = "assistant"
	RoleSystem    = "system"
)

Role constants for messages.

View Source
const (
	ContextTypeStackFile = "stack_file"
	ContextTypeComponent = "component"
	ContextTypeSetting   = "setting"
	ContextTypeQuery     = "query"
	ContextTypeATMOSMD   = "atmos_md"
)

ContextType constants.

View Source
const (
	// CheckpointVersion is the current checkpoint format version.
	CheckpointVersion = "1.0"
)

Variables

This section is empty.

Functions

func ValidateCheckpointFile

func ValidateCheckpointFile(path string) error

ValidateCheckpointFile validates a checkpoint file without importing. Useful for pre-import validation or CLI dry-run.

Types

type Checkpoint

type Checkpoint struct {
	// Version is the checkpoint format version for compatibility.
	Version string `json:"version" yaml:"version"`

	// ExportedAt is when the checkpoint was created.
	ExportedAt time.Time `json:"exported_at" yaml:"exported_at"`

	// ExportedBy is the user who exported the checkpoint (optional).
	ExportedBy string `json:"exported_by,omitempty" yaml:"exported_by,omitempty"`

	// Session contains session metadata.
	Session CheckpointSession `json:"session" yaml:"session"`

	// Messages contains the complete conversation history.
	Messages []CheckpointMessage `json:"messages" yaml:"messages"`

	// Context contains project-specific context.
	Context *CheckpointContext `json:"context,omitempty" yaml:"context,omitempty"`

	// Statistics contains session statistics.
	Statistics CheckpointStatistics `json:"statistics" yaml:"statistics"`
}

Checkpoint represents an exportable session snapshot. It contains all information needed to restore a session.

type CheckpointContext

type CheckpointContext struct {
	// ProjectInstructions is the ATMOS.md content at export time (optional).
	ProjectInstructions string `json:"project_instructions,omitempty" yaml:"project_instructions,omitempty"`

	// FilesAccessed is a list of files accessed during the session (optional).
	FilesAccessed []string `json:"files_accessed,omitempty" yaml:"files_accessed,omitempty"`

	// WorkingDirectory is the working directory at export time (optional).
	WorkingDirectory string `json:"working_directory,omitempty" yaml:"working_directory,omitempty"`
}

CheckpointContext contains project-specific context.

type CheckpointMessage

type CheckpointMessage struct {
	// Role is the message role (user, assistant, system).
	Role string `json:"role" yaml:"role"`

	// Content is the message content.
	Content string `json:"content" yaml:"content"`

	// CreatedAt is when the message was created.
	CreatedAt time.Time `json:"created_at" yaml:"created_at"`

	// Archived indicates if the message was compacted.
	Archived bool `json:"archived,omitempty" yaml:"archived,omitempty"`
}

CheckpointMessage represents a message in the checkpoint.

type CheckpointSession

type CheckpointSession struct {
	// Name is the session name.
	Name string `json:"name" yaml:"name"`

	// Provider is the AI provider (anthropic, openai, etc.).
	Provider string `json:"provider" yaml:"provider"`

	// Model is the AI model used.
	Model string `json:"model" yaml:"model"`

	// Skill is the AI skill name (optional).
	Skill string `json:"skill,omitempty" yaml:"skill,omitempty"`

	// ProjectPath is the project path where session was created.
	ProjectPath string `json:"project_path" yaml:"project_path"`

	// CreatedAt is when the session was created.
	CreatedAt time.Time `json:"created_at" yaml:"created_at"`

	// UpdatedAt is when the session was last updated.
	UpdatedAt time.Time `json:"updated_at" yaml:"updated_at"`

	// Metadata contains custom metadata.
	Metadata map[string]interface{} `json:"metadata,omitempty" yaml:"metadata,omitempty"`
}

CheckpointSession contains session metadata for export.

type CheckpointStatistics

type CheckpointStatistics struct {
	// MessageCount is the total number of messages.
	MessageCount int `json:"message_count" yaml:"message_count"`

	// UserMessages is the number of user messages.
	UserMessages int `json:"user_messages" yaml:"user_messages"`

	// AssistantMessages is the number of assistant messages.
	AssistantMessages int `json:"assistant_messages" yaml:"assistant_messages"`

	// TotalTokens is the total token count (if tracked).
	TotalTokens int64 `json:"total_tokens,omitempty" yaml:"total_tokens,omitempty"`

	// ToolCalls is the number of tool executions (if tracked).
	ToolCalls int `json:"tool_calls,omitempty" yaml:"tool_calls,omitempty"`
}

CheckpointStatistics contains session statistics.

type CompactConfig

type CompactConfig struct {
	Enabled            bool    `json:"enabled" yaml:"enabled"`
	TriggerThreshold   float64 `json:"trigger_threshold" yaml:"trigger_threshold"`       // 0.0-1.0, default 0.75
	CompactRatio       float64 `json:"compact_ratio" yaml:"compact_ratio"`               // 0.0-1.0, default 0.4
	PreserveRecent     int     `json:"preserve_recent" yaml:"preserve_recent"`           // Default 10
	UseAISummary       bool    `json:"use_ai_summary" yaml:"use_ai_summary"`             // Default true
	ShowSummaryMarkers bool    `json:"show_summary_markers" yaml:"show_summary_markers"` // Default false
}

CompactConfig holds configuration for auto-compact behavior.

func DefaultCompactConfig

func DefaultCompactConfig() CompactConfig

DefaultCompactConfig returns the default compaction configuration.

type CompactPlan

type CompactPlan struct {
	SessionID         string
	TotalMessages     int
	MessagesToCompact []*Message
	MessagesToKeep    []*Message
	EstimatedSavings  int // Token savings estimate
	Reason            string
}

CompactPlan describes what will be compacted.

type CompactResult

type CompactResult struct {
	SummaryID          string
	OriginalMessageIDs []int64
	SummaryContent     string
	TokenCount         int
	CompactedAt        time.Time
	Success            bool
	Error              error
}

CompactResult contains the outcome of compaction.

type CompactStatus

type CompactStatus struct {
	Stage            string // "starting", "summarizing", "completed", "failed"
	MessageCount     int    // Number of messages being compacted
	EstimatedSavings int    // Estimated token savings
	Error            error  // Error if failed
}

CompactStatus represents the status of a compaction operation.

type CompactStatusCallback

type CompactStatusCallback func(status CompactStatus)

CompactStatusCallback is called when compaction status changes. This allows UI components to show compaction progress.

type Compactor

type Compactor interface {
	// ShouldCompact determines if compaction is needed based on current history.
	ShouldCompact(messages []*Message, maxMessages int, config *CompactConfig) (bool, *CompactPlan)

	// Compact performs the compaction operation.
	Compact(ctx context.Context, plan *CompactPlan, config *CompactConfig) (*CompactResult, error)
}

Compactor handles intelligent conversation history compaction.

func NewCompactor

func NewCompactor(storage Storage, atmosConfig *schema.AtmosConfiguration) Compactor

NewCompactor creates a new compactor instance.

type ContextItem

type ContextItem struct {
	SessionID    string `json:"session_id"`
	ContextType  string `json:"context_type"`  // stack_file, component, setting
	ContextKey   string `json:"context_key"`   // e.g., "vpc", "prod-use1"
	ContextValue string `json:"context_value"` // JSON or text value
}

ContextItem represents a piece of context associated with a session.

type CreateSessionParams

type CreateSessionParams struct {
	Name     string
	Model    string
	Provider string
	Skill    string
	Metadata map[string]interface{}
}

CreateSessionParams holds parameters for creating a new session.

type DefaultCompactor

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

DefaultCompactor implements Compactor with AI-powered summarization.

func (*DefaultCompactor) Compact

func (c *DefaultCompactor) Compact(ctx context.Context, plan *CompactPlan, config *CompactConfig) (*CompactResult, error)

Compact performs the compaction operation with AI-powered summarization.

func (*DefaultCompactor) ShouldCompact

func (c *DefaultCompactor) ShouldCompact(messages []*Message, maxMessages int, config *CompactConfig) (bool, *CompactPlan)

ShouldCompact determines if compaction is needed.

type ExportOptions

type ExportOptions struct {
	// IncludeContext includes project instructions and file access history.
	IncludeContext bool

	// IncludeMetadata includes session metadata.
	IncludeMetadata bool

	// Format is the export format (json, yaml, markdown).
	Format string
}

ExportOptions contains options for exporting a checkpoint.

type ImportOptions

type ImportOptions struct {
	// Name is the name for the imported session.
	// If empty, uses the checkpoint's session name.
	Name string

	// ProjectPath is the project path for the imported session.
	// If empty, uses the current project path.
	ProjectPath string

	// OverwriteExisting allows overwriting an existing session with the same name.
	OverwriteExisting bool

	// IncludeContext includes project context in the import.
	IncludeContext bool
}

ImportOptions contains options for importing a checkpoint.

type Manager

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

Manager handles session lifecycle and operations.

func NewManager

func NewManager(storage Storage, projectPath string, maxSessions int, atmosConfig *schema.AtmosConfiguration) *Manager

NewManager creates a new session manager.

func (*Manager) AddContext

func (m *Manager) AddContext(ctx context.Context, sessionID, contextType, key, value string) error

AddContext adds a context item to a session.

func (*Manager) AddMessage

func (m *Manager) AddMessage(ctx context.Context, sessionID, role, content string) error

AddMessage adds a message to a session.

func (*Manager) CleanOldSessions

func (m *Manager) CleanOldSessions(ctx context.Context, retentionDays int) (int, error)

CleanOldSessions removes sessions older than the specified duration. A negative retentionDays (see RetentionUnset) means "not specified" and falls back to DefaultRetentionDays. A retentionDays value of 0 is honored literally: the cutoff is "now", so every existing session is deleted.

func (*Manager) Close

func (m *Manager) Close() error

Close closes the storage backend.

func (*Manager) CreateSession

func (m *Manager) CreateSession(ctx context.Context, params CreateSessionParams) (*Session, error)

CreateSession creates a new session.

func (*Manager) DeleteSession

func (m *Manager) DeleteSession(ctx context.Context, id string) error

DeleteSession deletes a session and all its data.

func (*Manager) ExportSession

func (m *Manager) ExportSession(ctx context.Context, sessionID string, outputPath string, opts ExportOptions) error

ExportSession exports a session to a checkpoint file.

func (*Manager) ExportSessionByName

func (m *Manager) ExportSessionByName(ctx context.Context, sessionName string, outputPath string, opts ExportOptions) error

ExportSessionByName exports a session by name.

func (*Manager) GetContext

func (m *Manager) GetContext(ctx context.Context, sessionID string) ([]*ContextItem, error)

GetContext retrieves all context items for a session.

func (*Manager) GetMessageCount

func (m *Manager) GetMessageCount(ctx context.Context, sessionID string) (int, error)

GetMessageCount returns the number of messages in a session.

func (*Manager) GetMessages

func (m *Manager) GetMessages(ctx context.Context, sessionID string, limit int) ([]*Message, error)

GetMessages retrieves messages for a session.

func (*Manager) GetMessagesWithCompaction

func (m *Manager) GetMessagesWithCompaction(ctx context.Context, sessionID string, limit int) ([]*Message, error)

GetMessagesWithCompaction retrieves messages for a session with auto-compact support.

func (*Manager) GetSession

func (m *Manager) GetSession(ctx context.Context, id string) (*Session, error)

GetSession retrieves a session by ID.

func (*Manager) GetSessionByName

func (m *Manager) GetSessionByName(ctx context.Context, name string) (*Session, error)

GetSessionByName retrieves a session by name within the current project.

func (*Manager) ImportSession

func (m *Manager) ImportSession(ctx context.Context, checkpointPath string, opts ImportOptions) (*Session, error)

ImportSession imports a session from a checkpoint file.

func (*Manager) ListSessions

func (m *Manager) ListSessions(ctx context.Context) ([]*Session, error)

ListSessions returns all sessions for the current project.

func (*Manager) SetCompactStatusCallback

func (m *Manager) SetCompactStatusCallback(callback CompactStatusCallback)

SetCompactStatusCallback sets the callback for compaction status updates. This allows UI components to be notified when compaction starts/completes.

func (*Manager) UpdateSession

func (m *Manager) UpdateSession(ctx context.Context, sess *Session) error

UpdateSession updates an existing session.

type Message

type Message struct {
	ID        int64     `json:"id"`
	SessionID string    `json:"session_id"`
	Role      string    `json:"role"` // user, assistant, system
	Content   string    `json:"content"`
	CreatedAt time.Time `json:"created_at"`
	Archived  bool      `json:"archived"`   // True if message has been compacted into a summary
	IsSummary bool      `json:"is_summary"` // True if this is a summary message (for display purposes)
}

Message represents a single message in a session.

type MockCompactor added in v1.223.0

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

MockCompactor is a mock of Compactor interface.

func NewMockCompactor added in v1.223.0

func NewMockCompactor(ctrl *gomock.Controller) *MockCompactor

NewMockCompactor creates a new mock instance.

func (*MockCompactor) Compact added in v1.223.0

func (m *MockCompactor) Compact(ctx context.Context, plan *CompactPlan, config *CompactConfig) (*CompactResult, error)

Compact mocks base method.

func (*MockCompactor) EXPECT added in v1.223.0

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockCompactor) ShouldCompact added in v1.223.0

func (m *MockCompactor) ShouldCompact(messages []*Message, maxMessages int, config *CompactConfig) (bool, *CompactPlan)

ShouldCompact mocks base method.

type MockCompactorMockRecorder added in v1.223.0

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

MockCompactorMockRecorder is the mock recorder for MockCompactor.

func (*MockCompactorMockRecorder) Compact added in v1.223.0

func (mr *MockCompactorMockRecorder) Compact(ctx, plan, config any) *gomock.Call

Compact indicates an expected call of Compact.

func (*MockCompactorMockRecorder) ShouldCompact added in v1.223.0

func (mr *MockCompactorMockRecorder) ShouldCompact(messages, maxMessages, config any) *gomock.Call

ShouldCompact indicates an expected call of ShouldCompact.

type SQLiteStorage

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

SQLiteStorage implements Storage using SQLite.

func NewSQLiteStorage

func NewSQLiteStorage(storagePath string) (*SQLiteStorage, error)

NewSQLiteStorage creates a new SQLite storage backend.

func (*SQLiteStorage) AddContext

func (s *SQLiteStorage) AddContext(ctx context.Context, item *ContextItem) error

AddContext adds a context item to a session.

func (*SQLiteStorage) AddMessage

func (s *SQLiteStorage) AddMessage(ctx context.Context, message *Message) error

AddMessage adds a message to a session.

func (*SQLiteStorage) ArchiveMessages

func (s *SQLiteStorage) ArchiveMessages(ctx context.Context, messageIDs []int64) error

ArchiveMessages marks messages as archived.

func (*SQLiteStorage) Close

func (s *SQLiteStorage) Close() error

Close closes the database connection.

func (*SQLiteStorage) CreateSession

func (s *SQLiteStorage) CreateSession(ctx context.Context, session *Session) error

CreateSession creates a new session.

func (*SQLiteStorage) DeleteContext

func (s *SQLiteStorage) DeleteContext(ctx context.Context, sessionID string) error

DeleteContext deletes all context items for a session.

func (*SQLiteStorage) DeleteOldSessions

func (s *SQLiteStorage) DeleteOldSessions(ctx context.Context, olderThan time.Time) (int, error)

DeleteOldSessions deletes sessions older than the specified time.

func (*SQLiteStorage) DeleteSession

func (s *SQLiteStorage) DeleteSession(ctx context.Context, id string) error

DeleteSession deletes a session.

func (*SQLiteStorage) GetActiveMessages

func (s *SQLiteStorage) GetActiveMessages(ctx context.Context, sessionID string, limit int) ([]*Message, error)

GetActiveMessages retrieves non-archived messages for a session.

func (*SQLiteStorage) GetContext

func (s *SQLiteStorage) GetContext(ctx context.Context, sessionID string) ([]*ContextItem, error)

GetContext retrieves all context items for a session.

func (*SQLiteStorage) GetMessageCount

func (s *SQLiteStorage) GetMessageCount(ctx context.Context, sessionID string) (int, error)

GetMessageCount returns the number of messages in a session.

func (*SQLiteStorage) GetMessages

func (s *SQLiteStorage) GetMessages(ctx context.Context, sessionID string, limit int) ([]*Message, error)

GetMessages retrieves messages for a session.

func (*SQLiteStorage) GetSession

func (s *SQLiteStorage) GetSession(ctx context.Context, id string) (*Session, error)

GetSession retrieves a session by ID.

func (*SQLiteStorage) GetSessionByName

func (s *SQLiteStorage) GetSessionByName(ctx context.Context, projectPath, name string) (*Session, error)

GetSessionByName retrieves a session by name and project path.

func (*SQLiteStorage) GetSummaries

func (s *SQLiteStorage) GetSummaries(ctx context.Context, sessionID string) ([]*Summary, error)

GetSummaries retrieves all summaries for a session.

func (*SQLiteStorage) ListSessions

func (s *SQLiteStorage) ListSessions(ctx context.Context, projectPath string, limit int) ([]*Session, error)

ListSessions returns all sessions for a project.

func (*SQLiteStorage) Migrate

func (s *SQLiteStorage) Migrate() error

Migrate creates or updates the database schema.

func (*SQLiteStorage) StoreSummary

func (s *SQLiteStorage) StoreSummary(ctx context.Context, summary *Summary) error

StoreSummary stores a message summary.

func (*SQLiteStorage) UpdateSession

func (s *SQLiteStorage) UpdateSession(ctx context.Context, session *Session) error

UpdateSession updates an existing session.

type Session

type Session struct {
	ID           string                 `json:"id"`
	Name         string                 `json:"name"`
	ProjectPath  string                 `json:"project_path"`
	Model        string                 `json:"model"`
	Provider     string                 `json:"provider"`
	Skill        string                 `json:"skill,omitempty"` // AI skill name (e.g., "general", "stack-analyzer")
	CreatedAt    time.Time              `json:"created_at"`
	UpdatedAt    time.Time              `json:"updated_at"`
	Metadata     map[string]interface{} `json:"metadata,omitempty"`
	MessageCount int                    `json:"message_count,omitempty"`
}

Session represents an AI chat session with persistent state.

type Storage

type Storage interface {
	// Session operations
	CreateSession(ctx context.Context, session *Session) error
	GetSession(ctx context.Context, id string) (*Session, error)
	GetSessionByName(ctx context.Context, projectPath, name string) (*Session, error)
	ListSessions(ctx context.Context, projectPath string, limit int) ([]*Session, error)
	UpdateSession(ctx context.Context, session *Session) error
	DeleteSession(ctx context.Context, id string) error
	DeleteOldSessions(ctx context.Context, olderThan time.Time) (int, error)

	// Message operations
	AddMessage(ctx context.Context, message *Message) error
	GetMessages(ctx context.Context, sessionID string, limit int) ([]*Message, error)
	GetMessageCount(ctx context.Context, sessionID string) (int, error)

	// Context operations
	AddContext(ctx context.Context, item *ContextItem) error
	GetContext(ctx context.Context, sessionID string) ([]*ContextItem, error)
	DeleteContext(ctx context.Context, sessionID string) error

	// Summary operations (auto-compact)
	StoreSummary(ctx context.Context, summary *Summary) error
	GetSummaries(ctx context.Context, sessionID string) ([]*Summary, error)
	ArchiveMessages(ctx context.Context, messageIDs []int64) error
	GetActiveMessages(ctx context.Context, sessionID string, limit int) ([]*Message, error)

	// Database management
	Close() error
	Migrate() error
}

Storage defines the interface for session persistence.

type Summary

type Summary struct {
	ID                 string    `json:"id"`
	SessionID          string    `json:"session_id"`
	Provider           string    `json:"provider"`
	OriginalMessageIDs []int64   `json:"original_message_ids"`
	MessageRange       string    `json:"message_range"` // Human-readable: "Messages 1-20"
	SummaryContent     string    `json:"summary_content"`
	TokenCount         int       `json:"token_count"`
	CompactedAt        time.Time `json:"compacted_at"`
}

Summary represents a compacted summary of multiple messages.

Jump to

Keyboard shortcuts

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