file_search.rs

 1use agent::FindPathToolInput;
 2use agent_settings::AgentProfileId;
 3use anyhow::Result;
 4use async_trait::async_trait;
 5use regex::Regex;
 6
 7use crate::example::{Example, ExampleContext, ExampleMetadata};
 8
 9pub struct FileSearchExample;
10
11#[async_trait(?Send)]
12impl Example for FileSearchExample {
13    fn meta(&self) -> ExampleMetadata {
14        ExampleMetadata {
15            name: "file_search".to_string(),
16            url: "https://github.com/zed-industries/zed.git".to_string(),
17            revision: "03ecb88fe30794873f191ddb728f597935b3101c".to_string(),
18            language_server: None,
19            max_assertions: Some(3),
20            profile_id: AgentProfileId::default(),
21            existing_thread_json: None,
22            max_turns: None,
23        }
24    }
25
26    async fn conversation(&self, cx: &mut ExampleContext) -> Result<()> {
27        const FILENAME: &str = "find_replace_file_tool.rs";
28
29        let prompt = format!(
30            r#"
31        Look at the `{FILENAME}`. I want to implement a card for it. The card should implement the `Render` trait.
32
33        The card should show a diff. It should be a beautifully presented diff. The card "box" should look like what we show for
34        markdown codeblocks (look at `MarkdownElement`). I want to see a red background for lines that were deleted and a green
35        background for lines that were added. We should have a div per diff line.
36        "#
37        );
38
39        let response = cx.prompt_with_max_turns(prompt, 1).await?;
40        let tool_use = response.expect_tool_call("find_path", cx)?;
41        let input = tool_use.parse_input::<FindPathToolInput>()?;
42
43        let glob = input.glob;
44        cx.assert(glob.ends_with(FILENAME), "glob ends with file name")?;
45
46        let without_filename = glob.replace(FILENAME, "");
47        let matches = Regex::new("(\\*\\*|zed)/(\\*\\*?/)?")
48            .unwrap()
49            .is_match(&without_filename);
50
51        cx.assert(matches, "glob starts with `**` or project")?;
52
53        Ok(())
54    }
55}