Skip to main content

forge_reasoning/
storage.rs

1//! Storage abstraction for checkpointing
2
3use crate::checkpoint::{CheckpointId, CheckpointSummary, SessionId, TemporalCheckpoint};
4use crate::errors::Result;
5
6/// Storage backend trait for checkpoints
7/// 
8/// Thread-safe version requires Send + Sync
9pub trait CheckpointStorage: Send + Sync {
10    /// Store a checkpoint
11    fn store(&self, checkpoint: &TemporalCheckpoint) -> Result<()>;
12
13    /// Retrieve a checkpoint by ID
14    fn get(&self, id: CheckpointId) -> Result<TemporalCheckpoint>;
15
16    /// Get the latest checkpoint for a session
17    fn get_latest(&self, session_id: SessionId) -> Result<Option<TemporalCheckpoint>>;
18
19    /// List all checkpoints for a session
20    fn list_by_session(&self, session_id: SessionId) -> Result<Vec<CheckpointSummary>>;
21
22    /// List checkpoints with a specific tag
23    fn list_by_tag(&self, tag: &str) -> Result<Vec<CheckpointSummary>>;
24
25    /// Delete a checkpoint
26    fn delete(&self, id: CheckpointId) -> Result<()>;
27
28    /// Get the next sequence number for a session
29    fn next_sequence(&self, session_id: SessionId) -> Result<u64>;
30
31    /// Get the maximum sequence number across all checkpoints
32    fn get_max_sequence(&self) -> Result<u64>;
33}
34
35/// Storage configuration
36#[derive(Clone, Debug)]
37pub struct StorageConfig {
38    pub path: std::path::PathBuf,
39    pub backend: BackendKind,
40    pub max_checkpoints: usize,
41    pub compression: bool,
42}
43
44impl StorageConfig {
45    pub fn sqlite(path: impl Into<std::path::PathBuf>) -> Self {
46        Self {
47            path: path.into(),
48            backend: BackendKind::SQLite,
49            max_checkpoints: 0,
50            compression: false,
51        }
52    }
53}
54
55/// Backend kind selection
56#[derive(Clone, Copy, Debug, PartialEq, Eq)]
57pub enum BackendKind {
58    SQLite,
59    NativeV3,
60}
61
62/// Factory function (placeholder for future implementations)
63pub fn create_storage(_config: &StorageConfig) -> Result<Box<dyn CheckpointStorage>> {
64    unimplemented!("Storage factory not yet implemented")
65}