Don't show deleted hunks when agent overwrites file (#29918)

Release Notes:

- Improved display of diffs when the agent rewrites a file from scratch.
This commit is contained in:
Antonio Scandurra 2025-05-05 15:13:36 +02:00 committed by GitHub
parent 4a7b3aa4b8
commit 5674b5cd4d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 43 additions and 40 deletions

View file

@ -118,7 +118,7 @@ impl Tool for CreateFileTool {
.map_err(|err| anyhow!("Unable to open buffer for {destination_path}: {err}"))?;
cx.update(|cx| {
action_log.update(cx, |action_log, cx| {
action_log.track_buffer(buffer.clone(), cx)
action_log.buffer_created(buffer.clone(), cx)
});
buffer.update(cx, |buffer, cx| buffer.set_text(contents, cx));
action_log.update(cx, |action_log, cx| {

View file

@ -101,7 +101,7 @@ impl EditAgent {
.render(&this.templates)?;
let new_chunks = this.request(previous_messages, prompt, cx).await?;
let (output, mut inner_events) = this.replace_text_with_chunks(buffer, new_chunks, cx);
let (output, mut inner_events) = this.overwrite_with_chunks(buffer, new_chunks, cx);
while let Some(event) = inner_events.next().await {
events_tx.unbounded_send(event).ok();
}
@ -110,7 +110,7 @@ impl EditAgent {
(output, events_rx)
}
fn replace_text_with_chunks(
fn overwrite_with_chunks(
&self,
buffer: Entity<Buffer>,
edit_chunks: impl 'static + Send + Stream<Item = Result<String, LanguageModelCompletionError>>,
@ -123,9 +123,9 @@ impl EditAgent {
let this = self.clone();
let task = cx.spawn(async move |cx| {
this.action_log
.update(cx, |log, cx| log.track_buffer(buffer.clone(), cx))?;
.update(cx, |log, cx| log.buffer_created(buffer.clone(), cx))?;
let output = this
.replace_text_with_chunks_internal(buffer, edit_chunks, output_events_tx, cx)
.overwrite_with_chunks_internal(buffer, edit_chunks, output_events_tx, cx)
.await;
this.project
.update(cx, |project, cx| project.set_agent_location(None, cx))?;
@ -134,7 +134,7 @@ impl EditAgent {
(task, output_events_rx)
}
async fn replace_text_with_chunks_internal(
async fn overwrite_with_chunks_internal(
&self,
buffer: Entity<Buffer>,
edit_chunks: impl 'static + Send + Stream<Item = Result<String, LanguageModelCompletionError>>,
@ -246,9 +246,9 @@ impl EditAgent {
let this = self.clone();
let task = cx.spawn(async move |mut cx| {
this.action_log
.update(cx, |log, cx| log.track_buffer(buffer.clone(), cx))?;
.update(cx, |log, cx| log.buffer_read(buffer.clone(), cx))?;
let output = this
.apply_edits_internal(buffer, edit_chunks, output_events_tx, &mut cx)
.apply_edit_chunks_internal(buffer, edit_chunks, output_events_tx, &mut cx)
.await;
this.project
.update(cx, |project, cx| project.set_agent_location(None, cx))?;
@ -257,7 +257,7 @@ impl EditAgent {
(task, output_events_rx)
}
async fn apply_edits_internal(
async fn apply_edit_chunks_internal(
&self,
buffer: Entity<Buffer>,
edit_chunks: impl 'static + Send + Stream<Item = Result<String, LanguageModelCompletionError>>,
@ -1027,7 +1027,7 @@ mod tests {
.read_with(cx, |log, _| log.project().clone());
let buffer = cx.new(|cx| Buffer::local("abc\ndef\nghi", cx));
let (chunks_tx, chunks_rx) = mpsc::unbounded();
let (apply, mut events) = agent.replace_text_with_chunks(
let (apply, mut events) = agent.overwrite_with_chunks(
buffer.clone(),
chunks_rx.map(|chunk: &str| Ok(chunk.to_string())),
&mut cx.to_async(),

View file

@ -239,8 +239,7 @@ impl Tool for EditFileTool {
};
let snapshot = cx.update(|cx| {
action_log.update(cx, |log, cx| log.track_buffer(buffer.clone(), cx));
action_log.update(cx, |log, cx| log.buffer_read(buffer.clone(), cx));
let base_version = diff.base_version.clone();
let snapshot = buffer.update(cx, |buffer, cx| {
buffer.finalize_last_transaction();

View file

@ -152,7 +152,7 @@ impl Tool for ReadFileTool {
})?;
action_log.update(cx, |log, cx| {
log.track_buffer(buffer.clone(), cx);
log.buffer_read(buffer.clone(), cx);
})?;
if let Some(anchor) = anchor {
@ -177,7 +177,7 @@ impl Tool for ReadFileTool {
let result = buffer.read_with(cx, |buffer, _cx| buffer.text())?;
action_log.update(cx, |log, cx| {
log.track_buffer(buffer, cx);
log.buffer_read(buffer, cx);
})?;
Ok(result)