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());
|
declared.insert(tc.id.clone());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if messages[i].role == "tool" {
|
} else if messages[i].role == "tool"
|
||||||
if let Some(ref tid) = messages[i].tool_call_id {
|
&& let Some(ref tid) = messages[i].tool_call_id
|
||||||
if !declared.contains(tid.as_str()) {
|
&& !declared.contains(tid.as_str()) {
|
||||||
messages.remove(i);
|
messages.remove(i);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
i += 1;
|
i += 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -299,26 +297,22 @@ impl ContextCompressor {
|
|||||||
if let Some(pos) = lower.find(marker) {
|
if let Some(pos) = lower.find(marker) {
|
||||||
let after = &lower[pos + marker.len()..];
|
let after = &lower[pos + marker.len()..];
|
||||||
// Look for a number in the vicinity (up to 10 chars after marker)
|
// 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 Some(num_str) = find_number_nearby(after, 50)
|
||||||
if let Ok(n) = num_str.parse::<usize>() {
|
&& let Ok(n) = num_str.parse::<usize>()
|
||||||
if (1024..=10_000_000).contains(&n) {
|
&& (1024..=10_000_000).contains(&n) {
|
||||||
return Some(n);
|
return Some(n);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Also try: "XXXX token context" or "XXXX limit"
|
// Also try: "XXXX token context" or "XXXX limit"
|
||||||
if let Some(num_str) = find_number_nearby(&lower, lower.len()) {
|
if let Some(num_str) = find_number_nearby(&lower, lower.len())
|
||||||
if let Ok(n) = num_str.parse::<usize>() {
|
&& let Ok(n) = num_str.parse::<usize>()
|
||||||
if (1024..=10_000_000).contains(&n)
|
&& (1024..=10_000_000).contains(&n)
|
||||||
&& (lower.contains("token") || lower.contains("context") || lower.contains("limit"))
|
&& (lower.contains("token") || lower.contains("context") || lower.contains("limit"))
|
||||||
{
|
{
|
||||||
return Some(n);
|
return Some(n);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|||||||
@ -394,7 +394,6 @@ pub fn build_system_prompt(
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use std::path::PathBuf;
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_builder_creates_sections() {
|
fn test_builder_creates_sections() {
|
||||||
|
|||||||
@ -1,3 +1,4 @@
|
|||||||
|
#![allow(dead_code)]
|
||||||
use crate::protocol::{SessionSummary, SlashCommandInfo};
|
use crate::protocol::{SessionSummary, SlashCommandInfo};
|
||||||
use std::collections::VecDeque;
|
use std::collections::VecDeque;
|
||||||
use tokio_tungstenite::tungstenite::Message;
|
use tokio_tungstenite::tungstenite::Message;
|
||||||
|
|||||||
@ -1,3 +1,5 @@
|
|||||||
|
#![allow(dead_code)]
|
||||||
|
|
||||||
pub fn render_markdown(content: &str) -> String {
|
pub fn render_markdown(content: &str) -> String {
|
||||||
content.to_string()
|
content.to_string()
|
||||||
}
|
}
|
||||||
|
|||||||
@ -134,6 +134,7 @@ enum AnthropicContent {
|
|||||||
},
|
},
|
||||||
Thinking {
|
Thinking {
|
||||||
#[serde(alias = "content")]
|
#[serde(alias = "content")]
|
||||||
|
#[allow(dead_code)]
|
||||||
thinking: String,
|
thinking: String,
|
||||||
},
|
},
|
||||||
#[serde(rename = "tool_use")]
|
#[serde(rename = "tool_use")]
|
||||||
|
|||||||
@ -214,15 +214,14 @@ impl LLMProvider for OpenAIProvider {
|
|||||||
|
|
||||||
if !status.is_success() {
|
if !status.is_success() {
|
||||||
let error = format!("API error {}: {}", status, text);
|
let error = format!("API error {}: {}", status, text);
|
||||||
if let Some(ref storage) = self.storage {
|
if let Some(ref storage) = self.storage
|
||||||
if let Err(e) = storage.append_llm_call(
|
&& let Err(e) = storage.append_llm_call(
|
||||||
&self.name, &self.model_id, &req_body_str,
|
&self.name, &self.model_id, &req_body_str,
|
||||||
Some(&text), Some(&error),
|
Some(&text), Some(&error),
|
||||||
start.elapsed().as_millis() as u64,
|
start.elapsed().as_millis() as u64,
|
||||||
).await {
|
).await {
|
||||||
tracing::warn!("failed to persist LLM call: {}", e);
|
tracing::warn!("failed to persist LLM call: {}", e);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return Err(error.into());
|
return Err(error.into());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -279,15 +278,14 @@ impl LLMProvider for OpenAIProvider {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
if let Some(ref storage) = self.storage {
|
if let Some(ref storage) = self.storage
|
||||||
if let Err(e) = storage.append_llm_call(
|
&& let Err(e) = storage.append_llm_call(
|
||||||
&self.name, &self.model_id, &req_body_str,
|
&self.name, &self.model_id, &req_body_str,
|
||||||
Some(&text), None,
|
Some(&text), None,
|
||||||
start.elapsed().as_millis() as u64,
|
start.elapsed().as_millis() as u64,
|
||||||
).await {
|
).await {
|
||||||
tracing::warn!("failed to persist LLM call: {}", e);
|
tracing::warn!("failed to persist LLM call: {}", e);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
Ok(response)
|
Ok(response)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -64,6 +64,7 @@ pub struct Session {
|
|||||||
/// Messages before this time have been compressed into memory.
|
/// Messages before this time have been compressed into memory.
|
||||||
pub last_consolidated_at: Option<i64>,
|
pub last_consolidated_at: Option<i64>,
|
||||||
pub last_compressed_message_at: Option<i64>,
|
pub last_compressed_message_at: Option<i64>,
|
||||||
|
#[allow(dead_code)]
|
||||||
memory_manager: Arc<crate::memory::MemoryManager>,
|
memory_manager: Arc<crate::memory::MemoryManager>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -516,7 +517,7 @@ impl Session {
|
|||||||
let now = Local::now().format("%Y-%m-%d %H:%M:%S");
|
let now = Local::now().format("%Y-%m-%d %H:%M:%S");
|
||||||
|
|
||||||
let mut md = String::new();
|
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!("- **Session ID**: `{}`\n", self.id));
|
||||||
md.push_str(&format!("- **Channel**: `{}`\n", self.id.channel));
|
md.push_str(&format!("- **Channel**: `{}`\n", self.id.channel));
|
||||||
md.push_str(&format!("- **Chat ID**: `{}`\n", self.id.chat_id));
|
md.push_str(&format!("- **Chat ID**: `{}`\n", self.id.chat_id));
|
||||||
@ -549,7 +550,7 @@ impl Session {
|
|||||||
md.push_str("```\n");
|
md.push_str("```\n");
|
||||||
|
|
||||||
if let Some(ref tool_calls) = msg.tool_calls {
|
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 {
|
for tc in tool_calls {
|
||||||
md.push_str(&format!("- {}: {:?}\n", tc.name, tc.arguments));
|
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()
|
self.inner.lock().await.current_sessions.get(&chat_scope).cloned()
|
||||||
};
|
};
|
||||||
|
|
||||||
if let Some(ref current_id) = current_id {
|
if let Some(ref current_id) = current_id
|
||||||
if let Ok(_) = self.storage.get_session(current_id).await {
|
&& let Ok(_) = self.storage.get_session(current_id).await {
|
||||||
let parts: Vec<&str> = current_id.split(':').collect();
|
let parts: Vec<&str> = current_id.split(':').collect();
|
||||||
if parts.len() == 3 {
|
if parts.len() == 3 {
|
||||||
return Ok(UnifiedSessionId::new(channel, chat_id, parts[2]));
|
return Ok(UnifiedSessionId::new(channel, chat_id, parts[2]));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
match self.storage.find_most_recent_session(channel, chat_id).await {
|
match self.storage.find_most_recent_session(channel, chat_id).await {
|
||||||
Ok(Some(meta)) => Ok(UnifiedSessionId::new(channel, chat_id, &meta.dialog_id)),
|
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
|
session_guard.add_message(user_message, true).await
|
||||||
.map_err(|e| AgentError::Other(format!("persist error: {}", e)))?;
|
.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
|
// Build skills prompt
|
||||||
let skills_prompt = self.skills_loader.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
|
session_guard.add_message(user_message, true).await
|
||||||
.map_err(|e| AgentError::Other(format!("persist error: {}", e)))?;
|
.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 skills_prompt = self.skills_loader.build_skills_prompt();
|
||||||
let system_prompt = session_guard.build_system_prompt(&skills_prompt, None);
|
let system_prompt = session_guard.build_system_prompt(&skills_prompt, None);
|
||||||
@ -1663,6 +1663,7 @@ mod tests {
|
|||||||
use super::*;
|
use super::*;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
fn test_provider_config() -> LLMProviderConfig {
|
fn test_provider_config() -> LLMProviderConfig {
|
||||||
LLMProviderConfig {
|
LLMProviderConfig {
|
||||||
provider_type: "openai".to_string(),
|
provider_type: "openai".to_string(),
|
||||||
|
|||||||
@ -115,8 +115,8 @@ impl SkillsLoader {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Load from workspace ./skills (if set)
|
// Load from workspace ./skills (if set)
|
||||||
if let Some(ref ws_dir) = self.workspace_skills_dir {
|
if let Some(ref ws_dir) = self.workspace_skills_dir
|
||||||
if ws_dir.exists() {
|
&& ws_dir.exists() {
|
||||||
let loaded = self.load_skills_from_dir(ws_dir);
|
let loaded = self.load_skills_from_dir(ws_dir);
|
||||||
tracing::debug!(
|
tracing::debug!(
|
||||||
dir = %ws_dir.display(),
|
dir = %ws_dir.display(),
|
||||||
@ -126,7 +126,6 @@ impl SkillsLoader {
|
|||||||
state.loaded_skills.extend(loaded);
|
state.loaded_skills.extend(loaded);
|
||||||
state.last_workspace_mtime = Self::get_dir_mtime(ws_dir);
|
state.last_workspace_mtime = Self::get_dir_mtime(ws_dir);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
state.last_load_time = SystemTime::now();
|
state.last_load_time = SystemTime::now();
|
||||||
|
|
||||||
|
|||||||
@ -349,20 +349,17 @@ fn grep_dir(
|
|||||||
};
|
};
|
||||||
|
|
||||||
if path.is_dir() {
|
if path.is_dir() {
|
||||||
if let Some(name) = rel.file_name().and_then(|n| n.to_str()) {
|
if let Some(name) = rel.file_name().and_then(|n| n.to_str())
|
||||||
if name.starts_with('.') && name.len() > 1 {
|
&& name.starts_with('.') && name.len() > 1 {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
grep_dir(base, &path, re, file_re, results, max)?;
|
grep_dir(base, &path, re, file_re, results, max)?;
|
||||||
} else if path.is_file() {
|
} else if path.is_file() {
|
||||||
if let Some(file_re) = file_re {
|
if let Some(file_re) = file_re
|
||||||
if let Some(name) = rel.file_name().and_then(|n| n.to_str()) {
|
&& let Some(name) = rel.file_name().and_then(|n| n.to_str())
|
||||||
if !file_re.is_match(name) {
|
&& !file_re.is_match(name) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if let Ok(content) = std::fs::read_to_string(&path) {
|
if let Ok(content) = std::fs::read_to_string(&path) {
|
||||||
for (line_num, line) in content.lines().enumerate() {
|
for (line_num, line) in content.lines().enumerate() {
|
||||||
|
|||||||
@ -301,18 +301,16 @@ fn walk_dir(
|
|||||||
};
|
};
|
||||||
|
|
||||||
if path.is_dir() {
|
if path.is_dir() {
|
||||||
if let Some(name) = rel.file_name().and_then(|n| n.to_str()) {
|
if let Some(name) = rel.file_name().and_then(|n| n.to_str())
|
||||||
if name.starts_with('.') && name.len() > 1 {
|
&& name.starts_with('.') && name.len() > 1 {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
walk_dir(base, &path, re, results, max)?;
|
walk_dir(base, &path, re, results, max)?;
|
||||||
} else if path.is_file() {
|
} else if path.is_file() {
|
||||||
if let Some(name) = rel.file_name().and_then(|n| n.to_str()) {
|
if let Some(name) = rel.file_name().and_then(|n| n.to_str())
|
||||||
if re.is_match(name) {
|
&& re.is_match(name) {
|
||||||
results.push(rel.to_string_lossy().to_string());
|
results.push(rel.to_string_lossy().to_string());
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if results.len() >= max {
|
if results.len() >= max {
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|||||||
@ -168,7 +168,7 @@ mod tests {
|
|||||||
writeln!(skill_file, "# Test Skill").unwrap();
|
writeln!(skill_file, "# Test Skill").unwrap();
|
||||||
writeln!(skill_file, "This is the test content.").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(),
|
temp_dir.path().to_path_buf(),
|
||||||
PathBuf::from("/nonexistent"),
|
PathBuf::from("/nonexistent"),
|
||||||
);
|
);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user