Documentation
¶
Index ¶
- Constants
- Variables
- func DatabasePath() string
- func EstimateTokens(text string) int
- func InitSchema() []string
- type CommandFailureCount
- type CommandRecord
- type CommandStats
- type ParseFailureRecord
- type ParseFailureSummary
- type ReportFilter
- type SavingsSummary
- type SessionInfo
- type TimedExecution
- type Tracker
- func (t *Tracker) CleanupOld() (int64, error)
- func (t *Tracker) Close() error
- func (t *Tracker) CountCommandsSince(since time.Time) (int64, error)
- func (t *Tracker) GetCommandStats(projectPath string) ([]CommandStats, error)
- func (t *Tracker) GetDailySavings(projectPath string, days int) ([]struct{ ... }, error)
- func (t *Tracker) GetParseFailureSummary() (*ParseFailureSummary, error)
- func (t *Tracker) GetRecentCommands(projectPath string, limit int) ([]CommandRecord, error)
- func (t *Tracker) GetSavings(projectPath string) (*SavingsSummary, error)
- func (t *Tracker) OverallSavingsPct() (float64, error)
- func (t *Tracker) Query(query string, args ...interface{}) (*sql.Rows, error)
- func (t *Tracker) Record(record *CommandRecord) error
- func (t *Tracker) RecordFallback(command string, projectPath string, output string, execTimeMs int64) error
- func (t *Tracker) RecordParseFailure(rawCommand string, errorMessage string, fallbackSucceeded bool) error
- func (t *Tracker) TokensSaved24h() (int64, error)
- func (t *Tracker) TokensSavedTotal() (int64, error)
- func (t *Tracker) TopCommands(limit int) ([]string, error)
Constants ¶
const CreateCommandsTable = `` /* 732-byte string literal not displayed */
CreateCommandsTable creates the main commands table.
const CreateMigrationTable = `` /* 134-byte string literal not displayed */
MigrationHistory tracks applied migrations.
const CreateParseFailuresTable = `` /* 332-byte string literal not displayed */
CreateParseFailuresTable creates a table for tracking parse failures.
const CreateSummaryView = `` /* 341-byte string literal not displayed */
CreateSummaryView creates a view for aggregated statistics.
const HistoryRetentionDays = 90
HistoryRetentionDays is the number of days to retain tracking data. Records older than this are automatically cleaned up on each write.
const SchemaVersion = 1
SchemaVersion is the current database schema version.
Variables ¶
var Migrations = []string{ CreateCommandsTable, CreateSummaryView, CreateParseFailuresTable, }
Migrations contains all migration statements in order.
Functions ¶
func EstimateTokens ¶
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 ¶
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 (*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 ¶
NewTracker creates a new Tracker with the given database path.
func (*Tracker) CleanupOld ¶
CleanupOld manually triggers cleanup of old records. Returns the number of records deleted.
func (*Tracker) CountCommandsSince ¶
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 ¶
OverallSavingsPct returns the overall savings percentage across all commands.
func (*Tracker) Query ¶
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 ¶
TokensSaved24h returns tokens saved in the last 24 hours.
func (*Tracker) TokensSavedTotal ¶
TokensSavedTotal returns total tokens saved across all time.