You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
pkg/status runs raw SQL against the cache's messages schema, duplicating knowledge that pkg/cache owns:
🪦 tsFormat re-declared at pkg/status/periods.go:14 (identical to pkg/cache/cache.go:24-28); literal layout strings again at pkg/status/compute.go:30 and compute.go:93
🪦 Raw messages-table SQL outside pkg/cache: pkg/status/compute.go:31-40, pkg/status/periods.go:24-52, pkg/status/throughput.go:32-37
🪦 Awkward round-trip: callers hold a *cache.Cache, unwrap with c.DB() to call status, which re-wraps via cache.NewFromDB(db) (pkg/status/compute.go:107) just to call SevenDaySamplesSince. Call sites: cmd/ccpulse/status.go:76,84,90, pkg/tui/model.go:978
🪦 The "headline tokens = input + output" business rule is encoded independently in 5 SQL strings + Go across two packages (pkg/cache/cache.go:720, cache.go:838, pkg/cache/projects.go:33, pkg/status/throughput.go:34, pkg/status/periods.go, pkg/status/compute.go:54) — and 🧮 Align token counts with Claude Code /usage (input + output, no cache) #232 already changed that definition once
Column names, ts layout, and the headline-token definition must change in two packages in lockstep today. Cache.DB() exists almost solely to feed status, defeating the encapsulation pkg/cache otherwise maintains.
🛠️ Suggested shape
Move the three aggregate queries into pkg/cache as methods (e.g. FiveHourTotals, PeriodTotals, ThroughputTotals); have status.Compute* accept *cache.Cache (or a 3-method interface); delete the duplicated tsFormat and the DB()/NewFromDB round-trip.
⚠️ Notes
Mechanical move; both packages are well-tested, but status_test.go seeds via raw SQL and would move/change too (overlaps with the test-fixture consolidation candidate — coordinate if both land).
🔍 Problem
pkg/statusruns raw SQL against the cache'smessagesschema, duplicating knowledge thatpkg/cacheowns:tsFormatre-declared atpkg/status/periods.go:14(identical topkg/cache/cache.go:24-28); literal layout strings again atpkg/status/compute.go:30andcompute.go:93messages-table SQL outside pkg/cache:pkg/status/compute.go:31-40,pkg/status/periods.go:24-52,pkg/status/throughput.go:32-37*cache.Cache, unwrap withc.DB()to call status, which re-wraps viacache.NewFromDB(db)(pkg/status/compute.go:107) just to callSevenDaySamplesSince. Call sites:cmd/ccpulse/status.go:76,84,90,pkg/tui/model.go:978pkg/cache/cache.go:720,cache.go:838,pkg/cache/projects.go:33,pkg/status/throughput.go:34,pkg/status/periods.go,pkg/status/compute.go:54) — and 🧮 Align token counts with Claude Code /usage (input + output, no cache) #232 already changed that definition onceColumn names, ts layout, and the headline-token definition must change in two packages in lockstep today.
Cache.DB()exists almost solely to feed status, defeating the encapsulation pkg/cache otherwise maintains.🛠️ Suggested shape
Move the three aggregate queries into
pkg/cacheas methods (e.g.FiveHourTotals,PeriodTotals,ThroughputTotals); havestatus.Compute*accept*cache.Cache(or a 3-method interface); delete the duplicatedtsFormatand theDB()/NewFromDBround-trip.status_test.goseeds via raw SQL and would move/change too (overlaps with the test-fixture consolidation candidate — coordinate if both land).