Update assistant to agent in settings and keymaps (#29943)

Closes #ISSUE

Release Notes:

- Agent Beta: Renamed the top-level `assistant` settings key to `agent`.
A migration for existing settings files is included.
- Agent Beta: Moved the `assistant::ToggleFocus`,
`assistant::ToggleModelSelector`, and `assistant::OpenRulesLibrary`
actions to the `agent` namespace. Existing keymaps that mention these
actions by their old names will continue to work.

---------

Co-authored-by: Max <max@zed.dev>
This commit is contained in:
Cole Miller 2025-05-05 21:02:56 -04:00 committed by GitHub
parent 34e10e4e56
commit bdd911f89e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
17 changed files with 191 additions and 58 deletions

View file

@ -57,3 +57,9 @@ pub(crate) mod m_2025_04_23 {
pub(crate) use settings::SETTINGS_PATTERNS;
}
pub(crate) mod m_2025_05_05 {
mod settings;
pub(crate) use settings::SETTINGS_PATTERNS;
}

View file

@ -0,0 +1,41 @@
use std::ops::Range;
use tree_sitter::{Query, QueryMatch};
use crate::{
MigrationPatterns, patterns::SETTINGS_ASSISTANT_PATTERN,
patterns::SETTINGS_EDIT_PREDICTIONS_ASSISTANT_PATTERN,
};
pub const SETTINGS_PATTERNS: MigrationPatterns = &[
(SETTINGS_ASSISTANT_PATTERN, rename_assistant),
(
SETTINGS_EDIT_PREDICTIONS_ASSISTANT_PATTERN,
rename_edit_prediction_assistant,
),
];
fn rename_assistant(
_contents: &str,
mat: &QueryMatch,
query: &Query,
) -> Option<(Range<usize>, String)> {
let key_capture_ix = query.capture_index_for_name("key")?;
let key_range = mat
.nodes_for_capture_index(key_capture_ix)
.next()?
.byte_range();
return Some((key_range, "agent".to_string()));
}
fn rename_edit_prediction_assistant(
_contents: &str,
mat: &QueryMatch,
query: &Query,
) -> Option<(Range<usize>, String)> {
let key_capture_ix = query.capture_index_for_name("enabled_in_assistant")?;
let key_range = mat
.nodes_for_capture_index(key_capture_ix)
.next()?
.byte_range();
return Some((key_range, "enabled_in_text_threads".to_string()));
}

View file

@ -136,6 +136,10 @@ pub fn migrate_settings(text: &str) -> Result<Option<String>> {
migrations::m_2025_04_23::SETTINGS_PATTERNS,
&SETTINGS_QUERY_2025_04_23,
),
(
migrations::m_2025_05_05::SETTINGS_PATTERNS,
&SETTINGS_QUERY_2025_05_05,
),
];
run_migrations(text, migrations)
}
@ -222,6 +226,10 @@ define_query!(
SETTINGS_QUERY_2025_04_23,
migrations::m_2025_04_23::SETTINGS_PATTERNS
);
define_query!(
SETTINGS_QUERY_2025_05_05,
migrations::m_2025_05_05::SETTINGS_PATTERNS
);
// custom query
static EDIT_PREDICTION_SETTINGS_MIGRATION_QUERY: LazyLock<Query> = LazyLock::new(|| {
@ -581,7 +589,7 @@ mod tests {
Some(
r#"
{
"assistant": {
"agent": {
"profiles": {
"custom": {
"name": "Custom",
@ -619,7 +627,7 @@ mod tests {
Some(
r#"
{
"assistant": {
"agent": {
"profiles": {
"custom": {
"name": "Custom",
@ -655,7 +663,24 @@ mod tests {
}
}
"#,
None,
Some(
r#"
{
"agent": {
"profiles": {
"custom": {
"name": "Custom",
"tools": {
"diagnostics": true,
"find_path": true,
"read_file": true
}
}
}
}
}
"#,
),
)
}
@ -679,7 +704,7 @@ mod tests {
Some(
r#"
{
"assistant": {
"agent": {
"profiles": {
"default": {
"tools": {
@ -694,4 +719,28 @@ mod tests {
),
);
}
#[test]
fn test_rename_assistant() {
assert_migrate_settings(
r#"{
"assistant": {
"foo": "bar"
},
"edit_predictions": {
"enabled_in_assistant": false,
}
}"#,
Some(
r#"{
"agent": {
"foo": "bar"
},
"edit_predictions": {
"enabled_in_text_threads": false,
}
}"#,
),
);
}
}

View file

@ -7,6 +7,7 @@ pub(crate) use keymap::{
};
pub(crate) use settings::{
SETTINGS_ASSISTANT_TOOLS_PATTERN, SETTINGS_LANGUAGES_PATTERN,
SETTINGS_ASSISTANT_PATTERN, SETTINGS_ASSISTANT_TOOLS_PATTERN,
SETTINGS_EDIT_PREDICTIONS_ASSISTANT_PATTERN, SETTINGS_LANGUAGES_PATTERN,
SETTINGS_NESTED_KEY_VALUE_PATTERN, SETTINGS_ROOT_KEY_VALUE_PATTERN,
};

View file

@ -71,3 +71,25 @@ pub const SETTINGS_ASSISTANT_TOOLS_PATTERN: &str = r#"(document
(#eq? @profiles "profiles")
(#eq? @tools_key "tools")
)"#;
pub const SETTINGS_ASSISTANT_PATTERN: &str = r#"(document
(object
(pair
key: (string (string_content) @key)
)
)
(#eq? @key "assistant")
)"#;
pub const SETTINGS_EDIT_PREDICTIONS_ASSISTANT_PATTERN: &str = r#"(document
(object
(pair
key: (string (string_content) @edit_predictions)
value: (object
(pair key: (string (string_content) @enabled_in_assistant))
)
)
)
(#eq? @edit_predictions "edit_predictions")
(#eq? @enabled_in_assistant "enabled_in_assistant")
)"#;