diff --git a/src/plan.rs b/src/plan.rs index 5118cb9..1c0c938 100644 --- a/src/plan.rs +++ b/src/plan.rs @@ -113,7 +113,7 @@ impl PlanManager { } pub fn get_plan(&self) -> Option { - self.current_plan.lock().unwrap().clone() + self.current_plan.lock().ok()?.clone() } pub fn set_plan(&self, plan: Plan) { diff --git a/src/tools/create_directory.rs b/src/tools/create_directory.rs index 17109ad..8263176 100644 --- a/src/tools/create_directory.rs +++ b/src/tools/create_directory.rs @@ -18,7 +18,7 @@ pub struct CreateDirectoryOutput { pub created_parents: bool, } -#[derive(Deserialize, Serialize)] +#[derive(Deserialize, Serialize, Default)] pub struct CreateDirectoryTool; impl Tool for CreateDirectoryTool { @@ -67,7 +67,7 @@ impl Tool for CreateDirectoryTool { } // Check if we need to create parent directories - let needs_parents = path.parent().map_or(false, |parent| !parent.exists()); + let needs_parents = path.parent().is_some_and(|parent| !parent.exists()); // Create the directory and all parent directories match fs::create_dir_all(dir_path) { @@ -94,7 +94,7 @@ impl Tool for CreateDirectoryTool { } } -#[derive(Deserialize, Serialize)] +#[derive(Deserialize, Serialize, Default)] pub struct WrappedCreateDirectoryTool { inner: CreateDirectoryTool, } @@ -119,8 +119,7 @@ impl Tool for WrappedCreateDirectoryTool { } async fn call(&self, args: Self::Args) -> Result { - println!(); - println!("{} {}({})", "●".bright_green(), "CreateDir", args.dir_path); + println!("\n{} CreateDir({})", "●".bright_green(), args.dir_path); let result = self.inner.call(args).await; diff --git a/src/tools/delete_file.rs b/src/tools/delete_file.rs index 805f8ea..d6a1abe 100644 --- a/src/tools/delete_file.rs +++ b/src/tools/delete_file.rs @@ -17,7 +17,7 @@ pub struct DeleteFileOutput { pub message: String, } -#[derive(Deserialize, Serialize)] +#[derive(Deserialize, Serialize, Default)] pub struct DeleteFileTool; impl Tool for DeleteFileTool { @@ -74,7 +74,7 @@ impl Tool for DeleteFileTool { } } } -#[derive(Deserialize, Serialize)] +#[derive(Deserialize, Serialize, Default)] pub struct WrappedDeleteFileTool { inner: DeleteFileTool, } @@ -99,8 +99,7 @@ impl Tool for WrappedDeleteFileTool { } async fn call(&self, args: Self::Args) -> Result { - println!(); - println!("{} {}({})", "●".bright_green(), "Delete", args.file_path); + println!("\n{} Delete({})", "●".bright_green(), args.file_path); let result = self.inner.call(args).await; diff --git a/src/tools/edit_file.rs b/src/tools/edit_file.rs index d6a7b5c..8be6ec9 100644 --- a/src/tools/edit_file.rs +++ b/src/tools/edit_file.rs @@ -21,7 +21,7 @@ pub struct EditFileOutput { pub message: String, } -#[derive(Deserialize, Serialize)] +#[derive(Deserialize, Serialize, Default)] pub struct EditFileTool; impl Tool for EditFileTool { @@ -123,7 +123,7 @@ impl Tool for EditFileTool { } } -#[derive(Deserialize, Serialize)] +#[derive(Deserialize, Serialize, Default)] pub struct WrappedEditFileTool { inner: EditFileTool, } @@ -148,8 +148,7 @@ impl Tool for WrappedEditFileTool { } async fn call(&self, args: Self::Args) -> Result { - println!(); - println!("{} {}({})", "●".bright_green(), "Edit", args.file_path); + println!("\n{} Edit({})", "●".bright_green(), args.file_path); let result = self.inner.call(args).await; diff --git a/src/tools/execute_bash_command.rs b/src/tools/execute_bash_command.rs index 59c8ad3..961355c 100644 --- a/src/tools/execute_bash_command.rs +++ b/src/tools/execute_bash_command.rs @@ -18,7 +18,7 @@ pub struct ExecuteBashCommandOutput { pub exit_code: Option, } -#[derive(Deserialize, Serialize)] +#[derive(Deserialize, Serialize, Default)] pub struct ExecuteBashCommandTool; impl Tool for ExecuteBashCommandTool { @@ -75,7 +75,7 @@ impl Tool for ExecuteBashCommandTool { } } -#[derive(Deserialize, Serialize)] +#[derive(Deserialize, Serialize, Default)] pub struct WrappedExecuteBashCommandTool { inner: ExecuteBashCommandTool, } @@ -100,8 +100,7 @@ impl Tool for WrappedExecuteBashCommandTool { } async fn call(&self, args: Self::Args) -> Result { - println!(); - println!("{} {}({})", "●".bright_green(), "Exec", args.command); + println!("\n{} Exec({})", "●".bright_green(), args.command); let result = self.inner.call(args).await; diff --git a/src/tools/grep_search.rs b/src/tools/grep_search.rs index ca87c75..d5bb7f2 100644 --- a/src/tools/grep_search.rs +++ b/src/tools/grep_search.rs @@ -33,7 +33,7 @@ pub struct GrepSearchOutput { pub message: String, } -#[derive(Deserialize, Serialize)] +#[derive(Deserialize, Serialize, Default)] pub struct GrepSearchTool; impl Tool for GrepSearchTool { @@ -85,7 +85,7 @@ impl Tool for GrepSearchTool { Err(_) => continue, // Skip entries we can't access }; - if entry.file_type().map_or(false, |ft| ft.is_file()) { + if entry.file_type().is_some_and(|ft| ft.is_file()) { files_searched += 1; if let Ok(content) = fs::read_to_string(entry.path()) { @@ -127,7 +127,7 @@ impl Tool for GrepSearchTool { } // Wrapper with visual feedback -#[derive(Deserialize, Serialize)] +#[derive(Deserialize, Serialize, Default)] pub struct WrappedGrepSearchTool { inner: GrepSearchTool, } @@ -151,7 +151,7 @@ impl Tool for WrappedGrepSearchTool { } async fn call(&self, args: Self::Args) -> Result { - println!("{} {}({})", "●".bright_green(), "Search", args.query); + println!("\n{} Search({})", "●".bright_green(), args.query); let result = self.inner.call(args).await; diff --git a/src/tools/read_file.rs b/src/tools/read_file.rs index b777eef..90cd56d 100644 --- a/src/tools/read_file.rs +++ b/src/tools/read_file.rs @@ -19,7 +19,7 @@ pub struct ReadFileOutput { pub message: String, } -#[derive(Deserialize, Serialize)] +#[derive(Deserialize, Serialize, Default)] pub struct ReadFileTool; impl Tool for ReadFileTool { @@ -88,7 +88,7 @@ impl Tool for ReadFileTool { } } // 在工具调用前后显示信息 -#[derive(Deserialize, Serialize)] +#[derive(Deserialize, Serialize, Default)] pub struct WrappedReadFileTool { inner: ReadFileTool, } @@ -113,8 +113,7 @@ impl Tool for WrappedReadFileTool { } async fn call(&self, args: Self::Args) -> Result { - println!(); - println!("{} {}({})", "●".bright_green(), "Read", args.file_path); + println!("\n{} Read({})", "●".bright_green(), args.file_path); let result = self.inner.call(args).await; diff --git a/src/tools/scan_codebase.rs b/src/tools/scan_codebase.rs index 116cd59..84f5009 100644 --- a/src/tools/scan_codebase.rs +++ b/src/tools/scan_codebase.rs @@ -18,12 +18,11 @@ pub struct ScanCodebaseOutput { pub total_directories: usize, } -#[derive(Deserialize, Serialize)] +#[derive(Deserialize, Serialize, Default)] pub struct ScanCodebaseTool; impl ScanCodebaseTool { fn scan_directory( - &self, path: &Path, prefix: &str, max_depth: usize, @@ -72,7 +71,7 @@ impl ScanCodebaseTool { result.push_str(&format!("{}{}{}\n", prefix, current_prefix, file_name_str)); dir_count += 1; - let (sub_result, sub_files, sub_dirs) = self.scan_directory( + let (sub_result, sub_files, sub_dirs) = Self::scan_directory( &entry.path(), &format!("{}{}", prefix, next_prefix), max_depth, @@ -136,7 +135,7 @@ impl Tool for ScanCodebaseTool { .unwrap_or_else(|| std::ffi::OsStr::new(root_path)) .to_string_lossy() ); - let (tree_result, file_count, dir_count) = self.scan_directory(path, "", 5, 0)?; + let (tree_result, file_count, dir_count) = Self::scan_directory(path, "", 5, 0)?; structure.push_str(&tree_result); Ok(ScanCodebaseOutput { @@ -148,7 +147,7 @@ impl Tool for ScanCodebaseTool { } } -#[derive(Deserialize, Serialize)] +#[derive(Deserialize, Serialize, Default)] pub struct WrappedScanCodebaseTool { inner: ScanCodebaseTool, } @@ -173,8 +172,7 @@ impl Tool for WrappedScanCodebaseTool { } async fn call(&self, args: Self::Args) -> Result { - println!(); - println!("{} {}({})", "●".bright_green(), "Scan", args.root_path); + println!("\n{} Scan({})", "●".bright_green(), args.root_path); let result = self.inner.call(args).await; diff --git a/src/tools/update_plan.rs b/src/tools/update_plan.rs index 3639473..f1536ae 100644 --- a/src/tools/update_plan.rs +++ b/src/tools/update_plan.rs @@ -203,8 +203,7 @@ impl Tool for WrappedUpdatePlanTool { UpdatePlanArgs::Clear => "Clear Plan", }; - println!(); - println!("{} {}", "●".bright_blue(), action_name); + println!("\n{} {}", "●".bright_blue(), action_name); let result = self.inner.as_ref().unwrap().call(args).await; diff --git a/src/tools/write_file.rs b/src/tools/write_file.rs index b83c9bf..6e51de3 100644 --- a/src/tools/write_file.rs +++ b/src/tools/write_file.rs @@ -19,7 +19,7 @@ pub struct WriteFileOutput { pub message: String, } -#[derive(Deserialize, Serialize)] +#[derive(Deserialize, Serialize, Default)] pub struct WriteFileTool; impl Tool for WriteFileTool { @@ -85,7 +85,7 @@ impl Tool for WriteFileTool { } } } -#[derive(Deserialize, Serialize)] +#[derive(Deserialize, Serialize, Default)] pub struct WrappedWriteFileTool { inner: WriteFileTool, } @@ -110,8 +110,7 @@ impl Tool for WrappedWriteFileTool { } async fn call(&self, args: Self::Args) -> Result { - println!(); - println!("{} {}({})", "●".bright_green(), "Write", args.file_path); + println!("\n{} Write({})", "●".bright_green(), args.file_path); // Store line count before moving args let line_count = args.content.lines().count();