Skip to main content

Workspace

Struct Workspace 

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

A workspace roots every file/search/shell operation at a directory and enforces a small capability policy.

All paths supplied to the tools are resolved relative to root and rejected if they escape it. Mutating operations require is_writable; bash requires bash_allowed.

The workspace also carries a small amount of shared session state — the set of files that have been read — so that edit_file can require a prior read_file (guarding against blind overwrites).

Workspace is cheap to clone; clones share the read-tracking state.

Implementations§

Source§

impl Workspace

Source

pub fn new(root: impl Into<PathBuf>) -> Self

Create a read-write workspace rooted at root (bash enabled).

If root exists it is canonicalized so containment checks are robust.

Source

pub fn read_only(root: impl Into<PathBuf>) -> Self

Create a read-only workspace (no writes, no bash) — useful for exploration / plan modes.

Source

pub fn writable(self, yes: bool) -> Self

Set whether mutating file operations are permitted.

Source

pub fn allow_bash(self, yes: bool) -> Self

Set whether the bash tool is permitted.

Source

pub fn bash_timeout(self, timeout: Duration) -> Self

Set the default timeout applied to bash commands.

Source

pub fn max_output_bytes(self, bytes: usize) -> Self

Set the maximum number of bytes captured from a stream before truncation.

Source

pub fn inherit_env(self, yes: bool) -> Self

Pass the whole parent environment to bash.

Off by default, because the parent environment of an agent process routinely holds provider API keys and a model-directed command can read them with env. Enable it only when the commands you run genuinely need the caller’s environment and you accept that exposure.

Source

pub fn env_allowlist<I, S>(self, keys: I) -> Self
where I: IntoIterator<Item = S>, S: Into<String>,

Replace the variables bash receives when the environment is not inherited.

Defaults to DEFAULT_ENV_ALLOWLIST. Adding a variable that holds a credential re-exposes it.

Source

pub fn inherits_env(&self) -> bool

Whether bash inherits the parent environment.

Source

pub fn bash_env(&self) -> Vec<(String, String)>

The variables bash receives, resolved from the current process.

Empty when the environment is inherited, in which case the caller must not clear it.

Source

pub fn root(&self) -> &Path

The workspace root.

Source

pub fn is_writable(&self) -> bool

Whether mutating file operations are permitted.

Source

pub fn bash_allowed(&self) -> bool

Whether the bash tool is permitted.

Source

pub fn bash_timeout_value(&self) -> Duration

The default bash timeout.

Source

pub fn max_output(&self) -> usize

The output-capture cap.

Source

pub fn resolve(&self, path: &str) -> Result<PathBuf, DevToolError>

Resolve a user-supplied path against the root, rejecting any path that escapes it (lexically). The target need not exist yet.

Source

pub fn display(&self, path: &Path) -> String

Render a path relative to the root for display (falls back to the full path).

Trait Implementations§

Source§

impl Clone for Workspace

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

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