Overview
The file pkg/cli/token_usage.go has grown to 1,141 lines, making it difficult to maintain and test. This task involves refactoring it into smaller, focused files with improved test coverage.
Current State
- File:
pkg/cli/token_usage.go
- Size: 1,141 lines
- Test file:
pkg/cli/token_usage_test.go (782 lines, ratio ~0.69)
- Functions: 31 functions across 10 structs
- Complexity: Mixed concerns — file discovery, parsing, analysis, steering events, sub-agent attribution
Proposed File Splits
token_usage_types.go — all structs, constants, package-level vars (~120 LOC)
token_usage_find.go — findTokenUsageFile, findAgentUsageFile, findUsageJSONLFiles, findAPIProxyEventsFile, findAgentStdioFile (~120 LOC)
token_usage_parse.go — parseTokenUsageFile, parseAgentUsageFile, record extraction helpers (~280 LOC)
token_usage_analyze.go — analyzeTokenUsage, analyzeTokenUsageAICOnly, extractAmbientContextMetrics, populateAIC, TokenUsageSummary methods (~350 LOC)
token_usage_steering.go — countAPIProxySteeringEvents, scanSteeringEntries, isSteeringEvent, proxyEventsEntry (~130 LOC)
token_usage_subagent.go — augmentSubagentModelAttribution, addTokenUsageWarning, extractSubagentModelRequests (~200 LOC)
Acceptance Criteria
Priority: Medium | Effort: Medium | Expected Impact: Improved maintainability and testability
Generated by 🧹 Daily File Diet · sonnet46 · 67.5 AIC · ⌖ 9.41 AIC · ⊞ 6.9K · ◷
Overview
The file
pkg/cli/token_usage.gohas grown to 1,141 lines, making it difficult to maintain and test. This task involves refactoring it into smaller, focused files with improved test coverage.Current State
pkg/cli/token_usage.gopkg/cli/token_usage_test.go(782 lines, ratio ~0.69)Proposed File Splits
token_usage_types.go— all structs, constants, package-level vars (~120 LOC)token_usage_find.go— findTokenUsageFile, findAgentUsageFile, findUsageJSONLFiles, findAPIProxyEventsFile, findAgentStdioFile (~120 LOC)token_usage_parse.go— parseTokenUsageFile, parseAgentUsageFile, record extraction helpers (~280 LOC)token_usage_analyze.go— analyzeTokenUsage, analyzeTokenUsageAICOnly, extractAmbientContextMetrics, populateAIC, TokenUsageSummary methods (~350 LOC)token_usage_steering.go— countAPIProxySteeringEvents, scanSteeringEntries, isSteeringEvent, proxyEventsEntry (~130 LOC)token_usage_subagent.go— augmentSubagentModelAttribution, addTokenUsageWarning, extractSubagentModelRequests (~200 LOC)Acceptance Criteria
make test-unit)make lint) and build (make build)Priority: Medium | Effort: Medium | Expected Impact: Improved maintainability and testability