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(decisions): stop harvest emitting title-only records (#605)
Raghav Chamadiya1f5e3e945ed5
diff --git a/packages/core/src/repowise/core/generation/page_generator/decision_harvest.py b/packages/core/src/repowise/core/generation/page_generator/decision_harvest.pyindex 30c96badf..1b4fd8282 100644--- a/packages/core/src/repowise/core/generation/page_generator/decision_harvest.py+++ b/packages/core/src/repowise/core/generation/page_generator/decision_harvest.py@@ -170,4 +170,15 @@ def harvest_decisions(rejected=rejected,)+ # Title fallback: the gate clears any paraphrased ``decision`` that is not a+ # verbatim substring of the source, but a survivor's ``source_quote`` keeps+ # the record alive — leaving a body-less, title-only decision. The title is+ # the model's own canonical one-line summary of the choice and is always+ # present (``parse_and_strip_decisions`` requires it), so promote it into the+ # empty ``decision`` field. Deterministic, no new LLM call, and the gate's+ # rejection behavior is untouched.+ for d in kept:+ if not d.decision and d.title:+ d.decision = d.title+return clean, [dataclasses.asdict(d) for d in kept]diff --git a/packages/server/src/repowise/server/mcp_server/_helpers.py b/packages/server/src/repowise/server/mcp_server/_helpers.pyindex d21586740..0033f5553 100644--- a/packages/server/src/repowise/server/mcp_server/_helpers.py+++ b/packages/server/src/repowise/server/mcp_server/_helpers.py@@ -221,6 +221,23 @@ def _meaningful_words(text: str) -> set[str]:return set(text.lower().split()) - _ORIGIN_STOP_WORDS+def _decision_body(record: object) -> str:+ """Effective one-line body for a decision record.++ The anti-hallucination gate clears a paraphrased ``decision`` that is not a+ verbatim substring of the source while a survivor's evidence quote keeps the+ record alive, which historically left ``llm_inferred`` records with an empty+ ``decision`` and only a title to show. The harvest path now promotes the+ title into ``decision`` at write time; this fall back covers records stored+ before that fix so read surfaces never emit a body-less decision. The title+ is the model's own canonical one-line summary of the choice and is always+ present.+ """+ return (getattr(record, "decision", "") or "").strip() or (+ getattr(record, "title", "") or ""+ ).strip()++def _commits_matching_decision(decision: dict, commits: list[dict]) -> list[dict]:"""Return commits whose messages share at least one keyword with *decision*."""decision_text = (diff --git a/packages/server/src/repowise/server/mcp_server/tool_context/targets.py b/packages/server/src/repowise/server/mcp_server/tool_context/targets.pyindex 129cd215e..01ec8af8c 100644--- a/packages/server/src/repowise/server/mcp_server/tool_context/targets.py+++ b/packages/server/src/repowise/server/mcp_server/tool_context/targets.py@@ -28,6 +28,7 @@ from repowise.core.persistence.models import (WikiSymbol,)from repowise.server.mcp_server._helpers import (+ _decision_body,filter_dicts_by_key,filter_path_list,is_excluded,@@ -703,7 +704,7 @@ async def _resolve_one_target("id": d.id,"title": d.title,"status": d.status,- "decision": d.decision,+ "decision": _decision_body(d),"rationale": d.rationale,"confidence": d.confidence,}diff --git a/packages/server/src/repowise/server/mcp_server/tool_why.py b/packages/server/src/repowise/server/mcp_server/tool_why.pyindex 6b4b74d01..3096f10bd 100644--- a/packages/server/src/repowise/server/mcp_server/tool_why.py+++ b/packages/server/src/repowise/server/mcp_server/tool_why.py@@ -20,6 +20,7 @@ from repowise.core.registry import mcp_tool_registry as mcpfrom repowise.server.mcp_server._helpers import (_build_origin_story,_compute_alignment,+ _decision_body,_get_exclude_spec,_get_repo,_is_path,@@ -91,7 +92,7 @@ async def _why_workspace_search(query: str) -> dict:"id": d.id,"title": d.title,"status": d.status,- "decision": d.decision,+ "decision": _decision_body(d),"rationale": d.rationale,"source": d.source,"confidence": d.confidence,@@ -161,7 +162,7 @@ def _governing_decision_entry(d: Any, affected_files: list, lineage: list[dict])"title": d.title,"status": d.status,"context": d.context,- "decision": d.decision,+ "decision": _decision_body(d),"rationale": d.rationale,"alternatives": json.loads(d.alternatives_json),"consequences": json.loads(d.consequences_json),@@ -347,7 +348,7 @@ def _merge_decisions("id": d.id,"title": d.title,"status": d.status,- "decision": d.decision,+ "decision": _decision_body(d),"rationale": d.rationale,"context": d.context,"consequences": json.loads(d.consequences_json),diff --git a/packages/server/src/repowise/server/schemas/decisions.py b/packages/server/src/repowise/server/schemas/decisions.pyindex bc6941fce..76b363d17 100644--- a/packages/server/src/repowise/server/schemas/decisions.py+++ b/packages/server/src/repowise/server/schemas/decisions.py@@ -57,7 +57,13 @@ class DecisionRecordResponse(BaseModel):title=obj.title, # type: ignore[attr-defined]status=obj.status, # type: ignore[attr-defined]context=obj.context, # type: ignore[attr-defined]- decision=obj.decision, # type: ignore[attr-defined]+ # Body fallback: the substring gate can clear a paraphrased+ # ``decision`` while an evidence quote keeps the record alive,+ # historically leaving a title-only record. Fall back to the title+ # (the model's canonical one-line summary, always present) so no read+ # surface emits a body-less decision. New records get this at write+ # time in the harvest path; this covers pre-fix stored records.+ decision=(obj.decision or "").strip() or obj.title, # type: ignore[attr-defined]rationale=obj.rationale, # type: ignore[attr-defined]alternatives=json.loads(obj.alternatives_json), # type: ignore[attr-defined]consequences=json.loads(obj.consequences_json), # type: ignore[attr-defined]diff --git a/tests/unit/generation/test_decision_harvest.py b/tests/unit/generation/test_decision_harvest.pyindex 353218c0a..de3d0a944 100644--- a/tests/unit/generation/test_decision_harvest.py+++ b/tests/unit/generation/test_decision_harvest.py@@ -128,6 +128,28 @@ def test_partial_hallucination_drops_only_ungrounded_fields():assert d["rationale"] == "", "the ungrounded rationale must be dropped"+def test_title_promoted_to_decision_when_gate_clears_paraphrase():+ # The decision/rationale are real but paraphrased, so the substring gate+ # clears them; the verbatim source_quote keeps the record alive. Without the+ # title fallback this leaves a body-less, title-only record. The title (the+ # model's canonical one-line summary) must be promoted into ``decision``.+ content = _fenced(+ '{"decisions": [{"title": "Use Redis for caching", '+ '"decision": "Persistence layer selected by the platform team", '+ '"rationale": "latency targets demanded an alternative approach", '+ '"source_quote": "We use Redis as the cache backend"}]}'+ )+ _clean, decisions = harvest_decisions(content, source_text=_SOURCE, evidence_file="cache.py")+ assert len(decisions) == 1+ d = decisions[0]+ # Paraphrased prose was cleared by the gate...+ assert d["rationale"] == ""+ # ...but the record is not body-less: the title filled the empty decision.+ assert d["decision"] == "Use Redis for caching"+ # The grounding quote that kept the record alive is still recorded.+ assert d["source_quote"] == "We use Redis as the cache backend"++def test_no_fence_yields_no_decisions():clean, decisions = harvest_decisions("# Overview\n\nPlain page.\n", source_text=_SOURCE, evidence_file="cache.py"