diff --git a/Cargo.lock b/Cargo.lock index fd3c241fc6be1ca95d4850e2f3436691a565e0ee..c8ce787a0b73018ea516cb69fa1b6f3766e180c6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -671,12 +671,10 @@ dependencies = [ "http_client", "indexed_docs", "language", - "language_model", "pretty_assertions", "project", "prompt_store", "rope", - "schemars", "semantic_index", "serde", "serde_json", diff --git a/crates/assistant/src/assistant.rs b/crates/assistant/src/assistant.rs index a62564c55d7af59cab237da08e9a12ecf4e0c714..ddd9c2974ccdbd8c58cee9dce328f22c3bd6a34c 100644 --- a/crates/assistant/src/assistant.rs +++ b/crates/assistant/src/assistant.rs @@ -10,7 +10,7 @@ use std::sync::Arc; use assistant_settings::AssistantSettings; use assistant_slash_command::SlashCommandRegistry; -use assistant_slash_commands::{ProjectSlashCommandFeatureFlag, SearchSlashCommandFeatureFlag}; +use assistant_slash_commands::SearchSlashCommandFeatureFlag; use client::Client; use command_palette_hooks::CommandPaletteFilter; use feature_flags::FeatureFlagAppExt; @@ -108,11 +108,8 @@ pub fn init( let is_search_slash_command_enabled = cx .update(|cx| cx.wait_for_flag::())? .await; - let is_project_slash_command_enabled = cx - .update(|cx| cx.wait_for_flag::())? - .await; - if !is_search_slash_command_enabled && !is_project_slash_command_enabled { + if !is_search_slash_command_enabled { return Ok(()); } @@ -137,7 +134,7 @@ pub fn init( assistant_panel::init(cx); context_server::init(cx); - register_slash_commands(Some(prompt_builder.clone()), cx); + register_slash_commands(cx); inline_assistant::init( fs.clone(), prompt_builder.clone(), @@ -213,7 +210,7 @@ fn update_active_language_model_from_settings(cx: &mut App) { }); } -fn register_slash_commands(prompt_builder: Option>, cx: &mut App) { +fn register_slash_commands(cx: &mut App) { let slash_command_registry = SlashCommandRegistry::global(cx); slash_command_registry.register_command(assistant_slash_commands::FileSlashCommand, true); @@ -231,21 +228,6 @@ fn register_slash_commands(prompt_builder: Option>, cx: &mut .register_command(assistant_slash_commands::DiagnosticsSlashCommand, true); slash_command_registry.register_command(assistant_slash_commands::FetchSlashCommand, true); - if let Some(prompt_builder) = prompt_builder { - cx.observe_flag::({ - let slash_command_registry = slash_command_registry.clone(); - move |is_enabled, _cx| { - if is_enabled { - slash_command_registry.register_command( - assistant_slash_commands::ProjectSlashCommand::new(prompt_builder.clone()), - true, - ); - } - } - }) - .detach(); - } - cx.observe_flag::({ let slash_command_registry = slash_command_registry.clone(); move |is_enabled, _cx| { diff --git a/crates/assistant_slash_commands/Cargo.toml b/crates/assistant_slash_commands/Cargo.toml index b2d98a88f45608280e37955809619ac92c45c13b..aeaf7f10304d09de40db43d526f473f3bb3a5c71 100644 --- a/crates/assistant_slash_commands/Cargo.toml +++ b/crates/assistant_slash_commands/Cargo.toml @@ -29,11 +29,9 @@ html_to_markdown.workspace = true http_client.workspace = true indexed_docs.workspace = true language.workspace = true -language_model.workspace = true project.workspace = true prompt_store.workspace = true rope.workspace = true -schemars.workspace = true semantic_index.workspace = true serde.workspace = true serde_json.workspace = true diff --git a/crates/assistant_slash_commands/src/assistant_slash_commands.rs b/crates/assistant_slash_commands/src/assistant_slash_commands.rs index 31b874fa0b5d98110b78521543340f34b9d7408a..b3e5bb045b9d87f8d221ff42ae74b4c62a03a227 100644 --- a/crates/assistant_slash_commands/src/assistant_slash_commands.rs +++ b/crates/assistant_slash_commands/src/assistant_slash_commands.rs @@ -7,7 +7,6 @@ mod docs_command; mod fetch_command; mod file_command; mod now_command; -mod project_command; mod prompt_command; mod search_command; mod selection_command; @@ -29,7 +28,6 @@ pub use crate::docs_command::*; pub use crate::fetch_command::*; pub use crate::file_command::*; pub use crate::now_command::*; -pub use crate::project_command::*; pub use crate::prompt_command::*; pub use crate::search_command::*; pub use crate::selection_command::*; diff --git a/crates/assistant_slash_commands/src/project_command.rs b/crates/assistant_slash_commands/src/project_command.rs deleted file mode 100644 index 584db58b59746d798659b39338a6d417cd7d35ab..0000000000000000000000000000000000000000 --- a/crates/assistant_slash_commands/src/project_command.rs +++ /dev/null @@ -1,197 +0,0 @@ -use std::{ - fmt::Write as _, - ops::DerefMut, - sync::{atomic::AtomicBool, Arc}, -}; - -use anyhow::{anyhow, Result}; -use assistant_slash_command::{ - ArgumentCompletion, SlashCommand, SlashCommandOutput, SlashCommandOutputSection, - SlashCommandResult, -}; -use feature_flags::FeatureFlag; -use gpui::{App, Task, WeakEntity}; -use language::{Anchor, CodeLabel, LspAdapterDelegate}; -use language_model::{LanguageModelRegistry, LanguageModelTool}; -use prompt_store::PromptBuilder; -use schemars::JsonSchema; -use semantic_index::SemanticDb; -use serde::Deserialize; -use ui::prelude::*; -use workspace::Workspace; - -use super::{create_label_for_command, search_command::add_search_result_section}; - -pub struct ProjectSlashCommandFeatureFlag; - -impl FeatureFlag for ProjectSlashCommandFeatureFlag { - const NAME: &'static str = "project-slash-command"; -} - -pub struct ProjectSlashCommand { - prompt_builder: Arc, -} - -impl ProjectSlashCommand { - pub fn new(prompt_builder: Arc) -> Self { - Self { prompt_builder } - } -} - -impl SlashCommand for ProjectSlashCommand { - fn name(&self) -> String { - "project".into() - } - - fn label(&self, cx: &App) -> CodeLabel { - create_label_for_command("project", &[], cx) - } - - fn description(&self) -> String { - "Generate a semantic search based on context".into() - } - - fn icon(&self) -> IconName { - IconName::Folder - } - - fn menu_text(&self) -> String { - self.description() - } - - fn requires_argument(&self) -> bool { - false - } - - fn complete_argument( - self: Arc, - _arguments: &[String], - _cancel: Arc, - _workspace: Option>, - _window: &mut Window, - _cx: &mut App, - ) -> Task>> { - Task::ready(Ok(Vec::new())) - } - - fn run( - self: Arc, - _arguments: &[String], - _context_slash_command_output_sections: &[SlashCommandOutputSection], - context_buffer: language::BufferSnapshot, - workspace: WeakEntity, - _delegate: Option>, - window: &mut Window, - cx: &mut App, - ) -> Task { - let model_registry = LanguageModelRegistry::read_global(cx); - let current_model = model_registry.active_model(); - let prompt_builder = self.prompt_builder.clone(); - - let Some(workspace) = workspace.upgrade() else { - return Task::ready(Err(anyhow::anyhow!("workspace was dropped"))); - }; - let project = workspace.read(cx).project().clone(); - let fs = project.read(cx).fs().clone(); - let Some(project_index) = - cx.update_global(|index: &mut SemanticDb, cx| index.project_index(project, cx)) - else { - return Task::ready(Err(anyhow::anyhow!("no project indexer"))); - }; - - window.spawn(cx, async move |cx| { - let current_model = current_model.ok_or_else(|| anyhow!("no model selected"))?; - - let prompt = - prompt_builder.generate_project_slash_command_prompt(context_buffer.text())?; - - let search_queries = current_model - .use_tool::( - language_model::LanguageModelRequest { - messages: vec![language_model::LanguageModelRequestMessage { - role: language_model::Role::User, - content: vec![language_model::MessageContent::Text(prompt)], - cache: false, - }], - tools: vec![], - stop: vec![], - temperature: None, - }, - cx.deref_mut(), - ) - .await? - .search_queries; - - let results = project_index - .read_with(cx, |project_index, cx| { - project_index.search(search_queries.clone(), 25, cx) - })? - .await?; - - let results = SemanticDb::load_results(results, &fs, &cx).await?; - - cx.background_spawn(async move { - let mut output = "Project context:\n".to_string(); - let mut sections = Vec::new(); - - for (ix, query) in search_queries.into_iter().enumerate() { - let start_ix = output.len(); - writeln!(&mut output, "Results for {query}:").unwrap(); - let mut has_results = false; - for result in &results { - if result.query_index == ix { - add_search_result_section(result, &mut output, &mut sections); - has_results = true; - } - } - if has_results { - sections.push(SlashCommandOutputSection { - range: start_ix..output.len(), - icon: IconName::MagnifyingGlass, - label: query.into(), - metadata: None, - }); - output.push('\n'); - } else { - output.truncate(start_ix); - } - } - - sections.push(SlashCommandOutputSection { - range: 0..output.len(), - icon: IconName::Book, - label: "Project context".into(), - metadata: None, - }); - - Ok(SlashCommandOutput { - text: output, - sections, - run_commands_in_text: true, - } - .to_event_stream()) - }) - .await - }) - } -} - -#[derive(JsonSchema, Deserialize)] -struct SearchQueries { - /// An array of semantic search queries. - /// - /// These queries will be used to search the user's codebase. - /// The function can only accept 4 queries, otherwise it will error. - /// As such, it's important that you limit the length of the search_queries array to 5 queries or less. - search_queries: Vec, -} - -impl LanguageModelTool for SearchQueries { - fn name() -> String { - "search_queries".to_string() - } - - fn description() -> String { - "Generate semantic search queries based on context".to_string() - } -}