Extract semantic code search post-processing into shared concern
Summary
Extracts the semantic code search post-processing logic from Mcp::Tools::SemanticCodeSearchService into a shared concern Ai::ActiveContext::Concerns::CodePostProcessing, so the same logic can be used by both the MCP tool and the REST API endpoint (added in the follow-up MR).
Extracted into the concern:
-
filter_excluded_results— filters results viaAi::FileExclusionService(Duo context exclusion settings) -
group_results_by_file— groups flat hit results by file path, merging adjacent line ranges -
compute_confidence_level— derives a confidence level from score distribution -
extract_scores— extracts scores from results - Constants:
HIGH_SCORE_THRESHOLD,MEDIUM_SCORE_THRESHOLD,STEEP_DROPOFF_THRESHOLD - Private helpers:
merge_sequential_ranges,build_range,compute_end_line
Also removes the three post-processing feature flags (include_score_in_response, include_confidence_in_response, group_by_file) which have been 100% rolled out.
How to test
- Start GDK and ensure semantic code search is configured and indexed for a project.
- Use the MCP tool via an MCP client (e.g. cursor with the GitLab MCP server configured).
- Call
semantic_code_search— results should include scores, confidence, and be grouped by file (same as before). - Run unit tests:
bundle exec rspec ee/spec/services/mcp/tools/semantic_code_search_service_spec.rb
Related
- Closes #593915
- Follow-up: !227817 (merged) (REST API endpoint)
Edited by Tian Gao