Skip to content

Refactor for maintainability: split TUI and centralize health hints - #19

Merged
pol-cova merged 2 commits into
mainfrom
cursor/maintainability-cleanup-0c24
Jul 24, 2026
Merged

pol-cova merged 2 commits into
mainfrom
cursor/maintainability-cleanup-0c24

Conversation

@pol-cova

Copy link
Copy Markdown
Owner

Summary

Applies the maintainability recommendations from codebase review: smaller focused files, centralized threshold logic, dead code removal, and expanded test coverage.

Changes

Dead code removal

  • Delete unused internal/metrics/types.go (Panel, TimeSeries were never referenced)
  • Remove unused config fields theme and prometheus_presets (presets remain in prometheus.Presets)
  • Fix config test to use valid panel names (processes, docker instead of non-functional overview)

Centralized health & thresholds

  • Use config.Thresholds as the single threshold type via alias in health
  • Add health.ApplyDefaults() and health.HealthyMessage constant
  • Refactor observe ask to use health.HintsWithThresholds and respect observe.yaml thresholds
  • Reuse prometheus.PresetByName for 5xx query text in assistant

TUI split (616-line monolith → 4 files)

  • dashboard.go (239 lines) — Bubble Tea lifecycle, collection, input
  • render.go (173 lines) — bars, sparks, charts, process tables
  • views.go (174 lines) — overview, chart, integration, help, detail views
  • styles.go (12 lines) — lipgloss styles

Collector refactor

  • Split local.Collect() into focused helpers (collectCPUAndMemory, collectNetworkRates, etc.)
  • Reuse processSummary in topProcesses

Performance / clarity

  • Use history.ReadSamples() for hints instead of copying 1800 snapshots every tick
  • Discover Prometheus metrics once at startup
  • Name constants: collectEveryNTicks, rename collector interface to metricsCollector

Tests

  • assistant_test.go — health hint integration, config thresholds, prometheus preset
  • health/defaults_test.go — threshold defaults
  • prometheus/preset_test.go — preset lookup
  • metrics/remote/remote_test.go — snapshot decode and SSH error handling
  • Expanded docker_test.go for unit parsing

Coverage: 36.6% → 39.6% overall; assistant 0% → 91%, remote 0% → 60%

Verification

gofmt -w .
go vet ./...
go test ./...
go build .

Skipped (follow-up)

  • Async metric collection (goroutine + channel) — larger behavioral change
  • Docker polling interval throttle — needs UX decision
  • topProcesses / net.Connections optimization on busy hosts — performance project
  • README update for valid panels config values
Open in Web Open in Cursor 

- Remove dead code: metrics/types.go, unused config Theme and Prometheus fields
- Unify threshold logic via health.ApplyDefaults and config.Thresholds alias
- Route observe ask through health hints and load config thresholds
- Split dashboard.go into dashboard, render, views, and styles files
- Refactor local.Collect into focused helper functions; reuse processSummary
- Avoid copying full metric history when computing dashboard hints
- Discover Prometheus metrics once at startup instead of every tick
- Add tests for assistant, health defaults, prometheus presets, remote, docker

Co-authored-by: Paul Contreras <pol-cova@users.noreply.github.com>
@pol-cova
pol-cova marked this pull request as ready for review July 19, 2026 23:15
Combine the split TUI structure and centralized health hints with main's theme support, prometheus preset querying, and sample history for ask.
@pol-cova
pol-cova merged commit 8fbfe68 into main Jul 24, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants