Skip to content

Codebase intelligence for AI and humans: code health scores, auto-generated docs, git analytics, dead code detection, and architectural decisions via MCP.

fix(commits): commits-page follow-ups (full-width agent strip, collapsible risk panel, repo-wide stat cards) (#552)

Raghav Chamadiya9b40e2e5c70b
diff --git a/packages/server/src/repowise/server/routers/git.py b/packages/server/src/repowise/server/routers/git.py
index bc9a0b69d..fd42911fe 100644
--- a/packages/server/src/repowise/server/routers/git.py
+++ b/packages/server/src/repowise/server/routers/git.py
@@ -7,7 +7,7 @@ from collections import Counter
from datetime import datetime, timedelta
from fastapi import APIRouter, Depends, HTTPException, Query
-from sqlalchemy import func, select
+from sqlalchemy import case, func, select
from sqlalchemy.ext.asyncio import AsyncSession
from repowise.core.analysis.change_risk import (
@@ -30,6 +30,7 @@ from repowise.server.schemas import (
CommitEvolutionBucket,
CommitEvolutionResponse,
CommitResponse,
+ CommitStatsResponse,
GitMetadataResponse,
GitSummaryResponse,
HotspotResponse,
@@ -259,6 +260,46 @@ async def get_agent_trend(
)
[email protected]("/{repo_id}/commits/stats", response_model=CommitStatsResponse)
+async def get_commit_stats(
+ repo_id: str,
+ session: AsyncSession = Depends(get_db_session), # noqa: B008
+) -> CommitStatsResponse:
+ """Repo-wide commit aggregates for the headline stat cards.
+
+ Computed over **every** indexed commit, not the loaded page — the feed is
+ paginated, so reducing the client's window mis-counts (a risk-sorted first
+ page is entirely top-tercile, and its fix/entropy figures are a slice, not
+ the whole). High-priority uses the same repo-relative tercile as the feed.
+ """
+ total = await crud.count_git_commits(session, repo_id)
+
+ # is_fix / entropy / agent counts in a single pass. CASE-SUM rather than
+ # COUNT(...) FILTER keeps it portable across SQLite and Postgres.
+ agg = (
+ await session.execute(
+ select(
+ func.sum(case((GitCommit.is_fix.is_(True), 1), else_=0)),
+ func.avg(GitCommit.entropy),
+ func.sum(case((GitCommit.agent_name.is_not(None), 1), else_=0)),
+ ).where(GitCommit.repository_id == repo_id)
+ )
+ ).one()
+ fix_count, avg_entropy, agent_count = agg
+
+ scores = await crud.get_commit_risk_scores(session, repo_id)
+ normalizer = RiskNormalizer.from_scores(scores)
+ high_priority = sum(1 for s in scores if normalizer.priority(s) == "high")
+
+ return CommitStatsResponse(
+ total_commits=total,
+ high_priority_count=high_priority,
+ fix_commit_count=int(fix_count or 0),
+ agent_commit_count=int(agent_count or 0),
+ avg_entropy=float(avg_entropy or 0.0),
+ )
+
+
@router.get("/{repo_id}/commits/evolution", response_model=CommitEvolutionResponse)
async def get_commit_evolution(
repo_id: str,
diff --git a/packages/server/src/repowise/server/schemas/__init__.py b/packages/server/src/repowise/server/schemas/__init__.py
index 2bd1dc696..231989cef 100644
--- a/packages/server/src/repowise/server/schemas/__init__.py
+++ b/packages/server/src/repowise/server/schemas/__init__.py
@@ -68,6 +68,7 @@ from .git import (
CommitEvolutionBucket,
CommitEvolutionResponse,
CommitResponse,
+ CommitStatsResponse,
GitMetadataResponse,
GitSummaryResponse,
HotspotResponse,
@@ -226,6 +227,7 @@ __all__ = [
"CochangeWarning",
"CommitDetailResponse",
"CommitResponse",
+ "CommitStatsResponse",
"CommunityDetailResponse",
"CommunityMember",
"CommunitySliceNodeResponse",
diff --git a/packages/server/src/repowise/server/schemas/git.py b/packages/server/src/repowise/server/schemas/git.py
index 53fcf246f..e332985f9 100644
--- a/packages/server/src/repowise/server/schemas/git.py
+++ b/packages/server/src/repowise/server/schemas/git.py
@@ -249,3 +249,19 @@ class CommitEvolutionResponse(BaseModel):
granularity: str # "month" | "week"
first_commit_at: str | None = None
last_commit_at: str | None = None
+
+
+class CommitStatsResponse(BaseModel):
+ """Repo-wide commit aggregates for the commits-page headline stat cards.
+
+ Computed over **all** indexed commits, not the loaded page — the paginated
+ feed only returns a window, so client-side reductions over it under-count
+ (e.g. a risk-sorted first page is all top-tercile). These are the honest
+ totals for the whole repository.
+ """
+
+ total_commits: int
+ high_priority_count: int # commits in the repo-relative top risk tercile
+ fix_commit_count: int # subjects classified as bug-fixes
+ agent_commit_count: int # agent-attributed commits
+ avg_entropy: float # mean change-diffusion across all commits
diff --git a/packages/types/src/git.ts b/packages/types/src/git.ts
index 85f451a27..d3ab31ae4 100644
--- a/packages/types/src/git.ts
+++ b/packages/types/src/git.ts
@@ -208,6 +208,15 @@ export interface CommitEvolution {
last_commit_at: string | null;
}
+/** Repo-wide commit aggregates (over all commits, not the loaded page). */
+export interface CommitStats {
+ total_commits: number;
+ high_priority_count: number;
+ fix_commit_count: number;
+ agent_commit_count: number;
+ avg_entropy: number;
+}
+
export interface OwnershipEntry {
module_path: string;
primary_owner: string | null;
diff --git a/packages/web/src/components/commits/commits-explorer.tsx b/packages/web/src/components/commits/commits-explorer.tsx
index a83a150b5..4328da4e3 100644
--- a/packages/web/src/components/commits/commits-explorer.tsx
+++ b/packages/web/src/components/commits/commits-explorer.tsx
@@ -23,10 +23,12 @@ import { CredibilityInfoButton } from "@repowise-dev/ui/commits/credibility-stri
import { CodeEvolutionChart } from "@repowise-dev/ui/commits/code-evolution-chart";
import { AgentTrendStrip } from "@repowise-dev/ui/commits/agent-trend-strip";
import { RiskDistributionChart } from "@repowise-dev/ui/git/risk-distribution-chart";
+import { CollapsibleSection } from "@repowise-dev/ui/shared/collapsible-section";
import {
getAgentTrend,
getCommit,
getCommitEvolution,
+ getCommitStats,
getCommitsPage,
getHotspots,
} from "@/lib/api/git";
@@ -62,6 +64,15 @@ export function CommitsExplorer({ repoId }: { repoId: string }) {
{ revalidateOnFocus: false },
);
+ // Repo-wide stat-card aggregates. Computed server-side over ALL commits — the
+ // loaded page is only a window (and, when risk-sorted, entirely top-tercile),
+ // so reducing `list` here would under-count fixes and inflate high-priority.
+ const { data: stats } = useSWR(
+ `commit-stats:${repoId}`,
+ () => getCommitStats(repoId),
+ { revalidateOnFocus: false },
+ );
+
// Repo-relative risk distribution — turns the credibility strip's
// "relative to this repo" claim into a picture.
const { data: hotspots } = useSWR(
@@ -77,15 +88,19 @@ export function CommitsExplorer({ repoId }: { repoId: string }) {
);
const list = data?.items ?? [];
- const total = data?.total ?? list.length;
+ const total = stats?.total_commits ?? data?.total ?? list.length;
const hasMore = data?.has_more ?? false;
- const highCount = list.filter((c) => c.review_priority === "high").length;
- const fixCount = list.filter((c) => c.is_fix).length;
+ // Prefer the repo-wide aggregates; fall back to the loaded page only until
+ // the stats request resolves so the cards aren't blank on first paint.
+ const highCount =
+ stats?.high_priority_count ?? list.filter((c) => c.review_priority === "high").length;
+ const fixCount = stats?.fix_commit_count ?? list.filter((c) => c.is_fix).length;
const avgEntropy =
- list.length > 0
+ stats?.avg_entropy ??
+ (list.length > 0
? list.reduce((s, c) => s + (c.entropy || 0), 0) / list.length
- : 0;
+ : 0);
if (isLoading && list.length === 0) {
return (
@@ -121,7 +136,7 @@ export function CommitsExplorer({ repoId }: { repoId: string }) {
<StatCard
label="High priority"
value={highCount}
- description="top tercile (loaded)"
+ description="top risk tercile"
icon={<AlertTriangle className="h-4 w-4 text-[var(--color-error)]" />}
/>
<StatCard
@@ -137,22 +152,21 @@ export function CommitsExplorer({ repoId }: { repoId: string }) {
/>
</div>
- {/* Secondary signals — smaller than the headline. Risk distribution
- turns the queue's "relative to this repo" claim into a picture; the
- agent-trend strip sits alongside it. */}
- <div className="grid gap-4 lg:grid-cols-2">
- {hotspots && hotspots.length > 0 && (
+ {/* Secondary signals — smaller than the headline. Risk distribution is
+ collapsible (it's a demoted detail); the agent-trend strip is a thin
+ full-width band beneath it. */}
+ {hotspots && hotspots.length > 0 && (
+ <CollapsibleSection
+ title="Risk distribution across the riskiest files"
+ hint={`${Math.min(12, hotspots.length)} of ${hotspots.length}`}
+ defaultOpen
+ >
<div className="rounded-lg border border-[var(--color-border-default)] bg-[var(--color-bg-surface)] p-4">
- <p className="mb-2 text-xs font-medium uppercase tracking-wider text-[var(--color-text-tertiary)]">
- Risk distribution across the riskiest files
- </p>
<RiskDistributionChart hotspots={hotspots} maxBars={12} />
</div>
- )}
- {trend && trend.agent_commits > 0 && (
- <AgentTrendStrip trend={trend} />
- )}
- </div>
+ </CollapsibleSection>
+ )}
+ {trend && trend.agent_commits > 0 && <AgentTrendStrip trend={trend} />}
<div className="space-y-2">
<div className="flex items-center gap-1.5 text-xs font-medium uppercase tracking-wider text-[var(--color-text-tertiary)]">
diff --git a/packages/web/src/lib/api/git.ts b/packages/web/src/lib/api/git.ts
index bbdb50120..d8430d052 100644
--- a/packages/web/src/lib/api/git.ts
+++ b/packages/web/src/lib/api/git.ts
@@ -2,6 +2,7 @@ import { apiGet } from "./client";
import type {
AgentTrend,
CommitEvolution,
+ CommitStats,
CommitDetailResponse,
CommitResponse,
GitMetadataResponse,
@@ -147,6 +148,10 @@ export async function getCommitEvolution(
);
}
+export async function getCommitStats(repoId: string): Promise<CommitStats> {
+ return apiGet<CommitStats>(`/api/repos/${repoId}/commits/stats`);
+}
+
export async function getCommit(
repoId: string,
sha: string,
diff --git a/packages/web/src/lib/api/types/git.ts b/packages/web/src/lib/api/types/git.ts
index 96ee52956..f13c1e06e 100644
--- a/packages/web/src/lib/api/types/git.ts
+++ b/packages/web/src/lib/api/types/git.ts
@@ -172,3 +172,12 @@ export interface CommitEvolution {
first_commit_at: string | null;
last_commit_at: string | null;
}
+
+/** Repo-wide commit aggregates (computed over all commits, not the loaded page). */
+export interface CommitStats {
+ total_commits: number;
+ high_priority_count: number;
+ fix_commit_count: number;
+ agent_commit_count: number;
+ avg_entropy: number;
+}