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

@ -45,3 +45,9 @@ pub(crate) mod m_2025_04_15 {
pub(crate) use keymap::KEYMAP_PATTERNS;
pub(crate) use settings::SETTINGS_PATTERNS;
}
pub(crate) mod m_2025_04_21 {
mod settings;
pub(crate) use settings::SETTINGS_PATTERNS;
}

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()))
}

View file

@ -128,6 +128,10 @@ pub fn migrate_settings(text: &str) -> Result<Option<String>> {
migrations::m_2025_04_15::SETTINGS_PATTERNS,
&SETTINGS_QUERY_2025_04_15,
),
(
migrations::m_2025_04_21::SETTINGS_PATTERNS,
&SETTINGS_QUERY_2025_04_21,
),
];
run_migrations(text, migrations)
}
@ -206,6 +210,10 @@ define_query!(
SETTINGS_QUERY_2025_04_15,
migrations::m_2025_04_15::SETTINGS_PATTERNS
);
define_query!(
SETTINGS_QUERY_2025_04_21,
migrations::m_2025_04_21::SETTINGS_PATTERNS
);
// custom query
static EDIT_PREDICTION_SETTINGS_MIGRATION_QUERY: LazyLock<Query> = LazyLock::new(|| {