2026-07-20 09:04:57 +07:00
|
|
|
//! Tool trait, execution context, and the registry of all built-in tools.
|
|
|
|
|
//!
|
|
|
|
|
//! This module defines the core `Tool` trait that every agent-invocable tool
|
2026-07-21 06:42:37 +07:00
|
|
|
//! must implement, the shared `ToolCtx` execution context, and utility
|
|
|
|
|
//! functions for path resolution, command execution, argument extraction,
|
|
|
|
|
//! and graduated-check rules.
|
|
|
|
|
//!
|
|
|
|
|
//! # Organisation
|
|
|
|
|
//!
|
|
|
|
|
//! ```text
|
|
|
|
|
//! tools/
|
|
|
|
|
//! ├── mod.rs — Tool trait, re-exports
|
|
|
|
|
//! ├── context.rs — ToolCtx, ToolCtxBuilder
|
|
|
|
|
//! ├── registry.rs — all_tools(), tool_defs(), tool_is_risky()
|
|
|
|
|
//! ├── util.rs — arg_str(), execute_cmd(), resolve_path(),
|
|
|
|
|
//! │ log_write_edit_tool()
|
|
|
|
|
//! ├── graduated.rs — GraduatedCheck, check_graduated_checks()
|
|
|
|
|
//! ├── executor.rs — InfrastructureToolExecutor
|
|
|
|
|
//! ├── fs/ — read, write, edit, delete
|
|
|
|
|
//! ├── git/ — git_operator, git_worktree, git_cred
|
|
|
|
|
//! ├── lsp/ — connect, disconnect, diagnostics, completion, etc.
|
|
|
|
|
//! ├── memory/ — remember, forget, recall
|
|
|
|
|
//! ├── utility/ — cd, dir_list, pong, todowrite, todofinish, etc.
|
|
|
|
|
//! ├── shell.rs — Bash tool
|
|
|
|
|
//! ├── bash_tools.rs
|
|
|
|
|
//! ├── search.rs — Grep, Glob
|
|
|
|
|
//! ├── semantic_search.rs
|
|
|
|
|
//! ├── web_search.rs
|
|
|
|
|
//! ├── sequential_think.rs
|
|
|
|
|
//! ├── plan.rs, spawn.rs, workflow.rs
|
|
|
|
|
//! └── parallel_delegate.rs
|
|
|
|
|
//! ```
|
2026-07-20 09:04:57 +07:00
|
|
|
|
|
|
|
|
use anyhow::Result;
|
|
|
|
|
use serde_json::Value;
|
|
|
|
|
|
|
|
|
|
pub mod bash_tools;
|
2026-07-21 07:21:22 +07:00
|
|
|
pub mod best_practice;
|
2026-07-21 06:42:37 +07:00
|
|
|
pub mod context;
|
|
|
|
|
pub mod executor;
|
2026-07-20 09:04:57 +07:00
|
|
|
pub mod fs;
|
|
|
|
|
pub mod git;
|
2026-07-21 06:42:37 +07:00
|
|
|
pub mod graduated;
|
2026-07-20 09:04:57 +07:00
|
|
|
pub mod lsp;
|
|
|
|
|
pub mod memory;
|
2026-07-20 16:59:22 +07:00
|
|
|
pub mod parallel_delegate;
|
2026-07-20 09:04:57 +07:00
|
|
|
pub mod plan;
|
2026-07-21 06:42:37 +07:00
|
|
|
pub mod registry;
|
2026-07-20 09:04:57 +07:00
|
|
|
pub mod search;
|
2026-07-20 16:59:22 +07:00
|
|
|
pub mod semantic_search;
|
2026-07-20 09:04:57 +07:00
|
|
|
pub mod sequential_think;
|
|
|
|
|
pub mod shell;
|
|
|
|
|
pub mod shell_filter;
|
|
|
|
|
pub mod spawn;
|
|
|
|
|
pub mod utility;
|
2026-07-21 06:42:37 +07:00
|
|
|
pub mod util;
|
2026-07-20 16:59:22 +07:00
|
|
|
pub mod web_search;
|
2026-07-20 09:04:57 +07:00
|
|
|
pub mod workflow;
|
|
|
|
|
|
2026-07-21 06:42:37 +07:00
|
|
|
// Re-export commonly used items at the `tools` root so existing imports
|
|
|
|
|
// like `crate::tools::{Tool, ToolCtx}` continue to work.
|
|
|
|
|
pub use context::{ToolCtx, ToolCtxBuilder};
|
|
|
|
|
pub use graduated::{check_graduated_checks, GraduatedCheck};
|
|
|
|
|
pub use registry::{all_tools, tool_defs, tool_is_risky};
|
|
|
|
|
pub use util::{arg_str, execute_cmd, log_write_edit_tool, resolve_path};
|
2026-07-20 09:04:57 +07:00
|
|
|
|
|
|
|
|
/// Common interface every agent-invocable tool implements.
|
|
|
|
|
pub trait Tool: Send + Sync {
|
|
|
|
|
fn name(&self) -> &'static str;
|
|
|
|
|
fn description(&self) -> &'static str;
|
|
|
|
|
fn parameters(&self) -> Value;
|
|
|
|
|
fn run(&self, ctx: &ToolCtx, args: &Value) -> Result<String>;
|
|
|
|
|
}
|
|
|
|
|
|
2026-07-21 06:42:37 +07:00
|
|
|
pub use git::git_cred;
|
|
|
|
|
pub use git::git_operator;
|
|
|
|
|
pub use git::git_worktree;
|