setup

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 8, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package setup provides an interactive first-time setup wizard for AINative Code.

The setup wizard guides new users through the initial configuration process, including:

  • LLM provider selection (Anthropic, OpenAI, Google Gemini, Ollama)
  • API key input and validation
  • Model selection with recommendations
  • Optional AINative platform integration
  • Extended thinking configuration
  • Color scheme and UI preferences

The wizard creates a configuration file at ~/.ainative-code.yaml and an initialization marker at ~/.ainative-code-initialized to track first-time setup.

Interactive Mode

By default, the wizard runs in interactive mode with a rich TUI powered by Bubble Tea. Users can navigate through steps using arrow keys and make selections interactively:

wizard := setup.NewWizard(ctx, setup.WizardConfig{
    InteractiveMode: true,
    SkipValidation:  false,
})
result, err := wizard.Run()

Non-Interactive Mode

For CI/CD environments or automated setups, the wizard supports non-interactive mode using environment variables:

export AINATIVE_PROVIDER=anthropic
export AINATIVE_ANTHROPIC_API_KEY=sk-ant-...
export AINATIVE_ANTHROPIC_MODEL=claude-3-5-sonnet-20241022
ainative-code setup --non-interactive

Validation

The wizard validates API keys and credentials by default:

  • Anthropic: Tests API key format and authentication
  • OpenAI: Validates key format and tests API access
  • Google: Checks API key validity
  • Ollama: Verifies server connectivity and model availability

Validation can be skipped for faster setup:

ainative-code setup --skip-validation

First-Run Detection

The wizard automatically detects first-time runs by checking for the initialization marker file. Users can force re-run setup:

ainative-code setup --force

Configuration Structure

The generated configuration includes:

  • App metadata (name, version, environment)
  • LLM provider settings with defaults
  • Platform authentication (optional)
  • Performance tuning (cache, concurrency)
  • Logging configuration
  • Security settings

Provider-Specific Configuration

Anthropic (Claude):

  • API key validation (must start with "sk-ant-")
  • Model selection (Sonnet 3.5, Opus 3, etc.)
  • Extended thinking mode
  • Prompt caching preferences

OpenAI (GPT):

  • API key validation (must start with "sk-")
  • Model selection (GPT-4 Turbo, GPT-4, GPT-3.5)
  • Organization ID (optional)

Google (Gemini):

  • API key validation
  • Model selection (Gemini Pro, Gemini Pro Vision)
  • Project ID and location (optional)

Ollama (Local):

Error Handling

The wizard handles errors gracefully:

  • Invalid API keys: Clear error messages with help links
  • Network failures: Distinguishes from validation failures
  • User cancellation: Clean exit without partial state
  • File system errors: Directory creation and permissions

Testing

The package includes comprehensive tests for:

  • Configuration building for all providers
  • API key validation
  • File operations (writing config, creating markers)
  • First-run detection
  • Non-interactive mode
  • Error cases

Example usage in tests:

wizard := setup.NewWizard(ctx, setup.WizardConfig{
    InteractiveMode: false,
    SkipValidation:  true,
})
wizard.SetSelections(map[string]interface{}{
    "provider":          "anthropic",
    "anthropic_api_key": "sk-ant-test",
})
result, err := wizard.Run()

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckFirstRun

func CheckFirstRun() bool

CheckFirstRun checks if this is a first run and whether setup is needed

func SanitizeAPIKey

func SanitizeAPIKey(apiKey string) string

SanitizeAPIKey sanitizes an API key for display

Types

type PromptModel

type PromptModel struct {
	Selections map[string]interface{}
	// contains filtered or unexported fields
}

PromptModel represents the state of the interactive prompts

func NewPromptModel

func NewPromptModel() PromptModel

NewPromptModel creates a new prompt model

func (PromptModel) Init

func (m PromptModel) Init() tea.Cmd

Init initializes the model

func (PromptModel) Update

func (m PromptModel) Update(msg tea.Msg) (tea.Model, tea.Cmd)

Update handles messages

func (PromptModel) View

func (m PromptModel) View() string

View renders the UI

type Step

type Step int

Step represents each step in the wizard

const (
	StepProvider Step = iota
	StepAnthropicAPIKey
	StepAnthropicModel
	StepExtendedThinking
	StepOpenAIAPIKey
	StepOpenAIModel
	StepGoogleAPIKey
	StepGoogleModel
	StepOllamaURL
	StepOllamaModel
	StepAINativeLogin
	StepAINativeAPIKey
	StepColorScheme
	StepPromptCaching
	StepComplete
)

type SummaryModel

type SummaryModel struct {
	Config     interface{}
	Selections map[string]interface{}
	Confirmed  bool
	// contains filtered or unexported fields
}

SummaryModel displays the configuration summary

func NewSummaryModel

func NewSummaryModel(cfg interface{}, selections map[string]interface{}) SummaryModel

NewSummaryModel creates a new summary model

func (SummaryModel) Init

func (m SummaryModel) Init() tea.Cmd

Init initializes the summary model

func (SummaryModel) Update

func (m SummaryModel) Update(msg tea.Msg) (tea.Model, tea.Cmd)

Update handles messages for summary

func (SummaryModel) View

func (m SummaryModel) View() string

View renders the summary

type Validator

type Validator struct {
	// contains filtered or unexported fields
}

Validator handles validation of API keys and connections

func NewValidator

func NewValidator() *Validator

NewValidator creates a new validator instance

func (*Validator) ValidateAINativeKey

func (v *Validator) ValidateAINativeKey(ctx context.Context, apiKey string) error

ValidateAINativeKey validates an AINative platform API key

func (*Validator) ValidateAll

func (v *Validator) ValidateAll(ctx context.Context, selections map[string]interface{}) error

ValidateAll performs comprehensive validation of all user inputs

func (*Validator) ValidateAnthropicKey

func (v *Validator) ValidateAnthropicKey(ctx context.Context, apiKey string) error

ValidateAnthropicKey validates an Anthropic API key

func (*Validator) ValidateGoogleKey

func (v *Validator) ValidateGoogleKey(ctx context.Context, apiKey string) error

ValidateGoogleKey validates a Google API key

func (*Validator) ValidateOllamaConnection

func (v *Validator) ValidateOllamaConnection(ctx context.Context, baseURL string) error

ValidateOllamaConnection validates connection to an Ollama server

func (*Validator) ValidateOllamaModel

func (v *Validator) ValidateOllamaModel(ctx context.Context, baseURL, modelName string) error

ValidateOllamaModel validates that a model exists in Ollama

func (*Validator) ValidateOpenAIKey

func (v *Validator) ValidateOpenAIKey(ctx context.Context, apiKey string) error

ValidateOpenAIKey validates an OpenAI API key

func (*Validator) ValidateProviderConfig

func (v *Validator) ValidateProviderConfig(ctx context.Context, provider string, selections map[string]interface{}) error

ValidateProviderConfig validates the complete provider configuration

type Wizard

type Wizard struct {
	// contains filtered or unexported fields
}

Wizard orchestrates the first-time setup process

func NewWizard

func NewWizard(ctx context.Context, cfg WizardConfig) *Wizard

NewWizard creates a new setup wizard instance

func (*Wizard) Run

func (w *Wizard) Run() (*WizardResult, error)

Run executes the setup wizard flow

func (*Wizard) SetSelections

func (w *Wizard) SetSelections(selections map[string]interface{})

SetSelections manually sets user selections (for non-interactive mode)

type WizardConfig

type WizardConfig struct {
	ConfigPath      string
	SkipValidation  bool
	InteractiveMode bool
}

WizardConfig holds configuration for the setup wizard

type WizardResult

type WizardResult struct {
	Config         *config.Config
	ConfigPath     string
	MarkerCreated  bool
	SkippedSetup   bool
	ValidationPass bool
}

WizardResult represents the output of the wizard

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL