From 3217576743bac0ebde0574170f110672de647819 Mon Sep 17 00:00:00 2001 From: Taylor Mullen Date: Mon, 12 May 2025 23:23:24 -0700 Subject: 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 --- packages/server/src/config/config.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'packages/server/src/config/config.ts') diff --git a/packages/server/src/config/config.ts b/packages/server/src/config/config.ts index daff1807..b5f7df3d 100644 --- a/packages/server/src/config/config.ts +++ b/packages/server/src/config/config.ts @@ -148,7 +148,7 @@ function createToolRegistry(config: Config): ToolRegistry { new ReadFileTool(targetDir), new GrepTool(targetDir), new GlobTool(targetDir), - new EditTool(targetDir), + new EditTool(config), new WriteFileTool(targetDir), new WebFetchTool(), // Note: WebFetchTool takes no arguments new ReadManyFilesTool(targetDir), -- cgit v1.2.3