config

package
v0.10.1 Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EnsureConfigExists

func EnsureConfigExists() error

EnsureConfigExists checks if a config file exists and creates a default one if not. It searches for .kit.{yml,yaml,json} files in the user's home directory. If none exist, creates a default .kit.yml with examples.

func FilepathOr

func FilepathOr[T any](key string, value *T) error

FilepathOr reads a configuration value that can be either a direct value or a filepath to a JSON/YAML file containing the value. If the value is a string starting with "~/" or a relative path, it's expanded to an absolute path. The contents of the file are then unmarshaled into the provided value pointer.

func HasEnvVars

func HasEnvVars(content string) bool

HasEnvVars checks if content contains environment variable patterns (${env://...}). This is useful for determining if substitution is needed before processing.

func LoadSystemPrompt

func LoadSystemPrompt(input string) (string, error)

LoadSystemPrompt loads system prompt from file or returns the string directly. If input is a path to an existing file, its contents are read and returned. Otherwise, the input string is returned as-is.

func SetConfigPath

func SetConfigPath(path string)

SetConfigPath sets the configuration file path for resolving relative paths in configuration values. This should be called when the configuration file location is known.

Types

type AdaptiveColor

type AdaptiveColor struct {
	Light string `json:"light,omitempty" yaml:"light,omitempty"`
	Dark  string `json:"dark,omitempty" yaml:"dark,omitempty"`
}

AdaptiveColor represents a color that adapts to light and dark themes. Either light or dark can be specified, or both for theme-aware coloring.

type Config

type Config struct {
	MCPServers     map[string]MCPServerConfig `json:"mcpServers" yaml:"mcpServers"`
	Model          string                     `json:"model,omitempty" yaml:"model,omitempty"`
	MaxSteps       int                        `json:"max-steps,omitempty" yaml:"max-steps,omitempty"`
	Debug          bool                       `json:"debug,omitempty" yaml:"debug,omitempty"`
	Compact        bool                       `json:"compact,omitempty" yaml:"compact,omitempty"`
	SystemPrompt   string                     `json:"system-prompt,omitempty" yaml:"system-prompt,omitempty"`
	ProviderAPIKey string                     `json:"provider-api-key,omitempty" yaml:"provider-api-key,omitempty"`
	ProviderURL    string                     `json:"provider-url,omitempty" yaml:"provider-url,omitempty"`
	Stream         *bool                      `json:"stream,omitempty" yaml:"stream,omitempty"`
	Theme          any                        `json:"theme" yaml:"theme"`
	MarkdownTheme  any                        `json:"markdown-theme" yaml:"markdown-theme"`
	// Model generation parameters
	MaxTokens     int      `json:"max-tokens,omitempty" yaml:"max-tokens,omitempty"`
	Temperature   *float32 `json:"temperature,omitempty" yaml:"temperature,omitempty"`
	TopP          *float32 `json:"top-p,omitempty" yaml:"top-p,omitempty"`
	TopK          *int32   `json:"top-k,omitempty" yaml:"top-k,omitempty"`
	StopSequences []string `json:"stop-sequences,omitempty" yaml:"stop-sequences,omitempty"`

	// Thinking / extended reasoning
	ThinkingLevel string `json:"thinking-level,omitempty" yaml:"thinking-level,omitempty"`

	// TLS configuration
	TLSSkipVerify bool `json:"tls-skip-verify,omitempty" yaml:"tls-skip-verify,omitempty"`
}

Config represents the complete application configuration including MCP servers, model settings, UI preferences, and API credentials. It supports both command-line flags and configuration file settings.

func LoadAndValidateConfig

func LoadAndValidateConfig() (*Config, error)

LoadAndValidateConfig loads configuration from viper, fixes environment variable casing issues, and validates the configuration. Returns an error if loading or validation fails.

func (*Config) Validate

func (c *Config) Validate() error

Validate validates the configuration, ensuring required fields are present for each server type and that tool filters are used correctly. Returns an error describing any validation failures.

type EnvSubstituter

type EnvSubstituter struct{}

EnvSubstituter handles environment variable substitution in configuration strings, supporting both ${env://VAR} and ${env://VAR:-default} patterns.

func (*EnvSubstituter) SubstituteEnvVars

func (e *EnvSubstituter) SubstituteEnvVars(content string) (string, error)

SubstituteEnvVars replaces ${env://VAR} and ${env://VAR:-default} patterns with environment variables. If a variable is not set and has a default value, the default is used. Returns an error if required variables (those without defaults) are not set.

type MCPServerConfig

type MCPServerConfig struct {
	Type          string            `json:"type"`
	Command       []string          `json:"command,omitempty"`
	Environment   map[string]string `json:"environment,omitempty"`
	URL           string            `json:"url,omitempty"`
	AllowedTools  []string          `json:"allowedTools,omitempty" yaml:"allowedTools,omitempty"`
	ExcludedTools []string          `json:"excludedTools,omitempty" yaml:"excludedTools,omitempty"`

	// Legacy fields for backward compatibility
	Transport string         `json:"transport,omitempty"`
	Args      []string       `json:"args,omitempty"`
	Env       map[string]any `json:"env,omitempty"`
	Headers   []string       `json:"headers,omitempty"`
}

MCPServerConfig represents configuration for an MCP server, supporting both local (stdio) and remote (StreamableHTTP/SSE) server types. It maintains backward compatibility with legacy configuration formats.

func (*MCPServerConfig) GetTransportType

func (s *MCPServerConfig) GetTransportType() string

GetTransportType returns the transport type for the server config, mapping simplified type names to actual transport protocols. Supports legacy format detection and automatic type inference from configuration.

func (*MCPServerConfig) UnmarshalJSON

func (s *MCPServerConfig) UnmarshalJSON(data []byte) error

UnmarshalJSON handles both new and legacy config formats for backward compatibility. New format uses "type" field with "local", "remote", or "builtin" values. Legacy format uses "transport", "command", "args", and "env" fields.

type MarkdownTheme

type MarkdownTheme struct {
	Text    AdaptiveColor `json:"text" yaml:"text"`
	Muted   AdaptiveColor `json:"muted" yaml:"muted"`
	Heading AdaptiveColor `json:"heading" yaml:"heading"`
	Emph    AdaptiveColor `json:"emph" yaml:"emph"`
	Strong  AdaptiveColor `json:"strong" yaml:"strong"`
	Link    AdaptiveColor `json:"link" yaml:"link"`
	Code    AdaptiveColor `json:"code" yaml:"code"`
	Error   AdaptiveColor `json:"error" yaml:"error"`
	Keyword AdaptiveColor `json:"keyword" yaml:"keyword"`
	String  AdaptiveColor `json:"string" yaml:"string"`
	Number  AdaptiveColor `json:"number" yaml:"number"`
	Comment AdaptiveColor `json:"comment" yaml:"comment"`
}

MarkdownTheme defines the color scheme for markdown rendering with syntax highlighting support and adaptive colors for light and dark modes.

type Theme

type Theme struct {
	Primary     AdaptiveColor `json:"primary" yaml:"primary"`
	Secondary   AdaptiveColor `json:"secondary" yaml:"secondary"`
	Success     AdaptiveColor `json:"success" yaml:"success"`
	Warning     AdaptiveColor `json:"warning" yaml:"warning"`
	Error       AdaptiveColor `json:"error" yaml:"error"`
	Info        AdaptiveColor `json:"info" yaml:"info"`
	Text        AdaptiveColor `json:"text" yaml:"text"`
	Muted       AdaptiveColor `json:"muted" yaml:"muted"`
	VeryMuted   AdaptiveColor `json:"very-muted" yaml:"very-muted"`
	Background  AdaptiveColor `json:"background" yaml:"background"`
	Border      AdaptiveColor `json:"border" yaml:"border"`
	MutedBorder AdaptiveColor `json:"muted-border" yaml:"muted-border"`
	System      AdaptiveColor `json:"system" yaml:"system"`
	Tool        AdaptiveColor `json:"tool" yaml:"tool"`
	Accent      AdaptiveColor `json:"accent" yaml:"accent"`
	Highlight   AdaptiveColor `json:"highlight" yaml:"highlight"`
}

Theme defines the color scheme for the application UI with adaptive colors that support both light and dark modes.

Jump to

Keyboard shortcuts

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