#![allow(dead_code)]
use std::sync::atomic::{AtomicBool, Ordering};
#[derive(Debug, Clone)]
pub struct FileHistorySnapshot {
pub file_path: String,
pub content: String,
pub timestamp: u64,
}
#[derive(Debug, Clone, Default)]
pub struct FileHistoryState {
pub snapshots: Vec<FileHistorySnapshot>,
pub enabled: bool,
}
pub fn file_history_enabled() -> bool {
crate::env_utils::is_env_truthy(&std::env::var("AI_CODE_FILE_HISTORY").unwrap_or_default())
}
pub fn file_history_restore_state_from_log(
snapshots: &[FileHistorySnapshot],
on_update_state: &dyn Fn(FileHistoryState),
) {
let state = FileHistoryState {
snapshots: snapshots.to_vec(),
enabled: true,
};
on_update_state(state);
}
pub fn file_history_snapshot_init(
initial_file_history_snapshots: Option<&[FileHistorySnapshot]>,
on_update_state: &dyn Fn(FileHistoryState),
) {
static INITIALIZED: AtomicBool = AtomicBool::new(false);
if !file_history_enabled() || INITIALIZED.load(Ordering::SeqCst) {
return;
}
INITIALIZED.store(true, Ordering::SeqCst);
if let Some(snapshots) = initial_file_history_snapshots {
file_history_restore_state_from_log(snapshots, on_update_state);
}
}