assistant2: Fail find-replace tool if both strings are equal (#27783)

Models seem to do this ever so often and get very confused. Failing here
helps them recover.

Release Notes:

- N/A

Co-authored-by: Richard Feldman <richard@zed.dev>
This commit is contained in:
Agus Zubiaga 2025-03-31 11:23:46 -03:00 committed by GitHub
parent 12c58d01bb
commit e6c64ebf7e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 6 additions and 0 deletions

View file

@ -182,6 +182,10 @@ impl Tool for FindReplaceFileTool {
return Err(anyhow!("`find` string cannot be empty. Use a different tool if you want to create a file."));
}
if input.find == input.replace {
return Err(anyhow!("The `find` and `replace` strings are identical, so no changes would be made."));
}
let result = cx
.background_spawn(async move {
replace_exact(&input.find, &input.replace, &snapshot).await