fix(search): wire SearchResult imports/exports and stabilize map hub selection#100
Merged
PatrickSys merged 2 commits intomasterfrom Apr 14, 2026
Merged
Conversation
Contributor
Greptile SummaryThis PR fixes two correctness gaps: Confidence Score: 5/5
|
| Filename | Overview |
|---|---|
| src/types/index.ts | Adds optional imports and exports to SearchResult, aligning it with the already-typed fields in CodeChunk. |
| src/core/search.ts | Wires chunk.imports and chunk.exports through both the main and fallback (test-chunk) search-result construction paths. |
| src/tools/search-codebase.ts | Removes the as unknown as { imports?: string[] } unsafe cast now that the fields are typed on SearchResult. |
| src/core/codebase-map.ts | Replaces manual iteration loop in enrichLayers with sortByCountThenAlpha, making hub-file selection deterministic on tied importer counts. |
| tests/codebase-map.test.ts | Adds a regression test for alphabetical tie-breaking using a temp-dir fixture with two equal-importer-count files. |
| tests/search-compact-mode.test.ts | Adds a regression test verifying full-mode serialization includes chunk-level imports (truncated to 5) and exports; also reformats two long assertion lines. |
Sequence Diagram
sequenceDiagram
participant C as search_codebase (tool)
participant S as CodebaseSearcher
participant SR as SearchResult
C->>S: search(query, limit, filters)
S->>SR: build result from CodeChunk
note over SR: imports: chunk.imports ✅<br/>exports: chunk.exports ✅
S-->>C: SearchResult[]
C->>C: "r.imports?.slice(0,5)<br/>r.exports?.slice(0,5)"
note over C: typed access, no cast ✅
C-->>C: serialize full-mode payload
Reviews (1): Last reviewed commit: "fix(search): wire SearchResult imports/e..." | Re-trigger Greptile
08c1cb2 to
5ba2b90
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What / Why
This fixes 2 small but real gaps in the search and map surfaces.
Full-mode
search_codebasewas trying to serialize chunk-levelimportsandexports, butSearchResultnever carried those fields through from the indexed chunk metadata. As a result, those keys were silently absent even when the data existed. This PR wires the typed fields through the search pipeline and removes the unsafe cast in the serializer.It also makes
enrichLayers()deterministic when multiple files in the same layer have the same importer count. Ties now follow the existing count-desc-then-alpha ordering instead of depending on iteration order.Changes
importsandexportstoSearchResultVerification
pnpm format:checkpnpm lintpnpm run type-checkpnpm buildpnpm test -- tests/search-compact-mode.test.tspnpm test -- tests/codebase-map.test.tspnpm testpnpm audit --prodRelease notes
This should appear in release notes as a search/map correctness fix.
.planning/**and Phase 16 release metadata are intentionally excluded from this PR