Codebase intelligence for AI and humans: code health scores, auto-generated docs, git analytics, dead code detection, and architectural decisions via MCP.
Python aicode-complexitycode-healthcode-intelligencecode-qualitydead-codedeveloper-toolsdocumentationgit-analyticsmcpopen-sourcepythonrefactoringstatic-analysistechnical-debt
fix(costs): nano-model pricing + lead the Costs page with agent savings (#422)
Raghav Chamadiyad94dd8a07dc9
diff --git a/.github/assets/savings.png b/.github/assets/savings.pngnew file mode 100644index 000000000..dcb7ccfaeBinary files /dev/null and b/.github/assets/savings.png differdiff --git a/.github/assets/webui.gif b/.github/assets/webui.gifindex d91b66fd5..fece7ce63 100644Binary files a/.github/assets/webui.gif and b/.github/assets/webui.gif differdiff --git a/README.md b/README.mdindex 825992072..9d83e6b96 100644--- a/README.md+++ b/README.md@@ -164,6 +164,11 @@ from distilled output as from raw. Opt-in Claude Code hook rewrites noisycommands automatically (shown for approval); `repowise saved` tracks tokensand dollars saved. Full guide: **[docs/DISTILL.md →](docs/DISTILL.md)**+<div align="center">+<img src=".github/assets/savings.png" alt="repowise Costs dashboard — tokens and dollars saved across distill and MCP tools" width="100%" />+<p align="center"><sub>The <strong>Costs</strong> dashboard tallies both savings surfaces — <code>repowise distill</code> (command output) and the MCP tools (each curated answer replacing the raw file reads it stood in for) — priced at your coding agent's own model. Example shown from a week of heavy local use.</sub></p>+</div>+### 3 · Code health predicts real defectsHealth scores are collected at a historical commit (T0); bug-fixing commits arediff --git a/packages/core/src/repowise/core/generation/cost_tracker.py b/packages/core/src/repowise/core/generation/cost_tracker.pyindex d02c08c3d..4994de761 100644--- a/packages/core/src/repowise/core/generation/cost_tracker.py+++ b/packages/core/src/repowise/core/generation/cost_tracker.py@@ -33,6 +33,11 @@ _PRICING: dict[str, dict[str, float]] = {"gpt-5": {"input": 1.25, "output": 10.0},"gpt-5-codex": {"input": 1.25, "output": 10.0},"gpt-5-mini": {"input": 0.25, "output": 2.0},+ # Nano tier — $0.05/$0.40 per 1M. Without these keys the model name falls+ # through to ``_FALLBACK_PRICING`` (Sonnet $3/$15) and overstates a nano+ # indexing run ~40×.+ "gpt-5-nano": {"input": 0.05, "output": 0.40},+ "gpt-5.4-nano": {"input": 0.05, "output": 0.40},"gpt-4o": {"input": 2.5, "output": 10.0},"gpt-4o-mini": {"input": 0.15, "output": 0.6},# Google Geminidiff --git a/packages/ui/src/costs/distill-savings-card.tsx b/packages/ui/src/costs/distill-savings-card.tsxindex 3875d24bd..912ff6698 100644--- a/packages/ui/src/costs/distill-savings-card.tsx+++ b/packages/ui/src/costs/distill-savings-card.tsx@@ -103,8 +103,10 @@ export function DistillSavingsCard({ data }: DistillSavingsCardProps) {const distillPct = total > 0 ? Math.round((distillSaved / total) * 100) : 0;const mcpPct = 100 - distillPct;- const topFilters = data.per_filter.slice(0, 3);- const topTools = (data.mcp_per_tool ?? []).slice(0, 3);+ const topFilters = [...data.per_filter]+ .sort((a, b) => b.saved_tokens - a.saved_tokens)+ .slice(0, 5);+ const topTools = (data.mcp_per_tool ?? []).slice(0, 5);const priced = agentLabel(data.pricing_agent) || data.pricing_model;const detected = data.pricing_source && data.pricing_source !== "default";const missed = (data.missed_tokens_est ?? 0) > 0;diff --git a/packages/web/src/app/repos/[id]/costs/page.tsx b/packages/web/src/app/repos/[id]/costs/page.tsxindex 5d5dafb53..1ebb823e9 100644--- a/packages/web/src/app/repos/[id]/costs/page.tsx+++ b/packages/web/src/app/repos/[id]/costs/page.tsx@@ -30,7 +30,7 @@ import { formatCost, formatNumber, formatTokens } from "@repowise-dev/ui/lib/forexport default function CostsPage() {const params = useParams<{ id: string }>();const id = params.id;- const [tab, setTab] = useState("daily");+ const [tab, setTab] = useState("operations");const { data: summary, isLoading: loadingSummary } = useSWR<CostSummary>(`costs-summary:${id}`,@@ -70,7 +70,7 @@ export default function CostsPage() {Cost Tracking</h1><p className="text-sm text-[var(--color-text-secondary)]">- LLM token usage and spend across all generation runs.+ What repowise saved your coding agent — and what generating the docs cost.</p></div>@@ -78,45 +78,13 @@ export default function CostsPage() {coding agent, across distill (CLI + hook) and MCP tool responses. */}<DistillSavingsCard data={distillSavings} />- {loadingSummary ? (- <div className="grid grid-cols-2 gap-3 sm:grid-cols-4">- {Array.from({ length: 4 }).map((_, i) => (- <Skeleton key={i} className="h-24 w-full rounded-lg" />- ))}- </div>- ) : summary ? (- <div className="grid grid-cols-2 gap-3 sm:grid-cols-4">- <StatCard- label="Total Cost"- value={formatCost(summary.total_cost_usd)}- description="all time"- icon={<DollarSign className="h-4 w-4 text-green-500" />}- />- <StatCard- label="Total Calls"- value={formatNumber(summary.total_calls)}- description="LLM API calls"- />- <StatCard- label="Input Tokens"- value={formatTokens(summary.total_input_tokens)}- description="prompt tokens"- />- <StatCard- label="Output Tokens"- value={formatTokens(summary.total_output_tokens)}- description="completion tokens"- />- </div>- ) : null}-<Tabs value={tab} onValueChange={setTab} className="w-full"><TabsList>+ <TabsTrigger value="operations">Spend by operation</TabsTrigger><TabsTrigger value="daily">Daily</TabsTrigger>- <TabsTrigger value="cache">Cache</TabsTrigger>- <TabsTrigger value="hotspots">Hotspots</TabsTrigger><TabsTrigger value="providers">Providers</TabsTrigger>- <TabsTrigger value="operations">Operations</TabsTrigger>+ <TabsTrigger value="hotspots">Hotspots</TabsTrigger>+ <TabsTrigger value="cache">Cache</TabsTrigger></TabsList><TabsContent value="daily" className="mt-4">@@ -253,6 +221,45 @@ export default function CostsPage() {</Card></TabsContent></Tabs>++ {/* Indexing / generation cost — deliberately secondary to the savings+ hero above. */}+ <div className="space-y-2">+ <p className="text-xs font-medium uppercase tracking-wide text-[var(--color-text-tertiary)]">+ Indexing & generation cost+ </p>+ {loadingSummary ? (+ <div className="grid grid-cols-2 gap-3 sm:grid-cols-4">+ {Array.from({ length: 4 }).map((_, i) => (+ <Skeleton key={i} className="h-24 w-full rounded-lg" />+ ))}+ </div>+ ) : summary ? (+ <div className="grid grid-cols-2 gap-3 sm:grid-cols-4">+ <StatCard+ label="Indexing cost"+ value={formatCost(summary.total_cost_usd)}+ description="across all generation runs"+ icon={<DollarSign className="h-4 w-4 text-green-500" />}+ />+ <StatCard+ label="Total Calls"+ value={formatNumber(summary.total_calls)}+ description="LLM API calls"+ />+ <StatCard+ label="Input Tokens"+ value={formatTokens(summary.total_input_tokens)}+ description="prompt tokens"+ />+ <StatCard+ label="Output Tokens"+ value={formatTokens(summary.total_output_tokens)}+ description="completion tokens"+ />+ </div>+ ) : null}+ </div></div>);}diff --git a/tests/unit/generation/test_cost_pricing.py b/tests/unit/generation/test_cost_pricing.pynew file mode 100644index 000000000..3b2e6298d--- /dev/null+++ b/tests/unit/generation/test_cost_pricing.py@@ -0,0 +1,23 @@+"""Pricing-table lookups for the cost tracker.++Regression guard for the nano tier: an unlisted model silently falls back to+the Sonnet-tier default rate, which overstates a cheap indexing run by ~40x.+"""++from __future__ import annotations++from repowise.core.generation.cost_tracker import (+ _FALLBACK_PRICING,+ get_model_pricing,+)+++def test_nano_models_priced_at_nano_rate_not_fallback() -> None:+ for model in ("gpt-5-nano", "gpt-5.4-nano"):+ pricing = get_model_pricing(model)+ assert pricing == {"input": 0.05, "output": 0.40}+ assert pricing != _FALLBACK_PRICING+++def test_unknown_model_still_falls_back() -> None:+ assert get_model_pricing("totally-made-up-model-9000") == _FALLBACK_PRICING