Skip to content

Conversation

@roomote
Copy link
Contributor

@roomote roomote bot commented Jul 19, 2025

This PR addresses issue #4731 by adding case sensitivity detection and debug logging to the search and replace algorithm.

Changes

  • Enhanced error messages: When a search fails, the algorithm now detects if there are potential case mismatches in the file and includes this information in the error message
  • Debug logging: Added console logging when case sensitivity issues are detected, helping AI assistants understand why modifications might be failing
  • Improved diagnostics: The error messages now include a count of potential case mismatches found in the file

Implementation Details

  1. Multi-search-replace.ts:

    • Added case mismatch detection when no match is found
    • Logs case differences when search and replace content differ only by case
    • Shows "Potential case mismatch" indicator with count in error messages
  2. Multi-file-search-replace.ts:

    • Similar implementation for multi-file operations
    • Consistent logging format for debugging
  3. Tests:

    • Added comprehensive test coverage for case sensitivity detection
    • Tests verify both error messages and console logging behavior

Example Output

When a case mismatch is detected, the error message will include:

No sufficiently similar match found (75% similar, needs 100%)

Debug Info:
- Similarity Score: 75%
- Required Threshold: 100%
- Search Range: start to end
- Tried both standard and aggressive line number stripping
- 🔍 **Potential case mismatch**: Found 2 location(s) where content differs only by case

And the console will log:

[apply_diff] Case sensitivity issue detected: 2 potential matches with different casing

This helps AI assistants understand that the issue might be related to case sensitivity rather than the content being completely different.

Fixes #4731


Important

Adds case sensitivity detection and logging to search and replace algorithm, enhancing error messages and diagnostics.

  • Behavior:
    • Adds case sensitivity detection and logging to multi-search-replace.ts and multi-file-search-replace.ts.
    • Enhances error messages with potential case mismatch information and count.
    • Logs case sensitivity issues to console.
  • Tests:
    • Adds tests in multi-search-replace.spec.ts for case sensitivity detection and logging.
    • Verifies error messages and console logging behavior.

This description was created by Ellipsis for 4e31af0. You can customize this summary. It will automatically update as commits are pushed.

- Add detection for case mismatches when search fails
- Log case sensitivity issues to console for AI debugging
- Show potential case mismatch count in error messages
- Add comprehensive tests for case sensitivity detection

Fixes #4731
@roomote roomote bot requested review from cte, jr and mrubens as code owners July 19, 2025 15:20
@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. enhancement New feature or request labels Jul 19, 2025
let replaceLines = replaceContent === "" ? [] : replaceContent.split(/\r?\n/)

// Check for case sensitivity issues after identical content check
if (searchContent !== replaceContent && searchContent.toLowerCase() === replaceContent.toLowerCase()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

The block that detects case differences (using toLowerCase and comparing word-by-word) is duplicated across strategies. Consider extracting this logic to a shared utility function to reduce duplication and ease future maintenance.

This comment was generated because it violated a code review rule: irule_tTqpIuNs8DV0QFGj.

@hannesrudolph hannesrudolph added the Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. label Jul 19, 2025
@daniel-lxs daniel-lxs moved this from Triage to PR [Needs Prelim Review] in Roo Code Roadmap Jul 21, 2025
@hannesrudolph hannesrudolph added PR - Needs Preliminary Review and removed Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. labels Jul 21, 2025
@daniel-lxs
Copy link
Member

These changes seem too complex, I think we should try simply adding a new suggestion to the suggested fixes list:

Suggested fixes:

  1. Verify the search content exactly matches the file content (including whitespace)
  2. Check for correct indentation and line endings
  3. Use <read_file> to see the current file content
  4. Consider breaking complex changes into smaller diffs
  5. Ensure start_line parameter matches the actual content location

To check the case of the Search block.

@daniel-lxs daniel-lxs closed this Jul 22, 2025
@github-project-automation github-project-automation bot moved this from New to Done in Roo Code Roadmap Jul 22, 2025
@github-project-automation github-project-automation bot moved this from PR [Needs Prelim Review] to Done in Roo Code Roadmap Jul 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request PR - Needs Preliminary Review size:L This PR changes 100-499 lines, ignoring generated files.

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

The search algorithm should inform the AI via debug logs if a case sensitivity issue occurs and the modification fails.

4 participants