feat: add glab search semantic command
Summary
- Adds
glab search semanticcommand to query the GitLab semantic code search REST endpoint (GET /projects/278964/search/semantic— added in gitlab!227817 (merged)) - Supports natural language queries with optional directory path filtering, result count limiting, and JSON output
- Project resolves from git remote by default; override with
-R/--repo
Closes https://gitlab.com/gitlab-org/cli/-/work_items/8227
MR chain
| Repo | MR | Status | Description |
|---|---|---|---|
| gitlab-org/gitlab | gitlab!227816 (merged) | Extract post-processing concern | |
| gitlab-org/gitlab | gitlab!227817 (merged) | Add REST endpoint | |
| gitlab-org/gitlab | gitlab!229665 (merged) | Add gPAT support (read_code permission) | |
| gitlab-org/gitlab | gitlab!228569 (merged) | FF mcp_semantic_code_search_use_rest_api | |
| gitlab-org/gitlab | gitlab!227818 | Sunset SemanticCodeSearchService | |
| gitlab-org/cli | !3084 | Add glab search semantic CLI command | |
| gitlab-org/editor-extensions/gitlab-lsp | gitlab-org/editor-extensions/gitlab-lsp!3157 | Add gitlab_semantic_code_search to tool catalog | |
| ai-assist | gitlab-org/modelops/applied-ml/code-suggestions/ai-assist!5174 | Add SemanticCodeSearch tool implementation |
Epic: https://gitlab.com/groups/gitlab-org/-/epics/21285
Flags
| Flag | Short | Default | Description |
|---|---|---|---|
--query |
-q |
required | Natural language search query |
--directory-path |
-d |
— | Restrict search to files under this path |
--knn |
— | server default (64) | Nearest neighbours to retrieve |
--limit |
-l |
server default (20) | Maximum results |
--output |
-F |
text |
Output format: text or json |
How to test
Unit tests:
go test ./internal/commands/search/...Local GDK verification:
# Unprovisioned project → 422 (not 500)
curl -sk -o /dev/null -w "%{http_code}\n" --header "PRIVATE-TOKEN: $TOKEN" \
"https://gdk.test:3443/api/v4/projects/7/search/semantic?q=auth"
# Happy path → 200 with results
glab search semantic -q "authentication" -R "gitlab-duo/test"Edited by Tian Gao