Skip to main content

LocalFileStorage

Struct LocalFileStorage 

Source
pub struct LocalFileStorage { /* private fields */ }
Expand description

Storage that keeps each key as a file under a base directory (LocalFileStorage).

The key’s / segments map onto directories: key a/b.json is the file <base_dir>/a/b.json. Writes are atomic: the bytes go to a scratch sibling that is then renamed over the target, so a crash mid-write never leaves a partial file. Missing directories are created on write. Bound to a Sandbox (see for_sandbox), all I/O goes through the sandbox instead, and atomicity is the sandbox’s.

The harness keeps its sessions in LocalFileStorage::new("./.agent").namespace("sessions"), the on-disk layout shared with the other Strands harness SDKs.

use strands::storage::{LocalFileStorage, Storage};

let sessions = LocalFileStorage::new(&root).namespace("sessions")?;
sessions.write("abc/scopes/agent/default/snapshots/snapshot_latest.json", b"{}").await?;
assert!(root.join("sessions/abc/scopes/agent/default/snapshots/snapshot_latest.json").is_file());

Implementations§

Source§

impl LocalFileStorage

Source

pub fn new(base_dir: impl AsRef<Path>) -> Self

Storage rooted at base_dir, using the default keyword search.

Source

pub fn with_config( base_dir: impl AsRef<Path>, config: LocalFileStorageConfig, ) -> Result<Self>

Storage rooted at base_dir, with options.

§Errors

When config combines a sandbox with a search strategy that requires host filesystem access.

Source

pub fn for_sandbox(&self, sandbox: Arc<dyn Sandbox>) -> Self

A storage with the same base directory whose I/O goes through sandbox.

Storage already bound to a sandbox comes back unchanged. A search strategy that requires host filesystem access is dropped with a warning, falling back to the keyword scan, which reads through the sandbox.

Source

pub fn base_dir(&self) -> &Path

The root directory of this storage, with repeated and trailing separators removed.

Source

pub fn namespace(&self, prefix: &str) -> Result<Self>

A storage rooted at the prefix subdirectory, sharing this storage’s search strategy.

§Errors

Returns a StorageError when the prefix contains a backslash, a .. segment, or a segment the platform does not read as one plain name (a Windows drive prefix).

Source

pub async fn search(&self, query: &str) -> Result<Vec<StorageSearchResult>>

Searches the stored files with the configured strategy or the default keyword scan.

§Errors

Returns the strategy’s error, or a StorageError when the keyword scan cannot list.

Trait Implementations§

Source§

impl Clone for LocalFileStorage

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for LocalFileStorage

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for LocalFileStorage

Source§

fn default() -> Self

Storage rooted at ./.strands/.

Source§

impl Storage for LocalFileStorage

Source§

fn write<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, key: &'life1 str, data: &'life2 [u8], ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Stores data under key, overwriting any existing value. Read more
Source§

fn read<'life0, 'life1, 'async_trait>( &'life0 self, key: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<Option<Vec<u8>>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

The bytes stored under key, or None when no value exists. Read more
Source§

fn delete<'life0, 'life1, 'async_trait>( &'life0 self, key: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Deletes the value stored under key. A no-op when the key does not exist. Read more
Source§

fn list<'life0, 'life1, 'async_trait>( &'life0 self, prefix: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<Vec<String>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

The full keys that start with prefix, sorted ascending. An empty prefix lists every key. Read more
Source§

fn namespace(&self, prefix: &str) -> Option<Result<Arc<dyn Storage>>>

A view of this storage with every key prefixed by prefix (optional namespace). Read more
Source§

fn search<'life0, 'life1, 'async_trait>( &'life0 self, query: &'life1 str, ) -> Pin<Box<dyn Future<Output = Option<Result<Vec<StorageSearchResult>>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Searches stored content for query, best match first (optional search). Read more
Source§

fn storage_type(&self) -> &str

The backend’s type name, recorded as the archive storageType. Read more
Source§

fn is_namespaced(&self) -> bool

Whether this is already a namespaced view, so constructs that scope storage under a default prefix use it as it is.
Source§

fn is_ephemeral(&self) -> bool

Whether stored data is lost when the process exits.

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
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> FutureExt for T

§

fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ

Attaches the provided Context to this type, returning a WithContext wrapper. Read more
§

fn with_current_context(self) -> WithContext<Self> ⓘ

Attaches the current Context to this type, returning a WithContext wrapper. Read more
§

impl<T> Instrument for T

§

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

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

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
§

impl<Unshared, Shared> IntoShared<Shared> for Unshared
where Shared: FromUnshared<Unshared>,

§

fn into_shared(self) -> Shared

Creates a shared type from an unshared type.
Source§

impl<S> IntoStorage for S
where S: Storage,

Source§

fn into_storage(self) -> Arc<dyn Storage> ⓘ

The storage, shared.
§

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

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + 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
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + 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
§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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

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

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

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