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
78#[cfg(feature = "smart-router")]
79pub mod smart_router;
80
81#[cfg(feature = "openapi")]
82pub mod openapi;
83
84// ── Public re-exports ────────────────────────────────────────────────────────
85
86// Always-available tools
87pub use error::{ResourceType, RetryStrategy, ToolErrorCategory, ToolOutcome, classify_error};
88pub use executor::{PreHookDecision, ToolExecutor, ToolPreHook};
89pub use registry::{ToolCategory, ToolRegistry};
90pub use sanitization::{
91    contains_sensitive_data, filter_tool_output, is_injection_attempt, redact_sensitive_data,
92    sanitize_external_content, wrap_with_content_source,
93};
94pub use tool_search::ToolSearchTool;
95
96// Native-only tools
97#[cfg(feature = "native")]
98pub use bash::BashTool;
99#[cfg(feature = "native")]
100pub use file_ops::FileOpsTool;
101#[cfg(feature = "native")]
102pub use git::GitTool;
103#[cfg(feature = "native")]
104pub use search::SearchTool;
105#[cfg(feature = "native")]
106pub use transaction::TransactionManager;
107#[cfg(feature = "native")]
108pub use validation::{ValidationTool, get_validation_tools};
109#[cfg(feature = "native")]
110pub use web::WebTool;
111
112// Feature-gated tools
113#[cfg(any(feature = "orchestrator", feature = "orchestrator-wasm"))]
114pub use orchestrator::OrchestratorTool;
115
116#[cfg(feature = "interpreters")]
117pub use code_exec::CodeExecTool;
118
119#[cfg(feature = "rag")]
120pub use semantic_search::SemanticSearchTool;
121
122#[cfg(feature = "rag")]
123pub use tool_embedding::ToolEmbeddingIndex;
124
125#[cfg(feature = "smart-router")]
126pub use smart_router::{
127    analyze_messages, analyze_query, get_context_for_analysis, get_smart_tools,
128    get_smart_tools_with_mcp, get_tools_for_categories,
129};
130
131#[cfg(feature = "openapi")]
132pub use openapi::{
133    HttpMethod, OpenApiAuth, OpenApiEndpoint, OpenApiParam, OpenApiTool, execute_openapi_tool,
134    openapi_to_tools,
135};