analytics

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jul 9, 2026 License: MIT Imports: 15 Imported by: 0

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

View Source
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

func CacheDonut(hitRatio float64, width int) string

CacheDonut renders an ASCII donut/bar chart of cache hit vs miss. Uses █ for hit portion and ░ for miss portion.

func CacheSavingsDetailed

func CacheSavingsDetailed(ss []model.Session) float64

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

func ClassifySession(s *model.Session) string

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.

func WasteScan

func WasteScan(ss []model.Session) []model.WasteFinding

WasteScan analyzes sessions for waste patterns and returns optimization findings with copy-pasteable fix suggestions.

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

type ContextEntry struct {
	Label  string
	Tokens int64
	Pct    float64
}

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.

type FileRetry

type FileRetry struct {
	File    string
	Retries int
}

FileRetry pairs a file path with its retry count.

func RetryRate

func RetryRate(osr model.OneShotRate) (avgRetries float64, topFiles []FileRetry)

RetryRate returns the average retries per edit operation and a sorted list of files with the most retries.

Jump to

Keyboard shortcuts

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