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
This commit is contained in:
@@ -306,8 +306,9 @@ fn try_extract_anthropic_tool_use(response: &str) -> Option<String> {
|
||||
if let Some(json_str) = extract_balanced_json(&response[start..]) {
|
||||
if let Ok(blocks) = serde_json::from_str::<Vec<Value>>(&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 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());
|
||||
@@ -318,7 +319,6 @@ fn try_extract_anthropic_tool_use(response: &str) -> Option<String> {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
None
|
||||
}
|
||||
@@ -427,8 +427,9 @@ fn extract_final_output_from_messages(messages: &[Value]) -> Option<String> {
|
||||
}
|
||||
} 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 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());
|
||||
@@ -440,7 +441,6 @@ fn extract_final_output_from_messages(messages: &[Value]) -> Option<String> {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
None
|
||||
}
|
||||
@@ -468,14 +468,14 @@ 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") {
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Check tool_calls field (OpenAI format)
|
||||
if let Some(tool_calls) = msg.get("tool_calls").and_then(|v| v.as_array()) {
|
||||
|
||||
@@ -92,8 +92,8 @@ pub async fn execute_todo_write<W: UiWriter>(
|
||||
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;
|
||||
@@ -111,7 +111,6 @@ pub async fn execute_todo_write<W: UiWriter>(
|
||||
Err(e) => return Ok(format!("❌ Failed to remove todo.g3.md: {}", e)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
match std::fs::write(&todo_path, content_str) {
|
||||
Ok(_) => {
|
||||
|
||||
Reference in New Issue
Block a user