lean-ctx 2.12.7

Context Intelligence Engine with CCP. 24 MCP tools, 90+ compression patterns, cross-session memory (CCP), persistent AI knowledge, multi-agent sharing, LITM-aware positioning. Supports 18+ AI tools. Reduces LLM token consumption by up to 99%.
Documentation
use crate::core::cache::SessionCache;
use crate::core::tokens::count_tokens;
use crate::tools::ctx_read;
use crate::tools::CrpMode;

pub fn handle(cache: &mut SessionCache, paths: &[String], mode: &str, crp_mode: CrpMode) -> String {
    let n = paths.len();
    if n == 0 {
        return "Read 0 files | 0 tokens saved".to_string();
    }

    let mut sections: Vec<String> = Vec::with_capacity(n);
    let mut total_saved: usize = 0;
    let mut total_original: usize = 0;

    for path in paths {
        let chunk = ctx_read::handle(cache, path, mode, crp_mode);
        let original = cache.get(path).map(|e| e.original_tokens).unwrap_or(0);
        let sent = count_tokens(&chunk);
        total_original = total_original.saturating_add(original);
        total_saved = total_saved.saturating_add(original.saturating_sub(sent));
        sections.push(chunk);
    }

    let body = sections.join("\n---\n");
    let summary = format!("Read {n} files | {total_saved} tokens saved");
    format!("{body}\n---\n{summary}")
}