Commit Graph

10 Commits

Author SHA1 Message Date
teernisse
9b1554d72c fix: sort top-spending days by date after cost-based limiting
The top-spending-days card first sorts all days by cost descending to
find the N highest-cost days, then was iterating over the full sorted
slice instead of the limited subset. Additionally, the limited days
appeared in cost order rather than chronological order, making the
timeline hard to scan.

Fix: after slicing to the top N, re-sort that subset by date
(most recent first) before rendering, and iterate over the correct
limited slice.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-23 09:37:05 -05:00
teernisse
4c649610c9 feat: add live activity charts to TUI overview tab
Add a new "Row 2.5" to the overview tab between the trend chart and
model/activity panels, showing two side-by-side live activity charts:

- Today: 24-bar hourly token histogram with 12h-format labels
  (12a, 1a, ... 11p). Header shows total tokens consumed today.

- Last Hour: 12-bar five-minute token histogram with relative-time
  labels (-55, -50, ... -5, now). Header shows tokens in the last
  60 minutes.

Both charts use BarChart with theme-colored bars (Blue for today,
Accent for last hour) and adapt height in compact layouts.

Helper functions hourLabels24() and minuteLabels() generate the
X-axis label arrays.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-23 09:36:59 -05:00
teernisse
93e343f657 feat: add TUI auto-refresh with configurable interval and manual refresh
Introduce background data refresh so the dashboard stays current without
restarting. This touches four layers:

Config (config.go):
- New TUIConfig struct with AutoRefresh (bool) and RefreshIntervalSec
  (int) fields, defaulting to enabled at 30-second intervals.
- Minimum interval floor of 10 seconds enforced at load time.

App core (app.go):
- RefreshDataMsg type for background refresh completion signaling.
- Auto-refresh state: interval timer, refreshing flag, lastRefresh
  timestamp. Checked on every tick; fires refreshDataCmd when elapsed.
- refreshDataCmd: background goroutine that loads session data via cache
  (with uncached fallback) and posts RefreshDataMsg on completion.
- Manual refresh keybind: 'r' triggers immediate refresh.
- Auto-refresh toggle keybind: 'R' toggles auto-refresh and persists
  the preference to config.toml.
- Help text updated with r/R keybind documentation.

Status bar (statusbar.go):
- Shows spinning refresh indicator during active refresh.
- Shows auto-refresh icon when auto-refresh is enabled.

Settings tab (tab_settings.go):
- Two new editable fields: Auto Refresh (bool) and Refresh Interval
  (seconds with 10s minimum).
- Settings display reads live App state to stay consistent with the
  R toggle keybind (avoids stale config-file reads).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-23 09:36:50 -05:00
teernisse
35fae37ba4 feat: overhaul TUI dashboard with subscription data, new tabs, and setup wizard
Major rewrite of the Bubble Tea dashboard, adding live claude.ai
integration and splitting the monolithic app.go into focused tab modules.

App model (app.go):
- Integrate claudeai.Client for live subscription/rate-limit data
- Add SubDataMsg and async fetch with periodic refresh (every 5 min)
- Add spinner for loading states (charmbracelet/bubbles spinner)
- Integrate huh form library for in-TUI setup wizard
- Rework tab routing to dispatch to dedicated tab renderers
- Add compact layout detection for narrow terminals (<100 cols)

TUI setup wizard (setup.go):
- Full huh-based setup flow embedded in the TUI (not just CLI)
- Three-step form: credentials, preferences (time range + theme), confirm
- Pre-populates from existing config, validates session key prefix
- Returns to dashboard on completion with config auto-saved

New tab modules:
- tab_overview.go: summary cards (sessions, prompts, cost, time), daily
  activity sparkline, rate-limit progress bars from live subscription data
- tab_breakdown.go: per-model usage table with calls, input/output tokens,
  cost, and share percentage; compact mode for narrow terminals
- tab_costs.go: cost analysis with daily cost chart, model cost breakdown,
  cache efficiency metrics, and budget tracking with progress bar

Rewritten tabs:
- tab_sessions.go: paginated session browser with sort-by-cost/tokens/time,
  per-session detail view, model usage breakdown per session, improved
  navigation (j/k, enter/esc, n/p for pages)
- tab_settings.go: updated to work with new theme struct and config fields
2026-02-20 16:08:26 -05:00
teernisse
2be7b5e193 refactor: simplify TUI theme struct and extract chart/progress components
Theme simplification (theme/theme.go):
- Remove Purple and BorderHover fields from Theme struct — neither was
  referenced in the new tab renderers, reducing per-theme boilerplate
  from 14 to 12 color definitions

Component extraction (components/):
- Move Sparkline() and BarChart() from card.go to new chart.go, giving
  visualization components their own file as complexity grows
- card.go retains MetricCard, ContentCard, LayoutRow, and CardInnerWidth
  which are layout-focused
- New chart.go: Sparkline (unicode block chars) and BarChart (multi-row
  with anchored Y-axis, optional X-axis labels, dynamic height/width)
- New progress.go: ProgressBar component with customizable width, color,
  and percentage display — used by rate-limit and budget views

Status bar and tab bar updates:
- statusbar.go: adapt to simplified theme struct
- tabbar.go: adapt to simplified theme struct
2026-02-20 16:08:06 -05:00
teernisse
a04a0065a0 feat: add root TUI app model with 10-tab dashboard and async data loading
Add the core App Bubble Tea model that orchestrates the entire TUI
dashboard. The model manages:

- 10 navigable tabs: Dashboard, Costs, Sessions, Models, Projects,
  Trends, Efficiency, Activity, Budget, and Settings. Each tab is
  accessible via single-key shortcuts (d/c/s/m/p/t/e/a/b/x) or
  left/right arrows for sequential navigation.

- Async data pipeline: launches the JSONL loader in a goroutine and
  receives progress updates via a channel subscription, displaying
  an animated loading screen with a spinner and file count. Data
  loads once on startup and recomputes aggregates when filters change.

- Filter state: supports configurable time range (7/30/90 days),
  project filter, and model filter. Changing any filter triggers
  recomputation of all derived stats (summary, daily, model, project
  breakdowns) including a comparison period for delta calculations.

- First-run detection: if no config file exists when data finishes
  loading, automatically enters the setup wizard flow before showing
  the dashboard.

- Tab-specific rendering: Dashboard shows metric cards with period-
  over-period deltas, daily token/cost bar charts, model pie-style
  breakdown, and top projects. Costs shows a per-model cost table.
  Trends renders daily tokens, cost, and session bar charts.
  Efficiency shows cache hit rate and savings metrics. Activity
  renders an hourly heatmap. Budget tracks spend against plan limits
  with a burn-rate projection chart.

- Help overlay: toggleable help panel listing all keyboard shortcuts,
  rendered as a centered overlay above the active tab content.
2026-02-19 15:38:43 -05:00
teernisse
b69b24c107 feat: add TUI feature modules for setup wizard, session browser, and settings
Add three self-contained feature modules that plug into the root App
model via shared state structs and render methods.

setup.go -- First-run wizard with a 5-step flow: welcome screen, API
key entry (password-masked text input), default time range selector
(radio-style j/k navigation over 7/30/90 day options), theme picker
(radio-style over all registered themes), and a completion screen
that persists choices to ~/.config/cburn/config.toml. Gracefully
handles save failures by noting the settings apply for the current
session only.

tab_sessions.go -- Session browser with two view modes: split view
(1/3 condensed list + 2/3 detail pane, scrollable with offset
tracking) and full-screen detail. The detail body shows duration,
prompt/API-call ratio, per-type token breakdown with cache cost
attribution, per-model API call table, and subagent indicator.

tab_settings.go -- Runtime settings editor with 4 configurable
fields (API key, theme, default days, monthly budget). Supports
inline text input editing with Enter/Esc save/cancel flow, immediate
config persistence, flash "Saved!" confirmation, and error display
on save failure. Theme changes apply instantly without restart.
2026-02-19 15:01:47 -05:00
teernisse
4d46977328 feat: expand component library with bar chart, content cards, and layout helpers
Add BarChart component that renders multi-row Unicode bar charts with
anchored Y-axis labels, automatic tick-step computation, sub-sampling
for narrow terminals, and optional X-axis date labels. The chart
gracefully degrades to a sparkline when width/height is too small.

Add ContentCard, CardRow, and CardInnerWidth utilities for consistent
bordered card layout across all dashboard tabs. ContentCard renders
a lipgloss-bordered card with optional bold title; CardRow joins
pre-rendered cards horizontally; CardInnerWidth computes the usable
text width after accounting for border and padding.

Add LayoutRow helper that distributes a total width into n integer
widths that sum exactly, absorbing the integer-division remainder
into the first items -- eliminates off-by-one pixel drift in multi-
column layouts.

Refactor MetricCard to accept an outerWidth parameter and derive the
content width internally by subtracting border, replacing the old
raw-width parameter that required callers to do the subtraction.
MetricCardRow now uses LayoutRow for exact width distribution.

Refine TabBar to render all tabs on a single row when they fit within
the terminal width, falling back to the two-row layout only when
they overflow.

Simplify StatusBar by removing the unused filterInfo append that was
cluttering the left section.
2026-02-19 15:01:26 -05:00
teernisse
79ab17488e feat: add TUI reusable components: metric cards, sparklines, tab bar, and status bar
Implement shared UI components used across the dashboard tabs:

- tui/components/card.go: Three components:

  * MetricCard: bordered card with label (muted), value (bold), and
    optional delta (dim) — used for the dashboard's top-level KPIs.

  * MetricCardRow: renders N cards side-by-side using lipgloss
    horizontal join, auto-calculating card width from available space.

  * Sparkline: theme-colored Unicode block sparkline (8-level,
    auto-scaled to series max). Used in Dashboard and Trends tabs.

  * ProgressBar: filled/empty bar (accent + dim) with percentage
    label. Used in the Budget tab for plan-relative spend.

- tui/components/statusbar.go: Bottom status bar with left-aligned
  keybinding hints ([f]ilter [?]help [q]uit), current filter info,
  and right-aligned data age indicator. Padding auto-fills to
  terminal width.

- tui/components/tabbar.go: 10-tab navigation bar split across two
  rows (Dashboard/Costs/Sessions/Models/Projects on row 1,
  Trends/Efficiency/Activity/Budget/Settings on row 2). Each
  inactive tab highlights its keyboard shortcut letter with [bracket]
  notation. Active tab renders in accent color. Settings uses 'x'
  as its shortcut (not present in the name, so appended). TabIdxByKey
  maps key presses to tab indices.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-19 13:02:59 -05:00
teernisse
253776ffd5 feat: add TUI theme system with four color palettes
Implement the theming layer for the interactive dashboard:

- tui/theme/theme.go: Theme struct with 14 semantic color roles
  (Background, Surface, Border, BorderHover, TextDim, TextMuted,
  TextPrimary, Accent, Green, Orange, Red, Blue, Purple, Yellow).
  Four built-in themes:

  * Flexoki Dark (default): warm, low-contrast palette designed for
    extended reading. Teal accent (#3AA99F) on near-black background.

  * Catppuccin Mocha: pastel warm tones with blue accent (#89B4FA)
    on dark surface (#1E1E2E).

  * Tokyo Night: cool blue/purple palette with blue accent (#7AA2F7)
    on deep navy (#1A1B26).

  * Terminal: ANSI 16-color only for maximum compatibility — maps
    all roles to standard terminal colors (0-15), works correctly
    in any terminal emulator regardless of true-color support.

  Global Active variable holds the current theme. SetActive/ByName
  enable runtime theme switching from the settings tab and setup
  wizard.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-19 13:02:45 -05:00