setup

package
v0.59.0 Latest Latest
Warning

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

Go to latest
Published: Feb 9, 2026 License: MIT Imports: 22 Imported by: 0

Documentation

Overview

Package setup provides interactive configuration wizards for first-run experience.

Package setup provides interactive configuration wizards including Bubble Tea TUI components.

Package setup provides profile management for CLASP configuration.

Package setup provides interactive configuration wizards including Bubble Tea TUI components.

Package setup provides secure input handling for sensitive data like API keys.

Package setup provides interactive configuration wizards for first-run experience.

Index

Constants

This section is empty.

Variables

View Source
var ErrCanceled = fmt.Errorf("setup canceled")

ErrCanceled is returned when the user cancels the model picker (Ctrl+C or Esc).

Functions

func ApplyConfigToEnv

func ApplyConfigToEnv() error

ApplyConfigToEnv applies saved config to environment variables.

func FormatProfileDetails added in v0.13.0

func FormatProfileDetails(profile *Profile) string

FormatProfileDetails returns detailed profile information.

func FormatProfileInfo added in v0.13.0

func FormatProfileInfo(profile *Profile, isActive bool) string

FormatProfileInfo returns a formatted string with profile information.

func GetConfigPath

func GetConfigPath() string

GetConfigPath returns the path to the CLASP config file.

func GetProfilePath

func GetProfilePath(name string) string

GetProfilePath returns the path to a specific profile.

func HasProfiles added in v0.49.0

func HasProfiles() bool

HasProfiles checks if any profiles exist.

func IsTTY added in v0.17.1

func IsTTY() bool

IsTTY checks if stdin is a terminal.

func MaskAPIKeyForDisplay added in v0.17.1

func MaskAPIKeyForDisplay(key string) string

MaskAPIKeyForDisplay masks an API key for safe display.

func NeedsSetup

func NeedsSetup() bool

NeedsSetup checks if configuration is missing and setup is required.

func QuickCheck added in v0.46.0

func QuickCheck() (bool, string)

QuickCheck performs a minimal set of checks for startup validation.

func RunModelPicker added in v0.17.1

func RunModelPicker(models []ModelInfo, provider, tier string) (string, error)

RunModelPicker runs the Bubble Tea model picker and returns the selected model. Returns ErrCanceled if the user presses Ctrl+C or Esc to cancel. Returns empty string with nil error only if no models were selected but not canceled.

func RunProfileSelector added in v0.49.0

func RunProfileSelector(profiles []*Profile, activeProfile string) (selectedProfile string, createNew, canceled bool, err error)

RunProfileSelector runs the Bubble Tea profile selector. Returns the selected profile name, or empty string for create new / canceled. The second return value indicates whether to create a new profile.

func RunSecureInput added in v0.17.1

func RunSecureInput(prompt, placeholder string, showLast4 bool) (string, error)

RunSecureInput runs the secure input and returns the entered value. Returns empty string if canceled.

func SelectOrCreateProfile added in v0.49.0

func SelectOrCreateProfile() (profileName string, createNew, canceled bool)

SelectOrCreateProfile shows the profile selector TUI if profiles exist, otherwise returns that a new profile should be created. Returns: profileName (if selected), createNew (if should create), canceled (if user quit)

func WarnCLIAPIKey added in v0.17.1

func WarnCLIAPIKey() string

WarnCLIAPIKey prints a warning if API key is passed via command line.

Types

type ClaudeCodeConfig added in v0.34.9

type ClaudeCodeConfig struct {
	// SkipPermissions enables --dangerously-skip-permissions flag (default: true)
	SkipPermissions bool `json:"skip_permissions"`
	// AdditionalArgs contains extra arguments to pass to Claude Code
	AdditionalArgs []string `json:"additional_args,omitempty"`
}

ClaudeCodeConfig represents Claude Code CLI configuration.

type ConfigFile

type ConfigFile struct {
	Provider        string            `json:"provider"`
	Model           string            `json:"model,omitempty"`
	APIKey          string            `json:"api_key,omitempty"`
	BaseURL         string            `json:"base_url,omitempty"`
	AzureEndpoint   string            `json:"azure_endpoint,omitempty"`
	AzureDeployment string            `json:"azure_deployment,omitempty"`
	ModelAliases    map[string]string `json:"model_aliases,omitempty"`
	CreatedAt       string            `json:"created_at"`
	UpdatedAt       string            `json:"updated_at"`
	// Claude Code settings
	ClaudeCodeConfig *ClaudeCodeConfig `json:"claude_code,omitempty"`
}

ConfigFile represents the saved configuration format.

func LoadConfig

func LoadConfig() (*ConfigFile, error)

LoadConfig loads configuration from the saved config file.

type DiagnosticResult added in v0.46.0

type DiagnosticResult struct {
	Name    string
	Status  string // "ok", "warning", "error"
	Message string
	Fix     string // Suggested fix if status is not ok
}

DiagnosticResult represents the result of a single diagnostic check.

type Doctor added in v0.46.0

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

Doctor runs comprehensive diagnostics on the CLASP installation.

func NewDoctor added in v0.46.0

func NewDoctor(verbose bool) *Doctor

NewDoctor creates a new Doctor instance.

func (*Doctor) HasErrors added in v0.46.0

func (d *Doctor) HasErrors() bool

HasErrors returns true if any errors were found.

func (*Doctor) PrintResults added in v0.46.0

func (d *Doctor) PrintResults(w io.Writer)

PrintResults formats and prints diagnostic results.

func (*Doctor) Run added in v0.46.0

func (d *Doctor) Run() []DiagnosticResult

Run executes all diagnostic checks and returns results.

type GlobalConfig added in v0.13.0

type GlobalConfig struct {
	ActiveProfile string `json:"active_profile"`
	LastUsed      string `json:"last_used,omitempty"`
}

GlobalConfig holds global settings and active profile reference.

type ModelInfo added in v0.17.1

type ModelInfo struct {
	ID            string  // Model ID (e.g., "gpt-4o")
	Name          string  // Display name (e.g., "GPT-4o")
	Desc          string  // Short description
	Provider      string  // Provider name
	InputPrice    float64 // Price per 1M input tokens in USD
	OutputPrice   float64 // Price per 1M output tokens in USD
	ContextSize   int     // Context window size in tokens
	IsRecommended bool    // Whether this is a recommended model
}

ModelInfo contains metadata about a model.

func GetKnownModels added in v0.17.1

func GetKnownModels(provider string) []ModelInfo

GetKnownModels returns model metadata for known providers.

func MergeModelLists added in v0.17.1

func MergeModelLists(fetched []string, known []ModelInfo) []ModelInfo

MergeModelLists merges fetched models with known model metadata.

func (ModelInfo) Description added in v0.17.1

func (m ModelInfo) Description() string

func (ModelInfo) FilterValue added in v0.17.1

func (m ModelInfo) FilterValue() string

Implement list.Item interface

func (ModelInfo) Title added in v0.17.1

func (m ModelInfo) Title() string

type ModelPicker added in v0.17.1

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

ModelPicker is a Bubble Tea model for fuzzy model selection.

func NewModelPicker added in v0.17.1

func NewModelPicker(models []ModelInfo, provider, tier string) *ModelPicker

NewModelPicker creates a new fuzzy model picker.

func (*ModelPicker) Canceled added in v0.50.14

func (m *ModelPicker) Canceled() bool

Canceled returns true if the user canceled the selection.

func (*ModelPicker) Init added in v0.17.1

func (m *ModelPicker) Init() tea.Cmd

Init initializes the model picker.

func (*ModelPicker) Selected added in v0.17.1

func (m *ModelPicker) Selected() *ModelInfo

Selected returns the selected model, or nil if canceled.

func (*ModelPicker) Update added in v0.17.1

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

Update handles input and updates the model picker state.

func (*ModelPicker) View added in v0.17.1

func (m *ModelPicker) View() string

View renders the model picker with visible filter input.

type Profile added in v0.13.0

type Profile struct {
	Name        string `json:"name"`
	Description string `json:"description,omitempty"`

	// Provider configuration
	Provider  string `json:"provider"`
	APIKey    string `json:"api_key,omitempty"`
	APIKeyEnv string `json:"api_key_env,omitempty"` // Reference to env var instead of storing key
	BaseURL   string `json:"base_url,omitempty"`

	// Azure-specific
	AzureEndpoint   string `json:"azure_endpoint,omitempty"`
	AzureDeployment string `json:"azure_deployment,omitempty"`

	// Model configuration
	DefaultModel string `json:"default_model,omitempty"`

	// Per-tier model mappings
	TierMappings map[string]TierMapping `json:"tier_mappings,omitempty"`

	// Default parameters
	Temperature *float64 `json:"temperature,omitempty"`
	MaxTokens   *int     `json:"max_tokens,omitempty"`

	// Server preferences
	Port int `json:"port,omitempty"`

	// Feature flags
	RateLimitEnabled      bool `json:"rate_limit_enabled,omitempty"`
	CacheEnabled          bool `json:"cache_enabled,omitempty"`
	CircuitBreakerEnabled bool `json:"circuit_breaker_enabled,omitempty"`

	// Claude Code settings
	ClaudeCode *ClaudeCodeConfig `json:"claude_code,omitempty"`

	// Timestamps
	CreatedAt string `json:"created_at"`
	UpdatedAt string `json:"updated_at"`
}

Profile represents a saved CLASP configuration profile.

type ProfileItem added in v0.49.0

type ProfileItem struct {
	Profile  *Profile
	IsActive bool
}

ProfileItem represents a profile in the selector list.

func (ProfileItem) Description added in v0.49.0

func (p ProfileItem) Description() string

func (ProfileItem) FilterValue added in v0.49.0

func (p ProfileItem) FilterValue() string

Implement list.Item interface

func (ProfileItem) Title added in v0.49.0

func (p ProfileItem) Title() string

type ProfileManager added in v0.13.0

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

ProfileManager handles profile CRUD operations.

func NewProfileManager added in v0.13.0

func NewProfileManager() *ProfileManager

NewProfileManager creates a new profile manager.

func (*ProfileManager) ApplyProfileToEnv added in v0.13.0

func (pm *ProfileManager) ApplyProfileToEnv(profile *Profile) error

ApplyProfileToEnv applies profile settings to environment variables.

func (*ProfileManager) CreateProfile added in v0.13.0

func (pm *ProfileManager) CreateProfile(profile *Profile) error

CreateProfile creates a new profile.

func (*ProfileManager) DeleteProfile added in v0.13.0

func (pm *ProfileManager) DeleteProfile(name string) error

DeleteProfile removes a profile.

func (*ProfileManager) EnsureDirectories added in v0.13.0

func (pm *ProfileManager) EnsureDirectories() error

EnsureDirectories creates necessary directories if they don't exist.

func (*ProfileManager) ExportProfile added in v0.13.0

func (pm *ProfileManager) ExportProfile(name string) ([]byte, error)

ExportProfile exports a profile to JSON. API keys are never included in exports for security. Instead, use api_key_env to reference environment variables.

func (*ProfileManager) GetActiveProfile added in v0.13.0

func (pm *ProfileManager) GetActiveProfile() (*Profile, error)

GetActiveProfile returns the currently active profile.

func (*ProfileManager) GetGlobalConfig added in v0.13.0

func (pm *ProfileManager) GetGlobalConfig() (*GlobalConfig, error)

GetGlobalConfig retrieves the global configuration.

func (*ProfileManager) GetGlobalConfigPath added in v0.13.0

func (pm *ProfileManager) GetGlobalConfigPath() string

GetGlobalConfigPath returns the global config file path.

func (*ProfileManager) GetProfile added in v0.13.0

func (pm *ProfileManager) GetProfile(name string) (*Profile, error)

GetProfile retrieves a profile by name.

func (*ProfileManager) GetProfilesDir added in v0.13.0

func (pm *ProfileManager) GetProfilesDir() string

GetProfilesDir returns the profiles directory path.

func (*ProfileManager) ImportProfile added in v0.13.0

func (pm *ProfileManager) ImportProfile(data []byte, newName string) error

ImportProfile imports a profile from JSON.

func (*ProfileManager) ListProfiles added in v0.13.0

func (pm *ProfileManager) ListProfiles() ([]*Profile, error)

ListProfiles returns all available profiles.

func (*ProfileManager) MigrateOldConfig added in v0.13.0

func (pm *ProfileManager) MigrateOldConfig() error

MigrateOldConfig migrates from old config.json format to new profile system.

func (*ProfileManager) ProfileExists added in v0.13.0

func (pm *ProfileManager) ProfileExists(name string) bool

ProfileExists checks if a profile exists.

func (*ProfileManager) RenameProfile added in v0.50.0

func (pm *ProfileManager) RenameProfile(oldName, newName string) error

RenameProfile renames a profile.

func (*ProfileManager) SaveGlobalConfig added in v0.13.0

func (pm *ProfileManager) SaveGlobalConfig(config *GlobalConfig) error

SaveGlobalConfig saves the global configuration.

func (*ProfileManager) SetActiveProfile added in v0.13.0

func (pm *ProfileManager) SetActiveProfile(name string) error

SetActiveProfile sets the active profile.

func (*ProfileManager) UpdateProfile added in v0.13.0

func (pm *ProfileManager) UpdateProfile(profile *Profile) error

UpdateProfile updates an existing profile.

type ProfileSelector added in v0.49.0

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

ProfileSelector is a Bubble Tea model for profile selection.

func NewProfileSelector added in v0.49.0

func NewProfileSelector(profiles []*Profile, activeProfile string) *ProfileSelector

NewProfileSelector creates a new profile selector.

func (*ProfileSelector) Init added in v0.49.0

func (m *ProfileSelector) Init() tea.Cmd

Init initializes the profile selector.

func (*ProfileSelector) Result added in v0.49.0

Result returns the result of the selection.

func (*ProfileSelector) Selected added in v0.49.0

func (m *ProfileSelector) Selected() *Profile

Selected returns the selected profile, or nil if canceled or creating new.

func (*ProfileSelector) Update added in v0.49.0

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

Update handles input and updates the profile selector state.

func (*ProfileSelector) View added in v0.49.0

func (m *ProfileSelector) View() string

View renders the profile selector.

type ProfileSelectorMode added in v0.50.0

type ProfileSelectorMode int

ProfileSelectorMode represents the current mode of the selector.

const (
	ModeSelect ProfileSelectorMode = iota
	ModeRename
	ModeDeleteConfirm
)

type ProfileSelectorResult added in v0.49.0

type ProfileSelectorResult int

ProfileSelectorResult represents the result of the profile selector.

const (
	ProfileResultSelected ProfileSelectorResult = iota
	ProfileResultCreateNew
	ProfileResultCanceled
	ProfileResultRenamed
	ProfileResultDeleted
)

type SecureInput added in v0.17.1

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

SecureInput provides password-style masked input for API keys.

func NewSecureInput added in v0.17.1

func NewSecureInput(prompt, placeholder string, showLast4 bool) *SecureInput

NewSecureInput creates a new password-style input for API keys.

func (*SecureInput) Canceled added in v0.50.14

func (s *SecureInput) Canceled() bool

Canceled returns true if the user pressed Esc or Ctrl+C.

func (*SecureInput) Init added in v0.17.1

func (s *SecureInput) Init() tea.Cmd

Init initializes the secure input.

func (*SecureInput) Submitted added in v0.17.1

func (s *SecureInput) Submitted() bool

Submitted returns true if the user pressed Enter.

func (*SecureInput) Update added in v0.17.1

func (s *SecureInput) Update(msg tea.Msg) (tea.Model, tea.Cmd)

Update handles input and updates the secure input state.

func (*SecureInput) Value added in v0.17.1

func (s *SecureInput) Value() string

Value returns the entered value.

func (*SecureInput) View added in v0.17.1

func (s *SecureInput) View() string

View renders the secure input.

type TierMapping added in v0.13.0

type TierMapping struct {
	Provider  string `json:"provider,omitempty"`
	Model     string `json:"model"`
	APIKey    string `json:"api_key,omitempty"`
	APIKeyEnv string `json:"api_key_env,omitempty"`
	BaseURL   string `json:"base_url,omitempty"`
}

TierMapping represents model mapping for a specific tier.

type Wizard

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

Wizard handles the interactive setup process.

func NewWizard

func NewWizard() *Wizard

NewWizard creates a new setup wizard.

func (*Wizard) FetchModelsPublic

func (w *Wizard) FetchModelsPublic(provider, apiKey, baseURL, azureEndpoint string) ([]string, error)

FetchModelsPublic is a public wrapper for fetchModels.

func (*Wizard) Run

func (w *Wizard) Run() (*config.Config, error)

Run executes the interactive setup wizard.

func (*Wizard) RunProfileCreate added in v0.13.0

func (w *Wizard) RunProfileCreate(profileName string) (*Profile, error)

RunProfileCreate runs the interactive profile creation wizard.

func (*Wizard) RunProfileDelete added in v0.13.0

func (w *Wizard) RunProfileDelete(name string) error

RunProfileDelete removes a profile.

func (*Wizard) RunProfileExport added in v0.13.0

func (w *Wizard) RunProfileExport(name, outputPath string) error

RunProfileExport exports a profile to a file.

func (*Wizard) RunProfileImport added in v0.13.0

func (w *Wizard) RunProfileImport(inputPath, newName string) error

RunProfileImport imports a profile from a file.

func (*Wizard) RunProfileList added in v0.13.0

func (w *Wizard) RunProfileList() error

RunProfileList displays all profiles.

func (*Wizard) RunProfileShow added in v0.13.0

func (w *Wizard) RunProfileShow(name string) error

RunProfileShow displays details for a specific or active profile.

func (*Wizard) RunProfileUse added in v0.13.0

func (w *Wizard) RunProfileUse(name string) error

RunProfileUse switches to a different profile.

Jump to

Keyboard shortcuts

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