Skip to main content

eventgraph/compositions/
meaning.rs

1//! Layer 11 (Culture) composition operations.
2//!
3//! 10 operations + 5 named functions for cross-cultural communication.
4
5use crate::errors::Result;
6use crate::event::{Event, Signer};
7use crate::grammar::Grammar;
8use crate::store::InMemoryStore;
9use crate::types::{ActorId, ConversationId, DomainScope, EventId};
10
11/// MeaningGrammar provides Layer 11 (Culture) composition operations.
12pub struct MeaningGrammar<'a>(Grammar<'a>);
13
14impl<'a> MeaningGrammar<'a> {
15    pub fn new(store: &'a mut InMemoryStore) -> Self {
16        Self(Grammar::new(store))
17    }
18
19    pub fn examine(&mut self, source: ActorId, examination: &str, causes: Vec<EventId>, conv_id: ConversationId, signer: &dyn Signer) -> Result<Event> {
20        self.0.emit(source, &format!("examine: {examination}"), conv_id, causes, signer)
21    }
22
23    pub fn reframe(&mut self, source: ActorId, reframing: &str, original: EventId, conv_id: ConversationId, signer: &dyn Signer) -> Result<Event> {
24        self.0.derive(source, &format!("reframe: {reframing}"), original, conv_id, signer)
25    }
26
27    pub fn question(&mut self, source: ActorId, question: &str, target: EventId, conv_id: ConversationId, signer: &dyn Signer) -> Result<Event> {
28        let (_, flag) = self.0.challenge(source, &format!("question: {question}"), target, conv_id, signer)?;
29        Ok(flag)
30    }
31
32    pub fn distill(&mut self, source: ActorId, wisdom: &str, experience: EventId, conv_id: ConversationId, signer: &dyn Signer) -> Result<Event> {
33        self.0.derive(source, &format!("distill: {wisdom}"), experience, conv_id, signer)
34    }
35
36    pub fn beautify(&mut self, source: ActorId, beauty: &str, causes: Vec<EventId>, conv_id: ConversationId, signer: &dyn Signer) -> Result<Event> {
37        self.0.emit(source, &format!("beautify: {beauty}"), conv_id, causes, signer)
38    }
39
40    pub fn liken(&mut self, source: ActorId, metaphor: &str, subject: EventId, conv_id: ConversationId, signer: &dyn Signer) -> Result<Event> {
41        self.0.derive(source, &format!("liken: {metaphor}"), subject, conv_id, signer)
42    }
43
44    pub fn lighten(&mut self, source: ActorId, humour: &str, causes: Vec<EventId>, conv_id: ConversationId, signer: &dyn Signer) -> Result<Event> {
45        self.0.emit(source, &format!("lighten: {humour}"), conv_id, causes, signer)
46    }
47
48    pub fn teach(&mut self, source: ActorId, student: ActorId, scope: Option<&DomainScope>, cause: EventId, conv_id: ConversationId, signer: &dyn Signer) -> Result<Event> {
49        self.0.channel(source, student, scope, cause, conv_id, signer)
50    }
51
52    pub fn translate(&mut self, source: ActorId, translation: &str, original: EventId, conv_id: ConversationId, signer: &dyn Signer) -> Result<Event> {
53        self.0.derive(source, &format!("translate: {translation}"), original, conv_id, signer)
54    }
55
56    pub fn prophesy(&mut self, source: ActorId, prediction: &str, causes: Vec<EventId>, conv_id: ConversationId, signer: &dyn Signer) -> Result<Event> {
57        self.0.emit(source, &format!("prophesy: {prediction}"), conv_id, causes, signer)
58    }
59
60    // --- Named Functions ---
61
62    pub fn design_review(&mut self, source: ActorId, beauty: &str, reframing: &str, question_str: &str, wisdom: &str, cause: EventId, conv_id: ConversationId, signer: &dyn Signer) -> Result<DesignReviewResult> {
63        let beautify_ev = self.beautify(source.clone(), beauty, vec![cause], conv_id.clone(), signer)?;
64        let reframe_ev = self.reframe(source.clone(), reframing, beautify_ev.id.clone(), conv_id.clone(), signer)?;
65        let q = self.question(source.clone(), question_str, reframe_ev.id.clone(), conv_id.clone(), signer)?;
66        let w = self.distill(source, wisdom, q.id.clone(), conv_id, signer)?;
67        Ok(DesignReviewResult { beauty: beautify_ev, reframe: reframe_ev, question: q, wisdom: w })
68    }
69
70    pub fn cultural_onboarding(&mut self, guide: ActorId, newcomer: ActorId, translation: &str, teaching_scope: Option<&DomainScope>, examination: &str, cause: EventId, conv_id: ConversationId, signer: &dyn Signer) -> Result<CulturalOnboardingResult> {
71        let translate_ev = self.translate(guide.clone(), translation, cause, conv_id.clone(), signer)?;
72        let teach_ev = self.teach(guide, newcomer.clone(), teaching_scope, translate_ev.id.clone(), conv_id.clone(), signer)?;
73        let examine_ev = self.examine(newcomer, examination, vec![teach_ev.id.clone()], conv_id, signer)?;
74        Ok(CulturalOnboardingResult { translation: translate_ev, teaching: teach_ev, examination: examine_ev })
75    }
76
77    pub fn forecast(&mut self, source: ActorId, prediction: &str, assumptions: &str, confidence: &str, causes: Vec<EventId>, conv_id: ConversationId, signer: &dyn Signer) -> Result<ForecastResult> {
78        let prophesy_ev = self.prophesy(source.clone(), prediction, causes, conv_id.clone(), signer)?;
79        let examine_ev = self.examine(source.clone(), assumptions, vec![prophesy_ev.id.clone()], conv_id.clone(), signer)?;
80        let distill_ev = self.distill(source, confidence, examine_ev.id.clone(), conv_id, signer)?;
81        Ok(ForecastResult { prophecy: prophesy_ev, examination: examine_ev, wisdom: distill_ev })
82    }
83
84    pub fn post_mortem(&mut self, source: ActorId, examination: &str, question_str: &str, wisdom: &str, cause: EventId, conv_id: ConversationId, signer: &dyn Signer) -> Result<MeaningPostMortemResult> {
85        let exam = self.examine(source.clone(), examination, vec![cause], conv_id.clone(), signer)?;
86        let q = self.question(source.clone(), question_str, exam.id.clone(), conv_id.clone(), signer)?;
87        let w = self.distill(source, wisdom, q.id.clone(), conv_id, signer)?;
88        Ok(MeaningPostMortemResult { examination: exam, questions: q, wisdom: w })
89    }
90
91    pub fn mentorship(&mut self, mentor: ActorId, student: ActorId, reframing: &str, wisdom: &str, translation: &str, scope: Option<&DomainScope>, cause: EventId, conv_id: ConversationId, signer: &dyn Signer) -> Result<MentorshipResult> {
92        let channel = self.teach(mentor.clone(), student.clone(), scope, cause, conv_id.clone(), signer)?;
93        let reframe_ev = self.reframe(mentor.clone(), reframing, channel.id.clone(), conv_id.clone(), signer)?;
94        let distill_ev = self.distill(mentor, wisdom, reframe_ev.id.clone(), conv_id.clone(), signer)?;
95        let translate_ev = self.translate(student, translation, distill_ev.id.clone(), conv_id, signer)?;
96        Ok(MentorshipResult { channel, reframing: reframe_ev, wisdom: distill_ev, translation: translate_ev })
97    }
98}
99
100pub struct DesignReviewResult { pub beauty: Event, pub reframe: Event, pub question: Event, pub wisdom: Event }
101pub struct CulturalOnboardingResult { pub translation: Event, pub teaching: Event, pub examination: Event }
102pub struct ForecastResult { pub prophecy: Event, pub examination: Event, pub wisdom: Event }
103pub struct MeaningPostMortemResult { pub examination: Event, pub questions: Event, pub wisdom: Event }
104pub struct MentorshipResult { pub channel: Event, pub reframing: Event, pub wisdom: Event, pub translation: Event }