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.

feat(health): name production code's score beside the all-files headline (#4204)

Raghav Chamadiya02bf67bbf2bc
diff --git a/docs/reference/MCP_RESPONSE_FIELDS.md b/docs/reference/MCP_RESPONSE_FIELDS.md
index 39733bf84..8df0d36c0 100644
--- a/docs/reference/MCP_RESPONSE_FIELDS.md
+++ b/docs/reference/MCP_RESPONSE_FIELDS.md
@@ -373,7 +373,7 @@ Items are ordered by value first, then tier. History markers (churn, ownership,
| Field | Meaning |
|-------|---------|
-| `kpis` | Hotspot health, `average_health` (NLOC-weighted), `average_health_unweighted`, `average_health_weighting`, pillar averages, `worst_performer_path`, `worst_test_path`, `non_code_files`, `average_health_code_only` |
+| `kpis` | Hotspot health, `average_health` (NLOC-weighted), `average_health_unweighted`, `average_health_weighting`, pillar averages, `production_average` (production code alone; only while tests are in `average_health`), `worst_performer_path`, `worst_test_path` |
| `unanalysed_file_count` | Files in a language health has no dialect for, stored with no score and left out of every figure; absent when there are none |
| `kpis.band`, `kpis.analysed_share` | The headline band is `null` when fewer than half the code files were analysed, since the average then speaks for a sample; `analysed_share` (scored over all code files) appears when some were left out. `get_overview` reports `code_health` the same way |
| `gap_analysis` | Weighted points the average must recover to reach 8.0, files below it, `files_to_reach_target`, `files_for_half_gap`, `weighted_gap_points`, `weighted_gross_gap_points` |
@@ -382,7 +382,7 @@ Items are ordered by value first, then tier. History markers (churn, ownership,
| `top_findings` / `findings`, `test_findings` | Production and test findings; their totals sum to the whole open set |
| metric row | `score` (defect dimension and headline), `maintainability_score`, `performance_score`, `weighted_deficit` = (8 - score) x NLOC, `is_test`, `has_test_file`, `primary_biomarker`, `total_deduction`, `structure_deduction` and `history_deduction` (the score is 10 minus both, before the 1.0 floor; history reads 0.0 under `counts="code_shape"`), `history: "short"` only when the file has fewer than 5 recorded commits (new, split out, or renamed without follow), where most history markers cannot fire yet, and `withheld_deduction` when part of it comes from a withheld finding type |
-`weighted_deficit` and the gap fields share one unit, score points x NLOC; they compare only with each other. Non-code files score a mechanical 10.0 because no marker reads them; `average_health_code_only` shows the headline without them. `primary_biomarker` prefers a discrete finding over the continuous `coverage_gradient`. Each finding carries a `dimension`; `advisory` findings (`assertion_free_test`, `mock_saturated_test`) never deduct and appear only with `include=["advisory"]`.
+`weighted_deficit` and the gap fields share one unit, score points x NLOC; they compare only with each other. `primary_biomarker` prefers a discrete finding over the continuous `coverage_gradient`. Each finding carries a `dimension`; `advisory` findings (`assertion_free_test`, `mock_saturated_test`) never deduct and appear only with `include=["advisory"]`.
Provisional finding types appear only with `include=["unverified"]`, each marked `verification: "unverified"`. A withheld type never lists but still lowers the score it was counted in, so a file row reports it as `withheld_deduction` and `_meta.withheld` names the type, its count and why it is held back. Targeted mode is never split into production and test.
diff --git a/packages/cli/src/repowise/cli/commands/health_cmd/command.py b/packages/cli/src/repowise/cli/commands/health_cmd/command.py
index 2a4fb6900..65d83dc3f 100644
--- a/packages/cli/src/repowise/cli/commands/health_cmd/command.py
+++ b/packages/cli/src/repowise/cli/commands/health_cmd/command.py
@@ -577,8 +577,17 @@ def _render_headline(kpis: dict[str, Any], code_shape: bool, unanalysed: int) ->
if band is not None:
band_color = BAND_TERMINAL_COLOR[band]
band_str = f" [[{band_color}]{BAND_LABEL[band]}[/{band_color}]]"
+ # Production code beside the all-files figure, while tests are in it.
+ production = kpis.get("production_average")
+ has_tests = (kpis.get("production_file_count") or 0) < (kpis.get("file_count") or 0)
+ production_str = (
+ f"Production code: [bold]{production}[/bold]/10 · "
+ if production is not None and has_tests
+ else ""
+ )
console.print(
f"\nCode health: [bold]{avg if avg is not None else '?'}[/bold]/10{band_str} · "
+ f"{production_str}"
f"Hotspot: [bold]{kpis.get('hotspot_health') or '?'}[/bold]/10 · "
f"Worst: [bold]{kpis.get('worst_performer_score') or '?'}[/bold]/10 "
f"({kpis.get('worst_performer_path') or 'n/a'})"
diff --git a/packages/server/src/repowise/server/mcp_server/tool_health/summary.py b/packages/server/src/repowise/server/mcp_server/tool_health/summary.py
index 665e8dc29..59950e3f9 100644
--- a/packages/server/src/repowise/server/mcp_server/tool_health/summary.py
+++ b/packages/server/src/repowise/server/mcp_server/tool_health/summary.py
@@ -9,9 +9,11 @@ from repowise.core.analysis.health.grading import TARGET_SCORE, analysed_share,
from repowise.core.analysis.health.models import primary_finding, split_by_origin
from repowise.core.analysis.health.perf.coverage import PerfCoverage
from repowise.core.analysis.health.ranking import worst_kpis
+from repowise.core.analysis.health.rows import split_tests
from repowise.core.analysis.health.scoring import (
hotspot_health,
nloc_weighted_attr,
+ nloc_weighted_score,
)
from repowise.core.persistence.models import HealthFileMetric
@@ -187,9 +189,17 @@ def _compute_kpis(
total_nloc = sum(max(m.nloc, 1) for m in metrics)
avg = sum(m.score * max(m.nloc, 1) for m in metrics) / total_nloc
share = analysed_share(len(metrics), unanalysed)
+ production, tests = split_tests(metrics)
return {
"file_count": len(metrics),
"average_health": round(avg, 2),
+ # Production code alone, weighted the same way; only said while tests
+ # are in ``average_health``, so ``scope="production"`` omits it.
+ **(
+ {"production_average": round(nloc_weighted_score(production), 2)}
+ if production and tests
+ else {}
+ ),
# ``None`` with no hotspot files, not an empty set averaged to 10.0.
"hotspot_health": hotspot_health(metrics, hotspot_paths or set()),
# Weighted vs plain mean: a gap means a few large files hold it down.
diff --git a/tests/unit/cli/test_health_cmd_controls.py b/tests/unit/cli/test_health_cmd_controls.py
index e42f78f80..2dc3165ea 100644
--- a/tests/unit/cli/test_health_cmd_controls.py
+++ b/tests/unit/cli/test_health_cmd_controls.py
@@ -182,3 +182,17 @@ def test_a_mostly_unanalysed_repo_gets_no_band_in_any_scope() -> None:
assert "Code health: 10.0/10 ·" in out, args
assert "Excellent" not in out, args
assert "analysed 4 of 435 code files" in out, args
+
+
+def test_the_headline_names_production_code_while_tests_are_in_it() -> None:
+ def headline(**kpis) -> str:
+ console = Console(file=io.StringIO(), width=400, force_terminal=False)
+ with patch.object(health_module, "console", console):
+ health_module._render_headline(kpis, False, 0)
+ return console.file.getvalue()
+
+ base = {"average_health": 8.0, "production_average": 6.0, "file_count": 2}
+ assert "Production code: 6.0/10 · Hotspot: ?/10" in headline(**base, production_file_count=1)
+ # Narrowed to production, the two figures are one.
+ narrowed = headline(**base, production_file_count=2)
+ assert "Production code" not in narrowed and "Hotspot: ?/10" in narrowed
diff --git a/tests/unit/server/mcp/test_health.py b/tests/unit/server/mcp/test_health.py
index 7676abd79..aebb47625 100644
--- a/tests/unit/server/mcp/test_health.py
+++ b/tests/unit/server/mcp/test_health.py
@@ -2946,3 +2946,18 @@ async def test_what_if_names_the_points_a_fix_recovers(setup_mcp, session, popul
# on 200 of the headline's 500 nloc; the only hotspot carries all of it.
assert top["gain"] == {"file": 2.5, "average": 1.0, "hotspot": 2.5}
assert row["fix_all_structure"]["file"] == 4.5
+
+
+def test_kpis_name_production_code_beside_the_all_files_average() -> None:
+ """``production_average`` rides beside ``average_health`` while tests are in
+ it, and is left out once the reading holds no tests."""
+ from repowise.core.persistence.models import HealthFileMetric
+ from repowise.server.mcp_server.tool_health.summary import _compute_kpis
+
+ def row(path: str, score: float, *, test: bool) -> HealthFileMetric:
+ return HealthFileMetric(file_path=path, score=score, nloc=100, is_test=test)
+
+ prod, test = row("src/a.py", 6.0, test=False), row("tests/test_a.py", 10.0, test=True)
+ mixed = _compute_kpis([prod, test], deductions={})
+ assert (mixed["average_health"], mixed["production_average"]) == (8.0, 6.0)
+ assert "production_average" not in _compute_kpis([prod], deductions={})