Documentation
¶
Overview ¶
Package conversation provides persistent storage for Claude conversations
Package conversation provides persistent storage for Claude conversations
Index ¶
- Variables
- type BuildContextOptions
- type CompressionType
- type Compressor
- type NoopCompressor
- type PruneOptions
- type Reader
- type SQLiteStore
- func (s *SQLiteStore) AppendTurn(ctx context.Context, turn *types.ConversationTurn) error
- func (s *SQLiteStore) ArchiveConversation(ctx context.Context, conversationID string) error
- func (s *SQLiteStore) BuildContext(ctx context.Context, taskID string, options *BuildContextOptions) (*types.ConversationContext, error)
- func (s *SQLiteStore) CreateConversation(ctx context.Context, taskID, worktree string) (*types.Conversation, error)
- func (s *SQLiteStore) DeleteConversation(ctx context.Context, conversationID string) error
- func (s *SQLiteStore) GetConversation(ctx context.Context, conversationID string) (*types.Conversation, error)
- func (s *SQLiteStore) GetConversationByTask(ctx context.Context, taskID string) (*types.Conversation, error)
- func (s *SQLiteStore) GetRecentTurns(ctx context.Context, conversationID string, limit int) ([]*types.ConversationTurn, error)
- func (s *SQLiteStore) GetStats(ctx context.Context, conversationID string) (*types.ConversationStats, error)
- func (s *SQLiteStore) GetTurn(ctx context.Context, turnID string) (*types.ConversationTurn, error)
- func (s *SQLiteStore) GetTurnsByRange(ctx context.Context, conversationID string, start, end int) ([]*types.ConversationTurn, error)
- func (s *SQLiteStore) GetTurnsByTokenBudget(ctx context.Context, conversationID string, maxTokens int) ([]*types.ConversationTurn, error)
- func (s *SQLiteStore) PruneConversation(ctx context.Context, conversationID string, options *PruneOptions) (int, error)
- func (s *SQLiteStore) ResumeConversation(ctx context.Context, taskID string) (*types.ConversationContext, error)
- func (s *SQLiteStore) SearchTurns(ctx context.Context, query string, limit int) ([]*types.ConversationSearchResult, error)
- func (s *SQLiteStore) SearchTurnsInConversation(ctx context.Context, conversationID, query string, limit int) ([]*types.ConversationSearchResult, error)
- func (s *SQLiteStore) SetCompressor(c Compressor)
- func (s *SQLiteStore) SetTokenCounter(c TokenCounter)
- func (s *SQLiteStore) UpdateConversationStatus(ctx context.Context, conversationID string, status types.ConversationStatus) error
- type SimpleTokenCounter
- type Store
- type TokenCounter
- type Writer
Constants ¶
This section is empty.
Variables ¶
var ( ErrConversationNotFound = fmt.Errorf("conversation not found") ErrTurnNotFound = fmt.Errorf("turn not found") )
Errors
Functions ¶
This section is empty.
Types ¶
type BuildContextOptions ¶
type BuildContextOptions struct {
MaxTurns int // Maximum number of recent turns to include
MaxTokens int // Maximum tokens to include (for context window)
IncludeSystem bool // Include system messages
IncludeTools bool // Include tool use messages
MinTurns int // Minimum number of turns to include (even if over token budget)
CompressionOK bool // Allow compressed content in context
}
BuildContextOptions specifies options for building conversation context
type CompressionType ¶
type CompressionType string
CompressionType represents the compression algorithm used
const ( CompressionNone CompressionType = "none" CompressionZstd CompressionType = "zstd" )
type Compressor ¶
type Compressor interface {
// Compress compresses the input data
Compress(data []byte) ([]byte, error)
// Decompress decompresses the input data
Decompress(data []byte) ([]byte, error)
// Type returns the compression type
Type() CompressionType
}
Compressor handles compression/decompression of conversation content
type NoopCompressor ¶
type NoopCompressor struct{}
NoopCompressor is a compressor that does nothing
func (*NoopCompressor) Decompress ¶
func (c *NoopCompressor) Decompress(data []byte) ([]byte, error)
func (*NoopCompressor) Type ¶
func (c *NoopCompressor) Type() CompressionType
type PruneOptions ¶
type PruneOptions struct {
KeepLastN int // Keep the last N turns (default: keep all)
OlderThan time.Duration // Remove turns older than this duration
KeepSystem bool // Keep system messages
MaxTokens int // Prune until total tokens is under this limit
DryRun bool // Don't actually delete, just return count
}
PruneOptions specifies options for pruning conversation history
type Reader ¶
type Reader interface {
io.Closer
// Next returns the next turn in the conversation
Next() (*types.ConversationTurn, error)
// Seek moves to a specific turn number
Seek(turnNumber int) error
}
Reader is an interface for reading turns from a conversation
type SQLiteStore ¶
type SQLiteStore struct {
// contains filtered or unexported fields
}
SQLiteStore implements Store using SQLite
func NewSQLiteStore ¶
func NewSQLiteStore(db *sql.DB) *SQLiteStore
NewSQLiteStore creates a new SQLite-backed conversation store
func (*SQLiteStore) AppendTurn ¶
func (s *SQLiteStore) AppendTurn(ctx context.Context, turn *types.ConversationTurn) error
AppendTurn adds a new turn to a conversation
func (*SQLiteStore) ArchiveConversation ¶
func (s *SQLiteStore) ArchiveConversation(ctx context.Context, conversationID string) error
ArchiveConversation moves a completed conversation to archive
func (*SQLiteStore) BuildContext ¶
func (s *SQLiteStore) BuildContext(ctx context.Context, taskID string, options *BuildContextOptions) (*types.ConversationContext, error)
BuildContext loads conversation context for a task
func (*SQLiteStore) CreateConversation ¶
func (s *SQLiteStore) CreateConversation(ctx context.Context, taskID, worktree string) (*types.Conversation, error)
CreateConversation creates a new conversation for a task
func (*SQLiteStore) DeleteConversation ¶
func (s *SQLiteStore) DeleteConversation(ctx context.Context, conversationID string) error
DeleteConversation deletes a conversation and all its turns
func (*SQLiteStore) GetConversation ¶
func (s *SQLiteStore) GetConversation(ctx context.Context, conversationID string) (*types.Conversation, error)
GetConversation retrieves a conversation by ID
func (*SQLiteStore) GetConversationByTask ¶
func (s *SQLiteStore) GetConversationByTask(ctx context.Context, taskID string) (*types.Conversation, error)
GetConversationByTask retrieves the active conversation for a task
func (*SQLiteStore) GetRecentTurns ¶
func (s *SQLiteStore) GetRecentTurns(ctx context.Context, conversationID string, limit int) ([]*types.ConversationTurn, error)
GetRecentTurns retrieves the N most recent turns from a conversation
func (*SQLiteStore) GetStats ¶
func (s *SQLiteStore) GetStats(ctx context.Context, conversationID string) (*types.ConversationStats, error)
GetStats returns statistics about a conversation
func (*SQLiteStore) GetTurn ¶
func (s *SQLiteStore) GetTurn(ctx context.Context, turnID string) (*types.ConversationTurn, error)
GetTurn retrieves a specific turn by ID
func (*SQLiteStore) GetTurnsByRange ¶
func (s *SQLiteStore) GetTurnsByRange(ctx context.Context, conversationID string, start, end int) ([]*types.ConversationTurn, error)
GetTurnsByRange retrieves turns in a specific range
func (*SQLiteStore) GetTurnsByTokenBudget ¶
func (s *SQLiteStore) GetTurnsByTokenBudget(ctx context.Context, conversationID string, maxTokens int) ([]*types.ConversationTurn, error)
GetTurnsByTokenBudget retrieves turns up to a token budget
func (*SQLiteStore) PruneConversation ¶
func (s *SQLiteStore) PruneConversation(ctx context.Context, conversationID string, options *PruneOptions) (int, error)
PruneConversation removes old turns from a conversation
func (*SQLiteStore) ResumeConversation ¶
func (s *SQLiteStore) ResumeConversation(ctx context.Context, taskID string) (*types.ConversationContext, error)
ResumeConversation loads conversation context for resuming a task
func (*SQLiteStore) SearchTurns ¶
func (s *SQLiteStore) SearchTurns(ctx context.Context, query string, limit int) ([]*types.ConversationSearchResult, error)
SearchTurns performs full-text search on conversation turns
func (*SQLiteStore) SearchTurnsInConversation ¶
func (s *SQLiteStore) SearchTurnsInConversation(ctx context.Context, conversationID, query string, limit int) ([]*types.ConversationSearchResult, error)
SearchTurnsInConversation searches within a specific conversation
func (*SQLiteStore) SetCompressor ¶
func (s *SQLiteStore) SetCompressor(c Compressor)
SetCompressor sets the compressor for this store
func (*SQLiteStore) SetTokenCounter ¶
func (s *SQLiteStore) SetTokenCounter(c TokenCounter)
SetTokenCounter sets the token counter for this store
func (*SQLiteStore) UpdateConversationStatus ¶
func (s *SQLiteStore) UpdateConversationStatus(ctx context.Context, conversationID string, status types.ConversationStatus) error
UpdateConversationStatus updates the status of a conversation
type SimpleTokenCounter ¶
type SimpleTokenCounter struct{}
SimpleTokenCounter is a simple token counter (rough estimate: ~4 chars per token)
func (*SimpleTokenCounter) CountTokens ¶
func (c *SimpleTokenCounter) CountTokens(text string) int
type Store ¶
type Store interface {
// CreateConversation creates a new conversation for a task
CreateConversation(ctx context.Context, taskID, worktree string) (*types.Conversation, error)
// GetConversation retrieves a conversation by ID
GetConversation(ctx context.Context, conversationID string) (*types.Conversation, error)
// GetConversationByTask retrieves the active conversation for a task
GetConversationByTask(ctx context.Context, taskID string) (*types.Conversation, error)
// UpdateConversationStatus updates the status of a conversation
UpdateConversationStatus(ctx context.Context, conversationID string, status types.ConversationStatus) error
// DeleteConversation deletes a conversation and all its turns
DeleteConversation(ctx context.Context, conversationID string) error
// AppendTurn adds a new turn to a conversation
AppendTurn(ctx context.Context, turn *types.ConversationTurn) error
// GetTurn retrieves a specific turn by ID
GetTurn(ctx context.Context, turnID string) (*types.ConversationTurn, error)
// GetRecentTurns retrieves the N most recent turns from a conversation
GetRecentTurns(ctx context.Context, conversationID string, limit int) ([]*types.ConversationTurn, error)
// GetTurnsByTokenBudget retrieves turns up to a token budget
GetTurnsByTokenBudget(ctx context.Context, conversationID string, maxTokens int) ([]*types.ConversationTurn, error)
// GetTurnsByRange retrieves turns in a specific range
GetTurnsByRange(ctx context.Context, conversationID string, start, end int) ([]*types.ConversationTurn, error)
// SearchTurns performs full-text search on conversation turns
SearchTurns(ctx context.Context, query string, limit int) ([]*types.ConversationSearchResult, error)
// SearchTurnsInConversation searches within a specific conversation
SearchTurnsInConversation(ctx context.Context, conversationID, query string, limit int) ([]*types.ConversationSearchResult, error)
// BuildContext loads conversation context for a task
BuildContext(ctx context.Context, taskID string, options *BuildContextOptions) (*types.ConversationContext, error)
// ResumeConversation loads conversation context for resuming a task
ResumeConversation(ctx context.Context, taskID string) (*types.ConversationContext, error)
// GetStats returns statistics about a conversation
GetStats(ctx context.Context, conversationID string) (*types.ConversationStats, error)
// PruneConversation removes old turns from a conversation
PruneConversation(ctx context.Context, conversationID string, options *PruneOptions) (int, error)
// ArchiveConversation moves a completed conversation to archive
ArchiveConversation(ctx context.Context, conversationID string) error
}
Store manages conversation persistence
type TokenCounter ¶
type TokenCounter interface {
// CountTokens estimates the number of tokens in the text
CountTokens(text string) int
}
TokenCounter estimates token count for text
type Writer ¶
type Writer interface {
io.WriteCloser
// WriteTurn writes a turn to the conversation
WriteTurn(turn *types.ConversationTurn) error
// Flush ensures all turns are written
Flush() error
}
Writer is an interface for writing turns to a conversation