Skip to main content

agentic_reality/engine/
mod.rs

1//! Write and Query engines for AgenticReality.
2
3pub mod query;
4pub mod write;
5
6pub use query::QueryEngine;
7pub use write::WriteEngine;
8
9use crate::index::RealityIndexes;
10use crate::storage::*;
11use crate::types::ids::IncarnationId;
12
13/// The main reality engine combining write and query capabilities.
14pub struct RealityEngine {
15    pub deployment_store: DeploymentStore,
16    pub environment_store: EnvironmentStore,
17    pub resource_store: ResourceStore,
18    pub reality_store: RealityStore,
19    pub topology_store: TopologyStore,
20    pub temporal_store: TemporalStore,
21    pub stakes_store: StakesStore,
22    pub coherence_store: CoherenceStore,
23    pub indexes: RealityIndexes,
24    dirty: bool,
25}
26
27impl RealityEngine {
28    /// Create a new empty reality engine.
29    pub fn new() -> Self {
30        Self {
31            deployment_store: DeploymentStore::new(),
32            environment_store: EnvironmentStore::new(),
33            resource_store: ResourceStore::new(),
34            reality_store: RealityStore::new(),
35            topology_store: TopologyStore::new(),
36            temporal_store: TemporalStore::new(),
37            stakes_store: StakesStore::new(),
38            coherence_store: CoherenceStore::new(),
39            indexes: RealityIndexes::new(),
40            dirty: false,
41        }
42    }
43
44    /// Get a write engine handle.
45    pub fn writer(&mut self) -> WriteEngine<'_> {
46        WriteEngine::new(self)
47    }
48
49    /// Get a query engine handle.
50    pub fn reader(&self) -> QueryEngine<'_> {
51        QueryEngine::new(self)
52    }
53
54    /// Whether the engine has unsaved changes.
55    pub fn is_dirty(&self) -> bool {
56        self.dirty
57    }
58
59    /// Mark the engine as dirty (has unsaved changes).
60    pub fn mark_dirty(&mut self) {
61        self.dirty = true;
62    }
63
64    /// Mark the engine as clean (all changes saved).
65    pub fn mark_clean(&mut self) {
66        self.dirty = false;
67    }
68
69    /// Get the current incarnation ID if initialized.
70    pub fn incarnation_id(&self) -> Option<IncarnationId> {
71        self.deployment_store
72            .soul
73            .as_ref()
74            .map(|s| s.incarnation_id)
75    }
76
77    /// Check if the engine has been initialized with a deployment soul.
78    pub fn is_initialized(&self) -> bool {
79        self.deployment_store.soul.is_some()
80    }
81}
82
83impl Default for RealityEngine {
84    fn default() -> Self {
85        Self::new()
86    }
87}
88
89/// Context summary — quick overview of reality state.
90#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
91pub struct ContextSummary {
92    pub incarnation_id: Option<IncarnationId>,
93    pub substrate_tier: Option<String>,
94    pub environment_type: Option<String>,
95    pub environment_mood: Option<String>,
96    pub resource_bottleneck: Option<String>,
97    pub stakes_level: Option<String>,
98    pub coherence_level: Option<String>,
99    pub uptime_secs: Option<u64>,
100}