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