Commit Graph
16 Commits
Author SHA1 Message Date
Eric Traut 13a966fc65 Honor the system clock preference across more TUI timestamps (#47321)
## Why

Several TUI views hard-code 24-hour timestamps even when the detected system preference is 12-hour time.

## What changed

Use the existing `ClockFormat` preference for rate-limit and spend-control reset times, usage notices, backend banners, reset-credit expiration times, analytics timestamps, and expanded session details in the resume picker. Capture the preference when constructing views and preserve existing timezone handling, including analytics' UTC labels.

## Testing

Add coverage for midnight, noon, and next-day reset labels in both clock formats, plus 12-hour analytics rendering with UTC labels. Update snapshots for status, banners, usage notices, reset-credit details, and expanded sessions, including narrow-width layouts. Pin test fixtures to explicit clock formats for deterministic output.

GitOrigin-RevId: 73c36d603ddc4eb7800614650a14c6f2961f8b70
2026-09-22 16:23:59 +00:00
Eric Traut b48232f975 Enable mouse navigation in the TUI usage view (#46866)
## What changed

- Enable mouse input for the usage overlay, with clickable tabs and report controls that invoke the same actions as keyboard shortcuts.
- Scroll the report, dashboard, or help body with the mouse wheel in bounded three-line steps, preserving separate reading positions.
- Limit clicks to rendered targets and ignore stale targets after refreshes, control changes, or surface transitions.

## Testing

Add coverage for mouse event routing, clipped targets, remapped or disabled keybindings, stale targets, bounded scrolling, and retained reading positions. Exercise the business token model filter through a mouse click.

GitOrigin-RevId: be839695d46609b6df7062f99711701372335907
2026-09-20 18:26:14 +00:00
Eric Traut d6d43270bd Improve usage report layouts and preserve reading positions (#46864)
## Why

Switching reports reset their scroll positions, and resizing could pull users back to a selection they had deliberately scrolled away from. Small terminals also need room for usage details, while larger terminals can show more of the chart.

## What changed

- Retain independent scroll positions for each report, the dashboard, and help. Keep visible selections on screen during resizing while respecting manual scrolling.
- Hide plots in small report areas, expand charts to use available height, and place breakdown tables beside plots in wide focused reports.
- Highlight selected chat and plan rows with the shared picker style, preserving padding after wrapping.
- Show dated plan periods in the dashboard and collapse expanded plan details before closing with `Esc`.

## Testing

Add regression tests and snapshots for responsive layouts, reading-position restoration across tabs and help, selection visibility during resizing, and highlighted chat-row padding.

GitOrigin-RevId: e18a472ff4356324fed71e496f47762a7ccf657d
2026-09-20 18:18:42 +00:00
Eric Traut 46f7d99d0e Stabilize usage dashboard navigation and add keyboard help (#46863)
## Why

Wrapping navigation and contextual hints can shift report content as the displayed state changes, especially on narrow terminals.

## What changed

- Use compact report tabs, fixed control rows, and two footer hint rows to keep report geometry stable.
- Show the account plan in the `Usage` heading and move date ranges, grouping, model filters, sort controls, and update timestamps above reports.
- Add scrollable `?` help with an independent scroll position, preserving report selection, expanded details, and reading position when dismissed.
- Share control availability between keyboard actions and help, and preserve configured keybindings when they conflict with the help shortcut.

## Testing

Add regression coverage for stable tabs after request failures, help state preservation, dashboard selection scrolling, date and update-time controls, and custom keybinding precedence. Update layout snapshots for the revised navigation and narrow help view.

GitOrigin-RevId: ab89ed2fd346171362f487c64af7206d9123859a
2026-09-20 18:18:19 +00:00
Felipe Coury b1f3c2f77e Expose experimental analytics plan history and improve navigation (#45772)
## What changed

- Expose `analytics_plan_history` in the experimental features menu for previewing consumer five-hour and weekly allowance history in `/analytics`. Keep it disabled by default.
- Add `h` and `l` as left/right navigation aliases in analytics, preserving explicit bindings and honoring remapped or unbound arrows.
- Use terminal-aware footer key colors to keep analytics shortcuts readable on light backgrounds.

## Testing

Add navigation tests for arrow equivalence, custom bindings, modifiers, and key repeat. Extend light-background contrast assertions and update style snapshots. Add a snapshot for the plan history experimental feature entry.

GitOrigin-RevId: 310e64a43a7dd08c8a3fd1efed6985805f7dd580
2026-09-15 19:19:50 +00:00
Felipe Coury de40696ec4 Improve analytics chart readability and navigation (#45770)
## Why

Reading daily totals required selecting each bar, and changing grouping required opening a picker. Section navigation could shift vertically, while scroll hints appeared even when content fit.

## What changed

- Make `g` cycle through available groupings and summary views directly.
- Show daily totals on charts spanning up to seven days when space permits, prioritizing the selected value and keeping neighboring labels separate.
- Keep section navigation at a stable height, show more legend rows in taller maximized reports, and move their update timestamp into the footer.
- Hide scroll hints when content fits, including an exact fit, and show only the active summary view label.

## Testing

Add regression tests and snapshots for seven-day totals, narrow label spacing, grouping wraparound and server capabilities, configured `g` navigation in ungrouped sections, stable tab placement, adaptive legends, footer timestamps, and overflow-dependent scroll hints.

GitOrigin-RevId: 9d14f314b4a22ca2d926f0e69c6b89e4f9c8550d
2026-09-15 19:13:32 +00:00
Felipe Coury 9bd49c9dcc Add an account Summary tab to Analytics (#45769)
## What changed

- Make Summary the initial Analytics tab, showing profile identity, token totals, streaks, activity insights, and most-used plugins and skills.
- Move daily, weekly, and cumulative token activity charts into Summary. Replace the usage menu's separate views with “View analytics”; `/usage weekly` and the other explicit modes open Summary with the requested view, while reopening from the menu retains navigation.
- Load account profiles independently of other reports, preserve missing values separately from zero, and reject responses when the active account changes. Refresh retries profile failures.
- Adapt Summary to narrow terminals and compact large chart totals and axis labels. Show the account email without its ID in the Analytics header.
- Flush queued transcript history before opening an overlay so startup output stays in the transcript.

## Testing

Add profile decoding and account identity tests, Summary layout and navigation snapshots, refresh and cancellation coverage, and regression tests for retained navigation and transcript history when opening Analytics.

GitOrigin-RevId: 6dbe6c4c98209000d8b4bc18a4e01b98fab5991a
2026-09-15 19:13:08 +00:00
Felipe Coury 8f0d2459ac Add consumer Top chats usage analytics (#45768)
## Why

Consumer analytics lacked a per-chat view of allowance usage and balance credit debits.

## What changed

- Add a Top chats panel for up to 100 local chats active in the past 30 days, including discovered descendants and excluding archived roots.
- Show weekly and five-hour usage as percentages of current full limits, plus balance credits including adjustments. Preserve exact credit decimals and distinguish missing values from zero.
- Support cycling sort metrics with `s`, a top-five dashboard summary, and expandable model, reasoning effort, and speed breakdowns.
- Query task usage through `query_v2` with bounded, disjoint descendant groups. Retain partial and unavailable rows, hide titles when usage is unavailable, and report ranking coverage and freshness.

## Testing

Add backend and TUI tests covering decimal precision, request and response validation, paginated archived descendants, unavailable responses, metric selection, title hiding, and top-five rendering.

GitOrigin-RevId: b8f233166576389c8212bb97eceb7c6be7f5f51d
2026-09-15 19:12:44 +00:00
Felipe Coury 0d0979f457 Add gated plan usage history to TUI analytics (#45766)
## What changed

- Add consumer plan usage history behind `analytics_plan_history`, disabled by default, fetching seven days of five-hour and weekly allowance periods.
- Show period usage percentages with expandable breakdowns by feature, model, surface, or turn start, plus snapshot freshness and incomplete coverage indicators.
- Preserve unknown usage separately from zero and handle an unavailable history endpoint without blocking other analytics reports.

## Testing

Add backend and TUI tests for unavailable endpoints, response validation, feature and account gating, account changes during requests, period navigation, snapshot resets, and narrow and wide layouts.

GitOrigin-RevId: 7bea87a3407730b18040d7dda7e7dd0afe67fb2e
2026-09-15 19:12:18 +00:00
Felipe Coury 0e7ab7c1b5 Add Top chats to usage analytics (#45765)
## What changed

- Show local chats active in the past 30 days, ranked by estimated lifetime credits, for supported Business and Enterprise plans. Exclude archived chats and subagents.
- Add expandable model, reasoning effort, and speed breakdowns, optional zero-credit groups, and dollar estimates when supplied by the backend.
- Load estimates in bounded batches of up to 100 distinct threads, retaining available results when some estimates are unavailable. Hide chat titles without a returned estimate and distinguish missing usage from zero.

## Testing

Add coverage for batch validation, partial failures, request limits, pagination and ranking, plan eligibility, title visibility, and responsive table navigation and details.

GitOrigin-RevId: 783b960a780f4e0fd39f57e2fa78fb31b3090c44
2026-09-15 19:07:03 +00:00
Felipe Coury ca53e19c75 Add an account analytics dashboard to /usage (#45764)
## What changed

- Add “Explore analytics” to the `/usage` menu for ChatGPT accounts, opening a full-screen dashboard.
- Show usage and messages for consumer accounts, credits and token usage for Business and Enterprise accounts, and plugin and skill activity for both.
- Support overview and maximized views, 7- and 30-day ranges, report grouping, daily details, model filtering for token usage, and refresh.
- Keep report loading and errors independent, cancel pending loads on close, and retain navigation state across reopening while preserving the composer draft.

## Testing

Add regression and snapshot coverage for account-specific reports, range and grouping changes, model filtering, loading and cancellation, small terminals, terminal colors, and draft preservation.

GitOrigin-RevId: 46da94a14d6e227551e740b85f9d2d552aaf75b0
2026-09-15 19:01:41 +00:00
Felipe Coury af3bc6f796 Add stacked chart primitives for account analytics (#45763)
## What changed

Add daily stacked bar rendering in the TUI analytics module, staged for dashboard integration.

- Plot three categories plus an Other remainder without renormalizing values, with separate positive and negative bands for signed credits.
- Add readable numeric axes, calendar ticks, a selection cursor, and a callout showing the authoritative daily total. Distinguish missing days from zero usage.
- Keep the selection visible in narrow viewports and omit labels that cannot fit without truncation.
- Use terminal palette colors for series and adapt secondary text to terminal color support and background.

## Testing

Add unit and snapshot coverage for axis scaling, signed bars on light and dark terminals, missing and zero values, narrow layouts, tiny segments, authoritative totals, and duplicate-date remainders.

GitOrigin-RevId: 2ed58def17abd14e77929016a54fd20e91d45670
2026-09-15 19:01:18 +00:00
Felipe Coury 1fc46a532b Load analytics reports with server plans and account identity checks (#45762)
## Why

Token plan claims can be stale, and the active account or user can change while a request is in flight. Analytics report selection and account-bound response data need to reflect the verified identity and current server plan.

## What changed

- Fetch the active account's plan once per analytics session and use it to select report endpoints and supported credit breakdowns.
- Add report loading with a fixed end date, account-scoped response caching, and token model filtering. Reuse payloads across grouping changes and evict invalid cached responses so requests can retry.
- Prefer complete attribution for usage breakdowns within the requested range; retain legacy surface/model data when attribution is incomplete and include all features in turn-start breakdowns.
- Add cancellable report-loading state with timeout and interruption errors, and preserve actionable sign-in and retry messages.
- Recheck the active identity after rate-limit reads before exposing account-bound fields.

## Testing

Add regression tests for server plan discovery, report routing and caching, model filtering, attribution fallback, failed-request retries, load cancellation, authentication recovery, and account or user changes during requests.

GitOrigin-RevId: 45c4c09f108c9703893f3ed15613437ebd7c74a8
2026-09-15 19:00:56 +00:00
Felipe Coury db078158c3 Add account-bound authentication for analytics requests (#45742)
## What changed

- Add `AnalyticsSession` to load local ChatGPT credentials, bind requests to the initial account and user, and reject identity changes before requests or when accepting results.
- Reload credentials and provide bounded recovery for unauthorized requests, using a backend client that disables redirects.
- Add lazy TUI analytics session initialization, account display metadata, and plan-specific credit groupings for future dashboard integration.

## Testing

Add regression tests for account and user changes, missing or API-key-only authentication, credential reloads, recovery after a `401` response, and session initialization after signing in.

GitOrigin-RevId: 2ba0d96fb44936d12d13aedffc3f2e61aedea560
2026-09-15 17:38:43 +00:00
Felipe Coury 7224096b85 Add token history and credit formatting helpers for analytics (#45741)
## What changed

- Add daily text token history grouped by model or token type, with date-range and model filtering, freshness metadata, and validation of token counts. Support both grouped and per-model report data, including reported model totals when components are unavailable.
- Add credit formatting helpers that preserve tiny signed adjustments and format integer millionths without floating-point rounding, plus a short date formatter.

## Testing

Add unit tests for token groupings, model filtering, freshness, missing components, explicit zero totals, and credit formatting across tiny refunds and integer limits.

GitOrigin-RevId: 706dcae7995e46707c2f1df9cdf3e06966459dd6
2026-09-15 17:33:25 +00:00
Felipe Coury 1fd5399004 Add account analytics data normalization to the TUI (#45740)
## What changed

Add display models and adapters from typed backend responses for usage, credits, messages, plugins, and skills. Normalize reports into daily histories with grouping labels, units, and freshness timestamps.

Preserve missing values, signed credit adjustments, and full daily totals when grouping usage by task start. Account for unassigned message counts as `Other`, merge duplicate dates, and fill unreported days only for credit reports. Group models contributing less than 1% of relative usage into `Other`.

This adds the data preparation layer for dashboard integration; it is not yet connected to `/usage`.

## Testing

Add unit tests covering missing versus explicit zero values, signed credits, enterprise labels and freshness, usage grouping, duplicate-date message remainders, and unsupported message groupings.

GitOrigin-RevId: 931f46a9a6521b4cda2fc26051e7a305cbf6fa6c
2026-09-15 17:32:58 +00:00