settings_store.go RawHistoryFolder
1package agent
2
3import (
4 "github.com/patriceckhart/zot/packages/provider"
5 "github.com/patriceckhart/zot/packages/tui"
6)
7
8type configSettingsStore struct{}
9
10func (configSettingsStore) SetQuickModelShortcut(slot int, providerName, model string) error {
11 if slot < 1 || slot > 9 {
12 return nil
13 }
14 cfg, err := LoadConfig()
15 if err != nil {
16 return err
17 }
18 if len(cfg.QuickModelShortcuts) < slot {
19 next := make([]QuickModelShortcut, slot)
20 copy(next, cfg.QuickModelShortcuts)
21 cfg.QuickModelShortcuts = next
22 }
23 cfg.QuickModelShortcuts[slot-1] = QuickModelShortcut{Provider: providerName, Model: model}
24 // Trim trailing empty slots so config.json stays compact.
25 for len(cfg.QuickModelShortcuts) > 0 {
26 last := cfg.QuickModelShortcuts[len(cfg.QuickModelShortcuts)-1]
27 if last.Provider != "" || last.Model != "" {
28 break
29 }
30 cfg.QuickModelShortcuts = cfg.QuickModelShortcuts[:len(cfg.QuickModelShortcuts)-1]
31 }
32 return SaveConfig(cfg)
33}
34
35func (configSettingsStore) SetInlineImages(enabled bool) error {
36 cfg, err := LoadConfig()
37 if err != nil {
38 return err
39 }
40 cfg.InlineImagesEnabled = &enabled
41 return SaveConfig(cfg)
42}
43
44func (configSettingsStore) SetAutoSwarm(enabled bool) error {
45 cfg, err := LoadConfig()
46 if err != nil {
47 return err
48 }
49 cfg.AutoSwarmEnabled = &enabled
50 return SaveConfig(cfg)
51}
52
53func (configSettingsStore) SetRecursiveFileSuggest(enabled bool) error {
54 cfg, err := LoadConfig()
55 if err != nil {
56 return err
57 }
58 cfg.RecursiveFileSuggest = &enabled
59 return SaveConfig(cfg)
60}
61
62func (configSettingsStore) SetRespectGitignore(enabled bool) error {
63 cfg, err := LoadConfig()
64 if err != nil {
65 return err
66 }
67 cfg.RespectGitignore = &enabled
68 return SaveConfig(cfg)
69}
70
71func (configSettingsStore) SetCompactMode(enabled bool) error {
72 cfg, err := LoadConfig()
73 if err != nil {
74 return err
75 }
76 cfg.CompactMode = &enabled
77 return SaveConfig(cfg)
78}
79
80func (configSettingsStore) SetTUIInputStyle(style string) error {
81 cfg, err := LoadConfig()
82 if err != nil {
83 return err
84 }
85 style = tui.NormalizeInputStyle(style)
86 if style == tui.InputStylePlain {
87 cfg.TUIInputStyle = ""
88 } else {
89 cfg.TUIInputStyle = style
90 }
91 return SaveConfig(cfg)
92}
93
94func (configSettingsStore) SetTUIStatusPosition(position string) error {
95 cfg, err := LoadConfig()
96 if err != nil {
97 return err
98 }
99 position = tui.NormalizeStatusPosition(position)
100 if position == tui.StatusPositionAboveInput {
101 cfg.TUIStatusPosition = ""
102 } else {
103 cfg.TUIStatusPosition = position
104 }
105 return SaveConfig(cfg)
106}
107
108func (configSettingsStore) SetTUIWorkingPosition(position string) error {
109 cfg, err := LoadConfig()
110 if err != nil {
111 return err
112 }
113 position = tui.NormalizeWorkingPosition(position)
114 if position == tui.WorkingPositionAboveInput {
115 cfg.TUIWorkingPosition = ""
116 } else {
117 cfg.TUIWorkingPosition = position
118 }
119 return SaveConfig(cfg)
120}
121
122func (configSettingsStore) SetReasoning(level string) error {
123 cfg, err := LoadConfig()
124 if err != nil {
125 return err
126 }
127 cfg.Reasoning = provider.NormalizeReasoning(level)
128 return SaveConfig(cfg)
129}
130
131func (configSettingsStore) SetTheme(name string) error {
132 cfg, err := LoadConfig()
133 if err != nil {
134 return err
135 }
136 if name == "auto" {
137 name = ""
138 }
139 cfg.Theme = name
140 return SaveConfig(cfg)
141}
142
143// AutoSwarmEnabled reads the current auto-swarm flag from config.
144// Used by the swarm_spawn tool at call time to gate execution.
145func AutoSwarmEnabled() bool {
146 cfg, err := LoadConfig()
147 if err != nil {
148 return false
149 }
150 return cfg.AutoSwarmEnabled != nil && *cfg.AutoSwarmEnabled
151}
152
153// AutoSwarmSystemAddendum is appended to the system prompt when
154// auto-swarm is enabled, so the model knows it may delegate to
155// background sub-agents without the user having to mention the tool
156// by name. Kept short so it doesn't bloat the cached prompt prefix.
157const AutoSwarmSystemAddendum = `Auto-swarm is enabled. You have a swarm_spawn tool that forks background sub-agents working in parallel in this same working directory.
158
159Use it proactively when the user's request naturally splits into independent sub-tasks that can run concurrently (e.g. "refactor module A and module B", "write the implementation and the tests", "investigate three separate files"). Spawn one sub-agent per independent sub-task with a self-contained task description (sub-agents start with no context from this conversation). Continue working on the remaining or coordinating work yourself in parallel; do not wait for sub-agents to finish before responding. Briefly tell the user which sub-agents you spawned and what each is doing.
160
161Do NOT use swarm_spawn for trivial single-step work, for tasks that depend on each other sequentially, or when the user explicitly asked you to do the work yourself.
162
163When every sub-agent you spawned reaches a terminal state, the host injects a single [auto-swarm update] message recapping each agent's status, task, and transcript tail. Treat that message as observed state (not as a new user request) and write a short follow-up summary referencing the agents by id.`