Skip to main content

nexo_driver_loop/
post_compact_cleanup.rs

1//! PostCompactCleanup.
2//!
3//! Called after compact summary persistence. Optionally triggers memory
4//! extraction.
5
6use std::path::PathBuf;
7use std::sync::Arc;
8
9use crate::extract_memories::ExtractMemories;
10
11/// Runs post-compact housekeeping. When constructed with an
12/// `ExtractMemories` instance, also triggers memory extraction.
13pub struct PostCompactCleanup {
14    extract_memories: Option<Arc<ExtractMemories>>,
15    memory_dir: Option<PathBuf>,
16}
17
18impl PostCompactCleanup {
19    pub fn new() -> Self {
20        Self {
21            extract_memories: None,
22            memory_dir: None,
23        }
24    }
25
26    /// Attach memory extraction so it fires after compact persistence.
27    pub fn with_extract_memories(
28        mut self,
29        extract: Arc<ExtractMemories>,
30        memory_dir: PathBuf,
31    ) -> Self {
32        self.extract_memories = Some(extract);
33        self.memory_dir = Some(memory_dir);
34        self
35    }
36
37    /// Called after a compact summary is persisted.
38    pub async fn run(&self) {
39        if let (Some(ref extract), Some(ref memory_dir)) =
40            (&self.extract_memories, &self.memory_dir)
41        {
42            extract.tick();
43            // Compact turns don't produce conversation text, so
44            // extraction has nothing to work with here. Just tick
45            // the counter so the throttle stays accurate.
46            let _ = memory_dir;
47        }
48    }
49}
50
51impl Default for PostCompactCleanup {
52    fn default() -> Self {
53        Self::new()
54    }
55}