refactor: update search tool parameters and documentation for clarity

- Changed the target parameter from "content" and "files" to "grep" and "find" to better represent their functionality.
- Revised descriptions in the tool definitions and execution code schema to enhance understanding of search modes and output formats.
- Ensured consistency in the handling of search operations across the codebase.
This commit is contained in:
teknium1
2026-02-20 02:46:30 -08:00
parent f9eb5edb96
commit c0d412a736
2 changed files with 16 additions and 12 deletions

View File

@@ -898,13 +898,13 @@ def get_file_tool_definitions() -> List[Dict[str, Any]]:
"properties": {
"pattern": {
"type": "string",
"description": "For target='content': regex pattern to search for. For target='files': glob pattern (e.g., '*.py', '*config*')"
"description": "Regex pattern for grep mode, or glob pattern (e.g., '*.py', '*config*') for find mode"
},
"target": {
"type": "string",
"enum": ["content", "files"],
"description": "Search mode: 'content' searches inside files (like grep/rg), 'files' searches for files by name (like find/glob)",
"default": "content"
"enum": ["grep", "find"],
"description": "'grep' searches inside file contents, 'find' searches for files by name",
"default": "grep"
},
"path": {
"type": "string",
@@ -913,7 +913,7 @@ def get_file_tool_definitions() -> List[Dict[str, Any]]:
},
"file_glob": {
"type": "string",
"description": "Filter files by pattern when target='content' (e.g., '*.py' to only search Python files)"
"description": "Filter files by pattern in grep mode (e.g., '*.py' to only search Python files)"
},
"limit": {
"type": "integer",
@@ -928,12 +928,12 @@ def get_file_tool_definitions() -> List[Dict[str, Any]]:
"output_mode": {
"type": "string",
"enum": ["content", "files_only", "count"],
"description": "Output format for content search: 'content' shows matching lines with line numbers, 'files_only' lists file paths, 'count' shows match counts per file",
"description": "Output format for grep mode: 'content' shows matching lines with line numbers, 'files_only' lists file paths, 'count' shows match counts per file",
"default": "content"
},
"context": {
"type": "integer",
"description": "Number of lines to show before and after each match (only for target='content', output_mode='content')",
"description": "Number of context lines before and after each match (grep mode only)",
"default": 0
}
},
@@ -2016,9 +2016,13 @@ def handle_file_function_call(
)
elif function_name == "search_files":
# Map user-facing target values to internal ones
target_map = {"grep": "content", "find": "files"}
raw_target = function_args.get("target", "grep")
target = target_map.get(raw_target, raw_target)
return search_tool(
pattern=function_args.get("pattern", ""),
target=function_args.get("target", "content"),
target=target,
path=function_args.get("path", "."),
file_glob=function_args.get("file_glob"),
limit=function_args.get("limit", 50),

View File

@@ -90,8 +90,8 @@ _TOOL_STUBS = {
),
"search_files": (
"search_files",
'pattern: str, target: str = "content", path: str = ".", file_glob: str = None, limit: int = 50',
'"""Search file contents (target="content") or find files (target="files"). Returns dict with "matches"."""',
'pattern: str, target: str = "grep", path: str = ".", file_glob: str = None, limit: int = 50',
'"""Search file contents (target="grep") or find files by name (target="find"). Returns dict with "matches"."""',
'{"pattern": pattern, "target": target, "path": path, "file_glob": file_glob, "limit": limit}',
),
"patch": (
@@ -553,8 +553,8 @@ EXECUTE_CODE_SCHEMA = {
" Lines are 1-indexed. Returns {\"content\": \"...\", \"total_lines\": N}\n"
" write_file(path: str, content: str) -> dict\n"
" Always overwrites the entire file.\n"
" search_files(pattern: str, target=\"content\", path=\".\", file_glob=None, limit=50) -> dict\n"
" target: \"content\" (grep) or \"files\" (find). Returns {\"matches\": [...]}\n"
" search_files(pattern: str, target=\"grep\", path=\".\", file_glob=None, limit=50) -> dict\n"
" target: \"grep\" (search inside files) or \"find\" (find files by name). Returns {\"matches\": [...]}\n"
" patch(path: str, old_string: str, new_string: str, replace_all: bool = False) -> dict\n"
" Replaces old_string with new_string in the file.\n"
" terminal(command: str, timeout=None, workdir=None) -> dict\n"