tracking

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Mar 19, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const CreateCommandsTable = `` /* 732-byte string literal not displayed */

CreateCommandsTable creates the main commands table.

View Source
const CreateMigrationTable = `` /* 134-byte string literal not displayed */

MigrationHistory tracks applied migrations.

View Source
const CreateParseFailuresTable = `` /* 332-byte string literal not displayed */

CreateParseFailuresTable creates a table for tracking parse failures.

View Source
const CreateSummaryView = `` /* 341-byte string literal not displayed */

CreateSummaryView creates a view for aggregated statistics.

View Source
const HistoryRetentionDays = 90

HistoryRetentionDays is the number of days to retain tracking data. Records older than this are automatically cleaned up on each write.

View Source
const SchemaVersion = 1

SchemaVersion is the current database schema version.

Variables

Migrations contains all migration statements in order.

Functions

func DatabasePath

func DatabasePath() string

DatabasePath returns the default database path.

func EstimateTokens

func EstimateTokens(text string) int

EstimateTokens provides a heuristic token count. Uses the formula: ceil(text.length / 4.0)

func InitSchema

func InitSchema() []string

InitSchema initializes all database tables and migrations.

Types

type CommandFailureCount

type CommandFailureCount struct {
	Command string `json:"command"`
	Count   int    `json:"count"`
}

CommandFailureCount represents a command and its failure count.

type CommandRecord

type CommandRecord struct {
	ID             int64     `json:"id"`
	Command        string    `json:"command"`
	OriginalOutput string    `json:"original_output,omitempty"`
	FilteredOutput string    `json:"filtered_output,omitempty"`
	OriginalTokens int       `json:"original_tokens"`
	FilteredTokens int       `json:"filtered_tokens"`
	SavedTokens    int       `json:"saved_tokens"`
	ProjectPath    string    `json:"project_path"`
	SessionID      string    `json:"session_id,omitempty"`
	ExecTimeMs     int64     `json:"exec_time_ms"`
	Timestamp      time.Time `json:"timestamp"`
	ParseSuccess   bool      `json:"parse_success"`
}

CommandRecord represents a single command execution record.

type CommandStats

type CommandStats struct {
	Command        string  `json:"command"`
	ExecutionCount int     `json:"execution_count"`
	TotalSaved     int     `json:"total_saved"`
	TotalOriginal  int     `json:"total_original"`
	ReductionPct   float64 `json:"reduction_percent"`
}

CommandStats represents statistics for a specific command type.

type ParseFailureRecord

type ParseFailureRecord struct {
	ID                int64     `json:"id"`
	Timestamp         time.Time `json:"timestamp"`
	RawCommand        string    `json:"raw_command"`
	ErrorMessage      string    `json:"error_message"`
	FallbackSucceeded bool      `json:"fallback_succeeded"`
}

ParseFailureRecord represents a single parse failure event.

type ParseFailureSummary

type ParseFailureSummary struct {
	Total          int64                 `json:"total"`
	RecoveryRate   float64               `json:"recovery_rate"`
	TopCommands    []CommandFailureCount `json:"top_commands"`
	RecentFailures []ParseFailureRecord  `json:"recent_failures"`
}

ParseFailureSummary represents aggregated parse failure analytics.

type ReportFilter

type ReportFilter struct {
	ProjectPath string     `json:"project_path,omitempty"`
	SessionID   string     `json:"session_id,omitempty"`
	Command     string     `json:"command,omitempty"`
	StartTime   *time.Time `json:"start_time,omitempty"`
	EndTime     *time.Time `json:"end_time,omitempty"`
}

ReportFilter represents filters for generating reports.

type SavingsSummary

type SavingsSummary struct {
	TotalCommands int     `json:"total_commands"`
	TotalSaved    int     `json:"total_saved"`
	TotalOriginal int     `json:"total_original"`
	TotalFiltered int     `json:"total_filtered"`
	ReductionPct  float64 `json:"reduction_percent"`
}

SavingsSummary represents aggregated token savings.

type SessionInfo

type SessionInfo struct {
	SessionID   string    `json:"session_id"`
	StartedAt   time.Time `json:"started_at"`
	ProjectPath string    `json:"project_path"`
}

SessionInfo represents information about a shell session.

type TimedExecution

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

TimedExecution tracks execution time and token savings.

func Start

func Start() *TimedExecution

Start begins a timed execution for tracking.

func (*TimedExecution) Track

func (t *TimedExecution) Track(command, tokmanCmd string, originalTokens, filteredTokens int)

Track records the execution with token savings.

func (*TimedExecution) TrackPassthrough added in v1.2.0

func (t *TimedExecution) TrackPassthrough(command, tokmanCmd string)

TrackPassthrough records a passthrough command (no filtering).

type Tracker

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

Tracker manages token tracking persistence.

func GetGlobalTracker

func GetGlobalTracker() *Tracker

GetGlobalTracker returns the global tracker instance (exported for external use).

func NewTracker

func NewTracker(dbPath string) (*Tracker, error)

NewTracker creates a new Tracker with the given database path.

func (*Tracker) CleanupOld

func (t *Tracker) CleanupOld() (int64, error)

CleanupOld manually triggers cleanup of old records. Returns the number of records deleted.

func (*Tracker) Close

func (t *Tracker) Close() error

Close closes the database connection.

func (*Tracker) CountCommandsSince

func (t *Tracker) CountCommandsSince(since time.Time) (int64, error)

CountCommandsSince returns the count of commands executed since the given time.

func (*Tracker) GetCommandStats

func (t *Tracker) GetCommandStats(projectPath string) ([]CommandStats, error)

GetCommandStats returns statistics grouped by command.

func (*Tracker) GetDailySavings

func (t *Tracker) GetDailySavings(projectPath string, days int) ([]struct {
	Date     string
	Saved    int
	Original int
	Commands int
}, error)

GetDailySavings returns token savings grouped by day.

func (*Tracker) GetParseFailureSummary

func (t *Tracker) GetParseFailureSummary() (*ParseFailureSummary, error)

GetParseFailureSummary returns aggregated parse failure analytics.

func (*Tracker) GetRecentCommands

func (t *Tracker) GetRecentCommands(projectPath string, limit int) ([]CommandRecord, error)

GetRecentCommands returns the most recent command executions.

func (*Tracker) GetSavings

func (t *Tracker) GetSavings(projectPath string) (*SavingsSummary, error)

GetSavings returns the total token savings for a project path. Uses GLOB matching to include child directories.

func (*Tracker) OverallSavingsPct

func (t *Tracker) OverallSavingsPct() (float64, error)

OverallSavingsPct returns the overall savings percentage across all commands.

func (*Tracker) Query

func (t *Tracker) Query(query string, args ...interface{}) (*sql.Rows, error)

Query executes a raw SQL query and returns the rows. This is exposed for custom aggregations in the economics package.

func (*Tracker) Record

func (t *Tracker) Record(record *CommandRecord) error

Record saves a command execution to the database.

func (*Tracker) RecordFallback added in v1.2.0

func (t *Tracker) RecordFallback(command string, projectPath string, output string, execTimeMs int64) error

RecordFallback records a command that wasn't recognized (parse failure).

func (*Tracker) RecordParseFailure

func (t *Tracker) RecordParseFailure(rawCommand string, errorMessage string, fallbackSucceeded bool) error

RecordParseFailure records a parse failure event.

func (*Tracker) TokensSaved24h

func (t *Tracker) TokensSaved24h() (int64, error)

TokensSaved24h returns tokens saved in the last 24 hours.

func (*Tracker) TokensSavedTotal

func (t *Tracker) TokensSavedTotal() (int64, error)

TokensSavedTotal returns total tokens saved across all time.

func (*Tracker) TopCommands

func (t *Tracker) TopCommands(limit int) ([]string, error)

TopCommands returns the top N commands by execution count.

Jump to

Keyboard shortcuts

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