Skip to content

Local code intelligence for developers and AI agents. Connect code, docs and infrastructure in a persistent graph, with CBM Lens, MCP tools, agent integrations and change-aware test selection.

feat(ui): findings feed Overview + hero Dashboard (Field Guide D2)

Martin Vogel46cf438dce9b
diff --git a/graph-ui/src/App.tsx b/graph-ui/src/App.tsx
index e51dadacf..8420059d1 100644
--- a/graph-ui/src/App.tsx
+++ b/graph-ui/src/App.tsx
@@ -225,6 +225,7 @@ export function App() {
onOpenSymbol={(qn) => openSymbol({ qn })}
onOpenModules={() => navigate({ tab: "modules" })}
onOpenFlows={() => navigate({ tab: "flows" })}
+ onOpenDashboard={() => navigate({ tab: "dashboard" })}
/>
) : activeTab === "modules" && selectedProject ? (
<ModulesTab
@@ -258,6 +259,7 @@ export function App() {
<DashboardTab
project={selectedProject}
onOpenSymbol={(ref) => openSymbol(ref)}
+ onOpenModulesPath={(path) => navigate({ tab: "modules", path })}
/>
) : activeTab === "symbol" && selectedProject && symbolRef ? (
<SymbolTab
diff --git a/graph-ui/src/components/DashboardTab.tsx b/graph-ui/src/components/DashboardTab.tsx
index a87ded4e4..554cebd40 100644
--- a/graph-ui/src/components/DashboardTab.tsx
+++ b/graph-ui/src/components/DashboardTab.tsx
@@ -1,15 +1,19 @@
-/* Dashboard — the project's numbers with the code behind them one click
- * away. No composite health score: the cards are the score. Everything is
- * derived from the graph (and one bounded git-log pass); nothing here asks
- * a model anything. */
-import { useEffect, useState } from "react";
+/* Dashboard — one hero and its context. The hero is the churn × complexity
+ * list (the evidence-backed "where the bugs live") with a knee-point head,
+ * a cost sentence, and mute-as-intended dispositions. Quality signals get
+ * tones and trends; inventory facts live in the footer; histograms exist
+ * only with a computed takeaway. No composite score — the cards are the
+ * score. Everything derives from the graph and one bounded git-log pass. */
+import { useEffect, useMemo, useState } from "react";
import { ScrollArea } from "@/components/ui/scroll-area";
+import { kneeCount, costSentence, findingKey, isDismissed, dismiss } from "../lib/findings";
interface MetricEntry {
qn?: string;
name?: string;
file?: string;
value: number;
+ commits?: number;
}
interface MetricsPayload {
@@ -23,6 +27,7 @@ interface MetricsPayload {
exported: number;
documented_exported: number;
avg_complexity: number;
+ files: number;
};
certainty: { calls: number; call_reference: number; usage: number };
complexity_hist: number[];
@@ -33,6 +38,8 @@ interface MetricsPayload {
top_churn: MetricEntry[];
top_churn_complex: MetricEntry[];
churn_available: boolean;
+ churn_total_commits: number;
+ churn_total_files: number;
history: {
indexed_at: string;
callables: number;
@@ -46,30 +53,10 @@ interface MetricsPayload {
interface DashboardTabProps {
project: string;
onOpenSymbol: (ref: { qn: string }) => void;
+ onOpenModulesPath: (path: string) => void;
}
const CPLX_LABELS = ["1", "2–5", "6–10", "11–20", "21–50", ">50"];
-const LINE_LABELS = ["≤10", "≤30", "≤60", "≤120", ">120"];
-
-function Histogram({ values, labels }: { values: number[]; labels: string[] }) {
- const max = Math.max(1, ...values);
- return (
- <div className="flex items-end gap-1.5 h-[72px] mt-2">
- {values.map((value, index) => (
- <div key={index} className="flex-1 flex flex-col items-center gap-1 min-w-0">
- <span className="text-[12px] tabular-nums text-foreground/45">
- {value.toLocaleString("en-US")}
- </span>
- <div
- className="w-full rounded-sm bg-primary/40"
- style={{ height: `${Math.max(2, (value / max) * 46)}px` }}
- />
- <span className="text-[12px] text-foreground/40">{labels[index]}</span>
- </div>
- ))}
- </div>
- );
-}
function Sparkline({ points }: { points: number[] }) {
if (points.length < 2) return null;
@@ -83,14 +70,20 @@ function Sparkline({ points }: { points: number[] }) {
)
.join(" ");
return (
- <svg viewBox="0 0 100 30" className="w-full h-[30px] mt-1" preserveAspectRatio="none">
- <polyline points={coords} fill="none" stroke="currentColor" strokeWidth="1.5"
- className="text-primary/60" vectorEffect="non-scaling-stroke" />
+ <svg viewBox="0 0 100 30" className="w-full h-[28px] mt-1" preserveAspectRatio="none">
+ <polyline
+ points={coords}
+ fill="none"
+ stroke="currentColor"
+ strokeWidth="1.5"
+ className="text-primary/50"
+ vectorEffect="non-scaling-stroke"
+ />
</svg>
);
}
-function StatCard({
+function QualityCard({
label,
value,
sub,
@@ -104,20 +97,16 @@ function StatCard({
trend?: number[];
}) {
return (
- <div className="bg-card border border-border/40 rounded-md p-4 min-w-0">
- <p className="text-[12px] uppercase tracking-widest text-foreground/45">{label}</p>
+ <div className="bg-card border border-border/50 rounded-md p-4 min-w-0">
+ <p className="text-[12px] uppercase tracking-widest text-foreground/40">{label}</p>
<p
className={`text-[22px] font-semibold tabular-nums mt-1 ${
- tone === "crit"
- ? "text-red-300/90"
- : tone === "warn"
- ? "text-amber-300/90"
- : "text-foreground/90"
+ tone === "crit" ? "text-crit" : tone === "warn" ? "text-warn" : "text-foreground/90"
}`}
>
{value}
</p>
- {sub && <p className="text-[12px] text-foreground/45 mt-0.5">{sub}</p>}
+ {sub && <p className="text-[12px] text-foreground/40 mt-0.5">{sub}</p>}
{trend && trend.length > 1 && <Sparkline points={trend} />}
</div>
);
@@ -135,8 +124,8 @@ function TopList({
onOpenSymbol?: (ref: { qn: string }) => void;
}) {
return (
- <div className="bg-card border border-border/40 rounded-md p-4">
- <p className="text-[12px] uppercase tracking-widest text-foreground/45 mb-2">{title}</p>
+ <div className="bg-card border border-border/50 rounded-md p-4">
+ <p className="text-[12px] uppercase tracking-widest text-foreground/40 mb-2">{title}</p>
<div className="space-y-px">
{entries.map((entry, index) => {
const label = entry.name ?? entry.file ?? "?";
@@ -160,7 +149,7 @@ function TopList({
>
{label}
</span>
- <span className="text-[12px] tabular-nums text-foreground/50 shrink-0">
+ <span className="text-[12px] tabular-nums text-foreground/35 shrink-0">
{entry.value.toLocaleString("en-US")} {unit}
</span>
</Row>
@@ -172,9 +161,11 @@ function TopList({
);
}
-export function DashboardTab({ project, onOpenSymbol }: DashboardTabProps) {
+export function DashboardTab({ project, onOpenSymbol, onOpenModulesPath }: DashboardTabProps) {
const [metrics, setMetrics] = useState<MetricsPayload | null>(null);
const [error, setError] = useState<string | null>(null);
+ const [showMuted, setShowMuted] = useState(false);
+ const [mutedTick, setMutedTick] = useState(0);
useEffect(() => {
let cancelled = false;
@@ -182,7 +173,8 @@ export function DashboardTab({ project, onOpenSymbol }: DashboardTabProps) {
setError(null);
fetch(`/api/metrics?${new URLSearchParams({ project })}`)
.then(async (res) => {
- if (!res.ok) throw new Error((await res.json().catch(() => null))?.error ?? `HTTP ${res.status}`);
+ if (!res.ok)
+ throw new Error((await res.json().catch(() => null))?.error ?? `HTTP ${res.status}`);
return res.json();
})
.then((payload) => {
@@ -196,10 +188,45 @@ export function DashboardTab({ project, onOpenSymbol }: DashboardTabProps) {
};
}, [project]);
+ /* Hero rows: knee-point head + dispositions. */
+ const hero = useMemo(() => {
+ void mutedTick;
+ const entries = metrics?.top_churn_complex ?? [];
+ const head = kneeCount(entries.map((entry) => entry.value));
+ const rows = entries.map((entry, index) => ({
+ entry,
+ inHead: index < head,
+ key: findingKey("hotspot", entry.file ?? String(index), entry.value),
+ }));
+ return {
+ visible: rows.filter((row) => showMuted || !isDismissed(row.key)),
+ mutedCount: rows.filter((row) => isDismissed(row.key)).length,
+ head,
+ headCommits: entries
+ .slice(0, head)
+ .reduce((sum, entry) => sum + (entry.commits ?? 0), 0),
+ };
+ }, [metrics, showMuted, mutedTick]);
+
+ const takeaway = useMemo(() => {
+ if (!metrics) return null;
+ const hist = metrics.complexity_hist;
+ const total = hist.reduce((a, b) => a + b, 0);
+ if (total === 0) return null;
+ const simple = hist[0] + hist[1];
+ const tail = hist[4] + hist[5];
+ const names = metrics.top_complex
+ .slice(0, 3)
+ .map((entry) => entry.name)
+ .filter(Boolean)
+ .join(", ");
+ return `${((simple / total) * 100).toFixed(0)}% of functions are simple (≤5); ${tail.toLocaleString("en-US")} exceed 20${names ? ` — led by ${names}` : ""}.`;
+ }, [metrics]);
+
if (error) {
return (
<div className="flex items-center justify-center h-full">
- <p className="text-red-400/80 text-sm">{error}</p>
+ <p className="text-crit/90 text-sm">{error}</p>
</div>
);
}
@@ -217,92 +244,176 @@ export function DashboardTab({ project, onOpenSymbol }: DashboardTabProps) {
const docShare = totals.exported > 0 ? totals.documented_exported / totals.exported : 0;
const testedShare = totals.callables > 0 ? totals.tested_symbols / totals.callables : 0;
const history = metrics.history ?? [];
+ const cost = costSentence(
+ hero.head,
+ hero.headCommits,
+ totals.files,
+ metrics.churn_total_commits,
+ );
return (
<ScrollArea className="h-full">
<div className="max-w-[1200px] mx-auto px-6 py-6">
- <p className="text-[12px] text-foreground/40 font-mono mb-4">
- computed from index {metrics.generated_from}
- {history.length > 1 && ` · trends across ${history.length} index runs`}
- </p>
+ {/* ── Hero: where the bugs live ─────────────────────────── */}
+ <div className="bg-card border border-border/50 rounded-md p-5 mb-4">
+ <div className="flex items-baseline gap-3 flex-wrap">
+ <h2 className="text-[17px] font-semibold text-foreground/90">
+ Where the bugs live — churn × complexity
+ </h2>
+ {hero.mutedCount > 0 && (
+ <button
+ onClick={() => setShowMuted((value) => !value)}
+ className="text-[12px] text-foreground/35 hover:text-foreground/60 transition-colors"
+ >
+ {showMuted ? "hide muted" : `${hero.mutedCount} muted — show`}
+ </button>
+ )}
+ </div>
+ {cost ? (
+ <p className="text-[13px] text-foreground/55 mt-1">
+ {cost} — change here is where defects concentrate.
+ </p>
+ ) : (
+ <p className="text-[13px] text-foreground/45 mt-1">
+ {metrics.churn_available
+ ? "Not enough churn data yet."
+ : "Churn unavailable — the project root has no readable git history."}
+ </p>
+ )}
+ <div className="mt-3 space-y-px">
+ {hero.visible.map(({ entry, inHead, key }) => (
+ <div
+ key={key}
+ className={`flex items-center gap-3 rounded-md px-3 py-[6px] ${
+ inHead ? "bg-popover border-l-2 border-warn/70" : ""
+ }`}
+ >
+ <button
+ onClick={() => {
+ const parent = entry.file?.split("/").slice(0, -1).join("/") ?? "";
+ onOpenModulesPath(parent);
+ }}
+ className="text-[13px] font-mono text-foreground/70 hover:text-primary truncate flex-1 text-left transition-colors"
+ title="Open in Modules"
+ >
+ {entry.file}
+ </button>
+ <span className="text-[12px] tabular-nums text-foreground/45 shrink-0">
+ {entry.commits?.toLocaleString("en-US") ?? "?"} commits
+ </span>
+ <span className="text-[12px] tabular-nums text-foreground/35 shrink-0 w-20 text-right">
+ {entry.value.toLocaleString("en-US")}
+ </span>
+ <button
+ onClick={() => {
+ dismiss(key);
+ setMutedTick((tick) => tick + 1);
+ }}
+ className="text-[12px] text-foreground/25 hover:text-foreground/60 shrink-0 transition-colors"
+ title="Mute as intended — resurfaces if the score grows an order of magnitude"
+ >
+ mute
+ </button>
+ </div>
+ ))}
+ {hero.visible.length === 0 && (
+ <p className="text-[13px] text-foreground/40 py-2">
+ Nothing here — either healthy, or everything is muted.
+ </p>
+ )}
+ </div>
+ </div>
- {/* Cards */}
- <div className="grid grid-cols-2 md:grid-cols-4 gap-3 mb-4">
- <StatCard
- label="Callables"
- value={totals.callables.toLocaleString("en-US")}
- sub={`avg complexity ${totals.avg_complexity.toFixed(1)}`}
- trend={history.map((entry) => entry.callables)}
- />
- <StatCard
+ {/* ── Quality signals: toned, trended ───────────────────── */}
+ <div className="grid grid-cols-2 lg:grid-cols-4 gap-3 mb-4">
+ <QualityCard
label="Call resolution"
value={`${(resolvedShare * 100).toFixed(0)}%`}
sub={`${certainty.usage.toLocaleString("en-US")} USAGE edges unproven`}
tone={resolvedShare < 0.6 ? "warn" : undefined}
trend={history.map((entry) => 1 - entry.usage_share)}
/>
- <StatCard
+ <QualityCard
label="Dead candidates"
value={totals.dead.toLocaleString("en-US")}
sub="no callers; entry/test/exported excluded"
tone={totals.dead > 0 ? "warn" : undefined}
trend={history.map((entry) => entry.dead)}
/>
- <StatCard
+ <QualityCard
label="Tested symbols"
value={`${(testedShare * 100).toFixed(0)}%`}
sub={`${totals.tested_symbols.toLocaleString("en-US")} with TESTS edges`}
trend={history.map((entry) => entry.tested)}
/>
- <StatCard
+ <QualityCard
label="Documented exports"
value={`${(docShare * 100).toFixed(0)}%`}
sub={`${totals.documented_exported.toLocaleString("en-US")} of ${totals.exported.toLocaleString("en-US")} exported`}
tone={docShare < 0.3 ? "warn" : undefined}
/>
- <StatCard
- label="Near-clone edges"
- value={totals.similar_edges.toLocaleString("en-US")}
- sub="SIMILAR_TO (MinHash)"
- />
- <StatCard
- label="Files not fully indexed"
- value={totals.missed_files.toLocaleString("en-US")}
- sub="the missed skeleton in the galaxy"
- tone={totals.missed_files > 0 ? "warn" : undefined}
- />
- <div className="bg-card border border-border/40 rounded-md p-4">
- <p className="text-[12px] uppercase tracking-widest text-foreground/45">
- Complexity distribution
- </p>
- <Histogram values={metrics.complexity_hist} labels={CPLX_LABELS} />
- </div>
</div>
- <div className="grid grid-cols-1 md:grid-cols-2 gap-3 mb-3">
- <div className="bg-card border border-border/40 rounded-md p-4">
- <p className="text-[12px] uppercase tracking-widest text-foreground/45">
- Function length (lines)
+ {/* ── Complexity, with its takeaway ─────────────────────── */}
+ <div className="grid grid-cols-1 lg:grid-cols-2 gap-3 mb-4">
+ <div className="bg-card border border-border/50 rounded-md p-4">
+ <p className="text-[12px] uppercase tracking-widest text-foreground/40">
+ Complexity distribution
</p>
- <Histogram values={metrics.lines_hist} labels={LINE_LABELS} />
+ {takeaway && <p className="text-[13px] text-foreground/60 mt-1">{takeaway}</p>}
+ <div className="flex items-end gap-1.5 h-[64px] mt-3">
+ {metrics.complexity_hist.map((value, index) => {
+ const max = Math.max(1, ...metrics.complexity_hist);
+ return (
+ <div key={index} className="flex-1 flex flex-col items-center gap-1 min-w-0">
+ <div
+ className={`w-full rounded-sm ${index >= 4 ? "bg-warn/60" : "bg-primary/35"}`}
+ style={{ height: `${Math.max(2, (value / max) * 40)}px` }}
+ />
+ <span className="text-[12px] text-foreground/35">{CPLX_LABELS[index]}</span>
+ </div>
+ );
+ })}
+ </div>
</div>
<TopList
- title={
- metrics.churn_available
- ? "Where the bugs live — churn × complexity (1y)"
- : "Churn unavailable (no git history readable)"
- }
- entries={metrics.top_churn_complex}
- unit="score"
+ title="Most churned files (1y)"
+ entries={metrics.top_churn}
+ unit="commits"
/>
</div>
- <div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-3">
- <TopList title="Most complex" entries={metrics.top_complex} unit="cyclo" onOpenSymbol={onOpenSymbol} />
- <TopList title="Hardest to follow" entries={metrics.top_cognitive} unit="cog" onOpenSymbol={onOpenSymbol} />
- <TopList title="Longest" entries={metrics.top_long} unit="lines" onOpenSymbol={onOpenSymbol} />
- <TopList title="Most churned files (1y)" entries={metrics.top_churn} unit="commits" />
+ {/* ── Drill-down lists ──────────────────────────────────── */}
+ <div className="grid grid-cols-1 md:grid-cols-3 gap-3">
+ <TopList
+ title="Most complex"
+ entries={metrics.top_complex}
+ unit="cyclo"
+ onOpenSymbol={onOpenSymbol}
+ />
+ <TopList
+ title="Hardest to follow"
+ entries={metrics.top_cognitive}
+ unit="cog"
+ onOpenSymbol={onOpenSymbol}
+ />
+ <TopList
+ title="Longest"
+ entries={metrics.top_long}
+ unit="lines"
+ onOpenSymbol={onOpenSymbol}
+ />
</div>
+
+ {/* ── Inventory footer — facts, untoned ─────────────────── */}
+ <p className="text-[12px] text-foreground/35 tabular-nums border-t border-border/40 pt-3 mt-5">
+ {totals.callables.toLocaleString("en-US")} callables ·{" "}
+ {totals.files.toLocaleString("en-US")} files ·{" "}
+ {totals.similar_edges.toLocaleString("en-US")} near-clone edges ·{" "}
+ {totals.missed_files.toLocaleString("en-US")} files not fully indexed · computed from
+ index {metrics.generated_from}
+ {history.length > 1 && ` · trends across ${history.length} index runs`}
+ </p>
</div>
</ScrollArea>
);
diff --git a/graph-ui/src/components/OverviewTab.tsx b/graph-ui/src/components/OverviewTab.tsx
index afe2c9bb5..e8e081718 100644
--- a/graph-ui/src/components/OverviewTab.tsx
+++ b/graph-ui/src/components/OverviewTab.tsx
@@ -1,13 +1,19 @@
-/* Overview — the first read of a project: freshness, the map of regions,
- * hubs, entry points, boundaries, surprising couplings and suggested
- * questions. Everything deterministic, everything with a why, everything
- * one click from detail or from the prompt composer. */
+/* Overview — a findings feed on a landmark map. Four opinionated slots
+ * answer "is anything wrong?"; findings are sentences with evidence, a next
+ * click and a dismissal; the region map gives newcomers named landmarks;
+ * reference material (hubs, entry points, boundaries) is one disclosure
+ * away instead of shouting; inventory lives in the footer. */
import { useEffect, useMemo, useState } from "react";
import { ScrollArea } from "@/components/ui/scroll-area";
import { fetchArchitecture, archRows, type ArchitectureJson } from "../lib/atlas";
import { fetchRegions } from "../hooks/useGraphData";
-import { disambiguateRegionNames, lensRegionsPayload, isBuiltinQn } from "../lib/regions";
+import {
+ disambiguateRegionNames,
+ lensRegionsPayload,
+ isBuiltinQn,
+} from "../lib/regions";
import { surprisingCouplings, suggestedQuestions } from "../lib/firstread";
+import { kneeCount, findingKey, isDismissed, dismiss } from "../lib/findings";
import { AddToPromptButton } from "./PromptBasket";
import type { RegionsPayload } from "../lib/types";
@@ -17,6 +23,7 @@ interface OverviewTabProps {
onOpenSymbol: (qn: string) => void;
onOpenModules: () => void;
onOpenFlows: () => void;
+ onOpenDashboard: () => void;
}
interface HotspotRow {
@@ -37,17 +44,59 @@ interface LanguageRow {
files: number;
}
+interface MetricsLite {
+ generated_from: string;
+ totals: { dead: number; missed_files: number; callables: number };
+ top_churn_complex: { file?: string; value: number; commits?: number }[];
+ churn_available: boolean;
+ history: { indexed_at: string; dead: number; avg_complexity: number }[];
+}
+
function shortQn(qn: string): string {
- const parts = qn.split(".");
- return parts.slice(-2).join(".");
+ return qn.split(".").slice(-2).join(".");
}
-function Card({ title, children, wide }: { title: string; children: React.ReactNode; wide?: boolean }) {
- return (
- <div className={`bg-card border border-border/40 rounded-md p-4 ${wide ? "col-span-full" : ""}`}>
- <p className="text-[12px] uppercase tracking-widest text-foreground/45 mb-3">{title}</p>
- {children}
- </div>
+function Slot({
+ label,
+ value,
+ sub,
+ tone,
+ onClick,
+}: {
+ label: string;
+ value: string;
+ sub?: string;
+ tone?: "warn" | "crit" | "quiet";
+ onClick?: () => void;
+}) {
+ const inner = (
+ <>
+ <p className="text-[12px] uppercase tracking-widest text-foreground/40">{label}</p>
+ <p
+ className={`font-semibold tabular-nums mt-1 truncate ${
+ tone === "crit"
+ ? "text-crit text-[22px]"
+ : tone === "warn"
+ ? "text-warn text-[22px]"
+ : tone === "quiet"
+ ? "text-foreground/60 text-[15px] mt-2"
+ : "text-foreground/90 text-[22px]"
+ }`}
+ >
+ {value}
+ </p>
+ {sub && <p className="text-[12px] text-foreground/40 mt-0.5 truncate">{sub}</p>}
+ </>
+ );
+ return onClick ? (
+ <button
+ onClick={onClick}
+ className="text-left bg-card border border-border/50 rounded-md p-4 min-w-0 hover:bg-surface-3 hover:border-primary/30 transition-all"
+ >
+ {inner}
+ </button>
+ ) : (
+ <div className="bg-card border border-border/50 rounded-md p-4 min-w-0">{inner}</div>
);
}
@@ -57,26 +106,36 @@ export function OverviewTab({
onOpenSymbol,
onOpenModules,
onOpenFlows,
+ onOpenDashboard,
}: OverviewTabProps) {
const [arch, setArch] = useState<ArchitectureJson | null>(null);
const [regions, setRegions] = useState<RegionsPayload | null>(null);
+ const [metrics, setMetrics] = useState<MetricsLite | null>(null);
const [error, setError] = useState<string | null>(null);
const [includeTests, setIncludeTests] = useState(false);
+ const [dismissedTick, setDismissedTick] = useState(0);
useEffect(() => {
let cancelled = false;
setArch(null);
setRegions(null);
+ setMetrics(null);
setError(null);
- Promise.allSettled([fetchArchitecture(project), fetchRegions(project)]).then(
- ([archResult, regionsResult]) => {
- if (cancelled) return;
- if (archResult.status === "fulfilled") setArch(archResult.value);
- if (regionsResult.status === "fulfilled") setRegions(regionsResult.value);
- if (archResult.status === "rejected" && regionsResult.status === "rejected")
- setError(String(archResult.reason?.message ?? "failed to load"));
- },
- );
+ Promise.allSettled([
+ fetchArchitecture(project),
+ fetchRegions(project),
+ fetch(`/api/metrics?${new URLSearchParams({ project })}`).then((res) =>
+ res.ok ? res.json() : Promise.reject(new Error(String(res.status))),
+ ),
+ ]).then(([archResult, regionsResult, metricsResult]) => {
+ if (cancelled) return;
+ if (archResult.status === "fulfilled") setArch(archResult.value);
+ if (regionsResult.status === "fulfilled") setRegions(regionsResult.value);
+ if (metricsResult.status === "fulfilled")
+ setMetrics(metricsResult.value as MetricsLite);
+ if (archResult.status === "rejected" && regionsResult.status === "rejected")
+ setError(String(archResult.reason?.message ?? "failed to load"));
+ });
return () => {
cancelled = true;
};
@@ -90,10 +149,32 @@ export function OverviewTab({
() => (lensed ? disambiguateRegionNames(lensed.regions) : []),
[lensed],
);
- const couplings = useMemo(() => (lensed ? surprisingCouplings(lensed, 4) : []), [lensed]);
- const questions = useMemo(() => (lensed ? suggestedQuestions(lensed, {}, 4) : []), [lensed]);
+ const hiddenTestRegions =
+ regions && lensed ? regions.regions.length - lensed.regions.length : 0;
+
+ const couplings = useMemo(() => (lensed ? surprisingCouplings(lensed, 5) : []), [lensed]);
+ const questions = useMemo(
+ () =>
+ lensed ? suggestedQuestions(lensed, { deadCount: metrics?.totals.dead }, 4) : [],
+ [lensed, metrics],
+ );
+
+ /* Findings with dismissal (magnitude-bucketed keys re-alert on jumps). */
+ const findings = useMemo(() => {
+ void dismissedTick;
+ return couplings
+ .map((coupling) => ({
+ coupling,
+ key: findingKey(
+ "coupling",
+ `${coupling.source.name}⇄${coupling.target.name}`,
+ coupling.weight,
+ ),
+ }))
+ .filter((finding) => !isDismissed(finding.key));
+ }, [couplings, dismissedTick]);
+ const dismissedCount = couplings.length - findings.length;
- const hiddenTestRegions = regions && lensed ? regions.regions.length - lensed.regions.length : 0;
const hotspots = useMemo(
() => archRows<HotspotRow>(arch, "hotspots").filter((row) => !isBuiltinQn(row.qn)),
[arch],
@@ -101,13 +182,38 @@ export function OverviewTab({
const entries = useMemo(() => archRows<EntryRow>(arch, "entry_points"), [arch]);
const boundaries = useMemo(() => archRows<BoundaryRow>(arch, "boundaries"), [arch]);
const languages = useMemo(() => archRows<LanguageRow>(arch, "languages"), [arch]);
- const totalNodes = typeof arch?.total_nodes === "number" ? arch.total_nodes : regions?.total_nodes;
+ const totalNodes =
+ typeof arch?.total_nodes === "number" ? arch.total_nodes : regions?.total_nodes;
const totalEdges = typeof arch?.total_edges === "number" ? arch.total_edges : undefined;
+ /* The four slots. */
+ const attention = useMemo(() => {
+ const scores = (metrics?.top_churn_complex ?? []).map((entry) => entry.value);
+ if (scores.length === 0) return null;
+ return kneeCount(scores);
+ }, [metrics]);
+ const riskiest = metrics?.top_churn_complex?.[0] ?? null;
+ const direction = useMemo(() => {
+ const history = metrics?.history ?? [];
+ if (history.length < 2) return null;
+ const previous = history[history.length - 2];
+ const current = history[history.length - 1];
+ const deadDelta = current.dead - previous.dead;
+ const cplxDelta = current.avg_complexity - previous.avg_complexity;
+ const deadPart =
+ deadDelta === 0 ? "dead →" : `dead ${deadDelta > 0 ? "+" : ""}${deadDelta}`;
+ const cplxPart =
+ Math.abs(cplxDelta) < 0.05 ? "complexity →" : `complexity ${cplxDelta > 0 ? "↑" : "↓"}`;
+ return {
+ text: `${deadPart} · ${cplxPart}`,
+ worsening: deadDelta > 0 || cplxDelta > 0.05,
+ };
+ }, [metrics]);
+
if (error) {
return (
<div className="flex items-center justify-center h-full">
- <p className="text-red-400/80 text-sm">{error}</p>
+ <p className="text-crit/90 text-sm">{error}</p>
</div>
);
}
@@ -122,100 +228,207 @@ export function OverviewTab({
return (
<ScrollArea className="h-full">
<div className="max-w-[1200px] mx-auto px-6 py-6">
- {/* Header numbers */}
- <div className="flex flex-wrap gap-6 mb-6">
- {[
- { label: "Symbols", value: totalNodes?.toLocaleString("en-US") ?? "…" },
- { label: "Edges", value: totalEdges?.toLocaleString("en-US") ?? "…" },
- { label: "Regions", value: displayRegions.length || "…" },
- {
- label: "Languages",
- value:
- languages
- .slice(0, 3)
- .map((lang) => lang.language)
- .join(" · ") || "…",
- },
- ].map((stat) => (
- <div key={stat.label}>
- <p className="text-[12px] uppercase tracking-widest text-foreground/40">{stat.label}</p>
- <p className="text-[17px] font-semibold text-foreground/90 tabular-nums">
- {stat.value}
+ {/* The four slots: is anything wrong? */}
+ <div className="grid grid-cols-2 lg:grid-cols-4 gap-3 mb-5">
+ <Slot
+ label="Needs attention"
+ value={
+ attention === null
+ ? metrics?.churn_available === false
+ ? "—"
+ : "…"
+ : `${attention} file${attention === 1 ? "" : "s"}`
+ }
+ sub={
+ attention === null
+ ? "churn unavailable without git history"
+ : "concentrate the churn × complexity risk"
+ }
+ tone={attention !== null && attention > 0 ? "warn" : undefined}
+ onClick={onOpenDashboard}
+ />
+ <Slot
+ label="Direction"
+ value={direction ? direction.text : "first index"}
+ sub={direction ? "since the previous index" : "trends appear after the next reindex"}
+ tone={direction?.worsening ? "warn" : "quiet"}
+ />
+ <Slot
+ label="Riskiest area"
+ value={riskiest?.file?.split("/").slice(-1)[0] ?? "—"}
+ sub={
+ riskiest
+ ? `${riskiest.commits ?? "?"} commits this year × high complexity — ${riskiest.file}`
+ : "no complex churning files"
+ }
+ tone={riskiest ? "crit" : undefined}
+ onClick={onOpenDashboard}
+ />
+ <Slot
+ label="Trust"
+ value={`${metrics?.totals.missed_files ?? 0} files missed`}
+ sub={`index ${metrics?.generated_from?.slice(0, 10) ?? "…"} · ${regions?.unmapped_nodes ?? 0} unmapped symbols`}
+ tone="quiet"
+ />
+ </div>
+
+ {/* Findings — sentences with evidence, a next click, a dismissal. */}
+ {(findings.length > 0 || dismissedCount > 0) && (
+ <div className="mb-5">
+ <div className="flex items-baseline gap-3 mb-2">
+ <p className="text-[12px] uppercase tracking-widest text-foreground/40">
+ Findings
</p>
+ {dismissedCount > 0 && (
+ <span className="text-[12px] text-foreground/30">
+ {dismissedCount} dismissed
+ </span>
+ )}
</div>
- ))}
- {regions && regions.unmapped_nodes > 0 && (
- <div>
- <p className="text-[12px] uppercase tracking-widest text-foreground/40">Unmapped</p>
- <p className="text-[17px] font-semibold text-amber-300/70 tabular-nums">
- {regions.unmapped_nodes.toLocaleString("en-US")}
- </p>
+ <div className="space-y-1.5">
+ {findings.map(({ coupling, key }) => (
+ <div
+ key={key}
+ className="flex items-start gap-3 bg-card border border-border/50 rounded-md px-4 py-2.5"
+ >
+ <div className="flex-1 min-w-0">
+ <p className="text-[14px] text-foreground/85">
+ <span className="font-medium">{coupling.source.name}</span>
+ <span className="text-foreground/40"> and </span>
+ <span className="font-medium">{coupling.target.name}</span>
+ <span className="text-foreground/40"> are unusually coupled</span>
+ </p>
+ <p className="text-[12px] text-foreground/45 mt-0.5">
+ {coupling.reasons.join(" · ")}
+ </p>
+ </div>
+ <button
+ onClick={() => onOpenRegion(coupling.source.id)}
+ className="text-[12px] text-primary/80 hover:text-primary shrink-0 transition-colors"
+ >
+ inspect
+ </button>
+ <button
+ onClick={() => {
+ dismiss(key);
+ setDismissedTick((tick) => tick + 1);
+ }}
+ className="text-[12px] text-foreground/30 hover:text-foreground/60 shrink-0 transition-colors"
+ title="Dismiss as intended — re-alerts if the coupling grows an order of magnitude"
+ >
+ intended
+ </button>
+ </div>
+ ))}
</div>
- )}
- </div>
+ </div>
+ )}
+
+ {/* Questions to hand your agent. */}
+ {questions.length > 0 && (
+ <div className="mb-5">
+ <p className="text-[12px] uppercase tracking-widest text-foreground/40 mb-2">
+ Questions this graph can answer — ask your agent
+ </p>
+ <div className="grid grid-cols-1 md:grid-cols-2 gap-2">
+ {questions.map((question) => (
+ <div
+ key={question.question}
+ className="flex items-start gap-2 bg-card border border-border/50 rounded-md px-3.5 py-2.5"
+ >
+ <div className="flex-1 min-w-0">
+ <p className="text-[13px] text-foreground/80">{question.question}</p>
+ <p className="text-[12px] text-foreground/40 mt-0.5">{question.why}</p>
+ </div>
+ <AddToPromptButton
+ small
+ item={{
+ kind: "question",
+ question: question.question,
+ why: question.why,
+ }}
+ />
+ </div>
+ ))}
+ </div>
+ </div>
+ )}
- <div className="grid grid-cols-1 md:grid-cols-2 gap-4">
- {/* Regions — the map */}
- <Card title={`Regions — the de-facto modules (${regions?.method ?? "…"})`} wide>
+ {/* The landmark map. */}
+ <div className="mb-5">
+ <div className="flex items-baseline justify-between mb-2">
+ <p className="text-[12px] uppercase tracking-widest text-foreground/40">
+ Regions — the de-facto modules ({regions?.method ?? "…"})
+ </p>
{hiddenTestRegions > 0 && (
<button
onClick={() => setIncludeTests((value) => !value)}
- className="float-right -mt-7 text-[12px] text-foreground/40 hover:text-foreground/70 transition-colors"
+ className="text-[12px] text-foreground/40 hover:text-foreground/70 transition-colors"
>
{includeTests
? "hide test code"
: `${hiddenTestRegions} test region${hiddenTestRegions > 1 ? "s" : ""} hidden — show`}
</button>
)}
- <div className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-2">
- {displayRegions.slice(0, 12).map((region) => (
- <button
- key={region.id}
- onClick={() => onOpenRegion(region.id)}
- className="text-left rounded-md border border-border/30 bg-card hover:bg-surface-3 hover:border-primary/30 p-3 transition-all group"
- >
- <div className="flex items-center gap-2 mb-1">
- <span
- className="w-2 h-2 rounded-full shrink-0"
- style={{ backgroundColor: region.color }}
- />
- <span className="text-[12px] font-medium text-foreground/80 truncate group-hover:text-primary transition-colors">
- {region.name}
- </span>
- </div>
- <p className="text-[12px] text-foreground/45 truncate">
- {region.members.toLocaleString("en-US")} symbols · cohesion{" "}
- {region.cohesion.toFixed(2)}
- </p>
- {region.why && (
- <p className="text-[12px] text-foreground/40 mt-1 line-clamp-2">{region.why}</p>
- )}
- </button>
- ))}
- </div>
- {displayRegions.length > 12 && (
+ </div>
+ <div className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-2">
+ {displayRegions.slice(0, 12).map((region) => (
<button
- onClick={onOpenModules}
- className="mt-2 text-[13px] text-primary/70 hover:text-primary transition-colors"
+ key={region.id}
+ onClick={() => onOpenRegion(region.id)}
+ className="text-left rounded-md border border-border/40 bg-card hover:bg-surface-3 hover:border-primary/30 p-3 transition-all group"
>
- all {displayRegions.length} regions in Modules →
+ <div className="flex items-center gap-2 mb-1">
+ <span
+ className="w-2 h-2 rounded-full shrink-0"
+ style={{ backgroundColor: region.color }}
+ />
+ <span className="text-[13px] font-medium text-foreground/85 truncate group-hover:text-primary transition-colors">
+ {region.name}
+ </span>
+ </div>
+ <p className="text-[12px] text-foreground/45 truncate tabular-nums">
+ {region.members.toLocaleString("en-US")} symbols · cohesion{" "}
+ {region.cohesion.toFixed(2)}
+ </p>
+ {region.why && (
+ <p className="text-[12px] text-foreground/35 mt-1 line-clamp-2">
+ {region.why}
+ </p>
+ )}
</button>
- )}
- </Card>
+ ))}
+ </div>
+ {displayRegions.length > 12 && (
+ <button
+ onClick={onOpenModules}
+ className="mt-2 text-[13px] text-primary/80 hover:text-primary transition-colors"
+ >
+ all {displayRegions.length} regions in Modules →
+ </button>
+ )}
+ </div>
- {/* Hubs */}
- <Card title="Hubs — highest fan-in">
- <div className="space-y-px">
+ {/* Reference — one disclosure away, never shouting. */}
+ <details className="mb-5">
+ <summary className="cursor-pointer text-[12px] uppercase tracking-widest text-foreground/40 hover:text-foreground/60 transition-colors select-none">
+ Reference — hubs, entry points, boundaries
+ </summary>
+ <div className="grid grid-cols-1 md:grid-cols-2 gap-4 mt-3">
+ <div className="bg-card border border-border/40 rounded-md p-4">
+ <p className="text-[12px] uppercase tracking-widest text-foreground/40 mb-2">
+ Hubs — highest fan-in
+ </p>
{hotspots.slice(0, 8).map((hotspot) => (
<div key={hotspot.qn} className="flex items-center gap-2 py-[3px]">
<button
onClick={() => onOpenSymbol(hotspot.qn)}
- className="text-[13px] font-mono text-foreground/60 hover:text-primary truncate flex-1 text-left transition-colors"
+ className="text-[13px] font-mono text-foreground/65 hover:text-primary truncate flex-1 text-left transition-colors"
title={hotspot.qn}
>
{shortQn(hotspot.qn)}
</button>
- <span className="text-[12px] tabular-nums text-foreground/45 shrink-0">
+ <span className="text-[12px] tabular-nums text-foreground/35 shrink-0">
{Number(hotspot.fan_in).toLocaleString("en-US")}
</span>
</div>
@@ -224,95 +437,43 @@ export function OverviewTab({
<p className="text-[13px] text-foreground/40">No hotspot data.</p>
)}
</div>
- </Card>
-
- {/* Start here */}
- <Card title="Start here — entry points">
- <div className="space-y-px">
+ <div className="bg-card border border-border/40 rounded-md p-4">
+ <p className="text-[12px] uppercase tracking-widest text-foreground/40 mb-2">
+ Entry points
+ </p>
{entries.slice(0, 8).map((entry) => (
<button
key={entry.qn}
onClick={() => onOpenSymbol(entry.qn)}
- className="flex items-center gap-2 w-full text-left py-[3px] group"
+ className="flex items-center gap-2 w-full text-left py-[3px] group/entry"
title={entry.qn}
>
- <span className="text-[13px] font-mono text-foreground/60 group-hover:text-primary truncate transition-colors">
+ <span className="text-[13px] font-mono text-foreground/65 group-hover/entry:text-primary truncate transition-colors">
{shortQn(entry.qn)}
</span>
- <span className="text-[12px] text-foreground/35 truncate ml-auto shrink-0 max-w-[40%]">
+ <span className="text-[12px] text-foreground/30 truncate ml-auto shrink-0 max-w-[45%]">
{entry.file}
</span>
</button>
))}
- {entries.length === 0 && (
- <p className="text-[13px] text-foreground/40">No entry points detected.</p>
- )}
- </div>
- <button
- onClick={onOpenFlows}
- className="mt-2 text-[13px] text-primary/70 hover:text-primary transition-colors"
- >
- follow them in Flows →
- </button>
- </Card>
-
- {/* Surprising couplings */}
- <Card title="Surprising couplings — with reasons">
- <div className="space-y-2">
- {couplings.map((coupling) => (
- <div key={`${coupling.source.id}-${coupling.target.id}`}>
- <p className="text-[13px] text-foreground/70">
- <span className="font-medium">{coupling.source.name}</span>
- <span className="text-foreground/45"> ⇄ </span>
- <span className="font-medium">{coupling.target.name}</span>
- </p>
- <p className="text-[12px] text-foreground/45">{coupling.reasons.join(" · ")}</p>
- </div>
- ))}
- {couplings.length === 0 && (
- <p className="text-[13px] text-foreground/40">
- No cross-region couplings stand out.
- </p>
- )}
- </div>
- </Card>
-
- {/* Suggested questions */}
- <Card title="Questions this graph can answer — ask your agent">
- <div className="space-y-2">
- {questions.map((question) => (
- <div key={question.question} className="flex items-start gap-2">
- <div className="flex-1 min-w-0">
- <p className="text-[13px] text-foreground/70">{question.question}</p>
- <p className="text-[12px] text-foreground/45">{question.why}</p>
- </div>
- <AddToPromptButton
- small
- item={{ kind: "question", question: question.question, why: question.why }}
- />
- </div>
- ))}
- {questions.length === 0 && (
- <p className="text-[13px] text-foreground/40">Nothing stands out structurally.</p>
- )}
+ <button
+ onClick={onOpenFlows}
+ className="mt-2 text-[12px] text-primary/80 hover:text-primary transition-colors"
+ >
+ follow them in Flows →
+ </button>
</div>
- </Card>
-
- {/* Boundaries */}
- <Card title="Boundaries — who calls across packages" wide>
- <div className="overflow-x-auto">
+ <div className="bg-card border border-border/40 rounded-md p-4 md:col-span-2 overflow-x-auto">
+ <p className="text-[12px] uppercase tracking-widest text-foreground/40 mb-2">
+ Boundaries — cross-package calls
+ </p>
<table className="w-full text-[13px]">
- <thead>
- <tr className="text-left text-[12px] uppercase tracking-wider text-foreground/40">
- <th className="py-1 pr-4 font-medium">from</th>
- <th className="py-1 pr-4 font-medium">to</th>
- <th className="py-1 text-right font-medium">calls</th>
- </tr>
- </thead>
<tbody>
{boundaries.slice(0, 8).map((boundary, index) => (
- <tr key={index} className="border-t border-border/20">
- <td className="py-1 pr-4 font-mono text-foreground/60">{boundary.from}</td>
+ <tr key={index} className="border-t border-border/30 first:border-t-0">
+ <td className="py-1 pr-4 font-mono text-foreground/60">
+ {boundary.from}
+ </td>
<td className="py-1 pr-4 font-mono text-foreground/60">{boundary.to}</td>
<td className="py-1 text-right tabular-nums text-foreground/40">
{Number(boundary.calls).toLocaleString("en-US")}
@@ -325,8 +486,19 @@ export function OverviewTab({
<p className="text-[13px] text-foreground/40">No cross-package calls recorded.</p>
)}
</div>
- </Card>
- </div>
+ </div>
+ </details>
+
+ {/* Inventory footer — facts, untoned. */}
+ <p className="text-[12px] text-foreground/35 tabular-nums border-t border-border/40 pt-3">
+ {totalNodes?.toLocaleString("en-US") ?? "…"} symbols ·{" "}
+ {totalEdges?.toLocaleString("en-US") ?? "…"} edges ·{" "}
+ {regions?.regions.length ?? "…"} regions ·{" "}
+ {languages
+ .slice(0, 4)
+ .map((lang) => lang.language)
+ .join(" · ") || "…"}
+ </p>
</div>
</ScrollArea>
);
diff --git a/graph-ui/src/lib/findings.test.ts b/graph-ui/src/lib/findings.test.ts
new file mode 100644
index 000000000..cdcbdc357
--- /dev/null
+++ b/graph-ui/src/lib/findings.test.ts
@@ -0,0 +1,73 @@
+import { describe, expect, it } from "vitest";
+import { kneeCount, costSentence, findingKey } from "./findings";
+import { isTestRegion, lensRegionsPayload, isBuiltinQn } from "./regions";
+import type { RegionsPayload } from "./types";
+
+describe("kneeCount", () => {
+ it("finds the largest relative drop", () => {
+ /* 100, 90, 85 | 20, 18 — the knee is after the third item. */
+ expect(kneeCount([100, 90, 85, 20, 18])).toBe(3);
+ });
+ it("degenerates safely", () => {
+ expect(kneeCount([])).toBe(0);
+ expect(kneeCount([5])).toBe(1);
+ expect(kneeCount([5, 5, 5])).toBe(1);
+ });
+});
+
+describe("costSentence", () => {
+ it("renders shares of codebase and commits", () => {
+ expect(costSentence(9, 340, 800, 1000)).toBe(
+ "9 files — 1.1% of the codebase, 34% of all commits this year",
+ );
+ });
+ it("returns null without denominators", () => {
+ expect(costSentence(9, 340, 0, 1000)).toBeNull();
+ expect(costSentence(0, 0, 800, 1000)).toBeNull();
+ });
+});
+
+describe("findingKey", () => {
+ it("buckets magnitude by order of magnitude so regressions resurface", () => {
+ expect(findingKey("coupling", "a⇄b", 400)).toBe(findingKey("coupling", "a⇄b", 900));
+ expect(findingKey("coupling", "a⇄b", 400)).not.toBe(findingKey("coupling", "a⇄b", 4000));
+ });
+});
+
+describe("product-code lens", () => {
+ const payload: RegionsPayload = {
+ level: "regions",
+ method: "leiden+folders",
+ total_nodes: 100,
+ unmapped_nodes: 0,
+ regions: [
+ { id: 0, name: "src/core", files: 2, members: 10, cohesion: 0.5, top_nodes: [], x: 0, y: 0, z: 0, size: 1, color: "#111111" },
+ { id: 1, name: "tests/model_fields", files: 2, members: 10, cohesion: 0.5, top_nodes: [], x: 0, y: 0, z: 0, size: 1, color: "#222222" },
+ { id: 2, name: "tests/e2e · runner", files: 2, members: 10, cohesion: 0.5, top_nodes: [], x: 0, y: 0, z: 0, size: 1, color: "#333333" },
+ ],
+ edges: [
+ { source: 0, target: 1, weight: 5 },
+ { source: 0, target: 0, weight: 1 },
+ ],
+ };
+ it("classifies test regions including disambiguated names", () => {
+ expect(isTestRegion("src/core")).toBe(false);
+ expect(isTestRegion("tests/model_fields")).toBe(true);
+ expect(isTestRegion("tests/e2e · runner")).toBe(true);
+ expect(isTestRegion("src/contest")).toBe(false);
+ });
+ it("filters regions and their edges", () => {
+ const lensed = lensRegionsPayload(payload, false);
+ expect(lensed.regions.map((region) => region.id)).toEqual([0]);
+ expect(lensed.edges).toEqual([{ source: 0, target: 0, weight: 1 }]);
+ expect(lensRegionsPayload(payload, true)).toBe(payload);
+ });
+});
+
+describe("isBuiltinQn", () => {
+ it("catches builtin namespaces without false positives", () => {
+ expect(isBuiltinQn("proj.builtins.len")).toBe(true);
+ expect(isBuiltinQn("builtins.print")).toBe(true);
+ expect(isBuiltinQn("proj.src.mybuiltins_helper.run")).toBe(false);
+ });
+});
diff --git a/graph-ui/src/lib/findings.ts b/graph-ui/src/lib/findings.ts
new file mode 100644
index 000000000..98bc2edfd
--- /dev/null
+++ b/graph-ui/src/lib/findings.ts
@@ -0,0 +1,75 @@
+/* Findings machinery: knee-point cutoffs, the cost sentence, and finding
+ * dismissals — the difference between a dashboard and a number museum. */
+
+/* Knee of a descending score list: the index AFTER which the largest
+ * relative drop occurs — "the head that matters" (CodeScene's refusal to
+ * show 5,000 items). Returns at least 1, at most values.length. */
+export function kneeCount(values: number[]): number {
+ if (values.length <= 1) return values.length;
+ let bestIndex = 0;
+ let bestRatio = 0;
+ for (let i = 0; i < values.length - 1; i++) {
+ const current = values[i];
+ const next = values[i + 1];
+ if (current <= 0) break;
+ const ratio = (current - next) / current;
+ if (ratio > bestRatio) {
+ bestRatio = ratio;
+ bestIndex = i;
+ }
+ }
+ return bestIndex + 1;
+}
+
+/* "9 files — 1.1% of the codebase, 34% of all commits this year." */
+export function costSentence(
+ headFiles: number,
+ headCommits: number,
+ totalFiles: number,
+ totalCommits: number,
+): string | null {
+ if (headFiles <= 0 || totalFiles <= 0 || totalCommits <= 0) return null;
+ const filesShare = ((headFiles / totalFiles) * 100).toFixed(1);
+ const commitShare = ((headCommits / totalCommits) * 100).toFixed(0);
+ return `${headFiles} file${headFiles > 1 ? "s" : ""} — ${filesShare}% of the codebase, ${commitShare}% of all commits this year`;
+}
+
+/* Dismissals: a finding stays dismissed until its magnitude changes bucket
+ * (an order-of-magnitude jump resurfaces it — regression re-alerts). */
+const DISMISS_KEY = "cbm-atlas-dismissed";
+
+export function findingKey(kind: string, subject: string, magnitude: number): string {
+ const bucket = magnitude > 0 ? Math.floor(Math.log10(magnitude)) : 0;
+ return `${kind}:${subject}:${bucket}`;
+}
+
+function readDismissed(): Set<string> {
+ try {
+ const raw = localStorage.getItem(DISMISS_KEY);
+ return new Set(raw ? (JSON.parse(raw) as string[]) : []);
+ } catch {
+ return new Set();
+ }
+}
+
+export function isDismissed(key: string): boolean {
+ return readDismissed().has(key);
+}
+
+export function dismiss(key: string): void {
+ try {
+ const set = readDismissed();
+ set.add(key);
+ localStorage.setItem(DISMISS_KEY, JSON.stringify([...set]));
+ } catch {
+ /* private mode — dismissals just don't persist */
+ }
+}
+
+export function undismissAll(): void {
+ try {
+ localStorage.removeItem(DISMISS_KEY);
+ } catch {
+ /* ignore */
+ }
+}
diff --git a/graph-ui/tsconfig.tsbuildinfo b/graph-ui/tsconfig.tsbuildinfo
index 255a8b2a1..a0fd99ce3 100644
--- a/graph-ui/tsconfig.tsbuildinfo
+++ b/graph-ui/tsconfig.tsbuildinfo
@@ -1 +1 @@
-{"root":["./src/app.tsx","./src/main.tsx","./src/vite-env.d.ts","./src/api/rpc.ts","./src/components/changestab.tsx","./src/components/commandk.tsx","./src/components/controltab.tsx","./src/components/dashboardtab.tsx","./src/components/displaysettingsmenu.tsx","./src/components/edgelines.tsx","./src/components/errorboundary.tsx","./src/components/filterpanel.tsx","./src/components/flowstab.tsx","./src/components/graphloader.tsx","./src/components/graphscene.test.ts","./src/components/graphscene.tsx","./src/components/graphtab.deadcode.test.tsx","./src/components/graphtab.filters.test.tsx","./src/components/graphtab.regions.test.tsx","./src/components/graphtab.test.ts","./src/components/graphtab.tsx","./src/components/missedcallout.tsx","./src/components/modulestab.tsx","./src/components/nodecloud.tsx","./src/components/nodedetailpanel.showmore.test.tsx","./src/components/nodedetailpanel.test.tsx","./src/components/nodedetailpanel.tsx","./src/components/nodelabels.tsx","./src/components/nodetooltip.tsx","./src/components/overviewtab.tsx","./src/components/projectcard.tsx","./src/components/promptbasket.tsx","./src/components/regionpanel.tsx","./src/components/resizehandle.tsx","./src/components/sidebar.tsx","./src/components/statstab.test.tsx","./src/components/statstab.tsx","./src/components/symboltab.tsx","./src/components/tabbar.tsx","./src/components/ui/badge.tsx","./src/components/ui/button.tsx","./src/components/ui/card.tsx","./src/components/ui/checkbox.tsx","./src/components/ui/input.tsx","./src/components/ui/scroll-area.tsx","./src/components/ui/separator.tsx","./src/hooks/usegraphdata.test.ts","./src/hooks/usegraphdata.ts","./src/hooks/useprojects.ts","./src/lib/atlas.test.ts","./src/lib/atlas.ts","./src/lib/colors.ts","./src/lib/composer.ts","./src/lib/density.test.ts","./src/lib/density.ts","./src/lib/firstread.ts","./src/lib/i18n.test.ts","./src/lib/i18n.ts","./src/lib/regions.test.ts","./src/lib/regions.ts","./src/lib/treemap.ts","./src/lib/types.ts","./src/lib/utils.ts"],"version":"5.9.3"}
\ No newline at end of file
+{"root":["./src/app.tsx","./src/main.tsx","./src/vite-env.d.ts","./src/api/rpc.ts","./src/components/changestab.tsx","./src/components/commandk.tsx","./src/components/controltab.tsx","./src/components/dashboardtab.tsx","./src/components/displaysettingsmenu.tsx","./src/components/edgelines.tsx","./src/components/errorboundary.tsx","./src/components/filterpanel.tsx","./src/components/flowstab.tsx","./src/components/graphloader.tsx","./src/components/graphscene.test.ts","./src/components/graphscene.tsx","./src/components/graphtab.deadcode.test.tsx","./src/components/graphtab.filters.test.tsx","./src/components/graphtab.regions.test.tsx","./src/components/graphtab.test.ts","./src/components/graphtab.tsx","./src/components/missedcallout.tsx","./src/components/modulestab.tsx","./src/components/nodecloud.tsx","./src/components/nodedetailpanel.showmore.test.tsx","./src/components/nodedetailpanel.test.tsx","./src/components/nodedetailpanel.tsx","./src/components/nodelabels.tsx","./src/components/nodetooltip.tsx","./src/components/overviewtab.tsx","./src/components/projectcard.tsx","./src/components/promptbasket.tsx","./src/components/regionpanel.tsx","./src/components/resizehandle.tsx","./src/components/sidebar.tsx","./src/components/statstab.test.tsx","./src/components/statstab.tsx","./src/components/symboltab.tsx","./src/components/tabbar.tsx","./src/components/ui/badge.tsx","./src/components/ui/button.tsx","./src/components/ui/card.tsx","./src/components/ui/checkbox.tsx","./src/components/ui/input.tsx","./src/components/ui/scroll-area.tsx","./src/components/ui/separator.tsx","./src/hooks/usegraphdata.test.ts","./src/hooks/usegraphdata.ts","./src/hooks/useprojects.ts","./src/lib/atlas.test.ts","./src/lib/atlas.ts","./src/lib/colors.ts","./src/lib/composer.ts","./src/lib/density.test.ts","./src/lib/density.ts","./src/lib/findings.test.ts","./src/lib/findings.ts","./src/lib/firstread.ts","./src/lib/i18n.test.ts","./src/lib/i18n.ts","./src/lib/regions.test.ts","./src/lib/regions.ts","./src/lib/treemap.ts","./src/lib/types.ts","./src/lib/utils.ts"],"version":"5.9.3"}
\ No newline at end of file
diff --git a/src/ui/atlas_metrics.c b/src/ui/atlas_metrics.c
index bc4387ab4..b9f48c5aa 100644
--- a/src/ui/atlas_metrics.c
+++ b/src/ui/atlas_metrics.c
@@ -44,6 +44,7 @@ typedef struct {
char *name;
char *file;
long long value;
+ long long value2; /* secondary detail (e.g. raw commits behind a score) */
} mx_entry_t;
typedef struct {
@@ -52,8 +53,8 @@ typedef struct {
} mx_top_t;
/* Keep the MX_TOP_N largest values (stable for ties: first seen wins). */
-static void mx_top_offer(mx_top_t *top, const char *qn, const char *name, const char *file,
- long long value) {
+static void mx_top_offer2(mx_top_t *top, const char *qn, const char *name, const char *file,
+ long long value, long long value2) {
int pos = top->count < MX_TOP_N ? top->count : MX_TOP_N;
while (pos > 0 && top->items[pos - 1].value < value)
pos--;
@@ -64,6 +65,7 @@ static void mx_top_offer(mx_top_t *top, const char *qn, const char *name, const
incoming.name = name ? strdup(name) : NULL;
incoming.file = file ? strdup(file) : NULL;
incoming.value = value;
+ incoming.value2 = value2;
mx_entry_t last = {0};
if (top->count == MX_TOP_N) {
last = top->items[MX_TOP_N - 1];
@@ -78,6 +80,11 @@ static void mx_top_offer(mx_top_t *top, const char *qn, const char *name, const
free(last.file);
}
+static void mx_top_offer(mx_top_t *top, const char *qn, const char *name, const char *file,
+ long long value) {
+ mx_top_offer2(top, qn, name, file, value, 0);
+}
+
static void mx_top_free(mx_top_t *top) {
for (int i = 0; i < top->count; i++) {
free(top->items[i].qn);
@@ -99,6 +106,8 @@ static void mx_top_json(yyjson_mut_doc *doc, yyjson_mut_val *root, const char *f
if (top->items[i].file)
yyjson_mut_obj_add_strcpy(doc, obj, "file", top->items[i].file);
yyjson_mut_obj_add_int(doc, obj, "value", top->items[i].value);
+ if (top->items[i].value2 > 0)
+ yyjson_mut_obj_add_int(doc, obj, "commits", top->items[i].value2);
yyjson_mut_arr_append(arr, obj);
}
yyjson_mut_obj_add_val(doc, root, field, arr);
@@ -368,6 +377,18 @@ static char *mx_build_json(cbm_store_t *store, const char *project, const char *
sqlite3_finalize(st);
}
+ /* A2. Distinct indexed files (denominator of the cost sentence). */
+ long long total_files = 0;
+ if (sqlite3_prepare_v2(db,
+ "SELECT COUNT(DISTINCT file_path) FROM nodes WHERE project=?1 AND "
+ "file_path IS NOT NULL AND file_path != ''",
+ -1, &st, NULL) == SQLITE_OK) {
+ sqlite3_bind_text(st, 1, project, -1, SQLITE_STATIC);
+ if (sqlite3_step(st) == SQLITE_ROW)
+ total_files = sqlite3_column_int64(st, 0);
+ sqlite3_finalize(st);
+ }
+
/* B. Edge certainty. */
long long calls_edges = 0, ref_edges = 0, usage_edges = 0;
if (sqlite3_prepare_v2(db,
@@ -446,13 +467,16 @@ static char *mx_build_json(cbm_store_t *store, const char *project, const char *
mx_churn_t churn = {0};
mx_churn_scan(root_path, &churn);
mx_top_t top_churn = {0}, top_risky = {0};
+ long long churn_total_commits = 0;
for (int i = 0; i < churn.key_count; i++) {
const char *file = churn.keys[i];
long long commits = (intptr_t)cbm_ht_get(churn.counts, file);
+ churn_total_commits += commits;
mx_top_offer(&top_churn, NULL, NULL, file, commits);
intptr_t max_cplx = file_cplx ? (intptr_t)cbm_ht_get(file_cplx, file) : 0;
if (max_cplx >= MX_CHURN_MIN_CPLX)
- mx_top_offer(&top_risky, NULL, NULL, file, commits * (long long)max_cplx);
+ mx_top_offer2(&top_risky, NULL, NULL, file, commits * (long long)max_cplx,
+ commits);
}
/* ── Serialize ───────────────────────────────────────────── */
@@ -466,6 +490,7 @@ static char *mx_build_json(cbm_store_t *store, const char *project, const char *
yyjson_mut_obj_add_int(doc, totals, "documented_exported", documented_exported);
yyjson_mut_obj_add_real(doc, totals, "avg_complexity",
callables > 0 ? (double)cplx_sum / (double)callables : 0.0);
+ yyjson_mut_obj_add_int(doc, totals, "files", total_files);
yyjson_mut_obj_add_val(doc, root, "totals", totals);
yyjson_mut_val *certainty = yyjson_mut_obj(doc);
@@ -489,6 +514,8 @@ static char *mx_build_json(cbm_store_t *store, const char *project, const char *
mx_top_json(doc, root, "top_churn", &top_churn);
mx_top_json(doc, root, "top_churn_complex", &top_risky);
yyjson_mut_obj_add_bool(doc, root, "churn_available", churn.counts != NULL);
+ yyjson_mut_obj_add_int(doc, root, "churn_total_commits", churn_total_commits);
+ yyjson_mut_obj_add_int(doc, root, "churn_total_files", churn.key_count);
long long callish = calls_edges + ref_edges + usage_edges;
mx_history_append_and_emit(doc, root, project, stamp, callables, dead,