tabby
tabby copied to clipboard
feat: add WarpGrep (Morph) as optional code search provider
Summary
- Adds WarpGrep as an optional, supplemental code search backend for the answer engine
- Follows the existing Serper integration pattern: env-var gated (
MORPH_API_KEY), factory closure,Optionfield inRetrievalService - WarpGrep is a multi-turn agentic search agent that performs local grep/read/list_directory operations against the repo, returning relevant code spans
- Tantivy code search remains the primary backend; WarpGrep results are merged and deduplicated. Completions are unaffected
How it works
- User sets
MORPH_API_KEY(and optionallyMORPH_API_ENDPOINT,MORPH_MODEL) - On startup,
webserver.rscreates aWarpGrepServicevia factory closure fromserve.rs - In
RetrievalService::collect_relevant_code(), after Tantivy search, WarpGrep runs as a supplemental search - WarpGrep sends the repo file tree + query to the Morph API, receives XML tool calls, executes them locally, and returns code spans
- Results are merged with Tantivy hits, deduplicated by
(filepath, start_line), and sorted by RRF score
Files changed
| File | Change |
|---|---|
crates/tabby/src/services/warpgrep/mod.rs |
New — WarpGrepService, multi-turn search loop, file tree builder |
crates/tabby/src/services/warpgrep/tool_executor.rs |
New — Local tool execution (grep, read, list_dir), XML parsing |
crates/tabby-common/src/api/code.rs |
Added WarpGrepSearch trait |
crates/tabby/src/serve.rs |
Added factory closure to ws.attach() |
ee/tabby-webserver/src/webserver.rs |
MORPH_API_KEY env check, passes to retrieval |
ee/tabby-webserver/src/service/retrieval.rs |
Added warpgrep field, supplemental search in collect_relevant_code() |
ee/.../answer.rs, thread.rs, page.rs |
Updated test call sites with None warpgrep param |
Security
- Path traversal protection via
canonicalize()+ prefix check on all tool executor paths - Fixed-string grep (
-F) to prevent ReDoS from LLM-supplied patterns - UTF-8 safe string truncation (char boundary aware)
- 30s HTTP timeout on Morph API calls
Test plan
- [x]
cargo checkpasses ontabby-common,tabby,tabby-webserver - [x]
cargo fmt --checkclean - [x]
cargo clippyclean (no new warnings) - [x] 7/7 warpgrep unit tests pass (XML parsing, finish output, line ranges, tool responses)
- [x] 4/4 retrieval tests pass (existing tests updated with new param)
- [x] No ast-grep lint violations
Closes #4452