sgr-agent-tools
14 reusable file-system tools + 2 backends for sgr-agent AI agents.
All tools are generic over FileBackend — implement it once for your runtime and get battle-tested tools out of the box.
Tools
Core (always available)
| # | Tool | Description |
|---|---|---|
| 1 | ReadTool |
Read file with trust metadata + indentation-aware mode |
| 2 | WriteTool |
Write file with JSON auto-repair |
| 3 | DeleteTool |
Delete files (single or batch) |
| 4 | SearchTool |
Smart search: query expansion, fuzzy regex, Levenshtein, auto-expand |
| 5 | ListTool |
List directory |
| 6 | TreeTool |
Directory tree |
| 7 | ReadAllTool |
Batch read all files in directory |
| 8 | MkDirTool |
Create directory (deferred) |
| 9 | MoveTool |
Move/rename file (deferred) |
| 10 | FindTool |
Find by name pattern (deferred) |
Optional (feature-gated)
| # | Tool | Feature | Description |
|---|---|---|---|
| 11 | EvalTool |
eval |
JavaScript via Boa engine |
| 12 | ShellTool |
shell |
Shell command execution |
| 13 | ApplyPatchTool |
patch |
Codex-compatible diff DSL editing |
Backends
| Backend | Feature | Description |
|---|---|---|
LocalFs |
local-fs |
Local filesystem (tokio::fs, symlink-safe, spawn_blocking) |
MockFs |
(always) | In-memory for testing (zero deps, instant, deterministic) |
Quick start
# Via sgr-agent (recommended)
= { = "0.7", = ["tools-all"] }
# Standalone
= { = "0.4", = ["local-fs", "shell", "patch"] }
use Arc;
use ;
let fs = new;
let read = ReadTool;
let write = WriteTool;
let search = SearchTool;
Testing with MockFs
use ;
use Tool;
let fs = new;
fs.add_file;
fs.add_file;
let read = ReadTool;
let result = read.execute_readonly.await.unwrap;
assert!;
// Assert final state
assert_eq!;
assert!;
ApplyPatchTool DSL
Codex-compatible diff format — saves tokens vs full file rewrites:
*** Begin Patch
*** Update File: src/main.rs
@@ fn main()
- println!("old");
+ println!("new");
*** End Patch
4-level fuzzy matching: exact -> trim_end -> trim -> unicode normalize.
ShellTool
ReadTool indentation mode
Smart code block extraction — expand from anchor line by indent level:
Custom tools
use ;
use FileBackend;
;
Middleware pattern
Extend base tools without forking:
Features
| Feature | Default | Adds |
|---|---|---|
| (none) | yes | 10 core tools + MockFs |
eval |
no | EvalTool (Boa JS, ~5MB) |
shell |
no | ShellTool (tokio::process) |
patch |
no | ApplyPatchTool (Codex DSL) |
local-fs |
no | LocalFs backend (tokio::fs) |
Architecture
sgr-agent-core <- Tool, FileBackend, AgentContext (6 deps)
^ ^
sgr-agent-tools sgr-agent
(this crate) (framework, re-exports via "tools" feature)
Attribution
ApplyPatchTool parser adapted from Codex RS (Apache-2.0).
ReadTool indentation mode inspired by Codex RS read_file.