file_search.rs

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