feat: enhance strictness of Rust compiler settings and improve code quality by treating warnings as errors
This commit is contained in:
@@ -151,7 +151,7 @@ fn detect_claude_settings_provider() -> Option<ProviderConfig> {
|
||||
let settings: ClaudeSettings = serde_json::from_str(&content).ok()?;
|
||||
let env = settings.env?;
|
||||
let base_url = env.anthropic_base_url?;
|
||||
let _api_key = env.anthropic_api_key?; // presence check — stored as env var, not in config.
|
||||
let _ = env.anthropic_api_key?; // presence check — stored as env var, not in config.
|
||||
Some(ProviderConfig {
|
||||
api_base: base_url,
|
||||
api_key_env: Some("ANTHROPIC_API_KEY".to_string()),
|
||||
|
||||
@@ -27,8 +27,6 @@ const MAX_MEMORY_ENTRIES: usize = 10_000;
|
||||
pub struct EditLog {
|
||||
pub entries: Vec<EditLogEntry>,
|
||||
pub path: std::path::PathBuf,
|
||||
/// Total entries on disk (may exceed `entries.len()` if truncated).
|
||||
pub total_on_disk: usize,
|
||||
}
|
||||
|
||||
impl EditLog {
|
||||
@@ -37,28 +35,26 @@ impl EditLog {
|
||||
/// `MAX_MEMORY_ENTRIES` to prevent OOM).
|
||||
pub fn new(session_dir: &std::path::Path) -> Self {
|
||||
let path = session_dir.join("edits.jsonl");
|
||||
let (entries, total_on_disk) = Self::load_from_disk(&path);
|
||||
EditLog { entries, path, total_on_disk }
|
||||
let entries = Self::load_from_disk(&path);
|
||||
EditLog { entries, path }
|
||||
}
|
||||
|
||||
/// Reads lines of edits.jsonl into memory, keeping only the most recent
|
||||
/// `MAX_MEMORY_ENTRIES` entries. The full history is preserved on disk
|
||||
/// regardless of the in-memory limit.
|
||||
fn load_from_disk(path: &std::path::Path) -> (Vec<EditLogEntry>, usize) {
|
||||
fn load_from_disk(path: &std::path::Path) -> Vec<EditLogEntry> {
|
||||
let file = match std::fs::File::open(path) {
|
||||
Ok(f) => f,
|
||||
Err(_) => return (Vec::new(), 0),
|
||||
Err(_) => return Vec::new(),
|
||||
};
|
||||
use std::io::{BufRead, BufReader};
|
||||
let reader = BufReader::new(file);
|
||||
let mut entries: Vec<EditLogEntry> = Vec::new();
|
||||
let mut total = 0usize;
|
||||
for line in reader.lines() {
|
||||
let line = match line {
|
||||
Ok(l) => l,
|
||||
Err(_) => continue,
|
||||
};
|
||||
total += 1;
|
||||
if let Ok(entry) = serde_json::from_str::<EditLogEntry>(&line) {
|
||||
// Keep only the most recent entries in memory
|
||||
if entries.len() >= MAX_MEMORY_ENTRIES {
|
||||
@@ -68,7 +64,7 @@ impl EditLog {
|
||||
entries.push(entry);
|
||||
}
|
||||
}
|
||||
(entries, total)
|
||||
entries
|
||||
}
|
||||
|
||||
/// Append one entry to `edits.jsonl` on disk and to the in-memory log,
|
||||
|
||||
@@ -226,6 +226,7 @@ pub fn slug_path(memory_dir: &Path, raw: &str) -> PathBuf {
|
||||
///
|
||||
/// Return: `Ok(())` on success, or an `io::Error` from serialization or
|
||||
/// the write.
|
||||
#[cfg(test)]
|
||||
pub fn export_lessons(memory_dir: &Path, output: &Path) -> std::io::Result<()> {
|
||||
let names = Memory::list(memory_dir);
|
||||
let lessons: Vec<Memory> = names.iter()
|
||||
@@ -255,6 +256,7 @@ pub fn export_lessons(memory_dir: &Path, output: &Path) -> std::io::Result<()> {
|
||||
/// import on the same file won't overwrite or duplicate existing memories.
|
||||
///
|
||||
/// Return: the number of memories actually imported (skips existing ones).
|
||||
#[cfg(test)]
|
||||
pub fn import_lessons(memory_dir: &Path, input: &Path) -> std::io::Result<usize> {
|
||||
let data = std::fs::read_to_string(input)?;
|
||||
let lessons: Vec<Memory> = serde_json::from_str(&data)
|
||||
|
||||
Reference in New Issue
Block a user