lean_ctx/core/context_os/
mod.rs1use std::path::PathBuf;
2use std::sync::{Arc, OnceLock};
3
4mod shared_sessions;
5pub use shared_sessions::{SharedSessionKey, SharedSessionStore};
6
7mod context_bus;
8pub use context_bus::{ContextBus, ContextEventKindV1, ContextEventV1};
9
10pub mod redaction;
11pub use redaction::{redact_event_payload, RedactionLevel};
12
13mod metrics;
14pub use metrics::{ContextOsMetrics, MetricsSnapshot};
15
16#[derive(Clone)]
21pub struct ContextOsRuntime {
22 pub shared_sessions: Arc<SharedSessionStore>,
23 pub bus: Arc<ContextBus>,
24 pub metrics: Arc<ContextOsMetrics>,
25}
26
27impl Default for ContextOsRuntime {
28 fn default() -> Self {
29 Self {
30 shared_sessions: Arc::new(SharedSessionStore::new()),
31 bus: Arc::new(ContextBus::new()),
32 metrics: Arc::new(ContextOsMetrics::default()),
33 }
34 }
35}
36
37impl ContextOsRuntime {
38 pub fn new() -> Self {
39 Self::default()
40 }
41
42 pub fn data_dir() -> Option<PathBuf> {
43 crate::core::data_dir::lean_ctx_data_dir().ok()
44 }
45}
46
47static RUNTIME: OnceLock<Arc<ContextOsRuntime>> = OnceLock::new();
48
49pub fn runtime() -> Arc<ContextOsRuntime> {
50 RUNTIME
51 .get_or_init(|| Arc::new(ContextOsRuntime::new()))
52 .clone()
53}