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: 5,
62 recap_min_tokens: 10_000,
63 notifications: true,
64 git_trailer: false,
65 }
66 }
67}
68
69impl ValueDisplayConfig {
70 pub fn effective_mode(&self) -> ValueDisplayMode {
72 std::env::var("LEAN_CTX_VALUE_DISPLAY")
73 .ok()
74 .and_then(|v| ValueDisplayMode::parse(&v))
75 .unwrap_or(self.mode)
76 }
77}
78
79#[cfg(test)]
80mod tests {
81 use super::*;
82
83 #[test]
84 fn defaults_are_subtle_and_on() {
85 let cfg: ValueDisplayConfig = toml::from_str("").unwrap();
86 assert_eq!(cfg, ValueDisplayConfig::default());
87 assert_eq!(cfg.mode, ValueDisplayMode::Minimal);
88 assert!(!cfg.git_trailer);
89 }
90
91 #[test]
92 fn parses_toml_section() {
93 let cfg: ValueDisplayConfig =
94 toml::from_str("mode = \"off\"\nrecap_every_turns = 20").unwrap();
95 assert_eq!(cfg.mode, ValueDisplayMode::Off);
96 assert_eq!(cfg.recap_every_turns, 20);
97 assert_eq!(cfg.recap_min_tokens, 10_000);
98 }
99
100 #[test]
101 fn env_values_parse() {
102 assert_eq!(ValueDisplayMode::parse("OFF"), Some(ValueDisplayMode::Off));
103 assert_eq!(ValueDisplayMode::parse("0"), Some(ValueDisplayMode::Off));
104 assert_eq!(
105 ValueDisplayMode::parse("verbose"),
106 Some(ValueDisplayMode::Verbose)
107 );
108 assert_eq!(ValueDisplayMode::parse("loud"), None);
109 }
110}