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(health): floor displayed scores so the figure never rounds into the next band (#2587)
Raghav Chamadiya468a7e62cebc
diff --git a/packages/cli/src/repowise/cli/commands/health_cmd/summary.py b/packages/cli/src/repowise/cli/commands/health_cmd/summary.pyindex 8cdc7a691..f711153fd 100644--- a/packages/cli/src/repowise/cli/commands/health_cmd/summary.py+++ b/packages/cli/src/repowise/cli/commands/health_cmd/summary.py@@ -96,13 +96,13 @@ def _render_badge(average_health: object) -> None:Emits a static shields badge for the current score (immediately usable) anddocuments the live endpoint form for a running Repowise server / hosted repo."""- from repowise.core.analysis.health.grading import BAND_BADGE_COLOR, band_for+ from repowise.core.analysis.health.grading import BAND_BADGE_COLOR, band_for, format_scoreif not isinstance(average_health, (int, float)):console.print("[yellow]No health score yet — run `repowise health` first.[/yellow]")returncolor = BAND_BADGE_COLOR[band_for(float(average_health))]- msg = f"{float(average_health):.1f}/10"+ msg = f"{format_score(float(average_health))}/10"static = f"https://img.shields.io/badge/health-{msg.replace('/', '%2F')}-{color}"console.print("[bold]Static badge (current score):[/bold]")console.print(f" ")diff --git a/packages/cli/src/repowise/cli/commands/status_cmd.py b/packages/cli/src/repowise/cli/commands/status_cmd.pyindex 981e0be48..2d451ef0f 100644--- a/packages/cli/src/repowise/cli/commands/status_cmd.py+++ b/packages/cli/src/repowise/cli/commands/status_cmd.py@@ -272,25 +272,27 @@ def _query_health_line(repo_path: Path) -> str | None:return Noneworst_path = data["worst_performer_path"] or "n/a"worst_score = data["worst_performer_score"]- worst_repr = f"{worst_score:.1f}" if worst_score is not None else "—"from repowise.core.analysis.health.grading import (BAND_LABEL,BAND_TERMINAL_COLOR,band_for,+ format_score,)+ worst_repr = format_score(worst_score) if worst_score is not None else "—"+band = band_for(float(data["average_health"]))band_color = BAND_TERMINAL_COLOR[band]# Maintainability and performance are co-surfaced pillars; show each when the# split has populated it (None on indexes that predate the relevant work).maint = data.get("maintainability_average")- maint_part = f" · {maint:.1f} (maintainability)" if maint is not None else ""+ maint_part = f" · {format_score(maint)} (maintainability)" if maint is not None else ""# Performance leads with the finding COUNT (the honest signal); the bounded# /10 average trails in parens as a summary, never as a verification claim.perf = data.get("performance_average")perf_findings = data.get("performance_findings", 0)perf_part = (- f" · {perf_findings} perf finding{'s' if perf_findings != 1 else ''} ({perf:.1f})"+ f" · {perf_findings} perf finding{'s' if perf_findings != 1 else ''} ({format_score(perf)})"if perf is not Noneelse "")@@ -298,9 +300,9 @@ def _query_health_line(repo_path: Path) -> str | None:# rather than printing a 10.0 that would read as "your hotspots are# perfect" when there are none to score.hotspot = data.get("hotspot_health")- hotspot_part = f"{hotspot:.1f} (hotspots) · " if hotspot is not None else ""+ hotspot_part = f"{format_score(hotspot)} (hotspots) · " if hotspot is not None else ""return (- f"[bold]Health:[/bold] {data['average_health']:.1f} (avg) "+ f"[bold]Health:[/bold] {format_score(data['average_health'])} (avg) "f"[[{band_color}]{BAND_LABEL[band]}[/{band_color}]] · "f"{hotspot_part}"f"{worst_repr} (worst: {worst_path})"diff --git a/packages/core/src/repowise/core/analysis/health/grading.py b/packages/core/src/repowise/core/analysis/health/grading.pyindex b7835f47f..c3e4da506 100644--- a/packages/core/src/repowise/core/analysis/health/grading.py+++ b/packages/core/src/repowise/core/analysis/health/grading.py@@ -98,6 +98,17 @@ def band_for(score: float) -> HealthBand:return "at_risk"+def format_score(score: float) -> str:+ """A 1-10 score at one decimal, rounded down, for display beside its band.++ Rounding to nearest would print 6.98 as "7.0" beside "Fair"; flooring can+ never cross a band edge, and :func:`band_for` stays on the unrounded value.+ Mirror of ``formatScore`` in ``packages/types``.+ """+ nearest = float(f"{score:.1f}")+ return f"{nearest - 0.1 if nearest > score else nearest:.1f}"++def distribution(metrics: list[Any]) -> dict[str, Any]:"""NLOC-weighted file distribution across the bands.diff --git a/packages/server/src/repowise/server/routers/code_health/badge.py b/packages/server/src/repowise/server/routers/code_health/badge.pyindex ee8d79e96..d4a91f87a 100644--- a/packages/server/src/repowise/server/routers/code_health/badge.py+++ b/packages/server/src/repowise/server/routers/code_health/badge.py@@ -5,7 +5,7 @@ from __future__ import annotationsfrom fastapi import Depends, HTTPException, Responsefrom sqlalchemy.ext.asyncio import AsyncSession-from repowise.core.analysis.health.grading import BAND_BADGE_COLOR, band_for+from repowise.core.analysis.health.grading import BAND_BADGE_COLOR, band_for, format_scorefrom repowise.core.persistence import crudfrom repowise.server.deps import get_db_sessionfrom repowise.server.schemas import HealthBadgeResponse@@ -30,7 +30,7 @@ def _badge_fields(average_health: float | None) -> tuple[str, str, str, str]:if average_health is None:return "health", "no data", _UNKNOWN_COLOR, "unknown"band = band_for(float(average_health))- return "health", f"{average_health:.1f}/10", BAND_BADGE_COLOR[band], band+ return "health", f"{format_score(average_health)}/10", BAND_BADGE_COLOR[band], banddef _render_badge_svg(label: str, message: str, color_name: str) -> str:diff --git a/packages/types/__tests__/health.test.ts b/packages/types/__tests__/health.test.tsindex 691d5f38b..d44a49f6e 100644--- a/packages/types/__tests__/health.test.ts+++ b/packages/types/__tests__/health.test.ts@@ -20,6 +20,7 @@ import {NEEDS_WORK_MIN,PERF_BOUNDARY_LABEL,bandForScore,+ formatScore,} from "../src/health.js";import { C4_IO_KINDS } from "../src/external-systems.js";@@ -71,3 +72,16 @@ describe("bandForScore", () => {expect(bandForScore(1.0)).toBe("at_risk");});});++describe("formatScore", () => {+ it("never rounds a score across a band edge", () => {+ // 6.98 rounds to "7.0" but bands Fair; the shown figure must band the same.+ for (const score of [6.98, 6.95, 8.49, 5.46, 3.999, 6.9999999]) {+ expect(bandForScore(Number(formatScore(score)))).toBe(bandForScore(score));+ }+ expect(formatScore(6.98)).toBe("6.9");+ expect(formatScore(7.0)).toBe("7.0");+ expect(formatScore(5.6)).toBe("5.6");+ expect(formatScore(10.0)).toBe("10.0");+ });+});diff --git a/packages/types/src/health.ts b/packages/types/src/health.tsindex 357dab8a3..48bd192e6 100644--- a/packages/types/src/health.ts+++ b/packages/types/src/health.ts@@ -163,6 +163,17 @@ export function bandForScore(score: number): HealthBand {return "at_risk";}+/**+ * A 1-10 score at one decimal, rounded down, for display beside its band.+ * Rounding to nearest would print 6.98 as "7.0" beside "Fair"; flooring can+ * never cross a band edge, and the band itself stays on the unrounded value.+ * Mirror of `grading.format_score` in core.+ */+export function formatScore(score: number): string {+ const nearest = Number(score.toFixed(1));+ return (nearest > score ? nearest - 0.1 : nearest).toFixed(1);+}+export interface HealthBandShare {/** Number of files in this band. */files: number;diff --git a/packages/ui/__tests__/health/code-health-lede.test.tsx b/packages/ui/__tests__/health/code-health-lede.test.tsxindex 428a8e675..620b804ac 100644--- a/packages/ui/__tests__/health/code-health-lede.test.tsx+++ b/packages/ui/__tests__/health/code-health-lede.test.tsx@@ -105,3 +105,12 @@ describe("CodeHealthLede — the two readings of one figure", () => {expect(screen.getByText(/287 files are not scored here/)).toBeTruthy();});});++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");+ });+});diff --git a/packages/ui/src/coupling/coupling-graph.tsx b/packages/ui/src/coupling/coupling-graph.tsxindex edf11c3a0..59baa0647 100644--- a/packages/ui/src/coupling/coupling-graph.tsx+++ b/packages/ui/src/coupling/coupling-graph.tsx@@ -11,6 +11,7 @@ import {HEALTH_BAND_LABEL,HEALTH_BAND_ORDER,HEALTH_BAND_RANGE_LABEL,+ formatScore,} from "@repowise-dev/types/health";import { healthBandNodeFill, healthNodeFill } from "../health/tokens";import { disambiguateBasenames } from "../lib/format";@@ -451,7 +452,7 @@ export function CouplingGraph({stroke="var(--color-bg-surface)"strokeWidth={isFocus ? 1.6 : 1}>- <title>{`${n.file_path}${n.score != null ? ` · score ${n.score.toFixed(1)}` : ""} · ${degree.get(n.file_path) ?? 0} couplings`}</title>+ <title>{`${n.file_path}${n.score != null ? ` · score ${formatScore(n.score)}` : ""} · ${degree.get(n.file_path) ?? 0} couplings`}</title></circle>{showLabel ? (<textdiff --git a/packages/ui/src/dashboard/health-overview-card.tsx b/packages/ui/src/dashboard/health-overview-card.tsxindex 0be9dff8b..4f891ed9e 100644--- a/packages/ui/src/dashboard/health-overview-card.tsx+++ b/packages/ui/src/dashboard/health-overview-card.tsx@@ -13,6 +13,7 @@ import { Card, CardContent, CardHeader, CardTitle } from "../ui/card";import { fileEntityPath } from "../shared/entity/routes";import { truncatePath } from "../lib/format";import { healthBand } from "../health/tokens";+import { formatScore } from "@repowise-dev/types/health";import { Sparkline } from "../health/sparkline";export interface HealthOverviewPoint {@@ -171,7 +172,7 @@ function MetricTile({<><div className="flex items-baseline gap-1.5"><span className="text-3xl font-bold tabular-nums leading-none" style={{ color: b?.color }}>- {value.toFixed(1)}+ {formatScore(value)}</span><span className="text-sm text-[var(--color-text-tertiary)]">/10</span><TrendChip delta={delta} />@@ -360,7 +361,7 @@ export function HealthOverviewCard({className="shrink-0 text-xs font-bold tabular-nums"style={{ color: healthBand(data.worst_performer_score).color }}>- {data.worst_performer_score.toFixed(1)}/10+ {formatScore(data.worst_performer_score)}/10</span></a>)}@@ -418,7 +419,7 @@ function PillarStat({) : (<span className="flex items-baseline gap-1.5"><span className="text-xl font-bold tabular-nums leading-none" style={{ color: b?.color }}>- {score.toFixed(1)}+ {formatScore(score)}</span><span className="text-xs text-[var(--color-text-tertiary)]">/10</span>{b ? (@@ -473,7 +474,7 @@ function PerformancePillarStat({{findings === 1 ? "risk" : "risks"}</span><span className="text-[10px] tabular-nums text-[var(--color-text-tertiary)]">- · {score.toFixed(1)}/10+ · {formatScore(score)}/10</span></span>)}diff --git a/packages/ui/src/files/file-health-tab.tsx b/packages/ui/src/files/file-health-tab.tsxindex 441cd70f0..8868c35b0 100644--- a/packages/ui/src/files/file-health-tab.tsx+++ b/packages/ui/src/files/file-health-tab.tsx@@ -2,7 +2,7 @@import { useMemo, useState, type ReactNode } from "react";import { HeartPulse } from "lucide-react";-import { bandForScore, HEALTH_BAND_LABEL } from "@repowise-dev/types/health";+import { bandForScore, formatScore, HEALTH_BAND_LABEL } from "@repowise-dev/types/health";import { EmptyState } from "../shared/empty-state";import { VirtualizedTable, useVirtualRows } from "../shared/virtualized-table";import { ScoreBreakdown, type ScoreBreakdownCategory } from "../health/score-breakdown";@@ -143,7 +143,7 @@ export function FileHealthTab({if (metric.maintainability_score != null) {pillars.push({label: "Maintainability",- value: metric.maintainability_score.toFixed(1),+ value: formatScore(metric.maintainability_score),valueColor: healthBandTextColor(bandForScore(metric.maintainability_score)),sub: HEALTH_BAND_LABEL[bandForScore(metric.maintainability_score)],});@@ -151,7 +151,7 @@ export function FileHealthTab({if (metric.performance_score != null) {pillars.push({label: "Performance",- value: metric.performance_score.toFixed(1),+ value: formatScore(metric.performance_score),valueColor: healthBandTextColor(bandForScore(metric.performance_score)),sub: HEALTH_BAND_LABEL[bandForScore(metric.performance_score)],});diff --git a/packages/ui/src/files/file-page-header.tsx b/packages/ui/src/files/file-page-header.tsxindex 778c3cfa4..c434634e2 100644--- a/packages/ui/src/files/file-page-header.tsx+++ b/packages/ui/src/files/file-page-header.tsx@@ -1,5 +1,5 @@import * as React from "react";-import { bandForScore, HEALTH_BAND_LABEL } from "@repowise-dev/types/health";+import { bandForScore, formatScore, HEALTH_BAND_LABEL } from "@repowise-dev/types/health";import type { FileDetailResponse } from "@repowise-dev/types/files";import { AskAboutThis } from "../chat/ask-about-this";import { PageLede } from "../shared/page-lede";@@ -100,7 +100,7 @@ export function FilePageHeader({{score != null ? (<PageLedelabel="Code health"- value={score.toFixed(1)}+ value={formatScore(score)}valueColor={healthBandColor(bandForScore(score))}unit="out of 10"band={{diff --git a/packages/ui/src/files/files-treemap.tsx b/packages/ui/src/files/files-treemap.tsxindex 49b0c6465..887c7ee5a 100644--- a/packages/ui/src/files/files-treemap.tsx+++ b/packages/ui/src/files/files-treemap.tsx@@ -5,6 +5,7 @@ import { hierarchy, treemap, treemapSquarify, type HierarchyRectangularNode } frimport type { FileRow } from "@repowise-dev/types/files";import {bandForScore,+ formatScore,HEALTH_BAND_LABEL,HEALTH_BAND_ORDER,HEALTH_BAND_RANGE_LABEL,@@ -472,7 +473,7 @@ export function FilesTreemap({style={{ color: healthColor(tip.child.avgScore) }}>{HEALTH_BAND_LABEL[bandForScore(tip.child.avgScore)]} ·{" "}- {tip.child.avgScore.toFixed(1)}+ {formatScore(tip.child.avgScore)}</p>)}</div>diff --git a/packages/ui/src/graph/graph-community-panel.tsx b/packages/ui/src/graph/graph-community-panel.tsxindex 39a96f591..3e7d7caf8 100644--- a/packages/ui/src/graph/graph-community-panel.tsx+++ b/packages/ui/src/graph/graph-community-panel.tsx@@ -10,7 +10,7 @@ import { InfoTip } from "../shared/info-tip";import { truncatePath } from "../lib/format";// Shared band function, never a local threshold: two surfaces disagreeing// about where "Good" starts is worse than the import.-import { bandForScore, type HealthBand } from "@repowise-dev/types/health";+import { bandForScore, formatScore, type HealthBand } from "@repowise-dev/types/health";import { healthBand } from "../health/tokens";import type { CommunityDetail } from "@repowise-dev/types/graph";@@ -256,7 +256,7 @@ function HealthLede({className="text-[32px] font-semibold leading-none tracking-tight tabular-nums"style={{ color: band.color }}>- {score.toFixed(1)}+ {formatScore(score)}</span><span className="text-xs text-[var(--color-text-tertiary)]">out of 10</span><spandiff --git a/packages/ui/src/health/churn-complexity-quadrant.tsx b/packages/ui/src/health/churn-complexity-quadrant.tsxindex 59b7c31ed..7793cd4a7 100644--- a/packages/ui/src/health/churn-complexity-quadrant.tsx+++ b/packages/ui/src/health/churn-complexity-quadrant.tsx@@ -4,7 +4,7 @@ import { useMemo, useState } from "react";// Value imports must come from the package root, not the `/health` subpath:// the vite/rollup base alias clobbers subpath value resolution. Type-only// subpath imports are fine (erased before resolution).-import { bandForScore } from "@repowise-dev/types";+import { bandForScore, formatScore } from "@repowise-dev/types";import type { ChurnComplexityPoint } from "@repowise-dev/types/health";import { HEALTH_BAND_FILL } from "./tokens";@@ -148,7 +148,7 @@ export function ChurnComplexityQuadrant({onMouseLeave={() => setHovered(null)}onClick={onSelect ? () => onSelect(p) : undefined}>- <title>{`${p.file_path}\n${p.commit_count_90d} commits/90d (${Math.round(p.churn_percentile)}th pct) · CCN ${p.max_ccn} · NLOC ${p.nloc} · score ${p.score.toFixed(1)}`}</title>+ <title>{`${p.file_path}\n${p.commit_count_90d} commits/90d (${Math.round(p.churn_percentile)}th pct) · CCN ${p.max_ccn} · NLOC ${p.nloc} · score ${formatScore(p.score)}`}</title></circle>);})}@@ -157,7 +157,7 @@ export function ChurnComplexityQuadrant({<div className="pointer-events-none absolute bottom-2 left-2 rounded-md border border-[var(--color-border-default)] bg-[var(--color-bg-elevated)] px-2 py-1 text-xs shadow-md"><span className="font-mono text-[var(--color-text-primary)]">{hovered.file_path}</span><span className="ml-2 text-[var(--color-text-tertiary)]">- {hovered.commit_count_90d} commits · CCN {hovered.max_ccn} · {hovered.score.toFixed(1)}+ {hovered.commit_count_90d} commits · CCN {hovered.max_ccn} · {formatScore(hovered.score)}</span></div>) : null}diff --git a/packages/ui/src/health/code-health-lede.tsx b/packages/ui/src/health/code-health-lede.tsxindex 643501f9e..5bc3f1e9a 100644--- a/packages/ui/src/health/code-health-lede.tsx+++ b/packages/ui/src/health/code-health-lede.tsx@@ -23,6 +23,7 @@import {bandForScore,+ formatScore,type DefectAccuracy,type HealthDistribution,type HealthOverviewSummary,@@ -134,7 +135,7 @@ export function CodeHealthLede({{ label: "Files", value: formatNumber(summary.file_count), hint: FILES_HINT },{label: "Maintainability",- value: maint == null ? "" : maint.toFixed(1),+ value: maint == null ? "" : formatScore(maint),valueColor: maint == null ? undefined : scoreTextColor(maint),hint: MAINTAINABILITY_HINT,// The map's lens marks its figure here now that the lede carries one@@ -149,7 +150,7 @@ export function CodeHealthLede({},{label: "Hotspot health",- value: hotspot == null ? "" : hotspot.toFixed(1),+ value: hotspot == null ? "" : formatScore(hotspot),valueColor: hotspot == null ? undefined : scoreTextColor(hotspot),hint: codeShape ? HOTSPOT_HINT_CODE_SHAPE : HOTSPOT_HINT,},@@ -161,7 +162,7 @@ export function CodeHealthLede({<PageLedelabel="Code health"labelHint={codeShape ? CODE_SHAPE_HINT : HEALTH_HINT}- value={health.toFixed(1)}+ value={formatScore(health)}valueColor={healthChip?.color}unit="out of 10"{...(healthChip ? { band: healthChip } : {})}@@ -208,7 +209,7 @@ export function CodeHealthLede({</strong>, this codebase scores{" "}<strong className="font-semibold text-[var(--color-text-primary)]">- {health.toFixed(1)} out of 10+ {formatScore(health)} out of 10</strong>{" "}for code health, weighted by lines of code and built from complexity,duplication, coverage@@ -220,7 +221,7 @@ export function CodeHealthLede({{/* Not "performance risk": this is a score on the same ladderas the health number, so a risk noun inverts it. "risk" belongsto the findings count in the ribbon. Matches HealthLede. */}- Static performance is scored separately at {perf.toFixed(1)} out of+ Static performance is scored separately at {formatScore(perf)} out of10 and never blended into the health score.</>)}@@ -256,7 +257,7 @@ export function CodeHealthLede({className="font-semibold"style={{ color: healthBandColor(bandForScore(hotspot)) }}>- {hotspot.toFixed(1)}+ {formatScore(hotspot)}</strong>, {describeGap(hotspot, health)}</p>diff --git a/packages/ui/src/health/health-badge.tsx b/packages/ui/src/health/health-badge.tsxindex 5bb1cdad4..92e02723c 100644--- a/packages/ui/src/health/health-badge.tsx+++ b/packages/ui/src/health/health-badge.tsx@@ -1,4 +1,4 @@-import { bandForScore } from "@repowise-dev/types";+import { bandForScore, formatScore } from "@repowise-dev/types";import { HEALTH_BAND_ORDER, type HealthBand } from "@repowise-dev/types/health";import { healthBandSoftBadgeClass } from "./tokens";@@ -26,9 +26,9 @@ export function HealthBadge({ score, band, size = "xs" }: HealthBadgeProps) {return (<spanclassName={`inline-flex items-center rounded font-semibold tabular-nums ${cls} ${sizing}`}- title={`Health ${score.toFixed(1)}/10`}+ title={`Health ${formatScore(score)}/10`}>- {score.toFixed(1)}+ {formatScore(score)}</span>);}diff --git a/packages/ui/src/health/health-file-drawer.tsx b/packages/ui/src/health/health-file-drawer.tsxindex ac8993ea7..71692803b 100644--- a/packages/ui/src/health/health-file-drawer.tsx+++ b/packages/ui/src/health/health-file-drawer.tsx@@ -40,7 +40,7 @@ import {// The shared bands, never a local threshold: this pill sits beside marks that// all derive from `bandForScore`, and two of them disagreeing about where a// band starts describes one file two ways in one viewport.-import { bandForScore, HEALTH_BAND_LABEL } from "@repowise-dev/types/health";+import { bandForScore, formatScore, HEALTH_BAND_LABEL } from "@repowise-dev/types/health";import type {FileHealthTrend,FileSignals,@@ -458,7 +458,7 @@ export function HealthFileDrawer({className="text-[40px] font-semibold leading-none tracking-tight tabular-nums"style={{ color: healthBandColor(bandForScore(metric.score)) }}>- {metric.score.toFixed(1)}+ {formatScore(metric.score)}</span><span className="text-xs text-[var(--color-text-tertiary)]">out of 10</span></div>@@ -913,7 +913,7 @@ function PillarScore({ v }: { v: number | null }) {className="text-lg font-semibold tabular-nums"style={{ color: healthBandColor(bandForScore(v)) }}>- {v.toFixed(1)}+ {formatScore(v)}<span className="text-xs font-normal text-[var(--color-text-tertiary)]">/10</span></span>);diff --git a/packages/ui/src/health/module-rollup-list.tsx b/packages/ui/src/health/module-rollup-list.tsxindex c3ccf4139..3f493192b 100644--- a/packages/ui/src/health/module-rollup-list.tsx+++ b/packages/ui/src/health/module-rollup-list.tsx@@ -3,6 +3,7 @@import { useMemo, useState } from "react";import { ResponsiveTable, type ResponsiveColumn } from "../shared/responsive-table";import { HealthBadge } from "./health-badge";+import { formatScore } from "@repowise-dev/types/health";export interface ModuleRollupRow {module: string;@@ -69,7 +70,7 @@ const COLUMNS: ResponsiveColumn<ModuleRollupRow>[] = [>{m.worst_performer_path}{" "}<span className="text-[var(--color-text-tertiary)]">- ({m.worst_performer_score.toFixed(1)})+ ({formatScore(m.worst_performer_score)})</span></span>),diff --git a/packages/ui/src/health/risk-coverage-scatter.tsx b/packages/ui/src/health/risk-coverage-scatter.tsxindex 4119ba6fa..d43a96801 100644--- a/packages/ui/src/health/risk-coverage-scatter.tsx+++ b/packages/ui/src/health/risk-coverage-scatter.tsx@@ -1,7 +1,7 @@"use client";import { useEffect, useMemo, useRef, useState } from "react";-import { GOOD_MIN, bandForScore, type CoverageBasis } from "@repowise-dev/types/health";+import { GOOD_MIN, bandForScore, formatScore, type CoverageBasis } from "@repowise-dev/types/health";import { HEALTH_BAND_FILL } from "./tokens";export interface RiskCoveragePoint {@@ -310,7 +310,7 @@ export function RiskCoverageScatter({{active.file_path}</span><span className="tabular-nums text-[var(--color-text-tertiary)]">- {active.health_score.toFixed(1)} health ·{" "}+ {formatScore(active.health_score)} health ·{" "}{inferred? active.reached? "a test reaches it"diff --git a/packages/ui/src/health/trend-view.tsx b/packages/ui/src/health/trend-view.tsxindex 2e27899a1..8aa005ed4 100644--- a/packages/ui/src/health/trend-view.tsx+++ b/packages/ui/src/health/trend-view.tsx@@ -20,6 +20,7 @@import { AlertTriangle, Info } from "lucide-react";import type { HealthCounts, HealthTrendResponse } from "@repowise-dev/types/health";+import { formatScore } from "@repowise-dev/types/health";import { Skeleton } from "../ui/skeleton";import { StatRibbon, type RibbonStat } from "../stats/stat-ribbon";@@ -107,7 +108,7 @@ export function TrendView({const stats: RibbonStat[] = [{label: "Code health",- value: otherReading ? "—" : summary.current_average_health.toFixed(1),+ value: otherReading ? "—" : formatScore(summary.current_average_health),...(otherReading? { sub: "recorded on the full score" }: {@@ -120,7 +121,7 @@ export function TrendView({},{label: "Hotspot health",- value: otherReading || hotspot == null ? "—" : hotspot.toFixed(1),+ value: otherReading || hotspot == null ? "—" : formatScore(hotspot),...(otherReading? { sub: "recorded on the full score" }: {diff --git a/packages/ui/src/overview/health-lede.tsx b/packages/ui/src/overview/health-lede.tsxindex f77239a1d..6a454364a 100644--- a/packages/ui/src/overview/health-lede.tsx+++ b/packages/ui/src/overview/health-lede.tsx@@ -1,5 +1,6 @@import * as React from "react";import { healthBand } from "../health/tokens";+import { formatScore } from "@repowise-dev/types/health";import { LedeLink, PageLede } from "../shared/page-lede";export interface HealthLedeProps {@@ -67,8 +68,8 @@ export function HealthLede({// it is named like its siblings and the word "risk" is left to the findings// count on the health page, where more genuinely is worse.const pillars: string[] = [];- if (maintainability != null) pillars.push(`maintainability ${maintainability.toFixed(1)}`);- if (performance != null) pillars.push(`static performance ${performance.toFixed(1)}`);+ if (maintainability != null) pillars.push(`maintainability ${formatScore(maintainability)}`);+ if (performance != null) pillars.push(`static performance ${formatScore(performance)}`);const pillarSentence =pillars.length === 0? null@@ -81,7 +82,7 @@ export function HealthLede({return (<PageLedelabel="Code health"- value={score.toFixed(1)}+ value={formatScore(score)}valueColor={band.color}unit="out of 10"band={band}@@ -94,7 +95,7 @@ export function HealthLede({<p>This codebase scores{" "}<strong className="font-semibold text-[var(--color-text-primary)]">- {score.toFixed(1)} out of 10+ {formatScore(score)} out of 10</strong>{" "}for code health, which we rate {band.label.toLowerCase()}.{pillarSentence && ` ${pillarSentence}`}@@ -115,7 +116,7 @@ export function HealthLede({</strong>{" "}are git hotspots, and they average{" "}<strong className="font-semibold" style={{ color: hot.color }}>- {hotspotHealth!.toFixed(1)}+ {formatScore(hotspotHealth!)}</strong>{" "}— which is where the fixes pay off most.</>diff --git a/packages/ui/src/overview/repo-rows.tsx b/packages/ui/src/overview/repo-rows.tsxindex cbee0a97e..11325e2db 100644--- a/packages/ui/src/overview/repo-rows.tsx+++ b/packages/ui/src/overview/repo-rows.tsx@@ -1,5 +1,6 @@import * as React from "react";import type { RepoIndexStatus } from "@repowise-dev/types/repos";+import { formatScore } from "@repowise-dev/types/health";import { formatNumber, formatRelativeTime } from "../lib/format";import { healthBand } from "../health/tokens";import { RepoAvatar } from "./repo-avatar";@@ -176,7 +177,7 @@ export function RepoRows({ repos, LinkComponent, actionsFor }: RepoRowsProps) {className="mt-1 text-[22px] font-semibold leading-none tabular-nums"style={{ color: band.color }}>- {repo.health.toFixed(1)}+ {formatScore(repo.health)}</p><pclassName="mt-1 text-[11px]"diff --git a/packages/vscode/webview/src/views/health/App.tsx b/packages/vscode/webview/src/views/health/App.tsxindex 696520383..f5124f0ba 100644--- a/packages/vscode/webview/src/views/health/App.tsx+++ b/packages/vscode/webview/src/views/health/App.tsx@@ -25,7 +25,7 @@ import { CodeHealthLede } from "@repowise-dev/ui/health/code-health-lede";import { TrendView } from "@repowise-dev/ui/health/trend-view";import { scoreTextColor } from "@repowise-dev/ui/health/tokens";import { OverviewSection } from "@repowise-dev/ui/overview";-import type { HealthFileMetric } from "@repowise-dev/types/health";+import { formatScore, type HealthFileMetric } from "@repowise-dev/types/health";import type { ViewProps } from "../../runtime/mount";import {useChurnLens,@@ -232,7 +232,7 @@ function FocusedScore({ label, value }: { label: string; value: number | null }){label}</p><p className={`font-mono text-[15px] tabular-nums ${tone}`}>- {value == null ? "-" : value.toFixed(1)}+ {value == null ? "-" : formatScore(value)}</p></div>);diff --git a/packages/vscode/webview/src/views/home/App.tsx b/packages/vscode/webview/src/views/home/App.tsxindex f05dfec32..fe55b803c 100644--- a/packages/vscode/webview/src/views/home/App.tsx+++ b/packages/vscode/webview/src/views/home/App.tsx@@ -30,6 +30,7 @@ import {Wrench,} from "lucide-react";import { scoreTextColor } from "@repowise-dev/ui/health/tokens";+import { formatScore } from "@repowise-dev/types/health";import type {HomeSummary,PanelViewId,@@ -329,7 +330,7 @@ function Hero({<spanclassName={`text-4xl font-bold leading-none tracking-tight tabular-nums ${scoreTone(headline)}`}>- {headline.toFixed(1)}+ {formatScore(headline)}</span><span className="pb-0.5 text-xs text-[var(--color-text-tertiary)]">/ 10</span></div>@@ -338,7 +339,7 @@ function Hero({{hasHotspot ? (<><span aria-hidden className="text-[var(--color-text-tertiary)]">·</span>- <span>hotspot {health?.hotspot?.toFixed(1)}</span>+ <span>hotspot {health?.hotspot != null ? formatScore(health.hotspot) : undefined}</span><DeltaChip delta={health?.hotspotDelta ?? null} /></>) : null}diff --git a/packages/web/src/components/zoom/zoom-detail-panel.tsx b/packages/web/src/components/zoom/zoom-detail-panel.tsxindex 1b886a87e..8e3d1bc59 100644--- a/packages/web/src/components/zoom/zoom-detail-panel.tsx+++ b/packages/web/src/components/zoom/zoom-detail-panel.tsx@@ -28,7 +28,7 @@ import {nodeRoles,summarizeRelations,} from "@repowise-dev/ui/zoom";-import { bandForScore } from "@repowise-dev/types/health";+import { bandForScore, formatScore } from "@repowise-dev/types/health";import { fileEntityPath } from "@repowise-dev/ui/shared/entity";import { pageHref } from "@/lib/utils/page-href";import { healthBandTextColor } from "@repowise-dev/ui/health";@@ -159,7 +159,7 @@ export function ZoomDetailPanel({<div className="border-t border-[var(--color-border-default)] pt-3"><div className={`flex items-baseline gap-2 ${bandClass}`}><span className="text-[32px] font-bold leading-none tabular-nums">- {node.health_score.toFixed(1)}+ {formatScore(node.health_score)}</span><span className="text-[15px] font-medium">{band}</span></div>diff --git a/tests/unit/health/test_grading.py b/tests/unit/health/test_grading.pyindex 12b78ef0f..9e0287516 100644--- a/tests/unit/health/test_grading.py+++ b/tests/unit/health/test_grading.py@@ -20,6 +20,7 @@ from repowise.core.analysis.health.grading import (TARGET_SCORE,band_for,distribution,+ format_score,)@@ -52,6 +53,16 @@ def test_band_for_boundaries() -> None:assert band_for(1.0) == "at_risk"+def test_format_score_never_rounds_across_a_band_edge() -> None:+ # 6.98 rounds to "7.0" but bands Fair; the shown figure must band the same.+ for score in (6.98, 6.95, 8.49, 5.46, 3.999, 6.9999999):+ assert band_for(float(format_score(score))) == band_for(score), score+ assert format_score(6.98) == "6.9"+ assert format_score(7.0) == "7.0"+ assert format_score(5.6) == "5.6"+ assert format_score(10.0) == "10.0"++def test_every_band_has_a_label_a_range_and_a_colour() -> None:bands = set(BAND_ORDER)assert bands == {"at_risk", "needs_work", "fair", "good", "excellent"}diff --git a/tests/unit/server/test_health_badge.py b/tests/unit/server/test_health_badge.pyindex a158a44a7..34814272c 100644--- a/tests/unit/server/test_health_badge.py+++ b/tests/unit/server/test_health_badge.py@@ -21,6 +21,8 @@ def test_badge_fields_band_colors() -> None:assert _badge_fields(6.0) == ("health", "6.0/10", "yellow", "fair")assert _badge_fields(4.5) == ("health", "4.5/10", "orange", "needs_work")assert _badge_fields(2.0) == ("health", "2.0/10", "red", "at_risk")+ # Just under an edge: the message must not round up into the next band.+ assert _badge_fields(6.98) == ("health", "6.9/10", "yellow", "fair")def test_every_band_colour_has_a_hex_for_the_self_rendered_svg() -> None: