Skip to main content

lean_ctx/core/config/
solution.rs

1use serde::{Deserialize, Serialize};
2
3/// Controls how strongly solution-efficiency guidance is applied.
4#[derive(Default, Serialize, Deserialize, Clone, Debug)]
5#[serde(rename_all = "lowercase")]
6pub enum SolutionIntensity {
7    #[serde(alias = "Off")]
8    Off,
9    #[serde(alias = "Minimal")]
10    Minimal,
11    #[default]
12    #[serde(alias = "Balanced")]
13    Balanced,
14    #[serde(alias = "Aggressive")]
15    Aggressive,
16}
17
18impl SolutionIntensity {
19    pub fn label(&self) -> &'static str {
20        match self {
21            Self::Off => "off",
22            Self::Minimal => "minimal",
23            Self::Balanced => "balanced",
24            Self::Aggressive => "aggressive",
25        }
26    }
27}
28
29static OFF_INTENSITY: SolutionIntensity = SolutionIntensity::Off;
30
31/// Configuration for solution-efficiency guidance.
32#[derive(Serialize, Deserialize, Clone, Debug)]
33#[serde(default)]
34pub struct SolutionConfig {
35    #[serde(default = "default_true")]
36    pub enabled: bool,
37    pub intensity: SolutionIntensity,
38    #[serde(default = "default_true")]
39    pub inject_in_instructions: bool,
40    #[serde(default = "default_true")]
41    pub inject_in_compose: bool,
42    #[serde(default = "default_true")]
43    pub inject_in_subagents: bool,
44    #[serde(default = "default_true")]
45    pub track_decisions: bool,
46    #[serde(default = "default_true")]
47    pub track_loc: bool,
48    #[serde(default = "default_true")]
49    pub platform_hints: bool,
50}
51
52const fn default_true() -> bool {
53    true
54}
55
56impl Default for SolutionConfig {
57    fn default() -> Self {
58        Self {
59            enabled: true,
60            intensity: SolutionIntensity::Balanced,
61            inject_in_instructions: true,
62            inject_in_compose: true,
63            inject_in_subagents: true,
64            track_decisions: true,
65            track_loc: true,
66            platform_hints: true,
67        }
68    }
69}
70
71impl SolutionConfig {
72    pub fn effective_intensity(&self) -> &SolutionIntensity {
73        if self.enabled {
74            &self.intensity
75        } else {
76            &OFF_INTENSITY
77        }
78    }
79
80    pub fn ladder_text(&self) -> &'static str {
81        const BALANCED: &str = "Solution efficiency ladder:\n\
821. YAGNI: is this needed at all?\n\
832. Reuse: does this codebase already provide it?\n\
843. Stdlib: can the standard library handle it?\n\
854. Native: use the platform's built-in capability.\n\
865. Dependency: use an already-installed dependency before adding one.\n\
876. One-line: can the correct solution be one line?\n\
887. Minimum: otherwise implement the minimum working code.\n\
89Preserve validation, security, and error-handling.";
90        const AGGRESSIVE: &str = "challenge every requirement, prefer deletion.\n\n\
91Solution efficiency ladder:\n\
921. YAGNI: is this needed at all?\n\
932. Reuse: does this codebase already provide it?\n\
943. Stdlib: can the standard library handle it?\n\
954. Native: use the platform's built-in capability.\n\
965. Dependency: use an already-installed dependency before adding one.\n\
976. One-line: can the correct solution be one line?\n\
987. Minimum: otherwise implement the minimum working code.\n\
99Preserve validation, security, and error-handling.";
100
101        match self.effective_intensity() {
102            SolutionIntensity::Off => "",
103            SolutionIntensity::Minimal => {
104                "Prefer stdlib and native platform alternatives before adding code or dependencies."
105            }
106            SolutionIntensity::Balanced => BALANCED,
107            SolutionIntensity::Aggressive => AGGRESSIVE,
108        }
109    }
110}