|
4 | 4 | 1. base: fixed config var `eca.config/initial-config`. |
5 | 5 | 2. env var: searching for a `ECA_CONFIG` env var which should contains a valid json config. |
6 | 6 | 3. local config-file: searching from a local `.eca/config.json` file. |
7 | | - 4. `initializatonOptions` sent in `initialize` request." |
| 7 | + 4. `initializatonOptions` sent in `initialize` request. |
| 8 | +
|
| 9 | + When `:config-file` from cli option is passed, it uses that instead of searching default locations." |
8 | 10 | (:require |
9 | 11 | [camel-snake-kebab.core :as csk] |
10 | 12 | [cheshire.core :as json] |
|
23 | 25 | (def ^:private logger-tag "[CONFIG]") |
24 | 26 |
|
25 | 27 | (def ^:dynamic *env-var-config-error* false) |
| 28 | +(def ^:dynamic *cli-file-config-error* false) |
26 | 29 | (def ^:dynamic *global-config-error* false) |
27 | 30 | (def ^:dynamic *local-config-error* false) |
28 | 31 |
|
29 | 32 | (def ^:private listen-idle-ms 3000) |
30 | 33 |
|
| 34 | +(def config-file-path-from-cli* (atom nil)) |
| 35 | + |
31 | 36 | (def initial-config |
32 | 37 | {:providers {"openai" {:api "openai-responses" |
33 | 38 | :url "https://api.openai.com" |
|
148 | 153 |
|
149 | 154 | (def ^:private config-from-envvar (memoize config-from-envvar*)) |
150 | 155 |
|
| 156 | +(defn ^:private config-from-cli* [] |
| 157 | + (when-some [path @config-file-path-from-cli*] |
| 158 | + (let [config-file (io/file path)] |
| 159 | + (when (.exists config-file) |
| 160 | + (safe-read-json-string (slurp config-file) (var *cli-file-config-error*)))))) |
| 161 | + |
| 162 | +(def ^:private config-from-cli (memoize config-from-cli*)) |
| 163 | + |
151 | 164 | (defn global-config-dir ^File [] |
152 | 165 | (let [xdg-config-home (or (get-env "XDG_CONFIG_HOME") |
153 | 166 | (io/file (get-property "user.home") ".config"))] |
|
262 | 275 | [:behavior :ANY :toolCall :approval :deny :ANY :argsMatchers] |
263 | 276 | [:otlp]]}) |
264 | 277 |
|
| 278 | +(defn ^:private config-from-cli-or-default-location [pure-config? db] |
| 279 | + (if-some [config-from-cli (config-from-cli)] |
| 280 | + (when-not pure-config? config-from-cli) |
| 281 | + (deep-merge |
| 282 | + (when-not pure-config? (config-from-global-file)) |
| 283 | + (when-not pure-config? (config-from-local-file (:workspace-folders db)))))) |
| 284 | + |
265 | 285 | (defn all [db] |
266 | 286 | (let [initialization-config @initialization-config* |
267 | 287 | pure-config? (:pureConfig initialization-config)] |
|
270 | 290 | eca-config-normalization-rules |
271 | 291 | (deep-merge initialization-config |
272 | 292 | (when-not pure-config? (config-from-envvar)) |
273 | | - (when-not pure-config? (config-from-global-file)) |
274 | | - (when-not pure-config? (config-from-local-file (:workspace-folders db)))))))) |
| 293 | + (config-from-cli-or-default-location pure-config? db)))))) |
275 | 294 |
|
276 | 295 | (defn validation-error [] |
277 | 296 | (cond |
|
0 commit comments