pub trait Environment: Send + Sync {
Show 16 methods
// Required methods
fn read_file<'life0, 'life1, 'async_trait>(
&'life0 self,
path: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<String, Error>> + Send + 'async_trait>>
where 'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait;
fn read_file_bytes<'life0, 'life1, 'async_trait>(
&'life0 self,
path: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<Vec<u8>, Error>> + Send + 'async_trait>>
where 'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait;
fn write_file<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
path: &'life1 str,
content: &'life2 str,
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>
where 'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Self: 'async_trait;
fn write_file_bytes<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
path: &'life1 str,
content: &'life2 [u8],
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>
where 'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Self: 'async_trait;
fn list_dir<'life0, 'life1, 'async_trait>(
&'life0 self,
path: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<Vec<FileEntry>, Error>> + Send + 'async_trait>>
where 'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait;
fn exists<'life0, 'life1, 'async_trait>(
&'life0 self,
path: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<bool, Error>> + Send + 'async_trait>>
where 'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait;
fn is_dir<'life0, 'life1, 'async_trait>(
&'life0 self,
path: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<bool, Error>> + Send + 'async_trait>>
where 'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait;
fn is_file<'life0, 'life1, 'async_trait>(
&'life0 self,
path: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<bool, Error>> + Send + 'async_trait>>
where 'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait;
fn create_dir<'life0, 'life1, 'async_trait>(
&'life0 self,
path: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>
where 'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait;
fn delete_file<'life0, 'life1, 'async_trait>(
&'life0 self,
path: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>
where 'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait;
fn delete_dir<'life0, 'life1, 'async_trait>(
&'life0 self,
path: &'life1 str,
recursive: bool,
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>
where 'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait;
fn grep<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
pattern: &'life1 str,
path: &'life2 str,
recursive: bool,
) -> Pin<Box<dyn Future<Output = Result<Vec<GrepMatch>, Error>> + Send + 'async_trait>>
where 'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Self: 'async_trait;
fn glob<'life0, 'life1, 'async_trait>(
&'life0 self,
pattern: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<Vec<String>, Error>> + Send + 'async_trait>>
where 'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait;
fn root(&self) -> &str;
// Provided methods
fn exec<'life0, 'life1, 'async_trait>(
&'life0 self,
_command: &'life1 str,
_timeout_ms: Option<u64>,
) -> Pin<Box<dyn Future<Output = Result<ExecResult, Error>> + Send + 'async_trait>>
where 'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait { ... }
fn resolve_path(&self, path: &str) -> String { ... }
}Expand description
Environment abstraction for file and command operations.
The SDK’s primitive tools (Read, Write, Grep, Glob, Bash) use this trait to interact with the underlying filesystem or storage backend.
Implementations:
LocalFileSystem- Standard filesystem (provided by SDK)InMemoryFileSystem- For testing (provided by SDK)- Custom backends (S3, Git, iCloud, etc.)
Required Methods§
Sourcefn read_file<'life0, 'life1, 'async_trait>(
&'life0 self,
path: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<String, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
fn read_file<'life0, 'life1, 'async_trait>(
&'life0 self,
path: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<String, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
Sourcefn read_file_bytes<'life0, 'life1, 'async_trait>(
&'life0 self,
path: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<Vec<u8>, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
fn read_file_bytes<'life0, 'life1, 'async_trait>(
&'life0 self,
path: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<Vec<u8>, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
Sourcefn write_file<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
path: &'life1 str,
content: &'life2 str,
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Self: 'async_trait,
fn write_file<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
path: &'life1 str,
content: &'life2 str,
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Self: 'async_trait,
Write string content to file (creates or overwrites)
§Errors
Returns an error if the file cannot be written.
Sourcefn write_file_bytes<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
path: &'life1 str,
content: &'life2 [u8],
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Self: 'async_trait,
fn write_file_bytes<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
path: &'life1 str,
content: &'life2 [u8],
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Self: 'async_trait,
Sourcefn list_dir<'life0, 'life1, 'async_trait>(
&'life0 self,
path: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<Vec<FileEntry>, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
fn list_dir<'life0, 'life1, 'async_trait>(
&'life0 self,
path: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<Vec<FileEntry>, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
Sourcefn exists<'life0, 'life1, 'async_trait>(
&'life0 self,
path: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<bool, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
fn exists<'life0, 'life1, 'async_trait>(
&'life0 self,
path: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<bool, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
Sourcefn is_dir<'life0, 'life1, 'async_trait>(
&'life0 self,
path: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<bool, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
fn is_dir<'life0, 'life1, 'async_trait>(
&'life0 self,
path: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<bool, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
Sourcefn is_file<'life0, 'life1, 'async_trait>(
&'life0 self,
path: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<bool, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
fn is_file<'life0, 'life1, 'async_trait>(
&'life0 self,
path: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<bool, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
Sourcefn create_dir<'life0, 'life1, 'async_trait>(
&'life0 self,
path: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
fn create_dir<'life0, 'life1, 'async_trait>(
&'life0 self,
path: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
Sourcefn delete_file<'life0, 'life1, 'async_trait>(
&'life0 self,
path: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
fn delete_file<'life0, 'life1, 'async_trait>(
&'life0 self,
path: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
Sourcefn delete_dir<'life0, 'life1, 'async_trait>(
&'life0 self,
path: &'life1 str,
recursive: bool,
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
fn delete_dir<'life0, 'life1, 'async_trait>(
&'life0 self,
path: &'life1 str,
recursive: bool,
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
Delete directory (must be empty unless recursive)
§Errors
Returns an error if the directory cannot be deleted.
Sourcefn grep<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
pattern: &'life1 str,
path: &'life2 str,
recursive: bool,
) -> Pin<Box<dyn Future<Output = Result<Vec<GrepMatch>, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Self: 'async_trait,
fn grep<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
pattern: &'life1 str,
path: &'life2 str,
recursive: bool,
) -> Pin<Box<dyn Future<Output = Result<Vec<GrepMatch>, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Self: 'async_trait,
Provided Methods§
Sourcefn exec<'life0, 'life1, 'async_trait>(
&'life0 self,
_command: &'life1 str,
_timeout_ms: Option<u64>,
) -> Pin<Box<dyn Future<Output = Result<ExecResult, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
fn exec<'life0, 'life1, 'async_trait>(
&'life0 self,
_command: &'life1 str,
_timeout_ms: Option<u64>,
) -> Pin<Box<dyn Future<Output = Result<ExecResult, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
Execute a shell command
Not all environments support this. Default implementation returns an error.
§Errors
Returns an error if command execution is not supported or fails.
Sourcefn resolve_path(&self, path: &str) -> String
fn resolve_path(&self, path: &str) -> String
Resolve an input path to an absolute path clamped to root.
This is the path-policy boundary for primitive tools: it interprets the
model-supplied path against the environment root and guarantees the
result can never lexically escape that root. Relative inputs are joined
to the root; absolute inputs are accepted only when they already fall
inside the root, otherwise they (and any .. traversal) are clamped
back inside it. So with root = /workspace, both ../../etc/passwd
and /etc/passwd resolve to a path under /workspace, never to the
host’s /etc/passwd.
§Security
The clamp is lexical (it does not touch the filesystem) so it cannot
detect a symlink inside the root that points outside it. Callers that
resolve against a real filesystem and need a symlink-proof boundary must
use resolve_within_root_secure, which canonicalizes the path and
verifies containment after following links.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".