Update grep to return snippets based on the passed keywords
What does this MR do and why?
This MR enhances the grep command to return contextual code snippets instead of just matching lines. The changes improve the usefulness of grep results for AI agents by providing surrounding context around matches.
Key improvements:
- Snippet extraction: Returns code snippets with configurable context (7 lines before/after by default) around each match
-
Multi-term search: Supports comma-separated search patterns (e.g.,
test,todo) with OR logic - Smart ranking: Returns top 10 files by match count, with up to 5 snippets per file
- Deduplication: Merges overlapping snippets to avoid redundant context
-
Enhanced output format: Includes file paths with line number ranges (e.g.,
file.go?start_line=5&end_line=19) - Non-recursive directory search: Searches only in the specified directory, not subdirectories
This makes grep results more actionable for AI agents that need to understand code context rather than just finding keyword matches.
Related issues
Please, refer to https://gitlab.com/gitlab-org/modelops/applied-ml/code-suggestions/ai-assist/-/merge_requests/3856 to explore the langSmith results.
Relates to gitlab-org/modelops/applied-ml/code-suggestions/ai-assist#1644 (closed).
How to set up and validate locally
- Make sure your AIGW is at the commit - gitlab-org/modelops/applied-ml/code-suggestions/ai-assist!3856 (merged).
- Rely on the CEF SWEbench instructions or use the VSCode ext with the golang executor to test the changes
Edited by Alexander Chueshev