config

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 11, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrUnsupportedReasoningEffort = errors.New("unsupported reasoning_effort")
View Source
var ReasoningEffortOptions = []string{"auto", "none", "low", "medium", "high", "xhigh"}

ReasoningEffortOptions enumerates the values exposed to the web UI; "auto" is added on top of the validated set so the UI can render the unset case.

Functions

func BuildSettingsResponse

func BuildSettingsResponse(path string, exists bool, raw map[string]any, order Order) map[string]any

BuildSettingsResponse renders the GET /api/settings payload. The web UI needs the saved config plus metadata about valid options / env vars to render the settings form without making extra calls.

func ExpandAbs

func ExpandAbs(path string) string

ExpandAbs resolves "~" to the user's home directory and returns the cleaned absolute path. Empty input stays empty.

func GateReasoningEffort

func GateReasoningEffort(effort string, supportsReasoning, adapterSupportsEffort bool) string

GateReasoningEffort returns effort only when the model supports reasoning and the adapter exposes the effort knob; otherwise it returns "".

func IsAPIKeyEnvRef

func IsAPIKeyEnvRef(value string) string

func MergeAPIKeys

func MergeAPIKeys(incoming, existing map[string]any)

MergeAPIKeys carries over saved api_keys for providers whose incoming payload omits them (the UI never echoes saved secrets back). Providers that explicitly clear api_key still drop it.

func ModelsForProvider

func ModelsForProvider(settings Settings, resolved ResolvedProvider) []string

ModelsForProvider returns the models to expose for a resolved provider: configured models first (with their explicit order), otherwise the spec's defaults, falling back to the single resolved model when no spec matches.

func NormalizeReasoningEffort

func NormalizeReasoningEffort(value string) (string, error)

func PermissionLevelOptions

func PermissionLevelOptions() []string

func PermissionModeOptions

func PermissionModeOptions() []string

func ProjectDirs

func ProjectDirs(cwd, project string) []string

ProjectDirs returns directories from project to cwd, inclusive.

func ResolveHome

func ResolveHome() string

ResolveHome returns the mycode home directory.

func ResolveProject

func ResolveProject(cwd string) string

ResolveProject returns the nearest Git project root, or cwd when no .git is found.

func ResolveSessionsDir

func ResolveSessionsDir() string

ResolveSessionsDir returns the persisted sessions directory.

func ResolveSymlinks(path string) string

ResolveSymlinks returns an absolute path with symlinks resolved for existing path components. Missing trailing components are kept as written.

func ResponseReasoningEffort

func ResponseReasoningEffort(value string) any

func ValidateGlobalConfig

func ValidateGlobalConfig(data any) (map[string]any, error)

func WriteSettingsFile

func WriteSettingsFile(path string, payload map[string]any, order Order) error

WriteSettingsFile writes payload as pretty-printed JSON via a temp-file rename, preserving the caller-supplied provider/model ordering. The atomic rename ensures a crash mid-write cannot truncate the settings.

Types

type Order

type Order struct {
	ProviderOrder []string
	ModelOrder    map[string][]string
}

func ParseConfigOrder

func ParseConfigOrder(data []byte) Order

ParseConfigOrder preserves model order lost by map unmarshalling.

func ReadRawSettings

func ReadRawSettings(path string) (raw map[string]any, order Order, exists bool, err error)

ReadRawSettings loads the global settings JSON. Returns an empty map and exists=false when the file is missing or not a regular file (e.g. a directory placeholder). Parse failures bubble up with the file path.

type PermissionConfig

type PermissionConfig struct {
	Level string
	Mode  string
}

PermissionConfig controls automatic tool execution.

func DefaultPermissionConfig

func DefaultPermissionConfig() PermissionConfig

type ProviderConfig

type ProviderConfig struct {
	Name            string
	Type            string
	Models          map[string]mycode.ModelOverride
	ModelOrder      []string
	APIKey          string
	APIKeyEnvVar    string
	BaseURL         string
	ReasoningEffort string
}

ProviderConfig defines one configured provider alias, parsed field by field from the raw settings JSON.

type ResolvedProvider

type ResolvedProvider struct {
	ProviderName    string
	ProviderType    string
	Model           string
	APIKey          string
	APIBase         string
	ReasoningEffort string
	Metadata        mycode.ModelMetadata
}

ResolvedProvider is the runnable provider config. Metadata is the model capability set already resolved from the bundled catalog plus any per-model config overrides.

func AvailableProviders

func AvailableProviders(settings Settings) []ResolvedProvider

AvailableProviders returns currently selectable providers in stable order.

func ResolveProvider

func ResolveProvider(settings Settings, providerName, model, apiKey, apiBase string) (ResolvedProvider, error)

ResolveProvider resolves one provider alias or built-in provider id.

type Settings

type Settings struct {
	Providers              map[string]ProviderConfig
	DefaultProvider        string
	DefaultModel           string
	DefaultReasoningEffort string
	CompactThreshold       float64
	Permission             PermissionConfig
	Port                   int
	CWD                    string
	Project                string
	ConfigPaths            []string
	// contains filtered or unexported fields
}

Settings is the resolved config view for one cwd.

func Load

func Load(cwd string) (Settings, error)

Load returns merged config for one cwd.

Jump to

Keyboard shortcuts

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