config.go

  1package config
  2
  3import "github.com/charmbracelet/crush/internal/fur/provider"
  4
  5const (
  6	appName              = "crush"
  7	defaultDataDirectory = ".crush"
  8	defaultLogLevel      = "info"
  9)
 10
 11var defaultContextPaths = []string{
 12	".github/copilot-instructions.md",
 13	".cursorrules",
 14	".cursor/rules/",
 15	"CLAUDE.md",
 16	"CLAUDE.local.md",
 17	"GEMINI.md",
 18	"gemini.md",
 19	"crush.md",
 20	"crush.local.md",
 21	"Crush.md",
 22	"Crush.local.md",
 23	"CRUSH.md",
 24	"CRUSH.local.md",
 25}
 26
 27type SelectedModel struct {
 28	// The model id as used by the provider API.
 29	// Required.
 30	Model string `json:"model"`
 31	// The model provider, same as the key/id used in the providers config.
 32	// Required.
 33	Provider string `json:"provider"`
 34
 35	// Only used by models that use the openai provider and need this set.
 36	ReasoningEffort string `json:"reasoning_effort,omitempty"`
 37
 38	// Overrides the default model configuration.
 39	MaxTokens int64 `json:"max_tokens,omitempty"`
 40
 41	// Used by anthropic models that can reason to indicate if the model should think.
 42	Think bool `json:"think,omitempty"`
 43}
 44
 45type ProviderConfig struct {
 46	// The provider's API endpoint.
 47	BaseURL string `json:"base_url,omitempty"`
 48	// The provider type, e.g. "openai", "anthropic", etc. if empty it defaults to openai.
 49	Type provider.Type `json:"type,omitempty"`
 50	// The provider's API key.
 51	APIKey string `json:"api_key,omitempty"`
 52	// Marks the provider as disabled.
 53	Disable bool `json:"disable,omitempty"`
 54
 55	// Extra headers to send with each request to the provider.
 56	ExtraHeaders map[string]string
 57
 58	// Used to pass extra parameters to the provider.
 59	ExtraParams map[string]string `json:"-"`
 60
 61	// The provider models
 62	Models []provider.Model `json:"models,omitempty"`
 63}
 64
 65type MCPType string
 66
 67const (
 68	MCPStdio MCPType = "stdio"
 69	MCPSse   MCPType = "sse"
 70	MCPHttp  MCPType = "http"
 71)
 72
 73type MCP struct {
 74	Command string   `json:"command,omitempty" `
 75	Env     []string `json:"env,omitempty"`
 76	Args    []string `json:"args,omitempty"`
 77	Type    MCPType  `json:"type"`
 78	URL     string   `json:"url,omitempty"`
 79
 80	// TODO: maybe make it possible to get the value from the env
 81	Headers map[string]string `json:"headers,omitempty"`
 82}
 83
 84type LSPConfig struct {
 85	Disabled bool     `json:"enabled,omitempty"`
 86	Command  string   `json:"command"`
 87	Args     []string `json:"args,omitempty"`
 88	Options  any      `json:"options,omitempty"`
 89}
 90
 91type TUIOptions struct {
 92	CompactMode bool `json:"compact_mode,omitempty"`
 93	// Here we can add themes later or any TUI related options
 94}
 95
 96type Options struct {
 97	ContextPaths         []string    `json:"context_paths,omitempty"`
 98	TUI                  *TUIOptions `json:"tui,omitempty"`
 99	Debug                bool        `json:"debug,omitempty"`
100	DebugLSP             bool        `json:"debug_lsp,omitempty"`
101	DisableAutoSummarize bool        `json:"disable_auto_summarize,omitempty"`
102	// Relative to the cwd
103	DataDirectory string `json:"data_directory,omitempty"`
104}
105
106// Config holds the configuration for crush.
107type Config struct {
108	workingDir string `json:"-"`
109	// We currently only support large/small as values here.
110	Models map[string]SelectedModel `json:"models,omitempty"`
111
112	// The providers that are configured
113	Providers map[string]ProviderConfig `json:"providers,omitempty"`
114
115	MCP map[string]MCP `json:"mcp,omitempty"`
116
117	LSP map[string]LSPConfig `json:"lsp,omitempty"`
118
119	Options *Options `json:"options,omitempty"`
120}
121
122func (c *Config) WorkingDir() string {
123	return c.workingDir
124}