From a244d6f869897c510fc9fbfbddf5197ba9756e47 Mon Sep 17 00:00:00 2001 From: Ahmed Butt Date: Sun, 12 Apr 2026 22:19:26 +0500 Subject: [PATCH] fix: extend search tool to support all major source file types Previously search_keyword_in_directory only searched .py files, making the architect agent blind to any non-Python workspace repo (JS, TS, Go, Java, etc). - Added SUPPORTED_EXTENSIONS covering 20+ common source and config file types - Default behaviour now searches all supported types when no extension is given - Added optional file_extension parameter for callers that want to narrow the search to a specific type (accepts with or without leading dot) Co-Authored-By: Claude Sonnet 4.6 --- agent/tools/search.py | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/agent/tools/search.py b/agent/tools/search.py index 789b852..ff375c1 100644 --- a/agent/tools/search.py +++ b/agent/tools/search.py @@ -85,18 +85,39 @@ def get_full_path(partial_path: str) -> str: return partial_path +SUPPORTED_EXTENSIONS = ( + ".py", ".js", ".jsx", ".ts", ".tsx", + ".java", ".go", ".rb", ".rs", ".cpp", ".c", ".h", + ".cs", ".php", ".swift", ".kt", ".scala", + ".md", ".txt", ".yaml", ".yml", ".json", ".toml", ".cfg", ".ini", +) + @tool(parse_docstring=True) -def search_keyword_in_directory(directory: str, search_term: str, context: int = 2): +def search_keyword_in_directory(directory: str, search_term: str, file_extension: str = "", context: int = 2): """ - A search tool that searchs for a keyword in all Python files contents in the specified directory. this tool is like cmd+f in your IDE. search_term MUST be at least 3 characters long. - + A search tool that searches for a keyword in source files in the specified directory. + This tool is like cmd+f in your IDE. search_term MUST be at least 3 characters long. + Args: directory: Directory path to search (can be partial or full path) - search_term: Term to search for in files contents (case-insensitive) + search_term: Term to search for in file contents (case-insensitive) + file_extension: Limit search to files with this extension e.g. '.py', '.ts', '.js'. + Leave empty to search all supported source file types. context: Number of context lines to include before and after match (default: 2) """ full_directory = get_full_path(directory) - return search_directory(full_directory, search_term, extension=".py", context=context) + if file_extension: + # Normalise: ensure it starts with a dot + ext = file_extension if file_extension.startswith(".") else f".{file_extension}" + return search_directory(full_directory, search_term, extension=ext, context=context) + + # Search across all supported extensions + results = [] + for ext in SUPPORTED_EXTENSIONS: + result = search_directory(full_directory, search_term, extension=ext, context=context) + if result and result != "No matches found.": + results.append(result) + return "\n".join(results) if results else "No matches found." # List of available tools search_tools = [search_keyword_in_directory]