Documentation
¶
Overview ¶
Package db provides SQLite persistence for Techne Code using GORM. It implements the SessionStore interface for storing sessions, messages, and tracking file reads and permission grants.
Index ¶
- func Open(dbPath string) (*gorm.DB, error)
- type GormSessionStore
- func (s *GormSessionStore) CreateSession(sess *session.Session) error
- func (s *GormSessionStore) DeleteMessages(sessionID string) error
- func (s *GormSessionStore) DeleteSession(id string) error
- func (s *GormSessionStore) GetMessages(sessionID string) ([]session.StoredMessage, error)
- func (s *GormSessionStore) GetMessagesAfter(sessionID string, after time.Time) ([]session.StoredMessage, error)
- func (s *GormSessionStore) GetSession(id string) (*session.Session, error)
- func (s *GormSessionStore) HasReadFile(sessionID, path string) (bool, error)
- func (s *GormSessionStore) ListSessions() ([]session.Session, error)
- func (s *GormSessionStore) SaveMessage(m *session.StoredMessage) error
- func (s *GormSessionStore) TrackReadFile(sessionID, path string) error
- func (s *GormSessionStore) UpdateSessionSummary(id, summaryMessageID string) error
- func (s *GormSessionStore) UpdateSessionTitle(id, title string) error
- type MessageModel
- type PermissionGrantModel
- type ReadFileModel
- type SessionModel
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type GormSessionStore ¶
type GormSessionStore struct {
// contains filtered or unexported fields
}
GormSessionStore implements session.SessionStore using GORM with SQLite.
func NewSessionStore ¶
func NewSessionStore(db *gorm.DB) *GormSessionStore
NewSessionStore creates a new GormSessionStore with the given database connection.
func (*GormSessionStore) CreateSession ¶
func (s *GormSessionStore) CreateSession(sess *session.Session) error
CreateSession creates a new session in the store. If sess.ID is empty, a UUID v4 is generated. CreatedAt and UpdatedAt are set to the current time.
func (*GormSessionStore) DeleteMessages ¶
func (s *GormSessionStore) DeleteMessages(sessionID string) error
DeleteMessages removes all messages for a session.
func (*GormSessionStore) DeleteSession ¶
func (s *GormSessionStore) DeleteSession(id string) error
DeleteSession removes a session and all its messages from the store. Messages are cascade deleted via foreign key constraint.
func (*GormSessionStore) GetMessages ¶
func (s *GormSessionStore) GetMessages(sessionID string) ([]session.StoredMessage, error)
GetMessages retrieves all messages for a session, ordered chronologically (CreatedAt ASC).
func (*GormSessionStore) GetMessagesAfter ¶
func (s *GormSessionStore) GetMessagesAfter(sessionID string, after time.Time) ([]session.StoredMessage, error)
GetMessagesAfter retrieves messages created after the specified time. Useful for fetching new messages after a summary point.
func (*GormSessionStore) GetSession ¶
func (s *GormSessionStore) GetSession(id string) (*session.Session, error)
GetSession retrieves a session by ID. Returns nil if the session doesn't exist.
func (*GormSessionStore) HasReadFile ¶
func (s *GormSessionStore) HasReadFile(sessionID, path string) (bool, error)
HasReadFile checks if a file was previously read in a session.
func (*GormSessionStore) ListSessions ¶
func (s *GormSessionStore) ListSessions() ([]session.Session, error)
ListSessions returns all sessions, ordered by UpdatedAt descending (most recent first).
func (*GormSessionStore) SaveMessage ¶
func (s *GormSessionStore) SaveMessage(m *session.StoredMessage) error
SaveMessage stores a message in the session history. If m.ID is empty, a UUID v4 is generated. CreatedAt is set to the current time if not provided.
func (*GormSessionStore) TrackReadFile ¶
func (s *GormSessionStore) TrackReadFile(sessionID, path string) error
TrackReadFile records that a file was read in a session. If the record already exists, ReadAt is updated (upsert behavior).
func (*GormSessionStore) UpdateSessionSummary ¶
func (s *GormSessionStore) UpdateSessionSummary(id, summaryMessageID string) error
UpdateSessionSummary updates the summary message reference for context compression.
func (*GormSessionStore) UpdateSessionTitle ¶
func (s *GormSessionStore) UpdateSessionTitle(id, title string) error
UpdateSessionTitle updates the title of a session.
type MessageModel ¶
type MessageModel struct {
ID string `gorm:"primaryKey"`
SessionID string `gorm:"not null;index"`
Role string `gorm:"not null;size:20"`
Content string `gorm:"not null;default:'[]'"` // JSON string
Model string `gorm:"column:model"`
CreatedAt time.Time `gorm:"not null;index"`
Session SessionModel `gorm:"foreignKey:SessionID"`
}
MessageModel is the GORM model for messages table.
func (MessageModel) TableName ¶
func (MessageModel) TableName() string
TableName returns the table name for MessageModel.
type PermissionGrantModel ¶
type PermissionGrantModel struct {
SessionID string `gorm:"primaryKey"`
ToolName string `gorm:"primaryKey;column:tool_name"`
Action string `gorm:"primaryKey"`
GrantedAt time.Time `gorm:"not null"`
}
PermissionGrantModel is the GORM model for permission_grants table. Tracks which tool/action combinations have been granted permission in a session.
func (PermissionGrantModel) TableName ¶
func (PermissionGrantModel) TableName() string
TableName returns the table name for PermissionGrantModel.
type ReadFileModel ¶
type ReadFileModel struct {
SessionID string `gorm:"primaryKey"`
Path string `gorm:"primaryKey"`
ReadAt time.Time `gorm:"not null"`
}
ReadFileModel is the GORM model for read_files table. Tracks which files have been read in each session for context management.
func (ReadFileModel) TableName ¶
func (ReadFileModel) TableName() string
TableName returns the table name for ReadFileModel.
type SessionModel ¶
type SessionModel struct {
ID string `gorm:"primaryKey"`
Title string `gorm:"not null;default:'New Session'"`
Model string `gorm:"not null"`
Provider string `gorm:"not null"`
SummaryMessageID *string `gorm:"column:summary_message_id"`
CreatedAt time.Time `gorm:"not null"`
UpdatedAt time.Time `gorm:"not null"`
Messages []MessageModel `gorm:"foreignKey:SessionID;constraint:OnDelete:CASCADE"`
}
SessionModel is the GORM model for sessions table.
func (SessionModel) TableName ¶
func (SessionModel) TableName() string
TableName returns the table name for SessionModel.