diff --git a/src/agent/context_compressor.rs b/src/agent/context_compressor.rs index 3904469..bf9d2b8 100644 --- a/src/agent/context_compressor.rs +++ b/src/agent/context_compressor.rs @@ -163,14 +163,12 @@ impl ContextCompressor { declared.insert(tc.id.clone()); } } - } else if messages[i].role == "tool" { - if let Some(ref tid) = messages[i].tool_call_id { - if !declared.contains(tid.as_str()) { + } else if messages[i].role == "tool" + && let Some(ref tid) = messages[i].tool_call_id + && !declared.contains(tid.as_str()) { messages.remove(i); continue; } - } - } i += 1; } } @@ -299,26 +297,22 @@ impl ContextCompressor { if let Some(pos) = lower.find(marker) { let after = &lower[pos + marker.len()..]; // Look for a number in the vicinity (up to 10 chars after marker) - if let Some(num_str) = find_number_nearby(after, 50) { - if let Ok(n) = num_str.parse::() { - if (1024..=10_000_000).contains(&n) { + if let Some(num_str) = find_number_nearby(after, 50) + && let Ok(n) = num_str.parse::() + && (1024..=10_000_000).contains(&n) { return Some(n); } - } - } } } // Also try: "XXXX token context" or "XXXX limit" - if let Some(num_str) = find_number_nearby(&lower, lower.len()) { - if let Ok(n) = num_str.parse::() { - if (1024..=10_000_000).contains(&n) + if let Some(num_str) = find_number_nearby(&lower, lower.len()) + && let Ok(n) = num_str.parse::() + && (1024..=10_000_000).contains(&n) && (lower.contains("token") || lower.contains("context") || lower.contains("limit")) { return Some(n); } - } - } None } diff --git a/src/agent/system_prompt.rs b/src/agent/system_prompt.rs index 778b906..9eca740 100644 --- a/src/agent/system_prompt.rs +++ b/src/agent/system_prompt.rs @@ -394,7 +394,6 @@ pub fn build_system_prompt( #[cfg(test)] mod tests { use super::*; - use std::path::PathBuf; #[test] fn test_builder_creates_sections() { diff --git a/src/client/tui/app.rs b/src/client/tui/app.rs index f2f2fe3..53e1356 100644 --- a/src/client/tui/app.rs +++ b/src/client/tui/app.rs @@ -1,3 +1,4 @@ +#![allow(dead_code)] use crate::protocol::{SessionSummary, SlashCommandInfo}; use std::collections::VecDeque; use tokio_tungstenite::tungstenite::Message; diff --git a/src/client/tui/markdown.rs b/src/client/tui/markdown.rs index 839d18a..747d802 100644 --- a/src/client/tui/markdown.rs +++ b/src/client/tui/markdown.rs @@ -1,3 +1,5 @@ +#![allow(dead_code)] + pub fn render_markdown(content: &str) -> String { content.to_string() } diff --git a/src/providers/anthropic.rs b/src/providers/anthropic.rs index fd16c55..fe33ada 100644 --- a/src/providers/anthropic.rs +++ b/src/providers/anthropic.rs @@ -134,6 +134,7 @@ enum AnthropicContent { }, Thinking { #[serde(alias = "content")] + #[allow(dead_code)] thinking: String, }, #[serde(rename = "tool_use")] diff --git a/src/providers/openai.rs b/src/providers/openai.rs index 882768f..4fde00c 100644 --- a/src/providers/openai.rs +++ b/src/providers/openai.rs @@ -214,15 +214,14 @@ impl LLMProvider for OpenAIProvider { if !status.is_success() { let error = format!("API error {}: {}", status, text); - if let Some(ref storage) = self.storage { - if let Err(e) = storage.append_llm_call( + if let Some(ref storage) = self.storage + && let Err(e) = storage.append_llm_call( &self.name, &self.model_id, &req_body_str, Some(&text), Some(&error), start.elapsed().as_millis() as u64, ).await { tracing::warn!("failed to persist LLM call: {}", e); } - } return Err(error.into()); } @@ -279,15 +278,14 @@ impl LLMProvider for OpenAIProvider { }, }; - if let Some(ref storage) = self.storage { - if let Err(e) = storage.append_llm_call( + if let Some(ref storage) = self.storage + && let Err(e) = storage.append_llm_call( &self.name, &self.model_id, &req_body_str, Some(&text), None, start.elapsed().as_millis() as u64, ).await { tracing::warn!("failed to persist LLM call: {}", e); } - } Ok(response) } diff --git a/src/session/session.rs b/src/session/session.rs index 4e10128..513ff1e 100644 --- a/src/session/session.rs +++ b/src/session/session.rs @@ -64,6 +64,7 @@ pub struct Session { /// Messages before this time have been compressed into memory. pub last_consolidated_at: Option, pub last_compressed_message_at: Option, + #[allow(dead_code)] memory_manager: Arc, } @@ -516,7 +517,7 @@ impl Session { let now = Local::now().format("%Y-%m-%d %H:%M:%S"); let mut md = String::new(); - md.push_str(&"# Session Dump\n\n".to_string()); + md.push_str("# Session Dump\n\n"); md.push_str(&format!("- **Session ID**: `{}`\n", self.id)); md.push_str(&format!("- **Channel**: `{}`\n", self.id.channel)); md.push_str(&format!("- **Chat ID**: `{}`\n", self.id.chat_id)); @@ -549,7 +550,7 @@ impl Session { md.push_str("```\n"); if let Some(ref tool_calls) = msg.tool_calls { - md.push_str(&"[Tool Calls]\n".to_string()); + md.push_str("[Tool Calls]\n"); for tc in tool_calls { md.push_str(&format!("- {}: {:?}\n", tc.name, tc.arguments)); } @@ -1201,14 +1202,13 @@ impl SessionManager { self.inner.lock().await.current_sessions.get(&chat_scope).cloned() }; - if let Some(ref current_id) = current_id { - if let Ok(_) = self.storage.get_session(current_id).await { + if let Some(ref current_id) = current_id + && let Ok(_) = self.storage.get_session(current_id).await { let parts: Vec<&str> = current_id.split(':').collect(); if parts.len() == 3 { return Ok(UnifiedSessionId::new(channel, chat_id, parts[2])); } } - } match self.storage.find_most_recent_session(channel, chat_id).await { Ok(Some(meta)) => Ok(UnifiedSessionId::new(channel, chat_id, &meta.dialog_id)), @@ -1337,7 +1337,7 @@ impl SessionManager { session_guard.add_message(user_message, true).await .map_err(|e| AgentError::Other(format!("persist error: {}", e)))?; - let mut history = session_guard.get_history().to_vec(); + let history = session_guard.get_history().to_vec(); // Build skills prompt let skills_prompt = self.skills_loader.build_skills_prompt(); @@ -1498,7 +1498,7 @@ impl SessionManager { session_guard.add_message(user_message, true).await .map_err(|e| AgentError::Other(format!("persist error: {}", e)))?; - let mut history = session_guard.get_history().to_vec(); + let history = session_guard.get_history().to_vec(); let skills_prompt = self.skills_loader.build_skills_prompt(); let system_prompt = session_guard.build_system_prompt(&skills_prompt, None); @@ -1663,6 +1663,7 @@ mod tests { use super::*; use std::collections::HashMap; + #[allow(dead_code)] fn test_provider_config() -> LLMProviderConfig { LLMProviderConfig { provider_type: "openai".to_string(), diff --git a/src/skills/mod.rs b/src/skills/mod.rs index fafff88..3a23748 100644 --- a/src/skills/mod.rs +++ b/src/skills/mod.rs @@ -115,8 +115,8 @@ impl SkillsLoader { } // Load from workspace ./skills (if set) - if let Some(ref ws_dir) = self.workspace_skills_dir { - if ws_dir.exists() { + if let Some(ref ws_dir) = self.workspace_skills_dir + && ws_dir.exists() { let loaded = self.load_skills_from_dir(ws_dir); tracing::debug!( dir = %ws_dir.display(), @@ -126,7 +126,6 @@ impl SkillsLoader { state.loaded_skills.extend(loaded); state.last_workspace_mtime = Self::get_dir_mtime(ws_dir); } - } state.last_load_time = SystemTime::now(); diff --git a/src/tools/content_search.rs b/src/tools/content_search.rs index 8ba81b9..8cabd81 100644 --- a/src/tools/content_search.rs +++ b/src/tools/content_search.rs @@ -349,20 +349,17 @@ fn grep_dir( }; if path.is_dir() { - if let Some(name) = rel.file_name().and_then(|n| n.to_str()) { - if name.starts_with('.') && name.len() > 1 { + if let Some(name) = rel.file_name().and_then(|n| n.to_str()) + && name.starts_with('.') && name.len() > 1 { continue; } - } grep_dir(base, &path, re, file_re, results, max)?; } else if path.is_file() { - if let Some(file_re) = file_re { - if let Some(name) = rel.file_name().and_then(|n| n.to_str()) { - if !file_re.is_match(name) { + if let Some(file_re) = file_re + && let Some(name) = rel.file_name().and_then(|n| n.to_str()) + && !file_re.is_match(name) { continue; } - } - } if let Ok(content) = std::fs::read_to_string(&path) { for (line_num, line) in content.lines().enumerate() { diff --git a/src/tools/file_search.rs b/src/tools/file_search.rs index f547b91..93f5bf7 100644 --- a/src/tools/file_search.rs +++ b/src/tools/file_search.rs @@ -301,18 +301,16 @@ fn walk_dir( }; if path.is_dir() { - if let Some(name) = rel.file_name().and_then(|n| n.to_str()) { - if name.starts_with('.') && name.len() > 1 { + if let Some(name) = rel.file_name().and_then(|n| n.to_str()) + && name.starts_with('.') && name.len() > 1 { continue; } - } walk_dir(base, &path, re, results, max)?; } else if path.is_file() { - if let Some(name) = rel.file_name().and_then(|n| n.to_str()) { - if re.is_match(name) { + if let Some(name) = rel.file_name().and_then(|n| n.to_str()) + && re.is_match(name) { results.push(rel.to_string_lossy().to_string()); } - } if results.len() >= max { return Ok(()); } diff --git a/src/tools/get_skill.rs b/src/tools/get_skill.rs index 22e4588..3250ec0 100644 --- a/src/tools/get_skill.rs +++ b/src/tools/get_skill.rs @@ -168,7 +168,7 @@ mod tests { writeln!(skill_file, "# Test Skill").unwrap(); writeln!(skill_file, "This is the test content.").unwrap(); - let mut loader = SkillsLoader::new_for_testing( + let loader = SkillsLoader::new_for_testing( temp_dir.path().to_path_buf(), PathBuf::from("/nonexistent"), );