vtcode_core/tools/
traits.rs1use anyhow::Result;
4use async_trait::async_trait;
5use serde_json::Value;
6use std::path::PathBuf;
7
8#[async_trait]
10pub trait Tool: Send + Sync {
11 async fn execute(&self, args: Value) -> Result<Value>;
13
14 fn name(&self) -> &'static str;
16
17 fn description(&self) -> &'static str;
19
20 fn validate_args(&self, _args: &Value) -> Result<()> {
22 Ok(())
24 }
25}
26
27#[async_trait]
29pub trait FileTool: Tool {
30 fn workspace_root(&self) -> &PathBuf;
32
33 async fn should_exclude(&self, path: &std::path::Path) -> bool;
35}
36
37#[async_trait]
39pub trait ModeTool: Tool {
40 fn supported_modes(&self) -> Vec<&'static str>;
42
43 async fn execute_mode(&self, mode: &str, args: Value) -> Result<Value>;
45}
46
47#[async_trait]
49pub trait CacheableTool: Tool {
50 fn cache_key(&self, args: &Value) -> String;
52
53 fn should_cache(&self, _args: &Value) -> bool {
55 true }
57
58 fn cache_ttl(&self) -> u64 {
60 300 }
62}
63
64#[async_trait]
66pub trait ToolExecutor: Send + Sync {
67 async fn execute_tool(&self, name: &str, args: Value) -> Result<Value>;
69
70 fn available_tools(&self) -> Vec<String>;
72
73 fn has_tool(&self, name: &str) -> bool;
75}