Skip to content

📂 refactor: split chart.go / cache.go / main.go by responsibility (pure code motion) #428

@martinciu

Description

@martinciu

🔍 Problem

Three files have outgrown their responsibilities. All three splits are pure code motion — no logic changes.

pkg/tui/chart.go (1333 lines, five responsibilities):

  • ZoomLevel + time↔column geometry (lines ~19-220)
  • Skyline-morph rasterization/drawing (~239-348)
  • Nice-number math + value formatting — formatTokenCount/formatUnitValue/formatBarValue/groupThousands/compactSig3/... (~394-468, 812-1011) — three number-formatting families living 400 lines apart is how their precision rules drifted into needing 📊 tui: higher-precision number formatting on 24h bars (fill the bar width) #324
  • Label overlays — x-labels, y-labels, in-bar labels, y-ticks (~498-779, 1275-1333)
  • The two chart builders (~1013-1273)

pkg/cache/cache.go (997 lines, four responsibilities): DB lifecycle (55-248, 651-663), usage-samples write/read (250-471, 964-997), message/cursor ingest (473-649), bucket aggregation (665-944). The package already set the precedent with recost.go / projects.go / lock.go — cache.go just never got the same treatment; new methods get appended wherever (e.g. EarliestMessageTime at 946 sits between zoomLabel and the warn-once machinery).

cmd/ccpulse/main.go (554 lines): status/index/doctor/recost each get their own file, but the config and version commands (with three inline anonymous subcommands + ensureConfigFile, main.go:117-195), the quota poller, backfill, and cache-rebuild helpers all live in main.go.

🛠️ Suggested shape

  • pkg/tui: split into format.go (number formatting), geometry.go (ZoomLevel, columnToTime/timeToColumn/bucketCountInRange/computeSpringSlice), labels.go (overlay*/splice/buildXLabelsRow/crossfadeLabelRow), skyline.go (rasterize/draw, pairs with zoomspring.go); chart.go keeps buildChart/buildLineChart
  • pkg/cache: split into usage_samples.go, buckets.go, ingest.go; lifecycle stays in cache.go
  • cmd/ccpulse: split out config.go and version.go command files; move runTUI + helpers to tui.go; main.go keeps main(), newRootCmd, globals

⚠️ Notes

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestgoPull requests that update go codeimportance: lowPolish, refactor, or nice-to-havesize: mMedium — 1 to 3 hourstuiTUI rendering, layout, or interaction

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions