Skip to main content

brainwires_tools/
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//! - **email** (`email` feature) - Email send/search/read/list via IMAP/SMTP
21//! - **calendar** (`calendar` feature) - Calendar CRUD and free/busy via Google Calendar/CalDAV
22//!
23//! ## Registry
24//! The `ToolRegistry` is a composable container. Create one and register
25//! whichever tools you need, or use `ToolRegistry::with_builtins()` for all.
26//!
27//! ```ignore
28//! use brainwires_tools::{ToolRegistry, BashTool, FileOpsTool};
29//!
30//! let mut registry = ToolRegistry::new();
31//! registry.register_tools(BashTool::get_tools());
32//! registry.register_tools(FileOpsTool::get_tools());
33//! ```
34
35// Re-export core types for convenience
36pub use brainwires_core::{
37    CommitResult, IdempotencyRecord, IdempotencyRegistry, StagedWrite, StagingBackend, Tool,
38    ToolContext, ToolInputSchema, ToolResult,
39};
40
41// ── Always-available modules (pure logic, WASM-safe) ────────────────────────
42
43mod default_executor;
44mod error;
45pub mod executor;
46mod registry;
47pub mod sanitization;
48mod tool_search;
49
50// ── Native-only modules (require filesystem, process, network) ──────────────
51
52#[cfg(feature = "native")]
53mod bash;
54#[cfg(feature = "native")]
55mod file_ops;
56#[cfg(feature = "native")]
57mod git;
58#[cfg(feature = "native")]
59mod search;
60#[cfg(feature = "native")]
61pub mod transaction;
62#[cfg(feature = "native")]
63pub mod validation;
64#[cfg(feature = "native")]
65mod web;
66
67// ── Feature-gated modules ────────────────────────────────────────────────────
68
69#[cfg(any(feature = "orchestrator", feature = "orchestrator-wasm"))]
70pub mod orchestrator;
71
72#[cfg(feature = "interpreters")]
73mod code_exec;
74
75#[cfg(feature = "rag")]
76mod semantic_search;
77
78#[cfg(feature = "rag")]
79mod tool_embedding;
80
81pub mod smart_router;
82
83#[cfg(feature = "openapi")]
84pub mod openapi;
85
86#[cfg(feature = "email")]
87mod email;
88
89#[cfg(feature = "calendar")]
90mod calendar;
91
92#[cfg(feature = "browser")]
93mod browser;
94
95/// OAuth 2.0 client, token store, and PKCE helpers for tool integrations.
96#[cfg(feature = "oauth")]
97pub mod oauth;
98
99/// OS-level primitives — filesystem event watching and service management (absorbed from brainwires-system).
100#[cfg(feature = "system")]
101pub mod system;
102
103/// Sandboxed multi-language code interpreters (absorbed from brainwires-code-interpreters).
104#[cfg(feature = "interpreters")]
105pub mod interpreters;
106
107// ── Public re-exports ────────────────────────────────────────────────────────
108
109// Always-available tools
110pub use default_executor::BuiltinToolExecutor;
111pub use error::{ResourceType, RetryStrategy, ToolErrorCategory, ToolOutcome, classify_error};
112pub use executor::{PreHookDecision, ToolExecutor, ToolPreHook};
113pub use registry::{ToolCategory, ToolRegistry};
114pub use sanitization::{
115    contains_sensitive_data, filter_tool_output, is_injection_attempt, redact_sensitive_data,
116    sanitize_external_content, wrap_with_content_source,
117};
118pub use tool_search::ToolSearchTool;
119
120// Native-only tools
121#[cfg(feature = "native")]
122pub use bash::BashTool;
123#[cfg(feature = "native")]
124pub use file_ops::FileOpsTool;
125#[cfg(feature = "native")]
126pub use git::GitTool;
127#[cfg(feature = "native")]
128pub use search::SearchTool;
129#[cfg(feature = "native")]
130pub use transaction::TransactionManager;
131#[cfg(feature = "native")]
132pub use validation::{ValidationTool, get_validation_tools};
133#[cfg(feature = "native")]
134pub use web::WebTool;
135
136// Feature-gated tools
137#[cfg(any(feature = "orchestrator", feature = "orchestrator-wasm"))]
138pub use orchestrator::OrchestratorTool;
139
140#[cfg(feature = "interpreters")]
141pub use code_exec::CodeExecTool;
142
143#[cfg(feature = "rag")]
144pub use semantic_search::SemanticSearchTool;
145
146#[cfg(feature = "rag")]
147pub use tool_embedding::ToolEmbeddingIndex;
148
149pub use smart_router::{
150    analyze_messages, analyze_query, get_context_for_analysis, get_smart_tools,
151    get_smart_tools_with_mcp, get_tools_for_categories,
152};
153
154#[cfg(feature = "openapi")]
155pub use openapi::{
156    HttpMethod, OpenApiAuth, OpenApiEndpoint, OpenApiParam, OpenApiTool, execute_openapi_tool,
157    openapi_to_tools,
158};
159
160#[cfg(feature = "email")]
161pub use email::EmailTool;
162
163#[cfg(feature = "calendar")]
164pub use calendar::CalendarTool;
165
166#[cfg(feature = "browser")]
167pub use browser::BrowserTool;