Skip to main content

sgr_agent_tools/
lib.rs

1//! sgr-agent-tools — 15 reusable file-system tools for sgr-agent based AI agents.
2//!
3//! All tools are generic over [`FileBackend`] trait.
4//!
5//! **Core (11):** ReadTool (+ indentation mode), WriteTool (JSON repair),
6//! DeleteTool (batch), SearchTool (smart search), ListTool, TreeTool,
7//! ReadAllTool, CopyTool, MkDirTool, MoveTool, FindTool.
8//!
9//! **Optional:** EvalTool (feature `eval`), ShellTool (feature `shell`),
10//! ApplyPatchTool (feature `patch` — Codex-compatible diff DSL).
11//!
12//! # Usage
13//!
14//! ```rust,ignore
15//! use sgr_agent_tools::{FileBackend, TreeTool, ReadTool, SearchTool, WriteTool};
16//!
17//! // Implement FileBackend for your runtime
18//! impl FileBackend for MyBackend { ... }
19//!
20//! // Create tools
21//! let b = Arc::new(MyBackend::new());
22//! let registry = ToolRegistry::new()
23//!     .register(ReadTool(b.clone()))
24//!     .register(WriteTool(b.clone()))
25//!     .register(SearchTool(b.clone()))
26//!     .register(TreeTool(b.clone()))
27//!     .register_deferred(MkDirTool(b.clone()));
28//! ```
29
30pub mod backend;
31pub mod helpers;
32pub mod trust;
33
34// Core tools
35pub mod delete;
36pub mod list;
37pub mod read;
38pub mod read_all;
39pub mod search;
40pub mod tree;
41pub mod write;
42
43// Dynamic context injection for skills
44pub mod skill_context;
45
46// Plan checklist tool (Codex-compatible update_plan)
47pub mod plan;
48
49// Deferred tools
50pub mod copy;
51pub mod find;
52pub mod mkdir;
53pub mod move_file;
54pub mod prepend;
55
56// Optional: eval (heavy dep on boa_engine)
57#[cfg(feature = "eval")]
58pub mod eval;
59
60// Optional: shell (needs tokio process feature)
61#[cfg(feature = "shell")]
62pub mod shell;
63
64// Optional: apply_patch (Codex-compatible diff editing)
65#[cfg(feature = "patch")]
66pub mod apply_patch;
67
68// Optional: local filesystem backend (std::fs + tokio::fs)
69#[cfg(feature = "local-fs")]
70pub mod local_fs;
71
72// In-memory mock backend (always available, zero deps)
73pub mod mock_fs;
74
75// Re-export the core trait
76pub use backend::FileBackend;
77
78#[cfg(feature = "local-fs")]
79pub use local_fs::LocalFs;
80pub use mock_fs::MockFs;
81
82// Re-export all tools
83pub use copy::CopyTool;
84pub use delete::DeleteTool;
85pub use find::FindTool;
86pub use list::ListTool;
87pub use mkdir::MkDirTool;
88pub use move_file::MoveTool;
89pub use prepend::PrependTool;
90pub use read::ReadTool;
91pub use read_all::ReadAllTool;
92pub use search::SearchTool;
93pub use tree::TreeTool;
94pub use write::WriteTool;
95
96pub use plan::{PlanState, PlanStep, UpdatePlanTool};
97
98#[cfg(feature = "eval")]
99pub use eval::EvalTool;
100
101#[cfg(feature = "shell")]
102pub use shell::ShellTool;
103
104#[cfg(feature = "patch")]
105pub use apply_patch::ApplyPatchTool;
106
107// Re-export helpers for wrapper tools (PAC1 uses these for Pac1SearchTool, etc.)
108pub use helpers::{backend_err, has_matches, truncate_output, unique_files_from_search};
109pub use search::{auto_expand_search, expand_query, fuzzy_regex, is_regex, smart_search};
110pub use trust::{infer_trust, wrap_with_meta};