cmdhistory

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: May 12, 2026 License: MIT Imports: 6 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CommandCount

type CommandCount struct {
	Command string
	Count   int
}

CommandCount pairs a command string with its execution count.

type DirCount

type DirCount struct {
	Dir   string
	Count int
}

DirCount pairs a directory path 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 New

func New(dbPath string) (*Store, error)

New opens or creates the command history database at the given path.

func (*Store) Close

func (s *Store) Close() error

Close closes the underlying database connection.

func (*Store) Recent

func (s *Store) Recent(n int) ([]Entry, error)

Recent returns the N most recent commands, ordered newest-first.

func (*Store) Record

func (s *Store) Record(entry Entry) error

Record saves a command execution with its context.

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

func (s *Store) SearchByDir(dir string, limit int) ([]Entry, error)

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.

Jump to

Keyboard shortcuts

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