Class: CommitGpt::SetupWizard
- Inherits:
-
Object
- Object
- CommitGpt::SetupWizard
- Defined in:
- lib/commitgpt/setup_wizard.rb
Overview
Interactive setup wizard for configuring AI providers
Constant Summary collapse
- DIFF_BYTES_PER_TOKEN =
Diff bytes per context token. Code and CJK pack more bytes into a token than English prose, so this stays deliberately conservative.
2- MAX_SUGGESTED_DIFF_LEN =
Ceiling for the suggested diff length. Past this a single request gets slow and one commit message stops describing the change usefully, so chunked mode is the better answer than a bigger window.
131_072- FALLBACK_DIFF_LEN =
Used when the model's context window is unknown
32_768
Instance Method Summary collapse
-
#change_model ⇒ Object
Change model for the active provider.
-
#choose_detail ⇒ Object
Choose how much the commit message says.
-
#choose_format ⇒ Object
Choose commit message format.
-
#initialize ⇒ SetupWizard
constructor
A new instance of SetupWizard.
-
#run ⇒ Object
Main entry point for setup.
-
#switch_provider ⇒ Object
Switch to a different configured provider.
Constructor Details
#initialize ⇒ SetupWizard
Returns a new instance of SetupWizard.
25 26 27 |
# File 'lib/commitgpt/setup_wizard.rb', line 25 def initialize @prompt = TTY::Prompt.new end |
Instance Method Details
#change_model ⇒ Object
Change model for the active provider
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/commitgpt/setup_wizard.rb', line 81 def change_model provider_config = ConfigManager.get_active_provider_config if provider_config.nil? || provider_config['api_key'].nil? || provider_config['api_key'].empty? puts "✖ No active provider configured. Please run 'aicm setup'.".red return end # Fetch models and let user select models = fetch_models_with_timeout(provider_config['base_url'], provider_config['api_key'], preset_models(provider_config['name'])) return if models.nil? model = select_model(models, provider_config['model']) # Update config ConfigManager.update_provider(provider_config['name'], { 'model' => model }) reset_provider_inference_params(provider_config['name']) puts "\nModel selected: #{model}".green end |
#choose_detail ⇒ Object
Choose how much the commit message says
120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/commitgpt/setup_wizard.rb', line 120 def choose_detail puts "\n→ Choose git commit message detail level:\n".green detail = @prompt.select('Select detail level:', default: default_detail_index) do || .choice 'Concise - Subject line only', 'concise' .choice 'Detailed - Subject line, explanatory paragraph, and bullet list of changes', 'detailed' end ConfigManager.set_commit_detail(detail) puts "\n✔ Commit detail set to: #{detail}".green end |
#choose_format ⇒ Object
Choose commit message format
104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/commitgpt/setup_wizard.rb', line 104 def choose_format prompt = TTY::Prompt.new puts "\n→ Choose git commit message format:\n".green format = prompt.select('Select format:') do || .choice 'Simple - Concise commit message', 'simple' .choice 'Conventional - Follow Conventional Commits specification', 'conventional' .choice 'Gitmoji - Use Gitmoji emoji standard', 'gitmoji' end ConfigManager.set_commit_format(format) puts "\n✔ Commit format set to: #{format}".green end |
#run ⇒ Object
Main entry point for setup
30 31 32 33 34 35 36 37 |
# File 'lib/commitgpt/setup_wizard.rb', line 30 def run ConfigManager.ensure_config_dir ConfigManager.generate_default_configs unless ConfigManager.config_exists? prompt_model_fetch_timeout provider_choice = select_provider configure_provider(provider_choice) end |
#switch_provider ⇒ Object
Switch to a different configured provider
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/commitgpt/setup_wizard.rb', line 40 def switch_provider configured = ConfigManager.configured_providers if configured.empty? puts "✖ No providers configured. Please run 'aicm setup' first.".red return end choices = configured.map do |p| preset = PROVIDER_PRESETS.find { |pr| pr[:value] == p['name'] } { name: preset ? preset[:label] : p['name'], value: p['name'] } end selected = @prompt.select('Choose your provider:', choices) # Get current config for this provider config = ConfigManager.load_config provider = config['providers'].find { |p| p['name'] == selected } # Fetch models and let user select models = fetch_models_with_timeout(provider['base_url'], provider['api_key'], preset_models(selected)) return if models.nil? model = select_model(models, provider['model']) # Prompt for diff length diff_len = prompt_diff_len(default_diff_len(selected, model, provider['diff_len'])) # Update config ConfigManager.update_provider(selected, { 'model' => model, 'diff_len' => diff_len }) reset_provider_inference_params(selected) ConfigManager.set_active_provider(selected) preset = PROVIDER_PRESETS.find { |pr| pr[:value] == selected } provider_label = preset ? preset[:label] : selected puts "\nModel selected: #{model}".green puts "Setup complete ✅ You're now using #{provider_label}.".green end |