shodh-memory 0.2.0

Persistent cognitive memory for AI agents and robots — Hebbian learning, knowledge graph, spatial recall. Zenoh/ROS2 native. Single binary, runs offline.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
//! Memory Consolidation Introspection
//!
//! Provides visibility into what the memory system is learning:
//! - Which memories are strengthening/decaying
//! - What associations are forming
//! - When consolidation events occur
//!
//! This makes the "brain" transparent rather than a black box.

use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
use std::collections::VecDeque;

/// Maximum number of events to keep in the event buffer
const MAX_EVENT_BUFFER_SIZE: usize = 1000;

/// Types of consolidation events that can occur
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(tag = "type", rename_all = "snake_case")]
pub enum ConsolidationEvent {
    /// Memory activation was strengthened (accessed/boosted)
    MemoryStrengthened {
        memory_id: String,
        content_preview: String,
        activation_before: f32,
        activation_after: f32,
        reason: StrengtheningReason,
        timestamp: DateTime<Utc>,
    },

    /// Memory activation decayed during maintenance
    MemoryDecayed {
        memory_id: String,
        content_preview: String,
        activation_before: f32,
        activation_after: f32,
        at_risk: bool, // Below threshold soon
        timestamp: DateTime<Utc>,
    },

    /// Hebbian edge was formed between memories
    EdgeFormed {
        from_memory_id: String,
        to_memory_id: String,
        initial_strength: f32,
        reason: EdgeFormationReason,
        timestamp: DateTime<Utc>,
    },

    /// Hebbian edge was strengthened (co-activation)
    EdgeStrengthened {
        from_memory_id: String,
        to_memory_id: String,
        strength_before: f32,
        strength_after: f32,
        co_activations: u32,
        timestamp: DateTime<Utc>,
    },

    /// Edge became potentiated (permanent through LTP)
    EdgePotentiated {
        from_memory_id: String,
        to_memory_id: String,
        final_strength: f32,
        total_co_activations: u32,
        timestamp: DateTime<Utc>,
    },

    /// Edge was pruned (decayed below threshold)
    EdgePruned {
        from_memory_id: String,
        to_memory_id: String,
        final_strength: f32,
        reason: PruningReason,
        timestamp: DateTime<Utc>,
    },

    /// Semantic fact was extracted from episodic memories
    FactExtracted {
        fact_id: String,
        fact_content: String,
        confidence: f32,
        source_memory_count: usize,
        fact_type: String,
        timestamp: DateTime<Utc>,
    },

    /// Existing fact was reinforced with new evidence
    FactReinforced {
        fact_id: String,
        fact_content: String,
        confidence_before: f32,
        confidence_after: f32,
        new_support_count: usize,
        timestamp: DateTime<Utc>,
    },

    /// Fact confidence decayed due to lack of reinforcement
    FactDecayed {
        fact_id: String,
        fact_content: String,
        confidence_before: f32,
        confidence_after: f32,
        days_since_reinforcement: i64,
        timestamp: DateTime<Utc>,
    },

    /// Fact was deleted (confidence fell below threshold)
    FactDeleted {
        fact_id: String,
        fact_content: String,
        final_confidence: f32,
        support_count: usize,
        reason: String,
        timestamp: DateTime<Utc>,
    },

    /// Memory was promoted to a higher tier
    MemoryPromoted {
        memory_id: String,
        content_preview: String,
        from_tier: String,
        to_tier: String,
        timestamp: DateTime<Utc>,
    },

    /// Maintenance cycle completed
    MaintenanceCycleCompleted {
        memories_processed: usize,
        memories_decayed: usize,
        edges_pruned: usize,
        duration_ms: u64,
        timestamp: DateTime<Utc>,
    },

    // SHO-105: Memory Replay Events
    // Based on Rasch & Born (2013) - sleep consolidation through replay
    /// Memory was replayed during consolidation cycle
    MemoryReplayed {
        memory_id: String,
        content_preview: String,
        activation_before: f32,
        activation_after: f32,
        replay_priority: f32,
        connected_memories_replayed: usize,
        timestamp: DateTime<Utc>,
    },

    /// Replay cycle completed (batch of memories replayed)
    ReplayCycleCompleted {
        memories_replayed: usize,
        edges_strengthened: usize,
        total_priority_score: f32,
        duration_ms: u64,
        timestamp: DateTime<Utc>,
    },

    // SHO-106: Memory Interference Events
    // Based on Anderson & Neely (1996) - retrieval competition
    /// Interference detected between memories
    InterferenceDetected {
        new_memory_id: String,
        old_memory_id: String,
        similarity: f32,
        interference_type: InterferenceType,
        timestamp: DateTime<Utc>,
    },

    /// Memory weakened due to interference
    MemoryWeakened {
        memory_id: String,
        content_preview: String,
        activation_before: f32,
        activation_after: f32,
        interfering_memory_id: String,
        interference_type: InterferenceType,
        timestamp: DateTime<Utc>,
    },

    /// Retrieval competition occurred (similar memories competed)
    RetrievalCompetition {
        query_preview: String,
        winner_memory_id: String,
        suppressed_memory_ids: Vec<String>,
        competition_factor: f32,
        timestamp: DateTime<Utc>,
    },

    // PIPE-2: Pattern-Triggered Replay Events
    // Based on hippocampal sharp-wave ripple research (Rasch & Born 2013)
    /// Pattern-triggered replay initiated (not timer-based)
    PatternTriggeredReplay {
        trigger_type: String,
        memory_ids: Vec<String>,
        pattern_confidence: f32,
        trigger_description: String,
        timestamp: DateTime<Utc>,
    },

    /// Entity co-occurrence pattern detected
    EntityPatternDetected {
        entity_group: Vec<String>,
        memory_ids: Vec<String>,
        overlap_score: f32,
        confidence: f32,
        timestamp: DateTime<Utc>,
    },

    /// Semantic cluster formed (dense similarity group)
    SemanticClusterFormed {
        memory_ids: Vec<String>,
        cluster_size: usize,
        avg_similarity: f32,
        centroid_id: String,
        timestamp: DateTime<Utc>,
    },

    /// Temporal cluster (session) detected
    TemporalClusterFormed {
        memory_ids: Vec<String>,
        session_duration_secs: i64,
        session_id: Option<String>,
        timestamp: DateTime<Utc>,
    },

    /// Salience spike detected (high importance/arousal memory)
    SalienceSpikeDetected {
        memory_id: String,
        content_preview: String,
        importance: f32,
        arousal: f32,
        surprise_factor: f32,
        timestamp: DateTime<Utc>,
    },

    /// Behavioral pattern change triggered replay
    BehavioralChangeDetected {
        change_type: String,
        affected_memory_ids: Vec<String>,
        context: String,
        timestamp: DateTime<Utc>,
    },

    /// Generic pattern detected (covers any trigger type)
    PatternDetected {
        trigger_type: String,
        description: String,
        memory_ids: Vec<String>,
        timestamp: DateTime<Utc>,
    },

    // Memory-Edge Tier Coupling Events
    // Direction 1: Edge tier promotion → Memory importance boost
    /// Edge tier promotion boosted a memory's importance
    EdgePromotionBoostApplied {
        memory_id: String,
        entity_name: String,
        old_tier: String,
        new_tier: String,
        importance_boost: f64,
        new_importance: f64,
        timestamp: DateTime<Utc>,
    },

    // Direction 2: Edge pruning → Orphan detection
    /// Memory became a graph orphan (lost all edges)
    GraphOrphanDetected {
        memory_id: String,
        entity_count: usize,
        compensatory_boost: f64,
        timestamp: DateTime<Utc>,
    },

    // Direction 3: Graph health → Promotion threshold adjustment
    /// Memory tier promotion threshold adjusted by graph health
    GraphAdjustedPromotion {
        memory_id: String,
        base_threshold: f64,
        adjusted_threshold: f64,
        l2_plus_edge_count: usize,
        promoted: bool,
        timestamp: DateTime<Utc>,
    },

    /// Graph decay consolidated into single call site (double-decay fix diagnostic)
    GraphDecayConsolidated {
        pruned_count: usize,
        orphaned_entities: usize,
        timestamp: DateTime<Utc>,
    },
}

/// Types of memory interference (SHO-106)
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum InterferenceType {
    /// New learning disrupts old memories
    Retroactive,
    /// Old memories interfere with new learning
    Proactive,
    /// Similar memories compete during retrieval
    RetrievalCompetition,
}

/// Reasons for memory strengthening
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum StrengtheningReason {
    /// Accessed during recall
    Recalled,
    /// Part of spreading activation
    SpreadingActivation,
    /// Explicitly boosted by user
    ExplicitBoost,
    /// Co-retrieved with another memory
    CoRetrieval,
    /// Potentiated during maintenance (Hebbian LTP for frequently accessed memories)
    MaintenancePotentiation,
}

/// Reasons for edge formation
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum EdgeFormationReason {
    /// Co-retrieved during recall
    CoRetrieval,
    /// Shared entities
    SharedEntities,
    /// Semantic similarity above threshold
    SemanticSimilarity,
    /// Temporal proximity
    TemporalProximity,
}

/// Reasons for edge pruning
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum PruningReason {
    /// Decayed below minimum threshold
    DecayedBelowThreshold,
    /// Not accessed for too long
    Inactivity,
    /// Explicitly invalidated
    Invalidated,
}

/// Aggregated consolidation report for a time period
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ConsolidationReport {
    /// Time period covered
    pub period: ReportPeriod,

    /// Memories that got stronger
    pub strengthened_memories: Vec<MemoryChange>,

    /// Memories that decayed
    pub decayed_memories: Vec<MemoryChange>,

    /// New associations formed
    pub formed_associations: Vec<AssociationChange>,

    /// Associations that got stronger
    pub strengthened_associations: Vec<AssociationChange>,

    /// Associations that became permanent (LTP)
    pub potentiated_associations: Vec<AssociationChange>,

    /// Associations that were pruned
    pub pruned_associations: Vec<AssociationChange>,

    /// Facts extracted from episodic memories
    pub extracted_facts: Vec<FactChange>,

    /// Facts that were reinforced
    pub reinforced_facts: Vec<FactChange>,

    /// Facts that decayed due to lack of reinforcement
    pub decayed_facts: Vec<FactChange>,

    /// Facts that were deleted (confidence too low)
    pub deleted_facts: Vec<FactChange>,

    // SHO-105: Replay events
    /// Memories that were replayed for consolidation
    pub replayed_memories: Vec<ReplayEvent>,

    // SHO-106: Interference events
    /// Interference events detected
    pub interference_events: Vec<InterferenceEvent>,

    /// Memories weakened due to interference
    pub weakened_memories: Vec<MemoryChange>,

    /// Aggregate statistics
    pub statistics: ConsolidationStats,
}

/// Replay event details (SHO-105)
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ReplayEvent {
    pub memory_id: String,
    pub content_preview: String,
    pub activation_before: f32,
    pub activation_after: f32,
    pub replay_priority: f32,
    pub connected_memories: usize,
    pub timestamp: DateTime<Utc>,
}

/// Interference event details (SHO-106)
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct InterferenceEvent {
    pub new_memory_id: String,
    pub old_memory_id: String,
    pub similarity: f32,
    pub interference_type: InterferenceType,
    pub timestamp: DateTime<Utc>,
}

/// Time period for a report
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ReportPeriod {
    pub start: DateTime<Utc>,
    pub end: DateTime<Utc>,
}

/// Change in a memory's state
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct MemoryChange {
    pub memory_id: String,
    pub content_preview: String,
    pub activation_before: f32,
    pub activation_after: f32,
    pub change_reason: String,
    pub at_risk: bool,
    pub timestamp: DateTime<Utc>,
}

/// Change in an association/edge
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct AssociationChange {
    pub from_memory_id: String,
    pub to_memory_id: String,
    pub strength_before: Option<f32>,
    pub strength_after: f32,
    pub co_activations: Option<u32>,
    pub reason: String,
    pub timestamp: DateTime<Utc>,
}

/// Change in a semantic fact
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct FactChange {
    pub fact_id: String,
    pub fact_content: String,
    pub confidence: f32,
    pub support_count: usize,
    pub fact_type: String,
    pub timestamp: DateTime<Utc>,
}

/// Aggregate statistics for consolidation
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct ConsolidationStats {
    pub total_memories: usize,
    pub memories_strengthened: usize,
    pub memories_decayed: usize,
    pub memories_at_risk: usize,
    pub edges_formed: usize,
    pub edges_strengthened: usize,
    pub edges_potentiated: usize,
    pub edges_pruned: usize,
    pub facts_extracted: usize,
    pub facts_reinforced: usize,
    pub facts_decayed: usize,
    pub facts_deleted: usize,
    pub maintenance_cycles: usize,
    pub total_maintenance_duration_ms: u64,
    // SHO-105: Replay statistics
    pub memories_replayed: usize,
    pub replay_cycles: usize,
    pub total_replay_priority: f32,
    // SHO-106: Interference statistics
    pub interference_events: usize,
    pub memories_weakened: usize,
    pub retrieval_competitions: usize,
}

/// Buffer for storing consolidation events
#[derive(Debug, Default)]
pub struct ConsolidationEventBuffer {
    events: VecDeque<ConsolidationEvent>,
    max_size: usize,
}

impl ConsolidationEventBuffer {
    pub fn new() -> Self {
        Self {
            events: VecDeque::new(),
            max_size: MAX_EVENT_BUFFER_SIZE,
        }
    }

    pub fn with_capacity(max_size: usize) -> Self {
        Self {
            events: VecDeque::with_capacity(max_size),
            max_size,
        }
    }

    /// Push a new event, evicting oldest if at capacity
    pub fn push(&mut self, event: ConsolidationEvent) {
        if self.events.len() >= self.max_size {
            self.events.pop_front();
        }
        self.events.push_back(event);
    }

    /// Get all events since a given timestamp
    pub fn events_since(&self, since: DateTime<Utc>) -> Vec<ConsolidationEvent> {
        self.events
            .iter()
            .filter(|e| e.timestamp() >= since)
            .cloned()
            .collect()
    }

    /// Get all events
    pub fn all_events(&self) -> Vec<ConsolidationEvent> {
        self.events.iter().cloned().collect()
    }

    /// Clear all events
    pub fn clear(&mut self) {
        self.events.clear();
    }

    /// Number of events in buffer
    pub fn len(&self) -> usize {
        self.events.len()
    }

    /// Check if buffer is empty
    pub fn is_empty(&self) -> bool {
        self.events.is_empty()
    }

    /// Generate a report from events in a time period
    pub fn generate_report(
        &self,
        since: DateTime<Utc>,
        until: DateTime<Utc>,
    ) -> ConsolidationReport {
        let events: Vec<_> = self
            .events
            .iter()
            .filter(|e| {
                let ts = e.timestamp();
                ts >= since && ts <= until
            })
            .collect();

        let mut report = ConsolidationReport {
            period: ReportPeriod {
                start: since,
                end: until,
            },
            strengthened_memories: Vec::new(),
            decayed_memories: Vec::new(),
            formed_associations: Vec::new(),
            strengthened_associations: Vec::new(),
            potentiated_associations: Vec::new(),
            pruned_associations: Vec::new(),
            extracted_facts: Vec::new(),
            reinforced_facts: Vec::new(),
            decayed_facts: Vec::new(),
            deleted_facts: Vec::new(),
            // SHO-105: Replay events
            replayed_memories: Vec::new(),
            // SHO-106: Interference events
            interference_events: Vec::new(),
            weakened_memories: Vec::new(),
            statistics: ConsolidationStats::default(),
        };

        for event in events {
            match event {
                ConsolidationEvent::MemoryStrengthened {
                    memory_id,
                    content_preview,
                    activation_before,
                    activation_after,
                    reason,
                    timestamp,
                } => {
                    report.strengthened_memories.push(MemoryChange {
                        memory_id: memory_id.clone(),
                        content_preview: content_preview.clone(),
                        activation_before: *activation_before,
                        activation_after: *activation_after,
                        change_reason: format!("{:?}", reason),
                        at_risk: false,
                        timestamp: *timestamp,
                    });
                    report.statistics.memories_strengthened += 1;
                }

                ConsolidationEvent::MemoryDecayed {
                    memory_id,
                    content_preview,
                    activation_before,
                    activation_after,
                    at_risk,
                    timestamp,
                } => {
                    report.decayed_memories.push(MemoryChange {
                        memory_id: memory_id.clone(),
                        content_preview: content_preview.clone(),
                        activation_before: *activation_before,
                        activation_after: *activation_after,
                        change_reason: "decay".to_string(),
                        at_risk: *at_risk,
                        timestamp: *timestamp,
                    });
                    report.statistics.memories_decayed += 1;
                    if *at_risk {
                        report.statistics.memories_at_risk += 1;
                    }
                }

                ConsolidationEvent::EdgeFormed {
                    from_memory_id,
                    to_memory_id,
                    initial_strength,
                    reason,
                    timestamp,
                } => {
                    report.formed_associations.push(AssociationChange {
                        from_memory_id: from_memory_id.clone(),
                        to_memory_id: to_memory_id.clone(),
                        strength_before: None,
                        strength_after: *initial_strength,
                        co_activations: Some(1),
                        reason: format!("{:?}", reason),
                        timestamp: *timestamp,
                    });
                    report.statistics.edges_formed += 1;
                }

                ConsolidationEvent::EdgeStrengthened {
                    from_memory_id,
                    to_memory_id,
                    strength_before,
                    strength_after,
                    co_activations,
                    timestamp,
                } => {
                    report.strengthened_associations.push(AssociationChange {
                        from_memory_id: from_memory_id.clone(),
                        to_memory_id: to_memory_id.clone(),
                        strength_before: Some(*strength_before),
                        strength_after: *strength_after,
                        co_activations: Some(*co_activations),
                        reason: "co_activation".to_string(),
                        timestamp: *timestamp,
                    });
                    report.statistics.edges_strengthened += 1;
                }

                ConsolidationEvent::EdgePotentiated {
                    from_memory_id,
                    to_memory_id,
                    final_strength,
                    total_co_activations,
                    timestamp,
                } => {
                    report.potentiated_associations.push(AssociationChange {
                        from_memory_id: from_memory_id.clone(),
                        to_memory_id: to_memory_id.clone(),
                        strength_before: None,
                        strength_after: *final_strength,
                        co_activations: Some(*total_co_activations),
                        reason: "long_term_potentiation".to_string(),
                        timestamp: *timestamp,
                    });
                    report.statistics.edges_potentiated += 1;
                }

                ConsolidationEvent::EdgePruned {
                    from_memory_id,
                    to_memory_id,
                    final_strength,
                    reason,
                    timestamp,
                } => {
                    report.pruned_associations.push(AssociationChange {
                        from_memory_id: from_memory_id.clone(),
                        to_memory_id: to_memory_id.clone(),
                        strength_before: Some(*final_strength),
                        strength_after: 0.0,
                        co_activations: None,
                        reason: format!("{:?}", reason),
                        timestamp: *timestamp,
                    });
                    report.statistics.edges_pruned += 1;
                }

                ConsolidationEvent::FactExtracted {
                    fact_id,
                    fact_content,
                    confidence,
                    source_memory_count,
                    fact_type,
                    timestamp,
                } => {
                    report.extracted_facts.push(FactChange {
                        fact_id: fact_id.clone(),
                        fact_content: fact_content.clone(),
                        confidence: *confidence,
                        support_count: *source_memory_count,
                        fact_type: fact_type.clone(),
                        timestamp: *timestamp,
                    });
                    report.statistics.facts_extracted += 1;
                }

                ConsolidationEvent::FactReinforced {
                    fact_id,
                    fact_content,
                    confidence_after,
                    new_support_count,
                    timestamp,
                    ..
                } => {
                    report.reinforced_facts.push(FactChange {
                        fact_id: fact_id.clone(),
                        fact_content: fact_content.clone(),
                        confidence: *confidence_after,
                        support_count: *new_support_count,
                        fact_type: "reinforced".to_string(),
                        timestamp: *timestamp,
                    });
                    report.statistics.facts_reinforced += 1;
                }

                ConsolidationEvent::FactDecayed {
                    fact_id,
                    fact_content,
                    confidence_after,
                    days_since_reinforcement,
                    timestamp,
                    ..
                } => {
                    report.decayed_facts.push(FactChange {
                        fact_id: fact_id.clone(),
                        fact_content: fact_content.clone(),
                        confidence: *confidence_after,
                        support_count: *days_since_reinforcement as usize,
                        fact_type: "decayed".to_string(),
                        timestamp: *timestamp,
                    });
                    report.statistics.facts_decayed += 1;
                }

                ConsolidationEvent::FactDeleted {
                    fact_id,
                    fact_content,
                    final_confidence,
                    support_count,
                    reason,
                    timestamp,
                } => {
                    report.deleted_facts.push(FactChange {
                        fact_id: fact_id.clone(),
                        fact_content: fact_content.clone(),
                        confidence: *final_confidence,
                        support_count: *support_count,
                        fact_type: reason.clone(),
                        timestamp: *timestamp,
                    });
                    report.statistics.facts_deleted += 1;
                }

                ConsolidationEvent::MemoryPromoted { .. } => {
                    // Track promotions if needed
                }

                ConsolidationEvent::MaintenanceCycleCompleted { duration_ms, .. } => {
                    report.statistics.maintenance_cycles += 1;
                    report.statistics.total_maintenance_duration_ms += duration_ms;
                }

                // SHO-105: Memory replay events
                ConsolidationEvent::MemoryReplayed {
                    memory_id,
                    content_preview,
                    activation_before,
                    activation_after,
                    replay_priority,
                    connected_memories_replayed,
                    timestamp,
                } => {
                    report.replayed_memories.push(ReplayEvent {
                        memory_id: memory_id.clone(),
                        content_preview: content_preview.clone(),
                        activation_before: *activation_before,
                        activation_after: *activation_after,
                        replay_priority: *replay_priority,
                        connected_memories: *connected_memories_replayed,
                        timestamp: *timestamp,
                    });
                    report.statistics.memories_replayed += 1;
                    report.statistics.total_replay_priority += replay_priority;
                }

                ConsolidationEvent::ReplayCycleCompleted {
                    memories_replayed,
                    total_priority_score,
                    ..
                } => {
                    report.statistics.replay_cycles += 1;
                    report.statistics.memories_replayed += memories_replayed;
                    report.statistics.total_replay_priority += total_priority_score;
                }

                // SHO-106: Memory interference events
                ConsolidationEvent::InterferenceDetected {
                    new_memory_id,
                    old_memory_id,
                    similarity,
                    interference_type,
                    timestamp,
                } => {
                    report.interference_events.push(InterferenceEvent {
                        new_memory_id: new_memory_id.clone(),
                        old_memory_id: old_memory_id.clone(),
                        similarity: *similarity,
                        interference_type: interference_type.clone(),
                        timestamp: *timestamp,
                    });
                    report.statistics.interference_events += 1;
                }

                ConsolidationEvent::MemoryWeakened {
                    memory_id,
                    content_preview,
                    activation_before,
                    activation_after,
                    interfering_memory_id,
                    interference_type,
                    timestamp,
                } => {
                    report.weakened_memories.push(MemoryChange {
                        memory_id: memory_id.clone(),
                        content_preview: content_preview.clone(),
                        activation_before: *activation_before,
                        activation_after: *activation_after,
                        change_reason: format!(
                            "{:?} interference from {}",
                            interference_type, interfering_memory_id
                        ),
                        at_risk: *activation_after < 0.1,
                        timestamp: *timestamp,
                    });
                    report.statistics.memories_weakened += 1;
                }

                ConsolidationEvent::RetrievalCompetition { .. } => {
                    report.statistics.retrieval_competitions += 1;
                }

                // PIPE-2: Pattern-triggered replay events
                // These are tracked in statistics but not in detailed lists (yet)
                ConsolidationEvent::PatternTriggeredReplay { .. } => {
                    // Could add to a pattern_triggers list if needed
                }
                ConsolidationEvent::EntityPatternDetected { .. } => {
                    // Tracked via PatternTriggeredReplay
                }
                ConsolidationEvent::SemanticClusterFormed { .. } => {
                    // Tracked via PatternTriggeredReplay
                }
                ConsolidationEvent::TemporalClusterFormed { .. } => {
                    // Tracked via PatternTriggeredReplay
                }
                ConsolidationEvent::SalienceSpikeDetected { .. } => {
                    // Tracked via PatternTriggeredReplay
                }
                ConsolidationEvent::BehavioralChangeDetected { .. } => {
                    // Tracked via PatternTriggeredReplay
                }
                ConsolidationEvent::PatternDetected { .. } => {
                    // Generic pattern - logged for introspection
                }

                // Memory-Edge Tier Coupling events — logged for introspection
                ConsolidationEvent::EdgePromotionBoostApplied { .. } => {}
                ConsolidationEvent::GraphOrphanDetected { .. } => {}
                ConsolidationEvent::GraphAdjustedPromotion { .. } => {}
                ConsolidationEvent::GraphDecayConsolidated { .. } => {}
            }
        }

        report
    }

    /// Generate a report from a slice of events (static method)
    ///
    /// This enables generating reports from events that come from multiple sources
    /// (e.g., persisted learning history + ephemeral buffer).
    pub fn generate_report_from_events(
        events: &[ConsolidationEvent],
        since: DateTime<Utc>,
        until: DateTime<Utc>,
    ) -> ConsolidationReport {
        let mut report = ConsolidationReport {
            period: ReportPeriod {
                start: since,
                end: until,
            },
            strengthened_memories: Vec::new(),
            decayed_memories: Vec::new(),
            formed_associations: Vec::new(),
            strengthened_associations: Vec::new(),
            potentiated_associations: Vec::new(),
            pruned_associations: Vec::new(),
            extracted_facts: Vec::new(),
            reinforced_facts: Vec::new(),
            decayed_facts: Vec::new(),
            deleted_facts: Vec::new(),
            replayed_memories: Vec::new(),
            interference_events: Vec::new(),
            weakened_memories: Vec::new(),
            statistics: ConsolidationStats::default(),
        };

        for event in events {
            match event {
                ConsolidationEvent::MemoryStrengthened {
                    memory_id,
                    content_preview,
                    activation_before,
                    activation_after,
                    reason,
                    timestamp,
                } => {
                    report.strengthened_memories.push(MemoryChange {
                        memory_id: memory_id.clone(),
                        content_preview: content_preview.clone(),
                        activation_before: *activation_before,
                        activation_after: *activation_after,
                        change_reason: format!("{:?}", reason),
                        at_risk: false,
                        timestamp: *timestamp,
                    });
                    report.statistics.memories_strengthened += 1;
                }

                ConsolidationEvent::MemoryDecayed {
                    memory_id,
                    content_preview,
                    activation_before,
                    activation_after,
                    at_risk,
                    timestamp,
                } => {
                    report.decayed_memories.push(MemoryChange {
                        memory_id: memory_id.clone(),
                        content_preview: content_preview.clone(),
                        activation_before: *activation_before,
                        activation_after: *activation_after,
                        change_reason: "decay".to_string(),
                        at_risk: *at_risk,
                        timestamp: *timestamp,
                    });
                    report.statistics.memories_decayed += 1;
                    if *at_risk {
                        report.statistics.memories_at_risk += 1;
                    }
                }

                ConsolidationEvent::EdgeFormed {
                    from_memory_id,
                    to_memory_id,
                    initial_strength,
                    reason,
                    timestamp,
                } => {
                    report.formed_associations.push(AssociationChange {
                        from_memory_id: from_memory_id.clone(),
                        to_memory_id: to_memory_id.clone(),
                        strength_before: None,
                        strength_after: *initial_strength,
                        co_activations: Some(1),
                        reason: format!("{:?}", reason),
                        timestamp: *timestamp,
                    });
                    report.statistics.edges_formed += 1;
                }

                ConsolidationEvent::EdgeStrengthened {
                    from_memory_id,
                    to_memory_id,
                    strength_before,
                    strength_after,
                    co_activations,
                    timestamp,
                } => {
                    report.strengthened_associations.push(AssociationChange {
                        from_memory_id: from_memory_id.clone(),
                        to_memory_id: to_memory_id.clone(),
                        strength_before: Some(*strength_before),
                        strength_after: *strength_after,
                        co_activations: Some(*co_activations),
                        reason: "co_activation".to_string(),
                        timestamp: *timestamp,
                    });
                    report.statistics.edges_strengthened += 1;
                }

                ConsolidationEvent::EdgePotentiated {
                    from_memory_id,
                    to_memory_id,
                    final_strength,
                    total_co_activations,
                    timestamp,
                } => {
                    report.potentiated_associations.push(AssociationChange {
                        from_memory_id: from_memory_id.clone(),
                        to_memory_id: to_memory_id.clone(),
                        strength_before: None,
                        strength_after: *final_strength,
                        co_activations: Some(*total_co_activations),
                        reason: "long_term_potentiation".to_string(),
                        timestamp: *timestamp,
                    });
                    report.statistics.edges_potentiated += 1;
                }

                ConsolidationEvent::EdgePruned {
                    from_memory_id,
                    to_memory_id,
                    final_strength,
                    reason,
                    timestamp,
                } => {
                    report.pruned_associations.push(AssociationChange {
                        from_memory_id: from_memory_id.clone(),
                        to_memory_id: to_memory_id.clone(),
                        strength_before: Some(*final_strength),
                        strength_after: 0.0,
                        co_activations: None,
                        reason: format!("{:?}", reason),
                        timestamp: *timestamp,
                    });
                    report.statistics.edges_pruned += 1;
                }

                ConsolidationEvent::FactExtracted {
                    fact_id,
                    fact_content,
                    confidence,
                    source_memory_count,
                    fact_type,
                    timestamp,
                } => {
                    report.extracted_facts.push(FactChange {
                        fact_id: fact_id.clone(),
                        fact_content: fact_content.clone(),
                        confidence: *confidence,
                        support_count: *source_memory_count,
                        fact_type: fact_type.clone(),
                        timestamp: *timestamp,
                    });
                    report.statistics.facts_extracted += 1;
                }

                ConsolidationEvent::FactReinforced {
                    fact_id,
                    fact_content,
                    confidence_after,
                    new_support_count,
                    timestamp,
                    ..
                } => {
                    report.reinforced_facts.push(FactChange {
                        fact_id: fact_id.clone(),
                        fact_content: fact_content.clone(),
                        confidence: *confidence_after,
                        support_count: *new_support_count,
                        fact_type: "reinforced".to_string(),
                        timestamp: *timestamp,
                    });
                    report.statistics.facts_reinforced += 1;
                }

                ConsolidationEvent::FactDecayed {
                    fact_id,
                    fact_content,
                    confidence_after,
                    days_since_reinforcement,
                    timestamp,
                    ..
                } => {
                    report.decayed_facts.push(FactChange {
                        fact_id: fact_id.clone(),
                        fact_content: fact_content.clone(),
                        confidence: *confidence_after,
                        support_count: *days_since_reinforcement as usize,
                        fact_type: "decayed".to_string(),
                        timestamp: *timestamp,
                    });
                    report.statistics.facts_decayed += 1;
                }

                ConsolidationEvent::FactDeleted {
                    fact_id,
                    fact_content,
                    final_confidence,
                    support_count,
                    reason,
                    timestamp,
                } => {
                    report.deleted_facts.push(FactChange {
                        fact_id: fact_id.clone(),
                        fact_content: fact_content.clone(),
                        confidence: *final_confidence,
                        support_count: *support_count,
                        fact_type: reason.clone(),
                        timestamp: *timestamp,
                    });
                    report.statistics.facts_deleted += 1;
                }

                ConsolidationEvent::MemoryPromoted { .. } => {
                    // Track promotions if needed
                }

                ConsolidationEvent::MaintenanceCycleCompleted { duration_ms, .. } => {
                    report.statistics.maintenance_cycles += 1;
                    report.statistics.total_maintenance_duration_ms += duration_ms;
                }

                ConsolidationEvent::MemoryReplayed {
                    memory_id,
                    content_preview,
                    activation_before,
                    activation_after,
                    replay_priority,
                    connected_memories_replayed,
                    timestamp,
                } => {
                    report.replayed_memories.push(ReplayEvent {
                        memory_id: memory_id.clone(),
                        content_preview: content_preview.clone(),
                        activation_before: *activation_before,
                        activation_after: *activation_after,
                        replay_priority: *replay_priority,
                        connected_memories: *connected_memories_replayed,
                        timestamp: *timestamp,
                    });
                    report.statistics.memories_replayed += 1;
                    report.statistics.total_replay_priority += replay_priority;
                }

                ConsolidationEvent::ReplayCycleCompleted {
                    memories_replayed,
                    total_priority_score,
                    ..
                } => {
                    report.statistics.replay_cycles += 1;
                    report.statistics.memories_replayed += memories_replayed;
                    report.statistics.total_replay_priority += total_priority_score;
                }

                ConsolidationEvent::InterferenceDetected {
                    new_memory_id,
                    old_memory_id,
                    similarity,
                    interference_type,
                    timestamp,
                } => {
                    report.interference_events.push(InterferenceEvent {
                        new_memory_id: new_memory_id.clone(),
                        old_memory_id: old_memory_id.clone(),
                        similarity: *similarity,
                        interference_type: interference_type.clone(),
                        timestamp: *timestamp,
                    });
                    report.statistics.interference_events += 1;
                }

                ConsolidationEvent::MemoryWeakened {
                    memory_id,
                    content_preview,
                    activation_before,
                    activation_after,
                    interfering_memory_id,
                    interference_type,
                    timestamp,
                } => {
                    report.weakened_memories.push(MemoryChange {
                        memory_id: memory_id.clone(),
                        content_preview: content_preview.clone(),
                        activation_before: *activation_before,
                        activation_after: *activation_after,
                        change_reason: format!(
                            "{:?} interference from {}",
                            interference_type, interfering_memory_id
                        ),
                        at_risk: *activation_after < 0.1,
                        timestamp: *timestamp,
                    });
                    report.statistics.memories_weakened += 1;
                }

                ConsolidationEvent::RetrievalCompetition { .. } => {
                    report.statistics.retrieval_competitions += 1;
                }

                // PIPE-2: Pattern-triggered replay events
                ConsolidationEvent::PatternTriggeredReplay { .. } => {}
                ConsolidationEvent::EntityPatternDetected { .. } => {}
                ConsolidationEvent::SemanticClusterFormed { .. } => {}
                ConsolidationEvent::TemporalClusterFormed { .. } => {}
                ConsolidationEvent::SalienceSpikeDetected { .. } => {}
                ConsolidationEvent::BehavioralChangeDetected { .. } => {}
                ConsolidationEvent::PatternDetected { .. } => {}

                // Memory-Edge Tier Coupling events — logged for introspection
                ConsolidationEvent::EdgePromotionBoostApplied { .. } => {}
                ConsolidationEvent::GraphOrphanDetected { .. } => {}
                ConsolidationEvent::GraphAdjustedPromotion { .. } => {}
                ConsolidationEvent::GraphDecayConsolidated { .. } => {}
            }
        }

        report
    }
}

impl ConsolidationEvent {
    /// Get the timestamp of this event
    pub fn timestamp(&self) -> DateTime<Utc> {
        match self {
            ConsolidationEvent::MemoryStrengthened { timestamp, .. } => *timestamp,
            ConsolidationEvent::MemoryDecayed { timestamp, .. } => *timestamp,
            ConsolidationEvent::EdgeFormed { timestamp, .. } => *timestamp,
            ConsolidationEvent::EdgeStrengthened { timestamp, .. } => *timestamp,
            ConsolidationEvent::EdgePotentiated { timestamp, .. } => *timestamp,
            ConsolidationEvent::EdgePruned { timestamp, .. } => *timestamp,
            ConsolidationEvent::FactExtracted { timestamp, .. } => *timestamp,
            ConsolidationEvent::FactReinforced { timestamp, .. } => *timestamp,
            ConsolidationEvent::FactDecayed { timestamp, .. } => *timestamp,
            ConsolidationEvent::FactDeleted { timestamp, .. } => *timestamp,
            ConsolidationEvent::MemoryPromoted { timestamp, .. } => *timestamp,
            ConsolidationEvent::MaintenanceCycleCompleted { timestamp, .. } => *timestamp,
            // SHO-105: Replay events
            ConsolidationEvent::MemoryReplayed { timestamp, .. } => *timestamp,
            ConsolidationEvent::ReplayCycleCompleted { timestamp, .. } => *timestamp,
            // SHO-106: Interference events
            ConsolidationEvent::InterferenceDetected { timestamp, .. } => *timestamp,
            ConsolidationEvent::MemoryWeakened { timestamp, .. } => *timestamp,
            ConsolidationEvent::RetrievalCompetition { timestamp, .. } => *timestamp,
            // PIPE-2: Pattern-triggered replay events
            ConsolidationEvent::PatternTriggeredReplay { timestamp, .. } => *timestamp,
            ConsolidationEvent::EntityPatternDetected { timestamp, .. } => *timestamp,
            ConsolidationEvent::SemanticClusterFormed { timestamp, .. } => *timestamp,
            ConsolidationEvent::TemporalClusterFormed { timestamp, .. } => *timestamp,
            ConsolidationEvent::SalienceSpikeDetected { timestamp, .. } => *timestamp,
            ConsolidationEvent::BehavioralChangeDetected { timestamp, .. } => *timestamp,
            ConsolidationEvent::PatternDetected { timestamp, .. } => *timestamp,
            // Memory-Edge Tier Coupling events
            ConsolidationEvent::EdgePromotionBoostApplied { timestamp, .. } => *timestamp,
            ConsolidationEvent::GraphOrphanDetected { timestamp, .. } => *timestamp,
            ConsolidationEvent::GraphAdjustedPromotion { timestamp, .. } => *timestamp,
            ConsolidationEvent::GraphDecayConsolidated { timestamp, .. } => *timestamp,
        }
    }

    /// Check if this event is significant enough to persist to learning history
    ///
    /// Significant events represent actual learning/state changes:
    /// - EdgePotentiated: Permanent association formed (LTP)
    /// - FactExtracted: New semantic knowledge created
    /// - FactDeleted: Knowledge was lost
    /// - FactReinforced: Fact got stronger evidence
    /// - InterferenceDetected: Memory conflict occurred
    /// - MemoryReplayed: Consolidation strengthened this memory
    /// - MemoryPromoted: Memory moved to higher tier
    /// - ReplayCycleCompleted: Batch consolidation summary
    /// - MaintenanceCycleCompleted: Maintenance summary
    ///
    /// Non-significant (routine housekeeping):
    /// - MemoryDecayed: Happens every cycle to every memory
    /// - MemoryStrengthened: High frequency access events
    /// - EdgeStrengthened: Incremental co-activation
    /// - EdgeFormed: Initial edge creation (may not survive)
    /// - EdgePruned: Cleanup of weak edges
    /// - FactDecayed: Minor confidence changes
    /// - MemoryWeakened: Consequence of interference (tracked via InterferenceDetected)
    /// - RetrievalCompetition: Transient retrieval-time event
    pub fn is_significant(&self) -> bool {
        matches!(
            self,
            ConsolidationEvent::EdgePotentiated { .. }
                | ConsolidationEvent::FactExtracted { .. }
                | ConsolidationEvent::FactDeleted { .. }
                | ConsolidationEvent::FactReinforced { .. }
                | ConsolidationEvent::InterferenceDetected { .. }
                | ConsolidationEvent::MemoryReplayed { .. }
                | ConsolidationEvent::MemoryPromoted { .. }
                | ConsolidationEvent::ReplayCycleCompleted { .. }
                | ConsolidationEvent::MaintenanceCycleCompleted { .. }
                // PIPE-2: Pattern-triggered events are significant
                | ConsolidationEvent::PatternTriggeredReplay { .. }
                | ConsolidationEvent::EntityPatternDetected { .. }
                | ConsolidationEvent::SemanticClusterFormed { .. }
                | ConsolidationEvent::SalienceSpikeDetected { .. }
                | ConsolidationEvent::PatternDetected { .. }
                // Memory-Edge Tier Coupling events are significant
                | ConsolidationEvent::EdgePromotionBoostApplied { .. }
                | ConsolidationEvent::GraphOrphanDetected { .. }
                | ConsolidationEvent::GraphAdjustedPromotion { .. }
                | ConsolidationEvent::GraphDecayConsolidated { .. }
        )
    }
}

impl Default for ConsolidationReport {
    fn default() -> Self {
        Self {
            period: ReportPeriod {
                start: Utc::now(),
                end: Utc::now(),
            },
            strengthened_memories: Vec::new(),
            decayed_memories: Vec::new(),
            formed_associations: Vec::new(),
            strengthened_associations: Vec::new(),
            potentiated_associations: Vec::new(),
            pruned_associations: Vec::new(),
            extracted_facts: Vec::new(),
            reinforced_facts: Vec::new(),
            decayed_facts: Vec::new(),
            deleted_facts: Vec::new(),
            // SHO-105: Replay events
            replayed_memories: Vec::new(),
            // SHO-106: Interference events
            interference_events: Vec::new(),
            weakened_memories: Vec::new(),
            statistics: ConsolidationStats::default(),
        }
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_event_buffer_push() {
        let mut buffer = ConsolidationEventBuffer::with_capacity(3);

        for i in 0..5 {
            buffer.push(ConsolidationEvent::MemoryDecayed {
                memory_id: format!("mem-{}", i),
                content_preview: format!("Memory {}", i),
                activation_before: 0.5,
                activation_after: 0.4,
                at_risk: false,
                timestamp: Utc::now(),
            });
        }

        // Should only keep last 3
        assert_eq!(buffer.len(), 3);
    }

    #[test]
    fn test_generate_report() {
        let mut buffer = ConsolidationEventBuffer::new();
        let now = Utc::now();

        buffer.push(ConsolidationEvent::MemoryStrengthened {
            memory_id: "mem-1".to_string(),
            content_preview: "Test memory".to_string(),
            activation_before: 0.5,
            activation_after: 0.7,
            reason: StrengtheningReason::Recalled,
            timestamp: now,
        });

        buffer.push(ConsolidationEvent::EdgeFormed {
            from_memory_id: "mem-1".to_string(),
            to_memory_id: "mem-2".to_string(),
            initial_strength: 0.5,
            reason: EdgeFormationReason::CoRetrieval,
            timestamp: now,
        });

        let report = buffer.generate_report(
            now - chrono::Duration::hours(1),
            now + chrono::Duration::hours(1),
        );

        assert_eq!(report.statistics.memories_strengthened, 1);
        assert_eq!(report.statistics.edges_formed, 1);
    }
}