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
feat(commits): lead the commit sheet with where the change lands (#2453)
Raghav Chamadiya5f609cd8a6e3
diff --git a/packages/ui/__tests__/commits/commit-detail-card.test.tsx b/packages/ui/__tests__/commits/commit-detail-card.test.tsxnew file mode 100644index 000000000..8579945b6--- /dev/null+++ b/packages/ui/__tests__/commits/commit-detail-card.test.tsx@@ -0,0 +1,87 @@+import { render, screen } from "@testing-library/react";+import { describe, expect, it } from "vitest";+import type { CommitDetail } from "@repowise-dev/types/git";+import { CommitDetailCard } from "../../src/commits/commit-detail-card";++const commit: CommitDetail = {+ sha: "9e51b06e65c4f28834aa2037a63e082da0ab4cf5",+ short_sha: "9e51b06",+ author_name: "Raghav Chamadiya",+ author_email: "[email protected]",+ committed_at: "2026-09-19T12:00:00Z",+ subject: "stop a failed HEAD read stranding a store's sync pointer",+ lines_added: 137,+ lines_deleted: 12,+ files_changed: 4,+ dirs_changed: 3,+ subsystems_changed: 2,+ entropy: 1.6,+ is_fix: true,+ change_risk_score: 7.9,+ change_risk_level: "high",+ risk_percentile: 36.2,+ review_priority: "moderate",+ drivers: [+ { feature: "la", value: 137, contribution: 1.4, label: "more lines added than baseline" },+ { feature: "nf", value: 4, contribution: -1.1, label: "more files than baseline" },+ ],+};++const fixHistory = {+ percentile: 89.4,+ files: [+ { path: "cli/commands/update_cmd/command.py", churn: 19, fix_pressure: 28.71 },+ { path: "core/workspace/update.py", churn: 4, fix_pressure: 16.2 },+ ],+};++describe("commit detail card", () => {+ it("leads with the repo-relative percentile, not a raw score", () => {+ render(<CommitDetailCard commit={commit} />);++ expect(screen.getByText("36th")).toBeInTheDocument();+ expect(screen.queryByText(/7\.9 out of 10/)).toBeNull();+ expect(screen.queryByText(/Supporting diff-size score/)).toBeNull();+ });++ it("names the files and their bug-fix record when git could score them", () => {+ render(<CommitDetailCard commit={commit} fixHistory={fixHistory} />);++ expect(screen.getByText("cli/commands/update_cmd/command.py")).toBeInTheDocument();+ expect(screen.getByText("28.7")).toBeInTheDocument();+ });++ it("says so when diff shape and fix history disagree", () => {+ render(<CommitDetailCard commit={commit} fixHistory={fixHistory} />);++ expect(screen.getByText(/heavy fix record/)).toBeInTheDocument();+ expect(screen.getByText(/89th percentile/)).toBeInTheDocument();+ });++ it("stays silent about the disagreement when the two rankings agree", () => {+ render(+ <CommitDetailCard+ commit={commit}+ fixHistory={{ ...fixHistory, percentile: 40 }}+ />,+ );++ expect(screen.queryByText(/heavy fix record/)).toBeNull();+ });++ it("renders without the fix block on a server with no checkout", () => {+ render(<CommitDetailCard commit={commit} fixHistory={null} />);++ expect(screen.getByText("36th")).toBeInTheDocument();+ expect(screen.queryByText(/Where this change lands/)).toBeNull();+ });++ it("keeps the driver table available but collapsed", () => {+ const { container } = render(<CommitDetailCard commit={commit} />);++ const details = container.querySelector("details");+ expect(details).not.toBeNull();+ expect(details?.hasAttribute("open")).toBe(false);+ expect(screen.getByText(/How the diff-shape rank was computed/)).toBeInTheDocument();+ });+});diff --git a/packages/ui/src/commits/commit-detail-card.tsx b/packages/ui/src/commits/commit-detail-card.tsxindex 47fe72d6d..6a9018126 100644--- a/packages/ui/src/commits/commit-detail-card.tsx+++ b/packages/ui/src/commits/commit-detail-card.tsx@@ -3,6 +3,7 @@ import { AskAboutThis } from "../chat/ask-about-this";import { AgentBadge, NewContributorBadge, isNewContributor } from "./agent-badge";import { PriorityBadge } from "./priority-badge";import { RiskDriverBreakdown, describeDriver } from "./risk-driver-breakdown";+import { FixHistoryTable, type FixHistoryRow } from "./fix-history-table";import { PageLede } from "../shared/page-lede";import { OverviewSection } from "../overview/section";import { formatDateTime } from "../lib/format";@@ -11,11 +12,11 @@ import type { CommitDetail } from "@repowise-dev/types/git";export interface CommitDetailCardProps {commit: CommitDetail;/**- * Raw score at this repo's moderate/high boundary — `CommitStats.high_cut`.- * Optional: without it the card states the score on its own rather than- * inventing a comparison.+ * Bug-fix record of the files this commit touched, scored live from git.+ * Absent on a server with no checkout, where the sheet falls back to the+ * diff-shape reading alone.*/- reviewCut?: number | null | undefined;+ fixHistory?: { files: FixHistoryRow[]; percentile: number | null } | null | undefined;className?: string;}@@ -26,8 +27,13 @@ export interface CommitDetailCardProps {* The supporting raw score remains visible with its per-commit unit and* diff-shape interpretation, never as a probability.*/-export function CommitDetailCard({ commit, reviewCut, className }: CommitDetailCardProps) {+export function CommitDetailCard({+ commit,+ fixHistory,+ className,+}: CommitDetailCardProps) {const c = commit;+ const fixFiles = fixHistory?.files ?? [];return (<div className={className}>@@ -89,33 +95,58 @@ export function CommitDetailCard({ commit, reviewCut, className }: CommitDetailCunit="percentile in this repo"badge={<PriorityBadge priority={c.review_priority} />}>- <p>{riskSentence(c, reviewCut)}</p>- {c.change_risk_score != null && (- <p>- Supporting diff-size score: {c.change_risk_score.toFixed(1)} out of 10,- calibrated per commit and not a probability.- </p>+ <p>{riskSentence(c)}</p>+ {reconcile(c, fixHistory?.percentile ?? null) && (+ <p>{reconcile(c, fixHistory?.percentile ?? null)}</p>)}</PageLede></div>- {/* No stat ribbon above this, deliberately. The model's feature set is- lines added, lines deleted, files, directories, subsystems, scatter- and author experience — which is every figure a ribbon here could- carry. A row of them above this table restates the table, and does it- without the one thing the table adds: what each measurement did to- the score. `CommitsLede` skipped its ribbon for the same reason. */}- <OverviewSection- className="mt-7"- title="What changed, and what it cost"- description="The measurements that explain the score, and the exact signed points each one moved it by. Red raised it, green lowered it, both against the model's baseline commit. File, directory and subsystem counts are left out: they enter the score, but their fitted signs are collinearity with diff size rather than a finding."- >- <RiskDriverBreakdown drivers={c.drivers} />- </OverviewSection>+ {fixFiles.length > 0 && (+ <OverviewSection+ className="mt-7"+ title="Where this change lands"+ description="The files this commit touched, and how much bug-fix history each one carries. Unlike the percentile above, this does not grow with the size of the diff."+ >+ <FixHistoryTable files={fixFiles} />+ </OverviewSection>+ )}++ {/* Collapsed, deliberately. The drivers explain a diff-size statistic+ that ranks 0.99 against lines added, so they are transparency about+ the model rather than the finding a reviewer opened this for. */}+ <details className="group mt-7">+ <summary className="cursor-pointer text-xs text-[var(--color-text-tertiary)] hover:text-[var(--color-text-secondary)]">+ How the diff-shape rank was computed+ </summary>+ <p className="mt-2 max-w-[62ch] text-xs text-[var(--color-text-tertiary)]">+ The measurements behind the rank, and the signed points each moved it+ by against the model's baseline commit. File, directory and+ subsystem counts are left out: they enter the score, but their fitted+ signs are collinearity with diff size rather than a finding.+ </p>+ <RiskDriverBreakdown className="mt-3" drivers={c.drivers} />+ </details></div>);}+/**+ * Says so when the two rankings disagree.+ *+ * Diff shape and fix history answer different questions and routinely part+ * company; the sheet used to show one of them and leave the reader to assume+ * it was the whole answer.+ */+function reconcile(c: CommitDetail, fixPercentile: number | null): string | null {+ if (fixPercentile == null) return null;+ const gap = fixPercentile - c.risk_percentile;+ if (Math.abs(gap) < 25) return null;+ return gap > 0+ ? `Ordinary in size, but it lands in files with a heavy fix record — ${Math.round(fixPercentile)}th percentile for prior fixes. That is the signal worth reading here.`+ : `Large for this repo, but it lands in files that have rarely broken — ${Math.round(fixPercentile)}th percentile for prior fixes.`;+}+/*** The sentence that makes the score mean something.*@@ -123,7 +154,7 @@ export function CommitDetailCard({ commit, reviewCut, className }: CommitDetailC* the exact percentile; this sentence explains its tercile without inventing a* defect probability from the supporting model score.*/-function riskSentence(c: CommitDetail, reviewCut: number | null | undefined): string {+function riskSentence(c: CommitDetail): string {const tercile: Record<string, string> = {high: "sits in the top third of this repo's own diff-shape distribution, the review-priority band worth reviewing",moderate:@@ -132,28 +163,14 @@ function riskSentence(c: CommitDetail, reviewCut: number | null | undefined): st};let out = `This commit ${tercile[c.review_priority] ?? tercile.moderate}`;- // `high_cut` is the moderate/high boundary and nothing else, so it only- // describes where *this* commit's band begins when the commit is in the top- // one. Appending it to a moderate commit would name the middle third's floor- // as a number that is actually its ceiling.- if (reviewCut != null && c.review_priority === "high") {- out += `, which here starts at ${reviewCut.toFixed(1)} out of 10`;- }out += ".";- if (c.change_risk_score != null) {- // `drivers` arrive strongest-first, and only score-raising ones explain- // why the score landed where it did.- const raising = c.drivers.filter((d) => d.value !== null && d.contribution > 0);- if (raising.length === 0) {- out += " The raw score stays low across every driver.";- } else {- // The same wording as the table below, not the server's baseline-relative- // labels. Two vocabularies for one set of drivers, a paragraph apart,- // reads as two different lists.- const reasons = raising.slice(0, 2).map(describeDriver).join(" and ");- out += ` What pushed the raw score up was mainly ${reasons}. That score is measured against the model's baseline commit rather than against this repo, so read it as the shape of the change rather than a verdict on it.`;- }+ // `drivers` arrive strongest-first, and only rank-raising ones explain where+ // the change landed. The same wording as the collapsed table below: two+ // vocabularies for one set of drivers reads as two different lists.+ const raising = c.drivers.filter((d) => d.value !== null && d.contribution > 0);+ if (raising.length > 0) {+ out += ` Mostly ${raising.slice(0, 2).map(describeDriver).join(" and ")}.`;}if (!c.agent_name && isNewContributor(c.author_commit_count)) {diff --git a/packages/ui/src/commits/fix-history-table.tsx b/packages/ui/src/commits/fix-history-table.tsxnew file mode 100644index 000000000..d9838fd1b--- /dev/null+++ b/packages/ui/src/commits/fix-history-table.tsx@@ -0,0 +1,73 @@+import { cn } from "../lib/cn";+import { formatLOC } from "../lib/format";++export interface FixHistoryRow {+ path: string;+ churn: number;+ fix_pressure: number;+}++export interface FixHistoryTableProps {+ files: FixHistoryRow[];+ className?: string;+}++/**+ * The bug-fix record of the files a commit touched.+ *+ * This leads the sheet because it is the one signal here that does not grow+ * with the diff: one line in a file fixed twenty times outranks a thousand+ * lines in files never fixed at all.+ */+export function FixHistoryTable({ files, className }: FixHistoryTableProps) {+ if (files.length === 0) return null;++ return (+ <table className={cn("w-full border-collapse text-xs", className)}>+ <caption className="sr-only">+ Files this commit touched, and how much bug-fix history each carries+ </caption>+ <thead>+ <tr>+ <th+ scope="col"+ className="border-b border-[var(--color-border-default)] pb-2 pr-3 text-left font-mono text-[10px] font-normal uppercase tracking-[0.12em] text-[var(--color-text-tertiary)]"+ >+ File+ </th>+ <th+ scope="col"+ className="border-b border-[var(--color-border-default)] pb-2 px-3 text-right font-mono text-[10px] font-normal uppercase tracking-[0.12em] text-[var(--color-text-tertiary)]"+ >+ Lines+ </th>+ <th+ scope="col"+ title="Past bug-fix commits on this file, weighted so a fix a year ago counts a half"+ className="cursor-help border-b border-[var(--color-border-default)] pb-2 pl-3 text-right font-mono text-[10px] font-normal uppercase tracking-[0.12em] text-[var(--color-text-tertiary)]"+ >+ Prior fixes+ </th>+ </tr>+ </thead>+ <tbody>+ {files.map((f) => (+ <tr+ key={f.path}+ className="border-b border-[var(--color-border-default)] last:border-0"+ >+ <td className="py-2 pr-3 align-middle font-mono text-[11px] text-[var(--color-text-secondary)] [overflow-wrap:anywhere]">+ {f.path}+ </td>+ <td className="whitespace-nowrap py-2 px-3 text-right align-middle tabular-nums text-[var(--color-text-tertiary)]">+ {formatLOC(f.churn)}+ </td>+ <td className="whitespace-nowrap py-2 pl-3 text-right align-middle tabular-nums text-[var(--color-text-primary)]">+ {f.fix_pressure.toFixed(1)}+ </td>+ </tr>+ ))}+ </tbody>+ </table>+ );+}diff --git a/packages/web/src/app/repos/[id]/commits/page.tsx b/packages/web/src/app/repos/[id]/commits/page.tsxindex 1d5e65924..62179baec 100644--- a/packages/web/src/app/repos/[id]/commits/page.tsx+++ b/packages/web/src/app/repos/[id]/commits/page.tsx@@ -122,7 +122,7 @@ export default async function CommitsPage({<CommitDistribution stats={stats} recent={recent?.items ?? []} /></OverviewSection>- <CommitDetailSheet repoId={id} reviewCut={stats?.high_cut} />+ <CommitDetailSheet repoId={id} /></PageShell>);}diff --git a/packages/web/src/components/commits/commit-detail-sheet.tsx b/packages/web/src/components/commits/commit-detail-sheet.tsxindex cf5eabc3c..306ed6434 100644--- a/packages/web/src/components/commits/commit-detail-sheet.tsx+++ b/packages/web/src/components/commits/commit-detail-sheet.tsx@@ -13,6 +13,7 @@ import {import { CommitDetailCard } from "@repowise-dev/ui/commits/commit-detail-card";import { AiPromptButton, AiPromptModal, buildCommitAiPrompt } from "@repowise-dev/ui/health";import { getCommit } from "@/lib/api/git";+import { getRiskRange } from "@/lib/api/risk";/*** The commit detail drawer, driven entirely by `?commit=`.@@ -22,16 +23,7 @@ import { getCommit } from "@/lib/api/git";* also what makes the deep link work — entity links from Overview and the file* pages land here with the sheet already open, and it survives a refresh.*/-export function CommitDetailSheet({- repoId,- reviewCut,-}: {- repoId: string;- /** `CommitStats.high_cut` — the raw score at this repo's review line. The- * page already has it, and without it the card can only state a commit's- * score with nothing to measure it against. */- reviewCut?: number | null | undefined;-}) {+export function CommitDetailSheet({ repoId }: { repoId: string }) {const [selectedSha, setSelectedSha] = useQueryState("commit");const [promptOpen, setPromptOpen] = useState(false);@@ -41,6 +33,19 @@ export function CommitDetailSheet({{ revalidateOnFocus: false },);+ // Scored live from git, because the indexed commit row carries Kamei+ // aggregates and no file list. A server with no checkout 404s here and the+ // sheet renders without the block rather than failing.+ const { data: range } = useSWR(+ selectedSha ? `commit-fixes:${repoId}:${selectedSha}` : null,+ () =>+ getRiskRange(repoId, {+ base: `${selectedSha}^`,+ head: selectedSha as string,+ }),+ { revalidateOnFocus: false, shouldRetryOnError: false },+ );+return (<><Sheet@@ -49,7 +54,7 @@ export function CommitDetailSheet({><SheetContent side="right" className="w-[440px] max-w-[92vw] sm:w-[560px]"><SheetHeader>- <SheetTitle>Commit change-risk</SheetTitle>+ <SheetTitle>Review this commit</SheetTitle></SheetHeader><div className="flex-1 overflow-y-auto px-4 pb-6">{isLoading || !detail ? (@@ -65,7 +70,12 @@ export function CommitDetailSheet({onClick={() => setPromptOpen(true)}/></div>- <CommitDetailCard commit={detail} reviewCut={reviewCut} />+ <CommitDetailCard+ commit={detail}+ fixHistory={+ range?.fix_history?.available ? range.fix_history : null+ }+ /></>)}</div>diff --git a/packages/web/src/lib/api/risk.ts b/packages/web/src/lib/api/risk.tsnew file mode 100644index 000000000..10e03014c--- /dev/null+++ b/packages/web/src/lib/api/risk.ts@@ -0,0 +1,3 @@+import "./client";++export * from "@repowise-dev/api-client/risk";