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 via Ai::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

  1. Start GDK and ensure semantic code search is configured and indexed for a project.
  2. Use the MCP tool via an MCP client (e.g. cursor with the GitLab MCP server configured).
  3. Call semantic_code_search — results should include scores, confidence, and be grouped by file (same as before).
  4. Run unit tests: bundle exec rspec ee/spec/services/mcp/tools/semantic_code_search_service_spec.rb
Edited by Tian Gao

Merge request reports

Loading