pub struct Workspace { /* private fields */ }harness only.Expand description
The directory the harness works in, re-exported so a harness needs no direct
adk-devtools dependency.
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 records the sha256 of every file read and of every file its tools
write, so that edit_file can require a prior read_file and refuse to edit a file
that changed since (spec 3.1 §7.26, §10 D7). The record is kept per session and agent,
taken from the tool call’s context, so one session or agent reading a file does not let
another edit it. Records live in a ReadLedger, in memory unless
with_read_ledger names a persistent one.
Workspace is cheap to clone. Clones share the read records, which stay
separated by session and agent; calls whose context names no session share one
record, kept in memory.
Implementations§
Source§impl Workspace
impl Workspace
Sourcepub fn new(root: impl Into<PathBuf>) -> Workspace
pub fn new(root: impl Into<PathBuf>) -> Workspace
Create a read-write workspace rooted at root, with bash disabled.
bash runs model-written commands on the host, outside the path containment the file
tools enforce, so it is off until allow_bash enables it. If root
exists it is canonicalized so containment checks are robust.
§Example
use adk_devtools::Workspace;
let files_only = Workspace::new("./my-repo");
assert!(!files_only.bash_allowed());
let with_shell = Workspace::new("./my-repo").allow_bash(true);
assert!(with_shell.bash_allowed());Sourcepub fn read_only(root: impl Into<PathBuf>) -> Workspace
pub fn read_only(root: impl Into<PathBuf>) -> Workspace
Create a read-only workspace (no writes, no bash) — useful for exploration / plan modes.
Sourcepub fn writable(self, yes: bool) -> Workspace
pub fn writable(self, yes: bool) -> Workspace
Set whether mutating file operations are permitted.
Sourcepub fn allow_bash(self, yes: bool) -> Workspace
pub fn allow_bash(self, yes: bool) -> Workspace
Set whether the bash tool is permitted. Off by default.
Commands run with the workspace root as their working directory, which is not a sandbox: they can reach absolute paths and the network.
Sourcepub fn bash_timeout(self, timeout: Duration) -> Workspace
pub fn bash_timeout(self, timeout: Duration) -> Workspace
Set the timeout applied to bash commands, and the most a call may request.
Sourcepub fn max_output_bytes(self, bytes: usize) -> Workspace
pub fn max_output_bytes(self, bytes: usize) -> Workspace
Set the most bytes of a bash command’s output an
OutputStore file keeps: the disk bound (default
DEFAULT_MAX_OUTPUT_BYTES, 64 MiB; spec 3.1 §10 D10). The result itself carries at
most INLINE_OUTPUT_CHARS characters whatever this
is, and memory holds only the start and end of each stream.
§Example
use adk_devtools::Workspace;
let ws = Workspace::new(".").allow_bash(true).max_output_bytes(8 * 1024 * 1024);
assert_eq!(ws.max_output(), 8 * 1024 * 1024);Sourcepub fn inherit_env(self, yes: bool) -> Workspace
pub fn inherit_env(self, yes: bool) -> Workspace
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.
Sourcepub fn env_allowlist<I, S>(self, keys: I) -> Workspace
pub fn env_allowlist<I, S>(self, keys: I) -> Workspace
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.
Sourcepub fn bash_kill_group_on_exit(self, yes: bool) -> Workspace
pub fn bash_kill_group_on_exit(self, yes: bool) -> Workspace
Set whether bash kills the rest of the command’s process group once the
shell exits. On by default.
With it on, a process the command leaves running in the background — sleep 300 &,
a dev server — is killed when the call returns, and the call does not wait for
it to close its output. Turn it off only when commands must leave processes
running; a timeout or a cancelled call still kills the group. Implements spec 3.1
§10 D3.
§Example
use adk_devtools::Workspace;
let ws = Workspace::new("./my-repo").allow_bash(true);
assert!(ws.kills_bash_group_on_exit());
let keeps_servers = ws.bash_kill_group_on_exit(false);
assert!(!keeps_servers.kills_bash_group_on_exit());Sourcepub fn kills_bash_group_on_exit(&self) -> bool
pub fn kills_bash_group_on_exit(&self) -> bool
Whether bash kills the command’s process group once the shell exits.
Set with bash_kill_group_on_exit; spec 3.1 §10 D3.
Sourcepub fn with_read_ledger(self, ledger: Arc<dyn ReadLedger>) -> Workspace
pub fn with_read_ledger(self, ledger: Arc<dyn ReadLedger>) -> Workspace
Keep read records in ledger instead of process memory (spec 3.1 §10 D7).
A host that resumes a session in another process — a held edit approved from a new
process, a crash-resumed run, a kernel process moved between workers — persists the
records with the session, so the read that preceded an edit is still known. Clones
made after this call share ledger.
§Example
use std::sync::Arc;
use adk_devtools::{InMemoryReadLedger, Workspace};
let ws = Workspace::new("./my-repo").with_read_ledger(Arc::new(InMemoryReadLedger::new()));
assert!(ws.is_writable());Sourcepub fn exclude_globs(self, globs: impl IntoIterator<Item = String>) -> Workspace
pub fn exclude_globs(self, globs: impl IntoIterator<Item = String>) -> Workspace
Replace the file patterns grep and glob skip and read_file refuses.
Defaults to DEFAULT_EXCLUDE_GLOBS; an empty list turns exclusion off. Each
pattern is a glob matched, ignoring case, against the path relative to the
root and against each of its components, so .env also excludes
config/.env and secrets/** everything under secrets/. A pattern that is
not a valid glob matches its literal text. Implements spec 3.1 §10 D5.
§Example
use std::path::Path;
use adk_devtools::Workspace;
let ws = Workspace::new("./my-repo").exclude_globs(["secrets/**".to_string()]);
assert!(ws.is_excluded(Path::new("secrets/prod/token.txt")));
assert!(!ws.is_excluded(Path::new(".env")));
let everything = Workspace::new("./my-repo").exclude_globs([]);
assert!(!everything.is_excluded(Path::new(".env")));Sourcepub fn is_excluded(&self, path: &Path) -> bool
pub fn is_excluded(&self, path: &Path) -> bool
Whether path matches one of the exclusion patterns.
path is relative to the root, or an absolute path inside it. The check is
lexical; read_file also checks the path a symlink resolves to. A harness
uses it to require approval before a read. Implements spec 3.1 §10 D5.
§Example
use std::path::Path;
use adk_devtools::Workspace;
let ws = Workspace::new("./my-repo");
assert!(ws.is_excluded(Path::new("deploy/server.KEY")));
assert!(!ws.is_excluded(Path::new("src/keys.rs")));Sourcepub fn inherits_env(&self) -> bool
pub fn inherits_env(&self) -> bool
Whether bash inherits the parent environment.
Sourcepub fn bash_env(&self) -> Vec<(String, String)>
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.
Sourcepub fn is_writable(&self) -> bool
pub fn is_writable(&self) -> bool
Whether mutating file operations are permitted.
Sourcepub fn bash_allowed(&self) -> bool
pub fn bash_allowed(&self) -> bool
Whether the bash tool is permitted.
Sourcepub fn bash_timeout_value(&self) -> Duration
pub fn bash_timeout_value(&self) -> Duration
The default bash timeout.
Sourcepub fn max_output(&self) -> usize
pub fn max_output(&self) -> usize
The most bytes of a command’s output its output file keeps.
Sourcepub fn resolve(&self, path: &str) -> Result<PathBuf, DevToolError>
pub fn resolve(&self, path: &str) -> Result<PathBuf, DevToolError>
Resolve a user-supplied path against the root, rejecting any path that escapes it, lexically or through a symlink. The target need not exist yet.
The returned path is the lexical one. The file tools open the canonical target the same check finds, following no symlink on it, so a link swapped onto the path after the check fails the call (spec 3.1 §10 D4).
Sourcepub fn display(&self, path: &Path) -> String
pub fn display(&self, path: &Path) -> String
Render a path relative to the root for display (falls back to the full path).
Sourcepub fn record_path(&self, resolved: &Path) -> String
pub fn record_path(&self, resolved: &Path) -> String
The key a read record names resolved by: its path relative to the root with /
separators, so a record written on one platform matches on another.
Sourcepub fn record_key(&self, path: &str) -> Result<String, DevToolError>
pub fn record_key(&self, path: &str) -> Result<String, DevToolError>
The key a read record and an expect_sha256 map name path by, after the
containment check: its path relative to the root with / separators.
§Errors
Returns DevToolError::PathEscape for a path outside the root.
§Example
let dir = tempfile::tempdir().unwrap();
let ws = adk_devtools::Workspace::new(dir.path());
assert_eq!(ws.record_key("./src/../src/lib.rs").unwrap(), "src/lib.rs");
assert!(ws.record_key("../outside").is_err());Sourcepub async fn read_for_review(
&self,
path: &str,
) -> Result<Option<Vec<u8>>, DevToolError>
pub async fn read_for_review( &self, path: &str, ) -> Result<Option<Vec<u8>>, DevToolError>
Reads path for a reviewer under the file tools’ rules — containment, no symlink
followed, excluded secret files refused — returning None when it does not exist
(spec 3.1 §7.26: a change set is composed over what the tools would read).
§Errors
Returns DevToolError::PathEscape, DevToolError::Excluded, or the read error.
§Example
let ws = adk_devtools::Workspace::new("./my-repo");
let current = ws.read_for_review("src/lib.rs").await?;Sourcepub async fn record_current(
&self,
ctx: &dyn ToolContext,
path: &str,
) -> Result<(), DevToolError>
pub async fn record_current( &self, ctx: &dyn ToolContext, path: &str, ) -> Result<(), DevToolError>
Records the current content of path as what the session and agent behind ctx
last saw, for a host step that changes a file right after the agent wrote it — a
formatter hook — so the agent’s next edit is not refused as stale (spec 3.1 §7.22,
§7.26).
§Errors
Returns the containment or read error for path.
§Example
ws.record_current(ctx, "src/lib.rs").await.unwrap();Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for Workspace
impl !UnwindSafe for Workspace
impl Forget for Workspace
impl Freeze for Workspacewhere
*const u8 is !null: Freeze,
PhantomData<u8>: Freeze,
*const ArcInner<dyn ReadLedger> is !null: Freeze,
PhantomData<ArcInner<dyn ReadLedger>>: Freeze,
*const ArcInner<Mutex<HashMap<String, String>>> is !null: Freeze,
PhantomData<ArcInner<Mutex<HashMap<String, String>>>>: Freeze,
PhantomData<String>: Freeze,
PhantomData<Pattern>: Freeze,
impl Move for Workspace
impl Send for Workspace
impl Sync for Workspace
impl Unpin for Workspace
impl UnsafeUnpin for Workspacewhere
*const u8 is !null: UnsafeUnpin,
PhantomData<u8>: UnsafeUnpin,
*const ArcInner<dyn ReadLedger> is !null: UnsafeUnpin,
PhantomData<ArcInner<dyn ReadLedger>>: UnsafeUnpin,
*const ArcInner<Mutex<HashMap<String, String>>> is !null: UnsafeUnpin,
PhantomData<ArcInner<Mutex<HashMap<String, String>>>>: UnsafeUnpin,
PhantomData<String>: UnsafeUnpin,
PhantomData<Pattern>: UnsafeUnpin,
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> FmtForward for T
impl<T> FmtForward for T
Source§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self to use its Binary implementation when Debug-formatted.Source§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self to use its Display implementation when
Debug-formatted.Source§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self to use its LowerExp implementation when
Debug-formatted.Source§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self to use its LowerHex implementation when
Debug-formatted.Source§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self to use its Octal implementation when Debug-formatted.Source§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self to use its Pointer implementation when
Debug-formatted.Source§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self to use its UpperExp implementation when
Debug-formatted.Source§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self to use its UpperHex implementation when
Debug-formatted.Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
Source§fn with_current_context(self) -> WithContext<Self> ⓘ
fn with_current_context(self) -> WithContext<Self> ⓘ
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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 moreimpl<T> MaybeSend for Twhere
T: Send,
Source§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
Source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
Source§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
Source§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
Source§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self, then passes self.as_ref() into the pipe function.Source§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self, then passes self.as_mut() into the pipe
function.Source§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self, then passes self.deref() into the pipe function.Source§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.Source§impl<T> Tap for T
impl<T> Tap for T
Source§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B> of a value. Read moreSource§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B> of a value. Read moreSource§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R> view of a value. Read moreSource§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R> view of a value. Read moreSource§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.Source§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut() only in debug builds, and is erased in release
builds.Source§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref() only in debug builds, and is erased in release
builds.Source§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut() only in debug builds, and is erased in release
builds.Source§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref() only in debug builds, and is erased in release
builds.