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.

eval: Improve `StreamingEditFileTool` performance (#52428)

Bennet Bo Fennerdd0d87f4eec9
diff --git a/crates/agent/src/tools/evals/fixtures/extract_handle_command_output/possible-09.diff b/crates/agent/src/tools/evals/fixtures/extract_handle_command_output/possible-09.diff
new file mode 100644
index 00000000000..6bc45657b3d
--- /dev/null
+++ b/crates/agent/src/tools/evals/fixtures/extract_handle_command_output/possible-09.diff
@@ -0,0 +1,20 @@
+@@ -5,7 +5,7 @@
+ use futures::AsyncWriteExt;
+ use gpui::SharedString;
+ use serde::{Deserialize, Serialize};
+-use std::process::Stdio;
++use std::process::{Output, Stdio};
+ use std::{ops::Range, path::Path};
+ use text::Rope;
+ use time::OffsetDateTime;
+@@ -94,6 +94,10 @@
+
+ let output = child.output().await.context("reading git blame output")?;
+
++ handle_command_output(output)
++}
++
++fn handle_command_output(output: Output) -> Result<String> {
+ if !output.status.success() {
+ let stderr = String::from_utf8_lossy(&output.stderr);
+ let trimmed = stderr.trim();
diff --git a/crates/agent/src/tools/evals/streaming_edit_file.rs b/crates/agent/src/tools/evals/streaming_edit_file.rs
index 5ab931915e4..6a55517037e 100644
--- a/crates/agent/src/tools/evals/streaming_edit_file.rs
+++ b/crates/agent/src/tools/evals/streaming_edit_file.rs
@@ -808,6 +808,8 @@ fn eval_extract_handle_command_output() {
include_str!("fixtures/extract_handle_command_output/possible-05.diff"),
include_str!("fixtures/extract_handle_command_output/possible-06.diff"),
include_str!("fixtures/extract_handle_command_output/possible-07.diff"),
+ include_str!("fixtures/extract_handle_command_output/possible-08.diff"),
+ include_str!("fixtures/extract_handle_command_output/possible-09.diff"),
];
eval_utils::eval(100, 0.95, eval_utils::NoProcessor, move || {
diff --git a/crates/agent/src/tools/streaming_edit_file_tool.rs b/crates/agent/src/tools/streaming_edit_file_tool.rs
index ea89d6fef77..df99b4d65a6 100644
--- a/crates/agent/src/tools/streaming_edit_file_tool.rs
+++ b/crates/agent/src/tools/streaming_edit_file_tool.rs
@@ -111,6 +111,8 @@ pub enum StreamingEditFileMode {
}
/// A single edit operation that replaces old text with new text
+/// Properly escape all text fields as valid JSON strings.
+/// Remember to escape special characters like newlines (`\n`) and quotes (`"`) in JSON strings.
#[derive(Clone, Debug, Serialize, Deserialize, JsonSchema)]
pub struct Edit {
/// The exact text to find in the file. This will be matched using fuzzy matching
diff --git a/crates/language_model/src/tool_schema.rs b/crates/language_model/src/tool_schema.rs
index f9402c28dc3..6fbb3761b43 100644
--- a/crates/language_model/src/tool_schema.rs
+++ b/crates/language_model/src/tool_schema.rs
@@ -17,7 +17,12 @@ pub enum LanguageModelToolSchemaFormat {
pub fn root_schema_for<T: JsonSchema>(format: LanguageModelToolSchemaFormat) -> Schema {
let mut generator = match format {
- LanguageModelToolSchemaFormat::JsonSchema => SchemaSettings::draft07().into_generator(),
+ LanguageModelToolSchemaFormat::JsonSchema => SchemaSettings::draft07()
+ .with(|settings| {
+ settings.meta_schema = None;
+ settings.inline_subschemas = true;
+ })
+ .into_generator(),
LanguageModelToolSchemaFormat::JsonSchemaSubset => SchemaSettings::openapi3()
.with(|settings| {
settings.meta_schema = None;