package config import ( "errors" "fmt" "os" "path/filepath" "github.com/BurntSushi/toml" ) // Project represents a named workspace project used for webhook routing. type Project struct { Name string `toml:"name"` Dir string `toml:"dir"` } type Config struct { DataDir string `toml:"data_dir"` DBPath string `toml:"-"` LogDir string `toml:"-"` ClaudeBinaryPath string `toml:"claude_binary_path"` GeminiBinaryPath string `toml:"gemini_binary_path"` MaxConcurrent int `toml:"max_concurrent"` DefaultTimeout string `toml:"default_timeout"` ServerAddr string `toml:"server_addr"` WebhookURL string `toml:"webhook_url"` WorkspaceRoot string `toml:"workspace_root"` WebhookSecret string `toml:"webhook_secret"` Projects []Project `toml:"projects"` } func Default() (*Config, error) { home, err := os.UserHomeDir() if err != nil { return nil, fmt.Errorf("cannot determine home directory: %w", err) } if home == "" { return nil, errors.New("cannot determine home directory: HOME is empty") } dataDir := filepath.Join(home, ".claudomator") return &Config{ DataDir: dataDir, DBPath: filepath.Join(dataDir, "claudomator.db"), LogDir: filepath.Join(dataDir, "executions"), ClaudeBinaryPath: "claude", GeminiBinaryPath: "gemini", MaxConcurrent: 3, DefaultTimeout: "15m", ServerAddr: ":8484", WorkspaceRoot: "/workspace", }, nil } // LoadFile loads a TOML config file on top of the defaults. // Fields not present in the file retain their default values. func LoadFile(path string) (*Config, error) { cfg, err := Default() if err != nil { return nil, err } if _, err := toml.DecodeFile(path, cfg); err != nil { return nil, fmt.Errorf("loading config file %q: %w", path, err) } return cfg, nil } // EnsureDirs creates the data directory structure. func (c *Config) EnsureDirs() error { for _, dir := range []string{c.DataDir, c.LogDir} { if err := os.MkdirAll(dir, 0700); err != nil { return err } } return nil }