Skip to main content

skiagram_core/analysis/
mod.rs

1//! Token-accounting analysis passes over the normalized model.
2
3pub mod aggregate;
4pub mod anomaly;
5pub mod classify;
6pub mod context;
7pub mod dedup;
8pub mod drilldown;
9pub mod flame;
10
11use jiff::civil::Date;
12use jiff::{tz::TimeZone, Timestamp};
13
14/// Civil date used for day bucketing and `--since`.
15///
16/// UTC on purpose: deterministic across machines/timezones. TODO(scope):
17/// local-timezone day option.
18pub(crate) fn utc_date(ts: Timestamp) -> Date {
19    ts.to_zoned(TimeZone::UTC).date()
20}
21
22/// Rough chars-per-token ratio for English/code. ONLY used for heuristics and
23/// the context-bloat ESTIMATE — NEVER for billing (billing always uses the
24/// agent-reported token counts; CLAUDE.md §8.7).
25pub(crate) const EST_CHARS_PER_TOKEN: u64 = 4;
26
27/// Estimate tokens from a char count. Estimate only — never a billed figure.
28pub(crate) fn est_tokens(chars: u64) -> u64 {
29    chars / EST_CHARS_PER_TOKEN
30}