lean-ctx 3.9.16

Context Runtime for AI Agents with CCP. 71 MCP tools, 10 read modes, 95+ compression patterns, cross-session memory (CCP), persistent AI knowledge with temporal facts + contradiction detection, multi-agent context sharing, LITM-aware positioning, AAAK compact format, adaptive compression with Thompson Sampling bandits. Supports 24+ AI tools. Reduces LLM token consumption by up to 99%.
Documentation
//! Cost metrics for benchmark comparison.

/// Cost per 1000 prompts.
pub(crate) fn cost_per_1k(total_cost_usd: f64, total_tasks: usize) -> f64 {
    if total_tasks == 0 {
        return 0.0;
    }
    total_cost_usd / total_tasks as f64 * 1000.0
}

/// Cost savings as a percentage.
pub(crate) fn savings_pct(baseline_cost: f64, treatment_cost: f64) -> f64 {
    if baseline_cost <= 0.0 {
        return 0.0;
    }
    (1.0 - treatment_cost / baseline_cost) * 100.0
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn savings_50_pct() {
        assert!((savings_pct(100.0, 50.0) - 50.0).abs() < 1e-9);
    }

    #[test]
    fn savings_zero_baseline() {
        assert_eq!(savings_pct(0.0, 50.0), 0.0);
    }
}