Documentation
¶
Overview ¶
Package sessioncache provides a SQLite-backed cache for Claude sessions. It watches the sessions directory for changes and keeps the cache in sync.
Package sessioncache provides session caching and element parsing.
Package sessioncache provides message caching with SQLite for fast retrieval.
Package sessioncache provides session streaming for real-time updates.
Index ¶
- type AssistantTextContent
- type Cache
- func (c *Cache) DeleteAllSessions() (int, error)
- func (c *Cache) DeleteSession(sessionID string) error
- func (c *Cache) ForceSync() error
- func (c *Cache) GetSessionsDir() string
- func (c *Cache) ListSessions() ([]SessionInfo, error)
- func (c *Cache) ListSessionsPaginated(limit, offset int) ([]SessionInfo, int, error)
- func (c *Cache) Start() error
- func (c *Cache) Stats() map[string]interface{}
- func (c *Cache) Stop() error
- type CachedMessage
- type ContextCompactionContent
- type DiffContent
- type DiffHunk
- type DiffLine
- type DiffLineType
- type DiffSummary
- type Element
- type ElementType
- type ElementsPagination
- type ElementsResponse
- type ImageDimensions
- type ImageMetadata
- type InterruptedContent
- type MessageCache
- type MessagesPage
- type SessionInfo
- type SessionStreamer
- type ThinkingContent
- type ToolCallContent
- type ToolResultContent
- type ToolStatus
- type UserInputContent
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AssistantTextContent ¶
type AssistantTextContent struct {
Text string `json:"text"`
}
AssistantTextContent represents assistant text element content.
type Cache ¶
type Cache struct {
// contains filtered or unexported fields
}
Cache manages the SQLite session cache with file watching.
func (*Cache) DeleteAllSessions ¶
DeleteAllSessions deletes all sessions from the cache and disk.
func (*Cache) DeleteSession ¶
DeleteSession deletes a specific session from the cache and disk.
func (*Cache) GetSessionsDir ¶
GetSessionsDir exports the sessions directory path.
func (*Cache) ListSessions ¶
func (c *Cache) ListSessions() ([]SessionInfo, error)
ListSessions returns all cached sessions, sorted by last_updated desc.
func (*Cache) ListSessionsPaginated ¶
func (c *Cache) ListSessionsPaginated(limit, offset int) ([]SessionInfo, int, error)
ListSessionsPaginated returns sessions with pagination support.
type CachedMessage ¶
type CachedMessage struct {
ID int64 `json:"id"`
SessionID string `json:"session_id"`
Type string `json:"type"`
UUID string `json:"uuid,omitempty"`
Timestamp string `json:"timestamp,omitempty"`
GitBranch string `json:"git_branch,omitempty"`
Message json.RawMessage `json:"message"`
IsContextCompaction bool `json:"is_context_compaction,omitempty"`
IsMeta bool `json:"is_meta,omitempty"`
LineNum int `json:"-"` // Line number in source file
// ImageMetadata contains image info from toolUseResult.file (for Read tool on images)
ImageMetadata *ImageMetadata `json:"image_metadata,omitempty"`
}
CachedMessage represents a message stored in the cache.
type ContextCompactionContent ¶
type ContextCompactionContent struct {
Summary string `json:"summary"`
}
ContextCompactionContent represents a context compaction summary element.
type DiffContent ¶
type DiffContent struct {
ToolCallID string `json:"tool_call_id"`
FilePath string `json:"file_path"`
Summary DiffSummary `json:"summary"`
Hunks []DiffHunk `json:"hunks"`
}
DiffContent represents diff element content.
type DiffHunk ¶
type DiffHunk struct {
Header string `json:"header"`
OldStart int `json:"old_start"`
OldCount int `json:"old_count"`
NewStart int `json:"new_start"`
NewCount int `json:"new_count"`
Lines []DiffLine `json:"lines"`
}
DiffHunk represents a diff hunk.
type DiffLine ¶
type DiffLine struct {
Type DiffLineType `json:"type"`
OldLine *int `json:"old_line,omitempty"`
NewLine *int `json:"new_line,omitempty"`
Content string `json:"content"`
}
DiffLine represents a single line in a diff.
type DiffLineType ¶
type DiffLineType string
DiffLineType represents the type of diff line.
const ( DiffLineContext DiffLineType = "context" DiffLineAdded DiffLineType = "added" DiffLineRemoved DiffLineType = "removed" )
type DiffSummary ¶
type DiffSummary struct {
Added int `json:"added"`
Removed int `json:"removed"`
Display string `json:"display"`
}
DiffSummary represents a summary of diff changes.
type Element ¶
type Element struct {
ID string `json:"id" example:"elem_001"`
Type ElementType `json:"type" example:"assistant_text"`
Timestamp string `json:"timestamp" example:"2025-12-19T10:30:00Z"`
Content json.RawMessage `json:"content" swaggertype:"object"`
}
Element represents a UI element parsed from session data. @Description UI element with type-specific content
func ParseSessionToElements ¶
func ParseSessionToElements(messages []json.RawMessage, sessionID string) ([]Element, error)
ParseSessionToElements converts session messages to UI elements.
type ElementType ¶
type ElementType string
ElementType represents the type of UI element.
const ( ElementTypeUserInput ElementType = "user_input" ElementTypeAssistantText ElementType = "assistant_text" ElementTypeToolCall ElementType = "tool_call" ElementTypeToolResult ElementType = "tool_result" ElementTypeDiff ElementType = "diff" ElementTypeThinking ElementType = "thinking" ElementTypeContextCompaction ElementType = "context_compaction" ElementTypeInterrupted ElementType = "interrupted" )
type ElementsPagination ¶
type ElementsPagination struct {
Total int `json:"total"`
Returned int `json:"returned"`
HasMoreBefore bool `json:"has_more_before"`
HasMoreAfter bool `json:"has_more_after"`
OldestID string `json:"oldest_id,omitempty"`
NewestID string `json:"newest_id,omitempty"`
}
ElementsPagination represents pagination info for elements.
type ElementsResponse ¶
type ElementsResponse struct {
SessionID string `json:"session_id"`
Elements []Element `json:"elements"`
Pagination ElementsPagination `json:"pagination"`
}
ElementsResponse represents the response for elements API.
type ImageDimensions ¶
type ImageDimensions struct {
// OriginalWidth is the original image width in pixels
OriginalWidth int `json:"original_width"`
// OriginalHeight is the original image height in pixels
OriginalHeight int `json:"original_height"`
// DisplayWidth is the scaled width for display
DisplayWidth int `json:"display_width"`
// DisplayHeight is the scaled height for display
DisplayHeight int `json:"display_height"`
}
ImageDimensions contains width/height info for images.
type ImageMetadata ¶
type ImageMetadata struct {
// FilePath is the path to the file that was read
FilePath string `json:"file_path,omitempty"`
// Type is the MIME type (e.g., "image/jpeg")
Type string `json:"type"`
// OriginalSize is the file size in bytes
OriginalSize int64 `json:"original_size"`
// Dimensions contains the image dimensions
Dimensions *ImageDimensions `json:"dimensions,omitempty"`
}
ImageMetadata contains image information from Claude's toolUseResult.
type InterruptedContent ¶
type InterruptedContent struct {
ToolCallID string `json:"tool_call_id"`
Message string `json:"message"`
}
InterruptedContent represents interrupted element content.
type MessageCache ¶
type MessageCache struct {
// contains filtered or unexported fields
}
MessageCache provides SQLite-backed message caching with pagination.
func NewMessageCache ¶
func NewMessageCache(sessionsDir string) (*MessageCache, error)
NewMessageCache creates a new message cache.
func (*MessageCache) Close ¶
func (mc *MessageCache) Close() error
Close closes the database connection.
func (*MessageCache) GetMessages ¶
func (mc *MessageCache) GetMessages(sessionID string, limit, offset int, order string) (*MessagesPage, error)
GetMessages returns paginated messages for a session. Parameters:
- sessionID: the session to fetch
- limit: max messages to return (0 = all, default 50)
- offset: starting position
- order: "asc" (oldest first) or "desc" (newest first, default)
func (*MessageCache) GetStats ¶
func (mc *MessageCache) GetStats() map[string]interface{}
GetStats returns cache statistics.
func (*MessageCache) InvalidateSession ¶
func (mc *MessageCache) InvalidateSession(sessionID string) error
InvalidateSession removes a session from the cache.
type MessagesPage ¶
type MessagesPage struct {
Messages []CachedMessage `json:"messages"`
Total int `json:"total"`
Limit int `json:"limit"`
Offset int `json:"offset"`
HasMore bool `json:"has_more"`
CacheHit bool `json:"cache_hit"`
QueryTimeMS float64 `json:"query_time_ms"`
}
MessagesPage represents a paginated response.
type SessionInfo ¶
type SessionInfo struct {
SessionID string `json:"session_id"`
Summary string `json:"summary"`
MessageCount int `json:"message_count"`
LastUpdated time.Time `json:"last_updated"`
Branch string `json:"branch,omitempty"`
}
SessionInfo represents cached session information.
type SessionStreamer ¶
type SessionStreamer struct {
// contains filtered or unexported fields
}
SessionStreamer watches a specific session file and streams new messages.
func NewSessionStreamer ¶
func NewSessionStreamer(sessionsDir string, hub ports.EventHub) *SessionStreamer
NewSessionStreamer creates a new session streamer.
func (*SessionStreamer) Close ¶
func (s *SessionStreamer) Close()
Close stops the streamer and releases resources.
func (*SessionStreamer) GetWatchedSession ¶
func (s *SessionStreamer) GetWatchedSession() string
GetWatchedSession returns the currently watched session ID.
func (*SessionStreamer) UnwatchSession ¶
func (s *SessionStreamer) UnwatchSession()
UnwatchSession stops watching the current session.
func (*SessionStreamer) WatchSession ¶
func (s *SessionStreamer) WatchSession(sessionID string) error
WatchSession starts watching a specific session for new messages. Call this when iOS selects a session to view.
type ThinkingContent ¶
ThinkingContent represents thinking element content.
type ToolCallContent ¶
type ToolCallContent struct {
Tool string `json:"tool"`
ToolID string `json:"tool_id,omitempty"`
Display string `json:"display"`
Params map[string]interface{} `json:"params"`
Status ToolStatus `json:"status"`
DurationMS int64 `json:"duration_ms,omitempty"`
}
ToolCallContent represents tool call element content.
type ToolResultContent ¶
type ToolResultContent struct {
ToolCallID string `json:"tool_call_id"`
ToolName string `json:"tool_name"`
IsError bool `json:"is_error"`
ErrorCode int `json:"error_code,omitempty"`
Summary string `json:"summary"`
FullContent string `json:"full_content"`
LineCount int `json:"line_count"`
Expandable bool `json:"expandable"`
Truncated bool `json:"truncated,omitempty"`
}
ToolResultContent represents tool result element content.
type ToolStatus ¶
type ToolStatus string
ToolStatus represents the status of a tool call.
const ( ToolStatusRunning ToolStatus = "running" ToolStatusCompleted ToolStatus = "completed" ToolStatusError ToolStatus = "error" ToolStatusInterrupted ToolStatus = "interrupted" )
type UserInputContent ¶
type UserInputContent struct {
Text string `json:"text"`
}
UserInputContent represents user input element content.