1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
//! # Agent Tools
//!
//! Agent tools for file operations, shell commands, HTTP requests, and task coordination.
//!
//! This module provides a comprehensive set of tools that can be used by LLM agents
//! to interact with the file system, execute commands, make HTTP requests, and
//! coordinate sub-agents.
//!
//! ## Tool Categories
//!
//! - **File Tools**: `ReadTool`, `WriteTool`, `EditTool`, `GlobTool`, `GrepTool`
//! - **Shell Tools**: `BashTool` (with safety validation to block dangerous commands)
//! - **Web Tools**: `FetchTool` (HTTP client supporting all methods)
//! - **Agent Tools**: `TaskTool` (sub-agent spawning), `TodoReadTool`, `TodoWriteTool`
//!
//! ## Key Features
//!
//! - **Workspace Boundary Enforcement**: All file operations are confined to the workspace directory
//! - **Command Safety**: Dangerous shell commands (rm -rf /, fork bombs, etc.) are automatically blocked
//! - **Session Isolation**: Todos and context are scoped to sessions
//! - **Recursion Limits**: Task tool enforces depth limits to prevent infinite loops
//! - **Timeout Support**: Shell and HTTP operations support configurable timeouts
//!
//! ## Quick Start
//!
//! ```rust,no_run
//! use sombrax_agentic_core::tools::{ToolContext, create_tool_set};
//! use std::path::PathBuf;
//!
//! // Create a context bound to a workspace directory
//! let context = ToolContext::new(
//! "session-123".to_string(),
//! PathBuf::from("/path/to/workspace"),
//! );
//!
//! // Create a registry with all tools
//! let tools = create_tool_set(context);
//! ```
//!
//! ## Using Individual Tools
//!
//! ```rust,no_run
//! use sombrax_agentic_core::tools::{ToolContext, ReadTool, BashTool};
//! use sombrax_agentic_core::tools::file::ReadArgs;
//! use sombrax_agentic_core::tools::shell::BashArgs;
//! use sombrax_agentic_core::tools::registry::Tool;
//! use std::path::PathBuf;
//!
//! # async fn example() -> Result<(), Box<dyn std::error::Error>> {
//! let context = ToolContext::new("session".to_string(), PathBuf::from("."));
//!
//! // Read a file
//! let read_tool = ReadTool::new(context.clone());
//! let output = read_tool.call(ReadArgs {
//! file_path: "Cargo.toml".to_string(),
//! description: None,
//! offset: None,
//! limit: None,
//! }).await?;
//! println!("Lines: {}", output.lines_read);
//!
//! // Execute a safe command
//! let bash_tool = BashTool::new(context);
//! let result = bash_tool.call(BashArgs {
//! command: "ls -la".to_string(),
//! timeout: Some(30_000),
//! description: Some("List files".to_string()),
//! }).await?;
//! println!("Exit code: {}", result.exit_code);
//! # Ok(())
//! # }
//! ```
//!
//! ## Sub-Agent Execution with AgentRuntime
//!
//! The TaskTool requires an [`AgentRuntime`] to spawn sub-agents.
//! Without a configured runtime, the tool returns an error.
//!
//! ```rust,no_run
//! use sombrax_agentic_core::tools::{ToolContext, TaskTool, create_tool_set_with_runtime};
//! use sombrax_agentic_core::tools::agent::{AgentRuntime, SubAgentRequest, SubAgentResponse};
//! use std::sync::Arc;
//! use std::path::PathBuf;
//!
//! // Implement AgentRuntime for your orchestrator
//! struct MyRuntime;
//!
//! #[async_trait::async_trait]
//! impl AgentRuntime for MyRuntime {
//! async fn spawn_subagent(&self, request: SubAgentRequest) -> Result<SubAgentResponse, String> {
//! // Delegate to your agent registry/orchestrator
//! todo!()
//! }
//! }
//!
//! // Create tool set with runtime
//! let context = ToolContext::new("session".into(), PathBuf::from("."));
//! let runtime: Arc<dyn AgentRuntime> = Arc::new(MyRuntime);
//! let tools = create_tool_set_with_runtime(context, runtime);
//! ```
//!
//! ## Architecture
//!
//! All tools implement the [`registry::Tool`] trait which provides:
//! - `definition()` - Returns JSON Schema for the tool's parameters
//! - `call()` - Executes the tool with provided arguments
//!
//! The [`ToolContext`] provides:
//! - Workspace boundary enforcement
//! - Session-scoped todo storage
//! - Child context creation for sub-agents
//! - Recursion depth tracking
use Future;
use Pin;
use Arc;
/// Wrapper to convert `tools::registry::Tool` to `tool::ToolDyn`.
///
/// This bridges the two tool systems in sac:
/// - `sombrax_agentic_core::tools::registry::Tool` - what built-in tools implement
/// - `sombrax_agentic_core::tool::ToolDyn` - what Agent uses for execution
;
/// Convert a registry Tool to an `Arc<dyn ToolDyn>` for use with Agent.
///
/// This allows using any tool that implements `sombrax_agentic_core::tools::registry::Tool`
/// with the Agent's tool execution system.
///
/// # Example
///
/// ```rust,no_run
/// use sombrax_agentic_core::tools::{ToolContext, ReadTool, into_tool_dyn};
/// use std::path::PathBuf;
///
/// let context = ToolContext::new("session".to_string(), PathBuf::from("."));
/// let read_tool = ReadTool::new(context);
/// let tool_dyn = into_tool_dyn(read_tool);
/// // Now tool_dyn can be used with Agent::tools()
/// ```
/// Skill tool for executing discovered skills.
// Re-export main types
pub use ToolContext;
pub use ToolError;
pub use ToolRegistry;
pub use ;
// Re-export file tools
pub use ;
// Re-export shell tools
pub use BashTool;
// Re-export web tools
pub use FetchTool;
// Re-export agent tools
pub use ;
// Re-export agent runtime types
pub use ;
// Re-export skill tool
pub use SkillTool;
/// Create a standard tool set with all available tools
///
/// Note: The TaskTool will operate in no-op mode without an AgentRuntime.
/// Use [`create_tool_set_with_runtime`] for full sub-agent support.
/// Create a standard tool set with an AgentRuntime for sub-agent execution
///
/// This function creates a complete tool set where TaskTool is wired to the
/// provided runtime for real sub-agent spawning.
///
/// # Arguments
/// * `context` - The tool execution context
/// * `runtime` - The agent runtime for spawning sub-agents
///
/// # Example
///
/// ```rust,no_run
/// use sombrax_agentic_core::tools::{ToolContext, create_tool_set_with_runtime};
/// use sombrax_agentic_core::tools::agent::{AgentRuntime, SubAgentRequest, SubAgentResponse};
/// use std::sync::Arc;
/// use std::path::PathBuf;
///
/// # struct MyRuntime;
/// # #[async_trait::async_trait]
/// # impl AgentRuntime for MyRuntime {
/// # async fn spawn_subagent(&self, _: SubAgentRequest) -> Result<SubAgentResponse, String> { todo!() }
/// # }
///
/// let context = ToolContext::new("session".into(), PathBuf::from("."));
/// let runtime: Arc<dyn AgentRuntime> = Arc::new(MyRuntime);
/// let tools = create_tool_set_with_runtime(context, runtime);
/// ```
/// Create a minimal tool set with file tools only