Documentation
¶
Overview ¶
Package data provides Go data models that map to the Copilot CLI session store SQLite database, along with types for filtering, sorting, and pivoting session queries.
Index ¶
- Variables
- func ChronicleReindex(ctx context.Context, onLine func(line string)) error
- func LastReindexTime() time.Time
- func Maintain() error
- type Checkpoint
- type FilterOptions
- type PivotField
- type SearchResult
- type Session
- type SessionDetail
- type SessionFile
- type SessionGroup
- type SessionRef
- type SortField
- type SortOptions
- type SortOrder
- type Store
- func (s *Store) Close() error
- func (s *Store) GetSession(id string) (*SessionDetail, error)
- func (s *Store) GroupSessions(pivot PivotField, filter FilterOptions, sort SortOptions, limit int) ([]SessionGroup, error)
- func (s *Store) ListBranches(repository string) ([]string, error)
- func (s *Store) ListFolders() ([]string, error)
- func (s *Store) ListRepositories() ([]string, error)
- func (s *Store) ListSessions(filter FilterOptions, sort SortOptions, limit int) ([]Session, error)
- func (s *Store) ListSessionsByIDs(ids []string) ([]Session, error)
- func (s *Store) SearchSessions(query string, limit int) ([]SearchResult, error)
- type Turn
Constants ¶
This section is empty.
Variables ¶
var ErrCopilotNotFound = errors.New("copilot CLI binary not found")
ErrCopilotNotFound is returned when the Copilot CLI binary cannot be located on the system.
var ErrIndexBusy = errors.New("session store is busy — Copilot CLI may be reindexing, try again shortly")
ErrIndexBusy is returned when the session store database is locked by another process (e.g. Copilot CLI reindexing).
var ErrReindexCancelled = errors.New("reindex cancelled")
ErrReindexCancelled is returned when the user cancels a running reindex.
Functions ¶
func ChronicleReindex ¶
ChronicleReindex launches the Copilot CLI in a pseudo-terminal, sends the /chronicle reindex slash command, and streams cleaned output lines to the provided callback. This performs the full ETL: reading session JSONL files, workspace metadata, and checkpoints into the SQLite store.
If the Copilot CLI binary cannot be found, it returns ErrCopilotNotFound and the caller should fall back to Maintain().
The ctx parameter supports cancellation — when cancelled the PTY is closed immediately and ErrReindexCancelled is returned.
The onLine callback receives each non-empty line of stripped output. It is called from a goroutine and must be safe for concurrent use.
func LastReindexTime ¶
LastReindexTime returns the modification time of the session store database file, which is updated whenever a reindex writes to it. Returns the zero time if the file cannot be found.
func Maintain ¶
func Maintain() error
Maintain opens a temporary read-write connection to the session store, checkpoints the WAL, rebuilds and optimises the FTS5 search index, then closes the connection. This does NOT modify session data — only index and journal maintenance. Safe to call while the read-only Store is open.
Types ¶
type Checkpoint ¶
type Checkpoint struct {
SessionID string `json:"session_id"`
CheckpointNumber int `json:"checkpoint_number"`
Title string `json:"title"`
Overview string `json:"overview"`
History string `json:"history"`
WorkDone string `json:"work_done"`
TechnicalDetails string `json:"technical_details"`
ImportantFiles string `json:"important_files"`
NextSteps string `json:"next_steps"`
}
Checkpoint maps to the checkpoints table and captures a point-in-time snapshot of session progress.
type FilterOptions ¶
type FilterOptions struct {
Query string `json:"query,omitempty"`
Folder string `json:"folder,omitempty"`
Repository string `json:"repository,omitempty"`
Branch string `json:"branch,omitempty"`
Since *time.Time `json:"since,omitempty"`
Until *time.Time `json:"until,omitempty"`
HasRefs bool `json:"has_refs,omitempty"`
ExcludedDirs []string `json:"excluded_dirs,omitempty"`
// DeepSearch controls the breadth of the text search. When false
// (default / quick mode), only session-level fields are searched
// (summary, branch, repository, cwd). When true (deep mode), related
// tables are also searched: turns.user_message, checkpoints.title,
// checkpoints.overview, session_files.file_path, session_refs.ref_value.
DeepSearch bool `json:"deep_search,omitempty"`
}
FilterOptions describes the criteria used to narrow session queries.
type PivotField ¶
type PivotField string
PivotField identifies the dimension used to group sessions.
const ( // PivotByFolder groups sessions by their working directory. PivotByFolder PivotField = "cwd" // PivotByRepo groups sessions by repository name. PivotByRepo PivotField = "repository" // PivotByBranch groups sessions by git branch name. PivotByBranch PivotField = "branch" // PivotByDate groups sessions by date (YYYY-MM-DD). PivotByDate PivotField = "date" )
type SearchResult ¶
type SearchResult struct {
Content string `json:"content"`
SessionID string `json:"session_id"`
SourceType string `json:"source_type"`
SourceID string `json:"source_id"`
Rank float64 `json:"rank"`
}
SearchResult holds a single row returned from the FTS5 search_index virtual table, including the relevance rank.
type Session ¶
type Session struct {
ID string `json:"id"`
Cwd string `json:"cwd"`
Repository string `json:"repository"`
Branch string `json:"branch"`
Summary string `json:"summary"`
CreatedAt string `json:"created_at"`
UpdatedAt string `json:"updated_at"`
// LastActiveAt is computed at query time as the latest turn timestamp,
// falling back to updated_at then created_at. This avoids the problem
// where the Copilot CLI reindex resets updated_at on all sessions.
LastActiveAt string `json:"last_active_at"`
// Computed fields – populated by JOIN aggregates, not stored in the table.
TurnCount int `json:"turn_count"`
FileCount int `json:"file_count"`
}
Session maps to the sessions table and carries computed aggregate counts populated at query time.
type SessionDetail ¶
type SessionDetail struct {
Session Session `json:"session"`
Turns []Turn `json:"turns"`
Checkpoints []Checkpoint `json:"checkpoints"`
Files []SessionFile `json:"files"`
Refs []SessionRef `json:"refs"`
}
SessionDetail is an aggregated view that combines a session with all of its related turns, checkpoints, files, and external references.
type SessionFile ¶
type SessionFile struct {
SessionID string `json:"session_id"`
FilePath string `json:"file_path"`
ToolName string `json:"tool_name"`
TurnIndex int `json:"turn_index"`
FirstSeenAt string `json:"first_seen_at"`
}
SessionFile maps to the session_files table and records a file touched during a session.
type SessionGroup ¶
type SessionGroup struct {
Label string `json:"label"`
Sessions []Session `json:"sessions"`
Count int `json:"count"`
}
SessionGroup holds a set of sessions that share a common pivot label.
type SessionRef ¶
type SessionRef struct {
SessionID string `json:"session_id"`
RefType string `json:"ref_type"` // "commit", "pr", or "issue"
RefValue string `json:"ref_value"`
TurnIndex int `json:"turn_index"`
CreatedAt string `json:"created_at"`
}
SessionRef maps to the session_refs table and links a session to an external reference such as a commit, pull request, or issue.
type SortField ¶
type SortField string
SortField identifies which column to sort sessions by.
const ( // SortByUpdated sorts sessions by last update time. SortByUpdated SortField = "updated_at" // SortByCreated sorts sessions by creation time. SortByCreated SortField = "created_at" // SortByTurns sorts sessions by conversation turn count. SortByTurns SortField = "turn_count" // SortByName sorts sessions alphabetically by summary. SortByName SortField = "summary" // SortByFolder sorts sessions alphabetically by working directory. SortByFolder SortField = "cwd" )
type SortOptions ¶
SortOptions combines a field and direction for ordering query results.
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store provides read-only access to the Copilot CLI session store.
func OpenPath ¶
OpenPath opens the session store at the given file path. The database is opened in read-only mode.
func (*Store) GetSession ¶
func (s *Store) GetSession(id string) (*SessionDetail, error)
GetSession loads a single session and all of its related turns, checkpoints, files, and refs.
func (*Store) GroupSessions ¶
func (s *Store) GroupSessions(pivot PivotField, filter FilterOptions, sort SortOptions, limit int) ([]SessionGroup, error)
GroupSessions groups sessions by the specified pivot field, applying the given filter and sort order within each group.
func (*Store) ListBranches ¶
ListBranches returns distinct branch values. If repository is non-empty, results are filtered to that repository.
func (*Store) ListFolders ¶
ListFolders returns the distinct cwd values across all sessions, sorted alphabetically.
func (*Store) ListRepositories ¶
ListRepositories returns the distinct non-empty repository values across all sessions, sorted alphabetically.
func (*Store) ListSessions ¶
func (s *Store) ListSessions(filter FilterOptions, sort SortOptions, limit int) ([]Session, error)
ListSessions returns sessions matching the filter, ordered and limited as specified. TurnCount and FileCount are computed via subqueries.
func (*Store) ListSessionsByIDs ¶
ListSessionsByIDs returns sessions matching the given IDs, preserving the input order. IDs not found in the database are silently skipped.
func (*Store) SearchSessions ¶
func (s *Store) SearchSessions(query string, limit int) ([]SearchResult, error)
SearchSessions performs a fuzzy substring search across session metadata and turn content, returning matches ranked by source type. Sessions with zero turns are excluded.
type Turn ¶
type Turn struct {
SessionID string `json:"session_id"`
TurnIndex int `json:"turn_index"`
UserMessage string `json:"user_message"`
AssistantResponse string `json:"assistant_response"`
Timestamp string `json:"timestamp"`
}
Turn maps to the turns table and represents a single conversational exchange within a session.