fix: resolve EditTool naming inconsistency causing agent confusion loops (#513)

* fix: resolve EditTool naming inconsistency causing agent confusion loops

* docs: restore original format for edit tool

* fix: apply prettier formatting to docs and tests

* test: update snapshots for edit tool
This commit is contained in:
Zagorulko Oleg
2025-09-09 06:33:07 +03:00
committed by GitHub
parent dded10f98c
commit 60c136ad67
10 changed files with 44 additions and 48 deletions

View File

@@ -136,11 +136,11 @@ Search for a pattern with file filtering and custom result limiting:
search_file_content(pattern="function", include="*.js", maxResults=10)
```
## 6. `replace` (Edit)
## 6. `edit` (Edit)
`replace` replaces text within a file. By default, replaces a single occurrence, but can replace multiple occurrences when `expected_replacements` is specified. This tool is designed for precise, targeted changes and requires significant context around the `old_string` to ensure it modifies the correct location.
`edit` replaces text within a file. By default, replaces a single occurrence, but can replace multiple occurrences when `expected_replacements` is specified. This tool is designed for precise, targeted changes and requires significant context around the `old_string` to ensure it modifies the correct location.
- **Tool name:** `replace`
- **Tool name:** `edit`
- **Display name:** Edit
- **File:** `edit.ts`
- **Parameters:**
@@ -158,7 +158,7 @@ search_file_content(pattern="function", include="*.js", maxResults=10)
- If one occurrence is found, it replaces it with `new_string`.
- **Enhanced Reliability (Multi-Stage Edit Correction):** To significantly improve the success rate of edits, especially when the model-provided `old_string` might not be perfectly precise, the tool incorporates a multi-stage edit correction mechanism.
- If the initial `old_string` isn't found or matches multiple locations, the tool can leverage the Gemini model to iteratively refine `old_string` (and potentially `new_string`).
- This self-correction process attempts to identify the unique segment the model intended to modify, making the `replace` operation more robust even with slightly imperfect initial context.
- This self-correction process attempts to identify the unique segment the model intended to modify, making the `edit` operation more robust even with slightly imperfect initial context.
- **Failure conditions:** Despite the correction mechanism, the tool will fail if:
- `file_path` is not absolute or is outside the root directory.
- `old_string` is not empty, but the `file_path` does not exist.