/ internal / config / settings.go
settings.go
 1  package config
 2  
 3  import (
 4  	"encoding/json"
 5  	"fmt"
 6  	"os"
 7  	"path/filepath"
 8  )
 9  
10  type Settings struct {
11  	SpinnerTexts []string `json:"spinner_texts"`
12  }
13  
14  var defaultSettings = Settings{
15  	SpinnerTexts: []string{
16  		"Thinking deeply...",
17  		"Exploring possibilities...",
18  		"Connecting the dots...",
19  		"Almost there...",
20  		"Analyzing patterns...",
21  		"Gathering insights...",
22  		"Processing information...",
23  		"Synthesizing results...",
24  		"Working on it...",
25  		"Crunching data...",
26  		"Weighing options...",
27  		"Reasoning step by step...",
28  		"Considering alternatives...",
29  		"Mapping the problem space...",
30  		"Tracing dependencies...",
31  		"Building a mental model...",
32  		"Searching for patterns...",
33  		"Evaluating trade-offs...",
34  		"Forming a hypothesis...",
35  		"Checking assumptions...",
36  		"Piecing it together...",
37  		"Following the thread...",
38  		"Digging deeper...",
39  		"Running through scenarios...",
40  		"Refining the approach...",
41  	},
42  }
43  
44  func LoadSettings() *Settings {
45  	s := defaultSettings
46  	dir := ShannonDir()
47  	if dir == "" {
48  		return &s
49  	}
50  	path := filepath.Join(dir, "settings.json")
51  
52  	data, err := os.ReadFile(path)
53  	if err != nil {
54  		return &s
55  	}
56  
57  	// Unmarshal on top of defaults — only overrides fields present in JSON
58  	if err := json.Unmarshal(data, &s); err != nil {
59  		return &defaultSettings
60  	}
61  
62  	// Ensure non-empty spinner texts
63  	if len(s.SpinnerTexts) == 0 {
64  		s.SpinnerTexts = defaultSettings.SpinnerTexts
65  	}
66  	return &s
67  }
68  
69  func SaveSettings(s *Settings) error {
70  	dir := ShannonDir()
71  	if dir == "" {
72  		return fmt.Errorf("failed to resolve home directory for settings")
73  	}
74  	path := filepath.Join(dir, "settings.json")
75  	data, err := json.MarshalIndent(s, "", "  ")
76  	if err != nil {
77  		return err
78  	}
79  	return os.WriteFile(path, data, 0600)
80  }
81  
82  // InitSettingsFile creates settings.json with defaults if it doesn't exist.
83  func InitSettingsFile(dir string) error {
84  	if dir == "" {
85  		return fmt.Errorf("failed to resolve home directory for settings")
86  	}
87  	path := filepath.Join(dir, "settings.json")
88  	if _, err := os.Stat(path); err == nil {
89  		return nil // already exists
90  	}
91  	return SaveSettings(&defaultSettings)
92  }