pub mod cache;
pub mod hash;
pub mod intensity;
pub mod redundancy;
pub mod summarize;
pub mod transcript;

pub use cache::SessionContext;
pub use intensity::Intensity;

use crate::config::Config;
use std::path::Path;

/// Pre-pass: load context, derive intensity from current usage, return a
/// scaled clone of the user's config to use for this single call.
pub fn pre_pass(
    cfg: &Config,
    sessions_dir: &Path,
    used_tokens: u64,
) -> (SessionContext, Intensity, Config) {
    let mut ctx = if cfg.context_cache_enabled {
        SessionContext::load(sessions_dir)
    } else {
        SessionContext::default()
    };
    // Phase 5: apply configurable tunables so all methods use user's values.
    ctx.init_tunables_from_config(cfg);
    // Real-context tracking (CF-1): squeez's own accounting only counts bytes
    // it processed; the transcript-measured context (when observed via hooks)
    // is authoritative. Use whichever signal is larger so intensity escalates
    // in MCP/image-heavy sessions squeez's byte counters never see.
    let effective_used = used_tokens.max(ctx.real_ctx_tokens);
    let level = intensity::derive(effective_used, cfg);
    let scaled = intensity::scale(cfg, level);
    (ctx, level, scaled)
}
