Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

Add completions and schema validation for agent profile tool settings (#65036)

Daniel Strobuschcd8c46741886
diff --git a/crates/settings/src/settings_store.rs b/crates/settings/src/settings_store.rs
index 0c0b00652f3..73b81193636 100644
--- a/crates/settings/src/settings_store.rs
+++ b/crates/settings/src/settings_store.rs
@@ -3169,6 +3169,51 @@ mod tests {
)
}
+ #[gpui::test]
+ fn test_agent_profile_tool_schema(cx: &mut App) {
+ SettingsStore::test(cx);
+
+ let schema = SettingsStore::json_schema(&SettingsJsonSchemaParams {
+ language_names: &[],
+ font_names: &[],
+ theme_names: &[],
+ icon_theme_names: &[],
+ lsp_adapter_names: &[],
+ action_names: &[],
+ action_documentation: &HashMap::default(),
+ deprecations: &HashMap::default(),
+ deprecation_messages: &HashMap::default(),
+ });
+ let tools = schema
+ .pointer("/$defs/AgentProfileContent/properties/tools")
+ .expect("agent profile tools schema should exist");
+ let properties = tools
+ .get("properties")
+ .and_then(Value::as_object)
+ .expect("agent profile tools should have named properties");
+ let boolean_schema = serde_json::json!({ "type": "boolean" });
+ for tool_schema in properties.values() {
+ assert_eq!(tool_schema, &boolean_schema);
+ }
+ assert_eq!(tools.get("additionalProperties"), Some(&Value::Bool(false)));
+
+ let defaults: Value = crate::parse_json_with_comments(default_settings().as_ref())
+ .expect("default settings should parse");
+ for profile in ["write", "ask"] {
+ let path = format!("/agent/profiles/{profile}/tools");
+ let default_tools = defaults
+ .pointer(&path)
+ .and_then(Value::as_object)
+ .expect("built-in profile should have tools");
+ for tool_name in default_tools.keys() {
+ assert!(
+ properties.contains_key(tool_name),
+ "{profile} tool {tool_name} should be suggested in the schema"
+ );
+ }
+ }
+ }
+
#[gpui::test]
fn test_lsp_settings_schema_generation(cx: &mut App) {
SettingsStore::test(cx);
diff --git a/crates/settings_content/src/agent.rs b/crates/settings_content/src/agent.rs
index 6bafc029cb8..b066bdaf298 100644
--- a/crates/settings_content/src/agent.rs
+++ b/crates/settings_content/src/agent.rs
@@ -589,6 +589,7 @@ impl AgentSettingsContent {
pub struct AgentProfileContent {
pub name: Arc<str>,
#[serde(default)]
+ #[schemars(schema_with = "agent_profile_tools_schema")]
pub tools: IndexMap<Arc<str>, bool>,
/// Whether all context servers are enabled by default.
pub enable_all_context_servers: Option<bool>,
@@ -604,6 +605,44 @@ pub struct ContextServerPresetContent {
pub tools: IndexMap<Arc<str>, bool>,
}
+fn agent_profile_tools_schema(_: &mut schemars::SchemaGenerator) -> schemars::Schema {
+ let tool_names = [
+ "apply_code_action",
+ "ask_user",
+ "copy_path",
+ "create_directory",
+ "create_thread",
+ "delete_path",
+ "diagnostics",
+ "edit_file",
+ "fetch",
+ "find_path",
+ "find_references",
+ "get_code_actions",
+ "go_to_definition",
+ "grep",
+ "list_agents_and_models",
+ "list_directory",
+ "move_path",
+ "read_file",
+ "rename_symbol",
+ "search_web",
+ "skill",
+ "spawn_agent",
+ "terminal",
+ "write_file",
+ ];
+ let properties = tool_names
+ .into_iter()
+ .map(|name| (name.to_string(), serde_json::json!({ "type": "boolean" })))
+ .collect::<serde_json::Map<_, _>>();
+ json_schema!({
+ "type": "object",
+ "properties": properties,
+ "additionalProperties": false
+ })
+}
+
#[derive(
Copy,
Clone,