agent: Use current shell (#28470)
Release Notes: - agent: Replace `bash` tool with `terminal` tool which uses the current shell --------- Co-authored-by: Bennet <bennet@zed.dev> Co-authored-by: Antonio <antonio@zed.dev>
This commit is contained in:
parent
8ac378b86e
commit
90bcde116f
15 changed files with 334 additions and 74 deletions
|
@ -37,3 +37,9 @@ pub(crate) mod m_2025_03_29 {
|
|||
|
||||
pub(crate) use settings::SETTINGS_PATTERNS;
|
||||
}
|
||||
|
||||
pub(crate) mod m_2025_04_15 {
|
||||
mod settings;
|
||||
|
||||
pub(crate) use settings::SETTINGS_PATTERNS;
|
||||
}
|
||||
|
|
29
crates/migrator/src/migrations/m_2025_04_15/settings.rs
Normal file
29
crates/migrator/src/migrations/m_2025_04_15/settings.rs
Normal file
|
@ -0,0 +1,29 @@
|
|||
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,
|
||||
replace_bash_with_terminal_in_profiles,
|
||||
)];
|
||||
|
||||
fn replace_bash_with_terminal_in_profiles(
|
||||
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())?;
|
||||
|
||||
if tool_name != "bash" {
|
||||
return None;
|
||||
}
|
||||
|
||||
Some((tool_name_range, "terminal".to_string()))
|
||||
}
|
|
@ -120,6 +120,10 @@ pub fn migrate_settings(text: &str) -> Result<Option<String>> {
|
|||
migrations::m_2025_03_29::SETTINGS_PATTERNS,
|
||||
&SETTINGS_QUERY_2025_03_29,
|
||||
),
|
||||
(
|
||||
migrations::m_2025_04_15::SETTINGS_PATTERNS,
|
||||
&SETTINGS_QUERY_2025_04_15,
|
||||
),
|
||||
];
|
||||
run_migrations(text, migrations)
|
||||
}
|
||||
|
@ -190,6 +194,10 @@ define_query!(
|
|||
SETTINGS_QUERY_2025_03_29,
|
||||
migrations::m_2025_03_29::SETTINGS_PATTERNS
|
||||
);
|
||||
define_query!(
|
||||
SETTINGS_QUERY_2025_04_15,
|
||||
migrations::m_2025_04_15::SETTINGS_PATTERNS
|
||||
);
|
||||
|
||||
// custom query
|
||||
static EDIT_PREDICTION_SETTINGS_MIGRATION_QUERY: LazyLock<Query> = LazyLock::new(|| {
|
||||
|
@ -527,4 +535,103 @@ mod tests {
|
|||
),
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_replace_bash_with_terminal_in_profiles() {
|
||||
assert_migrate_settings(
|
||||
r#"
|
||||
{
|
||||
"assistant": {
|
||||
"profiles": {
|
||||
"custom": {
|
||||
"name": "Custom",
|
||||
"tools": {
|
||||
"bash": true,
|
||||
"diagnostics": true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
"#,
|
||||
Some(
|
||||
r#"
|
||||
{
|
||||
"assistant": {
|
||||
"profiles": {
|
||||
"custom": {
|
||||
"name": "Custom",
|
||||
"tools": {
|
||||
"terminal": true,
|
||||
"diagnostics": true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
"#,
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_replace_bash_false_with_terminal_in_profiles() {
|
||||
assert_migrate_settings(
|
||||
r#"
|
||||
{
|
||||
"assistant": {
|
||||
"profiles": {
|
||||
"custom": {
|
||||
"name": "Custom",
|
||||
"tools": {
|
||||
"bash": false,
|
||||
"diagnostics": true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
"#,
|
||||
Some(
|
||||
r#"
|
||||
{
|
||||
"assistant": {
|
||||
"profiles": {
|
||||
"custom": {
|
||||
"name": "Custom",
|
||||
"tools": {
|
||||
"terminal": false,
|
||||
"diagnostics": true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
"#,
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_no_bash_in_profiles() {
|
||||
assert_migrate_settings(
|
||||
r#"
|
||||
{
|
||||
"assistant": {
|
||||
"profiles": {
|
||||
"custom": {
|
||||
"name": "Custom",
|
||||
"tools": {
|
||||
"diagnostics": true,
|
||||
"path_search": true,
|
||||
"read_file": true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
"#,
|
||||
None,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,5 +7,6 @@ pub(crate) use keymap::{
|
|||
};
|
||||
|
||||
pub(crate) use settings::{
|
||||
SETTINGS_LANGUAGES_PATTERN, SETTINGS_NESTED_KEY_VALUE_PATTERN, SETTINGS_ROOT_KEY_VALUE_PATTERN,
|
||||
SETTINGS_ASSISTANT_TOOLS_PATTERN, SETTINGS_LANGUAGES_PATTERN,
|
||||
SETTINGS_NESTED_KEY_VALUE_PATTERN, SETTINGS_ROOT_KEY_VALUE_PATTERN,
|
||||
};
|
||||
|
|
|
@ -39,3 +39,35 @@ pub const SETTINGS_LANGUAGES_PATTERN: &str = r#"(document
|
|||
)
|
||||
(#eq? @languages "languages")
|
||||
)"#;
|
||||
|
||||
pub const SETTINGS_ASSISTANT_TOOLS_PATTERN: &str = r#"(document
|
||||
(object
|
||||
(pair
|
||||
key: (string (string_content) @assistant)
|
||||
value: (object
|
||||
(pair
|
||||
key: (string (string_content) @profiles)
|
||||
value: (object
|
||||
(pair
|
||||
key: (_)
|
||||
value: (object
|
||||
(pair
|
||||
key: (string (string_content) @tools_key)
|
||||
value: (object
|
||||
(pair
|
||||
key: (string (string_content) @tool_name)
|
||||
value: (_) @tool_value
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
(#eq? @assistant "assistant")
|
||||
(#eq? @profiles "profiles")
|
||||
(#eq? @tools_key "tools")
|
||||
)"#;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue