chore: fix clippy lints and suppress dead_code warnings
This commit is contained in:
parent
5ef89cd667
commit
ac2c1e0fe0
@ -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::<usize>() {
|
||||
if (1024..=10_000_000).contains(&n) {
|
||||
if let Some(num_str) = find_number_nearby(after, 50)
|
||||
&& let Ok(n) = num_str.parse::<usize>()
|
||||
&& (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::<usize>() {
|
||||
if (1024..=10_000_000).contains(&n)
|
||||
if let Some(num_str) = find_number_nearby(&lower, lower.len())
|
||||
&& let Ok(n) = num_str.parse::<usize>()
|
||||
&& (1024..=10_000_000).contains(&n)
|
||||
&& (lower.contains("token") || lower.contains("context") || lower.contains("limit"))
|
||||
{
|
||||
return Some(n);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
None
|
||||
}
|
||||
|
||||
@ -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() {
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
#![allow(dead_code)]
|
||||
use crate::protocol::{SessionSummary, SlashCommandInfo};
|
||||
use std::collections::VecDeque;
|
||||
use tokio_tungstenite::tungstenite::Message;
|
||||
|
||||
@ -1,3 +1,5 @@
|
||||
#![allow(dead_code)]
|
||||
|
||||
pub fn render_markdown(content: &str) -> String {
|
||||
content.to_string()
|
||||
}
|
||||
|
||||
@ -134,6 +134,7 @@ enum AnthropicContent {
|
||||
},
|
||||
Thinking {
|
||||
#[serde(alias = "content")]
|
||||
#[allow(dead_code)]
|
||||
thinking: String,
|
||||
},
|
||||
#[serde(rename = "tool_use")]
|
||||
|
||||
@ -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)
|
||||
}
|
||||
|
||||
@ -64,6 +64,7 @@ pub struct Session {
|
||||
/// Messages before this time have been compressed into memory.
|
||||
pub last_consolidated_at: Option<i64>,
|
||||
pub last_compressed_message_at: Option<i64>,
|
||||
#[allow(dead_code)]
|
||||
memory_manager: Arc<crate::memory::MemoryManager>,
|
||||
}
|
||||
|
||||
@ -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(),
|
||||
|
||||
@ -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();
|
||||
|
||||
|
||||
@ -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() {
|
||||
|
||||
@ -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(());
|
||||
}
|
||||
|
||||
@ -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"),
|
||||
);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user