Skip to main content

adk_devtools/
lib.rs

1//! # adk-devtools
2//!
3//! Developer tools for ADK-Rust coding agents — `read_file`, `write_file`,
4//! `edit_file`, `apply_patch`, `glob`, `grep`, and `bash` — all scoped to a sandboxed
5//! [`Workspace`].
6//!
7//! These are the inner-loop tools a coding agent needs: read and edit files,
8//! search the tree, and run commands/tests. Every operation is rooted at a
9//! workspace directory and rejected if it escapes; mutations and `bash` are
10//! gated by the workspace's capability flags.
11//!
12//! ## Quick start
13//!
14//! ```rust
15//! use adk_devtools::{DevToolset, Workspace};
16//! use std::sync::Arc;
17//!
18//! // `bash` is off by default; enable it only for agents that need a shell.
19//! let workspace = Workspace::new("./my-repo").allow_bash(true);
20//! assert!(workspace.bash_allowed());
21//!
22//! // Register with an agent: `LlmAgentBuilder::new("coding-agent").toolset(toolset)`.
23//! let toolset = Arc::new(DevToolset::new(workspace));
24//! # let _ = toolset;
25//! ```
26//!
27//! ## Sandboxing
28//!
29//! [`Workspace`] enforces **path containment** (no escaping the root),
30//! **read-only** mode (deny writes/bash), **opt-in bash** (off until
31//! [`Workspace::allow_bash`] enables it), a **bash timeout** that a call
32//! can shorten but not extend, and **secret exclusion**: `grep` and `glob` skip
33//! files matching [`DEFAULT_EXCLUDE_GLOBS`] and `read_file` refuses them with
34//! [`DevToolError::Excluded`]. `edit_file` requires a prior `read_file` by the same
35//! session and agent, and refuses a file that changed since with
36//! [`DevToolError::Stale`]: every read and write records the file's sha256 in a
37//! [`ReadLedger`], which a host can persist with [`Workspace::with_read_ledger`].
38//! `edit_file`, `write_file` and `apply_patch` also take `expect_sha256`, the content a
39//! decision approved, and write nothing when the file differs (spec 3.1 §7.26).
40//!
41//! `bash` runs host-local through [`HostLauncher`] with a cleared environment plus
42//! [`DEFAULT_ENV_ALLOWLIST`], so provider API keys in the agent process are not
43//! visible to commands. The command reads end of file from standard input, runs in
44//! a new session with no controlling terminal, and its process group is killed when
45//! the shell exits, so nothing it starts outlives the call. For strong isolation,
46//! give [`BashTool::with_launcher`] a [`CommandLauncher`] that wraps the script in a
47//! sandbox, or run commands behind a containerized `adk-code` executor (see
48//! `docs/design/coding-agent.md`). The policy vocabulary is aligned with
49//! `adk-code`'s `SandboxPolicy`.
50
51#[cfg(any(unix, windows))]
52mod beneath;
53mod error;
54mod launcher;
55mod read_ledger;
56mod toolset;
57mod workspace;
58
59pub mod patch;
60pub mod tools;
61
62/// A process a [`CommandLauncher`] started itself in a Job Object, which
63/// [`CommandLauncher::spawn_contained`] returns (Windows, spec 3.2 §10 W5).
64#[cfg(windows)]
65pub use adk_sandbox::process_tree::ContainedChild;
66pub use error::DevToolError;
67pub use launcher::{CommandLauncher, HostLauncher, LaunchGuard};
68pub use read_ledger::{InMemoryReadLedger, ReadLedger, ReadScope, sha256_hex};
69pub use tools::{
70    ApplyPatchTool, BashTool, BoundedOutput, DEFAULT_MAX_INLINE_BYTES, EditFileTool, GlobTool,
71    GrepTool, INLINE_OUTPUT_CHARS, OutputFile, OutputStore, ReadFileTool, RunningCommand,
72    WriteFileTool, bound_output, sniff_inline_mime,
73};
74pub use toolset::DevToolset;
75pub use workspace::{
76    DEFAULT_ENV_ALLOWLIST, DEFAULT_EXCLUDE_GLOBS, DEFAULT_MAX_OUTPUT_BYTES, Workspace,
77};