lean-ctx 3.3.0

Context Runtime for AI Agents with CCP. 46 MCP tools, 10 read modes, 90+ compression patterns, cross-session memory (CCP), persistent AI knowledge with temporal facts + contradiction detection, multi-agent context sharing + diaries, 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
use std::path::Path;

use crate::core::handoff_ledger::HandoffLedgerV1;

pub fn format_created(path: &Path, ledger: &HandoffLedgerV1) -> String {
    let wf = ledger
        .workflow
        .as_ref()
        .map(|w| format!("{}@{}", w.spec.name, w.current))
        .unwrap_or_else(|| "none".to_string());
    format!(
        "ctx_handoff create\n path: {}\n md5: {}\n manifest_md5: {}\n workflow: {}\n evidence_keys: {}\n curated_refs: {}\n knowledge_facts: {}",
        path.display(),
        ledger.content_md5,
        ledger.manifest_md5,
        wf,
        ledger.evidence_keys.len(),
        ledger.curated_refs.len(),
        ledger.knowledge.facts.len()
    )
}

pub fn format_list(items: &[std::path::PathBuf]) -> String {
    if items.is_empty() {
        return "No handoff ledgers found.".to_string();
    }
    let mut lines = vec![format!("Handoff Ledgers ({}):", items.len())];
    for (i, p) in items.iter().take(20).enumerate() {
        lines.push(format!("  {}. {}", i + 1, p.display()));
    }
    lines.join("\n")
}

pub fn format_show(path: &Path, ledger: &HandoffLedgerV1) -> String {
    let mut out = serde_json::to_string_pretty(ledger).unwrap_or_else(|_| "{}".to_string());
    out.push('\n');
    format!("ctx_handoff show\n path: {}\n{}", path.display(), out)
}

pub fn format_clear(removed: u32) -> String {
    format!("ctx_handoff clear\n removed: {removed}")
}