pub struct BackupStore { /* private fields */ }Expand description
Per-(session, file) undo store with optional disk persistence.
Introduced alongside project-shared bridges (issue #14): one bridge can now serve many OpenCode sessions in the same project, so undo history must be partitioned by session to keep session A’s edits invisible to session B.
The 20-entry cap is enforced per (session, file) deliberately — a global per-file LRU would re-couple sessions and let one busy session evict another’s history.
Disk layout (schema v2):
<storage_dir>/backups/<session_hash>/session.json — session metadata
<storage_dir>/backups/<session_hash>/<path_hash>/meta.json — file path + count + session
<storage_dir>/backups/<session_hash>/<path_hash>/0.bak … 19.bak — snapshots
Legacy layouts from before sessionization (flat <path_hash>/ directly under
backups/) are migrated on first set_storage_dir call into the default
session namespace.
Implementations§
Source§impl BackupStore
impl BackupStore
pub fn new() -> Self
Sourcepub fn set_storage_dir(&mut self, dir: PathBuf, ttl_hours: u32)
pub fn set_storage_dir(&mut self, dir: PathBuf, ttl_hours: u32)
Set storage directory for disk persistence (called during configure).
Loads the disk index for all session namespaces, removes stale session directories, and migrates any legacy pre-session (flat) layout into the default namespace.
Sourcepub fn snapshot(
&mut self,
session: &str,
path: &Path,
description: &str,
) -> Result<String, AftError>
pub fn snapshot( &mut self, session: &str, path: &Path, description: &str, ) -> Result<String, AftError>
Snapshot the current contents of path under the given session namespace.
Sourcepub fn snapshot_with_op(
&mut self,
session: &str,
path: &Path,
description: &str,
op_id: Option<&str>,
) -> Result<String, AftError>
pub fn snapshot_with_op( &mut self, session: &str, path: &Path, description: &str, op_id: Option<&str>, ) -> Result<String, AftError>
Snapshot the current contents of path under the given session namespace,
optionally tagging it with an operation id shared by all files touched by
one mutating tool call.
Sourcepub fn restore_last_operation(
&mut self,
session: &str,
) -> Result<RestoredOperation, AftError>
pub fn restore_last_operation( &mut self, session: &str, ) -> Result<RestoredOperation, AftError>
Restore every top-of-stack backup entry belonging to the most recent operation in this session.
Sourcepub fn restore_latest(
&mut self,
session: &str,
path: &Path,
) -> Result<(BackupEntry, Option<String>), AftError>
pub fn restore_latest( &mut self, session: &str, path: &Path, ) -> Result<(BackupEntry, Option<String>), AftError>
Pop the most recent backup for (session, path) and restore the file.
Returns (entry, optional_warning).
Sourcepub fn history(&self, session: &str, path: &Path) -> Vec<BackupEntry>
pub fn history(&self, session: &str, path: &Path) -> Vec<BackupEntry>
Return the backup history for (session, path) (oldest first).
Sourcepub fn disk_history_count(&self, session: &str, path: &Path) -> usize
pub fn disk_history_count(&self, session: &str, path: &Path) -> usize
Return the number of on-disk backup entries for (session, file).
Sourcepub fn tracked_files(&self, session: &str) -> Vec<PathBuf>
pub fn tracked_files(&self, session: &str) -> Vec<PathBuf>
Return all files that have at least one backup entry in this session (memory + disk). Other sessions’ files are not visible.
Sourcepub fn sessions_with_backups(&self) -> Vec<String>
pub fn sessions_with_backups(&self) -> Vec<String>
Return all session namespaces that currently have any backup state
(memory or disk). Exposed for /aft-status aggregate reporting.
Sourcepub fn total_disk_bytes(&self) -> u64
pub fn total_disk_bytes(&self) -> u64
Total on-disk bytes across all sessions (best-effort, reads metadata only).
Used by /aft-status to surface storage footprint.
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for BackupStore
impl RefUnwindSafe for BackupStore
impl Send for BackupStore
impl Sync for BackupStore
impl Unpin for BackupStore
impl UnsafeUnpin for BackupStore
impl UnwindSafe for BackupStore
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more