brainwires_tool_runtime/lib.rs
1#![deny(missing_docs)]
2//! `brainwires-tool-runtime` — the execution-runtime half of the Brainwires
3//! tool surface. Companion crate to `brainwires-tool-builtins` (the concrete
4//! tools), unified by the `brainwires-tools` façade.
5//!
6//! ## What lives here
7//!
8//! - [`executor::ToolExecutor`] — the trait every tool dispatcher implements.
9//! - [`registry::ToolRegistry`] + [`registry::ToolCategory`] — composable tool
10//! registry and category metadata.
11//! - [`error`] — tool-error taxonomy + retry classification.
12//! - [`sanitization`] — content-source tagging, injection detection,
13//! sensitive-data redaction.
14//! - [`tool_search::ToolSearchTool`] — meta-tool for keyword / regex / (with
15//! `rag` feature) semantic tool discovery.
16//! - [`smart_router`] — query-driven category filtering.
17//! - [`transaction::TransactionManager`] — idempotency + staging-area
18//! bookkeeping for file-mutating tools (native only).
19//! - [`validation::ValidationTool`] — duplicate/syntax/build checks (native
20//! only).
21//!
22//! ## Feature-gated runtime modules
23//!
24//! - `orchestrator` (or `orchestrator-wasm`) — [`orchestrator::OrchestratorTool`]
25//! (Rhai script executor).
26//! - `oauth` — OAuth 2.0 client, PKCE, pluggable token store.
27//! - `openapi` — OpenAPI 3 spec → tool descriptor conversion.
28//! - `sandbox` — `sandbox_executor::SandboxedToolExecutor` (wraps any
29//! `ToolExecutor` to route bash/code-exec through `brainwires-sandbox`).
30//! - `sessions` — `sessions::SessionsTool` (`sessions_list`, `sessions_history`,
31//! `sessions_send`, `sessions_spawn`) over a `brainwires-session::SessionBroker`.
32//! - `rag` — [`tool_embedding::ToolEmbeddingIndex`] backing `ToolSearchTool`'s
33//! semantic mode.
34//!
35//! Concrete builtin tools (bash, file_ops, git, web, search, code_exec,
36//! interpreters, browser, email, calendar, system, semantic_search) live in
37//! `brainwires-tool-builtins`. The umbrella `brainwires-tools` façade re-exports
38//! both crates.
39
40// Re-export the core trait surface so consumers can pull everything off this crate.
41pub use brainwires_core::{
42 CommitResult, IdempotencyRecord, IdempotencyRegistry, StagedWrite, StagingBackend, Tool,
43 ToolContext, ToolInputSchema, ToolResult,
44};
45
46/// Tool-error taxonomy + retry classification.
47pub mod error;
48/// `ToolExecutor` trait + pre-hook surface.
49pub mod executor;
50/// Composable tool registry + category metadata.
51pub mod registry;
52/// Content-source tagging, injection detection, sensitive-data redaction.
53pub mod sanitization;
54/// Query-driven category filter (`analyze_query`, `get_smart_tools`).
55pub mod smart_router;
56/// Meta-tool for keyword / regex / (with `rag`) semantic tool discovery.
57pub mod tool_search;
58
59/// Idempotency + staging-area bookkeeping for file-mutating tools.
60#[cfg(feature = "native")]
61pub mod transaction;
62/// Code-quality checks (duplicates, syntax, build).
63#[cfg(feature = "native")]
64pub mod validation;
65
66/// Rhai-script orchestration tool.
67#[cfg(any(feature = "orchestrator", feature = "orchestrator-wasm"))]
68pub mod orchestrator;
69
70/// OAuth 2.0 client, PKCE, pluggable token store.
71#[cfg(feature = "oauth")]
72pub mod oauth;
73
74/// OpenAPI 3 spec → tool descriptor conversion.
75#[cfg(feature = "openapi")]
76pub mod openapi;
77
78/// Container-sandbox executor wrapper.
79#[cfg(feature = "sandbox")]
80pub mod sandbox_executor;
81
82/// `SessionsTool` + companion types over `brainwires-session::SessionBroker`.
83#[cfg(feature = "sessions")]
84pub mod sessions;
85
86/// RAG-backed tool-embedding index (powers `ToolSearchTool`'s semantic mode).
87#[cfg(feature = "rag")]
88pub mod tool_embedding;
89
90// ── Public re-exports ────────────────────────────────────────────────────────
91
92pub use error::{ResourceType, RetryStrategy, ToolErrorCategory, ToolOutcome, classify_error};
93pub use executor::{PreHookDecision, ToolExecutor, ToolPreHook};
94pub use registry::{ToolCategory, ToolRegistry};
95pub use sanitization::{
96 contains_sensitive_data, filter_tool_output, is_injection_attempt, redact_sensitive_data,
97 sanitize_external_content, wrap_with_content_source,
98};
99pub use smart_router::{
100 analyze_messages, analyze_query, get_context_for_analysis, get_smart_tools,
101 get_smart_tools_with_mcp, get_tools_for_categories,
102};
103pub use tool_search::ToolSearchTool;
104
105#[cfg(feature = "native")]
106pub use transaction::TransactionManager;
107#[cfg(feature = "native")]
108pub use validation::{ValidationTool, get_validation_tools};
109
110#[cfg(any(feature = "orchestrator", feature = "orchestrator-wasm"))]
111pub use orchestrator::OrchestratorTool;
112
113#[cfg(feature = "openapi")]
114pub use openapi::{
115 HttpMethod, OpenApiAuth, OpenApiEndpoint, OpenApiParam, OpenApiTool, execute_openapi_tool,
116 openapi_to_tools,
117};
118
119#[cfg(feature = "sandbox")]
120pub use sandbox_executor::SandboxedToolExecutor;
121
122// `SessionBroker` / `SessionId` / `SessionMessage` / `SessionSummary` /
123// `SpawnRequest` / `SpawnedSession` live in `brainwires-session::broker`. The
124// `SessionsTool` here only consumes them — depend on `brainwires-session`
125// directly.
126#[cfg(feature = "sessions")]
127pub use sessions::SessionsTool;
128
129#[cfg(feature = "rag")]
130pub use tool_embedding::ToolEmbeddingIndex;