Skip to content

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Jun 6, 2025

Implements a new search_regex tool that provides focused regex pattern searching in user-specified files, addressing the need for more targeted searches compared to the existing broad search_text functionality.

Key Features

  • Targeted searches: Requires explicit file specification (no default to searching all files)
  • Regex pattern matching: Full regex support with proper error handling for invalid patterns
  • Context lines: Optional context lines around matches for better understanding
  • Output control: Configurable character limits with truncation handling
  • Structured response: Consistent metadata format following existing tool conventions

Implementation Details

New Tool: search_regex

# Search for function definitions in specific files
result = await client.call_tool("search_regex", {
    "pattern": "def\\s+\\w+\\(",
    "files": ["main.py", "utils.py"]
})

# Search with context lines for better understanding
result = await client.call_tool("search_regex", {
    "pattern": "class\\s+\\w+",
    "files": ["src/models.py"],
    "context": 3,
    "max_chars": 1000
})

Key Differences from search_text

Feature search_text search_regex
File specification Optional (defaults to all files) Required (explicit list)
Use case Broad repository searches Targeted file searches
Performance Searches entire repo when no files specified Efficient - only searches specified files
Error handling Allows empty file searches Explicit error for empty file list

Error Handling

The tool provides comprehensive error handling for:

  • Invalid regex patterns with detailed error messages
  • Non-existent or inaccessible files
  • Files outside the authorized root directory
  • Empty file lists (explicit requirement)

Testing

  • 12 comprehensive test cases covering all functionality and edge cases
  • Manual testing verified for real-world usage scenarios
  • All existing tests pass - no breaking changes to existing functionality
  • Linting passes with project code style requirements

Documentation

Updated README.md with:

  • Tool description in the available tools section
  • Usage examples showing common patterns
  • Integration with existing exploration tools

This addresses the performance and usability concerns when users know exactly which files they want to search, providing a more efficient alternative to broad repository searches.

Fixes #29.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

- Update README.md with search_regex tool documentation and examples
- Tool is fully functional and tested with all edge cases covered
- Maintains compatibility with existing tools and follows conventions

Co-authored-by: eh-main-bot <[email protected]>
@Copilot Copilot AI changed the title [WIP] Add tool for searching a regex pattern in a single file or across a specified list of files (with structured/truncated output) Add targeted regex search tool for specific files Jun 6, 2025
@Copilot Copilot AI requested a review from eh-main-bot June 6, 2025 11:46
Copilot finished work on behalf of eh-main-bot June 6, 2025 11:46
Copy link

codecov bot commented Jun 6, 2025

Codecov Report

Attention: Patch coverage is 93.65079% with 4 lines in your changes missing coverage. Please review.

Project coverage is 93.12%. Comparing base (aa27f53) to head (1c6a77d).

Files with missing lines Patch % Lines
dev_kit_mcp_server/tools/explore/search_regex.py 93.44% 4 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #30      +/-   ##
==========================================
+ Coverage   93.09%   93.12%   +0.03%     
==========================================
  Files          33       34       +1     
  Lines         811      873      +62     
==========================================
+ Hits          755      813      +58     
- Misses         56       60       +4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Collaborator

@eh-main-bot eh-main-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot can we simplify this? make shorter and simpler?

Args:
pattern: Regex pattern to match against file content
files: List of file paths to search (required)
context: Number of context lines to include before/after matches (optional)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
context: Number of context lines to include before/after matches (optional)

no need for context param

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed the context parameter and simplified the implementation as requested. The tool now provides a cleaner, more focused regex search without context lines. All tests updated and passing. Changes in commit 1c6a77d.

Copy link
Contributor Author

Copilot AI commented Jun 6, 2025

@copilot can we simplify this? make shorter and simpler?

Simplified the search_regex implementation by removing the context parameter and related complexity. The tool now provides a cleaner, more focused regex search with simpler output format. Changes in commit 1c6a77d.

Copilot finished work on behalf of eh-main-bot June 6, 2025 12:25
@eh-main-bot eh-main-bot marked this pull request as ready for review June 6, 2025 15:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add tool for searching a regex pattern in a single file or across a specified list of files (with structured/truncated output)

2 participants