Documentation
¶
Overview ¶
Package analytics implements efficiency and analytics features for DevinMonitor: cache metrics, efficiency scoring, one-shot/retry rates, task categorization, waste detection, compaction events, model comparison, and context window analysis.
Commands self-register via cli.Register() in init() so that main.go can pull them in with a blank import, avoiding edits to existing files.
Index ¶
- Constants
- func AnalyzeContext(s *model.Session) model.ContextAnalysis
- func CacheDonut(hitRatio float64, width int) string
- func CacheSavingsDetailed(ss []model.Session) float64
- func CacheStatsAggregate(ss []model.Session) model.CacheStats
- func CacheStatsForSession(s *model.Session) model.CacheStats
- func ClassifySession(s *model.Session) string
- func CompareModels(ss []model.Session, modelNames []string) model.ModelComparison
- func DetectCompaction(s *model.Session) []model.CompactionEvent
- func DetectCompactionAll(ss []model.Session) []model.CompactionEvent
- func EfficiencyGrade(score model.EfficiencyScore) string
- func OneShotRateAggregate(ss []model.Session) model.OneShotRate
- func OneShotRateForSession(s *model.Session) model.OneShotRate
- func TaskCategories(ss []model.Session) []model.TaskCategory
- func WasteScan(ss []model.Session) []model.WasteFinding
- type CompactionSummary
- type ContextBreakdown
- type ContextEntry
- type EfficiencyMetrics
- type FileRetry
Constants ¶
const ( CatCoding = "Coding" CatDebugging = "Debugging" CatTesting = "Testing" CatExploration = "Exploration" CatPlanning = "Planning" CatDelegation = "Delegation" CatGitOps = "Git Ops" CatBuildDeploy = "Build/Deploy" CatConversation = "Conversation" CatGeneral = "General" )
Category names for task classification.
Variables ¶
This section is empty.
Functions ¶
func AnalyzeContext ¶
func AnalyzeContext(s *model.Session) model.ContextAnalysis
AnalyzeContext breaks down what fills a session's context window by tool type and message category. It uses NumTokensPreceding to track context growth and attributes token deltas to the preceding content.
func CacheDonut ¶
CacheDonut renders an ASCII donut/bar chart of cache hit vs miss. Uses █ for hit portion and ░ for miss portion.
func CacheSavingsDetailed ¶
CacheSavingsDetailed computes the cost saved by caching across all sessions, using per-model pricing. Savings = cache_read * (input_price - cache_read_price) per model.
func CacheStatsAggregate ¶
func CacheStatsAggregate(ss []model.Session) model.CacheStats
CacheStatsAggregate computes aggregate cache metrics across all sessions.
func CacheStatsForSession ¶
func CacheStatsForSession(s *model.Session) model.CacheStats
CacheStatsForSession computes cache metrics for a single session.
func ClassifySession ¶
ClassifySession determines the primary task category for a session based on tool usage patterns and message content keywords.
func CompareModels ¶
func CompareModels(ss []model.Session, modelNames []string) model.ModelComparison
CompareModels builds a side-by-side comparison of models. If modelNames is non-empty, only those models are included (fuzzy matched). Otherwise all models are compared.
func DetectCompaction ¶
func DetectCompaction(s *model.Session) []model.CompactionEvent
DetectCompaction scans a session's messages for context compaction events. A compaction is detected when num_tokens_preceding drops significantly between consecutive assistant messages (indicating the context window was compacted/summarized).
The threshold is a drop of more than 30% from the previous value.
func DetectCompactionAll ¶
func DetectCompactionAll(ss []model.Session) []model.CompactionEvent
DetectCompactionAll scans all sessions for compaction events.
func EfficiencyGrade ¶
func EfficiencyGrade(score model.EfficiencyScore) string
EfficiencyGrade maps a composite efficiency score to a letter grade A-F. The score blends cache savings, tokens-per-dollar, and tokens-per-request into a 0-100 numeric score.
func OneShotRateAggregate ¶
func OneShotRateAggregate(ss []model.Session) model.OneShotRate
OneShotRateAggregate computes aggregate one-shot/retry metrics across all sessions, tracking per-file retry counts.
func OneShotRateForSession ¶
func OneShotRateForSession(s *model.Session) model.OneShotRate
OneShotRateForSession computes one-shot/retry metrics for a single session. A retry is detected when the same file_path is edited again after an exec tool call occurred in between (indicating the first edit likely failed or was incomplete).
func TaskCategories ¶
func TaskCategories(ss []model.Session) []model.TaskCategory
TaskCategories classifies all sessions and returns aggregated category stats sorted by count descending.
Types ¶
type CompactionSummary ¶
type CompactionSummary struct {
TotalEvents int
TotalTokensSaved int
AvgDropPct float64
Events []model.CompactionEvent
}
CompactionSummary holds aggregate compaction stats.
func CompactionStats ¶
func CompactionStats(ss []model.Session) CompactionSummary
CompactionStats computes aggregate compaction statistics across sessions.
type ContextBreakdown ¶
type ContextBreakdown struct {
Categories []ContextEntry
Tools []ContextEntry
Total int64
}
ContextBreakdown returns sorted category and tool breakdowns for display.
func ContextBreakdownForSession ¶
func ContextBreakdownForSession(s *model.Session) ContextBreakdown
ContextBreakdownForSession returns a sorted, display-ready context breakdown.
type ContextEntry ¶
ContextEntry is a single entry in the context breakdown.
type EfficiencyMetrics ¶
type EfficiencyMetrics struct {
Score model.EfficiencyScore
Grade string
OutputVerbosity float64
TokensPerMin float64
CodeRatio float64
TotalCost float64
TotalRequests int
TotalOutput int64
TotalInput int64
}
EfficiencyMetrics holds the composite efficiency score plus supporting productivity metrics for display.
func ComputeEfficiency ¶
func ComputeEfficiency(ss []model.Session) EfficiencyMetrics
ComputeEfficiency computes the composite token efficiency score and supporting productivity metrics across all sessions.