config

package
v2026.609.1 Latest Latest
Warning

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

Go to latest
Published: Jun 9, 2026 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	EnvOpenAIBaseURL = "OPENAI_BASE_URL"
	EnvOpenAIAPIKey  = "OPENAI_API_KEY"
	EnvModelID       = "MODEL_ID"
)
View Source
const (
	ProviderNameChatGPTSub  = "ChatGPT Sub"
	ProviderNameClaudeSub   = "Claude Sub"
	ProviderNameCursorAPI   = "Cursor API"
	CursorAPIDefaultModelID = "composer-2.5"
	OpenAIPlatformBase      = "https://api.openai.com"
	AnthropicPlatformBase   = "https://api.anthropic.com"

	AuthKindAPIKey       = "api_key"
	AuthKindOAuthChatGPT = "oauth_chatgpt"
	AuthKindOAuthClaude  = "oauth_claude"
	AuthKindCursorAPI    = "cursor_api"

	ClaudeSubExpectedDate = "2026-06-15"
)
View Source
const (
	ProviderKindChatGPTSub          = 1
	ProviderKindOpenAICompatible    = 2
	ProviderKindAnthropicCompatible = 3
	ProviderKindClaudeSub           = 4
	ProviderKindCursorAPI           = 5
)
View Source
const APIProtocolAnthropic = "anthropic"
View Source
const APIProtocolOpenAI = "openai"
View Source
const DefaultAPIBaseDelayMS = 1000
View Source
const DefaultAPICircuitOpenSec = 60
View Source
const DefaultAPIConnectTimeoutSec = 30
View Source
const DefaultAPIMaxDelayMS = 30000
View Source
const DefaultAPIMaxRetries = 3
View Source
const DefaultCompactionThresholdTokens int64 = 131072
View Source
const DefaultDocSearchFullArticleScore = 0.9
View Source
const DefaultDocSearchMinNormalizedScore = 0.05
View Source
const DefaultResponseLanguage = "English"
View Source
const DefaultSkillSearchMinNormalizedScore = 0.05
View Source
const DefaultSubagentTimeoutMinutes = 20
View Source
const DefaultToolOutputMaxBytes = 65536
View Source
const DefaultToolOutputMaxLines = 2048
View Source
const DefaultWebSearchEngine = "duckduckgo"
View Source
const MaxModelPickerEntries = 25
View Source
const MinCompactionThresholdTokens int64 = 32768

Variables

View Source
var ErrOnboardProviderSkipped = errors.New("onboard provider skipped")

Functions

func AllDigits

func AllDigits(s string) bool

func AppendOrUpdateProvider

func AppendOrUpdateProvider(r *Root, p Provider)

func ApplyOAuthTokens

func ApplyOAuthTokens(p *Provider, t codex.TokenSet)

func ApplyOnboardMerge

func ApplyOnboardMerge(dst *Root, res *OnboardResult)

func BackupConfig

func BackupConfig() (string, error)

func ChooseProviderKind

func ChooseProviderKind(pio PromptIO, require bool, menuTitle string) (kind int, skipped bool, err error)

func ClampTimeoutMinutes

func ClampTimeoutMinutes(n int) error

func ConfigExists

func ConfigExists() (bool, error)

func ConfirmOnboardRerun

func ConfirmOnboardRerun(pio PromptIO) (bool, error)

func CursorAPIConfigured added in v2026.608.0

func CursorAPIConfigured(r *Root) bool

func EffectiveCompactionThresholdTokens

func EffectiveCompactionThresholdTokens(r *Root) int64

func EffectiveDocSearchFullArticleScore added in v2026.608.0

func EffectiveDocSearchFullArticleScore(r *Root) float64

func EffectiveDocSearchMinNorm added in v2026.608.0

func EffectiveDocSearchMinNorm(r *Root) float64

func EffectiveSkillSearchMinNorm

func EffectiveSkillSearchMinNorm(r *Root) float64

func EnsureChatGPTSubBaseURL

func EnsureChatGPTSubBaseURL(p *Provider)

func EnsureClaudeSubBaseURL

func EnsureClaudeSubBaseURL(p *Provider)

func FastModeSupportedByProvider

func FastModeSupportedByProvider(p *Provider) bool

func FirstProviderName

func FirstProviderName(r *Root) string

func IsOAuthAuthKind

func IsOAuthAuthKind(kind string) bool

func ModelPassesChatGPTSubFilter

func ModelPassesChatGPTSubFilter(modelID string) bool

func ModelPassesChatGPTSubPickerFilter

func ModelPassesChatGPTSubPickerFilter(modelID string) bool

func ModelPassesClaudeSubFilter

func ModelPassesClaudeSubFilter(modelID string) bool

func NeedsOnboard

func NeedsOnboard(r *Root) bool

func NormalizeAPIBase

func NormalizeAPIBase(raw string) (string, error)

func NormalizeAnthropicBase

func NormalizeAnthropicBase(raw string) (string, error)

func NoteRecentModelUse

func NoteRecentModelUse(r *Root, providerName, modelID string)

func ParseReasoningEffortToken

func ParseReasoningEffortToken(s string) (string, error)

func PickModelInteractive

func PickModelInteractive(pio PromptIO, p *Provider, providerLabel string, ids []string, allowSkip bool) (string, error)

func PrintConfigSkipHint

func PrintConfigSkipHint(out io.Writer, topic string)

func PrintProviderConnectMenu

func PrintProviderConnectMenu(out io.Writer, title string)

func ProviderConnectMenuLines

func ProviderConnectMenuLines() []string

func ProviderCredentialsReady

func ProviderCredentialsReady(p *Provider) bool

func ReadPromptLine

func ReadPromptLine(p PromptIO, prompt string) (string, error)

func ResolveExecConfig

func ResolveExecConfig(existing *Root, opts ExecResolveOpts) (*Root, *Provider, error)

func ResolveProviderBearer

func ResolveProviderBearer(ctx context.Context, r *Root, p *Provider) (string, error)

func Save

func Save(r *Root) error

func SubagentTimeout

func SubagentTimeout(r *Root) int

func WriteConfigSetupWarning

func WriteConfigSetupWarning(w io.Writer, r *Root)

Types

type APIResilienceConfig

type APIResilienceConfig struct {
	MaxRetries        int   `toml:"max_retries,omitempty"`
	BaseDelayMS       int   `toml:"base_delay_ms,omitempty"`
	MaxDelayMS        int   `toml:"max_delay_ms,omitempty"`
	Jitter            *bool `toml:"jitter,omitempty"`
	ConnectTimeoutSec int   `toml:"connect_timeout_sec,omitempty"`
	ReadTimeoutSec    int   `toml:"read_timeout_sec,omitempty"`
	CircuitOpenSec    int   `toml:"circuit_open_sec,omitempty"`
}

type APIResiliencePolicy

type APIResiliencePolicy struct {
	MaxRetries     int
	BaseDelay      time.Duration
	MaxDelay       time.Duration
	Jitter         bool
	ConnectTimeout time.Duration
	ReadTimeout    time.Duration
	CircuitOpen    time.Duration
}

func EffectiveAPIResilience

func EffectiveAPIResilience(r *Root) APIResiliencePolicy

type Current

type Current struct {
	Provider string `toml:"provider"`
	Model    string `toml:"model"`
}

type ExecResolveOpts

type ExecResolveOpts struct {
	EnvFile string
}

type ModelPickChoice

type ModelPickChoice struct {
	ProviderName string
	ModelID      string
	Changed      bool
}

func PickModelAfterAdd

func PickModelAfterAdd(pio PromptIO, prevProv, prevModel, newProvName string, newIDs []string, allowSkip bool) (ModelPickChoice, error)

type OAuthTokenSet

type OAuthTokenSet struct {
	AccessToken  string
	RefreshToken string
	ExpiresAt    time.Time
	AccountID    string
}

type OnboardOpts

type OnboardOpts struct {
	RequireProvider bool
}

type OnboardResult

type OnboardResult struct {
	UserName                  string
	ResponseLanguage          string
	SubagentTimeoutMinutes    int
	CompactionThresholdTokens int64
	NewProvider               *Provider
	SwitchCurrent             bool
	CurrentProvider           string
	CurrentModel              string
}

func RunOnboardWizard

func RunOnboardWizard(pio PromptIO, existing *Root, opts OnboardOpts) (*OnboardResult, error)

type PromptIO

type PromptIO struct {
	Stdin    io.Reader
	Out      io.Writer
	ReadLine func(prompt string) (string, error)
}

type Provider

type Provider struct {
	Name              string `toml:"-"`
	BaseURL           string `toml:"base_url"`
	APIKey            string `toml:"api_key"`
	APIProtocol       string `toml:"api_protocol,omitempty"`
	AuthKind          string `toml:"auth_kind,omitempty"`
	OAuthAccessToken  string `toml:"oauth_access_token,omitempty"`
	OAuthRefreshToken string `toml:"oauth_refresh_token,omitempty"`
	OAuthExpiresAt    string `toml:"oauth_expires_at,omitempty"`
	OAuthAccountID    string `toml:"oauth_account_id,omitempty"`
}

func NewChatGPTSubProvider

func NewChatGPTSubProvider(baseURL string, tokens codex.TokenSet) (Provider, error)

func ProviderByName

func ProviderByName(r *Root, name string) *Provider

func ProviderList

func ProviderList(r *Root) []Provider

func ResolveProvider

func ResolveProvider(r *Root) (*Provider, error)

func (*Provider) EffectiveAPIProtocol

func (p *Provider) EffectiveAPIProtocol() string

func (*Provider) EffectiveAuthKind

func (p *Provider) EffectiveAuthKind() string

func (*Provider) IsAnthropic

func (p *Provider) IsAnthropic() bool

func (*Provider) IsChatGPTSub

func (p *Provider) IsChatGPTSub() bool

func (*Provider) IsClaudeSub

func (p *Provider) IsClaudeSub() bool

func (*Provider) IsCursorAPI

func (p *Provider) IsCursorAPI() bool

func (*Provider) IsOAuthProvider

func (p *Provider) IsOAuthProvider() bool

func (*Provider) UsesAnthropicOAuthBearer

func (p *Provider) UsesAnthropicOAuthBearer() bool

type ProviderSetupOpts

type ProviderSetupOpts struct {
	RequireProvider bool
	WriteToConfig   bool
	SaveConfig      func() error
}

type ProviderSetupResult

type ProviderSetupResult struct {
	Provider        Provider
	SwitchCurrent   bool
	CurrentProvider string
	CurrentModel    string
}

func FinalizeProviderSetup

func FinalizeProviderSetup(pio PromptIO, cfg *Root, existing *Root, opts ProviderSetupOpts, prov Provider, ids []string) (*ProviderSetupResult, error)

func RunProviderSetupByKind

func RunProviderSetupByKind(ctx context.Context, pio PromptIO, cfg *Root, existing *Root, kind int, opts ProviderSetupOpts) (*ProviderSetupResult, error)

type RecentModelUse

type RecentModelUse struct {
	Provider string `toml:"provider"`
	Model    string `toml:"model"`
}

func RecentModelUseEntries

func RecentModelUseEntries(r *Root, preferProvider string) []RecentModelUse

type Root

type Root struct {
	UserName                  string               `toml:"user_name"`
	Providers                 map[string]*Provider `toml:"-"`
	Current                   Current              `toml:"current"`
	RecentModels              map[string][]string  `toml:"recent_models,omitempty"`
	SubagentTimeoutMinutes    int                  `toml:"subagent_timeout_minutes"`
	ReasoningEffort           string               `toml:"reasoning_effort"`
	FastMode                  *bool                `toml:"fast_mode,omitempty"`
	LogLevel                  string               `toml:"log_level"`
	MaxResponseTokens         int                  `toml:"max_response_tokens"`
	ShowThinking              bool                 `toml:"show_thinking"`
	Tools                     Tools                `toml:"tools,omitempty"`
	ShowUsageStats            *bool                `toml:"show_usage_stats"`
	ResponseLanguage          string               `toml:"response_language"`
	CompactionThresholdTokens int64                `toml:"compaction_threshold_tokens"`
	SkillSearchMinNorm        *float64             `toml:"skill_search_min_normalized_score,omitempty"`
	DocSearchMinNorm          *float64             `toml:"doc_search_min_normalized_score,omitempty"`
	DocSearchFullArticleScore *float64             `toml:"doc_search_full_article_score,omitempty"`
	WebSearchEngine           string               `toml:"web_search_engine,omitempty"`
	WebSearchAPIKey           string               `toml:"web_search_api_key,omitempty"`
	WebSearchBaseURL          string               `toml:"web_search_base_url,omitempty"`
	WebSearchCX               string               `toml:"web_search_cx,omitempty"`
	ToolOutput                ToolOutput           `toml:"tool_output,omitempty"`
	APIResilience             APIResilienceConfig  `toml:"api_resilience,omitempty"`
	AutoUpdate                *bool                `toml:"autoupdate,omitempty"`
}

func EmptyRoot

func EmptyRoot() *Root

func Load

func Load() (*Root, error)

func LoadOptional

func LoadOptional() (*Root, error)

func RunWizardIfNeeded

func RunWizardIfNeeded(stdin io.Reader) (*Root, error)

func (*Root) AutoUpdateEnabled added in v2026.602.3

func (r *Root) AutoUpdateEnabled() bool

func (*Root) EffectiveFastMode

func (r *Root) EffectiveFastMode() bool

func (*Root) EffectiveResponseLanguage

func (r *Root) EffectiveResponseLanguage() string

func (*Root) EffectiveWebSearchEngine

func (r *Root) EffectiveWebSearchEngine() string

func (*Root) FastModeEnabledForProvider

func (r *Root) FastModeEnabledForProvider(p *Provider) bool

func (*Root) GlobalReasoningEffort

func (r *Root) GlobalReasoningEffort() shared.ReasoningEffort

func (*Root) LegacyToolsEnabled

func (r *Root) LegacyToolsEnabled() bool

func (*Root) LegacyToolsForceEnabled

func (r *Root) LegacyToolsForceEnabled() bool

func (*Root) ModelDisplayName

func (r *Root) ModelDisplayName(p *Provider, model string) string

func (*Root) ReasoningEffortDisplayLabel

func (r *Root) ReasoningEffortDisplayLabel() string

func (*Root) ReasoningEffortIsNone

func (r *Root) ReasoningEffortIsNone() bool

func (*Root) ReasoningEffortLabel

func (r *Root) ReasoningEffortLabel() string

func (*Root) UsageStatsEnabled

func (r *Root) UsageStatsEnabled() bool

type ToolOutput

type ToolOutput struct {
	MaxBytes int `toml:"max_bytes,omitempty"`
	MaxLines int `toml:"max_lines,omitempty"`
}

type Tools

type Tools struct {
	Legacy              bool `toml:"legacy,omitempty"`
	LegacyForce         bool `toml:"legacy_force,omitempty"`
	CursorInternalTools bool `toml:"cursor_internal_tools,omitempty"`
}

Jump to

Keyboard shortcuts

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