Codebase intelligence for AI and humans: code health scores, auto-generated docs, git analytics, dead code detection, and architectural decisions via MCP.
Python aicode-complexitycode-healthcode-intelligencecode-qualitydead-codedeveloper-toolsdocumentationgit-analyticsmcpopen-sourcepythonrefactoringstatic-analysistechnical-debt
fix(ui): show the numbers code health surfaces actually serve (#3419)
Raghav Chamadiyad8eafa82519a
diff --git a/packages/types/src/actions.ts b/packages/types/src/actions.tsindex 2ce363d85..d84e293a8 100644--- a/packages/types/src/actions.ts+++ b/packages/types/src/actions.ts@@ -32,6 +32,9 @@ export const ACTION_TIER_LABELS: Record<ActionTier, string> = {improve_signal: "Improve what Repowise can see",};+/** The order tiers are listed in: core's `TIER_LABELS` order, pinned by the parity test. */+export const ACTION_TIER_ORDER: readonly ActionTier[] = ["act_now", "plan", "improve_signal"];+/** `unknown` is printed as a fact, never read as zero. */export type ActionFactBasis = "measured" | "inferred" | "unknown";diff --git a/packages/ui/__tests__/health/performance-view.test.tsx b/packages/ui/__tests__/health/performance-view.test.tsxindex 30f6264ab..f2dfd13fd 100644--- a/packages/ui/__tests__/health/performance-view.test.tsx+++ b/packages/ui/__tests__/health/performance-view.test.tsx@@ -103,13 +103,24 @@ describe("PerformanceView queue", () => {render(<PerformanceView adapter={adapter()} />);const items = await rows();expect(items).toHaveLength(3);- expect(screen.getByText(/1 in the repository/)).toBeTruthy();+ expect(screen.getAllByText("1 matching").length).toBeGreaterThan(0);const headings = screen.getAllByRole("heading", { level: 3 }).map((h) => h.textContent ?? "");expect(headings[0]).toContain("Plan ready");expect(headings[1]).toContain("Advisory");expect(headings[2]).toContain("Needs investigation");});+ it("keeps the green mark for a plan proven safe", async () => {+ render(<PerformanceView adapter={adapter()} />);+ const items = await rows();+ const dot = (li: HTMLElement) =>+ (li.querySelector("[aria-hidden='true'].rounded-full") as HTMLElement | null)?.style+ .backgroundColor;+ expect(dot(items[0]!)).toBe("var(--color-success)");+ // Advisory with a stored plan: not proven safe, so not green.+ expect(dot(items[1]!)).toBe("var(--color-text-tertiary)");+ });+it("shows the cause in words, where in mono, and the sink as separate evidence", async () => {render(<PerformanceView adapter={adapter()} />);const [first] = await rows();diff --git a/packages/ui/__tests__/overview/next-actions.test.tsx b/packages/ui/__tests__/overview/next-actions.test.tsxindex ce68f9174..a15927df8 100644--- a/packages/ui/__tests__/overview/next-actions.test.tsx+++ b/packages/ui/__tests__/overview/next-actions.test.tsx@@ -2,7 +2,7 @@ import { describe, expect, it, vi } from "vitest";import { fireEvent, render, screen, waitFor, within } from "@testing-library/react";import type { ActionsResponse, NextAction } from "@repowise-dev/types/actions";-import { NextActions } from "../../src/overview/next-actions.js";+import { NextActions, groupByTier } from "../../src/overview/next-actions.js";import { actionHref } from "../../src/overview/action-href.js";function action(overrides: Partial<NextAction> = {}): NextAction {@@ -334,3 +334,28 @@ describe("host-configurable hints", () => {expect(within(dialog).getByText(/get_risk\(src\/a\.py\)/)).toBeInTheDocument();});});++describe("groupByTier", () => {+ it("gives each tier one heading, in tier order, whatever the row order", () => {+ const rows = [+ action({ id: "p1", tier: "plan" }),+ action({ id: "n1", tier: "act_now" }),+ action({ id: "p2", tier: "plan" }),+ ];+ expect(groupByTier(rows).map(([tier, items]) => [tier, items.map((a) => a.id)])).toEqual([+ ["act_now", ["n1"]],+ ["plan", ["p1", "p2"]],+ ]);+ });++ it("keeps rows of a tier it does not know, in a trailing group", () => {+ const rows = [+ action({ id: "x1", tier: "someday" as NextAction["tier"] }),+ action({ id: "p1", tier: "plan" }),+ ];+ expect(groupByTier(rows).map(([tier, items]) => [tier, items.map((a) => a.id)])).toEqual([+ ["plan", ["p1"]],+ ["someday", ["x1"]],+ ]);+ });+});diff --git a/packages/ui/__tests__/refactoring/extract-helper-reuse.test.tsx b/packages/ui/__tests__/refactoring/extract-helper-reuse.test.tsxindex fdc8c9270..565cdcfbb 100644--- a/packages/ui/__tests__/refactoring/extract-helper-reuse.test.tsx+++ b/packages/ui/__tests__/refactoring/extract-helper-reuse.test.tsx@@ -8,6 +8,8 @@ import { describe, expect, it } from "vitest";import type { RefactoringPlan } from "@repowise-dev/types/refactoring";import { PlanDetail } from "../../src/refactoring/plan-detail";+import { RefactoringDrawer } from "../../src/refactoring/refactoring-drawer";+import { planWins } from "../../src/refactoring/types";const plan = {id: "plan-reuse",@@ -64,3 +66,12 @@ describe("Extract Helper reuse detail", () => {expect(screen.queryByText(/Extract it once/)).toBeNull();});});++describe("Extract Helper reuse in the drawer", () => {+ it("says the existing function is called, not a new helper", () => {+ render(<RefactoringDrawer plan={plan} open onOpenChange={() => {}} />);+ expect(screen.getByText(/Call the function that already holds this block/)).toBeTruthy();+ expect(screen.queryByText(/into one shared helper/)).toBeNull();+ expect(planWins(plan).map((w) => w.label)).toContain("2 duplicate copies collapsed into normalize()");+ });+});diff --git a/packages/ui/__tests__/refactoring/opportunity-drawer.test.tsx b/packages/ui/__tests__/refactoring/opportunity-drawer.test.tsxindex c3f4b882a..d20153e0f 100644--- a/packages/ui/__tests__/refactoring/opportunity-drawer.test.tsx+++ b/packages/ui/__tests__/refactoring/opportunity-drawer.test.tsx@@ -223,6 +223,46 @@ describe("OpportunityDrawer reach, verification and code", () => {expect(screen.queryByText("return c", { exact: false })).toBeNull();});+ it("shows each stage of a staged plan as its own excerpt, not the lines between", async () => {+ // 120 lines; stages 10-12 and 90-92, a gap far over the 40-line excerpt cap.+ const source = Array.from({ length: 120 }, (_, i) => `line_${i + 1}`).join("\n");+ const readSource = vi.fn().mockResolvedValue(source);+ const stage = (start: number, end: number) => ({+ span: { start, end },+ params: [],+ returns: [],+ suggested_name: null,+ ccn: 3,+ new_symbol: { signature_text: "def <name>():" },+ call_site: { replace_span: { start, end }, new_text: "<name>()" },+ });+ const plan = {+ ...PLAN,+ line_start: 1,+ line_end: 120,+ plan: { ...stage(10, 12), stages: [stage(10, 12), stage(90, 92)] },+ } as unknown as RefactoringPlan;+ render(+ <OpportunityDrawer+ detail={detail({+ steps: [{ ...STEP, line_start: 1, line_end: 120 }],+ steps_emitted: 1,+ plans: [plan],+ })}+ open+ onOpenChange={() => {}}+ readSource={readSource}+ />,+ );+ fireEvent.click(screen.getByRole("button", { name: "Show the code" }));+ expect(await screen.findByText("line_10", { exact: false })).toBeTruthy();+ expect(await screen.findByText("line_92", { exact: false })).toBeTruthy();+ expect(screen.queryByText("line_50", { exact: false })).toBeNull();+ expect(screen.getByText("Stage 2 · lines 90–92")).toBeTruthy();+ // Both excerpts share one read of the file.+ expect(readSource).toHaveBeenCalledTimes(1);+ });+it("offers the model-drafted diff preview when the host turned generation on", () => {render(<OpportunityDrawerdiff --git a/packages/ui/__tests__/refactoring/staged-extract-detail.test.tsx b/packages/ui/__tests__/refactoring/staged-extract-detail.test.tsxindex 822ddb415..99724b4e0 100644--- a/packages/ui/__tests__/refactoring/staged-extract-detail.test.tsx+++ b/packages/ui/__tests__/refactoring/staged-extract-detail.test.tsx@@ -3,7 +3,14 @@ import { describe, expect, it } from "vitest";import type { RefactoringPlan } from "@repowise-dev/types/refactoring";import { PlanDetail } from "../../src/refactoring/plan-detail";-import { extractMethodStages } from "../../src/refactoring/types";+import { PlanBefore } from "../../src/refactoring/plan-before";+import { planBlurb } from "../../src/refactoring/meta";+import {+ extractMethodStages,+ planWins,+ stagedLineCount,+ stepExcerptRange,+} from "../../src/refactoring/types";function stage(start: number, end: number, name: string | null, out: string[]) {return {@@ -132,3 +139,35 @@ describe("PlanDetail with fewer than two valid stages", () => {expect(screen.queryByText(/helpers it calls in order/)).toBeNull();});});++describe("A staged Extract Method plan outside the after view", () => {+ it("counts every stage in what you gain, not the first span", () => {+ const labels = planWins(plan).map((w) => w.label);+ expect(labels).toContain("40 lines lifted into 2 helpers");+ expect(labels.some((l) => l.includes("focused helper"))).toBe(false);+ });++ it("prints no line count when the stored figure is missing", () => {+ const bare = { ...plan, evidence: { ccn_removed: 28 } } satisfies RefactoringPlan;+ expect(stagedLineCount(bare)).toBeNull();+ expect(planWins(bare).some((w) => w.label.includes("lines lifted"))).toBe(false);+ });++ it("describes the plan as a split into several helpers", () => {+ expect(planBlurb(plan)).toBe("Split a long function into helpers it calls in order.");+ });++ it("states the function and every stage's lines under Today", () => {+ render(<PlanBefore plan={plan} />);+ expect(screen.getByText("persist")).toBeTruthy();+ expect(screen.getByText(/lines 5–90 · CCN 40/)).toBeTruthy();+ expect(screen.getByText("10–30, 34–60")).toBeTruthy();+ expect(screen.getByText(/2 blocks .* 40 lines in all/)).toBeTruthy();+ });++ it("covers every stage when a step shows its code", () => {+ const range = stepExcerptRange({ line_start: 5, line_end: 90 }, plan);+ expect(range).toMatchObject({ start: 10, end: 60, extraction: null });+ expect(range?.stages).toHaveLength(2);+ });+});diff --git a/packages/ui/src/health/ai-prompts/refactoring-prompts.ts b/packages/ui/src/health/ai-prompts/refactoring-prompts.tsindex f1417a38a..b51dc1539 100644--- a/packages/ui/src/health/ai-prompts/refactoring-prompts.ts+++ b/packages/ui/src/health/ai-prompts/refactoring-prompts.ts@@ -6,7 +6,7 @@ import type {RefactoringPlan,} from "@repowise-dev/types/refactoring";-import { typeMeta } from "../../refactoring/meta";+import { planBlurb, typeMeta } from "../../refactoring/meta";import { blastFiles } from "../../refactoring/types";import {planSourceLink,@@ -177,7 +177,7 @@ export function buildRefactoringPlanPrompt({"",`## ${meta.label}${repoSuffix(repoName)}`,"",- planFacts(plan, meta.blurb),+ planFacts(plan, planBlurb(plan)),"","## The plan","",diff --git a/packages/ui/src/health/performance/queue.tsx b/packages/ui/src/health/performance/queue.tsxindex 49d87045c..9d2b13b9a 100644--- a/packages/ui/src/health/performance/queue.tsx+++ b/packages/ui/src/health/performance/queue.tsx@@ -92,7 +92,7 @@ export function OpportunityQueue({{ACTIONABILITY_LABEL[section.state]}{facetTotal(facets, section.state) != null ? (<span className="ml-2 tabular-nums">- {facetTotal(facets, section.state)!.toLocaleString()} in the repository+ {facetTotal(facets, section.state)!.toLocaleString()} matching</span>) : null}</h3>@@ -124,7 +124,12 @@ export function OpportunityQueue({function StatusMark({ opportunity }: { opportunity: PerformanceOpportunity }) {const plan = planPresentation(opportunity);- const tone = plan.actionable ? "var(--color-success)" : "var(--color-text-tertiary)";+ // Green only where the plan is proven safe: an advisory cause can carry a+ // stored plan while the "Plan ready" count beside the queue reads 0.+ const tone =+ plan.actionable && opportunity.actionability_state === "plan_ready"+ ? "var(--color-success)"+ : "var(--color-text-tertiary)";return (<span className="inline-flex items-center gap-1.5 whitespace-nowrap text-xs font-medium text-[var(--color-text-secondary)]"><spandiff --git a/packages/ui/src/overview/next-actions.tsx b/packages/ui/src/overview/next-actions.tsxindex 5a4df94f8..98584add8 100644--- a/packages/ui/src/overview/next-actions.tsx+++ b/packages/ui/src/overview/next-actions.tsx@@ -5,6 +5,7 @@ import { BellOff, Check, PanelRight, X } from "lucide-react";import { toast } from "sonner";import {ACTION_TIER_LABELS,+ ACTION_TIER_ORDER,type ActionHorizonKey,type ActionsResponse,type ActionStateValue,@@ -157,7 +158,7 @@ export function NextActions({{groupByTier(shown).map(([tier, items]) => (<div key={tier} className="flex flex-col"><h3 className="pb-1 pt-3 font-mono text-[10px] uppercase tracking-[0.12em] text-[var(--color-text-tertiary)] first:pt-0">- {ACTION_TIER_LABELS[tier]}+ {ACTION_TIER_LABELS[tier] ?? tier}</h3><ul className="flex flex-col divide-y divide-[var(--color-border-default)]">{items.map((action) => (@@ -245,14 +246,17 @@ export function actionLocation(action: NextAction): string | null {return line ? `${path}:${line}` : path;}-function groupByTier(actions: NextAction[]): [ActionTier, NextAction[]][] {- const out: [ActionTier, NextAction[]][] = [];+/** One heading per tier in core's order, rank order kept inside each, as the+ * CLI groups them. A tier this build does not know trails under its raw name+ * rather than dropping its rows. */+export function groupByTier(actions: NextAction[]): [ActionTier, NextAction[]][] {+ const groups = new Map<ActionTier, NextAction[]>(ACTION_TIER_ORDER.map((t) => [t, []]));for (const a of actions) {- const last = out[out.length - 1];- if (last && last[0] === a.tier) last[1].push(a);- else out.push([a.tier, [a]]);+ const group = groups.get(a.tier);+ if (group) group.push(a);+ else groups.set(a.tier, [a]);}- return out;+ return [...groups].filter(([, items]) => items.length > 0);}export function ActionRow({diff --git a/packages/ui/src/refactoring/extract-method-before.tsx b/packages/ui/src/refactoring/extract-method-before.tsxnew file mode 100644index 000000000..df2ce1af1--- /dev/null+++ b/packages/ui/src/refactoring/extract-method-before.tsx@@ -0,0 +1,53 @@+"use client";++import type { RefactoringPlan } from "@repowise-dev/types/refactoring";++import {+ extractMethodPlan,+ extractMethodStages,+ extractOrchestrator,+ formatSpans,+ stagedLineCount,+} from "./types";++/**+ * "Today" for an Extract Method plan: the function, its range and the blocks+ * that move. The drawer's "after" hides its intro, so without this the half+ * stayed empty.+ */+export function ExtractMethodBefore({ plan }: { plan: RefactoringPlan }) {+ const stages = extractMethodStages(plan);+ const em = extractMethodPlan(plan);+ const spans = stages.length >= 2 ? stages.map((s) => s.span) : em.span ? [em.span] : [];+ const orchestrator = extractOrchestrator(plan);+ const lines = stagedLineCount(plan);+ const name = plan.target_symbol || (plan.file_path.split("/").pop() ?? plan.file_path);+ return (+ <div className="rounded-xl border border-[var(--color-border-default)] bg-[var(--color-bg-surface)] p-3.5">+ <div className="mb-2 flex flex-wrap items-baseline justify-between gap-x-2 gap-y-1">+ <code className="min-w-0 break-all text-xs font-semibold text-[var(--color-text-primary)]">+ {name}+ </code>+ {plan.line_start && plan.line_end ? (+ <span className="shrink-0 font-mono text-2xs tabular-nums text-[var(--color-text-tertiary)]">+ lines {plan.line_start}–{plan.line_end}+ {orchestrator ? ` · CCN ${orchestrator.before}` : ""}+ </span>+ ) : null}+ </div>+ {spans.length > 0 ? (+ <p className="text-2xs leading-relaxed text-[var(--color-text-tertiary)]">+ {spans.length === 1+ ? "One block inside it does a separable job: "+ : `${spans.length} blocks inside it each do a separable job${+ lines ? `, ${lines} lines in all` : ""+ }: `}+ <span className="font-mono tabular-nums text-[var(--color-text-secondary)]">+ {formatSpans(spans)}+ </span>+ .+ </p>+ ) : null}+ </div>+ );+}diff --git a/packages/ui/src/refactoring/meta.tsx b/packages/ui/src/refactoring/meta.tsxindex 2d0a7fc58..6657a4ba6 100644--- a/packages/ui/src/refactoring/meta.tsx+++ b/packages/ui/src/refactoring/meta.tsx@@ -2,7 +2,8 @@import * as React from "react";import { ArrowRightLeft, CopyMinus, FileStack, Gauge, Scissors, Split, Unlink } from "lucide-react";-import type { Confidence, RefactoringType } from "@repowise-dev/types/refactoring";+import type { Confidence, RefactoringPlan, RefactoringType } from "@repowise-dev/types/refactoring";+import { extractHelperReuse, extractMethodStages } from "./types";export interface RefactoringTypeMeta {label: string;@@ -73,6 +74,18 @@ export function typeMeta(type: RefactoringType | string): RefactoringTypeMeta {return TYPE_META[type] ?? FALLBACK;}+/** One plan's blurb. The type's promises one new helper; a reuse plan adds+ * none and a staged plan adds several. */+export function planBlurb(plan: RefactoringPlan): string {+ if (plan.refactoring_type === "extract_helper" && extractHelperReuse(plan)) {+ return "Call the function that already holds this block instead of keeping a copy of it.";+ }+ if (plan.refactoring_type === "extract_method" && extractMethodStages(plan).length >= 2) {+ return "Split a long function into helpers it calls in order.";+ }+ return typeMeta(plan.refactoring_type).blurb;+}+export function typeAccent(type: RefactoringType | string): string {return `var(${typeMeta(type).accentVar})`;}diff --git a/packages/ui/src/refactoring/opportunity-drawer.tsx b/packages/ui/src/refactoring/opportunity-drawer.tsxindex 1c4c1fff3..263024056 100644--- a/packages/ui/src/refactoring/opportunity-drawer.tsx+++ b/packages/ui/src/refactoring/opportunity-drawer.tsx@@ -41,7 +41,7 @@ import {RefactoringModelToggle,type RefactoringModelToggleProps,} from "./refactoring-settings-card";-import { extractHelperDetail, extractMethodSignature, stepExcerptRange } from "./types";+import { extractHelperDetail, extractMethodSignature, formatSpans, stepExcerptRange } from "./types";import {ORDERING_NOTE,STATUS_LABEL,@@ -653,7 +653,17 @@ function StepCode({const range = stepExcerptRange(step, plan);const extraction = range?.extraction ?? null;const slice = extraction?.span ?? null;+ const stages = range?.stages ?? [];const canRead = Boolean(readSource && range);+ // One read per file however many stage excerpts ask for it.+ const readOnce = React.useMemo(() => {+ if (!readSource) return undefined;+ const reads = new Map<string, Promise<string>>();+ return (path: string) => {+ if (!reads.has(path)) reads.set(path, readSource(path));+ return reads.get(path)!;+ };+ }, [readSource]);if (!stored?.snippet && !canRead && !plan) return null;return (<div className="mt-2">@@ -667,6 +677,15 @@ function StepCode({</button>{open ? (<div className="mt-2 space-y-3">+ {stages.length > 0 ? (+ <p className="text-[11.5px] text-[var(--color-text-tertiary)]">+ Lines{" "}+ <span className="font-mono tabular-nums text-[var(--color-text-secondary)]">+ {formatSpans(stages.map((st) => st.span))}+ </span>{" "}+ become {stages.length} helpers the function calls in order.+ </p>+ ) : null}{extraction && slice ? (<p className="text-[11.5px] text-[var(--color-text-tertiary)]">Lines {slice.start} to {slice.end} become{" "}@@ -677,12 +696,28 @@ function StepCode({) : null}{stored?.snippet ? (<CodeBlock code={stored.snippet} startLine={stored.snippetStartLine} />+ ) : canRead && stages.length > 0 ? (+ // Each stage on its own: one range from the first stage to the last+ // would show the lines between them and could cut a later stage.+ stages.map((st, i) => (+ <div key={st.span.start} className="space-y-1">+ <p className="font-mono text-[11px] text-[var(--color-text-tertiary)]">+ {`${st.name ?? `Stage ${i + 1}`} · lines ${formatSpans([st.span])}`}+ </p>+ <SourceExcerpt+ path={step.file_path}+ start={st.span.start}+ end={st.span.end}+ readSource={readOnce!}+ />+ </div>+ ))) : canRead ? (<SourceExcerptpath={step.file_path}start={range!.start}end={range!.end}- readSource={readSource!}+ readSource={readOnce!}/>) : null}{plan && onGenerateCode ? (diff --git a/packages/ui/src/refactoring/plan-before.tsx b/packages/ui/src/refactoring/plan-before.tsxindex 5247aa35e..de1e84036 100644--- a/packages/ui/src/refactoring/plan-before.tsx+++ b/packages/ui/src/refactoring/plan-before.tsx@@ -11,6 +11,7 @@ import {splitResidual,} from "./types";import type { RefactoringPlan } from "@repowise-dev/types/refactoring";+import { ExtractMethodBefore } from "./extract-method-before";export interface PlanBeforeProps {plan: RefactoringPlan;@@ -159,6 +160,8 @@ export function PlanBefore({ plan }: PlanBeforeProps) {);}+ if (plan.refactoring_type === "extract_method") return <ExtractMethodBefore plan={plan} />;+if (plan.refactoring_type === "move_method") {const mv = moveTarget(plan);if (!mv) return null;diff --git a/packages/ui/src/refactoring/plan-detail.tsx b/packages/ui/src/refactoring/plan-detail.tsxindex 299ebd46e..fcb3b88f0 100644--- a/packages/ui/src/refactoring/plan-detail.tsx+++ b/packages/ui/src/refactoring/plan-detail.tsx@@ -165,13 +165,20 @@ function StagedExtract({className="rounded-xl border border-[var(--color-border-default)] bg-[var(--color-bg-surface)] p-3.5"><details open={i === 0} className="group">- <summary className="flex cursor-pointer items-center gap-2 text-xs">+ {/* Wraps: in the drawer's half-width column a one-line summary+ clipped the line range and CCN off the right edge. */}+ <summary className="flex cursor-pointer flex-wrap items-center gap-x-2 gap-y-1 text-xs"><Scissors className="h-4 w-4 shrink-0" style={{ color: ACCENT }} aria-hidden />- <span className="font-mono text-[var(--color-text-primary)]">+ <span className="whitespace-nowrap font-mono text-[var(--color-text-primary)]">{stage.name ?? `Stage ${i + 1}`}</span>- <FileRef path={plan.file_path} line={stage.span.start} fileHref={fileHref} />- <span className="ml-auto shrink-0 font-mono text-[var(--color-text-secondary)]">+ <FileRef+ path={plan.file_path}+ line={stage.span.start}+ fileHref={fileHref}+ className="min-w-0 break-all"+ />+ <span className="ml-auto whitespace-nowrap font-mono text-[var(--color-text-secondary)]">lines {stage.span.start}–{stage.span.end}{stage.ccn ? ` · CCN ${stage.ccn}` : ""}</span>diff --git a/packages/ui/src/refactoring/refactoring-drawer.tsx b/packages/ui/src/refactoring/refactoring-drawer.tsxindex e2ebbd5ee..4bccd2bd0 100644--- a/packages/ui/src/refactoring/refactoring-drawer.tsx+++ b/packages/ui/src/refactoring/refactoring-drawer.tsx@@ -31,7 +31,7 @@ import { GenerateCodePanel } from "./generate-code-panel";import { RefactoringModelToggle, type RefactoringModelToggleProps } from "./refactoring-settings-card";import { PriorityExplanation } from "./priority-explanation";import { ValidationSummary } from "./validation-summary";-import { CONFIDENCE_LABEL, EFFORT_LABEL, typeMeta } from "./meta";+import { CONFIDENCE_LABEL, EFFORT_LABEL, planBlurb, typeMeta } from "./meta";import { blastCount, blastFiles, evidenceRows, planWins } from "./types";import type {Confidence,@@ -133,6 +133,7 @@ function DrawerBody({contextSlot?: ReactNode;}) {const meta = typeMeta(plan.refactoring_type);+ const blurb = planBlurb(plan);const effort = (plan.effort_bucket || "M") as EffortBucket;const confidence = (plan.confidence || "medium") as Confidence;const evidence = evidenceRows(plan);@@ -178,7 +179,7 @@ function DrawerBody({<div className="flex-1 space-y-6 overflow-y-auto px-5 py-5">{contextSlot}- <p className="text-sm leading-relaxed text-[var(--color-text-secondary)]">{meta.blurb}</p>+ <p className="text-sm leading-relaxed text-[var(--color-text-secondary)]">{blurb}</p>{plan.risks && plan.risks.length > 0 ? (<section>diff --git a/packages/ui/src/refactoring/types.ts b/packages/ui/src/refactoring/types.tsindex b13be5fa7..497432f20 100644--- a/packages/ui/src/refactoring/types.ts+++ b/packages/ui/src/refactoring/types.ts@@ -346,6 +346,20 @@ export function extractOrchestrator(plan: RefactoringPlan): { before: number; afreturn { before: raw.ccn_before, after: raw.ccn_after };}+/** Line spans as every staged surface prints them: `10–30, 34–60`. */+export function formatSpans(spans: ReadonlyArray<{ start: number; end: number }>): string {+ return spans.map((sp) => `${sp.start}–${sp.end}`).join(", ");+}++/** The lines a staged plan lifts, as the CLI reports them (`evidence.slice_nloc`).+ * Null for a single-span plan or when the figure was not stored, so no surface+ * prints a sum of spans as if it were that number. */+export function stagedLineCount(plan: RefactoringPlan): number | null {+ if (extractMethodStages(plan).length < 2) return null;+ const n = Number(plan.evidence?.slice_nloc ?? 0);+ return n > 0 ? n : null;+}+/** The helper an extraction proposes, as one line: `async name(a, b) -> c`.* For a plan stored before the server rendered `signature_text`. */export function extractMethodSignature(em: ExtractMethodPlan): string {@@ -362,11 +376,18 @@ export function extractMethodSignature(em: ExtractMethodPlan): string {export function stepExcerptRange(step: { line_start: number | null; line_end: number | null },plan: RefactoringPlan | undefined,-): { start: number; end: number; extraction: ExtractMethodPlan | null } | null {- const extraction = plan?.refactoring_type === "extract_method" ? extractMethodPlan(plan) : null;- if (extraction?.span) return { ...extraction.span, extraction };+): { start: number; end: number; extraction: ExtractMethodPlan | null; stages: ExtractStage[] } | null {+ const isExtract = plan?.refactoring_type === "extract_method";+ // A staged plan's top-level span is only its first stage. start..end spans+ // every stage for callers that need one range; excerpts read `stages`.+ const stages = isExtract ? extractMethodStages(plan!) : [];+ if (stages.length >= 2) {+ return { start: stages[0]!.span.start, end: stages[stages.length - 1]!.span.end, extraction: null, stages };+ }+ const extraction = isExtract ? extractMethodPlan(plan!) : null;+ if (extraction?.span) return { ...extraction.span, extraction, stages: [] };if (!step.line_start) return null;- return { start: step.line_start, end: step.line_end ?? step.line_start, extraction };+ return { start: step.line_start, end: step.line_end ?? step.line_start, extraction, stages: [] };}export interface SplitGroup {@@ -687,7 +708,8 @@ export function planWins(plan: RefactoringPlan): PlanWin[] {case "extract_helper": {const occ = extractHelperOccurrences(plan).length;const lines = Number(plan.evidence?.duplicated_lines ?? 0);- const name = extractHelperDetail(plan).suggestedName;+ const existing = extractHelperReuse(plan)?.existing_symbol.split("::").pop();+ const name = existing ?? extractHelperDetail(plan).suggestedName;if (occ)wins.push({label: name@@ -700,7 +722,12 @@ export function planWins(plan: RefactoringPlan): PlanWin[] {case "extract_method": {const em = extractMethodPlan(plan);const ccn = Number(plan.evidence?.ccn_removed ?? 0);- if (em.span) {+ const stages = extractMethodStages(plan);+ if (stages.length >= 2) {+ // Every stage moves, not only the first span the plan's top level carries.+ const lines = stagedLineCount(plan);+ if (lines) wins.push({ label: `${lines} lines lifted into ${stages.length} helpers` });+ } else if (em.span) {const lines = em.span.end - em.span.start + 1;wins.push({label: `${lines} line${lines === 1 ? "" : "s"} lifted into a focused helper`,diff --git a/packages/web/src/app/repos/[id]/code-health/page.tsx b/packages/web/src/app/repos/[id]/code-health/page.tsxindex 55b7f1e6c..b8cc2a43d 100644--- a/packages/web/src/app/repos/[id]/code-health/page.tsx+++ b/packages/web/src/app/repos/[id]/code-health/page.tsx@@ -17,8 +17,9 @@* symbol-drawer deep links point at it) but is labelled for what it is.** Tabs carry their count where one is cheap to get, so a clean repo says so- * before you spend a click. Findings rides on the overview request the page- * already makes and dead code dedupes onto the key its own tab uses. Security+ * before you spend a click. Dead code dedupes onto the key its own tab uses.+ * Findings is not numbered: the overview's queue inventory is not the list the+ * tab opens on, and that list's own total is a multi-second query. Security* has no count endpoint (only a findings list), and blast radius is a tool you* operate rather than a pile you read, so neither is numbered.*/@@ -291,8 +292,7 @@ export default function CodeHealthPage() {const selectedPath = searchParams.get("file");const opportunityId = searchParams.get("opportunity");- // Shares the SWR key with TriageView — the meta line and the findings count- // cost no extra request.+ // Shares the SWR key with TriageView, so the meta line costs no extra request.const { data: overview } = useSWR<HealthOverviewResponse>(`code-health-overview:${repoId}${viewKey}`,() => getHealthOverview(repoId, 25, scope, counts),@@ -427,13 +427,6 @@ export default function CodeHealthPage() {);const badges: Partial<Record<TabId, number | string>> = {};- // Performance has its own tab and is out of the findings list, so counting- // it here would put a bigger number on the tab than the tab can show.- if (overview) {- badges.findings =- overview.queue_counts?.findings.inventory ??- overview.summary.open_findings - (overview.summary.performance_findings ?? 0);- }if (deadCode) badges["dead-code"] = deadCode.total_findings;// No badge when the drift pass has not run: the response carries a cause// rather than a summary, and a 0 there would read as clean documentation.diff --git a/tests/unit/server/test_wire_vocabulary_parity.py b/tests/unit/server/test_wire_vocabulary_parity.pyindex a9a480d07..647584481 100644--- a/tests/unit/server/test_wire_vocabulary_parity.py+++ b/tests/unit/server/test_wire_vocabulary_parity.py@@ -92,6 +92,9 @@ def test_action_tier_labels_match_python() -> None:match = re.search(r"export const ACTION_TIER_LABELS[^=]*= \{(.*?)\};", text, re.DOTALL)assert match, "ACTION_TIER_LABELS is not declared in actions.ts"assert dict(re.findall(r'(\w+): "([^"]+)"', match.group(1))) == TIER_LABELS+ order = re.search(r"export const ACTION_TIER_ORDER[^=]*= \[(.*?)\];", text, re.DOTALL)+ assert order, "ACTION_TIER_ORDER is not declared in actions.ts"+ assert re.findall(r'"(\w+)"', order.group(1)) == list(TIER_LABELS)def test_fix_first_vocabularies_match_python() -> None: