tracking

package
v1.38.5 Latest Latest
Warning

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

Go to latest
Published: Apr 15, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddTrackingSkip added in v1.10.2

func AddTrackingSkip(cmd string) error

AddTrackingSkip adds a command to the no-track list so it is never recorded again.

func Cleanup

func Cleanup(days int) error

Cleanup removes records older than the given number of days.

func CountTokens

func CountTokens(s string) int

CountTokens returns the word count of a string (whitespace-split).

func DBPath added in v1.28.0

func DBPath() string

DBPath returns the path to the tracking database file.

func DeleteCommand added in v1.5.0

func DeleteCommand(cmd string) error

DeleteCommand removes all tracking records for a command key (first two words). This permanently erases the command from the history and unchopped report.

func ExportCSV added in v1.12.0

func ExportCSV(w io.Writer, records []Record) error

ExportCSV writes tracking history as CSV to w.

func ExportJSON added in v1.12.0

func ExportJSON(w io.Writer, records []Record, s Stats) error

ExportJSON writes tracking history and summary stats as JSON to w.

func FormatGain

func FormatGain(s Stats) string

FormatGain prints the gain summary report.

func FormatGainSince added in v1.12.0

func FormatGainSince(s Stats, sinceStr string) string

FormatGainSince formats a stats report for a --since time window.

func FormatHistory

func FormatHistory(records []Record, verbose bool, color bool) string

FormatHistory formats history records for display. When verbose is false, long command strings are truncated to 50 characters. When color is true, ANSI colors are applied to markers and savings percentages. In verbose mode, records are grouped by project with a header line between groups.

func FormatProjectSummary added in v1.28.0

func FormatProjectSummary(summaries []ProjectSummary) string

FormatProjectSummary formats per-project aggregate savings.

func FormatSummary added in v0.5.1

func FormatSummary(summaries []CommandSummary) string

FormatSummary formats per-command aggregates.

func FormatUnchopped added in v1.4.0

func FormatUnchopped(summaries []UnchoppedSummary, skipped []string, filtered []UnchoppedSummary, verbose bool) string

FormatUnchopped formats the unchopped commands report. summaries are active candidates; skipped are manually skipped commands; filtered are commands auto-excluded because a registered filter exists for them. verbose disables command name truncation.

func GetSkippedCommands added in v1.5.0

func GetSkippedCommands() ([]string, error)

GetSkippedCommands returns all commands in the skip list, ordered alphabetically.

func Init

func Init() error

Init opens (or creates) the tracking database and ensures the schema exists.

func IsColorEnabled added in v1.28.0

func IsColorEnabled() bool

IsColorEnabled reports whether color output should be used: stdout must be a terminal and NO_COLOR must not be set.

func MigrateWindowsDataDir added in v1.25.1

func MigrateWindowsDataDir()

MigrateWindowsDataDir is a no-op on non-Windows platforms.

func ParseSinceDuration added in v1.12.0

func ParseSinceDuration(s string) (time.Duration, error)

ParseSinceDuration parses duration strings like "7d", "2w", "24h", "30m". Supports: m (minutes), h (hours), d (days), w (weeks). Falls back to time.ParseDuration for standard Go duration strings.

func RemoveTrackingSkip added in v1.10.2

func RemoveTrackingSkip(cmd string) error

RemoveTrackingSkip removes a command from the no-track list, re-enabling tracking.

func SkipUnchopped added in v1.5.0

func SkipUnchopped(cmd string) error

SkipUnchopped marks a command as intentionally not needing a filter.

func Track

func Track(command string, rawTokens, filteredTokens int) error

Track records a command's token savings. Silent on error.

func UnskipUnchopped added in v1.5.0

func UnskipUnchopped(cmd string) error

UnskipUnchopped removes a command from the skip list.

Types

type CommandSummary added in v0.5.1

type CommandSummary struct {
	BaseCommand string
	Count       int
	RawTokens   int
	SavedTokens int
	SavingsPct  float64
	ZeroCount   int // times with 0% savings
}

CommandSummary holds per-command aggregate stats.

func GetCommandSummary added in v0.5.1

func GetCommandSummary() ([]CommandSummary, error)

GetCommandSummary returns per-base-command aggregates, sorted by tokens saved descending.

type ProjectSummary added in v1.28.0

type ProjectSummary struct {
	Project     string
	Count       int
	RawTokens   int
	SavedTokens int
	SavingsPct  float64
}

ProjectSummary holds per-project aggregate stats.

func GetProjectSummary added in v1.28.0

func GetProjectSummary() ([]ProjectSummary, error)

GetProjectSummary returns per-project aggregate stats, sorted by tokens saved descending.

type Record

type Record struct {
	Timestamp      string
	Command        string
	RawTokens      int
	FilteredTokens int
	SavingsPct     float64
	Project        string
}

Record holds a single tracking entry.

func FilterCompressed added in v1.38.0

func FilterCompressed(records []Record) []Record

FilterCompressed returns only records where output was actually compressed (savings > 0).

func GetHistory

func GetHistory(limit int) ([]Record, error)

GetHistory returns the last N tracking records in reverse chronological order.

func GetHistoryByProject added in v1.28.0

func GetHistoryByProject(project string, limit int) ([]Record, error)

GetHistoryByProject returns the last N tracking records for a specific project.

func GetHistorySince added in v1.12.0

func GetHistorySince(limit int, d time.Duration) ([]Record, error)

GetHistorySince returns up to limit records newer than the given duration.

type Stats

type Stats struct {
	TotalCommands     int
	TotalRawTokens    int
	TotalSavedTokens  int
	OverallSavingsPct float64
	TodayCommands     int
	TodayRawTokens    int
	TodaySavedTokens  int
	WeekCommands      int
	WeekRawTokens     int
	WeekSavedTokens   int
	MonthCommands     int
	MonthRawTokens    int
	MonthSavedTokens  int
	YearCommands      int
	YearRawTokens     int
	YearSavedTokens   int
}

Stats holds aggregate token savings statistics.

func GetStats

func GetStats() (Stats, error)

GetStats returns aggregate statistics.

func GetStatsSince added in v1.12.0

func GetStatsSince(d time.Duration) (Stats, error)

GetStatsSince returns aggregate stats for records within the last d duration.

type UnchoppedSummary added in v1.4.0

type UnchoppedSummary struct {
	Command     string
	Count       int
	TotalTokens int // total raw tokens that could have been saved
}

UnchoppedSummary holds stats for commands that consistently get 0% savings.

func GetUnchopped added in v1.4.0

func GetUnchopped() ([]UnchoppedSummary, error)

GetUnchopped returns commands that always got 0% savings, sorted by call count desc. These are the best candidates for writing new filters.

Jump to

Keyboard shortcuts

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