Skip to main content

SessionEnv

Trait SessionEnv 

Source
pub trait SessionEnv: Send + Sync {
    // Required methods
    fn read_file<'life0, 'life1, 'async_trait>(
        &'life0 self,
        path: &'life1 Path,
        max_lines: usize,
        max_bytes: usize,
    ) -> Pin<Box<dyn Future<Output = RuntimeResult<String>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn read_file_full<'life0, 'life1, 'async_trait>(
        &'life0 self,
        path: &'life1 Path,
        max_bytes: usize,
    ) -> Pin<Box<dyn Future<Output = RuntimeResult<String>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn write_file<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        path: &'life1 Path,
        content: &'life2 str,
    ) -> Pin<Box<dyn Future<Output = RuntimeResult<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait;
    fn exec<'life0, 'life1, 'life2, 'life3, 'async_trait>(
        &'life0 self,
        command: &'life1 str,
        cwd: &'life2 Path,
        timeout_ms: Option<u64>,
        cancel: &'life3 CancellationToken,
    ) -> Pin<Box<dyn Future<Output = RuntimeResult<ShellResult>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait,
             'life3: 'async_trait;
    fn glob<'life0, 'life1, 'async_trait>(
        &'life0 self,
        pattern: &'life1 str,
        limit: usize,
    ) -> Pin<Box<dyn Future<Output = RuntimeResult<Vec<String>>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn grep<'life0, 'life1, 'life2, 'life3, 'async_trait>(
        &'life0 self,
        pattern: &'life1 str,
        paths: &'life2 [&'life3 str],
        max_matches: usize,
    ) -> Pin<Box<dyn Future<Output = RuntimeResult<Vec<String>>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait,
             'life3: 'async_trait;
}
Expand description

The environment a session runs in.

Every method is async and fallible so it can be backed by anything from a real local directory to a remote container API (E2B, Daytona, …).

Required Methods§

Source

fn read_file<'life0, 'life1, 'async_trait>( &'life0 self, path: &'life1 Path, max_lines: usize, max_bytes: usize, ) -> Pin<Box<dyn Future<Output = RuntimeResult<String>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Read a file, bounded by max_lines / max_bytes.

Source

fn read_file_full<'life0, 'life1, 'async_trait>( &'life0 self, path: &'life1 Path, max_bytes: usize, ) -> Pin<Box<dyn Future<Output = RuntimeResult<String>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Read a file in full, erroring (NOT truncating) if it exceeds max_bytes.

Use for tools that must operate on the complete file (e.g. edit, which writes the file back): the bounded read_file silently truncates large files and would cause data loss on write-back. This method checks the file size (via metadata, before reading) and returns crate::error::RuntimeError::FileTooLarge if the file is too big, so the caller never operates on partial data. Path containment is enforced as for read_file.

Source

fn write_file<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, path: &'life1 Path, content: &'life2 str, ) -> Pin<Box<dyn Future<Output = RuntimeResult<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Write a file, creating parent directories as needed.

Source

fn exec<'life0, 'life1, 'life2, 'life3, 'async_trait>( &'life0 self, command: &'life1 str, cwd: &'life2 Path, timeout_ms: Option<u64>, cancel: &'life3 CancellationToken, ) -> Pin<Box<dyn Future<Output = RuntimeResult<ShellResult>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait,

Run a shell command, with a timeout_ms hint and cancellation.

Implementations should select! on cancel.cancelled() and, for child processes, send SIGTERM (then SIGKILL after a grace period) on cancel.

Source

fn glob<'life0, 'life1, 'async_trait>( &'life0 self, pattern: &'life1 str, limit: usize, ) -> Pin<Box<dyn Future<Output = RuntimeResult<Vec<String>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

List files matching a glob (bounded by limit).

Source

fn grep<'life0, 'life1, 'life2, 'life3, 'async_trait>( &'life0 self, pattern: &'life1 str, paths: &'life2 [&'life3 str], max_matches: usize, ) -> Pin<Box<dyn Future<Output = RuntimeResult<Vec<String>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait,

Grep for pattern, bounded by max_matches.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§