Documentation
¶
Overview ¶
Package cmdhistory implements a structured command history store using SQLite. Inspired by atuin, it records every Bash tool call with rich context (exit code, duration, working directory, git branch, session) and provides powerful FTS5-backed search and recall.
Index ¶
- type CommandCount
- type DirCount
- type Entry
- type HistoryStats
- type SearchOpts
- type Store
- func (s *Store) Close() error
- func (s *Store) Recent(n int) ([]Entry, error)
- func (s *Store) Record(entry Entry) error
- func (s *Store) Search(query string, opts SearchOpts) ([]Entry, error)
- func (s *Store) SearchByDir(dir string, limit int) ([]Entry, error)
- func (s *Store) Stats() (*HistoryStats, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CommandCount ¶
CommandCount pairs a command string with its execution count.
type Entry ¶
type Entry struct {
ID string
Command string
ExitCode int
Duration time.Duration
CWD string
GitBranch string
SessionID string
CreatedAt time.Time
}
Entry represents a single command execution with context.
type HistoryStats ¶
type HistoryStats struct {
TotalCommands int
UniqueCommands int
SuccessRate float64
TopCommands []CommandCount
TopDirectories []DirCount
}
HistoryStats holds aggregate usage statistics.
type SearchOpts ¶
type SearchOpts struct {
Limit int
ExitCode *int // filter by exit code (nil = any)
CWD string // filter by working directory
SessionID string // filter by session
Since time.Time // only entries after this time
}
SearchOpts controls filtering for the Search method.
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store provides access to the command history database.
func (*Store) Search ¶
func (s *Store) Search(query string, opts SearchOpts) ([]Entry, error)
Search finds commands matching the query using FTS5 full-text search. The query is passed through to the FTS5 MATCH operator, so callers can use FTS5 query syntax (e.g. prefix queries with *, boolean AND/OR/NOT). For simple substring searches, each word is automatically turned into a prefix token.
func (*Store) SearchByDir ¶
SearchByDir returns commands executed in a specific directory, newest-first.
func (*Store) Stats ¶
func (s *Store) Stats() (*HistoryStats, error)
Stats returns aggregate usage statistics computed in SQL for efficiency.