lean_ctx/core/config/
value_display.rs1use serde::{Deserialize, Serialize};
7
8#[derive(Debug, Clone, Copy, Default, Serialize, Deserialize, PartialEq, Eq)]
16#[serde(rename_all = "lowercase")]
17pub enum ValueDisplayMode {
18 Off,
19 #[default]
20 Minimal,
21 Milestones,
22 Verbose,
23}
24
25impl ValueDisplayMode {
26 pub fn parse(value: &str) -> Option<Self> {
27 match value.trim().to_ascii_lowercase().as_str() {
28 "off" | "0" | "false" | "none" => Some(Self::Off),
29 "minimal" | "on" | "1" | "true" => Some(Self::Minimal),
30 "milestones" => Some(Self::Milestones),
31 "verbose" => Some(Self::Verbose),
32 _ => None,
33 }
34 }
35}
36
37#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
38#[serde(default)]
39pub struct ValueDisplayConfig {
40 pub mode: ValueDisplayMode,
42 pub recap_every_turns: u32,
44 pub recap_min_tokens: u64,
47 pub notifications: bool,
50 pub git_trailer: bool,
52}
53
54impl Default for ValueDisplayConfig {
55 fn default() -> Self {
56 Self {
57 mode: ValueDisplayMode::default(),
58 recap_every_turns: 10,
59 recap_min_tokens: 50_000,
60 notifications: true,
61 git_trailer: false,
62 }
63 }
64}
65
66impl ValueDisplayConfig {
67 pub fn effective_mode(&self) -> ValueDisplayMode {
69 std::env::var("LEAN_CTX_VALUE_DISPLAY")
70 .ok()
71 .and_then(|v| ValueDisplayMode::parse(&v))
72 .unwrap_or(self.mode)
73 }
74}
75
76#[cfg(test)]
77mod tests {
78 use super::*;
79
80 #[test]
81 fn defaults_are_subtle_and_on() {
82 let cfg: ValueDisplayConfig = toml::from_str("").unwrap();
83 assert_eq!(cfg, ValueDisplayConfig::default());
84 assert_eq!(cfg.mode, ValueDisplayMode::Minimal);
85 assert!(!cfg.git_trailer);
86 }
87
88 #[test]
89 fn parses_toml_section() {
90 let cfg: ValueDisplayConfig =
91 toml::from_str("mode = \"off\"\nrecap_every_turns = 5").unwrap();
92 assert_eq!(cfg.mode, ValueDisplayMode::Off);
93 assert_eq!(cfg.recap_every_turns, 5);
94 assert_eq!(cfg.recap_min_tokens, 50_000);
95 }
96
97 #[test]
98 fn env_values_parse() {
99 assert_eq!(ValueDisplayMode::parse("OFF"), Some(ValueDisplayMode::Off));
100 assert_eq!(ValueDisplayMode::parse("0"), Some(ValueDisplayMode::Off));
101 assert_eq!(
102 ValueDisplayMode::parse("verbose"),
103 Some(ValueDisplayMode::Verbose)
104 );
105 assert_eq!(ValueDisplayMode::parse("loud"), None);
106 }
107}