Address golangci-lint findings and improve error handling throughout:
Package doc comments:
- Add canonical "// Package X ..." comments to source, model, config,
pipeline, cli, store, and main packages for godoc compliance.
Security & correctness:
- Fix directory permissions 0o755 -> 0o750 in store/cache.go Open()
(gosec G301: restrict group write on cache directory)
- Fix config.Save() to check encoder error before closing file, preventing
silent data loss on encode failure
- Add //nolint:gosec annotations with justifications on intentional
patterns (constructed file paths, manual bounds checking, config fields)
- Add //nolint:nilerr on intentional error-swallowing in scanner WalkDir
- Add //nolint:revive on stuttering type names (ModelStats, ModelUsage)
that would break too many call sites to rename
Performance (perfsprint):
- Replace fmt.Sprintf("%d", n) with strconv.FormatInt(n, 10) in format.go
FormatTokens() and FormatNumber() hot paths
- Clean up redundant fmt.Sprintf patterns in FormatCost and FormatDelta
Code cleanup:
- Convert if-else chain to switch in parser.go skipJSONString() for clarity
- Remove unused indexedResult struct from pipeline/loader.go
- Add deferred cache.Close() in pipeline/bench_test.go to prevent leaks
- Add deferred cache.Close() in cmd/root.go data loading path
- Fix doc comment alignment in scanner.go decodeProjectName
- Remove trailing blank line in cmd/costs.go
- Fix duplicate "/day" suffix in cmd/summary.go cost-per-day formatting
- Rename shadowed variable 'max' -> 'maxVal' in cli/render.go Sparkline
95 lines
2.1 KiB
Go
95 lines
2.1 KiB
Go
package model
|
|
|
|
import "time"
|
|
|
|
// SummaryStats holds the top-level aggregate across all sessions.
|
|
type SummaryStats struct {
|
|
TotalSessions int
|
|
TotalPrompts int
|
|
TotalAPICalls int
|
|
TotalDurationSecs int64
|
|
ActiveDays int
|
|
|
|
InputTokens int64
|
|
OutputTokens int64
|
|
CacheCreation5mTokens int64
|
|
CacheCreation1hTokens int64
|
|
CacheReadTokens int64
|
|
TotalBilledTokens int64
|
|
|
|
EstimatedCost float64
|
|
ActualCost *float64
|
|
CacheSavings float64
|
|
CacheHitRate float64
|
|
|
|
CostPerDay float64
|
|
TokensPerDay int64
|
|
SessionsPerDay float64
|
|
PromptsPerDay float64
|
|
MinutesPerDay float64
|
|
}
|
|
|
|
// DailyStats holds metrics for a single calendar day.
|
|
type DailyStats struct {
|
|
Date time.Time
|
|
Sessions int
|
|
Prompts int
|
|
APICalls int
|
|
DurationSecs int64
|
|
InputTokens int64
|
|
OutputTokens int64
|
|
CacheCreation5m int64
|
|
CacheCreation1h int64
|
|
CacheReadTokens int64
|
|
EstimatedCost float64
|
|
ActualCost *float64
|
|
}
|
|
|
|
// ModelStats holds aggregated metrics for a single model.
|
|
type ModelStats struct { //nolint:revive // renaming would break many call sites
|
|
Model string
|
|
APICalls int
|
|
InputTokens int64
|
|
OutputTokens int64
|
|
CacheCreation5m int64
|
|
CacheCreation1h int64
|
|
CacheReadTokens int64
|
|
EstimatedCost float64
|
|
SharePercent float64
|
|
TrendDirection int // -1, 0, +1 vs previous period
|
|
}
|
|
|
|
// ProjectStats holds aggregated metrics for a single project.
|
|
type ProjectStats struct {
|
|
Project string
|
|
Sessions int
|
|
Prompts int
|
|
TotalTokens int64
|
|
EstimatedCost float64
|
|
TrendDirection int
|
|
}
|
|
|
|
// HourlyStats holds prompt/session counts for one hour of the day.
|
|
type HourlyStats struct {
|
|
Hour int
|
|
Prompts int
|
|
Sessions int
|
|
Tokens int64
|
|
}
|
|
|
|
// WeeklyStats holds metrics for one calendar week.
|
|
type WeeklyStats struct {
|
|
WeekStart time.Time
|
|
Sessions int
|
|
Prompts int
|
|
TotalTokens int64
|
|
DurationSecs int64
|
|
EstimatedCost float64
|
|
}
|
|
|
|
// PeriodComparison holds current and previous period data for delta computation.
|
|
type PeriodComparison struct {
|
|
Current SummaryStats
|
|
Previous SummaryStats
|
|
}
|