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