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

sessionquery

package
v0.0.0-...-a92561a Latest Latest
Warning

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

Go to latest
Published: Oct 4, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrUnauthorized = errors.New("unauthorized: caller workspace does not have access to the target session")

ErrUnauthorized indicates the caller is not authorized to access sessions in the requested workspace.

Functions

This section is empty.

Types

type DB

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

DB wraps the SQLite database connection with connection synchronization.

func OpenDB

func OpenDB(dbPath string) (*DB, error)

OpenDB opens (or creates) the SQLite database at dbPath and initializes the schema.

func (*DB) Close

func (d *DB) Close() error

Close closes the underlying SQLite connection.

func (*DB) Conn

func (d *DB) Conn() *sql.DB

Conn returns the raw SQL DB connection.

func (*DB) Search

func (d *DB) Search(ctx context.Context, params SearchParams) (*SearchResponse, error)

Search executes an FTS5 search query over the indexed session database.

type Indexer

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

Indexer manages incremental full-text indexing of sessions.

func NewIndexer

func NewIndexer(db *DB, sessionsDir string) *Indexer

NewIndexer creates a new session indexer.

func (*Indexer) IndexSession

func (idx *Indexer) IndexSession(ctx context.Context, sessionID string) (bool, error)

IndexSession indexes or updates a single session if modified.

func (*Indexer) RebuildIndex

func (idx *Indexer) RebuildIndex(ctx context.Context) error

RebuildIndex drops all existing index tables and re-indexes all sessions from scratch.

func (*Indexer) SyncAll

func (idx *Indexer) SyncAll(ctx context.Context) (int, error)

SyncAll incrementally indexes all session files in sessionsDir and removes deleted ones.

type SearchMatch

type SearchMatch struct {
	SessionID string `json:"session_id"`
	Workspace string `json:"workspace"`
	Model     string `json:"model,omitempty"`
	Provider  string `json:"provider,omitempty"`
	Role      string `json:"role"`
	MsgIndex  int    `json:"msg_index"`
	Snippet   string `json:"snippet"`
	Content   string `json:"content"`
}

SearchMatch represents an individual matched message within a session.

type SearchParams

type SearchParams struct {
	CallerWorkspace string   `json:"caller_workspace,omitempty"` // Enforces workspace authorization boundary
	Workspace       string   `json:"workspace,omitempty"`        // Filter by workspace path
	SessionID       string   `json:"session_id,omitempty"`       // Scope search to a specific session
	Query           string   `json:"query"`                      // Full-text search term
	Roles           []string `json:"roles,omitempty"`            // e.g. ["user", "assistant"]
	Limit           int      `json:"limit,omitempty"`            // Results page limit (default 10, max 50)
	Offset          int      `json:"offset,omitempty"`           // Pagination offset
	MaxBytes        int      `json:"max_bytes,omitempty"`        // Maximum total bytes of content to return (default 16 KiB)
}

SearchParams specifies filters and parameters for full-text session queries.

type SearchResponse

type SearchResponse struct {
	Matches    []SearchMatch `json:"matches"`
	TotalCount int           `json:"total_count"`
	HasMore    bool          `json:"has_more"`
	Offset     int           `json:"offset"`
	Limit      int           `json:"limit"`
	Query      string        `json:"query"`
}

SearchResponse represents the paginated search result.

type Service

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

Service encapsulates database indexing and search capabilities.

func DefaultService

func DefaultService() (*Service, error)

DefaultService returns the process-wide session query service.

func NewService

func NewService(dbPath, sessionsDir string) (*Service, error)

NewService creates a new SessionQuery service with the specified paths.

func (*Service) Close

func (s *Service) Close() error

Close closes the underlying resources.

func (*Service) DB

func (s *Service) DB() *DB

DB returns the underlying DB instance.

func (*Service) Indexer

func (s *Service) Indexer() *Indexer

Indexer returns the underlying session indexer.

func (*Service) RebuildIndex

func (s *Service) RebuildIndex(ctx context.Context) error

RebuildIndex drops and rebuilds the full-text search index from scratch.

func (*Service) Search

func (s *Service) Search(ctx context.Context, params SearchParams) (*SearchResponse, error)

Search runs a full-text search against the indexed sessions. Automatically ensures the index is synchronized first.

Jump to

Keyboard shortcuts

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