Skip to content

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

fix(ui): lead Code Health with a short score headline and fold Fix first under it (#3026)

Raghav Chamadiya87d32a6d1c0a
diff --git a/packages/ui/__tests__/health/code-health-lede.test.tsx b/packages/ui/__tests__/health/code-health-lede.test.tsx
index 091273a6e..ea33b7585 100644
--- a/packages/ui/__tests__/health/code-health-lede.test.tsx
+++ b/packages/ui/__tests__/health/code-health-lede.test.tsx
@@ -76,9 +76,9 @@ describe("CodeHealthLede — the two readings of one figure", () => {
it("says what it excluded, and that the findings now add up", () => {
render(<CodeHealthLede summary={summary({ counts: "code_shape" })} />);
- expect(
- screen.getByText(/Change history excluded\. This scores the code alone/),
- ).toBeTruthy();
+ expect(screen.getByText("Change history excluded.")).toBeTruthy();
+ // The rest of the caption waits behind Breakdown.
+ expect(screen.getByText(/This scores the code alone/).closest("details")).toBeTruthy();
expect(screen.queryByText(/comes from change history/)).toBeNull();
});
@@ -109,9 +109,52 @@ describe("CodeHealthLede — the two readings of one figure", () => {
describe("CodeHealthLede — the figure and its band agree at the edge", () => {
it("does not print 7.0 beside Fair for a score just under Good", () => {
const { container } = render(<CodeHealthLede summary={summary({ average_health: 6.98 })} />);
- expect(container.textContent).toContain("scores 6.9 out of 10");
- expect(container.textContent).toContain("That puts it in the Fair band.");
- expect(container.textContent).not.toContain("7.0 out of 10");
+ expect(screen.getByText("6.9")).toBeTruthy();
+ expect(screen.getByText("Fair")).toBeTruthy();
+ expect(container.textContent).not.toContain("7.0");
+ });
+});
+
+describe("CodeHealthLede: what the first screen shows", () => {
+ const accuracy = { hits: 17, k: 20, precision: 0.85, base_rate: 0.1, lift: 8.61, window_days: 180 };
+
+ it("shows the validation line with its facts, outside any disclosure", () => {
+ render(<CodeHealthLede summary={summary()} accuracy={accuracy as never} />);
+ const line = screen.getByText(/Ranked against real bug-fix history/);
+ expect(line.textContent).toContain("17 of the 20 files");
+ expect(line.textContent).toContain("85% against a 10% base rate");
+ expect(line.textContent).toContain("8.61× better");
+ expect(line.closest("details")).toBeNull();
+ });
+
+ it("keeps the band breakdown and the history share behind a closed Breakdown", () => {
+ const distribution = {
+ total_files: 2,
+ total_nloc: 100,
+ bands: {
+ at_risk: { pct: 50, files: 1, nloc: 50 },
+ excellent: { pct: 50, files: 1, nloc: 50 },
+ },
+ };
+ render(<CodeHealthLede summary={summary()} distribution={distribution as never} />);
+ const toggle = screen.getByText("Breakdown");
+ const details = toggle.closest("details")!;
+ expect(details.open).toBe(false);
+ expect(details.textContent).toContain("50% at risk");
+ expect(details.textContent).toContain("comes from change history");
+ });
+
+ it("puts the method, performance and test-file notes behind How it is scored", () => {
+ render(
+ <CodeHealthLede
+ summary={summary({ worst_test_path: "tests/test_big.py", worst_test_score: 2.4 })}
+ />,
+ );
+ const details = screen.getByText("How it is scored").closest("details")!;
+ expect(details.open).toBe(false);
+ expect(details.textContent).toContain("churn and ownership");
+ expect(details.textContent).toContain("Static performance is scored separately");
+ expect(details.textContent).toContain("Test files are ranked apart.");
});
});
diff --git a/packages/ui/__tests__/health/fix-first.test.tsx b/packages/ui/__tests__/health/fix-first.test.tsx
index 2f55b614e..e43416ed3 100644
--- a/packages/ui/__tests__/health/fix-first.test.tsx
+++ b/packages/ui/__tests__/health/fix-first.test.tsx
@@ -1,6 +1,7 @@
/**
- * Fix first renders core's queue as it arrives: the header states the scope
- * exactly, the lead opens with its steps and Verify, and actions appear only
+ * Fix first renders core's queue as it arrives: the section starts closed
+ * with its count, the header states the scope exactly, each row is two scan
+ * lines that open onto the why, steps and Verify, and actions appear only
* where the item can back them.
*/
@@ -27,7 +28,21 @@ function renderList(overrides: Partial<React.ComponentProps<typeof FixFirstList>
);
}
+/** Rows start closed; open one by its title. */
+function openRow(item: FixItem) {
+ fireEvent.click(screen.getByRole("button", { name: new RegExp(item.title.replace(/[()]/g, "\\$&")) }));
+}
+
describe("Fix first header", () => {
+ it("starts closed, with the title and the item count on the toggle", () => {
+ const { container } = renderList();
+ const details = container.querySelector("details")!;
+ expect(details.open).toBe(false);
+ const summary = container.querySelector("summary")!;
+ expect(summary.textContent).toContain("Fix first");
+ expect(summary.textContent).toContain("3 items");
+ });
+
it("states shown of eligible and every nonzero exclusion with its count", () => {
expect(fixFirstScopeSentence(FIX_FIRST_QUEUE)).toBe(
"3 of 423 eligible items. Excluded: 612 in tests, 91 tooling, 5 generated, " +
@@ -63,6 +78,11 @@ describe("Fix first header", () => {
describe("Fix first items", () => {
it("renders tier as a word, the imperative title, and file:line linking to the file view", () => {
renderList();
+ const closed = screen.getAllByRole("listitem").filter((li) => li.parentElement?.tagName === "OL")[0]!;
+ // Closed, the row is tier, title, file:line and gain; the rest waits behind it.
+ expect(within(closed).getByText("+1.7 health on this file")).toBeTruthy();
+ expect(within(closed).queryByText(REFACTOR.why)).toBeNull();
+ openRow(REFACTOR);
const items = screen.getAllByRole("listitem").filter((li) => li.parentElement?.tagName === "OL");
const lead = items[0]!;
expect(within(lead).getByText("Now")).toBeTruthy();
@@ -77,8 +97,9 @@ describe("Fix first items", () => {
expect(within(lead).getByText("Small")).toBeTruthy();
});
- it("opens the lead with steps marked mechanical, Verify with reasons, and a copyable command", () => {
+ it("opens a row onto steps marked mechanical, Verify with reasons, and a copyable command", () => {
renderList();
+ openRow(REFACTOR);
expect(screen.getByText(/Extract lines 60-122 of quick_repo_scan into compute_info\(repo_path\)/)).toBeTruthy();
expect(screen.getAllByText("Mechanical").length).toBe(1);
expect(screen.getByText("tests/unit/cli/test_repo_scanner.py")).toBeTruthy();
@@ -91,7 +112,7 @@ describe("Fix first items", () => {
it("says no guarding tests were found when Verify is empty", () => {
renderList();
- fireEvent.click(screen.getByRole("button", { name: new RegExp(FINDING.title.replace(/[()]/g, "\\$&")) }));
+ openRow(FINDING);
expect(screen.getByText(/No guarding tests found/)).toBeTruthy();
});
@@ -100,6 +121,7 @@ describe("Fix first items", () => {
expect(fixPlanLabel(PERF)).toBe("Open the performance fix");
expect(fixPlanLabel(FINDING)).toBeNull();
renderList();
+ openRow(REFACTOR);
expect(screen.getByRole("link", { name: "Open the refactoring plan" }).getAttribute("href")).toBe(
"/plan/refop3_8ba13d978db910d160b1",
);
@@ -108,12 +130,13 @@ describe("Fix first items", () => {
it("offers triage only for an item backed by a finding id, and writes through the host", async () => {
const onTriage = vi.fn().mockResolvedValue(undefined);
renderList({ onTriage });
+ openRow(REFACTOR);
fireEvent.click(screen.getByRole("button", { name: "Acknowledged" }));
await waitFor(() => expect(onTriage).toHaveBeenCalledWith(REFACTOR, "acknowledged"));
expect(await screen.findByText("Saved as acknowledged.")).toBeTruthy();
// The perf item maps to no finding, so it has no triage control.
- fireEvent.click(screen.getByRole("button", { name: new RegExp(PERF.title) }));
+ openRow(PERF);
expect(screen.getAllByRole("button", { name: "Acknowledged" }).length).toBe(1);
});
@@ -134,6 +157,7 @@ describe("Fix first agent prompt", () => {
it("shows the prompt the host loads for the item", async () => {
const loadPrompt = vi.fn().mockResolvedValue("Prompt from core");
renderList({ loadPrompt });
+ openRow(REFACTOR);
fireEvent.click(screen.getByRole("button", { name: "Copy prompt for an agent" }));
expect(await screen.findByText("Prompt from core")).toBeTruthy();
expect(loadPrompt).toHaveBeenCalledWith(REFACTOR, expect.any(String));
diff --git a/packages/ui/__tests__/health/triage-view-lead.test.tsx b/packages/ui/__tests__/health/triage-view-lead.test.tsx
index 175212d47..3b02f420a 100644
--- a/packages/ui/__tests__/health/triage-view-lead.test.tsx
+++ b/packages/ui/__tests__/health/triage-view-lead.test.tsx
@@ -1,7 +1,6 @@
/**
- * When the host hands TriageView a lead (Fix first), it renders above the
- * score, and the score drops to one secondary line. Without one, the score
- * keeps leading, so a host that has not adopted Fix first is unchanged.
+ * The score leads Code Health in full. When the host hands TriageView Fix
+ * first, it renders under the score, never above it.
*/
import { describe, expect, it, vi } from "vitest";
@@ -42,18 +41,19 @@ function renderView(leadSlot?: React.ReactNode) {
}
describe("TriageView lead", () => {
- it("puts the lead first and the score behind one line", async () => {
+ it("leads with the full score and puts Fix first under it", async () => {
const { container } = renderView(<section data-testid="lead">Fix first</section>);
- await screen.findByText(/out of 10 across 3,787 files/);
+ const score = await screen.findByText("Maintainability");
const lead = screen.getByTestId("lead");
- const details = container.querySelector("details")!;
- expect(lead.compareDocumentPosition(details) & Node.DOCUMENT_POSITION_FOLLOWING).toBeTruthy();
- expect(details.open).toBe(false);
+ expect(score.compareDocumentPosition(lead) & Node.DOCUMENT_POSITION_FOLLOWING).toBeTruthy();
+ // The score is not folded behind a disclosure.
+ expect(screen.getByText("6.8").closest("details")).toBeNull();
+ expect(container.textContent).not.toContain("More");
});
it("keeps the full lede when no lead is given", async () => {
- const { container } = renderView();
+ renderView();
await screen.findByText("Maintainability");
- expect(container.querySelector("details")).toBeNull();
+ expect(screen.getByText("6.8").closest("details")).toBeNull();
});
});
diff --git a/packages/ui/src/health/code-health-lede.tsx b/packages/ui/src/health/code-health-lede.tsx
index b31218bf6..44f52968f 100644
--- a/packages/ui/src/health/code-health-lede.tsx
+++ b/packages/ui/src/health/code-health-lede.tsx
@@ -34,6 +34,11 @@ import { formatNumber } from "../lib/format";
import { healthBand, healthBandColor, scoreTextColor } from "./tokens";
import { HealthDistributionBar } from "./health-distribution-bar";
import { HEALTH_UNSUPPORTED_NOTICE } from "./map/lens";
+import { Info } from "lucide-react";
+
+/** The lede's two quiet toggles: "Breakdown" under the figure, "How it is scored" under the prose. */
+const DISCLOSURE =
+ "inline-flex cursor-pointer list-none items-center gap-1 rounded text-[11px] font-medium text-[var(--color-text-tertiary)] hover:text-[var(--color-text-secondary)] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--color-accent-primary)] [&::-webkit-details-marker]:hidden";
const HEALTH_HINT =
"Fitted against real bug history to predict where defects appear. Built from " +
@@ -204,34 +209,51 @@ export function CodeHealthLede({
layout="beside"
// The two second reads that belong to this number: how the repo's code
// volume splits across the bands, and how much of the deduction no
- // refactor can reach. The average alone hides whether this is
- // everything-mediocre or mostly-healthy-with-a-bad-corner, and it hides
- // that a refactor may not move it at all.
+ // refactor can reach. Both sit behind "Breakdown" so the first read is
+ // the figure and its band; native <details>, so keyboard and screen
+ // readers get the toggle for free.
figureFooter={
<>
- {distribution && <HealthDistributionBar distribution={distribution} height="sm" />}
- {codeShape ? (
- <p className="mt-3 text-[11px] leading-snug text-[var(--color-text-tertiary)]">
- Change history excluded. This scores the code alone, and every
- finding on this page counts toward it.
- {unscored > 0 && (
- <>
- {" "}
- {formatNumber(unscored)} files are not scored here, having no
- recorded split yet.
- </>
- )}
+ {codeShape && (
+ <p className="text-[11px] leading-snug text-[var(--color-text-tertiary)]">
+ Change history excluded.
</p>
- ) : (
- historyShare != null && (
- <p className="mt-3 text-[11px] leading-snug text-[var(--color-text-tertiary)]">
- <span className="tabular-nums text-[var(--color-text-secondary)]">
- {historyShare}%
- </span>{" "}
- of this comes from change history, not from the code. No edit to
- these files clears it.
- </p>
- )
+ )}
+ {(distribution || codeShape || historyShare != null) && (
+ <details className="mt-1.5">
+ <summary className={DISCLOSURE}>
+ <Info aria-hidden className="h-3 w-3" />
+ Breakdown
+ </summary>
+ <div className="mt-2.5 flex flex-col gap-3">
+ {distribution && (
+ <HealthDistributionBar distribution={distribution} height="sm" />
+ )}
+ {codeShape ? (
+ <p className="text-[11px] leading-snug text-[var(--color-text-tertiary)]">
+ This scores the code alone, and every finding on this page
+ counts toward it.
+ {unscored > 0 && (
+ <>
+ {" "}
+ {formatNumber(unscored)} files are not scored here, having
+ no recorded split yet.
+ </>
+ )}
+ </p>
+ ) : (
+ historyShare != null && (
+ <p className="text-[11px] leading-snug text-[var(--color-text-tertiary)]">
+ <span className="tabular-nums text-[var(--color-text-secondary)]">
+ {historyShare}%
+ </span>{" "}
+ of this comes from change history, not from the code. No
+ edit to these files clears it.
+ </p>
+ )
+ )}
+ </div>
+ </details>
)}
</>
}
@@ -241,23 +263,18 @@ export function CodeHealthLede({
<strong className="font-semibold text-[var(--color-text-primary)]">
{formatNumber(summary.file_count)} files
</strong>
- , this codebase scores{" "}
- <strong className="font-semibold text-[var(--color-text-primary)]">
- {formatScore(health)} out of 10
- </strong>{" "}
- for code health, weighted by lines of code and built from complexity,
- duplication, coverage
- {codeShape ? "" : ", churn and ownership"}.
- {healthChip ? <> That puts it in the {healthChip.label} band.</> : null}
- <UnanalysedNote count={summary.unanalysed_file_count ?? 0} />
- {perf != null && (
+ , weighted by lines of code.
+ {hotspot != null && (
<>
{" "}
- {/* Not "performance risk": this is a score on the same ladder
- as the health number, so a risk noun inverts it. "risk" belongs
- to the findings count in the ribbon. Matches HealthLede. */}
- Static performance is scored separately at {formatScore(perf)} out of
- 10 and never blended into the health score.
+ The files you change most average{" "}
+ <strong
+ className="font-semibold"
+ style={{ color: healthBandColor(bandForScore(hotspot)) }}
+ >
+ {formatScore(hotspot)}
+ </strong>
+ , {describeGap(hotspot, health)}
</>
)}
</p>
@@ -268,54 +285,61 @@ export function CodeHealthLede({
<strong className="font-semibold text-[var(--color-text-primary)]">
{accuracy.hits} of the {accuracy.k} files
</strong>{" "}
- it scores worst were touched by a fix in the last{" "}
- {windowLabel(accuracy.window_days)}. That is{" "}
+ it scores worst had a fix in the last {windowLabel(accuracy.window_days)},{" "}
{Math.round(accuracy.precision * 100)}% against a{" "}
- {Math.round(accuracy.base_rate * 100)}% base rate across the repo
+ {Math.round(accuracy.base_rate * 100)}% base rate
{accuracy.lift != null && (
<>
, so{" "}
<strong className="font-semibold text-[var(--color-text-primary)]">
{accuracy.lift}× better
</strong>{" "}
- than picking files at random
+ than picking at random
</>
)}
.
</p>
)}
- {hotspot != null && (
- <p className="mt-2.5">
- The files you change most average{" "}
- <strong
- className="font-semibold"
- style={{ color: healthBandColor(bandForScore(hotspot)) }}
- >
- {formatScore(hotspot)}
- </strong>
- , {describeGap(hotspot, health)}
- </p>
- )}
-
- {/* Tests are ranked apart from production files, so the weakest one
- would otherwise never be named on this page. */}
- {worstTestPath && worstTestScore != null && (
- <p className="mt-2.5">
- Test files are ranked apart. The lowest scoring is{" "}
- <span className="break-all font-mono text-[12px] text-[var(--color-text-primary)]">
- {worstTestPath}
- </span>{" "}
- at{" "}
- <strong
- className="font-semibold"
- style={{ color: healthBandColor(bandForScore(worstTestScore)) }}
- >
- {formatScore(worstTestScore)}
- </strong>
- .
- </p>
- )}
+ {/* The rest qualifies the figure rather than stating it, so it waits
+ behind one toggle instead of filling the first screen. */}
+ <details className="mt-2.5 break-inside-avoid">
+ <summary className={DISCLOSURE}>How it is scored</summary>
+ <div className="mt-2 flex flex-col gap-2">
+ <p>
+ Built from complexity, duplication, coverage
+ {codeShape ? "" : ", churn and ownership"}.
+ <UnanalysedNote count={summary.unanalysed_file_count ?? 0} />
+ </p>
+ {perf != null && (
+ // Not "performance risk": this is a score on the same ladder as
+ // the health number, so a risk noun inverts it. "risk" belongs to
+ // the findings count in the ribbon. Matches HealthLede.
+ <p>
+ Static performance is scored separately at {formatScore(perf)} out
+ of 10 and never blended into the health score.
+ </p>
+ )}
+ {/* Tests are ranked apart from production files, so the weakest
+ one would otherwise never be named on this page. */}
+ {worstTestPath && worstTestScore != null && (
+ <p>
+ Test files are ranked apart. The lowest scoring is{" "}
+ <span className="break-all font-mono text-[12px] text-[var(--color-text-primary)]">
+ {worstTestPath}
+ </span>{" "}
+ at{" "}
+ <strong
+ className="font-semibold"
+ style={{ color: healthBandColor(bandForScore(worstTestScore)) }}
+ >
+ {formatScore(worstTestScore)}
+ </strong>
+ .
+ </p>
+ )}
+ </div>
+ </details>
</PageLede>
<StatRibbon stats={stats} />
@@ -372,6 +396,6 @@ function describeGap(hotspot: number, average: number): string {
const gap = hotspot - average;
if (Math.abs(gap) < 0.25) return "in line with the codebase overall.";
return gap < 0
- ? `${Math.abs(gap).toFixed(1)} below the codebase overall. The weak spot is the code in motion.`
- : `${gap.toFixed(1)} above the codebase overall, so the busiest files are holding up.`;
+ ? `${Math.abs(gap).toFixed(1)} below the codebase overall.`
+ : `${gap.toFixed(1)} above the codebase overall.`;
}
diff --git a/packages/ui/src/health/fix-first/fix-first-item.tsx b/packages/ui/src/health/fix-first/fix-first-item.tsx
index 93903c8fe..33c3529b7 100644
--- a/packages/ui/src/health/fix-first/fix-first-item.tsx
+++ b/packages/ui/src/health/fix-first/fix-first-item.tsx
@@ -3,8 +3,9 @@
/**
* One Fix-first item: the change to make, where, why, and what it buys.
*
- * Collapsed, it is one scan line per fact a person decides on. Expanded, it is
- * the work itself: the steps in order with which ones are mechanical, how to
+ * Collapsed, it is two compact lines: tier and title, then file:line and gain.
+ * Expanded, it adds the why, effort, confidence and risk, then the work
+ * itself: the steps in order with which ones are mechanical, how to
* verify the change, the history around the file (muted, never ranked on), and
* the actions. Every word and number is the payload's; this component chooses
* only where each one sits.
@@ -70,12 +71,13 @@ export function FixFirstItem({
const reason = tierReason(item);
return (
- <li className="py-4">
- {/* Tier sits in its own column from sm; on a phone it rides above the
- title so the title keeps the width. */}
- <div className="flex min-w-0 flex-col gap-1 sm:flex-row sm:items-start sm:gap-3">
+ <li className="py-1.5">
+ {/* Two scan lines: tier and title, then where and what it buys. The why,
+ effort, confidence and risk open with the row. Tier sits in its own
+ column from sm; on a phone it rides above the title. */}
+ <div className="flex min-w-0 flex-col sm:flex-row sm:items-start sm:gap-3">
<span
- className="inline-flex shrink-0 items-center gap-1.5 text-xs text-[var(--color-text-secondary)] sm:mt-[3px] sm:w-14"
+ className="inline-flex shrink-0 items-center gap-1.5 text-xs leading-5 text-[var(--color-text-secondary)] sm:w-14"
{...(reason ? { title: reason } : {})}
>
<span aria-hidden className={`h-2 w-2 shrink-0 rounded-full ${TIER_DOT[item.tier]}`} />
@@ -90,44 +92,48 @@ export function FixFirstItem({
aria-controls={panelId}
className="group flex w-full min-w-0 items-start justify-between gap-3 rounded text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--color-accent-primary)]"
>
- <span className="min-w-0 text-[15px] font-semibold leading-snug text-[var(--color-text-primary)] [overflow-wrap:anywhere] [text-wrap:pretty] group-hover:text-[var(--color-accent-primary)]">
+ <span className="min-w-0 text-[13px] font-medium leading-5 text-[var(--color-text-primary)] [overflow-wrap:anywhere] group-hover:text-[var(--color-accent-primary)]">
{item.title}
</span>
<ChevronDown
aria-hidden
- className={`mt-0.5 h-4 w-4 shrink-0 text-[var(--color-text-tertiary)] transition-transform ${
+ className={`mt-[3px] h-3.5 w-3.5 shrink-0 text-[var(--color-text-tertiary)] transition-transform ${
expanded ? "rotate-180" : ""
}`}
/>
</button>
- <p className="mt-1 font-mono text-xs [overflow-wrap:anywhere]">
+ <p className="flex min-w-0 flex-wrap items-baseline gap-x-3 text-xs leading-4">
{href ? (
- <Link href={href} className={LINK}>
+ <Link href={href} className={`font-mono [overflow-wrap:anywhere] ${LINK}`}>
{location}
</Link>
) : (
- <span className="text-[var(--color-text-secondary)]">{location}</span>
+ <span className="font-mono text-[var(--color-text-secondary)] [overflow-wrap:anywhere]">
+ {location}
+ </span>
)}
+ <span className="text-[var(--color-text-tertiary)]">
+ Gain <span className="text-[var(--color-text-secondary)]">{item.gain.text}</span>
+ </span>
</p>
- <p className="mt-1.5 max-w-[72ch] text-xs leading-relaxed text-[var(--color-text-secondary)] [text-wrap:pretty]">
- {item.why}
- </p>
-
- <dl className="mt-1.5 flex flex-wrap gap-x-4 gap-y-1 text-xs text-[var(--color-text-tertiary)]">
- <Fact label="Gain" value={item.gain.text} />
- <Fact label="Effort" value={EFFORT_LABEL[item.effort.bucket]} title={item.effort.basis} />
- <Fact
- label="Confidence"
- value={CONFIDENCE_LABEL[item.confidence.level]}
- title={item.confidence.reason}
- />
- <Fact label="Risk" value={item.risk.text} />
- </dl>
-
{expanded ? (
- <div id={panelId} className="mt-4 flex flex-col gap-5">
+ <div id={panelId} className="mt-3 mb-2 flex flex-col gap-4">
+ <div>
+ <p className="max-w-[72ch] text-xs leading-relaxed text-[var(--color-text-secondary)] [text-wrap:pretty]">
+ {item.why}
+ </p>
+ <dl className="mt-1.5 flex flex-wrap gap-x-4 gap-y-1 text-xs text-[var(--color-text-tertiary)]">
+ <Fact label="Effort" value={EFFORT_LABEL[item.effort.bucket]} title={item.effort.basis} />
+ <Fact
+ label="Confidence"
+ value={CONFIDENCE_LABEL[item.confidence.level]}
+ title={item.confidence.reason}
+ />
+ <Fact label="Risk" value={item.risk.text} />
+ </dl>
+ </div>
<Steps item={item} fileHref={fileHref} LinkComponent={LinkComponent} />
<FixVerify item={item} />
{item.context.length > 0 ? (
diff --git a/packages/ui/src/health/fix-first/fix-first-list.tsx b/packages/ui/src/health/fix-first/fix-first-list.tsx
index dd76dc6a9..2185a360e 100644
--- a/packages/ui/src/health/fix-first/fix-first-list.tsx
+++ b/packages/ui/src/health/fix-first/fix-first-list.tsx
@@ -35,6 +35,11 @@ export interface FixFirstListProps {
LinkComponent?: ElementType | undefined;
/** Drop the section's top hairline when it opens the page. */
flush?: boolean | undefined;
+ /**
+ * Closed by default: the score leads Code Health, and Fix first sits under
+ * it as one line with its count until the reader opens it.
+ */
+ defaultOpen?: boolean | undefined;
}
export function FixFirstList({
@@ -49,16 +54,16 @@ export function FixFirstList({
onTriage,
loadPrompt,
LinkComponent,
- flush = true,
+ flush = false,
+ defaultOpen = false,
}: FixFirstListProps) {
- // The lead opens expanded: it is the one thing this section says to do.
- const [open, setOpen] = useState<ReadonlySet<string> | null>(null);
- const expanded = open ?? new Set(queue?.lead ? [queue.lead.id] : []);
+ // Every row starts as its one or two scan lines; the detail opens per row.
+ const [expanded, setExpanded] = useState<ReadonlySet<string>>(() => new Set());
const toggle = (id: string) => {
const next = new Set(expanded);
if (next.has(id)) next.delete(id);
else next.add(id);
- setOpen(next);
+ setExpanded(next);
};
const [promptFor, setPromptFor] = useState<FixItem | null>(null);
// Only fetched while the modal is open on an item; stable per item.
@@ -83,13 +88,20 @@ export function FixFirstList({
? `${fixFirstScopeSentence(queue)}${scope === "all" ? " Test files are included." : ""}`
: undefined;
+ const count = queue ? queue.items.length : null;
+
return (
<OverviewSection
title="Fix first"
flush={flush}
- action={toggleTests}
+ collapsible
+ defaultOpen={defaultOpen}
+ {...(count !== null ? { hint: `${count} ${count === 1 ? "item" : "items"}` } : {})}
{...(description ? { description } : {})}
>
+ {/* A collapsible section has no header action slot, so the toggle
+ leads the body. */}
+ {toggleTests ? <div>{toggleTests}</div> : null}
{error ? (
<ApiError
title="Couldn't load Fix first"
diff --git a/packages/ui/src/health/triage-view.tsx b/packages/ui/src/health/triage-view.tsx
index 1498e9da4..d72052e43 100644
--- a/packages/ui/src/health/triage-view.tsx
+++ b/packages/ui/src/health/triage-view.tsx
@@ -120,9 +120,8 @@ export function TriageView({
hotspotsSlot?: ReactNode;
trendSlot?: ReactNode;
/**
- * What the page leads with, above the score. When set, the score drops to
- * one secondary line with the rest behind "More": a ranked list of what to
- * fix answers "what do I do?" and the score only answers "how bad is it?".
+ * Fix first, under the score. The score leads the page; the host renders
+ * this collapsed so the headline keeps the first screen.
*/
leadSlot?: ReactNode;
}) {
@@ -165,14 +164,14 @@ export function TriageView({
if (isLoading) {
return (
<div className="flex flex-col gap-6">
- {/* The lead has its own request, so it never waits on this one. */}
- {leadSlot}
{/* Shapes and widths match the real layout. A skeleton that does not
causes a reflow when content lands, which reads as slower than
showing nothing. */}
<Skeleton className="h-12 w-40 rounded-lg" />
<Skeleton className="h-20 w-full max-w-[54ch] rounded-lg" />
<Skeleton className="h-[74px] w-full" />
+ {/* Fix first has its own request, so it never waits on this one. */}
+ {leadSlot}
<Skeleton className="w-full rounded-xl" style={{ height: MAP_HEIGHT }} />
</div>
);
@@ -195,14 +194,13 @@ export function TriageView({
return (
<div className="flex flex-col gap-6 sm:gap-8">
- {leadSlot}
<CodeHealthLede
summary={overview.summary}
accuracy={overview.defect_accuracy ?? null}
distribution={overview.distribution ?? null}
pillar={overlay === "maintainability" ? "maintainability" : "health"}
- variant={leadSlot ? "secondary" : "lead"}
/>
+ {leadSlot}
<OverviewSection
title="Code health map"
diff --git a/packages/web/src/components/code-health/fix-first-section.test.tsx b/packages/web/src/components/code-health/fix-first-section.test.tsx
index a2e3dbe7c..f7a6beed1 100644
--- a/packages/web/src/components/code-health/fix-first-section.test.tsx
+++ b/packages/web/src/components/code-health/fix-first-section.test.tsx
@@ -116,7 +116,9 @@ describe("FixFirstSection", () => {
getFixFirst.mockResolvedValue(queue([item({})]));
updateFindingStatus.mockResolvedValue({});
renderSection();
- fireEvent.click(await screen.findByRole("button", { name: "Resolved" }));
+ // Rows start closed; the actions open with the row.
+ fireEvent.click(await screen.findByRole("button", { name: /Extract lines 60-122/ }));
+ fireEvent.click(screen.getByRole("button", { name: "Resolved" }));
await waitFor(() => expect(updateFindingStatus).toHaveBeenCalledTimes(2));
expect(updateFindingStatus).toHaveBeenCalledWith("r1", "finding_1", "resolved");
expect(updateFindingStatus).toHaveBeenCalledWith("r1", "finding_2", "resolved");
@@ -126,7 +128,8 @@ describe("FixFirstSection", () => {
getFixFirst.mockResolvedValue(queue([item({})]));
getFixFirstItemPrompt.mockResolvedValue({ flavor: "generic", text: "Core prompt text" });
renderSection();
- fireEvent.click((await screen.findAllByRole("button", { name: "Copy prompt for an agent" }))[0]!);
+ fireEvent.click(await screen.findByRole("button", { name: /Extract lines 60-122/ }));
+ fireEvent.click(screen.getAllByRole("button", { name: "Copy prompt for an agent" })[0]!);
expect(await screen.findByText("Core prompt text")).toBeTruthy();
expect(getFixFirstItemPrompt).toHaveBeenCalledWith("r1", "fix1_a", {
flavor: expect.any(String),