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(refactoring): file-first cards, browsable list, and a visual plan modal (#590)
Raghav Chamadiyab8176af714ac
diff --git a/packages/ui/src/refactoring/index.ts b/packages/ui/src/refactoring/index.tsindex f0a32f619..d5c7d4036 100644--- a/packages/ui/src/refactoring/index.ts+++ b/packages/ui/src/refactoring/index.ts@@ -1,7 +1,9 @@export * from "./types";export * from "./meta";export * from "./plan-detail";+export * from "./plan-before";+export * from "./plan-comparison";export * from "./refactoring-plan-card";export * from "./refactoring-quadrant";-export * from "./refactoring-inspector";+export * from "./refactoring-modal";export * from "./refactoring-board";diff --git a/packages/ui/src/refactoring/plan-before.tsx b/packages/ui/src/refactoring/plan-before.tsxnew file mode 100644index 000000000..4d32a067f--- /dev/null+++ b/packages/ui/src/refactoring/plan-before.tsx@@ -0,0 +1,250 @@+"use client";++import { typeAccent } from "./meta";+import {+ cutEdges,+ cycleMembers,+ extractClassGroups,+ extractHelperOccurrences,+ moveTarget,+ type RefactoringPlan,+} from "./types";++export interface PlanBeforeProps {+ plan: RefactoringPlan;+}++function shortFile(path: string): string {+ const parts = path.split("/");+ return parts.length <= 2 ? path : `…/${parts.slice(-2).join("/")}`;+}++function baseName(path: string): string {+ const parts = path.split("/");+ return parts[parts.length - 1] ?? path;+}++/**+ * The "before" half of the before→after comparison: a synthesized picture of+ * the problem that triggered the plan. Deliberately shaped differently per type+ * so the issue reads at a glance — a tangled class, stacked duplicate sites, a+ * misplaced method reaching across, or a closed import loop.+ */+export function PlanBefore({ plan }: PlanBeforeProps) {+ const accent = typeAccent(plan.refactoring_type);++ if (plan.refactoring_type === "extract_class") {+ const groups = extractClassGroups(plan);+ const methods = groups.flatMap((g) => g.methods);+ const fields = groups.flatMap((g) => g.fields);+ const lcom4 = Number(plan.evidence?.lcom4 ?? 0);+ const shownM = methods.slice(0, 12);+ const shownF = fields.slice(0, 6);+ return (+ <div className="rounded-xl border border-[var(--color-border-default)] bg-[var(--color-bg-surface)] p-3.5">+ <div className="mb-2.5 flex items-center justify-between gap-2">+ <code className="truncate text-xs font-semibold text-[var(--color-text-primary)]">+ {plan.target_symbol || baseName(plan.file_path)}+ </code>+ {lcom4 > 0 ? (+ <span className="shrink-0 rounded-full bg-[var(--color-error)]/10 px-2 py-0.5 text-[10px] font-semibold tabular-nums text-[var(--color-error)]">+ LCOM4 {lcom4}+ </span>+ ) : null}+ </div>+ <p className="mb-2 text-[11px] text-[var(--color-text-tertiary)]">+ {methods.length} method{methods.length === 1 ? "" : "s"} and {fields.length} field+ {fields.length === 1 ? "" : "s"} packed into one class with no clear seams.+ </p>+ <div className="flex flex-wrap gap-1">+ {shownF.map((f) => (+ <code+ key={`f-${f}`}+ className="rounded bg-[var(--color-bg-elevated)] px-1.5 py-0.5 text-[11px] text-[var(--color-text-tertiary)]"+ >+ {f}+ </code>+ ))}+ {shownM.map((m) => (+ <code+ key={`m-${m}`}+ className="rounded bg-[var(--color-bg-elevated)] px-1.5 py-0.5 text-[11px] text-[var(--color-text-secondary)]"+ >+ {m}+ </code>+ ))}+ {methods.length + fields.length > shownM.length + shownF.length ? (+ <span className="px-1 py-0.5 text-[11px] text-[var(--color-text-tertiary)]">+ +{methods.length + fields.length - shownM.length - shownF.length} more+ </span>+ ) : null}+ </div>+ </div>+ );+ }++ if (plan.refactoring_type === "extract_helper") {+ const occ = extractHelperOccurrences(plan);+ const lines = Number(plan.evidence?.duplicated_lines ?? 0);+ const shown = occ.slice(0, 5);+ return (+ <div className="space-y-2">+ <p className="text-[11px] text-[var(--color-text-tertiary)]">+ The same {lines ? `~${lines}-line ` : ""}block is copy-pasted across {occ.length} site+ {occ.length === 1 ? "" : "s"}.+ </p>+ <div className="space-y-1.5">+ {shown.map((o, i) => (+ <div+ key={i}+ className="flex items-center justify-between gap-3 rounded-lg border border-dashed border-[var(--color-border-default)] bg-[var(--color-bg-surface)] px-3 py-2"+ >+ <code className="truncate text-[11px] text-[var(--color-text-secondary)]" title={o.file}>+ {shortFile(o.file)}+ </code>+ <span className="shrink-0 text-[10px] uppercase tracking-wide text-[var(--color-text-tertiary)]">+ duplicate+ </span>+ </div>+ ))}+ {occ.length > shown.length ? (+ <p className="px-1 text-[11px] text-[var(--color-text-tertiary)]">+ +{occ.length - shown.length} more copies+ </p>+ ) : null}+ </div>+ </div>+ );+ }++ if (plan.refactoring_type === "move_method") {+ const mv = moveTarget(plan);+ if (!mv) return null;+ const foreign = Number(plan.evidence?.foreign_calls ?? 0);+ const own = Number(plan.evidence?.own_calls ?? 0);+ return (+ <div className="rounded-xl border border-[var(--color-border-default)] bg-[var(--color-bg-surface)] p-3.5">+ <div className="rounded-lg border border-[var(--color-border-default)] bg-[var(--color-bg-elevated)] p-2.5">+ <div className="text-[10px] uppercase tracking-wide text-[var(--color-text-tertiary)]">+ Currently in+ </div>+ <code className="text-xs text-[var(--color-text-secondary)]">{mv.from_class}</code>+ <div className="mt-1.5 inline-flex items-center gap-1 rounded-md border border-dashed px-1.5 py-0.5" style={{ borderColor: accent }}>+ <code className="text-[11px] text-[var(--color-text-primary)]">{mv.method}()</code>+ </div>+ </div>+ <p className="mt-2.5 text-[11px] leading-relaxed text-[var(--color-text-tertiary)]">+ It reaches into{" "}+ <code className="text-[var(--color-text-secondary)]">{mv.to_class}</code>+ {foreign || own ? (+ <>+ {" "}+ {foreign} time{foreign === 1 ? "" : "s"} vs {own} call{own === 1 ? "" : "s"} to its own+ class — it belongs elsewhere.+ </>+ ) : (+ " more than its own class — it belongs elsewhere."+ )}+ </p>+ </div>+ );+ }++ if (plan.refactoring_type === "break_cycle") {+ return <CycleGraph plan={plan} accent={accent} />;+ }++ return null;+}++/** A small ring of the cycle members with arrows closing the loop. */+function CycleGraph({ plan, accent }: { plan: RefactoringPlan; accent: string }) {+ const members = cycleMembers(plan);+ const edges = cutEdges(plan);+ const n = Math.min(members.length, 8);+ if (n < 2) {+ return (+ <div className="rounded-xl border border-[var(--color-border-default)] bg-[var(--color-bg-surface)] p-3.5 text-[11px] text-[var(--color-text-tertiary)]">+ {members.length} files form an import cycle.+ </div>+ );+ }+ // Wider canvas leaves room for a file label outside each node.+ const W = 360;+ const H = 210;+ const cx = W / 2;+ const cy = H / 2;+ const r = 60;+ const cut = new Set(edges.map((e) => `${e.from}→${e.to}`));+ const pts = Array.from({ length: n }, (_, i) => {+ const a = (i / n) * Math.PI * 2 - Math.PI / 2;+ const cos = Math.cos(a);+ const sin = Math.sin(a);+ return {+ x: cx + r * cos,+ y: cy + r * sin,+ lx: cx + (r + 11) * cos,+ ly: cy + (r + 11) * sin,+ anchor: (cos > 0.15 ? "start" : cos < -0.15 ? "end" : "middle") as+ | "start"+ | "end"+ | "middle",+ file: members[i] ?? "",+ };+ });++ return (+ <div className="rounded-xl border border-[var(--color-border-default)] bg-[var(--color-bg-surface)] p-2">+ <svg viewBox={`0 0 ${W} ${H}`} width="100%" height={H} role="img" aria-label="Import cycle">+ {pts.map((p, i) => {+ const q = pts[(i + 1) % n]!;+ const isCut = cut.has(`${p.file}→${q.file}`) || cut.has(`${q.file}→${p.file}`);+ return (+ <line+ key={`e-${i}`}+ x1={p.x}+ y1={p.y}+ x2={q.x}+ y2={q.y}+ stroke={isCut ? "var(--color-error)" : accent}+ strokeWidth={isCut ? 2.5 : 1.6}+ strokeDasharray={isCut ? "4 4" : undefined}+ strokeOpacity={isCut ? 0.9 : 0.5}+ />+ );+ })}+ {pts.map((p, i) => (+ <g key={`n-${i}`}>+ <circle cx={p.x} cy={p.y} r={9} fill={accent} fillOpacity={0.9} />+ <text+ x={p.x}+ y={p.y}+ textAnchor="middle"+ dominantBaseline="central"+ fontSize={9}+ fontWeight={600}+ fill="var(--color-bg-surface)"+ >+ {i + 1}+ </text>+ <text+ x={p.lx}+ y={p.ly}+ textAnchor={p.anchor}+ dominantBaseline="central"+ fontSize={10}+ fill="currentColor"+ className="text-[var(--color-text-secondary)]"+ >+ {baseName(p.file)}+ </text>+ <title>{p.file}</title>+ </g>+ ))}+ </svg>+ <p className="px-2 pb-1 text-center text-[11px] text-[var(--color-text-tertiary)]">+ {members.length} files import each other in a closed loop.+ </p>+ </div>+ );+}diff --git a/packages/ui/src/refactoring/plan-comparison.tsx b/packages/ui/src/refactoring/plan-comparison.tsxnew file mode 100644index 000000000..1cb7412e2--- /dev/null+++ b/packages/ui/src/refactoring/plan-comparison.tsx@@ -0,0 +1,75 @@+"use client";++import { ArrowDown, ArrowRight, Check } from "lucide-react";+import { typeAccent } from "./meta";+import { PlanBefore } from "./plan-before";+import { PlanDetail } from "./plan-detail";+import type { RefactoringPlan } from "./types";++export interface PlanComparisonProps {+ plan: RefactoringPlan;+ fileHref?: ((path: string, line?: number | null) => string | undefined) | undefined;+}++/**+ * The modal centerpiece: the problem today on the left, the proposed result on+ * the right, an arrow between. The "after" reuses the per-type plan visual; the+ * "before" is the synthesized problem picture. Stacks on narrow viewports.+ */+export function PlanComparison({ plan, fileHref }: PlanComparisonProps) {+ const accent = typeAccent(plan.refactoring_type);+ return (+ <div className="relative grid gap-3 md:grid-cols-2">+ {/* before */}+ <div className="rounded-2xl border border-[var(--color-border-default)] bg-[var(--color-bg-elevated)]/40 p-4">+ <div className="mb-3 flex items-center gap-1.5">+ <span className="h-2 w-2 rounded-full bg-[var(--color-error)]" aria-hidden />+ <span className="text-xs font-semibold uppercase tracking-wide text-[var(--color-text-tertiary)]">+ Today+ </span>+ </div>+ <PlanBefore plan={plan} />+ </div>++ {/* desktop arrow — centered on the seam between the two columns */}+ <div+ className="pointer-events-none absolute left-1/2 top-1/2 z-10 hidden -translate-x-1/2 -translate-y-1/2 md:block"+ aria-hidden+ >+ <span+ className="flex h-9 w-9 items-center justify-center rounded-full border border-[var(--color-border-default)] bg-[var(--color-bg-surface)] shadow-sm"+ style={{ color: accent }}+ >+ <ArrowRight className="h-4 w-4" />+ </span>+ </div>++ {/* mobile arrow — between the stacked cards */}+ <div className="flex justify-center md:hidden" aria-hidden>+ <span+ className="flex h-7 w-7 items-center justify-center rounded-full border border-[var(--color-border-default)] bg-[var(--color-bg-surface)] shadow-sm"+ style={{ color: accent }}+ >+ <ArrowDown className="h-4 w-4" />+ </span>+ </div>++ {/* after */}+ <div+ className="rounded-2xl border p-4"+ style={{+ borderColor: `color-mix(in srgb, ${accent} 40%, transparent)`,+ backgroundColor: `color-mix(in srgb, ${accent} 5%, transparent)`,+ }}+ >+ <div className="mb-3 flex items-center gap-1.5">+ <Check className="h-3.5 w-3.5" style={{ color: accent }} />+ <span className="text-xs font-semibold uppercase tracking-wide" style={{ color: accent }}>+ After+ </span>+ </div>+ <PlanDetail plan={plan} fileHref={fileHref} hideIntro />+ </div>+ </div>+ );+}diff --git a/packages/ui/src/refactoring/plan-detail.tsx b/packages/ui/src/refactoring/plan-detail.tsxindex 9c4022647..6e4b55df7 100644--- a/packages/ui/src/refactoring/plan-detail.tsx+++ b/packages/ui/src/refactoring/plan-detail.tsx@@ -17,6 +17,9 @@ export interface PlanDetailProps {plan: RefactoringPlan;/** Render a file path as a link (e.g. to the file's health drawer). */fileHref?: ((path: string, line?: number | null) => string | undefined) | undefined;+ /** Drop the leading prose line — used when the plan is the "after" column of+ * a before→after comparison, where the intro would be redundant. */+ hideIntro?: boolean;}function shortFile(path: string): string {@@ -28,27 +31,35 @@ function FileRef({path,line,fileHref,+ className = "",}: {path: string;line?: number | null;fileHref?: PlanDetailProps["fileHref"];+ /** Extra classes, e.g. `block truncate` inside a `min-w-0` flex item. */+ className?: string;}) {- const label = (- <span className="font-mono text-xs text-[var(--color-text-secondary)]">+ const inner = (+ <>{shortFile(path)}{line ? <span className="text-[var(--color-text-tertiary)]">:{line}</span> : null}- </span>+ </>);const href = fileHref?.(path, line ?? null);- if (!href) return label;+ if (!href) {+ return (+ <span className={`font-mono text-xs text-[var(--color-text-secondary)] ${className}`} title={path}>+ {inner}+ </span>+ );+ }return (<ahref={href}- className="font-mono text-xs text-[var(--color-text-secondary)] underline-offset-2 hover:text-[var(--color-accent-primary)] hover:underline"+ className={`font-mono text-xs text-[var(--color-text-secondary)] underline-offset-2 hover:text-[var(--color-accent-primary)] hover:underline ${className}`}title={path}>- {shortFile(path)}- {line ? <span className="text-[var(--color-text-tertiary)]">:{line}</span> : null}+ {inner}</a>);}@@ -58,7 +69,7 @@ function FileRef({* tree, the move as an arrow, clone occurrences as a list, the cycle as cut* edges. This is the "what exactly to do" — the heart of the surface.*/-export function PlanDetail({ plan, fileHref }: PlanDetailProps) {+export function PlanDetail({ plan, fileHref, hideIntro = false }: PlanDetailProps) {const accent = typeAccent(plan.refactoring_type);if (plan.refactoring_type === "extract_class") {@@ -67,10 +78,12 @@ export function PlanDetail({ plan, fileHref }: PlanDetailProps) {);return (<div className="space-y-3">- <p className="text-xs text-[var(--color-text-tertiary)]">- Split into {groups.length} cohesive group{groups.length === 1 ? "" : "s"} — each- group's methods travel with the fields they touch.- </p>+ {hideIntro ? null : (+ <p className="text-xs text-[var(--color-text-tertiary)]">+ Split into {groups.length} cohesive group{groups.length === 1 ? "" : "s"} — each+ group's methods travel with the fields they touch.+ </p>+ )}<div className="grid gap-2.5 sm:grid-cols-2">{groups.map((g, i) => (<div@@ -132,24 +145,28 @@ export function PlanDetail({ plan, fileHref }: PlanDetailProps) {const site = helperSite(plan);return (<div className="space-y-3">- <p className="text-xs text-[var(--color-text-tertiary)]">- The same block appears in {occ.length} place{occ.length === 1 ? "" : "s"}. Extract- it once- {site ? (- <>- {" "}- near{" "}- <code className="rounded bg-[var(--color-bg-elevated)] px-1 py-0.5 text-[11px] text-[var(--color-text-secondary)]">- {site}- </code>- </>- ) : null}- .- </p>+ {hideIntro ? null : (+ <p className="text-xs text-[var(--color-text-tertiary)]">+ The same block appears in {occ.length} place{occ.length === 1 ? "" : "s"}. Extract+ it once+ {site ? (+ <>+ {" "}+ near{" "}+ <code className="rounded bg-[var(--color-bg-elevated)] px-1 py-0.5 text-[11px] text-[var(--color-text-secondary)]">+ {site}+ </code>+ </>+ ) : null}+ .+ </p>+ )}<ul className="divide-y divide-[var(--color-border-default)] overflow-hidden rounded-xl border border-[var(--color-border-default)] bg-[var(--color-bg-surface)]">{occ.map((o, i) => (<li key={i} className="flex items-center justify-between gap-3 px-3.5 py-2.5">- <FileRef path={o.file} line={o.line_start} fileHref={fileHref} />+ <span className="min-w-0 flex-1">+ <FileRef path={o.file} line={o.line_start} fileHref={fileHref} className="block truncate" />+ </span><span className="shrink-0 text-[11px] tabular-nums text-[var(--color-text-tertiary)]">lines {o.line_start}–{o.line_end}</span>@@ -165,9 +182,11 @@ export function PlanDetail({ plan, fileHref }: PlanDetailProps) {if (!mv) return null;return (<div className="space-y-3">- <p className="text-xs text-[var(--color-text-tertiary)]">- This method leans on another class's data more than its own — move it home.- </p>+ {hideIntro ? null : (+ <p className="text-xs text-[var(--color-text-tertiary)]">+ This method leans on another class's data more than its own — move it home.+ </p>+ )}<div className="flex flex-wrap items-center gap-3 rounded-xl border border-[var(--color-border-default)] bg-[var(--color-bg-surface)] p-4"><div className="rounded-lg border border-[var(--color-border-default)] bg-[var(--color-bg-elevated)] px-3 py-2"><div className="text-[10px] uppercase tracking-wide text-[var(--color-text-tertiary)]">@@ -203,24 +222,26 @@ export function PlanDetail({ plan, fileHref }: PlanDetailProps) {const edges = cutEdges(plan);return (<div className="space-y-3">- <p className="text-xs text-[var(--color-text-tertiary)]">- {members.length} files import each other in a cycle. Cut {edges.length} edge- {edges.length === 1 ? "" : "s"} to break it.- </p>+ {hideIntro ? null : (+ <p className="text-xs text-[var(--color-text-tertiary)]">+ {members.length} files import each other in a cycle. Cut {edges.length} edge+ {edges.length === 1 ? "" : "s"} to break it.+ </p>+ )}<div className="space-y-2 rounded-xl border border-[var(--color-border-default)] bg-[var(--color-bg-surface)] p-3.5"><div className="text-[10px] uppercase tracking-wide text-[var(--color-text-tertiary)]">Cut these import edges</div>{edges.map((e, i) => (- <div key={i} className="flex items-center gap-2 text-xs">+ <div key={i} className="flex flex-wrap items-center gap-x-2 gap-y-1 text-xs"><Scissors className="h-3.5 w-3.5 shrink-0" style={{ color: accent }} />- <FileRef path={e.from} fileHref={fileHref} />+ <FileRef path={e.from} fileHref={fileHref} className="min-w-0 truncate" /><ArrowRight className="h-3.5 w-3.5 shrink-0 text-[var(--color-text-tertiary)]" />- <FileRef path={e.to} fileHref={fileHref} />+ <FileRef path={e.to} fileHref={fileHref} className="min-w-0 truncate" /></div>))}{members.length > 0 ? (- <div className="pt-1 text-[11px] text-[var(--color-text-tertiary)]">+ <div className="break-words pt-1 text-[11px] leading-relaxed text-[var(--color-text-tertiary)]">Cycle: {members.map(shortFile).join(" → ")}</div>) : null}diff --git a/packages/ui/src/refactoring/refactoring-board.tsx b/packages/ui/src/refactoring/refactoring-board.tsxindex 8a2da4a91..48143e950 100644--- a/packages/ui/src/refactoring/refactoring-board.tsx+++ b/packages/ui/src/refactoring/refactoring-board.tsx@@ -1,15 +1,30 @@"use client";-import { useCallback, useEffect, useState } from "react";-import { Wrench } from "lucide-react";+import { useCallback, useEffect, useMemo, useState } from "react";+import { Search, Wrench } from "lucide-react";+import { Input } from "../ui/input";import { RefactoringPlanCard } from "./refactoring-plan-card";import { RefactoringQuadrant } from "./refactoring-quadrant";-import { RefactoringInspector } from "./refactoring-inspector";-import { typeAccent, typeMeta, TYPE_ORDER } from "./meta";-import type { RefactoringPlan, RefactoringSummary } from "./types";+import { RefactoringModal } from "./refactoring-modal";+import { typeAccent, typeMeta, CONFIDENCE_LABEL, TYPE_ORDER } from "./meta";+import { blastCount, type Confidence, type EffortBucket, type RefactoringPlan, type RefactoringSummary } from "./types";const PAGE_SIZE = 60;+const EFFORTS: EffortBucket[] = ["S", "M", "L", "XL"];+const EFFORT_RANK: Record<EffortBucket, number> = { S: 0, M: 1, L: 2, XL: 3 };+const CONFIDENCES: Confidence[] = ["high", "medium", "low"];++type SortKey = "priority" | "health" | "effort" | "blast" | "file";++const SORT_OPTIONS: { value: SortKey; label: string }[] = [+ { value: "priority", label: "Priority" },+ { value: "health", label: "Health recovered" },+ { value: "effort", label: "Effort (low first)" },+ { value: "blast", label: "Blast radius" },+ { value: "file", label: "File (A–Z)" },+];+export interface RefactoringBoardProps {plans: RefactoringPlan[];summary?: RefactoringSummary;@@ -24,8 +39,9 @@ export interface RefactoringBoardProps {/*** The Refactoring surface. The priority×effort quadrant is the full-width- * centerpiece; a calm grid of compact plan cards sits below it. Clicking the- * quadrant or a card opens the visual inspector for that one plan. No table.+ * centerpiece; a searchable, sortable, filterable grid of compact plan cards+ * sits below it. Clicking the quadrant or a card opens the visual modal for+ * that one plan. No table.*/export function RefactoringBoard({plans,@@ -38,20 +54,66 @@ export function RefactoringBoard({}: RefactoringBoardProps) {const [highlighted, setHighlighted] = useState<string | null>(null);const [selected, setSelected] = useState<RefactoringPlan | null>(null);- const [inspectorOpen, setInspectorOpen] = useState(false);+ const [modalOpen, setModalOpen] = useState(false);++ // List controls — make hundreds of plans browsable.+ const [query, setQuery] = useState("");+ const [sortKey, setSortKey] = useState<SortKey>("priority");+ const [effortSel, setEffortSel] = useState<Set<EffortBucket>>(new Set());+ const [confSel, setConfSel] = useState<Set<Confidence>>(new Set());+// Render the top-ranked cards first and grow on demand — a repo can surface// hundreds of plans and mounting them all at once would jank the grid.const [visibleCount, setVisibleCount] = useState(PAGE_SIZE);- // Reset the window whenever the (already rank-ordered) plan set changes,- // e.g. on a type-filter switch, so the top is always shown first.+ const toggle = useCallback(<T,>(setter: React.Dispatch<React.SetStateAction<Set<T>>>, value: T) => {+ setter((cur) => {+ const next = new Set(cur);+ if (next.has(value)) next.delete(value);+ else next.add(value);+ return next;+ });+ }, []);++ const processed = useMemo(() => {+ const q = query.trim().toLowerCase();+ let out = plans.filter((p) => {+ if (q && !`${p.file_path} ${p.target_symbol}`.toLowerCase().includes(q)) return false;+ if (effortSel.size && !effortSel.has((p.effort_bucket || "M") as EffortBucket)) return false;+ if (confSel.size && !confSel.has((p.confidence || "medium") as Confidence)) return false;+ return true;+ });+ // `priority` keeps the backend's rank order; the rest sort a copy.+ if (sortKey !== "priority") {+ out = [...out].sort((a, b) => {+ switch (sortKey) {+ case "health":+ return b.impact_delta - a.impact_delta;+ case "effort":+ return (+ EFFORT_RANK[(a.effort_bucket || "M") as EffortBucket] -+ EFFORT_RANK[(b.effort_bucket || "M") as EffortBucket]+ );+ case "blast":+ return blastCount(b) - blastCount(a);+ case "file":+ return a.file_path.localeCompare(b.file_path);+ default:+ return 0;+ }+ });+ }+ return out;+ }, [plans, query, sortKey, effortSel, confSel]);++ // Reset the window whenever the visible set changes (filter/sort/search/type).useEffect(() => {setVisibleCount(PAGE_SIZE);- }, [plans]);+ }, [processed]);const openPlan = useCallback((plan: RefactoringPlan) => {setSelected(plan);- setInspectorOpen(true);+ setModalOpen(true);}, []);const pickFromQuadrant = useCallback(@@ -76,6 +138,7 @@ export function RefactoringBoard({}const counts = new Map((summary?.by_type ?? []).map((c) => [c.type, c.count]));+ const filtersActive = query.trim() !== "" || effortSel.size > 0 || confSel.size > 0;return (<div className="space-y-8">@@ -112,44 +175,159 @@ export function RefactoringBoard({</section>) : null}- <section className="space-y-3">- <h3 className="text-sm font-semibold text-[var(--color-text-primary)]">- {plans.length} plan{plans.length === 1 ? "" : "s"}- </h3>- <div className="grid gap-4 sm:grid-cols-2 xl:grid-cols-3">- {plans.slice(0, visibleCount).map((plan) => (- <RefactoringPlanCard- key={plan.id}- plan={plan}- onOpen={openPlan}- onAiPrompt={onAiPrompt}- highlighted={highlighted === plan.id}+ <section className="space-y-4">+ {/* control bar */}+ <div className="flex flex-wrap items-center gap-3">+ <div className="relative min-w-[220px] flex-1">+ <Search className="pointer-events-none absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-[var(--color-text-tertiary)]" />+ <Input+ value={query}+ onChange={(e) => setQuery(e.target.value)}+ placeholder="Search file or symbol…"+ className="pl-9"+ aria-label="Search plans"/>- ))}+ </div>++ <div className="flex items-center gap-1.5">+ <label htmlFor="refactoring-sort" className="text-xs text-[var(--color-text-tertiary)]">+ Sort+ </label>+ <select+ id="refactoring-sort"+ value={sortKey}+ onChange={(e) => setSortKey(e.target.value as SortKey)}+ className="h-9 rounded-md border border-[var(--color-border-default)] bg-[var(--color-bg-surface)] px-2.5 text-sm text-[var(--color-text-primary)] transition-colors focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-[var(--color-accent-primary)]"+ >+ {SORT_OPTIONS.map((o) => (+ <option key={o.value} value={o.value}>+ {o.label}+ </option>+ ))}+ </select>+ </div></div>- {plans.length > visibleCount ? (- <div className="flex justify-center pt-1">++ {/* quick filters */}+ <div className="flex flex-wrap items-center gap-x-4 gap-y-2">+ <div className="flex items-center gap-1.5">+ <span className="text-[11px] uppercase tracking-wide text-[var(--color-text-tertiary)]">+ Effort+ </span>+ {EFFORTS.map((e) => (+ <FilterChip+ key={e}+ active={effortSel.has(e)}+ onClick={() => toggle(setEffortSel, e)}+ label={e}+ />+ ))}+ </div>+ <div className="flex items-center gap-1.5">+ <span className="text-[11px] uppercase tracking-wide text-[var(--color-text-tertiary)]">+ Confidence+ </span>+ {CONFIDENCES.map((c) => (+ <FilterChip+ key={c}+ active={confSel.has(c)}+ onClick={() => toggle(setConfSel, c)}+ label={CONFIDENCE_LABEL[c]}+ />+ ))}+ </div>+ </div>++ {/* count + reset */}+ <div className="flex items-center justify-between">+ <h3 className="text-sm font-semibold text-[var(--color-text-primary)]">+ {processed.length} plan{processed.length === 1 ? "" : "s"}+ {filtersActive ? (+ <span className="font-normal text-[var(--color-text-tertiary)]"> of {plans.length}</span>+ ) : null}+ </h3>+ {filtersActive ? (<buttontype="button"- onClick={() => setVisibleCount((n) => n + PAGE_SIZE)}- className="inline-flex items-center gap-1.5 rounded-lg border border-[var(--color-border-default)] px-4 py-2 text-sm font-medium text-[var(--color-text-secondary)] transition-colors hover:border-[var(--color-border-strong)] hover:text-[var(--color-text-primary)]"+ onClick={() => {+ setQuery("");+ setEffortSel(new Set());+ setConfSel(new Set());+ }}+ className="text-xs text-[var(--color-text-secondary)] underline-offset-2 hover:text-[var(--color-text-primary)] hover:underline">- Show {Math.min(PAGE_SIZE, plans.length - visibleCount)} more- <span className="text-[var(--color-text-tertiary)]">- · {plans.length - visibleCount} left- </span>+ Clear filters</button>+ ) : null}+ </div>++ {processed.length === 0 ? (+ <div className="rounded-2xl border border-dashed border-[var(--color-border-default)] bg-[var(--color-bg-surface)] px-6 py-12 text-center text-sm text-[var(--color-text-tertiary)]">+ No plans match these filters.</div>- ) : null}+ ) : (+ <>+ <div className="grid gap-4 sm:grid-cols-2 xl:grid-cols-3">+ {processed.slice(0, visibleCount).map((plan) => (+ <RefactoringPlanCard+ key={plan.id}+ plan={plan}+ onOpen={openPlan}+ onAiPrompt={onAiPrompt}+ highlighted={highlighted === plan.id}+ />+ ))}+ </div>+ {processed.length > visibleCount ? (+ <div className="flex justify-center pt-1">+ <button+ type="button"+ onClick={() => setVisibleCount((n) => n + PAGE_SIZE)}+ className="inline-flex items-center gap-1.5 rounded-lg border border-[var(--color-border-default)] px-4 py-2 text-sm font-medium text-[var(--color-text-secondary)] transition-colors hover:border-[var(--color-border-strong)] hover:text-[var(--color-text-primary)]"+ >+ Show {Math.min(PAGE_SIZE, processed.length - visibleCount)} more+ <span className="text-[var(--color-text-tertiary)]">+ · {processed.length - visibleCount} left+ </span>+ </button>+ </div>+ ) : null}+ </>+ )}</section>- <RefactoringInspector+ <RefactoringModalplan={selected}- open={inspectorOpen}- onOpenChange={setInspectorOpen}+ open={modalOpen}+ onOpenChange={setModalOpen}onAiPrompt={onAiPrompt}fileHref={fileHref}/></div>);}++function FilterChip({+ active,+ onClick,+ label,+}: {+ active: boolean;+ onClick: () => void;+ label: string;+}) {+ return (+ <button+ type="button"+ onClick={onClick}+ aria-pressed={active}+ className={`rounded-full border px-2.5 py-0.5 text-xs font-medium transition-colors ${+ active+ ? "border-[var(--color-accent-primary)] bg-[var(--color-accent-muted)] text-[var(--color-accent-primary)]"+ : "border-[var(--color-border-default)] text-[var(--color-text-secondary)] hover:border-[var(--color-border-strong)] hover:text-[var(--color-text-primary)]"+ }`}+ >+ {label}+ </button>+ );+}diff --git a/packages/ui/src/refactoring/refactoring-inspector.tsx b/packages/ui/src/refactoring/refactoring-inspector.tsxdeleted file mode 100644index 90bac51eb..000000000--- a/packages/ui/src/refactoring/refactoring-inspector.tsx+++ /dev/null@@ -1,208 +0,0 @@-"use client";--import { Layers, Sparkles } from "lucide-react";-import { Sheet, SheetContent, SheetHeader, SheetTitle } from "../ui/sheet";-import { PlanDetail } from "./plan-detail";-import { CONFIDENCE_LABEL, EFFORT_LABEL, typeAccent, typeMeta } from "./meta";-import {- blastCount,- blastFiles,- type Confidence,- type EffortBucket,- type RefactoringPlan,-} from "./types";--export interface RefactoringInspectorProps {- plan: RefactoringPlan | null;- open: boolean;- onOpenChange: (open: boolean) => void;- onAiPrompt?: ((plan: RefactoringPlan) => void) | undefined;- fileHref?: ((path: string, line?: number | null) => string | undefined) | undefined;-}--const EVIDENCE_LABELS: Record<string, string> = {- lcom4: "LCOM4",- method_count: "Methods",- field_count: "Fields",- wmc: "WMC",- occurrence_count: "Occurrences",- duplicated_lines: "Duplicated lines",- co_change_count: "Co-changes",- foreign_calls: "Calls to target",- own_calls: "Calls to own class",- own_distance: "Distance to own",- target_distance: "Distance to target",- cycle_size: "Cycle size",- edge_count: "Edges in cycle",- cut_count: "Edges to cut",-};--function evidenceRows(plan: RefactoringPlan): { label: string; value: string }[] {- const rows: { label: string; value: string }[] = [];- for (const [key, label] of Object.entries(EVIDENCE_LABELS)) {- const v = plan.evidence?.[key];- if (typeof v === "number" && Number.isFinite(v)) {- rows.push({ label, value: Number.isInteger(v) ? String(v) : v.toFixed(2) });- }- }- return rows;-}--/**- * The slide-over that renders one plan visually: the concrete per-type plan,- * the evidence behind it, and the blast radius. Mounted only for the selected- * plan, so the heavy visual cost is paid once, on demand.- */-export function RefactoringInspector({- plan,- open,- onOpenChange,- onAiPrompt,- fileHref,-}: RefactoringInspectorProps) {- return (- <Sheet open={open} onOpenChange={onOpenChange}>- <SheetContent- side="right"- className="w-full gap-0 overflow-y-auto p-0 sm:max-w-xl"- >- {plan ? <InspectorBody plan={plan} onAiPrompt={onAiPrompt} fileHref={fileHref} /> : null}- </SheetContent>- </Sheet>- );-}--function InspectorBody({- plan,- onAiPrompt,- fileHref,-}: {- plan: RefactoringPlan;- onAiPrompt?: ((plan: RefactoringPlan) => void) | undefined;- fileHref?: ((path: string, line?: number | null) => string | undefined) | undefined;-}) {- const meta = typeMeta(plan.refactoring_type);- const accent = typeAccent(plan.refactoring_type);- const { Icon } = meta;- const effort = (plan.effort_bucket || "M") as EffortBucket;- const confidence = (plan.confidence || "medium") as Confidence;- const evidence = evidenceRows(plan);- const blast = blastFiles(plan).filter((f) => f !== plan.file_path);- const blastN = blastCount(plan);-- return (- <>- <SheetHeader className="border-b border-[var(--color-border-default)] px-6 py-5 pr-12">- <SheetTitle className="flex items-center gap-3 text-base">- <span- className="flex h-9 w-9 shrink-0 items-center justify-center rounded-xl"- style={{ backgroundColor: `color-mix(in srgb, ${accent} 14%, transparent)`, color: accent }}- >- <Icon className="h-[18px] w-[18px]" />- </span>- <span className="min-w-0">- <span className="block font-semibold text-[var(--color-text-primary)]">{meta.label}</span>- <code className="block truncate text-xs font-normal text-[var(--color-text-secondary)]">- {plan.target_symbol}- </code>- </span>- </SheetTitle>- </SheetHeader>-- <div className="space-y-6 px-6 py-5">- <p className="text-sm leading-relaxed text-[var(--color-text-secondary)]">{meta.blurb}</p>-- {/* Signal chips */}- <div className="flex flex-wrap gap-2">- <Chip label="Effort" value={EFFORT_LABEL[effort]} />- <Chip label="Confidence" value={CONFIDENCE_LABEL[confidence]} />- {blastN > 0 ? <Chip label="Touches" value={`${blastN} file${blastN === 1 ? "" : "s"}`} /> : null}- {plan.impact_delta > 0 ? <Chip label="Recovers" value={`+${plan.impact_delta.toFixed(2)}`} /> : null}- </div>-- {/* The visual plan */}- <section>- <h4 className="mb-2.5 text-xs font-semibold uppercase tracking-wide text-[var(--color-text-tertiary)]">- The plan- </h4>- <PlanDetail plan={plan} fileHref={fileHref} />- </section>-- {/* Evidence */}- {evidence.length > 0 ? (- <section>- <h4 className="mb-2.5 text-xs font-semibold uppercase tracking-wide text-[var(--color-text-tertiary)]">- Why this was flagged- </h4>- <dl className="grid grid-cols-2 gap-2 sm:grid-cols-3">- {evidence.map((row) => (- <div- key={row.label}- className="rounded-lg border border-[var(--color-border-default)] bg-[var(--color-bg-surface)] px-3 py-2"- >- <dt className="text-[10px] uppercase tracking-wide text-[var(--color-text-tertiary)]">- {row.label}- </dt>- <dd className="mt-0.5 text-sm font-semibold tabular-nums text-[var(--color-text-primary)]">- {row.value}- </dd>- </div>- ))}- </dl>- </section>- ) : null}-- {/* Blast radius */}- {blast.length > 0 ? (- <section>- <h4 className="mb-2.5 flex items-center gap-1.5 text-xs font-semibold uppercase tracking-wide text-[var(--color-text-tertiary)]">- <Layers className="h-3.5 w-3.5" />- Also affected- </h4>- <ul className="space-y-1">- {blast.map((f) => {- const href = fileHref?.(f, null);- return (- <li key={f}>- {href ? (- <a- href={href}- className="font-mono text-xs text-[var(--color-text-secondary)] underline-offset-2 hover:text-[var(--color-accent-primary)] hover:underline"- >- {f}- </a>- ) : (- <span className="font-mono text-xs text-[var(--color-text-secondary)]">{f}</span>- )}- </li>- );- })}- </ul>- </section>- ) : null}- </div>-- {onAiPrompt ? (- <div className="sticky bottom-0 mt-auto border-t border-[var(--color-border-default)] bg-[var(--color-bg-surface)] px-6 py-4">- <button- type="button"- onClick={() => onAiPrompt(plan)}- className="inline-flex items-center gap-2 rounded-lg bg-[var(--color-accent-primary)] px-3.5 py-2 text-sm font-semibold text-[var(--color-bg-surface)] transition-opacity hover:opacity-90"- >- <Sparkles className="h-4 w-4" />- Get AI prompt- </button>- </div>- ) : null}- </>- );-}--function Chip({ label, value }: { label: string; value: string }) {- return (- <span className="inline-flex items-center gap-1.5 rounded-full border border-[var(--color-border-default)] bg-[var(--color-bg-surface)] px-3 py-1 text-xs">- <span className="text-[var(--color-text-tertiary)]">{label}</span>- <span className="font-medium text-[var(--color-text-primary)]">{value}</span>- </span>- );-}diff --git a/packages/ui/src/refactoring/refactoring-modal.tsx b/packages/ui/src/refactoring/refactoring-modal.tsxnew file mode 100644index 000000000..334fee1f5--- /dev/null+++ b/packages/ui/src/refactoring/refactoring-modal.tsx@@ -0,0 +1,250 @@+"use client";++import { Layers, Sparkles, TrendingUp } from "lucide-react";+import { Dialog, DialogContent, DialogTitle } from "../ui/dialog";+import { PlanComparison } from "./plan-comparison";+import { CONFIDENCE_LABEL, EFFORT_LABEL, typeAccent, typeMeta } from "./meta";+import {+ blastCount,+ blastFiles,+ evidenceRows,+ planWins,+ type Confidence,+ type EffortBucket,+ type RefactoringPlan,+} from "./types";++export interface RefactoringModalProps {+ plan: RefactoringPlan | null;+ open: boolean;+ onOpenChange: (open: boolean) => void;+ onAiPrompt?: ((plan: RefactoringPlan) => void) | undefined;+ fileHref?: ((path: string, line?: number | null) => string | undefined) | undefined;+}++function fileParts(path: string): { name: string; dir: string } {+ const parts = path.split("/");+ const name = parts[parts.length - 1] ?? path;+ const dir = parts.slice(0, -1).join("/");+ return { name, dir };+}++/**+ * The plan inspector as a large, centered modal. Leads with the file, frames+ * the health it recovers as the win, and shows the refactoring as a visual+ * before→after. Mounted only for the selected plan, so the heavy visual cost+ * is paid once, on demand.+ */+export function RefactoringModal({+ plan,+ open,+ onOpenChange,+ onAiPrompt,+ fileHref,+}: RefactoringModalProps) {+ return (+ <Dialog open={open} onOpenChange={onOpenChange}>+ <DialogContent className="max-h-[90vh] w-[calc(100%-1.5rem)] max-w-4xl gap-0 overflow-y-auto p-0">+ {plan ? (+ <ModalBody plan={plan} onAiPrompt={onAiPrompt} fileHref={fileHref} />+ ) : (+ <DialogTitle className="sr-only">Refactoring plan</DialogTitle>+ )}+ </DialogContent>+ </Dialog>+ );+}++function ModalBody({+ plan,+ onAiPrompt,+ fileHref,+}: {+ plan: RefactoringPlan;+ onAiPrompt?: ((plan: RefactoringPlan) => void) | undefined;+ fileHref?: ((path: string, line?: number | null) => string | undefined) | undefined;+}) {+ const meta = typeMeta(plan.refactoring_type);+ const accent = typeAccent(plan.refactoring_type);+ const { Icon } = meta;+ const effort = (plan.effort_bucket || "M") as EffortBucket;+ const confidence = (plan.confidence || "medium") as Confidence;+ const evidence = evidenceRows(plan);+ const wins = planWins(plan);+ const blast = blastFiles(plan).filter((f) => f !== plan.file_path);+ const blastN = blastCount(plan);+ const { name, dir } = fileParts(plan.file_path);++ return (+ <>+ {/* header — file first, type as a colored accent, win badge on the right */}+ <div+ className="border-b border-[var(--color-border-default)] px-6 py-5 pr-12"+ style={{ background: `linear-gradient(to bottom, color-mix(in srgb, ${accent} 6%, transparent), transparent)` }}+ >+ <div className="flex flex-wrap items-start justify-between gap-3">+ <div className="flex min-w-0 items-start gap-3">+ <span+ className="mt-0.5 flex h-9 w-9 shrink-0 items-center justify-center rounded-xl"+ style={{ backgroundColor: `color-mix(in srgb, ${accent} 14%, transparent)`, color: accent }}+ >+ <Icon className="h-[18px] w-[18px]" />+ </span>+ <div className="min-w-0">+ <DialogTitle className="truncate text-base font-semibold text-[var(--color-text-primary)]">+ {name}+ </DialogTitle>+ {dir ? (+ <p className="truncate font-mono text-[11px] text-[var(--color-text-tertiary)]">{dir}</p>+ ) : null}+ <div className="mt-1.5 flex flex-wrap items-center gap-2">+ <span+ className="inline-flex items-center gap-1.5 rounded-md px-1.5 py-0.5 text-[11px] font-semibold"+ style={{ backgroundColor: `color-mix(in srgb, ${accent} 14%, transparent)`, color: accent }}+ >+ {meta.label}+ </span>+ {plan.target_symbol ? (+ <code className="truncate text-[11px] text-[var(--color-text-secondary)]">+ {plan.target_symbol}+ </code>+ ) : null}+ </div>+ </div>+ </div>+ {plan.impact_delta > 0 ? (+ <span className="inline-flex shrink-0 items-center gap-1.5 rounded-full bg-[var(--color-success)]/10 px-3 py-1.5 text-sm font-semibold tabular-nums text-[var(--color-success)]">+ <TrendingUp className="h-4 w-4" />+ +{plan.impact_delta.toFixed(1)} health+ </span>+ ) : null}+ </div>+ </div>++ <div className="space-y-6 px-6 py-5">+ <p className="text-sm leading-relaxed text-[var(--color-text-secondary)]">{meta.blurb}</p>++ {/* the visual before → after */}+ <section>+ <h4 className="mb-3 text-xs font-semibold uppercase tracking-wide text-[var(--color-text-tertiary)]">+ The change+ </h4>+ <PlanComparison plan={plan} fileHref={fileHref} />+ </section>++ {/* what you gain */}+ {wins.length > 0 ? (+ <section className="rounded-2xl border border-[var(--color-success)]/25 bg-[var(--color-success)]/[0.05] p-4">+ <h4 className="mb-2.5 flex items-center gap-1.5 text-xs font-semibold uppercase tracking-wide text-[var(--color-success)]">+ <TrendingUp className="h-3.5 w-3.5" />+ What you gain+ </h4>+ <ul className="grid gap-x-6 gap-y-1.5 sm:grid-cols-2">+ {wins.map((w) => (+ <li+ key={w.label}+ className={`flex items-center gap-2 text-sm ${+ w.hero+ ? "font-semibold text-[var(--color-text-primary)]"+ : "text-[var(--color-text-secondary)]"+ }`}+ >+ <span+ className="h-1.5 w-1.5 shrink-0 rounded-full bg-[var(--color-success)]"+ aria-hidden+ />+ {w.label}+ </li>+ ))}+ </ul>+ <div className="mt-3 flex flex-wrap gap-2 border-t border-[var(--color-success)]/15 pt-3">+ <Chip label="Effort" value={EFFORT_LABEL[effort]} />+ <Chip label="Confidence" value={CONFIDENCE_LABEL[confidence]} />+ {blastN > 0 ? (+ <Chip label="Touches" value={`${blastN} file${blastN === 1 ? "" : "s"}`} />+ ) : null}+ </div>+ </section>+ ) : null}++ {/* evidence */}+ {evidence.length > 0 ? (+ <section>+ <h4 className="mb-2.5 text-xs font-semibold uppercase tracking-wide text-[var(--color-text-tertiary)]">+ Why this was flagged+ </h4>+ <dl className="grid grid-cols-2 gap-2 sm:grid-cols-4">+ {evidence.map((row) => (+ <div+ key={row.label}+ className="rounded-lg border border-[var(--color-border-default)] bg-[var(--color-bg-surface)] px-3 py-2"+ >+ <dt className="text-[10px] uppercase tracking-wide text-[var(--color-text-tertiary)]">+ {row.label}+ </dt>+ <dd className="mt-0.5 text-sm font-semibold tabular-nums text-[var(--color-text-primary)]">+ {row.value}+ </dd>+ </div>+ ))}+ </dl>+ </section>+ ) : null}++ {/* blast radius */}+ {blast.length > 0 ? (+ <section>+ <h4 className="mb-2.5 flex items-center gap-1.5 text-xs font-semibold uppercase tracking-wide text-[var(--color-text-tertiary)]">+ <Layers className="h-3.5 w-3.5" />+ Also affected+ </h4>+ <ul className="space-y-1">+ {blast.map((f) => {+ const href = fileHref?.(f, null);+ return (+ <li key={f}>+ {href ? (+ <a+ href={href}+ className="font-mono text-xs text-[var(--color-text-secondary)] underline-offset-2 hover:text-[var(--color-accent-primary)] hover:underline"+ >+ {f}+ </a>+ ) : (+ <span className="font-mono text-xs text-[var(--color-text-secondary)]">{f}</span>+ )}+ </li>+ );+ })}+ </ul>+ </section>+ ) : null}+ </div>++ {onAiPrompt ? (+ <div className="sticky bottom-0 mt-auto flex flex-col gap-3 border-t border-[var(--color-border-default)] bg-[var(--color-bg-overlay)] px-6 py-4 sm:flex-row sm:items-center sm:justify-between">+ <span className="hidden text-xs text-[var(--color-text-tertiary)] sm:block">+ Hand the exact steps, blast radius, and a completion contract to your coding agent.+ </span>+ <button+ type="button"+ onClick={() => onAiPrompt(plan)}+ className="inline-flex w-full shrink-0 items-center justify-center gap-2 rounded-lg bg-[var(--color-accent-primary)] px-3.5 py-2 text-sm font-semibold text-[var(--color-bg-surface)] transition-opacity hover:opacity-90 sm:w-auto"+ >+ <Sparkles className="h-4 w-4" />+ Get AI prompt+ </button>+ </div>+ ) : null}+ </>+ );+}++function Chip({ label, value }: { label: string; value: string }) {+ return (+ <span className="inline-flex items-center gap-1.5 rounded-full border border-[var(--color-border-default)] bg-[var(--color-bg-surface)] px-3 py-1 text-xs">+ <span className="text-[var(--color-text-tertiary)]">{label}</span>+ <span className="font-medium text-[var(--color-text-primary)]">{value}</span>+ </span>+ );+}diff --git a/packages/ui/src/refactoring/refactoring-plan-card.tsx b/packages/ui/src/refactoring/refactoring-plan-card.tsxindex c7fd1321b..00709b582 100644--- a/packages/ui/src/refactoring/refactoring-plan-card.tsx+++ b/packages/ui/src/refactoring/refactoring-plan-card.tsx@@ -20,14 +20,18 @@ export interface RefactoringPlanCardProps {highlighted?: boolean;}-function shortFile(path: string): string {+function fileParts(path: string): { name: string; dir: string } {const parts = path.split("/");- return parts.length <= 3 ? path : `…/${parts.slice(-3).join("/")}`;+ const name = parts[parts.length - 1] ?? path;+ const dirParts = parts.slice(0, -1);+ const dir = dirParts.length <= 3 ? dirParts.join("/") : `…/${dirParts.slice(-3).join("/")}`;+ return { name, dir };}/**- * A compact, clickable plan card. Deliberately light — the heavy visual lives- * in the inspector that opens on click — so a long grid stays performant.+ * A compact, clickable plan card — file first, with a type-colored rail so the+ * grid reads at a glance. Deliberately light: the heavy visual lives in the+ * modal that opens on click, so a long grid stays performant.*/export function RefactoringPlanCard({plan,@@ -41,62 +45,56 @@ export function RefactoringPlanCard({const blast = blastCount(plan);const effort = (plan.effort_bucket || "M") as EffortBucket;const confidence = (plan.confidence || "medium") as Confidence;+ const { name, dir } = fileParts(plan.file_path);return (<articledata-refactoring-plan={plan.id}- className={`group relative flex flex-col rounded-2xl border bg-[var(--color-bg-surface)] transition-all ${+ className={`group relative flex flex-col overflow-hidden rounded-2xl border bg-[var(--color-bg-surface)] transition-all ${highlighted? "border-[var(--color-accent-primary)] ring-1 ring-[var(--color-accent-primary)]/30": "border-[var(--color-border-default)] hover:border-[var(--color-border-strong)] hover:shadow-sm"}`}>+ {/* type-colored rail — the at-a-glance differentiator */}+ <span aria-hidden className="absolute inset-y-0 left-0 w-1" style={{ backgroundColor: accent }} />+<buttontype="button"onClick={onOpen ? () => onOpen(plan) : undefined}- className="flex flex-1 flex-col gap-3 p-4 text-left"+ className="flex flex-1 flex-col gap-2.5 py-4 pl-5 pr-4 text-left"disabled={!onOpen}- aria-label={`Open ${meta.label} plan for ${plan.target_symbol}`}+ aria-label={`Open ${meta.label} plan for ${plan.file_path}`}>- <div className="flex items-start gap-3">+ {/* file first */}+ <div className="min-w-0">+ <h3+ className="truncate text-sm font-semibold text-[var(--color-text-primary)]"+ title={plan.file_path}+ >+ {name}+ </h3>+ {dir ? (+ <p className="truncate font-mono text-[11px] text-[var(--color-text-tertiary)]">{dir}</p>+ ) : null}+ </div>++ {/* type + one-line synopsis */}+ <div className="flex items-center gap-2"><span- className="flex h-8 w-8 shrink-0 items-center justify-center rounded-lg"+ className="inline-flex shrink-0 items-center gap-1.5 rounded-md px-1.5 py-0.5 text-[11px] font-semibold"style={{ backgroundColor: `color-mix(in srgb, ${accent} 14%, transparent)`, color: accent }}>- <Icon className="h-4 w-4" />+ <Icon className="h-3.5 w-3.5" />+ {meta.label}+ </span>+ <span className="min-w-0 flex-1 truncate text-xs text-[var(--color-text-secondary)]">+ {planSynopsis(plan)}</span>- <div className="min-w-0 flex-1">- <div className="flex items-center gap-2">- <span className="text-[13px] font-semibold text-[var(--color-text-primary)]">- {meta.label}- </span>- <span- className="inline-flex items-center gap-1 text-[10px] text-[var(--color-text-tertiary)]"- title={`Detector confidence: ${CONFIDENCE_LABEL[confidence]}`}- >- <span className={`h-1.5 w-1.5 rounded-full ${CONFIDENCE_DOT[confidence]}`} />- {CONFIDENCE_LABEL[confidence]}- </span>- </div>- <p className="mt-0.5 truncate text-xs text-[var(--color-text-secondary)]">- {planSynopsis(plan)}- </p>- </div></div>- {plan.target_symbol ? (- <code className="block truncate text-[11px] text-[var(--color-text-secondary)]">- {plan.target_symbol}- </code>- ) : null}- <span- className="truncate font-mono text-[11px] text-[var(--color-text-tertiary)]"- title={plan.file_path}- >- {shortFile(plan.file_path)}- </span>-- <div className="mt-auto flex flex-wrap items-center gap-x-3 gap-y-1.5 pt-1 text-[11px] text-[var(--color-text-tertiary)]">+ {/* metric footer */}+ <div className="mt-auto flex items-center gap-x-3 gap-y-1.5 border-t border-[var(--color-border-default)] pt-3 text-[11px] text-[var(--color-text-tertiary)]"><span title={`Effort: ${EFFORT_LABEL[effort]}`} className="inline-flex items-center gap-1"><span className="rounded bg-[var(--color-bg-elevated)] px-1.5 py-0.5 font-medium tabular-nums text-[var(--color-text-secondary)]">{effort}@@ -108,8 +106,18 @@ export function RefactoringPlanCard({{blast}</span>) : null}+ <span+ className="inline-flex items-center gap-1"+ title={`Detector confidence: ${CONFIDENCE_LABEL[confidence]}`}+ >+ <span className={`h-1.5 w-1.5 rounded-full ${CONFIDENCE_DOT[confidence]}`} />+ {CONFIDENCE_LABEL[confidence]}+ </span>{plan.impact_delta > 0 ? (- <span className="tabular-nums" title="Health recovered if applied">+ <span+ className="ml-auto inline-flex items-center gap-1 rounded-full bg-[var(--color-success)]/10 px-2 py-0.5 font-semibold tabular-nums text-[var(--color-success)]"+ title="Health recovered if applied"+ >+{plan.impact_delta.toFixed(1)}</span>) : null}@@ -117,7 +125,7 @@ export function RefactoringPlanCard({</button>{onAiPrompt ? (- <div className="border-t border-[var(--color-border-default)] px-4 py-2">+ <div className="border-t border-[var(--color-border-default)] py-2 pl-5 pr-4"><buttontype="button"onClick={(e) => {diff --git a/packages/ui/src/refactoring/refactoring-quadrant.tsx b/packages/ui/src/refactoring/refactoring-quadrant.tsxindex 650e393ab..1129a2874 100644--- a/packages/ui/src/refactoring/refactoring-quadrant.tsx+++ b/packages/ui/src/refactoring/refactoring-quadrant.tsx@@ -73,7 +73,7 @@ export function RefactoringQuadrant({ plans, onSelect, height = 400 }: Refactori</p>) : null}<div className="relative">- <svg viewBox={`0 0 ${W} ${H}`} width="100%" height={H} role="img" aria-label="Priority versus effort scatter plot" className="overflow-visible">+ <svg viewBox={`0 0 ${W} ${H}`} role="img" aria-label="Priority versus effort scatter plot" className="h-auto w-full overflow-visible">{/* quadrant tints — top-left (high priority / low effort) is the sweet spot */}<rect x={padL} y={padT} width={midX - padL} height={midY - padT} fill="currentColor" className="text-[var(--color-success)]/[0.06]" /><rect x={midX} y={padT} width={W - padR - midX} height={midY - padT} fill="currentColor" className="text-[var(--color-caution)]/[0.04]" />diff --git a/packages/ui/src/refactoring/types.ts b/packages/ui/src/refactoring/types.tsindex 628d8fe2f..e3fe56a10 100644--- a/packages/ui/src/refactoring/types.ts+++ b/packages/ui/src/refactoring/types.ts@@ -178,3 +178,77 @@ export function blastCount(plan: RefactoringPlan): number {}return blastFiles(plan).length;}++// ── Evidence + win framing (shared by the inspector and the modal) ─────────++export const EVIDENCE_LABELS: Record<string, string> = {+ lcom4: "LCOM4",+ method_count: "Methods",+ field_count: "Fields",+ wmc: "WMC",+ occurrence_count: "Occurrences",+ duplicated_lines: "Duplicated lines",+ co_change_count: "Co-changes",+ foreign_calls: "Calls to target",+ own_calls: "Calls to own class",+ own_distance: "Distance to own",+ target_distance: "Distance to target",+ cycle_size: "Cycle size",+ edge_count: "Edges in cycle",+ cut_count: "Edges to cut",+};++export function evidenceRows(plan: RefactoringPlan): { label: string; value: string }[] {+ const rows: { label: string; value: string }[] = [];+ for (const [key, label] of Object.entries(EVIDENCE_LABELS)) {+ const v = plan.evidence?.[key];+ if (typeof v === "number" && Number.isFinite(v)) {+ rows.push({ label, value: Number.isInteger(v) ? String(v) : v.toFixed(2) });+ }+ }+ return rows;+}++export interface PlanWin {+ /** A health-score win is rendered as the hero; the rest are supporting. */+ hero?: boolean;+ label: string;+}++/** The concrete payoff of applying a plan, framed as wins for the "what you+ * gain" band. The health delta (if any) leads as the hero. */+export function planWins(plan: RefactoringPlan): PlanWin[] {+ const wins: PlanWin[] = [];+ if (plan.impact_delta > 0) {+ wins.push({ hero: true, label: `+${plan.impact_delta.toFixed(1)} health recovered` });+ }+ switch (plan.refactoring_type) {+ case "extract_class": {+ const n = extractClassGroups(plan).filter(+ (g) => g.methods.length > 0 || g.fields.length > 0,+ ).length;+ if (n) wins.push({ label: `${n} focused, single-responsibility class${n === 1 ? "" : "es"}` });+ break;+ }+ case "extract_helper": {+ const occ = extractHelperOccurrences(plan).length;+ const lines = Number(plan.evidence?.duplicated_lines ?? 0);+ if (occ) wins.push({ label: `${occ} duplicate cop${occ === 1 ? "y" : "ies"} collapsed to one` });+ if (lines) wins.push({ label: `~${lines} duplicated lines removed` });+ break;+ }+ case "move_method": {+ const mv = moveTarget(plan);+ if (mv) wins.push({ label: `${mv.method} lives with the data it uses` });+ break;+ }+ case "break_cycle": {+ const members = cycleMembers(plan).length;+ const edges = cutEdges(plan).length;+ if (members) wins.push({ label: `${members} files untangled` });+ if (edges) wins.push({ label: `${edges} import edge${edges === 1 ? "" : "s"} cut` });+ break;+ }+ }+ return wins;+}