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(mcp): stop get_why shedding the lanes that answer the question (#1954)

Raghav Chamadiyaeb0f88691afe
diff --git a/packages/server/src/repowise/server/mcp_server/_budget/contracts.py b/packages/server/src/repowise/server/mcp_server/_budget/contracts.py
index ab82505f0..58d8b3a78 100644
--- a/packages/server/src/repowise/server/mcp_server/_budget/contracts.py
+++ b/packages/server/src/repowise/server/mcp_server/_budget/contracts.py
@@ -85,17 +85,30 @@ _CONTRACTS: dict[str, ResponseBudgetContract] = {
expansion_argument="include",
protected=("answer", "confidence", "citations", "next_action_hint"),
),
+ # Dropping docs and episodes whole, and first, served 0 of 50 pages and 0 of
+ # 12 episodes on a file whose decision lane was 40 near-duplicates. They are
+ # ranked tails now, so a squeeze costs rows rather than the lane, and the
+ # decision lane pays before the lanes that answer.
+ #
+ # Search mode has no top-level origin_story or git_archaeology (its origin
+ # lives under the protected target_context), so for that shape the fix is
+ # the tail entries alone; the block entries only bite in path mode.
"get_why": ResponseBudgetContract(
"blocks",
(
- "related_documentation",
- "episodes",
+ # Titles the decisions lane already carries.
"origin_story.linked_decisions",
"decisions[]",
"code_rationale",
"git_archaeology.file_commits",
"git_archaeology.cross_references",
"git_archaeology.git_log",
+ # Ranked tails, moved here from the front of this tuple. Episodes
+ # last: they answer "what constrains changing this" when no decision
+ # governs the file.
+ "related_documentation[]",
+ "episodes[]",
+ "related_documentation",
"origin_story",
),
expansion_argument=None,
diff --git a/packages/server/src/repowise/server/mcp_server/_helpers.py b/packages/server/src/repowise/server/mcp_server/_helpers.py
index f421178a6..0d8bea5d6 100644
--- a/packages/server/src/repowise/server/mcp_server/_helpers.py
+++ b/packages/server/src/repowise/server/mcp_server/_helpers.py
@@ -294,6 +294,9 @@ _ORIGIN_STOP_WORDS = frozenset(
{"the", "a", "an", "is", "for", "to", "of", "in", "and", "or", "with"}
)
+#: Decisions the origin summary names, and the ceiling on its evidence clauses.
+_ORIGIN_NARRATED_DECISIONS = 3
+
def _meaningful_words(text: str) -> set[str]:
"""Lowercase keyword set with common stop-words removed."""
@@ -381,9 +384,11 @@ def _origin_summary_parts(
)
if linked_decisions:
- decision_titles = [d["title"] for d in linked_decisions[:3]]
- parts.append(f"Governed by: {', '.join(decision_titles)}.")
- for ld in linked_decisions:
+ named = linked_decisions[:_ORIGIN_NARRATED_DECISIONS]
+ parts.append(f"Governed by: {', '.join(d['title'] for d in named)}.")
+ # Unbounded, a file with 40 linked decisions got 16 evidence clauses,
+ # restating titles the caller's own cap had already removed.
+ for ld in named:
if ld["evidence_commits"]:
ec = ld["evidence_commits"][0]
parts.append(