//! Command types for CMS domain operations. //! //! Following the `NewXxx` / `XxxPatch` pattern from clean architecture, //! these types encapsulate the input data for create/update operations //! on domain entities. They decouple presentation DTOs from the entity //! mutation surface and provide a clear boundary for validation. use std::collections::HashMap; use super::settings::InternetMode; // --------------------------------------------------------------------------- // Settings // --------------------------------------------------------------------------- /// Partial update command for `Settings`. /// /// Every field is `Option`al — only non-`None` fields are applied to the /// existing settings instance. Use `apply_to()` to merge into a `Settings` /// value. #[derive(Debug, Clone, Default)] pub struct SettingsPatch { /// Override the internet access mode. pub internet_mode: Option, /// Override the active provider name. pub provider: Option, /// Override the active model name. pub model: Option, /// Replace the entire API-keys map. pub api_keys: Option>, /// Override the max tokens for completions. pub max_tokens: Option>, /// Override the temperature for completions. pub temperature: Option>, /// Override the review max lessons per run. pub review_max_lessons_per_run: Option, /// Override the adaptive review max skip count. pub adaptive_review_max_skip: Option, /// Override the verify shell command. pub verify_command: Option>, /// Override the verify timeout in milliseconds. pub verify_timeout_ms: Option, /// Override the max concurrency for workflow execution. pub workflow_max_concurrency: Option, /// Override the review-enabled flag. pub review_enabled: Option, /// Override the session-archive-enabled flag. pub session_archive_enabled: Option, /// Override the LSP auto-provision flag. pub lsp_auto_provision: Option, /// Override the list of LSP-managed languages. pub lsp_languages: Option>, /// Override the hive-mind node timeout in milliseconds. pub hive_mind_node_timeout_ms: Option, } impl SettingsPatch { /// Merge this patch into `settings`, overwriting each non-`None` field. /// /// Flow: for each optional field, if `Some`, assign it to the target. /// /// ## Errors /// Returns `Err` with a message if `internet_mode` is set to an /// unrecognised value. pub fn apply_to(&self, settings: &mut super::settings::Settings) -> Result<(), String> { if let Some(ref val) = self.internet_mode { settings.internet_mode = match val.as_str() { "Off" => InternetMode::Off, "ReadOnly" => InternetMode::ReadOnly, "Full" => InternetMode::Full, _ => { return Err(format!( "invalid internet_mode '{val}'; expected Off, ReadOnly, or Full" )) } }; } if let Some(ref val) = self.provider { settings.provider = val.clone(); } if let Some(ref val) = self.model { settings.model = val.clone(); } if let Some(ref val) = self.api_keys { settings.api_keys = val.clone(); } if let Some(val) = self.max_tokens { settings.max_tokens = val; } if let Some(val) = self.temperature { settings.temperature = val; } if let Some(val) = self.review_max_lessons_per_run { settings.review_max_lessons_per_run = val; } if let Some(val) = self.adaptive_review_max_skip { settings.adaptive_review_max_skip = val; } if let Some(ref val) = self.verify_command { settings.verify_command = val.clone(); } if let Some(val) = self.verify_timeout_ms { settings.verify_timeout_ms = val; } if let Some(val) = self.workflow_max_concurrency { settings.workflow_max_concurrency = val; } if let Some(val) = self.review_enabled { settings.flags.review_enabled = val; } if let Some(val) = self.session_archive_enabled { settings.flags.session_archive_enabled = val; } if let Some(val) = self.lsp_auto_provision { settings.flags.lsp_auto_provision = val; } if let Some(ref val) = self.lsp_languages { settings.lsp_languages = val.clone(); } if let Some(val) = self.hive_mind_node_timeout_ms { settings.hive_mind_node_timeout_ms = val; } Ok(()) } } // --------------------------------------------------------------------------- // Memory // --------------------------------------------------------------------------- /// Command to create a new memory entry. /// /// All required fields are non-optional; optional fields use `Option` /// and default to sensible values (empty or the service default). #[derive(Debug, Clone)] pub struct NewMemory { /// Unique name / slug for the memory. pub name: String, /// One-line summary of what the memory captures. pub description: String, /// The full memory content. pub content: String, /// Category kind (defaults to "reference" in the handler). pub kind: Option, /// Outcome of the remembered action. pub outcome: Option, /// Lifecycle stage (defaults to "new" in the handler). pub lifecycle: Option, /// Scope context for the memory. pub scope: Option, /// Code snippet captured before the action. pub before_snippet: Option, /// Code snippet captured after the action. pub after_snippet: Option, /// Source provenances (files, conversations, etc.). pub provenances: Option>, }