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    pub commercial: crate::core::solution_commercial::SolutionCommercialConfig,
51}
52
53const fn default_true() -> bool {
54    true
55}
56
57impl Default for SolutionConfig {
58    fn default() -> Self {
59        Self {
60            enabled: true,
61            intensity: SolutionIntensity::Balanced,
62            inject_in_instructions: true,
63            inject_in_compose: true,
64            inject_in_subagents: true,
65            track_decisions: true,
66            track_loc: true,
67            platform_hints: true,
68            commercial: Default::default(),
69        }
70    }
71}
72
73impl SolutionConfig {
74    pub fn effective_intensity(&self) -> &SolutionIntensity {
75        if self.enabled {
76            &self.intensity
77        } else {
78            &OFF_INTENSITY
79        }
80    }
81
82    pub fn ladder_text(&self) -> &'static str {
83        const BALANCED: &str = "Solution efficiency ladder:\n\
841. YAGNI: is this needed at all?\n\
852. Reuse: does this codebase already provide it?\n\
863. Stdlib: can the standard library handle it?\n\
874. Native: use the platform's built-in capability.\n\
885. Dependency: use an already-installed dependency before adding one.\n\
896. One-line: can the correct solution be one line?\n\
907. Minimum: otherwise implement the minimum working code.\n\
91Preserve validation, security, and error-handling.";
92        const AGGRESSIVE: &str = "challenge every requirement, prefer deletion.\n\n\
93Solution efficiency ladder:\n\
941. YAGNI: is this needed at all?\n\
952. Reuse: does this codebase already provide it?\n\
963. Stdlib: can the standard library handle it?\n\
974. Native: use the platform's built-in capability.\n\
985. Dependency: use an already-installed dependency before adding one.\n\
996. One-line: can the correct solution be one line?\n\
1007. Minimum: otherwise implement the minimum working code.\n\
101Preserve validation, security, and error-handling.";
102
103        match self.effective_intensity() {
104            SolutionIntensity::Off => "",
105            SolutionIntensity::Minimal => {
106                "Prefer stdlib and native platform alternatives before adding code or dependencies."
107            }
108            SolutionIntensity::Balanced => BALANCED,
109            SolutionIntensity::Aggressive => AGGRESSIVE,
110        }
111    }
112}