deepseek_rust_cli/tools/file/
navigation.rs1use std::{collections::HashMap, path::Path};
2
3use anyhow::Result;
4use async_trait::async_trait;
5use serde_json::Value;
6
7use crate::{agent::types::UndoAction, tools, tools::base::Tool};
8
9pub struct ListDirectoryTool;
10#[async_trait]
11impl Tool for ListDirectoryTool {
12 fn name(&self) -> &str {
13 "list_directory"
14 }
15 async fn execute(
16 &self,
17 args: &HashMap<String, Value>,
18 _undo: &mut Vec<UndoAction>,
19 _cwd: Option<&Path>,
20 ) -> Result<String> {
21 let path = args.get("path").and_then(|v| v.as_str());
22 tools::file_io::list_directory(path)
23 .await
24 .map(|v| v.join("\n"))
25 }
26}
27
28pub struct TreeViewTool;
29#[async_trait]
30impl Tool for TreeViewTool {
31 fn name(&self) -> &str {
32 "tree_view"
33 }
34 async fn execute(
35 &self,
36 args: &HashMap<String, Value>,
37 _undo: &mut Vec<UndoAction>,
38 _cwd: Option<&Path>,
39 ) -> Result<String> {
40 let path = args
41 .get("path")
42 .and_then(|v| v.as_str())
43 .map(|s| s.to_string());
44 let depth = args
45 .get("max_depth")
46 .and_then(|v| v.as_u64())
47 .map(|v| v as usize);
48 tools::file_ops::tree_view(path, depth).await
49 }
50}