fix(mcp): search_code converts multi-word patterns to regex#304
Open
jjoos wants to merge 1 commit intoDeusData:mainfrom
Open
fix(mcp): search_code converts multi-word patterns to regex#304jjoos wants to merge 1 commit intoDeusData:mainfrom
jjoos wants to merge 1 commit intoDeusData:mainfrom
Conversation
When pattern contains spaces and is not already a regex, convert to a regex with '.*' between words: "foo bar baz" → "foo.*bar.*baz". This matches all terms in order on a line instead of requiring the exact multi-word substring. Metacharacters in user input are escaped so the conversion is safe for arbitrary text. Includes test: search_code_multi_word verifies that a two-word query matches a line containing both words non-contiguously.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
search_codereturns 0 results when the pattern contains spaces (e.g."slack webhook handler"). Single-word queries like"webhook"or"handler"work fine.Root cause
handle_search_codewrites the pattern to a temp file and passes it togrep -F -f(fixed-string mode). A multi-word pattern like"slack webhook handler"is treated as a literal substring — grep looks for that exact 22-character sequence on one line. This almost never matches real code.Fix
Before invoking grep, if the pattern contains whitespace and
use_regexis false:.*→slack.*webhook.*handlergrep -E)This matches lines containing all words in order. Single-word patterns are unaffected (no spaces → no conversion).
Changes
src/mcp/mcp.c: 36 lines added in a new "Phase 0.5" block before grep invocation.tests/test_mcp.c: Newsearch_code_multi_wordtest verifying a two-word query finds a matching line.Testing
search_code_multi_word— searches for"HandleRequest error"in a fixture file containingfunc HandleRequest() error {. Verifies non-zero results.