@@ -16,14 +16,71 @@ use ratatui::{
1616 backend:: { Backend , CrosstermBackend } ,
1717 Terminal ,
1818} ;
19+ use std:: fs;
1920use std:: io;
2021use std:: sync:: Arc ;
2122use std:: time:: Duration ;
2223use tokio:: sync:: Mutex ;
2324use tokio:: task;
2425
26+ fn create_default_config ( ) -> io:: Result < ( ) > {
27+ let default_config = r#"# Configuration for the LLM API
28+ [llm]
29+ provider = "openai"
30+
31+ api_key = ""
32+
33+ api_base_url = "http://localhost:11434/v1"
34+
35+ # Set to a concrete model name or use AUTODETECT to pick the first model from /v1/models
36+ model_name = "AUTODETECT"
37+
38+
39+
40+ # Automation options
41+ max_attempts = 12
42+ workspace_root = ""
43+ shell = "bash"
44+ post_write_verify = true
45+ safe_fs = true
46+ "# ;
47+
48+ fs:: write ( "config.toml" , default_config) ?;
49+ Ok ( ( ) )
50+ }
51+
2552#[ tokio:: main]
2653async fn main ( ) -> Result < ( ) , Box < dyn std:: error:: Error > > {
54+ // Check if config.toml exists, if not prompt user to create it
55+ if !std:: path:: Path :: new ( "config.toml" ) . exists ( ) {
56+ eprintln ! ( "Error: config.toml not found!" ) ;
57+ eprintln ! ( ) ;
58+ eprintln ! ( "A configuration file is required to run this application." ) ;
59+ eprintln ! ( "Would you like to create a default config.toml? (y/n)" ) ;
60+
61+ let mut input = String :: new ( ) ;
62+ io:: stdin ( ) . read_line ( & mut input) ?;
63+
64+ if input. trim ( ) . to_lowercase ( ) == "y" {
65+ create_default_config ( ) ?;
66+ eprintln ! ( ) ;
67+ eprintln ! ( "✓ Created config.toml with default values." ) ;
68+ eprintln ! ( ) ;
69+ eprintln ! ( "IMPORTANT: Please edit config.toml and set your LLM configuration:" ) ;
70+ eprintln ! ( " - api_key: Your API key" ) ;
71+ eprintln ! ( " - api_base_url: Your LLM API endpoint" ) ;
72+ eprintln ! ( " - model_name: The model to use (or 'AUTODETECT')" ) ;
73+ eprintln ! ( ) ;
74+ eprintln ! ( "Run the application again after configuring." ) ;
75+ return Ok ( ( ) ) ;
76+ } else {
77+ eprintln ! ( ) ;
78+ eprintln ! ( "Please create a config.toml file manually." ) ;
79+ eprintln ! ( "You can use config_example.toml as a reference." ) ;
80+ return Err ( "Configuration file not found" . into ( ) ) ;
81+ }
82+ }
83+
2784 // Load configuration
2885 let config = Config :: from_file ( "config.toml" ) ?;
2986
0 commit comments