Codebase intelligence for AI and humans: code health scores, auto-generated docs, git analytics, dead code detection, and architectural decisions via MCP.
Python aicode-complexitycode-healthcode-intelligencecode-qualitydead-codedeveloper-toolsdocumentationgit-analyticsmcpopen-sourcepythonrefactoringstatic-analysistechnical-debt
feat(code-health): mark short-history files on the health file list (#4351)
MD JUBER QURAISHIbb60b4769414
diff --git a/packages/server/src/repowise/server/routers/code_health/files_routes.py b/packages/server/src/repowise/server/routers/code_health/files_routes.pyindex f089ba895..96a772669 100644--- a/packages/server/src/repowise/server/routers/code_health/files_routes.py+++ b/packages/server/src/repowise/server/routers/code_health/files_routes.py@@ -120,6 +120,8 @@ async def list_health_files(queued = {r.file_path: r.queued for r in await crud.performance_file_rollups(session, repo_id)}lang_by_path = await crud.get_file_language_map(session, repo_id)perf_langs = supported_perf_languages()+ # Read once per request, like the MCP rows; only the full row carries it.+ short_history = set() if summary else await crud.get_short_history_paths(session, repo_id)return {"total": total,"offset": offset,@@ -132,6 +134,7 @@ async def list_health_files(perf_opportunities=queued.get(m.file_path, 0),perf_analyzed=lang_by_path.get(m.file_path) in perf_langs,summary=summary,+ history_basis="short" if m.file_path in short_history else None,),m,)diff --git a/packages/server/src/repowise/server/routers/code_health/serializers.py b/packages/server/src/repowise/server/routers/code_health/serializers.pyindex 81a9edeaf..f88fa3084 100644--- a/packages/server/src/repowise/server/routers/code_health/serializers.py+++ b/packages/server/src/repowise/server/routers/code_health/serializers.py@@ -64,6 +64,7 @@ def _metric_to_dict(perf_opportunities: int = 0,perf_analyzed: bool | None = None,summary: bool = False,+ history_basis: str | None = None,) -> dict:"""One file row. ``summary=True`` omits the keys only the table and drawer read.@@ -121,6 +122,11 @@ def _metric_to_dict(out["primary_biomarker"] = lead.get("primary_biomarker") if lead else Noneout["primary_reason"] = lead.get("primary_reason") if lead else Noneout["total_deduction"] = lead.get("total_deduction") if lead else None+ # ``"short"``: too few recorded commits for most history markers to+ # fire, so a high score here is an absent history, not a clean one.+ # Omitted otherwise, like the MCP rows and the drawer's signals.+ if history_basis:+ out["history"] = history_basisreturn outdiff --git a/packages/types/src/health.ts b/packages/types/src/health.tsindex 61b4a3f18..0fb6e5e97 100644--- a/packages/types/src/health.ts+++ b/packages/types/src/health.ts@@ -285,6 +285,12 @@ export interface HealthFileMetric {structure_deduction?: number | null;history_deduction?: number | null;unclamped_score?: number | null;+ /**+ * `"short"`: too few recorded commits for most history markers to fire, so a+ * high score is an absent history rather than a clean one. Omitted otherwise+ * and on `fields=summary` rows.+ */+ history?: "short" | null;/*** Test material, decided at ingestion. Drives the production/all scope* without re-deriving the answer from the path on every surface.diff --git a/tests/unit/server/test_health_files_summary.py b/tests/unit/server/test_health_files_summary.pyindex 685940c26..5668dd1e3 100644--- a/tests/unit/server/test_health_files_summary.py+++ b/tests/unit/server/test_health_files_summary.py@@ -21,7 +21,7 @@ from repowise.core.analysis.health.models import HealthFindingData, Severityfrom repowise.core.analysis.health.perf.opportunities import link_performance_findingsfrom repowise.core.persistence import crudfrom repowise.core.persistence.database import get_session-from repowise.core.persistence.models import PerformanceOpportunity+from repowise.core.persistence.models import GitMetadata, PerformanceOpportunityfrom tests.unit.server.conftest import create_test_repo_FULL_ONLY = {@@ -204,3 +204,31 @@ async def test_an_unknown_fields_value_is_rejected(client: AsyncClient) -> None:f"/api/repos/{repo['id']}/health/files", params={"fields": "lean"})assert resp.status_code == 422+++async def test_list_row_marks_a_file_whose_history_is_too_short(client: AsyncClient, app) -> None:+ """A new file's high score is an absent history, not a clean one."""+ repo = await create_test_repo(client)+ await _seed(app, repo["id"])+ async with get_session(app.state.session_factory) as session:+ for i, commits in enumerate([2, 50]):+ session.add(+ GitMetadata(+ id=f"gm{i}",+ repository_id=repo["id"],+ file_path=f"src/f{i:02d}.py",+ commit_count_total=commits,+ )+ )++ full = (await client.get(f"/api/repos/{repo['id']}/health/files")).json()+ by_path = {f["file_path"]: f for f in full["files"]}+ assert by_path["src/f00.py"]["history"] == "short"+ assert "history" not in by_path["src/f01.py"]+ assert "history" not in by_path["src/f02.py"]++ lean = (+ await client.get(f"/api/repos/{repo['id']}/health/files", params={"fields": "summary"})+ ).json()+ assert all("history" not in f for f in lean["files"])