Skip to main content

vtcode_config/core/
automation.rs

1use crate::constants::{defaults, tool_limits, tools};
2use serde::{Deserialize, Serialize};
3use std::path::PathBuf;
4
5/// Automation-specific configuration toggles.
6#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
7#[derive(Debug, Clone, Deserialize, Serialize, Default)]
8pub struct AutomationConfig {
9    /// Full-auto execution safeguards.
10    #[serde(default)]
11    pub full_auto: FullAutoConfig,
12    /// Session and durable scheduled task controls.
13    #[serde(default)]
14    pub scheduled_tasks: ScheduledTasksConfig,
15    /// Loop engineering controls for external scheduler integration.
16    #[serde(default)]
17    pub loop_engine: LoopEngineConfig,
18}
19
20/// Controls for the built-in scheduled task subsystem.
21#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
22#[derive(Debug, Clone, Deserialize, Serialize)]
23pub struct ScheduledTasksConfig {
24    /// Enable scheduler tools and durable `vtcode schedule` jobs.
25    #[serde(default = "default_scheduled_tasks_enabled")]
26    pub enabled: bool,
27}
28
29impl Default for ScheduledTasksConfig {
30    fn default() -> Self {
31        Self { enabled: default_scheduled_tasks_enabled() }
32    }
33}
34
35/// Controls for running the agent without interactive approvals.
36#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
37#[derive(Debug, Clone, Deserialize, Serialize)]
38pub struct FullAutoConfig {
39    /// Enable the runtime flag once the workspace is configured for autonomous runs.
40    #[serde(default = "default_full_auto_enabled")]
41    pub enabled: bool,
42
43    /// Maximum number of autonomous agent turns before the exec runner pauses.
44    #[serde(default = "default_full_auto_max_turns")]
45    pub max_turns: usize,
46
47    /// Allow-list of tools that may execute automatically.
48    #[serde(default = "default_full_auto_allowed_tools")]
49    pub allowed_tools: Vec<String>,
50
51    /// Require presence of a profile/acknowledgement file before activation.
52    #[serde(default = "default_require_profile_ack")]
53    pub require_profile_ack: bool,
54
55    /// Optional path to a profile describing acceptable behaviors.
56    #[serde(default)]
57    pub profile_path: Option<PathBuf>,
58
59    /// Run a read-only verifier sub-agent after each mutating tool call.
60    /// When enabled, the harness spawns a verifier that re-reads the diff
61    /// and either approves or rejects the change before it is committed.
62    /// This doubles cost on mutating calls but catches propose-side errors.
63    #[serde(default)]
64    verify_mutations: bool,
65}
66
67impl Default for FullAutoConfig {
68    fn default() -> Self {
69        Self {
70            enabled: default_full_auto_enabled(),
71            max_turns: default_full_auto_max_turns(),
72            allowed_tools: default_full_auto_allowed_tools(),
73            require_profile_ack: default_require_profile_ack(),
74            profile_path: None,
75            verify_mutations: false,
76        }
77    }
78}
79
80fn default_full_auto_enabled() -> bool {
81    false
82}
83
84fn default_scheduled_tasks_enabled() -> bool {
85    false
86}
87
88fn default_full_auto_allowed_tools() -> Vec<String> {
89    vec![
90        tools::EXEC_COMMAND.to_string(),
91        tools::WRITE_STDIN.to_string(),
92        tools::APPLY_PATCH.to_string(),
93        tools::CODE_SEARCH.to_string(),
94        // Workflow-coordination tools stay available in every mode (see
95        // `ALWAYS_AVAILABLE_WORKFLOW_TOOLS`); listing them here keeps the
96        // documented default coherent with runtime behavior.
97        tools::TASK_TRACKER.to_string(),
98        tools::START_PLANNING.to_string(),
99        tools::REQUEST_USER_INPUT.to_string(),
100    ]
101}
102
103fn default_require_profile_ack() -> bool {
104    true
105}
106
107fn default_full_auto_max_turns() -> usize {
108    tool_limits::DEFAULT_FULL_AUTO_MAX_TURNS
109}
110
111/// Controls for loop engineering — running vtcode from an external scheduler.
112#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
113#[derive(Debug, Clone, Deserialize, Serialize)]
114pub struct LoopEngineConfig {
115    /// Enable loop engineering mode. When false, loop-specific features
116    /// (reconciler, per-iteration skills) are inactive.
117    #[serde(default)]
118    enabled: bool,
119
120    /// Optional circuit breaker: maximum loop iterations before the harness
121    /// refuses further runs. `None` means unlimited.
122    #[serde(default)]
123    max_iterations: Option<usize>,
124
125    /// After a worktree-isolated subagent completes, run the reconciler
126    /// (diff → verify → merge) automatically.
127    #[serde(default = "default_reconcile_on_complete")]
128    pub reconcile_on_complete: bool,
129
130    /// Skill names to preload into the agent context at the start of each
131    /// loop iteration. Empty means no per-iteration skill injection.
132    #[serde(default)]
133    preload_skills: Vec<String>,
134}
135
136impl Default for LoopEngineConfig {
137    fn default() -> Self {
138        Self {
139            enabled: false,
140            max_iterations: None,
141            reconcile_on_complete: default_reconcile_on_complete(),
142            preload_skills: Vec::new(),
143        }
144    }
145}
146
147fn default_reconcile_on_complete() -> bool {
148    true
149}
150
151/// Returns `true` when the loop engine is enabled, respecting the
152/// `VTCODE_DISABLE_LOOP_ENGINE` env-var override.
153pub fn loop_engine_enabled(config: &AutomationConfig) -> bool {
154    if std::env::var("VTCODE_DISABLE_LOOP_ENGINE").is_ok() {
155        return false;
156    }
157    config.loop_engine.enabled
158}
159
160#[cfg(test)]
161mod tests {
162    use super::*;
163
164    #[test]
165    fn full_auto_defaults_to_shared_turn_budget() {
166        assert_eq!(FullAutoConfig::default().max_turns, tool_limits::DEFAULT_FULL_AUTO_MAX_TURNS);
167    }
168
169    #[test]
170    fn full_auto_ignores_removed_auto_grant_key() {
171        // `auto_grant_tool_limits` was removed with the tool-loop budget;
172        // stale configs carrying it must still parse (the key is pruned on
173        // the next save with a warning).
174        let parsed = toml::from_str::<FullAutoConfig>("enabled = true\nauto_grant_tool_limits = false")
175            .expect("stale auto-grant key must parse");
176        assert!(parsed.enabled);
177    }
178}