feat(tool): search_code — dedup + rank find_code matches (Issue #10)#20
Merged
Conversation
… symbol Issue #10 part 1: wraps find_code matches into their containing functions, dedupes by NodeID, ranks by structural importance (definitions first, popular next, tests last). Mirrors codebase-memory-mcp's search_code. Embeddings (semantic_query) deferred per the YAGNI note in the issue. Reuses findCodeRegex / findCodeTreeSitter with withContext=true; adds a group + rank layer on top. Stamps Provenance.Tool like every other answer.
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.
Summary
Implements issue #10, part 1: a new `search_code` MCP tool that wraps `find_code` matches into their containing functions, dedupes by NodeID, and ranks by structural importance.
Semantic search (part 2) deferred per the YAGNI note in the issue — embeddings cost disk, RAM, and a build dep; ship dedup+rank first, add when a real consumer asks.
What it does
Same args as `find_code` (pattern, pattern_kind, scope, file_filter, limit). Output is an array of `groups`:
```
{
groups: [
{
nodeId, kind, summary, file, enclosingRange,
matchCount, matches: [{line, snippet}],
bucket: "definition" | "popular" | "test"
}
],
provenance: { tool: "yactt", version, fetchedAt }
}
```
Ranking: bucket tier → matchCount desc → fanIn desc → nodeId asc, stable.
Files
Reuse
Heavy lifting already lives in `internal/tool/findcode.go`:
`search_code` calls these with `withContext=true` and adds only the group + rank layer on top. No re-parsing, no duplicated logic.
Verification
Closes #10 (part 1).
🤖 Generated with Claude Code