Documentation
¶
Index ¶
- Constants
- func ApplyMigrations(db *sql.DB) error
- func DeleteSession(path string, sessionDir string) error
- func GenerateID() string
- type BranchSummaryEntry
- type CompactionEntry
- type EntryBase
- type EntryType
- type Header
- type LabelEntry
- type Manager
- func ContinueRecent(cwd, sessionDir string) (*Manager, error)
- func New(cwd, sessionDir string) *Manager
- func Open(path string) (*Manager, error)
- func OpenByID(cwd, sessionDir, sessionID string) (*Manager, error)
- func OpenByIDExact(sessionDir, sessionID string) (*Manager, error)
- func OpenByPathOrID(cwd, sessionDir, value string) (*Manager, error)
- func (m *Manager) AppendCompaction(summary, firstKeptEntryID string, tokensBefore int) (string, error)
- func (m *Manager) AppendMessage(msg provider.Message) (string, error)
- func (m *Manager) AppendModelChange(providerName, modelID string) (string, error)
- func (m *Manager) AppendSessionInfo(name string) (string, error)
- func (m *Manager) AppendThinkingLevelChange(level string) (string, error)
- func (m *Manager) GetFile() string
- func (m *Manager) GetHeader() *Header
- func (m *Manager) GetLatestCompaction() (CompactionEntry, bool)
- func (m *Manager) GetLeafID() *string
- func (m *Manager) GetMessages() []provider.Message
- func (m *Manager) GetReplayState() ReplayState
- func (m *Manager) Init() error
- func (m *Manager) InitWithID(id string) error
- func (m *Manager) RecordUsage(provider, protocol, model string, ...) error
- func (m *Manager) RecordUsageFromProviderUsage(provider, protocol, model string, usage *provider.Usage, durationMs int) error
- type MemoryStore
- func (m *MemoryStore) AppendCompaction(summary, firstKeptEntryID string, tokensBefore int) (string, error)
- func (m *MemoryStore) AppendMessage(msg provider.Message) (string, error)
- func (m *MemoryStore) AppendModelChange(providerName, modelID string) (string, error)
- func (m *MemoryStore) AppendSessionInfo(name string) (string, error)
- func (m *MemoryStore) AppendThinkingLevelChange(level string) (string, error)
- func (m *MemoryStore) GetFile() string
- func (m *MemoryStore) GetHeader() *Header
- func (m *MemoryStore) GetLatestCompaction() (CompactionEntry, bool)
- func (m *MemoryStore) GetLeafID() *string
- func (m *MemoryStore) GetMessages() []provider.Message
- func (m *MemoryStore) GetReplayState() ReplayState
- func (m *MemoryStore) Init() error
- func (m *MemoryStore) InitWithID(id string) error
- type MessageEntry
- type ModelChangeEntry
- type ReplayState
- type SessionDetail
- type SessionInfo
- type SessionInfoEntry
- type Store
- type ThinkingLevelChangeEntry
Constants ¶
const CurrentVersion = 3
Variables ¶
This section is empty.
Functions ¶
func ApplyMigrations ¶
ApplyMigrations runs any pending migrations in order. Already-applied migrations are skipped based on the schema_migrations table. It is safe to call on every DB open — it is a no-op if all migrations are applied.
func DeleteSession ¶
DeleteSession deletes a session file if it is under sessionDir.
Types ¶
type BranchSummaryEntry ¶
type BranchSummaryEntry struct {
EntryBase
Summary string `json:"summary"`
FromID string `json:"fromId"`
}
BranchSummaryEntry records a branch switch summary.
type CompactionEntry ¶
type CompactionEntry struct {
EntryBase
Summary string `json:"summary"`
FirstKeptEntry string `json:"firstKeptEntryId"`
TokensBefore int `json:"tokensBefore"`
SummaryVersion int `json:"summaryVersion,omitempty"`
PreviousCompactionID string `json:"previousCompactionId,omitempty"`
LastSummarizedEntry string `json:"lastSummarizedEntryId,omitempty"`
}
CompactionEntry records a context compaction.
type EntryBase ¶
type EntryBase struct {
Type EntryType `json:"type"`
ID string `json:"id"`
ParentID *string `json:"parentId"`
Timestamp time.Time `json:"timestamp"`
}
EntryBase contains common fields for all session entries.
type EntryType ¶
type EntryType string
EntryType identifies the type of a session entry.
const ( EntrySession EntryType = "session" EntryMessage EntryType = "message" EntryModelChange EntryType = "model_change" EntryThinkingChange EntryType = "thinking_level_change" EntryCompaction EntryType = "compaction" EntryBranchSummary EntryType = "branch_summary" EntryCustom EntryType = "custom" EntryCustomMessage EntryType = "custom_message" EntryLabel EntryType = "label" EntrySessionInfo EntryType = "session_info" )
type Header ¶
type Header struct {
Type EntryType `json:"type"`
Version int `json:"version"`
ID string `json:"id"`
Timestamp time.Time `json:"timestamp"`
Cwd string `json:"cwd"`
ParentSession string `json:"parentSession,omitempty"`
}
Header is the first line of a session file.
type LabelEntry ¶
type LabelEntry struct {
EntryBase
TargetID string `json:"targetId"`
Label *string `json:"label,omitempty"`
}
LabelEntry records a user-defined label on an entry.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager manages a single session's state and persistence.
func ContinueRecent ¶
ContinueRecent continues the most recent session for a directory, or creates new.
func OpenByID ¶
OpenByID opens the session for cwd whose session ID matches sessionID. Supports prefix matching — if sessionID matches multiple sessions, an error is returned.
func OpenByIDExact ¶
OpenByIDExact opens a session by exact session ID regardless of cwd.
func OpenByPathOrID ¶
OpenByPathOrID opens a session using either an explicit file path or a session ID for the supplied working directory.
func (*Manager) AppendCompaction ¶
func (m *Manager) AppendCompaction(summary, firstKeptEntryID string, tokensBefore int) (string, error)
AppendCompaction records a context compaction.
func (*Manager) AppendMessage ¶
AppendMessage adds a message entry.
func (*Manager) AppendModelChange ¶
AppendModelChange records a model change.
func (*Manager) AppendSessionInfo ¶
AppendSessionInfo records session metadata (e.g. display name).
func (*Manager) AppendThinkingLevelChange ¶
AppendThinkingLevelChange records a thinking level change.
func (*Manager) GetLatestCompaction ¶
func (m *Manager) GetLatestCompaction() (CompactionEntry, bool)
GetLatestCompaction returns the newest compaction entry in the current session.
func (*Manager) GetMessages ¶
GetMessages extracts all messages from the current branch.
func (*Manager) GetReplayState ¶
func (m *Manager) GetReplayState() ReplayState
GetReplayState returns the current branch after applying compaction entries.
func (*Manager) Init ¶
Init initializes a new session with an auto-generated session ID. Must be called before appending entries.
func (*Manager) InitWithID ¶
InitWithID initializes a new session using the provided session ID. If id is empty, a new random ID is generated.
type MemoryStore ¶
type MemoryStore struct {
// contains filtered or unexported fields
}
MemoryStore is an in-memory implementation of Store for testing. It does not persist data to disk.
func NewMemoryStore ¶
func NewMemoryStore() *MemoryStore
NewMemoryStore creates a new in-memory session store.
func (*MemoryStore) AppendCompaction ¶
func (m *MemoryStore) AppendCompaction(summary, firstKeptEntryID string, tokensBefore int) (string, error)
func (*MemoryStore) AppendMessage ¶
func (m *MemoryStore) AppendMessage(msg provider.Message) (string, error)
func (*MemoryStore) AppendModelChange ¶
func (m *MemoryStore) AppendModelChange(providerName, modelID string) (string, error)
func (*MemoryStore) AppendSessionInfo ¶
func (m *MemoryStore) AppendSessionInfo(name string) (string, error)
func (*MemoryStore) AppendThinkingLevelChange ¶
func (m *MemoryStore) AppendThinkingLevelChange(level string) (string, error)
func (*MemoryStore) GetFile ¶
func (m *MemoryStore) GetFile() string
func (*MemoryStore) GetHeader ¶
func (m *MemoryStore) GetHeader() *Header
func (*MemoryStore) GetLatestCompaction ¶
func (m *MemoryStore) GetLatestCompaction() (CompactionEntry, bool)
func (*MemoryStore) GetLeafID ¶
func (m *MemoryStore) GetLeafID() *string
func (*MemoryStore) GetMessages ¶
func (m *MemoryStore) GetMessages() []provider.Message
func (*MemoryStore) GetReplayState ¶
func (m *MemoryStore) GetReplayState() ReplayState
func (*MemoryStore) Init ¶
func (m *MemoryStore) Init() error
func (*MemoryStore) InitWithID ¶
func (m *MemoryStore) InitWithID(id string) error
type MessageEntry ¶
MessageEntry contains a conversation message.
type ModelChangeEntry ¶
type ModelChangeEntry struct {
EntryBase
Provider string `json:"provider"`
ModelID string `json:"modelId"`
}
ModelChangeEntry records a model switch.
type ReplayState ¶
ReplayState is the reconstructed conversation state after applying compactions.
type SessionDetail ¶
type SessionDetail struct {
SessionInfo
ID string
MessageCount int
Preview string // first user message (truncated)
}
SessionDetail contains detailed metadata about a session for display.
func ListForDirDetailed ¶
func ListForDirDetailed(cwd, sessionDir string) ([]SessionDetail, error)
ListForDirDetailed lists sessions with details (ID, message count, preview).
type SessionInfo ¶
SessionInfo contains metadata about a session file.
func ListForDir ¶
func ListForDir(cwd, sessionDir string) ([]SessionInfo, error)
ListForDir lists session files for a given working directory.
type SessionInfoEntry ¶
SessionInfoEntry stores session metadata.
type Store ¶
type Store interface {
// Init initializes the session store, creating the underlying
// database or storage if needed.
Init() error
// InitWithID initializes the session with a specific ID.
// An empty id generates a new one.
InitWithID(id string) error
// AppendMessage persists a conversation message and returns its entry ID.
AppendMessage(msg provider.Message) (string, error)
// AppendCompaction records a context compaction event.
AppendCompaction(summary, firstKeptEntryID string, tokensBefore int) (string, error)
// AppendModelChange records a model switch.
AppendModelChange(providerName, modelID string) (string, error)
// AppendThinkingLevelChange records a thinking level change.
AppendThinkingLevelChange(level string) (string, error)
// AppendSessionInfo records session metadata.
AppendSessionInfo(name string) (string, error)
// GetMessages returns all messages in the current branch,
// with compaction summaries applied.
GetMessages() []provider.Message
// GetReplayState returns the full replay state including
// messages and their entry IDs.
GetReplayState() ReplayState
// GetLeafID returns the current leaf entry ID, or nil if empty.
GetLeafID() *string
// GetLatestCompaction returns the most recent compaction entry,
// or (zero, false) if none exists.
GetLatestCompaction() (CompactionEntry, bool)
// GetFile returns the session file path (handle file for SQLite).
GetFile() string
// GetHeader returns the session header with metadata.
GetHeader() *Header
}
Store is the interface for session persistence backends. Manager implements this interface using SQLite. Alternative backends (in-memory for testing, cloud storage, etc.) can implement Store to swap the persistence layer without changing agent or UI code.
type ThinkingLevelChangeEntry ¶
ThinkingLevelChangeEntry records a thinking level change.