From 874be7b459f2d525de9d6f6a02a107d2a4f356c8 Mon Sep 17 00:00:00 2001 From: "Dhanji R. Prasanna" Date: Sun, 11 Jan 2026 16:21:33 +0530 Subject: [PATCH] refactor(core): collapse nested if statements per clippy Collapsed nested if statements that check related conditions into single conditions using &&. This improves readability by making the logical relationship between conditions explicit. Files changed: - feedback_extraction.rs: 3 instances of tool_use/final_output checks - tools/todo.rs: 1 instance of todo completion check Agent: fowler --- crates/g3-core/src/feedback_extraction.rs | 32 +++++++++++------------ crates/g3-core/src/tools/todo.rs | 29 ++++++++++---------- 2 files changed, 30 insertions(+), 31 deletions(-) diff --git a/crates/g3-core/src/feedback_extraction.rs b/crates/g3-core/src/feedback_extraction.rs index a0a9051..36d502c 100644 --- a/crates/g3-core/src/feedback_extraction.rs +++ b/crates/g3-core/src/feedback_extraction.rs @@ -306,12 +306,12 @@ fn try_extract_anthropic_tool_use(response: &str) -> Option { if let Some(json_str) = extract_balanced_json(&response[start..]) { if let Ok(blocks) = serde_json::from_str::>(&json_str) { for block in blocks { - if block.get("type").and_then(|v| v.as_str()) == Some("tool_use") { - if block.get("name").and_then(|v| v.as_str()) == Some("final_output") { - if let Some(input) = block.get("input") { - if let Some(summary) = input.get("summary").and_then(|v| v.as_str()) { - return Some(summary.to_string()); - } + if block.get("type").and_then(|v| v.as_str()) == Some("tool_use") + && block.get("name").and_then(|v| v.as_str()) == Some("final_output") + { + if let Some(input) = block.get("input") { + if let Some(summary) = input.get("summary").and_then(|v| v.as_str()) { + return Some(summary.to_string()); } } } @@ -427,12 +427,12 @@ fn extract_final_output_from_messages(messages: &[Value]) -> Option { } } else if let Some(content_array) = content.as_array() { for block in content_array { - if block.get("type").and_then(|v| v.as_str()) == Some("tool_use") { - if block.get("name").and_then(|v| v.as_str()) == Some("final_output") { - if let Some(input) = block.get("input") { - if let Some(summary) = input.get("summary").and_then(|v| v.as_str()) { - return Some(summary.to_string()); - } + if block.get("type").and_then(|v| v.as_str()) == Some("tool_use") + && block.get("name").and_then(|v| v.as_str()) == Some("final_output") + { + if let Some(input) = block.get("input") { + if let Some(summary) = input.get("summary").and_then(|v| v.as_str()) { + return Some(summary.to_string()); } } } @@ -468,10 +468,10 @@ fn is_final_output_tool_call(msg: &Value) -> bool { // Check array content (native tool calling) if let Some(content_array) = content.as_array() { for block in content_array { - if block.get("type").and_then(|v| v.as_str()) == Some("tool_use") { - if block.get("name").and_then(|v| v.as_str()) == Some("final_output") { - return true; - } + if block.get("type").and_then(|v| v.as_str()) == Some("tool_use") + && block.get("name").and_then(|v| v.as_str()) == Some("final_output") + { + return true; } } } diff --git a/crates/g3-core/src/tools/todo.rs b/crates/g3-core/src/tools/todo.rs index 67164c2..2571e04 100644 --- a/crates/g3-core/src/tools/todo.rs +++ b/crates/g3-core/src/tools/todo.rs @@ -92,24 +92,23 @@ pub async fn execute_todo_write( if !in_planner_mode && !has_incomplete && (content_str.contains("- [x]") || content_str.contains("- [X]")) + && todo_path.exists() { - if todo_path.exists() { - match std::fs::remove_file(&todo_path) { - Ok(_) => { - let mut todo = ctx.todo_content.write().await; - *todo = String::new(); - // Show the final completed TODOs before deletion - let mut result = - String::from("✅ All TODOs completed! Removed todo.g3.md\n\nFinal status:\n"); - for line in content_str.lines() { - ctx.ui_writer.print_tool_output_line(line); - result.push_str(line); - result.push('\n'); - } - return Ok(result); + match std::fs::remove_file(&todo_path) { + Ok(_) => { + let mut todo = ctx.todo_content.write().await; + *todo = String::new(); + // Show the final completed TODOs before deletion + let mut result = + String::from("✅ All TODOs completed! Removed todo.g3.md\n\nFinal status:\n"); + for line in content_str.lines() { + ctx.ui_writer.print_tool_output_line(line); + result.push_str(line); + result.push('\n'); } - Err(e) => return Ok(format!("❌ Failed to remove todo.g3.md: {}", e)), + return Ok(result); } + Err(e) => return Ok(format!("❌ Failed to remove todo.g3.md: {}", e)), } }