feat: per-plugin cost trend + threshold warnings (closes #201)#500
Merged
vivekchand merged 1 commit intomainfrom Apr 2, 2026
Merged
feat: per-plugin cost trend + threshold warnings (closes #201)#500vivekchand merged 1 commit intomainfrom
vivekchand merged 1 commit intomainfrom
Conversation
- Track per-day plugin token/cost breakdown in _compute_transcript_analytics - Add _compute_plugin_trend() helper: compares recent 7d vs prior 7d cost share and returns 'increasing' / 'decreasing' / 'stable' - Enhance GET /api/usage/by-plugin: each row now includes a trend field; warnings[] array emitted when plugin cost share exceeds threshold (default 50%) - New GET /api/usage/by-plugin/trend?days=N: returns daily time-series for all plugins in the requested window (default 14 days, max 90) enabling frontend charts and 'which plugins are getting more expensive?' analysis - 6 new tests covering both endpoints and threshold/trend fields
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #201
What
Extends the existing per-plugin cost attribution with the two missing sub-features from GH#201:
How
New:
_compute_plugin_trend(plugin, plugin_daily_stats)Computes trend direction (
increasing/decreasing/stable) for a given plugin by comparing its average daily cost-share % in the last 7 days vs the prior 7 days. A >20% relative delta is flagged as increasing or decreasing.Enhanced:
GET /api/usage/by-pluginEach plugin row now includes a
trendfield. Awarningsarray is emitted listing any plugins whose cost share exceeds the threshold (default 50%, configurable via?threshold=N).New:
GET /api/usage/by-plugin/trend?days=14Returns a per-day time-series for every plugin in the requested window (1–90 days). Shape:
{ "days": ["2026-03-20", ...], "plugins": { "exec": [{"day": "2026-03-20", "tokens": 120, "cost_usd": 0.001, "calls": 3}, ...], ... } }This powers frontend trend charts without any additional backend work.
Data collection
_compute_transcript_analyticsnow builds aplugin_daily_statsdict (day → plugin → {tokens, cost, calls}) alongside the existing aggregateplugin_stats.Tests
6 new tests in
TestPluginTrend:test_by_plugin_returns_200test_by_plugin_structure— verifiesplugins+warningskeystest_by_plugin_row_has_trend— verifies trend is one of valid valuestest_by_plugin_trend_endpoint_returns_200test_by_plugin_trend_structuretest_by_plugin_trend_days_param— verifies?days=7returns exactly 7 days