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,12 +306,12 @@ fn try_extract_anthropic_tool_use(response: &str) -> Option<String> {
|
|||||||
if let Some(json_str) = extract_balanced_json(&response[start..]) {
|
if let Some(json_str) = extract_balanced_json(&response[start..]) {
|
||||||
if let Ok(blocks) = serde_json::from_str::<Vec<Value>>(&json_str) {
|
if let Ok(blocks) = serde_json::from_str::<Vec<Value>>(&json_str) {
|
||||||
for block in blocks {
|
for block in blocks {
|
||||||
if block.get("type").and_then(|v| v.as_str()) == Some("tool_use") {
|
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") {
|
&& 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()) {
|
if let Some(input) = block.get("input") {
|
||||||
return Some(summary.to_string());
|
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<String> {
|
|||||||
}
|
}
|
||||||
} else if let Some(content_array) = content.as_array() {
|
} else if let Some(content_array) = content.as_array() {
|
||||||
for block in content_array {
|
for block in content_array {
|
||||||
if block.get("type").and_then(|v| v.as_str()) == Some("tool_use") {
|
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") {
|
&& 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()) {
|
if let Some(input) = block.get("input") {
|
||||||
return Some(summary.to_string());
|
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)
|
// Check array content (native tool calling)
|
||||||
if let Some(content_array) = content.as_array() {
|
if let Some(content_array) = content.as_array() {
|
||||||
for block in content_array {
|
for block in content_array {
|
||||||
if block.get("type").and_then(|v| v.as_str()) == Some("tool_use") {
|
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") {
|
&& block.get("name").and_then(|v| v.as_str()) == Some("final_output")
|
||||||
return true;
|
{
|
||||||
}
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -92,24 +92,23 @@ pub async fn execute_todo_write<W: UiWriter>(
|
|||||||
if !in_planner_mode
|
if !in_planner_mode
|
||||||
&& !has_incomplete
|
&& !has_incomplete
|
||||||
&& (content_str.contains("- [x]") || content_str.contains("- [X]"))
|
&& (content_str.contains("- [x]") || content_str.contains("- [X]"))
|
||||||
|
&& todo_path.exists()
|
||||||
{
|
{
|
||||||
if todo_path.exists() {
|
match std::fs::remove_file(&todo_path) {
|
||||||
match std::fs::remove_file(&todo_path) {
|
Ok(_) => {
|
||||||
Ok(_) => {
|
let mut todo = ctx.todo_content.write().await;
|
||||||
let mut todo = ctx.todo_content.write().await;
|
*todo = String::new();
|
||||||
*todo = String::new();
|
// Show the final completed TODOs before deletion
|
||||||
// Show the final completed TODOs before deletion
|
let mut result =
|
||||||
let mut result =
|
String::from("✅ All TODOs completed! Removed todo.g3.md\n\nFinal status:\n");
|
||||||
String::from("✅ All TODOs completed! Removed todo.g3.md\n\nFinal status:\n");
|
for line in content_str.lines() {
|
||||||
for line in content_str.lines() {
|
ctx.ui_writer.print_tool_output_line(line);
|
||||||
ctx.ui_writer.print_tool_output_line(line);
|
result.push_str(line);
|
||||||
result.push_str(line);
|
result.push('\n');
|
||||||
result.push('\n');
|
|
||||||
}
|
|
||||||
return Ok(result);
|
|
||||||
}
|
}
|
||||||
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)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user