history

package
v0.4.3 Latest Latest
Warning

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

Go to latest
Published: Jan 31, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AgentInteraction

type AgentInteraction struct {
	ID        int64
	Prompt    string // What the user asked
	Response  string // What the agent suggested
	Accepted  bool   // Did the user accept the suggestion?
	CommandID int64  // Link to executed command (if accepted)
	Context   string // Context that was sent (JSON)
	LatencyMs int64  // Agent response time
	Agent     string // Which agent (claude, ollama, etc.)
	Timestamp time.Time
}

AgentInteraction represents an agent prompt/response pair.

type Command

type Command struct {
	ID          int64
	Command     string    // The command that was executed
	Cwd         string    // Working directory
	ExitCode    int       // Exit code (0 = success)
	DurationMs  int64     // Execution duration in milliseconds
	Timestamp   time.Time // When the command was executed
	GitBranch   string    // Git branch at time of execution
	KubeContext string    // Kubernetes context
	IsSudo      bool      // Was this a sudo command?
	SudoUser    string    // User switched to (usually "root")
	RawCommand  string    // Original command with sudo prefix
}

Command represents a command in history.

type CommandCount

type CommandCount struct {
	Command string
	Count   int64
}

CommandCount pairs a command with its usage count.

type SearchOptions

type SearchOptions struct {
	Query      string // Full-text search query
	Limit      int    // Max results (0 = unlimited)
	Offset     int    // Pagination offset
	OnlyFailed bool   // Only show failed commands
	OnlySudo   bool   // Only show sudo commands
	Cwd        string // Filter by working directory
	Since      time.Time
	Before     time.Time
}

SearchOptions for querying history.

type SearchUI

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

SearchUI provides Ctrl+R style interactive search.

func NewSearchUI

func NewSearchUI(store *Store, palette prompt.Palette) *SearchUI

NewSearchUI creates a new search UI with the given color palette.

func (*SearchUI) Init

func (ui *SearchUI) Init() tea.Cmd

Init implements tea.Model.

func (*SearchUI) Run

func (ui *SearchUI) Run() (string, error)

Run starts the interactive search and returns the selected command.

func (*SearchUI) SetClipboard

func (ui *SearchUI) SetClipboard(buf *clipboard.Buffer)

SetClipboard sets the clipboard buffer for output cross-referencing.

func (*SearchUI) Update

func (ui *SearchUI) Update(msg tea.Msg) (tea.Model, tea.Cmd)

Update implements tea.Model.

func (*SearchUI) View

func (ui *SearchUI) View() string

View implements tea.Model.

type Stats

type Stats struct {
	TotalCommands      int64
	UniqueCommands     int64
	SuccessRate        float64
	TotalAgentCalls    int64
	AgentAcceptRate    float64
	MostUsedCommands   []CommandCount
	MostFailedCommands []CommandCount
}

Stats holds history statistics.

type Store

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

Store provides persistent command history.

func NewStore

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

NewStore creates or opens a history database.

func (*Store) Add

func (s *Store) Add(cmd Command) (int64, error)

Add inserts a command into history.

func (*Store) AddAgentInteraction

func (s *Store) AddAgentInteraction(interaction AgentInteraction) (int64, error)

AddAgentInteraction records an agent interaction.

func (*Store) Close

func (s *Store) Close() error

Close closes the database connection.

func (*Store) Count

func (s *Store) Count() (int64, error)

Count returns the total number of commands in history.

func (*Store) GetAgentInteractions

func (s *Store) GetAgentInteractions(prompt string, limit int) ([]AgentInteraction, error)

GetAgentInteractions returns agent interactions, optionally filtered.

func (*Store) GetRecent

func (s *Store) GetRecent(n int) ([]Command, error)

GetRecent returns the N most recent commands.

func (*Store) Search

func (s *Store) Search(opts SearchOptions) ([]Command, error)

Search performs a search on command history.

type SudoResult

type SudoResult struct {
	IsSudo     bool
	Command    string
	SudoUser   string
	RawCommand string
}

SudoResult contains parsed sudo command info.

func ParseSudoCommand

func ParseSudoCommand(raw string) SudoResult

ParseSudoCommand detects and parses sudo/doas commands.

Jump to

Keyboard shortcuts

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