midden 0.8.1

Resolve, audit, visualize, and clean coding-agent context and state
/// Format a byte count for human consumption. Always KiB at one decimal,
/// since we only use this for `.claude.json` size deltas. The divisor is
/// 1024, so the label says KiB — human_bytes already does.
pub fn kb(bytes: usize) -> String {
    format!("{:.1} KiB", bytes as f64 / 1024.0)
}

pub fn human_bytes(bytes: u64) -> String {
    const UNITS: [&str; 5] = ["B", "KiB", "MiB", "GiB", "TiB"];

    if bytes < 1024 {
        return format!("{bytes} B");
    }

    let mut value = bytes as f64;
    let mut unit = 0;
    while value >= 1024.0 && unit < UNITS.len() - 1 {
        value /= 1024.0;
        unit += 1;
    }

    format!("{value:.1} {}", UNITS[unit])
}

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

    #[test]
    fn human_bytes_scales_units() {
        assert_eq!(human_bytes(512), "512 B");
        assert_eq!(human_bytes(1024), "1.0 KiB");
        assert_eq!(human_bytes(150 * 1024 * 1024), "150.0 MiB");
        assert_eq!(human_bytes(3 * 1024 * 1024 * 1024), "3.0 GiB");
    }
}