Skip to main content

BackupStore

Struct BackupStore 

Source
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.bak19.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

Source

pub fn new() -> Self

Source

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.

Source

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.

Source

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.

Source

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.

Source

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).

Source

pub fn history(&self, session: &str, path: &Path) -> Vec<BackupEntry>

Return the backup history for (session, path) (oldest first).

Source

pub fn disk_history_count(&self, session: &str, path: &Path) -> usize

Return the number of on-disk backup entries for (session, file).

Source

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.

Source

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.

Source

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§

Source§

impl Debug for BackupStore

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more