config

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2025 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ConfigDirName       = ".codex-switch"
	ProfilesDirName     = "profiles"
	TemplatesDirName    = "templates"
	StateFileName       = "state.yaml"
	ConfigFileName      = "config.yaml"
	HistoryFileName     = "history.yaml"
	UpdateCacheFileName = "update_cache.yaml"
	ExportExtension     = ".cxs"

	// GitHub repository info for update checking
	GitHubRepoOwner = "HoBeedzc"
	GitHubRepoName  = "codex-switch"
	GitHubAPIURL    = "https://api.github.com/repos/" + GitHubRepoOwner + "/" + GitHubRepoName + "/releases/latest"

	// Default update check interval
	DefaultCheckIntervalHours = 24
)

Variables

This section is empty.

Functions

This section is empty.

Types

type CodexAuthJSON

type CodexAuthJSON struct {
	OpenAIAPIKey string `json:"OPENAI_API_KEY,omitempty"`
}

CodexAuthJSON represents the structure of ~/.codex/auth.json

type CodexConfig

type CodexConfig struct {
	ConfigName             string `yaml:"config_name,omitempty" toml:"config_name,omitempty"`
	ModelProvider          string `yaml:"model_provider,omitempty" toml:"model_provider,omitempty"`
	Model                  string `yaml:"model,omitempty" toml:"model,omitempty"`
	ModelReasoningEffort   string `yaml:"model_reasoning_effort,omitempty" toml:"model_reasoning_effort,omitempty"`
	WireAPI                string `yaml:"wire_api,omitempty" toml:"wire_api,omitempty"`
	EnvKey                 string `yaml:"env_key,omitempty" toml:"env_key,omitempty"`
	BaseURL                string `yaml:"base_url,omitempty" toml:"base_url,omitempty"`
	DisableResponseStorage bool   `yaml:"disable_response_storage,omitempty" toml:"disable_response_storage,omitempty"`
	RequiresOpenAIAuth     bool   `yaml:"requires_openai_auth,omitempty" toml:"requires_openai_auth,omitempty"`
}

CodexConfig represents the codex-specific configuration

type CodexConfigTOML

type CodexConfigTOML struct {
	ModelProvider          string                   `toml:"model_provider"`
	Model                  string                   `toml:"model"`
	ModelReasoningEffort   string                   `toml:"model_reasoning_effort"`
	DisableResponseStorage bool                     `toml:"disable_response_storage"`
	RequiresOpenAIAuth     bool                     `toml:"requires_openai_auth"`
	ModelProviders         map[string]CodexProvider `toml:"model_providers"`
}

CodexConfigTOML represents the structure of ~/.codex/config.toml

type CodexProvider

type CodexProvider struct {
	Name    string `toml:"name"`
	BaseURL string `toml:"base_url"`
	WireAPI string `toml:"wire_api"`
	EnvKey  string `toml:"env_key"`
}

CodexProvider represents a model provider configuration

type Config

type Config struct {
	APIKey                 string `yaml:"api_key,omitempty"`
	BaseURL                string `yaml:"base_url,omitempty"`
	Model                  string `yaml:"model,omitempty"`
	ModelReasoningEffort   string `yaml:"model_reasoning_effort,omitempty"`
	DisableResponseStorage bool   `yaml:"disable_response_storage"`
	RequiresOpenAIAuth     bool   `yaml:"requires_openai_auth"`
}

type ConfigurationApplier

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

ConfigurationApplier handles applying configuration profiles to external systems

func NewConfigurationApplier

func NewConfigurationApplier(manager *Manager) (*ConfigurationApplier, error)

NewConfigurationApplier creates a new configuration applier

func (*ConfigurationApplier) ApplyProfile

func (ca *ConfigurationApplier) ApplyProfile(profileName string) error

ApplyProfile applies the specified profile's configuration to external systems

func (*ConfigurationApplier) ClearCodexConfig

func (ca *ConfigurationApplier) ClearCodexConfig() error

ClearCodexConfig removes all codex configuration files

func (*ConfigurationApplier) ReadCurrentCodexConfig

func (ca *ConfigurationApplier) ReadCurrentCodexConfig() (*ExtendedConfig, error)

ReadCurrentCodexConfig reads the current Codex configuration from the actual files

func (*ConfigurationApplier) SaveCurrentConfigToProfile

func (ca *ConfigurationApplier) SaveCurrentConfigToProfile(profileName string) error

SaveCurrentConfigToProfile saves the current Codex configuration back to the profile

type ExtendedConfig

type ExtendedConfig struct {
	Config      `yaml:",inline"`
	CodexConfig *CodexConfig `yaml:"codex_config,omitempty"`
}

ExtendedConfig extends the base config with real switching capabilities

type GitHubAsset

type GitHubAsset struct {
	Name               string `json:"name"`
	BrowserDownloadURL string `json:"browser_download_url"`
	Size               int64  `json:"size"`
}

GitHubAsset represents a release asset

type GitHubRelease

type GitHubRelease struct {
	TagName     string        `json:"tag_name"`
	Name        string        `json:"name"`
	PublishedAt string        `json:"published_at"`
	Assets      []GitHubAsset `json:"assets"`
}

GitHubRelease represents the GitHub release API response

type History

type History struct {
	Entries []HistoryEntry `yaml:"entries"`
}

type HistoryEntry

type HistoryEntry struct {
	Profile   string    `yaml:"profile" json:"profile"`
	Action    string    `yaml:"action" json:"action"`
	Timestamp time.Time `yaml:"timestamp" json:"timestamp"`
	Details   string    `yaml:"details,omitempty" json:"details,omitempty"`
}

type Manager

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

func NewManager

func NewManager() (*Manager, error)

func (*Manager) CheckForUpdate

func (m *Manager) CheckForUpdate(currentVersion string) (latestVersion string, hasUpdate bool, err error)

CheckForUpdate checks GitHub for the latest version and updates the cache Returns the latest version and whether an update is available

func (*Manager) ClearCurrentProfile

func (m *Manager) ClearCurrentProfile() error

ClearCurrentProfile clears the current profile state (for empty mode)

func (*Manager) CopyProfile

func (m *Manager) CopyProfile(srcName, destName string) error

func (*Manager) DeleteProfile

func (m *Manager) DeleteProfile(name string) error

func (*Manager) GetCachedLatestVersion

func (m *Manager) GetCachedLatestVersion() string

GetCachedLatestVersion returns the cached latest version without making network request

func (*Manager) GetConfigDir

func (m *Manager) GetConfigDir() string

func (*Manager) GetCurrentProfile

func (m *Manager) GetCurrentProfile() (*Profile, error)

func (*Manager) GetCurrentProfileName

func (m *Manager) GetCurrentProfileName() (string, error)

func (*Manager) GetEmptyConfig

func (m *Manager) GetEmptyConfig() Config

GetEmptyConfig returns an empty configuration template

func (*Manager) GetHistory

func (m *Manager) GetHistory() ([]HistoryEntry, error)

func (*Manager) GetLatestRelease

func (m *Manager) GetLatestRelease() (*GitHubRelease, error)

GetLatestRelease fetches the latest release info from GitHub (exported for update command)

func (*Manager) GetPreviousProfileName

func (m *Manager) GetPreviousProfileName() (string, error)

func (*Manager) GetProfilesDir

func (m *Manager) GetProfilesDir() string

func (*Manager) GetTemplatesDir

func (m *Manager) GetTemplatesDir() string

func (*Manager) Initialize

func (m *Manager) Initialize() error

func (*Manager) ListProfiles

func (m *Manager) ListProfiles() ([]Profile, error)

func (*Manager) LoadProfile

func (m *Manager) LoadProfile(name string) (*Profile, error)

func (*Manager) LoadUpdateCache

func (m *Manager) LoadUpdateCache() (*UpdateCache, error)

LoadUpdateCache loads the update cache from file

func (*Manager) ProfileExists

func (m *Manager) ProfileExists(name string) bool

ProfileExists checks if a profile with the given name exists

func (*Manager) RenameProfile

func (m *Manager) RenameProfile(oldName, newName string) error

func (*Manager) SaveProfile

func (m *Manager) SaveProfile(profile *Profile) error

func (*Manager) SaveUpdateCache

func (m *Manager) SaveUpdateCache(cache *UpdateCache) error

SaveUpdateCache saves the update cache to file

func (*Manager) SetCurrentProfile

func (m *Manager) SetCurrentProfile(name string) error

func (*Manager) ShouldCheckUpdate

func (m *Manager) ShouldCheckUpdate() bool

ShouldCheckUpdate determines if an update check is needed based on cache

type Profile

type Profile struct {
	Name        string    `yaml:"name"`
	Description string    `yaml:"description,omitempty"`
	Config      Config    `yaml:"config"`
	CreatedAt   time.Time `yaml:"created_at"`
	UpdatedAt   time.Time `yaml:"updated_at"`
	Tags        []string  `yaml:"tags,omitempty"`
}

type State

type State struct {
	CurrentProfile  string    `yaml:"current_profile,omitempty"`
	PreviousProfile string    `yaml:"previous_profile,omitempty"`
	LastUpdated     time.Time `yaml:"last_updated"`
	Version         string    `yaml:"version"`
}

type UpdateCache

type UpdateCache struct {
	LastCheckTime      time.Time `yaml:"last_check_time"`
	LatestVersion      string    `yaml:"latest_version"`
	CheckIntervalHours int       `yaml:"check_interval_hours"`
}

UpdateCache stores the last update check result

Jump to

Keyboard shortcuts

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