agent: Migrate tool names in settings (#29168)

Release Notes:

- agent: Add migration to rename `find_replace_file` tool to
`edit_file`, and `regex_search` to `grep`.
This commit is contained in:
Agus Zubiaga 2025-04-21 14:03:42 -03:00 committed by GitHub
parent 942d4eb126
commit be76942a69
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 39 additions and 268 deletions

View file

@ -0,0 +1,25 @@
use std::ops::Range;
use tree_sitter::{Query, QueryMatch};
use crate::MigrationPatterns;
use crate::patterns::SETTINGS_ASSISTANT_TOOLS_PATTERN;
pub const SETTINGS_PATTERNS: MigrationPatterns =
&[(SETTINGS_ASSISTANT_TOOLS_PATTERN, rename_tools)];
fn rename_tools(contents: &str, mat: &QueryMatch, query: &Query) -> Option<(Range<usize>, String)> {
let tool_name_capture_ix = query.capture_index_for_name("tool_name")?;
let tool_name_range = mat
.nodes_for_capture_index(tool_name_capture_ix)
.next()?
.byte_range();
let tool_name = contents.get(tool_name_range.clone())?;
let new_name = match tool_name {
"find_replace_file" => "edit_file",
"regex_search" => "grep",
_ => return None,
};
Some((tool_name_range, new_name.to_string()))
}