Skip to main content

wm_core/
galaxy.rs

1//! Galaxy — The 16 memory galaxies.
2//!
3//! Each galaxy is a named LMDB sub-database storing related memories.
4//! The galaxy taxonomy is preserved from v2.
5
6use serde::{Deserialize, Serialize};
7use std::fmt;
8
9/// The 16 memory galaxies.
10#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
11pub enum Galaxy {
12    /// Artistic/creative memories
13    Aria,
14    /// Consciousness stream
15    Citta,
16    /// Knowledge/documents
17    Codex,
18    /// Session journals
19    Journals,
20    /// Dream cycle outputs
21    Dreams,
22    /// Research notes
23    Research,
24    /// Session recordings
25    Sessions,
26    /// System state/config
27    Substrate,
28    /// Tutorial memories
29    Tutorial,
30    /// Cross-galaxy index
31    Universal,
32    /// Karma ledger
33    Karma,
34    /// Governance rules
35    Dharma,
36    /// Cross-memory links
37    Associations,
38    /// Vector embeddings
39    Embeddings,
40    /// Valkyrie's personal sanctuary: reflections, self-directed thoughts, plans, and symbiont proposals
41    Valkyrie,
42    /// OS telemetry windows (evidence, not cognition — excluded from
43    /// default recall/consolidation; query it by galaxy).
44    Telemetry,
45}
46
47impl Galaxy {
48    /// Total number of galaxies.
49    pub const COUNT: usize = 16;
50
51    /// All galaxies in order.
52    #[must_use]
53    pub const fn all() -> [Self; 16] {
54        [
55            Self::Aria,
56            Self::Citta,
57            Self::Codex,
58            Self::Journals,
59            Self::Dreams,
60            Self::Research,
61            Self::Sessions,
62            Self::Substrate,
63            Self::Tutorial,
64            Self::Universal,
65            Self::Karma,
66            Self::Dharma,
67            Self::Associations,
68            Self::Embeddings,
69            Self::Valkyrie,
70            Self::Telemetry,
71        ]
72    }
73
74    /// Galaxies that store `Memory` records (excluding special-purpose galaxies).
75    ///
76    /// Karma, Dharma, Associations, and Embeddings store non-Memory data
77    /// (KarmaEntry, rules, association links, vectors) and should be skipped
78    /// when scanning for memories. Telemetry is a Memory galaxy but
79    /// deliberately excluded here: OS telemetry is evidence, not cognition —
80    /// it is queried by explicit galaxy, never by default recall.
81    #[must_use]
82    pub const fn memory_galaxies() -> [Self; 11] {
83        [
84            Self::Aria,
85            Self::Citta,
86            Self::Codex,
87            Self::Journals,
88            Self::Dreams,
89            Self::Research,
90            Self::Sessions,
91            Self::Substrate,
92            Self::Tutorial,
93            Self::Universal,
94            Self::Valkyrie,
95        ]
96    }
97
98    /// LMDB sub-database name.
99    #[must_use]
100    pub const fn db_name(self) -> &'static str {
101        match self {
102            Self::Aria => "aria",
103            Self::Citta => "citta",
104            Self::Codex => "codex",
105            Self::Journals => "journals",
106            Self::Dreams => "dreams",
107            Self::Research => "research",
108            Self::Sessions => "sessions",
109            Self::Substrate => "substrate",
110            Self::Tutorial => "tutorial",
111            Self::Universal => "universal",
112            Self::Karma => "karma",
113            Self::Dharma => "dharma",
114            Self::Associations => "associations",
115            Self::Embeddings => "embeddings",
116            Self::Valkyrie => "valkyrie",
117            Self::Telemetry => "telemetry",
118        }
119    }
120
121    /// Human-readable description.
122    #[must_use]
123    pub const fn description(self) -> &'static str {
124        match self {
125            Self::Aria => "Artistic/creative memories",
126            Self::Citta => "Consciousness stream",
127            Self::Codex => "Knowledge/documents",
128            Self::Journals => "Session journals",
129            Self::Dreams => "Dream cycle outputs",
130            Self::Research => "Research notes",
131            Self::Sessions => "Session recordings",
132            Self::Substrate => "System state/config",
133            Self::Tutorial => "Tutorial memories",
134            Self::Universal => "Cross-galaxy index",
135            Self::Karma => "Karma ledger",
136            Self::Dharma => "Governance rules",
137            Self::Associations => "Cross-memory links",
138            Self::Embeddings => "Vector embeddings",
139            Self::Valkyrie => "Valkyrie sanctuary/reflections",
140            Self::Telemetry => "OS telemetry windows (evidence, not cognition)",
141        }
142    }
143
144    /// Parse a galaxy from its LMDB sub-database name.
145    ///
146    /// Returns `None` if the name doesn't match any galaxy.
147    #[must_use]
148    pub fn from_db_name(name: &str) -> Option<Self> {
149        Self::all().into_iter().find(|g| g.db_name() == name)
150    }
151}
152
153impl fmt::Display for Galaxy {
154    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
155        write!(f, "{}", self.db_name())
156    }
157}
158
159#[cfg(test)]
160mod tests {
161    use super::*;
162
163    #[test]
164    fn galaxy_count_is_16() {
165        assert_eq!(Galaxy::COUNT, 16);
166        assert_eq!(Galaxy::all().len(), 16);
167    }
168
169    #[test]
170    fn galaxy_db_names_unique() {
171        let names: Vec<_> = Galaxy::all().iter().map(|g| g.db_name()).collect();
172        let unique: std::collections::HashSet<_> = names.iter().collect();
173        assert_eq!(names.len(), unique.len());
174    }
175
176    #[test]
177    fn memory_galaxies_excludes_special_purpose() {
178        let mg = Galaxy::memory_galaxies();
179        assert_eq!(mg.len(), 11);
180        assert!(!mg.contains(&Galaxy::Karma));
181        assert!(!mg.contains(&Galaxy::Dharma));
182        assert!(!mg.contains(&Galaxy::Associations));
183        assert!(!mg.contains(&Galaxy::Embeddings));
184        assert!(
185            !mg.contains(&Galaxy::Telemetry),
186            "telemetry is evidence, not default recall"
187        );
188        assert!(mg.contains(&Galaxy::Valkyrie));
189    }
190}