Skip to content

Conversation

@code-crusher
Copy link
Member

  • update fileedit with substring replacer for inline edit file tool calls
  • update changelog

@matter-code-review
Copy link
Contributor

matter-code-review bot commented Dec 29, 2025

Context

Summary By MatterAI MatterAI logo

🔄 What Changed

Optimized the mapNormalizedIndexToOriginal function in fileEditTool.ts to support offset-based resumption. This allows the tool to calculate the end position of a match by starting from the previously found start position, rather than re-scanning the entire file from the beginning. This PR also incorporates previous release refinements for CRLF handling and search feedback.

🔍 Impact of the Change

Significantly improves performance for large file edits, especially those with many CRLF sequences. By reducing the complexity of index mapping from O(N) to O(M) for subsequent lookups, the tool becomes more efficient during automated code modifications and prevents "off-by-one" errors on Windows systems.

📁 Total Files Changed

Click to Expand
File ChangeLog
Index Optimization src/core/tools/fileEditTool.ts Refactored mapNormalizedIndexToOriginal to accept start offsets and updated callers to resume scanning.
Version Bump src/package.json Updated version to 4.206.0.
Search Feedback src/services/ripgrep/index.ts Improved JSDoc and added helpful messaging for zero-result searches.

🧪 Test Added/Recommended

Recommended

  • Performance benchmarks for large files (>1MB) with mixed line endings to quantify the gain.
  • Unit tests verifying the accuracy of originalEnd when using non-zero start offsets.

🔒 Security Vulnerabilities

N/A

Implementation

The mapNormalizedIndexToOriginal function was updated to accept startOriginalIndex and startNormalizedPos as optional parameters. The flexibleSubstringReplacer logic now passes the originalStart and normalizedIndex into the second call to mapNormalizedIndexToOriginal, ensuring the loop resumes from the correct position. This avoids redundant iterations over the file content.

Screenshots

before after
N/A N/A

How to Test

  1. Run fileEditTool on a file with CRLF line endings.
  2. Verify that the substring replacement correctly identifies the original content range.
  3. Check for performance improvements on files larger than 1MB.
  4. Run a ripgrep search that returns zero results to verify the new hint message.

Get in Touch

N/A

Copy link
Contributor

@matter-code-review matter-code-review bot left a comment

Choose a reason for hiding this comment

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

🧪 PR Review is completed: The new replacers significantly improve robustness for source code editing. I've identified two issues: sourceCodeEscapeReplacer only handles double quotes (ignoring single quotes/backticks), and flexibleSubstringReplacer has duplicated logic that should be refactored.

Skipped files
  • CHANGELOG.md: Skipped file pattern

@code-crusher
Copy link
Member Author

/matterai fix

@matter-code-review
Copy link
Contributor

✅ I've created a fix PR to address the review comments!

🔗 matterai-fix: Address review comments for PR #21

Files Changed:

  • src/core/tools/fileEditTool.ts

Please review the changes and merge them if they look correct.

Copy link
Contributor

@matter-code-review matter-code-review bot left a comment

Choose a reason for hiding this comment

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

🧪 PR Review is completed: The changes correctly implement dynamic quote escaping and extract the index mapping logic. However, quoteChar appears to be undefined in sourceCodeEscapeReplacer, and the index mapping function can be optimized to avoid redundant scanning.

@matter-code-review
Copy link
Contributor

✅ Reviewed the changes: The changes correctly implement the performance optimizations for mapNormalizedIndexToOriginal by allowing resumed scanning. The logic appears sound and handles the CRLF mapping correctly.

@code-crusher code-crusher merged commit 5a6eaf2 into main Dec 29, 2025
6 of 13 checks passed
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.

2 participants