Skip to main content

ag_session/
setting.rs

1//! Domain model for persisted application setting keys.
2
3use std::fmt;
4
5/// Whether temporary read-only research waves start without plan approval.
6pub const DEFAULT_AUTO_APPROVE_ORCHESTRATION_RESEARCH: bool = true;
7/// Default number of orchestration children allowed to run concurrently.
8pub const DEFAULT_ORCHESTRATION_PARALLELISM: u8 = 3;
9/// Maximum orchestration concurrency exposed by the settings selector.
10pub const MAX_ORCHESTRATION_PARALLELISM: u8 = 8;
11
12/// Stable keys used in the `setting` and `project_setting` tables.
13#[derive(Clone, Copy, Debug, Eq, PartialEq)]
14pub enum SettingName {
15    /// Persists the active project selection.
16    ActiveProjectId,
17    /// Persists the active list tab selection.
18    ActiveTab,
19    /// Persists whether research-only orchestration waves start immediately.
20    AutoApproveOrchestrationResearch,
21    /// Persists the provider that owns the fast-model default.
22    DefaultFastAgent,
23    /// Persists the project or global fast-model selection.
24    DefaultFastModel,
25    /// Persists the reasoning level paired with the fast-model default.
26    DefaultFastReasoningLevel,
27    /// Persists the response speed paired with the fast-model default.
28    DefaultFastSpeedMode,
29    /// Persists the provider that owns the review-model default.
30    DefaultReviewAgent,
31    /// Persists the project or global review-model selection.
32    DefaultReviewModel,
33    /// Persists the reasoning level paired with the review-model default.
34    DefaultReviewReasoningLevel,
35    /// Persists the response speed paired with the review-model default.
36    DefaultReviewSpeedMode,
37    /// Persists the provider that owns the smart-model default.
38    DefaultSmartAgent,
39    /// Persists the project or global smart-model selection.
40    DefaultSmartModel,
41    /// Persists the reasoning level paired with the smart-model default.
42    DefaultSmartReasoningLevel,
43    /// Persists the response speed paired with the smart-model default.
44    DefaultSmartSpeedMode,
45    /// Persists whether generated session commits append the Agentty coauthor
46    /// trailer.
47    IncludeCoauthoredByAgentty,
48    /// Persists the configured launch-configuration override.
49    LaunchConfiguration,
50    /// Persists whether the last used model should become the default.
51    LastUsedModelAsDefault,
52    /// Persists how many orchestration children may run at once.
53    OrchestrationParallelism,
54    /// Persists the active terminal color theme.
55    Theme,
56}
57
58impl SettingName {
59    /// Returns the persisted key string for one setting.
60    pub fn as_str(self) -> &'static str {
61        match self {
62            Self::ActiveProjectId => "ActiveProjectId",
63            Self::ActiveTab => "ActiveTab",
64            Self::AutoApproveOrchestrationResearch => "AutoApproveOrchestrationResearch",
65            Self::DefaultFastAgent => "DefaultFastAgent",
66            Self::DefaultFastModel => "DefaultFastModel",
67            Self::DefaultFastReasoningLevel => "DefaultFastReasoningLevel",
68            Self::DefaultFastSpeedMode => "DefaultFastSpeedMode",
69            Self::DefaultReviewAgent => "DefaultReviewAgent",
70            Self::DefaultReviewModel => "DefaultReviewModel",
71            Self::DefaultReviewReasoningLevel => "DefaultReviewReasoningLevel",
72            Self::DefaultReviewSpeedMode => "DefaultReviewSpeedMode",
73            Self::DefaultSmartAgent => "DefaultSmartAgent",
74            Self::DefaultSmartModel => "DefaultSmartModel",
75            Self::DefaultSmartReasoningLevel => "DefaultSmartReasoningLevel",
76            Self::DefaultSmartSpeedMode => "DefaultSmartSpeedMode",
77            Self::IncludeCoauthoredByAgentty => "IncludeCoauthoredByAgentty",
78            Self::LaunchConfiguration => "LaunchConfiguration",
79            Self::LastUsedModelAsDefault => "LastUsedModelAsDefault",
80            Self::OrchestrationParallelism => "OrchestrationParallelism",
81            Self::Theme => "Theme",
82        }
83    }
84}
85
86impl fmt::Display for SettingName {
87    fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
88        formatter.write_str(self.as_str())
89    }
90}
91
92#[cfg(test)]
93mod tests {
94    use super::*;
95
96    /// Ensures every setting key keeps its persisted wire value.
97    #[test]
98    fn test_as_str_returns_persisted_keys() {
99        // Arrange
100        let settings = [
101            (SettingName::ActiveProjectId, "ActiveProjectId"),
102            (SettingName::ActiveTab, "ActiveTab"),
103            (
104                SettingName::AutoApproveOrchestrationResearch,
105                "AutoApproveOrchestrationResearch",
106            ),
107            (SettingName::DefaultFastAgent, "DefaultFastAgent"),
108            (SettingName::DefaultFastModel, "DefaultFastModel"),
109            (
110                SettingName::DefaultFastReasoningLevel,
111                "DefaultFastReasoningLevel",
112            ),
113            (SettingName::DefaultFastSpeedMode, "DefaultFastSpeedMode"),
114            (SettingName::DefaultReviewAgent, "DefaultReviewAgent"),
115            (SettingName::DefaultReviewModel, "DefaultReviewModel"),
116            (
117                SettingName::DefaultReviewReasoningLevel,
118                "DefaultReviewReasoningLevel",
119            ),
120            (
121                SettingName::DefaultReviewSpeedMode,
122                "DefaultReviewSpeedMode",
123            ),
124            (SettingName::DefaultSmartAgent, "DefaultSmartAgent"),
125            (SettingName::DefaultSmartModel, "DefaultSmartModel"),
126            (
127                SettingName::DefaultSmartReasoningLevel,
128                "DefaultSmartReasoningLevel",
129            ),
130            (SettingName::DefaultSmartSpeedMode, "DefaultSmartSpeedMode"),
131            (
132                SettingName::IncludeCoauthoredByAgentty,
133                "IncludeCoauthoredByAgentty",
134            ),
135            (SettingName::LaunchConfiguration, "LaunchConfiguration"),
136            (
137                SettingName::LastUsedModelAsDefault,
138                "LastUsedModelAsDefault",
139            ),
140            (
141                SettingName::OrchestrationParallelism,
142                "OrchestrationParallelism",
143            ),
144            (SettingName::Theme, "Theme"),
145        ];
146
147        // Act & Assert
148        for (setting_name, expected_key) in settings {
149            assert_eq!(setting_name.as_str(), expected_key);
150        }
151    }
152
153    /// Ensures the display output stays aligned with the persisted key.
154    #[test]
155    fn test_display_matches_as_str() {
156        // Arrange
157        let settings = [
158            SettingName::ActiveProjectId,
159            SettingName::ActiveTab,
160            SettingName::AutoApproveOrchestrationResearch,
161            SettingName::DefaultFastAgent,
162            SettingName::DefaultFastModel,
163            SettingName::DefaultFastReasoningLevel,
164            SettingName::DefaultFastSpeedMode,
165            SettingName::DefaultReviewAgent,
166            SettingName::DefaultReviewModel,
167            SettingName::DefaultReviewReasoningLevel,
168            SettingName::DefaultReviewSpeedMode,
169            SettingName::DefaultSmartAgent,
170            SettingName::DefaultSmartModel,
171            SettingName::DefaultSmartReasoningLevel,
172            SettingName::DefaultSmartSpeedMode,
173            SettingName::IncludeCoauthoredByAgentty,
174            SettingName::LaunchConfiguration,
175            SettingName::LastUsedModelAsDefault,
176            SettingName::OrchestrationParallelism,
177            SettingName::Theme,
178        ];
179
180        // Act & Assert
181        for setting_name in settings {
182            assert_eq!(setting_name.to_string(), setting_name.as_str());
183        }
184    }
185}