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(search): spend the result window on distinct files for code-location queries (#3011)

Raghav Chamadiya54ffeedbc984
diff --git a/docs/agent/MCP_TOOLS.md b/docs/agent/MCP_TOOLS.md
index 806f096fc..5d6635eca 100644
--- a/docs/agent/MCP_TOOLS.md
+++ b/docs/agent/MCP_TOOLS.md
@@ -200,19 +200,19 @@ get_symbol(symbol_id="repowise#a1b2c3d4e5f6", query="FAILED")
### `search_codebase`
-Hybrid search that routes by the shape of the query: identifiers search the symbol index, paths resolve files, prose runs wiki-semantic search, and mixed queries run both. Use it when you want ranked hits themselves: enumerating matches, resolving an identifier to a `symbol_id`, scoping a later `get_context`. For a question, call `get_answer`; it runs this retrieval internally.
+Hybrid search that routes by the shape of the query: identifiers search the symbol index, paths resolve files, prose runs wiki-semantic search, and mixed queries run both, keeping only pages that name a file. Use it when you want ranked hits themselves: enumerating matches, resolving an identifier to a `symbol_id`, scoping a later `get_context`. For a question, call `get_answer`; it runs this retrieval internally.
| Parameter | Type | Default | Meaning |
|-----------|------|---------|---------|
| `query` | string | required | Identifier, path or natural-language text |
-| `limit` | int | `5` | Max results |
+| `limit` | int | `5` | Max results. Outside `symbol` mode, at most this many distinct files: same-file hits share one row |
| `mode` | string | `"auto"` | `auto`, `concept`, `symbol`, `path` or `hybrid`. An unknown mode runs as `auto` |
| `kind` | string | none | `implementation`, `test`, `config` or `doc` |
| `symbol_kind` | string | none | Filter symbol hits, e.g. `function`, `class`, `method` |
| `page_type` | string | none | One page type, usually `file_page` or `module_page` |
| `repo` | string | default repo | Workspace repo alias, or `"all"` to search every repo |
-**Key return fields:** `results` (symbol hits carry `symbol_id`, `file`, line bounds and `signature`; file hits carry `file`; concept hits carry `relevance_score`, `snippet` and `sources`), `candidates` (up to `limit` distinct openable file paths, best first). If your next move is a Read, read `candidates`: some `results` are pages that are not files.
+**Key return fields:** `results` (symbol hits carry `symbol_id`, `file`, line bounds and `signature`, plus `symbols` (`name:line` of up to five other matches in that file, then `+N more`) when several matched; file hits carry `file`; concept hits carry `relevance_score`, `snippet` and `sources`), `candidates` (up to `limit` distinct openable file paths, best first). If your next move is a Read, read `candidates`: some `results` are pages that are not files.
```
search_codebase(query="GitIndexer index_repo")
diff --git a/docs/reference/MCP_RESPONSE_FIELDS.md b/docs/reference/MCP_RESPONSE_FIELDS.md
index b65f2162a..959af6b91 100644
--- a/docs/reference/MCP_RESPONSE_FIELDS.md
+++ b/docs/reference/MCP_RESPONSE_FIELDS.md
@@ -174,12 +174,15 @@ Opt-in blocks: `full_doc`, `ownership` (primary owner, bus factor, contributor c
| Field | Meaning |
|-------|---------|
| `results` | Ranked hits. Symbol hits: `type: "symbol"`, `symbol_id`, `name`, `kind`, `file`, `start_line`, `end_line`, `signature`, `next: "get_symbol"`. File hits: `type: "file"`, `page_id`, `file`, `title`, `next: "get_context"`. Concept hits: wiki pages with `relevance_score`, `snippet`, `target_path`, `sources` |
+| `symbols` | On a symbol hit outside `symbol` mode: up to five other matching symbols in the same file, as `name:line`, then a `+N more` entry counting the rest. Those matches share the row instead of taking slots of their own |
| `sources` | The retrievers that found a concept hit: `fts`, `vector`, or both. A hit found by `fts` alone has no semantic agreement |
| `candidates` | Up to `limit` distinct openable file paths, best first |
+Outside `mode="symbol"`, `limit` caps distinct files: hits are collapsed to one row per file, best row first, and the freed slots go to the next pages, then the next symbols. This includes concept mode, where a file page and a `symbol_spotlight` page of the same file are one row. `mode="symbol"` keeps one row per symbol, so overloads in one file each list.
+
Symbol hits rank by exact and qualified name match, query-token coverage, then graph centrality; non-test before test unless `kind="test"`. A `symbol_spotlight` page's `target_path` is a page id (`file.py::Symbol`); open its `file`.
-`results` ranks pages, and some pages are not files: a `module_page` is named by a group key that looks like a directory, an `scc_page` by a hash. `candidates` resolves symbol pages to their file, collapses several symbols of one file into one entry, skips pages that name no file, and backfills from below the result window. If the next move is a Read, read `candidates`. Decision records rank below file pages unless the query is why-shaped.
+`results` ranks pages, and some pages are not files: a `module_page` is named by a group key that looks like a directory, an `scc_page` by a hash. `candidates` resolves symbol pages to their file, collapses several symbols of one file into one entry, skips pages that name no file, and backfills from below the result window. If the next move is a Read, read `candidates`. A hybrid query (prose around an identifier) drops pages that name no file (module, onboarding, overview, decision pages) from `results` without refilling their slots, unless `page_type` or `kind="doc"` asks for pages; concept mode keeps them. Decision records rank below file pages unless the query is why-shaped.
---
diff --git a/packages/server/src/repowise/server/mcp_server/tool_search.py b/packages/server/src/repowise/server/mcp_server/tool_search.py
index 03fc15004..60ac9995d 100644
--- a/packages/server/src/repowise/server/mcp_server/tool_search.py
+++ b/packages/server/src/repowise/server/mcp_server/tool_search.py
@@ -154,6 +154,70 @@ def _interleave_hybrid(
return (symbols[: max(1, limit - reserved)] + concepts)[:limit]
+# Code-location windows over-fetch this many times ``limit`` so collapsing
+# same-file hits still leaves ``limit`` distinct files to serve.
+_FILE_WINDOW_OVERFETCH = 2
+# Other symbol names a collapsed row carries in ``symbols``.
+_MERGED_SYMBOL_CAP = 5
+
+
+def _collapse_by_file(hits: list[dict]) -> list[dict]:
+ """One row per (repo, file), best first; rows naming no file pass through.
+
+ The first row of a file wins. A later symbol hit in the same file folds
+ into the winner's ``symbols`` as ``name:line`` (capped) instead of taking a
+ slot of its own, so ``limit`` buys distinct files; past the cap a trailing
+ ``+N more`` entry counts the rest. Precedent:
+ ``symbol_backed_pages`` collapses the same way for the concept tail.
+ """
+ first_of: dict[tuple, dict] = {}
+ extra: dict[int, int] = {}
+ out: list[dict] = []
+ for hit in hits:
+ path = hit_file_path(hit)
+ if path is None:
+ out.append(hit)
+ continue
+ key = (hit.get("repo"), path)
+ first = first_of.get(key)
+ if first is None:
+ first_of[key] = hit
+ out.append(hit)
+ elif hit.get("type") == "symbol" and first.get("type") == "symbol":
+ merged = first.setdefault("symbols", [])
+ if len(merged) < _MERGED_SYMBOL_CAP:
+ merged.append(f"{hit.get('name')}:{hit.get('start_line')}")
+ else:
+ extra[id(first)] = extra.get(id(first), 0) + 1
+ for hit in out:
+ if id(hit) in extra:
+ hit["symbols"].append(f"+{extra[id(hit)]} more")
+ return out
+
+
+def _hybrid_window(
+ query: str,
+ symbols: list[dict],
+ concepts: list[dict],
+ limit: int,
+ exact: bool,
+ names: Container[str] | None = None,
+) -> list[dict]:
+ """The hybrid window, with no page for a file a shown symbol row covers.
+
+ Pages are dropped only for symbols the window actually shows, then the
+ window is rebuilt so the freed slots backfill. Concepts only shrink and the
+ symbol share only grows, so this settles in a few passes.
+ """
+ while True:
+ window = _interleave_hybrid(query, symbols, concepts, limit, exact, names)
+ shown = {item.get("file") for item in window if item.get("type") == "symbol"}
+ kept = [c for c in concepts if c.get("target_path") not in shown]
+ if len(kept) == len(concepts):
+ return window
+ concepts = kept
+
+
def _downweight_decisions(output: list[dict], query: str) -> None:
"""Scale decision_record relevance in place unless the query is why-shaped."""
if _is_why_shaped(query):
@@ -718,7 +782,7 @@ async def _search_single_repo(
output = _dedup_decisions(output)
output = _filter_by_kind(output, kind)
- return output[:limit]
+ return _collapse_by_file(output)[:limit]
async def _federated_search(
@@ -877,6 +941,9 @@ async def _structured_search(
multi = len(contexts) > 1
symbols: list[dict] = []
+ # Symbol rows past each repo's ``limit``: they only backfill slots that
+ # collapsing same-file rows frees, and never steer the exact-match signal.
+ spare: list[dict] = []
files: list[dict] = []
concepts: list[dict] = []
@@ -895,13 +962,17 @@ async def _structured_search(
if _idents:
symbol_query = " ".join(_idents)
+ # Only the hybrid window collapses symbol rows, so only it over-fetches
+ # them; path hits are file pages, already one row per file.
+ fetch = limit * _FILE_WINDOW_OVERFETCH if mode == "hybrid" else limit
for ctx in contexts:
if mode in ("symbol", "hybrid"):
s = await search_symbols_single(
- ctx, symbol_query, limit, symbol_kind=symbol_kind, kind=kind
+ ctx, symbol_query, fetch, symbol_kind=symbol_kind, kind=kind
)
_tag_repo(s, ctx, multi)
- symbols.extend(s)
+ symbols.extend(s[:limit])
+ spare.extend(s[limit:])
if mode == "path":
f = await search_paths_single(ctx, query, limit)
_tag_repo(f, ctx, multi)
@@ -914,6 +985,7 @@ async def _structured_search(
concepts.extend(c)
symbols.sort(key=lambda x: -(x.get("score") or 0.0))
+ spare.sort(key=lambda x: -(x.get("score") or 0.0))
files.sort(key=lambda x: -(x.get("score") or 0.0))
candidates = _identifier_candidates(query, mode, names)
if mode == "symbol":
@@ -930,19 +1002,32 @@ async def _structured_search(
missing = _missing_named_symbols(candidates, symbols, bool(canonical_symbol), concepts)
if missing:
symbols = [s for s in symbols if _has_exact_symbol(candidates, [s])]
+ spare = [s for s in spare if _has_exact_symbol(candidates, [s])]
if mode == "symbol":
results = symbols[:limit]
elif mode == "path":
results = files[:limit]
else: # hybrid: interleave symbol matches and concept pages for new files
- sym_files = {s.get("file") for s in symbols}
- concepts = [c for c in concepts if c.get("target_path") not in sym_files]
# Federation appends per-repo concept lists in repo order — re-rank by
# relevance so a strong page in repo B isn't buried under repo A's weak
# ones. (Single-repo: already sorted upstream; this is a no-op.)
concepts.sort(key=lambda x: -(x.get("relevance_score") or 0.0))
- results = _interleave_hybrid(query, symbols, concepts, limit, exact, names)
+ window = _hybrid_window(query, symbols, concepts, limit, exact, names)
+ # One row per file, so ``limit`` buys distinct files (mode "symbol"
+ # stays row-per-symbol: overloads there are the answer). Collapsing
+ # keeps the window's order and frees the slots same-file rows took;
+ # the next pages, then the next symbols, fill them.
+ served = {id(item) for item in window}
+ rest = [item for item in concepts + symbols + spare if id(item) not in served]
+ results = _collapse_by_file(window + rest)[:limit]
+ # A code-location query wants files to open, so a module, onboarding
+ # or decision page is dropped from the window. Its slot is not
+ # refilled: on the retrieval guard a refill bought +0.01 coverage at
+ # limit 5 for -0.01 precision at limit 10. Kept when the caller asked
+ # for pages by type or kind="doc".
+ if not page_type and kind != "doc":
+ results = [item for item in results if hit_file_path(item)]
repository = None
if not multi:
@@ -976,10 +1061,14 @@ async def _structured_search(
response["exact_match"] = exact and not missing
if missing:
shown = ", ".join(repr(c) for c in missing[:3])
+ # An empty window has no page to qualify, and its grep_hint
+ # already carries the sweep advice.
+ pages = f" Any page here is {NOT_THE_NAMED_SYMBOL}." if results else ""
+ sweep = "" if (grep_hint and not results) else " " + EXHAUSTIVE_SWEEP_HINT
response["note"] = (
f"No indexed symbol is named {shown}, so no symbol is returned "
- f"for it. Any page here is {NOT_THE_NAMED_SYMBOL}. Recheck the "
- "spelling, or search a shorter part of the name. " + EXHAUSTIVE_SWEEP_HINT
+ f"for it.{pages} Recheck the spelling, or search a shorter part "
+ f"of the name.{sweep}"
)
elif not exact:
shown = ", ".join(repr(c) for c in candidates[:3])
@@ -1023,23 +1112,23 @@ async def search_codebase(
For QUESTIONS ("how does X work", "where is Y handled", "why is Z like
this"), call get_answer instead: it runs this same hybrid retrieval
internally and synthesizes a cited answer, so searching first is a wasted
- round-trip. Use this tool when you want the raw ranked hits themselves —
- enumerating matches, resolving an identifier to a symbol_id, or scoping a
- later get_context call.
+ round-trip. Use this tool for the raw ranked hits: enumerating matches,
+ resolving an identifier to a symbol_id, or scoping get_context.
mode="auto" (default) routes the query: identifier-shaped queries search
the indexed symbols (returns symbol_id/file/line bounds — pipe into
get_symbol), path-shaped queries resolve files (pipe into get_context),
- and conceptual queries run wiki-semantic search. Mixed queries run hybrid,
- symbol hits first. Decision records rank below file pages unless the query
- is why-shaped.
+ and conceptual queries run wiki-semantic search. Mixed queries run hybrid:
+ symbol hits first, then file-backed pages only. Decision records rank
+ below file pages unless the query is why-shaped.
- `candidates` lists up to `limit` distinct openable file paths, best first.
- Some results are pages, not files; this is what to Read.
+ `candidates` lists up to `limit` distinct openable file paths, best
+ first: what to Read.
Args:
- query: identifier, path, or natural-language query.
- limit: max results (default 5).
+ query: identifier, path, or natural language.
+ limit: max results (default 5); distinct files outside
+ mode="symbol" (same-file symbols in `symbols`).
page_type: restrict to one page type. Common: file_page (per-file
docs, always present) or module_page (subsystem/concept pages).
Any stored type filters (repo_overview, layer_page, scc_page,
@@ -1132,6 +1221,8 @@ async def search_codebase(
output = _dedup_decisions(output)
output = _filter_by_kind(output, kind)
+ # A file page and a symbol page of one file are one place to look.
+ output = _collapse_by_file(output)
# Files the page retrievers structurally cannot see (a private helper, a
# local name, anything a file page's public-symbol table omits) get the
# weakest tail slots. No-op when the symbol leg names nothing new.
diff --git a/tests/unit/server/mcp/test_search.py b/tests/unit/server/mcp/test_search.py
index 71909eab8..2c1c1b642 100644
--- a/tests/unit/server/mcp/test_search.py
+++ b/tests/unit/server/mcp/test_search.py
@@ -1563,3 +1563,254 @@ async def test_an_exact_test_class_outranks_an_exact_code_function(
"tests/test_widget.py::Widgets",
"src/widget/core.py::Widgets",
]
+
+
+def _add_symbols(session, rid, rows):
+ """Seed ``(path, name, qualified_name, line)`` WikiSymbol rows."""
+ from repowise.core.persistence.models import WikiSymbol
+
+ for path, name, qualified, line in rows:
+ session.add(
+ WikiSymbol(
+ id=f"dw-{path}-{qualified}", repository_id=rid, file_path=path,
+ symbol_id=f"{path}::{qualified}", name=name, qualified_name=qualified,
+ kind="function", signature=name, start_line=line, end_line=line + 5,
+ language="python",
+ )
+ )
+
+
+_WIDGET_ROWS = [
+ ("src/widget/core.py", "widget", "widget", 10),
+ ("src/widget/core.py", "widget", "Box.widget", 40),
+ ("src/widget/listing.py", "widget_list", "widget_list", 1),
+ ("src/widget/drop.py", "widget_drop", "widget_drop", 1),
+ ("src/widget/sync.py", "widget_sync", "widget_sync", 1),
+]
+
+
+class TestDistinctFileWindow:
+ """Code-location windows spend ``limit`` on distinct files."""
+
+ def test_collapse_folds_same_file_symbols_and_keeps_repos_apart(self):
+ from repowise.server.mcp_server.tool_search import _collapse_by_file
+
+ hits = [
+ {"type": "symbol", "name": "a", "file": "x.py", "start_line": 1},
+ {"type": "symbol", "name": "b", "file": "x.py", "start_line": 9},
+ {"type": "symbol", "name": "c", "file": "x.py", "start_line": 5, "repo": "other"},
+ {"page_type": "module_page", "target_path": "pkg"},
+ {"page_type": "file_page", "target_path": "y.py"},
+ {"page_type": "symbol_spotlight", "target_path": "y.py"},
+ ]
+ out = _collapse_by_file(hits)
+ assert [h.get("name") or h["target_path"] for h in out] == ["a", "c", "pkg", "y.py"]
+ assert out[0]["symbols"] == ["b:9"]
+ assert "symbols" not in out[1]
+
+ def test_a_dominant_file_counts_what_its_cap_left_out(self):
+ from repowise.server.mcp_server.tool_search import _collapse_by_file
+
+ hits = [
+ {"type": "symbol", "name": f"s{i}", "file": "x.py", "start_line": i}
+ for i in range(10)
+ ]
+ (row,) = _collapse_by_file(hits)
+ assert row["symbols"] == ["s1:1", "s2:2", "s3:3", "s4:4", "s5:5", "+4 more"]
+
+ def test_pages_are_dropped_only_for_symbols_the_window_shows(self):
+ from repowise.server.mcp_server.tool_search import _hybrid_window
+
+ def sym(f):
+ return {"type": "symbol", "name": "x", "file": f}
+
+ def page(f):
+ return {"type": "page", "target_path": f, "relevance_score": 0.5}
+
+ # Four symbol files, but limit 4 with three pages shows only two
+ # symbols, so the page for d.py is the only way d.py is served.
+ symbols = [sym("a.py"), sym("b.py"), sym("c.py"), sym("d.py")]
+ out = _hybrid_window(
+ "compare Foo Bar", symbols, [page("d.py"), page("e.py"), page("f.py")], 4, True
+ )
+ assert [r.get("file") or r["target_path"] for r in out] == ["a.py", "b.py", "d.py", "e.py"]
+ # A page whose file a shown symbol covers gives its slot back.
+ out = _hybrid_window(
+ "compare Foo Bar", symbols, [page("b.py"), page("e.py"), page("f.py")], 4, True
+ )
+ assert [r.get("file") or r["target_path"] for r in out] == ["a.py", "b.py", "e.py", "f.py"]
+
+ @pytest.mark.asyncio
+ async def test_the_federated_page_leg_serves_one_row_per_file(self, setup_mcp):
+ import repowise.server.mcp_server as mcp_mod
+ from repowise.server.mcp_server._helpers import _resolve_repo_context
+ from repowise.server.mcp_server.tool_search import _search_single_repo
+
+ await _seed_page("file_page:api/client.go", "api/client.go")
+ await _seed_page(
+ "symbol_spotlight:api/client.go::HTTP", "api/client.go::HTTP", "symbol_spotlight"
+ )
+ await _seed_page("file_page:api/server.go", "api/server.go")
+
+ async def fake_search(query, limit=10):
+ return [
+ _mk_result("file_page:api/client.go", "c", "file_page", "api/client.go", 0.9),
+ _mk_result(
+ "symbol_spotlight:api/client.go::HTTP",
+ "HTTP",
+ "symbol_spotlight",
+ "api/client.go::HTTP",
+ 0.8,
+ ),
+ _mk_result("file_page:api/server.go", "s", "file_page", "api/server.go", 0.7),
+ ]
+
+ mcp_mod._vector_store.search = fake_search
+ out = await _search_single_repo(await _resolve_repo_context(None), "requests", 2, None)
+ assert [r["target_path"] for r in out] == ["api/client.go", "api/server.go"]
+
+ @pytest.mark.asyncio
+ async def test_hybrid_limit_buys_distinct_files(self, session, populated_db, setup_mcp):
+ from repowise.server.mcp_server import search_codebase
+
+ _add_symbols(session, populated_db, _WIDGET_ROWS)
+ await session.commit()
+
+ res = await search_codebase("widget", mode="hybrid", limit=3)
+ files = [r["file"] for r in res["results"]]
+ assert len(files) == 3 and len(set(files)) == 3
+ # The exact name still leads, carrying its same-file sibling.
+ lead = res["results"][0]
+ assert lead["symbol_id"] == "src/widget/core.py::Box.widget"
+ assert lead["symbols"] == ["widget:10"]
+
+ @pytest.mark.asyncio
+ async def test_symbol_mode_still_lists_each_overload(self, session, populated_db, setup_mcp):
+ from repowise.server.mcp_server import search_codebase
+
+ _add_symbols(session, populated_db, _WIDGET_ROWS)
+ await session.commit()
+
+ res = await search_codebase("widget", mode="symbol", limit=3)
+ ids = [r["symbol_id"] for r in res["results"]]
+ assert ids[:2] == ["src/widget/core.py::Box.widget", "src/widget/core.py::widget"]
+ assert all("symbols" not in r for r in res["results"])
+
+ @pytest.mark.asyncio
+ async def test_concept_window_serves_one_row_per_file(self, setup_mcp):
+ import repowise.server.mcp_server as mcp_mod
+ from repowise.server.mcp_server import search_codebase
+
+ await _seed_page("file_page:api/client.go", "api/client.go")
+ await _seed_page(
+ "symbol_spotlight:api/client.go::HTTP", "api/client.go::HTTP", "symbol_spotlight"
+ )
+ await _seed_page("file_page:api/server.go", "api/server.go")
+
+ async def fake_search(query, limit=10):
+ return [
+ _mk_result("file_page:api/client.go", "client.go", "file_page", "api/client.go", 0.9),
+ _mk_result(
+ "symbol_spotlight:api/client.go::HTTP",
+ "HTTP",
+ "symbol_spotlight",
+ "api/client.go::HTTP",
+ 0.8,
+ ),
+ _mk_result("file_page:api/server.go", "server.go", "file_page", "api/server.go", 0.7),
+ ]
+
+ mcp_mod._vector_store.search = fake_search
+ res = await search_codebase("how are requests issued", mode="concept", limit=2)
+ assert [r["target_path"] for r in res["results"]] == ["api/client.go", "api/server.go"]
+
+
+class TestPathlessPagesInCodeLocationModes:
+ """Hybrid windows drop pages naming no file; concept windows keep them."""
+
+ async def _seed(self):
+ import repowise.server.mcp_server as mcp_mod
+
+ await _seed_page("module_page:pkg/cmd/release", "pkg/cmd/release", "module_page")
+ await _seed_page(
+ "onboarding:onboarding/how_it_works", "onboarding/how_it_works", "onboarding"
+ )
+ await _seed_page("file_page:pkg/cmd/release/list.go", "pkg/cmd/release/list.go")
+
+ async def fake_search(query, limit=10):
+ return [
+ _mk_result(
+ "module_page:pkg/cmd/release", "Release", "module_page", "pkg/cmd/release", 0.9
+ ),
+ _mk_result(
+ "onboarding:onboarding/how_it_works",
+ "Guided Tour",
+ "onboarding",
+ "onboarding/how_it_works",
+ 0.8,
+ ),
+ _mk_result(
+ "file_page:pkg/cmd/release/list.go",
+ "list.go",
+ "file_page",
+ "pkg/cmd/release/list.go",
+ 0.7,
+ ),
+ ]
+
+ mcp_mod._vector_store.search = fake_search
+
+ @pytest.mark.asyncio
+ async def test_hybrid_drops_module_and_onboarding_pages(self, setup_mcp):
+ from repowise.server.mcp_server import search_codebase
+
+ await self._seed()
+ res = await search_codebase("listing releases in order", mode="hybrid", limit=5)
+ pages = [r["page_type"] for r in res["results"] if r["type"] == "page"]
+ assert pages == ["file_page"]
+
+ @pytest.mark.asyncio
+ async def test_concept_keeps_them(self, setup_mcp):
+ from repowise.server.mcp_server import search_codebase
+
+ await self._seed()
+ res = await search_codebase("listing releases in order", mode="concept", limit=5)
+ assert [r["page_type"] for r in res["results"]] == [
+ "module_page",
+ "onboarding",
+ "file_page",
+ ]
+
+ @pytest.mark.asyncio
+ async def test_an_empty_window_does_not_repeat_its_grep_hint(self, setup_mcp):
+ import repowise.server.mcp_server as mcp_mod
+ from repowise.server.mcp_server import search_codebase
+ from repowise.server.mcp_server._meta import EXHAUSTIVE_SWEEP_HINT
+
+ await _seed_page("module_page:pkg/cmd/release", "pkg/cmd/release", "module_page")
+
+ async def fake_search(query, limit=10):
+ return [
+ _mk_result(
+ "module_page:pkg/cmd/release", "Release", "module_page", "pkg/cmd/release", 0.9
+ )
+ ]
+
+ mcp_mod._vector_store.search = fake_search
+ res = await search_codebase("where is validate_trigger_nonce defined", mode="hybrid")
+ assert res["results"] == []
+ assert "No indexed symbol is named" in res["note"]
+ assert "Any page here" not in res["note"]
+ assert EXHAUSTIVE_SWEEP_HINT not in res["note"]
+ assert EXHAUSTIVE_SWEEP_HINT in res["grep_hint"]
+
+ @pytest.mark.asyncio
+ async def test_hybrid_keeps_them_when_pages_are_asked_for(self, setup_mcp):
+ from repowise.server.mcp_server import search_codebase
+
+ await self._seed()
+ res = await search_codebase(
+ "listing releases in order", mode="hybrid", page_type="module_page"
+ )
+ pages = [r["page_type"] for r in res["results"] if r["type"] == "page"]
+ assert pages == ["module_page"]