use anyhow::Result;
use std::fs;
use std::io::Write;
use std::path::Path;
use vtcode_core::config::{ConfigReadRequest, ConfigService, VTCodeConfig};
use vtcode_core::utils::colors::style;
pub async fn handle_config_command(output: Option<&Path>, use_home_dir: bool) -> Result<()> {
println!("{}\n", style("[CONFIG]").cyan().bold());
if use_home_dir {
let created_files = VTCodeConfig::bootstrap_project_with_options(
std::env::current_dir()?,
true, true, )?;
if !created_files.is_empty() {
println!("Configuration files created in user home directory:");
for file in created_files {
println!(" - {}", file);
}
} else {
println!("Configuration files already exist in user home directory");
}
} else if let Some(output_path) = output {
println!("Output path: {}", output_path.display());
let mut file = fs::File::create(output_path)?;
file.write_all(generate_default_config().as_bytes())?;
println!("Configuration written to {}", output_path.display());
} else {
println!("\nGenerated configuration:\n");
println!("{}", generate_default_config());
}
Ok(())
}
fn generate_default_config() -> String {
let config = if Path::new("vtcode.toml").exists() {
let workspace = std::env::current_dir().unwrap_or_else(|_| ".".into());
match ConfigService::read(ConfigReadRequest {
workspace,
runtime_overrides: Vec::new(),
}) {
Ok(response) => serde_json::from_value::<VTCodeConfig>(response.effective_config)
.unwrap_or_else(|_| VTCodeConfig::default()),
Err(_) => VTCodeConfig::default(),
}
} else {
VTCodeConfig::default()
};
toml::to_string_pretty(&config).unwrap_or_else(|_| {
r#"# VT Code Configuration File
# This file contains the configuration for VT Code
[agent]
# Default model to use
default_model = "gpt-5.4"
# AI provider (gemini, openai, anthropic)
provider = "openai"
# Environment variable containing API key
api_key_env = "OPENAI_API_KEY"
# Maximum conversation turns
max_conversation_turns = 150
# Reasoning effort level for models that support it (none, minimal, low, medium, high, xhigh)
reasoning_effort = "none"
# Main model temperature
temperature = 0.7
[security]
# Enable human-in-the-loop mode
human_in_the_loop = true
[tools]
# Default tool execution policy
default_policy = "prompt"
[commands]
# Allowed shell commands (whitelist)
allow_list = ["ls", "pwd", "cat", "grep", "git status", "git diff"]
[pty]
# Enable PTY support
enabled = true
# Default terminal dimensions
default_rows = 24
default_cols = 80
# Maximum concurrent PTY sessions
max_sessions = 10
# Command execution timeout in seconds
command_timeout_seconds = 300
"#
.to_string()
})
}