vtcode_core/config/core/
tools.rs

1use indexmap::IndexMap;
2use serde::{Deserialize, Serialize};
3
4use crate::config::constants::{defaults, tools};
5
6/// Tools configuration
7#[derive(Debug, Clone, Deserialize, Serialize)]
8pub struct ToolsConfig {
9    /// Default policy for tools not explicitly listed
10    #[serde(default = "default_tool_policy")]
11    pub default_policy: ToolPolicy,
12
13    /// Specific tool policies
14    #[serde(default)]
15    pub policies: IndexMap<String, ToolPolicy>,
16
17    /// Maximum inner tool-call loops per user turn
18    ///
19    /// Prevents infinite tool-calling cycles in interactive chat. This limits how
20    /// many back-and-forths the agent will perform executing tools and
21    /// re-asking the model before returning a final answer.
22    ///
23    #[serde(default = "default_max_tool_loops")]
24    pub max_tool_loops: usize,
25}
26
27impl Default for ToolsConfig {
28    fn default() -> Self {
29        let mut policies = IndexMap::new();
30        policies.insert(tools::GREP_SEARCH.to_string(), ToolPolicy::Allow);
31        policies.insert(tools::LIST_FILES.to_string(), ToolPolicy::Allow);
32        policies.insert(tools::UPDATE_PLAN.to_string(), ToolPolicy::Allow);
33        policies.insert(tools::RUN_TERMINAL_CMD.to_string(), ToolPolicy::Allow);
34        policies.insert(tools::READ_FILE.to_string(), ToolPolicy::Allow);
35        policies.insert(tools::WRITE_FILE.to_string(), ToolPolicy::Prompt);
36        policies.insert(tools::EDIT_FILE.to_string(), ToolPolicy::Allow);
37        policies.insert(tools::AST_GREP_SEARCH.to_string(), ToolPolicy::Allow);
38        policies.insert(tools::SIMPLE_SEARCH.to_string(), ToolPolicy::Allow);
39        policies.insert(tools::BASH.to_string(), ToolPolicy::Allow);
40        policies.insert(tools::CURL.to_string(), ToolPolicy::Prompt);
41        policies.insert(tools::APPLY_PATCH.to_string(), ToolPolicy::Prompt);
42        policies.insert(tools::SRGN.to_string(), ToolPolicy::Prompt);
43        Self {
44            default_policy: default_tool_policy(),
45            policies,
46            max_tool_loops: default_max_tool_loops(),
47        }
48    }
49}
50
51/// Tool execution policy
52#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Eq)]
53#[serde(rename_all = "lowercase")]
54pub enum ToolPolicy {
55    /// Allow execution without confirmation
56    Allow,
57    /// Prompt user for confirmation
58    Prompt,
59    /// Deny execution
60    Deny,
61}
62
63fn default_tool_policy() -> ToolPolicy {
64    ToolPolicy::Prompt
65}
66
67fn default_max_tool_loops() -> usize {
68    defaults::DEFAULT_MAX_TOOL_LOOPS
69}