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 default response style for newly created sessions.
38    DefaultResponseStyle,
39    /// Persists the provider that owns the smart-model default.
40    DefaultSmartAgent,
41    /// Persists the project or global smart-model selection.
42    DefaultSmartModel,
43    /// Persists the reasoning level paired with the smart-model default.
44    DefaultSmartReasoningLevel,
45    /// Persists the response speed paired with the smart-model default.
46    DefaultSmartSpeedMode,
47    /// Persists whether generated session commits append the Agentty coauthor
48    /// trailer.
49    IncludeCoauthoredByAgentty,
50    /// Persists the configured launch-configuration override.
51    LaunchConfiguration,
52    /// Persists whether the last used model should become the default.
53    LastUsedModelAsDefault,
54    /// Persists how many orchestration children may run at once.
55    OrchestrationParallelism,
56    /// Persists the active terminal color theme.
57    Theme,
58}
59
60impl SettingName {
61    /// Returns the persisted key string for one setting.
62    pub fn as_str(self) -> &'static str {
63        match self {
64            Self::ActiveProjectId => "ActiveProjectId",
65            Self::ActiveTab => "ActiveTab",
66            Self::AutoApproveOrchestrationResearch => "AutoApproveOrchestrationResearch",
67            Self::DefaultFastAgent => "DefaultFastAgent",
68            Self::DefaultFastModel => "DefaultFastModel",
69            Self::DefaultFastReasoningLevel => "DefaultFastReasoningLevel",
70            Self::DefaultFastSpeedMode => "DefaultFastSpeedMode",
71            Self::DefaultReviewAgent => "DefaultReviewAgent",
72            Self::DefaultReviewModel => "DefaultReviewModel",
73            Self::DefaultReviewReasoningLevel => "DefaultReviewReasoningLevel",
74            Self::DefaultReviewSpeedMode => "DefaultReviewSpeedMode",
75            Self::DefaultResponseStyle => "DefaultResponseStyle",
76            Self::DefaultSmartAgent => "DefaultSmartAgent",
77            Self::DefaultSmartModel => "DefaultSmartModel",
78            Self::DefaultSmartReasoningLevel => "DefaultSmartReasoningLevel",
79            Self::DefaultSmartSpeedMode => "DefaultSmartSpeedMode",
80            Self::IncludeCoauthoredByAgentty => "IncludeCoauthoredByAgentty",
81            Self::LaunchConfiguration => "LaunchConfiguration",
82            Self::LastUsedModelAsDefault => "LastUsedModelAsDefault",
83            Self::OrchestrationParallelism => "OrchestrationParallelism",
84            Self::Theme => "Theme",
85        }
86    }
87}
88
89impl fmt::Display for SettingName {
90    fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
91        formatter.write_str(self.as_str())
92    }
93}
94
95#[cfg(test)]
96mod tests {
97    use super::*;
98
99    /// Ensures every setting key keeps its persisted wire value.
100    #[test]
101    fn test_as_str_returns_persisted_keys() {
102        // Arrange
103        let settings = [
104            (SettingName::ActiveProjectId, "ActiveProjectId"),
105            (SettingName::ActiveTab, "ActiveTab"),
106            (
107                SettingName::AutoApproveOrchestrationResearch,
108                "AutoApproveOrchestrationResearch",
109            ),
110            (SettingName::DefaultFastAgent, "DefaultFastAgent"),
111            (SettingName::DefaultFastModel, "DefaultFastModel"),
112            (
113                SettingName::DefaultFastReasoningLevel,
114                "DefaultFastReasoningLevel",
115            ),
116            (SettingName::DefaultFastSpeedMode, "DefaultFastSpeedMode"),
117            (SettingName::DefaultReviewAgent, "DefaultReviewAgent"),
118            (SettingName::DefaultReviewModel, "DefaultReviewModel"),
119            (
120                SettingName::DefaultReviewReasoningLevel,
121                "DefaultReviewReasoningLevel",
122            ),
123            (
124                SettingName::DefaultReviewSpeedMode,
125                "DefaultReviewSpeedMode",
126            ),
127            (SettingName::DefaultResponseStyle, "DefaultResponseStyle"),
128            (SettingName::DefaultSmartAgent, "DefaultSmartAgent"),
129            (SettingName::DefaultSmartModel, "DefaultSmartModel"),
130            (
131                SettingName::DefaultSmartReasoningLevel,
132                "DefaultSmartReasoningLevel",
133            ),
134            (SettingName::DefaultSmartSpeedMode, "DefaultSmartSpeedMode"),
135            (
136                SettingName::IncludeCoauthoredByAgentty,
137                "IncludeCoauthoredByAgentty",
138            ),
139            (SettingName::LaunchConfiguration, "LaunchConfiguration"),
140            (
141                SettingName::LastUsedModelAsDefault,
142                "LastUsedModelAsDefault",
143            ),
144            (
145                SettingName::OrchestrationParallelism,
146                "OrchestrationParallelism",
147            ),
148            (SettingName::Theme, "Theme"),
149        ];
150
151        // Act & Assert
152        for (setting_name, expected_key) in settings {
153            assert_eq!(setting_name.as_str(), expected_key);
154        }
155    }
156
157    /// Ensures the display output stays aligned with the persisted key.
158    #[test]
159    fn test_display_matches_as_str() {
160        // Arrange
161        let settings = [
162            SettingName::ActiveProjectId,
163            SettingName::ActiveTab,
164            SettingName::AutoApproveOrchestrationResearch,
165            SettingName::DefaultFastAgent,
166            SettingName::DefaultFastModel,
167            SettingName::DefaultFastReasoningLevel,
168            SettingName::DefaultFastSpeedMode,
169            SettingName::DefaultReviewAgent,
170            SettingName::DefaultReviewModel,
171            SettingName::DefaultReviewReasoningLevel,
172            SettingName::DefaultReviewSpeedMode,
173            SettingName::DefaultResponseStyle,
174            SettingName::DefaultSmartAgent,
175            SettingName::DefaultSmartModel,
176            SettingName::DefaultSmartReasoningLevel,
177            SettingName::DefaultSmartSpeedMode,
178            SettingName::IncludeCoauthoredByAgentty,
179            SettingName::LaunchConfiguration,
180            SettingName::LastUsedModelAsDefault,
181            SettingName::OrchestrationParallelism,
182            SettingName::Theme,
183        ];
184
185        // Act & Assert
186        for setting_name in settings {
187            assert_eq!(setting_name.to_string(), setting_name.as_str());
188        }
189    }
190}