zagens_core/engine/context_snapshot.rs
1//! Thread-level context usage snapshot โ pure data type (M1 โ `zagens-core`).
2//!
3//! The companion `build_thread_context_snapshot` helper still lives in
4//! `crates/tui/src/context_snapshot.rs` because it depends on the tui-only
5//! `compaction::should_compact` (which is ~1k LOC of tui-specific working-set
6//! / pinning logic). Moving the helper would require dragging that whole
7//! chain into core โ out of scope for M1 (see `PR_M0_ENGINE_STRUCT_TO_CORE_SPIKE`
8//! ยง1.2). Only the wire-shape struct moves here so `Op::QueryContext.reply`
9//! can be a core type.
10
11use serde::{Deserialize, Serialize};
12
13/// Context fill + compaction policy snapshot for a thread.
14#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
15pub struct ThreadContextSnapshot {
16 /// Conservative estimate (`estimate_input_tokens_conservative`) for
17 /// compaction / overflow.
18 pub estimated_input_tokens: usize,
19 pub context_window_tokens: u32,
20 /// Percent from conservative estimate (primary UI ring).
21 pub usage_percent: f64,
22 pub message_count: usize,
23 pub compaction_enabled: bool,
24 pub compaction_threshold_tokens: usize,
25 pub compaction_floor_tokens: usize,
26 pub should_compact: bool,
27 /// Provider `usage.input_tokens` from the last API round (authoritative
28 /// per DeepSeek docs).
29 pub last_api_input_tokens: Option<u32>,
30 /// Percent from `last_api_input_tokens` when present.
31 pub last_api_usage_percent: Option<f64>,
32 /// Deprecated: last turn's **summed** `usage.input_tokens` (multi-round
33 /// turns inflate).
34 pub last_reported_input_tokens: Option<u32>,
35 /// `engine` when read from a loaded engine; `store` when reconstructed
36 /// from persisted turns.
37 pub source: String,
38}