gemini-cli/packages/server/src/utils
Taylor Mullen 3217576743 feat: Enhance `replace` tool reliability with multi-stage edit correction
This commit significantly improves the `replace` tool's robustness by introducing a multi-stage correction mechanism. This directly addresses challenges with LLM-generated tool inputs, particularly the over-escaping of strings sometimes observed with Gemini models, and other minor discrepancies that previously led to failed edits.

The correction process is as follows:
1.  **Targeted Unescaping:** The system first applies a specialized unescaping function to the `old_string` and `new_string` to counteract common LLM-induced escaping patterns.
2.  **LLM-Powered Discrepancy Resolution:** If a unique match for the `old_string` is still not found, the system leverages a Gemini model (`gemini-2.5-flash-preview-04-17`) to:
    *   Identify the most probable intended `old_string` in the file by intelligently correcting minor formatting or escaping differences.
    *   Adjust the `new_string` to correspond with any corrections made to the `old_string`, maintaining the original edit's intent.

This enhancement makes the `replace` tool more resilient and effective, leading to a higher success rate for automated code modifications. The `expected_replacements` parameter has been removed as the tool now focuses on finding a single, unique, and correctable match. The tool's description and error reporting have been updated to reflect these new capabilities.

Fixes https://b.corp.google.com/issues/416933027
2025-05-12 23:33:12 -07:00
..
editCorrector.test.ts feat: Enhance `replace` tool reliability with multi-stage edit correction 2025-05-12 23:33:12 -07:00
editCorrector.ts feat: Enhance `replace` tool reliability with multi-stage edit correction 2025-05-12 23:33:12 -07:00
errorReporting.test.ts Log server information on error. 2025-05-10 14:18:23 -07:00
errorReporting.ts Log server information on error. 2025-05-10 14:18:23 -07:00
errors.ts Cleanup low value comments. (#248) 2025-05-02 14:39:39 -07:00
generateContentResponseUtilities.ts Prevent console.warn's for tool calls. 2025-04-26 15:50:44 -07:00
getFolderStructure.ts Cleanup low value comments. (#248) 2025-05-02 14:39:39 -07:00
nextSpeakerChecker.test.ts Don't prematurely end convo w/ Gemini. 2025-05-10 14:05:58 -07:00
nextSpeakerChecker.ts Workaround model bug where it returns invalid history items. 2025-05-11 13:01:54 -07:00
paths.ts Cleanup low value comments. (#248) 2025-05-02 14:39:39 -07:00
schemaValidator.ts Cleanup low value comments. (#248) 2025-05-02 14:39:39 -07:00