Port edit tool logic

This commit is contained in:
Agus Zubiaga 2025-08-07 18:15:08 -03:00
parent 168e55db53
commit dbba5c8967
7 changed files with 1629 additions and 8 deletions

3
Cargo.lock generated
View file

@ -158,8 +158,10 @@ dependencies = [
"acp_thread",
"agent-client-protocol",
"agent_servers",
"agent_settings",
"anyhow",
"assistant_tool",
"assistant_tools",
"client",
"clock",
"cloud_llm_client",
@ -176,6 +178,7 @@ dependencies = [
"language_model",
"language_models",
"log",
"paths",
"project",
"prompt_store",
"reqwest_client",

View file

@ -14,9 +14,11 @@ workspace = true
[dependencies]
acp_thread.workspace = true
agent-client-protocol.workspace = true
agent_settings.workspace = true
agent_servers.workspace = true
anyhow.workspace = true
assistant_tool.workspace = true
assistant_tools.workspace = true
cloud_llm_client.workspace = true
collections.workspace = true
fs.workspace = true
@ -24,9 +26,11 @@ futures.workspace = true
gpui.workspace = true
handlebars = { workspace = true, features = ["rust-embed"] }
indoc.workspace = true
language.workspace = true
language_model.workspace = true
language_models.workspace = true
log.workspace = true
paths.workspace = true
project.workspace = true
prompt_store.workspace = true
rust-embed.workspace = true

View file

@ -1,5 +1,5 @@
use crate::{templates::Templates, AgentResponseEvent, Thread};
use crate::{FindPathTool, ToolCallAuthorization};
use crate::{EditFileTool, FindPathTool, ToolCallAuthorization};
use acp_thread::ModelSelector;
use agent_client_protocol as acp;
use anyhow::{anyhow, Context as _, Result};
@ -412,9 +412,10 @@ impl acp_thread::AgentConnection for NativeAgentConnection {
anyhow!("No default model configured. Please configure a default model in settings.")
})?;
let thread = cx.new(|_| {
let mut thread = Thread::new(project.clone(), agent.project_context.clone(), action_log, agent.templates.clone(), default_model);
let thread = cx.new(|cx| {
let mut thread = Thread::new(project.clone(), agent.project_context.clone(), action_log.clone(), agent.templates.clone(), default_model);
thread.add_tool(FindPathTool::new(project.clone()));
thread.add_tool(EditFileTool::new(project.clone(), cx.entity()));
thread
});

View file

@ -1,4 +1,5 @@
use crate::templates::{SystemPromptTemplate, Template, Templates};
use acp_thread::Diff;
use agent_client_protocol as acp;
use anyhow::{anyhow, Context as _, Result};
use assistant_tool::ActionLog;
@ -132,7 +133,7 @@ pub struct Thread {
project_context: Rc<RefCell<ProjectContext>>,
templates: Arc<Templates>,
pub selected_model: Arc<dyn LanguageModel>,
_action_log: Entity<ActionLog>,
action_log: Entity<ActionLog>,
}
impl Thread {
@ -152,7 +153,7 @@ impl Thread {
project_context,
templates,
selected_model: default_model,
_action_log: action_log,
action_log,
}
}
@ -322,6 +323,10 @@ impl Thread {
events_rx
}
pub fn action_log(&self) -> &Entity<ActionLog> {
&self.action_log
}
pub fn build_system_message(&self) -> AgentMessage {
log::debug!("Building system message");
let prompt = SystemPromptTemplate {
@ -538,6 +543,11 @@ impl Thread {
status: Some(acp::ToolCallStatus::InProgress),
..Default::default()
});
log::trace!(
"Running tool {:?} with input: {}",
tool_use.name,
serde_json::to_string_pretty(&tool_use.input).unwrap_or_default()
);
cx.update(|cx| tool.run(tool_use.input, tool_event_stream, cx))?
.await
})
@ -586,7 +596,7 @@ impl Thread {
self.messages.last_mut().unwrap()
}
fn build_completion_request(
pub(crate) fn build_completion_request(
&self,
completion_intent: CompletionIntent,
cx: &mut App,
@ -866,6 +876,12 @@ impl AgentResponseEventStream {
.ok();
}
fn send_tool_call_diff(&self, tool_call_diff: ToolCallDiff) {
self.0
.unbounded_send(Ok(AgentResponseEvent::ToolCallDiff(tool_call_diff)))
.ok();
}
fn send_stop(&self, reason: StopReason) {
match reason {
StopReason::EndTurn => {
@ -909,4 +925,11 @@ impl ToolCallEventStream {
pub fn send_update(&self, fields: acp::ToolCallUpdateFields) {
self.stream.send_tool_call_update(&self.tool_use_id, fields);
}
pub fn send_diff(&self, diff: Entity<Diff>) {
self.stream.send_tool_call_diff(ToolCallDiff {
tool_call_id: acp::ToolCallId(self.tool_use_id.to_string().into()),
diff,
});
}
}

View file

@ -1,3 +1,5 @@
mod edit_file_tool;
mod find_path_tool;
pub use edit_file_tool::*;
pub use find_path_tool::*;

File diff suppressed because it is too large Load diff

View file

@ -2,7 +2,7 @@ mod copy_path_tool;
mod create_directory_tool;
mod delete_path_tool;
mod diagnostics_tool;
mod edit_agent;
pub mod edit_agent;
mod edit_file_tool;
mod fetch_tool;
mod find_path_tool;
@ -14,7 +14,7 @@ mod open_tool;
mod project_notifications_tool;
mod read_file_tool;
mod schema;
mod templates;
pub mod templates;
mod terminal_tool;
mod thinking_tool;
mod ui;