Skip to main content

aura_agent/runtime/effects/
system.rs

1use super::AuraEffectSystem;
2use async_trait::async_trait;
3use aura_core::effects::{ConsoleEffects, SystemEffects, SystemError};
4use aura_core::AuraError;
5use std::collections::HashMap;
6
7// Implementation of ConsoleEffects
8#[async_trait]
9impl ConsoleEffects for AuraEffectSystem {
10    async fn log_info(&self, message: &str) -> Result<(), AuraError> {
11        tracing::info!("{}", message);
12        Ok(())
13    }
14
15    async fn log_warn(&self, message: &str) -> Result<(), AuraError> {
16        tracing::warn!("{}", message);
17        Ok(())
18    }
19
20    async fn log_error(&self, message: &str) -> Result<(), AuraError> {
21        tracing::error!("{}", message);
22        Ok(())
23    }
24
25    async fn log_debug(&self, message: &str) -> Result<(), AuraError> {
26        tracing::debug!("{}", message);
27        Ok(())
28    }
29}
30
31// Implementation of SystemEffects
32#[async_trait]
33impl SystemEffects for AuraEffectSystem {
34    async fn shutdown(&self) -> Result<(), SystemError> {
35        self.ensure_mock_system("shutdown")?;
36        Ok(())
37    }
38
39    async fn get_system_info(&self) -> Result<HashMap<String, String>, SystemError> {
40        self.ensure_mock_system("get_system_info")?;
41        let mut info = HashMap::new();
42        info.insert("version".to_string(), "0.1.0".to_string());
43        info.insert("build_time".to_string(), "mock".to_string());
44        info.insert("commit_hash".to_string(), "mock".to_string());
45        info.insert("platform".to_string(), "test".to_string());
46        Ok(info)
47    }
48
49    async fn log(&self, level: &str, component: &str, message: &str) -> Result<(), SystemError> {
50        // Use tracing instead of println to avoid corrupting TUI
51        match level.to_lowercase().as_str() {
52            "error" => tracing::error!(component = component, "{}", message),
53            "warn" => tracing::warn!(component = component, "{}", message),
54            "debug" => tracing::debug!(component = component, "{}", message),
55            "trace" => tracing::trace!(component = component, "{}", message),
56            _ => tracing::info!(component = component, "{}", message),
57        }
58        Ok(())
59    }
60
61    async fn log_with_context(
62        &self,
63        level: &str,
64        component: &str,
65        message: &str,
66        _context: HashMap<String, String>,
67    ) -> Result<(), SystemError> {
68        // Use tracing instead of println to avoid corrupting TUI
69        match level.to_lowercase().as_str() {
70            "error" => tracing::error!(component = component, "{}", message),
71            "warn" => tracing::warn!(component = component, "{}", message),
72            "debug" => tracing::debug!(component = component, "{}", message),
73            "trace" => tracing::trace!(component = component, "{}", message),
74            _ => tracing::info!(component = component, "{}", message),
75        }
76        Ok(())
77    }
78
79    async fn set_config(&self, _key: &str, _value: &str) -> Result<(), SystemError> {
80        self.ensure_mock_system("set_config")?;
81        Ok(())
82    }
83
84    async fn get_config(&self, _key: &str) -> Result<String, SystemError> {
85        self.ensure_mock_system("get_config")?;
86        Ok("mock_value".to_string())
87    }
88
89    async fn health_check(&self) -> Result<bool, SystemError> {
90        self.ensure_mock_system("health_check")?;
91        Ok(true)
92    }
93
94    async fn get_metrics(&self) -> Result<HashMap<String, f64>, SystemError> {
95        self.ensure_mock_system("get_metrics")?;
96        Ok(HashMap::new())
97    }
98
99    async fn restart_component(&self, _component: &str) -> Result<(), SystemError> {
100        self.ensure_mock_system("restart_component")?;
101        Ok(())
102    }
103}