Skip to content

Release Notes v0.4.1

Compare
Choose a tag to compare
@johnhuang316 johnhuang316 released this 14 Jul 03:16
· 8 commits to master since this release

Major Features

Regex Support in Search

Fixes #11: OR search (regex pipe operator) not working in search_code_advanced

Added comprehensive regex support to the search_code_advanced tool with the new regex parameter:

# OR searches now work!
search_code_advanced("ERROR|WARN", regex=True)      # Returns OR matches

# Other regex patterns
search_code_advanced("function|class", regex=True)  # OR search
search_code_advanced("^import", regex=True)         # Start of line
search_code_advanced("Error$", regex=True)          # End of line
search_code_advanced("[A-Z]+", regex=True)          # Character classes

Key Benefits:

  • OR searches: Use | to search for multiple patterns simultaneously
  • Pattern matching: Full regex support with anchors, character classes, etc.
  • Safety: Built-in ReDoS attack protection
  • Backward compatible: Default behavior unchanged (literal search)

Bug Fixes

Fixed ag (Silver Searcher) File Pattern Handling

Resolved issue where glob patterns like *.py were incorrectly passed to ag's -G parameter, causing incorrect file matching behavior.

Improvements:

  • *.py now correctly converts to \.py$ for ag's regex engine
  • test_*.js now correctly converts to ^test_.*\.js$
  • src/*.css now correctly converts to ^src/.*\.css$
  • All search tools (ugrep, ripgrep, ag, grep) now handle file patterns consistently

Technical Changes

New Features

  • regex parameter: Explicit control over regex vs literal search modes
  • Pattern safety validation: is_safe_regex_pattern() function with ReDoS protection
  • Automatic glob-to-regex conversion: Smart pattern conversion for ag search strategy
  • Enhanced file pattern support: Consistent behavior across all search backends

Security Enhancements

  • Protection against ReDoS (Regular Expression Denial of Service) attacks
  • Validates regex patterns before execution
  • Rejects potentially dangerous patterns like (.+)+, (.*)*
  • Only allows safe regex metacharacters: |, (, ), [, ], ^, $

Code Improvements

  • Renamed create_safe_fuzzy_pattern() to create_word_boundary_pattern() for clarity
  • Improved parameter documentation across all search strategies
  • Enhanced error handling and validation

Usage Examples

Basic Regex Search

# Default behavior (literal search) - unchanged
search_code_advanced("ERROR|WARN")  # Searches for literal "ERROR|WARN"

# New regex support
search_code_advanced("ERROR|WARN", regex=True)  # OR search

File Pattern Examples

# All these now work consistently across all search tools
search_code_advanced("def main", file_pattern="*.py")       # Python files
search_code_advanced("function", file_pattern="test_*.js")  # Test JS files
search_code_advanced("import", file_pattern="src/*.ts")     # TypeScript in src/

Advanced Regex Patterns

search_code_advanced("class [A-Z][a-zA-Z0-9]*", regex=True)  # Class names
search_code_advanced("(TODO|FIXME|HACK)", regex=True)        # Code comments
search_code_advanced("^\\s*def\\s+", regex=True)            # Function definitions

Security Notes

  • All regex patterns are validated for safety before execution
  • Dangerous patterns that could cause ReDoS attacks are automatically rejected
  • Pattern validation ensures server stability and performance
  • Safe regex features are clearly documented

Backward Compatibility

This release maintains 100% backward compatibility:

  • Default search behavior remains unchanged (literal string search)
  • Existing code will continue to work without any modifications
  • New regex parameter is optional with False as default
  • File pattern handling improved transparently without API changes

Migration Guide

To use regex features:

# Old way (still works)
search_code_advanced("simple text")

# New regex capabilities
search_code_advanced("pattern1|pattern2", regex=True)  # OR search
search_code_advanced("^start", regex=True)             # Line start
search_code_advanced("end$", regex=True)               # Line end

No migration needed for file patterns:

File pattern handling is automatically improved - existing code works better without changes.

Testing

This release has been thoroughly tested with:

  • Basic search functionality validation
  • OR pattern matching verification across all search backends
  • File pattern conversion for ag, ripgrep, ugrep, and grep
  • Safety checks for dangerous regex patterns
  • Backward compatibility confirmation with existing codebases
  • Performance testing with various pattern complexities

Related Issues

Version Updates

  • Bumped version to 0.4.1 reflecting the major regex feature addition
  • Updated version strings in pyproject.toml and src/code_index_mcp/__init__.py

Full Changelog: v0.3.1...v0.4.1