|
109 | 109 | (io/file (get-property "user.home") ".config"))] |
110 | 110 | (io/file xdg-config-home "eca"))) |
111 | 111 |
|
| 112 | +(defn global-config-file ^File [] |
| 113 | + (io/file (global-config-dir) "config.json")) |
| 114 | + |
112 | 115 | (defn ^:private config-from-global-file* [] |
113 | | - (let [config-file (io/file (global-config-dir) "config.json")] |
| 116 | + (let [config-file (global-config-file)] |
114 | 117 | (when (.exists config-file) |
115 | 118 | (safe-read-json-string (slurp config-file) (var *global-config-error*))))) |
116 | 119 |
|
|
190 | 193 | :else m*))] |
191 | 194 | (normalize-map [] m))) |
192 | 195 |
|
| 196 | +(def ^:private eca-config-normalization-rules |
| 197 | + {:kebab-case |
| 198 | + [[:providers]] |
| 199 | + :stringfy |
| 200 | + [[:providers] |
| 201 | + [:providers :ANY :models] |
| 202 | + [:toolCall :approval :allow] |
| 203 | + [:toolCall :approval :allow :ANY :argsMatchers] |
| 204 | + [:toolCall :approval :ask] |
| 205 | + [:toolCall :approval :ask :ANY :argsMatchers] |
| 206 | + [:toolCall :approval :deny] |
| 207 | + [:toolCall :approval :deny :ANY :argsMatchers] |
| 208 | + [:customTools] |
| 209 | + [:customTools :ANY :schema :properties] |
| 210 | + [:mcpServers]]}) |
| 211 | + |
193 | 212 | (defn all [db] |
194 | 213 | (let [initialization-config @initialization-config* |
195 | 214 | pure-config? (:pureConfig initialization-config)] |
196 | 215 | (deep-merge initial-config |
197 | 216 | (normalize-fields |
198 | | - {:kebab-case |
199 | | - [[:providers]] |
200 | | - :stringfy |
201 | | - [[:providers] |
202 | | - [:providers :ANY :models] |
203 | | - [:toolCall :approval :allow] |
204 | | - [:toolCall :approval :allow :ANY :argsMatchers] |
205 | | - [:toolCall :approval :ask] |
206 | | - [:toolCall :approval :ask :ANY :argsMatchers] |
207 | | - [:toolCall :approval :deny] |
208 | | - [:toolCall :approval :deny :ANY :argsMatchers] |
209 | | - [:customTools] |
210 | | - [:customTools :ANY :schema :properties] |
211 | | - [:mcpServers]]} |
| 217 | + eca-config-normalization-rules |
212 | 218 | (deep-merge initialization-config |
213 | 219 | (when-not pure-config? (config-from-envvar)) |
214 | 220 | (when-not pure-config? (config-from-global-file)) |
|
285 | 291 | (when (seq config-to-notify) |
286 | 292 | (swap! db* update :last-config-notified shared/deep-merge config-to-notify) |
287 | 293 | (messenger/config-updated messenger config-to-notify)))) |
| 294 | + |
| 295 | +(defn update-global-config! [config] |
| 296 | + (let [global-config-file (global-config-file) |
| 297 | + current-config (normalize-fields eca-config-normalization-rules (config-from-global-file)) |
| 298 | + new-config (deep-merge current-config |
| 299 | + (normalize-fields eca-config-normalization-rules config)) |
| 300 | + new-config-json (json/generate-string new-config {:pretty true})] |
| 301 | + (io/make-parents global-config-file) |
| 302 | + (spit global-config-file new-config-json))) |
0 commit comments