Skip to main content

brainwires_tool_system/
lib.rs

1#![deny(missing_docs)]
2//! Brainwires Tools - Built-in tool implementations for the Brainwires Agent Framework
3//!
4//! This crate provides a composable set of tools that agents can use:
5//!
6//! ## Always Available
7//! - **bash** - Shell command execution with proactive output management
8//! - **file_ops** - File read/write/edit/patch/list/search/delete/create_directory
9//! - **git** - Git operations (status, diff, log, stage, commit, push, pull, etc.)
10//! - **web** - URL fetching
11//! - **search** - Regex-based code search (respects .gitignore)
12//! - **validation** - Code quality checks (duplicates, build, syntax)
13//! - **tool_search** - Meta-tool for dynamic tool discovery
14//! - **error** - Error taxonomy and classification for retry strategies
15//!
16//! ## Feature-Gated
17//! - **orchestrator** (`orchestrator` feature) - Rhai script orchestration
18//! - **code_exec** (`interpreters` feature) - Sandboxed multi-language code execution
19//! - **semantic_search** (`rag` feature) - RAG-powered semantic codebase search
20//!
21//! ## Registry
22//! The `ToolRegistry` is a composable container. Create one and register
23//! whichever tools you need, or use `ToolRegistry::with_builtins()` for all.
24//!
25//! ```ignore
26//! use brainwires_tool_system::{ToolRegistry, BashTool, FileOpsTool};
27//!
28//! let mut registry = ToolRegistry::new();
29//! registry.register_tools(BashTool::get_tools());
30//! registry.register_tools(FileOpsTool::get_tools());
31//! ```
32
33// Re-export core types for convenience
34pub use brainwires_core::{
35    CommitResult, IdempotencyRecord, IdempotencyRegistry, StagedWrite, StagingBackend, Tool,
36    ToolContext, ToolInputSchema, ToolResult,
37};
38
39// ── Always-available modules (pure logic, WASM-safe) ────────────────────────
40
41mod error;
42pub mod executor;
43mod registry;
44pub mod sanitization;
45mod tool_search;
46
47// ── Native-only modules (require filesystem, process, network) ──────────────
48
49#[cfg(feature = "native")]
50mod bash;
51#[cfg(feature = "native")]
52mod file_ops;
53#[cfg(feature = "native")]
54mod git;
55#[cfg(feature = "native")]
56mod search;
57#[cfg(feature = "native")]
58pub mod transaction;
59#[cfg(feature = "native")]
60pub mod validation;
61#[cfg(feature = "native")]
62mod web;
63
64// ── Feature-gated modules ────────────────────────────────────────────────────
65
66#[cfg(any(feature = "orchestrator", feature = "orchestrator-wasm"))]
67pub mod orchestrator;
68
69#[cfg(feature = "interpreters")]
70mod code_exec;
71
72#[cfg(feature = "rag")]
73mod semantic_search;
74
75#[cfg(feature = "rag")]
76mod tool_embedding;
77
78pub mod smart_router;
79
80#[cfg(feature = "openapi")]
81pub mod openapi;
82
83// ── Public re-exports ────────────────────────────────────────────────────────
84
85// Always-available tools
86pub use error::{ResourceType, RetryStrategy, ToolErrorCategory, ToolOutcome, classify_error};
87pub use executor::{PreHookDecision, ToolExecutor, ToolPreHook};
88pub use registry::{ToolCategory, ToolRegistry};
89pub use sanitization::{
90    contains_sensitive_data, filter_tool_output, is_injection_attempt, redact_sensitive_data,
91    sanitize_external_content, wrap_with_content_source,
92};
93pub use tool_search::ToolSearchTool;
94
95// Native-only tools
96#[cfg(feature = "native")]
97pub use bash::BashTool;
98#[cfg(feature = "native")]
99pub use file_ops::FileOpsTool;
100#[cfg(feature = "native")]
101pub use git::GitTool;
102#[cfg(feature = "native")]
103pub use search::SearchTool;
104#[cfg(feature = "native")]
105pub use transaction::TransactionManager;
106#[cfg(feature = "native")]
107pub use validation::{ValidationTool, get_validation_tools};
108#[cfg(feature = "native")]
109pub use web::WebTool;
110
111// Feature-gated tools
112#[cfg(any(feature = "orchestrator", feature = "orchestrator-wasm"))]
113pub use orchestrator::OrchestratorTool;
114
115#[cfg(feature = "interpreters")]
116pub use code_exec::CodeExecTool;
117
118#[cfg(feature = "rag")]
119pub use semantic_search::SemanticSearchTool;
120
121#[cfg(feature = "rag")]
122pub use tool_embedding::ToolEmbeddingIndex;
123
124pub use smart_router::{
125    analyze_messages, analyze_query, get_context_for_analysis, get_smart_tools,
126    get_smart_tools_with_mcp, get_tools_for_categories,
127};
128
129#[cfg(feature = "openapi")]
130pub use openapi::{
131    HttpMethod, OpenApiAuth, OpenApiEndpoint, OpenApiParam, OpenApiTool, execute_openapi_tool,
132    openapi_to_tools,
133};